system.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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>
  6. * (c) Copyright 2007 Hewlett-Packard Development Company, L.P.
  7. * Bjorn Helgaas <bjorn.helgaas@hp.com>
  8. */
  9. #include <linux/pnp.h>
  10. #include <linux/device.h>
  11. #include <linux/init.h>
  12. #include <linux/slab.h>
  13. #include <linux/kernel.h>
  14. #include <linux/ioport.h>
  15. static const struct pnp_device_id pnp_dev_table[] = {
  16. /* General ID for reserving resources */
  17. { "PNP0c02", 0 },
  18. /* memory controller */
  19. { "PNP0c01", 0 },
  20. { "", 0 }
  21. };
  22. static void reserve_range(const char *pnpid, resource_size_t start, resource_size_t end, int port)
  23. {
  24. struct resource *res;
  25. char *regionid;
  26. regionid = kmalloc(16, GFP_KERNEL);
  27. if (regionid == NULL)
  28. return;
  29. snprintf(regionid, 16, "pnp %s", pnpid);
  30. if (port)
  31. res = request_region(start, end-start+1, regionid);
  32. else
  33. res = request_mem_region(start, end-start+1, regionid);
  34. if (res == NULL)
  35. kfree(regionid);
  36. else
  37. res->flags &= ~IORESOURCE_BUSY;
  38. /*
  39. * Failures at this point are usually harmless. pci quirks for
  40. * example do reserve stuff they know about too, so we may well
  41. * have double reservations.
  42. */
  43. printk(KERN_INFO
  44. "pnp: %s: %s range 0x%llx-0x%llx %s reserved\n",
  45. pnpid, port ? "ioport" : "iomem",
  46. (unsigned long long)start, (unsigned long long)end,
  47. NULL != res ? "has been" : "could not be");
  48. }
  49. static void reserve_resources_of_dev(const struct pnp_dev *dev)
  50. {
  51. int i;
  52. for (i = 0; i < PNP_MAX_PORT; i++) {
  53. if (!pnp_port_valid(dev, i))
  54. continue;
  55. if (pnp_port_start(dev, i) == 0)
  56. continue; /* disabled */
  57. if (pnp_port_start(dev, i) < 0x100)
  58. /*
  59. * Below 0x100 is only standard PC hardware
  60. * (pics, kbd, timer, dma, ...)
  61. * We should not get resource conflicts there,
  62. * and the kernel reserves these anyway
  63. * (see arch/i386/kernel/setup.c).
  64. * So, do nothing
  65. */
  66. continue;
  67. if (pnp_port_end(dev, i) < pnp_port_start(dev, i))
  68. continue; /* invalid */
  69. reserve_range(dev->dev.bus_id, pnp_port_start(dev, i),
  70. pnp_port_end(dev, i), 1);
  71. }
  72. for (i = 0; i < PNP_MAX_MEM; i++) {
  73. if (!pnp_mem_valid(dev, i))
  74. continue;
  75. reserve_range(dev->dev.bus_id, pnp_mem_start(dev, i),
  76. pnp_mem_end(dev, i), 0);
  77. }
  78. return;
  79. }
  80. static int system_pnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev_id)
  81. {
  82. reserve_resources_of_dev(dev);
  83. return 0;
  84. }
  85. static struct pnp_driver system_pnp_driver = {
  86. .name = "system",
  87. .id_table = pnp_dev_table,
  88. .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
  89. .probe = system_pnp_probe,
  90. .remove = NULL,
  91. };
  92. static int __init pnp_system_init(void)
  93. {
  94. return pnp_register_driver(&system_pnp_driver);
  95. }
  96. /**
  97. * Reserve motherboard resources after PCI claim BARs,
  98. * but before PCI assign resources for uninitialized PCI devices
  99. */
  100. fs_initcall(pnp_system_init);