Lines Matching +full:exported +full:- +full:sram
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Generic on-chip SRAM allocation driver
19 #include <soc/at91/atmel-secumod.h>
21 #include "sram.h"
33 mutex_lock(&part->lock); in sram_read()
34 memcpy_fromio(buf, part->base + pos, count); in sram_read()
35 mutex_unlock(&part->lock); in sram_read()
48 mutex_lock(&part->lock); in sram_write()
49 memcpy_toio(part->base + pos, buf, count); in sram_write()
50 mutex_unlock(&part->lock); in sram_write()
55 static int sram_add_pool(struct sram_dev *sram, struct sram_reserve *block, in sram_add_pool() argument
60 part->pool = devm_gen_pool_create(sram->dev, ilog2(SRAM_GRANULARITY), in sram_add_pool()
61 NUMA_NO_NODE, block->label); in sram_add_pool()
62 if (IS_ERR(part->pool)) in sram_add_pool()
63 return PTR_ERR(part->pool); in sram_add_pool()
65 ret = gen_pool_add_virt(part->pool, (unsigned long)part->base, start, in sram_add_pool()
66 block->size, NUMA_NO_NODE); in sram_add_pool()
68 dev_err(sram->dev, "failed to register subpool: %d\n", ret); in sram_add_pool()
75 static int sram_add_export(struct sram_dev *sram, struct sram_reserve *block, in sram_add_export() argument
78 sysfs_bin_attr_init(&part->battr); in sram_add_export()
79 part->battr.attr.name = devm_kasprintf(sram->dev, GFP_KERNEL, in sram_add_export()
80 "%llx.sram", in sram_add_export()
82 if (!part->battr.attr.name) in sram_add_export()
83 return -ENOMEM; in sram_add_export()
85 part->battr.attr.mode = S_IRUSR | S_IWUSR; in sram_add_export()
86 part->battr.read = sram_read; in sram_add_export()
87 part->battr.write = sram_write; in sram_add_export()
88 part->battr.size = block->size; in sram_add_export()
90 return device_create_bin_file(sram->dev, &part->battr); in sram_add_export()
93 static int sram_add_partition(struct sram_dev *sram, struct sram_reserve *block, in sram_add_partition() argument
97 struct sram_partition *part = &sram->partition[sram->partitions]; in sram_add_partition()
99 mutex_init(&part->lock); in sram_add_partition()
101 if (sram->config && sram->config->map_only_reserved) { in sram_add_partition()
104 if (sram->no_memory_wc) in sram_add_partition()
105 virt_base = devm_ioremap_resource(sram->dev, &block->res); in sram_add_partition()
107 virt_base = devm_ioremap_resource_wc(sram->dev, &block->res); in sram_add_partition()
110 dev_err(sram->dev, "could not map SRAM at %pr\n", &block->res); in sram_add_partition()
114 part->base = virt_base; in sram_add_partition()
116 part->base = sram->virt_base + block->start; in sram_add_partition()
119 if (block->pool) { in sram_add_partition()
120 ret = sram_add_pool(sram, block, start, part); in sram_add_partition()
124 if (block->export) { in sram_add_partition()
125 ret = sram_add_export(sram, block, start, part); in sram_add_partition()
129 if (block->protect_exec) { in sram_add_partition()
130 ret = sram_check_protect_exec(sram, block, part); in sram_add_partition()
134 ret = sram_add_pool(sram, block, start, part); in sram_add_partition()
141 sram->partitions++; in sram_add_partition()
146 static void sram_free_partitions(struct sram_dev *sram) in sram_free_partitions() argument
150 if (!sram->partitions) in sram_free_partitions()
153 part = &sram->partition[sram->partitions - 1]; in sram_free_partitions()
154 for (; sram->partitions; sram->partitions--, part--) { in sram_free_partitions()
155 if (part->battr.size) in sram_free_partitions()
156 device_remove_bin_file(sram->dev, &part->battr); in sram_free_partitions()
158 if (part->pool && in sram_free_partitions()
159 gen_pool_avail(part->pool) < gen_pool_size(part->pool)) in sram_free_partitions()
160 dev_err(sram->dev, "removed pool while SRAM allocated\n"); in sram_free_partitions()
170 return ra->start - rb->start; in sram_reserve_cmp()
173 static int sram_reserve_regions(struct sram_dev *sram, struct resource *res) in sram_reserve_regions() argument
175 struct device_node *np = sram->dev->of_node, *child; in sram_reserve_regions()
194 return -ENOMEM; in sram_reserve_regions()
202 dev_err(sram->dev, in sram_reserve_regions()
208 if (child_res.start < res->start || child_res.end > res->end) { in sram_reserve_regions()
209 dev_err(sram->dev, in sram_reserve_regions()
210 "reserved block %pOF outside the sram area\n", in sram_reserve_regions()
212 ret = -EINVAL; in sram_reserve_regions()
216 block->start = child_res.start - res->start; in sram_reserve_regions()
217 block->size = resource_size(&child_res); in sram_reserve_regions()
218 block->res = child_res; in sram_reserve_regions()
219 list_add_tail(&block->list, &reserve_list); in sram_reserve_regions()
221 block->export = of_property_read_bool(child, "export"); in sram_reserve_regions()
222 block->pool = of_property_read_bool(child, "pool"); in sram_reserve_regions()
223 block->protect_exec = of_property_read_bool(child, "protect-exec"); in sram_reserve_regions()
225 if ((block->export || block->pool || block->protect_exec) && in sram_reserve_regions()
226 block->size) { in sram_reserve_regions()
231 if (ret && ret != -EINVAL) { in sram_reserve_regions()
232 dev_err(sram->dev, in sram_reserve_regions()
238 block->label = devm_kasprintf(sram->dev, GFP_KERNEL, in sram_reserve_regions()
241 block->label = devm_kstrdup(sram->dev, in sram_reserve_regions()
243 if (!block->label) { in sram_reserve_regions()
244 ret = -ENOMEM; in sram_reserve_regions()
248 dev_dbg(sram->dev, "found %sblock '%s' 0x%x-0x%x\n", in sram_reserve_regions()
249 block->export ? "exported " : "", block->label, in sram_reserve_regions()
250 block->start, block->start + block->size); in sram_reserve_regions()
252 dev_dbg(sram->dev, "found reserved block 0x%x-0x%x\n", in sram_reserve_regions()
253 block->start, block->start + block->size); in sram_reserve_regions()
261 rblocks[nblocks - 1].start = size; in sram_reserve_regions()
262 rblocks[nblocks - 1].size = 0; in sram_reserve_regions()
263 list_add_tail(&rblocks[nblocks - 1].list, &reserve_list); in sram_reserve_regions()
268 sram->partition = devm_kcalloc(sram->dev, in sram_reserve_regions()
269 exports, sizeof(*sram->partition), in sram_reserve_regions()
271 if (!sram->partition) { in sram_reserve_regions()
272 ret = -ENOMEM; in sram_reserve_regions()
280 if (block->start < cur_start) { in sram_reserve_regions()
281 dev_err(sram->dev, in sram_reserve_regions()
283 block->start, cur_start); in sram_reserve_regions()
284 ret = -EINVAL; in sram_reserve_regions()
285 sram_free_partitions(sram); in sram_reserve_regions()
289 if ((block->export || block->pool || block->protect_exec) && in sram_reserve_regions()
290 block->size) { in sram_reserve_regions()
291 ret = sram_add_partition(sram, block, in sram_reserve_regions()
292 res->start + block->start); in sram_reserve_regions()
294 sram_free_partitions(sram); in sram_reserve_regions()
300 if (block->start == cur_start) { in sram_reserve_regions()
301 cur_start = block->start + block->size; in sram_reserve_regions()
310 cur_size = block->start - cur_start; in sram_reserve_regions()
312 if (sram->pool) { in sram_reserve_regions()
313 dev_dbg(sram->dev, "adding chunk 0x%lx-0x%lx\n", in sram_reserve_regions()
316 ret = gen_pool_add_virt(sram->pool, in sram_reserve_regions()
317 (unsigned long)sram->virt_base + cur_start, in sram_reserve_regions()
318 res->start + cur_start, cur_size, -1); in sram_reserve_regions()
320 sram_free_partitions(sram); in sram_reserve_regions()
326 cur_start = block->start + block->size; in sram_reserve_regions()
341 regmap = syscon_regmap_lookup_by_compatible("atmel,sama5d2-secumod"); in atmel_securam_wait()
343 return -ENODEV; in atmel_securam_wait()
366 { .compatible = "mmio-sram" },
367 { .compatible = "atmel,sama5d2-securam", .data = &atmel_securam_config },
368 { .compatible = "nvidia,tegra186-sysram", .data = &tegra_sysram_config },
369 { .compatible = "nvidia,tegra194-sysram", .data = &tegra_sysram_config },
370 { .compatible = "nvidia,tegra234-sysram", .data = &tegra_sysram_config },
377 struct sram_dev *sram; in sram_probe() local
382 config = of_device_get_match_data(&pdev->dev); in sram_probe()
384 sram = devm_kzalloc(&pdev->dev, sizeof(*sram), GFP_KERNEL); in sram_probe()
385 if (!sram) in sram_probe()
386 return -ENOMEM; in sram_probe()
388 sram->dev = &pdev->dev; in sram_probe()
389 sram->no_memory_wc = of_property_read_bool(pdev->dev.of_node, "no-memory-wc"); in sram_probe()
390 sram->config = config; in sram_probe()
392 if (!config || !config->map_only_reserved) { in sram_probe()
394 if (sram->no_memory_wc) in sram_probe()
395 sram->virt_base = devm_ioremap_resource(&pdev->dev, res); in sram_probe()
397 sram->virt_base = devm_ioremap_resource_wc(&pdev->dev, res); in sram_probe()
398 if (IS_ERR(sram->virt_base)) { in sram_probe()
399 dev_err(&pdev->dev, "could not map SRAM registers\n"); in sram_probe()
400 return PTR_ERR(sram->virt_base); in sram_probe()
403 sram->pool = devm_gen_pool_create(sram->dev, ilog2(SRAM_GRANULARITY), in sram_probe()
405 if (IS_ERR(sram->pool)) in sram_probe()
406 return PTR_ERR(sram->pool); in sram_probe()
409 clk = devm_clk_get_optional_enabled(sram->dev, NULL); in sram_probe()
413 ret = sram_reserve_regions(sram, in sram_probe()
418 platform_set_drvdata(pdev, sram); in sram_probe()
420 if (config && config->init) { in sram_probe()
421 ret = config->init(); in sram_probe()
426 if (sram->pool) in sram_probe()
427 dev_dbg(sram->dev, "SRAM pool: %zu KiB @ 0x%p\n", in sram_probe()
428 gen_pool_size(sram->pool) / 1024, sram->virt_base); in sram_probe()
433 sram_free_partitions(sram); in sram_probe()
440 struct sram_dev *sram = platform_get_drvdata(pdev); in sram_remove() local
442 sram_free_partitions(sram); in sram_remove()
444 if (sram->pool && gen_pool_avail(sram->pool) < gen_pool_size(sram->pool)) in sram_remove()
445 dev_err(sram->dev, "removed while SRAM allocated\n"); in sram_remove()
450 .name = "sram",