^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/dmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/pci-acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <asm/numa.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <asm/pci_x86.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) struct pci_root_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) struct acpi_pci_root_info common;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) struct pci_sysdata sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #ifdef CONFIG_PCI_MMCONFIG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) bool mcfg_added;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) u8 start_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) u8 end_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static bool pci_use_crs = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static bool pci_ignore_seg = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) static int __init set_use_crs(const struct dmi_system_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) pci_use_crs = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static int __init set_nouse_crs(const struct dmi_system_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) pci_use_crs = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static int __init set_ignore_seg(const struct dmi_system_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) printk(KERN_INFO "PCI: %s detected: ignoring ACPI _SEG\n", id->ident);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) pci_ignore_seg = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static const struct dmi_system_id pci_crs_quirks[] __initconst = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /* http://bugzilla.kernel.org/show_bug.cgi?id=14183 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) .callback = set_use_crs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) .ident = "IBM System x3800",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) DMI_MATCH(DMI_PRODUCT_NAME, "x3800"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) /* https://bugzilla.kernel.org/show_bug.cgi?id=16007 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /* 2006 AMD HT/VIA system with two host bridges */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) .callback = set_use_crs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) .ident = "ASRock ALiveSATA2-GLAN",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) DMI_MATCH(DMI_PRODUCT_NAME, "ALiveSATA2-GLAN"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /* https://bugzilla.kernel.org/show_bug.cgi?id=30552 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /* 2006 AMD HT/VIA system with two host bridges */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) .callback = set_use_crs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) .ident = "ASUS M2V-MX SE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) DMI_MATCH(DMI_BOARD_NAME, "M2V-MX SE"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) DMI_MATCH(DMI_BIOS_VENDOR, "American Megatrends Inc."),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /* https://bugzilla.kernel.org/show_bug.cgi?id=42619 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) .callback = set_use_crs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) .ident = "MSI MS-7253",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTERNATIONAL CO., LTD"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) DMI_MATCH(DMI_BOARD_NAME, "MS-7253"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies, LTD"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) /* https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/931368 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /* https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/1033299 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) .callback = set_use_crs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) .ident = "Foxconn K8M890-8237A",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) DMI_MATCH(DMI_BOARD_VENDOR, "Foxconn"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) DMI_MATCH(DMI_BOARD_NAME, "K8M890-8237A"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies, LTD"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) /* Now for the blacklist.. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) /* https://bugzilla.redhat.com/show_bug.cgi?id=769657 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) .callback = set_nouse_crs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) .ident = "Dell Studio 1557",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) DMI_MATCH(DMI_BOARD_VENDOR, "Dell Inc."),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) DMI_MATCH(DMI_PRODUCT_NAME, "Studio 1557"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) DMI_MATCH(DMI_BIOS_VERSION, "A09"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /* https://bugzilla.redhat.com/show_bug.cgi?id=769657 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) .callback = set_nouse_crs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) .ident = "Thinkpad SL510",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) DMI_MATCH(DMI_BOARD_NAME, "2847DFG"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) DMI_MATCH(DMI_BIOS_VERSION, "6JET85WW (1.43 )"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /* https://bugzilla.kernel.org/show_bug.cgi?id=42606 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) .callback = set_nouse_crs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) .ident = "Supermicro X8DTH",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) DMI_MATCH(DMI_PRODUCT_NAME, "X8DTH-i/6/iF/6F"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) DMI_MATCH(DMI_BIOS_VERSION, "2.0a"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /* https://bugzilla.kernel.org/show_bug.cgi?id=15362 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) .callback = set_ignore_seg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) .ident = "HP xw9300",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) .matches = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) DMI_MATCH(DMI_PRODUCT_NAME, "HP xw9300 Workstation"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) void __init pci_acpi_crs_quirks(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) int year = dmi_get_bios_year();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (year >= 0 && year < 2008 && iomem_resource.end <= 0xffffffff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) pci_use_crs = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) dmi_check_system(pci_crs_quirks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * If the user specifies "pci=use_crs" or "pci=nocrs" explicitly, that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * takes precedence over anything we figured out above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (pci_probe & PCI_ROOT_NO_CRS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) pci_use_crs = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) else if (pci_probe & PCI_USE__CRS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) pci_use_crs = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) printk(KERN_INFO "PCI: %s host bridge windows from ACPI; "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) "if necessary, use \"pci=%s\" and report a bug\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) pci_use_crs ? "Using" : "Ignoring",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) pci_use_crs ? "nocrs" : "use_crs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) #ifdef CONFIG_PCI_MMCONFIG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static int check_segment(u16 seg, struct device *dev, char *estr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (seg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) "%s can't access PCI configuration "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) "space under this host bridge.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) estr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * Failure in adding MMCFG information is not fatal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * just can't access extended configuration space of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * devices under this host bridge.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) dev_warn(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) "%s can't access extended PCI configuration "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) "space under this bridge.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) estr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static int setup_mcfg_map(struct acpi_pci_root_info *ci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) int result, seg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct pci_root_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) struct acpi_pci_root *root = ci->root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) struct device *dev = &ci->bridge->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) info = container_of(ci, struct pci_root_info, common);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) info->start_bus = (u8)root->secondary.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) info->end_bus = (u8)root->secondary.end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) info->mcfg_added = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) seg = info->sd.domain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* return success if MMCFG is not in use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (raw_pci_ext_ops && raw_pci_ext_ops != &pci_mmcfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (!(pci_probe & PCI_PROBE_MMCONF))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) return check_segment(seg, dev, "MMCONFIG is disabled,");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) result = pci_mmconfig_insert(dev, seg, info->start_bus, info->end_bus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) root->mcfg_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (result == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /* enable MMCFG if it hasn't been enabled yet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (raw_pci_ext_ops == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) raw_pci_ext_ops = &pci_mmcfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) info->mcfg_added = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) } else if (result != -EEXIST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return check_segment(seg, dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) "fail to add MMCONFIG information,");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static void teardown_mcfg_map(struct acpi_pci_root_info *ci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) struct pci_root_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) info = container_of(ci, struct pci_root_info, common);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (info->mcfg_added) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) pci_mmconfig_delete(info->sd.domain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) info->start_bus, info->end_bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) info->mcfg_added = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static int setup_mcfg_map(struct acpi_pci_root_info *ci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static void teardown_mcfg_map(struct acpi_pci_root_info *ci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) static int pci_acpi_root_get_node(struct acpi_pci_root *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) int busnum = root->secondary.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) struct acpi_device *device = root->device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) int node = acpi_get_node(device->handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (node == NUMA_NO_NODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) node = x86_pci_root_bus_node(busnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (node != 0 && node != NUMA_NO_NODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) dev_info(&device->dev, FW_BUG "no _PXM; falling back to node %d from hardware (may be inconsistent with ACPI node numbers)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (node != NUMA_NO_NODE && !node_online(node))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) node = NUMA_NO_NODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static int pci_acpi_root_init_info(struct acpi_pci_root_info *ci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) return setup_mcfg_map(ci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) static void pci_acpi_root_release_info(struct acpi_pci_root_info *ci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) teardown_mcfg_map(ci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) kfree(container_of(ci, struct pci_root_info, common));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * An IO port or MMIO resource assigned to a PCI host bridge may be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) * consumed by the host bridge itself or available to its child
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * bus/devices. The ACPI specification defines a bit (Producer/Consumer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * to tell whether the resource is consumed by the host bridge itself,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * but firmware hasn't used that bit consistently, so we can't rely on it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * On x86 and IA64 platforms, all IO port and MMIO resources are assumed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * to be available to child bus/devices except one special case:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * IO port [0xCF8-0xCFF] is consumed by the host bridge itself
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) * to access PCI configuration space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * So explicitly filter out PCI CFG IO ports[0xCF8-0xCFF].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static bool resource_is_pcicfg_ioport(struct resource *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) return (res->flags & IORESOURCE_IO) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) res->start == 0xCF8 && res->end == 0xCFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) static int pci_acpi_root_prepare_resources(struct acpi_pci_root_info *ci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) struct acpi_device *device = ci->bridge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) int busnum = ci->root->secondary.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) struct resource_entry *entry, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) status = acpi_pci_probe_root_resources(ci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) if (pci_use_crs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) resource_list_for_each_entry_safe(entry, tmp, &ci->resources)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) if (resource_is_pcicfg_ioport(entry->res))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) resource_list_destroy_entry(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) resource_list_for_each_entry_safe(entry, tmp, &ci->resources) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) dev_printk(KERN_DEBUG, &device->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) "host bridge window %pR (ignored)\n", entry->res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) resource_list_destroy_entry(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) x86_pci_root_bus_resources(busnum, &ci->resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) static struct acpi_pci_root_ops acpi_pci_root_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) .pci_ops = &pci_root_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) .init_info = pci_acpi_root_init_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) .release_info = pci_acpi_root_release_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) .prepare_resources = pci_acpi_root_prepare_resources,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) int domain = root->segment;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) int busnum = root->secondary.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) int node = pci_acpi_root_get_node(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) struct pci_bus *bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) if (pci_ignore_seg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) root->segment = domain = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (domain && !pci_domains_supported) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) printk(KERN_WARNING "pci_bus %04x:%02x: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) "ignored (multiple domains not supported)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) domain, busnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) bus = pci_find_bus(domain, busnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) if (bus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) * If the desired bus has been scanned already, replace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) * its bus->sysdata.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) struct pci_sysdata sd = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) .domain = domain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) .node = node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) .companion = root->device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) memcpy(bus->sysdata, &sd, sizeof(sd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) struct pci_root_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) info = kzalloc(sizeof(*info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) dev_err(&root->device->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) "pci_bus %04x:%02x: ignored (out of memory)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) domain, busnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) info->sd.domain = domain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) info->sd.node = node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) info->sd.companion = root->device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) bus = acpi_pci_root_create(root, &acpi_pci_root_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) &info->common, &info->sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) /* After the PCI-E bus has been walked and all devices discovered,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) * configure any settings of the fabric that might be necessary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) if (bus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) struct pci_bus *child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) list_for_each_entry(child, &bus->children, node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) pcie_bus_configure_settings(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) return bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) * We pass NULL as parent to pci_create_root_bus(), so if it is not NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) * here, pci_create_root_bus() has been called by someone else and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) * sysdata is likely to be different from what we expect. Let it go in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) * that case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) if (!bridge->dev.parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) struct pci_sysdata *sd = bridge->bus->sysdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) ACPI_COMPANION_SET(&bridge->dev, sd->companion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) int __init pci_acpi_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) struct pci_dev *dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) if (acpi_noirq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) acpi_irq_penalty_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) pcibios_enable_irq = acpi_pci_irq_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) pcibios_disable_irq = acpi_pci_irq_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) x86_init.pci.init_irq = x86_init_noop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if (pci_routeirq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) * PCI IRQ routing is set up by pci_enable_device(), but we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) * also do it here in case there are still broken drivers that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) * don't use pci_enable_device().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) for_each_pci_dev(dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) acpi_pci_irq_enable(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }