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