s3c2410fb: fix s3c2410 compilation
[pv_ops_mirror.git] / drivers / pnp / system.c
bloba06f980b3ac9b596ef886b08a908602c79ec270f
1 /*
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>
8 */
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 */
19 {"PNP0c02", 0},
20 /* memory controller */
21 {"PNP0c01", 0},
22 {"", 0}
25 static void reserve_range(const char *pnpid, resource_size_t start,
26 resource_size_t end, int port)
28 struct resource *res;
29 char *regionid;
31 regionid = kmalloc(16, GFP_KERNEL);
32 if (regionid == NULL)
33 return;
34 snprintf(regionid, 16, "pnp %s", pnpid);
35 if (port)
36 res = request_region(start, end - start + 1, regionid);
37 else
38 res = request_mem_region(start, end - start + 1, regionid);
39 if (res == NULL)
40 kfree(regionid);
41 else
42 res->flags &= ~IORESOURCE_BUSY;
44 * Failures at this point are usually harmless. pci quirks for
45 * example do reserve stuff they know about too, so we may well
46 * have double reservations.
48 printk(KERN_INFO "pnp: %s: %s range 0x%llx-0x%llx %s reserved\n",
49 pnpid, port ? "ioport" : "iomem",
50 (unsigned long long)start, (unsigned long long)end,
51 NULL != res ? "has been" : "could not be");
54 static void reserve_resources_of_dev(const struct pnp_dev *dev)
56 int i;
58 for (i = 0; i < PNP_MAX_PORT; i++) {
59 if (!pnp_port_valid(dev, i))
60 continue;
61 if (pnp_port_start(dev, i) == 0)
62 continue; /* disabled */
63 if (pnp_port_start(dev, i) < 0x100)
65 * Below 0x100 is only standard PC hardware
66 * (pics, kbd, timer, dma, ...)
67 * We should not get resource conflicts there,
68 * and the kernel reserves these anyway
69 * (see arch/i386/kernel/setup.c).
70 * So, do nothing
72 continue;
73 if (pnp_port_end(dev, i) < pnp_port_start(dev, i))
74 continue; /* invalid */
76 reserve_range(dev->dev.bus_id, pnp_port_start(dev, i),
77 pnp_port_end(dev, i), 1);
80 for (i = 0; i < PNP_MAX_MEM; i++) {
81 if (!pnp_mem_valid(dev, i))
82 continue;
84 reserve_range(dev->dev.bus_id, pnp_mem_start(dev, i),
85 pnp_mem_end(dev, i), 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);
93 return 0;
96 static struct pnp_driver system_pnp_driver = {
97 .name = "system",
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);