blob: 7d15521e468d11dfeeb5d7f5fe5840f15612738c [file] [log] [blame]
Patrick Venturee7728422018-11-14 20:16:33 -08001#pragma once
2
3#include <cstdint>
4#include <utility>
Patrick Venture517710d2019-01-17 11:37:40 -08005#include <vector>
Patrick Venturee7728422018-11-14 20:16:33 -08006
Patrick Venture1d5a31c2019-05-20 11:38:22 -07007namespace ipmi_flash
Patrick Venturee7728422018-11-14 20:16:33 -08008{
9
Patrick Venture36bffb42019-06-24 10:47:47 -070010struct MemorySet
11{
12 int mappedFd = -1;
13 std::uint8_t* mapped = nullptr;
14};
15
16/** The result from the mapWindow command. */
17struct 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
Patrick Venturee7728422018-11-14 20:16:33 -080028/**
Patrick Venture5251da92019-01-17 11:25:26 -080029 * 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.
Patrick Venturee7728422018-11-14 20:16:33 -080032 */
Patrick Venture5251da92019-01-17 11:25:26 -080033class HardwareMapperInterface
Patrick Venturee7728422018-11-14 20:16:33 -080034{
35 public:
Patrick Venture5251da92019-01-17 11:25:26 -080036 virtual ~HardwareMapperInterface() = default;
Patrick Venturee7728422018-11-14 20:16:33 -080037
38 /**
Patrick Venture36bffb42019-06-24 10:47:47 -070039 * Open the driver or whatever and map the region.
40 */
41 virtual MemorySet open() = 0;
42
43 /**
Patrick Venture2343cfc2019-01-17 13:04:36 -080044 * 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 /**
Patrick Venturee7728422018-11-14 20:16:33 -080050 * 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
Patrick Venture36bffb42019-06-24 10:47:47 -070057 * @return WindowMapResult - the result of the call
Patrick Venturee7728422018-11-14 20:16:33 -080058 */
Patrick Venture36bffb42019-06-24 10:47:47 -070059 virtual WindowMapResult mapWindow(std::uint32_t address,
60 std::uint32_t length) = 0;
Patrick Venturee7728422018-11-14 20:16:33 -080061};
62
Patrick Venture1d5a31c2019-05-20 11:38:22 -070063} // namespace ipmi_flash