Sampa Misra | 854e61f | 2019-08-22 04:36:47 -0500 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "file_io_by_type.hpp" |
| 4 | |
| 5 | #include "file_io_type_pel.hpp" |
| 6 | #include "libpldmresponder/utils.hpp" |
| 7 | #include "xyz/openbmc_project/Common/error.hpp" |
| 8 | |
| 9 | #include <stdint.h> |
| 10 | #include <unistd.h> |
| 11 | |
| 12 | #include <exception> |
| 13 | #include <filesystem> |
| 14 | #include <phosphor-logging/elog-errors.hpp> |
| 15 | #include <phosphor-logging/log.hpp> |
| 16 | #include <vector> |
| 17 | #include <xyz/openbmc_project/Logging/Entry/server.hpp> |
| 18 | |
| 19 | #include "libpldm/base.h" |
| 20 | #include "oem/ibm/libpldm/file_io.h" |
| 21 | |
| 22 | namespace pldm |
| 23 | { |
| 24 | namespace responder |
| 25 | { |
| 26 | |
| 27 | using namespace phosphor::logging; |
| 28 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
| 29 | |
| 30 | int FileHandler::transferFileData(const fs::path& path, bool upstream, |
| 31 | uint32_t offset, uint32_t length, |
| 32 | uint64_t address) |
| 33 | { |
| 34 | dma::DMA xdmaInterface; |
| 35 | |
| 36 | while (length > dma::maxSize) |
| 37 | { |
| 38 | auto rc = xdmaInterface.transferDataHost(path, offset, dma::maxSize, |
| 39 | address, upstream); |
| 40 | if (rc < 0) |
| 41 | { |
| 42 | return PLDM_ERROR; |
| 43 | } |
| 44 | offset += dma::maxSize; |
| 45 | length -= dma::maxSize; |
| 46 | address += dma::maxSize; |
| 47 | } |
| 48 | auto rc = |
| 49 | xdmaInterface.transferDataHost(path, offset, length, address, upstream); |
| 50 | return rc < 0 ? PLDM_ERROR : PLDM_SUCCESS; |
| 51 | } |
| 52 | |
| 53 | std::unique_ptr<FileHandler> getHandlerByType(uint16_t fileType, |
| 54 | uint32_t fileHandle) |
| 55 | { |
| 56 | switch (fileType) |
| 57 | { |
| 58 | case PLDM_FILE_TYPE_PEL: |
| 59 | { |
| 60 | return std::make_unique<PelHandler>(fileHandle); |
| 61 | break; |
| 62 | } |
| 63 | default: |
| 64 | { |
| 65 | elog<InternalFailure>(); |
| 66 | break; |
| 67 | } |
| 68 | } |
| 69 | return nullptr; |
| 70 | } |
| 71 | |
| 72 | } // namespace responder |
| 73 | } // namespace pldm |