aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/dma
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/dma')
-rw-r--r--drivers/dma/acpi-dma.c172
-rw-r--r--drivers/dma/dmatest.c45
-rw-r--r--drivers/dma/ste_dma40.c8
-rw-r--r--drivers/dma/tegra20-apb-dma.c5
4 files changed, 197 insertions, 33 deletions
diff --git a/drivers/dma/acpi-dma.c b/drivers/dma/acpi-dma.c
index ba6fc62e9651..5a18f82f732a 100644
--- a/drivers/dma/acpi-dma.c
+++ b/drivers/dma/acpi-dma.c
@@ -4,7 +4,8 @@
4 * Based on of-dma.c 4 * Based on of-dma.c
5 * 5 *
6 * Copyright (C) 2013, Intel Corporation 6 * Copyright (C) 2013, Intel Corporation
7 * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.com> 7 * Authors: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
8 * Mika Westerberg <mika.westerberg@linux.intel.com>
8 * 9 *
9 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as 11 * it under the terms of the GNU General Public License version 2 as
@@ -16,6 +17,7 @@
16#include <linux/list.h> 17#include <linux/list.h>
17#include <linux/mutex.h> 18#include <linux/mutex.h>
18#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/ioport.h>
19#include <linux/acpi.h> 21#include <linux/acpi.h>
20#include <linux/acpi_dma.h> 22#include <linux/acpi_dma.h>
21 23
@@ -23,6 +25,117 @@ static LIST_HEAD(acpi_dma_list);
23static DEFINE_MUTEX(acpi_dma_lock); 25static DEFINE_MUTEX(acpi_dma_lock);
24 26
25/** 27/**
28 * acpi_dma_parse_resource_group - match device and parse resource group
29 * @grp: CSRT resource group
30 * @adev: ACPI device to match with
31 * @adma: struct acpi_dma of the given DMA controller
32 *
33 * Returns 1 on success, 0 when no information is available, or appropriate
34 * errno value on error.
35 *
36 * In order to match a device from DSDT table to the corresponding CSRT device
37 * we use MMIO address and IRQ.
38 */
39static int acpi_dma_parse_resource_group(const struct acpi_csrt_group *grp,
40 struct acpi_device *adev, struct acpi_dma *adma)
41{
42 const struct acpi_csrt_shared_info *si;
43 struct list_head resource_list;
44 struct resource_list_entry *rentry;
45 resource_size_t mem = 0, irq = 0;
46 u32 vendor_id;
47 int ret;
48
49 if (grp->shared_info_length != sizeof(struct acpi_csrt_shared_info))
50 return -ENODEV;
51
52 INIT_LIST_HEAD(&resource_list);
53 ret = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
54 if (ret <= 0)
55 return 0;
56
57 list_for_each_entry(rentry, &resource_list, node) {
58 if (resource_type(&rentry->res) == IORESOURCE_MEM)
59 mem = rentry->res.start;
60 else if (resource_type(&rentry->res) == IORESOURCE_IRQ)
61 irq = rentry->res.start;
62 }
63
64 acpi_dev_free_resource_list(&resource_list);
65
66 /* Consider initial zero values as resource not found */
67 if (mem == 0 && irq == 0)
68 return 0;
69
70 si = (const struct acpi_csrt_shared_info *)&grp[1];
71
72 /* Match device by MMIO and IRQ */
73 if (si->mmio_base_low != mem || si->gsi_interrupt != irq)
74 return 0;
75
76 vendor_id = le32_to_cpu(grp->vendor_id);
77 dev_dbg(&adev->dev, "matches with %.4s%04X (rev %u)\n",
78 (char *)&vendor_id, grp->device_id, grp->revision);
79
80 /* Check if the request line range is available */
81 if (si->base_request_line == 0 && si->num_handshake_signals == 0)
82 return 0;
83
84 adma->base_request_line = si->base_request_line;
85 adma->end_request_line = si->base_request_line +
86 si->num_handshake_signals - 1;
87
88 dev_dbg(&adev->dev, "request line base: 0x%04x end: 0x%04x\n",
89 adma->base_request_line, adma->end_request_line);
90
91 return 1;
92}
93
94/**
95 * acpi_dma_parse_csrt - parse CSRT to exctract additional DMA resources
96 * @adev: ACPI device to match with
97 * @adma: struct acpi_dma of the given DMA controller
98 *
99 * CSRT or Core System Resources Table is a proprietary ACPI table
100 * introduced by Microsoft. This table can contain devices that are not in
101 * the system DSDT table. In particular DMA controllers might be described
102 * here.
103 *
104 * We are using this table to get the request line range of the specific DMA
105 * controller to be used later.
106 *
107 */
108static void acpi_dma_parse_csrt(struct acpi_device *adev, struct acpi_dma *adma)
109{
110 struct acpi_csrt_group *grp, *end;
111 struct acpi_table_csrt *csrt;
112 acpi_status status;
113 int ret;
114
115 status = acpi_get_table(ACPI_SIG_CSRT, 0,
116 (struct acpi_table_header **)&csrt);
117 if (ACPI_FAILURE(status)) {
118 if (status != AE_NOT_FOUND)
119 dev_warn(&adev->dev, "failed to get the CSRT table\n");
120 return;
121 }
122
123 grp = (struct acpi_csrt_group *)(csrt + 1);
124 end = (struct acpi_csrt_group *)((void *)csrt + csrt->header.length);
125
126 while (grp < end) {
127 ret = acpi_dma_parse_resource_group(grp, adev, adma);
128 if (ret < 0) {
129 dev_warn(&adev->dev,
130 "error in parsing resource group\n");
131 return;
132 }
133
134 grp = (struct acpi_csrt_group *)((void *)grp + grp->length);
135 }
136}
137
138/**
26 * acpi_dma_controller_register - Register a DMA controller to ACPI DMA helpers 139 * acpi_dma_controller_register - Register a DMA controller to ACPI DMA helpers
27 * @dev: struct device of DMA controller 140 * @dev: struct device of DMA controller
28 * @acpi_dma_xlate: translation function which converts a dma specifier 141 * @acpi_dma_xlate: translation function which converts a dma specifier
@@ -61,6 +174,8 @@ int acpi_dma_controller_register(struct device *dev,
61 adma->acpi_dma_xlate = acpi_dma_xlate; 174 adma->acpi_dma_xlate = acpi_dma_xlate;
62 adma->data = data; 175 adma->data = data;
63 176
177 acpi_dma_parse_csrt(adev, adma);
178
64 /* Now queue acpi_dma controller structure in list */ 179 /* Now queue acpi_dma controller structure in list */
65 mutex_lock(&acpi_dma_lock); 180 mutex_lock(&acpi_dma_lock);
66 list_add_tail(&adma->dma_controllers, &acpi_dma_list); 181 list_add_tail(&adma->dma_controllers, &acpi_dma_list);
@@ -149,6 +264,45 @@ void devm_acpi_dma_controller_free(struct device *dev)
149} 264}
150EXPORT_SYMBOL_GPL(devm_acpi_dma_controller_free); 265EXPORT_SYMBOL_GPL(devm_acpi_dma_controller_free);
151 266
267/**
268 * acpi_dma_update_dma_spec - prepare dma specifier to pass to translation function
269 * @adma: struct acpi_dma of DMA controller
270 * @dma_spec: dma specifier to update
271 *
272 * Returns 0, if no information is avaiable, -1 on mismatch, and 1 otherwise.
273 *
274 * Accordingly to ACPI 5.0 Specification Table 6-170 "Fixed DMA Resource
275 * Descriptor":
276 * DMA Request Line bits is a platform-relative number uniquely
277 * identifying the request line assigned. Request line-to-Controller
278 * mapping is done in a controller-specific OS driver.
279 * That's why we can safely adjust slave_id when the appropriate controller is
280 * found.
281 */
282static int acpi_dma_update_dma_spec(struct acpi_dma *adma,
283 struct acpi_dma_spec *dma_spec)
284{
285 /* Set link to the DMA controller device */
286 dma_spec->dev = adma->dev;
287
288 /* Check if the request line range is available */
289 if (adma->base_request_line == 0 && adma->end_request_line == 0)
290 return 0;
291
292 /* Check if slave_id falls to the range */
293 if (dma_spec->slave_id < adma->base_request_line ||
294 dma_spec->slave_id > adma->end_request_line)
295 return -1;
296
297 /*
298 * Here we adjust slave_id. It should be a relative number to the base
299 * request line.
300 */
301 dma_spec->slave_id -= adma->base_request_line;
302
303 return 1;
304}
305
152struct acpi_dma_parser_data { 306struct acpi_dma_parser_data {
153 struct acpi_dma_spec dma_spec; 307 struct acpi_dma_spec dma_spec;
154 size_t index; 308 size_t index;
@@ -193,6 +347,7 @@ struct dma_chan *acpi_dma_request_slave_chan_by_index(struct device *dev,
193 struct acpi_device *adev; 347 struct acpi_device *adev;
194 struct acpi_dma *adma; 348 struct acpi_dma *adma;
195 struct dma_chan *chan = NULL; 349 struct dma_chan *chan = NULL;
350 int found;
196 351
197 /* Check if the device was enumerated by ACPI */ 352 /* Check if the device was enumerated by ACPI */
198 if (!dev || !ACPI_HANDLE(dev)) 353 if (!dev || !ACPI_HANDLE(dev))
@@ -219,9 +374,20 @@ struct dma_chan *acpi_dma_request_slave_chan_by_index(struct device *dev,
219 mutex_lock(&acpi_dma_lock); 374 mutex_lock(&acpi_dma_lock);
220 375
221 list_for_each_entry(adma, &acpi_dma_list, dma_controllers) { 376 list_for_each_entry(adma, &acpi_dma_list, dma_controllers) {
222 dma_spec->dev = adma->dev; 377 /*
378 * We are not going to call translation function if slave_id
379 * doesn't fall to the request range.
380 */
381 found = acpi_dma_update_dma_spec(adma, dma_spec);
382 if (found < 0)
383 continue;
223 chan = adma->acpi_dma_xlate(dma_spec, adma); 384 chan = adma->acpi_dma_xlate(dma_spec, adma);
224 if (chan) 385 /*
386 * Try to get a channel only from the DMA controller that
387 * matches the slave_id. See acpi_dma_update_dma_spec()
388 * description for the details.
389 */
390 if (found > 0 || chan)
225 break; 391 break;
226 } 392 }
227 393
diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c
index d8ce4ecfef18..e88ded2c8d2f 100644
--- a/drivers/dma/dmatest.c
+++ b/drivers/dma/dmatest.c
@@ -716,8 +716,7 @@ static int dmatest_func(void *data)
716 } 716 }
717 dma_async_issue_pending(chan); 717 dma_async_issue_pending(chan);
718 718
719 wait_event_freezable_timeout(done_wait, 719 wait_event_freezable_timeout(done_wait, done.done,
720 done.done || kthread_should_stop(),
721 msecs_to_jiffies(params->timeout)); 720 msecs_to_jiffies(params->timeout));
722 721
723 status = dma_async_is_tx_complete(chan, cookie, NULL, NULL); 722 status = dma_async_is_tx_complete(chan, cookie, NULL, NULL);
@@ -997,7 +996,6 @@ static void stop_threaded_test(struct dmatest_info *info)
997static int __restart_threaded_test(struct dmatest_info *info, bool run) 996static int __restart_threaded_test(struct dmatest_info *info, bool run)
998{ 997{
999 struct dmatest_params *params = &info->params; 998 struct dmatest_params *params = &info->params;
1000 int ret;
1001 999
1002 /* Stop any running test first */ 1000 /* Stop any running test first */
1003 __stop_threaded_test(info); 1001 __stop_threaded_test(info);
@@ -1012,13 +1010,23 @@ static int __restart_threaded_test(struct dmatest_info *info, bool run)
1012 memcpy(params, &info->dbgfs_params, sizeof(*params)); 1010 memcpy(params, &info->dbgfs_params, sizeof(*params));
1013 1011
1014 /* Run test with new parameters */ 1012 /* Run test with new parameters */
1015 ret = __run_threaded_test(info); 1013 return __run_threaded_test(info);
1016 if (ret) { 1014}
1017 __stop_threaded_test(info); 1015
1018 pr_err("dmatest: Can't run test\n"); 1016static bool __is_threaded_test_run(struct dmatest_info *info)
1017{
1018 struct dmatest_chan *dtc;
1019
1020 list_for_each_entry(dtc, &info->channels, node) {
1021 struct dmatest_thread *thread;
1022
1023 list_for_each_entry(thread, &dtc->threads, node) {
1024 if (!thread->done)
1025 return true;
1026 }
1019 } 1027 }
1020 1028
1021 return ret; 1029 return false;
1022} 1030}
1023 1031
1024static ssize_t dtf_write_string(void *to, size_t available, loff_t *ppos, 1032static ssize_t dtf_write_string(void *to, size_t available, loff_t *ppos,
@@ -1091,22 +1099,10 @@ static ssize_t dtf_read_run(struct file *file, char __user *user_buf,
1091{ 1099{
1092 struct dmatest_info *info = file->private_data; 1100 struct dmatest_info *info = file->private_data;
1093 char buf[3]; 1101 char buf[3];
1094 struct dmatest_chan *dtc;
1095 bool alive = false;
1096 1102
1097 mutex_lock(&info->lock); 1103 mutex_lock(&info->lock);
1098 list_for_each_entry(dtc, &info->channels, node) {
1099 struct dmatest_thread *thread;
1100
1101 list_for_each_entry(thread, &dtc->threads, node) {
1102 if (!thread->done) {
1103 alive = true;
1104 break;
1105 }
1106 }
1107 }
1108 1104
1109 if (alive) { 1105 if (__is_threaded_test_run(info)) {
1110 buf[0] = 'Y'; 1106 buf[0] = 'Y';
1111 } else { 1107 } else {
1112 __stop_threaded_test(info); 1108 __stop_threaded_test(info);
@@ -1132,7 +1128,12 @@ static ssize_t dtf_write_run(struct file *file, const char __user *user_buf,
1132 1128
1133 if (strtobool(buf, &bv) == 0) { 1129 if (strtobool(buf, &bv) == 0) {
1134 mutex_lock(&info->lock); 1130 mutex_lock(&info->lock);
1135 ret = __restart_threaded_test(info, bv); 1131
1132 if (__is_threaded_test_run(info))
1133 ret = -EBUSY;
1134 else
1135 ret = __restart_threaded_test(info, bv);
1136
1136 mutex_unlock(&info->lock); 1137 mutex_unlock(&info->lock);
1137 } 1138 }
1138 1139
diff --git a/drivers/dma/ste_dma40.c b/drivers/dma/ste_dma40.c
index 1734feec47b1..71bf4ec300ea 100644
--- a/drivers/dma/ste_dma40.c
+++ b/drivers/dma/ste_dma40.c
@@ -1566,10 +1566,12 @@ static void dma_tc_handle(struct d40_chan *d40c)
1566 return; 1566 return;
1567 } 1567 }
1568 1568
1569 if (d40_queue_start(d40c) == NULL) 1569 if (d40_queue_start(d40c) == NULL) {
1570 d40c->busy = false; 1570 d40c->busy = false;
1571 pm_runtime_mark_last_busy(d40c->base->dev); 1571
1572 pm_runtime_put_autosuspend(d40c->base->dev); 1572 pm_runtime_mark_last_busy(d40c->base->dev);
1573 pm_runtime_put_autosuspend(d40c->base->dev);
1574 }
1573 1575
1574 d40_desc_remove(d40d); 1576 d40_desc_remove(d40d);
1575 d40_desc_done(d40c, d40d); 1577 d40_desc_done(d40c, d40d);
diff --git a/drivers/dma/tegra20-apb-dma.c b/drivers/dma/tegra20-apb-dma.c
index ce193409ebd3..33f59ecd256e 100644
--- a/drivers/dma/tegra20-apb-dma.c
+++ b/drivers/dma/tegra20-apb-dma.c
@@ -1273,11 +1273,6 @@ static int tegra_dma_probe(struct platform_device *pdev)
1273 platform_set_drvdata(pdev, tdma); 1273 platform_set_drvdata(pdev, tdma);
1274 1274
1275 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1275 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1276 if (!res) {
1277 dev_err(&pdev->dev, "No mem resource for DMA\n");
1278 return -EINVAL;
1279 }
1280
1281 tdma->base_addr = devm_ioremap_resource(&pdev->dev, res); 1276 tdma->base_addr = devm_ioremap_resource(&pdev->dev, res);
1282 if (IS_ERR(tdma->base_addr)) 1277 if (IS_ERR(tdma->base_addr))
1283 return PTR_ERR(tdma->base_addr); 1278 return PTR_ERR(tdma->base_addr);