hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/arch/x86/pci/common.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Low-Level PCI Support for PC
34 *
....@@ -18,6 +19,7 @@
1819 #include <asm/smp.h>
1920 #include <asm/pci_x86.h>
2021 #include <asm/setup.h>
22
+#include <asm/irqdomain.h>
2123
2224 unsigned int pci_probe = PCI_PROBE_BIOS | PCI_PROBE_CONF1 | PCI_PROBE_CONF2 |
2325 PCI_PROBE_MMCONF;
....@@ -134,7 +136,7 @@
134136 * resource so the kernel doesn't attempt to assign
135137 * it later on in pci_assign_unassigned_resources
136138 */
137
- for (bar = 0; bar <= PCI_STD_RESOURCE_END; bar++) {
139
+ for (bar = 0; bar < PCI_STD_NUM_BARS; bar++) {
138140 bar_r = &dev->resource[bar];
139141 if (bar_r->start == 0 && bar_r->end != 0) {
140142 bar_r->flags = 0;
....@@ -624,43 +626,6 @@
624626 return (pci_probe & PCI_ASSIGN_ALL_BUSSES) ? 1 : 0;
625627 }
626628
627
-#if defined(CONFIG_X86_DEV_DMA_OPS) && defined(CONFIG_PCI_DOMAINS)
628
-static LIST_HEAD(dma_domain_list);
629
-static DEFINE_SPINLOCK(dma_domain_list_lock);
630
-
631
-void add_dma_domain(struct dma_domain *domain)
632
-{
633
- spin_lock(&dma_domain_list_lock);
634
- list_add(&domain->node, &dma_domain_list);
635
- spin_unlock(&dma_domain_list_lock);
636
-}
637
-EXPORT_SYMBOL_GPL(add_dma_domain);
638
-
639
-void del_dma_domain(struct dma_domain *domain)
640
-{
641
- spin_lock(&dma_domain_list_lock);
642
- list_del(&domain->node);
643
- spin_unlock(&dma_domain_list_lock);
644
-}
645
-EXPORT_SYMBOL_GPL(del_dma_domain);
646
-
647
-static void set_dma_domain_ops(struct pci_dev *pdev)
648
-{
649
- struct dma_domain *domain;
650
-
651
- spin_lock(&dma_domain_list_lock);
652
- list_for_each_entry(domain, &dma_domain_list, node) {
653
- if (pci_domain_nr(pdev->bus) == domain->domain_nr) {
654
- pdev->dev.dma_ops = domain->dma_ops;
655
- break;
656
- }
657
- }
658
- spin_unlock(&dma_domain_list_lock);
659
-}
660
-#else
661
-static void set_dma_domain_ops(struct pci_dev *pdev) {}
662
-#endif
663
-
664629 static void set_dev_domain_options(struct pci_dev *pdev)
665630 {
666631 if (is_vmd(pdev->bus))
....@@ -669,8 +634,9 @@
669634
670635 int pcibios_add_device(struct pci_dev *dev)
671636 {
672
- struct setup_data *data;
673637 struct pci_setup_rom *rom;
638
+ struct irq_domain *msidom;
639
+ struct setup_data *data;
674640 u64 pa_data;
675641
676642 pa_data = boot_params.hdr.setup_data;
....@@ -696,8 +662,21 @@
696662 pa_data = data->next;
697663 memunmap(data);
698664 }
699
- set_dma_domain_ops(dev);
700665 set_dev_domain_options(dev);
666
+
667
+ /*
668
+ * Setup the initial MSI domain of the device. If the underlying
669
+ * bus has a PCI/MSI irqdomain associated use the bus domain,
670
+ * otherwise set the default domain. This ensures that special irq
671
+ * domains e.g. VMD are preserved. The default ensures initial
672
+ * operation if irq remapping is not active. If irq remapping is
673
+ * active it will overwrite the domain pointer when the device is
674
+ * associated to a remapping domain.
675
+ */
676
+ msidom = dev_get_msi_domain(&dev->bus->dev);
677
+ if (!msidom)
678
+ msidom = x86_pci_msi_default_domain;
679
+ dev_set_msi_domain(&dev->dev, msidom);
701680 return 0;
702681 }
703682
....@@ -735,3 +714,13 @@
735714 else
736715 return 0;
737716 }
717
+
718
+#if IS_ENABLED(CONFIG_VMD)
719
+struct pci_dev *pci_real_dma_dev(struct pci_dev *dev)
720
+{
721
+ if (is_vmd(dev->bus))
722
+ return to_pci_sysdata(dev->bus)->vmd_dev;
723
+
724
+ return dev;
725
+}
726
+#endif