Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Device tree based initialization code for reserved memory. |
| 3 | * |
Liam Mark | 6b6b749 | 2017-04-13 17:11:54 -0700 | [diff] [blame] | 4 | * Copyright (c) 2013, 2015, 2017 The Linux Foundation. All Rights Reserved. |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 5 | * Copyright (c) 2013,2014 Samsung Electronics Co., Ltd. |
| 6 | * http://www.samsung.com |
| 7 | * Author: Marek Szyprowski <m.szyprowski@samsung.com> |
| 8 | * Author: Josh Cartwright <joshc@codeaurora.org> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of the |
| 13 | * License or (at your optional) any later version of the license. |
| 14 | */ |
| 15 | |
Rob Herring | 606ad42 | 2016-06-15 08:32:18 -0500 | [diff] [blame] | 16 | #define pr_fmt(fmt) "OF: reserved mem: " fmt |
| 17 | |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 18 | #include <linux/err.h> |
| 19 | #include <linux/of.h> |
| 20 | #include <linux/of_fdt.h> |
| 21 | #include <linux/of_platform.h> |
| 22 | #include <linux/mm.h> |
| 23 | #include <linux/sizes.h> |
| 24 | #include <linux/of_reserved_mem.h> |
Mitchel Humpherys | ae1add2 | 2015-09-15 18:30:36 -0700 | [diff] [blame] | 25 | #include <linux/sort.h> |
Marek Szyprowski | 59ce403 | 2016-05-24 15:31:24 +0200 | [diff] [blame] | 26 | #include <linux/slab.h> |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 27 | |
Liam Mark | 6b6b749 | 2017-04-13 17:11:54 -0700 | [diff] [blame] | 28 | #define MAX_RESERVED_REGIONS 32 |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 29 | static struct reserved_mem reserved_mem[MAX_RESERVED_REGIONS]; |
| 30 | static int reserved_mem_count; |
| 31 | |
| 32 | #if defined(CONFIG_HAVE_MEMBLOCK) |
| 33 | #include <linux/memblock.h> |
| 34 | int __init __weak early_init_dt_alloc_reserved_memory_arch(phys_addr_t size, |
| 35 | phys_addr_t align, phys_addr_t start, phys_addr_t end, bool nomap, |
| 36 | phys_addr_t *res_base) |
| 37 | { |
Vinayak Menon | e53b50c | 2016-02-22 19:15:44 +0530 | [diff] [blame] | 38 | phys_addr_t base; |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 39 | /* |
| 40 | * We use __memblock_alloc_base() because memblock_alloc_base() |
| 41 | * panic()s on allocation failure. |
| 42 | */ |
Vinayak Menon | e53b50c | 2016-02-22 19:15:44 +0530 | [diff] [blame] | 43 | end = !end ? MEMBLOCK_ALLOC_ANYWHERE : end; |
| 44 | base = __memblock_alloc_base(size, align, end); |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 45 | if (!base) |
| 46 | return -ENOMEM; |
| 47 | |
| 48 | /* |
| 49 | * Check if the allocated region fits in to start..end window |
| 50 | */ |
| 51 | if (base < start) { |
| 52 | memblock_free(base, size); |
| 53 | return -ENOMEM; |
| 54 | } |
| 55 | |
| 56 | *res_base = base; |
| 57 | if (nomap) |
| 58 | return memblock_remove(base, size); |
| 59 | return 0; |
| 60 | } |
| 61 | #else |
| 62 | int __init __weak early_init_dt_alloc_reserved_memory_arch(phys_addr_t size, |
| 63 | phys_addr_t align, phys_addr_t start, phys_addr_t end, bool nomap, |
| 64 | phys_addr_t *res_base) |
| 65 | { |
| 66 | pr_err("Reserved memory not supported, ignoring region 0x%llx%s\n", |
| 67 | size, nomap ? " (nomap)" : ""); |
| 68 | return -ENOSYS; |
| 69 | } |
| 70 | #endif |
| 71 | |
| 72 | /** |
| 73 | * res_mem_save_node() - save fdt node for second pass initialization |
| 74 | */ |
| 75 | void __init fdt_reserved_mem_save_node(unsigned long node, const char *uname, |
| 76 | phys_addr_t base, phys_addr_t size) |
| 77 | { |
| 78 | struct reserved_mem *rmem = &reserved_mem[reserved_mem_count]; |
| 79 | |
| 80 | if (reserved_mem_count == ARRAY_SIZE(reserved_mem)) { |
Rob Herring | 606ad42 | 2016-06-15 08:32:18 -0500 | [diff] [blame] | 81 | pr_err("not enough space all defined regions.\n"); |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 82 | return; |
| 83 | } |
| 84 | |
| 85 | rmem->fdt_node = node; |
| 86 | rmem->name = uname; |
| 87 | rmem->base = base; |
| 88 | rmem->size = size; |
| 89 | |
| 90 | reserved_mem_count++; |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * res_mem_alloc_size() - allocate reserved memory described by 'size', 'align' |
| 96 | * and 'alloc-ranges' properties |
| 97 | */ |
| 98 | static int __init __reserved_mem_alloc_size(unsigned long node, |
| 99 | const char *uname, phys_addr_t *res_base, phys_addr_t *res_size) |
| 100 | { |
| 101 | int t_len = (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32); |
| 102 | phys_addr_t start = 0, end = 0; |
| 103 | phys_addr_t base = 0, align = 0, size; |
Rob Herring | 9d0c4df | 2014-04-01 23:49:03 -0500 | [diff] [blame] | 104 | int len; |
| 105 | const __be32 *prop; |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 106 | int nomap; |
| 107 | int ret; |
| 108 | |
| 109 | prop = of_get_flat_dt_prop(node, "size", &len); |
| 110 | if (!prop) |
| 111 | return -EINVAL; |
| 112 | |
| 113 | if (len != dt_root_size_cells * sizeof(__be32)) { |
Rob Herring | 606ad42 | 2016-06-15 08:32:18 -0500 | [diff] [blame] | 114 | pr_err("invalid size property in '%s' node.\n", uname); |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 115 | return -EINVAL; |
| 116 | } |
| 117 | size = dt_mem_next_cell(dt_root_size_cells, &prop); |
| 118 | |
| 119 | nomap = of_get_flat_dt_prop(node, "no-map", NULL) != NULL; |
| 120 | |
| 121 | prop = of_get_flat_dt_prop(node, "alignment", &len); |
| 122 | if (prop) { |
| 123 | if (len != dt_root_addr_cells * sizeof(__be32)) { |
Rob Herring | 606ad42 | 2016-06-15 08:32:18 -0500 | [diff] [blame] | 124 | pr_err("invalid alignment property in '%s' node.\n", |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 125 | uname); |
| 126 | return -EINVAL; |
| 127 | } |
| 128 | align = dt_mem_next_cell(dt_root_addr_cells, &prop); |
| 129 | } |
| 130 | |
Jason Liu | 1cc8e34 | 2015-11-10 20:30:26 +0800 | [diff] [blame] | 131 | /* Need adjust the alignment to satisfy the CMA requirement */ |
Jaewon | 7d48281 | 2016-05-25 13:29:50 +0900 | [diff] [blame] | 132 | if (IS_ENABLED(CONFIG_CMA) |
| 133 | && of_flat_dt_is_compatible(node, "shared-dma-pool") |
| 134 | && of_get_flat_dt_prop(node, "reusable", NULL) |
Stephen Rothwell | aaaab56 | 2016-05-31 09:38:56 +1000 | [diff] [blame] | 135 | && !of_get_flat_dt_prop(node, "no-map", NULL)) { |
| 136 | unsigned long order = |
| 137 | max_t(unsigned long, MAX_ORDER - 1, pageblock_order); |
| 138 | |
| 139 | align = max(align, (phys_addr_t)PAGE_SIZE << order); |
| 140 | } |
Jason Liu | 1cc8e34 | 2015-11-10 20:30:26 +0800 | [diff] [blame] | 141 | |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 142 | prop = of_get_flat_dt_prop(node, "alloc-ranges", &len); |
| 143 | if (prop) { |
| 144 | |
| 145 | if (len % t_len != 0) { |
Rob Herring | 606ad42 | 2016-06-15 08:32:18 -0500 | [diff] [blame] | 146 | pr_err("invalid alloc-ranges property in '%s', skipping node.\n", |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 147 | uname); |
| 148 | return -EINVAL; |
| 149 | } |
| 150 | |
| 151 | base = 0; |
| 152 | |
| 153 | while (len > 0) { |
| 154 | start = dt_mem_next_cell(dt_root_addr_cells, &prop); |
| 155 | end = start + dt_mem_next_cell(dt_root_size_cells, |
| 156 | &prop); |
| 157 | |
| 158 | ret = early_init_dt_alloc_reserved_memory_arch(size, |
| 159 | align, start, end, nomap, &base); |
| 160 | if (ret == 0) { |
Rob Herring | 606ad42 | 2016-06-15 08:32:18 -0500 | [diff] [blame] | 161 | pr_debug("allocated memory for '%s' node: base %pa, size %ld MiB\n", |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 162 | uname, &base, |
| 163 | (unsigned long)size / SZ_1M); |
| 164 | break; |
| 165 | } |
| 166 | len -= t_len; |
| 167 | } |
| 168 | |
| 169 | } else { |
| 170 | ret = early_init_dt_alloc_reserved_memory_arch(size, align, |
| 171 | 0, 0, nomap, &base); |
| 172 | if (ret == 0) |
Rob Herring | 606ad42 | 2016-06-15 08:32:18 -0500 | [diff] [blame] | 173 | pr_debug("allocated memory for '%s' node: base %pa, size %ld MiB\n", |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 174 | uname, &base, (unsigned long)size / SZ_1M); |
| 175 | } |
| 176 | |
| 177 | if (base == 0) { |
Rob Herring | 606ad42 | 2016-06-15 08:32:18 -0500 | [diff] [blame] | 178 | pr_info("failed to allocate memory for node '%s'\n", uname); |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 179 | return -ENOMEM; |
| 180 | } |
| 181 | |
| 182 | *res_base = base; |
| 183 | *res_size = size; |
| 184 | |
| 185 | return 0; |
| 186 | } |
| 187 | |
Marek Szyprowski | f618c47 | 2014-02-28 14:42:49 +0100 | [diff] [blame] | 188 | static const struct of_device_id __rmem_of_table_sentinel |
| 189 | __used __section(__reservedmem_of_table_end); |
| 190 | |
| 191 | /** |
| 192 | * res_mem_init_node() - call region specific reserved memory init code |
| 193 | */ |
| 194 | static int __init __reserved_mem_init_node(struct reserved_mem *rmem) |
| 195 | { |
| 196 | extern const struct of_device_id __reservedmem_of_table[]; |
| 197 | const struct of_device_id *i; |
| 198 | |
| 199 | for (i = __reservedmem_of_table; i < &__rmem_of_table_sentinel; i++) { |
| 200 | reservedmem_of_init_fn initfn = i->data; |
| 201 | const char *compat = i->compatible; |
| 202 | |
| 203 | if (!of_flat_dt_is_compatible(rmem->fdt_node, compat)) |
| 204 | continue; |
| 205 | |
Rob Herring | 9dd3107 | 2014-05-08 16:06:17 -0500 | [diff] [blame] | 206 | if (initfn(rmem) == 0) { |
Rob Herring | 606ad42 | 2016-06-15 08:32:18 -0500 | [diff] [blame] | 207 | pr_info("initialized node %s, compatible id %s\n", |
Marek Szyprowski | f618c47 | 2014-02-28 14:42:49 +0100 | [diff] [blame] | 208 | rmem->name, compat); |
| 209 | return 0; |
| 210 | } |
| 211 | } |
| 212 | return -ENOENT; |
| 213 | } |
| 214 | |
Mitchel Humpherys | ae1add2 | 2015-09-15 18:30:36 -0700 | [diff] [blame] | 215 | static int __init __rmem_cmp(const void *a, const void *b) |
| 216 | { |
| 217 | const struct reserved_mem *ra = a, *rb = b; |
| 218 | |
Michael Ellerman | 9eb8cd2 | 2015-11-18 21:46:38 +1100 | [diff] [blame] | 219 | if (ra->base < rb->base) |
| 220 | return -1; |
| 221 | |
| 222 | if (ra->base > rb->base) |
| 223 | return 1; |
| 224 | |
| 225 | return 0; |
Mitchel Humpherys | ae1add2 | 2015-09-15 18:30:36 -0700 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | static void __init __rmem_check_for_overlap(void) |
| 229 | { |
| 230 | int i; |
| 231 | |
| 232 | if (reserved_mem_count < 2) |
| 233 | return; |
| 234 | |
| 235 | sort(reserved_mem, reserved_mem_count, sizeof(reserved_mem[0]), |
| 236 | __rmem_cmp, NULL); |
| 237 | for (i = 0; i < reserved_mem_count - 1; i++) { |
| 238 | struct reserved_mem *this, *next; |
| 239 | |
| 240 | this = &reserved_mem[i]; |
| 241 | next = &reserved_mem[i + 1]; |
| 242 | if (!(this->base && next->base)) |
| 243 | continue; |
| 244 | if (this->base + this->size > next->base) { |
| 245 | phys_addr_t this_end, next_end; |
| 246 | |
| 247 | this_end = this->base + this->size; |
| 248 | next_end = next->base + next->size; |
Rob Herring | 606ad42 | 2016-06-15 08:32:18 -0500 | [diff] [blame] | 249 | pr_err("OVERLAP DETECTED!\n%s (%pa--%pa) overlaps with %s (%pa--%pa)\n", |
Michael Ellerman | 85a1c77 | 2015-11-10 16:08:33 +1100 | [diff] [blame] | 250 | this->name, &this->base, &this_end, |
| 251 | next->name, &next->base, &next_end); |
Mitchel Humpherys | ae1add2 | 2015-09-15 18:30:36 -0700 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | } |
| 255 | |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 256 | /** |
| 257 | * fdt_init_reserved_mem - allocate and init all saved reserved memory regions |
| 258 | */ |
| 259 | void __init fdt_init_reserved_mem(void) |
| 260 | { |
| 261 | int i; |
Mitchel Humpherys | ae1add2 | 2015-09-15 18:30:36 -0700 | [diff] [blame] | 262 | |
| 263 | /* check for overlapping reserved regions */ |
| 264 | __rmem_check_for_overlap(); |
| 265 | |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 266 | for (i = 0; i < reserved_mem_count; i++) { |
| 267 | struct reserved_mem *rmem = &reserved_mem[i]; |
| 268 | unsigned long node = rmem->fdt_node; |
Marek Szyprowski | 9dcfee0 | 2014-07-14 10:28:04 +0200 | [diff] [blame] | 269 | int len; |
| 270 | const __be32 *prop; |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 271 | int err = 0; |
| 272 | |
Marek Szyprowski | 9dcfee0 | 2014-07-14 10:28:04 +0200 | [diff] [blame] | 273 | prop = of_get_flat_dt_prop(node, "phandle", &len); |
| 274 | if (!prop) |
| 275 | prop = of_get_flat_dt_prop(node, "linux,phandle", &len); |
| 276 | if (prop) |
| 277 | rmem->phandle = of_read_number(prop, len/4); |
| 278 | |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 279 | if (rmem->size == 0) |
| 280 | err = __reserved_mem_alloc_size(node, rmem->name, |
| 281 | &rmem->base, &rmem->size); |
Marek Szyprowski | f618c47 | 2014-02-28 14:42:49 +0100 | [diff] [blame] | 282 | if (err == 0) |
| 283 | __reserved_mem_init_node(rmem); |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 284 | } |
| 285 | } |
Marek Szyprowski | 9dcfee0 | 2014-07-14 10:28:04 +0200 | [diff] [blame] | 286 | |
| 287 | static inline struct reserved_mem *__find_rmem(struct device_node *node) |
| 288 | { |
| 289 | unsigned int i; |
| 290 | |
| 291 | if (!node->phandle) |
| 292 | return NULL; |
| 293 | |
| 294 | for (i = 0; i < reserved_mem_count; i++) |
| 295 | if (reserved_mem[i].phandle == node->phandle) |
| 296 | return &reserved_mem[i]; |
| 297 | return NULL; |
| 298 | } |
| 299 | |
Marek Szyprowski | 59ce403 | 2016-05-24 15:31:24 +0200 | [diff] [blame] | 300 | struct rmem_assigned_device { |
| 301 | struct device *dev; |
Marek Szyprowski | 9dcfee0 | 2014-07-14 10:28:04 +0200 | [diff] [blame] | 302 | struct reserved_mem *rmem; |
Marek Szyprowski | 59ce403 | 2016-05-24 15:31:24 +0200 | [diff] [blame] | 303 | struct list_head list; |
| 304 | }; |
| 305 | |
| 306 | static LIST_HEAD(of_rmem_assigned_device_list); |
| 307 | static DEFINE_MUTEX(of_rmem_assigned_device_mutex); |
| 308 | |
| 309 | /** |
| 310 | * of_reserved_mem_device_init_by_idx() - assign reserved memory region to |
| 311 | * given device |
| 312 | * @dev: Pointer to the device to configure |
| 313 | * @np: Pointer to the device_node with 'reserved-memory' property |
| 314 | * @idx: Index of selected region |
| 315 | * |
| 316 | * This function assigns respective DMA-mapping operations based on reserved |
| 317 | * memory region specified by 'memory-region' property in @np node to the @dev |
| 318 | * device. When driver needs to use more than one reserved memory region, it |
| 319 | * should allocate child devices and initialize regions by name for each of |
| 320 | * child device. |
| 321 | * |
| 322 | * Returns error code or zero on success. |
| 323 | */ |
| 324 | int of_reserved_mem_device_init_by_idx(struct device *dev, |
| 325 | struct device_node *np, int idx) |
| 326 | { |
| 327 | struct rmem_assigned_device *rd; |
| 328 | struct device_node *target; |
| 329 | struct reserved_mem *rmem; |
Marek Szyprowski | 47f29df | 2014-10-29 14:50:29 -0700 | [diff] [blame] | 330 | int ret; |
Marek Szyprowski | 9dcfee0 | 2014-07-14 10:28:04 +0200 | [diff] [blame] | 331 | |
Marek Szyprowski | 59ce403 | 2016-05-24 15:31:24 +0200 | [diff] [blame] | 332 | if (!np || !dev) |
| 333 | return -EINVAL; |
Marek Szyprowski | 9dcfee0 | 2014-07-14 10:28:04 +0200 | [diff] [blame] | 334 | |
Marek Szyprowski | 59ce403 | 2016-05-24 15:31:24 +0200 | [diff] [blame] | 335 | target = of_parse_phandle(np, "memory-region", idx); |
| 336 | if (!target) |
Marek Szyprowski | 9f5a802 | 2016-06-08 03:51:53 -0300 | [diff] [blame] | 337 | return -ENODEV; |
Marek Szyprowski | 59ce403 | 2016-05-24 15:31:24 +0200 | [diff] [blame] | 338 | |
| 339 | rmem = __find_rmem(target); |
| 340 | of_node_put(target); |
Marek Szyprowski | 9dcfee0 | 2014-07-14 10:28:04 +0200 | [diff] [blame] | 341 | |
| 342 | if (!rmem || !rmem->ops || !rmem->ops->device_init) |
Marek Szyprowski | 47f29df | 2014-10-29 14:50:29 -0700 | [diff] [blame] | 343 | return -EINVAL; |
Marek Szyprowski | 9dcfee0 | 2014-07-14 10:28:04 +0200 | [diff] [blame] | 344 | |
Marek Szyprowski | 59ce403 | 2016-05-24 15:31:24 +0200 | [diff] [blame] | 345 | rd = kmalloc(sizeof(struct rmem_assigned_device), GFP_KERNEL); |
| 346 | if (!rd) |
| 347 | return -ENOMEM; |
| 348 | |
Marek Szyprowski | 47f29df | 2014-10-29 14:50:29 -0700 | [diff] [blame] | 349 | ret = rmem->ops->device_init(rmem, dev); |
Marek Szyprowski | 59ce403 | 2016-05-24 15:31:24 +0200 | [diff] [blame] | 350 | if (ret == 0) { |
| 351 | rd->dev = dev; |
| 352 | rd->rmem = rmem; |
| 353 | |
| 354 | mutex_lock(&of_rmem_assigned_device_mutex); |
| 355 | list_add(&rd->list, &of_rmem_assigned_device_list); |
| 356 | mutex_unlock(&of_rmem_assigned_device_mutex); |
| 357 | |
Marek Szyprowski | 47f29df | 2014-10-29 14:50:29 -0700 | [diff] [blame] | 358 | dev_info(dev, "assigned reserved memory node %s\n", rmem->name); |
Marek Szyprowski | 59ce403 | 2016-05-24 15:31:24 +0200 | [diff] [blame] | 359 | } else { |
| 360 | kfree(rd); |
| 361 | } |
Marek Szyprowski | 47f29df | 2014-10-29 14:50:29 -0700 | [diff] [blame] | 362 | |
| 363 | return ret; |
Marek Szyprowski | 9dcfee0 | 2014-07-14 10:28:04 +0200 | [diff] [blame] | 364 | } |
Marek Szyprowski | 59ce403 | 2016-05-24 15:31:24 +0200 | [diff] [blame] | 365 | EXPORT_SYMBOL_GPL(of_reserved_mem_device_init_by_idx); |
Marek Szyprowski | 9dcfee0 | 2014-07-14 10:28:04 +0200 | [diff] [blame] | 366 | |
| 367 | /** |
| 368 | * of_reserved_mem_device_release() - release reserved memory device structures |
Marek Szyprowski | 59ce403 | 2016-05-24 15:31:24 +0200 | [diff] [blame] | 369 | * @dev: Pointer to the device to deconfigure |
Marek Szyprowski | 9dcfee0 | 2014-07-14 10:28:04 +0200 | [diff] [blame] | 370 | * |
| 371 | * This function releases structures allocated for memory region handling for |
| 372 | * the given device. |
| 373 | */ |
| 374 | void of_reserved_mem_device_release(struct device *dev) |
| 375 | { |
Marek Szyprowski | 59ce403 | 2016-05-24 15:31:24 +0200 | [diff] [blame] | 376 | struct rmem_assigned_device *rd; |
| 377 | struct reserved_mem *rmem = NULL; |
Marek Szyprowski | 9dcfee0 | 2014-07-14 10:28:04 +0200 | [diff] [blame] | 378 | |
Marek Szyprowski | 59ce403 | 2016-05-24 15:31:24 +0200 | [diff] [blame] | 379 | mutex_lock(&of_rmem_assigned_device_mutex); |
| 380 | list_for_each_entry(rd, &of_rmem_assigned_device_list, list) { |
| 381 | if (rd->dev == dev) { |
| 382 | rmem = rd->rmem; |
| 383 | list_del(&rd->list); |
| 384 | kfree(rd); |
| 385 | break; |
| 386 | } |
| 387 | } |
| 388 | mutex_unlock(&of_rmem_assigned_device_mutex); |
Marek Szyprowski | 9dcfee0 | 2014-07-14 10:28:04 +0200 | [diff] [blame] | 389 | |
| 390 | if (!rmem || !rmem->ops || !rmem->ops->device_release) |
| 391 | return; |
| 392 | |
| 393 | rmem->ops->device_release(rmem, dev); |
| 394 | } |
George G. Davis | 615fde7 | 2015-01-09 09:29:05 -0500 | [diff] [blame] | 395 | EXPORT_SYMBOL_GPL(of_reserved_mem_device_release); |