1 #pragma once
2 
3 #include <cstdint>
4 #include <utility>
5 #include <vector>
6 
7 namespace ipmi_flash
8 {
9 
10 struct MemorySet
11 {
12     int mappedFd = -1;
13     std::uint8_t* mapped = nullptr;
14 };
15 
16 /** The result from the mapWindow command. */
17 struct WindowMapResult
18 {
19     /* The response can validly be 0, or EFBIG.  If it's EFBIG that means the
20      * region available is within the requested region. If the value is anything
21      * else, it's a complete failure.
22      */
23     std::uint8_t response;
24     std::uint32_t windowOffset;
25     std::uint32_t windowSize;
26 };
27 
28 /**
29  * Different LPC (or P2a) memory map implementations may require different
30  * mechanisms for specific tasks such as mapping the memory window or copying
31  * out data.
32  */
33 class HardwareMapperInterface
34 {
35   public:
36     virtual ~HardwareMapperInterface() = default;
37 
38     /**
39      * Open the driver or whatever and map the region.
40      */
41     virtual MemorySet open() = 0;
42 
43     /**
44      * Close the mapper.  This could mean, send an ioctl to turn off the region,
45      * or unmap anything mmapped.
46      */
47     virtual void close() = 0;
48 
49     /**
50      * Returns a windowOffset and windowSize if the requested window was mapped.
51      *
52      * TODO: If the length requested is too large, windowSize will be written
53      * with the max size that the BMC can map and returns false.
54      *
55      * @param[in] address - The address for mapping (passed to LPC window)
56      * @param[in] length - The length of the region
57      * @return WindowMapResult - the result of the call
58      */
59     virtual WindowMapResult mapWindow(std::uint32_t address,
60                                       std::uint32_t length) = 0;
61 };
62 
63 } // namespace ipmi_flash
64