common.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. /*
  2. * Low-Level PCI Support for PC
  3. *
  4. * (c) 1999--2000 Martin Mares <mj@ucw.cz>
  5. */
  6. #include <linux/sched.h>
  7. #include <linux/pci.h>
  8. #include <linux/ioport.h>
  9. #include <linux/init.h>
  10. #include <linux/dmi.h>
  11. #include <asm/acpi.h>
  12. #include <asm/segment.h>
  13. #include <asm/io.h>
  14. #include <asm/smp.h>
  15. #include "pci.h"
  16. unsigned int pci_probe = PCI_PROBE_BIOS | PCI_PROBE_CONF1 | PCI_PROBE_CONF2 |
  17. PCI_PROBE_MMCONF;
  18. static int pci_bf_sort;
  19. int pci_routeirq;
  20. int noioapicquirk;
  21. int noioapicreroute = 1;
  22. int pcibios_last_bus = -1;
  23. unsigned long pirq_table_addr;
  24. struct pci_bus *pci_root_bus;
  25. struct pci_raw_ops *raw_pci_ops;
  26. struct pci_raw_ops *raw_pci_ext_ops;
  27. int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
  28. int reg, int len, u32 *val)
  29. {
  30. if (reg < 256 && raw_pci_ops)
  31. return raw_pci_ops->read(domain, bus, devfn, reg, len, val);
  32. if (raw_pci_ext_ops)
  33. return raw_pci_ext_ops->read(domain, bus, devfn, reg, len, val);
  34. return -EINVAL;
  35. }
  36. int raw_pci_write(unsigned int domain, unsigned int bus, unsigned int devfn,
  37. int reg, int len, u32 val)
  38. {
  39. if (reg < 256 && raw_pci_ops)
  40. return raw_pci_ops->write(domain, bus, devfn, reg, len, val);
  41. if (raw_pci_ext_ops)
  42. return raw_pci_ext_ops->write(domain, bus, devfn, reg, len, val);
  43. return -EINVAL;
  44. }
  45. static int pci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
  46. {
  47. return raw_pci_read(pci_domain_nr(bus), bus->number,
  48. devfn, where, size, value);
  49. }
  50. static int pci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
  51. {
  52. return raw_pci_write(pci_domain_nr(bus), bus->number,
  53. devfn, where, size, value);
  54. }
  55. struct pci_ops pci_root_ops = {
  56. .read = pci_read,
  57. .write = pci_write,
  58. };
  59. /*
  60. * legacy, numa, and acpi all want to call pcibios_scan_root
  61. * from their initcalls. This flag prevents that.
  62. */
  63. int pcibios_scanned;
  64. /*
  65. * This interrupt-safe spinlock protects all accesses to PCI
  66. * configuration space.
  67. */
  68. DEFINE_SPINLOCK(pci_config_lock);
  69. static int __devinit can_skip_ioresource_align(const struct dmi_system_id *d)
  70. {
  71. pci_probe |= PCI_CAN_SKIP_ISA_ALIGN;
  72. printk(KERN_INFO "PCI: %s detected, can skip ISA alignment\n", d->ident);
  73. return 0;
  74. }
  75. static struct dmi_system_id can_skip_pciprobe_dmi_table[] __devinitdata = {
  76. /*
  77. * Systems where PCI IO resource ISA alignment can be skipped
  78. * when the ISA enable bit in the bridge control is not set
  79. */
  80. {
  81. .callback = can_skip_ioresource_align,
  82. .ident = "IBM System x3800",
  83. .matches = {
  84. DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
  85. DMI_MATCH(DMI_PRODUCT_NAME, "x3800"),
  86. },
  87. },
  88. {
  89. .callback = can_skip_ioresource_align,
  90. .ident = "IBM System x3850",
  91. .matches = {
  92. DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
  93. DMI_MATCH(DMI_PRODUCT_NAME, "x3850"),
  94. },
  95. },
  96. {
  97. .callback = can_skip_ioresource_align,
  98. .ident = "IBM System x3950",
  99. .matches = {
  100. DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
  101. DMI_MATCH(DMI_PRODUCT_NAME, "x3950"),
  102. },
  103. },
  104. {}
  105. };
  106. void __init dmi_check_skip_isa_align(void)
  107. {
  108. dmi_check_system(can_skip_pciprobe_dmi_table);
  109. }
  110. /*
  111. * Called after each bus is probed, but before its children
  112. * are examined.
  113. */
  114. void __devinit pcibios_fixup_bus(struct pci_bus *b)
  115. {
  116. pci_read_bridge_bases(b);
  117. }
  118. /*
  119. * Only use DMI information to set this if nothing was passed
  120. * on the kernel command line (which was parsed earlier).
  121. */
  122. static int __devinit set_bf_sort(const struct dmi_system_id *d)
  123. {
  124. if (pci_bf_sort == pci_bf_sort_default) {
  125. pci_bf_sort = pci_dmi_bf;
  126. printk(KERN_INFO "PCI: %s detected, enabling pci=bfsort.\n", d->ident);
  127. }
  128. return 0;
  129. }
  130. /*
  131. * Enable renumbering of PCI bus# ranges to reach all PCI busses (Cardbus)
  132. */
  133. #ifdef __i386__
  134. static int __devinit assign_all_busses(const struct dmi_system_id *d)
  135. {
  136. pci_probe |= PCI_ASSIGN_ALL_BUSSES;
  137. printk(KERN_INFO "%s detected: enabling PCI bus# renumbering"
  138. " (pci=assign-busses)\n", d->ident);
  139. return 0;
  140. }
  141. #endif
  142. static struct dmi_system_id __devinitdata pciprobe_dmi_table[] = {
  143. #ifdef __i386__
  144. /*
  145. * Laptops which need pci=assign-busses to see Cardbus cards
  146. */
  147. {
  148. .callback = assign_all_busses,
  149. .ident = "Samsung X20 Laptop",
  150. .matches = {
  151. DMI_MATCH(DMI_SYS_VENDOR, "Samsung Electronics"),
  152. DMI_MATCH(DMI_PRODUCT_NAME, "SX20S"),
  153. },
  154. },
  155. #endif /* __i386__ */
  156. {
  157. .callback = set_bf_sort,
  158. .ident = "Dell PowerEdge 1950",
  159. .matches = {
  160. DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
  161. DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1950"),
  162. },
  163. },
  164. {
  165. .callback = set_bf_sort,
  166. .ident = "Dell PowerEdge 1955",
  167. .matches = {
  168. DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
  169. DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1955"),
  170. },
  171. },
  172. {
  173. .callback = set_bf_sort,
  174. .ident = "Dell PowerEdge 2900",
  175. .matches = {
  176. DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
  177. DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2900"),
  178. },
  179. },
  180. {
  181. .callback = set_bf_sort,
  182. .ident = "Dell PowerEdge 2950",
  183. .matches = {
  184. DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
  185. DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2950"),
  186. },
  187. },
  188. {
  189. .callback = set_bf_sort,
  190. .ident = "Dell PowerEdge R900",
  191. .matches = {
  192. DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
  193. DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge R900"),
  194. },
  195. },
  196. {
  197. .callback = set_bf_sort,
  198. .ident = "HP ProLiant BL20p G3",
  199. .matches = {
  200. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  201. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G3"),
  202. },
  203. },
  204. {
  205. .callback = set_bf_sort,
  206. .ident = "HP ProLiant BL20p G4",
  207. .matches = {
  208. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  209. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G4"),
  210. },
  211. },
  212. {
  213. .callback = set_bf_sort,
  214. .ident = "HP ProLiant BL30p G1",
  215. .matches = {
  216. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  217. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL30p G1"),
  218. },
  219. },
  220. {
  221. .callback = set_bf_sort,
  222. .ident = "HP ProLiant BL25p G1",
  223. .matches = {
  224. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  225. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL25p G1"),
  226. },
  227. },
  228. {
  229. .callback = set_bf_sort,
  230. .ident = "HP ProLiant BL35p G1",
  231. .matches = {
  232. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  233. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL35p G1"),
  234. },
  235. },
  236. {
  237. .callback = set_bf_sort,
  238. .ident = "HP ProLiant BL45p G1",
  239. .matches = {
  240. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  241. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G1"),
  242. },
  243. },
  244. {
  245. .callback = set_bf_sort,
  246. .ident = "HP ProLiant BL45p G2",
  247. .matches = {
  248. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  249. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G2"),
  250. },
  251. },
  252. {
  253. .callback = set_bf_sort,
  254. .ident = "HP ProLiant BL460c G1",
  255. .matches = {
  256. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  257. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL460c G1"),
  258. },
  259. },
  260. {
  261. .callback = set_bf_sort,
  262. .ident = "HP ProLiant BL465c G1",
  263. .matches = {
  264. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  265. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL465c G1"),
  266. },
  267. },
  268. {
  269. .callback = set_bf_sort,
  270. .ident = "HP ProLiant BL480c G1",
  271. .matches = {
  272. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  273. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL480c G1"),
  274. },
  275. },
  276. {
  277. .callback = set_bf_sort,
  278. .ident = "HP ProLiant BL685c G1",
  279. .matches = {
  280. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  281. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL685c G1"),
  282. },
  283. },
  284. {
  285. .callback = set_bf_sort,
  286. .ident = "HP ProLiant DL360",
  287. .matches = {
  288. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  289. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL360"),
  290. },
  291. },
  292. {
  293. .callback = set_bf_sort,
  294. .ident = "HP ProLiant DL380",
  295. .matches = {
  296. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  297. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL380"),
  298. },
  299. },
  300. #ifdef __i386__
  301. {
  302. .callback = assign_all_busses,
  303. .ident = "Compaq EVO N800c",
  304. .matches = {
  305. DMI_MATCH(DMI_SYS_VENDOR, "Compaq"),
  306. DMI_MATCH(DMI_PRODUCT_NAME, "EVO N800c"),
  307. },
  308. },
  309. #endif
  310. {
  311. .callback = set_bf_sort,
  312. .ident = "HP ProLiant DL385 G2",
  313. .matches = {
  314. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  315. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL385 G2"),
  316. },
  317. },
  318. {
  319. .callback = set_bf_sort,
  320. .ident = "HP ProLiant DL585 G2",
  321. .matches = {
  322. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  323. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL585 G2"),
  324. },
  325. },
  326. {}
  327. };
  328. void __init dmi_check_pciprobe(void)
  329. {
  330. dmi_check_system(pciprobe_dmi_table);
  331. }
  332. struct pci_bus * __devinit pcibios_scan_root(int busnum)
  333. {
  334. struct pci_bus *bus = NULL;
  335. struct pci_sysdata *sd;
  336. while ((bus = pci_find_next_bus(bus)) != NULL) {
  337. if (bus->number == busnum) {
  338. /* Already scanned */
  339. return bus;
  340. }
  341. }
  342. /* Allocate per-root-bus (not per bus) arch-specific data.
  343. * TODO: leak; this memory is never freed.
  344. * It's arguable whether it's worth the trouble to care.
  345. */
  346. sd = kzalloc(sizeof(*sd), GFP_KERNEL);
  347. if (!sd) {
  348. printk(KERN_ERR "PCI: OOM, not probing PCI bus %02x\n", busnum);
  349. return NULL;
  350. }
  351. sd->node = get_mp_bus_to_node(busnum);
  352. printk(KERN_DEBUG "PCI: Probing PCI hardware (bus %02x)\n", busnum);
  353. bus = pci_scan_bus_parented(NULL, busnum, &pci_root_ops, sd);
  354. if (!bus)
  355. kfree(sd);
  356. return bus;
  357. }
  358. extern u8 pci_cache_line_size;
  359. static int __init pcibios_init(void)
  360. {
  361. struct cpuinfo_x86 *c = &boot_cpu_data;
  362. if (!raw_pci_ops) {
  363. printk(KERN_WARNING "PCI: System does not support PCI\n");
  364. return 0;
  365. }
  366. /*
  367. * Assume PCI cacheline size of 32 bytes for all x86s except K7/K8
  368. * and P4. It's also good for 386/486s (which actually have 16)
  369. * as quite a few PCI devices do not support smaller values.
  370. */
  371. pci_cache_line_size = 32 >> 2;
  372. if (c->x86 >= 6 && c->x86_vendor == X86_VENDOR_AMD)
  373. pci_cache_line_size = 64 >> 2; /* K7 & K8 */
  374. else if (c->x86 > 6 && c->x86_vendor == X86_VENDOR_INTEL)
  375. pci_cache_line_size = 128 >> 2; /* P4 */
  376. pcibios_resource_survey();
  377. if (pci_bf_sort >= pci_force_bf)
  378. pci_sort_breadthfirst();
  379. return 0;
  380. }
  381. subsys_initcall(pcibios_init);
  382. char * __devinit pcibios_setup(char *str)
  383. {
  384. if (!strcmp(str, "off")) {
  385. pci_probe = 0;
  386. return NULL;
  387. } else if (!strcmp(str, "bfsort")) {
  388. pci_bf_sort = pci_force_bf;
  389. return NULL;
  390. } else if (!strcmp(str, "nobfsort")) {
  391. pci_bf_sort = pci_force_nobf;
  392. return NULL;
  393. }
  394. #ifdef CONFIG_PCI_BIOS
  395. else if (!strcmp(str, "bios")) {
  396. pci_probe = PCI_PROBE_BIOS;
  397. return NULL;
  398. } else if (!strcmp(str, "nobios")) {
  399. pci_probe &= ~PCI_PROBE_BIOS;
  400. return NULL;
  401. } else if (!strcmp(str, "biosirq")) {
  402. pci_probe |= PCI_BIOS_IRQ_SCAN;
  403. return NULL;
  404. } else if (!strncmp(str, "pirqaddr=", 9)) {
  405. pirq_table_addr = simple_strtoul(str+9, NULL, 0);
  406. return NULL;
  407. }
  408. #endif
  409. #ifdef CONFIG_PCI_DIRECT
  410. else if (!strcmp(str, "conf1")) {
  411. pci_probe = PCI_PROBE_CONF1 | PCI_NO_CHECKS;
  412. return NULL;
  413. }
  414. else if (!strcmp(str, "conf2")) {
  415. pci_probe = PCI_PROBE_CONF2 | PCI_NO_CHECKS;
  416. return NULL;
  417. }
  418. #endif
  419. #ifdef CONFIG_PCI_MMCONFIG
  420. else if (!strcmp(str, "nommconf")) {
  421. pci_probe &= ~PCI_PROBE_MMCONF;
  422. return NULL;
  423. }
  424. else if (!strcmp(str, "check_enable_amd_mmconf")) {
  425. pci_probe |= PCI_CHECK_ENABLE_AMD_MMCONF;
  426. return NULL;
  427. }
  428. #endif
  429. else if (!strcmp(str, "noacpi")) {
  430. acpi_noirq_set();
  431. return NULL;
  432. }
  433. else if (!strcmp(str, "noearly")) {
  434. pci_probe |= PCI_PROBE_NOEARLY;
  435. return NULL;
  436. }
  437. #ifndef CONFIG_X86_VISWS
  438. else if (!strcmp(str, "usepirqmask")) {
  439. pci_probe |= PCI_USE_PIRQ_MASK;
  440. return NULL;
  441. } else if (!strncmp(str, "irqmask=", 8)) {
  442. pcibios_irq_mask = simple_strtol(str+8, NULL, 0);
  443. return NULL;
  444. } else if (!strncmp(str, "lastbus=", 8)) {
  445. pcibios_last_bus = simple_strtol(str+8, NULL, 0);
  446. return NULL;
  447. }
  448. #endif
  449. else if (!strcmp(str, "rom")) {
  450. pci_probe |= PCI_ASSIGN_ROMS;
  451. return NULL;
  452. } else if (!strcmp(str, "assign-busses")) {
  453. pci_probe |= PCI_ASSIGN_ALL_BUSSES;
  454. return NULL;
  455. } else if (!strcmp(str, "use_crs")) {
  456. pci_probe |= PCI_USE__CRS;
  457. return NULL;
  458. } else if (!strcmp(str, "routeirq")) {
  459. pci_routeirq = 1;
  460. return NULL;
  461. } else if (!strcmp(str, "skip_isa_align")) {
  462. pci_probe |= PCI_CAN_SKIP_ISA_ALIGN;
  463. return NULL;
  464. } else if (!strcmp(str, "noioapicquirk")) {
  465. noioapicquirk = 1;
  466. return NULL;
  467. } else if (!strcmp(str, "ioapicreroute")) {
  468. if (noioapicreroute != -1)
  469. noioapicreroute = 0;
  470. return NULL;
  471. }
  472. return str;
  473. }
  474. unsigned int pcibios_assign_all_busses(void)
  475. {
  476. return (pci_probe & PCI_ASSIGN_ALL_BUSSES) ? 1 : 0;
  477. }
  478. int pcibios_enable_device(struct pci_dev *dev, int mask)
  479. {
  480. int err;
  481. if ((err = pci_enable_resources(dev, mask)) < 0)
  482. return err;
  483. if (!dev->msi_enabled)
  484. return pcibios_enable_irq(dev);
  485. return 0;
  486. }
  487. void pcibios_disable_device (struct pci_dev *dev)
  488. {
  489. if (!dev->msi_enabled && pcibios_disable_irq)
  490. pcibios_disable_irq(dev);
  491. }
  492. struct pci_bus * __devinit pci_scan_bus_on_node(int busno, struct pci_ops *ops, int node)
  493. {
  494. struct pci_bus *bus = NULL;
  495. struct pci_sysdata *sd;
  496. /*
  497. * Allocate per-root-bus (not per bus) arch-specific data.
  498. * TODO: leak; this memory is never freed.
  499. * It's arguable whether it's worth the trouble to care.
  500. */
  501. sd = kzalloc(sizeof(*sd), GFP_KERNEL);
  502. if (!sd) {
  503. printk(KERN_ERR "PCI: OOM, skipping PCI bus %02x\n", busno);
  504. return NULL;
  505. }
  506. sd->node = node;
  507. bus = pci_scan_bus(busno, ops, sd);
  508. if (!bus)
  509. kfree(sd);
  510. return bus;
  511. }
  512. struct pci_bus * __devinit pci_scan_bus_with_sysdata(int busno)
  513. {
  514. return pci_scan_bus_on_node(busno, &pci_root_ops, -1);
  515. }