Merge branch 'x86-platform-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
authorLinus Torvalds <torvalds@linux-foundation.org>
Fri, 20 May 2011 01:08:06 +0000 (18:08 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 20 May 2011 01:08:06 +0000 (18:08 -0700)
* 'x86-platform-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip:
  x86: Introduce pci_map_biosrom()
  x86, olpc: Use device tree for platform identification

12 files changed:
arch/x86/Kconfig
arch/x86/include/asm/olpc_ofw.h
arch/x86/include/asm/probe_roms.h [new file with mode: 0644]
arch/x86/include/asm/setup.h
arch/x86/kernel/Makefile
arch/x86/kernel/head32.c
arch/x86/kernel/probe_roms.c [new file with mode: 0644]
arch/x86/kernel/probe_roms_32.c [deleted file]
arch/x86/kernel/x86_init.c
arch/x86/platform/olpc/Makefile
arch/x86/platform/olpc/olpc.c
arch/x86/platform/olpc/olpc_dt.c

index 0a1fe60037f29cf875accd73fba7ee1015ea5c87..4168e5d8632af2f162504ea1b80fbf11c94b5264 100644 (file)
@@ -2069,7 +2069,7 @@ config OLPC
        depends on !X86_PAE
        select GPIOLIB
        select OF
-       select OF_PROMTREE if PROC_DEVICETREE
+       select OF_PROMTREE
        ---help---
          Add support for detecting the unique features of the OLPC
          XO hardware.
index c5d3a5abbb9f4ec2757b468bc14459ce4d13d496..24487712e0b1915368f96a3a74ba362ff42fdbbd 100644 (file)
@@ -26,15 +26,12 @@ extern void setup_olpc_ofw_pgd(void);
 /* check if OFW was detected during boot */
 extern bool olpc_ofw_present(void);
 
+extern void olpc_dt_build_devicetree(void);
+
 #else /* !CONFIG_OLPC */
 static inline void olpc_ofw_detect(void) { }
 static inline void setup_olpc_ofw_pgd(void) { }
-#endif /* !CONFIG_OLPC */
-
-#ifdef CONFIG_OF_PROMTREE
-extern void olpc_dt_build_devicetree(void);
-#else
 static inline void olpc_dt_build_devicetree(void) { }
-#endif
+#endif /* !CONFIG_OLPC */
 
 #endif /* _ASM_X86_OLPC_OFW_H */
diff --git a/arch/x86/include/asm/probe_roms.h b/arch/x86/include/asm/probe_roms.h
new file mode 100644 (file)
index 0000000..4950a0b
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef _PROBE_ROMS_H_
+#define _PROBE_ROMS_H_
+struct pci_dev;
+
+extern void __iomem *pci_map_biosrom(struct pci_dev *pdev);
+extern void pci_unmap_biosrom(void __iomem *rom);
+extern size_t pci_biosrom_size(struct pci_dev *pdev);
+#endif
index 647d8a06ce4f8bc3938f3818cc98c1c946dc84d0..9756551ec76024dba4dbf7a4f09f988219ca6f0b 100644 (file)
@@ -104,10 +104,10 @@ void *extend_brk(size_t size, size_t align);
        type *name;                                     \
        RESERVE_BRK(name, sizeof(type) * entries)
 
+extern void probe_roms(void);
 #ifdef __i386__
 
 void __init i386_start_kernel(void);
-extern void probe_roms(void);
 
 #else
 void __init x86_64_start_kernel(char *real_mode);
index 97ebf82e0b7f0236002084b75ab2c95b6d3b8a7e..250806472a7e07373c7bf5cd66acfc8bca81d032 100644 (file)
@@ -36,7 +36,7 @@ obj-y                 += traps.o irq.o irq_$(BITS).o dumpstack_$(BITS).o
 obj-y                  += time.o ioport.o ldt.o dumpstack.o
 obj-y                  += setup.o x86_init.o i8259.o irqinit.o jump_label.o
 obj-$(CONFIG_IRQ_WORK)  += irq_work.o
-obj-$(CONFIG_X86_32)   += probe_roms_32.o
+obj-y                  += probe_roms.o
 obj-$(CONFIG_X86_32)   += sys_i386_32.o i386_ksyms_32.o
 obj-$(CONFIG_X86_64)   += sys_x86_64.o x8664_ksyms_64.o
 obj-$(CONFIG_X86_64)   += syscall_64.o vsyscall_64.o
index d6d6bb36193126885f4de35964fd6d07c7e3325b..3bb08509a7a151725182e5cf64d7dd636958e239 100644 (file)
@@ -23,7 +23,6 @@
 static void __init i386_default_early_setup(void)
 {
        /* Initialize 32bit specific setup functions */
-       x86_init.resources.probe_roms = probe_roms;
        x86_init.resources.reserve_resources = i386_reserve_resources;
        x86_init.mpparse.setup_ioapic_ids = setup_ioapic_ids_from_mpc;
 
diff --git a/arch/x86/kernel/probe_roms.c b/arch/x86/kernel/probe_roms.c
new file mode 100644 (file)
index 0000000..ba0a4cc
--- /dev/null
@@ -0,0 +1,267 @@
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/uaccess.h>
+#include <linux/mmzone.h>
+#include <linux/ioport.h>
+#include <linux/seq_file.h>
+#include <linux/console.h>
+#include <linux/init.h>
+#include <linux/edd.h>
+#include <linux/dmi.h>
+#include <linux/pfn.h>
+#include <linux/pci.h>
+#include <asm/pci-direct.h>
+
+
+#include <asm/e820.h>
+#include <asm/mmzone.h>
+#include <asm/setup.h>
+#include <asm/sections.h>
+#include <asm/io.h>
+#include <asm/setup_arch.h>
+
+static struct resource system_rom_resource = {
+       .name   = "System ROM",
+       .start  = 0xf0000,
+       .end    = 0xfffff,
+       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
+};
+
+static struct resource extension_rom_resource = {
+       .name   = "Extension ROM",
+       .start  = 0xe0000,
+       .end    = 0xeffff,
+       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
+};
+
+static struct resource adapter_rom_resources[] = { {
+       .name   = "Adapter ROM",
+       .start  = 0xc8000,
+       .end    = 0,
+       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
+}, {
+       .name   = "Adapter ROM",
+       .start  = 0,
+       .end    = 0,
+       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
+}, {
+       .name   = "Adapter ROM",
+       .start  = 0,
+       .end    = 0,
+       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
+}, {
+       .name   = "Adapter ROM",
+       .start  = 0,
+       .end    = 0,
+       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
+}, {
+       .name   = "Adapter ROM",
+       .start  = 0,
+       .end    = 0,
+       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
+}, {
+       .name   = "Adapter ROM",
+       .start  = 0,
+       .end    = 0,
+       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
+} };
+
+static struct resource video_rom_resource = {
+       .name   = "Video ROM",
+       .start  = 0xc0000,
+       .end    = 0xc7fff,
+       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
+};
+
+/* does this oprom support the given pci device, or any of the devices
+ * that the driver supports?
+ */
+static bool match_id(struct pci_dev *pdev, unsigned short vendor, unsigned short device)
+{
+       struct pci_driver *drv = pdev->driver;
+       const struct pci_device_id *id;
+
+       if (pdev->vendor == vendor && pdev->device == device)
+               return true;
+
+       for (id = drv ? drv->id_table : NULL; id && id->vendor; id++)
+               if (id->vendor == vendor && id->device == device)
+                       break;
+
+       return id && id->vendor;
+}
+
+static bool probe_list(struct pci_dev *pdev, unsigned short vendor,
+                      const unsigned char *rom_list)
+{
+       unsigned short device;
+
+       do {
+               if (probe_kernel_address(rom_list, device) != 0)
+                       device = 0;
+
+               if (device && match_id(pdev, vendor, device))
+                       break;
+
+               rom_list += 2;
+       } while (device);
+
+       return !!device;
+}
+
+static struct resource *find_oprom(struct pci_dev *pdev)
+{
+       struct resource *oprom = NULL;
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(adapter_rom_resources); i++) {
+               struct resource *res = &adapter_rom_resources[i];
+               unsigned short offset, vendor, device, list, rev;
+               const unsigned char *rom;
+
+               if (res->end == 0)
+                       break;
+
+               rom = isa_bus_to_virt(res->start);
+               if (probe_kernel_address(rom + 0x18, offset) != 0)
+                       continue;
+
+               if (probe_kernel_address(rom + offset + 0x4, vendor) != 0)
+                       continue;
+
+               if (probe_kernel_address(rom + offset + 0x6, device) != 0)
+                       continue;
+
+               if (match_id(pdev, vendor, device)) {
+                       oprom = res;
+                       break;
+               }
+
+               if (probe_kernel_address(rom + offset + 0x8, list) == 0 &&
+                   probe_kernel_address(rom + offset + 0xc, rev) == 0 &&
+                   rev >= 3 && list &&
+                   probe_list(pdev, vendor, rom + offset + list)) {
+                       oprom = res;
+                       break;
+               }
+       }
+
+       return oprom;
+}
+
+void *pci_map_biosrom(struct pci_dev *pdev)
+{
+       struct resource *oprom = find_oprom(pdev);
+
+       if (!oprom)
+               return NULL;
+
+       return ioremap(oprom->start, resource_size(oprom));
+}
+EXPORT_SYMBOL(pci_map_biosrom);
+
+void pci_unmap_biosrom(void __iomem *image)
+{
+       iounmap(image);
+}
+EXPORT_SYMBOL(pci_unmap_biosrom);
+
+size_t pci_biosrom_size(struct pci_dev *pdev)
+{
+       struct resource *oprom = find_oprom(pdev);
+
+       return oprom ? resource_size(oprom) : 0;
+}
+EXPORT_SYMBOL(pci_biosrom_size);
+
+#define ROMSIGNATURE 0xaa55
+
+static int __init romsignature(const unsigned char *rom)
+{
+       const unsigned short * const ptr = (const unsigned short *)rom;
+       unsigned short sig;
+
+       return probe_kernel_address(ptr, sig) == 0 && sig == ROMSIGNATURE;
+}
+
+static int __init romchecksum(const unsigned char *rom, unsigned long length)
+{
+       unsigned char sum, c;
+
+       for (sum = 0; length && probe_kernel_address(rom++, c) == 0; length--)
+               sum += c;
+       return !length && !sum;
+}
+
+void __init probe_roms(void)
+{
+       const unsigned char *rom;
+       unsigned long start, length, upper;
+       unsigned char c;
+       int i;
+
+       /* video rom */
+       upper = adapter_rom_resources[0].start;
+       for (start = video_rom_resource.start; start < upper; start += 2048) {
+               rom = isa_bus_to_virt(start);
+               if (!romsignature(rom))
+                       continue;
+
+               video_rom_resource.start = start;
+
+               if (probe_kernel_address(rom + 2, c) != 0)
+                       continue;
+
+               /* 0 < length <= 0x7f * 512, historically */
+               length = c * 512;
+
+               /* if checksum okay, trust length byte */
+               if (length && romchecksum(rom, length))
+                       video_rom_resource.end = start + length - 1;
+
+               request_resource(&iomem_resource, &video_rom_resource);
+               break;
+       }
+
+       start = (video_rom_resource.end + 1 + 2047) & ~2047UL;
+       if (start < upper)
+               start = upper;
+
+       /* system rom */
+       request_resource(&iomem_resource, &system_rom_resource);
+       upper = system_rom_resource.start;
+
+       /* check for extension rom (ignore length byte!) */
+       rom = isa_bus_to_virt(extension_rom_resource.start);
+       if (romsignature(rom)) {
+               length = extension_rom_resource.end - extension_rom_resource.start + 1;
+               if (romchecksum(rom, length)) {
+                       request_resource(&iomem_resource, &extension_rom_resource);
+                       upper = extension_rom_resource.start;
+               }
+       }
+
+       /* check for adapter roms on 2k boundaries */
+       for (i = 0; i < ARRAY_SIZE(adapter_rom_resources) && start < upper; start += 2048) {
+               rom = isa_bus_to_virt(start);
+               if (!romsignature(rom))
+                       continue;
+
+               if (probe_kernel_address(rom + 2, c) != 0)
+                       continue;
+
+               /* 0 < length <= 0x7f * 512, historically */
+               length = c * 512;
+
+               /* but accept any length that fits if checksum okay */
+               if (!length || start + length > upper || !romchecksum(rom, length))
+                       continue;
+
+               adapter_rom_resources[i].start = start;
+               adapter_rom_resources[i].end = start + length - 1;
+               request_resource(&iomem_resource, &adapter_rom_resources[i]);
+
+               start = adapter_rom_resources[i++].end & ~2047UL;
+       }
+}
+
diff --git a/arch/x86/kernel/probe_roms_32.c b/arch/x86/kernel/probe_roms_32.c
deleted file mode 100644 (file)
index 071e7fe..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-#include <linux/sched.h>
-#include <linux/mm.h>
-#include <linux/uaccess.h>
-#include <linux/mmzone.h>
-#include <linux/ioport.h>
-#include <linux/seq_file.h>
-#include <linux/console.h>
-#include <linux/init.h>
-#include <linux/edd.h>
-#include <linux/dmi.h>
-#include <linux/pfn.h>
-#include <linux/pci.h>
-#include <asm/pci-direct.h>
-
-
-#include <asm/e820.h>
-#include <asm/mmzone.h>
-#include <asm/setup.h>
-#include <asm/sections.h>
-#include <asm/io.h>
-#include <asm/setup_arch.h>
-
-static struct resource system_rom_resource = {
-       .name   = "System ROM",
-       .start  = 0xf0000,
-       .end    = 0xfffff,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
-};
-
-static struct resource extension_rom_resource = {
-       .name   = "Extension ROM",
-       .start  = 0xe0000,
-       .end    = 0xeffff,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
-};
-
-static struct resource adapter_rom_resources[] = { {
-       .name   = "Adapter ROM",
-       .start  = 0xc8000,
-       .end    = 0,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
-}, {
-       .name   = "Adapter ROM",
-       .start  = 0,
-       .end    = 0,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
-}, {
-       .name   = "Adapter ROM",
-       .start  = 0,
-       .end    = 0,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
-}, {
-       .name   = "Adapter ROM",
-       .start  = 0,
-       .end    = 0,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
-}, {
-       .name   = "Adapter ROM",
-       .start  = 0,
-       .end    = 0,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
-}, {
-       .name   = "Adapter ROM",
-       .start  = 0,
-       .end    = 0,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
-} };
-
-static struct resource video_rom_resource = {
-       .name   = "Video ROM",
-       .start  = 0xc0000,
-       .end    = 0xc7fff,
-       .flags  = IORESOURCE_BUSY | IORESOURCE_READONLY | IORESOURCE_MEM
-};
-
-#define ROMSIGNATURE 0xaa55
-
-static int __init romsignature(const unsigned char *rom)
-{
-       const unsigned short * const ptr = (const unsigned short *)rom;
-       unsigned short sig;
-
-       return probe_kernel_address(ptr, sig) == 0 && sig == ROMSIGNATURE;
-}
-
-static int __init romchecksum(const unsigned char *rom, unsigned long length)
-{
-       unsigned char sum, c;
-
-       for (sum = 0; length && probe_kernel_address(rom++, c) == 0; length--)
-               sum += c;
-       return !length && !sum;
-}
-
-void __init probe_roms(void)
-{
-       const unsigned char *rom;
-       unsigned long start, length, upper;
-       unsigned char c;
-       int i;
-
-       /* video rom */
-       upper = adapter_rom_resources[0].start;
-       for (start = video_rom_resource.start; start < upper; start += 2048) {
-               rom = isa_bus_to_virt(start);
-               if (!romsignature(rom))
-                       continue;
-
-               video_rom_resource.start = start;
-
-               if (probe_kernel_address(rom + 2, c) != 0)
-                       continue;
-
-               /* 0 < length <= 0x7f * 512, historically */
-               length = c * 512;
-
-               /* if checksum okay, trust length byte */
-               if (length && romchecksum(rom, length))
-                       video_rom_resource.end = start + length - 1;
-
-               request_resource(&iomem_resource, &video_rom_resource);
-               break;
-       }
-
-       start = (video_rom_resource.end + 1 + 2047) & ~2047UL;
-       if (start < upper)
-               start = upper;
-
-       /* system rom */
-       request_resource(&iomem_resource, &system_rom_resource);
-       upper = system_rom_resource.start;
-
-       /* check for extension rom (ignore length byte!) */
-       rom = isa_bus_to_virt(extension_rom_resource.start);
-       if (romsignature(rom)) {
-               length = extension_rom_resource.end - extension_rom_resource.start + 1;
-               if (romchecksum(rom, length)) {
-                       request_resource(&iomem_resource, &extension_rom_resource);
-                       upper = extension_rom_resource.start;
-               }
-       }
-
-       /* check for adapter roms on 2k boundaries */
-       for (i = 0; i < ARRAY_SIZE(adapter_rom_resources) && start < upper; start += 2048) {
-               rom = isa_bus_to_virt(start);
-               if (!romsignature(rom))
-                       continue;
-
-               if (probe_kernel_address(rom + 2, c) != 0)
-                       continue;
-
-               /* 0 < length <= 0x7f * 512, historically */
-               length = c * 512;
-
-               /* but accept any length that fits if checksum okay */
-               if (!length || start + length > upper || !romchecksum(rom, length))
-                       continue;
-
-               adapter_rom_resources[i].start = start;
-               adapter_rom_resources[i].end = start + length - 1;
-               request_resource(&iomem_resource, &adapter_rom_resources[i]);
-
-               start = adapter_rom_resources[i++].end & ~2047UL;
-       }
-}
-
index 75ef4b18e9b7963280c808bd59d1abe5579673ca..6f164bd5e14d167d417b2f86e5fc8580047ed371 100644 (file)
@@ -35,7 +35,7 @@ void iommu_shutdown_noop(void) { }
 struct x86_init_ops x86_init __initdata = {
 
        .resources = {
-               .probe_roms             = x86_init_noop,
+               .probe_roms             = probe_roms,
                .reserve_resources      = reserve_standard_io_resources,
                .memory_setup           = default_machine_specific_memory_setup,
        },
index c2a8cab65e5d71f82404a9b6b118dc6556c79489..81c5e2165c2416be638675f83f887e1f8f52d218 100644 (file)
@@ -1,4 +1,2 @@
-obj-$(CONFIG_OLPC)             += olpc.o
+obj-$(CONFIG_OLPC)             += olpc.o olpc_ofw.o olpc_dt.o
 obj-$(CONFIG_OLPC_XO1)         += olpc-xo1.o
-obj-$(CONFIG_OLPC)             += olpc_ofw.o
-obj-$(CONFIG_OF_PROMTREE)      += olpc_dt.o
index edaf3fe8dc5e4b0326c0280042b868cd3400bf4c..0060fd59ea001baaf1b31769bb1bbe6c490709ca 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/io.h>
 #include <linux/string.h>
 #include <linux/platform_device.h>
+#include <linux/of.h>
 
 #include <asm/geode.h>
 #include <asm/setup.h>
@@ -187,41 +188,43 @@ err:
 }
 EXPORT_SYMBOL_GPL(olpc_ec_cmd);
 
-static bool __init check_ofw_architecture(void)
+static bool __init check_ofw_architecture(struct device_node *root)
 {
-       size_t propsize;
-       char olpc_arch[5];
-       const void *args[] = { NULL, "architecture", olpc_arch, (void *)5 };
-       void *res[] = { &propsize };
+       const char *olpc_arch;
+       int propsize;
 
-       if (olpc_ofw("getprop", args, res)) {
-               printk(KERN_ERR "ofw: getprop call failed!\n");
-               return false;
-       }
+       olpc_arch = of_get_property(root, "architecture", &propsize);
        return propsize == 5 && strncmp("OLPC", olpc_arch, 5) == 0;
 }
 
-static u32 __init get_board_revision(void)
+static u32 __init get_board_revision(struct device_node *root)
 {
-       size_t propsize;
-       __be32 rev;
-       const void *args[] = { NULL, "board-revision-int", &rev, (void *)4 };
-       void *res[] = { &propsize };
-
-       if (olpc_ofw("getprop", args, res) || propsize != 4) {
-               printk(KERN_ERR "ofw: getprop call failed!\n");
-               return cpu_to_be32(0);
-       }
-       return be32_to_cpu(rev);
+       int propsize;
+       const __be32 *rev;
+
+       rev = of_get_property(root, "board-revision-int", &propsize);
+       if (propsize != 4)
+               return 0;
+
+       return be32_to_cpu(*rev);
 }
 
 static bool __init platform_detect(void)
 {
-       if (!check_ofw_architecture())
+       struct device_node *root = of_find_node_by_path("/");
+       bool success;
+
+       if (!root)
                return false;
-       olpc_platform_info.flags |= OLPC_F_PRESENT;
-       olpc_platform_info.boardrev = get_board_revision();
-       return true;
+
+       success = check_ofw_architecture(root);
+       if (success) {
+               olpc_platform_info.boardrev = get_board_revision(root);
+               olpc_platform_info.flags |= OLPC_F_PRESENT;
+       }
+
+       of_node_put(root);
+       return success;
 }
 
 static int __init add_xo1_platform_devices(void)
index 044bda5b3174f19c07a0fe9cb8b1ab1d77ca1b60..d39f63d017d2860aecc2f8b0237a56da5c3ca4c7 100644 (file)
@@ -19,7 +19,9 @@
 #include <linux/kernel.h>
 #include <linux/bootmem.h>
 #include <linux/of.h>
+#include <linux/of_platform.h>
 #include <linux/of_pdt.h>
+#include <asm/olpc.h>
 #include <asm/olpc_ofw.h>
 
 static phandle __init olpc_dt_getsibling(phandle node)
@@ -180,3 +182,20 @@ void __init olpc_dt_build_devicetree(void)
        pr_info("PROM DT: Built device tree with %u bytes of memory.\n",
                        prom_early_allocated);
 }
+
+/* A list of DT node/bus matches that we want to expose as platform devices */
+static struct of_device_id __initdata of_ids[] = {
+       { .compatible = "olpc,xo1-battery" },
+       { .compatible = "olpc,xo1-dcon" },
+       { .compatible = "olpc,xo1-rtc" },
+       {},
+};
+
+static int __init olpc_create_platform_devices(void)
+{
+       if (machine_is_olpc())
+               return of_platform_bus_probe(NULL, of_ids, NULL);
+       else
+               return 0;
+}
+device_initcall(olpc_create_platform_devices);