blob: a9839632250150a34e52c4c1e9bf54eacde37c66 [file] [log] [blame]
Tom Josephf8329ac2019-04-11 22:13:22 +05301#pragma once
2
3#include <stdint.h>
4#include <unistd.h>
5
6#include <filesystem>
7
8#include "libpldm/base.h"
9#include "libpldm/file_io.h"
10
11namespace pldm
12{
13
14namespace responder
15{
16
17namespace utils
18{
19
20/** @struct CustomFD
21 *
22 * RAII wrapper for file descriptor.
23 */
24struct CustomFD
25{
26 CustomFD(const CustomFD&) = delete;
27 CustomFD& operator=(const CustomFD&) = delete;
28 CustomFD(CustomFD&&) = delete;
29 CustomFD& operator=(CustomFD&&) = delete;
30
31 CustomFD(int fd) : fd(fd)
32 {
33 }
34
35 ~CustomFD()
36 {
37 if (fd >= 0)
38 {
39 close(fd);
40 }
41 }
42
43 int operator()() const
44 {
45 return fd;
46 }
47
48 private:
49 int fd = -1;
50};
51
52} // namespace utils
53
54namespace dma
55{
56
57/** @struct AspeedXdmaOp
58 *
59 * Structure representing XDMA operation
60 */
61struct AspeedXdmaOp
62{
63 uint8_t upstream; //!< boolean indicating the direction of the DMA
64 //!< operation, true means a transfer from BMC to host.
65 uint64_t hostAddr; //!< the DMA address on the host side, configured by
66 //!< PCI subsystem.
67 uint32_t len; //!< the size of the transfer in bytes, it should be a
68 //!< multiple of 16 bytes
69} __attribute__((packed));
70
71constexpr auto xdmaDev = "/dev/xdma";
72
73// The minimum data size of dma transfer in bytes
74constexpr uint32_t minSize = 16;
75
76// 16MB - 4096B (16773120 bytes) is the maximum data size of DMA transfer
77constexpr size_t maxSize = (16 * 1024 * 1024) - 4096;
78
79namespace fs = std::filesystem;
80
81/** @brief API to transfer data from BMC to host using DMA
82 *
83 * @param[in] file - pathname of the file from which to DMA data
84 * @param[in] offset - offset in the file
85 * @param[in] length - length of data to read from the file
86 * @param[in] address - dma address on the host side to transfer data
87 */
88int transferDatatoHost(const fs::path& file, uint32_t offset, uint32_t length,
89 uint64_t address);
90
91} // namespace dma
92
93/** @brief Handler for readFileIntoMemory command
94 *
95 * @param[in] request - pointer to PLDM request payload
96 * @param[in] payloadLength - length of the message payload
97 * @param[out] response - response message location
98 */
99void readFileIntoMemory(const uint8_t* request, size_t payloadLength,
100 pldm_msg* response);
101
102} // namespace responder
103} // namespace pldm