common.c 13 KB

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