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>
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 bus_dma_region *map = NULL; in of_dma_configure_id() local
99 u64 mask, end, size = 0; 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()
134 * Add a work around to treat the size as mask + 1 in case in of_dma_configure_id()
135 * it is defined in DT as a mask. 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()
154 * coherent mask if not, but we'll no longer do so quietly. in of_dma_configure_id()
156 if (!dev->dma_mask) { in of_dma_configure_id()
157 dev_warn(dev, "DMA mask not set\n"); 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()
167 * Limit coherent and dma mask based on size and default mask in of_dma_configure_id()
170 end = dma_start + size - 1; in of_dma_configure_id()
171 mask = DMA_BIT_MASK(ilog2(end) + 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()
185 if (iommu_ret == -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()
191 } else if (iommu_ret == -ENODEV) { in of_dma_configure_id()
192 dev_dbg(dev, "device is not behind an iommu\n"); in of_dma_configure_id()
194 dev_err(dev, "iommu configuration for device failed with %pe\n", in of_dma_configure_id()
202 dev_dbg(dev, "device is behind an iommu\n"); in of_dma_configure_id()
217 match = of_match_device(dev->driver->of_match_table, dev); in of_device_get_match_data()
221 return match->data; in of_device_get_match_data()
226 * of_device_modalias - Fill buffer with newline terminated modalias string
235 if (!dev || !dev->of_node || dev->of_node_reused) in of_device_modalias()
236 return -ENODEV; in of_device_modalias()
238 sl = of_modalias(dev->of_node, str, len - 2); in of_device_modalias()
241 if (sl > len - 2) in of_device_modalias()
242 return -ENOMEM; in of_device_modalias()
251 * of_device_uevent - Display OF related uevent information
262 if ((!dev) || (!dev->of_node)) in of_device_uevent()
265 add_uevent_var(env, "OF_NAME=%pOFn", dev->of_node); in of_device_uevent()
266 add_uevent_var(env, "OF_FULLNAME=%pOF", dev->of_node); in of_device_uevent()
267 type = of_node_get_device_type(dev->of_node); in of_device_uevent()
274 of_property_for_each_string(dev->of_node, "compatible", p, compat) { in of_device_uevent()
283 if (dev->of_node == app->np) { in of_device_uevent()
285 app->alias); in of_device_uevent()
297 if ((!dev) || (!dev->of_node) || dev->of_node_reused) in of_device_uevent_modalias()
298 return -ENODEV; in of_device_uevent_modalias()
302 return -ENOMEM; in of_device_uevent_modalias()
304 sl = of_modalias(dev->of_node, &env->buf[env->buflen-1], in of_device_uevent_modalias()
305 sizeof(env->buf) - env->buflen); in of_device_uevent_modalias()
308 if (sl >= (sizeof(env->buf) - env->buflen)) in of_device_uevent_modalias()
309 return -ENOMEM; in of_device_uevent_modalias()
310 env->buflen += sl; in of_device_uevent_modalias()
317 * of_device_make_bus_id - Use the device node data to assign a unique name
326 struct device_node *node = dev->of_node; in of_device_make_bus_id()
329 u32 mask; in of_device_make_bus_id() local
332 while (node->parent) { in of_device_make_bus_id()
339 if (!of_property_read_u32(node, "mask", &mask)) in of_device_make_bus_id()
341 addr, ffs(mask) - 1, node, dev_name(dev)); in of_device_make_bus_id()
351 kbasename(node->full_name), dev_name(dev)); in of_device_make_bus_id()
352 node = node->parent; in of_device_make_bus_id()