Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  *  Low-Level PCI Support for PC
0004  *
0005  *  (c) 1999--2000 Martin Mares <mj@ucw.cz>
0006  */
0007 
0008 #include <linux/sched.h>
0009 #include <linux/pci.h>
0010 #include <linux/pci-acpi.h>
0011 #include <linux/ioport.h>
0012 #include <linux/init.h>
0013 #include <linux/dmi.h>
0014 #include <linux/slab.h>
0015 
0016 #include <asm/acpi.h>
0017 #include <asm/segment.h>
0018 #include <asm/io.h>
0019 #include <asm/smp.h>
0020 #include <asm/pci_x86.h>
0021 #include <asm/setup.h>
0022 #include <asm/irqdomain.h>
0023 
0024 unsigned int pci_probe = PCI_PROBE_BIOS | PCI_PROBE_CONF1 | PCI_PROBE_CONF2 |
0025                 PCI_PROBE_MMCONF;
0026 
0027 static int pci_bf_sort;
0028 int pci_routeirq;
0029 int noioapicquirk;
0030 #ifdef CONFIG_X86_REROUTE_FOR_BROKEN_BOOT_IRQS
0031 int noioapicreroute = 0;
0032 #else
0033 int noioapicreroute = 1;
0034 #endif
0035 int pcibios_last_bus = -1;
0036 unsigned long pirq_table_addr;
0037 const struct pci_raw_ops *__read_mostly raw_pci_ops;
0038 const struct pci_raw_ops *__read_mostly raw_pci_ext_ops;
0039 
0040 int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
0041                         int reg, int len, u32 *val)
0042 {
0043     if (domain == 0 && reg < 256 && raw_pci_ops)
0044         return raw_pci_ops->read(domain, bus, devfn, reg, len, val);
0045     if (raw_pci_ext_ops)
0046         return raw_pci_ext_ops->read(domain, bus, devfn, reg, len, val);
0047     return -EINVAL;
0048 }
0049 
0050 int raw_pci_write(unsigned int domain, unsigned int bus, unsigned int devfn,
0051                         int reg, int len, u32 val)
0052 {
0053     if (domain == 0 && reg < 256 && raw_pci_ops)
0054         return raw_pci_ops->write(domain, bus, devfn, reg, len, val);
0055     if (raw_pci_ext_ops)
0056         return raw_pci_ext_ops->write(domain, bus, devfn, reg, len, val);
0057     return -EINVAL;
0058 }
0059 
0060 static int pci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
0061 {
0062     return raw_pci_read(pci_domain_nr(bus), bus->number,
0063                  devfn, where, size, value);
0064 }
0065 
0066 static int pci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
0067 {
0068     return raw_pci_write(pci_domain_nr(bus), bus->number,
0069                   devfn, where, size, value);
0070 }
0071 
0072 struct pci_ops pci_root_ops = {
0073     .read = pci_read,
0074     .write = pci_write,
0075 };
0076 
0077 /*
0078  * This interrupt-safe spinlock protects all accesses to PCI configuration
0079  * space, except for the mmconfig (ECAM) based operations.
0080  */
0081 DEFINE_RAW_SPINLOCK(pci_config_lock);
0082 
0083 static int __init can_skip_ioresource_align(const struct dmi_system_id *d)
0084 {
0085     pci_probe |= PCI_CAN_SKIP_ISA_ALIGN;
0086     printk(KERN_INFO "PCI: %s detected, can skip ISA alignment\n", d->ident);
0087     return 0;
0088 }
0089 
0090 static const struct dmi_system_id can_skip_pciprobe_dmi_table[] __initconst = {
0091 /*
0092  * Systems where PCI IO resource ISA alignment can be skipped
0093  * when the ISA enable bit in the bridge control is not set
0094  */
0095     {
0096         .callback = can_skip_ioresource_align,
0097         .ident = "IBM System x3800",
0098         .matches = {
0099             DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
0100             DMI_MATCH(DMI_PRODUCT_NAME, "x3800"),
0101         },
0102     },
0103     {
0104         .callback = can_skip_ioresource_align,
0105         .ident = "IBM System x3850",
0106         .matches = {
0107             DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
0108             DMI_MATCH(DMI_PRODUCT_NAME, "x3850"),
0109         },
0110     },
0111     {
0112         .callback = can_skip_ioresource_align,
0113         .ident = "IBM System x3950",
0114         .matches = {
0115             DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
0116             DMI_MATCH(DMI_PRODUCT_NAME, "x3950"),
0117         },
0118     },
0119     {}
0120 };
0121 
0122 void __init dmi_check_skip_isa_align(void)
0123 {
0124     dmi_check_system(can_skip_pciprobe_dmi_table);
0125 }
0126 
0127 static void pcibios_fixup_device_resources(struct pci_dev *dev)
0128 {
0129     struct resource *rom_r = &dev->resource[PCI_ROM_RESOURCE];
0130     struct resource *bar_r;
0131     int bar;
0132 
0133     if (pci_probe & PCI_NOASSIGN_BARS) {
0134         /*
0135         * If the BIOS did not assign the BAR, zero out the
0136         * resource so the kernel doesn't attempt to assign
0137         * it later on in pci_assign_unassigned_resources
0138         */
0139         for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
0140             bar_r = &dev->resource[bar];
0141             if (bar_r->start == 0 && bar_r->end != 0) {
0142                 bar_r->flags = 0;
0143                 bar_r->end = 0;
0144             }
0145         }
0146     }
0147 
0148     if (pci_probe & PCI_NOASSIGN_ROMS) {
0149         if (rom_r->parent)
0150             return;
0151         if (rom_r->start) {
0152             /* we deal with BIOS assigned ROM later */
0153             return;
0154         }
0155         rom_r->start = rom_r->end = rom_r->flags = 0;
0156     }
0157 }
0158 
0159 /*
0160  *  Called after each bus is probed, but before its children
0161  *  are examined.
0162  */
0163 
0164 void pcibios_fixup_bus(struct pci_bus *b)
0165 {
0166     struct pci_dev *dev;
0167 
0168     pci_read_bridge_bases(b);
0169     list_for_each_entry(dev, &b->devices, bus_list)
0170         pcibios_fixup_device_resources(dev);
0171 }
0172 
0173 void pcibios_add_bus(struct pci_bus *bus)
0174 {
0175     acpi_pci_add_bus(bus);
0176 }
0177 
0178 void pcibios_remove_bus(struct pci_bus *bus)
0179 {
0180     acpi_pci_remove_bus(bus);
0181 }
0182 
0183 /*
0184  * Only use DMI information to set this if nothing was passed
0185  * on the kernel command line (which was parsed earlier).
0186  */
0187 
0188 static int __init set_bf_sort(const struct dmi_system_id *d)
0189 {
0190     if (pci_bf_sort == pci_bf_sort_default) {
0191         pci_bf_sort = pci_dmi_bf;
0192         printk(KERN_INFO "PCI: %s detected, enabling pci=bfsort.\n", d->ident);
0193     }
0194     return 0;
0195 }
0196 
0197 static void __init read_dmi_type_b1(const struct dmi_header *dm,
0198                     void *private_data)
0199 {
0200     u8 *data = (u8 *)dm + 4;
0201 
0202     if (dm->type != 0xB1)
0203         return;
0204     if ((((*(u32 *)data) >> 9) & 0x03) == 0x01)
0205         set_bf_sort((const struct dmi_system_id *)private_data);
0206 }
0207 
0208 static int __init find_sort_method(const struct dmi_system_id *d)
0209 {
0210     dmi_walk(read_dmi_type_b1, (void *)d);
0211     return 0;
0212 }
0213 
0214 /*
0215  * Enable renumbering of PCI bus# ranges to reach all PCI busses (Cardbus)
0216  */
0217 #ifdef __i386__
0218 static int __init assign_all_busses(const struct dmi_system_id *d)
0219 {
0220     pci_probe |= PCI_ASSIGN_ALL_BUSSES;
0221     printk(KERN_INFO "%s detected: enabling PCI bus# renumbering"
0222             " (pci=assign-busses)\n", d->ident);
0223     return 0;
0224 }
0225 #endif
0226 
0227 static int __init set_scan_all(const struct dmi_system_id *d)
0228 {
0229     printk(KERN_INFO "PCI: %s detected, enabling pci=pcie_scan_all\n",
0230            d->ident);
0231     pci_add_flags(PCI_SCAN_ALL_PCIE_DEVS);
0232     return 0;
0233 }
0234 
0235 static const struct dmi_system_id pciprobe_dmi_table[] __initconst = {
0236 #ifdef __i386__
0237 /*
0238  * Laptops which need pci=assign-busses to see Cardbus cards
0239  */
0240     {
0241         .callback = assign_all_busses,
0242         .ident = "Samsung X20 Laptop",
0243         .matches = {
0244             DMI_MATCH(DMI_SYS_VENDOR, "Samsung Electronics"),
0245             DMI_MATCH(DMI_PRODUCT_NAME, "SX20S"),
0246         },
0247     },
0248 #endif      /* __i386__ */
0249     {
0250         .callback = set_bf_sort,
0251         .ident = "Dell PowerEdge 1950",
0252         .matches = {
0253             DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
0254             DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1950"),
0255         },
0256     },
0257     {
0258         .callback = set_bf_sort,
0259         .ident = "Dell PowerEdge 1955",
0260         .matches = {
0261             DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
0262             DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 1955"),
0263         },
0264     },
0265     {
0266         .callback = set_bf_sort,
0267         .ident = "Dell PowerEdge 2900",
0268         .matches = {
0269             DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
0270             DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2900"),
0271         },
0272     },
0273     {
0274         .callback = set_bf_sort,
0275         .ident = "Dell PowerEdge 2950",
0276         .matches = {
0277             DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
0278             DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge 2950"),
0279         },
0280     },
0281     {
0282         .callback = set_bf_sort,
0283         .ident = "Dell PowerEdge R900",
0284         .matches = {
0285             DMI_MATCH(DMI_SYS_VENDOR, "Dell"),
0286             DMI_MATCH(DMI_PRODUCT_NAME, "PowerEdge R900"),
0287         },
0288     },
0289     {
0290         .callback = find_sort_method,
0291         .ident = "Dell System",
0292         .matches = {
0293             DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
0294         },
0295     },
0296     {
0297         .callback = set_bf_sort,
0298         .ident = "HP ProLiant BL20p G3",
0299         .matches = {
0300             DMI_MATCH(DMI_SYS_VENDOR, "HP"),
0301             DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G3"),
0302         },
0303     },
0304     {
0305         .callback = set_bf_sort,
0306         .ident = "HP ProLiant BL20p G4",
0307         .matches = {
0308             DMI_MATCH(DMI_SYS_VENDOR, "HP"),
0309             DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL20p G4"),
0310         },
0311     },
0312     {
0313         .callback = set_bf_sort,
0314         .ident = "HP ProLiant BL30p G1",
0315         .matches = {
0316             DMI_MATCH(DMI_SYS_VENDOR, "HP"),
0317             DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL30p G1"),
0318         },
0319     },
0320     {
0321         .callback = set_bf_sort,
0322         .ident = "HP ProLiant BL25p G1",
0323         .matches = {
0324             DMI_MATCH(DMI_SYS_VENDOR, "HP"),
0325             DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL25p G1"),
0326         },
0327     },
0328     {
0329         .callback = set_bf_sort,
0330         .ident = "HP ProLiant BL35p G1",
0331         .matches = {
0332             DMI_MATCH(DMI_SYS_VENDOR, "HP"),
0333             DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL35p G1"),
0334         },
0335     },
0336     {
0337         .callback = set_bf_sort,
0338         .ident = "HP ProLiant BL45p G1",
0339         .matches = {
0340             DMI_MATCH(DMI_SYS_VENDOR, "HP"),
0341             DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G1"),
0342         },
0343     },
0344     {
0345         .callback = set_bf_sort,
0346         .ident = "HP ProLiant BL45p G2",
0347         .matches = {
0348             DMI_MATCH(DMI_SYS_VENDOR, "HP"),
0349             DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL45p G2"),
0350         },
0351     },
0352     {
0353         .callback = set_bf_sort,
0354         .ident = "HP ProLiant BL460c G1",
0355         .matches = {
0356             DMI_MATCH(DMI_SYS_VENDOR, "HP"),
0357             DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL460c G1"),
0358         },
0359     },
0360     {
0361         .callback = set_bf_sort,
0362         .ident = "HP ProLiant BL465c G1",
0363         .matches = {
0364             DMI_MATCH(DMI_SYS_VENDOR, "HP"),
0365             DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL465c G1"),
0366         },
0367     },
0368     {
0369         .callback = set_bf_sort,
0370         .ident = "HP ProLiant BL480c G1",
0371         .matches = {
0372             DMI_MATCH(DMI_SYS_VENDOR, "HP"),
0373             DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL480c G1"),
0374         },
0375     },
0376     {
0377         .callback = set_bf_sort,
0378         .ident = "HP ProLiant BL685c G1",
0379         .matches = {
0380             DMI_MATCH(DMI_SYS_VENDOR, "HP"),
0381             DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant BL685c G1"),
0382         },
0383     },
0384     {
0385         .callback = set_bf_sort,
0386         .ident = "HP ProLiant DL360",
0387         .matches = {
0388             DMI_MATCH(DMI_SYS_VENDOR, "HP"),
0389             DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL360"),
0390         },
0391     },
0392     {
0393         .callback = set_bf_sort,
0394         .ident = "HP ProLiant DL380",
0395         .matches = {
0396             DMI_MATCH(DMI_SYS_VENDOR, "HP"),
0397             DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL380"),
0398         },
0399     },
0400 #ifdef __i386__
0401     {
0402         .callback = assign_all_busses,
0403         .ident = "Compaq EVO N800c",
0404         .matches = {
0405             DMI_MATCH(DMI_SYS_VENDOR, "Compaq"),
0406             DMI_MATCH(DMI_PRODUCT_NAME, "EVO N800c"),
0407         },
0408     },
0409 #endif
0410     {
0411         .callback = set_bf_sort,
0412         .ident = "HP ProLiant DL385 G2",
0413         .matches = {
0414             DMI_MATCH(DMI_SYS_VENDOR, "HP"),
0415             DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL385 G2"),
0416         },
0417     },
0418     {
0419         .callback = set_bf_sort,
0420         .ident = "HP ProLiant DL585 G2",
0421         .matches = {
0422             DMI_MATCH(DMI_SYS_VENDOR, "HP"),
0423             DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL585 G2"),
0424         },
0425     },
0426     {
0427         .callback = set_scan_all,
0428         .ident = "Stratus/NEC ftServer",
0429         .matches = {
0430             DMI_MATCH(DMI_SYS_VENDOR, "Stratus"),
0431             DMI_MATCH(DMI_PRODUCT_NAME, "ftServer"),
0432         },
0433     },
0434         {
0435                 .callback = set_scan_all,
0436                 .ident = "Stratus/NEC ftServer",
0437                 .matches = {
0438                         DMI_MATCH(DMI_SYS_VENDOR, "NEC"),
0439                         DMI_MATCH(DMI_PRODUCT_NAME, "Express5800/R32"),
0440                 },
0441         },
0442         {
0443                 .callback = set_scan_all,
0444                 .ident = "Stratus/NEC ftServer",
0445                 .matches = {
0446                         DMI_MATCH(DMI_SYS_VENDOR, "NEC"),
0447                         DMI_MATCH(DMI_PRODUCT_NAME, "Express5800/R31"),
0448                 },
0449         },
0450     {}
0451 };
0452 
0453 void __init dmi_check_pciprobe(void)
0454 {
0455     dmi_check_system(pciprobe_dmi_table);
0456 }
0457 
0458 void pcibios_scan_root(int busnum)
0459 {
0460     struct pci_bus *bus;
0461     struct pci_sysdata *sd;
0462     LIST_HEAD(resources);
0463 
0464     sd = kzalloc(sizeof(*sd), GFP_KERNEL);
0465     if (!sd) {
0466         printk(KERN_ERR "PCI: OOM, skipping PCI bus %02x\n", busnum);
0467         return;
0468     }
0469     sd->node = x86_pci_root_bus_node(busnum);
0470     x86_pci_root_bus_resources(busnum, &resources);
0471     printk(KERN_DEBUG "PCI: Probing PCI hardware (bus %02x)\n", busnum);
0472     bus = pci_scan_root_bus(NULL, busnum, &pci_root_ops, sd, &resources);
0473     if (!bus) {
0474         pci_free_resource_list(&resources);
0475         kfree(sd);
0476         return;
0477     }
0478     pci_bus_add_devices(bus);
0479 }
0480 
0481 void __init pcibios_set_cache_line_size(void)
0482 {
0483     struct cpuinfo_x86 *c = &boot_cpu_data;
0484 
0485     /*
0486      * Set PCI cacheline size to that of the CPU if the CPU has reported it.
0487      * (For older CPUs that don't support cpuid, we se it to 32 bytes
0488      * It's also good for 386/486s (which actually have 16)
0489      * as quite a few PCI devices do not support smaller values.
0490      */
0491     if (c->x86_clflush_size > 0) {
0492         pci_dfl_cache_line_size = c->x86_clflush_size >> 2;
0493         printk(KERN_DEBUG "PCI: pci_cache_line_size set to %d bytes\n",
0494             pci_dfl_cache_line_size << 2);
0495     } else {
0496         pci_dfl_cache_line_size = 32 >> 2;
0497         printk(KERN_DEBUG "PCI: Unknown cacheline size. Setting to 32 bytes\n");
0498     }
0499 }
0500 
0501 int __init pcibios_init(void)
0502 {
0503     if (!raw_pci_ops && !raw_pci_ext_ops) {
0504         printk(KERN_WARNING "PCI: System does not support PCI\n");
0505         return 0;
0506     }
0507 
0508     pcibios_set_cache_line_size();
0509     pcibios_resource_survey();
0510 
0511     if (pci_bf_sort >= pci_force_bf)
0512         pci_sort_breadthfirst();
0513     return 0;
0514 }
0515 
0516 char *__init pcibios_setup(char *str)
0517 {
0518     if (!strcmp(str, "off")) {
0519         pci_probe = 0;
0520         return NULL;
0521     } else if (!strcmp(str, "bfsort")) {
0522         pci_bf_sort = pci_force_bf;
0523         return NULL;
0524     } else if (!strcmp(str, "nobfsort")) {
0525         pci_bf_sort = pci_force_nobf;
0526         return NULL;
0527     }
0528 #ifdef CONFIG_PCI_BIOS
0529     else if (!strcmp(str, "bios")) {
0530         pci_probe = PCI_PROBE_BIOS;
0531         return NULL;
0532     } else if (!strcmp(str, "nobios")) {
0533         pci_probe &= ~PCI_PROBE_BIOS;
0534         return NULL;
0535     } else if (!strcmp(str, "biosirq")) {
0536         pci_probe |= PCI_BIOS_IRQ_SCAN;
0537         return NULL;
0538     } else if (!strncmp(str, "pirqaddr=", 9)) {
0539         pirq_table_addr = simple_strtoul(str+9, NULL, 0);
0540         return NULL;
0541     }
0542 #endif
0543 #ifdef CONFIG_PCI_DIRECT
0544     else if (!strcmp(str, "conf1")) {
0545         pci_probe = PCI_PROBE_CONF1 | PCI_NO_CHECKS;
0546         return NULL;
0547     }
0548     else if (!strcmp(str, "conf2")) {
0549         pci_probe = PCI_PROBE_CONF2 | PCI_NO_CHECKS;
0550         return NULL;
0551     }
0552 #endif
0553 #ifdef CONFIG_PCI_MMCONFIG
0554     else if (!strcmp(str, "nommconf")) {
0555         pci_probe &= ~PCI_PROBE_MMCONF;
0556         return NULL;
0557     }
0558     else if (!strcmp(str, "check_enable_amd_mmconf")) {
0559         pci_probe |= PCI_CHECK_ENABLE_AMD_MMCONF;
0560         return NULL;
0561     }
0562 #endif
0563     else if (!strcmp(str, "noacpi")) {
0564         acpi_noirq_set();
0565         return NULL;
0566     }
0567     else if (!strcmp(str, "noearly")) {
0568         pci_probe |= PCI_PROBE_NOEARLY;
0569         return NULL;
0570     }
0571     else if (!strcmp(str, "usepirqmask")) {
0572         pci_probe |= PCI_USE_PIRQ_MASK;
0573         return NULL;
0574     } else if (!strncmp(str, "irqmask=", 8)) {
0575         pcibios_irq_mask = simple_strtol(str+8, NULL, 0);
0576         return NULL;
0577     } else if (!strncmp(str, "lastbus=", 8)) {
0578         pcibios_last_bus = simple_strtol(str+8, NULL, 0);
0579         return NULL;
0580     } else if (!strcmp(str, "rom")) {
0581         pci_probe |= PCI_ASSIGN_ROMS;
0582         return NULL;
0583     } else if (!strcmp(str, "norom")) {
0584         pci_probe |= PCI_NOASSIGN_ROMS;
0585         return NULL;
0586     } else if (!strcmp(str, "nobar")) {
0587         pci_probe |= PCI_NOASSIGN_BARS;
0588         return NULL;
0589     } else if (!strcmp(str, "assign-busses")) {
0590         pci_probe |= PCI_ASSIGN_ALL_BUSSES;
0591         return NULL;
0592     } else if (!strcmp(str, "use_crs")) {
0593         pci_probe |= PCI_USE__CRS;
0594         return NULL;
0595     } else if (!strcmp(str, "nocrs")) {
0596         pci_probe |= PCI_ROOT_NO_CRS;
0597         return NULL;
0598     } else if (!strcmp(str, "use_e820")) {
0599         pci_probe |= PCI_USE_E820;
0600         add_taint(TAINT_FIRMWARE_WORKAROUND, LOCKDEP_STILL_OK);
0601         return NULL;
0602     } else if (!strcmp(str, "no_e820")) {
0603         pci_probe |= PCI_NO_E820;
0604         add_taint(TAINT_FIRMWARE_WORKAROUND, LOCKDEP_STILL_OK);
0605         return NULL;
0606 #ifdef CONFIG_PHYS_ADDR_T_64BIT
0607     } else if (!strcmp(str, "big_root_window")) {
0608         pci_probe |= PCI_BIG_ROOT_WINDOW;
0609         return NULL;
0610 #endif
0611     } else if (!strcmp(str, "routeirq")) {
0612         pci_routeirq = 1;
0613         return NULL;
0614     } else if (!strcmp(str, "skip_isa_align")) {
0615         pci_probe |= PCI_CAN_SKIP_ISA_ALIGN;
0616         return NULL;
0617     } else if (!strcmp(str, "noioapicquirk")) {
0618         noioapicquirk = 1;
0619         return NULL;
0620     } else if (!strcmp(str, "ioapicreroute")) {
0621         if (noioapicreroute != -1)
0622             noioapicreroute = 0;
0623         return NULL;
0624     } else if (!strcmp(str, "noioapicreroute")) {
0625         if (noioapicreroute != -1)
0626             noioapicreroute = 1;
0627         return NULL;
0628     }
0629     return str;
0630 }
0631 
0632 unsigned int pcibios_assign_all_busses(void)
0633 {
0634     return (pci_probe & PCI_ASSIGN_ALL_BUSSES) ? 1 : 0;
0635 }
0636 
0637 static void set_dev_domain_options(struct pci_dev *pdev)
0638 {
0639     if (is_vmd(pdev->bus))
0640         pdev->hotplug_user_indicators = 1;
0641 }
0642 
0643 int pcibios_device_add(struct pci_dev *dev)
0644 {
0645     struct pci_setup_rom *rom;
0646     struct irq_domain *msidom;
0647     struct setup_data *data;
0648     u64 pa_data;
0649 
0650     pa_data = boot_params.hdr.setup_data;
0651     while (pa_data) {
0652         data = memremap(pa_data, sizeof(*rom), MEMREMAP_WB);
0653         if (!data)
0654             return -ENOMEM;
0655 
0656         if (data->type == SETUP_PCI) {
0657             rom = (struct pci_setup_rom *)data;
0658 
0659             if ((pci_domain_nr(dev->bus) == rom->segment) &&
0660                 (dev->bus->number == rom->bus) &&
0661                 (PCI_SLOT(dev->devfn) == rom->device) &&
0662                 (PCI_FUNC(dev->devfn) == rom->function) &&
0663                 (dev->vendor == rom->vendor) &&
0664                 (dev->device == rom->devid)) {
0665                 dev->rom = pa_data +
0666                       offsetof(struct pci_setup_rom, romdata);
0667                 dev->romlen = rom->pcilen;
0668             }
0669         }
0670         pa_data = data->next;
0671         memunmap(data);
0672     }
0673     set_dev_domain_options(dev);
0674 
0675     /*
0676      * Setup the initial MSI domain of the device. If the underlying
0677      * bus has a PCI/MSI irqdomain associated use the bus domain,
0678      * otherwise set the default domain. This ensures that special irq
0679      * domains e.g. VMD are preserved. The default ensures initial
0680      * operation if irq remapping is not active. If irq remapping is
0681      * active it will overwrite the domain pointer when the device is
0682      * associated to a remapping domain.
0683      */
0684     msidom = dev_get_msi_domain(&dev->bus->dev);
0685     if (!msidom)
0686         msidom = x86_pci_msi_default_domain;
0687     dev_set_msi_domain(&dev->dev, msidom);
0688     return 0;
0689 }
0690 
0691 int pcibios_enable_device(struct pci_dev *dev, int mask)
0692 {
0693     int err;
0694 
0695     if ((err = pci_enable_resources(dev, mask)) < 0)
0696         return err;
0697 
0698     if (!pci_dev_msi_enabled(dev))
0699         return pcibios_enable_irq(dev);
0700     return 0;
0701 }
0702 
0703 void pcibios_disable_device (struct pci_dev *dev)
0704 {
0705     if (!pci_dev_msi_enabled(dev) && pcibios_disable_irq)
0706         pcibios_disable_irq(dev);
0707 }
0708 
0709 #ifdef CONFIG_ACPI_HOTPLUG_IOAPIC
0710 void pcibios_release_device(struct pci_dev *dev)
0711 {
0712     if (atomic_dec_return(&dev->enable_cnt) >= 0)
0713         pcibios_disable_device(dev);
0714 
0715 }
0716 #endif
0717 
0718 int pci_ext_cfg_avail(void)
0719 {
0720     if (raw_pci_ext_ops)
0721         return 1;
0722     else
0723         return 0;
0724 }
0725 
0726 #if IS_ENABLED(CONFIG_VMD)
0727 struct pci_dev *pci_real_dma_dev(struct pci_dev *dev)
0728 {
0729     if (is_vmd(dev->bus))
0730         return to_pci_sysdata(dev->bus)->vmd_dev;
0731 
0732     return dev;
0733 }
0734 #endif