ARM: ep93xx: move timer to its own file
[linux/fpc-iii.git] / drivers / pnp / system.c
blob515f33882ab89ae27ea4d7006e818fa8b15fffb3
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/acpi.h>
11 #include <linux/pnp.h>
12 #include <linux/device.h>
13 #include <linux/init.h>
14 #include <linux/slab.h>
15 #include <linux/kernel.h>
16 #include <linux/ioport.h>
18 static const struct pnp_device_id pnp_dev_table[] = {
19 /* General ID for reserving resources */
20 {"PNP0c02", 0},
21 /* memory controller */
22 {"PNP0c01", 0},
23 {"", 0}
26 #ifdef CONFIG_ACPI
27 static bool __reserve_range(u64 start, unsigned int length, bool io, char *desc)
29 u8 space_id = io ? ACPI_ADR_SPACE_SYSTEM_IO : ACPI_ADR_SPACE_SYSTEM_MEMORY;
30 return !acpi_reserve_region(start, length, space_id, IORESOURCE_BUSY, desc);
32 #else
33 static bool __reserve_range(u64 start, unsigned int length, bool io, char *desc)
35 struct resource *res;
37 res = io ? request_region(start, length, desc) :
38 request_mem_region(start, length, desc);
39 if (res) {
40 res->flags &= ~IORESOURCE_BUSY;
41 return true;
43 return false;
45 #endif
47 static void reserve_range(struct pnp_dev *dev, struct resource *r, int port)
49 char *regionid;
50 const char *pnpid = dev_name(&dev->dev);
51 resource_size_t start = r->start, end = r->end;
52 bool reserved;
54 regionid = kmalloc(16, GFP_KERNEL);
55 if (!regionid)
56 return;
58 snprintf(regionid, 16, "pnp %s", pnpid);
59 reserved = __reserve_range(start, end - start + 1, !!port, regionid);
60 if (!reserved)
61 kfree(regionid);
64 * Failures at this point are usually harmless. pci quirks for
65 * example do reserve stuff they know about too, so we may well
66 * have double reservations.
68 dev_info(&dev->dev, "%pR %s reserved\n", r,
69 reserved ? "has been" : "could not be");
72 static void reserve_resources_of_dev(struct pnp_dev *dev)
74 struct resource *res;
75 int i;
77 for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) {
78 if (res->flags & IORESOURCE_DISABLED)
79 continue;
80 if (res->start == 0)
81 continue; /* disabled */
82 if (res->start < 0x100)
84 * Below 0x100 is only standard PC hardware
85 * (pics, kbd, timer, dma, ...)
86 * We should not get resource conflicts there,
87 * and the kernel reserves these anyway
88 * (see arch/i386/kernel/setup.c).
89 * So, do nothing
91 continue;
92 if (res->end < res->start)
93 continue; /* invalid */
95 reserve_range(dev, res, 1);
98 for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) {
99 if (res->flags & IORESOURCE_DISABLED)
100 continue;
102 reserve_range(dev, res, 0);
106 static int system_pnp_probe(struct pnp_dev *dev,
107 const struct pnp_device_id *dev_id)
109 reserve_resources_of_dev(dev);
110 return 0;
113 static struct pnp_driver system_pnp_driver = {
114 .name = "system",
115 .id_table = pnp_dev_table,
116 .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
117 .probe = system_pnp_probe,
120 static int __init pnp_system_init(void)
122 return pnp_register_driver(&system_pnp_driver);
126 * Reserve motherboard resources after PCI claim BARs,
127 * but before PCI assign resources for uninitialized PCI devices
129 fs_initcall(pnp_system_init);