From 475ab7429c936af3d0079b47bf7020d1acdd9dac Mon Sep 17 00:00:00 2001 From: Emmanuel Blot Date: Mon, 27 Nov 2023 19:46:40 +0100 Subject: [PATCH] [ot] hw/opentitan: ot_dev_proxy: make MemTxAttrs role extension optional Signed-off-by: Emmanuel Blot --- hw/opentitan/ot_dev_proxy.c | 24 ++++++++++++++++++------ hw/riscv/Kconfig | 1 + 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/hw/opentitan/ot_dev_proxy.c b/hw/opentitan/ot_dev_proxy.c index f164e27c1ce2..a69bc218bb61 100644 --- a/hw/opentitan/ot_dev_proxy.c +++ b/hw/opentitan/ot_dev_proxy.c @@ -183,6 +183,18 @@ enum OtDevProxyErr { #define PROXY_MAKE_UID(_uid_, _req_) \ (((_uid_) & ~(1u << 31u)) | (((uint32_t)(bool)(_req_)) << 31u)) +#if defined(MEMTXATTRS_HAS_ROLE) && (MEMTXATTRS_HAS_ROLE != 0) +#define MEMTXATTRS_WITH_ROLE(_r_) \ + (MemTxAttrs) \ + { \ + .role = _r_ \ + } +#define MEMTXATTRS_GET_ROLE(_a_) ((_a_).unspecified ? 0xfu : (_a_).role); +#else +#define MEMTXATTRS_WITH_ROLE(_r_) MEMTXATTRS_UNSPECIFIED +#define MEMTXATTRS_GET_ROLE(_a_) ((_a_).unspecified ? 0xfu : 0x0) +#endif + static void ot_dev_proxy_send(OtDevProxyState *s, unsigned uid, int dir, uint16_t command, const void *payload, size_t length) @@ -410,7 +422,7 @@ static void ot_dev_proxy_read_reg(OtDevProxyState *s) uint64_t tmp; if (role != PROXY_DISABLED_ROLE) { - MemTxAttrs attrs = { .role = role }; + MemTxAttrs attrs = MEMTXATTRS_WITH_ROLE(role); MemTxResult res; res = ops->read_with_attrs(mr->opaque, reg << 2u, &tmp, @@ -466,7 +478,7 @@ static void ot_dev_proxy_write_reg(OtDevProxyState *s) return; } - MemTxAttrs attrs = { .role = role }; + MemTxAttrs attrs = MEMTXATTRS_WITH_ROLE(role); MemTxResult res; uint64_t tmp; @@ -526,7 +538,7 @@ static void ot_dev_proxy_read_buffer(OtDevProxyState *s, bool mbx_mode) OtDevProxyItem *item = &s->items[devix]; OtDevProxyCaps *caps = &item->caps; Object *obj = item->obj; - MemTxAttrs attrs = { .role = role }; + MemTxAttrs attrs = MEMTXATTRS_WITH_ROLE(role); MemoryRegion *mr = NULL; MemTxResult res = MEMTX_OK; @@ -639,7 +651,7 @@ static void ot_dev_proxy_write_buffer(OtDevProxyState *s, bool mbx_mode) OtDevProxyItem *item = &s->items[devix]; OtDevProxyCaps *caps = &item->caps; Object *obj = item->obj; - MemTxAttrs attrs = { .role = role }; + MemTxAttrs attrs = MEMTXATTRS_WITH_ROLE(role); MemoryRegion *mr = NULL; MemTxResult res = MEMTX_OK; @@ -1552,7 +1564,7 @@ type_init(ot_dev_proxy_register_types) OtDevProxyWatcherState *s = opaque; if (s->read && s->stop) { - unsigned role = attrs.unspecified ? 0xfu : attrs.role; + unsigned role = MEMTXATTRS_GET_ROLE(attrs); uint32_t address = s->address + (uint32_t)addr; s->stop -= 1u; ot_dev_proxy_notify_mmio_access(s->devproxy, s->wid, false, role, @@ -1569,7 +1581,7 @@ static MemTxResult ot_dev_proxy_watcher_write_with_attrs( OtDevProxyWatcherState *s = opaque; if (s->write && s->stop) { - unsigned role = attrs.unspecified ? 0xfu : attrs.role; + unsigned role = MEMTXATTRS_GET_ROLE(attrs); uint32_t address = s->address + (uint32_t)addr; ot_dev_proxy_notify_mmio_access(s->devproxy, s->wid, true, role, address, size, (uint32_t)val64); diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig index 735c793310a1..df7c25b139d9 100644 --- a/hw/riscv/Kconfig +++ b/hw/riscv/Kconfig @@ -19,6 +19,7 @@ config OT_DARJEELING select OT_AST_DARJEELING select OT_CLKMGR select OT_CSRNG + select OT_DEV_PROXY select OT_EDN select OT_ENTROPY_SRC select OT_GPIO