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