common.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Low-Level PCI Support for PC
  4. *
  5. * (c) 1999--2000 Martin Mares <[email protected]>
  6. */
  7. #include <linux/sched.h>
  8. #include <linux/pci.h>
  9. #include <linux/pci-acpi.h>
  10. #include <linux/ioport.h>
  11. #include <linux/init.h>
  12. #include <linux/dmi.h>
  13. #include <linux/slab.h>
  14. #include <asm/acpi.h>
  15. #include <asm/segment.h>
  16. #include <asm/io.h>
  17. #include <asm/smp.h>
  18. #include <asm/pci_x86.h>
  19. #include <asm/setup.h>
  20. #include <asm/irqdomain.h>
  21. unsigned int pci_probe = PCI_PROBE_BIOS | PCI_PROBE_CONF1 | PCI_PROBE_CONF2 |
  22. PCI_PROBE_MMCONF;
  23. static int pci_bf_sort;
  24. int pci_routeirq;
  25. int noioapicquirk;
  26. #ifdef CONFIG_X86_REROUTE_FOR_BROKEN_BOOT_IRQS
  27. int noioapicreroute = 0;
  28. #else
  29. int noioapicreroute = 1;
  30. #endif
  31. int pcibios_last_bus = -1;
  32. unsigned long pirq_table_addr;
  33. const struct pci_raw_ops *__read_mostly raw_pci_ops;
  34. const struct pci_raw_ops *__read_mostly raw_pci_ext_ops;
  35. int raw_pci_read(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->read(domain, bus, devfn, reg, len, val);
  40. if (raw_pci_ext_ops)
  41. return raw_pci_ext_ops->read(domain, bus, devfn, reg, len, val);
  42. return -EINVAL;
  43. }
  44. int raw_pci_write(unsigned int domain, unsigned int bus, unsigned int devfn,
  45. int reg, int len, u32 val)
  46. {
  47. if (domain == 0 && reg < 256 && raw_pci_ops)
  48. return raw_pci_ops->write(domain, bus, devfn, reg, len, val);
  49. if (raw_pci_ext_ops)
  50. return raw_pci_ext_ops->write(domain, bus, devfn, reg, len, val);
  51. return -EINVAL;
  52. }
  53. static int pci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
  54. {
  55. return raw_pci_read(pci_domain_nr(bus), bus->number,
  56. devfn, where, size, value);
  57. }
  58. static int pci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
  59. {
  60. return raw_pci_write(pci_domain_nr(bus), bus->number,
  61. devfn, where, size, value);
  62. }
  63. struct pci_ops pci_root_ops = {
  64. .read = pci_read,
  65. .write = pci_write,
  66. };
  67. /*
  68. * This interrupt-safe spinlock protects all accesses to PCI configuration
  69. * space, except for the mmconfig (ECAM) based operations.
  70. */
  71. DEFINE_RAW_SPINLOCK(pci_config_lock);
  72. static int __init can_skip_ioresource_align(const struct dmi_system_id *d)
  73. {
  74. pci_probe |= PCI_CAN_SKIP_ISA_ALIGN;
  75. printk(KERN_INFO "PCI: %s detected, can skip ISA alignment\n", d->ident);
  76. return 0;
  77. }
  78. static const struct dmi_system_id can_skip_pciprobe_dmi_table[] __initconst = {
  79. /*
  80. * Systems where PCI IO resource ISA alignment can be skipped
  81. * when the ISA enable bit in the bridge control is not set
  82. */
  83. {
  84. .callback = can_skip_ioresource_align,
  85. .ident = "IBM System x3800",
  86. .matches = {
  87. DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
  88. DMI_MATCH(DMI_PRODUCT_NAME, "x3800"),
  89. },
  90. },
  91. {
  92. .callback = can_skip_ioresource_align,
  93. .ident = "IBM System x3850",
  94. .matches = {
  95. DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
  96. DMI_MATCH(DMI_PRODUCT_NAME, "x3850"),
  97. },
  98. },
  99. {
  100. .callback = can_skip_ioresource_align,
  101. .ident = "IBM System x3950",
  102. .matches = {
  103. DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
  104. DMI_MATCH(DMI_PRODUCT_NAME, "x3950"),
  105. },
  106. },
  107. {}
  108. };
  109. void __init dmi_check_skip_isa_align(void)
  110. {
  111. dmi_check_system(can_skip_pciprobe_dmi_table);
  112. }
  113. static void pcibios_fixup_device_resources(struct pci_dev *dev)
  114. {
  115. struct resource *rom_r = &dev->resource[PCI_ROM_RESOURCE];
  116. struct resource *bar_r;
  117. int bar;
  118. if (pci_probe & PCI_NOASSIGN_BARS) {
  119. /*
  120. * If the BIOS did not assign the BAR, zero out the
  121. * resource so the kernel doesn't attempt to assign
  122. * it later on in pci_assign_unassigned_resources
  123. */
  124. for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
  125. bar_r = &dev->resource[bar];
  126. if (bar_r->start == 0 && bar_r->end != 0) {
  127. bar_r->flags = 0;
  128. bar_r->end = 0;
  129. }
  130. }
  131. }
  132. if (pci_probe & PCI_NOASSIGN_ROMS) {
  133. if (rom_r->parent)
  134. return;
  135. if (rom_r->start) {
  136. /* we deal with BIOS assigned ROM later */
  137. return;
  138. }
  139. rom_r->start = rom_r->end = rom_r->flags = 0;
  140. }
  141. }
  142. /*
  143. * Called after each bus is probed, but before its children
  144. * are examined.
  145. */
  146. void pcibios_fixup_bus(struct pci_bus *b)
  147. {
  148. struct pci_dev *dev;
  149. pci_read_bridge_bases(b);
  150. list_for_each_entry(dev, &b->devices, bus_list)
  151. pcibios_fixup_device_resources(dev);
  152. }
  153. void pcibios_add_bus(struct pci_bus *bus)
  154. {
  155. acpi_pci_add_bus(bus);
  156. }
  157. void pcibios_remove_bus(struct pci_bus *bus)
  158. {
  159. acpi_pci_remove_bus(bus);
  160. }
  161. /*
  162. * Only use DMI information to set this if nothing was passed
  163. * on the kernel command line (which was parsed earlier).
  164. */
  165. static int __init set_bf_sort(const struct dmi_system_id *d)
  166. {
  167. if (pci_bf_sort == pci_bf_sort_default) {
  168. pci_bf_sort = pci_dmi_bf;
  169. printk(KERN_INFO "PCI: %s detected, enabling pci=bfsort.\n", d->ident);
  170. }
  171. return 0;
  172. }
  173. static void __init read_dmi_type_b1(const struct dmi_header *dm,
  174. void *private_data)
  175. {
  176. u8 *data = (u8 *)dm + 4;
  177. if (dm->type != 0xB1)
  178. return;
  179. if ((((*(u32 *)data) >> 9) & 0x03) == 0x01)
  180. set_bf_sort((const struct dmi_system_id *)private_data);
  181. }
  182. static int __init find_sort_method(const struct dmi_system_id *d)
  183. {
  184. dmi_walk(read_dmi_type_b1, (void *)d);
  185. return 0;
  186. }
  187. /*
  188. * Enable renumbering of PCI bus# ranges to reach all PCI busses (Cardbus)
  189. */
  190. #ifdef __i386__
  191. static int __init assign_all_busses(const struct dmi_system_id *d)
  192. {
  193. pci_probe |= PCI_ASSIGN_ALL_BUSSES;
  194. printk(KERN_INFO "%s detected: enabling PCI bus# renumbering"
  195. " (pci=assign-busses)\n", d->ident);
  196. return 0;
  197. }
  198. #endif
  199. static int __init set_scan_all(const struct dmi_system_id *d)
  200. {
  201. printk(KERN_INFO "PCI: %s detected, enabling pci=pcie_scan_all\n",
  202. d->ident);
  203. pci_add_flags(PCI_SCAN_ALL_PCIE_DEVS);
  204. return 0;
  205. }
  206. static const struct dmi_system_id pciprobe_dmi_table[] __initconst = {
  207. #ifdef __i386__
  208. /*
  209. * Laptops which need pci=assign-busses to see Cardbus cards
  210. */
  211. {
  212. .callback = assign_all_busses,
  213. .ident = "Samsung X20 Laptop",
  214. .matches = {
  215. DMI_MATCH(DMI_SYS_VENDOR, "Samsung Electronics"),
  216. DMI_MATCH(DMI_PRODUCT_NAME, "SX20S"),
  217. },
  218. },
  219. #endif /* __i386__ */
  220. {
  221. .callback = set_bf_sort,
  222. .ident = "Dell PowerEdge 1950",
  223. .matches = {
  224. DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
  225. DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1950"),
  226. },
  227. },
  228. {
  229. .callback = set_bf_sort,
  230. .ident = "Dell PowerEdge 1955",
  231. .matches = {
  232. DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
  233. DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1955"),
  234. },
  235. },
  236. {
  237. .callback = set_bf_sort,
  238. .ident = "Dell PowerEdge 2900",
  239. .matches = {
  240. DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
  241. DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2900"),
  242. },
  243. },
  244. {
  245. .callback = set_bf_sort,
  246. .ident = "Dell PowerEdge 2950",
  247. .matches = {
  248. DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
  249. DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2950"),
  250. },
  251. },
  252. {
  253. .callback = set_bf_sort,
  254. .ident = "Dell PowerEdge R900",
  255. .matches = {
  256. DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
  257. DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge R900"),
  258. },
  259. },
  260. {
  261. .callback = find_sort_method,
  262. .ident = "Dell System",
  263. .matches = {
  264. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
  265. },
  266. },
  267. {
  268. .callback = set_bf_sort,
  269. .ident = "HP ProLiant BL20p G3",
  270. .matches = {
  271. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  272. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G3"),
  273. },
  274. },
  275. {
  276. .callback = set_bf_sort,
  277. .ident = "HP ProLiant BL20p G4",
  278. .matches = {
  279. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  280. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G4"),
  281. },
  282. },
  283. {
  284. .callback = set_bf_sort,
  285. .ident = "HP ProLiant BL30p G1",
  286. .matches = {
  287. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  288. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL30p G1"),
  289. },
  290. },
  291. {
  292. .callback = set_bf_sort,
  293. .ident = "HP ProLiant BL25p G1",
  294. .matches = {
  295. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  296. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL25p G1"),
  297. },
  298. },
  299. {
  300. .callback = set_bf_sort,
  301. .ident = "HP ProLiant BL35p G1",
  302. .matches = {
  303. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  304. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL35p G1"),
  305. },
  306. },
  307. {
  308. .callback = set_bf_sort,
  309. .ident = "HP ProLiant BL45p G1",
  310. .matches = {
  311. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  312. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G1"),
  313. },
  314. },
  315. {
  316. .callback = set_bf_sort,
  317. .ident = "HP ProLiant BL45p G2",
  318. .matches = {
  319. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  320. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G2"),
  321. },
  322. },
  323. {
  324. .callback = set_bf_sort,
  325. .ident = "HP ProLiant BL460c G1",
  326. .matches = {
  327. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  328. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL460c G1"),
  329. },
  330. },
  331. {
  332. .callback = set_bf_sort,
  333. .ident = "HP ProLiant BL465c G1",
  334. .matches = {
  335. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  336. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL465c G1"),
  337. },
  338. },
  339. {
  340. .callback = set_bf_sort,
  341. .ident = "HP ProLiant BL480c G1",
  342. .matches = {
  343. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  344. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL480c G1"),
  345. },
  346. },
  347. {
  348. .callback = set_bf_sort,
  349. .ident = "HP ProLiant BL685c G1",
  350. .matches = {
  351. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  352. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL685c G1"),
  353. },
  354. },
  355. {
  356. .callback = set_bf_sort,
  357. .ident = "HP ProLiant DL360",
  358. .matches = {
  359. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  360. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL360"),
  361. },
  362. },
  363. {
  364. .callback = set_bf_sort,
  365. .ident = "HP ProLiant DL380",
  366. .matches = {
  367. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  368. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL380"),
  369. },
  370. },
  371. #ifdef __i386__
  372. {
  373. .callback = assign_all_busses,
  374. .ident = "Compaq EVO N800c",
  375. .matches = {
  376. DMI_MATCH(DMI_SYS_VENDOR, "Compaq"),
  377. DMI_MATCH(DMI_PRODUCT_NAME, "EVO N800c"),
  378. },
  379. },
  380. #endif
  381. {
  382. .callback = set_bf_sort,
  383. .ident = "HP ProLiant DL385 G2",
  384. .matches = {
  385. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  386. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL385 G2"),
  387. },
  388. },
  389. {
  390. .callback = set_bf_sort,
  391. .ident = "HP ProLiant DL585 G2",
  392. .matches = {
  393. DMI_MATCH(DMI_SYS_VENDOR, "HP"),
  394. DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL585 G2"),
  395. },
  396. },
  397. {
  398. .callback = set_scan_all,
  399. .ident = "Stratus/NEC ftServer",
  400. .matches = {
  401. DMI_MATCH(DMI_SYS_VENDOR, "Stratus"),
  402. DMI_MATCH(DMI_PRODUCT_NAME, "ftServer"),
  403. },
  404. },
  405. {
  406. .callback = set_scan_all,
  407. .ident = "Stratus/NEC ftServer",
  408. .matches = {
  409. DMI_MATCH(DMI_SYS_VENDOR, "NEC"),
  410. DMI_MATCH(DMI_PRODUCT_NAME, "Express5800/R32"),
  411. },
  412. },
  413. {
  414. .callback = set_scan_all,
  415. .ident = "Stratus/NEC ftServer",
  416. .matches = {
  417. DMI_MATCH(DMI_SYS_VENDOR, "NEC"),
  418. DMI_MATCH(DMI_PRODUCT_NAME, "Express5800/R31"),
  419. },
  420. },
  421. {}
  422. };
  423. void __init dmi_check_pciprobe(void)
  424. {
  425. dmi_check_system(pciprobe_dmi_table);
  426. }
  427. void pcibios_scan_root(int busnum)
  428. {
  429. struct pci_bus *bus;
  430. struct pci_sysdata *sd;
  431. LIST_HEAD(resources);
  432. sd = kzalloc(sizeof(*sd), GFP_KERNEL);
  433. if (!sd) {
  434. printk(KERN_ERR "PCI: OOM, skipping PCI bus %02x\n", busnum);
  435. return;
  436. }
  437. sd->node = x86_pci_root_bus_node(busnum);
  438. x86_pci_root_bus_resources(busnum, &resources);
  439. printk(KERN_DEBUG "PCI: Probing PCI hardware (bus %02x)\n", busnum);
  440. bus = pci_scan_root_bus(NULL, busnum, &pci_root_ops, sd, &resources);
  441. if (!bus) {
  442. pci_free_resource_list(&resources);
  443. kfree(sd);
  444. return;
  445. }
  446. pci_bus_add_devices(bus);
  447. }
  448. void __init pcibios_set_cache_line_size(void)
  449. {
  450. struct cpuinfo_x86 *c = &boot_cpu_data;
  451. /*
  452. * Set PCI cacheline size to that of the CPU if the CPU has reported it.
  453. * (For older CPUs that don't support cpuid, we se it to 32 bytes
  454. * It's also good for 386/486s (which actually have 16)
  455. * as quite a few PCI devices do not support smaller values.
  456. */
  457. if (c->x86_clflush_size > 0) {
  458. pci_dfl_cache_line_size = c->x86_clflush_size >> 2;
  459. printk(KERN_DEBUG "PCI: pci_cache_line_size set to %d bytes\n",
  460. pci_dfl_cache_line_size << 2);
  461. } else {
  462. pci_dfl_cache_line_size = 32 >> 2;
  463. printk(KERN_DEBUG "PCI: Unknown cacheline size. Setting to 32 bytes\n");
  464. }
  465. }
  466. int __init pcibios_init(void)
  467. {
  468. if (!raw_pci_ops && !raw_pci_ext_ops) {
  469. printk(KERN_WARNING "PCI: System does not support PCI\n");
  470. return 0;
  471. }
  472. pcibios_set_cache_line_size();
  473. pcibios_resource_survey();
  474. if (pci_bf_sort >= pci_force_bf)
  475. pci_sort_breadthfirst();
  476. return 0;
  477. }
  478. char *__init pcibios_setup(char *str)
  479. {
  480. if (!strcmp(str, "off")) {
  481. pci_probe = 0;
  482. return NULL;
  483. } else if (!strcmp(str, "bfsort")) {
  484. pci_bf_sort = pci_force_bf;
  485. return NULL;
  486. } else if (!strcmp(str, "nobfsort")) {
  487. pci_bf_sort = pci_force_nobf;
  488. return NULL;
  489. }
  490. #ifdef CONFIG_PCI_BIOS
  491. else if (!strcmp(str, "bios")) {
  492. pci_probe = PCI_PROBE_BIOS;
  493. return NULL;
  494. } else if (!strcmp(str, "nobios")) {
  495. pci_probe &= ~PCI_PROBE_BIOS;
  496. return NULL;
  497. } else if (!strcmp(str, "biosirq")) {
  498. pci_probe |= PCI_BIOS_IRQ_SCAN;
  499. return NULL;
  500. } else if (!strncmp(str, "pirqaddr=", 9)) {
  501. pirq_table_addr = simple_strtoul(str+9, NULL, 0);
  502. return NULL;
  503. }
  504. #endif
  505. #ifdef CONFIG_PCI_DIRECT
  506. else if (!strcmp(str, "conf1")) {
  507. pci_probe = PCI_PROBE_CONF1 | PCI_NO_CHECKS;
  508. return NULL;
  509. }
  510. else if (!strcmp(str, "conf2")) {
  511. pci_probe = PCI_PROBE_CONF2 | PCI_NO_CHECKS;
  512. return NULL;
  513. }
  514. #endif
  515. #ifdef CONFIG_PCI_MMCONFIG
  516. else if (!strcmp(str, "nommconf")) {
  517. pci_probe &= ~PCI_PROBE_MMCONF;
  518. return NULL;
  519. }
  520. else if (!strcmp(str, "check_enable_amd_mmconf")) {
  521. pci_probe |= PCI_CHECK_ENABLE_AMD_MMCONF;
  522. return NULL;
  523. }
  524. #endif
  525. else if (!strcmp(str, "noacpi")) {
  526. acpi_noirq_set();
  527. return NULL;
  528. }
  529. else if (!strcmp(str, "noearly")) {
  530. pci_probe |= PCI_PROBE_NOEARLY;
  531. return NULL;
  532. }
  533. else if (!strcmp(str, "usepirqmask")) {
  534. pci_probe |= PCI_USE_PIRQ_MASK;
  535. return NULL;
  536. } else if (!strncmp(str, "irqmask=", 8)) {
  537. pcibios_irq_mask = simple_strtol(str+8, NULL, 0);
  538. return NULL;
  539. } else if (!strncmp(str, "lastbus=", 8)) {
  540. pcibios_last_bus = simple_strtol(str+8, NULL, 0);
  541. return NULL;
  542. } else if (!strcmp(str, "rom")) {
  543. pci_probe |= PCI_ASSIGN_ROMS;
  544. return NULL;
  545. } else if (!strcmp(str, "norom")) {
  546. pci_probe |= PCI_NOASSIGN_ROMS;
  547. return NULL;
  548. } else if (!strcmp(str, "nobar")) {
  549. pci_probe |= PCI_NOASSIGN_BARS;
  550. return NULL;
  551. } else if (!strcmp(str, "assign-busses")) {
  552. pci_probe |= PCI_ASSIGN_ALL_BUSSES;
  553. return NULL;
  554. } else if (!strcmp(str, "use_crs")) {
  555. pci_probe |= PCI_USE__CRS;
  556. return NULL;
  557. } else if (!strcmp(str, "nocrs")) {
  558. pci_probe |= PCI_ROOT_NO_CRS;
  559. return NULL;
  560. } else if (!strcmp(str, "use_e820")) {
  561. pci_probe |= PCI_USE_E820;
  562. add_taint(TAINT_FIRMWARE_WORKAROUND, LOCKDEP_STILL_OK);
  563. return NULL;
  564. } else if (!strcmp(str, "no_e820")) {
  565. pci_probe |= PCI_NO_E820;
  566. add_taint(TAINT_FIRMWARE_WORKAROUND, LOCKDEP_STILL_OK);
  567. return NULL;
  568. #ifdef CONFIG_PHYS_ADDR_T_64BIT
  569. } else if (!strcmp(str, "big_root_window")) {
  570. pci_probe |= PCI_BIG_ROOT_WINDOW;
  571. return NULL;
  572. #endif
  573. } else if (!strcmp(str, "routeirq")) {
  574. pci_routeirq = 1;
  575. return NULL;
  576. } else if (!strcmp(str, "skip_isa_align")) {
  577. pci_probe |= PCI_CAN_SKIP_ISA_ALIGN;
  578. return NULL;
  579. } else if (!strcmp(str, "noioapicquirk")) {
  580. noioapicquirk = 1;
  581. return NULL;
  582. } else if (!strcmp(str, "ioapicreroute")) {
  583. if (noioapicreroute != -1)
  584. noioapicreroute = 0;
  585. return NULL;
  586. } else if (!strcmp(str, "noioapicreroute")) {
  587. if (noioapicreroute != -1)
  588. noioapicreroute = 1;
  589. return NULL;
  590. }
  591. return str;
  592. }
  593. unsigned int pcibios_assign_all_busses(void)
  594. {
  595. return (pci_probe & PCI_ASSIGN_ALL_BUSSES) ? 1 : 0;
  596. }
  597. static void set_dev_domain_options(struct pci_dev *pdev)
  598. {
  599. if (is_vmd(pdev->bus))
  600. pdev->hotplug_user_indicators = 1;
  601. }
  602. int pcibios_device_add(struct pci_dev *dev)
  603. {
  604. struct pci_setup_rom *rom;
  605. struct irq_domain *msidom;
  606. struct setup_data *data;
  607. u64 pa_data;
  608. pa_data = boot_params.hdr.setup_data;
  609. while (pa_data) {
  610. data = memremap(pa_data, sizeof(*rom), MEMREMAP_WB);
  611. if (!data)
  612. return -ENOMEM;
  613. if (data->type == SETUP_PCI) {
  614. rom = (struct pci_setup_rom *)data;
  615. if ((pci_domain_nr(dev->bus) == rom->segment) &&
  616. (dev->bus->number == rom->bus) &&
  617. (PCI_SLOT(dev->devfn) == rom->device) &&
  618. (PCI_FUNC(dev->devfn) == rom->function) &&
  619. (dev->vendor == rom->vendor) &&
  620. (dev->device == rom->devid)) {
  621. dev->rom = pa_data +
  622. offsetof(struct pci_setup_rom, romdata);
  623. dev->romlen = rom->pcilen;
  624. }
  625. }
  626. pa_data = data->next;
  627. memunmap(data);
  628. }
  629. set_dev_domain_options(dev);
  630. /*
  631. * Setup the initial MSI domain of the device. If the underlying
  632. * bus has a PCI/MSI irqdomain associated use the bus domain,
  633. * otherwise set the default domain. This ensures that special irq
  634. * domains e.g. VMD are preserved. The default ensures initial
  635. * operation if irq remapping is not active. If irq remapping is
  636. * active it will overwrite the domain pointer when the device is
  637. * associated to a remapping domain.
  638. */
  639. msidom = dev_get_msi_domain(&dev->bus->dev);
  640. if (!msidom)
  641. msidom = x86_pci_msi_default_domain;
  642. dev_set_msi_domain(&dev->dev, msidom);
  643. return 0;
  644. }
  645. int pcibios_enable_device(struct pci_dev *dev, int mask)
  646. {
  647. int err;
  648. if ((err = pci_enable_resources(dev, mask)) < 0)
  649. return err;
  650. if (!pci_dev_msi_enabled(dev))
  651. return pcibios_enable_irq(dev);
  652. return 0;
  653. }
  654. void pcibios_disable_device (struct pci_dev *dev)
  655. {
  656. if (!pci_dev_msi_enabled(dev) && pcibios_disable_irq)
  657. pcibios_disable_irq(dev);
  658. }
  659. #ifdef CONFIG_ACPI_HOTPLUG_IOAPIC
  660. void pcibios_release_device(struct pci_dev *dev)
  661. {
  662. if (atomic_dec_return(&dev->enable_cnt) >= 0)
  663. pcibios_disable_device(dev);
  664. }
  665. #endif
  666. int pci_ext_cfg_avail(void)
  667. {
  668. if (raw_pci_ext_ops)
  669. return 1;
  670. else
  671. return 0;
  672. }
  673. #if IS_ENABLED(CONFIG_VMD)
  674. struct pci_dev *pci_real_dma_dev(struct pci_dev *dev)
  675. {
  676. if (is_vmd(dev->bus))
  677. return to_pci_sysdata(dev->bus)->vmd_dev;
  678. return dev;
  679. }
  680. #endif