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, struct resource *r, int port)
28 const char *pnpid = dev_name(&dev->dev);
29 resource_size_t start = r->start, end = r->end;
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, "%pR %s reserved\n", r,
52 res ? "has been" : "could not be");
55 static void reserve_resources_of_dev(struct pnp_dev *dev)
60 for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) {
61 if (res->flags & IORESOURCE_DISABLED)
64 continue; /* disabled */
65 if (res->start < 0x100)
67 * Below 0x100 is only standard PC hardware
68 * (pics, kbd, timer, dma, ...)
69 * We should not get resource conflicts there,
70 * and the kernel reserves these anyway
71 * (see arch/i386/kernel/setup.c).
75 if (res->end < res->start)
76 continue; /* invalid */
78 reserve_range(dev, res, 1);
81 for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) {
82 if (res->flags & IORESOURCE_DISABLED)
85 reserve_range(dev, res, 0);
89 static int system_pnp_probe(struct pnp_dev *dev,
90 const struct pnp_device_id *dev_id)
92 reserve_resources_of_dev(dev);
96 static struct pnp_driver system_pnp_driver = {
98 .id_table = pnp_dev_table,
99 .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
100 .probe = system_pnp_probe,
103 static int __init pnp_system_init(void)
105 return pnp_register_driver(&system_pnp_driver);
109 * Reserve motherboard resources after PCI claim BARs,
110 * but before PCI assign resources for uninitialized PCI devices
112 fs_initcall(pnp_system_init);