Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[safe/jmp/linux-2.6] / drivers / pnp / pnpacpi / rsparser.c
index 46069e6..100e4d9 100644 (file)
@@ -3,6 +3,8 @@
  *
  * Copyright (c) 2004 Matthieu Castet <castet.matthieu@free.fr>
  * Copyright (c) 2004 Li Shaohua <shaohua.li@intel.com>
+ * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
+ *     Bjorn Helgaas <bjorn.helgaas@hp.com>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
@@ -22,6 +24,7 @@
 #include <linux/acpi.h>
 #include <linux/pci.h>
 #include <linux/pnp.h>
+#include <linux/slab.h>
 #include "../base.h"
 #include "pnpacpi.h"
 
@@ -121,7 +124,7 @@ static void pnpacpi_parse_allocated_irqresource(struct pnp_dev *dev,
        }
 
        flags = irq_flags(triggering, polarity, shareable);
-       irq = acpi_register_gsi(gsi, triggering, polarity);
+       irq = acpi_register_gsi(&dev->dev, gsi, triggering, polarity);
        if (irq >= 0)
                pcibios_penalize_isa_irq(irq, 1);
        else
@@ -130,7 +133,8 @@ static void pnpacpi_parse_allocated_irqresource(struct pnp_dev *dev,
        pnp_add_irq_resource(dev, irq, flags);
 }
 
