| 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 | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 37 | { | 
|  | 38 | } | 
| Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 39 |  | 
| Patrick Venture | 0d2a813 | 2018-11-09 11:34:21 -0800 | [diff] [blame] | 40 | bool open() override; | 
| Patrick Venture | 0fbabf2 | 2018-11-09 11:54:12 -0800 | [diff] [blame] | 41 | bool close() override; | 
| Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 42 | std::vector<std::uint8_t> copyFrom(std::uint32_t length) override; | 
| Patrick Venture | 7430464 | 2019-01-17 09:31:04 -0800 | [diff] [blame] | 43 | bool writeMeta(const std::vector<std::uint8_t>& configuration) override; | 
|  | 44 | std::vector<std::uint8_t> readMeta() override; | 
| Patrick Venture | e772842 | 2018-11-14 20:16:33 -0800 | [diff] [blame] | 45 |  | 
|  | 46 | private: | 
| Patrick Venture | 09c4f7a | 2018-11-16 20:28:04 -0800 | [diff] [blame] | 47 | bool setInitializedAndReturn(bool value) | 
|  | 48 | { | 
| Patrick Venture | 36bffb4 | 2019-06-24 10:47:47 -0700 | [diff] [blame] | 49 | if (value) | 
|  | 50 | { | 
|  | 51 | try | 
|  | 52 | { | 
|  | 53 | /* Try really opening the map. */ | 
|  | 54 | memory = mapper->open(); | 
|  | 55 | } | 
|  | 56 | catch (const MapperException& e) | 
|  | 57 | { | 
|  | 58 | std::fprintf(stderr, "received mapper exception: %s\n", | 
|  | 59 | e.what()); | 
|  | 60 | return false; | 
|  | 61 | } | 
|  | 62 | } | 
|  | 63 |  | 
| Patrick Venture | 09c4f7a | 2018-11-16 20:28:04 -0800 | [diff] [blame] | 64 | initialized = value; | 
|  | 65 | return value; | 
|  | 66 | } | 
|  | 67 |  | 
| Patrick Venture | 5251da9 | 2019-01-17 11:25:26 -0800 | [diff] [blame] | 68 | std::unique_ptr<HardwareMapperInterface> mapper; | 
| Patrick Venture | 09c4f7a | 2018-11-16 20:28:04 -0800 | [diff] [blame] | 69 | bool initialized; | 
| Patrick Venture | 36bffb4 | 2019-06-24 10:47:47 -0700 | [diff] [blame] | 70 | /* The LPC Handler does not take ownership of this, in case there's cleanup | 
|  | 71 | * required for close() | 
|  | 72 | */ | 
|  | 73 | MemorySet memory = {}; | 
|  | 74 |  | 
|  | 75 | /* Offset in reserved memory at which host data arrives. */ | 
|  | 76 | /* Size of the chunk of the memory region in use by the host (e.g. | 
|  | 77 | * mapped over external block mechanism). | 
|  | 78 | */ | 
|  | 79 | WindowMapResult mappingResult = {}; | 
| Patrick Venture | 1cde5f9 | 2018-11-07 08:26:47 -0800 | [diff] [blame] | 80 | }; | 
|  | 81 |  | 
| Patrick Venture | 1d5a31c | 2019-05-20 11:38:22 -0700 | [diff] [blame] | 82 | } // namespace ipmi_flash |