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