1 | The following changes since commit 9435a8b3dd35f1f926f1b9127e8a906217a5518a: | 1 | The following changes since commit 8032c78e556cd0baec111740a6c636863f9bd7c8: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/kraxel/tags/sirius/ipxe-20200908-pull-request' into staging (2020-09-08 21:21:13 +0100) | 3 | Merge tag 'firmware-20241216-pull-request' of https://gitlab.com/kraxel/qemu into staging (2024-12-16 14:20:33 -0500) |
4 | 4 | ||
5 | are available in the Git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | git@github.com:alistair23/qemu.git tags/pull-riscv-to-apply-20200910 | 7 | https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20241219-1 |
8 | 8 | ||
9 | for you to fetch changes up to 7595a65818ea9b49c36650a8c217a1ef9bd6e62a: | 9 | for you to fetch changes up to 5632d271be16b5e769342d54198c4359658abcb7: |
10 | 10 | ||
11 | hw/riscv: Sort the Kconfig options in alphabetical order (2020-09-09 15:54:19 -0700) | 11 | target/riscv: add support for RV64 Xiangshan Nanhu CPU (2024-12-18 11:07:59 +1000) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | This PR includes multiple fixes and features for RISC-V: | 14 | RISC-V PR for 10.0 |
15 | - Fixes a bug in printing trap causes | 15 | |
16 | - Allows 16-bit writes to the SiFive test device. This fixes the | 16 | * Correct the validness check of iova |
17 | failure to reboot the RISC-V virt machine | 17 | * Fix APLIC in_clrip and clripnum write emulation |
18 | - Support for the Microchip PolarFire SoC and Icicle Kit | 18 | * Support riscv-iommu-sys device |
19 | - A reafactor of RISC-V code out of hw/riscv | 19 | * Add Tenstorrent Ascalon CPU |
20 | * Add AIA userspace irqchip_split support | ||
21 | * Add Microblaze V generic board | ||
22 | * Upgrade ACPI SPCR table to support SPCR table revision 4 format | ||
23 | * Remove tswap64() calls from HTIF | ||
24 | * Support 64-bit address of initrd | ||
25 | * Introduce svukte ISA extension | ||
26 | * Support ssstateen extension | ||
27 | * Support for RV64 Xiangshan Nanhu CPU | ||
20 | 28 | ||
21 | ---------------------------------------------------------------- | 29 | ---------------------------------------------------------------- |
22 | Bin Meng (28): | 30 | Anton Blanchard (1): |
23 | target/riscv: cpu: Add a new 'resetvec' property | 31 | target/riscv: Add Tenstorrent Ascalon CPU |
24 | hw/riscv: hart: Add a new 'resetvec' property | ||
25 | target/riscv: cpu: Set reset vector based on the configured property value | ||
26 | hw/riscv: Initial support for Microchip PolarFire SoC Icicle Kit board | ||
27 | hw/char: Add Microchip PolarFire SoC MMUART emulation | ||
28 | hw/riscv: microchip_pfsoc: Connect 5 MMUARTs | ||
29 | hw/sd: Add Cadence SDHCI emulation | ||
30 | hw/riscv: microchip_pfsoc: Connect a Cadence SDHCI controller and an SD card | ||
31 | hw/dma: Add SiFive platform DMA controller emulation | ||
32 | hw/riscv: microchip_pfsoc: Connect a DMA controller | ||
33 | hw/net: cadence_gem: Add a new 'phy-addr' property | ||
34 | hw/arm: xlnx: Set all boards' GEM 'phy-addr' property value to 23 | ||
35 | hw/riscv: microchip_pfsoc: Connect 2 Cadence GEMs | ||
36 | hw/riscv: microchip_pfsoc: Hook GPIO controllers | ||
37 | hw/riscv: clint: Avoid using hard-coded timebase frequency | ||
38 | hw/riscv: sifive_u: Connect a DMA controller | ||
39 | hw/riscv: Move sifive_e_prci model to hw/misc | ||
40 | hw/riscv: Move sifive_u_prci model to hw/misc | ||
41 | hw/riscv: Move sifive_u_otp model to hw/misc | ||
42 | hw/riscv: Move sifive_gpio model to hw/gpio | ||
43 | hw/riscv: Move sifive_clint model to hw/intc | ||
44 | hw/riscv: Move sifive_plic model to hw/intc | ||
45 | hw/riscv: Move riscv_htif model to hw/char | ||
46 | hw/riscv: Move sifive_uart model to hw/char | ||
47 | hw/riscv: Move sifive_test model to hw/misc | ||
48 | hw/riscv: Always build riscv_hart.c | ||
49 | hw/riscv: Drop CONFIG_SIFIVE | ||
50 | hw/riscv: Sort the Kconfig options in alphabetical order | ||
51 | 32 | ||
52 | Nathan Chancellor (1): | 33 | Daniel Henrique Barboza (15): |
53 | riscv: sifive_test: Allow 16-bit writes to memory region | 34 | hw/riscv/riscv-iommu.c: add riscv_iommu_instance_init() |
35 | hw/riscv/riscv-iommu: parametrize CAP.IGS | ||
36 | hw/riscv/virt.c, riscv-iommu-sys.c: add MSIx support | ||
37 | hw/riscv/riscv-iommu: implement reset protocol | ||
38 | docs/specs: add riscv-iommu-sys information | ||
39 | hw/intc/riscv_aplic: rename is_kvm_aia() | ||
40 | hw/riscv/virt.c: reduce virt_use_kvm_aia() usage | ||
41 | hw/riscv/virt.c: rename helper to virt_use_kvm_aia_aplic_imsic() | ||
42 | target/riscv/kvm: consider irqchip_split() in aia_create() | ||
43 | hw/riscv/virt.c, riscv_aplic.c: add 'emulated_aplic' helpers | ||
44 | hw/intc/riscv_aplic: add kvm_msicfgaddr for split mode aplic-imsic | ||
45 | target/riscv/kvm: remove irqchip_split() restriction | ||
46 | docs: update riscv/virt.rst with kernel-irqchip=split support | ||
47 | target/riscv/tcg: hide warn for named feats when disabling via priv_ver | ||
48 | target/riscv: add ssstateen | ||
54 | 49 | ||
55 | Yifei Jiang (1): | 50 | Fea.Wang (6): |
56 | target/riscv: Fix bug in getting trap cause name for trace_riscv_trap | 51 | target/riscv: Add svukte extension capability variable |
52 | target/riscv: Support senvcfg[UKTE] bit when svukte extension is enabled | ||
53 | target/riscv: Support hstatus[HUKTE] bit when svukte extension is enabled | ||
54 | target/riscv: Check memory access to meet svukte rule | ||
55 | target/riscv: Expose svukte ISA extension | ||
56 | target/riscv: Check svukte is not enabled in RV32 | ||
57 | 57 | ||
58 | default-configs/riscv64-softmmu.mak | 1 + | 58 | Jason Chien (1): |
59 | {include/hw/riscv => hw/intc}/sifive_plic.h | 0 | 59 | hw/riscv/riscv-iommu.c: Correct the validness check of iova |
60 | hw/riscv/trace.h | 1 - | ||
61 | include/hw/char/mchp_pfsoc_mmuart.h | 61 ++++ | ||
62 | include/hw/{riscv => char}/riscv_htif.h | 0 | ||
63 | include/hw/{riscv => char}/sifive_uart.h | 0 | ||
64 | include/hw/dma/sifive_pdma.h | 57 ++++ | ||
65 | include/hw/{riscv => gpio}/sifive_gpio.h | 0 | ||
66 | include/hw/{riscv => intc}/sifive_clint.h | 4 +- | ||
67 | include/hw/{riscv => misc}/sifive_e_prci.h | 0 | ||
68 | include/hw/{riscv => misc}/sifive_test.h | 0 | ||
69 | include/hw/{riscv => misc}/sifive_u_otp.h | 0 | ||
70 | include/hw/{riscv => misc}/sifive_u_prci.h | 0 | ||
71 | include/hw/net/cadence_gem.h | 2 + | ||
72 | include/hw/riscv/microchip_pfsoc.h | 133 +++++++++ | ||
73 | include/hw/riscv/riscv_hart.h | 1 + | ||
74 | include/hw/riscv/sifive_e.h | 2 +- | ||
75 | include/hw/riscv/sifive_u.h | 17 +- | ||
76 | include/hw/sd/cadence_sdhci.h | 47 +++ | ||
77 | target/riscv/cpu.h | 8 +- | ||
78 | hw/arm/xilinx_zynq.c | 1 + | ||
79 | hw/arm/xlnx-versal.c | 1 + | ||
80 | hw/arm/xlnx-zynqmp.c | 2 + | ||
81 | hw/char/mchp_pfsoc_mmuart.c | 86 ++++++ | ||
82 | hw/{riscv => char}/riscv_htif.c | 2 +- | ||
83 | hw/{riscv => char}/sifive_uart.c | 2 +- | ||
84 | hw/dma/sifive_pdma.c | 313 ++++++++++++++++++++ | ||
85 | hw/{riscv => gpio}/sifive_gpio.c | 2 +- | ||
86 | hw/{riscv => intc}/sifive_clint.c | 28 +- | ||
87 | hw/{riscv => intc}/sifive_plic.c | 2 +- | ||
88 | hw/{riscv => misc}/sifive_e_prci.c | 2 +- | ||
89 | hw/{riscv => misc}/sifive_test.c | 4 +- | ||
90 | hw/{riscv => misc}/sifive_u_otp.c | 2 +- | ||
91 | hw/{riscv => misc}/sifive_u_prci.c | 2 +- | ||
92 | hw/net/cadence_gem.c | 7 +- | ||
93 | hw/riscv/microchip_pfsoc.c | 437 ++++++++++++++++++++++++++++ | ||
94 | hw/riscv/opentitan.c | 1 + | ||
95 | hw/riscv/riscv_hart.c | 3 + | ||
96 | hw/riscv/sifive_e.c | 12 +- | ||
97 | hw/riscv/sifive_u.c | 41 ++- | ||
98 | hw/riscv/spike.c | 7 +- | ||
99 | hw/riscv/virt.c | 9 +- | ||
100 | hw/sd/cadence_sdhci.c | 193 ++++++++++++ | ||
101 | target/riscv/cpu.c | 19 +- | ||
102 | target/riscv/cpu_helper.c | 8 +- | ||
103 | target/riscv/csr.c | 4 +- | ||
104 | MAINTAINERS | 9 + | ||
105 | hw/char/Kconfig | 9 + | ||
106 | hw/char/meson.build | 3 + | ||
107 | hw/dma/Kconfig | 3 + | ||
108 | hw/dma/meson.build | 1 + | ||
109 | hw/gpio/Kconfig | 3 + | ||
110 | hw/gpio/meson.build | 1 + | ||
111 | hw/gpio/trace-events | 6 + | ||
112 | hw/intc/Kconfig | 6 + | ||
113 | hw/intc/meson.build | 2 + | ||
114 | hw/misc/Kconfig | 12 + | ||
115 | hw/misc/meson.build | 6 + | ||
116 | hw/riscv/Kconfig | 70 +++-- | ||
117 | hw/riscv/meson.build | 12 +- | ||
118 | hw/riscv/trace-events | 7 - | ||
119 | hw/sd/Kconfig | 4 + | ||
120 | hw/sd/meson.build | 1 + | ||
121 | meson.build | 1 - | ||
122 | 64 files changed, 1575 insertions(+), 105 deletions(-) | ||
123 | rename {include/hw/riscv => hw/intc}/sifive_plic.h (100%) | ||
124 | delete mode 100644 hw/riscv/trace.h | ||
125 | create mode 100644 include/hw/char/mchp_pfsoc_mmuart.h | ||
126 | rename include/hw/{riscv => char}/riscv_htif.h (100%) | ||
127 | rename include/hw/{riscv => char}/sifive_uart.h (100%) | ||
128 | create mode 100644 include/hw/dma/sifive_pdma.h | ||
129 | rename include/hw/{riscv => gpio}/sifive_gpio.h (100%) | ||
130 | rename include/hw/{riscv => intc}/sifive_clint.h (92%) | ||
131 | rename include/hw/{riscv => misc}/sifive_e_prci.h (100%) | ||
132 | rename include/hw/{riscv => misc}/sifive_test.h (100%) | ||
133 | rename include/hw/{riscv => misc}/sifive_u_otp.h (100%) | ||
134 | rename include/hw/{riscv => misc}/sifive_u_prci.h (100%) | ||
135 | create mode 100644 include/hw/riscv/microchip_pfsoc.h | ||
136 | create mode 100644 include/hw/sd/cadence_sdhci.h | ||
137 | create mode 100644 hw/char/mchp_pfsoc_mmuart.c | ||
138 | rename hw/{riscv => char}/riscv_htif.c (99%) | ||
139 | rename hw/{riscv => char}/sifive_uart.c (99%) | ||
140 | create mode 100644 hw/dma/sifive_pdma.c | ||
141 | rename hw/{riscv => gpio}/sifive_gpio.c (99%) | ||
142 | rename hw/{riscv => intc}/sifive_clint.c (90%) | ||
143 | rename hw/{riscv => intc}/sifive_plic.c (99%) | ||
144 | rename hw/{riscv => misc}/sifive_e_prci.c (99%) | ||
145 | rename hw/{riscv => misc}/sifive_test.c (97%) | ||
146 | rename hw/{riscv => misc}/sifive_u_otp.c (99%) | ||
147 | rename hw/{riscv => misc}/sifive_u_prci.c (99%) | ||
148 | create mode 100644 hw/riscv/microchip_pfsoc.c | ||
149 | create mode 100644 hw/sd/cadence_sdhci.c | ||
150 | delete mode 100644 hw/riscv/trace-events | ||
151 | 60 | ||
61 | Jim Shu (3): | ||
62 | hw/riscv: Support to load DTB after 3GB memory on 64-bit system. | ||
63 | hw/riscv: Add a new struct RISCVBootInfo | ||
64 | hw/riscv: Add the checking if DTB overlaps to kernel or initrd | ||
65 | |||
66 | MollyChen (1): | ||
67 | target/riscv: add support for RV64 Xiangshan Nanhu CPU | ||
68 | |||
69 | Philippe Mathieu-Daudé (5): | ||
70 | MAINTAINERS: Cover RISC-V HTIF interface | ||
71 | hw/char/riscv_htif: Explicit little-endian implementation | ||
72 | hw/char/riscv_htif: Clarify MemoryRegionOps expect 32-bit accesses | ||
73 | target/riscv: Include missing headers in 'vector_internals.h' | ||
74 | target/riscv: Include missing headers in 'internals.h' | ||
75 | |||
76 | Sai Pavan Boddu (1): | ||
77 | hw/riscv: Add Microblaze V generic board | ||
78 | |||
79 | Sia Jee Heng (3): | ||
80 | qtest: allow SPCR acpi table changes | ||
81 | hw/acpi: Upgrade ACPI SPCR table to support SPCR table revision 4 format | ||
82 | tests/qtest/bios-tables-test: Update virt SPCR golden reference for RISC-V | ||
83 | |||
84 | Sunil V L (1): | ||
85 | hw/riscv/virt: Add IOMMU as platform device if the option is set | ||
86 | |||
87 | Tomasz Jeznach (1): | ||
88 | hw/riscv: add riscv-iommu-sys platform device | ||
89 | |||
90 | Yong-Xuan Wang (1): | ||
91 | hw/intc/riscv_aplic: Fix APLIC in_clrip and clripnum write emulation | ||
92 | |||
93 | MAINTAINERS | 8 + | ||
94 | docs/specs/index.rst | 1 + | ||
95 | docs/specs/riscv-aia.rst | 83 ++++++++++ | ||
96 | docs/specs/riscv-iommu.rst | 30 +++- | ||
97 | docs/system/riscv/microblaze-v-generic.rst | 42 +++++ | ||
98 | docs/system/riscv/virt.rst | 17 ++ | ||
99 | docs/system/target-riscv.rst | 1 + | ||
100 | hw/riscv/riscv-iommu-bits.h | 6 + | ||
101 | hw/riscv/riscv-iommu.h | 5 + | ||
102 | include/hw/acpi/acpi-defs.h | 7 +- | ||
103 | include/hw/acpi/aml-build.h | 2 +- | ||
104 | include/hw/intc/riscv_aplic.h | 8 + | ||
105 | include/hw/riscv/boot.h | 28 +++- | ||
106 | include/hw/riscv/iommu.h | 10 +- | ||
107 | include/hw/riscv/virt.h | 6 +- | ||
108 | target/riscv/cpu-qom.h | 2 + | ||
109 | target/riscv/cpu_bits.h | 2 + | ||
110 | target/riscv/cpu_cfg.h | 2 + | ||
111 | target/riscv/internals.h | 3 + | ||
112 | target/riscv/vector_internals.h | 1 + | ||
113 | hw/acpi/aml-build.c | 20 ++- | ||
114 | hw/arm/virt-acpi-build.c | 8 +- | ||
115 | hw/char/riscv_htif.c | 15 +- | ||
116 | hw/intc/riscv_aplic.c | 74 +++++++-- | ||
117 | hw/loongarch/acpi-build.c | 6 +- | ||
118 | hw/riscv/boot.c | 100 +++++++---- | ||
119 | hw/riscv/microblaze-v-generic.c | 184 +++++++++++++++++++++ | ||
120 | hw/riscv/microchip_pfsoc.c | 13 +- | ||
121 | hw/riscv/opentitan.c | 4 +- | ||
122 | hw/riscv/riscv-iommu-pci.c | 21 +++ | ||
123 | hw/riscv/riscv-iommu-sys.c | 256 +++++++++++++++++++++++++++++ | ||
124 | hw/riscv/riscv-iommu.c | 137 ++++++++++----- | ||
125 | hw/riscv/sifive_e.c | 4 +- | ||
126 | hw/riscv/sifive_u.c | 18 +- | ||
127 | hw/riscv/spike.c | 14 +- | ||
128 | hw/riscv/virt-acpi-build.c | 12 +- | ||
129 | hw/riscv/virt.c | 159 +++++++++++++++--- | ||
130 | target/riscv/cpu.c | 101 ++++++++++++ | ||
131 | target/riscv/cpu_helper.c | 55 +++++++ | ||
132 | target/riscv/csr.c | 7 + | ||
133 | target/riscv/kvm/kvm-cpu.c | 43 ++--- | ||
134 | target/riscv/tcg/tcg-cpu.c | 27 ++- | ||
135 | hw/riscv/Kconfig | 8 + | ||
136 | hw/riscv/meson.build | 3 +- | ||
137 | hw/riscv/trace-events | 4 + | ||
138 | tests/data/acpi/riscv64/virt/SPCR | Bin 80 -> 90 bytes | ||
139 | 46 files changed, 1380 insertions(+), 177 deletions(-) | ||
140 | create mode 100644 docs/specs/riscv-aia.rst | ||
141 | create mode 100644 docs/system/riscv/microblaze-v-generic.rst | ||
142 | create mode 100644 hw/riscv/microblaze-v-generic.c | ||
143 | create mode 100644 hw/riscv/riscv-iommu-sys.c | ||
144 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Jason Chien <jason.chien@sifive.com> | ||
1 | 2 | ||
3 | From RISCV IOMMU spec section 2.1.3: | ||
4 | When SXL is 1, the following rules apply: | ||
5 | - If the first-stage is not Bare, then a page fault corresponding to the | ||
6 | original access type occurs if the IOVA has bits beyond bit 31 set to 1. | ||
7 | - If the second-stage is not Bare, then a guest page fault corresponding | ||
8 | to the original access type occurs if the incoming GPA has bits beyond bit | ||
9 | 33 set to 1. | ||
10 | |||
11 | From RISCV IOMMU spec section 2.3 step 17: | ||
12 | Use the process specified in Section "Two-Stage Address Translation" of | ||
13 | the RISC-V Privileged specification to determine the GPA accessed by the | ||
14 | transaction. | ||
15 | |||
16 | From RISCV IOMMU spec section 2.3 step 19: | ||
17 | Use the second-stage address translation process specified in Section | ||
18 | "Two-Stage Address Translation" of the RISC-V Privileged specification | ||
19 | to translate the GPA A to determine the SPA accessed by the transaction. | ||
20 | |||
21 | This commit adds the iova check with the following rules: | ||
22 | - For Sv32, Sv32x4, Sv39x4, Sv48x4 and Sv57x4, the iova must be zero | ||
23 | extended. | ||
24 | - For Sv39, Sv48 and Sv57, the iova must be signed extended with most | ||
25 | significant bit. | ||
26 | |||
27 | Signed-off-by: Jason Chien <jason.chien@sifive.com> | ||
28 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
29 | Message-ID: <20241114065617.25133-1-jason.chien@sifive.com> | ||
30 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
31 | --- | ||
32 | hw/riscv/riscv-iommu.c | 23 ++++++++++++++++++++--- | ||
33 | 1 file changed, 20 insertions(+), 3 deletions(-) | ||
34 | |||
35 | diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c | ||
36 | index XXXXXXX..XXXXXXX 100644 | ||
37 | --- a/hw/riscv/riscv-iommu.c | ||
38 | +++ b/hw/riscv/riscv-iommu.c | ||
39 | @@ -XXX,XX +XXX,XX @@ static int riscv_iommu_spa_fetch(RISCVIOMMUState *s, RISCVIOMMUContext *ctx, | ||
40 | |||
41 | /* Address range check before first level lookup */ | ||
42 | if (!sc[pass].step) { | ||
43 | - const uint64_t va_mask = (1ULL << (va_skip + va_bits)) - 1; | ||
44 | - if ((addr & va_mask) != addr) { | ||
45 | - return RISCV_IOMMU_FQ_CAUSE_DMA_DISABLED; | ||
46 | + const uint64_t va_len = va_skip + va_bits; | ||
47 | + const uint64_t va_mask = (1ULL << va_len) - 1; | ||
48 | + | ||
49 | + if (pass == S_STAGE && va_len > 32) { | ||
50 | + target_ulong mask, masked_msbs; | ||
51 | + | ||
52 | + mask = (1L << (TARGET_LONG_BITS - (va_len - 1))) - 1; | ||
53 | + masked_msbs = (addr >> (va_len - 1)) & mask; | ||
54 | + | ||
55 | + if (masked_msbs != 0 && masked_msbs != mask) { | ||
56 | + return (iotlb->perm & IOMMU_WO) ? | ||
57 | + RISCV_IOMMU_FQ_CAUSE_WR_FAULT_S : | ||
58 | + RISCV_IOMMU_FQ_CAUSE_RD_FAULT_S; | ||
59 | + } | ||
60 | + } else { | ||
61 | + if ((addr & va_mask) != addr) { | ||
62 | + return (iotlb->perm & IOMMU_WO) ? | ||
63 | + RISCV_IOMMU_FQ_CAUSE_WR_FAULT_VS : | ||
64 | + RISCV_IOMMU_FQ_CAUSE_RD_FAULT_VS; | ||
65 | + } | ||
66 | } | ||
67 | } | ||
68 | |||
69 | -- | ||
70 | 2.47.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Yong-Xuan Wang <yongxuan.wang@sifive.com> | ||
1 | 2 | ||
3 | In the section "4.7 Precise effects on interrupt-pending bits" | ||
4 | of the RISC-V AIA specification defines that: | ||
5 | |||
6 | "If the source mode is Level1 or Level0 and the interrupt domain | ||
7 | is configured in MSI delivery mode (domaincfg.DM = 1): | ||
8 | The pending bit is cleared whenever the rectified input value is | ||
9 | low, when the interrupt is forwarded by MSI, or by a relevant | ||
10 | write to an in_clrip register or to clripnum." | ||
11 | |||
12 | Update the riscv_aplic_set_pending() to match the spec. | ||
13 | |||
14 | Fixes: bf31cf06eb ("hw/intc/riscv_aplic: Fix setipnum_le write emulation for APLIC MSI-mode") | ||
15 | Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com> | ||
16 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
17 | Message-ID: <20241029085349.30412-1-yongxuan.wang@sifive.com> | ||
18 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
19 | --- | ||
20 | hw/intc/riscv_aplic.c | 6 +++++- | ||
21 | 1 file changed, 5 insertions(+), 1 deletion(-) | ||
22 | |||
23 | diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/hw/intc/riscv_aplic.c | ||
26 | +++ b/hw/intc/riscv_aplic.c | ||
27 | @@ -XXX,XX +XXX,XX @@ static void riscv_aplic_set_pending(RISCVAPLICState *aplic, | ||
28 | |||
29 | if ((sm == APLIC_SOURCECFG_SM_LEVEL_HIGH) || | ||
30 | (sm == APLIC_SOURCECFG_SM_LEVEL_LOW)) { | ||
31 | - if (!aplic->msimode || (aplic->msimode && !pending)) { | ||
32 | + if (!aplic->msimode) { | ||
33 | return; | ||
34 | } | ||
35 | + if (aplic->msimode && !pending) { | ||
36 | + goto noskip_write_pending; | ||
37 | + } | ||
38 | if ((aplic->state[irq] & APLIC_ISTATE_INPUT) && | ||
39 | (sm == APLIC_SOURCECFG_SM_LEVEL_LOW)) { | ||
40 | return; | ||
41 | @@ -XXX,XX +XXX,XX @@ static void riscv_aplic_set_pending(RISCVAPLICState *aplic, | ||
42 | } | ||
43 | } | ||
44 | |||
45 | +noskip_write_pending: | ||
46 | riscv_aplic_set_pending_raw(aplic, irq, pending); | ||
47 | } | ||
48 | |||
49 | -- | ||
50 | 2.47.1 | diff view generated by jsdifflib |
1 | From: Nathan Chancellor <natechancellor@gmail.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | When shutting down the machine running a mainline Linux kernel, the | 3 | Move all the static initializion of the device to an init() function, |
4 | following error happens: | 4 | leaving only the dynamic initialization to be done during realize. |
5 | 5 | ||
6 | $ build/riscv64-softmmu/qemu-system-riscv64 -bios default -M virt \ | 6 | With this change s->cap is initialized with RISCV_IOMMU_CAP_DBG during |
7 | -display none -initrd rootfs.cpio -kernel Image -m 512m \ | 7 | init(), and realize() will increment s->cap with the extra caps. |
8 | -nodefaults -serial mon:stdio | ||
9 | ... | ||
10 | Requesting system poweroff | ||
11 | [ 4.999630] reboot: Power down | ||
12 | sbi_trap_error: hart0: trap handler failed (error -2) | ||
13 | sbi_trap_error: hart0: mcause=0x0000000000000007 mtval=0x0000000000100000 | ||
14 | sbi_trap_error: hart0: mepc=0x000000008000d4cc mstatus=0x0000000000001822 | ||
15 | sbi_trap_error: hart0: ra=0x000000008000999e sp=0x0000000080015c78 | ||
16 | sbi_trap_error: hart0: gp=0xffffffe000e76610 tp=0xffffffe0081b89c0 | ||
17 | sbi_trap_error: hart0: s0=0x0000000080015c88 s1=0x0000000000000040 | ||
18 | sbi_trap_error: hart0: a0=0x0000000000000000 a1=0x0000000080004024 | ||
19 | sbi_trap_error: hart0: a2=0x0000000080004024 a3=0x0000000080004024 | ||
20 | sbi_trap_error: hart0: a4=0x0000000000100000 a5=0x0000000000005555 | ||
21 | sbi_trap_error: hart0: a6=0x0000000000004024 a7=0x0000000080011158 | ||
22 | sbi_trap_error: hart0: s2=0x0000000000000000 s3=0x0000000080016000 | ||
23 | sbi_trap_error: hart0: s4=0x0000000000000000 s5=0x0000000000000000 | ||
24 | sbi_trap_error: hart0: s6=0x0000000000000001 s7=0x0000000000000000 | ||
25 | sbi_trap_error: hart0: s8=0x0000000000000000 s9=0x0000000000000000 | ||
26 | sbi_trap_error: hart0: s10=0x0000000000000000 s11=0x0000000000000008 | ||
27 | sbi_trap_error: hart0: t0=0x0000000000000000 t1=0x0000000000000000 | ||
28 | sbi_trap_error: hart0: t2=0x0000000000000000 t3=0x0000000000000000 | ||
29 | sbi_trap_error: hart0: t4=0x0000000000000000 t5=0x0000000000000000 | ||
30 | sbi_trap_error: hart0: t6=0x0000000000000000 | ||
31 | 8 | ||
32 | The kernel does a 16-bit write when powering off the machine, which | 9 | This will allow callers to add IOMMU capabilities before the |
33 | was allowed before commit 5d971f9e67 ("memory: Revert "memory: accept | 10 | realization. |
34 | mismatching sizes in memory_region_access_valid""). Make min_access_size | ||
35 | match reality so that the machine can shut down properly now. | ||
36 | 11 | ||
37 | Cc: qemu-stable@nongnu.org | 12 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
38 | Fixes: 88a07990fa ("SiFive RISC-V Test Finisher") | ||
39 | Fixes: 5d971f9e67 ("memory: Revert "memory: accept mismatching sizes in memory_region_access_valid"") | ||
40 | Signed-off-by: Nathan Chancellor <natechancellor@gmail.com> | ||
41 | Acked-by: Michael S. Tsirkin <mst@redhat.com> | ||
42 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
43 | Message-Id: <20200901055822.2721209-1-natechancellor@gmail.com> | 14 | Message-ID: <20241106133407.604587-2-dbarboza@ventanamicro.com> |
44 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
45 | --- | 16 | --- |
46 | hw/riscv/sifive_test.c | 2 +- | 17 | hw/riscv/riscv-iommu.c | 71 +++++++++++++++++++++++------------------- |
47 | 1 file changed, 1 insertion(+), 1 deletion(-) | 18 | 1 file changed, 39 insertions(+), 32 deletions(-) |
48 | 19 | ||
49 | diff --git a/hw/riscv/sifive_test.c b/hw/riscv/sifive_test.c | 20 | diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c |
50 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
51 | --- a/hw/riscv/sifive_test.c | 22 | --- a/hw/riscv/riscv-iommu.c |
52 | +++ b/hw/riscv/sifive_test.c | 23 | +++ b/hw/riscv/riscv-iommu.c |
53 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps sifive_test_ops = { | 24 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps riscv_iommu_trap_ops = { |
54 | .write = sifive_test_write, | ||
55 | .endianness = DEVICE_NATIVE_ENDIAN, | ||
56 | .valid = { | ||
57 | - .min_access_size = 4, | ||
58 | + .min_access_size = 2, | ||
59 | .max_access_size = 4 | ||
60 | } | 25 | } |
61 | }; | 26 | }; |
27 | |||
28 | +static void riscv_iommu_instance_init(Object *obj) | ||
29 | +{ | ||
30 | + RISCVIOMMUState *s = RISCV_IOMMU(obj); | ||
31 | + | ||
32 | + /* Enable translation debug interface */ | ||
33 | + s->cap = RISCV_IOMMU_CAP_DBG; | ||
34 | + | ||
35 | + /* Report QEMU target physical address space limits */ | ||
36 | + s->cap = set_field(s->cap, RISCV_IOMMU_CAP_PAS, | ||
37 | + TARGET_PHYS_ADDR_SPACE_BITS); | ||
38 | + | ||
39 | + /* TODO: method to report supported PID bits */ | ||
40 | + s->pid_bits = 8; /* restricted to size of MemTxAttrs.pid */ | ||
41 | + s->cap |= RISCV_IOMMU_CAP_PD8; | ||
42 | + | ||
43 | + /* register storage */ | ||
44 | + s->regs_rw = g_new0(uint8_t, RISCV_IOMMU_REG_SIZE); | ||
45 | + s->regs_ro = g_new0(uint8_t, RISCV_IOMMU_REG_SIZE); | ||
46 | + s->regs_wc = g_new0(uint8_t, RISCV_IOMMU_REG_SIZE); | ||
47 | + | ||
48 | + /* Mark all registers read-only */ | ||
49 | + memset(s->regs_ro, 0xff, RISCV_IOMMU_REG_SIZE); | ||
50 | + | ||
51 | + /* Device translation context cache */ | ||
52 | + s->ctx_cache = g_hash_table_new_full(riscv_iommu_ctx_hash, | ||
53 | + riscv_iommu_ctx_equal, | ||
54 | + g_free, NULL); | ||
55 | + | ||
56 | + s->iot_cache = g_hash_table_new_full(riscv_iommu_iot_hash, | ||
57 | + riscv_iommu_iot_equal, | ||
58 | + g_free, NULL); | ||
59 | + | ||
60 | + s->iommus.le_next = NULL; | ||
61 | + s->iommus.le_prev = NULL; | ||
62 | + QLIST_INIT(&s->spaces); | ||
63 | +} | ||
64 | + | ||
65 | static void riscv_iommu_realize(DeviceState *dev, Error **errp) | ||
66 | { | ||
67 | RISCVIOMMUState *s = RISCV_IOMMU(dev); | ||
68 | |||
69 | - s->cap = s->version & RISCV_IOMMU_CAP_VERSION; | ||
70 | + s->cap |= s->version & RISCV_IOMMU_CAP_VERSION; | ||
71 | if (s->enable_msi) { | ||
72 | s->cap |= RISCV_IOMMU_CAP_MSI_FLAT | RISCV_IOMMU_CAP_MSI_MRIF; | ||
73 | } | ||
74 | @@ -XXX,XX +XXX,XX @@ static void riscv_iommu_realize(DeviceState *dev, Error **errp) | ||
75 | s->cap |= RISCV_IOMMU_CAP_SV32X4 | RISCV_IOMMU_CAP_SV39X4 | | ||
76 | RISCV_IOMMU_CAP_SV48X4 | RISCV_IOMMU_CAP_SV57X4; | ||
77 | } | ||
78 | - /* Enable translation debug interface */ | ||
79 | - s->cap |= RISCV_IOMMU_CAP_DBG; | ||
80 | - | ||
81 | - /* Report QEMU target physical address space limits */ | ||
82 | - s->cap = set_field(s->cap, RISCV_IOMMU_CAP_PAS, | ||
83 | - TARGET_PHYS_ADDR_SPACE_BITS); | ||
84 | - | ||
85 | - /* TODO: method to report supported PID bits */ | ||
86 | - s->pid_bits = 8; /* restricted to size of MemTxAttrs.pid */ | ||
87 | - s->cap |= RISCV_IOMMU_CAP_PD8; | ||
88 | |||
89 | /* Out-of-reset translation mode: OFF (DMA disabled) BARE (passthrough) */ | ||
90 | s->ddtp = set_field(0, RISCV_IOMMU_DDTP_MODE, s->enable_off ? | ||
91 | RISCV_IOMMU_DDTP_MODE_OFF : RISCV_IOMMU_DDTP_MODE_BARE); | ||
92 | |||
93 | - /* register storage */ | ||
94 | - s->regs_rw = g_new0(uint8_t, RISCV_IOMMU_REG_SIZE); | ||
95 | - s->regs_ro = g_new0(uint8_t, RISCV_IOMMU_REG_SIZE); | ||
96 | - s->regs_wc = g_new0(uint8_t, RISCV_IOMMU_REG_SIZE); | ||
97 | - | ||
98 | - /* Mark all registers read-only */ | ||
99 | - memset(s->regs_ro, 0xff, RISCV_IOMMU_REG_SIZE); | ||
100 | - | ||
101 | /* | ||
102 | * Register complete MMIO space, including MSI/PBA registers. | ||
103 | * Note, PCIDevice implementation will add overlapping MR for MSI/PBA, | ||
104 | @@ -XXX,XX +XXX,XX @@ static void riscv_iommu_realize(DeviceState *dev, Error **errp) | ||
105 | memory_region_init_io(&s->trap_mr, OBJECT(dev), &riscv_iommu_trap_ops, s, | ||
106 | "riscv-iommu-trap", ~0ULL); | ||
107 | address_space_init(&s->trap_as, &s->trap_mr, "riscv-iommu-trap-as"); | ||
108 | - | ||
109 | - /* Device translation context cache */ | ||
110 | - s->ctx_cache = g_hash_table_new_full(riscv_iommu_ctx_hash, | ||
111 | - riscv_iommu_ctx_equal, | ||
112 | - g_free, NULL); | ||
113 | - | ||
114 | - s->iot_cache = g_hash_table_new_full(riscv_iommu_iot_hash, | ||
115 | - riscv_iommu_iot_equal, | ||
116 | - g_free, NULL); | ||
117 | - | ||
118 | - s->iommus.le_next = NULL; | ||
119 | - s->iommus.le_prev = NULL; | ||
120 | - QLIST_INIT(&s->spaces); | ||
121 | } | ||
122 | |||
123 | static void riscv_iommu_unrealize(DeviceState *dev) | ||
124 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo riscv_iommu_info = { | ||
125 | .name = TYPE_RISCV_IOMMU, | ||
126 | .parent = TYPE_DEVICE, | ||
127 | .instance_size = sizeof(RISCVIOMMUState), | ||
128 | + .instance_init = riscv_iommu_instance_init, | ||
129 | .class_init = riscv_iommu_class_init, | ||
130 | }; | ||
131 | |||
62 | -- | 132 | -- |
63 | 2.28.0 | 133 | 2.47.1 |
64 | |||
65 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | This is an effort to clean up the hw/riscv directory. Ideally it | 3 | Interrupt Generation Support (IGS) is a capability that is tied to the |
4 | should only contain the RISC-V SoC / machine codes plus generic | 4 | interrupt deliver mechanism, not with the core IOMMU emulation. We |
5 | codes. Let's move sifive_gpio model to hw/gpio directory. | 5 | should allow device implementations to set IGS as they wish. |
6 | 6 | ||
7 | Note this also removes the trace-events in the hw/riscv directory, | 7 | A new helper is added to make it easier for device impls to set IGS. Use |
8 | since gpio is the only supported trace target in that directory. | 8 | it in our existing IOMMU device (riscv-iommu-pci) to set |
9 | RISCV_IOMMU_CAPS_IGS_MSI. | ||
9 | 10 | ||
10 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 11 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
11 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
12 | Message-Id: <1599129623-68957-5-git-send-email-bmeng.cn@gmail.com> | 13 | Message-ID: <20241106133407.604587-3-dbarboza@ventanamicro.com> |
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
14 | --- | 15 | --- |
15 | hw/riscv/trace.h | 1 - | 16 | hw/riscv/riscv-iommu-bits.h | 6 ++++++ |
16 | include/hw/{riscv => gpio}/sifive_gpio.h | 0 | 17 | hw/riscv/riscv-iommu.h | 4 ++++ |
17 | include/hw/riscv/sifive_e.h | 2 +- | 18 | hw/riscv/riscv-iommu-pci.c | 1 + |
18 | include/hw/riscv/sifive_u.h | 2 +- | 19 | hw/riscv/riscv-iommu.c | 5 +++++ |
19 | hw/{riscv => gpio}/sifive_gpio.c | 2 +- | 20 | 4 files changed, 16 insertions(+) |
20 | hw/gpio/Kconfig | 3 +++ | ||
21 | hw/gpio/meson.build | 1 + | ||
22 | hw/gpio/trace-events | 6 ++++++ | ||
23 | hw/riscv/Kconfig | 2 ++ | ||
24 | hw/riscv/meson.build | 1 - | ||
25 | hw/riscv/trace-events | 7 ------- | ||
26 | meson.build | 1 - | ||
27 | 12 files changed, 15 insertions(+), 13 deletions(-) | ||
28 | delete mode 100644 hw/riscv/trace.h | ||
29 | rename include/hw/{riscv => gpio}/sifive_gpio.h (100%) | ||
30 | rename hw/{riscv => gpio}/sifive_gpio.c (99%) | ||
31 | delete mode 100644 hw/riscv/trace-events | ||
32 | 21 | ||
33 | diff --git a/hw/riscv/trace.h b/hw/riscv/trace.h | 22 | diff --git a/hw/riscv/riscv-iommu-bits.h b/hw/riscv/riscv-iommu-bits.h |
34 | deleted file mode 100644 | ||
35 | index XXXXXXX..XXXXXXX | ||
36 | --- a/hw/riscv/trace.h | ||
37 | +++ /dev/null | ||
38 | @@ -1 +0,0 @@ | ||
39 | -#include "trace/trace-hw_riscv.h" | ||
40 | diff --git a/include/hw/riscv/sifive_gpio.h b/include/hw/gpio/sifive_gpio.h | ||
41 | similarity index 100% | ||
42 | rename from include/hw/riscv/sifive_gpio.h | ||
43 | rename to include/hw/gpio/sifive_gpio.h | ||
44 | diff --git a/include/hw/riscv/sifive_e.h b/include/hw/riscv/sifive_e.h | ||
45 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
46 | --- a/include/hw/riscv/sifive_e.h | 24 | --- a/hw/riscv/riscv-iommu-bits.h |
47 | +++ b/include/hw/riscv/sifive_e.h | 25 | +++ b/hw/riscv/riscv-iommu-bits.h |
26 | @@ -XXX,XX +XXX,XX @@ struct riscv_iommu_pq_record { | ||
27 | #define RISCV_IOMMU_CAP_PD17 BIT_ULL(39) | ||
28 | #define RISCV_IOMMU_CAP_PD20 BIT_ULL(40) | ||
29 | |||
30 | +enum riscv_iommu_igs_modes { | ||
31 | + RISCV_IOMMU_CAP_IGS_MSI = 0, | ||
32 | + RISCV_IOMMU_CAP_IGS_WSI, | ||
33 | + RISCV_IOMMU_CAP_IGS_BOTH | ||
34 | +}; | ||
35 | + | ||
36 | /* 5.4 Features control register (32bits) */ | ||
37 | #define RISCV_IOMMU_REG_FCTL 0x0008 | ||
38 | #define RISCV_IOMMU_FCTL_BE BIT(0) | ||
39 | diff --git a/hw/riscv/riscv-iommu.h b/hw/riscv/riscv-iommu.h | ||
40 | index XXXXXXX..XXXXXXX 100644 | ||
41 | --- a/hw/riscv/riscv-iommu.h | ||
42 | +++ b/hw/riscv/riscv-iommu.h | ||
48 | @@ -XXX,XX +XXX,XX @@ | 43 | @@ -XXX,XX +XXX,XX @@ |
49 | 44 | ||
50 | #include "hw/riscv/riscv_hart.h" | 45 | #include "qom/object.h" |
51 | #include "hw/riscv/sifive_cpu.h" | 46 | #include "hw/riscv/iommu.h" |
52 | -#include "hw/riscv/sifive_gpio.h" | 47 | +#include "hw/riscv/riscv-iommu-bits.h" |
53 | +#include "hw/gpio/sifive_gpio.h" | 48 | + |
54 | 49 | +typedef enum riscv_iommu_igs_modes riscv_iommu_igs_mode; | |
55 | #define TYPE_RISCV_E_SOC "riscv.sifive.e.soc" | 50 | |
56 | #define RISCV_E_SOC(obj) \ | 51 | struct RISCVIOMMUState { |
57 | diff --git a/include/hw/riscv/sifive_u.h b/include/hw/riscv/sifive_u.h | 52 | /*< private >*/ |
53 | @@ -XXX,XX +XXX,XX @@ struct RISCVIOMMUState { | ||
54 | |||
55 | void riscv_iommu_pci_setup_iommu(RISCVIOMMUState *iommu, PCIBus *bus, | ||
56 | Error **errp); | ||
57 | +void riscv_iommu_set_cap_igs(RISCVIOMMUState *s, riscv_iommu_igs_mode mode); | ||
58 | |||
59 | /* private helpers */ | ||
60 | |||
61 | diff --git a/hw/riscv/riscv-iommu-pci.c b/hw/riscv/riscv-iommu-pci.c | ||
58 | index XXXXXXX..XXXXXXX 100644 | 62 | index XXXXXXX..XXXXXXX 100644 |
59 | --- a/include/hw/riscv/sifive_u.h | 63 | --- a/hw/riscv/riscv-iommu-pci.c |
60 | +++ b/include/hw/riscv/sifive_u.h | 64 | +++ b/hw/riscv/riscv-iommu-pci.c |
61 | @@ -XXX,XX +XXX,XX @@ | 65 | @@ -XXX,XX +XXX,XX @@ static void riscv_iommu_pci_init(Object *obj) |
62 | #include "hw/net/cadence_gem.h" | 66 | qdev_alias_all_properties(DEVICE(iommu), obj); |
63 | #include "hw/riscv/riscv_hart.h" | 67 | |
64 | #include "hw/riscv/sifive_cpu.h" | 68 | iommu->icvec_avail_vectors = RISCV_IOMMU_PCI_ICVEC_VECTORS; |
65 | -#include "hw/riscv/sifive_gpio.h" | 69 | + riscv_iommu_set_cap_igs(iommu, RISCV_IOMMU_CAP_IGS_MSI); |
66 | +#include "hw/gpio/sifive_gpio.h" | 70 | } |
67 | #include "hw/misc/sifive_u_otp.h" | 71 | |
68 | #include "hw/misc/sifive_u_prci.h" | 72 | static const Property riscv_iommu_pci_properties[] = { |
69 | 73 | diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c | |
70 | diff --git a/hw/riscv/sifive_gpio.c b/hw/gpio/sifive_gpio.c | ||
71 | similarity index 99% | ||
72 | rename from hw/riscv/sifive_gpio.c | ||
73 | rename to hw/gpio/sifive_gpio.c | ||
74 | index XXXXXXX..XXXXXXX 100644 | 74 | index XXXXXXX..XXXXXXX 100644 |
75 | --- a/hw/riscv/sifive_gpio.c | 75 | --- a/hw/riscv/riscv-iommu.c |
76 | +++ b/hw/gpio/sifive_gpio.c | 76 | +++ b/hw/riscv/riscv-iommu.c |
77 | @@ -XXX,XX +XXX,XX @@ | 77 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps riscv_iommu_trap_ops = { |
78 | #include "qemu/log.h" | 78 | } |
79 | #include "hw/irq.h" | 79 | }; |
80 | #include "hw/qdev-properties.h" | 80 | |
81 | -#include "hw/riscv/sifive_gpio.h" | 81 | +void riscv_iommu_set_cap_igs(RISCVIOMMUState *s, riscv_iommu_igs_mode mode) |
82 | +#include "hw/gpio/sifive_gpio.h" | 82 | +{ |
83 | #include "migration/vmstate.h" | 83 | + s->cap = set_field(s->cap, RISCV_IOMMU_CAP_IGS, mode); |
84 | #include "trace.h" | 84 | +} |
85 | |||
86 | diff --git a/hw/gpio/Kconfig b/hw/gpio/Kconfig | ||
87 | index XXXXXXX..XXXXXXX 100644 | ||
88 | --- a/hw/gpio/Kconfig | ||
89 | +++ b/hw/gpio/Kconfig | ||
90 | @@ -XXX,XX +XXX,XX @@ config PL061 | ||
91 | |||
92 | config GPIO_KEY | ||
93 | bool | ||
94 | + | 85 | + |
95 | +config SIFIVE_GPIO | 86 | static void riscv_iommu_instance_init(Object *obj) |
96 | + bool | 87 | { |
97 | diff --git a/hw/gpio/meson.build b/hw/gpio/meson.build | 88 | RISCVIOMMUState *s = RISCV_IOMMU(obj); |
98 | index XXXXXXX..XXXXXXX 100644 | ||
99 | --- a/hw/gpio/meson.build | ||
100 | +++ b/hw/gpio/meson.build | ||
101 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_gpio.c')) | ||
102 | softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_gpio.c')) | ||
103 | softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_gpio.c')) | ||
104 | softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_gpio.c')) | ||
105 | +softmmu_ss.add(when: 'CONFIG_SIFIVE_GPIO', if_true: files('sifive_gpio.c')) | ||
106 | diff --git a/hw/gpio/trace-events b/hw/gpio/trace-events | ||
107 | index XXXXXXX..XXXXXXX 100644 | ||
108 | --- a/hw/gpio/trace-events | ||
109 | +++ b/hw/gpio/trace-events | ||
110 | @@ -XXX,XX +XXX,XX @@ nrf51_gpio_read(uint64_t offset, uint64_t r) "offset 0x%" PRIx64 " value 0x%" PR | ||
111 | nrf51_gpio_write(uint64_t offset, uint64_t value) "offset 0x%" PRIx64 " value 0x%" PRIx64 | ||
112 | nrf51_gpio_set(int64_t line, int64_t value) "line %" PRIi64 " value %" PRIi64 | ||
113 | nrf51_gpio_update_output_irq(int64_t line, int64_t value) "line %" PRIi64 " value %" PRIi64 | ||
114 | + | ||
115 | +# sifive_gpio.c | ||
116 | +sifive_gpio_read(uint64_t offset, uint64_t r) "offset 0x%" PRIx64 " value 0x%" PRIx64 | ||
117 | +sifive_gpio_write(uint64_t offset, uint64_t value) "offset 0x%" PRIx64 " value 0x%" PRIx64 | ||
118 | +sifive_gpio_set(int64_t line, int64_t value) "line %" PRIi64 " value %" PRIi64 | ||
119 | +sifive_gpio_update_output_irq(int64_t line, int64_t value) "line %" PRIi64 " value %" PRIi64 | ||
120 | diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig | ||
121 | index XXXXXXX..XXXXXXX 100644 | ||
122 | --- a/hw/riscv/Kconfig | ||
123 | +++ b/hw/riscv/Kconfig | ||
124 | @@ -XXX,XX +XXX,XX @@ config SIFIVE_E | ||
125 | bool | ||
126 | select HART | ||
127 | select SIFIVE | ||
128 | + select SIFIVE_GPIO | ||
129 | select SIFIVE_E_PRCI | ||
130 | select UNIMP | ||
131 | |||
132 | @@ -XXX,XX +XXX,XX @@ config SIFIVE_U | ||
133 | select CADENCE | ||
134 | select HART | ||
135 | select SIFIVE | ||
136 | + select SIFIVE_GPIO | ||
137 | select SIFIVE_PDMA | ||
138 | select SIFIVE_U_OTP | ||
139 | select SIFIVE_U_PRCI | ||
140 | diff --git a/hw/riscv/meson.build b/hw/riscv/meson.build | ||
141 | index XXXXXXX..XXXXXXX 100644 | ||
142 | --- a/hw/riscv/meson.build | ||
143 | +++ b/hw/riscv/meson.build | ||
144 | @@ -XXX,XX +XXX,XX @@ riscv_ss.add(when: 'CONFIG_HART', if_true: files('riscv_hart.c')) | ||
145 | riscv_ss.add(when: 'CONFIG_OPENTITAN', if_true: files('opentitan.c')) | ||
146 | riscv_ss.add(when: 'CONFIG_RISCV_VIRT', if_true: files('virt.c')) | ||
147 | riscv_ss.add(when: 'CONFIG_SIFIVE', if_true: files('sifive_clint.c')) | ||
148 | -riscv_ss.add(when: 'CONFIG_SIFIVE', if_true: files('sifive_gpio.c')) | ||
149 | riscv_ss.add(when: 'CONFIG_SIFIVE', if_true: files('sifive_plic.c')) | ||
150 | riscv_ss.add(when: 'CONFIG_SIFIVE', if_true: files('sifive_test.c')) | ||
151 | riscv_ss.add(when: 'CONFIG_SIFIVE', if_true: files('sifive_uart.c')) | ||
152 | diff --git a/hw/riscv/trace-events b/hw/riscv/trace-events | ||
153 | deleted file mode 100644 | ||
154 | index XXXXXXX..XXXXXXX | ||
155 | --- a/hw/riscv/trace-events | ||
156 | +++ /dev/null | ||
157 | @@ -XXX,XX +XXX,XX @@ | ||
158 | -# See docs/devel/tracing.txt for syntax documentation. | ||
159 | - | ||
160 | -# hw/gpio/sifive_gpio.c | ||
161 | -sifive_gpio_read(uint64_t offset, uint64_t r) "offset 0x%" PRIx64 " value 0x%" PRIx64 | ||
162 | -sifive_gpio_write(uint64_t offset, uint64_t value) "offset 0x%" PRIx64 " value 0x%" PRIx64 | ||
163 | -sifive_gpio_set(int64_t line, int64_t value) "line %" PRIi64 " value %" PRIi64 | ||
164 | -sifive_gpio_update_output_irq(int64_t line, int64_t value) "line %" PRIi64 " value %" PRIi64 | ||
165 | diff --git a/meson.build b/meson.build | ||
166 | index XXXXXXX..XXXXXXX 100644 | ||
167 | --- a/meson.build | ||
168 | +++ b/meson.build | ||
169 | @@ -XXX,XX +XXX,XX @@ if have_system | ||
170 | 'hw/watchdog', | ||
171 | 'hw/xen', | ||
172 | 'hw/gpio', | ||
173 | - 'hw/riscv', | ||
174 | 'migration', | ||
175 | 'net', | ||
176 | 'ui', | ||
177 | -- | 89 | -- |
178 | 2.28.0 | 90 | 2.47.1 |
179 | |||
180 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Tomasz Jeznach <tjeznach@rivosinc.com> |
---|---|---|---|
2 | 2 | ||
3 | Microchip PolarFire SoC MMUART is ns16550 compatible, with some | 3 | This device models the RISC-V IOMMU as a sysbus device. The same design |
4 | additional registers. Create a simple MMUART model built on top | 4 | decisions taken in the riscv-iommu-pci device were kept, namely the |
5 | of the existing ns16550 model. | 5 | existence of 4 vectors are available for each interrupt cause. |
6 | 6 | ||
7 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 7 | The WSIs are emitted using the input of the s->notify() callback as a |
8 | index to an IRQ list. The IRQ list starts at 'base_irq' and goes until | ||
9 | base_irq + 3. This means that boards must have 4 contiguous IRQ lines | ||
10 | available, starting from 'base_irq'. | ||
11 | |||
12 | Signed-off-by: Tomasz Jeznach <tjeznach@rivosinc.com> | ||
13 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 14 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Message-Id: <1598924352-89526-6-git-send-email-bmeng.cn@gmail.com> | 15 | Message-ID: <20241106133407.604587-4-dbarboza@ventanamicro.com> |
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 17 | --- |
12 | include/hw/char/mchp_pfsoc_mmuart.h | 61 ++++++++++++++++++++ | 18 | include/hw/riscv/iommu.h | 4 ++ |
13 | hw/char/mchp_pfsoc_mmuart.c | 86 +++++++++++++++++++++++++++++ | 19 | hw/riscv/riscv-iommu-sys.c | 128 +++++++++++++++++++++++++++++++++++++ |
14 | MAINTAINERS | 2 + | 20 | hw/riscv/riscv-iommu.c | 3 +- |
15 | hw/char/Kconfig | 3 + | 21 | hw/riscv/meson.build | 2 +- |
16 | hw/char/meson.build | 1 + | 22 | 4 files changed, 134 insertions(+), 3 deletions(-) |
17 | 5 files changed, 153 insertions(+) | 23 | create mode 100644 hw/riscv/riscv-iommu-sys.c |
18 | create mode 100644 include/hw/char/mchp_pfsoc_mmuart.h | 24 | |
19 | create mode 100644 hw/char/mchp_pfsoc_mmuart.c | 25 | diff --git a/include/hw/riscv/iommu.h b/include/hw/riscv/iommu.h |
20 | 26 | index XXXXXXX..XXXXXXX 100644 | |
21 | diff --git a/include/hw/char/mchp_pfsoc_mmuart.h b/include/hw/char/mchp_pfsoc_mmuart.h | 27 | --- a/include/hw/riscv/iommu.h |
28 | +++ b/include/hw/riscv/iommu.h | ||
29 | @@ -XXX,XX +XXX,XX @@ typedef struct RISCVIOMMUSpace RISCVIOMMUSpace; | ||
30 | OBJECT_DECLARE_SIMPLE_TYPE(RISCVIOMMUStatePci, RISCV_IOMMU_PCI) | ||
31 | typedef struct RISCVIOMMUStatePci RISCVIOMMUStatePci; | ||
32 | |||
33 | +#define TYPE_RISCV_IOMMU_SYS "riscv-iommu-device" | ||
34 | +OBJECT_DECLARE_SIMPLE_TYPE(RISCVIOMMUStateSys, RISCV_IOMMU_SYS) | ||
35 | +typedef struct RISCVIOMMUStateSys RISCVIOMMUStateSys; | ||
36 | + | ||
37 | #endif | ||
38 | diff --git a/hw/riscv/riscv-iommu-sys.c b/hw/riscv/riscv-iommu-sys.c | ||
22 | new file mode 100644 | 39 | new file mode 100644 |
23 | index XXXXXXX..XXXXXXX | 40 | index XXXXXXX..XXXXXXX |
24 | --- /dev/null | 41 | --- /dev/null |
25 | +++ b/include/hw/char/mchp_pfsoc_mmuart.h | 42 | +++ b/hw/riscv/riscv-iommu-sys.c |
26 | @@ -XXX,XX +XXX,XX @@ | 43 | @@ -XXX,XX +XXX,XX @@ |
27 | +/* | 44 | +/* |
28 | + * Microchip PolarFire SoC MMUART emulation | 45 | + * QEMU emulation of an RISC-V IOMMU Platform Device |
29 | + * | 46 | + * |
30 | + * Copyright (c) 2020 Wind River Systems, Inc. | 47 | + * Copyright (C) 2022-2023 Rivos Inc. |
31 | + * | 48 | + * |
32 | + * Author: | 49 | + * This program is free software; you can redistribute it and/or modify it |
33 | + * Bin Meng <bin.meng@windriver.com> | 50 | + * under the terms and conditions of the GNU General Public License, |
34 | + * | 51 | + * version 2 or later, as published by the Free Software Foundation. |
35 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
36 | + * of this software and associated documentation files (the "Software"), to deal | ||
37 | + * in the Software without restriction, including without limitation the rights | ||
38 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
39 | + * copies of the Software, and to permit persons to whom the Software is | ||
40 | + * furnished to do so, subject to the following conditions: | ||
41 | + * | ||
42 | + * The above copyright notice and this permission notice shall be included in | ||
43 | + * all copies or substantial portions of the Software. | ||
44 | + * | ||
45 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
46 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
47 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
48 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
49 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
50 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
51 | + * THE SOFTWARE. | ||
52 | + */ | ||
53 | + | ||
54 | +#ifndef HW_MCHP_PFSOC_MMUART_H | ||
55 | +#define HW_MCHP_PFSOC_MMUART_H | ||
56 | + | ||
57 | +#include "hw/char/serial.h" | ||
58 | + | ||
59 | +#define MCHP_PFSOC_MMUART_REG_SIZE 52 | ||
60 | + | ||
61 | +typedef struct MchpPfSoCMMUartState { | ||
62 | + MemoryRegion iomem; | ||
63 | + hwaddr base; | ||
64 | + qemu_irq irq; | ||
65 | + | ||
66 | + SerialMM *serial; | ||
67 | + | ||
68 | + uint32_t reg[MCHP_PFSOC_MMUART_REG_SIZE / sizeof(uint32_t)]; | ||
69 | +} MchpPfSoCMMUartState; | ||
70 | + | ||
71 | +/** | ||
72 | + * mchp_pfsoc_mmuart_create - Create a Microchip PolarFire SoC MMUART | ||
73 | + * | ||
74 | + * This is a helper routine for board to create a MMUART device that is | ||
75 | + * compatible with Microchip PolarFire SoC. | ||
76 | + * | ||
77 | + * @sysmem: system memory region to map | ||
78 | + * @base: base address of the MMUART registers | ||
79 | + * @irq: IRQ number of the MMUART device | ||
80 | + * @chr: character device to associate to | ||
81 | + * | ||
82 | + * @return: a pointer to the device specific control structure | ||
83 | + */ | ||
84 | +MchpPfSoCMMUartState *mchp_pfsoc_mmuart_create(MemoryRegion *sysmem, | ||
85 | + hwaddr base, qemu_irq irq, Chardev *chr); | ||
86 | + | ||
87 | +#endif /* HW_MCHP_PFSOC_MMUART_H */ | ||
88 | diff --git a/hw/char/mchp_pfsoc_mmuart.c b/hw/char/mchp_pfsoc_mmuart.c | ||
89 | new file mode 100644 | ||
90 | index XXXXXXX..XXXXXXX | ||
91 | --- /dev/null | ||
92 | +++ b/hw/char/mchp_pfsoc_mmuart.c | ||
93 | @@ -XXX,XX +XXX,XX @@ | ||
94 | +/* | ||
95 | + * Microchip PolarFire SoC MMUART emulation | ||
96 | + * | ||
97 | + * Copyright (c) 2020 Wind River Systems, Inc. | ||
98 | + * | ||
99 | + * Author: | ||
100 | + * Bin Meng <bin.meng@windriver.com> | ||
101 | + * | ||
102 | + * This program is free software; you can redistribute it and/or | ||
103 | + * modify it under the terms of the GNU General Public License as | ||
104 | + * published by the Free Software Foundation; either version 2 or | ||
105 | + * (at your option) version 3 of the License. | ||
106 | + * | 52 | + * |
107 | + * This program is distributed in the hope that it will be useful, | 53 | + * This program is distributed in the hope that it will be useful, |
108 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | 54 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
109 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 55 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
110 | + * GNU General Public License for more details. | 56 | + * GNU General Public License for more details. |
111 | + * | 57 | + * |
112 | + * You should have received a copy of the GNU General Public License along | 58 | + * You should have received a copy of the GNU General Public License along |
113 | + * with this program; if not, see <http://www.gnu.org/licenses/>. | 59 | + * with this program; if not, see <http://www.gnu.org/licenses/>. |
114 | + */ | 60 | + */ |
115 | + | 61 | + |
116 | +#include "qemu/osdep.h" | 62 | +#include "qemu/osdep.h" |
117 | +#include "qemu/log.h" | 63 | +#include "hw/irq.h" |
118 | +#include "chardev/char.h" | 64 | +#include "hw/pci/pci_bus.h" |
119 | +#include "exec/address-spaces.h" | 65 | +#include "hw/qdev-properties.h" |
120 | +#include "hw/char/mchp_pfsoc_mmuart.h" | 66 | +#include "hw/sysbus.h" |
121 | + | 67 | +#include "qapi/error.h" |
122 | +static uint64_t mchp_pfsoc_mmuart_read(void *opaque, hwaddr addr, unsigned size) | 68 | +#include "qemu/error-report.h" |
123 | +{ | 69 | +#include "qemu/host-utils.h" |
124 | + MchpPfSoCMMUartState *s = opaque; | 70 | +#include "qemu/module.h" |
125 | + | 71 | +#include "qom/object.h" |
126 | + if (addr >= MCHP_PFSOC_MMUART_REG_SIZE) { | 72 | + |
127 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: read: addr=0x%" HWADDR_PRIx "\n", | 73 | +#include "riscv-iommu.h" |
128 | + __func__, addr); | 74 | + |
129 | + return 0; | 75 | +#define RISCV_IOMMU_SYSDEV_ICVEC_VECTORS 0x3333 |
130 | + } | 76 | + |
131 | + | 77 | +/* RISC-V IOMMU System Platform Device Emulation */ |
132 | + return s->reg[addr / sizeof(uint32_t)]; | 78 | + |
133 | +} | 79 | +struct RISCVIOMMUStateSys { |
134 | + | 80 | + SysBusDevice parent; |
135 | +static void mchp_pfsoc_mmuart_write(void *opaque, hwaddr addr, | 81 | + uint64_t addr; |
136 | + uint64_t value, unsigned size) | 82 | + uint32_t base_irq; |
137 | +{ | 83 | + DeviceState *irqchip; |
138 | + MchpPfSoCMMUartState *s = opaque; | 84 | + RISCVIOMMUState iommu; |
139 | + uint32_t val32 = (uint32_t)value; | 85 | + qemu_irq irqs[RISCV_IOMMU_INTR_COUNT]; |
140 | + | 86 | +}; |
141 | + if (addr >= MCHP_PFSOC_MMUART_REG_SIZE) { | 87 | + |
142 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: bad write: addr=0x%" HWADDR_PRIx | 88 | +static void riscv_iommu_sysdev_notify(RISCVIOMMUState *iommu, |
143 | + " v=0x%x\n", __func__, addr, val32); | 89 | + unsigned vector) |
90 | +{ | ||
91 | + RISCVIOMMUStateSys *s = container_of(iommu, RISCVIOMMUStateSys, iommu); | ||
92 | + uint32_t fctl = riscv_iommu_reg_get32(iommu, RISCV_IOMMU_REG_FCTL); | ||
93 | + | ||
94 | + /* We do not support MSIs yet */ | ||
95 | + if (!(fctl & RISCV_IOMMU_FCTL_WSI)) { | ||
144 | + return; | 96 | + return; |
145 | + } | 97 | + } |
146 | + | 98 | + |
147 | + s->reg[addr / sizeof(uint32_t)] = val32; | 99 | + qemu_irq_pulse(s->irqs[vector]); |
148 | +} | 100 | +} |
149 | + | 101 | + |
150 | +static const MemoryRegionOps mchp_pfsoc_mmuart_ops = { | 102 | +static void riscv_iommu_sys_realize(DeviceState *dev, Error **errp) |
151 | + .read = mchp_pfsoc_mmuart_read, | 103 | +{ |
152 | + .write = mchp_pfsoc_mmuart_write, | 104 | + RISCVIOMMUStateSys *s = RISCV_IOMMU_SYS(dev); |
153 | + .endianness = DEVICE_LITTLE_ENDIAN, | 105 | + SysBusDevice *sysdev = SYS_BUS_DEVICE(s); |
154 | + .impl = { | 106 | + PCIBus *pci_bus; |
155 | + .min_access_size = 4, | 107 | + qemu_irq irq; |
156 | + .max_access_size = 4, | 108 | + |
157 | + }, | 109 | + qdev_realize(DEVICE(&s->iommu), NULL, errp); |
110 | + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iommu.regs_mr); | ||
111 | + if (s->addr) { | ||
112 | + sysbus_mmio_map(SYS_BUS_DEVICE(s), 0, s->addr); | ||
113 | + } | ||
114 | + | ||
115 | + pci_bus = (PCIBus *) object_resolve_path_type("", TYPE_PCI_BUS, NULL); | ||
116 | + if (pci_bus) { | ||
117 | + riscv_iommu_pci_setup_iommu(&s->iommu, pci_bus, errp); | ||
118 | + } | ||
119 | + | ||
120 | + s->iommu.notify = riscv_iommu_sysdev_notify; | ||
121 | + | ||
122 | + /* 4 IRQs are defined starting from s->base_irq */ | ||
123 | + for (int i = 0; i < RISCV_IOMMU_INTR_COUNT; i++) { | ||
124 | + sysbus_init_irq(sysdev, &s->irqs[i]); | ||
125 | + irq = qdev_get_gpio_in(s->irqchip, s->base_irq + i); | ||
126 | + sysbus_connect_irq(sysdev, i, irq); | ||
127 | + } | ||
128 | +} | ||
129 | + | ||
130 | +static void riscv_iommu_sys_init(Object *obj) | ||
131 | +{ | ||
132 | + RISCVIOMMUStateSys *s = RISCV_IOMMU_SYS(obj); | ||
133 | + RISCVIOMMUState *iommu = &s->iommu; | ||
134 | + | ||
135 | + object_initialize_child(obj, "iommu", iommu, TYPE_RISCV_IOMMU); | ||
136 | + qdev_alias_all_properties(DEVICE(iommu), obj); | ||
137 | + | ||
138 | + iommu->icvec_avail_vectors = RISCV_IOMMU_SYSDEV_ICVEC_VECTORS; | ||
139 | + riscv_iommu_set_cap_igs(iommu, RISCV_IOMMU_CAP_IGS_WSI); | ||
140 | +} | ||
141 | + | ||
142 | +static Property riscv_iommu_sys_properties[] = { | ||
143 | + DEFINE_PROP_UINT64("addr", RISCVIOMMUStateSys, addr, 0), | ||
144 | + DEFINE_PROP_UINT32("base-irq", RISCVIOMMUStateSys, base_irq, 0), | ||
145 | + DEFINE_PROP_LINK("irqchip", RISCVIOMMUStateSys, irqchip, | ||
146 | + TYPE_DEVICE, DeviceState *), | ||
147 | + DEFINE_PROP_END_OF_LIST(), | ||
158 | +}; | 148 | +}; |
159 | + | 149 | + |
160 | +MchpPfSoCMMUartState *mchp_pfsoc_mmuart_create(MemoryRegion *sysmem, | 150 | +static void riscv_iommu_sys_class_init(ObjectClass *klass, void *data) |
161 | + hwaddr base, qemu_irq irq, Chardev *chr) | 151 | +{ |
162 | +{ | 152 | + DeviceClass *dc = DEVICE_CLASS(klass); |
163 | + MchpPfSoCMMUartState *s; | 153 | + dc->realize = riscv_iommu_sys_realize; |
164 | + | 154 | + set_bit(DEVICE_CATEGORY_MISC, dc->categories); |
165 | + s = g_new0(MchpPfSoCMMUartState, 1); | 155 | + device_class_set_props(dc, riscv_iommu_sys_properties); |
166 | + | 156 | +} |
167 | + memory_region_init_io(&s->iomem, NULL, &mchp_pfsoc_mmuart_ops, s, | 157 | + |
168 | + "mchp.pfsoc.mmuart", 0x1000); | 158 | +static const TypeInfo riscv_iommu_sys = { |
169 | + | 159 | + .name = TYPE_RISCV_IOMMU_SYS, |
170 | + s->base = base; | 160 | + .parent = TYPE_SYS_BUS_DEVICE, |
171 | + s->irq = irq; | 161 | + .class_init = riscv_iommu_sys_class_init, |
172 | + | 162 | + .instance_init = riscv_iommu_sys_init, |
173 | + s->serial = serial_mm_init(sysmem, base, 2, irq, 399193, chr, | 163 | + .instance_size = sizeof(RISCVIOMMUStateSys), |
174 | + DEVICE_LITTLE_ENDIAN); | 164 | +}; |
175 | + | 165 | + |
176 | + memory_region_add_subregion(sysmem, base + 0x20, &s->iomem); | 166 | +static void riscv_iommu_register_sys(void) |
177 | + | 167 | +{ |
178 | + return s; | 168 | + type_register_static(&riscv_iommu_sys); |
179 | +} | 169 | +} |
180 | diff --git a/MAINTAINERS b/MAINTAINERS | 170 | + |
171 | +type_init(riscv_iommu_register_sys) | ||
172 | diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c | ||
181 | index XXXXXXX..XXXXXXX 100644 | 173 | index XXXXXXX..XXXXXXX 100644 |
182 | --- a/MAINTAINERS | 174 | --- a/hw/riscv/riscv-iommu.c |
183 | +++ b/MAINTAINERS | 175 | +++ b/hw/riscv/riscv-iommu.c |
184 | @@ -XXX,XX +XXX,XX @@ M: Bin Meng <bin.meng@windriver.com> | 176 | @@ -XXX,XX +XXX,XX @@ static uint8_t riscv_iommu_get_icvec_vector(uint32_t icvec, uint32_t vec_type) |
185 | L: qemu-riscv@nongnu.org | 177 | |
186 | S: Supported | 178 | static void riscv_iommu_notify(RISCVIOMMUState *s, int vec_type) |
187 | F: hw/riscv/microchip_pfsoc.c | 179 | { |
188 | +F: hw/char/mchp_pfsoc_mmuart.c | 180 | - const uint32_t fctl = riscv_iommu_reg_get32(s, RISCV_IOMMU_REG_FCTL); |
189 | F: include/hw/riscv/microchip_pfsoc.h | 181 | uint32_t ipsr, icvec, vector; |
190 | +F: include/hw/char/mchp_pfsoc_mmuart.h | 182 | |
191 | 183 | - if (fctl & RISCV_IOMMU_FCTL_WSI || !s->notify) { | |
192 | RX Machines | 184 | + if (!s->notify) { |
193 | ----------- | 185 | return; |
194 | diff --git a/hw/char/Kconfig b/hw/char/Kconfig | 186 | } |
187 | |||
188 | diff --git a/hw/riscv/meson.build b/hw/riscv/meson.build | ||
195 | index XXXXXXX..XXXXXXX 100644 | 189 | index XXXXXXX..XXXXXXX 100644 |
196 | --- a/hw/char/Kconfig | 190 | --- a/hw/riscv/meson.build |
197 | +++ b/hw/char/Kconfig | 191 | +++ b/hw/riscv/meson.build |
198 | @@ -XXX,XX +XXX,XX @@ config RENESAS_SCI | 192 | @@ -XXX,XX +XXX,XX @@ riscv_ss.add(when: 'CONFIG_SIFIVE_U', if_true: files('sifive_u.c')) |
199 | 193 | riscv_ss.add(when: 'CONFIG_SPIKE', if_true: files('spike.c')) | |
200 | config AVR_USART | 194 | riscv_ss.add(when: 'CONFIG_MICROCHIP_PFSOC', if_true: files('microchip_pfsoc.c')) |
201 | bool | 195 | riscv_ss.add(when: 'CONFIG_ACPI', if_true: files('virt-acpi-build.c')) |
202 | + | 196 | -riscv_ss.add(when: 'CONFIG_RISCV_IOMMU', if_true: files('riscv-iommu.c', 'riscv-iommu-pci.c')) |
203 | +config MCHP_PFSOC_MMUART | 197 | +riscv_ss.add(when: 'CONFIG_RISCV_IOMMU', if_true: files('riscv-iommu.c', 'riscv-iommu-pci.c', 'riscv-iommu-sys.c')) |
204 | + bool | 198 | |
205 | diff --git a/hw/char/meson.build b/hw/char/meson.build | 199 | hw_arch += {'riscv': riscv_ss} |
206 | index XXXXXXX..XXXXXXX 100644 | ||
207 | --- a/hw/char/meson.build | ||
208 | +++ b/hw/char/meson.build | ||
209 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_aux.c')) | ||
210 | softmmu_ss.add(when: 'CONFIG_RENESAS_SCI', if_true: files('renesas_sci.c')) | ||
211 | softmmu_ss.add(when: 'CONFIG_SH4', if_true: files('sh_serial.c')) | ||
212 | softmmu_ss.add(when: 'CONFIG_STM32F2XX_USART', if_true: files('stm32f2xx_usart.c')) | ||
213 | +softmmu_ss.add(when: 'CONFIG_MCHP_PFSOC_MMUART', if_true: files('mchp_pfsoc_mmuart.c')) | ||
214 | |||
215 | specific_ss.add(when: 'CONFIG_TERMINAL3270', if_true: files('terminal3270.c')) | ||
216 | specific_ss.add(when: 'CONFIG_VIRTIO', if_true: files('virtio-serial-bus.c')) | ||
217 | -- | 200 | -- |
218 | 2.28.0 | 201 | 2.47.1 |
219 | |||
220 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Sunil V L <sunilvl@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | This is an effort to clean up the hw/riscv directory. Ideally it | 3 | Add a new machine option called 'iommu-sys' that enables a |
4 | should only contain the RISC-V SoC / machine codes plus generic | 4 | riscv-iommu-sys platform device for the 'virt' machine. The option is |
5 | codes. Let's move sifive_test model to hw/misc directory. | 5 | default 'off'. |
6 | 6 | ||
7 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 7 | The device will use IRQs 36 to 39. |
8 | |||
9 | We will not support both riscv-iommu-sys and riscv-iommu-pci devices in | ||
10 | the same board in this first implementation. If a riscv-iommu-pci device | ||
11 | is added in the command line we will disable the riscv-iommu-sys device. | ||
12 | |||
13 | Signed-off-by: Sunil V L <sunilvl@ventanamicro.com> | ||
14 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Message-Id: <1599129623-68957-10-git-send-email-bmeng.cn@gmail.com> | 16 | Message-ID: <20241106133407.604587-5-dbarboza@ventanamicro.com> |
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 17 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 18 | --- |
12 | include/hw/{riscv => misc}/sifive_test.h | 0 | 19 | include/hw/riscv/iommu.h | 2 + |
13 | hw/{riscv => misc}/sifive_test.c | 2 +- | 20 | include/hw/riscv/virt.h | 6 ++- |
14 | hw/riscv/virt.c | 2 +- | 21 | hw/riscv/virt.c | 104 ++++++++++++++++++++++++++++++++++++++- |
15 | hw/misc/Kconfig | 3 +++ | 22 | 3 files changed, 109 insertions(+), 3 deletions(-) |
16 | hw/misc/meson.build | 1 + | 23 | |
17 | hw/riscv/Kconfig | 1 + | 24 | diff --git a/include/hw/riscv/iommu.h b/include/hw/riscv/iommu.h |
18 | hw/riscv/meson.build | 1 - | ||
19 | 7 files changed, 7 insertions(+), 3 deletions(-) | ||
20 | rename include/hw/{riscv => misc}/sifive_test.h (100%) | ||
21 | rename hw/{riscv => misc}/sifive_test.c (98%) | ||
22 | |||
23 | diff --git a/include/hw/riscv/sifive_test.h b/include/hw/misc/sifive_test.h | ||
24 | similarity index 100% | ||
25 | rename from include/hw/riscv/sifive_test.h | ||
26 | rename to include/hw/misc/sifive_test.h | ||
27 | diff --git a/hw/riscv/sifive_test.c b/hw/misc/sifive_test.c | ||
28 | similarity index 98% | ||
29 | rename from hw/riscv/sifive_test.c | ||
30 | rename to hw/misc/sifive_test.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
32 | --- a/hw/riscv/sifive_test.c | 26 | --- a/include/hw/riscv/iommu.h |
33 | +++ b/hw/misc/sifive_test.c | 27 | +++ b/include/hw/riscv/iommu.h |
34 | @@ -XXX,XX +XXX,XX @@ | 28 | @@ -XXX,XX +XXX,XX @@ typedef struct RISCVIOMMUStatePci RISCVIOMMUStatePci; |
35 | #include "qemu/module.h" | 29 | OBJECT_DECLARE_SIMPLE_TYPE(RISCVIOMMUStateSys, RISCV_IOMMU_SYS) |
36 | #include "sysemu/runstate.h" | 30 | typedef struct RISCVIOMMUStateSys RISCVIOMMUStateSys; |
37 | #include "hw/hw.h" | 31 | |
38 | -#include "hw/riscv/sifive_test.h" | 32 | +#define FDT_IRQ_TYPE_EDGE_LOW 1 |
39 | +#include "hw/misc/sifive_test.h" | 33 | + |
40 | 34 | #endif | |
41 | static uint64_t sifive_test_read(void *opaque, hwaddr addr, unsigned int size) | 35 | diff --git a/include/hw/riscv/virt.h b/include/hw/riscv/virt.h |
42 | { | 36 | index XXXXXXX..XXXXXXX 100644 |
37 | --- a/include/hw/riscv/virt.h | ||
38 | +++ b/include/hw/riscv/virt.h | ||
39 | @@ -XXX,XX +XXX,XX @@ struct RISCVVirtState { | ||
40 | OnOffAuto acpi; | ||
41 | const MemMapEntry *memmap; | ||
42 | struct GPEXHost *gpex_host; | ||
43 | + OnOffAuto iommu_sys; | ||
44 | }; | ||
45 | |||
46 | enum { | ||
47 | @@ -XXX,XX +XXX,XX @@ enum { | ||
48 | VIRT_PCIE_MMIO, | ||
49 | VIRT_PCIE_PIO, | ||
50 | VIRT_PLATFORM_BUS, | ||
51 | - VIRT_PCIE_ECAM | ||
52 | + VIRT_PCIE_ECAM, | ||
53 | + VIRT_IOMMU_SYS, | ||
54 | }; | ||
55 | |||
56 | enum { | ||
57 | @@ -XXX,XX +XXX,XX @@ enum { | ||
58 | VIRTIO_IRQ = 1, /* 1 to 8 */ | ||
59 | VIRTIO_COUNT = 8, | ||
60 | PCIE_IRQ = 0x20, /* 32 to 35 */ | ||
61 | + IOMMU_SYS_IRQ = 0x24, /* 36-39 */ | ||
62 | VIRT_PLATFORM_BUS_IRQ = 64, /* 64 to 95 */ | ||
63 | }; | ||
64 | |||
65 | @@ -XXX,XX +XXX,XX @@ enum { | ||
66 | 1 + FDT_APLIC_INT_CELLS) | ||
67 | |||
68 | bool virt_is_acpi_enabled(RISCVVirtState *s); | ||
69 | +bool virt_is_iommu_sys_enabled(RISCVVirtState *s); | ||
70 | void virt_acpi_setup(RISCVVirtState *vms); | ||
71 | uint32_t imsic_num_bits(uint32_t count); | ||
72 | |||
43 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | 73 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c |
44 | index XXXXXXX..XXXXXXX 100644 | 74 | index XXXXXXX..XXXXXXX 100644 |
45 | --- a/hw/riscv/virt.c | 75 | --- a/hw/riscv/virt.c |
46 | +++ b/hw/riscv/virt.c | 76 | +++ b/hw/riscv/virt.c |
47 | @@ -XXX,XX +XXX,XX @@ | 77 | @@ -XXX,XX +XXX,XX @@ |
48 | #include "hw/char/serial.h" | 78 | #include "target/riscv/pmu.h" |
49 | #include "target/riscv/cpu.h" | ||
50 | #include "hw/riscv/riscv_hart.h" | 79 | #include "hw/riscv/riscv_hart.h" |
51 | -#include "hw/riscv/sifive_test.h" | 80 | #include "hw/riscv/iommu.h" |
81 | +#include "hw/riscv/riscv-iommu-bits.h" | ||
52 | #include "hw/riscv/virt.h" | 82 | #include "hw/riscv/virt.h" |
53 | #include "hw/riscv/boot.h" | 83 | #include "hw/riscv/boot.h" |
54 | #include "hw/riscv/numa.h" | 84 | #include "hw/riscv/numa.h" |
55 | #include "hw/intc/sifive_clint.h" | 85 | @@ -XXX,XX +XXX,XX @@ static const MemMapEntry virt_memmap[] = { |
56 | #include "hw/intc/sifive_plic.h" | 86 | [VIRT_CLINT] = { 0x2000000, 0x10000 }, |
57 | +#include "hw/misc/sifive_test.h" | 87 | [VIRT_ACLINT_SSWI] = { 0x2F00000, 0x4000 }, |
58 | #include "chardev/char.h" | 88 | [VIRT_PCIE_PIO] = { 0x3000000, 0x10000 }, |
59 | #include "sysemu/arch_init.h" | 89 | + [VIRT_IOMMU_SYS] = { 0x3010000, 0x1000 }, |
60 | #include "sysemu/device_tree.h" | 90 | [VIRT_PLATFORM_BUS] = { 0x4000000, 0x2000000 }, |
61 | diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig | 91 | [VIRT_PLIC] = { 0xc000000, VIRT_PLIC_SIZE(VIRT_CPUS_MAX * 2) }, |
62 | index XXXXXXX..XXXXXXX 100644 | 92 | [VIRT_APLIC_M] = { 0xc000000, APLIC_SIZE(VIRT_CPUS_MAX) }, |
63 | --- a/hw/misc/Kconfig | 93 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_virtio(RISCVVirtState *s, const MemMapEntry *memmap, |
64 | +++ b/hw/misc/Kconfig | 94 | |
65 | @@ -XXX,XX +XXX,XX @@ config MAC_VIA | 95 | static void create_fdt_pcie(RISCVVirtState *s, const MemMapEntry *memmap, |
66 | config AVR_POWER | 96 | uint32_t irq_pcie_phandle, |
67 | bool | 97 | - uint32_t msi_pcie_phandle) |
68 | 98 | + uint32_t msi_pcie_phandle, | |
69 | +config SIFIVE_TEST | 99 | + uint32_t iommu_sys_phandle) |
70 | + bool | 100 | { |
71 | + | 101 | g_autofree char *name = NULL; |
72 | config SIFIVE_E_PRCI | 102 | MachineState *ms = MACHINE(s); |
73 | bool | 103 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_pcie(RISCVVirtState *s, const MemMapEntry *memmap, |
74 | 104 | 2, virt_high_pcie_memmap.base, | |
75 | diff --git a/hw/misc/meson.build b/hw/misc/meson.build | 105 | 2, virt_high_pcie_memmap.base, 2, virt_high_pcie_memmap.size); |
76 | index XXXXXXX..XXXXXXX 100644 | 106 | |
77 | --- a/hw/misc/meson.build | 107 | + if (virt_is_iommu_sys_enabled(s)) { |
78 | +++ b/hw/misc/meson.build | 108 | + qemu_fdt_setprop_cells(ms->fdt, name, "iommu-map", |
79 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_ARM11SCU', if_true: files('arm11scu.c')) | 109 | + 0, iommu_sys_phandle, 0, 0, 0, |
80 | softmmu_ss.add(when: 'CONFIG_MOS6522', if_true: files('mos6522.c')) | 110 | + iommu_sys_phandle, 0, 0xffff); |
81 | 111 | + } | |
82 | # RISC-V devices | 112 | + |
83 | +softmmu_ss.add(when: 'CONFIG_SIFIVE_TEST', if_true: files('sifive_test.c')) | 113 | create_pcie_irq_map(s, ms->fdt, name, irq_pcie_phandle); |
84 | softmmu_ss.add(when: 'CONFIG_SIFIVE_E_PRCI', if_true: files('sifive_e_prci.c')) | 114 | } |
85 | softmmu_ss.add(when: 'CONFIG_SIFIVE_U_OTP', if_true: files('sifive_u_otp.c')) | 115 | |
86 | softmmu_ss.add(when: 'CONFIG_SIFIVE_U_PRCI', if_true: files('sifive_u_prci.c')) | 116 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_virtio_iommu(RISCVVirtState *s, uint16_t bdf) |
87 | diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig | 117 | bdf + 1, iommu_phandle, bdf + 1, 0xffff - bdf); |
88 | index XXXXXXX..XXXXXXX 100644 | 118 | } |
89 | --- a/hw/riscv/Kconfig | 119 | |
90 | +++ b/hw/riscv/Kconfig | 120 | +static void create_fdt_iommu_sys(RISCVVirtState *s, uint32_t irq_chip, |
91 | @@ -XXX,XX +XXX,XX @@ config RISCV_VIRT | 121 | + uint32_t *iommu_sys_phandle) |
92 | select SIFIVE | 122 | +{ |
93 | select SIFIVE_CLINT | 123 | + const char comp[] = "riscv,iommu"; |
94 | select SIFIVE_PLIC | 124 | + void *fdt = MACHINE(s)->fdt; |
95 | + select SIFIVE_TEST | 125 | + uint32_t iommu_phandle; |
96 | 126 | + g_autofree char *iommu_node = NULL; | |
97 | config MICROCHIP_PFSOC | 127 | + hwaddr addr = s->memmap[VIRT_IOMMU_SYS].base; |
98 | bool | 128 | + hwaddr size = s->memmap[VIRT_IOMMU_SYS].size; |
99 | diff --git a/hw/riscv/meson.build b/hw/riscv/meson.build | 129 | + uint32_t iommu_irq_map[RISCV_IOMMU_INTR_COUNT] = { |
100 | index XXXXXXX..XXXXXXX 100644 | 130 | + IOMMU_SYS_IRQ + RISCV_IOMMU_INTR_CQ, |
101 | --- a/hw/riscv/meson.build | 131 | + IOMMU_SYS_IRQ + RISCV_IOMMU_INTR_FQ, |
102 | +++ b/hw/riscv/meson.build | 132 | + IOMMU_SYS_IRQ + RISCV_IOMMU_INTR_PM, |
103 | @@ -XXX,XX +XXX,XX @@ riscv_ss.add(files('numa.c')) | 133 | + IOMMU_SYS_IRQ + RISCV_IOMMU_INTR_PQ, |
104 | riscv_ss.add(when: 'CONFIG_HART', if_true: files('riscv_hart.c')) | 134 | + }; |
105 | riscv_ss.add(when: 'CONFIG_OPENTITAN', if_true: files('opentitan.c')) | 135 | + |
106 | riscv_ss.add(when: 'CONFIG_RISCV_VIRT', if_true: files('virt.c')) | 136 | + iommu_node = g_strdup_printf("/soc/iommu@%x", |
107 | -riscv_ss.add(when: 'CONFIG_SIFIVE', if_true: files('sifive_test.c')) | 137 | + (unsigned int) s->memmap[VIRT_IOMMU_SYS].base); |
108 | riscv_ss.add(when: 'CONFIG_SIFIVE_E', if_true: files('sifive_e.c')) | 138 | + iommu_phandle = qemu_fdt_alloc_phandle(fdt); |
109 | riscv_ss.add(when: 'CONFIG_SIFIVE_U', if_true: files('sifive_u.c')) | 139 | + qemu_fdt_add_subnode(fdt, iommu_node); |
110 | riscv_ss.add(when: 'CONFIG_SPIKE', if_true: files('spike.c')) | 140 | + |
141 | + qemu_fdt_setprop(fdt, iommu_node, "compatible", comp, sizeof(comp)); | ||
142 | + qemu_fdt_setprop_cell(fdt, iommu_node, "#iommu-cells", 1); | ||
143 | + qemu_fdt_setprop_cell(fdt, iommu_node, "phandle", iommu_phandle); | ||
144 | + | ||
145 | + qemu_fdt_setprop_cells(fdt, iommu_node, "reg", | ||
146 | + addr >> 32, addr, size >> 32, size); | ||
147 | + qemu_fdt_setprop_cell(fdt, iommu_node, "interrupt-parent", irq_chip); | ||
148 | + | ||
149 | + qemu_fdt_setprop_cells(fdt, iommu_node, "interrupts", | ||
150 | + iommu_irq_map[0], FDT_IRQ_TYPE_EDGE_LOW, | ||
151 | + iommu_irq_map[1], FDT_IRQ_TYPE_EDGE_LOW, | ||
152 | + iommu_irq_map[2], FDT_IRQ_TYPE_EDGE_LOW, | ||
153 | + iommu_irq_map[3], FDT_IRQ_TYPE_EDGE_LOW); | ||
154 | + | ||
155 | + *iommu_sys_phandle = iommu_phandle; | ||
156 | +} | ||
157 | + | ||
158 | static void create_fdt_iommu(RISCVVirtState *s, uint16_t bdf) | ||
159 | { | ||
160 | const char comp[] = "riscv,pci-iommu"; | ||
161 | @@ -XXX,XX +XXX,XX @@ static void finalize_fdt(RISCVVirtState *s) | ||
162 | { | ||
163 | uint32_t phandle = 1, irq_mmio_phandle = 1, msi_pcie_phandle = 1; | ||
164 | uint32_t irq_pcie_phandle = 1, irq_virtio_phandle = 1; | ||
165 | + uint32_t iommu_sys_phandle = 1; | ||
166 | |||
167 | create_fdt_sockets(s, virt_memmap, &phandle, &irq_mmio_phandle, | ||
168 | &irq_pcie_phandle, &irq_virtio_phandle, | ||
169 | @@ -XXX,XX +XXX,XX @@ static void finalize_fdt(RISCVVirtState *s) | ||
170 | |||
171 | create_fdt_virtio(s, virt_memmap, irq_virtio_phandle); | ||
172 | |||
173 | - create_fdt_pcie(s, virt_memmap, irq_pcie_phandle, msi_pcie_phandle); | ||
174 | + if (virt_is_iommu_sys_enabled(s)) { | ||
175 | + create_fdt_iommu_sys(s, irq_mmio_phandle, &iommu_sys_phandle); | ||
176 | + } | ||
177 | + create_fdt_pcie(s, virt_memmap, irq_pcie_phandle, msi_pcie_phandle, | ||
178 | + iommu_sys_phandle); | ||
179 | |||
180 | create_fdt_reset(s, virt_memmap, &phandle); | ||
181 | |||
182 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine) | ||
183 | create_fdt(s, memmap); | ||
184 | } | ||
185 | |||
186 | + if (virt_is_iommu_sys_enabled(s)) { | ||
187 | + DeviceState *iommu_sys = qdev_new(TYPE_RISCV_IOMMU_SYS); | ||
188 | + | ||
189 | + object_property_set_uint(OBJECT(iommu_sys), "addr", | ||
190 | + s->memmap[VIRT_IOMMU_SYS].base, | ||
191 | + &error_fatal); | ||
192 | + object_property_set_uint(OBJECT(iommu_sys), "base-irq", | ||
193 | + IOMMU_SYS_IRQ, | ||
194 | + &error_fatal); | ||
195 | + object_property_set_link(OBJECT(iommu_sys), "irqchip", | ||
196 | + OBJECT(mmio_irqchip), | ||
197 | + &error_fatal); | ||
198 | + | ||
199 | + sysbus_realize_and_unref(SYS_BUS_DEVICE(iommu_sys), &error_fatal); | ||
200 | + } | ||
201 | + | ||
202 | s->machine_done.notify = virt_machine_done; | ||
203 | qemu_add_machine_init_done_notifier(&s->machine_done); | ||
204 | } | ||
205 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_instance_init(Object *obj) | ||
206 | s->oem_id = g_strndup(ACPI_BUILD_APPNAME6, 6); | ||
207 | s->oem_table_id = g_strndup(ACPI_BUILD_APPNAME8, 8); | ||
208 | s->acpi = ON_OFF_AUTO_AUTO; | ||
209 | + s->iommu_sys = ON_OFF_AUTO_AUTO; | ||
210 | } | ||
211 | |||
212 | static char *virt_get_aia_guests(Object *obj, Error **errp) | ||
213 | @@ -XXX,XX +XXX,XX @@ static void virt_set_aclint(Object *obj, bool value, Error **errp) | ||
214 | s->have_aclint = value; | ||
215 | } | ||
216 | |||
217 | +bool virt_is_iommu_sys_enabled(RISCVVirtState *s) | ||
218 | +{ | ||
219 | + return s->iommu_sys == ON_OFF_AUTO_ON; | ||
220 | +} | ||
221 | + | ||
222 | +static void virt_get_iommu_sys(Object *obj, Visitor *v, const char *name, | ||
223 | + void *opaque, Error **errp) | ||
224 | +{ | ||
225 | + RISCVVirtState *s = RISCV_VIRT_MACHINE(obj); | ||
226 | + OnOffAuto iommu_sys = s->iommu_sys; | ||
227 | + | ||
228 | + visit_type_OnOffAuto(v, name, &iommu_sys, errp); | ||
229 | +} | ||
230 | + | ||
231 | +static void virt_set_iommu_sys(Object *obj, Visitor *v, const char *name, | ||
232 | + void *opaque, Error **errp) | ||
233 | +{ | ||
234 | + RISCVVirtState *s = RISCV_VIRT_MACHINE(obj); | ||
235 | + | ||
236 | + visit_type_OnOffAuto(v, name, &s->iommu_sys, errp); | ||
237 | +} | ||
238 | + | ||
239 | bool virt_is_acpi_enabled(RISCVVirtState *s) | ||
240 | { | ||
241 | return s->acpi != ON_OFF_AUTO_OFF; | ||
242 | @@ -XXX,XX +XXX,XX @@ static HotplugHandler *virt_machine_get_hotplug_handler(MachineState *machine, | ||
243 | DeviceState *dev) | ||
244 | { | ||
245 | MachineClass *mc = MACHINE_GET_CLASS(machine); | ||
246 | + RISCVVirtState *s = RISCV_VIRT_MACHINE(machine); | ||
247 | |||
248 | if (device_is_dynamic_sysbus(mc, dev) || | ||
249 | object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI) || | ||
250 | object_dynamic_cast(OBJECT(dev), TYPE_RISCV_IOMMU_PCI)) { | ||
251 | + s->iommu_sys = ON_OFF_AUTO_OFF; | ||
252 | return HOTPLUG_HANDLER(machine); | ||
253 | } | ||
254 | |||
255 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev, | ||
256 | |||
257 | if (object_dynamic_cast(OBJECT(dev), TYPE_RISCV_IOMMU_PCI)) { | ||
258 | create_fdt_iommu(s, pci_get_bdf(PCI_DEVICE(dev))); | ||
259 | + s->iommu_sys = ON_OFF_AUTO_OFF; | ||
260 | } | ||
261 | } | ||
262 | |||
263 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_class_init(ObjectClass *oc, void *data) | ||
264 | NULL, NULL); | ||
265 | object_class_property_set_description(oc, "acpi", | ||
266 | "Enable ACPI"); | ||
267 | + | ||
268 | + object_class_property_add(oc, "iommu-sys", "OnOffAuto", | ||
269 | + virt_get_iommu_sys, virt_set_iommu_sys, | ||
270 | + NULL, NULL); | ||
271 | + object_class_property_set_description(oc, "iommu-sys", | ||
272 | + "Enable IOMMU platform device"); | ||
273 | } | ||
274 | |||
275 | static const TypeInfo virt_machine_typeinfo = { | ||
111 | -- | 276 | -- |
112 | 2.28.0 | 277 | 2.47.1 |
113 | |||
114 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | |
2 | |||
3 | MSIx support is added in the RISC-V IOMMU platform device by including | ||
4 | the required MSIx facilities to alow software to properly setup the MSIx | ||
5 | subsystem. | ||
6 | |||
7 | We took inspiration of what is being done in the riscv-iommu-pci device, | ||
8 | mainly msix_init() and msix_notify(), while keeping in mind that | ||
9 | riscv-iommu-sys isn't a true PCI device and we don't need to copy/paste | ||
10 | all the contents of these MSIx functions. | ||
11 | |||
12 | Two extra MSI MemoryRegions were added: 'msix-table' and 'msix-pba'. | ||
13 | They are used to manage r/w of the MSI table and Pending Bit Array (PBA) | ||
14 | respectively. Both are subregions of the main IOMMU memory region, | ||
15 | iommu->regs_mr, initialized during riscv_iommu_realize(), and each one | ||
16 | has their own handlers for MSIx reads and writes. | ||
17 | |||
18 | This is the expected memory map when using this device in the 'virt' | ||
19 | machine: | ||
20 | |||
21 | 0000000003010000-0000000003010fff (prio 0, i/o): riscv-iommu-regs | ||
22 | 0000000003010300-000000000301034f (prio 0, i/o): msix-table | ||
23 | 0000000003010400-0000000003010407 (prio 0, i/o): msix-pba | ||
24 | |||
25 | We're now able to set IGS to RISCV_IOMMU_CAP_IGS_BOTH, and userspace is | ||
26 | free to decide which interrupt model to use. | ||
27 | |||
28 | Enabling MSIx support for this device in the 'virt' machine requires | ||
29 | adding 'msi-parent' in the iommu-sys DT. | ||
30 | |||
31 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
32 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
33 | Message-ID: <20241106133407.604587-6-dbarboza@ventanamicro.com> | ||
34 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
35 | --- | ||
36 | hw/riscv/riscv-iommu-sys.c | 116 +++++++++++++++++++++++++++++++++++-- | ||
37 | hw/riscv/virt.c | 6 +- | ||
38 | hw/riscv/trace-events | 2 + | ||
39 | 3 files changed, 119 insertions(+), 5 deletions(-) | ||
40 | |||
41 | diff --git a/hw/riscv/riscv-iommu-sys.c b/hw/riscv/riscv-iommu-sys.c | ||
42 | index XXXXXXX..XXXXXXX 100644 | ||
43 | --- a/hw/riscv/riscv-iommu-sys.c | ||
44 | +++ b/hw/riscv/riscv-iommu-sys.c | ||
45 | @@ -XXX,XX +XXX,XX @@ | ||
46 | #include "qemu/host-utils.h" | ||
47 | #include "qemu/module.h" | ||
48 | #include "qom/object.h" | ||
49 | +#include "exec/exec-all.h" | ||
50 | +#include "trace.h" | ||
51 | |||
52 | #include "riscv-iommu.h" | ||
53 | |||
54 | #define RISCV_IOMMU_SYSDEV_ICVEC_VECTORS 0x3333 | ||
55 | |||
56 | +#define RISCV_IOMMU_PCI_MSIX_VECTORS 5 | ||
57 | + | ||
58 | /* RISC-V IOMMU System Platform Device Emulation */ | ||
59 | |||
60 | struct RISCVIOMMUStateSys { | ||
61 | @@ -XXX,XX +XXX,XX @@ struct RISCVIOMMUStateSys { | ||
62 | uint32_t base_irq; | ||
63 | DeviceState *irqchip; | ||
64 | RISCVIOMMUState iommu; | ||
65 | + | ||
66 | + /* Wired int support */ | ||
67 | qemu_irq irqs[RISCV_IOMMU_INTR_COUNT]; | ||
68 | + | ||
69 | + /* Memory Regions for MSIX table and pending bit entries. */ | ||
70 | + MemoryRegion msix_table_mmio; | ||
71 | + MemoryRegion msix_pba_mmio; | ||
72 | + uint8_t *msix_table; | ||
73 | + uint8_t *msix_pba; | ||
74 | +}; | ||
75 | + | ||
76 | +static uint64_t msix_table_mmio_read(void *opaque, hwaddr addr, | ||
77 | + unsigned size) | ||
78 | +{ | ||
79 | + RISCVIOMMUStateSys *s = opaque; | ||
80 | + | ||
81 | + g_assert(addr + size <= RISCV_IOMMU_PCI_MSIX_VECTORS * PCI_MSIX_ENTRY_SIZE); | ||
82 | + return pci_get_long(s->msix_table + addr); | ||
83 | +} | ||
84 | + | ||
85 | +static void msix_table_mmio_write(void *opaque, hwaddr addr, | ||
86 | + uint64_t val, unsigned size) | ||
87 | +{ | ||
88 | + RISCVIOMMUStateSys *s = opaque; | ||
89 | + | ||
90 | + g_assert(addr + size <= RISCV_IOMMU_PCI_MSIX_VECTORS * PCI_MSIX_ENTRY_SIZE); | ||
91 | + pci_set_long(s->msix_table + addr, val); | ||
92 | +} | ||
93 | + | ||
94 | +static const MemoryRegionOps msix_table_mmio_ops = { | ||
95 | + .read = msix_table_mmio_read, | ||
96 | + .write = msix_table_mmio_write, | ||
97 | + .endianness = DEVICE_LITTLE_ENDIAN, | ||
98 | + .valid = { | ||
99 | + .min_access_size = 4, | ||
100 | + .max_access_size = 8, | ||
101 | + }, | ||
102 | + .impl = { | ||
103 | + .max_access_size = 4, | ||
104 | + }, | ||
105 | +}; | ||
106 | + | ||
107 | +static uint64_t msix_pba_mmio_read(void *opaque, hwaddr addr, | ||
108 | + unsigned size) | ||
109 | +{ | ||
110 | + RISCVIOMMUStateSys *s = opaque; | ||
111 | + | ||
112 | + return pci_get_long(s->msix_pba + addr); | ||
113 | +} | ||
114 | + | ||
115 | +static void msix_pba_mmio_write(void *opaque, hwaddr addr, | ||
116 | + uint64_t val, unsigned size) | ||
117 | +{ | ||
118 | +} | ||
119 | + | ||
120 | +static const MemoryRegionOps msix_pba_mmio_ops = { | ||
121 | + .read = msix_pba_mmio_read, | ||
122 | + .write = msix_pba_mmio_write, | ||
123 | + .endianness = DEVICE_LITTLE_ENDIAN, | ||
124 | + .valid = { | ||
125 | + .min_access_size = 4, | ||
126 | + .max_access_size = 8, | ||
127 | + }, | ||
128 | + .impl = { | ||
129 | + .max_access_size = 4, | ||
130 | + }, | ||
131 | }; | ||
132 | |||
133 | +static void riscv_iommu_sysdev_init_msi(RISCVIOMMUStateSys *s, | ||
134 | + uint32_t n_vectors) | ||
135 | +{ | ||
136 | + RISCVIOMMUState *iommu = &s->iommu; | ||
137 | + uint32_t table_size = table_size = n_vectors * PCI_MSIX_ENTRY_SIZE; | ||
138 | + uint32_t table_offset = RISCV_IOMMU_REG_MSI_CONFIG; | ||
139 | + uint32_t pba_size = QEMU_ALIGN_UP(n_vectors, 64) / 8; | ||
140 | + uint32_t pba_offset = RISCV_IOMMU_REG_MSI_CONFIG + 256; | ||
141 | + | ||
142 | + s->msix_table = g_malloc0(table_size); | ||
143 | + s->msix_pba = g_malloc0(pba_size); | ||
144 | + | ||
145 | + memory_region_init_io(&s->msix_table_mmio, OBJECT(s), &msix_table_mmio_ops, | ||
146 | + s, "msix-table", table_size); | ||
147 | + memory_region_add_subregion(&iommu->regs_mr, table_offset, | ||
148 | + &s->msix_table_mmio); | ||
149 | + | ||
150 | + memory_region_init_io(&s->msix_pba_mmio, OBJECT(s), &msix_pba_mmio_ops, s, | ||
151 | + "msix-pba", pba_size); | ||
152 | + memory_region_add_subregion(&iommu->regs_mr, pba_offset, | ||
153 | + &s->msix_pba_mmio); | ||
154 | +} | ||
155 | + | ||
156 | +static void riscv_iommu_sysdev_send_MSI(RISCVIOMMUStateSys *s, | ||
157 | + uint32_t vector) | ||
158 | +{ | ||
159 | + uint8_t *table_entry = s->msix_table + vector * PCI_MSIX_ENTRY_SIZE; | ||
160 | + uint64_t msi_addr = pci_get_quad(table_entry + PCI_MSIX_ENTRY_LOWER_ADDR); | ||
161 | + uint32_t msi_data = pci_get_long(table_entry + PCI_MSIX_ENTRY_DATA); | ||
162 | + MemTxResult result; | ||
163 | + | ||
164 | + address_space_stl_le(&address_space_memory, msi_addr, | ||
165 | + msi_data, MEMTXATTRS_UNSPECIFIED, &result); | ||
166 | + trace_riscv_iommu_sys_msi_sent(vector, msi_addr, msi_data, result); | ||
167 | +} | ||
168 | + | ||
169 | static void riscv_iommu_sysdev_notify(RISCVIOMMUState *iommu, | ||
170 | unsigned vector) | ||
171 | { | ||
172 | RISCVIOMMUStateSys *s = container_of(iommu, RISCVIOMMUStateSys, iommu); | ||
173 | uint32_t fctl = riscv_iommu_reg_get32(iommu, RISCV_IOMMU_REG_FCTL); | ||
174 | |||
175 | - /* We do not support MSIs yet */ | ||
176 | - if (!(fctl & RISCV_IOMMU_FCTL_WSI)) { | ||
177 | + if (fctl & RISCV_IOMMU_FCTL_WSI) { | ||
178 | + qemu_irq_pulse(s->irqs[vector]); | ||
179 | + trace_riscv_iommu_sys_irq_sent(vector); | ||
180 | return; | ||
181 | } | ||
182 | |||
183 | - qemu_irq_pulse(s->irqs[vector]); | ||
184 | + riscv_iommu_sysdev_send_MSI(s, vector); | ||
185 | } | ||
186 | |||
187 | static void riscv_iommu_sys_realize(DeviceState *dev, Error **errp) | ||
188 | @@ -XXX,XX +XXX,XX @@ static void riscv_iommu_sys_realize(DeviceState *dev, Error **errp) | ||
189 | irq = qdev_get_gpio_in(s->irqchip, s->base_irq + i); | ||
190 | sysbus_connect_irq(sysdev, i, irq); | ||
191 | } | ||
192 | + | ||
193 | + riscv_iommu_sysdev_init_msi(s, RISCV_IOMMU_PCI_MSIX_VECTORS); | ||
194 | } | ||
195 | |||
196 | static void riscv_iommu_sys_init(Object *obj) | ||
197 | @@ -XXX,XX +XXX,XX @@ static void riscv_iommu_sys_init(Object *obj) | ||
198 | qdev_alias_all_properties(DEVICE(iommu), obj); | ||
199 | |||
200 | iommu->icvec_avail_vectors = RISCV_IOMMU_SYSDEV_ICVEC_VECTORS; | ||
201 | - riscv_iommu_set_cap_igs(iommu, RISCV_IOMMU_CAP_IGS_WSI); | ||
202 | + riscv_iommu_set_cap_igs(iommu, RISCV_IOMMU_CAP_IGS_BOTH); | ||
203 | } | ||
204 | |||
205 | static Property riscv_iommu_sys_properties[] = { | ||
206 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | ||
207 | index XXXXXXX..XXXXXXX 100644 | ||
208 | --- a/hw/riscv/virt.c | ||
209 | +++ b/hw/riscv/virt.c | ||
210 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_virtio_iommu(RISCVVirtState *s, uint16_t bdf) | ||
211 | } | ||
212 | |||
213 | static void create_fdt_iommu_sys(RISCVVirtState *s, uint32_t irq_chip, | ||
214 | + uint32_t msi_phandle, | ||
215 | uint32_t *iommu_sys_phandle) | ||
216 | { | ||
217 | const char comp[] = "riscv,iommu"; | ||
218 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_iommu_sys(RISCVVirtState *s, uint32_t irq_chip, | ||
219 | iommu_irq_map[2], FDT_IRQ_TYPE_EDGE_LOW, | ||
220 | iommu_irq_map[3], FDT_IRQ_TYPE_EDGE_LOW); | ||
221 | |||
222 | + qemu_fdt_setprop_cell(fdt, iommu_node, "msi-parent", msi_phandle); | ||
223 | + | ||
224 | *iommu_sys_phandle = iommu_phandle; | ||
225 | } | ||
226 | |||
227 | @@ -XXX,XX +XXX,XX @@ static void finalize_fdt(RISCVVirtState *s) | ||
228 | create_fdt_virtio(s, virt_memmap, irq_virtio_phandle); | ||
229 | |||
230 | if (virt_is_iommu_sys_enabled(s)) { | ||
231 | - create_fdt_iommu_sys(s, irq_mmio_phandle, &iommu_sys_phandle); | ||
232 | + create_fdt_iommu_sys(s, irq_mmio_phandle, msi_pcie_phandle, | ||
233 | + &iommu_sys_phandle); | ||
234 | } | ||
235 | create_fdt_pcie(s, virt_memmap, irq_pcie_phandle, msi_pcie_phandle, | ||
236 | iommu_sys_phandle); | ||
237 | diff --git a/hw/riscv/trace-events b/hw/riscv/trace-events | ||
238 | index XXXXXXX..XXXXXXX 100644 | ||
239 | --- a/hw/riscv/trace-events | ||
240 | +++ b/hw/riscv/trace-events | ||
241 | @@ -XXX,XX +XXX,XX @@ riscv_iommu_icvec_write(uint32_t orig, uint32_t actual) "ICVEC write: incoming 0 | ||
242 | riscv_iommu_ats(const char *id, unsigned b, unsigned d, unsigned f, uint64_t iova) "%s: translate request %04x:%02x.%u iova: 0x%"PRIx64 | ||
243 | riscv_iommu_ats_inval(const char *id) "%s: dev-iotlb invalidate" | ||
244 | riscv_iommu_ats_prgr(const char *id) "%s: dev-iotlb page request group response" | ||
245 | +riscv_iommu_sys_irq_sent(uint32_t vector) "IRQ sent to vector %u" | ||
246 | +riscv_iommu_sys_msi_sent(uint32_t vector, uint64_t msi_addr, uint32_t msi_data, uint32_t result) "MSI sent to vector %u msi_addr 0x%lx msi_data 0x%x result %u" | ||
247 | -- | ||
248 | 2.47.1 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | Microchip PolarFire SoC has 5 MMUARTs, and the Icicle Kit board | 3 | Add a riscv_iommu_reset() helper in the base emulation code that |
4 | wires 4 of them out. Let's connect all 5 MMUARTs. | 4 | implements the expected reset behavior as defined by the riscv-iommu |
5 | 5 | spec. | |
6 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 6 | |
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 7 | Devices can then use this helper in their own reset callbacks. |
8 | Message-Id: <1598924352-89526-7-git-send-email-bmeng.cn@gmail.com> | 8 | |
9 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
10 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | Message-ID: <20241106133407.604587-7-dbarboza@ventanamicro.com> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 13 | --- |
11 | include/hw/riscv/microchip_pfsoc.h | 20 ++++++++++++++++++++ | 14 | hw/riscv/riscv-iommu.h | 1 + |
12 | hw/riscv/microchip_pfsoc.c | 30 ++++++++++++++++++++++++++++++ | 15 | include/hw/riscv/iommu.h | 6 ++++-- |
13 | hw/riscv/Kconfig | 1 + | 16 | hw/riscv/riscv-iommu-pci.c | 20 ++++++++++++++++++++ |
14 | 3 files changed, 51 insertions(+) | 17 | hw/riscv/riscv-iommu-sys.c | 20 ++++++++++++++++++++ |
15 | 18 | hw/riscv/riscv-iommu.c | 35 +++++++++++++++++++++++++++++++++++ | |
16 | diff --git a/include/hw/riscv/microchip_pfsoc.h b/include/hw/riscv/microchip_pfsoc.h | 19 | hw/riscv/trace-events | 2 ++ |
17 | index XXXXXXX..XXXXXXX 100644 | 20 | 6 files changed, 82 insertions(+), 2 deletions(-) |
18 | --- a/include/hw/riscv/microchip_pfsoc.h | 21 | |
19 | +++ b/include/hw/riscv/microchip_pfsoc.h | 22 | diff --git a/hw/riscv/riscv-iommu.h b/hw/riscv/riscv-iommu.h |
23 | index XXXXXXX..XXXXXXX 100644 | ||
24 | --- a/hw/riscv/riscv-iommu.h | ||
25 | +++ b/hw/riscv/riscv-iommu.h | ||
26 | @@ -XXX,XX +XXX,XX @@ struct RISCVIOMMUState { | ||
27 | void riscv_iommu_pci_setup_iommu(RISCVIOMMUState *iommu, PCIBus *bus, | ||
28 | Error **errp); | ||
29 | void riscv_iommu_set_cap_igs(RISCVIOMMUState *s, riscv_iommu_igs_mode mode); | ||
30 | +void riscv_iommu_reset(RISCVIOMMUState *s); | ||
31 | |||
32 | /* private helpers */ | ||
33 | |||
34 | diff --git a/include/hw/riscv/iommu.h b/include/hw/riscv/iommu.h | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/include/hw/riscv/iommu.h | ||
37 | +++ b/include/hw/riscv/iommu.h | ||
38 | @@ -XXX,XX +XXX,XX @@ typedef struct RISCVIOMMUState RISCVIOMMUState; | ||
39 | typedef struct RISCVIOMMUSpace RISCVIOMMUSpace; | ||
40 | |||
41 | #define TYPE_RISCV_IOMMU_PCI "riscv-iommu-pci" | ||
42 | -OBJECT_DECLARE_SIMPLE_TYPE(RISCVIOMMUStatePci, RISCV_IOMMU_PCI) | ||
43 | +OBJECT_DECLARE_TYPE(RISCVIOMMUStatePci, RISCVIOMMUPciClass, RISCV_IOMMU_PCI) | ||
44 | typedef struct RISCVIOMMUStatePci RISCVIOMMUStatePci; | ||
45 | +typedef struct RISCVIOMMUPciClass RISCVIOMMUPciClass; | ||
46 | |||
47 | #define TYPE_RISCV_IOMMU_SYS "riscv-iommu-device" | ||
48 | -OBJECT_DECLARE_SIMPLE_TYPE(RISCVIOMMUStateSys, RISCV_IOMMU_SYS) | ||
49 | +OBJECT_DECLARE_TYPE(RISCVIOMMUStateSys, RISCVIOMMUSysClass, RISCV_IOMMU_SYS) | ||
50 | typedef struct RISCVIOMMUStateSys RISCVIOMMUStateSys; | ||
51 | +typedef struct RISCVIOMMUSysClass RISCVIOMMUSysClass; | ||
52 | |||
53 | #define FDT_IRQ_TYPE_EDGE_LOW 1 | ||
54 | |||
55 | diff --git a/hw/riscv/riscv-iommu-pci.c b/hw/riscv/riscv-iommu-pci.c | ||
56 | index XXXXXXX..XXXXXXX 100644 | ||
57 | --- a/hw/riscv/riscv-iommu-pci.c | ||
58 | +++ b/hw/riscv/riscv-iommu-pci.c | ||
20 | @@ -XXX,XX +XXX,XX @@ | 59 | @@ -XXX,XX +XXX,XX @@ |
21 | #ifndef HW_MICROCHIP_PFSOC_H | 60 | #include "cpu_bits.h" |
22 | #define HW_MICROCHIP_PFSOC_H | 61 | #include "riscv-iommu.h" |
23 | 62 | #include "riscv-iommu-bits.h" | |
24 | +#include "hw/char/mchp_pfsoc_mmuart.h" | 63 | +#include "trace.h" |
25 | + | 64 | |
26 | typedef struct MicrochipPFSoCState { | 65 | /* RISC-V IOMMU PCI Device Emulation */ |
27 | /*< private >*/ | 66 | #define RISCV_PCI_CLASS_SYSTEM_IOMMU 0x0806 |
28 | DeviceState parent_obj; | 67 | @@ -XXX,XX +XXX,XX @@ typedef struct RISCVIOMMUStatePci { |
29 | @@ -XXX,XX +XXX,XX @@ typedef struct MicrochipPFSoCState { | 68 | RISCVIOMMUState iommu; /* common IOMMU state */ |
30 | RISCVHartArrayState e_cpus; | 69 | } RISCVIOMMUStatePci; |
31 | RISCVHartArrayState u_cpus; | 70 | |
32 | DeviceState *plic; | 71 | +struct RISCVIOMMUPciClass { |
33 | + MchpPfSoCMMUartState *serial0; | 72 | + /*< public >*/ |
34 | + MchpPfSoCMMUartState *serial1; | 73 | + DeviceRealize parent_realize; |
35 | + MchpPfSoCMMUartState *serial2; | 74 | + ResettablePhases parent_phases; |
36 | + MchpPfSoCMMUartState *serial3; | 75 | +}; |
37 | + MchpPfSoCMMUartState *serial4; | 76 | + |
38 | } MicrochipPFSoCState; | 77 | /* interrupt delivery callback */ |
39 | 78 | static void riscv_iommu_pci_notify(RISCVIOMMUState *iommu, unsigned vector) | |
40 | #define TYPE_MICROCHIP_PFSOC "microchip.pfsoc" | 79 | { |
41 | @@ -XXX,XX +XXX,XX @@ enum { | 80 | @@ -XXX,XX +XXX,XX @@ static const Property riscv_iommu_pci_properties[] = { |
42 | MICROCHIP_PFSOC_L2CC, | 81 | DEFINE_PROP_END_OF_LIST(), |
43 | MICROCHIP_PFSOC_L2LIM, | ||
44 | MICROCHIP_PFSOC_PLIC, | ||
45 | + MICROCHIP_PFSOC_MMUART0, | ||
46 | MICROCHIP_PFSOC_SYSREG, | ||
47 | MICROCHIP_PFSOC_MPUCFG, | ||
48 | + MICROCHIP_PFSOC_MMUART1, | ||
49 | + MICROCHIP_PFSOC_MMUART2, | ||
50 | + MICROCHIP_PFSOC_MMUART3, | ||
51 | + MICROCHIP_PFSOC_MMUART4, | ||
52 | MICROCHIP_PFSOC_ENVM_CFG, | ||
53 | MICROCHIP_PFSOC_ENVM_DATA, | ||
54 | MICROCHIP_PFSOC_IOSCB_CFG, | ||
55 | MICROCHIP_PFSOC_DRAM, | ||
56 | }; | 82 | }; |
57 | 83 | ||
58 | +enum { | 84 | +static void riscv_iommu_pci_reset_hold(Object *obj, ResetType type) |
59 | + MICROCHIP_PFSOC_MMUART0_IRQ = 90, | 85 | +{ |
60 | + MICROCHIP_PFSOC_MMUART1_IRQ = 91, | 86 | + RISCVIOMMUStatePci *pci = RISCV_IOMMU_PCI(obj); |
61 | + MICROCHIP_PFSOC_MMUART2_IRQ = 92, | 87 | + RISCVIOMMUState *iommu = &pci->iommu; |
62 | + MICROCHIP_PFSOC_MMUART3_IRQ = 93, | 88 | + |
63 | + MICROCHIP_PFSOC_MMUART4_IRQ = 94, | 89 | + riscv_iommu_reset(iommu); |
90 | + | ||
91 | + trace_riscv_iommu_pci_reset_hold(type); | ||
92 | +} | ||
93 | + | ||
94 | static void riscv_iommu_pci_class_init(ObjectClass *klass, void *data) | ||
95 | { | ||
96 | DeviceClass *dc = DEVICE_CLASS(klass); | ||
97 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); | ||
98 | + ResettableClass *rc = RESETTABLE_CLASS(klass); | ||
99 | + | ||
100 | + rc->phases.hold = riscv_iommu_pci_reset_hold; | ||
101 | |||
102 | k->realize = riscv_iommu_pci_realize; | ||
103 | k->exit = riscv_iommu_pci_exit; | ||
104 | diff --git a/hw/riscv/riscv-iommu-sys.c b/hw/riscv/riscv-iommu-sys.c | ||
105 | index XXXXXXX..XXXXXXX 100644 | ||
106 | --- a/hw/riscv/riscv-iommu-sys.c | ||
107 | +++ b/hw/riscv/riscv-iommu-sys.c | ||
108 | @@ -XXX,XX +XXX,XX @@ struct RISCVIOMMUStateSys { | ||
109 | uint8_t *msix_pba; | ||
110 | }; | ||
111 | |||
112 | +struct RISCVIOMMUSysClass { | ||
113 | + /*< public >*/ | ||
114 | + DeviceRealize parent_realize; | ||
115 | + ResettablePhases parent_phases; | ||
64 | +}; | 116 | +}; |
65 | + | 117 | + |
66 | #define MICROCHIP_PFSOC_MANAGEMENT_CPU_COUNT 1 | 118 | static uint64_t msix_table_mmio_read(void *opaque, hwaddr addr, |
67 | #define MICROCHIP_PFSOC_COMPUTE_CPU_COUNT 4 | 119 | unsigned size) |
68 | 120 | { | |
69 | diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c | 121 | @@ -XXX,XX +XXX,XX @@ static Property riscv_iommu_sys_properties[] = { |
70 | index XXXXXXX..XXXXXXX 100644 | 122 | DEFINE_PROP_END_OF_LIST(), |
71 | --- a/hw/riscv/microchip_pfsoc.c | 123 | }; |
72 | +++ b/hw/riscv/microchip_pfsoc.c | 124 | |
73 | @@ -XXX,XX +XXX,XX @@ | 125 | +static void riscv_iommu_sys_reset_hold(Object *obj, ResetType type) |
74 | * 0) CLINT (Core Level Interruptor) | 126 | +{ |
75 | * 1) PLIC (Platform Level Interrupt Controller) | 127 | + RISCVIOMMUStateSys *sys = RISCV_IOMMU_SYS(obj); |
76 | * 2) eNVM (Embedded Non-Volatile Memory) | 128 | + RISCVIOMMUState *iommu = &sys->iommu; |
77 | + * 3) MMUARTs (Multi-Mode UART) | 129 | + |
78 | * | 130 | + riscv_iommu_reset(iommu); |
79 | * This board currently generates devicetree dynamically that indicates at least | 131 | + |
80 | * two harts and up to five harts. | 132 | + trace_riscv_iommu_sys_reset_hold(type); |
81 | @@ -XXX,XX +XXX,XX @@ | 133 | +} |
82 | #include "hw/irq.h" | 134 | + |
83 | #include "hw/loader.h" | 135 | static void riscv_iommu_sys_class_init(ObjectClass *klass, void *data) |
84 | #include "hw/sysbus.h" | 136 | { |
85 | +#include "chardev/char.h" | 137 | DeviceClass *dc = DEVICE_CLASS(klass); |
86 | #include "hw/cpu/cluster.h" | 138 | + ResettableClass *rc = RESETTABLE_CLASS(klass); |
87 | #include "target/riscv/cpu.h" | 139 | + |
88 | #include "hw/misc/unimp.h" | 140 | + rc->phases.hold = riscv_iommu_sys_reset_hold; |
89 | @@ -XXX,XX +XXX,XX @@ | 141 | + |
90 | #include "hw/riscv/sifive_clint.h" | 142 | dc->realize = riscv_iommu_sys_realize; |
91 | #include "hw/riscv/sifive_plic.h" | 143 | set_bit(DEVICE_CATEGORY_MISC, dc->categories); |
92 | #include "hw/riscv/microchip_pfsoc.h" | 144 | device_class_set_props(dc, riscv_iommu_sys_properties); |
93 | +#include "sysemu/sysemu.h" | 145 | diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c |
94 | 146 | index XXXXXXX..XXXXXXX 100644 | |
95 | /* | 147 | --- a/hw/riscv/riscv-iommu.c |
96 | * The BIOS image used by this machine is called Hart Software Services (HSS). | 148 | +++ b/hw/riscv/riscv-iommu.c |
97 | @@ -XXX,XX +XXX,XX @@ static const struct MemmapEntry { | 149 | @@ -XXX,XX +XXX,XX @@ static void riscv_iommu_unrealize(DeviceState *dev) |
98 | [MICROCHIP_PFSOC_L2CC] = { 0x2010000, 0x1000 }, | 150 | g_hash_table_unref(s->ctx_cache); |
99 | [MICROCHIP_PFSOC_L2LIM] = { 0x8000000, 0x2000000 }, | 151 | } |
100 | [MICROCHIP_PFSOC_PLIC] = { 0xc000000, 0x4000000 }, | 152 | |
101 | + [MICROCHIP_PFSOC_MMUART0] = { 0x20000000, 0x1000 }, | 153 | +void riscv_iommu_reset(RISCVIOMMUState *s) |
102 | [MICROCHIP_PFSOC_SYSREG] = { 0x20002000, 0x2000 }, | 154 | +{ |
103 | [MICROCHIP_PFSOC_MPUCFG] = { 0x20005000, 0x1000 }, | 155 | + uint32_t reg_clr; |
104 | + [MICROCHIP_PFSOC_MMUART1] = { 0x20100000, 0x1000 }, | 156 | + int ddtp_mode; |
105 | + [MICROCHIP_PFSOC_MMUART2] = { 0x20102000, 0x1000 }, | 157 | + |
106 | + [MICROCHIP_PFSOC_MMUART3] = { 0x20104000, 0x1000 }, | 158 | + /* |
107 | + [MICROCHIP_PFSOC_MMUART4] = { 0x20106000, 0x1000 }, | 159 | + * Clear DDTP while setting DDTP_mode back to user |
108 | [MICROCHIP_PFSOC_ENVM_CFG] = { 0x20200000, 0x1000 }, | 160 | + * initial setting. |
109 | [MICROCHIP_PFSOC_ENVM_DATA] = { 0x20220000, 0x20000 }, | 161 | + */ |
110 | [MICROCHIP_PFSOC_IOSCB_CFG] = { 0x37080000, 0x1000 }, | 162 | + ddtp_mode = s->enable_off ? |
111 | @@ -XXX,XX +XXX,XX @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp) | 163 | + RISCV_IOMMU_DDTP_MODE_OFF : RISCV_IOMMU_DDTP_MODE_BARE; |
112 | memmap[MICROCHIP_PFSOC_MPUCFG].base, | 164 | + s->ddtp = set_field(0, RISCV_IOMMU_DDTP_MODE, ddtp_mode); |
113 | memmap[MICROCHIP_PFSOC_MPUCFG].size); | 165 | + riscv_iommu_reg_set64(s, RISCV_IOMMU_REG_DDTP, s->ddtp); |
114 | 166 | + | |
115 | + /* MMUARTs */ | 167 | + reg_clr = RISCV_IOMMU_CQCSR_CQEN | RISCV_IOMMU_CQCSR_CIE | |
116 | + s->serial0 = mchp_pfsoc_mmuart_create(system_memory, | 168 | + RISCV_IOMMU_CQCSR_CQON | RISCV_IOMMU_CQCSR_BUSY; |
117 | + memmap[MICROCHIP_PFSOC_MMUART0].base, | 169 | + riscv_iommu_reg_mod32(s, RISCV_IOMMU_REG_CQCSR, 0, reg_clr); |
118 | + qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_MMUART0_IRQ), | 170 | + |
119 | + serial_hd(0)); | 171 | + reg_clr = RISCV_IOMMU_FQCSR_FQEN | RISCV_IOMMU_FQCSR_FIE | |
120 | + s->serial1 = mchp_pfsoc_mmuart_create(system_memory, | 172 | + RISCV_IOMMU_FQCSR_FQON | RISCV_IOMMU_FQCSR_BUSY; |
121 | + memmap[MICROCHIP_PFSOC_MMUART1].base, | 173 | + riscv_iommu_reg_mod32(s, RISCV_IOMMU_REG_FQCSR, 0, reg_clr); |
122 | + qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_MMUART1_IRQ), | 174 | + |
123 | + serial_hd(1)); | 175 | + reg_clr = RISCV_IOMMU_PQCSR_PQEN | RISCV_IOMMU_PQCSR_PIE | |
124 | + s->serial2 = mchp_pfsoc_mmuart_create(system_memory, | 176 | + RISCV_IOMMU_PQCSR_PQON | RISCV_IOMMU_PQCSR_BUSY; |
125 | + memmap[MICROCHIP_PFSOC_MMUART2].base, | 177 | + riscv_iommu_reg_mod32(s, RISCV_IOMMU_REG_PQCSR, 0, reg_clr); |
126 | + qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_MMUART2_IRQ), | 178 | + |
127 | + serial_hd(2)); | 179 | + riscv_iommu_reg_mod64(s, RISCV_IOMMU_REG_TR_REQ_CTL, 0, |
128 | + s->serial3 = mchp_pfsoc_mmuart_create(system_memory, | 180 | + RISCV_IOMMU_TR_REQ_CTL_GO_BUSY); |
129 | + memmap[MICROCHIP_PFSOC_MMUART3].base, | 181 | + |
130 | + qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_MMUART3_IRQ), | 182 | + riscv_iommu_reg_set32(s, RISCV_IOMMU_REG_IPSR, 0); |
131 | + serial_hd(3)); | 183 | + |
132 | + s->serial4 = mchp_pfsoc_mmuart_create(system_memory, | 184 | + g_hash_table_remove_all(s->ctx_cache); |
133 | + memmap[MICROCHIP_PFSOC_MMUART4].base, | 185 | + g_hash_table_remove_all(s->iot_cache); |
134 | + qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_MMUART4_IRQ), | 186 | +} |
135 | + serial_hd(4)); | 187 | + |
136 | + | 188 | static const Property riscv_iommu_properties[] = { |
137 | /* eNVM */ | 189 | DEFINE_PROP_UINT32("version", RISCVIOMMUState, version, |
138 | memory_region_init_rom(envm_data, OBJECT(dev), "microchip.pfsoc.envm.data", | 190 | RISCV_IOMMU_SPEC_DOT_VER), |
139 | memmap[MICROCHIP_PFSOC_ENVM_DATA].size, | 191 | diff --git a/hw/riscv/trace-events b/hw/riscv/trace-events |
140 | diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig | 192 | index XXXXXXX..XXXXXXX 100644 |
141 | index XXXXXXX..XXXXXXX 100644 | 193 | --- a/hw/riscv/trace-events |
142 | --- a/hw/riscv/Kconfig | 194 | +++ b/hw/riscv/trace-events |
143 | +++ b/hw/riscv/Kconfig | 195 | @@ -XXX,XX +XXX,XX @@ riscv_iommu_ats_inval(const char *id) "%s: dev-iotlb invalidate" |
144 | @@ -XXX,XX +XXX,XX @@ config MICROCHIP_PFSOC | 196 | riscv_iommu_ats_prgr(const char *id) "%s: dev-iotlb page request group response" |
145 | select HART | 197 | riscv_iommu_sys_irq_sent(uint32_t vector) "IRQ sent to vector %u" |
146 | select SIFIVE | 198 | riscv_iommu_sys_msi_sent(uint32_t vector, uint64_t msi_addr, uint32_t msi_data, uint32_t result) "MSI sent to vector %u msi_addr 0x%lx msi_data 0x%x result %u" |
147 | select UNIMP | 199 | +riscv_iommu_sys_reset_hold(int reset_type) "reset type %d" |
148 | + select MCHP_PFSOC_MMUART | 200 | +riscv_iommu_pci_reset_hold(int reset_type) "reset type %d" |
149 | -- | 201 | -- |
150 | 2.28.0 | 202 | 2.47.1 |
151 | |||
152 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
4 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
5 | Message-ID: <20241106133407.604587-8-dbarboza@ventanamicro.com> | ||
6 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
7 | --- | ||
8 | docs/specs/riscv-iommu.rst | 30 +++++++++++++++++++++++++++--- | ||
9 | docs/system/riscv/virt.rst | 10 ++++++++++ | ||
10 | 2 files changed, 37 insertions(+), 3 deletions(-) | ||
11 | |||
12 | diff --git a/docs/specs/riscv-iommu.rst b/docs/specs/riscv-iommu.rst | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/docs/specs/riscv-iommu.rst | ||
15 | +++ b/docs/specs/riscv-iommu.rst | ||
16 | @@ -XXX,XX +XXX,XX @@ RISC-V IOMMU support for RISC-V machines | ||
17 | QEMU implements a RISC-V IOMMU emulation based on the RISC-V IOMMU spec | ||
18 | version 1.0 `iommu1.0`_. | ||
19 | |||
20 | -The emulation includes a PCI reference device, riscv-iommu-pci, that QEMU | ||
21 | -RISC-V boards can use. The 'virt' RISC-V machine is compatible with this | ||
22 | -device. | ||
23 | +The emulation includes a PCI reference device (riscv-iommu-pci) and a platform | ||
24 | +bus device (riscv-iommu-sys) that QEMU RISC-V boards can use. The 'virt' | ||
25 | +RISC-V machine is compatible with both devices. | ||
26 | |||
27 | riscv-iommu-pci reference device | ||
28 | -------------------------------- | ||
29 | @@ -XXX,XX +XXX,XX @@ Several options are available to control the capabilities of the device, namely: | ||
30 | - "s-stage": enable s-stage support | ||
31 | - "g-stage": enable g-stage support | ||
32 | |||
33 | +riscv-iommu-sys device | ||
34 | +---------------------- | ||
35 | + | ||
36 | +This device implements the RISC-V IOMMU emulation as a platform bus device that | ||
37 | +RISC-V boards can use. | ||
38 | + | ||
39 | +For the 'virt' board the device is disabled by default. To enable it use the | ||
40 | +'iommu-sys' machine option: | ||
41 | + | ||
42 | +.. code-block:: bash | ||
43 | + | ||
44 | + $ qemu-system-riscv64 -M virt,iommu-sys=on (...) | ||
45 | + | ||
46 | +There is no options to configure the capabilities of this device in the 'virt' | ||
47 | +board using the QEMU command line. The device is configured with the following | ||
48 | +riscv-iommu options: | ||
49 | + | ||
50 | +- "ioatc-limit": default value (2Mb) | ||
51 | +- "intremap": enabled | ||
52 | +- "ats": enabled | ||
53 | +- "off": on (DMA disabled) | ||
54 | +- "s-stage": enabled | ||
55 | +- "g-stage": enabled | ||
56 | + | ||
57 | .. _iommu1.0: https://github.com/riscv-non-isa/riscv-iommu/releases/download/v1.0/riscv-iommu.pdf | ||
58 | |||
59 | .. _linux-v8: https://lore.kernel.org/linux-riscv/cover.1718388908.git.tjeznach@rivosinc.com/ | ||
60 | diff --git a/docs/system/riscv/virt.rst b/docs/system/riscv/virt.rst | ||
61 | index XXXXXXX..XXXXXXX 100644 | ||
62 | --- a/docs/system/riscv/virt.rst | ||
63 | +++ b/docs/system/riscv/virt.rst | ||
64 | @@ -XXX,XX +XXX,XX @@ command line: | ||
65 | |||
66 | $ qemu-system-riscv64 -M virt -device riscv-iommu-pci (...) | ||
67 | |||
68 | +It also has support for the riscv-iommu-sys platform device: | ||
69 | + | ||
70 | +.. code-block:: bash | ||
71 | + | ||
72 | + $ qemu-system-riscv64 -M virt,iommu-sys=on (...) | ||
73 | + | ||
74 | Refer to :ref:`riscv-iommu` for more information on how the RISC-V IOMMU support | ||
75 | works. | ||
76 | |||
77 | @@ -XXX,XX +XXX,XX @@ The following machine-specific options are supported: | ||
78 | having AIA IMSIC (i.e. "aia=aplic-imsic" selected). When not specified, | ||
79 | the default number of per-HART VS-level AIA IMSIC pages is 0. | ||
80 | |||
81 | +- iommu-sys=[on|off] | ||
82 | + | ||
83 | + Enables the riscv-iommu-sys platform device. Defaults to 'off'. | ||
84 | + | ||
85 | Running Linux kernel | ||
86 | -------------------- | ||
87 | |||
88 | -- | ||
89 | 2.47.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Anton Blanchard <antonb@tenstorrent.com> | ||
1 | 2 | ||
3 | Add a CPU entry for the Tenstorrent Ascalon CPU, a series of 2 wide to | ||
4 | 8 wide RV64 cores. More details can be found at | ||
5 | https://tenstorrent.com/ip/tt-ascalon | ||
6 | |||
7 | Signed-off-by: Anton Blanchard <antonb@tenstorrent.com> | ||
8 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
10 | Message-ID: <20241113110459.1607299-1-antonb@tenstorrent.com> | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | --- | ||
13 | target/riscv/cpu-qom.h | 1 + | ||
14 | target/riscv/cpu.c | 67 ++++++++++++++++++++++++++++++++++++++++++ | ||
15 | 2 files changed, 68 insertions(+) | ||
16 | |||
17 | diff --git a/target/riscv/cpu-qom.h b/target/riscv/cpu-qom.h | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/target/riscv/cpu-qom.h | ||
20 | +++ b/target/riscv/cpu-qom.h | ||
21 | @@ -XXX,XX +XXX,XX @@ | ||
22 | #define TYPE_RISCV_CPU_SIFIVE_U54 RISCV_CPU_TYPE_NAME("sifive-u54") | ||
23 | #define TYPE_RISCV_CPU_THEAD_C906 RISCV_CPU_TYPE_NAME("thead-c906") | ||
24 | #define TYPE_RISCV_CPU_VEYRON_V1 RISCV_CPU_TYPE_NAME("veyron-v1") | ||
25 | +#define TYPE_RISCV_CPU_TT_ASCALON RISCV_CPU_TYPE_NAME("tt-ascalon") | ||
26 | #define TYPE_RISCV_CPU_HOST RISCV_CPU_TYPE_NAME("host") | ||
27 | |||
28 | OBJECT_DECLARE_CPU_TYPE(RISCVCPU, RISCVCPUClass, RISCV_CPU) | ||
29 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/target/riscv/cpu.c | ||
32 | +++ b/target/riscv/cpu.c | ||
33 | @@ -XXX,XX +XXX,XX @@ static void rv64_veyron_v1_cpu_init(Object *obj) | ||
34 | #endif | ||
35 | } | ||
36 | |||
37 | +/* Tenstorrent Ascalon */ | ||
38 | +static void rv64_tt_ascalon_cpu_init(Object *obj) | ||
39 | +{ | ||
40 | + CPURISCVState *env = &RISCV_CPU(obj)->env; | ||
41 | + RISCVCPU *cpu = RISCV_CPU(obj); | ||
42 | + | ||
43 | + riscv_cpu_set_misa_ext(env, RVG | RVC | RVS | RVU | RVH | RVV); | ||
44 | + env->priv_ver = PRIV_VERSION_1_13_0; | ||
45 | + | ||
46 | + /* Enable ISA extensions */ | ||
47 | + cpu->cfg.mmu = true; | ||
48 | + cpu->cfg.vlenb = 256 >> 3; | ||
49 | + cpu->cfg.elen = 64; | ||
50 | + cpu->env.vext_ver = VEXT_VERSION_1_00_0; | ||
51 | + cpu->cfg.rvv_ma_all_1s = true; | ||
52 | + cpu->cfg.rvv_ta_all_1s = true; | ||
53 | + cpu->cfg.misa_w = true; | ||
54 | + cpu->cfg.pmp = true; | ||
55 | + cpu->cfg.cbom_blocksize = 64; | ||
56 | + cpu->cfg.cbop_blocksize = 64; | ||
57 | + cpu->cfg.cboz_blocksize = 64; | ||
58 | + cpu->cfg.ext_zic64b = true; | ||
59 | + cpu->cfg.ext_zicbom = true; | ||
60 | + cpu->cfg.ext_zicbop = true; | ||
61 | + cpu->cfg.ext_zicboz = true; | ||
62 | + cpu->cfg.ext_zicntr = true; | ||
63 | + cpu->cfg.ext_zicond = true; | ||
64 | + cpu->cfg.ext_zicsr = true; | ||
65 | + cpu->cfg.ext_zifencei = true; | ||
66 | + cpu->cfg.ext_zihintntl = true; | ||
67 | + cpu->cfg.ext_zihintpause = true; | ||
68 | + cpu->cfg.ext_zihpm = true; | ||
69 | + cpu->cfg.ext_zimop = true; | ||
70 | + cpu->cfg.ext_zawrs = true; | ||
71 | + cpu->cfg.ext_zfa = true; | ||
72 | + cpu->cfg.ext_zfbfmin = true; | ||
73 | + cpu->cfg.ext_zfh = true; | ||
74 | + cpu->cfg.ext_zfhmin = true; | ||
75 | + cpu->cfg.ext_zcb = true; | ||
76 | + cpu->cfg.ext_zcmop = true; | ||
77 | + cpu->cfg.ext_zba = true; | ||
78 | + cpu->cfg.ext_zbb = true; | ||
79 | + cpu->cfg.ext_zbs = true; | ||
80 | + cpu->cfg.ext_zkt = true; | ||
81 | + cpu->cfg.ext_zvbb = true; | ||
82 | + cpu->cfg.ext_zvbc = true; | ||
83 | + cpu->cfg.ext_zvfbfmin = true; | ||
84 | + cpu->cfg.ext_zvfbfwma = true; | ||
85 | + cpu->cfg.ext_zvfh = true; | ||
86 | + cpu->cfg.ext_zvfhmin = true; | ||
87 | + cpu->cfg.ext_zvkng = true; | ||
88 | + cpu->cfg.ext_smaia = true; | ||
89 | + cpu->cfg.ext_smstateen = true; | ||
90 | + cpu->cfg.ext_ssaia = true; | ||
91 | + cpu->cfg.ext_sscofpmf = true; | ||
92 | + cpu->cfg.ext_sstc = true; | ||
93 | + cpu->cfg.ext_svade = true; | ||
94 | + cpu->cfg.ext_svinval = true; | ||
95 | + cpu->cfg.ext_svnapot = true; | ||
96 | + cpu->cfg.ext_svpbmt = true; | ||
97 | + | ||
98 | +#ifndef CONFIG_USER_ONLY | ||
99 | + set_satp_mode_max_supported(cpu, VM_1_10_SV57); | ||
100 | +#endif | ||
101 | +} | ||
102 | + | ||
103 | #ifdef CONFIG_TCG | ||
104 | static void rv128_base_cpu_init(Object *obj) | ||
105 | { | ||
106 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo riscv_cpu_type_infos[] = { | ||
107 | DEFINE_VENDOR_CPU(TYPE_RISCV_CPU_SIFIVE_U54, MXL_RV64, rv64_sifive_u_cpu_init), | ||
108 | DEFINE_VENDOR_CPU(TYPE_RISCV_CPU_SHAKTI_C, MXL_RV64, rv64_sifive_u_cpu_init), | ||
109 | DEFINE_VENDOR_CPU(TYPE_RISCV_CPU_THEAD_C906, MXL_RV64, rv64_thead_c906_cpu_init), | ||
110 | + DEFINE_VENDOR_CPU(TYPE_RISCV_CPU_TT_ASCALON, MXL_RV64, rv64_tt_ascalon_cpu_init), | ||
111 | DEFINE_VENDOR_CPU(TYPE_RISCV_CPU_VEYRON_V1, MXL_RV64, rv64_veyron_v1_cpu_init), | ||
112 | #ifdef CONFIG_TCG | ||
113 | DEFINE_DYNAMIC_CPU(TYPE_RISCV_CPU_BASE128, MXL_RV128, rv128_base_cpu_init), | ||
114 | -- | ||
115 | 2.47.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | The helper is_kvm_aia() is checking not only for AIA, but for | ||
4 | aplic-imsic (i.e. "aia=aplic-imsic" in 'virt' RISC-V machine) with an | ||
5 | in-kernel chip present. | ||
6 | |||
7 | Rename it to be a bit clear what the helper is doing since we'll add | ||
8 | more AIA helpers in the next patches. | ||
9 | |||
10 | Make the helper public because the 'virt' machine will use it as well. | ||
11 | |||
12 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
14 | Message-ID: <20241119191706.718860-2-dbarboza@ventanamicro.com> | ||
15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
16 | --- | ||
17 | include/hw/intc/riscv_aplic.h | 1 + | ||
18 | hw/intc/riscv_aplic.c | 8 ++++---- | ||
19 | 2 files changed, 5 insertions(+), 4 deletions(-) | ||
20 | |||
21 | diff --git a/include/hw/intc/riscv_aplic.h b/include/hw/intc/riscv_aplic.h | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/include/hw/intc/riscv_aplic.h | ||
24 | +++ b/include/hw/intc/riscv_aplic.h | ||
25 | @@ -XXX,XX +XXX,XX @@ struct RISCVAPLICState { | ||
26 | }; | ||
27 | |||
28 | void riscv_aplic_add_child(DeviceState *parent, DeviceState *child); | ||
29 | +bool riscv_is_kvm_aia_aplic_imsic(bool msimode); | ||
30 | |||
31 | DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, | ||
32 | uint32_t hartid_base, uint32_t num_harts, uint32_t num_sources, | ||
33 | diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c | ||
34 | index XXXXXXX..XXXXXXX 100644 | ||
35 | --- a/hw/intc/riscv_aplic.c | ||
36 | +++ b/hw/intc/riscv_aplic.c | ||
37 | @@ -XXX,XX +XXX,XX @@ | ||
38 | * KVM AIA only supports APLIC MSI, fallback to QEMU emulation if we want to use | ||
39 | * APLIC Wired. | ||
40 | */ | ||
41 | -static bool is_kvm_aia(bool msimode) | ||
42 | +bool riscv_is_kvm_aia_aplic_imsic(bool msimode) | ||
43 | { | ||
44 | return kvm_irqchip_in_kernel() && msimode; | ||
45 | } | ||
46 | @@ -XXX,XX +XXX,XX @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp) | ||
47 | uint32_t i; | ||
48 | RISCVAPLICState *aplic = RISCV_APLIC(dev); | ||
49 | |||
50 | - if (!is_kvm_aia(aplic->msimode)) { | ||
51 | + if (!riscv_is_kvm_aia_aplic_imsic(aplic->msimode)) { | ||
52 | aplic->bitfield_words = (aplic->num_irqs + 31) >> 5; | ||
53 | aplic->sourcecfg = g_new0(uint32_t, aplic->num_irqs); | ||
54 | aplic->state = g_new0(uint32_t, aplic->num_irqs); | ||
55 | @@ -XXX,XX +XXX,XX @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp) | ||
56 | * have IRQ lines delegated by their parent APLIC. | ||
57 | */ | ||
58 | if (!aplic->parent) { | ||
59 | - if (kvm_enabled() && is_kvm_aia(aplic->msimode)) { | ||
60 | + if (kvm_enabled() && riscv_is_kvm_aia_aplic_imsic(aplic->msimode)) { | ||
61 | qdev_init_gpio_in(dev, riscv_kvm_aplic_request, aplic->num_irqs); | ||
62 | } else { | ||
63 | qdev_init_gpio_in(dev, riscv_aplic_request, aplic->num_irqs); | ||
64 | @@ -XXX,XX +XXX,XX @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, | ||
65 | |||
66 | sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); | ||
67 | |||
68 | - if (!is_kvm_aia(msimode)) { | ||
69 | + if (!riscv_is_kvm_aia_aplic_imsic(msimode)) { | ||
70 | sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); | ||
71 | } | ||
72 | |||
73 | -- | ||
74 | 2.47.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | In create_fdt_sockets() we have the following pattern: | ||
4 | |||
5 | if (kvm_enabled() && virt_use_kvm_aia(s)) { | ||
6 | (... do stuff ...) | ||
7 | } else { | ||
8 | (... do other stuff ...) | ||
9 | } | ||
10 | if (kvm_enabled() && virt_use_kvm_aia(s)) { | ||
11 | (... do more stuff ...) | ||
12 | } else { | ||
13 | (... do more other stuff) | ||
14 | } | ||
15 | |||
16 | Do everything in a single if/else clause to reduce the usage of | ||
17 | virt_use_kvm_aia() helper and to make the code a bit less repetitive. | ||
18 | |||
19 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
20 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
21 | Message-ID: <20241119191706.718860-3-dbarboza@ventanamicro.com> | ||
22 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
23 | --- | ||
24 | hw/riscv/virt.c | 10 ++++------ | ||
25 | 1 file changed, 4 insertions(+), 6 deletions(-) | ||
26 | |||
27 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | ||
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/hw/riscv/virt.c | ||
30 | +++ b/hw/riscv/virt.c | ||
31 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, | ||
32 | msi_m_phandle, msi_s_phandle, phandle, | ||
33 | &intc_phandles[0], xplic_phandles, | ||
34 | ms->smp.cpus); | ||
35 | + | ||
36 | + *irq_mmio_phandle = xplic_phandles[0]; | ||
37 | + *irq_virtio_phandle = xplic_phandles[0]; | ||
38 | + *irq_pcie_phandle = xplic_phandles[0]; | ||
39 | } else { | ||
40 | phandle_pos = ms->smp.cpus; | ||
41 | for (socket = (socket_count - 1); socket >= 0; socket--) { | ||
42 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, | ||
43 | s->soc[socket].num_harts); | ||
44 | } | ||
45 | } | ||
46 | - } | ||
47 | |||
48 | - if (kvm_enabled() && virt_use_kvm_aia(s)) { | ||
49 | - *irq_mmio_phandle = xplic_phandles[0]; | ||
50 | - *irq_virtio_phandle = xplic_phandles[0]; | ||
51 | - *irq_pcie_phandle = xplic_phandles[0]; | ||
52 | - } else { | ||
53 | for (socket = 0; socket < socket_count; socket++) { | ||
54 | if (socket == 0) { | ||
55 | *irq_mmio_phandle = xplic_phandles[socket]; | ||
56 | -- | ||
57 | 2.47.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | Similar to the riscv_is_kvm_aia_aplic_imsic() helper from riscv_aplic.c, | ||
4 | the existing virt_use_kvm_aia() is testing for KVM aia=aplic-imsic with | ||
5 | in-kernel irqchip enabled. It is not checking for a generic AIA support. | ||
6 | |||
7 | Rename the helper to virt_use_kvm_aia_aplic_imsic() to reflect what the | ||
8 | helper is doing, and use the existing riscv_is_kvm_aia_aplic_imsic() to | ||
9 | obscure details such as the presence of the in-kernel irqchip. | ||
10 | |||
11 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | Message-ID: <20241119191706.718860-4-dbarboza@ventanamicro.com> | ||
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
15 | --- | ||
16 | hw/riscv/virt.c | 12 +++++++----- | ||
17 | 1 file changed, 7 insertions(+), 5 deletions(-) | ||
18 | |||
19 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/hw/riscv/virt.c | ||
22 | +++ b/hw/riscv/virt.c | ||
23 | @@ -XXX,XX +XXX,XX @@ | ||
24 | #include "hw/virtio/virtio-iommu.h" | ||
25 | |||
26 | /* KVM AIA only supports APLIC MSI. APLIC Wired is always emulated by QEMU. */ | ||
27 | -static bool virt_use_kvm_aia(RISCVVirtState *s) | ||
28 | +static bool virt_use_kvm_aia_aplic_imsic(RISCVVirtAIAType aia_type) | ||
29 | { | ||
30 | - return kvm_irqchip_in_kernel() && s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC; | ||
31 | + bool msimode = aia_type == VIRT_AIA_TYPE_APLIC_IMSIC; | ||
32 | + | ||
33 | + return riscv_is_kvm_aia_aplic_imsic(msimode); | ||
34 | } | ||
35 | |||
36 | static bool virt_aclint_allowed(void) | ||
37 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, | ||
38 | *msi_pcie_phandle = msi_s_phandle; | ||
39 | } | ||
40 | |||
41 | - /* KVM AIA only has one APLIC instance */ | ||
42 | - if (kvm_enabled() && virt_use_kvm_aia(s)) { | ||
43 | + /* KVM AIA aplic-imsic only has one APLIC instance */ | ||
44 | + if (kvm_enabled() && virt_use_kvm_aia_aplic_imsic(s->aia_type)) { | ||
45 | create_fdt_socket_aplic(s, memmap, 0, | ||
46 | msi_m_phandle, msi_s_phandle, phandle, | ||
47 | &intc_phandles[0], xplic_phandles, | ||
48 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine) | ||
49 | } | ||
50 | } | ||
51 | |||
52 | - if (kvm_enabled() && virt_use_kvm_aia(s)) { | ||
53 | + if (kvm_enabled() && virt_use_kvm_aia_aplic_imsic(s->aia_type)) { | ||
54 | kvm_riscv_aia_create(machine, IMSIC_MMIO_GROUP_MIN_SHIFT, | ||
55 | VIRT_IRQCHIP_NUM_SOURCES, VIRT_IRQCHIP_NUM_MSIS, | ||
56 | memmap[VIRT_APLIC_S].base, | ||
57 | -- | ||
58 | 2.47.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | Before adding support to kernel-irqchip=split when using KVM AIA we need | ||
4 | to change how we create the in-kernel AIA device. | ||
5 | |||
6 | In the use case we have so far, i.e. in-kernel irqchip without split | ||
7 | mode, both the s-mode APLIC and IMSIC controllers are provided by the | ||
8 | irqchip. In irqchip_split() mode we'll emulate the s-mode APLIC | ||
9 | controller, which will send MSIs to the in-kernel IMSIC controller. To | ||
10 | do that we need to change kvm_riscv_aia_create() to not create the | ||
11 | in-kernel s-mode APLIC controller. | ||
12 | |||
13 | In the kernel source arch/riscv/kvm/aia_aplic.c, function | ||
14 | kvm_riscv_aia_aplic_init(), we verify that the APLIC controller won't be | ||
15 | instantiated by KVM if we do not set 'nr_sources', which is set via | ||
16 | KVM_DEV_RISCV_AIA_CONFIG_SRCS. For QEMU this means that we should not | ||
17 | set 'aia_irq_num' during kvm_riscv_aia_create() in irqchip_split() mode. | ||
18 | |||
19 | In this same condition, skip KVM_DEV_RISCV_AIA_ADDR_APLIC as well since | ||
20 | it is used to set the base address for the in-kernel APLIC controller. | ||
21 | |||
22 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
23 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
24 | Message-ID: <20241119191706.718860-5-dbarboza@ventanamicro.com> | ||
25 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
26 | --- | ||
27 | target/riscv/kvm/kvm-cpu.c | 38 +++++++++++++++++++++++--------------- | ||
28 | 1 file changed, 23 insertions(+), 15 deletions(-) | ||
29 | |||
30 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/target/riscv/kvm/kvm-cpu.c | ||
33 | +++ b/target/riscv/kvm/kvm-cpu.c | ||
34 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, | ||
35 | } | ||
36 | } | ||
37 | |||
38 | - ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG, | ||
39 | - KVM_DEV_RISCV_AIA_CONFIG_SRCS, | ||
40 | - &aia_irq_num, true, NULL); | ||
41 | - if (ret < 0) { | ||
42 | - error_report("KVM AIA: failed to set number of input irq lines"); | ||
43 | - exit(1); | ||
44 | - } | ||
45 | + /* | ||
46 | + * Skip APLIC creation in KVM if we're running split mode. | ||
47 | + * This is done by leaving KVM_DEV_RISCV_AIA_CONFIG_SRCS | ||
48 | + * unset. We can also skip KVM_DEV_RISCV_AIA_ADDR_APLIC | ||
49 | + * since KVM won't be using it. | ||
50 | + */ | ||
51 | + if (!kvm_kernel_irqchip_split()) { | ||
52 | + ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG, | ||
53 | + KVM_DEV_RISCV_AIA_CONFIG_SRCS, | ||
54 | + &aia_irq_num, true, NULL); | ||
55 | + if (ret < 0) { | ||
56 | + error_report("KVM AIA: failed to set number of input irq lines"); | ||
57 | + exit(1); | ||
58 | + } | ||
59 | + | ||
60 | + ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_ADDR, | ||
61 | + KVM_DEV_RISCV_AIA_ADDR_APLIC, | ||
62 | + &aplic_base, true, NULL); | ||
63 | + if (ret < 0) { | ||
64 | + error_report("KVM AIA: failed to set the base address of APLIC"); | ||
65 | + exit(1); | ||
66 | + } | ||
67 | + } | ||
68 | |||
69 | ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG, | ||
70 | KVM_DEV_RISCV_AIA_CONFIG_IDS, | ||
71 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, | ||
72 | exit(1); | ||
73 | } | ||
74 | |||
75 | - ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_ADDR, | ||
76 | - KVM_DEV_RISCV_AIA_ADDR_APLIC, | ||
77 | - &aplic_base, true, NULL); | ||
78 | - if (ret < 0) { | ||
79 | - error_report("KVM AIA: failed to set the base address of APLIC"); | ||
80 | - exit(1); | ||
81 | - } | ||
82 | - | ||
83 | for (socket = 0; socket < socket_count; socket++) { | ||
84 | socket_imsic_base = imsic_base + socket * (1U << group_shift); | ||
85 | hart_count = riscv_socket_hart_count(machine, socket); | ||
86 | -- | ||
87 | 2.47.1 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | This is an effort to clean up the hw/riscv directory. Ideally it | 3 | The current logic to determine if we don't need an emulated APLIC |
4 | should only contain the RISC-V SoC / machine codes plus generic | 4 | controller, i.e. KVM will provide for us, is to determine if we're |
5 | codes. Let's move sifive_plic model to hw/intc directory. | 5 | running KVM, with in-kernel irqchip support, and running |
6 | aia=aplic-imsic. This is modelled by riscv_is_kvm_aia_aplic_imsic() and | ||
7 | virt_use_kvm_aia_aplic_imsic(). | ||
6 | 8 | ||
7 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 9 | This won't suffice to support irqchip_split() mode: it will match |
10 | exactly the same conditions as the one above, but setting the irqchip to | ||
11 | 'split' mode will now require us to emulate an APLIC s-mode controller, | ||
12 | like we're doing with 'aia=aplic'. | ||
13 | |||
14 | Create a new riscv_use_emulated_aplic() helper that will encapsulate | ||
15 | this logic. Replace the uses of "riscv_is_kvm_aia_aplic_imsic()" with | ||
16 | this helper every time we're taking a decision on emulate an APLIC | ||
17 | controller or not. Do the same in virt.c with virt_use_emulated_aplic(). | ||
18 | |||
19 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 20 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Message-Id: <1599129623-68957-7-git-send-email-bmeng.cn@gmail.com> | 21 | Message-ID: <20241119191706.718860-6-dbarboza@ventanamicro.com> |
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 22 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 23 | --- |
12 | {include/hw/riscv => hw/intc}/sifive_plic.h | 0 | 24 | include/hw/intc/riscv_aplic.h | 1 + |
13 | hw/{riscv => intc}/sifive_plic.c | 2 +- | 25 | hw/intc/riscv_aplic.c | 24 +++++++++++++++++++++--- |
14 | hw/riscv/microchip_pfsoc.c | 2 +- | 26 | hw/riscv/virt.c | 14 ++++++++++++-- |
15 | hw/riscv/sifive_e.c | 2 +- | 27 | 3 files changed, 34 insertions(+), 5 deletions(-) |
16 | hw/riscv/sifive_u.c | 2 +- | ||
17 | hw/riscv/virt.c | 2 +- | ||
18 | hw/intc/Kconfig | 3 +++ | ||
19 | hw/intc/meson.build | 1 + | ||
20 | hw/riscv/Kconfig | 5 +++++ | ||
21 | hw/riscv/meson.build | 1 - | ||
22 | 10 files changed, 14 insertions(+), 6 deletions(-) | ||
23 | rename {include/hw/riscv => hw/intc}/sifive_plic.h (100%) | ||
24 | rename hw/{riscv => intc}/sifive_plic.c (99%) | ||
25 | 28 | ||
26 | diff --git a/include/hw/riscv/sifive_plic.h b/hw/intc/sifive_plic.h | 29 | diff --git a/include/hw/intc/riscv_aplic.h b/include/hw/intc/riscv_aplic.h |
27 | similarity index 100% | ||
28 | rename from include/hw/riscv/sifive_plic.h | ||
29 | rename to hw/intc/sifive_plic.h | ||
30 | diff --git a/hw/riscv/sifive_plic.c b/hw/intc/sifive_plic.c | ||
31 | similarity index 99% | ||
32 | rename from hw/riscv/sifive_plic.c | ||
33 | rename to hw/intc/sifive_plic.c | ||
34 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
35 | --- a/hw/riscv/sifive_plic.c | 31 | --- a/include/hw/intc/riscv_aplic.h |
36 | +++ b/hw/intc/sifive_plic.c | 32 | +++ b/include/hw/intc/riscv_aplic.h |
33 | @@ -XXX,XX +XXX,XX @@ struct RISCVAPLICState { | ||
34 | |||
35 | void riscv_aplic_add_child(DeviceState *parent, DeviceState *child); | ||
36 | bool riscv_is_kvm_aia_aplic_imsic(bool msimode); | ||
37 | +bool riscv_use_emulated_aplic(bool msimode); | ||
38 | |||
39 | DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, | ||
40 | uint32_t hartid_base, uint32_t num_harts, uint32_t num_sources, | ||
41 | diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c | ||
42 | index XXXXXXX..XXXXXXX 100644 | ||
43 | --- a/hw/intc/riscv_aplic.c | ||
44 | +++ b/hw/intc/riscv_aplic.c | ||
37 | @@ -XXX,XX +XXX,XX @@ | 45 | @@ -XXX,XX +XXX,XX @@ |
38 | #include "hw/pci/msi.h" | ||
39 | #include "hw/boards.h" | ||
40 | #include "hw/qdev-properties.h" | ||
41 | +#include "hw/intc/sifive_plic.h" | ||
42 | #include "target/riscv/cpu.h" | 46 | #include "target/riscv/cpu.h" |
43 | #include "sysemu/sysemu.h" | 47 | #include "sysemu/sysemu.h" |
44 | -#include "hw/riscv/sifive_plic.h" | 48 | #include "sysemu/kvm.h" |
45 | 49 | +#include "sysemu/tcg.h" | |
46 | #define RISCV_DEBUG_PLIC 0 | 50 | #include "kvm/kvm_riscv.h" |
47 | 51 | #include "migration/vmstate.h" | |
48 | diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c | 52 | |
49 | index XXXXXXX..XXXXXXX 100644 | 53 | @@ -XXX,XX +XXX,XX @@ bool riscv_is_kvm_aia_aplic_imsic(bool msimode) |
50 | --- a/hw/riscv/microchip_pfsoc.c | 54 | return kvm_irqchip_in_kernel() && msimode; |
51 | +++ b/hw/riscv/microchip_pfsoc.c | 55 | } |
52 | @@ -XXX,XX +XXX,XX @@ | 56 | |
53 | #include "hw/misc/unimp.h" | 57 | +bool riscv_use_emulated_aplic(bool msimode) |
54 | #include "hw/riscv/boot.h" | 58 | +{ |
55 | #include "hw/riscv/riscv_hart.h" | 59 | +#ifdef CONFIG_KVM |
56 | -#include "hw/riscv/sifive_plic.h" | 60 | + if (tcg_enabled()) { |
57 | #include "hw/riscv/microchip_pfsoc.h" | 61 | + return true; |
58 | #include "hw/intc/sifive_clint.h" | 62 | + } |
59 | +#include "hw/intc/sifive_plic.h" | 63 | + |
60 | #include "sysemu/sysemu.h" | 64 | + if (!riscv_is_kvm_aia_aplic_imsic(msimode)) { |
61 | 65 | + return true; | |
62 | /* | 66 | + } |
63 | diff --git a/hw/riscv/sifive_e.c b/hw/riscv/sifive_e.c | 67 | + |
64 | index XXXXXXX..XXXXXXX 100644 | 68 | + return kvm_kernel_irqchip_split(); |
65 | --- a/hw/riscv/sifive_e.c | 69 | +#else |
66 | +++ b/hw/riscv/sifive_e.c | 70 | + return true; |
67 | @@ -XXX,XX +XXX,XX @@ | 71 | +#endif |
68 | #include "hw/misc/unimp.h" | 72 | +} |
69 | #include "target/riscv/cpu.h" | 73 | + |
70 | #include "hw/riscv/riscv_hart.h" | 74 | static bool riscv_aplic_irq_rectified_val(RISCVAPLICState *aplic, |
71 | -#include "hw/riscv/sifive_plic.h" | 75 | uint32_t irq) |
72 | #include "hw/riscv/sifive_uart.h" | 76 | { |
73 | #include "hw/riscv/sifive_e.h" | 77 | @@ -XXX,XX +XXX,XX @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp) |
74 | #include "hw/riscv/boot.h" | 78 | uint32_t i; |
75 | #include "hw/intc/sifive_clint.h" | 79 | RISCVAPLICState *aplic = RISCV_APLIC(dev); |
76 | +#include "hw/intc/sifive_plic.h" | 80 | |
77 | #include "hw/misc/sifive_e_prci.h" | 81 | - if (!riscv_is_kvm_aia_aplic_imsic(aplic->msimode)) { |
78 | #include "chardev/char.h" | 82 | + if (riscv_use_emulated_aplic(aplic->msimode)) { |
79 | #include "sysemu/arch_init.h" | 83 | aplic->bitfield_words = (aplic->num_irqs + 31) >> 5; |
80 | diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c | 84 | aplic->sourcecfg = g_new0(uint32_t, aplic->num_irqs); |
81 | index XXXXXXX..XXXXXXX 100644 | 85 | aplic->state = g_new0(uint32_t, aplic->num_irqs); |
82 | --- a/hw/riscv/sifive_u.c | 86 | @@ -XXX,XX +XXX,XX @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp) |
83 | +++ b/hw/riscv/sifive_u.c | 87 | * have IRQ lines delegated by their parent APLIC. |
84 | @@ -XXX,XX +XXX,XX @@ | 88 | */ |
85 | #include "hw/misc/unimp.h" | 89 | if (!aplic->parent) { |
86 | #include "target/riscv/cpu.h" | 90 | - if (kvm_enabled() && riscv_is_kvm_aia_aplic_imsic(aplic->msimode)) { |
87 | #include "hw/riscv/riscv_hart.h" | 91 | + if (kvm_enabled() && !riscv_use_emulated_aplic(aplic->msimode)) { |
88 | -#include "hw/riscv/sifive_plic.h" | 92 | qdev_init_gpio_in(dev, riscv_kvm_aplic_request, aplic->num_irqs); |
89 | #include "hw/riscv/sifive_uart.h" | 93 | } else { |
90 | #include "hw/riscv/sifive_u.h" | 94 | qdev_init_gpio_in(dev, riscv_aplic_request, aplic->num_irqs); |
91 | #include "hw/riscv/boot.h" | 95 | @@ -XXX,XX +XXX,XX @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, |
92 | #include "hw/intc/sifive_clint.h" | 96 | |
93 | +#include "hw/intc/sifive_plic.h" | 97 | sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); |
94 | #include "chardev/char.h" | 98 | |
95 | #include "net/eth.h" | 99 | - if (!riscv_is_kvm_aia_aplic_imsic(msimode)) { |
96 | #include "sysemu/arch_init.h" | 100 | + if (riscv_use_emulated_aplic(msimode)) { |
101 | sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); | ||
102 | } | ||
103 | |||
97 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | 104 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c |
98 | index XXXXXXX..XXXXXXX 100644 | 105 | index XXXXXXX..XXXXXXX 100644 |
99 | --- a/hw/riscv/virt.c | 106 | --- a/hw/riscv/virt.c |
100 | +++ b/hw/riscv/virt.c | 107 | +++ b/hw/riscv/virt.c |
101 | @@ -XXX,XX +XXX,XX @@ | 108 | @@ -XXX,XX +XXX,XX @@ static bool virt_use_kvm_aia_aplic_imsic(RISCVVirtAIAType aia_type) |
102 | #include "hw/char/serial.h" | 109 | return riscv_is_kvm_aia_aplic_imsic(msimode); |
103 | #include "target/riscv/cpu.h" | 110 | } |
104 | #include "hw/riscv/riscv_hart.h" | 111 | |
105 | -#include "hw/riscv/sifive_plic.h" | 112 | +static bool virt_use_emulated_aplic(RISCVVirtAIAType aia_type) |
106 | #include "hw/riscv/sifive_test.h" | 113 | +{ |
107 | #include "hw/riscv/virt.h" | 114 | + bool msimode = aia_type == VIRT_AIA_TYPE_APLIC_IMSIC; |
108 | #include "hw/riscv/boot.h" | ||
109 | #include "hw/riscv/numa.h" | ||
110 | #include "hw/intc/sifive_clint.h" | ||
111 | +#include "hw/intc/sifive_plic.h" | ||
112 | #include "chardev/char.h" | ||
113 | #include "sysemu/arch_init.h" | ||
114 | #include "sysemu/device_tree.h" | ||
115 | diff --git a/hw/intc/Kconfig b/hw/intc/Kconfig | ||
116 | index XXXXXXX..XXXXXXX 100644 | ||
117 | --- a/hw/intc/Kconfig | ||
118 | +++ b/hw/intc/Kconfig | ||
119 | @@ -XXX,XX +XXX,XX @@ config LOONGSON_LIOINTC | ||
120 | |||
121 | config SIFIVE_CLINT | ||
122 | bool | ||
123 | + | 115 | + |
124 | +config SIFIVE_PLIC | 116 | + return riscv_use_emulated_aplic(msimode); |
125 | + bool | 117 | +} |
126 | diff --git a/hw/intc/meson.build b/hw/intc/meson.build | 118 | + |
127 | index XXXXXXX..XXXXXXX 100644 | 119 | static bool virt_aclint_allowed(void) |
128 | --- a/hw/intc/meson.build | 120 | { |
129 | +++ b/hw/intc/meson.build | 121 | return tcg_enabled() || qtest_enabled(); |
130 | @@ -XXX,XX +XXX,XX @@ specific_ss.add(when: 'CONFIG_S390_FLIC', if_true: files('s390_flic.c')) | 122 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, |
131 | specific_ss.add(when: 'CONFIG_S390_FLIC_KVM', if_true: files('s390_flic_kvm.c')) | 123 | *msi_pcie_phandle = msi_s_phandle; |
132 | specific_ss.add(when: 'CONFIG_SH4', if_true: files('sh_intc.c')) | 124 | } |
133 | specific_ss.add(when: 'CONFIG_SIFIVE_CLINT', if_true: files('sifive_clint.c')) | 125 | |
134 | +specific_ss.add(when: 'CONFIG_SIFIVE_PLIC', if_true: files('sifive_plic.c')) | 126 | - /* KVM AIA aplic-imsic only has one APLIC instance */ |
135 | specific_ss.add(when: 'CONFIG_XICS', if_true: files('xics.c')) | 127 | - if (kvm_enabled() && virt_use_kvm_aia_aplic_imsic(s->aia_type)) { |
136 | specific_ss.add(when: 'CONFIG_XICS_KVM', if_true: files('xics_kvm.c')) | 128 | + /* |
137 | specific_ss.add(when: 'CONFIG_XICS_SPAPR', if_true: files('xics_spapr.c')) | 129 | + * With KVM AIA aplic-imsic, using an irqchip without split |
138 | diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig | 130 | + * mode, we'll use only one APLIC instance. |
139 | index XXXXXXX..XXXXXXX 100644 | 131 | + */ |
140 | --- a/hw/riscv/Kconfig | 132 | + if (!virt_use_emulated_aplic(s->aia_type)) { |
141 | +++ b/hw/riscv/Kconfig | 133 | create_fdt_socket_aplic(s, memmap, 0, |
142 | @@ -XXX,XX +XXX,XX @@ config SIFIVE_E | 134 | msi_m_phandle, msi_s_phandle, phandle, |
143 | select SIFIVE | 135 | &intc_phandles[0], xplic_phandles, |
144 | select SIFIVE_CLINT | ||
145 | select SIFIVE_GPIO | ||
146 | + select SIFIVE_PLIC | ||
147 | select SIFIVE_E_PRCI | ||
148 | select UNIMP | ||
149 | |||
150 | @@ -XXX,XX +XXX,XX @@ config SIFIVE_U | ||
151 | select SIFIVE_CLINT | ||
152 | select SIFIVE_GPIO | ||
153 | select SIFIVE_PDMA | ||
154 | + select SIFIVE_PLIC | ||
155 | select SIFIVE_U_OTP | ||
156 | select SIFIVE_U_PRCI | ||
157 | select UNIMP | ||
158 | @@ -XXX,XX +XXX,XX @@ config SPIKE | ||
159 | select HTIF | ||
160 | select SIFIVE | ||
161 | select SIFIVE_CLINT | ||
162 | + select SIFIVE_PLIC | ||
163 | |||
164 | config OPENTITAN | ||
165 | bool | ||
166 | @@ -XXX,XX +XXX,XX @@ config RISCV_VIRT | ||
167 | select PFLASH_CFI01 | ||
168 | select SIFIVE | ||
169 | select SIFIVE_CLINT | ||
170 | + select SIFIVE_PLIC | ||
171 | |||
172 | config MICROCHIP_PFSOC | ||
173 | bool | ||
174 | @@ -XXX,XX +XXX,XX @@ config MICROCHIP_PFSOC | ||
175 | select UNIMP | ||
176 | select MCHP_PFSOC_MMUART | ||
177 | select SIFIVE_PDMA | ||
178 | + select SIFIVE_PLIC | ||
179 | select CADENCE_SDHCI | ||
180 | diff --git a/hw/riscv/meson.build b/hw/riscv/meson.build | ||
181 | index XXXXXXX..XXXXXXX 100644 | ||
182 | --- a/hw/riscv/meson.build | ||
183 | +++ b/hw/riscv/meson.build | ||
184 | @@ -XXX,XX +XXX,XX @@ riscv_ss.add(files('numa.c')) | ||
185 | riscv_ss.add(when: 'CONFIG_HART', if_true: files('riscv_hart.c')) | ||
186 | riscv_ss.add(when: 'CONFIG_OPENTITAN', if_true: files('opentitan.c')) | ||
187 | riscv_ss.add(when: 'CONFIG_RISCV_VIRT', if_true: files('virt.c')) | ||
188 | -riscv_ss.add(when: 'CONFIG_SIFIVE', if_true: files('sifive_plic.c')) | ||
189 | riscv_ss.add(when: 'CONFIG_SIFIVE', if_true: files('sifive_test.c')) | ||
190 | riscv_ss.add(when: 'CONFIG_SIFIVE', if_true: files('sifive_uart.c')) | ||
191 | riscv_ss.add(when: 'CONFIG_SIFIVE_E', if_true: files('sifive_e.c')) | ||
192 | -- | 136 | -- |
193 | 2.28.0 | 137 | 2.47.1 |
194 | |||
195 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | On the Icicle Kit board, the HSS firmware utilizes the on-chip DMA | 3 | The last step to enable KVM AIA aplic-imsic with irqchip in split mode |
4 | controller to move the 2nd stage bootloader in the system memory. | 4 | is to deal with how MSIs are going to be sent. In our current design we |
5 | Let's connect a DMA controller to Microchip PolarFire SoC. | 5 | don't allow an APLIC controller to send MSIs unless it's on m-mode. And |
6 | we also do not allow Supervisor MSI address configuration via the | ||
7 | 'smsiaddrcfg' and 'smsiaddrcfgh' registers unless it's also a m-mode | ||
8 | APLIC controller. | ||
6 | 9 | ||
7 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 10 | Add a new RISCVACPLICState attribute called 'kvm_msicfgaddr'. This |
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 11 | attribute represents the base configuration address for MSIs, in our |
9 | Message-Id: <1598924352-89526-11-git-send-email-bmeng.cn@gmail.com> | 12 | case the base addr of the IMSIC controller. This attribute is being set |
13 | only when running irqchip_split() mode with aia=aplic-imsic. | ||
14 | |||
15 | During riscv_aplic_msi_send() we'll check if the attribute was set to | ||
16 | skip the check for a m-mode APLIC controller and to change the resulting | ||
17 | MSI addr by adding kvm_msicfgaddr right before address_space_stl_le(). | ||
18 | |||
19 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
20 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
21 | Message-ID: <20241119191706.718860-7-dbarboza@ventanamicro.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 22 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 23 | --- |
12 | include/hw/riscv/microchip_pfsoc.h | 11 +++++++++++ | 24 | include/hw/intc/riscv_aplic.h | 6 +++++ |
13 | hw/riscv/microchip_pfsoc.c | 15 +++++++++++++++ | 25 | hw/intc/riscv_aplic.c | 42 +++++++++++++++++++++++++++-------- |
14 | hw/riscv/Kconfig | 1 + | 26 | hw/riscv/virt.c | 6 ++++- |
15 | 3 files changed, 27 insertions(+) | 27 | 3 files changed, 44 insertions(+), 10 deletions(-) |
16 | 28 | ||
17 | diff --git a/include/hw/riscv/microchip_pfsoc.h b/include/hw/riscv/microchip_pfsoc.h | 29 | diff --git a/include/hw/intc/riscv_aplic.h b/include/hw/intc/riscv_aplic.h |
18 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/include/hw/riscv/microchip_pfsoc.h | 31 | --- a/include/hw/intc/riscv_aplic.h |
20 | +++ b/include/hw/riscv/microchip_pfsoc.h | 32 | +++ b/include/hw/intc/riscv_aplic.h |
21 | @@ -XXX,XX +XXX,XX @@ | 33 | @@ -XXX,XX +XXX,XX @@ struct RISCVAPLICState { |
22 | #define HW_MICROCHIP_PFSOC_H | 34 | uint32_t num_irqs; |
23 | 35 | bool msimode; | |
24 | #include "hw/char/mchp_pfsoc_mmuart.h" | 36 | bool mmode; |
25 | +#include "hw/dma/sifive_pdma.h" | 37 | + |
26 | #include "hw/sd/cadence_sdhci.h" | 38 | + /* To support KVM aia=aplic-imsic with irqchip split mode */ |
27 | 39 | + bool kvm_splitmode; | |
28 | typedef struct MicrochipPFSoCState { | 40 | + uint32_t kvm_msicfgaddr; |
29 | @@ -XXX,XX +XXX,XX @@ typedef struct MicrochipPFSoCState { | 41 | + uint32_t kvm_msicfgaddrH; |
30 | MchpPfSoCMMUartState *serial2; | ||
31 | MchpPfSoCMMUartState *serial3; | ||
32 | MchpPfSoCMMUartState *serial4; | ||
33 | + SiFivePDMAState dma; | ||
34 | CadenceSDHCIState sdhci; | ||
35 | } MicrochipPFSoCState; | ||
36 | |||
37 | @@ -XXX,XX +XXX,XX @@ enum { | ||
38 | MICROCHIP_PFSOC_BUSERR_UNIT4, | ||
39 | MICROCHIP_PFSOC_CLINT, | ||
40 | MICROCHIP_PFSOC_L2CC, | ||
41 | + MICROCHIP_PFSOC_DMA, | ||
42 | MICROCHIP_PFSOC_L2LIM, | ||
43 | MICROCHIP_PFSOC_PLIC, | ||
44 | MICROCHIP_PFSOC_MMUART0, | ||
45 | @@ -XXX,XX +XXX,XX @@ enum { | ||
46 | }; | 42 | }; |
47 | 43 | ||
48 | enum { | 44 | void riscv_aplic_add_child(DeviceState *parent, DeviceState *child); |
49 | + MICROCHIP_PFSOC_DMA_IRQ0 = 5, | 45 | bool riscv_is_kvm_aia_aplic_imsic(bool msimode); |
50 | + MICROCHIP_PFSOC_DMA_IRQ1 = 6, | 46 | bool riscv_use_emulated_aplic(bool msimode); |
51 | + MICROCHIP_PFSOC_DMA_IRQ2 = 7, | 47 | +void riscv_aplic_set_kvm_msicfgaddr(RISCVAPLICState *aplic, hwaddr addr); |
52 | + MICROCHIP_PFSOC_DMA_IRQ3 = 8, | 48 | |
53 | + MICROCHIP_PFSOC_DMA_IRQ4 = 9, | 49 | DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, |
54 | + MICROCHIP_PFSOC_DMA_IRQ5 = 10, | 50 | uint32_t hartid_base, uint32_t num_harts, uint32_t num_sources, |
55 | + MICROCHIP_PFSOC_DMA_IRQ6 = 11, | 51 | diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c |
56 | + MICROCHIP_PFSOC_DMA_IRQ7 = 12, | ||
57 | MICROCHIP_PFSOC_EMMC_SD_IRQ = 88, | ||
58 | MICROCHIP_PFSOC_MMUART0_IRQ = 90, | ||
59 | MICROCHIP_PFSOC_MMUART1_IRQ = 91, | ||
60 | diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c | ||
61 | index XXXXXXX..XXXXXXX 100644 | 52 | index XXXXXXX..XXXXXXX 100644 |
62 | --- a/hw/riscv/microchip_pfsoc.c | 53 | --- a/hw/intc/riscv_aplic.c |
63 | +++ b/hw/riscv/microchip_pfsoc.c | 54 | +++ b/hw/intc/riscv_aplic.c |
64 | @@ -XXX,XX +XXX,XX @@ | 55 | @@ -XXX,XX +XXX,XX @@ bool riscv_use_emulated_aplic(bool msimode) |
65 | * 2) eNVM (Embedded Non-Volatile Memory) | 56 | #endif |
66 | * 3) MMUARTs (Multi-Mode UART) | 57 | } |
67 | * 4) Cadence eMMC/SDHC controller and an SD card connected to it | 58 | |
68 | + * 5) SiFive Platform DMA (Direct Memory Access Controller) | 59 | +void riscv_aplic_set_kvm_msicfgaddr(RISCVAPLICState *aplic, hwaddr addr) |
69 | * | 60 | +{ |
70 | * This board currently generates devicetree dynamically that indicates at least | 61 | +#ifdef CONFIG_KVM |
71 | * two harts and up to five harts. | 62 | + if (riscv_use_emulated_aplic(aplic->msimode)) { |
72 | @@ -XXX,XX +XXX,XX @@ static const struct MemmapEntry { | 63 | + aplic->kvm_msicfgaddr = extract64(addr, 0, 32); |
73 | [MICROCHIP_PFSOC_BUSERR_UNIT4] = { 0x1704000, 0x1000 }, | 64 | + aplic->kvm_msicfgaddrH = extract64(addr, 32, 32); |
74 | [MICROCHIP_PFSOC_CLINT] = { 0x2000000, 0x10000 }, | 65 | + } |
75 | [MICROCHIP_PFSOC_L2CC] = { 0x2010000, 0x1000 }, | 66 | +#endif |
76 | + [MICROCHIP_PFSOC_DMA] = { 0x3000000, 0x100000 }, | 67 | +} |
77 | [MICROCHIP_PFSOC_L2LIM] = { 0x8000000, 0x2000000 }, | ||
78 | [MICROCHIP_PFSOC_PLIC] = { 0xc000000, 0x4000000 }, | ||
79 | [MICROCHIP_PFSOC_MMUART0] = { 0x20000000, 0x1000 }, | ||
80 | @@ -XXX,XX +XXX,XX @@ static void microchip_pfsoc_soc_instance_init(Object *obj) | ||
81 | TYPE_RISCV_CPU_SIFIVE_U54); | ||
82 | qdev_prop_set_uint64(DEVICE(&s->u_cpus), "resetvec", RESET_VECTOR); | ||
83 | |||
84 | + object_initialize_child(obj, "dma-controller", &s->dma, | ||
85 | + TYPE_SIFIVE_PDMA); | ||
86 | + | 68 | + |
87 | object_initialize_child(obj, "sd-controller", &s->sdhci, | 69 | static bool riscv_aplic_irq_rectified_val(RISCVAPLICState *aplic, |
88 | TYPE_CADENCE_SDHCI); | 70 | uint32_t irq) |
89 | } | 71 | { |
90 | @@ -XXX,XX +XXX,XX @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp) | 72 | @@ -XXX,XX +XXX,XX @@ static void riscv_aplic_msi_send(RISCVAPLICState *aplic, |
91 | memmap[MICROCHIP_PFSOC_PLIC].size); | 73 | uint32_t lhxs, lhxw, hhxs, hhxw, group_idx, msicfgaddr, msicfgaddrH; |
92 | g_free(plic_hart_config); | 74 | |
93 | 75 | aplic_m = aplic; | |
94 | + /* DMA */ | 76 | - while (aplic_m && !aplic_m->mmode) { |
95 | + sysbus_realize(SYS_BUS_DEVICE(&s->dma), errp); | 77 | - aplic_m = aplic_m->parent; |
96 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->dma), 0, | 78 | - } |
97 | + memmap[MICROCHIP_PFSOC_DMA].base); | 79 | - if (!aplic_m) { |
98 | + for (i = 0; i < SIFIVE_PDMA_IRQS; i++) { | 80 | - qemu_log_mask(LOG_GUEST_ERROR, "%s: m-level APLIC not found\n", |
99 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->dma), i, | 81 | - __func__); |
100 | + qdev_get_gpio_in(DEVICE(s->plic), | 82 | - return; |
101 | + MICROCHIP_PFSOC_DMA_IRQ0 + i)); | 83 | + |
84 | + if (!aplic->kvm_splitmode) { | ||
85 | + while (aplic_m && !aplic_m->mmode) { | ||
86 | + aplic_m = aplic_m->parent; | ||
87 | + } | ||
88 | + if (!aplic_m) { | ||
89 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: m-level APLIC not found\n", | ||
90 | + __func__); | ||
91 | + return; | ||
92 | + } | ||
93 | } | ||
94 | |||
95 | if (aplic->mmode) { | ||
96 | @@ -XXX,XX +XXX,XX @@ static void riscv_aplic_msi_send(RISCVAPLICState *aplic, | ||
97 | addr |= (uint64_t)(guest_idx & APLIC_xMSICFGADDR_PPN_HART(lhxs)); | ||
98 | addr <<= APLIC_xMSICFGADDR_PPN_SHIFT; | ||
99 | |||
100 | + if (aplic->kvm_splitmode) { | ||
101 | + addr |= aplic->kvm_msicfgaddr; | ||
102 | + addr |= ((uint64_t)aplic->kvm_msicfgaddrH << 32); | ||
102 | + } | 103 | + } |
103 | + | 104 | + |
104 | /* SYSREG */ | 105 | address_space_stl_le(&address_space_memory, addr, |
105 | create_unimplemented_device("microchip.pfsoc.sysreg", | 106 | eiid, MEMTXATTRS_UNSPECIFIED, &result); |
106 | memmap[MICROCHIP_PFSOC_SYSREG].base, | 107 | if (result != MEMTX_OK) { |
107 | diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig | 108 | @@ -XXX,XX +XXX,XX @@ static void riscv_aplic_realize(DeviceState *dev, Error **errp) |
109 | memory_region_init_io(&aplic->mmio, OBJECT(dev), &riscv_aplic_ops, | ||
110 | aplic, TYPE_RISCV_APLIC, aplic->aperture_size); | ||
111 | sysbus_init_mmio(SYS_BUS_DEVICE(dev), &aplic->mmio); | ||
112 | + | ||
113 | + if (kvm_enabled()) { | ||
114 | + aplic->kvm_splitmode = true; | ||
115 | + } | ||
116 | } | ||
117 | |||
118 | /* | ||
119 | @@ -XXX,XX +XXX,XX @@ static const Property riscv_aplic_properties[] = { | ||
120 | |||
121 | static const VMStateDescription vmstate_riscv_aplic = { | ||
122 | .name = "riscv_aplic", | ||
123 | - .version_id = 1, | ||
124 | - .minimum_version_id = 1, | ||
125 | + .version_id = 2, | ||
126 | + .minimum_version_id = 2, | ||
127 | .fields = (const VMStateField[]) { | ||
128 | VMSTATE_UINT32(domaincfg, RISCVAPLICState), | ||
129 | VMSTATE_UINT32(mmsicfgaddr, RISCVAPLICState), | ||
130 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_riscv_aplic = { | ||
131 | VMSTATE_UINT32(smsicfgaddr, RISCVAPLICState), | ||
132 | VMSTATE_UINT32(smsicfgaddrH, RISCVAPLICState), | ||
133 | VMSTATE_UINT32(genmsi, RISCVAPLICState), | ||
134 | + VMSTATE_UINT32(kvm_msicfgaddr, RISCVAPLICState), | ||
135 | + VMSTATE_UINT32(kvm_msicfgaddrH, RISCVAPLICState), | ||
136 | VMSTATE_VARRAY_UINT32(sourcecfg, RISCVAPLICState, | ||
137 | num_irqs, 0, | ||
138 | vmstate_info_uint32, uint32_t), | ||
139 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | ||
108 | index XXXXXXX..XXXXXXX 100644 | 140 | index XXXXXXX..XXXXXXX 100644 |
109 | --- a/hw/riscv/Kconfig | 141 | --- a/hw/riscv/virt.c |
110 | +++ b/hw/riscv/Kconfig | 142 | +++ b/hw/riscv/virt.c |
111 | @@ -XXX,XX +XXX,XX @@ config MICROCHIP_PFSOC | 143 | @@ -XXX,XX +XXX,XX @@ static DeviceState *virt_create_aia(RISCVVirtAIAType aia_type, int aia_guests, |
112 | select SIFIVE | 144 | int base_hartid, int hart_count) |
113 | select UNIMP | 145 | { |
114 | select MCHP_PFSOC_MMUART | 146 | int i; |
115 | + select SIFIVE_PDMA | 147 | - hwaddr addr; |
116 | select CADENCE_SDHCI | 148 | + hwaddr addr = 0; |
149 | uint32_t guest_bits; | ||
150 | DeviceState *aplic_s = NULL; | ||
151 | DeviceState *aplic_m = NULL; | ||
152 | @@ -XXX,XX +XXX,XX @@ static DeviceState *virt_create_aia(RISCVVirtAIAType aia_type, int aia_guests, | ||
153 | VIRT_IRQCHIP_NUM_PRIO_BITS, | ||
154 | msimode, false, aplic_m); | ||
155 | |||
156 | + if (kvm_enabled() && msimode) { | ||
157 | + riscv_aplic_set_kvm_msicfgaddr(RISCV_APLIC(aplic_s), addr); | ||
158 | + } | ||
159 | + | ||
160 | return kvm_enabled() ? aplic_s : aplic_m; | ||
161 | } | ||
162 | |||
117 | -- | 163 | -- |
118 | 2.28.0 | 164 | 2.47.1 |
119 | |||
120 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | At present the Kconfig file is in disorder. Let's sort the options. | 3 | Remove the 'irqchip_split()' restriction in kvm_arch_init() now that |
4 | we have support for "-accel kvm,kernel-irqchip=split". | ||
4 | 5 | ||
5 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 6 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
6 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
7 | Message-Id: <1599129623-68957-13-git-send-email-bmeng.cn@gmail.com> | 8 | Message-ID: <20241119191706.718860-8-dbarboza@ventanamicro.com> |
8 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
9 | --- | 10 | --- |
10 | hw/riscv/Kconfig | 58 ++++++++++++++++++++++++------------------------ | 11 | target/riscv/kvm/kvm-cpu.c | 5 ----- |
11 | 1 file changed, 29 insertions(+), 29 deletions(-) | 12 | 1 file changed, 5 deletions(-) |
12 | 13 | ||
13 | diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig | 14 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c |
14 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/hw/riscv/Kconfig | 16 | --- a/target/riscv/kvm/kvm-cpu.c |
16 | +++ b/hw/riscv/Kconfig | 17 | +++ b/target/riscv/kvm/kvm-cpu.c |
17 | @@ -XXX,XX +XXX,XX @@ | 18 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_init(MachineState *ms, KVMState *s) |
18 | config IBEX | 19 | |
19 | bool | 20 | int kvm_arch_irqchip_create(KVMState *s) |
20 | 21 | { | |
21 | -config SIFIVE_E | 22 | - if (kvm_kernel_irqchip_split()) { |
22 | - bool | 23 | - error_report("-machine kernel_irqchip=split is not supported on RISC-V."); |
23 | - select MSI_NONBROKEN | 24 | - exit(1); |
24 | - select SIFIVE_CLINT | 25 | - } |
25 | - select SIFIVE_GPIO | ||
26 | - select SIFIVE_PLIC | ||
27 | - select SIFIVE_UART | ||
28 | - select SIFIVE_E_PRCI | ||
29 | - select UNIMP | ||
30 | - | 26 | - |
31 | -config SIFIVE_U | 27 | /* |
32 | +config MICROCHIP_PFSOC | 28 | * We can create the VAIA using the newer device control API. |
33 | bool | 29 | */ |
34 | - select CADENCE | ||
35 | + select CADENCE_SDHCI | ||
36 | + select MCHP_PFSOC_MMUART | ||
37 | select MSI_NONBROKEN | ||
38 | select SIFIVE_CLINT | ||
39 | - select SIFIVE_GPIO | ||
40 | select SIFIVE_PDMA | ||
41 | select SIFIVE_PLIC | ||
42 | - select SIFIVE_UART | ||
43 | - select SIFIVE_U_OTP | ||
44 | - select SIFIVE_U_PRCI | ||
45 | select UNIMP | ||
46 | |||
47 | -config SPIKE | ||
48 | - bool | ||
49 | - select HTIF | ||
50 | - select MSI_NONBROKEN | ||
51 | - select SIFIVE_CLINT | ||
52 | - select SIFIVE_PLIC | ||
53 | - | ||
54 | config OPENTITAN | ||
55 | bool | ||
56 | select IBEX | ||
57 | @@ -XXX,XX +XXX,XX @@ config RISCV_VIRT | ||
58 | bool | ||
59 | imply PCI_DEVICES | ||
60 | imply TEST_DEVICES | ||
61 | + select GOLDFISH_RTC | ||
62 | select MSI_NONBROKEN | ||
63 | select PCI | ||
64 | - select SERIAL | ||
65 | - select GOLDFISH_RTC | ||
66 | - select VIRTIO_MMIO | ||
67 | select PCI_EXPRESS_GENERIC_BRIDGE | ||
68 | select PFLASH_CFI01 | ||
69 | + select SERIAL | ||
70 | select SIFIVE_CLINT | ||
71 | select SIFIVE_PLIC | ||
72 | select SIFIVE_TEST | ||
73 | + select VIRTIO_MMIO | ||
74 | |||
75 | -config MICROCHIP_PFSOC | ||
76 | +config SIFIVE_E | ||
77 | bool | ||
78 | select MSI_NONBROKEN | ||
79 | select SIFIVE_CLINT | ||
80 | + select SIFIVE_GPIO | ||
81 | + select SIFIVE_PLIC | ||
82 | + select SIFIVE_UART | ||
83 | + select SIFIVE_E_PRCI | ||
84 | select UNIMP | ||
85 | - select MCHP_PFSOC_MMUART | ||
86 | + | ||
87 | +config SIFIVE_U | ||
88 | + bool | ||
89 | + select CADENCE | ||
90 | + select MSI_NONBROKEN | ||
91 | + select SIFIVE_CLINT | ||
92 | + select SIFIVE_GPIO | ||
93 | select SIFIVE_PDMA | ||
94 | select SIFIVE_PLIC | ||
95 | - select CADENCE_SDHCI | ||
96 | + select SIFIVE_UART | ||
97 | + select SIFIVE_U_OTP | ||
98 | + select SIFIVE_U_PRCI | ||
99 | + select UNIMP | ||
100 | + | ||
101 | +config SPIKE | ||
102 | + bool | ||
103 | + select HTIF | ||
104 | + select MSI_NONBROKEN | ||
105 | + select SIFIVE_CLINT | ||
106 | + select SIFIVE_PLIC | ||
107 | -- | 30 | -- |
108 | 2.28.0 | 31 | 2.47.1 |
109 | |||
110 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | The name SIFIVE is too vague to convey the required component of | 3 | Also add a new page, docs/specs/riscv-aia.rst, where we're documenting |
4 | MSI_NONBROKEN. Let's drop the option, and select MSI_NONBROKEN in | 4 | the state of AIA support in QEMU w.r.t the controllers being emulated or |
5 | each machine instead. | 5 | not depending on the AIA and accelerator settings. |
6 | 6 | ||
7 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 7 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Message-Id: <1599129623-68957-12-git-send-email-bmeng.cn@gmail.com> | 9 | Message-ID: <20241119191706.718860-9-dbarboza@ventanamicro.com> |
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 11 | --- |
12 | hw/riscv/Kconfig | 14 +++++--------- | 12 | docs/specs/index.rst | 1 + |
13 | 1 file changed, 5 insertions(+), 9 deletions(-) | 13 | docs/specs/riscv-aia.rst | 83 ++++++++++++++++++++++++++++++++++++++ |
14 | docs/system/riscv/virt.rst | 7 ++++ | ||
15 | 3 files changed, 91 insertions(+) | ||
16 | create mode 100644 docs/specs/riscv-aia.rst | ||
14 | 17 | ||
15 | diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig | 18 | diff --git a/docs/specs/index.rst b/docs/specs/index.rst |
16 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/hw/riscv/Kconfig | 20 | --- a/docs/specs/index.rst |
18 | +++ b/hw/riscv/Kconfig | 21 | +++ b/docs/specs/index.rst |
22 | @@ -XXX,XX +XXX,XX @@ guest hardware that is specific to QEMU. | ||
23 | rapl-msr | ||
24 | rocker | ||
25 | riscv-iommu | ||
26 | + riscv-aia | ||
27 | diff --git a/docs/specs/riscv-aia.rst b/docs/specs/riscv-aia.rst | ||
28 | new file mode 100644 | ||
29 | index XXXXXXX..XXXXXXX | ||
30 | --- /dev/null | ||
31 | +++ b/docs/specs/riscv-aia.rst | ||
19 | @@ -XXX,XX +XXX,XX @@ | 32 | @@ -XXX,XX +XXX,XX @@ |
20 | config IBEX | 33 | +.. _riscv-aia: |
21 | bool | 34 | + |
22 | 35 | +RISC-V AIA support for RISC-V machines | |
23 | -config SIFIVE | 36 | +====================================== |
24 | - bool | 37 | + |
25 | - select MSI_NONBROKEN | 38 | +AIA (Advanced Interrupt Architecture) support is implemented in the ``virt`` |
26 | - | 39 | +RISC-V machine for TCG and KVM accelerators. |
27 | config SIFIVE_E | 40 | + |
28 | bool | 41 | +The support consists of two main modes: |
29 | - select SIFIVE | 42 | + |
30 | + select MSI_NONBROKEN | 43 | +- "aia=aplic": adds one or more APLIC (Advanced Platform Level Interrupt Controller) |
31 | select SIFIVE_CLINT | 44 | + devices |
32 | select SIFIVE_GPIO | 45 | +- "aia=aplic-imsic": adds one or more APLIC device and an IMSIC (Incoming MSI |
33 | select SIFIVE_PLIC | 46 | + Controller) device for each CPU |
34 | @@ -XXX,XX +XXX,XX @@ config SIFIVE_E | 47 | + |
35 | config SIFIVE_U | 48 | +From an user standpoint, these modes will behave the same regardless of the accelerator |
36 | bool | 49 | +used. From a developer standpoint the accelerator settings will change what it being |
37 | select CADENCE | 50 | +emulated in userspace versus what is being emulated by an in-kernel irqchip. |
38 | - select SIFIVE | 51 | + |
39 | + select MSI_NONBROKEN | 52 | +When running TCG, all controllers are emulated in userspace, including machine mode |
40 | select SIFIVE_CLINT | 53 | +(m-mode) APLIC and IMSIC (when applicable). |
41 | select SIFIVE_GPIO | 54 | + |
42 | select SIFIVE_PDMA | 55 | +When running KVM: |
43 | @@ -XXX,XX +XXX,XX @@ config SIFIVE_U | 56 | + |
44 | config SPIKE | 57 | +- no m-mode is provided, so there is no m-mode APLIC or IMSIC emulation regardless of |
45 | bool | 58 | + the AIA mode chosen |
46 | select HTIF | 59 | +- with "aia=aplic", s-mode APLIC will be emulated by userspace |
47 | - select SIFIVE | 60 | +- with "aia=aplic-imsic" there are two possibilities. If no additional KVM option |
48 | + select MSI_NONBROKEN | 61 | + is provided there will be no APLIC or IMSIC emulation in userspace, and the virtual |
49 | select SIFIVE_CLINT | 62 | + machine will use the provided in-kernel APLIC and IMSIC controllers. If the user |
50 | select SIFIVE_PLIC | 63 | + chooses to use the irqchip in split mode via "-accel kvm,kernel-irqchip=split", |
51 | 64 | + s-mode APLIC will be emulated while using the s-mode IMSIC from the irqchip | |
52 | @@ -XXX,XX +XXX,XX @@ config RISCV_VIRT | 65 | + |
53 | bool | 66 | +The following table summarizes how the AIA and accelerator options defines what |
54 | imply PCI_DEVICES | 67 | +we will emulate in userspace: |
55 | imply TEST_DEVICES | 68 | + |
56 | + select MSI_NONBROKEN | 69 | + |
57 | select PCI | 70 | +.. list-table:: How AIA and accel options changes controller emulation |
58 | select SERIAL | 71 | + :widths: 25 25 25 25 25 25 25 |
59 | select GOLDFISH_RTC | 72 | + :header-rows: 1 |
60 | select VIRTIO_MMIO | 73 | + |
61 | select PCI_EXPRESS_GENERIC_BRIDGE | 74 | + * - Accel |
62 | select PFLASH_CFI01 | 75 | + - Accel props |
63 | - select SIFIVE | 76 | + - AIA type |
64 | select SIFIVE_CLINT | 77 | + - APLIC m-mode |
65 | select SIFIVE_PLIC | 78 | + - IMSIC m-mode |
66 | select SIFIVE_TEST | 79 | + - APLIC s-mode |
67 | 80 | + - IMSIC s-mode | |
68 | config MICROCHIP_PFSOC | 81 | + * - tcg |
69 | bool | 82 | + - --- |
70 | - select SIFIVE | 83 | + - aplic |
71 | + select MSI_NONBROKEN | 84 | + - emul |
72 | select SIFIVE_CLINT | 85 | + - n/a |
73 | select UNIMP | 86 | + - emul |
74 | select MCHP_PFSOC_MMUART | 87 | + - n/a |
88 | + * - tcg | ||
89 | + - --- | ||
90 | + - aplic-imsic | ||
91 | + - emul | ||
92 | + - emul | ||
93 | + - emul | ||
94 | + - emul | ||
95 | + * - kvm | ||
96 | + - --- | ||
97 | + - aplic | ||
98 | + - n/a | ||
99 | + - n/a | ||
100 | + - emul | ||
101 | + - n/a | ||
102 | + * - kvm | ||
103 | + - none | ||
104 | + - aplic-imsic | ||
105 | + - n/a | ||
106 | + - n/a | ||
107 | + - in-kernel | ||
108 | + - in-kernel | ||
109 | + * - kvm | ||
110 | + - irqchip=split | ||
111 | + - aplic-imsic | ||
112 | + - n/a | ||
113 | + - n/a | ||
114 | + - emul | ||
115 | + - in-kernel | ||
116 | diff --git a/docs/system/riscv/virt.rst b/docs/system/riscv/virt.rst | ||
117 | index XXXXXXX..XXXXXXX 100644 | ||
118 | --- a/docs/system/riscv/virt.rst | ||
119 | +++ b/docs/system/riscv/virt.rst | ||
120 | @@ -XXX,XX +XXX,XX @@ The following machine-specific options are supported: | ||
121 | MSIs. When not specified, this option is assumed to be "none" which selects | ||
122 | SiFive PLIC to handle wired interrupts. | ||
123 | |||
124 | + This option also interacts with '-accel kvm'. When using "aia=aplic-imsic" | ||
125 | + with KVM, it is possible to set the use of the kernel irqchip in split mode | ||
126 | + by using "-accel kvm,kernel-irqchip=split". In this case the ``virt`` machine | ||
127 | + will emulate the APLIC controller instead of using the APLIC controller from | ||
128 | + the irqchip. See :ref:`riscv-aia` for more details on all available AIA | ||
129 | + modes. | ||
130 | + | ||
131 | - aia-guests=nnn | ||
132 | |||
133 | The number of per-HART VS-level AIA IMSIC pages to be emulated for a guest | ||
75 | -- | 134 | -- |
76 | 2.28.0 | 135 | 2.47.1 |
77 | |||
78 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Sai Pavan Boddu <sai.pavan.boddu@amd.com> |
---|---|---|---|
2 | 2 | ||
3 | This is an initial support for Microchip PolarFire SoC Icicle Kit. | 3 | Add a basic board with interrupt controller (intc), timer, serial |
4 | The Icicle Kit board integrates a PolarFire SoC, with one SiFive's | 4 | (uartlite), small memory called LMB@0 (128kB) and DDR@0x80000000 |
5 | E51 plus four U54 cores and many on-chip peripherals and an FPGA. | 5 | (configured via command line eg. -m 2g). |
6 | 6 | This is basic configuration which matches HW generated out of AMD Vivado | |
7 | For more details about Microchip PolarFire Soc, please see: | 7 | (design tools). But initial configuration is going beyond what it is |
8 | https://www.microsemi.com/product-directory/soc-fpgas/5498-polarfire-soc-fpga | 8 | configured by default because validation should be done on other |
9 | 9 | configurations too. That's why wire also additional uart16500, axi | |
10 | Unlike SiFive FU540, the RISC-V core resect vector is at 0x20220000. | 10 | ethernet(with axi dma). |
11 | The following perepherals are created as an unimplemented device: | 11 | GPIOs, i2c and qspi is also listed for completeness. |
12 | 12 | ||
13 | - Bus Error Uint 0/1/2/3/4 | 13 | IRQ map is: (addr) |
14 | - L2 cache controller | 14 | 0 - timer (0x41c00000) |
15 | - SYSREG | 15 | 1 - uartlite (0x40600000) |
16 | - MPUCFG | 16 | 2 - i2c (0x40800000) |
17 | - IOSCBCFG | 17 | 3 - qspi (0x44a00000) |
18 | 18 | 4 - uart16550 (0x44a10000) | |
19 | More devices will be added later. | 19 | 5 - emaclite (0x40e00000) |
20 | 20 | 6 - timer2 (0x41c10000) | |
21 | The BIOS image used by this machine is hss.bin, aka Hart Software | 21 | 7 - axi emac (0x40c00000) |
22 | Services, which can be built from: | 22 | 8 - axi dma (0x41e00000) |
23 | https://github.com/polarfire-soc/hart-software-services | 23 | 9 - axi dma |
24 | 24 | 10 - gpio (0x40000000) | |
25 | To launch this machine: | 25 | 11 - gpio2 (0x40010000) |
26 | $ qemu-system-riscv64 -nographic -M microchip-icicle-kit | 26 | 12 - gpio3 (0x40020000) |
27 | 27 | ||
28 | The memory is set to 1 GiB by default to match the hardware. | 28 | Signed-off-by: Sai Pavan Boddu <sai.pavan.boddu@amd.com> |
29 | A sanity check on ram size is performed in the machine init routine | 29 | Signed-off-by: Michal Simek <michal.simek@amd.com> |
30 | to prompt user to increase the RAM size to > 1 GiB when less than | ||
31 | 1 GiB ram is detected. | ||
32 | |||
33 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | ||
34 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 30 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
35 | Message-Id: <1598924352-89526-5-git-send-email-bmeng.cn@gmail.com> | 31 | Message-ID: <20241125134739.18189-1-sai.pavan.boddu@amd.com> |
36 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 32 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
37 | --- | 33 | --- |
38 | default-configs/riscv64-softmmu.mak | 1 + | 34 | MAINTAINERS | 6 + |
39 | include/hw/riscv/microchip_pfsoc.h | 88 ++++++++ | 35 | docs/system/riscv/microblaze-v-generic.rst | 42 +++++ |
40 | hw/riscv/microchip_pfsoc.c | 312 ++++++++++++++++++++++++++++ | 36 | docs/system/target-riscv.rst | 1 + |
41 | MAINTAINERS | 7 + | 37 | hw/riscv/microblaze-v-generic.c | 184 +++++++++++++++++++++ |
42 | hw/riscv/Kconfig | 6 + | 38 | hw/riscv/Kconfig | 8 + |
43 | hw/riscv/meson.build | 1 + | 39 | hw/riscv/meson.build | 1 + |
44 | 6 files changed, 415 insertions(+) | 40 | 6 files changed, 242 insertions(+) |
45 | create mode 100644 include/hw/riscv/microchip_pfsoc.h | 41 | create mode 100644 docs/system/riscv/microblaze-v-generic.rst |
46 | create mode 100644 hw/riscv/microchip_pfsoc.c | 42 | create mode 100644 hw/riscv/microblaze-v-generic.c |
47 | 43 | ||
48 | diff --git a/default-configs/riscv64-softmmu.mak b/default-configs/riscv64-softmmu.mak | ||
49 | index XXXXXXX..XXXXXXX 100644 | ||
50 | --- a/default-configs/riscv64-softmmu.mak | ||
51 | +++ b/default-configs/riscv64-softmmu.mak | ||
52 | @@ -XXX,XX +XXX,XX @@ CONFIG_SPIKE=y | ||
53 | CONFIG_SIFIVE_E=y | ||
54 | CONFIG_SIFIVE_U=y | ||
55 | CONFIG_RISCV_VIRT=y | ||
56 | +CONFIG_MICROCHIP_PFSOC=y | ||
57 | diff --git a/include/hw/riscv/microchip_pfsoc.h b/include/hw/riscv/microchip_pfsoc.h | ||
58 | new file mode 100644 | ||
59 | index XXXXXXX..XXXXXXX | ||
60 | --- /dev/null | ||
61 | +++ b/include/hw/riscv/microchip_pfsoc.h | ||
62 | @@ -XXX,XX +XXX,XX @@ | ||
63 | +/* | ||
64 | + * Microchip PolarFire SoC machine interface | ||
65 | + * | ||
66 | + * Copyright (c) 2020 Wind River Systems, Inc. | ||
67 | + * | ||
68 | + * Author: | ||
69 | + * Bin Meng <bin.meng@windriver.com> | ||
70 | + * | ||
71 | + * This program is free software; you can redistribute it and/or modify it | ||
72 | + * under the terms and conditions of the GNU General Public License, | ||
73 | + * version 2 or later, as published by the Free Software Foundation. | ||
74 | + * | ||
75 | + * This program is distributed in the hope it will be useful, but WITHOUT | ||
76 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
77 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
78 | + * more details. | ||
79 | + * | ||
80 | + * You should have received a copy of the GNU General Public License along with | ||
81 | + * this program. If not, see <http://www.gnu.org/licenses/>. | ||
82 | + */ | ||
83 | + | ||
84 | +#ifndef HW_MICROCHIP_PFSOC_H | ||
85 | +#define HW_MICROCHIP_PFSOC_H | ||
86 | + | ||
87 | +typedef struct MicrochipPFSoCState { | ||
88 | + /*< private >*/ | ||
89 | + DeviceState parent_obj; | ||
90 | + | ||
91 | + /*< public >*/ | ||
92 | + CPUClusterState e_cluster; | ||
93 | + CPUClusterState u_cluster; | ||
94 | + RISCVHartArrayState e_cpus; | ||
95 | + RISCVHartArrayState u_cpus; | ||
96 | + DeviceState *plic; | ||
97 | +} MicrochipPFSoCState; | ||
98 | + | ||
99 | +#define TYPE_MICROCHIP_PFSOC "microchip.pfsoc" | ||
100 | +#define MICROCHIP_PFSOC(obj) \ | ||
101 | + OBJECT_CHECK(MicrochipPFSoCState, (obj), TYPE_MICROCHIP_PFSOC) | ||
102 | + | ||
103 | +typedef struct MicrochipIcicleKitState { | ||
104 | + /*< private >*/ | ||
105 | + MachineState parent_obj; | ||
106 | + | ||
107 | + /*< public >*/ | ||
108 | + MicrochipPFSoCState soc; | ||
109 | +} MicrochipIcicleKitState; | ||
110 | + | ||
111 | +#define TYPE_MICROCHIP_ICICLE_KIT_MACHINE \ | ||
112 | + MACHINE_TYPE_NAME("microchip-icicle-kit") | ||
113 | +#define MICROCHIP_ICICLE_KIT_MACHINE(obj) \ | ||
114 | + OBJECT_CHECK(MicrochipIcicleKitState, (obj), \ | ||
115 | + TYPE_MICROCHIP_ICICLE_KIT_MACHINE) | ||
116 | + | ||
117 | +enum { | ||
118 | + MICROCHIP_PFSOC_DEBUG, | ||
119 | + MICROCHIP_PFSOC_E51_DTIM, | ||
120 | + MICROCHIP_PFSOC_BUSERR_UNIT0, | ||
121 | + MICROCHIP_PFSOC_BUSERR_UNIT1, | ||
122 | + MICROCHIP_PFSOC_BUSERR_UNIT2, | ||
123 | + MICROCHIP_PFSOC_BUSERR_UNIT3, | ||
124 | + MICROCHIP_PFSOC_BUSERR_UNIT4, | ||
125 | + MICROCHIP_PFSOC_CLINT, | ||
126 | + MICROCHIP_PFSOC_L2CC, | ||
127 | + MICROCHIP_PFSOC_L2LIM, | ||
128 | + MICROCHIP_PFSOC_PLIC, | ||
129 | + MICROCHIP_PFSOC_SYSREG, | ||
130 | + MICROCHIP_PFSOC_MPUCFG, | ||
131 | + MICROCHIP_PFSOC_ENVM_CFG, | ||
132 | + MICROCHIP_PFSOC_ENVM_DATA, | ||
133 | + MICROCHIP_PFSOC_IOSCB_CFG, | ||
134 | + MICROCHIP_PFSOC_DRAM, | ||
135 | +}; | ||
136 | + | ||
137 | +#define MICROCHIP_PFSOC_MANAGEMENT_CPU_COUNT 1 | ||
138 | +#define MICROCHIP_PFSOC_COMPUTE_CPU_COUNT 4 | ||
139 | + | ||
140 | +#define MICROCHIP_PFSOC_PLIC_HART_CONFIG "MS" | ||
141 | +#define MICROCHIP_PFSOC_PLIC_NUM_SOURCES 185 | ||
142 | +#define MICROCHIP_PFSOC_PLIC_NUM_PRIORITIES 7 | ||
143 | +#define MICROCHIP_PFSOC_PLIC_PRIORITY_BASE 0x04 | ||
144 | +#define MICROCHIP_PFSOC_PLIC_PENDING_BASE 0x1000 | ||
145 | +#define MICROCHIP_PFSOC_PLIC_ENABLE_BASE 0x2000 | ||
146 | +#define MICROCHIP_PFSOC_PLIC_ENABLE_STRIDE 0x80 | ||
147 | +#define MICROCHIP_PFSOC_PLIC_CONTEXT_BASE 0x200000 | ||
148 | +#define MICROCHIP_PFSOC_PLIC_CONTEXT_STRIDE 0x1000 | ||
149 | + | ||
150 | +#endif /* HW_MICROCHIP_PFSOC_H */ | ||
151 | diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c | ||
152 | new file mode 100644 | ||
153 | index XXXXXXX..XXXXXXX | ||
154 | --- /dev/null | ||
155 | +++ b/hw/riscv/microchip_pfsoc.c | ||
156 | @@ -XXX,XX +XXX,XX @@ | ||
157 | +/* | ||
158 | + * QEMU RISC-V Board Compatible with Microchip PolarFire SoC Icicle Kit | ||
159 | + * | ||
160 | + * Copyright (c) 2020 Wind River Systems, Inc. | ||
161 | + * | ||
162 | + * Author: | ||
163 | + * Bin Meng <bin.meng@windriver.com> | ||
164 | + * | ||
165 | + * Provides a board compatible with the Microchip PolarFire SoC Icicle Kit | ||
166 | + * | ||
167 | + * 0) CLINT (Core Level Interruptor) | ||
168 | + * 1) PLIC (Platform Level Interrupt Controller) | ||
169 | + * 2) eNVM (Embedded Non-Volatile Memory) | ||
170 | + * | ||
171 | + * This board currently generates devicetree dynamically that indicates at least | ||
172 | + * two harts and up to five harts. | ||
173 | + * | ||
174 | + * This program is free software; you can redistribute it and/or modify it | ||
175 | + * under the terms and conditions of the GNU General Public License, | ||
176 | + * version 2 or later, as published by the Free Software Foundation. | ||
177 | + * | ||
178 | + * This program is distributed in the hope it will be useful, but WITHOUT | ||
179 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
180 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
181 | + * more details. | ||
182 | + * | ||
183 | + * You should have received a copy of the GNU General Public License along with | ||
184 | + * this program. If not, see <http://www.gnu.org/licenses/>. | ||
185 | + */ | ||
186 | + | ||
187 | +#include "qemu/osdep.h" | ||
188 | +#include "qemu/error-report.h" | ||
189 | +#include "qemu/log.h" | ||
190 | +#include "qemu/units.h" | ||
191 | +#include "qemu/cutils.h" | ||
192 | +#include "qapi/error.h" | ||
193 | +#include "hw/boards.h" | ||
194 | +#include "hw/irq.h" | ||
195 | +#include "hw/loader.h" | ||
196 | +#include "hw/sysbus.h" | ||
197 | +#include "hw/cpu/cluster.h" | ||
198 | +#include "target/riscv/cpu.h" | ||
199 | +#include "hw/misc/unimp.h" | ||
200 | +#include "hw/riscv/boot.h" | ||
201 | +#include "hw/riscv/riscv_hart.h" | ||
202 | +#include "hw/riscv/sifive_clint.h" | ||
203 | +#include "hw/riscv/sifive_plic.h" | ||
204 | +#include "hw/riscv/microchip_pfsoc.h" | ||
205 | + | ||
206 | +/* | ||
207 | + * The BIOS image used by this machine is called Hart Software Services (HSS). | ||
208 | + * See https://github.com/polarfire-soc/hart-software-services | ||
209 | + */ | ||
210 | +#define BIOS_FILENAME "hss.bin" | ||
211 | +#define RESET_VECTOR 0x20220000 | ||
212 | + | ||
213 | +static const struct MemmapEntry { | ||
214 | + hwaddr base; | ||
215 | + hwaddr size; | ||
216 | +} microchip_pfsoc_memmap[] = { | ||
217 | + [MICROCHIP_PFSOC_DEBUG] = { 0x0, 0x1000 }, | ||
218 | + [MICROCHIP_PFSOC_E51_DTIM] = { 0x1000000, 0x2000 }, | ||
219 | + [MICROCHIP_PFSOC_BUSERR_UNIT0] = { 0x1700000, 0x1000 }, | ||
220 | + [MICROCHIP_PFSOC_BUSERR_UNIT1] = { 0x1701000, 0x1000 }, | ||
221 | + [MICROCHIP_PFSOC_BUSERR_UNIT2] = { 0x1702000, 0x1000 }, | ||
222 | + [MICROCHIP_PFSOC_BUSERR_UNIT3] = { 0x1703000, 0x1000 }, | ||
223 | + [MICROCHIP_PFSOC_BUSERR_UNIT4] = { 0x1704000, 0x1000 }, | ||
224 | + [MICROCHIP_PFSOC_CLINT] = { 0x2000000, 0x10000 }, | ||
225 | + [MICROCHIP_PFSOC_L2CC] = { 0x2010000, 0x1000 }, | ||
226 | + [MICROCHIP_PFSOC_L2LIM] = { 0x8000000, 0x2000000 }, | ||
227 | + [MICROCHIP_PFSOC_PLIC] = { 0xc000000, 0x4000000 }, | ||
228 | + [MICROCHIP_PFSOC_SYSREG] = { 0x20002000, 0x2000 }, | ||
229 | + [MICROCHIP_PFSOC_MPUCFG] = { 0x20005000, 0x1000 }, | ||
230 | + [MICROCHIP_PFSOC_ENVM_CFG] = { 0x20200000, 0x1000 }, | ||
231 | + [MICROCHIP_PFSOC_ENVM_DATA] = { 0x20220000, 0x20000 }, | ||
232 | + [MICROCHIP_PFSOC_IOSCB_CFG] = { 0x37080000, 0x1000 }, | ||
233 | + [MICROCHIP_PFSOC_DRAM] = { 0x80000000, 0x0 }, | ||
234 | +}; | ||
235 | + | ||
236 | +static void microchip_pfsoc_soc_instance_init(Object *obj) | ||
237 | +{ | ||
238 | + MachineState *ms = MACHINE(qdev_get_machine()); | ||
239 | + MicrochipPFSoCState *s = MICROCHIP_PFSOC(obj); | ||
240 | + | ||
241 | + object_initialize_child(obj, "e-cluster", &s->e_cluster, TYPE_CPU_CLUSTER); | ||
242 | + qdev_prop_set_uint32(DEVICE(&s->e_cluster), "cluster-id", 0); | ||
243 | + | ||
244 | + object_initialize_child(OBJECT(&s->e_cluster), "e-cpus", &s->e_cpus, | ||
245 | + TYPE_RISCV_HART_ARRAY); | ||
246 | + qdev_prop_set_uint32(DEVICE(&s->e_cpus), "num-harts", 1); | ||
247 | + qdev_prop_set_uint32(DEVICE(&s->e_cpus), "hartid-base", 0); | ||
248 | + qdev_prop_set_string(DEVICE(&s->e_cpus), "cpu-type", | ||
249 | + TYPE_RISCV_CPU_SIFIVE_E51); | ||
250 | + qdev_prop_set_uint64(DEVICE(&s->e_cpus), "resetvec", RESET_VECTOR); | ||
251 | + | ||
252 | + object_initialize_child(obj, "u-cluster", &s->u_cluster, TYPE_CPU_CLUSTER); | ||
253 | + qdev_prop_set_uint32(DEVICE(&s->u_cluster), "cluster-id", 1); | ||
254 | + | ||
255 | + object_initialize_child(OBJECT(&s->u_cluster), "u-cpus", &s->u_cpus, | ||
256 | + TYPE_RISCV_HART_ARRAY); | ||
257 | + qdev_prop_set_uint32(DEVICE(&s->u_cpus), "num-harts", ms->smp.cpus - 1); | ||
258 | + qdev_prop_set_uint32(DEVICE(&s->u_cpus), "hartid-base", 1); | ||
259 | + qdev_prop_set_string(DEVICE(&s->u_cpus), "cpu-type", | ||
260 | + TYPE_RISCV_CPU_SIFIVE_U54); | ||
261 | + qdev_prop_set_uint64(DEVICE(&s->u_cpus), "resetvec", RESET_VECTOR); | ||
262 | +} | ||
263 | + | ||
264 | +static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp) | ||
265 | +{ | ||
266 | + MachineState *ms = MACHINE(qdev_get_machine()); | ||
267 | + MicrochipPFSoCState *s = MICROCHIP_PFSOC(dev); | ||
268 | + const struct MemmapEntry *memmap = microchip_pfsoc_memmap; | ||
269 | + MemoryRegion *system_memory = get_system_memory(); | ||
270 | + MemoryRegion *e51_dtim_mem = g_new(MemoryRegion, 1); | ||
271 | + MemoryRegion *l2lim_mem = g_new(MemoryRegion, 1); | ||
272 | + MemoryRegion *envm_data = g_new(MemoryRegion, 1); | ||
273 | + char *plic_hart_config; | ||
274 | + size_t plic_hart_config_len; | ||
275 | + int i; | ||
276 | + | ||
277 | + sysbus_realize(SYS_BUS_DEVICE(&s->e_cpus), &error_abort); | ||
278 | + sysbus_realize(SYS_BUS_DEVICE(&s->u_cpus), &error_abort); | ||
279 | + /* | ||
280 | + * The cluster must be realized after the RISC-V hart array container, | ||
281 | + * as the container's CPU object is only created on realize, and the | ||
282 | + * CPU must exist and have been parented into the cluster before the | ||
283 | + * cluster is realized. | ||
284 | + */ | ||
285 | + qdev_realize(DEVICE(&s->e_cluster), NULL, &error_abort); | ||
286 | + qdev_realize(DEVICE(&s->u_cluster), NULL, &error_abort); | ||
287 | + | ||
288 | + /* E51 DTIM */ | ||
289 | + memory_region_init_ram(e51_dtim_mem, NULL, "microchip.pfsoc.e51_dtim_mem", | ||
290 | + memmap[MICROCHIP_PFSOC_E51_DTIM].size, &error_fatal); | ||
291 | + memory_region_add_subregion(system_memory, | ||
292 | + memmap[MICROCHIP_PFSOC_E51_DTIM].base, | ||
293 | + e51_dtim_mem); | ||
294 | + | ||
295 | + /* Bus Error Units */ | ||
296 | + create_unimplemented_device("microchip.pfsoc.buserr_unit0_mem", | ||
297 | + memmap[MICROCHIP_PFSOC_BUSERR_UNIT0].base, | ||
298 | + memmap[MICROCHIP_PFSOC_BUSERR_UNIT0].size); | ||
299 | + create_unimplemented_device("microchip.pfsoc.buserr_unit1_mem", | ||
300 | + memmap[MICROCHIP_PFSOC_BUSERR_UNIT1].base, | ||
301 | + memmap[MICROCHIP_PFSOC_BUSERR_UNIT1].size); | ||
302 | + create_unimplemented_device("microchip.pfsoc.buserr_unit2_mem", | ||
303 | + memmap[MICROCHIP_PFSOC_BUSERR_UNIT2].base, | ||
304 | + memmap[MICROCHIP_PFSOC_BUSERR_UNIT2].size); | ||
305 | + create_unimplemented_device("microchip.pfsoc.buserr_unit3_mem", | ||
306 | + memmap[MICROCHIP_PFSOC_BUSERR_UNIT3].base, | ||
307 | + memmap[MICROCHIP_PFSOC_BUSERR_UNIT3].size); | ||
308 | + create_unimplemented_device("microchip.pfsoc.buserr_unit4_mem", | ||
309 | + memmap[MICROCHIP_PFSOC_BUSERR_UNIT4].base, | ||
310 | + memmap[MICROCHIP_PFSOC_BUSERR_UNIT4].size); | ||
311 | + | ||
312 | + /* CLINT */ | ||
313 | + sifive_clint_create(memmap[MICROCHIP_PFSOC_CLINT].base, | ||
314 | + memmap[MICROCHIP_PFSOC_CLINT].size, 0, ms->smp.cpus, | ||
315 | + SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, false); | ||
316 | + | ||
317 | + /* L2 cache controller */ | ||
318 | + create_unimplemented_device("microchip.pfsoc.l2cc", | ||
319 | + memmap[MICROCHIP_PFSOC_L2CC].base, memmap[MICROCHIP_PFSOC_L2CC].size); | ||
320 | + | ||
321 | + /* | ||
322 | + * Add L2-LIM at reset size. | ||
323 | + * This should be reduced in size as the L2 Cache Controller WayEnable | ||
324 | + * register is incremented. Unfortunately I don't see a nice (or any) way | ||
325 | + * to handle reducing or blocking out the L2 LIM while still allowing it | ||
326 | + * be re returned to all enabled after a reset. For the time being, just | ||
327 | + * leave it enabled all the time. This won't break anything, but will be | ||
328 | + * too generous to misbehaving guests. | ||
329 | + */ | ||
330 | + memory_region_init_ram(l2lim_mem, NULL, "microchip.pfsoc.l2lim", | ||
331 | + memmap[MICROCHIP_PFSOC_L2LIM].size, &error_fatal); | ||
332 | + memory_region_add_subregion(system_memory, | ||
333 | + memmap[MICROCHIP_PFSOC_L2LIM].base, | ||
334 | + l2lim_mem); | ||
335 | + | ||
336 | + /* create PLIC hart topology configuration string */ | ||
337 | + plic_hart_config_len = (strlen(MICROCHIP_PFSOC_PLIC_HART_CONFIG) + 1) * | ||
338 | + ms->smp.cpus; | ||
339 | + plic_hart_config = g_malloc0(plic_hart_config_len); | ||
340 | + for (i = 0; i < ms->smp.cpus; i++) { | ||
341 | + if (i != 0) { | ||
342 | + strncat(plic_hart_config, "," MICROCHIP_PFSOC_PLIC_HART_CONFIG, | ||
343 | + plic_hart_config_len); | ||
344 | + } else { | ||
345 | + strncat(plic_hart_config, "M", plic_hart_config_len); | ||
346 | + } | ||
347 | + plic_hart_config_len -= (strlen(MICROCHIP_PFSOC_PLIC_HART_CONFIG) + 1); | ||
348 | + } | ||
349 | + | ||
350 | + /* PLIC */ | ||
351 | + s->plic = sifive_plic_create(memmap[MICROCHIP_PFSOC_PLIC].base, | ||
352 | + plic_hart_config, 0, | ||
353 | + MICROCHIP_PFSOC_PLIC_NUM_SOURCES, | ||
354 | + MICROCHIP_PFSOC_PLIC_NUM_PRIORITIES, | ||
355 | + MICROCHIP_PFSOC_PLIC_PRIORITY_BASE, | ||
356 | + MICROCHIP_PFSOC_PLIC_PENDING_BASE, | ||
357 | + MICROCHIP_PFSOC_PLIC_ENABLE_BASE, | ||
358 | + MICROCHIP_PFSOC_PLIC_ENABLE_STRIDE, | ||
359 | + MICROCHIP_PFSOC_PLIC_CONTEXT_BASE, | ||
360 | + MICROCHIP_PFSOC_PLIC_CONTEXT_STRIDE, | ||
361 | + memmap[MICROCHIP_PFSOC_PLIC].size); | ||
362 | + g_free(plic_hart_config); | ||
363 | + | ||
364 | + /* SYSREG */ | ||
365 | + create_unimplemented_device("microchip.pfsoc.sysreg", | ||
366 | + memmap[MICROCHIP_PFSOC_SYSREG].base, | ||
367 | + memmap[MICROCHIP_PFSOC_SYSREG].size); | ||
368 | + | ||
369 | + /* MPUCFG */ | ||
370 | + create_unimplemented_device("microchip.pfsoc.mpucfg", | ||
371 | + memmap[MICROCHIP_PFSOC_MPUCFG].base, | ||
372 | + memmap[MICROCHIP_PFSOC_MPUCFG].size); | ||
373 | + | ||
374 | + /* eNVM */ | ||
375 | + memory_region_init_rom(envm_data, OBJECT(dev), "microchip.pfsoc.envm.data", | ||
376 | + memmap[MICROCHIP_PFSOC_ENVM_DATA].size, | ||
377 | + &error_fatal); | ||
378 | + memory_region_add_subregion(system_memory, | ||
379 | + memmap[MICROCHIP_PFSOC_ENVM_DATA].base, | ||
380 | + envm_data); | ||
381 | + | ||
382 | + /* IOSCBCFG */ | ||
383 | + create_unimplemented_device("microchip.pfsoc.ioscb.cfg", | ||
384 | + memmap[MICROCHIP_PFSOC_IOSCB_CFG].base, | ||
385 | + memmap[MICROCHIP_PFSOC_IOSCB_CFG].size); | ||
386 | +} | ||
387 | + | ||
388 | +static void microchip_pfsoc_soc_class_init(ObjectClass *oc, void *data) | ||
389 | +{ | ||
390 | + DeviceClass *dc = DEVICE_CLASS(oc); | ||
391 | + | ||
392 | + dc->realize = microchip_pfsoc_soc_realize; | ||
393 | + /* Reason: Uses serial_hds in realize function, thus can't be used twice */ | ||
394 | + dc->user_creatable = false; | ||
395 | +} | ||
396 | + | ||
397 | +static const TypeInfo microchip_pfsoc_soc_type_info = { | ||
398 | + .name = TYPE_MICROCHIP_PFSOC, | ||
399 | + .parent = TYPE_DEVICE, | ||
400 | + .instance_size = sizeof(MicrochipPFSoCState), | ||
401 | + .instance_init = microchip_pfsoc_soc_instance_init, | ||
402 | + .class_init = microchip_pfsoc_soc_class_init, | ||
403 | +}; | ||
404 | + | ||
405 | +static void microchip_pfsoc_soc_register_types(void) | ||
406 | +{ | ||
407 | + type_register_static(µchip_pfsoc_soc_type_info); | ||
408 | +} | ||
409 | + | ||
410 | +type_init(microchip_pfsoc_soc_register_types) | ||
411 | + | ||
412 | +static void microchip_icicle_kit_machine_init(MachineState *machine) | ||
413 | +{ | ||
414 | + MachineClass *mc = MACHINE_GET_CLASS(machine); | ||
415 | + const struct MemmapEntry *memmap = microchip_pfsoc_memmap; | ||
416 | + MicrochipIcicleKitState *s = MICROCHIP_ICICLE_KIT_MACHINE(machine); | ||
417 | + MemoryRegion *system_memory = get_system_memory(); | ||
418 | + MemoryRegion *main_mem = g_new(MemoryRegion, 1); | ||
419 | + | ||
420 | + /* Sanity check on RAM size */ | ||
421 | + if (machine->ram_size < mc->default_ram_size) { | ||
422 | + char *sz = size_to_str(mc->default_ram_size); | ||
423 | + error_report("Invalid RAM size, should be bigger than %s", sz); | ||
424 | + g_free(sz); | ||
425 | + exit(EXIT_FAILURE); | ||
426 | + } | ||
427 | + | ||
428 | + /* Initialize SoC */ | ||
429 | + object_initialize_child(OBJECT(machine), "soc", &s->soc, | ||
430 | + TYPE_MICROCHIP_PFSOC); | ||
431 | + qdev_realize(DEVICE(&s->soc), NULL, &error_abort); | ||
432 | + | ||
433 | + /* Register RAM */ | ||
434 | + memory_region_init_ram(main_mem, NULL, "microchip.icicle.kit.ram", | ||
435 | + machine->ram_size, &error_fatal); | ||
436 | + memory_region_add_subregion(system_memory, | ||
437 | + memmap[MICROCHIP_PFSOC_DRAM].base, main_mem); | ||
438 | + | ||
439 | + /* Load the firmware */ | ||
440 | + riscv_find_and_load_firmware(machine, BIOS_FILENAME, RESET_VECTOR, NULL); | ||
441 | +} | ||
442 | + | ||
443 | +static void microchip_icicle_kit_machine_class_init(ObjectClass *oc, void *data) | ||
444 | +{ | ||
445 | + MachineClass *mc = MACHINE_CLASS(oc); | ||
446 | + | ||
447 | + mc->desc = "Microchip PolarFire SoC Icicle Kit"; | ||
448 | + mc->init = microchip_icicle_kit_machine_init; | ||
449 | + mc->max_cpus = MICROCHIP_PFSOC_MANAGEMENT_CPU_COUNT + | ||
450 | + MICROCHIP_PFSOC_COMPUTE_CPU_COUNT; | ||
451 | + mc->min_cpus = MICROCHIP_PFSOC_MANAGEMENT_CPU_COUNT + 1; | ||
452 | + mc->default_cpus = mc->min_cpus; | ||
453 | + mc->default_ram_size = 1 * GiB; | ||
454 | +} | ||
455 | + | ||
456 | +static const TypeInfo microchip_icicle_kit_machine_typeinfo = { | ||
457 | + .name = MACHINE_TYPE_NAME("microchip-icicle-kit"), | ||
458 | + .parent = TYPE_MACHINE, | ||
459 | + .class_init = microchip_icicle_kit_machine_class_init, | ||
460 | + .instance_size = sizeof(MicrochipIcicleKitState), | ||
461 | +}; | ||
462 | + | ||
463 | +static void microchip_icicle_kit_machine_init_register_types(void) | ||
464 | +{ | ||
465 | + type_register_static(µchip_icicle_kit_machine_typeinfo); | ||
466 | +} | ||
467 | + | ||
468 | +type_init(microchip_icicle_kit_machine_init_register_types) | ||
469 | diff --git a/MAINTAINERS b/MAINTAINERS | 44 | diff --git a/MAINTAINERS b/MAINTAINERS |
470 | index XXXXXXX..XXXXXXX 100644 | 45 | index XXXXXXX..XXXXXXX 100644 |
471 | --- a/MAINTAINERS | 46 | --- a/MAINTAINERS |
472 | +++ b/MAINTAINERS | 47 | +++ b/MAINTAINERS |
473 | @@ -XXX,XX +XXX,XX @@ F: include/hw/riscv/opentitan.h | 48 | @@ -XXX,XX +XXX,XX @@ F: docs/system/riscv/sifive_u.rst |
474 | F: include/hw/char/ibex_uart.h | 49 | F: hw/*/*sifive*.c |
475 | F: include/hw/intc/ibex_plic.h | 50 | F: include/hw/*/*sifive*.h |
476 | 51 | ||
477 | +Microchip PolarFire SoC Icicle Kit | 52 | +AMD Microblaze-V Generic Board |
478 | +M: Bin Meng <bin.meng@windriver.com> | 53 | +M: Sai Pavan Boddu <sai.pavan.boddu@amd.com> |
479 | +L: qemu-riscv@nongnu.org | 54 | +S: Maintained |
480 | +S: Supported | 55 | +F: hw/riscv/microblaze-v-generic.c |
481 | +F: hw/riscv/microchip_pfsoc.c | 56 | +F: docs/system/riscv/microblaze-v-generic.rst |
482 | +F: include/hw/riscv/microchip_pfsoc.h | ||
483 | + | 57 | + |
484 | RX Machines | 58 | RX Machines |
485 | ----------- | 59 | ----------- |
486 | rx-gdbsim | 60 | rx-gdbsim |
61 | diff --git a/docs/system/riscv/microblaze-v-generic.rst b/docs/system/riscv/microblaze-v-generic.rst | ||
62 | new file mode 100644 | ||
63 | index XXXXXXX..XXXXXXX | ||
64 | --- /dev/null | ||
65 | +++ b/docs/system/riscv/microblaze-v-generic.rst | ||
66 | @@ -XXX,XX +XXX,XX @@ | ||
67 | +Microblaze-V generic board (``amd-microblaze-v-generic``) | ||
68 | +========================================================= | ||
69 | +The AMD MicroBlaze™ V processor is a soft-core RISC-V processor IP for AMD | ||
70 | +adaptive SoCs and FPGAs. The MicroBlaze™ V processor is based on the 32-bit (or | ||
71 | +64-bit) RISC-V instruction set architecture (ISA) and contains interfaces | ||
72 | +compatible with the classic MicroBlaze™ V processor (i.e it is a drop in | ||
73 | +replacement for the classic MicroBlaze™ processor in existing RTL designs). | ||
74 | +More information can be found in below document. | ||
75 | + | ||
76 | +https://docs.amd.com/r/en-US/ug1629-microblaze-v-user-guide/MicroBlaze-V-Architecture | ||
77 | + | ||
78 | +The MicroBlaze™ V generic board in QEMU has following supported devices: | ||
79 | + | ||
80 | + - timer | ||
81 | + - uartlite | ||
82 | + - uart16550 | ||
83 | + - emaclite | ||
84 | + - timer2 | ||
85 | + - axi emac | ||
86 | + - axi dma | ||
87 | + | ||
88 | +The MicroBlaze™ V core in QEMU has the following configuration: | ||
89 | + | ||
90 | + - RV32I base integer instruction set | ||
91 | + - "Zicsr" Control and Status register instructions | ||
92 | + - "Zifencei" instruction-fetch | ||
93 | + - Extensions: m, a, f, c | ||
94 | + | ||
95 | +Running | ||
96 | +""""""" | ||
97 | +Below is an example command line for launching mainline U-boot | ||
98 | +(xilinx_mbv32_defconfig) on the Microblaze-V generic board. | ||
99 | + | ||
100 | +.. code-block:: bash | ||
101 | + | ||
102 | + $ qemu-system-riscv32 -M amd-microblaze-v-generic \ | ||
103 | + -display none \ | ||
104 | + -device loader,addr=0x80000000,file=u-boot-spl.bin,cpu-num=0 \ | ||
105 | + -device loader,addr=0x80200000,file=u-boot.img \ | ||
106 | + -serial mon:stdio \ | ||
107 | + -device loader,addr=0x83000000,file=system.dtb \ | ||
108 | + -m 2g | ||
109 | diff --git a/docs/system/target-riscv.rst b/docs/system/target-riscv.rst | ||
110 | index XXXXXXX..XXXXXXX 100644 | ||
111 | --- a/docs/system/target-riscv.rst | ||
112 | +++ b/docs/system/target-riscv.rst | ||
113 | @@ -XXX,XX +XXX,XX @@ undocumented; you can get a complete list by running | ||
114 | .. toctree:: | ||
115 | :maxdepth: 1 | ||
116 | |||
117 | + riscv/microblaze-v-generic | ||
118 | riscv/microchip-icicle-kit | ||
119 | riscv/shakti-c | ||
120 | riscv/sifive_u | ||
121 | diff --git a/hw/riscv/microblaze-v-generic.c b/hw/riscv/microblaze-v-generic.c | ||
122 | new file mode 100644 | ||
123 | index XXXXXXX..XXXXXXX | ||
124 | --- /dev/null | ||
125 | +++ b/hw/riscv/microblaze-v-generic.c | ||
126 | @@ -XXX,XX +XXX,XX @@ | ||
127 | +/* | ||
128 | + * QEMU model of Microblaze V generic board. | ||
129 | + * | ||
130 | + * based on hw/microblaze/petalogix_ml605_mmu.c | ||
131 | + * | ||
132 | + * Copyright (c) 2011 Michal Simek <monstr@monstr.eu> | ||
133 | + * Copyright (c) 2011 PetaLogix | ||
134 | + * Copyright (c) 2009 Edgar E. Iglesias. | ||
135 | + * Copyright (C) 2024, Advanced Micro Devices, Inc. | ||
136 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
137 | + * | ||
138 | + * Written by Sai Pavan Boddu <sai.pavan.boddu@amd.com | ||
139 | + * and by Michal Simek <michal.simek@amd.com>. | ||
140 | + */ | ||
141 | + | ||
142 | +#include "qemu/osdep.h" | ||
143 | +#include "qemu/units.h" | ||
144 | +#include "qapi/error.h" | ||
145 | +#include "cpu.h" | ||
146 | +#include "hw/sysbus.h" | ||
147 | +#include "sysemu/sysemu.h" | ||
148 | +#include "net/net.h" | ||
149 | +#include "hw/boards.h" | ||
150 | +#include "hw/char/serial-mm.h" | ||
151 | +#include "exec/address-spaces.h" | ||
152 | +#include "hw/char/xilinx_uartlite.h" | ||
153 | +#include "hw/misc/unimp.h" | ||
154 | + | ||
155 | +#define LMB_BRAM_SIZE (128 * KiB) | ||
156 | +#define MEMORY_BASEADDR 0x80000000 | ||
157 | +#define INTC_BASEADDR 0x41200000 | ||
158 | +#define TIMER_BASEADDR 0x41c00000 | ||
159 | +#define TIMER_BASEADDR2 0x41c10000 | ||
160 | +#define UARTLITE_BASEADDR 0x40600000 | ||
161 | +#define ETHLITE_BASEADDR 0x40e00000 | ||
162 | +#define UART16550_BASEADDR 0x44a10000 | ||
163 | +#define AXIENET_BASEADDR 0x40c00000 | ||
164 | +#define AXIDMA_BASEADDR 0x41e00000 | ||
165 | +#define GPIO_BASEADDR 0x40000000 | ||
166 | +#define GPIO_BASEADDR2 0x40010000 | ||
167 | +#define GPIO_BASEADDR3 0x40020000 | ||
168 | +#define I2C_BASEADDR 0x40800000 | ||
169 | +#define QSPI_BASEADDR 0x44a00000 | ||
170 | + | ||
171 | +#define TIMER_IRQ 0 | ||
172 | +#define UARTLITE_IRQ 1 | ||
173 | +#define UART16550_IRQ 4 | ||
174 | +#define ETHLITE_IRQ 5 | ||
175 | +#define TIMER_IRQ2 6 | ||
176 | +#define AXIENET_IRQ 7 | ||
177 | +#define AXIDMA_IRQ1 8 | ||
178 | +#define AXIDMA_IRQ0 9 | ||
179 | + | ||
180 | +static void mb_v_generic_init(MachineState *machine) | ||
181 | +{ | ||
182 | + ram_addr_t ram_size = machine->ram_size; | ||
183 | + DeviceState *dev, *dma, *eth0; | ||
184 | + Object *ds, *cs; | ||
185 | + int i; | ||
186 | + RISCVCPU *cpu; | ||
187 | + hwaddr ddr_base = MEMORY_BASEADDR; | ||
188 | + MemoryRegion *phys_lmb_bram = g_new(MemoryRegion, 1); | ||
189 | + MemoryRegion *phys_ram = g_new(MemoryRegion, 1); | ||
190 | + qemu_irq irq[32]; | ||
191 | + MemoryRegion *sysmem = get_system_memory(); | ||
192 | + | ||
193 | + cpu = RISCV_CPU(object_new(machine->cpu_type)); | ||
194 | + object_property_set_bool(OBJECT(cpu), "h", false, NULL); | ||
195 | + object_property_set_bool(OBJECT(cpu), "d", false, NULL); | ||
196 | + qdev_realize(DEVICE(cpu), NULL, &error_abort); | ||
197 | + /* Attach emulated BRAM through the LMB. */ | ||
198 | + memory_region_init_ram(phys_lmb_bram, NULL, | ||
199 | + "mb_v.lmb_bram", LMB_BRAM_SIZE, | ||
200 | + &error_fatal); | ||
201 | + memory_region_add_subregion(sysmem, 0x00000000, phys_lmb_bram); | ||
202 | + | ||
203 | + memory_region_init_ram(phys_ram, NULL, "mb_v.ram", | ||
204 | + ram_size, &error_fatal); | ||
205 | + memory_region_add_subregion(sysmem, ddr_base, phys_ram); | ||
206 | + | ||
207 | + dev = qdev_new("xlnx.xps-intc"); | ||
208 | + qdev_prop_set_uint32(dev, "kind-of-intr", | ||
209 | + 1 << UARTLITE_IRQ); | ||
210 | + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); | ||
211 | + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, INTC_BASEADDR); | ||
212 | + sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, | ||
213 | + qdev_get_gpio_in(DEVICE(cpu), 11)); | ||
214 | + for (i = 0; i < 32; i++) { | ||
215 | + irq[i] = qdev_get_gpio_in(dev, i); | ||
216 | + } | ||
217 | + | ||
218 | + /* Uartlite */ | ||
219 | + dev = qdev_new(TYPE_XILINX_UARTLITE); | ||
220 | + qdev_prop_set_chr(dev, "chardev", serial_hd(0)); | ||
221 | + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); | ||
222 | + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, UARTLITE_BASEADDR); | ||
223 | + sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq[UARTLITE_IRQ]); | ||
224 | + | ||
225 | + /* Full uart */ | ||
226 | + serial_mm_init(sysmem, UART16550_BASEADDR + 0x1000, 2, | ||
227 | + irq[UART16550_IRQ], 115200, serial_hd(1), | ||
228 | + DEVICE_LITTLE_ENDIAN); | ||
229 | + | ||
230 | + /* 2 timers at irq 0 @ 100 Mhz. */ | ||
231 | + dev = qdev_new("xlnx.xps-timer"); | ||
232 | + qdev_prop_set_uint32(dev, "one-timer-only", 0); | ||
233 | + qdev_prop_set_uint32(dev, "clock-frequency", 100000000); | ||
234 | + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); | ||
235 | + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, TIMER_BASEADDR); | ||
236 | + sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq[TIMER_IRQ]); | ||
237 | + | ||
238 | + /* 2 timers at irq 3 @ 100 Mhz. */ | ||
239 | + dev = qdev_new("xlnx.xps-timer"); | ||
240 | + qdev_prop_set_uint32(dev, "one-timer-only", 0); | ||
241 | + qdev_prop_set_uint32(dev, "clock-frequency", 100000000); | ||
242 | + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); | ||
243 | + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, TIMER_BASEADDR2); | ||
244 | + sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq[TIMER_IRQ2]); | ||
245 | + | ||
246 | + /* Emaclite */ | ||
247 | + dev = qdev_new("xlnx.xps-ethernetlite"); | ||
248 | + qemu_configure_nic_device(dev, true, NULL); | ||
249 | + qdev_prop_set_uint32(dev, "tx-ping-pong", 0); | ||
250 | + qdev_prop_set_uint32(dev, "rx-ping-pong", 0); | ||
251 | + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); | ||
252 | + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, ETHLITE_BASEADDR); | ||
253 | + sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq[ETHLITE_IRQ]); | ||
254 | + | ||
255 | + /* axi ethernet and dma initialization. */ | ||
256 | + eth0 = qdev_new("xlnx.axi-ethernet"); | ||
257 | + dma = qdev_new("xlnx.axi-dma"); | ||
258 | + | ||
259 | + /* FIXME: attach to the sysbus instead */ | ||
260 | + object_property_add_child(qdev_get_machine(), "xilinx-eth", OBJECT(eth0)); | ||
261 | + object_property_add_child(qdev_get_machine(), "xilinx-dma", OBJECT(dma)); | ||
262 | + | ||
263 | + ds = object_property_get_link(OBJECT(dma), | ||
264 | + "axistream-connected-target", NULL); | ||
265 | + cs = object_property_get_link(OBJECT(dma), | ||
266 | + "axistream-control-connected-target", NULL); | ||
267 | + qemu_configure_nic_device(eth0, true, NULL); | ||
268 | + qdev_prop_set_uint32(eth0, "rxmem", 0x1000); | ||
269 | + qdev_prop_set_uint32(eth0, "txmem", 0x1000); | ||
270 | + object_property_set_link(OBJECT(eth0), "axistream-connected", ds, | ||
271 | + &error_abort); | ||
272 | + object_property_set_link(OBJECT(eth0), "axistream-control-connected", cs, | ||
273 | + &error_abort); | ||
274 | + sysbus_realize_and_unref(SYS_BUS_DEVICE(eth0), &error_fatal); | ||
275 | + sysbus_mmio_map(SYS_BUS_DEVICE(eth0), 0, AXIENET_BASEADDR); | ||
276 | + sysbus_connect_irq(SYS_BUS_DEVICE(eth0), 0, irq[AXIENET_IRQ]); | ||
277 | + | ||
278 | + ds = object_property_get_link(OBJECT(eth0), | ||
279 | + "axistream-connected-target", NULL); | ||
280 | + cs = object_property_get_link(OBJECT(eth0), | ||
281 | + "axistream-control-connected-target", NULL); | ||
282 | + qdev_prop_set_uint32(dma, "freqhz", 100000000); | ||
283 | + object_property_set_link(OBJECT(dma), "axistream-connected", ds, | ||
284 | + &error_abort); | ||
285 | + object_property_set_link(OBJECT(dma), "axistream-control-connected", cs, | ||
286 | + &error_abort); | ||
287 | + sysbus_realize_and_unref(SYS_BUS_DEVICE(dma), &error_fatal); | ||
288 | + sysbus_mmio_map(SYS_BUS_DEVICE(dma), 0, AXIDMA_BASEADDR); | ||
289 | + sysbus_connect_irq(SYS_BUS_DEVICE(dma), 0, irq[AXIDMA_IRQ0]); | ||
290 | + sysbus_connect_irq(SYS_BUS_DEVICE(dma), 1, irq[AXIDMA_IRQ1]); | ||
291 | + | ||
292 | + /* unimplemented devices */ | ||
293 | + create_unimplemented_device("gpio", GPIO_BASEADDR, 0x10000); | ||
294 | + create_unimplemented_device("gpio2", GPIO_BASEADDR2, 0x10000); | ||
295 | + create_unimplemented_device("gpio3", GPIO_BASEADDR3, 0x10000); | ||
296 | + create_unimplemented_device("i2c", I2C_BASEADDR, 0x10000); | ||
297 | + create_unimplemented_device("qspi", QSPI_BASEADDR, 0x10000); | ||
298 | +} | ||
299 | + | ||
300 | +static void mb_v_generic_machine_init(MachineClass *mc) | ||
301 | +{ | ||
302 | + mc->desc = "AMD Microblaze-V generic platform"; | ||
303 | + mc->init = mb_v_generic_init; | ||
304 | + mc->min_cpus = 1; | ||
305 | + mc->max_cpus = 1; | ||
306 | + mc->default_cpu_type = TYPE_RISCV_CPU_BASE; | ||
307 | + mc->default_cpus = 1; | ||
308 | +} | ||
309 | + | ||
310 | +DEFINE_MACHINE("amd-microblaze-v-generic", mb_v_generic_machine_init) | ||
487 | diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig | 311 | diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig |
488 | index XXXXXXX..XXXXXXX 100644 | 312 | index XXXXXXX..XXXXXXX 100644 |
489 | --- a/hw/riscv/Kconfig | 313 | --- a/hw/riscv/Kconfig |
490 | +++ b/hw/riscv/Kconfig | 314 | +++ b/hw/riscv/Kconfig |
491 | @@ -XXX,XX +XXX,XX @@ config RISCV_VIRT | 315 | @@ -XXX,XX +XXX,XX @@ config MICROCHIP_PFSOC |
492 | select PCI_EXPRESS_GENERIC_BRIDGE | 316 | select SIFIVE_PLIC |
493 | select PFLASH_CFI01 | 317 | select UNIMP |
494 | select SIFIVE | 318 | |
495 | + | 319 | +config MICROBLAZE_V |
496 | +config MICROCHIP_PFSOC | ||
497 | + bool | 320 | + bool |
498 | + select HART | 321 | + default y |
499 | + select SIFIVE | 322 | + depends on RISCV32 || RISCV64 |
500 | + select UNIMP | 323 | + select XILINX |
324 | + select XILINX_AXI | ||
325 | + select XILINX_ETHLITE | ||
326 | + | ||
327 | config OPENTITAN | ||
328 | bool | ||
329 | default y | ||
501 | diff --git a/hw/riscv/meson.build b/hw/riscv/meson.build | 330 | diff --git a/hw/riscv/meson.build b/hw/riscv/meson.build |
502 | index XXXXXXX..XXXXXXX 100644 | 331 | index XXXXXXX..XXXXXXX 100644 |
503 | --- a/hw/riscv/meson.build | 332 | --- a/hw/riscv/meson.build |
504 | +++ b/hw/riscv/meson.build | 333 | +++ b/hw/riscv/meson.build |
505 | @@ -XXX,XX +XXX,XX @@ riscv_ss.add(when: 'CONFIG_SIFIVE_U', if_true: files('sifive_u_otp.c')) | 334 | @@ -XXX,XX +XXX,XX @@ riscv_ss.add(when: 'CONFIG_SPIKE', if_true: files('spike.c')) |
506 | riscv_ss.add(when: 'CONFIG_SIFIVE_U', if_true: files('sifive_u_prci.c')) | 335 | riscv_ss.add(when: 'CONFIG_MICROCHIP_PFSOC', if_true: files('microchip_pfsoc.c')) |
507 | riscv_ss.add(when: 'CONFIG_SPIKE', if_true: files('riscv_htif.c')) | 336 | riscv_ss.add(when: 'CONFIG_ACPI', if_true: files('virt-acpi-build.c')) |
508 | riscv_ss.add(when: 'CONFIG_SPIKE', if_true: files('spike.c')) | 337 | riscv_ss.add(when: 'CONFIG_RISCV_IOMMU', if_true: files('riscv-iommu.c', 'riscv-iommu-pci.c', 'riscv-iommu-sys.c')) |
509 | +riscv_ss.add(when: 'CONFIG_MICROCHIP_PFSOC', if_true: files('microchip_pfsoc.c')) | 338 | +riscv_ss.add(when: 'CONFIG_MICROBLAZE_V', if_true: files('microblaze-v-generic.c')) |
510 | 339 | ||
511 | hw_arch += {'riscv': riscv_ss} | 340 | hw_arch += {'riscv': riscv_ss} |
512 | -- | 341 | -- |
513 | 2.28.0 | 342 | 2.47.1 |
514 | 343 | ||
515 | 344 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Sia Jee Heng <jeeheng.sia@starfivetech.com> |
---|---|---|---|
2 | 2 | ||
3 | Every RISC-V machine needs riscv_hart hence there is no need to | 3 | Signed-off-by: Sia Jee Heng <jeeheng.sia@starfivetech.com> |
4 | have a dedicated Kconfig option for it. Drop the Kconfig option | 4 | Reviewed-by: Sunil V L <sunilvl@ventanamicro.com> |
5 | and always build riscv_hart.c. | 5 | Acked-by: Alistair Francis <alistair.francis@wdc.com> |
6 | 6 | Message-ID: <20241028015744.624943-2-jeeheng.sia@starfivetech.com> | |
7 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | Message-Id: <1599129623-68957-11-git-send-email-bmeng.cn@gmail.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 7 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 8 | --- |
12 | hw/riscv/Kconfig | 9 --------- | 9 | tests/qtest/bios-tables-test-allowed-diff.h | 1 + |
13 | hw/riscv/meson.build | 2 +- | 10 | 1 file changed, 1 insertion(+) |
14 | 2 files changed, 1 insertion(+), 10 deletions(-) | ||
15 | 11 | ||
16 | diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig | 12 | diff --git a/tests/qtest/bios-tables-test-allowed-diff.h b/tests/qtest/bios-tables-test-allowed-diff.h |
17 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/hw/riscv/Kconfig | 14 | --- a/tests/qtest/bios-tables-test-allowed-diff.h |
19 | +++ b/hw/riscv/Kconfig | 15 | +++ b/tests/qtest/bios-tables-test-allowed-diff.h |
20 | @@ -XXX,XX +XXX,XX @@ | 16 | @@ -1 +1,2 @@ |
21 | -config HART | 17 | /* List of comma-separated changed AML files to ignore */ |
22 | - bool | 18 | +"tests/data/acpi/riscv64/virt/SPCR", |
23 | - | ||
24 | config IBEX | ||
25 | bool | ||
26 | |||
27 | @@ -XXX,XX +XXX,XX @@ config SIFIVE | ||
28 | |||
29 | config SIFIVE_E | ||
30 | bool | ||
31 | - select HART | ||
32 | select SIFIVE | ||
33 | select SIFIVE_CLINT | ||
34 | select SIFIVE_GPIO | ||
35 | @@ -XXX,XX +XXX,XX @@ config SIFIVE_E | ||
36 | config SIFIVE_U | ||
37 | bool | ||
38 | select CADENCE | ||
39 | - select HART | ||
40 | select SIFIVE | ||
41 | select SIFIVE_CLINT | ||
42 | select SIFIVE_GPIO | ||
43 | @@ -XXX,XX +XXX,XX @@ config SIFIVE_U | ||
44 | |||
45 | config SPIKE | ||
46 | bool | ||
47 | - select HART | ||
48 | select HTIF | ||
49 | select SIFIVE | ||
50 | select SIFIVE_CLINT | ||
51 | @@ -XXX,XX +XXX,XX @@ config SPIKE | ||
52 | config OPENTITAN | ||
53 | bool | ||
54 | select IBEX | ||
55 | - select HART | ||
56 | select UNIMP | ||
57 | |||
58 | config RISCV_VIRT | ||
59 | @@ -XXX,XX +XXX,XX @@ config RISCV_VIRT | ||
60 | imply PCI_DEVICES | ||
61 | imply TEST_DEVICES | ||
62 | select PCI | ||
63 | - select HART | ||
64 | select SERIAL | ||
65 | select GOLDFISH_RTC | ||
66 | select VIRTIO_MMIO | ||
67 | @@ -XXX,XX +XXX,XX @@ config RISCV_VIRT | ||
68 | |||
69 | config MICROCHIP_PFSOC | ||
70 | bool | ||
71 | - select HART | ||
72 | select SIFIVE | ||
73 | select SIFIVE_CLINT | ||
74 | select UNIMP | ||
75 | diff --git a/hw/riscv/meson.build b/hw/riscv/meson.build | ||
76 | index XXXXXXX..XXXXXXX 100644 | ||
77 | --- a/hw/riscv/meson.build | ||
78 | +++ b/hw/riscv/meson.build | ||
79 | @@ -XXX,XX +XXX,XX @@ | ||
80 | riscv_ss = ss.source_set() | ||
81 | riscv_ss.add(files('boot.c'), fdt) | ||
82 | riscv_ss.add(files('numa.c')) | ||
83 | -riscv_ss.add(when: 'CONFIG_HART', if_true: files('riscv_hart.c')) | ||
84 | +riscv_ss.add(files('riscv_hart.c')) | ||
85 | riscv_ss.add(when: 'CONFIG_OPENTITAN', if_true: files('opentitan.c')) | ||
86 | riscv_ss.add(when: 'CONFIG_RISCV_VIRT', if_true: files('virt.c')) | ||
87 | riscv_ss.add(when: 'CONFIG_SIFIVE_E', if_true: files('sifive_e.c')) | ||
88 | -- | 19 | -- |
89 | 2.28.0 | 20 | 2.47.1 |
90 | |||
91 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Sia Jee Heng <jeeheng.sia@starfivetech.com> |
---|---|---|---|
2 | 2 | ||
3 | This is an effort to clean up the hw/riscv directory. Ideally it | 3 | Update the SPCR table to accommodate the SPCR Table revision 4 [1]. |
4 | should only contain the RISC-V SoC / machine codes plus generic | 4 | The SPCR table has been modified to adhere to the revision 4 format [2]. |
5 | codes. Let's move sifive_u_otp model to hw/misc directory. | ||
6 | 5 | ||
7 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 6 | [1]: https://learn.microsoft.com/en-us/windows-hardware/drivers/serports/serial-port-console-redirection-table |
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 7 | [2]: https://github.com/acpica/acpica/pull/931 |
9 | Message-Id: <1599129623-68957-4-git-send-email-bmeng.cn@gmail.com> | 8 | |
9 | Signed-off-by: Sia Jee Heng <jeeheng.sia@starfivetech.com> | ||
10 | Reviewed-by: Sunil V L <sunilvl@ventanamicro.com> | ||
11 | Reviewed-by: Michael S. Tsirkin <mst@redhat.com> | ||
12 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | ||
14 | Message-ID: <20241028015744.624943-3-jeeheng.sia@starfivetech.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 16 | --- |
12 | include/hw/{riscv => misc}/sifive_u_otp.h | 0 | 17 | include/hw/acpi/acpi-defs.h | 7 +++++-- |
13 | include/hw/riscv/sifive_u.h | 2 +- | 18 | include/hw/acpi/aml-build.h | 2 +- |
14 | hw/{riscv => misc}/sifive_u_otp.c | 2 +- | 19 | hw/acpi/aml-build.c | 20 ++++++++++++++++---- |
15 | hw/misc/Kconfig | 3 +++ | 20 | hw/arm/virt-acpi-build.c | 8 ++++++-- |
16 | hw/misc/meson.build | 1 + | 21 | hw/loongarch/acpi-build.c | 6 +++++- |
17 | hw/riscv/Kconfig | 1 + | 22 | hw/riscv/virt-acpi-build.c | 12 +++++++++--- |
18 | hw/riscv/meson.build | 1 - | 23 | 6 files changed, 42 insertions(+), 13 deletions(-) |
19 | 7 files changed, 7 insertions(+), 3 deletions(-) | ||
20 | rename include/hw/{riscv => misc}/sifive_u_otp.h (100%) | ||
21 | rename hw/{riscv => misc}/sifive_u_otp.c (99%) | ||
22 | 24 | ||
23 | diff --git a/include/hw/riscv/sifive_u_otp.h b/include/hw/misc/sifive_u_otp.h | 25 | diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h |
24 | similarity index 100% | ||
25 | rename from include/hw/riscv/sifive_u_otp.h | ||
26 | rename to include/hw/misc/sifive_u_otp.h | ||
27 | diff --git a/include/hw/riscv/sifive_u.h b/include/hw/riscv/sifive_u.h | ||
28 | index XXXXXXX..XXXXXXX 100644 | 26 | index XXXXXXX..XXXXXXX 100644 |
29 | --- a/include/hw/riscv/sifive_u.h | 27 | --- a/include/hw/acpi/acpi-defs.h |
30 | +++ b/include/hw/riscv/sifive_u.h | 28 | +++ b/include/hw/acpi/acpi-defs.h |
31 | @@ -XXX,XX +XXX,XX @@ | 29 | @@ -XXX,XX +XXX,XX @@ typedef struct AcpiSpcrData { |
32 | #include "hw/riscv/riscv_hart.h" | 30 | uint8_t flow_control; |
33 | #include "hw/riscv/sifive_cpu.h" | 31 | uint8_t terminal_type; |
34 | #include "hw/riscv/sifive_gpio.h" | 32 | uint8_t language; |
35 | -#include "hw/riscv/sifive_u_otp.h" | 33 | - uint8_t reserved1; |
36 | +#include "hw/misc/sifive_u_otp.h" | 34 | uint16_t pci_device_id; /* Must be 0xffff if not PCI device */ |
37 | #include "hw/misc/sifive_u_prci.h" | 35 | uint16_t pci_vendor_id; /* Must be 0xffff if not PCI device */ |
38 | 36 | uint8_t pci_bus; | |
39 | #define TYPE_RISCV_U_SOC "riscv.sifive.u.soc" | 37 | @@ -XXX,XX +XXX,XX @@ typedef struct AcpiSpcrData { |
40 | diff --git a/hw/riscv/sifive_u_otp.c b/hw/misc/sifive_u_otp.c | 38 | uint8_t pci_function; |
41 | similarity index 99% | 39 | uint32_t pci_flags; |
42 | rename from hw/riscv/sifive_u_otp.c | 40 | uint8_t pci_segment; |
43 | rename to hw/misc/sifive_u_otp.c | 41 | - uint32_t reserved2; |
42 | + uint32_t uart_clk_freq; | ||
43 | + uint32_t precise_baudrate; | ||
44 | + uint32_t namespace_string_length; | ||
45 | + uint32_t namespace_string_offset; | ||
46 | + char namespace_string[]; | ||
47 | } AcpiSpcrData; | ||
48 | |||
49 | #define ACPI_FADT_ARM_PSCI_COMPLIANT (1 << 0) | ||
50 | diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h | ||
44 | index XXXXXXX..XXXXXXX 100644 | 51 | index XXXXXXX..XXXXXXX 100644 |
45 | --- a/hw/riscv/sifive_u_otp.c | 52 | --- a/include/hw/acpi/aml-build.h |
46 | +++ b/hw/misc/sifive_u_otp.c | 53 | +++ b/include/hw/acpi/aml-build.h |
47 | @@ -XXX,XX +XXX,XX @@ | 54 | @@ -XXX,XX +XXX,XX @@ void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog, |
48 | #include "hw/sysbus.h" | 55 | |
49 | #include "qemu/log.h" | 56 | void build_spcr(GArray *table_data, BIOSLinker *linker, |
50 | #include "qemu/module.h" | 57 | const AcpiSpcrData *f, const uint8_t rev, |
51 | -#include "hw/riscv/sifive_u_otp.h" | 58 | - const char *oem_id, const char *oem_table_id); |
52 | +#include "hw/misc/sifive_u_otp.h" | 59 | + const char *oem_id, const char *oem_table_id, const char *name); |
53 | 60 | #endif | |
54 | static uint64_t sifive_u_otp_read(void *opaque, hwaddr addr, unsigned int size) | 61 | diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c |
62 | index XXXXXXX..XXXXXXX 100644 | ||
63 | --- a/hw/acpi/aml-build.c | ||
64 | +++ b/hw/acpi/aml-build.c | ||
65 | @@ -XXX,XX +XXX,XX @@ static void build_processor_hierarchy_node(GArray *tbl, uint32_t flags, | ||
66 | |||
67 | void build_spcr(GArray *table_data, BIOSLinker *linker, | ||
68 | const AcpiSpcrData *f, const uint8_t rev, | ||
69 | - const char *oem_id, const char *oem_table_id) | ||
70 | + const char *oem_id, const char *oem_table_id, const char *name) | ||
55 | { | 71 | { |
56 | diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig | 72 | AcpiTable table = { .sig = "SPCR", .rev = rev, .oem_id = oem_id, |
73 | .oem_table_id = oem_table_id }; | ||
74 | @@ -XXX,XX +XXX,XX @@ void build_spcr(GArray *table_data, BIOSLinker *linker, | ||
75 | build_append_int_noprefix(table_data, f->pci_flags, 4); | ||
76 | /* PCI Segment */ | ||
77 | build_append_int_noprefix(table_data, f->pci_segment, 1); | ||
78 | - /* Reserved */ | ||
79 | - build_append_int_noprefix(table_data, 0, 4); | ||
80 | - | ||
81 | + if (rev < 4) { | ||
82 | + /* Reserved */ | ||
83 | + build_append_int_noprefix(table_data, 0, 4); | ||
84 | + } else { | ||
85 | + /* UartClkFreq */ | ||
86 | + build_append_int_noprefix(table_data, f->uart_clk_freq, 4); | ||
87 | + /* PreciseBaudrate */ | ||
88 | + build_append_int_noprefix(table_data, f->precise_baudrate, 4); | ||
89 | + /* NameSpaceStringLength */ | ||
90 | + build_append_int_noprefix(table_data, f->namespace_string_length, 2); | ||
91 | + /* NameSpaceStringOffset */ | ||
92 | + build_append_int_noprefix(table_data, f->namespace_string_offset, 2); | ||
93 | + /* NamespaceString[] */ | ||
94 | + g_array_append_vals(table_data, name, f->namespace_string_length); | ||
95 | + } | ||
96 | acpi_table_end(linker, &table); | ||
97 | } | ||
98 | /* | ||
99 | diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c | ||
57 | index XXXXXXX..XXXXXXX 100644 | 100 | index XXXXXXX..XXXXXXX 100644 |
58 | --- a/hw/misc/Kconfig | 101 | --- a/hw/arm/virt-acpi-build.c |
59 | +++ b/hw/misc/Kconfig | 102 | +++ b/hw/arm/virt-acpi-build.c |
60 | @@ -XXX,XX +XXX,XX @@ config AVR_POWER | 103 | @@ -XXX,XX +XXX,XX @@ spcr_setup(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) |
61 | config SIFIVE_E_PRCI | 104 | .pci_flags = 0, |
62 | bool | 105 | .pci_segment = 0, |
63 | 106 | }; | |
64 | +config SIFIVE_U_OTP | 107 | - |
65 | + bool | 108 | - build_spcr(table_data, linker, &serial, 2, vms->oem_id, vms->oem_table_id); |
66 | + | 109 | + /* |
67 | config SIFIVE_U_PRCI | 110 | + * Passing NULL as the SPCR Table for Revision 2 doesn't support |
68 | bool | 111 | + * NameSpaceString. |
69 | 112 | + */ | |
70 | diff --git a/hw/misc/meson.build b/hw/misc/meson.build | 113 | + build_spcr(table_data, linker, &serial, 2, vms->oem_id, vms->oem_table_id, |
114 | + NULL); | ||
115 | } | ||
116 | |||
117 | /* | ||
118 | diff --git a/hw/loongarch/acpi-build.c b/hw/loongarch/acpi-build.c | ||
71 | index XXXXXXX..XXXXXXX 100644 | 119 | index XXXXXXX..XXXXXXX 100644 |
72 | --- a/hw/misc/meson.build | 120 | --- a/hw/loongarch/acpi-build.c |
73 | +++ b/hw/misc/meson.build | 121 | +++ b/hw/loongarch/acpi-build.c |
74 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_MOS6522', if_true: files('mos6522.c')) | 122 | @@ -XXX,XX +XXX,XX @@ spcr_setup(GArray *table_data, BIOSLinker *linker, MachineState *machine) |
75 | 123 | }; | |
76 | # RISC-V devices | 124 | |
77 | softmmu_ss.add(when: 'CONFIG_SIFIVE_E_PRCI', if_true: files('sifive_e_prci.c')) | 125 | lvms = LOONGARCH_VIRT_MACHINE(machine); |
78 | +softmmu_ss.add(when: 'CONFIG_SIFIVE_U_OTP', if_true: files('sifive_u_otp.c')) | 126 | + /* |
79 | softmmu_ss.add(when: 'CONFIG_SIFIVE_U_PRCI', if_true: files('sifive_u_prci.c')) | 127 | + * Passing NULL as the SPCR Table for Revision 2 doesn't support |
80 | 128 | + * NameSpaceString. | |
81 | # PKUnity SoC devices | 129 | + */ |
82 | diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig | 130 | build_spcr(table_data, linker, &serial, 2, lvms->oem_id, |
131 | - lvms->oem_table_id); | ||
132 | + lvms->oem_table_id, NULL); | ||
133 | } | ||
134 | |||
135 | typedef | ||
136 | diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c | ||
83 | index XXXXXXX..XXXXXXX 100644 | 137 | index XXXXXXX..XXXXXXX 100644 |
84 | --- a/hw/riscv/Kconfig | 138 | --- a/hw/riscv/virt-acpi-build.c |
85 | +++ b/hw/riscv/Kconfig | 139 | +++ b/hw/riscv/virt-acpi-build.c |
86 | @@ -XXX,XX +XXX,XX @@ config SIFIVE_U | 140 | @@ -XXX,XX +XXX,XX @@ acpi_dsdt_add_uart(Aml *scope, const MemMapEntry *uart_memmap, |
87 | select HART | 141 | |
88 | select SIFIVE | 142 | /* |
89 | select SIFIVE_PDMA | 143 | * Serial Port Console Redirection Table (SPCR) |
90 | + select SIFIVE_U_OTP | 144 | - * Rev: 1.07 |
91 | select SIFIVE_U_PRCI | 145 | + * Rev: 1.10 |
92 | select UNIMP | 146 | */ |
93 | 147 | ||
94 | diff --git a/hw/riscv/meson.build b/hw/riscv/meson.build | 148 | static void |
95 | index XXXXXXX..XXXXXXX 100644 | 149 | spcr_setup(GArray *table_data, BIOSLinker *linker, RISCVVirtState *s) |
96 | --- a/hw/riscv/meson.build | 150 | { |
97 | +++ b/hw/riscv/meson.build | 151 | + const char name[] = "."; |
98 | @@ -XXX,XX +XXX,XX @@ riscv_ss.add(when: 'CONFIG_SIFIVE', if_true: files('sifive_test.c')) | 152 | AcpiSpcrData serial = { |
99 | riscv_ss.add(when: 'CONFIG_SIFIVE', if_true: files('sifive_uart.c')) | 153 | - .interface_type = 0, /* 16550 compatible */ |
100 | riscv_ss.add(when: 'CONFIG_SIFIVE_E', if_true: files('sifive_e.c')) | 154 | + .interface_type = 0x12, /* 16550 compatible */ |
101 | riscv_ss.add(when: 'CONFIG_SIFIVE_U', if_true: files('sifive_u.c')) | 155 | .base_addr.id = AML_AS_SYSTEM_MEMORY, |
102 | -riscv_ss.add(when: 'CONFIG_SIFIVE_U', if_true: files('sifive_u_otp.c')) | 156 | .base_addr.width = 32, |
103 | riscv_ss.add(when: 'CONFIG_SPIKE', if_true: files('riscv_htif.c')) | 157 | .base_addr.offset = 0, |
104 | riscv_ss.add(when: 'CONFIG_SPIKE', if_true: files('spike.c')) | 158 | @@ -XXX,XX +XXX,XX @@ spcr_setup(GArray *table_data, BIOSLinker *linker, RISCVVirtState *s) |
105 | riscv_ss.add(when: 'CONFIG_MICROCHIP_PFSOC', if_true: files('microchip_pfsoc.c')) | 159 | .pci_function = 0, |
160 | .pci_flags = 0, | ||
161 | .pci_segment = 0, | ||
162 | + .uart_clk_freq = 0, | ||
163 | + .precise_baudrate = 0, | ||
164 | + .namespace_string_length = sizeof(name), | ||
165 | + .namespace_string_offset = 88, | ||
166 | }; | ||
167 | |||
168 | - build_spcr(table_data, linker, &serial, 2, s->oem_id, s->oem_table_id); | ||
169 | + build_spcr(table_data, linker, &serial, 4, s->oem_id, s->oem_table_id, | ||
170 | + name); | ||
171 | } | ||
172 | |||
173 | /* RHCT Node[N] starts at offset 56 */ | ||
106 | -- | 174 | -- |
107 | 2.28.0 | 175 | 2.47.1 |
108 | |||
109 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Sia Jee Heng <jeeheng.sia@starfivetech.com> |
---|---|---|---|
2 | 2 | ||
3 | This is an effort to clean up the hw/riscv directory. Ideally it | 3 | Update the virt SPCR golden reference file for RISC-V to accommodate the |
4 | should only contain the RISC-V SoC / machine codes plus generic | 4 | SPCR Table revision 4 [1], utilizing the iasl binary compiled from the |
5 | codes. Let's move sifive_u_prci model to hw/misc directory. | 5 | latest ACPICA repository. The SPCR table has been modified to |
6 | adhere to the revision 4 format [2]. | ||
6 | 7 | ||
7 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 8 | [1]: https://learn.microsoft.com/en-us/windows-hardware/drivers/serports/serial-port-console-redirection-table |
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 9 | [2]: https://github.com/acpica/acpica/pull/931 |
9 | Message-Id: <1599129623-68957-3-git-send-email-bmeng.cn@gmail.com> | 10 | |
11 | Diffs from iasl: | ||
12 | /* | ||
13 | * Intel ACPI Component Architecture | ||
14 | * AML/ASL+ Disassembler version 20200925 (64-bit version) | ||
15 | * Copyright (c) 2000 - 2020 Intel Corporation | ||
16 | * | ||
17 | - * Disassembly of tests/data/acpi/riscv64/virt/SPCR, Wed Aug 28 18:28:19 2024 | ||
18 | + * Disassembly of /tmp/aml-MN0NS2, Wed Aug 28 18:28:19 2024 | ||
19 | * | ||
20 | * ACPI Data Table [SPCR] | ||
21 | * | ||
22 | * Format: [HexOffset DecimalOffset ByteLength] FieldName : FieldValue | ||
23 | */ | ||
24 | |||
25 | [000h 0000 4] Signature : "SPCR" [Serial Port Console Redirection table] | ||
26 | -[004h 0004 4] Table Length : 00000050 | ||
27 | -[008h 0008 1] Revision : 02 | ||
28 | -[009h 0009 1] Checksum : B9 | ||
29 | +[004h 0004 4] Table Length : 0000005A | ||
30 | +[008h 0008 1] Revision : 04 | ||
31 | +[009h 0009 1] Checksum : 13 | ||
32 | [00Ah 0010 6] Oem ID : "BOCHS " | ||
33 | [010h 0016 8] Oem Table ID : "BXPC " | ||
34 | [018h 0024 4] Oem Revision : 00000001 | ||
35 | [01Ch 0028 4] Asl Compiler ID : "BXPC" | ||
36 | [020h 0032 4] Asl Compiler Revision : 00000001 | ||
37 | |||
38 | -[024h 0036 1] Interface Type : 00 | ||
39 | +[024h 0036 1] Interface Type : 12 | ||
40 | [025h 0037 3] Reserved : 000000 | ||
41 | |||
42 | [028h 0040 12] Serial Port Register : [Generic Address Structure] | ||
43 | [028h 0040 1] Space ID : 00 [SystemMemory] | ||
44 | [029h 0041 1] Bit Width : 20 | ||
45 | [02Ah 0042 1] Bit Offset : 00 | ||
46 | [02Bh 0043 1] Encoded Access Width : 01 [Byte Access:8] | ||
47 | [02Ch 0044 8] Address : 0000000010000000 | ||
48 | |||
49 | [034h 0052 1] Interrupt Type : 10 | ||
50 | [035h 0053 1] PCAT-compatible IRQ : 00 | ||
51 | [036h 0054 4] Interrupt : 0000000A | ||
52 | [03Ah 0058 1] Baud Rate : 07 | ||
53 | [03Bh 0059 1] Parity : 00 | ||
54 | [03Ch 0060 1] Stop Bits : 01 | ||
55 | [03Dh 0061 1] Flow Control : 00 | ||
56 | [03Eh 0062 1] Terminal Type : 00 | ||
57 | [04Ch 0076 1] Reserved : 00 | ||
58 | [040h 0064 2] PCI Device ID : FFFF | ||
59 | [042h 0066 2] PCI Vendor ID : FFFF | ||
60 | [044h 0068 1] PCI Bus : 00 | ||
61 | [045h 0069 1] PCI Device : 00 | ||
62 | [046h 0070 1] PCI Function : 00 | ||
63 | [047h 0071 4] PCI Flags : 00000000 | ||
64 | [04Bh 0075 1] PCI Segment : 00 | ||
65 | -[04Ch 0076 4] Reserved : 00000000 | ||
66 | +[04Ch 0076 004h] Uart Clock Freq : 00000000 | ||
67 | +[050h 0080 004h] Precise Baud rate : 00000000 | ||
68 | +[054h 0084 002h] NameSpaceStringLength : 0002 | ||
69 | +[056h 0086 002h] NameSpaceStringOffset : 0058 | ||
70 | +[058h 0088 002h] NamespaceString : "." | ||
71 | |||
72 | -Raw Table Data: Length 80 (0x50) | ||
73 | +Raw Table Data: Length 90 (0x5A) | ||
74 | |||
75 | - 0000: 53 50 43 52 50 00 00 00 02 B9 42 4F 43 48 53 20 // SPCRP.....BOCHS | ||
76 | + 0000: 53 50 43 52 5A 00 00 00 04 13 42 4F 43 48 53 20 // SPCRZ.....BOCHS | ||
77 | 0010: 42 58 50 43 20 20 20 20 01 00 00 00 42 58 50 43 // BXPC ....BXPC | ||
78 | - 0020: 01 00 00 00 00 00 00 00 00 20 00 01 00 00 00 10 // ......... ...... | ||
79 | + 0020: 01 00 00 00 12 00 00 00 00 20 00 01 00 00 00 10 // ......... ...... | ||
80 | 0030: 00 00 00 00 10 00 0A 00 00 00 07 00 01 00 00 03 // ................ | ||
81 | 0040: FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 // ................ | ||
82 | + 0050: 00 00 00 00 02 00 58 00 2E 00 // ......X... | ||
83 | |||
84 | Signed-off-by: Sia Jee Heng <jeeheng.sia@starfivetech.com> | ||
85 | Reviewed-by: Sunil V L <sunilvl@ventanamicro.com> | ||
86 | Message-ID: <20241028015744.624943-4-jeeheng.sia@starfivetech.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 87 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 88 | --- |
12 | include/hw/{riscv => misc}/sifive_u_prci.h | 0 | 89 | tests/qtest/bios-tables-test-allowed-diff.h | 1 - |
13 | include/hw/riscv/sifive_u.h | 2 +- | 90 | tests/data/acpi/riscv64/virt/SPCR | Bin 80 -> 90 bytes |
14 | hw/{riscv => misc}/sifive_u_prci.c | 2 +- | 91 | 2 files changed, 1 deletion(-) |
15 | hw/misc/Kconfig | 3 +++ | ||
16 | hw/misc/meson.build | 1 + | ||
17 | hw/riscv/Kconfig | 1 + | ||
18 | hw/riscv/meson.build | 1 - | ||
19 | 7 files changed, 7 insertions(+), 3 deletions(-) | ||
20 | rename include/hw/{riscv => misc}/sifive_u_prci.h (100%) | ||
21 | rename hw/{riscv => misc}/sifive_u_prci.c (99%) | ||
22 | 92 | ||
23 | diff --git a/include/hw/riscv/sifive_u_prci.h b/include/hw/misc/sifive_u_prci.h | 93 | diff --git a/tests/qtest/bios-tables-test-allowed-diff.h b/tests/qtest/bios-tables-test-allowed-diff.h |
24 | similarity index 100% | ||
25 | rename from include/hw/riscv/sifive_u_prci.h | ||
26 | rename to include/hw/misc/sifive_u_prci.h | ||
27 | diff --git a/include/hw/riscv/sifive_u.h b/include/hw/riscv/sifive_u.h | ||
28 | index XXXXXXX..XXXXXXX 100644 | 94 | index XXXXXXX..XXXXXXX 100644 |
29 | --- a/include/hw/riscv/sifive_u.h | 95 | --- a/tests/qtest/bios-tables-test-allowed-diff.h |
30 | +++ b/include/hw/riscv/sifive_u.h | 96 | +++ b/tests/qtest/bios-tables-test-allowed-diff.h |
31 | @@ -XXX,XX +XXX,XX @@ | 97 | @@ -1,2 +1 @@ |
32 | #include "hw/riscv/riscv_hart.h" | 98 | /* List of comma-separated changed AML files to ignore */ |
33 | #include "hw/riscv/sifive_cpu.h" | 99 | -"tests/data/acpi/riscv64/virt/SPCR", |
34 | #include "hw/riscv/sifive_gpio.h" | 100 | diff --git a/tests/data/acpi/riscv64/virt/SPCR b/tests/data/acpi/riscv64/virt/SPCR |
35 | -#include "hw/riscv/sifive_u_prci.h" | ||
36 | #include "hw/riscv/sifive_u_otp.h" | ||
37 | +#include "hw/misc/sifive_u_prci.h" | ||
38 | |||
39 | #define TYPE_RISCV_U_SOC "riscv.sifive.u.soc" | ||
40 | #define RISCV_U_SOC(obj) \ | ||
41 | diff --git a/hw/riscv/sifive_u_prci.c b/hw/misc/sifive_u_prci.c | ||
42 | similarity index 99% | ||
43 | rename from hw/riscv/sifive_u_prci.c | ||
44 | rename to hw/misc/sifive_u_prci.c | ||
45 | index XXXXXXX..XXXXXXX 100644 | 101 | index XXXXXXX..XXXXXXX 100644 |
46 | --- a/hw/riscv/sifive_u_prci.c | 102 | Binary files a/tests/data/acpi/riscv64/virt/SPCR and b/tests/data/acpi/riscv64/virt/SPCR differ |
47 | +++ b/hw/misc/sifive_u_prci.c | ||
48 | @@ -XXX,XX +XXX,XX @@ | ||
49 | #include "hw/sysbus.h" | ||
50 | #include "qemu/log.h" | ||
51 | #include "qemu/module.h" | ||
52 | -#include "hw/riscv/sifive_u_prci.h" | ||
53 | +#include "hw/misc/sifive_u_prci.h" | ||
54 | |||
55 | static uint64_t sifive_u_prci_read(void *opaque, hwaddr addr, unsigned int size) | ||
56 | { | ||
57 | diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig | ||
58 | index XXXXXXX..XXXXXXX 100644 | ||
59 | --- a/hw/misc/Kconfig | ||
60 | +++ b/hw/misc/Kconfig | ||
61 | @@ -XXX,XX +XXX,XX @@ config AVR_POWER | ||
62 | config SIFIVE_E_PRCI | ||
63 | bool | ||
64 | |||
65 | +config SIFIVE_U_PRCI | ||
66 | + bool | ||
67 | + | ||
68 | source macio/Kconfig | ||
69 | diff --git a/hw/misc/meson.build b/hw/misc/meson.build | ||
70 | index XXXXXXX..XXXXXXX 100644 | ||
71 | --- a/hw/misc/meson.build | ||
72 | +++ b/hw/misc/meson.build | ||
73 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_MOS6522', if_true: files('mos6522.c')) | ||
74 | |||
75 | # RISC-V devices | ||
76 | softmmu_ss.add(when: 'CONFIG_SIFIVE_E_PRCI', if_true: files('sifive_e_prci.c')) | ||
77 | +softmmu_ss.add(when: 'CONFIG_SIFIVE_U_PRCI', if_true: files('sifive_u_prci.c')) | ||
78 | |||
79 | # PKUnity SoC devices | ||
80 | softmmu_ss.add(when: 'CONFIG_PUV3', if_true: files('puv3_pm.c')) | ||
81 | diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig | ||
82 | index XXXXXXX..XXXXXXX 100644 | ||
83 | --- a/hw/riscv/Kconfig | ||
84 | +++ b/hw/riscv/Kconfig | ||
85 | @@ -XXX,XX +XXX,XX @@ config SIFIVE_U | ||
86 | select HART | ||
87 | select SIFIVE | ||
88 | select SIFIVE_PDMA | ||
89 | + select SIFIVE_U_PRCI | ||
90 | select UNIMP | ||
91 | |||
92 | config SPIKE | ||
93 | diff --git a/hw/riscv/meson.build b/hw/riscv/meson.build | ||
94 | index XXXXXXX..XXXXXXX 100644 | ||
95 | --- a/hw/riscv/meson.build | ||
96 | +++ b/hw/riscv/meson.build | ||
97 | @@ -XXX,XX +XXX,XX @@ riscv_ss.add(when: 'CONFIG_SIFIVE', if_true: files('sifive_uart.c')) | ||
98 | riscv_ss.add(when: 'CONFIG_SIFIVE_E', if_true: files('sifive_e.c')) | ||
99 | riscv_ss.add(when: 'CONFIG_SIFIVE_U', if_true: files('sifive_u.c')) | ||
100 | riscv_ss.add(when: 'CONFIG_SIFIVE_U', if_true: files('sifive_u_otp.c')) | ||
101 | -riscv_ss.add(when: 'CONFIG_SIFIVE_U', if_true: files('sifive_u_prci.c')) | ||
102 | riscv_ss.add(when: 'CONFIG_SPIKE', if_true: files('riscv_htif.c')) | ||
103 | riscv_ss.add(when: 'CONFIG_SPIKE', if_true: files('spike.c')) | ||
104 | riscv_ss.add(when: 'CONFIG_MICROCHIP_PFSOC', if_true: files('microchip_pfsoc.c')) | ||
105 | -- | 103 | -- |
106 | 2.28.0 | 104 | 2.47.1 |
107 | |||
108 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Philippe Mathieu-Daudé <philmd@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | This is an effort to clean up the hw/riscv directory. Ideally it | 3 | The HTIF interface is RISC-V specific, add |
4 | should only contain the RISC-V SoC / machine codes plus generic | 4 | it within the MAINTAINERS section covering |
5 | codes. Let's move sifive_e_prci model to hw/misc directory. | 5 | hw/riscv/. |
6 | 6 | ||
7 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 7 | Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Message-Id: <1599129623-68957-2-git-send-email-bmeng.cn@gmail.com> | 9 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
10 | Message-ID: <20241129154304.34946-2-philmd@linaro.org> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 12 | --- |
12 | include/hw/{riscv => misc}/sifive_e_prci.h | 0 | 13 | MAINTAINERS | 2 ++ |
13 | hw/{riscv => misc}/sifive_e_prci.c | 2 +- | 14 | 1 file changed, 2 insertions(+) |
14 | hw/riscv/sifive_e.c | 2 +- | ||
15 | hw/misc/Kconfig | 3 +++ | ||
16 | hw/misc/meson.build | 3 +++ | ||
17 | hw/riscv/Kconfig | 1 + | ||
18 | hw/riscv/meson.build | 1 - | ||
19 | 7 files changed, 9 insertions(+), 3 deletions(-) | ||
20 | rename include/hw/{riscv => misc}/sifive_e_prci.h (100%) | ||
21 | rename hw/{riscv => misc}/sifive_e_prci.c (99%) | ||
22 | 15 | ||
23 | diff --git a/include/hw/riscv/sifive_e_prci.h b/include/hw/misc/sifive_e_prci.h | 16 | diff --git a/MAINTAINERS b/MAINTAINERS |
24 | similarity index 100% | ||
25 | rename from include/hw/riscv/sifive_e_prci.h | ||
26 | rename to include/hw/misc/sifive_e_prci.h | ||
27 | diff --git a/hw/riscv/sifive_e_prci.c b/hw/misc/sifive_e_prci.c | ||
28 | similarity index 99% | ||
29 | rename from hw/riscv/sifive_e_prci.c | ||
30 | rename to hw/misc/sifive_e_prci.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
32 | --- a/hw/riscv/sifive_e_prci.c | 18 | --- a/MAINTAINERS |
33 | +++ b/hw/misc/sifive_e_prci.c | 19 | +++ b/MAINTAINERS |
34 | @@ -XXX,XX +XXX,XX @@ | 20 | @@ -XXX,XX +XXX,XX @@ S: Supported |
35 | #include "qemu/log.h" | 21 | F: configs/targets/riscv* |
36 | #include "qemu/module.h" | 22 | F: docs/system/target-riscv.rst |
37 | #include "hw/hw.h" | 23 | F: target/riscv/ |
38 | -#include "hw/riscv/sifive_e_prci.h" | 24 | +F: hw/char/riscv_htif.c |
39 | +#include "hw/misc/sifive_e_prci.h" | 25 | F: hw/riscv/ |
40 | 26 | F: hw/intc/riscv* | |
41 | static uint64_t sifive_e_prci_read(void *opaque, hwaddr addr, unsigned int size) | 27 | +F: include/hw/char/riscv_htif.h |
42 | { | 28 | F: include/hw/riscv/ |
43 | diff --git a/hw/riscv/sifive_e.c b/hw/riscv/sifive_e.c | 29 | F: linux-user/host/riscv32/ |
44 | index XXXXXXX..XXXXXXX 100644 | 30 | F: linux-user/host/riscv64/ |
45 | --- a/hw/riscv/sifive_e.c | ||
46 | +++ b/hw/riscv/sifive_e.c | ||
47 | @@ -XXX,XX +XXX,XX @@ | ||
48 | #include "hw/riscv/sifive_clint.h" | ||
49 | #include "hw/riscv/sifive_uart.h" | ||
50 | #include "hw/riscv/sifive_e.h" | ||
51 | -#include "hw/riscv/sifive_e_prci.h" | ||
52 | #include "hw/riscv/boot.h" | ||
53 | +#include "hw/misc/sifive_e_prci.h" | ||
54 | #include "chardev/char.h" | ||
55 | #include "sysemu/arch_init.h" | ||
56 | #include "sysemu/sysemu.h" | ||
57 | diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig | ||
58 | index XXXXXXX..XXXXXXX 100644 | ||
59 | --- a/hw/misc/Kconfig | ||
60 | +++ b/hw/misc/Kconfig | ||
61 | @@ -XXX,XX +XXX,XX @@ config MAC_VIA | ||
62 | config AVR_POWER | ||
63 | bool | ||
64 | |||
65 | +config SIFIVE_E_PRCI | ||
66 | + bool | ||
67 | + | ||
68 | source macio/Kconfig | ||
69 | diff --git a/hw/misc/meson.build b/hw/misc/meson.build | ||
70 | index XXXXXXX..XXXXXXX 100644 | ||
71 | --- a/hw/misc/meson.build | ||
72 | +++ b/hw/misc/meson.build | ||
73 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_ARM11SCU', if_true: files('arm11scu.c')) | ||
74 | # Mac devices | ||
75 | softmmu_ss.add(when: 'CONFIG_MOS6522', if_true: files('mos6522.c')) | ||
76 | |||
77 | +# RISC-V devices | ||
78 | +softmmu_ss.add(when: 'CONFIG_SIFIVE_E_PRCI', if_true: files('sifive_e_prci.c')) | ||
79 | + | ||
80 | # PKUnity SoC devices | ||
81 | softmmu_ss.add(when: 'CONFIG_PUV3', if_true: files('puv3_pm.c')) | ||
82 | |||
83 | diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig | ||
84 | index XXXXXXX..XXXXXXX 100644 | ||
85 | --- a/hw/riscv/Kconfig | ||
86 | +++ b/hw/riscv/Kconfig | ||
87 | @@ -XXX,XX +XXX,XX @@ config SIFIVE_E | ||
88 | bool | ||
89 | select HART | ||
90 | select SIFIVE | ||
91 | + select SIFIVE_E_PRCI | ||
92 | select UNIMP | ||
93 | |||
94 | config SIFIVE_U | ||
95 | diff --git a/hw/riscv/meson.build b/hw/riscv/meson.build | ||
96 | index XXXXXXX..XXXXXXX 100644 | ||
97 | --- a/hw/riscv/meson.build | ||
98 | +++ b/hw/riscv/meson.build | ||
99 | @@ -XXX,XX +XXX,XX @@ riscv_ss.add(when: 'CONFIG_SIFIVE', if_true: files('sifive_plic.c')) | ||
100 | riscv_ss.add(when: 'CONFIG_SIFIVE', if_true: files('sifive_test.c')) | ||
101 | riscv_ss.add(when: 'CONFIG_SIFIVE', if_true: files('sifive_uart.c')) | ||
102 | riscv_ss.add(when: 'CONFIG_SIFIVE_E', if_true: files('sifive_e.c')) | ||
103 | -riscv_ss.add(when: 'CONFIG_SIFIVE_E', if_true: files('sifive_e_prci.c')) | ||
104 | riscv_ss.add(when: 'CONFIG_SIFIVE_U', if_true: files('sifive_u.c')) | ||
105 | riscv_ss.add(when: 'CONFIG_SIFIVE_U', if_true: files('sifive_u_otp.c')) | ||
106 | riscv_ss.add(when: 'CONFIG_SIFIVE_U', if_true: files('sifive_u_prci.c')) | ||
107 | -- | 31 | -- |
108 | 2.28.0 | 32 | 2.47.1 |
109 | 33 | ||
110 | 34 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Philippe Mathieu-Daudé <philmd@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | This is an effort to clean up the hw/riscv directory. Ideally it | 3 | Since our RISC-V system emulation is only built for little |
4 | should only contain the RISC-V SoC / machine codes plus generic | 4 | endian, the HTIF device aims to interface with little endian |
5 | codes. Let's move riscv_htif model to hw/char directory. | 5 | memory accesses, thus we can explicit htif_mm_ops:endianness |
6 | being DEVICE_LITTLE_ENDIAN. | ||
6 | 7 | ||
7 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 8 | In that case tswap64() is equivalent to le64_to_cpu(), as in |
9 | "convert this 64-bit little-endian value into host cpu order". | ||
10 | Replace to simplify. | ||
11 | |||
12 | Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Message-Id: <1599129623-68957-8-git-send-email-bmeng.cn@gmail.com> | 14 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
15 | Message-ID: <20241129154304.34946-3-philmd@linaro.org> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 17 | --- |
12 | include/hw/{riscv => char}/riscv_htif.h | 0 | 18 | hw/char/riscv_htif.c | 11 ++++++----- |
13 | hw/{riscv => char}/riscv_htif.c | 2 +- | 19 | 1 file changed, 6 insertions(+), 5 deletions(-) |
14 | hw/riscv/spike.c | 2 +- | ||
15 | hw/char/Kconfig | 3 +++ | ||
16 | hw/char/meson.build | 1 + | ||
17 | hw/riscv/Kconfig | 3 --- | ||
18 | hw/riscv/meson.build | 1 - | ||
19 | 7 files changed, 6 insertions(+), 6 deletions(-) | ||
20 | rename include/hw/{riscv => char}/riscv_htif.h (100%) | ||
21 | rename hw/{riscv => char}/riscv_htif.c (99%) | ||
22 | 20 | ||
23 | diff --git a/include/hw/riscv/riscv_htif.h b/include/hw/char/riscv_htif.h | 21 | diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c |
24 | similarity index 100% | ||
25 | rename from include/hw/riscv/riscv_htif.h | ||
26 | rename to include/hw/char/riscv_htif.h | ||
27 | diff --git a/hw/riscv/riscv_htif.c b/hw/char/riscv_htif.c | ||
28 | similarity index 99% | ||
29 | rename from hw/riscv/riscv_htif.c | ||
30 | rename to hw/char/riscv_htif.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
32 | --- a/hw/riscv/riscv_htif.c | 23 | --- a/hw/char/riscv_htif.c |
33 | +++ b/hw/char/riscv_htif.c | 24 | +++ b/hw/char/riscv_htif.c |
34 | @@ -XXX,XX +XXX,XX @@ | 25 | @@ -XXX,XX +XXX,XX @@ |
35 | #include "qapi/error.h" | ||
36 | #include "qemu/log.h" | ||
37 | #include "hw/sysbus.h" | ||
38 | +#include "hw/char/riscv_htif.h" | ||
39 | #include "hw/char/serial.h" | ||
40 | #include "chardev/char.h" | ||
41 | #include "chardev/char-fe.h" | ||
42 | -#include "hw/riscv/riscv_htif.h" | ||
43 | #include "qemu/timer.h" | 26 | #include "qemu/timer.h" |
44 | #include "qemu/error-report.h" | 27 | #include "qemu/error-report.h" |
45 | 28 | #include "exec/address-spaces.h" | |
46 | diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c | 29 | -#include "exec/tswap.h" |
47 | index XXXXXXX..XXXXXXX 100644 | 30 | +#include "qemu/bswap.h" |
48 | --- a/hw/riscv/spike.c | 31 | #include "sysemu/dma.h" |
49 | +++ b/hw/riscv/spike.c | 32 | #include "sysemu/runstate.h" |
50 | @@ -XXX,XX +XXX,XX @@ | 33 | |
51 | #include "hw/loader.h" | 34 | @@ -XXX,XX +XXX,XX @@ static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written) |
52 | #include "hw/sysbus.h" | 35 | } else { |
53 | #include "target/riscv/cpu.h" | 36 | uint64_t syscall[8]; |
54 | -#include "hw/riscv/riscv_htif.h" | 37 | cpu_physical_memory_read(payload, syscall, sizeof(syscall)); |
55 | #include "hw/riscv/riscv_hart.h" | 38 | - if (tswap64(syscall[0]) == PK_SYS_WRITE && |
56 | #include "hw/riscv/spike.h" | 39 | - tswap64(syscall[1]) == HTIF_DEV_CONSOLE && |
57 | #include "hw/riscv/boot.h" | 40 | - tswap64(syscall[3]) == HTIF_CONSOLE_CMD_PUTC) { |
58 | #include "hw/riscv/numa.h" | 41 | + if (le64_to_cpu(syscall[0]) == PK_SYS_WRITE && |
59 | +#include "hw/char/riscv_htif.h" | 42 | + le64_to_cpu(syscall[1]) == HTIF_DEV_CONSOLE && |
60 | #include "hw/intc/sifive_clint.h" | 43 | + le64_to_cpu(syscall[3]) == HTIF_CONSOLE_CMD_PUTC) { |
61 | #include "chardev/char.h" | 44 | uint8_t ch; |
62 | #include "sysemu/arch_init.h" | 45 | - cpu_physical_memory_read(tswap64(syscall[2]), &ch, 1); |
63 | diff --git a/hw/char/Kconfig b/hw/char/Kconfig | 46 | + cpu_physical_memory_read(le64_to_cpu(syscall[2]), &ch, 1); |
64 | index XXXXXXX..XXXXXXX 100644 | 47 | /* |
65 | --- a/hw/char/Kconfig | 48 | * XXX this blocks entire thread. Rewrite to use |
66 | +++ b/hw/char/Kconfig | 49 | * qemu_chr_fe_write and background I/O callbacks |
67 | @@ -XXX,XX +XXX,XX @@ | 50 | @@ -XXX,XX +XXX,XX @@ static void htif_mm_write(void *opaque, hwaddr addr, |
68 | config ESCC | 51 | static const MemoryRegionOps htif_mm_ops = { |
69 | bool | 52 | .read = htif_mm_read, |
70 | 53 | .write = htif_mm_write, | |
71 | +config HTIF | 54 | + .endianness = DEVICE_LITTLE_ENDIAN, |
72 | + bool | 55 | }; |
73 | + | 56 | |
74 | config PARALLEL | 57 | HTIFState *htif_mm_init(MemoryRegion *address_space, Chardev *chr, |
75 | bool | ||
76 | default y | ||
77 | diff --git a/hw/char/meson.build b/hw/char/meson.build | ||
78 | index XXXXXXX..XXXXXXX 100644 | ||
79 | --- a/hw/char/meson.build | ||
80 | +++ b/hw/char/meson.build | ||
81 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_SH4', if_true: files('sh_serial.c')) | ||
82 | softmmu_ss.add(when: 'CONFIG_STM32F2XX_USART', if_true: files('stm32f2xx_usart.c')) | ||
83 | softmmu_ss.add(when: 'CONFIG_MCHP_PFSOC_MMUART', if_true: files('mchp_pfsoc_mmuart.c')) | ||
84 | |||
85 | +specific_ss.add(when: 'CONFIG_HTIF', if_true: files('riscv_htif.c')) | ||
86 | specific_ss.add(when: 'CONFIG_TERMINAL3270', if_true: files('terminal3270.c')) | ||
87 | specific_ss.add(when: 'CONFIG_VIRTIO', if_true: files('virtio-serial-bus.c')) | ||
88 | specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_vty.c')) | ||
89 | diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig | ||
90 | index XXXXXXX..XXXXXXX 100644 | ||
91 | --- a/hw/riscv/Kconfig | ||
92 | +++ b/hw/riscv/Kconfig | ||
93 | @@ -XXX,XX +XXX,XX @@ | ||
94 | -config HTIF | ||
95 | - bool | ||
96 | - | ||
97 | config HART | ||
98 | bool | ||
99 | |||
100 | diff --git a/hw/riscv/meson.build b/hw/riscv/meson.build | ||
101 | index XXXXXXX..XXXXXXX 100644 | ||
102 | --- a/hw/riscv/meson.build | ||
103 | +++ b/hw/riscv/meson.build | ||
104 | @@ -XXX,XX +XXX,XX @@ riscv_ss.add(when: 'CONFIG_SIFIVE', if_true: files('sifive_test.c')) | ||
105 | riscv_ss.add(when: 'CONFIG_SIFIVE', if_true: files('sifive_uart.c')) | ||
106 | riscv_ss.add(when: 'CONFIG_SIFIVE_E', if_true: files('sifive_e.c')) | ||
107 | riscv_ss.add(when: 'CONFIG_SIFIVE_U', if_true: files('sifive_u.c')) | ||
108 | -riscv_ss.add(when: 'CONFIG_SPIKE', if_true: files('riscv_htif.c')) | ||
109 | riscv_ss.add(when: 'CONFIG_SPIKE', if_true: files('spike.c')) | ||
110 | riscv_ss.add(when: 'CONFIG_MICROCHIP_PFSOC', if_true: files('microchip_pfsoc.c')) | ||
111 | |||
112 | -- | 58 | -- |
113 | 2.28.0 | 59 | 2.47.1 |
114 | 60 | ||
115 | 61 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Philippe Mathieu-Daudé <philmd@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Cadence SD/SDIO/eMMC Host Controller (SD4HC) is an SDHCI compatible | 3 | Looking at htif_mm_ops[] read/write handlers, we notice they |
4 | controller. The SDHCI compatible registers start from offset 0x200, | 4 | expect 32-bit values to accumulate into to the 'fromhost' and |
5 | which are called Slot Register Set (SRS) in its datasheet. | 5 | 'tohost' 64-bit variables. Explicit by setting the .impl |
6 | min/max fields. | ||
6 | 7 | ||
7 | This creates a Cadence SDHCI model built on top of the existing | 8 | Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
8 | generic SDHCI model. Cadence specific Host Register Set (HRS) is | ||
9 | implemented to make guest software happy. | ||
10 | |||
11 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | ||
12 | Acked-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
13 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Acked-by: Alistair Francis <alistair.francis@wdc.com> |
14 | Message-Id: <1598924352-89526-8-git-send-email-bmeng.cn@gmail.com> | 10 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
11 | Message-ID: <20241129154304.34946-4-philmd@linaro.org> | ||
15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
16 | --- | 13 | --- |
17 | include/hw/sd/cadence_sdhci.h | 47 +++++++++ | 14 | hw/char/riscv_htif.c | 4 ++++ |
18 | hw/sd/cadence_sdhci.c | 193 ++++++++++++++++++++++++++++++++++ | 15 | 1 file changed, 4 insertions(+) |
19 | hw/sd/Kconfig | 4 + | ||
20 | hw/sd/meson.build | 1 + | ||
21 | 4 files changed, 245 insertions(+) | ||
22 | create mode 100644 include/hw/sd/cadence_sdhci.h | ||
23 | create mode 100644 hw/sd/cadence_sdhci.c | ||
24 | 16 | ||
25 | diff --git a/include/hw/sd/cadence_sdhci.h b/include/hw/sd/cadence_sdhci.h | 17 | diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c |
26 | new file mode 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
27 | index XXXXXXX..XXXXXXX | 19 | --- a/hw/char/riscv_htif.c |
28 | --- /dev/null | 20 | +++ b/hw/char/riscv_htif.c |
29 | +++ b/include/hw/sd/cadence_sdhci.h | 21 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps htif_mm_ops = { |
30 | @@ -XXX,XX +XXX,XX @@ | 22 | .read = htif_mm_read, |
31 | +/* | 23 | .write = htif_mm_write, |
32 | + * Cadence SDHCI emulation | 24 | .endianness = DEVICE_LITTLE_ENDIAN, |
33 | + * | ||
34 | + * Copyright (c) 2020 Wind River Systems, Inc. | ||
35 | + * | ||
36 | + * Author: | ||
37 | + * Bin Meng <bin.meng@windriver.com> | ||
38 | + * | ||
39 | + * This program is free software; you can redistribute it and/or | ||
40 | + * modify it under the terms of the GNU General Public License as | ||
41 | + * published by the Free Software Foundation; either version 2 or | ||
42 | + * (at your option) version 3 of the License. | ||
43 | + * | ||
44 | + * This program is distributed in the hope that it will be useful, | ||
45 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
46 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
47 | + * GNU General Public License for more details. | ||
48 | + * | ||
49 | + * You should have received a copy of the GNU General Public License along | ||
50 | + * with this program; if not, see <http://www.gnu.org/licenses/>. | ||
51 | + */ | ||
52 | + | ||
53 | +#ifndef CADENCE_SDHCI_H | ||
54 | +#define CADENCE_SDHCI_H | ||
55 | + | ||
56 | +#include "hw/sd/sdhci.h" | ||
57 | + | ||
58 | +#define CADENCE_SDHCI_REG_SIZE 0x100 | ||
59 | +#define CADENCE_SDHCI_NUM_REGS (CADENCE_SDHCI_REG_SIZE / sizeof(uint32_t)) | ||
60 | + | ||
61 | +typedef struct CadenceSDHCIState { | ||
62 | + SysBusDevice parent; | ||
63 | + | ||
64 | + MemoryRegion container; | ||
65 | + MemoryRegion iomem; | ||
66 | + BusState *bus; | ||
67 | + | ||
68 | + uint32_t regs[CADENCE_SDHCI_NUM_REGS]; | ||
69 | + | ||
70 | + SDHCIState sdhci; | ||
71 | +} CadenceSDHCIState; | ||
72 | + | ||
73 | +#define TYPE_CADENCE_SDHCI "cadence.sdhci" | ||
74 | +#define CADENCE_SDHCI(obj) OBJECT_CHECK(CadenceSDHCIState, (obj), \ | ||
75 | + TYPE_CADENCE_SDHCI) | ||
76 | + | ||
77 | +#endif /* CADENCE_SDHCI_H */ | ||
78 | diff --git a/hw/sd/cadence_sdhci.c b/hw/sd/cadence_sdhci.c | ||
79 | new file mode 100644 | ||
80 | index XXXXXXX..XXXXXXX | ||
81 | --- /dev/null | ||
82 | +++ b/hw/sd/cadence_sdhci.c | ||
83 | @@ -XXX,XX +XXX,XX @@ | ||
84 | +/* | ||
85 | + * Cadence SDHCI emulation | ||
86 | + * | ||
87 | + * Copyright (c) 2020 Wind River Systems, Inc. | ||
88 | + * | ||
89 | + * Author: | ||
90 | + * Bin Meng <bin.meng@windriver.com> | ||
91 | + * | ||
92 | + * This program is free software; you can redistribute it and/or | ||
93 | + * modify it under the terms of the GNU General Public License as | ||
94 | + * published by the Free Software Foundation; either version 2 or | ||
95 | + * (at your option) version 3 of the License. | ||
96 | + * | ||
97 | + * This program is distributed in the hope that it will be useful, | ||
98 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
99 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
100 | + * GNU General Public License for more details. | ||
101 | + * | ||
102 | + * You should have received a copy of the GNU General Public License along | ||
103 | + * with this program; if not, see <http://www.gnu.org/licenses/>. | ||
104 | + */ | ||
105 | + | ||
106 | +#include "qemu/osdep.h" | ||
107 | +#include "qemu/bitops.h" | ||
108 | +#include "qemu/error-report.h" | ||
109 | +#include "qemu/log.h" | ||
110 | +#include "qapi/error.h" | ||
111 | +#include "migration/vmstate.h" | ||
112 | +#include "hw/irq.h" | ||
113 | +#include "hw/sd/cadence_sdhci.h" | ||
114 | +#include "sdhci-internal.h" | ||
115 | + | ||
116 | +/* HRS - Host Register Set (specific to Cadence) */ | ||
117 | + | ||
118 | +#define CADENCE_SDHCI_HRS00 0x00 /* general information */ | ||
119 | +#define CADENCE_SDHCI_HRS00_SWR BIT(0) | ||
120 | +#define CADENCE_SDHCI_HRS00_POR_VAL 0x00010000 | ||
121 | + | ||
122 | +#define CADENCE_SDHCI_HRS04 0x10 /* PHY access port */ | ||
123 | +#define CADENCE_SDHCI_HRS04_WR BIT(24) | ||
124 | +#define CADENCE_SDHCI_HRS04_RD BIT(25) | ||
125 | +#define CADENCE_SDHCI_HRS04_ACK BIT(26) | ||
126 | + | ||
127 | +#define CADENCE_SDHCI_HRS06 0x18 /* eMMC control */ | ||
128 | +#define CADENCE_SDHCI_HRS06_TUNE_UP BIT(15) | ||
129 | + | ||
130 | +/* SRS - Slot Register Set (SDHCI-compatible) */ | ||
131 | + | ||
132 | +#define CADENCE_SDHCI_SRS_BASE 0x200 | ||
133 | + | ||
134 | +#define TO_REG(addr) ((addr) / sizeof(uint32_t)) | ||
135 | + | ||
136 | +static void cadence_sdhci_instance_init(Object *obj) | ||
137 | +{ | ||
138 | + CadenceSDHCIState *s = CADENCE_SDHCI(obj); | ||
139 | + | ||
140 | + object_initialize_child(OBJECT(s), "generic-sdhci", | ||
141 | + &s->sdhci, TYPE_SYSBUS_SDHCI); | ||
142 | +} | ||
143 | + | ||
144 | +static void cadence_sdhci_reset(DeviceState *dev) | ||
145 | +{ | ||
146 | + CadenceSDHCIState *s = CADENCE_SDHCI(dev); | ||
147 | + | ||
148 | + memset(s->regs, 0, CADENCE_SDHCI_REG_SIZE); | ||
149 | + s->regs[TO_REG(CADENCE_SDHCI_HRS00)] = CADENCE_SDHCI_HRS00_POR_VAL; | ||
150 | + | ||
151 | + device_cold_reset(DEVICE(&s->sdhci)); | ||
152 | +} | ||
153 | + | ||
154 | +static uint64_t cadence_sdhci_read(void *opaque, hwaddr addr, unsigned int size) | ||
155 | +{ | ||
156 | + CadenceSDHCIState *s = opaque; | ||
157 | + uint32_t val; | ||
158 | + | ||
159 | + val = s->regs[TO_REG(addr)]; | ||
160 | + | ||
161 | + return (uint64_t)val; | ||
162 | +} | ||
163 | + | ||
164 | +static void cadence_sdhci_write(void *opaque, hwaddr addr, uint64_t val, | ||
165 | + unsigned int size) | ||
166 | +{ | ||
167 | + CadenceSDHCIState *s = opaque; | ||
168 | + uint32_t val32 = (uint32_t)val; | ||
169 | + | ||
170 | + switch (addr) { | ||
171 | + case CADENCE_SDHCI_HRS00: | ||
172 | + /* | ||
173 | + * The only writable bit is SWR (software reset) and it automatically | ||
174 | + * clears to zero, so essentially this register remains unchanged. | ||
175 | + */ | ||
176 | + if (val32 & CADENCE_SDHCI_HRS00_SWR) { | ||
177 | + cadence_sdhci_reset(DEVICE(s)); | ||
178 | + } | ||
179 | + | ||
180 | + break; | ||
181 | + case CADENCE_SDHCI_HRS04: | ||
182 | + /* | ||
183 | + * Only emulate the ACK bit behavior when read or write transaction | ||
184 | + * are requested. | ||
185 | + */ | ||
186 | + if (val32 & (CADENCE_SDHCI_HRS04_WR | CADENCE_SDHCI_HRS04_RD)) { | ||
187 | + val32 |= CADENCE_SDHCI_HRS04_ACK; | ||
188 | + } else { | ||
189 | + val32 &= ~CADENCE_SDHCI_HRS04_ACK; | ||
190 | + } | ||
191 | + | ||
192 | + s->regs[TO_REG(addr)] = val32; | ||
193 | + break; | ||
194 | + case CADENCE_SDHCI_HRS06: | ||
195 | + if (val32 & CADENCE_SDHCI_HRS06_TUNE_UP) { | ||
196 | + val32 &= ~CADENCE_SDHCI_HRS06_TUNE_UP; | ||
197 | + } | ||
198 | + | ||
199 | + s->regs[TO_REG(addr)] = val32; | ||
200 | + break; | ||
201 | + default: | ||
202 | + s->regs[TO_REG(addr)] = val32; | ||
203 | + break; | ||
204 | + } | ||
205 | +} | ||
206 | + | ||
207 | +static const MemoryRegionOps cadence_sdhci_ops = { | ||
208 | + .read = cadence_sdhci_read, | ||
209 | + .write = cadence_sdhci_write, | ||
210 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
211 | + .impl = { | 25 | + .impl = { |
212 | + .min_access_size = 4, | 26 | + .min_access_size = 4, |
213 | + .max_access_size = 4, | 27 | + .max_access_size = 4, |
214 | + }, | 28 | + }, |
215 | + .valid = { | 29 | }; |
216 | + .min_access_size = 4, | 30 | |
217 | + .max_access_size = 4, | 31 | HTIFState *htif_mm_init(MemoryRegion *address_space, Chardev *chr, |
218 | + } | ||
219 | +}; | ||
220 | + | ||
221 | +static void cadence_sdhci_realize(DeviceState *dev, Error **errp) | ||
222 | +{ | ||
223 | + CadenceSDHCIState *s = CADENCE_SDHCI(dev); | ||
224 | + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); | ||
225 | + SysBusDevice *sbd_sdhci = SYS_BUS_DEVICE(&s->sdhci); | ||
226 | + | ||
227 | + memory_region_init(&s->container, OBJECT(s), | ||
228 | + "cadence.sdhci-container", 0x1000); | ||
229 | + sysbus_init_mmio(sbd, &s->container); | ||
230 | + | ||
231 | + memory_region_init_io(&s->iomem, OBJECT(s), &cadence_sdhci_ops, | ||
232 | + s, TYPE_CADENCE_SDHCI, CADENCE_SDHCI_REG_SIZE); | ||
233 | + memory_region_add_subregion(&s->container, 0, &s->iomem); | ||
234 | + | ||
235 | + sysbus_realize(sbd_sdhci, errp); | ||
236 | + memory_region_add_subregion(&s->container, CADENCE_SDHCI_SRS_BASE, | ||
237 | + sysbus_mmio_get_region(sbd_sdhci, 0)); | ||
238 | + | ||
239 | + /* propagate irq and "sd-bus" from generic-sdhci */ | ||
240 | + sysbus_pass_irq(sbd, sbd_sdhci); | ||
241 | + s->bus = qdev_get_child_bus(DEVICE(sbd_sdhci), "sd-bus"); | ||
242 | +} | ||
243 | + | ||
244 | +static const VMStateDescription vmstate_cadence_sdhci = { | ||
245 | + .name = TYPE_CADENCE_SDHCI, | ||
246 | + .version_id = 1, | ||
247 | + .fields = (VMStateField[]) { | ||
248 | + VMSTATE_UINT32_ARRAY(regs, CadenceSDHCIState, CADENCE_SDHCI_NUM_REGS), | ||
249 | + VMSTATE_END_OF_LIST(), | ||
250 | + }, | ||
251 | +}; | ||
252 | + | ||
253 | +static void cadence_sdhci_class_init(ObjectClass *classp, void *data) | ||
254 | +{ | ||
255 | + DeviceClass *dc = DEVICE_CLASS(classp); | ||
256 | + | ||
257 | + dc->desc = "Cadence SD/SDIO/eMMC Host Controller (SD4HC)"; | ||
258 | + dc->realize = cadence_sdhci_realize; | ||
259 | + dc->reset = cadence_sdhci_reset; | ||
260 | + dc->vmsd = &vmstate_cadence_sdhci; | ||
261 | +} | ||
262 | + | ||
263 | +static TypeInfo cadence_sdhci_info = { | ||
264 | + .name = TYPE_CADENCE_SDHCI, | ||
265 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
266 | + .instance_size = sizeof(CadenceSDHCIState), | ||
267 | + .instance_init = cadence_sdhci_instance_init, | ||
268 | + .class_init = cadence_sdhci_class_init, | ||
269 | +}; | ||
270 | + | ||
271 | +static void cadence_sdhci_register_types(void) | ||
272 | +{ | ||
273 | + type_register_static(&cadence_sdhci_info); | ||
274 | +} | ||
275 | + | ||
276 | +type_init(cadence_sdhci_register_types) | ||
277 | diff --git a/hw/sd/Kconfig b/hw/sd/Kconfig | ||
278 | index XXXXXXX..XXXXXXX 100644 | ||
279 | --- a/hw/sd/Kconfig | ||
280 | +++ b/hw/sd/Kconfig | ||
281 | @@ -XXX,XX +XXX,XX @@ config SDHCI_PCI | ||
282 | default y if PCI_DEVICES | ||
283 | depends on PCI | ||
284 | select SDHCI | ||
285 | + | ||
286 | +config CADENCE_SDHCI | ||
287 | + bool | ||
288 | + select SDHCI | ||
289 | diff --git a/hw/sd/meson.build b/hw/sd/meson.build | ||
290 | index XXXXXXX..XXXXXXX 100644 | ||
291 | --- a/hw/sd/meson.build | ||
292 | +++ b/hw/sd/meson.build | ||
293 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_PXA2XX', if_true: files('pxa2xx_mmci.c')) | ||
294 | softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_sdhost.c')) | ||
295 | softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_sdhci.c')) | ||
296 | softmmu_ss.add(when: 'CONFIG_ALLWINNER_H3', if_true: files('allwinner-sdhost.c')) | ||
297 | +softmmu_ss.add(when: 'CONFIG_CADENCE_SDHCI', if_true: files('cadence_sdhci.c')) | ||
298 | -- | 32 | -- |
299 | 2.28.0 | 33 | 2.47.1 |
300 | 34 | ||
301 | 35 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Jim Shu <jim.shu@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | At present the CLINT timestamp is using a hard-coded timebase | 3 | Larger initrd image will overlap the DTB at 3GB address. Since 64-bit |
4 | frequency value SIFIVE_CLINT_TIMEBASE_FREQ. This might not be | 4 | system doesn't have 32-bit addressable issue, we just load DTB to the end |
5 | true for all boards. | 5 | of dram in 64-bit system. |
6 | 6 | ||
7 | Add a new 'timebase-freq' property to the CLINT device, and | 7 | Signed-off-by: Jim Shu <jim.shu@sifive.com> |
8 | update various functions to accept this as a parameter. | ||
9 | |||
10 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | ||
11 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
12 | Message-Id: <1598924352-89526-16-git-send-email-bmeng.cn@gmail.com> | 9 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
10 | Message-ID: <20241120153935.24706-2-jim.shu@sifive.com> | ||
11 | [ Changes by AF | ||
12 | - Store fdt_load_addr_hi32 in the reset vector | ||
13 | ] | ||
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
14 | --- | 15 | --- |
15 | include/hw/riscv/sifive_clint.h | 4 +++- | 16 | include/hw/riscv/boot.h | 2 +- |
16 | target/riscv/cpu.h | 6 ++++-- | 17 | hw/riscv/boot.c | 14 +++++++++----- |
17 | hw/riscv/microchip_pfsoc.c | 6 +++++- | 18 | hw/riscv/microchip_pfsoc.c | 4 ++-- |
18 | hw/riscv/sifive_clint.c | 26 +++++++++++++++----------- | 19 | hw/riscv/sifive_u.c | 8 +++++--- |
19 | hw/riscv/sifive_e.c | 3 ++- | 20 | hw/riscv/spike.c | 4 ++-- |
20 | hw/riscv/sifive_u.c | 3 ++- | 21 | hw/riscv/virt.c | 2 +- |
21 | hw/riscv/spike.c | 3 ++- | 22 | 6 files changed, 20 insertions(+), 14 deletions(-) |
22 | hw/riscv/virt.c | 3 ++- | ||
23 | target/riscv/cpu_helper.c | 4 +++- | ||
24 | target/riscv/csr.c | 4 ++-- | ||
25 | 10 files changed, 40 insertions(+), 22 deletions(-) | ||
26 | 23 | ||
27 | diff --git a/include/hw/riscv/sifive_clint.h b/include/hw/riscv/sifive_clint.h | 24 | diff --git a/include/hw/riscv/boot.h b/include/hw/riscv/boot.h |
28 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
29 | --- a/include/hw/riscv/sifive_clint.h | 26 | --- a/include/hw/riscv/boot.h |
30 | +++ b/include/hw/riscv/sifive_clint.h | 27 | +++ b/include/hw/riscv/boot.h |
31 | @@ -XXX,XX +XXX,XX @@ typedef struct SiFiveCLINTState { | 28 | @@ -XXX,XX +XXX,XX @@ target_ulong riscv_load_kernel(MachineState *machine, |
32 | uint32_t timecmp_base; | 29 | bool load_initrd, |
33 | uint32_t time_base; | 30 | symbol_fn_t sym_cb); |
34 | uint32_t aperture_size; | 31 | uint64_t riscv_compute_fdt_addr(hwaddr dram_start, uint64_t dram_size, |
35 | + uint32_t timebase_freq; | 32 | - MachineState *ms); |
36 | } SiFiveCLINTState; | 33 | + MachineState *ms, RISCVHartArrayState *harts); |
37 | 34 | void riscv_load_fdt(hwaddr fdt_addr, void *fdt); | |
38 | DeviceState *sifive_clint_create(hwaddr addr, hwaddr size, | 35 | void riscv_setup_rom_reset_vec(MachineState *machine, RISCVHartArrayState *harts, |
39 | uint32_t hartid_base, uint32_t num_harts, uint32_t sip_base, | 36 | hwaddr saddr, |
40 | - uint32_t timecmp_base, uint32_t time_base, bool provide_rdtime); | 37 | diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c |
41 | + uint32_t timecmp_base, uint32_t time_base, uint32_t timebase_freq, | ||
42 | + bool provide_rdtime); | ||
43 | |||
44 | enum { | ||
45 | SIFIVE_SIP_BASE = 0x0, | ||
46 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
47 | index XXXXXXX..XXXXXXX 100644 | 38 | index XXXXXXX..XXXXXXX 100644 |
48 | --- a/target/riscv/cpu.h | 39 | --- a/hw/riscv/boot.c |
49 | +++ b/target/riscv/cpu.h | 40 | +++ b/hw/riscv/boot.c |
50 | @@ -XXX,XX +XXX,XX @@ struct CPURISCVState { | 41 | @@ -XXX,XX +XXX,XX @@ out: |
51 | pmp_table_t pmp_state; | 42 | * The FDT is fdt_packed() during the calculation. |
52 | 43 | */ | |
53 | /* machine specific rdtime callback */ | 44 | uint64_t riscv_compute_fdt_addr(hwaddr dram_base, hwaddr dram_size, |
54 | - uint64_t (*rdtime_fn)(void); | 45 | - MachineState *ms) |
55 | + uint64_t (*rdtime_fn)(uint32_t); | 46 | + MachineState *ms, RISCVHartArrayState *harts) |
56 | + uint32_t rdtime_fn_arg; | 47 | { |
57 | 48 | int ret = fdt_pack(ms->fdt); | |
58 | /* True if in debugger mode. */ | 49 | hwaddr dram_end, temp; |
59 | bool debugger; | 50 | @@ -XXX,XX +XXX,XX @@ uint64_t riscv_compute_fdt_addr(hwaddr dram_base, hwaddr dram_size, |
60 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env); | 51 | |
61 | int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint32_t interrupts); | 52 | /* |
62 | uint32_t riscv_cpu_update_mip(RISCVCPU *cpu, uint32_t mask, uint32_t value); | 53 | * We should put fdt as far as possible to avoid kernel/initrd overwriting |
63 | #define BOOL_TO_MASK(x) (-!!(x)) /* helper for riscv_cpu_update_mip value */ | 54 | - * its content. But it should be addressable by 32 bit system as well. |
64 | -void riscv_cpu_set_rdtime_fn(CPURISCVState *env, uint64_t (*fn)(void)); | 55 | - * Thus, put it at an 2MB aligned address that less than fdt size from the |
65 | +void riscv_cpu_set_rdtime_fn(CPURISCVState *env, uint64_t (*fn)(uint32_t), | 56 | - * end of dram or 3GB whichever is lesser. |
66 | + uint32_t arg); | 57 | + * its content. But it should be addressable by 32 bit system as well in RV32. |
67 | #endif | 58 | + * Thus, put it near to the end of dram in RV64, and put it near to the end |
68 | void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv); | 59 | + * of dram or 3GB whichever is lesser in RV32. |
69 | 60 | */ | |
61 | - temp = (dram_base < 3072 * MiB) ? MIN(dram_end, 3072 * MiB) : dram_end; | ||
62 | + if (!riscv_is_32bit(harts)) { | ||
63 | + temp = dram_end; | ||
64 | + } else { | ||
65 | + temp = (dram_base < 3072 * MiB) ? MIN(dram_end, 3072 * MiB) : dram_end; | ||
66 | + } | ||
67 | |||
68 | return QEMU_ALIGN_DOWN(temp - fdtsize, 2 * MiB); | ||
69 | } | ||
70 | diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c | 70 | diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c |
71 | index XXXXXXX..XXXXXXX 100644 | 71 | index XXXXXXX..XXXXXXX 100644 |
72 | --- a/hw/riscv/microchip_pfsoc.c | 72 | --- a/hw/riscv/microchip_pfsoc.c |
73 | +++ b/hw/riscv/microchip_pfsoc.c | 73 | +++ b/hw/riscv/microchip_pfsoc.c |
74 | @@ -XXX,XX +XXX,XX @@ | 74 | @@ -XXX,XX +XXX,XX @@ static void microchip_icicle_kit_machine_init(MachineState *machine) |
75 | #define BIOS_FILENAME "hss.bin" | 75 | bool kernel_as_payload = false; |
76 | #define RESET_VECTOR 0x20220000 | 76 | target_ulong firmware_end_addr, kernel_start_addr; |
77 | 77 | uint64_t kernel_entry; | |
78 | +/* CLINT timebase frequency */ | 78 | - uint32_t fdt_load_addr; |
79 | +#define CLINT_TIMEBASE_FREQ 1000000 | 79 | + uint64_t fdt_load_addr; |
80 | + | 80 | DriveInfo *dinfo = drive_get(IF_SD, 0, 0); |
81 | /* GEM version */ | 81 | |
82 | #define GEM_REVISION 0x0107010c | 82 | /* Sanity check on RAM size */ |
83 | 83 | @@ -XXX,XX +XXX,XX @@ static void microchip_icicle_kit_machine_init(MachineState *machine) | |
84 | @@ -XXX,XX +XXX,XX @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp) | 84 | /* Compute the fdt load address in dram */ |
85 | /* CLINT */ | 85 | fdt_load_addr = riscv_compute_fdt_addr(memmap[MICROCHIP_PFSOC_DRAM_LO].base, |
86 | sifive_clint_create(memmap[MICROCHIP_PFSOC_CLINT].base, | 86 | memmap[MICROCHIP_PFSOC_DRAM_LO].size, |
87 | memmap[MICROCHIP_PFSOC_CLINT].size, 0, ms->smp.cpus, | 87 | - machine); |
88 | - SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, false); | 88 | + machine, &s->soc.u_cpus); |
89 | + SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, | 89 | riscv_load_fdt(fdt_load_addr, machine->fdt); |
90 | + CLINT_TIMEBASE_FREQ, false); | 90 | |
91 | 91 | /* Load the reset vector */ | |
92 | /* L2 cache controller */ | ||
93 | create_unimplemented_device("microchip.pfsoc.l2cc", | ||
94 | diff --git a/hw/riscv/sifive_clint.c b/hw/riscv/sifive_clint.c | ||
95 | index XXXXXXX..XXXXXXX 100644 | ||
96 | --- a/hw/riscv/sifive_clint.c | ||
97 | +++ b/hw/riscv/sifive_clint.c | ||
98 | @@ -XXX,XX +XXX,XX @@ | ||
99 | #include "hw/riscv/sifive_clint.h" | ||
100 | #include "qemu/timer.h" | ||
101 | |||
102 | -static uint64_t cpu_riscv_read_rtc(void) | ||
103 | +static uint64_t cpu_riscv_read_rtc(uint32_t timebase_freq) | ||
104 | { | ||
105 | return muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), | ||
106 | - SIFIVE_CLINT_TIMEBASE_FREQ, NANOSECONDS_PER_SECOND); | ||
107 | + timebase_freq, NANOSECONDS_PER_SECOND); | ||
108 | } | ||
109 | |||
110 | /* | ||
111 | * Called when timecmp is written to update the QEMU timer or immediately | ||
112 | * trigger timer interrupt if mtimecmp <= current timer value. | ||
113 | */ | ||
114 | -static void sifive_clint_write_timecmp(RISCVCPU *cpu, uint64_t value) | ||
115 | +static void sifive_clint_write_timecmp(RISCVCPU *cpu, uint64_t value, | ||
116 | + uint32_t timebase_freq) | ||
117 | { | ||
118 | uint64_t next; | ||
119 | uint64_t diff; | ||
120 | |||
121 | - uint64_t rtc_r = cpu_riscv_read_rtc(); | ||
122 | + uint64_t rtc_r = cpu_riscv_read_rtc(timebase_freq); | ||
123 | |||
124 | cpu->env.timecmp = value; | ||
125 | if (cpu->env.timecmp <= rtc_r) { | ||
126 | @@ -XXX,XX +XXX,XX @@ static void sifive_clint_write_timecmp(RISCVCPU *cpu, uint64_t value) | ||
127 | diff = cpu->env.timecmp - rtc_r; | ||
128 | /* back to ns (note args switched in muldiv64) */ | ||
129 | next = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + | ||
130 | - muldiv64(diff, NANOSECONDS_PER_SECOND, SIFIVE_CLINT_TIMEBASE_FREQ); | ||
131 | + muldiv64(diff, NANOSECONDS_PER_SECOND, timebase_freq); | ||
132 | timer_mod(cpu->env.timer, next); | ||
133 | } | ||
134 | |||
135 | @@ -XXX,XX +XXX,XX @@ static uint64_t sifive_clint_read(void *opaque, hwaddr addr, unsigned size) | ||
136 | } | ||
137 | } else if (addr == clint->time_base) { | ||
138 | /* time_lo */ | ||
139 | - return cpu_riscv_read_rtc() & 0xFFFFFFFF; | ||
140 | + return cpu_riscv_read_rtc(clint->timebase_freq) & 0xFFFFFFFF; | ||
141 | } else if (addr == clint->time_base + 4) { | ||
142 | /* time_hi */ | ||
143 | - return (cpu_riscv_read_rtc() >> 32) & 0xFFFFFFFF; | ||
144 | + return (cpu_riscv_read_rtc(clint->timebase_freq) >> 32) & 0xFFFFFFFF; | ||
145 | } | ||
146 | |||
147 | error_report("clint: invalid read: %08x", (uint32_t)addr); | ||
148 | @@ -XXX,XX +XXX,XX @@ static void sifive_clint_write(void *opaque, hwaddr addr, uint64_t value, | ||
149 | /* timecmp_lo */ | ||
150 | uint64_t timecmp_hi = env->timecmp >> 32; | ||
151 | sifive_clint_write_timecmp(RISCV_CPU(cpu), | ||
152 | - timecmp_hi << 32 | (value & 0xFFFFFFFF)); | ||
153 | + timecmp_hi << 32 | (value & 0xFFFFFFFF), clint->timebase_freq); | ||
154 | return; | ||
155 | } else if ((addr & 0x7) == 4) { | ||
156 | /* timecmp_hi */ | ||
157 | uint64_t timecmp_lo = env->timecmp; | ||
158 | sifive_clint_write_timecmp(RISCV_CPU(cpu), | ||
159 | - value << 32 | (timecmp_lo & 0xFFFFFFFF)); | ||
160 | + value << 32 | (timecmp_lo & 0xFFFFFFFF), clint->timebase_freq); | ||
161 | } else { | ||
162 | error_report("clint: invalid timecmp write: %08x", (uint32_t)addr); | ||
163 | } | ||
164 | @@ -XXX,XX +XXX,XX @@ static Property sifive_clint_properties[] = { | ||
165 | DEFINE_PROP_UINT32("timecmp-base", SiFiveCLINTState, timecmp_base, 0), | ||
166 | DEFINE_PROP_UINT32("time-base", SiFiveCLINTState, time_base, 0), | ||
167 | DEFINE_PROP_UINT32("aperture-size", SiFiveCLINTState, aperture_size, 0), | ||
168 | + DEFINE_PROP_UINT32("timebase-freq", SiFiveCLINTState, timebase_freq, 0), | ||
169 | DEFINE_PROP_END_OF_LIST(), | ||
170 | }; | ||
171 | |||
172 | @@ -XXX,XX +XXX,XX @@ type_init(sifive_clint_register_types) | ||
173 | */ | ||
174 | DeviceState *sifive_clint_create(hwaddr addr, hwaddr size, | ||
175 | uint32_t hartid_base, uint32_t num_harts, uint32_t sip_base, | ||
176 | - uint32_t timecmp_base, uint32_t time_base, bool provide_rdtime) | ||
177 | + uint32_t timecmp_base, uint32_t time_base, uint32_t timebase_freq, | ||
178 | + bool provide_rdtime) | ||
179 | { | ||
180 | int i; | ||
181 | for (i = 0; i < num_harts; i++) { | ||
182 | @@ -XXX,XX +XXX,XX @@ DeviceState *sifive_clint_create(hwaddr addr, hwaddr size, | ||
183 | continue; | ||
184 | } | ||
185 | if (provide_rdtime) { | ||
186 | - riscv_cpu_set_rdtime_fn(env, cpu_riscv_read_rtc); | ||
187 | + riscv_cpu_set_rdtime_fn(env, cpu_riscv_read_rtc, timebase_freq); | ||
188 | } | ||
189 | env->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, | ||
190 | &sifive_clint_timer_cb, cpu); | ||
191 | @@ -XXX,XX +XXX,XX @@ DeviceState *sifive_clint_create(hwaddr addr, hwaddr size, | ||
192 | qdev_prop_set_uint32(dev, "timecmp-base", timecmp_base); | ||
193 | qdev_prop_set_uint32(dev, "time-base", time_base); | ||
194 | qdev_prop_set_uint32(dev, "aperture-size", size); | ||
195 | + qdev_prop_set_uint32(dev, "timebase-freq", timebase_freq); | ||
196 | sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); | ||
197 | sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); | ||
198 | return dev; | ||
199 | diff --git a/hw/riscv/sifive_e.c b/hw/riscv/sifive_e.c | ||
200 | index XXXXXXX..XXXXXXX 100644 | ||
201 | --- a/hw/riscv/sifive_e.c | ||
202 | +++ b/hw/riscv/sifive_e.c | ||
203 | @@ -XXX,XX +XXX,XX @@ static void sifive_e_soc_realize(DeviceState *dev, Error **errp) | ||
204 | memmap[SIFIVE_E_PLIC].size); | ||
205 | sifive_clint_create(memmap[SIFIVE_E_CLINT].base, | ||
206 | memmap[SIFIVE_E_CLINT].size, 0, ms->smp.cpus, | ||
207 | - SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, false); | ||
208 | + SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, | ||
209 | + SIFIVE_CLINT_TIMEBASE_FREQ, false); | ||
210 | create_unimplemented_device("riscv.sifive.e.aon", | ||
211 | memmap[SIFIVE_E_AON].base, memmap[SIFIVE_E_AON].size); | ||
212 | sifive_e_prci_create(memmap[SIFIVE_E_PRCI].base); | ||
213 | diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c | 92 | diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c |
214 | index XXXXXXX..XXXXXXX 100644 | 93 | index XXXXXXX..XXXXXXX 100644 |
215 | --- a/hw/riscv/sifive_u.c | 94 | --- a/hw/riscv/sifive_u.c |
216 | +++ b/hw/riscv/sifive_u.c | 95 | +++ b/hw/riscv/sifive_u.c |
217 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_soc_realize(DeviceState *dev, Error **errp) | 96 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_machine_init(MachineState *machine) |
218 | serial_hd(1), qdev_get_gpio_in(DEVICE(s->plic), SIFIVE_U_UART1_IRQ)); | 97 | target_ulong firmware_end_addr, kernel_start_addr; |
219 | sifive_clint_create(memmap[SIFIVE_U_CLINT].base, | 98 | const char *firmware_name; |
220 | memmap[SIFIVE_U_CLINT].size, 0, ms->smp.cpus, | 99 | uint32_t start_addr_hi32 = 0x00000000; |
221 | - SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, false); | 100 | + uint32_t fdt_load_addr_hi32 = 0x00000000; |
222 | + SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, | 101 | int i; |
223 | + SIFIVE_CLINT_TIMEBASE_FREQ, false); | 102 | - uint32_t fdt_load_addr; |
224 | 103 | + uint64_t fdt_load_addr; | |
225 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->prci), errp)) { | 104 | uint64_t kernel_entry; |
226 | return; | 105 | DriveInfo *dinfo; |
106 | BlockBackend *blk; | ||
107 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_machine_init(MachineState *machine) | ||
108 | |||
109 | fdt_load_addr = riscv_compute_fdt_addr(memmap[SIFIVE_U_DEV_DRAM].base, | ||
110 | memmap[SIFIVE_U_DEV_DRAM].size, | ||
111 | - machine); | ||
112 | + machine, &s->soc.u_cpus); | ||
113 | riscv_load_fdt(fdt_load_addr, machine->fdt); | ||
114 | |||
115 | if (!riscv_is_32bit(&s->soc.u_cpus)) { | ||
116 | start_addr_hi32 = (uint64_t)start_addr >> 32; | ||
117 | + fdt_load_addr_hi32 = fdt_load_addr >> 32; | ||
118 | } | ||
119 | |||
120 | /* reset vector */ | ||
121 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_machine_init(MachineState *machine) | ||
122 | start_addr, /* start: .dword */ | ||
123 | start_addr_hi32, | ||
124 | fdt_load_addr, /* fdt_laddr: .dword */ | ||
125 | - 0x00000000, | ||
126 | + fdt_load_addr_hi32, | ||
127 | 0x00000000, | ||
128 | /* fw_dyn: */ | ||
129 | }; | ||
227 | diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c | 130 | diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c |
228 | index XXXXXXX..XXXXXXX 100644 | 131 | index XXXXXXX..XXXXXXX 100644 |
229 | --- a/hw/riscv/spike.c | 132 | --- a/hw/riscv/spike.c |
230 | +++ b/hw/riscv/spike.c | 133 | +++ b/hw/riscv/spike.c |
231 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) | 134 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) |
232 | sifive_clint_create( | 135 | hwaddr firmware_load_addr = memmap[SPIKE_DRAM].base; |
233 | memmap[SPIKE_CLINT].base + i * memmap[SPIKE_CLINT].size, | 136 | target_ulong kernel_start_addr; |
234 | memmap[SPIKE_CLINT].size, base_hartid, hart_count, | 137 | char *firmware_name; |
235 | - SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, false); | 138 | - uint32_t fdt_load_addr; |
236 | + SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, | 139 | + uint64_t fdt_load_addr; |
237 | + SIFIVE_CLINT_TIMEBASE_FREQ, false); | 140 | uint64_t kernel_entry; |
238 | } | 141 | char *soc_name; |
239 | 142 | int i, base_hartid, hart_count; | |
240 | /* register system main memory (actual RAM) */ | 143 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) |
144 | |||
145 | fdt_load_addr = riscv_compute_fdt_addr(memmap[SPIKE_DRAM].base, | ||
146 | memmap[SPIKE_DRAM].size, | ||
147 | - machine); | ||
148 | + machine, &s->soc[0]); | ||
149 | riscv_load_fdt(fdt_load_addr, machine->fdt); | ||
150 | |||
151 | /* load the reset vector */ | ||
241 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | 152 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c |
242 | index XXXXXXX..XXXXXXX 100644 | 153 | index XXXXXXX..XXXXXXX 100644 |
243 | --- a/hw/riscv/virt.c | 154 | --- a/hw/riscv/virt.c |
244 | +++ b/hw/riscv/virt.c | 155 | +++ b/hw/riscv/virt.c |
245 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine) | 156 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_done(Notifier *notifier, void *data) |
246 | sifive_clint_create( | 157 | |
247 | memmap[VIRT_CLINT].base + i * memmap[VIRT_CLINT].size, | 158 | fdt_load_addr = riscv_compute_fdt_addr(memmap[VIRT_DRAM].base, |
248 | memmap[VIRT_CLINT].size, base_hartid, hart_count, | 159 | memmap[VIRT_DRAM].size, |
249 | - SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, true); | 160 | - machine); |
250 | + SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE, | 161 | + machine, &s->soc[0]); |
251 | + SIFIVE_CLINT_TIMEBASE_FREQ, true); | 162 | riscv_load_fdt(fdt_load_addr, machine->fdt); |
252 | 163 | ||
253 | /* Per-socket PLIC hart topology configuration string */ | 164 | /* load the reset vector */ |
254 | plic_hart_config_len = | ||
255 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | ||
256 | index XXXXXXX..XXXXXXX 100644 | ||
257 | --- a/target/riscv/cpu_helper.c | ||
258 | +++ b/target/riscv/cpu_helper.c | ||
259 | @@ -XXX,XX +XXX,XX @@ uint32_t riscv_cpu_update_mip(RISCVCPU *cpu, uint32_t mask, uint32_t value) | ||
260 | return old; | ||
261 | } | ||
262 | |||
263 | -void riscv_cpu_set_rdtime_fn(CPURISCVState *env, uint64_t (*fn)(void)) | ||
264 | +void riscv_cpu_set_rdtime_fn(CPURISCVState *env, uint64_t (*fn)(uint32_t), | ||
265 | + uint32_t arg) | ||
266 | { | ||
267 | env->rdtime_fn = fn; | ||
268 | + env->rdtime_fn_arg = arg; | ||
269 | } | ||
270 | |||
271 | void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv) | ||
272 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | ||
273 | index XXXXXXX..XXXXXXX 100644 | ||
274 | --- a/target/riscv/csr.c | ||
275 | +++ b/target/riscv/csr.c | ||
276 | @@ -XXX,XX +XXX,XX @@ static int read_time(CPURISCVState *env, int csrno, target_ulong *val) | ||
277 | return -RISCV_EXCP_ILLEGAL_INST; | ||
278 | } | ||
279 | |||
280 | - *val = env->rdtime_fn() + delta; | ||
281 | + *val = env->rdtime_fn(env->rdtime_fn_arg) + delta; | ||
282 | return 0; | ||
283 | } | ||
284 | |||
285 | @@ -XXX,XX +XXX,XX @@ static int read_timeh(CPURISCVState *env, int csrno, target_ulong *val) | ||
286 | return -RISCV_EXCP_ILLEGAL_INST; | ||
287 | } | ||
288 | |||
289 | - *val = (env->rdtime_fn() + delta) >> 32; | ||
290 | + *val = (env->rdtime_fn(env->rdtime_fn_arg) + delta) >> 32; | ||
291 | return 0; | ||
292 | } | ||
293 | #endif | ||
294 | -- | 165 | -- |
295 | 2.28.0 | 166 | 2.47.1 |
296 | |||
297 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Jim Shu <jim.shu@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | This is an effort to clean up the hw/riscv directory. Ideally it | 3 | Add a new struct RISCVBootInfo to sync boot information between multiple |
4 | should only contain the RISC-V SoC / machine codes plus generic | 4 | boot functions. |
5 | codes. Let's move sifive_clint model to hw/intc directory. | ||
6 | 5 | ||
7 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 6 | Signed-off-by: Jim Shu <jim.shu@sifive.com> |
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Message-Id: <1599129623-68957-6-git-send-email-bmeng.cn@gmail.com> | 8 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
9 | Message-ID: <20241120153935.24706-3-jim.shu@sifive.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 11 | --- |
12 | include/hw/{riscv => intc}/sifive_clint.h | 0 | 12 | include/hw/riscv/boot.h | 25 ++++++++++----- |
13 | hw/{riscv => intc}/sifive_clint.c | 2 +- | 13 | hw/riscv/boot.c | 65 ++++++++++++++++++++++---------------- |
14 | hw/riscv/microchip_pfsoc.c | 2 +- | 14 | hw/riscv/microchip_pfsoc.c | 11 ++++--- |
15 | hw/riscv/sifive_e.c | 2 +- | 15 | hw/riscv/opentitan.c | 4 ++- |
16 | hw/riscv/sifive_u.c | 2 +- | 16 | hw/riscv/sifive_e.c | 4 ++- |
17 | hw/riscv/spike.c | 2 +- | 17 | hw/riscv/sifive_u.c | 12 ++++--- |
18 | hw/riscv/virt.c | 2 +- | 18 | hw/riscv/spike.c | 12 ++++--- |
19 | hw/intc/Kconfig | 3 +++ | 19 | hw/riscv/virt.c | 13 +++++--- |
20 | hw/intc/meson.build | 1 + | 20 | 8 files changed, 90 insertions(+), 56 deletions(-) |
21 | hw/riscv/Kconfig | 5 +++++ | ||
22 | hw/riscv/meson.build | 1 - | ||
23 | 11 files changed, 15 insertions(+), 7 deletions(-) | ||
24 | rename include/hw/{riscv => intc}/sifive_clint.h (100%) | ||
25 | rename hw/{riscv => intc}/sifive_clint.c (99%) | ||
26 | 21 | ||
27 | diff --git a/include/hw/riscv/sifive_clint.h b/include/hw/intc/sifive_clint.h | 22 | diff --git a/include/hw/riscv/boot.h b/include/hw/riscv/boot.h |
28 | similarity index 100% | 23 | index XXXXXXX..XXXXXXX 100644 |
29 | rename from include/hw/riscv/sifive_clint.h | 24 | --- a/include/hw/riscv/boot.h |
30 | rename to include/hw/intc/sifive_clint.h | 25 | +++ b/include/hw/riscv/boot.h |
31 | diff --git a/hw/riscv/sifive_clint.c b/hw/intc/sifive_clint.c | ||
32 | similarity index 99% | ||
33 | rename from hw/riscv/sifive_clint.c | ||
34 | rename to hw/intc/sifive_clint.c | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/hw/riscv/sifive_clint.c | ||
37 | +++ b/hw/intc/sifive_clint.c | ||
38 | @@ -XXX,XX +XXX,XX @@ | 26 | @@ -XXX,XX +XXX,XX @@ |
39 | #include "hw/sysbus.h" | 27 | #define RISCV32_BIOS_BIN "opensbi-riscv32-generic-fw_dynamic.bin" |
40 | #include "target/riscv/cpu.h" | 28 | #define RISCV64_BIOS_BIN "opensbi-riscv64-generic-fw_dynamic.bin" |
41 | #include "hw/qdev-properties.h" | 29 | |
42 | -#include "hw/riscv/sifive_clint.h" | 30 | +typedef struct RISCVBootInfo { |
43 | +#include "hw/intc/sifive_clint.h" | 31 | + ssize_t kernel_size; |
44 | #include "qemu/timer.h" | 32 | + hwaddr image_low_addr; |
45 | 33 | + hwaddr image_high_addr; | |
46 | static uint64_t cpu_riscv_read_rtc(uint32_t timebase_freq) | 34 | + |
35 | + bool is_32bit; | ||
36 | +} RISCVBootInfo; | ||
37 | + | ||
38 | bool riscv_is_32bit(RISCVHartArrayState *harts); | ||
39 | |||
40 | char *riscv_plic_hart_config_string(int hart_count); | ||
41 | |||
42 | -target_ulong riscv_calc_kernel_start_addr(RISCVHartArrayState *harts, | ||
43 | +void riscv_boot_info_init(RISCVBootInfo *info, RISCVHartArrayState *harts); | ||
44 | +target_ulong riscv_calc_kernel_start_addr(RISCVBootInfo *info, | ||
45 | target_ulong firmware_end_addr); | ||
46 | target_ulong riscv_find_and_load_firmware(MachineState *machine, | ||
47 | const char *default_machine_firmware, | ||
48 | @@ -XXX,XX +XXX,XX @@ char *riscv_find_firmware(const char *firmware_filename, | ||
49 | target_ulong riscv_load_firmware(const char *firmware_filename, | ||
50 | hwaddr *firmware_load_addr, | ||
51 | symbol_fn_t sym_cb); | ||
52 | -target_ulong riscv_load_kernel(MachineState *machine, | ||
53 | - RISCVHartArrayState *harts, | ||
54 | - target_ulong firmware_end_addr, | ||
55 | - bool load_initrd, | ||
56 | - symbol_fn_t sym_cb); | ||
57 | -uint64_t riscv_compute_fdt_addr(hwaddr dram_start, uint64_t dram_size, | ||
58 | - MachineState *ms, RISCVHartArrayState *harts); | ||
59 | +void riscv_load_kernel(MachineState *machine, | ||
60 | + RISCVBootInfo *info, | ||
61 | + target_ulong kernel_start_addr, | ||
62 | + bool load_initrd, | ||
63 | + symbol_fn_t sym_cb); | ||
64 | +uint64_t riscv_compute_fdt_addr(hwaddr dram_base, hwaddr dram_size, | ||
65 | + MachineState *ms, RISCVBootInfo *info); | ||
66 | void riscv_load_fdt(hwaddr fdt_addr, void *fdt); | ||
67 | void riscv_setup_rom_reset_vec(MachineState *machine, RISCVHartArrayState *harts, | ||
68 | hwaddr saddr, | ||
69 | diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c | ||
70 | index XXXXXXX..XXXXXXX 100644 | ||
71 | --- a/hw/riscv/boot.c | ||
72 | +++ b/hw/riscv/boot.c | ||
73 | @@ -XXX,XX +XXX,XX @@ char *riscv_plic_hart_config_string(int hart_count) | ||
74 | return g_strjoinv(",", (char **)vals); | ||
75 | } | ||
76 | |||
77 | -target_ulong riscv_calc_kernel_start_addr(RISCVHartArrayState *harts, | ||
78 | +void riscv_boot_info_init(RISCVBootInfo *info, RISCVHartArrayState *harts) | ||
79 | +{ | ||
80 | + info->kernel_size = 0; | ||
81 | + info->is_32bit = riscv_is_32bit(harts); | ||
82 | +} | ||
83 | + | ||
84 | +target_ulong riscv_calc_kernel_start_addr(RISCVBootInfo *info, | ||
85 | target_ulong firmware_end_addr) { | ||
86 | - if (riscv_is_32bit(harts)) { | ||
87 | + if (info->is_32bit) { | ||
88 | return QEMU_ALIGN_UP(firmware_end_addr, 4 * MiB); | ||
89 | } else { | ||
90 | return QEMU_ALIGN_UP(firmware_end_addr, 2 * MiB); | ||
91 | @@ -XXX,XX +XXX,XX @@ target_ulong riscv_load_firmware(const char *firmware_filename, | ||
92 | exit(1); | ||
93 | } | ||
94 | |||
95 | -static void riscv_load_initrd(MachineState *machine, uint64_t kernel_entry) | ||
96 | +static void riscv_load_initrd(MachineState *machine, RISCVBootInfo *info) | ||
97 | { | ||
98 | const char *filename = machine->initrd_filename; | ||
99 | uint64_t mem_size = machine->ram_size; | ||
100 | @@ -XXX,XX +XXX,XX @@ static void riscv_load_initrd(MachineState *machine, uint64_t kernel_entry) | ||
101 | * halfway into RAM, and for boards with 1GB of RAM or more we put | ||
102 | * the initrd at 512MB. | ||
103 | */ | ||
104 | - start = kernel_entry + MIN(mem_size / 2, 512 * MiB); | ||
105 | + start = info->image_low_addr + MIN(mem_size / 2, 512 * MiB); | ||
106 | |||
107 | size = load_ramdisk(filename, start, mem_size - start); | ||
108 | if (size == -1) { | ||
109 | @@ -XXX,XX +XXX,XX @@ static void riscv_load_initrd(MachineState *machine, uint64_t kernel_entry) | ||
110 | } | ||
111 | } | ||
112 | |||
113 | -target_ulong riscv_load_kernel(MachineState *machine, | ||
114 | - RISCVHartArrayState *harts, | ||
115 | - target_ulong kernel_start_addr, | ||
116 | - bool load_initrd, | ||
117 | - symbol_fn_t sym_cb) | ||
118 | +void riscv_load_kernel(MachineState *machine, | ||
119 | + RISCVBootInfo *info, | ||
120 | + target_ulong kernel_start_addr, | ||
121 | + bool load_initrd, | ||
122 | + symbol_fn_t sym_cb) | ||
123 | { | ||
124 | const char *kernel_filename = machine->kernel_filename; | ||
125 | - uint64_t kernel_load_base, kernel_entry; | ||
126 | + ssize_t kernel_size; | ||
127 | void *fdt = machine->fdt; | ||
128 | |||
129 | g_assert(kernel_filename != NULL); | ||
130 | @@ -XXX,XX +XXX,XX @@ target_ulong riscv_load_kernel(MachineState *machine, | ||
131 | * the (expected) load address load address. This allows kernels to have | ||
132 | * separate SBI and ELF entry points (used by FreeBSD, for example). | ||
133 | */ | ||
134 | - if (load_elf_ram_sym(kernel_filename, NULL, NULL, NULL, | ||
135 | - NULL, &kernel_load_base, NULL, NULL, 0, | ||
136 | - EM_RISCV, 1, 0, NULL, true, sym_cb) > 0) { | ||
137 | - kernel_entry = kernel_load_base; | ||
138 | + kernel_size = load_elf_ram_sym(kernel_filename, NULL, NULL, NULL, NULL, | ||
139 | + &info->image_low_addr, &info->image_high_addr, | ||
140 | + NULL, 0, EM_RISCV, 1, 0, NULL, true, sym_cb); | ||
141 | + if (kernel_size > 0) { | ||
142 | + info->kernel_size = kernel_size; | ||
143 | goto out; | ||
144 | } | ||
145 | |||
146 | - if (load_uimage_as(kernel_filename, &kernel_entry, NULL, NULL, | ||
147 | - NULL, NULL, NULL) > 0) { | ||
148 | + kernel_size = load_uimage_as(kernel_filename, &info->image_low_addr, | ||
149 | + NULL, NULL, NULL, NULL, NULL); | ||
150 | + if (kernel_size > 0) { | ||
151 | + info->kernel_size = kernel_size; | ||
152 | + info->image_high_addr = info->image_low_addr + kernel_size; | ||
153 | goto out; | ||
154 | } | ||
155 | |||
156 | - if (load_image_targphys_as(kernel_filename, kernel_start_addr, | ||
157 | - current_machine->ram_size, NULL) > 0) { | ||
158 | - kernel_entry = kernel_start_addr; | ||
159 | + kernel_size = load_image_targphys_as(kernel_filename, kernel_start_addr, | ||
160 | + current_machine->ram_size, NULL); | ||
161 | + if (kernel_size > 0) { | ||
162 | + info->kernel_size = kernel_size; | ||
163 | + info->image_low_addr = kernel_start_addr; | ||
164 | + info->image_high_addr = info->image_low_addr + kernel_size; | ||
165 | goto out; | ||
166 | } | ||
167 | |||
168 | @@ -XXX,XX +XXX,XX @@ target_ulong riscv_load_kernel(MachineState *machine, | ||
169 | |||
170 | out: | ||
171 | /* | ||
172 | - * For 32 bit CPUs 'kernel_entry' can be sign-extended by | ||
173 | + * For 32 bit CPUs 'image_low_addr' can be sign-extended by | ||
174 | * load_elf_ram_sym(). | ||
175 | */ | ||
176 | - if (riscv_is_32bit(harts)) { | ||
177 | - kernel_entry = extract64(kernel_entry, 0, 32); | ||
178 | + if (info->is_32bit) { | ||
179 | + info->image_low_addr = extract64(info->image_low_addr, 0, 32); | ||
180 | } | ||
181 | |||
182 | if (load_initrd && machine->initrd_filename) { | ||
183 | - riscv_load_initrd(machine, kernel_entry); | ||
184 | + riscv_load_initrd(machine, info); | ||
185 | } | ||
186 | |||
187 | if (fdt && machine->kernel_cmdline && *machine->kernel_cmdline) { | ||
188 | qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", | ||
189 | machine->kernel_cmdline); | ||
190 | } | ||
191 | - | ||
192 | - return kernel_entry; | ||
193 | } | ||
194 | |||
195 | /* | ||
196 | @@ -XXX,XX +XXX,XX @@ out: | ||
197 | * The FDT is fdt_packed() during the calculation. | ||
198 | */ | ||
199 | uint64_t riscv_compute_fdt_addr(hwaddr dram_base, hwaddr dram_size, | ||
200 | - MachineState *ms, RISCVHartArrayState *harts) | ||
201 | + MachineState *ms, RISCVBootInfo *info) | ||
202 | { | ||
203 | int ret = fdt_pack(ms->fdt); | ||
204 | hwaddr dram_end, temp; | ||
205 | @@ -XXX,XX +XXX,XX @@ uint64_t riscv_compute_fdt_addr(hwaddr dram_base, hwaddr dram_size, | ||
206 | * Thus, put it near to the end of dram in RV64, and put it near to the end | ||
207 | * of dram or 3GB whichever is lesser in RV32. | ||
208 | */ | ||
209 | - if (!riscv_is_32bit(harts)) { | ||
210 | + if (!info->is_32bit) { | ||
211 | temp = dram_end; | ||
212 | } else { | ||
213 | temp = (dram_base < 3072 * MiB) ? MIN(dram_end, 3072 * MiB) : dram_end; | ||
47 | diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c | 214 | diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c |
48 | index XXXXXXX..XXXXXXX 100644 | 215 | index XXXXXXX..XXXXXXX 100644 |
49 | --- a/hw/riscv/microchip_pfsoc.c | 216 | --- a/hw/riscv/microchip_pfsoc.c |
50 | +++ b/hw/riscv/microchip_pfsoc.c | 217 | +++ b/hw/riscv/microchip_pfsoc.c |
51 | @@ -XXX,XX +XXX,XX @@ | 218 | @@ -XXX,XX +XXX,XX @@ static void microchip_icicle_kit_machine_init(MachineState *machine) |
52 | #include "hw/misc/unimp.h" | 219 | uint64_t kernel_entry; |
53 | #include "hw/riscv/boot.h" | 220 | uint64_t fdt_load_addr; |
54 | #include "hw/riscv/riscv_hart.h" | 221 | DriveInfo *dinfo = drive_get(IF_SD, 0, 0); |
55 | -#include "hw/riscv/sifive_clint.h" | 222 | + RISCVBootInfo boot_info; |
56 | #include "hw/riscv/sifive_plic.h" | 223 | |
57 | #include "hw/riscv/microchip_pfsoc.h" | 224 | /* Sanity check on RAM size */ |
58 | +#include "hw/intc/sifive_clint.h" | 225 | if (machine->ram_size < mc->default_ram_size) { |
59 | #include "sysemu/sysemu.h" | 226 | @@ -XXX,XX +XXX,XX @@ static void microchip_icicle_kit_machine_init(MachineState *machine) |
60 | 227 | firmware_end_addr = riscv_find_and_load_firmware(machine, firmware_name, | |
61 | /* | 228 | &firmware_load_addr, NULL); |
229 | |||
230 | + riscv_boot_info_init(&boot_info, &s->soc.u_cpus); | ||
231 | if (kernel_as_payload) { | ||
232 | - kernel_start_addr = riscv_calc_kernel_start_addr(&s->soc.u_cpus, | ||
233 | + kernel_start_addr = riscv_calc_kernel_start_addr(&boot_info, | ||
234 | firmware_end_addr); | ||
235 | |||
236 | - kernel_entry = riscv_load_kernel(machine, &s->soc.u_cpus, | ||
237 | - kernel_start_addr, true, NULL); | ||
238 | + riscv_load_kernel(machine, &boot_info, kernel_start_addr, | ||
239 | + true, NULL); | ||
240 | + kernel_entry = boot_info.image_low_addr; | ||
241 | |||
242 | /* Compute the fdt load address in dram */ | ||
243 | fdt_load_addr = riscv_compute_fdt_addr(memmap[MICROCHIP_PFSOC_DRAM_LO].base, | ||
244 | memmap[MICROCHIP_PFSOC_DRAM_LO].size, | ||
245 | - machine, &s->soc.u_cpus); | ||
246 | + machine, &boot_info); | ||
247 | riscv_load_fdt(fdt_load_addr, machine->fdt); | ||
248 | |||
249 | /* Load the reset vector */ | ||
250 | diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c | ||
251 | index XXXXXXX..XXXXXXX 100644 | ||
252 | --- a/hw/riscv/opentitan.c | ||
253 | +++ b/hw/riscv/opentitan.c | ||
254 | @@ -XXX,XX +XXX,XX @@ static void opentitan_machine_init(MachineState *machine) | ||
255 | OpenTitanState *s = OPENTITAN_MACHINE(machine); | ||
256 | const MemMapEntry *memmap = ibex_memmap; | ||
257 | MemoryRegion *sys_mem = get_system_memory(); | ||
258 | + RISCVBootInfo boot_info; | ||
259 | |||
260 | if (machine->ram_size != mc->default_ram_size) { | ||
261 | char *sz = size_to_str(mc->default_ram_size); | ||
262 | @@ -XXX,XX +XXX,XX @@ static void opentitan_machine_init(MachineState *machine) | ||
263 | riscv_load_firmware(machine->firmware, &firmware_load_addr, NULL); | ||
264 | } | ||
265 | |||
266 | + riscv_boot_info_init(&boot_info, &s->soc.cpus); | ||
267 | if (machine->kernel_filename) { | ||
268 | - riscv_load_kernel(machine, &s->soc.cpus, | ||
269 | + riscv_load_kernel(machine, &boot_info, | ||
270 | memmap[IBEX_DEV_RAM].base, | ||
271 | false, NULL); | ||
272 | } | ||
62 | diff --git a/hw/riscv/sifive_e.c b/hw/riscv/sifive_e.c | 273 | diff --git a/hw/riscv/sifive_e.c b/hw/riscv/sifive_e.c |
63 | index XXXXXXX..XXXXXXX 100644 | 274 | index XXXXXXX..XXXXXXX 100644 |
64 | --- a/hw/riscv/sifive_e.c | 275 | --- a/hw/riscv/sifive_e.c |
65 | +++ b/hw/riscv/sifive_e.c | 276 | +++ b/hw/riscv/sifive_e.c |
66 | @@ -XXX,XX +XXX,XX @@ | 277 | @@ -XXX,XX +XXX,XX @@ static void sifive_e_machine_init(MachineState *machine) |
67 | #include "target/riscv/cpu.h" | 278 | SiFiveEState *s = RISCV_E_MACHINE(machine); |
68 | #include "hw/riscv/riscv_hart.h" | 279 | MemoryRegion *sys_mem = get_system_memory(); |
69 | #include "hw/riscv/sifive_plic.h" | 280 | int i; |
70 | -#include "hw/riscv/sifive_clint.h" | 281 | + RISCVBootInfo boot_info; |
71 | #include "hw/riscv/sifive_uart.h" | 282 | |
72 | #include "hw/riscv/sifive_e.h" | 283 | if (machine->ram_size != mc->default_ram_size) { |
73 | #include "hw/riscv/boot.h" | 284 | char *sz = size_to_str(mc->default_ram_size); |
74 | +#include "hw/intc/sifive_clint.h" | 285 | @@ -XXX,XX +XXX,XX @@ static void sifive_e_machine_init(MachineState *machine) |
75 | #include "hw/misc/sifive_e_prci.h" | 286 | rom_add_blob_fixed_as("mrom.reset", reset_vec, sizeof(reset_vec), |
76 | #include "chardev/char.h" | 287 | memmap[SIFIVE_E_DEV_MROM].base, &address_space_memory); |
77 | #include "sysemu/arch_init.h" | 288 | |
289 | + riscv_boot_info_init(&boot_info, &s->soc.cpus); | ||
290 | if (machine->kernel_filename) { | ||
291 | - riscv_load_kernel(machine, &s->soc.cpus, | ||
292 | + riscv_load_kernel(machine, &boot_info, | ||
293 | memmap[SIFIVE_E_DEV_DTIM].base, | ||
294 | false, NULL); | ||
295 | } | ||
78 | diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c | 296 | diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c |
79 | index XXXXXXX..XXXXXXX 100644 | 297 | index XXXXXXX..XXXXXXX 100644 |
80 | --- a/hw/riscv/sifive_u.c | 298 | --- a/hw/riscv/sifive_u.c |
81 | +++ b/hw/riscv/sifive_u.c | 299 | +++ b/hw/riscv/sifive_u.c |
82 | @@ -XXX,XX +XXX,XX @@ | 300 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_machine_init(MachineState *machine) |
83 | #include "target/riscv/cpu.h" | 301 | BlockBackend *blk; |
84 | #include "hw/riscv/riscv_hart.h" | 302 | DeviceState *flash_dev, *sd_dev, *card_dev; |
85 | #include "hw/riscv/sifive_plic.h" | 303 | qemu_irq flash_cs, sd_cs; |
86 | -#include "hw/riscv/sifive_clint.h" | 304 | + RISCVBootInfo boot_info; |
87 | #include "hw/riscv/sifive_uart.h" | 305 | |
88 | #include "hw/riscv/sifive_u.h" | 306 | /* Initialize SoC */ |
89 | #include "hw/riscv/boot.h" | 307 | object_initialize_child(OBJECT(machine), "soc", &s->soc, TYPE_RISCV_U_SOC); |
90 | +#include "hw/intc/sifive_clint.h" | 308 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_machine_init(MachineState *machine) |
91 | #include "chardev/char.h" | 309 | firmware_end_addr = riscv_find_and_load_firmware(machine, firmware_name, |
92 | #include "net/eth.h" | 310 | &start_addr, NULL); |
93 | #include "sysemu/arch_init.h" | 311 | |
312 | + riscv_boot_info_init(&boot_info, &s->soc.u_cpus); | ||
313 | if (machine->kernel_filename) { | ||
314 | - kernel_start_addr = riscv_calc_kernel_start_addr(&s->soc.u_cpus, | ||
315 | + kernel_start_addr = riscv_calc_kernel_start_addr(&boot_info, | ||
316 | firmware_end_addr); | ||
317 | - | ||
318 | - kernel_entry = riscv_load_kernel(machine, &s->soc.u_cpus, | ||
319 | - kernel_start_addr, true, NULL); | ||
320 | + riscv_load_kernel(machine, &boot_info, kernel_start_addr, | ||
321 | + true, NULL); | ||
322 | + kernel_entry = boot_info.image_low_addr; | ||
323 | } else { | ||
324 | /* | ||
325 | * If dynamic firmware is used, it doesn't know where is the next mode | ||
326 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_machine_init(MachineState *machine) | ||
327 | |||
328 | fdt_load_addr = riscv_compute_fdt_addr(memmap[SIFIVE_U_DEV_DRAM].base, | ||
329 | memmap[SIFIVE_U_DEV_DRAM].size, | ||
330 | - machine, &s->soc.u_cpus); | ||
331 | + machine, &boot_info); | ||
332 | riscv_load_fdt(fdt_load_addr, machine->fdt); | ||
333 | |||
334 | if (!riscv_is_32bit(&s->soc.u_cpus)) { | ||
94 | diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c | 335 | diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c |
95 | index XXXXXXX..XXXXXXX 100644 | 336 | index XXXXXXX..XXXXXXX 100644 |
96 | --- a/hw/riscv/spike.c | 337 | --- a/hw/riscv/spike.c |
97 | +++ b/hw/riscv/spike.c | 338 | +++ b/hw/riscv/spike.c |
98 | @@ -XXX,XX +XXX,XX @@ | 339 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) |
99 | #include "target/riscv/cpu.h" | 340 | char *soc_name; |
100 | #include "hw/riscv/riscv_htif.h" | 341 | int i, base_hartid, hart_count; |
101 | #include "hw/riscv/riscv_hart.h" | 342 | bool htif_custom_base = false; |
102 | -#include "hw/riscv/sifive_clint.h" | 343 | + RISCVBootInfo boot_info; |
103 | #include "hw/riscv/spike.h" | 344 | |
104 | #include "hw/riscv/boot.h" | 345 | /* Check socket count limit */ |
105 | #include "hw/riscv/numa.h" | 346 | if (SPIKE_SOCKETS_MAX < riscv_socket_count(machine)) { |
106 | +#include "hw/intc/sifive_clint.h" | 347 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) |
107 | #include "chardev/char.h" | 348 | create_fdt(s, memmap, riscv_is_32bit(&s->soc[0]), htif_custom_base); |
108 | #include "sysemu/arch_init.h" | 349 | |
109 | #include "sysemu/device_tree.h" | 350 | /* Load kernel */ |
351 | + riscv_boot_info_init(&boot_info, &s->soc[0]); | ||
352 | if (machine->kernel_filename) { | ||
353 | - kernel_start_addr = riscv_calc_kernel_start_addr(&s->soc[0], | ||
354 | + kernel_start_addr = riscv_calc_kernel_start_addr(&boot_info, | ||
355 | firmware_end_addr); | ||
356 | |||
357 | - kernel_entry = riscv_load_kernel(machine, &s->soc[0], | ||
358 | - kernel_start_addr, | ||
359 | - true, htif_symbol_callback); | ||
360 | + riscv_load_kernel(machine, &boot_info, kernel_start_addr, | ||
361 | + true, htif_symbol_callback); | ||
362 | + kernel_entry = boot_info.image_low_addr; | ||
363 | } else { | ||
364 | /* | ||
365 | * If dynamic firmware is used, it doesn't know where is the next mode | ||
366 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) | ||
367 | |||
368 | fdt_load_addr = riscv_compute_fdt_addr(memmap[SPIKE_DRAM].base, | ||
369 | memmap[SPIKE_DRAM].size, | ||
370 | - machine, &s->soc[0]); | ||
371 | + machine, &boot_info); | ||
372 | riscv_load_fdt(fdt_load_addr, machine->fdt); | ||
373 | |||
374 | /* load the reset vector */ | ||
110 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | 375 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c |
111 | index XXXXXXX..XXXXXXX 100644 | 376 | index XXXXXXX..XXXXXXX 100644 |
112 | --- a/hw/riscv/virt.c | 377 | --- a/hw/riscv/virt.c |
113 | +++ b/hw/riscv/virt.c | 378 | +++ b/hw/riscv/virt.c |
114 | @@ -XXX,XX +XXX,XX @@ | 379 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_done(Notifier *notifier, void *data) |
115 | #include "target/riscv/cpu.h" | 380 | uint64_t fdt_load_addr; |
116 | #include "hw/riscv/riscv_hart.h" | 381 | uint64_t kernel_entry = 0; |
117 | #include "hw/riscv/sifive_plic.h" | 382 | BlockBackend *pflash_blk0; |
118 | -#include "hw/riscv/sifive_clint.h" | 383 | + RISCVBootInfo boot_info; |
119 | #include "hw/riscv/sifive_test.h" | 384 | |
120 | #include "hw/riscv/virt.h" | 385 | /* |
121 | #include "hw/riscv/boot.h" | 386 | * An user provided dtb must include everything, including |
122 | #include "hw/riscv/numa.h" | 387 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_done(Notifier *notifier, void *data) |
123 | +#include "hw/intc/sifive_clint.h" | 388 | } |
124 | #include "chardev/char.h" | 389 | } |
125 | #include "sysemu/arch_init.h" | 390 | |
126 | #include "sysemu/device_tree.h" | 391 | + riscv_boot_info_init(&boot_info, &s->soc[0]); |
127 | diff --git a/hw/intc/Kconfig b/hw/intc/Kconfig | ||
128 | index XXXXXXX..XXXXXXX 100644 | ||
129 | --- a/hw/intc/Kconfig | ||
130 | +++ b/hw/intc/Kconfig | ||
131 | @@ -XXX,XX +XXX,XX @@ config RX_ICU | ||
132 | |||
133 | config LOONGSON_LIOINTC | ||
134 | bool | ||
135 | + | 392 | + |
136 | +config SIFIVE_CLINT | 393 | if (machine->kernel_filename && !kernel_entry) { |
137 | + bool | 394 | - kernel_start_addr = riscv_calc_kernel_start_addr(&s->soc[0], |
138 | diff --git a/hw/intc/meson.build b/hw/intc/meson.build | 395 | + kernel_start_addr = riscv_calc_kernel_start_addr(&boot_info, |
139 | index XXXXXXX..XXXXXXX 100644 | 396 | firmware_end_addr); |
140 | --- a/hw/intc/meson.build | 397 | - |
141 | +++ b/hw/intc/meson.build | 398 | - kernel_entry = riscv_load_kernel(machine, &s->soc[0], |
142 | @@ -XXX,XX +XXX,XX @@ specific_ss.add(when: 'CONFIG_RX_ICU', if_true: files('rx_icu.c')) | 399 | - kernel_start_addr, true, NULL); |
143 | specific_ss.add(when: 'CONFIG_S390_FLIC', if_true: files('s390_flic.c')) | 400 | + riscv_load_kernel(machine, &boot_info, kernel_start_addr, |
144 | specific_ss.add(when: 'CONFIG_S390_FLIC_KVM', if_true: files('s390_flic_kvm.c')) | 401 | + true, NULL); |
145 | specific_ss.add(when: 'CONFIG_SH4', if_true: files('sh_intc.c')) | 402 | + kernel_entry = boot_info.image_low_addr; |
146 | +specific_ss.add(when: 'CONFIG_SIFIVE_CLINT', if_true: files('sifive_clint.c')) | 403 | } |
147 | specific_ss.add(when: 'CONFIG_XICS', if_true: files('xics.c')) | 404 | |
148 | specific_ss.add(when: 'CONFIG_XICS_KVM', if_true: files('xics_kvm.c')) | 405 | fdt_load_addr = riscv_compute_fdt_addr(memmap[VIRT_DRAM].base, |
149 | specific_ss.add(when: 'CONFIG_XICS_SPAPR', if_true: files('xics_spapr.c')) | 406 | memmap[VIRT_DRAM].size, |
150 | diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig | 407 | - machine, &s->soc[0]); |
151 | index XXXXXXX..XXXXXXX 100644 | 408 | + machine, &boot_info); |
152 | --- a/hw/riscv/Kconfig | 409 | riscv_load_fdt(fdt_load_addr, machine->fdt); |
153 | +++ b/hw/riscv/Kconfig | 410 | |
154 | @@ -XXX,XX +XXX,XX @@ config SIFIVE_E | 411 | /* load the reset vector */ |
155 | bool | ||
156 | select HART | ||
157 | select SIFIVE | ||
158 | + select SIFIVE_CLINT | ||
159 | select SIFIVE_GPIO | ||
160 | select SIFIVE_E_PRCI | ||
161 | select UNIMP | ||
162 | @@ -XXX,XX +XXX,XX @@ config SIFIVE_U | ||
163 | select CADENCE | ||
164 | select HART | ||
165 | select SIFIVE | ||
166 | + select SIFIVE_CLINT | ||
167 | select SIFIVE_GPIO | ||
168 | select SIFIVE_PDMA | ||
169 | select SIFIVE_U_OTP | ||
170 | @@ -XXX,XX +XXX,XX @@ config SPIKE | ||
171 | select HART | ||
172 | select HTIF | ||
173 | select SIFIVE | ||
174 | + select SIFIVE_CLINT | ||
175 | |||
176 | config OPENTITAN | ||
177 | bool | ||
178 | @@ -XXX,XX +XXX,XX @@ config RISCV_VIRT | ||
179 | select PCI_EXPRESS_GENERIC_BRIDGE | ||
180 | select PFLASH_CFI01 | ||
181 | select SIFIVE | ||
182 | + select SIFIVE_CLINT | ||
183 | |||
184 | config MICROCHIP_PFSOC | ||
185 | bool | ||
186 | select HART | ||
187 | select SIFIVE | ||
188 | + select SIFIVE_CLINT | ||
189 | select UNIMP | ||
190 | select MCHP_PFSOC_MMUART | ||
191 | select SIFIVE_PDMA | ||
192 | diff --git a/hw/riscv/meson.build b/hw/riscv/meson.build | ||
193 | index XXXXXXX..XXXXXXX 100644 | ||
194 | --- a/hw/riscv/meson.build | ||
195 | +++ b/hw/riscv/meson.build | ||
196 | @@ -XXX,XX +XXX,XX @@ riscv_ss.add(files('numa.c')) | ||
197 | riscv_ss.add(when: 'CONFIG_HART', if_true: files('riscv_hart.c')) | ||
198 | riscv_ss.add(when: 'CONFIG_OPENTITAN', if_true: files('opentitan.c')) | ||
199 | riscv_ss.add(when: 'CONFIG_RISCV_VIRT', if_true: files('virt.c')) | ||
200 | -riscv_ss.add(when: 'CONFIG_SIFIVE', if_true: files('sifive_clint.c')) | ||
201 | riscv_ss.add(when: 'CONFIG_SIFIVE', if_true: files('sifive_plic.c')) | ||
202 | riscv_ss.add(when: 'CONFIG_SIFIVE', if_true: files('sifive_test.c')) | ||
203 | riscv_ss.add(when: 'CONFIG_SIFIVE', if_true: files('sifive_uart.c')) | ||
204 | -- | 412 | -- |
205 | 2.28.0 | 413 | 2.47.1 |
206 | |||
207 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Jim Shu <jim.shu@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | SiFive FU540 SoC integrates a platform DMA controller with 4 DMA | 3 | DTB is placed to the end of memory, so we will check if the start |
4 | channels. This connects the exsiting SiFive PDMA model to the SoC, | 4 | address of DTB overlaps to the address of kernel/initrd. |
5 | and adds its device tree data as well. | ||
6 | 5 | ||
7 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 6 | Signed-off-by: Jim Shu <jim.shu@sifive.com> |
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Message-Id: <1598924352-89526-17-git-send-email-bmeng.cn@gmail.com> | 8 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
9 | Message-ID: <20241120153935.24706-4-jim.shu@sifive.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 11 | --- |
12 | include/hw/riscv/sifive_u.h | 11 +++++++++++ | 12 | include/hw/riscv/boot.h | 3 +++ |
13 | hw/riscv/sifive_u.c | 30 ++++++++++++++++++++++++++++++ | 13 | hw/riscv/boot.c | 25 ++++++++++++++++++++++++- |
14 | hw/riscv/Kconfig | 1 + | 14 | 2 files changed, 27 insertions(+), 1 deletion(-) |
15 | 3 files changed, 42 insertions(+) | ||
16 | 15 | ||
17 | diff --git a/include/hw/riscv/sifive_u.h b/include/hw/riscv/sifive_u.h | 16 | diff --git a/include/hw/riscv/boot.h b/include/hw/riscv/boot.h |
18 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/include/hw/riscv/sifive_u.h | 18 | --- a/include/hw/riscv/boot.h |
20 | +++ b/include/hw/riscv/sifive_u.h | 19 | +++ b/include/hw/riscv/boot.h |
21 | @@ -XXX,XX +XXX,XX @@ | 20 | @@ -XXX,XX +XXX,XX @@ typedef struct RISCVBootInfo { |
22 | #ifndef HW_SIFIVE_U_H | 21 | hwaddr image_low_addr; |
23 | #define HW_SIFIVE_U_H | 22 | hwaddr image_high_addr; |
24 | 23 | ||
25 | +#include "hw/dma/sifive_pdma.h" | 24 | + hwaddr initrd_start; |
26 | #include "hw/net/cadence_gem.h" | 25 | + ssize_t initrd_size; |
27 | #include "hw/riscv/riscv_hart.h" | 26 | + |
28 | #include "hw/riscv/sifive_cpu.h" | 27 | bool is_32bit; |
29 | @@ -XXX,XX +XXX,XX @@ typedef struct SiFiveUSoCState { | 28 | } RISCVBootInfo; |
30 | SiFiveUPRCIState prci; | 29 | |
31 | SIFIVEGPIOState gpio; | 30 | diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c |
32 | SiFiveUOTPState otp; | ||
33 | + SiFivePDMAState dma; | ||
34 | CadenceGEMState gem; | ||
35 | |||
36 | uint32_t serial; | ||
37 | @@ -XXX,XX +XXX,XX @@ enum { | ||
38 | SIFIVE_U_MROM, | ||
39 | SIFIVE_U_CLINT, | ||
40 | SIFIVE_U_L2CC, | ||
41 | + SIFIVE_U_PDMA, | ||
42 | SIFIVE_U_L2LIM, | ||
43 | SIFIVE_U_PLIC, | ||
44 | SIFIVE_U_PRCI, | ||
45 | @@ -XXX,XX +XXX,XX @@ enum { | ||
46 | SIFIVE_U_GPIO_IRQ13 = 20, | ||
47 | SIFIVE_U_GPIO_IRQ14 = 21, | ||
48 | SIFIVE_U_GPIO_IRQ15 = 22, | ||
49 | + SIFIVE_U_PDMA_IRQ0 = 23, | ||
50 | + SIFIVE_U_PDMA_IRQ1 = 24, | ||
51 | + SIFIVE_U_PDMA_IRQ2 = 25, | ||
52 | + SIFIVE_U_PDMA_IRQ3 = 26, | ||
53 | + SIFIVE_U_PDMA_IRQ4 = 27, | ||
54 | + SIFIVE_U_PDMA_IRQ5 = 28, | ||
55 | + SIFIVE_U_PDMA_IRQ6 = 29, | ||
56 | + SIFIVE_U_PDMA_IRQ7 = 30, | ||
57 | SIFIVE_U_GEM_IRQ = 0x35 | ||
58 | }; | ||
59 | |||
60 | diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c | ||
61 | index XXXXXXX..XXXXXXX 100644 | 31 | index XXXXXXX..XXXXXXX 100644 |
62 | --- a/hw/riscv/sifive_u.c | 32 | --- a/hw/riscv/boot.c |
63 | +++ b/hw/riscv/sifive_u.c | 33 | +++ b/hw/riscv/boot.c |
64 | @@ -XXX,XX +XXX,XX @@ | 34 | @@ -XXX,XX +XXX,XX @@ char *riscv_plic_hart_config_string(int hart_count) |
65 | * 4) GPIO (General Purpose Input/Output Controller) | 35 | void riscv_boot_info_init(RISCVBootInfo *info, RISCVHartArrayState *harts) |
66 | * 5) OTP (One-Time Programmable) memory with stored serial number | 36 | { |
67 | * 6) GEM (Gigabit Ethernet Controller) and management block | 37 | info->kernel_size = 0; |
68 | + * 7) DMA (Direct Memory Access Controller) | 38 | + info->initrd_size = 0; |
69 | * | 39 | info->is_32bit = riscv_is_32bit(harts); |
70 | * This board currently generates devicetree dynamically that indicates at least | 40 | } |
71 | * two harts and up to five harts. | 41 | |
72 | @@ -XXX,XX +XXX,XX @@ static const struct MemmapEntry { | 42 | @@ -XXX,XX +XXX,XX @@ static void riscv_load_initrd(MachineState *machine, RISCVBootInfo *info) |
73 | [SIFIVE_U_MROM] = { 0x1000, 0xf000 }, | 43 | } |
74 | [SIFIVE_U_CLINT] = { 0x2000000, 0x10000 }, | 44 | } |
75 | [SIFIVE_U_L2CC] = { 0x2010000, 0x1000 }, | 45 | |
76 | + [SIFIVE_U_PDMA] = { 0x3000000, 0x100000 }, | 46 | + info->initrd_start = start; |
77 | [SIFIVE_U_L2LIM] = { 0x8000000, 0x2000000 }, | 47 | + info->initrd_size = size; |
78 | [SIFIVE_U_PLIC] = { 0xc000000, 0x4000000 }, | ||
79 | [SIFIVE_U_PRCI] = { 0x10000000, 0x1000 }, | ||
80 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap, | ||
81 | qemu_fdt_setprop_string(fdt, nodename, "compatible", "gpio-restart"); | ||
82 | g_free(nodename); | ||
83 | |||
84 | + nodename = g_strdup_printf("/soc/dma@%lx", | ||
85 | + (long)memmap[SIFIVE_U_PDMA].base); | ||
86 | + qemu_fdt_add_subnode(fdt, nodename); | ||
87 | + qemu_fdt_setprop_cell(fdt, nodename, "#dma-cells", 1); | ||
88 | + qemu_fdt_setprop_cells(fdt, nodename, "interrupts", | ||
89 | + SIFIVE_U_PDMA_IRQ0, SIFIVE_U_PDMA_IRQ1, SIFIVE_U_PDMA_IRQ2, | ||
90 | + SIFIVE_U_PDMA_IRQ3, SIFIVE_U_PDMA_IRQ4, SIFIVE_U_PDMA_IRQ5, | ||
91 | + SIFIVE_U_PDMA_IRQ6, SIFIVE_U_PDMA_IRQ7); | ||
92 | + qemu_fdt_setprop_cell(fdt, nodename, "interrupt-parent", plic_phandle); | ||
93 | + qemu_fdt_setprop_cells(fdt, nodename, "reg", | ||
94 | + 0x0, memmap[SIFIVE_U_PDMA].base, | ||
95 | + 0x0, memmap[SIFIVE_U_PDMA].size); | ||
96 | + qemu_fdt_setprop_string(fdt, nodename, "compatible", | ||
97 | + "sifive,fu540-c000-pdma"); | ||
98 | + g_free(nodename); | ||
99 | + | 48 | + |
100 | nodename = g_strdup_printf("/soc/cache-controller@%lx", | 49 | /* Some RISC-V machines (e.g. opentitan) don't have a fdt. */ |
101 | (long)memmap[SIFIVE_U_L2CC].base); | 50 | if (fdt) { |
102 | qemu_fdt_add_subnode(fdt, nodename); | 51 | end = start + size; |
103 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_soc_instance_init(Object *obj) | 52 | @@ -XXX,XX +XXX,XX @@ uint64_t riscv_compute_fdt_addr(hwaddr dram_base, hwaddr dram_size, |
104 | object_initialize_child(obj, "otp", &s->otp, TYPE_SIFIVE_U_OTP); | 53 | int ret = fdt_pack(ms->fdt); |
105 | object_initialize_child(obj, "gem", &s->gem, TYPE_CADENCE_GEM); | 54 | hwaddr dram_end, temp; |
106 | object_initialize_child(obj, "gpio", &s->gpio, TYPE_SIFIVE_GPIO); | 55 | int fdtsize; |
107 | + object_initialize_child(obj, "pdma", &s->dma, TYPE_SIFIVE_PDMA); | 56 | + uint64_t dtb_start, dtb_start_limit; |
108 | } | 57 | |
109 | 58 | /* Should only fail if we've built a corrupted tree */ | |
110 | static void sifive_u_soc_realize(DeviceState *dev, Error **errp) | 59 | g_assert(ret == 0); |
111 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_soc_realize(DeviceState *dev, Error **errp) | 60 | @@ -XXX,XX +XXX,XX @@ uint64_t riscv_compute_fdt_addr(hwaddr dram_base, hwaddr dram_size, |
112 | SIFIVE_U_GPIO_IRQ0 + i)); | 61 | exit(1); |
113 | } | 62 | } |
114 | 63 | ||
115 | + /* PDMA */ | 64 | + if (info->initrd_size) { |
116 | + sysbus_realize(SYS_BUS_DEVICE(&s->dma), errp); | 65 | + /* If initrd is successfully loaded, place DTB after it. */ |
117 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->dma), 0, memmap[SIFIVE_U_PDMA].base); | 66 | + dtb_start_limit = info->initrd_start + info->initrd_size; |
118 | + | 67 | + } else if (info->kernel_size) { |
119 | + /* Connect PDMA interrupts to the PLIC */ | 68 | + /* If only kernel is successfully loaded, place DTB after it. */ |
120 | + for (i = 0; i < SIFIVE_PDMA_IRQS; i++) { | 69 | + dtb_start_limit = info->image_high_addr; |
121 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->dma), i, | 70 | + } else { |
122 | + qdev_get_gpio_in(DEVICE(s->plic), | 71 | + /* Otherwise, do not check DTB overlapping */ |
123 | + SIFIVE_U_PDMA_IRQ0 + i)); | 72 | + dtb_start_limit = 0; |
124 | + } | 73 | + } |
125 | + | 74 | + |
126 | qdev_prop_set_uint32(DEVICE(&s->otp), "serial", s->serial); | 75 | /* |
127 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->otp), errp)) { | 76 | * A dram_size == 0, usually from a MemMapEntry[].size element, |
128 | return; | 77 | * means that the DRAM block goes all the way to ms->ram_size. |
129 | diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig | 78 | @@ -XXX,XX +XXX,XX @@ uint64_t riscv_compute_fdt_addr(hwaddr dram_base, hwaddr dram_size, |
130 | index XXXXXXX..XXXXXXX 100644 | 79 | temp = (dram_base < 3072 * MiB) ? MIN(dram_end, 3072 * MiB) : dram_end; |
131 | --- a/hw/riscv/Kconfig | 80 | } |
132 | +++ b/hw/riscv/Kconfig | 81 | |
133 | @@ -XXX,XX +XXX,XX @@ config SIFIVE_U | 82 | - return QEMU_ALIGN_DOWN(temp - fdtsize, 2 * MiB); |
134 | select CADENCE | 83 | + dtb_start = QEMU_ALIGN_DOWN(temp - fdtsize, 2 * MiB); |
135 | select HART | 84 | + |
136 | select SIFIVE | 85 | + if (dtb_start_limit && (dtb_start < dtb_start_limit)) { |
137 | + select SIFIVE_PDMA | 86 | + error_report("No enough memory to place DTB after kernel/initrd"); |
138 | select UNIMP | 87 | + exit(1); |
139 | 88 | + } | |
140 | config SPIKE | 89 | + |
90 | + return dtb_start; | ||
91 | } | ||
92 | |||
93 | /* | ||
141 | -- | 94 | -- |
142 | 2.28.0 | 95 | 2.47.1 |
143 | |||
144 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: "Fea.Wang" <fea.wang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Microchip PolarFire SoC integrates 3 GPIOs controllers. It seems | 3 | Refer to the draft of svukte extension from: |
4 | enough to create unimplemented devices to cover their register | 4 | https://github.com/riscv/riscv-isa-manual/pull/1564 |
5 | spaces at this point. | ||
6 | 5 | ||
7 | With this commit, QEMU can boot to U-Boot (2nd stage bootloader) | 6 | Svukte provides a means to make user-mode accesses to supervisor memory |
8 | all the way to the Linux shell login prompt, with a modified HSS | 7 | raise page faults in constant time, mitigating attacks that attempt to |
9 | (1st stage bootloader). | 8 | discover the supervisor software's address-space layout. |
10 | 9 | ||
11 | For detailed instructions on how to create images for the Icicle | 10 | Signed-off-by: Fea.Wang <fea.wang@sifive.com> |
12 | Kit board, please check QEMU RISC-V WiKi page at: | 11 | Reviewed-by: Frank Chang <frank.chang@sifive.com> |
13 | https://wiki.qemu.org/Documentation/Platforms/RISCV | 12 | Reviewed-by: Jim Shu <jim.shu@sifive.com> |
14 | 13 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | |
15 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | ||
16 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 14 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
17 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 15 | Message-ID: <20241203034932.25185-2-fea.wang@sifive.com> |
18 | Message-Id: <1598924352-89526-15-git-send-email-bmeng.cn@gmail.com> | ||
19 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
20 | --- | 17 | --- |
21 | include/hw/riscv/microchip_pfsoc.h | 3 +++ | 18 | target/riscv/cpu_cfg.h | 1 + |
22 | hw/riscv/microchip_pfsoc.c | 14 ++++++++++++++ | 19 | 1 file changed, 1 insertion(+) |
23 | 2 files changed, 17 insertions(+) | ||
24 | 20 | ||
25 | diff --git a/include/hw/riscv/microchip_pfsoc.h b/include/hw/riscv/microchip_pfsoc.h | 21 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h |
26 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/include/hw/riscv/microchip_pfsoc.h | 23 | --- a/target/riscv/cpu_cfg.h |
28 | +++ b/include/hw/riscv/microchip_pfsoc.h | 24 | +++ b/target/riscv/cpu_cfg.h |
29 | @@ -XXX,XX +XXX,XX @@ enum { | 25 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { |
30 | MICROCHIP_PFSOC_MMUART4, | 26 | bool ext_svnapot; |
31 | MICROCHIP_PFSOC_GEM0, | 27 | bool ext_svpbmt; |
32 | MICROCHIP_PFSOC_GEM1, | 28 | bool ext_svvptc; |
33 | + MICROCHIP_PFSOC_GPIO0, | 29 | + bool ext_svukte; |
34 | + MICROCHIP_PFSOC_GPIO1, | 30 | bool ext_zdinx; |
35 | + MICROCHIP_PFSOC_GPIO2, | 31 | bool ext_zaamo; |
36 | MICROCHIP_PFSOC_ENVM_CFG, | 32 | bool ext_zacas; |
37 | MICROCHIP_PFSOC_ENVM_DATA, | ||
38 | MICROCHIP_PFSOC_IOSCB_CFG, | ||
39 | diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c | ||
40 | index XXXXXXX..XXXXXXX 100644 | ||
41 | --- a/hw/riscv/microchip_pfsoc.c | ||
42 | +++ b/hw/riscv/microchip_pfsoc.c | ||
43 | @@ -XXX,XX +XXX,XX @@ static const struct MemmapEntry { | ||
44 | [MICROCHIP_PFSOC_MMUART4] = { 0x20106000, 0x1000 }, | ||
45 | [MICROCHIP_PFSOC_GEM0] = { 0x20110000, 0x2000 }, | ||
46 | [MICROCHIP_PFSOC_GEM1] = { 0x20112000, 0x2000 }, | ||
47 | + [MICROCHIP_PFSOC_GPIO0] = { 0x20120000, 0x1000 }, | ||
48 | + [MICROCHIP_PFSOC_GPIO1] = { 0x20121000, 0x1000 }, | ||
49 | + [MICROCHIP_PFSOC_GPIO2] = { 0x20122000, 0x1000 }, | ||
50 | [MICROCHIP_PFSOC_ENVM_CFG] = { 0x20200000, 0x1000 }, | ||
51 | [MICROCHIP_PFSOC_ENVM_DATA] = { 0x20220000, 0x20000 }, | ||
52 | [MICROCHIP_PFSOC_IOSCB_CFG] = { 0x37080000, 0x1000 }, | ||
53 | @@ -XXX,XX +XXX,XX @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp) | ||
54 | sysbus_connect_irq(SYS_BUS_DEVICE(&s->gem1), 0, | ||
55 | qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_GEM1_IRQ)); | ||
56 | |||
57 | + /* GPIOs */ | ||
58 | + create_unimplemented_device("microchip.pfsoc.gpio0", | ||
59 | + memmap[MICROCHIP_PFSOC_GPIO0].base, | ||
60 | + memmap[MICROCHIP_PFSOC_GPIO0].size); | ||
61 | + create_unimplemented_device("microchip.pfsoc.gpio1", | ||
62 | + memmap[MICROCHIP_PFSOC_GPIO1].base, | ||
63 | + memmap[MICROCHIP_PFSOC_GPIO1].size); | ||
64 | + create_unimplemented_device("microchip.pfsoc.gpio2", | ||
65 | + memmap[MICROCHIP_PFSOC_GPIO2].base, | ||
66 | + memmap[MICROCHIP_PFSOC_GPIO2].size); | ||
67 | + | ||
68 | /* eNVM */ | ||
69 | memory_region_init_rom(envm_data, OBJECT(dev), "microchip.pfsoc.envm.data", | ||
70 | memmap[MICROCHIP_PFSOC_ENVM_DATA].size, | ||
71 | -- | 33 | -- |
72 | 2.28.0 | 34 | 2.47.1 |
73 | |||
74 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: "Fea.Wang" <fea.wang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Microchip PolarFire SoC integrates 2 Candence GEMs to provide | 3 | Svukte extension add UKTE bit, bit[8] in senvcfg CSR. The bit will be |
4 | IEEE 802.3 standard-compliant 10/100/1000 Mbps ethernet interface. | 4 | supported when the svukte extension is enabled. |
5 | 5 | ||
6 | On the Icicle Kit board, GEM0 connects to a PHY at address 8 while | 6 | When senvcfg[UKTE] bit is set, the memory access from U-mode should do |
7 | GEM1 connects to a PHY at address 9. | 7 | the svukte check only except HLV/HLVX/HSV H-mode instructions which |
8 | depend on hstatus[HUKTE]. | ||
8 | 9 | ||
9 | The 2nd stage bootloader (U-Boot) is using GEM1 by default, so we | 10 | Signed-off-by: Fea.Wang <fea.wang@sifive.com> |
10 | must specify 2 '-nic' options from the command line in order to get | 11 | Reviewed-by: Frank Chang <frank.chang@sifive.com> |
11 | a working ethernet. | 12 | Reviewed-by: Jim Shu <jim.shu@sifive.com> |
12 | 13 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | |
13 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | ||
14 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 14 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
15 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 15 | Message-ID: <20241203034932.25185-3-fea.wang@sifive.com> |
16 | Message-Id: <1598924352-89526-14-git-send-email-bmeng.cn@gmail.com> | ||
17 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
18 | --- | 17 | --- |
19 | include/hw/riscv/microchip_pfsoc.h | 7 ++++++ | 18 | target/riscv/cpu_bits.h | 1 + |
20 | hw/riscv/microchip_pfsoc.c | 39 ++++++++++++++++++++++++++++++ | 19 | target/riscv/csr.c | 4 ++++ |
21 | 2 files changed, 46 insertions(+) | 20 | 2 files changed, 5 insertions(+) |
22 | 21 | ||
23 | diff --git a/include/hw/riscv/microchip_pfsoc.h b/include/hw/riscv/microchip_pfsoc.h | 22 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h |
24 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
25 | --- a/include/hw/riscv/microchip_pfsoc.h | 24 | --- a/target/riscv/cpu_bits.h |
26 | +++ b/include/hw/riscv/microchip_pfsoc.h | 25 | +++ b/target/riscv/cpu_bits.h |
27 | @@ -XXX,XX +XXX,XX @@ | 26 | @@ -XXX,XX +XXX,XX @@ typedef enum RISCVException { |
28 | 27 | #define SENVCFG_CBIE MENVCFG_CBIE | |
29 | #include "hw/char/mchp_pfsoc_mmuart.h" | 28 | #define SENVCFG_CBCFE MENVCFG_CBCFE |
30 | #include "hw/dma/sifive_pdma.h" | 29 | #define SENVCFG_CBZE MENVCFG_CBZE |
31 | +#include "hw/net/cadence_gem.h" | 30 | +#define SENVCFG_UKTE BIT(8) |
32 | #include "hw/sd/cadence_sdhci.h" | 31 | |
33 | 32 | #define HENVCFG_FIOM MENVCFG_FIOM | |
34 | typedef struct MicrochipPFSoCState { | 33 | #define HENVCFG_LPE MENVCFG_LPE |
35 | @@ -XXX,XX +XXX,XX @@ typedef struct MicrochipPFSoCState { | 34 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
36 | MchpPfSoCMMUartState *serial3; | ||
37 | MchpPfSoCMMUartState *serial4; | ||
38 | SiFivePDMAState dma; | ||
39 | + CadenceGEMState gem0; | ||
40 | + CadenceGEMState gem1; | ||
41 | CadenceSDHCIState sdhci; | ||
42 | } MicrochipPFSoCState; | ||
43 | |||
44 | @@ -XXX,XX +XXX,XX @@ enum { | ||
45 | MICROCHIP_PFSOC_MMUART2, | ||
46 | MICROCHIP_PFSOC_MMUART3, | ||
47 | MICROCHIP_PFSOC_MMUART4, | ||
48 | + MICROCHIP_PFSOC_GEM0, | ||
49 | + MICROCHIP_PFSOC_GEM1, | ||
50 | MICROCHIP_PFSOC_ENVM_CFG, | ||
51 | MICROCHIP_PFSOC_ENVM_DATA, | ||
52 | MICROCHIP_PFSOC_IOSCB_CFG, | ||
53 | @@ -XXX,XX +XXX,XX @@ enum { | ||
54 | MICROCHIP_PFSOC_DMA_IRQ5 = 10, | ||
55 | MICROCHIP_PFSOC_DMA_IRQ6 = 11, | ||
56 | MICROCHIP_PFSOC_DMA_IRQ7 = 12, | ||
57 | + MICROCHIP_PFSOC_GEM0_IRQ = 64, | ||
58 | + MICROCHIP_PFSOC_GEM1_IRQ = 70, | ||
59 | MICROCHIP_PFSOC_EMMC_SD_IRQ = 88, | ||
60 | MICROCHIP_PFSOC_MMUART0_IRQ = 90, | ||
61 | MICROCHIP_PFSOC_MMUART1_IRQ = 91, | ||
62 | diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c | ||
63 | index XXXXXXX..XXXXXXX 100644 | 35 | index XXXXXXX..XXXXXXX 100644 |
64 | --- a/hw/riscv/microchip_pfsoc.c | 36 | --- a/target/riscv/csr.c |
65 | +++ b/hw/riscv/microchip_pfsoc.c | 37 | +++ b/target/riscv/csr.c |
66 | @@ -XXX,XX +XXX,XX @@ | 38 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_senvcfg(CPURISCVState *env, int csrno, |
67 | * 3) MMUARTs (Multi-Mode UART) | 39 | mask |= SENVCFG_SSE; |
68 | * 4) Cadence eMMC/SDHC controller and an SD card connected to it | 40 | } |
69 | * 5) SiFive Platform DMA (Direct Memory Access Controller) | 41 | |
70 | + * 6) GEM (Gigabit Ethernet MAC Controller) | 42 | + if (env_archcpu(env)->cfg.ext_svukte) { |
71 | * | 43 | + mask |= SENVCFG_UKTE; |
72 | * This board currently generates devicetree dynamically that indicates at least | ||
73 | * two harts and up to five harts. | ||
74 | @@ -XXX,XX +XXX,XX @@ | ||
75 | #define BIOS_FILENAME "hss.bin" | ||
76 | #define RESET_VECTOR 0x20220000 | ||
77 | |||
78 | +/* GEM version */ | ||
79 | +#define GEM_REVISION 0x0107010c | ||
80 | + | ||
81 | static const struct MemmapEntry { | ||
82 | hwaddr base; | ||
83 | hwaddr size; | ||
84 | @@ -XXX,XX +XXX,XX @@ static const struct MemmapEntry { | ||
85 | [MICROCHIP_PFSOC_MMUART2] = { 0x20102000, 0x1000 }, | ||
86 | [MICROCHIP_PFSOC_MMUART3] = { 0x20104000, 0x1000 }, | ||
87 | [MICROCHIP_PFSOC_MMUART4] = { 0x20106000, 0x1000 }, | ||
88 | + [MICROCHIP_PFSOC_GEM0] = { 0x20110000, 0x2000 }, | ||
89 | + [MICROCHIP_PFSOC_GEM1] = { 0x20112000, 0x2000 }, | ||
90 | [MICROCHIP_PFSOC_ENVM_CFG] = { 0x20200000, 0x1000 }, | ||
91 | [MICROCHIP_PFSOC_ENVM_DATA] = { 0x20220000, 0x20000 }, | ||
92 | [MICROCHIP_PFSOC_IOSCB_CFG] = { 0x37080000, 0x1000 }, | ||
93 | @@ -XXX,XX +XXX,XX @@ static void microchip_pfsoc_soc_instance_init(Object *obj) | ||
94 | object_initialize_child(obj, "dma-controller", &s->dma, | ||
95 | TYPE_SIFIVE_PDMA); | ||
96 | |||
97 | + object_initialize_child(obj, "gem0", &s->gem0, TYPE_CADENCE_GEM); | ||
98 | + object_initialize_child(obj, "gem1", &s->gem1, TYPE_CADENCE_GEM); | ||
99 | + | ||
100 | object_initialize_child(obj, "sd-controller", &s->sdhci, | ||
101 | TYPE_CADENCE_SDHCI); | ||
102 | } | ||
103 | @@ -XXX,XX +XXX,XX @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp) | ||
104 | MemoryRegion *envm_data = g_new(MemoryRegion, 1); | ||
105 | char *plic_hart_config; | ||
106 | size_t plic_hart_config_len; | ||
107 | + NICInfo *nd; | ||
108 | int i; | ||
109 | |||
110 | sysbus_realize(SYS_BUS_DEVICE(&s->e_cpus), &error_abort); | ||
111 | @@ -XXX,XX +XXX,XX @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp) | ||
112 | qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_MMUART4_IRQ), | ||
113 | serial_hd(4)); | ||
114 | |||
115 | + /* GEMs */ | ||
116 | + | ||
117 | + nd = &nd_table[0]; | ||
118 | + if (nd->used) { | ||
119 | + qemu_check_nic_model(nd, TYPE_CADENCE_GEM); | ||
120 | + qdev_set_nic_properties(DEVICE(&s->gem0), nd); | ||
121 | + } | ||
122 | + nd = &nd_table[1]; | ||
123 | + if (nd->used) { | ||
124 | + qemu_check_nic_model(nd, TYPE_CADENCE_GEM); | ||
125 | + qdev_set_nic_properties(DEVICE(&s->gem1), nd); | ||
126 | + } | 44 | + } |
127 | + | 45 | + |
128 | + object_property_set_int(OBJECT(&s->gem0), "revision", GEM_REVISION, errp); | 46 | env->senvcfg = (env->senvcfg & ~mask) | (val & mask); |
129 | + object_property_set_int(OBJECT(&s->gem0), "phy-addr", 8, errp); | 47 | return RISCV_EXCP_NONE; |
130 | + sysbus_realize(SYS_BUS_DEVICE(&s->gem0), errp); | 48 | } |
131 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->gem0), 0, | ||
132 | + memmap[MICROCHIP_PFSOC_GEM0].base); | ||
133 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->gem0), 0, | ||
134 | + qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_GEM0_IRQ)); | ||
135 | + | ||
136 | + object_property_set_int(OBJECT(&s->gem1), "revision", GEM_REVISION, errp); | ||
137 | + object_property_set_int(OBJECT(&s->gem1), "phy-addr", 9, errp); | ||
138 | + sysbus_realize(SYS_BUS_DEVICE(&s->gem1), errp); | ||
139 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->gem1), 0, | ||
140 | + memmap[MICROCHIP_PFSOC_GEM1].base); | ||
141 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->gem1), 0, | ||
142 | + qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_GEM1_IRQ)); | ||
143 | + | ||
144 | /* eNVM */ | ||
145 | memory_region_init_rom(envm_data, OBJECT(dev), "microchip.pfsoc.envm.data", | ||
146 | memmap[MICROCHIP_PFSOC_ENVM_DATA].size, | ||
147 | -- | 49 | -- |
148 | 2.28.0 | 50 | 2.47.1 |
149 | |||
150 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: "Fea.Wang" <fea.wang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | RISC-V machines do not instantiate RISC-V CPUs directly, instead | 3 | Svukte extension add HUKTE bit, bit[24] in hstatus CSR. The written |
4 | they do that via the hart array. Add a new property for the reset | 4 | value will be masked when the svukte extension is not enabled. |
5 | vector address to allow the value to be passed to the CPU, before | ||
6 | CPU is realized. | ||
7 | 5 | ||
8 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 6 | When hstatus[HUKTE] bit is set, HLV/HLVX/HSV work in the U-mode should |
7 | do svukte check. | ||
8 | |||
9 | Signed-off-by: Fea.Wang <fea.wang@sifive.com> | ||
10 | Reviewed-by: Frank Chang <frank.chang@sifive.com> | ||
11 | Reviewed-by: Jim Shu <jim.shu@sifive.com> | ||
12 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
10 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 14 | Message-ID: <20241203034932.25185-4-fea.wang@sifive.com> |
11 | Message-Id: <1598924352-89526-3-git-send-email-bmeng.cn@gmail.com> | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
13 | --- | 16 | --- |
14 | include/hw/riscv/riscv_hart.h | 1 + | 17 | target/riscv/cpu_bits.h | 1 + |
15 | hw/riscv/riscv_hart.c | 3 +++ | 18 | target/riscv/csr.c | 3 +++ |
16 | 2 files changed, 4 insertions(+) | 19 | 2 files changed, 4 insertions(+) |
17 | 20 | ||
18 | diff --git a/include/hw/riscv/riscv_hart.h b/include/hw/riscv/riscv_hart.h | 21 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h |
19 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/include/hw/riscv/riscv_hart.h | 23 | --- a/target/riscv/cpu_bits.h |
21 | +++ b/include/hw/riscv/riscv_hart.h | 24 | +++ b/target/riscv/cpu_bits.h |
22 | @@ -XXX,XX +XXX,XX @@ typedef struct RISCVHartArrayState { | 25 | @@ -XXX,XX +XXX,XX @@ typedef enum { |
23 | uint32_t num_harts; | 26 | #define HSTATUS_VTVM 0x00100000 |
24 | uint32_t hartid_base; | 27 | #define HSTATUS_VTW 0x00200000 |
25 | char *cpu_type; | 28 | #define HSTATUS_VTSR 0x00400000 |
26 | + uint64_t resetvec; | 29 | +#define HSTATUS_HUKTE 0x01000000 |
27 | RISCVCPU *harts; | 30 | #define HSTATUS_VSXL 0x300000000 |
28 | } RISCVHartArrayState; | 31 | |
29 | 32 | #define HSTATUS32_WPRI 0xFF8FF87E | |
30 | diff --git a/hw/riscv/riscv_hart.c b/hw/riscv/riscv_hart.c | 33 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
31 | index XXXXXXX..XXXXXXX 100644 | 34 | index XXXXXXX..XXXXXXX 100644 |
32 | --- a/hw/riscv/riscv_hart.c | 35 | --- a/target/riscv/csr.c |
33 | +++ b/hw/riscv/riscv_hart.c | 36 | +++ b/target/riscv/csr.c |
34 | @@ -XXX,XX +XXX,XX @@ static Property riscv_harts_props[] = { | 37 | @@ -XXX,XX +XXX,XX @@ static RISCVException read_hstatus(CPURISCVState *env, int csrno, |
35 | DEFINE_PROP_UINT32("num-harts", RISCVHartArrayState, num_harts, 1), | 38 | static RISCVException write_hstatus(CPURISCVState *env, int csrno, |
36 | DEFINE_PROP_UINT32("hartid-base", RISCVHartArrayState, hartid_base, 0), | 39 | target_ulong val) |
37 | DEFINE_PROP_STRING("cpu-type", RISCVHartArrayState, cpu_type), | ||
38 | + DEFINE_PROP_UINT64("resetvec", RISCVHartArrayState, resetvec, | ||
39 | + DEFAULT_RSTVEC), | ||
40 | DEFINE_PROP_END_OF_LIST(), | ||
41 | }; | ||
42 | |||
43 | @@ -XXX,XX +XXX,XX @@ static bool riscv_hart_realize(RISCVHartArrayState *s, int idx, | ||
44 | char *cpu_type, Error **errp) | ||
45 | { | 40 | { |
46 | object_initialize_child(OBJECT(s), "harts[*]", &s->harts[idx], cpu_type); | 41 | + if (!env_archcpu(env)->cfg.ext_svukte) { |
47 | + qdev_prop_set_uint64(DEVICE(&s->harts[idx]), "resetvec", s->resetvec); | 42 | + val = val & (~HSTATUS_HUKTE); |
48 | s->harts[idx].env.mhartid = s->hartid_base + idx; | 43 | + } |
49 | qemu_register_reset(riscv_harts_cpu_reset, &s->harts[idx]); | 44 | env->hstatus = val; |
50 | return qdev_realize(DEVICE(&s->harts[idx]), NULL, errp); | 45 | if (riscv_cpu_mxl(env) != MXL_RV32 && get_field(val, HSTATUS_VSXL) != 2) { |
46 | qemu_log_mask(LOG_UNIMP, | ||
51 | -- | 47 | -- |
52 | 2.28.0 | 48 | 2.47.1 |
53 | |||
54 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: "Fea.Wang" <fea.wang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Microchip PolarFire SoC integrates a DMA engine that supports: | 3 | Follow the Svukte spec, do the memory access address checking |
4 | * Independent concurrent DMA transfers using 4 DMA channels | ||
5 | * Generation of interrupts on various conditions during execution | ||
6 | which is actually an IP reused from the SiFive FU540 chip. | ||
7 | 4 | ||
8 | This creates a model to support both polling and interrupt modes. | 5 | 1. Include instruction fetches or explicit memory accesses |
6 | 2. System run in effective privilege U or VU | ||
7 | 3. Check senvcfg[UKTE] being set, or hstatus[HUKTE] being set if | ||
8 | instruction is HLV, HLVX, HSV and execute from U mode to VU mode | ||
9 | 4. Depend on Sv39 and check virtual addresses bit[SXLEN-1] | ||
10 | 5. Raises a page-fault exception corresponding to the original access | ||
11 | type. | ||
9 | 12 | ||
10 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 13 | Ref: https://github.com/riscv/riscv-isa-manual/pull/1564/files |
11 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | 14 | |
12 | Message-Id: <1598924352-89526-10-git-send-email-bmeng.cn@gmail.com> | 15 | Signed-off-by: Frank Chang <frank.chang@sifive.com> |
16 | Signed-off-by: Fea.Wang <fea.wang@sifive.com> | ||
17 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
18 | Reviewed-by: Jim Shu <jim.shu@sifive.com> | ||
19 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
20 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
21 | Message-ID: <20241203034932.25185-5-fea.wang@sifive.com> | ||
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 22 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
14 | --- | 23 | --- |
15 | include/hw/dma/sifive_pdma.h | 57 +++++++ | 24 | target/riscv/cpu_helper.c | 55 +++++++++++++++++++++++++++++++++++++++ |
16 | hw/dma/sifive_pdma.c | 313 +++++++++++++++++++++++++++++++++++ | 25 | 1 file changed, 55 insertions(+) |
17 | hw/dma/Kconfig | 3 + | ||
18 | hw/dma/meson.build | 1 + | ||
19 | 4 files changed, 374 insertions(+) | ||
20 | create mode 100644 include/hw/dma/sifive_pdma.h | ||
21 | create mode 100644 hw/dma/sifive_pdma.c | ||
22 | 26 | ||
23 | diff --git a/include/hw/dma/sifive_pdma.h b/include/hw/dma/sifive_pdma.h | 27 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c |
24 | new file mode 100644 | 28 | index XXXXXXX..XXXXXXX 100644 |
25 | index XXXXXXX..XXXXXXX | 29 | --- a/target/riscv/cpu_helper.c |
26 | --- /dev/null | 30 | +++ b/target/riscv/cpu_helper.c |
27 | +++ b/include/hw/dma/sifive_pdma.h | 31 | @@ -XXX,XX +XXX,XX @@ static int get_physical_address_pmp(CPURISCVState *env, int *prot, hwaddr addr, |
28 | @@ -XXX,XX +XXX,XX @@ | 32 | return TRANSLATE_SUCCESS; |
29 | +/* | 33 | } |
30 | + * SiFive Platform DMA emulation | 34 | |
31 | + * | 35 | +/* Returns 'true' if a svukte address check is needed */ |
32 | + * Copyright (c) 2020 Wind River Systems, Inc. | 36 | +static bool do_svukte_check(CPURISCVState *env, bool first_stage, |
33 | + * | 37 | + int mode, bool virt) |
34 | + * Author: | ||
35 | + * Bin Meng <bin.meng@windriver.com> | ||
36 | + * | ||
37 | + * This program is free software; you can redistribute it and/or | ||
38 | + * modify it under the terms of the GNU General Public License as | ||
39 | + * published by the Free Software Foundation; either version 2 or | ||
40 | + * (at your option) version 3 of the License. | ||
41 | + * | ||
42 | + * This program is distributed in the hope that it will be useful, | ||
43 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
44 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
45 | + * GNU General Public License for more details. | ||
46 | + * | ||
47 | + * You should have received a copy of the GNU General Public License along | ||
48 | + * with this program; if not, see <http://www.gnu.org/licenses/>. | ||
49 | + */ | ||
50 | + | ||
51 | +#ifndef SIFIVE_PDMA_H | ||
52 | +#define SIFIVE_PDMA_H | ||
53 | + | ||
54 | +struct sifive_pdma_chan { | ||
55 | + uint32_t control; | ||
56 | + uint32_t next_config; | ||
57 | + uint64_t next_bytes; | ||
58 | + uint64_t next_dst; | ||
59 | + uint64_t next_src; | ||
60 | + uint32_t exec_config; | ||
61 | + uint64_t exec_bytes; | ||
62 | + uint64_t exec_dst; | ||
63 | + uint64_t exec_src; | ||
64 | + int state; | ||
65 | +}; | ||
66 | + | ||
67 | +#define SIFIVE_PDMA_CHANS 4 | ||
68 | +#define SIFIVE_PDMA_IRQS (SIFIVE_PDMA_CHANS * 2) | ||
69 | +#define SIFIVE_PDMA_REG_SIZE 0x100000 | ||
70 | +#define SIFIVE_PDMA_CHAN_NO(reg) ((reg & (SIFIVE_PDMA_REG_SIZE - 1)) >> 12) | ||
71 | + | ||
72 | +typedef struct SiFivePDMAState { | ||
73 | + SysBusDevice parent; | ||
74 | + MemoryRegion iomem; | ||
75 | + qemu_irq irq[SIFIVE_PDMA_IRQS]; | ||
76 | + | ||
77 | + struct sifive_pdma_chan chan[SIFIVE_PDMA_CHANS]; | ||
78 | +} SiFivePDMAState; | ||
79 | + | ||
80 | +#define TYPE_SIFIVE_PDMA "sifive.pdma" | ||
81 | + | ||
82 | +#define SIFIVE_PDMA(obj) \ | ||
83 | + OBJECT_CHECK(SiFivePDMAState, (obj), TYPE_SIFIVE_PDMA) | ||
84 | + | ||
85 | +#endif /* SIFIVE_PDMA_H */ | ||
86 | diff --git a/hw/dma/sifive_pdma.c b/hw/dma/sifive_pdma.c | ||
87 | new file mode 100644 | ||
88 | index XXXXXXX..XXXXXXX | ||
89 | --- /dev/null | ||
90 | +++ b/hw/dma/sifive_pdma.c | ||
91 | @@ -XXX,XX +XXX,XX @@ | ||
92 | +/* | ||
93 | + * SiFive Platform DMA emulation | ||
94 | + * | ||
95 | + * Copyright (c) 2020 Wind River Systems, Inc. | ||
96 | + * | ||
97 | + * Author: | ||
98 | + * Bin Meng <bin.meng@windriver.com> | ||
99 | + * | ||
100 | + * This program is free software; you can redistribute it and/or | ||
101 | + * modify it under the terms of the GNU General Public License as | ||
102 | + * published by the Free Software Foundation; either version 2 or | ||
103 | + * (at your option) version 3 of the License. | ||
104 | + * | ||
105 | + * This program is distributed in the hope that it will be useful, | ||
106 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
107 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
108 | + * GNU General Public License for more details. | ||
109 | + * | ||
110 | + * You should have received a copy of the GNU General Public License along | ||
111 | + * with this program; if not, see <http://www.gnu.org/licenses/>. | ||
112 | + */ | ||
113 | + | ||
114 | +#include "qemu/osdep.h" | ||
115 | +#include "qemu/bitops.h" | ||
116 | +#include "qemu/log.h" | ||
117 | +#include "qapi/error.h" | ||
118 | +#include "hw/hw.h" | ||
119 | +#include "hw/irq.h" | ||
120 | +#include "hw/qdev-properties.h" | ||
121 | +#include "hw/sysbus.h" | ||
122 | +#include "migration/vmstate.h" | ||
123 | +#include "sysemu/dma.h" | ||
124 | +#include "hw/dma/sifive_pdma.h" | ||
125 | + | ||
126 | +#define DMA_CONTROL 0x000 | ||
127 | +#define CONTROL_CLAIM BIT(0) | ||
128 | +#define CONTROL_RUN BIT(1) | ||
129 | +#define CONTROL_DONE_IE BIT(14) | ||
130 | +#define CONTROL_ERR_IE BIT(15) | ||
131 | +#define CONTROL_DONE BIT(30) | ||
132 | +#define CONTROL_ERR BIT(31) | ||
133 | + | ||
134 | +#define DMA_NEXT_CONFIG 0x004 | ||
135 | +#define CONFIG_REPEAT BIT(2) | ||
136 | +#define CONFIG_ORDER BIT(3) | ||
137 | +#define CONFIG_WRSZ_SHIFT 24 | ||
138 | +#define CONFIG_RDSZ_SHIFT 28 | ||
139 | +#define CONFIG_SZ_MASK 0xf | ||
140 | + | ||
141 | +#define DMA_NEXT_BYTES 0x008 | ||
142 | +#define DMA_NEXT_DST 0x010 | ||
143 | +#define DMA_NEXT_SRC 0x018 | ||
144 | +#define DMA_EXEC_CONFIG 0x104 | ||
145 | +#define DMA_EXEC_BYTES 0x108 | ||
146 | +#define DMA_EXEC_DST 0x110 | ||
147 | +#define DMA_EXEC_SRC 0x118 | ||
148 | + | ||
149 | +enum dma_chan_state { | ||
150 | + DMA_CHAN_STATE_IDLE, | ||
151 | + DMA_CHAN_STATE_STARTED, | ||
152 | + DMA_CHAN_STATE_ERROR, | ||
153 | + DMA_CHAN_STATE_DONE | ||
154 | +}; | ||
155 | + | ||
156 | +static void sifive_pdma_run(SiFivePDMAState *s, int ch) | ||
157 | +{ | 38 | +{ |
158 | + uint64_t bytes = s->chan[ch].next_bytes; | 39 | + /* Svukte extension depends on Sv39. */ |
159 | + uint64_t dst = s->chan[ch].next_dst; | 40 | + if (!(env_archcpu(env)->cfg.ext_svukte || |
160 | + uint64_t src = s->chan[ch].next_src; | 41 | + !first_stage || |
161 | + uint32_t config = s->chan[ch].next_config; | 42 | + VM_1_10_SV39 != get_field(env->satp, SATP64_MODE))) { |
162 | + int wsize, rsize, size; | 43 | + return false; |
163 | + uint8_t buf[64]; | ||
164 | + int n; | ||
165 | + | ||
166 | + /* do nothing if bytes to transfer is zero */ | ||
167 | + if (!bytes) { | ||
168 | + goto error; | ||
169 | + } | 44 | + } |
170 | + | 45 | + |
171 | + /* | 46 | + /* |
172 | + * The manual does not describe how the hardware behaviors when | 47 | + * Check hstatus.HUKTE if the effective mode is switched to VU-mode by |
173 | + * config.wsize and config.rsize are given different values. | 48 | + * executing HLV/HLVX/HSV in U-mode. |
174 | + * A common case is memory to memory DMA, and in this case they | 49 | + * For other cases, check senvcfg.UKTE. |
175 | + * are normally the same. Abort if this expectation fails. | ||
176 | + */ | 50 | + */ |
177 | + wsize = (config >> CONFIG_WRSZ_SHIFT) & CONFIG_SZ_MASK; | 51 | + if (env->priv == PRV_U && !env->virt_enabled && virt) { |
178 | + rsize = (config >> CONFIG_RDSZ_SHIFT) & CONFIG_SZ_MASK; | 52 | + if (!get_field(env->hstatus, HSTATUS_HUKTE)) { |
179 | + if (wsize != rsize) { | 53 | + return false; |
180 | + goto error; | 54 | + } |
55 | + } else if (!get_field(env->senvcfg, SENVCFG_UKTE)) { | ||
56 | + return false; | ||
181 | + } | 57 | + } |
182 | + | 58 | + |
183 | + /* | 59 | + /* |
184 | + * Calculate the transaction size | 60 | + * Svukte extension is qualified only in U or VU-mode. |
185 | + * | 61 | + * |
186 | + * size field is base 2 logarithm of DMA transaction size, | 62 | + * Effective mode can be switched to U or VU-mode by: |
187 | + * but there is an upper limit of 64 bytes per transaction. | 63 | + * - M-mode + mstatus.MPRV=1 + mstatus.MPP=U-mode. |
64 | + * - Execute HLV/HLVX/HSV from HS-mode + hstatus.SPVP=0. | ||
65 | + * - U-mode. | ||
66 | + * - VU-mode. | ||
67 | + * - Execute HLV/HLVX/HSV from U-mode + hstatus.HU=1. | ||
188 | + */ | 68 | + */ |
189 | + size = wsize; | 69 | + if (mode != PRV_U) { |
190 | + if (size > 6) { | 70 | + return false; |
191 | + size = 6; | ||
192 | + } | ||
193 | + size = 1 << size; | ||
194 | + | ||
195 | + /* the bytes to transfer should be multiple of transaction size */ | ||
196 | + if (bytes % size) { | ||
197 | + goto error; | ||
198 | + } | 71 | + } |
199 | + | 72 | + |
200 | + /* indicate a DMA transfer is started */ | 73 | + return true; |
201 | + s->chan[ch].state = DMA_CHAN_STATE_STARTED; | 74 | +} |
202 | + s->chan[ch].control &= ~CONTROL_DONE; | ||
203 | + s->chan[ch].control &= ~CONTROL_ERR; | ||
204 | + | 75 | + |
205 | + /* load the next_ registers into their exec_ counterparts */ | 76 | +static bool check_svukte_addr(CPURISCVState *env, vaddr addr) |
206 | + s->chan[ch].exec_config = config; | 77 | +{ |
207 | + s->chan[ch].exec_bytes = bytes; | 78 | + /* svukte extension excludes RV32 */ |
208 | + s->chan[ch].exec_dst = dst; | 79 | + uint32_t sxlen = 32 * riscv_cpu_sxl(env); |
209 | + s->chan[ch].exec_src = src; | 80 | + uint64_t high_bit = addr & (1UL << (sxlen - 1)); |
81 | + return !high_bit; | ||
82 | +} | ||
210 | + | 83 | + |
211 | + for (n = 0; n < bytes / size; n++) { | 84 | /* |
212 | + cpu_physical_memory_read(s->chan[ch].exec_src, buf, size); | 85 | * get_physical_address - get the physical address for this virtual address |
213 | + cpu_physical_memory_write(s->chan[ch].exec_dst, buf, size); | 86 | * |
214 | + s->chan[ch].exec_src += size; | 87 | @@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, |
215 | + s->chan[ch].exec_dst += size; | 88 | MemTxResult res; |
216 | + s->chan[ch].exec_bytes -= size; | 89 | MemTxAttrs attrs = MEMTXATTRS_UNSPECIFIED; |
90 | int mode = mmuidx_priv(mmu_idx); | ||
91 | + bool virt = mmuidx_2stage(mmu_idx); | ||
92 | bool use_background = false; | ||
93 | hwaddr ppn; | ||
94 | int napot_bits = 0; | ||
95 | @@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, | ||
96 | bool is_sstack_idx = ((mmu_idx & MMU_IDX_SS_WRITE) == MMU_IDX_SS_WRITE); | ||
97 | bool sstack_page = false; | ||
98 | |||
99 | + if (do_svukte_check(env, first_stage, mode, virt) && | ||
100 | + !check_svukte_addr(env, addr)) { | ||
101 | + return TRANSLATE_FAIL; | ||
217 | + } | 102 | + } |
218 | + | 103 | + |
219 | + /* indicate a DMA transfer is done */ | 104 | /* |
220 | + s->chan[ch].state = DMA_CHAN_STATE_DONE; | 105 | * Check if we should use the background registers for the two |
221 | + s->chan[ch].control &= ~CONTROL_RUN; | 106 | * stage translation. We don't need to check if we actually need |
222 | + s->chan[ch].control |= CONTROL_DONE; | ||
223 | + | ||
224 | + /* reload exec_ registers if repeat is required */ | ||
225 | + if (s->chan[ch].next_config & CONFIG_REPEAT) { | ||
226 | + s->chan[ch].exec_bytes = bytes; | ||
227 | + s->chan[ch].exec_dst = dst; | ||
228 | + s->chan[ch].exec_src = src; | ||
229 | + } | ||
230 | + | ||
231 | + return; | ||
232 | + | ||
233 | +error: | ||
234 | + s->chan[ch].state = DMA_CHAN_STATE_ERROR; | ||
235 | + s->chan[ch].control |= CONTROL_ERR; | ||
236 | + return; | ||
237 | +} | ||
238 | + | ||
239 | +static inline void sifive_pdma_update_irq(SiFivePDMAState *s, int ch) | ||
240 | +{ | ||
241 | + bool done_ie, err_ie; | ||
242 | + | ||
243 | + done_ie = !!(s->chan[ch].control & CONTROL_DONE_IE); | ||
244 | + err_ie = !!(s->chan[ch].control & CONTROL_ERR_IE); | ||
245 | + | ||
246 | + if (done_ie && (s->chan[ch].control & CONTROL_DONE)) { | ||
247 | + qemu_irq_raise(s->irq[ch * 2]); | ||
248 | + } else { | ||
249 | + qemu_irq_lower(s->irq[ch * 2]); | ||
250 | + } | ||
251 | + | ||
252 | + if (err_ie && (s->chan[ch].control & CONTROL_ERR)) { | ||
253 | + qemu_irq_raise(s->irq[ch * 2 + 1]); | ||
254 | + } else { | ||
255 | + qemu_irq_lower(s->irq[ch * 2 + 1]); | ||
256 | + } | ||
257 | + | ||
258 | + s->chan[ch].state = DMA_CHAN_STATE_IDLE; | ||
259 | +} | ||
260 | + | ||
261 | +static uint64_t sifive_pdma_read(void *opaque, hwaddr offset, unsigned size) | ||
262 | +{ | ||
263 | + SiFivePDMAState *s = opaque; | ||
264 | + int ch = SIFIVE_PDMA_CHAN_NO(offset); | ||
265 | + uint64_t val = 0; | ||
266 | + | ||
267 | + if (ch >= SIFIVE_PDMA_CHANS) { | ||
268 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Invalid channel no %d\n", | ||
269 | + __func__, ch); | ||
270 | + return 0; | ||
271 | + } | ||
272 | + | ||
273 | + offset &= 0xfff; | ||
274 | + switch (offset) { | ||
275 | + case DMA_CONTROL: | ||
276 | + val = s->chan[ch].control; | ||
277 | + break; | ||
278 | + case DMA_NEXT_CONFIG: | ||
279 | + val = s->chan[ch].next_config; | ||
280 | + break; | ||
281 | + case DMA_NEXT_BYTES: | ||
282 | + val = s->chan[ch].next_bytes; | ||
283 | + break; | ||
284 | + case DMA_NEXT_DST: | ||
285 | + val = s->chan[ch].next_dst; | ||
286 | + break; | ||
287 | + case DMA_NEXT_SRC: | ||
288 | + val = s->chan[ch].next_src; | ||
289 | + break; | ||
290 | + case DMA_EXEC_CONFIG: | ||
291 | + val = s->chan[ch].exec_config; | ||
292 | + break; | ||
293 | + case DMA_EXEC_BYTES: | ||
294 | + val = s->chan[ch].exec_bytes; | ||
295 | + break; | ||
296 | + case DMA_EXEC_DST: | ||
297 | + val = s->chan[ch].exec_dst; | ||
298 | + break; | ||
299 | + case DMA_EXEC_SRC: | ||
300 | + val = s->chan[ch].exec_src; | ||
301 | + break; | ||
302 | + default: | ||
303 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIX "\n", | ||
304 | + __func__, offset); | ||
305 | + break; | ||
306 | + } | ||
307 | + | ||
308 | + return val; | ||
309 | +} | ||
310 | + | ||
311 | +static void sifive_pdma_write(void *opaque, hwaddr offset, | ||
312 | + uint64_t value, unsigned size) | ||
313 | +{ | ||
314 | + SiFivePDMAState *s = opaque; | ||
315 | + int ch = SIFIVE_PDMA_CHAN_NO(offset); | ||
316 | + | ||
317 | + if (ch >= SIFIVE_PDMA_CHANS) { | ||
318 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Invalid channel no %d\n", | ||
319 | + __func__, ch); | ||
320 | + return; | ||
321 | + } | ||
322 | + | ||
323 | + offset &= 0xfff; | ||
324 | + switch (offset) { | ||
325 | + case DMA_CONTROL: | ||
326 | + s->chan[ch].control = value; | ||
327 | + | ||
328 | + if (value & CONTROL_RUN) { | ||
329 | + sifive_pdma_run(s, ch); | ||
330 | + } | ||
331 | + | ||
332 | + sifive_pdma_update_irq(s, ch); | ||
333 | + break; | ||
334 | + case DMA_NEXT_CONFIG: | ||
335 | + s->chan[ch].next_config = value; | ||
336 | + break; | ||
337 | + case DMA_NEXT_BYTES: | ||
338 | + s->chan[ch].next_bytes = value; | ||
339 | + break; | ||
340 | + case DMA_NEXT_DST: | ||
341 | + s->chan[ch].next_dst = value; | ||
342 | + break; | ||
343 | + case DMA_NEXT_SRC: | ||
344 | + s->chan[ch].next_src = value; | ||
345 | + break; | ||
346 | + case DMA_EXEC_CONFIG: | ||
347 | + case DMA_EXEC_BYTES: | ||
348 | + case DMA_EXEC_DST: | ||
349 | + case DMA_EXEC_SRC: | ||
350 | + /* these are read-only registers */ | ||
351 | + break; | ||
352 | + default: | ||
353 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIX "\n", | ||
354 | + __func__, offset); | ||
355 | + break; | ||
356 | + } | ||
357 | +} | ||
358 | + | ||
359 | +static const MemoryRegionOps sifive_pdma_ops = { | ||
360 | + .read = sifive_pdma_read, | ||
361 | + .write = sifive_pdma_write, | ||
362 | + .endianness = DEVICE_LITTLE_ENDIAN, | ||
363 | + /* there are 32-bit and 64-bit wide registers */ | ||
364 | + .impl = { | ||
365 | + .min_access_size = 4, | ||
366 | + .max_access_size = 8, | ||
367 | + } | ||
368 | +}; | ||
369 | + | ||
370 | +static void sifive_pdma_realize(DeviceState *dev, Error **errp) | ||
371 | +{ | ||
372 | + SiFivePDMAState *s = SIFIVE_PDMA(dev); | ||
373 | + int i; | ||
374 | + | ||
375 | + memory_region_init_io(&s->iomem, OBJECT(dev), &sifive_pdma_ops, s, | ||
376 | + TYPE_SIFIVE_PDMA, SIFIVE_PDMA_REG_SIZE); | ||
377 | + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem); | ||
378 | + | ||
379 | + for (i = 0; i < SIFIVE_PDMA_IRQS; i++) { | ||
380 | + sysbus_init_irq(SYS_BUS_DEVICE(dev), &s->irq[i]); | ||
381 | + } | ||
382 | +} | ||
383 | + | ||
384 | +static void sifive_pdma_class_init(ObjectClass *klass, void *data) | ||
385 | +{ | ||
386 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
387 | + | ||
388 | + dc->desc = "SiFive Platform DMA controller"; | ||
389 | + dc->realize = sifive_pdma_realize; | ||
390 | +} | ||
391 | + | ||
392 | +static const TypeInfo sifive_pdma_info = { | ||
393 | + .name = TYPE_SIFIVE_PDMA, | ||
394 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
395 | + .instance_size = sizeof(SiFivePDMAState), | ||
396 | + .class_init = sifive_pdma_class_init, | ||
397 | +}; | ||
398 | + | ||
399 | +static void sifive_pdma_register_types(void) | ||
400 | +{ | ||
401 | + type_register_static(&sifive_pdma_info); | ||
402 | +} | ||
403 | + | ||
404 | +type_init(sifive_pdma_register_types) | ||
405 | diff --git a/hw/dma/Kconfig b/hw/dma/Kconfig | ||
406 | index XXXXXXX..XXXXXXX 100644 | ||
407 | --- a/hw/dma/Kconfig | ||
408 | +++ b/hw/dma/Kconfig | ||
409 | @@ -XXX,XX +XXX,XX @@ config ZYNQ_DEVCFG | ||
410 | |||
411 | config STP2000 | ||
412 | bool | ||
413 | + | ||
414 | +config SIFIVE_PDMA | ||
415 | + bool | ||
416 | diff --git a/hw/dma/meson.build b/hw/dma/meson.build | ||
417 | index XXXXXXX..XXXXXXX 100644 | ||
418 | --- a/hw/dma/meson.build | ||
419 | +++ b/hw/dma/meson.build | ||
420 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_XLNX_ZYNQMP_ARM', if_true: files('xlnx-zdma.c')) | ||
421 | softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_dma.c', 'soc_dma.c')) | ||
422 | softmmu_ss.add(when: 'CONFIG_PXA2XX', if_true: files('pxa2xx_dma.c')) | ||
423 | softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_dma.c')) | ||
424 | +softmmu_ss.add(when: 'CONFIG_SIFIVE_PDMA', if_true: files('sifive_pdma.c')) | ||
425 | -- | 107 | -- |
426 | 2.28.0 | 108 | 2.47.1 |
427 | |||
428 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: "Fea.Wang" <fea.wang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Currently the reset vector address is hard-coded in a RISC-V CPU's | 3 | Add "svukte" in the ISA string when svukte extension is enabled. |
4 | instance_init() routine. In a real world we can have 2 exact same | ||
5 | CPUs except for the reset vector address, which is pretty common in | ||
6 | the RISC-V core IP licensing business. | ||
7 | 4 | ||
8 | Normally reset vector address is a configurable parameter. Let's | 5 | Signed-off-by: Fea.Wang <fea.wang@sifive.com> |
9 | create a 64-bit property to store the reset vector address which | 6 | Reviewed-by: Frank Chang <frank.chang@sifive.com> |
10 | covers both 32-bit and 64-bit CPUs. | 7 | Reviewed-by: Jim Shu <jim.shu@sifive.com> |
11 | |||
12 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | ||
13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
14 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 9 | Message-ID: <20241203034932.25185-6-fea.wang@sifive.com> |
15 | Message-Id: <1598924352-89526-2-git-send-email-bmeng.cn@gmail.com> | ||
16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
17 | --- | 11 | --- |
18 | target/riscv/cpu.h | 1 + | 12 | target/riscv/cpu.c | 2 ++ |
19 | target/riscv/cpu.c | 1 + | 13 | 1 file changed, 2 insertions(+) |
20 | 2 files changed, 2 insertions(+) | ||
21 | 14 | ||
22 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
23 | index XXXXXXX..XXXXXXX 100644 | ||
24 | --- a/target/riscv/cpu.h | ||
25 | +++ b/target/riscv/cpu.h | ||
26 | @@ -XXX,XX +XXX,XX @@ typedef struct RISCVCPU { | ||
27 | uint16_t elen; | ||
28 | bool mmu; | ||
29 | bool pmp; | ||
30 | + uint64_t resetvec; | ||
31 | } cfg; | ||
32 | } RISCVCPU; | ||
33 | |||
34 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 15 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
35 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
36 | --- a/target/riscv/cpu.c | 17 | --- a/target/riscv/cpu.c |
37 | +++ b/target/riscv/cpu.c | 18 | +++ b/target/riscv/cpu.c |
38 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_properties[] = { | 19 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { |
39 | DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64), | 20 | ISA_EXT_DATA_ENTRY(svinval, PRIV_VERSION_1_12_0, ext_svinval), |
40 | DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true), | 21 | ISA_EXT_DATA_ENTRY(svnapot, PRIV_VERSION_1_12_0, ext_svnapot), |
41 | DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true), | 22 | ISA_EXT_DATA_ENTRY(svpbmt, PRIV_VERSION_1_12_0, ext_svpbmt), |
42 | + DEFINE_PROP_UINT64("resetvec", RISCVCPU, cfg.resetvec, DEFAULT_RSTVEC), | 23 | + ISA_EXT_DATA_ENTRY(svukte, PRIV_VERSION_1_13_0, ext_svukte), |
24 | ISA_EXT_DATA_ENTRY(svvptc, PRIV_VERSION_1_13_0, ext_svvptc), | ||
25 | ISA_EXT_DATA_ENTRY(xtheadba, PRIV_VERSION_1_11_0, ext_xtheadba), | ||
26 | ISA_EXT_DATA_ENTRY(xtheadbb, PRIV_VERSION_1_11_0, ext_xtheadbb), | ||
27 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[] = { | ||
28 | |||
29 | /* These are experimental so mark with 'x-' */ | ||
30 | const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = { | ||
31 | + MULTI_EXT_CFG_BOOL("x-svukte", ext_svukte, false), | ||
43 | DEFINE_PROP_END_OF_LIST(), | 32 | DEFINE_PROP_END_OF_LIST(), |
44 | }; | 33 | }; |
45 | 34 | ||
46 | -- | 35 | -- |
47 | 2.28.0 | 36 | 2.47.1 |
48 | |||
49 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: "Fea.Wang" <fea.wang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | When cadence_gem model was created for Xilinx boards, the PHY address | 3 | The spec explicitly says svukte doesn't support RV32. So check that it |
4 | was hard-coded to 23 in the GEM model. Now that we have introduced a | 4 | is not enabled in RV32. |
5 | property we can use that to tell GEM model what our PHY address is. | ||
6 | Change all boards' GEM 'phy-addr' property value to 23, and set the | ||
7 | PHY address default value to 0 in the GEM model. | ||
8 | 5 | ||
9 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 6 | Signed-off-by: Fea.Wang <fea.wang@sifive.com> |
10 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
11 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
12 | Message-Id: <1598924352-89526-13-git-send-email-bmeng.cn@gmail.com> | 8 | Message-ID: <20241203034932.25185-7-fea.wang@sifive.com> |
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
14 | --- | 10 | --- |
15 | hw/arm/xilinx_zynq.c | 1 + | 11 | target/riscv/tcg/tcg-cpu.c | 5 +++++ |
16 | hw/arm/xlnx-versal.c | 1 + | 12 | 1 file changed, 5 insertions(+) |
17 | hw/arm/xlnx-zynqmp.c | 2 ++ | ||
18 | hw/net/cadence_gem.c | 6 +++--- | ||
19 | 4 files changed, 7 insertions(+), 3 deletions(-) | ||
20 | 13 | ||
21 | diff --git a/hw/arm/xilinx_zynq.c b/hw/arm/xilinx_zynq.c | 14 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c |
22 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/hw/arm/xilinx_zynq.c | 16 | --- a/target/riscv/tcg/tcg-cpu.c |
24 | +++ b/hw/arm/xilinx_zynq.c | 17 | +++ b/target/riscv/tcg/tcg-cpu.c |
25 | @@ -XXX,XX +XXX,XX @@ static void gem_init(NICInfo *nd, uint32_t base, qemu_irq irq) | 18 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) |
26 | qemu_check_nic_model(nd, TYPE_CADENCE_GEM); | 19 | return; |
27 | qdev_set_nic_properties(dev, nd); | ||
28 | } | 20 | } |
29 | + object_property_set_int(OBJECT(dev), "phy-addr", 23, &error_abort); | 21 | |
30 | s = SYS_BUS_DEVICE(dev); | 22 | + if (mcc->misa_mxl_max == MXL_RV32 && cpu->cfg.ext_svukte) { |
31 | sysbus_realize_and_unref(s, &error_fatal); | 23 | + error_setg(errp, "svukte is not supported for RV32"); |
32 | sysbus_mmio_map(s, 0, base); | 24 | + return; |
33 | diff --git a/hw/arm/xlnx-versal.c b/hw/arm/xlnx-versal.c | 25 | + } |
34 | index XXXXXXX..XXXXXXX 100644 | 26 | + |
35 | --- a/hw/arm/xlnx-versal.c | 27 | /* |
36 | +++ b/hw/arm/xlnx-versal.c | 28 | * Disable isa extensions based on priv spec after we |
37 | @@ -XXX,XX +XXX,XX @@ static void versal_create_gems(Versal *s, qemu_irq *pic) | 29 | * validated and set everything we need. |
38 | qemu_check_nic_model(nd, "cadence_gem"); | ||
39 | qdev_set_nic_properties(dev, nd); | ||
40 | } | ||
41 | + object_property_set_int(OBJECT(dev), "phy-addr", 23, &error_abort); | ||
42 | object_property_set_int(OBJECT(dev), "num-priority-queues", 2, | ||
43 | &error_abort); | ||
44 | object_property_set_link(OBJECT(dev), "dma", OBJECT(&s->mr_ps), | ||
45 | diff --git a/hw/arm/xlnx-zynqmp.c b/hw/arm/xlnx-zynqmp.c | ||
46 | index XXXXXXX..XXXXXXX 100644 | ||
47 | --- a/hw/arm/xlnx-zynqmp.c | ||
48 | +++ b/hw/arm/xlnx-zynqmp.c | ||
49 | @@ -XXX,XX +XXX,XX @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp) | ||
50 | } | ||
51 | object_property_set_int(OBJECT(&s->gem[i]), "revision", GEM_REVISION, | ||
52 | &error_abort); | ||
53 | + object_property_set_int(OBJECT(&s->gem[i]), "phy-addr", 23, | ||
54 | + &error_abort); | ||
55 | object_property_set_int(OBJECT(&s->gem[i]), "num-priority-queues", 2, | ||
56 | &error_abort); | ||
57 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->gem[i]), errp)) { | ||
58 | diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c | ||
59 | index XXXXXXX..XXXXXXX 100644 | ||
60 | --- a/hw/net/cadence_gem.c | ||
61 | +++ b/hw/net/cadence_gem.c | ||
62 | @@ -XXX,XX +XXX,XX @@ | ||
63 | #define GEM_PHYMNTNC_REG_SHIFT 18 | ||
64 | |||
65 | /* Marvell PHY definitions */ | ||
66 | -#define BOARD_PHY_ADDRESS 23 /* PHY address we will emulate a device at */ | ||
67 | +#define BOARD_PHY_ADDRESS 0 /* PHY address we will emulate a device at */ | ||
68 | |||
69 | #define PHY_REG_CONTROL 0 | ||
70 | #define PHY_REG_STATUS 1 | ||
71 | @@ -XXX,XX +XXX,XX @@ static uint64_t gem_read(void *opaque, hwaddr offset, unsigned size) | ||
72 | uint32_t phy_addr, reg_num; | ||
73 | |||
74 | phy_addr = (retval & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT; | ||
75 | - if (phy_addr == s->phy_addr || phy_addr == 0) { | ||
76 | + if (phy_addr == s->phy_addr) { | ||
77 | reg_num = (retval & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT; | ||
78 | retval &= 0xFFFF0000; | ||
79 | retval |= gem_phy_read(s, reg_num); | ||
80 | @@ -XXX,XX +XXX,XX @@ static void gem_write(void *opaque, hwaddr offset, uint64_t val, | ||
81 | uint32_t phy_addr, reg_num; | ||
82 | |||
83 | phy_addr = (val & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT; | ||
84 | - if (phy_addr == s->phy_addr || phy_addr == 0) { | ||
85 | + if (phy_addr == s->phy_addr) { | ||
86 | reg_num = (val & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT; | ||
87 | gem_phy_write(s, reg_num, val); | ||
88 | } | ||
89 | -- | 30 | -- |
90 | 2.28.0 | 31 | 2.47.1 |
91 | |||
92 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Philippe Mathieu-Daudé <philmd@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | At present the PHY address of the PHY connected to GEM is hard-coded | 3 | Rather than relying on implicit includes, explicit them, |
4 | to either 23 (BOARD_PHY_ADDRESS) or 0. This might not be the case for | 4 | in order to avoid when refactoring unrelated headers: |
5 | all boards. Add a new 'phy-addr' property so that board can specify | ||
6 | the PHY address for each GEM instance. | ||
7 | 5 | ||
8 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 6 | target/riscv/vector_internals.h:36:12: error: call to undeclared function 'FIELD_EX32'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] |
9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 7 | 36 | return FIELD_EX32(simd_data(desc), VDATA, NF); |
10 | Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> | 8 | | ^ |
9 | |||
10 | Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
11 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
12 | Message-Id: <1598924352-89526-12-git-send-email-bmeng.cn@gmail.com> | 12 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
13 | Message-ID: <20241203200828.47311-2-philmd@linaro.org> | ||
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
14 | --- | 15 | --- |
15 | include/hw/net/cadence_gem.h | 2 ++ | 16 | target/riscv/vector_internals.h | 1 + |
16 | hw/net/cadence_gem.c | 5 +++-- | 17 | 1 file changed, 1 insertion(+) |
17 | 2 files changed, 5 insertions(+), 2 deletions(-) | ||
18 | 18 | ||
19 | diff --git a/include/hw/net/cadence_gem.h b/include/hw/net/cadence_gem.h | 19 | diff --git a/target/riscv/vector_internals.h b/target/riscv/vector_internals.h |
20 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/include/hw/net/cadence_gem.h | 21 | --- a/target/riscv/vector_internals.h |
22 | +++ b/include/hw/net/cadence_gem.h | 22 | +++ b/target/riscv/vector_internals.h |
23 | @@ -XXX,XX +XXX,XX @@ typedef struct CadenceGEMState { | 23 | @@ -XXX,XX +XXX,XX @@ |
24 | /* Mask of register bits which are write 1 to clear */ | 24 | #define TARGET_RISCV_VECTOR_INTERNALS_H |
25 | uint32_t regs_w1c[CADENCE_GEM_MAXREG]; | 25 | |
26 | 26 | #include "qemu/bitops.h" | |
27 | + /* PHY address */ | 27 | +#include "hw/registerfields.h" |
28 | + uint8_t phy_addr; | 28 | #include "cpu.h" |
29 | /* PHY registers backing store */ | 29 | #include "tcg/tcg-gvec-desc.h" |
30 | uint16_t phy_regs[32]; | 30 | #include "internals.h" |
31 | |||
32 | diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/hw/net/cadence_gem.c | ||
35 | +++ b/hw/net/cadence_gem.c | ||
36 | @@ -XXX,XX +XXX,XX @@ static uint64_t gem_read(void *opaque, hwaddr offset, unsigned size) | ||
37 | uint32_t phy_addr, reg_num; | ||
38 | |||
39 | phy_addr = (retval & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT; | ||
40 | - if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0) { | ||
41 | + if (phy_addr == s->phy_addr || phy_addr == 0) { | ||
42 | reg_num = (retval & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT; | ||
43 | retval &= 0xFFFF0000; | ||
44 | retval |= gem_phy_read(s, reg_num); | ||
45 | @@ -XXX,XX +XXX,XX @@ static void gem_write(void *opaque, hwaddr offset, uint64_t val, | ||
46 | uint32_t phy_addr, reg_num; | ||
47 | |||
48 | phy_addr = (val & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT; | ||
49 | - if (phy_addr == BOARD_PHY_ADDRESS || phy_addr == 0) { | ||
50 | + if (phy_addr == s->phy_addr || phy_addr == 0) { | ||
51 | reg_num = (val & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT; | ||
52 | gem_phy_write(s, reg_num, val); | ||
53 | } | ||
54 | @@ -XXX,XX +XXX,XX @@ static Property gem_properties[] = { | ||
55 | DEFINE_NIC_PROPERTIES(CadenceGEMState, conf), | ||
56 | DEFINE_PROP_UINT32("revision", CadenceGEMState, revision, | ||
57 | GEM_MODID_VALUE), | ||
58 | + DEFINE_PROP_UINT8("phy-addr", CadenceGEMState, phy_addr, BOARD_PHY_ADDRESS), | ||
59 | DEFINE_PROP_UINT8("num-priority-queues", CadenceGEMState, | ||
60 | num_priority_queues, 1), | ||
61 | DEFINE_PROP_UINT8("num-type1-screeners", CadenceGEMState, | ||
62 | -- | 31 | -- |
63 | 2.28.0 | 32 | 2.47.1 |
64 | 33 | ||
65 | 34 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Philippe Mathieu-Daudé <philmd@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | This is an effort to clean up the hw/riscv directory. Ideally it | 3 | Rather than relying on implicit includes, explicit them, |
4 | should only contain the RISC-V SoC / machine codes plus generic | 4 | in order to avoid when refactoring unrelated headers: |
5 | codes. Let's move sifive_uart model to hw/char directory. | ||
6 | 5 | ||
7 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 6 | target/riscv/internals.h:49:15: error: use of undeclared identifier 'PRV_S' |
7 | 49 | ret = PRV_S; | ||
8 | | ^ | ||
9 | target/riscv/internals.h:93:9: error: call to undeclared function 'env_archcpu'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] | ||
10 | 93 | if (env_archcpu(env)->cfg.ext_zfinx) { | ||
11 | | ^ | ||
12 | target/riscv/internals.h:101:15: error: unknown type name 'float32'; did you mean 'float'? | ||
13 | 101 | static inline float32 check_nanbox_s(CPURISCVState *env, uint64_t f) | ||
14 | | ^~~~~~~ | ||
15 | | float | ||
16 | |||
17 | Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 18 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Message-Id: <1599129623-68957-9-git-send-email-bmeng.cn@gmail.com> | 19 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
20 | Message-ID: <20241203200828.47311-3-philmd@linaro.org> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 21 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 22 | --- |
12 | include/hw/{riscv => char}/sifive_uart.h | 0 | 23 | target/riscv/internals.h | 3 +++ |
13 | hw/{riscv => char}/sifive_uart.c | 2 +- | 24 | 1 file changed, 3 insertions(+) |
14 | hw/riscv/sifive_e.c | 2 +- | ||
15 | hw/riscv/sifive_u.c | 2 +- | ||
16 | hw/char/Kconfig | 3 +++ | ||
17 | hw/char/meson.build | 1 + | ||
18 | hw/riscv/Kconfig | 2 ++ | ||
19 | hw/riscv/meson.build | 1 - | ||
20 | 8 files changed, 9 insertions(+), 4 deletions(-) | ||
21 | rename include/hw/{riscv => char}/sifive_uart.h (100%) | ||
22 | rename hw/{riscv => char}/sifive_uart.c (99%) | ||
23 | 25 | ||
24 | diff --git a/include/hw/riscv/sifive_uart.h b/include/hw/char/sifive_uart.h | 26 | diff --git a/target/riscv/internals.h b/target/riscv/internals.h |
25 | similarity index 100% | ||
26 | rename from include/hw/riscv/sifive_uart.h | ||
27 | rename to include/hw/char/sifive_uart.h | ||
28 | diff --git a/hw/riscv/sifive_uart.c b/hw/char/sifive_uart.c | ||
29 | similarity index 99% | ||
30 | rename from hw/riscv/sifive_uart.c | ||
31 | rename to hw/char/sifive_uart.c | ||
32 | index XXXXXXX..XXXXXXX 100644 | 27 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/hw/riscv/sifive_uart.c | 28 | --- a/target/riscv/internals.h |
34 | +++ b/hw/char/sifive_uart.c | 29 | +++ b/target/riscv/internals.h |
35 | @@ -XXX,XX +XXX,XX @@ | 30 | @@ -XXX,XX +XXX,XX @@ |
36 | #include "chardev/char-fe.h" | 31 | #ifndef RISCV_CPU_INTERNALS_H |
37 | #include "hw/hw.h" | 32 | #define RISCV_CPU_INTERNALS_H |
38 | #include "hw/irq.h" | 33 | |
39 | -#include "hw/riscv/sifive_uart.h" | 34 | +#include "exec/cpu-common.h" |
40 | +#include "hw/char/sifive_uart.h" | 35 | #include "hw/registerfields.h" |
36 | +#include "fpu/softfloat-types.h" | ||
37 | +#include "target/riscv/cpu_bits.h" | ||
41 | 38 | ||
42 | /* | 39 | /* |
43 | * Not yet implemented: | 40 | * The current MMU Modes are: |
44 | diff --git a/hw/riscv/sifive_e.c b/hw/riscv/sifive_e.c | ||
45 | index XXXXXXX..XXXXXXX 100644 | ||
46 | --- a/hw/riscv/sifive_e.c | ||
47 | +++ b/hw/riscv/sifive_e.c | ||
48 | @@ -XXX,XX +XXX,XX @@ | ||
49 | #include "hw/misc/unimp.h" | ||
50 | #include "target/riscv/cpu.h" | ||
51 | #include "hw/riscv/riscv_hart.h" | ||
52 | -#include "hw/riscv/sifive_uart.h" | ||
53 | #include "hw/riscv/sifive_e.h" | ||
54 | #include "hw/riscv/boot.h" | ||
55 | +#include "hw/char/sifive_uart.h" | ||
56 | #include "hw/intc/sifive_clint.h" | ||
57 | #include "hw/intc/sifive_plic.h" | ||
58 | #include "hw/misc/sifive_e_prci.h" | ||
59 | diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c | ||
60 | index XXXXXXX..XXXXXXX 100644 | ||
61 | --- a/hw/riscv/sifive_u.c | ||
62 | +++ b/hw/riscv/sifive_u.c | ||
63 | @@ -XXX,XX +XXX,XX @@ | ||
64 | #include "hw/misc/unimp.h" | ||
65 | #include "target/riscv/cpu.h" | ||
66 | #include "hw/riscv/riscv_hart.h" | ||
67 | -#include "hw/riscv/sifive_uart.h" | ||
68 | #include "hw/riscv/sifive_u.h" | ||
69 | #include "hw/riscv/boot.h" | ||
70 | +#include "hw/char/sifive_uart.h" | ||
71 | #include "hw/intc/sifive_clint.h" | ||
72 | #include "hw/intc/sifive_plic.h" | ||
73 | #include "chardev/char.h" | ||
74 | diff --git a/hw/char/Kconfig b/hw/char/Kconfig | ||
75 | index XXXXXXX..XXXXXXX 100644 | ||
76 | --- a/hw/char/Kconfig | ||
77 | +++ b/hw/char/Kconfig | ||
78 | @@ -XXX,XX +XXX,XX @@ config AVR_USART | ||
79 | |||
80 | config MCHP_PFSOC_MMUART | ||
81 | bool | ||
82 | + | ||
83 | +config SIFIVE_UART | ||
84 | + bool | ||
85 | diff --git a/hw/char/meson.build b/hw/char/meson.build | ||
86 | index XXXXXXX..XXXXXXX 100644 | ||
87 | --- a/hw/char/meson.build | ||
88 | +++ b/hw/char/meson.build | ||
89 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_EXYNOS4', if_true: files('exynos4210_uart.c')) | ||
90 | softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_uart.c')) | ||
91 | softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_aux.c')) | ||
92 | softmmu_ss.add(when: 'CONFIG_RENESAS_SCI', if_true: files('renesas_sci.c')) | ||
93 | +softmmu_ss.add(when: 'CONFIG_SIFIVE_UART', if_true: files('sifive_uart.c')) | ||
94 | softmmu_ss.add(when: 'CONFIG_SH4', if_true: files('sh_serial.c')) | ||
95 | softmmu_ss.add(when: 'CONFIG_STM32F2XX_USART', if_true: files('stm32f2xx_usart.c')) | ||
96 | softmmu_ss.add(when: 'CONFIG_MCHP_PFSOC_MMUART', if_true: files('mchp_pfsoc_mmuart.c')) | ||
97 | diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig | ||
98 | index XXXXXXX..XXXXXXX 100644 | ||
99 | --- a/hw/riscv/Kconfig | ||
100 | +++ b/hw/riscv/Kconfig | ||
101 | @@ -XXX,XX +XXX,XX @@ config SIFIVE_E | ||
102 | select SIFIVE_CLINT | ||
103 | select SIFIVE_GPIO | ||
104 | select SIFIVE_PLIC | ||
105 | + select SIFIVE_UART | ||
106 | select SIFIVE_E_PRCI | ||
107 | select UNIMP | ||
108 | |||
109 | @@ -XXX,XX +XXX,XX @@ config SIFIVE_U | ||
110 | select SIFIVE_GPIO | ||
111 | select SIFIVE_PDMA | ||
112 | select SIFIVE_PLIC | ||
113 | + select SIFIVE_UART | ||
114 | select SIFIVE_U_OTP | ||
115 | select SIFIVE_U_PRCI | ||
116 | select UNIMP | ||
117 | diff --git a/hw/riscv/meson.build b/hw/riscv/meson.build | ||
118 | index XXXXXXX..XXXXXXX 100644 | ||
119 | --- a/hw/riscv/meson.build | ||
120 | +++ b/hw/riscv/meson.build | ||
121 | @@ -XXX,XX +XXX,XX @@ riscv_ss.add(when: 'CONFIG_HART', if_true: files('riscv_hart.c')) | ||
122 | riscv_ss.add(when: 'CONFIG_OPENTITAN', if_true: files('opentitan.c')) | ||
123 | riscv_ss.add(when: 'CONFIG_RISCV_VIRT', if_true: files('virt.c')) | ||
124 | riscv_ss.add(when: 'CONFIG_SIFIVE', if_true: files('sifive_test.c')) | ||
125 | -riscv_ss.add(when: 'CONFIG_SIFIVE', if_true: files('sifive_uart.c')) | ||
126 | riscv_ss.add(when: 'CONFIG_SIFIVE_E', if_true: files('sifive_e.c')) | ||
127 | riscv_ss.add(when: 'CONFIG_SIFIVE_U', if_true: files('sifive_u.c')) | ||
128 | riscv_ss.add(when: 'CONFIG_SPIKE', if_true: files('spike.c')) | ||
129 | -- | 41 | -- |
130 | 2.28.0 | 42 | 2.47.1 |
131 | 43 | ||
132 | 44 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | Microchip PolarFire SoC integrates one Cadence SDHCI controller. | 3 | Commit 68c9e54bea handled a situation where a warning was being shown |
4 | On the Icicle Kit board, one eMMC chip and an external SD card | 4 | when using the 'sifive_e' cpu when disabling the named extension zic64b. |
5 | connect to this controller depending on different configuration. | 5 | It makes little sense to show user warnings for named extensions that |
6 | users can't control, and the solution taken was to disable zic64b | ||
7 | manually in riscv_cpu_update_named_features(). | ||
6 | 8 | ||
7 | As QEMU does not support eMMC yet, we just emulate the SD card | 9 | This solution won't scale well when adding more named features, and can |
8 | configuration. To test this, the Hart Software Services (HSS) | 10 | eventually end up repeating riscv_cpu_disable_priv_spec_isa_exts(). |
9 | should choose the SD card configuration: | ||
10 | 11 | ||
11 | $ cp boards/icicle-kit-es/def_config.sdcard .config | 12 | Change riscv_cpu_disable_priv_spec_isa_exts() to not show warnings when |
12 | $ make BOARD=icicle-kit-es | 13 | disabling a named feature. This will accomplish the same thing we're |
14 | doing today while avoiding having two points where we're disabling | ||
15 | exts via priv_ver mismatch. | ||
13 | 16 | ||
14 | The SD card image can be built from the Yocto BSP at: | 17 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
15 | https://github.com/polarfire-soc/meta-polarfire-soc-yocto-bsp | ||
16 | |||
17 | Note the generated SD card image should be resized before use: | ||
18 | $ qemu-img resize /path/to/sdcard.img 4G | ||
19 | |||
20 | Launch QEMU with the following command: | ||
21 | $ qemu-system-riscv64 -nographic -M microchip-icicle-kit -sd sdcard.img | ||
22 | |||
23 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | ||
24 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
25 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 18 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
26 | Message-Id: <1598924352-89526-9-git-send-email-bmeng.cn@gmail.com> | 19 | Message-ID: <20241113171755.978109-2-dbarboza@ventanamicro.com> |
27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 20 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
28 | --- | 21 | --- |
29 | include/hw/riscv/microchip_pfsoc.h | 4 ++++ | 22 | target/riscv/tcg/tcg-cpu.c | 13 ++++++++++--- |
30 | hw/riscv/microchip_pfsoc.c | 23 +++++++++++++++++++++++ | 23 | 1 file changed, 10 insertions(+), 3 deletions(-) |
31 | hw/riscv/Kconfig | 1 + | ||
32 | 3 files changed, 28 insertions(+) | ||
33 | 24 | ||
34 | diff --git a/include/hw/riscv/microchip_pfsoc.h b/include/hw/riscv/microchip_pfsoc.h | 25 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c |
35 | index XXXXXXX..XXXXXXX 100644 | 26 | index XXXXXXX..XXXXXXX 100644 |
36 | --- a/include/hw/riscv/microchip_pfsoc.h | 27 | --- a/target/riscv/tcg/tcg-cpu.c |
37 | +++ b/include/hw/riscv/microchip_pfsoc.h | 28 | +++ b/target/riscv/tcg/tcg-cpu.c |
38 | @@ -XXX,XX +XXX,XX @@ | 29 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu) |
39 | #define HW_MICROCHIP_PFSOC_H | 30 | } |
40 | 31 | ||
41 | #include "hw/char/mchp_pfsoc_mmuart.h" | 32 | isa_ext_update_enabled(cpu, edata->ext_enable_offset, false); |
42 | +#include "hw/sd/cadence_sdhci.h" | ||
43 | |||
44 | typedef struct MicrochipPFSoCState { | ||
45 | /*< private >*/ | ||
46 | @@ -XXX,XX +XXX,XX @@ typedef struct MicrochipPFSoCState { | ||
47 | MchpPfSoCMMUartState *serial2; | ||
48 | MchpPfSoCMMUartState *serial3; | ||
49 | MchpPfSoCMMUartState *serial4; | ||
50 | + CadenceSDHCIState sdhci; | ||
51 | } MicrochipPFSoCState; | ||
52 | |||
53 | #define TYPE_MICROCHIP_PFSOC "microchip.pfsoc" | ||
54 | @@ -XXX,XX +XXX,XX @@ enum { | ||
55 | MICROCHIP_PFSOC_MMUART0, | ||
56 | MICROCHIP_PFSOC_SYSREG, | ||
57 | MICROCHIP_PFSOC_MPUCFG, | ||
58 | + MICROCHIP_PFSOC_EMMC_SD, | ||
59 | MICROCHIP_PFSOC_MMUART1, | ||
60 | MICROCHIP_PFSOC_MMUART2, | ||
61 | MICROCHIP_PFSOC_MMUART3, | ||
62 | @@ -XXX,XX +XXX,XX @@ enum { | ||
63 | }; | ||
64 | |||
65 | enum { | ||
66 | + MICROCHIP_PFSOC_EMMC_SD_IRQ = 88, | ||
67 | MICROCHIP_PFSOC_MMUART0_IRQ = 90, | ||
68 | MICROCHIP_PFSOC_MMUART1_IRQ = 91, | ||
69 | MICROCHIP_PFSOC_MMUART2_IRQ = 92, | ||
70 | diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c | ||
71 | index XXXXXXX..XXXXXXX 100644 | ||
72 | --- a/hw/riscv/microchip_pfsoc.c | ||
73 | +++ b/hw/riscv/microchip_pfsoc.c | ||
74 | @@ -XXX,XX +XXX,XX @@ | ||
75 | * 1) PLIC (Platform Level Interrupt Controller) | ||
76 | * 2) eNVM (Embedded Non-Volatile Memory) | ||
77 | * 3) MMUARTs (Multi-Mode UART) | ||
78 | + * 4) Cadence eMMC/SDHC controller and an SD card connected to it | ||
79 | * | ||
80 | * This board currently generates devicetree dynamically that indicates at least | ||
81 | * two harts and up to five harts. | ||
82 | @@ -XXX,XX +XXX,XX @@ static const struct MemmapEntry { | ||
83 | [MICROCHIP_PFSOC_MMUART0] = { 0x20000000, 0x1000 }, | ||
84 | [MICROCHIP_PFSOC_SYSREG] = { 0x20002000, 0x2000 }, | ||
85 | [MICROCHIP_PFSOC_MPUCFG] = { 0x20005000, 0x1000 }, | ||
86 | + [MICROCHIP_PFSOC_EMMC_SD] = { 0x20008000, 0x1000 }, | ||
87 | [MICROCHIP_PFSOC_MMUART1] = { 0x20100000, 0x1000 }, | ||
88 | [MICROCHIP_PFSOC_MMUART2] = { 0x20102000, 0x1000 }, | ||
89 | [MICROCHIP_PFSOC_MMUART3] = { 0x20104000, 0x1000 }, | ||
90 | @@ -XXX,XX +XXX,XX @@ static void microchip_pfsoc_soc_instance_init(Object *obj) | ||
91 | qdev_prop_set_string(DEVICE(&s->u_cpus), "cpu-type", | ||
92 | TYPE_RISCV_CPU_SIFIVE_U54); | ||
93 | qdev_prop_set_uint64(DEVICE(&s->u_cpus), "resetvec", RESET_VECTOR); | ||
94 | + | 33 | + |
95 | + object_initialize_child(obj, "sd-controller", &s->sdhci, | 34 | + /* |
96 | + TYPE_CADENCE_SDHCI); | 35 | + * Do not show user warnings for named features that users |
36 | + * can't enable/disable in the command line. See commit | ||
37 | + * 68c9e54bea for more info. | ||
38 | + */ | ||
39 | + if (cpu_cfg_offset_is_named_feat(edata->ext_enable_offset)) { | ||
40 | + continue; | ||
41 | + } | ||
42 | #ifndef CONFIG_USER_ONLY | ||
43 | warn_report("disabling %s extension for hart 0x" TARGET_FMT_lx | ||
44 | " because privilege spec version does not match", | ||
45 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_update_named_features(RISCVCPU *cpu) | ||
46 | cpu->cfg.has_priv_1_13 = true; | ||
47 | } | ||
48 | |||
49 | - /* zic64b is 1.12 or later */ | ||
50 | cpu->cfg.ext_zic64b = cpu->cfg.cbom_blocksize == 64 && | ||
51 | cpu->cfg.cbop_blocksize == 64 && | ||
52 | - cpu->cfg.cboz_blocksize == 64 && | ||
53 | - cpu->cfg.has_priv_1_12; | ||
54 | + cpu->cfg.cboz_blocksize == 64; | ||
97 | } | 55 | } |
98 | 56 | ||
99 | static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp) | 57 | static void riscv_cpu_validate_g(RISCVCPU *cpu) |
100 | @@ -XXX,XX +XXX,XX @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp) | ||
101 | memmap[MICROCHIP_PFSOC_MPUCFG].base, | ||
102 | memmap[MICROCHIP_PFSOC_MPUCFG].size); | ||
103 | |||
104 | + /* SDHCI */ | ||
105 | + sysbus_realize(SYS_BUS_DEVICE(&s->sdhci), errp); | ||
106 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->sdhci), 0, | ||
107 | + memmap[MICROCHIP_PFSOC_EMMC_SD].base); | ||
108 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->sdhci), 0, | ||
109 | + qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_EMMC_SD_IRQ)); | ||
110 | + | ||
111 | /* MMUARTs */ | ||
112 | s->serial0 = mchp_pfsoc_mmuart_create(system_memory, | ||
113 | memmap[MICROCHIP_PFSOC_MMUART0].base, | ||
114 | @@ -XXX,XX +XXX,XX @@ static void microchip_icicle_kit_machine_init(MachineState *machine) | ||
115 | MicrochipIcicleKitState *s = MICROCHIP_ICICLE_KIT_MACHINE(machine); | ||
116 | MemoryRegion *system_memory = get_system_memory(); | ||
117 | MemoryRegion *main_mem = g_new(MemoryRegion, 1); | ||
118 | + DriveInfo *dinfo = drive_get_next(IF_SD); | ||
119 | |||
120 | /* Sanity check on RAM size */ | ||
121 | if (machine->ram_size < mc->default_ram_size) { | ||
122 | @@ -XXX,XX +XXX,XX @@ static void microchip_icicle_kit_machine_init(MachineState *machine) | ||
123 | |||
124 | /* Load the firmware */ | ||
125 | riscv_find_and_load_firmware(machine, BIOS_FILENAME, RESET_VECTOR, NULL); | ||
126 | + | ||
127 | + /* Attach an SD card */ | ||
128 | + if (dinfo) { | ||
129 | + CadenceSDHCIState *sdhci = &(s->soc.sdhci); | ||
130 | + DeviceState *card = qdev_new(TYPE_SD_CARD); | ||
131 | + | ||
132 | + qdev_prop_set_drive_err(card, "drive", blk_by_legacy_dinfo(dinfo), | ||
133 | + &error_fatal); | ||
134 | + qdev_realize_and_unref(card, sdhci->bus, &error_fatal); | ||
135 | + } | ||
136 | } | ||
137 | |||
138 | static void microchip_icicle_kit_machine_class_init(ObjectClass *oc, void *data) | ||
139 | diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig | ||
140 | index XXXXXXX..XXXXXXX 100644 | ||
141 | --- a/hw/riscv/Kconfig | ||
142 | +++ b/hw/riscv/Kconfig | ||
143 | @@ -XXX,XX +XXX,XX @@ config MICROCHIP_PFSOC | ||
144 | select SIFIVE | ||
145 | select UNIMP | ||
146 | select MCHP_PFSOC_MMUART | ||
147 | + select CADENCE_SDHCI | ||
148 | -- | 58 | -- |
149 | 2.28.0 | 59 | 2.47.1 |
150 | |||
151 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | Now that we have the newly introduced 'resetvec' property in the | 3 | ssstateen is defined in RVA22 as: |
4 | RISC-V CPU and HART, instead of hard-coding the reset vector addr | ||
5 | in the CPU's instance_init(), move that to riscv_cpu_realize() | ||
6 | based on the configured property value from the RISC-V machines. | ||
7 | 4 | ||
8 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 5 | "Supervisor-mode view of the state-enable extension. The supervisor-mode |
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 6 | (sstateen0-3) and hypervisor-mode (hstateen0-3) state-enable registers |
10 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 7 | must be provided." |
11 | Message-Id: <1598924352-89526-4-git-send-email-bmeng.cn@gmail.com> | 8 | |
9 | Add ssstateen as a named feature that is available if we also have | ||
10 | smstateen. | ||
11 | |||
12 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
13 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
14 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
15 | Message-ID: <20241113171755.978109-3-dbarboza@ventanamicro.com> | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
13 | --- | 17 | --- |
14 | hw/riscv/opentitan.c | 1 + | 18 | target/riscv/cpu_cfg.h | 1 + |
15 | hw/riscv/sifive_e.c | 1 + | 19 | target/riscv/cpu.c | 2 ++ |
16 | hw/riscv/sifive_u.c | 2 ++ | 20 | target/riscv/tcg/tcg-cpu.c | 9 ++++++++- |
17 | target/riscv/cpu.c | 7 ++----- | 21 | 3 files changed, 11 insertions(+), 1 deletion(-) |
18 | 4 files changed, 6 insertions(+), 5 deletions(-) | ||
19 | 22 | ||
20 | diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c | 23 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h |
21 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/hw/riscv/opentitan.c | 25 | --- a/target/riscv/cpu_cfg.h |
23 | +++ b/hw/riscv/opentitan.c | 26 | +++ b/target/riscv/cpu_cfg.h |
24 | @@ -XXX,XX +XXX,XX @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp) | 27 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { |
25 | &error_abort); | 28 | /* Named features */ |
26 | object_property_set_int(OBJECT(&s->cpus), "num-harts", ms->smp.cpus, | 29 | bool ext_svade; |
27 | &error_abort); | 30 | bool ext_zic64b; |
28 | + object_property_set_int(OBJECT(&s->cpus), "resetvec", 0x8090, &error_abort); | 31 | + bool ext_ssstateen; |
29 | sysbus_realize(SYS_BUS_DEVICE(&s->cpus), &error_abort); | 32 | |
30 | 33 | /* | |
31 | /* Boot ROM */ | 34 | * Always 'true' booleans for named features |
32 | diff --git a/hw/riscv/sifive_e.c b/hw/riscv/sifive_e.c | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/hw/riscv/sifive_e.c | ||
35 | +++ b/hw/riscv/sifive_e.c | ||
36 | @@ -XXX,XX +XXX,XX @@ static void sifive_e_soc_init(Object *obj) | ||
37 | object_initialize_child(obj, "cpus", &s->cpus, TYPE_RISCV_HART_ARRAY); | ||
38 | object_property_set_int(OBJECT(&s->cpus), "num-harts", ms->smp.cpus, | ||
39 | &error_abort); | ||
40 | + object_property_set_int(OBJECT(&s->cpus), "resetvec", 0x1004, &error_abort); | ||
41 | object_initialize_child(obj, "riscv.sifive.e.gpio0", &s->gpio, | ||
42 | TYPE_SIFIVE_GPIO); | ||
43 | } | ||
44 | diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c | ||
45 | index XXXXXXX..XXXXXXX 100644 | ||
46 | --- a/hw/riscv/sifive_u.c | ||
47 | +++ b/hw/riscv/sifive_u.c | ||
48 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_soc_instance_init(Object *obj) | ||
49 | qdev_prop_set_uint32(DEVICE(&s->e_cpus), "num-harts", 1); | ||
50 | qdev_prop_set_uint32(DEVICE(&s->e_cpus), "hartid-base", 0); | ||
51 | qdev_prop_set_string(DEVICE(&s->e_cpus), "cpu-type", SIFIVE_E_CPU); | ||
52 | + qdev_prop_set_uint64(DEVICE(&s->e_cpus), "resetvec", 0x1004); | ||
53 | |||
54 | object_initialize_child(obj, "u-cluster", &s->u_cluster, TYPE_CPU_CLUSTER); | ||
55 | qdev_prop_set_uint32(DEVICE(&s->u_cluster), "cluster-id", 1); | ||
56 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_soc_instance_init(Object *obj) | ||
57 | qdev_prop_set_uint32(DEVICE(&s->u_cpus), "num-harts", ms->smp.cpus - 1); | ||
58 | qdev_prop_set_uint32(DEVICE(&s->u_cpus), "hartid-base", 1); | ||
59 | qdev_prop_set_string(DEVICE(&s->u_cpus), "cpu-type", SIFIVE_U_CPU); | ||
60 | + qdev_prop_set_uint64(DEVICE(&s->u_cpus), "resetvec", 0x1004); | ||
61 | |||
62 | object_initialize_child(obj, "prci", &s->prci, TYPE_SIFIVE_U_PRCI); | ||
63 | object_initialize_child(obj, "otp", &s->otp, TYPE_SIFIVE_U_OTP); | ||
64 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 35 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
65 | index XXXXXXX..XXXXXXX 100644 | 36 | index XXXXXXX..XXXXXXX 100644 |
66 | --- a/target/riscv/cpu.c | 37 | --- a/target/riscv/cpu.c |
67 | +++ b/target/riscv/cpu.c | 38 | +++ b/target/riscv/cpu.c |
68 | @@ -XXX,XX +XXX,XX @@ static void riscv_any_cpu_init(Object *obj) | 39 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { |
69 | CPURISCVState *env = &RISCV_CPU(obj)->env; | 40 | ISA_EXT_DATA_ENTRY(ssccptr, PRIV_VERSION_1_11_0, has_priv_1_11), |
70 | set_misa(env, RVXLEN | RVI | RVM | RVA | RVF | RVD | RVC | RVU); | 41 | ISA_EXT_DATA_ENTRY(sscofpmf, PRIV_VERSION_1_12_0, ext_sscofpmf), |
71 | set_priv_version(env, PRIV_VERSION_1_11_0); | 42 | ISA_EXT_DATA_ENTRY(sscounterenw, PRIV_VERSION_1_12_0, has_priv_1_12), |
72 | - set_resetvec(env, DEFAULT_RSTVEC); | 43 | + ISA_EXT_DATA_ENTRY(ssstateen, PRIV_VERSION_1_12_0, ext_ssstateen), |
44 | ISA_EXT_DATA_ENTRY(sstc, PRIV_VERSION_1_12_0, ext_sstc), | ||
45 | ISA_EXT_DATA_ENTRY(sstvala, PRIV_VERSION_1_12_0, has_priv_1_12), | ||
46 | ISA_EXT_DATA_ENTRY(sstvecd, PRIV_VERSION_1_12_0, has_priv_1_12), | ||
47 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = { | ||
48 | */ | ||
49 | const RISCVCPUMultiExtConfig riscv_cpu_named_features[] = { | ||
50 | MULTI_EXT_CFG_BOOL("zic64b", ext_zic64b, true), | ||
51 | + MULTI_EXT_CFG_BOOL("ssstateen", ext_ssstateen, true), | ||
52 | |||
53 | DEFINE_PROP_END_OF_LIST(), | ||
54 | }; | ||
55 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | ||
56 | index XXXXXXX..XXXXXXX 100644 | ||
57 | --- a/target/riscv/tcg/tcg-cpu.c | ||
58 | +++ b/target/riscv/tcg/tcg-cpu.c | ||
59 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_enable_named_feat(RISCVCPU *cpu, uint32_t feat_offset) | ||
60 | * All other named features are already enabled | ||
61 | * in riscv_tcg_cpu_instance_init(). | ||
62 | */ | ||
63 | - if (feat_offset == CPU_CFG_OFFSET(ext_zic64b)) { | ||
64 | + switch (feat_offset) { | ||
65 | + case CPU_CFG_OFFSET(ext_zic64b): | ||
66 | cpu->cfg.cbom_blocksize = 64; | ||
67 | cpu->cfg.cbop_blocksize = 64; | ||
68 | cpu->cfg.cboz_blocksize = 64; | ||
69 | + break; | ||
70 | + case CPU_CFG_OFFSET(ext_ssstateen): | ||
71 | + cpu->cfg.ext_smstateen = true; | ||
72 | + break; | ||
73 | } | ||
73 | } | 74 | } |
74 | 75 | ||
75 | static void riscv_base_cpu_init(Object *obj) | 76 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_update_named_features(RISCVCPU *cpu) |
76 | @@ -XXX,XX +XXX,XX @@ static void riscv_base_cpu_init(Object *obj) | 77 | cpu->cfg.ext_zic64b = cpu->cfg.cbom_blocksize == 64 && |
77 | CPURISCVState *env = &RISCV_CPU(obj)->env; | 78 | cpu->cfg.cbop_blocksize == 64 && |
78 | /* We set this in the realise function */ | 79 | cpu->cfg.cboz_blocksize == 64; |
79 | set_misa(env, 0); | 80 | + |
80 | - set_resetvec(env, DEFAULT_RSTVEC); | 81 | + cpu->cfg.ext_ssstateen = cpu->cfg.ext_smstateen; |
81 | } | 82 | } |
82 | 83 | ||
83 | static void rvxx_sifive_u_cpu_init(Object *obj) | 84 | static void riscv_cpu_validate_g(RISCVCPU *cpu) |
84 | @@ -XXX,XX +XXX,XX @@ static void rvxx_sifive_u_cpu_init(Object *obj) | ||
85 | CPURISCVState *env = &RISCV_CPU(obj)->env; | ||
86 | set_misa(env, RVXLEN | RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); | ||
87 | set_priv_version(env, PRIV_VERSION_1_10_0); | ||
88 | - set_resetvec(env, 0x1004); | ||
89 | } | ||
90 | |||
91 | static void rvxx_sifive_e_cpu_init(Object *obj) | ||
92 | @@ -XXX,XX +XXX,XX @@ static void rvxx_sifive_e_cpu_init(Object *obj) | ||
93 | CPURISCVState *env = &RISCV_CPU(obj)->env; | ||
94 | set_misa(env, RVXLEN | RVI | RVM | RVA | RVC | RVU); | ||
95 | set_priv_version(env, PRIV_VERSION_1_10_0); | ||
96 | - set_resetvec(env, 0x1004); | ||
97 | qdev_prop_set_bit(DEVICE(obj), "mmu", false); | ||
98 | } | ||
99 | |||
100 | @@ -XXX,XX +XXX,XX @@ static void rv32_ibex_cpu_init(Object *obj) | ||
101 | CPURISCVState *env = &RISCV_CPU(obj)->env; | ||
102 | set_misa(env, RV32 | RVI | RVM | RVC | RVU); | ||
103 | set_priv_version(env, PRIV_VERSION_1_10_0); | ||
104 | - set_resetvec(env, 0x8090); | ||
105 | qdev_prop_set_bit(DEVICE(obj), "mmu", false); | ||
106 | } | ||
107 | |||
108 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) | ||
109 | set_feature(env, RISCV_FEATURE_PMP); | ||
110 | } | ||
111 | |||
112 | + set_resetvec(env, cpu->cfg.resetvec); | ||
113 | + | ||
114 | /* If misa isn't set (rv32 and rv64 machines) set it here */ | ||
115 | if (!env->misa) { | ||
116 | /* Do some ISA extension error checking */ | ||
117 | -- | 85 | -- |
118 | 2.28.0 | 86 | 2.47.1 |
119 | |||
120 | diff view generated by jsdifflib |
1 | From: Yifei Jiang <jiangyifei@huawei.com> | 1 | From: MollyChen <xiaoou@iscas.ac.cn> |
---|---|---|---|
2 | 2 | ||
3 | When the cause number is equal to or greater than 23, print "(unknown)" in | 3 | Add a CPU entry for the RV64 XiangShan NANHU CPU which |
4 | trace_riscv_trap. The max valid number of riscv_excp_names is 23, so the last | 4 | supports single-core and dual-core configurations. More |
5 | excpetion "guest_store_page_fault" can not be printed. | 5 | details can be found at |
6 | https://docs.xiangshan.cc/zh-cn/latest/integration/overview | ||
6 | 7 | ||
7 | In addition, the current check of cause is invalid for riscv_intr_names. So | 8 | Signed-off-by: MollyChen <xiaoou@iscas.ac.cn> |
8 | introduce riscv_cpu_get_trap_name to get the trap cause name. | 9 | Acked-by: Alistair Francis <alistair.francis@wdc.com> |
9 | 10 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | |
10 | Signed-off-by: Yifei Jiang <jiangyifei@huawei.com> | 11 | Message-ID: <20241205073622.46052-1-xiaoou@iscas.ac.cn> |
11 | Signed-off-by: Yipeng Yin <yinyipeng1@huawei.com> | 12 | [ Changes by AF |
12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 13 | - Fixup code formatting |
13 | Message-Id: <20200814035819.1214-1-jiangyifei@huawei.com> | 14 | ] |
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
15 | --- | 16 | --- |
16 | target/riscv/cpu.h | 1 + | 17 | target/riscv/cpu-qom.h | 1 + |
17 | target/riscv/cpu.c | 11 +++++++++++ | 18 | target/riscv/cpu.c | 30 ++++++++++++++++++++++++++++++ |
18 | target/riscv/cpu_helper.c | 4 ++-- | 19 | 2 files changed, 31 insertions(+) |
19 | 3 files changed, 14 insertions(+), 2 deletions(-) | ||
20 | 20 | ||
21 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 21 | diff --git a/target/riscv/cpu-qom.h b/target/riscv/cpu-qom.h |
22 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/target/riscv/cpu.h | 23 | --- a/target/riscv/cpu-qom.h |
24 | +++ b/target/riscv/cpu.h | 24 | +++ b/target/riscv/cpu-qom.h |
25 | @@ -XXX,XX +XXX,XX @@ extern const char * const riscv_fpr_regnames[]; | 25 | @@ -XXX,XX +XXX,XX @@ |
26 | extern const char * const riscv_excp_names[]; | 26 | #define TYPE_RISCV_CPU_THEAD_C906 RISCV_CPU_TYPE_NAME("thead-c906") |
27 | extern const char * const riscv_intr_names[]; | 27 | #define TYPE_RISCV_CPU_VEYRON_V1 RISCV_CPU_TYPE_NAME("veyron-v1") |
28 | 28 | #define TYPE_RISCV_CPU_TT_ASCALON RISCV_CPU_TYPE_NAME("tt-ascalon") | |
29 | +const char *riscv_cpu_get_trap_name(target_ulong cause, bool async); | 29 | +#define TYPE_RISCV_CPU_XIANGSHAN_NANHU RISCV_CPU_TYPE_NAME("xiangshan-nanhu") |
30 | void riscv_cpu_do_interrupt(CPUState *cpu); | 30 | #define TYPE_RISCV_CPU_HOST RISCV_CPU_TYPE_NAME("host") |
31 | int riscv_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); | 31 | |
32 | int riscv_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); | 32 | OBJECT_DECLARE_CPU_TYPE(RISCVCPU, RISCVCPUClass, RISCV_CPU) |
33 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 33 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
34 | index XXXXXXX..XXXXXXX 100644 | 34 | index XXXXXXX..XXXXXXX 100644 |
35 | --- a/target/riscv/cpu.c | 35 | --- a/target/riscv/cpu.c |
36 | +++ b/target/riscv/cpu.c | 36 | +++ b/target/riscv/cpu.c |
37 | @@ -XXX,XX +XXX,XX @@ const char * const riscv_intr_names[] = { | 37 | @@ -XXX,XX +XXX,XX @@ static void rv64_tt_ascalon_cpu_init(Object *obj) |
38 | "reserved" | 38 | #endif |
39 | }; | 39 | } |
40 | 40 | ||
41 | +const char *riscv_cpu_get_trap_name(target_ulong cause, bool async) | 41 | +static void rv64_xiangshan_nanhu_cpu_init(Object *obj) |
42 | +{ | 42 | +{ |
43 | + if (async) { | 43 | + CPURISCVState *env = &RISCV_CPU(obj)->env; |
44 | + return (cause < ARRAY_SIZE(riscv_intr_names)) ? | 44 | + RISCVCPU *cpu = RISCV_CPU(obj); |
45 | + riscv_intr_names[cause] : "(unknown)"; | 45 | + |
46 | + } else { | 46 | + riscv_cpu_set_misa_ext(env, RVG | RVC | RVB | RVS | RVU); |
47 | + return (cause < ARRAY_SIZE(riscv_excp_names)) ? | 47 | + env->priv_ver = PRIV_VERSION_1_12_0; |
48 | + riscv_excp_names[cause] : "(unknown)"; | 48 | + |
49 | + } | 49 | + /* Enable ISA extensions */ |
50 | + cpu->cfg.ext_zbc = true; | ||
51 | + cpu->cfg.ext_zbkb = true; | ||
52 | + cpu->cfg.ext_zbkc = true; | ||
53 | + cpu->cfg.ext_zbkx = true; | ||
54 | + cpu->cfg.ext_zknd = true; | ||
55 | + cpu->cfg.ext_zkne = true; | ||
56 | + cpu->cfg.ext_zknh = true; | ||
57 | + cpu->cfg.ext_zksed = true; | ||
58 | + cpu->cfg.ext_zksh = true; | ||
59 | + cpu->cfg.ext_svinval = true; | ||
60 | + | ||
61 | + cpu->cfg.mmu = true; | ||
62 | + cpu->cfg.pmp = true; | ||
63 | + | ||
64 | +#ifndef CONFIG_USER_ONLY | ||
65 | + set_satp_mode_max_supported(cpu, VM_1_10_SV39); | ||
66 | +#endif | ||
50 | +} | 67 | +} |
51 | + | 68 | + |
52 | static void set_misa(CPURISCVState *env, target_ulong misa) | 69 | #ifdef CONFIG_TCG |
70 | static void rv128_base_cpu_init(Object *obj) | ||
53 | { | 71 | { |
54 | env->misa_mask = env->misa = misa; | 72 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo riscv_cpu_type_infos[] = { |
55 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | 73 | DEFINE_VENDOR_CPU(TYPE_RISCV_CPU_THEAD_C906, MXL_RV64, rv64_thead_c906_cpu_init), |
56 | index XXXXXXX..XXXXXXX 100644 | 74 | DEFINE_VENDOR_CPU(TYPE_RISCV_CPU_TT_ASCALON, MXL_RV64, rv64_tt_ascalon_cpu_init), |
57 | --- a/target/riscv/cpu_helper.c | 75 | DEFINE_VENDOR_CPU(TYPE_RISCV_CPU_VEYRON_V1, MXL_RV64, rv64_veyron_v1_cpu_init), |
58 | +++ b/target/riscv/cpu_helper.c | 76 | + DEFINE_VENDOR_CPU(TYPE_RISCV_CPU_XIANGSHAN_NANHU, |
59 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs) | 77 | + MXL_RV64, rv64_xiangshan_nanhu_cpu_init), |
60 | } | 78 | #ifdef CONFIG_TCG |
61 | } | 79 | DEFINE_DYNAMIC_CPU(TYPE_RISCV_CPU_BASE128, MXL_RV128, rv128_base_cpu_init), |
62 | 80 | #endif /* CONFIG_TCG */ | |
63 | - trace_riscv_trap(env->mhartid, async, cause, env->pc, tval, cause < 23 ? | ||
64 | - (async ? riscv_intr_names : riscv_excp_names)[cause] : "(unknown)"); | ||
65 | + trace_riscv_trap(env->mhartid, async, cause, env->pc, tval, | ||
66 | + riscv_cpu_get_trap_name(cause, async)); | ||
67 | |||
68 | if (env->priv <= PRV_S && | ||
69 | cause < TARGET_LONG_BITS && ((deleg >> cause) & 1)) { | ||
70 | -- | 81 | -- |
71 | 2.28.0 | 82 | 2.47.1 |
72 | |||
73 | diff view generated by jsdifflib |