bus_numa.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include <linux/init.h>
  2. #include <linux/pci.h>
  3. #include <linux/range.h>
  4. #include "bus_numa.h"
  5. int pci_root_num;
  6. struct pci_root_info pci_root_info[PCI_ROOT_NR];
  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 (i = 0; i < pci_root_num; i++) {
  19. if (pci_root_info[i].bus_min == b->number)
  20. break;
  21. }
  22. if (i == pci_root_num)
  23. return;
  24. printk(KERN_DEBUG "PCI: peer root bus %02x res updated from pci conf\n",
  25. b->number);
  26. pci_bus_remove_resources(b);
  27. info = &pci_root_info[i];
  28. for (j = 0; j < info->res_num; j++) {
  29. struct resource *res;
  30. struct resource *root;
  31. res = &info->res[j];
  32. pci_bus_add_resource(b, res, 0);
  33. if (res->flags & IORESOURCE_IO)
  34. root = &ioport_resource;
  35. else
  36. root = &iomem_resource;
  37. insert_resource(root, res);
  38. }
  39. }
  40. void __devinit update_res(struct pci_root_info *info, resource_size_t start,
  41. resource_size_t end, unsigned long flags, int merge)
  42. {
  43. int i;
  44. struct resource *res;
  45. if (start > end)
  46. return;
  47. if (start == MAX_RESOURCE)
  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. resource_size_t final_start, final_end;
  54. resource_size_t common_start, common_end;
  55. res = &info->res[i];
  56. if (res->flags != flags)
  57. continue;
  58. common_start = max(res->start, start);
  59. common_end = min(res->end, end);
  60. if (common_start > common_end + 1)
  61. continue;
  62. final_start = min(res->start, start);
  63. final_end = max(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. }