blob: 4158b9b7c389e6feadd019ee25f36cfdbb06e028 [file] [log] [blame]
Patrick Venture1cde5f92018-11-07 08:26:47 -08001#pragma once
2
3#include "data_handler.hpp"
Patrick Venture36bffb42019-06-24 10:47:47 -07004#include "mapper_errors.hpp"
Patrick Venture5251da92019-01-17 11:25:26 -08005#include "window_hw_interface.hpp"
Patrick Venture1cde5f92018-11-07 08:26:47 -08006
7#include <cstdint>
Patrick Venturee7728422018-11-14 20:16:33 -08008#include <memory>
Patrick Venture1cde5f92018-11-07 08:26:47 -08009#include <vector>
10
Patrick Venture1d5a31c2019-05-20 11:38:22 -070011namespace ipmi_flash
Patrick Venture1cde5f92018-11-07 08:26:47 -080012{
13
Patrick Venture8c535332018-11-08 15:58:00 -080014struct LpcRegion
15{
16 /* Host LPC address where the chunk is to be mapped. */
17 std::uint32_t address;
18
19 /* Size of the chunk to be mapped. */
20 std::uint32_t length;
21} __attribute__((packed));
22
23/**
24 * Data Handler for configuration the ASPEED LPC memory region, reading and
25 * writing data.
26 */
Patrick Venture1cde5f92018-11-07 08:26:47 -080027class LpcDataHandler : public DataInterface
28{
Patrick Venture1cde5f92018-11-07 08:26:47 -080029 public:
Patrick Venturee7728422018-11-14 20:16:33 -080030 /**
31 * Create an LpcDataHandler.
32 *
33 * @param[in] mapper - pointer to a mapper implementation to use.
34 */
Patrick Venture78b1a662019-01-17 12:38:26 -080035 explicit LpcDataHandler(std::unique_ptr<HardwareMapperInterface> mapper) :
Patrick Venture09c4f7a2018-11-16 20:28:04 -080036 mapper(std::move(mapper)), initialized(false)
Patrick Venturee7728422018-11-14 20:16:33 -080037 {
38 }
Patrick Venture1cde5f92018-11-07 08:26:47 -080039
Patrick Venture0d2a8132018-11-09 11:34:21 -080040 bool open() override;
Patrick Venture0fbabf22018-11-09 11:54:12 -080041 bool close() override;
Patrick Venture1cde5f92018-11-07 08:26:47 -080042 std::vector<std::uint8_t> copyFrom(std::uint32_t length) override;
Patrick Venture74304642019-01-17 09:31:04 -080043 bool writeMeta(const std::vector<std::uint8_t>& configuration) override;
44 std::vector<std::uint8_t> readMeta() override;
Patrick Venturee7728422018-11-14 20:16:33 -080045
46 private:
Patrick Venture09c4f7a2018-11-16 20:28:04 -080047 bool setInitializedAndReturn(bool value)
48 {
Patrick Venture36bffb42019-06-24 10:47:47 -070049 if (value)
50 {
51 try
52 {
53 /* Try really opening the map. */
54 memory = mapper->open();
55 }
56 catch (const MapperException& e)
57 {
58 std::fprintf(stderr, "received mapper exception: %s\n",
59 e.what());
60 return false;
61 }
62 }
63
Patrick Venture09c4f7a2018-11-16 20:28:04 -080064 initialized = value;
65 return value;
66 }
67
Patrick Venture5251da92019-01-17 11:25:26 -080068 std::unique_ptr<HardwareMapperInterface> mapper;
Patrick Venture09c4f7a2018-11-16 20:28:04 -080069 bool initialized;
Patrick Venture36bffb42019-06-24 10:47:47 -070070 /* The LPC Handler does not take ownership of this, in case there's cleanup
71 * required for close()
72 */
73 MemorySet memory = {};
74
75 /* Offset in reserved memory at which host data arrives. */
76 /* Size of the chunk of the memory region in use by the host (e.g.
77 * mapped over external block mechanism).
78 */
79 WindowMapResult mappingResult = {};
Patrick Venture1cde5f92018-11-07 08:26:47 -080080};
81
Patrick Venture1d5a31c2019-05-20 11:38:22 -070082} // namespace ipmi_flash