Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <cstdint> |
| 4 | #include <utility> |
Patrick Venture | 517710d | 2019-01-17 11:37:40 -0800 | [diff] [blame] | 5 | #include <vector> |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 6 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 7 | namespace ipmi_flash |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 8 | { |
| 9 | |
Patrick Venture | 36bffb4 | 2019-06-24 10:47:47 -0700 | [diff] [blame] | 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 | |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 28 | /** |
Patrick Venture | 5251da9 | 2019-01-17 11:25:26 -0800 | [diff] [blame] | 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. |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 32 | */ |
Patrick Venture | 5251da9 | 2019-01-17 11:25:26 -0800 | [diff] [blame] | 33 | class HardwareMapperInterface |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 34 | { |
| 35 | public: |
Patrick Venture | 5251da9 | 2019-01-17 11:25:26 -0800 | [diff] [blame] | 36 | virtual ~HardwareMapperInterface() = default; |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 37 | |
| 38 | /** |
Patrick Venture | 36bffb4 | 2019-06-24 10:47:47 -0700 | [diff] [blame] | 39 | * Open the driver or whatever and map the region. |
| 40 | */ |
| 41 | virtual MemorySet open() = 0; |
| 42 | |
| 43 | /** |
Patrick Venture | 2343cfc | 2019-01-17 13:04:36 -0800 | [diff] [blame] | 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 | /** |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 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 |
Patrick Venture | 36bffb4 | 2019-06-24 10:47:47 -0700 | [diff] [blame] | 57 | * @return WindowMapResult - the result of the call |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 58 | */ |
Patrick Venture | 36bffb4 | 2019-06-24 10:47:47 -0700 | [diff] [blame] | 59 | virtual WindowMapResult mapWindow(std::uint32_t address, |
| 60 | std::uint32_t length) = 0; |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 61 | }; |
| 62 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 63 | } // namespace ipmi_flash |