Skip to content

Commit 4e8a317

Browse files
committed
[ot] hw/opentitan: ot_spi_device: Add Passthrough IRQs and SPI Host prop
This adds the corresponding out IRQs to OT SPI Device, as well as a property that contains the downstream OT SPI Host. Signed-off-by: Alice Ziuziakowska <[email protected]>
1 parent 93272e9 commit 4e8a317

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

hw/opentitan/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ config OT_SOCDBG_CTRL
196196

197197
config OT_SPI_DEVICE
198198
bool
199+
select OT_SPI_HOST
199200

200201
config OT_SPI_HOST
201202
bool

hw/opentitan/ot_spi_device.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "hw/opentitan/ot_common.h"
3737
#include "hw/opentitan/ot_fifo32.h"
3838
#include "hw/opentitan/ot_spi_device.h"
39+
#include "hw/opentitan/ot_spi_host.h"
3940
#include "hw/qdev-properties-system.h"
4041
#include "hw/qdev-properties.h"
4142
#include "hw/registerfields.h"
@@ -450,12 +451,17 @@ struct OtSPIDeviceState {
450451
SpiDeviceFlash flash;
451452
SpiDeviceTpm tpm;
452453

454+
/* CS signal for downstream flash in passthrough mode, active low */
455+
IbexIRQ passthrough_cs;
456+
IbexIRQ passthrough_en;
457+
453458
uint32_t *spi_regs; /* Registers */
454459
uint32_t *tpm_regs; /* Registers */
455460
uint32_t *sram;
456461

457462
/* Properties */
458463
char *ot_id;
464+
OtSPIHostState *spihost; /* downstream SPI Host */
459465
CharBackend chr; /* communication device */
460466
guint watch_tag; /* tracker for comm device change */
461467
};
@@ -2311,6 +2317,8 @@ static int ot_spi_device_chr_be_change(void *opaque)
23112317
static Property ot_spi_device_properties[] = {
23122318
DEFINE_PROP_STRING(OT_COMMON_DEV_ID, OtSPIDeviceState, ot_id),
23132319
DEFINE_PROP_CHR("chardev", OtSPIDeviceState, chr),
2320+
DEFINE_PROP_LINK("spihost", OtSPIDeviceState, spihost, TYPE_OT_SPI_HOST,
2321+
OtSPIHostState *),
23142322
DEFINE_PROP_END_OF_LIST(),
23152323
};
23162324

@@ -2373,6 +2381,9 @@ static void ot_spi_device_reset_enter(Object *obj, ResetType type)
23732381

23742382
s->tpm_regs[R_TPM_CAP] = 0x660100u;
23752383

2384+
ibex_irq_lower(&s->passthrough_en);
2385+
ibex_irq_raise(&s->passthrough_cs);
2386+
23762387
ot_spi_device_update_irqs(s);
23772388
ot_spi_device_update_alerts(s);
23782389
}
@@ -2430,6 +2441,12 @@ static void ot_spi_device_init(Object *obj)
24302441
ibex_qdev_init_irq(obj, &s->alerts[ix], OT_DEVICE_ALERT);
24312442
}
24322443

2444+
/* Passthrough enable is active high, CS is active low */
2445+
ibex_qdev_init_irq_default(OBJECT(s), &s->passthrough_en,
2446+
OT_SPI_DEVICE_PASSTHROUGH_EN, 0);
2447+
ibex_qdev_init_irq_default(OBJECT(s), &s->passthrough_cs,
2448+
OT_SPI_DEVICE_PASSTHROUGH_CS, 1);
2449+
24332450
/*
24342451
* This timer is used to hand over to the vCPU whenever a READBUF_* irq is
24352452
* raised, otherwide the vCPU would not be able to get notified that a

include/hw/opentitan/ot_spi_device.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
* QEMU OpenTitan SPI Device controller
33
*
44
* Copyright (c) 2023-2025 Rivos, Inc.
5+
* Copyright (c) 2025 lowRISC contributors.
56
*
67
* Author(s):
78
* Emmanuel Blot <[email protected]>
9+
* Alice Ziuziakowska <[email protected]>
810
*
911
* Permission is hereby granted, free of charge, to any person obtaining a copy
1012
* of this software and associated documentation files (the "Software"), to deal
@@ -33,4 +35,8 @@
3335
#define TYPE_OT_SPI_DEVICE "ot-spi_device"
3436
OBJECT_DECLARE_TYPE(OtSPIDeviceState, OtSPIDeviceClass, OT_SPI_DEVICE)
3537

38+
/* IRQ lines to downstream OT SPI Host */
39+
#define OT_SPI_DEVICE_PASSTHROUGH_EN (TYPE_OT_SPI_DEVICE "-passthrough-en")
40+
#define OT_SPI_DEVICE_PASSTHROUGH_CS (TYPE_OT_SPI_DEVICE "-passthrough-cs")
41+
3642
#endif /* HW_OPENTITAN_OT_SPI_DEVICE_H */

0 commit comments

Comments
 (0)