Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
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> | |
40ab4f4c BH |
6 | * Copyright (C) 2008 Hewlett-Packard Development Company, L.P. |
7 | * Bjorn Helgaas <bjorn.helgaas@hp.com> | |
50eca3eb | 8 | * |
1da177e4 LT |
9 | * This program is free software; you can redistribute it and/or modify it |
10 | * under the terms of the GNU General Public License as published by the | |
11 | * Free Software Foundation; either version 2, or (at your option) any | |
12 | * later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, but | |
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | * General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
22 | */ | |
23 | #include <linux/kernel.h> | |
24 | #include <linux/acpi.h> | |
25 | #include <linux/pci.h> | |
02d83b5d | 26 | #include <linux/pnp.h> |
5a0e3ad6 | 27 | #include <linux/slab.h> |
02d83b5d | 28 | #include "../base.h" |
1da177e4 LT |
29 | #include "pnpacpi.h" |
30 | ||
31 | #ifdef CONFIG_IA64 | |
32 | #define valid_IRQ(i) (1) | |
33 | #else | |
34 | #define valid_IRQ(i) (((i) != 0) && ((i) != 2)) | |
35 | #endif | |
36 | ||
37 | /* | |
38 | * Allocated Resources | |
39 | */ | |
cd7ec927 | 40 | static int irq_flags(int triggering, int polarity, int shareable) |
1da177e4 | 41 | { |
cd7ec927 BH |
42 | int flags; |
43 | ||
50eca3eb | 44 | if (triggering == ACPI_LEVEL_SENSITIVE) { |
1c6e7d0a | 45 | if (polarity == ACPI_ACTIVE_LOW) |
cd7ec927 | 46 | flags = IORESOURCE_IRQ_LOWLEVEL; |
1da177e4 | 47 | else |
cd7ec927 | 48 | flags = IORESOURCE_IRQ_HIGHLEVEL; |
9dd78466 | 49 | } else { |
1c6e7d0a | 50 | if (polarity == ACPI_ACTIVE_LOW) |
cd7ec927 | 51 | flags = IORESOURCE_IRQ_LOWEDGE; |
1da177e4 | 52 | else |
cd7ec927 | 53 | flags = IORESOURCE_IRQ_HIGHEDGE; |
1da177e4 | 54 | } |
cd7ec927 | 55 | |
a993273b | 56 | if (shareable == ACPI_SHARED) |
cd7ec927 BH |
57 | flags |= IORESOURCE_IRQ_SHAREABLE; |
58 | ||
59 | return flags; | |
1da177e4 LT |
60 | } |
61 | ||
e9fe9e18 | 62 | static void decode_irq_flags(struct pnp_dev *dev, int flags, int *triggering, |
a993273b | 63 | int *polarity, int *shareable) |
1da177e4 | 64 | { |
e9fe9e18 BH |
65 | switch (flags & (IORESOURCE_IRQ_LOWLEVEL | IORESOURCE_IRQ_HIGHLEVEL | |
66 | IORESOURCE_IRQ_LOWEDGE | IORESOURCE_IRQ_HIGHEDGE)) { | |
1da177e4 | 67 | case IORESOURCE_IRQ_LOWLEVEL: |
50eca3eb BM |
68 | *triggering = ACPI_LEVEL_SENSITIVE; |
69 | *polarity = ACPI_ACTIVE_LOW; | |
1da177e4 | 70 | break; |
1c6e7d0a | 71 | case IORESOURCE_IRQ_HIGHLEVEL: |
50eca3eb BM |
72 | *triggering = ACPI_LEVEL_SENSITIVE; |
73 | *polarity = ACPI_ACTIVE_HIGH; | |
1da177e4 LT |
74 | break; |
75 | case IORESOURCE_IRQ_LOWEDGE: | |
50eca3eb BM |
76 | *triggering = ACPI_EDGE_SENSITIVE; |
77 | *polarity = ACPI_ACTIVE_LOW; | |
1da177e4 LT |
78 | break; |
79 | case IORESOURCE_IRQ_HIGHEDGE: | |
50eca3eb BM |
80 | *triggering = ACPI_EDGE_SENSITIVE; |
81 | *polarity = ACPI_ACTIVE_HIGH; | |
1da177e4 | 82 | break; |
e9fe9e18 BH |
83 | default: |
84 | dev_err(&dev->dev, "can't encode invalid IRQ mode %#x\n", | |
85 | flags); | |
86 | *triggering = ACPI_EDGE_SENSITIVE; | |
87 | *polarity = ACPI_ACTIVE_HIGH; | |
88 | break; | |
1da177e4 | 89 | } |
a993273b BH |
90 | |
91 | if (flags & IORESOURCE_IRQ_SHAREABLE) | |
92 | *shareable = ACPI_SHARED; | |
93 | else | |
94 | *shareable = ACPI_EXCLUSIVE; | |
1da177e4 LT |
95 | } |
96 | ||
4ab55d8d | 97 | static void pnpacpi_parse_allocated_irqresource(struct pnp_dev *dev, |
07d4e9af BH |
98 | u32 gsi, int triggering, |
99 | int polarity, int shareable) | |
1da177e4 | 100 | { |
dbddd038 | 101 | int irq, flags; |
61fd47e0 | 102 | int p, t; |
dbed12da | 103 | |
5acf9141 BH |
104 | if (!valid_IRQ(gsi)) { |
105 | pnp_add_irq_resource(dev, gsi, IORESOURCE_DISABLED); | |
dbed12da | 106 | return; |
5acf9141 | 107 | } |
dbed12da | 108 | |
61fd47e0 SL |
109 | /* |
110 | * in IO-APIC mode, use overrided attribute. Two reasons: | |
111 | * 1. BIOS bug in DSDT | |
112 | * 2. BIOS uses IO-APIC mode Interrupt Source Override | |
113 | */ | |
114 | if (!acpi_get_override_irq(gsi, &t, &p)) { | |
115 | t = t ? ACPI_LEVEL_SENSITIVE : ACPI_EDGE_SENSITIVE; | |
116 | p = p ? ACPI_ACTIVE_LOW : ACPI_ACTIVE_HIGH; | |
117 | ||
118 | if (triggering != t || polarity != p) { | |
af11cb2d | 119 | dev_warn(&dev->dev, "IRQ %d override to %s, %s\n", |
61fd47e0 SL |
120 | gsi, t ? "edge":"level", p ? "low":"high"); |
121 | triggering = t; | |
122 | polarity = p; | |
123 | } | |
124 | } | |
125 | ||
dbddd038 | 126 | flags = irq_flags(triggering, polarity, shareable); |
a2f809b0 | 127 | irq = acpi_register_gsi(&dev->dev, gsi, triggering, polarity); |
dbddd038 BH |
128 | if (irq >= 0) |
129 | pcibios_penalize_isa_irq(irq, 1); | |
130 | else | |
131 | flags |= IORESOURCE_DISABLED; | |
dbed12da | 132 | |
dbddd038 | 133 | pnp_add_irq_resource(dev, irq, flags); |
1da177e4 LT |
134 | } |
135 | ||
958a1fdd BH |
136 | static int dma_flags(struct pnp_dev *dev, int type, int bus_master, |
137 | int transfer) | |
362ea087 MK |
138 | { |
139 | int flags = 0; | |
140 | ||
141 | if (bus_master) | |
142 | flags |= IORESOURCE_DMA_MASTER; | |
143 | switch (type) { | |
144 | case ACPI_COMPATIBILITY: | |
145 | flags |= IORESOURCE_DMA_COMPATIBLE; | |
146 | break; | |
147 | case ACPI_TYPE_A: | |
148 | flags |= IORESOURCE_DMA_TYPEA; | |
149 | break; | |
150 | case ACPI_TYPE_B: | |
151 | flags |= IORESOURCE_DMA_TYPEB; | |
152 | break; | |
153 | case ACPI_TYPE_F: | |
154 | flags |= IORESOURCE_DMA_TYPEF; | |
155 | break; | |
156 | default: | |
157 | /* Set a default value ? */ | |
158 | flags |= IORESOURCE_DMA_COMPATIBLE; | |
958a1fdd | 159 | dev_err(&dev->dev, "invalid DMA type %d\n", type); |
362ea087 MK |
160 | } |
161 | switch (transfer) { | |
162 | case ACPI_TRANSFER_8: | |
163 | flags |= IORESOURCE_DMA_8BIT; | |
164 | break; | |
165 | case ACPI_TRANSFER_8_16: | |
166 | flags |= IORESOURCE_DMA_8AND16BIT; | |
167 | break; | |
168 | case ACPI_TRANSFER_16: | |
169 | flags |= IORESOURCE_DMA_16BIT; | |
170 | break; | |
171 | default: | |
172 | /* Set a default value ? */ | |
173 | flags |= IORESOURCE_DMA_8AND16BIT; | |
958a1fdd | 174 | dev_err(&dev->dev, "invalid DMA transfer type %d\n", transfer); |
362ea087 MK |
175 | } |
176 | ||
177 | return flags; | |
178 | } | |
179 | ||
cc8c2e30 | 180 | static void pnpacpi_parse_allocated_ioresource(struct pnp_dev *dev, u64 start, |
fa35b492 BH |
181 | u64 len, int io_decode, |
182 | int window) | |
1da177e4 | 183 | { |
cc8c2e30 BH |
184 | int flags = 0; |
185 | u64 end = start + len - 1; | |
07d4e9af | 186 | |
cc8c2e30 | 187 | if (io_decode == ACPI_DECODE_16) |
08c9f262 | 188 | flags |= IORESOURCE_IO_16BIT_ADDR; |
cc8c2e30 BH |
189 | if (len == 0 || end >= 0x10003) |
190 | flags |= IORESOURCE_DISABLED; | |
fa35b492 BH |
191 | if (window) |
192 | flags |= IORESOURCE_WINDOW; | |
cc8c2e30 BH |
193 | |
194 | pnp_add_io_resource(dev, start, end, flags); | |
1da177e4 LT |
195 | } |
196 | ||
40ab4f4c BH |
197 | /* |
198 | * Device CSRs that do not appear in PCI config space should be described | |
199 | * via ACPI. This would normally be done with Address Space Descriptors | |
200 | * marked as "consumer-only," but old versions of Windows and Linux ignore | |
201 | * the producer/consumer flag, so HP invented a vendor-defined resource to | |
202 | * describe the location and size of CSR space. | |
203 | */ | |
204 | static struct acpi_vendor_uuid hp_ccsr_uuid = { | |
205 | .subtype = 2, | |
206 | .data = { 0xf9, 0xad, 0xe9, 0x69, 0x4f, 0x92, 0x5f, 0xab, 0xf6, 0x4a, | |
207 | 0x24, 0xd2, 0x01, 0x37, 0x0e, 0xad }, | |
208 | }; | |
209 | ||
210 | static int vendor_resource_matches(struct pnp_dev *dev, | |
211 | struct acpi_resource_vendor_typed *vendor, | |
212 | struct acpi_vendor_uuid *match, | |
213 | int expected_len) | |
214 | { | |
215 | int uuid_len = sizeof(vendor->uuid); | |
216 | u8 uuid_subtype = vendor->uuid_subtype; | |
217 | u8 *uuid = vendor->uuid; | |
218 | int actual_len; | |
219 | ||
220 | /* byte_length includes uuid_subtype and uuid */ | |
221 | actual_len = vendor->byte_length - uuid_len - 1; | |
222 | ||
223 | if (uuid_subtype == match->subtype && | |
224 | uuid_len == sizeof(match->data) && | |
225 | memcmp(uuid, match->data, uuid_len) == 0) { | |
226 | if (expected_len && expected_len != actual_len) { | |
227 | dev_err(&dev->dev, "wrong vendor descriptor size; " | |
228 | "expected %d, found %d bytes\n", | |
229 | expected_len, actual_len); | |
230 | return 0; | |
231 | } | |
232 | ||
233 | return 1; | |
234 | } | |
235 | ||
236 | return 0; | |
237 | } | |
238 | ||
239 | static void pnpacpi_parse_allocated_vendor(struct pnp_dev *dev, | |
240 | struct acpi_resource_vendor_typed *vendor) | |
241 | { | |
242 | if (vendor_resource_matches(dev, vendor, &hp_ccsr_uuid, 16)) { | |
243 | u64 start, length; | |
244 | ||
245 | memcpy(&start, vendor->byte_data, sizeof(start)); | |
246 | memcpy(&length, vendor->byte_data + 8, sizeof(length)); | |
247 | ||
248 | pnp_add_mem_resource(dev, start, start + length - 1, 0); | |
249 | } | |
250 | } | |
251 | ||
4ab55d8d | 252 | static void pnpacpi_parse_allocated_memresource(struct pnp_dev *dev, |
d6180f36 | 253 | u64 start, u64 len, |
fa35b492 | 254 | int write_protect, int window) |
1da177e4 | 255 | { |
d6180f36 BH |
256 | int flags = 0; |
257 | u64 end = start + len - 1; | |
258 | ||
259 | if (len == 0) | |
260 | flags |= IORESOURCE_DISABLED; | |
261 | if (write_protect == ACPI_READ_WRITE_MEMORY) | |
262 | flags |= IORESOURCE_MEM_WRITEABLE; | |
fa35b492 BH |
263 | if (window) |
264 | flags |= IORESOURCE_WINDOW; | |
d6180f36 BH |
265 | |
266 | pnp_add_mem_resource(dev, start, end, flags); | |
1da177e4 LT |
267 | } |
268 | ||
7e0e9c04 BH |
269 | static void pnpacpi_parse_allocated_busresource(struct pnp_dev *dev, |
270 | u64 start, u64 len) | |
271 | { | |
272 | u64 end = start + len - 1; | |
273 | ||
274 | pnp_add_bus_resource(dev, start, end); | |
275 | } | |
276 | ||
4ab55d8d | 277 | static void pnpacpi_parse_allocated_address_space(struct pnp_dev *dev, |
07d4e9af | 278 | struct acpi_resource *res) |
1acfb7f2 BH |
279 | { |
280 | struct acpi_resource_address64 addr, *p = &addr; | |
281 | acpi_status status; | |
fa35b492 | 282 | int window; |
3162b6f0 | 283 | u64 len; |
1acfb7f2 BH |
284 | |
285 | status = acpi_resource_to_address64(res, p); | |
286 | if (!ACPI_SUCCESS(status)) { | |
af11cb2d | 287 | dev_warn(&dev->dev, "failed to convert resource type %d\n", |
9dd78466 | 288 | res->type); |
1acfb7f2 BH |
289 | return; |
290 | } | |
291 | ||
f238b414 BH |
292 | /* Windows apparently computes length rather than using _LEN */ |
293 | len = p->maximum - p->minimum + 1; | |
fa35b492 | 294 | window = (p->producer_consumer == ACPI_PRODUCER) ? 1 : 0; |
2b8de5f5 | 295 | |
1acfb7f2 | 296 | if (p->resource_type == ACPI_MEMORY_RANGE) |
3162b6f0 | 297 | pnpacpi_parse_allocated_memresource(dev, p->minimum, len, |
fa35b492 | 298 | p->info.mem.write_protect, window); |
1acfb7f2 | 299 | else if (p->resource_type == ACPI_IO_RANGE) |
3162b6f0 | 300 | pnpacpi_parse_allocated_ioresource(dev, p->minimum, len, |
07d4e9af | 301 | p->granularity == 0xfff ? ACPI_DECODE_10 : |
fa35b492 | 302 | ACPI_DECODE_16, window); |
7e0e9c04 | 303 | else if (p->resource_type == ACPI_BUS_NUMBER_RANGE) |
3162b6f0 | 304 | pnpacpi_parse_allocated_busresource(dev, p->minimum, len); |
1acfb7f2 | 305 | } |
1da177e4 | 306 | |
8cb24c8f BH |
307 | static void pnpacpi_parse_allocated_ext_address_space(struct pnp_dev *dev, |
308 | struct acpi_resource *res) | |
309 | { | |
310 | struct acpi_resource_extended_address64 *p = &res->data.ext_address64; | |
fa35b492 | 311 | int window; |
3162b6f0 | 312 | u64 len; |
8cb24c8f | 313 | |
f238b414 BH |
314 | /* Windows apparently computes length rather than using _LEN */ |
315 | len = p->maximum - p->minimum + 1; | |
fa35b492 | 316 | window = (p->producer_consumer == ACPI_PRODUCER) ? 1 : 0; |
8cb24c8f BH |
317 | |
318 | if (p->resource_type == ACPI_MEMORY_RANGE) | |
3162b6f0 | 319 | pnpacpi_parse_allocated_memresource(dev, p->minimum, len, |
fa35b492 | 320 | p->info.mem.write_protect, window); |
8cb24c8f | 321 | else if (p->resource_type == ACPI_IO_RANGE) |
3162b6f0 | 322 | pnpacpi_parse_allocated_ioresource(dev, p->minimum, len, |
8cb24c8f | 323 | p->granularity == 0xfff ? ACPI_DECODE_10 : |
fa35b492 | 324 | ACPI_DECODE_16, window); |
7e0e9c04 | 325 | else if (p->resource_type == ACPI_BUS_NUMBER_RANGE) |
3162b6f0 | 326 | pnpacpi_parse_allocated_busresource(dev, p->minimum, len); |
8cb24c8f BH |
327 | } |
328 | ||
1da177e4 | 329 | static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res, |
9dd78466 | 330 | void *data) |
1da177e4 | 331 | { |
4ab55d8d | 332 | struct pnp_dev *dev = data; |
9570a20e BH |
333 | struct acpi_resource_irq *irq; |
334 | struct acpi_resource_dma *dma; | |
335 | struct acpi_resource_io *io; | |
336 | struct acpi_resource_fixed_io *fixed_io; | |
40ab4f4c | 337 | struct acpi_resource_vendor_typed *vendor_typed; |
9570a20e BH |
338 | struct acpi_resource_memory24 *memory24; |
339 | struct acpi_resource_memory32 *memory32; | |
340 | struct acpi_resource_fixed_memory32 *fixed_memory32; | |
341 | struct acpi_resource_extended_irq *extended_irq; | |
dc16f5f2 | 342 | int i, flags; |
1da177e4 | 343 | |
eca008c8 | 344 | switch (res->type) { |
50eca3eb | 345 | case ACPI_RESOURCE_TYPE_IRQ: |
dbed12da BH |
346 | /* |
347 | * Per spec, only one interrupt per descriptor is allowed in | |
348 | * _CRS, but some firmware violates this, so parse them all. | |
349 | */ | |
9570a20e | 350 | irq = &res->data.irq; |
5acf9141 BH |
351 | if (irq->interrupt_count == 0) |
352 | pnp_add_irq_resource(dev, 0, IORESOURCE_DISABLED); | |
353 | else { | |
354 | for (i = 0; i < irq->interrupt_count; i++) { | |
355 | pnpacpi_parse_allocated_irqresource(dev, | |
356 | irq->interrupts[i], | |
357 | irq->triggering, | |
358 | irq->polarity, | |
359 | irq->sharable); | |
360 | } | |
361 | ||
362 | /* | |
363 | * The IRQ encoder puts a single interrupt in each | |
364 | * descriptor, so if a _CRS descriptor has more than | |
365 | * one interrupt, we won't be able to re-encode it. | |
366 | */ | |
367 | if (pnp_can_write(dev) && irq->interrupt_count > 1) { | |
368 | dev_warn(&dev->dev, "multiple interrupts in " | |
369 | "_CRS descriptor; configuration can't " | |
370 | "be changed\n"); | |
371 | dev->capabilities &= ~PNP_WRITE; | |
372 | } | |
1da177e4 LT |
373 | } |
374 | break; | |
375 | ||
50eca3eb | 376 | case ACPI_RESOURCE_TYPE_DMA: |
9570a20e | 377 | dma = &res->data.dma; |
5acf9141 | 378 | if (dma->channel_count > 0 && dma->channels[0] != (u8) -1) |
958a1fdd | 379 | flags = dma_flags(dev, dma->type, dma->bus_master, |
dc16f5f2 | 380 | dma->transfer); |
5acf9141 BH |
381 | else |
382 | flags = IORESOURCE_DISABLED; | |
383 | pnp_add_dma_resource(dev, dma->channels[0], flags); | |
1da177e4 | 384 | break; |
0af5853b | 385 | |
50eca3eb | 386 | case ACPI_RESOURCE_TYPE_IO: |
9570a20e | 387 | io = &res->data.io; |
4ab55d8d | 388 | pnpacpi_parse_allocated_ioresource(dev, |
9570a20e BH |
389 | io->minimum, |
390 | io->address_length, | |
fa35b492 | 391 | io->io_decode, 0); |
1da177e4 | 392 | break; |
0af5853b LB |
393 | |
394 | case ACPI_RESOURCE_TYPE_START_DEPENDENT: | |
395 | case ACPI_RESOURCE_TYPE_END_DEPENDENT: | |
396 | break; | |
397 | ||
50eca3eb | 398 | case ACPI_RESOURCE_TYPE_FIXED_IO: |
9570a20e | 399 | fixed_io = &res->data.fixed_io; |
4ab55d8d | 400 | pnpacpi_parse_allocated_ioresource(dev, |
9570a20e BH |
401 | fixed_io->address, |
402 | fixed_io->address_length, | |
fa35b492 | 403 | ACPI_DECODE_10, 0); |
1da177e4 | 404 | break; |
0af5853b LB |
405 | |
406 | case ACPI_RESOURCE_TYPE_VENDOR: | |
40ab4f4c BH |
407 | vendor_typed = &res->data.vendor_typed; |
408 | pnpacpi_parse_allocated_vendor(dev, vendor_typed); | |
0af5853b LB |
409 | break; |
410 | ||
411 | case ACPI_RESOURCE_TYPE_END_TAG: | |
412 | break; | |
413 | ||
50eca3eb | 414 | case ACPI_RESOURCE_TYPE_MEMORY24: |
9570a20e | 415 | memory24 = &res->data.memory24; |
4ab55d8d | 416 | pnpacpi_parse_allocated_memresource(dev, |
9570a20e BH |
417 | memory24->minimum, |
418 | memory24->address_length, | |
fa35b492 | 419 | memory24->write_protect, 0); |
1da177e4 | 420 | break; |
50eca3eb | 421 | case ACPI_RESOURCE_TYPE_MEMORY32: |
9570a20e | 422 | memory32 = &res->data.memory32; |
4ab55d8d | 423 | pnpacpi_parse_allocated_memresource(dev, |
9570a20e BH |
424 | memory32->minimum, |
425 | memory32->address_length, | |
fa35b492 | 426 | memory32->write_protect, 0); |
1da177e4 | 427 | break; |
50eca3eb | 428 | case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: |
9570a20e | 429 | fixed_memory32 = &res->data.fixed_memory32; |
4ab55d8d | 430 | pnpacpi_parse_allocated_memresource(dev, |
9570a20e BH |
431 | fixed_memory32->address, |
432 | fixed_memory32->address_length, | |
fa35b492 | 433 | fixed_memory32->write_protect, 0); |
1da177e4 | 434 | break; |
50eca3eb | 435 | case ACPI_RESOURCE_TYPE_ADDRESS16: |
50eca3eb | 436 | case ACPI_RESOURCE_TYPE_ADDRESS32: |
50eca3eb | 437 | case ACPI_RESOURCE_TYPE_ADDRESS64: |
4ab55d8d | 438 | pnpacpi_parse_allocated_address_space(dev, res); |
1da177e4 | 439 | break; |
0af5853b LB |
440 | |
441 | case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64: | |
8cb24c8f | 442 | pnpacpi_parse_allocated_ext_address_space(dev, res); |
0af5853b LB |
443 | break; |
444 | ||
445 | case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: | |
9570a20e | 446 | extended_irq = &res->data.extended_irq; |
2b8de5f5 | 447 | |
5acf9141 BH |
448 | if (extended_irq->interrupt_count == 0) |
449 | pnp_add_irq_resource(dev, 0, IORESOURCE_DISABLED); | |
450 | else { | |
451 | for (i = 0; i < extended_irq->interrupt_count; i++) { | |
452 | pnpacpi_parse_allocated_irqresource(dev, | |
453 | extended_irq->interrupts[i], | |
454 | extended_irq->triggering, | |
455 | extended_irq->polarity, | |
456 | extended_irq->sharable); | |
457 | } | |
458 | ||
459 | /* | |
460 | * The IRQ encoder puts a single interrupt in each | |
461 | * descriptor, so if a _CRS descriptor has more than | |
462 | * one interrupt, we won't be able to re-encode it. | |
463 | */ | |
464 | if (pnp_can_write(dev) && | |
465 | extended_irq->interrupt_count > 1) { | |
466 | dev_warn(&dev->dev, "multiple interrupts in " | |
467 | "_CRS descriptor; configuration can't " | |
468 | "be changed\n"); | |
469 | dev->capabilities &= ~PNP_WRITE; | |
470 | } | |
0af5853b LB |
471 | } |
472 | break; | |
473 | ||
474 | case ACPI_RESOURCE_TYPE_GENERIC_REGISTER: | |
1da177e4 | 475 | break; |
0af5853b | 476 | |
1da177e4 | 477 | default: |
af11cb2d BH |
478 | dev_warn(&dev->dev, "unknown resource type %d in _CRS\n", |
479 | res->type); | |
1da177e4 LT |
480 | return AE_ERROR; |
481 | } | |
1c6e7d0a | 482 | |
1da177e4 LT |
483 | return AE_OK; |
484 | } | |
485 | ||
d152cf5d | 486 | int pnpacpi_parse_allocated_resource(struct pnp_dev *dev) |
1da177e4 | 487 | { |
c4da6940 BH |
488 | struct acpi_device *acpi_dev = dev->data; |
489 | acpi_handle handle = acpi_dev->handle; | |
d152cf5d | 490 | acpi_status status; |
4ab55d8d | 491 | |
2f53432c | 492 | pnp_dbg(&dev->dev, "parse allocated resources\n"); |
72dcc883 | 493 | |
f4490002 | 494 | pnp_init_resources(dev); |
1da177e4 | 495 | |
d152cf5d BH |
496 | status = acpi_walk_resources(handle, METHOD_NAME__CRS, |
497 | pnpacpi_allocated_resource, dev); | |
498 | ||
499 | if (ACPI_FAILURE(status)) { | |
500 | if (status != AE_NOT_FOUND) | |
501 | dev_err(&dev->dev, "can't evaluate _CRS: %d", status); | |
502 | return -EPERM; | |
503 | } | |
504 | return 0; | |
1da177e4 LT |
505 | } |
506 | ||
c1caf06c | 507 | static __init void pnpacpi_parse_dma_option(struct pnp_dev *dev, |
1f32ca31 | 508 | unsigned int option_flags, |
2bb9a6b3 | 509 | struct acpi_resource_dma *p) |
1da177e4 LT |
510 | { |
511 | int i; | |
18fd470a | 512 | unsigned char map = 0, flags; |
1da177e4 | 513 | |
9dd78466 | 514 | for (i = 0; i < p->channel_count; i++) |
c227536b | 515 | map |= 1 << p->channels[i]; |
1da177e4 | 516 | |
18fd470a | 517 | flags = dma_flags(dev, p->type, p->bus_master, p->transfer); |
1f32ca31 | 518 | pnp_register_dma_resource(dev, option_flags, map, flags); |
1da177e4 LT |
519 | } |
520 | ||
c1caf06c | 521 | static __init void pnpacpi_parse_irq_option(struct pnp_dev *dev, |
1f32ca31 | 522 | unsigned int option_flags, |
2bb9a6b3 | 523 | struct acpi_resource_irq *p) |
1da177e4 LT |
524 | { |
525 | int i; | |
c227536b | 526 | pnp_irq_mask_t map; |
18fd470a | 527 | unsigned char flags; |
1da177e4 | 528 | |
c227536b | 529 | bitmap_zero(map.bits, PNP_IRQ_NR); |
9dd78466 | 530 | for (i = 0; i < p->interrupt_count; i++) |
1da177e4 | 531 | if (p->interrupts[i]) |
c227536b | 532 | __set_bit(p->interrupts[i], map.bits); |
1da177e4 | 533 | |
18fd470a | 534 | flags = irq_flags(p->triggering, p->polarity, p->sharable); |
1f32ca31 | 535 | pnp_register_irq_resource(dev, option_flags, &map, flags); |
1da177e4 LT |
536 | } |
537 | ||
c1caf06c | 538 | static __init void pnpacpi_parse_ext_irq_option(struct pnp_dev *dev, |
1f32ca31 | 539 | unsigned int option_flags, |
2bb9a6b3 | 540 | struct acpi_resource_extended_irq *p) |
1da177e4 LT |
541 | { |
542 | int i; | |
c227536b | 543 | pnp_irq_mask_t map; |
18fd470a | 544 | unsigned char flags; |
1da177e4 | 545 | |
c227536b | 546 | bitmap_zero(map.bits, PNP_IRQ_NR); |
fe2cf598 BH |
547 | for (i = 0; i < p->interrupt_count; i++) { |
548 | if (p->interrupts[i]) { | |
549 | if (p->interrupts[i] < PNP_IRQ_NR) | |
550 | __set_bit(p->interrupts[i], map.bits); | |
551 | else | |
552 | dev_err(&dev->dev, "ignoring IRQ %d option " | |
553 | "(too large for %d entry bitmap)\n", | |
554 | p->interrupts[i], PNP_IRQ_NR); | |
555 | } | |
556 | } | |
1da177e4 | 557 | |
18fd470a | 558 | flags = irq_flags(p->triggering, p->polarity, p->sharable); |
1f32ca31 | 559 | pnp_register_irq_resource(dev, option_flags, &map, flags); |
1da177e4 LT |
560 | } |
561 | ||
c1caf06c | 562 | static __init void pnpacpi_parse_port_option(struct pnp_dev *dev, |
1f32ca31 | 563 | unsigned int option_flags, |
2bb9a6b3 | 564 | struct acpi_resource_io *io) |
1da177e4 | 565 | { |
c227536b | 566 | unsigned char flags = 0; |
1da177e4 | 567 | |
c227536b | 568 | if (io->io_decode == ACPI_DECODE_16) |
18fd470a | 569 | flags = IORESOURCE_IO_16BIT_ADDR; |
1f32ca31 | 570 | pnp_register_port_resource(dev, option_flags, io->minimum, io->maximum, |
c227536b | 571 | io->alignment, io->address_length, flags); |
1da177e4 LT |
572 | } |
573 | ||
c1caf06c | 574 | static __init void pnpacpi_parse_fixed_port_option(struct pnp_dev *dev, |
1f32ca31 | 575 | unsigned int option_flags, |
2bb9a6b3 | 576 | struct acpi_resource_fixed_io *io) |
1da177e4 | 577 | { |
1f32ca31 | 578 | pnp_register_port_resource(dev, option_flags, io->address, io->address, |
18fd470a | 579 | 0, io->address_length, IORESOURCE_IO_FIXED); |
1da177e4 LT |
580 | } |
581 | ||
c1caf06c | 582 | static __init void pnpacpi_parse_mem24_option(struct pnp_dev *dev, |
1f32ca31 | 583 | unsigned int option_flags, |
2bb9a6b3 | 584 | struct acpi_resource_memory24 *p) |
1da177e4 | 585 | { |
c227536b | 586 | unsigned char flags = 0; |
1da177e4 | 587 | |
c227536b | 588 | if (p->write_protect == ACPI_READ_WRITE_MEMORY) |
18fd470a | 589 | flags = IORESOURCE_MEM_WRITEABLE; |
1f32ca31 | 590 | pnp_register_mem_resource(dev, option_flags, p->minimum, p->maximum, |
c227536b | 591 | p->alignment, p->address_length, flags); |
1da177e4 LT |
592 | } |
593 | ||
c1caf06c | 594 | static __init void pnpacpi_parse_mem32_option(struct pnp_dev *dev, |
1f32ca31 | 595 | unsigned int option_flags, |
2bb9a6b3 | 596 | struct acpi_resource_memory32 *p) |
1da177e4 | 597 | { |
c227536b | 598 | unsigned char flags = 0; |
1da177e4 | 599 | |
c227536b | 600 | if (p->write_protect == ACPI_READ_WRITE_MEMORY) |
18fd470a | 601 | flags = IORESOURCE_MEM_WRITEABLE; |
1f32ca31 | 602 | pnp_register_mem_resource(dev, option_flags, p->minimum, p->maximum, |
c227536b | 603 | p->alignment, p->address_length, flags); |
1da177e4 LT |
604 | } |
605 | ||
c1caf06c | 606 | static __init void pnpacpi_parse_fixed_mem32_option(struct pnp_dev *dev, |
1f32ca31 | 607 | unsigned int option_flags, |
2bb9a6b3 | 608 | struct acpi_resource_fixed_memory32 *p) |
1da177e4 | 609 | { |
c227536b | 610 | unsigned char flags = 0; |
1da177e4 | 611 | |
c227536b | 612 | if (p->write_protect == ACPI_READ_WRITE_MEMORY) |
18fd470a | 613 | flags = IORESOURCE_MEM_WRITEABLE; |
1f32ca31 | 614 | pnp_register_mem_resource(dev, option_flags, p->address, p->address, |
c227536b | 615 | 0, p->address_length, flags); |
1da177e4 LT |
616 | } |
617 | ||
c1caf06c | 618 | static __init void pnpacpi_parse_address_option(struct pnp_dev *dev, |
1f32ca31 | 619 | unsigned int option_flags, |
2bb9a6b3 | 620 | struct acpi_resource *r) |
6f957eaf BH |
621 | { |
622 | struct acpi_resource_address64 addr, *p = &addr; | |
623 | acpi_status status; | |
c227536b | 624 | unsigned char flags = 0; |
6f957eaf BH |
625 | |
626 | status = acpi_resource_to_address64(r, p); | |
958a1fdd BH |
627 | if (ACPI_FAILURE(status)) { |
628 | dev_warn(&dev->dev, "can't convert resource type %d\n", | |
9dd78466 | 629 | r->type); |
6f957eaf BH |
630 | return; |
631 | } | |
632 | ||
6f957eaf | 633 | if (p->resource_type == ACPI_MEMORY_RANGE) { |
c227536b | 634 | if (p->info.mem.write_protect == ACPI_READ_WRITE_MEMORY) |
18fd470a | 635 | flags = IORESOURCE_MEM_WRITEABLE; |
1f32ca31 BH |
636 | pnp_register_mem_resource(dev, option_flags, p->minimum, |
637 | p->minimum, 0, p->address_length, | |
638 | flags); | |
c227536b | 639 | } else if (p->resource_type == ACPI_IO_RANGE) |
1f32ca31 BH |
640 | pnp_register_port_resource(dev, option_flags, p->minimum, |
641 | p->minimum, 0, p->address_length, | |
18fd470a | 642 | IORESOURCE_IO_FIXED); |
6f957eaf BH |
643 | } |
644 | ||
8cb24c8f BH |
645 | static __init void pnpacpi_parse_ext_address_option(struct pnp_dev *dev, |
646 | unsigned int option_flags, | |
647 | struct acpi_resource *r) | |
648 | { | |
649 | struct acpi_resource_extended_address64 *p = &r->data.ext_address64; | |
650 | unsigned char flags = 0; | |
651 | ||
8cb24c8f BH |
652 | if (p->resource_type == ACPI_MEMORY_RANGE) { |
653 | if (p->info.mem.write_protect == ACPI_READ_WRITE_MEMORY) | |
18fd470a | 654 | flags = IORESOURCE_MEM_WRITEABLE; |
8cb24c8f BH |
655 | pnp_register_mem_resource(dev, option_flags, p->minimum, |
656 | p->minimum, 0, p->address_length, | |
657 | flags); | |
658 | } else if (p->resource_type == ACPI_IO_RANGE) | |
659 | pnp_register_port_resource(dev, option_flags, p->minimum, | |
660 | p->minimum, 0, p->address_length, | |
18fd470a | 661 | IORESOURCE_IO_FIXED); |
8cb24c8f BH |
662 | } |
663 | ||
1da177e4 | 664 | struct acpipnp_parse_option_s { |
1da177e4 | 665 | struct pnp_dev *dev; |
1f32ca31 | 666 | unsigned int option_flags; |
1da177e4 LT |
667 | }; |
668 | ||
2bb9a6b3 TR |
669 | static __init acpi_status pnpacpi_option_resource(struct acpi_resource *res, |
670 | void *data) | |
1da177e4 | 671 | { |
e2a1a6f1 | 672 | int priority; |
4721a4cc | 673 | struct acpipnp_parse_option_s *parse_data = data; |
1da177e4 | 674 | struct pnp_dev *dev = parse_data->dev; |
1f32ca31 | 675 | unsigned int option_flags = parse_data->option_flags; |
1da177e4 | 676 | |
eca008c8 | 677 | switch (res->type) { |
9dd78466 | 678 | case ACPI_RESOURCE_TYPE_IRQ: |
1f32ca31 | 679 | pnpacpi_parse_irq_option(dev, option_flags, &res->data.irq); |
9dd78466 | 680 | break; |
0af5853b | 681 | |
9dd78466 | 682 | case ACPI_RESOURCE_TYPE_DMA: |
1f32ca31 | 683 | pnpacpi_parse_dma_option(dev, option_flags, &res->data.dma); |
9dd78466 | 684 | break; |
0af5853b | 685 | |
9dd78466 BH |
686 | case ACPI_RESOURCE_TYPE_START_DEPENDENT: |
687 | switch (res->data.start_dpf.compatibility_priority) { | |
688 | case ACPI_GOOD_CONFIGURATION: | |
689 | priority = PNP_RES_PRIORITY_PREFERRED; | |
1da177e4 | 690 | break; |
0af5853b | 691 | |
9dd78466 BH |
692 | case ACPI_ACCEPTABLE_CONFIGURATION: |
693 | priority = PNP_RES_PRIORITY_ACCEPTABLE; | |
b008b8d7 | 694 | break; |
0af5853b | 695 | |
9dd78466 BH |
696 | case ACPI_SUB_OPTIMAL_CONFIGURATION: |
697 | priority = PNP_RES_PRIORITY_FUNCTIONAL; | |
0af5853b | 698 | break; |
9dd78466 BH |
699 | default: |
700 | priority = PNP_RES_PRIORITY_INVALID; | |
0af5853b | 701 | break; |
9dd78466 | 702 | } |
1f32ca31 | 703 | parse_data->option_flags = pnp_new_dependent_set(dev, priority); |
9dd78466 | 704 | break; |
0af5853b | 705 | |
9dd78466 | 706 | case ACPI_RESOURCE_TYPE_END_DEPENDENT: |
1f32ca31 | 707 | parse_data->option_flags = 0; |
9dd78466 | 708 | break; |
0af5853b | 709 | |
9dd78466 | 710 | case ACPI_RESOURCE_TYPE_IO: |
1f32ca31 | 711 | pnpacpi_parse_port_option(dev, option_flags, &res->data.io); |
9dd78466 | 712 | break; |
0af5853b | 713 | |
9dd78466 | 714 | case ACPI_RESOURCE_TYPE_FIXED_IO: |
1f32ca31 | 715 | pnpacpi_parse_fixed_port_option(dev, option_flags, |
c1caf06c | 716 | &res->data.fixed_io); |
9dd78466 | 717 | break; |
0af5853b | 718 | |
9dd78466 BH |
719 | case ACPI_RESOURCE_TYPE_VENDOR: |
720 | case ACPI_RESOURCE_TYPE_END_TAG: | |
721 | break; | |
0af5853b | 722 | |
9dd78466 | 723 | case ACPI_RESOURCE_TYPE_MEMORY24: |
1f32ca31 BH |
724 | pnpacpi_parse_mem24_option(dev, option_flags, |
725 | &res->data.memory24); | |
9dd78466 | 726 | break; |
0af5853b | 727 | |
9dd78466 | 728 | case ACPI_RESOURCE_TYPE_MEMORY32: |
1f32ca31 BH |
729 | pnpacpi_parse_mem32_option(dev, option_flags, |
730 | &res->data.memory32); | |
9dd78466 | 731 | break; |
0af5853b | 732 | |
9dd78466 | 733 | case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: |
1f32ca31 | 734 | pnpacpi_parse_fixed_mem32_option(dev, option_flags, |
9dd78466 BH |
735 | &res->data.fixed_memory32); |
736 | break; | |
0af5853b | 737 | |
9dd78466 BH |
738 | case ACPI_RESOURCE_TYPE_ADDRESS16: |
739 | case ACPI_RESOURCE_TYPE_ADDRESS32: | |
740 | case ACPI_RESOURCE_TYPE_ADDRESS64: | |
1f32ca31 | 741 | pnpacpi_parse_address_option(dev, option_flags, res); |
9dd78466 | 742 | break; |
0af5853b | 743 | |
9dd78466 | 744 | case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64: |
8cb24c8f | 745 | pnpacpi_parse_ext_address_option(dev, option_flags, res); |
9dd78466 BH |
746 | break; |
747 | ||
748 | case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: | |
1f32ca31 | 749 | pnpacpi_parse_ext_irq_option(dev, option_flags, |
c1caf06c | 750 | &res->data.extended_irq); |
9dd78466 BH |
751 | break; |
752 | ||
753 | case ACPI_RESOURCE_TYPE_GENERIC_REGISTER: | |
754 | break; | |
755 | ||
756 | default: | |
af11cb2d BH |
757 | dev_warn(&dev->dev, "unknown resource type %d in _PRS\n", |
758 | res->type); | |
9dd78466 | 759 | return AE_ERROR; |
1da177e4 | 760 | } |
1c6e7d0a | 761 | |
1da177e4 LT |
762 | return AE_OK; |
763 | } | |
764 | ||
d152cf5d | 765 | int __init pnpacpi_parse_resource_option_data(struct pnp_dev *dev) |
1da177e4 | 766 | { |
c4da6940 BH |
767 | struct acpi_device *acpi_dev = dev->data; |
768 | acpi_handle handle = acpi_dev->handle; | |
1da177e4 LT |
769 | acpi_status status; |
770 | struct acpipnp_parse_option_s parse_data; | |
771 | ||
2f53432c | 772 | pnp_dbg(&dev->dev, "parse resource options\n"); |
72dcc883 | 773 | |
1da177e4 | 774 | parse_data.dev = dev; |
1f32ca31 BH |
775 | parse_data.option_flags = 0; |
776 | ||
50eca3eb | 777 | status = acpi_walk_resources(handle, METHOD_NAME__PRS, |
9dd78466 | 778 | pnpacpi_option_resource, &parse_data); |
1da177e4 | 779 | |
d152cf5d BH |
780 | if (ACPI_FAILURE(status)) { |
781 | if (status != AE_NOT_FOUND) | |
782 | dev_err(&dev->dev, "can't evaluate _PRS: %d", status); | |
783 | return -EPERM; | |
784 | } | |
785 | return 0; | |
1da177e4 LT |
786 | } |
787 | ||
b5f2490b | 788 | static int pnpacpi_supported_resource(struct acpi_resource *res) |
1da177e4 | 789 | { |
eca008c8 | 790 | switch (res->type) { |
50eca3eb | 791 | case ACPI_RESOURCE_TYPE_IRQ: |
50eca3eb BM |
792 | case ACPI_RESOURCE_TYPE_DMA: |
793 | case ACPI_RESOURCE_TYPE_IO: | |
794 | case ACPI_RESOURCE_TYPE_FIXED_IO: | |
795 | case ACPI_RESOURCE_TYPE_MEMORY24: | |
796 | case ACPI_RESOURCE_TYPE_MEMORY32: | |
797 | case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: | |
50eca3eb BM |
798 | case ACPI_RESOURCE_TYPE_ADDRESS16: |
799 | case ACPI_RESOURCE_TYPE_ADDRESS32: | |
800 | case ACPI_RESOURCE_TYPE_ADDRESS64: | |
8cb24c8f | 801 | case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64: |
0af5853b | 802 | case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: |
b5f2490b | 803 | return 1; |
1da177e4 | 804 | } |
b5f2490b BH |
805 | return 0; |
806 | } | |
807 | ||
808 | /* | |
809 | * Set resource | |
810 | */ | |
811 | static acpi_status pnpacpi_count_resources(struct acpi_resource *res, | |
9dd78466 | 812 | void *data) |
b5f2490b | 813 | { |
4721a4cc | 814 | int *res_cnt = data; |
b5f2490b BH |
815 | |
816 | if (pnpacpi_supported_resource(res)) | |
817 | (*res_cnt)++; | |
1da177e4 LT |
818 | return AE_OK; |
819 | } | |
820 | ||
1c6e7d0a | 821 | static acpi_status pnpacpi_type_resources(struct acpi_resource *res, void *data) |
1da177e4 | 822 | { |
4721a4cc | 823 | struct acpi_resource **resource = data; |
b5f2490b BH |
824 | |
825 | if (pnpacpi_supported_resource(res)) { | |
eca008c8 | 826 | (*resource)->type = res->type; |
b5f2490b | 827 | (*resource)->length = sizeof(struct acpi_resource); |
36d872a3 BH |
828 | if (res->type == ACPI_RESOURCE_TYPE_IRQ) |
829 | (*resource)->data.irq.descriptor_length = | |
830 | res->data.irq.descriptor_length; | |
1da177e4 | 831 | (*resource)++; |
1da177e4 LT |
832 | } |
833 | ||
834 | return AE_OK; | |
835 | } | |
836 | ||
cdef6254 | 837 | int pnpacpi_build_resource_template(struct pnp_dev *dev, |
9dd78466 | 838 | struct acpi_buffer *buffer) |
1da177e4 | 839 | { |
c4da6940 BH |
840 | struct acpi_device *acpi_dev = dev->data; |
841 | acpi_handle handle = acpi_dev->handle; | |
1da177e4 LT |
842 | struct acpi_resource *resource; |
843 | int res_cnt = 0; | |
844 | acpi_status status; | |
845 | ||
50eca3eb | 846 | status = acpi_walk_resources(handle, METHOD_NAME__CRS, |
9dd78466 | 847 | pnpacpi_count_resources, &res_cnt); |
1da177e4 | 848 | if (ACPI_FAILURE(status)) { |
d152cf5d | 849 | dev_err(&dev->dev, "can't evaluate _CRS: %d\n", status); |
1da177e4 LT |
850 | return -EINVAL; |
851 | } | |
852 | if (!res_cnt) | |
853 | return -EINVAL; | |
854 | buffer->length = sizeof(struct acpi_resource) * (res_cnt + 1) + 1; | |
cd861280 | 855 | buffer->pointer = kzalloc(buffer->length - 1, GFP_KERNEL); |
1da177e4 LT |
856 | if (!buffer->pointer) |
857 | return -ENOMEM; | |
72dcc883 | 858 | |
1da177e4 | 859 | resource = (struct acpi_resource *)buffer->pointer; |
50eca3eb | 860 | status = acpi_walk_resources(handle, METHOD_NAME__CRS, |
9dd78466 | 861 | pnpacpi_type_resources, &resource); |
1da177e4 LT |
862 | if (ACPI_FAILURE(status)) { |
863 | kfree(buffer->pointer); | |
d152cf5d | 864 | dev_err(&dev->dev, "can't evaluate _CRS: %d\n", status); |
1da177e4 LT |
865 | return -EINVAL; |
866 | } | |
867 | /* resource will pointer the end resource now */ | |
50eca3eb | 868 | resource->type = ACPI_RESOURCE_TYPE_END_TAG; |
1da177e4 LT |
869 | |
870 | return 0; | |
871 | } | |
872 | ||
72dcc883 BH |
873 | static void pnpacpi_encode_irq(struct pnp_dev *dev, |
874 | struct acpi_resource *resource, | |
9dd78466 | 875 | struct resource *p) |
1da177e4 | 876 | { |
9570a20e | 877 | struct acpi_resource_irq *irq = &resource->data.irq; |
a993273b | 878 | int triggering, polarity, shareable; |
1c6e7d0a | 879 | |
aee3ad81 BH |
880 | if (!pnp_resource_enabled(p)) { |
881 | irq->interrupt_count = 0; | |
2f53432c | 882 | pnp_dbg(&dev->dev, " encode irq (%s)\n", |
aee3ad81 BH |
883 | p ? "disabled" : "missing"); |
884 | return; | |
885 | } | |
886 | ||
a993273b | 887 | decode_irq_flags(dev, p->flags, &triggering, &polarity, &shareable); |
9570a20e BH |
888 | irq->triggering = triggering; |
889 | irq->polarity = polarity; | |
a993273b | 890 | irq->sharable = shareable; |
9570a20e BH |
891 | irq->interrupt_count = 1; |
892 | irq->interrupts[0] = p->start; | |
72dcc883 | 893 | |
2f53432c | 894 | pnp_dbg(&dev->dev, " encode irq %d %s %s %s (%d-byte descriptor)\n", |
36d872a3 | 895 | (int) p->start, |
72dcc883 BH |
896 | triggering == ACPI_LEVEL_SENSITIVE ? "level" : "edge", |
897 | polarity == ACPI_ACTIVE_LOW ? "low" : "high", | |
36d872a3 BH |
898 | irq->sharable == ACPI_SHARED ? "shared" : "exclusive", |
899 | irq->descriptor_length); | |
1da177e4 LT |
900 | } |
901 | ||
72dcc883 BH |
902 | static void pnpacpi_encode_ext_irq(struct pnp_dev *dev, |
903 | struct acpi_resource *resource, | |
9dd78466 | 904 | struct resource *p) |
1da177e4 | 905 | { |
9570a20e | 906 | struct acpi_resource_extended_irq *extended_irq = &resource->data.extended_irq; |
a993273b | 907 | int triggering, polarity, shareable; |
1c6e7d0a | 908 | |
aee3ad81 BH |
909 | if (!pnp_resource_enabled(p)) { |
910 | extended_irq->interrupt_count = 0; | |
2f53432c | 911 | pnp_dbg(&dev->dev, " encode extended irq (%s)\n", |
aee3ad81 BH |
912 | p ? "disabled" : "missing"); |
913 | return; | |
914 | } | |
915 | ||
a993273b | 916 | decode_irq_flags(dev, p->flags, &triggering, &polarity, &shareable); |
9570a20e BH |
917 | extended_irq->producer_consumer = ACPI_CONSUMER; |
918 | extended_irq->triggering = triggering; | |
919 | extended_irq->polarity = polarity; | |
a993273b | 920 | extended_irq->sharable = shareable; |
9570a20e BH |
921 | extended_irq->interrupt_count = 1; |
922 | extended_irq->interrupts[0] = p->start; | |
72dcc883 | 923 | |
2f53432c | 924 | pnp_dbg(&dev->dev, " encode irq %d %s %s %s\n", (int) p->start, |
72dcc883 BH |
925 | triggering == ACPI_LEVEL_SENSITIVE ? "level" : "edge", |
926 | polarity == ACPI_ACTIVE_LOW ? "low" : "high", | |
927 | extended_irq->sharable == ACPI_SHARED ? "shared" : "exclusive"); | |
1da177e4 LT |
928 | } |
929 | ||
72dcc883 BH |
930 | static void pnpacpi_encode_dma(struct pnp_dev *dev, |
931 | struct acpi_resource *resource, | |
9dd78466 | 932 | struct resource *p) |
1da177e4 | 933 | { |
9570a20e BH |
934 | struct acpi_resource_dma *dma = &resource->data.dma; |
935 | ||
aee3ad81 BH |
936 | if (!pnp_resource_enabled(p)) { |
937 | dma->channel_count = 0; | |
2f53432c | 938 | pnp_dbg(&dev->dev, " encode dma (%s)\n", |
aee3ad81 BH |
939 | p ? "disabled" : "missing"); |
940 | return; | |
941 | } | |
942 | ||
1da177e4 | 943 | /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */ |
ccc4c7bb | 944 | switch (p->flags & IORESOURCE_DMA_SPEED_MASK) { |
9dd78466 | 945 | case IORESOURCE_DMA_TYPEA: |
9570a20e | 946 | dma->type = ACPI_TYPE_A; |
9dd78466 BH |
947 | break; |
948 | case IORESOURCE_DMA_TYPEB: | |
9570a20e | 949 | dma->type = ACPI_TYPE_B; |
9dd78466 BH |
950 | break; |
951 | case IORESOURCE_DMA_TYPEF: | |
9570a20e | 952 | dma->type = ACPI_TYPE_F; |
9dd78466 BH |
953 | break; |
954 | default: | |
9570a20e | 955 | dma->type = ACPI_COMPATIBILITY; |
ccc4c7bb VP |
956 | } |
957 | ||
958 | switch (p->flags & IORESOURCE_DMA_TYPE_MASK) { | |
9dd78466 | 959 | case IORESOURCE_DMA_8BIT: |
9570a20e | 960 | dma->transfer = ACPI_TRANSFER_8; |
9dd78466 BH |
961 | break; |
962 | case IORESOURCE_DMA_8AND16BIT: | |
9570a20e | 963 | dma->transfer = ACPI_TRANSFER_8_16; |
9dd78466 BH |
964 | break; |
965 | default: | |
9570a20e | 966 | dma->transfer = ACPI_TRANSFER_16; |
ccc4c7bb VP |
967 | } |
968 | ||
9570a20e BH |
969 | dma->bus_master = !!(p->flags & IORESOURCE_DMA_MASTER); |
970 | dma->channel_count = 1; | |
971 | dma->channels[0] = p->start; | |
72dcc883 | 972 | |
2f53432c | 973 | pnp_dbg(&dev->dev, " encode dma %d " |
72dcc883 BH |
974 | "type %#x transfer %#x master %d\n", |
975 | (int) p->start, dma->type, dma->transfer, dma->bus_master); | |
1da177e4 LT |
976 | } |
977 | ||
72dcc883 BH |
978 | static void pnpacpi_encode_io(struct pnp_dev *dev, |
979 | struct acpi_resource *resource, | |
9dd78466 | 980 | struct resource *p) |
1da177e4 | 981 | { |
9570a20e BH |
982 | struct acpi_resource_io *io = &resource->data.io; |
983 | ||
aee3ad81 BH |
984 | if (pnp_resource_enabled(p)) { |
985 | /* Note: pnp_assign_port copies pnp_port->flags into p->flags */ | |
08c9f262 | 986 | io->io_decode = (p->flags & IORESOURCE_IO_16BIT_ADDR) ? |
aee3ad81 BH |
987 | ACPI_DECODE_16 : ACPI_DECODE_10; |
988 | io->minimum = p->start; | |
989 | io->maximum = p->end; | |
990 | io->alignment = 0; /* Correct? */ | |
28f65c11 | 991 | io->address_length = resource_size(p); |
aee3ad81 BH |
992 | } else { |
993 | io->minimum = 0; | |
994 | io->address_length = 0; | |
995 | } | |
72dcc883 | 996 | |
2f53432c | 997 | pnp_dbg(&dev->dev, " encode io %#x-%#x decode %#x\n", io->minimum, |
aee3ad81 | 998 | io->minimum + io->address_length - 1, io->io_decode); |
1da177e4 LT |
999 | } |
1000 | ||
72dcc883 BH |
1001 | static void pnpacpi_encode_fixed_io(struct pnp_dev *dev, |
1002 | struct acpi_resource *resource, | |
9dd78466 | 1003 | struct resource *p) |
1da177e4 | 1004 | { |
9570a20e BH |
1005 | struct acpi_resource_fixed_io *fixed_io = &resource->data.fixed_io; |
1006 | ||
aee3ad81 BH |
1007 | if (pnp_resource_enabled(p)) { |
1008 | fixed_io->address = p->start; | |
28f65c11 | 1009 | fixed_io->address_length = resource_size(p); |
aee3ad81 BH |
1010 | } else { |
1011 | fixed_io->address = 0; | |
1012 | fixed_io->address_length = 0; | |
1013 | } | |
72dcc883 | 1014 | |
2f53432c | 1015 | pnp_dbg(&dev->dev, " encode fixed_io %#x-%#x\n", fixed_io->address, |
aee3ad81 | 1016 | fixed_io->address + fixed_io->address_length - 1); |
1da177e4 LT |
1017 | } |
1018 | ||
72dcc883 BH |
1019 | static void pnpacpi_encode_mem24(struct pnp_dev *dev, |
1020 | struct acpi_resource *resource, | |
9dd78466 | 1021 | struct resource *p) |
1da177e4 | 1022 | { |
9570a20e BH |
1023 | struct acpi_resource_memory24 *memory24 = &resource->data.memory24; |
1024 | ||
aee3ad81 BH |
1025 | if (pnp_resource_enabled(p)) { |
1026 | /* Note: pnp_assign_mem copies pnp_mem->flags into p->flags */ | |
1027 | memory24->write_protect = p->flags & IORESOURCE_MEM_WRITEABLE ? | |
1028 | ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; | |
1029 | memory24->minimum = p->start; | |
1030 | memory24->maximum = p->end; | |
1031 | memory24->alignment = 0; | |
28f65c11 | 1032 | memory24->address_length = resource_size(p); |
aee3ad81 BH |
1033 | } else { |
1034 | memory24->minimum = 0; | |
1035 | memory24->address_length = 0; | |
1036 | } | |
1037 | ||
2f53432c | 1038 | pnp_dbg(&dev->dev, " encode mem24 %#x-%#x write_protect %#x\n", |
aee3ad81 BH |
1039 | memory24->minimum, |
1040 | memory24->minimum + memory24->address_length - 1, | |
72dcc883 | 1041 | memory24->write_protect); |
1da177e4 LT |
1042 | } |
1043 | ||
72dcc883 BH |
1044 | static void pnpacpi_encode_mem32(struct pnp_dev *dev, |
1045 | struct acpi_resource *resource, | |
9dd78466 | 1046 | struct resource *p) |
1da177e4 | 1047 | { |
9570a20e BH |
1048 | struct acpi_resource_memory32 *memory32 = &resource->data.memory32; |
1049 | ||
aee3ad81 BH |
1050 | if (pnp_resource_enabled(p)) { |
1051 | memory32->write_protect = p->flags & IORESOURCE_MEM_WRITEABLE ? | |
1052 | ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; | |
1053 | memory32->minimum = p->start; | |
1054 | memory32->maximum = p->end; | |
1055 | memory32->alignment = 0; | |
28f65c11 | 1056 | memory32->address_length = resource_size(p); |
aee3ad81 BH |
1057 | } else { |
1058 | memory32->minimum = 0; | |
1059 | memory32->alignment = 0; | |
1060 | } | |
72dcc883 | 1061 | |
2f53432c | 1062 | pnp_dbg(&dev->dev, " encode mem32 %#x-%#x write_protect %#x\n", |
aee3ad81 BH |
1063 | memory32->minimum, |
1064 | memory32->minimum + memory32->address_length - 1, | |
72dcc883 | 1065 | memory32->write_protect); |
1da177e4 LT |
1066 | } |
1067 | ||
72dcc883 BH |
1068 | static void pnpacpi_encode_fixed_mem32(struct pnp_dev *dev, |
1069 | struct acpi_resource *resource, | |
9dd78466 | 1070 | struct resource *p) |
1da177e4 | 1071 | { |
9570a20e BH |
1072 | struct acpi_resource_fixed_memory32 *fixed_memory32 = &resource->data.fixed_memory32; |
1073 | ||
aee3ad81 BH |
1074 | if (pnp_resource_enabled(p)) { |
1075 | fixed_memory32->write_protect = | |
1076 | p->flags & IORESOURCE_MEM_WRITEABLE ? | |
1077 | ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; | |
1078 | fixed_memory32->address = p->start; | |
28f65c11 | 1079 | fixed_memory32->address_length = resource_size(p); |
aee3ad81 BH |
1080 | } else { |
1081 | fixed_memory32->address = 0; | |
1082 | fixed_memory32->address_length = 0; | |
1083 | } | |
72dcc883 | 1084 | |
2f53432c | 1085 | pnp_dbg(&dev->dev, " encode fixed_mem32 %#x-%#x write_protect %#x\n", |
aee3ad81 BH |
1086 | fixed_memory32->address, |
1087 | fixed_memory32->address + fixed_memory32->address_length - 1, | |
72dcc883 | 1088 | fixed_memory32->write_protect); |
1da177e4 LT |
1089 | } |
1090 | ||
4ab55d8d | 1091 | int pnpacpi_encode_resources(struct pnp_dev *dev, struct acpi_buffer *buffer) |
1da177e4 LT |
1092 | { |
1093 | int i = 0; | |
1094 | /* pnpacpi_build_resource_template allocates extra mem */ | |
9dd78466 | 1095 | int res_cnt = (buffer->length - 1) / sizeof(struct acpi_resource) - 1; |
4721a4cc | 1096 | struct acpi_resource *resource = buffer->pointer; |
1da177e4 LT |
1097 | int port = 0, irq = 0, dma = 0, mem = 0; |
1098 | ||
2f53432c | 1099 | pnp_dbg(&dev->dev, "encode %d resources\n", res_cnt); |
1da177e4 | 1100 | while (i < res_cnt) { |
9dd78466 | 1101 | switch (resource->type) { |
50eca3eb | 1102 | case ACPI_RESOURCE_TYPE_IRQ: |
72dcc883 | 1103 | pnpacpi_encode_irq(dev, resource, |
7e2cf31f | 1104 | pnp_get_resource(dev, IORESOURCE_IRQ, irq)); |
1da177e4 LT |
1105 | irq++; |
1106 | break; | |
1107 | ||
50eca3eb | 1108 | case ACPI_RESOURCE_TYPE_DMA: |
72dcc883 | 1109 | pnpacpi_encode_dma(dev, resource, |
7e2cf31f | 1110 | pnp_get_resource(dev, IORESOURCE_DMA, dma)); |
1c6e7d0a | 1111 | dma++; |
1da177e4 | 1112 | break; |
50eca3eb | 1113 | case ACPI_RESOURCE_TYPE_IO: |
72dcc883 | 1114 | pnpacpi_encode_io(dev, resource, |
7e2cf31f | 1115 | pnp_get_resource(dev, IORESOURCE_IO, port)); |
1c6e7d0a | 1116 | port++; |
1da177e4 | 1117 | break; |
50eca3eb | 1118 | case ACPI_RESOURCE_TYPE_FIXED_IO: |
72dcc883 | 1119 | pnpacpi_encode_fixed_io(dev, resource, |
7e2cf31f | 1120 | pnp_get_resource(dev, IORESOURCE_IO, port)); |
1c6e7d0a | 1121 | port++; |
1da177e4 | 1122 | break; |
50eca3eb | 1123 | case ACPI_RESOURCE_TYPE_MEMORY24: |
72dcc883 | 1124 | pnpacpi_encode_mem24(dev, resource, |
7e2cf31f | 1125 | pnp_get_resource(dev, IORESOURCE_MEM, mem)); |
1c6e7d0a | 1126 | mem++; |
1da177e4 | 1127 | break; |
50eca3eb | 1128 | case ACPI_RESOURCE_TYPE_MEMORY32: |
72dcc883 | 1129 | pnpacpi_encode_mem32(dev, resource, |
7e2cf31f | 1130 | pnp_get_resource(dev, IORESOURCE_MEM, mem)); |
1c6e7d0a | 1131 | mem++; |
1da177e4 | 1132 | break; |
50eca3eb | 1133 | case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: |
72dcc883 | 1134 | pnpacpi_encode_fixed_mem32(dev, resource, |
7e2cf31f | 1135 | pnp_get_resource(dev, IORESOURCE_MEM, mem)); |
1c6e7d0a | 1136 | mem++; |
1da177e4 | 1137 | break; |
0af5853b | 1138 | case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: |
72dcc883 | 1139 | pnpacpi_encode_ext_irq(dev, resource, |
7e2cf31f | 1140 | pnp_get_resource(dev, IORESOURCE_IRQ, irq)); |
0af5853b LB |
1141 | irq++; |
1142 | break; | |
1143 | case ACPI_RESOURCE_TYPE_START_DEPENDENT: | |
1144 | case ACPI_RESOURCE_TYPE_END_DEPENDENT: | |
1145 | case ACPI_RESOURCE_TYPE_VENDOR: | |
1146 | case ACPI_RESOURCE_TYPE_END_TAG: | |
1147 | case ACPI_RESOURCE_TYPE_ADDRESS16: | |
1148 | case ACPI_RESOURCE_TYPE_ADDRESS32: | |
1149 | case ACPI_RESOURCE_TYPE_ADDRESS64: | |
1150 | case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64: | |
1151 | case ACPI_RESOURCE_TYPE_GENERIC_REGISTER: | |
9dd78466 | 1152 | default: /* other type */ |
af11cb2d BH |
1153 | dev_warn(&dev->dev, "can't encode unknown resource " |
1154 | "type %d\n", resource->type); | |
1da177e4 LT |
1155 | return -EINVAL; |
1156 | } | |
1c6e7d0a BH |
1157 | resource++; |
1158 | i++; | |
1da177e4 LT |
1159 | } |
1160 | return 0; | |
1161 | } |