blob: 98cbc9f18eed36f281a00893e3ad0df58cfb0873 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * pnpacpi -- PnP ACPI driver
3 *
4 * Copyright (c) 2004 Matthieu Castet <castet.matthieu@free.fr>
5 * Copyright (c) 2004 Li Shaohua <shaohua.li@intel.com>
Bob Moore50eca3e2005-09-30 19:03:00 -04006 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21#include <linux/kernel.h>
22#include <linux/acpi.h>
23#include <linux/pci.h>
24#include "pnpacpi.h"
25
26#ifdef CONFIG_IA64
27#define valid_IRQ(i) (1)
28#else
29#define valid_IRQ(i) (((i) != 0) && ((i) != 2))
30#endif
31
32/*
33 * Allocated Resources
34 */
Bob Moore50eca3e2005-09-30 19:03:00 -040035static int irq_flags(int triggering, int polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -070036{
Bob Moore50eca3e2005-09-30 19:03:00 -040037 if (triggering == ACPI_LEVEL_SENSITIVE) {
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -050038 if (polarity == ACPI_ACTIVE_LOW)
Bjorn Helgaas4cec0862007-08-15 10:32:09 -060039 return IORESOURCE_IRQ_LOWLEVEL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 else
Bjorn Helgaas4cec0862007-08-15 10:32:09 -060041 return IORESOURCE_IRQ_HIGHLEVEL;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -070042 } else {
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -050043 if (polarity == ACPI_ACTIVE_LOW)
Bjorn Helgaas4cec0862007-08-15 10:32:09 -060044 return IORESOURCE_IRQ_LOWEDGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 else
Bjorn Helgaas4cec0862007-08-15 10:32:09 -060046 return IORESOURCE_IRQ_HIGHEDGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070048}
49
Bob Moore50eca3e2005-09-30 19:03:00 -040050static void decode_irq_flags(int flag, int *triggering, int *polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051{
52 switch (flag) {
53 case IORESOURCE_IRQ_LOWLEVEL:
Bob Moore50eca3e2005-09-30 19:03:00 -040054 *triggering = ACPI_LEVEL_SENSITIVE;
55 *polarity = ACPI_ACTIVE_LOW;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 break;
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -050057 case IORESOURCE_IRQ_HIGHLEVEL:
Bob Moore50eca3e2005-09-30 19:03:00 -040058 *triggering = ACPI_LEVEL_SENSITIVE;
59 *polarity = ACPI_ACTIVE_HIGH;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 break;
61 case IORESOURCE_IRQ_LOWEDGE:
Bob Moore50eca3e2005-09-30 19:03:00 -040062 *triggering = ACPI_EDGE_SENSITIVE;
63 *polarity = ACPI_ACTIVE_LOW;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 break;
65 case IORESOURCE_IRQ_HIGHEDGE:
Bob Moore50eca3e2005-09-30 19:03:00 -040066 *triggering = ACPI_EDGE_SENSITIVE;
67 *polarity = ACPI_ACTIVE_HIGH;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 break;
69 }
70}
71
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -070072static void pnpacpi_parse_allocated_irqresource(struct pnp_resource_table *res,
73 u32 gsi, int triggering,
74 int polarity, int shareable)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
76 int i = 0;
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -040077 int irq;
Shaohua Li61fd47e2007-11-17 01:05:28 -050078 int p, t;
Len Brown66a21732008-01-12 17:56:36 -050079 static unsigned char warned;
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -040080
81 if (!valid_IRQ(gsi))
82 return;
83
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 while (!(res->irq_resource[i].flags & IORESOURCE_UNSET) &&
Bjorn Helgaas9dd78462007-07-26 10:41:20 -070085 i < PNP_MAX_IRQ)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 i++;
Len Brown0093cb12008-04-23 00:09:13 -040087 if (i >= PNP_MAX_IRQ) {
88 if (!warned) {
89 printk(KERN_WARNING "pnpacpi: exceeded the max number"
90 " of IRQ resources: %d\n", PNP_MAX_IRQ);
91 warned = 1;
92 }
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -040093 return;
Zhao Yakuia7839e92007-11-28 16:21:21 -080094 }
Shaohua Li61fd47e2007-11-17 01:05:28 -050095 /*
96 * in IO-APIC mode, use overrided attribute. Two reasons:
97 * 1. BIOS bug in DSDT
98 * 2. BIOS uses IO-APIC mode Interrupt Source Override
99 */
100 if (!acpi_get_override_irq(gsi, &t, &p)) {
101 t = t ? ACPI_LEVEL_SENSITIVE : ACPI_EDGE_SENSITIVE;
102 p = p ? ACPI_ACTIVE_LOW : ACPI_ACTIVE_HIGH;
103
104 if (triggering != t || polarity != p) {
105 pnp_warn("IRQ %d override to %s, %s",
106 gsi, t ? "edge":"level", p ? "low":"high");
107 triggering = t;
108 polarity = p;
109 }
110 }
111
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700112 res->irq_resource[i].flags = IORESOURCE_IRQ; // Also clears _UNSET flag
Michael Karcher362ea082007-03-08 23:29:29 -0500113 res->irq_resource[i].flags |= irq_flags(triggering, polarity);
Bob Moore50eca3e2005-09-30 19:03:00 -0400114 irq = acpi_register_gsi(gsi, triggering, polarity);
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -0400115 if (irq < 0) {
116 res->irq_resource[i].flags |= IORESOURCE_DISABLED;
117 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 }
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -0400119
Bjorn Helgaasc32928c2006-07-03 00:24:10 -0700120 if (shareable)
121 res->irq_resource[i].flags |= IORESOURCE_IRQ_SHAREABLE;
122
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -0400123 res->irq_resource[i].start = irq;
124 res->irq_resource[i].end = irq;
125 pcibios_penalize_isa_irq(irq, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126}
127
Michael Karcher362ea082007-03-08 23:29:29 -0500128static int dma_flags(int type, int bus_master, int transfer)
129{
130 int flags = 0;
131
132 if (bus_master)
133 flags |= IORESOURCE_DMA_MASTER;
134 switch (type) {
135 case ACPI_COMPATIBILITY:
136 flags |= IORESOURCE_DMA_COMPATIBLE;
137 break;
138 case ACPI_TYPE_A:
139 flags |= IORESOURCE_DMA_TYPEA;
140 break;
141 case ACPI_TYPE_B:
142 flags |= IORESOURCE_DMA_TYPEB;
143 break;
144 case ACPI_TYPE_F:
145 flags |= IORESOURCE_DMA_TYPEF;
146 break;
147 default:
148 /* Set a default value ? */
149 flags |= IORESOURCE_DMA_COMPATIBLE;
150 pnp_err("Invalid DMA type");
151 }
152 switch (transfer) {
153 case ACPI_TRANSFER_8:
154 flags |= IORESOURCE_DMA_8BIT;
155 break;
156 case ACPI_TRANSFER_8_16:
157 flags |= IORESOURCE_DMA_8AND16BIT;
158 break;
159 case ACPI_TRANSFER_16:
160 flags |= IORESOURCE_DMA_16BIT;
161 break;
162 default:
163 /* Set a default value ? */
164 flags |= IORESOURCE_DMA_8AND16BIT;
165 pnp_err("Invalid DMA transfer type");
166 }
167
168 return flags;
169}
170
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700171static void pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table *res,
172 u32 dma, int type,
173 int bus_master, int transfer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174{
175 int i = 0;
Len Brown66a21732008-01-12 17:56:36 -0500176 static unsigned char warned;
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700177
Adrian Bunk0dec63b2005-05-01 08:59:30 -0700178 while (i < PNP_MAX_DMA &&
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700179 !(res->dma_resource[i].flags & IORESOURCE_UNSET))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 i++;
181 if (i < PNP_MAX_DMA) {
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700182 res->dma_resource[i].flags = IORESOURCE_DMA; // Also clears _UNSET flag
183 res->dma_resource[i].flags |=
184 dma_flags(type, bus_master, transfer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 if (dma == -1) {
186 res->dma_resource[i].flags |= IORESOURCE_DISABLED;
187 return;
188 }
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -0400189 res->dma_resource[i].start = dma;
190 res->dma_resource[i].end = dma;
Len Brown66a21732008-01-12 17:56:36 -0500191 } else if (!warned) {
Len Brown33fd7af2008-03-26 13:29:32 -0400192 printk(KERN_WARNING "pnpacpi: exceeded the max number of DMA "
Zhao Yakuia7839e92007-11-28 16:21:21 -0800193 "resources: %d \n", PNP_MAX_DMA);
Len Brown66a21732008-01-12 17:56:36 -0500194 warned = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 }
196}
197
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700198static void pnpacpi_parse_allocated_ioresource(struct pnp_resource_table *res,
199 u64 io, u64 len, int io_decode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200{
201 int i = 0;
Len Brown66a21732008-01-12 17:56:36 -0500202 static unsigned char warned;
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 while (!(res->port_resource[i].flags & IORESOURCE_UNSET) &&
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700205 i < PNP_MAX_PORT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 i++;
207 if (i < PNP_MAX_PORT) {
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700208 res->port_resource[i].flags = IORESOURCE_IO; // Also clears _UNSET flag
Michael Karcher362ea082007-03-08 23:29:29 -0500209 if (io_decode == ACPI_DECODE_16)
210 res->port_resource[i].flags |= PNP_PORT_FLAG_16BITADDR;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700211 if (len <= 0 || (io + len - 1) >= 0x10003) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 res->port_resource[i].flags |= IORESOURCE_DISABLED;
213 return;
214 }
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -0400215 res->port_resource[i].start = io;
216 res->port_resource[i].end = io + len - 1;
Len Brown66a21732008-01-12 17:56:36 -0500217 } else if (!warned) {
Len Brown33fd7af2008-03-26 13:29:32 -0400218 printk(KERN_WARNING "pnpacpi: exceeded the max number of IO "
Zhao Yakuia7839e92007-11-28 16:21:21 -0800219 "resources: %d \n", PNP_MAX_PORT);
Len Brownefe7cf22008-01-17 15:21:10 -0800220 warned = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 }
222}
223
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700224static void pnpacpi_parse_allocated_memresource(struct pnp_resource_table *res,
225 u64 mem, u64 len,
226 int write_protect)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227{
228 int i = 0;
Len Brown66a21732008-01-12 17:56:36 -0500229 static unsigned char warned;
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700230
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 while (!(res->mem_resource[i].flags & IORESOURCE_UNSET) &&
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700232 (i < PNP_MAX_MEM))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 i++;
234 if (i < PNP_MAX_MEM) {
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700235 res->mem_resource[i].flags = IORESOURCE_MEM; // Also clears _UNSET flag
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 if (len <= 0) {
237 res->mem_resource[i].flags |= IORESOURCE_DISABLED;
238 return;
239 }
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700240 if (write_protect == ACPI_READ_WRITE_MEMORY)
Michael Karcher362ea082007-03-08 23:29:29 -0500241 res->mem_resource[i].flags |= IORESOURCE_MEM_WRITEABLE;
242
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -0400243 res->mem_resource[i].start = mem;
244 res->mem_resource[i].end = mem + len - 1;
Len Brown66a21732008-01-12 17:56:36 -0500245 } else if (!warned) {
Len Brown33fd7af2008-03-26 13:29:32 -0400246 printk(KERN_WARNING "pnpacpi: exceeded the max number of mem "
Zhao Yakuia7839e92007-11-28 16:21:21 -0800247 "resources: %d\n", PNP_MAX_MEM);
Len Brownefe7cf22008-01-17 15:21:10 -0800248 warned = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 }
250}
251
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700252static void pnpacpi_parse_allocated_address_space(struct pnp_resource_table *res_table,
253 struct acpi_resource *res)
Bjorn Helgaas1acfb7f2006-03-28 17:03:00 -0500254{
255 struct acpi_resource_address64 addr, *p = &addr;
256 acpi_status status;
257
258 status = acpi_resource_to_address64(res, p);
259 if (!ACPI_SUCCESS(status)) {
260 pnp_warn("PnPACPI: failed to convert resource type %d",
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700261 res->type);
Bjorn Helgaas1acfb7f2006-03-28 17:03:00 -0500262 return;
263 }
264
matthieu castet2b8de5f2006-08-05 12:15:12 -0700265 if (p->producer_consumer == ACPI_PRODUCER)
266 return;
267
Bjorn Helgaas1acfb7f2006-03-28 17:03:00 -0500268 if (p->resource_type == ACPI_MEMORY_RANGE)
269 pnpacpi_parse_allocated_memresource(res_table,
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700270 p->minimum, p->address_length,
271 p->info.mem.write_protect);
Bjorn Helgaas1acfb7f2006-03-28 17:03:00 -0500272 else if (p->resource_type == ACPI_IO_RANGE)
273 pnpacpi_parse_allocated_ioresource(res_table,
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700274 p->minimum, p->address_length,
275 p->granularity == 0xfff ? ACPI_DECODE_10 :
276 ACPI_DECODE_16);
Bjorn Helgaas1acfb7f2006-03-28 17:03:00 -0500277}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
279static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700280 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
Bjorn Helgaas4721a4cc2007-08-15 10:32:10 -0600282 struct pnp_resource_table *res_table = data;
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -0400283 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
Len Browneca008c2005-09-22 00:25:18 -0400285 switch (res->type) {
Bob Moore50eca3e2005-09-30 19:03:00 -0400286 case ACPI_RESOURCE_TYPE_IRQ:
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -0400287 /*
288 * Per spec, only one interrupt per descriptor is allowed in
289 * _CRS, but some firmware violates this, so parse them all.
290 */
Bob Moore50eca3e2005-09-30 19:03:00 -0400291 for (i = 0; i < res->data.irq.interrupt_count; i++) {
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -0400292 pnpacpi_parse_allocated_irqresource(res_table,
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700293 res->data.irq.interrupts[i],
294 res->data.irq.triggering,
295 res->data.irq.polarity,
296 res->data.irq.sharable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 }
298 break;
299
Bob Moore50eca3e2005-09-30 19:03:00 -0400300 case ACPI_RESOURCE_TYPE_DMA:
301 if (res->data.dma.channel_count > 0)
302 pnpacpi_parse_allocated_dmaresource(res_table,
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700303 res->data.dma.channels[0],
304 res->data.dma.type,
305 res->data.dma.bus_master,
306 res->data.dma.transfer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 break;
Len Brown0af58532006-01-20 01:11:37 -0500308
Bob Moore50eca3e2005-09-30 19:03:00 -0400309 case ACPI_RESOURCE_TYPE_IO:
310 pnpacpi_parse_allocated_ioresource(res_table,
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700311 res->data.io.minimum,
312 res->data.io.address_length,
313 res->data.io.io_decode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 break;
Len Brown0af58532006-01-20 01:11:37 -0500315
316 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
317 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
318 break;
319
Bob Moore50eca3e2005-09-30 19:03:00 -0400320 case ACPI_RESOURCE_TYPE_FIXED_IO:
321 pnpacpi_parse_allocated_ioresource(res_table,
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700322 res->data.fixed_io.address,
323 res->data.fixed_io.address_length,
324 ACPI_DECODE_10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 break;
Len Brown0af58532006-01-20 01:11:37 -0500326
327 case ACPI_RESOURCE_TYPE_VENDOR:
328 break;
329
330 case ACPI_RESOURCE_TYPE_END_TAG:
331 break;
332
Bob Moore50eca3e2005-09-30 19:03:00 -0400333 case ACPI_RESOURCE_TYPE_MEMORY24:
334 pnpacpi_parse_allocated_memresource(res_table,
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700335 res->data.memory24.minimum,
336 res->data.memory24.address_length,
337 res->data.memory24.write_protect);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400339 case ACPI_RESOURCE_TYPE_MEMORY32:
340 pnpacpi_parse_allocated_memresource(res_table,
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700341 res->data.memory32.minimum,
342 res->data.memory32.address_length,
343 res->data.memory32.write_protect);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400345 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
346 pnpacpi_parse_allocated_memresource(res_table,
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700347 res->data.fixed_memory32.address,
348 res->data.fixed_memory32.address_length,
349 res->data.fixed_memory32.write_protect);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400351 case ACPI_RESOURCE_TYPE_ADDRESS16:
Bob Moore50eca3e2005-09-30 19:03:00 -0400352 case ACPI_RESOURCE_TYPE_ADDRESS32:
Bob Moore50eca3e2005-09-30 19:03:00 -0400353 case ACPI_RESOURCE_TYPE_ADDRESS64:
Bjorn Helgaas1acfb7f2006-03-28 17:03:00 -0500354 pnpacpi_parse_allocated_address_space(res_table, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 break;
Len Brown0af58532006-01-20 01:11:37 -0500356
357 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
matthieu castet2b8de5f2006-08-05 12:15:12 -0700358 if (res->data.ext_address64.producer_consumer == ACPI_PRODUCER)
359 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 break;
Len Brown0af58532006-01-20 01:11:37 -0500361
362 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
matthieu castet2b8de5f2006-08-05 12:15:12 -0700363 if (res->data.extended_irq.producer_consumer == ACPI_PRODUCER)
364 return AE_OK;
365
Len Brown0af58532006-01-20 01:11:37 -0500366 for (i = 0; i < res->data.extended_irq.interrupt_count; i++) {
367 pnpacpi_parse_allocated_irqresource(res_table,
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700368 res->data.extended_irq.interrupts[i],
369 res->data.extended_irq.triggering,
370 res->data.extended_irq.polarity,
371 res->data.extended_irq.sharable);
Len Brown0af58532006-01-20 01:11:37 -0500372 }
373 break;
374
375 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
376 break;
377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 default:
Len Browneca008c2005-09-22 00:25:18 -0400379 pnp_warn("PnPACPI: unknown resource type %d", res->type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 return AE_ERROR;
381 }
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500382
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 return AE_OK;
384}
385
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700386acpi_status pnpacpi_parse_allocated_resource(acpi_handle handle,
387 struct pnp_resource_table * res)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388{
389 /* Blank the resource table values */
390 pnp_init_resource_table(res);
391
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700392 return acpi_walk_resources(handle, METHOD_NAME__CRS,
393 pnpacpi_allocated_resource, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394}
395
Thomas Renninger2bb9a6b2008-02-06 01:40:03 -0800396static __init void pnpacpi_parse_dma_option(struct pnp_option *option,
397 struct acpi_resource_dma *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398{
399 int i;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700400 struct pnp_dma *dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
Bob Moore50eca3e2005-09-30 19:03:00 -0400402 if (p->channel_count == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 return;
Robert P. J. Daycd861282006-12-13 00:34:52 -0800404 dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 if (!dma)
406 return;
407
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700408 for (i = 0; i < p->channel_count; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 dma->map |= 1 << p->channels[i];
Michael Karcher362ea082007-03-08 23:29:29 -0500410
411 dma->flags = dma_flags(p->type, p->bus_master, p->transfer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500413 pnp_register_dma_resource(option, dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414}
415
Thomas Renninger2bb9a6b2008-02-06 01:40:03 -0800416static __init void pnpacpi_parse_irq_option(struct pnp_option *option,
417 struct acpi_resource_irq *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418{
419 int i;
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500420 struct pnp_irq *irq;
421
Bob Moore50eca3e2005-09-30 19:03:00 -0400422 if (p->interrupt_count == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 return;
Robert P. J. Daycd861282006-12-13 00:34:52 -0800424 irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 if (!irq)
426 return;
427
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700428 for (i = 0; i < p->interrupt_count; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 if (p->interrupts[i])
430 __set_bit(p->interrupts[i], irq->map);
Bob Moore50eca3e2005-09-30 19:03:00 -0400431 irq->flags = irq_flags(p->triggering, p->polarity);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
433 pnp_register_irq_resource(option, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434}
435
Thomas Renninger2bb9a6b2008-02-06 01:40:03 -0800436static __init void pnpacpi_parse_ext_irq_option(struct pnp_option *option,
437 struct acpi_resource_extended_irq *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438{
439 int i;
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500440 struct pnp_irq *irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
Bob Moore50eca3e2005-09-30 19:03:00 -0400442 if (p->interrupt_count == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 return;
Robert P. J. Daycd861282006-12-13 00:34:52 -0800444 irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 if (!irq)
446 return;
447
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700448 for (i = 0; i < p->interrupt_count; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 if (p->interrupts[i])
450 __set_bit(p->interrupts[i], irq->map);
Bob Moore50eca3e2005-09-30 19:03:00 -0400451 irq->flags = irq_flags(p->triggering, p->polarity);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
453 pnp_register_irq_resource(option, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454}
455
Thomas Renninger2bb9a6b2008-02-06 01:40:03 -0800456static __init void pnpacpi_parse_port_option(struct pnp_option *option,
457 struct acpi_resource_io *io)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458{
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500459 struct pnp_port *port;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
Bob Moore50eca3e2005-09-30 19:03:00 -0400461 if (io->address_length == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 return;
Robert P. J. Daycd861282006-12-13 00:34:52 -0800463 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 if (!port)
465 return;
Bob Moore50eca3e2005-09-30 19:03:00 -0400466 port->min = io->minimum;
467 port->max = io->maximum;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 port->align = io->alignment;
Bob Moore50eca3e2005-09-30 19:03:00 -0400469 port->size = io->address_length;
470 port->flags = ACPI_DECODE_16 == io->io_decode ?
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700471 PNP_PORT_FLAG_16BITADDR : 0;
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500472 pnp_register_port_resource(option, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473}
474
Thomas Renninger2bb9a6b2008-02-06 01:40:03 -0800475static __init void pnpacpi_parse_fixed_port_option(struct pnp_option *option,
476 struct acpi_resource_fixed_io *io)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477{
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500478 struct pnp_port *port;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
Bob Moore50eca3e2005-09-30 19:03:00 -0400480 if (io->address_length == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 return;
Robert P. J. Daycd861282006-12-13 00:34:52 -0800482 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 if (!port)
484 return;
Bob Moore50eca3e2005-09-30 19:03:00 -0400485 port->min = port->max = io->address;
486 port->size = io->address_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 port->align = 0;
488 port->flags = PNP_PORT_FLAG_FIXED;
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500489 pnp_register_port_resource(option, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490}
491
Thomas Renninger2bb9a6b2008-02-06 01:40:03 -0800492static __init void pnpacpi_parse_mem24_option(struct pnp_option *option,
493 struct acpi_resource_memory24 *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494{
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500495 struct pnp_mem *mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
Bob Moore50eca3e2005-09-30 19:03:00 -0400497 if (p->address_length == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 return;
Robert P. J. Daycd861282006-12-13 00:34:52 -0800499 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 if (!mem)
501 return;
Bob Moore50eca3e2005-09-30 19:03:00 -0400502 mem->min = p->minimum;
503 mem->max = p->maximum;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 mem->align = p->alignment;
Bob Moore50eca3e2005-09-30 19:03:00 -0400505 mem->size = p->address_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Bob Moore08978312005-10-21 00:00:00 -0400507 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700508 IORESOURCE_MEM_WRITEABLE : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500510 pnp_register_mem_resource(option, mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511}
512
Thomas Renninger2bb9a6b2008-02-06 01:40:03 -0800513static __init void pnpacpi_parse_mem32_option(struct pnp_option *option,
514 struct acpi_resource_memory32 *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515{
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500516 struct pnp_mem *mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
Bob Moore50eca3e2005-09-30 19:03:00 -0400518 if (p->address_length == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 return;
Robert P. J. Daycd861282006-12-13 00:34:52 -0800520 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 if (!mem)
522 return;
Bob Moore50eca3e2005-09-30 19:03:00 -0400523 mem->min = p->minimum;
524 mem->max = p->maximum;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 mem->align = p->alignment;
Bob Moore50eca3e2005-09-30 19:03:00 -0400526 mem->size = p->address_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Bob Moore08978312005-10-21 00:00:00 -0400528 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700529 IORESOURCE_MEM_WRITEABLE : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500531 pnp_register_mem_resource(option, mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532}
533
Thomas Renninger2bb9a6b2008-02-06 01:40:03 -0800534static __init void pnpacpi_parse_fixed_mem32_option(struct pnp_option *option,
535 struct acpi_resource_fixed_memory32 *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536{
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500537 struct pnp_mem *mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
Bob Moore50eca3e2005-09-30 19:03:00 -0400539 if (p->address_length == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 return;
Robert P. J. Daycd861282006-12-13 00:34:52 -0800541 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 if (!mem)
543 return;
Bob Moore50eca3e2005-09-30 19:03:00 -0400544 mem->min = mem->max = p->address;
545 mem->size = p->address_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 mem->align = 0;
547
Bob Moore08978312005-10-21 00:00:00 -0400548 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700549 IORESOURCE_MEM_WRITEABLE : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500551 pnp_register_mem_resource(option, mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552}
553
Thomas Renninger2bb9a6b2008-02-06 01:40:03 -0800554static __init void pnpacpi_parse_address_option(struct pnp_option *option,
555 struct acpi_resource *r)
Bjorn Helgaas6f957ea2005-09-20 15:26:00 -0400556{
557 struct acpi_resource_address64 addr, *p = &addr;
558 acpi_status status;
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500559 struct pnp_mem *mem;
560 struct pnp_port *port;
Bjorn Helgaas6f957ea2005-09-20 15:26:00 -0400561
562 status = acpi_resource_to_address64(r, p);
563 if (!ACPI_SUCCESS(status)) {
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700564 pnp_warn("PnPACPI: failed to convert resource type %d",
565 r->type);
Bjorn Helgaas6f957ea2005-09-20 15:26:00 -0400566 return;
567 }
568
569 if (p->address_length == 0)
570 return;
571
572 if (p->resource_type == ACPI_MEMORY_RANGE) {
Robert P. J. Daycd861282006-12-13 00:34:52 -0800573 mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
Bjorn Helgaas6f957ea2005-09-20 15:26:00 -0400574 if (!mem)
575 return;
Len Browned03f432006-01-07 03:50:18 -0500576 mem->min = mem->max = p->minimum;
Bjorn Helgaas6f957ea2005-09-20 15:26:00 -0400577 mem->size = p->address_length;
578 mem->align = 0;
Len Browned03f432006-01-07 03:50:18 -0500579 mem->flags = (p->info.mem.write_protect ==
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700580 ACPI_READ_WRITE_MEMORY) ? IORESOURCE_MEM_WRITEABLE
581 : 0;
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500582 pnp_register_mem_resource(option, mem);
Bjorn Helgaas6f957ea2005-09-20 15:26:00 -0400583 } else if (p->resource_type == ACPI_IO_RANGE) {
Robert P. J. Daycd861282006-12-13 00:34:52 -0800584 port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
Bjorn Helgaas6f957ea2005-09-20 15:26:00 -0400585 if (!port)
586 return;
Len Browned03f432006-01-07 03:50:18 -0500587 port->min = port->max = p->minimum;
Bjorn Helgaas6f957ea2005-09-20 15:26:00 -0400588 port->size = p->address_length;
589 port->align = 0;
590 port->flags = PNP_PORT_FLAG_FIXED;
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500591 pnp_register_port_resource(option, port);
Bjorn Helgaas6f957ea2005-09-20 15:26:00 -0400592 }
593}
594
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595struct acpipnp_parse_option_s {
596 struct pnp_option *option;
Matthieu Castetb008b8d2005-03-25 12:03:15 -0500597 struct pnp_option *option_independent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 struct pnp_dev *dev;
599};
600
Thomas Renninger2bb9a6b2008-02-06 01:40:03 -0800601static __init acpi_status pnpacpi_option_resource(struct acpi_resource *res,
602 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603{
604 int priority = 0;
Bjorn Helgaas4721a4cc2007-08-15 10:32:10 -0600605 struct acpipnp_parse_option_s *parse_data = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 struct pnp_dev *dev = parse_data->dev;
607 struct pnp_option *option = parse_data->option;
608
Len Browneca008c2005-09-22 00:25:18 -0400609 switch (res->type) {
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700610 case ACPI_RESOURCE_TYPE_IRQ:
611 pnpacpi_parse_irq_option(option, &res->data.irq);
612 break;
613
614 case ACPI_RESOURCE_TYPE_DMA:
615 pnpacpi_parse_dma_option(option, &res->data.dma);
616 break;
617
618 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
619 switch (res->data.start_dpf.compatibility_priority) {
620 case ACPI_GOOD_CONFIGURATION:
621 priority = PNP_RES_PRIORITY_PREFERRED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 break;
Len Brown0af58532006-01-20 01:11:37 -0500623
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700624 case ACPI_ACCEPTABLE_CONFIGURATION:
625 priority = PNP_RES_PRIORITY_ACCEPTABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 break;
Len Brown0af58532006-01-20 01:11:37 -0500627
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700628 case ACPI_SUB_OPTIMAL_CONFIGURATION:
629 priority = PNP_RES_PRIORITY_FUNCTIONAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 default:
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700632 priority = PNP_RES_PRIORITY_INVALID;
633 break;
634 }
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700635 /* TBD: Consider performance/robustness bits */
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700636 option = pnp_register_dependent_option(dev, priority);
637 if (!option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 return AE_ERROR;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700639 parse_data->option = option;
640 break;
641
642 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
643 /*only one EndDependentFn is allowed */
644 if (!parse_data->option_independent) {
645 pnp_warn("PnPACPI: more than one EndDependentFn");
646 return AE_ERROR;
647 }
648 parse_data->option = parse_data->option_independent;
649 parse_data->option_independent = NULL;
650 break;
651
652 case ACPI_RESOURCE_TYPE_IO:
653 pnpacpi_parse_port_option(option, &res->data.io);
654 break;
655
656 case ACPI_RESOURCE_TYPE_FIXED_IO:
657 pnpacpi_parse_fixed_port_option(option, &res->data.fixed_io);
658 break;
659
660 case ACPI_RESOURCE_TYPE_VENDOR:
661 case ACPI_RESOURCE_TYPE_END_TAG:
662 break;
663
664 case ACPI_RESOURCE_TYPE_MEMORY24:
665 pnpacpi_parse_mem24_option(option, &res->data.memory24);
666 break;
667
668 case ACPI_RESOURCE_TYPE_MEMORY32:
669 pnpacpi_parse_mem32_option(option, &res->data.memory32);
670 break;
671
672 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
673 pnpacpi_parse_fixed_mem32_option(option,
674 &res->data.fixed_memory32);
675 break;
676
677 case ACPI_RESOURCE_TYPE_ADDRESS16:
678 case ACPI_RESOURCE_TYPE_ADDRESS32:
679 case ACPI_RESOURCE_TYPE_ADDRESS64:
680 pnpacpi_parse_address_option(option, res);
681 break;
682
683 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
684 break;
685
686 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
687 pnpacpi_parse_ext_irq_option(option, &res->data.extended_irq);
688 break;
689
690 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
691 break;
692
693 default:
694 pnp_warn("PnPACPI: unknown resource type %d", res->type);
695 return AE_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 }
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500697
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 return AE_OK;
699}
700
Thomas Renninger2bb9a6b2008-02-06 01:40:03 -0800701acpi_status __init pnpacpi_parse_resource_option_data(acpi_handle handle,
702 struct pnp_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703{
704 acpi_status status;
705 struct acpipnp_parse_option_s parse_data;
706
707 parse_data.option = pnp_register_independent_option(dev);
708 if (!parse_data.option)
709 return AE_ERROR;
Matthieu Castetb008b8d2005-03-25 12:03:15 -0500710 parse_data.option_independent = parse_data.option;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 parse_data.dev = dev;
Bob Moore50eca3e2005-09-30 19:03:00 -0400712 status = acpi_walk_resources(handle, METHOD_NAME__PRS,
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700713 pnpacpi_option_resource, &parse_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
715 return status;
716}
717
Bjorn Helgaasb5f2490b2006-03-28 17:04:00 -0500718static int pnpacpi_supported_resource(struct acpi_resource *res)
719{
720 switch (res->type) {
721 case ACPI_RESOURCE_TYPE_IRQ:
722 case ACPI_RESOURCE_TYPE_DMA:
723 case ACPI_RESOURCE_TYPE_IO:
724 case ACPI_RESOURCE_TYPE_FIXED_IO:
725 case ACPI_RESOURCE_TYPE_MEMORY24:
726 case ACPI_RESOURCE_TYPE_MEMORY32:
727 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
728 case ACPI_RESOURCE_TYPE_ADDRESS16:
729 case ACPI_RESOURCE_TYPE_ADDRESS32:
730 case ACPI_RESOURCE_TYPE_ADDRESS64:
731 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
732 return 1;
733 }
734 return 0;
735}
736
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737/*
738 * Set resource
739 */
740static acpi_status pnpacpi_count_resources(struct acpi_resource *res,
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700741 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742{
Bjorn Helgaas4721a4cc2007-08-15 10:32:10 -0600743 int *res_cnt = data;
Bjorn Helgaasb5f2490b2006-03-28 17:04:00 -0500744
745 if (pnpacpi_supported_resource(res))
746 (*res_cnt)++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 return AE_OK;
748}
749
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500750static acpi_status pnpacpi_type_resources(struct acpi_resource *res, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751{
Bjorn Helgaas4721a4cc2007-08-15 10:32:10 -0600752 struct acpi_resource **resource = data;
Bjorn Helgaasb5f2490b2006-03-28 17:04:00 -0500753
754 if (pnpacpi_supported_resource(res)) {
Len Browneca008c2005-09-22 00:25:18 -0400755 (*resource)->type = res->type;
Bjorn Helgaasb5f2490b2006-03-28 17:04:00 -0500756 (*resource)->length = sizeof(struct acpi_resource);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 (*resource)++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 }
759
760 return AE_OK;
761}
762
Bob Moore50eca3e2005-09-30 19:03:00 -0400763int pnpacpi_build_resource_template(acpi_handle handle,
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700764 struct acpi_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765{
766 struct acpi_resource *resource;
767 int res_cnt = 0;
768 acpi_status status;
769
Bob Moore50eca3e2005-09-30 19:03:00 -0400770 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700771 pnpacpi_count_resources, &res_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 if (ACPI_FAILURE(status)) {
773 pnp_err("Evaluate _CRS failed");
774 return -EINVAL;
775 }
776 if (!res_cnt)
777 return -EINVAL;
778 buffer->length = sizeof(struct acpi_resource) * (res_cnt + 1) + 1;
Robert P. J. Daycd861282006-12-13 00:34:52 -0800779 buffer->pointer = kzalloc(buffer->length - 1, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 if (!buffer->pointer)
781 return -ENOMEM;
782 pnp_dbg("Res cnt %d", res_cnt);
783 resource = (struct acpi_resource *)buffer->pointer;
Bob Moore50eca3e2005-09-30 19:03:00 -0400784 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700785 pnpacpi_type_resources, &resource);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 if (ACPI_FAILURE(status)) {
787 kfree(buffer->pointer);
788 pnp_err("Evaluate _CRS failed");
789 return -EINVAL;
790 }
791 /* resource will pointer the end resource now */
Bob Moore50eca3e2005-09-30 19:03:00 -0400792 resource->type = ACPI_RESOURCE_TYPE_END_TAG;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
794 return 0;
795}
796
Bob Moore50eca3e2005-09-30 19:03:00 -0400797static void pnpacpi_encode_irq(struct acpi_resource *resource,
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700798 struct resource *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799{
Bob Moore50eca3e2005-09-30 19:03:00 -0400800 int triggering, polarity;
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500801
802 decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
Bob Moore50eca3e2005-09-30 19:03:00 -0400803 resource->data.irq.triggering = triggering;
804 resource->data.irq.polarity = polarity;
805 if (triggering == ACPI_EDGE_SENSITIVE)
806 resource->data.irq.sharable = ACPI_EXCLUSIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 else
Bob Moore50eca3e2005-09-30 19:03:00 -0400808 resource->data.irq.sharable = ACPI_SHARED;
809 resource->data.irq.interrupt_count = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 resource->data.irq.interrupts[0] = p->start;
811}
812
813static void pnpacpi_encode_ext_irq(struct acpi_resource *resource,
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700814 struct resource *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815{
Bob Moore50eca3e2005-09-30 19:03:00 -0400816 int triggering, polarity;
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500817
818 decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 resource->data.extended_irq.producer_consumer = ACPI_CONSUMER;
Bob Moore50eca3e2005-09-30 19:03:00 -0400820 resource->data.extended_irq.triggering = triggering;
821 resource->data.extended_irq.polarity = polarity;
822 if (triggering == ACPI_EDGE_SENSITIVE)
823 resource->data.irq.sharable = ACPI_EXCLUSIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 else
Bob Moore50eca3e2005-09-30 19:03:00 -0400825 resource->data.irq.sharable = ACPI_SHARED;
826 resource->data.extended_irq.interrupt_count = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 resource->data.extended_irq.interrupts[0] = p->start;
828}
829
830static void pnpacpi_encode_dma(struct acpi_resource *resource,
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700831 struct resource *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
Vojtech Pavlikccc4c7b2006-04-07 20:00:27 +0200834 switch (p->flags & IORESOURCE_DMA_SPEED_MASK) {
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700835 case IORESOURCE_DMA_TYPEA:
836 resource->data.dma.type = ACPI_TYPE_A;
837 break;
838 case IORESOURCE_DMA_TYPEB:
839 resource->data.dma.type = ACPI_TYPE_B;
840 break;
841 case IORESOURCE_DMA_TYPEF:
842 resource->data.dma.type = ACPI_TYPE_F;
843 break;
844 default:
845 resource->data.dma.type = ACPI_COMPATIBILITY;
Vojtech Pavlikccc4c7b2006-04-07 20:00:27 +0200846 }
847
848 switch (p->flags & IORESOURCE_DMA_TYPE_MASK) {
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700849 case IORESOURCE_DMA_8BIT:
850 resource->data.dma.transfer = ACPI_TRANSFER_8;
851 break;
852 case IORESOURCE_DMA_8AND16BIT:
853 resource->data.dma.transfer = ACPI_TRANSFER_8_16;
854 break;
855 default:
856 resource->data.dma.transfer = ACPI_TRANSFER_16;
Vojtech Pavlikccc4c7b2006-04-07 20:00:27 +0200857 }
858
859 resource->data.dma.bus_master = !!(p->flags & IORESOURCE_DMA_MASTER);
Bob Moore50eca3e2005-09-30 19:03:00 -0400860 resource->data.dma.channel_count = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 resource->data.dma.channels[0] = p->start;
862}
863
864static void pnpacpi_encode_io(struct acpi_resource *resource,
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700865 struct resource *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700868 resource->data.io.io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR) ?
869 ACPI_DECODE_16 : ACPI_DECODE_10;
Bob Moore50eca3e2005-09-30 19:03:00 -0400870 resource->data.io.minimum = p->start;
871 resource->data.io.maximum = p->end;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700872 resource->data.io.alignment = 0; /* Correct? */
Bob Moore50eca3e2005-09-30 19:03:00 -0400873 resource->data.io.address_length = p->end - p->start + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874}
875
876static void pnpacpi_encode_fixed_io(struct acpi_resource *resource,
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700877 struct resource *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878{
Bob Moore50eca3e2005-09-30 19:03:00 -0400879 resource->data.fixed_io.address = p->start;
880 resource->data.fixed_io.address_length = p->end - p->start + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881}
882
883static void pnpacpi_encode_mem24(struct acpi_resource *resource,
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700884 struct resource *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */
Bob Moore08978312005-10-21 00:00:00 -0400887 resource->data.memory24.write_protect =
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700888 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
889 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
Bob Moore50eca3e2005-09-30 19:03:00 -0400890 resource->data.memory24.minimum = p->start;
891 resource->data.memory24.maximum = p->end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 resource->data.memory24.alignment = 0;
Bob Moore50eca3e2005-09-30 19:03:00 -0400893 resource->data.memory24.address_length = p->end - p->start + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894}
895
896static void pnpacpi_encode_mem32(struct acpi_resource *resource,
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700897 struct resource *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898{
Bob Moore08978312005-10-21 00:00:00 -0400899 resource->data.memory32.write_protect =
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700900 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
901 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
Bob Moore50eca3e2005-09-30 19:03:00 -0400902 resource->data.memory32.minimum = p->start;
903 resource->data.memory32.maximum = p->end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 resource->data.memory32.alignment = 0;
Bob Moore50eca3e2005-09-30 19:03:00 -0400905 resource->data.memory32.address_length = p->end - p->start + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906}
907
908static void pnpacpi_encode_fixed_mem32(struct acpi_resource *resource,
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700909 struct resource *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910{
Bob Moore08978312005-10-21 00:00:00 -0400911 resource->data.fixed_memory32.write_protect =
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700912 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
913 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
Bob Moore50eca3e2005-09-30 19:03:00 -0400914 resource->data.fixed_memory32.address = p->start;
915 resource->data.fixed_memory32.address_length = p->end - p->start + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916}
917
Bob Moore50eca3e2005-09-30 19:03:00 -0400918int pnpacpi_encode_resources(struct pnp_resource_table *res_table,
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700919 struct acpi_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920{
921 int i = 0;
922 /* pnpacpi_build_resource_template allocates extra mem */
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700923 int res_cnt = (buffer->length - 1) / sizeof(struct acpi_resource) - 1;
Bjorn Helgaas4721a4cc2007-08-15 10:32:10 -0600924 struct acpi_resource *resource = buffer->pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 int port = 0, irq = 0, dma = 0, mem = 0;
926
927 pnp_dbg("res cnt %d", res_cnt);
928 while (i < res_cnt) {
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700929 switch (resource->type) {
Bob Moore50eca3e2005-09-30 19:03:00 -0400930 case ACPI_RESOURCE_TYPE_IRQ:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 pnp_dbg("Encode irq");
Bob Moore50eca3e2005-09-30 19:03:00 -0400932 pnpacpi_encode_irq(resource,
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700933 &res_table->irq_resource[irq]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 irq++;
935 break;
936
Bob Moore50eca3e2005-09-30 19:03:00 -0400937 case ACPI_RESOURCE_TYPE_DMA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 pnp_dbg("Encode dma");
Bob Moore50eca3e2005-09-30 19:03:00 -0400939 pnpacpi_encode_dma(resource,
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700940 &res_table->dma_resource[dma]);
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500941 dma++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400943 case ACPI_RESOURCE_TYPE_IO:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 pnp_dbg("Encode io");
Bob Moore50eca3e2005-09-30 19:03:00 -0400945 pnpacpi_encode_io(resource,
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700946 &res_table->port_resource[port]);
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500947 port++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400949 case ACPI_RESOURCE_TYPE_FIXED_IO:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 pnp_dbg("Encode fixed io");
951 pnpacpi_encode_fixed_io(resource,
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700952 &res_table->
953 port_resource[port]);
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500954 port++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400956 case ACPI_RESOURCE_TYPE_MEMORY24:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 pnp_dbg("Encode mem24");
958 pnpacpi_encode_mem24(resource,
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700959 &res_table->mem_resource[mem]);
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500960 mem++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400962 case ACPI_RESOURCE_TYPE_MEMORY32:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 pnp_dbg("Encode mem32");
964 pnpacpi_encode_mem32(resource,
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700965 &res_table->mem_resource[mem]);
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500966 mem++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400968 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 pnp_dbg("Encode fixed mem32");
970 pnpacpi_encode_fixed_mem32(resource,
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700971 &res_table->
972 mem_resource[mem]);
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500973 mem++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 break;
Len Brown0af58532006-01-20 01:11:37 -0500975 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
976 pnp_dbg("Encode ext irq");
977 pnpacpi_encode_ext_irq(resource,
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700978 &res_table->irq_resource[irq]);
Len Brown0af58532006-01-20 01:11:37 -0500979 irq++;
980 break;
981 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
982 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
983 case ACPI_RESOURCE_TYPE_VENDOR:
984 case ACPI_RESOURCE_TYPE_END_TAG:
985 case ACPI_RESOURCE_TYPE_ADDRESS16:
986 case ACPI_RESOURCE_TYPE_ADDRESS32:
987 case ACPI_RESOURCE_TYPE_ADDRESS64:
988 case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
989 case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700990 default: /* other type */
Len Browneca008c2005-09-22 00:25:18 -0400991 pnp_warn("unknown resource type %d", resource->type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 return -EINVAL;
993 }
Bjorn Helgaas1c6e7d02006-03-28 17:04:00 -0500994 resource++;
995 i++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 }
997 return 0;
998}