blob: ac87c2217212480ab4613727fe0a91804078ecd3 [file] [log] [blame]
Patrick Venturee7728422018-11-14 20:16:33 -08001#pragma once
2
Patrick Venture7b91cbc2018-11-28 14:24:41 -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 Venturebf064632019-01-17 12:20:21 -08008#include <string>
Patrick Venturec9c60882019-01-17 11:44:47 -08009#include <utility>
10#include <vector>
Patrick Venture92973f12018-11-16 21:00:44 -080011
Patrick Venture1d5a31c2019-05-20 11:38:22 -070012namespace ipmi_flash
Patrick Venturee7728422018-11-14 20:16:33 -080013{
14
Patrick Venture5251da92019-01-17 11:25:26 -080015class LpcMapperAspeed : public HardwareMapperInterface
Patrick Venturee7728422018-11-14 20:16:33 -080016{
17 public:
Patrick Venture5251da92019-01-17 11:25:26 -080018 static std::unique_ptr<HardwareMapperInterface>
Patrick Venture78b1a662019-01-17 12:38:26 -080019 createAspeedMapper(std::uint32_t regionAddress, std::size_t regionSize);
Patrick Venturee7728422018-11-14 20:16:33 -080020
Patrick Venturefac07132019-01-18 07:45:12 -080021 /* NOTE: This object is created and then never destroyed (unless ipmid
22 * stops/crashes, etc)
23 */
Patrick Venture78b1a662019-01-17 12:38:26 -080024 LpcMapperAspeed(std::uint32_t regionAddress, std::size_t regionSize,
Patrick Venturefa9d0c92018-12-13 16:38:27 -080025 const internal::Sys* sys = &internal::sys_impl) :
Patrick Venture78b1a662019-01-17 12:38:26 -080026 regionAddress(regionAddress),
27 regionSize(regionSize), sys(sys){};
Patrick Venturee7728422018-11-14 20:16:33 -080028
Patrick Venturefac07132019-01-18 07:45:12 -080029 LpcMapperAspeed(const LpcMapperAspeed&) = delete;
30 LpcMapperAspeed& operator=(const LpcMapperAspeed&) = delete;
31 LpcMapperAspeed(LpcMapperAspeed&&) = default;
32 LpcMapperAspeed& operator=(LpcMapperAspeed&&) = default;
33
Patrick Venture36bffb42019-06-24 10:47:47 -070034 /* throws MapperException */
35 MemorySet open() override;
36
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 Venturea9e00052019-01-17 12:56:56 -080042 /**
43 * Attempt to mmap the region.
44 *
45 * @return true on success, false otherwise.
46 */
47 bool mapRegion();
48
Patrick Venture7b91cbc2018-11-28 14:24:41 -080049 private:
Patrick Venturebf064632019-01-17 12:20:21 -080050 static const std::string lpcControlPath;
Patrick Venture5d96c352019-01-17 12:44:06 -080051 int mappedFd = -1;
Patrick Venturea9e00052019-01-17 12:56:56 -080052 std::uint8_t* mappedRegion = nullptr;
Patrick Venture78b1a662019-01-17 12:38:26 -080053 std::uint32_t regionAddress;
Patrick Venture28abae72018-12-14 09:44:02 -080054 std::size_t regionSize;
Patrick Venturefa9d0c92018-12-13 16:38:27 -080055 const internal::Sys* sys;
Patrick Venturee7728422018-11-14 20:16:33 -080056};
57
Patrick Venture1d5a31c2019-05-20 11:38:22 -070058} // namespace ipmi_flash