bus_numa.c 3.3 KB

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