1
Nuvoton new board models, and some more minor stuff. I also put
1
Some arm patches; my to-review queue is by no means empty, but
2
in the deprecation patches for unicore32 and lm32.
2
this is a big enough set of patches to be getting on with...
3
3
4
thanks
5
-- PMM
4
-- PMM
6
5
7
The following changes since commit a68694cd1f3e5448cca814ff39b871f9ebd71ed5:
6
The following changes since commit cb9c6a8e5ad6a1f0ce164d352e3102df46986e22:
8
7
9
Merge remote-tracking branch 'remotes/philmd-gitlab/tags/edk2-next-20200914' into staging (2020-09-14 12:18:58 +0100)
8
.gitlab-ci.d/windows: Work-around timeout and OpenGL problems of the MSYS2 jobs (2023-01-04 18:58:33 +0000)
10
9
11
are available in the Git repository at:
10
are available in the Git repository at:
12
11
13
https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20200914
12
https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20230105
14
13
15
for you to fetch changes up to dd44ae00fc5342ed99acb68ec3508f76a71d523a:
14
for you to fetch changes up to 93c9678de9dc7d2e68f9e8477da072bac30ef132:
16
15
17
MAINTAINERS: Add maintainer entry for Xilinx ZynqMP CAN controller (2020-09-14 14:27:08 +0100)
16
hw/net: Fix read of uninitialized memory in imx_fec. (2023-01-05 15:33:00 +0000)
18
17
19
----------------------------------------------------------------
18
----------------------------------------------------------------
20
target-arm queue:
19
target-arm queue:
21
* hw/misc/a9scu: Do not allow invalid CPU count
20
* Implement AArch32 ARMv8-R support
22
* hw/misc/a9scu: Minor cleanups
21
* Add Cortex-R52 CPU
23
* hw/timer/armv7m_systick: assert that board code set system_clock_scale
22
* fix handling of HLT semihosting in system mode
24
* decodetree: Improve identifier matching
23
* hw/timer/ixm_epit: cleanup and fix bug in compare handling
25
* target/arm: Clean up neon fp insn size field decode
24
* target/arm: Coding style fixes
26
* target/arm: Remove KVM support for 32-bit Arm hosts
25
* target/arm: Clean up includes
27
* hw/arm/mps2: New board models mps2-an386, mps2-an500
26
* nseries: minor code cleanups
28
* Deprecate Unicore32 port
27
* target/arm: align exposed ID registers with Linux
29
* Deprecate lm32 port
28
* hw/arm/smmu-common: remove unnecessary inlines
30
* target/arm: Count PMU events when MDCR.SPME is set
29
* i.MX7D: Handle GPT timers
31
* hw/arm: versal-virt: Correct the tx/rx GEM clocks
30
* i.MX7D: Connect IRQs to GPIO devices
32
* New Nuvoton iBMC board models npcm750-evb, quanta-gsj
31
* i.MX6UL: Add a specific GPT timer instance
33
* xlnx-zynqmp: implement ZynqMP CAN controllers
32
* hw/net: Fix read of uninitialized memory in imx_fec
34
33
35
----------------------------------------------------------------
34
----------------------------------------------------------------
36
Aaron Lindsay (1):
35
Alex Bennée (1):
37
target/arm: Count PMU events when MDCR.SPME is set
36
target/arm: fix handling of HLT semihosting in system mode
38
37
39
Edgar E. Iglesias (1):
38
Axel Heider (8):
40
hw/arm: versal-virt: Correct the tx/rx GEM clocks
39
hw/timer/imx_epit: improve comments
40
hw/timer/imx_epit: cleanup CR defines
41
hw/timer/imx_epit: define SR_OCIF
42
hw/timer/imx_epit: update interrupt state on CR write access
43
hw/timer/imx_epit: hard reset initializes CR with 0
44
hw/timer/imx_epit: factor out register write handlers
45
hw/timer/imx_epit: remove explicit fields cnt and freq
46
hw/timer/imx_epit: fix compare timer handling
41
47
42
Havard Skinnemoen (14):
48
Claudio Fontana (1):
43
hw/misc: Add NPCM7xx System Global Control Registers device model
49
target/arm: cleanup cpu includes
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
50
58
Peter Maydell (11):
51
Fabiano Rosas (5):
59
hw/timer/armv7m_systick: assert that board code set system_clock_scale
52
target/arm: Fix checkpatch comment style warnings in helper.c
60
target/arm: Convert Neon 3-same-fp size field to MO_* in decode
53
target/arm: Fix checkpatch space errors in helper.c
61
target/arm: Convert Neon VCVT fp size field to MO_* in decode
54
target/arm: Fix checkpatch brace errors in helper.c
62
target/arm: Convert VCMLA, VCADD size field to MO_* in decode
55
target/arm: Remove unused includes from m_helper.c
63
target/arm: Remove KVM support for 32-bit Arm hosts
56
target/arm: Remove unused includes from helper.c
64
target/arm: Remove no-longer-reachable 32-bit KVM code
65
hw/arm/mps2: New board model mps2-an386
66
hw/arm/mps2: New board model mps2-an500
67
docs/system/arm/mps2.rst: Make board list consistent
68
Deprecate Unicore32 port
69
Deprecate lm32 port
70
57
71
Philippe Mathieu-Daudé (4):
58
Jean-Christophe Dubois (4):
72
hw/misc/a9scu: Do not allow invalid CPU count
59
i.MX7D: Connect GPT timers to IRQ
73
hw/misc/a9scu: Simplify setting MemoryRegionOps::valid fields
60
i.MX7D: Compute clock frequency for the fixed frequency clocks.
74
hw/misc/a9scu: Simplify setting MemoryRegionOps::impl fields
61
i.MX6UL: Add a specific GPT timer instance for the i.MX6UL
75
hw/misc/a9scu: Report unimplemented accesses with qemu_log_mask(UNIMP)
62
i.MX7D: Connect IRQs to GPIO devices.
76
63
77
Richard Henderson (1):
64
Peter Maydell (1):
78
decodetree: Improve identifier matching
65
target/arm:Set lg_page_size to 0 if either S1 or S2 asks for it
79
66
80
Vikram Garhwal (4):
67
Philippe Mathieu-Daudé (5):
81
hw/net/can: Introduce Xilinx ZynqMP CAN controller
68
hw/input/tsc2xxx: Constify set_transform()'s MouseTransformInfo arg
82
xlnx-zynqmp: Connect Xilinx ZynqMP CAN controllers
69
hw/arm/nseries: Constify various read-only arrays
83
tests/qtest: Introduce tests for Xilinx ZynqMP CAN controller
70
hw/arm/nseries: Silent -Wmissing-field-initializers warning
84
MAINTAINERS: Add maintainer entry for Xilinx ZynqMP CAN controller
71
hw/arm/smmu-common: Reduce smmu_inv_notifiers_mr() scope
72
hw/arm/smmu-common: Avoid using inlined functions with external linkage
85
73
86
docs/system/arm/mps2.rst | 20 +-
74
Stephen Longfield (1):
87
docs/system/arm/nuvoton.rst | 92 +++
75
hw/net: Fix read of uninitialized memory in imx_fec.
88
docs/system/deprecated.rst | 32 +-
89
docs/system/target-arm.rst | 1 +
90
configure | 2 +-
91
default-configs/arm-softmmu.mak | 1 +
92
include/hw/arm/npcm7xx.h | 112 +++
93
include/hw/arm/xlnx-zynqmp.h | 8 +
94
include/hw/mem/npcm7xx_mc.h | 36 +
95
include/hw/misc/npcm7xx_clk.h | 48 ++
96
include/hw/misc/npcm7xx_gcr.h | 43 ++
97
include/hw/net/xlnx-zynqmp-can.h | 78 +++
98
include/hw/nvram/npcm7xx_otp.h | 79 +++
99
include/hw/ssi/npcm7xx_fiu.h | 73 ++
100
include/hw/timer/npcm7xx_timer.h | 78 +++
101
target/arm/kvm-consts.h | 7 -
102
target/arm/kvm_arm.h | 6 -
103
target/arm/neon-dp.decode | 18 +-
104
target/arm/neon-shared.decode | 18 +-
105
tests/decode/succ_ident1.decode | 7 +
106
hw/arm/mps2.c | 97 ++-
107
hw/arm/npcm7xx.c | 532 +++++++++++++++
108
hw/arm/npcm7xx_boards.c | 197 ++++++
109
hw/arm/xlnx-versal-virt.c | 2 +-
110
hw/arm/xlnx-zcu102.c | 20 +
111
hw/arm/xlnx-zynqmp.c | 34 +
112
hw/mem/npcm7xx_mc.c | 84 +++
113
hw/misc/a9scu.c | 59 +-
114
hw/misc/npcm7xx_clk.c | 266 ++++++++
115
hw/misc/npcm7xx_gcr.c | 269 ++++++++
116
hw/net/can/xlnx-zynqmp-can.c | 1165 ++++++++++++++++++++++++++++++++
117
hw/nvram/npcm7xx_otp.c | 440 ++++++++++++
118
hw/ssi/npcm7xx_fiu.c | 572 ++++++++++++++++
119
hw/timer/armv7m_systick.c | 8 +
120
hw/timer/npcm7xx_timer.c | 543 +++++++++++++++
121
target/arm/cpu.c | 101 ++-
122
target/arm/helper.c | 2 +-
123
target/arm/kvm.c | 7 -
124
target/arm/kvm32.c | 595 ----------------
125
tests/qtest/xlnx-can-test.c | 359 ++++++++++
126
.gitmodules | 3 +
127
MAINTAINERS | 18 +
128
hw/arm/Kconfig | 9 +
129
hw/arm/meson.build | 1 +
130
hw/mem/meson.build | 1 +
131
hw/misc/meson.build | 4 +
132
hw/misc/trace-events | 8 +
133
hw/net/can/meson.build | 1 +
134
hw/nvram/meson.build | 1 +
135
hw/ssi/meson.build | 1 +
136
hw/ssi/trace-events | 11 +
137
hw/timer/meson.build | 1 +
138
hw/timer/trace-events | 5 +
139
pc-bios/README | 6 +
140
pc-bios/meson.build | 1 +
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
76
77
Tobias Röhmel (7):
78
target/arm: Don't add all MIDR aliases for cores that implement PMSA
79
target/arm: Make RVBAR available for all ARMv8 CPUs
80
target/arm: Make stage_2_format for cache attributes optional
81
target/arm: Enable TTBCR_EAE for ARMv8-R AArch32
82
target/arm: Add PMSAv8r registers
83
target/arm: Add PMSAv8r functionality
84
target/arm: Add ARM Cortex-R52 CPU
85
86
Zhuojia Shen (1):
87
target/arm: align exposed ID registers with Linux
88
89
include/hw/arm/fsl-imx7.h | 20 +
90
include/hw/arm/smmu-common.h | 3 -
91
include/hw/input/tsc2xxx.h | 4 +-
92
include/hw/timer/imx_epit.h | 8 +-
93
include/hw/timer/imx_gpt.h | 1 +
94
target/arm/cpu.h | 6 +
95
target/arm/internals.h | 4 +
96
hw/arm/fsl-imx6ul.c | 2 +-
97
hw/arm/fsl-imx7.c | 41 +-
98
hw/arm/nseries.c | 28 +-
99
hw/arm/smmu-common.c | 15 +-
100
hw/input/tsc2005.c | 2 +-
101
hw/input/tsc210x.c | 3 +-
102
hw/misc/imx6ul_ccm.c | 6 -
103
hw/misc/imx7_ccm.c | 49 ++-
104
hw/net/imx_fec.c | 8 +-
105
hw/timer/imx_epit.c | 376 +++++++++-------
106
hw/timer/imx_gpt.c | 25 ++
107
target/arm/cpu.c | 35 +-
108
target/arm/cpu64.c | 6 -
109
target/arm/cpu_tcg.c | 42 ++
110
target/arm/debug_helper.c | 3 +
111
target/arm/helper.c | 871 +++++++++++++++++++++++++++++---------
112
target/arm/m_helper.c | 16 -
113
target/arm/machine.c | 28 ++
114
target/arm/ptw.c | 152 +++++--
115
target/arm/tlb_helper.c | 4 +
116
target/arm/translate.c | 2 +-
117
tests/tcg/aarch64/sysregs.c | 24 +-
118
tests/tcg/aarch64/Makefile.target | 7 +-
119
30 files changed, 1330 insertions(+), 461 deletions(-)
120
diff view generated by jsdifflib
1
The VCMLA and VCADD insns have a size field which is 0 for fp16
1
In get_phys_addr_twostage() we set the lg_page_size of the result to
2
and 1 for fp32 (note that this is the reverse of the Neon 3-same
2
the maximum of the stage 1 and stage 2 page sizes. This works for
3
encoding!). Convert it to MO_* values in decode for consistency.
3
the case where we do want to create a TLB entry, because we know the
4
common TLB code only creates entries of the TARGET_PAGE_SIZE and
5
asking for a size larger than that only means that invalidations
6
invalidate the whole larger area. However, if lg_page_size is
7
smaller than TARGET_PAGE_SIZE this effectively means "don't create a
8
TLB entry"; in this case if either S1 or S2 said "this covers less
9
than a page and can't go in a TLB" then the final result also should
10
be marked that way. Set the resulting page size to 0 if either
11
stage asked for a less-than-a-page entry, and expand the comment
12
to explain what's going on.
13
14
This has no effect for VMSA because currently the VMSA lookup always
15
returns results that cover at least TARGET_PAGE_SIZE; however when we
16
add v8R support it will reuse this code path, and for v8R the S1 and
17
S2 results can be smaller than TARGET_PAGE_SIZE.
4
18
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
19
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
20
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20200903133209.5141-4-peter.maydell@linaro.org
21
Message-id: 20221212142708.610090-1-peter.maydell@linaro.org
8
---
22
---
9
target/arm/neon-shared.decode | 18 ++++++++++++------
23
target/arm/ptw.c | 16 +++++++++++++---
10
target/arm/translate-neon.c.inc | 22 ++++++++++++----------
24
1 file changed, 13 insertions(+), 3 deletions(-)
11
2 files changed, 24 insertions(+), 16 deletions(-)
12
25
13
diff --git a/target/arm/neon-shared.decode b/target/arm/neon-shared.decode
26
diff --git a/target/arm/ptw.c b/target/arm/ptw.c
14
index XXXXXXX..XXXXXXX 100644
27
index XXXXXXX..XXXXXXX 100644
15
--- a/target/arm/neon-shared.decode
28
--- a/target/arm/ptw.c
16
+++ b/target/arm/neon-shared.decode
29
+++ b/target/arm/ptw.c
17
@@ -XXX,XX +XXX,XX @@
30
@@ -XXX,XX +XXX,XX @@ static bool get_phys_addr_twostage(CPUARMState *env, S1Translate *ptw,
18
%vd_dp 22:1 12:4
19
%vd_sp 12:4 22:1
20
21
-VCMLA 1111 110 rot:2 . 1 size:1 .... .... 1000 . q:1 . 0 .... \
22
- vm=%vm_dp vn=%vn_dp vd=%vd_dp
23
+# For VCMLA/VCADD insns, convert the single-bit size field
24
+# which is 0 for fp16 and 1 for fp32 into a MO_* constant.
25
+# (Note that this is the reverse of the sense of the 1-bit size
26
+# field in the 3same_fp Neon insns.)
27
+%vcadd_size 20:1 !function=plus1
28
29
-VCADD 1111 110 rot:1 1 . 0 size:1 .... .... 1000 . q:1 . 0 .... \
30
- vm=%vm_dp vn=%vn_dp vd=%vd_dp
31
+VCMLA 1111 110 rot:2 . 1 . .... .... 1000 . q:1 . 0 .... \
32
+ vm=%vm_dp vn=%vn_dp vd=%vd_dp size=%vcadd_size
33
+
34
+VCADD 1111 110 rot:1 1 . 0 . .... .... 1000 . q:1 . 0 .... \
35
+ vm=%vm_dp vn=%vn_dp vd=%vd_dp size=%vcadd_size
36
37
# VUDOT and VSDOT
38
VDOT 1111 110 00 . 10 .... .... 1101 . q:1 . u:1 .... \
39
@@ -XXX,XX +XXX,XX @@ VFML 1111 110 0 s:1 . 10 .... .... 1000 . 1 . 1 .... \
40
vm=%vm_dp vn=%vn_dp vd=%vd_dp q=1
41
42
VCMLA_scalar 1111 1110 0 . rot:2 .... .... 1000 . q:1 index:1 0 vm:4 \
43
- vn=%vn_dp vd=%vd_dp size=0
44
+ vn=%vn_dp vd=%vd_dp size=1
45
VCMLA_scalar 1111 1110 1 . rot:2 .... .... 1000 . q:1 . 0 .... \
46
- vm=%vm_dp vn=%vn_dp vd=%vd_dp size=1 index=0
47
+ vm=%vm_dp vn=%vn_dp vd=%vd_dp size=2 index=0
48
49
VDOT_scalar 1111 1110 0 . 10 .... .... 1101 . q:1 index:1 u:1 rm:4 \
50
vm=%vm_dp vn=%vn_dp vd=%vd_dp
51
diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc
52
index XXXXXXX..XXXXXXX 100644
53
--- a/target/arm/translate-neon.c.inc
54
+++ b/target/arm/translate-neon.c.inc
55
@@ -XXX,XX +XXX,XX @@ static bool trans_VCMLA(DisasContext *s, arg_VCMLA *a)
56
gen_helper_gvec_3_ptr *fn_gvec_ptr;
57
58
if (!dc_isar_feature(aa32_vcma, s)
59
- || (!a->size && !dc_isar_feature(aa32_fp16_arith, s))) {
60
+ || (a->size == MO_16 && !dc_isar_feature(aa32_fp16_arith, s))) {
61
return false;
62
}
31
}
63
32
64
@@ -XXX,XX +XXX,XX @@ static bool trans_VCMLA(DisasContext *s, arg_VCMLA *a)
33
/*
34
- * Use the maximum of the S1 & S2 page size, so that invalidation
35
- * of pages > TARGET_PAGE_SIZE works correctly.
36
+ * If either S1 or S2 returned a result smaller than TARGET_PAGE_SIZE,
37
+ * this means "don't put this in the TLB"; in this case, return a
38
+ * result with lg_page_size == 0 to achieve that. Otherwise,
39
+ * use the maximum of the S1 & S2 page size, so that invalidation
40
+ * of pages > TARGET_PAGE_SIZE works correctly. (This works even though
41
+ * we know the combined result permissions etc only cover the minimum
42
+ * of the S1 and S2 page size, because we know that the common TLB code
43
+ * never actually creates TLB entries bigger than TARGET_PAGE_SIZE,
44
+ * and passing a larger page size value only affects invalidations.)
45
*/
46
- if (result->f.lg_page_size < s1_lgpgsz) {
47
+ if (result->f.lg_page_size < TARGET_PAGE_BITS ||
48
+ s1_lgpgsz < TARGET_PAGE_BITS) {
49
+ result->f.lg_page_size = 0;
50
+ } else if (result->f.lg_page_size < s1_lgpgsz) {
51
result->f.lg_page_size = s1_lgpgsz;
65
}
52
}
66
53
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
--
54
--
121
2.20.1
55
2.25.1
122
123
diff view generated by jsdifflib
1
From: Vikram Garhwal <fnu.vikram@xilinx.com>
1
From: Tobias Röhmel <tobias.roehmel@rwth-aachen.de>
2
2
3
Reviewed-by: Francisco Iglesias <francisco.iglesias@xilinx.com>
3
Cores with PMSA have the MPUIR register which has the
4
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
4
same encoding as the MIDR alias with opc2=4. So we only
5
Signed-off-by: Vikram Garhwal <fnu.vikram@xilinx.com>
5
add that alias if we are not realizing a core that
6
Message-id: 1597278668-339715-5-git-send-email-fnu.vikram@xilinx.com
6
implements PMSA.
7
8
Signed-off-by: Tobias Röhmel <tobias.roehmel@rwth-aachen.de>
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
10
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
11
Message-id: 20221206102504.165775-2-tobias.roehmel@rwth-aachen.de
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
---
13
---
9
MAINTAINERS | 8 ++++++++
14
target/arm/helper.c | 13 +++++++++----
10
1 file changed, 8 insertions(+)
15
1 file changed, 9 insertions(+), 4 deletions(-)
11
16
12
diff --git a/MAINTAINERS b/MAINTAINERS
17
diff --git a/target/arm/helper.c b/target/arm/helper.c
13
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
14
--- a/MAINTAINERS
19
--- a/target/arm/helper.c
15
+++ b/MAINTAINERS
20
+++ b/target/arm/helper.c
16
@@ -XXX,XX +XXX,XX @@ F: hw/net/opencores_eth.c
21
@@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu)
17
22
.access = PL1_R, .type = ARM_CP_NO_RAW, .resetvalue = cpu->midr,
18
Devices
23
.fieldoffset = offsetof(CPUARMState, cp15.c0_cpuid),
19
-------
24
.readfn = midr_read },
20
+Xilinx CAN
25
- /* crn = 0 op1 = 0 crm = 0 op2 = 4,7 : AArch32 aliases of MIDR */
21
+M: Vikram Garhwal <fnu.vikram@xilinx.com>
26
- { .name = "MIDR", .type = ARM_CP_ALIAS | ARM_CP_CONST,
22
+M: Francisco Iglesias <francisco.iglesias@xilinx.com>
27
- .cp = 15, .crn = 0, .crm = 0, .opc1 = 0, .opc2 = 4,
23
+S: Maintained
28
- .access = PL1_R, .resetvalue = cpu->midr },
24
+F: hw/net/can/xlnx-*
29
+ /* crn = 0 op1 = 0 crm = 0 op2 = 7 : AArch32 aliases of MIDR */
25
+F: include/hw/net/xlnx-*
30
{ .name = "MIDR", .type = ARM_CP_ALIAS | ARM_CP_CONST,
26
+F: tests/qtest/xlnx-can-test*
31
.cp = 15, .crn = 0, .crm = 0, .opc1 = 0, .opc2 = 7,
27
+
32
.access = PL1_R, .resetvalue = cpu->midr },
28
EDU
33
@@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu)
29
M: Jiri Slaby <jslaby@suse.cz>
34
.accessfn = access_aa64_tid1,
30
S: Maintained
35
.type = ARM_CP_CONST, .resetvalue = cpu->revidr },
36
};
37
+ ARMCPRegInfo id_v8_midr_alias_cp_reginfo = {
38
+ .name = "MIDR", .type = ARM_CP_ALIAS | ARM_CP_CONST,
39
+ .cp = 15, .crn = 0, .crm = 0, .opc1 = 0, .opc2 = 4,
40
+ .access = PL1_R, .resetvalue = cpu->midr
41
+ };
42
ARMCPRegInfo id_cp_reginfo[] = {
43
/* These are common to v8 and pre-v8 */
44
{ .name = "CTR",
45
@@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu)
46
}
47
if (arm_feature(env, ARM_FEATURE_V8)) {
48
define_arm_cp_regs(cpu, id_v8_midr_cp_reginfo);
49
+ if (!arm_feature(env, ARM_FEATURE_PMSA)) {
50
+ define_one_arm_cp_reg(cpu, &id_v8_midr_alias_cp_reginfo);
51
+ }
52
} else {
53
define_arm_cp_regs(cpu, id_pre_v8_midr_cp_reginfo);
54
}
31
--
55
--
32
2.20.1
56
2.25.1
33
57
34
58
diff view generated by jsdifflib
1
Deprecate our lm32 target support. Michael Walle (former lm32 maintainer)
1
From: Tobias Röhmel <tobias.roehmel@rwth-aachen.de>
2
suggested that we do this in 2019:
3
https://www.mail-archive.com/qemu-devel@nongnu.org/msg605024.html
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
2
7
In commit 4b4d96c776f552e (March 2020) we marked it as 'orphan' in
3
RVBAR shadows RVBAR_ELx where x is the highest exception
8
the MAINTAINERS file, but didn't officially deprecate it. Mark it
4
level if the highest EL is not EL3. This patch also allows
9
deprecated now, with the intention of removing it from QEMU in
5
ARMv8 CPUs to change the reset address with
10
mid-2021 before the 6.1 release.
6
the rvbar property.
11
7
8
Signed-off-by: Tobias Röhmel <tobias.roehmel@rwth-aachen.de>
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
10
Message-id: 20221206102504.165775-3-tobias.roehmel@rwth-aachen.de
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
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>
15
Reviewed-by: Thomas Huth <thuth@redhat.com>
16
Acked-by: Michael Walle <michael@walle.cc>
17
Message-id: 20200827113259.25064-1-peter.maydell@linaro.org
18
---
12
---
19
docs/system/deprecated.rst | 8 ++++++++
13
target/arm/cpu.c | 6 +++++-
20
1 file changed, 8 insertions(+)
14
target/arm/helper.c | 21 ++++++++++++++-------
15
2 files changed, 19 insertions(+), 8 deletions(-)
21
16
22
diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
17
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
23
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
24
--- a/docs/system/deprecated.rst
19
--- a/target/arm/cpu.c
25
+++ b/docs/system/deprecated.rst
20
+++ b/target/arm/cpu.c
26
@@ -XXX,XX +XXX,XX @@ The above, converted to the current supported format::
21
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset_hold(Object *obj)
27
linux-user mode CPUs
22
env->cp15.cpacr_el1 = FIELD_DP64(env->cp15.cpacr_el1,
28
--------------------
23
CPACR, CP11, 3);
29
24
#endif
30
+``lm32`` CPUs (since 5.2.0)
25
+ if (arm_feature(env, ARM_FEATURE_V8)) {
31
+'''''''''''''''''''''''''''
26
+ env->cp15.rvbar = cpu->rvbar_prop;
32
+
27
+ env->regs[15] = cpu->rvbar_prop;
33
+The ``lm32`` guest CPU support is deprecated and will be removed in
28
+ }
34
+a future version of QEMU. The only public user of this architecture
29
}
35
+was the milkymist project, which has been dead for years; there was
30
36
+never an upstream Linux port.
31
#if defined(CONFIG_USER_ONLY)
37
+
32
@@ -XXX,XX +XXX,XX @@ void arm_cpu_post_init(Object *obj)
38
``unicore32`` CPUs (since 5.2.0)
33
qdev_property_add_static(DEVICE(obj), &arm_cpu_reset_hivecs_property);
39
''''''''''''''''''''''''''''''''
34
}
35
36
- if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
37
+ if (arm_feature(&cpu->env, ARM_FEATURE_V8)) {
38
object_property_add_uint64_ptr(obj, "rvbar",
39
&cpu->rvbar_prop,
40
OBJ_PROP_FLAG_READWRITE);
41
diff --git a/target/arm/helper.c b/target/arm/helper.c
42
index XXXXXXX..XXXXXXX 100644
43
--- a/target/arm/helper.c
44
+++ b/target/arm/helper.c
45
@@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu)
46
if (!arm_feature(env, ARM_FEATURE_EL3) &&
47
!arm_feature(env, ARM_FEATURE_EL2)) {
48
ARMCPRegInfo rvbar = {
49
- .name = "RVBAR_EL1", .state = ARM_CP_STATE_AA64,
50
+ .name = "RVBAR_EL1", .state = ARM_CP_STATE_BOTH,
51
.opc0 = 3, .opc1 = 0, .crn = 12, .crm = 0, .opc2 = 1,
52
.access = PL1_R,
53
.fieldoffset = offsetof(CPUARMState, cp15.rvbar),
54
@@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu)
55
}
56
/* RVBAR_EL2 is only implemented if EL2 is the highest EL */
57
if (!arm_feature(env, ARM_FEATURE_EL3)) {
58
- ARMCPRegInfo rvbar = {
59
- .name = "RVBAR_EL2", .state = ARM_CP_STATE_AA64,
60
- .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 0, .opc2 = 1,
61
- .access = PL2_R,
62
- .fieldoffset = offsetof(CPUARMState, cp15.rvbar),
63
+ ARMCPRegInfo rvbar[] = {
64
+ {
65
+ .name = "RVBAR_EL2", .state = ARM_CP_STATE_AA64,
66
+ .opc0 = 3, .opc1 = 4, .crn = 12, .crm = 0, .opc2 = 1,
67
+ .access = PL2_R,
68
+ .fieldoffset = offsetof(CPUARMState, cp15.rvbar),
69
+ },
70
+ { .name = "RVBAR", .type = ARM_CP_ALIAS,
71
+ .cp = 15, .opc1 = 0, .crn = 12, .crm = 0, .opc2 = 1,
72
+ .access = PL2_R,
73
+ .fieldoffset = offsetof(CPUARMState, cp15.rvbar),
74
+ },
75
};
76
- define_one_arm_cp_reg(cpu, &rvbar);
77
+ define_arm_cp_regs(cpu, rvbar);
78
}
79
}
40
80
41
--
81
--
42
2.20.1
82
2.25.1
43
83
44
84
diff view generated by jsdifflib
1
From: Vikram Garhwal <fnu.vikram@xilinx.com>
1
From: Tobias Röhmel <tobias.roehmel@rwth-aachen.de>
2
2
3
The QTests perform five tests on the Xilinx ZynqMP CAN controller:
3
The v8R PMSAv8 has a two-stage MPU translation process, but, unlike
4
Tests the CAN controller in loopback, sleep and snoop mode.
4
VMSAv8, the stage 2 attributes are in the same format as the stage 1
5
Tests filtering of incoming CAN messages.
5
attributes (8-bit MAIR format). Rather than converting the MAIR
6
format to the format used for VMSA stage 2 (bits [5:2] of a VMSA
7
stage 2 descriptor) and then converting back to do the attribute
8
combination, allow combined_attrs_nofwb() to accept s2 attributes
9
that are already in the MAIR format.
6
10
7
Reviewed-by: Francisco Iglesias <francisco.iglesias@xilinx.com>
11
We move the assert() to combined_attrs_fwb(), because that function
8
Signed-off-by: Vikram Garhwal <fnu.vikram@xilinx.com>
12
really does require a VMSA stage 2 attribute format. (We will never
9
Message-id: 1597278668-339715-4-git-send-email-fnu.vikram@xilinx.com
13
get there for v8R, because PMSAv8 does not implement FEAT_S2FWB.)
10
[PMM: updated to meson build system]
14
15
Signed-off-by: Tobias Röhmel <tobias.roehmel@rwth-aachen.de>
16
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
17
Message-id: 20221206102504.165775-4-tobias.roehmel@rwth-aachen.de
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
18
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
19
---
13
tests/qtest/xlnx-can-test.c | 359 ++++++++++++++++++++++++++++++++++++
20
target/arm/ptw.c | 10 ++++++++--
14
tests/qtest/meson.build | 1 +
21
1 file changed, 8 insertions(+), 2 deletions(-)
15
2 files changed, 360 insertions(+)
16
create mode 100644 tests/qtest/xlnx-can-test.c
17
22
18
diff --git a/tests/qtest/xlnx-can-test.c b/tests/qtest/xlnx-can-test.c
23
diff --git a/target/arm/ptw.c b/target/arm/ptw.c
19
new file mode 100644
24
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX
25
--- a/target/arm/ptw.c
21
--- /dev/null
26
+++ b/target/arm/ptw.c
22
+++ b/tests/qtest/xlnx-can-test.c
27
@@ -XXX,XX +XXX,XX @@ static uint8_t combined_attrs_nofwb(uint64_t hcr,
23
@@ -XXX,XX +XXX,XX @@
28
{
24
+/*
29
uint8_t s1lo, s2lo, s1hi, s2hi, s2_mair_attrs, ret_attrs;
25
+ * QTests for the Xilinx ZynqMP CAN controller.
30
26
+ *
31
- s2_mair_attrs = convert_stage2_attrs(hcr, s2.attrs);
27
+ * Copyright (c) 2020 Xilinx Inc.
32
+ if (s2.is_s2_format) {
28
+ *
33
+ s2_mair_attrs = convert_stage2_attrs(hcr, s2.attrs);
29
+ * Written-by: Vikram Garhwal<fnu.vikram@xilinx.com>
34
+ } else {
30
+ *
35
+ s2_mair_attrs = s2.attrs;
31
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
36
+ }
32
+ * of this software and associated documentation files (the "Software"), to deal
37
33
+ * in the Software without restriction, including without limitation the rights
38
s1lo = extract32(s1.attrs, 0, 4);
34
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
39
s2lo = extract32(s2_mair_attrs, 0, 4);
35
+ * copies of the Software, and to permit persons to whom the Software is
40
@@ -XXX,XX +XXX,XX @@ static uint8_t force_cacheattr_nibble_wb(uint8_t attr)
36
+ * furnished to do so, subject to the following conditions:
41
*/
37
+ *
42
static uint8_t combined_attrs_fwb(ARMCacheAttrs s1, ARMCacheAttrs s2)
38
+ * The above copyright notice and this permission notice shall be included in
43
{
39
+ * all copies or substantial portions of the Software.
44
+ assert(s2.is_s2_format && !s1.is_s2_format);
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
+ */
49
+
45
+
50
+#include "qemu/osdep.h"
46
switch (s2.attrs) {
51
+#include "libqos/libqtest.h"
47
case 7:
52
+
48
/* Use stage 1 attributes */
53
+/* Base address. */
49
@@ -XXX,XX +XXX,XX @@ static ARMCacheAttrs combine_cacheattrs(uint64_t hcr,
54
+#define CAN0_BASE_ADDR 0xFF060000
50
ARMCacheAttrs ret;
55
+#define CAN1_BASE_ADDR 0xFF070000
51
bool tagged = false;
56
+
52
57
+/* Register addresses. */
53
- assert(s2.is_s2_format && !s1.is_s2_format);
58
+#define R_SRR_OFFSET 0x00
54
+ assert(!s1.is_s2_format);
59
+#define R_MSR_OFFSET 0x04
55
ret.is_s2_format = false;
60
+#define R_SR_OFFSET 0x18
56
61
+#define R_ISR_OFFSET 0x1C
57
if (s1.attrs == 0xf0) {
62
+#define R_ICR_OFFSET 0x24
63
+#define R_TXID_OFFSET 0x30
64
+#define R_TXDLC_OFFSET 0x34
65
+#define R_TXDATA1_OFFSET 0x38
66
+#define R_TXDATA2_OFFSET 0x3C
67
+#define R_RXID_OFFSET 0x50
68
+#define R_RXDLC_OFFSET 0x54
69
+#define R_RXDATA1_OFFSET 0x58
70
+#define R_RXDATA2_OFFSET 0x5C
71
+#define R_AFR 0x60
72
+#define R_AFMR1 0x64
73
+#define R_AFIR1 0x68
74
+#define R_AFMR2 0x6C
75
+#define R_AFIR2 0x70
76
+#define R_AFMR3 0x74
77
+#define R_AFIR3 0x78
78
+#define R_AFMR4 0x7C
79
+#define R_AFIR4 0x80
80
+
81
+/* CAN modes. */
82
+#define CONFIG_MODE 0x00
83
+#define NORMAL_MODE 0x00
84
+#define LOOPBACK_MODE 0x02
85
+#define SNOOP_MODE 0x04
86
+#define SLEEP_MODE 0x01
87
+#define ENABLE_CAN (1 << 1)
88
+#define STATUS_NORMAL_MODE (1 << 3)
89
+#define STATUS_LOOPBACK_MODE (1 << 1)
90
+#define STATUS_SNOOP_MODE (1 << 12)
91
+#define STATUS_SLEEP_MODE (1 << 2)
92
+#define ISR_TXOK (1 << 1)
93
+#define ISR_RXOK (1 << 4)
94
+
95
+static void match_rx_tx_data(uint32_t *buf_tx, uint32_t *buf_rx,
96
+ uint8_t can_timestamp)
97
+{
98
+ uint16_t size = 0;
99
+ uint8_t len = 4;
100
+
101
+ while (size < len) {
102
+ if (R_RXID_OFFSET + 4 * size == R_RXDLC_OFFSET) {
103
+ g_assert_cmpint(buf_rx[size], ==, buf_tx[size] + can_timestamp);
104
+ } else {
105
+ g_assert_cmpint(buf_rx[size], ==, buf_tx[size]);
106
+ }
107
+
108
+ size++;
109
+ }
110
+}
111
+
112
+static void read_data(QTestState *qts, uint64_t can_base_addr, uint32_t *buf_rx)
113
+{
114
+ uint32_t int_status;
115
+
116
+ /* Read the interrupt on CAN rx. */
117
+ int_status = qtest_readl(qts, can_base_addr + R_ISR_OFFSET) & ISR_RXOK;
118
+
119
+ g_assert_cmpint(int_status, ==, ISR_RXOK);
120
+
121
+ /* Read the RX register data for CAN. */
122
+ buf_rx[0] = qtest_readl(qts, can_base_addr + R_RXID_OFFSET);
123
+ buf_rx[1] = qtest_readl(qts, can_base_addr + R_RXDLC_OFFSET);
124
+ buf_rx[2] = qtest_readl(qts, can_base_addr + R_RXDATA1_OFFSET);
125
+ buf_rx[3] = qtest_readl(qts, can_base_addr + R_RXDATA2_OFFSET);
126
+
127
+ /* Clear the RX interrupt. */
128
+ qtest_writel(qts, CAN1_BASE_ADDR + R_ICR_OFFSET, ISR_RXOK);
129
+}
130
+
131
+static void send_data(QTestState *qts, uint64_t can_base_addr, uint32_t *buf_tx)
132
+{
133
+ uint32_t int_status;
134
+
135
+ /* Write the TX register data for CAN. */
136
+ qtest_writel(qts, can_base_addr + R_TXID_OFFSET, buf_tx[0]);
137
+ qtest_writel(qts, can_base_addr + R_TXDLC_OFFSET, buf_tx[1]);
138
+ qtest_writel(qts, can_base_addr + R_TXDATA1_OFFSET, buf_tx[2]);
139
+ qtest_writel(qts, can_base_addr + R_TXDATA2_OFFSET, buf_tx[3]);
140
+
141
+ /* Read the interrupt on CAN for tx. */
142
+ int_status = qtest_readl(qts, can_base_addr + R_ISR_OFFSET) & ISR_TXOK;
143
+
144
+ g_assert_cmpint(int_status, ==, ISR_TXOK);
145
+
146
+ /* Clear the interrupt for tx. */
147
+ qtest_writel(qts, CAN0_BASE_ADDR + R_ICR_OFFSET, ISR_TXOK);
148
+}
149
+
150
+/*
151
+ * This test will be transferring data from CAN0 and CAN1 through canbus. CAN0
152
+ * initiate the data transfer to can-bus, CAN1 receives the data. Test compares
153
+ * the data sent from CAN0 with received on CAN1.
154
+ */
155
+static void test_can_bus(void)
156
+{
157
+ uint32_t buf_tx[4] = { 0xFF, 0x80000000, 0x12345678, 0x87654321 };
158
+ uint32_t buf_rx[4] = { 0x00, 0x00, 0x00, 0x00 };
159
+ uint32_t status = 0;
160
+ uint8_t can_timestamp = 1;
161
+
162
+ QTestState *qts = qtest_init("-machine xlnx-zcu102"
163
+ " -object can-bus,id=canbus0"
164
+ " -machine xlnx-zcu102.canbus0=canbus0"
165
+ " -machine xlnx-zcu102.canbus1=canbus0"
166
+ );
167
+
168
+ /* Configure the CAN0 and CAN1. */
169
+ qtest_writel(qts, CAN0_BASE_ADDR + R_SRR_OFFSET, ENABLE_CAN);
170
+ qtest_writel(qts, CAN0_BASE_ADDR + R_MSR_OFFSET, NORMAL_MODE);
171
+ qtest_writel(qts, CAN1_BASE_ADDR + R_SRR_OFFSET, ENABLE_CAN);
172
+ qtest_writel(qts, CAN1_BASE_ADDR + R_MSR_OFFSET, NORMAL_MODE);
173
+
174
+ /* Check here if CAN0 and CAN1 are in normal mode. */
175
+ status = qtest_readl(qts, CAN0_BASE_ADDR + R_SR_OFFSET);
176
+ g_assert_cmpint(status, ==, STATUS_NORMAL_MODE);
177
+
178
+ status = qtest_readl(qts, CAN1_BASE_ADDR + R_SR_OFFSET);
179
+ g_assert_cmpint(status, ==, STATUS_NORMAL_MODE);
180
+
181
+ send_data(qts, CAN0_BASE_ADDR, buf_tx);
182
+
183
+ read_data(qts, CAN1_BASE_ADDR, buf_rx);
184
+ match_rx_tx_data(buf_tx, buf_rx, can_timestamp);
185
+
186
+ qtest_quit(qts);
187
+}
188
+
189
+/*
190
+ * This test is performing loopback mode on CAN0 and CAN1. Data sent from TX of
191
+ * each CAN0 and CAN1 are compared with RX register data for respective CAN.
192
+ */
193
+static void test_can_loopback(void)
194
+{
195
+ uint32_t buf_tx[4] = { 0xFF, 0x80000000, 0x12345678, 0x87654321 };
196
+ uint32_t buf_rx[4] = { 0x00, 0x00, 0x00, 0x00 };
197
+ uint32_t status = 0;
198
+
199
+ QTestState *qts = qtest_init("-machine xlnx-zcu102"
200
+ " -object can-bus,id=canbus0"
201
+ " -machine xlnx-zcu102.canbus0=canbus0"
202
+ " -machine xlnx-zcu102.canbus1=canbus0"
203
+ );
204
+
205
+ /* Configure the CAN0 in loopback mode. */
206
+ qtest_writel(qts, CAN0_BASE_ADDR + R_SRR_OFFSET, CONFIG_MODE);
207
+ qtest_writel(qts, CAN0_BASE_ADDR + R_MSR_OFFSET, LOOPBACK_MODE);
208
+ qtest_writel(qts, CAN0_BASE_ADDR + R_SRR_OFFSET, ENABLE_CAN);
209
+
210
+ /* Check here if CAN0 is set in loopback mode. */
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
+
233
+ qtest_quit(qts);
234
+}
235
+
236
+/*
237
+ * Enable filters for CAN1. This will filter incoming messages with ID. In this
238
+ * test message will pass through filter 2.
239
+ */
240
+static void test_can_filter(void)
241
+{
242
+ uint32_t buf_tx[4] = { 0x14, 0x80000000, 0x12345678, 0x87654321 };
243
+ uint32_t buf_rx[4] = { 0x00, 0x00, 0x00, 0x00 };
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
+
371
+int main(int argc, char **argv)
372
+{
373
+ g_test_init(&argc, &argv, NULL);
374
+
375
+ qtest_add_func("/net/can/can_bus", test_can_bus);
376
+ qtest_add_func("/net/can/can_loopback", test_can_loopback);
377
+ qtest_add_func("/net/can/can_filter", test_can_filter);
378
+ qtest_add_func("/net/can/can_test_snoopmode", test_can_snoopmode);
379
+ qtest_add_func("/net/can/can_test_sleepmode", test_can_sleepmode);
380
+
381
+ return g_test_run();
382
+}
383
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
384
index XXXXXXX..XXXXXXX 100644
385
--- a/tests/qtest/meson.build
386
+++ b/tests/qtest/meson.build
387
@@ -XXX,XX +XXX,XX @@ qtests_aarch64 = \
388
(config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? ['tpm-tis-device-swtpm-test'] : []) + \
389
['numa-test',
390
'boot-serial-test',
391
+ 'xlnx-can-test',
392
'migration-test']
393
394
qtests_s390x = \
395
--
58
--
396
2.20.1
59
2.25.1
397
60
398
61
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Tobias Röhmel <tobias.roehmel@rwth-aachen.de>
2
2
3
This adds two acceptance tests for the quanta-gsj machine.
3
ARMv8-R AArch32 CPUs behave as if TTBCR.EAE is always 1 even
4
tough they don't have the TTBCR register.
5
See ARM Architecture Reference Manual Supplement - ARMv8, for the ARMv8-R
6
AArch32 architecture profile Version:A.c section C1.2.
4
7
5
One test downloads a lightly patched openbmc flash image from github and
8
Signed-off-by: Tobias Röhmel <tobias.roehmel@rwth-aachen.de>
6
verifies that it boots all the way to the login prompt.
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
7
10
Message-id: 20221206102504.165775-5-tobias.roehmel@rwth-aachen.de
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>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
18
---
12
---
19
tests/acceptance/boot_linux_console.py | 83 ++++++++++++++++++++++++++
13
target/arm/internals.h | 4 ++++
20
1 file changed, 83 insertions(+)
14
target/arm/debug_helper.c | 3 +++
15
target/arm/tlb_helper.c | 4 ++++
16
3 files changed, 11 insertions(+)
21
17
22
diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
18
diff --git a/target/arm/internals.h b/target/arm/internals.h
23
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
24
--- a/tests/acceptance/boot_linux_console.py
20
--- a/target/arm/internals.h
25
+++ b/tests/acceptance/boot_linux_console.py
21
+++ b/target/arm/internals.h
26
@@ -XXX,XX +XXX,XX @@ class BootLinuxConsole(LinuxKernelTest):
22
@@ -XXX,XX +XXX,XX @@ unsigned int arm_pamax(ARMCPU *cpu);
27
'sda')
23
static inline bool extended_addresses_enabled(CPUARMState *env)
28
# cubieboard's reboot is not functioning; omit reboot test.
24
{
29
25
uint64_t tcr = env->cp15.tcr_el[arm_is_secure(env) ? 3 : 1];
30
+ def test_arm_quanta_gsj(self):
26
+ if (arm_feature(env, ARM_FEATURE_PMSA) &&
31
+ """
27
+ arm_feature(env, ARM_FEATURE_V8)) {
32
+ :avocado: tags=arch:arm
28
+ return true;
33
+ :avocado: tags=machine:quanta-gsj
29
+ }
34
+ """
30
return arm_el_is_aa64(env, 1) ||
35
+ # 25 MiB compressed, 32 MiB uncompressed.
31
(arm_feature(env, ARM_FEATURE_LPAE) && (tcr & TTBCR_EAE));
36
+ image_url = (
32
}
37
+ 'https://github.com/hskinnemoen/openbmc/releases/download/'
33
diff --git a/target/arm/debug_helper.c b/target/arm/debug_helper.c
38
+ '20200711-gsj-qemu-0/obmc-phosphor-image-gsj.static.mtd.gz')
34
index XXXXXXX..XXXXXXX 100644
39
+ image_hash = '14895e634923345cb5c8776037ff7876df96f6b1'
35
--- a/target/arm/debug_helper.c
40
+ image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash)
36
+++ b/target/arm/debug_helper.c
41
+ image_name = 'obmc.mtd'
37
@@ -XXX,XX +XXX,XX @@ static uint32_t arm_debug_exception_fsr(CPUARMState *env)
42
+ image_path = os.path.join(self.workdir, image_name)
38
43
+ archive.gzip_uncompress(image_path_gz, image_path)
39
if (target_el == 2 || arm_el_is_aa64(env, target_el)) {
44
+
40
using_lpae = true;
45
+ self.vm.set_console()
41
+ } else if (arm_feature(env, ARM_FEATURE_PMSA) &&
46
+ drive_args = 'file=' + image_path + ',if=mtd,bus=0,unit=0'
42
+ arm_feature(env, ARM_FEATURE_V8)) {
47
+ self.vm.add_args('-drive', drive_args)
43
+ using_lpae = true;
48
+ self.vm.launch()
44
} else {
49
+
45
if (arm_feature(env, ARM_FEATURE_LPAE) &&
50
+ # Disable drivers and services that stall for a long time during boot,
46
(env->cp15.tcr_el[target_el] & TTBCR_EAE)) {
51
+ # to avoid running past the 90-second timeout. These may be removed
47
diff --git a/target/arm/tlb_helper.c b/target/arm/tlb_helper.c
52
+ # as the corresponding device support is added.
48
index XXXXXXX..XXXXXXX 100644
53
+ kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + (
49
--- a/target/arm/tlb_helper.c
54
+ 'console=${console} '
50
+++ b/target/arm/tlb_helper.c
55
+ 'mem=${mem} '
51
@@ -XXX,XX +XXX,XX @@ bool regime_using_lpae_format(CPUARMState *env, ARMMMUIdx mmu_idx)
56
+ 'initcall_blacklist=npcm_i2c_bus_driver_init '
52
if (el == 2 || arm_el_is_aa64(env, el)) {
57
+ 'systemd.mask=systemd-random-seed.service '
53
return true;
58
+ 'systemd.mask=dropbearkey.service '
54
}
59
+ )
55
+ if (arm_feature(env, ARM_FEATURE_PMSA) &&
60
+
56
+ arm_feature(env, ARM_FEATURE_V8)) {
61
+ self.wait_for_console_pattern('> BootBlock by Nuvoton')
57
+ return true;
62
+ self.wait_for_console_pattern('>Device: Poleg BMC NPCM730')
58
+ }
63
+ self.wait_for_console_pattern('>Skip DDR init.')
59
if (arm_feature(env, ARM_FEATURE_LPAE)
64
+ self.wait_for_console_pattern('U-Boot ')
60
&& (regime_tcr(env, mmu_idx) & TTBCR_EAE)) {
65
+ interrupt_interactive_console_until_pattern(
61
return true;
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
--
62
--
117
2.20.1
63
2.25.1
118
64
119
65
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Tobias Röhmel <tobias.roehmel@rwth-aachen.de>
2
2
3
This supports reading and writing OTP fuses and keys. Only fuse reading
3
Signed-off-by: Tobias Röhmel <tobias.roehmel@rwth-aachen.de>
4
has been tested. Protection is not implemented.
4
Message-id: 20221206102504.165775-6-tobias.roehmel@rwth-aachen.de
5
6
Reviewed-by: Avi Fishman <avi.fishman@nuvoton.com>
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Tested-by: Alexander Bulekov <alxndr@bu.edu>
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>
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
---
6
---
14
include/hw/arm/npcm7xx.h | 3 +
7
target/arm/cpu.h | 6 +
15
include/hw/nvram/npcm7xx_otp.h | 79 ++++++
8
target/arm/cpu.c | 28 +++-
16
hw/arm/npcm7xx.c | 29 +++
9
target/arm/helper.c | 302 +++++++++++++++++++++++++++++++++++++++++++
17
hw/nvram/npcm7xx_otp.c | 440 +++++++++++++++++++++++++++++++++
10
target/arm/machine.c | 28 ++++
18
hw/nvram/meson.build | 1 +
11
4 files changed, 360 insertions(+), 4 deletions(-)
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
12
23
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
13
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
24
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
25
--- a/include/hw/arm/npcm7xx.h
15
--- a/target/arm/cpu.h
26
+++ b/include/hw/arm/npcm7xx.h
16
+++ b/target/arm/cpu.h
27
@@ -XXX,XX +XXX,XX @@
17
@@ -XXX,XX +XXX,XX @@ typedef struct CPUArchState {
28
#include "hw/cpu/a9mpcore.h"
18
};
29
#include "hw/misc/npcm7xx_clk.h"
19
uint64_t sctlr_el[4];
30
#include "hw/misc/npcm7xx_gcr.h"
20
};
31
+#include "hw/nvram/npcm7xx_otp.h"
21
+ uint64_t vsctlr; /* Virtualization System control register. */
32
#include "hw/timer/npcm7xx_timer.h"
22
uint64_t cpacr_el1; /* Architectural feature access control register */
33
#include "target/arm/cpu.h"
23
uint64_t cptr_el[4]; /* ARMv8 feature trap registers */
34
24
uint32_t c1_xscaleauxcr; /* XScale auxiliary control register. */
35
@@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState {
25
@@ -XXX,XX +XXX,XX @@ typedef struct CPUArchState {
36
NPCM7xxGCRState gcr;
26
*/
37
NPCM7xxCLKState clk;
27
uint32_t *rbar[M_REG_NUM_BANKS];
38
NPCM7xxTimerCtrlState tim[3];
28
uint32_t *rlar[M_REG_NUM_BANKS];
39
+ NPCM7xxOTPState key_storage;
29
+ uint32_t *hprbar;
40
+ NPCM7xxOTPState fuse_array;
30
+ uint32_t *hprlar;
41
} NPCM7xxState;
31
uint32_t mair0[M_REG_NUM_BANKS];
42
32
uint32_t mair1[M_REG_NUM_BANKS];
43
#define TYPE_NPCM7XX "npcm7xx"
33
+ uint32_t hprselr;
44
diff --git a/include/hw/nvram/npcm7xx_otp.h b/include/hw/nvram/npcm7xx_otp.h
34
} pmsav8;
45
new file mode 100644
35
46
index XXXXXXX..XXXXXXX
36
/* v8M SAU */
47
--- /dev/null
37
@@ -XXX,XX +XXX,XX @@ struct ArchCPU {
48
+++ b/include/hw/nvram/npcm7xx_otp.h
38
bool has_mpu;
49
@@ -XXX,XX +XXX,XX @@
39
/* PMSAv7 MPU number of supported regions */
50
+/*
40
uint32_t pmsav7_dregion;
51
+ * Nuvoton NPCM7xx OTP (Fuse Array) Interface
41
+ /* PMSAv8 MPU number of supported hyp regions */
52
+ *
42
+ uint32_t pmsav8r_hdregion;
53
+ * Copyright 2020 Google LLC
43
/* v8M SAU number of supported regions */
54
+ *
44
uint32_t sau_sregion;
55
+ * This program is free software; you can redistribute it and/or modify it
45
56
+ * under the terms of the GNU General Public License as published by the
46
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
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
+
68
+#include "exec/memory.h"
69
+#include "hw/sysbus.h"
70
+
71
+/* Each OTP module holds 8192 bits of one-time programmable storage */
72
+#define NPCM7XX_OTP_ARRAY_BITS (8192)
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
47
index XXXXXXX..XXXXXXX 100644
131
--- a/hw/arm/npcm7xx.c
48
--- a/target/arm/cpu.c
132
+++ b/hw/arm/npcm7xx.c
49
+++ b/target/arm/cpu.c
133
@@ -XXX,XX +XXX,XX @@
50
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset_hold(Object *obj)
134
#define NPCM7XX_MMIO_BA (0x80000000)
51
sizeof(*env->pmsav7.dracr) * cpu->pmsav7_dregion);
135
#define NPCM7XX_MMIO_SZ (0x7ffd0000)
52
}
136
53
}
137
+/* OTP key storage and fuse strap array */
54
+
138
+#define NPCM7XX_OTP1_BA (0xf0189000)
55
+ if (cpu->pmsav8r_hdregion > 0) {
139
+#define NPCM7XX_OTP2_BA (0xf018a000)
56
+ memset(env->pmsav8.hprbar, 0,
140
+
57
+ sizeof(*env->pmsav8.hprbar) * cpu->pmsav8r_hdregion);
141
/* Core system modules. */
58
+ memset(env->pmsav8.hprlar, 0,
142
#define NPCM7XX_L2C_BA (0xf03fc000)
59
+ sizeof(*env->pmsav8.hprlar) * cpu->pmsav8r_hdregion);
143
#define NPCM7XX_CPUP_BA (0xf03fe000)
60
+ }
144
@@ -XXX,XX +XXX,XX @@ void npcm7xx_load_kernel(MachineState *machine, NPCM7xxState *soc)
61
+
145
arm_load_kernel(&soc->cpu[0], machine, &npcm7xx_binfo);
62
env->pmsav7.rnr[M_REG_NS] = 0;
63
env->pmsav7.rnr[M_REG_S] = 0;
64
env->pmsav8.mair0[M_REG_NS] = 0;
65
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
66
/* MPU can be configured out of a PMSA CPU either by setting has-mpu
67
* to false or by setting pmsav7-dregion to 0.
68
*/
69
- if (!cpu->has_mpu) {
70
- cpu->pmsav7_dregion = 0;
71
- }
72
- if (cpu->pmsav7_dregion == 0) {
73
+ if (!cpu->has_mpu || cpu->pmsav7_dregion == 0) {
74
cpu->has_mpu = false;
75
+ cpu->pmsav7_dregion = 0;
76
+ cpu->pmsav8r_hdregion = 0;
77
}
78
79
if (arm_feature(env, ARM_FEATURE_PMSA) &&
80
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
81
env->pmsav7.dracr = g_new0(uint32_t, nr);
82
}
83
}
84
+
85
+ if (cpu->pmsav8r_hdregion > 0xff) {
86
+ error_setg(errp, "PMSAv8 MPU EL2 #regions invalid %" PRIu32,
87
+ cpu->pmsav8r_hdregion);
88
+ return;
89
+ }
90
+
91
+ if (cpu->pmsav8r_hdregion) {
92
+ env->pmsav8.hprbar = g_new0(uint32_t,
93
+ cpu->pmsav8r_hdregion);
94
+ env->pmsav8.hprlar = g_new0(uint32_t,
95
+ cpu->pmsav8r_hdregion);
96
+ }
97
}
98
99
if (arm_feature(env, ARM_FEATURE_M_SECURITY)) {
100
diff --git a/target/arm/helper.c b/target/arm/helper.c
101
index XXXXXXX..XXXXXXX 100644
102
--- a/target/arm/helper.c
103
+++ b/target/arm/helper.c
104
@@ -XXX,XX +XXX,XX @@ static void pmsav7_rgnr_write(CPUARMState *env, const ARMCPRegInfo *ri,
105
raw_write(env, ri, value);
146
}
106
}
147
107
148
+static void npcm7xx_init_fuses(NPCM7xxState *s)
108
+static void prbar_write(CPUARMState *env, const ARMCPRegInfo *ri,
149
+{
109
+ uint64_t value)
150
+ NPCM7xxClass *nc = NPCM7XX_GET_CLASS(s);
110
+{
151
+ uint32_t value;
111
+ ARMCPU *cpu = env_archcpu(env);
112
+
113
+ tlb_flush(CPU(cpu)); /* Mappings may have changed - purge! */
114
+ env->pmsav8.rbar[M_REG_NS][env->pmsav7.rnr[M_REG_NS]] = value;
115
+}
116
+
117
+static uint64_t prbar_read(CPUARMState *env, const ARMCPRegInfo *ri)
118
+{
119
+ return env->pmsav8.rbar[M_REG_NS][env->pmsav7.rnr[M_REG_NS]];
120
+}
121
+
122
+static void prlar_write(CPUARMState *env, const ARMCPRegInfo *ri,
123
+ uint64_t value)
124
+{
125
+ ARMCPU *cpu = env_archcpu(env);
126
+
127
+ tlb_flush(CPU(cpu)); /* Mappings may have changed - purge! */
128
+ env->pmsav8.rlar[M_REG_NS][env->pmsav7.rnr[M_REG_NS]] = value;
129
+}
130
+
131
+static uint64_t prlar_read(CPUARMState *env, const ARMCPRegInfo *ri)
132
+{
133
+ return env->pmsav8.rlar[M_REG_NS][env->pmsav7.rnr[M_REG_NS]];
134
+}
135
+
136
+static void prselr_write(CPUARMState *env, const ARMCPRegInfo *ri,
137
+ uint64_t value)
138
+{
139
+ ARMCPU *cpu = env_archcpu(env);
152
+
140
+
153
+ /*
141
+ /*
154
+ * The initial mask of disabled modules indicates the chip derivative (e.g.
142
+ * Ignore writes that would select not implemented region.
155
+ * NPCM750 or NPCM730).
143
+ * This is architecturally UNPREDICTABLE.
156
+ */
144
+ */
157
+ value = tswap32(nc->disabled_modules);
145
+ if (value >= cpu->pmsav7_dregion) {
158
+ npcm7xx_otp_array_write(&s->fuse_array, &value, NPCM7XX_FUSE_DERIVATIVE,
146
+ return;
159
+ sizeof(value));
147
+ }
160
+}
148
+
161
+
149
+ env->pmsav7.rnr[M_REG_NS] = value;
162
static qemu_irq npcm7xx_irq(NPCM7xxState *s, int n)
150
+}
163
{
151
+
164
return qdev_get_gpio_in(DEVICE(&s->a9mpcore), n);
152
+static void hprbar_write(CPUARMState *env, const ARMCPRegInfo *ri,
165
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj)
153
+ uint64_t value)
166
object_property_add_alias(obj, "power-on-straps", OBJECT(&s->gcr),
154
+{
167
"power-on-straps");
155
+ ARMCPU *cpu = env_archcpu(env);
168
object_initialize_child(obj, "clk", &s->clk, TYPE_NPCM7XX_CLK);
156
+
169
+ object_initialize_child(obj, "otp1", &s->key_storage,
157
+ tlb_flush(CPU(cpu)); /* Mappings may have changed - purge! */
170
+ TYPE_NPCM7XX_KEY_STORAGE);
158
+ env->pmsav8.hprbar[env->pmsav8.hprselr] = value;
171
+ object_initialize_child(obj, "otp2", &s->fuse_array,
159
+}
172
+ TYPE_NPCM7XX_FUSE_ARRAY);
160
+
173
161
+static uint64_t hprbar_read(CPUARMState *env, const ARMCPRegInfo *ri)
174
for (i = 0; i < ARRAY_SIZE(s->tim); i++) {
162
+{
175
object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER);
163
+ return env->pmsav8.hprbar[env->pmsav8.hprselr];
176
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
164
+}
177
sysbus_realize(SYS_BUS_DEVICE(&s->clk), &error_abort);
165
+
178
sysbus_mmio_map(SYS_BUS_DEVICE(&s->clk), 0, NPCM7XX_CLK_BA);
166
+static void hprlar_write(CPUARMState *env, const ARMCPRegInfo *ri,
179
167
+ uint64_t value)
180
+ /* OTP key storage and fuse strap array. Cannot fail. */
168
+{
181
+ sysbus_realize(SYS_BUS_DEVICE(&s->key_storage), &error_abort);
169
+ ARMCPU *cpu = env_archcpu(env);
182
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->key_storage), 0, NPCM7XX_OTP1_BA);
170
+
183
+ sysbus_realize(SYS_BUS_DEVICE(&s->fuse_array), &error_abort);
171
+ tlb_flush(CPU(cpu)); /* Mappings may have changed - purge! */
184
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->fuse_array), 0, NPCM7XX_OTP2_BA);
172
+ env->pmsav8.hprlar[env->pmsav8.hprselr] = value;
185
+ npcm7xx_init_fuses(s);
173
+}
186
+
174
+
187
/* Timer Modules (TIM). Cannot fail. */
175
+static uint64_t hprlar_read(CPUARMState *env, const ARMCPRegInfo *ri)
188
QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_tim_addr) != ARRAY_SIZE(s->tim));
176
+{
189
for (i = 0; i < ARRAY_SIZE(s->tim); i++) {
177
+ return env->pmsav8.hprlar[env->pmsav8.hprselr];
190
diff --git a/hw/nvram/npcm7xx_otp.c b/hw/nvram/npcm7xx_otp.c
178
+}
191
new file mode 100644
179
+
192
index XXXXXXX..XXXXXXX
180
+static void hprenr_write(CPUARMState *env, const ARMCPRegInfo *ri,
193
--- /dev/null
181
+ uint64_t value)
194
+++ b/hw/nvram/npcm7xx_otp.c
182
+{
195
@@ -XXX,XX +XXX,XX @@
183
+ uint32_t n;
196
+/*
184
+ uint32_t bit;
197
+ * Nuvoton NPCM7xx OTP (Fuse Array) Interface
185
+ ARMCPU *cpu = env_archcpu(env);
198
+ *
186
+
199
+ * Copyright 2020 Google LLC
187
+ /* Ignore writes to unimplemented regions */
200
+ *
188
+ int rmax = MIN(cpu->pmsav8r_hdregion, 32);
201
+ * This program is free software; you can redistribute it and/or modify it
189
+ value &= MAKE_64BIT_MASK(0, rmax);
202
+ * under the terms of the GNU General Public License as published by the
190
+
203
+ * Free Software Foundation; either version 2 of the License, or
191
+ tlb_flush(CPU(cpu)); /* Mappings may have changed - purge! */
204
+ * (at your option) any later version.
192
+
205
+ *
193
+ /* Register alias is only valid for first 32 indexes */
206
+ * This program is distributed in the hope that it will be useful, but WITHOUT
194
+ for (n = 0; n < rmax; ++n) {
207
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
195
+ bit = extract32(value, n, 1);
208
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
196
+ env->pmsav8.hprlar[n] = deposit32(
209
+ * for more details.
197
+ env->pmsav8.hprlar[n], 0, 1, bit);
210
+ */
198
+ }
211
+
199
+}
212
+#include "qemu/osdep.h"
200
+
213
+
201
+static uint64_t hprenr_read(CPUARMState *env, const ARMCPRegInfo *ri)
214
+#include "hw/nvram/npcm7xx_otp.h"
202
+{
215
+#include "migration/vmstate.h"
203
+ uint32_t n;
216
+#include "qapi/error.h"
204
+ uint32_t result = 0x0;
217
+#include "qemu/bitops.h"
205
+ ARMCPU *cpu = env_archcpu(env);
218
+#include "qemu/log.h"
206
+
219
+#include "qemu/module.h"
207
+ /* Register alias is only valid for first 32 indexes */
220
+#include "qemu/units.h"
208
+ for (n = 0; n < MIN(cpu->pmsav8r_hdregion, 32); ++n) {
221
+
209
+ if (env->pmsav8.hprlar[n] & 0x1) {
222
+/* Each module has 4 KiB of register space. Only a fraction of it is used. */
210
+ result |= (0x1 << n);
223
+#define NPCM7XX_OTP_REGS_SIZE (4 * KiB)
211
+ }
224
+
212
+ }
225
+/* 32-bit register indices. */
213
+ return result;
226
+typedef enum NPCM7xxOTPRegister {
214
+}
227
+ NPCM7XX_OTP_FST,
215
+
228
+ NPCM7XX_OTP_FADDR,
216
+static void hprselr_write(CPUARMState *env, const ARMCPRegInfo *ri,
229
+ NPCM7XX_OTP_FDATA,
217
+ uint64_t value)
230
+ NPCM7XX_OTP_FCFG,
218
+{
231
+ /* Offset 0x10 is FKEYIND in OTP1, FUSTRAP in OTP2 */
219
+ ARMCPU *cpu = env_archcpu(env);
232
+ NPCM7XX_OTP_FKEYIND = 0x0010 / sizeof(uint32_t),
220
+
233
+ NPCM7XX_OTP_FUSTRAP = 0x0010 / sizeof(uint32_t),
221
+ /*
234
+ NPCM7XX_OTP_FCTL,
222
+ * Ignore writes that would select not implemented region.
235
+ NPCM7XX_OTP_REGS_END,
223
+ * This is architecturally UNPREDICTABLE.
236
+} NPCM7xxOTPRegister;
224
+ */
237
+
225
+ if (value >= cpu->pmsav8r_hdregion) {
238
+/* Register field definitions. */
226
+ return;
239
+#define FST_RIEN BIT(2)
227
+ }
240
+#define FST_RDST BIT(1)
228
+
241
+#define FST_RDY BIT(0)
229
+ env->pmsav8.hprselr = value;
242
+#define FST_RO_MASK (FST_RDST | FST_RDY)
230
+}
243
+
231
+
244
+#define FADDR_BYTEADDR(rv) extract32((rv), 0, 10)
232
+static void pmsav8r_regn_write(CPUARMState *env, const ARMCPRegInfo *ri,
245
+#define FADDR_BITPOS(rv) extract32((rv), 10, 3)
233
+ uint64_t value)
246
+
234
+{
247
+#define FDATA_CLEAR 0x00000001
235
+ ARMCPU *cpu = env_archcpu(env);
248
+
236
+ uint8_t index = (extract32(ri->opc0, 0, 1) << 4) |
249
+#define FCFG_FDIS BIT(31)
237
+ (extract32(ri->crm, 0, 3) << 1) | extract32(ri->opc2, 2, 1);
250
+#define FCFG_FCFGLK_MASK 0x00ff0000
238
+
251
+
239
+ tlb_flush(CPU(cpu)); /* Mappings may have changed - purge! */
252
+#define FCTL_PROG_CMD1 0x00000001
240
+
253
+#define FCTL_PROG_CMD2 0xbf79e5d0
241
+ if (ri->opc1 & 4) {
254
+#define FCTL_READ_CMD 0x00000002
242
+ if (index >= cpu->pmsav8r_hdregion) {
255
+
243
+ return;
256
+/**
244
+ }
257
+ * struct NPCM7xxOTPClass - OTP module class.
245
+ if (ri->opc2 & 0x1) {
258
+ * @parent: System bus device class.
246
+ env->pmsav8.hprlar[index] = value;
259
+ * @mmio_ops: MMIO register operations for this type of module.
247
+ } else {
260
+ *
248
+ env->pmsav8.hprbar[index] = value;
261
+ * The two OTP modules (key-storage and fuse-array) have slightly different
249
+ }
262
+ * behavior, so we give them different MMIO register operations.
250
+ } else {
263
+ */
251
+ if (index >= cpu->pmsav7_dregion) {
264
+struct NPCM7xxOTPClass {
252
+ return;
265
+ SysBusDeviceClass parent;
253
+ }
266
+
254
+ if (ri->opc2 & 0x1) {
267
+ const MemoryRegionOps *mmio_ops;
255
+ env->pmsav8.rlar[M_REG_NS][index] = value;
256
+ } else {
257
+ env->pmsav8.rbar[M_REG_NS][index] = value;
258
+ }
259
+ }
260
+}
261
+
262
+static uint64_t pmsav8r_regn_read(CPUARMState *env, const ARMCPRegInfo *ri)
263
+{
264
+ ARMCPU *cpu = env_archcpu(env);
265
+ uint8_t index = (extract32(ri->opc0, 0, 1) << 4) |
266
+ (extract32(ri->crm, 0, 3) << 1) | extract32(ri->opc2, 2, 1);
267
+
268
+ if (ri->opc1 & 4) {
269
+ if (index >= cpu->pmsav8r_hdregion) {
270
+ return 0x0;
271
+ }
272
+ if (ri->opc2 & 0x1) {
273
+ return env->pmsav8.hprlar[index];
274
+ } else {
275
+ return env->pmsav8.hprbar[index];
276
+ }
277
+ } else {
278
+ if (index >= cpu->pmsav7_dregion) {
279
+ return 0x0;
280
+ }
281
+ if (ri->opc2 & 0x1) {
282
+ return env->pmsav8.rlar[M_REG_NS][index];
283
+ } else {
284
+ return env->pmsav8.rbar[M_REG_NS][index];
285
+ }
286
+ }
287
+}
288
+
289
+static const ARMCPRegInfo pmsav8r_cp_reginfo[] = {
290
+ { .name = "PRBAR",
291
+ .cp = 15, .opc1 = 0, .crn = 6, .crm = 3, .opc2 = 0,
292
+ .access = PL1_RW, .type = ARM_CP_NO_RAW,
293
+ .accessfn = access_tvm_trvm,
294
+ .readfn = prbar_read, .writefn = prbar_write },
295
+ { .name = "PRLAR",
296
+ .cp = 15, .opc1 = 0, .crn = 6, .crm = 3, .opc2 = 1,
297
+ .access = PL1_RW, .type = ARM_CP_NO_RAW,
298
+ .accessfn = access_tvm_trvm,
299
+ .readfn = prlar_read, .writefn = prlar_write },
300
+ { .name = "PRSELR", .resetvalue = 0,
301
+ .cp = 15, .opc1 = 0, .crn = 6, .crm = 2, .opc2 = 1,
302
+ .access = PL1_RW, .accessfn = access_tvm_trvm,
303
+ .writefn = prselr_write,
304
+ .fieldoffset = offsetof(CPUARMState, pmsav7.rnr[M_REG_NS]) },
305
+ { .name = "HPRBAR", .resetvalue = 0,
306
+ .cp = 15, .opc1 = 4, .crn = 6, .crm = 3, .opc2 = 0,
307
+ .access = PL2_RW, .type = ARM_CP_NO_RAW,
308
+ .readfn = hprbar_read, .writefn = hprbar_write },
309
+ { .name = "HPRLAR",
310
+ .cp = 15, .opc1 = 4, .crn = 6, .crm = 3, .opc2 = 1,
311
+ .access = PL2_RW, .type = ARM_CP_NO_RAW,
312
+ .readfn = hprlar_read, .writefn = hprlar_write },
313
+ { .name = "HPRSELR", .resetvalue = 0,
314
+ .cp = 15, .opc1 = 4, .crn = 6, .crm = 2, .opc2 = 1,
315
+ .access = PL2_RW,
316
+ .writefn = hprselr_write,
317
+ .fieldoffset = offsetof(CPUARMState, pmsav8.hprselr) },
318
+ { .name = "HPRENR",
319
+ .cp = 15, .opc1 = 4, .crn = 6, .crm = 1, .opc2 = 1,
320
+ .access = PL2_RW, .type = ARM_CP_NO_RAW,
321
+ .readfn = hprenr_read, .writefn = hprenr_write },
268
+};
322
+};
269
+
323
+
270
+#define NPCM7XX_OTP_CLASS(klass) \
324
static const ARMCPRegInfo pmsav7_cp_reginfo[] = {
271
+ OBJECT_CLASS_CHECK(NPCM7xxOTPClass, (klass), TYPE_NPCM7XX_OTP)
325
/* Reset for all these registers is handled in arm_cpu_reset(),
272
+#define NPCM7XX_OTP_GET_CLASS(obj) \
326
* because the PMSAv7 is also used by M-profile CPUs, which do
273
+ OBJECT_GET_CLASS(NPCM7xxOTPClass, (obj), TYPE_NPCM7XX_OTP)
327
@@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu)
274
+
328
.access = PL1_R, .type = ARM_CP_CONST,
275
+static uint8_t ecc_encode_nibble(uint8_t n)
329
.resetvalue = cpu->pmsav7_dregion << 8
276
+{
330
};
277
+ uint8_t result = n;
331
+ /* HMPUIR is specific to PMSA V8 */
278
+
332
+ ARMCPRegInfo id_hmpuir_reginfo = {
279
+ result |= (((n >> 0) & 1) ^ ((n >> 1) & 1)) << 4;
333
+ .name = "HMPUIR",
280
+ result |= (((n >> 2) & 1) ^ ((n >> 3) & 1)) << 5;
334
+ .cp = 15, .opc1 = 4, .crn = 0, .crm = 0, .opc2 = 4,
281
+ result |= (((n >> 0) & 1) ^ ((n >> 2) & 1)) << 6;
335
+ .access = PL2_R, .type = ARM_CP_CONST,
282
+ result |= (((n >> 1) & 1) ^ ((n >> 3) & 1)) << 7;
336
+ .resetvalue = cpu->pmsav8r_hdregion
283
+
337
+ };
284
+ return result;
338
static const ARMCPRegInfo crn0_wi_reginfo = {
285
+}
339
.name = "CRN0_WI", .cp = 15, .crn = 0, .crm = CP_ANY,
286
+
340
.opc1 = CP_ANY, .opc2 = CP_ANY, .access = PL1_W,
287
+void npcm7xx_otp_array_write(NPCM7xxOTPState *s, const void *data,
341
@@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu)
288
+ unsigned int offset, unsigned int len)
342
define_arm_cp_regs(cpu, id_cp_reginfo);
289
+{
343
if (!arm_feature(env, ARM_FEATURE_PMSA)) {
290
+ const uint8_t *src = data;
344
define_one_arm_cp_reg(cpu, &id_tlbtr_reginfo);
291
+ uint8_t *dst = &s->array[offset];
345
+ } else if (arm_feature(env, ARM_FEATURE_PMSA) &&
292
+
346
+ arm_feature(env, ARM_FEATURE_V8)) {
293
+ while (len-- > 0) {
347
+ uint32_t i = 0;
294
+ uint8_t c = *src++;
348
+ char *tmp_string;
295
+
349
+
296
+ *dst++ = ecc_encode_nibble(extract8(c, 0, 4));
350
+ define_one_arm_cp_reg(cpu, &id_mpuir_reginfo);
297
+ *dst++ = ecc_encode_nibble(extract8(c, 4, 4));
351
+ define_one_arm_cp_reg(cpu, &id_hmpuir_reginfo);
298
+ }
352
+ define_arm_cp_regs(cpu, pmsav8r_cp_reginfo);
299
+}
353
+
300
+
354
+ /* Register alias is only valid for first 32 indexes */
301
+/* Common register read handler for both OTP classes. */
355
+ for (i = 0; i < MIN(cpu->pmsav7_dregion, 32); ++i) {
302
+static uint64_t npcm7xx_otp_read(NPCM7xxOTPState *s, NPCM7xxOTPRegister reg)
356
+ uint8_t crm = 0b1000 | extract32(i, 1, 3);
303
+{
357
+ uint8_t opc1 = extract32(i, 4, 1);
304
+ uint32_t value = 0;
358
+ uint8_t opc2 = extract32(i, 0, 1) << 2;
305
+
359
+
306
+ switch (reg) {
360
+ tmp_string = g_strdup_printf("PRBAR%u", i);
307
+ case NPCM7XX_OTP_FST:
361
+ ARMCPRegInfo tmp_prbarn_reginfo = {
308
+ case NPCM7XX_OTP_FADDR:
362
+ .name = tmp_string, .type = ARM_CP_ALIAS | ARM_CP_NO_RAW,
309
+ case NPCM7XX_OTP_FDATA:
363
+ .cp = 15, .opc1 = opc1, .crn = 6, .crm = crm, .opc2 = opc2,
310
+ case NPCM7XX_OTP_FCFG:
364
+ .access = PL1_RW, .resetvalue = 0,
311
+ value = s->regs[reg];
365
+ .accessfn = access_tvm_trvm,
312
+ break;
366
+ .writefn = pmsav8r_regn_write, .readfn = pmsav8r_regn_read
313
+
367
+ };
314
+ case NPCM7XX_OTP_FCTL:
368
+ define_one_arm_cp_reg(cpu, &tmp_prbarn_reginfo);
315
+ qemu_log_mask(LOG_GUEST_ERROR,
369
+ g_free(tmp_string);
316
+ "%s: read from write-only FCTL register\n",
370
+
317
+ DEVICE(s)->canonical_path);
371
+ opc2 = extract32(i, 0, 1) << 2 | 0x1;
318
+ break;
372
+ tmp_string = g_strdup_printf("PRLAR%u", i);
319
+
373
+ ARMCPRegInfo tmp_prlarn_reginfo = {
320
+ default:
374
+ .name = tmp_string, .type = ARM_CP_ALIAS | ARM_CP_NO_RAW,
321
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: read from invalid offset 0x%zx\n",
375
+ .cp = 15, .opc1 = opc1, .crn = 6, .crm = crm, .opc2 = opc2,
322
+ DEVICE(s)->canonical_path, reg * sizeof(uint32_t));
376
+ .access = PL1_RW, .resetvalue = 0,
323
+ break;
377
+ .accessfn = access_tvm_trvm,
324
+ }
378
+ .writefn = pmsav8r_regn_write, .readfn = pmsav8r_regn_read
325
+
379
+ };
326
+ return value;
380
+ define_one_arm_cp_reg(cpu, &tmp_prlarn_reginfo);
327
+}
381
+ g_free(tmp_string);
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
+ }
382
+ }
426
+ break;
383
+
427
+
384
+ /* Register alias is only valid for first 32 indexes */
428
+ default:
385
+ for (i = 0; i < MIN(cpu->pmsav8r_hdregion, 32); ++i) {
429
+ qemu_log_mask(LOG_GUEST_ERROR,
386
+ uint8_t crm = 0b1000 | extract32(i, 1, 3);
430
+ "%s: unrecognized FCNTL value 0x%" PRIx32 "\n",
387
+ uint8_t opc1 = 0b100 | extract32(i, 4, 1);
431
+ DEVICE(s)->canonical_path, value);
388
+ uint8_t opc2 = extract32(i, 0, 1) << 2;
432
+ break;
389
+
433
+ }
390
+ tmp_string = g_strdup_printf("HPRBAR%u", i);
434
+ if (value != FCTL_PROG_CMD1) {
391
+ ARMCPRegInfo tmp_hprbarn_reginfo = {
435
+ value = 0;
392
+ .name = tmp_string,
436
+ }
393
+ .type = ARM_CP_NO_RAW,
437
+ break;
394
+ .cp = 15, .opc1 = opc1, .crn = 6, .crm = crm, .opc2 = opc2,
438
+
395
+ .access = PL2_RW, .resetvalue = 0,
439
+ default:
396
+ .writefn = pmsav8r_regn_write, .readfn = pmsav8r_regn_read
440
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: write to invalid offset 0x%zx\n",
397
+ };
441
+ DEVICE(s)->canonical_path, reg * sizeof(uint32_t));
398
+ define_one_arm_cp_reg(cpu, &tmp_hprbarn_reginfo);
442
+ return;
399
+ g_free(tmp_string);
443
+ }
400
+
444
+
401
+ opc2 = extract32(i, 0, 1) << 2 | 0x1;
445
+ s->regs[reg] = value;
402
+ tmp_string = g_strdup_printf("HPRLAR%u", i);
446
+}
403
+ ARMCPRegInfo tmp_hprlarn_reginfo = {
447
+
404
+ .name = tmp_string,
448
+/* Register read handler specific to the fuse array OTP module. */
405
+ .type = ARM_CP_NO_RAW,
449
+static uint64_t npcm7xx_fuse_array_read(void *opaque, hwaddr addr,
406
+ .cp = 15, .opc1 = opc1, .crn = 6, .crm = crm, .opc2 = opc2,
450
+ unsigned int size)
407
+ .access = PL2_RW, .resetvalue = 0,
451
+{
408
+ .writefn = pmsav8r_regn_write, .readfn = pmsav8r_regn_read
452
+ NPCM7xxOTPRegister reg = addr / sizeof(uint32_t);
409
+ };
453
+ NPCM7xxOTPState *s = opaque;
410
+ define_one_arm_cp_reg(cpu, &tmp_hprlarn_reginfo);
454
+ uint32_t value;
411
+ g_free(tmp_string);
455
+
412
+ }
456
+ /*
413
} else if (arm_feature(env, ARM_FEATURE_V7)) {
457
+ * Only the Fuse Strap register needs special handling; all other registers
414
define_one_arm_cp_reg(cpu, &id_mpuir_reginfo);
458
+ * work the same way for both kinds of OTP modules.
415
}
459
+ */
416
@@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu)
460
+ if (reg != NPCM7XX_OTP_FUSTRAP) {
417
sctlr.type |= ARM_CP_SUPPRESS_TB_END;
461
+ value = npcm7xx_otp_read(s, reg);
418
}
462
+ } else {
419
define_one_arm_cp_reg(cpu, &sctlr);
463
+ /* FUSTRAP is stored as three copies in the OTP array. */
420
+
464
+ uint32_t fustrap[3];
421
+ if (arm_feature(env, ARM_FEATURE_PMSA) &&
465
+
422
+ arm_feature(env, ARM_FEATURE_V8)) {
466
+ memcpy(fustrap, &s->array[0], sizeof(fustrap));
423
+ ARMCPRegInfo vsctlr = {
467
+
424
+ .name = "VSCTLR", .state = ARM_CP_STATE_AA32,
468
+ /* Determine value by a majority vote on each bit. */
425
+ .cp = 15, .opc1 = 4, .crn = 2, .crm = 0, .opc2 = 0,
469
+ value = (fustrap[0] & fustrap[1]) | (fustrap[0] & fustrap[2]) |
426
+ .access = PL2_RW, .resetvalue = 0x0,
470
+ (fustrap[1] & fustrap[2]);
427
+ .fieldoffset = offsetoflow32(CPUARMState, cp15.vsctlr),
471
+ }
428
+ };
472
+
429
+ define_one_arm_cp_reg(cpu, &vsctlr);
473
+ return value;
430
+ }
474
+}
431
}
475
+
432
476
+/* Register write handler specific to the fuse array OTP module. */
433
if (cpu_isar_feature(aa64_lor, cpu)) {
477
+static void npcm7xx_fuse_array_write(void *opaque, hwaddr addr, uint64_t v,
434
diff --git a/target/arm/machine.c b/target/arm/machine.c
478
+ unsigned int size)
435
index XXXXXXX..XXXXXXX 100644
479
+{
436
--- a/target/arm/machine.c
480
+ NPCM7xxOTPRegister reg = addr / sizeof(uint32_t);
437
+++ b/target/arm/machine.c
481
+ NPCM7xxOTPState *s = opaque;
438
@@ -XXX,XX +XXX,XX @@ static bool pmsav8_needed(void *opaque)
482
+
439
arm_feature(env, ARM_FEATURE_V8);
483
+ /*
440
}
484
+ * The Fuse Strap register is read-only. Other registers are handled by
441
485
+ * common code.
442
+static bool pmsav8r_needed(void *opaque)
486
+ */
443
+{
487
+ if (reg != NPCM7XX_OTP_FUSTRAP) {
444
+ ARMCPU *cpu = opaque;
488
+ npcm7xx_otp_write(s, reg, v);
445
+ CPUARMState *env = &cpu->env;
489
+ }
446
+
490
+}
447
+ return arm_feature(env, ARM_FEATURE_PMSA) &&
491
+
448
+ arm_feature(env, ARM_FEATURE_V8) &&
492
+static const MemoryRegionOps npcm7xx_fuse_array_ops = {
449
+ !arm_feature(env, ARM_FEATURE_M);
493
+ .read = npcm7xx_fuse_array_read,
450
+}
494
+ .write = npcm7xx_fuse_array_write,
451
+
495
+ .endianness = DEVICE_LITTLE_ENDIAN,
452
+static const VMStateDescription vmstate_pmsav8r = {
496
+ .valid = {
453
+ .name = "cpu/pmsav8/pmsav8r",
497
+ .min_access_size = 4,
454
+ .version_id = 1,
498
+ .max_access_size = 4,
455
+ .minimum_version_id = 1,
499
+ .unaligned = false,
456
+ .needed = pmsav8r_needed,
457
+ .fields = (VMStateField[]) {
458
+ VMSTATE_VARRAY_UINT32(env.pmsav8.hprbar, ARMCPU,
459
+ pmsav8r_hdregion, 0, vmstate_info_uint32, uint32_t),
460
+ VMSTATE_VARRAY_UINT32(env.pmsav8.hprlar, ARMCPU,
461
+ pmsav8r_hdregion, 0, vmstate_info_uint32, uint32_t),
462
+ VMSTATE_END_OF_LIST()
500
+ },
463
+ },
501
+};
464
+};
502
+
465
+
503
+/* Register read handler specific to the key storage OTP module. */
466
static const VMStateDescription vmstate_pmsav8 = {
504
+static uint64_t npcm7xx_key_storage_read(void *opaque, hwaddr addr,
467
.name = "cpu/pmsav8",
505
+ unsigned int size)
468
.version_id = 1,
506
+{
469
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_pmsav8 = {
507
+ NPCM7xxOTPRegister reg = addr / sizeof(uint32_t);
470
VMSTATE_UINT32(env.pmsav8.mair0[M_REG_NS], ARMCPU),
508
+ NPCM7xxOTPState *s = opaque;
471
VMSTATE_UINT32(env.pmsav8.mair1[M_REG_NS], ARMCPU),
509
+
472
VMSTATE_END_OF_LIST()
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
+ },
473
+ },
553
+};
474
+ .subsections = (const VMStateDescription * []) {
554
+
475
+ &vmstate_pmsav8r,
555
+static void npcm7xx_otp_enter_reset(Object *obj, ResetType type)
476
+ NULL
556
+{
477
}
557
+ NPCM7xxOTPState *s = NPCM7XX_OTP(obj);
478
};
558
+
479
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
--
480
--
649
2.20.1
481
2.25.1
650
482
651
483
diff view generated by jsdifflib
1
From: Vikram Garhwal <fnu.vikram@xilinx.com>
1
From: Tobias Röhmel <tobias.roehmel@rwth-aachen.de>
2
2
3
The Xilinx ZynqMP CAN controller is developed based on SocketCAN, QEMU CAN bus
3
Add PMSAv8r translation.
4
implementation. Bus connection and socketCAN connection for each CAN module
4
5
can be set through command lines.
5
Signed-off-by: Tobias Röhmel <tobias.roehmel@rwth-aachen.de>
6
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
7
Example for using single CAN:
7
Message-id: 20221206102504.165775-7-tobias.roehmel@rwth-aachen.de
8
-object can-bus,id=canbus0 \
9
-machine xlnx-zcu102.canbus0=canbus0 \
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>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
28
---
9
---
29
include/hw/net/xlnx-zynqmp-can.h | 78 ++
10
target/arm/ptw.c | 126 ++++++++++++++++++++++++++++++++++++++---------
30
hw/net/can/xlnx-zynqmp-can.c | 1165 ++++++++++++++++++++++++++++++
11
1 file changed, 104 insertions(+), 22 deletions(-)
31
hw/net/can/meson.build | 1 +
12
32
3 files changed, 1244 insertions(+)
13
diff --git a/target/arm/ptw.c b/target/arm/ptw.c
33
create mode 100644 include/hw/net/xlnx-zynqmp-can.h
14
index XXXXXXX..XXXXXXX 100644
34
create mode 100644 hw/net/can/xlnx-zynqmp-can.c
15
--- a/target/arm/ptw.c
35
16
+++ b/target/arm/ptw.c
36
diff --git a/include/hw/net/xlnx-zynqmp-can.h b/include/hw/net/xlnx-zynqmp-can.h
17
@@ -XXX,XX +XXX,XX @@ static bool pmsav7_use_background_region(ARMCPU *cpu, ARMMMUIdx mmu_idx,
37
new file mode 100644
18
38
index XXXXXXX..XXXXXXX
19
if (arm_feature(env, ARM_FEATURE_M)) {
39
--- /dev/null
20
return env->v7m.mpu_ctrl[is_secure] & R_V7M_MPU_CTRL_PRIVDEFENA_MASK;
40
+++ b/include/hw/net/xlnx-zynqmp-can.h
21
- } else {
41
@@ -XXX,XX +XXX,XX @@
22
- return regime_sctlr(env, mmu_idx) & SCTLR_BR;
42
+/*
23
}
43
+ * QEMU model of the Xilinx ZynqMP CAN controller.
24
+
44
+ *
25
+ if (mmu_idx == ARMMMUIdx_Stage2) {
45
+ * Copyright (c) 2020 Xilinx Inc.
26
+ return false;
46
+ *
27
+ }
47
+ * Written-by: Vikram Garhwal<fnu.vikram@xilinx.com>
28
+
48
+ *
29
+ return regime_sctlr(env, mmu_idx) & SCTLR_BR;
49
+ * Based on QEMU CAN Device emulation implemented by Jin Yang, Deniz Eren and
30
}
50
+ * Pavel Pisa.
31
51
+ *
32
static bool get_phys_addr_pmsav7(CPUARMState *env, uint32_t address,
52
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
33
@@ -XXX,XX +XXX,XX @@ static bool get_phys_addr_pmsav7(CPUARMState *env, uint32_t address,
53
+ * of this software and associated documentation files (the "Software"), to deal
34
return !(result->f.prot & (1 << access_type));
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
56
+ * copies of the Software, and to permit persons to whom the Software is
37
+static uint32_t *regime_rbar(CPUARMState *env, ARMMMUIdx mmu_idx,
57
+ * furnished to do so, subject to the following conditions:
38
+ uint32_t secure)
58
+ *
59
+ * The above copyright notice and this permission notice shall be included in
60
+ * all copies or substantial portions of the Software.
61
+ *
62
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
63
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
64
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
65
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
66
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
67
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
68
+ * THE SOFTWARE.
69
+ */
70
+
71
+#ifndef XLNX_ZYNQMP_CAN_H
72
+#define XLNX_ZYNQMP_CAN_H
73
+
74
+#include "hw/register.h"
75
+#include "net/can_emu.h"
76
+#include "net/can_host.h"
77
+#include "qemu/fifo32.h"
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
+{
39
+{
387
+ uint32_t irq;
40
+ if (regime_el(env, mmu_idx) == 2) {
388
+
41
+ return env->pmsav8.hprbar;
389
+ /* Watermark register interrupts. */
42
+ } else {
390
+ if ((fifo32_num_free(&s->tx_fifo) / CAN_FRAME_SIZE) >
43
+ return env->pmsav8.rbar[secure];
391
+ ARRAY_FIELD_EX32(s->regs, WIR, EW)) {
44
+ }
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
+}
45
+}
423
+
46
+
424
+static void can_ier_post_write(RegisterInfo *reg, uint64_t val64)
47
+static uint32_t *regime_rlar(CPUARMState *env, ARMMMUIdx mmu_idx,
48
+ uint32_t secure)
425
+{
49
+{
426
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
50
+ if (regime_el(env, mmu_idx) == 2) {
427
+
51
+ return env->pmsav8.hprlar;
428
+ can_update_irq(s);
52
+ } else {
53
+ return env->pmsav8.rlar[secure];
54
+ }
429
+}
55
+}
430
+
56
+
431
+static uint64_t can_icr_pre_write(RegisterInfo *reg, uint64_t val64)
57
bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address,
432
+{
58
MMUAccessType access_type, ARMMMUIdx mmu_idx,
433
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
59
bool secure, GetPhysAddrResult *result,
434
+ uint32_t val = val64;
60
@@ -XXX,XX +XXX,XX @@ bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address,
435
+
61
bool hit = false;
436
+ s->regs[R_INTERRUPT_STATUS_REGISTER] &= ~val;
62
uint32_t addr_page_base = address & TARGET_PAGE_MASK;
437
+ can_update_irq(s);
63
uint32_t addr_page_limit = addr_page_base + (TARGET_PAGE_SIZE - 1);
438
+
64
+ int region_counter;
439
+ return 0;
65
+
440
+}
66
+ if (regime_el(env, mmu_idx) == 2) {
441
+
67
+ region_counter = cpu->pmsav8r_hdregion;
442
+static void can_config_reset(XlnxZynqMPCANState *s)
68
+ } else {
443
+{
69
+ region_counter = cpu->pmsav7_dregion;
444
+ /* Reset all the configuration registers. */
70
+ }
445
+ register_reset(&s->reg_info[R_SOFTWARE_RESET_REGISTER]);
71
446
+ register_reset(&s->reg_info[R_MODE_SELECT_REGISTER]);
72
result->f.lg_page_size = TARGET_PAGE_BITS;
447
+ register_reset(
73
result->f.phys_addr = address;
448
+ &s->reg_info[R_ARBITRATION_PHASE_BAUD_RATE_PRESCALER_REGISTER]);
74
@@ -XXX,XX +XXX,XX @@ bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address,
449
+ register_reset(&s->reg_info[R_ARBITRATION_PHASE_BIT_TIMING_REGISTER]);
75
*mregion = -1;
450
+ register_reset(&s->reg_info[R_STATUS_REGISTER]);
76
}
451
+ register_reset(&s->reg_info[R_INTERRUPT_STATUS_REGISTER]);
77
452
+ register_reset(&s->reg_info[R_INTERRUPT_ENABLE_REGISTER]);
78
+ if (mmu_idx == ARMMMUIdx_Stage2) {
453
+ register_reset(&s->reg_info[R_INTERRUPT_CLEAR_REGISTER]);
79
+ fi->stage2 = true;
454
+ register_reset(&s->reg_info[R_WIR]);
80
+ }
455
+}
81
+
456
+
82
/*
457
+static void can_config_mode(XlnxZynqMPCANState *s)
83
* Unlike the ARM ARM pseudocode, we don't need to check whether this
458
+{
84
* was an exception vector read from the vector table (which is always
459
+ register_reset(&s->reg_info[R_ERROR_COUNTER_REGISTER]);
85
@@ -XXX,XX +XXX,XX @@ bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address,
460
+ register_reset(&s->reg_info[R_ERROR_STATUS_REGISTER]);
86
hit = true;
461
+
87
}
462
+ /* Put XlnxZynqMPCAN in configuration mode. */
88
463
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, CONFIG, 1);
89
- for (n = (int)cpu->pmsav7_dregion - 1; n >= 0; n--) {
464
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, WKUP, 0);
90
+ uint32_t bitmask;
465
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, SLP, 0);
91
+ if (arm_feature(env, ARM_FEATURE_M)) {
466
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, BSOFF, 0);
92
+ bitmask = 0x1f;
467
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, ERROR, 0);
93
+ } else {
468
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, RXOFLW, 0);
94
+ bitmask = 0x3f;
469
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, RXOK, 0);
95
+ fi->level = 0;
470
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, TXOK, 0);
96
+ }
471
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, ARBLST, 0);
97
+
472
+
98
+ for (n = region_counter - 1; n >= 0; n--) {
473
+ can_update_irq(s);
99
/* region search */
474
+}
100
/*
475
+
101
- * Note that the base address is bits [31:5] from the register
476
+static void update_status_register_mode_bits(XlnxZynqMPCANState *s)
102
- * with bits [4:0] all zeroes, but the limit address is bits
477
+{
103
- * [31:5] from the register with bits [4:0] all ones.
478
+ bool sleep_status = ARRAY_FIELD_EX32(s->regs, STATUS_REGISTER, SLEEP);
104
+ * Note that the base address is bits [31:x] from the register
479
+ bool sleep_mode = ARRAY_FIELD_EX32(s->regs, MODE_SELECT_REGISTER, SLEEP);
105
+ * with bits [x-1:0] all zeroes, but the limit address is bits
480
+ /* Wake up interrupt bit. */
106
+ * [31:x] from the register with bits [x:0] all ones. Where x is
481
+ bool wakeup_irq_val = sleep_status && (sleep_mode == 0);
107
+ * 5 for Cortex-M and 6 for Cortex-R
482
+ /* Sleep interrupt bit. */
108
*/
483
+ bool sleep_irq_val = sleep_mode && (sleep_status == 0);
109
- uint32_t base = env->pmsav8.rbar[secure][n] & ~0x1f;
484
+
110
- uint32_t limit = env->pmsav8.rlar[secure][n] | 0x1f;
485
+ /* Clear previous core mode status bits. */
111
+ uint32_t base = regime_rbar(env, mmu_idx, secure)[n] & ~bitmask;
486
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, LBACK, 0);
112
+ uint32_t limit = regime_rlar(env, mmu_idx, secure)[n] | bitmask;
487
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, SLEEP, 0);
113
488
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, SNOOP, 0);
114
- if (!(env->pmsav8.rlar[secure][n] & 0x1)) {
489
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, NORMAL, 0);
115
+ if (!(regime_rlar(env, mmu_idx, secure)[n] & 0x1)) {
490
+
116
/* Region disabled */
491
+ /* set current mode bit and generate irqs accordingly. */
117
continue;
492
+ if (ARRAY_FIELD_EX32(s->regs, MODE_SELECT_REGISTER, LBACK)) {
118
}
493
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, LBACK, 1);
119
@@ -XXX,XX +XXX,XX @@ bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address,
494
+ } else if (ARRAY_FIELD_EX32(s->regs, MODE_SELECT_REGISTER, SLEEP)) {
120
* PMSAv7 where highest-numbered-region wins)
495
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, SLEEP, 1);
121
*/
496
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, SLP,
122
fi->type = ARMFault_Permission;
497
+ sleep_irq_val);
123
- fi->level = 1;
498
+ } else if (ARRAY_FIELD_EX32(s->regs, MODE_SELECT_REGISTER, SNOOP)) {
124
+ if (arm_feature(env, ARM_FEATURE_M)) {
499
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, SNOOP, 1);
125
+ fi->level = 1;
500
+ } else {
126
+ }
501
+ /*
127
return true;
502
+ * If all bits are zero then XlnxZynqMPCAN is set in normal mode.
128
}
503
+ */
129
504
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, NORMAL, 1);
130
@@ -XXX,XX +XXX,XX @@ bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address,
505
+ /* Set wakeup interrupt bit. */
131
}
506
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, WKUP,
132
507
+ wakeup_irq_val);
133
if (!hit) {
508
+ }
134
- /* background fault */
509
+
135
- fi->type = ARMFault_Background;
510
+ can_update_irq(s);
136
+ if (arm_feature(env, ARM_FEATURE_M)) {
511
+}
137
+ fi->type = ARMFault_Background;
512
+
138
+ } else {
513
+static void can_exit_sleep_mode(XlnxZynqMPCANState *s)
139
+ fi->type = ARMFault_Permission;
514
+{
140
+ }
515
+ ARRAY_FIELD_DP32(s->regs, MODE_SELECT_REGISTER, SLEEP, 0);
141
return true;
516
+ update_status_register_mode_bits(s);
142
}
517
+}
143
518
+
144
@@ -XXX,XX +XXX,XX @@ bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address,
519
+static void generate_frame(qemu_can_frame *frame, uint32_t *data)
145
/* hit using the background region */
520
+{
146
get_phys_addr_pmsav7_default(env, mmu_idx, address, &result->f.prot);
521
+ frame->can_id = data[0];
147
} else {
522
+ frame->can_dlc = FIELD_EX32(data[1], TXFIFO_DLC, DLC);
148
- uint32_t ap = extract32(env->pmsav8.rbar[secure][matchregion], 1, 2);
523
+
149
- uint32_t xn = extract32(env->pmsav8.rbar[secure][matchregion], 0, 1);
524
+ frame->data[0] = FIELD_EX32(data[2], TXFIFO_DATA1, DB3);
150
+ uint32_t matched_rbar = regime_rbar(env, mmu_idx, secure)[matchregion];
525
+ frame->data[1] = FIELD_EX32(data[2], TXFIFO_DATA1, DB2);
151
+ uint32_t matched_rlar = regime_rlar(env, mmu_idx, secure)[matchregion];
526
+ frame->data[2] = FIELD_EX32(data[2], TXFIFO_DATA1, DB1);
152
+ uint32_t ap = extract32(matched_rbar, 1, 2);
527
+ frame->data[3] = FIELD_EX32(data[2], TXFIFO_DATA1, DB0);
153
+ uint32_t xn = extract32(matched_rbar, 0, 1);
528
+
154
bool pxn = false;
529
+ frame->data[4] = FIELD_EX32(data[3], TXFIFO_DATA2, DB7);
155
530
+ frame->data[5] = FIELD_EX32(data[3], TXFIFO_DATA2, DB6);
156
if (arm_feature(env, ARM_FEATURE_V8_1M)) {
531
+ frame->data[6] = FIELD_EX32(data[3], TXFIFO_DATA2, DB5);
157
- pxn = extract32(env->pmsav8.rlar[secure][matchregion], 4, 1);
532
+ frame->data[7] = FIELD_EX32(data[3], TXFIFO_DATA2, DB4);
158
+ pxn = extract32(matched_rlar, 4, 1);
533
+}
159
}
534
+
160
535
+static bool tx_ready_check(XlnxZynqMPCANState *s)
161
if (m_is_system_region(env, address)) {
536
+{
162
@@ -XXX,XX +XXX,XX @@ bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address,
537
+ if (ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, SRST)) {
163
xn = 1;
538
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
164
}
539
+
165
540
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Attempting to transfer data while"
166
- result->f.prot = simple_ap_to_rw_prot(env, mmu_idx, ap);
541
+ " data while controller is in reset mode.\n",
167
+ if (regime_el(env, mmu_idx) == 2) {
542
+ path);
168
+ result->f.prot = simple_ap_to_rw_prot_is_user(ap,
543
+ return false;
169
+ mmu_idx != ARMMMUIdx_E2);
544
+ }
170
+ } else {
545
+
171
+ result->f.prot = simple_ap_to_rw_prot(env, mmu_idx, ap);
546
+ if (ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, CEN) == 0) {
172
+ }
547
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
173
+
548
+
174
+ if (!arm_feature(env, ARM_FEATURE_M)) {
549
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Attempting to transfer"
175
+ uint8_t attrindx = extract32(matched_rlar, 1, 3);
550
+ " data while controller is in configuration mode. Reset"
176
+ uint64_t mair = env->cp15.mair_el[regime_el(env, mmu_idx)];
551
+ " the core so operations can start fresh.\n",
177
+ uint8_t sh = extract32(matched_rlar, 3, 2);
552
+ path);
178
+
553
+ return false;
179
+ if (regime_sctlr(env, mmu_idx) & SCTLR_WXN &&
554
+ }
180
+ result->f.prot & PAGE_WRITE && mmu_idx != ARMMMUIdx_Stage2) {
555
+
181
+ xn = 0x1;
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
+ }
182
+ }
580
+
183
+
581
+ if (ARRAY_FIELD_EX32(s->regs, STATUS_REGISTER, LBACK)) {
184
+ if ((regime_el(env, mmu_idx) == 1) &&
582
+ /*
185
+ regime_sctlr(env, mmu_idx) & SCTLR_UWXN && ap == 0x1) {
583
+ * Controller is in loopback. In Loopback mode, the CAN core
186
+ pxn = 0x1;
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
+ }
187
+ }
609
+ }
188
+
610
+
189
+ result->cacheattrs.is_s2_format = false;
611
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, TXOK, 1);
190
+ result->cacheattrs.attrs = extract64(mair, attrindx * 8, 8);
612
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, TXBFLL, 0);
191
+ result->cacheattrs.shareability = sh;
613
+
192
+ }
614
+ if (ARRAY_FIELD_EX32(s->regs, STATUS_REGISTER, SLEEP)) {
193
+
615
+ can_exit_sleep_mode(s);
194
if (result->f.prot && !xn && !(pxn && !is_user)) {
616
+ }
195
result->f.prot |= PAGE_EXEC;
617
+ } else {
196
}
618
+ DB_PRINT(s, "Not enabled for data transfer.\n");
197
- /*
619
+ }
198
- * We don't need to look the attribute up in the MAIR0/MAIR1
620
+
199
- * registers because that only tells us about cacheability.
621
+ can_update_irq(s);
200
- */
622
+}
201
+
623
+
202
if (mregion) {
624
+static uint64_t can_srr_pre_write(RegisterInfo *reg, uint64_t val64)
203
*mregion = matchregion;
625
+{
204
}
626
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
205
}
627
+ uint32_t val = val64;
206
628
+
207
fi->type = ARMFault_Permission;
629
+ ARRAY_FIELD_DP32(s->regs, SOFTWARE_RESET_REGISTER, CEN,
208
- fi->level = 1;
630
+ FIELD_EX32(val, SOFTWARE_RESET_REGISTER, CEN));
209
+ if (arm_feature(env, ARM_FEATURE_M)) {
631
+
210
+ fi->level = 1;
632
+ if (FIELD_EX32(val, SOFTWARE_RESET_REGISTER, SRST)) {
211
+ }
633
+ DB_PRINT(s, "Resetting controller.\n");
212
return !(result->f.prot & (1 << access_type));
634
+
213
}
635
+ /* First, core will do software reset then will enter in config mode. */
214
636
+ can_config_reset(s);
215
@@ -XXX,XX +XXX,XX @@ static bool get_phys_addr_twostage(CPUARMState *env, S1Translate *ptw,
637
+ }
216
cacheattrs1 = result->cacheattrs;
638
+
217
memset(result, 0, sizeof(*result));
639
+ if (ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, CEN) == 0) {
218
640
+ can_config_mode(s);
219
- ret = get_phys_addr_lpae(env, ptw, ipa, access_type, is_el0, result, fi);
641
+ } else {
220
+ if (arm_feature(env, ARM_FEATURE_PMSA)) {
642
+ /*
221
+ ret = get_phys_addr_pmsav8(env, ipa, access_type,
643
+ * Leave config mode. Now XlnxZynqMPCAN core will enter normal,
222
+ ptw->in_mmu_idx, is_secure, result, fi);
644
+ * sleep, snoop or loopback mode depending upon LBACK, SLEEP, SNOOP
223
+ } else {
645
+ * register states.
224
+ ret = get_phys_addr_lpae(env, ptw, ipa, access_type,
646
+ */
225
+ is_el0, result, fi);
647
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, CONFIG, 0);
226
+ }
648
+
227
fi->s2addr = ipa;
649
+ ptimer_transaction_begin(s->can_timer);
228
650
+ ptimer_set_count(s->can_timer, 0);
229
/* Combine the S1 and S2 perms. */
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
+ }
778
+ }
779
+
780
+ if (ARRAY_FIELD_EX32(s->regs, AFR, UAF2)) {
781
+ uint32_t id_masked = s->regs[R_AFMR2] & frame->can_id;
782
+ uint32_t filter_id_masked = s->regs[R_AFMR2] & s->regs[R_AFIR2];
783
+
784
+ if (filter_id_masked == id_masked) {
785
+ filter_pass = true;
786
+ }
787
+ }
788
+
789
+ if (ARRAY_FIELD_EX32(s->regs, AFR, UAF3)) {
790
+ uint32_t id_masked = s->regs[R_AFMR3] & frame->can_id;
791
+ uint32_t filter_id_masked = s->regs[R_AFMR3] & s->regs[R_AFIR3];
792
+
793
+ if (filter_id_masked == id_masked) {
794
+ filter_pass = true;
795
+ }
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
--
230
--
1301
2.20.1
231
2.25.1
1302
232
1303
233
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Tobias Röhmel <tobias.roehmel@rwth-aachen.de>
2
2
3
This just implements the bare minimum to cause the boot block to skip
3
All constants are taken from the ARM Cortex-R52 Processor TRM Revision: r1p3
4
memory initialization.
5
4
6
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
5
Signed-off-by: Tobias Röhmel <tobias.roehmel@rwth-aachen.de>
7
Reviewed-by: Cédric Le Goater <clg@kaod.org>
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Message-id: 20221206102504.165775-8-tobias.roehmel@rwth-aachen.de
9
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
10
Tested-by: Alexander Bulekov <alxndr@bu.edu>
11
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
12
Message-id: 20200911052101.2602693-10-hskinnemoen@google.com
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
---
9
---
15
include/hw/arm/npcm7xx.h | 2 +
10
target/arm/cpu_tcg.c | 42 ++++++++++++++++++++++++++++++++++++++++++
16
include/hw/mem/npcm7xx_mc.h | 36 ++++++++++++++++
11
1 file changed, 42 insertions(+)
17
hw/arm/npcm7xx.c | 6 +++
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
12
24
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
13
diff --git a/target/arm/cpu_tcg.c b/target/arm/cpu_tcg.c
25
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
26
--- a/include/hw/arm/npcm7xx.h
15
--- a/target/arm/cpu_tcg.c
27
+++ b/include/hw/arm/npcm7xx.h
16
+++ b/target/arm/cpu_tcg.c
28
@@ -XXX,XX +XXX,XX @@
17
@@ -XXX,XX +XXX,XX @@ static void cortex_r5_initfn(Object *obj)
29
18
define_arm_cp_regs(cpu, cortexr5_cp_reginfo);
30
#include "hw/boards.h"
19
}
31
#include "hw/cpu/a9mpcore.h"
20
32
+#include "hw/mem/npcm7xx_mc.h"
21
+static void cortex_r52_initfn(Object *obj)
33
#include "hw/misc/npcm7xx_clk.h"
22
+{
34
#include "hw/misc/npcm7xx_gcr.h"
23
+ ARMCPU *cpu = ARM_CPU(obj);
35
#include "hw/nvram/npcm7xx_otp.h"
36
@@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState {
37
NPCM7xxTimerCtrlState tim[3];
38
NPCM7xxOTPState key_storage;
39
NPCM7xxOTPState fuse_array;
40
+ NPCM7xxMCState mc;
41
} NPCM7xxState;
42
43
#define TYPE_NPCM7XX "npcm7xx"
44
diff --git a/include/hw/mem/npcm7xx_mc.h b/include/hw/mem/npcm7xx_mc.h
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
+
24
+
68
+#include "exec/memory.h"
25
+ set_feature(&cpu->env, ARM_FEATURE_V8);
69
+#include "hw/sysbus.h"
26
+ set_feature(&cpu->env, ARM_FEATURE_EL2);
27
+ set_feature(&cpu->env, ARM_FEATURE_PMSA);
28
+ set_feature(&cpu->env, ARM_FEATURE_NEON);
29
+ set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER);
30
+ cpu->midr = 0x411fd133; /* r1p3 */
31
+ cpu->revidr = 0x00000000;
32
+ cpu->reset_fpsid = 0x41034023;
33
+ cpu->isar.mvfr0 = 0x10110222;
34
+ cpu->isar.mvfr1 = 0x12111111;
35
+ cpu->isar.mvfr2 = 0x00000043;
36
+ cpu->ctr = 0x8144c004;
37
+ cpu->reset_sctlr = 0x30c50838;
38
+ cpu->isar.id_pfr0 = 0x00000131;
39
+ cpu->isar.id_pfr1 = 0x10111001;
40
+ cpu->isar.id_dfr0 = 0x03010006;
41
+ cpu->id_afr0 = 0x00000000;
42
+ cpu->isar.id_mmfr0 = 0x00211040;
43
+ cpu->isar.id_mmfr1 = 0x40000000;
44
+ cpu->isar.id_mmfr2 = 0x01200000;
45
+ cpu->isar.id_mmfr3 = 0xf0102211;
46
+ cpu->isar.id_mmfr4 = 0x00000010;
47
+ cpu->isar.id_isar0 = 0x02101110;
48
+ cpu->isar.id_isar1 = 0x13112111;
49
+ cpu->isar.id_isar2 = 0x21232142;
50
+ cpu->isar.id_isar3 = 0x01112131;
51
+ cpu->isar.id_isar4 = 0x00010142;
52
+ cpu->isar.id_isar5 = 0x00010001;
53
+ cpu->isar.dbgdidr = 0x77168000;
54
+ cpu->clidr = (1 << 27) | (1 << 24) | 0x3;
55
+ cpu->ccsidr[0] = 0x700fe01a; /* 32KB L1 dcache */
56
+ cpu->ccsidr[1] = 0x201fe00a; /* 32KB L1 icache */
70
+
57
+
71
+/**
58
+ cpu->pmsav7_dregion = 16;
72
+ * struct NPCM7xxMCState - Device state for the memory controller.
59
+ cpu->pmsav8r_hdregion = 16;
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
+{
151
+ /*
152
+ * If bits 8..11 @ offset 0 are not zero, the boot block thinks the memory
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
+}
60
+}
163
+
61
+
164
+static void npcm7xx_mc_write(void *opaque, hwaddr addr, uint64_t v,
62
static void cortex_r5f_initfn(Object *obj)
165
+ unsigned int size)
63
{
166
+{
64
ARMCPU *cpu = ARM_CPU(obj);
167
+ qemu_log_mask(LOG_UNIMP, "%s: mostly unimplemented\n", __func__);
65
@@ -XXX,XX +XXX,XX @@ static const ARMCPUInfo arm_tcg_cpus[] = {
168
+}
66
.class_init = arm_v7m_class_init },
169
+
67
{ .name = "cortex-r5", .initfn = cortex_r5_initfn },
170
+static const MemoryRegionOps npcm7xx_mc_ops = {
68
{ .name = "cortex-r5f", .initfn = cortex_r5f_initfn },
171
+ .read = npcm7xx_mc_read,
69
+ { .name = "cortex-r52", .initfn = cortex_r52_initfn },
172
+ .write = npcm7xx_mc_write,
70
{ .name = "ti925t", .initfn = ti925t_initfn },
173
+ .endianness = DEVICE_LITTLE_ENDIAN,
71
{ .name = "sa1100", .initfn = sa1100_initfn },
174
+ .valid = {
72
{ .name = "sa1110", .initfn = sa1110_initfn },
175
+ .min_access_size = 4,
176
+ .max_access_size = 4,
177
+ .unaligned = false,
178
+ },
179
+};
180
+
181
+static void npcm7xx_mc_realize(DeviceState *dev, Error **errp)
182
+{
183
+ NPCM7xxMCState *s = NPCM7XX_MC(dev);
184
+
185
+ memory_region_init_io(&s->mmio, OBJECT(s), &npcm7xx_mc_ops, s, "regs",
186
+ NPCM7XX_MC_REGS_SIZE);
187
+ sysbus_init_mmio(&s->parent, &s->mmio);
188
+}
189
+
190
+static void npcm7xx_mc_class_init(ObjectClass *klass, void *data)
191
+{
192
+ DeviceClass *dc = DEVICE_CLASS(klass);
193
+
194
+ dc->desc = "NPCM7xx Memory Controller stub";
195
+ dc->realize = npcm7xx_mc_realize;
196
+}
197
+
198
+static const TypeInfo npcm7xx_mc_types[] = {
199
+ {
200
+ .name = TYPE_NPCM7XX_MC,
201
+ .parent = TYPE_SYS_BUS_DEVICE,
202
+ .instance_size = sizeof(NPCM7xxMCState),
203
+ .class_init = npcm7xx_mc_class_init,
204
+ },
205
+};
206
+DEFINE_TYPES(npcm7xx_mc_types);
207
diff --git a/hw/mem/meson.build b/hw/mem/meson.build
208
index XXXXXXX..XXXXXXX 100644
209
--- a/hw/mem/meson.build
210
+++ b/hw/mem/meson.build
211
@@ -XXX,XX +XXX,XX @@
212
mem_ss = ss.source_set()
213
mem_ss.add(files('memory-device.c'))
214
mem_ss.add(when: 'CONFIG_DIMM', if_true: files('pc-dimm.c'))
215
+mem_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_mc.c'))
216
mem_ss.add(when: 'CONFIG_NVDIMM', if_true: files('nvdimm.c'))
217
218
softmmu_ss.add_all(when: 'CONFIG_MEM_DEVICE', if_true: mem_ss)
219
--
73
--
220
2.20.1
74
2.25.1
221
75
222
76
diff view generated by jsdifflib
1
From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com>
1
From: Alex Bennée <alex.bennee@linaro.org>
2
2
3
Correct the GEMs tx/rx clocks to use the 125Mhz fixed-clock.
3
The check semihosting_enabled() wants to know if the guest is
4
This matches the setup with the fixed-link 100Mbit PHY.
4
currently in user mode. Unlike the other cases the test was inverted
5
It also avoids the following warnings from the Linux kernel
5
causing us to block semihosting calls in non-EL0 modes.
6
driver:
7
6
8
eth0: unable to generate target frequency: 125000000 Hz
7
Cc: qemu-stable@nongnu.org
9
8
Fixes: 19b26317e9 (target/arm: Honour -semihosting-config userspace=on)
10
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
11
Reviewed-by: Luc Michel <luc.michel@greensocs.com>
10
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
13
Message-id: 20200909174647.662864-2-edgar.iglesias@gmail.com
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
---
12
---
16
hw/arm/xlnx-versal-virt.c | 2 +-
13
target/arm/translate.c | 2 +-
17
1 file changed, 1 insertion(+), 1 deletion(-)
14
1 file changed, 1 insertion(+), 1 deletion(-)
18
15
19
diff --git a/hw/arm/xlnx-versal-virt.c b/hw/arm/xlnx-versal-virt.c
16
diff --git a/target/arm/translate.c b/target/arm/translate.c
20
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
21
--- a/hw/arm/xlnx-versal-virt.c
18
--- a/target/arm/translate.c
22
+++ b/hw/arm/xlnx-versal-virt.c
19
+++ b/target/arm/translate.c
23
@@ -XXX,XX +XXX,XX @@ static void fdt_add_gem_nodes(VersalVirt *s)
20
@@ -XXX,XX +XXX,XX @@ static inline void gen_hlt(DisasContext *s, int imm)
24
s->phandle.ethernet_phy[i]);
21
* semihosting, to provide some semblance of security
25
qemu_fdt_setprop_cells(s->fdt, name, "clocks",
22
* (and for consistency with our 32-bit semihosting).
26
s->phandle.clk_25Mhz, s->phandle.clk_25Mhz,
23
*/
27
- s->phandle.clk_25Mhz, s->phandle.clk_25Mhz);
24
- if (semihosting_enabled(s->current_el != 0) &&
28
+ s->phandle.clk_125Mhz, s->phandle.clk_125Mhz);
25
+ if (semihosting_enabled(s->current_el == 0) &&
29
qemu_fdt_setprop(s->fdt, name, "clock-names",
26
(imm == (s->thumb ? 0x3c : 0xf000))) {
30
clocknames, sizeof(clocknames));
27
gen_exception_internal_insn(s, EXCP_SEMIHOST);
31
qemu_fdt_setprop_cells(s->fdt, name, "interrupts",
28
return;
32
--
29
--
33
2.20.1
30
2.25.1
34
31
35
32
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Axel Heider <axel.heider@hensoldt.net>
2
2
3
This allows these NPCM7xx-based boards to boot from a flash image, e.g.
3
Fix typos, add background information
4
one built with OpenBMC. For example like this:
5
4
6
IMAGE=${OPENBMC}/build/tmp/deploy/images/gsj/image-bmc
5
Signed-off-by: Axel Heider <axel.heider@hensoldt.net>
7
qemu-system-arm -machine quanta-gsj -nographic \
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
    -drive file=${IMAGE},if=mtd,bus=0,unit=0,format=raw,snapshot=on
9
10
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
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>
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
18
---
8
---
19
hw/arm/npcm7xx_boards.c | 20 ++++++++++++++++++++
9
hw/timer/imx_epit.c | 20 ++++++++++++++++----
20
1 file changed, 20 insertions(+)
10
1 file changed, 16 insertions(+), 4 deletions(-)
21
11
22
diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c
12
diff --git a/hw/timer/imx_epit.c b/hw/timer/imx_epit.c
23
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
24
--- a/hw/arm/npcm7xx_boards.c
14
--- a/hw/timer/imx_epit.c
25
+++ b/hw/arm/npcm7xx_boards.c
15
+++ b/hw/timer/imx_epit.c
26
@@ -XXX,XX +XXX,XX @@
16
@@ -XXX,XX +XXX,XX @@ static void imx_epit_set_freq(IMXEPITState *s)
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
}
17
}
36
}
18
}
37
19
38
+static void npcm7xx_connect_flash(NPCM7xxFIUState *fiu, int cs_no,
20
+/*
39
+ const char *flash_type, DriveInfo *dinfo)
21
+ * This is called both on hardware (device) reset and software reset.
40
+{
22
+ */
41
+ DeviceState *flash;
23
static void imx_epit_reset(DeviceState *dev)
42
+ qemu_irq flash_cs;
43
+
44
+ flash = qdev_new(flash_type);
45
+ if (dinfo) {
46
+ qdev_prop_set_drive(flash, "drive", blk_by_legacy_dinfo(dinfo));
47
+ }
48
+ qdev_realize_and_unref(flash, BUS(fiu->spi), &error_fatal);
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
+}
53
+
54
static void npcm7xx_connect_dram(NPCM7xxState *soc, MemoryRegion *dram)
55
{
24
{
56
memory_region_add_subregion(get_system_memory(), NPCM7XX_DRAM_BA, dram);
25
IMXEPITState *s = IMX_EPIT(dev);
57
@@ -XXX,XX +XXX,XX @@ static void npcm750_evb_init(MachineState *machine)
26
58
qdev_realize(DEVICE(soc), NULL, &error_fatal);
27
- /*
59
28
- * Soft reset doesn't touch some bits; hard reset clears them
60
npcm7xx_load_bootrom(machine, soc);
29
- */
61
+ npcm7xx_connect_flash(&soc->fiu[0], 0, "w25q256", drive_get(IF_MTD, 0, 0));
30
+ /* Soft reset doesn't touch some bits; hard reset clears them */
62
npcm7xx_load_kernel(machine, soc);
31
s->cr &= (CR_EN|CR_ENMOD|CR_STOPEN|CR_DOZEN|CR_WAITEN|CR_DBGEN);
32
s->sr = 0;
33
s->lr = EPIT_TIMER_MAX;
34
@@ -XXX,XX +XXX,XX @@ static void imx_epit_write(void *opaque, hwaddr offset, uint64_t value,
35
ptimer_transaction_begin(s->timer_cmp);
36
ptimer_transaction_begin(s->timer_reload);
37
38
+ /* Update the frequency. Has been done already in case of a reset. */
39
if (!(s->cr & CR_SWR)) {
40
imx_epit_set_freq(s);
41
}
42
@@ -XXX,XX +XXX,XX @@ static void imx_epit_write(void *opaque, hwaddr offset, uint64_t value,
43
break;
44
45
case 1: /* SR - ACK*/
46
- /* writing 1 to OCIF clear the OCIF bit */
47
+ /* writing 1 to OCIF clears the OCIF bit */
48
if (value & 0x01) {
49
s->sr = 0;
50
imx_epit_update_int(s);
51
@@ -XXX,XX +XXX,XX @@ static void imx_epit_realize(DeviceState *dev, Error **errp)
52
0x00001000);
53
sysbus_init_mmio(sbd, &s->iomem);
54
55
+ /*
56
+ * The reload timer keeps running when the peripheral is enabled. It is a
57
+ * kind of wall clock that does not generate any interrupts. The callback
58
+ * needs to be provided, but it does nothing as the ptimer already supports
59
+ * all necessary reloading functionality.
60
+ */
61
s->timer_reload = ptimer_init(imx_epit_reload, s, PTIMER_POLICY_LEGACY);
62
63
+ /*
64
+ * The compare timer is running only when the peripheral configuration is
65
+ * in a state that will generate compare interrupts.
66
+ */
67
s->timer_cmp = ptimer_init(imx_epit_cmp, s, PTIMER_POLICY_LEGACY);
63
}
68
}
64
69
65
@@ -XXX,XX +XXX,XX @@ static void quanta_gsj_init(MachineState *machine)
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
--
70
--
75
2.20.1
71
2.25.1
76
77
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Axel Heider <axel.heider@hensoldt.net>
2
2
3
Reviewed-by: Cédric Le Goater <clg@kaod.org>
3
remove unused defines, add needed defines
4
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
4
5
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
5
Signed-off-by: Axel Heider <axel.heider@hensoldt.net>
6
Message-id: 20200911052101.2602693-14-hskinnemoen@google.com
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
---
8
---
9
docs/system/arm/nuvoton.rst | 92 +++++++++++++++++++++++++++++++++++++
9
include/hw/timer/imx_epit.h | 4 ++--
10
docs/system/target-arm.rst | 1 +
10
hw/timer/imx_epit.c | 4 ++--
11
2 files changed, 93 insertions(+)
11
2 files changed, 4 insertions(+), 4 deletions(-)
12
create mode 100644 docs/system/arm/nuvoton.rst
13
12
14
diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst
13
diff --git a/include/hw/timer/imx_epit.h b/include/hw/timer/imx_epit.h
15
new file mode 100644
14
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX
15
--- a/include/hw/timer/imx_epit.h
17
--- /dev/null
16
+++ b/include/hw/timer/imx_epit.h
18
+++ b/docs/system/arm/nuvoton.rst
19
@@ -XXX,XX +XXX,XX @@
17
@@ -XXX,XX +XXX,XX @@
20
+Nuvoton iBMC boards (``npcm750-evb``, ``quanta-gsj``)
18
#define CR_OCIEN (1 << 2)
21
+=====================================================
19
#define CR_RLD (1 << 3)
22
+
20
#define CR_PRESCALE_SHIFT (4)
23
+The `Nuvoton iBMC`_ chips (NPCM7xx) are a family of ARM-based SoCs that are
21
-#define CR_PRESCALE_MASK (0xfff)
24
+designed to be used as Baseboard Management Controllers (BMCs) in various
22
+#define CR_PRESCALE_BITS (12)
25
+servers. They all feature one or two ARM Cortex A9 CPU cores, as well as an
23
#define CR_SWR (1 << 16)
26
+assortment of peripherals targeted for either Enterprise or Data Center /
24
#define CR_IOVW (1 << 17)
27
+Hyperscale applications. The former is a superset of the latter, so NPCM750 has
25
#define CR_DBGEN (1 << 18)
28
+all the peripherals of NPCM730 and more.
26
@@ -XXX,XX +XXX,XX @@
29
+
27
#define CR_DOZEN (1 << 20)
30
+.. _Nuvoton iBMC: https://www.nuvoton.com/products/cloud-computing/ibmc/
28
#define CR_STOPEN (1 << 21)
31
+
29
#define CR_CLKSRC_SHIFT (24)
32
+The NPCM750 SoC has two Cortex A9 cores and is targeted for the Enterprise
30
-#define CR_CLKSRC_MASK (0x3 << CR_CLKSRC_SHIFT)
33
+segment. The following machines are based on this chip :
31
+#define CR_CLKSRC_BITS (2)
34
+
32
35
+- ``npcm750-evb`` Nuvoton NPCM750 Evaluation board
33
#define EPIT_TIMER_MAX 0XFFFFFFFFUL
36
+
34
37
+The NPCM730 SoC has two Cortex A9 cores and is targeted for Data Center and
35
diff --git a/hw/timer/imx_epit.c b/hw/timer/imx_epit.c
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
36
index XXXXXXX..XXXXXXX 100644
114
--- a/docs/system/target-arm.rst
37
--- a/hw/timer/imx_epit.c
115
+++ b/docs/system/target-arm.rst
38
+++ b/hw/timer/imx_epit.c
116
@@ -XXX,XX +XXX,XX @@ undocumented; you can get a complete list by running
39
@@ -XXX,XX +XXX,XX @@ static void imx_epit_set_freq(IMXEPITState *s)
117
arm/musicpal
40
uint32_t clksrc;
118
arm/gumstix
41
uint32_t prescaler;
119
arm/nseries
42
120
+ arm/nuvoton
43
- clksrc = extract32(s->cr, CR_CLKSRC_SHIFT, 2);
121
arm/orangepi
44
- prescaler = 1 + extract32(s->cr, CR_PRESCALE_SHIFT, 12);
122
arm/palm
45
+ clksrc = extract32(s->cr, CR_CLKSRC_SHIFT, CR_CLKSRC_BITS);
123
arm/xscale
46
+ prescaler = 1 + extract32(s->cr, CR_PRESCALE_SHIFT, CR_PRESCALE_BITS);
47
48
s->freq = imx_ccm_get_clock_frequency(s->ccm,
49
imx_epit_clocks[clksrc]) / prescaler;
124
--
50
--
125
2.20.1
51
2.25.1
126
127
diff view generated by jsdifflib
1
Deprecate our Unicore32 target support:
1
From: Axel Heider <axel.heider@hensoldt.net>
2
* the Linux kernel dropped support for unicore32 in commit
3
05119217a9bd199c for its 5.9 release (with rationale in the
4
cover letter: https://lkml.org/lkml/2020/8/3/232 )
5
* there is apparently no upstream toolchain that can create unicore32
6
binaries
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
2
3
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
14
Message-id: 20200825172719.19422-1-peter.maydell@linaro.org
15
---
5
---
16
docs/system/deprecated.rst | 8 ++++++++
6
include/hw/timer/imx_epit.h | 2 ++
17
1 file changed, 8 insertions(+)
7
hw/timer/imx_epit.c | 12 ++++++------
8
2 files changed, 8 insertions(+), 6 deletions(-)
18
9
19
diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
10
diff --git a/include/hw/timer/imx_epit.h b/include/hw/timer/imx_epit.h
20
index XXXXXXX..XXXXXXX 100644
11
index XXXXXXX..XXXXXXX 100644
21
--- a/docs/system/deprecated.rst
12
--- a/include/hw/timer/imx_epit.h
22
+++ b/docs/system/deprecated.rst
13
+++ b/include/hw/timer/imx_epit.h
23
@@ -XXX,XX +XXX,XX @@ The above, converted to the current supported format::
14
@@ -XXX,XX +XXX,XX @@
24
linux-user mode CPUs
15
#define CR_CLKSRC_SHIFT (24)
25
--------------------
16
#define CR_CLKSRC_BITS (2)
26
17
27
+``unicore32`` CPUs (since 5.2.0)
18
+#define SR_OCIF (1 << 0)
28
+''''''''''''''''''''''''''''''''
29
+
19
+
30
+The ``unicore32`` guest CPU support is deprecated and will be removed in
20
#define EPIT_TIMER_MAX 0XFFFFFFFFUL
31
+a future version of QEMU. Support for this CPU was removed from the
21
32
+upstream Linux kernel, and there is no available upstream toolchain
22
#define TYPE_IMX_EPIT "imx.epit"
33
+to build binaries for it.
23
diff --git a/hw/timer/imx_epit.c b/hw/timer/imx_epit.c
34
+
24
index XXXXXXX..XXXXXXX 100644
35
``tilegx`` CPUs (since 5.1.0)
25
--- a/hw/timer/imx_epit.c
36
'''''''''''''''''''''''''''''
26
+++ b/hw/timer/imx_epit.c
27
@@ -XXX,XX +XXX,XX @@ static const IMXClk imx_epit_clocks[] = {
28
*/
29
static void imx_epit_update_int(IMXEPITState *s)
30
{
31
- if (s->sr && (s->cr & CR_OCIEN) && (s->cr & CR_EN)) {
32
+ if ((s->sr & SR_OCIF) && (s->cr & CR_OCIEN) && (s->cr & CR_EN)) {
33
qemu_irq_raise(s->irq);
34
} else {
35
qemu_irq_lower(s->irq);
36
@@ -XXX,XX +XXX,XX @@ static void imx_epit_write(void *opaque, hwaddr offset, uint64_t value,
37
break;
38
39
case 1: /* SR - ACK*/
40
- /* writing 1 to OCIF clears the OCIF bit */
41
- if (value & 0x01) {
42
- s->sr = 0;
43
+ /* writing 1 to SR.OCIF clears this bit and turns the interrupt off */
44
+ if (value & SR_OCIF) {
45
+ s->sr = 0; /* SR.OCIF is the only bit in this register anyway */
46
imx_epit_update_int(s);
47
}
48
break;
49
@@ -XXX,XX +XXX,XX @@ static void imx_epit_cmp(void *opaque)
50
IMXEPITState *s = IMX_EPIT(opaque);
51
52
DPRINTF("sr was %d\n", s->sr);
53
-
54
- s->sr = 1;
55
+ /* Set interrupt status bit SR.OCIF and update the interrupt state */
56
+ s->sr |= SR_OCIF;
57
imx_epit_update_int(s);
58
}
37
59
38
--
60
--
39
2.20.1
61
2.25.1
40
41
diff view generated by jsdifflib
1
Make the list of MPS2 boards consistent in the phrasing of each
1
From: Axel Heider <axel.heider@hensoldt.net>
2
entry, use the correct casing of "Arm", and move the mps2-an511
3
entry so the list is in numeric order.
4
2
3
The interrupt state can change due to:
4
- reset clears both SR.OCIF and CR.OCIE
5
- write to CR.EN or CR.OCIE
6
7
Signed-off-by: Axel Heider <axel.heider@hensoldt.net>
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Message-id: 20200903202048.15370-4-peter.maydell@linaro.org
8
---
10
---
9
docs/system/arm/mps2.rst | 14 +++++++-------
11
hw/timer/imx_epit.c | 16 ++++++++++++----
10
1 file changed, 7 insertions(+), 7 deletions(-)
12
1 file changed, 12 insertions(+), 4 deletions(-)
11
13
12
diff --git a/docs/system/arm/mps2.rst b/docs/system/arm/mps2.rst
14
diff --git a/hw/timer/imx_epit.c b/hw/timer/imx_epit.c
13
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
14
--- a/docs/system/arm/mps2.rst
16
--- a/hw/timer/imx_epit.c
15
+++ b/docs/system/arm/mps2.rst
17
+++ b/hw/timer/imx_epit.c
16
@@ -XXX,XX +XXX,XX @@ as seen by the guest depend significantly on the FPGA image.
18
@@ -XXX,XX +XXX,XX @@ static void imx_epit_write(void *opaque, hwaddr offset, uint64_t value,
17
QEMU models the following FPGA images:
19
if (s->cr & CR_SWR) {
18
20
/* handle the reset */
19
``mps2-an385``
21
imx_epit_reset(DEVICE(s));
20
- Cortex-M3 as documented in ARM Application Note AN385
22
- /*
21
+ Cortex-M3 as documented in Arm Application Note AN385
23
- * TODO: could we 'break' here? following operations appear
22
``mps2-an386``
24
- * to duplicate the work imx_epit_reset() already did.
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
26
- Cortex-M7 as documented in ARM Application Note AN500
28
+ /*
27
-``mps2-an511``
29
+ * The interrupt state can change due to:
28
- Cortex-M3 'DesignStart' as documented in AN511
30
+ * - reset clears both SR.OCIF and CR.OCIE
29
+ Cortex-M7 as documented in Arm Application Note AN500
31
+ * - write to CR.EN or CR.OCIE
30
``mps2-an505``
32
+ */
31
- Cortex-M33 as documented in ARM Application Note AN505
33
+ imx_epit_update_int(s);
32
+ Cortex-M33 as documented in Arm Application Note AN505
34
+
33
+``mps2-an511``
35
+ /*
34
+ Cortex-M3 'DesignStart' as documented in Arm Application Note AN511
36
+ * TODO: could we 'break' here for reset? following operations appear
35
``mps2-an521``
37
+ * to duplicate the work imx_epit_reset() already did.
36
- Dual Cortex-M33 as documented in Application Note AN521
38
+ */
37
+ Dual Cortex-M33 as documented in Arm Application Note AN521
39
+
38
40
ptimer_transaction_begin(s->timer_cmp);
39
Differences between QEMU and real hardware:
41
ptimer_transaction_begin(s->timer_reload);
40
42
41
--
43
--
42
2.20.1
44
2.25.1
43
44
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Axel Heider <axel.heider@hensoldt.net>
2
2
3
This implements a device model for the NPCM7xx SPI flash controller.
3
Signed-off-by: Axel Heider <axel.heider@hensoldt.net>
4
4
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
5
Direct reads and writes, and user-mode transactions have been tested in
6
various modes. Protection features are not implemented yet.
7
8
All the FIU instances are available in the SoC's address space,
9
regardless of whether or not they're connected to actual flash chips.
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>
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
19
---
6
---
20
include/hw/arm/npcm7xx.h | 2 +
7
hw/timer/imx_epit.c | 20 ++++++++++++++------
21
include/hw/ssi/npcm7xx_fiu.h | 73 +++++
8
1 file changed, 14 insertions(+), 6 deletions(-)
22
hw/arm/npcm7xx.c | 58 ++++
23
hw/ssi/npcm7xx_fiu.c | 572 +++++++++++++++++++++++++++++++++++
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
9
31
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
10
diff --git a/hw/timer/imx_epit.c b/hw/timer/imx_epit.c
32
index XXXXXXX..XXXXXXX 100644
11
index XXXXXXX..XXXXXXX 100644
33
--- a/include/hw/arm/npcm7xx.h
12
--- a/hw/timer/imx_epit.c
34
+++ b/include/hw/arm/npcm7xx.h
13
+++ b/hw/timer/imx_epit.c
35
@@ -XXX,XX +XXX,XX @@
14
@@ -XXX,XX +XXX,XX @@ static void imx_epit_set_freq(IMXEPITState *s)
36
#include "hw/misc/npcm7xx_gcr.h"
15
/*
37
#include "hw/nvram/npcm7xx_otp.h"
16
* This is called both on hardware (device) reset and software reset.
38
#include "hw/timer/npcm7xx_timer.h"
17
*/
39
+#include "hw/ssi/npcm7xx_fiu.h"
18
-static void imx_epit_reset(DeviceState *dev)
40
#include "target/arm/cpu.h"
19
+static void imx_epit_reset(IMXEPITState *s, bool is_hard_reset)
41
42
#define NPCM7XX_MAX_NUM_CPUS (2)
43
@@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState {
44
NPCM7xxOTPState key_storage;
45
NPCM7xxOTPState fuse_array;
46
NPCM7xxMCState mc;
47
+ NPCM7xxFIUState fiu[2];
48
} NPCM7xxState;
49
50
#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
131
index XXXXXXX..XXXXXXX 100644
132
--- a/hw/arm/npcm7xx.c
133
+++ b/hw/arm/npcm7xx.c
134
@@ -XXX,XX +XXX,XX @@ static const hwaddr npcm7xx_uart_addr[] = {
135
0xf0004000,
136
};
137
138
+/* Direct memory-mapped access to SPI0 CS0-1. */
139
+static const hwaddr npcm7xx_fiu0_flash_addr[] = {
140
+ 0x80000000, /* CS0 */
141
+ 0x88000000, /* CS1 */
142
+};
143
+
144
+/* Direct memory-mapped access to SPI3 CS0-3. */
145
+static const hwaddr npcm7xx_fiu3_flash_addr[] = {
146
+ 0xa0000000, /* CS0 */
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
{
20
{
174
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj)
21
- IMXEPITState *s = IMX_EPIT(dev);
175
for (i = 0; i < ARRAY_SIZE(s->tim); i++) {
22
-
176
object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER);
23
/* Soft reset doesn't touch some bits; hard reset clears them */
177
}
24
- s->cr &= (CR_EN|CR_ENMOD|CR_STOPEN|CR_DOZEN|CR_WAITEN|CR_DBGEN);
178
+
25
+ if (is_hard_reset) {
179
+ QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_fiu) != ARRAY_SIZE(s->fiu));
26
+ s->cr = 0;
180
+ for (i = 0; i < ARRAY_SIZE(s->fiu); i++) {
27
+ } else {
181
+ object_initialize_child(obj, npcm7xx_fiu[i].name, &s->fiu[i],
28
+ s->cr &= (CR_EN|CR_ENMOD|CR_STOPEN|CR_DOZEN|CR_WAITEN|CR_DBGEN);
182
+ TYPE_NPCM7XX_FIU);
183
+ }
29
+ }
30
s->sr = 0;
31
s->lr = EPIT_TIMER_MAX;
32
s->cmp = 0;
33
@@ -XXX,XX +XXX,XX @@ static void imx_epit_write(void *opaque, hwaddr offset, uint64_t value,
34
s->cr = value & 0x03ffffff;
35
if (s->cr & CR_SWR) {
36
/* handle the reset */
37
- imx_epit_reset(DEVICE(s));
38
+ imx_epit_reset(s, false);
39
}
40
41
/*
42
@@ -XXX,XX +XXX,XX @@ static void imx_epit_realize(DeviceState *dev, Error **errp)
43
s->timer_cmp = ptimer_init(imx_epit_cmp, s, PTIMER_POLICY_LEGACY);
184
}
44
}
185
45
186
static void npcm7xx_realize(DeviceState *dev, Error **errp)
46
+static void imx_epit_dev_reset(DeviceState *dev)
187
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
188
serial_hd(i), DEVICE_LITTLE_ENDIAN);
189
}
190
191
+ /*
192
+ * Flash Interface Unit (FIU). Can fail if incorrect number of chip selects
193
+ * specified, but this is a programming error.
194
+ */
195
+ QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_fiu) != ARRAY_SIZE(s->fiu));
196
+ for (i = 0; i < ARRAY_SIZE(s->fiu); i++) {
197
+ SysBusDevice *sbd = SYS_BUS_DEVICE(&s->fiu[i]);
198
+ int j;
199
+
200
+ object_property_set_int(OBJECT(sbd), "cs-count",
201
+ npcm7xx_fiu[i].cs_count, &error_abort);
202
+ sysbus_realize(sbd, &error_abort);
203
+
204
+ sysbus_mmio_map(sbd, 0, npcm7xx_fiu[i].regs_addr);
205
+ for (j = 0; j < npcm7xx_fiu[i].cs_count; j++) {
206
+ sysbus_mmio_map(sbd, j + 1, npcm7xx_fiu[i].flash_addr[j]);
207
+ }
208
+ }
209
+
210
/* RAM2 (SRAM) */
211
memory_region_init_ram(&s->sram, OBJECT(dev), "ram2",
212
NPCM7XX_RAM2_SZ, &error_abort);
213
diff --git a/hw/ssi/npcm7xx_fiu.c b/hw/ssi/npcm7xx_fiu.c
214
new file mode 100644
215
index XXXXXXX..XXXXXXX
216
--- /dev/null
217
+++ b/hw/ssi/npcm7xx_fiu.c
218
@@ -XXX,XX +XXX,XX @@
219
+/*
220
+ * Nuvoton NPCM7xx Flash Interface Unit (FIU)
221
+ *
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
+{
47
+{
326
+ int index = flash - fiu->flash;
48
+ IMXEPITState *s = IMX_EPIT(dev);
327
+
49
+ imx_epit_reset(s, true);
328
+ g_assert(index >= 0 && index < fiu->cs_count);
329
+
330
+ return index;
331
+}
50
+}
332
+
51
+
333
+/* Assert the chip select specified in the UMA Control/Status Register. */
52
static void imx_epit_class_init(ObjectClass *klass, void *data)
334
+static void npcm7xx_fiu_select(NPCM7xxFIUState *s, int cs_id)
53
{
335
+{
54
DeviceClass *dc = DEVICE_CLASS(klass);
336
+ trace_npcm7xx_fiu_select(DEVICE(s)->canonical_path, cs_id);
55
337
+
56
dc->realize = imx_epit_realize;
338
+ if (cs_id < s->cs_count) {
57
- dc->reset = imx_epit_reset;
339
+ qemu_irq_lower(s->cs_lines[cs_id]);
58
+ dc->reset = imx_epit_dev_reset;
340
+ } else {
59
dc->vmsd = &vmstate_imx_timer_epit;
341
+ qemu_log_mask(LOG_GUEST_ERROR,
60
dc->desc = "i.MX periodic timer";
342
+ "%s: UMA to CS%d; this module has only %d chip selects",
61
}
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
--
62
--
834
2.20.1
63
2.25.1
835
836
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Axel Heider <axel.heider@hensoldt.net>
2
2
3
Report unimplemented register accesses using qemu_log_mask(UNIMP).
3
Signed-off-by: Axel Heider <axel.heider@hensoldt.net>
4
4
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
5
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20200901144100.116742-5-f4bug@amsat.org
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
6
---
10
hw/misc/a9scu.c | 6 ++++++
7
hw/timer/imx_epit.c | 215 ++++++++++++++++++++++++--------------------
11
1 file changed, 6 insertions(+)
8
1 file changed, 117 insertions(+), 98 deletions(-)
12
9
13
diff --git a/hw/misc/a9scu.c b/hw/misc/a9scu.c
10
diff --git a/hw/timer/imx_epit.c b/hw/timer/imx_epit.c
14
index XXXXXXX..XXXXXXX 100644
11
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/misc/a9scu.c
12
--- a/hw/timer/imx_epit.c
16
+++ b/hw/misc/a9scu.c
13
+++ b/hw/timer/imx_epit.c
17
@@ -XXX,XX +XXX,XX @@
14
@@ -XXX,XX +XXX,XX @@ static void imx_epit_reload_compare_timer(IMXEPITState *s)
18
#include "hw/qdev-properties.h"
19
#include "migration/vmstate.h"
20
#include "qapi/error.h"
21
+#include "qemu/log.h"
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
}
15
}
33
}
16
}
34
@@ -XXX,XX +XXX,XX @@ static void a9_scu_write(void *opaque, hwaddr offset,
17
35
case 0x54: /* SCU Non-secure Access Control Register */
18
+static void imx_epit_write_cr(IMXEPITState *s, uint32_t value)
36
/* unimplemented, fall through */
19
+{
20
+ uint32_t oldcr = s->cr;
21
+
22
+ s->cr = value & 0x03ffffff;
23
+
24
+ if (s->cr & CR_SWR) {
25
+ /* handle the reset */
26
+ imx_epit_reset(s, false);
27
+ }
28
+
29
+ /*
30
+ * The interrupt state can change due to:
31
+ * - reset clears both SR.OCIF and CR.OCIE
32
+ * - write to CR.EN or CR.OCIE
33
+ */
34
+ imx_epit_update_int(s);
35
+
36
+ /*
37
+ * TODO: could we 'break' here for reset? following operations appear
38
+ * to duplicate the work imx_epit_reset() already did.
39
+ */
40
+
41
+ ptimer_transaction_begin(s->timer_cmp);
42
+ ptimer_transaction_begin(s->timer_reload);
43
+
44
+ /* Update the frequency. Has been done already in case of a reset. */
45
+ if (!(s->cr & CR_SWR)) {
46
+ imx_epit_set_freq(s);
47
+ }
48
+
49
+ if (s->freq && (s->cr & CR_EN) && !(oldcr & CR_EN)) {
50
+ if (s->cr & CR_ENMOD) {
51
+ if (s->cr & CR_RLD) {
52
+ ptimer_set_limit(s->timer_reload, s->lr, 1);
53
+ ptimer_set_limit(s->timer_cmp, s->lr, 1);
54
+ } else {
55
+ ptimer_set_limit(s->timer_reload, EPIT_TIMER_MAX, 1);
56
+ ptimer_set_limit(s->timer_cmp, EPIT_TIMER_MAX, 1);
57
+ }
58
+ }
59
+
60
+ imx_epit_reload_compare_timer(s);
61
+ ptimer_run(s->timer_reload, 0);
62
+ if (s->cr & CR_OCIEN) {
63
+ ptimer_run(s->timer_cmp, 0);
64
+ } else {
65
+ ptimer_stop(s->timer_cmp);
66
+ }
67
+ } else if (!(s->cr & CR_EN)) {
68
+ /* stop both timers */
69
+ ptimer_stop(s->timer_reload);
70
+ ptimer_stop(s->timer_cmp);
71
+ } else if (s->cr & CR_OCIEN) {
72
+ if (!(oldcr & CR_OCIEN)) {
73
+ imx_epit_reload_compare_timer(s);
74
+ ptimer_run(s->timer_cmp, 0);
75
+ }
76
+ } else {
77
+ ptimer_stop(s->timer_cmp);
78
+ }
79
+
80
+ ptimer_transaction_commit(s->timer_cmp);
81
+ ptimer_transaction_commit(s->timer_reload);
82
+}
83
+
84
+static void imx_epit_write_sr(IMXEPITState *s, uint32_t value)
85
+{
86
+ /* writing 1 to SR.OCIF clears this bit and turns the interrupt off */
87
+ if (value & SR_OCIF) {
88
+ s->sr = 0; /* SR.OCIF is the only bit in this register anyway */
89
+ imx_epit_update_int(s);
90
+ }
91
+}
92
+
93
+static void imx_epit_write_lr(IMXEPITState *s, uint32_t value)
94
+{
95
+ s->lr = value;
96
+
97
+ ptimer_transaction_begin(s->timer_cmp);
98
+ ptimer_transaction_begin(s->timer_reload);
99
+ if (s->cr & CR_RLD) {
100
+ /* Also set the limit if the LRD bit is set */
101
+ /* If IOVW bit is set then set the timer value */
102
+ ptimer_set_limit(s->timer_reload, s->lr, s->cr & CR_IOVW);
103
+ ptimer_set_limit(s->timer_cmp, s->lr, 0);
104
+ } else if (s->cr & CR_IOVW) {
105
+ /* If IOVW bit is set then set the timer value */
106
+ ptimer_set_count(s->timer_reload, s->lr);
107
+ }
108
+ /*
109
+ * Commit the change to s->timer_reload, so it can propagate. Otherwise
110
+ * the timer interrupt may not fire properly. The commit must happen
111
+ * before calling imx_epit_reload_compare_timer(), which reads
112
+ * s->timer_reload internally again.
113
+ */
114
+ ptimer_transaction_commit(s->timer_reload);
115
+ imx_epit_reload_compare_timer(s);
116
+ ptimer_transaction_commit(s->timer_cmp);
117
+}
118
+
119
+static void imx_epit_write_cmp(IMXEPITState *s, uint32_t value)
120
+{
121
+ s->cmp = value;
122
+
123
+ ptimer_transaction_begin(s->timer_cmp);
124
+ imx_epit_reload_compare_timer(s);
125
+ ptimer_transaction_commit(s->timer_cmp);
126
+}
127
+
128
static void imx_epit_write(void *opaque, hwaddr offset, uint64_t value,
129
unsigned size)
130
{
131
IMXEPITState *s = IMX_EPIT(opaque);
132
- uint64_t oldcr;
133
134
DPRINTF("(%s, value = 0x%08x)\n", imx_epit_reg_name(offset >> 2),
135
(uint32_t)value);
136
137
switch (offset >> 2) {
138
case 0: /* CR */
139
-
140
- oldcr = s->cr;
141
- s->cr = value & 0x03ffffff;
142
- if (s->cr & CR_SWR) {
143
- /* handle the reset */
144
- imx_epit_reset(s, false);
145
- }
146
-
147
- /*
148
- * The interrupt state can change due to:
149
- * - reset clears both SR.OCIF and CR.OCIE
150
- * - write to CR.EN or CR.OCIE
151
- */
152
- imx_epit_update_int(s);
153
-
154
- /*
155
- * TODO: could we 'break' here for reset? following operations appear
156
- * to duplicate the work imx_epit_reset() already did.
157
- */
158
-
159
- ptimer_transaction_begin(s->timer_cmp);
160
- ptimer_transaction_begin(s->timer_reload);
161
-
162
- /* Update the frequency. Has been done already in case of a reset. */
163
- if (!(s->cr & CR_SWR)) {
164
- imx_epit_set_freq(s);
165
- }
166
-
167
- if (s->freq && (s->cr & CR_EN) && !(oldcr & CR_EN)) {
168
- if (s->cr & CR_ENMOD) {
169
- if (s->cr & CR_RLD) {
170
- ptimer_set_limit(s->timer_reload, s->lr, 1);
171
- ptimer_set_limit(s->timer_cmp, s->lr, 1);
172
- } else {
173
- ptimer_set_limit(s->timer_reload, EPIT_TIMER_MAX, 1);
174
- ptimer_set_limit(s->timer_cmp, EPIT_TIMER_MAX, 1);
175
- }
176
- }
177
-
178
- imx_epit_reload_compare_timer(s);
179
- ptimer_run(s->timer_reload, 0);
180
- if (s->cr & CR_OCIEN) {
181
- ptimer_run(s->timer_cmp, 0);
182
- } else {
183
- ptimer_stop(s->timer_cmp);
184
- }
185
- } else if (!(s->cr & CR_EN)) {
186
- /* stop both timers */
187
- ptimer_stop(s->timer_reload);
188
- ptimer_stop(s->timer_cmp);
189
- } else if (s->cr & CR_OCIEN) {
190
- if (!(oldcr & CR_OCIEN)) {
191
- imx_epit_reload_compare_timer(s);
192
- ptimer_run(s->timer_cmp, 0);
193
- }
194
- } else {
195
- ptimer_stop(s->timer_cmp);
196
- }
197
-
198
- ptimer_transaction_commit(s->timer_cmp);
199
- ptimer_transaction_commit(s->timer_reload);
200
+ imx_epit_write_cr(s, (uint32_t)value);
201
break;
202
203
- case 1: /* SR - ACK*/
204
- /* writing 1 to SR.OCIF clears this bit and turns the interrupt off */
205
- if (value & SR_OCIF) {
206
- s->sr = 0; /* SR.OCIF is the only bit in this register anyway */
207
- imx_epit_update_int(s);
208
- }
209
+ case 1: /* SR */
210
+ imx_epit_write_sr(s, (uint32_t)value);
211
break;
212
213
- case 2: /* LR - set ticks */
214
- s->lr = value;
215
-
216
- ptimer_transaction_begin(s->timer_cmp);
217
- ptimer_transaction_begin(s->timer_reload);
218
- if (s->cr & CR_RLD) {
219
- /* Also set the limit if the LRD bit is set */
220
- /* If IOVW bit is set then set the timer value */
221
- ptimer_set_limit(s->timer_reload, s->lr, s->cr & CR_IOVW);
222
- ptimer_set_limit(s->timer_cmp, s->lr, 0);
223
- } else if (s->cr & CR_IOVW) {
224
- /* If IOVW bit is set then set the timer value */
225
- ptimer_set_count(s->timer_reload, s->lr);
226
- }
227
- /*
228
- * Commit the change to s->timer_reload, so it can propagate. Otherwise
229
- * the timer interrupt may not fire properly. The commit must happen
230
- * before calling imx_epit_reload_compare_timer(), which reads
231
- * s->timer_reload internally again.
232
- */
233
- ptimer_transaction_commit(s->timer_reload);
234
- imx_epit_reload_compare_timer(s);
235
- ptimer_transaction_commit(s->timer_cmp);
236
+ case 2: /* LR */
237
+ imx_epit_write_lr(s, (uint32_t)value);
238
break;
239
240
case 3: /* CMP */
241
- s->cmp = value;
242
-
243
- ptimer_transaction_begin(s->timer_cmp);
244
- imx_epit_reload_compare_timer(s);
245
- ptimer_transaction_commit(s->timer_cmp);
246
-
247
+ imx_epit_write_cmp(s, (uint32_t)value);
248
break;
249
37
default:
250
default:
38
+ qemu_log_mask(LOG_UNIMP, "%s: Unsupported offset 0x%"HWADDR_PRIx
251
qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: Bad register at offset 0x%"
39
+ " value 0x%"PRIx64"\n",
252
HWADDR_PRIx "\n", TYPE_IMX_EPIT, __func__, offset);
40
+ __func__, offset, value);
253
-
41
break;
254
break;
42
}
255
}
43
}
256
}
257
+
258
static void imx_epit_cmp(void *opaque)
259
{
260
IMXEPITState *s = IMX_EPIT(opaque);
44
--
261
--
45
2.20.1
262
2.25.1
46
47
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Axel Heider <axel.heider@hensoldt.net>
2
2
3
Implement a device model for the System Global Control Registers in the
3
The CNT register is a read-only register. There is no need to
4
NPCM730 and NPCM750 BMC SoCs.
4
store it's value, it can be calculated on demand.
5
The calculated frequency is needed temporarily only.
5
6
6
This is primarily used to enable SMP boot (the boot ROM spins reading
7
Note that this is a migration compatibility break for all boards
7
the SCRPAD register) and DDR memory initialization; other registers are
8
types that use the EPIT peripheral.
8
best effort for now.
9
9
10
The reset values of the MDLR and PWRON registers are determined by the
10
Signed-off-by: Axel Heider <axel.heider@hensoldt.net>
11
SoC variant (730 vs 750) and board straps respectively.
11
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
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>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
21
---
13
---
22
include/hw/misc/npcm7xx_gcr.h | 43 ++++++
14
include/hw/timer/imx_epit.h | 2 -
23
hw/misc/npcm7xx_gcr.c | 269 ++++++++++++++++++++++++++++++++++
15
hw/timer/imx_epit.c | 73 ++++++++++++++-----------------------
24
MAINTAINERS | 8 +
16
2 files changed, 28 insertions(+), 47 deletions(-)
25
hw/arm/Kconfig | 3 +
26
hw/misc/meson.build | 3 +
27
hw/misc/trace-events | 4 +
28
6 files changed, 330 insertions(+)
29
create mode 100644 include/hw/misc/npcm7xx_gcr.h
30
create mode 100644 hw/misc/npcm7xx_gcr.c
31
17
32
diff --git a/include/hw/misc/npcm7xx_gcr.h b/include/hw/misc/npcm7xx_gcr.h
18
diff --git a/include/hw/timer/imx_epit.h b/include/hw/timer/imx_epit.h
33
new file mode 100644
19
index XXXXXXX..XXXXXXX 100644
34
index XXXXXXX..XXXXXXX
20
--- a/include/hw/timer/imx_epit.h
35
--- /dev/null
21
+++ b/include/hw/timer/imx_epit.h
36
+++ b/include/hw/misc/npcm7xx_gcr.h
22
@@ -XXX,XX +XXX,XX @@ struct IMXEPITState {
37
@@ -XXX,XX +XXX,XX @@
23
uint32_t sr;
38
+/*
24
uint32_t lr;
39
+ * Nuvoton NPCM7xx System Global Control Registers.
25
uint32_t cmp;
40
+ *
26
- uint32_t cnt;
41
+ * Copyright 2020 Google LLC
27
42
+ *
28
- uint32_t freq;
43
+ * This program is free software; you can redistribute it and/or modify it
29
qemu_irq irq;
44
+ * under the terms of the GNU General Public License as published by the
30
};
45
+ * Free Software Foundation; either version 2 of the License, or
31
46
+ * (at your option) any later version.
32
diff --git a/hw/timer/imx_epit.c b/hw/timer/imx_epit.c
47
+ *
33
index XXXXXXX..XXXXXXX 100644
48
+ * This program is distributed in the hope that it will be useful, but WITHOUT
34
--- a/hw/timer/imx_epit.c
49
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35
+++ b/hw/timer/imx_epit.c
50
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
36
@@ -XXX,XX +XXX,XX @@ static void imx_epit_update_int(IMXEPITState *s)
51
+ * for more details.
37
}
52
+ */
38
}
53
+#ifndef NPCM7XX_GCR_H
39
54
+#define NPCM7XX_GCR_H
40
-/*
55
+
41
- * Must be called from within a ptimer_transaction_begin/commit block
56
+#include "exec/memory.h"
42
- * for both s->timer_cmp and s->timer_reload.
57
+#include "hw/sysbus.h"
43
- */
58
+
44
-static void imx_epit_set_freq(IMXEPITState *s)
59
+/*
45
+static uint32_t imx_epit_get_freq(IMXEPITState *s)
60
+ * Number of registers in our device state structure. Don't change this without
46
{
61
+ * incrementing the version_id in the vmstate.
47
- uint32_t clksrc;
62
+ */
48
- uint32_t prescaler;
63
+#define NPCM7XX_GCR_NR_REGS (0x148 / sizeof(uint32_t))
49
-
64
+
50
- clksrc = extract32(s->cr, CR_CLKSRC_SHIFT, CR_CLKSRC_BITS);
65
+typedef struct NPCM7xxGCRState {
51
- prescaler = 1 + extract32(s->cr, CR_PRESCALE_SHIFT, CR_PRESCALE_BITS);
66
+ SysBusDevice parent;
52
-
67
+
53
- s->freq = imx_ccm_get_clock_frequency(s->ccm,
68
+ MemoryRegion iomem;
54
- imx_epit_clocks[clksrc]) / prescaler;
69
+
55
-
70
+ uint32_t regs[NPCM7XX_GCR_NR_REGS];
56
- DPRINTF("Setting ptimer frequency to %u\n", s->freq);
71
+
57
-
72
+ uint32_t reset_pwron;
58
- if (s->freq) {
73
+ uint32_t reset_mdlr;
59
- ptimer_set_freq(s->timer_reload, s->freq);
74
+ uint32_t reset_intcr3;
60
- ptimer_set_freq(s->timer_cmp, s->freq);
75
+} NPCM7xxGCRState;
61
- }
76
+
62
+ uint32_t clksrc = extract32(s->cr, CR_CLKSRC_SHIFT, CR_CLKSRC_BITS);
77
+#define TYPE_NPCM7XX_GCR "npcm7xx-gcr"
63
+ uint32_t prescaler = 1 + extract32(s->cr, CR_PRESCALE_SHIFT, CR_PRESCALE_BITS);
78
+#define NPCM7XX_GCR(obj) OBJECT_CHECK(NPCM7xxGCRState, (obj), TYPE_NPCM7XX_GCR)
64
+ uint32_t f_in = imx_ccm_get_clock_frequency(s->ccm, imx_epit_clocks[clksrc]);
79
+
65
+ uint32_t freq = f_in / prescaler;
80
+#endif /* NPCM7XX_GCR_H */
66
+ DPRINTF("ptimer frequency is %u\n", freq);
81
diff --git a/hw/misc/npcm7xx_gcr.c b/hw/misc/npcm7xx_gcr.c
67
+ return freq;
82
new file mode 100644
68
}
83
index XXXXXXX..XXXXXXX
69
84
--- /dev/null
70
/*
85
+++ b/hw/misc/npcm7xx_gcr.c
71
@@ -XXX,XX +XXX,XX @@ static void imx_epit_reset(IMXEPITState *s, bool is_hard_reset)
86
@@ -XXX,XX +XXX,XX @@
72
s->sr = 0;
87
+/*
73
s->lr = EPIT_TIMER_MAX;
88
+ * Nuvoton NPCM7xx System Global Control Registers.
74
s->cmp = 0;
89
+ *
75
- s->cnt = 0;
90
+ * Copyright 2020 Google LLC
76
ptimer_transaction_begin(s->timer_cmp);
91
+ *
77
ptimer_transaction_begin(s->timer_reload);
92
+ * This program is free software; you can redistribute it and/or modify it
78
- /* stop both timers */
93
+ * under the terms of the GNU General Public License as published by the
94
+ * Free Software Foundation; either version 2 of the License, or
95
+ * (at your option) any later version.
96
+ *
97
+ * This program is distributed in the hope that it will be useful, but WITHOUT
98
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
99
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
100
+ * for more details.
101
+ */
102
+
103
+#include "qemu/osdep.h"
104
+
105
+#include "hw/misc/npcm7xx_gcr.h"
106
+#include "hw/qdev-properties.h"
107
+#include "migration/vmstate.h"
108
+#include "qapi/error.h"
109
+#include "qemu/cutils.h"
110
+#include "qemu/log.h"
111
+#include "qemu/module.h"
112
+#include "qemu/units.h"
113
+
114
+#include "trace.h"
115
+
116
+#define NPCM7XX_GCR_MIN_DRAM_SIZE (128 * MiB)
117
+#define NPCM7XX_GCR_MAX_DRAM_SIZE (2 * GiB)
118
+
119
+enum NPCM7xxGCRRegisters {
120
+ NPCM7XX_GCR_PDID,
121
+ NPCM7XX_GCR_PWRON,
122
+ NPCM7XX_GCR_MFSEL1 = 0x0c / sizeof(uint32_t),
123
+ NPCM7XX_GCR_MFSEL2,
124
+ NPCM7XX_GCR_MISCPE,
125
+ NPCM7XX_GCR_SPSWC = 0x038 / sizeof(uint32_t),
126
+ NPCM7XX_GCR_INTCR,
127
+ NPCM7XX_GCR_INTSR,
128
+ NPCM7XX_GCR_HIFCR = 0x050 / sizeof(uint32_t),
129
+ NPCM7XX_GCR_INTCR2 = 0x060 / sizeof(uint32_t),
130
+ NPCM7XX_GCR_MFSEL3,
131
+ NPCM7XX_GCR_SRCNT,
132
+ NPCM7XX_GCR_RESSR,
133
+ NPCM7XX_GCR_RLOCKR1,
134
+ NPCM7XX_GCR_FLOCKR1,
135
+ NPCM7XX_GCR_DSCNT,
136
+ NPCM7XX_GCR_MDLR,
137
+ NPCM7XX_GCR_SCRPAD3,
138
+ NPCM7XX_GCR_SCRPAD2,
139
+ NPCM7XX_GCR_DAVCLVLR = 0x098 / sizeof(uint32_t),
140
+ NPCM7XX_GCR_INTCR3,
141
+ NPCM7XX_GCR_VSINTR = 0x0ac / sizeof(uint32_t),
142
+ NPCM7XX_GCR_MFSEL4,
143
+ NPCM7XX_GCR_CPBPNTR = 0x0c4 / sizeof(uint32_t),
144
+ NPCM7XX_GCR_CPCTL = 0x0d0 / sizeof(uint32_t),
145
+ NPCM7XX_GCR_CP2BST,
146
+ NPCM7XX_GCR_B2CPNT,
147
+ NPCM7XX_GCR_CPPCTL,
148
+ NPCM7XX_GCR_I2CSEGSEL,
149
+ NPCM7XX_GCR_I2CSEGCTL,
150
+ NPCM7XX_GCR_VSRCR,
151
+ NPCM7XX_GCR_MLOCKR,
152
+ NPCM7XX_GCR_SCRPAD = 0x013c / sizeof(uint32_t),
153
+ NPCM7XX_GCR_USB1PHYCTL,
154
+ NPCM7XX_GCR_USB2PHYCTL,
155
+ NPCM7XX_GCR_REGS_END,
156
+};
157
+
158
+static const uint32_t cold_reset_values[NPCM7XX_GCR_NR_REGS] = {
159
+ [NPCM7XX_GCR_PDID] = 0x04a92750, /* Poleg A1 */
160
+ [NPCM7XX_GCR_MISCPE] = 0x0000ffff,
161
+ [NPCM7XX_GCR_SPSWC] = 0x00000003,
162
+ [NPCM7XX_GCR_INTCR] = 0x0000035e,
163
+ [NPCM7XX_GCR_HIFCR] = 0x0000004e,
164
+ [NPCM7XX_GCR_INTCR2] = (1U << 19), /* DDR initialized */
165
+ [NPCM7XX_GCR_RESSR] = 0x80000000,
166
+ [NPCM7XX_GCR_DSCNT] = 0x000000c0,
167
+ [NPCM7XX_GCR_DAVCLVLR] = 0x5a00f3cf,
168
+ [NPCM7XX_GCR_SCRPAD] = 0x00000008,
169
+ [NPCM7XX_GCR_USB1PHYCTL] = 0x034730e4,
170
+ [NPCM7XX_GCR_USB2PHYCTL] = 0x034730e4,
171
+};
172
+
173
+static uint64_t npcm7xx_gcr_read(void *opaque, hwaddr offset, unsigned size)
174
+{
175
+ uint32_t reg = offset / sizeof(uint32_t);
176
+ NPCM7xxGCRState *s = opaque;
177
+
178
+ if (reg >= NPCM7XX_GCR_NR_REGS) {
179
+ qemu_log_mask(LOG_GUEST_ERROR,
180
+ "%s: offset 0x%04" HWADDR_PRIx " out of range\n",
181
+ __func__, offset);
182
+ return 0;
183
+ }
184
+
185
+ trace_npcm7xx_gcr_read(offset, s->regs[reg]);
186
+
187
+ return s->regs[reg];
188
+}
189
+
190
+static void npcm7xx_gcr_write(void *opaque, hwaddr offset,
191
+ uint64_t v, unsigned size)
192
+{
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
+ },
240
+};
241
+
242
+static void npcm7xx_gcr_enter_reset(Object *obj, ResetType type)
243
+{
244
+ NPCM7xxGCRState *s = NPCM7XX_GCR(obj);
245
+
246
+ QEMU_BUILD_BUG_ON(sizeof(s->regs) != sizeof(cold_reset_values));
247
+
248
+ switch (type) {
249
+ case RESET_TYPE_COLD:
250
+ memcpy(s->regs, cold_reset_values, sizeof(s->regs));
251
+ s->regs[NPCM7XX_GCR_PWRON] = s->reset_pwron;
252
+ s->regs[NPCM7XX_GCR_MDLR] = s->reset_mdlr;
253
+ s->regs[NPCM7XX_GCR_INTCR3] = s->reset_intcr3;
254
+ break;
255
+ }
256
+}
257
+
258
+static void npcm7xx_gcr_realize(DeviceState *dev, Error **errp)
259
+{
260
+ ERRP_GUARD();
261
+ NPCM7xxGCRState *s = NPCM7XX_GCR(dev);
262
+ uint64_t dram_size;
263
+ Object *obj;
264
+
265
+ obj = object_property_get_link(OBJECT(dev), "dram-mr", errp);
266
+ if (!obj) {
267
+ error_prepend(errp, "%s: required dram-mr link not found: ", __func__);
268
+ return;
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
+
79
+
287
+ /*
80
+ /*
288
+ * The GMMAP (Graphics Memory Map) field is used by u-boot to detect the
81
+ * The reset switches off the input clock, so even if the CR.EN is still
289
+ * DRAM size, and is normally initialized by the boot block as part of DRAM
82
+ * set, the timers are no longer running.
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
+ */
83
+ */
300
+ s->reset_intcr3 |= ctz64(dram_size / NPCM7XX_GCR_MIN_DRAM_SIZE) << 8;
84
+ assert(imx_epit_get_freq(s) == 0);
301
+}
85
ptimer_stop(s->timer_cmp);
302
+
86
ptimer_stop(s->timer_reload);
303
+static void npcm7xx_gcr_init(Object *obj)
87
- /* compute new frequency */
304
+{
88
- imx_epit_set_freq(s);
305
+ NPCM7xxGCRState *s = NPCM7XX_GCR(obj);
89
/* init both timers to EPIT_TIMER_MAX */
306
+
90
ptimer_set_limit(s->timer_cmp, EPIT_TIMER_MAX, 1);
307
+ memory_region_init_io(&s->iomem, obj, &npcm7xx_gcr_ops, s,
91
ptimer_set_limit(s->timer_reload, EPIT_TIMER_MAX, 1);
308
+ TYPE_NPCM7XX_GCR, 4 * KiB);
92
- if (s->freq && (s->cr & CR_EN)) {
309
+ sysbus_init_mmio(&s->parent, &s->iomem);
93
- /* if the timer is still enabled, restart it */
310
+}
94
- ptimer_run(s->timer_reload, 0);
311
+
95
- }
312
+static const VMStateDescription vmstate_npcm7xx_gcr = {
96
ptimer_transaction_commit(s->timer_cmp);
313
+ .name = "npcm7xx-gcr",
97
ptimer_transaction_commit(s->timer_reload);
314
+ .version_id = 0,
98
}
315
+ .minimum_version_id = 0,
99
316
+ .fields = (VMStateField[]) {
100
-static uint32_t imx_epit_update_count(IMXEPITState *s)
317
+ VMSTATE_UINT32_ARRAY(regs, NPCM7xxGCRState, NPCM7XX_GCR_NR_REGS),
101
-{
318
+ VMSTATE_END_OF_LIST(),
102
- s->cnt = ptimer_get_count(s->timer_reload);
319
+ },
103
-
320
+};
104
- return s->cnt;
321
+
105
-}
322
+static Property npcm7xx_gcr_properties[] = {
106
-
323
+ DEFINE_PROP_UINT32("disabled-modules", NPCM7xxGCRState, reset_mdlr, 0),
107
static uint64_t imx_epit_read(void *opaque, hwaddr offset, unsigned size)
324
+ DEFINE_PROP_UINT32("power-on-straps", NPCM7xxGCRState, reset_pwron, 0),
108
{
325
+ DEFINE_PROP_END_OF_LIST(),
109
IMXEPITState *s = IMX_EPIT(opaque);
326
+};
110
@@ -XXX,XX +XXX,XX @@ static uint64_t imx_epit_read(void *opaque, hwaddr offset, unsigned size)
327
+
111
break;
328
+static void npcm7xx_gcr_class_init(ObjectClass *klass, void *data)
112
329
+{
113
case 4: /* CNT */
330
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
114
- imx_epit_update_count(s);
331
+ DeviceClass *dc = DEVICE_CLASS(klass);
115
- reg_value = s->cnt;
332
+
116
+ reg_value = ptimer_get_count(s->timer_reload);
333
+ QEMU_BUILD_BUG_ON(NPCM7XX_GCR_REGS_END > NPCM7XX_GCR_NR_REGS);
117
break;
334
+
118
335
+ dc->desc = "NPCM7xx System Global Control Registers";
119
default:
336
+ dc->realize = npcm7xx_gcr_realize;
120
@@ -XXX,XX +XXX,XX @@ static void imx_epit_reload_compare_timer(IMXEPITState *s)
337
+ dc->vmsd = &vmstate_npcm7xx_gcr;
121
{
338
+ rc->phases.enter = npcm7xx_gcr_enter_reset;
122
if ((s->cr & (CR_EN | CR_OCIEN)) == (CR_EN | CR_OCIEN)) {
339
+
123
/* if the compare feature is on and timers are running */
340
+ device_class_set_props(dc, npcm7xx_gcr_properties);
124
- uint32_t tmp = imx_epit_update_count(s);
341
+}
125
+ uint32_t tmp = ptimer_get_count(s->timer_reload);
342
+
126
uint64_t next;
343
+static const TypeInfo npcm7xx_gcr_info = {
127
if (tmp > s->cmp) {
344
+ .name = TYPE_NPCM7XX_GCR,
128
/* It'll fire in this round of the timer */
345
+ .parent = TYPE_SYS_BUS_DEVICE,
129
@@ -XXX,XX +XXX,XX @@ static void imx_epit_reload_compare_timer(IMXEPITState *s)
346
+ .instance_size = sizeof(NPCM7xxGCRState),
130
347
+ .instance_init = npcm7xx_gcr_init,
131
static void imx_epit_write_cr(IMXEPITState *s, uint32_t value)
348
+ .class_init = npcm7xx_gcr_class_init,
132
{
349
+};
133
+ uint32_t freq = 0;
350
+
134
uint32_t oldcr = s->cr;
351
+static void npcm7xx_gcr_register_type(void)
135
352
+{
136
s->cr = value & 0x03ffffff;
353
+ type_register_static(&npcm7xx_gcr_info);
137
@@ -XXX,XX +XXX,XX @@ static void imx_epit_write_cr(IMXEPITState *s, uint32_t value)
354
+}
138
ptimer_transaction_begin(s->timer_cmp);
355
+type_init(npcm7xx_gcr_register_type);
139
ptimer_transaction_begin(s->timer_reload);
356
diff --git a/MAINTAINERS b/MAINTAINERS
140
357
index XXXXXXX..XXXXXXX 100644
141
- /* Update the frequency. Has been done already in case of a reset. */
358
--- a/MAINTAINERS
142
+ /*
359
+++ b/MAINTAINERS
143
+ * Update the frequency. In case of a reset the input clock was
360
@@ -XXX,XX +XXX,XX @@ S: Odd Fixes
144
+ * switched off, so this can be skipped.
361
F: hw/arm/musicpal.c
145
+ */
362
F: docs/system/arm/musicpal.rst
146
if (!(s->cr & CR_SWR)) {
363
147
- imx_epit_set_freq(s);
364
+Nuvoton NPCM7xx
148
+ freq = imx_epit_get_freq(s);
365
+M: Havard Skinnemoen <hskinnemoen@google.com>
149
+ if (freq) {
366
+M: Tyrone Ting <kfting@nuvoton.com>
150
+ ptimer_set_freq(s->timer_reload, freq);
367
+L: qemu-arm@nongnu.org
151
+ ptimer_set_freq(s->timer_cmp, freq);
368
+S: Supported
152
+ }
369
+F: hw/*/npcm7xx*
153
}
370
+F: include/hw/*/npcm7xx*
154
371
+
155
- if (s->freq && (s->cr & CR_EN) && !(oldcr & CR_EN)) {
372
nSeries
156
+ if (freq && (s->cr & CR_EN) && !(oldcr & CR_EN)) {
373
M: Andrzej Zaborowski <balrogg@gmail.com>
157
if (s->cr & CR_ENMOD) {
374
M: Peter Maydell <peter.maydell@linaro.org>
158
if (s->cr & CR_RLD) {
375
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
159
ptimer_set_limit(s->timer_reload, s->lr, 1);
376
index XXXXXXX..XXXXXXX 100644
160
@@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps imx_epit_ops = {
377
--- a/hw/arm/Kconfig
161
378
+++ b/hw/arm/Kconfig
162
static const VMStateDescription vmstate_imx_timer_epit = {
379
@@ -XXX,XX +XXX,XX @@ config XLNX_VERSAL
163
.name = TYPE_IMX_EPIT,
380
select VIRTIO_MMIO
164
- .version_id = 2,
381
select UNIMP
165
- .minimum_version_id = 2,
382
166
+ .version_id = 3,
383
+config NPCM7XX
167
+ .minimum_version_id = 3,
384
+ bool
168
.fields = (VMStateField[]) {
385
+
169
VMSTATE_UINT32(cr, IMXEPITState),
386
config FSL_IMX25
170
VMSTATE_UINT32(sr, IMXEPITState),
387
bool
171
VMSTATE_UINT32(lr, IMXEPITState),
388
select IMX
172
VMSTATE_UINT32(cmp, IMXEPITState),
389
diff --git a/hw/misc/meson.build b/hw/misc/meson.build
173
- VMSTATE_UINT32(cnt, IMXEPITState),
390
index XXXXXXX..XXXXXXX 100644
174
- VMSTATE_UINT32(freq, IMXEPITState),
391
--- a/hw/misc/meson.build
175
VMSTATE_PTIMER(timer_reload, IMXEPITState),
392
+++ b/hw/misc/meson.build
176
VMSTATE_PTIMER(timer_cmp, IMXEPITState),
393
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_IMX', if_true: files(
177
VMSTATE_END_OF_LIST()
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
--
178
--
419
2.20.1
179
2.25.1
420
421
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Axel Heider <axel.heider@hensoldt.net>
2
2
3
Enough functionality to boot the Linux kernel has been implemented. This
3
- fix #1263 for CR writes
4
includes:
4
- rework compare time handling
5
- The compare timer has to run even if CR.OCIEN is not set,
6
as SR.OCIF must be updated.
7
- The compare timer fires exactly once when the
8
compare value is less than the current value, but the
9
reload values is less than the compare value.
10
- The compare timer will never fire if the reload value is
11
less than the compare value. Disable it in this case.
5
12
6
- Correct power-on reset values so the various clock rates can be
13
Signed-off-by: Axel Heider <axel.heider@hensoldt.net>
7
accurately calculated.
14
[PMM: fixed minor style nits]
8
- Clock enables stick around when written.
15
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
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>
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
22
---
17
---
23
include/hw/misc/npcm7xx_clk.h | 48 ++++++
18
hw/timer/imx_epit.c | 192 ++++++++++++++++++++++++++------------------
24
hw/misc/npcm7xx_clk.c | 266 ++++++++++++++++++++++++++++++++++
19
1 file changed, 116 insertions(+), 76 deletions(-)
25
hw/misc/meson.build | 1 +
26
hw/misc/trace-events | 4 +
27
4 files changed, 319 insertions(+)
28
create mode 100644 include/hw/misc/npcm7xx_clk.h
29
create mode 100644 hw/misc/npcm7xx_clk.c
30
20
31
diff --git a/include/hw/misc/npcm7xx_clk.h b/include/hw/misc/npcm7xx_clk.h
21
diff --git a/hw/timer/imx_epit.c b/hw/timer/imx_epit.c
32
new file mode 100644
22
index XXXXXXX..XXXXXXX 100644
33
index XXXXXXX..XXXXXXX
23
--- a/hw/timer/imx_epit.c
34
--- /dev/null
24
+++ b/hw/timer/imx_epit.c
35
+++ b/include/hw/misc/npcm7xx_clk.h
36
@@ -XXX,XX +XXX,XX @@
25
@@ -XXX,XX +XXX,XX @@
26
* Originally written by Hans Jiang
27
* Updated by Peter Chubb
28
* Updated by Jean-Christophe Dubois <jcd@tribudubois.net>
29
+ * Updated by Axel Heider
30
*
31
* This code is licensed under GPL version 2 or later. See
32
* the COPYING file in the top-level directory.
33
@@ -XXX,XX +XXX,XX @@ static uint64_t imx_epit_read(void *opaque, hwaddr offset, unsigned size)
34
return reg_value;
35
}
36
37
-/* Must be called from ptimer_transaction_begin/commit block for s->timer_cmp */
38
-static void imx_epit_reload_compare_timer(IMXEPITState *s)
37
+/*
39
+/*
38
+ * Nuvoton NPCM7xx Clock Control Registers.
40
+ * Must be called from a ptimer_transaction_begin/commit block for
39
+ *
41
+ * s->timer_cmp, but outside of a transaction block of s->timer_reload,
40
+ * Copyright 2020 Google LLC
42
+ * so the proper counter value is read.
41
+ *
42
+ * 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
44
+ * Free Software Foundation; either version 2 of the License, or
45
+ * (at your option) any later version.
46
+ *
47
+ * 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
49
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
50
+ * for more details.
51
+ */
43
+ */
52
+#ifndef NPCM7XX_CLK_H
44
+static void imx_epit_update_compare_timer(IMXEPITState *s)
53
+#define NPCM7XX_CLK_H
45
{
54
+
46
- if ((s->cr & (CR_EN | CR_OCIEN)) == (CR_EN | CR_OCIEN)) {
55
+#include "exec/memory.h"
47
- /* if the compare feature is on and timers are running */
56
+#include "hw/sysbus.h"
48
- uint32_t tmp = ptimer_get_count(s->timer_reload);
57
+
49
- uint64_t next;
58
+/*
50
- if (tmp > s->cmp) {
59
+ * The reference clock frequency for the timer modules, and the SECCNT and
51
- /* It'll fire in this round of the timer */
60
+ * CNTR25M registers in this module, is always 25 MHz.
52
- next = tmp - s->cmp;
61
+ */
53
- } else { /* catch it next time around */
62
+#define NPCM7XX_TIMER_REF_HZ (25000000)
54
- next = tmp - s->cmp + ((s->cr & CR_RLD) ? EPIT_TIMER_MAX : s->lr);
63
+
55
+ uint64_t counter = 0;
64
+/*
56
+ bool is_oneshot = false;
65
+ * Number of registers in our device state structure. Don't change this without
57
+ /*
66
+ * incrementing the version_id in the vmstate.
58
+ * The compare timer only has to run if the timer peripheral is active
67
+ */
59
+ * and there is an input clock, Otherwise it can be switched off.
68
+#define NPCM7XX_CLK_NR_REGS (0x70 / sizeof(uint32_t))
60
+ */
69
+
61
+ bool is_active = (s->cr & CR_EN) && imx_epit_get_freq(s);
70
+typedef struct NPCM7xxCLKState {
62
+ if (is_active) {
71
+ SysBusDevice parent;
63
+ /*
72
+
64
+ * Calculate next timeout for compare timer. Reading the reload
73
+ MemoryRegion iomem;
65
+ * counter returns proper results only if pending transactions
74
+
66
+ * on it are committed here. Otherwise stale values are be read.
75
+ uint32_t regs[NPCM7XX_CLK_NR_REGS];
67
+ */
76
+
68
+ counter = ptimer_get_count(s->timer_reload);
77
+ /* Time reference for SECCNT and CNTR25M, initialized by power on reset */
69
+ uint64_t limit = ptimer_get_limit(s->timer_cmp);
78
+ int64_t ref_ns;
70
+ /*
79
+} NPCM7xxCLKState;
71
+ * The compare timer is a periodic timer if the limit is at least
80
+
72
+ * the compare value. Otherwise it may fire at most once in the
81
+#define TYPE_NPCM7XX_CLK "npcm7xx-clk"
73
+ * current round.
82
+#define NPCM7XX_CLK(obj) OBJECT_CHECK(NPCM7xxCLKState, (obj), TYPE_NPCM7XX_CLK)
74
+ */
83
+
75
+ bool is_oneshot = (limit >= s->cmp);
84
+#endif /* NPCM7XX_CLK_H */
76
+ if (counter >= s->cmp) {
85
diff --git a/hw/misc/npcm7xx_clk.c b/hw/misc/npcm7xx_clk.c
77
+ /* The compare timer fires in the current round. */
86
new file mode 100644
78
+ counter -= s->cmp;
87
index XXXXXXX..XXXXXXX
79
+ } else if (!is_oneshot) {
88
--- /dev/null
80
+ /*
89
+++ b/hw/misc/npcm7xx_clk.c
81
+ * The compare timer fires after a reload, as it is below the
90
@@ -XXX,XX +XXX,XX @@
82
+ * compare value already in this round. Note that the counter
91
+/*
83
+ * value calculated below can be above the 32-bit limit, which
92
+ * Nuvoton NPCM7xx Clock Control Registers.
84
+ * is legal here because the compare timer is an internal
93
+ *
85
+ * helper ptimer only.
94
+ * Copyright 2020 Google LLC
86
+ */
95
+ *
87
+ counter += limit - s->cmp;
96
+ * This program is free software; you can redistribute it and/or modify it
88
+ } else {
97
+ * under the terms of the GNU General Public License as published by the
89
+ /*
98
+ * Free Software Foundation; either version 2 of the License, or
90
+ * The compare timer won't fire in this round, and the limit is
99
+ * (at your option) any later version.
91
+ * set to a value below the compare value. This practically means
100
+ *
92
+ * it will never fire, so it can be switched off.
101
+ * This program is distributed in the hope that it will be useful, but WITHOUT
93
+ */
102
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
94
+ is_active = false;
103
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
95
}
104
+ * for more details.
96
- ptimer_set_count(s->timer_cmp, next);
105
+ */
97
}
106
+
98
+
107
+#include "qemu/osdep.h"
99
+ /*
108
+
100
+ * Set the compare timer and let it run, or stop it. This is agnostic
109
+#include "hw/misc/npcm7xx_clk.h"
101
+ * of CR.OCIEN bit, as this bit affects interrupt generation only. The
110
+#include "migration/vmstate.h"
102
+ * compare timer needs to run even if no interrupts are to be generated,
111
+#include "qemu/error-report.h"
103
+ * because the SR.OCIF bit must be updated also.
112
+#include "qemu/log.h"
104
+ * Note that the timer might already be stopped or be running with
113
+#include "qemu/module.h"
105
+ * counter values. However, finding out when an update is needed and
114
+#include "qemu/timer.h"
106
+ * when not is not trivial. It's much easier applying the setting again,
115
+#include "qemu/units.h"
107
+ * as this does not harm either and the overhead is negligible.
116
+#include "trace.h"
108
+ */
117
+
109
+ if (is_active) {
118
+#define PLLCON_LOKI BIT(31)
110
+ ptimer_set_count(s->timer_cmp, counter);
119
+#define PLLCON_LOKS BIT(30)
111
+ ptimer_run(s->timer_cmp, is_oneshot ? 1 : 0);
120
+#define PLLCON_PWDEN BIT(12)
112
+ } else {
121
+
113
+ ptimer_stop(s->timer_cmp);
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
+
152
+/*
153
+ * These reset values were taken from version 0.91 of the NPCM750R data sheet.
154
+ *
155
+ * All are loaded on power-up reset. CLKENx and SWRSTR should also be loaded on
156
+ * core domain reset, but this reset type is not yet supported by QEMU.
157
+ */
158
+static const uint32_t cold_reset_values[NPCM7XX_CLK_NR_REGS] = {
159
+ [NPCM7XX_CLK_CLKEN1] = 0xffffffff,
160
+ [NPCM7XX_CLK_CLKSEL] = 0x004aaaaa,
161
+ [NPCM7XX_CLK_CLKDIV1] = 0x5413f855,
162
+ [NPCM7XX_CLK_PLLCON0] = 0x00222101 | PLLCON_LOKI,
163
+ [NPCM7XX_CLK_PLLCON1] = 0x00202101 | PLLCON_LOKI,
164
+ [NPCM7XX_CLK_IPSRST1] = 0x00001000,
165
+ [NPCM7XX_CLK_IPSRST2] = 0x80000000,
166
+ [NPCM7XX_CLK_CLKEN2] = 0xffffffff,
167
+ [NPCM7XX_CLK_CLKDIV2] = 0xaa4f8f9f,
168
+ [NPCM7XX_CLK_CLKEN3] = 0xffffffff,
169
+ [NPCM7XX_CLK_IPSRST3] = 0x03000000,
170
+ [NPCM7XX_CLK_WD0RCR] = 0xffffffff,
171
+ [NPCM7XX_CLK_WD1RCR] = 0xffffffff,
172
+ [NPCM7XX_CLK_WD2RCR] = 0xffffffff,
173
+ [NPCM7XX_CLK_SWRSTC1] = 0x00000003,
174
+ [NPCM7XX_CLK_PLLCON2] = 0x00c02105 | PLLCON_LOKI,
175
+ [NPCM7XX_CLK_CORSTC] = 0x04000003,
176
+ [NPCM7XX_CLK_PLLCONG] = 0x01228606 | PLLCON_LOKI,
177
+ [NPCM7XX_CLK_AHBCKFI] = 0x000000c8,
178
+};
179
+
180
+static uint64_t npcm7xx_clk_read(void *opaque, hwaddr offset, unsigned size)
181
+{
182
+ uint32_t reg = offset / sizeof(uint32_t);
183
+ NPCM7xxCLKState *s = opaque;
184
+ int64_t now_ns;
185
+ uint32_t value = 0;
186
+
187
+ if (reg >= NPCM7XX_CLK_NR_REGS) {
188
+ qemu_log_mask(LOG_GUEST_ERROR,
189
+ "%s: offset 0x%04" HWADDR_PRIx " out of range\n",
190
+ __func__, offset);
191
+ return 0;
192
+ }
114
+ }
193
+
115
+
194
+ switch (reg) {
116
}
195
+ case NPCM7XX_CLK_SWRSTR:
117
196
+ qemu_log_mask(LOG_GUEST_ERROR,
118
static void imx_epit_write_cr(IMXEPITState *s, uint32_t value)
197
+ "%s: register @ 0x%04" HWADDR_PRIx " is write-only\n",
119
{
198
+ __func__, offset);
120
- uint32_t freq = 0;
199
+ break;
121
uint32_t oldcr = s->cr;
200
+
122
201
+ case NPCM7XX_CLK_SECCNT:
123
s->cr = value & 0x03ffffff;
202
+ now_ns = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
124
203
+ value = (now_ns - s->ref_ns) / NANOSECONDS_PER_SECOND;
125
if (s->cr & CR_SWR) {
204
+ break;
126
- /* handle the reset */
205
+
127
+ /*
206
+ case NPCM7XX_CLK_CNTR25M:
128
+ * Reset clears CR.SWR again. It does not touch CR.EN, but the timers
207
+ now_ns = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
129
+ * are still stopped because the input clock is disabled.
208
+ /*
130
+ */
209
+ * This register counts 25 MHz cycles, updating every 640 ns. It rolls
131
imx_epit_reset(s, false);
210
+ * over to zero every second.
132
+ } else {
211
+ *
133
+ uint32_t freq;
212
+ * The 4 LSBs are always zero: (1e9 / 640) << 4 = 25000000.
134
+ uint32_t toggled_cr_bits = oldcr ^ s->cr;
213
+ */
135
+ /* re-initialize the limits if CR.RLD has changed */
214
+ value = (((now_ns - s->ref_ns) / 640) << 4) % NPCM7XX_TIMER_REF_HZ;
136
+ bool set_limit = toggled_cr_bits & CR_RLD;
215
+ break;
137
+ /* set the counter if the timer got just enabled and CR.ENMOD is set */
216
+
138
+ bool is_switched_on = (toggled_cr_bits & s->cr) & CR_EN;
217
+ default:
139
+ bool set_counter = is_switched_on && (s->cr & CR_ENMOD);
218
+ value = s->regs[reg];
140
+
219
+ break;
141
+ ptimer_transaction_begin(s->timer_cmp);
220
+ };
142
+ ptimer_transaction_begin(s->timer_reload);
221
+
143
+ freq = imx_epit_get_freq(s);
222
+ trace_npcm7xx_clk_read(offset, value);
144
+ if (freq) {
223
+
145
+ ptimer_set_freq(s->timer_reload, freq);
224
+ return value;
146
+ ptimer_set_freq(s->timer_cmp, freq);
225
+}
147
+ }
226
+
148
+
227
+static void npcm7xx_clk_write(void *opaque, hwaddr offset,
149
+ if (set_limit || set_counter) {
228
+ uint64_t v, unsigned size)
150
+ uint64_t limit = (s->cr & CR_RLD) ? s->lr : EPIT_TIMER_MAX;
229
+{
151
+ ptimer_set_limit(s->timer_reload, limit, set_counter ? 1 : 0);
230
+ uint32_t reg = offset / sizeof(uint32_t);
152
+ if (set_limit) {
231
+ NPCM7xxCLKState *s = opaque;
153
+ ptimer_set_limit(s->timer_cmp, limit, 0);
232
+ uint32_t value = v;
233
+
234
+ trace_npcm7xx_clk_write(offset, value);
235
+
236
+ if (reg >= NPCM7XX_CLK_NR_REGS) {
237
+ qemu_log_mask(LOG_GUEST_ERROR,
238
+ "%s: offset 0x%04" HWADDR_PRIx " out of range\n",
239
+ __func__, offset);
240
+ return;
241
+ }
242
+
243
+ switch (reg) {
244
+ case NPCM7XX_CLK_SWRSTR:
245
+ qemu_log_mask(LOG_UNIMP, "%s: SW reset not implemented: 0x%02x\n",
246
+ __func__, value);
247
+ value = 0;
248
+ break;
249
+
250
+ case NPCM7XX_CLK_PLLCON0:
251
+ case NPCM7XX_CLK_PLLCON1:
252
+ case NPCM7XX_CLK_PLLCON2:
253
+ case NPCM7XX_CLK_PLLCONG:
254
+ if (value & PLLCON_PWDEN) {
255
+ /* Power down -- clear lock and indicate loss of lock */
256
+ value &= ~PLLCON_LOKI;
257
+ value |= PLLCON_LOKS;
258
+ } else {
259
+ /* Normal mode -- assume always locked */
260
+ value |= PLLCON_LOKI;
261
+ /* Keep LOKS unchanged unless cleared by writing 1 */
262
+ if (value & PLLCON_LOKS) {
263
+ value &= ~PLLCON_LOKS;
264
+ } else {
265
+ value |= (value & PLLCON_LOKS);
266
+ }
154
+ }
267
+ }
155
+ }
268
+ break;
156
+ /*
269
+
157
+ * If there is an input clock and the peripheral is enabled, then
270
+ case NPCM7XX_CLK_CNTR25M:
158
+ * ensure the wall clock timer is ticking. Otherwise stop the timers.
271
+ qemu_log_mask(LOG_GUEST_ERROR,
159
+ * The compare timer will be updated later.
272
+ "%s: register @ 0x%04" HWADDR_PRIx " is read-only\n",
160
+ */
273
+ __func__, offset);
161
+ if (freq && (s->cr & CR_EN)) {
274
+ return;
162
+ ptimer_run(s->timer_reload, 0);
275
+ }
163
+ } else {
276
+
164
+ ptimer_stop(s->timer_reload);
277
+ s->regs[reg] = value;
165
+ }
278
+}
166
+ /* Commit changes to reload timer, so they can propagate. */
279
+
167
+ ptimer_transaction_commit(s->timer_reload);
280
+static const struct MemoryRegionOps npcm7xx_clk_ops = {
168
+ /* Update compare timer based on the committed reload timer value. */
281
+ .read = npcm7xx_clk_read,
169
+ imx_epit_update_compare_timer(s);
282
+ .write = npcm7xx_clk_write,
170
+ ptimer_transaction_commit(s->timer_cmp);
283
+ .endianness = DEVICE_LITTLE_ENDIAN,
171
}
284
+ .valid = {
172
285
+ .min_access_size = 4,
173
/*
286
+ .max_access_size = 4,
174
@@ -XXX,XX +XXX,XX @@ static void imx_epit_write_cr(IMXEPITState *s, uint32_t value)
287
+ .unaligned = false,
175
* - write to CR.EN or CR.OCIE
288
+ },
176
*/
289
+};
177
imx_epit_update_int(s);
290
+
178
-
291
+static void npcm7xx_clk_enter_reset(Object *obj, ResetType type)
179
- /*
292
+{
180
- * TODO: could we 'break' here for reset? following operations appear
293
+ NPCM7xxCLKState *s = NPCM7XX_CLK(obj);
181
- * to duplicate the work imx_epit_reset() already did.
294
+
182
- */
295
+ QEMU_BUILD_BUG_ON(sizeof(s->regs) != sizeof(cold_reset_values));
183
-
296
+
184
- ptimer_transaction_begin(s->timer_cmp);
297
+ switch (type) {
185
- ptimer_transaction_begin(s->timer_reload);
298
+ case RESET_TYPE_COLD:
186
-
299
+ memcpy(s->regs, cold_reset_values, sizeof(cold_reset_values));
187
- /*
300
+ s->ref_ns = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
188
- * Update the frequency. In case of a reset the input clock was
301
+ return;
189
- * switched off, so this can be skipped.
302
+ }
190
- */
303
+
191
- if (!(s->cr & CR_SWR)) {
304
+ /*
192
- freq = imx_epit_get_freq(s);
305
+ * A small number of registers need to be reset on a core domain reset,
193
- if (freq) {
306
+ * but no such reset type exists yet.
194
- ptimer_set_freq(s->timer_reload, freq);
307
+ */
195
- ptimer_set_freq(s->timer_cmp, freq);
308
+ qemu_log_mask(LOG_UNIMP, "%s: reset type %d not implemented.",
196
- }
309
+ __func__, type);
197
- }
310
+}
198
-
311
+
199
- if (freq && (s->cr & CR_EN) && !(oldcr & CR_EN)) {
312
+static void npcm7xx_clk_init(Object *obj)
200
- if (s->cr & CR_ENMOD) {
313
+{
201
- if (s->cr & CR_RLD) {
314
+ NPCM7xxCLKState *s = NPCM7XX_CLK(obj);
202
- ptimer_set_limit(s->timer_reload, s->lr, 1);
315
+
203
- ptimer_set_limit(s->timer_cmp, s->lr, 1);
316
+ memory_region_init_io(&s->iomem, obj, &npcm7xx_clk_ops, s,
204
- } else {
317
+ TYPE_NPCM7XX_CLK, 4 * KiB);
205
- ptimer_set_limit(s->timer_reload, EPIT_TIMER_MAX, 1);
318
+ sysbus_init_mmio(&s->parent, &s->iomem);
206
- ptimer_set_limit(s->timer_cmp, EPIT_TIMER_MAX, 1);
319
+}
207
- }
320
+
208
- }
321
+static const VMStateDescription vmstate_npcm7xx_clk = {
209
-
322
+ .name = "npcm7xx-clk",
210
- imx_epit_reload_compare_timer(s);
323
+ .version_id = 0,
211
- ptimer_run(s->timer_reload, 0);
324
+ .minimum_version_id = 0,
212
- if (s->cr & CR_OCIEN) {
325
+ .fields = (VMStateField[]) {
213
- ptimer_run(s->timer_cmp, 0);
326
+ VMSTATE_UINT32_ARRAY(regs, NPCM7xxCLKState, NPCM7XX_CLK_NR_REGS),
214
- } else {
327
+ VMSTATE_INT64(ref_ns, NPCM7xxCLKState),
215
- ptimer_stop(s->timer_cmp);
328
+ VMSTATE_END_OF_LIST(),
216
- }
329
+ },
217
- } else if (!(s->cr & CR_EN)) {
330
+};
218
- /* stop both timers */
331
+
219
- ptimer_stop(s->timer_reload);
332
+static void npcm7xx_clk_class_init(ObjectClass *klass, void *data)
220
- ptimer_stop(s->timer_cmp);
333
+{
221
- } else if (s->cr & CR_OCIEN) {
334
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
222
- if (!(oldcr & CR_OCIEN)) {
335
+ DeviceClass *dc = DEVICE_CLASS(klass);
223
- imx_epit_reload_compare_timer(s);
336
+
224
- ptimer_run(s->timer_cmp, 0);
337
+ QEMU_BUILD_BUG_ON(NPCM7XX_CLK_REGS_END > NPCM7XX_CLK_NR_REGS);
225
- }
338
+
226
- } else {
339
+ dc->desc = "NPCM7xx Clock Control Registers";
227
- ptimer_stop(s->timer_cmp);
340
+ dc->vmsd = &vmstate_npcm7xx_clk;
228
- }
341
+ rc->phases.enter = npcm7xx_clk_enter_reset;
229
-
342
+}
230
- ptimer_transaction_commit(s->timer_cmp);
343
+
231
- ptimer_transaction_commit(s->timer_reload);
344
+static const TypeInfo npcm7xx_clk_info = {
232
}
345
+ .name = TYPE_NPCM7XX_CLK,
233
346
+ .parent = TYPE_SYS_BUS_DEVICE,
234
static void imx_epit_write_sr(IMXEPITState *s, uint32_t value)
347
+ .instance_size = sizeof(NPCM7xxCLKState),
235
@@ -XXX,XX +XXX,XX @@ static void imx_epit_write_lr(IMXEPITState *s, uint32_t value)
348
+ .instance_init = npcm7xx_clk_init,
236
/* If IOVW bit is set then set the timer value */
349
+ .class_init = npcm7xx_clk_class_init,
237
ptimer_set_count(s->timer_reload, s->lr);
350
+};
238
}
351
+
239
- /*
352
+static void npcm7xx_clk_register_type(void)
240
- * Commit the change to s->timer_reload, so it can propagate. Otherwise
353
+{
241
- * the timer interrupt may not fire properly. The commit must happen
354
+ type_register_static(&npcm7xx_clk_info);
242
- * before calling imx_epit_reload_compare_timer(), which reads
355
+}
243
- * s->timer_reload internally again.
356
+type_init(npcm7xx_clk_register_type);
244
- */
357
diff --git a/hw/misc/meson.build b/hw/misc/meson.build
245
+ /* Commit the changes to s->timer_reload, so they can propagate. */
358
index XXXXXXX..XXXXXXX 100644
246
ptimer_transaction_commit(s->timer_reload);
359
--- a/hw/misc/meson.build
247
- imx_epit_reload_compare_timer(s);
360
+++ b/hw/misc/meson.build
248
+ /* Update the compare timer based on the committed reload timer value. */
361
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_IMX', if_true: files(
249
+ imx_epit_update_compare_timer(s);
362
softmmu_ss.add(when: 'CONFIG_MILKYMIST', if_true: files('milkymist-hpdmc.c', 'milkymist-pfpu.c'))
250
ptimer_transaction_commit(s->timer_cmp);
363
softmmu_ss.add(when: 'CONFIG_MAINSTONE', if_true: files('mst_fpga.c'))
251
}
364
softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files(
252
365
+ 'npcm7xx_clk.c',
253
@@ -XXX,XX +XXX,XX @@ static void imx_epit_write_cmp(IMXEPITState *s, uint32_t value)
366
'npcm7xx_gcr.c',
254
{
367
))
255
s->cmp = value;
368
softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files(
256
369
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
257
+ /* Update the compare timer based on the committed reload timer value. */
370
index XXXXXXX..XXXXXXX 100644
258
ptimer_transaction_begin(s->timer_cmp);
371
--- a/hw/misc/trace-events
259
- imx_epit_reload_compare_timer(s);
372
+++ b/hw/misc/trace-events
260
+ imx_epit_update_compare_timer(s);
373
@@ -XXX,XX +XXX,XX @@ mos6522_set_sr_int(void) "set sr_int"
261
ptimer_transaction_commit(s->timer_cmp);
374
mos6522_write(uint64_t addr, uint64_t val) "reg=0x%"PRIx64 " val=0x%"PRIx64
262
}
375
mos6522_read(uint64_t addr, unsigned val) "reg=0x%"PRIx64 " val=0x%x"
263
376
264
@@ -XXX,XX +XXX,XX @@ static void imx_epit_cmp(void *opaque)
377
+# npcm7xx_clk.c
265
{
378
+npcm7xx_clk_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
266
IMXEPITState *s = IMX_EPIT(opaque);
379
+npcm7xx_clk_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
267
380
+
268
+ /* The cmp ptimer can't be running when the peripheral is disabled */
381
# npcm7xx_gcr.c
269
+ assert(s->cr & CR_EN);
382
npcm7xx_gcr_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
270
+
383
npcm7xx_gcr_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
271
DPRINTF("sr was %d\n", s->sr);
272
/* Set interrupt status bit SR.OCIF and update the interrupt state */
273
s->sr |= SR_OCIF;
384
--
274
--
385
2.20.1
275
2.25.1
386
387
diff view generated by jsdifflib
1
From: Aaron Lindsay <aaron@os.amperecomputing.com>
1
From: Fabiano Rosas <farosas@suse.de>
2
2
3
This check was backwards when introduced in commit
3
Fix these:
4
033614c47de78409ad3fb39bb7bd1483b71c6789:
5
4
6
target/arm: Filter cycle counter based on PMCCFILTR_EL0
5
WARNING: Block comments use a leading /* on a separate line
6
WARNING: Block comments use * on subsequent lines
7
WARNING: Block comments use a trailing */ on a separate line
7
8
8
Cc: qemu-stable@nongnu.org
9
Signed-off-by: Fabiano Rosas <farosas@suse.de>
9
Signed-off-by: Aaron Lindsay <aaron@os.amperecomputing.com>
10
Reviewed-by: Claudio Fontana <cfontana@suse.de>
10
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
12
Message-id: 20221213190537.511-2-farosas@suse.de
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
14
---
13
target/arm/helper.c | 2 +-
15
target/arm/helper.c | 323 +++++++++++++++++++++++++++++---------------
14
1 file changed, 1 insertion(+), 1 deletion(-)
16
1 file changed, 215 insertions(+), 108 deletions(-)
15
17
16
diff --git a/target/arm/helper.c b/target/arm/helper.c
18
diff --git a/target/arm/helper.c b/target/arm/helper.c
17
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
18
--- a/target/arm/helper.c
20
--- a/target/arm/helper.c
19
+++ b/target/arm/helper.c
21
+++ b/target/arm/helper.c
20
@@ -XXX,XX +XXX,XX @@ static bool pmu_counter_enabled(CPUARMState *env, uint8_t counter)
22
@@ -XXX,XX +XXX,XX @@ uint64_t read_raw_cp_reg(CPUARMState *env, const ARMCPRegInfo *ri)
23
static void write_raw_cp_reg(CPUARMState *env, const ARMCPRegInfo *ri,
24
uint64_t v)
25
{
26
- /* Raw write of a coprocessor register (as needed for migration, etc).
27
+ /*
28
+ * Raw write of a coprocessor register (as needed for migration, etc).
29
* Note that constant registers are treated as write-ignored; the
30
* caller should check for success by whether a readback gives the
31
* value written.
32
@@ -XXX,XX +XXX,XX @@ static void write_raw_cp_reg(CPUARMState *env, const ARMCPRegInfo *ri,
33
34
static bool raw_accessors_invalid(const ARMCPRegInfo *ri)
35
{
36
- /* Return true if the regdef would cause an assertion if you called
37
+ /*
38
+ * Return true if the regdef would cause an assertion if you called
39
* read_raw_cp_reg() or write_raw_cp_reg() on it (ie if it is a
40
* program bug for it not to have the NO_RAW flag).
41
* NB that returning false here doesn't necessarily mean that calling
42
@@ -XXX,XX +XXX,XX @@ bool write_list_to_cpustate(ARMCPU *cpu)
43
if (ri->type & ARM_CP_NO_RAW) {
44
continue;
45
}
46
- /* Write value and confirm it reads back as written
47
+ /*
48
+ * Write value and confirm it reads back as written
49
* (to catch read-only registers and partially read-only
50
* registers where the incoming migration value doesn't match)
51
*/
52
@@ -XXX,XX +XXX,XX @@ static gint cpreg_key_compare(gconstpointer a, gconstpointer b)
53
54
void init_cpreg_list(ARMCPU *cpu)
55
{
56
- /* Initialise the cpreg_tuples[] array based on the cp_regs hash.
57
+ /*
58
+ * Initialise the cpreg_tuples[] array based on the cp_regs hash.
59
* Note that we require cpreg_tuples[] to be sorted by key ID.
60
*/
61
GList *keys;
62
@@ -XXX,XX +XXX,XX @@ static CPAccessResult access_el3_aa32ns(CPUARMState *env,
63
return CP_ACCESS_OK;
64
}
65
66
-/* Some secure-only AArch32 registers trap to EL3 if used from
67
+/*
68
+ * Some secure-only AArch32 registers trap to EL3 if used from
69
* Secure EL1 (but are just ordinary UNDEF in other non-EL3 contexts).
70
* Note that an access from Secure EL1 can only happen if EL3 is AArch64.
71
* We assume that the .access field is set to PL1_RW.
72
@@ -XXX,XX +XXX,XX @@ static CPAccessResult access_trap_aa32s_el1(CPUARMState *env,
73
return CP_ACCESS_TRAP_UNCATEGORIZED;
74
}
75
76
-/* Check for traps to performance monitor registers, which are controlled
77
+/*
78
+ * Check for traps to performance monitor registers, which are controlled
79
* by MDCR_EL2.TPM for EL2 and MDCR_EL3.TPM for EL3.
80
*/
81
static CPAccessResult access_tpm(CPUARMState *env, const ARMCPRegInfo *ri,
82
@@ -XXX,XX +XXX,XX @@ static void fcse_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value)
83
ARMCPU *cpu = env_archcpu(env);
84
85
if (raw_read(env, ri) != value) {
86
- /* Unlike real hardware the qemu TLB uses virtual addresses,
87
+ /*
88
+ * Unlike real hardware the qemu TLB uses virtual addresses,
89
* not modified virtual addresses, so this causes a TLB flush.
90
*/
91
tlb_flush(CPU(cpu));
92
@@ -XXX,XX +XXX,XX @@ static void contextidr_write(CPUARMState *env, const ARMCPRegInfo *ri,
93
94
if (raw_read(env, ri) != value && !arm_feature(env, ARM_FEATURE_PMSA)
95
&& !extended_addresses_enabled(env)) {
96
- /* For VMSA (when not using the LPAE long descriptor page table
97
+ /*
98
+ * For VMSA (when not using the LPAE long descriptor page table
99
* format) this register includes the ASID, so do a TLB flush.
100
* For PMSA it is purely a process ID and no action is needed.
101
*/
102
@@ -XXX,XX +XXX,XX @@ static void tlbiipas2is_hyp_write(CPUARMState *env, const ARMCPRegInfo *ri,
103
}
104
105
static const ARMCPRegInfo cp_reginfo[] = {
106
- /* Define the secure and non-secure FCSE identifier CP registers
107
+ /*
108
+ * Define the secure and non-secure FCSE identifier CP registers
109
* separately because there is no secure bank in V8 (no _EL3). This allows
110
* the secure register to be properly reset and migrated. There is also no
111
* v8 EL1 version of the register so the non-secure instance stands alone.
112
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo cp_reginfo[] = {
113
.access = PL1_RW, .secure = ARM_CP_SECSTATE_S,
114
.fieldoffset = offsetof(CPUARMState, cp15.fcseidr_s),
115
.resetvalue = 0, .writefn = fcse_write, .raw_writefn = raw_write, },
116
- /* Define the secure and non-secure context identifier CP registers
117
+ /*
118
+ * Define the secure and non-secure context identifier CP registers
119
* separately because there is no secure bank in V8 (no _EL3). This allows
120
* the secure register to be properly reset and migrated. In the
121
* non-secure case, the 32-bit register will have reset and migration
122
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo cp_reginfo[] = {
123
};
124
125
static const ARMCPRegInfo not_v8_cp_reginfo[] = {
126
- /* NB: Some of these registers exist in v8 but with more precise
127
+ /*
128
+ * NB: Some of these registers exist in v8 but with more precise
129
* definitions that don't use CP_ANY wildcards (mostly in v8_cp_reginfo[]).
130
*/
131
/* MMU Domain access control / MPU write buffer control */
132
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo not_v8_cp_reginfo[] = {
133
.writefn = dacr_write, .raw_writefn = raw_write,
134
.bank_fieldoffsets = { offsetoflow32(CPUARMState, cp15.dacr_s),
135
offsetoflow32(CPUARMState, cp15.dacr_ns) } },
136
- /* ARMv7 allocates a range of implementation defined TLB LOCKDOWN regs.
137
+ /*
138
+ * ARMv7 allocates a range of implementation defined TLB LOCKDOWN regs.
139
* For v6 and v5, these mappings are overly broad.
140
*/
141
{ .name = "TLB_LOCKDOWN", .cp = 15, .crn = 10, .crm = 0,
142
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo not_v8_cp_reginfo[] = {
143
};
144
145
static const ARMCPRegInfo not_v6_cp_reginfo[] = {
146
- /* Not all pre-v6 cores implemented this WFI, so this is slightly
147
+ /*
148
+ * Not all pre-v6 cores implemented this WFI, so this is slightly
149
* over-broad.
150
*/
151
{ .name = "WFI_v5", .cp = 15, .crn = 7, .crm = 8, .opc1 = 0, .opc2 = 2,
152
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo not_v6_cp_reginfo[] = {
153
};
154
155
static const ARMCPRegInfo not_v7_cp_reginfo[] = {
156
- /* Standard v6 WFI (also used in some pre-v6 cores); not in v7 (which
157
+ /*
158
+ * Standard v6 WFI (also used in some pre-v6 cores); not in v7 (which
159
* is UNPREDICTABLE; we choose to NOP as most implementations do).
160
*/
161
{ .name = "WFI_v6", .cp = 15, .crn = 7, .crm = 0, .opc1 = 0, .opc2 = 4,
162
.access = PL1_W, .type = ARM_CP_WFI },
163
- /* L1 cache lockdown. Not architectural in v6 and earlier but in practice
164
+ /*
165
+ * L1 cache lockdown. Not architectural in v6 and earlier but in practice
166
* implemented in 926, 946, 1026, 1136, 1176 and 11MPCore. StrongARM and
167
* OMAPCP will override this space.
168
*/
169
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo not_v7_cp_reginfo[] = {
170
{ .name = "DUMMY", .cp = 15, .crn = 0, .crm = 0, .opc1 = 1, .opc2 = CP_ANY,
171
.access = PL1_R, .type = ARM_CP_CONST | ARM_CP_NO_RAW,
172
.resetvalue = 0 },
173
- /* We don't implement pre-v7 debug but most CPUs had at least a DBGDIDR;
174
+ /*
175
+ * We don't implement pre-v7 debug but most CPUs had at least a DBGDIDR;
176
* implementing it as RAZ means the "debug architecture version" bits
177
* will read as a reserved value, which should cause Linux to not try
178
* to use the debug hardware.
179
*/
180
{ .name = "DBGDIDR", .cp = 14, .crn = 0, .crm = 0, .opc1 = 0, .opc2 = 0,
181
.access = PL0_R, .type = ARM_CP_CONST, .resetvalue = 0 },
182
- /* MMU TLB control. Note that the wildcarding means we cover not just
183
+ /*
184
+ * MMU TLB control. Note that the wildcarding means we cover not just
185
* the unified TLB ops but also the dside/iside/inner-shareable variants.
186
*/
187
{ .name = "TLBIALL", .cp = 15, .crn = 8, .crm = CP_ANY,
188
@@ -XXX,XX +XXX,XX @@ static void cpacr_write(CPUARMState *env, const ARMCPRegInfo *ri,
189
190
/* In ARMv8 most bits of CPACR_EL1 are RES0. */
191
if (!arm_feature(env, ARM_FEATURE_V8)) {
192
- /* ARMv7 defines bits for unimplemented coprocessors as RAZ/WI.
193
+ /*
194
+ * ARMv7 defines bits for unimplemented coprocessors as RAZ/WI.
195
* ASEDIS [31] and D32DIS [30] are both UNK/SBZP without VFP.
196
* TRCDIS [28] is RAZ/WI since we do not implement a trace macrocell.
197
*/
198
@@ -XXX,XX +XXX,XX @@ static void cpacr_write(CPUARMState *env, const ARMCPRegInfo *ri,
199
value |= R_CPACR_ASEDIS_MASK;
200
}
201
202
- /* VFPv3 and upwards with NEON implement 32 double precision
203
+ /*
204
+ * VFPv3 and upwards with NEON implement 32 double precision
205
* registers (D0-D31).
206
*/
207
if (!cpu_isar_feature(aa32_simd_r32, env_archcpu(env))) {
208
@@ -XXX,XX +XXX,XX @@ static uint64_t cpacr_read(CPUARMState *env, const ARMCPRegInfo *ri)
209
210
static void cpacr_reset(CPUARMState *env, const ARMCPRegInfo *ri)
211
{
212
- /* Call cpacr_write() so that we reset with the correct RAO bits set
213
+ /*
214
+ * Call cpacr_write() so that we reset with the correct RAO bits set
215
* for our CPU features.
216
*/
217
cpacr_write(env, ri, 0);
218
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v6_cp_reginfo[] = {
219
{ .name = "MVA_prefetch",
220
.cp = 15, .crn = 7, .crm = 13, .opc1 = 0, .opc2 = 1,
221
.access = PL1_W, .type = ARM_CP_NOP },
222
- /* We need to break the TB after ISB to execute self-modifying code
223
+ /*
224
+ * We need to break the TB after ISB to execute self-modifying code
225
* correctly and also to take any pending interrupts immediately.
226
* So use arm_cp_write_ignore() function instead of ARM_CP_NOP flag.
227
*/
228
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v6_cp_reginfo[] = {
229
.bank_fieldoffsets = { offsetof(CPUARMState, cp15.ifar_s),
230
offsetof(CPUARMState, cp15.ifar_ns) },
231
.resetvalue = 0, },
232
- /* Watchpoint Fault Address Register : should actually only be present
233
+ /*
234
+ * Watchpoint Fault Address Register : should actually only be present
235
* for 1136, 1176, 11MPCore.
236
*/
237
{ .name = "WFAR", .cp = 15, .crn = 6, .crm = 0, .opc1 = 0, .opc2 = 1,
238
@@ -XXX,XX +XXX,XX @@ static bool event_supported(uint16_t number)
239
static CPAccessResult pmreg_access(CPUARMState *env, const ARMCPRegInfo *ri,
240
bool isread)
241
{
242
- /* Performance monitor registers user accessibility is controlled
243
+ /*
244
+ * Performance monitor registers user accessibility is controlled
245
* by PMUSERENR. MDCR_EL2.TPM and MDCR_EL3.TPM allow configurable
246
* trapping to EL2 or EL3 for other accesses.
247
*/
248
@@ -XXX,XX +XXX,XX @@ static CPAccessResult pmreg_access_ccntr(CPUARMState *env,
249
(MDCR_HPME | MDCR_HPMD | MDCR_HPMN | MDCR_HCCD | MDCR_HLP)
250
#define MDCR_EL3_PMU_ENABLE_BITS (MDCR_SPME | MDCR_SCCD)
251
252
-/* Returns true if the counter (pass 31 for PMCCNTR) should count events using
253
+/*
254
+ * Returns true if the counter (pass 31 for PMCCNTR) should count events using
255
* the current EL, security state, and register configuration.
256
*/
257
static bool pmu_counter_enabled(CPUARMState *env, uint8_t counter)
258
@@ -XXX,XX +XXX,XX @@ static uint64_t pmccntr_read(CPUARMState *env, const ARMCPRegInfo *ri)
259
static void pmselr_write(CPUARMState *env, const ARMCPRegInfo *ri,
260
uint64_t value)
261
{
262
- /* The value of PMSELR.SEL affects the behavior of PMXEVTYPER and
263
+ /*
264
+ * The value of PMSELR.SEL affects the behavior of PMXEVTYPER and
265
* PMXEVCNTR. We allow [0..31] to be written to PMSELR here; in the
266
* meanwhile, we check PMSELR.SEL when PMXEVTYPER and PMXEVCNTR are
267
* accessed.
268
@@ -XXX,XX +XXX,XX @@ static void pmevtyper_write(CPUARMState *env, const ARMCPRegInfo *ri,
269
env->cp15.c14_pmevtyper[counter] = value & PMXEVTYPER_MASK;
270
pmevcntr_op_finish(env, counter);
271
}
272
- /* Attempts to access PMXEVTYPER are CONSTRAINED UNPREDICTABLE when
273
+ /*
274
+ * Attempts to access PMXEVTYPER are CONSTRAINED UNPREDICTABLE when
275
* PMSELR value is equal to or greater than the number of implemented
276
* counters, but not equal to 0x1f. We opt to behave as a RAZ/WI.
277
*/
278
@@ -XXX,XX +XXX,XX @@ static uint64_t pmevcntr_read(CPUARMState *env, const ARMCPRegInfo *ri,
279
}
280
return ret;
281
} else {
282
- /* We opt to behave as a RAZ/WI when attempts to access PM[X]EVCNTR
283
- * are CONSTRAINED UNPREDICTABLE. */
284
+ /*
285
+ * We opt to behave as a RAZ/WI when attempts to access PM[X]EVCNTR
286
+ * are CONSTRAINED UNPREDICTABLE.
287
+ */
288
return 0;
289
}
290
}
291
@@ -XXX,XX +XXX,XX @@ static void pmintenclr_write(CPUARMState *env, const ARMCPRegInfo *ri,
292
static void vbar_write(CPUARMState *env, const ARMCPRegInfo *ri,
293
uint64_t value)
294
{
295
- /* Note that even though the AArch64 view of this register has bits
296
+ /*
297
+ * Note that even though the AArch64 view of this register has bits
298
* [10:0] all RES0 we can only mask the bottom 5, to comply with the
299
* architectural requirements for bits which are RES0 only in some
300
* contexts. (ARMv8 would permit us to do no masking at all, but ARMv7
301
@@ -XXX,XX +XXX,XX @@ static void scr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value)
302
if (!arm_feature(env, ARM_FEATURE_EL2)) {
303
valid_mask &= ~SCR_HCE;
304
305
- /* On ARMv7, SMD (or SCD as it is called in v7) is only
306
+ /*
307
+ * On ARMv7, SMD (or SCD as it is called in v7) is only
308
* supported if EL2 exists. The bit is UNK/SBZP when
309
* EL2 is unavailable. In QEMU ARMv7, we force it to always zero
310
* when EL2 is unavailable.
311
@@ -XXX,XX +XXX,XX @@ static uint64_t ccsidr_read(CPUARMState *env, const ARMCPRegInfo *ri)
312
{
313
ARMCPU *cpu = env_archcpu(env);
314
315
- /* Acquire the CSSELR index from the bank corresponding to the CCSIDR
316
+ /*
317
+ * Acquire the CSSELR index from the bank corresponding to the CCSIDR
318
* bank
319
*/
320
uint32_t index = A32_BANKED_REG_GET(env, csselr,
321
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v7_cp_reginfo[] = {
322
/* the old v6 WFI, UNPREDICTABLE in v7 but we choose to NOP */
323
{ .name = "NOP", .cp = 15, .crn = 7, .crm = 0, .opc1 = 0, .opc2 = 4,
324
.access = PL1_W, .type = ARM_CP_NOP },
325
- /* Performance monitors are implementation defined in v7,
326
+ /*
327
+ * Performance monitors are implementation defined in v7,
328
* but with an ARM recommended set of registers, which we
329
* follow.
330
*
331
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v7_cp_reginfo[] = {
332
.writefn = csselr_write, .resetvalue = 0,
333
.bank_fieldoffsets = { offsetof(CPUARMState, cp15.csselr_s),
334
offsetof(CPUARMState, cp15.csselr_ns) } },
335
- /* Auxiliary ID register: this actually has an IMPDEF value but for now
336
+ /*
337
+ * Auxiliary ID register: this actually has an IMPDEF value but for now
338
* just RAZ for all cores:
339
*/
340
{ .name = "AIDR", .state = ARM_CP_STATE_BOTH,
341
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v7_cp_reginfo[] = {
342
.access = PL1_R, .type = ARM_CP_CONST,
343
.accessfn = access_aa64_tid1,
344
.resetvalue = 0 },
345
- /* Auxiliary fault status registers: these also are IMPDEF, and we
346
+ /*
347
+ * Auxiliary fault status registers: these also are IMPDEF, and we
348
* choose to RAZ/WI for all cores.
349
*/
350
{ .name = "AFSR0_EL1", .state = ARM_CP_STATE_BOTH,
351
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v7_cp_reginfo[] = {
352
.opc0 = 3, .opc1 = 0, .crn = 5, .crm = 1, .opc2 = 1,
353
.access = PL1_RW, .accessfn = access_tvm_trvm,
354
.type = ARM_CP_CONST, .resetvalue = 0 },
355
- /* MAIR can just read-as-written because we don't implement caches
356
+ /*
357
+ * MAIR can just read-as-written because we don't implement caches
358
* and so don't need to care about memory attributes.
359
*/
360
{ .name = "MAIR_EL1", .state = ARM_CP_STATE_AA64,
361
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v7_cp_reginfo[] = {
362
.opc0 = 3, .opc1 = 6, .crn = 10, .crm = 2, .opc2 = 0,
363
.access = PL3_RW, .fieldoffset = offsetof(CPUARMState, cp15.mair_el[3]),
364
.resetvalue = 0 },
365
- /* For non-long-descriptor page tables these are PRRR and NMRR;
366
+ /*
367
+ * For non-long-descriptor page tables these are PRRR and NMRR;
368
* regardless they still act as reads-as-written for QEMU.
369
*/
370
- /* MAIR0/1 are defined separately from their 64-bit counterpart which
371
+ /*
372
+ * MAIR0/1 are defined separately from their 64-bit counterpart which
373
* allows them to assign the correct fieldoffset based on the endianness
374
* handled in the field definitions.
375
*/
376
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v6k_cp_reginfo[] = {
377
static CPAccessResult gt_cntfrq_access(CPUARMState *env, const ARMCPRegInfo *ri,
378
bool isread)
379
{
380
- /* CNTFRQ: not visible from PL0 if both PL0PCTEN and PL0VCTEN are zero.
381
+ /*
382
+ * CNTFRQ: not visible from PL0 if both PL0PCTEN and PL0VCTEN are zero.
383
* Writable only at the highest implemented exception level.
384
*/
385
int el = arm_current_el(env);
386
@@ -XXX,XX +XXX,XX @@ static CPAccessResult gt_stimer_access(CPUARMState *env,
387
const ARMCPRegInfo *ri,
388
bool isread)
389
{
390
- /* The AArch64 register view of the secure physical timer is
391
+ /*
392
+ * The AArch64 register view of the secure physical timer is
393
* always accessible from EL3, and configurably accessible from
394
* Secure EL1.
395
*/
396
@@ -XXX,XX +XXX,XX @@ static void gt_recalc_timer(ARMCPU *cpu, int timeridx)
397
ARMGenericTimer *gt = &cpu->env.cp15.c14_timer[timeridx];
398
399
if (gt->ctl & 1) {
400
- /* Timer enabled: calculate and set current ISTATUS, irq, and
401
+ /*
402
+ * Timer enabled: calculate and set current ISTATUS, irq, and
403
* reset timer to when ISTATUS next has to change
404
*/
405
uint64_t offset = timeridx == GTIMER_VIRT ?
406
@@ -XXX,XX +XXX,XX @@ static void gt_recalc_timer(ARMCPU *cpu, int timeridx)
407
/* Next transition is when we hit cval */
408
nexttick = gt->cval + offset;
409
}
410
- /* Note that the desired next expiry time might be beyond the
411
+ /*
412
+ * Note that the desired next expiry time might be beyond the
413
* signed-64-bit range of a QEMUTimer -- in this case we just
414
* set the timer for as far in the future as possible. When the
415
* timer expires we will reset the timer for any remaining period.
416
@@ -XXX,XX +XXX,XX @@ static void gt_ctl_write(CPUARMState *env, const ARMCPRegInfo *ri,
417
/* Enable toggled */
418
gt_recalc_timer(cpu, timeridx);
419
} else if ((oldval ^ value) & 2) {
420
- /* IMASK toggled: don't need to recalculate,
421
+ /*
422
+ * IMASK toggled: don't need to recalculate,
423
* just set the interrupt line based on ISTATUS
424
*/
425
int irqstate = (oldval & 4) && !(value & 2);
426
@@ -XXX,XX +XXX,XX @@ static void arm_gt_cntfrq_reset(CPUARMState *env, const ARMCPRegInfo *opaque)
427
}
428
429
static const ARMCPRegInfo generic_timer_cp_reginfo[] = {
430
- /* Note that CNTFRQ is purely reads-as-written for the benefit
431
+ /*
432
+ * Note that CNTFRQ is purely reads-as-written for the benefit
433
* of software; writing it doesn't actually change the timer frequency.
434
* Our reset value matches the fixed frequency we implement the timer at.
435
*/
436
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo generic_timer_cp_reginfo[] = {
437
.readfn = gt_virt_redir_cval_read, .raw_readfn = raw_read,
438
.writefn = gt_virt_redir_cval_write, .raw_writefn = raw_write,
439
},
440
- /* Secure timer -- this is actually restricted to only EL3
441
+ /*
442
+ * Secure timer -- this is actually restricted to only EL3
443
* and configurably Secure-EL1 via the accessfn.
444
*/
445
{ .name = "CNTPS_TVAL_EL1", .state = ARM_CP_STATE_AA64,
446
@@ -XXX,XX +XXX,XX @@ static CPAccessResult e2h_access(CPUARMState *env, const ARMCPRegInfo *ri,
447
448
#else
449
450
-/* In user-mode most of the generic timer registers are inaccessible
451
+/*
452
+ * In user-mode most of the generic timer registers are inaccessible
453
* however modern kernels (4.12+) allow access to cntvct_el0
454
*/
455
456
@@ -XXX,XX +XXX,XX @@ static uint64_t gt_virt_cnt_read(CPUARMState *env, const ARMCPRegInfo *ri)
457
{
458
ARMCPU *cpu = env_archcpu(env);
459
460
- /* Currently we have no support for QEMUTimer in linux-user so we
461
+ /*
462
+ * Currently we have no support for QEMUTimer in linux-user so we
463
* can't call gt_get_countervalue(env), instead we directly
464
* call the lower level functions.
465
*/
466
@@ -XXX,XX +XXX,XX @@ static CPAccessResult ats_access(CPUARMState *env, const ARMCPRegInfo *ri,
467
bool isread)
468
{
469
if (ri->opc2 & 4) {
470
- /* The ATS12NSO* operations must trap to EL3 or EL2 if executed in
471
+ /*
472
+ * The ATS12NSO* operations must trap to EL3 or EL2 if executed in
473
* Secure EL1 (which can only happen if EL3 is AArch64).
474
* They are simply UNDEF if executed from NS EL1.
475
* They function normally from EL2 or EL3.
476
@@ -XXX,XX +XXX,XX @@ static uint64_t do_ats_write(CPUARMState *env, uint64_t value,
477
}
21
}
478
}
22
} else {
479
} else {
23
prohibited = arm_feature(env, ARM_FEATURE_EL3) &&
480
- /* fsr is a DFSR/IFSR value for the short descriptor
24
- (env->cp15.mdcr_el3 & MDCR_SPME);
481
+ /*
25
+ !(env->cp15.mdcr_el3 & MDCR_SPME);
482
+ * fsr is a DFSR/IFSR value for the short descriptor
26
}
483
* translation table format (with WnR always clear).
27
484
* Convert it to a 32-bit PAR.
28
if (prohibited && counter == 31) {
485
*/
486
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo pmsav8r_cp_reginfo[] = {
487
};
488
489
static const ARMCPRegInfo pmsav7_cp_reginfo[] = {
490
- /* Reset for all these registers is handled in arm_cpu_reset(),
491
+ /*
492
+ * Reset for all these registers is handled in arm_cpu_reset(),
493
* because the PMSAv7 is also used by M-profile CPUs, which do
494
* not register cpregs but still need the state to be reset.
495
*/
496
@@ -XXX,XX +XXX,XX @@ static void vmsa_ttbcr_write(CPUARMState *env, const ARMCPRegInfo *ri,
497
}
498
499
if (arm_feature(env, ARM_FEATURE_LPAE)) {
500
- /* With LPAE the TTBCR could result in a change of ASID
501
+ /*
502
+ * With LPAE the TTBCR could result in a change of ASID
503
* via the TTBCR.A1 bit, so do a TLB flush.
504
*/
505
tlb_flush(CPU(cpu));
506
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo vmsa_cp_reginfo[] = {
507
offsetoflow32(CPUARMState, cp15.tcr_el[1])} },
508
};
509
510
-/* Note that unlike TTBCR, writing to TTBCR2 does not require flushing
511
+/*
512
+ * Note that unlike TTBCR, writing to TTBCR2 does not require flushing
513
* qemu tlbs nor adjusting cached masks.
514
*/
515
static const ARMCPRegInfo ttbcr2_reginfo = {
516
@@ -XXX,XX +XXX,XX @@ static void omap_wfi_write(CPUARMState *env, const ARMCPRegInfo *ri,
517
static void omap_cachemaint_write(CPUARMState *env, const ARMCPRegInfo *ri,
518
uint64_t value)
519
{
520
- /* On OMAP there are registers indicating the max/min index of dcache lines
521
+ /*
522
+ * On OMAP there are registers indicating the max/min index of dcache lines
523
* containing a dirty line; cache flush operations have to reset these.
524
*/
525
env->cp15.c15_i_max = 0x000;
526
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo omap_cp_reginfo[] = {
527
.crm = 8, .opc1 = 0, .opc2 = 0, .access = PL1_RW,
528
.type = ARM_CP_NO_RAW,
529
.readfn = arm_cp_read_zero, .writefn = omap_wfi_write, },
530
- /* TODO: Peripheral port remap register:
531
+ /*
532
+ * TODO: Peripheral port remap register:
533
* On OMAP2 mcr p15, 0, rn, c15, c2, 4 sets up the interrupt controller
534
* base address at $rn & ~0xfff and map size of 0x200 << ($rn & 0xfff),
535
* when MMU is off.
536
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo xscale_cp_reginfo[] = {
537
.cp = 15, .crn = 1, .crm = 0, .opc1 = 0, .opc2 = 1, .access = PL1_RW,
538
.fieldoffset = offsetof(CPUARMState, cp15.c1_xscaleauxcr),
539
.resetvalue = 0, },
540
- /* XScale specific cache-lockdown: since we have no cache we NOP these
541
+ /*
542
+ * XScale specific cache-lockdown: since we have no cache we NOP these
543
* and hope the guest does not really rely on cache behaviour.
544
*/
545
{ .name = "XSCALE_LOCK_ICACHE_LINE",
546
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo xscale_cp_reginfo[] = {
547
};
548
549
static const ARMCPRegInfo dummy_c15_cp_reginfo[] = {
550
- /* RAZ/WI the whole crn=15 space, when we don't have a more specific
551
+ /*
552
+ * RAZ/WI the whole crn=15 space, when we don't have a more specific
553
* implementation of this implementation-defined space.
554
* Ideally this should eventually disappear in favour of actually
555
* implementing the correct behaviour for all cores.
556
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo cache_block_ops_cp_reginfo[] = {
557
};
558
559
static const ARMCPRegInfo cache_test_clean_cp_reginfo[] = {
560
- /* The cache test-and-clean instructions always return (1 << 30)
561
+ /*
562
+ * The cache test-and-clean instructions always return (1 << 30)
563
* to indicate that there are no dirty cache lines.
564
*/
565
{ .name = "TC_DCACHE", .cp = 15, .crn = 7, .crm = 10, .opc1 = 0, .opc2 = 3,
566
@@ -XXX,XX +XXX,XX @@ static uint64_t mpidr_read_val(CPUARMState *env)
567
568
if (arm_feature(env, ARM_FEATURE_V7MP)) {
569
mpidr |= (1U << 31);
570
- /* Cores which are uniprocessor (non-coherent)
571
+ /*
572
+ * Cores which are uniprocessor (non-coherent)
573
* but still implement the MP extensions set
574
* bit 30. (For instance, Cortex-R5).
575
*/
576
@@ -XXX,XX +XXX,XX @@ static CPAccessResult access_tocu(CPUARMState *env, const ARMCPRegInfo *ri,
577
return do_cacheop_pou_access(env, HCR_TOCU | HCR_TPU);
578
}
579
580
-/* See: D4.7.2 TLB maintenance requirements and the TLB maintenance instructions
581
+/*
582
+ * See: D4.7.2 TLB maintenance requirements and the TLB maintenance instructions
583
* Page D4-1736 (DDI0487A.b)
584
*/
585
586
@@ -XXX,XX +XXX,XX @@ static void tlbi_aa64_alle3is_write(CPUARMState *env, const ARMCPRegInfo *ri,
587
static void tlbi_aa64_vae2_write(CPUARMState *env, const ARMCPRegInfo *ri,
588
uint64_t value)
589
{
590
- /* Invalidate by VA, EL2
591
+ /*
592
+ * Invalidate by VA, EL2
593
* Currently handles both VAE2 and VALE2, since we don't support
594
* flush-last-level-only.
595
*/
596
@@ -XXX,XX +XXX,XX @@ static void tlbi_aa64_vae2_write(CPUARMState *env, const ARMCPRegInfo *ri,
597
static void tlbi_aa64_vae3_write(CPUARMState *env, const ARMCPRegInfo *ri,
598
uint64_t value)
599
{
600
- /* Invalidate by VA, EL3
601
+ /*
602
+ * Invalidate by VA, EL3
603
* Currently handles both VAE3 and VALE3, since we don't support
604
* flush-last-level-only.
605
*/
606
@@ -XXX,XX +XXX,XX @@ static void tlbi_aa64_vae1is_write(CPUARMState *env, const ARMCPRegInfo *ri,
607
static void tlbi_aa64_vae1_write(CPUARMState *env, const ARMCPRegInfo *ri,
608
uint64_t value)
609
{
610
- /* Invalidate by VA, EL1&0 (AArch64 version).
611
+ /*
612
+ * Invalidate by VA, EL1&0 (AArch64 version).
613
* Currently handles all of VAE1, VAAE1, VAALE1 and VALE1,
614
* since we don't support flush-for-specific-ASID-only or
615
* flush-last-level-only.
616
@@ -XXX,XX +XXX,XX @@ static CPAccessResult sp_el0_access(CPUARMState *env, const ARMCPRegInfo *ri,
617
bool isread)
618
{
619
if (!(env->pstate & PSTATE_SP)) {
620
- /* Access to SP_EL0 is undefined if it's being used as
621
+ /*
622
+ * Access to SP_EL0 is undefined if it's being used as
623
* the stack pointer.
624
*/
625
return CP_ACCESS_TRAP_UNCATEGORIZED;
626
@@ -XXX,XX +XXX,XX @@ static void sctlr_write(CPUARMState *env, const ARMCPRegInfo *ri,
627
}
628
629
if (raw_read(env, ri) == value) {
630
- /* Skip the TLB flush if nothing actually changed; Linux likes
631
+ /*
632
+ * Skip the TLB flush if nothing actually changed; Linux likes
633
* to do a lot of pointless SCTLR writes.
634
*/
635
return;
636
@@ -XXX,XX +XXX,XX @@ static void mdcr_el2_write(CPUARMState *env, const ARMCPRegInfo *ri,
637
}
638
639
static const ARMCPRegInfo v8_cp_reginfo[] = {
640
- /* Minimal set of EL0-visible registers. This will need to be expanded
641
+ /*
642
+ * Minimal set of EL0-visible registers. This will need to be expanded
643
* significantly for system emulation of AArch64 CPUs.
644
*/
645
{ .name = "NZCV", .state = ARM_CP_STATE_AA64,
646
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v8_cp_reginfo[] = {
647
.opc0 = 3, .opc1 = 0, .crn = 4, .crm = 0, .opc2 = 0,
648
.access = PL1_RW,
649
.fieldoffset = offsetof(CPUARMState, banked_spsr[BANK_SVC]) },
650
- /* We rely on the access checks not allowing the guest to write to the
651
+ /*
652
+ * We rely on the access checks not allowing the guest to write to the
653
* state field when SPSel indicates that it's being used as the stack
654
* pointer.
655
*/
656
@@ -XXX,XX +XXX,XX @@ static void do_hcr_write(CPUARMState *env, uint64_t value, uint64_t valid_mask)
657
if (arm_feature(env, ARM_FEATURE_EL3)) {
658
valid_mask &= ~HCR_HCD;
659
} else if (cpu->psci_conduit != QEMU_PSCI_CONDUIT_SMC) {
660
- /* Architecturally HCR.TSC is RES0 if EL3 is not implemented.
661
+ /*
662
+ * Architecturally HCR.TSC is RES0 if EL3 is not implemented.
663
* However, if we're using the SMC PSCI conduit then QEMU is
664
* effectively acting like EL3 firmware and so the guest at
665
* EL2 should retain the ability to prevent EL1 from being
666
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo el2_cp_reginfo[] = {
667
.access = PL2_W, .type = ARM_CP_NO_RAW | ARM_CP_EL3_NO_EL2_UNDEF,
668
.writefn = tlbi_aa64_vae2is_write },
669
#ifndef CONFIG_USER_ONLY
670
- /* Unlike the other EL2-related AT operations, these must
671
+ /*
672
+ * Unlike the other EL2-related AT operations, these must
673
* UNDEF from EL3 if EL2 is not implemented, which is why we
674
* define them here rather than with the rest of the AT ops.
675
*/
676
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo el2_cp_reginfo[] = {
677
.access = PL2_W, .accessfn = at_s1e2_access,
678
.type = ARM_CP_NO_RAW | ARM_CP_RAISES_EXC | ARM_CP_EL3_NO_EL2_UNDEF,
679
.writefn = ats_write64 },
680
- /* The AArch32 ATS1H* operations are CONSTRAINED UNPREDICTABLE
681
+ /*
682
+ * The AArch32 ATS1H* operations are CONSTRAINED UNPREDICTABLE
683
* if EL2 is not implemented; we choose to UNDEF. Behaviour at EL3
684
* with SCR.NS == 0 outside Monitor mode is UNPREDICTABLE; we choose
685
* to behave as if SCR.NS was 1.
686
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo el2_cp_reginfo[] = {
687
.writefn = ats1h_write, .type = ARM_CP_NO_RAW | ARM_CP_RAISES_EXC },
688
{ .name = "CNTHCTL_EL2", .state = ARM_CP_STATE_BOTH,
689
.opc0 = 3, .opc1 = 4, .crn = 14, .crm = 1, .opc2 = 0,
690
- /* ARMv7 requires bit 0 and 1 to reset to 1. ARMv8 defines the
691
+ /*
692
+ * ARMv7 requires bit 0 and 1 to reset to 1. ARMv8 defines the
693
* reset values as IMPDEF. We choose to reset to 3 to comply with
694
* both ARMv7 and ARMv8.
695
*/
696
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo el2_sec_cp_reginfo[] = {
697
static CPAccessResult nsacr_access(CPUARMState *env, const ARMCPRegInfo *ri,
698
bool isread)
699
{
700
- /* The NSACR is RW at EL3, and RO for NS EL1 and NS EL2.
701
+ /*
702
+ * The NSACR is RW at EL3, and RO for NS EL1 and NS EL2.
703
* At Secure EL1 it traps to EL3 or EL2.
704
*/
705
if (arm_current_el(env) == 3) {
706
@@ -XXX,XX +XXX,XX @@ static void define_pmu_regs(ARMCPU *cpu)
707
}
708
}
709
710
-/* We don't know until after realize whether there's a GICv3
711
+/*
712
+ * We don't know until after realize whether there's a GICv3
713
* attached, and that is what registers the gicv3 sysregs.
714
* So we have to fill in the GIC fields in ID_PFR/ID_PFR1_EL1/ID_AA64PFR0_EL1
715
* at runtime.
716
@@ -XXX,XX +XXX,XX @@ static uint64_t id_aa64pfr0_read(CPUARMState *env, const ARMCPRegInfo *ri)
717
}
718
#endif
719
720
-/* Shared logic between LORID and the rest of the LOR* registers.
721
+/*
722
+ * Shared logic between LORID and the rest of the LOR* registers.
723
* Secure state exclusion has already been dealt with.
724
*/
725
static CPAccessResult access_lor_ns(CPUARMState *env,
726
@@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu)
727
728
define_arm_cp_regs(cpu, cp_reginfo);
729
if (!arm_feature(env, ARM_FEATURE_V8)) {
730
- /* Must go early as it is full of wildcards that may be
731
+ /*
732
+ * Must go early as it is full of wildcards that may be
733
* overridden by later definitions.
734
*/
735
define_arm_cp_regs(cpu, not_v8_cp_reginfo);
736
@@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu)
737
.access = PL1_R, .type = ARM_CP_CONST,
738
.accessfn = access_aa32_tid3,
739
.resetvalue = cpu->isar.id_pfr0 },
740
- /* ID_PFR1 is not a plain ARM_CP_CONST because we don't know
741
+ /*
742
+ * ID_PFR1 is not a plain ARM_CP_CONST because we don't know
743
* the value of the GIC field until after we define these regs.
744
*/
745
{ .name = "ID_PFR1", .state = ARM_CP_STATE_BOTH,
746
@@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu)
747
748
define_arm_cp_regs(cpu, el3_regs);
749
}
750
- /* The behaviour of NSACR is sufficiently various that we don't
751
+ /*
752
+ * The behaviour of NSACR is sufficiently various that we don't
753
* try to describe it in a single reginfo:
754
* if EL3 is 64 bit, then trap to EL3 from S EL1,
755
* reads as constant 0xc00 from NS EL1 and NS EL2
756
@@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu)
757
if (cpu_isar_feature(aa32_jazelle, cpu)) {
758
define_arm_cp_regs(cpu, jazelle_regs);
759
}
760
- /* Slightly awkwardly, the OMAP and StrongARM cores need all of
761
+ /*
762
+ * Slightly awkwardly, the OMAP and StrongARM cores need all of
763
* cp15 crn=0 to be writes-ignored, whereas for other cores they should
764
* be read-only (ie write causes UNDEF exception).
765
*/
766
{
767
ARMCPRegInfo id_pre_v8_midr_cp_reginfo[] = {
768
- /* Pre-v8 MIDR space.
769
+ /*
770
+ * Pre-v8 MIDR space.
771
* Note that the MIDR isn't a simple constant register because
772
* of the TI925 behaviour where writes to another register can
773
* cause the MIDR value to change.
774
@@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu)
775
if (arm_feature(env, ARM_FEATURE_OMAPCP) ||
776
arm_feature(env, ARM_FEATURE_STRONGARM)) {
777
size_t i;
778
- /* Register the blanket "writes ignored" value first to cover the
779
+ /*
780
+ * Register the blanket "writes ignored" value first to cover the
781
* whole space. Then update the specific ID registers to allow write
782
* access, so that they ignore writes rather than causing them to
783
* UNDEF.
784
@@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu)
785
.raw_writefn = raw_write,
786
};
787
if (arm_feature(env, ARM_FEATURE_XSCALE)) {
788
- /* Normally we would always end the TB on an SCTLR write, but Linux
789
+ /*
790
+ * Normally we would always end the TB on an SCTLR write, but Linux
791
* arch/arm/mach-pxa/sleep.S expects two instructions following
792
* an MMU enable to execute from cache. Imitate this behaviour.
793
*/
794
@@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r,
795
void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu,
796
const ARMCPRegInfo *r, void *opaque)
797
{
798
- /* Define implementations of coprocessor registers.
799
+ /*
800
+ * Define implementations of coprocessor registers.
801
* We store these in a hashtable because typically
802
* there are less than 150 registers in a space which
803
* is 16*16*16*8*8 = 262144 in size.
804
@@ -XXX,XX +XXX,XX @@ void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu,
805
default:
806
g_assert_not_reached();
807
}
808
- /* The AArch64 pseudocode CheckSystemAccess() specifies that op1
809
+ /*
810
+ * The AArch64 pseudocode CheckSystemAccess() specifies that op1
811
* encodes a minimum access level for the register. We roll this
812
* runtime check into our general permission check code, so check
813
* here that the reginfo's specified permissions are strict enough
814
@@ -XXX,XX +XXX,XX @@ void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu,
815
assert((r->access & ~mask) == 0);
816
}
817
818
- /* Check that the register definition has enough info to handle
819
+ /*
820
+ * Check that the register definition has enough info to handle
821
* reads and writes if they are permitted.
822
*/
823
if (!(r->type & (ARM_CP_SPECIAL_MASK | ARM_CP_CONST))) {
824
@@ -XXX,XX +XXX,XX @@ void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu,
825
continue;
826
}
827
if (state == ARM_CP_STATE_AA32) {
828
- /* Under AArch32 CP registers can be common
829
+ /*
830
+ * Under AArch32 CP registers can be common
831
* (same for secure and non-secure world) or banked.
832
*/
833
char *name;
834
@@ -XXX,XX +XXX,XX @@ void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu,
835
g_assert_not_reached();
836
}
837
} else {
838
- /* AArch64 registers get mapped to non-secure instance
839
- * of AArch32 */
840
+ /*
841
+ * AArch64 registers get mapped to non-secure instance
842
+ * of AArch32
843
+ */
844
add_cpreg_to_hashtable(cpu, r, opaque, state,
845
ARM_CP_SECSTATE_NS,
846
crm, opc1, opc2, r->name);
847
@@ -XXX,XX +XXX,XX @@ void arm_cp_reset_ignore(CPUARMState *env, const ARMCPRegInfo *opaque)
848
849
static int bad_mode_switch(CPUARMState *env, int mode, CPSRWriteType write_type)
850
{
851
- /* Return true if it is not valid for us to switch to
852
+ /*
853
+ * Return true if it is not valid for us to switch to
854
* this CPU mode (ie all the UNPREDICTABLE cases in
855
* the ARM ARM CPSRWriteByInstr pseudocode).
856
*/
857
@@ -XXX,XX +XXX,XX @@ static int bad_mode_switch(CPUARMState *env, int mode, CPSRWriteType write_type)
858
case ARM_CPU_MODE_UND:
859
case ARM_CPU_MODE_IRQ:
860
case ARM_CPU_MODE_FIQ:
861
- /* Note that we don't implement the IMPDEF NSACR.RFR which in v7
862
+ /*
863
+ * Note that we don't implement the IMPDEF NSACR.RFR which in v7
864
* allows FIQ mode to be Secure-only. (In v8 this doesn't exist.)
865
*/
866
- /* If HCR.TGE is set then changes from Monitor to NS PL1 via MSR
867
+ /*
868
+ * If HCR.TGE is set then changes from Monitor to NS PL1 via MSR
869
* and CPS are treated as illegal mode changes.
870
*/
871
if (write_type == CPSRWriteByInstr &&
872
@@ -XXX,XX +XXX,XX @@ void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask,
873
env->GE = (val >> 16) & 0xf;
874
}
875
876
- /* In a V7 implementation that includes the security extensions but does
877
+ /*
878
+ * In a V7 implementation that includes the security extensions but does
879
* not include Virtualization Extensions the SCR.FW and SCR.AW bits control
880
* whether non-secure software is allowed to change the CPSR_F and CPSR_A
881
* bits respectively.
882
@@ -XXX,XX +XXX,XX @@ void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask,
883
changed_daif = (env->daif ^ val) & mask;
884
885
if (changed_daif & CPSR_A) {
886
- /* Check to see if we are allowed to change the masking of async
887
+ /*
888
+ * Check to see if we are allowed to change the masking of async
889
* abort exceptions from a non-secure state.
890
*/
891
if (!(env->cp15.scr_el3 & SCR_AW)) {
892
@@ -XXX,XX +XXX,XX @@ void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask,
893
}
894
895
if (changed_daif & CPSR_F) {
896
- /* Check to see if we are allowed to change the masking of FIQ
897
+ /*
898
+ * Check to see if we are allowed to change the masking of FIQ
899
* exceptions from a non-secure state.
900
*/
901
if (!(env->cp15.scr_el3 & SCR_FW)) {
902
@@ -XXX,XX +XXX,XX @@ void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask,
903
mask &= ~CPSR_F;
904
}
905
906
- /* Check whether non-maskable FIQ (NMFI) support is enabled.
907
+ /*
908
+ * Check whether non-maskable FIQ (NMFI) support is enabled.
909
* If this bit is set software is not allowed to mask
910
* FIQs, but is allowed to set CPSR_F to 0.
911
*/
912
@@ -XXX,XX +XXX,XX @@ void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask,
913
if (write_type != CPSRWriteRaw &&
914
((env->uncached_cpsr ^ val) & mask & CPSR_M)) {
915
if ((env->uncached_cpsr & CPSR_M) == ARM_CPU_MODE_USR) {
916
- /* Note that we can only get here in USR mode if this is a
917
+ /*
918
+ * Note that we can only get here in USR mode if this is a
919
* gdb stub write; for this case we follow the architectural
920
* behaviour for guest writes in USR mode of ignoring an attempt
921
* to switch mode. (Those are caught by translate.c for writes
922
@@ -XXX,XX +XXX,XX @@ void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask,
923
*/
924
mask &= ~CPSR_M;
925
} else if (bad_mode_switch(env, val & CPSR_M, write_type)) {
926
- /* Attempt to switch to an invalid mode: this is UNPREDICTABLE in
927
+ /*
928
+ * Attempt to switch to an invalid mode: this is UNPREDICTABLE in
929
* v7, and has defined behaviour in v8:
930
* + leave CPSR.M untouched
931
* + allow changes to the other CPSR fields
932
@@ -XXX,XX +XXX,XX @@ static void switch_mode(CPUARMState *env, int mode)
933
env->regs[14] = env->banked_r14[r14_bank_number(mode)];
934
}
935
936
-/* Physical Interrupt Target EL Lookup Table
937
+/*
938
+ * Physical Interrupt Target EL Lookup Table
939
*
940
* [ From ARM ARM section G1.13.4 (Table G1-15) ]
941
*
942
@@ -XXX,XX +XXX,XX @@ uint32_t arm_phys_excp_target_el(CPUState *cs, uint32_t excp_idx,
943
if (arm_feature(env, ARM_FEATURE_EL3)) {
944
rw = ((env->cp15.scr_el3 & SCR_RW) == SCR_RW);
945
} else {
946
- /* Either EL2 is the highest EL (and so the EL2 register width
947
+ /*
948
+ * Either EL2 is the highest EL (and so the EL2 register width
949
* is given by is64); or there is no EL2 or EL3, in which case
950
* the value of 'rw' does not affect the table lookup anyway.
951
*/
952
@@ -XXX,XX +XXX,XX @@ void aarch64_sync_64_to_32(CPUARMState *env)
953
env->banked_r13[bank_number(ARM_CPU_MODE_UND)] = env->xregs[23];
954
}
955
956
- /* Registers x24-x30 are mapped to r8-r14 in FIQ mode. If we are in FIQ
957
+ /*
958
+ * Registers x24-x30 are mapped to r8-r14 in FIQ mode. If we are in FIQ
959
* mode, then we can copy to r8-r14. Otherwise, we copy to the
960
* FIQ bank for r8-r14.
961
*/
962
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_do_interrupt_aarch32(CPUState *cs)
963
/* High vectors. When enabled, base address cannot be remapped. */
964
addr += 0xffff0000;
965
} else {
966
- /* ARM v7 architectures provide a vector base address register to remap
967
+ /*
968
+ * ARM v7 architectures provide a vector base address register to remap
969
* the interrupt vector table.
970
* This register is only followed in non-monitor mode, and is banked.
971
* Note: only bits 31:5 are valid.
972
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_do_interrupt_aarch64(CPUState *cs)
973
aarch64_sve_change_el(env, cur_el, new_el, is_a64(env));
974
975
if (cur_el < new_el) {
976
- /* Entry vector offset depends on whether the implemented EL
977
+ /*
978
+ * Entry vector offset depends on whether the implemented EL
979
* immediately lower than the target level is using AArch32 or AArch64
980
*/
981
bool is_aa64;
982
@@ -XXX,XX +XXX,XX @@ static void handle_semihosting(CPUState *cs)
983
}
984
#endif
985
986
-/* Handle a CPU exception for A and R profile CPUs.
987
+/*
988
+ * Handle a CPU exception for A and R profile CPUs.
989
* Do any appropriate logging, handle PSCI calls, and then hand off
990
* to the AArch64-entry or AArch32-entry function depending on the
991
* target exception level's register width.
992
@@ -XXX,XX +XXX,XX @@ void arm_cpu_do_interrupt(CPUState *cs)
993
}
994
#endif
995
996
- /* Hooks may change global state so BQL should be held, also the
997
+ /*
998
+ * Hooks may change global state so BQL should be held, also the
999
* BQL needs to be held for any modification of
1000
* cs->interrupt_request.
1001
*/
1002
@@ -XXX,XX +XXX,XX @@ ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va,
1003
};
1004
}
1005
1006
-/* Note that signed overflow is undefined in C. The following routines are
1007
- careful to use unsigned types where modulo arithmetic is required.
1008
- Failure to do so _will_ break on newer gcc. */
1009
+/*
1010
+ * Note that signed overflow is undefined in C. The following routines are
1011
+ * careful to use unsigned types where modulo arithmetic is required.
1012
+ * Failure to do so _will_ break on newer gcc.
1013
+ */
1014
1015
/* Signed saturating arithmetic. */
1016
1017
@@ -XXX,XX +XXX,XX @@ uint32_t HELPER(sel_flags)(uint32_t flags, uint32_t a, uint32_t b)
1018
return (a & mask) | (b & ~mask);
1019
}
1020
1021
-/* CRC helpers.
1022
+/*
1023
+ * CRC helpers.
1024
* The upper bytes of val (above the number specified by 'bytes') must have
1025
* been zeroed out by the caller.
1026
*/
1027
@@ -XXX,XX +XXX,XX @@ uint32_t HELPER(crc32c)(uint32_t acc, uint32_t val, uint32_t bytes)
1028
return crc32c(acc, buf, bytes) ^ 0xffffffff;
1029
}
1030
1031
-/* Return the exception level to which FP-disabled exceptions should
1032
+/*
1033
+ * Return the exception level to which FP-disabled exceptions should
1034
* be taken, or 0 if FP is enabled.
1035
*/
1036
int fp_exception_el(CPUARMState *env, int cur_el)
1037
@@ -XXX,XX +XXX,XX @@ int fp_exception_el(CPUARMState *env, int cur_el)
1038
#ifndef CONFIG_USER_ONLY
1039
uint64_t hcr_el2;
1040
1041
- /* CPACR and the CPTR registers don't exist before v6, so FP is
1042
+ /*
1043
+ * CPACR and the CPTR registers don't exist before v6, so FP is
1044
* always accessible
1045
*/
1046
if (!arm_feature(env, ARM_FEATURE_V6)) {
1047
@@ -XXX,XX +XXX,XX @@ int fp_exception_el(CPUARMState *env, int cur_el)
1048
1049
hcr_el2 = arm_hcr_el2_eff(env);
1050
1051
- /* The CPACR controls traps to EL1, or PL1 if we're 32 bit:
1052
+ /*
1053
+ * The CPACR controls traps to EL1, or PL1 if we're 32 bit:
1054
* 0, 2 : trap EL0 and EL1/PL1 accesses
1055
* 1 : trap only EL0 accesses
1056
* 3 : trap no accesses
29
--
1057
--
30
2.20.1
1058
2.25.1
31
32
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Fabiano Rosas <farosas@suse.de>
2
2
3
Per the datasheet (DDI0407 r2p0):
3
Fix the following:
4
4
5
"All SCU registers are byte accessible" and are 32-bit aligned.
5
ERROR: spaces required around that '|' (ctx:VxV)
6
ERROR: space required before the open parenthesis '('
7
ERROR: spaces required around that '+' (ctx:VxB)
8
ERROR: space prohibited between function name and open parenthesis '('
6
9
7
Set MemoryRegionOps::valid min/max fields and simplify the write()
10
(the last two still have some occurrences in macros which I left
8
handler.
11
behind because it might impact readability)
9
12
10
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
13
Signed-off-by: Fabiano Rosas <farosas@suse.de>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
14
Reviewed-by: Claudio Fontana <cfontana@suse.de>
12
Message-id: 20200901144100.116742-3-f4bug@amsat.org
15
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
16
Message-id: 20221213190537.511-3-farosas@suse.de
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
---
18
---
15
hw/misc/a9scu.c | 21 +++++----------------
19
target/arm/helper.c | 42 +++++++++++++++++++++---------------------
16
1 file changed, 5 insertions(+), 16 deletions(-)
20
1 file changed, 21 insertions(+), 21 deletions(-)
17
21
18
diff --git a/hw/misc/a9scu.c b/hw/misc/a9scu.c
22
diff --git a/target/arm/helper.c b/target/arm/helper.c
19
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
20
--- a/hw/misc/a9scu.c
24
--- a/target/arm/helper.c
21
+++ b/hw/misc/a9scu.c
25
+++ b/target/arm/helper.c
22
@@ -XXX,XX +XXX,XX @@ static void a9_scu_write(void *opaque, hwaddr offset,
26
@@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_list(gpointer key, gpointer opaque)
23
uint64_t value, unsigned size)
27
uint32_t regidx = (uintptr_t)key;
24
{
28
const ARMCPRegInfo *ri = get_arm_cp_reginfo(cpu->cp_regs, regidx);
25
A9SCUState *s = (A9SCUState *)opaque;
29
26
- uint32_t mask;
30
- if (!(ri->type & (ARM_CP_NO_RAW|ARM_CP_ALIAS))) {
27
+ uint32_t mask = MAKE_64BIT_MASK(0, size * 8);
31
+ if (!(ri->type & (ARM_CP_NO_RAW | ARM_CP_ALIAS))) {
28
uint32_t shift;
32
cpu->cpreg_indexes[cpu->cpreg_array_len] = cpreg_to_kvm_id(regidx);
29
- switch (size) {
33
/* The value array need not be initialized at this point */
30
- case 1:
34
cpu->cpreg_array_len++;
31
- mask = 0xff;
35
@@ -XXX,XX +XXX,XX @@ static void count_cpreg(gpointer key, gpointer opaque)
32
- break;
36
33
- case 2:
37
ri = g_hash_table_lookup(cpu->cp_regs, key);
34
- mask = 0xffff;
38
35
- break;
39
- if (!(ri->type & (ARM_CP_NO_RAW|ARM_CP_ALIAS))) {
36
- case 4:
40
+ if (!(ri->type & (ARM_CP_NO_RAW | ARM_CP_ALIAS))) {
37
- mask = 0xffffffff;
41
cpu->cpreg_array_len++;
38
- break;
42
}
39
- default:
43
}
40
- fprintf(stderr, "Invalid size %u in write to a9 scu register %x\n",
44
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v6k_cp_reginfo[] = {
41
- size, (unsigned)offset);
45
.resetfn = arm_cp_reset_ignore },
42
- return;
46
{ .name = "TPIDRRO_EL0", .state = ARM_CP_STATE_AA64,
43
- }
47
.opc0 = 3, .opc1 = 3, .opc2 = 3, .crn = 13, .crm = 0,
44
48
- .access = PL0_R|PL1_W,
45
switch (offset) {
49
+ .access = PL0_R | PL1_W,
46
case 0x00: /* Control */
50
.fieldoffset = offsetof(CPUARMState, cp15.tpidrro_el[0]),
47
@@ -XXX,XX +XXX,XX @@ static void a9_scu_write(void *opaque, hwaddr offset,
51
.resetvalue = 0},
48
static const MemoryRegionOps a9_scu_ops = {
52
{ .name = "TPIDRURO", .cp = 15, .crn = 13, .crm = 0, .opc1 = 0, .opc2 = 3,
49
.read = a9_scu_read,
53
- .access = PL0_R|PL1_W,
50
.write = a9_scu_write,
54
+ .access = PL0_R | PL1_W,
51
+ .valid = {
55
.bank_fieldoffsets = { offsetoflow32(CPUARMState, cp15.tpidruro_s),
52
+ .min_access_size = 1,
56
offsetoflow32(CPUARMState, cp15.tpidruro_ns) },
53
+ .max_access_size = 4,
57
.resetfn = arm_cp_reset_ignore },
54
+ },
58
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo cache_block_ops_cp_reginfo[] = {
55
.endianness = DEVICE_NATIVE_ENDIAN,
59
.resetvalue = 0 },
60
/* The cache ops themselves: these all NOP for QEMU */
61
{ .name = "IICR", .cp = 15, .crm = 5, .opc1 = 0,
62
- .access = PL1_W, .type = ARM_CP_NOP|ARM_CP_64BIT },
63
+ .access = PL1_W, .type = ARM_CP_NOP | ARM_CP_64BIT },
64
{ .name = "IDCR", .cp = 15, .crm = 6, .opc1 = 0,
65
- .access = PL1_W, .type = ARM_CP_NOP|ARM_CP_64BIT },
66
+ .access = PL1_W, .type = ARM_CP_NOP | ARM_CP_64BIT },
67
{ .name = "CDCR", .cp = 15, .crm = 12, .opc1 = 0,
68
- .access = PL0_W, .type = ARM_CP_NOP|ARM_CP_64BIT },
69
+ .access = PL0_W, .type = ARM_CP_NOP | ARM_CP_64BIT },
70
{ .name = "PIR", .cp = 15, .crm = 12, .opc1 = 1,
71
- .access = PL0_W, .type = ARM_CP_NOP|ARM_CP_64BIT },
72
+ .access = PL0_W, .type = ARM_CP_NOP | ARM_CP_64BIT },
73
{ .name = "PDR", .cp = 15, .crm = 12, .opc1 = 2,
74
- .access = PL0_W, .type = ARM_CP_NOP|ARM_CP_64BIT },
75
+ .access = PL0_W, .type = ARM_CP_NOP | ARM_CP_64BIT },
76
{ .name = "CIDCR", .cp = 15, .crm = 14, .opc1 = 0,
77
- .access = PL1_W, .type = ARM_CP_NOP|ARM_CP_64BIT },
78
+ .access = PL1_W, .type = ARM_CP_NOP | ARM_CP_64BIT },
56
};
79
};
57
80
81
static const ARMCPRegInfo cache_test_clean_cp_reginfo[] = {
82
@@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu)
83
ARMCPRegInfo cbar = {
84
.name = "CBAR",
85
.cp = 15, .crn = 15, .crm = 0, .opc1 = 4, .opc2 = 0,
86
- .access = PL1_R|PL3_W, .resetvalue = cpu->reset_cbar,
87
+ .access = PL1_R | PL3_W, .resetvalue = cpu->reset_cbar,
88
.fieldoffset = offsetof(CPUARMState,
89
cp15.c15_config_base_address)
90
};
91
@@ -XXX,XX +XXX,XX @@ static void switch_mode(CPUARMState *env, int mode)
92
return;
93
94
if (old_mode == ARM_CPU_MODE_FIQ) {
95
- memcpy (env->fiq_regs, env->regs + 8, 5 * sizeof(uint32_t));
96
- memcpy (env->regs + 8, env->usr_regs, 5 * sizeof(uint32_t));
97
+ memcpy(env->fiq_regs, env->regs + 8, 5 * sizeof(uint32_t));
98
+ memcpy(env->regs + 8, env->usr_regs, 5 * sizeof(uint32_t));
99
} else if (mode == ARM_CPU_MODE_FIQ) {
100
- memcpy (env->usr_regs, env->regs + 8, 5 * sizeof(uint32_t));
101
- memcpy (env->regs + 8, env->fiq_regs, 5 * sizeof(uint32_t));
102
+ memcpy(env->usr_regs, env->regs + 8, 5 * sizeof(uint32_t));
103
+ memcpy(env->regs + 8, env->fiq_regs, 5 * sizeof(uint32_t));
104
}
105
106
i = bank_number(old_mode);
107
@@ -XXX,XX +XXX,XX @@ static inline uint8_t sub8_usat(uint8_t a, uint8_t b)
108
RESULT(sum, n, 16); \
109
if (sum >= 0) \
110
ge |= 3 << (n * 2); \
111
- } while(0)
112
+ } while (0)
113
114
#define SARITH8(a, b, n, op) do { \
115
int32_t sum; \
116
@@ -XXX,XX +XXX,XX @@ static inline uint8_t sub8_usat(uint8_t a, uint8_t b)
117
RESULT(sum, n, 8); \
118
if (sum >= 0) \
119
ge |= 1 << n; \
120
- } while(0)
121
+ } while (0)
122
123
124
#define ADD16(a, b, n) SARITH16(a, b, n, +)
125
@@ -XXX,XX +XXX,XX @@ static inline uint8_t sub8_usat(uint8_t a, uint8_t b)
126
RESULT(sum, n, 16); \
127
if ((sum >> 16) == 1) \
128
ge |= 3 << (n * 2); \
129
- } while(0)
130
+ } while (0)
131
132
#define ADD8(a, b, n) do { \
133
uint32_t sum; \
134
@@ -XXX,XX +XXX,XX @@ static inline uint8_t sub8_usat(uint8_t a, uint8_t b)
135
RESULT(sum, n, 8); \
136
if ((sum >> 8) == 1) \
137
ge |= 1 << n; \
138
- } while(0)
139
+ } while (0)
140
141
#define SUB16(a, b, n) do { \
142
uint32_t sum; \
143
@@ -XXX,XX +XXX,XX @@ static inline uint8_t sub8_usat(uint8_t a, uint8_t b)
144
RESULT(sum, n, 16); \
145
if ((sum >> 16) == 0) \
146
ge |= 3 << (n * 2); \
147
- } while(0)
148
+ } while (0)
149
150
#define SUB8(a, b, n) do { \
151
uint32_t sum; \
152
@@ -XXX,XX +XXX,XX @@ static inline uint8_t sub8_usat(uint8_t a, uint8_t b)
153
RESULT(sum, n, 8); \
154
if ((sum >> 8) == 0) \
155
ge |= 1 << n; \
156
- } while(0)
157
+ } while (0)
158
159
#define PFX u
160
#define ARITH_GE
58
--
161
--
59
2.20.1
162
2.25.1
60
61
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Fabiano Rosas <farosas@suse.de>
2
2
3
Per the datasheet (DDI0407 r2p0):
3
Fix this:
4
ERROR: braces {} are necessary for all arms of this statement
4
5
5
"The SCU connects one to four Cortex-A9 processors to
6
Signed-off-by: Fabiano Rosas <farosas@suse.de>
6
the memory system through the AXI interfaces."
7
Reviewed-by: Claudio Fontana <cfontana@suse.de>
7
8
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
8
Change the instance_init() handler to a device_realize()
9
Message-id: 20221213190537.511-4-farosas@suse.de
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>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
---
11
---
17
hw/misc/a9scu.c | 18 +++++++++++++-----
12
target/arm/helper.c | 67 ++++++++++++++++++++++++++++-----------------
18
1 file changed, 13 insertions(+), 5 deletions(-)
13
1 file changed, 42 insertions(+), 25 deletions(-)
19
14
20
diff --git a/hw/misc/a9scu.c b/hw/misc/a9scu.c
15
diff --git a/target/arm/helper.c b/target/arm/helper.c
21
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
22
--- a/hw/misc/a9scu.c
17
--- a/target/arm/helper.c
23
+++ b/hw/misc/a9scu.c
18
+++ b/target/arm/helper.c
24
@@ -XXX,XX +XXX,XX @@
19
@@ -XXX,XX +XXX,XX @@ void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask,
25
#include "hw/misc/a9scu.h"
20
env->CF = (val >> 29) & 1;
26
#include "hw/qdev-properties.h"
21
env->VF = (val << 3) & 0x80000000;
27
#include "migration/vmstate.h"
22
}
28
+#include "qapi/error.h"
23
- if (mask & CPSR_Q)
29
#include "qemu/module.h"
24
+ if (mask & CPSR_Q) {
30
25
env->QF = ((val & CPSR_Q) != 0);
31
+#define A9_SCU_CPU_MAX 4
26
- if (mask & CPSR_T)
32
+
27
+ }
33
static uint64_t a9_scu_read(void *opaque, hwaddr offset,
28
+ if (mask & CPSR_T) {
34
unsigned size)
29
env->thumb = ((val & CPSR_T) != 0);
30
+ }
31
if (mask & CPSR_IT_0_1) {
32
env->condexec_bits &= ~3;
33
env->condexec_bits |= (val >> 25) & 3;
34
@@ -XXX,XX +XXX,XX @@ static void switch_mode(CPUARMState *env, int mode)
35
int i;
36
37
old_mode = env->uncached_cpsr & CPSR_M;
38
- if (mode == old_mode)
39
+ if (mode == old_mode) {
40
return;
41
+ }
42
43
if (old_mode == ARM_CPU_MODE_FIQ) {
44
memcpy(env->fiq_regs, env->regs + 8, 5 * sizeof(uint32_t));
45
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_do_interrupt_aarch32(CPUState *cs)
46
new_mode = ARM_CPU_MODE_UND;
47
addr = 0x04;
48
mask = CPSR_I;
49
- if (env->thumb)
50
+ if (env->thumb) {
51
offset = 2;
52
- else
53
+ } else {
54
offset = 4;
55
+ }
56
break;
57
case EXCP_SWI:
58
new_mode = ARM_CPU_MODE_SVC;
59
@@ -XXX,XX +XXX,XX @@ static inline uint16_t add16_sat(uint16_t a, uint16_t b)
60
61
res = a + b;
62
if (((res ^ a) & 0x8000) && !((a ^ b) & 0x8000)) {
63
- if (a & 0x8000)
64
+ if (a & 0x8000) {
65
res = 0x8000;
66
- else
67
+ } else {
68
res = 0x7fff;
69
+ }
70
}
71
return res;
72
}
73
@@ -XXX,XX +XXX,XX @@ static inline uint8_t add8_sat(uint8_t a, uint8_t b)
74
75
res = a + b;
76
if (((res ^ a) & 0x80) && !((a ^ b) & 0x80)) {
77
- if (a & 0x80)
78
+ if (a & 0x80) {
79
res = 0x80;
80
- else
81
+ } else {
82
res = 0x7f;
83
+ }
84
}
85
return res;
86
}
87
@@ -XXX,XX +XXX,XX @@ static inline uint16_t sub16_sat(uint16_t a, uint16_t b)
88
89
res = a - b;
90
if (((res ^ a) & 0x8000) && ((a ^ b) & 0x8000)) {
91
- if (a & 0x8000)
92
+ if (a & 0x8000) {
93
res = 0x8000;
94
- else
95
+ } else {
96
res = 0x7fff;
97
+ }
98
}
99
return res;
100
}
101
@@ -XXX,XX +XXX,XX @@ static inline uint8_t sub8_sat(uint8_t a, uint8_t b)
102
103
res = a - b;
104
if (((res ^ a) & 0x80) && ((a ^ b) & 0x80)) {
105
- if (a & 0x80)
106
+ if (a & 0x80) {
107
res = 0x80;
108
- else
109
+ } else {
110
res = 0x7f;
111
+ }
112
}
113
return res;
114
}
115
@@ -XXX,XX +XXX,XX @@ static inline uint16_t add16_usat(uint16_t a, uint16_t b)
35
{
116
{
36
@@ -XXX,XX +XXX,XX @@ static void a9_scu_reset(DeviceState *dev)
117
uint16_t res;
37
s->control = 0;
118
res = a + b;
119
- if (res < a)
120
+ if (res < a) {
121
res = 0xffff;
122
+ }
123
return res;
38
}
124
}
39
125
40
-static void a9_scu_init(Object *obj)
126
static inline uint16_t sub16_usat(uint16_t a, uint16_t b)
41
+static void a9_scu_realize(DeviceState *dev, Error **errp)
42
{
127
{
43
- A9SCUState *s = A9_SCU(obj);
128
- if (a > b)
44
- SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
129
+ if (a > b) {
45
+ A9SCUState *s = A9_SCU(dev);
130
return a - b;
46
+ SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
131
- else
47
132
+ } else {
48
- memory_region_init_io(&s->iomem, obj, &a9_scu_ops, s,
133
return 0;
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;
52
+ }
134
+ }
53
+
54
+ memory_region_init_io(&s->iomem, OBJECT(s), &a9_scu_ops, s,
55
"a9-scu", 0x100);
56
sysbus_init_mmio(sbd, &s->iomem);
57
}
135
}
58
@@ -XXX,XX +XXX,XX @@ static void a9_scu_class_init(ObjectClass *klass, void *data)
136
59
device_class_set_props(dc, a9_scu_properties);
137
static inline uint8_t add8_usat(uint8_t a, uint8_t b)
60
dc->vmsd = &vmstate_a9_scu;
138
{
61
dc->reset = a9_scu_reset;
139
uint8_t res;
62
+ dc->realize = a9_scu_realize;
140
res = a + b;
141
- if (res < a)
142
+ if (res < a) {
143
res = 0xff;
144
+ }
145
return res;
63
}
146
}
64
147
65
static const TypeInfo a9_scu_info = {
148
static inline uint8_t sub8_usat(uint8_t a, uint8_t b)
66
.name = TYPE_A9_SCU,
149
{
67
.parent = TYPE_SYS_BUS_DEVICE,
150
- if (a > b)
68
.instance_size = sizeof(A9SCUState),
151
+ if (a > b) {
69
- .instance_init = a9_scu_init,
152
return a - b;
70
.class_init = a9_scu_class_init,
153
- else
71
};
154
+ } else {
155
return 0;
156
+ }
157
}
158
159
#define ADD16(a, b, n) RESULT(add16_usat(a, b), n, 16);
160
@@ -XXX,XX +XXX,XX @@ static inline uint8_t sub8_usat(uint8_t a, uint8_t b)
161
162
static inline uint8_t do_usad(uint8_t a, uint8_t b)
163
{
164
- if (a > b)
165
+ if (a > b) {
166
return a - b;
167
- else
168
+ } else {
169
return b - a;
170
+ }
171
}
172
173
/* Unsigned sum of absolute byte differences. */
174
@@ -XXX,XX +XXX,XX @@ uint32_t HELPER(sel_flags)(uint32_t flags, uint32_t a, uint32_t b)
175
uint32_t mask;
176
177
mask = 0;
178
- if (flags & 1)
179
+ if (flags & 1) {
180
mask |= 0xff;
181
- if (flags & 2)
182
+ }
183
+ if (flags & 2) {
184
mask |= 0xff00;
185
- if (flags & 4)
186
+ }
187
+ if (flags & 4) {
188
mask |= 0xff0000;
189
- if (flags & 8)
190
+ }
191
+ if (flags & 8) {
192
mask |= 0xff000000;
193
+ }
194
return (a & mask) | (b & ~mask);
195
}
72
196
73
--
197
--
74
2.20.1
198
2.25.1
75
76
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Fabiano Rosas <farosas@suse.de>
2
2
3
This is a minimalistic boot ROM written specifically for use with QEMU.
3
Signed-off-by: Fabiano Rosas <farosas@suse.de>
4
It supports loading the second-stage loader from SPI flash into RAM, SMP
4
Reviewed-by: Claudio Fontana <cfontana@suse.de>
5
boot, and not much else.
5
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
6
6
Message-id: 20221213190537.511-5-farosas@suse.de
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
10
Message-id: 20200911052101.2602693-7-hskinnemoen@google.com
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
8
---
13
.gitmodules | 3 +++
9
target/arm/m_helper.c | 16 ----------------
14
MAINTAINERS | 2 ++
10
1 file changed, 16 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
11
24
diff --git a/.gitmodules b/.gitmodules
12
diff --git a/target/arm/m_helper.c b/target/arm/m_helper.c
25
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
26
--- a/.gitmodules
14
--- a/target/arm/m_helper.c
27
+++ b/.gitmodules
15
+++ b/target/arm/m_helper.c
28
@@ -XXX,XX +XXX,XX @@
16
@@ -XXX,XX +XXX,XX @@
29
[submodule "meson"]
17
*/
30
    path = meson
18
31
    url = https://github.com/mesonbuild/meson/
19
#include "qemu/osdep.h"
32
+[submodule "roms/vbootrom"]
20
-#include "qemu/units.h"
33
+    path = roms/vbootrom
21
-#include "target/arm/idau.h"
34
+    url = https://github.com/google/vbootrom.git
22
-#include "trace.h"
35
diff --git a/MAINTAINERS b/MAINTAINERS
23
#include "cpu.h"
36
index XXXXXXX..XXXXXXX 100644
24
#include "internals.h"
37
--- a/MAINTAINERS
25
-#include "exec/gdbstub.h"
38
+++ b/MAINTAINERS
26
#include "exec/helper-proto.h"
39
@@ -XXX,XX +XXX,XX @@ L: qemu-arm@nongnu.org
27
-#include "qemu/host-utils.h"
40
S: Supported
28
#include "qemu/main-loop.h"
41
F: hw/*/npcm7xx*
29
#include "qemu/bitops.h"
42
F: include/hw/*/npcm7xx*
30
-#include "qemu/crc32c.h"
43
+F: pc-bios/npcm7xx_bootrom.bin
31
-#include "qemu/qemu-print.h"
44
+F: roms/vbootrom
32
#include "qemu/log.h"
45
33
#include "exec/exec-all.h"
46
nSeries
34
-#include <zlib.h> /* For crc32 */
47
M: Andrzej Zaborowski <balrogg@gmail.com>
35
-#include "semihosting/semihost.h"
48
diff --git a/pc-bios/README b/pc-bios/README
36
-#include "sysemu/cpus.h"
49
index XXXXXXX..XXXXXXX 100644
37
-#include "sysemu/kvm.h"
50
--- a/pc-bios/README
38
-#include "qemu/range.h"
51
+++ b/pc-bios/README
39
-#include "qapi/qapi-commands-machine-target.h"
52
@@ -XXX,XX +XXX,XX @@
40
-#include "qapi/error.h"
53
("Simplified BSD License" or "FreeBSD License", SPDX: BSD-2-Clause). OpenSBI
41
-#include "qemu/guest-random.h"
54
source code also contains code reused from other projects desribed here:
42
#ifdef CONFIG_TCG
55
https://github.com/riscv/opensbi/blob/master/ThirdPartyNotices.md.
43
-#include "arm_ldst.h"
56
+
44
#include "exec/cpu_ldst.h"
57
+- npcm7xx_bootrom.bin is a simplified, free (Apache 2.0) boot ROM for Nuvoton
45
#include "semihosting/common-semi.h"
58
+ NPCM7xx BMC devices. It currently implements the bare minimum to load, parse,
46
#endif
59
+ initialize and run boot images stored in SPI flash, but may grow more
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
--
47
--
136
2.20.1
48
2.25.1
137
138
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Fabiano Rosas <farosas@suse.de>
2
2
3
This adds two new machines, both supported by OpenBMC:
3
Signed-off-by: Fabiano Rosas <farosas@suse.de>
4
4
Reviewed-by: Claudio Fontana <cfontana@suse.de>
5
- npcm750-evb: Nuvoton NPCM750 Evaluation Board.
5
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
6
- quanta-gsj: A board with a NPCM730 chip.
6
Message-id: 20221213190537.511-6-farosas@suse.de
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>
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
25
---
8
---
26
default-configs/arm-softmmu.mak | 1 +
9
target/arm/helper.c | 7 -------
27
include/hw/arm/npcm7xx.h | 19 +++++
10
1 file changed, 7 deletions(-)
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
11
33
diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
12
diff --git a/target/arm/helper.c b/target/arm/helper.c
34
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
35
--- a/default-configs/arm-softmmu.mak
14
--- a/target/arm/helper.c
36
+++ b/default-configs/arm-softmmu.mak
15
+++ b/target/arm/helper.c
37
@@ -XXX,XX +XXX,XX @@ CONFIG_GUMSTIX=y
38
CONFIG_SPITZ=y
39
CONFIG_TOSA=y
40
CONFIG_Z2=y
41
+CONFIG_NPCM7XX=y
42
CONFIG_COLLIE=y
43
CONFIG_ASPEED_SOC=y
44
CONFIG_NETDUINO2=y
45
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
46
index XXXXXXX..XXXXXXX 100644
47
--- a/include/hw/arm/npcm7xx.h
48
+++ b/include/hw/arm/npcm7xx.h
49
@@ -XXX,XX +XXX,XX @@
16
@@ -XXX,XX +XXX,XX @@
50
#define NPCM7XX_SMP_BOOTREG_ADDR (0xf080013c) /* GCR.SCRPAD */
17
*/
51
#define NPCM7XX_GIC_CPU_IF_ADDR (0xf03fe100) /* GIC within A9 */
18
52
19
#include "qemu/osdep.h"
53
+typedef struct NPCM7xxMachine {
20
-#include "qemu/units.h"
54
+ MachineState parent;
21
#include "qemu/log.h"
55
+} NPCM7xxMachine;
22
#include "trace.h"
56
+
23
#include "cpu.h"
57
+#define TYPE_NPCM7XX_MACHINE MACHINE_TYPE_NAME("npcm7xx")
24
#include "internals.h"
58
+#define NPCM7XX_MACHINE(obj) \
25
#include "exec/helper-proto.h"
59
+ OBJECT_CHECK(NPCM7xxMachine, (obj), TYPE_NPCM7XX_MACHINE)
26
-#include "qemu/host-utils.h"
60
+
27
#include "qemu/main-loop.h"
61
+typedef struct NPCM7xxMachineClass {
28
#include "qemu/timer.h"
62
+ MachineClass parent;
29
#include "qemu/bitops.h"
63
+
64
+ const char *soc_type;
65
+} NPCM7xxMachineClass;
66
+
67
+#define NPCM7XX_MACHINE_CLASS(klass) \
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 @@
30
@@ -XXX,XX +XXX,XX @@
81
+/*
31
#include "exec/exec-all.h"
82
+ * Machine definitions for boards featuring an NPCM7xx SoC.
32
#include <zlib.h> /* For crc32 */
83
+ *
33
#include "hw/irq.h"
84
+ * Copyright 2020 Google LLC
34
-#include "semihosting/semihost.h"
85
+ *
35
-#include "sysemu/cpus.h"
86
+ * This program is free software; you can redistribute it and/or modify it
36
#include "sysemu/cpu-timers.h"
87
+ * under the terms of the GNU General Public License as published by the
37
#include "sysemu/kvm.h"
88
+ * Free Software Foundation; either version 2 of the License, or
38
-#include "qemu/range.h"
89
+ * (at your option) any later version.
39
#include "qapi/qapi-commands-machine-target.h"
90
+ *
40
#include "qapi/error.h"
91
+ * This program is distributed in the hope that it will be useful, but WITHOUT
41
#include "qemu/guest-random.h"
92
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
42
#ifdef CONFIG_TCG
93
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
43
-#include "arm_ldst.h"
94
+ * for more details.
44
-#include "exec/cpu_ldst.h"
95
+ */
45
#include "semihosting/common-semi.h"
96
+
46
#endif
97
+#include "qemu/osdep.h"
47
#include "cpregs.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
+ }
128
+
129
+ obj = object_new_with_props(nmc->soc_type, OBJECT(machine), "soc",
130
+ &error_abort, NULL);
131
+ object_property_set_uint(obj, "power-on-straps", hw_straps, &error_abort);
132
+
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
--
48
--
240
2.20.1
49
2.25.1
241
242
diff view generated by jsdifflib
1
Now that 32-bit KVM host support is gone, KVM can never
1
From: Claudio Fontana <cfontana@suse.de>
2
be enabled unless CONFIG_AARCH64 is true, and some code
3
paths are no longer reachable and can be deleted.
4
2
3
Remove some unused headers.
4
5
Signed-off-by: Claudio Fontana <cfontana@suse.de>
6
Acked-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Claudio Fontana <cfontana@suse.de>
8
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
9
Signed-off-by: Fabiano Rosas <farosas@suse.de>
10
Message-id: 20221213190537.511-7-farosas@suse.de
11
[added back some includes that are still needed at this point]
12
Signed-off-by: Fabiano Rosas <farosas@suse.de>
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
8
Message-id: 20200904154156.31943-3-peter.maydell@linaro.org
9
---
14
---
10
target/arm/kvm-consts.h | 7 ---
15
target/arm/cpu.c | 1 -
11
target/arm/kvm_arm.h | 6 ---
16
target/arm/cpu64.c | 6 ------
12
target/arm/cpu.c | 101 +++++++++++++++++++---------------------
17
2 files changed, 7 deletions(-)
13
target/arm/kvm.c | 7 ---
14
4 files changed, 47 insertions(+), 74 deletions(-)
15
18
16
diff --git a/target/arm/kvm-consts.h b/target/arm/kvm-consts.h
17
index XXXXXXX..XXXXXXX 100644
18
--- a/target/arm/kvm-consts.h
19
+++ b/target/arm/kvm-consts.h
20
@@ -XXX,XX +XXX,XX @@ MISMATCH_CHECK(QEMU_PSCI_RET_DISABLED, PSCI_RET_DISABLED);
21
*/
22
#define QEMU_KVM_ARM_TARGET_NONE UINT_MAX
23
24
-#ifdef TARGET_AARCH64
25
MISMATCH_CHECK(QEMU_KVM_ARM_TARGET_AEM_V8, KVM_ARM_TARGET_AEM_V8);
26
MISMATCH_CHECK(QEMU_KVM_ARM_TARGET_FOUNDATION_V8, KVM_ARM_TARGET_FOUNDATION_V8);
27
MISMATCH_CHECK(QEMU_KVM_ARM_TARGET_CORTEX_A57, KVM_ARM_TARGET_CORTEX_A57);
28
MISMATCH_CHECK(QEMU_KVM_ARM_TARGET_XGENE_POTENZA, KVM_ARM_TARGET_XGENE_POTENZA);
29
MISMATCH_CHECK(QEMU_KVM_ARM_TARGET_CORTEX_A53, KVM_ARM_TARGET_CORTEX_A53);
30
-#else
31
-MISMATCH_CHECK(QEMU_KVM_ARM_TARGET_CORTEX_A15, KVM_ARM_TARGET_CORTEX_A15);
32
-MISMATCH_CHECK(QEMU_KVM_ARM_TARGET_CORTEX_A7, KVM_ARM_TARGET_CORTEX_A7);
33
-#endif
34
35
#define CP_REG_ARM64 0x6000000000000000ULL
36
#define CP_REG_ARM_COPROC_MASK 0x000000000FFF0000
37
@@ -XXX,XX +XXX,XX @@ MISMATCH_CHECK(QEMU_KVM_ARM_TARGET_CORTEX_A7, KVM_ARM_TARGET_CORTEX_A7);
38
/* No kernel define but it's useful to QEMU */
39
#define CP_REG_ARM64_SYSREG_CP (CP_REG_ARM64_SYSREG >> CP_REG_ARM_COPROC_SHIFT)
40
41
-#ifdef TARGET_AARCH64
42
MISMATCH_CHECK(CP_REG_ARM64, KVM_REG_ARM64);
43
MISMATCH_CHECK(CP_REG_ARM_COPROC_MASK, KVM_REG_ARM_COPROC_MASK);
44
MISMATCH_CHECK(CP_REG_ARM_COPROC_SHIFT, KVM_REG_ARM_COPROC_SHIFT);
45
@@ -XXX,XX +XXX,XX @@ MISMATCH_CHECK(CP_REG_ARM64_SYSREG_CRM_MASK, KVM_REG_ARM64_SYSREG_CRM_MASK);
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
{
60
if (kvm_irqchip_in_kernel()) {
61
-#ifdef TARGET_AARCH64
62
return "kvm-arm-gicv3";
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
19
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
72
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
73
--- a/target/arm/cpu.c
21
--- a/target/arm/cpu.c
74
+++ b/target/arm/cpu.c
22
+++ b/target/arm/cpu.c
75
@@ -XXX,XX +XXX,XX @@ static void cortex_a15_initfn(Object *obj)
23
@@ -XXX,XX +XXX,XX @@
76
}
24
#include "target/arm/idau.h"
77
25
#include "qemu/module.h"
78
#ifndef TARGET_AARCH64
26
#include "qapi/error.h"
79
-/* -cpu max: if KVM is enabled, like -cpu host (best possible with this host);
27
-#include "qapi/visitor.h"
80
- * otherwise, a CPU with as many features enabled as our emulation supports.
28
#include "cpu.h"
81
+/*
29
#ifdef CONFIG_TCG
82
+ * -cpu max: a CPU with as many features enabled as our emulation supports.
30
#include "hw/core/tcg-cpu-ops.h"
83
* The version of '-cpu max' for qemu-system-aarch64 is defined in cpu64.c;
31
diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
84
- * this only needs to handle 32 bits.
32
index XXXXXXX..XXXXXXX 100644
85
+ * this only needs to handle 32 bits, and need not care about KVM.
33
--- a/target/arm/cpu64.c
86
*/
34
+++ b/target/arm/cpu64.c
87
static void arm_max_initfn(Object *obj)
35
@@ -XXX,XX +XXX,XX @@
88
{
36
#include "qemu/osdep.h"
89
ARMCPU *cpu = ARM_CPU(obj);
37
#include "qapi/error.h"
90
38
#include "cpu.h"
91
- if (kvm_enabled()) {
39
-#ifdef CONFIG_TCG
92
- kvm_arm_set_cpu_features_from_host(cpu);
40
-#include "hw/core/tcg-cpu-ops.h"
93
- } else {
41
-#endif /* CONFIG_TCG */
94
- cortex_a15_initfn(obj);
42
#include "qemu/module.h"
95
+ cortex_a15_initfn(obj);
43
-#if !defined(CONFIG_USER_ONLY)
96
44
-#include "hw/loader.h"
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
45
-#endif
184
+ t = cpu->isar.id_mmfr4;
46
#include "sysemu/kvm.h"
185
+ t = FIELD_DP32(t, ID_MMFR4, HPDS, 1); /* AA32HPD */
47
#include "sysemu/hvf.h"
186
+ t = FIELD_DP32(t, ID_MMFR4, AC2, 1); /* ACTLR2, HACTLR2 */
48
#include "kvm_arm.h"
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
}
193
#endif
194
195
@@ -XXX,XX +XXX,XX @@ static void arm_host_initfn(Object *obj)
196
197
static const TypeInfo host_arm_cpu_type_info = {
198
.name = TYPE_ARM_HOST_CPU,
199
-#ifdef TARGET_AARCH64
200
.parent = TYPE_AARCH64_CPU,
201
-#else
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
}
214
215
-/* The #ifdef protections are until 32bit headers are imported and can
216
- * be removed once both 32 and 64 bit reach feature parity.
217
- */
218
void kvm_arch_update_guest_debug(CPUState *cs, struct kvm_guest_debug *dbg)
219
{
220
-#ifdef KVM_GUESTDBG_USE_SW_BP
221
if (kvm_sw_breakpoints_active(cs)) {
222
dbg->control |= KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_USE_SW_BP;
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
}
232
233
void kvm_arch_init_irq_routing(KVMState *s)
234
--
49
--
235
2.20.1
50
2.25.1
236
237
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
The Nuvoton NPCM7xx SoC family are used to implement Baseboard
3
The pointed MouseTransformInfo structure is accessed read-only.
4
Management Controllers in servers. While the family includes four SoCs,
5
this patch implements limited support for two of them: NPCM730 (targeted
6
for Data Center applications) and NPCM750 (targeted for Enterprise
7
applications).
8
4
9
This patch includes little more than the bare minimum needed to boot a
5
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
10
Linux kernel built with NPCM7xx support in direct-kernel mode:
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
11
7
Message-id: 20221220142520.24094-2-philmd@linaro.org
12
- Two Cortex-A9 CPU cores with built-in periperhals.
13
- Global Configuration Registers.
14
- Clock Management.
15
- 3 Timer Modules with 5 timers each.
16
- 4 serial ports.
17
18
The chips themselves have a lot more features, some of which will be
19
added to the model at a later stage.
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>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
29
---
9
---
30
include/hw/arm/npcm7xx.h | 85 ++++++++
10
include/hw/input/tsc2xxx.h | 4 ++--
31
hw/arm/npcm7xx.c | 407 +++++++++++++++++++++++++++++++++++++++
11
hw/input/tsc2005.c | 2 +-
32
hw/arm/Kconfig | 5 +
12
hw/input/tsc210x.c | 3 +--
33
hw/arm/meson.build | 1 +
13
3 files changed, 4 insertions(+), 5 deletions(-)
34
4 files changed, 498 insertions(+)
35
create mode 100644 include/hw/arm/npcm7xx.h
36
create mode 100644 hw/arm/npcm7xx.c
37
14
38
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
15
diff --git a/include/hw/input/tsc2xxx.h b/include/hw/input/tsc2xxx.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
+
62
+#include "hw/boards.h"
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
+{
234
+ /*
235
+ * The default smpboot stub halts the secondary CPU with a 'wfi'
236
+ * instruction, but the arch/arm/mach-npcm/platsmp.c in the Linux kernel
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
+ */
241
+ uint32_t smpboot[] = {
242
+ 0xe59f2018, /* ldr r2, bootreg_addr */
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
+
254
+ for (i = 0; i < ARRAY_SIZE(smpboot); i++) {
255
+ smpboot[i] = tswap32(smpboot[i]);
256
+ }
257
+
258
+ rom_add_blob_fixed("smpboot", smpboot, sizeof(smpboot),
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;
335
+ }
336
+ }
337
+
338
+ /* A9MPCORE peripherals. Can only fail if we pass bad parameters here. */
339
+ object_property_set_int(OBJECT(&s->a9mpcore), "num-cpu", nc->num_cpus,
340
+ &error_abort);
341
+ object_property_set_int(OBJECT(&s->a9mpcore), "num-irq", NPCM7XX_NUM_IRQ,
342
+ &error_abort);
343
+ sysbus_realize(SYS_BUS_DEVICE(&s->a9mpcore), &error_abort);
344
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->a9mpcore), 0, NPCM7XX_CPUP_BA);
345
+
346
+ for (i = 0; i < nc->num_cpus; i++) {
347
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->a9mpcore), i,
348
+ qdev_get_gpio_in(DEVICE(&s->cpu[i]), ARM_CPU_IRQ));
349
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->a9mpcore), i + nc->num_cpus,
350
+ qdev_get_gpio_in(DEVICE(&s->cpu[i]), ARM_CPU_FIQ));
351
+ }
352
+
353
+ /* L2 cache controller */
354
+ sysbus_create_simple("l2x0", NPCM7XX_L2C_BA, NULL);
355
+
356
+ /* System Global Control Registers (GCR). Can fail due to user input. */
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
16
index XXXXXXX..XXXXXXX 100644
544
--- a/hw/arm/Kconfig
17
--- a/include/hw/input/tsc2xxx.h
545
+++ b/hw/arm/Kconfig
18
+++ b/include/hw/input/tsc2xxx.h
546
@@ -XXX,XX +XXX,XX @@ config XLNX_VERSAL
19
@@ -XXX,XX +XXX,XX @@ uWireSlave *tsc2102_init(qemu_irq pint);
547
20
uWireSlave *tsc2301_init(qemu_irq penirq, qemu_irq kbirq, qemu_irq dav);
548
config NPCM7XX
21
I2SCodec *tsc210x_codec(uWireSlave *chip);
549
bool
22
uint32_t tsc210x_txrx(void *opaque, uint32_t value, int len);
550
+ select A9MPCORE
23
-void tsc210x_set_transform(uWireSlave *chip, MouseTransformInfo *info);
551
+ select ARM_GIC
24
+void tsc210x_set_transform(uWireSlave *chip, const MouseTransformInfo *info);
552
+ select PL310 # cache controller
25
void tsc210x_key_event(uWireSlave *chip, int key, int down);
553
+ select SERIAL
26
554
+ select UNIMP
27
/* tsc2005.c */
555
28
void *tsc2005_init(qemu_irq pintdav);
556
config FSL_IMX25
29
uint32_t tsc2005_txrx(void *opaque, uint32_t value, int len);
557
bool
30
-void tsc2005_set_transform(void *opaque, MouseTransformInfo *info);
558
diff --git a/hw/arm/meson.build b/hw/arm/meson.build
31
+void tsc2005_set_transform(void *opaque, const MouseTransformInfo *info);
32
33
#endif
34
diff --git a/hw/input/tsc2005.c b/hw/input/tsc2005.c
559
index XXXXXXX..XXXXXXX 100644
35
index XXXXXXX..XXXXXXX 100644
560
--- a/hw/arm/meson.build
36
--- a/hw/input/tsc2005.c
561
+++ b/hw/arm/meson.build
37
+++ b/hw/input/tsc2005.c
562
@@ -XXX,XX +XXX,XX @@ arm_ss.add(when: 'CONFIG_MICROBIT', if_true: files('microbit.c'))
38
@@ -XXX,XX +XXX,XX @@ void *tsc2005_init(qemu_irq pintdav)
563
arm_ss.add(when: 'CONFIG_MUSICPAL', if_true: files('musicpal.c'))
39
* from the touchscreen. Assuming 12-bit precision was used during
564
arm_ss.add(when: 'CONFIG_NETDUINO2', if_true: files('netduino2.c'))
40
* tslib calibration.
565
arm_ss.add(when: 'CONFIG_NETDUINOPLUS2', if_true: files('netduinoplus2.c'))
41
*/
566
+arm_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx.c'))
42
-void tsc2005_set_transform(void *opaque, MouseTransformInfo *info)
567
arm_ss.add(when: 'CONFIG_NSERIES', if_true: files('nseries.c'))
43
+void tsc2005_set_transform(void *opaque, const MouseTransformInfo *info)
568
arm_ss.add(when: 'CONFIG_SX1', if_true: files('omap_sx1.c'))
44
{
569
arm_ss.add(when: 'CONFIG_CHEETAH', if_true: files('palm.c'))
45
TSC2005State *s = (TSC2005State *) opaque;
46
47
diff --git a/hw/input/tsc210x.c b/hw/input/tsc210x.c
48
index XXXXXXX..XXXXXXX 100644
49
--- a/hw/input/tsc210x.c
50
+++ b/hw/input/tsc210x.c
51
@@ -XXX,XX +XXX,XX @@ I2SCodec *tsc210x_codec(uWireSlave *chip)
52
* from the touchscreen. Assuming 12-bit precision was used during
53
* tslib calibration.
54
*/
55
-void tsc210x_set_transform(uWireSlave *chip,
56
- MouseTransformInfo *info)
57
+void tsc210x_set_transform(uWireSlave *chip, const MouseTransformInfo *info)
58
{
59
TSC210xState *s = (TSC210xState *) chip->opaque;
60
#if 0
570
--
61
--
571
2.20.1
62
2.25.1
572
63
573
64
diff view generated by jsdifflib
1
From: Vikram Garhwal <fnu.vikram@xilinx.com>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
Connect CAN0 and CAN1 on the ZynqMP.
3
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
4
4
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
Reviewed-by: Francisco Iglesias <francisco.iglesias@xilinx.com>
5
Message-id: 20221220142520.24094-3-philmd@linaro.org
6
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
7
Signed-off-by: Vikram Garhwal <fnu.vikram@xilinx.com>
8
Message-id: 1597278668-339715-3-git-send-email-fnu.vikram@xilinx.com
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
7
---
11
include/hw/arm/xlnx-zynqmp.h | 8 ++++++++
8
hw/arm/nseries.c | 18 +++++++++---------
12
hw/arm/xlnx-zcu102.c | 20 ++++++++++++++++++++
9
1 file changed, 9 insertions(+), 9 deletions(-)
13
hw/arm/xlnx-zynqmp.c | 34 ++++++++++++++++++++++++++++++++++
14
3 files changed, 62 insertions(+)
15
10
16
diff --git a/include/hw/arm/xlnx-zynqmp.h b/include/hw/arm/xlnx-zynqmp.h
11
diff --git a/hw/arm/nseries.c b/hw/arm/nseries.c
17
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
18
--- a/include/hw/arm/xlnx-zynqmp.h
13
--- a/hw/arm/nseries.c
19
+++ b/include/hw/arm/xlnx-zynqmp.h
14
+++ b/hw/arm/nseries.c
20
@@ -XXX,XX +XXX,XX @@
15
@@ -XXX,XX +XXX,XX @@ static void n8x0_i2c_setup(struct n800_s *s)
21
#include "hw/intc/arm_gic.h"
16
}
22
#include "hw/net/cadence_gem.h"
17
23
#include "hw/char/cadence_uart.h"
18
/* Touchscreen and keypad controller */
24
+#include "hw/net/xlnx-zynqmp-can.h"
19
-static MouseTransformInfo n800_pointercal = {
25
#include "hw/ide/ahci.h"
20
+static const MouseTransformInfo n800_pointercal = {
26
#include "hw/sd/sdhci.h"
21
.x = 800,
27
#include "hw/ssi/xilinx_spips.h"
22
.y = 480,
28
@@ -XXX,XX +XXX,XX @@
23
.a = { 14560, -68, -3455208, -39, -9621, 35152972, 65536 },
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 {
46
47
CadenceGEMState gem[XLNX_ZYNQMP_NUM_GEMS];
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;
55
/* Has the RPU subsystem? */
56
bool has_rpu;
57
+
58
+ /* CAN bus. */
59
+ CanBusState *canbus[XLNX_ZYNQMP_NUM_CAN];
60
};
24
};
61
25
62
#endif
26
-static MouseTransformInfo n810_pointercal = {
63
diff --git a/hw/arm/xlnx-zcu102.c b/hw/arm/xlnx-zcu102.c
27
+static const MouseTransformInfo n810_pointercal = {
64
index XXXXXXX..XXXXXXX 100644
28
.x = 800,
65
--- a/hw/arm/xlnx-zcu102.c
29
.y = 480,
66
+++ b/hw/arm/xlnx-zcu102.c
30
.a = { 15041, 148, -4731056, 171, -10238, 35933380, 65536 },
67
@@ -XXX,XX +XXX,XX @@
31
@@ -XXX,XX +XXX,XX @@ static void n810_key_event(void *opaque, int keycode)
68
#include "sysemu/qtest.h"
32
69
#include "sysemu/device_tree.h"
33
#define M    0
70
#include "qom/object.h"
34
71
+#include "net/can_emu.h"
35
-static int n810_keys[0x80] = {
72
36
+static const int n810_keys[0x80] = {
73
struct XlnxZCU102 {
37
[0x01] = 16,    /* Q */
74
MachineState parent_obj;
38
[0x02] = 37,    /* K */
75
@@ -XXX,XX +XXX,XX @@ struct XlnxZCU102 {
39
[0x03] = 24,    /* O */
76
bool secure;
40
@@ -XXX,XX +XXX,XX @@ static void n8x0_usb_setup(struct n800_s *s)
77
bool virt;
41
/* Setup done before the main bootloader starts by some early setup code
78
42
* - used when we want to run the main bootloader in emulation. This
79
+ CanBusState *canbus[XLNX_ZYNQMP_NUM_CAN];
43
* isn't documented. */
80
+
44
-static uint32_t n800_pinout[104] = {
81
struct arm_boot_info binfo;
45
+static const uint32_t n800_pinout[104] = {
46
0x080f00d8, 0x00d40808, 0x03080808, 0x080800d0,
47
0x00dc0808, 0x0b0f0f00, 0x080800b4, 0x00c00808,
48
0x08080808, 0x180800c4, 0x00b80000, 0x08080808,
49
@@ -XXX,XX +XXX,XX @@ static void n8x0_boot_init(void *opaque)
50
#define OMAP_TAG_CBUS        0x4e03
51
#define OMAP_TAG_EM_ASIC_BB5    0x4e04
52
53
-static struct omap_gpiosw_info_s {
54
+static const struct omap_gpiosw_info_s {
55
const char *name;
56
int line;
57
int type;
58
@@ -XXX,XX +XXX,XX @@ static struct omap_gpiosw_info_s {
59
{ NULL }
82
};
60
};
83
typedef struct XlnxZCU102 XlnxZCU102;
61
84
@@ -XXX,XX +XXX,XX @@ static void xlnx_zcu102_init(MachineState *machine)
62
-static struct omap_partition_info_s {
85
object_property_set_bool(OBJECT(&s->soc), "virtualization", s->virt,
63
+static const struct omap_partition_info_s {
86
&error_fatal);
64
uint32_t offset;
87
65
uint32_t size;
88
+ for (i = 0; i < XLNX_ZYNQMP_NUM_CAN; i++) {
66
int mask;
89
+ gchar *bus_name = g_strdup_printf("canbus%d", i);
67
@@ -XXX,XX +XXX,XX @@ static struct omap_partition_info_s {
90
+
68
{ 0, 0, 0, NULL }
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
116
index XXXXXXX..XXXXXXX 100644
117
--- a/hw/arm/xlnx-zynqmp.c
118
+++ b/hw/arm/xlnx-zynqmp.c
119
@@ -XXX,XX +XXX,XX @@ static const int uart_intr[XLNX_ZYNQMP_NUM_UARTS] = {
120
21, 22,
121
};
69
};
122
70
123
+static const uint64_t can_addr[XLNX_ZYNQMP_NUM_CAN] = {
71
-static uint8_t n8x0_bd_addr[6] = { N8X0_BD_ADDR };
124
+ 0xFF060000, 0xFF070000,
72
+static const uint8_t n8x0_bd_addr[6] = { N8X0_BD_ADDR };
125
+};
73
126
+
74
static int n8x0_atag_setup(void *p, int model)
127
+static const int can_intr[XLNX_ZYNQMP_NUM_CAN] = {
75
{
128
+ 23, 24,
76
uint8_t *b;
129
+};
77
uint16_t *w;
130
+
78
uint32_t *l;
131
static const uint64_t sdhci_addr[XLNX_ZYNQMP_NUM_SDHCI] = {
79
- struct omap_gpiosw_info_s *gpiosw;
132
0xFF160000, 0xFF170000,
80
- struct omap_partition_info_s *partition;
133
};
81
+ const struct omap_gpiosw_info_s *gpiosw;
134
@@ -XXX,XX +XXX,XX @@ static void xlnx_zynqmp_init(Object *obj)
82
+ const struct omap_partition_info_s *partition;
135
TYPE_CADENCE_UART);
83
const char *tag;
136
}
84
137
85
w = p;
138
+ for (i = 0; i < XLNX_ZYNQMP_NUM_CAN; i++) {
139
+ object_initialize_child(obj, "can[*]", &s->can[i],
140
+ TYPE_XLNX_ZYNQMP_CAN);
141
+ }
142
+
143
object_initialize_child(obj, "sata", &s->sata, TYPE_SYSBUS_AHCI);
144
145
for (i = 0; i < XLNX_ZYNQMP_NUM_SDHCI; i++) {
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[] = {
171
DEFINE_PROP_BOOL("has_rpu", XlnxZynqMPState, has_rpu, false),
172
DEFINE_PROP_LINK("ddr-ram", XlnxZynqMPState, ddr_ram, TYPE_MEMORY_REGION,
173
MemoryRegion *),
174
+ 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
--
86
--
182
2.20.1
87
2.25.1
183
88
184
89
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
When booting directly into a kernel, bypassing the boot loader, the CPU and
3
Silent when compiling with -Wextra:
4
UART clocks are not set up correctly. This makes the system appear very
5
slow, and causes the initrd boot test to fail when optimization is off.
6
4
7
The UART clock must run at 24 MHz. The default 25 MHz reference clock
5
../hw/arm/nseries.c:1081:12: warning: missing field 'line' initializer [-Wmissing-field-initializers]
8
cannot achieve this, so switch to PLL2/2 @ 480 MHz, which works
6
{ NULL }
9
perfectly with the default /20 divider.
7
^
10
8
11
The CPU clock should run at 800 MHz, so switch it to PLL1/2. PLL1 runs
9
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
12
at 800 MHz by default, so we need to double the feedback divider as well
10
Message-id: 20221220142520.24094-4-philmd@linaro.org
13
to make it run at 1600 MHz (so PLL1/2 runs at 800 MHz).
11
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
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>
19
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.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>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
23
---
13
---
24
include/hw/arm/npcm7xx.h | 1 +
14
hw/arm/nseries.c | 10 ++++------
25
hw/arm/npcm7xx.c | 32 ++++++++++++++++++++++++++++++++
15
1 file changed, 4 insertions(+), 6 deletions(-)
26
2 files changed, 33 insertions(+)
27
16
28
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
17
diff --git a/hw/arm/nseries.c b/hw/arm/nseries.c
29
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
30
--- a/include/hw/arm/npcm7xx.h
19
--- a/hw/arm/nseries.c
31
+++ b/include/hw/arm/npcm7xx.h
20
+++ b/hw/arm/nseries.c
32
@@ -XXX,XX +XXX,XX @@
21
@@ -XXX,XX +XXX,XX @@ static const struct omap_gpiosw_info_s {
33
#define NPCM7XX_SMP_LOADER_START (0xffff0000) /* Boot ROM */
22
"headphone", N8X0_HEADPHONE_GPIO,
34
#define NPCM7XX_SMP_BOOTREG_ADDR (0xf080013c) /* GCR.SCRPAD */
23
OMAP_GPIOSW_TYPE_CONNECTION | OMAP_GPIOSW_INVERTED,
35
#define NPCM7XX_GIC_CPU_IF_ADDR (0xf03fe100) /* GIC within A9 */
36
+#define NPCM7XX_BOARD_SETUP_ADDR (0xffff1000) /* Boot ROM */
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
},
24
},
25
- { NULL }
26
+ { /* end of list */ }
27
}, n810_gpiosw_info[] = {
28
{
29
"gps_reset", N810_GPS_RESET_GPIO,
30
@@ -XXX,XX +XXX,XX @@ static const struct omap_gpiosw_info_s {
31
"slide", N810_SLIDE_GPIO,
32
OMAP_GPIOSW_TYPE_COVER | OMAP_GPIOSW_INVERTED,
33
},
34
- { NULL }
35
+ { /* end of list */ }
60
};
36
};
61
37
62
+static void npcm7xx_write_board_setup(ARMCPU *cpu,
38
static const struct omap_partition_info_s {
63
+ const struct arm_boot_info *info)
39
@@ -XXX,XX +XXX,XX @@ static const struct omap_partition_info_s {
64
+{
40
{ 0x00080000, 0x00200000, 0x0, "kernel" },
65
+ uint32_t board_setup[] = {
41
{ 0x00280000, 0x00200000, 0x3, "initfs" },
66
+ 0xe59f0010, /* ldr r0, clk_base_addr */
42
{ 0x00480000, 0x0fb80000, 0x3, "rootfs" },
67
+ 0xe59f1010, /* ldr r1, pllcon1_value */
43
-
68
+ 0xe5801010, /* str r1, [r0, #16] */
44
- { 0, 0, 0, NULL }
69
+ 0xe59f100c, /* ldr r1, clksel_value */
45
+ { /* end of list */ }
70
+ 0xe5801004, /* str r1, [r0, #4] */
46
}, n810_part_info[] = {
71
+ 0xe12fff1e, /* bx lr */
47
{ 0x00000000, 0x00020000, 0x3, "bootloader" },
72
+ NPCM7XX_CLK_BA,
48
{ 0x00020000, 0x00060000, 0x0, "config" },
73
+ NPCM7XX_PLLCON1_FIXUP_VAL,
49
{ 0x00080000, 0x00220000, 0x0, "kernel" },
74
+ NPCM7XX_CLKSEL_FIXUP_VAL,
50
{ 0x002a0000, 0x00400000, 0x0, "initfs" },
75
+ };
51
{ 0x006a0000, 0x0f960000, 0x0, "rootfs" },
76
+ int i;
52
-
77
+
53
- { 0, 0, 0, NULL }
78
+ for (i = 0; i < ARRAY_SIZE(board_setup); i++) {
54
+ { /* end of list */ }
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
};
55
};
95
56
96
void npcm7xx_load_kernel(MachineState *machine, NPCM7xxState *soc)
57
static const uint8_t n8x0_bd_addr[6] = { N8X0_BD_ADDR };
97
--
58
--
98
2.20.1
59
2.25.1
99
60
100
61
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Zhuojia Shen <chaosdefinition@hotmail.com>
2
2
3
Only argument set members have to be C identifiers, everything
3
In CPUID registers exposed to userspace, some registers were missing
4
else gets prefixed during conversion to C. Some places just
4
and some fields were not exposed. This patch aligns exposed ID
5
checked the leading character, and some places matched a leading
5
registers and their fields with what the upstream kernel currently
6
character plus a C identifier.
6
exposes.
7
7
8
Convert everything to match full identifiers, including the
8
Specifically, the following new ID registers/fields are exposed to
9
[&%@&] prefix, and drop the full C identifier requirement.
9
userspace:
10
10
11
Reported-by: Peter Maydell <peter.maydell@linaro.org>
11
ID_AA64PFR1_EL1.BT: bits 3-0
12
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
12
ID_AA64PFR1_EL1.MTE: bits 11-8
13
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
13
ID_AA64PFR1_EL1.SME: bits 27-24
14
Message-id: 20200903192334.1603773-1-richard.henderson@linaro.org
14
15
ID_AA64ZFR0_EL1.SVEver: bits 3-0
16
ID_AA64ZFR0_EL1.AES: bits 7-4
17
ID_AA64ZFR0_EL1.BitPerm: bits 19-16
18
ID_AA64ZFR0_EL1.BF16: bits 23-20
19
ID_AA64ZFR0_EL1.SHA3: bits 35-32
20
ID_AA64ZFR0_EL1.SM4: bits 43-40
21
ID_AA64ZFR0_EL1.I8MM: bits 47-44
22
ID_AA64ZFR0_EL1.F32MM: bits 55-52
23
ID_AA64ZFR0_EL1.F64MM: bits 59-56
24
25
ID_AA64SMFR0_EL1.F32F32: bit 32
26
ID_AA64SMFR0_EL1.B16F32: bit 34
27
ID_AA64SMFR0_EL1.F16F32: bit 35
28
ID_AA64SMFR0_EL1.I8I32: bits 39-36
29
ID_AA64SMFR0_EL1.F64F64: bit 48
30
ID_AA64SMFR0_EL1.I16I64: bits 55-52
31
ID_AA64SMFR0_EL1.FA64: bit 63
32
33
ID_AA64MMFR0_EL1.ECV: bits 63-60
34
35
ID_AA64MMFR1_EL1.AFP: bits 47-44
36
37
ID_AA64MMFR2_EL1.AT: bits 35-32
38
39
ID_AA64ISAR0_EL1.RNDR: bits 63-60
40
41
ID_AA64ISAR1_EL1.FRINTTS: bits 35-32
42
ID_AA64ISAR1_EL1.BF16: bits 47-44
43
ID_AA64ISAR1_EL1.DGH: bits 51-48
44
ID_AA64ISAR1_EL1.I8MM: bits 55-52
45
46
ID_AA64ISAR2_EL1.WFxT: bits 3-0
47
ID_AA64ISAR2_EL1.RPRES: bits 7-4
48
ID_AA64ISAR2_EL1.GPA3: bits 11-8
49
ID_AA64ISAR2_EL1.APA3: bits 15-12
50
51
The code is also refactored to use symbolic names for ID register fields
52
for better readability and maintainability.
53
54
The test case in tests/tcg/aarch64/sysregs.c is also updated to match
55
the intended behavior.
56
57
Signed-off-by: Zhuojia Shen <chaosdefinition@hotmail.com>
58
Message-id: DS7PR12MB6309FB585E10772928F14271ACE79@DS7PR12MB6309.namprd12.prod.outlook.com
59
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
60
[PMM: use Sn_n_Cn_Cn_n syntax to work with older assemblers
61
that don't recognize id_aa64isar2_el1 and id_aa64mmfr2_el1]
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
62
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
---
63
---
17
tests/decode/succ_ident1.decode | 7 +++++
64
target/arm/helper.c | 96 +++++++++++++++++++++++++------
18
scripts/decodetree.py | 46 +++++++++++++++++++++------------
65
tests/tcg/aarch64/sysregs.c | 24 ++++++--
19
2 files changed, 37 insertions(+), 16 deletions(-)
66
tests/tcg/aarch64/Makefile.target | 7 ++-
20
create mode 100644 tests/decode/succ_ident1.decode
67
3 files changed, 103 insertions(+), 24 deletions(-)
21
68
22
diff --git a/tests/decode/succ_ident1.decode b/tests/decode/succ_ident1.decode
69
diff --git a/target/arm/helper.c b/target/arm/helper.c
23
new file mode 100644
70
index XXXXXXX..XXXXXXX 100644
24
index XXXXXXX..XXXXXXX
71
--- a/target/arm/helper.c
25
--- /dev/null
72
+++ b/target/arm/helper.c
26
+++ b/tests/decode/succ_ident1.decode
73
@@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu)
74
#ifdef CONFIG_USER_ONLY
75
static const ARMCPRegUserSpaceInfo v8_user_idregs[] = {
76
{ .name = "ID_AA64PFR0_EL1",
77
- .exported_bits = 0x000f000f00ff0000,
78
- .fixed_bits = 0x0000000000000011 },
79
+ .exported_bits = R_ID_AA64PFR0_FP_MASK |
80
+ R_ID_AA64PFR0_ADVSIMD_MASK |
81
+ R_ID_AA64PFR0_SVE_MASK |
82
+ R_ID_AA64PFR0_DIT_MASK,
83
+ .fixed_bits = (0x1u << R_ID_AA64PFR0_EL0_SHIFT) |
84
+ (0x1u << R_ID_AA64PFR0_EL1_SHIFT) },
85
{ .name = "ID_AA64PFR1_EL1",
86
- .exported_bits = 0x00000000000000f0 },
87
+ .exported_bits = R_ID_AA64PFR1_BT_MASK |
88
+ R_ID_AA64PFR1_SSBS_MASK |
89
+ R_ID_AA64PFR1_MTE_MASK |
90
+ R_ID_AA64PFR1_SME_MASK },
91
{ .name = "ID_AA64PFR*_EL1_RESERVED",
92
- .is_glob = true },
93
- { .name = "ID_AA64ZFR0_EL1" },
94
+ .is_glob = true },
95
+ { .name = "ID_AA64ZFR0_EL1",
96
+ .exported_bits = R_ID_AA64ZFR0_SVEVER_MASK |
97
+ R_ID_AA64ZFR0_AES_MASK |
98
+ R_ID_AA64ZFR0_BITPERM_MASK |
99
+ R_ID_AA64ZFR0_BFLOAT16_MASK |
100
+ R_ID_AA64ZFR0_SHA3_MASK |
101
+ R_ID_AA64ZFR0_SM4_MASK |
102
+ R_ID_AA64ZFR0_I8MM_MASK |
103
+ R_ID_AA64ZFR0_F32MM_MASK |
104
+ R_ID_AA64ZFR0_F64MM_MASK },
105
+ { .name = "ID_AA64SMFR0_EL1",
106
+ .exported_bits = R_ID_AA64SMFR0_F32F32_MASK |
107
+ R_ID_AA64SMFR0_B16F32_MASK |
108
+ R_ID_AA64SMFR0_F16F32_MASK |
109
+ R_ID_AA64SMFR0_I8I32_MASK |
110
+ R_ID_AA64SMFR0_F64F64_MASK |
111
+ R_ID_AA64SMFR0_I16I64_MASK |
112
+ R_ID_AA64SMFR0_FA64_MASK },
113
{ .name = "ID_AA64MMFR0_EL1",
114
- .fixed_bits = 0x00000000ff000000 },
115
- { .name = "ID_AA64MMFR1_EL1" },
116
+ .exported_bits = R_ID_AA64MMFR0_ECV_MASK,
117
+ .fixed_bits = (0xfu << R_ID_AA64MMFR0_TGRAN64_SHIFT) |
118
+ (0xfu << R_ID_AA64MMFR0_TGRAN4_SHIFT) },
119
+ { .name = "ID_AA64MMFR1_EL1",
120
+ .exported_bits = R_ID_AA64MMFR1_AFP_MASK },
121
+ { .name = "ID_AA64MMFR2_EL1",
122
+ .exported_bits = R_ID_AA64MMFR2_AT_MASK },
123
{ .name = "ID_AA64MMFR*_EL1_RESERVED",
124
- .is_glob = true },
125
+ .is_glob = true },
126
{ .name = "ID_AA64DFR0_EL1",
127
- .fixed_bits = 0x0000000000000006 },
128
- { .name = "ID_AA64DFR1_EL1" },
129
+ .fixed_bits = (0x6u << R_ID_AA64DFR0_DEBUGVER_SHIFT) },
130
+ { .name = "ID_AA64DFR1_EL1" },
131
{ .name = "ID_AA64DFR*_EL1_RESERVED",
132
- .is_glob = true },
133
+ .is_glob = true },
134
{ .name = "ID_AA64AFR*",
135
- .is_glob = true },
136
+ .is_glob = true },
137
{ .name = "ID_AA64ISAR0_EL1",
138
- .exported_bits = 0x00fffffff0fffff0 },
139
+ .exported_bits = R_ID_AA64ISAR0_AES_MASK |
140
+ R_ID_AA64ISAR0_SHA1_MASK |
141
+ R_ID_AA64ISAR0_SHA2_MASK |
142
+ R_ID_AA64ISAR0_CRC32_MASK |
143
+ R_ID_AA64ISAR0_ATOMIC_MASK |
144
+ R_ID_AA64ISAR0_RDM_MASK |
145
+ R_ID_AA64ISAR0_SHA3_MASK |
146
+ R_ID_AA64ISAR0_SM3_MASK |
147
+ R_ID_AA64ISAR0_SM4_MASK |
148
+ R_ID_AA64ISAR0_DP_MASK |
149
+ R_ID_AA64ISAR0_FHM_MASK |
150
+ R_ID_AA64ISAR0_TS_MASK |
151
+ R_ID_AA64ISAR0_RNDR_MASK },
152
{ .name = "ID_AA64ISAR1_EL1",
153
- .exported_bits = 0x000000f0ffffffff },
154
+ .exported_bits = R_ID_AA64ISAR1_DPB_MASK |
155
+ R_ID_AA64ISAR1_APA_MASK |
156
+ R_ID_AA64ISAR1_API_MASK |
157
+ R_ID_AA64ISAR1_JSCVT_MASK |
158
+ R_ID_AA64ISAR1_FCMA_MASK |
159
+ R_ID_AA64ISAR1_LRCPC_MASK |
160
+ R_ID_AA64ISAR1_GPA_MASK |
161
+ R_ID_AA64ISAR1_GPI_MASK |
162
+ R_ID_AA64ISAR1_FRINTTS_MASK |
163
+ R_ID_AA64ISAR1_SB_MASK |
164
+ R_ID_AA64ISAR1_BF16_MASK |
165
+ R_ID_AA64ISAR1_DGH_MASK |
166
+ R_ID_AA64ISAR1_I8MM_MASK },
167
+ { .name = "ID_AA64ISAR2_EL1",
168
+ .exported_bits = R_ID_AA64ISAR2_WFXT_MASK |
169
+ R_ID_AA64ISAR2_RPRES_MASK |
170
+ R_ID_AA64ISAR2_GPA3_MASK |
171
+ R_ID_AA64ISAR2_APA3_MASK },
172
{ .name = "ID_AA64ISAR*_EL1_RESERVED",
173
- .is_glob = true },
174
+ .is_glob = true },
175
};
176
modify_arm_cp_regs(v8_idregs, v8_user_idregs);
177
#endif
178
@@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu)
179
#ifdef CONFIG_USER_ONLY
180
static const ARMCPRegUserSpaceInfo id_v8_user_midr_cp_reginfo[] = {
181
{ .name = "MIDR_EL1",
182
- .exported_bits = 0x00000000ffffffff },
183
- { .name = "REVIDR_EL1" },
184
+ .exported_bits = R_MIDR_EL1_REVISION_MASK |
185
+ R_MIDR_EL1_PARTNUM_MASK |
186
+ R_MIDR_EL1_ARCHITECTURE_MASK |
187
+ R_MIDR_EL1_VARIANT_MASK |
188
+ R_MIDR_EL1_IMPLEMENTER_MASK },
189
+ { .name = "REVIDR_EL1" },
190
};
191
modify_arm_cp_regs(id_v8_midr_cp_reginfo, id_v8_user_midr_cp_reginfo);
192
#endif
193
diff --git a/tests/tcg/aarch64/sysregs.c b/tests/tcg/aarch64/sysregs.c
194
index XXXXXXX..XXXXXXX 100644
195
--- a/tests/tcg/aarch64/sysregs.c
196
+++ b/tests/tcg/aarch64/sysregs.c
27
@@ -XXX,XX +XXX,XX @@
197
@@ -XXX,XX +XXX,XX @@
28
+%1f 0:8
198
#define HWCAP_CPUID (1 << 11)
29
+%2f 8:8
199
#endif
30
+%3f 16:8
200
201
+/*
202
+ * Older assemblers don't recognize newer system register names,
203
+ * but we can still access them by the Sn_n_Cn_Cn_n syntax.
204
+ */
205
+#define SYS_ID_AA64ISAR2_EL1 S3_0_C0_C6_2
206
+#define SYS_ID_AA64MMFR2_EL1 S3_0_C0_C7_2
31
+
207
+
32
+&3arg a b c
208
int failed_bit_count;
33
+@3arg ........ ........ ........ ........ &3arg a=%1f b=%2f c=%3f
209
34
+3insn 00000000 ........ ........ ........ @3arg
210
/* Read and print system register `id' value */
35
diff --git a/scripts/decodetree.py b/scripts/decodetree.py
211
@@ -XXX,XX +XXX,XX @@ int main(void)
212
* minimum valid fields - for the purposes of this check allowed
213
* to have non-zero values.
214
*/
215
- get_cpu_reg_check_mask(id_aa64isar0_el1, _m(00ff,ffff,f0ff,fff0));
216
- get_cpu_reg_check_mask(id_aa64isar1_el1, _m(0000,00f0,ffff,ffff));
217
+ get_cpu_reg_check_mask(id_aa64isar0_el1, _m(f0ff,ffff,f0ff,fff0));
218
+ get_cpu_reg_check_mask(id_aa64isar1_el1, _m(00ff,f0ff,ffff,ffff));
219
+ get_cpu_reg_check_mask(SYS_ID_AA64ISAR2_EL1, _m(0000,0000,0000,ffff));
220
/* TGran4 & TGran64 as pegged to -1 */
221
- get_cpu_reg_check_mask(id_aa64mmfr0_el1, _m(0000,0000,ff00,0000));
222
- get_cpu_reg_check_zero(id_aa64mmfr1_el1);
223
+ get_cpu_reg_check_mask(id_aa64mmfr0_el1, _m(f000,0000,ff00,0000));
224
+ get_cpu_reg_check_mask(id_aa64mmfr1_el1, _m(0000,f000,0000,0000));
225
+ get_cpu_reg_check_mask(SYS_ID_AA64MMFR2_EL1, _m(0000,000f,0000,0000));
226
/* EL1/EL0 reported as AA64 only */
227
get_cpu_reg_check_mask(id_aa64pfr0_el1, _m(000f,000f,00ff,0011));
228
- get_cpu_reg_check_mask(id_aa64pfr1_el1, _m(0000,0000,0000,00f0));
229
+ get_cpu_reg_check_mask(id_aa64pfr1_el1, _m(0000,0000,0f00,0fff));
230
/* all hidden, DebugVer fixed to 0x6 (ARMv8 debug architecture) */
231
get_cpu_reg_check_mask(id_aa64dfr0_el1, _m(0000,0000,0000,0006));
232
get_cpu_reg_check_zero(id_aa64dfr1_el1);
233
- get_cpu_reg_check_zero(id_aa64zfr0_el1);
234
+ get_cpu_reg_check_mask(id_aa64zfr0_el1, _m(0ff0,ff0f,00ff,00ff));
235
+#ifdef HAS_ARMV9_SME
236
+ get_cpu_reg_check_mask(id_aa64smfr0_el1, _m(80f1,00fd,0000,0000));
237
+#endif
238
239
get_cpu_reg_check_zero(id_aa64afr0_el1);
240
get_cpu_reg_check_zero(id_aa64afr1_el1);
241
diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target
36
index XXXXXXX..XXXXXXX 100644
242
index XXXXXXX..XXXXXXX 100644
37
--- a/scripts/decodetree.py
243
--- a/tests/tcg/aarch64/Makefile.target
38
+++ b/scripts/decodetree.py
244
+++ b/tests/tcg/aarch64/Makefile.target
39
@@ -XXX,XX +XXX,XX @@ output_fd = None
245
@@ -XXX,XX +XXX,XX @@ config-cc.mak: Makefile
40
insntype = 'uint32_t'
246
     $(call cc-option,-march=armv8.1-a+sve2, CROSS_CC_HAS_SVE2); \
41
decode_function = 'decode'
247
     $(call cc-option,-march=armv8.3-a, CROSS_CC_HAS_ARMV8_3); \
42
248
     $(call cc-option,-mbranch-protection=standard, CROSS_CC_HAS_ARMV8_BTI); \
43
-re_ident = '[a-zA-Z][a-zA-Z0-9_]*'
249
-     $(call cc-option,-march=armv8.5-a+memtag, CROSS_CC_HAS_ARMV8_MTE)) 3> config-cc.mak
44
+# An identifier for C.
250
+     $(call cc-option,-march=armv8.5-a+memtag, CROSS_CC_HAS_ARMV8_MTE); \
45
+re_C_ident = '[a-zA-Z][a-zA-Z0-9_]*'
251
+     $(call cc-option,-march=armv9-a+sme, CROSS_CC_HAS_ARMV9_SME)) 3> config-cc.mak
46
252
-include config-cc.mak
47
+# Identifiers for Arguments, Fields, Formats and Patterns.
253
48
+re_arg_ident = '&[a-zA-Z0-9_]*'
254
# Pauth Tests
49
+re_fld_ident = '%[a-zA-Z0-9_]*'
255
@@ -XXX,XX +XXX,XX @@ endif
50
+re_fmt_ident = '@[a-zA-Z0-9_]*'
256
ifneq ($(CROSS_CC_HAS_SVE),)
51
+re_pat_ident = '[a-zA-Z0-9_]*'
257
# System Registers Tests
52
258
AARCH64_TESTS += sysregs
53
def error_with_file(file, lineno, *args):
259
+ifneq ($(CROSS_CC_HAS_ARMV9_SME),)
54
"""Print an error message from file:line and args and exit."""
260
+sysregs: CFLAGS+=-march=armv9-a+sme -DHAS_ARMV9_SME
55
@@ -XXX,XX +XXX,XX @@ class ExcMultiPattern(MultiPattern):
261
+else
56
def parse_field(lineno, name, toks):
262
sysregs: CFLAGS+=-march=armv8.1-a+sve
57
"""Parse one instruction field from TOKS at LINENO"""
263
+endif
58
global fields
264
59
- global re_ident
265
# SVE ioctl test
60
global insnwidth
266
AARCH64_TESTS += sve-ioctls
61
62
# A "simple" field will have only one entry;
63
@@ -XXX,XX +XXX,XX @@ def parse_field(lineno, name, toks):
64
width = 0
65
func = None
66
for t in toks:
67
- if re.fullmatch('!function=' + re_ident, t):
68
+ if re.match('^!function=', t):
69
if func:
70
error(lineno, 'duplicate function')
71
func = t.split('=')
72
@@ -XXX,XX +XXX,XX @@ def parse_field(lineno, name, toks):
73
def parse_arguments(lineno, name, toks):
74
"""Parse one argument set from TOKS at LINENO"""
75
global arguments
76
- global re_ident
77
+ global re_C_ident
78
global anyextern
79
80
flds = []
81
@@ -XXX,XX +XXX,XX @@ def parse_arguments(lineno, name, toks):
82
extern = True
83
anyextern = True
84
continue
85
- if not re.fullmatch(re_ident, t):
86
+ if not re.fullmatch(re_C_ident, t):
87
error(lineno, 'invalid argument set token "{0}"'.format(t))
88
if t in flds:
89
error(lineno, 'duplicate argument "{0}"'.format(t))
90
@@ -XXX,XX +XXX,XX @@ def parse_generic(lineno, parent_pat, name, toks):
91
global arguments
92
global formats
93
global allpatterns
94
- global re_ident
95
+ global re_arg_ident
96
+ global re_fld_ident
97
+ global re_fmt_ident
98
+ global re_C_ident
99
global insnwidth
100
global insnmask
101
global variablewidth
102
@@ -XXX,XX +XXX,XX @@ def parse_generic(lineno, parent_pat, name, toks):
103
fmt = None
104
for t in toks:
105
# '&Foo' gives a format an explcit argument set.
106
- if t[0] == '&':
107
+ if re.fullmatch(re_arg_ident, t):
108
tt = t[1:]
109
if arg:
110
error(lineno, 'multiple argument sets')
111
@@ -XXX,XX +XXX,XX @@ def parse_generic(lineno, parent_pat, name, toks):
112
continue
113
114
# '@Foo' gives a pattern an explicit format.
115
- if t[0] == '@':
116
+ if re.fullmatch(re_fmt_ident, t):
117
tt = t[1:]
118
if fmt:
119
error(lineno, 'multiple formats')
120
@@ -XXX,XX +XXX,XX @@ def parse_generic(lineno, parent_pat, name, toks):
121
continue
122
123
# '%Foo' imports a field.
124
- if t[0] == '%':
125
+ if re.fullmatch(re_fld_ident, t):
126
tt = t[1:]
127
flds = add_field_byname(lineno, flds, tt, tt)
128
continue
129
130
# 'Foo=%Bar' imports a field with a different name.
131
- if re.fullmatch(re_ident + '=%' + re_ident, t):
132
+ if re.fullmatch(re_C_ident + '=' + re_fld_ident, t):
133
(fname, iname) = t.split('=%')
134
flds = add_field_byname(lineno, flds, fname, iname)
135
continue
136
137
# 'Foo=number' sets an argument field to a constant value
138
- if re.fullmatch(re_ident + '=[+-]?[0-9]+', t):
139
+ if re.fullmatch(re_C_ident + '=[+-]?[0-9]+', t):
140
(fname, value) = t.split('=')
141
value = int(value)
142
flds = add_field(lineno, flds, fname, ConstField(value))
143
@@ -XXX,XX +XXX,XX @@ def parse_generic(lineno, parent_pat, name, toks):
144
fixedmask = (fixedmask << shift) | fms
145
undefmask = (undefmask << shift) | ubm
146
# Otherwise, fieldname:fieldwidth
147
- elif re.fullmatch(re_ident + ':s?[0-9]+', t):
148
+ elif re.fullmatch(re_C_ident + ':s?[0-9]+', t):
149
(fname, flen) = t.split(':')
150
sign = False
151
if flen[0] == 's':
152
@@ -XXX,XX +XXX,XX @@ def parse_generic(lineno, parent_pat, name, toks):
153
154
def parse_file(f, parent_pat):
155
"""Parse all of the patterns within a file"""
156
+ global re_arg_ident
157
+ global re_fld_ident
158
+ global re_fmt_ident
159
+ global re_pat_ident
160
161
# Read all of the lines of the file. Concatenate lines
162
# ending in backslash; discard empty lines and comments.
163
@@ -XXX,XX +XXX,XX @@ def parse_file(f, parent_pat):
164
continue
165
166
# Determine the type of object needing to be parsed.
167
- if name[0] == '%':
168
+ if re.fullmatch(re_fld_ident, name):
169
parse_field(start_lineno, name[1:], toks)
170
- elif name[0] == '&':
171
+ elif re.fullmatch(re_arg_ident, name):
172
parse_arguments(start_lineno, name[1:], toks)
173
- elif name[0] == '@':
174
+ elif re.fullmatch(re_fmt_ident, name):
175
parse_generic(start_lineno, None, name[1:], toks)
176
- else:
177
+ elif re.fullmatch(re_pat_ident, name):
178
parse_generic(start_lineno, parent_pat, name, toks)
179
+ else:
180
+ error(lineno, 'invalid token "{0}"'.format(name))
181
toks = []
182
183
if nesting != 0:
184
--
267
--
185
2.20.1
268
2.25.1
186
187
diff view generated by jsdifflib
1
Implement a model of the MPS2 with the AN500 firmware. This is
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
similar to the AN385, with the following differences:
3
* Cortex-M7 CPU
4
* PSRAM is at 0x6000_0000
5
* Ethernet is at 0xa000_0000
6
* No zbt_boot_ctrl remapping of the low 16K
7
(but QEMU doesn't implement this anyway)
8
* no "block RAM" at 0x01000000
9
2
3
This function is not used anywhere outside this file,
4
so we can make the function "static void".
5
6
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Reviewed-by: Eric Auger <eric.auger@redhat.com>
9
Message-id: 20221216214924.4711-2-philmd@linaro.org
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
12
Message-id: 20200903202048.15370-3-peter.maydell@linaro.org
13
---
11
---
14
docs/system/arm/mps2.rst | 6 ++--
12
include/hw/arm/smmu-common.h | 3 ---
15
hw/arm/mps2.c | 67 +++++++++++++++++++++++++++++++++-------
13
hw/arm/smmu-common.c | 2 +-
16
2 files changed, 60 insertions(+), 13 deletions(-)
14
2 files changed, 1 insertion(+), 4 deletions(-)
17
15
18
diff --git a/docs/system/arm/mps2.rst b/docs/system/arm/mps2.rst
16
diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h
19
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
20
--- a/docs/system/arm/mps2.rst
18
--- a/include/hw/arm/smmu-common.h
21
+++ b/docs/system/arm/mps2.rst
19
+++ b/include/hw/arm/smmu-common.h
22
@@ -XXX,XX +XXX,XX @@
20
@@ -XXX,XX +XXX,XX @@ void smmu_iotlb_inv_iova(SMMUState *s, int asid, dma_addr_t iova,
23
-Arm MPS2 boards (``mps2-an385``, ``mps2-an386``, ``mps2-an505``, ``mps2-an511``, ``mps2-an521``)
21
/* Unmap the range of all the notifiers registered to any IOMMU mr */
24
-================================================================================================
22
void smmu_inv_notifiers_all(SMMUState *s);
25
+Arm MPS2 boards (``mps2-an385``, ``mps2-an386``, ``mps2-an500``, ``mps2-an505``, ``mps2-an511``, ``mps2-an521``)
23
26
+================================================================================================================
24
-/* Unmap the range of all the notifiers registered to @mr */
27
25
-void smmu_inv_notifiers_mr(IOMMUMemoryRegion *mr);
28
These board models all use Arm M-profile CPUs.
26
-
29
27
#endif /* HW_ARM_SMMU_COMMON_H */
30
@@ -XXX,XX +XXX,XX @@ QEMU models the following FPGA images:
28
diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c
31
Cortex-M3 as documented in ARM Application Note AN385
32
``mps2-an386``
33
Cortex-M4 as documented in ARM Application Note AN386
34
+``mps2-an500``
35
+ Cortex-M7 as documented in ARM Application Note AN500
36
``mps2-an511``
37
Cortex-M3 'DesignStart' as documented in AN511
38
``mps2-an505``
39
diff --git a/hw/arm/mps2.c b/hw/arm/mps2.c
40
index XXXXXXX..XXXXXXX 100644
29
index XXXXXXX..XXXXXXX 100644
41
--- a/hw/arm/mps2.c
30
--- a/hw/arm/smmu-common.c
42
+++ b/hw/arm/mps2.c
31
+++ b/hw/arm/smmu-common.c
43
@@ -XXX,XX +XXX,XX @@
32
@@ -XXX,XX +XXX,XX @@ static void smmu_unmap_notifier_range(IOMMUNotifier *n)
44
* We model the following FPGA images:
45
* "mps2-an385" -- Cortex-M3 as documented in ARM Application Note AN385
46
* "mps2-an386" -- Cortex-M4 as documented in ARM Application Note AN386
47
+ * "mps2-an500" -- Cortex-M7 as documented in ARM Application Note AN500
48
* "mps2-an511" -- Cortex-M3 'DesignStart' as documented in AN511
49
*
50
* Links to the TRM for the board itself and to the various Application
51
@@ -XXX,XX +XXX,XX @@
52
typedef enum MPS2FPGAType {
53
FPGA_AN385,
54
FPGA_AN386,
55
+ FPGA_AN500,
56
FPGA_AN511,
57
} MPS2FPGAType;
58
59
@@ -XXX,XX +XXX,XX @@ struct MPS2MachineClass {
60
MachineClass parent;
61
MPS2FPGAType fpga_type;
62
uint32_t scc_id;
63
+ bool has_block_ram;
64
+ hwaddr ethernet_base;
65
+ hwaddr psram_base;
66
};
67
typedef struct MPS2MachineClass MPS2MachineClass;
68
69
@@ -XXX,XX +XXX,XX @@ typedef struct MPS2MachineState MPS2MachineState;
70
#define TYPE_MPS2_MACHINE "mps2"
71
#define TYPE_MPS2_AN385_MACHINE MACHINE_TYPE_NAME("mps2-an385")
72
#define TYPE_MPS2_AN386_MACHINE MACHINE_TYPE_NAME("mps2-an386")
73
+#define TYPE_MPS2_AN500_MACHINE MACHINE_TYPE_NAME("mps2-an500")
74
#define TYPE_MPS2_AN511_MACHINE MACHINE_TYPE_NAME("mps2-an511")
75
76
DECLARE_OBJ_CHECKERS(MPS2MachineState, MPS2MachineClass,
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
*/
103
- memory_region_add_subregion(system_memory, 0x21000000, machine->ram);
104
+ memory_region_add_subregion(system_memory, mmc->psram_base, machine->ram);
105
106
- switch (mmc->fpga_type) {
107
- case FPGA_AN385:
108
- case FPGA_AN386:
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
}
33
}
169
34
170
static void mps2_an386_class_init(ObjectClass *oc, void *data)
35
/* Unmap all notifiers attached to @mr */
171
@@ -XXX,XX +XXX,XX @@ static void mps2_an386_class_init(ObjectClass *oc, void *data)
36
-inline void smmu_inv_notifiers_mr(IOMMUMemoryRegion *mr)
172
mmc->fpga_type = FPGA_AN386;
37
+static void smmu_inv_notifiers_mr(IOMMUMemoryRegion *mr)
173
mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m4");
38
{
174
mmc->scc_id = 0x41043860;
39
IOMMUNotifier *n;
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
};
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
40
226
--
41
--
227
2.20.1
42
2.25.1
228
43
229
44
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
If a -bios option is specified on the command line, load the image into
3
When using Clang ("Apple clang version 14.0.0 (clang-1400.0.29.202)")
4
the internal ROM memory region, which contains the first instructions
4
and building with -Wall we get:
5
run by the CPU after reset.
6
5
7
If -bios is not specified, the vbootrom included with qemu is loaded by
6
hw/arm/smmu-common.c:173:33: warning: static function 'smmu_hash_remove_by_asid_iova' is used in an inline function with external linkage [-Wstatic-in-inline]
8
default.
7
hw/arm/smmu-common.h:170:1: note: use 'static' to give inline function 'smmu_iotlb_inv_iova' internal linkage
8
void smmu_iotlb_inv_iova(SMMUState *s, int asid, dma_addr_t iova,
9
^
10
static
9
11
10
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
12
None of our code base require / use inlined functions with external
11
Reviewed-by: Cédric Le Goater <clg@kaod.org>
13
linkage. Some places use internal inlining in the hot path. These
12
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
14
two functions are certainly not in any hot path and don't justify
13
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
15
any inlining, so these are likely oversights rather than intentional.
14
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
16
15
Message-id: 20200911052101.2602693-8-hskinnemoen@google.com
17
Reported-by: Stefan Weil <sw@weilnetz.de>
18
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
19
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
20
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
21
Reviewed-by: Eric Auger <eric.auger@redhat.com>
22
Message-id: 20221216214924.4711-3-philmd@linaro.org
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
23
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
---
24
---
18
hw/arm/npcm7xx_boards.c | 32 ++++++++++++++++++++++++++++++++
25
hw/arm/smmu-common.c | 13 ++++++-------
19
1 file changed, 32 insertions(+)
26
1 file changed, 6 insertions(+), 7 deletions(-)
20
27
21
diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c
28
diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c
22
index XXXXXXX..XXXXXXX 100644
29
index XXXXXXX..XXXXXXX 100644
23
--- a/hw/arm/npcm7xx_boards.c
30
--- a/hw/arm/smmu-common.c
24
+++ b/hw/arm/npcm7xx_boards.c
31
+++ b/hw/arm/smmu-common.c
25
@@ -XXX,XX +XXX,XX @@
32
@@ -XXX,XX +XXX,XX @@ void smmu_iotlb_insert(SMMUState *bs, SMMUTransCfg *cfg, SMMUTLBEntry *new)
26
#include "exec/address-spaces.h"
33
g_hash_table_insert(bs->iotlb, key, new);
27
#include "hw/arm/npcm7xx.h"
34
}
28
#include "hw/core/cpu.h"
35
29
+#include "hw/loader.h"
36
-inline void smmu_iotlb_inv_all(SMMUState *s)
30
#include "qapi/error.h"
37
+void smmu_iotlb_inv_all(SMMUState *s)
31
+#include "qemu-common.h"
32
#include "qemu/units.h"
33
+#include "sysemu/sysemu.h"
34
35
#define NPCM750_EVB_POWER_ON_STRAPS 0x00001ff7
36
#define QUANTA_GSJ_POWER_ON_STRAPS 0x00001fff
37
38
+static const char npcm7xx_default_bootrom[] = "npcm7xx_bootrom.bin";
39
+
40
+static void npcm7xx_load_bootrom(MachineState *machine, NPCM7xxState *soc)
41
+{
42
+ g_autofree char *filename = NULL;
43
+ int ret;
44
+
45
+ if (!bios_name) {
46
+ bios_name = npcm7xx_default_bootrom;
47
+ }
48
+
49
+ filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
50
+ if (!filename) {
51
+ error_report("Could not find ROM image '%s'", bios_name);
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
{
38
{
67
memory_region_add_subregion(get_system_memory(), NPCM7XX_DRAM_BA, dram);
39
trace_smmu_iotlb_inv_all();
68
@@ -XXX,XX +XXX,XX @@ static void npcm750_evb_init(MachineState *machine)
40
g_hash_table_remove_all(s->iotlb);
69
npcm7xx_connect_dram(soc, machine->ram);
41
@@ -XXX,XX +XXX,XX @@ static gboolean smmu_hash_remove_by_asid_iova(gpointer key, gpointer value,
70
qdev_realize(DEVICE(soc), NULL, &error_fatal);
42
((entry->iova & ~info->mask) == info->iova);
71
72
+ npcm7xx_load_bootrom(machine, soc);
73
npcm7xx_load_kernel(machine, soc);
74
}
43
}
75
44
76
@@ -XXX,XX +XXX,XX @@ static void quanta_gsj_init(MachineState *machine)
45
-inline void
77
npcm7xx_connect_dram(soc, machine->ram);
46
-smmu_iotlb_inv_iova(SMMUState *s, int asid, dma_addr_t iova,
78
qdev_realize(DEVICE(soc), NULL, &error_fatal);
47
- uint8_t tg, uint64_t num_pages, uint8_t ttl)
79
48
+void smmu_iotlb_inv_iova(SMMUState *s, int asid, dma_addr_t iova,
80
+ npcm7xx_load_bootrom(machine, soc);
49
+ uint8_t tg, uint64_t num_pages, uint8_t ttl)
81
npcm7xx_load_kernel(machine, soc);
50
{
51
/* if tg is not set we use 4KB range invalidation */
52
uint8_t granule = tg ? tg * 2 + 10 : 12;
53
@@ -XXX,XX +XXX,XX @@ smmu_iotlb_inv_iova(SMMUState *s, int asid, dma_addr_t iova,
54
&info);
82
}
55
}
83
56
57
-inline void smmu_iotlb_inv_asid(SMMUState *s, uint16_t asid)
58
+void smmu_iotlb_inv_asid(SMMUState *s, uint16_t asid)
59
{
60
trace_smmu_iotlb_inv_asid(asid);
61
g_hash_table_foreach_remove(s->iotlb, smmu_hash_remove_by_asid, &asid);
62
@@ -XXX,XX +XXX,XX @@ error:
63
*
64
* return 0 on success
65
*/
66
-inline int smmu_ptw(SMMUTransCfg *cfg, dma_addr_t iova, IOMMUAccessFlags perm,
67
- SMMUTLBEntry *tlbe, SMMUPTWEventInfo *info)
68
+int smmu_ptw(SMMUTransCfg *cfg, dma_addr_t iova, IOMMUAccessFlags perm,
69
+ SMMUTLBEntry *tlbe, SMMUPTWEventInfo *info)
70
{
71
if (!cfg->aa64) {
72
/*
84
--
73
--
85
2.20.1
74
2.25.1
86
75
87
76
diff view generated by jsdifflib
1
Convert the insns using the 2reg_vcvt and 2reg_vcvt_f16 formats
1
From: Jean-Christophe Dubois <jcd@tribudubois.net>
2
to pass the size through to the trans function as a MO_* value
3
rather than the '0==f32, 1==f16' used in the fp 3-same encodings.
4
2
3
So far the GPT timers were unable to raise IRQs to the processor.
4
5
Signed-off-by: Jean-Christophe Dubois <jcd@tribudubois.net>
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20200903133209.5141-3-peter.maydell@linaro.org
8
---
8
---
9
target/arm/neon-dp.decode | 3 +--
9
include/hw/arm/fsl-imx7.h | 5 +++++
10
target/arm/translate-neon.c.inc | 4 ++--
10
hw/arm/fsl-imx7.c | 10 ++++++++++
11
2 files changed, 3 insertions(+), 4 deletions(-)
11
2 files changed, 15 insertions(+)
12
12
13
diff --git a/target/arm/neon-dp.decode b/target/arm/neon-dp.decode
13
diff --git a/include/hw/arm/fsl-imx7.h b/include/hw/arm/fsl-imx7.h
14
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
15
--- a/target/arm/neon-dp.decode
15
--- a/include/hw/arm/fsl-imx7.h
16
+++ b/target/arm/neon-dp.decode
16
+++ b/include/hw/arm/fsl-imx7.h
17
@@ -XXX,XX +XXX,XX @@ VMINNM_fp_3s 1111 001 1 0 . 1 . .... .... 1111 ... 1 .... @3same_fp
17
@@ -XXX,XX +XXX,XX @@ enum FslIMX7IRQs {
18
@2reg_shll_b .... ... . . . 001 shift:3 .... .... 0 . . . .... \
18
FSL_IMX7_USB2_IRQ = 42,
19
&2reg_shift vm=%vm_dp vd=%vd_dp size=0 q=0
19
FSL_IMX7_USB3_IRQ = 40,
20
20
21
-# We use size=0 for fp32 and size=1 for fp16 to match the 3-same encodings.
21
+ FSL_IMX7_GPT1_IRQ = 55,
22
@2reg_vcvt .... ... . . . 1 ..... .... .... . q:1 . . .... \
22
+ FSL_IMX7_GPT2_IRQ = 54,
23
- &2reg_shift vm=%vm_dp vd=%vd_dp size=0 shift=%neon_rshift_i5
23
+ FSL_IMX7_GPT3_IRQ = 53,
24
+ &2reg_shift vm=%vm_dp vd=%vd_dp size=2 shift=%neon_rshift_i5
24
+ FSL_IMX7_GPT4_IRQ = 52,
25
@2reg_vcvt_f16 .... ... . . . 11 .... .... .... . q:1 . . .... \
25
+
26
&2reg_shift vm=%vm_dp vd=%vd_dp size=1 shift=%neon_rshift_i4
26
FSL_IMX7_WDOG1_IRQ = 78,
27
27
FSL_IMX7_WDOG2_IRQ = 79,
28
diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc
28
FSL_IMX7_WDOG3_IRQ = 10,
29
diff --git a/hw/arm/fsl-imx7.c b/hw/arm/fsl-imx7.c
29
index XXXXXXX..XXXXXXX 100644
30
index XXXXXXX..XXXXXXX 100644
30
--- a/target/arm/translate-neon.c.inc
31
--- a/hw/arm/fsl-imx7.c
31
+++ b/target/arm/translate-neon.c.inc
32
+++ b/hw/arm/fsl-imx7.c
32
@@ -XXX,XX +XXX,XX @@ static bool do_fp_2sh(DisasContext *s, arg_2reg_shift *a,
33
@@ -XXX,XX +XXX,XX @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp)
33
return false;
34
FSL_IMX7_GPT4_ADDR,
35
};
36
37
+ static const int FSL_IMX7_GPTn_IRQ[FSL_IMX7_NUM_GPTS] = {
38
+ FSL_IMX7_GPT1_IRQ,
39
+ FSL_IMX7_GPT2_IRQ,
40
+ FSL_IMX7_GPT3_IRQ,
41
+ FSL_IMX7_GPT4_IRQ,
42
+ };
43
+
44
s->gpt[i].ccm = IMX_CCM(&s->ccm);
45
sysbus_realize(SYS_BUS_DEVICE(&s->gpt[i]), &error_abort);
46
sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpt[i]), 0, FSL_IMX7_GPTn_ADDR[i]);
47
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpt[i]), 0,
48
+ qdev_get_gpio_in(DEVICE(&s->a7mpcore),
49
+ FSL_IMX7_GPTn_IRQ[i]));
34
}
50
}
35
51
36
- if (a->size != 0) {
52
for (i = 0; i < FSL_IMX7_NUM_GPIOS; i++) {
37
+ if (a->size == MO_16) {
38
if (!dc_isar_feature(aa32_fp16_arith, s)) {
39
return false;
40
}
41
@@ -XXX,XX +XXX,XX @@ static bool do_fp_2sh(DisasContext *s, arg_2reg_shift *a,
42
return true;
43
}
44
45
- fpst = fpstatus_ptr(a->size ? FPST_STD_F16 : FPST_STD);
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
--
53
--
51
2.20.1
54
2.25.1
52
53
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Jean-Christophe Dubois <jcd@tribudubois.net>
2
2
3
The NPCM730 and NPCM750 SoCs have three timer modules each holding five
3
CCM derived clocks will have to be added later.
4
timers and some shared registers (e.g. interrupt status).
5
4
6
Each timer runs at 25 MHz divided by a prescaler, and counts down from a
5
Signed-off-by: Jean-Christophe Dubois <jcd@tribudubois.net>
7
configurable initial value to zero. When zero is reached, the interrupt
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
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>
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
23
---
8
---
24
include/hw/timer/npcm7xx_timer.h | 78 +++++
9
hw/misc/imx7_ccm.c | 49 +++++++++++++++++++++++++++++++++++++---------
25
hw/timer/npcm7xx_timer.c | 543 +++++++++++++++++++++++++++++++
10
1 file changed, 40 insertions(+), 9 deletions(-)
26
hw/timer/meson.build | 1 +
27
hw/timer/trace-events | 5 +
28
4 files changed, 627 insertions(+)
29
create mode 100644 include/hw/timer/npcm7xx_timer.h
30
create mode 100644 hw/timer/npcm7xx_timer.c
31
11
32
diff --git a/include/hw/timer/npcm7xx_timer.h b/include/hw/timer/npcm7xx_timer.h
12
diff --git a/hw/misc/imx7_ccm.c b/hw/misc/imx7_ccm.c
33
new file mode 100644
13
index XXXXXXX..XXXXXXX 100644
34
index XXXXXXX..XXXXXXX
14
--- a/hw/misc/imx7_ccm.c
35
--- /dev/null
15
+++ b/hw/misc/imx7_ccm.c
36
+++ b/include/hw/timer/npcm7xx_timer.h
37
@@ -XXX,XX +XXX,XX @@
16
@@ -XXX,XX +XXX,XX @@
38
+/*
17
#include "hw/misc/imx7_ccm.h"
39
+ * Nuvoton NPCM7xx Timer Controller
18
#include "migration/vmstate.h"
40
+ *
19
41
+ * Copyright 2020 Google LLC
42
+ *
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
+ */
53
+#ifndef NPCM7XX_TIMER_H
54
+#define NPCM7XX_TIMER_H
55
+
56
+#include "exec/memory.h"
57
+#include "hw/sysbus.h"
58
+#include "qemu/timer.h"
59
+
60
+/* Each Timer Module (TIM) instance holds five 25 MHz timers. */
61
+#define NPCM7XX_TIMERS_PER_CTRL (5)
62
+
63
+/*
64
+ * Number of registers in our device state structure. Don't change this without
65
+ * incrementing the version_id in the vmstate.
66
+ */
67
+#define NPCM7XX_TIMER_NR_REGS (0x54 / sizeof(uint32_t))
68
+
69
+typedef struct NPCM7xxTimerCtrlState NPCM7xxTimerCtrlState;
70
+
71
+/**
72
+ * struct NPCM7xxTimer - Individual timer state.
73
+ * @irq: GIC interrupt line to fire on expiration (if enabled).
74
+ * @qtimer: QEMU timer that notifies us on expiration.
75
+ * @expires_ns: Absolute virtual expiration time.
76
+ * @remaining_ns: Remaining time until expiration if timer is paused.
77
+ * @tcsr: The Timer Control and Status Register.
78
+ * @ticr: The Timer Initial Count Register.
79
+ */
80
+typedef struct NPCM7xxTimer {
81
+ NPCM7xxTimerCtrlState *ctrl;
82
+
83
+ qemu_irq irq;
84
+ QEMUTimer qtimer;
85
+ int64_t expires_ns;
86
+ int64_t remaining_ns;
87
+
88
+ uint32_t tcsr;
89
+ uint32_t ticr;
90
+} NPCM7xxTimer;
91
+
92
+/**
93
+ * struct NPCM7xxTimerCtrlState - Timer Module device state.
94
+ * @parent: System bus device.
95
+ * @iomem: Memory region through which registers are accessed.
96
+ * @tisr: The Timer Interrupt Status Register.
97
+ * @wtcr: The Watchdog Timer Control Register.
98
+ * @timer: The five individual timers managed by this module.
99
+ */
100
+struct NPCM7xxTimerCtrlState {
101
+ SysBusDevice parent;
102
+
103
+ MemoryRegion iomem;
104
+
105
+ uint32_t tisr;
106
+ uint32_t wtcr;
107
+
108
+ NPCM7xxTimer timer[NPCM7XX_TIMERS_PER_CTRL];
109
+};
110
+
111
+#define TYPE_NPCM7XX_TIMER "npcm7xx-timer"
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"
20
+#include "trace.h"
151
+
21
+
152
+/* 32-bit register indices. */
22
+#define CKIH_FREQ 24000000 /* 24MHz crystal input */
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
+
23
+
174
+/* Register field definitions. */
24
static void imx7_analog_reset(DeviceState *dev)
175
+#define NPCM7XX_TCSR_CEN BIT(30)
25
{
176
+#define NPCM7XX_TCSR_IE BIT(29)
26
IMX7AnalogState *s = IMX7_ANALOG(dev);
177
+#define NPCM7XX_TCSR_PERIODIC BIT(27)
27
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_imx7_ccm = {
178
+#define NPCM7XX_TCSR_CRST BIT(26)
28
static uint32_t imx7_ccm_get_clock_frequency(IMXCCMState *dev, IMXClk clock)
179
+#define NPCM7XX_TCSR_CACT BIT(25)
29
{
180
+#define NPCM7XX_TCSR_RSVD 0x01ffff00
30
/*
181
+#define NPCM7XX_TCSR_PRESCALE_START 0
31
- * This function is "consumed" by GPT emulation code, however on
182
+#define NPCM7XX_TCSR_PRESCALE_LEN 8
32
- * i.MX7 each GPT block can have their own clock root. This means
33
- * that this functions needs somehow to know requester's identity
34
- * and the way to pass it: be it via additional IMXClk constants
35
- * or by adding another argument to this method needs to be
36
- * figured out
37
+ * This function is "consumed" by GPT emulation code. Some clocks
38
+ * have fixed frequencies and we can provide requested frequency
39
+ * easily. However for CCM provided clocks (like IPG) each GPT
40
+ * timer can have its own clock root.
41
+ * This means we need additionnal information when calling this
42
+ * function to know the requester's identity.
43
*/
44
- qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: Not implemented\n",
45
- TYPE_IMX7_CCM, __func__);
46
- return 0;
47
+ uint32_t freq = 0;
183
+
48
+
184
+/*
49
+ switch (clock) {
185
+ * Returns the index of timer in the tc->timer array. This can be used to
50
+ case CLK_NONE:
186
+ * locate the registers that belong to this timer.
51
+ break;
187
+ */
52
+ case CLK_32k:
188
+static int npcm7xx_timer_index(NPCM7xxTimerCtrlState *tc, NPCM7xxTimer *timer)
53
+ freq = CKIL_FREQ;
189
+{
54
+ break;
190
+ int index = timer - tc->timer;
55
+ case CLK_HIGH:
191
+
56
+ freq = CKIH_FREQ;
192
+ g_assert(index >= 0 && index < NPCM7XX_TIMERS_PER_CTRL);
57
+ break;
193
+
58
+ case CLK_IPG:
194
+ return index;
59
+ case CLK_IPG_HIGH:
195
+}
60
+ /*
196
+
61
+ * For now we don't have a way to figure out the device this
197
+/* Return the value by which to divide the reference clock rate. */
62
+ * function is called for. Until then the IPG derived clocks
198
+static uint32_t npcm7xx_tcsr_prescaler(uint32_t tcsr)
63
+ * are left unimplemented.
199
+{
64
+ */
200
+ return extract32(tcsr, NPCM7XX_TCSR_PRESCALE_START,
65
+ qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: Clock %d Not implemented\n",
201
+ NPCM7XX_TCSR_PRESCALE_LEN) + 1;
66
+ TYPE_IMX7_CCM, __func__, clock);
202
+}
67
+ break;
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
+ }
347
+ }
348
+
349
+ if ((old_tcsr ^ new_tcsr) & NPCM7XX_TCSR_IE) {
350
+ npcm7xx_timer_check_interrupt(t);
351
+ }
352
+ if (new_tcsr & NPCM7XX_TCSR_CRST) {
353
+ npcm7xx_timer_restart(t, old_tcsr);
354
+ t->tcsr &= ~NPCM7XX_TCSR_CRST;
355
+ }
356
+ if ((old_tcsr ^ new_tcsr) & NPCM7XX_TCSR_CEN) {
357
+ if (new_tcsr & NPCM7XX_TCSR_CEN) {
358
+ t->tcsr |= NPCM7XX_TCSR_CACT;
359
+ npcm7xx_timer_start(t);
360
+ } else {
361
+ t->tcsr &= ~NPCM7XX_TCSR_CACT;
362
+ npcm7xx_timer_pause(t);
363
+ }
364
+ }
365
+}
366
+
367
+static void npcm7xx_timer_write_ticr(NPCM7xxTimer *t, uint32_t new_ticr)
368
+{
369
+ t->ticr = new_ticr;
370
+
371
+ npcm7xx_timer_restart(t, t->tcsr);
372
+}
373
+
374
+static void npcm7xx_timer_write_tisr(NPCM7xxTimerCtrlState *s, uint32_t value)
375
+{
376
+ int i;
377
+
378
+ s->tisr &= ~value;
379
+ for (i = 0; i < ARRAY_SIZE(s->timer); i++) {
380
+ if (value & (1U << i)) {
381
+ npcm7xx_timer_check_interrupt(&s->timer[i]);
382
+ }
383
+ }
384
+}
385
+
386
+static hwaddr npcm7xx_tcsr_index(hwaddr reg)
387
+{
388
+ switch (reg) {
389
+ case NPCM7XX_TIMER_TCSR0:
390
+ return 0;
391
+ case NPCM7XX_TIMER_TCSR1:
392
+ return 1;
393
+ case NPCM7XX_TIMER_TCSR2:
394
+ return 2;
395
+ case NPCM7XX_TIMER_TCSR3:
396
+ return 3;
397
+ case NPCM7XX_TIMER_TCSR4:
398
+ return 4;
399
+ default:
68
+ default:
400
+ g_assert_not_reached();
69
+ qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: unsupported clock %d\n",
401
+ }
70
+ TYPE_IMX7_CCM, __func__, clock);
402
+}
403
+
404
+static hwaddr npcm7xx_ticr_index(hwaddr reg)
405
+{
406
+ switch (reg) {
407
+ case NPCM7XX_TIMER_TICR0:
408
+ return 0;
409
+ case NPCM7XX_TIMER_TICR1:
410
+ return 1;
411
+ case NPCM7XX_TIMER_TICR2:
412
+ return 2;
413
+ case NPCM7XX_TIMER_TICR3:
414
+ return 3;
415
+ case NPCM7XX_TIMER_TICR4:
416
+ return 4;
417
+ default:
418
+ g_assert_not_reached();
419
+ }
420
+}
421
+
422
+static hwaddr npcm7xx_tdr_index(hwaddr reg)
423
+{
424
+ switch (reg) {
425
+ case NPCM7XX_TIMER_TDR0:
426
+ return 0;
427
+ case NPCM7XX_TIMER_TDR1:
428
+ return 1;
429
+ case NPCM7XX_TIMER_TDR2:
430
+ return 2;
431
+ case NPCM7XX_TIMER_TDR3:
432
+ return 3;
433
+ case NPCM7XX_TIMER_TDR4:
434
+ return 4;
435
+ default:
436
+ g_assert_not_reached();
437
+ }
438
+}
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;
71
+ break;
485
+ }
72
+ }
486
+
73
+
487
+ trace_npcm7xx_timer_read(DEVICE(s)->canonical_path, offset, value);
74
+ trace_ccm_clock_freq(clock, freq);
488
+
75
+
489
+ return value;
76
+ return freq;
490
+}
77
}
491
+
78
492
+static void npcm7xx_timer_write(void *opaque, hwaddr offset,
79
static void imx7_ccm_class_init(ObjectClass *klass, void *data)
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
--
80
--
694
2.20.1
81
2.25.1
695
696
diff view generated by jsdifflib
1
Implement a model of the MPS2 with the AN386 firmware. This is
1
From: Jean-Christophe Dubois <jcd@tribudubois.net>
2
essentially identical to the AN385 firmware, but it has a
3
Cortex-M4 rather than a Cortex-M3.
4
2
3
The i.MX6UL doesn't support CLK_HIGH ou CLK_HIGH_DIV clock source.
4
5
Signed-off-by: Jean-Christophe Dubois <jcd@tribudubois.net>
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
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: 20200903202048.15370-2-peter.maydell@linaro.org
9
---
8
---
10
docs/system/arm/mps2.rst | 8 +++++---
9
include/hw/timer/imx_gpt.h | 1 +
11
hw/arm/mps2.c | 34 +++++++++++++++++++++++++++++-----
10
hw/arm/fsl-imx6ul.c | 2 +-
12
2 files changed, 34 insertions(+), 8 deletions(-)
11
hw/misc/imx6ul_ccm.c | 6 ------
12
hw/timer/imx_gpt.c | 25 +++++++++++++++++++++++++
13
4 files changed, 27 insertions(+), 7 deletions(-)
13
14
14
diff --git a/docs/system/arm/mps2.rst b/docs/system/arm/mps2.rst
15
diff --git a/include/hw/timer/imx_gpt.h b/include/hw/timer/imx_gpt.h
15
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
16
--- a/docs/system/arm/mps2.rst
17
--- a/include/hw/timer/imx_gpt.h
17
+++ b/docs/system/arm/mps2.rst
18
+++ b/include/hw/timer/imx_gpt.h
18
@@ -XXX,XX +XXX,XX @@
19
@@ -XXX,XX +XXX,XX @@
19
-Arm MPS2 boards (``mps2-an385``, ``mps2-an505``, ``mps2-an511``, ``mps2-an521``)
20
#define TYPE_IMX25_GPT "imx25.gpt"
20
-================================================================================
21
#define TYPE_IMX31_GPT "imx31.gpt"
21
+Arm MPS2 boards (``mps2-an385``, ``mps2-an386``, ``mps2-an505``, ``mps2-an511``, ``mps2-an521``)
22
#define TYPE_IMX6_GPT "imx6.gpt"
22
+================================================================================================
23
+#define TYPE_IMX6UL_GPT "imx6ul.gpt"
23
24
#define TYPE_IMX7_GPT "imx7.gpt"
24
These board models all use Arm M-profile CPUs.
25
25
26
#define TYPE_IMX_GPT TYPE_IMX25_GPT
26
@@ -XXX,XX +XXX,XX @@ QEMU models the following FPGA images:
27
diff --git a/hw/arm/fsl-imx6ul.c b/hw/arm/fsl-imx6ul.c
27
28
``mps2-an385``
29
Cortex-M3 as documented in ARM Application Note AN385
30
+``mps2-an386``
31
+ Cortex-M4 as documented in ARM Application Note AN386
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
37
Differences between QEMU and real hardware:
38
39
-- AN385 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
42
if zbt_boot_ctrl is always zero)
43
- QEMU provides a LAN9118 ethernet rather than LAN9220; the only guest
44
diff --git a/hw/arm/mps2.c b/hw/arm/mps2.c
45
index XXXXXXX..XXXXXXX 100644
28
index XXXXXXX..XXXXXXX 100644
46
--- a/hw/arm/mps2.c
29
--- a/hw/arm/fsl-imx6ul.c
47
+++ b/hw/arm/mps2.c
30
+++ b/hw/arm/fsl-imx6ul.c
48
@@ -XXX,XX +XXX,XX @@
31
@@ -XXX,XX +XXX,XX @@ static void fsl_imx6ul_init(Object *obj)
49
* as seen by the guest depend significantly on the FPGA image.
32
*/
50
* We model the following FPGA images:
33
for (i = 0; i < FSL_IMX6UL_NUM_GPTS; i++) {
51
* "mps2-an385" -- Cortex-M3 as documented in ARM Application Note AN385
34
snprintf(name, NAME_SIZE, "gpt%d", i);
52
+ * "mps2-an386" -- Cortex-M4 as documented in ARM Application Note AN386
35
- object_initialize_child(obj, name, &s->gpt[i], TYPE_IMX7_GPT);
53
* "mps2-an511" -- Cortex-M3 'DesignStart' as documented in AN511
36
+ object_initialize_child(obj, name, &s->gpt[i], TYPE_IMX6UL_GPT);
54
*
37
}
55
* Links to the TRM for the board itself and to the various Application
38
56
@@ -XXX,XX +XXX,XX @@
39
/*
57
40
diff --git a/hw/misc/imx6ul_ccm.c b/hw/misc/imx6ul_ccm.c
58
typedef enum MPS2FPGAType {
41
index XXXXXXX..XXXXXXX 100644
59
FPGA_AN385,
42
--- a/hw/misc/imx6ul_ccm.c
60
+ FPGA_AN386,
43
+++ b/hw/misc/imx6ul_ccm.c
61
FPGA_AN511,
44
@@ -XXX,XX +XXX,XX @@ static uint32_t imx6ul_ccm_get_clock_frequency(IMXCCMState *dev, IMXClk clock)
62
} MPS2FPGAType;
45
case CLK_32k:
63
46
freq = CKIL_FREQ;
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;
47
break;
109
case FPGA_AN511:
48
- case CLK_HIGH:
110
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
49
- freq = CKIH_FREQ;
111
50
- break;
112
switch (mmc->fpga_type) {
51
- case CLK_HIGH_DIV:
113
case FPGA_AN385:
52
- freq = CKIH_FREQ / 8;
114
+ case FPGA_AN386:
53
- break;
115
{
54
default:
116
/* The overflow IRQs for UARTs 0, 1 and 2 are ORed together.
55
qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: unsupported clock %d\n",
117
* Overflow for UARTs 4 and 5 doesn't trigger any interrupt.
56
TYPE_IMX6UL_CCM, __func__, clock);
118
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
57
diff --git a/hw/timer/imx_gpt.c b/hw/timer/imx_gpt.c
119
*/
58
index XXXXXXX..XXXXXXX 100644
120
lan9118_init(&nd_table[0], 0x40200000,
59
--- a/hw/timer/imx_gpt.c
121
qdev_get_gpio_in(armv7m,
60
+++ b/hw/timer/imx_gpt.c
122
- mmc->fpga_type == FPGA_AN385 ? 13 : 47));
61
@@ -XXX,XX +XXX,XX @@ static const IMXClk imx6_gpt_clocks[] = {
123
+ mmc->fpga_type == FPGA_AN511 ? 47 : 13));
62
CLK_HIGH, /* 111 reference clock */
124
63
};
125
system_clock_scale = NANOSECONDS_PER_SECOND / SYSCLK_FRQ;
64
126
65
+static const IMXClk imx6ul_gpt_clocks[] = {
127
@@ -XXX,XX +XXX,XX @@ static void mps2_an385_class_init(ObjectClass *oc, void *data)
66
+ CLK_NONE, /* 000 No clock source */
128
mmc->scc_id = 0x41043850;
67
+ CLK_IPG, /* 001 ipg_clk, 532MHz*/
68
+ CLK_IPG_HIGH, /* 010 ipg_clk_highfreq */
69
+ CLK_EXT, /* 011 External clock */
70
+ CLK_32k, /* 100 ipg_clk_32k */
71
+ CLK_NONE, /* 101 not defined */
72
+ CLK_NONE, /* 110 not defined */
73
+ CLK_NONE, /* 111 not defined */
74
+};
75
+
76
static const IMXClk imx7_gpt_clocks[] = {
77
CLK_NONE, /* 000 No clock source */
78
CLK_IPG, /* 001 ipg_clk, 532MHz*/
79
@@ -XXX,XX +XXX,XX @@ static void imx6_gpt_init(Object *obj)
80
s->clocks = imx6_gpt_clocks;
129
}
81
}
130
82
131
+static void mps2_an386_class_init(ObjectClass *oc, void *data)
83
+static void imx6ul_gpt_init(Object *obj)
132
+{
84
+{
133
+ MachineClass *mc = MACHINE_CLASS(oc);
85
+ IMXGPTState *s = IMX_GPT(obj);
134
+ MPS2MachineClass *mmc = MPS2_MACHINE_CLASS(oc);
135
+
86
+
136
+ mc->desc = "ARM MPS2 with AN386 FPGA image for Cortex-M4";
87
+ s->clocks = imx6ul_gpt_clocks;
137
+ mmc->fpga_type = FPGA_AN386;
138
+ mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m4");
139
+ mmc->scc_id = 0x41043860;
140
+}
88
+}
141
+
89
+
142
static void mps2_an511_class_init(ObjectClass *oc, void *data)
90
static void imx7_gpt_init(Object *obj)
143
{
91
{
144
MachineClass *mc = MACHINE_CLASS(oc);
92
IMXGPTState *s = IMX_GPT(obj);
145
@@ -XXX,XX +XXX,XX @@ static const TypeInfo mps2_an385_info = {
93
@@ -XXX,XX +XXX,XX @@ static const TypeInfo imx6_gpt_info = {
146
.class_init = mps2_an385_class_init,
94
.instance_init = imx6_gpt_init,
147
};
95
};
148
96
149
+static const TypeInfo mps2_an386_info = {
97
+static const TypeInfo imx6ul_gpt_info = {
150
+ .name = TYPE_MPS2_AN386_MACHINE,
98
+ .name = TYPE_IMX6UL_GPT,
151
+ .parent = TYPE_MPS2_MACHINE,
99
+ .parent = TYPE_IMX25_GPT,
152
+ .class_init = mps2_an386_class_init,
100
+ .instance_init = imx6ul_gpt_init,
153
+};
101
+};
154
+
102
+
155
static const TypeInfo mps2_an511_info = {
103
static const TypeInfo imx7_gpt_info = {
156
.name = TYPE_MPS2_AN511_MACHINE,
104
.name = TYPE_IMX7_GPT,
157
.parent = TYPE_MPS2_MACHINE,
105
.parent = TYPE_IMX25_GPT,
158
@@ -XXX,XX +XXX,XX @@ static void mps2_machine_init(void)
106
@@ -XXX,XX +XXX,XX @@ static void imx_gpt_register_types(void)
159
{
107
type_register_static(&imx25_gpt_info);
160
type_register_static(&mps2_info);
108
type_register_static(&imx31_gpt_info);
161
type_register_static(&mps2_an385_info);
109
type_register_static(&imx6_gpt_info);
162
+ type_register_static(&mps2_an386_info);
110
+ type_register_static(&imx6ul_gpt_info);
163
type_register_static(&mps2_an511_info);
111
type_register_static(&imx7_gpt_info);
164
}
112
}
165
113
166
--
114
--
167
2.20.1
115
2.25.1
168
169
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Jean-Christophe Dubois <jcd@tribudubois.net>
2
2
3
This model implementation is designed for 32-bit accesses.
3
IRQs were not associated to the various GPIO devices inside i.MX7D.
4
We can simplify setting the MemoryRegionOps::impl min/max
4
This patch brings the i.MX7D on par with i.MX6.
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: Jean-Christophe Dubois <jcd@tribudubois.net>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20221226101418.415170-1-jcd@tribudubois.net
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
include/hw/arm/fsl-imx7.h | 15 +++++++++++++++
14
1 file changed, 5 insertions(+), 11 deletions(-)
12
hw/arm/fsl-imx7.c | 31 ++++++++++++++++++++++++++++++-
13
2 files changed, 45 insertions(+), 1 deletion(-)
15
14
16
diff --git a/hw/misc/a9scu.c b/hw/misc/a9scu.c
15
diff --git a/include/hw/arm/fsl-imx7.h b/include/hw/arm/fsl-imx7.h
17
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/misc/a9scu.c
17
--- a/include/hw/arm/fsl-imx7.h
19
+++ b/hw/misc/a9scu.c
18
+++ b/include/hw/arm/fsl-imx7.h
20
@@ -XXX,XX +XXX,XX @@ static uint64_t a9_scu_read(void *opaque, hwaddr offset,
19
@@ -XXX,XX +XXX,XX @@ enum FslIMX7IRQs {
21
return (((1 << s->num_cpu) - 1) << 4) | (s->num_cpu - 1);
20
FSL_IMX7_GPT3_IRQ = 53,
22
case 0x08: /* CPU Power Status */
21
FSL_IMX7_GPT4_IRQ = 52,
23
return s->status;
22
24
- case 0x09: /* CPU status. */
23
+ FSL_IMX7_GPIO1_LOW_IRQ = 64,
25
- return s->status >> 8;
24
+ FSL_IMX7_GPIO1_HIGH_IRQ = 65,
26
- case 0x0a: /* CPU status. */
25
+ FSL_IMX7_GPIO2_LOW_IRQ = 66,
27
- return s->status >> 16;
26
+ FSL_IMX7_GPIO2_HIGH_IRQ = 67,
28
- case 0x0b: /* CPU status. */
27
+ FSL_IMX7_GPIO3_LOW_IRQ = 68,
29
- return s->status >> 24;
28
+ FSL_IMX7_GPIO3_HIGH_IRQ = 69,
30
case 0x0c: /* Invalidate All Registers In Secure State */
29
+ FSL_IMX7_GPIO4_LOW_IRQ = 70,
31
return 0;
30
+ FSL_IMX7_GPIO4_HIGH_IRQ = 71,
32
case 0x40: /* Filtering Start Address Register */
31
+ FSL_IMX7_GPIO5_LOW_IRQ = 72,
33
@@ -XXX,XX +XXX,XX @@ static void a9_scu_write(void *opaque, hwaddr offset,
32
+ FSL_IMX7_GPIO5_HIGH_IRQ = 73,
34
uint64_t value, unsigned size)
33
+ FSL_IMX7_GPIO6_LOW_IRQ = 74,
35
{
34
+ FSL_IMX7_GPIO6_HIGH_IRQ = 75,
36
A9SCUState *s = (A9SCUState *)opaque;
35
+ FSL_IMX7_GPIO7_LOW_IRQ = 76,
37
- uint32_t mask = MAKE_64BIT_MASK(0, size * 8);
36
+ FSL_IMX7_GPIO7_HIGH_IRQ = 77,
38
- uint32_t shift;
37
+
39
38
FSL_IMX7_WDOG1_IRQ = 78,
40
switch (offset) {
39
FSL_IMX7_WDOG2_IRQ = 79,
41
case 0x00: /* Control */
40
FSL_IMX7_WDOG3_IRQ = 10,
42
@@ -XXX,XX +XXX,XX @@ static void a9_scu_write(void *opaque, hwaddr offset,
41
diff --git a/hw/arm/fsl-imx7.c b/hw/arm/fsl-imx7.c
43
case 0x4: /* Configuration: RO */
42
index XXXXXXX..XXXXXXX 100644
44
break;
43
--- a/hw/arm/fsl-imx7.c
45
case 0x08: case 0x09: case 0x0A: case 0x0B: /* Power Control */
44
+++ b/hw/arm/fsl-imx7.c
46
- shift = (offset - 0x8) * 8;
45
@@ -XXX,XX +XXX,XX @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp)
47
- s->status &= ~(mask << shift);
46
FSL_IMX7_GPIO7_ADDR,
48
- s->status |= ((value & mask) << shift);
47
};
49
+ s->status = value;
48
50
break;
49
+ static const int FSL_IMX7_GPIOn_LOW_IRQ[FSL_IMX7_NUM_GPIOS] = {
51
case 0x0c: /* Invalidate All Registers In Secure State */
50
+ FSL_IMX7_GPIO1_LOW_IRQ,
52
/* no-op as we do not implement caches */
51
+ FSL_IMX7_GPIO2_LOW_IRQ,
53
@@ -XXX,XX +XXX,XX @@ static void a9_scu_write(void *opaque, hwaddr offset,
52
+ FSL_IMX7_GPIO3_LOW_IRQ,
54
static const MemoryRegionOps a9_scu_ops = {
53
+ FSL_IMX7_GPIO4_LOW_IRQ,
55
.read = a9_scu_read,
54
+ FSL_IMX7_GPIO5_LOW_IRQ,
56
.write = a9_scu_write,
55
+ FSL_IMX7_GPIO6_LOW_IRQ,
57
+ .impl = {
56
+ FSL_IMX7_GPIO7_LOW_IRQ,
58
+ .min_access_size = 4,
57
+ };
59
+ .max_access_size = 4,
58
+
60
+ },
59
+ static const int FSL_IMX7_GPIOn_HIGH_IRQ[FSL_IMX7_NUM_GPIOS] = {
61
.valid = {
60
+ FSL_IMX7_GPIO1_HIGH_IRQ,
62
.min_access_size = 1,
61
+ FSL_IMX7_GPIO2_HIGH_IRQ,
63
.max_access_size = 4,
62
+ FSL_IMX7_GPIO3_HIGH_IRQ,
63
+ FSL_IMX7_GPIO4_HIGH_IRQ,
64
+ FSL_IMX7_GPIO5_HIGH_IRQ,
65
+ FSL_IMX7_GPIO6_HIGH_IRQ,
66
+ FSL_IMX7_GPIO7_HIGH_IRQ,
67
+ };
68
+
69
sysbus_realize(SYS_BUS_DEVICE(&s->gpio[i]), &error_abort);
70
- sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpio[i]), 0, FSL_IMX7_GPIOn_ADDR[i]);
71
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpio[i]), 0,
72
+ FSL_IMX7_GPIOn_ADDR[i]);
73
+
74
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpio[i]), 0,
75
+ qdev_get_gpio_in(DEVICE(&s->a7mpcore),
76
+ FSL_IMX7_GPIOn_LOW_IRQ[i]));
77
+
78
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpio[i]), 1,
79
+ qdev_get_gpio_in(DEVICE(&s->a7mpcore),
80
+ FSL_IMX7_GPIOn_HIGH_IRQ[i]));
81
}
82
83
/*
64
--
84
--
65
2.20.1
85
2.25.1
66
67
diff view generated by jsdifflib
Deleted patch
1
It is the responsibility of board code for an armv7m system to set
2
system_clock_scale appropriately for the CPU speed of the core.
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
1
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
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
12
Message-id: 20200825160847.18091-1-peter.maydell@linaro.org
13
---
14
hw/timer/armv7m_systick.c | 8 ++++++++
15
1 file changed, 8 insertions(+)
16
17
diff --git a/hw/timer/armv7m_systick.c b/hw/timer/armv7m_systick.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/hw/timer/armv7m_systick.c
20
+++ b/hw/timer/armv7m_systick.c
21
@@ -XXX,XX +XXX,XX @@ static void systick_reset(DeviceState *dev)
22
{
23
SysTickState *s = SYSTICK(dev);
24
25
+ /*
26
+ * Forgetting to set system_clock_scale is always a board code
27
+ * bug. We can't check this earlier because for some boards
28
+ * (like stellaris) it is not yet configured at the point where
29
+ * the systick device is realized.
30
+ */
31
+ assert(system_clock_scale != 0);
32
+
33
s->control = 0;
34
s->reload = 0;
35
s->tick = 0;
36
--
37
2.20.1
38
39
diff view generated by jsdifflib
1
In the Neon instructions, some instruction formats have a 2-bit size
1
From: Stephen Longfield <slongfield@google.com>
2
field which corresponds exactly to QEMU's MO_8/16/32/64. However the
3
floating-point insns in the 3-same group have a 1-bit size field
4
which is "0 for 32-bit float and 1 for 16-bit float". Currently we
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
2
9
Move the handling of the 1-bit size to the decodetree file, so that
3
Size is used at lines 1088/1188 for the loop, which reads the last 4
10
all these insns consistently pass a size to the trans_ function which
4
bytes from the crc_ptr so it does need to get increased, however it
11
is an MO_8/16/32/64 value.
5
shouldn't be increased before the buffer is passed to CRC computation,
6
or the crc32 function will access uninitialized memory.
12
7
13
In this commit we switch over the insns using the 3same_fp and
8
This was pointed out to me by clg@kaod.org during the code review of
14
3same_fp_q0 formats.
9
a similar patch to hw/net/ftgmac100.c
15
10
11
Change-Id: Ib0464303b191af1e28abeb2f5105eb25aadb5e9b
12
Signed-off-by: Stephen Longfield <slongfield@google.com>
13
Reviewed-by: Patrick Venture <venture@google.com>
14
Message-id: 20221221183202.3788132-1-slongfield@google.com
15
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
18
Message-id: 20200903133209.5141-2-peter.maydell@linaro.org
19
---
17
---
20
target/arm/neon-dp.decode | 15 ++++++++++-----
18
hw/net/imx_fec.c | 8 ++++----
21
target/arm/translate-neon.c.inc | 16 +++++++++++-----
19
1 file changed, 4 insertions(+), 4 deletions(-)
22
2 files changed, 21 insertions(+), 10 deletions(-)
23
20
24
diff --git a/target/arm/neon-dp.decode b/target/arm/neon-dp.decode
21
diff --git a/hw/net/imx_fec.c b/hw/net/imx_fec.c
25
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
26
--- a/target/arm/neon-dp.decode
23
--- a/hw/net/imx_fec.c
27
+++ b/target/arm/neon-dp.decode
24
+++ b/hw/net/imx_fec.c
28
@@ -XXX,XX +XXX,XX @@
25
@@ -XXX,XX +XXX,XX @@ static ssize_t imx_fec_receive(NetClientState *nc, const uint8_t *buf,
29
@3same_q0 .... ... . . . size:2 .... .... .... . 0 . . .... \
26
return 0;
30
&3same vm=%vm_dp vn=%vn_dp vd=%vd_dp q=0
31
32
-# For FP insns the high bit of 'size' is used as part of opcode decode
33
-@3same_fp .... ... . . . . size:1 .... .... .... . q:1 . . .... \
34
- &3same vm=%vm_dp vn=%vn_dp vd=%vd_dp
35
-@3same_fp_q0 .... ... . . . . size:1 .... .... .... . 0 . . .... \
36
- &3same vm=%vm_dp vn=%vn_dp vd=%vd_dp q=0
37
+# For FP insns the high bit of 'size' is used as part of opcode decode,
38
+# and the 'size' bit is 0 for 32-bit float and 1 for 16-bit float.
39
+# This converts this encoding to the same MO_8/16/32/64 values that the
40
+# integer neon insns use.
41
+%3same_fp_size 20:1 !function=neon_3same_fp_size
42
+
43
+@3same_fp .... ... . . . . . .... .... .... . q:1 . . .... \
44
+ &3same vm=%vm_dp vn=%vn_dp vd=%vd_dp size=%3same_fp_size
45
+@3same_fp_q0 .... ... . . . . . .... .... .... . 0 . . .... \
46
+ &3same vm=%vm_dp vn=%vn_dp vd=%vd_dp q=0 size=%3same_fp_size
47
48
VHADD_S_3s 1111 001 0 0 . .. .... .... 0000 . . . 0 .... @3same
49
VHADD_U_3s 1111 001 1 0 . .. .... .... 0000 . . . 0 .... @3same
50
diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc
51
index XXXXXXX..XXXXXXX 100644
52
--- a/target/arm/translate-neon.c.inc
53
+++ b/target/arm/translate-neon.c.inc
54
@@ -XXX,XX +XXX,XX @@ static inline int rsub_8(DisasContext *s, int x)
55
return 8 - x;
56
}
57
58
+static inline int neon_3same_fp_size(DisasContext *s, int x)
59
+{
60
+ /* Convert 0==fp32, 1==fp16 into a MO_* value */
61
+ return MO_32 - x;
62
+}
63
+
64
/* Include the generated Neon decoder */
65
#include "decode-neon-dp.c.inc"
66
#include "decode-neon-ls.c.inc"
67
@@ -XXX,XX +XXX,XX @@ DO_3SAME_VQDMULH(VQRDMULH, qrdmulh)
68
WRAP_FP_GVEC(gen_##INSN##_fp16_3s, FPST_STD_F16, HFUNC) \
69
static bool trans_##INSN##_fp_3s(DisasContext *s, arg_3same *a) \
70
{ \
71
- if (a->size != 0) { \
72
+ if (a->size == MO_16) { \
73
if (!dc_isar_feature(aa32_fp16_arith, s)) { \
74
return false; \
75
} \
76
@@ -XXX,XX +XXX,XX @@ static bool trans_VMAXNM_fp_3s(DisasContext *s, arg_3same *a)
77
return false;
78
}
27
}
79
28
80
- if (a->size != 0) {
29
- /* 4 bytes for the CRC. */
81
+ if (a->size == MO_16) {
30
- size += 4;
82
if (!dc_isar_feature(aa32_fp16_arith, s)) {
31
crc = cpu_to_be32(crc32(~0, buf, size));
83
return false;
32
+ /* Increase size by 4, loop below reads the last 4 bytes from crc_ptr. */
84
}
33
+ size += 4;
85
@@ -XXX,XX +XXX,XX @@ static bool trans_VMINNM_fp_3s(DisasContext *s, arg_3same *a)
34
crc_ptr = (uint8_t *) &crc;
86
return false;
35
36
/* Huge frames are truncated. */
37
@@ -XXX,XX +XXX,XX @@ static ssize_t imx_enet_receive(NetClientState *nc, const uint8_t *buf,
38
return 0;
87
}
39
}
88
40
89
- if (a->size != 0) {
41
- /* 4 bytes for the CRC. */
90
+ if (a->size == MO_16) {
42
- size += 4;
91
if (!dc_isar_feature(aa32_fp16_arith, s)) {
43
crc = cpu_to_be32(crc32(~0, buf, size));
92
return false;
44
+ /* Increase size by 4, loop below reads the last 4 bytes from crc_ptr. */
93
}
45
+ size += 4;
94
@@ -XXX,XX +XXX,XX @@ static bool do_3same_fp_pair(DisasContext *s, arg_3same *a,
46
crc_ptr = (uint8_t *) &crc;
95
assert(a->q == 0); /* enforced by decode patterns */
47
96
48
if (shift16) {
97
98
- fpstatus = fpstatus_ptr(a->size != 0 ? FPST_STD_F16 : FPST_STD);
99
+ fpstatus = fpstatus_ptr(a->size == MO_16 ? FPST_STD_F16 : FPST_STD);
100
tcg_gen_gvec_3_ptr(vfp_reg_offset(1, a->vd),
101
vfp_reg_offset(1, a->vn),
102
vfp_reg_offset(1, a->vm),
103
@@ -XXX,XX +XXX,XX @@ static bool do_3same_fp_pair(DisasContext *s, arg_3same *a,
104
#define DO_3S_FP_PAIR(INSN,FUNC) \
105
static bool trans_##INSN##_fp_3s(DisasContext *s, arg_3same *a) \
106
{ \
107
- if (a->size != 0) { \
108
+ if (a->size == MO_16) { \
109
if (!dc_isar_feature(aa32_fp16_arith, s)) { \
110
return false; \
111
} \
112
--
49
--
113
2.20.1
50
2.25.1
114
115
diff view generated by jsdifflib
Deleted patch
1
We deprecated the support for KVM on 32-bit Arm hosts in time
2
for release 5.0, which means that our deprecation policy allows
3
us to drop it in release 5.2. Remove the code.
4
1
5
To repeat the rationale from the deprecation note: the Linux
6
kernel dropped support for 32-bit Arm KVM hosts in 5.7.
7
8
Running 32-bit guests on a 64-bit Arm host remains supported.
9
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
13
Message-id: 20200904154156.31943-2-peter.maydell@linaro.org
14
---
15
docs/system/deprecated.rst | 16 +-
16
configure | 2 +-
17
target/arm/kvm32.c | 595 -------------------------------------
18
target/arm/meson.build | 5 +-
19
4 files changed, 10 insertions(+), 608 deletions(-)
20
delete mode 100644 target/arm/kvm32.c
21
22
diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
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
71
index XXXXXXX..XXXXXXX
72
--- a/target/arm/kvm32.c
73
+++ /dev/null
74
@@ -XXX,XX +XXX,XX @@
75
-/*
76
- * ARM implementation of KVM hooks, 32 bit specific code.
77
- *
78
- * Copyright Christoffer Dall 2009-2010
79
- *
80
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
81
- * See the COPYING file in the top-level directory.
82
- *
83
- */
84
-
85
-#include "qemu/osdep.h"
86
-#include <sys/ioctl.h>
87
-
88
-#include <linux/kvm.h>
89
-
90
-#include "qemu-common.h"
91
-#include "cpu.h"
92
-#include "qemu/timer.h"
93
-#include "sysemu/runstate.h"
94
-#include "sysemu/kvm.h"
95
-#include "kvm_arm.h"
96
-#include "internals.h"
97
-#include "qemu/log.h"
98
-
99
-static int read_sys_reg32(int fd, uint32_t *pret, uint64_t id)
100
-{
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
- }
246
-}
247
-
248
-typedef struct CPRegStateLevel {
249
- uint64_t regidx;
250
- int level;
251
-} CPRegStateLevel;
252
-
253
-/* All coprocessor registers not listed in the following table are assumed to
254
- * be of the level KVM_PUT_RUNTIME_STATE. If a register should be written less
255
- * often, you must add it to this table with a state of either
256
- * KVM_PUT_RESET_STATE or KVM_PUT_FULL_STATE.
257
- */
258
-static const CPRegStateLevel non_runtime_cpregs[] = {
259
- { KVM_REG_ARM_TIMER_CNT, KVM_PUT_FULL_STATE },
260
-};
261
-
262
-int kvm_arm_cpreg_level(uint64_t regidx)
263
-{
264
- int i;
265
-
266
- for (i = 0; i < ARRAY_SIZE(non_runtime_cpregs); i++) {
267
- const CPRegStateLevel *l = &non_runtime_cpregs[i];
268
- if (l->regidx == regidx) {
269
- return l->level;
270
- }
271
- }
272
-
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
--
687
2.20.1
688
689
diff view generated by jsdifflib