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 | b933e19 | 2007-10-16 23:31:11 -0700 | [diff] [blame] | 25 | static void reserve_range(struct pnp_dev *dev, resource_size_t start, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 26 | resource_size_t end, int port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | char *regionid; |
Bjorn Helgaas | b933e19 | 2007-10-16 23:31:11 -0700 | [diff] [blame] | 29 | const char *pnpid = dev->dev.bus_id; |
| 30 | struct resource *res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
| 32 | regionid = kmalloc(16, GFP_KERNEL); |
Bjorn Helgaas | b933e19 | 2007-10-16 23:31:11 -0700 | [diff] [blame] | 33 | if (!regionid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | return; |
Bjorn Helgaas | b933e19 | 2007-10-16 23:31:11 -0700 | [diff] [blame] | 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | snprintf(regionid, 16, "pnp %s", pnpid); |
Bjorn Helgaas | a8c78f7 | 2007-01-18 16:43:27 -0700 | [diff] [blame] | 37 | if (port) |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 38 | res = request_region(start, end - start + 1, regionid); |
Bjorn Helgaas | a8c78f7 | 2007-01-18 16:43:27 -0700 | [diff] [blame] | 39 | else |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 40 | res = request_mem_region(start, end - start + 1, regionid); |
Bjorn Helgaas | b933e19 | 2007-10-16 23:31:11 -0700 | [diff] [blame] | 41 | if (res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | res->flags &= ~IORESOURCE_BUSY; |
Bjorn Helgaas | b933e19 | 2007-10-16 23:31:11 -0700 | [diff] [blame] | 43 | else |
| 44 | kfree(regionid); |
| 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | */ |
Bjorn Helgaas | b933e19 | 2007-10-16 23:31:11 -0700 | [diff] [blame] | 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"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Bjorn Helgaas | b933e19 | 2007-10-16 23:31:11 -0700 | [diff] [blame] | 57 | static void reserve_resources_of_dev(struct pnp_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | { |
Bjorn Helgaas | 95ab366 | 2008-04-28 16:34:26 -0600 | [diff] [blame] | 59 | struct resource *res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | int i; |
| 61 | |
Bjorn Helgaas | 95ab366 | 2008-04-28 16:34:26 -0600 | [diff] [blame] | 62 | for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) { |
Bjorn Helgaas | aee3ad8 | 2008-06-27 16:56:57 -0600 | [diff] [blame^] | 63 | if (res->flags & IORESOURCE_DISABLED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | continue; |
Bjorn Helgaas | 95ab366 | 2008-04-28 16:34:26 -0600 | [diff] [blame] | 65 | if (res->start == 0) |
Bjorn Helgaas | 5859554 | 2007-01-18 16:43:46 -0700 | [diff] [blame] | 66 | continue; /* disabled */ |
Bjorn Helgaas | 95ab366 | 2008-04-28 16:34:26 -0600 | [diff] [blame] | 67 | if (res->start < 0x100) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
Bjorn Helgaas | 95ab366 | 2008-04-28 16:34:26 -0600 | [diff] [blame] | 77 | if (res->end < res->start) |
Bjorn Helgaas | 5859554 | 2007-01-18 16:43:46 -0700 | [diff] [blame] | 78 | continue; /* invalid */ |
| 79 | |
Bjorn Helgaas | 95ab366 | 2008-04-28 16:34:26 -0600 | [diff] [blame] | 80 | reserve_range(dev, res->start, res->end, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Bjorn Helgaas | 95ab366 | 2008-04-28 16:34:26 -0600 | [diff] [blame] | 83 | for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) { |
Bjorn Helgaas | aee3ad8 | 2008-06-27 16:56:57 -0600 | [diff] [blame^] | 84 | if (res->flags & IORESOURCE_DISABLED) |
Bjorn Helgaas | a8c78f7 | 2007-01-18 16:43:27 -0700 | [diff] [blame] | 85 | continue; |
| 86 | |
Bjorn Helgaas | 95ab366 | 2008-04-28 16:34:26 -0600 | [diff] [blame] | 87 | reserve_range(dev, res->start, res->end, 0); |
Bjorn Helgaas | a8c78f7 | 2007-01-18 16:43:27 -0700 | [diff] [blame] | 88 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 91 | static int system_pnp_probe(struct pnp_dev *dev, |
| 92 | const struct pnp_device_id *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | { |
| 94 | reserve_resources_of_dev(dev); |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | static struct pnp_driver system_pnp_driver = { |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 99 | .name = "system", |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 100 | .id_table = pnp_dev_table, |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 101 | .flags = PNP_DRIVER_RES_DO_NOT_CHANGE, |
| 102 | .probe = system_pnp_probe, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | static 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 | */ |
| 114 | fs_initcall(pnp_system_init); |