Introduce PCI mbox module for Nuvoton SoC
cover Introduce PCI mbox module for Nuvoton SoC
The PCI mbox module connects to a host such that the host can interact with the BMC SoC as a PCI device using a chardev. This chardev portion will be in a follow-on CL with the corresponding documentation.
Hao Wu (2):
hw/misc: Add Nuvoton's PCI Mailbox Module
hw/arm: Add PCI mailbox module to Nuvoton SoC
docs/system/arm/nuvoton.rst | 1 + hw/arm/npcm7xx.c | 15 ++- hw/misc/meson.build | 1 + hw/misc/npcm7xx_pci_mbox.c | 178 +++++++++++++++++++++++++++++ hw/misc/trace-events | 5 + include/hw/arm/npcm7xx.h | 2 + include/hw/misc/npcm7xx_pci_mbox.h | 63 ++++++++++ 7 files changed, 264 insertions(+), 1 deletion(-) create mode 100644 hw/misc/npcm7xx_pci_mbox.c create mode 100644 include/hw/misc/npcm7xx_pci_mbox.h
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
PATCH 2/2 hw/arm: Add PCI mailbox module to Nuvoton SoC
From: Hao Wu <[email protected]>
This patch wires the PCI mailbox module to Nuvoton SoC.
--- docs/system/arm/nuvoton.rst | 1 + hw/arm/npcm7xx.c | 15 ++++++++++++++- include/hw/arm/npcm7xx.h | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-)
docs/system/arm/nuvoton.rst +1 -0
@@ -48,6 +48,7 @@ Supported devices * SMBus controller (SMBF) * Ethernet controller (EMC) * Tachometer + * PCI Mailbox Missing devices ---------------
hw/arm/npcm7xx.c +14 -1
@@ -53,6 +53,9 @@/* ADC Module */ #define NPCM7XX_ADC_BA (0xf000c000) +/* PCI Mailbox Module */ +#define NPCM7XX_PCI_MBOX_BA (0xf0848000) +/* Internal AHB SRAM */ #define NPCM7XX_RAM3_BA (0xc0008000)#define NPCM7XX_RAM3_SZ (4 * KiB)
@@ -83,6 +86,7 @@ enum NPCM7xxInterrupt {NPCM7XX_UART1_IRQ ,NPCM7XX_UART2_IRQ ,NPCM7XX_UART3_IRQ , +NPCM7XX_PCI_MBOX_IRQ =8 ,NPCM7XX_EMC1RX_IRQ =15 ,NPCM7XX_EMC1TX_IRQ , NPCM7XX_MMC_IRQ = 26,
@@ -447,6 +451,8 @@ static void npcm7xx_init(Object *obj)object_initialize_child (obj,"emc[*]" , &s->emc[i],TYPE_NPCM7XX_EMC ); } +object_initialize_child (obj,"pci-mbox" , &s->pci_mbox, +TYPE_NPCM7XX_PCI_MBOX );object_initialize_child (obj,"mmc" , &s->mmc,TYPE_NPCM7XX_SDHCI ); }
@@ -697,6 +703,14 @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) } } +/* PCI Mailbox. Cannot fail */ +sysbus_realize (SYS_BUS_DEVICE (&s->pci_mbox), &error_abort); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->pci_mbox),0 ,NPCM7XX_PCI_MBOX_BA ); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->pci_mbox),1 , +NPCM7XX_PCI_MBOX_BA +NPCM7XX_PCI_MBOX_RAM_SIZE ); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->pci_mbox),0 , +npcm7xx_irq (s,NPCM7XX_PCI_MBOX_IRQ )); +/* RAM2 (SRAM) */ memory_region_init_ram (&s->sram,OBJECT (dev),"ram2" ,NPCM7XX_RAM2_SZ , &error_abort);
@@ -747,7 +761,6 @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)create_unimplemented_device ("npcm7xx.usbd[8]" ,0xf0838000 ,4 * KiB);create_unimplemented_device ("npcm7xx.usbd[9]" ,0xf0839000 ,4 * KiB);create_unimplemented_device ("npcm7xx.sd" ,0xf0840000 ,8 * KiB); -create_unimplemented_device ("npcm7xx.pcimbx" ,0xf0848000 ,512 * KiB);create_unimplemented_device ("npcm7xx.aes" ,0xf0858000 ,4 * KiB);create_unimplemented_device ("npcm7xx.des" ,0xf0859000 ,4 * KiB);create_unimplemented_device ("npcm7xx.sha" ,0xf085a000 ,4 * KiB);
include/hw/arm/npcm7xx.h +2 -0
@@ -26,6 +26,7 @@#include "hw/misc/npcm7xx_clk.h" #include "hw/misc/npcm7xx_gcr.h" #include "hw/misc/npcm7xx_mft.h" +#include "hw/misc/npcm7xx_pci_mbox.h" #include "hw/misc/npcm7xx_pwm.h" #include "hw/misc/npcm7xx_rng.h" #include "hw/net/npcm7xx_emc.h"
@@ -104,6 +105,7 @@ typedef struct NPCM7xxState {OHCISysBusState ohci;NPCM7xxFIUState fiu[2 ];NPCM7xxEMCState emc[2 ]; +NPCM7xxPCIMBoxState pci_mbox;NPCM7xxSDHCIState mmc; } NPCM7xxState;
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
PATCH 1/2 hw/misc: Add Nuvoton's PCI Mailbox Module
In reply to Patrick VentureFrom: Hao Wu <[email protected]>
The PCI Mailbox Module is a high-bandwidth communcation module between a Nuvoton BMC and CPU. It features 16KB RAM that are both accessible by the BMC and core CPU. and supports interrupt for both sides.
This patch implements the BMC side of the PCI mailbox module. Communication with the core CPU is emulated via a chardev and will be in a follow-up patch.
--- hw/misc/meson.build | 1 + hw/misc/npcm7xx_pci_mbox.c | 178 +++++++++++++++++++++++++++++ hw/misc/trace-events | 5 + include/hw/misc/npcm7xx_pci_mbox.h | 63 ++++++++++ 4 files changed, 247 insertions(+) create mode 100644 hw/misc/npcm7xx_pci_mbox.c create mode 100644 include/hw/misc/npcm7xx_pci_mbox.h
hw/misc/meson.build +1 -0
@@ -63,6 +63,7 @@ softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files( 'npcm7xx_clk.c', 'npcm7xx_gcr.c', 'npcm7xx_mft.c', + 'npcm7xx_pci_mbox.c', 'npcm7xx_pwm.c', 'npcm7xx_rng.c', ))
hw/misc/npcm7xx_pci_mbox.c new file +178 -0
178 lines not on this page · raw message
hw/misc/trace-events +5 -0
@@ -124,6 +124,11 @@ npcm7xx_pwm_write(const char *id, uint64_t offset, uint32_t value) "%s offset: 0 npcm7xx_pwm_update_freq(const char *id, uint8_t index, uint32_t old_value, uint32_t new_value) "%s pwm[%u] Update Freq: old_freq: %u, new_freq: %u" npcm7xx_pwm_update_duty(const char *id, uint8_t index, uint32_t old_value, uint32_t new_value) "%s pwm[%u] Update Duty: old_duty: %u, new_duty: %u" +# npcm7xx_pci_mbox.c +npcm7xx_pci_mbox_read(const char *id, uint64_t offset, uint64_t value, unsigned size) "%s offset: 0x%04" PRIx64 " value: 0x%02" PRIx64 " size: %u" +npcm7xx_pci_mbox_write(const char *id, uint64_t offset, uint64_t value, unsigned size) "%s offset: 0x%04" PRIx64 " value: 0x%02" PRIx64 " size: %u" +npcm7xx_pci_mbox_irq(int irq_level) "irq level: %d" + # stm32f4xx_syscfg.c stm32f4xx_syscfg_set_irq(int gpio, int line, int level) "Interrupt: GPIO: %d, Line: %d; Level: %d" stm32f4xx_pulse_exti(int irq) "Pulse EXTI: %d"
include/hw/misc/npcm7xx_pci_mbox.h new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
Re: [PATCH 1/2] hw/misc: Add Nuvoton's PCI Mailbox Module
Quoted 8 lines · Patrick Venture
From: Hao Wu <[email protected]>
The PCI Mailbox Module is a high-bandwidth communcation module between a Nuvoton BMC and CPU. It features 16KB RAM that are both accessible by the BMC and core CPU. and supports interrupt for both sides.
Quoted 6 lines
This patch implements the BMC side of the PCI mailbox module. Communication with the core CPU is emulated via a chardev and will be in a follow-up patch.
Reviewed-by Patrick Venture <[email protected]>Reviewed-by Joe Komlodi <[email protected]>
Hi; this mostly looks good, but I have a question about s->content.
hw/misc/npcm7xx_pci_mbox.c line 136
Quoted 7 lines
hw/misc/npcm7xx_pci_mbox.c new file +7
-0+static void npcm7xx_pci_mbox_init (Object *obj) +{ +NPCM7xxPCIMBoxState *s =NPCM7XX_PCI_MBOX (obj); +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); + +memory_region_init_ram_device_ptr (&s->ram, obj,"pci-mbox-ram" , +NPCM7XX_PCI_MBOX_RAM_SIZE , s->content);
What's s->content for? Nothing in the rest of the device emulation touches it, which seems odd.
memory_region_init_ram_device_ptr() is intended primarily for "create a MemoryRegion corresponding to something like a bit of a host device (eg a host PCI MMIO BAR). That doesn't seem like what you're doing here. In particular, using it means that you take on responsibility for ensuring that the underlying memory gets migrated, which you're not doing.
If you just want a MemoryRegion that's backed by a bit of host memory, use memory_region_init_ram().
include/hw/misc/npcm7xx_pci_mbox.h line 61
Quoted 3 lines
include/hw/misc/npcm7xx_pci_mbox.h new file +3
-0+#define TYPE_NPCM7XX_PCI_MBOX "npcm7xx-pci-mbox" +#define NPCM7XX_PCI_MBOX (obj) \ + OBJECT_CHECK(NPCM7xxPCIMBoxState, (obj), TYPE_NPCM7XX_PCI_MBOX)
We prefer the OBJECT_DECLARE_SIMPLE_TYPE() macro rather than hand-defining a cast macro these days.
thanks
-- PMM
Re: [PATCH 2/2] hw/arm: Add PCI mailbox module to Nuvoton SoC
In reply to Patrick VentureQuoted 9 lines · Patrick Venture
From: Hao Wu <[email protected]>
This patch wires the PCI mailbox module to Nuvoton SoC.
Reviewed-by Patrick Venture <[email protected]>Reviewed-by Joe Komlodi <[email protected]>Signed-off-by Hao Wu <[email protected]>---
thanks
-- PMM
Re: [PATCH 1/2] hw/misc: Add Nuvoton's PCI Mailbox Module
In reply to Peter MaydellQuoted 27 lines · Peter Maydell
Quoted 8 lines · Patrick Venture
From: Hao Wu <[email protected]>
The PCI Mailbox Module is a high-bandwidth communcation module between a Nuvoton BMC and CPU. It features 16KB RAM that are both accessible by the BMC and core CPU. and supports interrupt for both sides.
Quoted 6 lines
This patch implements the BMC side of the PCI mailbox module. Communication with the core CPU is emulated via a chardev and will be in a follow-up patch.
Reviewed-by Patrick Venture <[email protected]>Reviewed-by Joe Komlodi <[email protected]>Hi; this mostly looks good, but I have a question about
s->content.hw/misc/npcm7xx_pci_mbox.c
Quoted 7 lines
hw/misc/npcm7xx_pci_mbox.c new file +7
-0+static void npcm7xx_pci_mbox_init (Object *obj) +{ +NPCM7xxPCIMBoxState *s =NPCM7XX_PCI_MBOX (obj); +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); + + memory_region_init_ram_device_ptr(&s->ram, obj, "pci-mbox-ram", + NPCM7XX_PCI_MBOX_RAM_SIZE,
s->content);
Quoted 3 lines
What's
s->contentfor? Nothing in the rest of the device emulation touches it, which seems odd.
Hao informed me that we can drop the content bit here, since it's not used until a later patch that we'll be sending up with a bit more detail when we get a chance. I sent this series up to land some of the groundwork.
I can send out a v2 with that bit removed.
Quoted 11 lines
memory_region_init_ram_device_ptr()is intended primarily for "create a MemoryRegion corresponding to something like a bit of a host device (eg a host PCI MMIO BAR). That doesn't seem like what you're doing here. In particular, using it means that you take on responsibility for ensuring that the underlying memory gets migrated, which you're not doing.If you just want a MemoryRegion that's backed by a bit of host memory, use
memory_region_init_ram().
I think this is what we use it for in the future patches, when we add it back, it'll come with the context.
Quoted 8 lines
include/hw/misc/npcm7xx_pci_mbox.h line 61
Quoted 4 lines
include/hw/misc/npcm7xx_pci_mbox.h new file +3
-0+#define TYPE_NPCM7XX_PCI_MBOX "npcm7xx-pci-mbox" +#define NPCM7XX_PCI_MBOX (obj) \ + OBJECT_CHECK(NPCM7xxPCIMBoxState, (obj), TYPE_NPCM7XX_PCI_MBOX)We prefer the
OBJECT_DECLARE_SIMPLE_TYPE()macro rather than hand-defining a cast macro these days.
Ack.
Quoted 4 lines
thanks
-- PMM
Thanks!
Re: [PATCH 1/2] hw/misc: Add Nuvoton's PCI Mailbox Module
Quoted 68 lines · Patrick Venture
Quoted 27 lines · Peter Maydell
Quoted 8 lines · Patrick Venture
From: Hao Wu <[email protected]>
The PCI Mailbox Module is a high-bandwidth communcation module between a Nuvoton BMC and CPU. It features 16KB RAM that are both accessible by the BMC and core CPU. and supports interrupt for both sides.
Quoted 6 lines
This patch implements the BMC side of the PCI mailbox module. Communication with the core CPU is emulated via a chardev and will be in a follow-up patch.
Reviewed-by Patrick Venture <[email protected]>Reviewed-by Joe Komlodi <[email protected]>Hi; this mostly looks good, but I have a question about
s->content.hw/misc/npcm7xx_pci_mbox.c
Quoted 7 lines
hw/misc/npcm7xx_pci_mbox.c new file +7
-0+static void npcm7xx_pci_mbox_init (Object *obj) +{ +NPCM7xxPCIMBoxState *s =NPCM7XX_PCI_MBOX (obj); +SysBusDevice *sbd =SYS_BUS_DEVICE (obj); + + memory_region_init_ram_device_ptr(&s->ram, obj, "pci-mbox-ram", + NPCM7XX_PCI_MBOX_RAM_SIZE,
s->content);Quoted 3 lines
What's
s->contentfor? Nothing in the rest of the device emulation touches it, which seems odd.Hao informed me that we can drop the content bit here, since it's not used until a later patch that we'll be sending up with a bit more detail when we get a chance. I sent this series up to land some of the groundwork.
I can send out a v2 with that bit removed.
Quoted 11 lines
memory_region_init_ram_device_ptr()is intended primarily for "create a MemoryRegion corresponding to something like a bit of a host device (eg a host PCI MMIO BAR). That doesn't seem like what you're doing here. In particular, using it means that you take on responsibility for ensuring that the underlying memory gets migrated, which you're not doing.If you just want a MemoryRegion that's backed by a bit of host memory, use
memory_region_init_ram().I think this is what we use it for in the future patches, when we add it back, it'll come with the context.
Quoted 8 lines
include/hw/misc/npcm7xx_pci_mbox.h line 61
Quoted 4 lines
include/hw/misc/npcm7xx_pci_mbox.h new file +3
-0+#define TYPE_NPCM7XX_PCI_MBOX "npcm7xx-pci-mbox" +#define NPCM7XX_PCI_MBOX (obj) \ + OBJECT_CHECK(NPCM7xxPCIMBoxState, (obj), TYPE_NPCM7XX_PCI_MBOX)We prefer the
OBJECT_DECLARE_SIMPLE_TYPE()macro rather than hand-defining a cast macro these days.
Quoted 8 lines
Ack.
Quoted 4 lines
thanks
-- PMM
Peter, just an FYI, this fell off my radar, but I will be circling back this week to revisit any patches I've sent that are in limbo or waiting on me, etc. Thanks for your patience.
Quoted 3 lines
Thanks!