blob: ec974cafcb48471b37d647a022339a5c0ed5e9e7 [file] [log] [blame]
Patrick Venture1cde5f92018-11-07 08:26:47 -08001#pragma once
2
3#include "data_handler.hpp"
Patrick Venture5251da92019-01-17 11:25:26 -08004#include "window_hw_interface.hpp"
Patrick Venture1cde5f92018-11-07 08:26:47 -08005
6#include <cstdint>
Patrick Venturee7728422018-11-14 20:16:33 -08007#include <memory>
Patrick Venture1cde5f92018-11-07 08:26:47 -08008#include <vector>
9
Patrick Venture1d5a31c2019-05-20 11:38:22 -070010namespace ipmi_flash
Patrick Venture1cde5f92018-11-07 08:26:47 -080011{
12
Patrick Venture8c535332018-11-08 15:58:00 -080013struct LpcRegion
14{
15 /* Host LPC address where the chunk is to be mapped. */
16 std::uint32_t address;
17
18 /* Size of the chunk to be mapped. */
19 std::uint32_t length;
20} __attribute__((packed));
21
22/**
23 * Data Handler for configuration the ASPEED LPC memory region, reading and
24 * writing data.
25 */
Patrick Venture1cde5f92018-11-07 08:26:47 -080026class LpcDataHandler : public DataInterface
27{
Patrick Venture1cde5f92018-11-07 08:26:47 -080028 public:
Patrick Venturee7728422018-11-14 20:16:33 -080029 /**
30 * Create an LpcDataHandler.
31 *
32 * @param[in] mapper - pointer to a mapper implementation to use.
33 */
Patrick Venture78b1a662019-01-17 12:38:26 -080034 explicit LpcDataHandler(std::unique_ptr<HardwareMapperInterface> mapper) :
Patrick Venture09c4f7a2018-11-16 20:28:04 -080035 mapper(std::move(mapper)), initialized(false)
Patrick Venture9b37b092020-05-28 20:58:57 -070036 {}
Patrick Venture1cde5f92018-11-07 08:26:47 -080037
Patrick Venture0d2a8132018-11-09 11:34:21 -080038 bool open() override;
Patrick Venture0fbabf22018-11-09 11:54:12 -080039 bool close() override;
Patrick Venture1cde5f92018-11-07 08:26:47 -080040 std::vector<std::uint8_t> copyFrom(std::uint32_t length) override;
Patrick Venture74304642019-01-17 09:31:04 -080041 bool writeMeta(const std::vector<std::uint8_t>& configuration) override;
42 std::vector<std::uint8_t> readMeta() override;
Patrick Venturee7728422018-11-14 20:16:33 -080043
44 private:
Patrick Venturea6065502020-10-26 13:06:40 -070045 bool setInitializedAndReturn(bool value);
Patrick Venture09c4f7a2018-11-16 20:28:04 -080046
Patrick Venture5251da92019-01-17 11:25:26 -080047 std::unique_ptr<HardwareMapperInterface> mapper;
Patrick Venture09c4f7a2018-11-16 20:28:04 -080048 bool initialized;
Patrick Venture36bffb42019-06-24 10:47:47 -070049 /* The LPC Handler does not take ownership of this, in case there's cleanup
50 * required for close()
51 */
52 MemorySet memory = {};
53
54 /* Offset in reserved memory at which host data arrives. */
55 /* Size of the chunk of the memory region in use by the host (e.g.
56 * mapped over external block mechanism).
57 */
58 WindowMapResult mappingResult = {};
Patrick Venture1cde5f92018-11-07 08:26:47 -080059};
60
Patrick Venture1d5a31c2019-05-20 11:38:22 -070061} // namespace ipmi_flash