bus_numa.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include <linux/init.h>
  2. #include <linux/pci.h>
  3. #include "bus_numa.h"
  4. int pci_root_num;
  5. struct pci_root_info pci_root_info[PCI_ROOT_NR];
  6. int found_all_numa_early;
  7. void x86_pci_root_bus_res_quirks(struct pci_bus *b)
  8. {
  9. int i;
  10. int j;
  11. struct pci_root_info *info;
  12. /* don't go for it if _CRS is used already */
  13. if (b->resource[0] != &ioport_resource ||
  14. b->resource[1] != &iomem_resource)
  15. return;
  16. if (!pci_root_num)
  17. return;
  18. /* for amd, if only one root bus, don't need to do anything */
  19. if (pci_root_num < 2 && found_all_numa_early)
  20. return;
  21. for (i = 0; i < pci_root_num; i++) {
  22. if (pci_root_info[i].bus_min == b->number)
  23. break;
  24. }
  25. if (i == pci_root_num)
  26. return;
  27. printk(KERN_DEBUG "PCI: peer root bus %02x res updated from pci conf\n",
  28. b->number);
  29. info = &pci_root_info[i];
  30. for (j = 0; j < info->res_num; j++) {
  31. struct resource *res;
  32. struct resource *root;
  33. res = &info->res[j];
  34. b->resource[j] = res;
  35. if (res->flags & IORESOURCE_IO)
  36. root = &ioport_resource;
  37. else
  38. root = &iomem_resource;
  39. insert_resource(root, res);
  40. }
  41. }
  42. void __devinit update_res(struct pci_root_info *info, size_t start,
  43. size_t end, unsigned long flags, int merge)
  44. {
  45. int i;
  46. struct resource *res;
  47. if (start > end)
  48. return;
  49. if (!merge)
  50. goto addit;
  51. /* try to merge it with old one */
  52. for (i = 0; i < info->res_num; i++) {
  53. size_t final_start, final_end;
  54. size_t common_start, common_end;
  55. res = &info->res[i];
  56. if (res->flags != flags)
  57. continue;
  58. common_start = max((size_t)res->start, start);
  59. common_end = min((size_t)res->end, end);
  60. if (common_start > common_end + 1)
  61. continue;
  62. final_start = min((size_t)res->start, start);
  63. final_end = max((size_t)res->end, end);
  64. res->start = final_start;
  65. res->end = final_end;
  66. return;
  67. }
  68. addit:
  69. /* need to add that */
  70. if (info->res_num >= RES_NUM)
  71. return;
  72. res = &info->res[info->res_num];
  73. res->name = info->name;
  74. res->flags = flags;
  75. res->start = start;
  76. res->end = end;
  77. res->child = NULL;
  78. info->res_num++;
  79. }