blob: 55c4563986b38aebc36b158eb7c9a649d7105d5c [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 */
Bjorn Helgaas9dd78462007-07-26 10:41:20 -070019 {"PNP0c02", 0},
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 /* memory controller */
Bjorn Helgaas9dd78462007-07-26 10:41:20 -070021 {"PNP0c01", 0},
22 {"", 0}
Linus Torvalds1da177e2005-04-16 15:20:36 -070023};
24
Bjorn Helgaasb933e192007-10-16 23:31:11 -070025static void reserve_range(struct pnp_dev *dev, resource_size_t start,
Bjorn Helgaas9dd78462007-07-26 10:41:20 -070026 resource_size_t end, int port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070027{
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 char *regionid;
Bjorn Helgaasb933e192007-10-16 23:31:11 -070029 const char *pnpid = dev->dev.bus_id;
30 struct resource *res;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32 regionid = kmalloc(16, GFP_KERNEL);
Bjorn Helgaasb933e192007-10-16 23:31:11 -070033 if (!regionid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 return;
Bjorn Helgaasb933e192007-10-16 23:31:11 -070035
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 snprintf(regionid, 16, "pnp %s", pnpid);
Bjorn Helgaasa8c78f72007-01-18 16:43:27 -070037 if (port)
Bjorn Helgaas9dd78462007-07-26 10:41:20 -070038 res = request_region(start, end - start + 1, regionid);
Bjorn Helgaasa8c78f72007-01-18 16:43:27 -070039 else
Bjorn Helgaas9dd78462007-07-26 10:41:20 -070040 res = request_mem_region(start, end - start + 1, regionid);
Bjorn Helgaasb933e192007-10-16 23:31:11 -070041 if (res)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 res->flags &= ~IORESOURCE_BUSY;
Bjorn Helgaasb933e192007-10-16 23:31:11 -070043 else
44 kfree(regionid);
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 /*
47 * Failures at this point are usually harmless. pci quirks for
48 * example do reserve stuff they know about too, so we may well
49 * have double reservations.
50 */
Bjorn Helgaasb933e192007-10-16 23:31:11 -070051 dev_info(&dev->dev, "%s range 0x%llx-0x%llx %s reserved\n",
52 port ? "ioport" : "iomem",
53 (unsigned long long) start, (unsigned long long) end,
54 res ? "has been" : "could not be");
Linus Torvalds1da177e2005-04-16 15:20:36 -070055}
56
Bjorn Helgaasb933e192007-10-16 23:31:11 -070057static void reserve_resources_of_dev(struct pnp_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
59 int i;
60
Bjorn Helgaas58595542007-01-18 16:43:46 -070061 for (i = 0; i < PNP_MAX_PORT; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 if (!pnp_port_valid(dev, i))
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 continue;
64 if (pnp_port_start(dev, i) == 0)
Bjorn Helgaas58595542007-01-18 16:43:46 -070065 continue; /* disabled */
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 if (pnp_port_start(dev, i) < 0x100)
67 /*
68 * Below 0x100 is only standard PC hardware
69 * (pics, kbd, timer, dma, ...)
70 * We should not get resource conflicts there,
71 * and the kernel reserves these anyway
72 * (see arch/i386/kernel/setup.c).
73 * So, do nothing
74 */
75 continue;
76 if (pnp_port_end(dev, i) < pnp_port_start(dev, i))
Bjorn Helgaas58595542007-01-18 16:43:46 -070077 continue; /* invalid */
78
Bjorn Helgaasb933e192007-10-16 23:31:11 -070079 reserve_range(dev, pnp_port_start(dev, i),
Bjorn Helgaas9dd78462007-07-26 10:41:20 -070080 pnp_port_end(dev, i), 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 }
82
Bjorn Helgaasa8c78f72007-01-18 16:43:27 -070083 for (i = 0; i < PNP_MAX_MEM; i++) {
84 if (!pnp_mem_valid(dev, i))
85 continue;
86
Bjorn Helgaasb933e192007-10-16 23:31:11 -070087 reserve_range(dev, pnp_mem_start(dev, i),
Bjorn Helgaas9dd78462007-07-26 10:41:20 -070088 pnp_mem_end(dev, i), 0);
Bjorn Helgaasa8c78f72007-01-18 16:43:27 -070089 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
Bjorn Helgaas9dd78462007-07-26 10:41:20 -070092static int system_pnp_probe(struct pnp_dev *dev,
93 const struct pnp_device_id *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094{
95 reserve_resources_of_dev(dev);
96 return 0;
97}
98
99static struct pnp_driver system_pnp_driver = {
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700100 .name = "system",
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700101 .id_table = pnp_dev_table,
Bjorn Helgaas07d4e9a2007-07-26 10:41:21 -0700102 .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
103 .probe = system_pnp_probe,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104};
105
106static int __init pnp_system_init(void)
107{
108 return pnp_register_driver(&system_pnp_driver);
109}
110
111/**
112 * Reserve motherboard resources after PCI claim BARs,
113 * but before PCI assign resources for uninitialized PCI devices
114 */
115fs_initcall(pnp_system_init);