xref: /openbmc/phosphor-ipmi-flash/bmc/firmware-handler/lpc_aspeed.hpp (revision 42a44c281cce08be0ca6251955f4fb73d30c8ced)
1 #pragma once
2 
3 #include "internal/sys.hpp"
4 #include "window_hw_interface.hpp"
5 
6 #include <cstdint>
7 #include <memory>
8 #include <string>
9 #include <utility>
10 #include <vector>
11 
12 namespace ipmi_flash
13 {
14 
15 class LpcMapperAspeed : public HardwareMapperInterface
16 {
17   public:
18     static std::unique_ptr<HardwareMapperInterface>
19         createAspeedMapper(std::uint32_t regionAddress, std::size_t regionSize);
20 
21     /* NOTE: This object is created and then never destroyed (unless ipmid
22      * stops/crashes, etc)
23      */
LpcMapperAspeed(std::uint32_t regionAddress,std::size_t regionSize,const internal::Sys * sys=& internal::sys_impl)24     LpcMapperAspeed(std::uint32_t regionAddress, std::size_t regionSize,
25                     const internal::Sys* sys = &internal::sys_impl) :
26         regionAddress(regionAddress), regionSize(regionSize), sys(sys) {};
27 
28     LpcMapperAspeed(const LpcMapperAspeed&) = delete;
29     LpcMapperAspeed& operator=(const LpcMapperAspeed&) = delete;
30     LpcMapperAspeed(LpcMapperAspeed&&) = default;
31     LpcMapperAspeed& operator=(LpcMapperAspeed&&) = default;
32 
33     /* throws MapperException */
34     MemorySet open() override;
35 
36     void close() override;
37 
38     WindowMapResult mapWindow(std::uint32_t address,
39                               std::uint32_t length) override;
40 
41     /**
42      * Attempt to mmap the region.
43      *
44      * @return true on success, false otherwise.
45      */
46     bool mapRegion();
47 
48   private:
49     static const std::string lpcControlPath;
50     int mappedFd = -1;
51     std::uint8_t* mappedRegion = nullptr;
52     std::uint32_t regionAddress;
53     std::size_t regionSize;
54     const internal::Sys* sys;
55 };
56 
57 } // namespace ipmi_flash
58