]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/pnp/system.c
ipv6: Check the hop limit setting in ancillary data.
[net-next-2.6.git] / drivers / pnp / system.c
CommitLineData
1da177e4
LT
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>
a8c78f7f
BH
6 * (c) Copyright 2007 Hewlett-Packard Development Company, L.P.
7 * Bjorn Helgaas <bjorn.helgaas@hp.com>
1da177e4
LT
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
17static const struct pnp_device_id pnp_dev_table[] = {
18 /* General ID for reserving resources */
9dd78466 19 {"PNP0c02", 0},
1da177e4 20 /* memory controller */
9dd78466
BH
21 {"PNP0c01", 0},
22 {"", 0}
1da177e4
LT
23};
24
b933e19d 25static void reserve_range(struct pnp_dev *dev, resource_size_t start,
9dd78466 26 resource_size_t end, int port)
1da177e4 27{
1da177e4 28 char *regionid;
b933e19d
BH
29 const char *pnpid = dev->dev.bus_id;
30 struct resource *res;
1da177e4
LT
31
32 regionid = kmalloc(16, GFP_KERNEL);
b933e19d 33 if (!regionid)
1da177e4 34 return;
b933e19d 35
1da177e4 36 snprintf(regionid, 16, "pnp %s", pnpid);
a8c78f7f 37 if (port)
9dd78466 38 res = request_region(start, end - start + 1, regionid);
a8c78f7f 39 else
9dd78466 40 res = request_mem_region(start, end - start + 1, regionid);
b933e19d 41 if (res)
1da177e4 42 res->flags &= ~IORESOURCE_BUSY;
b933e19d
BH
43 else
44 kfree(regionid);
45
1da177e4
LT
46 /*
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 */
b933e19d
BH
51 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");
1da177e4
LT
55}
56
b933e19d 57static void reserve_resources_of_dev(struct pnp_dev *dev)
1da177e4 58{
95ab3669 59 struct resource *res;
1da177e4
LT
60 int i;
61
95ab3669
BH
62 for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) {
63 if (res->flags & IORESOURCE_UNSET)
1da177e4 64 continue;
95ab3669 65 if (res->start == 0)
5859554c 66 continue; /* disabled */
95ab3669 67 if (res->start < 0x100)
1da177e4
LT
68 /*
69 * Below 0x100 is only standard PC hardware
70 * (pics, kbd, timer, dma, ...)
71 * We should not get resource conflicts there,
72 * and the kernel reserves these anyway
73 * (see arch/i386/kernel/setup.c).
74 * So, do nothing
75 */
76 continue;
95ab3669 77 if (res->end < res->start)
5859554c
BH
78 continue; /* invalid */
79
95ab3669 80 reserve_range(dev, res->start, res->end, 1);
1da177e4
LT
81 }
82
95ab3669
BH
83 for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) {
84 if (res->flags & IORESOURCE_UNSET)
a8c78f7f
BH
85 continue;
86
95ab3669 87 reserve_range(dev, res->start, res->end, 0);
a8c78f7f 88 }
1da177e4
LT
89}
90
9dd78466
BH
91static int system_pnp_probe(struct pnp_dev *dev,
92 const struct pnp_device_id *dev_id)
1da177e4
LT
93{
94 reserve_resources_of_dev(dev);
95 return 0;
96}
97
98static struct pnp_driver system_pnp_driver = {
07d4e9af 99 .name = "system",
9dd78466 100 .id_table = pnp_dev_table,
07d4e9af
BH
101 .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
102 .probe = system_pnp_probe,
1da177e4
LT
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);