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> |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 6 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2, or (at your option) any |
| 10 | * later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | */ |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/acpi.h> |
| 23 | #include <linux/pci.h> |
| 24 | #include "pnpacpi.h" |
| 25 | |
| 26 | #ifdef CONFIG_IA64 |
| 27 | #define valid_IRQ(i) (1) |
| 28 | #else |
| 29 | #define valid_IRQ(i) (((i) != 0) && ((i) != 2)) |
| 30 | #endif |
| 31 | |
| 32 | /* |
| 33 | * Allocated Resources |
| 34 | */ |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 35 | static int irq_flags(int triggering, int polarity) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | { |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 37 | if (triggering == ACPI_LEVEL_SENSITIVE) { |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 38 | if (polarity == ACPI_ACTIVE_LOW) |
Bjorn Helgaas | 4cec086 | 2007-08-15 10:32:09 -0600 | [diff] [blame] | 39 | return IORESOURCE_IRQ_LOWLEVEL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | else |
Bjorn Helgaas | 4cec086 | 2007-08-15 10:32:09 -0600 | [diff] [blame] | 41 | return IORESOURCE_IRQ_HIGHLEVEL; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 42 | } else { |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 43 | if (polarity == ACPI_ACTIVE_LOW) |
Bjorn Helgaas | 4cec086 | 2007-08-15 10:32:09 -0600 | [diff] [blame] | 44 | return IORESOURCE_IRQ_LOWEDGE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | else |
Bjorn Helgaas | 4cec086 | 2007-08-15 10:32:09 -0600 | [diff] [blame] | 46 | return IORESOURCE_IRQ_HIGHEDGE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 50 | static void decode_irq_flags(int flag, int *triggering, int *polarity) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | { |
| 52 | switch (flag) { |
| 53 | case IORESOURCE_IRQ_LOWLEVEL: |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 54 | *triggering = ACPI_LEVEL_SENSITIVE; |
| 55 | *polarity = ACPI_ACTIVE_LOW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | break; |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 57 | case IORESOURCE_IRQ_HIGHLEVEL: |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 58 | *triggering = ACPI_LEVEL_SENSITIVE; |
| 59 | *polarity = ACPI_ACTIVE_HIGH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | break; |
| 61 | case IORESOURCE_IRQ_LOWEDGE: |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 62 | *triggering = ACPI_EDGE_SENSITIVE; |
| 63 | *polarity = ACPI_ACTIVE_LOW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | break; |
| 65 | case IORESOURCE_IRQ_HIGHEDGE: |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 66 | *triggering = ACPI_EDGE_SENSITIVE; |
| 67 | *polarity = ACPI_ACTIVE_HIGH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | break; |
| 69 | } |
| 70 | } |
| 71 | |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 72 | static void pnpacpi_parse_allocated_irqresource(struct pnp_resource_table *res, |
| 73 | u32 gsi, int triggering, |
| 74 | int polarity, int shareable) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | { |
| 76 | int i = 0; |
Bjorn Helgaas | dbed12d | 2005-09-03 00:37:56 -0400 | [diff] [blame] | 77 | int irq; |
Shaohua Li | 61fd47e | 2007-11-17 01:05:28 -0500 | [diff] [blame] | 78 | int p, t; |
Bjorn Helgaas | dbed12d | 2005-09-03 00:37:56 -0400 | [diff] [blame] | 79 | |
| 80 | if (!valid_IRQ(gsi)) |
| 81 | return; |
| 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | while (!(res->irq_resource[i].flags & IORESOURCE_UNSET) && |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 84 | i < PNP_MAX_IRQ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | i++; |
Zhao Yakui | a7839e9 | 2007-11-28 16:21:21 -0800 | [diff] [blame] | 86 | if (i >= PNP_MAX_IRQ) { |
| 87 | printk(KERN_ERR "pnpacpi: exceeded the max number of IRQ " |
| 88 | "resources: %d \n", PNP_MAX_IRQ); |
Bjorn Helgaas | dbed12d | 2005-09-03 00:37:56 -0400 | [diff] [blame] | 89 | return; |
Zhao Yakui | a7839e9 | 2007-11-28 16:21:21 -0800 | [diff] [blame] | 90 | } |
Shaohua Li | 61fd47e | 2007-11-17 01:05:28 -0500 | [diff] [blame] | 91 | /* |
| 92 | * in IO-APIC mode, use overrided attribute. Two reasons: |
| 93 | * 1. BIOS bug in DSDT |
| 94 | * 2. BIOS uses IO-APIC mode Interrupt Source Override |
| 95 | */ |
| 96 | if (!acpi_get_override_irq(gsi, &t, &p)) { |
| 97 | t = t ? ACPI_LEVEL_SENSITIVE : ACPI_EDGE_SENSITIVE; |
| 98 | p = p ? ACPI_ACTIVE_LOW : ACPI_ACTIVE_HIGH; |
| 99 | |
| 100 | if (triggering != t || polarity != p) { |
| 101 | pnp_warn("IRQ %d override to %s, %s", |
| 102 | gsi, t ? "edge":"level", p ? "low":"high"); |
| 103 | triggering = t; |
| 104 | polarity = p; |
| 105 | } |
| 106 | } |
| 107 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 108 | res->irq_resource[i].flags = IORESOURCE_IRQ; // Also clears _UNSET flag |
Michael Karcher | 362ea08 | 2007-03-08 23:29:29 -0500 | [diff] [blame] | 109 | res->irq_resource[i].flags |= irq_flags(triggering, polarity); |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 110 | irq = acpi_register_gsi(gsi, triggering, polarity); |
Bjorn Helgaas | dbed12d | 2005-09-03 00:37:56 -0400 | [diff] [blame] | 111 | if (irq < 0) { |
| 112 | res->irq_resource[i].flags |= IORESOURCE_DISABLED; |
| 113 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
Bjorn Helgaas | dbed12d | 2005-09-03 00:37:56 -0400 | [diff] [blame] | 115 | |
Bjorn Helgaas | c32928c | 2006-07-03 00:24:10 -0700 | [diff] [blame] | 116 | if (shareable) |
| 117 | res->irq_resource[i].flags |= IORESOURCE_IRQ_SHAREABLE; |
| 118 | |
Bjorn Helgaas | dbed12d | 2005-09-03 00:37:56 -0400 | [diff] [blame] | 119 | res->irq_resource[i].start = irq; |
| 120 | res->irq_resource[i].end = irq; |
| 121 | pcibios_penalize_isa_irq(irq, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Michael Karcher | 362ea08 | 2007-03-08 23:29:29 -0500 | [diff] [blame] | 124 | static int dma_flags(int type, int bus_master, int transfer) |
| 125 | { |
| 126 | int flags = 0; |
| 127 | |
| 128 | if (bus_master) |
| 129 | flags |= IORESOURCE_DMA_MASTER; |
| 130 | switch (type) { |
| 131 | case ACPI_COMPATIBILITY: |
| 132 | flags |= IORESOURCE_DMA_COMPATIBLE; |
| 133 | break; |
| 134 | case ACPI_TYPE_A: |
| 135 | flags |= IORESOURCE_DMA_TYPEA; |
| 136 | break; |
| 137 | case ACPI_TYPE_B: |
| 138 | flags |= IORESOURCE_DMA_TYPEB; |
| 139 | break; |
| 140 | case ACPI_TYPE_F: |
| 141 | flags |= IORESOURCE_DMA_TYPEF; |
| 142 | break; |
| 143 | default: |
| 144 | /* Set a default value ? */ |
| 145 | flags |= IORESOURCE_DMA_COMPATIBLE; |
| 146 | pnp_err("Invalid DMA type"); |
| 147 | } |
| 148 | switch (transfer) { |
| 149 | case ACPI_TRANSFER_8: |
| 150 | flags |= IORESOURCE_DMA_8BIT; |
| 151 | break; |
| 152 | case ACPI_TRANSFER_8_16: |
| 153 | flags |= IORESOURCE_DMA_8AND16BIT; |
| 154 | break; |
| 155 | case ACPI_TRANSFER_16: |
| 156 | flags |= IORESOURCE_DMA_16BIT; |
| 157 | break; |
| 158 | default: |
| 159 | /* Set a default value ? */ |
| 160 | flags |= IORESOURCE_DMA_8AND16BIT; |
| 161 | pnp_err("Invalid DMA transfer type"); |
| 162 | } |
| 163 | |
| 164 | return flags; |
| 165 | } |
| 166 | |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 167 | static void pnpacpi_parse_allocated_dmaresource(struct pnp_resource_table *res, |
| 168 | u32 dma, int type, |
| 169 | int bus_master, int transfer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | { |
| 171 | int i = 0; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 172 | |
Adrian Bunk | 0dec63b | 2005-05-01 08:59:30 -0700 | [diff] [blame] | 173 | while (i < PNP_MAX_DMA && |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 174 | !(res->dma_resource[i].flags & IORESOURCE_UNSET)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | i++; |
| 176 | if (i < PNP_MAX_DMA) { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 177 | res->dma_resource[i].flags = IORESOURCE_DMA; // Also clears _UNSET flag |
| 178 | res->dma_resource[i].flags |= |
| 179 | dma_flags(type, bus_master, transfer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | if (dma == -1) { |
| 181 | res->dma_resource[i].flags |= IORESOURCE_DISABLED; |
| 182 | return; |
| 183 | } |
Bjorn Helgaas | dbed12d | 2005-09-03 00:37:56 -0400 | [diff] [blame] | 184 | res->dma_resource[i].start = dma; |
| 185 | res->dma_resource[i].end = dma; |
Zhao Yakui | a7839e9 | 2007-11-28 16:21:21 -0800 | [diff] [blame] | 186 | } else { |
| 187 | printk(KERN_ERR "pnpacpi: exceeded the max number of DMA " |
| 188 | "resources: %d \n", PNP_MAX_DMA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | } |
| 190 | } |
| 191 | |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 192 | static void pnpacpi_parse_allocated_ioresource(struct pnp_resource_table *res, |
| 193 | u64 io, u64 len, int io_decode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | { |
| 195 | int i = 0; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | while (!(res->port_resource[i].flags & IORESOURCE_UNSET) && |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 198 | i < PNP_MAX_PORT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | i++; |
| 200 | if (i < PNP_MAX_PORT) { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 201 | res->port_resource[i].flags = IORESOURCE_IO; // Also clears _UNSET flag |
Michael Karcher | 362ea08 | 2007-03-08 23:29:29 -0500 | [diff] [blame] | 202 | if (io_decode == ACPI_DECODE_16) |
| 203 | res->port_resource[i].flags |= PNP_PORT_FLAG_16BITADDR; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 204 | if (len <= 0 || (io + len - 1) >= 0x10003) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | res->port_resource[i].flags |= IORESOURCE_DISABLED; |
| 206 | return; |
| 207 | } |
Bjorn Helgaas | dbed12d | 2005-09-03 00:37:56 -0400 | [diff] [blame] | 208 | res->port_resource[i].start = io; |
| 209 | res->port_resource[i].end = io + len - 1; |
Zhao Yakui | a7839e9 | 2007-11-28 16:21:21 -0800 | [diff] [blame] | 210 | } else { |
| 211 | printk(KERN_ERR "pnpacpi: exceeded the max number of IO " |
| 212 | "resources: %d \n", PNP_MAX_PORT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | } |
| 214 | } |
| 215 | |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 216 | static void pnpacpi_parse_allocated_memresource(struct pnp_resource_table *res, |
| 217 | u64 mem, u64 len, |
| 218 | int write_protect) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | { |
| 220 | int i = 0; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 221 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | while (!(res->mem_resource[i].flags & IORESOURCE_UNSET) && |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 223 | (i < PNP_MAX_MEM)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | i++; |
| 225 | if (i < PNP_MAX_MEM) { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 226 | res->mem_resource[i].flags = IORESOURCE_MEM; // Also clears _UNSET flag |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | if (len <= 0) { |
| 228 | res->mem_resource[i].flags |= IORESOURCE_DISABLED; |
| 229 | return; |
| 230 | } |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 231 | if (write_protect == ACPI_READ_WRITE_MEMORY) |
Michael Karcher | 362ea08 | 2007-03-08 23:29:29 -0500 | [diff] [blame] | 232 | res->mem_resource[i].flags |= IORESOURCE_MEM_WRITEABLE; |
| 233 | |
Bjorn Helgaas | dbed12d | 2005-09-03 00:37:56 -0400 | [diff] [blame] | 234 | res->mem_resource[i].start = mem; |
| 235 | res->mem_resource[i].end = mem + len - 1; |
Zhao Yakui | a7839e9 | 2007-11-28 16:21:21 -0800 | [diff] [blame] | 236 | } else { |
| 237 | printk(KERN_ERR "pnpacpi: exceeded the max number of mem " |
| 238 | "resources: %d\n", PNP_MAX_MEM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 242 | static void pnpacpi_parse_allocated_address_space(struct pnp_resource_table *res_table, |
| 243 | struct acpi_resource *res) |
Bjorn Helgaas | 1acfb7f | 2006-03-28 17:03:00 -0500 | [diff] [blame] | 244 | { |
| 245 | struct acpi_resource_address64 addr, *p = &addr; |
| 246 | acpi_status status; |
| 247 | |
| 248 | status = acpi_resource_to_address64(res, p); |
| 249 | if (!ACPI_SUCCESS(status)) { |
| 250 | pnp_warn("PnPACPI: failed to convert resource type %d", |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 251 | res->type); |
Bjorn Helgaas | 1acfb7f | 2006-03-28 17:03:00 -0500 | [diff] [blame] | 252 | return; |
| 253 | } |
| 254 | |
matthieu castet | 2b8de5f | 2006-08-05 12:15:12 -0700 | [diff] [blame] | 255 | if (p->producer_consumer == ACPI_PRODUCER) |
| 256 | return; |
| 257 | |
Bjorn Helgaas | 1acfb7f | 2006-03-28 17:03:00 -0500 | [diff] [blame] | 258 | if (p->resource_type == ACPI_MEMORY_RANGE) |
| 259 | pnpacpi_parse_allocated_memresource(res_table, |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 260 | p->minimum, p->address_length, |
| 261 | p->info.mem.write_protect); |
Bjorn Helgaas | 1acfb7f | 2006-03-28 17:03:00 -0500 | [diff] [blame] | 262 | else if (p->resource_type == ACPI_IO_RANGE) |
| 263 | pnpacpi_parse_allocated_ioresource(res_table, |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 264 | p->minimum, p->address_length, |
| 265 | p->granularity == 0xfff ? ACPI_DECODE_10 : |
| 266 | ACPI_DECODE_16); |
Bjorn Helgaas | 1acfb7f | 2006-03-28 17:03:00 -0500 | [diff] [blame] | 267 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
| 269 | static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 270 | void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | { |
Bjorn Helgaas | 4721a4cc | 2007-08-15 10:32:10 -0600 | [diff] [blame] | 272 | struct pnp_resource_table *res_table = data; |
Bjorn Helgaas | dbed12d | 2005-09-03 00:37:56 -0400 | [diff] [blame] | 273 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
Len Brown | eca008c | 2005-09-22 00:25:18 -0400 | [diff] [blame] | 275 | switch (res->type) { |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 276 | case ACPI_RESOURCE_TYPE_IRQ: |
Bjorn Helgaas | dbed12d | 2005-09-03 00:37:56 -0400 | [diff] [blame] | 277 | /* |
| 278 | * Per spec, only one interrupt per descriptor is allowed in |
| 279 | * _CRS, but some firmware violates this, so parse them all. |
| 280 | */ |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 281 | for (i = 0; i < res->data.irq.interrupt_count; i++) { |
Bjorn Helgaas | dbed12d | 2005-09-03 00:37:56 -0400 | [diff] [blame] | 282 | pnpacpi_parse_allocated_irqresource(res_table, |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 283 | res->data.irq.interrupts[i], |
| 284 | res->data.irq.triggering, |
| 285 | res->data.irq.polarity, |
| 286 | res->data.irq.sharable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | } |
| 288 | break; |
| 289 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 290 | case ACPI_RESOURCE_TYPE_DMA: |
| 291 | if (res->data.dma.channel_count > 0) |
| 292 | pnpacpi_parse_allocated_dmaresource(res_table, |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 293 | res->data.dma.channels[0], |
| 294 | res->data.dma.type, |
| 295 | res->data.dma.bus_master, |
| 296 | res->data.dma.transfer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | break; |
Len Brown | 0af5853 | 2006-01-20 01:11:37 -0500 | [diff] [blame] | 298 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 299 | case ACPI_RESOURCE_TYPE_IO: |
| 300 | pnpacpi_parse_allocated_ioresource(res_table, |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 301 | res->data.io.minimum, |
| 302 | res->data.io.address_length, |
| 303 | res->data.io.io_decode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | break; |
Len Brown | 0af5853 | 2006-01-20 01:11:37 -0500 | [diff] [blame] | 305 | |
| 306 | case ACPI_RESOURCE_TYPE_START_DEPENDENT: |
| 307 | case ACPI_RESOURCE_TYPE_END_DEPENDENT: |
| 308 | break; |
| 309 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 310 | case ACPI_RESOURCE_TYPE_FIXED_IO: |
| 311 | pnpacpi_parse_allocated_ioresource(res_table, |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 312 | res->data.fixed_io.address, |
| 313 | res->data.fixed_io.address_length, |
| 314 | ACPI_DECODE_10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | break; |
Len Brown | 0af5853 | 2006-01-20 01:11:37 -0500 | [diff] [blame] | 316 | |
| 317 | case ACPI_RESOURCE_TYPE_VENDOR: |
| 318 | break; |
| 319 | |
| 320 | case ACPI_RESOURCE_TYPE_END_TAG: |
| 321 | break; |
| 322 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 323 | case ACPI_RESOURCE_TYPE_MEMORY24: |
| 324 | pnpacpi_parse_allocated_memresource(res_table, |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 325 | res->data.memory24.minimum, |
| 326 | res->data.memory24.address_length, |
| 327 | res->data.memory24.write_protect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | break; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 329 | case ACPI_RESOURCE_TYPE_MEMORY32: |
| 330 | pnpacpi_parse_allocated_memresource(res_table, |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 331 | res->data.memory32.minimum, |
| 332 | res->data.memory32.address_length, |
| 333 | res->data.memory32.write_protect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | break; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 335 | case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: |
| 336 | pnpacpi_parse_allocated_memresource(res_table, |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 337 | res->data.fixed_memory32.address, |
| 338 | res->data.fixed_memory32.address_length, |
| 339 | res->data.fixed_memory32.write_protect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | break; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 341 | case ACPI_RESOURCE_TYPE_ADDRESS16: |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 342 | case ACPI_RESOURCE_TYPE_ADDRESS32: |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 343 | case ACPI_RESOURCE_TYPE_ADDRESS64: |
Bjorn Helgaas | 1acfb7f | 2006-03-28 17:03:00 -0500 | [diff] [blame] | 344 | pnpacpi_parse_allocated_address_space(res_table, res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | break; |
Len Brown | 0af5853 | 2006-01-20 01:11:37 -0500 | [diff] [blame] | 346 | |
| 347 | case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64: |
matthieu castet | 2b8de5f | 2006-08-05 12:15:12 -0700 | [diff] [blame] | 348 | if (res->data.ext_address64.producer_consumer == ACPI_PRODUCER) |
| 349 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | break; |
Len Brown | 0af5853 | 2006-01-20 01:11:37 -0500 | [diff] [blame] | 351 | |
| 352 | case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: |
matthieu castet | 2b8de5f | 2006-08-05 12:15:12 -0700 | [diff] [blame] | 353 | if (res->data.extended_irq.producer_consumer == ACPI_PRODUCER) |
| 354 | return AE_OK; |
| 355 | |
Len Brown | 0af5853 | 2006-01-20 01:11:37 -0500 | [diff] [blame] | 356 | for (i = 0; i < res->data.extended_irq.interrupt_count; i++) { |
| 357 | pnpacpi_parse_allocated_irqresource(res_table, |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 358 | res->data.extended_irq.interrupts[i], |
| 359 | res->data.extended_irq.triggering, |
| 360 | res->data.extended_irq.polarity, |
| 361 | res->data.extended_irq.sharable); |
Len Brown | 0af5853 | 2006-01-20 01:11:37 -0500 | [diff] [blame] | 362 | } |
| 363 | break; |
| 364 | |
| 365 | case ACPI_RESOURCE_TYPE_GENERIC_REGISTER: |
| 366 | break; |
| 367 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | default: |
Len Brown | eca008c | 2005-09-22 00:25:18 -0400 | [diff] [blame] | 369 | pnp_warn("PnPACPI: unknown resource type %d", res->type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | return AE_ERROR; |
| 371 | } |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | return AE_OK; |
| 374 | } |
| 375 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 376 | acpi_status pnpacpi_parse_allocated_resource(acpi_handle handle, |
| 377 | struct pnp_resource_table * res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | { |
| 379 | /* Blank the resource table values */ |
| 380 | pnp_init_resource_table(res); |
| 381 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 382 | return acpi_walk_resources(handle, METHOD_NAME__CRS, |
| 383 | pnpacpi_allocated_resource, res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | } |
| 385 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 386 | static void pnpacpi_parse_dma_option(struct pnp_option *option, |
| 387 | struct acpi_resource_dma *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | { |
| 389 | int i; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 390 | struct pnp_dma *dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 392 | if (p->channel_count == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | return; |
Robert P. J. Day | cd86128 | 2006-12-13 00:34:52 -0800 | [diff] [blame] | 394 | dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | if (!dma) |
| 396 | return; |
| 397 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 398 | for (i = 0; i < p->channel_count; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | dma->map |= 1 << p->channels[i]; |
Michael Karcher | 362ea08 | 2007-03-08 23:29:29 -0500 | [diff] [blame] | 400 | |
| 401 | dma->flags = dma_flags(p->type, p->bus_master, p->transfer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 403 | pnp_register_dma_resource(option, dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | static void pnpacpi_parse_irq_option(struct pnp_option *option, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 407 | struct acpi_resource_irq *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | { |
| 409 | int i; |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 410 | struct pnp_irq *irq; |
| 411 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 412 | if (p->interrupt_count == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | return; |
Robert P. J. Day | cd86128 | 2006-12-13 00:34:52 -0800 | [diff] [blame] | 414 | irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | if (!irq) |
| 416 | return; |
| 417 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 418 | for (i = 0; i < p->interrupt_count; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | if (p->interrupts[i]) |
| 420 | __set_bit(p->interrupts[i], irq->map); |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 421 | irq->flags = irq_flags(p->triggering, p->polarity); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
| 423 | pnp_register_irq_resource(option, irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | static void pnpacpi_parse_ext_irq_option(struct pnp_option *option, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 427 | struct acpi_resource_extended_irq *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | { |
| 429 | int i; |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 430 | struct pnp_irq *irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 432 | if (p->interrupt_count == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | return; |
Robert P. J. Day | cd86128 | 2006-12-13 00:34:52 -0800 | [diff] [blame] | 434 | irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | if (!irq) |
| 436 | return; |
| 437 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 438 | for (i = 0; i < p->interrupt_count; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | if (p->interrupts[i]) |
| 440 | __set_bit(p->interrupts[i], irq->map); |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 441 | irq->flags = irq_flags(p->triggering, p->polarity); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
| 443 | pnp_register_irq_resource(option, irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | } |
| 445 | |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 446 | static void pnpacpi_parse_port_option(struct pnp_option *option, |
| 447 | struct acpi_resource_io *io) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | { |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 449 | struct pnp_port *port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 451 | if (io->address_length == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | return; |
Robert P. J. Day | cd86128 | 2006-12-13 00:34:52 -0800 | [diff] [blame] | 453 | port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | if (!port) |
| 455 | return; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 456 | port->min = io->minimum; |
| 457 | port->max = io->maximum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | port->align = io->alignment; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 459 | port->size = io->address_length; |
| 460 | port->flags = ACPI_DECODE_16 == io->io_decode ? |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 461 | PNP_PORT_FLAG_16BITADDR : 0; |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 462 | pnp_register_port_resource(option, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | } |
| 464 | |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 465 | static void pnpacpi_parse_fixed_port_option(struct pnp_option *option, |
| 466 | struct acpi_resource_fixed_io *io) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | { |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 468 | struct pnp_port *port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 470 | if (io->address_length == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | return; |
Robert P. J. Day | cd86128 | 2006-12-13 00:34:52 -0800 | [diff] [blame] | 472 | port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | if (!port) |
| 474 | return; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 475 | port->min = port->max = io->address; |
| 476 | port->size = io->address_length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | port->align = 0; |
| 478 | port->flags = PNP_PORT_FLAG_FIXED; |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 479 | pnp_register_port_resource(option, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | } |
| 481 | |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 482 | static void pnpacpi_parse_mem24_option(struct pnp_option *option, |
| 483 | struct acpi_resource_memory24 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | { |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 485 | struct pnp_mem *mem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 487 | if (p->address_length == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | return; |
Robert P. J. Day | cd86128 | 2006-12-13 00:34:52 -0800 | [diff] [blame] | 489 | mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | if (!mem) |
| 491 | return; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 492 | mem->min = p->minimum; |
| 493 | mem->max = p->maximum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | mem->align = p->alignment; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 495 | mem->size = p->address_length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 497 | mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ? |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 498 | IORESOURCE_MEM_WRITEABLE : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 500 | pnp_register_mem_resource(option, mem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | } |
| 502 | |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 503 | static void pnpacpi_parse_mem32_option(struct pnp_option *option, |
| 504 | struct acpi_resource_memory32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | { |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 506 | struct pnp_mem *mem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 508 | if (p->address_length == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | return; |
Robert P. J. Day | cd86128 | 2006-12-13 00:34:52 -0800 | [diff] [blame] | 510 | mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | if (!mem) |
| 512 | return; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 513 | mem->min = p->minimum; |
| 514 | mem->max = p->maximum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | mem->align = p->alignment; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 516 | mem->size = p->address_length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 518 | mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ? |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 519 | IORESOURCE_MEM_WRITEABLE : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 521 | pnp_register_mem_resource(option, mem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | } |
| 523 | |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 524 | static void pnpacpi_parse_fixed_mem32_option(struct pnp_option *option, |
| 525 | struct acpi_resource_fixed_memory32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | { |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 527 | struct pnp_mem *mem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 529 | if (p->address_length == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | return; |
Robert P. J. Day | cd86128 | 2006-12-13 00:34:52 -0800 | [diff] [blame] | 531 | mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | if (!mem) |
| 533 | return; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 534 | mem->min = mem->max = p->address; |
| 535 | mem->size = p->address_length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | mem->align = 0; |
| 537 | |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 538 | mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ? |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 539 | IORESOURCE_MEM_WRITEABLE : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 541 | pnp_register_mem_resource(option, mem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 544 | static void pnpacpi_parse_address_option(struct pnp_option *option, |
| 545 | struct acpi_resource *r) |
Bjorn Helgaas | 6f957ea | 2005-09-20 15:26:00 -0400 | [diff] [blame] | 546 | { |
| 547 | struct acpi_resource_address64 addr, *p = &addr; |
| 548 | acpi_status status; |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 549 | struct pnp_mem *mem; |
| 550 | struct pnp_port *port; |
Bjorn Helgaas | 6f957ea | 2005-09-20 15:26:00 -0400 | [diff] [blame] | 551 | |
| 552 | status = acpi_resource_to_address64(r, p); |
| 553 | if (!ACPI_SUCCESS(status)) { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 554 | pnp_warn("PnPACPI: failed to convert resource type %d", |
| 555 | r->type); |
Bjorn Helgaas | 6f957ea | 2005-09-20 15:26:00 -0400 | [diff] [blame] | 556 | return; |
| 557 | } |
| 558 | |
| 559 | if (p->address_length == 0) |
| 560 | return; |
| 561 | |
| 562 | if (p->resource_type == ACPI_MEMORY_RANGE) { |
Robert P. J. Day | cd86128 | 2006-12-13 00:34:52 -0800 | [diff] [blame] | 563 | mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL); |
Bjorn Helgaas | 6f957ea | 2005-09-20 15:26:00 -0400 | [diff] [blame] | 564 | if (!mem) |
| 565 | return; |
Len Brown | ed03f43 | 2006-01-07 03:50:18 -0500 | [diff] [blame] | 566 | mem->min = mem->max = p->minimum; |
Bjorn Helgaas | 6f957ea | 2005-09-20 15:26:00 -0400 | [diff] [blame] | 567 | mem->size = p->address_length; |
| 568 | mem->align = 0; |
Len Brown | ed03f43 | 2006-01-07 03:50:18 -0500 | [diff] [blame] | 569 | mem->flags = (p->info.mem.write_protect == |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 570 | ACPI_READ_WRITE_MEMORY) ? IORESOURCE_MEM_WRITEABLE |
| 571 | : 0; |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 572 | pnp_register_mem_resource(option, mem); |
Bjorn Helgaas | 6f957ea | 2005-09-20 15:26:00 -0400 | [diff] [blame] | 573 | } else if (p->resource_type == ACPI_IO_RANGE) { |
Robert P. J. Day | cd86128 | 2006-12-13 00:34:52 -0800 | [diff] [blame] | 574 | port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL); |
Bjorn Helgaas | 6f957ea | 2005-09-20 15:26:00 -0400 | [diff] [blame] | 575 | if (!port) |
| 576 | return; |
Len Brown | ed03f43 | 2006-01-07 03:50:18 -0500 | [diff] [blame] | 577 | port->min = port->max = p->minimum; |
Bjorn Helgaas | 6f957ea | 2005-09-20 15:26:00 -0400 | [diff] [blame] | 578 | port->size = p->address_length; |
| 579 | port->align = 0; |
| 580 | port->flags = PNP_PORT_FLAG_FIXED; |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 581 | pnp_register_port_resource(option, port); |
Bjorn Helgaas | 6f957ea | 2005-09-20 15:26:00 -0400 | [diff] [blame] | 582 | } |
| 583 | } |
| 584 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | struct acpipnp_parse_option_s { |
| 586 | struct pnp_option *option; |
Matthieu Castet | b008b8d | 2005-03-25 12:03:15 -0500 | [diff] [blame] | 587 | struct pnp_option *option_independent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | struct pnp_dev *dev; |
| 589 | }; |
| 590 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 591 | static acpi_status pnpacpi_option_resource(struct acpi_resource *res, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 592 | void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | { |
| 594 | int priority = 0; |
Bjorn Helgaas | 4721a4cc | 2007-08-15 10:32:10 -0600 | [diff] [blame] | 595 | struct acpipnp_parse_option_s *parse_data = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | struct pnp_dev *dev = parse_data->dev; |
| 597 | struct pnp_option *option = parse_data->option; |
| 598 | |
Len Brown | eca008c | 2005-09-22 00:25:18 -0400 | [diff] [blame] | 599 | switch (res->type) { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 600 | case ACPI_RESOURCE_TYPE_IRQ: |
| 601 | pnpacpi_parse_irq_option(option, &res->data.irq); |
| 602 | break; |
| 603 | |
| 604 | case ACPI_RESOURCE_TYPE_DMA: |
| 605 | pnpacpi_parse_dma_option(option, &res->data.dma); |
| 606 | break; |
| 607 | |
| 608 | case ACPI_RESOURCE_TYPE_START_DEPENDENT: |
| 609 | switch (res->data.start_dpf.compatibility_priority) { |
| 610 | case ACPI_GOOD_CONFIGURATION: |
| 611 | priority = PNP_RES_PRIORITY_PREFERRED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | break; |
Len Brown | 0af5853 | 2006-01-20 01:11:37 -0500 | [diff] [blame] | 613 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 614 | case ACPI_ACCEPTABLE_CONFIGURATION: |
| 615 | priority = PNP_RES_PRIORITY_ACCEPTABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | break; |
Len Brown | 0af5853 | 2006-01-20 01:11:37 -0500 | [diff] [blame] | 617 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 618 | case ACPI_SUB_OPTIMAL_CONFIGURATION: |
| 619 | priority = PNP_RES_PRIORITY_FUNCTIONAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | default: |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 622 | priority = PNP_RES_PRIORITY_INVALID; |
| 623 | break; |
| 624 | } |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 625 | /* TBD: Consider performance/robustness bits */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 626 | option = pnp_register_dependent_option(dev, priority); |
| 627 | if (!option) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | return AE_ERROR; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 629 | parse_data->option = option; |
| 630 | break; |
| 631 | |
| 632 | case ACPI_RESOURCE_TYPE_END_DEPENDENT: |
| 633 | /*only one EndDependentFn is allowed */ |
| 634 | if (!parse_data->option_independent) { |
| 635 | pnp_warn("PnPACPI: more than one EndDependentFn"); |
| 636 | return AE_ERROR; |
| 637 | } |
| 638 | parse_data->option = parse_data->option_independent; |
| 639 | parse_data->option_independent = NULL; |
| 640 | break; |
| 641 | |
| 642 | case ACPI_RESOURCE_TYPE_IO: |
| 643 | pnpacpi_parse_port_option(option, &res->data.io); |
| 644 | break; |
| 645 | |
| 646 | case ACPI_RESOURCE_TYPE_FIXED_IO: |
| 647 | pnpacpi_parse_fixed_port_option(option, &res->data.fixed_io); |
| 648 | break; |
| 649 | |
| 650 | case ACPI_RESOURCE_TYPE_VENDOR: |
| 651 | case ACPI_RESOURCE_TYPE_END_TAG: |
| 652 | break; |
| 653 | |
| 654 | case ACPI_RESOURCE_TYPE_MEMORY24: |
| 655 | pnpacpi_parse_mem24_option(option, &res->data.memory24); |
| 656 | break; |
| 657 | |
| 658 | case ACPI_RESOURCE_TYPE_MEMORY32: |
| 659 | pnpacpi_parse_mem32_option(option, &res->data.memory32); |
| 660 | break; |
| 661 | |
| 662 | case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: |
| 663 | pnpacpi_parse_fixed_mem32_option(option, |
| 664 | &res->data.fixed_memory32); |
| 665 | break; |
| 666 | |
| 667 | case ACPI_RESOURCE_TYPE_ADDRESS16: |
| 668 | case ACPI_RESOURCE_TYPE_ADDRESS32: |
| 669 | case ACPI_RESOURCE_TYPE_ADDRESS64: |
| 670 | pnpacpi_parse_address_option(option, res); |
| 671 | break; |
| 672 | |
| 673 | case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64: |
| 674 | break; |
| 675 | |
| 676 | case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: |
| 677 | pnpacpi_parse_ext_irq_option(option, &res->data.extended_irq); |
| 678 | break; |
| 679 | |
| 680 | case ACPI_RESOURCE_TYPE_GENERIC_REGISTER: |
| 681 | break; |
| 682 | |
| 683 | default: |
| 684 | pnp_warn("PnPACPI: unknown resource type %d", res->type); |
| 685 | return AE_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | } |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 687 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | return AE_OK; |
| 689 | } |
| 690 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 691 | acpi_status pnpacpi_parse_resource_option_data(acpi_handle handle, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 692 | struct pnp_dev * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | { |
| 694 | acpi_status status; |
| 695 | struct acpipnp_parse_option_s parse_data; |
| 696 | |
| 697 | parse_data.option = pnp_register_independent_option(dev); |
| 698 | if (!parse_data.option) |
| 699 | return AE_ERROR; |
Matthieu Castet | b008b8d | 2005-03-25 12:03:15 -0500 | [diff] [blame] | 700 | parse_data.option_independent = parse_data.option; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | parse_data.dev = dev; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 702 | status = acpi_walk_resources(handle, METHOD_NAME__PRS, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 703 | pnpacpi_option_resource, &parse_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | |
| 705 | return status; |
| 706 | } |
| 707 | |
Bjorn Helgaas | b5f2490b | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 708 | static int pnpacpi_supported_resource(struct acpi_resource *res) |
| 709 | { |
| 710 | switch (res->type) { |
| 711 | case ACPI_RESOURCE_TYPE_IRQ: |
| 712 | case ACPI_RESOURCE_TYPE_DMA: |
| 713 | case ACPI_RESOURCE_TYPE_IO: |
| 714 | case ACPI_RESOURCE_TYPE_FIXED_IO: |
| 715 | case ACPI_RESOURCE_TYPE_MEMORY24: |
| 716 | case ACPI_RESOURCE_TYPE_MEMORY32: |
| 717 | case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: |
| 718 | case ACPI_RESOURCE_TYPE_ADDRESS16: |
| 719 | case ACPI_RESOURCE_TYPE_ADDRESS32: |
| 720 | case ACPI_RESOURCE_TYPE_ADDRESS64: |
| 721 | case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: |
| 722 | return 1; |
| 723 | } |
| 724 | return 0; |
| 725 | } |
| 726 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | /* |
| 728 | * Set resource |
| 729 | */ |
| 730 | static acpi_status pnpacpi_count_resources(struct acpi_resource *res, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 731 | void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | { |
Bjorn Helgaas | 4721a4cc | 2007-08-15 10:32:10 -0600 | [diff] [blame] | 733 | int *res_cnt = data; |
Bjorn Helgaas | b5f2490b | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 734 | |
| 735 | if (pnpacpi_supported_resource(res)) |
| 736 | (*res_cnt)++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | return AE_OK; |
| 738 | } |
| 739 | |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 740 | static acpi_status pnpacpi_type_resources(struct acpi_resource *res, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | { |
Bjorn Helgaas | 4721a4cc | 2007-08-15 10:32:10 -0600 | [diff] [blame] | 742 | struct acpi_resource **resource = data; |
Bjorn Helgaas | b5f2490b | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 743 | |
| 744 | if (pnpacpi_supported_resource(res)) { |
Len Brown | eca008c | 2005-09-22 00:25:18 -0400 | [diff] [blame] | 745 | (*resource)->type = res->type; |
Bjorn Helgaas | b5f2490b | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 746 | (*resource)->length = sizeof(struct acpi_resource); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | (*resource)++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | return AE_OK; |
| 751 | } |
| 752 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 753 | int pnpacpi_build_resource_template(acpi_handle handle, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 754 | struct acpi_buffer *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | { |
| 756 | struct acpi_resource *resource; |
| 757 | int res_cnt = 0; |
| 758 | acpi_status status; |
| 759 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 760 | status = acpi_walk_resources(handle, METHOD_NAME__CRS, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 761 | pnpacpi_count_resources, &res_cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | if (ACPI_FAILURE(status)) { |
| 763 | pnp_err("Evaluate _CRS failed"); |
| 764 | return -EINVAL; |
| 765 | } |
| 766 | if (!res_cnt) |
| 767 | return -EINVAL; |
| 768 | buffer->length = sizeof(struct acpi_resource) * (res_cnt + 1) + 1; |
Robert P. J. Day | cd86128 | 2006-12-13 00:34:52 -0800 | [diff] [blame] | 769 | buffer->pointer = kzalloc(buffer->length - 1, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | if (!buffer->pointer) |
| 771 | return -ENOMEM; |
| 772 | pnp_dbg("Res cnt %d", res_cnt); |
| 773 | resource = (struct acpi_resource *)buffer->pointer; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 774 | status = acpi_walk_resources(handle, METHOD_NAME__CRS, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 775 | pnpacpi_type_resources, &resource); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | if (ACPI_FAILURE(status)) { |
| 777 | kfree(buffer->pointer); |
| 778 | pnp_err("Evaluate _CRS failed"); |
| 779 | return -EINVAL; |
| 780 | } |
| 781 | /* resource will pointer the end resource now */ |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 782 | resource->type = ACPI_RESOURCE_TYPE_END_TAG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | |
| 784 | return 0; |
| 785 | } |
| 786 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 787 | static void pnpacpi_encode_irq(struct acpi_resource *resource, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 788 | struct resource *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | { |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 790 | int triggering, polarity; |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 791 | |
| 792 | decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity); |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 793 | resource->data.irq.triggering = triggering; |
| 794 | resource->data.irq.polarity = polarity; |
| 795 | if (triggering == ACPI_EDGE_SENSITIVE) |
| 796 | resource->data.irq.sharable = ACPI_EXCLUSIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | else |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 798 | resource->data.irq.sharable = ACPI_SHARED; |
| 799 | resource->data.irq.interrupt_count = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | resource->data.irq.interrupts[0] = p->start; |
| 801 | } |
| 802 | |
| 803 | static void pnpacpi_encode_ext_irq(struct acpi_resource *resource, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 804 | struct resource *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | { |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 806 | int triggering, polarity; |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 807 | |
| 808 | decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | resource->data.extended_irq.producer_consumer = ACPI_CONSUMER; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 810 | resource->data.extended_irq.triggering = triggering; |
| 811 | resource->data.extended_irq.polarity = polarity; |
| 812 | if (triggering == ACPI_EDGE_SENSITIVE) |
| 813 | resource->data.irq.sharable = ACPI_EXCLUSIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | else |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 815 | resource->data.irq.sharable = ACPI_SHARED; |
| 816 | resource->data.extended_irq.interrupt_count = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | resource->data.extended_irq.interrupts[0] = p->start; |
| 818 | } |
| 819 | |
| 820 | static void pnpacpi_encode_dma(struct acpi_resource *resource, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 821 | struct resource *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */ |
Vojtech Pavlik | ccc4c7b | 2006-04-07 20:00:27 +0200 | [diff] [blame] | 824 | switch (p->flags & IORESOURCE_DMA_SPEED_MASK) { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 825 | case IORESOURCE_DMA_TYPEA: |
| 826 | resource->data.dma.type = ACPI_TYPE_A; |
| 827 | break; |
| 828 | case IORESOURCE_DMA_TYPEB: |
| 829 | resource->data.dma.type = ACPI_TYPE_B; |
| 830 | break; |
| 831 | case IORESOURCE_DMA_TYPEF: |
| 832 | resource->data.dma.type = ACPI_TYPE_F; |
| 833 | break; |
| 834 | default: |
| 835 | resource->data.dma.type = ACPI_COMPATIBILITY; |
Vojtech Pavlik | ccc4c7b | 2006-04-07 20:00:27 +0200 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | switch (p->flags & IORESOURCE_DMA_TYPE_MASK) { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 839 | case IORESOURCE_DMA_8BIT: |
| 840 | resource->data.dma.transfer = ACPI_TRANSFER_8; |
| 841 | break; |
| 842 | case IORESOURCE_DMA_8AND16BIT: |
| 843 | resource->data.dma.transfer = ACPI_TRANSFER_8_16; |
| 844 | break; |
| 845 | default: |
| 846 | resource->data.dma.transfer = ACPI_TRANSFER_16; |
Vojtech Pavlik | ccc4c7b | 2006-04-07 20:00:27 +0200 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | resource->data.dma.bus_master = !!(p->flags & IORESOURCE_DMA_MASTER); |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 850 | resource->data.dma.channel_count = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | resource->data.dma.channels[0] = p->start; |
| 852 | } |
| 853 | |
| 854 | static void pnpacpi_encode_io(struct acpi_resource *resource, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 855 | struct resource *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 858 | resource->data.io.io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR) ? |
| 859 | ACPI_DECODE_16 : ACPI_DECODE_10; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 860 | resource->data.io.minimum = p->start; |
| 861 | resource->data.io.maximum = p->end; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 862 | resource->data.io.alignment = 0; /* Correct? */ |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 863 | resource->data.io.address_length = p->end - p->start + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | static void pnpacpi_encode_fixed_io(struct acpi_resource *resource, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 867 | struct resource *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | { |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 869 | resource->data.fixed_io.address = p->start; |
| 870 | resource->data.fixed_io.address_length = p->end - p->start + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | static void pnpacpi_encode_mem24(struct acpi_resource *resource, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 874 | struct resource *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */ |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 877 | resource->data.memory24.write_protect = |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 878 | (p->flags & IORESOURCE_MEM_WRITEABLE) ? |
| 879 | ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 880 | resource->data.memory24.minimum = p->start; |
| 881 | resource->data.memory24.maximum = p->end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | resource->data.memory24.alignment = 0; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 883 | resource->data.memory24.address_length = p->end - p->start + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | static void pnpacpi_encode_mem32(struct acpi_resource *resource, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 887 | struct resource *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | { |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 889 | resource->data.memory32.write_protect = |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 890 | (p->flags & IORESOURCE_MEM_WRITEABLE) ? |
| 891 | ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 892 | resource->data.memory32.minimum = p->start; |
| 893 | resource->data.memory32.maximum = p->end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | resource->data.memory32.alignment = 0; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 895 | resource->data.memory32.address_length = p->end - p->start + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | static void pnpacpi_encode_fixed_mem32(struct acpi_resource *resource, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 899 | struct resource *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | { |
Bob Moore | 0897831 | 2005-10-21 00:00:00 -0400 | [diff] [blame] | 901 | resource->data.fixed_memory32.write_protect = |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 902 | (p->flags & IORESOURCE_MEM_WRITEABLE) ? |
| 903 | ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 904 | resource->data.fixed_memory32.address = p->start; |
| 905 | resource->data.fixed_memory32.address_length = p->end - p->start + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | } |
| 907 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 908 | int pnpacpi_encode_resources(struct pnp_resource_table *res_table, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 909 | struct acpi_buffer *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | { |
| 911 | int i = 0; |
| 912 | /* pnpacpi_build_resource_template allocates extra mem */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 913 | int res_cnt = (buffer->length - 1) / sizeof(struct acpi_resource) - 1; |
Bjorn Helgaas | 4721a4cc | 2007-08-15 10:32:10 -0600 | [diff] [blame] | 914 | struct acpi_resource *resource = buffer->pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | int port = 0, irq = 0, dma = 0, mem = 0; |
| 916 | |
| 917 | pnp_dbg("res cnt %d", res_cnt); |
| 918 | while (i < res_cnt) { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 919 | switch (resource->type) { |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 920 | case ACPI_RESOURCE_TYPE_IRQ: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | pnp_dbg("Encode irq"); |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 922 | pnpacpi_encode_irq(resource, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 923 | &res_table->irq_resource[irq]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | irq++; |
| 925 | break; |
| 926 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 927 | case ACPI_RESOURCE_TYPE_DMA: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | pnp_dbg("Encode dma"); |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 929 | pnpacpi_encode_dma(resource, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 930 | &res_table->dma_resource[dma]); |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 931 | dma++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | break; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 933 | case ACPI_RESOURCE_TYPE_IO: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | pnp_dbg("Encode io"); |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 935 | pnpacpi_encode_io(resource, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 936 | &res_table->port_resource[port]); |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 937 | port++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | break; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 939 | case ACPI_RESOURCE_TYPE_FIXED_IO: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | pnp_dbg("Encode fixed io"); |
| 941 | pnpacpi_encode_fixed_io(resource, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 942 | &res_table-> |
| 943 | port_resource[port]); |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 944 | port++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | break; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 946 | case ACPI_RESOURCE_TYPE_MEMORY24: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | pnp_dbg("Encode mem24"); |
| 948 | pnpacpi_encode_mem24(resource, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 949 | &res_table->mem_resource[mem]); |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 950 | mem++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | break; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 952 | case ACPI_RESOURCE_TYPE_MEMORY32: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | pnp_dbg("Encode mem32"); |
| 954 | pnpacpi_encode_mem32(resource, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 955 | &res_table->mem_resource[mem]); |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 956 | mem++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | break; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 958 | case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | pnp_dbg("Encode fixed mem32"); |
| 960 | pnpacpi_encode_fixed_mem32(resource, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 961 | &res_table-> |
| 962 | mem_resource[mem]); |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 963 | mem++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | break; |
Len Brown | 0af5853 | 2006-01-20 01:11:37 -0500 | [diff] [blame] | 965 | case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: |
| 966 | pnp_dbg("Encode ext irq"); |
| 967 | pnpacpi_encode_ext_irq(resource, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 968 | &res_table->irq_resource[irq]); |
Len Brown | 0af5853 | 2006-01-20 01:11:37 -0500 | [diff] [blame] | 969 | irq++; |
| 970 | break; |
| 971 | case ACPI_RESOURCE_TYPE_START_DEPENDENT: |
| 972 | case ACPI_RESOURCE_TYPE_END_DEPENDENT: |
| 973 | case ACPI_RESOURCE_TYPE_VENDOR: |
| 974 | case ACPI_RESOURCE_TYPE_END_TAG: |
| 975 | case ACPI_RESOURCE_TYPE_ADDRESS16: |
| 976 | case ACPI_RESOURCE_TYPE_ADDRESS32: |
| 977 | case ACPI_RESOURCE_TYPE_ADDRESS64: |
| 978 | case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64: |
| 979 | case ACPI_RESOURCE_TYPE_GENERIC_REGISTER: |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 980 | default: /* other type */ |
Len Brown | eca008c | 2005-09-22 00:25:18 -0400 | [diff] [blame] | 981 | pnp_warn("unknown resource type %d", resource->type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | return -EINVAL; |
| 983 | } |
Bjorn Helgaas | 1c6e7d0 | 2006-03-28 17:04:00 -0500 | [diff] [blame] | 984 | resource++; |
| 985 | i++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | } |
| 987 | return 0; |
| 988 | } |