blob: a8a95540b1ef78a225ea39653bc48e8a217410d4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Bjorn Helgaasa8c78f72007-01-18 16:43:27 -07006 * (c) Copyright 2007 Hewlett-Packard Development Company, L.P.
7 * Bjorn Helgaas <bjorn.helgaas@hp.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
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
17static 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
Petr Vandroveca2b091d2007-04-01 23:49:46 -070025static void reserve_range(const char *pnpid, resource_size_t start, resource_size_t end, int port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070026{
27 struct resource *res;
28 char *regionid;
29
30 regionid = kmalloc(16, GFP_KERNEL);
Bjorn Helgaas58595542007-01-18 16:43:46 -070031 if (regionid == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 return;
33 snprintf(regionid, 16, "pnp %s", pnpid);
Bjorn Helgaasa8c78f72007-01-18 16:43:27 -070034 if (port)
Petr Vandroveca2b091d2007-04-01 23:49:46 -070035 res = request_region(start, end-start+1, regionid);
Bjorn Helgaasa8c78f72007-01-18 16:43:27 -070036 else
Petr Vandroveca2b091d2007-04-01 23:49:46 -070037 res = request_mem_region(start, end-start+1, regionid);
Bjorn Helgaas58595542007-01-18 16:43:46 -070038 if (res == NULL)
39 kfree(regionid);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 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
Petr Vandroveca2b091d2007-04-01 23:49:46 -070048 "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,
Bjorn Helgaas58595542007-01-18 16:43:46 -070051 NULL != res ? "has been" : "could not be");
Linus Torvalds1da177e2005-04-16 15:20:36 -070052}
53
Petr Vandroveca2b091d2007-04-01 23:49:46 -070054static void reserve_resources_of_dev(const struct pnp_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
56 int i;
57
Bjorn Helgaas58595542007-01-18 16:43:46 -070058 for (i = 0; i < PNP_MAX_PORT; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 if (!pnp_port_valid(dev, i))
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 continue;
61 if (pnp_port_start(dev, i) == 0)
Bjorn Helgaas58595542007-01-18 16:43:46 -070062 continue; /* disabled */
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 if (pnp_port_start(dev, i) < 0x100)
64 /*
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
71 */
72 continue;
73 if (pnp_port_end(dev, i) < pnp_port_start(dev, i))
Bjorn Helgaas58595542007-01-18 16:43:46 -070074 continue; /* invalid */
75
76 reserve_range(dev->dev.bus_id, pnp_port_start(dev, i),
77 pnp_port_end(dev, i), 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 }
79
Bjorn Helgaasa8c78f72007-01-18 16:43:27 -070080 for (i = 0; i < PNP_MAX_MEM; i++) {
81 if (!pnp_mem_valid(dev, i))
82 continue;
83
84 reserve_range(dev->dev.bus_id, pnp_mem_start(dev, i),
85 pnp_mem_end(dev, i), 0);
86 }
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 return;
89}
90
91static int system_pnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev_id)
92{
93 reserve_resources_of_dev(dev);
94 return 0;
95}
96
97static struct pnp_driver system_pnp_driver = {
98 .name = "system",
99 .id_table = pnp_dev_table,
100 .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
101 .probe = system_pnp_probe,
102 .remove = NULL,
103};
104
105static int __init pnp_system_init(void)
106{
107 return pnp_register_driver(&system_pnp_driver);
108}
109
110/**
111 * Reserve motherboard resources after PCI claim BARs,
112 * but before PCI assign resources for uninitialized PCI devices
113 */
114fs_initcall(pnp_system_init);