2 * system.c - a driver for reserving pnp system resources
4 * Some code is based on pnpbios_core.c
5 * Copyright 2002 Adam Belay <ambx1@neo.rr.com>
6 * (c) Copyright 2007 Hewlett-Packard Development Company, L.P.
7 * Bjorn Helgaas <bjorn.helgaas@hp.com>
10 #include <linux/pnp.h>
11 #include <linux/device.h>
12 #include <linux/init.h>
13 #include <linux/slab.h>
14 #include <linux/kernel.h>
15 #include <linux/ioport.h>
17 static const struct pnp_device_id pnp_dev_table[] = {
18 /* General ID for reserving resources */
20 /* memory controller */
25 static void reserve_range(struct pnp_dev *dev, resource_size_t start,
26 resource_size_t end, int port)
29 const char *pnpid = dev->dev.bus_id;
32 regionid = kmalloc(16, GFP_KERNEL);
36 snprintf(regionid, 16, "pnp %s", pnpid);
38 res = request_region(start, end - start + 1, regionid);
40 res = request_mem_region(start, end - start + 1, regionid);
42 res->flags &= ~IORESOURCE_BUSY;
47 * Failures at this point are usually harmless. pci quirks for
48 * example do reserve stuff they know about too, so we may well
49 * have double reservations.
51 dev_info(&dev->dev, "%s range 0x%llx-0x%llx %s reserved\n",
52 port ? "ioport" : "iomem",
53 (unsigned long long) start, (unsigned long long) end,
54 res ? "has been" : "could not be");
57 static void reserve_resources_of_dev(struct pnp_dev *dev)
62 for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) {
63 if (res->flags & IORESOURCE_DISABLED)
66 continue; /* disabled */
67 if (res->start < 0x100)
69 * Below 0x100 is only standard PC hardware
70 * (pics, kbd, timer, dma, ...)
71 * We should not get resource conflicts there,
72 * and the kernel reserves these anyway
73 * (see arch/i386/kernel/setup.c).
77 if (res->end < res->start)
78 continue; /* invalid */
80 reserve_range(dev, res->start, res->end, 1);
83 for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) {
84 if (res->flags & IORESOURCE_DISABLED)
87 reserve_range(dev, res->start, res->end, 0);
91 static int system_pnp_probe(struct pnp_dev *dev,
92 const struct pnp_device_id *dev_id)
94 reserve_resources_of_dev(dev);
98 static struct pnp_driver system_pnp_driver = {
100 .id_table = pnp_dev_table,
101 .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
102 .probe = system_pnp_probe,
105 static int __init pnp_system_init(void)
107 return pnp_register_driver(&system_pnp_driver);
111 * Reserve motherboard resources after PCI claim BARs,
112 * but before PCI assign resources for uninitialized PCI devices
114 fs_initcall(pnp_system_init);