mmconf-fam10h_64.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * AMD Family 10h mmconfig enablement
  3. */
  4. #include <linux/types.h>
  5. #include <linux/mm.h>
  6. #include <linux/string.h>
  7. #include <linux/pci.h>
  8. #include <linux/dmi.h>
  9. #include <asm/pci-direct.h>
  10. #include <linux/sort.h>
  11. #include <asm/io.h>
  12. #include <asm/msr.h>
  13. #include <asm/acpi.h>
  14. #include <asm/mmconfig.h>
  15. #include "../pci/pci.h"
  16. struct pci_hostbridge_probe {
  17. u32 bus;
  18. u32 slot;
  19. u32 vendor;
  20. u32 device;
  21. };
  22. static u64 __cpuinitdata fam10h_pci_mmconf_base;
  23. static int __cpuinitdata fam10h_pci_mmconf_base_status;
  24. static struct pci_hostbridge_probe pci_probes[] __cpuinitdata = {
  25. { 0, 0x18, PCI_VENDOR_ID_AMD, 0x1200 },
  26. { 0xff, 0, PCI_VENDOR_ID_AMD, 0x1200 },
  27. };
  28. struct range {
  29. u64 start;
  30. u64 end;
  31. };
  32. static int __cpuinit cmp_range(const void *x1, const void *x2)
  33. {
  34. const struct range *r1 = x1;
  35. const struct range *r2 = x2;
  36. int start1, start2;
  37. start1 = r1->start >> 32;
  38. start2 = r2->start >> 32;
  39. return start1 - start2;
  40. }
  41. /*[47:0] */
  42. /* need to avoid (0xfd<<32) and (0xfe<<32), ht used space */
  43. #define FAM10H_PCI_MMCONF_BASE (0xfcULL<<32)
  44. #define BASE_VALID(b) ((b != (0xfdULL << 32)) && (b != (0xfeULL << 32)))
  45. static void __cpuinit get_fam10h_pci_mmconf_base(void)
  46. {
  47. int i;
  48. unsigned bus;
  49. unsigned slot;
  50. int found;
  51. u64 val;
  52. u32 address;
  53. u64 tom2;
  54. u64 base = FAM10H_PCI_MMCONF_BASE;
  55. int hi_mmio_num;
  56. struct range range[8];
  57. /* only try to get setting from BSP */
  58. /* -1 or 1 */
  59. if (fam10h_pci_mmconf_base_status)
  60. return;
  61. if (!early_pci_allowed())
  62. goto fail;
  63. found = 0;
  64. for (i = 0; i < ARRAY_SIZE(pci_probes); i++) {
  65. u32 id;
  66. u16 device;
  67. u16 vendor;
  68. bus = pci_probes[i].bus;
  69. slot = pci_probes[i].slot;
  70. id = read_pci_config(bus, slot, 0, PCI_VENDOR_ID);
  71. vendor = id & 0xffff;
  72. device = (id>>16) & 0xffff;
  73. if (pci_probes[i].vendor == vendor &&
  74. pci_probes[i].device == device) {
  75. found = 1;
  76. break;
  77. }
  78. }
  79. if (!found)
  80. goto fail;
  81. /* SYS_CFG */
  82. address = MSR_K8_SYSCFG;
  83. rdmsrl(address, val);
  84. /* TOP_MEM2 is not enabled? */
  85. if (!(val & (1<<21))) {
  86. tom2 = 0;
  87. } else {
  88. /* TOP_MEM2 */
  89. address = MSR_K8_TOP_MEM2;
  90. rdmsrl(address, val);
  91. tom2 = val & (0xffffULL<<32);
  92. }
  93. if (base <= tom2)
  94. base = tom2 + (1ULL<<32);
  95. /*
  96. * need to check if the range is in the high mmio range that is
  97. * above 4G
  98. */
  99. hi_mmio_num = 0;
  100. for (i = 0; i < 8; i++) {
  101. u32 reg;
  102. u64 start;
  103. u64 end;
  104. reg = read_pci_config(bus, slot, 1, 0x80 + (i << 3));
  105. if (!(reg & 3))
  106. continue;
  107. start = (((u64)reg) << 8) & (0xffULL << 32); /* 39:16 on 31:8*/
  108. reg = read_pci_config(bus, slot, 1, 0x84 + (i << 3));
  109. end = (((u64)reg) << 8) & (0xffULL << 32); /* 39:16 on 31:8*/
  110. if (!end)
  111. continue;
  112. range[hi_mmio_num].start = start;
  113. range[hi_mmio_num].end = end;
  114. hi_mmio_num++;
  115. }
  116. if (!hi_mmio_num)
  117. goto out;
  118. /* sort the range */
  119. sort(range, hi_mmio_num, sizeof(struct range), cmp_range, NULL);
  120. if (range[hi_mmio_num - 1].end < base)
  121. goto out;
  122. if (range[0].start > base)
  123. goto out;
  124. /* need to find one window */
  125. base = range[0].start - (1ULL << 32);
  126. if ((base > tom2) && BASE_VALID(base))
  127. goto out;
  128. base = range[hi_mmio_num - 1].end + (1ULL << 32);
  129. if ((base > tom2) && BASE_VALID(base))
  130. goto out;
  131. /* need to find window between ranges */
  132. if (hi_mmio_num > 1)
  133. for (i = 0; i < hi_mmio_num - 1; i++) {
  134. if (range[i + 1].start > (range[i].end + (1ULL << 32))) {
  135. base = range[i].end + (1ULL << 32);
  136. if ((base > tom2) && BASE_VALID(base))
  137. goto out;
  138. }
  139. }
  140. fail:
  141. fam10h_pci_mmconf_base_status = -1;
  142. return;
  143. out:
  144. fam10h_pci_mmconf_base = base;
  145. fam10h_pci_mmconf_base_status = 1;
  146. }
  147. void __cpuinit fam10h_check_enable_mmcfg(void)
  148. {
  149. u64 val;
  150. u32 address;
  151. if (!(pci_probe & PCI_CHECK_ENABLE_AMD_MMCONF))
  152. return;
  153. address = MSR_FAM10H_MMIO_CONF_BASE;
  154. rdmsrl(address, val);
  155. /* try to make sure that AP's setting is identical to BSP setting */
  156. if (val & FAM10H_MMIO_CONF_ENABLE) {
  157. unsigned busnbits;
  158. busnbits = (val >> FAM10H_MMIO_CONF_BUSRANGE_SHIFT) &
  159. FAM10H_MMIO_CONF_BUSRANGE_MASK;
  160. /* only trust the one handle 256 buses, if acpi=off */
  161. if (!acpi_pci_disabled || busnbits >= 8) {
  162. u64 base;
  163. base = val & (0xffffULL << 32);
  164. if (fam10h_pci_mmconf_base_status <= 0) {
  165. fam10h_pci_mmconf_base = base;
  166. fam10h_pci_mmconf_base_status = 1;
  167. return;
  168. } else if (fam10h_pci_mmconf_base == base)
  169. return;
  170. }
  171. }
  172. /*
  173. * if it is not enabled, try to enable it and assume only one segment
  174. * with 256 buses
  175. */
  176. get_fam10h_pci_mmconf_base();
  177. if (fam10h_pci_mmconf_base_status <= 0)
  178. return;
  179. printk(KERN_INFO "Enable MMCONFIG on AMD Family 10h\n");
  180. val &= ~((FAM10H_MMIO_CONF_BASE_MASK<<FAM10H_MMIO_CONF_BASE_SHIFT) |
  181. (FAM10H_MMIO_CONF_BUSRANGE_MASK<<FAM10H_MMIO_CONF_BUSRANGE_SHIFT));
  182. val |= fam10h_pci_mmconf_base | (8 << FAM10H_MMIO_CONF_BUSRANGE_SHIFT) |
  183. FAM10H_MMIO_CONF_ENABLE;
  184. wrmsrl(address, val);
  185. }
  186. static int __devinit set_check_enable_amd_mmconf(const struct dmi_system_id *d)
  187. {
  188. pci_probe |= PCI_CHECK_ENABLE_AMD_MMCONF;
  189. return 0;
  190. }
  191. static struct dmi_system_id __devinitdata mmconf_dmi_table[] = {
  192. {
  193. .callback = set_check_enable_amd_mmconf,
  194. .ident = "Sun Microsystems Machine",
  195. .matches = {
  196. DMI_MATCH(DMI_SYS_VENDOR, "Sun Microsystems"),
  197. },
  198. },
  199. {}
  200. };
  201. void __cpuinit check_enable_amd_mmconf_dmi(void)
  202. {
  203. dmi_check_system(mmconf_dmi_table);
  204. }