blob: cc0443325f3bc19f4327af34ead2a6f78d5918a7 [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 Venture9b37b092020-05-28 20:58:57 -070037 {}
Patrick Venture1cde5f92018-11-07 08:26:47 -080038
Patrick Venture0d2a8132018-11-09 11:34:21 -080039 bool open() override;
Patrick Venture0fbabf22018-11-09 11:54:12 -080040 bool close() override;
Patrick Venture1cde5f92018-11-07 08:26:47 -080041 std::vector<std::uint8_t> copyFrom(std::uint32_t length) override;
Patrick Venture74304642019-01-17 09:31:04 -080042 bool writeMeta(const std::vector<std::uint8_t>& configuration) override;
43 std::vector<std::uint8_t> readMeta() override;
Patrick Venturee7728422018-11-14 20:16:33 -080044
45 private:
Patrick Venture09c4f7a2018-11-16 20:28:04 -080046 bool setInitializedAndReturn(bool value)
47 {
Patrick Venture36bffb42019-06-24 10:47:47 -070048 if (value)
49 {
50 try
51 {
52 /* Try really opening the map. */
53 memory = mapper->open();
54 }
55 catch (const MapperException& e)
56 {
57 std::fprintf(stderr, "received mapper exception: %s\n",
58 e.what());
59 return false;
60 }
61 }
62
Patrick Venture09c4f7a2018-11-16 20:28:04 -080063 initialized = value;
64 return value;
65 }
66
Patrick Venture5251da92019-01-17 11:25:26 -080067 std::unique_ptr<HardwareMapperInterface> mapper;
Patrick Venture09c4f7a2018-11-16 20:28:04 -080068 bool initialized;
Patrick Venture36bffb42019-06-24 10:47:47 -070069 /* The LPC Handler does not take ownership of this, in case there's cleanup
70 * required for close()
71 */
72 MemorySet memory = {};
73
74 /* Offset in reserved memory at which host data arrives. */
75 /* Size of the chunk of the memory region in use by the host (e.g.
76 * mapped over external block mechanism).
77 */
78 WindowMapResult mappingResult = {};
Patrick Venture1cde5f92018-11-07 08:26:47 -080079};
80
Patrick Venture1d5a31c2019-05-20 11:38:22 -070081} // namespace ipmi_flash