system.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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, struct resource *r, int port)
  23. {
  24. char *regionid;
  25. const char *pnpid = dev_name(&dev->dev);
  26. resource_size_t start = r->start, end = r->end;
  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, "%pR %s reserved\n", r,
  46. res ? "has been" : "could not be");
  47. }
  48. static void reserve_resources_of_dev(struct pnp_dev *dev)
  49. {
  50. struct resource *res;
  51. int i;
  52. for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) {
  53. if (res->flags & IORESOURCE_DISABLED)
  54. continue;
  55. if (res->start == 0)
  56. continue; /* disabled */
  57. if (res->start < 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 (res->end < res->start)
  68. continue; /* invalid */
  69. reserve_range(dev, res, 1);
  70. }
  71. for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) {
  72. if (res->flags & IORESOURCE_DISABLED)
  73. continue;
  74. reserve_range(dev, res, 0);
  75. }
  76. }
  77. static int system_pnp_probe(struct pnp_dev *dev,
  78. const struct pnp_device_id *dev_id)
  79. {
  80. reserve_resources_of_dev(dev);
  81. return 0;
  82. }
  83. static struct pnp_driver system_pnp_driver = {
  84. .name = "system",
  85. .id_table = pnp_dev_table,
  86. .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
  87. .probe = system_pnp_probe,
  88. };
  89. static int __init pnp_system_init(void)
  90. {
  91. return pnp_register_driver(&system_pnp_driver);
  92. }
  93. /**
  94. * Reserve motherboard resources after PCI claim BARs,
  95. * but before PCI assign resources for uninitialized PCI devices
  96. */
  97. fs_initcall(pnp_system_init);