Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | 8b58856 | 2018-11-18 08:44:33 -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 | c9c6088 | 2019-01-17 11:44:47 -0800 | [diff] [blame] | 8 | #include <utility> |
Patrick Venture | 517710d | 2019-01-17 11:37:40 -0800 | [diff] [blame] | 9 | #include <vector> |
Patrick Venture | 92973f1 | 2018-11-16 21:00:44 -0800 | [diff] [blame] | 10 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 11 | namespace ipmi_flash |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 12 | { |
| 13 | |
Patrick Venture | 5251da9 | 2019-01-17 11:25:26 -0800 | [diff] [blame] | 14 | class LpcMapperNuvoton : public HardwareMapperInterface |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 15 | { |
| 16 | public: |
Patrick Venture | 78b1a66 | 2019-01-17 12:38:26 -0800 | [diff] [blame] | 17 | static std::unique_ptr<HardwareMapperInterface> |
Patrick Venture | 36bffb4 | 2019-06-24 10:47:47 -0700 | [diff] [blame] | 18 | createNuvotonMapper(std::uint32_t regionAddress, |
| 19 | std::uint32_t regionSize); |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 20 | |
Patrick Venture | 8b58856 | 2018-11-18 08:44:33 -0800 | [diff] [blame] | 21 | /** |
| 22 | * Create an LpcMapper for Nuvoton. |
| 23 | * |
Patrick Venture | 78b1a66 | 2019-01-17 12:38:26 -0800 | [diff] [blame] | 24 | * @param[in] regionAddress - where to map the window into BMC memory. |
Patrick Venture | 36bffb4 | 2019-06-24 10:47:47 -0700 | [diff] [blame] | 25 | * @param[in] regionSize - the size to map for copying data. |
Patrick Venture | 8b58856 | 2018-11-18 08:44:33 -0800 | [diff] [blame] | 26 | * @param[in] a sys call interface pointer. |
| 27 | * @todo Needs reserved memory region's physical address and size. |
| 28 | */ |
Patrick Venture | 36bffb4 | 2019-06-24 10:47:47 -0700 | [diff] [blame] | 29 | LpcMapperNuvoton(std::uint32_t regionAddress, std::uint32_t regionSize, |
Patrick Venture | 78b1a66 | 2019-01-17 12:38:26 -0800 | [diff] [blame] | 30 | const internal::Sys* sys = &internal::sys_impl) : |
| 31 | regionAddress(regionAddress), |
Patrick Venture | 36bffb4 | 2019-06-24 10:47:47 -0700 | [diff] [blame] | 32 | 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 Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 38 | |
Patrick Venture | 2343cfc | 2019-01-17 13:04:36 -0800 | [diff] [blame] | 39 | void close() override; |
| 40 | |
Patrick Venture | 36bffb4 | 2019-06-24 10:47:47 -0700 | [diff] [blame] | 41 | WindowMapResult mapWindow(std::uint32_t address, |
| 42 | std::uint32_t length) override; |
Patrick Venture | 517710d | 2019-01-17 11:37:40 -0800 | [diff] [blame] | 43 | |
Patrick Venture | 8b58856 | 2018-11-18 08:44:33 -0800 | [diff] [blame] | 44 | private: |
Patrick Venture | 78b1a66 | 2019-01-17 12:38:26 -0800 | [diff] [blame] | 45 | std::uint32_t regionAddress; |
Patrick Venture | 36bffb4 | 2019-06-24 10:47:47 -0700 | [diff] [blame] | 46 | std::uint32_t memoryRegionSize; |
Patrick Venture | fa9d0c9 | 2018-12-13 16:38:27 -0800 | [diff] [blame] | 47 | const internal::Sys* sys; |
Patrick Venture | 36bffb4 | 2019-06-24 10:47:47 -0700 | [diff] [blame] | 48 | |
| 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 Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 54 | }; |
| 55 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 56 | } // namespace ipmi_flash |