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