tools/pci: refactor PCI bridge

Use polymorphism to handle the differences between Aspeed and Nuvoton
PCI devices.

Add unit tests (now at 100% line coverage for tools/pci.cpp).

Signed-off-by: Benjamin Fair <benjaminfair@google.com>
Change-Id: I43e63ec5eb9fce5fb0fc74e0e69667dd13b7433f
diff --git a/tools/p2a.hpp b/tools/p2a.hpp
index 1d1cb2d..08153d2 100644
--- a/tools/p2a.hpp
+++ b/tools/p2a.hpp
@@ -2,7 +2,6 @@
 
 #include "interface.hpp"
 #include "internal/sys.hpp"
-#include "io.hpp"
 #include "pci.hpp"
 #include "progress.hpp"
 
@@ -11,30 +10,17 @@
 #include <cstdint>
 #include <vector>
 
-constexpr std::size_t aspeedP2aConfig = 0x0f000;
-constexpr std::size_t aspeedP2aBridge = 0x0f004;
-constexpr std::uint32_t p2ABridgeEnabled = 0x1;
-
-struct PciDeviceInfo
-{
-    std::uint16_t VID;
-    std::uint16_t DID;
-    std::size_t Offset;
-    std::size_t Length;
-    std::uint16_t bar;
-};
-
 namespace host_tool
 {
 
 class P2aDataHandler : public DataInterface
 {
   public:
-    P2aDataHandler(ipmiblob::BlobInterface* blob, HostIoInterface* io,
-                   PciUtilInterface* pci, ProgressInterface* progress,
+    P2aDataHandler(ipmiblob::BlobInterface* blob, const PciAccess* pci,
+                   ProgressInterface* progress,
                    const internal::Sys* sys = &internal::sys_impl) :
         blob(blob),
-        io(io), pci(pci), progress(progress), sys(sys)
+        pci(pci), progress(progress), sys(sys)
     {}
 
     bool sendContents(const std::string& input, std::uint16_t session) override;
@@ -45,16 +31,9 @@
 
   private:
     ipmiblob::BlobInterface* blob;
-    HostIoInterface* io;
-    PciUtilInterface* pci;
+    const PciAccess* pci;
     ProgressInterface* progress;
     const internal::Sys* sys;
-
-    constexpr struct PciDeviceInfo static aspeedPciDeviceInfo = {
-        0x1a03, 0x2000, 0x10000, 0x10000, 1};
-    constexpr struct PciDeviceInfo static nuvotonPciDeviceInfo = {
-        0x1050, 0x0750, 0x0, 0x4000, 0};
-    const std::vector<PciDeviceInfo> PCIDeviceList = {aspeedPciDeviceInfo,
-                                                      nuvotonPciDeviceInfo};
 };
+
 } // namespace host_tool