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