Lines Matching refs:sram
68 static int sram_add_pool(struct sram_dev *sram, struct sram_reserve *block, in sram_add_pool() argument
73 part->pool = devm_gen_pool_create(sram->dev, ilog2(SRAM_GRANULARITY), in sram_add_pool()
81 dev_err(sram->dev, "failed to register subpool: %d\n", ret); in sram_add_pool()
88 static int sram_add_export(struct sram_dev *sram, struct sram_reserve *block, in sram_add_export() argument
92 part->battr.attr.name = devm_kasprintf(sram->dev, GFP_KERNEL, in sram_add_export()
103 return device_create_bin_file(sram->dev, &part->battr); in sram_add_export()
106 static int sram_add_partition(struct sram_dev *sram, struct sram_reserve *block, in sram_add_partition() argument
110 struct sram_partition *part = &sram->partition[sram->partitions]; in sram_add_partition()
113 part->base = sram->virt_base + block->start; in sram_add_partition()
116 ret = sram_add_pool(sram, block, start, part); in sram_add_partition()
121 ret = sram_add_export(sram, block, start, part); in sram_add_partition()
126 ret = sram_check_protect_exec(sram, block, part); in sram_add_partition()
130 ret = sram_add_pool(sram, block, start, part); in sram_add_partition()
137 sram->partitions++; in sram_add_partition()
142 static void sram_free_partitions(struct sram_dev *sram) in sram_free_partitions() argument
146 if (!sram->partitions) in sram_free_partitions()
149 part = &sram->partition[sram->partitions - 1]; in sram_free_partitions()
150 for (; sram->partitions; sram->partitions--, part--) { in sram_free_partitions()
152 device_remove_bin_file(sram->dev, &part->battr); in sram_free_partitions()
156 dev_err(sram->dev, "removed pool while SRAM allocated\n"); in sram_free_partitions()
169 static int sram_reserve_regions(struct sram_dev *sram, struct resource *res) in sram_reserve_regions() argument
171 struct device_node *np = sram->dev->of_node, *child; in sram_reserve_regions()
198 dev_err(sram->dev, in sram_reserve_regions()
205 dev_err(sram->dev, in sram_reserve_regions()
232 dev_err(sram->dev, in sram_reserve_regions()
240 block->label = devm_kstrdup(sram->dev, in sram_reserve_regions()
247 dev_dbg(sram->dev, "found %sblock '%s' 0x%x-0x%x\n", in sram_reserve_regions()
251 dev_dbg(sram->dev, "found reserved block 0x%x-0x%x\n", in sram_reserve_regions()
267 sram->partition = devm_kcalloc(sram->dev, in sram_reserve_regions()
268 exports, sizeof(*sram->partition), in sram_reserve_regions()
270 if (!sram->partition) { in sram_reserve_regions()
280 dev_err(sram->dev, in sram_reserve_regions()
284 sram_free_partitions(sram); in sram_reserve_regions()
290 ret = sram_add_partition(sram, block, in sram_reserve_regions()
293 sram_free_partitions(sram); in sram_reserve_regions()
311 dev_dbg(sram->dev, "adding chunk 0x%lx-0x%lx\n", in sram_reserve_regions()
314 ret = gen_pool_add_virt(sram->pool, in sram_reserve_regions()
315 (unsigned long)sram->virt_base + cur_start, in sram_reserve_regions()
318 sram_free_partitions(sram); in sram_reserve_regions()
357 struct sram_dev *sram; in sram_probe() local
363 sram = devm_kzalloc(&pdev->dev, sizeof(*sram), GFP_KERNEL); in sram_probe()
364 if (!sram) in sram_probe()
367 sram->dev = &pdev->dev; in sram_probe()
371 dev_err(sram->dev, "found no memory resource\n"); in sram_probe()
377 if (!devm_request_mem_region(sram->dev, res->start, size, pdev->name)) { in sram_probe()
378 dev_err(sram->dev, "could not request region for resource\n"); in sram_probe()
383 sram->virt_base = devm_ioremap(sram->dev, res->start, size); in sram_probe()
385 sram->virt_base = devm_ioremap_wc(sram->dev, res->start, size); in sram_probe()
386 if (!sram->virt_base) in sram_probe()
389 sram->pool = devm_gen_pool_create(sram->dev, ilog2(SRAM_GRANULARITY), in sram_probe()
391 if (IS_ERR(sram->pool)) in sram_probe()
392 return PTR_ERR(sram->pool); in sram_probe()
394 sram->clk = devm_clk_get(sram->dev, NULL); in sram_probe()
395 if (IS_ERR(sram->clk)) in sram_probe()
396 sram->clk = NULL; in sram_probe()
398 clk_prepare_enable(sram->clk); in sram_probe()
400 ret = sram_reserve_regions(sram, res); in sram_probe()
404 platform_set_drvdata(pdev, sram); in sram_probe()
413 dev_dbg(sram->dev, "SRAM pool: %zu KiB @ 0x%p\n", in sram_probe()
414 gen_pool_size(sram->pool) / 1024, sram->virt_base); in sram_probe()
419 sram_free_partitions(sram); in sram_probe()
421 if (sram->clk) in sram_probe()
422 clk_disable_unprepare(sram->clk); in sram_probe()
429 struct sram_dev *sram = platform_get_drvdata(pdev); in sram_remove() local
431 sram_free_partitions(sram); in sram_remove()
433 if (gen_pool_avail(sram->pool) < gen_pool_size(sram->pool)) in sram_remove()
434 dev_err(sram->dev, "removed while SRAM allocated\n"); in sram_remove()
436 if (sram->clk) in sram_remove()
437 clk_disable_unprepare(sram->clk); in sram_remove()