]> err.no Git - linux-2.6/blob - drivers/pnp/system.c
PNP: reserve system board iomem resources as well as ioport resources
[linux-2.6] / drivers / pnp / system.c
1 /*
2  * system.c - a driver for reserving pnp system resources
3  *
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>
8  */
9
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>
16
17 static const struct pnp_device_id pnp_dev_table[] = {
18         /* General ID for reserving resources */
19         {       "PNP0c02",              0       },
20         /* memory controller */
21         {       "PNP0c01",              0       },
22         {       "",                     0       }
23 };
24
25 static void reserve_range(char *pnpid, int start, int end, int port)
26 {
27         struct resource *res;
28         char *regionid;
29
30         regionid = kmalloc(16, GFP_KERNEL);
31         if ( regionid == NULL )
32                 return;
33         snprintf(regionid, 16, "pnp %s", pnpid);
34         if (port)
35                 res = request_region(start,end-start+1,regionid);
36         else
37                 res = request_mem_region(start,end-start+1,regionid);
38         if ( res == NULL )
39                 kfree( regionid );
40         else
41                 res->flags &= ~IORESOURCE_BUSY;
42         /*
43          * Failures at this point are usually harmless. pci quirks for
44          * example do reserve stuff they know about too, so we may well
45          * have double reservations.
46          */
47         printk(KERN_INFO
48                 "pnp: %s: %s range 0x%x-0x%x %s reserved\n",
49                 pnpid, port ? "ioport" : "iomem", start, end,
50                 NULL != res ? "has been" : "could not be"
51         );
52
53         return;
54 }
55
56 static void reserve_resources_of_dev( struct pnp_dev *dev )
57 {
58         int i;
59
60         for (i=0;i<PNP_MAX_PORT;i++) {
61                 if (!pnp_port_valid(dev, i))
62                         /* end of resources */
63                         continue;
64                 if (pnp_port_start(dev, i) == 0)
65                         /* disabled */
66                         /* Do nothing */
67                         continue;
68                 if (pnp_port_start(dev, i) < 0x100)
69                         /*
70                          * Below 0x100 is only standard PC hardware
71                          * (pics, kbd, timer, dma, ...)
72                          * We should not get resource conflicts there,
73                          * and the kernel reserves these anyway
74                          * (see arch/i386/kernel/setup.c).
75                          * So, do nothing
76                          */
77                         continue;
78                 if (pnp_port_end(dev, i) < pnp_port_start(dev, i))
79                         /* invalid endpoint */
80                         /* Do nothing */
81                         continue;
82                 reserve_range(
83                         dev->dev.bus_id,
84                         pnp_port_start(dev, i),
85                         pnp_port_end(dev, i), 1
86                 );
87         }
88
89         for (i = 0; i < PNP_MAX_MEM; i++) {
90                 if (!pnp_mem_valid(dev, i))
91                         continue;
92
93                 reserve_range(dev->dev.bus_id, pnp_mem_start(dev, i),
94                         pnp_mem_end(dev, i), 0);
95         }
96
97         return;
98 }
99
100 static int system_pnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev_id)
101 {
102         reserve_resources_of_dev(dev);
103         return 0;
104 }
105
106 static struct pnp_driver system_pnp_driver = {
107         .name           = "system",
108         .id_table       = pnp_dev_table,
109         .flags          = PNP_DRIVER_RES_DO_NOT_CHANGE,
110         .probe          = system_pnp_probe,
111         .remove         = NULL,
112 };
113
114 static int __init pnp_system_init(void)
115 {
116         return pnp_register_driver(&system_pnp_driver);
117 }
118
119 /**
120  * Reserve motherboard resources after PCI claim BARs,
121  * but before PCI assign resources for uninitialized PCI devices
122  */
123 fs_initcall(pnp_system_init);