blob: 0c24dc8c5f6b77defd82d0cd018a7474869aa469 [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
10/**
Patrick Venture5251da92019-01-17 11:25:26 -080011 * Different LPC (or P2a) memory map implementations may require different
12 * mechanisms for specific tasks such as mapping the memory window or copying
13 * out data.
Patrick Venturee7728422018-11-14 20:16:33 -080014 */
Patrick Venture5251da92019-01-17 11:25:26 -080015class HardwareMapperInterface
Patrick Venturee7728422018-11-14 20:16:33 -080016{
17 public:
Patrick Venture5251da92019-01-17 11:25:26 -080018 virtual ~HardwareMapperInterface() = default;
Patrick Venturee7728422018-11-14 20:16:33 -080019
20 /**
Patrick Venture2343cfc2019-01-17 13:04:36 -080021 * Close the mapper. This could mean, send an ioctl to turn off the region,
22 * or unmap anything mmapped.
23 */
24 virtual void close() = 0;
25
26 /**
Patrick Venturee7728422018-11-14 20:16:33 -080027 * Returns a windowOffset and windowSize if the requested window was mapped.
28 *
29 * TODO: If the length requested is too large, windowSize will be written
30 * with the max size that the BMC can map and returns false.
31 *
32 * @param[in] address - The address for mapping (passed to LPC window)
33 * @param[in] length - The length of the region
34 * @return windowOffset, windowSize - The offset into the window and
35 * length of the region. On failure, length is set to 0.
36 */
37 virtual std::pair<std::uint32_t, std::uint32_t>
38 mapWindow(std::uint32_t address, std::uint32_t length) = 0;
Patrick Venture517710d2019-01-17 11:37:40 -080039
40 /**
41 * Returns the bytes from the mapped window.
42 *
43 * @param[in] length - the number of bytes to copy.
44 * @return the bytes copied out of the region.
45 */
46 virtual std::vector<std::uint8_t> copyFrom(std::uint32_t length) = 0;
Patrick Venturee7728422018-11-14 20:16:33 -080047};
48
Patrick Venture1d5a31c2019-05-20 11:38:22 -070049} // namespace ipmi_flash