1 #pragma once
2 
3 #include "internal/sys.hpp"
4 #include "window_hw_interface.hpp"
5 
6 #include <cstdint>
7 #include <memory>
8 #include <utility>
9 #include <vector>
10 
11 namespace ipmi_flash
12 {
13 
14 class LpcMapperNuvoton : public HardwareMapperInterface
15 {
16   public:
17     static std::unique_ptr<HardwareMapperInterface> createNuvotonMapper(
18         std::uint32_t regionAddress, std::uint32_t regionSize);
19 
20     /**
21      * Create an LpcMapper for Nuvoton.
22      *
23      * @param[in] regionAddress - where to map the window into BMC memory.
24      * @param[in] regionSize - the size to map for copying data.
25      * @param[in] a sys call interface pointer.
26      * @todo Needs reserved memory region's physical address and size.
27      */
LpcMapperNuvoton(std::uint32_t regionAddress,std::uint32_t regionSize,const internal::Sys * sys=& internal::sys_impl)28     LpcMapperNuvoton(std::uint32_t regionAddress, std::uint32_t regionSize,
29                      const internal::Sys* sys = &internal::sys_impl) :
30         regionAddress(regionAddress), memoryRegionSize(regionSize), sys(sys) {};
31 
32     /** Attempt to map the window for copying bytes, after mapWindow is called.
33      * throws MapperException
34      */
35     MemorySet open() override;
36 
37     void close() override;
38 
39     WindowMapResult mapWindow(std::uint32_t address,
40                               std::uint32_t length) override;
41 
42   private:
43     std::uint32_t regionAddress;
44     std::uint32_t memoryRegionSize;
45     const internal::Sys* sys;
46 
47     /* The file handle to /dev/mem. */
48     int mappedFd = -1;
49 
50     /* The pointer to the memory-mapped region. */
51     std::uint8_t* mapped = nullptr;
52 };
53 
54 } // namespace ipmi_flash
55