[PATCH kvm-unit-tests 5/5] lib/pci: reduce library noise

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Avoid printfs in library code unless in a printing function, e.g.
pci_dev_print. Particularly we can avoid printing anything the
caller can easily print themselves, if so desired.

Signed-off-by: Andrew Jones <drjones@xxxxxxxxxx>
---
 lib/pci.c             | 23 +++++++++++++++++------
 lib/x86/intel-iommu.c |  3 +++
 x86/intel-iommu.c     |  2 ++
 3 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/lib/pci.c b/lib/pci.c
index 8ceb8ef91c75..62b1c6b0b7c5 100644
--- a/lib/pci.c
+++ b/lib/pci.c
@@ -16,7 +16,6 @@ void pci_cap_walk(struct pci_dev *dev, pci_cap_handler_t handler)
 	cap_offset = pci_config_readb(dev->bdf, PCI_CAPABILITY_LIST);
 	while (cap_offset) {
 		cap_id = pci_config_readb(dev->bdf, cap_offset);
-		printf("PCI detected cap 0x%x\n", cap_id);
 		assert(cap_id < PCI_CAP_ID_MAX + 1);
 		handler(dev, cap_offset, cap_id);
 		cap_offset = pci_config_readb(dev->bdf, cap_offset + 1);
@@ -64,12 +63,9 @@ bool pci_setup_msi(struct pci_dev *dev, uint64_t msi_addr, uint32_t msi_data)
 		pci_config_writel(addr, offset + PCI_MSI_ADDRESS_HI,
 				  (uint32_t)(msi_addr >> 32));
 		pci_config_writel(addr, offset + PCI_MSI_DATA_64, msi_data);
-		printf("MSI: dev 0x%x init 64bit address: ", addr);
 	} else {
 		pci_config_writel(addr, offset + PCI_MSI_DATA_32, msi_data);
-		printf("MSI: dev 0x%x init 32bit address: ", addr);
 	}
-	printf("addr=0x%" PRIx64 ", data=0x%x\n", msi_addr, msi_data);
 
 	pci_msi_set_enable(dev, true);
 
@@ -274,6 +270,21 @@ void pci_dev_print_id(pcidevaddr_t dev)
 		pci_config_readw(dev, PCI_DEVICE_ID));
 }
 
+static void pci_cap_print(struct pci_dev *dev, int cap_offset, int cap_id)
+{
+	switch (cap_id) {
+	case PCI_CAP_ID_MSI: {
+		uint16_t control = pci_config_readw(dev->bdf, cap_offset + PCI_MSI_FLAGS);
+		printf("\tMSI,%s-bit capability ", control & PCI_MSI_FLAGS_64BIT ? "64" : "32");
+		break;
+	}
+	default:
+		printf("\tcapability 0x%02x ", cap_id);
+		break;
+	}
+	printf("at offset 0x%02x\n", cap_offset);
+}
+
 void pci_dev_print(pcidevaddr_t dev)
 {
 	uint8_t header = pci_config_readb(dev, PCI_HEADER_TYPE);
@@ -289,6 +300,8 @@ void pci_dev_print(pcidevaddr_t dev)
 	printf(" type %02x progif %02x class %02x subclass %02x\n",
 	       header, progif, class, subclass);
 
+	pci_cap_walk(&pci_dev, pci_cap_print);
+
 	if ((header & PCI_HEADER_TYPE_MASK) != PCI_HEADER_TYPE_NORMAL)
 		return;
 
@@ -337,8 +350,6 @@ static void pci_cap_setup(struct pci_dev *dev, int cap_offset, int cap_id)
 {
 	switch (cap_id) {
 	case PCI_CAP_ID_MSI:
-		printf("Detected MSI for device 0x%x offset 0x%x\n",
-			dev->bdf, cap_offset);
 		dev->msi_offset = cap_offset;
 		break;
 	}
diff --git a/lib/x86/intel-iommu.c b/lib/x86/intel-iommu.c
index c35b758d1383..7cc5a702aed4 100644
--- a/lib/x86/intel-iommu.c
+++ b/lib/x86/intel-iommu.c
@@ -324,6 +324,9 @@ bool vtd_setup_msi(struct pci_dev *dev, int vector, int dest_id)
 	msi_addr.head = 0xfee;
 	msi_data.subhandle = 0;
 
+	printf("%s: msi_addr=0x%" PRIx64 ", msi_data=0x%x\n", __func__,
+		*(uint64_t *)&msi_addr, *(uint32_t *)&msi_data);
+
 	return pci_setup_msi(dev, *(uint64_t *)&msi_addr,
 			     *(uint32_t *)&msi_data);
 }
diff --git a/x86/intel-iommu.c b/x86/intel-iommu.c
index d1fa420aab9e..a01b23e674a8 100644
--- a/x86/intel-iommu.c
+++ b/x86/intel-iommu.c
@@ -153,6 +153,8 @@ int main(int argc, char *argv[])
 		report_skip(VTD_TEST_IR_IOAPIC);
 		report_skip(VTD_TEST_IR_MSI);
 	} else {
+		printf("Found EDU device:\n");
+		pci_dev_print(edu_dev.pci_dev.bdf);
 		vtd_test_dmar();
 		vtd_test_ir();
 	}
-- 
2.9.3

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux