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