blob: 9aa5b8bdb8ad915ff5056d28c9f8c630d48281ef [file] [log] [blame]
Patrick Venturee7728422018-11-14 20:16:33 -08001#pragma once
2
Patrick Venture8b588562018-11-18 08:44:33 -08003#include "internal/sys.hpp"
Patrick Venture5251da92019-01-17 11:25:26 -08004#include "window_hw_interface.hpp"
Patrick Venturee7728422018-11-14 20:16:33 -08005
Patrick Venturec9c60882019-01-17 11:44:47 -08006#include <cstdint>
Patrick Venture92973f12018-11-16 21:00:44 -08007#include <memory>
Patrick Venturec9c60882019-01-17 11:44:47 -08008#include <utility>
Patrick Venture517710d2019-01-17 11:37:40 -08009#include <vector>
Patrick Venture92973f12018-11-16 21:00:44 -080010
Patrick Venture1d5a31c2019-05-20 11:38:22 -070011namespace ipmi_flash
Patrick Venturee7728422018-11-14 20:16:33 -080012{
13
Patrick Venture5251da92019-01-17 11:25:26 -080014class LpcMapperNuvoton : public HardwareMapperInterface
Patrick Venturee7728422018-11-14 20:16:33 -080015{
16 public:
Patrick Williams42a44c22024-08-16 15:21:32 -040017 static std::unique_ptr<HardwareMapperInterface> createNuvotonMapper(
18 std::uint32_t regionAddress, std::uint32_t regionSize);
Patrick Venturee7728422018-11-14 20:16:33 -080019
Patrick Venture8b588562018-11-18 08:44:33 -080020 /**
21 * Create an LpcMapper for Nuvoton.
22 *
Patrick Venture78b1a662019-01-17 12:38:26 -080023 * @param[in] regionAddress - where to map the window into BMC memory.
Patrick Venture36bffb42019-06-24 10:47:47 -070024 * @param[in] regionSize - the size to map for copying data.
Patrick Venture8b588562018-11-18 08:44:33 -080025 * @param[in] a sys call interface pointer.
26 * @todo Needs reserved memory region's physical address and size.
27 */
Patrick Venture36bffb42019-06-24 10:47:47 -070028 LpcMapperNuvoton(std::uint32_t regionAddress, std::uint32_t regionSize,
Patrick Venture78b1a662019-01-17 12:38:26 -080029 const internal::Sys* sys = &internal::sys_impl) :
Patrick Williams42a44c22024-08-16 15:21:32 -040030 regionAddress(regionAddress), memoryRegionSize(regionSize), sys(sys) {};
Patrick Venture36bffb42019-06-24 10:47:47 -070031
32 /** Attempt to map the window for copying bytes, after mapWindow is called.
33 * throws MapperException
34 */
35 MemorySet open() override;
Patrick Venturee7728422018-11-14 20:16:33 -080036
Patrick Venture2343cfc2019-01-17 13:04:36 -080037 void close() override;
38
Patrick Venture36bffb42019-06-24 10:47:47 -070039 WindowMapResult mapWindow(std::uint32_t address,
40 std::uint32_t length) override;
Patrick Venture517710d2019-01-17 11:37:40 -080041
Patrick Venture8b588562018-11-18 08:44:33 -080042 private:
Patrick Venture78b1a662019-01-17 12:38:26 -080043 std::uint32_t regionAddress;
Patrick Venture36bffb42019-06-24 10:47:47 -070044 std::uint32_t memoryRegionSize;
Patrick Venturefa9d0c92018-12-13 16:38:27 -080045 const internal::Sys* sys;
Patrick Venture36bffb42019-06-24 10:47:47 -070046
47 /* The file handle to /dev/mem. */
48 int mappedFd = -1;
49
50 /* The pointer to the memory-mapped region. */
51 std::uint8_t* mapped = nullptr;
Patrick Venturee7728422018-11-14 20:16:33 -080052};
53
Patrick Venture1d5a31c2019-05-20 11:38:22 -070054} // namespace ipmi_flash