[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 35/45] Add mailbox test stub
From: |
Sergey Kambalin |
Subject: |
[PATCH v3 35/45] Add mailbox test stub |
Date: |
Sun, 3 Dec 2023 15:49:00 -0600 |
Signed-off-by: Sergey Kambalin <sergey.kambalin@auriga.com>
---
include/hw/arm/bcm2838_peripherals.h | 2 +
tests/qtest/bcm2838-mailbox.c | 71 ++++++++++++++++++++++++++++
tests/qtest/bcm2838-mailbox.h | 46 ++++++++++++++++++
tests/qtest/meson.build | 1 +
4 files changed, 120 insertions(+)
create mode 100644 tests/qtest/bcm2838-mailbox.c
create mode 100644 tests/qtest/bcm2838-mailbox.h
diff --git a/include/hw/arm/bcm2838_peripherals.h
b/include/hw/arm/bcm2838_peripherals.h
index cdeb892f04..2b97e55048 100644
--- a/include/hw/arm/bcm2838_peripherals.h
+++ b/include/hw/arm/bcm2838_peripherals.h
@@ -56,6 +56,8 @@
#define BCM2838_MPHI_OFFSET 0xb200
#define BCM2838_MPHI_SIZE 0x200
+#define GENET_OFFSET 0x1580000
+
#define TYPE_BCM2838_PERIPHERALS "bcm2838-peripherals"
OBJECT_DECLARE_TYPE(BCM2838PeripheralState, BCM2838PeripheralClass,
BCM2838_PERIPHERALS)
diff --git a/tests/qtest/bcm2838-mailbox.c b/tests/qtest/bcm2838-mailbox.c
new file mode 100644
index 0000000000..2edc24e15e
--- /dev/null
+++ b/tests/qtest/bcm2838-mailbox.c
@@ -0,0 +1,71 @@
+/*
+ * Helper functions to work with BCM2838 mailbox via qtest interface.
+ *
+ * Copyright (c) 2023 Auriga LLC
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "hw/registerfields.h"
+#include "libqtest-single.h"
+#include "bcm2838-mailbox.h"
+
+
+static uint32_t qtest_mbox0_read_reg32(QTestState *s, uint32_t offset)
+{
+ return qtest_readl(s, MBOX0_BASE + offset);
+}
+
+static void qtest_mbox1_write_reg32(QTestState *s, uint32_t offset, uint32_t
value)
+{
+ return qtest_writel(s, MBOX1_BASE + offset, value);
+}
+
+static void qtest_mbox1_write(QTestState *s, uint8_t channel, uint32_t data)
+{
+ uint32_t reg;
+
+ reg = FIELD_DP32(reg, MBOX_WRITE_REG, CHANNEL, channel);
+ reg = FIELD_DP32(reg, MBOX_WRITE_REG, DATA, data);
+ qtest_mbox1_write_reg32(s, MBOX_REG_WRITE, reg);
+}
+
+int qtest_mbox0_has_data(QTestState *s) {
+ return !(qtest_mbox0_read_reg32(s, MBOX_REG_STATUS) & MBOX_READ_EMPTY);
+}
+
+int mbox0_has_data(void) {
+ return qtest_mbox0_has_data(global_qtest);
+}
+
+void qtest_mbox0_read_message(QTestState *s,
+ uint8_t channel,
+ void *msgbuf,
+ size_t msgbuf_size)
+{
+ uint32_t reg;
+ uint32_t msgaddr;
+
+ g_assert(qtest_mbox0_has_data(s));
+ reg = qtest_mbox0_read_reg32(s, MBOX_REG_READ);
+ g_assert_cmphex(FIELD_EX32(reg, MBOX_WRITE_REG, CHANNEL), ==, channel);
+ msgaddr = FIELD_EX32(reg, MBOX_WRITE_REG, DATA) << 4;
+ qtest_memread(s, msgaddr, msgbuf, msgbuf_size);
+}
+
+void mbox0_read_message(uint8_t channel, void *msgbuf, size_t msgbuf_size) {
+ qtest_mbox0_read_message(global_qtest, channel, msgbuf, msgbuf_size);
+}
+
+void qtest_mbox1_write_message(QTestState *s, uint8_t channel, uint32_t
msg_addr)
+{
+ qtest_mbox1_write(s, channel, msg_addr >> 4);
+}
+
+
+void mbox1_write_message(uint8_t channel, uint32_t msg_addr)
+{
+ qtest_mbox1_write_message(global_qtest, channel, msg_addr);
+}
diff --git a/tests/qtest/bcm2838-mailbox.h b/tests/qtest/bcm2838-mailbox.h
new file mode 100644
index 0000000000..1d02ca9c2c
--- /dev/null
+++ b/tests/qtest/bcm2838-mailbox.h
@@ -0,0 +1,46 @@
+/*
+ * Declarations for BCM2838 mailbox test.
+ *
+ * Copyright (c) 2023 Auriga LLC
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+
+REG32(MBOX_WRITE_REG, 0)
+FIELD(MBOX_WRITE_REG, CHANNEL, 0, 4)
+FIELD(MBOX_WRITE_REG, DATA, 4, 28)
+
+REG32(MBOX_SIZE_STAT, 0)
+FIELD(MBOX_WRITE_REG, SIZE, 0, 30)
+FIELD(MBOX_WRITE_REG, SUCCESS, 30, 1)
+
+typedef struct {
+ uint32_t size;
+ uint32_t req_resp_code;
+} MboxBufHeader;
+
+#define DECLARE_TAG_TYPE(TypeName, RequestValueType, ResponseValueType) \
+typedef struct { \
+ uint32_t id; \
+ uint32_t value_buffer_size; \
+ union { \
+ struct { \
+ uint32_t zero; \
+ RequestValueType value; \
+ } request; \
+ struct { \
+ uint32_t size_stat; \
+ ResponseValueType value; \
+ } response; \
+ }; \
+} TypeName
+
+
+int mbox0_has_data(void);
+void mbox0_read_message(uint8_t channel, void *msgbuf, size_t msgbuf_size);
+void mbox1_write_message(uint8_t channel, uint32_t msg_addr);
+int qtest_mbox0_has_data(QTestState *s);
+void qtest_mbox0_read_message(QTestState *s, uint8_t channel, void *msgbuf,
size_t msgbuf_size);
+void qtest_mbox1_write_message(QTestState *s, uint8_t channel, uint32_t
msg_addr);
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
index 47dabf91d0..92eba5ac99 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -321,6 +321,7 @@ qtests = {
'virtio-net-failover': files('migration-helpers.c'),
'vmgenid-test': files('boot-sector.c', 'acpi-utils.c'),
'netdev-socket': files('netdev-socket.c', '../unit/socket-helpers.c'),
+ 'bcm2838-mbox-property-test' : files('bcm2838-mailbox.c'),
}
if vnc.found()
--
2.34.1
- [PATCH v3 25/45] Add GENET register structs. Part 3, (continued)
- [PATCH v3 25/45] Add GENET register structs. Part 3, Sergey Kambalin, 2023/12/03
- [PATCH v3 26/45] Add GENET register structs. Part 4, Sergey Kambalin, 2023/12/03
- [PATCH v3 27/45] Add GENET register access macros, Sergey Kambalin, 2023/12/03
- [PATCH v3 28/45] Implement GENET register ops, Sergey Kambalin, 2023/12/03
- [PATCH v3 29/45] Implement GENET MDIO, Sergey Kambalin, 2023/12/03
- [PATCH v3 30/45] Implement GENET TX path, Sergey Kambalin, 2023/12/03
- [PATCH v3 31/45] Implement GENET RX path, Sergey Kambalin, 2023/12/03
- [PATCH v3 32/45] Enable BCM2838 GENET controller, Sergey Kambalin, 2023/12/03
- [PATCH v3 33/45] Connect RNG200, PCIE and GENET to GIC, Sergey Kambalin, 2023/12/03
- [PATCH v3 34/45] Add Rpi4b boot tests, Sergey Kambalin, 2023/12/03
- [PATCH v3 35/45] Add mailbox test stub,
Sergey Kambalin <=
- [PATCH v3 36/45] Add mailbox test constants, Sergey Kambalin, 2023/12/03
- [PATCH v3 37/45] Add mailbox tests tags. Part 1, Sergey Kambalin, 2023/12/03
- [PATCH v3 38/45] Add mailbox tests tags. Part 2, Sergey Kambalin, 2023/12/03
- [PATCH v3 39/45] Add mailbox tests tags. Part 3, Sergey Kambalin, 2023/12/03
- [PATCH v3 40/45] Add mailbox property tests. Part 1, Sergey Kambalin, 2023/12/03
- [PATCH v3 41/45] Add mailbox property tests. Part 2, Sergey Kambalin, 2023/12/03
- [PATCH v3 42/45] Add mailbox property tests. Part 3, Sergey Kambalin, 2023/12/03
- [PATCH v3 43/45] Add missed BCM2835 properties, Sergey Kambalin, 2023/12/03
- [PATCH v3 44/45] Append added properties to mailbox test, Sergey Kambalin, 2023/12/03
- [PATCH v3 45/45] Add RPi4B to paspi4.rst, Sergey Kambalin, 2023/12/03