diff mbox

[kvm-unit-tests,v3,6/8] x86: move x86/pci to the common lib

Message ID 1453140064-9040-7-git-send-email-drjones@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Andrew Jones Jan. 18, 2016, 6:01 p.m. UTC
Also move pci_config_read into asm/pci.h

Signed-off-by: Andrew Jones <drjones@redhat.com>
Reviewed-by: Radim Kr?má? <rkrcmar@redhat.com>
---
 config/config-x86-common.mak |  2 +-
 lib/asm-generic/pci.h        |  4 ++++
 lib/{x86 => }/pci.c          | 14 ++++++--------
 lib/{x86 => }/pci.h          |  9 ++++++++-
 lib/x86/asm/pci.h            | 19 +++++++++++++++++++
 x86/vmexit.c                 |  2 +-
 6 files changed, 39 insertions(+), 11 deletions(-)
 create mode 100644 lib/asm-generic/pci.h
 rename lib/{x86 => }/pci.c (84%)
 rename lib/{x86 => }/pci.h (60%)
 create mode 100644 lib/x86/asm/pci.h
diff mbox

Patch

diff --git a/config/config-x86-common.mak b/config/config-x86-common.mak
index 4a2746826784c..3a14feaaa7748 100644
--- a/config/config-x86-common.mak
+++ b/config/config-x86-common.mak
@@ -2,6 +2,7 @@ 
 
 all: test_cases
 
+cflatobjs += lib/pci.o
 cflatobjs += lib/x86/io.o
 cflatobjs += lib/x86/smp.o
 cflatobjs += lib/x86/vm.o
@@ -10,7 +11,6 @@  cflatobjs += lib/x86/apic.o
 cflatobjs += lib/x86/atomic.o
 cflatobjs += lib/x86/desc.o
 cflatobjs += lib/x86/isr.o
-cflatobjs += lib/x86/pci.o
 cflatobjs += lib/x86/acpi.o
 
 $(libcflat): LDFLAGS += -nostdlib
diff --git a/lib/asm-generic/pci.h b/lib/asm-generic/pci.h
new file mode 100644
index 0000000000000..3fa0b2ab1fe64
--- /dev/null
+++ b/lib/asm-generic/pci.h
@@ -0,0 +1,4 @@ 
+#ifndef _ASM_GENERIC_PCI_H_
+#define _ASM_GENERIC_PCI_H_
+#error need architecture specific asm/pci.h
+#endif
diff --git a/lib/x86/pci.c b/lib/pci.c
similarity index 84%
rename from lib/x86/pci.c
rename to lib/pci.c
index 6aa6d70353127..0058d70c888d8 100644
--- a/lib/x86/pci.c
+++ b/lib/pci.c
@@ -1,13 +1,11 @@ 
+/*
+ * Copyright (C) 2013, Red Hat Inc, Michael S. Tsirkin <mst@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.
+ */
 #include <linux/pci_regs.h>
 #include "pci.h"
-#include "io.h"
-
-static uint32_t pci_config_read(pcidevaddr_t dev, uint8_t reg)
-{
-    uint32_t index = reg | (dev << 8) | (0x1 << 31); 
-    outl(index, 0xCF8);
-    return inl(0xCFC);
-}
+#include "asm/pci.h"
 
 /* Scan bus look for a specific device. Only bus 0 scanned for now. */
 pcidevaddr_t pci_find_dev(uint16_t vendor_id, uint16_t device_id)
diff --git a/lib/x86/pci.h b/lib/pci.h
similarity index 60%
rename from lib/x86/pci.h
rename to lib/pci.h
index 046e68f9a65b6..65fcd9444461c 100644
--- a/lib/x86/pci.h
+++ b/lib/pci.h
@@ -1,6 +1,13 @@ 
 #ifndef PCI_H
 #define PCI_H
-
+/*
+ * API for scanning a PCI bus for a given device, as well to access
+ * BAR registers.
+ *
+ * Copyright (C) 2013, Red Hat Inc, Michael S. Tsirkin <mst@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.
+ */
 #include "libcflat.h"
 
 typedef uint16_t pcidevaddr_t;
diff --git a/lib/x86/asm/pci.h b/lib/x86/asm/pci.h
new file mode 100644
index 0000000000000..4ec20e17d25bb
--- /dev/null
+++ b/lib/x86/asm/pci.h
@@ -0,0 +1,19 @@ 
+#ifndef ASM_PCI_H
+#define ASM_PCI_H
+/*
+ * Copyright (C) 2013, Red Hat Inc, Michael S. Tsirkin <mst@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.
+ */
+#include "libcflat.h"
+#include "pci.h"
+#include "x86/io.h"
+
+static inline uint32_t pci_config_read(pcidevaddr_t dev, uint8_t reg)
+{
+    uint32_t index = reg | (dev << 8) | (0x1 << 31);
+    outl(index, 0xCF8);
+    return inl(0xCFC);
+}
+
+#endif
diff --git a/x86/vmexit.c b/x86/vmexit.c
index e9f240872788a..81ac7a88fda93 100644
--- a/x86/vmexit.c
+++ b/x86/vmexit.c
@@ -2,9 +2,9 @@ 
 #include "smp.h"
 #include "processor.h"
 #include "atomic.h"
+#include "pci.h"
 #include "x86/vm.h"
 #include "x86/desc.h"
-#include "x86/pci.h"
 #include "x86/acpi.h"
 #include "x86/io.h"