diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/acpi/Makefile | 1 | ||||
-rw-r--r-- | drivers/acpi/csrt.c | 159 | ||||
-rw-r--r-- | drivers/acpi/internal.h | 1 | ||||
-rw-r--r-- | drivers/acpi/scan.c | 1 | ||||
-rw-r--r-- | drivers/dma/acpi-dma.c | 172 |
5 files changed, 169 insertions, 165 deletions
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index ecb743bf05a5..6050c8028dce 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile | |||
@@ -38,7 +38,6 @@ acpi-y += processor_core.o | |||
38 | acpi-y += ec.o | 38 | acpi-y += ec.o |
39 | acpi-$(CONFIG_ACPI_DOCK) += dock.o | 39 | acpi-$(CONFIG_ACPI_DOCK) += dock.o |
40 | acpi-y += pci_root.o pci_link.o pci_irq.o | 40 | acpi-y += pci_root.o pci_link.o pci_irq.o |
41 | acpi-y += csrt.o | ||
42 | acpi-$(CONFIG_X86_INTEL_LPSS) += acpi_lpss.o | 41 | acpi-$(CONFIG_X86_INTEL_LPSS) += acpi_lpss.o |
43 | acpi-y += acpi_platform.o | 42 | acpi-y += acpi_platform.o |
44 | acpi-y += power.o | 43 | acpi-y += power.o |
diff --git a/drivers/acpi/csrt.c b/drivers/acpi/csrt.c deleted file mode 100644 index 5c15a91faf0b..000000000000 --- a/drivers/acpi/csrt.c +++ /dev/null | |||
@@ -1,159 +0,0 @@ | |||
1 | /* | ||
2 | * Support for Core System Resources Table (CSRT) | ||
3 | * | ||
4 | * Copyright (C) 2013, Intel Corporation | ||
5 | * Authors: Mika Westerberg <mika.westerberg@linux.intel.com> | ||
6 | * Andy Shevchenko <andriy.shevchenko@linux.intel.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | */ | ||
12 | |||
13 | #define pr_fmt(fmt) "ACPI: CSRT: " fmt | ||
14 | |||
15 | #include <linux/acpi.h> | ||
16 | #include <linux/device.h> | ||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/platform_device.h> | ||
20 | #include <linux/sizes.h> | ||
21 | |||
22 | ACPI_MODULE_NAME("CSRT"); | ||
23 | |||
24 | static int __init acpi_csrt_parse_shared_info(struct platform_device *pdev, | ||
25 | const struct acpi_csrt_group *grp) | ||
26 | { | ||
27 | const struct acpi_csrt_shared_info *si; | ||
28 | struct resource res[3]; | ||
29 | size_t nres; | ||
30 | int ret; | ||
31 | |||
32 | memset(res, 0, sizeof(res)); | ||
33 | nres = 0; | ||
34 | |||
35 | si = (const struct acpi_csrt_shared_info *)&grp[1]; | ||
36 | /* | ||
37 | * The peripherals that are listed on CSRT typically support only | ||
38 | * 32-bit addresses so we only use the low part of MMIO base for | ||
39 | * now. | ||
40 | */ | ||
41 | if (!si->mmio_base_high && si->mmio_base_low) { | ||
42 | /* | ||
43 | * There is no size of the memory resource in shared_info | ||
44 | * so we assume that it is 4k here. | ||
45 | */ | ||
46 | res[nres].start = si->mmio_base_low; | ||
47 | res[nres].end = res[0].start + SZ_4K - 1; | ||
48 | res[nres++].flags = IORESOURCE_MEM; | ||
49 | } | ||
50 | |||
51 | if (si->gsi_interrupt) { | ||
52 | int irq = acpi_register_gsi(NULL, si->gsi_interrupt, | ||
53 | si->interrupt_mode, | ||
54 | si->interrupt_polarity); | ||
55 | res[nres].start = irq; | ||
56 | res[nres].end = irq; | ||
57 | res[nres++].flags = IORESOURCE_IRQ; | ||
58 | } | ||
59 | |||
60 | if (si->base_request_line || si->num_handshake_signals) { | ||
61 | /* | ||
62 | * We pass the driver a DMA resource describing the range | ||
63 | * of request lines the device supports. | ||
64 | */ | ||
65 | res[nres].start = si->base_request_line; | ||
66 | res[nres].end = res[nres].start + si->num_handshake_signals - 1; | ||
67 | res[nres++].flags = IORESOURCE_DMA; | ||
68 | } | ||
69 | |||
70 | ret = platform_device_add_resources(pdev, res, nres); | ||
71 | if (ret) { | ||
72 | if (si->gsi_interrupt) | ||
73 | acpi_unregister_gsi(si->gsi_interrupt); | ||
74 | return ret; | ||
75 | } | ||
76 | |||
77 | return 0; | ||
78 | } | ||
79 | |||
80 | static int __init | ||
81 | acpi_csrt_parse_resource_group(const struct acpi_csrt_group *grp) | ||
82 | { | ||
83 | struct platform_device *pdev; | ||
84 | char vendor[5], name[16]; | ||
85 | int ret, i; | ||
86 | |||
87 | vendor[0] = grp->vendor_id; | ||
88 | vendor[1] = grp->vendor_id >> 8; | ||
89 | vendor[2] = grp->vendor_id >> 16; | ||
90 | vendor[3] = grp->vendor_id >> 24; | ||
91 | vendor[4] = '\0'; | ||
92 | |||
93 | if (grp->shared_info_length != sizeof(struct acpi_csrt_shared_info)) | ||
94 | return -ENODEV; | ||
95 | |||
96 | snprintf(name, sizeof(name), "%s%04X", vendor, grp->device_id); | ||
97 | pdev = platform_device_alloc(name, PLATFORM_DEVID_AUTO); | ||
98 | if (!pdev) | ||
99 | return -ENOMEM; | ||
100 | |||
101 | /* Add resources based on the shared info */ | ||
102 | ret = acpi_csrt_parse_shared_info(pdev, grp); | ||
103 | if (ret) | ||
104 | goto fail; | ||
105 | |||
106 | ret = platform_device_add(pdev); | ||
107 | if (ret) | ||
108 | goto fail; | ||
109 | |||
110 | for (i = 0; i < pdev->num_resources; i++) | ||
111 | dev_dbg(&pdev->dev, "%pR\n", &pdev->resource[i]); | ||
112 | |||
113 | return 0; | ||
114 | |||
115 | fail: | ||
116 | platform_device_put(pdev); | ||
117 | return ret; | ||
118 | } | ||
119 | |||
120 | /* | ||
121 | * CSRT or Core System Resources Table is a proprietary ACPI table | ||
122 | * introduced by Microsoft. This table can contain devices that are not in | ||
123 | * the system DSDT table. In particular DMA controllers might be described | ||
124 | * here. | ||
125 | * | ||
126 | * We present these devices as normal platform devices that don't have ACPI | ||
127 | * IDs or handle. The platform device name will be something like | ||
128 | * <VENDOR><DEVID>.<n>.auto for example: INTL9C06.0.auto. | ||
129 | */ | ||
130 | void __init acpi_csrt_init(void) | ||
131 | { | ||
132 | struct acpi_csrt_group *grp, *end; | ||
133 | struct acpi_table_csrt *csrt; | ||
134 | acpi_status status; | ||
135 | int ret; | ||
136 | |||
137 | status = acpi_get_table(ACPI_SIG_CSRT, 0, | ||
138 | (struct acpi_table_header **)&csrt); | ||
139 | if (ACPI_FAILURE(status)) { | ||
140 | if (status != AE_NOT_FOUND) | ||
141 | pr_warn("failed to get the CSRT table\n"); | ||
142 | return; | ||
143 | } | ||
144 | |||
145 | pr_debug("parsing CSRT table for devices\n"); | ||
146 | |||
147 | grp = (struct acpi_csrt_group *)(csrt + 1); | ||
148 | end = (struct acpi_csrt_group *)((void *)csrt + csrt->header.length); | ||
149 | |||
150 | while (grp < end) { | ||
151 | ret = acpi_csrt_parse_resource_group(grp); | ||
152 | if (ret) { | ||
153 | pr_warn("error in parsing resource group: %d\n", ret); | ||
154 | return; | ||
155 | } | ||
156 | |||
157 | grp = (struct acpi_csrt_group *)((void *)grp + grp->length); | ||
158 | } | ||
159 | } | ||
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h index 6f1afd9118c8..297cbf456f86 100644 --- a/drivers/acpi/internal.h +++ b/drivers/acpi/internal.h | |||
@@ -35,7 +35,6 @@ void acpi_pci_link_init(void); | |||
35 | void acpi_pci_root_hp_init(void); | 35 | void acpi_pci_root_hp_init(void); |
36 | void acpi_platform_init(void); | 36 | void acpi_platform_init(void); |
37 | int acpi_sysfs_init(void); | 37 | int acpi_sysfs_init(void); |
38 | void acpi_csrt_init(void); | ||
39 | #ifdef CONFIG_ACPI_CONTAINER | 38 | #ifdef CONFIG_ACPI_CONTAINER |
40 | void acpi_container_init(void); | 39 | void acpi_container_init(void); |
41 | #else | 40 | #else |
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index fe158fd4f1df..aacc08f951aa 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c | |||
@@ -2042,7 +2042,6 @@ int __init acpi_scan_init(void) | |||
2042 | acpi_pci_link_init(); | 2042 | acpi_pci_link_init(); |
2043 | acpi_platform_init(); | 2043 | acpi_platform_init(); |
2044 | acpi_lpss_init(); | 2044 | acpi_lpss_init(); |
2045 | acpi_csrt_init(); | ||
2046 | acpi_container_init(); | 2045 | acpi_container_init(); |
2047 | acpi_memory_hotplug_init(); | 2046 | acpi_memory_hotplug_init(); |
2048 | 2047 | ||
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); | |||
23 | static DEFINE_MUTEX(acpi_dma_lock); | 25 | static 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 | */ | ||
39 | static 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 | */ | ||
108 | static 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 | } |
150 | EXPORT_SYMBOL_GPL(devm_acpi_dma_controller_free); | 265 | EXPORT_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 | */ | ||
282 | static 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 | |||
152 | struct acpi_dma_parser_data { | 306 | struct 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 | ||