Lines Matching +full:dma +full:- +full:coherent
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)) 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()
69 * the OF node having DMA configuration. 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()
89 * Attempt to initialize a restricted-dma-pool region if one was found. in of_dma_set_restricted_buffer()
93 dev_warn(dev, "failed to initialise \"restricted-dma-pool\" memory node\n"); in of_dma_set_restricted_buffer()
97 * of_dma_configure_id - Setup DMA configuration
98 * @dev: Device to apply DMA configuration
99 * @np: Pointer to OF node having DMA configuration
101 * DMA capability is not explicitly described by firmware.
104 * Try to get devices's DMA configuration from DT and update it
107 * If platform code needs to use its own special DMA configuration, it
109 * to fix up DMA configuration.
118 bool coherent; in of_dma_configure_id() local
125 * DMA configuration regardless of whether "dma-ranges" is in of_dma_configure_id()
129 return ret == -ENODEV ? 0 : ret; in of_dma_configure_id()
134 /* Determine the overall bounds of all DMA regions */ in of_dma_configure_id()
135 for (dma_start = ~0; r->size; r++) { in of_dma_configure_id()
137 if (r->dma_start < dma_start) in of_dma_configure_id()
138 dma_start = r->dma_start; in of_dma_configure_id()
139 if (r->dma_start + r->size > dma_end) in of_dma_configure_id()
140 dma_end = r->dma_start + r->size; in of_dma_configure_id()
142 size = dma_end - dma_start; in of_dma_configure_id()
149 dev_warn(dev, "Invalid size 0x%llx for dma-range(s)\n", in of_dma_configure_id()
157 return -EINVAL; in of_dma_configure_id()
162 * If @dev is expected to be DMA-capable then the bus code that created in of_dma_configure_id()
165 * coherent mask if not, but we'll no longer do so quietly. in of_dma_configure_id()
167 if (!dev->dma_mask) { in of_dma_configure_id()
168 dev_warn(dev, "DMA mask not set\n"); in of_dma_configure_id()
169 dev->dma_mask = &dev->coherent_dma_mask; in of_dma_configure_id()
172 if (!size && dev->coherent_dma_mask) in of_dma_configure_id()
173 size = max(dev->coherent_dma_mask, dev->coherent_dma_mask + 1); in of_dma_configure_id()
178 * Limit coherent and dma mask based on size and default mask in of_dma_configure_id()
181 end = dma_start + size - 1; in of_dma_configure_id()
183 dev->coherent_dma_mask &= mask; in of_dma_configure_id()
184 *dev->dma_mask &= mask; in of_dma_configure_id()
185 /* ...but only set bus limit and range map if we found valid dma-ranges earlier */ in of_dma_configure_id()
187 dev->bus_dma_limit = end; in of_dma_configure_id()
188 dev->dma_range_map = map; in of_dma_configure_id()
191 coherent = of_dma_is_coherent(np); in of_dma_configure_id()
192 dev_dbg(dev, "device is%sdma coherent\n", in of_dma_configure_id()
193 coherent ? " " : " not "); in of_dma_configure_id()
196 if (PTR_ERR(iommu) == -EPROBE_DEFER) { in of_dma_configure_id()
197 /* Don't touch range map if it wasn't set from a valid dma-ranges */ in of_dma_configure_id()
199 dev->dma_range_map = NULL; in of_dma_configure_id()
201 return -EPROBE_DEFER; in of_dma_configure_id()
207 arch_setup_dma_ops(dev, dma_start, size, iommu, coherent); in of_dma_configure_id()
218 device_initialize(&pdev->dev); in of_device_register()
225 device_unregister(&ofdev->dev); in of_device_unregister()
233 match = of_match_device(dev->driver->of_match_table, dev); in of_device_get_match_data()
237 return match->data; in of_device_get_match_data()
249 if ((!dev) || (!dev->of_node)) in of_device_get_modalias()
250 return -ENODEV; in of_device_get_modalias()
254 csize = snprintf(str, len, "of:N%pOFn%c%s", dev->of_node, 'T', in of_device_get_modalias()
255 of_node_get_device_type(dev->of_node)); in of_device_get_modalias()
257 len -= csize; in of_device_get_modalias()
261 of_property_for_each_string(dev->of_node, "compatible", p, compat) { in of_device_get_modalias()
273 len -= csize; in of_device_get_modalias()
292 return -ENOMEM; in of_device_request_module()
304 * of_device_modalias - Fill buffer with newline terminated modalias string
311 ssize_t sl = of_device_get_modalias(dev, str, len - 2); in of_device_modalias()
314 if (sl > len - 2) in of_device_modalias()
315 return -ENOMEM; in of_device_modalias()
324 * of_device_uevent - Display OF related uevent information
325 * @dev: Device to apply DMA configuration
335 if ((!dev) || (!dev->of_node)) in of_device_uevent()
338 add_uevent_var(env, "OF_NAME=%pOFn", dev->of_node); in of_device_uevent()
339 add_uevent_var(env, "OF_FULLNAME=%pOF", dev->of_node); in of_device_uevent()
340 type = of_node_get_device_type(dev->of_node); in of_device_uevent()
347 of_property_for_each_string(dev->of_node, "compatible", p, compat) { in of_device_uevent()
356 if (dev->of_node == app->np) { in of_device_uevent()
358 app->alias); in of_device_uevent()
369 if ((!dev) || (!dev->of_node)) in of_device_uevent_modalias()
370 return -ENODEV; in of_device_uevent_modalias()
374 return -ENOMEM; in of_device_uevent_modalias()
376 sl = of_device_get_modalias(dev, &env->buf[env->buflen-1], in of_device_uevent_modalias()
377 sizeof(env->buf) - env->buflen); in of_device_uevent_modalias()
378 if (sl >= (sizeof(env->buf) - env->buflen)) in of_device_uevent_modalias()
379 return -ENOMEM; in of_device_uevent_modalias()
380 env->buflen += sl; in of_device_uevent_modalias()