xref: /openbmc/phosphor-ipmi-flash/tools/p2a.hpp (revision 9b37b095)
1 #pragma once
2 
3 #include "interface.hpp"
4 #include "internal/sys.hpp"
5 #include "io.hpp"
6 #include "pci.hpp"
7 #include "progress.hpp"
8 
9 #include <ipmiblob/blob_interface.hpp>
10 
11 #include <cstdint>
12 #include <vector>
13 
14 constexpr std::size_t aspeedP2aConfig = 0x0f000;
15 constexpr std::size_t aspeedP2aBridge = 0x0f004;
16 constexpr std::uint32_t p2ABridgeEnabled = 0x1;
17 
18 struct PciDeviceInfo
19 {
20     std::uint16_t VID;
21     std::uint16_t DID;
22     std::size_t Offset;
23     std::size_t Length;
24     std::uint16_t bar;
25 };
26 
27 namespace host_tool
28 {
29 
30 class P2aDataHandler : public DataInterface
31 {
32   public:
33     P2aDataHandler(ipmiblob::BlobInterface* blob, HostIoInterface* io,
34                    PciUtilInterface* pci, ProgressInterface* progress,
35                    const internal::Sys* sys = &internal::sys_impl) :
36         blob(blob),
37         io(io), pci(pci), progress(progress), sys(sys)
38     {}
39 
40     bool sendContents(const std::string& input, std::uint16_t session) override;
41     ipmi_flash::FirmwareFlags::UpdateFlags supportedType() const override
42     {
43         return ipmi_flash::FirmwareFlags::UpdateFlags::p2a;
44     }
45 
46   private:
47     ipmiblob::BlobInterface* blob;
48     HostIoInterface* io;
49     PciUtilInterface* pci;
50     ProgressInterface* progress;
51     const internal::Sys* sys;
52 
53     constexpr struct PciDeviceInfo static aspeedPciDeviceInfo = {
54         0x1a03, 0x2000, 0x10000, 0x10000, 1};
55     constexpr struct PciDeviceInfo static nuvotonPciDeviceInfo = {
56         0x1050, 0x0750, 0x0, 0x4000, 0};
57     const std::vector<PciDeviceInfo> PCIDeviceList = {aspeedPciDeviceInfo,
58                                                       nuvotonPciDeviceInfo};
59 };
60 } // namespace host_tool
61