blob: 9300efd6bbadbf3d2c5bdebf8df6b77bdc0baa4d [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 Venture2343cfc2019-01-17 13:04:36 -080034 void close() override;
35
Patrick Venturee7728422018-11-14 20:16:33 -080036 std::pair<std::uint32_t, std::uint32_t>
37 mapWindow(std::uint32_t address, std::uint32_t length) override;
Patrick Venture7b91cbc2018-11-28 14:24:41 -080038
Patrick Venture517710d2019-01-17 11:37:40 -080039 std::vector<std::uint8_t> copyFrom(std::uint32_t length) override;
40
Patrick Venturea9e00052019-01-17 12:56:56 -080041 /**
42 * Attempt to mmap the region.
43 *
44 * @return true on success, false otherwise.
45 */
46 bool mapRegion();
47
Patrick Venture7b91cbc2018-11-28 14:24:41 -080048 private:
Patrick Venturebf064632019-01-17 12:20:21 -080049 static const std::string lpcControlPath;
Patrick Venture5d96c352019-01-17 12:44:06 -080050 int mappedFd = -1;
Patrick Venturea9e00052019-01-17 12:56:56 -080051 std::uint8_t* mappedRegion = nullptr;
Patrick Venture78b1a662019-01-17 12:38:26 -080052 std::uint32_t regionAddress;
Patrick Venture28abae72018-12-14 09:44:02 -080053 std::size_t regionSize;
Patrick Venturefa9d0c92018-12-13 16:38:27 -080054 const internal::Sys* sys;
Patrick Venturee7728422018-11-14 20:16:33 -080055};
56
Patrick Venture1d5a31c2019-05-20 11:38:22 -070057} // namespace ipmi_flash