-static int dma_flags(int type, int bus_master, int transfer)
+static int dma_flags(struct pnp_dev *dev, int type, int bus_master,
+                    int transfer)
 {
        int flags = 0;
 
@@ -152,7 +156,7 @@ static int dma_flags(int type, int bus_master, int transfer)
        default:
                /* Set a default value ? */
                flags |= IORESOURCE_DMA_COMPATIBLE;
-               pnp_err("Invalid DMA type");
+               dev_err(&dev->dev, "invalid DMA type %d\n", type);
        }
        switch (transfer) {
        case ACPI_TRANSFER_8:
@@ -167,14 +171,15 @@ static int dma_flags(int type, int bus_master, int transfer)
        default:
                /* Set a default value ? */
                flags |= IORESOURCE_DMA_8AND16BIT;
-               pnp_err("Invalid DMA transfer type");
+               dev_err(&dev->dev, "invalid DMA transfer type %d\n", transfer);
        }
 
        return flags;
 }
 
 static void pnpacpi_parse_allocated_ioresource(struct pnp_dev *dev, u64 start,
-                                              u64 len, int io_decode)
+                                              u64 len, int io_decode,
+                                              int window)
 {
        int flags = 0;
        u64 end = start + len - 1;
@@ -183,13 +188,70 @@ static void pnpacpi_parse_allocated_ioresource(struct pnp_dev *dev, u64 start,
                flags |= IORESOURCE_IO_16BIT_ADDR;
        if (len == 0 || end >= 0x10003)
                flags |= IORESOURCE_DISABLED;
+       if (window)
+               flags |= IORESOURCE_WINDOW;
 
        pnp_add_io_resource(dev, start, end, flags);
 }
 
+/*
+ * Device CSRs that do not appear in PCI config space should be described
+ * via ACPI.  This would normally be done with Address Space Descriptors
+ * marked as "consumer-only," but old versions of Windows and Linux ignore
+ * the producer/consumer flag, so HP invented a vendor-defined resource to
+ * describe the location and size of CSR space.
+ */
+static struct acpi_vendor_uuid hp_ccsr_uuid = {
+       .subtype = 2,
+       .data = { 0xf9, 0xad, 0xe9, 0x69, 0x4f, 0x92, 0x5f, 0xab, 0xf6, 0x4a,
+           0x24, 0xd2, 0x01, 0x37, 0x0e, 0xad },
+};
+
+static int vendor_resource_matches(struct pnp_dev *dev,
+                                  struct acpi_resource_vendor_typed *vendor,
+                                  struct acpi_vendor_uuid *match,
+                                  int expected_len)
+{
+       int uuid_len = sizeof(vendor->uuid);
+       u8 uuid_subtype = vendor->uuid_subtype;
+       u8 *uuid = vendor->uuid;
+       int actual_len;
+
+       /* byte_length includes uuid_subtype and uuid */
+       actual_len = vendor->byte_length - uuid_len - 1;
+
+       if (uuid_subtype == match->subtype &&
+           uuid_len == sizeof(match->data) &&
+           memcmp(uuid, match->data, uuid_len) == 0) {
+               if (expected_len && expected_len != actual_len) {
+                       dev_err(&dev->dev, "wrong vendor descriptor size; "
+                               "expected %d, found %d bytes\n",
+                               expected_len, actual_len);
+                       return 0;
+               }
+
+               return 1;
+       }
+
+       return 0;
+}
+
+static void pnpacpi_parse_allocated_vendor(struct pnp_dev *dev,
+                                   struct acpi_resource_vendor_typed *vendor)
+{
+       if (vendor_resource_matches(dev, vendor, &hp_ccsr_uuid, 16)) {
+               u64 start, length;
+
+               memcpy(&start, vendor->byte_data, sizeof(start));
+               memcpy(&length, vendor->byte_data + 8, sizeof(length));
+
+               pnp_add_mem_resource(dev, start, start + length - 1, 0);
+       }
+}
+
 static void pnpacpi_parse_allocated_memresource(struct pnp_dev *dev,
                                                u64 start, u64 len,
-                                               int write_protect)
+                                               int write_protect, int window)
 {
        int flags = 0;
        u64 end = start + len - 1;
@@ -198,15 +260,27 @@ static void pnpacpi_parse_allocated_memresource(struct pnp_dev *dev,
                flags |= IORESOURCE_DISABLED;
        if (write_protect == ACPI_READ_WRITE_MEMORY)
                flags |= IORESOURCE_MEM_WRITEABLE;
+       if (window)
+               flags |= IORESOURCE_WINDOW;
 
        pnp_add_mem_resource(dev, start, end, flags);
 }
 
+static void pnpacpi_parse_allocated_busresource(struct pnp_dev *dev,
+                                               u64 start, u64 len)
+{
+       u64 end = start + len - 1;
+
+       pnp_add_bus_resource(dev, start, end);
+}
+
 static void pnpacpi_parse_allocated_address_space(struct pnp_dev *dev,
                                                  struct acpi_resource *res)
 {
        struct acpi_resource_address64 addr, *p = &addr;
        acpi_status status;
+       int window;
+       u64 len;
 
        status = acpi_resource_to_address64(res, p);
        if (!ACPI_SUCCESS(status)) {
@@ -215,18 +289,41 @@ static void pnpacpi_parse_allocated_address_space(struct pnp_dev *dev,
                return;
        }
 
-       if (p->producer_consumer == ACPI_PRODUCER)
-               return;
+       /* Windows apparently computes length rather than using _LEN */
+       len = p->maximum - p->minimum + 1;
+       window = (p->producer_consumer == ACPI_PRODUCER) ? 1 : 0;
 
        if (p->resource_type == ACPI_MEMORY_RANGE)
-               pnpacpi_parse_allocated_memresource(dev,
-                       p->minimum, p->address_length,
-                       p->info.mem.write_protect);
+               pnpacpi_parse_allocated_memresource(dev, p->minimum, len,
+                       p->info.mem.write_protect, window);
        else if (p->resource_type == ACPI_IO_RANGE)
-               pnpacpi_parse_allocated_ioresource(dev,
-                       p->minimum, p->address_length,
+               pnpacpi_parse_allocated_ioresource(dev, p->minimum, len,
+                       p->granularity == 0xfff ? ACPI_DECODE_10 :
+                               ACPI_DECODE_16, window);
+       else if (p->resource_type == ACPI_BUS_NUMBER_RANGE)
+               pnpacpi_parse_allocated_busresource(dev, p->minimum, len);
+}
+
+static void pnpacpi_parse_allocated_ext_address_space(struct pnp_dev *dev,
+                                                     struct acpi_resource *res)
+{
+       struct acpi_resource_extended_address64 *p = &res->data.ext_address64;
+       int window;
+       u64 len;
+
+       /* Windows apparently computes length rather than using _LEN */
+       len = p->maximum - p->minimum + 1;
+       window = (p->producer_consumer == ACPI_PRODUCER) ? 1 : 0;
+
+       if (p->resource_type == ACPI_MEMORY_RANGE)
+               pnpacpi_parse_allocated_memresource(dev, p->minimum, len,
+                       p->info.mem.write_protect, window);
+       else if (p->resource_type == ACPI_IO_RANGE)
+               pnpacpi_parse_allocated_ioresource(dev, p->minimum, len,
                        p->granularity == 0xfff ? ACPI_DECODE_10 :
-                               ACPI_DECODE_16);
+                               ACPI_DECODE_16, window);
+       else if (p->resource_type == ACPI_BUS_NUMBER_RANGE)
+               pnpacpi_parse_allocated_busresource(dev, p->minimum, len);
 }
 
 static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
@@ -237,6 +334,7 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
        struct acpi_resource_dma *dma;
        struct acpi_resource_io *io;
        struct acpi_resource_fixed_io *fixed_io;
+       struct acpi_resource_vendor_typed *vendor_typed;
        struct acpi_resource_memory24 *memory24;
        struct acpi_resource_memory32 *memory32;
        struct acpi_resource_fixed_memory32 *fixed_memory32;
@@ -278,7 +376,7 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
        case ACPI_RESOURCE_TYPE_DMA:
                dma = &res->data.dma;
                if (dma->channel_count > 0 && dma->channels[0] != (u8) -1)
-                       flags = dma_flags(dma->type, dma->bus_master,
+                       flags = dma_flags(dev, dma->type, dma->bus_master,
                                          dma->transfer);
                else
                        flags = IORESOURCE_DISABLED;
@@ -290,7 +388,7 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
                pnpacpi_parse_allocated_ioresource(dev,
                        io->minimum,
                        io->address_length,
-                       io->io_decode);
+                       io->io_decode, 0);
                break;
 
        case ACPI_RESOURCE_TYPE_START_DEPENDENT:
@@ -302,10 +400,12 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
                pnpacpi_parse_allocated_ioresource(dev,
                        fixed_io->address,
                        fixed_io->address_length,
-                       ACPI_DECODE_10);
+                       ACPI_DECODE_10, 0);
                break;
 
        case ACPI_RESOURCE_TYPE_VENDOR:
+               vendor_typed = &res->data.vendor_typed;
+               pnpacpi_parse_allocated_vendor(dev, vendor_typed);
                break;
 
        case ACPI_RESOURCE_TYPE_END_TAG:
@@ -316,21 +416,21 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
                pnpacpi_parse_allocated_memresource(dev,
                        memory24->minimum,
                        memory24->address_length,
-                       memory24->write_protect);
+                       memory24->write_protect, 0);
                break;
        case ACPI_RESOURCE_TYPE_MEMORY32:
                memory32 = &res->data.memory32;
                pnpacpi_parse_allocated_memresource(dev,
                        memory32->minimum,
                        memory32->address_length,
-                       memory32->write_protect);
+                       memory32->write_protect, 0);
                break;
        case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
                fixed_memory32 = &res->data.fixed_memory32;
                pnpacpi_parse_allocated_memresource(dev,
                        fixed_memory32->address,
                        fixed_memory32->address_length,
-                       fixed_memory32->write_protect);
+                       fixed_memory32->write_protect, 0);
                break;
        case ACPI_RESOURCE_TYPE_ADDRESS16:
        case ACPI_RESOURCE_TYPE_ADDRESS32:
