Lines Matching +full:iommu +full:- +full:map +full:- +full:mask
1 // SPDX-License-Identifier: GPL-2.0
8 #include <linux/dma-direct.h> /* for bus_dma_region */
9 #include <linux/dma-map-ops.h>
20 * of_match_device - Tell if a struct device matches an of_device_id list
30 if ((!matches) || (!dev->of_node)) in of_match_device()
32 return of_match_node(matches, dev->of_node); in of_match_device()
42 tmp = get_device(&dev->dev); in of_dev_get()
53 put_device(&dev->dev); in of_dev_put()
59 BUG_ON(ofdev->dev.of_node == NULL); in of_device_add()
63 ofdev->name = dev_name(&ofdev->dev); in of_device_add()
64 ofdev->id = PLATFORM_DEVID_NONE; in of_device_add()
71 set_dev_node(&ofdev->dev, of_node_to_nid(ofdev->dev.of_node)); in of_device_add()
73 return device_add(&ofdev->dev); in of_device_add()
77 * of_dma_configure - Setup DMA configuration
94 const struct iommu_ops *iommu; in of_dma_configure_id() local
95 const struct bus_dma_region *map = NULL; in of_dma_configure_id() local
97 u64 mask, end, size = 0; in of_dma_configure_id() local
101 ret = of_dma_get_range(np, &map); in of_dma_configure_id()
105 * DMA configuration regardless of whether "dma-ranges" is in of_dma_configure_id()
109 return ret == -ENODEV ? 0 : ret; in of_dma_configure_id()
111 const struct bus_dma_region *r = map; in of_dma_configure_id()
115 for (dma_start = ~0; r->size; r++) { in of_dma_configure_id()
117 if (r->dma_start < dma_start) in of_dma_configure_id()
118 dma_start = r->dma_start; in of_dma_configure_id()
119 if (r->dma_start + r->size > dma_end) in of_dma_configure_id()
120 dma_end = r->dma_start + r->size; in of_dma_configure_id()
122 size = dma_end - dma_start; in of_dma_configure_id()
125 * Add a work around to treat the size as mask + 1 in case in of_dma_configure_id()
126 * it is defined in DT as a mask. in of_dma_configure_id()
129 dev_warn(dev, "Invalid size 0x%llx for dma-range(s)\n", in of_dma_configure_id()
136 kfree(map); in of_dma_configure_id()
137 return -EINVAL; in of_dma_configure_id()
142 * If @dev is expected to be DMA-capable then the bus code that created in of_dma_configure_id()
145 * coherent mask if not, but we'll no longer do so quietly. in of_dma_configure_id()
147 if (!dev->dma_mask) { in of_dma_configure_id()
148 dev_warn(dev, "DMA mask not set\n"); in of_dma_configure_id()
149 dev->dma_mask = &dev->coherent_dma_mask; in of_dma_configure_id()
152 if (!size && dev->coherent_dma_mask) in of_dma_configure_id()
153 size = max(dev->coherent_dma_mask, dev->coherent_dma_mask + 1); in of_dma_configure_id()
158 * Limit coherent and dma mask based on size and default mask in of_dma_configure_id()
161 end = dma_start + size - 1; in of_dma_configure_id()
162 mask = DMA_BIT_MASK(ilog2(end) + 1); in of_dma_configure_id()
163 dev->coherent_dma_mask &= mask; in of_dma_configure_id()
164 *dev->dma_mask &= mask; in of_dma_configure_id()
165 /* ...but only set bus limit and range map if we found valid dma-ranges earlier */ in of_dma_configure_id()
167 dev->bus_dma_limit = end; in of_dma_configure_id()
168 dev->dma_range_map = map; in of_dma_configure_id()
175 iommu = of_iommu_configure(dev, np, id); in of_dma_configure_id()
176 if (PTR_ERR(iommu) == -EPROBE_DEFER) { in of_dma_configure_id()
177 /* Don't touch range map if it wasn't set from a valid dma-ranges */ in of_dma_configure_id()
179 dev->dma_range_map = NULL; in of_dma_configure_id()
180 kfree(map); in of_dma_configure_id()
181 return -EPROBE_DEFER; in of_dma_configure_id()
184 dev_dbg(dev, "device is%sbehind an iommu\n", in of_dma_configure_id()
185 iommu ? " " : " not "); in of_dma_configure_id()
187 arch_setup_dma_ops(dev, dma_start, size, iommu, coherent); in of_dma_configure_id()
195 device_initialize(&pdev->dev); in of_device_register()
202 device_unregister(&ofdev->dev); in of_device_unregister()
210 match = of_match_device(dev->driver->of_match_table, dev); in of_device_get_match_data()
214 return match->data; in of_device_get_match_data()
226 if ((!dev) || (!dev->of_node)) in of_device_get_modalias()
227 return -ENODEV; in of_device_get_modalias()
231 csize = snprintf(str, len, "of:N%pOFn%c%s", dev->of_node, 'T', in of_device_get_modalias()
232 of_node_get_device_type(dev->of_node)); in of_device_get_modalias()
234 len -= csize; in of_device_get_modalias()
238 of_property_for_each_string(dev->of_node, "compatible", p, compat) { in of_device_get_modalias()
250 len -= csize; in of_device_get_modalias()
272 return -ENOMEM; in of_device_request_module()
275 str[size - 1] = '\0'; in of_device_request_module()
284 * of_device_modalias - Fill buffer with newline terminated modalias string
288 ssize_t sl = of_device_get_modalias(dev, str, len - 2); in of_device_modalias()
291 if (sl > len - 2) in of_device_modalias()
292 return -ENOMEM; in of_device_modalias()
301 * of_device_uevent - Display OF related uevent information
310 if ((!dev) || (!dev->of_node)) in of_device_uevent()
313 add_uevent_var(env, "OF_NAME=%pOFn", dev->of_node); in of_device_uevent()
314 add_uevent_var(env, "OF_FULLNAME=%pOF", dev->of_node); in of_device_uevent()
315 type = of_node_get_device_type(dev->of_node); in of_device_uevent()
322 of_property_for_each_string(dev->of_node, "compatible", p, compat) { in of_device_uevent()
331 if (dev->of_node == app->np) { in of_device_uevent()
333 app->alias); in of_device_uevent()
344 if ((!dev) || (!dev->of_node)) in of_device_uevent_modalias()
345 return -ENODEV; in of_device_uevent_modalias()
349 return -ENOMEM; in of_device_uevent_modalias()
351 sl = of_device_get_modalias(dev, &env->buf[env->buflen-1], in of_device_uevent_modalias()
352 sizeof(env->buf) - env->buflen); in of_device_uevent_modalias()
353 if (sl >= (sizeof(env->buf) - env->buflen)) in of_device_uevent_modalias()
354 return -ENOMEM; in of_device_uevent_modalias()
355 env->buflen += sl; in of_device_uevent_modalias()