blob: c6db14d30ed6d155ca323e698b9f06e08820669a [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{
37 int flag;
Bob Moore50eca3e2005-09-30 19:03:00 -040038 if (triggering == ACPI_LEVEL_SENSITIVE) {
39 if(polarity == ACPI_ACTIVE_LOW)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 flag = IORESOURCE_IRQ_LOWLEVEL;
41 else
42 flag = IORESOURCE_IRQ_HIGHLEVEL;
43 }
44 else {
Bob Moore50eca3e2005-09-30 19:03:00 -040045 if(polarity == ACPI_ACTIVE_LOW)
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 flag = IORESOURCE_IRQ_LOWEDGE;
47 else
48 flag = IORESOURCE_IRQ_HIGHEDGE;
49 }
50 return flag;
51}
52
Bob Moore50eca3e2005-09-30 19:03:00 -040053static void decode_irq_flags(int flag, int *triggering, int *polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054{
55 switch (flag) {
56 case IORESOURCE_IRQ_LOWLEVEL:
Bob Moore50eca3e2005-09-30 19:03:00 -040057 *triggering = ACPI_LEVEL_SENSITIVE;
58 *polarity = ACPI_ACTIVE_LOW;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 break;
60 case IORESOURCE_IRQ_HIGHLEVEL:
Bob Moore50eca3e2005-09-30 19:03:00 -040061 *triggering = ACPI_LEVEL_SENSITIVE;
62 *polarity = ACPI_ACTIVE_HIGH;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 break;
64 case IORESOURCE_IRQ_LOWEDGE:
Bob Moore50eca3e2005-09-30 19:03:00 -040065 *triggering = ACPI_EDGE_SENSITIVE;
66 *polarity = ACPI_ACTIVE_LOW;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 break;
68 case IORESOURCE_IRQ_HIGHEDGE:
Bob Moore50eca3e2005-09-30 19:03:00 -040069 *triggering = ACPI_EDGE_SENSITIVE;
70 *polarity = ACPI_ACTIVE_HIGH;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 break;
72 }
73}
74
75static void
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -040076pnpacpi_parse_allocated_irqresource(struct pnp_resource_table * res, u32 gsi,
Bob Moore50eca3e2005-09-30 19:03:00 -040077 int triggering, int polarity)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078{
79 int i = 0;
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -040080 int irq;
81
82 if (!valid_IRQ(gsi))
83 return;
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 while (!(res->irq_resource[i].flags & IORESOURCE_UNSET) &&
86 i < PNP_MAX_IRQ)
87 i++;
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -040088 if (i >= PNP_MAX_IRQ)
89 return;
90
91 res->irq_resource[i].flags = IORESOURCE_IRQ; // Also clears _UNSET flag
Bob Moore50eca3e2005-09-30 19:03:00 -040092 irq = acpi_register_gsi(gsi, triggering, polarity);
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -040093 if (irq < 0) {
94 res->irq_resource[i].flags |= IORESOURCE_DISABLED;
95 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 }
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -040097
98 res->irq_resource[i].start = irq;
99 res->irq_resource[i].end = irq;
100 pcibios_penalize_isa_irq(irq, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101}
102
103static void
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -0400104pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table * res, u32 dma)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105{
106 int i = 0;
Adrian Bunk0dec63b2005-05-01 08:59:30 -0700107 while (i < PNP_MAX_DMA &&
108 !(res->dma_resource[i].flags & IORESOURCE_UNSET))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 i++;
110 if (i < PNP_MAX_DMA) {
111 res->dma_resource[i].flags = IORESOURCE_DMA; // Also clears _UNSET flag
112 if (dma == -1) {
113 res->dma_resource[i].flags |= IORESOURCE_DISABLED;
114 return;
115 }
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -0400116 res->dma_resource[i].start = dma;
117 res->dma_resource[i].end = dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 }
119}
120
121static void
122pnpacpi_parse_allocated_ioresource(struct pnp_resource_table * res,
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -0400123 u32 io, u32 len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
125 int i = 0;
126 while (!(res->port_resource[i].flags & IORESOURCE_UNSET) &&
127 i < PNP_MAX_PORT)
128 i++;
129 if (i < PNP_MAX_PORT) {
130 res->port_resource[i].flags = IORESOURCE_IO; // Also clears _UNSET flag
131 if (len <= 0 || (io + len -1) >= 0x10003) {
132 res->port_resource[i].flags |= IORESOURCE_DISABLED;
133 return;
134 }
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -0400135 res->port_resource[i].start = io;
136 res->port_resource[i].end = io + len - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 }
138}
139
140static void
141pnpacpi_parse_allocated_memresource(struct pnp_resource_table * res,
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -0400142 u64 mem, u64 len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143{
144 int i = 0;
145 while (!(res->mem_resource[i].flags & IORESOURCE_UNSET) &&
146 (i < PNP_MAX_MEM))
147 i++;
148 if (i < PNP_MAX_MEM) {
149 res->mem_resource[i].flags = IORESOURCE_MEM; // Also clears _UNSET flag
150 if (len <= 0) {
151 res->mem_resource[i].flags |= IORESOURCE_DISABLED;
152 return;
153 }
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -0400154 res->mem_resource[i].start = mem;
155 res->mem_resource[i].end = mem + len - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 }
157}
158
159
160static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
161 void *data)
162{
163 struct pnp_resource_table * res_table = (struct pnp_resource_table *)data;
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -0400164 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Len Browneca008c2005-09-22 00:25:18 -0400166 switch (res->type) {
Bob Moore50eca3e2005-09-30 19:03:00 -0400167 case ACPI_RESOURCE_TYPE_IRQ:
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -0400168 /*
169 * Per spec, only one interrupt per descriptor is allowed in
170 * _CRS, but some firmware violates this, so parse them all.
171 */
Bob Moore50eca3e2005-09-30 19:03:00 -0400172 for (i = 0; i < res->data.irq.interrupt_count; i++) {
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -0400173 pnpacpi_parse_allocated_irqresource(res_table,
174 res->data.irq.interrupts[i],
Bob Moore50eca3e2005-09-30 19:03:00 -0400175 res->data.irq.triggering,
176 res->data.irq.polarity);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 }
178 break;
179
Bob Moore50eca3e2005-09-30 19:03:00 -0400180 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
181 for (i = 0; i < res->data.extended_irq.interrupt_count; i++) {
Bjorn Helgaasdbed12d2005-09-03 00:37:56 -0400182 pnpacpi_parse_allocated_irqresource(res_table,
183 res->data.extended_irq.interrupts[i],
Bob Moore50eca3e2005-09-30 19:03:00 -0400184 res->data.extended_irq.triggering,
185 res->data.extended_irq.polarity);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 }
187 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400188 case ACPI_RESOURCE_TYPE_DMA:
189 if (res->data.dma.channel_count > 0)
190 pnpacpi_parse_allocated_dmaresource(res_table,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 res->data.dma.channels[0]);
192 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400193 case ACPI_RESOURCE_TYPE_IO:
194 pnpacpi_parse_allocated_ioresource(res_table,
195 res->data.io.minimum,
196 res->data.io.address_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400198 case ACPI_RESOURCE_TYPE_FIXED_IO:
199 pnpacpi_parse_allocated_ioresource(res_table,
200 res->data.fixed_io.address,
201 res->data.fixed_io.address_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400203 case ACPI_RESOURCE_TYPE_MEMORY24:
204 pnpacpi_parse_allocated_memresource(res_table,
205 res->data.memory24.minimum,
206 res->data.memory24.address_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400208 case ACPI_RESOURCE_TYPE_MEMORY32:
209 pnpacpi_parse_allocated_memresource(res_table,
210 res->data.memory32.minimum,
211 res->data.memory32.address_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400213 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
214 pnpacpi_parse_allocated_memresource(res_table,
215 res->data.fixed_memory32.address,
216 res->data.fixed_memory32.address_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400218 case ACPI_RESOURCE_TYPE_ADDRESS16:
219 pnpacpi_parse_allocated_memresource(res_table,
220 res->data.address16.minimum,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 res->data.address16.address_length);
222 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400223 case ACPI_RESOURCE_TYPE_ADDRESS32:
224 pnpacpi_parse_allocated_memresource(res_table,
225 res->data.address32.minimum,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 res->data.address32.address_length);
227 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400228 case ACPI_RESOURCE_TYPE_ADDRESS64:
229 pnpacpi_parse_allocated_memresource(res_table,
230 res->data.address64.minimum,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 res->data.address64.address_length);
232 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400233 case ACPI_RESOURCE_TYPE_VENDOR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 break;
235 default:
Len Browneca008c2005-09-22 00:25:18 -0400236 pnp_warn("PnPACPI: unknown resource type %d", res->type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 return AE_ERROR;
238 }
239
240 return AE_OK;
241}
242
243acpi_status pnpacpi_parse_allocated_resource(acpi_handle handle, struct pnp_resource_table * res)
244{
245 /* Blank the resource table values */
246 pnp_init_resource_table(res);
247
248 return acpi_walk_resources(handle, METHOD_NAME__CRS, pnpacpi_allocated_resource, res);
249}
250
251static void pnpacpi_parse_dma_option(struct pnp_option *option, struct acpi_resource_dma *p)
252{
253 int i;
254 struct pnp_dma * dma;
255
Bob Moore50eca3e2005-09-30 19:03:00 -0400256 if (p->channel_count == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 return;
Bjorn Helgaasa2822e72005-09-06 15:16:51 -0700258 dma = kcalloc(1, sizeof(struct pnp_dma), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 if (!dma)
260 return;
261
Bob Moore50eca3e2005-09-30 19:03:00 -0400262 for(i = 0; i < p->channel_count; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 dma->map |= 1 << p->channels[i];
264 dma->flags = 0;
265 if (p->bus_master)
266 dma->flags |= IORESOURCE_DMA_MASTER;
267 switch (p->type) {
268 case ACPI_COMPATIBILITY:
269 dma->flags |= IORESOURCE_DMA_COMPATIBLE;
270 break;
271 case ACPI_TYPE_A:
272 dma->flags |= IORESOURCE_DMA_TYPEA;
273 break;
274 case ACPI_TYPE_B:
275 dma->flags |= IORESOURCE_DMA_TYPEB;
276 break;
277 case ACPI_TYPE_F:
278 dma->flags |= IORESOURCE_DMA_TYPEF;
279 break;
280 default:
281 /* Set a default value ? */
282 dma->flags |= IORESOURCE_DMA_COMPATIBLE;
283 pnp_err("Invalid DMA type");
284 }
285 switch (p->transfer) {
286 case ACPI_TRANSFER_8:
287 dma->flags |= IORESOURCE_DMA_8BIT;
288 break;
289 case ACPI_TRANSFER_8_16:
290 dma->flags |= IORESOURCE_DMA_8AND16BIT;
291 break;
292 case ACPI_TRANSFER_16:
293 dma->flags |= IORESOURCE_DMA_16BIT;
294 break;
295 default:
296 /* Set a default value ? */
297 dma->flags |= IORESOURCE_DMA_8AND16BIT;
298 pnp_err("Invalid DMA transfer type");
299 }
300
301 pnp_register_dma_resource(option,dma);
302 return;
303}
304
305
306static void pnpacpi_parse_irq_option(struct pnp_option *option,
307 struct acpi_resource_irq *p)
308{
309 int i;
310 struct pnp_irq * irq;
311
Bob Moore50eca3e2005-09-30 19:03:00 -0400312 if (p->interrupt_count == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 return;
Bjorn Helgaasa2822e72005-09-06 15:16:51 -0700314 irq = kcalloc(1, sizeof(struct pnp_irq), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 if (!irq)
316 return;
317
Bob Moore50eca3e2005-09-30 19:03:00 -0400318 for(i = 0; i < p->interrupt_count; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 if (p->interrupts[i])
320 __set_bit(p->interrupts[i], irq->map);
Bob Moore50eca3e2005-09-30 19:03:00 -0400321 irq->flags = irq_flags(p->triggering, p->polarity);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
323 pnp_register_irq_resource(option, irq);
324 return;
325}
326
327static void pnpacpi_parse_ext_irq_option(struct pnp_option *option,
Bob Moore50eca3e2005-09-30 19:03:00 -0400328 struct acpi_resource_extended_irq *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329{
330 int i;
331 struct pnp_irq * irq;
332
Bob Moore50eca3e2005-09-30 19:03:00 -0400333 if (p->interrupt_count == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 return;
Bjorn Helgaasa2822e72005-09-06 15:16:51 -0700335 irq = kcalloc(1, sizeof(struct pnp_irq), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 if (!irq)
337 return;
338
Bob Moore50eca3e2005-09-30 19:03:00 -0400339 for(i = 0; i < p->interrupt_count; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 if (p->interrupts[i])
341 __set_bit(p->interrupts[i], irq->map);
Bob Moore50eca3e2005-09-30 19:03:00 -0400342 irq->flags = irq_flags(p->triggering, p->polarity);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
344 pnp_register_irq_resource(option, irq);
345 return;
346}
347
348static void
349pnpacpi_parse_port_option(struct pnp_option *option,
350 struct acpi_resource_io *io)
351{
352 struct pnp_port * port;
353
Bob Moore50eca3e2005-09-30 19:03:00 -0400354 if (io->address_length == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 return;
Bjorn Helgaasa2822e72005-09-06 15:16:51 -0700356 port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 if (!port)
358 return;
Bob Moore50eca3e2005-09-30 19:03:00 -0400359 port->min = io->minimum;
360 port->max = io->maximum;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 port->align = io->alignment;
Bob Moore50eca3e2005-09-30 19:03:00 -0400362 port->size = io->address_length;
363 port->flags = ACPI_DECODE_16 == io->io_decode ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 PNP_PORT_FLAG_16BITADDR : 0;
365 pnp_register_port_resource(option,port);
366 return;
367}
368
369static void
370pnpacpi_parse_fixed_port_option(struct pnp_option *option,
371 struct acpi_resource_fixed_io *io)
372{
373 struct pnp_port * port;
374
Bob Moore50eca3e2005-09-30 19:03:00 -0400375 if (io->address_length == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 return;
Bjorn Helgaasa2822e72005-09-06 15:16:51 -0700377 port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 if (!port)
379 return;
Bob Moore50eca3e2005-09-30 19:03:00 -0400380 port->min = port->max = io->address;
381 port->size = io->address_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 port->align = 0;
383 port->flags = PNP_PORT_FLAG_FIXED;
384 pnp_register_port_resource(option,port);
385 return;
386}
387
388static void
389pnpacpi_parse_mem24_option(struct pnp_option *option,
Bob Moore50eca3e2005-09-30 19:03:00 -0400390 struct acpi_resource_memory24 *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391{
392 struct pnp_mem * mem;
393
Bob Moore50eca3e2005-09-30 19:03:00 -0400394 if (p->address_length == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 return;
Bjorn Helgaasa2822e72005-09-06 15:16:51 -0700396 mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 if (!mem)
398 return;
Bob Moore50eca3e2005-09-30 19:03:00 -0400399 mem->min = p->minimum;
400 mem->max = p->maximum;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 mem->align = p->alignment;
Bob Moore50eca3e2005-09-30 19:03:00 -0400402 mem->size = p->address_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Bob Moore08978312005-10-21 00:00:00 -0400404 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 IORESOURCE_MEM_WRITEABLE : 0;
406
407 pnp_register_mem_resource(option,mem);
408 return;
409}
410
411static void
412pnpacpi_parse_mem32_option(struct pnp_option *option,
Bob Moore50eca3e2005-09-30 19:03:00 -0400413 struct acpi_resource_memory32 *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414{
415 struct pnp_mem * mem;
416
Bob Moore50eca3e2005-09-30 19:03:00 -0400417 if (p->address_length == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 return;
Bjorn Helgaasa2822e72005-09-06 15:16:51 -0700419 mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 if (!mem)
421 return;
Bob Moore50eca3e2005-09-30 19:03:00 -0400422 mem->min = p->minimum;
423 mem->max = p->maximum;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 mem->align = p->alignment;
Bob Moore50eca3e2005-09-30 19:03:00 -0400425 mem->size = p->address_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
Bob Moore08978312005-10-21 00:00:00 -0400427 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 IORESOURCE_MEM_WRITEABLE : 0;
429
430 pnp_register_mem_resource(option,mem);
431 return;
432}
433
434static void
435pnpacpi_parse_fixed_mem32_option(struct pnp_option *option,
Bob Moore50eca3e2005-09-30 19:03:00 -0400436 struct acpi_resource_fixed_memory32 *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437{
438 struct pnp_mem * mem;
439
Bob Moore50eca3e2005-09-30 19:03:00 -0400440 if (p->address_length == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 return;
Bjorn Helgaasa2822e72005-09-06 15:16:51 -0700442 mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 if (!mem)
444 return;
Bob Moore50eca3e2005-09-30 19:03:00 -0400445 mem->min = mem->max = p->address;
446 mem->size = p->address_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 mem->align = 0;
448
Bob Moore08978312005-10-21 00:00:00 -0400449 mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 IORESOURCE_MEM_WRITEABLE : 0;
451
452 pnp_register_mem_resource(option,mem);
453 return;
454}
455
Bjorn Helgaas6f957ea2005-09-20 15:26:00 -0400456static void
457pnpacpi_parse_address_option(struct pnp_option *option, struct acpi_resource *r)
458{
459 struct acpi_resource_address64 addr, *p = &addr;
460 acpi_status status;
461 struct pnp_mem * mem;
462 struct pnp_port * port;
463
464 status = acpi_resource_to_address64(r, p);
465 if (!ACPI_SUCCESS(status)) {
Len Browned03f432006-01-07 03:50:18 -0500466 pnp_warn("PnPACPI: failed to convert resource type %d", r->type);
Bjorn Helgaas6f957ea2005-09-20 15:26:00 -0400467 return;
468 }
469
470 if (p->address_length == 0)
471 return;
472
473 if (p->resource_type == ACPI_MEMORY_RANGE) {
474 mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
475 if (!mem)
476 return;
Len Browned03f432006-01-07 03:50:18 -0500477 mem->min = mem->max = p->minimum;
Bjorn Helgaas6f957ea2005-09-20 15:26:00 -0400478 mem->size = p->address_length;
479 mem->align = 0;
Len Browned03f432006-01-07 03:50:18 -0500480 mem->flags = (p->info.mem.write_protect ==
Bjorn Helgaas6f957ea2005-09-20 15:26:00 -0400481 ACPI_READ_WRITE_MEMORY) ? IORESOURCE_MEM_WRITEABLE : 0;
482 pnp_register_mem_resource(option,mem);
483 } else if (p->resource_type == ACPI_IO_RANGE) {
484 port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL);
485 if (!port)
486 return;
Len Browned03f432006-01-07 03:50:18 -0500487 port->min = port->max = p->minimum;
Bjorn Helgaas6f957ea2005-09-20 15:26:00 -0400488 port->size = p->address_length;
489 port->align = 0;
490 port->flags = PNP_PORT_FLAG_FIXED;
491 pnp_register_port_resource(option,port);
492 }
493}
494
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495struct acpipnp_parse_option_s {
496 struct pnp_option *option;
Matthieu Castetb008b8d2005-03-25 12:03:15 -0500497 struct pnp_option *option_independent;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 struct pnp_dev *dev;
499};
500
Bob Moore50eca3e2005-09-30 19:03:00 -0400501static acpi_status pnpacpi_option_resource(struct acpi_resource *res,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 void *data)
503{
504 int priority = 0;
505 struct acpipnp_parse_option_s *parse_data = (struct acpipnp_parse_option_s *)data;
506 struct pnp_dev *dev = parse_data->dev;
507 struct pnp_option *option = parse_data->option;
508
Len Browneca008c2005-09-22 00:25:18 -0400509 switch (res->type) {
Bob Moore50eca3e2005-09-30 19:03:00 -0400510 case ACPI_RESOURCE_TYPE_IRQ:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 pnpacpi_parse_irq_option(option, &res->data.irq);
512 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400513 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 pnpacpi_parse_ext_irq_option(option,
515 &res->data.extended_irq);
516 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400517 case ACPI_RESOURCE_TYPE_DMA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 pnpacpi_parse_dma_option(option, &res->data.dma);
519 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400520 case ACPI_RESOURCE_TYPE_IO:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 pnpacpi_parse_port_option(option, &res->data.io);
522 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400523 case ACPI_RESOURCE_TYPE_FIXED_IO:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 pnpacpi_parse_fixed_port_option(option,
525 &res->data.fixed_io);
526 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400527 case ACPI_RESOURCE_TYPE_MEMORY24:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 pnpacpi_parse_mem24_option(option, &res->data.memory24);
529 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400530 case ACPI_RESOURCE_TYPE_MEMORY32:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 pnpacpi_parse_mem32_option(option, &res->data.memory32);
532 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400533 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 pnpacpi_parse_fixed_mem32_option(option,
535 &res->data.fixed_memory32);
536 break;
Len Browned03f432006-01-07 03:50:18 -0500537 case ACPI_RESOURCE_TYPE_ADDRESS16:
538 case ACPI_RESOURCE_TYPE_ADDRESS32:
539 case ACPI_RESOURCE_TYPE_ADDRESS64:
Bjorn Helgaas6f957ea2005-09-20 15:26:00 -0400540 pnpacpi_parse_address_option(option, res);
541 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400542 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 switch (res->data.start_dpf.compatibility_priority) {
544 case ACPI_GOOD_CONFIGURATION:
545 priority = PNP_RES_PRIORITY_PREFERRED;
546 break;
547
548 case ACPI_ACCEPTABLE_CONFIGURATION:
549 priority = PNP_RES_PRIORITY_ACCEPTABLE;
550 break;
551
552 case ACPI_SUB_OPTIMAL_CONFIGURATION:
553 priority = PNP_RES_PRIORITY_FUNCTIONAL;
554 break;
555 default:
556 priority = PNP_RES_PRIORITY_INVALID;
557 break;
558 }
559 /* TBD: Considering performace/robustness bits */
560 option = pnp_register_dependent_option(dev, priority);
561 if (!option)
562 return AE_ERROR;
563 parse_data->option = option;
564 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400565 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
Matthieu Castetb008b8d2005-03-25 12:03:15 -0500566 /*only one EndDependentFn is allowed*/
567 if (!parse_data->option_independent) {
568 pnp_warn("PnPACPI: more than one EndDependentFn");
569 return AE_ERROR;
570 }
571 parse_data->option = parse_data->option_independent;
572 parse_data->option_independent = NULL;
573 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 default:
Len Browneca008c2005-09-22 00:25:18 -0400575 pnp_warn("PnPACPI: unknown resource type %d", res->type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 return AE_ERROR;
577 }
578
579 return AE_OK;
580}
581
Bob Moore50eca3e2005-09-30 19:03:00 -0400582acpi_status pnpacpi_parse_resource_option_data(acpi_handle handle,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 struct pnp_dev *dev)
584{
585 acpi_status status;
586 struct acpipnp_parse_option_s parse_data;
587
588 parse_data.option = pnp_register_independent_option(dev);
589 if (!parse_data.option)
590 return AE_ERROR;
Matthieu Castetb008b8d2005-03-25 12:03:15 -0500591 parse_data.option_independent = parse_data.option;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 parse_data.dev = dev;
Bob Moore50eca3e2005-09-30 19:03:00 -0400593 status = acpi_walk_resources(handle, METHOD_NAME__PRS,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 pnpacpi_option_resource, &parse_data);
595
596 return status;
597}
598
599/*
600 * Set resource
601 */
602static acpi_status pnpacpi_count_resources(struct acpi_resource *res,
603 void *data)
604{
605 int *res_cnt = (int *)data;
Len Browneca008c2005-09-22 00:25:18 -0400606 switch (res->type) {
Bob Moore50eca3e2005-09-30 19:03:00 -0400607 case ACPI_RESOURCE_TYPE_IRQ:
608 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
609 case ACPI_RESOURCE_TYPE_DMA:
610 case ACPI_RESOURCE_TYPE_IO:
611 case ACPI_RESOURCE_TYPE_FIXED_IO:
612 case ACPI_RESOURCE_TYPE_MEMORY24:
613 case ACPI_RESOURCE_TYPE_MEMORY32:
614 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
Bob Moore50eca3e2005-09-30 19:03:00 -0400615 case ACPI_RESOURCE_TYPE_ADDRESS16:
616 case ACPI_RESOURCE_TYPE_ADDRESS32:
617 case ACPI_RESOURCE_TYPE_ADDRESS64:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 (*res_cnt) ++;
619 default:
620 return AE_OK;
621 }
622 return AE_OK;
623}
624
625static acpi_status pnpacpi_type_resources(struct acpi_resource *res,
626 void *data)
627{
628 struct acpi_resource **resource = (struct acpi_resource **)data;
Len Browneca008c2005-09-22 00:25:18 -0400629 switch (res->type) {
Bob Moore50eca3e2005-09-30 19:03:00 -0400630 case ACPI_RESOURCE_TYPE_IRQ:
631 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
632 case ACPI_RESOURCE_TYPE_DMA:
633 case ACPI_RESOURCE_TYPE_IO:
634 case ACPI_RESOURCE_TYPE_FIXED_IO:
635 case ACPI_RESOURCE_TYPE_MEMORY24:
636 case ACPI_RESOURCE_TYPE_MEMORY32:
637 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
Bob Moore50eca3e2005-09-30 19:03:00 -0400638 case ACPI_RESOURCE_TYPE_ADDRESS16:
639 case ACPI_RESOURCE_TYPE_ADDRESS32:
640 case ACPI_RESOURCE_TYPE_ADDRESS64:
Len Browneca008c2005-09-22 00:25:18 -0400641 (*resource)->type = res->type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 (*resource)++;
643 default:
644 return AE_OK;
645 }
646
647 return AE_OK;
648}
649
Bob Moore50eca3e2005-09-30 19:03:00 -0400650int pnpacpi_build_resource_template(acpi_handle handle,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 struct acpi_buffer *buffer)
652{
653 struct acpi_resource *resource;
654 int res_cnt = 0;
655 acpi_status status;
656
Bob Moore50eca3e2005-09-30 19:03:00 -0400657 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 pnpacpi_count_resources, &res_cnt);
659 if (ACPI_FAILURE(status)) {
660 pnp_err("Evaluate _CRS failed");
661 return -EINVAL;
662 }
663 if (!res_cnt)
664 return -EINVAL;
665 buffer->length = sizeof(struct acpi_resource) * (res_cnt + 1) + 1;
Bjorn Helgaasa2822e72005-09-06 15:16:51 -0700666 buffer->pointer = kcalloc(1, buffer->length - 1, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 if (!buffer->pointer)
668 return -ENOMEM;
669 pnp_dbg("Res cnt %d", res_cnt);
670 resource = (struct acpi_resource *)buffer->pointer;
Bob Moore50eca3e2005-09-30 19:03:00 -0400671 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 pnpacpi_type_resources, &resource);
673 if (ACPI_FAILURE(status)) {
674 kfree(buffer->pointer);
675 pnp_err("Evaluate _CRS failed");
676 return -EINVAL;
677 }
678 /* resource will pointer the end resource now */
Bob Moore50eca3e2005-09-30 19:03:00 -0400679 resource->type = ACPI_RESOURCE_TYPE_END_TAG;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
681 return 0;
682}
683
Bob Moore50eca3e2005-09-30 19:03:00 -0400684static void pnpacpi_encode_irq(struct acpi_resource *resource,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 struct resource *p)
686{
Bob Moore50eca3e2005-09-30 19:03:00 -0400687 int triggering, polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
Bob Moore50eca3e2005-09-30 19:03:00 -0400689 decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering,
690 &polarity);
691 resource->type = ACPI_RESOURCE_TYPE_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 resource->length = sizeof(struct acpi_resource);
Bob Moore50eca3e2005-09-30 19:03:00 -0400693 resource->data.irq.triggering = triggering;
694 resource->data.irq.polarity = polarity;
695 if (triggering == ACPI_EDGE_SENSITIVE)
696 resource->data.irq.sharable = ACPI_EXCLUSIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 else
Bob Moore50eca3e2005-09-30 19:03:00 -0400698 resource->data.irq.sharable = ACPI_SHARED;
699 resource->data.irq.interrupt_count = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 resource->data.irq.interrupts[0] = p->start;
701}
702
703static void pnpacpi_encode_ext_irq(struct acpi_resource *resource,
704 struct resource *p)
705{
Bob Moore50eca3e2005-09-30 19:03:00 -0400706 int triggering, polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707
Bob Moore50eca3e2005-09-30 19:03:00 -0400708 decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering,
709 &polarity);
710 resource->type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 resource->length = sizeof(struct acpi_resource);
712 resource->data.extended_irq.producer_consumer = ACPI_CONSUMER;
Bob Moore50eca3e2005-09-30 19:03:00 -0400713 resource->data.extended_irq.triggering = triggering;
714 resource->data.extended_irq.polarity = polarity;
715 if (triggering == ACPI_EDGE_SENSITIVE)
716 resource->data.irq.sharable = ACPI_EXCLUSIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 else
Bob Moore50eca3e2005-09-30 19:03:00 -0400718 resource->data.irq.sharable = ACPI_SHARED;
719 resource->data.extended_irq.interrupt_count = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 resource->data.extended_irq.interrupts[0] = p->start;
721}
722
723static void pnpacpi_encode_dma(struct acpi_resource *resource,
724 struct resource *p)
725{
Bob Moore50eca3e2005-09-30 19:03:00 -0400726 resource->type = ACPI_RESOURCE_TYPE_DMA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 resource->length = sizeof(struct acpi_resource);
728 /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
729 if (p->flags & IORESOURCE_DMA_COMPATIBLE)
730 resource->data.dma.type = ACPI_COMPATIBILITY;
731 else if (p->flags & IORESOURCE_DMA_TYPEA)
732 resource->data.dma.type = ACPI_TYPE_A;
733 else if (p->flags & IORESOURCE_DMA_TYPEB)
734 resource->data.dma.type = ACPI_TYPE_B;
735 else if (p->flags & IORESOURCE_DMA_TYPEF)
736 resource->data.dma.type = ACPI_TYPE_F;
737 if (p->flags & IORESOURCE_DMA_8BIT)
738 resource->data.dma.transfer = ACPI_TRANSFER_8;
739 else if (p->flags & IORESOURCE_DMA_8AND16BIT)
740 resource->data.dma.transfer = ACPI_TRANSFER_8_16;
741 else if (p->flags & IORESOURCE_DMA_16BIT)
742 resource->data.dma.transfer = ACPI_TRANSFER_16;
743 resource->data.dma.bus_master = p->flags & IORESOURCE_DMA_MASTER;
Bob Moore50eca3e2005-09-30 19:03:00 -0400744 resource->data.dma.channel_count = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 resource->data.dma.channels[0] = p->start;
746}
747
748static void pnpacpi_encode_io(struct acpi_resource *resource,
749 struct resource *p)
750{
Bob Moore50eca3e2005-09-30 19:03:00 -0400751 resource->type = ACPI_RESOURCE_TYPE_IO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 resource->length = sizeof(struct acpi_resource);
753 /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */
754 resource->data.io.io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR)?
Bob Moore50eca3e2005-09-30 19:03:00 -0400755 ACPI_DECODE_16 : ACPI_DECODE_10;
756 resource->data.io.minimum = p->start;
757 resource->data.io.maximum = p->end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 resource->data.io.alignment = 0; /* Correct? */
Bob Moore50eca3e2005-09-30 19:03:00 -0400759 resource->data.io.address_length = p->end - p->start + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760}
761
762static void pnpacpi_encode_fixed_io(struct acpi_resource *resource,
763 struct resource *p)
764{
Bob Moore50eca3e2005-09-30 19:03:00 -0400765 resource->type = ACPI_RESOURCE_TYPE_FIXED_IO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 resource->length = sizeof(struct acpi_resource);
Bob Moore50eca3e2005-09-30 19:03:00 -0400767 resource->data.fixed_io.address = p->start;
768 resource->data.fixed_io.address_length = p->end - p->start + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769}
770
771static void pnpacpi_encode_mem24(struct acpi_resource *resource,
772 struct resource *p)
773{
Bob Moore50eca3e2005-09-30 19:03:00 -0400774 resource->type = ACPI_RESOURCE_TYPE_MEMORY24;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 resource->length = sizeof(struct acpi_resource);
776 /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */
Bob Moore08978312005-10-21 00:00:00 -0400777 resource->data.memory24.write_protect =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
779 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
Bob Moore50eca3e2005-09-30 19:03:00 -0400780 resource->data.memory24.minimum = p->start;
781 resource->data.memory24.maximum = p->end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 resource->data.memory24.alignment = 0;
Bob Moore50eca3e2005-09-30 19:03:00 -0400783 resource->data.memory24.address_length = p->end - p->start + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784}
785
786static void pnpacpi_encode_mem32(struct acpi_resource *resource,
787 struct resource *p)
788{
Bob Moore50eca3e2005-09-30 19:03:00 -0400789 resource->type = ACPI_RESOURCE_TYPE_MEMORY32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 resource->length = sizeof(struct acpi_resource);
Bob Moore08978312005-10-21 00:00:00 -0400791 resource->data.memory32.write_protect =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
793 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
Bob Moore50eca3e2005-09-30 19:03:00 -0400794 resource->data.memory32.minimum = p->start;
795 resource->data.memory32.maximum = p->end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 resource->data.memory32.alignment = 0;
Bob Moore50eca3e2005-09-30 19:03:00 -0400797 resource->data.memory32.address_length = p->end - p->start + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798}
799
800static void pnpacpi_encode_fixed_mem32(struct acpi_resource *resource,
801 struct resource *p)
802{
Bob Moore50eca3e2005-09-30 19:03:00 -0400803 resource->type = ACPI_RESOURCE_TYPE_FIXED_MEMORY32;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 resource->length = sizeof(struct acpi_resource);
Bob Moore08978312005-10-21 00:00:00 -0400805 resource->data.fixed_memory32.write_protect =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 (p->flags & IORESOURCE_MEM_WRITEABLE) ?
807 ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
Bob Moore50eca3e2005-09-30 19:03:00 -0400808 resource->data.fixed_memory32.address = p->start;
809 resource->data.fixed_memory32.address_length = p->end - p->start + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810}
811
Bob Moore50eca3e2005-09-30 19:03:00 -0400812int pnpacpi_encode_resources(struct pnp_resource_table *res_table,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 struct acpi_buffer *buffer)
814{
815 int i = 0;
816 /* pnpacpi_build_resource_template allocates extra mem */
817 int res_cnt = (buffer->length - 1)/sizeof(struct acpi_resource) - 1;
818 struct acpi_resource *resource = (struct acpi_resource*)buffer->pointer;
819 int port = 0, irq = 0, dma = 0, mem = 0;
820
821 pnp_dbg("res cnt %d", res_cnt);
822 while (i < res_cnt) {
Len Browneca008c2005-09-22 00:25:18 -0400823 switch(resource->type) {
Bob Moore50eca3e2005-09-30 19:03:00 -0400824 case ACPI_RESOURCE_TYPE_IRQ:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 pnp_dbg("Encode irq");
Bob Moore50eca3e2005-09-30 19:03:00 -0400826 pnpacpi_encode_irq(resource,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 &res_table->irq_resource[irq]);
828 irq++;
829 break;
830
Bob Moore50eca3e2005-09-30 19:03:00 -0400831 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 pnp_dbg("Encode ext irq");
Bob Moore50eca3e2005-09-30 19:03:00 -0400833 pnpacpi_encode_ext_irq(resource,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 &res_table->irq_resource[irq]);
835 irq++;
836 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400837 case ACPI_RESOURCE_TYPE_DMA:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 pnp_dbg("Encode dma");
Bob Moore50eca3e2005-09-30 19:03:00 -0400839 pnpacpi_encode_dma(resource,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 &res_table->dma_resource[dma]);
841 dma ++;
842 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400843 case ACPI_RESOURCE_TYPE_IO:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 pnp_dbg("Encode io");
Bob Moore50eca3e2005-09-30 19:03:00 -0400845 pnpacpi_encode_io(resource,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 &res_table->port_resource[port]);
847 port ++;
848 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400849 case ACPI_RESOURCE_TYPE_FIXED_IO:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 pnp_dbg("Encode fixed io");
851 pnpacpi_encode_fixed_io(resource,
852 &res_table->port_resource[port]);
853 port ++;
854 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400855 case ACPI_RESOURCE_TYPE_MEMORY24:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 pnp_dbg("Encode mem24");
857 pnpacpi_encode_mem24(resource,
858 &res_table->mem_resource[mem]);
859 mem ++;
860 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400861 case ACPI_RESOURCE_TYPE_MEMORY32:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 pnp_dbg("Encode mem32");
863 pnpacpi_encode_mem32(resource,
864 &res_table->mem_resource[mem]);
865 mem ++;
866 break;
Bob Moore50eca3e2005-09-30 19:03:00 -0400867 case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 pnp_dbg("Encode fixed mem32");
869 pnpacpi_encode_fixed_mem32(resource,
870 &res_table->mem_resource[mem]);
871 mem ++;
872 break;
873 default: /* other type */
Len Browneca008c2005-09-22 00:25:18 -0400874 pnp_warn("unknown resource type %d", resource->type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 return -EINVAL;
876 }
877 resource ++;
878 i ++;
879 }
880 return 0;
881}