[sw] Remove 16-bit MMIO Functions
These are currently not used, and do not have a fully-featured API.
Indeed there is no plan to support this width in the bitfield.h library,
and most comportable hardware has settled on 8-bit or 32-bit accesses
being the only valid way to access MMIO registers.
Signed-off-by: Sam Elliott <selliott@lowrisc.org>
diff --git a/sw/device/lib/base/mmio.c b/sw/device/lib/base/mmio.c
index 4580c50..74cc8e8 100644
--- a/sw/device/lib/base/mmio.c
+++ b/sw/device/lib/base/mmio.c
@@ -123,12 +123,9 @@
// `extern` declarations to give the inline functions in the
// corresponding header a link location.
extern uint8_t mmio_region_read8(mmio_region_t base, ptrdiff_t offset);
-extern uint16_t mmio_region_read16(mmio_region_t base, ptrdiff_t offset);
extern uint32_t mmio_region_read32(mmio_region_t base, ptrdiff_t offset);
extern void mmio_region_write8(mmio_region_t base, ptrdiff_t offset,
uint8_t value);
-extern void mmio_region_write16(mmio_region_t base, ptrdiff_t offset,
- uint16_t value);
extern void mmio_region_write32(mmio_region_t base, ptrdiff_t offset,
uint32_t value);
extern uint32_t mmio_region_read_mask32(mmio_region_t base, ptrdiff_t offset,
diff --git a/sw/device/lib/base/mmio.h b/sw/device/lib/base/mmio.h
index 885b9bf..bea2c90 100644
--- a/sw/device/lib/base/mmio.h
+++ b/sw/device/lib/base/mmio.h
@@ -64,21 +64,6 @@
}
/**
- * Reads an aligned uint16_t from the MMIO region `base` at the given byte
- * offset.
- *
- * This function is guaranteed to commit a read to memory, and will not be
- * reordered with respect to other MMIO manipulations.
- *
- * @param base the region to read from.
- * @param offset the offset to read at, in bytes.
- * @return the read value.
- */
-inline uint16_t mmio_region_read16(mmio_region_t base, ptrdiff_t offset) {
- return ((volatile uint16_t *)base.base)[offset / sizeof(uint16_t)];
-}
-
-/**
* Reads an aligned uint32_t from the MMIO region `base` at the given byte
* offset.
*
@@ -110,22 +95,6 @@
}
/**
- * Writes an aligned uint16_t to the MMIO region `base` at the given byte
- * offset.
- *
- * This function is guaranteed to commit a write to memory, and will not be
- * reordered with respect to other region manipulations.
- *
- * @param base the region to write to.
- * @param offset the offset to write at, in bytes.
- * @param value the value to write.
- */
-inline void mmio_region_write16(mmio_region_t base, ptrdiff_t offset,
- uint16_t value) {
- ((volatile uint16_t *)base.base)[offset / sizeof(uint16_t)] = value;
-}
-
-/**
* Writes an aligned uint32_t to the MMIO region `base` at the given byte
* offset.
*
@@ -155,11 +124,9 @@
* Stubbed-out read/write operations for overriding by a testing library.
*/
uint8_t mmio_region_read8(mmio_region_t base, ptrdiff_t offset);
-uint16_t mmio_region_read16(mmio_region_t base, ptrdiff_t offset);
uint32_t mmio_region_read32(mmio_region_t base, ptrdiff_t offset);
void mmio_region_write8(mmio_region_t base, ptrdiff_t offset, uint8_t value);
-void mmio_region_write16(mmio_region_t base, ptrdiff_t offset, uint16_t value);
void mmio_region_write32(mmio_region_t base, ptrdiff_t offset, uint32_t value);
#endif // MOCK_MMIO
diff --git a/sw/device/lib/testing/mock_mmio.cc b/sw/device/lib/testing/mock_mmio.cc
index fbbe121..dfa803a 100644
--- a/sw/device/lib/testing/mock_mmio.cc
+++ b/sw/device/lib/testing/mock_mmio.cc
@@ -16,11 +16,6 @@
return dev->Read8(offset);
}
-uint16_t mmio_region_read16(mmio_region_t base, ptrdiff_t offset) {
- auto *dev = static_cast<MockDevice *>(base.mock);
- return dev->Read16(offset);
-}
-
uint32_t mmio_region_read32(mmio_region_t base, ptrdiff_t offset) {
auto *dev = static_cast<MockDevice *>(base.mock);
return dev->Read32(offset);
@@ -31,11 +26,6 @@
dev->Write8(offset, value);
}
-void mmio_region_write16(mmio_region_t base, ptrdiff_t offset, uint16_t value) {
- auto *dev = static_cast<MockDevice *>(base.mock);
- dev->Write16(offset, value);
-}
-
void mmio_region_write32(mmio_region_t base, ptrdiff_t offset, uint32_t value) {
auto *dev = static_cast<MockDevice *>(base.mock);
dev->Write32(offset, value);
diff --git a/sw/device/lib/testing/mock_mmio.h b/sw/device/lib/testing/mock_mmio.h
index e23cea9..f30e247 100644
--- a/sw/device/lib/testing/mock_mmio.h
+++ b/sw/device/lib/testing/mock_mmio.h
@@ -175,11 +175,9 @@
mmio_region_t region() { return {this}; }
MOCK_METHOD(uint8_t, Read8, (ptrdiff_t offset));
- MOCK_METHOD(uint16_t, Read16, (ptrdiff_t offset));
MOCK_METHOD(uint32_t, Read32, (ptrdiff_t offset));
MOCK_METHOD(void, Write8, (ptrdiff_t offset, uint8_t value));
- MOCK_METHOD(void, Write16, (ptrdiff_t offset, uint16_t value));
MOCK_METHOD(void, Write32, (ptrdiff_t offset, uint32_t value));
/**
@@ -235,21 +233,6 @@
/**
* Expect a read to the device `dev` at the given offset, returning the given
- * 16-bit value.
- *
- * The value may be given as an integer, a pointer to little-endian data,
- * or a `std::initializer_list<BitField>`.
- *
- * This expectation is sequenced with all other `EXPECT_READ` and `EXPECT_WRITE`
- * calls.
- */
-#define EXPECT_READ16_AT(dev, offset, ...) \
- EXPECT_CALL(dev, Read16(offset)) \
- .WillOnce( \
- testing::Return(mock_mmio::internal::ToInt<uint16_t>(__VA_ARGS__)))
-
-/**
- * Expect a read to the device `dev` at the given offset, returning the given
* 32-bit value.
*
* The value may be given as an integer, a pointer to little-endian data,
@@ -278,20 +261,6 @@
dev, Write8(offset, mock_mmio::internal::ToInt<uint8_t>(__VA_ARGS__)))
/**
- * Expect a write to the device `dev` at the given offset with the given 16-bit
- * value.
- *
- * The value may be given as an integer, a pointer to little-endian data,
- * or a `std::initializer_list<BitField>`.
- *
- * This expectation is sequenced with all other `EXPECT_READ` and `EXPECT_WRITE`
- * calls.
- */
-#define EXPECT_WRITE16_AT(dev, offset, ...) \
- EXPECT_CALL( \
- dev, Write16(offset, mock_mmio::internal::ToInt<uint16_t>(__VA_ARGS__)))
-
-/**
* Expect a write to the device `dev` at the given offset with the given 32-bit
* value.
*
@@ -321,21 +290,6 @@
EXPECT_READ8_AT(this->dev(), offset, __VA_ARGS__)
/**
- * Expect a read at the given offset, returning the given 16-bit value.
- *
- * The value may be given as an integer, a pointer to little-endian data,
- * or a `std::initializer_list<BitField>`.
- *
- * This function is only available in tests using a fixture that derives
- * `MmioTest`.
- *
- * This expectation is sequenced with all other `EXPECT_READ` and `EXPECT_WRITE`
- * calls.
- */
-#define EXPECT_READ16(offset, ...) \
- EXPECT_READ16_AT(this->dev(), offset, __VA_ARGS__)
-
-/**
* Expect a read at the given offset, returning the given 32-bit value.
*
* The value may be given as an integer, a pointer to little-endian data,
@@ -366,21 +320,6 @@
EXPECT_WRITE8_AT(this->dev(), offset, __VA_ARGS__);
/**
- * Expect a write to the given offset with the given 16-bit value.
- *
- * The value may be given as an integer, a pointer to little-endian data,
- * or a `std::initializer_list<BitField>`.
- *
- * This function is only available in tests using a fixture that derives
- * `MmioTest`.
- *
- * This expectation is sequenced with all other `EXPECT_READ` and `EXPECT_WRITE`
- * calls.
- */
-#define EXPECT_WRITE16(offset, ...) \
- EXPECT_WRITE16_AT(this->dev(), offset, __VA_ARGS__);
-
-/**
* Expect a write to the given offset with the given 32-bit value.
*
* The value may be given as an integer, a pointer to little-endian data,
@@ -429,19 +368,6 @@
EXPECT_MASK_INTERAL_(8, dev, offset, __VA_ARGS__)
/**
- * Expect an unspecified 16-bit read to the device `dev` at the given offset,
- * followed by a write to the same location, with the same value but with some
- * bits changed; the remaining bits must be untouched.
- *
- * The changed bits are specified by a `std::initializer_list<MaskedBitField>`.
- *
- * This expectation is sequenced with all other `EXPECT_READ` and `EXPECT_WRITE`
- * calls.
- */
-#define EXPECT_MASK16_AT(dev, offset, ...) \
- EXPECT_MASK_INTERAL_(16, dev, offset, __VA_ARGS__)
-
-/**
* Expect an unspecified 32-bit read to the device `dev` at the given offset,
* followed by a write to the same location, with the same value but with some
* bits changed; the remaining bits must be untouched.
@@ -471,22 +397,6 @@
EXPECT_MASK32_AT(this->dev(), offset, __VA_ARGS__)
/**
- * Expect an unspecified 16-bit read at the given offset, followed by a write to
- * the same location, with the same value but with some bits changed; the
- * remaining bits must be untouched.
- *
- * The changed bits are specified by a `std::initializer_list<MaskedBitField>`.
- *
- * This function is only available in tests using a fixture that derives
- * `MmioTest`.
- *
- * This expectation is sequenced with all other `EXPECT_READ` and `EXPECT_WRITE`
- * calls.
- */
-#define EXPECT_MASK16(offset, ...) \
- EXPECT_MASK32_AT(this->dev(), offset, __VA_ARGS__)
-
-/**
* Expect an unspecified 32-bit read at the given offset, followed by a write to
* the same location, with the same value but with some bits changed; the
* remaining bits must be untouched.
diff --git a/sw/device/lib/testing/mock_mmio_test.cc b/sw/device/lib/testing/mock_mmio_test.cc
index 8e752b4..8ceb3d5 100644
--- a/sw/device/lib/testing/mock_mmio_test.cc
+++ b/sw/device/lib/testing/mock_mmio_test.cc
@@ -14,14 +14,16 @@
/**
* Exercises the register |dev| by reading a value at offset 0x0,
- * writing its complement to 0x4, and then writing its upper half
- * and lower half to 0x8 and 0xa.
+ * writing its complement to 0x4, and then writing it byte by byte
+ * back over itself, from MSB to LSB.
*/
uint32_t WriteTwice(mmio_region_t dev) {
auto value = mmio_region_read32(dev, 0x0);
mmio_region_write32(dev, 0x4, ~value);
- mmio_region_write16(dev, 0x8, value >> 16);
- mmio_region_write16(dev, 0xa, value & 0xffff);
+ mmio_region_write8(dev, 0x12, (value >> 24) & 0xff);
+ mmio_region_write8(dev, 0x8, (value >> 16) & 0xff);
+ mmio_region_write8(dev, 0x4, (value >> 8) & 0xff);
+ mmio_region_write8(dev, 0x0, value & 0xff);
return value;
}
@@ -29,9 +31,11 @@
TEST_F(MockMmioTest, WriteTwice) {
EXPECT_READ32(0x0, 0xdeadbeef);
- EXPECT_WRITE32(0x4, 0x21524110)
- EXPECT_WRITE16(0x8, 0xdead);
- EXPECT_WRITE16(0xa, 0xbeef);
+ EXPECT_WRITE32(0x4, 0x21524110);
+ EXPECT_WRITE8(0x12, 0xde);
+ EXPECT_WRITE8(0x8, 0xad);
+ EXPECT_WRITE8(0x4, 0xbe);
+ EXPECT_WRITE8(0x0, 0xef);
EXPECT_EQ(WriteTwice(dev().region()), 0xdeadbeef);
}
@@ -56,8 +60,8 @@
EXPECT_READ8(0xc, {{0x0, false}, {0x1, true}, {0x3, true}});
EXPECT_EQ(mmio_region_read8(dev().region(), 0xc), 0b1010);
- EXPECT_WRITE16(0x12, {{0x0, 0xfe}, {0x8, 0xca}});
- mmio_region_write16(dev().region(), 0x12, 0xcafe);
+ EXPECT_WRITE32(0x12, {{0x0, 0xfe}, {0x8, 0xca}});
+ mmio_region_write32(dev().region(), 0x12, 0xcafe);
}
TEST_F(MockMmioTest, ExpectMask) {