Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | 7b91cbc | 2018-11-28 14:24:41 -0800 | [diff] [blame] | 3 | #include "internal/sys.hpp" |
Patrick Venture | 5251da9 | 2019-01-17 11:25:26 -0800 | [diff] [blame] | 4 | #include "window_hw_interface.hpp" |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 5 | |
Patrick Venture | c9c6088 | 2019-01-17 11:44:47 -0800 | [diff] [blame] | 6 | #include <cstdint> |
Patrick Venture | 92973f1 | 2018-11-16 21:00:44 -0800 | [diff] [blame] | 7 | #include <memory> |
Patrick Venture | bf06463 | 2019-01-17 12:20:21 -0800 | [diff] [blame] | 8 | #include <string> |
Patrick Venture | c9c6088 | 2019-01-17 11:44:47 -0800 | [diff] [blame] | 9 | #include <utility> |
| 10 | #include <vector> |
Patrick Venture | 92973f1 | 2018-11-16 21:00:44 -0800 | [diff] [blame] | 11 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 12 | namespace ipmi_flash |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 13 | { |
| 14 | |
Patrick Venture | 5251da9 | 2019-01-17 11:25:26 -0800 | [diff] [blame] | 15 | class LpcMapperAspeed : public HardwareMapperInterface |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 16 | { |
| 17 | public: |
Patrick Venture | 5251da9 | 2019-01-17 11:25:26 -0800 | [diff] [blame] | 18 | static std::unique_ptr<HardwareMapperInterface> |
Patrick Venture | 78b1a66 | 2019-01-17 12:38:26 -0800 | [diff] [blame] | 19 | createAspeedMapper(std::uint32_t regionAddress, std::size_t regionSize); |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 20 | |
Patrick Venture | fac0713 | 2019-01-18 07:45:12 -0800 | [diff] [blame] | 21 | /* NOTE: This object is created and then never destroyed (unless ipmid |
| 22 | * stops/crashes, etc) |
| 23 | */ |
Patrick Venture | 78b1a66 | 2019-01-17 12:38:26 -0800 | [diff] [blame] | 24 | LpcMapperAspeed(std::uint32_t regionAddress, std::size_t regionSize, |
Patrick Venture | fa9d0c9 | 2018-12-13 16:38:27 -0800 | [diff] [blame] | 25 | const internal::Sys* sys = &internal::sys_impl) : |
Patrick Venture | 78b1a66 | 2019-01-17 12:38:26 -0800 | [diff] [blame] | 26 | regionAddress(regionAddress), |
| 27 | regionSize(regionSize), sys(sys){}; |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 28 | |
Patrick Venture | fac0713 | 2019-01-18 07:45:12 -0800 | [diff] [blame] | 29 | LpcMapperAspeed(const LpcMapperAspeed&) = delete; |
| 30 | LpcMapperAspeed& operator=(const LpcMapperAspeed&) = delete; |
| 31 | LpcMapperAspeed(LpcMapperAspeed&&) = default; |
| 32 | LpcMapperAspeed& operator=(LpcMapperAspeed&&) = default; |
| 33 | |
Patrick Venture | 2343cfc | 2019-01-17 13:04:36 -0800 | [diff] [blame] | 34 | void close() override; |
| 35 | |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 36 | std::pair<std::uint32_t, std::uint32_t> |
| 37 | mapWindow(std::uint32_t address, std::uint32_t length) override; |
Patrick Venture | 7b91cbc | 2018-11-28 14:24:41 -0800 | [diff] [blame] | 38 | |
Patrick Venture | 517710d | 2019-01-17 11:37:40 -0800 | [diff] [blame] | 39 | std::vector<std::uint8_t> copyFrom(std::uint32_t length) override; |
| 40 | |
Patrick Venture | a9e0005 | 2019-01-17 12:56:56 -0800 | [diff] [blame] | 41 | /** |
| 42 | * Attempt to mmap the region. |
| 43 | * |
| 44 | * @return true on success, false otherwise. |
| 45 | */ |
| 46 | bool mapRegion(); |
| 47 | |
Patrick Venture | 7b91cbc | 2018-11-28 14:24:41 -0800 | [diff] [blame] | 48 | private: |
Patrick Venture | bf06463 | 2019-01-17 12:20:21 -0800 | [diff] [blame] | 49 | static const std::string lpcControlPath; |
Patrick Venture | 5d96c35 | 2019-01-17 12:44:06 -0800 | [diff] [blame] | 50 | int mappedFd = -1; |
Patrick Venture | a9e0005 | 2019-01-17 12:56:56 -0800 | [diff] [blame] | 51 | std::uint8_t* mappedRegion = nullptr; |
Patrick Venture | 78b1a66 | 2019-01-17 12:38:26 -0800 | [diff] [blame] | 52 | std::uint32_t regionAddress; |
Patrick Venture | 28abae7 | 2018-12-14 09:44:02 -0800 | [diff] [blame] | 53 | std::size_t regionSize; |
Patrick Venture | fa9d0c9 | 2018-12-13 16:38:27 -0800 | [diff] [blame] | 54 | const internal::Sys* sys; |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 55 | }; |
| 56 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 57 | } // namespace ipmi_flash |