Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "data_handler.hpp" |
Patrick Venture | 36bffb4 | 2019-06-24 10:47:47 -0700 | [diff] [blame] | 4 | #include "mapper_errors.hpp" |
Patrick Venture | 5251da9 | 2019-01-17 11:25:26 -0800 | [diff] [blame] | 5 | #include "window_hw_interface.hpp" |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 6 | |
| 7 | #include <cstdint> |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 8 | #include <memory> |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 11 | namespace ipmi_flash |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 12 | { |
| 13 | |
Patrick Venture | 8c53533 | 2018-11-08 15:58:00 -0800 | [diff] [blame] | 14 | struct LpcRegion |
| 15 | { |
| 16 | /* Host LPC address where the chunk is to be mapped. */ |
| 17 | std::uint32_t address; |
| 18 | |
| 19 | /* Size of the chunk to be mapped. */ |
| 20 | std::uint32_t length; |
| 21 | } __attribute__((packed)); |
| 22 | |
| 23 | /** |
| 24 | * Data Handler for configuration the ASPEED LPC memory region, reading and |
| 25 | * writing data. |
| 26 | */ |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 27 | class LpcDataHandler : public DataInterface |
| 28 | { |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 29 | public: |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 30 | /** |
| 31 | * Create an LpcDataHandler. |
| 32 | * |
| 33 | * @param[in] mapper - pointer to a mapper implementation to use. |
| 34 | */ |
Patrick Venture | 78b1a66 | 2019-01-17 12:38:26 -0800 | [diff] [blame] | 35 | explicit LpcDataHandler(std::unique_ptr<HardwareMapperInterface> mapper) : |
Patrick Venture | 09c4f7a | 2018-11-16 20:28:04 -0800 | [diff] [blame] | 36 | mapper(std::move(mapper)), initialized(false) |
Patrick Venture | 9b37b09 | 2020-05-28 20:58:57 -0700 | [diff] [blame^] | 37 | {} |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 38 | |
Patrick Venture | 0d2a813 | 2018-11-09 11:34:21 -0800 | [diff] [blame] | 39 | bool open() override; |
Patrick Venture | 0fbabf2 | 2018-11-09 11:54:12 -0800 | [diff] [blame] | 40 | bool close() override; |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 41 | std::vector<std::uint8_t> copyFrom(std::uint32_t length) override; |
Patrick Venture | 7430464 | 2019-01-17 09:31:04 -0800 | [diff] [blame] | 42 | bool writeMeta(const std::vector<std::uint8_t>& configuration) override; |
| 43 | std::vector<std::uint8_t> readMeta() override; |
Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 44 | |
| 45 | private: |
Patrick Venture | 09c4f7a | 2018-11-16 20:28:04 -0800 | [diff] [blame] | 46 | bool setInitializedAndReturn(bool value) |
| 47 | { |
Patrick Venture | 36bffb4 | 2019-06-24 10:47:47 -0700 | [diff] [blame] | 48 | if (value) |
| 49 | { |
| 50 | try |
| 51 | { |
| 52 | /* Try really opening the map. */ |
| 53 | memory = mapper->open(); |
| 54 | } |
| 55 | catch (const MapperException& e) |
| 56 | { |
| 57 | std::fprintf(stderr, "received mapper exception: %s\n", |
| 58 | e.what()); |
| 59 | return false; |
| 60 | } |
| 61 | } |
| 62 | |
Patrick Venture | 09c4f7a | 2018-11-16 20:28:04 -0800 | [diff] [blame] | 63 | initialized = value; |
| 64 | return value; |
| 65 | } |
| 66 | |
Patrick Venture | 5251da9 | 2019-01-17 11:25:26 -0800 | [diff] [blame] | 67 | std::unique_ptr<HardwareMapperInterface> mapper; |
Patrick Venture | 09c4f7a | 2018-11-16 20:28:04 -0800 | [diff] [blame] | 68 | bool initialized; |
Patrick Venture | 36bffb4 | 2019-06-24 10:47:47 -0700 | [diff] [blame] | 69 | /* The LPC Handler does not take ownership of this, in case there's cleanup |
| 70 | * required for close() |
| 71 | */ |
| 72 | MemorySet memory = {}; |
| 73 | |
| 74 | /* Offset in reserved memory at which host data arrives. */ |
| 75 | /* Size of the chunk of the memory region in use by the host (e.g. |
| 76 | * mapped over external block mechanism). |
| 77 | */ |
| 78 | WindowMapResult mappingResult = {}; |
Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 79 | }; |
| 80 | |
Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 81 | } // namespace ipmi_flash |