Lines Matching +full:iommu +full:- +full:map
1 // SPDX-License-Identifier: GPL-2.0
8 #include <linux/dma-direct.h> /* for bus_dma_region */
9 #include <linux/dma-map-ops.h>
19 * of_match_device - Tell if a struct device matches an of_device_id list
29 if (!matches || !dev->of_node || dev->of_node_reused) in of_match_device()
31 return of_match_node(matches, dev->of_node); in of_match_device()
38 struct device_node *node, *of_node = dev->of_node; in of_dma_set_restricted_buffer()
44 count = of_property_count_elems_of_size(of_node, "memory-region", in of_dma_set_restricted_buffer()
47 * If dev->of_node doesn't exist or doesn't contain memory-region, try in of_dma_set_restricted_buffer()
53 of_node, "memory-region", sizeof(u32)); in of_dma_set_restricted_buffer()
57 node = of_parse_phandle(of_node, "memory-region", i); in of_dma_set_restricted_buffer()
60 * restricted-dma-pool region is allowed. in of_dma_set_restricted_buffer()
62 if (of_device_is_compatible(node, "restricted-dma-pool") && in of_dma_set_restricted_buffer()
71 * Attempt to initialize a restricted-dma-pool region if one was found. in of_dma_set_restricted_buffer()
75 dev_warn(dev, "failed to initialise \"restricted-dma-pool\" memory node\n"); in of_dma_set_restricted_buffer()
79 * of_dma_configure_id - Setup DMA configuration
96 const struct iommu_ops *iommu; in of_dma_configure_id() local
97 const struct bus_dma_region *map = NULL; in of_dma_configure_id() local
104 if (np == dev->of_node) in of_dma_configure_id()
109 ret = of_dma_get_range(bus_np, &map); in of_dma_configure_id()
114 * DMA configuration regardless of whether "dma-ranges" is in of_dma_configure_id()
118 return ret == -ENODEV ? 0 : ret; in of_dma_configure_id()
120 const struct bus_dma_region *r = map; in of_dma_configure_id()
124 for (dma_start = ~0; r->size; r++) { in of_dma_configure_id()
126 if (r->dma_start < dma_start) in of_dma_configure_id()
127 dma_start = r->dma_start; in of_dma_configure_id()
128 if (r->dma_start + r->size > dma_end) in of_dma_configure_id()
129 dma_end = r->dma_start + r->size; in of_dma_configure_id()
131 size = dma_end - dma_start; in of_dma_configure_id()
138 dev_warn(dev, "Invalid size 0x%llx for dma-range(s)\n", in of_dma_configure_id()
145 kfree(map); in of_dma_configure_id()
146 return -EINVAL; in of_dma_configure_id()
151 * If @dev is expected to be DMA-capable then the bus code that created in of_dma_configure_id()
156 if (!dev->dma_mask) { in of_dma_configure_id()
158 dev->dma_mask = &dev->coherent_dma_mask; in of_dma_configure_id()
161 if (!size && dev->coherent_dma_mask) in of_dma_configure_id()
162 size = max(dev->coherent_dma_mask, dev->coherent_dma_mask + 1); in of_dma_configure_id()
170 end = dma_start + size - 1; in of_dma_configure_id()
172 dev->coherent_dma_mask &= mask; in of_dma_configure_id()
173 *dev->dma_mask &= mask; in of_dma_configure_id()
174 /* ...but only set bus limit and range map if we found valid dma-ranges earlier */ in of_dma_configure_id()
176 dev->bus_dma_limit = end; in of_dma_configure_id()
177 dev->dma_range_map = map; in of_dma_configure_id()
184 iommu = of_iommu_configure(dev, np, id); in of_dma_configure_id()
185 if (PTR_ERR(iommu) == -EPROBE_DEFER) { in of_dma_configure_id()
186 /* Don't touch range map if it wasn't set from a valid dma-ranges */ in of_dma_configure_id()
188 dev->dma_range_map = NULL; in of_dma_configure_id()
189 kfree(map); in of_dma_configure_id()
190 return -EPROBE_DEFER; in of_dma_configure_id()
193 dev_dbg(dev, "device is%sbehind an iommu\n", in of_dma_configure_id()
194 iommu ? " " : " not "); in of_dma_configure_id()
196 arch_setup_dma_ops(dev, dma_start, size, iommu, coherent); in of_dma_configure_id()
198 if (!iommu) in of_dma_configure_id()
209 match = of_match_device(dev->driver->of_match_table, dev); in of_device_get_match_data()
213 return match->data; in of_device_get_match_data()
218 * of_device_modalias - Fill buffer with newline terminated modalias string
227 if (!dev || !dev->of_node || dev->of_node_reused) in of_device_modalias()
228 return -ENODEV; in of_device_modalias()
230 sl = of_modalias(dev->of_node, str, len - 2); in of_device_modalias()
233 if (sl > len - 2) in of_device_modalias()
234 return -ENOMEM; in of_device_modalias()
243 * of_device_uevent - Display OF related uevent information
254 if ((!dev) || (!dev->of_node)) in of_device_uevent()
257 add_uevent_var(env, "OF_NAME=%pOFn", dev->of_node); in of_device_uevent()
258 add_uevent_var(env, "OF_FULLNAME=%pOF", dev->of_node); in of_device_uevent()
259 type = of_node_get_device_type(dev->of_node); in of_device_uevent()
266 of_property_for_each_string(dev->of_node, "compatible", p, compat) { in of_device_uevent()
275 if (dev->of_node == app->np) { in of_device_uevent()
277 app->alias); in of_device_uevent()
289 if ((!dev) || (!dev->of_node) || dev->of_node_reused) in of_device_uevent_modalias()
290 return -ENODEV; in of_device_uevent_modalias()
294 return -ENOMEM; in of_device_uevent_modalias()
296 sl = of_modalias(dev->of_node, &env->buf[env->buflen-1], in of_device_uevent_modalias()
297 sizeof(env->buf) - env->buflen); in of_device_uevent_modalias()
300 if (sl >= (sizeof(env->buf) - env->buflen)) in of_device_uevent_modalias()
301 return -ENOMEM; in of_device_uevent_modalias()
302 env->buflen += sl; in of_device_uevent_modalias()