@@ -339,14 +439,11 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
                break;
 
        case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
-               if (res->data.ext_address64.producer_consumer == ACPI_PRODUCER)
-                       return AE_OK;
+               pnpacpi_parse_allocated_ext_address_space(dev, res);
                break;
 
        case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
                extended_irq = &res->data.extended_irq;
-               if (extended_irq->producer_consumer == ACPI_PRODUCER)
-                       return AE_OK;
 
                if (extended_irq->interrupt_count == 0)
                        pnp_add_irq_resource(dev, 0, IORESOURCE_DISABLED);
@@ -388,10 +485,11 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
 
 int pnpacpi_parse_allocated_resource(struct pnp_dev *dev)
 {
-       acpi_handle handle = dev->data;
+       struct acpi_device *acpi_dev = dev->data;
+       acpi_handle handle = acpi_dev->handle;
        acpi_status status;
 
-       dev_dbg(&dev->dev, "parse allocated resources\n");
+       pnp_dbg(&dev->dev, "parse allocated resources\n");
 
        pnp_init_resources(dev);
 
@@ -407,183 +505,151 @@ int pnpacpi_parse_allocated_resource(struct pnp_dev *dev)
 }
 
 static __init void pnpacpi_parse_dma_option(struct pnp_dev *dev,
-                                           struct pnp_option *option,
+                                           unsigned int option_flags,
                                            struct acpi_resource_dma *p)
 {
        int i;
-       struct pnp_dma *dma;
+       unsigned char map = 0, flags;
 
        if (p->channel_count == 0)
                return;
-       dma = kzalloc(sizeof(struct pnp_dma), GFP_KERNEL);
-       if (!dma)
-               return;
 
        for (i = 0; i < p->channel_count; i++)
-               dma->map |= 1 << p->channels[i];
-
-       dma->flags = dma_flags(p->type, p->bus_master, p->transfer);
+               map |= 1 << p->channels[i];
 
-       pnp_register_dma_resource(dev, option, dma);
+       flags = dma_flags(dev, p->type, p->bus_master, p->transfer);
+       pnp_register_dma_resource(dev, option_flags, map, flags);
 }
 
 static __init void pnpacpi_parse_irq_option(struct pnp_dev *dev,
-                                           struct pnp_option *option,
+                                           unsigned int option_flags,
                                            struct acpi_resource_irq *p)
 {
        int i;
-       struct pnp_irq *irq;
+       pnp_irq_mask_t map;
+       unsigned char flags;
 
        if (p->interrupt_count == 0)
                return;
-       irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
-       if (!irq)
-               return;
 
+       bitmap_zero(map.bits, PNP_IRQ_NR);
        for (i = 0; i < p->interrupt_count; i++)
                if (p->interrupts[i])
-                       __set_bit(p->interrupts[i], irq->map);
-       irq->flags = irq_flags(p->triggering, p->polarity, p->sharable);
+                       __set_bit(p->interrupts[i], map.bits);
 
-       pnp_register_irq_resource(dev, option, irq);
+       flags = irq_flags(p->triggering, p->polarity, p->sharable);
+       pnp_register_irq_resource(dev, option_flags, &map, flags);
 }
 
 static __init void pnpacpi_parse_ext_irq_option(struct pnp_dev *dev,
-                                               struct pnp_option *option,
+                                       unsigned int option_flags,
                                        struct acpi_resource_extended_irq *p)
 {
        int i;
-       struct pnp_irq *irq;
+       pnp_irq_mask_t map;
+       unsigned char flags;
 
        if (p->interrupt_count == 0)
                return;
-       irq = kzalloc(sizeof(struct pnp_irq), GFP_KERNEL);
-       if (!irq)
-               return;
 
-       for (i = 0; i < p->interrupt_count; i++)
-               if (p->interrupts[i])
-                       __set_bit(p->interrupts[i], irq->map);
-       irq->flags = irq_flags(p->triggering, p->polarity, p->sharable);
+       bitmap_zero(map.bits, PNP_IRQ_NR);
+       for (i = 0; i < p->interrupt_count; i++) {
+               if (p->interrupts[i]) {
+                       if (p->interrupts[i] < PNP_IRQ_NR)
+                               __set_bit(p->interrupts[i], map.bits);
+                       else
+                               dev_err(&dev->dev, "ignoring IRQ %d option "
+                                       "(too large for %d entry bitmap)\n",
+                                       p->interrupts[i], PNP_IRQ_NR);
+               }
+       }
 
-       pnp_register_irq_resource(dev, option, irq);
+       flags = irq_flags(p->triggering, p->polarity, p->sharable);
+       pnp_register_irq_resource(dev, option_flags, &map, flags);
 }
 
 static __init void pnpacpi_parse_port_option(struct pnp_dev *dev,
-                                            struct pnp_option *option,
+                                            unsigned int option_flags,
                                             struct acpi_resource_io *io)
 {
-       struct pnp_port *port;
+       unsigned char flags = 0;
 
        if (io->address_length == 0)
                return;
-       port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
-       if (!port)
-               return;
-       port->min = io->minimum;
-       port->max = io->maximum;
-       port->align = io->alignment;
-       port->size = io->address_length;
-       port->flags = ACPI_DECODE_16 == io->io_decode ?
-           IORESOURCE_IO_16BIT_ADDR : 0;
-       pnp_register_port_resource(dev, option, port);
+
+       if (io->io_decode == ACPI_DECODE_16)
+               flags = IORESOURCE_IO_16BIT_ADDR;
+       pnp_register_port_resource(dev, option_flags, io->minimum, io->maximum,
+                                  io->alignment, io->address_length, flags);
 }
 
 static __init void pnpacpi_parse_fixed_port_option(struct pnp_dev *dev,
-                                                  struct pnp_option *option,
+                                       unsigned int option_flags,
                                        struct acpi_resource_fixed_io *io)
 {
-       struct pnp_port *port;
-
        if (io->address_length == 0)
                return;
-       port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
-       if (!port)
-               return;
-       port->min = port->max = io->address;
-       port->size = io->address_length;
-       port->align = 0;
-       port->flags = IORESOURCE_IO_FIXED;
-       pnp_register_port_resource(dev, option, port);
+
+       pnp_register_port_resource(dev, option_flags, io->address, io->address,
+                                  0, io->address_length, IORESOURCE_IO_FIXED);
 }
 
 static __init void pnpacpi_parse_mem24_option(struct pnp_dev *dev,
-                                             struct pnp_option *option,
+                                             unsigned int option_flags,
                                              struct acpi_resource_memory24 *p)
 {
-       struct pnp_mem *mem;
+       unsigned char flags = 0;
 
        if (p->address_length == 0)
                return;
-       mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
-       if (!mem)
-               return;
-       mem->min = p->minimum;
-       mem->max = p->maximum;
-       mem->align = p->alignment;
-       mem->size = p->address_length;
 
-       mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
-           IORESOURCE_MEM_WRITEABLE : 0;
-
-       pnp_register_mem_resource(dev, option, mem);
+       if (p->write_protect == ACPI_READ_WRITE_MEMORY)
+               flags = IORESOURCE_MEM_WRITEABLE;
+       pnp_register_mem_resource(dev, option_flags, p->minimum, p->maximum,
+                                 p->alignment, p->address_length, flags);
 }
 
 static __init void pnpacpi_parse_mem32_option(struct pnp_dev *dev,
-                                             struct pnp_option *option,
+                                             unsigned int option_flags,
                                              struct acpi_resource_memory32 *p)
 {
-       struct pnp_mem *mem;
+       unsigned char flags = 0;
 
        if (p->address_length == 0)
                return;
-       mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
-       if (!mem)
-               return;
-       mem->min = p->minimum;
-       mem->max = p->maximum;
-       mem->align = p->alignment;
-       mem->size = p->address_length;
 
-       mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
-           IORESOURCE_MEM_WRITEABLE : 0;
-
-       pnp_register_mem_resource(dev, option, mem);
+       if (p->write_protect == ACPI_READ_WRITE_MEMORY)
+               flags = IORESOURCE_MEM_WRITEABLE;
+       pnp_register_mem_resource(dev, option_flags, p->minimum, p->maximum,
+                                 p->alignment, p->address_length, flags);
 }
 
 static __init void pnpacpi_parse_fixed_mem32_option(struct pnp_dev *dev,
-                                                   struct pnp_option *option,
+                                       unsigned int option_flags,
                                        struct acpi_resource_fixed_memory32 *p)
 {
-       struct pnp_mem *mem;
+       unsigned char flags = 0;
 
        if (p->address_length == 0)
                return;
-       mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
-       if (!mem)
-               return;
-       mem->min = mem->max = p->address;
-       mem->size = p->address_length;
-       mem->align = 0;
 
-       mem->flags = (ACPI_READ_WRITE_MEMORY == p->write_protect) ?
-           IORESOURCE_MEM_WRITEABLE : 0;
-
-       pnp_register_mem_resource(dev, option, mem);
+       if (p->write_protect == ACPI_READ_WRITE_MEMORY)
+               flags = IORESOURCE_MEM_WRITEABLE;
+       pnp_register_mem_resource(dev, option_flags, p->address, p->address,
+                                 0, p->address_length, flags);
 }
 
 static __init void pnpacpi_parse_address_option(struct pnp_dev *dev,
-                                               struct pnp_option *option,
+                                               unsigned int option_flags,
                                                struct acpi_resource *r)
 {
        struct acpi_resource_address64 addr, *p = &addr;
        acpi_status status;
-       struct pnp_mem *mem;
-       struct pnp_port *port;
+       unsigned char flags = 0;
 
        status = acpi_resource_to_address64(r, p);
-       if (!ACPI_SUCCESS(status)) {
-               pnp_warn("PnPACPI: failed to convert resource type %d",
+       if (ACPI_FAILURE(status)) {
+               dev_warn(&dev->dev, "can't convert resource type %d\n",
                         r->type);
                return;
        }
@@ -592,49 +658,59 @@ static __init void pnpacpi_parse_address_option(struct pnp_dev *dev,
                return;
 
        if (p->resource_type == ACPI_MEMORY_RANGE) {
-               mem = kzalloc(sizeof(struct pnp_mem), GFP_KERNEL);
-               if (!mem)
-                       return;
-               mem->min = mem->max = p->minimum;
-               mem->size = p->address_length;
-               mem->align = 0;
-               mem->flags = (p->info.mem.write_protect ==
-                             ACPI_READ_WRITE_MEMORY) ? IORESOURCE_MEM_WRITEABLE
-                   : 0;
-               pnp_register_mem_resource(dev, option, mem);
-       } else if (p->resource_type == ACPI_IO_RANGE) {
-               port = kzalloc(sizeof(struct pnp_port), GFP_KERNEL);
-               if (!port)
-                       return;
-               port->min = port->max = p->minimum;
-               port->size = p->address_length;
-               port->align = 0;
-               port->flags = IORESOURCE_IO_FIXED;
-               pnp_register_port_resource(dev, option, port);
-       }
+               if (p->info.mem.write_protect == ACPI_READ_WRITE_MEMORY)
+                       flags = IORESOURCE_MEM_WRITEABLE;
+               pnp_register_mem_resource(dev, option_flags, p->minimum,
+                                         p->minimum, 0, p->address_length,
+                                         flags);
+       } else if (p->resource_type == ACPI_IO_RANGE)
+               pnp_register_port_resource(dev, option_flags, p->minimum,
+                                          p->minimum, 0, p->address_length,
+                                          IORESOURCE_IO_FIXED);
+}
+
+static __init void pnpacpi_parse_ext_address_option(struct pnp_dev *dev,
+                                                   unsigned int option_flags,
+                                                   struct acpi_resource *r)
+{
+       struct acpi_resource_extended_address64 *p = &r->data.ext_address64;
+       unsigned char flags = 0;
+
+       if (p->address_length == 0)
+               return;
+
+       if (p->resource_type == ACPI_MEMORY_RANGE) {
+               if (p->info.mem.write_protect == ACPI_READ_WRITE_MEMORY)
+                       flags = IORESOURCE_MEM_WRITEABLE;
+               pnp_register_mem_resource(dev, option_flags, p->minimum,
+                                         p->minimum, 0, p->address_length,
+                                         flags);
+       } else if (p->resource_type == ACPI_IO_RANGE)
+               pnp_register_port_resource(dev, option_flags, p->minimum,
+                                          p->minimum, 0, p->address_length,
+                                          IORESOURCE_IO_FIXED);
 }
 
 struct acpipnp_parse_option_s {
-       struct pnp_option *option;
-       struct pnp_option *option_independent;
        struct pnp_dev *dev;
+       unsigned int option_flags;
 };
 
 static __init acpi_status pnpacpi_option_resource(struct acpi_resource *res,
                                                  void *data)
 {
-       int priority = 0;
+       int priority;
        struct acpipnp_parse_option_s *parse_data = data;
        struct pnp_dev *dev = parse_data->dev;
-       struct pnp_option *option = parse_data->option;
+       unsigned int option_flags = parse_data->option_flags;
 
        switch (res->type) {
        case ACPI_RESOURCE_TYPE_IRQ:
-               pnpacpi_parse_irq_option(dev, option, &res->data.irq);
+               pnpacpi_parse_irq_option(dev, option_flags, &res->data.irq);
                break;
 
        case ACPI_RESOURCE_TYPE_DMA:
-               pnpacpi_parse_dma_option(dev, option, &res->data.dma);
+               pnpacpi_parse_dma_option(dev, option_flags, &res->data.dma);
                break;
 
        case ACPI_RESOURCE_TYPE_START_DEPENDENT:
@@ -654,31 +730,19 @@ static __init acpi_status pnpacpi_option_resource(struct acpi_resource *res,
                        priority = PNP_RES_PRIORITY_INVALID;
                        break;
                }
-               /* TBD: Consider performance/robustness bits */
-               option = pnp_register_dependent_option(dev, priority);
-               if (!option)
-                       return AE_ERROR;
-               parse_data->option = option;
+               parse_data->option_flags = pnp_new_dependent_set(dev, priority);
                break;
 
        case ACPI_RESOURCE_TYPE_END_DEPENDENT:
-               /*only one EndDependentFn is allowed */
-               if (!parse_data->option_independent) {
-                       dev_warn(&dev->dev, "more than one EndDependentFn "
-                                "in _PRS\n");
-                       return AE_ERROR;
-               }
-               parse_data->option = parse_data->option_independent;
-               parse_data->option_independent = NULL;
-               dev_dbg(&dev->dev, "end dependent options\n");
+               parse_data->option_flags = 0;
                break;
 
        case ACPI_RESOURCE_TYPE_IO:
-               pnpacpi_parse_port_option(dev, option, &res->data.io);
+               pnpacpi_parse_port_option(dev, option_flags, &res->data.io);
                break;
 
        case ACPI_RESOURCE_TYPE_FIXED_IO:
-               pnpacpi_parse_fixed_port_option(dev, option,
+               pnpacpi_parse_fixed_port_option(dev, option_flags,
                                                &res->data.fixed_io);
                break;
 
@@ -687,29 +751,32 @@ static __init acpi_status pnpacpi_option_resource(struct acpi_resource *res,
                break;
 
        case ACPI_RESOURCE_TYPE_MEMORY24:
-               pnpacpi_parse_mem24_option(dev, option, &res->data.memory24);
+               pnpacpi_parse_mem24_option(dev, option_flags,
+                                          &res->data.memory24);
                break;
 
        case ACPI_RESOURCE_TYPE_MEMORY32:
-               pnpacpi_parse_mem32_option(dev, option, &res->data.memory32);
+               pnpacpi_parse_mem32_option(dev, option_flags,
+                                          &res->data.memory32);
                break;
 
        case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
-               pnpacpi_parse_fixed_mem32_option(dev, option,
+               pnpacpi_parse_fixed_mem32_option(dev, option_flags,
                                                 &res->data.fixed_memory32);
                break;
 
        case ACPI_RESOURCE_TYPE_ADDRESS16:
        case ACPI_RESOURCE_TYPE_ADDRESS32:
        case ACPI_RESOURCE_TYPE_ADDRESS64:
-               pnpacpi_parse_address_option(dev, option, res);
+               pnpacpi_parse_address_option(dev, option_flags, res);
                break;
 
        case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
+               pnpacpi_parse_ext_address_option(dev, option_flags, res);
                break;
 
        case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
-               pnpacpi_parse_ext_irq_option(dev, option,
+               pnpacpi_parse_ext_irq_option(dev, option_flags,
                                             &res->data.extended_irq);
                break;
 
@@ -727,18 +794,16 @@ static __init acpi_status pnpacpi_option_resource(struct acpi_resource *res,
 
 int __init pnpacpi_parse_resource_option_data(struct pnp_dev *dev)
 {
-       acpi_handle handle = dev->data;
+       struct acpi_device *acpi_dev = dev->data;
+       acpi_handle handle = acpi_dev->handle;
        acpi_status status;
        struct acpipnp_parse_option_s parse_data;
 
-       dev_dbg(&dev->dev, "parse resource options\n");
+       pnp_dbg(&dev->dev, "parse resource options\n");
 
-       parse_data.option = pnp_register_independent_option(dev);
-       if (!parse_data.option)
-               return -ENOMEM;
-
-       parse_data.option_independent = parse_data.option;
        parse_data.dev = dev;
+       parse_data.option_flags = 0;
+
        status = acpi_walk_resources(handle, METHOD_NAME__PRS,
                                     pnpacpi_option_resource, &parse_data);
 
@@ -763,6 +828,7 @@ static int pnpacpi_supported_resource(struct acpi_resource *res)
        case ACPI_RESOURCE_TYPE_ADDRESS16:
        case ACPI_RESOURCE_TYPE_ADDRESS32:
        case ACPI_RESOURCE_TYPE_ADDRESS64:
+       case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
        case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
                return 1;
        }
@@ -801,7 +867,8 @@ static acpi_status pnpacpi_type_resources(struct acpi_resource *res, void *data)
 int pnpacpi_build_resource_template(struct pnp_dev *dev,
                                    struct acpi_buffer *buffer)
 {
-       acpi_handle handle = dev->data;
+       struct acpi_device *acpi_dev = dev->data;
+       acpi_handle handle = acpi_dev->handle;
        struct acpi_resource *resource;
        int res_cnt = 0;
        acpi_status status;
@@ -842,7 +909,7 @@ static void pnpacpi_encode_irq(struct pnp_dev *dev,
 
        if (!pnp_resource_enabled(p)) {
                irq->interrupt_count = 0;
-               dev_dbg(&dev->dev, "  encode irq (%s)\n",
+               pnp_dbg(&dev->dev, "  encode irq (%s)\n",
                        p ? "disabled" : "missing");
                return;
        }
@@ -854,7 +921,7 @@ static void pnpacpi_encode_irq(struct pnp_dev *dev,
        irq->interrupt_count = 1;
        irq->interrupts[0] = p->start;
 
-       dev_dbg(&dev->dev, "  encode irq %d %s %s %s (%d-byte descriptor)\n",
+       pnp_dbg(&dev->dev, "  encode irq %d %s %s %s (%d-byte descriptor)\n",
                (int) p->start,
                triggering == ACPI_LEVEL_SENSITIVE ? "level" : "edge",
                polarity == ACPI_ACTIVE_LOW ? "low" : "high",
@@ -871,7 +938,7 @@ static void pnpacpi_encode_ext_irq(struct pnp_dev *dev,
 
        if (!pnp_resource_enabled(p)) {
                extended_irq->interrupt_count = 0;
-               dev_dbg(&dev->dev, "  encode extended irq (%s)\n",
+               pnp_dbg(&dev->dev, "  encode extended irq (%s)\n",
                        p ? "disabled" : "missing");
                return;
        }
@@ -884,7 +951,7 @@ static void pnpacpi_encode_ext_irq(struct pnp_dev *dev,
        extended_irq->interrupt_count = 1;
        extended_irq->interrupts[0] = p->start;
 
-       dev_dbg(&dev->dev, "  encode irq %d %s %s %s\n", (int) p->start,
+       pnp_dbg(&dev->dev, "  encode irq %d %s %s %s\n", (int) p->start,
                triggering == ACPI_LEVEL_SENSITIVE ? "level" : "edge",
                polarity == ACPI_ACTIVE_LOW ? "low" : "high",
                extended_irq->sharable == ACPI_SHARED ? "shared" : "exclusive");
@@ -898,7 +965,7 @@ static void pnpacpi_encode_dma(struct pnp_dev *dev,
 
        if (!pnp_resource_enabled(p)) {
                dma->channel_count = 0;
-               dev_dbg(&dev->dev, "  encode dma (%s)\n",
+               pnp_dbg(&dev->dev, "  encode dma (%s)\n",
                        p ? "disabled" : "missing");
                return;
        }
@@ -933,7 +1000,7 @@ static void pnpacpi_encode_dma(struct pnp_dev *dev,
        dma->channel_count = 1;
        dma->channels[0] = p->start;
 
-       dev_dbg(&dev->dev, "  encode dma %d "
+       pnp_dbg(&dev->dev, "  encode dma %d "
                "type %#x transfer %#x master %d\n",
                (int) p->start, dma->type, dma->transfer, dma->bus_master);
 }
@@ -957,7 +1024,7 @@ static void pnpacpi_encode_io(struct pnp_dev *dev,
                io->address_length = 0;
        }
 
-       dev_dbg(&dev->dev, "  encode io %#x-%#x decode %#x\n", io->minimum,
+       pnp_dbg(&dev->dev, "  encode io %#x-%#x decode %#x\n", io->minimum,
                io->minimum + io->address_length - 1, io->io_decode);
 }
 
@@ -975,7 +1042,7 @@ static void pnpacpi_encode_fixed_io(struct pnp_dev *dev,
                fixed_io->address_length = 0;
        }
 
-       dev_dbg(&dev->dev, "  encode fixed_io %#x-%#x\n", fixed_io->address,
+       pnp_dbg(&dev->dev, "  encode fixed_io %#x-%#x\n", fixed_io->address,
                fixed_io->address + fixed_io->address_length - 1);
 }
 
@@ -998,7 +1065,7 @@ static void pnpacpi_encode_mem24(struct pnp_dev *dev,
                memory24->address_length = 0;
        }
 
-       dev_dbg(&dev->dev, "  encode mem24 %#x-%#x write_protect %#x\n",
+       pnp_dbg(&dev->dev, "  encode mem24 %#x-%#x write_protect %#x\n",
                memory24->minimum,
                memory24->minimum + memory24->address_length - 1,
                memory24->write_protect);
@@ -1022,7 +1089,7 @@ static void pnpacpi_encode_mem32(struct pnp_dev *dev,
                memory32->alignment = 0;
        }
 
-       dev_dbg(&dev->dev, "  encode mem32 %#x-%#x write_protect %#x\n",
+       pnp_dbg(&dev->dev, "  encode mem32 %#x-%#x write_protect %#x\n",
                memory32->minimum,
                memory32->minimum + memory32->address_length - 1,
                memory32->write_protect);
@@ -1045,7 +1112,7 @@ static void pnpacpi_encode_fixed_mem32(struct pnp_dev *dev,
                fixed_memory32->address_length = 0;
        }
 
-       dev_dbg(&dev->dev, "  encode fixed_mem32 %#x-%#x write_protect %#x\n",
+       pnp_dbg(&dev->dev, "  encode fixed_mem32 %#x-%#x write_protect %#x\n",
                fixed_memory32->address,
                fixed_memory32->address + fixed_memory32->address_length - 1,
                fixed_memory32->write_protect);
@@ -1059,7 +1126,7 @@ int pnpacpi_encode_resources(struct pnp_dev *dev, struct acpi_buffer *buffer)
        struct acpi_resource *resource = buffer->pointer;
        int port = 0, irq = 0, dma = 0, mem = 0;
 
-       dev_dbg(&dev->dev, "encode %d resources\n", res_cnt);
+       pnp_dbg(&dev->dev, "encode %d resources\n", res_cnt);
        while (i < res_cnt) {
                switch (resource->type) {
                case ACPI_RESOURCE_TYPE_IRQ: