blob: c66653b568deafedc6b1cb387ec17bbb835a5192 [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 Venture78b1a662019-01-17 12:38:26 -080017 static std::unique_ptr<HardwareMapperInterface>
Patrick Venture36bffb42019-06-24 10:47:47 -070018 createNuvotonMapper(std::uint32_t regionAddress,
19 std::uint32_t regionSize);
Patrick Venturee7728422018-11-14 20:16:33 -080020
Patrick Venture8b588562018-11-18 08:44:33 -080021 /**
22 * Create an LpcMapper for Nuvoton.
23 *
Patrick Venture78b1a662019-01-17 12:38:26 -080024 * @param[in] regionAddress - where to map the window into BMC memory.
Patrick Venture36bffb42019-06-24 10:47:47 -070025 * @param[in] regionSize - the size to map for copying data.
Patrick Venture8b588562018-11-18 08:44:33 -080026 * @param[in] a sys call interface pointer.
27 * @todo Needs reserved memory region's physical address and size.
28 */
Patrick Venture36bffb42019-06-24 10:47:47 -070029 LpcMapperNuvoton(std::uint32_t regionAddress, std::uint32_t regionSize,
Patrick Venture78b1a662019-01-17 12:38:26 -080030 const internal::Sys* sys = &internal::sys_impl) :
31 regionAddress(regionAddress),
Patrick Venture36bffb42019-06-24 10:47:47 -070032 memoryRegionSize(regionSize), sys(sys){};
33
34 /** Attempt to map the window for copying bytes, after mapWindow is called.
35 * throws MapperException
36 */
37 MemorySet open() override;
Patrick Venturee7728422018-11-14 20:16:33 -080038
Patrick Venture2343cfc2019-01-17 13:04:36 -080039 void close() override;
40
Patrick Venture36bffb42019-06-24 10:47:47 -070041 WindowMapResult mapWindow(std::uint32_t address,
42 std::uint32_t length) override;
Patrick Venture517710d2019-01-17 11:37:40 -080043
Patrick Venture8b588562018-11-18 08:44:33 -080044 private:
Patrick Venture78b1a662019-01-17 12:38:26 -080045 std::uint32_t regionAddress;
Patrick Venture36bffb42019-06-24 10:47:47 -070046 std::uint32_t memoryRegionSize;
Patrick Venturefa9d0c92018-12-13 16:38:27 -080047 const internal::Sys* sys;
Patrick Venture36bffb42019-06-24 10:47:47 -070048
49 /* The file handle to /dev/mem. */
50 int mappedFd = -1;
51
52 /* The pointer to the memory-mapped region. */
53 std::uint8_t* mapped = nullptr;
Patrick Venturee7728422018-11-14 20:16:33 -080054};
55
Patrick Venture1d5a31c2019-05-20 11:38:22 -070056} // namespace ipmi_flash