Lines Matching refs:sram
21 #include "sram.h"
55 static int sram_add_pool(struct sram_dev *sram, struct sram_reserve *block,
60 part->pool = devm_gen_pool_create(sram->dev, ilog2(SRAM_GRANULARITY),
68 dev_err(sram->dev, "failed to register subpool: %d\n", ret);
75 static int sram_add_export(struct sram_dev *sram, struct sram_reserve *block,
79 part->battr.attr.name = devm_kasprintf(sram->dev, GFP_KERNEL,
80 "%llx.sram",
90 return device_create_bin_file(sram->dev, &part->battr);
93 static int sram_add_partition(struct sram_dev *sram, struct sram_reserve *block,
97 struct sram_partition *part = &sram->partition[sram->partitions];
100 part->base = sram->virt_base + block->start;
103 ret = sram_add_pool(sram, block, start, part);
108 ret = sram_add_export(sram, block, start, part);
113 ret = sram_check_protect_exec(sram, block, part);
117 ret = sram_add_pool(sram, block, start, part);
124 sram->partitions++;
129 static void sram_free_partitions(struct sram_dev *sram)
133 if (!sram->partitions)
136 part = &sram->partition[sram->partitions - 1];
137 for (; sram->partitions; sram->partitions--, part--) {
139 device_remove_bin_file(sram->dev, &part->battr);
143 dev_err(sram->dev, "removed pool while SRAM allocated\n");
156 static int sram_reserve_regions(struct sram_dev *sram, struct resource *res)
158 struct device_node *np = sram->dev->of_node, *child;
185 dev_err(sram->dev,
192 dev_err(sram->dev,
193 "reserved block %pOF outside the sram area\n",
219 dev_err(sram->dev,
227 block->label = devm_kstrdup(sram->dev,
234 dev_dbg(sram->dev, "found %sblock '%s' 0x%x-0x%x\n",
238 dev_dbg(sram->dev, "found reserved block 0x%x-0x%x\n",
254 sram->partition = devm_kcalloc(sram->dev,
255 exports, sizeof(*sram->partition),
257 if (!sram->partition) {
267 dev_err(sram->dev,
271 sram_free_partitions(sram);
277 ret = sram_add_partition(sram, block,
280 sram_free_partitions(sram);
298 dev_dbg(sram->dev, "adding chunk 0x%lx-0x%lx\n",
301 ret = gen_pool_add_virt(sram->pool,
302 (unsigned long)sram->virt_base + cur_start,
305 sram_free_partitions(sram);
335 { .compatible = "mmio-sram" },
342 struct sram_dev *sram;
346 sram = devm_kzalloc(&pdev->dev, sizeof(*sram), GFP_KERNEL);
347 if (!sram)
350 sram->dev = &pdev->dev;
353 sram->virt_base = devm_platform_ioremap_resource(pdev, 0);
355 sram->virt_base = devm_platform_ioremap_resource_wc(pdev, 0);
356 if (IS_ERR(sram->virt_base)) {
358 return PTR_ERR(sram->virt_base);
361 sram->pool = devm_gen_pool_create(sram->dev, ilog2(SRAM_GRANULARITY),
363 if (IS_ERR(sram->pool))
364 return PTR_ERR(sram->pool);
366 sram->clk = devm_clk_get(sram->dev, NULL);
367 if (IS_ERR(sram->clk))
368 sram->clk = NULL;
370 clk_prepare_enable(sram->clk);
372 ret = sram_reserve_regions(sram,
377 platform_set_drvdata(pdev, sram);
386 dev_dbg(sram->dev, "SRAM pool: %zu KiB @ 0x%p\n",
387 gen_pool_size(sram->pool) / 1024, sram->virt_base);
392 sram_free_partitions(sram);
394 if (sram->clk)
395 clk_disable_unprepare(sram->clk);
402 struct sram_dev *sram = platform_get_drvdata(pdev);
404 sram_free_partitions(sram);
406 if (gen_pool_avail(sram->pool) < gen_pool_size(sram->pool))
407 dev_err(sram->dev, "removed while SRAM allocated\n");
409 if (sram->clk)
410 clk_disable_unprepare(sram->clk);
417 .name = "sram",