blob: 8431730c35602cb3d02846119e7bbfb9dbf39180 [file] [log] [blame]
Patrick Venture1cde5f92018-11-07 08:26:47 -08001#pragma once
2
3#include "data_handler.hpp"
Patrick Venturee7728422018-11-14 20:16:33 -08004#include "lpc_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
10namespace blobs
11{
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 *
Patrick Venture002916a2018-11-15 10:38:07 -080032 * @param[in] regionAddress - BMC address to point the map for the LPC
33 * memory region.
Patrick Venturee7728422018-11-14 20:16:33 -080034 * @param[in] mapper - pointer to a mapper implementation to use.
35 */
Patrick Venture002916a2018-11-15 10:38:07 -080036 LpcDataHandler(std::uint32_t regionAddress,
37 std::unique_ptr<LpcMapperInterface> mapper) :
38 regionAddress(regionAddress),
Patrick Venture09c4f7a2018-11-16 20:28:04 -080039 mapper(std::move(mapper)), initialized(false)
Patrick Venturee7728422018-11-14 20:16:33 -080040 {
41 }
Patrick Venture1cde5f92018-11-07 08:26:47 -080042
Patrick Venture0d2a8132018-11-09 11:34:21 -080043 bool open() override;
Patrick Venture0fbabf22018-11-09 11:54:12 -080044 bool close() override;
Patrick Venture1cde5f92018-11-07 08:26:47 -080045 std::vector<std::uint8_t> copyFrom(std::uint32_t length) override;
Patrick Venture8c535332018-11-08 15:58:00 -080046 bool write(const std::vector<std::uint8_t>& configuration) override;
47 std::vector<std::uint8_t> read() override;
Patrick Venturee7728422018-11-14 20:16:33 -080048
49 private:
Patrick Venture09c4f7a2018-11-16 20:28:04 -080050 bool setInitializedAndReturn(bool value)
51 {
52 initialized = value;
53 return value;
54 }
55
Patrick Venture002916a2018-11-15 10:38:07 -080056 std::uint32_t regionAddress;
Patrick Venturee7728422018-11-14 20:16:33 -080057 std::unique_ptr<LpcMapperInterface> mapper;
Patrick Venture09c4f7a2018-11-16 20:28:04 -080058 bool initialized;
Patrick Venture1cde5f92018-11-07 08:26:47 -080059};
60
61} // namespace blobs