xref: /openbmc/bios-bmc-smm-error-logger/include/buffer.hpp (revision fcbc3db143de5e878f1c4465dcda724bcd5db371)
1 #pragma once
2 
3 #include "pci_handler.hpp"
4 
5 #include <array>
6 #include <cstdint>
7 #include <memory>
8 
9 namespace bios_bmc_smm_error_logger
10 {
11 
12 struct CircularBufferHeader
13 {
14     uint32_t bmcInterfaceVersion;        // Offset 0x0
15     uint32_t biosInterfaceVersion;       // Offset 0x4
16     std::array<uint32_t, 4> magicNumber; // Offset 0x8
17     uint16_t queueSize;                  // Offset 0x18
18     uint16_t ueRegionSize;               // Offset 0x1a
19     uint32_t bmcFlags;                   // Offset 0x1c
20     uint16_t bmcReadPtr;                 // Offset 0x20
21     std::array<uint8_t, 6> padding1;     // Offset 0x22
22     uint32_t biosFlags;                  // Offset 0x28
23     uint16_t biosWritePtr;               // Offset 0x2c
24     std::array<uint8_t, 2> padding2;     // Offset 0x2e
25     // UE reserved region:                  Offset 0x30
26     // Error log queue:                     Offset 0x30 + UE reserved region
27 
28     bool operator==(const CircularBufferHeader& other) const
29     {
30         return this->bmcInterfaceVersion == other.bmcInterfaceVersion &&
31                this->biosInterfaceVersion == other.biosInterfaceVersion &&
32                this->magicNumber == other.magicNumber &&
33                this->queueSize == other.queueSize &&
34                this->ueRegionSize == other.ueRegionSize &&
35                this->bmcFlags == other.bmcFlags &&
36                this->bmcReadPtr == other.bmcReadPtr &&
37                /* Skip comparing padding1 */
38                this->biosFlags == other.biosFlags &&
39                this->biosWritePtr == other.biosWritePtr;
40         /* Skip comparing padding2 */
41     }
42 } __attribute__((__packed__));
43 
44 /**
45  * An interface class for the buffer helper APIs
46  */
47 class BufferInterface
48 {
49   public:
50     virtual ~BufferInterface() = default;
51 
52     /**
53      * Zero out the buffer first before populating the header
54      *
55      * @param[in] bmcInterfaceVersion - Used to initialize the header
56      * @param[in] queueSize - Used to initialize the header
57      * @param[in] ueRegionSize - Used to initialize the header
58      * @param[in] magicNumber - Used to initialize the header
59      * @return true if successful
60      */
61     virtual void initialize(uint32_t bmcInterfaceVersion, uint16_t queueSize,
62                             uint16_t ueRegionSize,
63                             const std::array<uint32_t, 4>& magicNumber) = 0;
64 };
65 
66 /**
67  * Buffer implementation class
68  */
69 class BufferImpl : public BufferInterface
70 {
71   public:
72     /** @brief Constructor for BufferImpl
73      *  @param[in] dataInterface     - DataInterface for this object
74      */
75     explicit BufferImpl(std::unique_ptr<DataInterface> dataInterface);
76     void initialize(uint32_t bmcInterfaceVersion, uint16_t queueSize,
77                     uint16_t ueRegionSize,
78                     const std::array<uint32_t, 4>& magicNumber) override;
79 
80   private:
81     std::unique_ptr<DataInterface> dataInterface;
82 };
83 
84 } // namespace bios_bmc_smm_error_logger
85