1 #pragma once
2 
3 #include "data_handler.hpp"
4 #include "window_hw_interface.hpp"
5 
6 #include <cstdint>
7 #include <memory>
8 #include <vector>
9 
10 namespace ipmi_flash
11 {
12 
13 struct 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  */
26 class LpcDataHandler : public DataInterface
27 {
28   public:
29     /**
30      * Create an LpcDataHandler.
31      *
32      * @param[in] mapper - pointer to a mapper implementation to use.
33      */
LpcDataHandler(std::unique_ptr<HardwareMapperInterface> mapper)34     explicit LpcDataHandler(std::unique_ptr<HardwareMapperInterface> mapper) :
35         mapper(std::move(mapper)), initialized(false)
36     {}
37 
38     bool open() override;
39     bool close() override;
40     std::vector<std::uint8_t> copyFrom(std::uint32_t length) override;
41     bool writeMeta(const std::vector<std::uint8_t>& configuration) override;
42     std::vector<std::uint8_t> readMeta() override;
43 
44   private:
45     bool setInitializedAndReturn(bool value);
46 
47     std::unique_ptr<HardwareMapperInterface> mapper;
48     bool initialized;
49     /* 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 = {};
59 };
60 
61 } // namespace ipmi_flash
62