Lines Matching +full:iommu +full:- +full:map

1 // SPDX-License-Identifier: GPL-2.0
9 #include <linux/dma-direct.h> /* for bus_dma_region */
10 #include <linux/dma-map-ops.h>
21 * of_match_device - Tell if a struct device matches an of_device_id list
31 if (!matches || !dev->of_node || dev->of_node_reused) in of_match_device()
33 return of_match_node(matches, dev->of_node); in of_match_device()
39 BUG_ON(ofdev->dev.of_node == NULL); in of_device_add()
43 ofdev->name = dev_name(&ofdev->dev); in of_device_add()
44 ofdev->id = PLATFORM_DEVID_NONE; in of_device_add()
51 set_dev_node(&ofdev->dev, of_node_to_nid(ofdev->dev.of_node)); in of_device_add()
53 return device_add(&ofdev->dev); in of_device_add()
59 struct device_node *node, *of_node = dev->of_node; in of_dma_set_restricted_buffer()
65 count = of_property_count_elems_of_size(of_node, "memory-region", in of_dma_set_restricted_buffer()
68 * If dev->of_node doesn't exist or doesn't contain memory-region, try in of_dma_set_restricted_buffer()
74 of_node, "memory-region", sizeof(u32)); in of_dma_set_restricted_buffer()
78 node = of_parse_phandle(of_node, "memory-region", i); in of_dma_set_restricted_buffer()
81 * restricted-dma-pool region is allowed. in of_dma_set_restricted_buffer()
83 if (of_device_is_compatible(node, "restricted-dma-pool") && in of_dma_set_restricted_buffer()
92 * Attempt to initialize a restricted-dma-pool region if one was found. in of_dma_set_restricted_buffer()
96 dev_warn(dev, "failed to initialise \"restricted-dma-pool\" memory node\n"); in of_dma_set_restricted_buffer()
100 * of_dma_configure_id - Setup DMA configuration
117 const struct iommu_ops *iommu; in of_dma_configure_id() local
118 const struct bus_dma_region *map = NULL; in of_dma_configure_id() local
125 if (np == dev->of_node) in of_dma_configure_id()
130 ret = of_dma_get_range(bus_np, &map); in of_dma_configure_id()
135 * DMA configuration regardless of whether "dma-ranges" is in of_dma_configure_id()
139 return ret == -ENODEV ? 0 : ret; in of_dma_configure_id()
141 const struct bus_dma_region *r = map; in of_dma_configure_id()
145 for (dma_start = ~0; r->size; r++) { in of_dma_configure_id()
147 if (r->dma_start < dma_start) in of_dma_configure_id()
148 dma_start = r->dma_start; in of_dma_configure_id()
149 if (r->dma_start + r->size > dma_end) in of_dma_configure_id()
150 dma_end = r->dma_start + r->size; in of_dma_configure_id()
152 size = dma_end - dma_start; in of_dma_configure_id()
159 dev_warn(dev, "Invalid size 0x%llx for dma-range(s)\n", in of_dma_configure_id()
166 kfree(map); in of_dma_configure_id()
167 return -EINVAL; in of_dma_configure_id()
172 * If @dev is expected to be DMA-capable then the bus code that created in of_dma_configure_id()
177 if (!dev->dma_mask) { in of_dma_configure_id()
179 dev->dma_mask = &dev->coherent_dma_mask; in of_dma_configure_id()
182 if (!size && dev->coherent_dma_mask) in of_dma_configure_id()
183 size = max(dev->coherent_dma_mask, dev->coherent_dma_mask + 1); in of_dma_configure_id()
191 end = dma_start + size - 1; in of_dma_configure_id()
193 dev->coherent_dma_mask &= mask; in of_dma_configure_id()
194 *dev->dma_mask &= mask; in of_dma_configure_id()
195 /* ...but only set bus limit and range map if we found valid dma-ranges earlier */ in of_dma_configure_id()
197 dev->bus_dma_limit = end; in of_dma_configure_id()
198 dev->dma_range_map = map; in of_dma_configure_id()
205 iommu = of_iommu_configure(dev, np, id); in of_dma_configure_id()
206 if (PTR_ERR(iommu) == -EPROBE_DEFER) { in of_dma_configure_id()
207 /* Don't touch range map if it wasn't set from a valid dma-ranges */ in of_dma_configure_id()
209 dev->dma_range_map = NULL; in of_dma_configure_id()
210 kfree(map); in of_dma_configure_id()
211 return -EPROBE_DEFER; in of_dma_configure_id()
214 dev_dbg(dev, "device is%sbehind an iommu\n", in of_dma_configure_id()
215 iommu ? " " : " not "); in of_dma_configure_id()
217 arch_setup_dma_ops(dev, dma_start, size, iommu, coherent); in of_dma_configure_id()
219 if (!iommu) in of_dma_configure_id()
228 device_initialize(&pdev->dev); in of_device_register()
235 device_unregister(&ofdev->dev); in of_device_unregister()
243 match = of_match_device(dev->driver->of_match_table, dev); in of_device_get_match_data()
247 return match->data; in of_device_get_match_data()
259 if ((!dev) || (!dev->of_node)) in of_device_get_modalias()
260 return -ENODEV; in of_device_get_modalias()
264 csize = snprintf(str, len, "of:N%pOFn%c%s", dev->of_node, 'T', in of_device_get_modalias()
265 of_node_get_device_type(dev->of_node)); in of_device_get_modalias()
267 len -= csize; in of_device_get_modalias()
271 of_property_for_each_string(dev->of_node, "compatible", p, compat) { in of_device_get_modalias()
283 len -= csize; in of_device_get_modalias()
302 return -ENOMEM; in of_device_request_module()
314 * of_device_modalias - Fill buffer with newline terminated modalias string
321 ssize_t sl = of_device_get_modalias(dev, str, len - 2); in of_device_modalias()
324 if (sl > len - 2) in of_device_modalias()
325 return -ENOMEM; in of_device_modalias()
334 * of_device_uevent - Display OF related uevent information
345 if ((!dev) || (!dev->of_node)) in of_device_uevent()
348 add_uevent_var(env, "OF_NAME=%pOFn", dev->of_node); in of_device_uevent()
349 add_uevent_var(env, "OF_FULLNAME=%pOF", dev->of_node); in of_device_uevent()
350 type = of_node_get_device_type(dev->of_node); in of_device_uevent()
357 of_property_for_each_string(dev->of_node, "compatible", p, compat) { in of_device_uevent()
366 if (dev->of_node == app->np) { in of_device_uevent()
368 app->alias); in of_device_uevent()
379 if ((!dev) || (!dev->of_node)) in of_device_uevent_modalias()
380 return -ENODEV; in of_device_uevent_modalias()
384 return -ENOMEM; in of_device_uevent_modalias()
386 sl = of_device_get_modalias(dev, &env->buf[env->buflen-1], in of_device_uevent_modalias()
387 sizeof(env->buf) - env->buflen); in of_device_uevent_modalias()
388 if (sl >= (sizeof(env->buf) - env->buflen)) in of_device_uevent_modalias()
389 return -ENOMEM; in of_device_uevent_modalias()
390 env->buflen += sl; in of_device_uevent_modalias()