Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Bjorn Helgaas | a8c78f7 | 2007-01-18 16:43:27 -0700 | [diff] [blame] | 6 | * (c) Copyright 2007 Hewlett-Packard Development Company, L.P. |
| 7 | * Bjorn Helgaas <bjorn.helgaas@hp.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 17 | static const struct pnp_device_id pnp_dev_table[] = { |
| 18 | /* General ID for reserving resources */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 19 | {"PNP0c02", 0}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | /* memory controller */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 21 | {"PNP0c01", 0}, |
| 22 | {"", 0} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | }; |
| 24 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 25 | static void reserve_range(const char *pnpid, resource_size_t start, |
| 26 | resource_size_t end, int port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | { |
| 28 | struct resource *res; |
| 29 | char *regionid; |
| 30 | |
| 31 | regionid = kmalloc(16, GFP_KERNEL); |
Bjorn Helgaas | 5859554 | 2007-01-18 16:43:46 -0700 | [diff] [blame] | 32 | if (regionid == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | return; |
| 34 | snprintf(regionid, 16, "pnp %s", pnpid); |
Bjorn Helgaas | a8c78f7 | 2007-01-18 16:43:27 -0700 | [diff] [blame] | 35 | if (port) |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 36 | res = request_region(start, end - start + 1, regionid); |
Bjorn Helgaas | a8c78f7 | 2007-01-18 16:43:27 -0700 | [diff] [blame] | 37 | else |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 38 | res = request_mem_region(start, end - start + 1, regionid); |
Bjorn Helgaas | 5859554 | 2007-01-18 16:43:46 -0700 | [diff] [blame] | 39 | if (res == NULL) |
| 40 | kfree(regionid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | else |
| 42 | res->flags &= ~IORESOURCE_BUSY; |
| 43 | /* |
| 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. |
| 47 | */ |
| 48 | printk(KERN_INFO |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 49 | "pnp: %s: %s range 0x%llx-0x%llx %s reserved\n", |
| 50 | pnpid, port ? "ioport" : "iomem", |
| 51 | (unsigned long long)start, (unsigned long long)end, |
| 52 | NULL != res ? "has been" : "could not be"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Petr Vandrovec | a2b091d | 2007-04-01 23:49:46 -0700 | [diff] [blame] | 55 | static void reserve_resources_of_dev(const struct pnp_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | { |
| 57 | int i; |
| 58 | |
Bjorn Helgaas | 5859554 | 2007-01-18 16:43:46 -0700 | [diff] [blame] | 59 | for (i = 0; i < PNP_MAX_PORT; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | if (!pnp_port_valid(dev, i)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | continue; |
| 62 | if (pnp_port_start(dev, i) == 0) |
Bjorn Helgaas | 5859554 | 2007-01-18 16:43:46 -0700 | [diff] [blame] | 63 | continue; /* disabled */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | if (pnp_port_start(dev, i) < 0x100) |
| 65 | /* |
| 66 | * Below 0x100 is only standard PC hardware |
| 67 | * (pics, kbd, timer, dma, ...) |
| 68 | * We should not get resource conflicts there, |
| 69 | * and the kernel reserves these anyway |
| 70 | * (see arch/i386/kernel/setup.c). |
| 71 | * So, do nothing |
| 72 | */ |
| 73 | continue; |
| 74 | if (pnp_port_end(dev, i) < pnp_port_start(dev, i)) |
Bjorn Helgaas | 5859554 | 2007-01-18 16:43:46 -0700 | [diff] [blame] | 75 | continue; /* invalid */ |
| 76 | |
| 77 | reserve_range(dev->dev.bus_id, pnp_port_start(dev, i), |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 78 | pnp_port_end(dev, i), 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Bjorn Helgaas | a8c78f7 | 2007-01-18 16:43:27 -0700 | [diff] [blame] | 81 | for (i = 0; i < PNP_MAX_MEM; i++) { |
| 82 | if (!pnp_mem_valid(dev, i)) |
| 83 | continue; |
| 84 | |
| 85 | reserve_range(dev->dev.bus_id, pnp_mem_start(dev, i), |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 86 | pnp_mem_end(dev, i), 0); |
Bjorn Helgaas | a8c78f7 | 2007-01-18 16:43:27 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | return; |
| 90 | } |
| 91 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 92 | static int system_pnp_probe(struct pnp_dev *dev, |
| 93 | const struct pnp_device_id *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | { |
| 95 | reserve_resources_of_dev(dev); |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | static struct pnp_driver system_pnp_driver = { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame^] | 100 | .name = "system", |
| 101 | .id_table = pnp_dev_table, |
| 102 | .flags = PNP_DRIVER_RES_DO_NOT_CHANGE, |
| 103 | .probe = system_pnp_probe, |
| 104 | .remove = NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | static int __init pnp_system_init(void) |
| 108 | { |
| 109 | return pnp_register_driver(&system_pnp_driver); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Reserve motherboard resources after PCI claim BARs, |
| 114 | * but before PCI assign resources for uninitialized PCI devices |
| 115 | */ |
| 116 | fs_initcall(pnp_system_init); |