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>
10 #include <linux/device.h>
11 #include <linux/init.h>
12 #include <linux/slab.h>
13 #include <linux/kernel.h>
14 #include <linux/ioport.h>
16 static const struct pnp_device_id pnp_dev_table[] = {
17 /* General ID for reserving resources */
19 /* memory controller */
24 static void reserve_ioport_range(char *pnpid, int start, int end)
29 regionid = kmalloc(16, GFP_KERNEL);
30 if ( regionid == NULL )
32 snprintf(regionid, 16, "pnp %s", pnpid);
33 res = request_region(start,end-start+1,regionid);
37 res->flags &= ~IORESOURCE_BUSY;
39 * Failures at this point are usually harmless. pci quirks for
40 * example do reserve stuff they know about too, so we may well
41 * have double reservations.
44 "pnp: %s: ioport range 0x%x-0x%x %s reserved\n",
46 NULL != res ? "has been" : "could not be"
52 static void reserve_resources_of_dev( struct pnp_dev *dev )
56 for (i=0;i<PNP_MAX_PORT;i++) {
57 if (!pnp_port_valid(dev, i))
58 /* end of resources */
60 if (pnp_port_start(dev, i) == 0)
64 if (pnp_port_start(dev, i) < 0x100)
66 * Below 0x100 is only standard PC hardware
67 * (pics, kbd, timer, dma, ...)
68 * We should not get resource conflicts there,
69 * and the kernel reserves these anyway
70 * (see arch/i386/kernel/setup.c).
74 if (pnp_port_end(dev, i) < pnp_port_start(dev, i))
75 /* invalid endpoint */
80 pnp_port_start(dev, i),
88 static int system_pnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev_id)
90 reserve_resources_of_dev(dev);
94 static struct pnp_driver system_pnp_driver = {
96 .id_table = pnp_dev_table,
97 .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
98 .probe = system_pnp_probe,
102 static int __init pnp_system_init(void)
104 return pnp_register_driver(&system_pnp_driver);
108 * Reserve motherboard resources after PCI claim BARs,
109 * but before PCI assign resources for uninitialized PCI devices
111 fs_initcall(pnp_system_init);