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(struct pnp_dev *dev, resource_size_t start,
  23. resource_size_t end, int port)
  24. {
  25. char *regionid;
  26. const char *pnpid = dev_name(&dev->dev);
  27. struct resource *res;
  28. regionid = kmalloc(16, GFP_KERNEL);
  29. if (!regionid)
  30. return;
  31. snprintf(regionid, 16, "pnp %s", pnpid);
  32. if (port)
  33. res = request_region(start, end - start + 1, regionid);
  34. else
  35. res = request_mem_region(start, end - start + 1, regionid);
  36. if (res)
  37. res->flags &= ~IORESOURCE_BUSY;
  38. else
  39. kfree(regionid);
  40. /*
  41. * Failures at this point are usually harmless. pci quirks for
  42. * example do reserve stuff they know about too, so we may well
  43. * have double reservations.
  44. */
  45. dev_info(&dev->dev, "%s range 0x%llx-0x%llx %s reserved\n",
  46. port ? "ioport" : "iomem",
  47. (unsigned long long) start, (unsigned long long) end,
  48. res ? "has been" : "could not be");
  49. }
  50. static void reserve_resources_of_dev(struct pnp_dev *dev)
  51. {
  52. struct resource *res;
  53. int i;
  54. for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) {
  55. if (res->flags & IORESOURCE_DISABLED)
  56. continue;
  57. if (res->start == 0)
  58. continue; /* disabled */
  59. if (res->start < 0x100)
  60. /*
  61. * Below 0x100 is only standard PC hardware
  62. * (pics, kbd, timer, dma, ...)
  63. * We should not get resource conflicts there,
  64. * and the kernel reserves these anyway
  65. * (see arch/i386/kernel/setup.c).
  66. * So, do nothing
  67. */
  68. continue;
  69. if (res->end < res->start)
  70. continue; /* invalid */
  71. reserve_range(dev, res->start, res->end, 1);
  72. }
  73. for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) {
  74. if (res->flags & IORESOURCE_DISABLED)
  75. continue;
  76. reserve_range(dev, res->start, res->end, 0);
  77. }
  78. }
  79. static int system_pnp_probe(struct pnp_dev *dev,
  80. 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. };
  91. static int __init pnp_system_init(void)
  92. {
  93. return pnp_register_driver(&system_pnp_driver);
  94. }
  95. /**
  96. * Reserve motherboard resources after PCI claim BARs,
  97. * but before PCI assign resources for uninitialized PCI devices
  98. */
  99. fs_initcall(pnp_system_init);