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];
101 if (sram->config && sram->config->map_only_reserved) {
104 if (sram->no_memory_wc)
105 virt_base = devm_ioremap_resource(sram->dev, &block->res);
107 virt_base = devm_ioremap_resource_wc(sram->dev, &block->res);
110 dev_err(sram->dev, "could not map SRAM at %pr\n", &block->res);
116 part->base = sram->virt_base + block->start;
120 ret = sram_add_pool(sram, block, start, part);
125 ret = sram_add_export(sram, block, start, part);
130 ret = sram_check_protect_exec(sram, block, part);
134 ret = sram_add_pool(sram, block, start, part);
141 sram->partitions++;
146 static void sram_free_partitions(struct sram_dev *sram)
150 if (!sram->partitions)
153 part = &sram->partition[sram->partitions - 1];
154 for (; sram->partitions; sram->partitions--, part--) {
156 device_remove_bin_file(sram->dev, &part->battr);
160 dev_err(sram->dev, "removed pool while SRAM allocated\n");
173 static int sram_reserve_regions(struct sram_dev *sram, struct resource *res)
175 struct device_node *np = sram->dev->of_node, *child;
202 dev_err(sram->dev,
209 dev_err(sram->dev,
210 "reserved block %pOF outside the sram area\n",
232 dev_err(sram->dev,
238 block->label = devm_kasprintf(sram->dev, GFP_KERNEL,
241 block->label = devm_kstrdup(sram->dev,
248 dev_dbg(sram->dev, "found %sblock '%s' 0x%x-0x%x\n",
252 dev_dbg(sram->dev, "found reserved block 0x%x-0x%x\n",
268 sram->partition = devm_kcalloc(sram->dev,
269 exports, sizeof(*sram->partition),
271 if (!sram->partition) {
281 dev_err(sram->dev,
285 sram_free_partitions(sram);
291 ret = sram_add_partition(sram, block,
294 sram_free_partitions(sram);
312 if (sram->pool) {
313 dev_dbg(sram->dev, "adding chunk 0x%lx-0x%lx\n",
316 ret = gen_pool_add_virt(sram->pool,
317 (unsigned long)sram->virt_base + cur_start,
320 sram_free_partitions(sram);
366 { .compatible = "mmio-sram" },
377 struct sram_dev *sram;
384 sram = devm_kzalloc(&pdev->dev, sizeof(*sram), GFP_KERNEL);
385 if (!sram)
388 sram->dev = &pdev->dev;
389 sram->no_memory_wc = of_property_read_bool(pdev->dev.of_node, "no-memory-wc");
390 sram->config = config;
394 if (sram->no_memory_wc)
395 sram->virt_base = devm_ioremap_resource(&pdev->dev, res);
397 sram->virt_base = devm_ioremap_resource_wc(&pdev->dev, res);
398 if (IS_ERR(sram->virt_base)) {
400 return PTR_ERR(sram->virt_base);
403 sram->pool = devm_gen_pool_create(sram->dev, ilog2(SRAM_GRANULARITY),
405 if (IS_ERR(sram->pool))
406 return PTR_ERR(sram->pool);
409 clk = devm_clk_get_optional_enabled(sram->dev, NULL);
413 ret = sram_reserve_regions(sram,
418 platform_set_drvdata(pdev, sram);
426 if (sram->pool)
427 dev_dbg(sram->dev, "SRAM pool: %zu KiB @ 0x%p\n",
428 gen_pool_size(sram->pool) / 1024, sram->virt_base);
433 sram_free_partitions(sram);
440 struct sram_dev *sram = platform_get_drvdata(pdev);
442 sram_free_partitions(sram);
444 if (sram->pool && gen_pool_avail(sram->pool) < gen_pool_size(sram->pool))
445 dev_err(sram->dev, "removed while SRAM allocated\n");
452 .name = "sram",