Lines Matching +full:protect +full:- +full:exec
2 * Generic on-chip SRAM allocation driver
18 * MA 02110-1301, USA.
32 #include <soc/at91/atmel-secumod.h>
46 mutex_lock(&part->lock); in sram_read()
47 memcpy_fromio(buf, part->base + pos, count); in sram_read()
48 mutex_unlock(&part->lock); in sram_read()
61 mutex_lock(&part->lock); in sram_write()
62 memcpy_toio(part->base + pos, buf, count); in sram_write()
63 mutex_unlock(&part->lock); in sram_write()
73 part->pool = devm_gen_pool_create(sram->dev, ilog2(SRAM_GRANULARITY), in sram_add_pool()
74 NUMA_NO_NODE, block->label); in sram_add_pool()
75 if (IS_ERR(part->pool)) in sram_add_pool()
76 return PTR_ERR(part->pool); in sram_add_pool()
78 ret = gen_pool_add_virt(part->pool, (unsigned long)part->base, start, in sram_add_pool()
79 block->size, NUMA_NO_NODE); in sram_add_pool()
81 dev_err(sram->dev, "failed to register subpool: %d\n", ret); in sram_add_pool()
91 sysfs_bin_attr_init(&part->battr); in sram_add_export()
92 part->battr.attr.name = devm_kasprintf(sram->dev, GFP_KERNEL, in sram_add_export()
95 if (!part->battr.attr.name) in sram_add_export()
96 return -ENOMEM; in sram_add_export()
98 part->battr.attr.mode = S_IRUSR | S_IWUSR; in sram_add_export()
99 part->battr.read = sram_read; in sram_add_export()
100 part->battr.write = sram_write; in sram_add_export()
101 part->battr.size = block->size; in sram_add_export()
103 return device_create_bin_file(sram->dev, &part->battr); in sram_add_export()
110 struct sram_partition *part = &sram->partition[sram->partitions]; in sram_add_partition()
112 mutex_init(&part->lock); in sram_add_partition()
113 part->base = sram->virt_base + block->start; in sram_add_partition()
115 if (block->pool) { in sram_add_partition()
120 if (block->export) { in sram_add_partition()
125 if (block->protect_exec) { in sram_add_partition()
137 sram->partitions++; in sram_add_partition()
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()
151 if (part->battr.size) in sram_free_partitions()
152 device_remove_bin_file(sram->dev, &part->battr); in sram_free_partitions()
154 if (part->pool && in sram_free_partitions()
155 gen_pool_avail(part->pool) < gen_pool_size(part->pool)) in sram_free_partitions()
156 dev_err(sram->dev, "removed pool while SRAM allocated\n"); in sram_free_partitions()
166 return ra->start - rb->start; in sram_reserve_cmp()
171 struct device_node *np = sram->dev->of_node, *child; in sram_reserve_regions()
190 return -ENOMEM; in sram_reserve_regions()
198 dev_err(sram->dev, in sram_reserve_regions()
204 if (child_res.start < res->start || child_res.end > res->end) { in sram_reserve_regions()
205 dev_err(sram->dev, in sram_reserve_regions()
208 ret = -EINVAL; in sram_reserve_regions()
212 block->start = child_res.start - res->start; in sram_reserve_regions()
213 block->size = resource_size(&child_res); in sram_reserve_regions()
214 list_add_tail(&block->list, &reserve_list); in sram_reserve_regions()
217 block->export = true; in sram_reserve_regions()
220 block->pool = true; in sram_reserve_regions()
222 if (of_find_property(child, "protect-exec", NULL)) in sram_reserve_regions()
223 block->protect_exec = true; 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 label = child->name; in sram_reserve_regions()
240 block->label = devm_kstrdup(sram->dev, in sram_reserve_regions()
242 if (!block->label) { in sram_reserve_regions()
243 ret = -ENOMEM; in sram_reserve_regions()
247 dev_dbg(sram->dev, "found %sblock '%s' 0x%x-0x%x\n", in sram_reserve_regions()
248 block->export ? "exported " : "", block->label, in sram_reserve_regions()
249 block->start, block->start + block->size); in sram_reserve_regions()
251 dev_dbg(sram->dev, "found reserved block 0x%x-0x%x\n", in sram_reserve_regions()
252 block->start, block->start + block->size); in sram_reserve_regions()
260 rblocks[nblocks - 1].start = size; in sram_reserve_regions()
261 rblocks[nblocks - 1].size = 0; in sram_reserve_regions()
262 list_add_tail(&rblocks[nblocks - 1].list, &reserve_list); 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()
271 ret = -ENOMEM; in sram_reserve_regions()
279 if (block->start < cur_start) { in sram_reserve_regions()
280 dev_err(sram->dev, in sram_reserve_regions()
282 block->start, cur_start); in sram_reserve_regions()
283 ret = -EINVAL; in sram_reserve_regions()
288 if ((block->export || block->pool || block->protect_exec) && in sram_reserve_regions()
289 block->size) { in sram_reserve_regions()
291 res->start + block->start); in sram_reserve_regions()
299 if (block->start == cur_start) { in sram_reserve_regions()
300 cur_start = block->start + block->size; in sram_reserve_regions()
309 cur_size = block->start - cur_start; 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()
316 res->start + cur_start, cur_size, -1); in sram_reserve_regions()
323 cur_start = block->start + block->size; in sram_reserve_regions()
340 regmap = syscon_regmap_lookup_by_compatible("atmel,sama5d2-secumod"); in atmel_securam_wait()
342 return -ENODEV; in atmel_securam_wait()
350 { .compatible = "mmio-sram" },
351 { .compatible = "atmel,sama5d2-securam", .data = atmel_securam_wait },
363 sram = devm_kzalloc(&pdev->dev, sizeof(*sram), GFP_KERNEL); in sram_probe()
365 return -ENOMEM; in sram_probe()
367 sram->dev = &pdev->dev; in sram_probe()
371 dev_err(sram->dev, "found no memory resource\n"); in sram_probe()
372 return -EINVAL; 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()
379 return -EBUSY; in sram_probe()
382 if (of_property_read_bool(pdev->dev.of_node, "no-memory-wc")) 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()
387 return -ENOMEM; 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()
406 init_func = of_device_get_match_data(&pdev->dev); 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()
421 if (sram->clk) in sram_probe()
422 clk_disable_unprepare(sram->clk); in sram_probe()
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()