Lines Matching +full:acpi +full:- +full:based
1 // SPDX-License-Identifier: GPL-2.0-only
3 * ACPI helpers for DMA request / controller
5 * Based on of-dma.c
12 #include <linux/acpi.h>
15 #include <linux/dma-mapping.h>
32 * acpi_dma_parse_resource_group - match device and parse resource group
34 * @adev: ACPI device to match with
53 if (grp->shared_info_length != sizeof(struct acpi_csrt_shared_info)) in acpi_dma_parse_resource_group()
54 return -ENODEV; in acpi_dma_parse_resource_group()
62 if (resource_type(rentry->res) == IORESOURCE_MEM) in acpi_dma_parse_resource_group()
63 mem = rentry->res->start; in acpi_dma_parse_resource_group()
64 else if (resource_type(rentry->res) == IORESOURCE_IRQ) in acpi_dma_parse_resource_group()
65 irq = rentry->res->start; in acpi_dma_parse_resource_group()
77 if (si->mmio_base_low != lower_32_bits(mem) || in acpi_dma_parse_resource_group()
78 si->mmio_base_high != upper_32_bits(mem)) in acpi_dma_parse_resource_group()
86 ret = acpi_register_gsi(NULL, si->gsi_interrupt, si->interrupt_mode, si->interrupt_polarity); in acpi_dma_parse_resource_group()
94 dev_dbg(&adev->dev, "matches with %.4s%04X (rev %u)\n", in acpi_dma_parse_resource_group()
95 (char *)&grp->vendor_id, grp->device_id, grp->revision); in acpi_dma_parse_resource_group()
98 if (si->base_request_line == 0 && si->num_handshake_signals == 0) in acpi_dma_parse_resource_group()
101 /* Set up DMA mask based on value from CSRT */ in acpi_dma_parse_resource_group()
102 ret = dma_coerce_mask_and_coherent(&adev->dev, in acpi_dma_parse_resource_group()
103 DMA_BIT_MASK(si->dma_address_width)); in acpi_dma_parse_resource_group()
107 adma->base_request_line = si->base_request_line; in acpi_dma_parse_resource_group()
108 adma->end_request_line = si->base_request_line + in acpi_dma_parse_resource_group()
109 si->num_handshake_signals - 1; in acpi_dma_parse_resource_group()
111 dev_dbg(&adev->dev, "request line base: 0x%04x end: 0x%04x\n", in acpi_dma_parse_resource_group()
112 adma->base_request_line, adma->end_request_line); in acpi_dma_parse_resource_group()
118 * acpi_dma_parse_csrt - parse CSRT to extract additional DMA resources
119 * @adev: ACPI device to match with
122 * CSRT or Core System Resources Table is a proprietary ACPI table
141 dev_warn(&adev->dev, "failed to get the CSRT table\n"); in acpi_dma_parse_csrt()
146 end = (struct acpi_csrt_group *)((void *)csrt + csrt->header.length); in acpi_dma_parse_csrt()
151 dev_warn(&adev->dev, in acpi_dma_parse_csrt()
156 grp = (struct acpi_csrt_group *)((void *)grp + grp->length); in acpi_dma_parse_csrt()
163 * acpi_dma_controller_register - Register a DMA controller to ACPI DMA helpers
185 return -EINVAL; in acpi_dma_controller_register()
187 /* Check if the device was enumerated by ACPI */ in acpi_dma_controller_register()
190 return -EINVAL; in acpi_dma_controller_register()
194 return -ENOMEM; in acpi_dma_controller_register()
196 adma->dev = dev; in acpi_dma_controller_register()
197 adma->acpi_dma_xlate = acpi_dma_xlate; in acpi_dma_controller_register()
198 adma->data = data; in acpi_dma_controller_register()
204 list_add_tail(&adma->dma_controllers, &acpi_dma_list); in acpi_dma_controller_register()
212 * acpi_dma_controller_free - Remove a DMA controller from ACPI DMA helpers list
225 return -EINVAL; in acpi_dma_controller_free()
230 if (adma->dev == dev) { in acpi_dma_controller_free()
231 list_del(&adma->dma_controllers); in acpi_dma_controller_free()
238 return -ENODEV; in acpi_dma_controller_free()
248 * devm_acpi_dma_controller_register - resource managed acpi_dma_controller_register()
276 * acpi_dma_update_dma_spec - prepare dma specifier to pass to translation function
280 * Accordingly to ACPI 5.0 Specification Table 6-170 "Fixed DMA Resource
282 * DMA Request Line bits is a platform-relative number uniquely
283 * identifying the request line assigned. Request line-to-Controller
284 * mapping is done in a controller-specific OS driver.
289 * 0, if no information is available, -1 on mismatch, and 1 otherwise.
295 dma_spec->dev = adma->dev; in acpi_dma_update_dma_spec()
298 if (adma->base_request_line == 0 && adma->end_request_line == 0) in acpi_dma_update_dma_spec()
302 if (dma_spec->slave_id < adma->base_request_line || in acpi_dma_update_dma_spec()
303 dma_spec->slave_id > adma->end_request_line) in acpi_dma_update_dma_spec()
304 return -1; in acpi_dma_update_dma_spec()
310 dma_spec->slave_id -= adma->base_request_line; in acpi_dma_update_dma_spec()
322 * acpi_dma_parse_fixed_dma - Parse FixedDMA ACPI resources to a DMA specifier
330 if (res->type == ACPI_RESOURCE_TYPE_FIXED_DMA) { in acpi_dma_parse_fixed_dma()
331 struct acpi_resource_fixed_dma *dma = &res->data.fixed_dma; in acpi_dma_parse_fixed_dma()
333 if (pdata->n++ == pdata->index) { in acpi_dma_parse_fixed_dma()
334 pdata->dma_spec.chan_id = dma->channels; in acpi_dma_parse_fixed_dma()
335 pdata->dma_spec.slave_id = dma->request_lines; in acpi_dma_parse_fixed_dma()
339 /* Tell the ACPI core to skip this resource */ in acpi_dma_parse_fixed_dma()
344 * acpi_dma_request_slave_chan_by_index - Get the DMA slave channel
367 dma_spec->chan_id = -1; in acpi_dma_request_slave_chan_by_index()
368 dma_spec->slave_id = -1; in acpi_dma_request_slave_chan_by_index()
377 if (dma_spec->slave_id < 0 || dma_spec->chan_id < 0) in acpi_dma_request_slave_chan_by_index()
378 return ERR_PTR(-ENODEV); in acpi_dma_request_slave_chan_by_index()
390 chan = adma->acpi_dma_xlate(dma_spec, adma); in acpi_dma_request_slave_chan_by_index()
401 return chan ? chan : ERR_PTR(-EPROBE_DEFER); in acpi_dma_request_slave_chan_by_index()
406 * acpi_dma_request_slave_chan_by_name - Get the DMA slave channel
410 * In order to support both Device Tree and ACPI in a single driver we
411 * translate the names "tx" and "rx" here based on the most common case where
414 * If the device has "dma-names" property the FixedDMA descriptor indices
415 * are retrieved based on those. Otherwise the function falls back using
426 index = device_property_match_string(dev, "dma-names", name); in acpi_dma_request_slave_chan_by_name()
433 return ERR_PTR(-ENODEV); in acpi_dma_request_slave_chan_by_name()
442 * acpi_dma_simple_xlate - Simple ACPI DMA engine translation helper
443 * @dma_spec: pointer to ACPI DMA specifier
444 * @adma: pointer to ACPI DMA controller data
446 * A simple translation function for ACPI based devices. Passes &struct
455 struct acpi_dma_filter_info *info = adma->data; in acpi_dma_simple_xlate()
457 if (!info || !info->filter_fn) in acpi_dma_simple_xlate()
460 return dma_request_channel(info->dma_cap, info->filter_fn, dma_spec); in acpi_dma_simple_xlate()