Lines Matching refs:sram
57 static int sram_add_pool(struct sram_dev *sram, struct sram_reserve *block, in sram_add_pool() argument
62 part->pool = devm_gen_pool_create(sram->dev, ilog2(SRAM_GRANULARITY), in sram_add_pool()
70 dev_err(sram->dev, "failed to register subpool: %d\n", ret); in sram_add_pool()
77 static int sram_add_export(struct sram_dev *sram, struct sram_reserve *block, in sram_add_export() argument
81 part->battr.attr.name = devm_kasprintf(sram->dev, GFP_KERNEL, in sram_add_export()
92 return device_create_bin_file(sram->dev, &part->battr); in sram_add_export()
95 static int sram_add_partition(struct sram_dev *sram, struct sram_reserve *block, in sram_add_partition() argument
99 struct sram_partition *part = &sram->partition[sram->partitions]; in sram_add_partition()
103 if (sram->config && sram->config->map_only_reserved) { in sram_add_partition()
106 if (sram->no_memory_wc) in sram_add_partition()
107 virt_base = devm_ioremap_resource(sram->dev, &block->res); in sram_add_partition()
109 virt_base = devm_ioremap_resource_wc(sram->dev, &block->res); in sram_add_partition()
112 dev_err(sram->dev, "could not map SRAM at %pr\n", &block->res); in sram_add_partition()
118 part->base = sram->virt_base + block->start; in sram_add_partition()
122 ret = sram_add_pool(sram, block, start, part); in sram_add_partition()
127 ret = sram_add_export(sram, block, start, part); in sram_add_partition()
132 ret = sram_check_protect_exec(sram, block, part); in sram_add_partition()
136 ret = sram_add_pool(sram, block, start, part); in sram_add_partition()
143 sram->partitions++; in sram_add_partition()
148 static void sram_free_partitions(struct sram_dev *sram) in sram_free_partitions() argument
152 if (!sram->partitions) in sram_free_partitions()
155 part = &sram->partition[sram->partitions - 1]; in sram_free_partitions()
156 for (; sram->partitions; sram->partitions--, part--) { in sram_free_partitions()
158 device_remove_bin_file(sram->dev, &part->battr); in sram_free_partitions()
162 dev_err(sram->dev, "removed pool while SRAM allocated\n"); in sram_free_partitions()
175 static int sram_reserve_regions(struct sram_dev *sram, struct resource *res) in sram_reserve_regions() argument
177 struct device_node *np = sram->dev->of_node, *child; in sram_reserve_regions()
204 dev_err(sram->dev, in sram_reserve_regions()
211 dev_err(sram->dev, in sram_reserve_regions()
234 dev_err(sram->dev, in sram_reserve_regions()
240 block->label = devm_kasprintf(sram->dev, GFP_KERNEL, in sram_reserve_regions()
243 block->label = devm_kstrdup(sram->dev, in sram_reserve_regions()
250 dev_dbg(sram->dev, "found %sblock '%s' 0x%x-0x%x\n", in sram_reserve_regions()
254 dev_dbg(sram->dev, "found reserved block 0x%x-0x%x\n", in sram_reserve_regions()
270 sram->partition = devm_kcalloc(sram->dev, in sram_reserve_regions()
271 exports, sizeof(*sram->partition), in sram_reserve_regions()
273 if (!sram->partition) { in sram_reserve_regions()
283 dev_err(sram->dev, in sram_reserve_regions()
287 sram_free_partitions(sram); in sram_reserve_regions()
293 ret = sram_add_partition(sram, block, in sram_reserve_regions()
296 sram_free_partitions(sram); in sram_reserve_regions()
314 if (sram->pool) { in sram_reserve_regions()
315 dev_dbg(sram->dev, "adding chunk 0x%lx-0x%lx\n", in sram_reserve_regions()
318 ret = gen_pool_add_virt(sram->pool, in sram_reserve_regions()
319 (unsigned long)sram->virt_base + cur_start, in sram_reserve_regions()
322 sram_free_partitions(sram); in sram_reserve_regions()
379 struct sram_dev *sram; in sram_probe() local
386 sram = devm_kzalloc(&pdev->dev, sizeof(*sram), GFP_KERNEL); in sram_probe()
387 if (!sram) in sram_probe()
390 sram->dev = &pdev->dev; in sram_probe()
391 sram->no_memory_wc = of_property_read_bool(pdev->dev.of_node, "no-memory-wc"); in sram_probe()
392 sram->config = config; in sram_probe()
396 if (sram->no_memory_wc) in sram_probe()
397 sram->virt_base = devm_ioremap_resource(&pdev->dev, res); in sram_probe()
399 sram->virt_base = devm_ioremap_resource_wc(&pdev->dev, res); in sram_probe()
400 if (IS_ERR(sram->virt_base)) { in sram_probe()
402 return PTR_ERR(sram->virt_base); in sram_probe()
405 sram->pool = devm_gen_pool_create(sram->dev, ilog2(SRAM_GRANULARITY), in sram_probe()
407 if (IS_ERR(sram->pool)) in sram_probe()
408 return PTR_ERR(sram->pool); in sram_probe()
411 clk = devm_clk_get_optional_enabled(sram->dev, NULL); in sram_probe()
415 ret = sram_reserve_regions(sram, in sram_probe()
420 platform_set_drvdata(pdev, sram); in sram_probe()
428 if (sram->pool) in sram_probe()
429 dev_dbg(sram->dev, "SRAM pool: %zu KiB @ 0x%p\n", in sram_probe()
430 gen_pool_size(sram->pool) / 1024, sram->virt_base); in sram_probe()
435 sram_free_partitions(sram); in sram_probe()
442 struct sram_dev *sram = platform_get_drvdata(pdev); in sram_remove() local
444 sram_free_partitions(sram); in sram_remove()
446 if (sram->pool && gen_pool_avail(sram->pool) < gen_pool_size(sram->pool)) in sram_remove()
447 dev_err(sram->dev, "removed while SRAM allocated\n"); in sram_remove()