Skip to content

Commit 31b8cd2

Browse files
committed
[ot] hw/opentitan: ot_uart: add ot_id identifier string
Signed-off-by: Emmanuel Blot <eblot@rivosinc.com>
1 parent 2ce9880 commit 31b8cd2

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

hw/opentitan/ot_uart.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* QEMU OpenTitan UART device
33
*
44
* Copyright (c) 2022-2024 Rivos, Inc.
5+
* Copyright (c) 2025 lowRISC contributors.
56
*
67
* Author(s):
78
* Loïc Lefort <loic@rivosinc.com>
@@ -156,6 +157,7 @@ struct OtUARTState {
156157
uint32_t tx_watermark_level;
157158
guint watch_tag;
158159

160+
char *ot_id;
159161
uint32_t pclk;
160162
CharBackend chr;
161163
};
@@ -180,7 +182,7 @@ static void ot_uart_update_irqs(OtUARTState *s)
180182
{
181183
uint32_t state_masked = s->regs[R_INTR_STATE] & s->regs[R_INTR_ENABLE];
182184

183-
trace_ot_uart_irqs(s->regs[R_INTR_STATE], s->regs[R_INTR_ENABLE],
185+
trace_ot_uart_irqs(s->ot_id, s->regs[R_INTR_STATE], s->regs[R_INTR_ENABLE],
184186
state_masked);
185187

186188
for (int index = 0; index < OT_UART_IRQ_NUM; index++) {
@@ -451,7 +453,7 @@ static uint64_t ot_uart_read(void *opaque, hwaddr addr, unsigned size)
451453
}
452454

453455
uint32_t pc = ibex_get_current_pc();
454-
trace_ot_uart_io_read_out((uint32_t)addr, REG_NAME(reg), val32, pc);
456+
trace_ot_uart_io_read_out(s->ot_id, (uint32_t)addr, REG_NAME(reg), val32, pc);
455457

456458
return (uint64_t)val32;
457459
}
@@ -466,7 +468,7 @@ static void ot_uart_write(void *opaque, hwaddr addr, uint64_t val64,
466468
hwaddr reg = R32_OFF(addr);
467469

468470
uint32_t pc = ibex_get_current_pc();
469-
trace_ot_uart_io_write((uint32_t)addr, REG_NAME(reg), val32, pc);
471+
trace_ot_uart_io_write(s->ot_id, (uint32_t)addr, REG_NAME(reg), val32, pc);
470472

471473
switch (reg) {
472474
case R_INTR_STATE:
@@ -557,6 +559,7 @@ static const MemoryRegionOps ot_uart_ops = {
557559
};
558560

559561
static Property ot_uart_properties[] = {
562+
DEFINE_PROP_STRING("ot_id", OtUARTState, ot_id),
560563
DEFINE_PROP_CHR("chardev", OtUARTState, chr),
561564
DEFINE_PROP_UINT32("pclk", OtUARTState, pclk, 0u),
562565
DEFINE_PROP_END_OF_LIST(),
@@ -579,18 +582,6 @@ static int ot_uart_be_change(void *opaque)
579582
return 0;
580583
}
581584

582-
static void ot_uart_realize(DeviceState *dev, Error **errp)
583-
{
584-
OtUARTState *s = OT_UART(dev);
585-
(void)errp;
586-
587-
fifo8_create(&s->tx_fifo, OT_UART_TX_FIFO_SIZE);
588-
fifo8_create(&s->rx_fifo, OT_UART_RX_FIFO_SIZE);
589-
590-
qemu_chr_fe_set_handlers(&s->chr, ot_uart_can_receive, ot_uart_receive,
591-
NULL, ot_uart_be_change, s, NULL, true);
592-
}
593-
594585
static void ot_uart_reset(DeviceState *dev)
595586
{
596587
OtUARTState *s = OT_UART(dev);
@@ -608,6 +599,23 @@ static void ot_uart_reset(DeviceState *dev)
608599
ibex_irq_set(&s->alert, 0);
609600
}
610601

602+
static void ot_uart_realize(DeviceState *dev, Error **errp)
603+
{
604+
OtUARTState *s = OT_UART(dev);
605+
(void)errp;
606+
607+
if (!s->ot_id) {
608+
s->ot_id =
609+
g_strdup(object_get_canonical_path_component(OBJECT(s)->parent));
610+
}
611+
612+
fifo8_create(&s->tx_fifo, OT_UART_TX_FIFO_SIZE);
613+
fifo8_create(&s->rx_fifo, OT_UART_RX_FIFO_SIZE);
614+
615+
qemu_chr_fe_set_handlers(&s->chr, ot_uart_can_receive, ot_uart_receive,
616+
NULL, ot_uart_be_change, s, NULL, true);
617+
}
618+
611619
static void ot_uart_init(Object *obj)
612620
{
613621
OtUARTState *s = OT_UART(obj);

hw/opentitan/trace-events

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ ot_timer_update_irq(const char *id, bool level) "%s: %d"
503503

504504
# ot_uart.c
505505

506-
ot_uart_debug(const char *msg) "%s"
507-
ot_uart_io_read_out(uint32_t addr, const char *regname, uint32_t val, uint32_t pc) "addr=0x%02x (%s), val=0x%x, pc=0x%x"
508-
ot_uart_io_write(uint32_t addr, const char *regname, uint32_t val, uint32_t pc) "addr=0x%02x (%s), val=0x%x, pc=0x%x"
509-
ot_uart_irqs(uint32_t active, uint32_t mask, uint32_t eff) "act:0x%08x msk:0x%08x eff:0x%08x"
506+
ot_uart_debug(const char *id, const char *msg) "%s: %s"
507+
ot_uart_io_read_out(const char *id, uint32_t addr, const char *regname, uint32_t val, uint32_t pc) "%s: addr=0x%02x (%s), val=0x%x, pc=0x%x"
508+
ot_uart_io_write(const char *id, uint32_t addr, const char *regname, uint32_t val, uint32_t pc) "%s: addr=0x%02x (%s), val=0x%x, pc=0x%x"
509+
ot_uart_irqs(const char *id, uint32_t active, uint32_t mask, uint32_t eff) "%s: act:0x%08x msk:0x%08x eff:0x%08x"

0 commit comments

Comments
 (0)