| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * ACPI helpers for DMA request / controller |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 6 | 7 | * Copyright (C) 2013, Intel Corporation |
|---|
| 7 | 8 | * Authors: Andy Shevchenko <andriy.shevchenko@linux.intel.com> |
|---|
| 8 | 9 | * Mika Westerberg <mika.westerberg@linux.intel.com> |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 11 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 12 | | - * published by the Free Software Foundation. |
|---|
| 13 | 10 | */ |
|---|
| 14 | 11 | |
|---|
| 15 | 12 | #include <linux/device.h> |
|---|
| 13 | +#include <linux/dma-mapping.h> |
|---|
| 16 | 14 | #include <linux/err.h> |
|---|
| 17 | 15 | #include <linux/module.h> |
|---|
| 18 | 16 | #include <linux/kernel.h> |
|---|
| .. | .. |
|---|
| 89 | 87 | if (si->base_request_line == 0 && si->num_handshake_signals == 0) |
|---|
| 90 | 88 | return 0; |
|---|
| 91 | 89 | |
|---|
| 90 | + /* Set up DMA mask based on value from CSRT */ |
|---|
| 91 | + ret = dma_coerce_mask_and_coherent(&adev->dev, |
|---|
| 92 | + DMA_BIT_MASK(si->dma_address_width)); |
|---|
| 93 | + if (ret) |
|---|
| 94 | + return 0; |
|---|
| 95 | + |
|---|
| 92 | 96 | adma->base_request_line = si->base_request_line; |
|---|
| 93 | 97 | adma->end_request_line = si->base_request_line + |
|---|
| 94 | 98 | si->num_handshake_signals - 1; |
|---|
| .. | .. |
|---|
| 149 | 153 | * @dev: struct device of DMA controller |
|---|
| 150 | 154 | * @acpi_dma_xlate: translation function which converts a dma specifier |
|---|
| 151 | 155 | * into a dma_chan structure |
|---|
| 152 | | - * @data pointer to controller specific data to be used by |
|---|
| 156 | + * @data: pointer to controller specific data to be used by |
|---|
| 153 | 157 | * translation function |
|---|
| 154 | 158 | * |
|---|
| 155 | 159 | * Allocated memory should be freed with appropriate acpi_dma_controller_free() |
|---|
| .. | .. |
|---|
| 233 | 237 | * devm_acpi_dma_controller_register - resource managed acpi_dma_controller_register() |
|---|
| 234 | 238 | * @dev: device that is registering this DMA controller |
|---|
| 235 | 239 | * @acpi_dma_xlate: translation function |
|---|
| 236 | | - * @data pointer to controller specific data |
|---|
| 240 | + * @data: pointer to controller specific data |
|---|
| 237 | 241 | * |
|---|
| 238 | 242 | * Managed acpi_dma_controller_register(). DMA controller registered by this |
|---|
| 239 | 243 | * function are automatically freed on driver detach. See |
|---|
| .. | .. |
|---|
| 266 | 270 | |
|---|
| 267 | 271 | /** |
|---|
| 268 | 272 | * devm_acpi_dma_controller_free - resource managed acpi_dma_controller_free() |
|---|
| 273 | + * @dev: device that is unregistering as DMA controller |
|---|
| 269 | 274 | * |
|---|
| 270 | 275 | * Unregister a DMA controller registered with |
|---|
| 271 | 276 | * devm_acpi_dma_controller_register(). Normally this function will not need to |
|---|
| .. | .. |
|---|
| 359 | 364 | { |
|---|
| 360 | 365 | struct acpi_dma_parser_data pdata; |
|---|
| 361 | 366 | struct acpi_dma_spec *dma_spec = &pdata.dma_spec; |
|---|
| 367 | + struct acpi_device *adev = ACPI_COMPANION(dev); |
|---|
| 362 | 368 | struct list_head resource_list; |
|---|
| 363 | | - struct acpi_device *adev; |
|---|
| 364 | 369 | struct acpi_dma *adma; |
|---|
| 365 | 370 | struct dma_chan *chan = NULL; |
|---|
| 366 | 371 | int found; |
|---|
| 367 | | - |
|---|
| 368 | | - /* Check if the device was enumerated by ACPI */ |
|---|
| 369 | | - if (!dev) |
|---|
| 370 | | - return ERR_PTR(-ENODEV); |
|---|
| 371 | | - |
|---|
| 372 | | - adev = ACPI_COMPANION(dev); |
|---|
| 373 | | - if (!adev) |
|---|
| 374 | | - return ERR_PTR(-ENODEV); |
|---|
| 372 | + int ret; |
|---|
| 375 | 373 | |
|---|
| 376 | 374 | memset(&pdata, 0, sizeof(pdata)); |
|---|
| 377 | 375 | pdata.index = index; |
|---|
| .. | .. |
|---|
| 381 | 379 | dma_spec->slave_id = -1; |
|---|
| 382 | 380 | |
|---|
| 383 | 381 | INIT_LIST_HEAD(&resource_list); |
|---|
| 384 | | - acpi_dev_get_resources(adev, &resource_list, |
|---|
| 385 | | - acpi_dma_parse_fixed_dma, &pdata); |
|---|
| 382 | + ret = acpi_dev_get_resources(adev, &resource_list, |
|---|
| 383 | + acpi_dma_parse_fixed_dma, &pdata); |
|---|
| 386 | 384 | acpi_dev_free_resource_list(&resource_list); |
|---|
| 385 | + if (ret < 0) |
|---|
| 386 | + return ERR_PTR(ret); |
|---|
| 387 | 387 | |
|---|
| 388 | 388 | if (dma_spec->slave_id < 0 || dma_spec->chan_id < 0) |
|---|
| 389 | 389 | return ERR_PTR(-ENODEV); |
|---|