Lines Matching +full:reserved +full:- +full:memory

1 // SPDX-License-Identifier: GPL-2.0+
3 * Device tree based initialization code for reserved memory.
5 * Copyright (c) 2013, 2015 The Linux Foundation. All Rights Reserved.
12 #define pr_fmt(fmt) "OF: reserved mem: " fmt
44 return -ENOMEM; in early_init_dt_alloc_reserved_memory_arch()
58 * fdt_reserved_mem_save_node() - save fdt node for second pass initialization
70 rmem->fdt_node = node; in fdt_reserved_mem_save_node()
71 rmem->name = uname; in fdt_reserved_mem_save_node()
72 rmem->base = base; in fdt_reserved_mem_save_node()
73 rmem->size = size; in fdt_reserved_mem_save_node()
80 * __reserved_mem_alloc_size() - allocate reserved memory described by
81 * 'size', 'alignment' and 'alloc-ranges' properties.
96 return -EINVAL; in __reserved_mem_alloc_size()
100 return -EINVAL; in __reserved_mem_alloc_size()
109 return -EINVAL; in __reserved_mem_alloc_size()
114 nomap = of_get_flat_dt_prop(node, "no-map", NULL) != NULL; in __reserved_mem_alloc_size()
118 && of_flat_dt_is_compatible(node, "shared-dma-pool") in __reserved_mem_alloc_size()
123 prop = of_get_flat_dt_prop(node, "alloc-ranges", &len); in __reserved_mem_alloc_size()
127 pr_err("invalid alloc-ranges property in '%s', skipping node.\n", in __reserved_mem_alloc_size()
129 return -EINVAL; in __reserved_mem_alloc_size()
142 pr_debug("allocated memory for '%s' node: base %pa, size %lu MiB\n", in __reserved_mem_alloc_size()
147 len -= t_len; in __reserved_mem_alloc_size()
154 pr_debug("allocated memory for '%s' node: base %pa, size %lu MiB\n", in __reserved_mem_alloc_size()
159 pr_err("failed to allocate memory for node '%s': size %lu MiB\n", in __reserved_mem_alloc_size()
161 return -ENOMEM; in __reserved_mem_alloc_size()
174 * __reserved_mem_init_node() - call region specific reserved memory init code
180 int ret = -ENOENT; in __reserved_mem_init_node()
183 reservedmem_of_init_fn initfn = i->data; in __reserved_mem_init_node()
184 const char *compat = i->compatible; in __reserved_mem_init_node()
186 if (!of_flat_dt_is_compatible(rmem->fdt_node, compat)) in __reserved_mem_init_node()
192 rmem->name, compat); in __reserved_mem_init_node()
203 if (ra->base < rb->base) in __rmem_cmp()
204 return -1; in __rmem_cmp()
206 if (ra->base > rb->base) in __rmem_cmp()
214 if (ra->size < rb->size) in __rmem_cmp()
215 return -1; in __rmem_cmp()
216 if (ra->size > rb->size) in __rmem_cmp()
231 for (i = 0; i < reserved_mem_count - 1; i++) { in __rmem_check_for_overlap()
237 if (this->base + this->size > next->base) { in __rmem_check_for_overlap()
240 this_end = this->base + this->size; in __rmem_check_for_overlap()
241 next_end = next->base + next->size; in __rmem_check_for_overlap()
242 pr_err("OVERLAP DETECTED!\n%s (%pa--%pa) overlaps with %s (%pa--%pa)\n", in __rmem_check_for_overlap()
243 this->name, &this->base, &this_end, in __rmem_check_for_overlap()
244 next->name, &next->base, &next_end); in __rmem_check_for_overlap()
250 * fdt_init_reserved_mem() - allocate and init all saved reserved memory regions
256 /* check for overlapping reserved regions */ in fdt_init_reserved_mem()
261 unsigned long node = rmem->fdt_node; in fdt_init_reserved_mem()
267 nomap = of_get_flat_dt_prop(node, "no-map", NULL) != NULL; in fdt_init_reserved_mem()
272 rmem->phandle = of_read_number(prop, len/4); in fdt_init_reserved_mem()
274 if (rmem->size == 0) in fdt_init_reserved_mem()
275 err = __reserved_mem_alloc_size(node, rmem->name, in fdt_init_reserved_mem()
276 &rmem->base, &rmem->size); in fdt_init_reserved_mem()
279 if (err != 0 && err != -ENOENT) { in fdt_init_reserved_mem()
281 rmem->name); in fdt_init_reserved_mem()
283 memblock_clear_nomap(rmem->base, rmem->size); in fdt_init_reserved_mem()
285 memblock_phys_free(rmem->base, in fdt_init_reserved_mem()
286 rmem->size); in fdt_init_reserved_mem()
296 if (!node->phandle) in __find_rmem()
300 if (reserved_mem[i].phandle == node->phandle) in __find_rmem()
315 * of_reserved_mem_device_init_by_idx() - assign reserved memory region to
318 * @np: Pointer to the device_node with 'reserved-memory' property
321 * This function assigns respective DMA-mapping operations based on reserved
322 * memory region specified by 'memory-region' property in @np node to the @dev
323 * device. When driver needs to use more than one reserved memory region, it
338 return -EINVAL; in of_reserved_mem_device_init_by_idx()
340 target = of_parse_phandle(np, "memory-region", idx); in of_reserved_mem_device_init_by_idx()
342 return -ENODEV; in of_reserved_mem_device_init_by_idx()
352 if (!rmem || !rmem->ops || !rmem->ops->device_init) in of_reserved_mem_device_init_by_idx()
353 return -EINVAL; in of_reserved_mem_device_init_by_idx()
357 return -ENOMEM; in of_reserved_mem_device_init_by_idx()
359 ret = rmem->ops->device_init(rmem, dev); in of_reserved_mem_device_init_by_idx()
361 rd->dev = dev; in of_reserved_mem_device_init_by_idx()
362 rd->rmem = rmem; in of_reserved_mem_device_init_by_idx()
365 list_add(&rd->list, &of_rmem_assigned_device_list); in of_reserved_mem_device_init_by_idx()
368 dev_info(dev, "assigned reserved memory node %s\n", rmem->name); in of_reserved_mem_device_init_by_idx()
378 * of_reserved_mem_device_init_by_name() - assign named reserved memory region
381 * @np: pointer to the device node with 'memory-region' property
382 * @name: name of the selected memory region
384 * Returns: 0 on success or a negative error-code on failure.
390 int idx = of_property_match_string(np, "memory-region-names", name); in of_reserved_mem_device_init_by_name()
397 * of_reserved_mem_device_release() - release reserved memory device structures
400 * This function releases structures allocated for memory region handling for
410 if (rd->dev == dev) in of_reserved_mem_device_release()
411 list_move_tail(&rd->list, &release_list); in of_reserved_mem_device_release()
416 if (rd->rmem && rd->rmem->ops && rd->rmem->ops->device_release) in of_reserved_mem_device_release()
417 rd->rmem->ops->device_release(rd->rmem, dev); in of_reserved_mem_device_release()
425 * of_reserved_mem_lookup() - acquire reserved_mem from a device node
426 * @np: node pointer of the desired reserved-memory region
438 if (!np->full_name) in of_reserved_mem_lookup()
441 name = kbasename(np->full_name); in of_reserved_mem_lookup()