buffer: Update queueSize and Read/Write Ptrs to 3B
This allows for bigger Queue size than 64KB.
Tested: Verified this with a new BIOS
Signed-off-by: Brandon Kim <brandonkim@google.com>
Change-Id: I558a24c3b2500754424bdad6459244279592238b
diff --git a/include/buffer.hpp b/include/buffer.hpp
index 54d197e..a44e504 100644
--- a/include/buffer.hpp
+++ b/include/buffer.hpp
@@ -14,6 +14,7 @@
/* Adding endianness */
using boost::endian::little_uint16_t;
+using boost::endian::little_uint24_t;
using boost::endian::little_uint32_t;
using boost::endian::little_uint64_t;
@@ -33,14 +34,14 @@
little_uint32_t bmcInterfaceVersion; // Offset 0x0
little_uint32_t biosInterfaceVersion; // Offset 0x4
std::array<little_uint32_t, 4> magicNumber; // Offset 0x8
- little_uint16_t queueSize; // Offset 0x18
- little_uint16_t ueRegionSize; // Offset 0x1a
- little_uint32_t bmcFlags; // Offset 0x1c
- little_uint16_t bmcReadPtr; // Offset 0x20
- std::array<uint8_t, 6> reserved1; // Offset 0x22
+ little_uint24_t queueSize; // Offset 0x18
+ little_uint16_t ueRegionSize; // Offset 0x1b
+ little_uint32_t bmcFlags; // Offset 0x1d
+ little_uint24_t bmcReadPtr; // Offset 0x21
+ std::array<uint8_t, 4> reserved1; // Offset 0x24
little_uint32_t biosFlags; // Offset 0x28
- little_uint16_t biosWritePtr; // Offset 0x2c
- std::array<uint8_t, 2> reserved2; // Offset 0x2e
+ little_uint24_t biosWritePtr; // Offset 0x2c
+ uint8_t reserved2; // Offset 0x2f
// UE reserved region: Offset 0x30
// Error log queue: Offset 0x30 + UE reserved region
diff --git a/src/buffer.cpp b/src/buffer.cpp
index 5d39f69..b0922d7 100644
--- a/src/buffer.cpp
+++ b/src/buffer.cpp
@@ -101,20 +101,20 @@
constexpr uint8_t bmcReadPtrOffset =
offsetof(struct CircularBufferHeader, bmcReadPtr);
- little_uint16_t truncatedReadPtr =
- boost::endian::native_to_little(newReadPtr & 0xffff);
+ little_uint24_t truncatedReadPtr =
+ boost::endian::native_to_little(newReadPtr & 0xffffff);
uint8_t* truncatedReadPtrPtr =
reinterpret_cast<uint8_t*>(&truncatedReadPtr);
size_t writtenSize = dataInterface->write(
bmcReadPtrOffset, std::span<const uint8_t>{
truncatedReadPtrPtr,
- truncatedReadPtrPtr + sizeof(little_uint16_t)});
- if (writtenSize != sizeof(little_uint16_t))
+ truncatedReadPtrPtr + sizeof(truncatedReadPtr)});
+ if (writtenSize != sizeof(truncatedReadPtr))
{
throw std::runtime_error(fmt::format(
"[updateReadPtr] Wrote '{}' bytes, instead of expected '{}'",
- writtenSize, sizeof(little_uint16_t)));
+ writtenSize, sizeof(truncatedReadPtr)));
}
cachedBufferHeader.bmcReadPtr = truncatedReadPtr;
}
diff --git a/test/buffer_test.cpp b/test/buffer_test.cpp
index 712c801..fce322b 100644
--- a/test/buffer_test.cpp
+++ b/test/buffer_test.cpp
@@ -44,7 +44,7 @@
// CircularBufferHeader size is 0x30, ensure the test region is bigger
static constexpr size_t testRegionSize = 0x200;
static constexpr uint32_t testBmcInterfaceVersion = 123;
- static constexpr uint16_t testQueueSize = 0x100;
+ static constexpr uint32_t testQueueSize = 0x100;
static constexpr uint16_t testUeRegionSize = 0x50;
static constexpr std::array<uint32_t, 4> testMagicNumber = {
0x12345678, 0x22345678, 0x32345678, 0x42345678};
@@ -185,7 +185,7 @@
} catch (const std::runtime_error& e) {
EXPECT_STREQ(
e.what(),
- "[updateReadPtr] Wrote '1' bytes, instead of expected '2'");
+ "[updateReadPtr] Wrote '1' bytes, instead of expected '3'");
throw;
},
std::runtime_error);
@@ -193,11 +193,11 @@
TEST_F(BufferTest, BufferUpdateReadPtrPass)
{
- constexpr size_t expectedWriteSize = 2;
- constexpr uint8_t expectedBmcReadPtrOffset = 0x20;
- // Check that we truncate the highest 16bits
+ constexpr size_t expectedWriteSize = 3;
+ constexpr uint8_t expectedBmcReadPtrOffset = 0x21;
+ // Check that we truncate the highest 24bits
const uint32_t testNewReadPtr = 0x99881234;
- const std::vector<uint8_t> expectedReadPtr{0x34, 0x12};
+ const std::vector<uint8_t> expectedReadPtr{0x34, 0x12, 0x88};
EXPECT_CALL(*dataInterfaceMockPtr, write(expectedBmcReadPtrOffset,
ElementsAreArray(expectedReadPtr)))
@@ -205,7 +205,8 @@
EXPECT_NO_THROW(bufferImpl->updateReadPtr(testNewReadPtr));
auto cachedHeader = bufferImpl->getCachedBufferHeader();
- EXPECT_EQ(boost::endian::little_to_native(cachedHeader.bmcReadPtr), 0x1234);
+ EXPECT_EQ(boost::endian::little_to_native(cachedHeader.bmcReadPtr),
+ 0x881234);
}
TEST_F(BufferTest, BufferUpdateBmcFlagsFail)
@@ -229,7 +230,7 @@
TEST_F(BufferTest, BufferUpdateBmcFlagsPass)
{
constexpr size_t expectedWriteSize = 4;
- constexpr uint8_t expectedBmcReadPtrOffset = 0x1c;
+ constexpr uint8_t expectedBmcReadPtrOffset = 0x1d;
const std::vector<uint8_t> expectedNewBmcFlagsVector{0x04, 0x0, 0x0, 0x00};
EXPECT_CALL(*dataInterfaceMockPtr,
@@ -270,8 +271,8 @@
testQueueSize, testUeRegionSize,
testMagicNumber));
}
- static constexpr size_t expectedWriteSize = 2;
- static constexpr uint8_t expectedBmcReadPtrOffset = 0x20;
+ static constexpr size_t expectedWriteSize = 3;
+ static constexpr uint8_t expectedBmcReadPtrOffset = 0x21;
static constexpr size_t expectedqueueOffset = 0x30 + testUeRegionSize;
uint8_t* testInitializationHeaderPtr =
@@ -344,7 +345,7 @@
// Call to updateReadPtr is triggered
const std::vector<uint8_t> expectedReadPtr{
- static_cast<uint8_t>(testOffset + testLength), 0x0};
+ static_cast<uint8_t>(testOffset + testLength), 0x0, 0x0};
EXPECT_CALL(*dataInterfaceMockPtr, write(expectedBmcReadPtrOffset,
ElementsAreArray(expectedReadPtr)))
.WillOnce(Return(expectedWriteSize));
@@ -409,7 +410,7 @@
// Call to updateReadPtr is triggered
const std::vector<uint8_t> expectedReadPtr{
- static_cast<uint8_t>(testBytesLeft), 0x0};
+ static_cast<uint8_t>(testBytesLeft), 0x0, 0x0};
EXPECT_CALL(*dataInterfaceMockPtr, write(expectedBmcReadPtrOffset,
ElementsAreArray(expectedReadPtr)))
.WillOnce(Return(expectedWriteSize));
@@ -440,7 +441,7 @@
// Call to updateReadPtr is triggered, since we read to the very end of the
// buffer, update the readPtr up around to 0
- const std::vector<uint8_t> expectedReadPtr{0x0, 0x0};
+ const std::vector<uint8_t> expectedReadPtr{0x0, 0x0, 0x0};
EXPECT_CALL(*dataInterfaceMockPtr, write(expectedBmcReadPtrOffset,
ElementsAreArray(expectedReadPtr)))
.WillOnce(Return(expectedWriteSize));