1
Nuvoton new board models, and some more minor stuff. I also put
1
target-arm queue: I have a lot more still in my to-review
2
in the deprecation patches for unicore32 and lm32.
2
queue, but my rule of thumb is when I get to 50 patches or
3
so to send out what I have.
3
4
4
thanks
5
thanks
5
-- PMM
6
-- PMM
6
7
7
The following changes since commit a68694cd1f3e5448cca814ff39b871f9ebd71ed5:
8
The following changes since commit 9a7beaad3dbba982f7a461d676b55a5c3851d312:
8
9
9
Merge remote-tracking branch 'remotes/philmd-gitlab/tags/edk2-next-20200914' into staging (2020-09-14 12:18:58 +0100)
10
Merge remote-tracking branch 'remotes/alistair/tags/pull-riscv-to-apply-20210304' into staging (2021-03-05 10:47:46 +0000)
10
11
11
are available in the Git repository at:
12
are available in the Git repository at:
12
13
13
https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20200914
14
https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20210305
14
15
15
for you to fetch changes up to dd44ae00fc5342ed99acb68ec3508f76a71d523a:
16
for you to fetch changes up to 2c669ff88ec6733420a000103a2b8b9e93df4945:
16
17
17
MAINTAINERS: Add maintainer entry for Xilinx ZynqMP CAN controller (2020-09-14 14:27:08 +0100)
18
hw/arm/mps2: Update old infocenter.arm.com URLs (2021-03-05 15:17:38 +0000)
18
19
19
----------------------------------------------------------------
20
----------------------------------------------------------------
20
target-arm queue:
21
* sbsa-ref: remove cortex-a53 from list of supported cpus
21
* hw/misc/a9scu: Do not allow invalid CPU count
22
* sbsa-ref: add 'max' to list of allowed cpus
22
* hw/misc/a9scu: Minor cleanups
23
* target/arm: Add support for FEAT_SSBS, Speculative Store Bypass Safe
23
* hw/timer/armv7m_systick: assert that board code set system_clock_scale
24
* npcm7xx: add EMC model
24
* decodetree: Improve identifier matching
25
* xlnx-zynqmp: Remove obsolete 'has_rpu' property
25
* target/arm: Clean up neon fp insn size field decode
26
* target/arm: Speed up aarch64 TBL/TBX
26
* target/arm: Remove KVM support for 32-bit Arm hosts
27
* virtio-mmio: improve virtio-mmio get_dev_path alog
27
* hw/arm/mps2: New board models mps2-an386, mps2-an500
28
* target/arm: Use TCF0 and TFSRE0 for unprivileged tag checks
28
* Deprecate Unicore32 port
29
* target/arm: Restrict v8M IDAU to TCG
29
* Deprecate lm32 port
30
* target/arm/cpu: Update coding style to make checkpatch.pl happy
30
* target/arm: Count PMU events when MDCR.SPME is set
31
* musicpal, tc6393xb, omap_lcdc, tcx: drop dead code for non-32-bit-RGB surfaces
31
* hw/arm: versal-virt: Correct the tx/rx GEM clocks
32
* Add new board: mps3-an524
32
* New Nuvoton iBMC board models npcm750-evb, quanta-gsj
33
* xlnx-zynqmp: implement ZynqMP CAN controllers
34
33
35
----------------------------------------------------------------
34
----------------------------------------------------------------
36
Aaron Lindsay (1):
35
Doug Evans (3):
37
target/arm: Count PMU events when MDCR.SPME is set
36
hw/net: Add npcm7xx emc model
37
hw/arm: Add npcm7xx emc model
38
tests/qtests: Add npcm7xx emc model test
38
39
39
Edgar E. Iglesias (1):
40
Marcin Juszkiewicz (2):
40
hw/arm: versal-virt: Correct the tx/rx GEM clocks
41
sbsa-ref: remove cortex-a53 from list of supported cpus
42
sbsa-ref: add 'max' to list of allowed cpus
41
43
42
Havard Skinnemoen (14):
44
Peter Collingbourne (1):
43
hw/misc: Add NPCM7xx System Global Control Registers device model
45
target/arm: Use TCF0 and TFSRE0 for unprivileged tag checks
44
hw/misc: Add NPCM7xx Clock Controller device model
45
hw/timer: Add NPCM7xx Timer device model
46
hw/arm: Add NPCM730 and NPCM750 SoC models
47
hw/arm: Add two NPCM7xx-based machines
48
roms: Add virtual Boot ROM for NPCM7xx SoCs
49
hw/arm: Load -bios image as a boot ROM for npcm7xx
50
hw/nvram: NPCM7xx OTP device model
51
hw/mem: Stubbed out NPCM7xx Memory Controller model
52
hw/ssi: NPCM7xx Flash Interface Unit device model
53
hw/arm: Wire up BMC boot flash for npcm750-evb and quanta-gsj
54
hw/arm/npcm7xx: add board setup stub for CPU and UART clocks
55
docs/system: Add Nuvoton machine documentation
56
tests/acceptance: console boot tests for quanta-gsj
57
46
58
Peter Maydell (11):
47
Peter Maydell (34):
59
hw/timer/armv7m_systick: assert that board code set system_clock_scale
48
hw/arm/musicpal: Remove dead code for non-32-bit-RGB surfaces
60
target/arm: Convert Neon 3-same-fp size field to MO_* in decode
49
hw/display/tc6393xb: Remove dead code for handling non-32bpp surfaces
61
target/arm: Convert Neon VCVT fp size field to MO_* in decode
50
hw/display/tc6393xb: Expand out macros in template header
62
target/arm: Convert VCMLA, VCADD size field to MO_* in decode
51
hw/display/tc6393xb: Inline tc6393xb_draw_graphic32() at its callsite
63
target/arm: Remove KVM support for 32-bit Arm hosts
52
hw/display/omap_lcdc: Expand out macros in template header
64
target/arm: Remove no-longer-reachable 32-bit KVM code
53
hw/display/omap_lcdc: Drop broken bigendian ifdef
65
hw/arm/mps2: New board model mps2-an386
54
hw/display/omap_lcdc: Fix coding style issues in template header
66
hw/arm/mps2: New board model mps2-an500
55
hw/display/omap_lcdc: Inline template header into C file
67
docs/system/arm/mps2.rst: Make board list consistent
56
hw/display/omap_lcdc: Delete unnecessary macro
68
Deprecate Unicore32 port
57
hw/display/tcx: Drop unnecessary code for handling BGR format outputs
69
Deprecate lm32 port
58
hw/arm/mps2-tz: Make SYSCLK frequency board-specific
59
hw/misc/mps2-scc: Support configurable number of OSCCLK values
60
hw/arm/mps2-tz: Correct the OSCCLK settings for mps2-an505 and mps2-an511
61
hw/arm/mps2-tz: Make the OSCCLK settings be configurable per-board
62
hw/misc/mps2-fpgaio: Make number of LEDs configurable by board
63
hw/misc/mps2-fpgaio: Support SWITCH register
64
hw/arm/mps2-tz: Make FPGAIO switch and LED config per-board
65
hw/arm/mps2-tz: Condition IRQ splitting on number of CPUs, not board type
66
hw/arm/mps2-tz: Make number of IRQs board-specific
67
hw/misc/mps2-scc: Implement CFG_REG5 and CFG_REG6 for MPS3 AN524
68
hw/arm/mps2-tz: Correct wrong interrupt numbers for DMA and SPI
69
hw/arm/mps2-tz: Allow PPCPortInfo structures to specify device interrupts
70
hw/arm/mps2-tz: Move device IRQ info to data structures
71
hw/arm/mps2-tz: Size the uart-irq-orgate based on the number of UARTs
72
hw/arm/mps2-tz: Allow boards to have different PPCInfo data
73
hw/arm/mps2-tz: Make RAM arrangement board-specific
74
hw/arm/mps2-tz: Set MachineClass default_ram info from RAMInfo data
75
hw/arm/mps2-tz: Support ROMs as well as RAMs
76
hw/arm/mps2-tz: Get armv7m_load_kernel() size argument from RAMInfo
77
hw/arm/mps2-tz: Add new mps3-an524 board
78
hw/arm/mps2-tz: Stub out USB controller for mps3-an524
79
hw/arm/mps2-tz: Provide PL031 RTC on mps3-an524
80
docs/system/arm/mps2.rst: Document the new mps3-an524 board
81
hw/arm/mps2: Update old infocenter.arm.com URLs
70
82
71
Philippe Mathieu-Daudé (4):
83
Philippe Mathieu-Daudé (4):
72
hw/misc/a9scu: Do not allow invalid CPU count
84
hw/arm/xlnx-zynqmp: Remove obsolete 'has_rpu' property
73
hw/misc/a9scu: Simplify setting MemoryRegionOps::valid fields
85
hw/i2c/npcm7xx_smbus: Simplify npcm7xx_smbus_init()
74
hw/misc/a9scu: Simplify setting MemoryRegionOps::impl fields
86
target/arm: Restrict v8M IDAU to TCG
75
hw/misc/a9scu: Report unimplemented accesses with qemu_log_mask(UNIMP)
87
target/arm/cpu: Update coding style to make checkpatch.pl happy
88
89
Rebecca Cran (3):
90
target/arm: Add support for FEAT_SSBS, Speculative Store Bypass Safe
91
target/arm: Enable FEAT_SSBS for "max" AARCH64 CPU
92
target/arm: Set ID_PFR2.SSBS to 1 for "max" 32-bit CPU
76
93
77
Richard Henderson (1):
94
Richard Henderson (1):
78
decodetree: Improve identifier matching
95
target/arm: Speed up aarch64 TBL/TBX
79
96
80
Vikram Garhwal (4):
97
schspa (1):
81
hw/net/can: Introduce Xilinx ZynqMP CAN controller
98
virtio-mmio: improve virtio-mmio get_dev_path alog
82
xlnx-zynqmp: Connect Xilinx ZynqMP CAN controllers
83
tests/qtest: Introduce tests for Xilinx ZynqMP CAN controller
84
MAINTAINERS: Add maintainer entry for Xilinx ZynqMP CAN controller
85
99
86
docs/system/arm/mps2.rst | 20 +-
100
docs/system/arm/mps2.rst | 24 +-
87
docs/system/arm/nuvoton.rst | 92 +++
101
docs/system/arm/nuvoton.rst | 3 +-
88
docs/system/deprecated.rst | 32 +-
102
hw/display/omap_lcd_template.h | 169 --------
89
docs/system/target-arm.rst | 1 +
103
hw/display/tc6393xb_template.h | 72 ----
90
configure | 2 +-
104
include/hw/arm/armsse.h | 4 +-
91
default-configs/arm-softmmu.mak | 1 +
105
include/hw/arm/npcm7xx.h | 2 +
92
include/hw/arm/npcm7xx.h | 112 +++
106
include/hw/arm/xlnx-zynqmp.h | 2 -
93
include/hw/arm/xlnx-zynqmp.h | 8 +
107
include/hw/misc/armsse-cpuid.h | 2 +-
94
include/hw/mem/npcm7xx_mc.h | 36 +
108
include/hw/misc/armsse-mhu.h | 2 +-
95
include/hw/misc/npcm7xx_clk.h | 48 ++
109
include/hw/misc/iotkit-secctl.h | 2 +-
96
include/hw/misc/npcm7xx_gcr.h | 43 ++
110
include/hw/misc/iotkit-sysctl.h | 2 +-
97
include/hw/net/xlnx-zynqmp-can.h | 78 +++
111
include/hw/misc/iotkit-sysinfo.h | 2 +-
98
include/hw/nvram/npcm7xx_otp.h | 79 +++
112
include/hw/misc/mps2-fpgaio.h | 8 +-
99
include/hw/ssi/npcm7xx_fiu.h | 73 ++
113
include/hw/misc/mps2-scc.h | 10 +-
100
include/hw/timer/npcm7xx_timer.h | 78 +++
114
include/hw/net/npcm7xx_emc.h | 286 +++++++++++++
101
target/arm/kvm-consts.h | 7 -
115
include/ui/console.h | 10 -
102
target/arm/kvm_arm.h | 6 -
116
target/arm/cpu.h | 15 +-
103
target/arm/neon-dp.decode | 18 +-
117
target/arm/helper-a64.h | 2 +-
104
target/arm/neon-shared.decode | 18 +-
118
target/arm/internals.h | 6 +
105
tests/decode/succ_ident1.decode | 7 +
119
hw/arm/mps2-tz.c | 632 +++++++++++++++++++++++-----
106
hw/arm/mps2.c | 97 ++-
120
hw/arm/mps2.c | 5 +
107
hw/arm/npcm7xx.c | 532 +++++++++++++++
121
hw/arm/musicpal.c | 64 ++-
108
hw/arm/npcm7xx_boards.c | 197 ++++++
122
hw/arm/npcm7xx.c | 50 ++-
109
hw/arm/xlnx-versal-virt.c | 2 +-
123
hw/arm/sbsa-ref.c | 2 +-
110
hw/arm/xlnx-zcu102.c | 20 +
124
hw/arm/xlnx-zynqmp.c | 6 -
111
hw/arm/xlnx-zynqmp.c | 34 +
125
hw/display/omap_lcdc.c | 129 +++++-
112
hw/mem/npcm7xx_mc.c | 84 +++
126
hw/display/tc6393xb.c | 48 +--
113
hw/misc/a9scu.c | 59 +-
127
hw/display/tcx.c | 31 +-
114
hw/misc/npcm7xx_clk.c | 266 ++++++++
128
hw/i2c/npcm7xx_smbus.c | 1 -
115
hw/misc/npcm7xx_gcr.c | 269 ++++++++
129
hw/misc/armsse-cpuid.c | 2 +-
116
hw/net/can/xlnx-zynqmp-can.c | 1165 ++++++++++++++++++++++++++++++++
130
hw/misc/armsse-mhu.c | 2 +-
117
hw/nvram/npcm7xx_otp.c | 440 ++++++++++++
131
hw/misc/iotkit-sysctl.c | 2 +-
118
hw/ssi/npcm7xx_fiu.c | 572 ++++++++++++++++
132
hw/misc/iotkit-sysinfo.c | 2 +-
119
hw/timer/armv7m_systick.c | 8 +
133
hw/misc/mps2-fpgaio.c | 43 +-
120
hw/timer/npcm7xx_timer.c | 543 +++++++++++++++
134
hw/misc/mps2-scc.c | 93 ++++-
121
target/arm/cpu.c | 101 ++-
135
hw/net/npcm7xx_emc.c | 857 ++++++++++++++++++++++++++++++++++++++
122
target/arm/helper.c | 2 +-
136
hw/virtio/virtio-mmio.c | 13 +-
123
target/arm/kvm.c | 7 -
137
target/arm/cpu.c | 23 +-
124
target/arm/kvm32.c | 595 ----------------
138
target/arm/cpu64.c | 5 +
125
tests/qtest/xlnx-can-test.c | 359 ++++++++++
139
target/arm/cpu_tcg.c | 8 +
126
.gitmodules | 3 +
140
target/arm/helper-a64.c | 32 --
127
MAINTAINERS | 18 +
141
target/arm/helper.c | 39 +-
128
hw/arm/Kconfig | 9 +
142
target/arm/mte_helper.c | 13 +-
129
hw/arm/meson.build | 1 +
143
target/arm/translate-a64.c | 70 +---
130
hw/mem/meson.build | 1 +
144
target/arm/vec_helper.c | 48 +++
131
hw/misc/meson.build | 4 +
145
tests/qtest/npcm7xx_emc-test.c | 862 +++++++++++++++++++++++++++++++++++++++
132
hw/misc/trace-events | 8 +
146
hw/net/meson.build | 1 +
133
hw/net/can/meson.build | 1 +
147
hw/net/trace-events | 17 +
134
hw/nvram/meson.build | 1 +
148
tests/qtest/meson.build | 3 +-
135
hw/ssi/meson.build | 1 +
149
49 files changed, 3098 insertions(+), 628 deletions(-)
136
hw/ssi/trace-events | 11 +
150
delete mode 100644 hw/display/omap_lcd_template.h
137
hw/timer/meson.build | 1 +
151
delete mode 100644 hw/display/tc6393xb_template.h
138
hw/timer/trace-events | 5 +
152
create mode 100644 include/hw/net/npcm7xx_emc.h
139
pc-bios/README | 6 +
153
create mode 100644 hw/net/npcm7xx_emc.c
140
pc-bios/meson.build | 1 +
154
create mode 100644 tests/qtest/npcm7xx_emc-test.c
141
pc-bios/npcm7xx_bootrom.bin | Bin 0 -> 768 bytes
142
roms/Makefile | 7 +
143
roms/vbootrom | 1 +
144
scripts/decodetree.py | 46 +-
145
target/arm/meson.build | 5 +-
146
target/arm/translate-neon.c.inc | 42 +-
147
tests/acceptance/boot_linux_console.py | 83 +++
148
tests/qtest/meson.build | 1 +
149
63 files changed, 5584 insertions(+), 783 deletions(-)
150
create mode 100644 docs/system/arm/nuvoton.rst
151
create mode 100644 include/hw/arm/npcm7xx.h
152
create mode 100644 include/hw/mem/npcm7xx_mc.h
153
create mode 100644 include/hw/misc/npcm7xx_clk.h
154
create mode 100644 include/hw/misc/npcm7xx_gcr.h
155
create mode 100644 include/hw/net/xlnx-zynqmp-can.h
156
create mode 100644 include/hw/nvram/npcm7xx_otp.h
157
create mode 100644 include/hw/ssi/npcm7xx_fiu.h
158
create mode 100644 include/hw/timer/npcm7xx_timer.h
159
create mode 100644 tests/decode/succ_ident1.decode
160
create mode 100644 hw/arm/npcm7xx.c
161
create mode 100644 hw/arm/npcm7xx_boards.c
162
create mode 100644 hw/mem/npcm7xx_mc.c
163
create mode 100644 hw/misc/npcm7xx_clk.c
164
create mode 100644 hw/misc/npcm7xx_gcr.c
165
create mode 100644 hw/net/can/xlnx-zynqmp-can.c
166
create mode 100644 hw/nvram/npcm7xx_otp.c
167
create mode 100644 hw/ssi/npcm7xx_fiu.c
168
create mode 100644 hw/timer/npcm7xx_timer.c
169
delete mode 100644 target/arm/kvm32.c
170
create mode 100644 tests/qtest/xlnx-can-test.c
171
create mode 100644 pc-bios/npcm7xx_bootrom.bin
172
create mode 160000 roms/vbootrom
173
155
diff view generated by jsdifflib
1
From: Vikram Garhwal <fnu.vikram@xilinx.com>
1
From: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
2
2
3
Reviewed-by: Francisco Iglesias <francisco.iglesias@xilinx.com>
3
Cortex-A53 supports 40bits of address space. sbsa-ref's memory starts
4
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
4
above this limit.
5
Signed-off-by: Vikram Garhwal <fnu.vikram@xilinx.com>
5
6
Message-id: 1597278668-339715-5-git-send-email-fnu.vikram@xilinx.com
6
Signed-off-by: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Acked-by: Leif Lindholm <leif@nuviainc.com>
9
Message-id: 20210216150122.3830863-2-marcin.juszkiewicz@linaro.org
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
---
11
---
9
MAINTAINERS | 8 ++++++++
12
hw/arm/sbsa-ref.c | 1 -
10
1 file changed, 8 insertions(+)
13
1 file changed, 1 deletion(-)
11
14
12
diff --git a/MAINTAINERS b/MAINTAINERS
15
diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
13
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
14
--- a/MAINTAINERS
17
--- a/hw/arm/sbsa-ref.c
15
+++ b/MAINTAINERS
18
+++ b/hw/arm/sbsa-ref.c
16
@@ -XXX,XX +XXX,XX @@ F: hw/net/opencores_eth.c
19
@@ -XXX,XX +XXX,XX @@ static const int sbsa_ref_irqmap[] = {
17
20
};
18
Devices
21
19
-------
22
static const char * const valid_cpus[] = {
20
+Xilinx CAN
23
- ARM_CPU_TYPE_NAME("cortex-a53"),
21
+M: Vikram Garhwal <fnu.vikram@xilinx.com>
24
ARM_CPU_TYPE_NAME("cortex-a57"),
22
+M: Francisco Iglesias <francisco.iglesias@xilinx.com>
25
ARM_CPU_TYPE_NAME("cortex-a72"),
23
+S: Maintained
26
};
24
+F: hw/net/can/xlnx-*
25
+F: include/hw/net/xlnx-*
26
+F: tests/qtest/xlnx-can-test*
27
+
28
EDU
29
M: Jiri Slaby <jslaby@suse.cz>
30
S: Maintained
31
--
27
--
32
2.20.1
28
2.20.1
33
29
34
30
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
2
2
3
When booting directly into a kernel, bypassing the boot loader, the CPU and
3
Let add 'max' cpu while work goes on adding newer CPU types than
4
UART clocks are not set up correctly. This makes the system appear very
4
Cortex-A72. This allows us to check SVE etc support.
5
slow, and causes the initrd boot test to fail when optimization is off.
6
5
7
The UART clock must run at 24 MHz. The default 25 MHz reference clock
6
Signed-off-by: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
8
cannot achieve this, so switch to PLL2/2 @ 480 MHz, which works
7
Acked-by: Leif Lindholm <leif@nuviainc.com>
9
perfectly with the default /20 divider.
10
11
The CPU clock should run at 800 MHz, so switch it to PLL1/2. PLL1 runs
12
at 800 MHz by default, so we need to double the feedback divider as well
13
to make it run at 1600 MHz (so PLL1/2 runs at 800 MHz).
14
15
We don't bother checking for PLL lock because we know our emulated PLLs
16
lock instantly.
17
18
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
19
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Message-id: 20210216150122.3830863-3-marcin.juszkiewicz@linaro.org
20
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
21
Message-id: 20200911052101.2602693-13-hskinnemoen@google.com
22
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
23
---
11
---
24
include/hw/arm/npcm7xx.h | 1 +
12
hw/arm/sbsa-ref.c | 1 +
25
hw/arm/npcm7xx.c | 32 ++++++++++++++++++++++++++++++++
13
1 file changed, 1 insertion(+)
26
2 files changed, 33 insertions(+)
27
14
28
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
15
diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
29
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
30
--- a/include/hw/arm/npcm7xx.h
17
--- a/hw/arm/sbsa-ref.c
31
+++ b/include/hw/arm/npcm7xx.h
18
+++ b/hw/arm/sbsa-ref.c
32
@@ -XXX,XX +XXX,XX @@
19
@@ -XXX,XX +XXX,XX @@ static const int sbsa_ref_irqmap[] = {
33
#define NPCM7XX_SMP_LOADER_START (0xffff0000) /* Boot ROM */
20
static const char * const valid_cpus[] = {
34
#define NPCM7XX_SMP_BOOTREG_ADDR (0xf080013c) /* GCR.SCRPAD */
21
ARM_CPU_TYPE_NAME("cortex-a57"),
35
#define NPCM7XX_GIC_CPU_IF_ADDR (0xf03fe100) /* GIC within A9 */
22
ARM_CPU_TYPE_NAME("cortex-a72"),
36
+#define NPCM7XX_BOARD_SETUP_ADDR (0xffff1000) /* Boot ROM */
23
+ ARM_CPU_TYPE_NAME("max"),
37
38
typedef struct NPCM7xxMachine {
39
MachineState parent;
40
diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c
41
index XXXXXXX..XXXXXXX 100644
42
--- a/hw/arm/npcm7xx.c
43
+++ b/hw/arm/npcm7xx.c
44
@@ -XXX,XX +XXX,XX @@
45
#define NPCM7XX_ROM_BA (0xffff0000)
46
#define NPCM7XX_ROM_SZ (64 * KiB)
47
48
+/* Clock configuration values to be fixed up when bypassing bootloader */
49
+
50
+/* Run PLL1 at 1600 MHz */
51
+#define NPCM7XX_PLLCON1_FIXUP_VAL (0x00402101)
52
+/* Run the CPU from PLL1 and UART from PLL2 */
53
+#define NPCM7XX_CLKSEL_FIXUP_VAL (0x004aaba9)
54
+
55
/*
56
* Interrupt lines going into the GIC. This does not include internal Cortex-A9
57
* interrupts.
58
@@ -XXX,XX +XXX,XX @@ static const struct {
59
},
60
};
24
};
61
25
62
+static void npcm7xx_write_board_setup(ARMCPU *cpu,
26
static bool cpu_type_valid(const char *cpu)
63
+ const struct arm_boot_info *info)
64
+{
65
+ uint32_t board_setup[] = {
66
+ 0xe59f0010, /* ldr r0, clk_base_addr */
67
+ 0xe59f1010, /* ldr r1, pllcon1_value */
68
+ 0xe5801010, /* str r1, [r0, #16] */
69
+ 0xe59f100c, /* ldr r1, clksel_value */
70
+ 0xe5801004, /* str r1, [r0, #4] */
71
+ 0xe12fff1e, /* bx lr */
72
+ NPCM7XX_CLK_BA,
73
+ NPCM7XX_PLLCON1_FIXUP_VAL,
74
+ NPCM7XX_CLKSEL_FIXUP_VAL,
75
+ };
76
+ int i;
77
+
78
+ for (i = 0; i < ARRAY_SIZE(board_setup); i++) {
79
+ board_setup[i] = tswap32(board_setup[i]);
80
+ }
81
+ rom_add_blob_fixed("board-setup", board_setup, sizeof(board_setup),
82
+ info->board_setup_addr);
83
+}
84
+
85
static void npcm7xx_write_secondary_boot(ARMCPU *cpu,
86
const struct arm_boot_info *info)
87
{
88
@@ -XXX,XX +XXX,XX @@ static struct arm_boot_info npcm7xx_binfo = {
89
.gic_cpu_if_addr = NPCM7XX_GIC_CPU_IF_ADDR,
90
.write_secondary_boot = npcm7xx_write_secondary_boot,
91
.board_id = -1,
92
+ .board_setup_addr = NPCM7XX_BOARD_SETUP_ADDR,
93
+ .write_board_setup = npcm7xx_write_board_setup,
94
};
95
96
void npcm7xx_load_kernel(MachineState *machine, NPCM7xxState *soc)
97
--
27
--
98
2.20.1
28
2.20.1
99
29
100
30
diff view generated by jsdifflib
1
From: Vikram Garhwal <fnu.vikram@xilinx.com>
1
From: Rebecca Cran <rebecca@nuviainc.com>
2
2
3
The Xilinx ZynqMP CAN controller is developed based on SocketCAN, QEMU CAN bus
3
Add support for FEAT_SSBS. SSBS (Speculative Store Bypass Safe) is an
4
implementation. Bus connection and socketCAN connection for each CAN module
4
optional feature in ARMv8.0, and mandatory in ARMv8.5.
5
can be set through command lines.
6
5
7
Example for using single CAN:
6
Signed-off-by: Rebecca Cran <rebecca@nuviainc.com>
8
-object can-bus,id=canbus0 \
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
-machine xlnx-zcu102.canbus0=canbus0 \
8
Message-id: 20210216224543.16142-2-rebecca@nuviainc.com
10
-object can-host-socketcan,id=socketcan0,if=vcan0,canbus=canbus0
11
12
Example for connecting both CAN to same virtual CAN on host machine:
13
-object can-bus,id=canbus0 -object can-bus,id=canbus1 \
14
-machine xlnx-zcu102.canbus0=canbus0 \
15
-machine xlnx-zcu102.canbus1=canbus1 \
16
-object can-host-socketcan,id=socketcan0,if=vcan0,canbus=canbus0 \
17
-object can-host-socketcan,id=socketcan1,if=vcan0,canbus=canbus1
18
19
To create virtual CAN on the host machine, please check the QEMU CAN docs:
20
https://github.com/qemu/qemu/blob/master/docs/can.txt
21
22
Signed-off-by: Vikram Garhwal <fnu.vikram@xilinx.com>
23
Reviewed-by: Francisco Iglesias <francisco.iglesias@xilinx.com>
24
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
25
Message-id: 1597278668-339715-2-git-send-email-fnu.vikram@xilinx.com
26
[PMM: updated to meson build system]
27
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
28
---
10
---
29
include/hw/net/xlnx-zynqmp-can.h | 78 ++
11
target/arm/cpu.h | 15 ++++++++++++++-
30
hw/net/can/xlnx-zynqmp-can.c | 1165 ++++++++++++++++++++++++++++++
12
target/arm/internals.h | 6 ++++++
31
hw/net/can/meson.build | 1 +
13
target/arm/helper.c | 37 +++++++++++++++++++++++++++++++++++++
32
3 files changed, 1244 insertions(+)
14
target/arm/translate-a64.c | 12 ++++++++++++
33
create mode 100644 include/hw/net/xlnx-zynqmp-can.h
15
4 files changed, 69 insertions(+), 1 deletion(-)
34
create mode 100644 hw/net/can/xlnx-zynqmp-can.c
35
16
36
diff --git a/include/hw/net/xlnx-zynqmp-can.h b/include/hw/net/xlnx-zynqmp-can.h
17
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
37
new file mode 100644
18
index XXXXXXX..XXXXXXX 100644
38
index XXXXXXX..XXXXXXX
19
--- a/target/arm/cpu.h
39
--- /dev/null
20
+++ b/target/arm/cpu.h
40
+++ b/include/hw/net/xlnx-zynqmp-can.h
21
@@ -XXX,XX +XXX,XX @@ void pmu_init(ARMCPU *cpu);
41
@@ -XXX,XX +XXX,XX @@
22
#define SCTLR_TE (1U << 30) /* AArch32 only */
42
+/*
23
#define SCTLR_EnIB (1U << 30) /* v8.3, AArch64 only */
43
+ * QEMU model of the Xilinx ZynqMP CAN controller.
24
#define SCTLR_EnIA (1U << 31) /* v8.3, AArch64 only */
44
+ *
25
+#define SCTLR_DSSBS_32 (1U << 31) /* v8.5, AArch32 only */
45
+ * Copyright (c) 2020 Xilinx Inc.
26
#define SCTLR_BT0 (1ULL << 35) /* v8.5-BTI */
46
+ *
27
#define SCTLR_BT1 (1ULL << 36) /* v8.5-BTI */
47
+ * Written-by: Vikram Garhwal<fnu.vikram@xilinx.com>
28
#define SCTLR_ITFSB (1ULL << 37) /* v8.5-MemTag */
48
+ *
29
@@ -XXX,XX +XXX,XX @@ void pmu_init(ARMCPU *cpu);
49
+ * Based on QEMU CAN Device emulation implemented by Jin Yang, Deniz Eren and
30
#define SCTLR_TCF (3ULL << 40) /* v8.5-MemTag */
50
+ * Pavel Pisa.
31
#define SCTLR_ATA0 (1ULL << 42) /* v8.5-MemTag */
51
+ *
32
#define SCTLR_ATA (1ULL << 43) /* v8.5-MemTag */
52
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
33
-#define SCTLR_DSSBS (1ULL << 44) /* v8.5 */
53
+ * of this software and associated documentation files (the "Software"), to deal
34
+#define SCTLR_DSSBS_64 (1ULL << 44) /* v8.5, AArch64 only */
54
+ * in the Software without restriction, including without limitation the rights
35
55
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
36
#define CPTR_TCPAC (1U << 31)
56
+ * copies of the Software, and to permit persons to whom the Software is
37
#define CPTR_TTA (1U << 20)
57
+ * furnished to do so, subject to the following conditions:
38
@@ -XXX,XX +XXX,XX @@ void pmu_init(ARMCPU *cpu);
58
+ *
39
#define CPSR_IL (1U << 20)
59
+ * The above copyright notice and this permission notice shall be included in
40
#define CPSR_DIT (1U << 21)
60
+ * all copies or substantial portions of the Software.
41
#define CPSR_PAN (1U << 22)
61
+ *
42
+#define CPSR_SSBS (1U << 23)
62
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
43
#define CPSR_J (1U << 24)
63
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
44
#define CPSR_IT_0_1 (3U << 25)
64
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
45
#define CPSR_Q (1U << 27)
65
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
46
@@ -XXX,XX +XXX,XX @@ void pmu_init(ARMCPU *cpu);
66
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
47
#define PSTATE_A (1U << 8)
67
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
48
#define PSTATE_D (1U << 9)
68
+ * THE SOFTWARE.
49
#define PSTATE_BTYPE (3U << 10)
69
+ */
50
+#define PSTATE_SSBS (1U << 12)
70
+
51
#define PSTATE_IL (1U << 20)
71
+#ifndef XLNX_ZYNQMP_CAN_H
52
#define PSTATE_SS (1U << 21)
72
+#define XLNX_ZYNQMP_CAN_H
53
#define PSTATE_PAN (1U << 22)
73
+
54
@@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa32_dit(const ARMISARegisters *id)
74
+#include "hw/register.h"
55
return FIELD_EX32(id->id_pfr0, ID_PFR0, DIT) != 0;
75
+#include "net/can_emu.h"
56
}
76
+#include "net/can_host.h"
57
77
+#include "qemu/fifo32.h"
58
+static inline bool isar_feature_aa32_ssbs(const ARMISARegisters *id)
78
+#include "hw/ptimer.h"
79
+#include "hw/qdev-clock.h"
80
+
81
+#define TYPE_XLNX_ZYNQMP_CAN "xlnx.zynqmp-can"
82
+
83
+#define XLNX_ZYNQMP_CAN(obj) \
84
+ OBJECT_CHECK(XlnxZynqMPCANState, (obj), TYPE_XLNX_ZYNQMP_CAN)
85
+
86
+#define MAX_CAN_CTRLS 2
87
+#define XLNX_ZYNQMP_CAN_R_MAX (0x84 / 4)
88
+#define MAILBOX_CAPACITY 64
89
+#define CAN_TIMER_MAX 0XFFFFUL
90
+#define CAN_DEFAULT_CLOCK (24 * 1000 * 1000)
91
+
92
+/* Each CAN_FRAME will have 4 * 32bit size. */
93
+#define CAN_FRAME_SIZE 4
94
+#define RXFIFO_SIZE (MAILBOX_CAPACITY * CAN_FRAME_SIZE)
95
+
96
+typedef struct XlnxZynqMPCANState {
97
+ SysBusDevice parent_obj;
98
+ MemoryRegion iomem;
99
+
100
+ qemu_irq irq;
101
+
102
+ CanBusClientState bus_client;
103
+ CanBusState *canbus;
104
+
105
+ struct {
106
+ uint32_t ext_clk_freq;
107
+ } cfg;
108
+
109
+ RegisterInfo reg_info[XLNX_ZYNQMP_CAN_R_MAX];
110
+ uint32_t regs[XLNX_ZYNQMP_CAN_R_MAX];
111
+
112
+ Fifo32 rx_fifo;
113
+ Fifo32 tx_fifo;
114
+ Fifo32 txhpb_fifo;
115
+
116
+ ptimer_state *can_timer;
117
+} XlnxZynqMPCANState;
118
+
119
+#endif
120
diff --git a/hw/net/can/xlnx-zynqmp-can.c b/hw/net/can/xlnx-zynqmp-can.c
121
new file mode 100644
122
index XXXXXXX..XXXXXXX
123
--- /dev/null
124
+++ b/hw/net/can/xlnx-zynqmp-can.c
125
@@ -XXX,XX +XXX,XX @@
126
+/*
127
+ * QEMU model of the Xilinx ZynqMP CAN controller.
128
+ * This implementation is based on the following datasheet:
129
+ * https://www.xilinx.com/support/documentation/user_guides/ug1085-zynq-ultrascale-trm.pdf
130
+ *
131
+ * Copyright (c) 2020 Xilinx Inc.
132
+ *
133
+ * Written-by: Vikram Garhwal<fnu.vikram@xilinx.com>
134
+ *
135
+ * Based on QEMU CAN Device emulation implemented by Jin Yang, Deniz Eren and
136
+ * Pavel Pisa
137
+ *
138
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
139
+ * of this software and associated documentation files (the "Software"), to deal
140
+ * in the Software without restriction, including without limitation the rights
141
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
142
+ * copies of the Software, and to permit persons to whom the Software is
143
+ * furnished to do so, subject to the following conditions:
144
+ *
145
+ * The above copyright notice and this permission notice shall be included in
146
+ * all copies or substantial portions of the Software.
147
+ *
148
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
149
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
150
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
151
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
152
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
153
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
154
+ * THE SOFTWARE.
155
+ */
156
+
157
+#include "qemu/osdep.h"
158
+#include "hw/sysbus.h"
159
+#include "hw/register.h"
160
+#include "hw/irq.h"
161
+#include "qapi/error.h"
162
+#include "qemu/bitops.h"
163
+#include "qemu/log.h"
164
+#include "qemu/cutils.h"
165
+#include "sysemu/sysemu.h"
166
+#include "migration/vmstate.h"
167
+#include "hw/qdev-properties.h"
168
+#include "net/can_emu.h"
169
+#include "net/can_host.h"
170
+#include "qemu/event_notifier.h"
171
+#include "qom/object_interfaces.h"
172
+#include "hw/net/xlnx-zynqmp-can.h"
173
+
174
+#ifndef XLNX_ZYNQMP_CAN_ERR_DEBUG
175
+#define XLNX_ZYNQMP_CAN_ERR_DEBUG 0
176
+#endif
177
+
178
+#define DB_PRINT(dev, ...) do { \
179
+ if (XLNX_ZYNQMP_CAN_ERR_DEBUG) { \
180
+ g_autofree char *path = object_get_canonical_path(OBJECT(dev)); \
181
+ qemu_log("%s: %s", path, ## __VA_ARGS__); \
182
+ } \
183
+} while (0)
184
+
185
+#define MAX_DLC 8
186
+#undef ERROR
187
+
188
+REG32(SOFTWARE_RESET_REGISTER, 0x0)
189
+ FIELD(SOFTWARE_RESET_REGISTER, CEN, 1, 1)
190
+ FIELD(SOFTWARE_RESET_REGISTER, SRST, 0, 1)
191
+REG32(MODE_SELECT_REGISTER, 0x4)
192
+ FIELD(MODE_SELECT_REGISTER, SNOOP, 2, 1)
193
+ FIELD(MODE_SELECT_REGISTER, LBACK, 1, 1)
194
+ FIELD(MODE_SELECT_REGISTER, SLEEP, 0, 1)
195
+REG32(ARBITRATION_PHASE_BAUD_RATE_PRESCALER_REGISTER, 0x8)
196
+ FIELD(ARBITRATION_PHASE_BAUD_RATE_PRESCALER_REGISTER, BRP, 0, 8)
197
+REG32(ARBITRATION_PHASE_BIT_TIMING_REGISTER, 0xc)
198
+ FIELD(ARBITRATION_PHASE_BIT_TIMING_REGISTER, SJW, 7, 2)
199
+ FIELD(ARBITRATION_PHASE_BIT_TIMING_REGISTER, TS2, 4, 3)
200
+ FIELD(ARBITRATION_PHASE_BIT_TIMING_REGISTER, TS1, 0, 4)
201
+REG32(ERROR_COUNTER_REGISTER, 0x10)
202
+ FIELD(ERROR_COUNTER_REGISTER, REC, 8, 8)
203
+ FIELD(ERROR_COUNTER_REGISTER, TEC, 0, 8)
204
+REG32(ERROR_STATUS_REGISTER, 0x14)
205
+ FIELD(ERROR_STATUS_REGISTER, ACKER, 4, 1)
206
+ FIELD(ERROR_STATUS_REGISTER, BERR, 3, 1)
207
+ FIELD(ERROR_STATUS_REGISTER, STER, 2, 1)
208
+ FIELD(ERROR_STATUS_REGISTER, FMER, 1, 1)
209
+ FIELD(ERROR_STATUS_REGISTER, CRCER, 0, 1)
210
+REG32(STATUS_REGISTER, 0x18)
211
+ FIELD(STATUS_REGISTER, SNOOP, 12, 1)
212
+ FIELD(STATUS_REGISTER, ACFBSY, 11, 1)
213
+ FIELD(STATUS_REGISTER, TXFLL, 10, 1)
214
+ FIELD(STATUS_REGISTER, TXBFLL, 9, 1)
215
+ FIELD(STATUS_REGISTER, ESTAT, 7, 2)
216
+ FIELD(STATUS_REGISTER, ERRWRN, 6, 1)
217
+ FIELD(STATUS_REGISTER, BBSY, 5, 1)
218
+ FIELD(STATUS_REGISTER, BIDLE, 4, 1)
219
+ FIELD(STATUS_REGISTER, NORMAL, 3, 1)
220
+ FIELD(STATUS_REGISTER, SLEEP, 2, 1)
221
+ FIELD(STATUS_REGISTER, LBACK, 1, 1)
222
+ FIELD(STATUS_REGISTER, CONFIG, 0, 1)
223
+REG32(INTERRUPT_STATUS_REGISTER, 0x1c)
224
+ FIELD(INTERRUPT_STATUS_REGISTER, TXFEMP, 14, 1)
225
+ FIELD(INTERRUPT_STATUS_REGISTER, TXFWMEMP, 13, 1)
226
+ FIELD(INTERRUPT_STATUS_REGISTER, RXFWMFLL, 12, 1)
227
+ FIELD(INTERRUPT_STATUS_REGISTER, WKUP, 11, 1)
228
+ FIELD(INTERRUPT_STATUS_REGISTER, SLP, 10, 1)
229
+ FIELD(INTERRUPT_STATUS_REGISTER, BSOFF, 9, 1)
230
+ FIELD(INTERRUPT_STATUS_REGISTER, ERROR, 8, 1)
231
+ FIELD(INTERRUPT_STATUS_REGISTER, RXNEMP, 7, 1)
232
+ FIELD(INTERRUPT_STATUS_REGISTER, RXOFLW, 6, 1)
233
+ FIELD(INTERRUPT_STATUS_REGISTER, RXUFLW, 5, 1)
234
+ FIELD(INTERRUPT_STATUS_REGISTER, RXOK, 4, 1)
235
+ FIELD(INTERRUPT_STATUS_REGISTER, TXBFLL, 3, 1)
236
+ FIELD(INTERRUPT_STATUS_REGISTER, TXFLL, 2, 1)
237
+ FIELD(INTERRUPT_STATUS_REGISTER, TXOK, 1, 1)
238
+ FIELD(INTERRUPT_STATUS_REGISTER, ARBLST, 0, 1)
239
+REG32(INTERRUPT_ENABLE_REGISTER, 0x20)
240
+ FIELD(INTERRUPT_ENABLE_REGISTER, ETXFEMP, 14, 1)
241
+ FIELD(INTERRUPT_ENABLE_REGISTER, ETXFWMEMP, 13, 1)
242
+ FIELD(INTERRUPT_ENABLE_REGISTER, ERXFWMFLL, 12, 1)
243
+ FIELD(INTERRUPT_ENABLE_REGISTER, EWKUP, 11, 1)
244
+ FIELD(INTERRUPT_ENABLE_REGISTER, ESLP, 10, 1)
245
+ FIELD(INTERRUPT_ENABLE_REGISTER, EBSOFF, 9, 1)
246
+ FIELD(INTERRUPT_ENABLE_REGISTER, EERROR, 8, 1)
247
+ FIELD(INTERRUPT_ENABLE_REGISTER, ERXNEMP, 7, 1)
248
+ FIELD(INTERRUPT_ENABLE_REGISTER, ERXOFLW, 6, 1)
249
+ FIELD(INTERRUPT_ENABLE_REGISTER, ERXUFLW, 5, 1)
250
+ FIELD(INTERRUPT_ENABLE_REGISTER, ERXOK, 4, 1)
251
+ FIELD(INTERRUPT_ENABLE_REGISTER, ETXBFLL, 3, 1)
252
+ FIELD(INTERRUPT_ENABLE_REGISTER, ETXFLL, 2, 1)
253
+ FIELD(INTERRUPT_ENABLE_REGISTER, ETXOK, 1, 1)
254
+ FIELD(INTERRUPT_ENABLE_REGISTER, EARBLST, 0, 1)
255
+REG32(INTERRUPT_CLEAR_REGISTER, 0x24)
256
+ FIELD(INTERRUPT_CLEAR_REGISTER, CTXFEMP, 14, 1)
257
+ FIELD(INTERRUPT_CLEAR_REGISTER, CTXFWMEMP, 13, 1)
258
+ FIELD(INTERRUPT_CLEAR_REGISTER, CRXFWMFLL, 12, 1)
259
+ FIELD(INTERRUPT_CLEAR_REGISTER, CWKUP, 11, 1)
260
+ FIELD(INTERRUPT_CLEAR_REGISTER, CSLP, 10, 1)
261
+ FIELD(INTERRUPT_CLEAR_REGISTER, CBSOFF, 9, 1)
262
+ FIELD(INTERRUPT_CLEAR_REGISTER, CERROR, 8, 1)
263
+ FIELD(INTERRUPT_CLEAR_REGISTER, CRXNEMP, 7, 1)
264
+ FIELD(INTERRUPT_CLEAR_REGISTER, CRXOFLW, 6, 1)
265
+ FIELD(INTERRUPT_CLEAR_REGISTER, CRXUFLW, 5, 1)
266
+ FIELD(INTERRUPT_CLEAR_REGISTER, CRXOK, 4, 1)
267
+ FIELD(INTERRUPT_CLEAR_REGISTER, CTXBFLL, 3, 1)
268
+ FIELD(INTERRUPT_CLEAR_REGISTER, CTXFLL, 2, 1)
269
+ FIELD(INTERRUPT_CLEAR_REGISTER, CTXOK, 1, 1)
270
+ FIELD(INTERRUPT_CLEAR_REGISTER, CARBLST, 0, 1)
271
+REG32(TIMESTAMP_REGISTER, 0x28)
272
+ FIELD(TIMESTAMP_REGISTER, CTS, 0, 1)
273
+REG32(WIR, 0x2c)
274
+ FIELD(WIR, EW, 8, 8)
275
+ FIELD(WIR, FW, 0, 8)
276
+REG32(TXFIFO_ID, 0x30)
277
+ FIELD(TXFIFO_ID, IDH, 21, 11)
278
+ FIELD(TXFIFO_ID, SRRRTR, 20, 1)
279
+ FIELD(TXFIFO_ID, IDE, 19, 1)
280
+ FIELD(TXFIFO_ID, IDL, 1, 18)
281
+ FIELD(TXFIFO_ID, RTR, 0, 1)
282
+REG32(TXFIFO_DLC, 0x34)
283
+ FIELD(TXFIFO_DLC, DLC, 28, 4)
284
+REG32(TXFIFO_DATA1, 0x38)
285
+ FIELD(TXFIFO_DATA1, DB0, 24, 8)
286
+ FIELD(TXFIFO_DATA1, DB1, 16, 8)
287
+ FIELD(TXFIFO_DATA1, DB2, 8, 8)
288
+ FIELD(TXFIFO_DATA1, DB3, 0, 8)
289
+REG32(TXFIFO_DATA2, 0x3c)
290
+ FIELD(TXFIFO_DATA2, DB4, 24, 8)
291
+ FIELD(TXFIFO_DATA2, DB5, 16, 8)
292
+ FIELD(TXFIFO_DATA2, DB6, 8, 8)
293
+ FIELD(TXFIFO_DATA2, DB7, 0, 8)
294
+REG32(TXHPB_ID, 0x40)
295
+ FIELD(TXHPB_ID, IDH, 21, 11)
296
+ FIELD(TXHPB_ID, SRRRTR, 20, 1)
297
+ FIELD(TXHPB_ID, IDE, 19, 1)
298
+ FIELD(TXHPB_ID, IDL, 1, 18)
299
+ FIELD(TXHPB_ID, RTR, 0, 1)
300
+REG32(TXHPB_DLC, 0x44)
301
+ FIELD(TXHPB_DLC, DLC, 28, 4)
302
+REG32(TXHPB_DATA1, 0x48)
303
+ FIELD(TXHPB_DATA1, DB0, 24, 8)
304
+ FIELD(TXHPB_DATA1, DB1, 16, 8)
305
+ FIELD(TXHPB_DATA1, DB2, 8, 8)
306
+ FIELD(TXHPB_DATA1, DB3, 0, 8)
307
+REG32(TXHPB_DATA2, 0x4c)
308
+ FIELD(TXHPB_DATA2, DB4, 24, 8)
309
+ FIELD(TXHPB_DATA2, DB5, 16, 8)
310
+ FIELD(TXHPB_DATA2, DB6, 8, 8)
311
+ FIELD(TXHPB_DATA2, DB7, 0, 8)
312
+REG32(RXFIFO_ID, 0x50)
313
+ FIELD(RXFIFO_ID, IDH, 21, 11)
314
+ FIELD(RXFIFO_ID, SRRRTR, 20, 1)
315
+ FIELD(RXFIFO_ID, IDE, 19, 1)
316
+ FIELD(RXFIFO_ID, IDL, 1, 18)
317
+ FIELD(RXFIFO_ID, RTR, 0, 1)
318
+REG32(RXFIFO_DLC, 0x54)
319
+ FIELD(RXFIFO_DLC, DLC, 28, 4)
320
+ FIELD(RXFIFO_DLC, RXT, 0, 16)
321
+REG32(RXFIFO_DATA1, 0x58)
322
+ FIELD(RXFIFO_DATA1, DB0, 24, 8)
323
+ FIELD(RXFIFO_DATA1, DB1, 16, 8)
324
+ FIELD(RXFIFO_DATA1, DB2, 8, 8)
325
+ FIELD(RXFIFO_DATA1, DB3, 0, 8)
326
+REG32(RXFIFO_DATA2, 0x5c)
327
+ FIELD(RXFIFO_DATA2, DB4, 24, 8)
328
+ FIELD(RXFIFO_DATA2, DB5, 16, 8)
329
+ FIELD(RXFIFO_DATA2, DB6, 8, 8)
330
+ FIELD(RXFIFO_DATA2, DB7, 0, 8)
331
+REG32(AFR, 0x60)
332
+ FIELD(AFR, UAF4, 3, 1)
333
+ FIELD(AFR, UAF3, 2, 1)
334
+ FIELD(AFR, UAF2, 1, 1)
335
+ FIELD(AFR, UAF1, 0, 1)
336
+REG32(AFMR1, 0x64)
337
+ FIELD(AFMR1, AMIDH, 21, 11)
338
+ FIELD(AFMR1, AMSRR, 20, 1)
339
+ FIELD(AFMR1, AMIDE, 19, 1)
340
+ FIELD(AFMR1, AMIDL, 1, 18)
341
+ FIELD(AFMR1, AMRTR, 0, 1)
342
+REG32(AFIR1, 0x68)
343
+ FIELD(AFIR1, AIIDH, 21, 11)
344
+ FIELD(AFIR1, AISRR, 20, 1)
345
+ FIELD(AFIR1, AIIDE, 19, 1)
346
+ FIELD(AFIR1, AIIDL, 1, 18)
347
+ FIELD(AFIR1, AIRTR, 0, 1)
348
+REG32(AFMR2, 0x6c)
349
+ FIELD(AFMR2, AMIDH, 21, 11)
350
+ FIELD(AFMR2, AMSRR, 20, 1)
351
+ FIELD(AFMR2, AMIDE, 19, 1)
352
+ FIELD(AFMR2, AMIDL, 1, 18)
353
+ FIELD(AFMR2, AMRTR, 0, 1)
354
+REG32(AFIR2, 0x70)
355
+ FIELD(AFIR2, AIIDH, 21, 11)
356
+ FIELD(AFIR2, AISRR, 20, 1)
357
+ FIELD(AFIR2, AIIDE, 19, 1)
358
+ FIELD(AFIR2, AIIDL, 1, 18)
359
+ FIELD(AFIR2, AIRTR, 0, 1)
360
+REG32(AFMR3, 0x74)
361
+ FIELD(AFMR3, AMIDH, 21, 11)
362
+ FIELD(AFMR3, AMSRR, 20, 1)
363
+ FIELD(AFMR3, AMIDE, 19, 1)
364
+ FIELD(AFMR3, AMIDL, 1, 18)
365
+ FIELD(AFMR3, AMRTR, 0, 1)
366
+REG32(AFIR3, 0x78)
367
+ FIELD(AFIR3, AIIDH, 21, 11)
368
+ FIELD(AFIR3, AISRR, 20, 1)
369
+ FIELD(AFIR3, AIIDE, 19, 1)
370
+ FIELD(AFIR3, AIIDL, 1, 18)
371
+ FIELD(AFIR3, AIRTR, 0, 1)
372
+REG32(AFMR4, 0x7c)
373
+ FIELD(AFMR4, AMIDH, 21, 11)
374
+ FIELD(AFMR4, AMSRR, 20, 1)
375
+ FIELD(AFMR4, AMIDE, 19, 1)
376
+ FIELD(AFMR4, AMIDL, 1, 18)
377
+ FIELD(AFMR4, AMRTR, 0, 1)
378
+REG32(AFIR4, 0x80)
379
+ FIELD(AFIR4, AIIDH, 21, 11)
380
+ FIELD(AFIR4, AISRR, 20, 1)
381
+ FIELD(AFIR4, AIIDE, 19, 1)
382
+ FIELD(AFIR4, AIIDL, 1, 18)
383
+ FIELD(AFIR4, AIRTR, 0, 1)
384
+
385
+static void can_update_irq(XlnxZynqMPCANState *s)
386
+{
59
+{
387
+ uint32_t irq;
60
+ return FIELD_EX32(id->id_pfr2, ID_PFR2, SSBS) != 0;
388
+
389
+ /* Watermark register interrupts. */
390
+ if ((fifo32_num_free(&s->tx_fifo) / CAN_FRAME_SIZE) >
391
+ ARRAY_FIELD_EX32(s->regs, WIR, EW)) {
392
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, TXFWMEMP, 1);
393
+ }
394
+
395
+ if ((fifo32_num_used(&s->rx_fifo) / CAN_FRAME_SIZE) >
396
+ ARRAY_FIELD_EX32(s->regs, WIR, FW)) {
397
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, RXFWMFLL, 1);
398
+ }
399
+
400
+ /* RX Interrupts. */
401
+ if (fifo32_num_used(&s->rx_fifo) >= CAN_FRAME_SIZE) {
402
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, RXNEMP, 1);
403
+ }
404
+
405
+ /* TX interrupts. */
406
+ if (fifo32_is_empty(&s->tx_fifo)) {
407
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, TXFEMP, 1);
408
+ }
409
+
410
+ if (fifo32_is_full(&s->tx_fifo)) {
411
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, TXFLL, 1);
412
+ }
413
+
414
+ if (fifo32_is_full(&s->txhpb_fifo)) {
415
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, TXBFLL, 1);
416
+ }
417
+
418
+ irq = s->regs[R_INTERRUPT_STATUS_REGISTER];
419
+ irq &= s->regs[R_INTERRUPT_ENABLE_REGISTER];
420
+
421
+ qemu_set_irq(s->irq, irq);
422
+}
61
+}
423
+
62
+
424
+static void can_ier_post_write(RegisterInfo *reg, uint64_t val64)
63
/*
64
* 64-bit feature tests via id registers.
65
*/
66
@@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_dit(const ARMISARegisters *id)
67
return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, DIT) != 0;
68
}
69
70
+static inline bool isar_feature_aa64_ssbs(const ARMISARegisters *id)
425
+{
71
+{
426
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
72
+ return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, SSBS) != 0;
427
+
428
+ can_update_irq(s);
429
+}
73
+}
430
+
74
+
431
+static uint64_t can_icr_pre_write(RegisterInfo *reg, uint64_t val64)
75
/*
76
* Feature tests for "does this exist in either 32-bit or 64-bit?"
77
*/
78
diff --git a/target/arm/internals.h b/target/arm/internals.h
79
index XXXXXXX..XXXXXXX 100644
80
--- a/target/arm/internals.h
81
+++ b/target/arm/internals.h
82
@@ -XXX,XX +XXX,XX @@ static inline uint32_t aarch32_cpsr_valid_mask(uint64_t features,
83
if (isar_feature_aa32_dit(id)) {
84
valid |= CPSR_DIT;
85
}
86
+ if (isar_feature_aa32_ssbs(id)) {
87
+ valid |= CPSR_SSBS;
88
+ }
89
90
return valid;
91
}
92
@@ -XXX,XX +XXX,XX @@ static inline uint32_t aarch64_pstate_valid_mask(const ARMISARegisters *id)
93
if (isar_feature_aa64_dit(id)) {
94
valid |= PSTATE_DIT;
95
}
96
+ if (isar_feature_aa64_ssbs(id)) {
97
+ valid |= PSTATE_SSBS;
98
+ }
99
if (isar_feature_aa64_mte(id)) {
100
valid |= PSTATE_TCO;
101
}
102
diff --git a/target/arm/helper.c b/target/arm/helper.c
103
index XXXXXXX..XXXXXXX 100644
104
--- a/target/arm/helper.c
105
+++ b/target/arm/helper.c
106
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo dit_reginfo = {
107
.readfn = aa64_dit_read, .writefn = aa64_dit_write
108
};
109
110
+static uint64_t aa64_ssbs_read(CPUARMState *env, const ARMCPRegInfo *ri)
432
+{
111
+{
433
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
112
+ return env->pstate & PSTATE_SSBS;
434
+ uint32_t val = val64;
435
+
436
+ s->regs[R_INTERRUPT_STATUS_REGISTER] &= ~val;
437
+ can_update_irq(s);
438
+
439
+ return 0;
440
+}
113
+}
441
+
114
+
442
+static void can_config_reset(XlnxZynqMPCANState *s)
115
+static void aa64_ssbs_write(CPUARMState *env, const ARMCPRegInfo *ri,
116
+ uint64_t value)
443
+{
117
+{
444
+ /* Reset all the configuration registers. */
118
+ env->pstate = (env->pstate & ~PSTATE_SSBS) | (value & PSTATE_SSBS);
445
+ register_reset(&s->reg_info[R_SOFTWARE_RESET_REGISTER]);
446
+ register_reset(&s->reg_info[R_MODE_SELECT_REGISTER]);
447
+ register_reset(
448
+ &s->reg_info[R_ARBITRATION_PHASE_BAUD_RATE_PRESCALER_REGISTER]);
449
+ register_reset(&s->reg_info[R_ARBITRATION_PHASE_BIT_TIMING_REGISTER]);
450
+ register_reset(&s->reg_info[R_STATUS_REGISTER]);
451
+ register_reset(&s->reg_info[R_INTERRUPT_STATUS_REGISTER]);
452
+ register_reset(&s->reg_info[R_INTERRUPT_ENABLE_REGISTER]);
453
+ register_reset(&s->reg_info[R_INTERRUPT_CLEAR_REGISTER]);
454
+ register_reset(&s->reg_info[R_WIR]);
455
+}
119
+}
456
+
120
+
457
+static void can_config_mode(XlnxZynqMPCANState *s)
121
+static const ARMCPRegInfo ssbs_reginfo = {
458
+{
122
+ .name = "SSBS", .state = ARM_CP_STATE_AA64,
459
+ register_reset(&s->reg_info[R_ERROR_COUNTER_REGISTER]);
123
+ .opc0 = 3, .opc1 = 3, .crn = 4, .crm = 2, .opc2 = 6,
460
+ register_reset(&s->reg_info[R_ERROR_STATUS_REGISTER]);
124
+ .type = ARM_CP_NO_RAW, .access = PL0_RW,
125
+ .readfn = aa64_ssbs_read, .writefn = aa64_ssbs_write
126
+};
461
+
127
+
462
+ /* Put XlnxZynqMPCAN in configuration mode. */
128
static CPAccessResult aa64_cacheop_poc_access(CPUARMState *env,
463
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, CONFIG, 1);
129
const ARMCPRegInfo *ri,
464
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, WKUP, 0);
130
bool isread)
465
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, SLP, 0);
131
@@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu)
466
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, BSOFF, 0);
132
if (cpu_isar_feature(aa64_dit, cpu)) {
467
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, ERROR, 0);
133
define_one_arm_cp_reg(cpu, &dit_reginfo);
468
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, RXOFLW, 0);
134
}
469
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, RXOK, 0);
135
+ if (cpu_isar_feature(aa64_ssbs, cpu)) {
470
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, TXOK, 0);
136
+ define_one_arm_cp_reg(cpu, &ssbs_reginfo);
471
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, ARBLST, 0);
472
+
473
+ can_update_irq(s);
474
+}
475
+
476
+static void update_status_register_mode_bits(XlnxZynqMPCANState *s)
477
+{
478
+ bool sleep_status = ARRAY_FIELD_EX32(s->regs, STATUS_REGISTER, SLEEP);
479
+ bool sleep_mode = ARRAY_FIELD_EX32(s->regs, MODE_SELECT_REGISTER, SLEEP);
480
+ /* Wake up interrupt bit. */
481
+ bool wakeup_irq_val = sleep_status && (sleep_mode == 0);
482
+ /* Sleep interrupt bit. */
483
+ bool sleep_irq_val = sleep_mode && (sleep_status == 0);
484
+
485
+ /* Clear previous core mode status bits. */
486
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, LBACK, 0);
487
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, SLEEP, 0);
488
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, SNOOP, 0);
489
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, NORMAL, 0);
490
+
491
+ /* set current mode bit and generate irqs accordingly. */
492
+ if (ARRAY_FIELD_EX32(s->regs, MODE_SELECT_REGISTER, LBACK)) {
493
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, LBACK, 1);
494
+ } else if (ARRAY_FIELD_EX32(s->regs, MODE_SELECT_REGISTER, SLEEP)) {
495
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, SLEEP, 1);
496
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, SLP,
497
+ sleep_irq_val);
498
+ } else if (ARRAY_FIELD_EX32(s->regs, MODE_SELECT_REGISTER, SNOOP)) {
499
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, SNOOP, 1);
500
+ } else {
501
+ /*
502
+ * If all bits are zero then XlnxZynqMPCAN is set in normal mode.
503
+ */
504
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, NORMAL, 1);
505
+ /* Set wakeup interrupt bit. */
506
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, WKUP,
507
+ wakeup_irq_val);
508
+ }
137
+ }
509
+
138
510
+ can_update_irq(s);
139
if (arm_feature(env, ARM_FEATURE_EL2) && cpu_isar_feature(aa64_vh, cpu)) {
511
+}
140
define_arm_cp_regs(cpu, vhe_reginfo);
512
+
141
@@ -XXX,XX +XXX,XX @@ static void take_aarch32_exception(CPUARMState *env, int new_mode,
513
+static void can_exit_sleep_mode(XlnxZynqMPCANState *s)
142
env->uncached_cpsr &= ~(CPSR_IL | CPSR_J);
514
+{
143
env->daif |= mask;
515
+ ARRAY_FIELD_DP32(s->regs, MODE_SELECT_REGISTER, SLEEP, 0);
144
516
+ update_status_register_mode_bits(s);
145
+ if (cpu_isar_feature(aa32_ssbs, env_archcpu(env))) {
517
+}
146
+ if (env->cp15.sctlr_el[new_el] & SCTLR_DSSBS_32) {
518
+
147
+ env->uncached_cpsr |= CPSR_SSBS;
519
+static void generate_frame(qemu_can_frame *frame, uint32_t *data)
148
+ } else {
520
+{
149
+ env->uncached_cpsr &= ~CPSR_SSBS;
521
+ frame->can_id = data[0];
522
+ frame->can_dlc = FIELD_EX32(data[1], TXFIFO_DLC, DLC);
523
+
524
+ frame->data[0] = FIELD_EX32(data[2], TXFIFO_DATA1, DB3);
525
+ frame->data[1] = FIELD_EX32(data[2], TXFIFO_DATA1, DB2);
526
+ frame->data[2] = FIELD_EX32(data[2], TXFIFO_DATA1, DB1);
527
+ frame->data[3] = FIELD_EX32(data[2], TXFIFO_DATA1, DB0);
528
+
529
+ frame->data[4] = FIELD_EX32(data[3], TXFIFO_DATA2, DB7);
530
+ frame->data[5] = FIELD_EX32(data[3], TXFIFO_DATA2, DB6);
531
+ frame->data[6] = FIELD_EX32(data[3], TXFIFO_DATA2, DB5);
532
+ frame->data[7] = FIELD_EX32(data[3], TXFIFO_DATA2, DB4);
533
+}
534
+
535
+static bool tx_ready_check(XlnxZynqMPCANState *s)
536
+{
537
+ if (ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, SRST)) {
538
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
539
+
540
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Attempting to transfer data while"
541
+ " data while controller is in reset mode.\n",
542
+ path);
543
+ return false;
544
+ }
545
+
546
+ if (ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, CEN) == 0) {
547
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
548
+
549
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Attempting to transfer"
550
+ " data while controller is in configuration mode. Reset"
551
+ " the core so operations can start fresh.\n",
552
+ path);
553
+ return false;
554
+ }
555
+
556
+ if (ARRAY_FIELD_EX32(s->regs, STATUS_REGISTER, SNOOP)) {
557
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
558
+
559
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Attempting to transfer"
560
+ " data while controller is in SNOOP MODE.\n",
561
+ path);
562
+ return false;
563
+ }
564
+
565
+ return true;
566
+}
567
+
568
+static void transfer_fifo(XlnxZynqMPCANState *s, Fifo32 *fifo)
569
+{
570
+ qemu_can_frame frame;
571
+ uint32_t data[CAN_FRAME_SIZE];
572
+ int i;
573
+ bool can_tx = tx_ready_check(s);
574
+
575
+ if (can_tx) {
576
+ while (!fifo32_is_empty(fifo)) {
577
+ for (i = 0; i < CAN_FRAME_SIZE; i++) {
578
+ data[i] = fifo32_pop(fifo);
579
+ }
580
+
581
+ if (ARRAY_FIELD_EX32(s->regs, STATUS_REGISTER, LBACK)) {
582
+ /*
583
+ * Controller is in loopback. In Loopback mode, the CAN core
584
+ * transmits a recessive bitstream on to the XlnxZynqMPCAN Bus.
585
+ * Any message transmitted is looped back to the RX line and
586
+ * acknowledged. The XlnxZynqMPCAN core receives any message
587
+ * that it transmits.
588
+ */
589
+ if (fifo32_is_full(&s->rx_fifo)) {
590
+ DB_PRINT(s, "Loopback: RX FIFO is full."
591
+ " TX FIFO will be flushed.\n");
592
+
593
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER,
594
+ RXOFLW, 1);
595
+ } else {
596
+ for (i = 0; i < CAN_FRAME_SIZE; i++) {
597
+ fifo32_push(&s->rx_fifo, data[i]);
598
+ }
599
+
600
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER,
601
+ RXOK, 1);
602
+ }
603
+ } else {
604
+ /* Normal mode Tx. */
605
+ generate_frame(&frame, data);
606
+
607
+ can_bus_client_send(&s->bus_client, &frame, 1);
608
+ }
609
+ }
610
+
611
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, TXOK, 1);
612
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, TXBFLL, 0);
613
+
614
+ if (ARRAY_FIELD_EX32(s->regs, STATUS_REGISTER, SLEEP)) {
615
+ can_exit_sleep_mode(s);
616
+ }
617
+ } else {
618
+ DB_PRINT(s, "Not enabled for data transfer.\n");
619
+ }
620
+
621
+ can_update_irq(s);
622
+}
623
+
624
+static uint64_t can_srr_pre_write(RegisterInfo *reg, uint64_t val64)
625
+{
626
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
627
+ uint32_t val = val64;
628
+
629
+ ARRAY_FIELD_DP32(s->regs, SOFTWARE_RESET_REGISTER, CEN,
630
+ FIELD_EX32(val, SOFTWARE_RESET_REGISTER, CEN));
631
+
632
+ if (FIELD_EX32(val, SOFTWARE_RESET_REGISTER, SRST)) {
633
+ DB_PRINT(s, "Resetting controller.\n");
634
+
635
+ /* First, core will do software reset then will enter in config mode. */
636
+ can_config_reset(s);
637
+ }
638
+
639
+ if (ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, CEN) == 0) {
640
+ can_config_mode(s);
641
+ } else {
642
+ /*
643
+ * Leave config mode. Now XlnxZynqMPCAN core will enter normal,
644
+ * sleep, snoop or loopback mode depending upon LBACK, SLEEP, SNOOP
645
+ * register states.
646
+ */
647
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, CONFIG, 0);
648
+
649
+ ptimer_transaction_begin(s->can_timer);
650
+ ptimer_set_count(s->can_timer, 0);
651
+ ptimer_transaction_commit(s->can_timer);
652
+
653
+ /* XlnxZynqMPCAN is out of config mode. It will send pending data. */
654
+ transfer_fifo(s, &s->txhpb_fifo);
655
+ transfer_fifo(s, &s->tx_fifo);
656
+ }
657
+
658
+ update_status_register_mode_bits(s);
659
+
660
+ return s->regs[R_SOFTWARE_RESET_REGISTER];
661
+}
662
+
663
+static uint64_t can_msr_pre_write(RegisterInfo *reg, uint64_t val64)
664
+{
665
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
666
+ uint32_t val = val64;
667
+ uint8_t multi_mode;
668
+
669
+ /*
670
+ * Multiple mode set check. This is done to make sure user doesn't set
671
+ * multiple modes.
672
+ */
673
+ multi_mode = FIELD_EX32(val, MODE_SELECT_REGISTER, LBACK) +
674
+ FIELD_EX32(val, MODE_SELECT_REGISTER, SLEEP) +
675
+ FIELD_EX32(val, MODE_SELECT_REGISTER, SNOOP);
676
+
677
+ if (multi_mode > 1) {
678
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
679
+
680
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Attempting to config"
681
+ " several modes simultaneously. One mode will be selected"
682
+ " according to their priority: LBACK > SLEEP > SNOOP.\n",
683
+ path);
684
+ }
685
+
686
+ if (ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, CEN) == 0) {
687
+ /* We are in configuration mode, any mode can be selected. */
688
+ s->regs[R_MODE_SELECT_REGISTER] = val;
689
+ } else {
690
+ bool sleep_mode_bit = FIELD_EX32(val, MODE_SELECT_REGISTER, SLEEP);
691
+
692
+ ARRAY_FIELD_DP32(s->regs, MODE_SELECT_REGISTER, SLEEP, sleep_mode_bit);
693
+
694
+ if (FIELD_EX32(val, MODE_SELECT_REGISTER, LBACK)) {
695
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
696
+
697
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Attempting to set"
698
+ " LBACK mode without setting CEN bit as 0.\n",
699
+ path);
700
+ } else if (FIELD_EX32(val, MODE_SELECT_REGISTER, SNOOP)) {
701
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
702
+
703
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Attempting to set"
704
+ " SNOOP mode without setting CEN bit as 0.\n",
705
+ path);
706
+ }
707
+
708
+ update_status_register_mode_bits(s);
709
+ }
710
+
711
+ return s->regs[R_MODE_SELECT_REGISTER];
712
+}
713
+
714
+static uint64_t can_brpr_pre_write(RegisterInfo *reg, uint64_t val64)
715
+{
716
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
717
+ uint32_t val = val64;
718
+
719
+ /* Only allow writes when in config mode. */
720
+ if (ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, CEN)) {
721
+ val = s->regs[R_ARBITRATION_PHASE_BAUD_RATE_PRESCALER_REGISTER];
722
+ }
723
+
724
+ return val;
725
+}
726
+
727
+static uint64_t can_btr_pre_write(RegisterInfo *reg, uint64_t val64)
728
+{
729
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
730
+ uint32_t val = val64;
731
+
732
+ /* Only allow writes when in config mode. */
733
+ if (ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, CEN)) {
734
+ val = s->regs[R_ARBITRATION_PHASE_BIT_TIMING_REGISTER];
735
+ }
736
+
737
+ return val;
738
+}
739
+
740
+static uint64_t can_tcr_pre_write(RegisterInfo *reg, uint64_t val64)
741
+{
742
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
743
+ uint32_t val = val64;
744
+
745
+ if (FIELD_EX32(val, TIMESTAMP_REGISTER, CTS)) {
746
+ ptimer_transaction_begin(s->can_timer);
747
+ ptimer_set_count(s->can_timer, 0);
748
+ ptimer_transaction_commit(s->can_timer);
749
+ }
750
+
751
+ return 0;
752
+}
753
+
754
+static void update_rx_fifo(XlnxZynqMPCANState *s, const qemu_can_frame *frame)
755
+{
756
+ bool filter_pass = false;
757
+ uint16_t timestamp = 0;
758
+
759
+ /* If no filter is enabled. Message will be stored in FIFO. */
760
+ if (!((ARRAY_FIELD_EX32(s->regs, AFR, UAF1)) |
761
+ (ARRAY_FIELD_EX32(s->regs, AFR, UAF2)) |
762
+ (ARRAY_FIELD_EX32(s->regs, AFR, UAF3)) |
763
+ (ARRAY_FIELD_EX32(s->regs, AFR, UAF4)))) {
764
+ filter_pass = true;
765
+ }
766
+
767
+ /*
768
+ * Messages that pass any of the acceptance filters will be stored in
769
+ * the RX FIFO.
770
+ */
771
+ if (ARRAY_FIELD_EX32(s->regs, AFR, UAF1)) {
772
+ uint32_t id_masked = s->regs[R_AFMR1] & frame->can_id;
773
+ uint32_t filter_id_masked = s->regs[R_AFMR1] & s->regs[R_AFIR1];
774
+
775
+ if (filter_id_masked == id_masked) {
776
+ filter_pass = true;
777
+ }
150
+ }
778
+ }
151
+ }
779
+
152
+
780
+ if (ARRAY_FIELD_EX32(s->regs, AFR, UAF2)) {
153
if (new_mode == ARM_CPU_MODE_HYP) {
781
+ uint32_t id_masked = s->regs[R_AFMR2] & frame->can_id;
154
env->thumb = (env->cp15.sctlr_el[2] & SCTLR_TE) != 0;
782
+ uint32_t filter_id_masked = s->regs[R_AFMR2] & s->regs[R_AFIR2];
155
env->elr_el[2] = env->regs[15];
783
+
156
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_do_interrupt_aarch64(CPUState *cs)
784
+ if (filter_id_masked == id_masked) {
157
new_mode |= PSTATE_TCO;
785
+ filter_pass = true;
158
}
159
160
+ if (cpu_isar_feature(aa64_ssbs, cpu)) {
161
+ if (env->cp15.sctlr_el[new_el] & SCTLR_DSSBS_64) {
162
+ new_mode |= PSTATE_SSBS;
163
+ } else {
164
+ new_mode &= ~PSTATE_SSBS;
786
+ }
165
+ }
787
+ }
166
+ }
788
+
167
+
789
+ if (ARRAY_FIELD_EX32(s->regs, AFR, UAF3)) {
168
pstate_write(env, PSTATE_DAIF | new_mode);
790
+ uint32_t id_masked = s->regs[R_AFMR3] & frame->can_id;
169
env->aarch64 = 1;
791
+ uint32_t filter_id_masked = s->regs[R_AFMR3] & s->regs[R_AFIR3];
170
aarch64_restore_sp(env, new_el);
171
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
172
index XXXXXXX..XXXXXXX 100644
173
--- a/target/arm/translate-a64.c
174
+++ b/target/arm/translate-a64.c
175
@@ -XXX,XX +XXX,XX @@ static void handle_msr_i(DisasContext *s, uint32_t insn,
176
tcg_temp_free_i32(t1);
177
break;
178
179
+ case 0x19: /* SSBS */
180
+ if (!dc_isar_feature(aa64_ssbs, s)) {
181
+ goto do_unallocated;
182
+ }
183
+ if (crm & 1) {
184
+ set_pstate_bits(PSTATE_SSBS);
185
+ } else {
186
+ clear_pstate_bits(PSTATE_SSBS);
187
+ }
188
+ /* Don't need to rebuild hflags since SSBS is a nop */
189
+ break;
792
+
190
+
793
+ if (filter_id_masked == id_masked) {
191
case 0x1a: /* DIT */
794
+ filter_pass = true;
192
if (!dc_isar_feature(aa64_dit, s)) {
795
+ }
193
goto do_unallocated;
796
+ }
797
+
798
+ if (ARRAY_FIELD_EX32(s->regs, AFR, UAF4)) {
799
+ uint32_t id_masked = s->regs[R_AFMR4] & frame->can_id;
800
+ uint32_t filter_id_masked = s->regs[R_AFMR4] & s->regs[R_AFIR4];
801
+
802
+ if (filter_id_masked == id_masked) {
803
+ filter_pass = true;
804
+ }
805
+ }
806
+
807
+ /* Store the message in fifo if it passed through any of the filters. */
808
+ if (filter_pass && frame->can_dlc <= MAX_DLC) {
809
+
810
+ if (fifo32_is_full(&s->rx_fifo)) {
811
+ DB_PRINT(s, "RX FIFO is full.\n");
812
+
813
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, RXOFLW, 1);
814
+ } else {
815
+ timestamp = CAN_TIMER_MAX - ptimer_get_count(s->can_timer);
816
+
817
+ fifo32_push(&s->rx_fifo, frame->can_id);
818
+
819
+ fifo32_push(&s->rx_fifo, deposit32(0, R_RXFIFO_DLC_DLC_SHIFT,
820
+ R_RXFIFO_DLC_DLC_LENGTH,
821
+ frame->can_dlc) |
822
+ deposit32(0, R_RXFIFO_DLC_RXT_SHIFT,
823
+ R_RXFIFO_DLC_RXT_LENGTH,
824
+ timestamp));
825
+
826
+ /* First 32 bit of the data. */
827
+ fifo32_push(&s->rx_fifo, deposit32(0, R_TXFIFO_DATA1_DB3_SHIFT,
828
+ R_TXFIFO_DATA1_DB3_LENGTH,
829
+ frame->data[0]) |
830
+ deposit32(0, R_TXFIFO_DATA1_DB2_SHIFT,
831
+ R_TXFIFO_DATA1_DB2_LENGTH,
832
+ frame->data[1]) |
833
+ deposit32(0, R_TXFIFO_DATA1_DB1_SHIFT,
834
+ R_TXFIFO_DATA1_DB1_LENGTH,
835
+ frame->data[2]) |
836
+ deposit32(0, R_TXFIFO_DATA1_DB0_SHIFT,
837
+ R_TXFIFO_DATA1_DB0_LENGTH,
838
+ frame->data[3]));
839
+ /* Last 32 bit of the data. */
840
+ fifo32_push(&s->rx_fifo, deposit32(0, R_TXFIFO_DATA2_DB7_SHIFT,
841
+ R_TXFIFO_DATA2_DB7_LENGTH,
842
+ frame->data[4]) |
843
+ deposit32(0, R_TXFIFO_DATA2_DB6_SHIFT,
844
+ R_TXFIFO_DATA2_DB6_LENGTH,
845
+ frame->data[5]) |
846
+ deposit32(0, R_TXFIFO_DATA2_DB5_SHIFT,
847
+ R_TXFIFO_DATA2_DB5_LENGTH,
848
+ frame->data[6]) |
849
+ deposit32(0, R_TXFIFO_DATA2_DB4_SHIFT,
850
+ R_TXFIFO_DATA2_DB4_LENGTH,
851
+ frame->data[7]));
852
+
853
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, RXOK, 1);
854
+ }
855
+
856
+ can_update_irq(s);
857
+ } else {
858
+ DB_PRINT(s, "Message didn't pass through any filter or dlc"
859
+ " is not in range.\n");
860
+ }
861
+}
862
+
863
+static uint64_t can_rxfifo_pre_read(RegisterInfo *reg, uint64_t val64)
864
+{
865
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
866
+ uint32_t r = 0;
867
+
868
+ if (!fifo32_is_empty(&s->rx_fifo)) {
869
+ r = fifo32_pop(&s->rx_fifo);
870
+ } else {
871
+ DB_PRINT(s, "No message in RXFIFO.\n");
872
+
873
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, RXUFLW, 1);
874
+ }
875
+
876
+ can_update_irq(s);
877
+ return r;
878
+}
879
+
880
+static void can_filter_enable_post_write(RegisterInfo *reg, uint64_t val64)
881
+{
882
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
883
+
884
+ if (ARRAY_FIELD_EX32(s->regs, AFR, UAF1) &&
885
+ ARRAY_FIELD_EX32(s->regs, AFR, UAF2) &&
886
+ ARRAY_FIELD_EX32(s->regs, AFR, UAF3) &&
887
+ ARRAY_FIELD_EX32(s->regs, AFR, UAF4)) {
888
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, ACFBSY, 1);
889
+ } else {
890
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, ACFBSY, 0);
891
+ }
892
+}
893
+
894
+static uint64_t can_filter_mask_pre_write(RegisterInfo *reg, uint64_t val64)
895
+{
896
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
897
+ uint32_t reg_idx = (reg->access->addr) / 4;
898
+ uint32_t val = val64;
899
+ uint32_t filter_number = (reg_idx - R_AFMR1) / 2;
900
+
901
+ /* modify an acceptance filter, the corresponding UAF bit should be '0.' */
902
+ if (!(s->regs[R_AFR] & (1 << filter_number))) {
903
+ s->regs[reg_idx] = val;
904
+ } else {
905
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
906
+
907
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Acceptance filter %d"
908
+ " mask is not set as corresponding UAF bit is not 0.\n",
909
+ path, filter_number + 1);
910
+ }
911
+
912
+ return s->regs[reg_idx];
913
+}
914
+
915
+static uint64_t can_filter_id_pre_write(RegisterInfo *reg, uint64_t val64)
916
+{
917
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
918
+ uint32_t reg_idx = (reg->access->addr) / 4;
919
+ uint32_t val = val64;
920
+ uint32_t filter_number = (reg_idx - R_AFIR1) / 2;
921
+
922
+ if (!(s->regs[R_AFR] & (1 << filter_number))) {
923
+ s->regs[reg_idx] = val;
924
+ } else {
925
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
926
+
927
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Acceptance filter %d"
928
+ " id is not set as corresponding UAF bit is not 0.\n",
929
+ path, filter_number + 1);
930
+ }
931
+
932
+ return s->regs[reg_idx];
933
+}
934
+
935
+static void can_tx_post_write(RegisterInfo *reg, uint64_t val64)
936
+{
937
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
938
+ uint32_t val = val64;
939
+
940
+ bool is_txhpb = reg->access->addr > A_TXFIFO_DATA2;
941
+
942
+ bool initiate_transfer = (reg->access->addr == A_TXFIFO_DATA2) ||
943
+ (reg->access->addr == A_TXHPB_DATA2);
944
+
945
+ Fifo32 *f = is_txhpb ? &s->txhpb_fifo : &s->tx_fifo;
946
+
947
+ DB_PRINT(s, "TX FIFO write.\n");
948
+
949
+ if (!fifo32_is_full(f)) {
950
+ fifo32_push(f, val);
951
+ } else {
952
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
953
+
954
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: TX FIFO is full.\n", path);
955
+ }
956
+
957
+ /* Initiate the message send if TX register is written. */
958
+ if (initiate_transfer &&
959
+ ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, CEN)) {
960
+ transfer_fifo(s, f);
961
+ }
962
+
963
+ can_update_irq(s);
964
+}
965
+
966
+static const RegisterAccessInfo can_regs_info[] = {
967
+ { .name = "SOFTWARE_RESET_REGISTER",
968
+ .addr = A_SOFTWARE_RESET_REGISTER,
969
+ .rsvd = 0xfffffffc,
970
+ .pre_write = can_srr_pre_write,
971
+ },{ .name = "MODE_SELECT_REGISTER",
972
+ .addr = A_MODE_SELECT_REGISTER,
973
+ .rsvd = 0xfffffff8,
974
+ .pre_write = can_msr_pre_write,
975
+ },{ .name = "ARBITRATION_PHASE_BAUD_RATE_PRESCALER_REGISTER",
976
+ .addr = A_ARBITRATION_PHASE_BAUD_RATE_PRESCALER_REGISTER,
977
+ .rsvd = 0xffffff00,
978
+ .pre_write = can_brpr_pre_write,
979
+ },{ .name = "ARBITRATION_PHASE_BIT_TIMING_REGISTER",
980
+ .addr = A_ARBITRATION_PHASE_BIT_TIMING_REGISTER,
981
+ .rsvd = 0xfffffe00,
982
+ .pre_write = can_btr_pre_write,
983
+ },{ .name = "ERROR_COUNTER_REGISTER",
984
+ .addr = A_ERROR_COUNTER_REGISTER,
985
+ .rsvd = 0xffff0000,
986
+ .ro = 0xffffffff,
987
+ },{ .name = "ERROR_STATUS_REGISTER",
988
+ .addr = A_ERROR_STATUS_REGISTER,
989
+ .rsvd = 0xffffffe0,
990
+ .w1c = 0x1f,
991
+ },{ .name = "STATUS_REGISTER", .addr = A_STATUS_REGISTER,
992
+ .reset = 0x1,
993
+ .rsvd = 0xffffe000,
994
+ .ro = 0x1fff,
995
+ },{ .name = "INTERRUPT_STATUS_REGISTER",
996
+ .addr = A_INTERRUPT_STATUS_REGISTER,
997
+ .reset = 0x6000,
998
+ .rsvd = 0xffff8000,
999
+ .ro = 0x7fff,
1000
+ },{ .name = "INTERRUPT_ENABLE_REGISTER",
1001
+ .addr = A_INTERRUPT_ENABLE_REGISTER,
1002
+ .rsvd = 0xffff8000,
1003
+ .post_write = can_ier_post_write,
1004
+ },{ .name = "INTERRUPT_CLEAR_REGISTER",
1005
+ .addr = A_INTERRUPT_CLEAR_REGISTER,
1006
+ .rsvd = 0xffff8000,
1007
+ .pre_write = can_icr_pre_write,
1008
+ },{ .name = "TIMESTAMP_REGISTER",
1009
+ .addr = A_TIMESTAMP_REGISTER,
1010
+ .rsvd = 0xfffffffe,
1011
+ .pre_write = can_tcr_pre_write,
1012
+ },{ .name = "WIR", .addr = A_WIR,
1013
+ .reset = 0x3f3f,
1014
+ .rsvd = 0xffff0000,
1015
+ },{ .name = "TXFIFO_ID", .addr = A_TXFIFO_ID,
1016
+ .post_write = can_tx_post_write,
1017
+ },{ .name = "TXFIFO_DLC", .addr = A_TXFIFO_DLC,
1018
+ .rsvd = 0xfffffff,
1019
+ .post_write = can_tx_post_write,
1020
+ },{ .name = "TXFIFO_DATA1", .addr = A_TXFIFO_DATA1,
1021
+ .post_write = can_tx_post_write,
1022
+ },{ .name = "TXFIFO_DATA2", .addr = A_TXFIFO_DATA2,
1023
+ .post_write = can_tx_post_write,
1024
+ },{ .name = "TXHPB_ID", .addr = A_TXHPB_ID,
1025
+ .post_write = can_tx_post_write,
1026
+ },{ .name = "TXHPB_DLC", .addr = A_TXHPB_DLC,
1027
+ .rsvd = 0xfffffff,
1028
+ .post_write = can_tx_post_write,
1029
+ },{ .name = "TXHPB_DATA1", .addr = A_TXHPB_DATA1,
1030
+ .post_write = can_tx_post_write,
1031
+ },{ .name = "TXHPB_DATA2", .addr = A_TXHPB_DATA2,
1032
+ .post_write = can_tx_post_write,
1033
+ },{ .name = "RXFIFO_ID", .addr = A_RXFIFO_ID,
1034
+ .ro = 0xffffffff,
1035
+ .post_read = can_rxfifo_pre_read,
1036
+ },{ .name = "RXFIFO_DLC", .addr = A_RXFIFO_DLC,
1037
+ .rsvd = 0xfff0000,
1038
+ .post_read = can_rxfifo_pre_read,
1039
+ },{ .name = "RXFIFO_DATA1", .addr = A_RXFIFO_DATA1,
1040
+ .post_read = can_rxfifo_pre_read,
1041
+ },{ .name = "RXFIFO_DATA2", .addr = A_RXFIFO_DATA2,
1042
+ .post_read = can_rxfifo_pre_read,
1043
+ },{ .name = "AFR", .addr = A_AFR,
1044
+ .rsvd = 0xfffffff0,
1045
+ .post_write = can_filter_enable_post_write,
1046
+ },{ .name = "AFMR1", .addr = A_AFMR1,
1047
+ .pre_write = can_filter_mask_pre_write,
1048
+ },{ .name = "AFIR1", .addr = A_AFIR1,
1049
+ .pre_write = can_filter_id_pre_write,
1050
+ },{ .name = "AFMR2", .addr = A_AFMR2,
1051
+ .pre_write = can_filter_mask_pre_write,
1052
+ },{ .name = "AFIR2", .addr = A_AFIR2,
1053
+ .pre_write = can_filter_id_pre_write,
1054
+ },{ .name = "AFMR3", .addr = A_AFMR3,
1055
+ .pre_write = can_filter_mask_pre_write,
1056
+ },{ .name = "AFIR3", .addr = A_AFIR3,
1057
+ .pre_write = can_filter_id_pre_write,
1058
+ },{ .name = "AFMR4", .addr = A_AFMR4,
1059
+ .pre_write = can_filter_mask_pre_write,
1060
+ },{ .name = "AFIR4", .addr = A_AFIR4,
1061
+ .pre_write = can_filter_id_pre_write,
1062
+ }
1063
+};
1064
+
1065
+static void xlnx_zynqmp_can_ptimer_cb(void *opaque)
1066
+{
1067
+ /* No action required on the timer rollover. */
1068
+}
1069
+
1070
+static const MemoryRegionOps can_ops = {
1071
+ .read = register_read_memory,
1072
+ .write = register_write_memory,
1073
+ .endianness = DEVICE_LITTLE_ENDIAN,
1074
+ .valid = {
1075
+ .min_access_size = 4,
1076
+ .max_access_size = 4,
1077
+ },
1078
+};
1079
+
1080
+static void xlnx_zynqmp_can_reset_init(Object *obj, ResetType type)
1081
+{
1082
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(obj);
1083
+ unsigned int i;
1084
+
1085
+ for (i = R_RXFIFO_ID; i < ARRAY_SIZE(s->reg_info); ++i) {
1086
+ register_reset(&s->reg_info[i]);
1087
+ }
1088
+
1089
+ ptimer_transaction_begin(s->can_timer);
1090
+ ptimer_set_count(s->can_timer, 0);
1091
+ ptimer_transaction_commit(s->can_timer);
1092
+}
1093
+
1094
+static void xlnx_zynqmp_can_reset_hold(Object *obj)
1095
+{
1096
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(obj);
1097
+ unsigned int i;
1098
+
1099
+ for (i = 0; i < R_RXFIFO_ID; ++i) {
1100
+ register_reset(&s->reg_info[i]);
1101
+ }
1102
+
1103
+ /*
1104
+ * Reset FIFOs when CAN model is reset. This will clear the fifo writes
1105
+ * done by post_write which gets called from register_reset function,
1106
+ * post_write handle will not be able to trigger tx because CAN will be
1107
+ * disabled when software_reset_register is cleared first.
1108
+ */
1109
+ fifo32_reset(&s->rx_fifo);
1110
+ fifo32_reset(&s->tx_fifo);
1111
+ fifo32_reset(&s->txhpb_fifo);
1112
+}
1113
+
1114
+static bool xlnx_zynqmp_can_can_receive(CanBusClientState *client)
1115
+{
1116
+ XlnxZynqMPCANState *s = container_of(client, XlnxZynqMPCANState,
1117
+ bus_client);
1118
+
1119
+ if (ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, SRST)) {
1120
+ DB_PRINT(s, "Controller is in reset.\n");
1121
+ return false;
1122
+ } else if ((ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, CEN)) == 0) {
1123
+ DB_PRINT(s, "Controller is disabled. Incoming messages"
1124
+ " will be discarded.\n");
1125
+ return false;
1126
+ } else {
1127
+ return true;
1128
+ }
1129
+}
1130
+
1131
+static ssize_t xlnx_zynqmp_can_receive(CanBusClientState *client,
1132
+ const qemu_can_frame *buf, size_t buf_size) {
1133
+ XlnxZynqMPCANState *s = container_of(client, XlnxZynqMPCANState,
1134
+ bus_client);
1135
+ const qemu_can_frame *frame = buf;
1136
+
1137
+ DB_PRINT(s, "Incoming data.\n");
1138
+
1139
+ if (buf_size <= 0) {
1140
+ DB_PRINT(s, "Junk data received.\n");
1141
+ return 0;
1142
+ }
1143
+ if (ARRAY_FIELD_EX32(s->regs, STATUS_REGISTER, LBACK)) {
1144
+ /*
1145
+ * XlnxZynqMPCAN will not participate in normal bus communication
1146
+ * and will not receive any messages transmitted by other CAN nodes.
1147
+ */
1148
+ DB_PRINT(s, "Controller is in loopback mode. It will not"
1149
+ " receive data.\n");
1150
+
1151
+ } else if (ARRAY_FIELD_EX32(s->regs, STATUS_REGISTER, SNOOP)) {
1152
+ /* Snoop Mode: Just keep the data. no response back. */
1153
+ update_rx_fifo(s, frame);
1154
+ } else if ((ARRAY_FIELD_EX32(s->regs, STATUS_REGISTER, SLEEP))) {
1155
+ /*
1156
+ * XlnxZynqMPCAN is in sleep mode. Any data on bus will bring it to wake
1157
+ * up state.
1158
+ */
1159
+ can_exit_sleep_mode(s);
1160
+ update_rx_fifo(s, frame);
1161
+ } else if ((ARRAY_FIELD_EX32(s->regs, STATUS_REGISTER, SLEEP)) == 0) {
1162
+ update_rx_fifo(s, frame);
1163
+ } else {
1164
+ DB_PRINT(s, "Cannot receive data as controller is not configured"
1165
+ " correctly.\n");
1166
+ }
1167
+
1168
+ return 1;
1169
+}
1170
+
1171
+static CanBusClientInfo can_xilinx_bus_client_info = {
1172
+ .can_receive = xlnx_zynqmp_can_can_receive,
1173
+ .receive = xlnx_zynqmp_can_receive,
1174
+};
1175
+
1176
+static int xlnx_zynqmp_can_connect_to_bus(XlnxZynqMPCANState *s,
1177
+ CanBusState *bus)
1178
+{
1179
+ s->bus_client.info = &can_xilinx_bus_client_info;
1180
+
1181
+ if (can_bus_insert_client(bus, &s->bus_client) < 0) {
1182
+ return -1;
1183
+ }
1184
+ return 0;
1185
+}
1186
+
1187
+static void xlnx_zynqmp_can_realize(DeviceState *dev, Error **errp)
1188
+{
1189
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(dev);
1190
+
1191
+ if (s->canbus) {
1192
+ if (xlnx_zynqmp_can_connect_to_bus(s, s->canbus) < 0) {
1193
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
1194
+
1195
+ error_setg(errp, "%s: xlnx_zynqmp_can_connect_to_bus"
1196
+ " failed.", path);
1197
+ return;
1198
+ }
1199
+
1200
+ } else {
1201
+ /* If no bus is set. */
1202
+ DB_PRINT(s, "Canbus property is not set.\n");
1203
+ }
1204
+
1205
+ /* Create RX FIFO, TXFIFO, TXHPB storage. */
1206
+ fifo32_create(&s->rx_fifo, RXFIFO_SIZE);
1207
+ fifo32_create(&s->tx_fifo, RXFIFO_SIZE);
1208
+ fifo32_create(&s->txhpb_fifo, CAN_FRAME_SIZE);
1209
+
1210
+ /* Allocate a new timer. */
1211
+ s->can_timer = ptimer_init(xlnx_zynqmp_can_ptimer_cb, s,
1212
+ PTIMER_POLICY_DEFAULT);
1213
+
1214
+ ptimer_transaction_begin(s->can_timer);
1215
+
1216
+ ptimer_set_freq(s->can_timer, s->cfg.ext_clk_freq);
1217
+ ptimer_set_limit(s->can_timer, CAN_TIMER_MAX, 1);
1218
+ ptimer_run(s->can_timer, 0);
1219
+ ptimer_transaction_commit(s->can_timer);
1220
+}
1221
+
1222
+static void xlnx_zynqmp_can_init(Object *obj)
1223
+{
1224
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(obj);
1225
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
1226
+
1227
+ RegisterInfoArray *reg_array;
1228
+
1229
+ memory_region_init(&s->iomem, obj, TYPE_XLNX_ZYNQMP_CAN,
1230
+ XLNX_ZYNQMP_CAN_R_MAX * 4);
1231
+ reg_array = register_init_block32(DEVICE(obj), can_regs_info,
1232
+ ARRAY_SIZE(can_regs_info),
1233
+ s->reg_info, s->regs,
1234
+ &can_ops,
1235
+ XLNX_ZYNQMP_CAN_ERR_DEBUG,
1236
+ XLNX_ZYNQMP_CAN_R_MAX * 4);
1237
+
1238
+ memory_region_add_subregion(&s->iomem, 0x00, &reg_array->mem);
1239
+ sysbus_init_mmio(sbd, &s->iomem);
1240
+ sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->irq);
1241
+}
1242
+
1243
+static const VMStateDescription vmstate_can = {
1244
+ .name = TYPE_XLNX_ZYNQMP_CAN,
1245
+ .version_id = 1,
1246
+ .minimum_version_id = 1,
1247
+ .fields = (VMStateField[]) {
1248
+ VMSTATE_FIFO32(rx_fifo, XlnxZynqMPCANState),
1249
+ VMSTATE_FIFO32(tx_fifo, XlnxZynqMPCANState),
1250
+ VMSTATE_FIFO32(txhpb_fifo, XlnxZynqMPCANState),
1251
+ VMSTATE_UINT32_ARRAY(regs, XlnxZynqMPCANState, XLNX_ZYNQMP_CAN_R_MAX),
1252
+ VMSTATE_PTIMER(can_timer, XlnxZynqMPCANState),
1253
+ VMSTATE_END_OF_LIST(),
1254
+ }
1255
+};
1256
+
1257
+static Property xlnx_zynqmp_can_properties[] = {
1258
+ DEFINE_PROP_UINT32("ext_clk_freq", XlnxZynqMPCANState, cfg.ext_clk_freq,
1259
+ CAN_DEFAULT_CLOCK),
1260
+ DEFINE_PROP_LINK("canbus", XlnxZynqMPCANState, canbus, TYPE_CAN_BUS,
1261
+ CanBusState *),
1262
+ DEFINE_PROP_END_OF_LIST(),
1263
+};
1264
+
1265
+static void xlnx_zynqmp_can_class_init(ObjectClass *klass, void *data)
1266
+{
1267
+ DeviceClass *dc = DEVICE_CLASS(klass);
1268
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
1269
+
1270
+ rc->phases.enter = xlnx_zynqmp_can_reset_init;
1271
+ rc->phases.hold = xlnx_zynqmp_can_reset_hold;
1272
+ dc->realize = xlnx_zynqmp_can_realize;
1273
+ device_class_set_props(dc, xlnx_zynqmp_can_properties);
1274
+ dc->vmsd = &vmstate_can;
1275
+}
1276
+
1277
+static const TypeInfo can_info = {
1278
+ .name = TYPE_XLNX_ZYNQMP_CAN,
1279
+ .parent = TYPE_SYS_BUS_DEVICE,
1280
+ .instance_size = sizeof(XlnxZynqMPCANState),
1281
+ .class_init = xlnx_zynqmp_can_class_init,
1282
+ .instance_init = xlnx_zynqmp_can_init,
1283
+};
1284
+
1285
+static void can_register_types(void)
1286
+{
1287
+ type_register_static(&can_info);
1288
+}
1289
+
1290
+type_init(can_register_types)
1291
diff --git a/hw/net/can/meson.build b/hw/net/can/meson.build
1292
index XXXXXXX..XXXXXXX 100644
1293
--- a/hw/net/can/meson.build
1294
+++ b/hw/net/can/meson.build
1295
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_CAN_SJA1000', if_true: files('can_sja1000.c'))
1296
softmmu_ss.add(when: 'CONFIG_CAN_PCI', if_true: files('can_kvaser_pci.c'))
1297
softmmu_ss.add(when: 'CONFIG_CAN_PCI', if_true: files('can_pcm3680_pci.c'))
1298
softmmu_ss.add(when: 'CONFIG_CAN_PCI', if_true: files('can_mioe3680_pci.c'))
1299
+softmmu_ss.add(when: 'CONFIG_XLNX_ZYNQMP', if_true: files('xlnx-zynqmp-can.c'))
1300
--
194
--
1301
2.20.1
195
2.20.1
1302
196
1303
197
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Rebecca Cran <rebecca@nuviainc.com>
2
2
3
This adds two acceptance tests for the quanta-gsj machine.
3
Set ID_AA64PFR1_EL1.SSBS to 2 and ID_PFR2.SSBS to 1.
4
4
5
One test downloads a lightly patched openbmc flash image from github and
5
Signed-off-by: Rebecca Cran <rebecca@nuviainc.com>
6
verifies that it boots all the way to the login prompt.
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
7
Message-id: 20210216224543.16142-3-rebecca@nuviainc.com
8
The other test downloads a kernel, initrd and dtb built from the same
9
openbmc source and verifies that the kernel detects all CPUs and boots
10
to the point where it can't find the root filesystem (because we have no
11
flash image in this case).
12
13
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
14
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
15
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
16
Message-id: 20200911052101.2602693-15-hskinnemoen@google.com
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
18
---
9
---
19
tests/acceptance/boot_linux_console.py | 83 ++++++++++++++++++++++++++
10
target/arm/cpu64.c | 5 +++++
20
1 file changed, 83 insertions(+)
11
1 file changed, 5 insertions(+)
21
12
22
diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
13
diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
23
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
24
--- a/tests/acceptance/boot_linux_console.py
15
--- a/target/arm/cpu64.c
25
+++ b/tests/acceptance/boot_linux_console.py
16
+++ b/target/arm/cpu64.c
26
@@ -XXX,XX +XXX,XX @@ class BootLinuxConsole(LinuxKernelTest):
17
@@ -XXX,XX +XXX,XX @@ static void aarch64_max_initfn(Object *obj)
27
'sda')
18
28
# cubieboard's reboot is not functioning; omit reboot test.
19
t = cpu->isar.id_aa64pfr1;
29
20
t = FIELD_DP64(t, ID_AA64PFR1, BT, 1);
30
+ def test_arm_quanta_gsj(self):
21
+ t = FIELD_DP64(t, ID_AA64PFR1, SSBS, 2);
31
+ """
22
/*
32
+ :avocado: tags=arch:arm
23
* Begin with full support for MTE. This will be downgraded to MTE=0
33
+ :avocado: tags=machine:quanta-gsj
24
* during realize if the board provides no tag memory, much like
34
+ """
25
@@ -XXX,XX +XXX,XX @@ static void aarch64_max_initfn(Object *obj)
35
+ # 25 MiB compressed, 32 MiB uncompressed.
26
u = FIELD_DP32(u, ID_PFR0, DIT, 1);
36
+ image_url = (
27
cpu->isar.id_pfr0 = u;
37
+ 'https://github.com/hskinnemoen/openbmc/releases/download/'
28
38
+ '20200711-gsj-qemu-0/obmc-phosphor-image-gsj.static.mtd.gz')
29
+ u = cpu->isar.id_pfr2;
39
+ image_hash = '14895e634923345cb5c8776037ff7876df96f6b1'
30
+ u = FIELD_DP32(u, ID_PFR2, SSBS, 1);
40
+ image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash)
31
+ cpu->isar.id_pfr2 = u;
41
+ image_name = 'obmc.mtd'
42
+ image_path = os.path.join(self.workdir, image_name)
43
+ archive.gzip_uncompress(image_path_gz, image_path)
44
+
32
+
45
+ self.vm.set_console()
33
u = cpu->isar.id_mmfr3;
46
+ drive_args = 'file=' + image_path + ',if=mtd,bus=0,unit=0'
34
u = FIELD_DP32(u, ID_MMFR3, PAN, 2); /* ATS1E1 */
47
+ self.vm.add_args('-drive', drive_args)
35
cpu->isar.id_mmfr3 = u;
48
+ self.vm.launch()
49
+
50
+ # Disable drivers and services that stall for a long time during boot,
51
+ # to avoid running past the 90-second timeout. These may be removed
52
+ # as the corresponding device support is added.
53
+ kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + (
54
+ 'console=${console} '
55
+ 'mem=${mem} '
56
+ 'initcall_blacklist=npcm_i2c_bus_driver_init '
57
+ 'systemd.mask=systemd-random-seed.service '
58
+ 'systemd.mask=dropbearkey.service '
59
+ )
60
+
61
+ self.wait_for_console_pattern('> BootBlock by Nuvoton')
62
+ self.wait_for_console_pattern('>Device: Poleg BMC NPCM730')
63
+ self.wait_for_console_pattern('>Skip DDR init.')
64
+ self.wait_for_console_pattern('U-Boot ')
65
+ interrupt_interactive_console_until_pattern(
66
+ self, 'Hit any key to stop autoboot:', 'U-Boot>')
67
+ exec_command_and_wait_for_pattern(
68
+ self, "setenv bootargs ${bootargs} " + kernel_command_line,
69
+ 'U-Boot>')
70
+ exec_command_and_wait_for_pattern(
71
+ self, 'run romboot', 'Booting Kernel from flash')
72
+ self.wait_for_console_pattern('Booting Linux on physical CPU 0x0')
73
+ self.wait_for_console_pattern('CPU1: thread -1, cpu 1, socket 0')
74
+ self.wait_for_console_pattern('OpenBMC Project Reference Distro')
75
+ self.wait_for_console_pattern('gsj login:')
76
+
77
+ def test_arm_quanta_gsj_initrd(self):
78
+ """
79
+ :avocado: tags=arch:arm
80
+ :avocado: tags=machine:quanta-gsj
81
+ """
82
+ initrd_url = (
83
+ 'https://github.com/hskinnemoen/openbmc/releases/download/'
84
+ '20200711-gsj-qemu-0/obmc-phosphor-initramfs-gsj.cpio.xz')
85
+ initrd_hash = '98fefe5d7e56727b1eb17d5c00311b1b5c945300'
86
+ initrd_path = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
87
+ kernel_url = (
88
+ 'https://github.com/hskinnemoen/openbmc/releases/download/'
89
+ '20200711-gsj-qemu-0/uImage-gsj.bin')
90
+ kernel_hash = 'fa67b2f141d56d39b3c54305c0e8a899c99eb2c7'
91
+ kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
92
+ dtb_url = (
93
+ 'https://github.com/hskinnemoen/openbmc/releases/download/'
94
+ '20200711-gsj-qemu-0/nuvoton-npcm730-gsj.dtb')
95
+ dtb_hash = '18315f7006d7b688d8312d5c727eecd819aa36a4'
96
+ dtb_path = self.fetch_asset(dtb_url, asset_hash=dtb_hash)
97
+
98
+ self.vm.set_console()
99
+ kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
100
+ 'console=ttyS0,115200n8 '
101
+ 'earlycon=uart8250,mmio32,0xf0001000')
102
+ self.vm.add_args('-kernel', kernel_path,
103
+ '-initrd', initrd_path,
104
+ '-dtb', dtb_path,
105
+ '-append', kernel_command_line)
106
+ self.vm.launch()
107
+
108
+ self.wait_for_console_pattern('Booting Linux on physical CPU 0x0')
109
+ self.wait_for_console_pattern('CPU1: thread -1, cpu 1, socket 0')
110
+ self.wait_for_console_pattern(
111
+ 'Give root password for system maintenance')
112
+
113
def test_arm_orangepi(self):
114
"""
115
:avocado: tags=arch:arm
116
--
36
--
117
2.20.1
37
2.20.1
118
38
119
39
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Rebecca Cran <rebecca@nuviainc.com>
2
2
3
Reviewed-by: Cédric Le Goater <clg@kaod.org>
3
Enable FEAT_SSBS for the "max" 32-bit CPU.
4
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
4
5
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
5
Signed-off-by: Rebecca Cran <rebecca@nuviainc.com>
6
Message-id: 20200911052101.2602693-14-hskinnemoen@google.com
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20210216224543.16142-4-rebecca@nuviainc.com
8
[PMM: fix typo causing compilation failure]
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
---
10
---
9
docs/system/arm/nuvoton.rst | 92 +++++++++++++++++++++++++++++++++++++
11
target/arm/cpu.c | 4 ++++
10
docs/system/target-arm.rst | 1 +
12
1 file changed, 4 insertions(+)
11
2 files changed, 93 insertions(+)
12
create mode 100644 docs/system/arm/nuvoton.rst
13
13
14
diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst
14
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
15
new file mode 100644
15
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX
16
--- a/target/arm/cpu.c
17
--- /dev/null
17
+++ b/target/arm/cpu.c
18
+++ b/docs/system/arm/nuvoton.rst
18
@@ -XXX,XX +XXX,XX @@ static void arm_max_initfn(Object *obj)
19
@@ -XXX,XX +XXX,XX @@
19
t = cpu->isar.id_pfr0;
20
+Nuvoton iBMC boards (``npcm750-evb``, ``quanta-gsj``)
20
t = FIELD_DP32(t, ID_PFR0, DIT, 1);
21
+=====================================================
21
cpu->isar.id_pfr0 = t;
22
+
22
+
23
+The `Nuvoton iBMC`_ chips (NPCM7xx) are a family of ARM-based SoCs that are
23
+ t = cpu->isar.id_pfr2;
24
+designed to be used as Baseboard Management Controllers (BMCs) in various
24
+ t = FIELD_DP32(t, ID_PFR2, SSBS, 1);
25
+servers. They all feature one or two ARM Cortex A9 CPU cores, as well as an
25
+ cpu->isar.id_pfr2 = t;
26
+assortment of peripherals targeted for either Enterprise or Data Center /
26
}
27
+Hyperscale applications. The former is a superset of the latter, so NPCM750 has
27
#endif
28
+all the peripherals of NPCM730 and more.
28
}
29
+
30
+.. _Nuvoton iBMC: https://www.nuvoton.com/products/cloud-computing/ibmc/
31
+
32
+The NPCM750 SoC has two Cortex A9 cores and is targeted for the Enterprise
33
+segment. The following machines are based on this chip :
34
+
35
+- ``npcm750-evb`` Nuvoton NPCM750 Evaluation board
36
+
37
+The NPCM730 SoC has two Cortex A9 cores and is targeted for Data Center and
38
+Hyperscale applications. The following machines are based on this chip :
39
+
40
+- ``quanta-gsj`` Quanta GSJ server BMC
41
+
42
+There are also two more SoCs, NPCM710 and NPCM705, which are single-core
43
+variants of NPCM750 and NPCM730, respectively. These are currently not
44
+supported by QEMU.
45
+
46
+Supported devices
47
+-----------------
48
+
49
+ * SMP (Dual Core Cortex-A9)
50
+ * Cortex-A9MPCore built-in peripherals: SCU, GIC, Global Timer, Private Timer
51
+ and Watchdog.
52
+ * SRAM, ROM and DRAM mappings
53
+ * System Global Control Registers (GCR)
54
+ * Clock and reset controller (CLK)
55
+ * Timer controller (TIM)
56
+ * Serial ports (16550-based)
57
+ * DDR4 memory controller (dummy interface indicating memory training is done)
58
+ * OTP controllers (no protection features)
59
+ * Flash Interface Unit (FIU; no protection features)
60
+
61
+Missing devices
62
+---------------
63
+
64
+ * GPIO controller
65
+ * LPC/eSPI host-to-BMC interface, including
66
+
67
+ * Keyboard and mouse controller interface (KBCI)
68
+ * Keyboard Controller Style (KCS) channels
69
+ * BIOS POST code FIFO
70
+ * System Wake-up Control (SWC)
71
+ * Shared memory (SHM)
72
+ * eSPI slave interface
73
+
74
+ * Ethernet controllers (GMAC and EMC)
75
+ * USB host (USBH)
76
+ * USB device (USBD)
77
+ * SMBus controller (SMBF)
78
+ * Peripheral SPI controller (PSPI)
79
+ * Analog to Digital Converter (ADC)
80
+ * SD/MMC host
81
+ * Random Number Generator (RNG)
82
+ * PECI interface
83
+ * Pulse Width Modulation (PWM)
84
+ * Tachometer
85
+ * PCI and PCIe root complex and bridges
86
+ * VDM and MCTP support
87
+ * Serial I/O expansion
88
+ * LPC/eSPI host
89
+ * Coprocessor
90
+ * Graphics
91
+ * Video capture
92
+ * Encoding compression engine
93
+ * Security features
94
+
95
+Boot options
96
+------------
97
+
98
+The Nuvoton machines can boot from an OpenBMC firmware image, or directly into
99
+a kernel using the ``-kernel`` option. OpenBMC images for `quanta-gsj` and
100
+possibly others can be downloaded from the OpenPOWER jenkins :
101
+
102
+ https://openpower.xyz/
103
+
104
+The firmware image should be attached as an MTD drive. Example :
105
+
106
+.. code-block:: bash
107
+
108
+ $ qemu-system-arm -machine quanta-gsj -nographic \
109
+ -drive file=image-bmc,if=mtd,bus=0,unit=0,format=raw
110
+
111
+The default root password for test images is usually ``0penBmc``.
112
diff --git a/docs/system/target-arm.rst b/docs/system/target-arm.rst
113
index XXXXXXX..XXXXXXX 100644
114
--- a/docs/system/target-arm.rst
115
+++ b/docs/system/target-arm.rst
116
@@ -XXX,XX +XXX,XX @@ undocumented; you can get a complete list by running
117
arm/musicpal
118
arm/gumstix
119
arm/nseries
120
+ arm/nuvoton
121
arm/orangepi
122
arm/palm
123
arm/xscale
124
--
29
--
125
2.20.1
30
2.20.1
126
31
127
32
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Doug Evans <dje@google.com>
2
2
3
Enough functionality to boot the Linux kernel has been implemented. This
3
This is a 10/100 ethernet device that has several features.
4
includes:
4
Only the ones needed by the Linux driver have been implemented.
5
See npcm7xx_emc.c for a list of unimplemented features.
5
6
6
- Correct power-on reset values so the various clock rates can be
7
Reviewed-by: Hao Wu <wuhaotsh@google.com>
7
accurately calculated.
8
Reviewed-by: Avi Fishman <avi.fishman@nuvoton.com>
8
- Clock enables stick around when written.
9
Signed-off-by: Doug Evans <dje@google.com>
9
10
Message-id: 20210218212453.831406-2-dje@google.com
10
In addition, a best effort attempt to implement SECCNT and CNTR25M was
11
made even though I don't think the kernel needs them.
12
13
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
14
Reviewed-by: Joel Stanley <joel@jms.id.au>
15
Reviewed-by: Cédric Le Goater <clg@kaod.org>
16
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
17
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
18
Tested-by: Alexander Bulekov <alxndr@bu.edu>
19
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
20
Message-id: 20200911052101.2602693-3-hskinnemoen@google.com
21
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
22
---
12
---
23
include/hw/misc/npcm7xx_clk.h | 48 ++++++
13
include/hw/net/npcm7xx_emc.h | 286 ++++++++++++
24
hw/misc/npcm7xx_clk.c | 266 ++++++++++++++++++++++++++++++++++
14
hw/net/npcm7xx_emc.c | 857 +++++++++++++++++++++++++++++++++++
25
hw/misc/meson.build | 1 +
15
hw/net/meson.build | 1 +
26
hw/misc/trace-events | 4 +
16
hw/net/trace-events | 17 +
27
4 files changed, 319 insertions(+)
17
4 files changed, 1161 insertions(+)
28
create mode 100644 include/hw/misc/npcm7xx_clk.h
18
create mode 100644 include/hw/net/npcm7xx_emc.h
29
create mode 100644 hw/misc/npcm7xx_clk.c
19
create mode 100644 hw/net/npcm7xx_emc.c
30
20
31
diff --git a/include/hw/misc/npcm7xx_clk.h b/include/hw/misc/npcm7xx_clk.h
21
diff --git a/include/hw/net/npcm7xx_emc.h b/include/hw/net/npcm7xx_emc.h
32
new file mode 100644
22
new file mode 100644
33
index XXXXXXX..XXXXXXX
23
index XXXXXXX..XXXXXXX
34
--- /dev/null
24
--- /dev/null
35
+++ b/include/hw/misc/npcm7xx_clk.h
25
+++ b/include/hw/net/npcm7xx_emc.h
36
@@ -XXX,XX +XXX,XX @@
26
@@ -XXX,XX +XXX,XX @@
37
+/*
27
+/*
38
+ * Nuvoton NPCM7xx Clock Control Registers.
28
+ * Nuvoton NPCM7xx EMC Module
39
+ *
29
+ *
40
+ * Copyright 2020 Google LLC
30
+ * Copyright 2020 Google LLC
41
+ *
31
+ *
42
+ * This program is free software; you can redistribute it and/or modify it
32
+ * This program is free software; you can redistribute it and/or modify it
43
+ * under the terms of the GNU General Public License as published by the
33
+ * under the terms of the GNU General Public License as published by the
...
...
47
+ * This program is distributed in the hope that it will be useful, but WITHOUT
37
+ * This program is distributed in the hope that it will be useful, but WITHOUT
48
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
38
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
49
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
39
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
50
+ * for more details.
40
+ * for more details.
51
+ */
41
+ */
52
+#ifndef NPCM7XX_CLK_H
42
+
53
+#define NPCM7XX_CLK_H
43
+#ifndef NPCM7XX_EMC_H
54
+
44
+#define NPCM7XX_EMC_H
55
+#include "exec/memory.h"
45
+
46
+#include "hw/irq.h"
56
+#include "hw/sysbus.h"
47
+#include "hw/sysbus.h"
57
+
48
+#include "net/net.h"
58
+/*
49
+
59
+ * The reference clock frequency for the timer modules, and the SECCNT and
50
+/* 32-bit register indices. */
60
+ * CNTR25M registers in this module, is always 25 MHz.
51
+enum NPCM7xxPWMRegister {
61
+ */
52
+ /* Control registers. */
62
+#define NPCM7XX_TIMER_REF_HZ (25000000)
53
+ REG_CAMCMR,
63
+
54
+ REG_CAMEN,
64
+/*
55
+
65
+ * Number of registers in our device state structure. Don't change this without
56
+ /* There are 16 CAMn[ML] registers. */
66
+ * incrementing the version_id in the vmstate.
57
+ REG_CAMM_BASE,
67
+ */
58
+ REG_CAML_BASE,
68
+#define NPCM7XX_CLK_NR_REGS (0x70 / sizeof(uint32_t))
59
+ REG_CAMML_LAST = 0x21,
69
+
60
+
70
+typedef struct NPCM7xxCLKState {
61
+ REG_TXDLSA = 0x22,
62
+ REG_RXDLSA,
63
+ REG_MCMDR,
64
+ REG_MIID,
65
+ REG_MIIDA,
66
+ REG_FFTCR,
67
+ REG_TSDR,
68
+ REG_RSDR,
69
+ REG_DMARFC,
70
+ REG_MIEN,
71
+
72
+ /* Status registers. */
73
+ REG_MISTA,
74
+ REG_MGSTA,
75
+ REG_MPCNT,
76
+ REG_MRPC,
77
+ REG_MRPCC,
78
+ REG_MREPC,
79
+ REG_DMARFS,
80
+ REG_CTXDSA,
81
+ REG_CTXBSA,
82
+ REG_CRXDSA,
83
+ REG_CRXBSA,
84
+
85
+ NPCM7XX_NUM_EMC_REGS,
86
+};
87
+
88
+/* REG_CAMCMR fields */
89
+/* Enable CAM Compare */
90
+#define REG_CAMCMR_ECMP (1 << 4)
91
+/* Complement CAM Compare */
92
+#define REG_CAMCMR_CCAM (1 << 3)
93
+/* Accept Broadcast Packet */
94
+#define REG_CAMCMR_ABP (1 << 2)
95
+/* Accept Multicast Packet */
96
+#define REG_CAMCMR_AMP (1 << 1)
97
+/* Accept Unicast Packet */
98
+#define REG_CAMCMR_AUP (1 << 0)
99
+
100
+/* REG_MCMDR fields */
101
+/* Software Reset */
102
+#define REG_MCMDR_SWR (1 << 24)
103
+/* Internal Loopback Select */
104
+#define REG_MCMDR_LBK (1 << 21)
105
+/* Operation Mode Select */
106
+#define REG_MCMDR_OPMOD (1 << 20)
107
+/* Enable MDC Clock Generation */
108
+#define REG_MCMDR_ENMDC (1 << 19)
109
+/* Full-Duplex Mode Select */
110
+#define REG_MCMDR_FDUP (1 << 18)
111
+/* Enable SQE Checking */
112
+#define REG_MCMDR_ENSEQ (1 << 17)
113
+/* Send PAUSE Frame */
114
+#define REG_MCMDR_SDPZ (1 << 16)
115
+/* No Defer */
116
+#define REG_MCMDR_NDEF (1 << 9)
117
+/* Frame Transmission On */
118
+#define REG_MCMDR_TXON (1 << 8)
119
+/* Strip CRC Checksum */
120
+#define REG_MCMDR_SPCRC (1 << 5)
121
+/* Accept CRC Error Packet */
122
+#define REG_MCMDR_AEP (1 << 4)
123
+/* Accept Control Packet */
124
+#define REG_MCMDR_ACP (1 << 3)
125
+/* Accept Runt Packet */
126
+#define REG_MCMDR_ARP (1 << 2)
127
+/* Accept Long Packet */
128
+#define REG_MCMDR_ALP (1 << 1)
129
+/* Frame Reception On */
130
+#define REG_MCMDR_RXON (1 << 0)
131
+
132
+/* REG_MIEN fields */
133
+/* Enable Transmit Descriptor Unavailable Interrupt */
134
+#define REG_MIEN_ENTDU (1 << 23)
135
+/* Enable Transmit Completion Interrupt */
136
+#define REG_MIEN_ENTXCP (1 << 18)
137
+/* Enable Transmit Interrupt */
138
+#define REG_MIEN_ENTXINTR (1 << 16)
139
+/* Enable Receive Descriptor Unavailable Interrupt */
140
+#define REG_MIEN_ENRDU (1 << 10)
141
+/* Enable Receive Good Interrupt */
142
+#define REG_MIEN_ENRXGD (1 << 4)
143
+/* Enable Receive Interrupt */
144
+#define REG_MIEN_ENRXINTR (1 << 0)
145
+
146
+/* REG_MISTA fields */
147
+/* TODO: Add error fields and support simulated errors? */
148
+/* Transmit Bus Error Interrupt */
149
+#define REG_MISTA_TXBERR (1 << 24)
150
+/* Transmit Descriptor Unavailable Interrupt */
151
+#define REG_MISTA_TDU (1 << 23)
152
+/* Transmit Completion Interrupt */
153
+#define REG_MISTA_TXCP (1 << 18)
154
+/* Transmit Interrupt */
155
+#define REG_MISTA_TXINTR (1 << 16)
156
+/* Receive Bus Error Interrupt */
157
+#define REG_MISTA_RXBERR (1 << 11)
158
+/* Receive Descriptor Unavailable Interrupt */
159
+#define REG_MISTA_RDU (1 << 10)
160
+/* DMA Early Notification Interrupt */
161
+#define REG_MISTA_DENI (1 << 9)
162
+/* Maximum Frame Length Interrupt */
163
+#define REG_MISTA_DFOI (1 << 8)
164
+/* Receive Good Interrupt */
165
+#define REG_MISTA_RXGD (1 << 4)
166
+/* Packet Too Long Interrupt */
167
+#define REG_MISTA_PTLE (1 << 3)
168
+/* Receive Interrupt */
169
+#define REG_MISTA_RXINTR (1 << 0)
170
+
171
+/* REG_MGSTA fields */
172
+/* Transmission Halted */
173
+#define REG_MGSTA_TXHA (1 << 11)
174
+/* Receive Halted */
175
+#define REG_MGSTA_RXHA (1 << 11)
176
+
177
+/* REG_DMARFC fields */
178
+/* Maximum Receive Frame Length */
179
+#define REG_DMARFC_RXMS(word) extract32((word), 0, 16)
180
+
181
+/* REG MIIDA fields */
182
+/* Busy Bit */
183
+#define REG_MIIDA_BUSY (1 << 17)
184
+
185
+/* Transmit and receive descriptors */
186
+typedef struct NPCM7xxEMCTxDesc NPCM7xxEMCTxDesc;
187
+typedef struct NPCM7xxEMCRxDesc NPCM7xxEMCRxDesc;
188
+
189
+struct NPCM7xxEMCTxDesc {
190
+ uint32_t flags;
191
+ uint32_t txbsa;
192
+ uint32_t status_and_length;
193
+ uint32_t ntxdsa;
194
+};
195
+
196
+struct NPCM7xxEMCRxDesc {
197
+ uint32_t status_and_length;
198
+ uint32_t rxbsa;
199
+ uint32_t reserved;
200
+ uint32_t nrxdsa;
201
+};
202
+
203
+/* NPCM7xxEMCTxDesc.flags values */
204
+/* Owner: 0 = cpu, 1 = emc */
205
+#define TX_DESC_FLAG_OWNER_MASK (1 << 31)
206
+/* Transmit interrupt enable */
207
+#define TX_DESC_FLAG_INTEN (1 << 2)
208
+/* CRC append */
209
+#define TX_DESC_FLAG_CRCAPP (1 << 1)
210
+/* Padding enable */
211
+#define TX_DESC_FLAG_PADEN (1 << 0)
212
+
213
+/* NPCM7xxEMCTxDesc.status_and_length values */
214
+/* Collision count */
215
+#define TX_DESC_STATUS_CCNT_SHIFT 28
216
+#define TX_DESC_STATUS_CCNT_BITSIZE 4
217
+/* SQE error */
218
+#define TX_DESC_STATUS_SQE (1 << 26)
219
+/* Transmission paused */
220
+#define TX_DESC_STATUS_PAU (1 << 25)
221
+/* P transmission halted */
222
+#define TX_DESC_STATUS_TXHA (1 << 24)
223
+/* Late collision */
224
+#define TX_DESC_STATUS_LC (1 << 23)
225
+/* Transmission abort */
226
+#define TX_DESC_STATUS_TXABT (1 << 22)
227
+/* No carrier sense */
228
+#define TX_DESC_STATUS_NCS (1 << 21)
229
+/* Defer exceed */
230
+#define TX_DESC_STATUS_EXDEF (1 << 20)
231
+/* Transmission complete */
232
+#define TX_DESC_STATUS_TXCP (1 << 19)
233
+/* Transmission deferred */
234
+#define TX_DESC_STATUS_DEF (1 << 17)
235
+/* Transmit interrupt */
236
+#define TX_DESC_STATUS_TXINTR (1 << 16)
237
+
238
+#define TX_DESC_PKT_LEN(word) extract32((word), 0, 16)
239
+
240
+/* Transmit buffer start address */
241
+#define TX_DESC_TXBSA(word) ((uint32_t) (word) & ~3u)
242
+
243
+/* Next transmit descriptor start address */
244
+#define TX_DESC_NTXDSA(word) ((uint32_t) (word) & ~3u)
245
+
246
+/* NPCM7xxEMCRxDesc.status_and_length values */
247
+/* Owner: 0b00 = cpu, 0b01 = undefined, 0b10 = emc, 0b11 = undefined */
248
+#define RX_DESC_STATUS_OWNER_SHIFT 30
249
+#define RX_DESC_STATUS_OWNER_BITSIZE 2
250
+#define RX_DESC_STATUS_OWNER_MASK (3 << RX_DESC_STATUS_OWNER_SHIFT)
251
+/* Runt packet */
252
+#define RX_DESC_STATUS_RP (1 << 22)
253
+/* Alignment error */
254
+#define RX_DESC_STATUS_ALIE (1 << 21)
255
+/* Frame reception complete */
256
+#define RX_DESC_STATUS_RXGD (1 << 20)
257
+/* Packet too long */
258
+#define RX_DESC_STATUS_PTLE (1 << 19)
259
+/* CRC error */
260
+#define RX_DESC_STATUS_CRCE (1 << 17)
261
+/* Receive interrupt */
262
+#define RX_DESC_STATUS_RXINTR (1 << 16)
263
+
264
+#define RX_DESC_PKT_LEN(word) extract32((word), 0, 16)
265
+
266
+/* Receive buffer start address */
267
+#define RX_DESC_RXBSA(word) ((uint32_t) (word) & ~3u)
268
+
269
+/* Next receive descriptor start address */
270
+#define RX_DESC_NRXDSA(word) ((uint32_t) (word) & ~3u)
271
+
272
+/* Minimum packet length, when TX_DESC_FLAG_PADEN is set. */
273
+#define MIN_PACKET_LENGTH 64
274
+
275
+struct NPCM7xxEMCState {
276
+ /*< private >*/
71
+ SysBusDevice parent;
277
+ SysBusDevice parent;
278
+ /*< public >*/
72
+
279
+
73
+ MemoryRegion iomem;
280
+ MemoryRegion iomem;
74
+
281
+
75
+ uint32_t regs[NPCM7XX_CLK_NR_REGS];
282
+ qemu_irq tx_irq;
76
+
283
+ qemu_irq rx_irq;
77
+ /* Time reference for SECCNT and CNTR25M, initialized by power on reset */
284
+
78
+ int64_t ref_ns;
285
+ NICState *nic;
79
+} NPCM7xxCLKState;
286
+ NICConf conf;
80
+
287
+
81
+#define TYPE_NPCM7XX_CLK "npcm7xx-clk"
288
+ /* 0 or 1, for log messages */
82
+#define NPCM7XX_CLK(obj) OBJECT_CHECK(NPCM7xxCLKState, (obj), TYPE_NPCM7XX_CLK)
289
+ uint8_t emc_num;
83
+
290
+
84
+#endif /* NPCM7XX_CLK_H */
291
+ uint32_t regs[NPCM7XX_NUM_EMC_REGS];
85
diff --git a/hw/misc/npcm7xx_clk.c b/hw/misc/npcm7xx_clk.c
292
+
293
+ /*
294
+ * tx is active. Set to true by TSDR and then switches off when out of
295
+ * descriptors. If the TXON bit in REG_MCMDR is off then this is off.
296
+ */
297
+ bool tx_active;
298
+
299
+ /*
300
+ * rx is active. Set to true by RSDR and then switches off when out of
301
+ * descriptors. If the RXON bit in REG_MCMDR is off then this is off.
302
+ */
303
+ bool rx_active;
304
+};
305
+
306
+typedef struct NPCM7xxEMCState NPCM7xxEMCState;
307
+
308
+#define TYPE_NPCM7XX_EMC "npcm7xx-emc"
309
+#define NPCM7XX_EMC(obj) \
310
+ OBJECT_CHECK(NPCM7xxEMCState, (obj), TYPE_NPCM7XX_EMC)
311
+
312
+#endif /* NPCM7XX_EMC_H */
313
diff --git a/hw/net/npcm7xx_emc.c b/hw/net/npcm7xx_emc.c
86
new file mode 100644
314
new file mode 100644
87
index XXXXXXX..XXXXXXX
315
index XXXXXXX..XXXXXXX
88
--- /dev/null
316
--- /dev/null
89
+++ b/hw/misc/npcm7xx_clk.c
317
+++ b/hw/net/npcm7xx_emc.c
90
@@ -XXX,XX +XXX,XX @@
318
@@ -XXX,XX +XXX,XX @@
91
+/*
319
+/*
92
+ * Nuvoton NPCM7xx Clock Control Registers.
320
+ * Nuvoton NPCM7xx EMC Module
93
+ *
321
+ *
94
+ * Copyright 2020 Google LLC
322
+ * Copyright 2020 Google LLC
95
+ *
323
+ *
96
+ * This program is free software; you can redistribute it and/or modify it
324
+ * This program is free software; you can redistribute it and/or modify it
97
+ * under the terms of the GNU General Public License as published by the
325
+ * under the terms of the GNU General Public License as published by the
...
...
100
+ *
328
+ *
101
+ * This program is distributed in the hope that it will be useful, but WITHOUT
329
+ * This program is distributed in the hope that it will be useful, but WITHOUT
102
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
330
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
103
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
331
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
104
+ * for more details.
332
+ * for more details.
333
+ *
334
+ * Unsupported/unimplemented features:
335
+ * - MCMDR.FDUP (full duplex) is ignored, half duplex is not supported
336
+ * - Only CAM0 is supported, CAM[1-15] are not
337
+ * - writes to CAMEN.[1-15] are ignored, these bits always read as zeroes
338
+ * - MII is not implemented, MIIDA.BUSY and MIID always return zero
339
+ * - MCMDR.LBK is not implemented
340
+ * - MCMDR.{OPMOD,ENSQE,AEP,ARP} are not supported
341
+ * - H/W FIFOs are not supported, MCMDR.FFTCR is ignored
342
+ * - MGSTA.SQE is not supported
343
+ * - pause and control frames are not implemented
344
+ * - MGSTA.CCNT is not supported
345
+ * - MPCNT, DMARFS are not implemented
105
+ */
346
+ */
106
+
347
+
107
+#include "qemu/osdep.h"
348
+#include "qemu/osdep.h"
108
+
349
+
109
+#include "hw/misc/npcm7xx_clk.h"
350
+/* For crc32 */
351
+#include <zlib.h>
352
+
353
+#include "qemu-common.h"
354
+#include "hw/irq.h"
355
+#include "hw/qdev-clock.h"
356
+#include "hw/qdev-properties.h"
357
+#include "hw/net/npcm7xx_emc.h"
358
+#include "net/eth.h"
110
+#include "migration/vmstate.h"
359
+#include "migration/vmstate.h"
360
+#include "qemu/bitops.h"
111
+#include "qemu/error-report.h"
361
+#include "qemu/error-report.h"
112
+#include "qemu/log.h"
362
+#include "qemu/log.h"
113
+#include "qemu/module.h"
363
+#include "qemu/module.h"
114
+#include "qemu/timer.h"
115
+#include "qemu/units.h"
364
+#include "qemu/units.h"
365
+#include "sysemu/dma.h"
116
+#include "trace.h"
366
+#include "trace.h"
117
+
367
+
118
+#define PLLCON_LOKI BIT(31)
368
+#define CRC_LENGTH 4
119
+#define PLLCON_LOKS BIT(30)
120
+#define PLLCON_PWDEN BIT(12)
121
+
122
+enum NPCM7xxCLKRegisters {
123
+ NPCM7XX_CLK_CLKEN1,
124
+ NPCM7XX_CLK_CLKSEL,
125
+ NPCM7XX_CLK_CLKDIV1,
126
+ NPCM7XX_CLK_PLLCON0,
127
+ NPCM7XX_CLK_PLLCON1,
128
+ NPCM7XX_CLK_SWRSTR,
129
+ NPCM7XX_CLK_IPSRST1 = 0x20 / sizeof(uint32_t),
130
+ NPCM7XX_CLK_IPSRST2,
131
+ NPCM7XX_CLK_CLKEN2,
132
+ NPCM7XX_CLK_CLKDIV2,
133
+ NPCM7XX_CLK_CLKEN3,
134
+ NPCM7XX_CLK_IPSRST3,
135
+ NPCM7XX_CLK_WD0RCR,
136
+ NPCM7XX_CLK_WD1RCR,
137
+ NPCM7XX_CLK_WD2RCR,
138
+ NPCM7XX_CLK_SWRSTC1,
139
+ NPCM7XX_CLK_SWRSTC2,
140
+ NPCM7XX_CLK_SWRSTC3,
141
+ NPCM7XX_CLK_SWRSTC4,
142
+ NPCM7XX_CLK_PLLCON2,
143
+ NPCM7XX_CLK_CLKDIV3,
144
+ NPCM7XX_CLK_CORSTC,
145
+ NPCM7XX_CLK_PLLCONG,
146
+ NPCM7XX_CLK_AHBCKFI,
147
+ NPCM7XX_CLK_SECCNT,
148
+ NPCM7XX_CLK_CNTR25M,
149
+ NPCM7XX_CLK_REGS_END,
150
+};
151
+
369
+
152
+/*
370
+/*
153
+ * These reset values were taken from version 0.91 of the NPCM750R data sheet.
371
+ * The maximum size of a (layer 2) ethernet frame as defined by 802.3.
154
+ *
372
+ * 1518 = 6(dest macaddr) + 6(src macaddr) + 2(proto) + 4(crc) + 1500(payload)
155
+ * All are loaded on power-up reset. CLKENx and SWRSTR should also be loaded on
373
+ * This does not include an additional 4 for the vlan field (802.1q).
156
+ * core domain reset, but this reset type is not yet supported by QEMU.
157
+ */
374
+ */
158
+static const uint32_t cold_reset_values[NPCM7XX_CLK_NR_REGS] = {
375
+#define MAX_ETH_FRAME_SIZE 1518
159
+ [NPCM7XX_CLK_CLKEN1] = 0xffffffff,
376
+
160
+ [NPCM7XX_CLK_CLKSEL] = 0x004aaaaa,
377
+static const char *emc_reg_name(int regno)
161
+ [NPCM7XX_CLK_CLKDIV1] = 0x5413f855,
378
+{
162
+ [NPCM7XX_CLK_PLLCON0] = 0x00222101 | PLLCON_LOKI,
379
+#define REG(name) case REG_ ## name: return #name;
163
+ [NPCM7XX_CLK_PLLCON1] = 0x00202101 | PLLCON_LOKI,
380
+ switch (regno) {
164
+ [NPCM7XX_CLK_IPSRST1] = 0x00001000,
381
+ REG(CAMCMR)
165
+ [NPCM7XX_CLK_IPSRST2] = 0x80000000,
382
+ REG(CAMEN)
166
+ [NPCM7XX_CLK_CLKEN2] = 0xffffffff,
383
+ REG(TXDLSA)
167
+ [NPCM7XX_CLK_CLKDIV2] = 0xaa4f8f9f,
384
+ REG(RXDLSA)
168
+ [NPCM7XX_CLK_CLKEN3] = 0xffffffff,
385
+ REG(MCMDR)
169
+ [NPCM7XX_CLK_IPSRST3] = 0x03000000,
386
+ REG(MIID)
170
+ [NPCM7XX_CLK_WD0RCR] = 0xffffffff,
387
+ REG(MIIDA)
171
+ [NPCM7XX_CLK_WD1RCR] = 0xffffffff,
388
+ REG(FFTCR)
172
+ [NPCM7XX_CLK_WD2RCR] = 0xffffffff,
389
+ REG(TSDR)
173
+ [NPCM7XX_CLK_SWRSTC1] = 0x00000003,
390
+ REG(RSDR)
174
+ [NPCM7XX_CLK_PLLCON2] = 0x00c02105 | PLLCON_LOKI,
391
+ REG(DMARFC)
175
+ [NPCM7XX_CLK_CORSTC] = 0x04000003,
392
+ REG(MIEN)
176
+ [NPCM7XX_CLK_PLLCONG] = 0x01228606 | PLLCON_LOKI,
393
+ REG(MISTA)
177
+ [NPCM7XX_CLK_AHBCKFI] = 0x000000c8,
394
+ REG(MGSTA)
178
+};
395
+ REG(MPCNT)
179
+
396
+ REG(MRPC)
180
+static uint64_t npcm7xx_clk_read(void *opaque, hwaddr offset, unsigned size)
397
+ REG(MRPCC)
181
+{
398
+ REG(MREPC)
399
+ REG(DMARFS)
400
+ REG(CTXDSA)
401
+ REG(CTXBSA)
402
+ REG(CRXDSA)
403
+ REG(CRXBSA)
404
+ case REG_CAMM_BASE + 0: return "CAM0M";
405
+ case REG_CAML_BASE + 0: return "CAM0L";
406
+ case REG_CAMM_BASE + 2 ... REG_CAMML_LAST:
407
+ /* Only CAM0 is supported, fold the others into something simple. */
408
+ if (regno & 1) {
409
+ return "CAM<n>L";
410
+ } else {
411
+ return "CAM<n>M";
412
+ }
413
+ default: return "UNKNOWN";
414
+ }
415
+#undef REG
416
+}
417
+
418
+static void emc_reset(NPCM7xxEMCState *emc)
419
+{
420
+ trace_npcm7xx_emc_reset(emc->emc_num);
421
+
422
+ memset(&emc->regs[0], 0, sizeof(emc->regs));
423
+
424
+ /* These regs have non-zero reset values. */
425
+ emc->regs[REG_TXDLSA] = 0xfffffffc;
426
+ emc->regs[REG_RXDLSA] = 0xfffffffc;
427
+ emc->regs[REG_MIIDA] = 0x00900000;
428
+ emc->regs[REG_FFTCR] = 0x0101;
429
+ emc->regs[REG_DMARFC] = 0x0800;
430
+ emc->regs[REG_MPCNT] = 0x7fff;
431
+
432
+ emc->tx_active = false;
433
+ emc->rx_active = false;
434
+}
435
+
436
+static void npcm7xx_emc_reset(DeviceState *dev)
437
+{
438
+ NPCM7xxEMCState *emc = NPCM7XX_EMC(dev);
439
+ emc_reset(emc);
440
+}
441
+
442
+static void emc_soft_reset(NPCM7xxEMCState *emc)
443
+{
444
+ /*
445
+ * The docs say at least MCMDR.{LBK,OPMOD} bits are not changed during a
446
+ * soft reset, but does not go into further detail. For now, KISS.
447
+ */
448
+ uint32_t mcmdr = emc->regs[REG_MCMDR];
449
+ emc_reset(emc);
450
+ emc->regs[REG_MCMDR] = mcmdr & (REG_MCMDR_LBK | REG_MCMDR_OPMOD);
451
+
452
+ qemu_set_irq(emc->tx_irq, 0);
453
+ qemu_set_irq(emc->rx_irq, 0);
454
+}
455
+
456
+static void emc_set_link(NetClientState *nc)
457
+{
458
+ /* Nothing to do yet. */
459
+}
460
+
461
+/* MISTA.TXINTR is the union of the individual bits with their enables. */
462
+static void emc_update_mista_txintr(NPCM7xxEMCState *emc)
463
+{
464
+ /* Only look at the bits we support. */
465
+ uint32_t mask = (REG_MISTA_TXBERR |
466
+ REG_MISTA_TDU |
467
+ REG_MISTA_TXCP);
468
+ if (emc->regs[REG_MISTA] & emc->regs[REG_MIEN] & mask) {
469
+ emc->regs[REG_MISTA] |= REG_MISTA_TXINTR;
470
+ } else {
471
+ emc->regs[REG_MISTA] &= ~REG_MISTA_TXINTR;
472
+ }
473
+}
474
+
475
+/* MISTA.RXINTR is the union of the individual bits with their enables. */
476
+static void emc_update_mista_rxintr(NPCM7xxEMCState *emc)
477
+{
478
+ /* Only look at the bits we support. */
479
+ uint32_t mask = (REG_MISTA_RXBERR |
480
+ REG_MISTA_RDU |
481
+ REG_MISTA_RXGD);
482
+ if (emc->regs[REG_MISTA] & emc->regs[REG_MIEN] & mask) {
483
+ emc->regs[REG_MISTA] |= REG_MISTA_RXINTR;
484
+ } else {
485
+ emc->regs[REG_MISTA] &= ~REG_MISTA_RXINTR;
486
+ }
487
+}
488
+
489
+/* N.B. emc_update_mista_txintr must have already been called. */
490
+static void emc_update_tx_irq(NPCM7xxEMCState *emc)
491
+{
492
+ int level = !!(emc->regs[REG_MISTA] &
493
+ emc->regs[REG_MIEN] &
494
+ REG_MISTA_TXINTR);
495
+ trace_npcm7xx_emc_update_tx_irq(level);
496
+ qemu_set_irq(emc->tx_irq, level);
497
+}
498
+
499
+/* N.B. emc_update_mista_rxintr must have already been called. */
500
+static void emc_update_rx_irq(NPCM7xxEMCState *emc)
501
+{
502
+ int level = !!(emc->regs[REG_MISTA] &
503
+ emc->regs[REG_MIEN] &
504
+ REG_MISTA_RXINTR);
505
+ trace_npcm7xx_emc_update_rx_irq(level);
506
+ qemu_set_irq(emc->rx_irq, level);
507
+}
508
+
509
+/* Update IRQ states due to changes in MIEN,MISTA. */
510
+static void emc_update_irq_from_reg_change(NPCM7xxEMCState *emc)
511
+{
512
+ emc_update_mista_txintr(emc);
513
+ emc_update_tx_irq(emc);
514
+
515
+ emc_update_mista_rxintr(emc);
516
+ emc_update_rx_irq(emc);
517
+}
518
+
519
+static int emc_read_tx_desc(dma_addr_t addr, NPCM7xxEMCTxDesc *desc)
520
+{
521
+ if (dma_memory_read(&address_space_memory, addr, desc, sizeof(*desc))) {
522
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to read descriptor @ 0x%"
523
+ HWADDR_PRIx "\n", __func__, addr);
524
+ return -1;
525
+ }
526
+ desc->flags = le32_to_cpu(desc->flags);
527
+ desc->txbsa = le32_to_cpu(desc->txbsa);
528
+ desc->status_and_length = le32_to_cpu(desc->status_and_length);
529
+ desc->ntxdsa = le32_to_cpu(desc->ntxdsa);
530
+ return 0;
531
+}
532
+
533
+static int emc_write_tx_desc(const NPCM7xxEMCTxDesc *desc, dma_addr_t addr)
534
+{
535
+ NPCM7xxEMCTxDesc le_desc;
536
+
537
+ le_desc.flags = cpu_to_le32(desc->flags);
538
+ le_desc.txbsa = cpu_to_le32(desc->txbsa);
539
+ le_desc.status_and_length = cpu_to_le32(desc->status_and_length);
540
+ le_desc.ntxdsa = cpu_to_le32(desc->ntxdsa);
541
+ if (dma_memory_write(&address_space_memory, addr, &le_desc,
542
+ sizeof(le_desc))) {
543
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to write descriptor @ 0x%"
544
+ HWADDR_PRIx "\n", __func__, addr);
545
+ return -1;
546
+ }
547
+ return 0;
548
+}
549
+
550
+static int emc_read_rx_desc(dma_addr_t addr, NPCM7xxEMCRxDesc *desc)
551
+{
552
+ if (dma_memory_read(&address_space_memory, addr, desc, sizeof(*desc))) {
553
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to read descriptor @ 0x%"
554
+ HWADDR_PRIx "\n", __func__, addr);
555
+ return -1;
556
+ }
557
+ desc->status_and_length = le32_to_cpu(desc->status_and_length);
558
+ desc->rxbsa = le32_to_cpu(desc->rxbsa);
559
+ desc->reserved = le32_to_cpu(desc->reserved);
560
+ desc->nrxdsa = le32_to_cpu(desc->nrxdsa);
561
+ return 0;
562
+}
563
+
564
+static int emc_write_rx_desc(const NPCM7xxEMCRxDesc *desc, dma_addr_t addr)
565
+{
566
+ NPCM7xxEMCRxDesc le_desc;
567
+
568
+ le_desc.status_and_length = cpu_to_le32(desc->status_and_length);
569
+ le_desc.rxbsa = cpu_to_le32(desc->rxbsa);
570
+ le_desc.reserved = cpu_to_le32(desc->reserved);
571
+ le_desc.nrxdsa = cpu_to_le32(desc->nrxdsa);
572
+ if (dma_memory_write(&address_space_memory, addr, &le_desc,
573
+ sizeof(le_desc))) {
574
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to write descriptor @ 0x%"
575
+ HWADDR_PRIx "\n", __func__, addr);
576
+ return -1;
577
+ }
578
+ return 0;
579
+}
580
+
581
+static void emc_set_mista(NPCM7xxEMCState *emc, uint32_t flags)
582
+{
583
+ trace_npcm7xx_emc_set_mista(flags);
584
+ emc->regs[REG_MISTA] |= flags;
585
+ if (extract32(flags, 16, 16)) {
586
+ emc_update_mista_txintr(emc);
587
+ }
588
+ if (extract32(flags, 0, 16)) {
589
+ emc_update_mista_rxintr(emc);
590
+ }
591
+}
592
+
593
+static void emc_halt_tx(NPCM7xxEMCState *emc, uint32_t mista_flag)
594
+{
595
+ emc->tx_active = false;
596
+ emc_set_mista(emc, mista_flag);
597
+}
598
+
599
+static void emc_halt_rx(NPCM7xxEMCState *emc, uint32_t mista_flag)
600
+{
601
+ emc->rx_active = false;
602
+ emc_set_mista(emc, mista_flag);
603
+}
604
+
605
+static void emc_set_next_tx_descriptor(NPCM7xxEMCState *emc,
606
+ const NPCM7xxEMCTxDesc *tx_desc,
607
+ uint32_t desc_addr)
608
+{
609
+ /* Update the current descriptor, if only to reset the owner flag. */
610
+ if (emc_write_tx_desc(tx_desc, desc_addr)) {
611
+ /*
612
+ * We just read it so this shouldn't generally happen.
613
+ * Error already reported.
614
+ */
615
+ emc_set_mista(emc, REG_MISTA_TXBERR);
616
+ }
617
+ emc->regs[REG_CTXDSA] = TX_DESC_NTXDSA(tx_desc->ntxdsa);
618
+}
619
+
620
+static void emc_set_next_rx_descriptor(NPCM7xxEMCState *emc,
621
+ const NPCM7xxEMCRxDesc *rx_desc,
622
+ uint32_t desc_addr)
623
+{
624
+ /* Update the current descriptor, if only to reset the owner flag. */
625
+ if (emc_write_rx_desc(rx_desc, desc_addr)) {
626
+ /*
627
+ * We just read it so this shouldn't generally happen.
628
+ * Error already reported.
629
+ */
630
+ emc_set_mista(emc, REG_MISTA_RXBERR);
631
+ }
632
+ emc->regs[REG_CRXDSA] = RX_DESC_NRXDSA(rx_desc->nrxdsa);
633
+}
634
+
635
+static void emc_try_send_next_packet(NPCM7xxEMCState *emc)
636
+{
637
+ /* Working buffer for sending out packets. Most packets fit in this. */
638
+#define TX_BUFFER_SIZE 2048
639
+ uint8_t tx_send_buffer[TX_BUFFER_SIZE];
640
+ uint32_t desc_addr = TX_DESC_NTXDSA(emc->regs[REG_CTXDSA]);
641
+ NPCM7xxEMCTxDesc tx_desc;
642
+ uint32_t next_buf_addr, length;
643
+ uint8_t *buf;
644
+ g_autofree uint8_t *malloced_buf = NULL;
645
+
646
+ if (emc_read_tx_desc(desc_addr, &tx_desc)) {
647
+ /* Error reading descriptor, already reported. */
648
+ emc_halt_tx(emc, REG_MISTA_TXBERR);
649
+ emc_update_tx_irq(emc);
650
+ return;
651
+ }
652
+
653
+ /* Nothing we can do if we don't own the descriptor. */
654
+ if (!(tx_desc.flags & TX_DESC_FLAG_OWNER_MASK)) {
655
+ trace_npcm7xx_emc_cpu_owned_desc(desc_addr);
656
+ emc_halt_tx(emc, REG_MISTA_TDU);
657
+ emc_update_tx_irq(emc);
658
+ return;
659
+ }
660
+
661
+ /* Give the descriptor back regardless of what happens. */
662
+ tx_desc.flags &= ~TX_DESC_FLAG_OWNER_MASK;
663
+ tx_desc.status_and_length &= 0xffff;
664
+
665
+ /*
666
+ * Despite the h/w documentation saying the tx buffer is word aligned,
667
+ * the linux driver does not word align the buffer. There is value in not
668
+ * aligning the buffer: See the description of NET_IP_ALIGN in linux
669
+ * kernel sources.
670
+ */
671
+ next_buf_addr = tx_desc.txbsa;
672
+ emc->regs[REG_CTXBSA] = next_buf_addr;
673
+ length = TX_DESC_PKT_LEN(tx_desc.status_and_length);
674
+ buf = &tx_send_buffer[0];
675
+
676
+ if (length > sizeof(tx_send_buffer)) {
677
+ malloced_buf = g_malloc(length);
678
+ buf = malloced_buf;
679
+ }
680
+
681
+ if (dma_memory_read(&address_space_memory, next_buf_addr, buf, length)) {
682
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to read packet @ 0x%x\n",
683
+ __func__, next_buf_addr);
684
+ emc_set_mista(emc, REG_MISTA_TXBERR);
685
+ emc_set_next_tx_descriptor(emc, &tx_desc, desc_addr);
686
+ emc_update_tx_irq(emc);
687
+ trace_npcm7xx_emc_tx_done(emc->regs[REG_CTXDSA]);
688
+ return;
689
+ }
690
+
691
+ if ((tx_desc.flags & TX_DESC_FLAG_PADEN) && (length < MIN_PACKET_LENGTH)) {
692
+ memset(buf + length, 0, MIN_PACKET_LENGTH - length);
693
+ length = MIN_PACKET_LENGTH;
694
+ }
695
+
696
+ /* N.B. emc_receive can get called here. */
697
+ qemu_send_packet(qemu_get_queue(emc->nic), buf, length);
698
+ trace_npcm7xx_emc_sent_packet(length);
699
+
700
+ tx_desc.status_and_length |= TX_DESC_STATUS_TXCP;
701
+ if (tx_desc.flags & TX_DESC_FLAG_INTEN) {
702
+ emc_set_mista(emc, REG_MISTA_TXCP);
703
+ }
704
+ if (emc->regs[REG_MISTA] & emc->regs[REG_MIEN] & REG_MISTA_TXINTR) {
705
+ tx_desc.status_and_length |= TX_DESC_STATUS_TXINTR;
706
+ }
707
+
708
+ emc_set_next_tx_descriptor(emc, &tx_desc, desc_addr);
709
+ emc_update_tx_irq(emc);
710
+ trace_npcm7xx_emc_tx_done(emc->regs[REG_CTXDSA]);
711
+}
712
+
713
+static bool emc_can_receive(NetClientState *nc)
714
+{
715
+ NPCM7xxEMCState *emc = NPCM7XX_EMC(qemu_get_nic_opaque(nc));
716
+
717
+ bool can_receive = emc->rx_active;
718
+ trace_npcm7xx_emc_can_receive(can_receive);
719
+ return can_receive;
720
+}
721
+
722
+/* If result is false then *fail_reason contains the reason. */
723
+static bool emc_receive_filter1(NPCM7xxEMCState *emc, const uint8_t *buf,
724
+ size_t len, const char **fail_reason)
725
+{
726
+ eth_pkt_types_e pkt_type = get_eth_packet_type(PKT_GET_ETH_HDR(buf));
727
+
728
+ switch (pkt_type) {
729
+ case ETH_PKT_BCAST:
730
+ if (emc->regs[REG_CAMCMR] & REG_CAMCMR_CCAM) {
731
+ return true;
732
+ } else {
733
+ *fail_reason = "Broadcast packet disabled";
734
+ return !!(emc->regs[REG_CAMCMR] & REG_CAMCMR_ABP);
735
+ }
736
+ case ETH_PKT_MCAST:
737
+ if (emc->regs[REG_CAMCMR] & REG_CAMCMR_CCAM) {
738
+ return true;
739
+ } else {
740
+ *fail_reason = "Multicast packet disabled";
741
+ return !!(emc->regs[REG_CAMCMR] & REG_CAMCMR_AMP);
742
+ }
743
+ case ETH_PKT_UCAST: {
744
+ bool matches;
745
+ if (emc->regs[REG_CAMCMR] & REG_CAMCMR_AUP) {
746
+ return true;
747
+ }
748
+ matches = ((emc->regs[REG_CAMCMR] & REG_CAMCMR_ECMP) &&
749
+ /* We only support one CAM register, CAM0. */
750
+ (emc->regs[REG_CAMEN] & (1 << 0)) &&
751
+ memcmp(buf, emc->conf.macaddr.a, ETH_ALEN) == 0);
752
+ if (emc->regs[REG_CAMCMR] & REG_CAMCMR_CCAM) {
753
+ *fail_reason = "MACADDR matched, comparison complemented";
754
+ return !matches;
755
+ } else {
756
+ *fail_reason = "MACADDR didn't match";
757
+ return matches;
758
+ }
759
+ }
760
+ default:
761
+ g_assert_not_reached();
762
+ }
763
+}
764
+
765
+static bool emc_receive_filter(NPCM7xxEMCState *emc, const uint8_t *buf,
766
+ size_t len)
767
+{
768
+ const char *fail_reason = NULL;
769
+ bool ok = emc_receive_filter1(emc, buf, len, &fail_reason);
770
+ if (!ok) {
771
+ trace_npcm7xx_emc_packet_filtered_out(fail_reason);
772
+ }
773
+ return ok;
774
+}
775
+
776
+static ssize_t emc_receive(NetClientState *nc, const uint8_t *buf, size_t len1)
777
+{
778
+ NPCM7xxEMCState *emc = NPCM7XX_EMC(qemu_get_nic_opaque(nc));
779
+ const uint32_t len = len1;
780
+ size_t max_frame_len;
781
+ bool long_frame;
782
+ uint32_t desc_addr;
783
+ NPCM7xxEMCRxDesc rx_desc;
784
+ uint32_t crc;
785
+ uint8_t *crc_ptr;
786
+ uint32_t buf_addr;
787
+
788
+ trace_npcm7xx_emc_receiving_packet(len);
789
+
790
+ if (!emc_can_receive(nc)) {
791
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Unexpected packet\n", __func__);
792
+ return -1;
793
+ }
794
+
795
+ if (len < ETH_HLEN ||
796
+ /* Defensive programming: drop unsupportable large packets. */
797
+ len > 0xffff - CRC_LENGTH) {
798
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Dropped frame of %u bytes\n",
799
+ __func__, len);
800
+ return len;
801
+ }
802
+
803
+ /*
804
+ * DENI is set if EMC received the Length/Type field of the incoming
805
+ * packet, so it will be set regardless of what happens next.
806
+ */
807
+ emc_set_mista(emc, REG_MISTA_DENI);
808
+
809
+ if (!emc_receive_filter(emc, buf, len)) {
810
+ emc_update_rx_irq(emc);
811
+ return len;
812
+ }
813
+
814
+ /* Huge frames (> DMARFC) are dropped. */
815
+ max_frame_len = REG_DMARFC_RXMS(emc->regs[REG_DMARFC]);
816
+ if (len + CRC_LENGTH > max_frame_len) {
817
+ trace_npcm7xx_emc_packet_dropped(len);
818
+ emc_set_mista(emc, REG_MISTA_DFOI);
819
+ emc_update_rx_irq(emc);
820
+ return len;
821
+ }
822
+
823
+ /*
824
+ * Long Frames (> MAX_ETH_FRAME_SIZE) are also dropped, unless MCMDR.ALP
825
+ * is set.
826
+ */
827
+ long_frame = false;
828
+ if (len + CRC_LENGTH > MAX_ETH_FRAME_SIZE) {
829
+ if (emc->regs[REG_MCMDR] & REG_MCMDR_ALP) {
830
+ long_frame = true;
831
+ } else {
832
+ trace_npcm7xx_emc_packet_dropped(len);
833
+ emc_set_mista(emc, REG_MISTA_PTLE);
834
+ emc_update_rx_irq(emc);
835
+ return len;
836
+ }
837
+ }
838
+
839
+ desc_addr = RX_DESC_NRXDSA(emc->regs[REG_CRXDSA]);
840
+ if (emc_read_rx_desc(desc_addr, &rx_desc)) {
841
+ /* Error reading descriptor, already reported. */
842
+ emc_halt_rx(emc, REG_MISTA_RXBERR);
843
+ emc_update_rx_irq(emc);
844
+ return len;
845
+ }
846
+
847
+ /* Nothing we can do if we don't own the descriptor. */
848
+ if (!(rx_desc.status_and_length & RX_DESC_STATUS_OWNER_MASK)) {
849
+ trace_npcm7xx_emc_cpu_owned_desc(desc_addr);
850
+ emc_halt_rx(emc, REG_MISTA_RDU);
851
+ emc_update_rx_irq(emc);
852
+ return len;
853
+ }
854
+
855
+ crc = 0;
856
+ crc_ptr = (uint8_t *) &crc;
857
+ if (!(emc->regs[REG_MCMDR] & REG_MCMDR_SPCRC)) {
858
+ crc = cpu_to_be32(crc32(~0, buf, len));
859
+ }
860
+
861
+ /* Give the descriptor back regardless of what happens. */
862
+ rx_desc.status_and_length &= ~RX_DESC_STATUS_OWNER_MASK;
863
+
864
+ buf_addr = rx_desc.rxbsa;
865
+ emc->regs[REG_CRXBSA] = buf_addr;
866
+ if (dma_memory_write(&address_space_memory, buf_addr, buf, len) ||
867
+ (!(emc->regs[REG_MCMDR] & REG_MCMDR_SPCRC) &&
868
+ dma_memory_write(&address_space_memory, buf_addr + len, crc_ptr,
869
+ 4))) {
870
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Bus error writing packet\n",
871
+ __func__);
872
+ emc_set_mista(emc, REG_MISTA_RXBERR);
873
+ emc_set_next_rx_descriptor(emc, &rx_desc, desc_addr);
874
+ emc_update_rx_irq(emc);
875
+ trace_npcm7xx_emc_rx_done(emc->regs[REG_CRXDSA]);
876
+ return len;
877
+ }
878
+
879
+ trace_npcm7xx_emc_received_packet(len);
880
+
881
+ /* Note: We've already verified len+4 <= 0xffff. */
882
+ rx_desc.status_and_length = len;
883
+ if (!(emc->regs[REG_MCMDR] & REG_MCMDR_SPCRC)) {
884
+ rx_desc.status_and_length += 4;
885
+ }
886
+ rx_desc.status_and_length |= RX_DESC_STATUS_RXGD;
887
+ emc_set_mista(emc, REG_MISTA_RXGD);
888
+
889
+ if (emc->regs[REG_MISTA] & emc->regs[REG_MIEN] & REG_MISTA_RXINTR) {
890
+ rx_desc.status_and_length |= RX_DESC_STATUS_RXINTR;
891
+ }
892
+ if (long_frame) {
893
+ rx_desc.status_and_length |= RX_DESC_STATUS_PTLE;
894
+ }
895
+
896
+ emc_set_next_rx_descriptor(emc, &rx_desc, desc_addr);
897
+ emc_update_rx_irq(emc);
898
+ trace_npcm7xx_emc_rx_done(emc->regs[REG_CRXDSA]);
899
+ return len;
900
+}
901
+
902
+static void emc_try_receive_next_packet(NPCM7xxEMCState *emc)
903
+{
904
+ if (emc_can_receive(qemu_get_queue(emc->nic))) {
905
+ qemu_flush_queued_packets(qemu_get_queue(emc->nic));
906
+ }
907
+}
908
+
909
+static uint64_t npcm7xx_emc_read(void *opaque, hwaddr offset, unsigned size)
910
+{
911
+ NPCM7xxEMCState *emc = opaque;
182
+ uint32_t reg = offset / sizeof(uint32_t);
912
+ uint32_t reg = offset / sizeof(uint32_t);
183
+ NPCM7xxCLKState *s = opaque;
913
+ uint32_t result;
184
+ int64_t now_ns;
914
+
185
+ uint32_t value = 0;
915
+ if (reg >= NPCM7XX_NUM_EMC_REGS) {
186
+
187
+ if (reg >= NPCM7XX_CLK_NR_REGS) {
188
+ qemu_log_mask(LOG_GUEST_ERROR,
916
+ qemu_log_mask(LOG_GUEST_ERROR,
189
+ "%s: offset 0x%04" HWADDR_PRIx " out of range\n",
917
+ "%s: Invalid offset 0x%04" HWADDR_PRIx "\n",
190
+ __func__, offset);
918
+ __func__, offset);
191
+ return 0;
919
+ return 0;
192
+ }
920
+ }
193
+
921
+
194
+ switch (reg) {
922
+ switch (reg) {
195
+ case NPCM7XX_CLK_SWRSTR:
923
+ case REG_MIID:
924
+ /*
925
+ * We don't implement MII. For determinism, always return zero as
926
+ * writes record the last value written for debugging purposes.
927
+ */
928
+ qemu_log_mask(LOG_UNIMP, "%s: Read of MIID, returning 0\n", __func__);
929
+ result = 0;
930
+ break;
931
+ case REG_TSDR:
932
+ case REG_RSDR:
196
+ qemu_log_mask(LOG_GUEST_ERROR,
933
+ qemu_log_mask(LOG_GUEST_ERROR,
197
+ "%s: register @ 0x%04" HWADDR_PRIx " is write-only\n",
934
+ "%s: Read of write-only reg, %s/%d\n",
198
+ __func__, offset);
935
+ __func__, emc_reg_name(reg), reg);
199
+ break;
936
+ return 0;
200
+
201
+ case NPCM7XX_CLK_SECCNT:
202
+ now_ns = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
203
+ value = (now_ns - s->ref_ns) / NANOSECONDS_PER_SECOND;
204
+ break;
205
+
206
+ case NPCM7XX_CLK_CNTR25M:
207
+ now_ns = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
208
+ /*
209
+ * This register counts 25 MHz cycles, updating every 640 ns. It rolls
210
+ * over to zero every second.
211
+ *
212
+ * The 4 LSBs are always zero: (1e9 / 640) << 4 = 25000000.
213
+ */
214
+ value = (((now_ns - s->ref_ns) / 640) << 4) % NPCM7XX_TIMER_REF_HZ;
215
+ break;
216
+
217
+ default:
937
+ default:
218
+ value = s->regs[reg];
938
+ result = emc->regs[reg];
219
+ break;
939
+ break;
220
+ };
940
+ }
221
+
941
+
222
+ trace_npcm7xx_clk_read(offset, value);
942
+ trace_npcm7xx_emc_reg_read(emc->emc_num, result, emc_reg_name(reg), reg);
223
+
943
+ return result;
224
+ return value;
944
+}
225
+}
945
+
226
+
946
+static void npcm7xx_emc_write(void *opaque, hwaddr offset,
227
+static void npcm7xx_clk_write(void *opaque, hwaddr offset,
228
+ uint64_t v, unsigned size)
947
+ uint64_t v, unsigned size)
229
+{
948
+{
949
+ NPCM7xxEMCState *emc = opaque;
230
+ uint32_t reg = offset / sizeof(uint32_t);
950
+ uint32_t reg = offset / sizeof(uint32_t);
231
+ NPCM7xxCLKState *s = opaque;
232
+ uint32_t value = v;
951
+ uint32_t value = v;
233
+
952
+
234
+ trace_npcm7xx_clk_write(offset, value);
953
+ g_assert(size == sizeof(uint32_t));
235
+
954
+
236
+ if (reg >= NPCM7XX_CLK_NR_REGS) {
955
+ if (reg >= NPCM7XX_NUM_EMC_REGS) {
237
+ qemu_log_mask(LOG_GUEST_ERROR,
956
+ qemu_log_mask(LOG_GUEST_ERROR,
238
+ "%s: offset 0x%04" HWADDR_PRIx " out of range\n",
957
+ "%s: Invalid offset 0x%04" HWADDR_PRIx "\n",
239
+ __func__, offset);
958
+ __func__, offset);
240
+ return;
959
+ return;
241
+ }
960
+ }
242
+
961
+
962
+ trace_npcm7xx_emc_reg_write(emc->emc_num, emc_reg_name(reg), reg, value);
963
+
243
+ switch (reg) {
964
+ switch (reg) {
244
+ case NPCM7XX_CLK_SWRSTR:
965
+ case REG_CAMCMR:
245
+ qemu_log_mask(LOG_UNIMP, "%s: SW reset not implemented: 0x%02x\n",
966
+ emc->regs[reg] = value;
246
+ __func__, value);
967
+ break;
247
+ value = 0;
968
+ case REG_CAMEN:
248
+ break;
969
+ /* Only CAM0 is supported, don't pretend otherwise. */
249
+
970
+ if (value & ~1) {
250
+ case NPCM7XX_CLK_PLLCON0:
971
+ qemu_log_mask(LOG_GUEST_ERROR,
251
+ case NPCM7XX_CLK_PLLCON1:
972
+ "%s: Only CAM0 is supported, cannot enable others"
252
+ case NPCM7XX_CLK_PLLCON2:
973
+ ": 0x%x\n",
253
+ case NPCM7XX_CLK_PLLCONG:
974
+ __func__, value);
254
+ if (value & PLLCON_PWDEN) {
975
+ }
255
+ /* Power down -- clear lock and indicate loss of lock */
976
+ emc->regs[reg] = value & 1;
256
+ value &= ~PLLCON_LOKI;
977
+ break;
257
+ value |= PLLCON_LOKS;
978
+ case REG_CAMM_BASE + 0:
258
+ } else {
979
+ emc->regs[reg] = value;
259
+ /* Normal mode -- assume always locked */
980
+ emc->conf.macaddr.a[0] = value >> 24;
260
+ value |= PLLCON_LOKI;
981
+ emc->conf.macaddr.a[1] = value >> 16;
261
+ /* Keep LOKS unchanged unless cleared by writing 1 */
982
+ emc->conf.macaddr.a[2] = value >> 8;
262
+ if (value & PLLCON_LOKS) {
983
+ emc->conf.macaddr.a[3] = value >> 0;
263
+ value &= ~PLLCON_LOKS;
984
+ break;
264
+ } else {
985
+ case REG_CAML_BASE + 0:
265
+ value |= (value & PLLCON_LOKS);
986
+ emc->regs[reg] = value;
987
+ emc->conf.macaddr.a[4] = value >> 24;
988
+ emc->conf.macaddr.a[5] = value >> 16;
989
+ break;
990
+ case REG_MCMDR: {
991
+ uint32_t prev;
992
+ if (value & REG_MCMDR_SWR) {
993
+ emc_soft_reset(emc);
994
+ /* On h/w the reset happens over multiple cycles. For now KISS. */
995
+ break;
996
+ }
997
+ prev = emc->regs[reg];
998
+ emc->regs[reg] = value;
999
+ /* Update tx state. */
1000
+ if (!(prev & REG_MCMDR_TXON) &&
1001
+ (value & REG_MCMDR_TXON)) {
1002
+ emc->regs[REG_CTXDSA] = emc->regs[REG_TXDLSA];
1003
+ /*
1004
+ * Linux kernel turns TX on with CPU still holding descriptor,
1005
+ * which suggests we should wait for a write to TSDR before trying
1006
+ * to send a packet: so we don't send one here.
1007
+ */
1008
+ } else if ((prev & REG_MCMDR_TXON) &&
1009
+ !(value & REG_MCMDR_TXON)) {
1010
+ emc->regs[REG_MGSTA] |= REG_MGSTA_TXHA;
1011
+ }
1012
+ if (!(value & REG_MCMDR_TXON)) {
1013
+ emc_halt_tx(emc, 0);
1014
+ }
1015
+ /* Update rx state. */
1016
+ if (!(prev & REG_MCMDR_RXON) &&
1017
+ (value & REG_MCMDR_RXON)) {
1018
+ emc->regs[REG_CRXDSA] = emc->regs[REG_RXDLSA];
1019
+ } else if ((prev & REG_MCMDR_RXON) &&
1020
+ !(value & REG_MCMDR_RXON)) {
1021
+ emc->regs[REG_MGSTA] |= REG_MGSTA_RXHA;
1022
+ }
1023
+ if (!(value & REG_MCMDR_RXON)) {
1024
+ emc_halt_rx(emc, 0);
1025
+ }
1026
+ break;
1027
+ }
1028
+ case REG_TXDLSA:
1029
+ case REG_RXDLSA:
1030
+ case REG_DMARFC:
1031
+ case REG_MIID:
1032
+ emc->regs[reg] = value;
1033
+ break;
1034
+ case REG_MIEN:
1035
+ emc->regs[reg] = value;
1036
+ emc_update_irq_from_reg_change(emc);
1037
+ break;
1038
+ case REG_MISTA:
1039
+ /* Clear the bits that have 1 in "value". */
1040
+ emc->regs[reg] &= ~value;
1041
+ emc_update_irq_from_reg_change(emc);
1042
+ break;
1043
+ case REG_MGSTA:
1044
+ /* Clear the bits that have 1 in "value". */
1045
+ emc->regs[reg] &= ~value;
1046
+ break;
1047
+ case REG_TSDR:
1048
+ if (emc->regs[REG_MCMDR] & REG_MCMDR_TXON) {
1049
+ emc->tx_active = true;
1050
+ /* Keep trying to send packets until we run out. */
1051
+ while (emc->tx_active) {
1052
+ emc_try_send_next_packet(emc);
266
+ }
1053
+ }
267
+ }
1054
+ }
268
+ break;
1055
+ break;
269
+
1056
+ case REG_RSDR:
270
+ case NPCM7XX_CLK_CNTR25M:
1057
+ if (emc->regs[REG_MCMDR] & REG_MCMDR_RXON) {
1058
+ emc->rx_active = true;
1059
+ emc_try_receive_next_packet(emc);
1060
+ }
1061
+ break;
1062
+ case REG_MIIDA:
1063
+ emc->regs[reg] = value & ~REG_MIIDA_BUSY;
1064
+ break;
1065
+ case REG_MRPC:
1066
+ case REG_MRPCC:
1067
+ case REG_MREPC:
1068
+ case REG_CTXDSA:
1069
+ case REG_CTXBSA:
1070
+ case REG_CRXDSA:
1071
+ case REG_CRXBSA:
271
+ qemu_log_mask(LOG_GUEST_ERROR,
1072
+ qemu_log_mask(LOG_GUEST_ERROR,
272
+ "%s: register @ 0x%04" HWADDR_PRIx " is read-only\n",
1073
+ "%s: Write to read-only reg %s/%d\n",
273
+ __func__, offset);
1074
+ __func__, emc_reg_name(reg), reg);
274
+ return;
1075
+ break;
275
+ }
1076
+ default:
276
+
1077
+ qemu_log_mask(LOG_UNIMP, "%s: Write to unimplemented reg %s/%d\n",
277
+ s->regs[reg] = value;
1078
+ __func__, emc_reg_name(reg), reg);
278
+}
1079
+ break;
279
+
1080
+ }
280
+static const struct MemoryRegionOps npcm7xx_clk_ops = {
1081
+}
281
+ .read = npcm7xx_clk_read,
1082
+
282
+ .write = npcm7xx_clk_write,
1083
+static const struct MemoryRegionOps npcm7xx_emc_ops = {
1084
+ .read = npcm7xx_emc_read,
1085
+ .write = npcm7xx_emc_write,
283
+ .endianness = DEVICE_LITTLE_ENDIAN,
1086
+ .endianness = DEVICE_LITTLE_ENDIAN,
284
+ .valid = {
1087
+ .valid = {
285
+ .min_access_size = 4,
1088
+ .min_access_size = 4,
286
+ .max_access_size = 4,
1089
+ .max_access_size = 4,
287
+ .unaligned = false,
1090
+ .unaligned = false,
288
+ },
1091
+ },
289
+};
1092
+};
290
+
1093
+
291
+static void npcm7xx_clk_enter_reset(Object *obj, ResetType type)
1094
+static void emc_cleanup(NetClientState *nc)
292
+{
1095
+{
293
+ NPCM7xxCLKState *s = NPCM7XX_CLK(obj);
1096
+ /* Nothing to do yet. */
294
+
1097
+}
295
+ QEMU_BUILD_BUG_ON(sizeof(s->regs) != sizeof(cold_reset_values));
1098
+
296
+
1099
+static NetClientInfo net_npcm7xx_emc_info = {
297
+ switch (type) {
1100
+ .type = NET_CLIENT_DRIVER_NIC,
298
+ case RESET_TYPE_COLD:
1101
+ .size = sizeof(NICState),
299
+ memcpy(s->regs, cold_reset_values, sizeof(cold_reset_values));
1102
+ .can_receive = emc_can_receive,
300
+ s->ref_ns = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
1103
+ .receive = emc_receive,
301
+ return;
1104
+ .cleanup = emc_cleanup,
302
+ }
1105
+ .link_status_changed = emc_set_link,
303
+
1106
+};
304
+ /*
1107
+
305
+ * A small number of registers need to be reset on a core domain reset,
1108
+static void npcm7xx_emc_realize(DeviceState *dev, Error **errp)
306
+ * but no such reset type exists yet.
1109
+{
307
+ */
1110
+ NPCM7xxEMCState *emc = NPCM7XX_EMC(dev);
308
+ qemu_log_mask(LOG_UNIMP, "%s: reset type %d not implemented.",
1111
+ SysBusDevice *sbd = SYS_BUS_DEVICE(emc);
309
+ __func__, type);
1112
+
310
+}
1113
+ memory_region_init_io(&emc->iomem, OBJECT(emc), &npcm7xx_emc_ops, emc,
311
+
1114
+ TYPE_NPCM7XX_EMC, 4 * KiB);
312
+static void npcm7xx_clk_init(Object *obj)
1115
+ sysbus_init_mmio(sbd, &emc->iomem);
313
+{
1116
+ sysbus_init_irq(sbd, &emc->tx_irq);
314
+ NPCM7xxCLKState *s = NPCM7XX_CLK(obj);
1117
+ sysbus_init_irq(sbd, &emc->rx_irq);
315
+
1118
+
316
+ memory_region_init_io(&s->iomem, obj, &npcm7xx_clk_ops, s,
1119
+ qemu_macaddr_default_if_unset(&emc->conf.macaddr);
317
+ TYPE_NPCM7XX_CLK, 4 * KiB);
1120
+ emc->nic = qemu_new_nic(&net_npcm7xx_emc_info, &emc->conf,
318
+ sysbus_init_mmio(&s->parent, &s->iomem);
1121
+ object_get_typename(OBJECT(dev)), dev->id, emc);
319
+}
1122
+ qemu_format_nic_info_str(qemu_get_queue(emc->nic), emc->conf.macaddr.a);
320
+
1123
+}
321
+static const VMStateDescription vmstate_npcm7xx_clk = {
1124
+
322
+ .name = "npcm7xx-clk",
1125
+static void npcm7xx_emc_unrealize(DeviceState *dev)
1126
+{
1127
+ NPCM7xxEMCState *emc = NPCM7XX_EMC(dev);
1128
+
1129
+ qemu_del_nic(emc->nic);
1130
+}
1131
+
1132
+static const VMStateDescription vmstate_npcm7xx_emc = {
1133
+ .name = TYPE_NPCM7XX_EMC,
323
+ .version_id = 0,
1134
+ .version_id = 0,
324
+ .minimum_version_id = 0,
1135
+ .minimum_version_id = 0,
325
+ .fields = (VMStateField[]) {
1136
+ .fields = (VMStateField[]) {
326
+ VMSTATE_UINT32_ARRAY(regs, NPCM7xxCLKState, NPCM7XX_CLK_NR_REGS),
1137
+ VMSTATE_UINT8(emc_num, NPCM7xxEMCState),
327
+ VMSTATE_INT64(ref_ns, NPCM7xxCLKState),
1138
+ VMSTATE_UINT32_ARRAY(regs, NPCM7xxEMCState, NPCM7XX_NUM_EMC_REGS),
1139
+ VMSTATE_BOOL(tx_active, NPCM7xxEMCState),
1140
+ VMSTATE_BOOL(rx_active, NPCM7xxEMCState),
328
+ VMSTATE_END_OF_LIST(),
1141
+ VMSTATE_END_OF_LIST(),
329
+ },
1142
+ },
330
+};
1143
+};
331
+
1144
+
332
+static void npcm7xx_clk_class_init(ObjectClass *klass, void *data)
1145
+static Property npcm7xx_emc_properties[] = {
333
+{
1146
+ DEFINE_NIC_PROPERTIES(NPCM7xxEMCState, conf),
334
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
1147
+ DEFINE_PROP_END_OF_LIST(),
1148
+};
1149
+
1150
+static void npcm7xx_emc_class_init(ObjectClass *klass, void *data)
1151
+{
335
+ DeviceClass *dc = DEVICE_CLASS(klass);
1152
+ DeviceClass *dc = DEVICE_CLASS(klass);
336
+
1153
+
337
+ QEMU_BUILD_BUG_ON(NPCM7XX_CLK_REGS_END > NPCM7XX_CLK_NR_REGS);
1154
+ set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
338
+
1155
+ dc->desc = "NPCM7xx EMC Controller";
339
+ dc->desc = "NPCM7xx Clock Control Registers";
1156
+ dc->realize = npcm7xx_emc_realize;
340
+ dc->vmsd = &vmstate_npcm7xx_clk;
1157
+ dc->unrealize = npcm7xx_emc_unrealize;
341
+ rc->phases.enter = npcm7xx_clk_enter_reset;
1158
+ dc->reset = npcm7xx_emc_reset;
342
+}
1159
+ dc->vmsd = &vmstate_npcm7xx_emc;
343
+
1160
+ device_class_set_props(dc, npcm7xx_emc_properties);
344
+static const TypeInfo npcm7xx_clk_info = {
1161
+}
345
+ .name = TYPE_NPCM7XX_CLK,
1162
+
346
+ .parent = TYPE_SYS_BUS_DEVICE,
1163
+static const TypeInfo npcm7xx_emc_info = {
347
+ .instance_size = sizeof(NPCM7xxCLKState),
1164
+ .name = TYPE_NPCM7XX_EMC,
348
+ .instance_init = npcm7xx_clk_init,
1165
+ .parent = TYPE_SYS_BUS_DEVICE,
349
+ .class_init = npcm7xx_clk_class_init,
1166
+ .instance_size = sizeof(NPCM7xxEMCState),
1167
+ .class_init = npcm7xx_emc_class_init,
350
+};
1168
+};
351
+
1169
+
352
+static void npcm7xx_clk_register_type(void)
1170
+static void npcm7xx_emc_register_type(void)
353
+{
1171
+{
354
+ type_register_static(&npcm7xx_clk_info);
1172
+ type_register_static(&npcm7xx_emc_info);
355
+}
1173
+}
356
+type_init(npcm7xx_clk_register_type);
1174
+
357
diff --git a/hw/misc/meson.build b/hw/misc/meson.build
1175
+type_init(npcm7xx_emc_register_type)
1176
diff --git a/hw/net/meson.build b/hw/net/meson.build
358
index XXXXXXX..XXXXXXX 100644
1177
index XXXXXXX..XXXXXXX 100644
359
--- a/hw/misc/meson.build
1178
--- a/hw/net/meson.build
360
+++ b/hw/misc/meson.build
1179
+++ b/hw/net/meson.build
361
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_IMX', if_true: files(
1180
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_I82596_COMMON', if_true: files('i82596.c'))
362
softmmu_ss.add(when: 'CONFIG_MILKYMIST', if_true: files('milkymist-hpdmc.c', 'milkymist-pfpu.c'))
1181
softmmu_ss.add(when: 'CONFIG_SUNHME', if_true: files('sunhme.c'))
363
softmmu_ss.add(when: 'CONFIG_MAINSTONE', if_true: files('mst_fpga.c'))
1182
softmmu_ss.add(when: 'CONFIG_FTGMAC100', if_true: files('ftgmac100.c'))
364
softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files(
1183
softmmu_ss.add(when: 'CONFIG_SUNGEM', if_true: files('sungem.c'))
365
+ 'npcm7xx_clk.c',
1184
+softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_emc.c'))
366
'npcm7xx_gcr.c',
1185
367
))
1186
softmmu_ss.add(when: 'CONFIG_ETRAXFS', if_true: files('etraxfs_eth.c'))
368
softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files(
1187
softmmu_ss.add(when: 'CONFIG_COLDFIRE', if_true: files('mcf_fec.c'))
369
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
1188
diff --git a/hw/net/trace-events b/hw/net/trace-events
370
index XXXXXXX..XXXXXXX 100644
1189
index XXXXXXX..XXXXXXX 100644
371
--- a/hw/misc/trace-events
1190
--- a/hw/net/trace-events
372
+++ b/hw/misc/trace-events
1191
+++ b/hw/net/trace-events
373
@@ -XXX,XX +XXX,XX @@ mos6522_set_sr_int(void) "set sr_int"
1192
@@ -XXX,XX +XXX,XX @@ imx_fec_receive_last(int last) "rx frame flags 0x%04x"
374
mos6522_write(uint64_t addr, uint64_t val) "reg=0x%"PRIx64 " val=0x%"PRIx64
1193
imx_enet_receive(size_t size) "len %zu"
375
mos6522_read(uint64_t addr, unsigned val) "reg=0x%"PRIx64 " val=0x%x"
1194
imx_enet_receive_len(uint64_t addr, int len) "rx_bd 0x%"PRIx64" length %d"
376
1195
imx_enet_receive_last(int last) "rx frame flags 0x%04x"
377
+# npcm7xx_clk.c
1196
+
378
+npcm7xx_clk_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
1197
+# npcm7xx_emc.c
379
+npcm7xx_clk_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
1198
+npcm7xx_emc_reset(int emc_num) "Resetting emc%d"
380
+
1199
+npcm7xx_emc_update_tx_irq(int level) "Setting tx irq to %d"
381
# npcm7xx_gcr.c
1200
+npcm7xx_emc_update_rx_irq(int level) "Setting rx irq to %d"
382
npcm7xx_gcr_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
1201
+npcm7xx_emc_set_mista(uint32_t flags) "ORing 0x%x into MISTA"
383
npcm7xx_gcr_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
1202
+npcm7xx_emc_cpu_owned_desc(uint32_t addr) "Can't process cpu-owned descriptor @0x%x"
1203
+npcm7xx_emc_sent_packet(uint32_t len) "Sent %u byte packet"
1204
+npcm7xx_emc_tx_done(uint32_t ctxdsa) "TX done, CTXDSA=0x%x"
1205
+npcm7xx_emc_can_receive(int can_receive) "Can receive: %d"
1206
+npcm7xx_emc_packet_filtered_out(const char* fail_reason) "Packet filtered out: %s"
1207
+npcm7xx_emc_packet_dropped(uint32_t len) "%u byte packet dropped"
1208
+npcm7xx_emc_receiving_packet(uint32_t len) "Receiving %u byte packet"
1209
+npcm7xx_emc_received_packet(uint32_t len) "Received %u byte packet"
1210
+npcm7xx_emc_rx_done(uint32_t crxdsa) "RX done, CRXDSA=0x%x"
1211
+npcm7xx_emc_reg_read(int emc_num, uint32_t result, const char *name, int regno) "emc%d: 0x%x = reg[%s/%d]"
1212
+npcm7xx_emc_reg_write(int emc_num, const char *name, int regno, uint32_t value) "emc%d: reg[%s/%d] = 0x%x"
384
--
1213
--
385
2.20.1
1214
2.20.1
386
1215
387
1216
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Doug Evans <dje@google.com>
2
2
3
This implements a device model for the NPCM7xx SPI flash controller.
3
This is a 10/100 ethernet device that has several features.
4
Only the ones needed by the Linux driver have been implemented.
5
See npcm7xx_emc.c for a list of unimplemented features.
4
6
5
Direct reads and writes, and user-mode transactions have been tested in
7
Reviewed-by: Hao Wu <wuhaotsh@google.com>
6
various modes. Protection features are not implemented yet.
8
Reviewed-by: Avi Fishman <avi.fishman@nuvoton.com>
7
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
All the FIU instances are available in the SoC's address space,
10
Signed-off-by: Doug Evans <dje@google.com>
9
regardless of whether or not they're connected to actual flash chips.
11
Message-id: 20210218212453.831406-3-dje@google.com
10
11
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
12
Reviewed-by: Cédric Le Goater <clg@kaod.org>
13
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
14
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
15
Tested-by: Alexander Bulekov <alxndr@bu.edu>
16
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
17
Message-id: 20200911052101.2602693-11-hskinnemoen@google.com
18
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
19
---
13
---
20
include/hw/arm/npcm7xx.h | 2 +
14
docs/system/arm/nuvoton.rst | 3 ++-
21
include/hw/ssi/npcm7xx_fiu.h | 73 +++++
15
include/hw/arm/npcm7xx.h | 2 ++
22
hw/arm/npcm7xx.c | 58 ++++
16
hw/arm/npcm7xx.c | 50 +++++++++++++++++++++++++++++++++++--
23
hw/ssi/npcm7xx_fiu.c | 572 +++++++++++++++++++++++++++++++++++
17
3 files changed, 52 insertions(+), 3 deletions(-)
24
hw/arm/Kconfig | 1 +
25
hw/ssi/meson.build | 1 +
26
hw/ssi/trace-events | 11 +
27
7 files changed, 718 insertions(+)
28
create mode 100644 include/hw/ssi/npcm7xx_fiu.h
29
create mode 100644 hw/ssi/npcm7xx_fiu.c
30
18
19
diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst
20
index XXXXXXX..XXXXXXX 100644
21
--- a/docs/system/arm/nuvoton.rst
22
+++ b/docs/system/arm/nuvoton.rst
23
@@ -XXX,XX +XXX,XX @@ Supported devices
24
* Analog to Digital Converter (ADC)
25
* Pulse Width Modulation (PWM)
26
* SMBus controller (SMBF)
27
+ * Ethernet controller (EMC)
28
29
Missing devices
30
---------------
31
@@ -XXX,XX +XXX,XX @@ Missing devices
32
* Shared memory (SHM)
33
* eSPI slave interface
34
35
- * Ethernet controllers (GMAC and EMC)
36
+ * Ethernet controller (GMAC)
37
* USB device (USBD)
38
* Peripheral SPI controller (PSPI)
39
* SD/MMC host
31
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
40
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
32
index XXXXXXX..XXXXXXX 100644
41
index XXXXXXX..XXXXXXX 100644
33
--- a/include/hw/arm/npcm7xx.h
42
--- a/include/hw/arm/npcm7xx.h
34
+++ b/include/hw/arm/npcm7xx.h
43
+++ b/include/hw/arm/npcm7xx.h
35
@@ -XXX,XX +XXX,XX @@
44
@@ -XXX,XX +XXX,XX @@
36
#include "hw/misc/npcm7xx_gcr.h"
45
#include "hw/misc/npcm7xx_gcr.h"
46
#include "hw/misc/npcm7xx_pwm.h"
47
#include "hw/misc/npcm7xx_rng.h"
48
+#include "hw/net/npcm7xx_emc.h"
37
#include "hw/nvram/npcm7xx_otp.h"
49
#include "hw/nvram/npcm7xx_otp.h"
38
#include "hw/timer/npcm7xx_timer.h"
50
#include "hw/timer/npcm7xx_timer.h"
39
+#include "hw/ssi/npcm7xx_fiu.h"
51
#include "hw/ssi/npcm7xx_fiu.h"
40
#include "target/arm/cpu.h"
41
42
#define NPCM7XX_MAX_NUM_CPUS (2)
43
@@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState {
52
@@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState {
44
NPCM7xxOTPState key_storage;
53
EHCISysBusState ehci;
45
NPCM7xxOTPState fuse_array;
54
OHCISysBusState ohci;
46
NPCM7xxMCState mc;
55
NPCM7xxFIUState fiu[2];
47
+ NPCM7xxFIUState fiu[2];
56
+ NPCM7xxEMCState emc[2];
48
} NPCM7xxState;
57
} NPCM7xxState;
49
58
50
#define TYPE_NPCM7XX "npcm7xx"
59
#define TYPE_NPCM7XX "npcm7xx"
51
diff --git a/include/hw/ssi/npcm7xx_fiu.h b/include/hw/ssi/npcm7xx_fiu.h
52
new file mode 100644
53
index XXXXXXX..XXXXXXX
54
--- /dev/null
55
+++ b/include/hw/ssi/npcm7xx_fiu.h
56
@@ -XXX,XX +XXX,XX @@
57
+/*
58
+ * Nuvoton NPCM7xx Flash Interface Unit (FIU)
59
+ *
60
+ * Copyright 2020 Google LLC
61
+ *
62
+ * This program is free software; you can redistribute it and/or modify it
63
+ * under the terms of the GNU General Public License as published by the
64
+ * Free Software Foundation; either version 2 of the License, or
65
+ * (at your option) any later version.
66
+ *
67
+ * This program is distributed in the hope that it will be useful, but WITHOUT
68
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
69
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
70
+ * for more details.
71
+ */
72
+#ifndef NPCM7XX_FIU_H
73
+#define NPCM7XX_FIU_H
74
+
75
+#include "hw/ssi/ssi.h"
76
+#include "hw/sysbus.h"
77
+
78
+/*
79
+ * Number of registers in our device state structure. Don't change this without
80
+ * incrementing the version_id in the vmstate.
81
+ */
82
+#define NPCM7XX_FIU_NR_REGS (0x7c / sizeof(uint32_t))
83
+
84
+typedef struct NPCM7xxFIUState NPCM7xxFIUState;
85
+
86
+/**
87
+ * struct NPCM7xxFIUFlash - Per-chipselect flash controller state.
88
+ * @direct_access: Memory region for direct flash access.
89
+ * @fiu: Pointer to flash controller shared state.
90
+ */
91
+typedef struct NPCM7xxFIUFlash {
92
+ MemoryRegion direct_access;
93
+ NPCM7xxFIUState *fiu;
94
+} NPCM7xxFIUFlash;
95
+
96
+/**
97
+ * NPCM7xxFIUState - Device state for one Flash Interface Unit.
98
+ * @parent: System bus device.
99
+ * @mmio: Memory region for register access.
100
+ * @cs_count: Number of flash chips that may be connected to this module.
101
+ * @active_cs: Currently active chip select, or -1 if no chip is selected.
102
+ * @cs_lines: GPIO lines that may be wired to flash chips.
103
+ * @flash: Array of @cs_count per-flash-chip state objects.
104
+ * @spi: The SPI bus mastered by this controller.
105
+ * @regs: Register contents.
106
+ *
107
+ * Each FIU has a shared bank of registers, and controls up to four chip
108
+ * selects. Each chip select has a dedicated memory region which may be used to
109
+ * read and write the flash connected to that chip select as if it were memory.
110
+ */
111
+struct NPCM7xxFIUState {
112
+ SysBusDevice parent;
113
+
114
+ MemoryRegion mmio;
115
+
116
+ int32_t cs_count;
117
+ int32_t active_cs;
118
+ qemu_irq *cs_lines;
119
+ NPCM7xxFIUFlash *flash;
120
+
121
+ SSIBus *spi;
122
+
123
+ uint32_t regs[NPCM7XX_FIU_NR_REGS];
124
+};
125
+
126
+#define TYPE_NPCM7XX_FIU "npcm7xx-fiu"
127
+#define NPCM7XX_FIU(obj) OBJECT_CHECK(NPCM7xxFIUState, (obj), TYPE_NPCM7XX_FIU)
128
+
129
+#endif /* NPCM7XX_FIU_H */
130
diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c
60
diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c
131
index XXXXXXX..XXXXXXX 100644
61
index XXXXXXX..XXXXXXX 100644
132
--- a/hw/arm/npcm7xx.c
62
--- a/hw/arm/npcm7xx.c
133
+++ b/hw/arm/npcm7xx.c
63
+++ b/hw/arm/npcm7xx.c
134
@@ -XXX,XX +XXX,XX @@ static const hwaddr npcm7xx_uart_addr[] = {
64
@@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt {
135
0xf0004000,
65
NPCM7XX_UART1_IRQ,
66
NPCM7XX_UART2_IRQ,
67
NPCM7XX_UART3_IRQ,
68
+ NPCM7XX_EMC1RX_IRQ = 15,
69
+ NPCM7XX_EMC1TX_IRQ,
70
NPCM7XX_TIMER0_IRQ = 32, /* Timer Module 0 */
71
NPCM7XX_TIMER1_IRQ,
72
NPCM7XX_TIMER2_IRQ,
73
@@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt {
74
NPCM7XX_SMBUS15_IRQ,
75
NPCM7XX_PWM0_IRQ = 93, /* PWM module 0 */
76
NPCM7XX_PWM1_IRQ, /* PWM module 1 */
77
+ NPCM7XX_EMC2RX_IRQ = 114,
78
+ NPCM7XX_EMC2TX_IRQ,
79
NPCM7XX_GPIO0_IRQ = 116,
80
NPCM7XX_GPIO1_IRQ,
81
NPCM7XX_GPIO2_IRQ,
82
@@ -XXX,XX +XXX,XX @@ static const hwaddr npcm7xx_smbus_addr[] = {
83
0xf008f000,
136
};
84
};
137
85
138
+/* Direct memory-mapped access to SPI0 CS0-1. */
86
+/* Register base address for each EMC Module */
139
+static const hwaddr npcm7xx_fiu0_flash_addr[] = {
87
+static const hwaddr npcm7xx_emc_addr[] = {
140
+ 0x80000000, /* CS0 */
88
+ 0xf0825000,
141
+ 0x88000000, /* CS1 */
89
+ 0xf0826000,
142
+};
90
+};
143
+
91
+
144
+/* Direct memory-mapped access to SPI3 CS0-3. */
92
static const struct {
145
+static const hwaddr npcm7xx_fiu3_flash_addr[] = {
93
hwaddr regs_addr;
146
+ 0xa0000000, /* CS0 */
94
uint32_t unconnected_pins;
147
+ 0xa8000000, /* CS1 */
148
+ 0xb0000000, /* CS2 */
149
+ 0xb8000000, /* CS3 */
150
+};
151
+
152
+static const struct {
153
+ const char *name;
154
+ hwaddr regs_addr;
155
+ int cs_count;
156
+ const hwaddr *flash_addr;
157
+} npcm7xx_fiu[] = {
158
+ {
159
+ .name = "fiu0",
160
+ .regs_addr = 0xfb000000,
161
+ .cs_count = ARRAY_SIZE(npcm7xx_fiu0_flash_addr),
162
+ .flash_addr = npcm7xx_fiu0_flash_addr,
163
+ }, {
164
+ .name = "fiu3",
165
+ .regs_addr = 0xc0000000,
166
+ .cs_count = ARRAY_SIZE(npcm7xx_fiu3_flash_addr),
167
+ .flash_addr = npcm7xx_fiu3_flash_addr,
168
+ },
169
+};
170
+
171
static void npcm7xx_write_secondary_boot(ARMCPU *cpu,
172
const struct arm_boot_info *info)
173
{
174
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj)
95
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj)
175
for (i = 0; i < ARRAY_SIZE(s->tim); i++) {
96
for (i = 0; i < ARRAY_SIZE(s->pwm); i++) {
176
object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER);
97
object_initialize_child(obj, "pwm[*]", &s->pwm[i], TYPE_NPCM7XX_PWM);
177
}
98
}
178
+
99
+
179
+ QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_fiu) != ARRAY_SIZE(s->fiu));
100
+ for (i = 0; i < ARRAY_SIZE(s->emc); i++) {
180
+ for (i = 0; i < ARRAY_SIZE(s->fiu); i++) {
101
+ object_initialize_child(obj, "emc[*]", &s->emc[i], TYPE_NPCM7XX_EMC);
181
+ object_initialize_child(obj, npcm7xx_fiu[i].name, &s->fiu[i],
182
+ TYPE_NPCM7XX_FIU);
183
+ }
102
+ }
184
}
103
}
185
104
186
static void npcm7xx_realize(DeviceState *dev, Error **errp)
105
static void npcm7xx_realize(DeviceState *dev, Error **errp)
187
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
106
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
188
serial_hd(i), DEVICE_LITTLE_ENDIAN);
107
sysbus_connect_irq(sbd, i, npcm7xx_irq(s, NPCM7XX_PWM0_IRQ + i));
189
}
108
}
190
109
191
+ /*
110
+ /*
192
+ * Flash Interface Unit (FIU). Can fail if incorrect number of chip selects
111
+ * EMC Modules. Cannot fail.
193
+ * specified, but this is a programming error.
112
+ * The mapping of the device to its netdev backend works as follows:
113
+ * emc[i] = nd_table[i]
114
+ * This works around the inability to specify the netdev property for the
115
+ * emc device: it's not pluggable and thus the -device option can't be
116
+ * used.
194
+ */
117
+ */
195
+ QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_fiu) != ARRAY_SIZE(s->fiu));
118
+ QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_emc_addr) != ARRAY_SIZE(s->emc));
196
+ for (i = 0; i < ARRAY_SIZE(s->fiu); i++) {
119
+ QEMU_BUILD_BUG_ON(ARRAY_SIZE(s->emc) != 2);
197
+ SysBusDevice *sbd = SYS_BUS_DEVICE(&s->fiu[i]);
120
+ for (i = 0; i < ARRAY_SIZE(s->emc); i++) {
198
+ int j;
121
+ s->emc[i].emc_num = i;
199
+
122
+ SysBusDevice *sbd = SYS_BUS_DEVICE(&s->emc[i]);
200
+ object_property_set_int(OBJECT(sbd), "cs-count",
123
+ if (nd_table[i].used) {
201
+ npcm7xx_fiu[i].cs_count, &error_abort);
124
+ qemu_check_nic_model(&nd_table[i], TYPE_NPCM7XX_EMC);
125
+ qdev_set_nic_properties(DEVICE(sbd), &nd_table[i]);
126
+ }
127
+ /*
128
+ * The device exists regardless of whether it's connected to a QEMU
129
+ * netdev backend. So always instantiate it even if there is no
130
+ * backend.
131
+ */
202
+ sysbus_realize(sbd, &error_abort);
132
+ sysbus_realize(sbd, &error_abort);
203
+
133
+ sysbus_mmio_map(sbd, 0, npcm7xx_emc_addr[i]);
204
+ sysbus_mmio_map(sbd, 0, npcm7xx_fiu[i].regs_addr);
134
+ int tx_irq = i == 0 ? NPCM7XX_EMC1TX_IRQ : NPCM7XX_EMC2TX_IRQ;
205
+ for (j = 0; j < npcm7xx_fiu[i].cs_count; j++) {
135
+ int rx_irq = i == 0 ? NPCM7XX_EMC1RX_IRQ : NPCM7XX_EMC2RX_IRQ;
206
+ sysbus_mmio_map(sbd, j + 1, npcm7xx_fiu[i].flash_addr[j]);
136
+ /*
207
+ }
137
+ * N.B. The values for the second argument sysbus_connect_irq are
138
+ * chosen to match the registration order in npcm7xx_emc_realize.
139
+ */
140
+ sysbus_connect_irq(sbd, 0, npcm7xx_irq(s, tx_irq));
141
+ sysbus_connect_irq(sbd, 1, npcm7xx_irq(s, rx_irq));
208
+ }
142
+ }
209
+
143
+
210
/* RAM2 (SRAM) */
144
/*
211
memory_region_init_ram(&s->sram, OBJECT(dev), "ram2",
145
* Flash Interface Unit (FIU). Can fail if incorrect number of chip selects
212
NPCM7XX_RAM2_SZ, &error_abort);
146
* specified, but this is a programming error.
213
diff --git a/hw/ssi/npcm7xx_fiu.c b/hw/ssi/npcm7xx_fiu.c
147
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
214
new file mode 100644
148
create_unimplemented_device("npcm7xx.vcd", 0xf0810000, 64 * KiB);
215
index XXXXXXX..XXXXXXX
149
create_unimplemented_device("npcm7xx.ece", 0xf0820000, 8 * KiB);
216
--- /dev/null
150
create_unimplemented_device("npcm7xx.vdma", 0xf0822000, 8 * KiB);
217
+++ b/hw/ssi/npcm7xx_fiu.c
151
- create_unimplemented_device("npcm7xx.emc1", 0xf0825000, 4 * KiB);
218
@@ -XXX,XX +XXX,XX @@
152
- create_unimplemented_device("npcm7xx.emc2", 0xf0826000, 4 * KiB);
219
+/*
153
create_unimplemented_device("npcm7xx.usbd[0]", 0xf0830000, 4 * KiB);
220
+ * Nuvoton NPCM7xx Flash Interface Unit (FIU)
154
create_unimplemented_device("npcm7xx.usbd[1]", 0xf0831000, 4 * KiB);
221
+ *
155
create_unimplemented_device("npcm7xx.usbd[2]", 0xf0832000, 4 * KiB);
222
+ * Copyright 2020 Google LLC
223
+ *
224
+ * This program is free software; you can redistribute it and/or modify it
225
+ * under the terms of the GNU General Public License as published by the
226
+ * Free Software Foundation; either version 2 of the License, or
227
+ * (at your option) any later version.
228
+ *
229
+ * This program is distributed in the hope that it will be useful, but WITHOUT
230
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
231
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
232
+ * for more details.
233
+ */
234
+
235
+#include "qemu/osdep.h"
236
+
237
+#include "hw/irq.h"
238
+#include "hw/qdev-properties.h"
239
+#include "hw/ssi/npcm7xx_fiu.h"
240
+#include "migration/vmstate.h"
241
+#include "qapi/error.h"
242
+#include "qemu/error-report.h"
243
+#include "qemu/log.h"
244
+#include "qemu/module.h"
245
+#include "qemu/units.h"
246
+
247
+#include "trace.h"
248
+
249
+/* Up to 128 MiB of flash may be accessed directly as memory. */
250
+#define NPCM7XX_FIU_FLASH_WINDOW_SIZE (128 * MiB)
251
+
252
+/* Each module has 4 KiB of register space. Only a fraction of it is used. */
253
+#define NPCM7XX_FIU_CTRL_REGS_SIZE (4 * KiB)
254
+
255
+/* 32-bit FIU register indices. */
256
+enum NPCM7xxFIURegister {
257
+ NPCM7XX_FIU_DRD_CFG,
258
+ NPCM7XX_FIU_DWR_CFG,
259
+ NPCM7XX_FIU_UMA_CFG,
260
+ NPCM7XX_FIU_UMA_CTS,
261
+ NPCM7XX_FIU_UMA_CMD,
262
+ NPCM7XX_FIU_UMA_ADDR,
263
+ NPCM7XX_FIU_PRT_CFG,
264
+ NPCM7XX_FIU_UMA_DW0 = 0x0020 / sizeof(uint32_t),
265
+ NPCM7XX_FIU_UMA_DW1,
266
+ NPCM7XX_FIU_UMA_DW2,
267
+ NPCM7XX_FIU_UMA_DW3,
268
+ NPCM7XX_FIU_UMA_DR0,
269
+ NPCM7XX_FIU_UMA_DR1,
270
+ NPCM7XX_FIU_UMA_DR2,
271
+ NPCM7XX_FIU_UMA_DR3,
272
+ NPCM7XX_FIU_PRT_CMD0,
273
+ NPCM7XX_FIU_PRT_CMD1,
274
+ NPCM7XX_FIU_PRT_CMD2,
275
+ NPCM7XX_FIU_PRT_CMD3,
276
+ NPCM7XX_FIU_PRT_CMD4,
277
+ NPCM7XX_FIU_PRT_CMD5,
278
+ NPCM7XX_FIU_PRT_CMD6,
279
+ NPCM7XX_FIU_PRT_CMD7,
280
+ NPCM7XX_FIU_PRT_CMD8,
281
+ NPCM7XX_FIU_PRT_CMD9,
282
+ NPCM7XX_FIU_CFG = 0x78 / sizeof(uint32_t),
283
+ NPCM7XX_FIU_REGS_END,
284
+};
285
+
286
+/* FIU_{DRD,DWR,UMA,PTR}_CFG cannot be written when this bit is set. */
287
+#define NPCM7XX_FIU_CFG_LCK BIT(31)
288
+
289
+/* Direct Read configuration register fields. */
290
+#define FIU_DRD_CFG_ADDSIZ(rv) extract32(rv, 16, 2)
291
+#define FIU_ADDSIZ_3BYTES 0
292
+#define FIU_ADDSIZ_4BYTES 1
293
+#define FIU_DRD_CFG_DBW(rv) extract32(rv, 12, 2)
294
+#define FIU_DRD_CFG_ACCTYPE(rv) extract32(rv, 8, 2)
295
+#define FIU_DRD_CFG_RDCMD(rv) extract32(rv, 0, 8)
296
+
297
+/* Direct Write configuration register fields. */
298
+#define FIU_DWR_CFG_ADDSIZ(rv) extract32(rv, 16, 2)
299
+#define FIU_DWR_CFG_WRCMD(rv) extract32(rv, 0, 8)
300
+
301
+/* User-Mode Access register fields. */
302
+
303
+/* Command Mode Lock and the bits protected by it. */
304
+#define FIU_UMA_CFG_CMMLCK BIT(30)
305
+#define FIU_UMA_CFG_CMMLCK_MASK 0x00000403
306
+
307
+#define FIU_UMA_CFG_RDATSIZ(rv) extract32(rv, 24, 5)
308
+#define FIU_UMA_CFG_DBSIZ(rv) extract32(rv, 21, 3)
309
+#define FIU_UMA_CFG_WDATSIZ(rv) extract32(rv, 16, 5)
310
+#define FIU_UMA_CFG_ADDSIZ(rv) extract32(rv, 11, 3)
311
+#define FIU_UMA_CFG_CMDSIZ(rv) extract32(rv, 10, 1)
312
+#define FIU_UMA_CFG_DBPCK(rv) extract32(rv, 6, 2)
313
+
314
+#define FIU_UMA_CTS_RDYIE BIT(25)
315
+#define FIU_UMA_CTS_RDYST BIT(24)
316
+#define FIU_UMA_CTS_SW_CS BIT(16)
317
+#define FIU_UMA_CTS_DEV_NUM(rv) extract32(rv, 8, 2)
318
+#define FIU_UMA_CTS_EXEC_DONE BIT(0)
319
+
320
+/*
321
+ * Returns the index of flash in the fiu->flash array. This corresponds to the
322
+ * chip select ID of the flash.
323
+ */
324
+static int npcm7xx_fiu_cs_index(NPCM7xxFIUState *fiu, NPCM7xxFIUFlash *flash)
325
+{
326
+ int index = flash - fiu->flash;
327
+
328
+ g_assert(index >= 0 && index < fiu->cs_count);
329
+
330
+ return index;
331
+}
332
+
333
+/* Assert the chip select specified in the UMA Control/Status Register. */
334
+static void npcm7xx_fiu_select(NPCM7xxFIUState *s, int cs_id)
335
+{
336
+ trace_npcm7xx_fiu_select(DEVICE(s)->canonical_path, cs_id);
337
+
338
+ if (cs_id < s->cs_count) {
339
+ qemu_irq_lower(s->cs_lines[cs_id]);
340
+ } else {
341
+ qemu_log_mask(LOG_GUEST_ERROR,
342
+ "%s: UMA to CS%d; this module has only %d chip selects",
343
+ DEVICE(s)->canonical_path, cs_id, s->cs_count);
344
+ cs_id = -1;
345
+ }
346
+
347
+ s->active_cs = cs_id;
348
+}
349
+
350
+/* Deassert the currently active chip select. */
351
+static void npcm7xx_fiu_deselect(NPCM7xxFIUState *s)
352
+{
353
+ if (s->active_cs < 0) {
354
+ return;
355
+ }
356
+
357
+ trace_npcm7xx_fiu_deselect(DEVICE(s)->canonical_path, s->active_cs);
358
+
359
+ qemu_irq_raise(s->cs_lines[s->active_cs]);
360
+ s->active_cs = -1;
361
+}
362
+
363
+/* Direct flash memory read handler. */
364
+static uint64_t npcm7xx_fiu_flash_read(void *opaque, hwaddr addr,
365
+ unsigned int size)
366
+{
367
+ NPCM7xxFIUFlash *f = opaque;
368
+ NPCM7xxFIUState *fiu = f->fiu;
369
+ uint64_t value = 0;
370
+ uint32_t drd_cfg;
371
+ int dummy_cycles;
372
+ int i;
373
+
374
+ if (fiu->active_cs != -1) {
375
+ qemu_log_mask(LOG_GUEST_ERROR,
376
+ "%s: direct flash read with CS%d already active",
377
+ DEVICE(fiu)->canonical_path, fiu->active_cs);
378
+ }
379
+
380
+ npcm7xx_fiu_select(fiu, npcm7xx_fiu_cs_index(fiu, f));
381
+
382
+ drd_cfg = fiu->regs[NPCM7XX_FIU_DRD_CFG];
383
+ ssi_transfer(fiu->spi, FIU_DRD_CFG_RDCMD(drd_cfg));
384
+
385
+ switch (FIU_DRD_CFG_ADDSIZ(drd_cfg)) {
386
+ case FIU_ADDSIZ_4BYTES:
387
+ ssi_transfer(fiu->spi, extract32(addr, 24, 8));
388
+ /* fall through */
389
+ case FIU_ADDSIZ_3BYTES:
390
+ ssi_transfer(fiu->spi, extract32(addr, 16, 8));
391
+ ssi_transfer(fiu->spi, extract32(addr, 8, 8));
392
+ ssi_transfer(fiu->spi, extract32(addr, 0, 8));
393
+ break;
394
+
395
+ default:
396
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: bad address size %d\n",
397
+ DEVICE(fiu)->canonical_path, FIU_DRD_CFG_ADDSIZ(drd_cfg));
398
+ break;
399
+ }
400
+
401
+ /* Flash chip model expects one transfer per dummy bit, not byte */
402
+ dummy_cycles =
403
+ (FIU_DRD_CFG_DBW(drd_cfg) * 8) >> FIU_DRD_CFG_ACCTYPE(drd_cfg);
404
+ for (i = 0; i < dummy_cycles; i++) {
405
+ ssi_transfer(fiu->spi, 0);
406
+ }
407
+
408
+ for (i = 0; i < size; i++) {
409
+ value = deposit64(value, 8 * i, 8, ssi_transfer(fiu->spi, 0));
410
+ }
411
+
412
+ trace_npcm7xx_fiu_flash_read(DEVICE(fiu)->canonical_path, fiu->active_cs,
413
+ addr, size, value);
414
+
415
+ npcm7xx_fiu_deselect(fiu);
416
+
417
+ return value;
418
+}
419
+
420
+/* Direct flash memory write handler. */
421
+static void npcm7xx_fiu_flash_write(void *opaque, hwaddr addr, uint64_t v,
422
+ unsigned int size)
423
+{
424
+ NPCM7xxFIUFlash *f = opaque;
425
+ NPCM7xxFIUState *fiu = f->fiu;
426
+ uint32_t dwr_cfg;
427
+ int cs_id;
428
+ int i;
429
+
430
+ if (fiu->active_cs != -1) {
431
+ qemu_log_mask(LOG_GUEST_ERROR,
432
+ "%s: direct flash write with CS%d already active",
433
+ DEVICE(fiu)->canonical_path, fiu->active_cs);
434
+ }
435
+
436
+ cs_id = npcm7xx_fiu_cs_index(fiu, f);
437
+ trace_npcm7xx_fiu_flash_write(DEVICE(fiu)->canonical_path, cs_id, addr,
438
+ size, v);
439
+ npcm7xx_fiu_select(fiu, cs_id);
440
+
441
+ dwr_cfg = fiu->regs[NPCM7XX_FIU_DWR_CFG];
442
+ ssi_transfer(fiu->spi, FIU_DWR_CFG_WRCMD(dwr_cfg));
443
+
444
+ switch (FIU_DWR_CFG_ADDSIZ(dwr_cfg)) {
445
+ case FIU_ADDSIZ_4BYTES:
446
+ ssi_transfer(fiu->spi, extract32(addr, 24, 8));
447
+ /* fall through */
448
+ case FIU_ADDSIZ_3BYTES:
449
+ ssi_transfer(fiu->spi, extract32(addr, 16, 8));
450
+ ssi_transfer(fiu->spi, extract32(addr, 8, 8));
451
+ ssi_transfer(fiu->spi, extract32(addr, 0, 8));
452
+ break;
453
+
454
+ default:
455
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: bad address size %d\n",
456
+ DEVICE(fiu)->canonical_path, FIU_DWR_CFG_ADDSIZ(dwr_cfg));
457
+ break;
458
+ }
459
+
460
+ for (i = 0; i < size; i++) {
461
+ ssi_transfer(fiu->spi, extract64(v, i * 8, 8));
462
+ }
463
+
464
+ npcm7xx_fiu_deselect(fiu);
465
+}
466
+
467
+static const MemoryRegionOps npcm7xx_fiu_flash_ops = {
468
+ .read = npcm7xx_fiu_flash_read,
469
+ .write = npcm7xx_fiu_flash_write,
470
+ .endianness = DEVICE_LITTLE_ENDIAN,
471
+ .valid = {
472
+ .min_access_size = 1,
473
+ .max_access_size = 8,
474
+ .unaligned = true,
475
+ },
476
+};
477
+
478
+/* Control register read handler. */
479
+static uint64_t npcm7xx_fiu_ctrl_read(void *opaque, hwaddr addr,
480
+ unsigned int size)
481
+{
482
+ hwaddr reg = addr / sizeof(uint32_t);
483
+ NPCM7xxFIUState *s = opaque;
484
+ uint32_t value;
485
+
486
+ if (reg < NPCM7XX_FIU_NR_REGS) {
487
+ value = s->regs[reg];
488
+ } else {
489
+ qemu_log_mask(LOG_GUEST_ERROR,
490
+ "%s: read from invalid offset 0x%" PRIx64 "\n",
491
+ DEVICE(s)->canonical_path, addr);
492
+ value = 0;
493
+ }
494
+
495
+ trace_npcm7xx_fiu_ctrl_read(DEVICE(s)->canonical_path, addr, value);
496
+
497
+ return value;
498
+}
499
+
500
+/* Send the specified number of address bytes from the UMA address register. */
501
+static void send_address(SSIBus *spi, unsigned int addsiz, uint32_t addr)
502
+{
503
+ switch (addsiz) {
504
+ case 4:
505
+ ssi_transfer(spi, extract32(addr, 24, 8));
506
+ /* fall through */
507
+ case 3:
508
+ ssi_transfer(spi, extract32(addr, 16, 8));
509
+ /* fall through */
510
+ case 2:
511
+ ssi_transfer(spi, extract32(addr, 8, 8));
512
+ /* fall through */
513
+ case 1:
514
+ ssi_transfer(spi, extract32(addr, 0, 8));
515
+ /* fall through */
516
+ case 0:
517
+ break;
518
+ }
519
+}
520
+
521
+/* Send the number of dummy bits specified in the UMA config register. */
522
+static void send_dummy_bits(SSIBus *spi, uint32_t uma_cfg, uint32_t uma_cmd)
523
+{
524
+ unsigned int bits_per_clock = 1U << FIU_UMA_CFG_DBPCK(uma_cfg);
525
+ unsigned int i;
526
+
527
+ for (i = 0; i < FIU_UMA_CFG_DBSIZ(uma_cfg); i++) {
528
+ /* Use bytes 0 and 1 first, then keep repeating byte 2 */
529
+ unsigned int field = (i < 2) ? ((i + 1) * 8) : 24;
530
+ unsigned int j;
531
+
532
+ for (j = 0; j < 8; j += bits_per_clock) {
533
+ ssi_transfer(spi, extract32(uma_cmd, field + j, bits_per_clock));
534
+ }
535
+ }
536
+}
537
+
538
+/* Perform a User-Mode Access transaction. */
539
+static void npcm7xx_fiu_uma_transaction(NPCM7xxFIUState *s)
540
+{
541
+ uint32_t uma_cts = s->regs[NPCM7XX_FIU_UMA_CTS];
542
+ uint32_t uma_cfg;
543
+ unsigned int i;
544
+
545
+ /* SW_CS means the CS is already forced low, so don't touch it. */
546
+ if (uma_cts & FIU_UMA_CTS_SW_CS) {
547
+ int cs_id = FIU_UMA_CTS_DEV_NUM(s->regs[NPCM7XX_FIU_UMA_CTS]);
548
+ npcm7xx_fiu_select(s, cs_id);
549
+ }
550
+
551
+ /* Send command, if present. */
552
+ uma_cfg = s->regs[NPCM7XX_FIU_UMA_CFG];
553
+ if (FIU_UMA_CFG_CMDSIZ(uma_cfg) > 0) {
554
+ ssi_transfer(s->spi, extract32(s->regs[NPCM7XX_FIU_UMA_CMD], 0, 8));
555
+ }
556
+
557
+ /* Send address, if present. */
558
+ send_address(s->spi, FIU_UMA_CFG_ADDSIZ(uma_cfg),
559
+ s->regs[NPCM7XX_FIU_UMA_ADDR]);
560
+
561
+ /* Write data, if present. */
562
+ for (i = 0; i < FIU_UMA_CFG_WDATSIZ(uma_cfg); i++) {
563
+ unsigned int reg =
564
+ (i < 16) ? (NPCM7XX_FIU_UMA_DW0 + i / 4) : NPCM7XX_FIU_UMA_DW3;
565
+ unsigned int field = (i % 4) * 8;
566
+
567
+ ssi_transfer(s->spi, extract32(s->regs[reg], field, 8));
568
+ }
569
+
570
+ /* Send dummy bits, if present. */
571
+ send_dummy_bits(s->spi, uma_cfg, s->regs[NPCM7XX_FIU_UMA_CMD]);
572
+
573
+ /* Read data, if present. */
574
+ for (i = 0; i < FIU_UMA_CFG_RDATSIZ(uma_cfg); i++) {
575
+ unsigned int reg = NPCM7XX_FIU_UMA_DR0 + i / 4;
576
+ unsigned int field = (i % 4) * 8;
577
+ uint8_t c;
578
+
579
+ c = ssi_transfer(s->spi, 0);
580
+ if (reg <= NPCM7XX_FIU_UMA_DR3) {
581
+ s->regs[reg] = deposit32(s->regs[reg], field, 8, c);
582
+ }
583
+ }
584
+
585
+ /* Again, don't touch CS if the user is forcing it low. */
586
+ if (uma_cts & FIU_UMA_CTS_SW_CS) {
587
+ npcm7xx_fiu_deselect(s);
588
+ }
589
+
590
+ /* RDYST means a command has completed since it was cleared. */
591
+ s->regs[NPCM7XX_FIU_UMA_CTS] |= FIU_UMA_CTS_RDYST;
592
+ /* EXEC_DONE means Execute Command / Not Done, so clear it here. */
593
+ s->regs[NPCM7XX_FIU_UMA_CTS] &= ~FIU_UMA_CTS_EXEC_DONE;
594
+}
595
+
596
+/* Control register write handler. */
597
+static void npcm7xx_fiu_ctrl_write(void *opaque, hwaddr addr, uint64_t v,
598
+ unsigned int size)
599
+{
600
+ hwaddr reg = addr / sizeof(uint32_t);
601
+ NPCM7xxFIUState *s = opaque;
602
+ uint32_t value = v;
603
+
604
+ trace_npcm7xx_fiu_ctrl_write(DEVICE(s)->canonical_path, addr, value);
605
+
606
+ switch (reg) {
607
+ case NPCM7XX_FIU_UMA_CFG:
608
+ if (s->regs[reg] & FIU_UMA_CFG_CMMLCK) {
609
+ value &= ~FIU_UMA_CFG_CMMLCK_MASK;
610
+ value |= (s->regs[reg] & FIU_UMA_CFG_CMMLCK_MASK);
611
+ }
612
+ /* fall through */
613
+ case NPCM7XX_FIU_DRD_CFG:
614
+ case NPCM7XX_FIU_DWR_CFG:
615
+ if (s->regs[reg] & NPCM7XX_FIU_CFG_LCK) {
616
+ qemu_log_mask(LOG_GUEST_ERROR,
617
+ "%s: write to locked register @ 0x%" PRIx64 "\n",
618
+ DEVICE(s)->canonical_path, addr);
619
+ return;
620
+ }
621
+ s->regs[reg] = value;
622
+ break;
623
+
624
+ case NPCM7XX_FIU_UMA_CTS:
625
+ if (value & FIU_UMA_CTS_RDYST) {
626
+ value &= ~FIU_UMA_CTS_RDYST;
627
+ } else {
628
+ value |= s->regs[reg] & FIU_UMA_CTS_RDYST;
629
+ }
630
+ if ((s->regs[reg] ^ value) & FIU_UMA_CTS_SW_CS) {
631
+ if (value & FIU_UMA_CTS_SW_CS) {
632
+ /*
633
+ * Don't drop CS if there's a transfer in progress, or we're
634
+ * about to start one.
635
+ */
636
+ if (!((value | s->regs[reg]) & FIU_UMA_CTS_EXEC_DONE)) {
637
+ npcm7xx_fiu_deselect(s);
638
+ }
639
+ } else {
640
+ int cs_id = FIU_UMA_CTS_DEV_NUM(s->regs[NPCM7XX_FIU_UMA_CTS]);
641
+ npcm7xx_fiu_select(s, cs_id);
642
+ }
643
+ }
644
+ s->regs[reg] = value | (s->regs[reg] & FIU_UMA_CTS_EXEC_DONE);
645
+ if (value & FIU_UMA_CTS_EXEC_DONE) {
646
+ npcm7xx_fiu_uma_transaction(s);
647
+ }
648
+ break;
649
+
650
+ case NPCM7XX_FIU_UMA_DR0 ... NPCM7XX_FIU_UMA_DR3:
651
+ qemu_log_mask(LOG_GUEST_ERROR,
652
+ "%s: write to read-only register @ 0x%" PRIx64 "\n",
653
+ DEVICE(s)->canonical_path, addr);
654
+ return;
655
+
656
+ case NPCM7XX_FIU_PRT_CFG:
657
+ case NPCM7XX_FIU_PRT_CMD0 ... NPCM7XX_FIU_PRT_CMD9:
658
+ qemu_log_mask(LOG_UNIMP, "%s: PRT is not implemented\n", __func__);
659
+ break;
660
+
661
+ case NPCM7XX_FIU_UMA_CMD:
662
+ case NPCM7XX_FIU_UMA_ADDR:
663
+ case NPCM7XX_FIU_UMA_DW0 ... NPCM7XX_FIU_UMA_DW3:
664
+ case NPCM7XX_FIU_CFG:
665
+ s->regs[reg] = value;
666
+ break;
667
+
668
+ default:
669
+ qemu_log_mask(LOG_GUEST_ERROR,
670
+ "%s: write to invalid offset 0x%" PRIx64 "\n",
671
+ DEVICE(s)->canonical_path, addr);
672
+ return;
673
+ }
674
+}
675
+
676
+static const MemoryRegionOps npcm7xx_fiu_ctrl_ops = {
677
+ .read = npcm7xx_fiu_ctrl_read,
678
+ .write = npcm7xx_fiu_ctrl_write,
679
+ .endianness = DEVICE_LITTLE_ENDIAN,
680
+ .valid = {
681
+ .min_access_size = 4,
682
+ .max_access_size = 4,
683
+ .unaligned = false,
684
+ },
685
+};
686
+
687
+static void npcm7xx_fiu_enter_reset(Object *obj, ResetType type)
688
+{
689
+ NPCM7xxFIUState *s = NPCM7XX_FIU(obj);
690
+
691
+ trace_npcm7xx_fiu_enter_reset(DEVICE(obj)->canonical_path, type);
692
+
693
+ memset(s->regs, 0, sizeof(s->regs));
694
+
695
+ s->regs[NPCM7XX_FIU_DRD_CFG] = 0x0300100b;
696
+ s->regs[NPCM7XX_FIU_DWR_CFG] = 0x03000002;
697
+ s->regs[NPCM7XX_FIU_UMA_CFG] = 0x00000400;
698
+ s->regs[NPCM7XX_FIU_UMA_CTS] = 0x00010000;
699
+ s->regs[NPCM7XX_FIU_UMA_CMD] = 0x0000000b;
700
+ s->regs[NPCM7XX_FIU_PRT_CFG] = 0x00000400;
701
+ s->regs[NPCM7XX_FIU_CFG] = 0x0000000b;
702
+}
703
+
704
+static void npcm7xx_fiu_hold_reset(Object *obj)
705
+{
706
+ NPCM7xxFIUState *s = NPCM7XX_FIU(obj);
707
+ int i;
708
+
709
+ trace_npcm7xx_fiu_hold_reset(DEVICE(obj)->canonical_path);
710
+
711
+ for (i = 0; i < s->cs_count; i++) {
712
+ qemu_irq_raise(s->cs_lines[i]);
713
+ }
714
+}
715
+
716
+static void npcm7xx_fiu_realize(DeviceState *dev, Error **errp)
717
+{
718
+ NPCM7xxFIUState *s = NPCM7XX_FIU(dev);
719
+ SysBusDevice *sbd = &s->parent;
720
+ int i;
721
+
722
+ if (s->cs_count <= 0) {
723
+ error_setg(errp, "%s: %d chip selects specified, need at least one",
724
+ dev->canonical_path, s->cs_count);
725
+ return;
726
+ }
727
+
728
+ s->spi = ssi_create_bus(dev, "spi");
729
+ s->cs_lines = g_new0(qemu_irq, s->cs_count);
730
+ qdev_init_gpio_out_named(DEVICE(s), s->cs_lines, "cs", s->cs_count);
731
+ s->flash = g_new0(NPCM7xxFIUFlash, s->cs_count);
732
+
733
+ /*
734
+ * Register the control registers region first. It may be followed by one
735
+ * or more direct flash access regions.
736
+ */
737
+ memory_region_init_io(&s->mmio, OBJECT(s), &npcm7xx_fiu_ctrl_ops, s, "ctrl",
738
+ NPCM7XX_FIU_CTRL_REGS_SIZE);
739
+ sysbus_init_mmio(sbd, &s->mmio);
740
+
741
+ for (i = 0; i < s->cs_count; i++) {
742
+ NPCM7xxFIUFlash *flash = &s->flash[i];
743
+ flash->fiu = s;
744
+ memory_region_init_io(&flash->direct_access, OBJECT(s),
745
+ &npcm7xx_fiu_flash_ops, &s->flash[i], "flash",
746
+ NPCM7XX_FIU_FLASH_WINDOW_SIZE);
747
+ sysbus_init_mmio(sbd, &flash->direct_access);
748
+ }
749
+}
750
+
751
+static const VMStateDescription vmstate_npcm7xx_fiu = {
752
+ .name = "npcm7xx-fiu",
753
+ .version_id = 0,
754
+ .minimum_version_id = 0,
755
+ .fields = (VMStateField[]) {
756
+ VMSTATE_INT32(active_cs, NPCM7xxFIUState),
757
+ VMSTATE_UINT32_ARRAY(regs, NPCM7xxFIUState, NPCM7XX_FIU_NR_REGS),
758
+ VMSTATE_END_OF_LIST(),
759
+ },
760
+};
761
+
762
+static Property npcm7xx_fiu_properties[] = {
763
+ DEFINE_PROP_INT32("cs-count", NPCM7xxFIUState, cs_count, 0),
764
+ DEFINE_PROP_END_OF_LIST(),
765
+};
766
+
767
+static void npcm7xx_fiu_class_init(ObjectClass *klass, void *data)
768
+{
769
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
770
+ DeviceClass *dc = DEVICE_CLASS(klass);
771
+
772
+ QEMU_BUILD_BUG_ON(NPCM7XX_FIU_REGS_END > NPCM7XX_FIU_NR_REGS);
773
+
774
+ dc->desc = "NPCM7xx Flash Interface Unit";
775
+ dc->realize = npcm7xx_fiu_realize;
776
+ dc->vmsd = &vmstate_npcm7xx_fiu;
777
+ rc->phases.enter = npcm7xx_fiu_enter_reset;
778
+ rc->phases.hold = npcm7xx_fiu_hold_reset;
779
+ device_class_set_props(dc, npcm7xx_fiu_properties);
780
+}
781
+
782
+static const TypeInfo npcm7xx_fiu_types[] = {
783
+ {
784
+ .name = TYPE_NPCM7XX_FIU,
785
+ .parent = TYPE_SYS_BUS_DEVICE,
786
+ .instance_size = sizeof(NPCM7xxFIUState),
787
+ .class_init = npcm7xx_fiu_class_init,
788
+ },
789
+};
790
+DEFINE_TYPES(npcm7xx_fiu_types);
791
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
792
index XXXXXXX..XXXXXXX 100644
793
--- a/hw/arm/Kconfig
794
+++ b/hw/arm/Kconfig
795
@@ -XXX,XX +XXX,XX @@ config NPCM7XX
796
select ARM_GIC
797
select PL310 # cache controller
798
select SERIAL
799
+ select SSI
800
select UNIMP
801
802
config FSL_IMX25
803
diff --git a/hw/ssi/meson.build b/hw/ssi/meson.build
804
index XXXXXXX..XXXXXXX 100644
805
--- a/hw/ssi/meson.build
806
+++ b/hw/ssi/meson.build
807
@@ -XXX,XX +XXX,XX @@
808
softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_smc.c'))
809
softmmu_ss.add(when: 'CONFIG_MSF2', if_true: files('mss-spi.c'))
810
+softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_fiu.c'))
811
softmmu_ss.add(when: 'CONFIG_PL022', if_true: files('pl022.c'))
812
softmmu_ss.add(when: 'CONFIG_SSI', if_true: files('ssi.c'))
813
softmmu_ss.add(when: 'CONFIG_STM32F2XX_SPI', if_true: files('stm32f2xx_spi.c'))
814
diff --git a/hw/ssi/trace-events b/hw/ssi/trace-events
815
index XXXXXXX..XXXXXXX 100644
816
--- a/hw/ssi/trace-events
817
+++ b/hw/ssi/trace-events
818
@@ -XXX,XX +XXX,XX @@ aspeed_smc_dma_checksum(uint32_t addr, uint32_t data) "0x%08x: 0x%08x"
819
aspeed_smc_dma_rw(const char *dir, uint32_t flash_addr, uint32_t dram_addr, uint32_t size) "%s flash:@0x%08x dram:@0x%08x size:0x%08x"
820
aspeed_smc_write(uint64_t addr, uint32_t size, uint64_t data) "@0x%" PRIx64 " size %u: 0x%" PRIx64
821
aspeed_smc_flash_select(int cs, const char *prefix) "CS%d %sselect"
822
+
823
+# npcm7xx_fiu.c
824
+
825
+npcm7xx_fiu_enter_reset(const char *id, int reset_type) "%s reset type: %d"
826
+npcm7xx_fiu_hold_reset(const char *id) "%s"
827
+npcm7xx_fiu_select(const char *id, int cs) "%s select CS%d"
828
+npcm7xx_fiu_deselect(const char *id, int cs) "%s deselect CS%d"
829
+npcm7xx_fiu_ctrl_read(const char *id, uint64_t addr, uint32_t data) "%s offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
830
+npcm7xx_fiu_ctrl_write(const char *id, uint64_t addr, uint32_t data) "%s offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
831
+npcm7xx_fiu_flash_read(const char *id, int cs, uint64_t addr, unsigned int size, uint64_t value) "%s[%d] offset: 0x%08" PRIx64 " size: %u value: 0x%" PRIx64
832
+npcm7xx_fiu_flash_write(const char *id, int cs, uint64_t addr, unsigned int size, uint64_t value) "%s[%d] offset: 0x%08" PRIx64 " size: %u value: 0x%" PRIx64
833
--
156
--
834
2.20.1
157
2.20.1
835
158
836
159
diff view generated by jsdifflib
1
From: Vikram Garhwal <fnu.vikram@xilinx.com>
1
From: Doug Evans <dje@google.com>
2
2
3
The QTests perform five tests on the Xilinx ZynqMP CAN controller:
3
Reviewed-by: Hao Wu <wuhaotsh@google.com>
4
Tests the CAN controller in loopback, sleep and snoop mode.
4
Reviewed-by: Avi Fishman <avi.fishman@nuvoton.com>
5
Tests filtering of incoming CAN messages.
5
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
6
6
Signed-off-by: Doug Evans <dje@google.com>
7
Reviewed-by: Francisco Iglesias <francisco.iglesias@xilinx.com>
7
Message-id: 20210218212453.831406-4-dje@google.com
8
Signed-off-by: Vikram Garhwal <fnu.vikram@xilinx.com>
9
Message-id: 1597278668-339715-4-git-send-email-fnu.vikram@xilinx.com
10
[PMM: updated to meson build system]
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
9
---
13
tests/qtest/xlnx-can-test.c | 359 ++++++++++++++++++++++++++++++++++++
10
tests/qtest/npcm7xx_emc-test.c | 862 +++++++++++++++++++++++++++++++++
14
tests/qtest/meson.build | 1 +
11
tests/qtest/meson.build | 3 +-
15
2 files changed, 360 insertions(+)
12
2 files changed, 864 insertions(+), 1 deletion(-)
16
create mode 100644 tests/qtest/xlnx-can-test.c
13
create mode 100644 tests/qtest/npcm7xx_emc-test.c
17
14
18
diff --git a/tests/qtest/xlnx-can-test.c b/tests/qtest/xlnx-can-test.c
15
diff --git a/tests/qtest/npcm7xx_emc-test.c b/tests/qtest/npcm7xx_emc-test.c
19
new file mode 100644
16
new file mode 100644
20
index XXXXXXX..XXXXXXX
17
index XXXXXXX..XXXXXXX
21
--- /dev/null
18
--- /dev/null
22
+++ b/tests/qtest/xlnx-can-test.c
19
+++ b/tests/qtest/npcm7xx_emc-test.c
23
@@ -XXX,XX +XXX,XX @@
20
@@ -XXX,XX +XXX,XX @@
24
+/*
21
+/*
25
+ * QTests for the Xilinx ZynqMP CAN controller.
22
+ * QTests for Nuvoton NPCM7xx EMC Modules.
26
+ *
23
+ *
27
+ * Copyright (c) 2020 Xilinx Inc.
24
+ * Copyright 2020 Google LLC
28
+ *
25
+ *
29
+ * Written-by: Vikram Garhwal<fnu.vikram@xilinx.com>
26
+ * This program is free software; you can redistribute it and/or modify it
27
+ * under the terms of the GNU General Public License as published by the
28
+ * Free Software Foundation; either version 2 of the License, or
29
+ * (at your option) any later version.
30
+ *
30
+ *
31
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
31
+ * This program is distributed in the hope that it will be useful, but WITHOUT
32
+ * of this software and associated documentation files (the "Software"), to deal
32
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
33
+ * in the Software without restriction, including without limitation the rights
33
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
34
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
34
+ * for more details.
35
+ * copies of the Software, and to permit persons to whom the Software is
36
+ * furnished to do so, subject to the following conditions:
37
+ *
38
+ * The above copyright notice and this permission notice shall be included in
39
+ * all copies or substantial portions of the Software.
40
+ *
41
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
44
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
45
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
46
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
47
+ * THE SOFTWARE.
48
+ */
35
+ */
49
+
36
+
50
+#include "qemu/osdep.h"
37
+#include "qemu/osdep.h"
51
+#include "libqos/libqtest.h"
38
+#include "qemu-common.h"
52
+
39
+#include "libqos/libqos.h"
53
+/* Base address. */
40
+#include "qapi/qmp/qdict.h"
54
+#define CAN0_BASE_ADDR 0xFF060000
41
+#include "qapi/qmp/qnum.h"
55
+#define CAN1_BASE_ADDR 0xFF070000
42
+#include "qemu/bitops.h"
56
+
43
+#include "qemu/iov.h"
57
+/* Register addresses. */
44
+
58
+#define R_SRR_OFFSET 0x00
45
+/* Name of the emc device. */
59
+#define R_MSR_OFFSET 0x04
46
+#define TYPE_NPCM7XX_EMC "npcm7xx-emc"
60
+#define R_SR_OFFSET 0x18
47
+
61
+#define R_ISR_OFFSET 0x1C
48
+/* Timeout for various operations, in seconds. */
62
+#define R_ICR_OFFSET 0x24
49
+#define TIMEOUT_SECONDS 10
63
+#define R_TXID_OFFSET 0x30
50
+
64
+#define R_TXDLC_OFFSET 0x34
51
+/* Address in memory of the descriptor. */
65
+#define R_TXDATA1_OFFSET 0x38
52
+#define DESC_ADDR (1 << 20) /* 1 MiB */
66
+#define R_TXDATA2_OFFSET 0x3C
53
+
67
+#define R_RXID_OFFSET 0x50
54
+/* Address in memory of the data packet. */
68
+#define R_RXDLC_OFFSET 0x54
55
+#define DATA_ADDR (DESC_ADDR + 4096)
69
+#define R_RXDATA1_OFFSET 0x58
56
+
70
+#define R_RXDATA2_OFFSET 0x5C
57
+#define CRC_LENGTH 4
71
+#define R_AFR 0x60
58
+
72
+#define R_AFMR1 0x64
59
+#define NUM_TX_DESCRIPTORS 3
73
+#define R_AFIR1 0x68
60
+#define NUM_RX_DESCRIPTORS 2
74
+#define R_AFMR2 0x6C
61
+
75
+#define R_AFIR2 0x70
62
+/* Size of tx,rx test buffers. */
76
+#define R_AFMR3 0x74
63
+#define TX_DATA_LEN 64
77
+#define R_AFIR3 0x78
64
+#define RX_DATA_LEN 64
78
+#define R_AFMR4 0x7C
65
+
79
+#define R_AFIR4 0x80
66
+#define TX_STEP_COUNT 10000
80
+
67
+#define RX_STEP_COUNT 10000
81
+/* CAN modes. */
68
+
82
+#define CONFIG_MODE 0x00
69
+/* 32-bit register indices. */
83
+#define NORMAL_MODE 0x00
70
+typedef enum NPCM7xxPWMRegister {
84
+#define LOOPBACK_MODE 0x02
71
+ /* Control registers. */
85
+#define SNOOP_MODE 0x04
72
+ REG_CAMCMR,
86
+#define SLEEP_MODE 0x01
73
+ REG_CAMEN,
87
+#define ENABLE_CAN (1 << 1)
74
+
88
+#define STATUS_NORMAL_MODE (1 << 3)
75
+ /* There are 16 CAMn[ML] registers. */
89
+#define STATUS_LOOPBACK_MODE (1 << 1)
76
+ REG_CAMM_BASE,
90
+#define STATUS_SNOOP_MODE (1 << 12)
77
+ REG_CAML_BASE,
91
+#define STATUS_SLEEP_MODE (1 << 2)
78
+
92
+#define ISR_TXOK (1 << 1)
79
+ REG_TXDLSA = 0x22,
93
+#define ISR_RXOK (1 << 4)
80
+ REG_RXDLSA,
94
+
81
+ REG_MCMDR,
95
+static void match_rx_tx_data(uint32_t *buf_tx, uint32_t *buf_rx,
82
+ REG_MIID,
96
+ uint8_t can_timestamp)
83
+ REG_MIIDA,
97
+{
84
+ REG_FFTCR,
98
+ uint16_t size = 0;
85
+ REG_TSDR,
99
+ uint8_t len = 4;
86
+ REG_RSDR,
100
+
87
+ REG_DMARFC,
101
+ while (size < len) {
88
+ REG_MIEN,
102
+ if (R_RXID_OFFSET + 4 * size == R_RXDLC_OFFSET) {
89
+
103
+ g_assert_cmpint(buf_rx[size], ==, buf_tx[size] + can_timestamp);
90
+ /* Status registers. */
91
+ REG_MISTA,
92
+ REG_MGSTA,
93
+ REG_MPCNT,
94
+ REG_MRPC,
95
+ REG_MRPCC,
96
+ REG_MREPC,
97
+ REG_DMARFS,
98
+ REG_CTXDSA,
99
+ REG_CTXBSA,
100
+ REG_CRXDSA,
101
+ REG_CRXBSA,
102
+
103
+ NPCM7XX_NUM_EMC_REGS,
104
+} NPCM7xxPWMRegister;
105
+
106
+enum { NUM_CAMML_REGS = 16 };
107
+
108
+/* REG_CAMCMR fields */
109
+/* Enable CAM Compare */
110
+#define REG_CAMCMR_ECMP (1 << 4)
111
+/* Accept Unicast Packet */
112
+#define REG_CAMCMR_AUP (1 << 0)
113
+
114
+/* REG_MCMDR fields */
115
+/* Software Reset */
116
+#define REG_MCMDR_SWR (1 << 24)
117
+/* Frame Transmission On */
118
+#define REG_MCMDR_TXON (1 << 8)
119
+/* Accept Long Packet */
120
+#define REG_MCMDR_ALP (1 << 1)
121
+/* Frame Reception On */
122
+#define REG_MCMDR_RXON (1 << 0)
123
+
124
+/* REG_MIEN fields */
125
+/* Enable Transmit Completion Interrupt */
126
+#define REG_MIEN_ENTXCP (1 << 18)
127
+/* Enable Transmit Interrupt */
128
+#define REG_MIEN_ENTXINTR (1 << 16)
129
+/* Enable Receive Good Interrupt */
130
+#define REG_MIEN_ENRXGD (1 << 4)
131
+/* ENable Receive Interrupt */
132
+#define REG_MIEN_ENRXINTR (1 << 0)
133
+
134
+/* REG_MISTA fields */
135
+/* Transmit Bus Error Interrupt */
136
+#define REG_MISTA_TXBERR (1 << 24)
137
+/* Transmit Descriptor Unavailable Interrupt */
138
+#define REG_MISTA_TDU (1 << 23)
139
+/* Transmit Completion Interrupt */
140
+#define REG_MISTA_TXCP (1 << 18)
141
+/* Transmit Interrupt */
142
+#define REG_MISTA_TXINTR (1 << 16)
143
+/* Receive Bus Error Interrupt */
144
+#define REG_MISTA_RXBERR (1 << 11)
145
+/* Receive Descriptor Unavailable Interrupt */
146
+#define REG_MISTA_RDU (1 << 10)
147
+/* DMA Early Notification Interrupt */
148
+#define REG_MISTA_DENI (1 << 9)
149
+/* Maximum Frame Length Interrupt */
150
+#define REG_MISTA_DFOI (1 << 8)
151
+/* Receive Good Interrupt */
152
+#define REG_MISTA_RXGD (1 << 4)
153
+/* Packet Too Long Interrupt */
154
+#define REG_MISTA_PTLE (1 << 3)
155
+/* Receive Interrupt */
156
+#define REG_MISTA_RXINTR (1 << 0)
157
+
158
+typedef struct NPCM7xxEMCTxDesc NPCM7xxEMCTxDesc;
159
+typedef struct NPCM7xxEMCRxDesc NPCM7xxEMCRxDesc;
160
+
161
+struct NPCM7xxEMCTxDesc {
162
+ uint32_t flags;
163
+ uint32_t txbsa;
164
+ uint32_t status_and_length;
165
+ uint32_t ntxdsa;
166
+};
167
+
168
+struct NPCM7xxEMCRxDesc {
169
+ uint32_t status_and_length;
170
+ uint32_t rxbsa;
171
+ uint32_t reserved;
172
+ uint32_t nrxdsa;
173
+};
174
+
175
+/* NPCM7xxEMCTxDesc.flags values */
176
+/* Owner: 0 = cpu, 1 = emc */
177
+#define TX_DESC_FLAG_OWNER_MASK (1 << 31)
178
+/* Transmit interrupt enable */
179
+#define TX_DESC_FLAG_INTEN (1 << 2)
180
+
181
+/* NPCM7xxEMCTxDesc.status_and_length values */
182
+/* Transmission complete */
183
+#define TX_DESC_STATUS_TXCP (1 << 19)
184
+/* Transmit interrupt */
185
+#define TX_DESC_STATUS_TXINTR (1 << 16)
186
+
187
+/* NPCM7xxEMCRxDesc.status_and_length values */
188
+/* Owner: 0b00 = cpu, 0b10 = emc */
189
+#define RX_DESC_STATUS_OWNER_SHIFT 30
190
+#define RX_DESC_STATUS_OWNER_MASK 0xc0000000
191
+/* Frame Reception Complete */
192
+#define RX_DESC_STATUS_RXGD (1 << 20)
193
+/* Packet too long */
194
+#define RX_DESC_STATUS_PTLE (1 << 19)
195
+/* Receive Interrupt */
196
+#define RX_DESC_STATUS_RXINTR (1 << 16)
197
+
198
+#define RX_DESC_PKT_LEN(word) ((uint32_t) (word) & 0xffff)
199
+
200
+typedef struct EMCModule {
201
+ int rx_irq;
202
+ int tx_irq;
203
+ uint64_t base_addr;
204
+} EMCModule;
205
+
206
+typedef struct TestData {
207
+ const EMCModule *module;
208
+} TestData;
209
+
210
+static const EMCModule emc_module_list[] = {
211
+ {
212
+ .rx_irq = 15,
213
+ .tx_irq = 16,
214
+ .base_addr = 0xf0825000
215
+ },
216
+ {
217
+ .rx_irq = 114,
218
+ .tx_irq = 115,
219
+ .base_addr = 0xf0826000
220
+ }
221
+};
222
+
223
+/* Returns the index of the EMC module. */
224
+static int emc_module_index(const EMCModule *mod)
225
+{
226
+ ptrdiff_t diff = mod - emc_module_list;
227
+
228
+ g_assert_true(diff >= 0 && diff < ARRAY_SIZE(emc_module_list));
229
+
230
+ return diff;
231
+}
232
+
233
+static void packet_test_clear(void *sockets)
234
+{
235
+ int *test_sockets = sockets;
236
+
237
+ close(test_sockets[0]);
238
+ g_free(test_sockets);
239
+}
240
+
241
+static int *packet_test_init(int module_num, GString *cmd_line)
242
+{
243
+ int *test_sockets = g_new(int, 2);
244
+ int ret = socketpair(PF_UNIX, SOCK_STREAM, 0, test_sockets);
245
+ g_assert_cmpint(ret, != , -1);
246
+
247
+ /*
248
+ * KISS and use -nic. We specify two nics (both emc{0,1}) because there's
249
+ * currently no way to specify only emc1: The driver implicitly relies on
250
+ * emc[i] == nd_table[i].
251
+ */
252
+ if (module_num == 0) {
253
+ g_string_append_printf(cmd_line,
254
+ " -nic socket,fd=%d,model=" TYPE_NPCM7XX_EMC " "
255
+ " -nic user,model=" TYPE_NPCM7XX_EMC " ",
256
+ test_sockets[1]);
257
+ } else {
258
+ g_string_append_printf(cmd_line,
259
+ " -nic user,model=" TYPE_NPCM7XX_EMC " "
260
+ " -nic socket,fd=%d,model=" TYPE_NPCM7XX_EMC " ",
261
+ test_sockets[1]);
262
+ }
263
+
264
+ g_test_queue_destroy(packet_test_clear, test_sockets);
265
+ return test_sockets;
266
+}
267
+
268
+static uint32_t emc_read(QTestState *qts, const EMCModule *mod,
269
+ NPCM7xxPWMRegister regno)
270
+{
271
+ return qtest_readl(qts, mod->base_addr + regno * sizeof(uint32_t));
272
+}
273
+
274
+static void emc_write(QTestState *qts, const EMCModule *mod,
275
+ NPCM7xxPWMRegister regno, uint32_t value)
276
+{
277
+ qtest_writel(qts, mod->base_addr + regno * sizeof(uint32_t), value);
278
+}
279
+
280
+static void emc_read_tx_desc(QTestState *qts, uint32_t addr,
281
+ NPCM7xxEMCTxDesc *desc)
282
+{
283
+ qtest_memread(qts, addr, desc, sizeof(*desc));
284
+ desc->flags = le32_to_cpu(desc->flags);
285
+ desc->txbsa = le32_to_cpu(desc->txbsa);
286
+ desc->status_and_length = le32_to_cpu(desc->status_and_length);
287
+ desc->ntxdsa = le32_to_cpu(desc->ntxdsa);
288
+}
289
+
290
+static void emc_write_tx_desc(QTestState *qts, const NPCM7xxEMCTxDesc *desc,
291
+ uint32_t addr)
292
+{
293
+ NPCM7xxEMCTxDesc le_desc;
294
+
295
+ le_desc.flags = cpu_to_le32(desc->flags);
296
+ le_desc.txbsa = cpu_to_le32(desc->txbsa);
297
+ le_desc.status_and_length = cpu_to_le32(desc->status_and_length);
298
+ le_desc.ntxdsa = cpu_to_le32(desc->ntxdsa);
299
+ qtest_memwrite(qts, addr, &le_desc, sizeof(le_desc));
300
+}
301
+
302
+static void emc_read_rx_desc(QTestState *qts, uint32_t addr,
303
+ NPCM7xxEMCRxDesc *desc)
304
+{
305
+ qtest_memread(qts, addr, desc, sizeof(*desc));
306
+ desc->status_and_length = le32_to_cpu(desc->status_and_length);
307
+ desc->rxbsa = le32_to_cpu(desc->rxbsa);
308
+ desc->reserved = le32_to_cpu(desc->reserved);
309
+ desc->nrxdsa = le32_to_cpu(desc->nrxdsa);
310
+}
311
+
312
+static void emc_write_rx_desc(QTestState *qts, const NPCM7xxEMCRxDesc *desc,
313
+ uint32_t addr)
314
+{
315
+ NPCM7xxEMCRxDesc le_desc;
316
+
317
+ le_desc.status_and_length = cpu_to_le32(desc->status_and_length);
318
+ le_desc.rxbsa = cpu_to_le32(desc->rxbsa);
319
+ le_desc.reserved = cpu_to_le32(desc->reserved);
320
+ le_desc.nrxdsa = cpu_to_le32(desc->nrxdsa);
321
+ qtest_memwrite(qts, addr, &le_desc, sizeof(le_desc));
322
+}
323
+
324
+/*
325
+ * Reset the EMC module.
326
+ * The module must be reset before, e.g., TXDLSA,RXDLSA are changed.
327
+ */
328
+static bool emc_soft_reset(QTestState *qts, const EMCModule *mod)
329
+{
330
+ uint32_t val;
331
+ uint64_t end_time;
332
+
333
+ emc_write(qts, mod, REG_MCMDR, REG_MCMDR_SWR);
334
+
335
+ /*
336
+ * Wait for device to reset as the linux driver does.
337
+ * During reset the AHB reads 0 for all registers. So first wait for
338
+ * something that resets to non-zero, and then wait for SWR becoming 0.
339
+ */
340
+ end_time = g_get_monotonic_time() + TIMEOUT_SECONDS * G_TIME_SPAN_SECOND;
341
+
342
+ do {
343
+ qtest_clock_step(qts, 100);
344
+ val = emc_read(qts, mod, REG_FFTCR);
345
+ } while (val == 0 && g_get_monotonic_time() < end_time);
346
+ if (val != 0) {
347
+ do {
348
+ qtest_clock_step(qts, 100);
349
+ val = emc_read(qts, mod, REG_MCMDR);
350
+ if ((val & REG_MCMDR_SWR) == 0) {
351
+ /*
352
+ * N.B. The CAMs have been reset here, so macaddr matching of
353
+ * incoming packets will not work.
354
+ */
355
+ return true;
356
+ }
357
+ } while (g_get_monotonic_time() < end_time);
358
+ }
359
+
360
+ g_message("%s: Timeout expired", __func__);
361
+ return false;
362
+}
363
+
364
+/* Check emc registers are reset to default value. */
365
+static void test_init(gconstpointer test_data)
366
+{
367
+ const TestData *td = test_data;
368
+ const EMCModule *mod = td->module;
369
+ QTestState *qts = qtest_init("-machine quanta-gsj");
370
+ int i;
371
+
372
+#define CHECK_REG(regno, value) \
373
+ do { \
374
+ g_assert_cmphex(emc_read(qts, mod, (regno)), ==, (value)); \
375
+ } while (0)
376
+
377
+ CHECK_REG(REG_CAMCMR, 0);
378
+ CHECK_REG(REG_CAMEN, 0);
379
+ CHECK_REG(REG_TXDLSA, 0xfffffffc);
380
+ CHECK_REG(REG_RXDLSA, 0xfffffffc);
381
+ CHECK_REG(REG_MCMDR, 0);
382
+ CHECK_REG(REG_MIID, 0);
383
+ CHECK_REG(REG_MIIDA, 0x00900000);
384
+ CHECK_REG(REG_FFTCR, 0x0101);
385
+ CHECK_REG(REG_DMARFC, 0x0800);
386
+ CHECK_REG(REG_MIEN, 0);
387
+ CHECK_REG(REG_MISTA, 0);
388
+ CHECK_REG(REG_MGSTA, 0);
389
+ CHECK_REG(REG_MPCNT, 0x7fff);
390
+ CHECK_REG(REG_MRPC, 0);
391
+ CHECK_REG(REG_MRPCC, 0);
392
+ CHECK_REG(REG_MREPC, 0);
393
+ CHECK_REG(REG_DMARFS, 0);
394
+ CHECK_REG(REG_CTXDSA, 0);
395
+ CHECK_REG(REG_CTXBSA, 0);
396
+ CHECK_REG(REG_CRXDSA, 0);
397
+ CHECK_REG(REG_CRXBSA, 0);
398
+
399
+#undef CHECK_REG
400
+
401
+ for (i = 0; i < NUM_CAMML_REGS; ++i) {
402
+ g_assert_cmpuint(emc_read(qts, mod, REG_CAMM_BASE + i * 2), ==,
403
+ 0);
404
+ g_assert_cmpuint(emc_read(qts, mod, REG_CAML_BASE + i * 2), ==,
405
+ 0);
406
+ }
407
+
408
+ qtest_quit(qts);
409
+}
410
+
411
+static bool emc_wait_irq(QTestState *qts, const EMCModule *mod, int step,
412
+ bool is_tx)
413
+{
414
+ uint64_t end_time =
415
+ g_get_monotonic_time() + TIMEOUT_SECONDS * G_TIME_SPAN_SECOND;
416
+
417
+ do {
418
+ if (qtest_get_irq(qts, is_tx ? mod->tx_irq : mod->rx_irq)) {
419
+ return true;
420
+ }
421
+ qtest_clock_step(qts, step);
422
+ } while (g_get_monotonic_time() < end_time);
423
+
424
+ g_message("%s: Timeout expired", __func__);
425
+ return false;
426
+}
427
+
428
+static bool emc_wait_mista(QTestState *qts, const EMCModule *mod, int step,
429
+ uint32_t flag)
430
+{
431
+ uint64_t end_time =
432
+ g_get_monotonic_time() + TIMEOUT_SECONDS * G_TIME_SPAN_SECOND;
433
+
434
+ do {
435
+ uint32_t mista = emc_read(qts, mod, REG_MISTA);
436
+ if (mista & flag) {
437
+ return true;
438
+ }
439
+ qtest_clock_step(qts, step);
440
+ } while (g_get_monotonic_time() < end_time);
441
+
442
+ g_message("%s: Timeout expired", __func__);
443
+ return false;
444
+}
445
+
446
+static bool wait_socket_readable(int fd)
447
+{
448
+ fd_set read_fds;
449
+ struct timeval tv;
450
+ int rv;
451
+
452
+ FD_ZERO(&read_fds);
453
+ FD_SET(fd, &read_fds);
454
+ tv.tv_sec = TIMEOUT_SECONDS;
455
+ tv.tv_usec = 0;
456
+ rv = select(fd + 1, &read_fds, NULL, NULL, &tv);
457
+ if (rv == -1) {
458
+ perror("select");
459
+ } else if (rv == 0) {
460
+ g_message("%s: Timeout expired", __func__);
461
+ }
462
+ return rv == 1;
463
+}
464
+
465
+/* Initialize *desc (in host endian format). */
466
+static void init_tx_desc(NPCM7xxEMCTxDesc *desc, size_t count,
467
+ uint32_t desc_addr)
468
+{
469
+ g_assert(count >= 2);
470
+ memset(&desc[0], 0, sizeof(*desc) * count);
471
+ /* Leave the last one alone, owned by the cpu -> stops transmission. */
472
+ for (size_t i = 0; i < count - 1; ++i) {
473
+ desc[i].flags =
474
+ (TX_DESC_FLAG_OWNER_MASK | /* owner = 1: emc */
475
+ TX_DESC_FLAG_INTEN |
476
+ 0 | /* crc append = 0 */
477
+ 0 /* padding enable = 0 */);
478
+ desc[i].status_and_length =
479
+ (0 | /* collision count = 0 */
480
+ 0 | /* SQE = 0 */
481
+ 0 | /* PAU = 0 */
482
+ 0 | /* TXHA = 0 */
483
+ 0 | /* LC = 0 */
484
+ 0 | /* TXABT = 0 */
485
+ 0 | /* NCS = 0 */
486
+ 0 | /* EXDEF = 0 */
487
+ 0 | /* TXCP = 0 */
488
+ 0 | /* DEF = 0 */
489
+ 0 | /* TXINTR = 0 */
490
+ 0 /* length filled in later */);
491
+ desc[i].ntxdsa = desc_addr + (i + 1) * sizeof(*desc);
492
+ }
493
+}
494
+
495
+static void enable_tx(QTestState *qts, const EMCModule *mod,
496
+ const NPCM7xxEMCTxDesc *desc, size_t count,
497
+ uint32_t desc_addr, uint32_t mien_flags)
498
+{
499
+ /* Write the descriptors to guest memory. */
500
+ for (size_t i = 0; i < count; ++i) {
501
+ emc_write_tx_desc(qts, desc + i, desc_addr + i * sizeof(*desc));
502
+ }
503
+
504
+ /* Trigger sending the packet. */
505
+ /* The module must be reset before changing TXDLSA. */
506
+ g_assert(emc_soft_reset(qts, mod));
507
+ emc_write(qts, mod, REG_TXDLSA, desc_addr);
508
+ emc_write(qts, mod, REG_CTXDSA, ~0);
509
+ emc_write(qts, mod, REG_MIEN, REG_MIEN_ENTXCP | mien_flags);
510
+ {
511
+ uint32_t mcmdr = emc_read(qts, mod, REG_MCMDR);
512
+ mcmdr |= REG_MCMDR_TXON;
513
+ emc_write(qts, mod, REG_MCMDR, mcmdr);
514
+ }
515
+
516
+ /* Prod the device to send the packet. */
517
+ emc_write(qts, mod, REG_TSDR, 1);
518
+}
519
+
520
+static void emc_send_verify1(QTestState *qts, const EMCModule *mod, int fd,
521
+ bool with_irq, uint32_t desc_addr,
522
+ uint32_t next_desc_addr,
523
+ const char *test_data, int test_size)
524
+{
525
+ NPCM7xxEMCTxDesc result_desc;
526
+ uint32_t expected_mask, expected_value, recv_len;
527
+ int ret;
528
+ char buffer[TX_DATA_LEN];
529
+
530
+ g_assert(wait_socket_readable(fd));
531
+
532
+ /* Read the descriptor back. */
533
+ emc_read_tx_desc(qts, desc_addr, &result_desc);
534
+ /* Descriptor should be owned by cpu now. */
535
+ g_assert((result_desc.flags & TX_DESC_FLAG_OWNER_MASK) == 0);
536
+ /* Test the status bits, ignoring the length field. */
537
+ expected_mask = 0xffff << 16;
538
+ expected_value = TX_DESC_STATUS_TXCP;
539
+ if (with_irq) {
540
+ expected_value |= TX_DESC_STATUS_TXINTR;
541
+ }
542
+ g_assert_cmphex((result_desc.status_and_length & expected_mask), ==,
543
+ expected_value);
544
+
545
+ /* Check data sent to the backend. */
546
+ recv_len = ~0;
547
+ ret = qemu_recv(fd, &recv_len, sizeof(recv_len), MSG_DONTWAIT);
548
+ g_assert_cmpint(ret, == , sizeof(recv_len));
549
+
550
+ g_assert(wait_socket_readable(fd));
551
+ memset(buffer, 0xff, sizeof(buffer));
552
+ ret = qemu_recv(fd, buffer, test_size, MSG_DONTWAIT);
553
+ g_assert_cmpmem(buffer, ret, test_data, test_size);
554
+}
555
+
556
+static void emc_send_verify(QTestState *qts, const EMCModule *mod, int fd,
557
+ bool with_irq)
558
+{
559
+ NPCM7xxEMCTxDesc desc[NUM_TX_DESCRIPTORS];
560
+ uint32_t desc_addr = DESC_ADDR;
561
+ static const char test1_data[] = "TEST1";
562
+ static const char test2_data[] = "Testing 1 2 3 ...";
563
+ uint32_t data1_addr = DATA_ADDR;
564
+ uint32_t data2_addr = data1_addr + sizeof(test1_data);
565
+ bool got_tdu;
566
+ uint32_t end_desc_addr;
567
+
568
+ /* Prepare test data buffer. */
569
+ qtest_memwrite(qts, data1_addr, test1_data, sizeof(test1_data));
570
+ qtest_memwrite(qts, data2_addr, test2_data, sizeof(test2_data));
571
+
572
+ init_tx_desc(&desc[0], NUM_TX_DESCRIPTORS, desc_addr);
573
+ desc[0].txbsa = data1_addr;
574
+ desc[0].status_and_length |= sizeof(test1_data);
575
+ desc[1].txbsa = data2_addr;
576
+ desc[1].status_and_length |= sizeof(test2_data);
577
+
578
+ enable_tx(qts, mod, &desc[0], NUM_TX_DESCRIPTORS, desc_addr,
579
+ with_irq ? REG_MIEN_ENTXINTR : 0);
580
+
581
+ /*
582
+ * It's problematic to observe the interrupt for each packet.
583
+ * Instead just wait until all the packets go out.
584
+ */
585
+ got_tdu = false;
586
+ while (!got_tdu) {
587
+ if (with_irq) {
588
+ g_assert_true(emc_wait_irq(qts, mod, TX_STEP_COUNT,
589
+ /*is_tx=*/true));
104
+ } else {
590
+ } else {
105
+ g_assert_cmpint(buf_rx[size], ==, buf_tx[size]);
591
+ g_assert_true(emc_wait_mista(qts, mod, TX_STEP_COUNT,
592
+ REG_MISTA_TXINTR));
106
+ }
593
+ }
107
+
594
+ got_tdu = !!(emc_read(qts, mod, REG_MISTA) & REG_MISTA_TDU);
108
+ size++;
595
+ /* If we don't have TDU yet, reset the interrupt. */
109
+ }
596
+ if (!got_tdu) {
110
+}
597
+ emc_write(qts, mod, REG_MISTA,
111
+
598
+ emc_read(qts, mod, REG_MISTA) & 0xffff0000);
112
+static void read_data(QTestState *qts, uint64_t can_base_addr, uint32_t *buf_rx)
599
+ }
113
+{
600
+ }
114
+ uint32_t int_status;
601
+
115
+
602
+ end_desc_addr = desc_addr + 2 * sizeof(desc[0]);
116
+ /* Read the interrupt on CAN rx. */
603
+ g_assert_cmphex(emc_read(qts, mod, REG_CTXDSA), ==, end_desc_addr);
117
+ int_status = qtest_readl(qts, can_base_addr + R_ISR_OFFSET) & ISR_RXOK;
604
+ g_assert_cmphex(emc_read(qts, mod, REG_MISTA), ==,
118
+
605
+ REG_MISTA_TXCP | REG_MISTA_TXINTR | REG_MISTA_TDU);
119
+ g_assert_cmpint(int_status, ==, ISR_RXOK);
606
+
120
+
607
+ emc_send_verify1(qts, mod, fd, with_irq,
121
+ /* Read the RX register data for CAN. */
608
+ desc_addr, end_desc_addr,
122
+ buf_rx[0] = qtest_readl(qts, can_base_addr + R_RXID_OFFSET);
609
+ test1_data, sizeof(test1_data));
123
+ buf_rx[1] = qtest_readl(qts, can_base_addr + R_RXDLC_OFFSET);
610
+ emc_send_verify1(qts, mod, fd, with_irq,
124
+ buf_rx[2] = qtest_readl(qts, can_base_addr + R_RXDATA1_OFFSET);
611
+ desc_addr + sizeof(desc[0]), end_desc_addr,
125
+ buf_rx[3] = qtest_readl(qts, can_base_addr + R_RXDATA2_OFFSET);
612
+ test2_data, sizeof(test2_data));
126
+
613
+}
127
+ /* Clear the RX interrupt. */
614
+
128
+ qtest_writel(qts, CAN1_BASE_ADDR + R_ICR_OFFSET, ISR_RXOK);
615
+/* Initialize *desc (in host endian format). */
129
+}
616
+static void init_rx_desc(NPCM7xxEMCRxDesc *desc, size_t count,
130
+
617
+ uint32_t desc_addr, uint32_t data_addr)
131
+static void send_data(QTestState *qts, uint64_t can_base_addr, uint32_t *buf_tx)
618
+{
132
+{
619
+ g_assert_true(count >= 2);
133
+ uint32_t int_status;
620
+ memset(desc, 0, sizeof(*desc) * count);
134
+
621
+ desc[0].rxbsa = data_addr;
135
+ /* Write the TX register data for CAN. */
622
+ desc[0].status_and_length =
136
+ qtest_writel(qts, can_base_addr + R_TXID_OFFSET, buf_tx[0]);
623
+ (0b10 << RX_DESC_STATUS_OWNER_SHIFT | /* owner = 10: emc */
137
+ qtest_writel(qts, can_base_addr + R_TXDLC_OFFSET, buf_tx[1]);
624
+ 0 | /* RP = 0 */
138
+ qtest_writel(qts, can_base_addr + R_TXDATA1_OFFSET, buf_tx[2]);
625
+ 0 | /* ALIE = 0 */
139
+ qtest_writel(qts, can_base_addr + R_TXDATA2_OFFSET, buf_tx[3]);
626
+ 0 | /* RXGD = 0 */
140
+
627
+ 0 | /* PTLE = 0 */
141
+ /* Read the interrupt on CAN for tx. */
628
+ 0 | /* CRCE = 0 */
142
+ int_status = qtest_readl(qts, can_base_addr + R_ISR_OFFSET) & ISR_TXOK;
629
+ 0 | /* RXINTR = 0 */
143
+
630
+ 0 /* length (filled in later) */);
144
+ g_assert_cmpint(int_status, ==, ISR_TXOK);
631
+ /* Leave the last one alone, owned by the cpu -> stops transmission. */
145
+
632
+ desc[0].nrxdsa = desc_addr + sizeof(*desc);
146
+ /* Clear the interrupt for tx. */
633
+}
147
+ qtest_writel(qts, CAN0_BASE_ADDR + R_ICR_OFFSET, ISR_TXOK);
634
+
148
+}
635
+static void enable_rx(QTestState *qts, const EMCModule *mod,
149
+
636
+ const NPCM7xxEMCRxDesc *desc, size_t count,
150
+/*
637
+ uint32_t desc_addr, uint32_t mien_flags,
151
+ * This test will be transferring data from CAN0 and CAN1 through canbus. CAN0
638
+ uint32_t mcmdr_flags)
152
+ * initiate the data transfer to can-bus, CAN1 receives the data. Test compares
639
+{
153
+ * the data sent from CAN0 with received on CAN1.
640
+ /*
154
+ */
641
+ * Write the descriptor to guest memory.
155
+static void test_can_bus(void)
642
+ * FWIW, IWBN if the docs said the buffer needs to be at least DMARFC
156
+{
643
+ * bytes.
157
+ uint32_t buf_tx[4] = { 0xFF, 0x80000000, 0x12345678, 0x87654321 };
644
+ */
158
+ uint32_t buf_rx[4] = { 0x00, 0x00, 0x00, 0x00 };
645
+ for (size_t i = 0; i < count; ++i) {
159
+ uint32_t status = 0;
646
+ emc_write_rx_desc(qts, desc + i, desc_addr + i * sizeof(*desc));
160
+ uint8_t can_timestamp = 1;
647
+ }
161
+
648
+
162
+ QTestState *qts = qtest_init("-machine xlnx-zcu102"
649
+ /* Trigger receiving the packet. */
163
+ " -object can-bus,id=canbus0"
650
+ /* The module must be reset before changing RXDLSA. */
164
+ " -machine xlnx-zcu102.canbus0=canbus0"
651
+ g_assert(emc_soft_reset(qts, mod));
165
+ " -machine xlnx-zcu102.canbus1=canbus0"
652
+ emc_write(qts, mod, REG_RXDLSA, desc_addr);
166
+ );
653
+ emc_write(qts, mod, REG_MIEN, REG_MIEN_ENRXGD | mien_flags);
167
+
654
+
168
+ /* Configure the CAN0 and CAN1. */
655
+ /*
169
+ qtest_writel(qts, CAN0_BASE_ADDR + R_SRR_OFFSET, ENABLE_CAN);
656
+ * We don't know what the device's macaddr is, so just accept all
170
+ qtest_writel(qts, CAN0_BASE_ADDR + R_MSR_OFFSET, NORMAL_MODE);
657
+ * unicast packets (AUP).
171
+ qtest_writel(qts, CAN1_BASE_ADDR + R_SRR_OFFSET, ENABLE_CAN);
658
+ */
172
+ qtest_writel(qts, CAN1_BASE_ADDR + R_MSR_OFFSET, NORMAL_MODE);
659
+ emc_write(qts, mod, REG_CAMCMR, REG_CAMCMR_AUP);
173
+
660
+ emc_write(qts, mod, REG_CAMEN, 1 << 0);
174
+ /* Check here if CAN0 and CAN1 are in normal mode. */
661
+ {
175
+ status = qtest_readl(qts, CAN0_BASE_ADDR + R_SR_OFFSET);
662
+ uint32_t mcmdr = emc_read(qts, mod, REG_MCMDR);
176
+ g_assert_cmpint(status, ==, STATUS_NORMAL_MODE);
663
+ mcmdr |= REG_MCMDR_RXON | mcmdr_flags;
177
+
664
+ emc_write(qts, mod, REG_MCMDR, mcmdr);
178
+ status = qtest_readl(qts, CAN1_BASE_ADDR + R_SR_OFFSET);
665
+ }
179
+ g_assert_cmpint(status, ==, STATUS_NORMAL_MODE);
666
+
180
+
667
+ /* Prod the device to accept a packet. */
181
+ send_data(qts, CAN0_BASE_ADDR, buf_tx);
668
+ emc_write(qts, mod, REG_RSDR, 1);
182
+
669
+}
183
+ read_data(qts, CAN1_BASE_ADDR, buf_rx);
670
+
184
+ match_rx_tx_data(buf_tx, buf_rx, can_timestamp);
671
+static void emc_recv_verify(QTestState *qts, const EMCModule *mod, int fd,
672
+ bool with_irq)
673
+{
674
+ NPCM7xxEMCRxDesc desc[NUM_RX_DESCRIPTORS];
675
+ uint32_t desc_addr = DESC_ADDR;
676
+ uint32_t data_addr = DATA_ADDR;
677
+ int ret;
678
+ uint32_t expected_mask, expected_value;
679
+ NPCM7xxEMCRxDesc result_desc;
680
+
681
+ /* Prepare test data buffer. */
682
+ const char test[RX_DATA_LEN] = "TEST";
683
+ int len = htonl(sizeof(test));
684
+ const struct iovec iov[] = {
685
+ {
686
+ .iov_base = &len,
687
+ .iov_len = sizeof(len),
688
+ },{
689
+ .iov_base = (char *) test,
690
+ .iov_len = sizeof(test),
691
+ },
692
+ };
693
+
694
+ /*
695
+ * Reset the device BEFORE sending a test packet, otherwise the packet
696
+ * may get swallowed by an active device of an earlier test.
697
+ */
698
+ init_rx_desc(&desc[0], NUM_RX_DESCRIPTORS, desc_addr, data_addr);
699
+ enable_rx(qts, mod, &desc[0], NUM_RX_DESCRIPTORS, desc_addr,
700
+ with_irq ? REG_MIEN_ENRXINTR : 0, 0);
701
+
702
+ /* Send test packet to device's socket. */
703
+ ret = iov_send(fd, iov, 2, 0, sizeof(len) + sizeof(test));
704
+ g_assert_cmpint(ret, == , sizeof(test) + sizeof(len));
705
+
706
+ /* Wait for RX interrupt. */
707
+ if (with_irq) {
708
+ g_assert_true(emc_wait_irq(qts, mod, RX_STEP_COUNT, /*is_tx=*/false));
709
+ } else {
710
+ g_assert_true(emc_wait_mista(qts, mod, RX_STEP_COUNT, REG_MISTA_RXGD));
711
+ }
712
+
713
+ g_assert_cmphex(emc_read(qts, mod, REG_CRXDSA), ==,
714
+ desc_addr + sizeof(desc[0]));
715
+
716
+ expected_mask = 0xffff;
717
+ expected_value = (REG_MISTA_DENI |
718
+ REG_MISTA_RXGD |
719
+ REG_MISTA_RXINTR);
720
+ g_assert_cmphex((emc_read(qts, mod, REG_MISTA) & expected_mask),
721
+ ==, expected_value);
722
+
723
+ /* Read the descriptor back. */
724
+ emc_read_rx_desc(qts, desc_addr, &result_desc);
725
+ /* Descriptor should be owned by cpu now. */
726
+ g_assert((result_desc.status_and_length & RX_DESC_STATUS_OWNER_MASK) == 0);
727
+ /* Test the status bits, ignoring the length field. */
728
+ expected_mask = 0xffff << 16;
729
+ expected_value = RX_DESC_STATUS_RXGD;
730
+ if (with_irq) {
731
+ expected_value |= RX_DESC_STATUS_RXINTR;
732
+ }
733
+ g_assert_cmphex((result_desc.status_and_length & expected_mask), ==,
734
+ expected_value);
735
+ g_assert_cmpint(RX_DESC_PKT_LEN(result_desc.status_and_length), ==,
736
+ RX_DATA_LEN + CRC_LENGTH);
737
+
738
+ {
739
+ char buffer[RX_DATA_LEN];
740
+ qtest_memread(qts, data_addr, buffer, sizeof(buffer));
741
+ g_assert_cmpstr(buffer, == , "TEST");
742
+ }
743
+}
744
+
745
+static void emc_test_ptle(QTestState *qts, const EMCModule *mod, int fd)
746
+{
747
+ NPCM7xxEMCRxDesc desc[NUM_RX_DESCRIPTORS];
748
+ uint32_t desc_addr = DESC_ADDR;
749
+ uint32_t data_addr = DATA_ADDR;
750
+ int ret;
751
+ NPCM7xxEMCRxDesc result_desc;
752
+ uint32_t expected_mask, expected_value;
753
+
754
+ /* Prepare test data buffer. */
755
+#define PTLE_DATA_LEN 1600
756
+ char test_data[PTLE_DATA_LEN];
757
+ int len = htonl(sizeof(test_data));
758
+ const struct iovec iov[] = {
759
+ {
760
+ .iov_base = &len,
761
+ .iov_len = sizeof(len),
762
+ },{
763
+ .iov_base = (char *) test_data,
764
+ .iov_len = sizeof(test_data),
765
+ },
766
+ };
767
+ memset(test_data, 42, sizeof(test_data));
768
+
769
+ /*
770
+ * Reset the device BEFORE sending a test packet, otherwise the packet
771
+ * may get swallowed by an active device of an earlier test.
772
+ */
773
+ init_rx_desc(&desc[0], NUM_RX_DESCRIPTORS, desc_addr, data_addr);
774
+ enable_rx(qts, mod, &desc[0], NUM_RX_DESCRIPTORS, desc_addr,
775
+ REG_MIEN_ENRXINTR, REG_MCMDR_ALP);
776
+
777
+ /* Send test packet to device's socket. */
778
+ ret = iov_send(fd, iov, 2, 0, sizeof(len) + sizeof(test_data));
779
+ g_assert_cmpint(ret, == , sizeof(test_data) + sizeof(len));
780
+
781
+ /* Wait for RX interrupt. */
782
+ g_assert_true(emc_wait_irq(qts, mod, RX_STEP_COUNT, /*is_tx=*/false));
783
+
784
+ /* Read the descriptor back. */
785
+ emc_read_rx_desc(qts, desc_addr, &result_desc);
786
+ /* Descriptor should be owned by cpu now. */
787
+ g_assert((result_desc.status_and_length & RX_DESC_STATUS_OWNER_MASK) == 0);
788
+ /* Test the status bits, ignoring the length field. */
789
+ expected_mask = 0xffff << 16;
790
+ expected_value = (RX_DESC_STATUS_RXGD |
791
+ RX_DESC_STATUS_PTLE |
792
+ RX_DESC_STATUS_RXINTR);
793
+ g_assert_cmphex((result_desc.status_and_length & expected_mask), ==,
794
+ expected_value);
795
+ g_assert_cmpint(RX_DESC_PKT_LEN(result_desc.status_and_length), ==,
796
+ PTLE_DATA_LEN + CRC_LENGTH);
797
+
798
+ {
799
+ char buffer[PTLE_DATA_LEN];
800
+ qtest_memread(qts, data_addr, buffer, sizeof(buffer));
801
+ g_assert(memcmp(buffer, test_data, PTLE_DATA_LEN) == 0);
802
+ }
803
+}
804
+
805
+static void test_tx(gconstpointer test_data)
806
+{
807
+ const TestData *td = test_data;
808
+ GString *cmd_line = g_string_new("-machine quanta-gsj");
809
+ int *test_sockets = packet_test_init(emc_module_index(td->module),
810
+ cmd_line);
811
+ QTestState *qts = qtest_init(cmd_line->str);
812
+
813
+ /*
814
+ * TODO: For pedantic correctness test_sockets[0] should be closed after
815
+ * the fork and before the exec, but that will require some harness
816
+ * improvements.
817
+ */
818
+ close(test_sockets[1]);
819
+ /* Defensive programming */
820
+ test_sockets[1] = -1;
821
+
822
+ qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic");
823
+
824
+ emc_send_verify(qts, td->module, test_sockets[0], /*with_irq=*/false);
825
+ emc_send_verify(qts, td->module, test_sockets[0], /*with_irq=*/true);
185
+
826
+
186
+ qtest_quit(qts);
827
+ qtest_quit(qts);
187
+}
828
+}
188
+
829
+
189
+/*
830
+static void test_rx(gconstpointer test_data)
190
+ * This test is performing loopback mode on CAN0 and CAN1. Data sent from TX of
831
+{
191
+ * each CAN0 and CAN1 are compared with RX register data for respective CAN.
832
+ const TestData *td = test_data;
192
+ */
833
+ GString *cmd_line = g_string_new("-machine quanta-gsj");
193
+static void test_can_loopback(void)
834
+ int *test_sockets = packet_test_init(emc_module_index(td->module),
194
+{
835
+ cmd_line);
195
+ uint32_t buf_tx[4] = { 0xFF, 0x80000000, 0x12345678, 0x87654321 };
836
+ QTestState *qts = qtest_init(cmd_line->str);
196
+ uint32_t buf_rx[4] = { 0x00, 0x00, 0x00, 0x00 };
837
+
197
+ uint32_t status = 0;
838
+ /*
198
+
839
+ * TODO: For pedantic correctness test_sockets[0] should be closed after
199
+ QTestState *qts = qtest_init("-machine xlnx-zcu102"
840
+ * the fork and before the exec, but that will require some harness
200
+ " -object can-bus,id=canbus0"
841
+ * improvements.
201
+ " -machine xlnx-zcu102.canbus0=canbus0"
842
+ */
202
+ " -machine xlnx-zcu102.canbus1=canbus0"
843
+ close(test_sockets[1]);
203
+ );
844
+ /* Defensive programming */
204
+
845
+ test_sockets[1] = -1;
205
+ /* Configure the CAN0 in loopback mode. */
846
+
206
+ qtest_writel(qts, CAN0_BASE_ADDR + R_SRR_OFFSET, CONFIG_MODE);
847
+ qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic");
207
+ qtest_writel(qts, CAN0_BASE_ADDR + R_MSR_OFFSET, LOOPBACK_MODE);
848
+
208
+ qtest_writel(qts, CAN0_BASE_ADDR + R_SRR_OFFSET, ENABLE_CAN);
849
+ emc_recv_verify(qts, td->module, test_sockets[0], /*with_irq=*/false);
209
+
850
+ emc_recv_verify(qts, td->module, test_sockets[0], /*with_irq=*/true);
210
+ /* Check here if CAN0 is set in loopback mode. */
851
+ emc_test_ptle(qts, td->module, test_sockets[0]);
211
+ status = qtest_readl(qts, CAN0_BASE_ADDR + R_SR_OFFSET);
212
+
213
+ g_assert_cmpint(status, ==, STATUS_LOOPBACK_MODE);
214
+
215
+ send_data(qts, CAN0_BASE_ADDR, buf_tx);
216
+ read_data(qts, CAN0_BASE_ADDR, buf_rx);
217
+ match_rx_tx_data(buf_tx, buf_rx, 0);
218
+
219
+ /* Configure the CAN1 in loopback mode. */
220
+ qtest_writel(qts, CAN1_BASE_ADDR + R_SRR_OFFSET, CONFIG_MODE);
221
+ qtest_writel(qts, CAN1_BASE_ADDR + R_MSR_OFFSET, LOOPBACK_MODE);
222
+ qtest_writel(qts, CAN1_BASE_ADDR + R_SRR_OFFSET, ENABLE_CAN);
223
+
224
+ /* Check here if CAN1 is set in loopback mode. */
225
+ status = qtest_readl(qts, CAN1_BASE_ADDR + R_SR_OFFSET);
226
+
227
+ g_assert_cmpint(status, ==, STATUS_LOOPBACK_MODE);
228
+
229
+ send_data(qts, CAN1_BASE_ADDR, buf_tx);
230
+ read_data(qts, CAN1_BASE_ADDR, buf_rx);
231
+ match_rx_tx_data(buf_tx, buf_rx, 0);
232
+
852
+
233
+ qtest_quit(qts);
853
+ qtest_quit(qts);
234
+}
854
+}
235
+
855
+
236
+/*
856
+static void emc_add_test(const char *name, const TestData* td,
237
+ * Enable filters for CAN1. This will filter incoming messages with ID. In this
857
+ GTestDataFunc fn)
238
+ * test message will pass through filter 2.
858
+{
239
+ */
859
+ g_autofree char *full_name = g_strdup_printf(
240
+static void test_can_filter(void)
860
+ "npcm7xx_emc/emc[%d]/%s", emc_module_index(td->module), name);
241
+{
861
+ qtest_add_data_func(full_name, td, fn);
242
+ uint32_t buf_tx[4] = { 0x14, 0x80000000, 0x12345678, 0x87654321 };
862
+}
243
+ uint32_t buf_rx[4] = { 0x00, 0x00, 0x00, 0x00 };
863
+#define add_test(name, td) emc_add_test(#name, td, test_##name)
244
+ uint32_t status = 0;
245
+ uint8_t can_timestamp = 1;
246
+
247
+ QTestState *qts = qtest_init("-machine xlnx-zcu102"
248
+ " -object can-bus,id=canbus0"
249
+ " -machine xlnx-zcu102.canbus0=canbus0"
250
+ " -machine xlnx-zcu102.canbus1=canbus0"
251
+ );
252
+
253
+ /* Configure the CAN0 and CAN1. */
254
+ qtest_writel(qts, CAN0_BASE_ADDR + R_SRR_OFFSET, ENABLE_CAN);
255
+ qtest_writel(qts, CAN0_BASE_ADDR + R_MSR_OFFSET, NORMAL_MODE);
256
+ qtest_writel(qts, CAN1_BASE_ADDR + R_SRR_OFFSET, ENABLE_CAN);
257
+ qtest_writel(qts, CAN1_BASE_ADDR + R_MSR_OFFSET, NORMAL_MODE);
258
+
259
+ /* Check here if CAN0 and CAN1 are in normal mode. */
260
+ status = qtest_readl(qts, CAN0_BASE_ADDR + R_SR_OFFSET);
261
+ g_assert_cmpint(status, ==, STATUS_NORMAL_MODE);
262
+
263
+ status = qtest_readl(qts, CAN1_BASE_ADDR + R_SR_OFFSET);
264
+ g_assert_cmpint(status, ==, STATUS_NORMAL_MODE);
265
+
266
+ /* Set filter for CAN1 for incoming messages. */
267
+ qtest_writel(qts, CAN1_BASE_ADDR + R_AFR, 0x0);
268
+ qtest_writel(qts, CAN1_BASE_ADDR + R_AFMR1, 0xF7);
269
+ qtest_writel(qts, CAN1_BASE_ADDR + R_AFIR1, 0x121F);
270
+ qtest_writel(qts, CAN1_BASE_ADDR + R_AFMR2, 0x5431);
271
+ qtest_writel(qts, CAN1_BASE_ADDR + R_AFIR2, 0x14);
272
+ qtest_writel(qts, CAN1_BASE_ADDR + R_AFMR3, 0x1234);
273
+ qtest_writel(qts, CAN1_BASE_ADDR + R_AFIR3, 0x5431);
274
+ qtest_writel(qts, CAN1_BASE_ADDR + R_AFMR4, 0xFFF);
275
+ qtest_writel(qts, CAN1_BASE_ADDR + R_AFIR4, 0x1234);
276
+
277
+ qtest_writel(qts, CAN1_BASE_ADDR + R_AFR, 0xF);
278
+
279
+ send_data(qts, CAN0_BASE_ADDR, buf_tx);
280
+
281
+ read_data(qts, CAN1_BASE_ADDR, buf_rx);
282
+ match_rx_tx_data(buf_tx, buf_rx, can_timestamp);
283
+
284
+ qtest_quit(qts);
285
+}
286
+
287
+/* Testing sleep mode on CAN0 while CAN1 is in normal mode. */
288
+static void test_can_sleepmode(void)
289
+{
290
+ uint32_t buf_tx[4] = { 0x14, 0x80000000, 0x12345678, 0x87654321 };
291
+ uint32_t buf_rx[4] = { 0x00, 0x00, 0x00, 0x00 };
292
+ uint32_t status = 0;
293
+ uint8_t can_timestamp = 1;
294
+
295
+ QTestState *qts = qtest_init("-machine xlnx-zcu102"
296
+ " -object can-bus,id=canbus0"
297
+ " -machine xlnx-zcu102.canbus0=canbus0"
298
+ " -machine xlnx-zcu102.canbus1=canbus0"
299
+ );
300
+
301
+ /* Configure the CAN0. */
302
+ qtest_writel(qts, CAN0_BASE_ADDR + R_SRR_OFFSET, CONFIG_MODE);
303
+ qtest_writel(qts, CAN0_BASE_ADDR + R_MSR_OFFSET, SLEEP_MODE);
304
+ qtest_writel(qts, CAN0_BASE_ADDR + R_SRR_OFFSET, ENABLE_CAN);
305
+
306
+ qtest_writel(qts, CAN1_BASE_ADDR + R_SRR_OFFSET, ENABLE_CAN);
307
+ qtest_writel(qts, CAN1_BASE_ADDR + R_MSR_OFFSET, NORMAL_MODE);
308
+
309
+ /* Check here if CAN0 is in SLEEP mode and CAN1 in normal mode. */
310
+ status = qtest_readl(qts, CAN0_BASE_ADDR + R_SR_OFFSET);
311
+ g_assert_cmpint(status, ==, STATUS_SLEEP_MODE);
312
+
313
+ status = qtest_readl(qts, CAN1_BASE_ADDR + R_SR_OFFSET);
314
+ g_assert_cmpint(status, ==, STATUS_NORMAL_MODE);
315
+
316
+ send_data(qts, CAN1_BASE_ADDR, buf_tx);
317
+
318
+ /*
319
+ * Once CAN1 sends data on can-bus. CAN0 should exit sleep mode.
320
+ * Check the CAN0 status now. It should exit the sleep mode and receive the
321
+ * incoming data.
322
+ */
323
+ status = qtest_readl(qts, CAN0_BASE_ADDR + R_SR_OFFSET);
324
+ g_assert_cmpint(status, ==, STATUS_NORMAL_MODE);
325
+
326
+ read_data(qts, CAN0_BASE_ADDR, buf_rx);
327
+
328
+ match_rx_tx_data(buf_tx, buf_rx, can_timestamp);
329
+
330
+ qtest_quit(qts);
331
+}
332
+
333
+/* Testing Snoop mode on CAN0 while CAN1 is in normal mode. */
334
+static void test_can_snoopmode(void)
335
+{
336
+ uint32_t buf_tx[4] = { 0x14, 0x80000000, 0x12345678, 0x87654321 };
337
+ uint32_t buf_rx[4] = { 0x00, 0x00, 0x00, 0x00 };
338
+ uint32_t status = 0;
339
+ uint8_t can_timestamp = 1;
340
+
341
+ QTestState *qts = qtest_init("-machine xlnx-zcu102"
342
+ " -object can-bus,id=canbus0"
343
+ " -machine xlnx-zcu102.canbus0=canbus0"
344
+ " -machine xlnx-zcu102.canbus1=canbus0"
345
+ );
346
+
347
+ /* Configure the CAN0. */
348
+ qtest_writel(qts, CAN0_BASE_ADDR + R_SRR_OFFSET, CONFIG_MODE);
349
+ qtest_writel(qts, CAN0_BASE_ADDR + R_MSR_OFFSET, SNOOP_MODE);
350
+ qtest_writel(qts, CAN0_BASE_ADDR + R_SRR_OFFSET, ENABLE_CAN);
351
+
352
+ qtest_writel(qts, CAN1_BASE_ADDR + R_SRR_OFFSET, ENABLE_CAN);
353
+ qtest_writel(qts, CAN1_BASE_ADDR + R_MSR_OFFSET, NORMAL_MODE);
354
+
355
+ /* Check here if CAN0 is in SNOOP mode and CAN1 in normal mode. */
356
+ status = qtest_readl(qts, CAN0_BASE_ADDR + R_SR_OFFSET);
357
+ g_assert_cmpint(status, ==, STATUS_SNOOP_MODE);
358
+
359
+ status = qtest_readl(qts, CAN1_BASE_ADDR + R_SR_OFFSET);
360
+ g_assert_cmpint(status, ==, STATUS_NORMAL_MODE);
361
+
362
+ send_data(qts, CAN1_BASE_ADDR, buf_tx);
363
+
364
+ read_data(qts, CAN0_BASE_ADDR, buf_rx);
365
+
366
+ match_rx_tx_data(buf_tx, buf_rx, can_timestamp);
367
+
368
+ qtest_quit(qts);
369
+}
370
+
864
+
371
+int main(int argc, char **argv)
865
+int main(int argc, char **argv)
372
+{
866
+{
867
+ TestData test_data_list[ARRAY_SIZE(emc_module_list)];
868
+
373
+ g_test_init(&argc, &argv, NULL);
869
+ g_test_init(&argc, &argv, NULL);
374
+
870
+
375
+ qtest_add_func("/net/can/can_bus", test_can_bus);
871
+ for (int i = 0; i < ARRAY_SIZE(emc_module_list); ++i) {
376
+ qtest_add_func("/net/can/can_loopback", test_can_loopback);
872
+ TestData *td = &test_data_list[i];
377
+ qtest_add_func("/net/can/can_filter", test_can_filter);
873
+
378
+ qtest_add_func("/net/can/can_test_snoopmode", test_can_snoopmode);
874
+ td->module = &emc_module_list[i];
379
+ qtest_add_func("/net/can/can_test_sleepmode", test_can_sleepmode);
875
+
876
+ add_test(init, td);
877
+ add_test(tx, td);
878
+ add_test(rx, td);
879
+ }
380
+
880
+
381
+ return g_test_run();
881
+ return g_test_run();
382
+}
882
+}
383
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
883
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
384
index XXXXXXX..XXXXXXX 100644
884
index XXXXXXX..XXXXXXX 100644
385
--- a/tests/qtest/meson.build
885
--- a/tests/qtest/meson.build
386
+++ b/tests/qtest/meson.build
886
+++ b/tests/qtest/meson.build
387
@@ -XXX,XX +XXX,XX @@ qtests_aarch64 = \
887
@@ -XXX,XX +XXX,XX @@ qtests_npcm7xx = \
388
(config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? ['tpm-tis-device-swtpm-test'] : []) + \
888
'npcm7xx_rng-test',
389
['numa-test',
889
'npcm7xx_smbus-test',
390
'boot-serial-test',
890
'npcm7xx_timer-test',
391
+ 'xlnx-can-test',
891
- 'npcm7xx_watchdog_timer-test']
392
'migration-test']
892
+ 'npcm7xx_watchdog_timer-test'] + \
393
893
+ (slirp.found() ? ['npcm7xx_emc-test'] : [])
394
qtests_s390x = \
894
qtests_arm = \
895
(config_all_devices.has_key('CONFIG_CMSDK_APB_DUALTIMER') ? ['cmsdk-apb-dualtimer-test'] : []) + \
896
(config_all_devices.has_key('CONFIG_CMSDK_APB_TIMER') ? ['cmsdk-apb-timer-test'] : []) + \
395
--
897
--
396
2.20.1
898
2.20.1
397
899
398
900
diff view generated by jsdifflib
1
From: Vikram Garhwal <fnu.vikram@xilinx.com>
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
Connect CAN0 and CAN1 on the ZynqMP.
3
We hint the 'has_rpu' property is no longer required since commit
4
6908ec448b4 ("xlnx-zynqmp: Properly support the smp command line
5
option") which was released in QEMU v2.11.0.
4
6
5
Reviewed-by: Francisco Iglesias <francisco.iglesias@xilinx.com>
7
Beside, this device is marked 'user_creatable = false', so the
6
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
8
only thing that could be setting the property is the board code
7
Signed-off-by: Vikram Garhwal <fnu.vikram@xilinx.com>
9
that creates the device.
8
Message-id: 1597278668-339715-3-git-send-email-fnu.vikram@xilinx.com
10
11
Since the property is not user-facing, we can remove it without
12
going through the deprecation process.
13
14
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
15
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
16
Message-id: 20210219144350.1979905-1-f4bug@amsat.org
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
18
---
11
include/hw/arm/xlnx-zynqmp.h | 8 ++++++++
19
include/hw/arm/xlnx-zynqmp.h | 2 --
12
hw/arm/xlnx-zcu102.c | 20 ++++++++++++++++++++
20
hw/arm/xlnx-zynqmp.c | 6 ------
13
hw/arm/xlnx-zynqmp.c | 34 ++++++++++++++++++++++++++++++++++
21
2 files changed, 8 deletions(-)
14
3 files changed, 62 insertions(+)
15
22
16
diff --git a/include/hw/arm/xlnx-zynqmp.h b/include/hw/arm/xlnx-zynqmp.h
23
diff --git a/include/hw/arm/xlnx-zynqmp.h b/include/hw/arm/xlnx-zynqmp.h
17
index XXXXXXX..XXXXXXX 100644
24
index XXXXXXX..XXXXXXX 100644
18
--- a/include/hw/arm/xlnx-zynqmp.h
25
--- a/include/hw/arm/xlnx-zynqmp.h
19
+++ b/include/hw/arm/xlnx-zynqmp.h
26
+++ b/include/hw/arm/xlnx-zynqmp.h
20
@@ -XXX,XX +XXX,XX @@
21
#include "hw/intc/arm_gic.h"
22
#include "hw/net/cadence_gem.h"
23
#include "hw/char/cadence_uart.h"
24
+#include "hw/net/xlnx-zynqmp-can.h"
25
#include "hw/ide/ahci.h"
26
#include "hw/sd/sdhci.h"
27
#include "hw/ssi/xilinx_spips.h"
28
@@ -XXX,XX +XXX,XX @@
29
#include "hw/cpu/cluster.h"
30
#include "target/arm/cpu.h"
31
#include "qom/object.h"
32
+#include "net/can_emu.h"
33
34
#define TYPE_XLNX_ZYNQMP "xlnx,zynqmp"
35
typedef struct XlnxZynqMPState XlnxZynqMPState;
36
@@ -XXX,XX +XXX,XX @@ DECLARE_INSTANCE_CHECKER(XlnxZynqMPState, XLNX_ZYNQMP,
37
#define XLNX_ZYNQMP_NUM_RPU_CPUS 2
38
#define XLNX_ZYNQMP_NUM_GEMS 4
39
#define XLNX_ZYNQMP_NUM_UARTS 2
40
+#define XLNX_ZYNQMP_NUM_CAN 2
41
+#define XLNX_ZYNQMP_CAN_REF_CLK (24 * 1000 * 1000)
42
#define XLNX_ZYNQMP_NUM_SDHCI 2
43
#define XLNX_ZYNQMP_NUM_SPIS 2
44
#define XLNX_ZYNQMP_NUM_GDMA_CH 8
45
@@ -XXX,XX +XXX,XX @@ struct XlnxZynqMPState {
27
@@ -XXX,XX +XXX,XX @@ struct XlnxZynqMPState {
46
28
bool secure;
47
CadenceGEMState gem[XLNX_ZYNQMP_NUM_GEMS];
29
/* Has the ARM Virtualization extensions? */
48
CadenceUARTState uart[XLNX_ZYNQMP_NUM_UARTS];
49
+ XlnxZynqMPCANState can[XLNX_ZYNQMP_NUM_CAN];
50
SysbusAHCIState sata;
51
SDHCIState sdhci[XLNX_ZYNQMP_NUM_SDHCI];
52
XilinxSPIPS spi[XLNX_ZYNQMP_NUM_SPIS];
53
@@ -XXX,XX +XXX,XX @@ struct XlnxZynqMPState {
54
bool virt;
30
bool virt;
55
/* Has the RPU subsystem? */
31
- /* Has the RPU subsystem? */
56
bool has_rpu;
32
- bool has_rpu;
57
+
33
58
+ /* CAN bus. */
34
/* CAN bus. */
59
+ CanBusState *canbus[XLNX_ZYNQMP_NUM_CAN];
35
CanBusState *canbus[XLNX_ZYNQMP_NUM_CAN];
60
};
61
62
#endif
63
diff --git a/hw/arm/xlnx-zcu102.c b/hw/arm/xlnx-zcu102.c
64
index XXXXXXX..XXXXXXX 100644
65
--- a/hw/arm/xlnx-zcu102.c
66
+++ b/hw/arm/xlnx-zcu102.c
67
@@ -XXX,XX +XXX,XX @@
68
#include "sysemu/qtest.h"
69
#include "sysemu/device_tree.h"
70
#include "qom/object.h"
71
+#include "net/can_emu.h"
72
73
struct XlnxZCU102 {
74
MachineState parent_obj;
75
@@ -XXX,XX +XXX,XX @@ struct XlnxZCU102 {
76
bool secure;
77
bool virt;
78
79
+ CanBusState *canbus[XLNX_ZYNQMP_NUM_CAN];
80
+
81
struct arm_boot_info binfo;
82
};
83
typedef struct XlnxZCU102 XlnxZCU102;
84
@@ -XXX,XX +XXX,XX @@ static void xlnx_zcu102_init(MachineState *machine)
85
object_property_set_bool(OBJECT(&s->soc), "virtualization", s->virt,
86
&error_fatal);
87
88
+ for (i = 0; i < XLNX_ZYNQMP_NUM_CAN; i++) {
89
+ gchar *bus_name = g_strdup_printf("canbus%d", i);
90
+
91
+ object_property_set_link(OBJECT(&s->soc), bus_name,
92
+ OBJECT(s->canbus[i]), &error_fatal);
93
+ g_free(bus_name);
94
+ }
95
+
96
qdev_realize(DEVICE(&s->soc), NULL, &error_fatal);
97
98
/* Create and plug in the SD cards */
99
@@ -XXX,XX +XXX,XX @@ static void xlnx_zcu102_machine_instance_init(Object *obj)
100
"Set on/off to enable/disable emulating a "
101
"guest CPU which implements the ARM "
102
"Virtualization Extensions");
103
+ object_property_add_link(obj, "xlnx-zcu102.canbus0", TYPE_CAN_BUS,
104
+ (Object **)&s->canbus[0],
105
+ object_property_allow_set_link,
106
+ 0);
107
+
108
+ object_property_add_link(obj, "xlnx-zcu102.canbus1", TYPE_CAN_BUS,
109
+ (Object **)&s->canbus[1],
110
+ object_property_allow_set_link,
111
+ 0);
112
}
113
114
static void xlnx_zcu102_machine_class_init(ObjectClass *oc, void *data)
115
diff --git a/hw/arm/xlnx-zynqmp.c b/hw/arm/xlnx-zynqmp.c
36
diff --git a/hw/arm/xlnx-zynqmp.c b/hw/arm/xlnx-zynqmp.c
116
index XXXXXXX..XXXXXXX 100644
37
index XXXXXXX..XXXXXXX 100644
117
--- a/hw/arm/xlnx-zynqmp.c
38
--- a/hw/arm/xlnx-zynqmp.c
118
+++ b/hw/arm/xlnx-zynqmp.c
39
+++ b/hw/arm/xlnx-zynqmp.c
119
@@ -XXX,XX +XXX,XX @@ static const int uart_intr[XLNX_ZYNQMP_NUM_UARTS] = {
40
@@ -XXX,XX +XXX,XX @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
120
21, 22,
41
}
121
};
122
123
+static const uint64_t can_addr[XLNX_ZYNQMP_NUM_CAN] = {
124
+ 0xFF060000, 0xFF070000,
125
+};
126
+
127
+static const int can_intr[XLNX_ZYNQMP_NUM_CAN] = {
128
+ 23, 24,
129
+};
130
+
131
static const uint64_t sdhci_addr[XLNX_ZYNQMP_NUM_SDHCI] = {
132
0xFF160000, 0xFF170000,
133
};
134
@@ -XXX,XX +XXX,XX @@ static void xlnx_zynqmp_init(Object *obj)
135
TYPE_CADENCE_UART);
136
}
42
}
137
43
138
+ for (i = 0; i < XLNX_ZYNQMP_NUM_CAN; i++) {
44
- if (s->has_rpu) {
139
+ object_initialize_child(obj, "can[*]", &s->can[i],
45
- info_report("The 'has_rpu' property is no longer required, to use the "
140
+ TYPE_XLNX_ZYNQMP_CAN);
46
- "RPUs just use -smp 6.");
141
+ }
47
- }
142
+
48
-
143
object_initialize_child(obj, "sata", &s->sata, TYPE_SYSBUS_AHCI);
49
xlnx_zynqmp_create_rpu(ms, s, boot_cpu, &err);
144
50
if (err) {
145
for (i = 0; i < XLNX_ZYNQMP_NUM_SDHCI; i++) {
51
error_propagate(errp, err);
146
@@ -XXX,XX +XXX,XX @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
147
gic_spi[uart_intr[i]]);
148
}
149
150
+ for (i = 0; i < XLNX_ZYNQMP_NUM_CAN; i++) {
151
+ object_property_set_int(OBJECT(&s->can[i]), "ext_clk_freq",
152
+ XLNX_ZYNQMP_CAN_REF_CLK, &error_abort);
153
+
154
+ object_property_set_link(OBJECT(&s->can[i]), "canbus",
155
+ OBJECT(s->canbus[i]), &error_fatal);
156
+
157
+ sysbus_realize(SYS_BUS_DEVICE(&s->can[i]), &err);
158
+ if (err) {
159
+ error_propagate(errp, err);
160
+ return;
161
+ }
162
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->can[i]), 0, can_addr[i]);
163
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->can[i]), 0,
164
+ gic_spi[can_intr[i]]);
165
+ }
166
+
167
object_property_set_int(OBJECT(&s->sata), "num-ports", SATA_NUM_PORTS,
168
&error_abort);
169
if (!sysbus_realize(SYS_BUS_DEVICE(&s->sata), errp)) {
170
@@ -XXX,XX +XXX,XX @@ static Property xlnx_zynqmp_props[] = {
52
@@ -XXX,XX +XXX,XX @@ static Property xlnx_zynqmp_props[] = {
171
DEFINE_PROP_BOOL("has_rpu", XlnxZynqMPState, has_rpu, false),
53
DEFINE_PROP_STRING("boot-cpu", XlnxZynqMPState, boot_cpu),
54
DEFINE_PROP_BOOL("secure", XlnxZynqMPState, secure, false),
55
DEFINE_PROP_BOOL("virtualization", XlnxZynqMPState, virt, false),
56
- DEFINE_PROP_BOOL("has_rpu", XlnxZynqMPState, has_rpu, false),
172
DEFINE_PROP_LINK("ddr-ram", XlnxZynqMPState, ddr_ram, TYPE_MEMORY_REGION,
57
DEFINE_PROP_LINK("ddr-ram", XlnxZynqMPState, ddr_ram, TYPE_MEMORY_REGION,
173
MemoryRegion *),
58
MemoryRegion *),
174
+ DEFINE_PROP_LINK("canbus0", XlnxZynqMPState, canbus[0], TYPE_CAN_BUS,
59
DEFINE_PROP_LINK("canbus0", XlnxZynqMPState, canbus[0], TYPE_CAN_BUS,
175
+ CanBusState *),
176
+ DEFINE_PROP_LINK("canbus1", XlnxZynqMPState, canbus[1], TYPE_CAN_BUS,
177
+ CanBusState *),
178
DEFINE_PROP_END_OF_LIST()
179
};
180
181
--
60
--
182
2.20.1
61
2.20.1
183
62
184
63
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Richard Henderson <richard.henderson@linaro.org>
2
2
3
Only argument set members have to be C identifiers, everything
3
Always perform one call instead of two for 16-byte operands.
4
else gets prefixed during conversion to C. Some places just
4
Use byte loads/stores directly into the vector register file
5
checked the leading character, and some places matched a leading
5
instead of extractions and deposits to a 64-bit local variable.
6
character plus a C identifier.
6
7
7
In order to easily receive pointers into the vector register file,
8
Convert everything to match full identifiers, including the
8
convert the helper to the gvec out-of-line signature. Move the
9
[&%@&] prefix, and drop the full C identifier requirement.
9
helper into vec_helper.c, where it can make use of H1 and clear_tail.
10
10
11
Reported-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
11
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
13
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
12
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
14
Message-id: 20200903192334.1603773-1-richard.henderson@linaro.org
13
Tested-by: Alex Bennée <alex.bennee@linaro.org>
14
Message-id: 20210224230532.276878-1-richard.henderson@linaro.org
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
---
16
---
17
tests/decode/succ_ident1.decode | 7 +++++
17
target/arm/helper-a64.h | 2 +-
18
scripts/decodetree.py | 46 +++++++++++++++++++++------------
18
target/arm/helper-a64.c | 32 ---------------------
19
2 files changed, 37 insertions(+), 16 deletions(-)
19
target/arm/translate-a64.c | 58 +++++---------------------------------
20
create mode 100644 tests/decode/succ_ident1.decode
20
target/arm/vec_helper.c | 48 +++++++++++++++++++++++++++++++
21
21
4 files changed, 56 insertions(+), 84 deletions(-)
22
diff --git a/tests/decode/succ_ident1.decode b/tests/decode/succ_ident1.decode
22
23
new file mode 100644
23
diff --git a/target/arm/helper-a64.h b/target/arm/helper-a64.h
24
index XXXXXXX..XXXXXXX
24
index XXXXXXX..XXXXXXX 100644
25
--- /dev/null
25
--- a/target/arm/helper-a64.h
26
+++ b/tests/decode/succ_ident1.decode
26
+++ b/target/arm/helper-a64.h
27
@@ -XXX,XX +XXX,XX @@
27
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_3(vfp_cmps_a64, i64, f32, f32, ptr)
28
+%1f 0:8
28
DEF_HELPER_3(vfp_cmpes_a64, i64, f32, f32, ptr)
29
+%2f 8:8
29
DEF_HELPER_3(vfp_cmpd_a64, i64, f64, f64, ptr)
30
+%3f 16:8
30
DEF_HELPER_3(vfp_cmped_a64, i64, f64, f64, ptr)
31
+
31
-DEF_HELPER_FLAGS_5(simd_tbl, TCG_CALL_NO_RWG_SE, i64, env, i64, i64, i32, i32)
32
+&3arg a b c
32
+DEF_HELPER_FLAGS_4(simd_tblx, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
33
+@3arg ........ ........ ........ ........ &3arg a=%1f b=%2f c=%3f
33
DEF_HELPER_FLAGS_3(vfp_mulxs, TCG_CALL_NO_RWG, f32, f32, f32, ptr)
34
+3insn 00000000 ........ ........ ........ @3arg
34
DEF_HELPER_FLAGS_3(vfp_mulxd, TCG_CALL_NO_RWG, f64, f64, f64, ptr)
35
diff --git a/scripts/decodetree.py b/scripts/decodetree.py
35
DEF_HELPER_FLAGS_3(neon_ceq_f64, TCG_CALL_NO_RWG, i64, i64, i64, ptr)
36
index XXXXXXX..XXXXXXX 100644
36
diff --git a/target/arm/helper-a64.c b/target/arm/helper-a64.c
37
--- a/scripts/decodetree.py
37
index XXXXXXX..XXXXXXX 100644
38
+++ b/scripts/decodetree.py
38
--- a/target/arm/helper-a64.c
39
@@ -XXX,XX +XXX,XX @@ output_fd = None
39
+++ b/target/arm/helper-a64.c
40
insntype = 'uint32_t'
40
@@ -XXX,XX +XXX,XX @@ float64 HELPER(vfp_mulxd)(float64 a, float64 b, void *fpstp)
41
decode_function = 'decode'
41
return float64_mul(a, b, fpst);
42
42
}
43
-re_ident = '[a-zA-Z][a-zA-Z0-9_]*'
43
44
+# An identifier for C.
44
-uint64_t HELPER(simd_tbl)(CPUARMState *env, uint64_t result, uint64_t indices,
45
+re_C_ident = '[a-zA-Z][a-zA-Z0-9_]*'
45
- uint32_t rn, uint32_t numregs)
46
46
-{
47
+# Identifiers for Arguments, Fields, Formats and Patterns.
47
- /* Helper function for SIMD TBL and TBX. We have to do the table
48
+re_arg_ident = '&[a-zA-Z0-9_]*'
48
- * lookup part for the 64 bits worth of indices we're passed in.
49
+re_fld_ident = '%[a-zA-Z0-9_]*'
49
- * result is the initial results vector (either zeroes for TBL
50
+re_fmt_ident = '@[a-zA-Z0-9_]*'
50
- * or some guest values for TBX), rn the register number where
51
+re_pat_ident = '[a-zA-Z0-9_]*'
51
- * the table starts, and numregs the number of registers in the table.
52
52
- * We return the results of the lookups.
53
def error_with_file(file, lineno, *args):
53
- */
54
"""Print an error message from file:line and args and exit."""
54
- int shift;
55
@@ -XXX,XX +XXX,XX @@ class ExcMultiPattern(MultiPattern):
55
-
56
def parse_field(lineno, name, toks):
56
- for (shift = 0; shift < 64; shift += 8) {
57
"""Parse one instruction field from TOKS at LINENO"""
57
- int index = extract64(indices, shift, 8);
58
global fields
58
- if (index < 16 * numregs) {
59
- global re_ident
59
- /* Convert index (a byte offset into the virtual table
60
global insnwidth
60
- * which is a series of 128-bit vectors concatenated)
61
61
- * into the correct register element plus a bit offset
62
# A "simple" field will have only one entry;
62
- * into that element, bearing in mind that the table
63
@@ -XXX,XX +XXX,XX @@ def parse_field(lineno, name, toks):
63
- * can wrap around from V31 to V0.
64
width = 0
64
- */
65
func = None
65
- int elt = (rn * 2 + (index >> 3)) % 64;
66
for t in toks:
66
- int bitidx = (index & 7) * 8;
67
- if re.fullmatch('!function=' + re_ident, t):
67
- uint64_t *q = aa64_vfp_qreg(env, elt >> 1);
68
+ if re.match('^!function=', t):
68
- uint64_t val = extract64(q[elt & 1], bitidx, 8);
69
if func:
69
-
70
error(lineno, 'duplicate function')
70
- result = deposit64(result, shift, 8, val);
71
func = t.split('=')
71
- }
72
@@ -XXX,XX +XXX,XX @@ def parse_field(lineno, name, toks):
72
- }
73
def parse_arguments(lineno, name, toks):
73
- return result;
74
"""Parse one argument set from TOKS at LINENO"""
74
-}
75
global arguments
75
-
76
- global re_ident
76
/* 64bit/double versions of the neon float compare functions */
77
+ global re_C_ident
77
uint64_t HELPER(neon_ceq_f64)(float64 a, float64 b, void *fpstp)
78
global anyextern
78
{
79
79
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
80
flds = []
80
index XXXXXXX..XXXXXXX 100644
81
@@ -XXX,XX +XXX,XX @@ def parse_arguments(lineno, name, toks):
81
--- a/target/arm/translate-a64.c
82
extern = True
82
+++ b/target/arm/translate-a64.c
83
anyextern = True
83
@@ -XXX,XX +XXX,XX @@ static void disas_simd_tb(DisasContext *s, uint32_t insn)
84
continue
84
int rm = extract32(insn, 16, 5);
85
- if not re.fullmatch(re_ident, t):
85
int rn = extract32(insn, 5, 5);
86
+ if not re.fullmatch(re_C_ident, t):
86
int rd = extract32(insn, 0, 5);
87
error(lineno, 'invalid argument set token "{0}"'.format(t))
87
- int is_tblx = extract32(insn, 12, 1);
88
if t in flds:
88
- int len = extract32(insn, 13, 2);
89
error(lineno, 'duplicate argument "{0}"'.format(t))
89
- TCGv_i64 tcg_resl, tcg_resh, tcg_idx;
90
@@ -XXX,XX +XXX,XX @@ def parse_generic(lineno, parent_pat, name, toks):
90
- TCGv_i32 tcg_regno, tcg_numregs;
91
global arguments
91
+ int is_tbx = extract32(insn, 12, 1);
92
global formats
92
+ int len = (extract32(insn, 13, 2) + 1) * 16;
93
global allpatterns
93
94
- global re_ident
94
if (op2 != 0) {
95
+ global re_arg_ident
95
unallocated_encoding(s);
96
+ global re_fld_ident
96
@@ -XXX,XX +XXX,XX @@ static void disas_simd_tb(DisasContext *s, uint32_t insn)
97
+ global re_fmt_ident
97
return;
98
+ global re_C_ident
98
}
99
global insnwidth
99
100
global insnmask
100
- /* This does a table lookup: for every byte element in the input
101
global variablewidth
101
- * we index into a table formed from up to four vector registers,
102
@@ -XXX,XX +XXX,XX @@ def parse_generic(lineno, parent_pat, name, toks):
102
- * and then the output is the result of the lookups. Our helper
103
fmt = None
103
- * function does the lookup operation for a single 64 bit part of
104
for t in toks:
104
- * the input.
105
# '&Foo' gives a format an explcit argument set.
105
- */
106
- if t[0] == '&':
106
- tcg_resl = tcg_temp_new_i64();
107
+ if re.fullmatch(re_arg_ident, t):
107
- tcg_resh = NULL;
108
tt = t[1:]
108
-
109
if arg:
109
- if (is_tblx) {
110
error(lineno, 'multiple argument sets')
110
- read_vec_element(s, tcg_resl, rd, 0, MO_64);
111
@@ -XXX,XX +XXX,XX @@ def parse_generic(lineno, parent_pat, name, toks):
111
- } else {
112
continue
112
- tcg_gen_movi_i64(tcg_resl, 0);
113
113
- }
114
# '@Foo' gives a pattern an explicit format.
114
-
115
- if t[0] == '@':
115
- if (is_q) {
116
+ if re.fullmatch(re_fmt_ident, t):
116
- tcg_resh = tcg_temp_new_i64();
117
tt = t[1:]
117
- if (is_tblx) {
118
if fmt:
118
- read_vec_element(s, tcg_resh, rd, 1, MO_64);
119
error(lineno, 'multiple formats')
119
- } else {
120
@@ -XXX,XX +XXX,XX @@ def parse_generic(lineno, parent_pat, name, toks):
120
- tcg_gen_movi_i64(tcg_resh, 0);
121
continue
121
- }
122
122
- }
123
# '%Foo' imports a field.
123
-
124
- if t[0] == '%':
124
- tcg_idx = tcg_temp_new_i64();
125
+ if re.fullmatch(re_fld_ident, t):
125
- tcg_regno = tcg_const_i32(rn);
126
tt = t[1:]
126
- tcg_numregs = tcg_const_i32(len + 1);
127
flds = add_field_byname(lineno, flds, tt, tt)
127
- read_vec_element(s, tcg_idx, rm, 0, MO_64);
128
continue
128
- gen_helper_simd_tbl(tcg_resl, cpu_env, tcg_resl, tcg_idx,
129
129
- tcg_regno, tcg_numregs);
130
# 'Foo=%Bar' imports a field with a different name.
130
- if (is_q) {
131
- if re.fullmatch(re_ident + '=%' + re_ident, t):
131
- read_vec_element(s, tcg_idx, rm, 1, MO_64);
132
+ if re.fullmatch(re_C_ident + '=' + re_fld_ident, t):
132
- gen_helper_simd_tbl(tcg_resh, cpu_env, tcg_resh, tcg_idx,
133
(fname, iname) = t.split('=%')
133
- tcg_regno, tcg_numregs);
134
flds = add_field_byname(lineno, flds, fname, iname)
134
- }
135
continue
135
- tcg_temp_free_i64(tcg_idx);
136
136
- tcg_temp_free_i32(tcg_regno);
137
# 'Foo=number' sets an argument field to a constant value
137
- tcg_temp_free_i32(tcg_numregs);
138
- if re.fullmatch(re_ident + '=[+-]?[0-9]+', t):
138
-
139
+ if re.fullmatch(re_C_ident + '=[+-]?[0-9]+', t):
139
- write_vec_element(s, tcg_resl, rd, 0, MO_64);
140
(fname, value) = t.split('=')
140
- tcg_temp_free_i64(tcg_resl);
141
value = int(value)
141
-
142
flds = add_field(lineno, flds, fname, ConstField(value))
142
- if (is_q) {
143
@@ -XXX,XX +XXX,XX @@ def parse_generic(lineno, parent_pat, name, toks):
143
- write_vec_element(s, tcg_resh, rd, 1, MO_64);
144
fixedmask = (fixedmask << shift) | fms
144
- tcg_temp_free_i64(tcg_resh);
145
undefmask = (undefmask << shift) | ubm
145
- }
146
# Otherwise, fieldname:fieldwidth
146
- clear_vec_high(s, is_q, rd);
147
- elif re.fullmatch(re_ident + ':s?[0-9]+', t):
147
+ tcg_gen_gvec_2_ptr(vec_full_reg_offset(s, rd),
148
+ elif re.fullmatch(re_C_ident + ':s?[0-9]+', t):
148
+ vec_full_reg_offset(s, rm), cpu_env,
149
(fname, flen) = t.split(':')
149
+ is_q ? 16 : 8, vec_full_reg_size(s),
150
sign = False
150
+ (len << 6) | (is_tbx << 5) | rn,
151
if flen[0] == 's':
151
+ gen_helper_simd_tblx);
152
@@ -XXX,XX +XXX,XX @@ def parse_generic(lineno, parent_pat, name, toks):
152
}
153
153
154
def parse_file(f, parent_pat):
154
/* ZIP/UZP/TRN
155
"""Parse all of the patterns within a file"""
155
diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c
156
+ global re_arg_ident
156
index XXXXXXX..XXXXXXX 100644
157
+ global re_fld_ident
157
--- a/target/arm/vec_helper.c
158
+ global re_fmt_ident
158
+++ b/target/arm/vec_helper.c
159
+ global re_pat_ident
159
@@ -XXX,XX +XXX,XX @@ DO_VRINT_RMODE(gvec_vrint_rm_h, helper_rinth, uint16_t)
160
160
DO_VRINT_RMODE(gvec_vrint_rm_s, helper_rints, uint32_t)
161
# Read all of the lines of the file. Concatenate lines
161
162
# ending in backslash; discard empty lines and comments.
162
#undef DO_VRINT_RMODE
163
@@ -XXX,XX +XXX,XX @@ def parse_file(f, parent_pat):
163
+
164
continue
164
+#ifdef TARGET_AARCH64
165
165
+void HELPER(simd_tblx)(void *vd, void *vm, void *venv, uint32_t desc)
166
# Determine the type of object needing to be parsed.
166
+{
167
- if name[0] == '%':
167
+ const uint8_t *indices = vm;
168
+ if re.fullmatch(re_fld_ident, name):
168
+ CPUARMState *env = venv;
169
parse_field(start_lineno, name[1:], toks)
169
+ size_t oprsz = simd_oprsz(desc);
170
- elif name[0] == '&':
170
+ uint32_t rn = extract32(desc, SIMD_DATA_SHIFT, 5);
171
+ elif re.fullmatch(re_arg_ident, name):
171
+ bool is_tbx = extract32(desc, SIMD_DATA_SHIFT + 5, 1);
172
parse_arguments(start_lineno, name[1:], toks)
172
+ uint32_t table_len = desc >> (SIMD_DATA_SHIFT + 6);
173
- elif name[0] == '@':
173
+ union {
174
+ elif re.fullmatch(re_fmt_ident, name):
174
+ uint8_t b[16];
175
parse_generic(start_lineno, None, name[1:], toks)
175
+ uint64_t d[2];
176
- else:
176
+ } result;
177
+ elif re.fullmatch(re_pat_ident, name):
177
+
178
parse_generic(start_lineno, parent_pat, name, toks)
178
+ /*
179
+ else:
179
+ * We must construct the final result in a temp, lest the output
180
+ error(lineno, 'invalid token "{0}"'.format(name))
180
+ * overlaps the input table. For TBL, begin with zero; for TBX,
181
toks = []
181
+ * begin with the original register contents. Note that we always
182
182
+ * copy 16 bytes here to avoid an extra branch; clearing the high
183
if nesting != 0:
183
+ * bits of the register for oprsz == 8 is handled below.
184
+ */
185
+ if (is_tbx) {
186
+ memcpy(&result, vd, 16);
187
+ } else {
188
+ memset(&result, 0, 16);
189
+ }
190
+
191
+ for (size_t i = 0; i < oprsz; ++i) {
192
+ uint32_t index = indices[H1(i)];
193
+
194
+ if (index < table_len) {
195
+ /*
196
+ * Convert index (a byte offset into the virtual table
197
+ * which is a series of 128-bit vectors concatenated)
198
+ * into the correct register element, bearing in mind
199
+ * that the table can wrap around from V31 to V0.
200
+ */
201
+ const uint8_t *table = (const uint8_t *)
202
+ aa64_vfp_qreg(env, (rn + (index >> 4)) % 32);
203
+ result.b[H1(i)] = table[H1(index % 16)];
204
+ }
205
+ }
206
+
207
+ memcpy(vd, &result, 16);
208
+ clear_tail(vd, oprsz, simd_maxsz(desc));
209
+}
210
+#endif
184
--
211
--
185
2.20.1
212
2.20.1
186
213
187
214
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
Report unimplemented register accesses using qemu_log_mask(UNIMP).
3
The STATUS register will be reset to IDLE in
4
cnpcm7xx_smbus_enter_reset(), no need to preset
5
it in instance_init().
4
6
5
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Reviewed-by: Hao Wu <wuhaotsh@google.com>
7
Message-id: 20200901144100.116742-5-f4bug@amsat.org
9
Message-id: 20210228224813.312532-1-f4bug@amsat.org
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
11
---
10
hw/misc/a9scu.c | 6 ++++++
12
hw/i2c/npcm7xx_smbus.c | 1 -
11
1 file changed, 6 insertions(+)
13
1 file changed, 1 deletion(-)
12
14
13
diff --git a/hw/misc/a9scu.c b/hw/misc/a9scu.c
15
diff --git a/hw/i2c/npcm7xx_smbus.c b/hw/i2c/npcm7xx_smbus.c
14
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/misc/a9scu.c
17
--- a/hw/i2c/npcm7xx_smbus.c
16
+++ b/hw/misc/a9scu.c
18
+++ b/hw/i2c/npcm7xx_smbus.c
17
@@ -XXX,XX +XXX,XX @@
19
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_init(Object *obj)
18
#include "hw/qdev-properties.h"
20
sysbus_init_mmio(sbd, &s->iomem);
19
#include "migration/vmstate.h"
21
20
#include "qapi/error.h"
22
s->bus = i2c_init_bus(DEVICE(s), "i2c-bus");
21
+#include "qemu/log.h"
23
- s->status = NPCM7XX_SMBUS_STATUS_IDLE;
22
#include "qemu/module.h"
23
24
#define A9_SCU_CPU_MAX 4
25
@@ -XXX,XX +XXX,XX @@ static uint64_t a9_scu_read(void *opaque, hwaddr offset,
26
case 0x54: /* SCU Non-secure Access Control Register */
27
/* unimplemented, fall through */
28
default:
29
+ qemu_log_mask(LOG_UNIMP, "%s: Unsupported offset 0x%"HWADDR_PRIx"\n",
30
+ __func__, offset);
31
return 0;
32
}
33
}
24
}
34
@@ -XXX,XX +XXX,XX @@ static void a9_scu_write(void *opaque, hwaddr offset,
25
35
case 0x54: /* SCU Non-secure Access Control Register */
26
static const VMStateDescription vmstate_npcm7xx_smbus = {
36
/* unimplemented, fall through */
37
default:
38
+ qemu_log_mask(LOG_UNIMP, "%s: Unsupported offset 0x%"HWADDR_PRIx
39
+ " value 0x%"PRIx64"\n",
40
+ __func__, offset, value);
41
break;
42
}
43
}
44
--
27
--
45
2.20.1
28
2.20.1
46
29
47
30
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: schspa <schspa@gmail.com>
2
2
3
This is a minimalistic boot ROM written specifically for use with QEMU.
3
At the moment the following QEMU command line triggers an assertion
4
It supports loading the second-stage loader from SPI flash into RAM, SMP
4
failure On xlnx-versal SOC:
5
boot, and not much else.
5
qemu-system-aarch64 \
6
-machine xlnx-versal-virt -nographic -smp 2 -m 128 \
7
-fsdev local,id=shareid,path=${HOME}/work,security_model=none \
8
-device virtio-9p-device,fsdev=shareid,mount_tag=share \
9
-fsdev local,id=shareid1,path=${HOME}/Music,security_model=none \
10
-device virtio-9p-device,fsdev=shareid1,mount_tag=share1
6
11
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
12
qemu-system-aarch64: ../migration/savevm.c:860:
8
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
13
vmstate_register_with_alias_id:
9
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
14
Assertion `!se->compat || se->instance_id == 0' failed.
10
Message-id: 20200911052101.2602693-7-hskinnemoen@google.com
15
16
This problem was fixed on arm virt platform in commit f58b39d2d5b
17
("virtio-mmio: format transport base address in BusClass.get_dev_path")
18
19
It works perfectly on arm virt platform. but there is still there on
20
xlnx-versal SOC.
21
22
The main difference between arm virt and xlnx-versal is they use
23
different way to create virtio-mmio qdev. on arm virt, it calls
24
sysbus_create_simple("virtio-mmio", base, pic[irq]); which will call
25
sysbus_mmio_map internally and assign base address to subsys device
26
mmio correctly. but xlnx-versal's implements won't do this.
27
28
However, xlnx-versal can't switch to sysbus_create_simple() to create
29
virtio-mmio device. It's because xlnx-versal's cpu use
30
VersalVirt.soc.fpd.apu.mr as it's memory. which is subregion of
31
system_memory. sysbus_create_simple will add virtio to system_memory,
32
which can't be accessed by cpu.
33
34
Besides, xlnx-versal can't add sysbus_mmio_map api call too, because
35
this will add memory region to system_memory, and it can't be added
36
to VersalVirt.soc.fpd.apu.mr again.
37
38
We can solve this by assign correct base address offset on dev_path.
39
40
This path was test on aarch64 virt & xlnx-versal platform.
41
42
Signed-off-by: schspa <schspa@gmail.com>
43
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
44
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
45
---
13
.gitmodules | 3 +++
46
hw/virtio/virtio-mmio.c | 13 +++++++------
14
MAINTAINERS | 2 ++
47
1 file changed, 7 insertions(+), 6 deletions(-)
15
pc-bios/README | 6 ++++++
16
pc-bios/meson.build | 1 +
17
pc-bios/npcm7xx_bootrom.bin | Bin 0 -> 768 bytes
18
roms/Makefile | 7 +++++++
19
roms/vbootrom | 1 +
20
7 files changed, 20 insertions(+)
21
create mode 100644 pc-bios/npcm7xx_bootrom.bin
22
create mode 160000 roms/vbootrom
23
48
24
diff --git a/.gitmodules b/.gitmodules
49
diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c
25
index XXXXXXX..XXXXXXX 100644
50
index XXXXXXX..XXXXXXX 100644
26
--- a/.gitmodules
51
--- a/hw/virtio/virtio-mmio.c
27
+++ b/.gitmodules
52
+++ b/hw/virtio/virtio-mmio.c
28
@@ -XXX,XX +XXX,XX @@
53
@@ -XXX,XX +XXX,XX @@ static char *virtio_mmio_bus_get_dev_path(DeviceState *dev)
29
[submodule "meson"]
54
BusState *virtio_mmio_bus;
30
    path = meson
55
VirtIOMMIOProxy *virtio_mmio_proxy;
31
    url = https://github.com/mesonbuild/meson/
56
char *proxy_path;
32
+[submodule "roms/vbootrom"]
57
- SysBusDevice *proxy_sbd;
33
+    path = roms/vbootrom
58
char *path;
34
+    url = https://github.com/google/vbootrom.git
59
+ MemoryRegionSection section;
35
diff --git a/MAINTAINERS b/MAINTAINERS
60
36
index XXXXXXX..XXXXXXX 100644
61
virtio_mmio_bus = qdev_get_parent_bus(dev);
37
--- a/MAINTAINERS
62
virtio_mmio_proxy = VIRTIO_MMIO(virtio_mmio_bus->parent);
38
+++ b/MAINTAINERS
63
@@ -XXX,XX +XXX,XX @@ static char *virtio_mmio_bus_get_dev_path(DeviceState *dev)
39
@@ -XXX,XX +XXX,XX @@ L: qemu-arm@nongnu.org
64
}
40
S: Supported
65
41
F: hw/*/npcm7xx*
66
/* Otherwise, we append the base address of the transport. */
42
F: include/hw/*/npcm7xx*
67
- proxy_sbd = SYS_BUS_DEVICE(virtio_mmio_proxy);
43
+F: pc-bios/npcm7xx_bootrom.bin
68
- assert(proxy_sbd->num_mmio == 1);
44
+F: roms/vbootrom
69
- assert(proxy_sbd->mmio[0].memory == &virtio_mmio_proxy->iomem);
45
70
+ section = memory_region_find(&virtio_mmio_proxy->iomem, 0, 0x200);
46
nSeries
71
+ assert(section.mr);
47
M: Andrzej Zaborowski <balrogg@gmail.com>
72
48
diff --git a/pc-bios/README b/pc-bios/README
73
if (proxy_path) {
49
index XXXXXXX..XXXXXXX 100644
74
path = g_strdup_printf("%s/virtio-mmio@" TARGET_FMT_plx, proxy_path,
50
--- a/pc-bios/README
75
- proxy_sbd->mmio[0].addr);
51
+++ b/pc-bios/README
76
+ section.offset_within_address_space);
52
@@ -XXX,XX +XXX,XX @@
77
} else {
53
("Simplified BSD License" or "FreeBSD License", SPDX: BSD-2-Clause). OpenSBI
78
path = g_strdup_printf("virtio-mmio@" TARGET_FMT_plx,
54
source code also contains code reused from other projects desribed here:
79
- proxy_sbd->mmio[0].addr);
55
https://github.com/riscv/opensbi/blob/master/ThirdPartyNotices.md.
80
+ section.offset_within_address_space);
81
}
82
+ memory_region_unref(section.mr);
56
+
83
+
57
+- npcm7xx_bootrom.bin is a simplified, free (Apache 2.0) boot ROM for Nuvoton
84
g_free(proxy_path);
58
+ NPCM7xx BMC devices. It currently implements the bare minimum to load, parse,
85
return path;
59
+ initialize and run boot images stored in SPI flash, but may grow more
86
}
60
+ features over time as needed. The source code is available at:
61
+ https://github.com/google/vbootrom
62
diff --git a/pc-bios/meson.build b/pc-bios/meson.build
63
index XXXXXXX..XXXXXXX 100644
64
--- a/pc-bios/meson.build
65
+++ b/pc-bios/meson.build
66
@@ -XXX,XX +XXX,XX @@ blobs = files(
67
'opensbi-riscv64-generic-fw_dynamic.bin',
68
'opensbi-riscv32-generic-fw_dynamic.elf',
69
'opensbi-riscv64-generic-fw_dynamic.elf',
70
+ 'npcm7xx_bootrom.bin',
71
)
72
73
if install_blobs
74
diff --git a/pc-bios/npcm7xx_bootrom.bin b/pc-bios/npcm7xx_bootrom.bin
75
new file mode 100644
76
index XXXXXXX..XXXXXXX
77
GIT binary patch
78
literal 768
79
zcmd5)JxClu6n-<aczPbVhZYusb8wKx;7TklHfmuZdYT9pDRLwd1p_t-DFpWpyA+8(
80
zwKtZg3J4a0aCM3_X(ZL&4g;46VVk5e$K;z;L99|b@aE%v^S$rQ8)h(Vm@cB9IYc+2
81
z2SHd4^NwTIGE%w>9S05p1#kf90Sj5Z(jG8}+)IZIp~iXK=T&)dL`%d-q*8aR#mq{7
82
z9`=6;Dr(H0ACe72R5x?!)^86Qj-X%{+!K9iZNA@*wkBAV&iZ(l^I9?!Gz=S2I_*1d
83
zr+tTQDHjvyzKnw(hu00yX`u!Fv<!~XVcX?@kr#<B0(gGU?$W{gSsQa}CF^8Cfzp2X
84
z@P}yDV-bci(K9XL$FU!som2C`c)?Uc&294s^}Wzumap{hg1X^jN|V25M5tQZ=<9lN
85
z%(zKz#t-qCwHKb;HygOCpvCNL_4@1tXV1YGf^XUE_$zr{g8zWh-6gz-teI(eibtxo
86
z?0OZI4%rU0741PgUD`2xq@H|*4=+Rs?%N)Ox5G+q>C;DilBe_YlkeSUVHA-crNk+k
87
jtiF_MudA<CB(}8|fqYwCf3re&=&@_s761P#-ID$TwgmBa
88
89
literal 0
90
HcmV?d00001
91
92
diff --git a/roms/Makefile b/roms/Makefile
93
index XXXXXXX..XXXXXXX 100644
94
--- a/roms/Makefile
95
+++ b/roms/Makefile
96
@@ -XXX,XX +XXX,XX @@ find-cross-gcc = $(firstword $(wildcard $(patsubst %ld,%gcc,$(call find-cross-ld
97
# finally strip off path + toolname so we get the prefix
98
find-cross-prefix = $(subst gcc,,$(notdir $(call find-cross-gcc,$(1))))
99
100
+arm_cross_prefix := $(call find-cross-prefix,arm)
101
powerpc64_cross_prefix := $(call find-cross-prefix,powerpc64)
102
powerpc_cross_prefix := $(call find-cross-prefix,powerpc)
103
x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
104
@@ -XXX,XX +XXX,XX @@ default help:
105
    @echo " skiboot -- update skiboot.lid"
106
    @echo " u-boot.e500 -- update u-boot.e500"
107
    @echo " u-boot.sam460 -- update u-boot.sam460"
108
+    @echo " npcm7xx_bootrom -- update vbootrom for npcm7xx"
109
    @echo " efi -- update UEFI (edk2) platform firmware"
110
    @echo " opensbi32-generic -- update OpenSBI for 32-bit generic machine"
111
    @echo " opensbi64-generic -- update OpenSBI for 64-bit generic machine"
112
@@ -XXX,XX +XXX,XX @@ bios-microvm:
113
    $(MAKE) -C qboot
114
    cp qboot/bios.bin ../pc-bios/bios-microvm.bin
115
116
+npcm7xx_bootrom:
117
+    $(MAKE) -C vbootrom CROSS_COMPILE=$(arm_cross_prefix)
118
+    cp vbootrom/npcm7xx_bootrom.bin ../pc-bios/npcm7xx_bootrom.bin
119
+
120
clean:
121
    rm -rf seabios/.config seabios/out seabios/builds
122
    $(MAKE) -C sgabios clean
123
@@ -XXX,XX +XXX,XX @@ clean:
124
    $(MAKE) -f Makefile.edk2 clean
125
    $(MAKE) -C opensbi clean
126
    $(MAKE) -C qboot clean
127
+    $(MAKE) -C vbootrom clean
128
diff --git a/roms/vbootrom b/roms/vbootrom
129
new file mode 160000
130
index XXXXXXX..XXXXXXX
131
--- /dev/null
132
+++ b/roms/vbootrom
133
@@ -0,0 +1 @@
134
+Subproject commit 0c37a43527f0ee2b9584e7fb2fdc805e902635ac
135
--
87
--
136
2.20.1
88
2.20.1
137
89
138
90
diff view generated by jsdifflib
1
From: Aaron Lindsay <aaron@os.amperecomputing.com>
1
From: Peter Collingbourne <pcc@google.com>
2
2
3
This check was backwards when introduced in commit
3
Section D6.7 of the ARM ARM states:
4
033614c47de78409ad3fb39bb7bd1483b71c6789:
5
4
6
target/arm: Filter cycle counter based on PMCCFILTR_EL0
5
For the purpose of determining Tag Check Fault handling, unprivileged
6
load and store instructions are treated as if executed at EL0 when
7
executed at either:
8
- EL1, when the Effective value of PSTATE.UAO is 0.
9
- EL2, when both the Effective value of HCR_EL2.{E2H, TGE} is {1, 1}
10
and the Effective value of PSTATE.UAO is 0.
7
11
8
Cc: qemu-stable@nongnu.org
12
ARM has confirmed a defect in the pseudocode function
9
Signed-off-by: Aaron Lindsay <aaron@os.amperecomputing.com>
13
AArch64.TagCheckFault that makes it inconsistent with the above
14
wording. The remedy is to adjust references to PSTATE.EL in that
15
function to instead refer to AArch64.AccessUsesEL(acctype), so
16
that unprivileged instructions use SCTLR_EL1.TCF0 and TFSRE0_EL1.
17
The exception type for synchronous tag check faults remains unchanged.
18
19
This patch implements the described change by partially reverting
20
commits 50244cc76abc and cc97b0019bb5.
21
22
Signed-off-by: Peter Collingbourne <pcc@google.com>
23
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
24
Message-id: 20210219201820.2672077-1-pcc@google.com
10
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
25
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
26
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
27
---
13
target/arm/helper.c | 2 +-
28
target/arm/helper.c | 2 +-
14
1 file changed, 1 insertion(+), 1 deletion(-)
29
target/arm/mte_helper.c | 13 +++++++++----
30
2 files changed, 10 insertions(+), 5 deletions(-)
15
31
16
diff --git a/target/arm/helper.c b/target/arm/helper.c
32
diff --git a/target/arm/helper.c b/target/arm/helper.c
17
index XXXXXXX..XXXXXXX 100644
33
index XXXXXXX..XXXXXXX 100644
18
--- a/target/arm/helper.c
34
--- a/target/arm/helper.c
19
+++ b/target/arm/helper.c
35
+++ b/target/arm/helper.c
20
@@ -XXX,XX +XXX,XX @@ static bool pmu_counter_enabled(CPUARMState *env, uint8_t counter)
36
@@ -XXX,XX +XXX,XX @@ static uint32_t rebuild_hflags_a64(CPUARMState *env, int el, int fp_el,
37
if (FIELD_EX32(flags, TBFLAG_A64, UNPRIV)
38
&& tbid
39
&& !(env->pstate & PSTATE_TCO)
40
- && (sctlr & SCTLR_TCF)
41
+ && (sctlr & SCTLR_TCF0)
42
&& allocation_tag_access_enabled(env, 0, sctlr)) {
43
flags = FIELD_DP32(flags, TBFLAG_A64, MTE0_ACTIVE, 1);
21
}
44
}
22
} else {
45
diff --git a/target/arm/mte_helper.c b/target/arm/mte_helper.c
23
prohibited = arm_feature(env, ARM_FEATURE_EL3) &&
46
index XXXXXXX..XXXXXXX 100644
24
- (env->cp15.mdcr_el3 & MDCR_SPME);
47
--- a/target/arm/mte_helper.c
25
+ !(env->cp15.mdcr_el3 & MDCR_SPME);
48
+++ b/target/arm/mte_helper.c
49
@@ -XXX,XX +XXX,XX @@ static void mte_check_fail(CPUARMState *env, uint32_t desc,
50
reg_el = regime_el(env, arm_mmu_idx);
51
sctlr = env->cp15.sctlr_el[reg_el];
52
53
- el = arm_current_el(env);
54
- if (el == 0) {
55
+ switch (arm_mmu_idx) {
56
+ case ARMMMUIdx_E10_0:
57
+ case ARMMMUIdx_E20_0:
58
+ el = 0;
59
tcf = extract64(sctlr, 38, 2);
60
- } else {
61
+ break;
62
+ default:
63
+ el = reg_el;
64
tcf = extract64(sctlr, 40, 2);
26
}
65
}
27
66
28
if (prohibited && counter == 31) {
67
@@ -XXX,XX +XXX,XX @@ static void mte_check_fail(CPUARMState *env, uint32_t desc,
68
env->exception.vaddress = dirty_ptr;
69
70
is_write = FIELD_EX32(desc, MTEDESC, WRITE);
71
- syn = syn_data_abort_no_iss(el != 0, 0, 0, 0, 0, is_write, 0x11);
72
+ syn = syn_data_abort_no_iss(arm_current_el(env) != 0, 0, 0, 0, 0,
73
+ is_write, 0x11);
74
raise_exception(env, EXCP_DATA_ABORT, syn, exception_target_el(env));
75
/* noreturn, but fall through to the assert anyway */
76
29
--
77
--
30
2.20.1
78
2.20.1
31
79
32
80
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
Per the datasheet (DDI0407 r2p0):
3
IDAU is specific to M-profile. KVM only supports A-profile.
4
Restrict this interface to TCG, as it is pointless (and
5
confusing) on a KVM-only build.
4
6
5
"All SCU registers are byte accessible" and are 32-bit aligned.
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
7
Set MemoryRegionOps::valid min/max fields and simplify the write()
8
handler.
9
10
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
Message-id: 20210221222617.2579610-2-f4bug@amsat.org
12
Message-id: 20200901144100.116742-3-f4bug@amsat.org
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
---
12
---
15
hw/misc/a9scu.c | 21 +++++----------------
13
target/arm/cpu.c | 7 -------
16
1 file changed, 5 insertions(+), 16 deletions(-)
14
target/arm/cpu_tcg.c | 8 ++++++++
15
2 files changed, 8 insertions(+), 7 deletions(-)
17
16
18
diff --git a/hw/misc/a9scu.c b/hw/misc/a9scu.c
17
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
19
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
20
--- a/hw/misc/a9scu.c
19
--- a/target/arm/cpu.c
21
+++ b/hw/misc/a9scu.c
20
+++ b/target/arm/cpu.c
22
@@ -XXX,XX +XXX,XX @@ static void a9_scu_write(void *opaque, hwaddr offset,
21
@@ -XXX,XX +XXX,XX @@ static const TypeInfo arm_cpu_type_info = {
23
uint64_t value, unsigned size)
22
.class_init = arm_cpu_class_init,
23
};
24
25
-static const TypeInfo idau_interface_type_info = {
26
- .name = TYPE_IDAU_INTERFACE,
27
- .parent = TYPE_INTERFACE,
28
- .class_size = sizeof(IDAUInterfaceClass),
29
-};
30
-
31
static void arm_cpu_register_types(void)
24
{
32
{
25
A9SCUState *s = (A9SCUState *)opaque;
33
const size_t cpu_count = ARRAY_SIZE(arm_cpus);
26
- uint32_t mask;
34
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_register_types(void)
27
+ uint32_t mask = MAKE_64BIT_MASK(0, size * 8);
35
if (cpu_count) {
28
uint32_t shift;
36
size_t i;
29
- switch (size) {
37
30
- case 1:
38
- type_register_static(&idau_interface_type_info);
31
- mask = 0xff;
39
for (i = 0; i < cpu_count; ++i) {
32
- break;
40
arm_cpu_register(&arm_cpus[i]);
33
- case 2:
41
}
34
- mask = 0xffff;
42
diff --git a/target/arm/cpu_tcg.c b/target/arm/cpu_tcg.c
35
- break;
43
index XXXXXXX..XXXXXXX 100644
36
- case 4:
44
--- a/target/arm/cpu_tcg.c
37
- mask = 0xffffffff;
45
+++ b/target/arm/cpu_tcg.c
38
- break;
46
@@ -XXX,XX +XXX,XX @@
39
- default:
47
#include "hw/core/tcg-cpu-ops.h"
40
- fprintf(stderr, "Invalid size %u in write to a9 scu register %x\n",
48
#endif /* CONFIG_TCG */
41
- size, (unsigned)offset);
49
#include "internals.h"
42
- return;
50
+#include "target/arm/idau.h"
43
- }
51
44
52
/* CPU models. These are not needed for the AArch64 linux-user build. */
45
switch (offset) {
53
#if !defined(CONFIG_USER_ONLY) || !defined(TARGET_AARCH64)
46
case 0x00: /* Control */
54
@@ -XXX,XX +XXX,XX @@ static const ARMCPUInfo arm_tcg_cpus[] = {
47
@@ -XXX,XX +XXX,XX @@ static void a9_scu_write(void *opaque, hwaddr offset,
55
{ .name = "pxa270-c5", .initfn = pxa270c5_initfn },
48
static const MemoryRegionOps a9_scu_ops = {
49
.read = a9_scu_read,
50
.write = a9_scu_write,
51
+ .valid = {
52
+ .min_access_size = 1,
53
+ .max_access_size = 4,
54
+ },
55
.endianness = DEVICE_NATIVE_ENDIAN,
56
};
56
};
57
57
58
+static const TypeInfo idau_interface_type_info = {
59
+ .name = TYPE_IDAU_INTERFACE,
60
+ .parent = TYPE_INTERFACE,
61
+ .class_size = sizeof(IDAUInterfaceClass),
62
+};
63
+
64
static void arm_tcg_cpu_register_types(void)
65
{
66
size_t i;
67
68
+ type_register_static(&idau_interface_type_info);
69
for (i = 0; i < ARRAY_SIZE(arm_tcg_cpus); ++i) {
70
arm_cpu_register(&arm_tcg_cpus[i]);
71
}
58
--
72
--
59
2.20.1
73
2.20.1
60
74
61
75
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
This model implementation is designed for 32-bit accesses.
3
We will move this code in the next commit. Clean it up
4
We can simplify setting the MemoryRegionOps::impl min/max
4
first to avoid checkpatch.pl errors.
5
fields to 32-bit (memory::access_with_adjusted_size() will
6
take care of the 8/16-bit accesses).
7
5
8
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20210221222617.2579610-3-f4bug@amsat.org
10
Message-id: 20200901144100.116742-4-f4bug@amsat.org
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
10
---
13
hw/misc/a9scu.c | 16 +++++-----------
11
target/arm/cpu.c | 12 ++++++++----
14
1 file changed, 5 insertions(+), 11 deletions(-)
12
1 file changed, 8 insertions(+), 4 deletions(-)
15
13
16
diff --git a/hw/misc/a9scu.c b/hw/misc/a9scu.c
14
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
17
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/misc/a9scu.c
16
--- a/target/arm/cpu.c
19
+++ b/hw/misc/a9scu.c
17
+++ b/target/arm/cpu.c
20
@@ -XXX,XX +XXX,XX @@ static uint64_t a9_scu_read(void *opaque, hwaddr offset,
18
@@ -XXX,XX +XXX,XX @@ static void cortex_a8_initfn(Object *obj)
21
return (((1 << s->num_cpu) - 1) << 4) | (s->num_cpu - 1);
19
}
22
case 0x08: /* CPU Power Status */
20
23
return s->status;
21
static const ARMCPRegInfo cortexa9_cp_reginfo[] = {
24
- case 0x09: /* CPU status. */
22
- /* power_control should be set to maximum latency. Again,
25
- return s->status >> 8;
23
+ /*
26
- case 0x0a: /* CPU status. */
24
+ * power_control should be set to maximum latency. Again,
27
- return s->status >> 16;
25
* default to 0 and set by private hook
28
- case 0x0b: /* CPU status. */
26
*/
29
- return s->status >> 24;
27
{ .name = "A9_PWRCTL", .cp = 15, .crn = 15, .crm = 0, .opc1 = 0, .opc2 = 0,
30
case 0x0c: /* Invalidate All Registers In Secure State */
28
@@ -XXX,XX +XXX,XX @@ static void cortex_a9_initfn(Object *obj)
31
return 0;
29
set_feature(&cpu->env, ARM_FEATURE_NEON);
32
case 0x40: /* Filtering Start Address Register */
30
set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
33
@@ -XXX,XX +XXX,XX @@ static void a9_scu_write(void *opaque, hwaddr offset,
31
set_feature(&cpu->env, ARM_FEATURE_EL3);
34
uint64_t value, unsigned size)
32
- /* Note that A9 supports the MP extensions even for
33
+ /*
34
+ * Note that A9 supports the MP extensions even for
35
* A9UP and single-core A9MP (which are both different
36
* and valid configurations; we don't model A9UP).
37
*/
38
@@ -XXX,XX +XXX,XX @@ static uint64_t a15_l2ctlr_read(CPUARMState *env, const ARMCPRegInfo *ri)
35
{
39
{
36
A9SCUState *s = (A9SCUState *)opaque;
40
MachineState *ms = MACHINE(qdev_get_machine());
37
- uint32_t mask = MAKE_64BIT_MASK(0, size * 8);
41
38
- uint32_t shift;
42
- /* Linux wants the number of processors from here.
39
43
+ /*
40
switch (offset) {
44
+ * Linux wants the number of processors from here.
41
case 0x00: /* Control */
45
* Might as well set the interrupt-controller bit too.
42
@@ -XXX,XX +XXX,XX @@ static void a9_scu_write(void *opaque, hwaddr offset,
46
*/
43
case 0x4: /* Configuration: RO */
47
return ((ms->smp.cpus - 1) << 24) | (1 << 23);
44
break;
48
@@ -XXX,XX +XXX,XX @@ static void cortex_a7_initfn(Object *obj)
45
case 0x08: case 0x09: case 0x0A: case 0x0B: /* Power Control */
49
cpu->isar.id_mmfr1 = 0x40000000;
46
- shift = (offset - 0x8) * 8;
50
cpu->isar.id_mmfr2 = 0x01240000;
47
- s->status &= ~(mask << shift);
51
cpu->isar.id_mmfr3 = 0x02102211;
48
- s->status |= ((value & mask) << shift);
52
- /* a7_mpcore_r0p5_trm, page 4-4 gives 0x01101110; but
49
+ s->status = value;
53
+ /*
50
break;
54
+ * a7_mpcore_r0p5_trm, page 4-4 gives 0x01101110; but
51
case 0x0c: /* Invalidate All Registers In Secure State */
55
* table 4-41 gives 0x02101110, which includes the arm div insns.
52
/* no-op as we do not implement caches */
56
*/
53
@@ -XXX,XX +XXX,XX @@ static void a9_scu_write(void *opaque, hwaddr offset,
57
cpu->isar.id_isar0 = 0x02101110;
54
static const MemoryRegionOps a9_scu_ops = {
55
.read = a9_scu_read,
56
.write = a9_scu_write,
57
+ .impl = {
58
+ .min_access_size = 4,
59
+ .max_access_size = 4,
60
+ },
61
.valid = {
62
.min_access_size = 1,
63
.max_access_size = 4,
64
--
58
--
65
2.20.1
59
2.20.1
66
60
67
61
diff view generated by jsdifflib
1
The VCMLA and VCADD insns have a size field which is 0 for fp16
1
For a long time now the UI layer has guaranteed that the console
2
and 1 for fp32 (note that this is the reverse of the Neon 3-same
2
surface is always 32 bits per pixel RGB. Remove the legacy dead
3
encoding!). Convert it to MO_* values in decode for consistency.
3
code from the milkymist display device which was handling the
4
possibility that the console surface was some other format.
4
5
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20200903133209.5141-4-peter.maydell@linaro.org
8
Message-id: 20210215103215.4944-2-peter.maydell@linaro.org
8
---
9
---
9
target/arm/neon-shared.decode | 18 ++++++++++++------
10
hw/arm/musicpal.c | 64 ++++++++++++++++++-----------------------------
10
target/arm/translate-neon.c.inc | 22 ++++++++++++----------
11
1 file changed, 24 insertions(+), 40 deletions(-)
11
2 files changed, 24 insertions(+), 16 deletions(-)
12
12
13
diff --git a/target/arm/neon-shared.decode b/target/arm/neon-shared.decode
13
diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c
14
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
15
--- a/target/arm/neon-shared.decode
15
--- a/hw/arm/musicpal.c
16
+++ b/target/arm/neon-shared.decode
16
+++ b/hw/arm/musicpal.c
17
@@ -XXX,XX +XXX,XX @@
17
@@ -XXX,XX +XXX,XX @@ static uint8_t scale_lcd_color(musicpal_lcd_state *s, uint8_t col)
18
%vd_dp 22:1 12:4
18
}
19
%vd_sp 12:4 22:1
19
}
20
20
21
-VCMLA 1111 110 rot:2 . 1 size:1 .... .... 1000 . q:1 . 0 .... \
21
-#define SET_LCD_PIXEL(depth, type) \
22
- vm=%vm_dp vn=%vn_dp vd=%vd_dp
22
-static inline void glue(set_lcd_pixel, depth) \
23
+# For VCMLA/VCADD insns, convert the single-bit size field
23
- (musicpal_lcd_state *s, int x, int y, type col) \
24
+# which is 0 for fp16 and 1 for fp32 into a MO_* constant.
24
-{ \
25
+# (Note that this is the reverse of the sense of the 1-bit size
25
- int dx, dy; \
26
+# field in the 3same_fp Neon insns.)
26
- DisplaySurface *surface = qemu_console_surface(s->con); \
27
+%vcadd_size 20:1 !function=plus1
27
- type *pixel = &((type *) surface_data(surface))[(y * 128 * 3 + x) * 3]; \
28
28
-\
29
-VCADD 1111 110 rot:1 1 . 0 size:1 .... .... 1000 . q:1 . 0 .... \
29
- for (dy = 0; dy < 3; dy++, pixel += 127 * 3) \
30
- vm=%vm_dp vn=%vn_dp vd=%vd_dp
30
- for (dx = 0; dx < 3; dx++, pixel++) \
31
+VCMLA 1111 110 rot:2 . 1 . .... .... 1000 . q:1 . 0 .... \
31
- *pixel = col; \
32
+ vm=%vm_dp vn=%vn_dp vd=%vd_dp size=%vcadd_size
32
+static inline void set_lcd_pixel32(musicpal_lcd_state *s,
33
+ int x, int y, uint32_t col)
34
+{
35
+ int dx, dy;
36
+ DisplaySurface *surface = qemu_console_surface(s->con);
37
+ uint32_t *pixel =
38
+ &((uint32_t *) surface_data(surface))[(y * 128 * 3 + x) * 3];
33
+
39
+
34
+VCADD 1111 110 rot:1 1 . 0 . .... .... 1000 . q:1 . 0 .... \
40
+ for (dy = 0; dy < 3; dy++, pixel += 127 * 3) {
35
+ vm=%vm_dp vn=%vn_dp vd=%vd_dp size=%vcadd_size
41
+ for (dx = 0; dx < 3; dx++, pixel++) {
36
42
+ *pixel = col;
37
# VUDOT and VSDOT
43
+ }
38
VDOT 1111 110 00 . 10 .... .... 1101 . q:1 . u:1 .... \
44
+ }
39
@@ -XXX,XX +XXX,XX @@ VFML 1111 110 0 s:1 . 10 .... .... 1000 . 1 . 1 .... \
45
}
40
vm=%vm_dp vn=%vn_dp vd=%vd_dp q=1
46
-SET_LCD_PIXEL(8, uint8_t)
41
47
-SET_LCD_PIXEL(16, uint16_t)
42
VCMLA_scalar 1111 1110 0 . rot:2 .... .... 1000 . q:1 index:1 0 vm:4 \
48
-SET_LCD_PIXEL(32, uint32_t)
43
- vn=%vn_dp vd=%vd_dp size=0
49
44
+ vn=%vn_dp vd=%vd_dp size=1
50
static void lcd_refresh(void *opaque)
45
VCMLA_scalar 1111 1110 1 . rot:2 .... .... 1000 . q:1 . 0 .... \
51
{
46
- vm=%vm_dp vn=%vn_dp vd=%vd_dp size=1 index=0
52
musicpal_lcd_state *s = opaque;
47
+ vm=%vm_dp vn=%vn_dp vd=%vd_dp size=2 index=0
53
- DisplaySurface *surface = qemu_console_surface(s->con);
48
54
int x, y, col;
49
VDOT_scalar 1111 1110 0 . 10 .... .... 1101 . q:1 index:1 u:1 rm:4 \
55
50
vm=%vm_dp vn=%vn_dp vd=%vd_dp
56
- switch (surface_bits_per_pixel(surface)) {
51
diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc
57
- case 0:
52
index XXXXXXX..XXXXXXX 100644
58
- return;
53
--- a/target/arm/translate-neon.c.inc
59
-#define LCD_REFRESH(depth, func) \
54
+++ b/target/arm/translate-neon.c.inc
60
- case depth: \
55
@@ -XXX,XX +XXX,XX @@ static bool trans_VCMLA(DisasContext *s, arg_VCMLA *a)
61
- col = func(scale_lcd_color(s, (MP_LCD_TEXTCOLOR >> 16) & 0xff), \
56
gen_helper_gvec_3_ptr *fn_gvec_ptr;
62
- scale_lcd_color(s, (MP_LCD_TEXTCOLOR >> 8) & 0xff), \
57
63
- scale_lcd_color(s, MP_LCD_TEXTCOLOR & 0xff)); \
58
if (!dc_isar_feature(aa32_vcma, s)
64
- for (x = 0; x < 128; x++) { \
59
- || (!a->size && !dc_isar_feature(aa32_fp16_arith, s))) {
65
- for (y = 0; y < 64; y++) { \
60
+ || (a->size == MO_16 && !dc_isar_feature(aa32_fp16_arith, s))) {
66
- if (s->video_ram[x + (y/8)*128] & (1 << (y % 8))) { \
61
return false;
67
- glue(set_lcd_pixel, depth)(s, x, y, col); \
68
- } else { \
69
- glue(set_lcd_pixel, depth)(s, x, y, 0); \
70
- } \
71
- } \
72
- } \
73
- break;
74
- LCD_REFRESH(8, rgb_to_pixel8)
75
- LCD_REFRESH(16, rgb_to_pixel16)
76
- LCD_REFRESH(32, (is_surface_bgr(surface) ?
77
- rgb_to_pixel32bgr : rgb_to_pixel32))
78
- default:
79
- hw_error("unsupported colour depth %i\n",
80
- surface_bits_per_pixel(surface));
81
+ col = rgb_to_pixel32(scale_lcd_color(s, (MP_LCD_TEXTCOLOR >> 16) & 0xff),
82
+ scale_lcd_color(s, (MP_LCD_TEXTCOLOR >> 8) & 0xff),
83
+ scale_lcd_color(s, MP_LCD_TEXTCOLOR & 0xff));
84
+ for (x = 0; x < 128; x++) {
85
+ for (y = 0; y < 64; y++) {
86
+ if (s->video_ram[x + (y / 8) * 128] & (1 << (y % 8))) {
87
+ set_lcd_pixel32(s, x, y, col);
88
+ } else {
89
+ set_lcd_pixel32(s, x, y, 0);
90
+ }
91
+ }
62
}
92
}
63
93
64
@@ -XXX,XX +XXX,XX @@ static bool trans_VCMLA(DisasContext *s, arg_VCMLA *a)
94
dpy_gfx_update(s->con, 0, 0, 128*3, 64*3);
65
}
66
67
opr_sz = (1 + a->q) * 8;
68
- fpst = fpstatus_ptr(a->size == 0 ? FPST_STD_F16 : FPST_STD);
69
- fn_gvec_ptr = a->size ? gen_helper_gvec_fcmlas : gen_helper_gvec_fcmlah;
70
+ fpst = fpstatus_ptr(a->size == MO_16 ? FPST_STD_F16 : FPST_STD);
71
+ fn_gvec_ptr = (a->size == MO_16) ?
72
+ gen_helper_gvec_fcmlah : gen_helper_gvec_fcmlas;
73
tcg_gen_gvec_3_ptr(vfp_reg_offset(1, a->vd),
74
vfp_reg_offset(1, a->vn),
75
vfp_reg_offset(1, a->vm),
76
@@ -XXX,XX +XXX,XX @@ static bool trans_VCADD(DisasContext *s, arg_VCADD *a)
77
gen_helper_gvec_3_ptr *fn_gvec_ptr;
78
79
if (!dc_isar_feature(aa32_vcma, s)
80
- || (!a->size && !dc_isar_feature(aa32_fp16_arith, s))) {
81
+ || (a->size == MO_16 && !dc_isar_feature(aa32_fp16_arith, s))) {
82
return false;
83
}
84
85
@@ -XXX,XX +XXX,XX @@ static bool trans_VCADD(DisasContext *s, arg_VCADD *a)
86
}
87
88
opr_sz = (1 + a->q) * 8;
89
- fpst = fpstatus_ptr(a->size == 0 ? FPST_STD_F16 : FPST_STD);
90
- fn_gvec_ptr = a->size ? gen_helper_gvec_fcadds : gen_helper_gvec_fcaddh;
91
+ fpst = fpstatus_ptr(a->size == MO_16 ? FPST_STD_F16 : FPST_STD);
92
+ fn_gvec_ptr = (a->size == MO_16) ?
93
+ gen_helper_gvec_fcaddh : gen_helper_gvec_fcadds;
94
tcg_gen_gvec_3_ptr(vfp_reg_offset(1, a->vd),
95
vfp_reg_offset(1, a->vn),
96
vfp_reg_offset(1, a->vm),
97
@@ -XXX,XX +XXX,XX @@ static bool trans_VCMLA_scalar(DisasContext *s, arg_VCMLA_scalar *a)
98
if (!dc_isar_feature(aa32_vcma, s)) {
99
return false;
100
}
101
- if (a->size == 0 && !dc_isar_feature(aa32_fp16_arith, s)) {
102
+ if (a->size == MO_16 && !dc_isar_feature(aa32_fp16_arith, s)) {
103
return false;
104
}
105
106
@@ -XXX,XX +XXX,XX @@ static bool trans_VCMLA_scalar(DisasContext *s, arg_VCMLA_scalar *a)
107
return true;
108
}
109
110
- fn_gvec_ptr = (a->size ? gen_helper_gvec_fcmlas_idx
111
- : gen_helper_gvec_fcmlah_idx);
112
+ fn_gvec_ptr = (a->size == MO_16) ?
113
+ gen_helper_gvec_fcmlah_idx : gen_helper_gvec_fcmlas_idx;
114
opr_sz = (1 + a->q) * 8;
115
- fpst = fpstatus_ptr(a->size == 0 ? FPST_STD_F16 : FPST_STD);
116
+ fpst = fpstatus_ptr(a->size == MO_16 ? FPST_STD_F16 : FPST_STD);
117
tcg_gen_gvec_3_ptr(vfp_reg_offset(1, a->vd),
118
vfp_reg_offset(1, a->vn),
119
vfp_reg_offset(1, a->vm),
120
--
95
--
121
2.20.1
96
2.20.1
122
97
123
98
diff view generated by jsdifflib
New patch
1
For a long time now the UI layer has guaranteed that the console
2
surface is always 32 bits per pixel RGB. Remove the legacy dead
3
code from the tc6393xb display device which was handling the
4
possibility that the console surface was some other format.
1
5
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20210215103215.4944-3-peter.maydell@linaro.org
9
---
10
include/ui/console.h | 10 ----------
11
hw/display/tc6393xb.c | 33 +--------------------------------
12
2 files changed, 1 insertion(+), 42 deletions(-)
13
14
diff --git a/include/ui/console.h b/include/ui/console.h
15
index XXXXXXX..XXXXXXX 100644
16
--- a/include/ui/console.h
17
+++ b/include/ui/console.h
18
@@ -XXX,XX +XXX,XX @@ PixelFormat qemu_default_pixelformat(int bpp);
19
DisplaySurface *qemu_create_displaysurface(int width, int height);
20
void qemu_free_displaysurface(DisplaySurface *surface);
21
22
-static inline int is_surface_bgr(DisplaySurface *surface)
23
-{
24
- if (PIXMAN_FORMAT_BPP(surface->format) == 32 &&
25
- PIXMAN_FORMAT_TYPE(surface->format) == PIXMAN_TYPE_ABGR) {
26
- return 1;
27
- } else {
28
- return 0;
29
- }
30
-}
31
-
32
static inline int is_buffer_shared(DisplaySurface *surface)
33
{
34
return !(surface->flags & QEMU_ALLOCATED_FLAG);
35
diff --git a/hw/display/tc6393xb.c b/hw/display/tc6393xb.c
36
index XXXXXXX..XXXXXXX 100644
37
--- a/hw/display/tc6393xb.c
38
+++ b/hw/display/tc6393xb.c
39
@@ -XXX,XX +XXX,XX @@ static void tc6393xb_nand_writeb(TC6393xbState *s, hwaddr addr, uint32_t value)
40
(uint32_t) addr, value & 0xff);
41
}
42
43
-#define BITS 8
44
-#include "tc6393xb_template.h"
45
-#define BITS 15
46
-#include "tc6393xb_template.h"
47
-#define BITS 16
48
-#include "tc6393xb_template.h"
49
-#define BITS 24
50
-#include "tc6393xb_template.h"
51
#define BITS 32
52
#include "tc6393xb_template.h"
53
54
static void tc6393xb_draw_graphic(TC6393xbState *s, int full_update)
55
{
56
- DisplaySurface *surface = qemu_console_surface(s->con);
57
-
58
- switch (surface_bits_per_pixel(surface)) {
59
- case 8:
60
- tc6393xb_draw_graphic8(s);
61
- break;
62
- case 15:
63
- tc6393xb_draw_graphic15(s);
64
- break;
65
- case 16:
66
- tc6393xb_draw_graphic16(s);
67
- break;
68
- case 24:
69
- tc6393xb_draw_graphic24(s);
70
- break;
71
- case 32:
72
- tc6393xb_draw_graphic32(s);
73
- break;
74
- default:
75
- printf("tc6393xb: unknown depth %d\n",
76
- surface_bits_per_pixel(surface));
77
- return;
78
- }
79
-
80
+ tc6393xb_draw_graphic32(s);
81
dpy_gfx_update_full(s->con);
82
}
83
84
--
85
2.20.1
86
87
diff view generated by jsdifflib
New patch
1
Now the template header is included only for BITS==32, expand
2
out all the macros that depended on the BITS setting.
1
3
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
Message-id: 20210215103215.4944-4-peter.maydell@linaro.org
7
---
8
hw/display/tc6393xb_template.h | 35 ++++------------------------------
9
1 file changed, 4 insertions(+), 31 deletions(-)
10
11
diff --git a/hw/display/tc6393xb_template.h b/hw/display/tc6393xb_template.h
12
index XXXXXXX..XXXXXXX 100644
13
--- a/hw/display/tc6393xb_template.h
14
+++ b/hw/display/tc6393xb_template.h
15
@@ -XXX,XX +XXX,XX @@
16
* with this program; if not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
-#if BITS == 8
20
-# define SET_PIXEL(addr, color) (*(uint8_t *)addr = color)
21
-#elif BITS == 15 || BITS == 16
22
-# define SET_PIXEL(addr, color) (*(uint16_t *)addr = color)
23
-#elif BITS == 24
24
-# define SET_PIXEL(addr, color) \
25
- do { \
26
- addr[0] = color; \
27
- addr[1] = (color) >> 8; \
28
- addr[2] = (color) >> 16; \
29
- } while (0)
30
-#elif BITS == 32
31
-# define SET_PIXEL(addr, color) (*(uint32_t *)addr = color)
32
-#else
33
-# error unknown bit depth
34
-#endif
35
-
36
-
37
-static void glue(tc6393xb_draw_graphic, BITS)(TC6393xbState *s)
38
+static void tc6393xb_draw_graphic32(TC6393xbState *s)
39
{
40
DisplaySurface *surface = qemu_console_surface(s->con);
41
int i;
42
@@ -XXX,XX +XXX,XX @@ static void glue(tc6393xb_draw_graphic, BITS)(TC6393xbState *s)
43
data_buffer = s->vram_ptr;
44
data_display = surface_data(surface);
45
for(i = 0; i < s->scr_height; i++) {
46
-#if (BITS == 16)
47
- memcpy(data_display, data_buffer, s->scr_width * 2);
48
- data_buffer += s->scr_width;
49
- data_display += surface_stride(surface);
50
-#else
51
int j;
52
- for (j = 0; j < s->scr_width; j++, data_display += BITS / 8, data_buffer++) {
53
+ for (j = 0; j < s->scr_width; j++, data_display += 4, data_buffer++) {
54
uint16_t color = *data_buffer;
55
- uint32_t dest_color = glue(rgb_to_pixel, BITS)(
56
+ uint32_t dest_color = rgb_to_pixel32(
57
((color & 0xf800) * 0x108) >> 11,
58
((color & 0x7e0) * 0x41) >> 9,
59
((color & 0x1f) * 0x21) >> 2
60
);
61
- SET_PIXEL(data_display, dest_color);
62
+ *(uint32_t *)data_display = dest_color;
63
}
64
-#endif
65
}
66
}
67
-
68
-#undef BITS
69
-#undef SET_PIXEL
70
--
71
2.20.1
72
73
diff view generated by jsdifflib
1
We deprecated the support for KVM on 32-bit Arm hosts in time
1
The function tc6393xb_draw_graphic32() is called in exactly one place,
2
for release 5.0, which means that our deprecation policy allows
2
so just inline the function body at its callsite. This allows us to
3
us to drop it in release 5.2. Remove the code.
3
drop the template header entirely.
4
4
5
To repeat the rationale from the deprecation note: the Linux
5
The code move includes a single added space after 'for' to fix
6
kernel dropped support for 32-bit Arm KVM hosts in 5.7.
6
the coding style.
7
8
Running 32-bit guests on a 64-bit Arm host remains supported.
9
7
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
10
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
13
Message-id: 20200904154156.31943-2-peter.maydell@linaro.org
11
Message-id: 20210215103215.4944-5-peter.maydell@linaro.org
14
---
12
---
15
docs/system/deprecated.rst | 16 +-
13
hw/display/tc6393xb_template.h | 45 ----------------------------------
16
configure | 2 +-
14
hw/display/tc6393xb.c | 23 ++++++++++++++---
17
target/arm/kvm32.c | 595 -------------------------------------
15
2 files changed, 19 insertions(+), 49 deletions(-)
18
target/arm/meson.build | 5 +-
16
delete mode 100644 hw/display/tc6393xb_template.h
19
4 files changed, 10 insertions(+), 608 deletions(-)
20
delete mode 100644 target/arm/kvm32.c
21
17
22
diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
18
diff --git a/hw/display/tc6393xb_template.h b/hw/display/tc6393xb_template.h
23
index XXXXXXX..XXXXXXX 100644
24
--- a/docs/system/deprecated.rst
25
+++ b/docs/system/deprecated.rst
26
@@ -XXX,XX +XXX,XX @@ The ``compat`` property used to set backwards compatibility modes for
27
the processor has been deprecated. The ``max-cpu-compat`` property of
28
the ``pseries`` machine type should be used instead.
29
30
-KVM guest support on 32-bit Arm hosts (since 5.0)
31
-'''''''''''''''''''''''''''''''''''''''''''''''''
32
-
33
-The Linux kernel has dropped support for allowing 32-bit Arm systems
34
-to host KVM guests as of the 5.7 kernel. Accordingly, QEMU is deprecating
35
-its support for this configuration and will remove it in a future version.
36
-Running 32-bit guests on a 64-bit Arm host remains supported.
37
-
38
System emulator devices
39
-----------------------
40
41
@@ -XXX,XX +XXX,XX @@ should be used instead of the 1.09.1 version.
42
System emulator CPUS
43
--------------------
44
45
+KVM guest support on 32-bit Arm hosts (removed in 5.2)
46
+''''''''''''''''''''''''''''''''''''''''''''''''''''''
47
+
48
+The Linux kernel has dropped support for allowing 32-bit Arm systems
49
+to host KVM guests as of the 5.7 kernel. Accordingly, QEMU is deprecating
50
+its support for this configuration and will remove it in a future version.
51
+Running 32-bit guests on a 64-bit Arm host remains supported.
52
+
53
RISC-V ISA Specific CPUs (removed in 5.1)
54
'''''''''''''''''''''''''''''''''''''''''
55
56
diff --git a/configure b/configure
57
index XXXXXXX..XXXXXXX 100755
58
--- a/configure
59
+++ b/configure
60
@@ -XXX,XX +XXX,XX @@ supported_kvm_target() {
61
test "$kvm" = "yes" || return 1
62
glob "$1" "*-softmmu" || return 1
63
case "${1%-softmmu}:$cpu" in
64
- arm:arm | aarch64:aarch64 | \
65
+ aarch64:aarch64 | \
66
i386:i386 | i386:x86_64 | i386:x32 | \
67
x86_64:i386 | x86_64:x86_64 | x86_64:x32 | \
68
mips:mips | mipsel:mips | mips64:mips | mips64el:mips | \
69
diff --git a/target/arm/kvm32.c b/target/arm/kvm32.c
70
deleted file mode 100644
19
deleted file mode 100644
71
index XXXXXXX..XXXXXXX
20
index XXXXXXX..XXXXXXX
72
--- a/target/arm/kvm32.c
21
--- a/hw/display/tc6393xb_template.h
73
+++ /dev/null
22
+++ /dev/null
74
@@ -XXX,XX +XXX,XX @@
23
@@ -XXX,XX +XXX,XX @@
75
-/*
24
-/*
76
- * ARM implementation of KVM hooks, 32 bit specific code.
25
- * Toshiba TC6393XB I/O Controller.
26
- * Found in Sharp Zaurus SL-6000 (tosa) or some
27
- * Toshiba e-Series PDAs.
77
- *
28
- *
78
- * Copyright Christoffer Dall 2009-2010
29
- * FB support code. Based on G364 fb emulator
79
- *
30
- *
80
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
31
- * Copyright (c) 2007 Hervé Poussineau
81
- * See the COPYING file in the top-level directory.
82
- *
32
- *
33
- * This program is free software; you can redistribute it and/or
34
- * modify it under the terms of the GNU General Public License as
35
- * published by the Free Software Foundation; either version 2 of
36
- * the License, or (at your option) any later version.
37
- *
38
- * This program is distributed in the hope that it will be useful,
39
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
40
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41
- * GNU General Public License for more details.
42
- *
43
- * You should have received a copy of the GNU General Public License along
44
- * with this program; if not, see <http://www.gnu.org/licenses/>.
83
- */
45
- */
84
-
46
-
85
-#include "qemu/osdep.h"
47
-static void tc6393xb_draw_graphic32(TC6393xbState *s)
86
-#include <sys/ioctl.h>
48
-{
49
- DisplaySurface *surface = qemu_console_surface(s->con);
50
- int i;
51
- uint16_t *data_buffer;
52
- uint8_t *data_display;
87
-
53
-
88
-#include <linux/kvm.h>
54
- data_buffer = s->vram_ptr;
89
-
55
- data_display = surface_data(surface);
90
-#include "qemu-common.h"
56
- for(i = 0; i < s->scr_height; i++) {
91
-#include "cpu.h"
57
- int j;
92
-#include "qemu/timer.h"
58
- for (j = 0; j < s->scr_width; j++, data_display += 4, data_buffer++) {
93
-#include "sysemu/runstate.h"
59
- uint16_t color = *data_buffer;
94
-#include "sysemu/kvm.h"
60
- uint32_t dest_color = rgb_to_pixel32(
95
-#include "kvm_arm.h"
61
- ((color & 0xf800) * 0x108) >> 11,
96
-#include "internals.h"
62
- ((color & 0x7e0) * 0x41) >> 9,
97
-#include "qemu/log.h"
63
- ((color & 0x1f) * 0x21) >> 2
98
-
64
- );
99
-static int read_sys_reg32(int fd, uint32_t *pret, uint64_t id)
65
- *(uint32_t *)data_display = dest_color;
100
-{
66
- }
101
- struct kvm_one_reg idreg = { .id = id, .addr = (uintptr_t)pret };
102
-
103
- assert((id & KVM_REG_SIZE_MASK) == KVM_REG_SIZE_U32);
104
- return ioctl(fd, KVM_GET_ONE_REG, &idreg);
105
-}
106
-
107
-bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
108
-{
109
- /* Identify the feature bits corresponding to the host CPU, and
110
- * fill out the ARMHostCPUClass fields accordingly. To do this
111
- * we have to create a scratch VM, create a single CPU inside it,
112
- * and then query that CPU for the relevant ID registers.
113
- */
114
- int err = 0, fdarray[3];
115
- uint32_t midr, id_pfr0;
116
- uint64_t features = 0;
117
-
118
- /* Old kernels may not know about the PREFERRED_TARGET ioctl: however
119
- * we know these will only support creating one kind of guest CPU,
120
- * which is its preferred CPU type.
121
- */
122
- static const uint32_t cpus_to_try[] = {
123
- QEMU_KVM_ARM_TARGET_CORTEX_A15,
124
- QEMU_KVM_ARM_TARGET_NONE
125
- };
126
- /*
127
- * target = -1 informs kvm_arm_create_scratch_host_vcpu()
128
- * to use the preferred target
129
- */
130
- struct kvm_vcpu_init init = { .target = -1, };
131
-
132
- if (!kvm_arm_create_scratch_host_vcpu(cpus_to_try, fdarray, &init)) {
133
- return false;
134
- }
135
-
136
- ahcf->target = init.target;
137
-
138
- /* This is not strictly blessed by the device tree binding docs yet,
139
- * but in practice the kernel does not care about this string so
140
- * there is no point maintaining an KVM_ARM_TARGET_* -> string table.
141
- */
142
- ahcf->dtb_compatible = "arm,arm-v7";
143
-
144
- err |= read_sys_reg32(fdarray[2], &midr, ARM_CP15_REG32(0, 0, 0, 0));
145
- err |= read_sys_reg32(fdarray[2], &id_pfr0, ARM_CP15_REG32(0, 0, 1, 0));
146
-
147
- err |= read_sys_reg32(fdarray[2], &ahcf->isar.id_isar0,
148
- ARM_CP15_REG32(0, 0, 2, 0));
149
- err |= read_sys_reg32(fdarray[2], &ahcf->isar.id_isar1,
150
- ARM_CP15_REG32(0, 0, 2, 1));
151
- err |= read_sys_reg32(fdarray[2], &ahcf->isar.id_isar2,
152
- ARM_CP15_REG32(0, 0, 2, 2));
153
- err |= read_sys_reg32(fdarray[2], &ahcf->isar.id_isar3,
154
- ARM_CP15_REG32(0, 0, 2, 3));
155
- err |= read_sys_reg32(fdarray[2], &ahcf->isar.id_isar4,
156
- ARM_CP15_REG32(0, 0, 2, 4));
157
- err |= read_sys_reg32(fdarray[2], &ahcf->isar.id_isar5,
158
- ARM_CP15_REG32(0, 0, 2, 5));
159
- if (read_sys_reg32(fdarray[2], &ahcf->isar.id_isar6,
160
- ARM_CP15_REG32(0, 0, 2, 7))) {
161
- /*
162
- * Older kernels don't support reading ID_ISAR6. This register was
163
- * only introduced in ARMv8, so we can assume that it is zero on a
164
- * CPU that a kernel this old is running on.
165
- */
166
- ahcf->isar.id_isar6 = 0;
167
- }
168
-
169
- err |= read_sys_reg32(fdarray[2], &ahcf->isar.id_dfr0,
170
- ARM_CP15_REG32(0, 0, 1, 2));
171
-
172
- err |= read_sys_reg32(fdarray[2], &ahcf->isar.mvfr0,
173
- KVM_REG_ARM | KVM_REG_SIZE_U32 |
174
- KVM_REG_ARM_VFP | KVM_REG_ARM_VFP_MVFR0);
175
- err |= read_sys_reg32(fdarray[2], &ahcf->isar.mvfr1,
176
- KVM_REG_ARM | KVM_REG_SIZE_U32 |
177
- KVM_REG_ARM_VFP | KVM_REG_ARM_VFP_MVFR1);
178
- /*
179
- * FIXME: There is not yet a way to read MVFR2.
180
- * Fortunately there is not yet anything in there that affects migration.
181
- */
182
-
183
- err |= read_sys_reg32(fdarray[2], &ahcf->isar.id_mmfr0,
184
- ARM_CP15_REG32(0, 0, 1, 4));
185
- err |= read_sys_reg32(fdarray[2], &ahcf->isar.id_mmfr1,
186
- ARM_CP15_REG32(0, 0, 1, 5));
187
- err |= read_sys_reg32(fdarray[2], &ahcf->isar.id_mmfr2,
188
- ARM_CP15_REG32(0, 0, 1, 6));
189
- err |= read_sys_reg32(fdarray[2], &ahcf->isar.id_mmfr3,
190
- ARM_CP15_REG32(0, 0, 1, 7));
191
- if (read_sys_reg32(fdarray[2], &ahcf->isar.id_mmfr4,
192
- ARM_CP15_REG32(0, 0, 2, 6))) {
193
- /*
194
- * Older kernels don't support reading ID_MMFR4 (a new in v8
195
- * register); assume it's zero.
196
- */
197
- ahcf->isar.id_mmfr4 = 0;
198
- }
199
-
200
- /*
201
- * There is no way to read DBGDIDR, because currently 32-bit KVM
202
- * doesn't implement debug at all. Leave it at zero.
203
- */
204
-
205
- kvm_arm_destroy_scratch_host_vcpu(fdarray);
206
-
207
- if (err < 0) {
208
- return false;
209
- }
210
-
211
- /* Now we've retrieved all the register information we can
212
- * set the feature bits based on the ID register fields.
213
- * We can assume any KVM supporting CPU is at least a v7
214
- * with VFPv3, virtualization extensions, and the generic
215
- * timers; this in turn implies most of the other feature
216
- * bits, but a few must be tested.
217
- */
218
- features |= 1ULL << ARM_FEATURE_V7VE;
219
- features |= 1ULL << ARM_FEATURE_GENERIC_TIMER;
220
-
221
- if (extract32(id_pfr0, 12, 4) == 1) {
222
- features |= 1ULL << ARM_FEATURE_THUMB2EE;
223
- }
224
- if (extract32(ahcf->isar.mvfr1, 12, 4) == 1) {
225
- features |= 1ULL << ARM_FEATURE_NEON;
226
- }
227
-
228
- ahcf->features = features;
229
-
230
- return true;
231
-}
232
-
233
-bool kvm_arm_reg_syncs_via_cpreg_list(uint64_t regidx)
234
-{
235
- /* Return true if the regidx is a register we should synchronize
236
- * via the cpreg_tuples array (ie is not a core reg we sync by
237
- * hand in kvm_arch_get/put_registers())
238
- */
239
- switch (regidx & KVM_REG_ARM_COPROC_MASK) {
240
- case KVM_REG_ARM_CORE:
241
- case KVM_REG_ARM_VFP:
242
- return false;
243
- default:
244
- return true;
245
- }
67
- }
246
-}
68
-}
69
diff --git a/hw/display/tc6393xb.c b/hw/display/tc6393xb.c
70
index XXXXXXX..XXXXXXX 100644
71
--- a/hw/display/tc6393xb.c
72
+++ b/hw/display/tc6393xb.c
73
@@ -XXX,XX +XXX,XX @@ static void tc6393xb_nand_writeb(TC6393xbState *s, hwaddr addr, uint32_t value)
74
(uint32_t) addr, value & 0xff);
75
}
76
77
-#define BITS 32
78
-#include "tc6393xb_template.h"
247
-
79
-
248
-typedef struct CPRegStateLevel {
80
static void tc6393xb_draw_graphic(TC6393xbState *s, int full_update)
249
- uint64_t regidx;
81
{
250
- int level;
82
- tc6393xb_draw_graphic32(s);
251
-} CPRegStateLevel;
83
+ DisplaySurface *surface = qemu_console_surface(s->con);
252
-
84
+ int i;
253
-/* All coprocessor registers not listed in the following table are assumed to
85
+ uint16_t *data_buffer;
254
- * be of the level KVM_PUT_RUNTIME_STATE. If a register should be written less
86
+ uint8_t *data_display;
255
- * often, you must add it to this table with a state of either
87
+
256
- * KVM_PUT_RESET_STATE or KVM_PUT_FULL_STATE.
88
+ data_buffer = s->vram_ptr;
257
- */
89
+ data_display = surface_data(surface);
258
-static const CPRegStateLevel non_runtime_cpregs[] = {
90
+ for (i = 0; i < s->scr_height; i++) {
259
- { KVM_REG_ARM_TIMER_CNT, KVM_PUT_FULL_STATE },
91
+ int j;
260
-};
92
+ for (j = 0; j < s->scr_width; j++, data_display += 4, data_buffer++) {
261
-
93
+ uint16_t color = *data_buffer;
262
-int kvm_arm_cpreg_level(uint64_t regidx)
94
+ uint32_t dest_color = rgb_to_pixel32(
263
-{
95
+ ((color & 0xf800) * 0x108) >> 11,
264
- int i;
96
+ ((color & 0x7e0) * 0x41) >> 9,
265
-
97
+ ((color & 0x1f) * 0x21) >> 2
266
- for (i = 0; i < ARRAY_SIZE(non_runtime_cpregs); i++) {
98
+ );
267
- const CPRegStateLevel *l = &non_runtime_cpregs[i];
99
+ *(uint32_t *)data_display = dest_color;
268
- if (l->regidx == regidx) {
100
+ }
269
- return l->level;
101
+ }
270
- }
102
dpy_gfx_update_full(s->con);
271
- }
103
}
272
-
104
273
- return KVM_PUT_RUNTIME_STATE;
274
-}
275
-
276
-#define ARM_CPU_ID_MPIDR 0, 0, 0, 5
277
-
278
-int kvm_arch_init_vcpu(CPUState *cs)
279
-{
280
- int ret;
281
- uint64_t v;
282
- uint32_t mpidr;
283
- struct kvm_one_reg r;
284
- ARMCPU *cpu = ARM_CPU(cs);
285
-
286
- if (cpu->kvm_target == QEMU_KVM_ARM_TARGET_NONE) {
287
- fprintf(stderr, "KVM is not supported for this guest CPU type\n");
288
- return -EINVAL;
289
- }
290
-
291
- qemu_add_vm_change_state_handler(kvm_arm_vm_state_change, cs);
292
-
293
- /* Determine init features for this CPU */
294
- memset(cpu->kvm_init_features, 0, sizeof(cpu->kvm_init_features));
295
- if (cs->start_powered_off) {
296
- cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_POWER_OFF;
297
- }
298
- if (kvm_check_extension(cs->kvm_state, KVM_CAP_ARM_PSCI_0_2)) {
299
- cpu->psci_version = 2;
300
- cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_PSCI_0_2;
301
- }
302
-
303
- /* Do KVM_ARM_VCPU_INIT ioctl */
304
- ret = kvm_arm_vcpu_init(cs);
305
- if (ret) {
306
- return ret;
307
- }
308
-
309
- /* Query the kernel to make sure it supports 32 VFP
310
- * registers: QEMU's "cortex-a15" CPU is always a
311
- * VFP-D32 core. The simplest way to do this is just
312
- * to attempt to read register d31.
313
- */
314
- r.id = KVM_REG_ARM | KVM_REG_SIZE_U64 | KVM_REG_ARM_VFP | 31;
315
- r.addr = (uintptr_t)(&v);
316
- ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, &r);
317
- if (ret == -ENOENT) {
318
- return -EINVAL;
319
- }
320
-
321
- /*
322
- * When KVM is in use, PSCI is emulated in-kernel and not by qemu.
323
- * Currently KVM has its own idea about MPIDR assignment, so we
324
- * override our defaults with what we get from KVM.
325
- */
326
- ret = kvm_get_one_reg(cs, ARM_CP15_REG32(ARM_CPU_ID_MPIDR), &mpidr);
327
- if (ret) {
328
- return ret;
329
- }
330
- cpu->mp_affinity = mpidr & ARM32_AFFINITY_MASK;
331
-
332
- /* Check whether userspace can specify guest syndrome value */
333
- kvm_arm_init_serror_injection(cs);
334
-
335
- return kvm_arm_init_cpreg_list(cpu);
336
-}
337
-
338
-int kvm_arch_destroy_vcpu(CPUState *cs)
339
-{
340
-    return 0;
341
-}
342
-
343
-typedef struct Reg {
344
- uint64_t id;
345
- int offset;
346
-} Reg;
347
-
348
-#define COREREG(KERNELNAME, QEMUFIELD) \
349
- { \
350
- KVM_REG_ARM | KVM_REG_SIZE_U32 | \
351
- KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(KERNELNAME), \
352
- offsetof(CPUARMState, QEMUFIELD) \
353
- }
354
-
355
-#define VFPSYSREG(R) \
356
- { \
357
- KVM_REG_ARM | KVM_REG_SIZE_U32 | KVM_REG_ARM_VFP | \
358
- KVM_REG_ARM_VFP_##R, \
359
- offsetof(CPUARMState, vfp.xregs[ARM_VFP_##R]) \
360
- }
361
-
362
-/* Like COREREG, but handle fields which are in a uint64_t in CPUARMState. */
363
-#define COREREG64(KERNELNAME, QEMUFIELD) \
364
- { \
365
- KVM_REG_ARM | KVM_REG_SIZE_U32 | \
366
- KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(KERNELNAME), \
367
- offsetoflow32(CPUARMState, QEMUFIELD) \
368
- }
369
-
370
-static const Reg regs[] = {
371
- /* R0_usr .. R14_usr */
372
- COREREG(usr_regs.uregs[0], regs[0]),
373
- COREREG(usr_regs.uregs[1], regs[1]),
374
- COREREG(usr_regs.uregs[2], regs[2]),
375
- COREREG(usr_regs.uregs[3], regs[3]),
376
- COREREG(usr_regs.uregs[4], regs[4]),
377
- COREREG(usr_regs.uregs[5], regs[5]),
378
- COREREG(usr_regs.uregs[6], regs[6]),
379
- COREREG(usr_regs.uregs[7], regs[7]),
380
- COREREG(usr_regs.uregs[8], usr_regs[0]),
381
- COREREG(usr_regs.uregs[9], usr_regs[1]),
382
- COREREG(usr_regs.uregs[10], usr_regs[2]),
383
- COREREG(usr_regs.uregs[11], usr_regs[3]),
384
- COREREG(usr_regs.uregs[12], usr_regs[4]),
385
- COREREG(usr_regs.uregs[13], banked_r13[BANK_USRSYS]),
386
- COREREG(usr_regs.uregs[14], banked_r14[BANK_USRSYS]),
387
- /* R13, R14, SPSR for SVC, ABT, UND, IRQ banks */
388
- COREREG(svc_regs[0], banked_r13[BANK_SVC]),
389
- COREREG(svc_regs[1], banked_r14[BANK_SVC]),
390
- COREREG64(svc_regs[2], banked_spsr[BANK_SVC]),
391
- COREREG(abt_regs[0], banked_r13[BANK_ABT]),
392
- COREREG(abt_regs[1], banked_r14[BANK_ABT]),
393
- COREREG64(abt_regs[2], banked_spsr[BANK_ABT]),
394
- COREREG(und_regs[0], banked_r13[BANK_UND]),
395
- COREREG(und_regs[1], banked_r14[BANK_UND]),
396
- COREREG64(und_regs[2], banked_spsr[BANK_UND]),
397
- COREREG(irq_regs[0], banked_r13[BANK_IRQ]),
398
- COREREG(irq_regs[1], banked_r14[BANK_IRQ]),
399
- COREREG64(irq_regs[2], banked_spsr[BANK_IRQ]),
400
- /* R8_fiq .. R14_fiq and SPSR_fiq */
401
- COREREG(fiq_regs[0], fiq_regs[0]),
402
- COREREG(fiq_regs[1], fiq_regs[1]),
403
- COREREG(fiq_regs[2], fiq_regs[2]),
404
- COREREG(fiq_regs[3], fiq_regs[3]),
405
- COREREG(fiq_regs[4], fiq_regs[4]),
406
- COREREG(fiq_regs[5], banked_r13[BANK_FIQ]),
407
- COREREG(fiq_regs[6], banked_r14[BANK_FIQ]),
408
- COREREG64(fiq_regs[7], banked_spsr[BANK_FIQ]),
409
- /* R15 */
410
- COREREG(usr_regs.uregs[15], regs[15]),
411
- /* VFP system registers */
412
- VFPSYSREG(FPSID),
413
- VFPSYSREG(MVFR1),
414
- VFPSYSREG(MVFR0),
415
- VFPSYSREG(FPEXC),
416
- VFPSYSREG(FPINST),
417
- VFPSYSREG(FPINST2),
418
-};
419
-
420
-int kvm_arch_put_registers(CPUState *cs, int level)
421
-{
422
- ARMCPU *cpu = ARM_CPU(cs);
423
- CPUARMState *env = &cpu->env;
424
- struct kvm_one_reg r;
425
- int mode, bn;
426
- int ret, i;
427
- uint32_t cpsr, fpscr;
428
-
429
- /* Make sure the banked regs are properly set */
430
- mode = env->uncached_cpsr & CPSR_M;
431
- bn = bank_number(mode);
432
- if (mode == ARM_CPU_MODE_FIQ) {
433
- memcpy(env->fiq_regs, env->regs + 8, 5 * sizeof(uint32_t));
434
- } else {
435
- memcpy(env->usr_regs, env->regs + 8, 5 * sizeof(uint32_t));
436
- }
437
- env->banked_r13[bn] = env->regs[13];
438
- env->banked_spsr[bn] = env->spsr;
439
- env->banked_r14[r14_bank_number(mode)] = env->regs[14];
440
-
441
- /* Now we can safely copy stuff down to the kernel */
442
- for (i = 0; i < ARRAY_SIZE(regs); i++) {
443
- r.id = regs[i].id;
444
- r.addr = (uintptr_t)(env) + regs[i].offset;
445
- ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, &r);
446
- if (ret) {
447
- return ret;
448
- }
449
- }
450
-
451
- /* Special cases which aren't a single CPUARMState field */
452
- cpsr = cpsr_read(env);
453
- r.id = KVM_REG_ARM | KVM_REG_SIZE_U32 |
454
- KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(usr_regs.ARM_cpsr);
455
- r.addr = (uintptr_t)(&cpsr);
456
- ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, &r);
457
- if (ret) {
458
- return ret;
459
- }
460
-
461
- /* VFP registers */
462
- r.id = KVM_REG_ARM | KVM_REG_SIZE_U64 | KVM_REG_ARM_VFP;
463
- for (i = 0; i < 32; i++) {
464
- r.addr = (uintptr_t)aa32_vfp_dreg(env, i);
465
- ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, &r);
466
- if (ret) {
467
- return ret;
468
- }
469
- r.id++;
470
- }
471
-
472
- r.id = KVM_REG_ARM | KVM_REG_SIZE_U32 | KVM_REG_ARM_VFP |
473
- KVM_REG_ARM_VFP_FPSCR;
474
- fpscr = vfp_get_fpscr(env);
475
- r.addr = (uintptr_t)&fpscr;
476
- ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, &r);
477
- if (ret) {
478
- return ret;
479
- }
480
-
481
- write_cpustate_to_list(cpu, true);
482
-
483
- if (!write_list_to_kvmstate(cpu, level)) {
484
- return EINVAL;
485
- }
486
-
487
- /*
488
- * Setting VCPU events should be triggered after syncing the registers
489
- * to avoid overwriting potential changes made by KVM upon calling
490
- * KVM_SET_VCPU_EVENTS ioctl
491
- */
492
- ret = kvm_put_vcpu_events(cpu);
493
- if (ret) {
494
- return ret;
495
- }
496
-
497
- kvm_arm_sync_mpstate_to_kvm(cpu);
498
-
499
- return ret;
500
-}
501
-
502
-int kvm_arch_get_registers(CPUState *cs)
503
-{
504
- ARMCPU *cpu = ARM_CPU(cs);
505
- CPUARMState *env = &cpu->env;
506
- struct kvm_one_reg r;
507
- int mode, bn;
508
- int ret, i;
509
- uint32_t cpsr, fpscr;
510
-
511
- for (i = 0; i < ARRAY_SIZE(regs); i++) {
512
- r.id = regs[i].id;
513
- r.addr = (uintptr_t)(env) + regs[i].offset;
514
- ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, &r);
515
- if (ret) {
516
- return ret;
517
- }
518
- }
519
-
520
- /* Special cases which aren't a single CPUARMState field */
521
- r.id = KVM_REG_ARM | KVM_REG_SIZE_U32 |
522
- KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(usr_regs.ARM_cpsr);
523
- r.addr = (uintptr_t)(&cpsr);
524
- ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, &r);
525
- if (ret) {
526
- return ret;
527
- }
528
- cpsr_write(env, cpsr, 0xffffffff, CPSRWriteRaw);
529
-
530
- /* Make sure the current mode regs are properly set */
531
- mode = env->uncached_cpsr & CPSR_M;
532
- bn = bank_number(mode);
533
- if (mode == ARM_CPU_MODE_FIQ) {
534
- memcpy(env->regs + 8, env->fiq_regs, 5 * sizeof(uint32_t));
535
- } else {
536
- memcpy(env->regs + 8, env->usr_regs, 5 * sizeof(uint32_t));
537
- }
538
- env->regs[13] = env->banked_r13[bn];
539
- env->spsr = env->banked_spsr[bn];
540
- env->regs[14] = env->banked_r14[r14_bank_number(mode)];
541
-
542
- /* VFP registers */
543
- r.id = KVM_REG_ARM | KVM_REG_SIZE_U64 | KVM_REG_ARM_VFP;
544
- for (i = 0; i < 32; i++) {
545
- r.addr = (uintptr_t)aa32_vfp_dreg(env, i);
546
- ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, &r);
547
- if (ret) {
548
- return ret;
549
- }
550
- r.id++;
551
- }
552
-
553
- r.id = KVM_REG_ARM | KVM_REG_SIZE_U32 | KVM_REG_ARM_VFP |
554
- KVM_REG_ARM_VFP_FPSCR;
555
- r.addr = (uintptr_t)&fpscr;
556
- ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, &r);
557
- if (ret) {
558
- return ret;
559
- }
560
- vfp_set_fpscr(env, fpscr);
561
-
562
- ret = kvm_get_vcpu_events(cpu);
563
- if (ret) {
564
- return ret;
565
- }
566
-
567
- if (!write_kvmstate_to_list(cpu)) {
568
- return EINVAL;
569
- }
570
- /* Note that it's OK to have registers which aren't in CPUState,
571
- * so we can ignore a failure return here.
572
- */
573
- write_list_to_cpustate(cpu);
574
-
575
- kvm_arm_sync_mpstate_to_qemu(cpu);
576
-
577
- return 0;
578
-}
579
-
580
-int kvm_arch_insert_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp)
581
-{
582
- qemu_log_mask(LOG_UNIMP, "%s: guest debug not yet implemented\n", __func__);
583
- return -EINVAL;
584
-}
585
-
586
-int kvm_arch_remove_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp)
587
-{
588
- qemu_log_mask(LOG_UNIMP, "%s: guest debug not yet implemented\n", __func__);
589
- return -EINVAL;
590
-}
591
-
592
-bool kvm_arm_handle_debug(CPUState *cs, struct kvm_debug_exit_arch *debug_exit)
593
-{
594
- qemu_log_mask(LOG_UNIMP, "%s: guest debug not yet implemented\n", __func__);
595
- return false;
596
-}
597
-
598
-int kvm_arch_insert_hw_breakpoint(target_ulong addr,
599
- target_ulong len, int type)
600
-{
601
- qemu_log_mask(LOG_UNIMP, "%s: not implemented\n", __func__);
602
- return -EINVAL;
603
-}
604
-
605
-int kvm_arch_remove_hw_breakpoint(target_ulong addr,
606
- target_ulong len, int type)
607
-{
608
- qemu_log_mask(LOG_UNIMP, "%s: not implemented\n", __func__);
609
- return -EINVAL;
610
-}
611
-
612
-void kvm_arch_remove_all_hw_breakpoints(void)
613
-{
614
- qemu_log_mask(LOG_UNIMP, "%s: not implemented\n", __func__);
615
-}
616
-
617
-void kvm_arm_copy_hw_debug_data(struct kvm_guest_debug_arch *ptr)
618
-{
619
- qemu_log_mask(LOG_UNIMP, "%s: not implemented\n", __func__);
620
-}
621
-
622
-bool kvm_arm_hw_debug_active(CPUState *cs)
623
-{
624
- return false;
625
-}
626
-
627
-void kvm_arm_pmu_set_irq(CPUState *cs, int irq)
628
-{
629
- qemu_log_mask(LOG_UNIMP, "%s: not implemented\n", __func__);
630
-}
631
-
632
-void kvm_arm_pmu_init(CPUState *cs)
633
-{
634
- qemu_log_mask(LOG_UNIMP, "%s: not implemented\n", __func__);
635
-}
636
-
637
-#define ARM_REG_DFSR ARM_CP15_REG32(0, 5, 0, 0)
638
-#define ARM_REG_TTBCR ARM_CP15_REG32(0, 2, 0, 2)
639
-/*
640
- *DFSR:
641
- * TTBCR.EAE == 0
642
- * FS[4] - DFSR[10]
643
- * FS[3:0] - DFSR[3:0]
644
- * TTBCR.EAE == 1
645
- * FS, bits [5:0]
646
- */
647
-#define DFSR_FSC(lpae, v) \
648
- ((lpae) ? ((v) & 0x3F) : (((v) >> 6) | ((v) & 0x1F)))
649
-
650
-#define DFSC_EXTABT(lpae) ((lpae) ? 0x10 : 0x08)
651
-
652
-bool kvm_arm_verify_ext_dabt_pending(CPUState *cs)
653
-{
654
- uint32_t dfsr_val;
655
-
656
- if (!kvm_get_one_reg(cs, ARM_REG_DFSR, &dfsr_val)) {
657
- ARMCPU *cpu = ARM_CPU(cs);
658
- CPUARMState *env = &cpu->env;
659
- uint32_t ttbcr;
660
- int lpae = 0;
661
-
662
- if (!kvm_get_one_reg(cs, ARM_REG_TTBCR, &ttbcr)) {
663
- lpae = arm_feature(env, ARM_FEATURE_LPAE) && (ttbcr & TTBCR_EAE);
664
- }
665
- /* The verification is based on FS filed of the DFSR reg only*/
666
- return (DFSR_FSC(lpae, dfsr_val) == DFSC_EXTABT(lpae));
667
- }
668
- return false;
669
-}
670
diff --git a/target/arm/meson.build b/target/arm/meson.build
671
index XXXXXXX..XXXXXXX 100644
672
--- a/target/arm/meson.build
673
+++ b/target/arm/meson.build
674
@@ -XXX,XX +XXX,XX @@ arm_ss.add(zlib)
675
676
arm_ss.add(when: 'CONFIG_TCG', if_true: files('arm-semi.c'))
677
678
-kvm_ss = ss.source_set()
679
-kvm_ss.add(when: 'TARGET_AARCH64', if_true: files('kvm64.c'), if_false: files('kvm32.c'))
680
-arm_ss.add_all(when: 'CONFIG_KVM', if_true: kvm_ss)
681
-arm_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c'), if_false: files('kvm-stub.c'))
682
+arm_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c', 'kvm64.c'), if_false: files('kvm-stub.c'))
683
684
arm_ss.add(when: 'TARGET_AARCH64', if_true: files(
685
'cpu64.c',
686
--
105
--
687
2.20.1
106
2.20.1
688
107
689
108
diff view generated by jsdifflib
New patch
1
The omap_lcdc template header is already only included once, for
2
DEPTH==32, but it still has all the macro-driven parameterization
3
for other depths. Expand out all the macros in the header.
1
4
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Message-id: 20210215103215.4944-6-peter.maydell@linaro.org
9
---
10
hw/display/omap_lcd_template.h | 67 ++++++++++++++--------------------
11
1 file changed, 28 insertions(+), 39 deletions(-)
12
13
diff --git a/hw/display/omap_lcd_template.h b/hw/display/omap_lcd_template.h
14
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/display/omap_lcd_template.h
16
+++ b/hw/display/omap_lcd_template.h
17
@@ -XXX,XX +XXX,XX @@
18
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19
*/
20
21
-#if DEPTH == 32
22
-# define BPP 4
23
-# define PIXEL_TYPE uint32_t
24
-#else
25
-# error unsupport depth
26
-#endif
27
-
28
/*
29
* 2-bit colour
30
*/
31
-static void glue(draw_line2_, DEPTH)(void *opaque,
32
- uint8_t *d, const uint8_t *s, int width, int deststep)
33
+static void draw_line2_32(void *opaque, uint8_t *d, const uint8_t *s,
34
+ int width, int deststep)
35
{
36
uint16_t *pal = opaque;
37
uint8_t v, r, g, b;
38
@@ -XXX,XX +XXX,XX @@ static void glue(draw_line2_, DEPTH)(void *opaque,
39
r = (pal[v & 3] >> 4) & 0xf0;
40
g = pal[v & 3] & 0xf0;
41
b = (pal[v & 3] << 4) & 0xf0;
42
- ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
43
- d += BPP;
44
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
45
+ d += 4;
46
v >>= 2;
47
r = (pal[v & 3] >> 4) & 0xf0;
48
g = pal[v & 3] & 0xf0;
49
b = (pal[v & 3] << 4) & 0xf0;
50
- ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
51
- d += BPP;
52
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
53
+ d += 4;
54
v >>= 2;
55
r = (pal[v & 3] >> 4) & 0xf0;
56
g = pal[v & 3] & 0xf0;
57
b = (pal[v & 3] << 4) & 0xf0;
58
- ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
59
- d += BPP;
60
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
61
+ d += 4;
62
v >>= 2;
63
r = (pal[v & 3] >> 4) & 0xf0;
64
g = pal[v & 3] & 0xf0;
65
b = (pal[v & 3] << 4) & 0xf0;
66
- ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
67
- d += BPP;
68
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
69
+ d += 4;
70
s ++;
71
width -= 4;
72
} while (width > 0);
73
@@ -XXX,XX +XXX,XX @@ static void glue(draw_line2_, DEPTH)(void *opaque,
74
/*
75
* 4-bit colour
76
*/
77
-static void glue(draw_line4_, DEPTH)(void *opaque,
78
- uint8_t *d, const uint8_t *s, int width, int deststep)
79
+static void draw_line4_32(void *opaque, uint8_t *d, const uint8_t *s,
80
+ int width, int deststep)
81
{
82
uint16_t *pal = opaque;
83
uint8_t v, r, g, b;
84
@@ -XXX,XX +XXX,XX @@ static void glue(draw_line4_, DEPTH)(void *opaque,
85
r = (pal[v & 0xf] >> 4) & 0xf0;
86
g = pal[v & 0xf] & 0xf0;
87
b = (pal[v & 0xf] << 4) & 0xf0;
88
- ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
89
- d += BPP;
90
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
91
+ d += 4;
92
v >>= 4;
93
r = (pal[v & 0xf] >> 4) & 0xf0;
94
g = pal[v & 0xf] & 0xf0;
95
b = (pal[v & 0xf] << 4) & 0xf0;
96
- ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
97
- d += BPP;
98
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
99
+ d += 4;
100
s ++;
101
width -= 2;
102
} while (width > 0);
103
@@ -XXX,XX +XXX,XX @@ static void glue(draw_line4_, DEPTH)(void *opaque,
104
/*
105
* 8-bit colour
106
*/
107
-static void glue(draw_line8_, DEPTH)(void *opaque,
108
- uint8_t *d, const uint8_t *s, int width, int deststep)
109
+static void draw_line8_32(void *opaque, uint8_t *d, const uint8_t *s,
110
+ int width, int deststep)
111
{
112
uint16_t *pal = opaque;
113
uint8_t v, r, g, b;
114
@@ -XXX,XX +XXX,XX @@ static void glue(draw_line8_, DEPTH)(void *opaque,
115
r = (pal[v] >> 4) & 0xf0;
116
g = pal[v] & 0xf0;
117
b = (pal[v] << 4) & 0xf0;
118
- ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
119
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
120
s ++;
121
- d += BPP;
122
+ d += 4;
123
} while (-- width != 0);
124
}
125
126
/*
127
* 12-bit colour
128
*/
129
-static void glue(draw_line12_, DEPTH)(void *opaque,
130
- uint8_t *d, const uint8_t *s, int width, int deststep)
131
+static void draw_line12_32(void *opaque, uint8_t *d, const uint8_t *s,
132
+ int width, int deststep)
133
{
134
uint16_t v;
135
uint8_t r, g, b;
136
@@ -XXX,XX +XXX,XX @@ static void glue(draw_line12_, DEPTH)(void *opaque,
137
r = (v >> 4) & 0xf0;
138
g = v & 0xf0;
139
b = (v << 4) & 0xf0;
140
- ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
141
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
142
s += 2;
143
- d += BPP;
144
+ d += 4;
145
} while (-- width != 0);
146
}
147
148
/*
149
* 16-bit colour
150
*/
151
-static void glue(draw_line16_, DEPTH)(void *opaque,
152
- uint8_t *d, const uint8_t *s, int width, int deststep)
153
+static void draw_line16_32(void *opaque, uint8_t *d, const uint8_t *s,
154
+ int width, int deststep)
155
{
156
#if defined(HOST_WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN)
157
memcpy(d, s, width * 2);
158
@@ -XXX,XX +XXX,XX @@ static void glue(draw_line16_, DEPTH)(void *opaque,
159
r = (v >> 8) & 0xf8;
160
g = (v >> 3) & 0xfc;
161
b = (v << 3) & 0xf8;
162
- ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
163
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
164
s += 2;
165
- d += BPP;
166
+ d += 4;
167
} while (-- width != 0);
168
#endif
169
}
170
-
171
-#undef DEPTH
172
-#undef BPP
173
-#undef PIXEL_TYPE
174
--
175
2.20.1
176
177
diff view generated by jsdifflib
New patch
1
The draw_line16_32() function in the omap_lcdc template header
2
includes an ifdef for the case where HOST_WORDS_BIGENDIAN matches
3
TARGET_WORDS_BIGENDIAN. This is trying to optimise for "source
4
bitmap and destination bitmap format match", but it is broken,
5
because in this function the formats don't match: the source is
6
16-bit colour and the destination is 32-bit colour, so a memcpy()
7
will produce corrupted graphics output. Drop the bogus ifdef.
1
8
9
This bug was introduced in commit ea644cf343129, when we dropped
10
support for DEPTH values other than 32 from the template header.
11
The old #if line was
12
#if DEPTH == 16 && defined(HOST_WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN)
13
and this was mistakenly changed to
14
#if defined(HOST_WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN)
15
rather than deleting the #if as now having an always-false condition.
16
17
Fixes: ea644cf343129
18
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
19
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
20
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
21
Message-id: 20210215103215.4944-7-peter.maydell@linaro.org
22
---
23
hw/display/omap_lcd_template.h | 4 ----
24
1 file changed, 4 deletions(-)
25
26
diff --git a/hw/display/omap_lcd_template.h b/hw/display/omap_lcd_template.h
27
index XXXXXXX..XXXXXXX 100644
28
--- a/hw/display/omap_lcd_template.h
29
+++ b/hw/display/omap_lcd_template.h
30
@@ -XXX,XX +XXX,XX @@ static void draw_line12_32(void *opaque, uint8_t *d, const uint8_t *s,
31
static void draw_line16_32(void *opaque, uint8_t *d, const uint8_t *s,
32
int width, int deststep)
33
{
34
-#if defined(HOST_WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN)
35
- memcpy(d, s, width * 2);
36
-#else
37
uint16_t v;
38
uint8_t r, g, b;
39
40
@@ -XXX,XX +XXX,XX @@ static void draw_line16_32(void *opaque, uint8_t *d, const uint8_t *s,
41
s += 2;
42
d += 4;
43
} while (-- width != 0);
44
-#endif
45
}
46
--
47
2.20.1
48
49
diff view generated by jsdifflib
New patch
1
Fix some minor coding style issues in the template header,
2
so checkpatch doesn't complain when we move the code.
1
3
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Message-id: 20210215103215.4944-8-peter.maydell@linaro.org
8
---
9
hw/display/omap_lcd_template.h | 6 +++---
10
1 file changed, 3 insertions(+), 3 deletions(-)
11
12
diff --git a/hw/display/omap_lcd_template.h b/hw/display/omap_lcd_template.h
13
index XXXXXXX..XXXXXXX 100644
14
--- a/hw/display/omap_lcd_template.h
15
+++ b/hw/display/omap_lcd_template.h
16
@@ -XXX,XX +XXX,XX @@ static void draw_line2_32(void *opaque, uint8_t *d, const uint8_t *s,
17
b = (pal[v & 3] << 4) & 0xf0;
18
((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
19
d += 4;
20
- s ++;
21
+ s++;
22
width -= 4;
23
} while (width > 0);
24
}
25
@@ -XXX,XX +XXX,XX @@ static void draw_line4_32(void *opaque, uint8_t *d, const uint8_t *s,
26
b = (pal[v & 0xf] << 4) & 0xf0;
27
((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
28
d += 4;
29
- s ++;
30
+ s++;
31
width -= 2;
32
} while (width > 0);
33
}
34
@@ -XXX,XX +XXX,XX @@ static void draw_line8_32(void *opaque, uint8_t *d, const uint8_t *s,
35
g = pal[v] & 0xf0;
36
b = (pal[v] << 4) & 0xf0;
37
((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
38
- s ++;
39
+ s++;
40
d += 4;
41
} while (-- width != 0);
42
}
43
--
44
2.20.1
45
46
diff view generated by jsdifflib
New patch
1
We only include the template header once, so just inline it into the
2
source file for the device.
1
3
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Message-id: 20210215103215.4944-9-peter.maydell@linaro.org
8
---
9
hw/display/omap_lcd_template.h | 154 ---------------------------------
10
hw/display/omap_lcdc.c | 127 ++++++++++++++++++++++++++-
11
2 files changed, 125 insertions(+), 156 deletions(-)
12
delete mode 100644 hw/display/omap_lcd_template.h
13
14
diff --git a/hw/display/omap_lcd_template.h b/hw/display/omap_lcd_template.h
15
deleted file mode 100644
16
index XXXXXXX..XXXXXXX
17
--- a/hw/display/omap_lcd_template.h
18
+++ /dev/null
19
@@ -XXX,XX +XXX,XX @@
20
-/*
21
- * QEMU OMAP LCD Emulator templates
22
- *
23
- * Copyright (c) 2006 Andrzej Zaborowski <balrog@zabor.org>
24
- *
25
- * Redistribution and use in source and binary forms, with or without
26
- * modification, are permitted provided that the following conditions
27
- * are met:
28
- *
29
- * 1. Redistributions of source code must retain the above copyright
30
- * notice, this list of conditions and the following disclaimer.
31
- * 2. Redistributions in binary form must reproduce the above copyright
32
- * notice, this list of conditions and the following disclaimer in
33
- * the documentation and/or other materials provided with the
34
- * distribution.
35
- *
36
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
37
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
38
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
39
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
40
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
41
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
42
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
43
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
44
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
45
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
46
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47
- */
48
-
49
-/*
50
- * 2-bit colour
51
- */
52
-static void draw_line2_32(void *opaque, uint8_t *d, const uint8_t *s,
53
- int width, int deststep)
54
-{
55
- uint16_t *pal = opaque;
56
- uint8_t v, r, g, b;
57
-
58
- do {
59
- v = ldub_p((void *) s);
60
- r = (pal[v & 3] >> 4) & 0xf0;
61
- g = pal[v & 3] & 0xf0;
62
- b = (pal[v & 3] << 4) & 0xf0;
63
- ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
64
- d += 4;
65
- v >>= 2;
66
- r = (pal[v & 3] >> 4) & 0xf0;
67
- g = pal[v & 3] & 0xf0;
68
- b = (pal[v & 3] << 4) & 0xf0;
69
- ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
70
- d += 4;
71
- v >>= 2;
72
- r = (pal[v & 3] >> 4) & 0xf0;
73
- g = pal[v & 3] & 0xf0;
74
- b = (pal[v & 3] << 4) & 0xf0;
75
- ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
76
- d += 4;
77
- v >>= 2;
78
- r = (pal[v & 3] >> 4) & 0xf0;
79
- g = pal[v & 3] & 0xf0;
80
- b = (pal[v & 3] << 4) & 0xf0;
81
- ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
82
- d += 4;
83
- s++;
84
- width -= 4;
85
- } while (width > 0);
86
-}
87
-
88
-/*
89
- * 4-bit colour
90
- */
91
-static void draw_line4_32(void *opaque, uint8_t *d, const uint8_t *s,
92
- int width, int deststep)
93
-{
94
- uint16_t *pal = opaque;
95
- uint8_t v, r, g, b;
96
-
97
- do {
98
- v = ldub_p((void *) s);
99
- r = (pal[v & 0xf] >> 4) & 0xf0;
100
- g = pal[v & 0xf] & 0xf0;
101
- b = (pal[v & 0xf] << 4) & 0xf0;
102
- ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
103
- d += 4;
104
- v >>= 4;
105
- r = (pal[v & 0xf] >> 4) & 0xf0;
106
- g = pal[v & 0xf] & 0xf0;
107
- b = (pal[v & 0xf] << 4) & 0xf0;
108
- ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
109
- d += 4;
110
- s++;
111
- width -= 2;
112
- } while (width > 0);
113
-}
114
-
115
-/*
116
- * 8-bit colour
117
- */
118
-static void draw_line8_32(void *opaque, uint8_t *d, const uint8_t *s,
119
- int width, int deststep)
120
-{
121
- uint16_t *pal = opaque;
122
- uint8_t v, r, g, b;
123
-
124
- do {
125
- v = ldub_p((void *) s);
126
- r = (pal[v] >> 4) & 0xf0;
127
- g = pal[v] & 0xf0;
128
- b = (pal[v] << 4) & 0xf0;
129
- ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
130
- s++;
131
- d += 4;
132
- } while (-- width != 0);
133
-}
134
-
135
-/*
136
- * 12-bit colour
137
- */
138
-static void draw_line12_32(void *opaque, uint8_t *d, const uint8_t *s,
139
- int width, int deststep)
140
-{
141
- uint16_t v;
142
- uint8_t r, g, b;
143
-
144
- do {
145
- v = lduw_le_p((void *) s);
146
- r = (v >> 4) & 0xf0;
147
- g = v & 0xf0;
148
- b = (v << 4) & 0xf0;
149
- ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
150
- s += 2;
151
- d += 4;
152
- } while (-- width != 0);
153
-}
154
-
155
-/*
156
- * 16-bit colour
157
- */
158
-static void draw_line16_32(void *opaque, uint8_t *d, const uint8_t *s,
159
- int width, int deststep)
160
-{
161
- uint16_t v;
162
- uint8_t r, g, b;
163
-
164
- do {
165
- v = lduw_le_p((void *) s);
166
- r = (v >> 8) & 0xf8;
167
- g = (v >> 3) & 0xfc;
168
- b = (v << 3) & 0xf8;
169
- ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
170
- s += 2;
171
- d += 4;
172
- } while (-- width != 0);
173
-}
174
diff --git a/hw/display/omap_lcdc.c b/hw/display/omap_lcdc.c
175
index XXXXXXX..XXXXXXX 100644
176
--- a/hw/display/omap_lcdc.c
177
+++ b/hw/display/omap_lcdc.c
178
@@ -XXX,XX +XXX,XX @@ static void omap_lcd_interrupts(struct omap_lcd_panel_s *s)
179
180
#define draw_line_func drawfn
181
182
-#define DEPTH 32
183
-#include "omap_lcd_template.h"
184
+/*
185
+ * 2-bit colour
186
+ */
187
+static void draw_line2_32(void *opaque, uint8_t *d, const uint8_t *s,
188
+ int width, int deststep)
189
+{
190
+ uint16_t *pal = opaque;
191
+ uint8_t v, r, g, b;
192
+
193
+ do {
194
+ v = ldub_p((void *) s);
195
+ r = (pal[v & 3] >> 4) & 0xf0;
196
+ g = pal[v & 3] & 0xf0;
197
+ b = (pal[v & 3] << 4) & 0xf0;
198
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
199
+ d += 4;
200
+ v >>= 2;
201
+ r = (pal[v & 3] >> 4) & 0xf0;
202
+ g = pal[v & 3] & 0xf0;
203
+ b = (pal[v & 3] << 4) & 0xf0;
204
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
205
+ d += 4;
206
+ v >>= 2;
207
+ r = (pal[v & 3] >> 4) & 0xf0;
208
+ g = pal[v & 3] & 0xf0;
209
+ b = (pal[v & 3] << 4) & 0xf0;
210
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
211
+ d += 4;
212
+ v >>= 2;
213
+ r = (pal[v & 3] >> 4) & 0xf0;
214
+ g = pal[v & 3] & 0xf0;
215
+ b = (pal[v & 3] << 4) & 0xf0;
216
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
217
+ d += 4;
218
+ s++;
219
+ width -= 4;
220
+ } while (width > 0);
221
+}
222
+
223
+/*
224
+ * 4-bit colour
225
+ */
226
+static void draw_line4_32(void *opaque, uint8_t *d, const uint8_t *s,
227
+ int width, int deststep)
228
+{
229
+ uint16_t *pal = opaque;
230
+ uint8_t v, r, g, b;
231
+
232
+ do {
233
+ v = ldub_p((void *) s);
234
+ r = (pal[v & 0xf] >> 4) & 0xf0;
235
+ g = pal[v & 0xf] & 0xf0;
236
+ b = (pal[v & 0xf] << 4) & 0xf0;
237
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
238
+ d += 4;
239
+ v >>= 4;
240
+ r = (pal[v & 0xf] >> 4) & 0xf0;
241
+ g = pal[v & 0xf] & 0xf0;
242
+ b = (pal[v & 0xf] << 4) & 0xf0;
243
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
244
+ d += 4;
245
+ s++;
246
+ width -= 2;
247
+ } while (width > 0);
248
+}
249
+
250
+/*
251
+ * 8-bit colour
252
+ */
253
+static void draw_line8_32(void *opaque, uint8_t *d, const uint8_t *s,
254
+ int width, int deststep)
255
+{
256
+ uint16_t *pal = opaque;
257
+ uint8_t v, r, g, b;
258
+
259
+ do {
260
+ v = ldub_p((void *) s);
261
+ r = (pal[v] >> 4) & 0xf0;
262
+ g = pal[v] & 0xf0;
263
+ b = (pal[v] << 4) & 0xf0;
264
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
265
+ s++;
266
+ d += 4;
267
+ } while (-- width != 0);
268
+}
269
+
270
+/*
271
+ * 12-bit colour
272
+ */
273
+static void draw_line12_32(void *opaque, uint8_t *d, const uint8_t *s,
274
+ int width, int deststep)
275
+{
276
+ uint16_t v;
277
+ uint8_t r, g, b;
278
+
279
+ do {
280
+ v = lduw_le_p((void *) s);
281
+ r = (v >> 4) & 0xf0;
282
+ g = v & 0xf0;
283
+ b = (v << 4) & 0xf0;
284
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
285
+ s += 2;
286
+ d += 4;
287
+ } while (-- width != 0);
288
+}
289
+
290
+/*
291
+ * 16-bit colour
292
+ */
293
+static void draw_line16_32(void *opaque, uint8_t *d, const uint8_t *s,
294
+ int width, int deststep)
295
+{
296
+ uint16_t v;
297
+ uint8_t r, g, b;
298
+
299
+ do {
300
+ v = lduw_le_p((void *) s);
301
+ r = (v >> 8) & 0xf8;
302
+ g = (v >> 3) & 0xfc;
303
+ b = (v << 3) & 0xf8;
304
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
305
+ s += 2;
306
+ d += 4;
307
+ } while (-- width != 0);
308
+}
309
310
static void omap_update_display(void *opaque)
311
{
312
--
313
2.20.1
314
315
diff view generated by jsdifflib
New patch
1
The macro draw_line_func is used only once; just expand it.
1
2
3
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Message-id: 20210215103215.4944-10-peter.maydell@linaro.org
7
---
8
hw/display/omap_lcdc.c | 4 +---
9
1 file changed, 1 insertion(+), 3 deletions(-)
10
11
diff --git a/hw/display/omap_lcdc.c b/hw/display/omap_lcdc.c
12
index XXXXXXX..XXXXXXX 100644
13
--- a/hw/display/omap_lcdc.c
14
+++ b/hw/display/omap_lcdc.c
15
@@ -XXX,XX +XXX,XX @@ static void omap_lcd_interrupts(struct omap_lcd_panel_s *s)
16
qemu_irq_lower(s->irq);
17
}
18
19
-#define draw_line_func drawfn
20
-
21
/*
22
* 2-bit colour
23
*/
24
@@ -XXX,XX +XXX,XX @@ static void omap_update_display(void *opaque)
25
{
26
struct omap_lcd_panel_s *omap_lcd = (struct omap_lcd_panel_s *) opaque;
27
DisplaySurface *surface;
28
- draw_line_func draw_line;
29
+ drawfn draw_line;
30
int size, height, first, last;
31
int width, linesize, step, bpp, frame_offset;
32
hwaddr frame_base;
33
--
34
2.20.1
35
36
diff view generated by jsdifflib
New patch
1
For a long time now the UI layer has guaranteed that the console
2
surface is always 32 bits per pixel, RGB. The TCX code already
3
assumes 32bpp, but it still has some checks of is_surface_bgr()
4
in an attempt to support 32bpp BGR. is_surface_bgr() will always
5
return false for the qemu_console_surface(), unless the display
6
device itself has deliberately created an alternate-format
7
surface via a function like qemu_create_displaysurface_from().
1
8
9
Drop the never-used BGR-handling code, and assert that we have
10
a 32-bit surface rather than just doing nothing if it isn't.
11
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
14
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
15
Message-id: 20210215102149.20513-1-peter.maydell@linaro.org
16
---
17
hw/display/tcx.c | 31 ++++++++-----------------------
18
1 file changed, 8 insertions(+), 23 deletions(-)
19
20
diff --git a/hw/display/tcx.c b/hw/display/tcx.c
21
index XXXXXXX..XXXXXXX 100644
22
--- a/hw/display/tcx.c
23
+++ b/hw/display/tcx.c
24
@@ -XXX,XX +XXX,XX @@ static int tcx_check_dirty(TCXState *s, DirtyBitmapSnapshot *snap,
25
26
static void update_palette_entries(TCXState *s, int start, int end)
27
{
28
- DisplaySurface *surface = qemu_console_surface(s->con);
29
int i;
30
31
for (i = start; i < end; i++) {
32
- if (is_surface_bgr(surface)) {
33
- s->palette[i] = rgb_to_pixel32bgr(s->r[i], s->g[i], s->b[i]);
34
- } else {
35
- s->palette[i] = rgb_to_pixel32(s->r[i], s->g[i], s->b[i]);
36
- }
37
+ s->palette[i] = rgb_to_pixel32(s->r[i], s->g[i], s->b[i]);
38
}
39
tcx_set_dirty(s, 0, memory_region_size(&s->vram_mem));
40
}
41
@@ -XXX,XX +XXX,XX @@ static void tcx_draw_cursor32(TCXState *s1, uint8_t *d,
42
}
43
44
/*
45
- XXX Could be much more optimal:
46
- * detect if line/page/whole screen is in 24 bit mode
47
- * if destination is also BGR, use memcpy
48
- */
49
+ * XXX Could be much more optimal:
50
+ * detect if line/page/whole screen is in 24 bit mode
51
+ */
52
static inline void tcx24_draw_line32(TCXState *s1, uint8_t *d,
53
const uint8_t *s, int width,
54
const uint32_t *cplane,
55
const uint32_t *s24)
56
{
57
- DisplaySurface *surface = qemu_console_surface(s1->con);
58
- int x, bgr, r, g, b;
59
+ int x, r, g, b;
60
uint8_t val, *p8;
61
uint32_t *p = (uint32_t *)d;
62
uint32_t dval;
63
- bgr = is_surface_bgr(surface);
64
for(x = 0; x < width; x++, s++, s24++) {
65
if (be32_to_cpu(*cplane) & 0x03000000) {
66
/* 24-bit direct, BGR order */
67
@@ -XXX,XX +XXX,XX @@ static inline void tcx24_draw_line32(TCXState *s1, uint8_t *d,
68
b = *p8++;
69
g = *p8++;
70
r = *p8;
71
- if (bgr)
72
- dval = rgb_to_pixel32bgr(r, g, b);
73
- else
74
- dval = rgb_to_pixel32(r, g, b);
75
+ dval = rgb_to_pixel32(r, g, b);
76
} else {
77
/* 8-bit pseudocolor */
78
val = *s;
79
@@ -XXX,XX +XXX,XX @@ static void tcx_update_display(void *opaque)
80
int y, y_start, dd, ds;
81
uint8_t *d, *s;
82
83
- if (surface_bits_per_pixel(surface) != 32) {
84
- return;
85
- }
86
+ assert(surface_bits_per_pixel(surface) == 32);
87
88
page = 0;
89
y_start = -1;
90
@@ -XXX,XX +XXX,XX @@ static void tcx24_update_display(void *opaque)
91
uint8_t *d, *s;
92
uint32_t *cptr, *s24;
93
94
- if (surface_bits_per_pixel(surface) != 32) {
95
- return;
96
- }
97
+ assert(surface_bits_per_pixel(surface) == 32);
98
99
page = 0;
100
y_start = -1;
101
--
102
2.20.1
103
104
diff view generated by jsdifflib
New patch
1
The AN524 has a different SYSCLK frequency from the AN505 and AN521;
2
make the SYSCLK frequency a field in the MPS2TZMachineClass rather
3
than a compile-time constant so we can support the AN524.
1
4
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20210215115138.20465-2-peter.maydell@linaro.org
9
---
10
hw/arm/mps2-tz.c | 10 ++++++----
11
1 file changed, 6 insertions(+), 4 deletions(-)
12
13
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
14
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/arm/mps2-tz.c
16
+++ b/hw/arm/mps2-tz.c
17
@@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineClass {
18
MachineClass parent;
19
MPS2TZFPGAType fpga_type;
20
uint32_t scc_id;
21
+ uint32_t sysclk_frq; /* Main SYSCLK frequency in Hz */
22
const char *armsse_type;
23
};
24
25
@@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineState {
26
27
OBJECT_DECLARE_TYPE(MPS2TZMachineState, MPS2TZMachineClass, MPS2TZ_MACHINE)
28
29
-/* Main SYSCLK frequency in Hz */
30
-#define SYSCLK_FRQ 20000000
31
/* Slow 32Khz S32KCLK frequency in Hz */
32
#define S32KCLK_FRQ (32 * 1000)
33
34
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_unimp_dev(MPS2TZMachineState *mms,
35
static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
36
const char *name, hwaddr size)
37
{
38
+ MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
39
CMSDKAPBUART *uart = opaque;
40
int i = uart - &mms->uart[0];
41
int rxirqno = i * 2;
42
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
43
44
object_initialize_child(OBJECT(mms), name, uart, TYPE_CMSDK_APB_UART);
45
qdev_prop_set_chr(DEVICE(uart), "chardev", serial_hd(i));
46
- qdev_prop_set_uint32(DEVICE(uart), "pclk-frq", SYSCLK_FRQ);
47
+ qdev_prop_set_uint32(DEVICE(uart), "pclk-frq", mmc->sysclk_frq);
48
sysbus_realize(SYS_BUS_DEVICE(uart), &error_fatal);
49
s = SYS_BUS_DEVICE(uart);
50
sysbus_connect_irq(s, 0, get_sse_irq_in(mms, txirqno));
51
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
52
53
/* These clocks don't need migration because they are fixed-frequency */
54
mms->sysclk = clock_new(OBJECT(machine), "SYSCLK");
55
- clock_set_hz(mms->sysclk, SYSCLK_FRQ);
56
+ clock_set_hz(mms->sysclk, mmc->sysclk_frq);
57
mms->s32kclk = clock_new(OBJECT(machine), "S32KCLK");
58
clock_set_hz(mms->s32kclk, S32KCLK_FRQ);
59
60
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an505_class_init(ObjectClass *oc, void *data)
61
mmc->fpga_type = FPGA_AN505;
62
mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m33");
63
mmc->scc_id = 0x41045050;
64
+ mmc->sysclk_frq = 20 * 1000 * 1000; /* 20MHz */
65
mmc->armsse_type = TYPE_IOTKIT;
66
}
67
68
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an521_class_init(ObjectClass *oc, void *data)
69
mmc->fpga_type = FPGA_AN521;
70
mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m33");
71
mmc->scc_id = 0x41045210;
72
+ mmc->sysclk_frq = 20 * 1000 * 1000; /* 20MHz */
73
mmc->armsse_type = TYPE_SSE200;
74
}
75
76
--
77
2.20.1
78
79
diff view generated by jsdifflib
1
Implement a model of the MPS2 with the AN500 firmware. This is
1
Currently the MPS2 SCC device implements a fixed number of OSCCLK
2
similar to the AN385, with the following differences:
2
values (3). The variant of this device in the MPS3 AN524 board has 6
3
* Cortex-M7 CPU
3
OSCCLK values. Switch to using a PROP_ARRAY, which allows board code
4
* PSRAM is at 0x6000_0000
4
to specify how large the OSCCLK array should be as well as its
5
* Ethernet is at 0xa000_0000
5
values.
6
* No zbt_boot_ctrl remapping of the low 16K
6
7
(but QEMU doesn't implement this anyway)
7
With a variable-length property array, the SCC no longer specifies
8
* no "block RAM" at 0x01000000
8
default values for the OSCCLKs, so we must set them explicitly in the
9
board code. This defaults are actually incorrect for the an521 and
10
an505; we will correct this bug in a following patch.
11
12
This is a migration compatibility break for all the mps boards.
9
13
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
15
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
12
Message-id: 20200903202048.15370-3-peter.maydell@linaro.org
16
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
17
Message-id: 20210215115138.20465-3-peter.maydell@linaro.org
13
---
18
---
14
docs/system/arm/mps2.rst | 6 ++--
19
include/hw/misc/mps2-scc.h | 7 +++----
15
hw/arm/mps2.c | 67 +++++++++++++++++++++++++++++++++-------
20
hw/arm/mps2-tz.c | 5 +++++
16
2 files changed, 60 insertions(+), 13 deletions(-)
21
hw/arm/mps2.c | 5 +++++
22
hw/misc/mps2-scc.c | 24 +++++++++++++-----------
23
4 files changed, 26 insertions(+), 15 deletions(-)
17
24
18
diff --git a/docs/system/arm/mps2.rst b/docs/system/arm/mps2.rst
25
diff --git a/include/hw/misc/mps2-scc.h b/include/hw/misc/mps2-scc.h
19
index XXXXXXX..XXXXXXX 100644
26
index XXXXXXX..XXXXXXX 100644
20
--- a/docs/system/arm/mps2.rst
27
--- a/include/hw/misc/mps2-scc.h
21
+++ b/docs/system/arm/mps2.rst
28
+++ b/include/hw/misc/mps2-scc.h
22
@@ -XXX,XX +XXX,XX @@
29
@@ -XXX,XX +XXX,XX @@
23
-Arm MPS2 boards (``mps2-an385``, ``mps2-an386``, ``mps2-an505``, ``mps2-an511``, ``mps2-an521``)
30
#define TYPE_MPS2_SCC "mps2-scc"
24
-================================================================================================
31
OBJECT_DECLARE_SIMPLE_TYPE(MPS2SCC, MPS2_SCC)
25
+Arm MPS2 boards (``mps2-an385``, ``mps2-an386``, ``mps2-an500``, ``mps2-an505``, ``mps2-an511``, ``mps2-an521``)
32
26
+================================================================================================================
33
-#define NUM_OSCCLK 3
27
34
-
28
These board models all use Arm M-profile CPUs.
35
struct MPS2SCC {
29
36
/*< private >*/
30
@@ -XXX,XX +XXX,XX @@ QEMU models the following FPGA images:
37
SysBusDevice parent_obj;
31
Cortex-M3 as documented in ARM Application Note AN385
38
@@ -XXX,XX +XXX,XX @@ struct MPS2SCC {
32
``mps2-an386``
39
uint32_t dll;
33
Cortex-M4 as documented in ARM Application Note AN386
40
uint32_t aid;
34
+``mps2-an500``
41
uint32_t id;
35
+ Cortex-M7 as documented in ARM Application Note AN500
42
- uint32_t oscclk[NUM_OSCCLK];
36
``mps2-an511``
43
- uint32_t oscclk_reset[NUM_OSCCLK];
37
Cortex-M3 'DesignStart' as documented in AN511
44
+ uint32_t num_oscclk;
38
``mps2-an505``
45
+ uint32_t *oscclk;
46
+ uint32_t *oscclk_reset;
47
};
48
49
#endif
50
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
51
index XXXXXXX..XXXXXXX 100644
52
--- a/hw/arm/mps2-tz.c
53
+++ b/hw/arm/mps2-tz.c
54
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_scc(MPS2TZMachineState *mms, void *opaque,
55
qdev_prop_set_uint32(sccdev, "scc-cfg4", 0x2);
56
qdev_prop_set_uint32(sccdev, "scc-aid", 0x00200008);
57
qdev_prop_set_uint32(sccdev, "scc-id", mmc->scc_id);
58
+ /* This will need to be per-FPGA image eventually */
59
+ qdev_prop_set_uint32(sccdev, "len-oscclk", 3);
60
+ qdev_prop_set_uint32(sccdev, "oscclk[0]", 50000000);
61
+ qdev_prop_set_uint32(sccdev, "oscclk[1]", 24576000);
62
+ qdev_prop_set_uint32(sccdev, "oscclk[2]", 25000000);
63
sysbus_realize(SYS_BUS_DEVICE(scc), &error_fatal);
64
return sysbus_mmio_get_region(SYS_BUS_DEVICE(sccdev), 0);
65
}
39
diff --git a/hw/arm/mps2.c b/hw/arm/mps2.c
66
diff --git a/hw/arm/mps2.c b/hw/arm/mps2.c
40
index XXXXXXX..XXXXXXX 100644
67
index XXXXXXX..XXXXXXX 100644
41
--- a/hw/arm/mps2.c
68
--- a/hw/arm/mps2.c
42
+++ b/hw/arm/mps2.c
69
+++ b/hw/arm/mps2.c
43
@@ -XXX,XX +XXX,XX @@
70
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
44
* We model the following FPGA images:
71
qdev_prop_set_uint32(sccdev, "scc-cfg4", 0x2);
45
* "mps2-an385" -- Cortex-M3 as documented in ARM Application Note AN385
72
qdev_prop_set_uint32(sccdev, "scc-aid", 0x00200008);
46
* "mps2-an386" -- Cortex-M4 as documented in ARM Application Note AN386
73
qdev_prop_set_uint32(sccdev, "scc-id", mmc->scc_id);
47
+ * "mps2-an500" -- Cortex-M7 as documented in ARM Application Note AN500
74
+ /* All these FPGA images have the same OSCCLK configuration */
48
* "mps2-an511" -- Cortex-M3 'DesignStart' as documented in AN511
75
+ qdev_prop_set_uint32(sccdev, "len-oscclk", 3);
49
*
76
+ qdev_prop_set_uint32(sccdev, "oscclk[0]", 50000000);
50
* Links to the TRM for the board itself and to the various Application
77
+ qdev_prop_set_uint32(sccdev, "oscclk[1]", 24576000);
51
@@ -XXX,XX +XXX,XX @@
78
+ qdev_prop_set_uint32(sccdev, "oscclk[2]", 25000000);
52
typedef enum MPS2FPGAType {
79
sysbus_realize(SYS_BUS_DEVICE(&mms->scc), &error_fatal);
53
FPGA_AN385,
80
sysbus_mmio_map(SYS_BUS_DEVICE(sccdev), 0, 0x4002f000);
54
FPGA_AN386,
81
object_initialize_child(OBJECT(mms), "fpgaio",
55
+ FPGA_AN500,
82
diff --git a/hw/misc/mps2-scc.c b/hw/misc/mps2-scc.c
56
FPGA_AN511,
83
index XXXXXXX..XXXXXXX 100644
57
} MPS2FPGAType;
84
--- a/hw/misc/mps2-scc.c
58
85
+++ b/hw/misc/mps2-scc.c
59
@@ -XXX,XX +XXX,XX @@ struct MPS2MachineClass {
86
@@ -XXX,XX +XXX,XX @@ static bool scc_cfg_write(MPS2SCC *s, unsigned function,
60
MachineClass parent;
87
{
61
MPS2FPGAType fpga_type;
88
trace_mps2_scc_cfg_write(function, device, value);
62
uint32_t scc_id;
89
63
+ bool has_block_ram;
90
- if (function != 1 || device >= NUM_OSCCLK) {
64
+ hwaddr ethernet_base;
91
+ if (function != 1 || device >= s->num_oscclk) {
65
+ hwaddr psram_base;
92
qemu_log_mask(LOG_GUEST_ERROR,
93
"MPS2 SCC config write: bad function %d device %d\n",
94
function, device);
95
@@ -XXX,XX +XXX,XX @@ static bool scc_cfg_write(MPS2SCC *s, unsigned function,
96
static bool scc_cfg_read(MPS2SCC *s, unsigned function,
97
unsigned device, uint32_t *value)
98
{
99
- if (function != 1 || device >= NUM_OSCCLK) {
100
+ if (function != 1 || device >= s->num_oscclk) {
101
qemu_log_mask(LOG_GUEST_ERROR,
102
"MPS2 SCC config read: bad function %d device %d\n",
103
function, device);
104
@@ -XXX,XX +XXX,XX @@ static void mps2_scc_reset(DeviceState *dev)
105
s->cfgctrl = 0x100000;
106
s->cfgstat = 0;
107
s->dll = 0xffff0001;
108
- for (i = 0; i < NUM_OSCCLK; i++) {
109
+ for (i = 0; i < s->num_oscclk; i++) {
110
s->oscclk[i] = s->oscclk_reset[i];
111
}
112
for (i = 0; i < ARRAY_SIZE(s->led); i++) {
113
@@ -XXX,XX +XXX,XX @@ static void mps2_scc_realize(DeviceState *dev, Error **errp)
114
LED_COLOR_GREEN, name);
115
g_free(name);
116
}
117
+
118
+ s->oscclk = g_new0(uint32_t, s->num_oscclk);
119
}
120
121
static const VMStateDescription mps2_scc_vmstate = {
122
.name = "mps2-scc",
123
- .version_id = 1,
124
- .minimum_version_id = 1,
125
+ .version_id = 2,
126
+ .minimum_version_id = 2,
127
.fields = (VMStateField[]) {
128
VMSTATE_UINT32(cfg0, MPS2SCC),
129
VMSTATE_UINT32(cfg1, MPS2SCC),
130
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription mps2_scc_vmstate = {
131
VMSTATE_UINT32(cfgctrl, MPS2SCC),
132
VMSTATE_UINT32(cfgstat, MPS2SCC),
133
VMSTATE_UINT32(dll, MPS2SCC),
134
- VMSTATE_UINT32_ARRAY(oscclk, MPS2SCC, NUM_OSCCLK),
135
+ VMSTATE_VARRAY_UINT32(oscclk, MPS2SCC, num_oscclk,
136
+ 0, vmstate_info_uint32, uint32_t),
137
VMSTATE_END_OF_LIST()
138
}
66
};
139
};
67
typedef struct MPS2MachineClass MPS2MachineClass;
140
@@ -XXX,XX +XXX,XX @@ static Property mps2_scc_properties[] = {
68
141
DEFINE_PROP_UINT32("scc-cfg4", MPS2SCC, cfg4, 0),
69
@@ -XXX,XX +XXX,XX @@ typedef struct MPS2MachineState MPS2MachineState;
142
DEFINE_PROP_UINT32("scc-aid", MPS2SCC, aid, 0),
70
#define TYPE_MPS2_MACHINE "mps2"
143
DEFINE_PROP_UINT32("scc-id", MPS2SCC, id, 0),
71
#define TYPE_MPS2_AN385_MACHINE MACHINE_TYPE_NAME("mps2-an385")
144
- /* These are the initial settings for the source clocks on the board.
72
#define TYPE_MPS2_AN386_MACHINE MACHINE_TYPE_NAME("mps2-an386")
145
+ /*
73
+#define TYPE_MPS2_AN500_MACHINE MACHINE_TYPE_NAME("mps2-an500")
146
+ * These are the initial settings for the source clocks on the board.
74
#define TYPE_MPS2_AN511_MACHINE MACHINE_TYPE_NAME("mps2-an511")
147
* In hardware they can be configured via a config file read by the
75
148
* motherboard configuration controller to suit the FPGA image.
76
DECLARE_OBJ_CHECKERS(MPS2MachineState, MPS2MachineClass,
149
- * These default values are used by most of the standard FPGA images.
77
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
78
*
79
* AN385/AN386/AN511:
80
* 0x21000000 .. 0x21ffffff : PSRAM (16MB)
81
- * AN385/AN386 only:
82
+ * AN385/AN386/AN500:
83
* 0x00000000 .. 0x003fffff : ZBT SSRAM1
84
* 0x00400000 .. 0x007fffff : mirror of ZBT SSRAM1
85
* 0x20000000 .. 0x203fffff : ZBT SSRAM 2&3
86
* 0x20400000 .. 0x207fffff : mirror of ZBT SSRAM 2&3
87
+ * AN385/AN386 only:
88
* 0x01000000 .. 0x01003fff : block RAM (16K)
89
* 0x01004000 .. 0x01007fff : mirror of above
90
* 0x01008000 .. 0x0100bfff : mirror of above
91
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
92
* 0x00400000 .. 0x007fffff : ZBT SSRAM1
93
* 0x20000000 .. 0x2001ffff : SRAM
94
* 0x20400000 .. 0x207fffff : ZBT SSRAM 2&3
95
+ * AN500 only:
96
+ * 0x60000000 .. 0x60ffffff : PSRAM (16MB)
97
*
98
* The AN385/AN386 has a feature where the lowest 16K can be mapped
99
* either to the bottom of the ZBT SSRAM1 or to the block RAM.
100
* This is of no use for QEMU so we don't implement it (as if
101
* zbt_boot_ctrl is always zero).
102
*/
150
*/
103
- memory_region_add_subregion(system_memory, 0x21000000, machine->ram);
151
- DEFINE_PROP_UINT32("oscclk0", MPS2SCC, oscclk_reset[0], 50000000),
104
+ memory_region_add_subregion(system_memory, mmc->psram_base, machine->ram);
152
- DEFINE_PROP_UINT32("oscclk1", MPS2SCC, oscclk_reset[1], 24576000),
105
153
- DEFINE_PROP_UINT32("oscclk2", MPS2SCC, oscclk_reset[2], 25000000),
106
- switch (mmc->fpga_type) {
154
+ DEFINE_PROP_ARRAY("oscclk", MPS2SCC, num_oscclk, oscclk_reset,
107
- case FPGA_AN385:
155
+ qdev_prop_uint32, uint32_t),
108
- case FPGA_AN386:
156
DEFINE_PROP_END_OF_LIST(),
109
- make_ram(&mms->ssram1, "mps.ssram1", 0x0, 0x400000);
110
- make_ram_alias(&mms->ssram1_m, "mps.ssram1_m", &mms->ssram1, 0x400000);
111
- make_ram(&mms->ssram23, "mps.ssram23", 0x20000000, 0x400000);
112
- make_ram_alias(&mms->ssram23_m, "mps.ssram23_m",
113
- &mms->ssram23, 0x20400000);
114
+ if (mmc->has_block_ram) {
115
make_ram(&mms->blockram, "mps.blockram", 0x01000000, 0x4000);
116
make_ram_alias(&mms->blockram_m1, "mps.blockram_m1",
117
&mms->blockram, 0x01004000);
118
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
119
&mms->blockram, 0x01008000);
120
make_ram_alias(&mms->blockram_m3, "mps.blockram_m3",
121
&mms->blockram, 0x0100c000);
122
+ }
123
+
124
+ switch (mmc->fpga_type) {
125
+ case FPGA_AN385:
126
+ case FPGA_AN386:
127
+ case FPGA_AN500:
128
+ make_ram(&mms->ssram1, "mps.ssram1", 0x0, 0x400000);
129
+ make_ram_alias(&mms->ssram1_m, "mps.ssram1_m", &mms->ssram1, 0x400000);
130
+ make_ram(&mms->ssram23, "mps.ssram23", 0x20000000, 0x400000);
131
+ make_ram_alias(&mms->ssram23_m, "mps.ssram23_m",
132
+ &mms->ssram23, 0x20400000);
133
break;
134
case FPGA_AN511:
135
make_ram(&mms->blockram, "mps.blockram", 0x0, 0x40000);
136
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
137
switch (mmc->fpga_type) {
138
case FPGA_AN385:
139
case FPGA_AN386:
140
+ case FPGA_AN500:
141
qdev_prop_set_uint32(armv7m, "num-irq", 32);
142
break;
143
case FPGA_AN511:
144
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
145
switch (mmc->fpga_type) {
146
case FPGA_AN385:
147
case FPGA_AN386:
148
+ case FPGA_AN500:
149
{
150
/* The overflow IRQs for UARTs 0, 1 and 2 are ORed together.
151
* Overflow for UARTs 4 and 5 doesn't trigger any interrupt.
152
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
153
/* In hardware this is a LAN9220; the LAN9118 is software compatible
154
* except that it doesn't support the checksum-offload feature.
155
*/
156
- lan9118_init(&nd_table[0], 0x40200000,
157
+ lan9118_init(&nd_table[0], mmc->ethernet_base,
158
qdev_get_gpio_in(armv7m,
159
mmc->fpga_type == FPGA_AN511 ? 47 : 13));
160
161
@@ -XXX,XX +XXX,XX @@ static void mps2_an385_class_init(ObjectClass *oc, void *data)
162
mmc->fpga_type = FPGA_AN385;
163
mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m3");
164
mmc->scc_id = 0x41043850;
165
+ mmc->psram_base = 0x21000000;
166
+ mmc->ethernet_base = 0x40200000;
167
+ mmc->has_block_ram = true;
168
}
169
170
static void mps2_an386_class_init(ObjectClass *oc, void *data)
171
@@ -XXX,XX +XXX,XX @@ static void mps2_an386_class_init(ObjectClass *oc, void *data)
172
mmc->fpga_type = FPGA_AN386;
173
mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m4");
174
mmc->scc_id = 0x41043860;
175
+ mmc->psram_base = 0x21000000;
176
+ mmc->ethernet_base = 0x40200000;
177
+ mmc->has_block_ram = true;
178
+}
179
+
180
+static void mps2_an500_class_init(ObjectClass *oc, void *data)
181
+{
182
+ MachineClass *mc = MACHINE_CLASS(oc);
183
+ MPS2MachineClass *mmc = MPS2_MACHINE_CLASS(oc);
184
+
185
+ mc->desc = "ARM MPS2 with AN500 FPGA image for Cortex-M7";
186
+ mmc->fpga_type = FPGA_AN500;
187
+ mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m7");
188
+ mmc->scc_id = 0x41045000;
189
+ mmc->psram_base = 0x60000000;
190
+ mmc->ethernet_base = 0xa0000000;
191
+ mmc->has_block_ram = false;
192
}
193
194
static void mps2_an511_class_init(ObjectClass *oc, void *data)
195
@@ -XXX,XX +XXX,XX @@ static void mps2_an511_class_init(ObjectClass *oc, void *data)
196
mmc->fpga_type = FPGA_AN511;
197
mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m3");
198
mmc->scc_id = 0x41045110;
199
+ mmc->psram_base = 0x21000000;
200
+ mmc->ethernet_base = 0x40200000;
201
+ mmc->has_block_ram = false;
202
}
203
204
static const TypeInfo mps2_info = {
205
@@ -XXX,XX +XXX,XX @@ static const TypeInfo mps2_an386_info = {
206
.class_init = mps2_an386_class_init,
207
};
157
};
208
209
+static const TypeInfo mps2_an500_info = {
210
+ .name = TYPE_MPS2_AN500_MACHINE,
211
+ .parent = TYPE_MPS2_MACHINE,
212
+ .class_init = mps2_an500_class_init,
213
+};
214
+
215
static const TypeInfo mps2_an511_info = {
216
.name = TYPE_MPS2_AN511_MACHINE,
217
.parent = TYPE_MPS2_MACHINE,
218
@@ -XXX,XX +XXX,XX @@ static void mps2_machine_init(void)
219
type_register_static(&mps2_info);
220
type_register_static(&mps2_an385_info);
221
type_register_static(&mps2_an386_info);
222
+ type_register_static(&mps2_an500_info);
223
type_register_static(&mps2_an511_info);
224
}
225
158
226
--
159
--
227
2.20.1
160
2.20.1
228
161
229
162
diff view generated by jsdifflib
New patch
1
We were previously using the default OSCCLK settings, which are
2
correct for the older MPS2 boards (mps2-an385, mps2-an386,
3
mps2-an500, mps2-an511), but wrong for the mps2-an505 and mps2-511
4
implemented in mps2-tz.c. Now we're setting the values explicitly we
5
can fix them to be correct.
1
6
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
Message-id: 20210215115138.20465-4-peter.maydell@linaro.org
11
---
12
hw/arm/mps2-tz.c | 4 ++--
13
1 file changed, 2 insertions(+), 2 deletions(-)
14
15
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/hw/arm/mps2-tz.c
18
+++ b/hw/arm/mps2-tz.c
19
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_scc(MPS2TZMachineState *mms, void *opaque,
20
qdev_prop_set_uint32(sccdev, "scc-id", mmc->scc_id);
21
/* This will need to be per-FPGA image eventually */
22
qdev_prop_set_uint32(sccdev, "len-oscclk", 3);
23
- qdev_prop_set_uint32(sccdev, "oscclk[0]", 50000000);
24
- qdev_prop_set_uint32(sccdev, "oscclk[1]", 24576000);
25
+ qdev_prop_set_uint32(sccdev, "oscclk[0]", 40000000);
26
+ qdev_prop_set_uint32(sccdev, "oscclk[1]", 24580000);
27
qdev_prop_set_uint32(sccdev, "oscclk[2]", 25000000);
28
sysbus_realize(SYS_BUS_DEVICE(scc), &error_fatal);
29
return sysbus_mmio_get_region(SYS_BUS_DEVICE(sccdev), 0);
30
--
31
2.20.1
32
33
diff view generated by jsdifflib
New patch
1
The AN505 and AN511 happen to share the same OSCCLK values, but the
2
AN524 will have a different set (and more of them), so split the
3
settings out to be per-board.
1
4
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20210215115138.20465-5-peter.maydell@linaro.org
9
---
10
hw/arm/mps2-tz.c | 23 ++++++++++++++++++-----
11
1 file changed, 18 insertions(+), 5 deletions(-)
12
13
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
14
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/arm/mps2-tz.c
16
+++ b/hw/arm/mps2-tz.c
17
@@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineClass {
18
MPS2TZFPGAType fpga_type;
19
uint32_t scc_id;
20
uint32_t sysclk_frq; /* Main SYSCLK frequency in Hz */
21
+ uint32_t len_oscclk;
22
+ const uint32_t *oscclk;
23
const char *armsse_type;
24
};
25
26
@@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_TYPE(MPS2TZMachineState, MPS2TZMachineClass, MPS2TZ_MACHINE)
27
/* Slow 32Khz S32KCLK frequency in Hz */
28
#define S32KCLK_FRQ (32 * 1000)
29
30
+static const uint32_t an505_oscclk[] = {
31
+ 40000000,
32
+ 24580000,
33
+ 25000000,
34
+};
35
+
36
/* Create an alias of an entire original MemoryRegion @orig
37
* located at @base in the memory map.
38
*/
39
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_scc(MPS2TZMachineState *mms, void *opaque,
40
MPS2SCC *scc = opaque;
41
DeviceState *sccdev;
42
MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
43
+ uint32_t i;
44
45
object_initialize_child(OBJECT(mms), "scc", scc, TYPE_MPS2_SCC);
46
sccdev = DEVICE(scc);
47
qdev_prop_set_uint32(sccdev, "scc-cfg4", 0x2);
48
qdev_prop_set_uint32(sccdev, "scc-aid", 0x00200008);
49
qdev_prop_set_uint32(sccdev, "scc-id", mmc->scc_id);
50
- /* This will need to be per-FPGA image eventually */
51
- qdev_prop_set_uint32(sccdev, "len-oscclk", 3);
52
- qdev_prop_set_uint32(sccdev, "oscclk[0]", 40000000);
53
- qdev_prop_set_uint32(sccdev, "oscclk[1]", 24580000);
54
- qdev_prop_set_uint32(sccdev, "oscclk[2]", 25000000);
55
+ qdev_prop_set_uint32(sccdev, "len-oscclk", mmc->len_oscclk);
56
+ for (i = 0; i < mmc->len_oscclk; i++) {
57
+ g_autofree char *propname = g_strdup_printf("oscclk[%u]", i);
58
+ qdev_prop_set_uint32(sccdev, propname, mmc->oscclk[i]);
59
+ }
60
sysbus_realize(SYS_BUS_DEVICE(scc), &error_fatal);
61
return sysbus_mmio_get_region(SYS_BUS_DEVICE(sccdev), 0);
62
}
63
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an505_class_init(ObjectClass *oc, void *data)
64
mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m33");
65
mmc->scc_id = 0x41045050;
66
mmc->sysclk_frq = 20 * 1000 * 1000; /* 20MHz */
67
+ mmc->oscclk = an505_oscclk;
68
+ mmc->len_oscclk = ARRAY_SIZE(an505_oscclk);
69
mmc->armsse_type = TYPE_IOTKIT;
70
}
71
72
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an521_class_init(ObjectClass *oc, void *data)
73
mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m33");
74
mmc->scc_id = 0x41045210;
75
mmc->sysclk_frq = 20 * 1000 * 1000; /* 20MHz */
76
+ mmc->oscclk = an505_oscclk; /* AN521 is the same as AN505 here */
77
+ mmc->len_oscclk = ARRAY_SIZE(an505_oscclk);
78
mmc->armsse_type = TYPE_SSE200;
79
}
80
81
--
82
2.20.1
83
84
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
The MPS2 board has 2 LEDs, but the MPS3 board has 10 LEDs. The
2
FPGAIO device is similar on both sets of boards, but the LED0
3
register has correspondingly more bits that have an effect. Add a
4
device property for number of LEDs.
2
5
3
Per the datasheet (DDI0407 r2p0):
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Message-id: 20210215115138.20465-6-peter.maydell@linaro.org
10
---
11
include/hw/misc/mps2-fpgaio.h | 5 ++++-
12
hw/misc/mps2-fpgaio.c | 31 +++++++++++++++++++++++--------
13
2 files changed, 27 insertions(+), 9 deletions(-)
4
14
5
"The SCU connects one to four Cortex-A9 processors to
15
diff --git a/include/hw/misc/mps2-fpgaio.h b/include/hw/misc/mps2-fpgaio.h
6
the memory system through the AXI interfaces."
7
8
Change the instance_init() handler to a device_realize()
9
one so we can verify the property is in range, and return
10
an error to the caller if not.
11
12
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
13
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
14
Message-id: 20200901144100.116742-2-f4bug@amsat.org
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
---
17
hw/misc/a9scu.c | 18 +++++++++++++-----
18
1 file changed, 13 insertions(+), 5 deletions(-)
19
20
diff --git a/hw/misc/a9scu.c b/hw/misc/a9scu.c
21
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
22
--- a/hw/misc/a9scu.c
17
--- a/include/hw/misc/mps2-fpgaio.h
23
+++ b/hw/misc/a9scu.c
18
+++ b/include/hw/misc/mps2-fpgaio.h
24
@@ -XXX,XX +XXX,XX @@
19
@@ -XXX,XX +XXX,XX @@
25
#include "hw/misc/a9scu.h"
20
#define TYPE_MPS2_FPGAIO "mps2-fpgaio"
26
#include "hw/qdev-properties.h"
21
OBJECT_DECLARE_SIMPLE_TYPE(MPS2FPGAIO, MPS2_FPGAIO)
27
#include "migration/vmstate.h"
22
28
+#include "qapi/error.h"
23
+#define MPS2FPGAIO_MAX_LEDS 32
29
#include "qemu/module.h"
30
31
+#define A9_SCU_CPU_MAX 4
32
+
24
+
33
static uint64_t a9_scu_read(void *opaque, hwaddr offset,
25
struct MPS2FPGAIO {
34
unsigned size)
26
/*< private >*/
27
SysBusDevice parent_obj;
28
29
/*< public >*/
30
MemoryRegion iomem;
31
- LEDState *led[2];
32
+ LEDState *led[MPS2FPGAIO_MAX_LEDS];
33
+ uint32_t num_leds;
34
35
uint32_t led0;
36
uint32_t prescale;
37
diff --git a/hw/misc/mps2-fpgaio.c b/hw/misc/mps2-fpgaio.c
38
index XXXXXXX..XXXXXXX 100644
39
--- a/hw/misc/mps2-fpgaio.c
40
+++ b/hw/misc/mps2-fpgaio.c
41
@@ -XXX,XX +XXX,XX @@ static void mps2_fpgaio_write(void *opaque, hwaddr offset, uint64_t value,
42
43
switch (offset) {
44
case A_LED0:
45
- s->led0 = value & 0x3;
46
- led_set_state(s->led[0], value & 0x01);
47
- led_set_state(s->led[1], value & 0x02);
48
+ if (s->num_leds != 0) {
49
+ uint32_t i;
50
+
51
+ s->led0 = value & MAKE_64BIT_MASK(0, s->num_leds);
52
+ for (i = 0; i < s->num_leds; i++) {
53
+ led_set_state(s->led[i], value & (1 << i));
54
+ }
55
+ }
56
break;
57
case A_PRESCALE:
58
resync_counter(s);
59
@@ -XXX,XX +XXX,XX @@ static void mps2_fpgaio_reset(DeviceState *dev)
60
s->pscntr = 0;
61
s->pscntr_sync_ticks = now;
62
63
- for (size_t i = 0; i < ARRAY_SIZE(s->led); i++) {
64
+ for (size_t i = 0; i < s->num_leds; i++) {
65
device_cold_reset(DEVICE(s->led[i]));
66
}
67
}
68
@@ -XXX,XX +XXX,XX @@ static void mps2_fpgaio_init(Object *obj)
69
static void mps2_fpgaio_realize(DeviceState *dev, Error **errp)
35
{
70
{
36
@@ -XXX,XX +XXX,XX @@ static void a9_scu_reset(DeviceState *dev)
71
MPS2FPGAIO *s = MPS2_FPGAIO(dev);
37
s->control = 0;
72
+ uint32_t i;
38
}
73
39
74
- s->led[0] = led_create_simple(OBJECT(dev), GPIO_POLARITY_ACTIVE_HIGH,
40
-static void a9_scu_init(Object *obj)
75
- LED_COLOR_GREEN, "USERLED0");
41
+static void a9_scu_realize(DeviceState *dev, Error **errp)
76
- s->led[1] = led_create_simple(OBJECT(dev), GPIO_POLARITY_ACTIVE_HIGH,
42
{
77
- LED_COLOR_GREEN, "USERLED1");
43
- A9SCUState *s = A9_SCU(obj);
78
+ if (s->num_leds > MPS2FPGAIO_MAX_LEDS) {
44
- SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
79
+ error_setg(errp, "num-leds cannot be greater than %d",
45
+ A9SCUState *s = A9_SCU(dev);
80
+ MPS2FPGAIO_MAX_LEDS);
46
+ SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
47
48
- memory_region_init_io(&s->iomem, obj, &a9_scu_ops, s,
49
+ if (!s->num_cpu || s->num_cpu > A9_SCU_CPU_MAX) {
50
+ error_setg(errp, "Illegal CPU count: %u", s->num_cpu);
51
+ return;
81
+ return;
52
+ }
82
+ }
53
+
83
+
54
+ memory_region_init_io(&s->iomem, OBJECT(s), &a9_scu_ops, s,
84
+ for (i = 0; i < s->num_leds; i++) {
55
"a9-scu", 0x100);
85
+ g_autofree char *ledname = g_strdup_printf("USERLED%d", i);
56
sysbus_init_mmio(sbd, &s->iomem);
86
+ s->led[i] = led_create_simple(OBJECT(dev), GPIO_POLARITY_ACTIVE_HIGH,
87
+ LED_COLOR_GREEN, ledname);
88
+ }
57
}
89
}
58
@@ -XXX,XX +XXX,XX @@ static void a9_scu_class_init(ObjectClass *klass, void *data)
90
59
device_class_set_props(dc, a9_scu_properties);
91
static bool mps2_fpgaio_counters_needed(void *opaque)
60
dc->vmsd = &vmstate_a9_scu;
92
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription mps2_fpgaio_vmstate = {
61
dc->reset = a9_scu_reset;
93
static Property mps2_fpgaio_properties[] = {
62
+ dc->realize = a9_scu_realize;
94
/* Frequency of the prescale counter */
63
}
95
DEFINE_PROP_UINT32("prescale-clk", MPS2FPGAIO, prescale_clk, 20000000),
64
96
+ /* Number of LEDs controlled by LED0 register */
65
static const TypeInfo a9_scu_info = {
97
+ DEFINE_PROP_UINT32("num-leds", MPS2FPGAIO, num_leds, 2),
66
.name = TYPE_A9_SCU,
98
DEFINE_PROP_END_OF_LIST(),
67
.parent = TYPE_SYS_BUS_DEVICE,
68
.instance_size = sizeof(A9SCUState),
69
- .instance_init = a9_scu_init,
70
.class_init = a9_scu_class_init,
71
};
99
};
72
100
73
--
101
--
74
2.20.1
102
2.20.1
75
103
76
104
diff view generated by jsdifflib
1
Deprecate our lm32 target support. Michael Walle (former lm32 maintainer)
1
MPS3 boards have an extra SWITCH register in the FPGAIO block which
2
suggested that we do this in 2019:
2
reports the value of some switches. Implement this, governed by a
3
https://www.mail-archive.com/qemu-devel@nongnu.org/msg605024.html
3
property the board code can use to specify whether whether it exists.
4
because the only public user of the architecture is the many-years-dead
5
milkymist project. (The Linux port to lm32 was never merged upstream.)
6
7
In commit 4b4d96c776f552e (March 2020) we marked it as 'orphan' in
8
the MAINTAINERS file, but didn't officially deprecate it. Mark it
9
deprecated now, with the intention of removing it from QEMU in
10
mid-2021 before the 6.1 release.
11
4
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
14
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
15
Reviewed-by: Thomas Huth <thuth@redhat.com>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
16
Acked-by: Michael Walle <michael@walle.cc>
8
Message-id: 20210215115138.20465-7-peter.maydell@linaro.org
17
Message-id: 20200827113259.25064-1-peter.maydell@linaro.org
18
---
9
---
19
docs/system/deprecated.rst | 8 ++++++++
10
include/hw/misc/mps2-fpgaio.h | 1 +
20
1 file changed, 8 insertions(+)
11
hw/misc/mps2-fpgaio.c | 10 ++++++++++
12
2 files changed, 11 insertions(+)
21
13
22
diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
14
diff --git a/include/hw/misc/mps2-fpgaio.h b/include/hw/misc/mps2-fpgaio.h
23
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
24
--- a/docs/system/deprecated.rst
16
--- a/include/hw/misc/mps2-fpgaio.h
25
+++ b/docs/system/deprecated.rst
17
+++ b/include/hw/misc/mps2-fpgaio.h
26
@@ -XXX,XX +XXX,XX @@ The above, converted to the current supported format::
18
@@ -XXX,XX +XXX,XX @@ struct MPS2FPGAIO {
27
linux-user mode CPUs
19
MemoryRegion iomem;
28
--------------------
20
LEDState *led[MPS2FPGAIO_MAX_LEDS];
29
21
uint32_t num_leds;
30
+``lm32`` CPUs (since 5.2.0)
22
+ bool has_switches;
31
+'''''''''''''''''''''''''''
23
32
+
24
uint32_t led0;
33
+The ``lm32`` guest CPU support is deprecated and will be removed in
25
uint32_t prescale;
34
+a future version of QEMU. The only public user of this architecture
26
diff --git a/hw/misc/mps2-fpgaio.c b/hw/misc/mps2-fpgaio.c
35
+was the milkymist project, which has been dead for years; there was
27
index XXXXXXX..XXXXXXX 100644
36
+never an upstream Linux port.
28
--- a/hw/misc/mps2-fpgaio.c
37
+
29
+++ b/hw/misc/mps2-fpgaio.c
38
``unicore32`` CPUs (since 5.2.0)
30
@@ -XXX,XX +XXX,XX @@ REG32(CLK100HZ, 0x14)
39
''''''''''''''''''''''''''''''''
31
REG32(COUNTER, 0x18)
32
REG32(PRESCALE, 0x1c)
33
REG32(PSCNTR, 0x20)
34
+REG32(SWITCH, 0x28)
35
REG32(MISC, 0x4c)
36
37
static uint32_t counter_from_tickoff(int64_t now, int64_t tick_offset, int frq)
38
@@ -XXX,XX +XXX,XX @@ static uint64_t mps2_fpgaio_read(void *opaque, hwaddr offset, unsigned size)
39
resync_counter(s);
40
r = s->pscntr;
41
break;
42
+ case A_SWITCH:
43
+ if (!s->has_switches) {
44
+ goto bad_offset;
45
+ }
46
+ /* User-togglable board switches. We don't model that, so report 0. */
47
+ r = 0;
48
+ break;
49
default:
50
+ bad_offset:
51
qemu_log_mask(LOG_GUEST_ERROR,
52
"MPS2 FPGAIO read: bad offset %x\n", (int) offset);
53
r = 0;
54
@@ -XXX,XX +XXX,XX @@ static Property mps2_fpgaio_properties[] = {
55
DEFINE_PROP_UINT32("prescale-clk", MPS2FPGAIO, prescale_clk, 20000000),
56
/* Number of LEDs controlled by LED0 register */
57
DEFINE_PROP_UINT32("num-leds", MPS2FPGAIO, num_leds, 2),
58
+ DEFINE_PROP_BOOL("has-switches", MPS2FPGAIO, has_switches, false),
59
DEFINE_PROP_END_OF_LIST(),
60
};
40
61
41
--
62
--
42
2.20.1
63
2.20.1
43
64
44
65
diff view generated by jsdifflib
1
Make the list of MPS2 boards consistent in the phrasing of each
1
Set the FPGAIO num-leds and have-switches properties explicitly
2
entry, use the correct casing of "Arm", and move the mps2-an511
2
per-board, rather than relying on the defaults. The AN505 and AN521
3
entry so the list is in numeric order.
3
both have the same settings as the default values, but the AN524 will
4
be different.
4
5
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Message-id: 20200903202048.15370-4-peter.maydell@linaro.org
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Message-id: 20210215115138.20465-8-peter.maydell@linaro.org
8
---
10
---
9
docs/system/arm/mps2.rst | 14 +++++++-------
11
hw/arm/mps2-tz.c | 9 +++++++++
10
1 file changed, 7 insertions(+), 7 deletions(-)
12
1 file changed, 9 insertions(+)
11
13
12
diff --git a/docs/system/arm/mps2.rst b/docs/system/arm/mps2.rst
14
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
13
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
14
--- a/docs/system/arm/mps2.rst
16
--- a/hw/arm/mps2-tz.c
15
+++ b/docs/system/arm/mps2.rst
17
+++ b/hw/arm/mps2-tz.c
16
@@ -XXX,XX +XXX,XX @@ as seen by the guest depend significantly on the FPGA image.
18
@@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineClass {
17
QEMU models the following FPGA images:
19
uint32_t sysclk_frq; /* Main SYSCLK frequency in Hz */
18
20
uint32_t len_oscclk;
19
``mps2-an385``
21
const uint32_t *oscclk;
20
- Cortex-M3 as documented in ARM Application Note AN385
22
+ uint32_t fpgaio_num_leds; /* Number of LEDs in FPGAIO LED0 register */
21
+ Cortex-M3 as documented in Arm Application Note AN385
23
+ bool fpgaio_has_switches; /* Does FPGAIO have SWITCH register? */
22
``mps2-an386``
24
const char *armsse_type;
23
- Cortex-M4 as documented in ARM Application Note AN386
25
};
24
+ Cortex-M4 as documented in Arm Application Note AN386
26
25
``mps2-an500``
27
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_fpgaio(MPS2TZMachineState *mms, void *opaque,
26
- Cortex-M7 as documented in ARM Application Note AN500
28
const char *name, hwaddr size)
27
-``mps2-an511``
29
{
28
- Cortex-M3 'DesignStart' as documented in AN511
30
MPS2FPGAIO *fpgaio = opaque;
29
+ Cortex-M7 as documented in Arm Application Note AN500
31
+ MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
30
``mps2-an505``
32
31
- Cortex-M33 as documented in ARM Application Note AN505
33
object_initialize_child(OBJECT(mms), "fpgaio", fpgaio, TYPE_MPS2_FPGAIO);
32
+ Cortex-M33 as documented in Arm Application Note AN505
34
+ qdev_prop_set_uint32(DEVICE(fpgaio), "num-leds", mmc->fpgaio_num_leds);
33
+``mps2-an511``
35
+ qdev_prop_set_bit(DEVICE(fpgaio), "has-switches", mmc->fpgaio_has_switches);
34
+ Cortex-M3 'DesignStart' as documented in Arm Application Note AN511
36
sysbus_realize(SYS_BUS_DEVICE(fpgaio), &error_fatal);
35
``mps2-an521``
37
return sysbus_mmio_get_region(SYS_BUS_DEVICE(fpgaio), 0);
36
- Dual Cortex-M33 as documented in Application Note AN521
38
}
37
+ Dual Cortex-M33 as documented in Arm Application Note AN521
39
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an505_class_init(ObjectClass *oc, void *data)
38
40
mmc->sysclk_frq = 20 * 1000 * 1000; /* 20MHz */
39
Differences between QEMU and real hardware:
41
mmc->oscclk = an505_oscclk;
42
mmc->len_oscclk = ARRAY_SIZE(an505_oscclk);
43
+ mmc->fpgaio_num_leds = 2;
44
+ mmc->fpgaio_has_switches = false;
45
mmc->armsse_type = TYPE_IOTKIT;
46
}
47
48
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an521_class_init(ObjectClass *oc, void *data)
49
mmc->sysclk_frq = 20 * 1000 * 1000; /* 20MHz */
50
mmc->oscclk = an505_oscclk; /* AN521 is the same as AN505 here */
51
mmc->len_oscclk = ARRAY_SIZE(an505_oscclk);
52
+ mmc->fpgaio_num_leds = 2;
53
+ mmc->fpgaio_has_switches = false;
54
mmc->armsse_type = TYPE_SSE200;
55
}
40
56
41
--
57
--
42
2.20.1
58
2.20.1
43
59
44
60
diff view generated by jsdifflib
New patch
1
In the mps2-tz board code, we handle devices whose interrupt lines
2
must be wired to all CPUs by creating IRQ splitter devices for the
3
AN521, because it has 2 CPUs, but wiring the device IRQ directly to
4
the SSE/IoTKit input for the AN505, which has only 1 CPU.
1
5
6
We can avoid making an explicit check on the board type constant by
7
instead creating and using the IRQ splitters for any board with more
8
than 1 CPU. This avoids having to add extra cases to the
9
conditionals every time we add new boards.
10
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
13
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
14
Message-id: 20210215115138.20465-9-peter.maydell@linaro.org
15
---
16
hw/arm/mps2-tz.c | 19 +++++++++----------
17
1 file changed, 9 insertions(+), 10 deletions(-)
18
19
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
20
index XXXXXXX..XXXXXXX 100644
21
--- a/hw/arm/mps2-tz.c
22
+++ b/hw/arm/mps2-tz.c
23
@@ -XXX,XX +XXX,XX @@ static void make_ram_alias(MemoryRegion *mr, const char *name,
24
static qemu_irq get_sse_irq_in(MPS2TZMachineState *mms, int irqno)
25
{
26
/* Return a qemu_irq which will signal IRQ n to all CPUs in the SSE. */
27
- MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
28
+ MachineClass *mc = MACHINE_GET_CLASS(mms);
29
30
assert(irqno < MPS2TZ_NUMIRQ);
31
32
- switch (mmc->fpga_type) {
33
- case FPGA_AN505:
34
- return qdev_get_gpio_in_named(DEVICE(&mms->iotkit), "EXP_IRQ", irqno);
35
- case FPGA_AN521:
36
+ if (mc->max_cpus > 1) {
37
return qdev_get_gpio_in(DEVICE(&mms->cpu_irq_splitter[irqno]), 0);
38
- default:
39
- g_assert_not_reached();
40
+ } else {
41
+ return qdev_get_gpio_in_named(DEVICE(&mms->iotkit), "EXP_IRQ", irqno);
42
}
43
}
44
45
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
46
sysbus_realize(SYS_BUS_DEVICE(&mms->iotkit), &error_fatal);
47
48
/*
49
- * The AN521 needs us to create splitters to feed the IRQ inputs
50
- * for each CPU in the SSE-200 from each device in the board.
51
+ * If this board has more than one CPU, then we need to create splitters
52
+ * to feed the IRQ inputs for each CPU in the SSE from each device in the
53
+ * board. If there is only one CPU, we can just wire the device IRQ
54
+ * directly to the SSE's IRQ input.
55
*/
56
- if (mmc->fpga_type == FPGA_AN521) {
57
+ if (mc->max_cpus > 1) {
58
for (i = 0; i < MPS2TZ_NUMIRQ; i++) {
59
char *name = g_strdup_printf("mps2-irq-splitter%d", i);
60
SplitIRQ *splitter = &mms->cpu_irq_splitter[i];
61
--
62
2.20.1
63
64
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
The AN524 has more interrupt lines than the AN505 and AN521; make
2
numirq board-specific rather than a compile-time constant.
2
3
3
If a -bios option is specified on the command line, load the image into
4
Since the difference is small (92 on the current boards and 95 on the
4
the internal ROM memory region, which contains the first instructions
5
new one) we don't dynamically allocate the cpu_irq_splitter[] array
5
run by the CPU after reset.
6
but leave it as a fixed length array whose size is the maximum needed
7
for any of the boards.
6
8
7
If -bios is not specified, the vbootrom included with qemu is loaded by
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
default.
10
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Message-id: 20210215115138.20465-10-peter.maydell@linaro.org
13
---
14
hw/arm/mps2-tz.c | 15 ++++++++++-----
15
1 file changed, 10 insertions(+), 5 deletions(-)
9
16
10
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
17
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
11
Reviewed-by: Cédric Le Goater <clg@kaod.org>
12
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
13
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
14
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
15
Message-id: 20200911052101.2602693-8-hskinnemoen@google.com
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
---
18
hw/arm/npcm7xx_boards.c | 32 ++++++++++++++++++++++++++++++++
19
1 file changed, 32 insertions(+)
20
21
diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c
22
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
23
--- a/hw/arm/npcm7xx_boards.c
19
--- a/hw/arm/mps2-tz.c
24
+++ b/hw/arm/npcm7xx_boards.c
20
+++ b/hw/arm/mps2-tz.c
25
@@ -XXX,XX +XXX,XX @@
21
@@ -XXX,XX +XXX,XX @@
26
#include "exec/address-spaces.h"
22
#include "hw/qdev-clock.h"
27
#include "hw/arm/npcm7xx.h"
23
#include "qom/object.h"
28
#include "hw/core/cpu.h"
24
29
+#include "hw/loader.h"
25
-#define MPS2TZ_NUMIRQ 92
30
#include "qapi/error.h"
26
+#define MPS2TZ_NUMIRQ_MAX 92
31
+#include "qemu-common.h"
27
32
#include "qemu/units.h"
28
typedef enum MPS2TZFPGAType {
33
+#include "sysemu/sysemu.h"
29
FPGA_AN505,
34
30
@@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineClass {
35
#define NPCM750_EVB_POWER_ON_STRAPS 0x00001ff7
31
const uint32_t *oscclk;
36
#define QUANTA_GSJ_POWER_ON_STRAPS 0x00001fff
32
uint32_t fpgaio_num_leds; /* Number of LEDs in FPGAIO LED0 register */
37
33
bool fpgaio_has_switches; /* Does FPGAIO have SWITCH register? */
38
+static const char npcm7xx_default_bootrom[] = "npcm7xx_bootrom.bin";
34
+ int numirq; /* Number of external interrupts */
39
+
35
const char *armsse_type;
40
+static void npcm7xx_load_bootrom(MachineState *machine, NPCM7xxState *soc)
36
};
41
+{
37
42
+ g_autofree char *filename = NULL;
38
@@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineState {
43
+ int ret;
39
SplitIRQ sec_resp_splitter;
44
+
40
qemu_or_irq uart_irq_orgate;
45
+ if (!bios_name) {
41
DeviceState *lan9118;
46
+ bios_name = npcm7xx_default_bootrom;
42
- SplitIRQ cpu_irq_splitter[MPS2TZ_NUMIRQ];
47
+ }
43
+ SplitIRQ cpu_irq_splitter[MPS2TZ_NUMIRQ_MAX];
48
+
44
Clock *sysclk;
49
+ filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
45
Clock *s32kclk;
50
+ if (!filename) {
46
};
51
+ error_report("Could not find ROM image '%s'", bios_name);
47
@@ -XXX,XX +XXX,XX @@ static qemu_irq get_sse_irq_in(MPS2TZMachineState *mms, int irqno)
52
+ if (!machine->kernel_filename) {
53
+ /* We can't boot without a bootrom or a kernel image. */
54
+ exit(1);
55
+ }
56
+ return;
57
+ }
58
+ ret = load_image_mr(filename, &soc->irom);
59
+ if (ret < 0) {
60
+ error_report("Failed to load ROM image '%s'", filename);
61
+ exit(1);
62
+ }
63
+}
64
+
65
static void npcm7xx_connect_dram(NPCM7xxState *soc, MemoryRegion *dram)
66
{
48
{
67
memory_region_add_subregion(get_system_memory(), NPCM7XX_DRAM_BA, dram);
49
/* Return a qemu_irq which will signal IRQ n to all CPUs in the SSE. */
68
@@ -XXX,XX +XXX,XX @@ static void npcm750_evb_init(MachineState *machine)
50
MachineClass *mc = MACHINE_GET_CLASS(mms);
69
npcm7xx_connect_dram(soc, machine->ram);
51
+ MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
70
qdev_realize(DEVICE(soc), NULL, &error_fatal);
52
71
53
- assert(irqno < MPS2TZ_NUMIRQ);
72
+ npcm7xx_load_bootrom(machine, soc);
54
+ assert(irqno < mmc->numirq);
73
npcm7xx_load_kernel(machine, soc);
55
56
if (mc->max_cpus > 1) {
57
return qdev_get_gpio_in(DEVICE(&mms->cpu_irq_splitter[irqno]), 0);
58
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
59
iotkitdev = DEVICE(&mms->iotkit);
60
object_property_set_link(OBJECT(&mms->iotkit), "memory",
61
OBJECT(system_memory), &error_abort);
62
- qdev_prop_set_uint32(iotkitdev, "EXP_NUMIRQ", MPS2TZ_NUMIRQ);
63
+ qdev_prop_set_uint32(iotkitdev, "EXP_NUMIRQ", mmc->numirq);
64
qdev_connect_clock_in(iotkitdev, "MAINCLK", mms->sysclk);
65
qdev_connect_clock_in(iotkitdev, "S32KCLK", mms->s32kclk);
66
sysbus_realize(SYS_BUS_DEVICE(&mms->iotkit), &error_fatal);
67
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
68
* board. If there is only one CPU, we can just wire the device IRQ
69
* directly to the SSE's IRQ input.
70
*/
71
+ assert(mmc->numirq <= MPS2TZ_NUMIRQ_MAX);
72
if (mc->max_cpus > 1) {
73
- for (i = 0; i < MPS2TZ_NUMIRQ; i++) {
74
+ for (i = 0; i < mmc->numirq; i++) {
75
char *name = g_strdup_printf("mps2-irq-splitter%d", i);
76
SplitIRQ *splitter = &mms->cpu_irq_splitter[i];
77
78
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an505_class_init(ObjectClass *oc, void *data)
79
mmc->len_oscclk = ARRAY_SIZE(an505_oscclk);
80
mmc->fpgaio_num_leds = 2;
81
mmc->fpgaio_has_switches = false;
82
+ mmc->numirq = 92;
83
mmc->armsse_type = TYPE_IOTKIT;
74
}
84
}
75
85
76
@@ -XXX,XX +XXX,XX @@ static void quanta_gsj_init(MachineState *machine)
86
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an521_class_init(ObjectClass *oc, void *data)
77
npcm7xx_connect_dram(soc, machine->ram);
87
mmc->len_oscclk = ARRAY_SIZE(an505_oscclk);
78
qdev_realize(DEVICE(soc), NULL, &error_fatal);
88
mmc->fpgaio_num_leds = 2;
79
89
mmc->fpgaio_has_switches = false;
80
+ npcm7xx_load_bootrom(machine, soc);
90
+ mmc->numirq = 92;
81
npcm7xx_load_kernel(machine, soc);
91
mmc->armsse_type = TYPE_SSE200;
82
}
92
}
83
93
84
--
94
--
85
2.20.1
95
2.20.1
86
96
87
97
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
The AN524 version of the SCC interface has different behaviour for
2
some of the CFG registers; implement it.
2
3
3
This just implements the bare minimum to cause the boot block to skip
4
Each board in this family can have minor differences in the meaning
4
memory initialization.
5
of the CFG registers, so rather than trying to specify all the
6
possible semantics via individual device properties, we make the
7
behaviour conditional on the part-number field of the SCC_ID register
8
which the board code already passes us.
5
9
6
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
10
For the AN524, the differences are:
7
Reviewed-by: Cédric Le Goater <clg@kaod.org>
11
* CFG3 is reserved rather than being board switches
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
12
* CFG5 is a new register ("ACLK Frequency in Hz")
9
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
13
* CFG6 is a new register ("Clock divider for BRAM")
10
Tested-by: Alexander Bulekov <alxndr@bu.edu>
14
11
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
15
We implement both of the new registers as reads-as-written.
12
Message-id: 20200911052101.2602693-10-hskinnemoen@google.com
16
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
18
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
19
Message-id: 20210215115138.20465-11-peter.maydell@linaro.org
14
---
20
---
15
include/hw/arm/npcm7xx.h | 2 +
21
include/hw/misc/mps2-scc.h | 3 ++
16
include/hw/mem/npcm7xx_mc.h | 36 ++++++++++++++++
22
hw/misc/mps2-scc.c | 71 ++++++++++++++++++++++++++++++++++++--
17
hw/arm/npcm7xx.c | 6 +++
23
2 files changed, 72 insertions(+), 2 deletions(-)
18
hw/mem/npcm7xx_mc.c | 84 +++++++++++++++++++++++++++++++++++++
19
hw/mem/meson.build | 1 +
20
5 files changed, 129 insertions(+)
21
create mode 100644 include/hw/mem/npcm7xx_mc.h
22
create mode 100644 hw/mem/npcm7xx_mc.c
23
24
24
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
25
diff --git a/include/hw/misc/mps2-scc.h b/include/hw/misc/mps2-scc.h
25
index XXXXXXX..XXXXXXX 100644
26
index XXXXXXX..XXXXXXX 100644
26
--- a/include/hw/arm/npcm7xx.h
27
--- a/include/hw/misc/mps2-scc.h
27
+++ b/include/hw/arm/npcm7xx.h
28
+++ b/include/hw/misc/mps2-scc.h
29
@@ -XXX,XX +XXX,XX @@ struct MPS2SCC {
30
31
uint32_t cfg0;
32
uint32_t cfg1;
33
+ uint32_t cfg2;
34
uint32_t cfg4;
35
+ uint32_t cfg5;
36
+ uint32_t cfg6;
37
uint32_t cfgdata_rtn;
38
uint32_t cfgdata_out;
39
uint32_t cfgctrl;
40
diff --git a/hw/misc/mps2-scc.c b/hw/misc/mps2-scc.c
41
index XXXXXXX..XXXXXXX 100644
42
--- a/hw/misc/mps2-scc.c
43
+++ b/hw/misc/mps2-scc.c
28
@@ -XXX,XX +XXX,XX @@
44
@@ -XXX,XX +XXX,XX @@
29
45
30
#include "hw/boards.h"
46
REG32(CFG0, 0)
31
#include "hw/cpu/a9mpcore.h"
47
REG32(CFG1, 4)
32
+#include "hw/mem/npcm7xx_mc.h"
48
+REG32(CFG2, 8)
33
#include "hw/misc/npcm7xx_clk.h"
49
REG32(CFG3, 0xc)
34
#include "hw/misc/npcm7xx_gcr.h"
50
REG32(CFG4, 0x10)
35
#include "hw/nvram/npcm7xx_otp.h"
51
+REG32(CFG5, 0x14)
36
@@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState {
52
+REG32(CFG6, 0x18)
37
NPCM7xxTimerCtrlState tim[3];
53
REG32(CFGDATA_RTN, 0xa0)
38
NPCM7xxOTPState key_storage;
54
REG32(CFGDATA_OUT, 0xa4)
39
NPCM7xxOTPState fuse_array;
55
REG32(CFGCTRL, 0xa8)
40
+ NPCM7xxMCState mc;
56
@@ -XXX,XX +XXX,XX @@ REG32(DLL, 0x100)
41
} NPCM7xxState;
57
REG32(AID, 0xFF8)
42
58
REG32(ID, 0xFFC)
43
#define TYPE_NPCM7XX "npcm7xx"
59
44
diff --git a/include/hw/mem/npcm7xx_mc.h b/include/hw/mem/npcm7xx_mc.h
60
+static int scc_partno(MPS2SCC *s)
45
new file mode 100644
46
index XXXXXXX..XXXXXXX
47
--- /dev/null
48
+++ b/include/hw/mem/npcm7xx_mc.h
49
@@ -XXX,XX +XXX,XX @@
50
+/*
51
+ * Nuvoton NPCM7xx Memory Controller stub
52
+ *
53
+ * Copyright 2020 Google LLC
54
+ *
55
+ * This program is free software; you can redistribute it and/or modify it
56
+ * under the terms of the GNU General Public License as published by the
57
+ * Free Software Foundation; either version 2 of the License, or
58
+ * (at your option) any later version.
59
+ *
60
+ * This program is distributed in the hope that it will be useful, but WITHOUT
61
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
62
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
63
+ * for more details.
64
+ */
65
+#ifndef NPCM7XX_MC_H
66
+#define NPCM7XX_MC_H
67
+
68
+#include "exec/memory.h"
69
+#include "hw/sysbus.h"
70
+
71
+/**
72
+ * struct NPCM7xxMCState - Device state for the memory controller.
73
+ * @parent: System bus device.
74
+ * @mmio: Memory region through which registers are accessed.
75
+ */
76
+typedef struct NPCM7xxMCState {
77
+ SysBusDevice parent;
78
+
79
+ MemoryRegion mmio;
80
+} NPCM7xxMCState;
81
+
82
+#define TYPE_NPCM7XX_MC "npcm7xx-mc"
83
+#define NPCM7XX_MC(obj) OBJECT_CHECK(NPCM7xxMCState, (obj), TYPE_NPCM7XX_MC)
84
+
85
+#endif /* NPCM7XX_MC_H */
86
diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c
87
index XXXXXXX..XXXXXXX 100644
88
--- a/hw/arm/npcm7xx.c
89
+++ b/hw/arm/npcm7xx.c
90
@@ -XXX,XX +XXX,XX @@
91
#define NPCM7XX_CPUP_BA (0xf03fe000)
92
#define NPCM7XX_GCR_BA (0xf0800000)
93
#define NPCM7XX_CLK_BA (0xf0801000)
94
+#define NPCM7XX_MC_BA (0xf0824000)
95
96
/* Internal AHB SRAM */
97
#define NPCM7XX_RAM3_BA (0xc0008000)
98
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj)
99
TYPE_NPCM7XX_KEY_STORAGE);
100
object_initialize_child(obj, "otp2", &s->fuse_array,
101
TYPE_NPCM7XX_FUSE_ARRAY);
102
+ object_initialize_child(obj, "mc", &s->mc, TYPE_NPCM7XX_MC);
103
104
for (i = 0; i < ARRAY_SIZE(s->tim); i++) {
105
object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER);
106
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
107
sysbus_mmio_map(SYS_BUS_DEVICE(&s->fuse_array), 0, NPCM7XX_OTP2_BA);
108
npcm7xx_init_fuses(s);
109
110
+ /* Fake Memory Controller (MC). Cannot fail. */
111
+ sysbus_realize(SYS_BUS_DEVICE(&s->mc), &error_abort);
112
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->mc), 0, NPCM7XX_MC_BA);
113
+
114
/* Timer Modules (TIM). Cannot fail. */
115
QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_tim_addr) != ARRAY_SIZE(s->tim));
116
for (i = 0; i < ARRAY_SIZE(s->tim); i++) {
117
diff --git a/hw/mem/npcm7xx_mc.c b/hw/mem/npcm7xx_mc.c
118
new file mode 100644
119
index XXXXXXX..XXXXXXX
120
--- /dev/null
121
+++ b/hw/mem/npcm7xx_mc.c
122
@@ -XXX,XX +XXX,XX @@
123
+/*
124
+ * Nuvoton NPCM7xx Memory Controller stub
125
+ *
126
+ * Copyright 2020 Google LLC
127
+ *
128
+ * This program is free software; you can redistribute it and/or modify it
129
+ * under the terms of the GNU General Public License as published by the
130
+ * Free Software Foundation; either version 2 of the License, or
131
+ * (at your option) any later version.
132
+ *
133
+ * This program is distributed in the hope that it will be useful, but WITHOUT
134
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
135
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
136
+ * for more details.
137
+ */
138
+
139
+#include "qemu/osdep.h"
140
+
141
+#include "hw/mem/npcm7xx_mc.h"
142
+#include "qapi/error.h"
143
+#include "qemu/log.h"
144
+#include "qemu/module.h"
145
+#include "qemu/units.h"
146
+
147
+#define NPCM7XX_MC_REGS_SIZE (4 * KiB)
148
+
149
+static uint64_t npcm7xx_mc_read(void *opaque, hwaddr addr, unsigned int size)
150
+{
61
+{
151
+ /*
62
+ /* Return the partno field of the SCC_ID (0x524, 0x511, etc) */
152
+ * If bits 8..11 @ offset 0 are not zero, the boot block thinks the memory
63
+ return extract32(s->id, 4, 8);
153
+ * controller has already been initialized and will skip DDR training.
154
+ */
155
+ if (addr == 0) {
156
+ return 0x100;
157
+ }
158
+
159
+ qemu_log_mask(LOG_UNIMP, "%s: mostly unimplemented\n", __func__);
160
+
161
+ return 0;
162
+}
64
+}
163
+
65
+
164
+static void npcm7xx_mc_write(void *opaque, hwaddr addr, uint64_t v,
66
/* Handle a write via the SYS_CFG channel to the specified function/device.
165
+ unsigned int size)
67
* Return false on error (reported to guest via SYS_CFGCTRL ERROR bit).
166
+{
68
*/
167
+ qemu_log_mask(LOG_UNIMP, "%s: mostly unimplemented\n", __func__);
69
@@ -XXX,XX +XXX,XX @@ static uint64_t mps2_scc_read(void *opaque, hwaddr offset, unsigned size)
168
+}
70
case A_CFG1:
169
+
71
r = s->cfg1;
170
+static const MemoryRegionOps npcm7xx_mc_ops = {
72
break;
171
+ .read = npcm7xx_mc_read,
73
+ case A_CFG2:
172
+ .write = npcm7xx_mc_write,
74
+ if (scc_partno(s) != 0x524) {
173
+ .endianness = DEVICE_LITTLE_ENDIAN,
75
+ /* CFG2 reserved on other boards */
174
+ .valid = {
76
+ goto bad_offset;
175
+ .min_access_size = 4,
77
+ }
176
+ .max_access_size = 4,
78
+ r = s->cfg2;
177
+ .unaligned = false,
79
+ break;
178
+ },
80
case A_CFG3:
179
+};
81
+ if (scc_partno(s) == 0x524) {
180
+
82
+ /* CFG3 reserved on AN524 */
181
+static void npcm7xx_mc_realize(DeviceState *dev, Error **errp)
83
+ goto bad_offset;
182
+{
84
+ }
183
+ NPCM7xxMCState *s = NPCM7XX_MC(dev);
85
/* These are user-settable DIP switches on the board. We don't
184
+
86
* model that, so just return zeroes.
185
+ memory_region_init_io(&s->mmio, OBJECT(s), &npcm7xx_mc_ops, s, "regs",
87
*/
186
+ NPCM7XX_MC_REGS_SIZE);
88
@@ -XXX,XX +XXX,XX @@ static uint64_t mps2_scc_read(void *opaque, hwaddr offset, unsigned size)
187
+ sysbus_init_mmio(&s->parent, &s->mmio);
89
case A_CFG4:
188
+}
90
r = s->cfg4;
189
+
91
break;
190
+static void npcm7xx_mc_class_init(ObjectClass *klass, void *data)
92
+ case A_CFG5:
191
+{
93
+ if (scc_partno(s) != 0x524) {
192
+ DeviceClass *dc = DEVICE_CLASS(klass);
94
+ /* CFG5 reserved on other boards */
193
+
95
+ goto bad_offset;
194
+ dc->desc = "NPCM7xx Memory Controller stub";
96
+ }
195
+ dc->realize = npcm7xx_mc_realize;
97
+ r = s->cfg5;
196
+}
98
+ break;
197
+
99
+ case A_CFG6:
198
+static const TypeInfo npcm7xx_mc_types[] = {
100
+ if (scc_partno(s) != 0x524) {
199
+ {
101
+ /* CFG6 reserved on other boards */
200
+ .name = TYPE_NPCM7XX_MC,
102
+ goto bad_offset;
201
+ .parent = TYPE_SYS_BUS_DEVICE,
103
+ }
202
+ .instance_size = sizeof(NPCM7xxMCState),
104
+ r = s->cfg6;
203
+ .class_init = npcm7xx_mc_class_init,
105
+ break;
204
+ },
106
case A_CFGDATA_RTN:
205
+};
107
r = s->cfgdata_rtn;
206
+DEFINE_TYPES(npcm7xx_mc_types);
108
break;
207
diff --git a/hw/mem/meson.build b/hw/mem/meson.build
109
@@ -XXX,XX +XXX,XX @@ static uint64_t mps2_scc_read(void *opaque, hwaddr offset, unsigned size)
208
index XXXXXXX..XXXXXXX 100644
110
r = s->id;
209
--- a/hw/mem/meson.build
111
break;
210
+++ b/hw/mem/meson.build
112
default:
211
@@ -XXX,XX +XXX,XX @@
113
+ bad_offset:
212
mem_ss = ss.source_set()
114
qemu_log_mask(LOG_GUEST_ERROR,
213
mem_ss.add(files('memory-device.c'))
115
"MPS2 SCC read: bad offset %x\n", (int) offset);
214
mem_ss.add(when: 'CONFIG_DIMM', if_true: files('pc-dimm.c'))
116
r = 0;
215
+mem_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_mc.c'))
117
@@ -XXX,XX +XXX,XX @@ static void mps2_scc_write(void *opaque, hwaddr offset, uint64_t value,
216
mem_ss.add(when: 'CONFIG_NVDIMM', if_true: files('nvdimm.c'))
118
led_set_state(s->led[i], extract32(value, i, 1));
217
119
}
218
softmmu_ss.add_all(when: 'CONFIG_MEM_DEVICE', if_true: mem_ss)
120
break;
121
+ case A_CFG2:
122
+ if (scc_partno(s) != 0x524) {
123
+ /* CFG2 reserved on other boards */
124
+ goto bad_offset;
125
+ }
126
+ /* AN524: QSPI Select signal */
127
+ s->cfg2 = value;
128
+ break;
129
+ case A_CFG5:
130
+ if (scc_partno(s) != 0x524) {
131
+ /* CFG5 reserved on other boards */
132
+ goto bad_offset;
133
+ }
134
+ /* AN524: ACLK frequency in Hz */
135
+ s->cfg5 = value;
136
+ break;
137
+ case A_CFG6:
138
+ if (scc_partno(s) != 0x524) {
139
+ /* CFG6 reserved on other boards */
140
+ goto bad_offset;
141
+ }
142
+ /* AN524: Clock divider for BRAM */
143
+ s->cfg6 = value;
144
+ break;
145
case A_CFGDATA_OUT:
146
s->cfgdata_out = value;
147
break;
148
@@ -XXX,XX +XXX,XX @@ static void mps2_scc_write(void *opaque, hwaddr offset, uint64_t value,
149
s->dll = deposit32(s->dll, 24, 8, extract32(value, 24, 8));
150
break;
151
default:
152
+ bad_offset:
153
qemu_log_mask(LOG_GUEST_ERROR,
154
"MPS2 SCC write: bad offset 0x%x\n", (int) offset);
155
break;
156
@@ -XXX,XX +XXX,XX @@ static void mps2_scc_reset(DeviceState *dev)
157
trace_mps2_scc_reset();
158
s->cfg0 = 0;
159
s->cfg1 = 0;
160
+ s->cfg2 = 0;
161
+ s->cfg5 = 0;
162
+ s->cfg6 = 0;
163
s->cfgdata_rtn = 0;
164
s->cfgdata_out = 0;
165
s->cfgctrl = 0x100000;
166
@@ -XXX,XX +XXX,XX @@ static void mps2_scc_realize(DeviceState *dev, Error **errp)
167
168
static const VMStateDescription mps2_scc_vmstate = {
169
.name = "mps2-scc",
170
- .version_id = 2,
171
- .minimum_version_id = 2,
172
+ .version_id = 3,
173
+ .minimum_version_id = 3,
174
.fields = (VMStateField[]) {
175
VMSTATE_UINT32(cfg0, MPS2SCC),
176
VMSTATE_UINT32(cfg1, MPS2SCC),
177
+ VMSTATE_UINT32(cfg2, MPS2SCC),
178
+ /* cfg3, cfg4 are read-only so need not be migrated */
179
+ VMSTATE_UINT32(cfg5, MPS2SCC),
180
+ VMSTATE_UINT32(cfg6, MPS2SCC),
181
VMSTATE_UINT32(cfgdata_rtn, MPS2SCC),
182
VMSTATE_UINT32(cfgdata_out, MPS2SCC),
183
VMSTATE_UINT32(cfgctrl, MPS2SCC),
219
--
184
--
220
2.20.1
185
2.20.1
221
186
222
187
diff view generated by jsdifflib
1
From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com>
1
On the MPS2 boards, the first 32 interrupt lines are entirely
2
internal to the SSE; interrupt lines for devices outside the SSE
3
start at 32. In the application notes that document each FPGA image,
4
the interrupt wiring is documented from the point of view of the CPU,
5
so '0' is the first of the SSE's interrupts and the devices in the
6
FPGA image itself are '32' and up: so the UART 0 Receive interrupt is
7
32, the SPI #0 interrupt is 51, and so on.
2
8
3
Correct the GEMs tx/rx clocks to use the 125Mhz fixed-clock.
9
Within our implementation, because the external interrupts must be
4
This matches the setup with the fixed-link 100Mbit PHY.
10
connected to the EXP_IRQ[0...n] lines of the SSE object, we made the
5
It also avoids the following warnings from the Linux kernel
11
get_sse_irq_in() function take an irqno whose values start at 0 for
6
driver:
12
the first FPGA device interrupt. In this numbering scheme the UART 0
13
Receive interrupt is 0, the SPI #0 interrupt is 19, and so on.
7
14
8
eth0: unable to generate target frequency: 125000000 Hz
15
The result of these two different numbering schemes has been that
16
half of the devices were wired up to the wrong IRQs: the UART IRQs
17
are wired up correctly, but the DMA and SPI devices were passing
18
start-at-32 values to get_sse_irq_in() and so being mis-connected.
9
19
10
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
20
Fix the bug by making get_sse_irq_in() take values specified with the
11
Reviewed-by: Luc Michel <luc.michel@greensocs.com>
21
same scheme that the hardware manuals use, to avoid confusion.
12
Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
22
13
Message-id: 20200909174647.662864-2-edgar.iglesias@gmail.com
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
23
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
24
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
25
Message-id: 20210215115138.20465-12-peter.maydell@linaro.org
15
---
26
---
16
hw/arm/xlnx-versal-virt.c | 2 +-
27
hw/arm/mps2-tz.c | 24 +++++++++++++++++-------
17
1 file changed, 1 insertion(+), 1 deletion(-)
28
1 file changed, 17 insertions(+), 7 deletions(-)
18
29
19
diff --git a/hw/arm/xlnx-versal-virt.c b/hw/arm/xlnx-versal-virt.c
30
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
20
index XXXXXXX..XXXXXXX 100644
31
index XXXXXXX..XXXXXXX 100644
21
--- a/hw/arm/xlnx-versal-virt.c
32
--- a/hw/arm/mps2-tz.c
22
+++ b/hw/arm/xlnx-versal-virt.c
33
+++ b/hw/arm/mps2-tz.c
23
@@ -XXX,XX +XXX,XX @@ static void fdt_add_gem_nodes(VersalVirt *s)
34
@@ -XXX,XX +XXX,XX @@ static void make_ram_alias(MemoryRegion *mr, const char *name,
24
s->phandle.ethernet_phy[i]);
35
25
qemu_fdt_setprop_cells(s->fdt, name, "clocks",
36
static qemu_irq get_sse_irq_in(MPS2TZMachineState *mms, int irqno)
26
s->phandle.clk_25Mhz, s->phandle.clk_25Mhz,
37
{
27
- s->phandle.clk_25Mhz, s->phandle.clk_25Mhz);
38
- /* Return a qemu_irq which will signal IRQ n to all CPUs in the SSE. */
28
+ s->phandle.clk_125Mhz, s->phandle.clk_125Mhz);
39
+ /*
29
qemu_fdt_setprop(s->fdt, name, "clock-names",
40
+ * Return a qemu_irq which will signal IRQ n to all CPUs in the
30
clocknames, sizeof(clocknames));
41
+ * SSE. The irqno should be as the CPU sees it, so the first
31
qemu_fdt_setprop_cells(s->fdt, name, "interrupts",
42
+ * external-to-the-SSE interrupt is 32.
43
+ */
44
MachineClass *mc = MACHINE_GET_CLASS(mms);
45
MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
46
47
- assert(irqno < mmc->numirq);
48
+ assert(irqno >= 32 && irqno < (mmc->numirq + 32));
49
+
50
+ /*
51
+ * Convert from "CPU irq number" (as listed in the FPGA image
52
+ * documentation) to the SSE external-interrupt number.
53
+ */
54
+ irqno -= 32;
55
56
if (mc->max_cpus > 1) {
57
return qdev_get_gpio_in(DEVICE(&mms->cpu_irq_splitter[irqno]), 0);
58
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
59
MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
60
CMSDKAPBUART *uart = opaque;
61
int i = uart - &mms->uart[0];
62
- int rxirqno = i * 2;
63
- int txirqno = i * 2 + 1;
64
- int combirqno = i + 10;
65
+ int rxirqno = i * 2 + 32;
66
+ int txirqno = i * 2 + 33;
67
+ int combirqno = i + 42;
68
SysBusDevice *s;
69
DeviceState *orgate_dev = DEVICE(&mms->uart_irq_orgate);
70
71
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_eth_dev(MPS2TZMachineState *mms, void *opaque,
72
73
s = SYS_BUS_DEVICE(mms->lan9118);
74
sysbus_realize_and_unref(s, &error_fatal);
75
- sysbus_connect_irq(s, 0, get_sse_irq_in(mms, 16));
76
+ sysbus_connect_irq(s, 0, get_sse_irq_in(mms, 48));
77
return sysbus_mmio_get_region(s, 0);
78
}
79
80
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
81
&error_fatal);
82
qdev_realize(DEVICE(&mms->uart_irq_orgate), NULL, &error_fatal);
83
qdev_connect_gpio_out(DEVICE(&mms->uart_irq_orgate), 0,
84
- get_sse_irq_in(mms, 15));
85
+ get_sse_irq_in(mms, 47));
86
87
/* Most of the devices in the FPGA are behind Peripheral Protection
88
* Controllers. The required order for initializing things is:
32
--
89
--
33
2.20.1
90
2.20.1
34
91
35
92
diff view generated by jsdifflib
1
Now that 32-bit KVM host support is gone, KVM can never
1
The mps2-tz code uses PPCPortInfo data structures to define what
2
be enabled unless CONFIG_AARCH64 is true, and some code
2
devices are present and how they are wired up. Currently we use
3
paths are no longer reachable and can be deleted.
3
these to specify device types and addresses, but hard-code the
4
interrupt line wiring in each make_* helper function. This works for
5
the two boards we have at the moment, but the AN524 has some devices
6
with different interrupt assignments.
7
8
This commit adds the framework to allow PPCPortInfo structures to
9
specify interrupt numbers. We add an array of interrupt numbers to
10
the PPCPortInfo struct, and pass it through to the make_* helpers.
11
The following commit will change the make_* helpers over to using the
12
framework.
4
13
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
15
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
16
Message-id: 20210215115138.20465-13-peter.maydell@linaro.org
8
Message-id: 20200904154156.31943-3-peter.maydell@linaro.org
9
---
17
---
10
target/arm/kvm-consts.h | 7 ---
18
hw/arm/mps2-tz.c | 36 ++++++++++++++++++++++++------------
11
target/arm/kvm_arm.h | 6 ---
19
1 file changed, 24 insertions(+), 12 deletions(-)
12
target/arm/cpu.c | 101 +++++++++++++++++++---------------------
13
target/arm/kvm.c | 7 ---
14
4 files changed, 47 insertions(+), 74 deletions(-)
15
20
16
diff --git a/target/arm/kvm-consts.h b/target/arm/kvm-consts.h
21
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
17
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
18
--- a/target/arm/kvm-consts.h
23
--- a/hw/arm/mps2-tz.c
19
+++ b/target/arm/kvm-consts.h
24
+++ b/hw/arm/mps2-tz.c
20
@@ -XXX,XX +XXX,XX @@ MISMATCH_CHECK(QEMU_PSCI_RET_DISABLED, PSCI_RET_DISABLED);
25
@@ -XXX,XX +XXX,XX @@ static qemu_irq get_sse_irq_in(MPS2TZMachineState *mms, int irqno)
26
* needs to be plugged into the downstream end of the PPC port.
21
*/
27
*/
22
#define QEMU_KVM_ARM_TARGET_NONE UINT_MAX
28
typedef MemoryRegion *MakeDevFn(MPS2TZMachineState *mms, void *opaque,
23
29
- const char *name, hwaddr size);
24
-#ifdef TARGET_AARCH64
30
+ const char *name, hwaddr size,
25
MISMATCH_CHECK(QEMU_KVM_ARM_TARGET_AEM_V8, KVM_ARM_TARGET_AEM_V8);
31
+ const int *irqs);
26
MISMATCH_CHECK(QEMU_KVM_ARM_TARGET_FOUNDATION_V8, KVM_ARM_TARGET_FOUNDATION_V8);
32
27
MISMATCH_CHECK(QEMU_KVM_ARM_TARGET_CORTEX_A57, KVM_ARM_TARGET_CORTEX_A57);
33
typedef struct PPCPortInfo {
28
MISMATCH_CHECK(QEMU_KVM_ARM_TARGET_XGENE_POTENZA, KVM_ARM_TARGET_XGENE_POTENZA);
34
const char *name;
29
MISMATCH_CHECK(QEMU_KVM_ARM_TARGET_CORTEX_A53, KVM_ARM_TARGET_CORTEX_A53);
35
@@ -XXX,XX +XXX,XX @@ typedef struct PPCPortInfo {
30
-#else
36
void *opaque;
31
-MISMATCH_CHECK(QEMU_KVM_ARM_TARGET_CORTEX_A15, KVM_ARM_TARGET_CORTEX_A15);
37
hwaddr addr;
32
-MISMATCH_CHECK(QEMU_KVM_ARM_TARGET_CORTEX_A7, KVM_ARM_TARGET_CORTEX_A7);
38
hwaddr size;
33
-#endif
39
+ int irqs[3]; /* currently no device needs more IRQ lines than this */
34
40
} PPCPortInfo;
35
#define CP_REG_ARM64 0x6000000000000000ULL
41
36
#define CP_REG_ARM_COPROC_MASK 0x000000000FFF0000
42
typedef struct PPCInfo {
37
@@ -XXX,XX +XXX,XX @@ MISMATCH_CHECK(QEMU_KVM_ARM_TARGET_CORTEX_A7, KVM_ARM_TARGET_CORTEX_A7);
43
@@ -XXX,XX +XXX,XX @@ typedef struct PPCInfo {
38
/* No kernel define but it's useful to QEMU */
44
} PPCInfo;
39
#define CP_REG_ARM64_SYSREG_CP (CP_REG_ARM64_SYSREG >> CP_REG_ARM_COPROC_SHIFT)
45
40
46
static MemoryRegion *make_unimp_dev(MPS2TZMachineState *mms,
41
-#ifdef TARGET_AARCH64
47
- void *opaque,
42
MISMATCH_CHECK(CP_REG_ARM64, KVM_REG_ARM64);
48
- const char *name, hwaddr size)
43
MISMATCH_CHECK(CP_REG_ARM_COPROC_MASK, KVM_REG_ARM_COPROC_MASK);
49
+ void *opaque,
44
MISMATCH_CHECK(CP_REG_ARM_COPROC_SHIFT, KVM_REG_ARM_COPROC_SHIFT);
50
+ const char *name, hwaddr size,
45
@@ -XXX,XX +XXX,XX @@ MISMATCH_CHECK(CP_REG_ARM64_SYSREG_CRM_MASK, KVM_REG_ARM64_SYSREG_CRM_MASK);
51
+ const int *irqs)
46
MISMATCH_CHECK(CP_REG_ARM64_SYSREG_CRM_SHIFT, KVM_REG_ARM64_SYSREG_CRM_SHIFT);
47
MISMATCH_CHECK(CP_REG_ARM64_SYSREG_OP2_MASK, KVM_REG_ARM64_SYSREG_OP2_MASK);
48
MISMATCH_CHECK(CP_REG_ARM64_SYSREG_OP2_SHIFT, KVM_REG_ARM64_SYSREG_OP2_SHIFT);
49
-#endif
50
51
#undef MISMATCH_CHECK
52
53
diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h
54
index XXXXXXX..XXXXXXX 100644
55
--- a/target/arm/kvm_arm.h
56
+++ b/target/arm/kvm_arm.h
57
@@ -XXX,XX +XXX,XX @@ static inline const char *gic_class_name(void)
58
static inline const char *gicv3_class_name(void)
59
{
52
{
60
if (kvm_irqchip_in_kernel()) {
53
/* Initialize, configure and realize a TYPE_UNIMPLEMENTED_DEVICE,
61
-#ifdef TARGET_AARCH64
54
* and return a pointer to its MemoryRegion.
62
return "kvm-arm-gicv3";
55
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_unimp_dev(MPS2TZMachineState *mms,
63
-#else
64
- error_report("KVM GICv3 acceleration is not supported on this "
65
- "platform");
66
- exit(1);
67
-#endif
68
} else {
69
if (kvm_enabled()) {
70
error_report("Userspace GICv3 is not supported with KVM");
71
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
72
index XXXXXXX..XXXXXXX 100644
73
--- a/target/arm/cpu.c
74
+++ b/target/arm/cpu.c
75
@@ -XXX,XX +XXX,XX @@ static void cortex_a15_initfn(Object *obj)
76
}
56
}
77
57
78
#ifndef TARGET_AARCH64
58
static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
79
-/* -cpu max: if KVM is enabled, like -cpu host (best possible with this host);
59
- const char *name, hwaddr size)
80
- * otherwise, a CPU with as many features enabled as our emulation supports.
60
+ const char *name, hwaddr size,
81
+/*
61
+ const int *irqs)
82
+ * -cpu max: a CPU with as many features enabled as our emulation supports.
83
* The version of '-cpu max' for qemu-system-aarch64 is defined in cpu64.c;
84
- * this only needs to handle 32 bits.
85
+ * this only needs to handle 32 bits, and need not care about KVM.
86
*/
87
static void arm_max_initfn(Object *obj)
88
{
62
{
89
ARMCPU *cpu = ARM_CPU(obj);
63
MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
90
64
CMSDKAPBUART *uart = opaque;
91
- if (kvm_enabled()) {
65
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
92
- kvm_arm_set_cpu_features_from_host(cpu);
93
- } else {
94
- cortex_a15_initfn(obj);
95
+ cortex_a15_initfn(obj);
96
97
- /* old-style VFP short-vector support */
98
- cpu->isar.mvfr0 = FIELD_DP32(cpu->isar.mvfr0, MVFR0, FPSHVEC, 1);
99
+ /* old-style VFP short-vector support */
100
+ cpu->isar.mvfr0 = FIELD_DP32(cpu->isar.mvfr0, MVFR0, FPSHVEC, 1);
101
102
#ifdef CONFIG_USER_ONLY
103
- /* We don't set these in system emulation mode for the moment,
104
- * since we don't correctly set (all of) the ID registers to
105
- * advertise them.
106
- */
107
- set_feature(&cpu->env, ARM_FEATURE_V8);
108
- {
109
- uint32_t t;
110
+ /*
111
+ * We don't set these in system emulation mode for the moment,
112
+ * since we don't correctly set (all of) the ID registers to
113
+ * advertise them.
114
+ */
115
+ set_feature(&cpu->env, ARM_FEATURE_V8);
116
+ {
117
+ uint32_t t;
118
119
- t = cpu->isar.id_isar5;
120
- t = FIELD_DP32(t, ID_ISAR5, AES, 2);
121
- t = FIELD_DP32(t, ID_ISAR5, SHA1, 1);
122
- t = FIELD_DP32(t, ID_ISAR5, SHA2, 1);
123
- t = FIELD_DP32(t, ID_ISAR5, CRC32, 1);
124
- t = FIELD_DP32(t, ID_ISAR5, RDM, 1);
125
- t = FIELD_DP32(t, ID_ISAR5, VCMA, 1);
126
- cpu->isar.id_isar5 = t;
127
+ t = cpu->isar.id_isar5;
128
+ t = FIELD_DP32(t, ID_ISAR5, AES, 2);
129
+ t = FIELD_DP32(t, ID_ISAR5, SHA1, 1);
130
+ t = FIELD_DP32(t, ID_ISAR5, SHA2, 1);
131
+ t = FIELD_DP32(t, ID_ISAR5, CRC32, 1);
132
+ t = FIELD_DP32(t, ID_ISAR5, RDM, 1);
133
+ t = FIELD_DP32(t, ID_ISAR5, VCMA, 1);
134
+ cpu->isar.id_isar5 = t;
135
136
- t = cpu->isar.id_isar6;
137
- t = FIELD_DP32(t, ID_ISAR6, JSCVT, 1);
138
- t = FIELD_DP32(t, ID_ISAR6, DP, 1);
139
- t = FIELD_DP32(t, ID_ISAR6, FHM, 1);
140
- t = FIELD_DP32(t, ID_ISAR6, SB, 1);
141
- t = FIELD_DP32(t, ID_ISAR6, SPECRES, 1);
142
- cpu->isar.id_isar6 = t;
143
+ t = cpu->isar.id_isar6;
144
+ t = FIELD_DP32(t, ID_ISAR6, JSCVT, 1);
145
+ t = FIELD_DP32(t, ID_ISAR6, DP, 1);
146
+ t = FIELD_DP32(t, ID_ISAR6, FHM, 1);
147
+ t = FIELD_DP32(t, ID_ISAR6, SB, 1);
148
+ t = FIELD_DP32(t, ID_ISAR6, SPECRES, 1);
149
+ cpu->isar.id_isar6 = t;
150
151
- t = cpu->isar.mvfr1;
152
- t = FIELD_DP32(t, MVFR1, FPHP, 3); /* v8.2-FP16 */
153
- t = FIELD_DP32(t, MVFR1, SIMDHP, 2); /* v8.2-FP16 */
154
- cpu->isar.mvfr1 = t;
155
+ t = cpu->isar.mvfr1;
156
+ t = FIELD_DP32(t, MVFR1, FPHP, 3); /* v8.2-FP16 */
157
+ t = FIELD_DP32(t, MVFR1, SIMDHP, 2); /* v8.2-FP16 */
158
+ cpu->isar.mvfr1 = t;
159
160
- t = cpu->isar.mvfr2;
161
- t = FIELD_DP32(t, MVFR2, SIMDMISC, 3); /* SIMD MaxNum */
162
- t = FIELD_DP32(t, MVFR2, FPMISC, 4); /* FP MaxNum */
163
- cpu->isar.mvfr2 = t;
164
+ t = cpu->isar.mvfr2;
165
+ t = FIELD_DP32(t, MVFR2, SIMDMISC, 3); /* SIMD MaxNum */
166
+ t = FIELD_DP32(t, MVFR2, FPMISC, 4); /* FP MaxNum */
167
+ cpu->isar.mvfr2 = t;
168
169
- t = cpu->isar.id_mmfr3;
170
- t = FIELD_DP32(t, ID_MMFR3, PAN, 2); /* ATS1E1 */
171
- cpu->isar.id_mmfr3 = t;
172
+ t = cpu->isar.id_mmfr3;
173
+ t = FIELD_DP32(t, ID_MMFR3, PAN, 2); /* ATS1E1 */
174
+ cpu->isar.id_mmfr3 = t;
175
176
- t = cpu->isar.id_mmfr4;
177
- t = FIELD_DP32(t, ID_MMFR4, HPDS, 1); /* AA32HPD */
178
- t = FIELD_DP32(t, ID_MMFR4, AC2, 1); /* ACTLR2, HACTLR2 */
179
- t = FIELD_DP32(t, ID_MMFR4, CNP, 1); /* TTCNP */
180
- t = FIELD_DP32(t, ID_MMFR4, XNX, 1); /* TTS2UXN */
181
- cpu->isar.id_mmfr4 = t;
182
- }
183
-#endif
184
+ t = cpu->isar.id_mmfr4;
185
+ t = FIELD_DP32(t, ID_MMFR4, HPDS, 1); /* AA32HPD */
186
+ t = FIELD_DP32(t, ID_MMFR4, AC2, 1); /* ACTLR2, HACTLR2 */
187
+ t = FIELD_DP32(t, ID_MMFR4, CNP, 1); /* TTCNP */
188
+ t = FIELD_DP32(t, ID_MMFR4, XNX, 1); /* TTS2UXN */
189
+ cpu->isar.id_mmfr4 = t;
190
}
191
+#endif
192
}
66
}
193
#endif
67
194
68
static MemoryRegion *make_scc(MPS2TZMachineState *mms, void *opaque,
195
@@ -XXX,XX +XXX,XX @@ static void arm_host_initfn(Object *obj)
69
- const char *name, hwaddr size)
196
70
+ const char *name, hwaddr size,
197
static const TypeInfo host_arm_cpu_type_info = {
71
+ const int *irqs)
198
.name = TYPE_ARM_HOST_CPU,
72
{
199
-#ifdef TARGET_AARCH64
73
MPS2SCC *scc = opaque;
200
.parent = TYPE_AARCH64_CPU,
74
DeviceState *sccdev;
201
-#else
75
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_scc(MPS2TZMachineState *mms, void *opaque,
202
- .parent = TYPE_ARM_CPU,
203
-#endif
204
.instance_init = arm_host_initfn,
205
};
206
207
diff --git a/target/arm/kvm.c b/target/arm/kvm.c
208
index XXXXXXX..XXXXXXX 100644
209
--- a/target/arm/kvm.c
210
+++ b/target/arm/kvm.c
211
@@ -XXX,XX +XXX,XX @@ int kvm_arch_process_async_events(CPUState *cs)
212
return 0;
213
}
76
}
214
77
215
-/* The #ifdef protections are until 32bit headers are imported and can
78
static MemoryRegion *make_fpgaio(MPS2TZMachineState *mms, void *opaque,
216
- * be removed once both 32 and 64 bit reach feature parity.
79
- const char *name, hwaddr size)
217
- */
80
+ const char *name, hwaddr size,
218
void kvm_arch_update_guest_debug(CPUState *cs, struct kvm_guest_debug *dbg)
81
+ const int *irqs)
219
{
82
{
220
-#ifdef KVM_GUESTDBG_USE_SW_BP
83
MPS2FPGAIO *fpgaio = opaque;
221
if (kvm_sw_breakpoints_active(cs)) {
84
MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
222
dbg->control |= KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_USE_SW_BP;
85
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_fpgaio(MPS2TZMachineState *mms, void *opaque,
223
}
224
-#endif
225
-#ifdef KVM_GUESTDBG_USE_HW
226
if (kvm_arm_hw_debug_active(cs)) {
227
dbg->control |= KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_USE_HW;
228
kvm_arm_copy_hw_debug_data(&dbg->arch);
229
}
230
-#endif
231
}
86
}
232
87
233
void kvm_arch_init_irq_routing(KVMState *s)
88
static MemoryRegion *make_eth_dev(MPS2TZMachineState *mms, void *opaque,
89
- const char *name, hwaddr size)
90
+ const char *name, hwaddr size,
91
+ const int *irqs)
92
{
93
SysBusDevice *s;
94
NICInfo *nd = &nd_table[0];
95
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_eth_dev(MPS2TZMachineState *mms, void *opaque,
96
}
97
98
static MemoryRegion *make_mpc(MPS2TZMachineState *mms, void *opaque,
99
- const char *name, hwaddr size)
100
+ const char *name, hwaddr size,
101
+ const int *irqs)
102
{
103
TZMPC *mpc = opaque;
104
int i = mpc - &mms->ssram_mpc[0];
105
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_mpc(MPS2TZMachineState *mms, void *opaque,
106
}
107
108
static MemoryRegion *make_dma(MPS2TZMachineState *mms, void *opaque,
109
- const char *name, hwaddr size)
110
+ const char *name, hwaddr size,
111
+ const int *irqs)
112
{
113
PL080State *dma = opaque;
114
int i = dma - &mms->dma[0];
115
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_dma(MPS2TZMachineState *mms, void *opaque,
116
}
117
118
static MemoryRegion *make_spi(MPS2TZMachineState *mms, void *opaque,
119
- const char *name, hwaddr size)
120
+ const char *name, hwaddr size,
121
+ const int *irqs)
122
{
123
/*
124
* The AN505 has five PL022 SPI controllers.
125
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_spi(MPS2TZMachineState *mms, void *opaque,
126
}
127
128
static MemoryRegion *make_i2c(MPS2TZMachineState *mms, void *opaque,
129
- const char *name, hwaddr size)
130
+ const char *name, hwaddr size,
131
+ const int *irqs)
132
{
133
ArmSbconI2CState *i2c = opaque;
134
SysBusDevice *s;
135
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
136
continue;
137
}
138
139
- mr = pinfo->devfn(mms, pinfo->opaque, pinfo->name, pinfo->size);
140
+ mr = pinfo->devfn(mms, pinfo->opaque, pinfo->name, pinfo->size,
141
+ pinfo->irqs);
142
portname = g_strdup_printf("port[%d]", port);
143
object_property_set_link(OBJECT(ppc), portname, OBJECT(mr),
144
&error_fatal);
234
--
145
--
235
2.20.1
146
2.20.1
236
147
237
148
diff view generated by jsdifflib
1
In the Neon instructions, some instruction formats have a 2-bit size
1
Move the specification of the IRQ information for the uart, ethernet,
2
field which corresponds exactly to QEMU's MO_8/16/32/64. However the
2
dma and spi devices to the data structures. (The other devices
3
floating-point insns in the 3-same group have a 1-bit size field
3
handled by the PPCPortInfo structures don't have any interrupt lines
4
which is "0 for 32-bit float and 1 for 16-bit float". Currently we
4
we need to wire up.)
5
pass these values directly through to trans_ functions, which means
6
that when reading a particular trans_ function you need to know if
7
that insn uses a 2-bit size or a 1-bit size.
8
9
Move the handling of the 1-bit size to the decodetree file, so that
10
all these insns consistently pass a size to the trans_ function which
11
is an MO_8/16/32/64 value.
12
13
In this commit we switch over the insns using the 3same_fp and
14
3same_fp_q0 formats.
15
5
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
18
Message-id: 20200903133209.5141-2-peter.maydell@linaro.org
8
Message-id: 20210215115138.20465-14-peter.maydell@linaro.org
19
---
9
---
20
target/arm/neon-dp.decode | 15 ++++++++++-----
10
hw/arm/mps2-tz.c | 52 +++++++++++++++++++++++-------------------------
21
target/arm/translate-neon.c.inc | 16 +++++++++++-----
11
1 file changed, 25 insertions(+), 27 deletions(-)
22
2 files changed, 21 insertions(+), 10 deletions(-)
23
12
24
diff --git a/target/arm/neon-dp.decode b/target/arm/neon-dp.decode
13
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
25
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
26
--- a/target/arm/neon-dp.decode
15
--- a/hw/arm/mps2-tz.c
27
+++ b/target/arm/neon-dp.decode
16
+++ b/hw/arm/mps2-tz.c
28
@@ -XXX,XX +XXX,XX @@
17
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
29
@3same_q0 .... ... . . . size:2 .... .... .... . 0 . . .... \
18
const char *name, hwaddr size,
30
&3same vm=%vm_dp vn=%vn_dp vd=%vd_dp q=0
19
const int *irqs)
31
20
{
32
-# For FP insns the high bit of 'size' is used as part of opcode decode
21
+ /* The irq[] array is tx, rx, combined, in that order */
33
-@3same_fp .... ... . . . . size:1 .... .... .... . q:1 . . .... \
22
MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
34
- &3same vm=%vm_dp vn=%vn_dp vd=%vd_dp
23
CMSDKAPBUART *uart = opaque;
35
-@3same_fp_q0 .... ... . . . . size:1 .... .... .... . 0 . . .... \
24
int i = uart - &mms->uart[0];
36
- &3same vm=%vm_dp vn=%vn_dp vd=%vd_dp q=0
25
- int rxirqno = i * 2 + 32;
37
+# For FP insns the high bit of 'size' is used as part of opcode decode,
26
- int txirqno = i * 2 + 33;
38
+# and the 'size' bit is 0 for 32-bit float and 1 for 16-bit float.
27
- int combirqno = i + 42;
39
+# This converts this encoding to the same MO_8/16/32/64 values that the
28
SysBusDevice *s;
40
+# integer neon insns use.
29
DeviceState *orgate_dev = DEVICE(&mms->uart_irq_orgate);
41
+%3same_fp_size 20:1 !function=neon_3same_fp_size
30
42
+
31
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
43
+@3same_fp .... ... . . . . . .... .... .... . q:1 . . .... \
32
qdev_prop_set_uint32(DEVICE(uart), "pclk-frq", mmc->sysclk_frq);
44
+ &3same vm=%vm_dp vn=%vn_dp vd=%vd_dp size=%3same_fp_size
33
sysbus_realize(SYS_BUS_DEVICE(uart), &error_fatal);
45
+@3same_fp_q0 .... ... . . . . . .... .... .... . 0 . . .... \
34
s = SYS_BUS_DEVICE(uart);
46
+ &3same vm=%vm_dp vn=%vn_dp vd=%vd_dp q=0 size=%3same_fp_size
35
- sysbus_connect_irq(s, 0, get_sse_irq_in(mms, txirqno));
47
36
- sysbus_connect_irq(s, 1, get_sse_irq_in(mms, rxirqno));
48
VHADD_S_3s 1111 001 0 0 . .. .... .... 0000 . . . 0 .... @3same
37
+ sysbus_connect_irq(s, 0, get_sse_irq_in(mms, irqs[0]));
49
VHADD_U_3s 1111 001 1 0 . .. .... .... 0000 . . . 0 .... @3same
38
+ sysbus_connect_irq(s, 1, get_sse_irq_in(mms, irqs[1]));
50
diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc
39
sysbus_connect_irq(s, 2, qdev_get_gpio_in(orgate_dev, i * 2));
51
index XXXXXXX..XXXXXXX 100644
40
sysbus_connect_irq(s, 3, qdev_get_gpio_in(orgate_dev, i * 2 + 1));
52
--- a/target/arm/translate-neon.c.inc
41
- sysbus_connect_irq(s, 4, get_sse_irq_in(mms, combirqno));
53
+++ b/target/arm/translate-neon.c.inc
42
+ sysbus_connect_irq(s, 4, get_sse_irq_in(mms, irqs[2]));
54
@@ -XXX,XX +XXX,XX @@ static inline int rsub_8(DisasContext *s, int x)
43
return sysbus_mmio_get_region(SYS_BUS_DEVICE(uart), 0);
55
return 8 - x;
56
}
44
}
57
45
58
+static inline int neon_3same_fp_size(DisasContext *s, int x)
46
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_eth_dev(MPS2TZMachineState *mms, void *opaque,
59
+{
47
60
+ /* Convert 0==fp32, 1==fp16 into a MO_* value */
48
s = SYS_BUS_DEVICE(mms->lan9118);
61
+ return MO_32 - x;
49
sysbus_realize_and_unref(s, &error_fatal);
62
+}
50
- sysbus_connect_irq(s, 0, get_sse_irq_in(mms, 48));
63
+
51
+ sysbus_connect_irq(s, 0, get_sse_irq_in(mms, irqs[0]));
64
/* Include the generated Neon decoder */
52
return sysbus_mmio_get_region(s, 0);
65
#include "decode-neon-dp.c.inc"
53
}
66
#include "decode-neon-ls.c.inc"
54
67
@@ -XXX,XX +XXX,XX @@ DO_3SAME_VQDMULH(VQRDMULH, qrdmulh)
55
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_dma(MPS2TZMachineState *mms, void *opaque,
68
WRAP_FP_GVEC(gen_##INSN##_fp16_3s, FPST_STD_F16, HFUNC) \
56
const char *name, hwaddr size,
69
static bool trans_##INSN##_fp_3s(DisasContext *s, arg_3same *a) \
57
const int *irqs)
70
{ \
58
{
71
- if (a->size != 0) { \
59
+ /* The irq[] array is DMACINTR, DMACINTERR, DMACINTTC, in that order */
72
+ if (a->size == MO_16) { \
60
PL080State *dma = opaque;
73
if (!dc_isar_feature(aa32_fp16_arith, s)) { \
61
int i = dma - &mms->dma[0];
74
return false; \
62
SysBusDevice *s;
75
} \
63
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_dma(MPS2TZMachineState *mms, void *opaque,
76
@@ -XXX,XX +XXX,XX @@ static bool trans_VMAXNM_fp_3s(DisasContext *s, arg_3same *a)
64
77
return false;
65
s = SYS_BUS_DEVICE(dma);
78
}
66
/* Wire up DMACINTR, DMACINTERR, DMACINTTC */
79
67
- sysbus_connect_irq(s, 0, get_sse_irq_in(mms, 58 + i * 3));
80
- if (a->size != 0) {
68
- sysbus_connect_irq(s, 1, get_sse_irq_in(mms, 56 + i * 3));
81
+ if (a->size == MO_16) {
69
- sysbus_connect_irq(s, 2, get_sse_irq_in(mms, 57 + i * 3));
82
if (!dc_isar_feature(aa32_fp16_arith, s)) {
70
+ sysbus_connect_irq(s, 0, get_sse_irq_in(mms, irqs[0]));
83
return false;
71
+ sysbus_connect_irq(s, 1, get_sse_irq_in(mms, irqs[1]));
84
}
72
+ sysbus_connect_irq(s, 2, get_sse_irq_in(mms, irqs[2]));
85
@@ -XXX,XX +XXX,XX @@ static bool trans_VMINNM_fp_3s(DisasContext *s, arg_3same *a)
73
86
return false;
74
g_free(mscname);
87
}
75
return sysbus_mmio_get_region(s, 0);
88
76
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_spi(MPS2TZMachineState *mms, void *opaque,
89
- if (a->size != 0) {
77
* lines are set via the "MISC" register in the MPS2 FPGAIO device.
90
+ if (a->size == MO_16) {
78
*/
91
if (!dc_isar_feature(aa32_fp16_arith, s)) {
79
PL022State *spi = opaque;
92
return false;
80
- int i = spi - &mms->spi[0];
93
}
81
SysBusDevice *s;
94
@@ -XXX,XX +XXX,XX @@ static bool do_3same_fp_pair(DisasContext *s, arg_3same *a,
82
95
assert(a->q == 0); /* enforced by decode patterns */
83
object_initialize_child(OBJECT(mms), name, spi, TYPE_PL022);
96
84
sysbus_realize(SYS_BUS_DEVICE(spi), &error_fatal);
97
85
s = SYS_BUS_DEVICE(spi);
98
- fpstatus = fpstatus_ptr(a->size != 0 ? FPST_STD_F16 : FPST_STD);
86
- sysbus_connect_irq(s, 0, get_sse_irq_in(mms, 51 + i));
99
+ fpstatus = fpstatus_ptr(a->size == MO_16 ? FPST_STD_F16 : FPST_STD);
87
+ sysbus_connect_irq(s, 0, get_sse_irq_in(mms, irqs[0]));
100
tcg_gen_gvec_3_ptr(vfp_reg_offset(1, a->vd),
88
return sysbus_mmio_get_region(s, 0);
101
vfp_reg_offset(1, a->vn),
89
}
102
vfp_reg_offset(1, a->vm),
90
103
@@ -XXX,XX +XXX,XX @@ static bool do_3same_fp_pair(DisasContext *s, arg_3same *a,
91
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
104
#define DO_3S_FP_PAIR(INSN,FUNC) \
92
}, {
105
static bool trans_##INSN##_fp_3s(DisasContext *s, arg_3same *a) \
93
.name = "apb_ppcexp1",
106
{ \
94
.ports = {
107
- if (a->size != 0) { \
95
- { "spi0", make_spi, &mms->spi[0], 0x40205000, 0x1000 },
108
+ if (a->size == MO_16) { \
96
- { "spi1", make_spi, &mms->spi[1], 0x40206000, 0x1000 },
109
if (!dc_isar_feature(aa32_fp16_arith, s)) { \
97
- { "spi2", make_spi, &mms->spi[2], 0x40209000, 0x1000 },
110
return false; \
98
- { "spi3", make_spi, &mms->spi[3], 0x4020a000, 0x1000 },
111
} \
99
- { "spi4", make_spi, &mms->spi[4], 0x4020b000, 0x1000 },
100
- { "uart0", make_uart, &mms->uart[0], 0x40200000, 0x1000 },
101
- { "uart1", make_uart, &mms->uart[1], 0x40201000, 0x1000 },
102
- { "uart2", make_uart, &mms->uart[2], 0x40202000, 0x1000 },
103
- { "uart3", make_uart, &mms->uart[3], 0x40203000, 0x1000 },
104
- { "uart4", make_uart, &mms->uart[4], 0x40204000, 0x1000 },
105
+ { "spi0", make_spi, &mms->spi[0], 0x40205000, 0x1000, { 51 } },
106
+ { "spi1", make_spi, &mms->spi[1], 0x40206000, 0x1000, { 52 } },
107
+ { "spi2", make_spi, &mms->spi[2], 0x40209000, 0x1000, { 53 } },
108
+ { "spi3", make_spi, &mms->spi[3], 0x4020a000, 0x1000, { 54 } },
109
+ { "spi4", make_spi, &mms->spi[4], 0x4020b000, 0x1000, { 55 } },
110
+ { "uart0", make_uart, &mms->uart[0], 0x40200000, 0x1000, { 32, 33, 42 } },
111
+ { "uart1", make_uart, &mms->uart[1], 0x40201000, 0x1000, { 34, 35, 43 } },
112
+ { "uart2", make_uart, &mms->uart[2], 0x40202000, 0x1000, { 36, 37, 44 } },
113
+ { "uart3", make_uart, &mms->uart[3], 0x40203000, 0x1000, { 38, 39, 45 } },
114
+ { "uart4", make_uart, &mms->uart[4], 0x40204000, 0x1000, { 40, 41, 46 } },
115
{ "i2c0", make_i2c, &mms->i2c[0], 0x40207000, 0x1000 },
116
{ "i2c1", make_i2c, &mms->i2c[1], 0x40208000, 0x1000 },
117
{ "i2c2", make_i2c, &mms->i2c[2], 0x4020c000, 0x1000 },
118
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
119
{ "gpio1", make_unimp_dev, &mms->gpio[1], 0x40101000, 0x1000 },
120
{ "gpio2", make_unimp_dev, &mms->gpio[2], 0x40102000, 0x1000 },
121
{ "gpio3", make_unimp_dev, &mms->gpio[3], 0x40103000, 0x1000 },
122
- { "eth", make_eth_dev, NULL, 0x42000000, 0x100000 },
123
+ { "eth", make_eth_dev, NULL, 0x42000000, 0x100000, { 48 } },
124
},
125
}, {
126
.name = "ahb_ppcexp1",
127
.ports = {
128
- { "dma0", make_dma, &mms->dma[0], 0x40110000, 0x1000 },
129
- { "dma1", make_dma, &mms->dma[1], 0x40111000, 0x1000 },
130
- { "dma2", make_dma, &mms->dma[2], 0x40112000, 0x1000 },
131
- { "dma3", make_dma, &mms->dma[3], 0x40113000, 0x1000 },
132
+ { "dma0", make_dma, &mms->dma[0], 0x40110000, 0x1000, { 58, 56, 57 } },
133
+ { "dma1", make_dma, &mms->dma[1], 0x40111000, 0x1000, { 61, 59, 60 } },
134
+ { "dma2", make_dma, &mms->dma[2], 0x40112000, 0x1000, { 64, 62, 63 } },
135
+ { "dma3", make_dma, &mms->dma[3], 0x40113000, 0x1000, { 67, 65, 66 } },
136
},
137
},
138
};
112
--
139
--
113
2.20.1
140
2.20.1
114
141
115
142
diff view generated by jsdifflib
New patch
1
We create an OR gate to wire together the overflow IRQs for all the
2
UARTs on the board; this has to have twice the number of inputs as
3
there are UARTs, since each UART feeds it a TX overflow and an RX
4
overflow interrupt line. Replace the hardcoded '10' with a
5
calculation based on the size of the uart[] array in the
6
MPS2TZMachineState. (We rely on OR gate inputs that are never wired
7
up or asserted being treated as always-zero.)
1
8
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
11
Message-id: 20210215115138.20465-15-peter.maydell@linaro.org
12
---
13
hw/arm/mps2-tz.c | 11 ++++++++---
14
1 file changed, 8 insertions(+), 3 deletions(-)
15
16
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/arm/mps2-tz.c
19
+++ b/hw/arm/mps2-tz.c
20
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
21
*/
22
memory_region_add_subregion(system_memory, 0x80000000, machine->ram);
23
24
- /* The overflow IRQs for all UARTs are ORed together.
25
+ /*
26
+ * The overflow IRQs for all UARTs are ORed together.
27
* Tx, Rx and "combined" IRQs are sent to the NVIC separately.
28
- * Create the OR gate for this.
29
+ * Create the OR gate for this: it has one input for the TX overflow
30
+ * and one for the RX overflow for each UART we might have.
31
+ * (If the board has fewer than the maximum possible number of UARTs
32
+ * those inputs are never wired up and are treated as always-zero.)
33
*/
34
object_initialize_child(OBJECT(mms), "uart-irq-orgate",
35
&mms->uart_irq_orgate, TYPE_OR_IRQ);
36
- object_property_set_int(OBJECT(&mms->uart_irq_orgate), "num-lines", 10,
37
+ object_property_set_int(OBJECT(&mms->uart_irq_orgate), "num-lines",
38
+ 2 * ARRAY_SIZE(mms->uart),
39
&error_fatal);
40
qdev_realize(DEVICE(&mms->uart_irq_orgate), NULL, &error_fatal);
41
qdev_connect_gpio_out(DEVICE(&mms->uart_irq_orgate), 0,
42
--
43
2.20.1
44
45
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
The AN505 and AN521 have the same device layout, but the AN524 is
2
somewhat different. Allow for more than one PPCInfo array, which can
3
be selected based on the board type.
2
4
3
This adds two new machines, both supported by OpenBMC:
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20210215115138.20465-16-peter.maydell@linaro.org
8
---
9
hw/arm/mps2-tz.c | 16 ++++++++++++++--
10
1 file changed, 14 insertions(+), 2 deletions(-)
4
11
5
- npcm750-evb: Nuvoton NPCM750 Evaluation Board.
12
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
6
- quanta-gsj: A board with a NPCM730 chip.
7
8
They rely on the NPCM7xx SoC device to do the heavy lifting. They are
9
almost completely identical at the moment, apart from the SoC type,
10
which currently only changes the reset contents of one register
11
(GCR.MDLR), but they might grow apart a bit more as more functionality
12
is added.
13
14
Both machines can boot the Linux kernel into /bin/sh.
15
16
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
17
Reviewed-by: Joel Stanley <joel@jms.id.au>
18
Reviewed-by: Cédric Le Goater <clg@kaod.org>
19
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
20
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
21
Tested-by: Alexander Bulekov <alxndr@bu.edu>
22
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
23
Message-id: 20200911052101.2602693-6-hskinnemoen@google.com
24
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
25
---
26
default-configs/arm-softmmu.mak | 1 +
27
include/hw/arm/npcm7xx.h | 19 +++++
28
hw/arm/npcm7xx_boards.c | 145 ++++++++++++++++++++++++++++++++
29
hw/arm/meson.build | 2 +-
30
4 files changed, 166 insertions(+), 1 deletion(-)
31
create mode 100644 hw/arm/npcm7xx_boards.c
32
33
diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
34
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
35
--- a/default-configs/arm-softmmu.mak
14
--- a/hw/arm/mps2-tz.c
36
+++ b/default-configs/arm-softmmu.mak
15
+++ b/hw/arm/mps2-tz.c
37
@@ -XXX,XX +XXX,XX @@ CONFIG_GUMSTIX=y
16
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
38
CONFIG_SPITZ=y
17
MemoryRegion *system_memory = get_system_memory();
39
CONFIG_TOSA=y
18
DeviceState *iotkitdev;
40
CONFIG_Z2=y
19
DeviceState *dev_splitter;
41
+CONFIG_NPCM7XX=y
20
+ const PPCInfo *ppcs;
42
CONFIG_COLLIE=y
21
+ int num_ppcs;
43
CONFIG_ASPEED_SOC=y
22
int i;
44
CONFIG_NETDUINO2=y
23
45
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
24
if (strcmp(machine->cpu_type, mc->default_cpu_type) != 0) {
46
index XXXXXXX..XXXXXXX 100644
25
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
47
--- a/include/hw/arm/npcm7xx.h
26
* + wire up the PPC's control lines to the IoTKit object
48
+++ b/include/hw/arm/npcm7xx.h
27
*/
49
@@ -XXX,XX +XXX,XX @@
28
50
#define NPCM7XX_SMP_BOOTREG_ADDR (0xf080013c) /* GCR.SCRPAD */
29
- const PPCInfo ppcs[] = { {
51
#define NPCM7XX_GIC_CPU_IF_ADDR (0xf03fe100) /* GIC within A9 */
30
+ const PPCInfo an505_ppcs[] = { {
52
31
.name = "apb_ppcexp0",
53
+typedef struct NPCM7xxMachine {
32
.ports = {
54
+ MachineState parent;
33
{ "ssram-0", make_mpc, &mms->ssram_mpc[0], 0x58007000, 0x1000 },
55
+} NPCM7xxMachine;
34
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
56
+
35
},
57
+#define TYPE_NPCM7XX_MACHINE MACHINE_TYPE_NAME("npcm7xx")
36
};
58
+#define NPCM7XX_MACHINE(obj) \
37
59
+ OBJECT_CHECK(NPCM7xxMachine, (obj), TYPE_NPCM7XX_MACHINE)
38
- for (i = 0; i < ARRAY_SIZE(ppcs); i++) {
60
+
39
+ switch (mmc->fpga_type) {
61
+typedef struct NPCM7xxMachineClass {
40
+ case FPGA_AN505:
62
+ MachineClass parent;
41
+ case FPGA_AN521:
63
+
42
+ ppcs = an505_ppcs;
64
+ const char *soc_type;
43
+ num_ppcs = ARRAY_SIZE(an505_ppcs);
65
+} NPCM7xxMachineClass;
44
+ break;
66
+
45
+ default:
67
+#define NPCM7XX_MACHINE_CLASS(klass) \
46
+ g_assert_not_reached();
68
+ OBJECT_CLASS_CHECK(NPCM7xxMachineClass, (klass), TYPE_NPCM7XX_MACHINE)
69
+#define NPCM7XX_MACHINE_GET_CLASS(obj) \
70
+ OBJECT_GET_CLASS(NPCM7xxMachineClass, (obj), TYPE_NPCM7XX_MACHINE)
71
+
72
typedef struct NPCM7xxState {
73
DeviceState parent;
74
75
diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c
76
new file mode 100644
77
index XXXXXXX..XXXXXXX
78
--- /dev/null
79
+++ b/hw/arm/npcm7xx_boards.c
80
@@ -XXX,XX +XXX,XX @@
81
+/*
82
+ * Machine definitions for boards featuring an NPCM7xx SoC.
83
+ *
84
+ * Copyright 2020 Google LLC
85
+ *
86
+ * This program is free software; you can redistribute it and/or modify it
87
+ * under the terms of the GNU General Public License as published by the
88
+ * Free Software Foundation; either version 2 of the License, or
89
+ * (at your option) any later version.
90
+ *
91
+ * This program is distributed in the hope that it will be useful, but WITHOUT
92
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
93
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
94
+ * for more details.
95
+ */
96
+
97
+#include "qemu/osdep.h"
98
+
99
+#include "exec/address-spaces.h"
100
+#include "hw/arm/npcm7xx.h"
101
+#include "hw/core/cpu.h"
102
+#include "qapi/error.h"
103
+#include "qemu/units.h"
104
+
105
+#define NPCM750_EVB_POWER_ON_STRAPS 0x00001ff7
106
+#define QUANTA_GSJ_POWER_ON_STRAPS 0x00001fff
107
+
108
+static void npcm7xx_connect_dram(NPCM7xxState *soc, MemoryRegion *dram)
109
+{
110
+ memory_region_add_subregion(get_system_memory(), NPCM7XX_DRAM_BA, dram);
111
+
112
+ object_property_set_link(OBJECT(soc), "dram-mr", OBJECT(dram),
113
+ &error_abort);
114
+}
115
+
116
+static NPCM7xxState *npcm7xx_create_soc(MachineState *machine,
117
+ uint32_t hw_straps)
118
+{
119
+ NPCM7xxMachineClass *nmc = NPCM7XX_MACHINE_GET_CLASS(machine);
120
+ MachineClass *mc = &nmc->parent;
121
+ Object *obj;
122
+
123
+ if (strcmp(machine->cpu_type, mc->default_cpu_type) != 0) {
124
+ error_report("This board can only be used with %s",
125
+ mc->default_cpu_type);
126
+ exit(1);
127
+ }
47
+ }
128
+
48
+
129
+ obj = object_new_with_props(nmc->soc_type, OBJECT(machine), "soc",
49
+ for (i = 0; i < num_ppcs; i++) {
130
+ &error_abort, NULL);
50
const PPCInfo *ppcinfo = &ppcs[i];
131
+ object_property_set_uint(obj, "power-on-straps", hw_straps, &error_abort);
51
TZPPC *ppc = &mms->ppc[i];
132
+
52
DeviceState *ppcdev;
133
+ return NPCM7XX(obj);
134
+}
135
+
136
+static void npcm750_evb_init(MachineState *machine)
137
+{
138
+ NPCM7xxState *soc;
139
+
140
+ soc = npcm7xx_create_soc(machine, NPCM750_EVB_POWER_ON_STRAPS);
141
+ npcm7xx_connect_dram(soc, machine->ram);
142
+ qdev_realize(DEVICE(soc), NULL, &error_fatal);
143
+
144
+ npcm7xx_load_kernel(machine, soc);
145
+}
146
+
147
+static void quanta_gsj_init(MachineState *machine)
148
+{
149
+ NPCM7xxState *soc;
150
+
151
+ soc = npcm7xx_create_soc(machine, QUANTA_GSJ_POWER_ON_STRAPS);
152
+ npcm7xx_connect_dram(soc, machine->ram);
153
+ qdev_realize(DEVICE(soc), NULL, &error_fatal);
154
+
155
+ npcm7xx_load_kernel(machine, soc);
156
+}
157
+
158
+static void npcm7xx_set_soc_type(NPCM7xxMachineClass *nmc, const char *type)
159
+{
160
+ NPCM7xxClass *sc = NPCM7XX_CLASS(object_class_by_name(type));
161
+ MachineClass *mc = MACHINE_CLASS(nmc);
162
+
163
+ nmc->soc_type = type;
164
+ mc->default_cpus = mc->min_cpus = mc->max_cpus = sc->num_cpus;
165
+}
166
+
167
+static void npcm7xx_machine_class_init(ObjectClass *oc, void *data)
168
+{
169
+ MachineClass *mc = MACHINE_CLASS(oc);
170
+
171
+ mc->no_floppy = 1;
172
+ mc->no_cdrom = 1;
173
+ mc->no_parallel = 1;
174
+ mc->default_ram_id = "ram";
175
+ mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a9");
176
+}
177
+
178
+/*
179
+ * Schematics:
180
+ * https://github.com/Nuvoton-Israel/nuvoton-info/blob/master/npcm7xx-poleg/evaluation-board/board_deliverables/NPCM750x_EB_ver.A1.1_COMPLETE.pdf
181
+ */
182
+static void npcm750_evb_machine_class_init(ObjectClass *oc, void *data)
183
+{
184
+ NPCM7xxMachineClass *nmc = NPCM7XX_MACHINE_CLASS(oc);
185
+ MachineClass *mc = MACHINE_CLASS(oc);
186
+
187
+ npcm7xx_set_soc_type(nmc, TYPE_NPCM750);
188
+
189
+ mc->desc = "Nuvoton NPCM750 Evaluation Board (Cortex A9)";
190
+ mc->init = npcm750_evb_init;
191
+ mc->default_ram_size = 512 * MiB;
192
+};
193
+
194
+static void gsj_machine_class_init(ObjectClass *oc, void *data)
195
+{
196
+ NPCM7xxMachineClass *nmc = NPCM7XX_MACHINE_CLASS(oc);
197
+ MachineClass *mc = MACHINE_CLASS(oc);
198
+
199
+ npcm7xx_set_soc_type(nmc, TYPE_NPCM730);
200
+
201
+ mc->desc = "Quanta GSJ (Cortex A9)";
202
+ mc->init = quanta_gsj_init;
203
+ mc->default_ram_size = 512 * MiB;
204
+};
205
+
206
+static const TypeInfo npcm7xx_machine_types[] = {
207
+ {
208
+ .name = TYPE_NPCM7XX_MACHINE,
209
+ .parent = TYPE_MACHINE,
210
+ .instance_size = sizeof(NPCM7xxMachine),
211
+ .class_size = sizeof(NPCM7xxMachineClass),
212
+ .class_init = npcm7xx_machine_class_init,
213
+ .abstract = true,
214
+ }, {
215
+ .name = MACHINE_TYPE_NAME("npcm750-evb"),
216
+ .parent = TYPE_NPCM7XX_MACHINE,
217
+ .class_init = npcm750_evb_machine_class_init,
218
+ }, {
219
+ .name = MACHINE_TYPE_NAME("quanta-gsj"),
220
+ .parent = TYPE_NPCM7XX_MACHINE,
221
+ .class_init = gsj_machine_class_init,
222
+ },
223
+};
224
+
225
+DEFINE_TYPES(npcm7xx_machine_types)
226
diff --git a/hw/arm/meson.build b/hw/arm/meson.build
227
index XXXXXXX..XXXXXXX 100644
228
--- a/hw/arm/meson.build
229
+++ b/hw/arm/meson.build
230
@@ -XXX,XX +XXX,XX @@ arm_ss.add(when: 'CONFIG_MICROBIT', if_true: files('microbit.c'))
231
arm_ss.add(when: 'CONFIG_MUSICPAL', if_true: files('musicpal.c'))
232
arm_ss.add(when: 'CONFIG_NETDUINO2', if_true: files('netduino2.c'))
233
arm_ss.add(when: 'CONFIG_NETDUINOPLUS2', if_true: files('netduinoplus2.c'))
234
-arm_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx.c'))
235
+arm_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx.c', 'npcm7xx_boards.c'))
236
arm_ss.add(when: 'CONFIG_NSERIES', if_true: files('nseries.c'))
237
arm_ss.add(when: 'CONFIG_SX1', if_true: files('omap_sx1.c'))
238
arm_ss.add(when: 'CONFIG_CHEETAH', if_true: files('palm.c'))
239
--
53
--
240
2.20.1
54
2.20.1
241
55
242
56
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
The AN505 and AN521 have the same layout of RAM; the AN524 does not.
2
2
Replace the current hard-coding of where the RAM is and which parts
3
The NPCM730 and NPCM750 SoCs have three timer modules each holding five
3
of it are behind which MPCs with a data-driven approach.
4
timers and some shared registers (e.g. interrupt status).
4
5
6
Each timer runs at 25 MHz divided by a prescaler, and counts down from a
7
configurable initial value to zero. When zero is reached, the interrupt
8
flag for the timer is set, and the timer is disabled (one-shot mode) or
9
reloaded from its initial value (periodic mode).
10
11
This implementation is sufficient to boot a Linux kernel configured for
12
NPCM750. Note that the kernel does not seem to actually turn on the
13
interrupts.
14
15
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
16
Reviewed-by: Joel Stanley <joel@jms.id.au>
17
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
18
Tested-by: Alexander Bulekov <alxndr@bu.edu>
19
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
20
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
21
Message-id: 20200911052101.2602693-4-hskinnemoen@google.com
22
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20210215115138.20465-17-peter.maydell@linaro.org
23
---
8
---
24
include/hw/timer/npcm7xx_timer.h | 78 +++++
9
hw/arm/mps2-tz.c | 175 +++++++++++++++++++++++++++++++++++++----------
25
hw/timer/npcm7xx_timer.c | 543 +++++++++++++++++++++++++++++++
10
1 file changed, 138 insertions(+), 37 deletions(-)
26
hw/timer/meson.build | 1 +
11
27
hw/timer/trace-events | 5 +
12
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
28
4 files changed, 627 insertions(+)
13
index XXXXXXX..XXXXXXX 100644
29
create mode 100644 include/hw/timer/npcm7xx_timer.h
14
--- a/hw/arm/mps2-tz.c
30
create mode 100644 hw/timer/npcm7xx_timer.c
15
+++ b/hw/arm/mps2-tz.c
31
32
diff --git a/include/hw/timer/npcm7xx_timer.h b/include/hw/timer/npcm7xx_timer.h
33
new file mode 100644
34
index XXXXXXX..XXXXXXX
35
--- /dev/null
36
+++ b/include/hw/timer/npcm7xx_timer.h
37
@@ -XXX,XX +XXX,XX @@
16
@@ -XXX,XX +XXX,XX @@
17
#include "qom/object.h"
18
19
#define MPS2TZ_NUMIRQ_MAX 92
20
+#define MPS2TZ_RAM_MAX 4
21
22
typedef enum MPS2TZFPGAType {
23
FPGA_AN505,
24
FPGA_AN521,
25
} MPS2TZFPGAType;
26
38
+/*
27
+/*
39
+ * Nuvoton NPCM7xx Timer Controller
28
+ * Define the layout of RAM in a board, including which parts are
40
+ *
29
+ * behind which MPCs.
41
+ * Copyright 2020 Google LLC
30
+ * mrindex specifies the index into mms->ram[] to use for the backing RAM;
42
+ *
31
+ * -1 means "use the system RAM".
43
+ * This program is free software; you can redistribute it and/or modify it
44
+ * under the terms of the GNU General Public License as published by the
45
+ * Free Software Foundation; either version 2 of the License, or
46
+ * (at your option) any later version.
47
+ *
48
+ * This program is distributed in the hope that it will be useful, but WITHOUT
49
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
50
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
51
+ * for more details.
52
+ */
32
+ */
53
+#ifndef NPCM7XX_TIMER_H
33
+typedef struct RAMInfo {
54
+#define NPCM7XX_TIMER_H
34
+ const char *name;
55
+
35
+ uint32_t base;
56
+#include "exec/memory.h"
36
+ uint32_t size;
57
+#include "hw/sysbus.h"
37
+ int mpc; /* MPC number, -1 for "not behind an MPC" */
58
+#include "qemu/timer.h"
38
+ int mrindex;
59
+
39
+ int flags;
60
+/* Each Timer Module (TIM) instance holds five 25 MHz timers. */
40
+} RAMInfo;
61
+#define NPCM7XX_TIMERS_PER_CTRL (5)
62
+
41
+
63
+/*
42
+/*
64
+ * Number of registers in our device state structure. Don't change this without
43
+ * Flag values:
65
+ * incrementing the version_id in the vmstate.
44
+ * IS_ALIAS: this RAM area is an alias to the upstream end of the
45
+ * MPC specified by its .mpc value
66
+ */
46
+ */
67
+#define NPCM7XX_TIMER_NR_REGS (0x54 / sizeof(uint32_t))
47
+#define IS_ALIAS 1
68
+
48
+
69
+typedef struct NPCM7xxTimerCtrlState NPCM7xxTimerCtrlState;
49
struct MPS2TZMachineClass {
70
+
50
MachineClass parent;
71
+/**
51
MPS2TZFPGAType fpga_type;
72
+ * struct NPCM7xxTimer - Individual timer state.
52
@@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineClass {
73
+ * @irq: GIC interrupt line to fire on expiration (if enabled).
53
uint32_t fpgaio_num_leds; /* Number of LEDs in FPGAIO LED0 register */
74
+ * @qtimer: QEMU timer that notifies us on expiration.
54
bool fpgaio_has_switches; /* Does FPGAIO have SWITCH register? */
75
+ * @expires_ns: Absolute virtual expiration time.
55
int numirq; /* Number of external interrupts */
76
+ * @remaining_ns: Remaining time until expiration if timer is paused.
56
+ const RAMInfo *raminfo;
77
+ * @tcsr: The Timer Control and Status Register.
57
const char *armsse_type;
78
+ * @ticr: The Timer Initial Count Register.
58
};
79
+ */
59
80
+typedef struct NPCM7xxTimer {
60
@@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineState {
81
+ NPCM7xxTimerCtrlState *ctrl;
61
MachineState parent;
82
+
62
83
+ qemu_irq irq;
63
ARMSSE iotkit;
84
+ QEMUTimer qtimer;
64
- MemoryRegion ssram[3];
85
+ int64_t expires_ns;
65
- MemoryRegion ssram1_m;
86
+ int64_t remaining_ns;
66
+ MemoryRegion ram[MPS2TZ_RAM_MAX];
87
+
67
MPS2SCC scc;
88
+ uint32_t tcsr;
68
MPS2FPGAIO fpgaio;
89
+ uint32_t ticr;
69
TZPPC ppc[5];
90
+} NPCM7xxTimer;
70
- TZMPC ssram_mpc[3];
91
+
71
+ TZMPC mpc[3];
92
+/**
72
PL022State spi[5];
93
+ * struct NPCM7xxTimerCtrlState - Timer Module device state.
73
ArmSbconI2CState i2c[4];
94
+ * @parent: System bus device.
74
UnimplementedDeviceState i2s_audio;
95
+ * @iomem: Memory region through which registers are accessed.
75
@@ -XXX,XX +XXX,XX @@ static const uint32_t an505_oscclk[] = {
96
+ * @tisr: The Timer Interrupt Status Register.
76
25000000,
97
+ * @wtcr: The Watchdog Timer Control Register.
77
};
98
+ * @timer: The five individual timers managed by this module.
78
99
+ */
79
+static const RAMInfo an505_raminfo[] = { {
100
+struct NPCM7xxTimerCtrlState {
80
+ .name = "ssram-0",
101
+ SysBusDevice parent;
81
+ .base = 0x00000000,
102
+
82
+ .size = 0x00400000,
103
+ MemoryRegion iomem;
83
+ .mpc = 0,
104
+
84
+ .mrindex = 0,
105
+ uint32_t tisr;
85
+ }, {
106
+ uint32_t wtcr;
86
+ .name = "ssram-1",
107
+
87
+ .base = 0x28000000,
108
+ NPCM7xxTimer timer[NPCM7XX_TIMERS_PER_CTRL];
88
+ .size = 0x00200000,
89
+ .mpc = 1,
90
+ .mrindex = 1,
91
+ }, {
92
+ .name = "ssram-2",
93
+ .base = 0x28200000,
94
+ .size = 0x00200000,
95
+ .mpc = 2,
96
+ .mrindex = 2,
97
+ }, {
98
+ .name = "ssram-0-alias",
99
+ .base = 0x00400000,
100
+ .size = 0x00400000,
101
+ .mpc = 0,
102
+ .mrindex = 3,
103
+ .flags = IS_ALIAS,
104
+ }, {
105
+ /* Use the largest bit of contiguous RAM as our "system memory" */
106
+ .name = "mps.ram",
107
+ .base = 0x80000000,
108
+ .size = 16 * MiB,
109
+ .mpc = -1,
110
+ .mrindex = -1,
111
+ }, {
112
+ .name = NULL,
113
+ },
109
+};
114
+};
110
+
115
+
111
+#define TYPE_NPCM7XX_TIMER "npcm7xx-timer"
116
+static const RAMInfo *find_raminfo_for_mpc(MPS2TZMachineState *mms, int mpc)
112
+#define NPCM7XX_TIMER(obj) \
113
+ OBJECT_CHECK(NPCM7xxTimerCtrlState, (obj), TYPE_NPCM7XX_TIMER)
114
+
115
+#endif /* NPCM7XX_TIMER_H */
116
diff --git a/hw/timer/npcm7xx_timer.c b/hw/timer/npcm7xx_timer.c
117
new file mode 100644
118
index XXXXXXX..XXXXXXX
119
--- /dev/null
120
+++ b/hw/timer/npcm7xx_timer.c
121
@@ -XXX,XX +XXX,XX @@
122
+/*
123
+ * Nuvoton NPCM7xx Timer Controller
124
+ *
125
+ * Copyright 2020 Google LLC
126
+ *
127
+ * This program is free software; you can redistribute it and/or modify it
128
+ * under the terms of the GNU General Public License as published by the
129
+ * Free Software Foundation; either version 2 of the License, or
130
+ * (at your option) any later version.
131
+ *
132
+ * This program is distributed in the hope that it will be useful, but WITHOUT
133
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
134
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
135
+ * for more details.
136
+ */
137
+
138
+#include "qemu/osdep.h"
139
+
140
+#include "hw/irq.h"
141
+#include "hw/misc/npcm7xx_clk.h"
142
+#include "hw/timer/npcm7xx_timer.h"
143
+#include "migration/vmstate.h"
144
+#include "qemu/bitops.h"
145
+#include "qemu/error-report.h"
146
+#include "qemu/log.h"
147
+#include "qemu/module.h"
148
+#include "qemu/timer.h"
149
+#include "qemu/units.h"
150
+#include "trace.h"
151
+
152
+/* 32-bit register indices. */
153
+enum NPCM7xxTimerRegisters {
154
+ NPCM7XX_TIMER_TCSR0,
155
+ NPCM7XX_TIMER_TCSR1,
156
+ NPCM7XX_TIMER_TICR0,
157
+ NPCM7XX_TIMER_TICR1,
158
+ NPCM7XX_TIMER_TDR0,
159
+ NPCM7XX_TIMER_TDR1,
160
+ NPCM7XX_TIMER_TISR,
161
+ NPCM7XX_TIMER_WTCR,
162
+ NPCM7XX_TIMER_TCSR2,
163
+ NPCM7XX_TIMER_TCSR3,
164
+ NPCM7XX_TIMER_TICR2,
165
+ NPCM7XX_TIMER_TICR3,
166
+ NPCM7XX_TIMER_TDR2,
167
+ NPCM7XX_TIMER_TDR3,
168
+ NPCM7XX_TIMER_TCSR4 = 0x0040 / sizeof(uint32_t),
169
+ NPCM7XX_TIMER_TICR4 = 0x0048 / sizeof(uint32_t),
170
+ NPCM7XX_TIMER_TDR4 = 0x0050 / sizeof(uint32_t),
171
+ NPCM7XX_TIMER_REGS_END,
172
+};
173
+
174
+/* Register field definitions. */
175
+#define NPCM7XX_TCSR_CEN BIT(30)
176
+#define NPCM7XX_TCSR_IE BIT(29)
177
+#define NPCM7XX_TCSR_PERIODIC BIT(27)
178
+#define NPCM7XX_TCSR_CRST BIT(26)
179
+#define NPCM7XX_TCSR_CACT BIT(25)
180
+#define NPCM7XX_TCSR_RSVD 0x01ffff00
181
+#define NPCM7XX_TCSR_PRESCALE_START 0
182
+#define NPCM7XX_TCSR_PRESCALE_LEN 8
183
+
184
+/*
185
+ * Returns the index of timer in the tc->timer array. This can be used to
186
+ * locate the registers that belong to this timer.
187
+ */
188
+static int npcm7xx_timer_index(NPCM7xxTimerCtrlState *tc, NPCM7xxTimer *timer)
189
+{
117
+{
190
+ int index = timer - tc->timer;
118
+ MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
191
+
119
+ const RAMInfo *p;
192
+ g_assert(index >= 0 && index < NPCM7XX_TIMERS_PER_CTRL);
120
+
193
+
121
+ for (p = mmc->raminfo; p->name; p++) {
194
+ return index;
122
+ if (p->mpc == mpc && !(p->flags & IS_ALIAS)) {
195
+}
123
+ return p;
196
+
197
+/* Return the value by which to divide the reference clock rate. */
198
+static uint32_t npcm7xx_tcsr_prescaler(uint32_t tcsr)
199
+{
200
+ return extract32(tcsr, NPCM7XX_TCSR_PRESCALE_START,
201
+ NPCM7XX_TCSR_PRESCALE_LEN) + 1;
202
+}
203
+
204
+/* Convert a timer cycle count to a time interval in nanoseconds. */
205
+static int64_t npcm7xx_timer_count_to_ns(NPCM7xxTimer *t, uint32_t count)
206
+{
207
+ int64_t ns = count;
208
+
209
+ ns *= NANOSECONDS_PER_SECOND / NPCM7XX_TIMER_REF_HZ;
210
+ ns *= npcm7xx_tcsr_prescaler(t->tcsr);
211
+
212
+ return ns;
213
+}
214
+
215
+/* Convert a time interval in nanoseconds to a timer cycle count. */
216
+static uint32_t npcm7xx_timer_ns_to_count(NPCM7xxTimer *t, int64_t ns)
217
+{
218
+ int64_t count;
219
+
220
+ count = ns / (NANOSECONDS_PER_SECOND / NPCM7XX_TIMER_REF_HZ);
221
+ count /= npcm7xx_tcsr_prescaler(t->tcsr);
222
+
223
+ return count;
224
+}
225
+
226
+/*
227
+ * Raise the interrupt line if there's a pending interrupt and interrupts are
228
+ * enabled for this timer. If not, lower it.
229
+ */
230
+static void npcm7xx_timer_check_interrupt(NPCM7xxTimer *t)
231
+{
232
+ NPCM7xxTimerCtrlState *tc = t->ctrl;
233
+ int index = npcm7xx_timer_index(tc, t);
234
+ bool pending = (t->tcsr & NPCM7XX_TCSR_IE) && (tc->tisr & BIT(index));
235
+
236
+ qemu_set_irq(t->irq, pending);
237
+ trace_npcm7xx_timer_irq(DEVICE(tc)->canonical_path, index, pending);
238
+}
239
+
240
+/* Start or resume the timer. */
241
+static void npcm7xx_timer_start(NPCM7xxTimer *t)
242
+{
243
+ int64_t now;
244
+
245
+ now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
246
+ t->expires_ns = now + t->remaining_ns;
247
+ timer_mod(&t->qtimer, t->expires_ns);
248
+}
249
+
250
+/*
251
+ * Called when the counter reaches zero. Sets the interrupt flag, and either
252
+ * restarts or disables the timer.
253
+ */
254
+static void npcm7xx_timer_reached_zero(NPCM7xxTimer *t)
255
+{
256
+ NPCM7xxTimerCtrlState *tc = t->ctrl;
257
+ int index = npcm7xx_timer_index(tc, t);
258
+
259
+ tc->tisr |= BIT(index);
260
+
261
+ if (t->tcsr & NPCM7XX_TCSR_PERIODIC) {
262
+ t->remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr);
263
+ if (t->tcsr & NPCM7XX_TCSR_CEN) {
264
+ npcm7xx_timer_start(t);
265
+ }
266
+ } else {
267
+ t->tcsr &= ~(NPCM7XX_TCSR_CEN | NPCM7XX_TCSR_CACT);
268
+ }
269
+
270
+ npcm7xx_timer_check_interrupt(t);
271
+}
272
+
273
+/* Stop counting. Record the time remaining so we can continue later. */
274
+static void npcm7xx_timer_pause(NPCM7xxTimer *t)
275
+{
276
+ int64_t now;
277
+
278
+ timer_del(&t->qtimer);
279
+ now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
280
+ t->remaining_ns = t->expires_ns - now;
281
+ if (t->remaining_ns <= 0) {
282
+ npcm7xx_timer_reached_zero(t);
283
+ }
284
+}
285
+
286
+/*
287
+ * Restart the timer from its initial value. If the timer was enabled and stays
288
+ * enabled, adjust the QEMU timer according to the new count. If the timer is
289
+ * transitioning from disabled to enabled, the caller is expected to start the
290
+ * timer later.
291
+ */
292
+static void npcm7xx_timer_restart(NPCM7xxTimer *t, uint32_t old_tcsr)
293
+{
294
+ t->remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr);
295
+
296
+ if (old_tcsr & t->tcsr & NPCM7XX_TCSR_CEN) {
297
+ npcm7xx_timer_start(t);
298
+ }
299
+}
300
+
301
+/* Register read and write handlers */
302
+
303
+static uint32_t npcm7xx_timer_read_tdr(NPCM7xxTimer *t)
304
+{
305
+ if (t->tcsr & NPCM7XX_TCSR_CEN) {
306
+ int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
307
+
308
+ return npcm7xx_timer_ns_to_count(t, t->expires_ns - now);
309
+ }
310
+
311
+ return npcm7xx_timer_ns_to_count(t, t->remaining_ns);
312
+}
313
+
314
+static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr)
315
+{
316
+ uint32_t old_tcsr = t->tcsr;
317
+ uint32_t tdr;
318
+
319
+ if (new_tcsr & NPCM7XX_TCSR_RSVD) {
320
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: reserved bits in 0x%08x ignored\n",
321
+ __func__, new_tcsr);
322
+ new_tcsr &= ~NPCM7XX_TCSR_RSVD;
323
+ }
324
+ if (new_tcsr & NPCM7XX_TCSR_CACT) {
325
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: read-only bits in 0x%08x ignored\n",
326
+ __func__, new_tcsr);
327
+ new_tcsr &= ~NPCM7XX_TCSR_CACT;
328
+ }
329
+ if ((new_tcsr & NPCM7XX_TCSR_CRST) && (new_tcsr & NPCM7XX_TCSR_CEN)) {
330
+ qemu_log_mask(LOG_GUEST_ERROR,
331
+ "%s: both CRST and CEN set; ignoring CEN.\n",
332
+ __func__);
333
+ new_tcsr &= ~NPCM7XX_TCSR_CEN;
334
+ }
335
+
336
+ /* Calculate the value of TDR before potentially changing the prescaler. */
337
+ tdr = npcm7xx_timer_read_tdr(t);
338
+
339
+ t->tcsr = (t->tcsr & NPCM7XX_TCSR_CACT) | new_tcsr;
340
+
341
+ if (npcm7xx_tcsr_prescaler(old_tcsr) != npcm7xx_tcsr_prescaler(new_tcsr)) {
342
+ /* Recalculate time remaining based on the current TDR value. */
343
+ t->remaining_ns = npcm7xx_timer_count_to_ns(t, tdr);
344
+ if (old_tcsr & t->tcsr & NPCM7XX_TCSR_CEN) {
345
+ npcm7xx_timer_start(t);
346
+ }
124
+ }
347
+ }
125
+ }
348
+
126
+ /* if raminfo array doesn't have an entry for each MPC this is a bug */
349
+ if ((old_tcsr ^ new_tcsr) & NPCM7XX_TCSR_IE) {
127
+ g_assert_not_reached();
350
+ npcm7xx_timer_check_interrupt(t);
128
+}
129
+
130
+static MemoryRegion *mr_for_raminfo(MPS2TZMachineState *mms,
131
+ const RAMInfo *raminfo)
132
+{
133
+ /* Return an initialized MemoryRegion for the RAMInfo. */
134
+ MemoryRegion *ram;
135
+
136
+ if (raminfo->mrindex < 0) {
137
+ /* Means this RAMInfo is for QEMU's "system memory" */
138
+ MachineState *machine = MACHINE(mms);
139
+ return machine->ram;
351
+ }
140
+ }
352
+ if (new_tcsr & NPCM7XX_TCSR_CRST) {
141
+
353
+ npcm7xx_timer_restart(t, old_tcsr);
142
+ assert(raminfo->mrindex < MPS2TZ_RAM_MAX);
354
+ t->tcsr &= ~NPCM7XX_TCSR_CRST;
143
+ ram = &mms->ram[raminfo->mrindex];
355
+ }
144
+
356
+ if ((old_tcsr ^ new_tcsr) & NPCM7XX_TCSR_CEN) {
145
+ memory_region_init_ram(ram, NULL, raminfo->name,
357
+ if (new_tcsr & NPCM7XX_TCSR_CEN) {
146
+ raminfo->size, &error_fatal);
358
+ t->tcsr |= NPCM7XX_TCSR_CACT;
147
+ return ram;
359
+ npcm7xx_timer_start(t);
148
+}
360
+ } else {
149
+
361
+ t->tcsr &= ~NPCM7XX_TCSR_CACT;
150
/* Create an alias of an entire original MemoryRegion @orig
362
+ npcm7xx_timer_pause(t);
151
* located at @base in the memory map.
152
*/
153
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_mpc(MPS2TZMachineState *mms, void *opaque,
154
const int *irqs)
155
{
156
TZMPC *mpc = opaque;
157
- int i = mpc - &mms->ssram_mpc[0];
158
- MemoryRegion *ssram = &mms->ssram[i];
159
+ int i = mpc - &mms->mpc[0];
160
MemoryRegion *upstream;
161
- char *mpcname = g_strdup_printf("%s-mpc", name);
162
- static uint32_t ramsize[] = { 0x00400000, 0x00200000, 0x00200000 };
163
- static uint32_t rambase[] = { 0x00000000, 0x28000000, 0x28200000 };
164
+ const RAMInfo *raminfo = find_raminfo_for_mpc(mms, i);
165
+ MemoryRegion *ram = mr_for_raminfo(mms, raminfo);
166
167
- memory_region_init_ram(ssram, NULL, name, ramsize[i], &error_fatal);
168
-
169
- object_initialize_child(OBJECT(mms), mpcname, mpc, TYPE_TZ_MPC);
170
- object_property_set_link(OBJECT(mpc), "downstream", OBJECT(ssram),
171
+ object_initialize_child(OBJECT(mms), name, mpc, TYPE_TZ_MPC);
172
+ object_property_set_link(OBJECT(mpc), "downstream", OBJECT(ram),
173
&error_fatal);
174
sysbus_realize(SYS_BUS_DEVICE(mpc), &error_fatal);
175
/* Map the upstream end of the MPC into system memory */
176
upstream = sysbus_mmio_get_region(SYS_BUS_DEVICE(mpc), 1);
177
- memory_region_add_subregion(get_system_memory(), rambase[i], upstream);
178
+ memory_region_add_subregion(get_system_memory(), raminfo->base, upstream);
179
/* and connect its interrupt to the IoTKit */
180
qdev_connect_gpio_out_named(DEVICE(mpc), "irq", 0,
181
qdev_get_gpio_in_named(DEVICE(&mms->iotkit),
182
"mpcexp_status", i));
183
184
- /* The first SSRAM is a special case as it has an alias; accesses to
185
- * the alias region at 0x00400000 must also go to the MPC upstream.
186
- */
187
- if (i == 0) {
188
- make_ram_alias(&mms->ssram1_m, "mps.ssram1_m", upstream, 0x00400000);
189
- }
190
-
191
- g_free(mpcname);
192
/* Return the register interface MR for our caller to map behind the PPC */
193
return sysbus_mmio_get_region(SYS_BUS_DEVICE(mpc), 0);
194
}
195
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_i2c(MPS2TZMachineState *mms, void *opaque,
196
return sysbus_mmio_get_region(s, 0);
197
}
198
199
+static void create_non_mpc_ram(MPS2TZMachineState *mms)
200
+{
201
+ /*
202
+ * Handle the RAMs which are either not behind MPCs or which are
203
+ * aliases to another MPC.
204
+ */
205
+ const RAMInfo *p;
206
+ MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
207
+
208
+ for (p = mmc->raminfo; p->name; p++) {
209
+ if (p->flags & IS_ALIAS) {
210
+ SysBusDevice *mpc_sbd = SYS_BUS_DEVICE(&mms->mpc[p->mpc]);
211
+ MemoryRegion *upstream = sysbus_mmio_get_region(mpc_sbd, 1);
212
+ make_ram_alias(&mms->ram[p->mrindex], p->name, upstream, p->base);
213
+ } else if (p->mpc == -1) {
214
+ /* RAM not behind an MPC */
215
+ MemoryRegion *mr = mr_for_raminfo(mms, p);
216
+ memory_region_add_subregion(get_system_memory(), p->base, mr);
363
+ }
217
+ }
364
+ }
218
+ }
365
+}
219
+}
366
+
220
+
367
+static void npcm7xx_timer_write_ticr(NPCM7xxTimer *t, uint32_t new_ticr)
221
static void mps2tz_common_init(MachineState *machine)
368
+{
222
{
369
+ t->ticr = new_ticr;
223
MPS2TZMachineState *mms = MPS2TZ_MACHINE(machine);
370
+
224
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
371
+ npcm7xx_timer_restart(t, t->tcsr);
225
qdev_connect_gpio_out_named(iotkitdev, "sec_resp_cfg", 0,
372
+}
226
qdev_get_gpio_in(dev_splitter, 0));
373
+
227
374
+static void npcm7xx_timer_write_tisr(NPCM7xxTimerCtrlState *s, uint32_t value)
228
- /* The IoTKit sets up much of the memory layout, including
375
+{
229
+ /*
376
+ int i;
230
+ * The IoTKit sets up much of the memory layout, including
377
+
231
* the aliases between secure and non-secure regions in the
378
+ s->tisr &= ~value;
232
- * address space. The FPGA itself contains:
379
+ for (i = 0; i < ARRAY_SIZE(s->timer); i++) {
233
- *
380
+ if (value & (1U << i)) {
234
- * 0x00000000..0x003fffff SSRAM1
381
+ npcm7xx_timer_check_interrupt(&s->timer[i]);
235
- * 0x00400000..0x007fffff alias of SSRAM1
382
+ }
236
- * 0x28000000..0x283fffff 4MB SSRAM2 + SSRAM3
383
+ }
237
- * 0x40100000..0x4fffffff AHB Master Expansion 1 interface devices
384
+}
238
- * 0x80000000..0x80ffffff 16MB PSRAM
385
+
239
- */
386
+static hwaddr npcm7xx_tcsr_index(hwaddr reg)
240
-
387
+{
241
- /* The FPGA images have an odd combination of different RAMs,
388
+ switch (reg) {
242
+ * address space, and also most of the devices in the system.
389
+ case NPCM7XX_TIMER_TCSR0:
243
+ * The FPGA itself contains various RAMs and some additional devices.
390
+ return 0;
244
+ * The FPGA images have an odd combination of different RAMs,
391
+ case NPCM7XX_TIMER_TCSR1:
245
* because in hardware they are different implementations and
392
+ return 1;
246
* connected to different buses, giving varying performance/size
393
+ case NPCM7XX_TIMER_TCSR2:
247
* tradeoffs. For QEMU they're all just RAM, though. We arbitrarily
394
+ return 2;
248
- * call the 16MB our "system memory", as it's the largest lump.
395
+ case NPCM7XX_TIMER_TCSR3:
249
+ * call the largest lump our "system memory".
396
+ return 3;
250
*/
397
+ case NPCM7XX_TIMER_TCSR4:
251
- memory_region_add_subregion(system_memory, 0x80000000, machine->ram);
398
+ return 4;
252
399
+ default:
253
/*
400
+ g_assert_not_reached();
254
* The overflow IRQs for all UARTs are ORed together.
401
+ }
255
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
402
+}
256
const PPCInfo an505_ppcs[] = { {
403
+
257
.name = "apb_ppcexp0",
404
+static hwaddr npcm7xx_ticr_index(hwaddr reg)
258
.ports = {
405
+{
259
- { "ssram-0", make_mpc, &mms->ssram_mpc[0], 0x58007000, 0x1000 },
406
+ switch (reg) {
260
- { "ssram-1", make_mpc, &mms->ssram_mpc[1], 0x58008000, 0x1000 },
407
+ case NPCM7XX_TIMER_TICR0:
261
- { "ssram-2", make_mpc, &mms->ssram_mpc[2], 0x58009000, 0x1000 },
408
+ return 0;
262
+ { "ssram-0-mpc", make_mpc, &mms->mpc[0], 0x58007000, 0x1000 },
409
+ case NPCM7XX_TIMER_TICR1:
263
+ { "ssram-1-mpc", make_mpc, &mms->mpc[1], 0x58008000, 0x1000 },
410
+ return 1;
264
+ { "ssram-2-mpc", make_mpc, &mms->mpc[2], 0x58009000, 0x1000 },
411
+ case NPCM7XX_TIMER_TICR2:
265
},
412
+ return 2;
266
}, {
413
+ case NPCM7XX_TIMER_TICR3:
267
.name = "apb_ppcexp1",
414
+ return 3;
268
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
415
+ case NPCM7XX_TIMER_TICR4:
269
416
+ return 4;
270
create_unimplemented_device("FPGA NS PC", 0x48007000, 0x1000);
417
+ default:
271
418
+ g_assert_not_reached();
272
+ create_non_mpc_ram(mms);
419
+ }
273
+
420
+}
274
armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename, 0x400000);
421
+
275
}
422
+static hwaddr npcm7xx_tdr_index(hwaddr reg)
276
423
+{
277
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an505_class_init(ObjectClass *oc, void *data)
424
+ switch (reg) {
278
mmc->fpgaio_num_leds = 2;
425
+ case NPCM7XX_TIMER_TDR0:
279
mmc->fpgaio_has_switches = false;
426
+ return 0;
280
mmc->numirq = 92;
427
+ case NPCM7XX_TIMER_TDR1:
281
+ mmc->raminfo = an505_raminfo;
428
+ return 1;
282
mmc->armsse_type = TYPE_IOTKIT;
429
+ case NPCM7XX_TIMER_TDR2:
283
}
430
+ return 2;
284
431
+ case NPCM7XX_TIMER_TDR3:
285
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an521_class_init(ObjectClass *oc, void *data)
432
+ return 3;
286
mmc->fpgaio_num_leds = 2;
433
+ case NPCM7XX_TIMER_TDR4:
287
mmc->fpgaio_has_switches = false;
434
+ return 4;
288
mmc->numirq = 92;
435
+ default:
289
+ mmc->raminfo = an505_raminfo; /* AN521 is the same as AN505 here */
436
+ g_assert_not_reached();
290
mmc->armsse_type = TYPE_SSE200;
437
+ }
291
}
438
+}
292
439
+
440
+static uint64_t npcm7xx_timer_read(void *opaque, hwaddr offset, unsigned size)
441
+{
442
+ NPCM7xxTimerCtrlState *s = opaque;
443
+ uint64_t value = 0;
444
+ hwaddr reg;
445
+
446
+ reg = offset / sizeof(uint32_t);
447
+ switch (reg) {
448
+ case NPCM7XX_TIMER_TCSR0:
449
+ case NPCM7XX_TIMER_TCSR1:
450
+ case NPCM7XX_TIMER_TCSR2:
451
+ case NPCM7XX_TIMER_TCSR3:
452
+ case NPCM7XX_TIMER_TCSR4:
453
+ value = s->timer[npcm7xx_tcsr_index(reg)].tcsr;
454
+ break;
455
+
456
+ case NPCM7XX_TIMER_TICR0:
457
+ case NPCM7XX_TIMER_TICR1:
458
+ case NPCM7XX_TIMER_TICR2:
459
+ case NPCM7XX_TIMER_TICR3:
460
+ case NPCM7XX_TIMER_TICR4:
461
+ value = s->timer[npcm7xx_ticr_index(reg)].ticr;
462
+ break;
463
+
464
+ case NPCM7XX_TIMER_TDR0:
465
+ case NPCM7XX_TIMER_TDR1:
466
+ case NPCM7XX_TIMER_TDR2:
467
+ case NPCM7XX_TIMER_TDR3:
468
+ case NPCM7XX_TIMER_TDR4:
469
+ value = npcm7xx_timer_read_tdr(&s->timer[npcm7xx_tdr_index(reg)]);
470
+ break;
471
+
472
+ case NPCM7XX_TIMER_TISR:
473
+ value = s->tisr;
474
+ break;
475
+
476
+ case NPCM7XX_TIMER_WTCR:
477
+ value = s->wtcr;
478
+ break;
479
+
480
+ default:
481
+ qemu_log_mask(LOG_GUEST_ERROR,
482
+ "%s: invalid offset 0x%04" HWADDR_PRIx "\n",
483
+ __func__, offset);
484
+ break;
485
+ }
486
+
487
+ trace_npcm7xx_timer_read(DEVICE(s)->canonical_path, offset, value);
488
+
489
+ return value;
490
+}
491
+
492
+static void npcm7xx_timer_write(void *opaque, hwaddr offset,
493
+ uint64_t v, unsigned size)
494
+{
495
+ uint32_t reg = offset / sizeof(uint32_t);
496
+ NPCM7xxTimerCtrlState *s = opaque;
497
+ uint32_t value = v;
498
+
499
+ trace_npcm7xx_timer_write(DEVICE(s)->canonical_path, offset, value);
500
+
501
+ switch (reg) {
502
+ case NPCM7XX_TIMER_TCSR0:
503
+ case NPCM7XX_TIMER_TCSR1:
504
+ case NPCM7XX_TIMER_TCSR2:
505
+ case NPCM7XX_TIMER_TCSR3:
506
+ case NPCM7XX_TIMER_TCSR4:
507
+ npcm7xx_timer_write_tcsr(&s->timer[npcm7xx_tcsr_index(reg)], value);
508
+ return;
509
+
510
+ case NPCM7XX_TIMER_TICR0:
511
+ case NPCM7XX_TIMER_TICR1:
512
+ case NPCM7XX_TIMER_TICR2:
513
+ case NPCM7XX_TIMER_TICR3:
514
+ case NPCM7XX_TIMER_TICR4:
515
+ npcm7xx_timer_write_ticr(&s->timer[npcm7xx_ticr_index(reg)], value);
516
+ return;
517
+
518
+ case NPCM7XX_TIMER_TDR0:
519
+ case NPCM7XX_TIMER_TDR1:
520
+ case NPCM7XX_TIMER_TDR2:
521
+ case NPCM7XX_TIMER_TDR3:
522
+ case NPCM7XX_TIMER_TDR4:
523
+ qemu_log_mask(LOG_GUEST_ERROR,
524
+ "%s: register @ 0x%04" HWADDR_PRIx " is read-only\n",
525
+ __func__, offset);
526
+ return;
527
+
528
+ case NPCM7XX_TIMER_TISR:
529
+ npcm7xx_timer_write_tisr(s, value);
530
+ return;
531
+
532
+ case NPCM7XX_TIMER_WTCR:
533
+ qemu_log_mask(LOG_UNIMP, "%s: WTCR write not implemented: 0x%08x\n",
534
+ __func__, value);
535
+ return;
536
+ }
537
+
538
+ qemu_log_mask(LOG_GUEST_ERROR,
539
+ "%s: invalid offset 0x%04" HWADDR_PRIx "\n",
540
+ __func__, offset);
541
+}
542
+
543
+static const struct MemoryRegionOps npcm7xx_timer_ops = {
544
+ .read = npcm7xx_timer_read,
545
+ .write = npcm7xx_timer_write,
546
+ .endianness = DEVICE_LITTLE_ENDIAN,
547
+ .valid = {
548
+ .min_access_size = 4,
549
+ .max_access_size = 4,
550
+ .unaligned = false,
551
+ },
552
+};
553
+
554
+/* Called when the QEMU timer expires. */
555
+static void npcm7xx_timer_expired(void *opaque)
556
+{
557
+ NPCM7xxTimer *t = opaque;
558
+
559
+ if (t->tcsr & NPCM7XX_TCSR_CEN) {
560
+ npcm7xx_timer_reached_zero(t);
561
+ }
562
+}
563
+
564
+static void npcm7xx_timer_enter_reset(Object *obj, ResetType type)
565
+{
566
+ NPCM7xxTimerCtrlState *s = NPCM7XX_TIMER(obj);
567
+ int i;
568
+
569
+ for (i = 0; i < NPCM7XX_TIMERS_PER_CTRL; i++) {
570
+ NPCM7xxTimer *t = &s->timer[i];
571
+
572
+ timer_del(&t->qtimer);
573
+ t->expires_ns = 0;
574
+ t->remaining_ns = 0;
575
+ t->tcsr = 0x00000005;
576
+ t->ticr = 0x00000000;
577
+ }
578
+
579
+ s->tisr = 0x00000000;
580
+ s->wtcr = 0x00000400;
581
+}
582
+
583
+static void npcm7xx_timer_hold_reset(Object *obj)
584
+{
585
+ NPCM7xxTimerCtrlState *s = NPCM7XX_TIMER(obj);
586
+ int i;
587
+
588
+ for (i = 0; i < NPCM7XX_TIMERS_PER_CTRL; i++) {
589
+ qemu_irq_lower(s->timer[i].irq);
590
+ }
591
+}
592
+
593
+static void npcm7xx_timer_realize(DeviceState *dev, Error **errp)
594
+{
595
+ NPCM7xxTimerCtrlState *s = NPCM7XX_TIMER(dev);
596
+ SysBusDevice *sbd = &s->parent;
597
+ int i;
598
+
599
+ for (i = 0; i < NPCM7XX_TIMERS_PER_CTRL; i++) {
600
+ NPCM7xxTimer *t = &s->timer[i];
601
+ t->ctrl = s;
602
+ timer_init_ns(&t->qtimer, QEMU_CLOCK_VIRTUAL, npcm7xx_timer_expired, t);
603
+ sysbus_init_irq(sbd, &t->irq);
604
+ }
605
+
606
+ memory_region_init_io(&s->iomem, OBJECT(s), &npcm7xx_timer_ops, s,
607
+ TYPE_NPCM7XX_TIMER, 4 * KiB);
608
+ sysbus_init_mmio(sbd, &s->iomem);
609
+}
610
+
611
+static const VMStateDescription vmstate_npcm7xx_timer = {
612
+ .name = "npcm7xx-timer",
613
+ .version_id = 0,
614
+ .minimum_version_id = 0,
615
+ .fields = (VMStateField[]) {
616
+ VMSTATE_TIMER(qtimer, NPCM7xxTimer),
617
+ VMSTATE_INT64(expires_ns, NPCM7xxTimer),
618
+ VMSTATE_INT64(remaining_ns, NPCM7xxTimer),
619
+ VMSTATE_UINT32(tcsr, NPCM7xxTimer),
620
+ VMSTATE_UINT32(ticr, NPCM7xxTimer),
621
+ VMSTATE_END_OF_LIST(),
622
+ },
623
+};
624
+
625
+static const VMStateDescription vmstate_npcm7xx_timer_ctrl = {
626
+ .name = "npcm7xx-timer-ctrl",
627
+ .version_id = 0,
628
+ .minimum_version_id = 0,
629
+ .fields = (VMStateField[]) {
630
+ VMSTATE_UINT32(tisr, NPCM7xxTimerCtrlState),
631
+ VMSTATE_UINT32(wtcr, NPCM7xxTimerCtrlState),
632
+ VMSTATE_STRUCT_ARRAY(timer, NPCM7xxTimerCtrlState,
633
+ NPCM7XX_TIMERS_PER_CTRL, 0, vmstate_npcm7xx_timer,
634
+ NPCM7xxTimer),
635
+ VMSTATE_END_OF_LIST(),
636
+ },
637
+};
638
+
639
+static void npcm7xx_timer_class_init(ObjectClass *klass, void *data)
640
+{
641
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
642
+ DeviceClass *dc = DEVICE_CLASS(klass);
643
+
644
+ QEMU_BUILD_BUG_ON(NPCM7XX_TIMER_REGS_END > NPCM7XX_TIMER_NR_REGS);
645
+
646
+ dc->desc = "NPCM7xx Timer Controller";
647
+ dc->realize = npcm7xx_timer_realize;
648
+ dc->vmsd = &vmstate_npcm7xx_timer_ctrl;
649
+ rc->phases.enter = npcm7xx_timer_enter_reset;
650
+ rc->phases.hold = npcm7xx_timer_hold_reset;
651
+}
652
+
653
+static const TypeInfo npcm7xx_timer_info = {
654
+ .name = TYPE_NPCM7XX_TIMER,
655
+ .parent = TYPE_SYS_BUS_DEVICE,
656
+ .instance_size = sizeof(NPCM7xxTimerCtrlState),
657
+ .class_init = npcm7xx_timer_class_init,
658
+};
659
+
660
+static void npcm7xx_timer_register_type(void)
661
+{
662
+ type_register_static(&npcm7xx_timer_info);
663
+}
664
+type_init(npcm7xx_timer_register_type);
665
diff --git a/hw/timer/meson.build b/hw/timer/meson.build
666
index XXXXXXX..XXXXXXX 100644
667
--- a/hw/timer/meson.build
668
+++ b/hw/timer/meson.build
669
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_LM32', if_true: files('lm32_timer.c'))
670
softmmu_ss.add(when: 'CONFIG_MILKYMIST', if_true: files('milkymist-sysctl.c'))
671
softmmu_ss.add(when: 'CONFIG_MIPS_CPS', if_true: files('mips_gictimer.c'))
672
softmmu_ss.add(when: 'CONFIG_MSF2', if_true: files('mss-timer.c'))
673
+softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_timer.c'))
674
softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_timer.c'))
675
softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_gptimer.c'))
676
softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_synctimer.c'))
677
diff --git a/hw/timer/trace-events b/hw/timer/trace-events
678
index XXXXXXX..XXXXXXX 100644
679
--- a/hw/timer/trace-events
680
+++ b/hw/timer/trace-events
681
@@ -XXX,XX +XXX,XX @@ cmsdk_apb_dualtimer_read(uint64_t offset, uint64_t data, unsigned size) "CMSDK A
682
cmsdk_apb_dualtimer_write(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB dualtimer write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
683
cmsdk_apb_dualtimer_reset(void) "CMSDK APB dualtimer: reset"
684
685
+# npcm7xx_timer.c
686
+npcm7xx_timer_read(const char *id, uint64_t offset, uint64_t value) " %s offset: 0x%04" PRIx64 " value 0x%08" PRIx64
687
+npcm7xx_timer_write(const char *id, uint64_t offset, uint64_t value) "%s offset: 0x%04" PRIx64 " value 0x%08" PRIx64
688
+npcm7xx_timer_irq(const char *id, int timer, int state) "%s timer %d state %d"
689
+
690
# nrf51_timer.c
691
nrf51_timer_read(uint8_t timer_id, uint64_t addr, uint32_t value, unsigned size) "timer %u read addr 0x%" PRIx64 " data 0x%" PRIx32 " size %u"
692
nrf51_timer_write(uint8_t timer_id, uint64_t addr, uint32_t value, unsigned size) "timer %u write addr 0x%" PRIx64 " data 0x%" PRIx32 " size %u"
693
--
293
--
694
2.20.1
294
2.20.1
695
295
696
296
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
Instead of hardcoding the MachineClass default_ram_size and
2
default_ram_id fields, set them on class creation by finding the
3
entry in the RAMInfo array which is marked as being the QEMU system
4
RAM.
2
5
3
The Nuvoton NPCM7xx SoC family are used to implement Baseboard
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
Management Controllers in servers. While the family includes four SoCs,
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
this patch implements limited support for two of them: NPCM730 (targeted
8
Message-id: 20210215115138.20465-18-peter.maydell@linaro.org
6
for Data Center applications) and NPCM750 (targeted for Enterprise
9
---
7
applications).
10
hw/arm/mps2-tz.c | 24 ++++++++++++++++++++++--
11
1 file changed, 22 insertions(+), 2 deletions(-)
8
12
9
This patch includes little more than the bare minimum needed to boot a
13
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
10
Linux kernel built with NPCM7xx support in direct-kernel mode:
14
index XXXXXXX..XXXXXXX 100644
11
15
--- a/hw/arm/mps2-tz.c
12
- Two Cortex-A9 CPU cores with built-in periperhals.
16
+++ b/hw/arm/mps2-tz.c
13
- Global Configuration Registers.
17
@@ -XXX,XX +XXX,XX @@ static void mps2tz_class_init(ObjectClass *oc, void *data)
14
- Clock Management.
18
15
- 3 Timer Modules with 5 timers each.
19
mc->init = mps2tz_common_init;
16
- 4 serial ports.
20
iic->check = mps2_tz_idau_check;
17
21
- mc->default_ram_size = 16 * MiB;
18
The chips themselves have a lot more features, some of which will be
22
- mc->default_ram_id = "mps.ram";
19
added to the model at a later stage.
23
+}
20
21
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
22
Reviewed-by: Joel Stanley <joel@jms.id.au>
23
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
24
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
25
Tested-by: Alexander Bulekov <alxndr@bu.edu>
26
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
27
Message-id: 20200911052101.2602693-5-hskinnemoen@google.com
28
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
29
---
30
include/hw/arm/npcm7xx.h | 85 ++++++++
31
hw/arm/npcm7xx.c | 407 +++++++++++++++++++++++++++++++++++++++
32
hw/arm/Kconfig | 5 +
33
hw/arm/meson.build | 1 +
34
4 files changed, 498 insertions(+)
35
create mode 100644 include/hw/arm/npcm7xx.h
36
create mode 100644 hw/arm/npcm7xx.c
37
38
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
39
new file mode 100644
40
index XXXXXXX..XXXXXXX
41
--- /dev/null
42
+++ b/include/hw/arm/npcm7xx.h
43
@@ -XXX,XX +XXX,XX @@
44
+/*
45
+ * Nuvoton NPCM7xx SoC family.
46
+ *
47
+ * Copyright 2020 Google LLC
48
+ *
49
+ * This program is free software; you can redistribute it and/or modify it
50
+ * under the terms of the GNU General Public License as published by the
51
+ * Free Software Foundation; either version 2 of the License, or
52
+ * (at your option) any later version.
53
+ *
54
+ * This program is distributed in the hope that it will be useful, but WITHOUT
55
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
56
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
57
+ * for more details.
58
+ */
59
+#ifndef NPCM7XX_H
60
+#define NPCM7XX_H
61
+
24
+
62
+#include "hw/boards.h"
25
+static void mps2tz_set_default_ram_info(MPS2TZMachineClass *mmc)
63
+#include "hw/cpu/a9mpcore.h"
64
+#include "hw/misc/npcm7xx_clk.h"
65
+#include "hw/misc/npcm7xx_gcr.h"
66
+#include "hw/timer/npcm7xx_timer.h"
67
+#include "target/arm/cpu.h"
68
+
69
+#define NPCM7XX_MAX_NUM_CPUS (2)
70
+
71
+/* The first half of the address space is reserved for DDR4 DRAM. */
72
+#define NPCM7XX_DRAM_BA (0x00000000)
73
+#define NPCM7XX_DRAM_SZ (2 * GiB)
74
+
75
+/* Magic addresses for setting up direct kernel booting and SMP boot stubs. */
76
+#define NPCM7XX_LOADER_START (0x00000000) /* Start of SDRAM */
77
+#define NPCM7XX_SMP_LOADER_START (0xffff0000) /* Boot ROM */
78
+#define NPCM7XX_SMP_BOOTREG_ADDR (0xf080013c) /* GCR.SCRPAD */
79
+#define NPCM7XX_GIC_CPU_IF_ADDR (0xf03fe100) /* GIC within A9 */
80
+
81
+typedef struct NPCM7xxState {
82
+ DeviceState parent;
83
+
84
+ ARMCPU cpu[NPCM7XX_MAX_NUM_CPUS];
85
+ A9MPPrivState a9mpcore;
86
+
87
+ MemoryRegion sram;
88
+ MemoryRegion irom;
89
+ MemoryRegion ram3;
90
+ MemoryRegion *dram;
91
+
92
+ NPCM7xxGCRState gcr;
93
+ NPCM7xxCLKState clk;
94
+ NPCM7xxTimerCtrlState tim[3];
95
+} NPCM7xxState;
96
+
97
+#define TYPE_NPCM7XX "npcm7xx"
98
+#define NPCM7XX(obj) OBJECT_CHECK(NPCM7xxState, (obj), TYPE_NPCM7XX)
99
+
100
+#define TYPE_NPCM730 "npcm730"
101
+#define TYPE_NPCM750 "npcm750"
102
+
103
+typedef struct NPCM7xxClass {
104
+ DeviceClass parent;
105
+
106
+ /* Bitmask of modules that are permanently disabled on this chip. */
107
+ uint32_t disabled_modules;
108
+ /* Number of CPU cores enabled in this SoC class (may be 1 or 2). */
109
+ uint32_t num_cpus;
110
+} NPCM7xxClass;
111
+
112
+#define NPCM7XX_CLASS(klass) \
113
+ OBJECT_CLASS_CHECK(NPCM7xxClass, (klass), TYPE_NPCM7XX)
114
+#define NPCM7XX_GET_CLASS(obj) \
115
+ OBJECT_GET_CLASS(NPCM7xxClass, (obj), TYPE_NPCM7XX)
116
+
117
+/**
118
+ * npcm7xx_load_kernel - Loads memory with everything needed to boot
119
+ * @machine - The machine containing the SoC to be booted.
120
+ * @soc - The SoC containing the CPU to be booted.
121
+ *
122
+ * This will set up the ARM boot info structure for the specific NPCM7xx
123
+ * derivative and call arm_load_kernel() to set up loading of the kernel, etc.
124
+ * into memory, if requested by the user.
125
+ */
126
+void npcm7xx_load_kernel(MachineState *machine, NPCM7xxState *soc);
127
+
128
+#endif /* NPCM7XX_H */
129
diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c
130
new file mode 100644
131
index XXXXXXX..XXXXXXX
132
--- /dev/null
133
+++ b/hw/arm/npcm7xx.c
134
@@ -XXX,XX +XXX,XX @@
135
+/*
136
+ * Nuvoton NPCM7xx SoC family.
137
+ *
138
+ * Copyright 2020 Google LLC
139
+ *
140
+ * This program is free software; you can redistribute it and/or modify it
141
+ * under the terms of the GNU General Public License as published by the
142
+ * Free Software Foundation; either version 2 of the License, or
143
+ * (at your option) any later version.
144
+ *
145
+ * This program is distributed in the hope that it will be useful, but WITHOUT
146
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
147
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
148
+ * for more details.
149
+ */
150
+
151
+#include "qemu/osdep.h"
152
+
153
+#include "exec/address-spaces.h"
154
+#include "hw/arm/boot.h"
155
+#include "hw/arm/npcm7xx.h"
156
+#include "hw/char/serial.h"
157
+#include "hw/loader.h"
158
+#include "hw/misc/unimp.h"
159
+#include "hw/qdev-properties.h"
160
+#include "qapi/error.h"
161
+#include "qemu/units.h"
162
+#include "sysemu/sysemu.h"
163
+
164
+/*
165
+ * This covers the whole MMIO space. We'll use this to catch any MMIO accesses
166
+ * that aren't handled by any device.
167
+ */
168
+#define NPCM7XX_MMIO_BA (0x80000000)
169
+#define NPCM7XX_MMIO_SZ (0x7ffd0000)
170
+
171
+/* Core system modules. */
172
+#define NPCM7XX_L2C_BA (0xf03fc000)
173
+#define NPCM7XX_CPUP_BA (0xf03fe000)
174
+#define NPCM7XX_GCR_BA (0xf0800000)
175
+#define NPCM7XX_CLK_BA (0xf0801000)
176
+
177
+/* Internal AHB SRAM */
178
+#define NPCM7XX_RAM3_BA (0xc0008000)
179
+#define NPCM7XX_RAM3_SZ (4 * KiB)
180
+
181
+/* Memory blocks at the end of the address space */
182
+#define NPCM7XX_RAM2_BA (0xfffd0000)
183
+#define NPCM7XX_RAM2_SZ (128 * KiB)
184
+#define NPCM7XX_ROM_BA (0xffff0000)
185
+#define NPCM7XX_ROM_SZ (64 * KiB)
186
+
187
+/*
188
+ * Interrupt lines going into the GIC. This does not include internal Cortex-A9
189
+ * interrupts.
190
+ */
191
+enum NPCM7xxInterrupt {
192
+ NPCM7XX_UART0_IRQ = 2,
193
+ NPCM7XX_UART1_IRQ,
194
+ NPCM7XX_UART2_IRQ,
195
+ NPCM7XX_UART3_IRQ,
196
+ NPCM7XX_TIMER0_IRQ = 32, /* Timer Module 0 */
197
+ NPCM7XX_TIMER1_IRQ,
198
+ NPCM7XX_TIMER2_IRQ,
199
+ NPCM7XX_TIMER3_IRQ,
200
+ NPCM7XX_TIMER4_IRQ,
201
+ NPCM7XX_TIMER5_IRQ, /* Timer Module 1 */
202
+ NPCM7XX_TIMER6_IRQ,
203
+ NPCM7XX_TIMER7_IRQ,
204
+ NPCM7XX_TIMER8_IRQ,
205
+ NPCM7XX_TIMER9_IRQ,
206
+ NPCM7XX_TIMER10_IRQ, /* Timer Module 2 */
207
+ NPCM7XX_TIMER11_IRQ,
208
+ NPCM7XX_TIMER12_IRQ,
209
+ NPCM7XX_TIMER13_IRQ,
210
+ NPCM7XX_TIMER14_IRQ,
211
+};
212
+
213
+/* Total number of GIC interrupts, including internal Cortex-A9 interrupts. */
214
+#define NPCM7XX_NUM_IRQ (160)
215
+
216
+/* Register base address for each Timer Module */
217
+static const hwaddr npcm7xx_tim_addr[] = {
218
+ 0xf0008000,
219
+ 0xf0009000,
220
+ 0xf000a000,
221
+};
222
+
223
+/* Register base address for each 16550 UART */
224
+static const hwaddr npcm7xx_uart_addr[] = {
225
+ 0xf0001000,
226
+ 0xf0002000,
227
+ 0xf0003000,
228
+ 0xf0004000,
229
+};
230
+
231
+static void npcm7xx_write_secondary_boot(ARMCPU *cpu,
232
+ const struct arm_boot_info *info)
233
+{
26
+{
234
+ /*
27
+ /*
235
+ * The default smpboot stub halts the secondary CPU with a 'wfi'
28
+ * Set mc->default_ram_size and default_ram_id from the
236
+ * instruction, but the arch/arm/mach-npcm/platsmp.c in the Linux kernel
29
+ * information in mmc->raminfo.
237
+ * does not send an IPI to wake it up, so the second CPU fails to boot. So
238
+ * we need to provide our own smpboot stub that can not use 'wfi', it has
239
+ * to spin the secondary CPU until the first CPU writes to the SCRPAD reg.
240
+ */
30
+ */
241
+ uint32_t smpboot[] = {
31
+ MachineClass *mc = MACHINE_CLASS(mmc);
242
+ 0xe59f2018, /* ldr r2, bootreg_addr */
32
+ const RAMInfo *p;
243
+ 0xe3a00000, /* mov r0, #0 */
244
+ 0xe5820000, /* str r0, [r2] */
245
+ 0xe320f002, /* wfe */
246
+ 0xe5921000, /* ldr r1, [r2] */
247
+ 0xe1110001, /* tst r1, r1 */
248
+ 0x0afffffb, /* beq <wfe> */
249
+ 0xe12fff11, /* bx r1 */
250
+ NPCM7XX_SMP_BOOTREG_ADDR,
251
+ };
252
+ int i;
253
+
33
+
254
+ for (i = 0; i < ARRAY_SIZE(smpboot); i++) {
34
+ for (p = mmc->raminfo; p->name; p++) {
255
+ smpboot[i] = tswap32(smpboot[i]);
35
+ if (p->mrindex < 0) {
256
+ }
36
+ /* Found the entry for "system memory" */
257
+
37
+ mc->default_ram_size = p->size;
258
+ rom_add_blob_fixed("smpboot", smpboot, sizeof(smpboot),
38
+ mc->default_ram_id = p->name;
259
+ NPCM7XX_SMP_LOADER_START);
260
+}
261
+
262
+static struct arm_boot_info npcm7xx_binfo = {
263
+ .loader_start = NPCM7XX_LOADER_START,
264
+ .smp_loader_start = NPCM7XX_SMP_LOADER_START,
265
+ .smp_bootreg_addr = NPCM7XX_SMP_BOOTREG_ADDR,
266
+ .gic_cpu_if_addr = NPCM7XX_GIC_CPU_IF_ADDR,
267
+ .write_secondary_boot = npcm7xx_write_secondary_boot,
268
+ .board_id = -1,
269
+};
270
+
271
+void npcm7xx_load_kernel(MachineState *machine, NPCM7xxState *soc)
272
+{
273
+ NPCM7xxClass *sc = NPCM7XX_GET_CLASS(soc);
274
+
275
+ npcm7xx_binfo.ram_size = machine->ram_size;
276
+ npcm7xx_binfo.nb_cpus = sc->num_cpus;
277
+
278
+ arm_load_kernel(&soc->cpu[0], machine, &npcm7xx_binfo);
279
+}
280
+
281
+static qemu_irq npcm7xx_irq(NPCM7xxState *s, int n)
282
+{
283
+ return qdev_get_gpio_in(DEVICE(&s->a9mpcore), n);
284
+}
285
+
286
+static void npcm7xx_init(Object *obj)
287
+{
288
+ NPCM7xxState *s = NPCM7XX(obj);
289
+ int i;
290
+
291
+ for (i = 0; i < NPCM7XX_MAX_NUM_CPUS; i++) {
292
+ object_initialize_child(obj, "cpu[*]", &s->cpu[i],
293
+ ARM_CPU_TYPE_NAME("cortex-a9"));
294
+ }
295
+
296
+ object_initialize_child(obj, "a9mpcore", &s->a9mpcore, TYPE_A9MPCORE_PRIV);
297
+ object_initialize_child(obj, "gcr", &s->gcr, TYPE_NPCM7XX_GCR);
298
+ object_property_add_alias(obj, "power-on-straps", OBJECT(&s->gcr),
299
+ "power-on-straps");
300
+ object_initialize_child(obj, "clk", &s->clk, TYPE_NPCM7XX_CLK);
301
+
302
+ for (i = 0; i < ARRAY_SIZE(s->tim); i++) {
303
+ object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER);
304
+ }
305
+}
306
+
307
+static void npcm7xx_realize(DeviceState *dev, Error **errp)
308
+{
309
+ NPCM7xxState *s = NPCM7XX(dev);
310
+ NPCM7xxClass *nc = NPCM7XX_GET_CLASS(s);
311
+ int i;
312
+
313
+ if (memory_region_size(s->dram) > NPCM7XX_DRAM_SZ) {
314
+ error_setg(errp, "%s: NPCM7xx cannot address more than %" PRIu64
315
+ " MiB of DRAM", __func__, NPCM7XX_DRAM_SZ / MiB);
316
+ return;
317
+ }
318
+
319
+ /* CPUs */
320
+ for (i = 0; i < nc->num_cpus; i++) {
321
+ object_property_set_int(OBJECT(&s->cpu[i]), "mp-affinity",
322
+ arm_cpu_mp_affinity(i, NPCM7XX_MAX_NUM_CPUS),
323
+ &error_abort);
324
+ object_property_set_int(OBJECT(&s->cpu[i]), "reset-cbar",
325
+ NPCM7XX_GIC_CPU_IF_ADDR, &error_abort);
326
+ object_property_set_bool(OBJECT(&s->cpu[i]), "reset-hivecs", true,
327
+ &error_abort);
328
+
329
+ /* Disable security extensions. */
330
+ object_property_set_bool(OBJECT(&s->cpu[i]), "has_el3", false,
331
+ &error_abort);
332
+
333
+ if (!qdev_realize(DEVICE(&s->cpu[i]), NULL, errp)) {
334
+ return;
39
+ return;
335
+ }
40
+ }
336
+ }
41
+ }
337
+
42
+ g_assert_not_reached();
338
+ /* A9MPCORE peripherals. Can only fail if we pass bad parameters here. */
43
}
339
+ object_property_set_int(OBJECT(&s->a9mpcore), "num-cpu", nc->num_cpus,
44
340
+ &error_abort);
45
static void mps2tz_an505_class_init(ObjectClass *oc, void *data)
341
+ object_property_set_int(OBJECT(&s->a9mpcore), "num-irq", NPCM7XX_NUM_IRQ,
46
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an505_class_init(ObjectClass *oc, void *data)
342
+ &error_abort);
47
mmc->numirq = 92;
343
+ sysbus_realize(SYS_BUS_DEVICE(&s->a9mpcore), &error_abort);
48
mmc->raminfo = an505_raminfo;
344
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->a9mpcore), 0, NPCM7XX_CPUP_BA);
49
mmc->armsse_type = TYPE_IOTKIT;
345
+
50
+ mps2tz_set_default_ram_info(mmc);
346
+ for (i = 0; i < nc->num_cpus; i++) {
51
}
347
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->a9mpcore), i,
52
348
+ qdev_get_gpio_in(DEVICE(&s->cpu[i]), ARM_CPU_IRQ));
53
static void mps2tz_an521_class_init(ObjectClass *oc, void *data)
349
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->a9mpcore), i + nc->num_cpus,
54
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an521_class_init(ObjectClass *oc, void *data)
350
+ qdev_get_gpio_in(DEVICE(&s->cpu[i]), ARM_CPU_FIQ));
55
mmc->numirq = 92;
351
+ }
56
mmc->raminfo = an505_raminfo; /* AN521 is the same as AN505 here */
352
+
57
mmc->armsse_type = TYPE_SSE200;
353
+ /* L2 cache controller */
58
+ mps2tz_set_default_ram_info(mmc);
354
+ sysbus_create_simple("l2x0", NPCM7XX_L2C_BA, NULL);
59
}
355
+
60
356
+ /* System Global Control Registers (GCR). Can fail due to user input. */
61
static const TypeInfo mps2tz_info = {
357
+ object_property_set_int(OBJECT(&s->gcr), "disabled-modules",
358
+ nc->disabled_modules, &error_abort);
359
+ object_property_add_const_link(OBJECT(&s->gcr), "dram-mr", OBJECT(s->dram));
360
+ if (!sysbus_realize(SYS_BUS_DEVICE(&s->gcr), errp)) {
361
+ return;
362
+ }
363
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->gcr), 0, NPCM7XX_GCR_BA);
364
+
365
+ /* Clock Control Registers (CLK). Cannot fail. */
366
+ sysbus_realize(SYS_BUS_DEVICE(&s->clk), &error_abort);
367
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->clk), 0, NPCM7XX_CLK_BA);
368
+
369
+ /* Timer Modules (TIM). Cannot fail. */
370
+ QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_tim_addr) != ARRAY_SIZE(s->tim));
371
+ for (i = 0; i < ARRAY_SIZE(s->tim); i++) {
372
+ SysBusDevice *sbd = SYS_BUS_DEVICE(&s->tim[i]);
373
+ int first_irq;
374
+ int j;
375
+
376
+ sysbus_realize(sbd, &error_abort);
377
+ sysbus_mmio_map(sbd, 0, npcm7xx_tim_addr[i]);
378
+
379
+ first_irq = NPCM7XX_TIMER0_IRQ + i * NPCM7XX_TIMERS_PER_CTRL;
380
+ for (j = 0; j < NPCM7XX_TIMERS_PER_CTRL; j++) {
381
+ qemu_irq irq = npcm7xx_irq(s, first_irq + j);
382
+ sysbus_connect_irq(sbd, j, irq);
383
+ }
384
+ }
385
+
386
+ /* UART0..3 (16550 compatible) */
387
+ for (i = 0; i < ARRAY_SIZE(npcm7xx_uart_addr); i++) {
388
+ serial_mm_init(get_system_memory(), npcm7xx_uart_addr[i], 2,
389
+ npcm7xx_irq(s, NPCM7XX_UART0_IRQ + i), 115200,
390
+ serial_hd(i), DEVICE_LITTLE_ENDIAN);
391
+ }
392
+
393
+ /* RAM2 (SRAM) */
394
+ memory_region_init_ram(&s->sram, OBJECT(dev), "ram2",
395
+ NPCM7XX_RAM2_SZ, &error_abort);
396
+ memory_region_add_subregion(get_system_memory(), NPCM7XX_RAM2_BA, &s->sram);
397
+
398
+ /* RAM3 (SRAM) */
399
+ memory_region_init_ram(&s->ram3, OBJECT(dev), "ram3",
400
+ NPCM7XX_RAM3_SZ, &error_abort);
401
+ memory_region_add_subregion(get_system_memory(), NPCM7XX_RAM3_BA, &s->ram3);
402
+
403
+ /* Internal ROM */
404
+ memory_region_init_rom(&s->irom, OBJECT(dev), "irom", NPCM7XX_ROM_SZ,
405
+ &error_abort);
406
+ memory_region_add_subregion(get_system_memory(), NPCM7XX_ROM_BA, &s->irom);
407
+
408
+ create_unimplemented_device("npcm7xx.shm", 0xc0001000, 4 * KiB);
409
+ create_unimplemented_device("npcm7xx.vdmx", 0xe0800000, 4 * KiB);
410
+ create_unimplemented_device("npcm7xx.pcierc", 0xe1000000, 64 * KiB);
411
+ create_unimplemented_device("npcm7xx.kcs", 0xf0007000, 4 * KiB);
412
+ create_unimplemented_device("npcm7xx.rng", 0xf000b000, 4 * KiB);
413
+ create_unimplemented_device("npcm7xx.adc", 0xf000c000, 4 * KiB);
414
+ create_unimplemented_device("npcm7xx.gfxi", 0xf000e000, 4 * KiB);
415
+ create_unimplemented_device("npcm7xx.gpio[0]", 0xf0010000, 4 * KiB);
416
+ create_unimplemented_device("npcm7xx.gpio[1]", 0xf0011000, 4 * KiB);
417
+ create_unimplemented_device("npcm7xx.gpio[2]", 0xf0012000, 4 * KiB);
418
+ create_unimplemented_device("npcm7xx.gpio[3]", 0xf0013000, 4 * KiB);
419
+ create_unimplemented_device("npcm7xx.gpio[4]", 0xf0014000, 4 * KiB);
420
+ create_unimplemented_device("npcm7xx.gpio[5]", 0xf0015000, 4 * KiB);
421
+ create_unimplemented_device("npcm7xx.gpio[6]", 0xf0016000, 4 * KiB);
422
+ create_unimplemented_device("npcm7xx.gpio[7]", 0xf0017000, 4 * KiB);
423
+ create_unimplemented_device("npcm7xx.smbus[0]", 0xf0080000, 4 * KiB);
424
+ create_unimplemented_device("npcm7xx.smbus[1]", 0xf0081000, 4 * KiB);
425
+ create_unimplemented_device("npcm7xx.smbus[2]", 0xf0082000, 4 * KiB);
426
+ create_unimplemented_device("npcm7xx.smbus[3]", 0xf0083000, 4 * KiB);
427
+ create_unimplemented_device("npcm7xx.smbus[4]", 0xf0084000, 4 * KiB);
428
+ create_unimplemented_device("npcm7xx.smbus[5]", 0xf0085000, 4 * KiB);
429
+ create_unimplemented_device("npcm7xx.smbus[6]", 0xf0086000, 4 * KiB);
430
+ create_unimplemented_device("npcm7xx.smbus[7]", 0xf0087000, 4 * KiB);
431
+ create_unimplemented_device("npcm7xx.smbus[8]", 0xf0088000, 4 * KiB);
432
+ create_unimplemented_device("npcm7xx.smbus[9]", 0xf0089000, 4 * KiB);
433
+ create_unimplemented_device("npcm7xx.smbus[10]", 0xf008a000, 4 * KiB);
434
+ create_unimplemented_device("npcm7xx.smbus[11]", 0xf008b000, 4 * KiB);
435
+ create_unimplemented_device("npcm7xx.smbus[12]", 0xf008c000, 4 * KiB);
436
+ create_unimplemented_device("npcm7xx.smbus[13]", 0xf008d000, 4 * KiB);
437
+ create_unimplemented_device("npcm7xx.smbus[14]", 0xf008e000, 4 * KiB);
438
+ create_unimplemented_device("npcm7xx.smbus[15]", 0xf008f000, 4 * KiB);
439
+ create_unimplemented_device("npcm7xx.espi", 0xf009f000, 4 * KiB);
440
+ create_unimplemented_device("npcm7xx.peci", 0xf0100000, 4 * KiB);
441
+ create_unimplemented_device("npcm7xx.siox[1]", 0xf0101000, 4 * KiB);
442
+ create_unimplemented_device("npcm7xx.siox[2]", 0xf0102000, 4 * KiB);
443
+ create_unimplemented_device("npcm7xx.pwm[0]", 0xf0103000, 4 * KiB);
444
+ create_unimplemented_device("npcm7xx.pwm[1]", 0xf0104000, 4 * KiB);
445
+ create_unimplemented_device("npcm7xx.mft[0]", 0xf0180000, 4 * KiB);
446
+ create_unimplemented_device("npcm7xx.mft[1]", 0xf0181000, 4 * KiB);
447
+ create_unimplemented_device("npcm7xx.mft[2]", 0xf0182000, 4 * KiB);
448
+ create_unimplemented_device("npcm7xx.mft[3]", 0xf0183000, 4 * KiB);
449
+ create_unimplemented_device("npcm7xx.mft[4]", 0xf0184000, 4 * KiB);
450
+ create_unimplemented_device("npcm7xx.mft[5]", 0xf0185000, 4 * KiB);
451
+ create_unimplemented_device("npcm7xx.mft[6]", 0xf0186000, 4 * KiB);
452
+ create_unimplemented_device("npcm7xx.mft[7]", 0xf0187000, 4 * KiB);
453
+ create_unimplemented_device("npcm7xx.pspi1", 0xf0200000, 4 * KiB);
454
+ create_unimplemented_device("npcm7xx.pspi2", 0xf0201000, 4 * KiB);
455
+ create_unimplemented_device("npcm7xx.ahbpci", 0xf0400000, 1 * MiB);
456
+ create_unimplemented_device("npcm7xx.mcphy", 0xf05f0000, 64 * KiB);
457
+ create_unimplemented_device("npcm7xx.gmac1", 0xf0802000, 8 * KiB);
458
+ create_unimplemented_device("npcm7xx.gmac2", 0xf0804000, 8 * KiB);
459
+ create_unimplemented_device("npcm7xx.ehci", 0xf0806000, 4 * KiB);
460
+ create_unimplemented_device("npcm7xx.ohci", 0xf0807000, 4 * KiB);
461
+ create_unimplemented_device("npcm7xx.vcd", 0xf0810000, 64 * KiB);
462
+ create_unimplemented_device("npcm7xx.ece", 0xf0820000, 8 * KiB);
463
+ create_unimplemented_device("npcm7xx.vdma", 0xf0822000, 8 * KiB);
464
+ create_unimplemented_device("npcm7xx.emc1", 0xf0825000, 4 * KiB);
465
+ create_unimplemented_device("npcm7xx.emc2", 0xf0826000, 4 * KiB);
466
+ create_unimplemented_device("npcm7xx.usbd[0]", 0xf0830000, 4 * KiB);
467
+ create_unimplemented_device("npcm7xx.usbd[1]", 0xf0831000, 4 * KiB);
468
+ create_unimplemented_device("npcm7xx.usbd[2]", 0xf0832000, 4 * KiB);
469
+ create_unimplemented_device("npcm7xx.usbd[3]", 0xf0833000, 4 * KiB);
470
+ create_unimplemented_device("npcm7xx.usbd[4]", 0xf0834000, 4 * KiB);
471
+ create_unimplemented_device("npcm7xx.usbd[5]", 0xf0835000, 4 * KiB);
472
+ create_unimplemented_device("npcm7xx.usbd[6]", 0xf0836000, 4 * KiB);
473
+ create_unimplemented_device("npcm7xx.usbd[7]", 0xf0837000, 4 * KiB);
474
+ create_unimplemented_device("npcm7xx.usbd[8]", 0xf0838000, 4 * KiB);
475
+ create_unimplemented_device("npcm7xx.usbd[9]", 0xf0839000, 4 * KiB);
476
+ create_unimplemented_device("npcm7xx.sd", 0xf0840000, 8 * KiB);
477
+ create_unimplemented_device("npcm7xx.mmc", 0xf0842000, 8 * KiB);
478
+ create_unimplemented_device("npcm7xx.pcimbx", 0xf0848000, 512 * KiB);
479
+ create_unimplemented_device("npcm7xx.aes", 0xf0858000, 4 * KiB);
480
+ create_unimplemented_device("npcm7xx.des", 0xf0859000, 4 * KiB);
481
+ create_unimplemented_device("npcm7xx.sha", 0xf085a000, 4 * KiB);
482
+ create_unimplemented_device("npcm7xx.secacc", 0xf085b000, 4 * KiB);
483
+ create_unimplemented_device("npcm7xx.spixcs0", 0xf8000000, 16 * MiB);
484
+ create_unimplemented_device("npcm7xx.spixcs1", 0xf9000000, 16 * MiB);
485
+ create_unimplemented_device("npcm7xx.spix", 0xfb001000, 4 * KiB);
486
+}
487
+
488
+static Property npcm7xx_properties[] = {
489
+ DEFINE_PROP_LINK("dram-mr", NPCM7xxState, dram, TYPE_MEMORY_REGION,
490
+ MemoryRegion *),
491
+ DEFINE_PROP_END_OF_LIST(),
492
+};
493
+
494
+static void npcm7xx_class_init(ObjectClass *oc, void *data)
495
+{
496
+ DeviceClass *dc = DEVICE_CLASS(oc);
497
+
498
+ dc->realize = npcm7xx_realize;
499
+ dc->user_creatable = false;
500
+ device_class_set_props(dc, npcm7xx_properties);
501
+}
502
+
503
+static void npcm730_class_init(ObjectClass *oc, void *data)
504
+{
505
+ NPCM7xxClass *nc = NPCM7XX_CLASS(oc);
506
+
507
+ /* NPCM730 is optimized for data center use, so no graphics, etc. */
508
+ nc->disabled_modules = 0x00300395;
509
+ nc->num_cpus = 2;
510
+}
511
+
512
+static void npcm750_class_init(ObjectClass *oc, void *data)
513
+{
514
+ NPCM7xxClass *nc = NPCM7XX_CLASS(oc);
515
+
516
+ /* NPCM750 has 2 cores and a full set of peripherals */
517
+ nc->disabled_modules = 0x00000000;
518
+ nc->num_cpus = 2;
519
+}
520
+
521
+static const TypeInfo npcm7xx_soc_types[] = {
522
+ {
523
+ .name = TYPE_NPCM7XX,
524
+ .parent = TYPE_DEVICE,
525
+ .instance_size = sizeof(NPCM7xxState),
526
+ .instance_init = npcm7xx_init,
527
+ .class_size = sizeof(NPCM7xxClass),
528
+ .class_init = npcm7xx_class_init,
529
+ .abstract = true,
530
+ }, {
531
+ .name = TYPE_NPCM730,
532
+ .parent = TYPE_NPCM7XX,
533
+ .class_init = npcm730_class_init,
534
+ }, {
535
+ .name = TYPE_NPCM750,
536
+ .parent = TYPE_NPCM7XX,
537
+ .class_init = npcm750_class_init,
538
+ },
539
+};
540
+
541
+DEFINE_TYPES(npcm7xx_soc_types);
542
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
543
index XXXXXXX..XXXXXXX 100644
544
--- a/hw/arm/Kconfig
545
+++ b/hw/arm/Kconfig
546
@@ -XXX,XX +XXX,XX @@ config XLNX_VERSAL
547
548
config NPCM7XX
549
bool
550
+ select A9MPCORE
551
+ select ARM_GIC
552
+ select PL310 # cache controller
553
+ select SERIAL
554
+ select UNIMP
555
556
config FSL_IMX25
557
bool
558
diff --git a/hw/arm/meson.build b/hw/arm/meson.build
559
index XXXXXXX..XXXXXXX 100644
560
--- a/hw/arm/meson.build
561
+++ b/hw/arm/meson.build
562
@@ -XXX,XX +XXX,XX @@ arm_ss.add(when: 'CONFIG_MICROBIT', if_true: files('microbit.c'))
563
arm_ss.add(when: 'CONFIG_MUSICPAL', if_true: files('musicpal.c'))
564
arm_ss.add(when: 'CONFIG_NETDUINO2', if_true: files('netduino2.c'))
565
arm_ss.add(when: 'CONFIG_NETDUINOPLUS2', if_true: files('netduinoplus2.c'))
566
+arm_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx.c'))
567
arm_ss.add(when: 'CONFIG_NSERIES', if_true: files('nseries.c'))
568
arm_ss.add(when: 'CONFIG_SX1', if_true: files('omap_sx1.c'))
569
arm_ss.add(when: 'CONFIG_CHEETAH', if_true: files('palm.c'))
570
--
62
--
571
2.20.1
63
2.20.1
572
64
573
65
diff view generated by jsdifflib
1
Convert the insns using the 2reg_vcvt and 2reg_vcvt_f16 formats
1
The AN505 and AN521 don't have any read-only memory, but the AN524
2
to pass the size through to the trans function as a MO_* value
2
does; add a flag to ROMInfo to mark a region as ROM.
3
rather than the '0==f32, 1==f16' used in the fp 3-same encodings.
4
3
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20200903133209.5141-3-peter.maydell@linaro.org
6
Message-id: 20210215115138.20465-19-peter.maydell@linaro.org
8
---
7
---
9
target/arm/neon-dp.decode | 3 +--
8
hw/arm/mps2-tz.c | 6 ++++++
10
target/arm/translate-neon.c.inc | 4 ++--
9
1 file changed, 6 insertions(+)
11
2 files changed, 3 insertions(+), 4 deletions(-)
12
10
13
diff --git a/target/arm/neon-dp.decode b/target/arm/neon-dp.decode
11
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
14
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
15
--- a/target/arm/neon-dp.decode
13
--- a/hw/arm/mps2-tz.c
16
+++ b/target/arm/neon-dp.decode
14
+++ b/hw/arm/mps2-tz.c
17
@@ -XXX,XX +XXX,XX @@ VMINNM_fp_3s 1111 001 1 0 . 1 . .... .... 1111 ... 1 .... @3same_fp
15
@@ -XXX,XX +XXX,XX @@ typedef struct RAMInfo {
18
@2reg_shll_b .... ... . . . 001 shift:3 .... .... 0 . . . .... \
16
* Flag values:
19
&2reg_shift vm=%vm_dp vd=%vd_dp size=0 q=0
17
* IS_ALIAS: this RAM area is an alias to the upstream end of the
20
18
* MPC specified by its .mpc value
21
-# We use size=0 for fp32 and size=1 for fp16 to match the 3-same encodings.
19
+ * IS_ROM: this RAM area is read-only
22
@2reg_vcvt .... ... . . . 1 ..... .... .... . q:1 . . .... \
20
*/
23
- &2reg_shift vm=%vm_dp vd=%vd_dp size=0 shift=%neon_rshift_i5
21
#define IS_ALIAS 1
24
+ &2reg_shift vm=%vm_dp vd=%vd_dp size=2 shift=%neon_rshift_i5
22
+#define IS_ROM 2
25
@2reg_vcvt_f16 .... ... . . . 11 .... .... .... . q:1 . . .... \
23
26
&2reg_shift vm=%vm_dp vd=%vd_dp size=1 shift=%neon_rshift_i4
24
struct MPS2TZMachineClass {
27
25
MachineClass parent;
28
diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc
26
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *mr_for_raminfo(MPS2TZMachineState *mms,
29
index XXXXXXX..XXXXXXX 100644
27
if (raminfo->mrindex < 0) {
30
--- a/target/arm/translate-neon.c.inc
28
/* Means this RAMInfo is for QEMU's "system memory" */
31
+++ b/target/arm/translate-neon.c.inc
29
MachineState *machine = MACHINE(mms);
32
@@ -XXX,XX +XXX,XX @@ static bool do_fp_2sh(DisasContext *s, arg_2reg_shift *a,
30
+ assert(!(raminfo->flags & IS_ROM));
33
return false;
31
return machine->ram;
34
}
32
}
35
33
36
- if (a->size != 0) {
34
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *mr_for_raminfo(MPS2TZMachineState *mms,
37
+ if (a->size == MO_16) {
35
38
if (!dc_isar_feature(aa32_fp16_arith, s)) {
36
memory_region_init_ram(ram, NULL, raminfo->name,
39
return false;
37
raminfo->size, &error_fatal);
40
}
38
+ if (raminfo->flags & IS_ROM) {
41
@@ -XXX,XX +XXX,XX @@ static bool do_fp_2sh(DisasContext *s, arg_2reg_shift *a,
39
+ memory_region_set_readonly(ram, true);
42
return true;
40
+ }
43
}
41
return ram;
44
42
}
45
- fpst = fpstatus_ptr(a->size ? FPST_STD_F16 : FPST_STD);
43
46
+ fpst = fpstatus_ptr(a->size == MO_16 ? FPST_STD_F16 : FPST_STD);
47
tcg_gen_gvec_2_ptr(rd_ofs, rm_ofs, fpst, vec_size, vec_size, a->shift, fn);
48
tcg_temp_free_ptr(fpst);
49
return true;
50
--
44
--
51
2.20.1
45
2.20.1
52
46
53
47
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
The armv7m_load_kernel() function takes a mem_size argument which it
2
expects to be the size of the memory region at guest address 0. (It
3
uses this argument only as a limit on how large a raw image file it
4
can load at address zero).
2
5
3
This allows these NPCM7xx-based boards to boot from a flash image, e.g.
6
Instead of hardcoding this value, find the RAMInfo corresponding to
4
one built with OpenBMC. For example like this:
7
the 0 address and extract its size.
5
8
6
IMAGE=${OPENBMC}/build/tmp/deploy/images/gsj/image-bmc
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
qemu-system-arm -machine quanta-gsj -nographic \
10
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
    -drive file=${IMAGE},if=mtd,bus=0,unit=0,format=raw,snapshot=on
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Message-id: 20210215115138.20465-20-peter.maydell@linaro.org
13
---
14
hw/arm/mps2-tz.c | 17 ++++++++++++++++-
15
1 file changed, 16 insertions(+), 1 deletion(-)
9
16
10
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
17
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
11
Reviewed-by: Cédric Le Goater <clg@kaod.org>
12
Tested-by: Cédric Le Goater <clg@kaod.org>
13
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
14
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
15
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
16
Message-id: 20200911052101.2602693-12-hskinnemoen@google.com
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
18
---
19
hw/arm/npcm7xx_boards.c | 20 ++++++++++++++++++++
20
1 file changed, 20 insertions(+)
21
22
diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c
23
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
24
--- a/hw/arm/npcm7xx_boards.c
19
--- a/hw/arm/mps2-tz.c
25
+++ b/hw/arm/npcm7xx_boards.c
20
+++ b/hw/arm/mps2-tz.c
26
@@ -XXX,XX +XXX,XX @@
21
@@ -XXX,XX +XXX,XX @@ static void create_non_mpc_ram(MPS2TZMachineState *mms)
27
#include "hw/arm/npcm7xx.h"
28
#include "hw/core/cpu.h"
29
#include "hw/loader.h"
30
+#include "hw/qdev-properties.h"
31
#include "qapi/error.h"
32
#include "qemu-common.h"
33
#include "qemu/units.h"
34
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_load_bootrom(MachineState *machine, NPCM7xxState *soc)
35
}
22
}
36
}
23
}
37
24
38
+static void npcm7xx_connect_flash(NPCM7xxFIUState *fiu, int cs_no,
25
+static uint32_t boot_ram_size(MPS2TZMachineState *mms)
39
+ const char *flash_type, DriveInfo *dinfo)
40
+{
26
+{
41
+ DeviceState *flash;
27
+ /* Return the size of the RAM block at guest address zero */
42
+ qemu_irq flash_cs;
28
+ const RAMInfo *p;
29
+ MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
43
+
30
+
44
+ flash = qdev_new(flash_type);
31
+ for (p = mmc->raminfo; p->name; p++) {
45
+ if (dinfo) {
32
+ if (p->base == 0) {
46
+ qdev_prop_set_drive(flash, "drive", blk_by_legacy_dinfo(dinfo));
33
+ return p->size;
34
+ }
47
+ }
35
+ }
48
+ qdev_realize_and_unref(flash, BUS(fiu->spi), &error_fatal);
36
+ g_assert_not_reached();
49
+
50
+ flash_cs = qdev_get_gpio_in_named(flash, SSI_GPIO_CS, 0);
51
+ qdev_connect_gpio_out_named(DEVICE(fiu), "cs", cs_no, flash_cs);
52
+}
37
+}
53
+
38
+
54
static void npcm7xx_connect_dram(NPCM7xxState *soc, MemoryRegion *dram)
39
static void mps2tz_common_init(MachineState *machine)
55
{
40
{
56
memory_region_add_subregion(get_system_memory(), NPCM7XX_DRAM_BA, dram);
41
MPS2TZMachineState *mms = MPS2TZ_MACHINE(machine);
57
@@ -XXX,XX +XXX,XX @@ static void npcm750_evb_init(MachineState *machine)
42
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
58
qdev_realize(DEVICE(soc), NULL, &error_fatal);
43
59
44
create_non_mpc_ram(mms);
60
npcm7xx_load_bootrom(machine, soc);
45
61
+ npcm7xx_connect_flash(&soc->fiu[0], 0, "w25q256", drive_get(IF_MTD, 0, 0));
46
- armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename, 0x400000);
62
npcm7xx_load_kernel(machine, soc);
47
+ armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename,
48
+ boot_ram_size(mms));
63
}
49
}
64
50
65
@@ -XXX,XX +XXX,XX @@ static void quanta_gsj_init(MachineState *machine)
51
static void mps2_tz_idau_check(IDAUInterface *ii, uint32_t address,
66
qdev_realize(DEVICE(soc), NULL, &error_fatal);
67
68
npcm7xx_load_bootrom(machine, soc);
69
+ npcm7xx_connect_flash(&soc->fiu[0], 0, "mx25l25635e",
70
+ drive_get(IF_MTD, 0, 0));
71
npcm7xx_load_kernel(machine, soc);
72
}
73
74
--
52
--
75
2.20.1
53
2.20.1
76
54
77
55
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
Add support for the mps3-an524 board; this is an SSE-200 based FPGA
2
2
image, like the existing mps2-an521. It has a usefully larger amount
3
Implement a device model for the System Global Control Registers in the
3
of RAM, and a PL031 RTC, as well as some more minor differences.
4
NPCM730 and NPCM750 BMC SoCs.
4
5
5
In real hardware this image runs on a newer generation of the FPGA
6
This is primarily used to enable SMP boot (the boot ROM spins reading
6
board, the MPS3 rather than the older MPS2. Architecturally the two
7
the SCRPAD register) and DDR memory initialization; other registers are
7
boards are similar, so we implement the MPS3 boards in the mps2-tz.c
8
best effort for now.
8
file as variations of the existing MPS2 boards.
9
9
10
The reset values of the MDLR and PWRON registers are determined by the
11
SoC variant (730 vs 750) and board straps respectively.
12
13
Reviewed-by: Joel Stanley <joel@jms.id.au>
14
Reviewed-by: Cédric Le Goater <clg@kaod.org>
15
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
16
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
17
Tested-by: Alexander Bulekov <alxndr@bu.edu>
18
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
19
Message-id: 20200911052101.2602693-2-hskinnemoen@google.com
20
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Message-id: 20210215115138.20465-21-peter.maydell@linaro.org
21
---
13
---
22
include/hw/misc/npcm7xx_gcr.h | 43 ++++++
14
hw/arm/mps2-tz.c | 139 +++++++++++++++++++++++++++++++++++++++++++++--
23
hw/misc/npcm7xx_gcr.c | 269 ++++++++++++++++++++++++++++++++++
15
1 file changed, 135 insertions(+), 4 deletions(-)
24
MAINTAINERS | 8 +
16
25
hw/arm/Kconfig | 3 +
17
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
26
hw/misc/meson.build | 3 +
18
index XXXXXXX..XXXXXXX 100644
27
hw/misc/trace-events | 4 +
19
--- a/hw/arm/mps2-tz.c
28
6 files changed, 330 insertions(+)
20
+++ b/hw/arm/mps2-tz.c
29
create mode 100644 include/hw/misc/npcm7xx_gcr.h
30
create mode 100644 hw/misc/npcm7xx_gcr.c
31
32
diff --git a/include/hw/misc/npcm7xx_gcr.h b/include/hw/misc/npcm7xx_gcr.h
33
new file mode 100644
34
index XXXXXXX..XXXXXXX
35
--- /dev/null
36
+++ b/include/hw/misc/npcm7xx_gcr.h
37
@@ -XXX,XX +XXX,XX @@
21
@@ -XXX,XX +XXX,XX @@
38
+/*
22
* This source file covers the following FPGA images, for TrustZone cores:
39
+ * Nuvoton NPCM7xx System Global Control Registers.
23
* "mps2-an505" -- Cortex-M33 as documented in ARM Application Note AN505
40
+ *
24
* "mps2-an521" -- Dual Cortex-M33 as documented in Application Note AN521
41
+ * Copyright 2020 Google LLC
25
+ * "mps2-an524" -- Dual Cortex-M33 as documented in Application Note AN524
42
+ *
26
*
43
+ * This program is free software; you can redistribute it and/or modify it
27
* Links to the TRM for the board itself and to the various Application
44
+ * under the terms of the GNU General Public License as published by the
28
* Notes which document the FPGA images can be found here:
45
+ * Free Software Foundation; either version 2 of the License, or
46
+ * (at your option) any later version.
47
+ *
48
+ * This program is distributed in the hope that it will be useful, but WITHOUT
49
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
50
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
51
+ * for more details.
52
+ */
53
+#ifndef NPCM7XX_GCR_H
54
+#define NPCM7XX_GCR_H
55
+
56
+#include "exec/memory.h"
57
+#include "hw/sysbus.h"
58
+
59
+/*
60
+ * Number of registers in our device state structure. Don't change this without
61
+ * incrementing the version_id in the vmstate.
62
+ */
63
+#define NPCM7XX_GCR_NR_REGS (0x148 / sizeof(uint32_t))
64
+
65
+typedef struct NPCM7xxGCRState {
66
+ SysBusDevice parent;
67
+
68
+ MemoryRegion iomem;
69
+
70
+ uint32_t regs[NPCM7XX_GCR_NR_REGS];
71
+
72
+ uint32_t reset_pwron;
73
+ uint32_t reset_mdlr;
74
+ uint32_t reset_intcr3;
75
+} NPCM7xxGCRState;
76
+
77
+#define TYPE_NPCM7XX_GCR "npcm7xx-gcr"
78
+#define NPCM7XX_GCR(obj) OBJECT_CHECK(NPCM7xxGCRState, (obj), TYPE_NPCM7XX_GCR)
79
+
80
+#endif /* NPCM7XX_GCR_H */
81
diff --git a/hw/misc/npcm7xx_gcr.c b/hw/misc/npcm7xx_gcr.c
82
new file mode 100644
83
index XXXXXXX..XXXXXXX
84
--- /dev/null
85
+++ b/hw/misc/npcm7xx_gcr.c
86
@@ -XXX,XX +XXX,XX @@
29
@@ -XXX,XX +XXX,XX @@
87
+/*
30
* http://infocenter.arm.com/help/topic/com.arm.doc.dai0505b/index.html
88
+ * Nuvoton NPCM7xx System Global Control Registers.
31
* Application Note AN521:
89
+ *
32
* http://infocenter.arm.com/help/topic/com.arm.doc.dai0521c/index.html
90
+ * Copyright 2020 Google LLC
33
+ * Application Note AN524:
91
+ *
34
+ * https://developer.arm.com/documentation/dai0524/latest/
92
+ * This program is free software; you can redistribute it and/or modify it
35
*
93
+ * under the terms of the GNU General Public License as published by the
36
* The AN505 defers to the Cortex-M33 processor ARMv8M IoT Kit FVP User Guide
94
+ * Free Software Foundation; either version 2 of the License, or
37
* (ARM ECM0601256) for the details of some of the device layout:
95
+ * (at your option) any later version.
38
* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
96
+ *
39
- * Similarly, the AN521 uses the SSE-200, and the SSE-200 TRM defines
97
+ * This program is distributed in the hope that it will be useful, but WITHOUT
40
+ * Similarly, the AN521 and AN524 use the SSE-200, and the SSE-200 TRM defines
98
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
41
* most of the device layout:
99
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
42
* http://infocenter.arm.com/help/topic/com.arm.doc.101104_0100_00_en/corelink_sse200_subsystem_for_embedded_technical_reference_manual_101104_0100_00_en.pdf
100
+ * for more details.
43
*
101
+ */
44
@@ -XXX,XX +XXX,XX @@
102
+
45
#include "hw/qdev-clock.h"
103
+#include "qemu/osdep.h"
46
#include "qom/object.h"
104
+
47
105
+#include "hw/misc/npcm7xx_gcr.h"
48
-#define MPS2TZ_NUMIRQ_MAX 92
106
+#include "hw/qdev-properties.h"
49
+#define MPS2TZ_NUMIRQ_MAX 95
107
+#include "migration/vmstate.h"
50
#define MPS2TZ_RAM_MAX 4
108
+#include "qapi/error.h"
51
109
+#include "qemu/cutils.h"
52
typedef enum MPS2TZFPGAType {
110
+#include "qemu/log.h"
53
FPGA_AN505,
111
+#include "qemu/module.h"
54
FPGA_AN521,
112
+#include "qemu/units.h"
55
+ FPGA_AN524,
113
+
56
} MPS2TZFPGAType;
114
+#include "trace.h"
57
115
+
58
/*
116
+#define NPCM7XX_GCR_MIN_DRAM_SIZE (128 * MiB)
59
@@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineState {
117
+#define NPCM7XX_GCR_MAX_DRAM_SIZE (2 * GiB)
60
TZPPC ppc[5];
118
+
61
TZMPC mpc[3];
119
+enum NPCM7xxGCRRegisters {
62
PL022State spi[5];
120
+ NPCM7XX_GCR_PDID,
63
- ArmSbconI2CState i2c[4];
121
+ NPCM7XX_GCR_PWRON,
64
+ ArmSbconI2CState i2c[5];
122
+ NPCM7XX_GCR_MFSEL1 = 0x0c / sizeof(uint32_t),
65
UnimplementedDeviceState i2s_audio;
123
+ NPCM7XX_GCR_MFSEL2,
66
UnimplementedDeviceState gpio[4];
124
+ NPCM7XX_GCR_MISCPE,
67
UnimplementedDeviceState gfx;
125
+ NPCM7XX_GCR_SPSWC = 0x038 / sizeof(uint32_t),
68
+ UnimplementedDeviceState cldc;
126
+ NPCM7XX_GCR_INTCR,
69
+ UnimplementedDeviceState rtc;
127
+ NPCM7XX_GCR_INTSR,
70
PL080State dma[4];
128
+ NPCM7XX_GCR_HIFCR = 0x050 / sizeof(uint32_t),
71
TZMSC msc[4];
129
+ NPCM7XX_GCR_INTCR2 = 0x060 / sizeof(uint32_t),
72
- CMSDKAPBUART uart[5];
130
+ NPCM7XX_GCR_MFSEL3,
73
+ CMSDKAPBUART uart[6];
131
+ NPCM7XX_GCR_SRCNT,
74
SplitIRQ sec_resp_splitter;
132
+ NPCM7XX_GCR_RESSR,
75
qemu_or_irq uart_irq_orgate;
133
+ NPCM7XX_GCR_RLOCKR1,
76
DeviceState *lan9118;
134
+ NPCM7XX_GCR_FLOCKR1,
77
@@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineState {
135
+ NPCM7XX_GCR_DSCNT,
78
#define TYPE_MPS2TZ_MACHINE "mps2tz"
136
+ NPCM7XX_GCR_MDLR,
79
#define TYPE_MPS2TZ_AN505_MACHINE MACHINE_TYPE_NAME("mps2-an505")
137
+ NPCM7XX_GCR_SCRPAD3,
80
#define TYPE_MPS2TZ_AN521_MACHINE MACHINE_TYPE_NAME("mps2-an521")
138
+ NPCM7XX_GCR_SCRPAD2,
81
+#define TYPE_MPS3TZ_AN524_MACHINE MACHINE_TYPE_NAME("mps3-an524")
139
+ NPCM7XX_GCR_DAVCLVLR = 0x098 / sizeof(uint32_t),
82
140
+ NPCM7XX_GCR_INTCR3,
83
OBJECT_DECLARE_TYPE(MPS2TZMachineState, MPS2TZMachineClass, MPS2TZ_MACHINE)
141
+ NPCM7XX_GCR_VSINTR = 0x0ac / sizeof(uint32_t),
84
142
+ NPCM7XX_GCR_MFSEL4,
85
@@ -XXX,XX +XXX,XX @@ static const uint32_t an505_oscclk[] = {
143
+ NPCM7XX_GCR_CPBPNTR = 0x0c4 / sizeof(uint32_t),
86
25000000,
144
+ NPCM7XX_GCR_CPCTL = 0x0d0 / sizeof(uint32_t),
87
};
145
+ NPCM7XX_GCR_CP2BST,
88
146
+ NPCM7XX_GCR_B2CPNT,
89
+static const uint32_t an524_oscclk[] = {
147
+ NPCM7XX_GCR_CPPCTL,
90
+ 24000000,
148
+ NPCM7XX_GCR_I2CSEGSEL,
91
+ 32000000,
149
+ NPCM7XX_GCR_I2CSEGCTL,
92
+ 50000000,
150
+ NPCM7XX_GCR_VSRCR,
93
+ 50000000,
151
+ NPCM7XX_GCR_MLOCKR,
94
+ 24576000,
152
+ NPCM7XX_GCR_SCRPAD = 0x013c / sizeof(uint32_t),
95
+ 23750000,
153
+ NPCM7XX_GCR_USB1PHYCTL,
154
+ NPCM7XX_GCR_USB2PHYCTL,
155
+ NPCM7XX_GCR_REGS_END,
156
+};
96
+};
157
+
97
+
158
+static const uint32_t cold_reset_values[NPCM7XX_GCR_NR_REGS] = {
98
static const RAMInfo an505_raminfo[] = { {
159
+ [NPCM7XX_GCR_PDID] = 0x04a92750, /* Poleg A1 */
99
.name = "ssram-0",
160
+ [NPCM7XX_GCR_MISCPE] = 0x0000ffff,
100
.base = 0x00000000,
161
+ [NPCM7XX_GCR_SPSWC] = 0x00000003,
101
@@ -XXX,XX +XXX,XX @@ static const RAMInfo an505_raminfo[] = { {
162
+ [NPCM7XX_GCR_INTCR] = 0x0000035e,
102
},
163
+ [NPCM7XX_GCR_HIFCR] = 0x0000004e,
103
};
164
+ [NPCM7XX_GCR_INTCR2] = (1U << 19), /* DDR initialized */
104
165
+ [NPCM7XX_GCR_RESSR] = 0x80000000,
105
+static const RAMInfo an524_raminfo[] = { {
166
+ [NPCM7XX_GCR_DSCNT] = 0x000000c0,
106
+ .name = "bram",
167
+ [NPCM7XX_GCR_DAVCLVLR] = 0x5a00f3cf,
107
+ .base = 0x00000000,
168
+ [NPCM7XX_GCR_SCRPAD] = 0x00000008,
108
+ .size = 512 * KiB,
169
+ [NPCM7XX_GCR_USB1PHYCTL] = 0x034730e4,
109
+ .mpc = 0,
170
+ [NPCM7XX_GCR_USB2PHYCTL] = 0x034730e4,
110
+ .mrindex = 0,
171
+};
111
+ }, {
172
+
112
+ .name = "sram",
173
+static uint64_t npcm7xx_gcr_read(void *opaque, hwaddr offset, unsigned size)
113
+ .base = 0x20000000,
174
+{
114
+ .size = 32 * 4 * KiB,
175
+ uint32_t reg = offset / sizeof(uint32_t);
115
+ .mpc = 1,
176
+ NPCM7xxGCRState *s = opaque;
116
+ .mrindex = 1,
177
+
117
+ }, {
178
+ if (reg >= NPCM7XX_GCR_NR_REGS) {
118
+ /* We don't model QSPI flash yet; for now expose it as simple ROM */
179
+ qemu_log_mask(LOG_GUEST_ERROR,
119
+ .name = "QSPI",
180
+ "%s: offset 0x%04" HWADDR_PRIx " out of range\n",
120
+ .base = 0x28000000,
181
+ __func__, offset);
121
+ .size = 8 * MiB,
182
+ return 0;
122
+ .mpc = 1,
183
+ }
123
+ .mrindex = 2,
184
+
124
+ .flags = IS_ROM,
185
+ trace_npcm7xx_gcr_read(offset, s->regs[reg]);
125
+ }, {
186
+
126
+ .name = "DDR",
187
+ return s->regs[reg];
127
+ .base = 0x60000000,
188
+}
128
+ .size = 2 * GiB,
189
+
129
+ .mpc = 2,
190
+static void npcm7xx_gcr_write(void *opaque, hwaddr offset,
130
+ .mrindex = -1,
191
+ uint64_t v, unsigned size)
131
+ }, {
192
+{
132
+ .name = NULL,
193
+ uint32_t reg = offset / sizeof(uint32_t);
194
+ NPCM7xxGCRState *s = opaque;
195
+ uint32_t value = v;
196
+
197
+ trace_npcm7xx_gcr_write(offset, value);
198
+
199
+ if (reg >= NPCM7XX_GCR_NR_REGS) {
200
+ qemu_log_mask(LOG_GUEST_ERROR,
201
+ "%s: offset 0x%04" HWADDR_PRIx " out of range\n",
202
+ __func__, offset);
203
+ return;
204
+ }
205
+
206
+ switch (reg) {
207
+ case NPCM7XX_GCR_PDID:
208
+ case NPCM7XX_GCR_PWRON:
209
+ case NPCM7XX_GCR_INTSR:
210
+ qemu_log_mask(LOG_GUEST_ERROR,
211
+ "%s: register @ 0x%04" HWADDR_PRIx " is read-only\n",
212
+ __func__, offset);
213
+ return;
214
+
215
+ case NPCM7XX_GCR_RESSR:
216
+ case NPCM7XX_GCR_CP2BST:
217
+ /* Write 1 to clear */
218
+ value = s->regs[reg] & ~value;
219
+ break;
220
+
221
+ case NPCM7XX_GCR_RLOCKR1:
222
+ case NPCM7XX_GCR_MDLR:
223
+ /* Write 1 to set */
224
+ value |= s->regs[reg];
225
+ break;
226
+ };
227
+
228
+ s->regs[reg] = value;
229
+}
230
+
231
+static const struct MemoryRegionOps npcm7xx_gcr_ops = {
232
+ .read = npcm7xx_gcr_read,
233
+ .write = npcm7xx_gcr_write,
234
+ .endianness = DEVICE_LITTLE_ENDIAN,
235
+ .valid = {
236
+ .min_access_size = 4,
237
+ .max_access_size = 4,
238
+ .unaligned = false,
239
+ },
133
+ },
240
+};
134
+};
241
+
135
+
242
+static void npcm7xx_gcr_enter_reset(Object *obj, ResetType type)
136
static const RAMInfo *find_raminfo_for_mpc(MPS2TZMachineState *mms, int mpc)
137
{
138
MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
139
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
140
},
141
};
142
143
+ const PPCInfo an524_ppcs[] = { {
144
+ .name = "apb_ppcexp0",
145
+ .ports = {
146
+ { "bram-mpc", make_mpc, &mms->mpc[0], 0x58007000, 0x1000 },
147
+ { "qspi-mpc", make_mpc, &mms->mpc[1], 0x58008000, 0x1000 },
148
+ { "ddr-mpc", make_mpc, &mms->mpc[2], 0x58009000, 0x1000 },
149
+ },
150
+ }, {
151
+ .name = "apb_ppcexp1",
152
+ .ports = {
153
+ { "i2c0", make_i2c, &mms->i2c[0], 0x41200000, 0x1000 },
154
+ { "i2c1", make_i2c, &mms->i2c[1], 0x41201000, 0x1000 },
155
+ { "spi0", make_spi, &mms->spi[0], 0x41202000, 0x1000, { 52 } },
156
+ { "spi1", make_spi, &mms->spi[1], 0x41203000, 0x1000, { 53 } },
157
+ { "spi2", make_spi, &mms->spi[2], 0x41204000, 0x1000, { 54 } },
158
+ { "i2c2", make_i2c, &mms->i2c[2], 0x41205000, 0x1000 },
159
+ { "i2c3", make_i2c, &mms->i2c[3], 0x41206000, 0x1000 },
160
+ { /* port 7 reserved */ },
161
+ { "i2c4", make_i2c, &mms->i2c[4], 0x41208000, 0x1000 },
162
+ },
163
+ }, {
164
+ .name = "apb_ppcexp2",
165
+ .ports = {
166
+ { "scc", make_scc, &mms->scc, 0x41300000, 0x1000 },
167
+ { "i2s-audio", make_unimp_dev, &mms->i2s_audio,
168
+ 0x41301000, 0x1000 },
169
+ { "fpgaio", make_fpgaio, &mms->fpgaio, 0x41302000, 0x1000 },
170
+ { "uart0", make_uart, &mms->uart[0], 0x41303000, 0x1000, { 32, 33, 42 } },
171
+ { "uart1", make_uart, &mms->uart[1], 0x41304000, 0x1000, { 34, 35, 43 } },
172
+ { "uart2", make_uart, &mms->uart[2], 0x41305000, 0x1000, { 36, 37, 44 } },
173
+ { "uart3", make_uart, &mms->uart[3], 0x41306000, 0x1000, { 38, 39, 45 } },
174
+ { "uart4", make_uart, &mms->uart[4], 0x41307000, 0x1000, { 40, 41, 46 } },
175
+ { "uart5", make_uart, &mms->uart[5], 0x41308000, 0x1000, { 124, 125, 126 } },
176
+
177
+ { /* port 9 reserved */ },
178
+ { "clcd", make_unimp_dev, &mms->cldc, 0x4130a000, 0x1000 },
179
+ { "rtc", make_unimp_dev, &mms->rtc, 0x4130b000, 0x1000 },
180
+ },
181
+ }, {
182
+ .name = "ahb_ppcexp0",
183
+ .ports = {
184
+ { "gpio0", make_unimp_dev, &mms->gpio[0], 0x41100000, 0x1000 },
185
+ { "gpio1", make_unimp_dev, &mms->gpio[1], 0x41101000, 0x1000 },
186
+ { "gpio2", make_unimp_dev, &mms->gpio[2], 0x41102000, 0x1000 },
187
+ { "gpio3", make_unimp_dev, &mms->gpio[3], 0x41103000, 0x1000 },
188
+ { "eth", make_eth_dev, NULL, 0x41400000, 0x100000, { 48 } },
189
+ },
190
+ },
191
+ };
192
+
193
switch (mmc->fpga_type) {
194
case FPGA_AN505:
195
case FPGA_AN521:
196
ppcs = an505_ppcs;
197
num_ppcs = ARRAY_SIZE(an505_ppcs);
198
break;
199
+ case FPGA_AN524:
200
+ ppcs = an524_ppcs;
201
+ num_ppcs = ARRAY_SIZE(an524_ppcs);
202
+ break;
203
default:
204
g_assert_not_reached();
205
}
206
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an521_class_init(ObjectClass *oc, void *data)
207
mps2tz_set_default_ram_info(mmc);
208
}
209
210
+static void mps3tz_an524_class_init(ObjectClass *oc, void *data)
243
+{
211
+{
244
+ NPCM7xxGCRState *s = NPCM7XX_GCR(obj);
212
+ MachineClass *mc = MACHINE_CLASS(oc);
245
+
213
+ MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_CLASS(oc);
246
+ QEMU_BUILD_BUG_ON(sizeof(s->regs) != sizeof(cold_reset_values));
214
+
247
+
215
+ mc->desc = "ARM MPS3 with AN524 FPGA image for dual Cortex-M33";
248
+ switch (type) {
216
+ mc->default_cpus = 2;
249
+ case RESET_TYPE_COLD:
217
+ mc->min_cpus = mc->default_cpus;
250
+ memcpy(s->regs, cold_reset_values, sizeof(s->regs));
218
+ mc->max_cpus = mc->default_cpus;
251
+ s->regs[NPCM7XX_GCR_PWRON] = s->reset_pwron;
219
+ mmc->fpga_type = FPGA_AN524;
252
+ s->regs[NPCM7XX_GCR_MDLR] = s->reset_mdlr;
220
+ mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m33");
253
+ s->regs[NPCM7XX_GCR_INTCR3] = s->reset_intcr3;
221
+ mmc->scc_id = 0x41045240;
254
+ break;
222
+ mmc->sysclk_frq = 32 * 1000 * 1000; /* 32MHz */
255
+ }
223
+ mmc->oscclk = an524_oscclk;
224
+ mmc->len_oscclk = ARRAY_SIZE(an524_oscclk);
225
+ mmc->fpgaio_num_leds = 10;
226
+ mmc->fpgaio_has_switches = true;
227
+ mmc->numirq = 95;
228
+ mmc->raminfo = an524_raminfo;
229
+ mmc->armsse_type = TYPE_SSE200;
230
+ mps2tz_set_default_ram_info(mmc);
256
+}
231
+}
257
+
232
+
258
+static void npcm7xx_gcr_realize(DeviceState *dev, Error **errp)
233
static const TypeInfo mps2tz_info = {
259
+{
234
.name = TYPE_MPS2TZ_MACHINE,
260
+ ERRP_GUARD();
235
.parent = TYPE_MACHINE,
261
+ NPCM7xxGCRState *s = NPCM7XX_GCR(dev);
236
@@ -XXX,XX +XXX,XX @@ static const TypeInfo mps2tz_an521_info = {
262
+ uint64_t dram_size;
237
.class_init = mps2tz_an521_class_init,
263
+ Object *obj;
238
};
264
+
239
265
+ obj = object_property_get_link(OBJECT(dev), "dram-mr", errp);
240
+static const TypeInfo mps3tz_an524_info = {
266
+ if (!obj) {
241
+ .name = TYPE_MPS3TZ_AN524_MACHINE,
267
+ error_prepend(errp, "%s: required dram-mr link not found: ", __func__);
242
+ .parent = TYPE_MPS2TZ_MACHINE,
268
+ return;
243
+ .class_init = mps3tz_an524_class_init,
269
+ }
270
+ dram_size = memory_region_size(MEMORY_REGION(obj));
271
+ if (!is_power_of_2(dram_size) ||
272
+ dram_size < NPCM7XX_GCR_MIN_DRAM_SIZE ||
273
+ dram_size > NPCM7XX_GCR_MAX_DRAM_SIZE) {
274
+ g_autofree char *sz = size_to_str(dram_size);
275
+ g_autofree char *min_sz = size_to_str(NPCM7XX_GCR_MIN_DRAM_SIZE);
276
+ g_autofree char *max_sz = size_to_str(NPCM7XX_GCR_MAX_DRAM_SIZE);
277
+ error_setg(errp, "%s: unsupported DRAM size %s", __func__, sz);
278
+ error_append_hint(errp,
279
+ "DRAM size must be a power of two between %s and %s,"
280
+ " inclusive.\n", min_sz, max_sz);
281
+ return;
282
+ }
283
+
284
+ /* Power-on reset value */
285
+ s->reset_intcr3 = 0x00001002;
286
+
287
+ /*
288
+ * The GMMAP (Graphics Memory Map) field is used by u-boot to detect the
289
+ * DRAM size, and is normally initialized by the boot block as part of DRAM
290
+ * training. However, since we don't have a complete emulation of the
291
+ * memory controller and try to make it look like it has already been
292
+ * initialized, the boot block will skip this initialization, and we need
293
+ * to make sure this field is set correctly up front.
294
+ *
295
+ * WARNING: some versions of u-boot only looks at bits 8 and 9, so 2 GiB of
296
+ * DRAM will be interpreted as 128 MiB.
297
+ *
298
+ * https://github.com/Nuvoton-Israel/u-boot/blob/2aef993bd2aafeb5408dbaad0f3ce099ee40c4aa/board/nuvoton/poleg/poleg.c#L244
299
+ */
300
+ s->reset_intcr3 |= ctz64(dram_size / NPCM7XX_GCR_MIN_DRAM_SIZE) << 8;
301
+}
302
+
303
+static void npcm7xx_gcr_init(Object *obj)
304
+{
305
+ NPCM7xxGCRState *s = NPCM7XX_GCR(obj);
306
+
307
+ memory_region_init_io(&s->iomem, obj, &npcm7xx_gcr_ops, s,
308
+ TYPE_NPCM7XX_GCR, 4 * KiB);
309
+ sysbus_init_mmio(&s->parent, &s->iomem);
310
+}
311
+
312
+static const VMStateDescription vmstate_npcm7xx_gcr = {
313
+ .name = "npcm7xx-gcr",
314
+ .version_id = 0,
315
+ .minimum_version_id = 0,
316
+ .fields = (VMStateField[]) {
317
+ VMSTATE_UINT32_ARRAY(regs, NPCM7xxGCRState, NPCM7XX_GCR_NR_REGS),
318
+ VMSTATE_END_OF_LIST(),
319
+ },
320
+};
244
+};
321
+
245
+
322
+static Property npcm7xx_gcr_properties[] = {
246
static void mps2tz_machine_init(void)
323
+ DEFINE_PROP_UINT32("disabled-modules", NPCM7xxGCRState, reset_mdlr, 0),
247
{
324
+ DEFINE_PROP_UINT32("power-on-straps", NPCM7xxGCRState, reset_pwron, 0),
248
type_register_static(&mps2tz_info);
325
+ DEFINE_PROP_END_OF_LIST(),
249
type_register_static(&mps2tz_an505_info);
326
+};
250
type_register_static(&mps2tz_an521_info);
327
+
251
+ type_register_static(&mps3tz_an524_info);
328
+static void npcm7xx_gcr_class_init(ObjectClass *klass, void *data)
252
}
329
+{
253
330
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
254
type_init(mps2tz_machine_init);
331
+ DeviceClass *dc = DEVICE_CLASS(klass);
332
+
333
+ QEMU_BUILD_BUG_ON(NPCM7XX_GCR_REGS_END > NPCM7XX_GCR_NR_REGS);
334
+
335
+ dc->desc = "NPCM7xx System Global Control Registers";
336
+ dc->realize = npcm7xx_gcr_realize;
337
+ dc->vmsd = &vmstate_npcm7xx_gcr;
338
+ rc->phases.enter = npcm7xx_gcr_enter_reset;
339
+
340
+ device_class_set_props(dc, npcm7xx_gcr_properties);
341
+}
342
+
343
+static const TypeInfo npcm7xx_gcr_info = {
344
+ .name = TYPE_NPCM7XX_GCR,
345
+ .parent = TYPE_SYS_BUS_DEVICE,
346
+ .instance_size = sizeof(NPCM7xxGCRState),
347
+ .instance_init = npcm7xx_gcr_init,
348
+ .class_init = npcm7xx_gcr_class_init,
349
+};
350
+
351
+static void npcm7xx_gcr_register_type(void)
352
+{
353
+ type_register_static(&npcm7xx_gcr_info);
354
+}
355
+type_init(npcm7xx_gcr_register_type);
356
diff --git a/MAINTAINERS b/MAINTAINERS
357
index XXXXXXX..XXXXXXX 100644
358
--- a/MAINTAINERS
359
+++ b/MAINTAINERS
360
@@ -XXX,XX +XXX,XX @@ S: Odd Fixes
361
F: hw/arm/musicpal.c
362
F: docs/system/arm/musicpal.rst
363
364
+Nuvoton NPCM7xx
365
+M: Havard Skinnemoen <hskinnemoen@google.com>
366
+M: Tyrone Ting <kfting@nuvoton.com>
367
+L: qemu-arm@nongnu.org
368
+S: Supported
369
+F: hw/*/npcm7xx*
370
+F: include/hw/*/npcm7xx*
371
+
372
nSeries
373
M: Andrzej Zaborowski <balrogg@gmail.com>
374
M: Peter Maydell <peter.maydell@linaro.org>
375
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
376
index XXXXXXX..XXXXXXX 100644
377
--- a/hw/arm/Kconfig
378
+++ b/hw/arm/Kconfig
379
@@ -XXX,XX +XXX,XX @@ config XLNX_VERSAL
380
select VIRTIO_MMIO
381
select UNIMP
382
383
+config NPCM7XX
384
+ bool
385
+
386
config FSL_IMX25
387
bool
388
select IMX
389
diff --git a/hw/misc/meson.build b/hw/misc/meson.build
390
index XXXXXXX..XXXXXXX 100644
391
--- a/hw/misc/meson.build
392
+++ b/hw/misc/meson.build
393
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_IMX', if_true: files(
394
))
395
softmmu_ss.add(when: 'CONFIG_MILKYMIST', if_true: files('milkymist-hpdmc.c', 'milkymist-pfpu.c'))
396
softmmu_ss.add(when: 'CONFIG_MAINSTONE', if_true: files('mst_fpga.c'))
397
+softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files(
398
+ 'npcm7xx_gcr.c',
399
+))
400
softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files(
401
'omap_clk.c',
402
'omap_gpmc.c',
403
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
404
index XXXXXXX..XXXXXXX 100644
405
--- a/hw/misc/trace-events
406
+++ b/hw/misc/trace-events
407
@@ -XXX,XX +XXX,XX @@ mos6522_set_sr_int(void) "set sr_int"
408
mos6522_write(uint64_t addr, uint64_t val) "reg=0x%"PRIx64 " val=0x%"PRIx64
409
mos6522_read(uint64_t addr, unsigned val) "reg=0x%"PRIx64 " val=0x%x"
410
411
+# npcm7xx_gcr.c
412
+npcm7xx_gcr_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
413
+npcm7xx_gcr_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
414
+
415
# stm32f4xx_syscfg.c
416
stm32f4xx_syscfg_set_irq(int gpio, int line, int level) "Interupt: GPIO: %d, Line: %d; Level: %d"
417
stm32f4xx_pulse_exti(int irq) "Pulse EXTI: %d"
418
--
255
--
419
2.20.1
256
2.20.1
420
257
421
258
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
The AN524 has a USB controller (an ISP1763); we don't have a model of
2
it but we should provide a stub "unimplemented-device" for it. This
3
is slightly complicated because the USB controller shares a PPC port
4
with the ethernet controller.
2
5
3
This supports reading and writing OTP fuses and keys. Only fuse reading
6
Implement a make_* function which provides creates a container
4
has been tested. Protection is not implemented.
7
MemoryRegion with both the ethernet controller and an
8
unimplemented-device stub for the USB controller.
5
9
6
Reviewed-by: Avi Fishman <avi.fishman@nuvoton.com>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
11
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
12
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Tested-by: Alexander Bulekov <alxndr@bu.edu>
13
Message-id: 20210215115138.20465-22-peter.maydell@linaro.org
10
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
11
Message-id: 20200911052101.2602693-9-hskinnemoen@google.com
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
---
14
---
14
include/hw/arm/npcm7xx.h | 3 +
15
hw/arm/mps2-tz.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
15
include/hw/nvram/npcm7xx_otp.h | 79 ++++++
16
1 file changed, 47 insertions(+), 1 deletion(-)
16
hw/arm/npcm7xx.c | 29 +++
17
hw/nvram/npcm7xx_otp.c | 440 +++++++++++++++++++++++++++++++++
18
hw/nvram/meson.build | 1 +
19
5 files changed, 552 insertions(+)
20
create mode 100644 include/hw/nvram/npcm7xx_otp.h
21
create mode 100644 hw/nvram/npcm7xx_otp.c
22
17
23
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
18
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
24
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
25
--- a/include/hw/arm/npcm7xx.h
20
--- a/hw/arm/mps2-tz.c
26
+++ b/include/hw/arm/npcm7xx.h
21
+++ b/hw/arm/mps2-tz.c
27
@@ -XXX,XX +XXX,XX @@
22
@@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineState {
28
#include "hw/cpu/a9mpcore.h"
23
29
#include "hw/misc/npcm7xx_clk.h"
24
ARMSSE iotkit;
30
#include "hw/misc/npcm7xx_gcr.h"
25
MemoryRegion ram[MPS2TZ_RAM_MAX];
31
+#include "hw/nvram/npcm7xx_otp.h"
26
+ MemoryRegion eth_usb_container;
32
#include "hw/timer/npcm7xx_timer.h"
33
#include "target/arm/cpu.h"
34
35
@@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState {
36
NPCM7xxGCRState gcr;
37
NPCM7xxCLKState clk;
38
NPCM7xxTimerCtrlState tim[3];
39
+ NPCM7xxOTPState key_storage;
40
+ NPCM7xxOTPState fuse_array;
41
} NPCM7xxState;
42
43
#define TYPE_NPCM7XX "npcm7xx"
44
diff --git a/include/hw/nvram/npcm7xx_otp.h b/include/hw/nvram/npcm7xx_otp.h
45
new file mode 100644
46
index XXXXXXX..XXXXXXX
47
--- /dev/null
48
+++ b/include/hw/nvram/npcm7xx_otp.h
49
@@ -XXX,XX +XXX,XX @@
50
+/*
51
+ * Nuvoton NPCM7xx OTP (Fuse Array) Interface
52
+ *
53
+ * Copyright 2020 Google LLC
54
+ *
55
+ * This program is free software; you can redistribute it and/or modify it
56
+ * under the terms of the GNU General Public License as published by the
57
+ * Free Software Foundation; either version 2 of the License, or
58
+ * (at your option) any later version.
59
+ *
60
+ * This program is distributed in the hope that it will be useful, but WITHOUT
61
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
62
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
63
+ * for more details.
64
+ */
65
+#ifndef NPCM7XX_OTP_H
66
+#define NPCM7XX_OTP_H
67
+
27
+
68
+#include "exec/memory.h"
28
MPS2SCC scc;
69
+#include "hw/sysbus.h"
29
MPS2FPGAIO fpgaio;
30
TZPPC ppc[5];
31
@@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineState {
32
UnimplementedDeviceState gfx;
33
UnimplementedDeviceState cldc;
34
UnimplementedDeviceState rtc;
35
+ UnimplementedDeviceState usb;
36
PL080State dma[4];
37
TZMSC msc[4];
38
CMSDKAPBUART uart[6];
39
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_eth_dev(MPS2TZMachineState *mms, void *opaque,
40
return sysbus_mmio_get_region(s, 0);
41
}
42
43
+static MemoryRegion *make_eth_usb(MPS2TZMachineState *mms, void *opaque,
44
+ const char *name, hwaddr size,
45
+ const int *irqs)
46
+{
47
+ /*
48
+ * The AN524 makes the ethernet and USB share a PPC port.
49
+ * irqs[] is the ethernet IRQ.
50
+ */
51
+ SysBusDevice *s;
52
+ NICInfo *nd = &nd_table[0];
70
+
53
+
71
+/* Each OTP module holds 8192 bits of one-time programmable storage */
54
+ memory_region_init(&mms->eth_usb_container, OBJECT(mms),
72
+#define NPCM7XX_OTP_ARRAY_BITS (8192)
55
+ "mps2-tz-eth-usb-container", 0x200000);
73
+#define NPCM7XX_OTP_ARRAY_BYTES (NPCM7XX_OTP_ARRAY_BITS / BITS_PER_BYTE)
74
+
75
+/* Fuse array offsets */
76
+#define NPCM7XX_FUSE_FUSTRAP (0)
77
+#define NPCM7XX_FUSE_CP_FUSTRAP (12)
78
+#define NPCM7XX_FUSE_DAC_CALIB (16)
79
+#define NPCM7XX_FUSE_ADC_CALIB (24)
80
+#define NPCM7XX_FUSE_DERIVATIVE (64)
81
+#define NPCM7XX_FUSE_TEST_SIG (72)
82
+#define NPCM7XX_FUSE_DIE_LOCATION (74)
83
+#define NPCM7XX_FUSE_GP1 (80)
84
+#define NPCM7XX_FUSE_GP2 (128)
85
+
86
+/*
87
+ * Number of registers in our device state structure. Don't change this without
88
+ * incrementing the version_id in the vmstate.
89
+ */
90
+#define NPCM7XX_OTP_NR_REGS (0x18 / sizeof(uint32_t))
91
+
92
+/**
93
+ * struct NPCM7xxOTPState - Device state for one OTP module.
94
+ * @parent: System bus device.
95
+ * @mmio: Memory region through which registers are accessed.
96
+ * @regs: Register contents.
97
+ * @array: OTP storage array.
98
+ */
99
+typedef struct NPCM7xxOTPState {
100
+ SysBusDevice parent;
101
+
102
+ MemoryRegion mmio;
103
+ uint32_t regs[NPCM7XX_OTP_NR_REGS];
104
+ uint8_t array[NPCM7XX_OTP_ARRAY_BYTES];
105
+} NPCM7xxOTPState;
106
+
107
+#define TYPE_NPCM7XX_OTP "npcm7xx-otp"
108
+#define NPCM7XX_OTP(obj) OBJECT_CHECK(NPCM7xxOTPState, (obj), TYPE_NPCM7XX_OTP)
109
+
110
+#define TYPE_NPCM7XX_KEY_STORAGE "npcm7xx-key-storage"
111
+#define TYPE_NPCM7XX_FUSE_ARRAY "npcm7xx-fuse-array"
112
+
113
+typedef struct NPCM7xxOTPClass NPCM7xxOTPClass;
114
+
115
+/**
116
+ * npcm7xx_otp_array_write - ECC encode and write data to OTP array.
117
+ * @s: OTP module.
118
+ * @data: Data to be encoded and written.
119
+ * @offset: Offset of first byte to be written in the OTP array.
120
+ * @len: Number of bytes before ECC encoding.
121
+ *
122
+ * Each nibble of data is encoded into a byte, so the number of bytes written
123
+ * to the array will be @len * 2.
124
+ */
125
+extern void npcm7xx_otp_array_write(NPCM7xxOTPState *s, const void *data,
126
+ unsigned int offset, unsigned int len);
127
+
128
+#endif /* NPCM7XX_OTP_H */
129
diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c
130
index XXXXXXX..XXXXXXX 100644
131
--- a/hw/arm/npcm7xx.c
132
+++ b/hw/arm/npcm7xx.c
133
@@ -XXX,XX +XXX,XX @@
134
#define NPCM7XX_MMIO_BA (0x80000000)
135
#define NPCM7XX_MMIO_SZ (0x7ffd0000)
136
137
+/* OTP key storage and fuse strap array */
138
+#define NPCM7XX_OTP1_BA (0xf0189000)
139
+#define NPCM7XX_OTP2_BA (0xf018a000)
140
+
141
/* Core system modules. */
142
#define NPCM7XX_L2C_BA (0xf03fc000)
143
#define NPCM7XX_CPUP_BA (0xf03fe000)
144
@@ -XXX,XX +XXX,XX @@ void npcm7xx_load_kernel(MachineState *machine, NPCM7xxState *soc)
145
arm_load_kernel(&soc->cpu[0], machine, &npcm7xx_binfo);
146
}
147
148
+static void npcm7xx_init_fuses(NPCM7xxState *s)
149
+{
150
+ NPCM7xxClass *nc = NPCM7XX_GET_CLASS(s);
151
+ uint32_t value;
152
+
56
+
153
+ /*
57
+ /*
154
+ * The initial mask of disabled modules indicates the chip derivative (e.g.
58
+ * In hardware this is a LAN9220; the LAN9118 is software compatible
155
+ * NPCM750 or NPCM730).
59
+ * except that it doesn't support the checksum-offload feature.
156
+ */
60
+ */
157
+ value = tswap32(nc->disabled_modules);
61
+ qemu_check_nic_model(nd, "lan9118");
158
+ npcm7xx_otp_array_write(&s->fuse_array, &value, NPCM7XX_FUSE_DERIVATIVE,
62
+ mms->lan9118 = qdev_new(TYPE_LAN9118);
159
+ sizeof(value));
63
+ qdev_set_nic_properties(mms->lan9118, nd);
64
+
65
+ s = SYS_BUS_DEVICE(mms->lan9118);
66
+ sysbus_realize_and_unref(s, &error_fatal);
67
+ sysbus_connect_irq(s, 0, get_sse_irq_in(mms, irqs[0]));
68
+
69
+ memory_region_add_subregion(&mms->eth_usb_container,
70
+ 0, sysbus_mmio_get_region(s, 0));
71
+
72
+ /* The USB OTG controller is an ISP1763; we don't have a model of it. */
73
+ object_initialize_child(OBJECT(mms), "usb-otg",
74
+ &mms->usb, TYPE_UNIMPLEMENTED_DEVICE);
75
+ qdev_prop_set_string(DEVICE(&mms->usb), "name", "usb-otg");
76
+ qdev_prop_set_uint64(DEVICE(&mms->usb), "size", 0x100000);
77
+ s = SYS_BUS_DEVICE(&mms->usb);
78
+ sysbus_realize(s, &error_fatal);
79
+
80
+ memory_region_add_subregion(&mms->eth_usb_container,
81
+ 0x100000, sysbus_mmio_get_region(s, 0));
82
+
83
+ return &mms->eth_usb_container;
160
+}
84
+}
161
+
85
+
162
static qemu_irq npcm7xx_irq(NPCM7xxState *s, int n)
86
static MemoryRegion *make_mpc(MPS2TZMachineState *mms, void *opaque,
163
{
87
const char *name, hwaddr size,
164
return qdev_get_gpio_in(DEVICE(&s->a9mpcore), n);
88
const int *irqs)
165
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj)
89
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
166
object_property_add_alias(obj, "power-on-straps", OBJECT(&s->gcr),
90
{ "gpio1", make_unimp_dev, &mms->gpio[1], 0x41101000, 0x1000 },
167
"power-on-straps");
91
{ "gpio2", make_unimp_dev, &mms->gpio[2], 0x41102000, 0x1000 },
168
object_initialize_child(obj, "clk", &s->clk, TYPE_NPCM7XX_CLK);
92
{ "gpio3", make_unimp_dev, &mms->gpio[3], 0x41103000, 0x1000 },
169
+ object_initialize_child(obj, "otp1", &s->key_storage,
93
- { "eth", make_eth_dev, NULL, 0x41400000, 0x100000, { 48 } },
170
+ TYPE_NPCM7XX_KEY_STORAGE);
94
+ { "eth-usb", make_eth_usb, NULL, 0x41400000, 0x200000, { 48 } },
171
+ object_initialize_child(obj, "otp2", &s->fuse_array,
95
},
172
+ TYPE_NPCM7XX_FUSE_ARRAY);
96
},
173
97
};
174
for (i = 0; i < ARRAY_SIZE(s->tim); i++) {
175
object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER);
176
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
177
sysbus_realize(SYS_BUS_DEVICE(&s->clk), &error_abort);
178
sysbus_mmio_map(SYS_BUS_DEVICE(&s->clk), 0, NPCM7XX_CLK_BA);
179
180
+ /* OTP key storage and fuse strap array. Cannot fail. */
181
+ sysbus_realize(SYS_BUS_DEVICE(&s->key_storage), &error_abort);
182
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->key_storage), 0, NPCM7XX_OTP1_BA);
183
+ sysbus_realize(SYS_BUS_DEVICE(&s->fuse_array), &error_abort);
184
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->fuse_array), 0, NPCM7XX_OTP2_BA);
185
+ npcm7xx_init_fuses(s);
186
+
187
/* Timer Modules (TIM). Cannot fail. */
188
QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_tim_addr) != ARRAY_SIZE(s->tim));
189
for (i = 0; i < ARRAY_SIZE(s->tim); i++) {
190
diff --git a/hw/nvram/npcm7xx_otp.c b/hw/nvram/npcm7xx_otp.c
191
new file mode 100644
192
index XXXXXXX..XXXXXXX
193
--- /dev/null
194
+++ b/hw/nvram/npcm7xx_otp.c
195
@@ -XXX,XX +XXX,XX @@
196
+/*
197
+ * Nuvoton NPCM7xx OTP (Fuse Array) Interface
198
+ *
199
+ * Copyright 2020 Google LLC
200
+ *
201
+ * This program is free software; you can redistribute it and/or modify it
202
+ * under the terms of the GNU General Public License as published by the
203
+ * Free Software Foundation; either version 2 of the License, or
204
+ * (at your option) any later version.
205
+ *
206
+ * This program is distributed in the hope that it will be useful, but WITHOUT
207
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
208
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
209
+ * for more details.
210
+ */
211
+
212
+#include "qemu/osdep.h"
213
+
214
+#include "hw/nvram/npcm7xx_otp.h"
215
+#include "migration/vmstate.h"
216
+#include "qapi/error.h"
217
+#include "qemu/bitops.h"
218
+#include "qemu/log.h"
219
+#include "qemu/module.h"
220
+#include "qemu/units.h"
221
+
222
+/* Each module has 4 KiB of register space. Only a fraction of it is used. */
223
+#define NPCM7XX_OTP_REGS_SIZE (4 * KiB)
224
+
225
+/* 32-bit register indices. */
226
+typedef enum NPCM7xxOTPRegister {
227
+ NPCM7XX_OTP_FST,
228
+ NPCM7XX_OTP_FADDR,
229
+ NPCM7XX_OTP_FDATA,
230
+ NPCM7XX_OTP_FCFG,
231
+ /* Offset 0x10 is FKEYIND in OTP1, FUSTRAP in OTP2 */
232
+ NPCM7XX_OTP_FKEYIND = 0x0010 / sizeof(uint32_t),
233
+ NPCM7XX_OTP_FUSTRAP = 0x0010 / sizeof(uint32_t),
234
+ NPCM7XX_OTP_FCTL,
235
+ NPCM7XX_OTP_REGS_END,
236
+} NPCM7xxOTPRegister;
237
+
238
+/* Register field definitions. */
239
+#define FST_RIEN BIT(2)
240
+#define FST_RDST BIT(1)
241
+#define FST_RDY BIT(0)
242
+#define FST_RO_MASK (FST_RDST | FST_RDY)
243
+
244
+#define FADDR_BYTEADDR(rv) extract32((rv), 0, 10)
245
+#define FADDR_BITPOS(rv) extract32((rv), 10, 3)
246
+
247
+#define FDATA_CLEAR 0x00000001
248
+
249
+#define FCFG_FDIS BIT(31)
250
+#define FCFG_FCFGLK_MASK 0x00ff0000
251
+
252
+#define FCTL_PROG_CMD1 0x00000001
253
+#define FCTL_PROG_CMD2 0xbf79e5d0
254
+#define FCTL_READ_CMD 0x00000002
255
+
256
+/**
257
+ * struct NPCM7xxOTPClass - OTP module class.
258
+ * @parent: System bus device class.
259
+ * @mmio_ops: MMIO register operations for this type of module.
260
+ *
261
+ * The two OTP modules (key-storage and fuse-array) have slightly different
262
+ * behavior, so we give them different MMIO register operations.
263
+ */
264
+struct NPCM7xxOTPClass {
265
+ SysBusDeviceClass parent;
266
+
267
+ const MemoryRegionOps *mmio_ops;
268
+};
269
+
270
+#define NPCM7XX_OTP_CLASS(klass) \
271
+ OBJECT_CLASS_CHECK(NPCM7xxOTPClass, (klass), TYPE_NPCM7XX_OTP)
272
+#define NPCM7XX_OTP_GET_CLASS(obj) \
273
+ OBJECT_GET_CLASS(NPCM7xxOTPClass, (obj), TYPE_NPCM7XX_OTP)
274
+
275
+static uint8_t ecc_encode_nibble(uint8_t n)
276
+{
277
+ uint8_t result = n;
278
+
279
+ result |= (((n >> 0) & 1) ^ ((n >> 1) & 1)) << 4;
280
+ result |= (((n >> 2) & 1) ^ ((n >> 3) & 1)) << 5;
281
+ result |= (((n >> 0) & 1) ^ ((n >> 2) & 1)) << 6;
282
+ result |= (((n >> 1) & 1) ^ ((n >> 3) & 1)) << 7;
283
+
284
+ return result;
285
+}
286
+
287
+void npcm7xx_otp_array_write(NPCM7xxOTPState *s, const void *data,
288
+ unsigned int offset, unsigned int len)
289
+{
290
+ const uint8_t *src = data;
291
+ uint8_t *dst = &s->array[offset];
292
+
293
+ while (len-- > 0) {
294
+ uint8_t c = *src++;
295
+
296
+ *dst++ = ecc_encode_nibble(extract8(c, 0, 4));
297
+ *dst++ = ecc_encode_nibble(extract8(c, 4, 4));
298
+ }
299
+}
300
+
301
+/* Common register read handler for both OTP classes. */
302
+static uint64_t npcm7xx_otp_read(NPCM7xxOTPState *s, NPCM7xxOTPRegister reg)
303
+{
304
+ uint32_t value = 0;
305
+
306
+ switch (reg) {
307
+ case NPCM7XX_OTP_FST:
308
+ case NPCM7XX_OTP_FADDR:
309
+ case NPCM7XX_OTP_FDATA:
310
+ case NPCM7XX_OTP_FCFG:
311
+ value = s->regs[reg];
312
+ break;
313
+
314
+ case NPCM7XX_OTP_FCTL:
315
+ qemu_log_mask(LOG_GUEST_ERROR,
316
+ "%s: read from write-only FCTL register\n",
317
+ DEVICE(s)->canonical_path);
318
+ break;
319
+
320
+ default:
321
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: read from invalid offset 0x%zx\n",
322
+ DEVICE(s)->canonical_path, reg * sizeof(uint32_t));
323
+ break;
324
+ }
325
+
326
+ return value;
327
+}
328
+
329
+/* Read a byte from the OTP array into the data register. */
330
+static void npcm7xx_otp_read_array(NPCM7xxOTPState *s)
331
+{
332
+ uint32_t faddr = s->regs[NPCM7XX_OTP_FADDR];
333
+
334
+ s->regs[NPCM7XX_OTP_FDATA] = s->array[FADDR_BYTEADDR(faddr)];
335
+ s->regs[NPCM7XX_OTP_FST] |= FST_RDST | FST_RDY;
336
+}
337
+
338
+/* Program a byte from the data register into the OTP array. */
339
+static void npcm7xx_otp_program_array(NPCM7xxOTPState *s)
340
+{
341
+ uint32_t faddr = s->regs[NPCM7XX_OTP_FADDR];
342
+
343
+ /* Bits can only go 0->1, never 1->0. */
344
+ s->array[FADDR_BYTEADDR(faddr)] |= (1U << FADDR_BITPOS(faddr));
345
+ s->regs[NPCM7XX_OTP_FST] |= FST_RDST | FST_RDY;
346
+}
347
+
348
+/* Compute the next value of the FCFG register. */
349
+static uint32_t npcm7xx_otp_compute_fcfg(uint32_t cur_value, uint32_t new_value)
350
+{
351
+ uint32_t lock_mask;
352
+ uint32_t value;
353
+
354
+ /*
355
+ * FCFGLK holds sticky bits 16..23, indicating which bits in FPRGLK (8..15)
356
+ * and FRDLK (0..7) that are read-only.
357
+ */
358
+ lock_mask = (cur_value & FCFG_FCFGLK_MASK) >> 8;
359
+ lock_mask |= lock_mask >> 8;
360
+ /* FDIS and FCFGLK bits are sticky (write 1 to set; can't clear). */
361
+ value = cur_value & (FCFG_FDIS | FCFG_FCFGLK_MASK);
362
+ /* Preserve read-only bits in FPRGLK and FRDLK */
363
+ value |= cur_value & lock_mask;
364
+ /* Set all bits that aren't read-only. */
365
+ value |= new_value & ~lock_mask;
366
+
367
+ return value;
368
+}
369
+
370
+/* Common register write handler for both OTP classes. */
371
+static void npcm7xx_otp_write(NPCM7xxOTPState *s, NPCM7xxOTPRegister reg,
372
+ uint32_t value)
373
+{
374
+ switch (reg) {
375
+ case NPCM7XX_OTP_FST:
376
+ /* RDST is cleared by writing 1 to it. */
377
+ if (value & FST_RDST) {
378
+ s->regs[NPCM7XX_OTP_FST] &= ~FST_RDST;
379
+ }
380
+ /* Preserve read-only and write-one-to-clear bits */
381
+ value &= ~FST_RO_MASK;
382
+ value |= s->regs[NPCM7XX_OTP_FST] & FST_RO_MASK;
383
+ break;
384
+
385
+ case NPCM7XX_OTP_FADDR:
386
+ break;
387
+
388
+ case NPCM7XX_OTP_FDATA:
389
+ /*
390
+ * This register is cleared by writing a magic value to it; no other
391
+ * values can be written.
392
+ */
393
+ if (value == FDATA_CLEAR) {
394
+ value = 0;
395
+ } else {
396
+ value = s->regs[NPCM7XX_OTP_FDATA];
397
+ }
398
+ break;
399
+
400
+ case NPCM7XX_OTP_FCFG:
401
+ value = npcm7xx_otp_compute_fcfg(s->regs[NPCM7XX_OTP_FCFG], value);
402
+ break;
403
+
404
+ case NPCM7XX_OTP_FCTL:
405
+ switch (value) {
406
+ case FCTL_READ_CMD:
407
+ npcm7xx_otp_read_array(s);
408
+ break;
409
+
410
+ case FCTL_PROG_CMD1:
411
+ /*
412
+ * Programming requires writing two separate magic values to this
413
+ * register; this is the first one. Just store it so it can be
414
+ * verified later when the second magic value is received.
415
+ */
416
+ break;
417
+
418
+ case FCTL_PROG_CMD2:
419
+ /*
420
+ * Only initiate programming if we received the first half of the
421
+ * command immediately before this one.
422
+ */
423
+ if (s->regs[NPCM7XX_OTP_FCTL] == FCTL_PROG_CMD1) {
424
+ npcm7xx_otp_program_array(s);
425
+ }
426
+ break;
427
+
428
+ default:
429
+ qemu_log_mask(LOG_GUEST_ERROR,
430
+ "%s: unrecognized FCNTL value 0x%" PRIx32 "\n",
431
+ DEVICE(s)->canonical_path, value);
432
+ break;
433
+ }
434
+ if (value != FCTL_PROG_CMD1) {
435
+ value = 0;
436
+ }
437
+ break;
438
+
439
+ default:
440
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: write to invalid offset 0x%zx\n",
441
+ DEVICE(s)->canonical_path, reg * sizeof(uint32_t));
442
+ return;
443
+ }
444
+
445
+ s->regs[reg] = value;
446
+}
447
+
448
+/* Register read handler specific to the fuse array OTP module. */
449
+static uint64_t npcm7xx_fuse_array_read(void *opaque, hwaddr addr,
450
+ unsigned int size)
451
+{
452
+ NPCM7xxOTPRegister reg = addr / sizeof(uint32_t);
453
+ NPCM7xxOTPState *s = opaque;
454
+ uint32_t value;
455
+
456
+ /*
457
+ * Only the Fuse Strap register needs special handling; all other registers
458
+ * work the same way for both kinds of OTP modules.
459
+ */
460
+ if (reg != NPCM7XX_OTP_FUSTRAP) {
461
+ value = npcm7xx_otp_read(s, reg);
462
+ } else {
463
+ /* FUSTRAP is stored as three copies in the OTP array. */
464
+ uint32_t fustrap[3];
465
+
466
+ memcpy(fustrap, &s->array[0], sizeof(fustrap));
467
+
468
+ /* Determine value by a majority vote on each bit. */
469
+ value = (fustrap[0] & fustrap[1]) | (fustrap[0] & fustrap[2]) |
470
+ (fustrap[1] & fustrap[2]);
471
+ }
472
+
473
+ return value;
474
+}
475
+
476
+/* Register write handler specific to the fuse array OTP module. */
477
+static void npcm7xx_fuse_array_write(void *opaque, hwaddr addr, uint64_t v,
478
+ unsigned int size)
479
+{
480
+ NPCM7xxOTPRegister reg = addr / sizeof(uint32_t);
481
+ NPCM7xxOTPState *s = opaque;
482
+
483
+ /*
484
+ * The Fuse Strap register is read-only. Other registers are handled by
485
+ * common code.
486
+ */
487
+ if (reg != NPCM7XX_OTP_FUSTRAP) {
488
+ npcm7xx_otp_write(s, reg, v);
489
+ }
490
+}
491
+
492
+static const MemoryRegionOps npcm7xx_fuse_array_ops = {
493
+ .read = npcm7xx_fuse_array_read,
494
+ .write = npcm7xx_fuse_array_write,
495
+ .endianness = DEVICE_LITTLE_ENDIAN,
496
+ .valid = {
497
+ .min_access_size = 4,
498
+ .max_access_size = 4,
499
+ .unaligned = false,
500
+ },
501
+};
502
+
503
+/* Register read handler specific to the key storage OTP module. */
504
+static uint64_t npcm7xx_key_storage_read(void *opaque, hwaddr addr,
505
+ unsigned int size)
506
+{
507
+ NPCM7xxOTPRegister reg = addr / sizeof(uint32_t);
508
+ NPCM7xxOTPState *s = opaque;
509
+
510
+ /*
511
+ * Only the Fuse Key Index register needs special handling; all other
512
+ * registers work the same way for both kinds of OTP modules.
513
+ */
514
+ if (reg != NPCM7XX_OTP_FKEYIND) {
515
+ return npcm7xx_otp_read(s, reg);
516
+ }
517
+
518
+ qemu_log_mask(LOG_UNIMP, "%s: FKEYIND is not implemented\n", __func__);
519
+
520
+ return s->regs[NPCM7XX_OTP_FKEYIND];
521
+}
522
+
523
+/* Register write handler specific to the key storage OTP module. */
524
+static void npcm7xx_key_storage_write(void *opaque, hwaddr addr, uint64_t v,
525
+ unsigned int size)
526
+{
527
+ NPCM7xxOTPRegister reg = addr / sizeof(uint32_t);
528
+ NPCM7xxOTPState *s = opaque;
529
+
530
+ /*
531
+ * Only the Fuse Key Index register needs special handling; all other
532
+ * registers work the same way for both kinds of OTP modules.
533
+ */
534
+ if (reg != NPCM7XX_OTP_FKEYIND) {
535
+ npcm7xx_otp_write(s, reg, v);
536
+ return;
537
+ }
538
+
539
+ qemu_log_mask(LOG_UNIMP, "%s: FKEYIND is not implemented\n", __func__);
540
+
541
+ s->regs[NPCM7XX_OTP_FKEYIND] = v;
542
+}
543
+
544
+static const MemoryRegionOps npcm7xx_key_storage_ops = {
545
+ .read = npcm7xx_key_storage_read,
546
+ .write = npcm7xx_key_storage_write,
547
+ .endianness = DEVICE_LITTLE_ENDIAN,
548
+ .valid = {
549
+ .min_access_size = 4,
550
+ .max_access_size = 4,
551
+ .unaligned = false,
552
+ },
553
+};
554
+
555
+static void npcm7xx_otp_enter_reset(Object *obj, ResetType type)
556
+{
557
+ NPCM7xxOTPState *s = NPCM7XX_OTP(obj);
558
+
559
+ memset(s->regs, 0, sizeof(s->regs));
560
+
561
+ s->regs[NPCM7XX_OTP_FST] = 0x00000001;
562
+ s->regs[NPCM7XX_OTP_FCFG] = 0x20000000;
563
+}
564
+
565
+static void npcm7xx_otp_realize(DeviceState *dev, Error **errp)
566
+{
567
+ NPCM7xxOTPClass *oc = NPCM7XX_OTP_GET_CLASS(dev);
568
+ NPCM7xxOTPState *s = NPCM7XX_OTP(dev);
569
+ SysBusDevice *sbd = &s->parent;
570
+
571
+ memset(s->array, 0, sizeof(s->array));
572
+
573
+ memory_region_init_io(&s->mmio, OBJECT(s), oc->mmio_ops, s, "regs",
574
+ NPCM7XX_OTP_REGS_SIZE);
575
+ sysbus_init_mmio(sbd, &s->mmio);
576
+}
577
+
578
+static const VMStateDescription vmstate_npcm7xx_otp = {
579
+ .name = "npcm7xx-otp",
580
+ .version_id = 0,
581
+ .minimum_version_id = 0,
582
+ .fields = (VMStateField[]) {
583
+ VMSTATE_UINT32_ARRAY(regs, NPCM7xxOTPState, NPCM7XX_OTP_NR_REGS),
584
+ VMSTATE_UINT8_ARRAY(array, NPCM7xxOTPState, NPCM7XX_OTP_ARRAY_BYTES),
585
+ VMSTATE_END_OF_LIST(),
586
+ },
587
+};
588
+
589
+static void npcm7xx_otp_class_init(ObjectClass *klass, void *data)
590
+{
591
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
592
+ DeviceClass *dc = DEVICE_CLASS(klass);
593
+
594
+ QEMU_BUILD_BUG_ON(NPCM7XX_OTP_REGS_END > NPCM7XX_OTP_NR_REGS);
595
+
596
+ dc->realize = npcm7xx_otp_realize;
597
+ dc->vmsd = &vmstate_npcm7xx_otp;
598
+ rc->phases.enter = npcm7xx_otp_enter_reset;
599
+}
600
+
601
+static void npcm7xx_key_storage_class_init(ObjectClass *klass, void *data)
602
+{
603
+ NPCM7xxOTPClass *oc = NPCM7XX_OTP_CLASS(klass);
604
+
605
+ oc->mmio_ops = &npcm7xx_key_storage_ops;
606
+}
607
+
608
+static void npcm7xx_fuse_array_class_init(ObjectClass *klass, void *data)
609
+{
610
+ NPCM7xxOTPClass *oc = NPCM7XX_OTP_CLASS(klass);
611
+
612
+ oc->mmio_ops = &npcm7xx_fuse_array_ops;
613
+}
614
+
615
+static const TypeInfo npcm7xx_otp_types[] = {
616
+ {
617
+ .name = TYPE_NPCM7XX_OTP,
618
+ .parent = TYPE_SYS_BUS_DEVICE,
619
+ .instance_size = sizeof(NPCM7xxOTPState),
620
+ .class_size = sizeof(NPCM7xxOTPClass),
621
+ .class_init = npcm7xx_otp_class_init,
622
+ .abstract = true,
623
+ },
624
+ {
625
+ .name = TYPE_NPCM7XX_KEY_STORAGE,
626
+ .parent = TYPE_NPCM7XX_OTP,
627
+ .class_init = npcm7xx_key_storage_class_init,
628
+ },
629
+ {
630
+ .name = TYPE_NPCM7XX_FUSE_ARRAY,
631
+ .parent = TYPE_NPCM7XX_OTP,
632
+ .class_init = npcm7xx_fuse_array_class_init,
633
+ },
634
+};
635
+DEFINE_TYPES(npcm7xx_otp_types);
636
diff --git a/hw/nvram/meson.build b/hw/nvram/meson.build
637
index XXXXXXX..XXXXXXX 100644
638
--- a/hw/nvram/meson.build
639
+++ b/hw/nvram/meson.build
640
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_DS1225Y', if_true: files('ds1225y.c'))
641
softmmu_ss.add(when: 'CONFIG_NMC93XX_EEPROM', if_true: files('eeprom93xx.c'))
642
softmmu_ss.add(when: 'CONFIG_AT24C', if_true: files('eeprom_at24c.c'))
643
softmmu_ss.add(when: 'CONFIG_MAC_NVRAM', if_true: files('mac_nvram.c'))
644
+softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_otp.c'))
645
softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_nvm.c'))
646
647
specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_nvram.c'))
648
--
98
--
649
2.20.1
99
2.20.1
650
100
651
101
diff view generated by jsdifflib
1
It is the responsibility of board code for an armv7m system to set
1
The AN524 has a PL031 RTC, which we have a model of; provide it
2
system_clock_scale appropriately for the CPU speed of the core.
2
rather than an unimplemented-device stub.
3
If it forgets to do this, then QEMU will hang if the guest tries
4
to use the systick timer in the "tick at the CPU clock frequency" mode.
5
6
We forgot that in a couple of our boards (see commits ce4f70e81ed23c93f,
7
e7e5a9595ab1136). Add an assertion in the systick reset method so
8
we don't let any new boards in with the same bug.
9
3
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
5
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
12
Message-id: 20200825160847.18091-1-peter.maydell@linaro.org
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20210215115138.20465-23-peter.maydell@linaro.org
13
---
8
---
14
hw/timer/armv7m_systick.c | 8 ++++++++
9
hw/arm/mps2-tz.c | 22 ++++++++++++++++++++--
15
1 file changed, 8 insertions(+)
10
1 file changed, 20 insertions(+), 2 deletions(-)
16
11
17
diff --git a/hw/timer/armv7m_systick.c b/hw/timer/armv7m_systick.c
12
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
18
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
19
--- a/hw/timer/armv7m_systick.c
14
--- a/hw/arm/mps2-tz.c
20
+++ b/hw/timer/armv7m_systick.c
15
+++ b/hw/arm/mps2-tz.c
21
@@ -XXX,XX +XXX,XX @@ static void systick_reset(DeviceState *dev)
16
@@ -XXX,XX +XXX,XX @@
17
#include "hw/misc/tz-msc.h"
18
#include "hw/arm/armsse.h"
19
#include "hw/dma/pl080.h"
20
+#include "hw/rtc/pl031.h"
21
#include "hw/ssi/pl022.h"
22
#include "hw/i2c/arm_sbcon_i2c.h"
23
#include "hw/net/lan9118.h"
24
@@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineState {
25
UnimplementedDeviceState gpio[4];
26
UnimplementedDeviceState gfx;
27
UnimplementedDeviceState cldc;
28
- UnimplementedDeviceState rtc;
29
UnimplementedDeviceState usb;
30
+ PL031State rtc;
31
PL080State dma[4];
32
TZMSC msc[4];
33
CMSDKAPBUART uart[6];
34
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_i2c(MPS2TZMachineState *mms, void *opaque,
35
return sysbus_mmio_get_region(s, 0);
36
}
37
38
+static MemoryRegion *make_rtc(MPS2TZMachineState *mms, void *opaque,
39
+ const char *name, hwaddr size,
40
+ const int *irqs)
41
+{
42
+ PL031State *pl031 = opaque;
43
+ SysBusDevice *s;
44
+
45
+ object_initialize_child(OBJECT(mms), name, pl031, TYPE_PL031);
46
+ s = SYS_BUS_DEVICE(pl031);
47
+ sysbus_realize(s, &error_fatal);
48
+ /*
49
+ * The board docs don't give an IRQ number for the PL031, so
50
+ * presumably it is not connected.
51
+ */
52
+ return sysbus_mmio_get_region(s, 0);
53
+}
54
+
55
static void create_non_mpc_ram(MPS2TZMachineState *mms)
22
{
56
{
23
SysTickState *s = SYSTICK(dev);
57
/*
24
58
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
25
+ /*
59
26
+ * Forgetting to set system_clock_scale is always a board code
60
{ /* port 9 reserved */ },
27
+ * bug. We can't check this earlier because for some boards
61
{ "clcd", make_unimp_dev, &mms->cldc, 0x4130a000, 0x1000 },
28
+ * (like stellaris) it is not yet configured at the point where
62
- { "rtc", make_unimp_dev, &mms->rtc, 0x4130b000, 0x1000 },
29
+ * the systick device is realized.
63
+ { "rtc", make_rtc, &mms->rtc, 0x4130b000, 0x1000 },
30
+ */
64
},
31
+ assert(system_clock_scale != 0);
65
}, {
32
+
66
.name = "ahb_ppcexp0",
33
s->control = 0;
34
s->reload = 0;
35
s->tick = 0;
36
--
67
--
37
2.20.1
68
2.20.1
38
69
39
70
diff view generated by jsdifflib
1
Implement a model of the MPS2 with the AN386 firmware. This is
1
Add brief documentation of the new mps3-an524 board.
2
essentially identical to the AN385 firmware, but it has a
3
Cortex-M4 rather than a Cortex-M3.
4
2
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
3
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Message-id: 20210215115138.20465-24-peter.maydell@linaro.org
8
Message-id: 20200903202048.15370-2-peter.maydell@linaro.org
9
---
7
---
10
docs/system/arm/mps2.rst | 8 +++++---
8
docs/system/arm/mps2.rst | 24 ++++++++++++++++++------
11
hw/arm/mps2.c | 34 +++++++++++++++++++++++++++++-----
9
1 file changed, 18 insertions(+), 6 deletions(-)
12
2 files changed, 34 insertions(+), 8 deletions(-)
13
10
14
diff --git a/docs/system/arm/mps2.rst b/docs/system/arm/mps2.rst
11
diff --git a/docs/system/arm/mps2.rst b/docs/system/arm/mps2.rst
15
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
16
--- a/docs/system/arm/mps2.rst
13
--- a/docs/system/arm/mps2.rst
17
+++ b/docs/system/arm/mps2.rst
14
+++ b/docs/system/arm/mps2.rst
18
@@ -XXX,XX +XXX,XX @@
15
@@ -XXX,XX +XXX,XX @@
19
-Arm MPS2 boards (``mps2-an385``, ``mps2-an505``, ``mps2-an511``, ``mps2-an521``)
16
-Arm MPS2 boards (``mps2-an385``, ``mps2-an386``, ``mps2-an500``, ``mps2-an505``, ``mps2-an511``, ``mps2-an521``)
20
-================================================================================
17
-================================================================================================================
21
+Arm MPS2 boards (``mps2-an385``, ``mps2-an386``, ``mps2-an505``, ``mps2-an511``, ``mps2-an521``)
18
+Arm MPS2 and MPS3 boards (``mps2-an385``, ``mps2-an386``, ``mps2-an500``, ``mps2-an505``, ``mps2-an511``, ``mps2-an521``, ``mps3-an524``)
22
+================================================================================================
19
+=========================================================================================================================================
23
20
24
These board models all use Arm M-profile CPUs.
21
These board models all use Arm M-profile CPUs.
25
22
23
-The Arm MPS2 and MPS2+ dev boards are FPGA based (the 2+ has a bigger
24
-FPGA but is otherwise the same as the 2). Since the CPU itself
25
-and most of the devices are in the FPGA, the details of the board
26
-as seen by the guest depend significantly on the FPGA image.
27
+The Arm MPS2, MPS2+ and MPS3 dev boards are FPGA based (the 2+ has a
28
+bigger FPGA but is otherwise the same as the 2; the 3 has a bigger
29
+FPGA again, can handle 4GB of RAM and has a USB controller and QSPI flash).
30
+
31
+Since the CPU itself and most of the devices are in the FPGA, the
32
+details of the board as seen by the guest depend significantly on the
33
+FPGA image.
34
35
QEMU models the following FPGA images:
36
26
@@ -XXX,XX +XXX,XX @@ QEMU models the following FPGA images:
37
@@ -XXX,XX +XXX,XX @@ QEMU models the following FPGA images:
27
38
Cortex-M3 'DesignStart' as documented in Arm Application Note AN511
28
``mps2-an385``
39
``mps2-an521``
29
Cortex-M3 as documented in ARM Application Note AN385
40
Dual Cortex-M33 as documented in Arm Application Note AN521
30
+``mps2-an386``
41
+``mps3-an524``
31
+ Cortex-M4 as documented in ARM Application Note AN386
42
+ Dual Cortex-M33 on an MPS3, as documented in Arm Application Note AN524
32
``mps2-an511``
33
Cortex-M3 'DesignStart' as documented in AN511
34
``mps2-an505``
35
@@ -XXX,XX +XXX,XX @@ QEMU models the following FPGA images:
36
43
37
Differences between QEMU and real hardware:
44
Differences between QEMU and real hardware:
38
45
39
-- AN385 remapping of low 16K of memory to either ZBT SSRAM1 or to
46
- AN385/AN386 remapping of low 16K of memory to either ZBT SSRAM1 or to
40
+- AN385/AN386 remapping of low 16K of memory to either ZBT SSRAM1 or to
41
block RAM is unimplemented (QEMU always maps this to ZBT SSRAM1, as
47
block RAM is unimplemented (QEMU always maps this to ZBT SSRAM1, as
42
if zbt_boot_ctrl is always zero)
48
if zbt_boot_ctrl is always zero)
49
+- AN524 remapping of low memory to either BRAM or to QSPI flash is
50
+ unimplemented (QEMU always maps this to BRAM, ignoring the
51
+ SCC CFG_REG0 memory-remap bit)
43
- QEMU provides a LAN9118 ethernet rather than LAN9220; the only guest
52
- QEMU provides a LAN9118 ethernet rather than LAN9220; the only guest
44
diff --git a/hw/arm/mps2.c b/hw/arm/mps2.c
53
visible difference is that the LAN9118 doesn't support checksum
45
index XXXXXXX..XXXXXXX 100644
54
offloading
46
--- a/hw/arm/mps2.c
55
+- QEMU does not model the QSPI flash in MPS3 boards as real QSPI
47
+++ b/hw/arm/mps2.c
56
+ flash, but only as simple ROM, so attempting to rewrite the flash
48
@@ -XXX,XX +XXX,XX @@
57
+ from the guest will fail
49
* as seen by the guest depend significantly on the FPGA image.
58
+- QEMU does not model the USB controller in MPS3 boards
50
* We model the following FPGA images:
51
* "mps2-an385" -- Cortex-M3 as documented in ARM Application Note AN385
52
+ * "mps2-an386" -- Cortex-M4 as documented in ARM Application Note AN386
53
* "mps2-an511" -- Cortex-M3 'DesignStart' as documented in AN511
54
*
55
* Links to the TRM for the board itself and to the various Application
56
@@ -XXX,XX +XXX,XX @@
57
58
typedef enum MPS2FPGAType {
59
FPGA_AN385,
60
+ FPGA_AN386,
61
FPGA_AN511,
62
} MPS2FPGAType;
63
64
@@ -XXX,XX +XXX,XX @@ typedef struct MPS2MachineState MPS2MachineState;
65
66
#define TYPE_MPS2_MACHINE "mps2"
67
#define TYPE_MPS2_AN385_MACHINE MACHINE_TYPE_NAME("mps2-an385")
68
+#define TYPE_MPS2_AN386_MACHINE MACHINE_TYPE_NAME("mps2-an386")
69
#define TYPE_MPS2_AN511_MACHINE MACHINE_TYPE_NAME("mps2-an511")
70
71
DECLARE_OBJ_CHECKERS(MPS2MachineState, MPS2MachineClass,
72
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
73
* tradeoffs. For QEMU they're all just RAM, though. We arbitrarily
74
* call the 16MB our "system memory", as it's the largest lump.
75
*
76
- * Common to both boards:
77
- * 0x21000000..0x21ffffff : PSRAM (16MB)
78
- * AN385 only:
79
+ * AN385/AN386/AN511:
80
+ * 0x21000000 .. 0x21ffffff : PSRAM (16MB)
81
+ * AN385/AN386 only:
82
* 0x00000000 .. 0x003fffff : ZBT SSRAM1
83
* 0x00400000 .. 0x007fffff : mirror of ZBT SSRAM1
84
* 0x20000000 .. 0x203fffff : ZBT SSRAM 2&3
85
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
86
* 0x20000000 .. 0x2001ffff : SRAM
87
* 0x20400000 .. 0x207fffff : ZBT SSRAM 2&3
88
*
89
- * The AN385 has a feature where the lowest 16K can be mapped
90
+ * The AN385/AN386 has a feature where the lowest 16K can be mapped
91
* either to the bottom of the ZBT SSRAM1 or to the block RAM.
92
* This is of no use for QEMU so we don't implement it (as if
93
* zbt_boot_ctrl is always zero).
94
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
95
96
switch (mmc->fpga_type) {
97
case FPGA_AN385:
98
+ case FPGA_AN386:
99
make_ram(&mms->ssram1, "mps.ssram1", 0x0, 0x400000);
100
make_ram_alias(&mms->ssram1_m, "mps.ssram1_m", &mms->ssram1, 0x400000);
101
make_ram(&mms->ssram23, "mps.ssram23", 0x20000000, 0x400000);
102
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
103
armv7m = DEVICE(&mms->armv7m);
104
switch (mmc->fpga_type) {
105
case FPGA_AN385:
106
+ case FPGA_AN386:
107
qdev_prop_set_uint32(armv7m, "num-irq", 32);
108
break;
109
case FPGA_AN511:
110
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
111
112
switch (mmc->fpga_type) {
113
case FPGA_AN385:
114
+ case FPGA_AN386:
115
{
116
/* The overflow IRQs for UARTs 0, 1 and 2 are ORed together.
117
* Overflow for UARTs 4 and 5 doesn't trigger any interrupt.
118
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
119
*/
120
lan9118_init(&nd_table[0], 0x40200000,
121
qdev_get_gpio_in(armv7m,
122
- mmc->fpga_type == FPGA_AN385 ? 13 : 47));
123
+ mmc->fpga_type == FPGA_AN511 ? 47 : 13));
124
125
system_clock_scale = NANOSECONDS_PER_SECOND / SYSCLK_FRQ;
126
127
@@ -XXX,XX +XXX,XX @@ static void mps2_an385_class_init(ObjectClass *oc, void *data)
128
mmc->scc_id = 0x41043850;
129
}
130
131
+static void mps2_an386_class_init(ObjectClass *oc, void *data)
132
+{
133
+ MachineClass *mc = MACHINE_CLASS(oc);
134
+ MPS2MachineClass *mmc = MPS2_MACHINE_CLASS(oc);
135
+
136
+ mc->desc = "ARM MPS2 with AN386 FPGA image for Cortex-M4";
137
+ mmc->fpga_type = FPGA_AN386;
138
+ mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m4");
139
+ mmc->scc_id = 0x41043860;
140
+}
141
+
142
static void mps2_an511_class_init(ObjectClass *oc, void *data)
143
{
144
MachineClass *mc = MACHINE_CLASS(oc);
145
@@ -XXX,XX +XXX,XX @@ static const TypeInfo mps2_an385_info = {
146
.class_init = mps2_an385_class_init,
147
};
148
149
+static const TypeInfo mps2_an386_info = {
150
+ .name = TYPE_MPS2_AN386_MACHINE,
151
+ .parent = TYPE_MPS2_MACHINE,
152
+ .class_init = mps2_an386_class_init,
153
+};
154
+
155
static const TypeInfo mps2_an511_info = {
156
.name = TYPE_MPS2_AN511_MACHINE,
157
.parent = TYPE_MPS2_MACHINE,
158
@@ -XXX,XX +XXX,XX @@ static void mps2_machine_init(void)
159
{
160
type_register_static(&mps2_info);
161
type_register_static(&mps2_an385_info);
162
+ type_register_static(&mps2_an386_info);
163
type_register_static(&mps2_an511_info);
164
}
165
166
--
59
--
167
2.20.1
60
2.20.1
168
61
169
62
diff view generated by jsdifflib
1
Deprecate our Unicore32 target support:
1
Update old infocenter.arm.com URLs to the equivalent developer.arm.com
2
* the Linux kernel dropped support for unicore32 in commit
2
ones (the old URLs should redirect, but we might as well avoid the
3
05119217a9bd199c for its 5.9 release (with rationale in the
3
redirection notice, and the new URLs are pleasantly shorter).
4
cover letter: https://lkml.org/lkml/2020/8/3/232 )
4
5
* there is apparently no upstream toolchain that can create unicore32
5
This commit covers the links to the MPS2 board TRM, the various
6
binaries
6
Application Notes, the IoTKit and SSE-200 documents.
7
* the maintainer doesn't seem to have made any contributions to
8
QEMU since the port first landed in 2012
9
* nobody else seems to have made changes to the unicore code except
10
for generic cleanups either
11
7
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
14
Message-id: 20200825172719.19422-1-peter.maydell@linaro.org
10
Message-id: 20210215115138.20465-25-peter.maydell@linaro.org
15
---
11
---
16
docs/system/deprecated.rst | 8 ++++++++
12
include/hw/arm/armsse.h | 4 ++--
17
1 file changed, 8 insertions(+)
13
include/hw/misc/armsse-cpuid.h | 2 +-
18
14
include/hw/misc/armsse-mhu.h | 2 +-
19
diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
15
include/hw/misc/iotkit-secctl.h | 2 +-
20
index XXXXXXX..XXXXXXX 100644
16
include/hw/misc/iotkit-sysctl.h | 2 +-
21
--- a/docs/system/deprecated.rst
17
include/hw/misc/iotkit-sysinfo.h | 2 +-
22
+++ b/docs/system/deprecated.rst
18
include/hw/misc/mps2-fpgaio.h | 2 +-
23
@@ -XXX,XX +XXX,XX @@ The above, converted to the current supported format::
19
hw/arm/mps2-tz.c | 11 +++++------
24
linux-user mode CPUs
20
hw/misc/armsse-cpuid.c | 2 +-
25
--------------------
21
hw/misc/armsse-mhu.c | 2 +-
26
22
hw/misc/iotkit-sysctl.c | 2 +-
27
+``unicore32`` CPUs (since 5.2.0)
23
hw/misc/iotkit-sysinfo.c | 2 +-
28
+''''''''''''''''''''''''''''''''
24
hw/misc/mps2-fpgaio.c | 2 +-
29
+
25
hw/misc/mps2-scc.c | 2 +-
30
+The ``unicore32`` guest CPU support is deprecated and will be removed in
26
14 files changed, 19 insertions(+), 20 deletions(-)
31
+a future version of QEMU. Support for this CPU was removed from the
27
32
+upstream Linux kernel, and there is no available upstream toolchain
28
diff --git a/include/hw/arm/armsse.h b/include/hw/arm/armsse.h
33
+to build binaries for it.
29
index XXXXXXX..XXXXXXX 100644
34
+
30
--- a/include/hw/arm/armsse.h
35
``tilegx`` CPUs (since 5.1.0)
31
+++ b/include/hw/arm/armsse.h
36
'''''''''''''''''''''''''''''
32
@@ -XXX,XX +XXX,XX @@
33
* hardware, which include the IoT Kit and the SSE-050, SSE-100 and
34
* SSE-200. Currently we model:
35
* - the Arm IoT Kit which is documented in
36
- * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
37
+ * https://developer.arm.com/documentation/ecm0601256/latest
38
* - the SSE-200 which is documented in
39
- * http://infocenter.arm.com/help/topic/com.arm.doc.101104_0100_00_en/corelink_sse200_subsystem_for_embedded_technical_reference_manual_101104_0100_00_en.pdf
40
+ * https://developer.arm.com/documentation/101104/latest/
41
*
42
* The IoTKit contains:
43
* a Cortex-M33
44
diff --git a/include/hw/misc/armsse-cpuid.h b/include/hw/misc/armsse-cpuid.h
45
index XXXXXXX..XXXXXXX 100644
46
--- a/include/hw/misc/armsse-cpuid.h
47
+++ b/include/hw/misc/armsse-cpuid.h
48
@@ -XXX,XX +XXX,XX @@
49
/*
50
* This is a model of the "CPU_IDENTITY" register block which is part of the
51
* Arm SSE-200 and documented in
52
- * http://infocenter.arm.com/help/topic/com.arm.doc.101104_0100_00_en/corelink_sse200_subsystem_for_embedded_technical_reference_manual_101104_0100_00_en.pdf
53
+ * https://developer.arm.com/documentation/101104/latest/
54
*
55
* QEMU interface:
56
* + QOM property "CPUID": the value to use for the CPUID register
57
diff --git a/include/hw/misc/armsse-mhu.h b/include/hw/misc/armsse-mhu.h
58
index XXXXXXX..XXXXXXX 100644
59
--- a/include/hw/misc/armsse-mhu.h
60
+++ b/include/hw/misc/armsse-mhu.h
61
@@ -XXX,XX +XXX,XX @@
62
/*
63
* This is a model of the Message Handling Unit (MHU) which is part of the
64
* Arm SSE-200 and documented in
65
- * http://infocenter.arm.com/help/topic/com.arm.doc.101104_0100_00_en/corelink_sse200_subsystem_for_embedded_technical_reference_manual_101104_0100_00_en.pdf
66
+ * https://developer.arm.com/documentation/101104/latest/
67
*
68
* QEMU interface:
69
* + sysbus MMIO region 0: the system information register bank
70
diff --git a/include/hw/misc/iotkit-secctl.h b/include/hw/misc/iotkit-secctl.h
71
index XXXXXXX..XXXXXXX 100644
72
--- a/include/hw/misc/iotkit-secctl.h
73
+++ b/include/hw/misc/iotkit-secctl.h
74
@@ -XXX,XX +XXX,XX @@
75
76
/* This is a model of the security controller which is part of the
77
* Arm IoT Kit and documented in
78
- * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
79
+ * https://developer.arm.com/documentation/ecm0601256/latest
80
*
81
* QEMU interface:
82
* + sysbus MMIO region 0 is the "secure privilege control block" registers
83
diff --git a/include/hw/misc/iotkit-sysctl.h b/include/hw/misc/iotkit-sysctl.h
84
index XXXXXXX..XXXXXXX 100644
85
--- a/include/hw/misc/iotkit-sysctl.h
86
+++ b/include/hw/misc/iotkit-sysctl.h
87
@@ -XXX,XX +XXX,XX @@
88
/*
89
* This is a model of the "system control element" which is part of the
90
* Arm IoTKit and documented in
91
- * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
92
+ * https://developer.arm.com/documentation/ecm0601256/latest
93
* Specifically, it implements the "system information block" and
94
* "system control register" blocks.
95
*
96
diff --git a/include/hw/misc/iotkit-sysinfo.h b/include/hw/misc/iotkit-sysinfo.h
97
index XXXXXXX..XXXXXXX 100644
98
--- a/include/hw/misc/iotkit-sysinfo.h
99
+++ b/include/hw/misc/iotkit-sysinfo.h
100
@@ -XXX,XX +XXX,XX @@
101
/*
102
* This is a model of the "system information block" which is part of the
103
* Arm IoTKit and documented in
104
- * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
105
+ * https://developer.arm.com/documentation/ecm0601256/latest
106
* QEMU interface:
107
* + QOM property "SYS_VERSION": value to use for SYS_VERSION register
108
* + QOM property "SYS_CONFIG": value to use for SYS_CONFIG register
109
diff --git a/include/hw/misc/mps2-fpgaio.h b/include/hw/misc/mps2-fpgaio.h
110
index XXXXXXX..XXXXXXX 100644
111
--- a/include/hw/misc/mps2-fpgaio.h
112
+++ b/include/hw/misc/mps2-fpgaio.h
113
@@ -XXX,XX +XXX,XX @@
114
/* This is a model of the FPGAIO register block in the AN505
115
* FPGA image for the MPS2 dev board; it is documented in the
116
* application note:
117
- * http://infocenter.arm.com/help/topic/com.arm.doc.dai0505b/index.html
118
+ * https://developer.arm.com/documentation/dai0505/latest/
119
*
120
* QEMU interface:
121
* + sysbus MMIO region 0: the register bank
122
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
123
index XXXXXXX..XXXXXXX 100644
124
--- a/hw/arm/mps2-tz.c
125
+++ b/hw/arm/mps2-tz.c
126
@@ -XXX,XX +XXX,XX @@
127
* https://developer.arm.com/products/system-design/development-boards/fpga-prototyping-boards/mps2
128
*
129
* Board TRM:
130
- * http://infocenter.arm.com/help/topic/com.arm.doc.100112_0200_06_en/versatile_express_cortex_m_prototyping_systems_v2m_mps2_and_v2m_mps2plus_technical_reference_100112_0200_06_en.pdf
131
+ * https://developer.arm.com/documentation/100112/latest/
132
* Application Note AN505:
133
- * http://infocenter.arm.com/help/topic/com.arm.doc.dai0505b/index.html
134
+ * https://developer.arm.com/documentation/dai0505/latest/
135
* Application Note AN521:
136
- * http://infocenter.arm.com/help/topic/com.arm.doc.dai0521c/index.html
137
+ * https://developer.arm.com/documentation/dai0521/latest/
138
* Application Note AN524:
139
* https://developer.arm.com/documentation/dai0524/latest/
140
*
141
* The AN505 defers to the Cortex-M33 processor ARMv8M IoT Kit FVP User Guide
142
* (ARM ECM0601256) for the details of some of the device layout:
143
- * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
144
+ * https://developer.arm.com/documentation/ecm0601256/latest
145
* Similarly, the AN521 and AN524 use the SSE-200, and the SSE-200 TRM defines
146
* most of the device layout:
147
- * http://infocenter.arm.com/help/topic/com.arm.doc.101104_0100_00_en/corelink_sse200_subsystem_for_embedded_technical_reference_manual_101104_0100_00_en.pdf
148
- *
149
+ * https://developer.arm.com/documentation/101104/latest/
150
*/
151
152
#include "qemu/osdep.h"
153
diff --git a/hw/misc/armsse-cpuid.c b/hw/misc/armsse-cpuid.c
154
index XXXXXXX..XXXXXXX 100644
155
--- a/hw/misc/armsse-cpuid.c
156
+++ b/hw/misc/armsse-cpuid.c
157
@@ -XXX,XX +XXX,XX @@
158
/*
159
* This is a model of the "CPU_IDENTITY" register block which is part of the
160
* Arm SSE-200 and documented in
161
- * http://infocenter.arm.com/help/topic/com.arm.doc.101104_0100_00_en/corelink_sse200_subsystem_for_embedded_technical_reference_manual_101104_0100_00_en.pdf
162
+ * https://developer.arm.com/documentation/101104/latest/
163
*
164
* It consists of one read-only CPUID register (set by QOM property), plus the
165
* usual ID registers.
166
diff --git a/hw/misc/armsse-mhu.c b/hw/misc/armsse-mhu.c
167
index XXXXXXX..XXXXXXX 100644
168
--- a/hw/misc/armsse-mhu.c
169
+++ b/hw/misc/armsse-mhu.c
170
@@ -XXX,XX +XXX,XX @@
171
/*
172
* This is a model of the Message Handling Unit (MHU) which is part of the
173
* Arm SSE-200 and documented in
174
- * http://infocenter.arm.com/help/topic/com.arm.doc.101104_0100_00_en/corelink_sse200_subsystem_for_embedded_technical_reference_manual_101104_0100_00_en.pdf
175
+ * https://developer.arm.com/documentation/101104/latest/
176
*/
177
178
#include "qemu/osdep.h"
179
diff --git a/hw/misc/iotkit-sysctl.c b/hw/misc/iotkit-sysctl.c
180
index XXXXXXX..XXXXXXX 100644
181
--- a/hw/misc/iotkit-sysctl.c
182
+++ b/hw/misc/iotkit-sysctl.c
183
@@ -XXX,XX +XXX,XX @@
184
/*
185
* This is a model of the "system control element" which is part of the
186
* Arm IoTKit and documented in
187
- * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
188
+ * https://developer.arm.com/documentation/ecm0601256/latest
189
* Specifically, it implements the "system control register" blocks.
190
*/
191
192
diff --git a/hw/misc/iotkit-sysinfo.c b/hw/misc/iotkit-sysinfo.c
193
index XXXXXXX..XXXXXXX 100644
194
--- a/hw/misc/iotkit-sysinfo.c
195
+++ b/hw/misc/iotkit-sysinfo.c
196
@@ -XXX,XX +XXX,XX @@
197
/*
198
* This is a model of the "system information block" which is part of the
199
* Arm IoTKit and documented in
200
- * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
201
+ * https://developer.arm.com/documentation/ecm0601256/latest
202
* It consists of 2 read-only version/config registers, plus the
203
* usual ID registers.
204
*/
205
diff --git a/hw/misc/mps2-fpgaio.c b/hw/misc/mps2-fpgaio.c
206
index XXXXXXX..XXXXXXX 100644
207
--- a/hw/misc/mps2-fpgaio.c
208
+++ b/hw/misc/mps2-fpgaio.c
209
@@ -XXX,XX +XXX,XX @@
210
/* This is a model of the "FPGA system control and I/O" block found
211
* in the AN505 FPGA image for the MPS2 devboard.
212
* It is documented in AN505:
213
- * http://infocenter.arm.com/help/topic/com.arm.doc.dai0505b/index.html
214
+ * https://developer.arm.com/documentation/dai0505/latest/
215
*/
216
217
#include "qemu/osdep.h"
218
diff --git a/hw/misc/mps2-scc.c b/hw/misc/mps2-scc.c
219
index XXXXXXX..XXXXXXX 100644
220
--- a/hw/misc/mps2-scc.c
221
+++ b/hw/misc/mps2-scc.c
222
@@ -XXX,XX +XXX,XX @@
223
* found in the FPGA images of MPS2 development boards.
224
*
225
* Documentation of it can be found in the MPS2 TRM:
226
- * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.100112_0100_03_en/index.html
227
+ * https://developer.arm.com/documentation/100112/latest/
228
* and also in the Application Notes documenting individual FPGA images.
229
*/
37
230
38
--
231
--
39
2.20.1
232
2.20.1
40
233
41
234
diff view generated by jsdifflib