bus_numa.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #include <linux/init.h>
  2. #include <linux/pci.h>
  3. #include <linux/range.h>
  4. #include "bus_numa.h"
  5. LIST_HEAD(pci_root_infos);
  6. static struct pci_root_info *x86_find_pci_root_info(int bus)
  7. {
  8. struct pci_root_info *info;
  9. if (list_empty(&pci_root_infos))
  10. return NULL;
  11. list_for_each_entry(info, &pci_root_infos, list)
  12. if (info->busn.start == bus)
  13. return info;
  14. return NULL;
  15. }
  16. void x86_pci_root_bus_resources(int bus, struct list_head *resources)
  17. {
  18. struct pci_root_info *info = x86_find_pci_root_info(bus);
  19. struct pci_root_res *root_res;
  20. struct pci_host_bridge_window *window;
  21. bool found = false;
  22. if (!info)
  23. goto default_resources;
  24. printk(KERN_DEBUG "PCI: root bus %02x: hardware-probed resources\n",
  25. bus);
  26. /* already added by acpi ? */
  27. list_for_each_entry(window, resources, list)
  28. if (window->res->flags & IORESOURCE_BUS) {
  29. found = true;
  30. break;
  31. }
  32. if (!found)
  33. pci_add_resource(resources, &info->busn);
  34. list_for_each_entry(root_res, &info->resources, list) {
  35. struct resource *res;
  36. struct resource *root;
  37. res = &root_res->res;
  38. pci_add_resource(resources, res);
  39. if (res->flags & IORESOURCE_IO)
  40. root = &ioport_resource;
  41. else
  42. root = &iomem_resource;
  43. insert_resource(root, res);
  44. }
  45. return;
  46. default_resources:
  47. /*
  48. * We don't have any host bridge aperture information from the
  49. * "native host bridge drivers," e.g., amd_bus or broadcom_bus,
  50. * so fall back to the defaults historically used by pci_create_bus().
  51. */
  52. printk(KERN_DEBUG "PCI: root bus %02x: using default resources\n", bus);
  53. pci_add_resource(resources, &ioport_resource);
  54. pci_add_resource(resources, &iomem_resource);
  55. }
  56. struct pci_root_info __init *alloc_pci_root_info(int bus_min, int bus_max,
  57. int node, int link)
  58. {
  59. struct pci_root_info *info;
  60. info = kzalloc(sizeof(*info), GFP_KERNEL);
  61. if (!info)
  62. return info;
  63. sprintf(info->name, "PCI Bus #%02x", bus_min);
  64. INIT_LIST_HEAD(&info->resources);
  65. info->busn.name = info->name;
  66. info->busn.start = bus_min;
  67. info->busn.end = bus_max;
  68. info->busn.flags = IORESOURCE_BUS;
  69. info->node = node;
  70. info->link = link;
  71. list_add_tail(&info->list, &pci_root_infos);
  72. return info;
  73. }
  74. void __devinit update_res(struct pci_root_info *info, resource_size_t start,
  75. resource_size_t end, unsigned long flags, int merge)
  76. {
  77. struct resource *res;
  78. struct pci_root_res *root_res;
  79. if (start > end)
  80. return;
  81. if (start == MAX_RESOURCE)
  82. return;
  83. if (!merge)
  84. goto addit;
  85. /* try to merge it with old one */
  86. list_for_each_entry(root_res, &info->resources, list) {
  87. resource_size_t final_start, final_end;
  88. resource_size_t common_start, common_end;
  89. res = &root_res->res;
  90. if (res->flags != flags)
  91. continue;
  92. common_start = max(res->start, start);
  93. common_end = min(res->end, end);
  94. if (common_start > common_end + 1)
  95. continue;
  96. final_start = min(res->start, start);
  97. final_end = max(res->end, end);
  98. res->start = final_start;
  99. res->end = final_end;
  100. return;
  101. }
  102. addit:
  103. /* need to add that */
  104. root_res = kzalloc(sizeof(*root_res), GFP_KERNEL);
  105. if (!root_res)
  106. return;
  107. res = &root_res->res;
  108. res->name = info->name;
  109. res->flags = flags;
  110. res->start = start;
  111. res->end = end;
  112. list_add_tail(&root_res->list, &info->resources);
  113. }