1
Second pull request of the week; mostly RTH's support for some
1
Nuvoton new board models, and some more minor stuff. I also put
2
new-in-v8.1/v8.3 instructions, and my v8M board model.
2
in the deprecation patches for unicore32 and lm32.
3
3
4
thanks
4
thanks
5
-- PMM
5
-- PMM
6
6
7
The following changes since commit 427cbc7e4136a061628cb4315cc8182ea36d772f:
7
The following changes since commit a68694cd1f3e5448cca814ff39b871f9ebd71ed5:
8
8
9
Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging (2018-03-01 18:46:41 +0000)
9
Merge remote-tracking branch 'remotes/philmd-gitlab/tags/edk2-next-20200914' into staging (2020-09-14 12:18:58 +0100)
10
10
11
are available in the Git repository at:
11
are available in the Git repository at:
12
12
13
git://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20180302
13
https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20200914
14
14
15
for you to fetch changes up to e66a67bf28e1b4fce2e3d72a2610dbd48d9d3078:
15
for you to fetch changes up to dd44ae00fc5342ed99acb68ec3508f76a71d523a:
16
16
17
target/arm: Enable ARM_FEATURE_V8_FCMA (2018-03-02 11:03:45 +0000)
17
MAINTAINERS: Add maintainer entry for Xilinx ZynqMP CAN controller (2020-09-14 14:27:08 +0100)
18
18
19
----------------------------------------------------------------
19
----------------------------------------------------------------
20
target-arm queue:
20
target-arm queue:
21
* implement FCMA and RDM v8.1 and v8.3 instructions
21
* hw/misc/a9scu: Do not allow invalid CPU count
22
* enable Cortex-M33 v8M core, and provide new mps2-an505 board model
22
* hw/misc/a9scu: Minor cleanups
23
that uses it
23
* hw/timer/armv7m_systick: assert that board code set system_clock_scale
24
* decodetree: Propagate return value from translate subroutines
24
* decodetree: Improve identifier matching
25
* xlnx-zynqmp: Implement the RTC device
25
* target/arm: Clean up neon fp insn size field decode
26
* target/arm: Remove KVM support for 32-bit Arm hosts
27
* hw/arm/mps2: New board models mps2-an386, mps2-an500
28
* Deprecate Unicore32 port
29
* Deprecate lm32 port
30
* target/arm: Count PMU events when MDCR.SPME is set
31
* hw/arm: versal-virt: Correct the tx/rx GEM clocks
32
* New Nuvoton iBMC board models npcm750-evb, quanta-gsj
33
* xlnx-zynqmp: implement ZynqMP CAN controllers
26
34
27
----------------------------------------------------------------
35
----------------------------------------------------------------
28
Alistair Francis (3):
36
Aaron Lindsay (1):
29
xlnx-zynqmp-rtc: Initial commit
37
target/arm: Count PMU events when MDCR.SPME is set
30
xlnx-zynqmp-rtc: Add basic time support
31
xlnx-zynqmp: Connect the RTC device
32
38
33
Peter Maydell (19):
39
Edgar E. Iglesias (1):
34
loader: Add new load_ramdisk_as()
40
hw/arm: versal-virt: Correct the tx/rx GEM clocks
35
hw/arm/boot: Honour CPU's address space for image loads
36
hw/arm/armv7m: Honour CPU's address space for image loads
37
target/arm: Define an IDAU interface
38
armv7m: Forward idau property to CPU object
39
target/arm: Define init-svtor property for the reset secure VTOR value
40
armv7m: Forward init-svtor property to CPU object
41
target/arm: Add Cortex-M33
42
hw/misc/unimp: Move struct to header file
43
include/hw/or-irq.h: Add missing include guard
44
qdev: Add new qdev_init_gpio_in_named_with_opaque()
45
hw/core/split-irq: Device that splits IRQ lines
46
hw/misc/mps2-fpgaio: FPGA control block for MPS2 AN505
47
hw/misc/tz-ppc: Model TrustZone peripheral protection controller
48
hw/misc/iotkit-secctl: Arm IoT Kit security controller initial skeleton
49
hw/misc/iotkit-secctl: Add handling for PPCs
50
hw/misc/iotkit-secctl: Add remaining simple registers
51
hw/arm/iotkit: Model Arm IOT Kit
52
mps2-an505: New board model: MPS2 with AN505 Cortex-M33 FPGA image
53
41
54
Richard Henderson (17):
42
Havard Skinnemoen (14):
55
decodetree: Propagate return value from translate subroutines
43
hw/misc: Add NPCM7xx System Global Control Registers device model
56
target/arm: Add ARM_FEATURE_V8_RDM
44
hw/misc: Add NPCM7xx Clock Controller device model
57
target/arm: Refactor disas_simd_indexed decode
45
hw/timer: Add NPCM7xx Timer device model
58
target/arm: Refactor disas_simd_indexed size checks
46
hw/arm: Add NPCM730 and NPCM750 SoC models
59
target/arm: Decode aa64 armv8.1 scalar three same extra
47
hw/arm: Add two NPCM7xx-based machines
60
target/arm: Decode aa64 armv8.1 three same extra
48
roms: Add virtual Boot ROM for NPCM7xx SoCs
61
target/arm: Decode aa64 armv8.1 scalar/vector x indexed element
49
hw/arm: Load -bios image as a boot ROM for npcm7xx
62
target/arm: Decode aa32 armv8.1 three same
50
hw/nvram: NPCM7xx OTP device model
63
target/arm: Decode aa32 armv8.1 two reg and a scalar
51
hw/mem: Stubbed out NPCM7xx Memory Controller model
64
target/arm: Enable ARM_FEATURE_V8_RDM
52
hw/ssi: NPCM7xx Flash Interface Unit device model
65
target/arm: Add ARM_FEATURE_V8_FCMA
53
hw/arm: Wire up BMC boot flash for npcm750-evb and quanta-gsj
66
target/arm: Decode aa64 armv8.3 fcadd
54
hw/arm/npcm7xx: add board setup stub for CPU and UART clocks
67
target/arm: Decode aa64 armv8.3 fcmla
55
docs/system: Add Nuvoton machine documentation
68
target/arm: Decode aa32 armv8.3 3-same
56
tests/acceptance: console boot tests for quanta-gsj
69
target/arm: Decode aa32 armv8.3 2-reg-index
70
target/arm: Decode t32 simd 3reg and 2reg_scalar extension
71
target/arm: Enable ARM_FEATURE_V8_FCMA
72
57
73
hw/arm/Makefile.objs | 2 +
58
Peter Maydell (11):
74
hw/core/Makefile.objs | 1 +
59
hw/timer/armv7m_systick: assert that board code set system_clock_scale
75
hw/misc/Makefile.objs | 4 +
60
target/arm: Convert Neon 3-same-fp size field to MO_* in decode
76
hw/timer/Makefile.objs | 1 +
61
target/arm: Convert Neon VCVT fp size field to MO_* in decode
77
target/arm/Makefile.objs | 2 +-
62
target/arm: Convert VCMLA, VCADD size field to MO_* in decode
78
include/hw/arm/armv7m.h | 5 +
63
target/arm: Remove KVM support for 32-bit Arm hosts
79
include/hw/arm/iotkit.h | 109 ++++++
64
target/arm: Remove no-longer-reachable 32-bit KVM code
80
include/hw/arm/xlnx-zynqmp.h | 2 +
65
hw/arm/mps2: New board model mps2-an386
81
include/hw/core/split-irq.h | 57 +++
66
hw/arm/mps2: New board model mps2-an500
82
include/hw/irq.h | 4 +-
67
docs/system/arm/mps2.rst: Make board list consistent
83
include/hw/loader.h | 12 +-
68
Deprecate Unicore32 port
84
include/hw/misc/iotkit-secctl.h | 103 ++++++
69
Deprecate lm32 port
85
include/hw/misc/mps2-fpgaio.h | 43 +++
86
include/hw/misc/tz-ppc.h | 101 ++++++
87
include/hw/misc/unimp.h | 10 +
88
include/hw/or-irq.h | 5 +
89
include/hw/qdev-core.h | 30 +-
90
include/hw/timer/xlnx-zynqmp-rtc.h | 86 +++++
91
target/arm/cpu.h | 8 +
92
target/arm/helper.h | 31 ++
93
target/arm/idau.h | 61 ++++
94
hw/arm/armv7m.c | 35 +-
95
hw/arm/boot.c | 119 ++++---
96
hw/arm/iotkit.c | 598 +++++++++++++++++++++++++++++++
97
hw/arm/mps2-tz.c | 503 ++++++++++++++++++++++++++
98
hw/arm/xlnx-zynqmp.c | 14 +
99
hw/core/loader.c | 8 +-
100
hw/core/qdev.c | 8 +-
101
hw/core/split-irq.c | 89 +++++
102
hw/misc/iotkit-secctl.c | 704 +++++++++++++++++++++++++++++++++++++
103
hw/misc/mps2-fpgaio.c | 176 ++++++++++
104
hw/misc/tz-ppc.c | 302 ++++++++++++++++
105
hw/misc/unimp.c | 10 -
106
hw/timer/xlnx-zynqmp-rtc.c | 272 ++++++++++++++
107
linux-user/elfload.c | 2 +
108
target/arm/cpu.c | 66 +++-
109
target/arm/cpu64.c | 2 +
110
target/arm/helper.c | 28 +-
111
target/arm/translate-a64.c | 514 +++++++++++++++++++++------
112
target/arm/translate.c | 275 +++++++++++++--
113
target/arm/vec_helper.c | 429 ++++++++++++++++++++++
114
default-configs/arm-softmmu.mak | 5 +
115
hw/misc/trace-events | 24 ++
116
hw/timer/trace-events | 3 +
117
scripts/decodetree.py | 5 +-
118
45 files changed, 4668 insertions(+), 200 deletions(-)
119
create mode 100644 include/hw/arm/iotkit.h
120
create mode 100644 include/hw/core/split-irq.h
121
create mode 100644 include/hw/misc/iotkit-secctl.h
122
create mode 100644 include/hw/misc/mps2-fpgaio.h
123
create mode 100644 include/hw/misc/tz-ppc.h
124
create mode 100644 include/hw/timer/xlnx-zynqmp-rtc.h
125
create mode 100644 target/arm/idau.h
126
create mode 100644 hw/arm/iotkit.c
127
create mode 100644 hw/arm/mps2-tz.c
128
create mode 100644 hw/core/split-irq.c
129
create mode 100644 hw/misc/iotkit-secctl.c
130
create mode 100644 hw/misc/mps2-fpgaio.c
131
create mode 100644 hw/misc/tz-ppc.c
132
create mode 100644 hw/timer/xlnx-zynqmp-rtc.c
133
create mode 100644 target/arm/vec_helper.c
134
70
71
Philippe Mathieu-Daudé (4):
72
hw/misc/a9scu: Do not allow invalid CPU count
73
hw/misc/a9scu: Simplify setting MemoryRegionOps::valid fields
74
hw/misc/a9scu: Simplify setting MemoryRegionOps::impl fields
75
hw/misc/a9scu: Report unimplemented accesses with qemu_log_mask(UNIMP)
76
77
Richard Henderson (1):
78
decodetree: Improve identifier matching
79
80
Vikram Garhwal (4):
81
hw/net/can: Introduce Xilinx ZynqMP CAN controller
82
xlnx-zynqmp: Connect Xilinx ZynqMP CAN controllers
83
tests/qtest: Introduce tests for Xilinx ZynqMP CAN controller
84
MAINTAINERS: Add maintainer entry for Xilinx ZynqMP CAN controller
85
86
docs/system/arm/mps2.rst | 20 +-
87
docs/system/arm/nuvoton.rst | 92 +++
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
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
3
Per the datasheet (DDI0407 r2p0):
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
4
5
Message-id: 20180228193125.20577-12-richard.henderson@linaro.org
5
"The SCU connects one to four Cortex-A9 processors to
6
the memory system through the AXI interfaces."
7
8
Change the instance_init() handler to a device_realize()
9
one so we can verify the property is in range, and return
10
an error to the caller if not.
11
12
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
13
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
14
Message-id: 20200901144100.116742-2-f4bug@amsat.org
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
---
16
---
8
target/arm/helper.h | 7 ++++
17
hw/misc/a9scu.c | 18 +++++++++++++-----
9
target/arm/translate-a64.c | 48 ++++++++++++++++++++++-
18
1 file changed, 13 insertions(+), 5 deletions(-)
10
target/arm/vec_helper.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++
11
3 files changed, 151 insertions(+), 1 deletion(-)
12
19
13
diff --git a/target/arm/helper.h b/target/arm/helper.h
20
diff --git a/hw/misc/a9scu.c b/hw/misc/a9scu.c
14
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
15
--- a/target/arm/helper.h
22
--- a/hw/misc/a9scu.c
16
+++ b/target/arm/helper.h
23
+++ b/hw/misc/a9scu.c
17
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_5(gvec_qrdmlah_s32, TCG_CALL_NO_RWG,
24
@@ -XXX,XX +XXX,XX @@
18
DEF_HELPER_FLAGS_5(gvec_qrdmlsh_s32, TCG_CALL_NO_RWG,
25
#include "hw/misc/a9scu.h"
19
void, ptr, ptr, ptr, ptr, i32)
26
#include "hw/qdev-properties.h"
20
27
#include "migration/vmstate.h"
21
+DEF_HELPER_FLAGS_5(gvec_fcaddh, TCG_CALL_NO_RWG,
28
+#include "qapi/error.h"
22
+ void, ptr, ptr, ptr, ptr, i32)
29
#include "qemu/module.h"
23
+DEF_HELPER_FLAGS_5(gvec_fcadds, TCG_CALL_NO_RWG,
30
24
+ void, ptr, ptr, ptr, ptr, i32)
31
+#define A9_SCU_CPU_MAX 4
25
+DEF_HELPER_FLAGS_5(gvec_fcaddd, TCG_CALL_NO_RWG,
26
+ void, ptr, ptr, ptr, ptr, i32)
27
+
32
+
28
#ifdef TARGET_AARCH64
33
static uint64_t a9_scu_read(void *opaque, hwaddr offset,
29
#include "helper-a64.h"
34
unsigned size)
30
#endif
35
{
31
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
36
@@ -XXX,XX +XXX,XX @@ static void a9_scu_reset(DeviceState *dev)
32
index XXXXXXX..XXXXXXX 100644
37
s->control = 0;
33
--- a/target/arm/translate-a64.c
34
+++ b/target/arm/translate-a64.c
35
@@ -XXX,XX +XXX,XX @@ static void gen_gvec_op3_env(DisasContext *s, bool is_q, int rd,
36
is_q ? 16 : 8, vec_full_reg_size(s), 0, fn);
37
}
38
}
38
39
39
+/* Expand a 3-operand + fpstatus pointer + simd data value operation using
40
-static void a9_scu_init(Object *obj)
40
+ * an out-of-line helper.
41
+static void a9_scu_realize(DeviceState *dev, Error **errp)
41
+ */
42
{
42
+static void gen_gvec_op3_fpst(DisasContext *s, bool is_q, int rd, int rn,
43
- A9SCUState *s = A9_SCU(obj);
43
+ int rm, bool is_fp16, int data,
44
- SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
44
+ gen_helper_gvec_3_ptr *fn)
45
+ A9SCUState *s = A9_SCU(dev);
45
+{
46
+ SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
46
+ TCGv_ptr fpst = get_fpstatus_ptr(is_fp16);
47
47
+ tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, rd),
48
- memory_region_init_io(&s->iomem, obj, &a9_scu_ops, s,
48
+ vec_full_reg_offset(s, rn),
49
+ if (!s->num_cpu || s->num_cpu > A9_SCU_CPU_MAX) {
49
+ vec_full_reg_offset(s, rm), fpst,
50
+ error_setg(errp, "Illegal CPU count: %u", s->num_cpu);
50
+ is_q ? 16 : 8, vec_full_reg_size(s), data, fn);
51
+ return;
51
+ tcg_temp_free_ptr(fpst);
52
+ }
52
+}
53
+
53
+
54
/* Set ZF and NF based on a 64 bit result. This is alas fiddlier
54
+ memory_region_init_io(&s->iomem, OBJECT(s), &a9_scu_ops, s,
55
* than the 32 bit equivalent.
55
"a9-scu", 0x100);
56
*/
56
sysbus_init_mmio(sbd, &s->iomem);
57
@@ -XXX,XX +XXX,XX @@ static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn)
58
int size = extract32(insn, 22, 2);
59
bool u = extract32(insn, 29, 1);
60
bool is_q = extract32(insn, 30, 1);
61
- int feature;
62
+ int feature, rot;
63
64
switch (u * 16 + opcode) {
65
case 0x10: /* SQRDMLAH (vector) */
66
@@ -XXX,XX +XXX,XX @@ static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn)
67
}
68
feature = ARM_FEATURE_V8_RDM;
69
break;
70
+ case 0xc: /* FCADD, #90 */
71
+ case 0xe: /* FCADD, #270 */
72
+ if (size == 0
73
+ || (size == 1 && !arm_dc_feature(s, ARM_FEATURE_V8_FP16))
74
+ || (size == 3 && !is_q)) {
75
+ unallocated_encoding(s);
76
+ return;
77
+ }
78
+ feature = ARM_FEATURE_V8_FCMA;
79
+ break;
80
default:
81
unallocated_encoding(s);
82
return;
83
@@ -XXX,XX +XXX,XX @@ static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn)
84
}
85
return;
86
87
+ case 0xc: /* FCADD, #90 */
88
+ case 0xe: /* FCADD, #270 */
89
+ rot = extract32(opcode, 1, 1);
90
+ switch (size) {
91
+ case 1:
92
+ gen_gvec_op3_fpst(s, is_q, rd, rn, rm, size == 1, rot,
93
+ gen_helper_gvec_fcaddh);
94
+ break;
95
+ case 2:
96
+ gen_gvec_op3_fpst(s, is_q, rd, rn, rm, size == 1, rot,
97
+ gen_helper_gvec_fcadds);
98
+ break;
99
+ case 3:
100
+ gen_gvec_op3_fpst(s, is_q, rd, rn, rm, size == 1, rot,
101
+ gen_helper_gvec_fcaddd);
102
+ break;
103
+ default:
104
+ g_assert_not_reached();
105
+ }
106
+ return;
107
+
108
default:
109
g_assert_not_reached();
110
}
111
diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c
112
index XXXXXXX..XXXXXXX 100644
113
--- a/target/arm/vec_helper.c
114
+++ b/target/arm/vec_helper.c
115
@@ -XXX,XX +XXX,XX @@
116
#include "exec/exec-all.h"
117
#include "exec/helper-proto.h"
118
#include "tcg/tcg-gvec-desc.h"
119
+#include "fpu/softfloat.h"
120
121
122
+/* Note that vector data is stored in host-endian 64-bit chunks,
123
+ so addressing units smaller than that needs a host-endian fixup. */
124
+#ifdef HOST_WORDS_BIGENDIAN
125
+#define H1(x) ((x) ^ 7)
126
+#define H2(x) ((x) ^ 3)
127
+#define H4(x) ((x) ^ 1)
128
+#else
129
+#define H1(x) (x)
130
+#define H2(x) (x)
131
+#define H4(x) (x)
132
+#endif
133
+
134
#define SET_QC() env->vfp.xregs[ARM_VFP_FPSCR] |= CPSR_Q
135
136
static void clear_tail(void *vd, uintptr_t opr_sz, uintptr_t max_sz)
137
@@ -XXX,XX +XXX,XX @@ void HELPER(gvec_qrdmlsh_s32)(void *vd, void *vn, void *vm,
138
}
139
clear_tail(d, opr_sz, simd_maxsz(desc));
140
}
57
}
141
+
58
@@ -XXX,XX +XXX,XX @@ static void a9_scu_class_init(ObjectClass *klass, void *data)
142
+void HELPER(gvec_fcaddh)(void *vd, void *vn, void *vm,
59
device_class_set_props(dc, a9_scu_properties);
143
+ void *vfpst, uint32_t desc)
60
dc->vmsd = &vmstate_a9_scu;
144
+{
61
dc->reset = a9_scu_reset;
145
+ uintptr_t opr_sz = simd_oprsz(desc);
62
+ dc->realize = a9_scu_realize;
146
+ float16 *d = vd;
63
}
147
+ float16 *n = vn;
64
148
+ float16 *m = vm;
65
static const TypeInfo a9_scu_info = {
149
+ float_status *fpst = vfpst;
66
.name = TYPE_A9_SCU,
150
+ uint32_t neg_real = extract32(desc, SIMD_DATA_SHIFT, 1);
67
.parent = TYPE_SYS_BUS_DEVICE,
151
+ uint32_t neg_imag = neg_real ^ 1;
68
.instance_size = sizeof(A9SCUState),
152
+ uintptr_t i;
69
- .instance_init = a9_scu_init,
153
+
70
.class_init = a9_scu_class_init,
154
+ /* Shift boolean to the sign bit so we can xor to negate. */
71
};
155
+ neg_real <<= 15;
72
156
+ neg_imag <<= 15;
157
+
158
+ for (i = 0; i < opr_sz / 2; i += 2) {
159
+ float16 e0 = n[H2(i)];
160
+ float16 e1 = m[H2(i + 1)] ^ neg_imag;
161
+ float16 e2 = n[H2(i + 1)];
162
+ float16 e3 = m[H2(i)] ^ neg_real;
163
+
164
+ d[H2(i)] = float16_add(e0, e1, fpst);
165
+ d[H2(i + 1)] = float16_add(e2, e3, fpst);
166
+ }
167
+ clear_tail(d, opr_sz, simd_maxsz(desc));
168
+}
169
+
170
+void HELPER(gvec_fcadds)(void *vd, void *vn, void *vm,
171
+ void *vfpst, uint32_t desc)
172
+{
173
+ uintptr_t opr_sz = simd_oprsz(desc);
174
+ float32 *d = vd;
175
+ float32 *n = vn;
176
+ float32 *m = vm;
177
+ float_status *fpst = vfpst;
178
+ uint32_t neg_real = extract32(desc, SIMD_DATA_SHIFT, 1);
179
+ uint32_t neg_imag = neg_real ^ 1;
180
+ uintptr_t i;
181
+
182
+ /* Shift boolean to the sign bit so we can xor to negate. */
183
+ neg_real <<= 31;
184
+ neg_imag <<= 31;
185
+
186
+ for (i = 0; i < opr_sz / 4; i += 2) {
187
+ float32 e0 = n[H4(i)];
188
+ float32 e1 = m[H4(i + 1)] ^ neg_imag;
189
+ float32 e2 = n[H4(i + 1)];
190
+ float32 e3 = m[H4(i)] ^ neg_real;
191
+
192
+ d[H4(i)] = float32_add(e0, e1, fpst);
193
+ d[H4(i + 1)] = float32_add(e2, e3, fpst);
194
+ }
195
+ clear_tail(d, opr_sz, simd_maxsz(desc));
196
+}
197
+
198
+void HELPER(gvec_fcaddd)(void *vd, void *vn, void *vm,
199
+ void *vfpst, uint32_t desc)
200
+{
201
+ uintptr_t opr_sz = simd_oprsz(desc);
202
+ float64 *d = vd;
203
+ float64 *n = vn;
204
+ float64 *m = vm;
205
+ float_status *fpst = vfpst;
206
+ uint64_t neg_real = extract64(desc, SIMD_DATA_SHIFT, 1);
207
+ uint64_t neg_imag = neg_real ^ 1;
208
+ uintptr_t i;
209
+
210
+ /* Shift boolean to the sign bit so we can xor to negate. */
211
+ neg_real <<= 63;
212
+ neg_imag <<= 63;
213
+
214
+ for (i = 0; i < opr_sz / 8; i += 2) {
215
+ float64 e0 = n[i];
216
+ float64 e1 = m[i + 1] ^ neg_imag;
217
+ float64 e2 = n[i + 1];
218
+ float64 e3 = m[i] ^ neg_real;
219
+
220
+ d[i] = float64_add(e0, e1, fpst);
221
+ d[i + 1] = float64_add(e2, e3, fpst);
222
+ }
223
+ clear_tail(d, opr_sz, simd_maxsz(desc));
224
+}
225
--
73
--
226
2.16.2
74
2.20.1
227
75
228
76
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
Not enabled anywhere yet.
3
Per the datasheet (DDI0407 r2p0):
4
4
5
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
5
"All SCU registers are byte accessible" and are 32-bit aligned.
6
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
6
7
Message-id: 20180228193125.20577-11-richard.henderson@linaro.org
7
Set MemoryRegionOps::valid min/max fields and simplify the write()
8
handler.
9
10
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Message-id: 20200901144100.116742-3-f4bug@amsat.org
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
14
---
10
target/arm/cpu.h | 1 +
15
hw/misc/a9scu.c | 21 +++++----------------
11
linux-user/elfload.c | 1 +
16
1 file changed, 5 insertions(+), 16 deletions(-)
12
2 files changed, 2 insertions(+)
13
17
14
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
18
diff --git a/hw/misc/a9scu.c b/hw/misc/a9scu.c
15
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
16
--- a/target/arm/cpu.h
20
--- a/hw/misc/a9scu.c
17
+++ b/target/arm/cpu.h
21
+++ b/hw/misc/a9scu.c
18
@@ -XXX,XX +XXX,XX @@ enum arm_features {
22
@@ -XXX,XX +XXX,XX @@ static void a9_scu_write(void *opaque, hwaddr offset,
19
ARM_FEATURE_V8_SM4, /* implements SM4 part of v8 Crypto Extensions */
23
uint64_t value, unsigned size)
20
ARM_FEATURE_V8_RDM, /* implements v8.1 simd round multiply */
24
{
21
ARM_FEATURE_V8_FP16, /* implements v8.2 half-precision float */
25
A9SCUState *s = (A9SCUState *)opaque;
22
+ ARM_FEATURE_V8_FCMA, /* has complex number part of v8.3 extensions. */
26
- uint32_t mask;
27
+ uint32_t mask = MAKE_64BIT_MASK(0, size * 8);
28
uint32_t shift;
29
- switch (size) {
30
- case 1:
31
- mask = 0xff;
32
- break;
33
- case 2:
34
- mask = 0xffff;
35
- break;
36
- case 4:
37
- mask = 0xffffffff;
38
- break;
39
- default:
40
- fprintf(stderr, "Invalid size %u in write to a9 scu register %x\n",
41
- size, (unsigned)offset);
42
- return;
43
- }
44
45
switch (offset) {
46
case 0x00: /* Control */
47
@@ -XXX,XX +XXX,XX @@ static void a9_scu_write(void *opaque, hwaddr offset,
48
static const MemoryRegionOps a9_scu_ops = {
49
.read = a9_scu_read,
50
.write = a9_scu_write,
51
+ .valid = {
52
+ .min_access_size = 1,
53
+ .max_access_size = 4,
54
+ },
55
.endianness = DEVICE_NATIVE_ENDIAN,
23
};
56
};
24
57
25
static inline int arm_feature(CPUARMState *env, int feature)
26
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
27
index XXXXXXX..XXXXXXX 100644
28
--- a/linux-user/elfload.c
29
+++ b/linux-user/elfload.c
30
@@ -XXX,XX +XXX,XX @@ static uint32_t get_elf_hwcap(void)
31
GET_FEATURE(ARM_FEATURE_V8_FP16,
32
ARM_HWCAP_A64_FPHP | ARM_HWCAP_A64_ASIMDHP);
33
GET_FEATURE(ARM_FEATURE_V8_RDM, ARM_HWCAP_A64_ASIMDRDM);
34
+ GET_FEATURE(ARM_FEATURE_V8_FCMA, ARM_HWCAP_A64_FCMA);
35
#undef GET_FEATURE
36
37
return hwcaps;
38
--
58
--
39
2.16.2
59
2.20.1
40
60
41
61
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
Happily, the bits are in the same places compared to a32.
3
This model implementation is designed for 32-bit accesses.
4
We can simplify setting the MemoryRegionOps::impl min/max
5
fields to 32-bit (memory::access_with_adjusted_size() will
6
take care of the 8/16-bit accesses).
4
7
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Message-id: 20180228193125.20577-16-richard.henderson@linaro.org
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
10
Message-id: 20200901144100.116742-4-f4bug@amsat.org
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
12
---
10
target/arm/translate.c | 14 +++++++++++++-
13
hw/misc/a9scu.c | 16 +++++-----------
11
1 file changed, 13 insertions(+), 1 deletion(-)
14
1 file changed, 5 insertions(+), 11 deletions(-)
12
15
13
diff --git a/target/arm/translate.c b/target/arm/translate.c
16
diff --git a/hw/misc/a9scu.c b/hw/misc/a9scu.c
14
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
15
--- a/target/arm/translate.c
18
--- a/hw/misc/a9scu.c
16
+++ b/target/arm/translate.c
19
+++ b/hw/misc/a9scu.c
17
@@ -XXX,XX +XXX,XX @@ static void disas_thumb2_insn(DisasContext *s, uint32_t insn)
20
@@ -XXX,XX +XXX,XX @@ static uint64_t a9_scu_read(void *opaque, hwaddr offset,
18
default_exception_el(s));
21
return (((1 << s->num_cpu) - 1) << 4) | (s->num_cpu - 1);
19
break;
22
case 0x08: /* CPU Power Status */
20
}
23
return s->status;
21
- if (((insn >> 24) & 3) == 3) {
24
- case 0x09: /* CPU status. */
22
+ if ((insn & 0xfe000a00) == 0xfc000800
25
- return s->status >> 8;
23
+ && arm_dc_feature(s, ARM_FEATURE_V8)) {
26
- case 0x0a: /* CPU status. */
24
+ /* The Thumb2 and ARM encodings are identical. */
27
- return s->status >> 16;
25
+ if (disas_neon_insn_3same_ext(s, insn)) {
28
- case 0x0b: /* CPU status. */
26
+ goto illegal_op;
29
- return s->status >> 24;
27
+ }
30
case 0x0c: /* Invalidate All Registers In Secure State */
28
+ } else if ((insn & 0xff000a00) == 0xfe000800
31
return 0;
29
+ && arm_dc_feature(s, ARM_FEATURE_V8)) {
32
case 0x40: /* Filtering Start Address Register */
30
+ /* The Thumb2 and ARM encodings are identical. */
33
@@ -XXX,XX +XXX,XX @@ static void a9_scu_write(void *opaque, hwaddr offset,
31
+ if (disas_neon_insn_2reg_scalar_ext(s, insn)) {
34
uint64_t value, unsigned size)
32
+ goto illegal_op;
35
{
33
+ }
36
A9SCUState *s = (A9SCUState *)opaque;
34
+ } else if (((insn >> 24) & 3) == 3) {
37
- uint32_t mask = MAKE_64BIT_MASK(0, size * 8);
35
/* Translate into the equivalent ARM encoding. */
38
- uint32_t shift;
36
insn = (insn & 0xe2ffffff) | ((insn & (1 << 28)) >> 4) | (1 << 28);
39
37
if (disas_neon_data_insn(s, insn)) {
40
switch (offset) {
41
case 0x00: /* Control */
42
@@ -XXX,XX +XXX,XX @@ static void a9_scu_write(void *opaque, hwaddr offset,
43
case 0x4: /* Configuration: RO */
44
break;
45
case 0x08: case 0x09: case 0x0A: case 0x0B: /* Power Control */
46
- shift = (offset - 0x8) * 8;
47
- s->status &= ~(mask << shift);
48
- s->status |= ((value & mask) << shift);
49
+ s->status = value;
50
break;
51
case 0x0c: /* Invalidate All Registers In Secure State */
52
/* no-op as we do not implement caches */
53
@@ -XXX,XX +XXX,XX @@ static void a9_scu_write(void *opaque, hwaddr offset,
54
static const MemoryRegionOps a9_scu_ops = {
55
.read = a9_scu_read,
56
.write = a9_scu_write,
57
+ .impl = {
58
+ .min_access_size = 4,
59
+ .max_access_size = 4,
60
+ },
61
.valid = {
62
.min_access_size = 1,
63
.max_access_size = 4,
38
--
64
--
39
2.16.2
65
2.20.1
40
66
41
67
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
Enable it for the "any" CPU used by *-linux-user.
3
Report unimplemented register accesses using qemu_log_mask(UNIMP).
4
4
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20180228193125.20577-17-richard.henderson@linaro.org
7
Message-id: 20200901144100.116742-5-f4bug@amsat.org
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
9
---
10
target/arm/cpu.c | 1 +
10
hw/misc/a9scu.c | 6 ++++++
11
target/arm/cpu64.c | 1 +
11
1 file changed, 6 insertions(+)
12
2 files changed, 2 insertions(+)
13
12
14
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
13
diff --git a/hw/misc/a9scu.c b/hw/misc/a9scu.c
15
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
16
--- a/target/arm/cpu.c
15
--- a/hw/misc/a9scu.c
17
+++ b/target/arm/cpu.c
16
+++ b/hw/misc/a9scu.c
18
@@ -XXX,XX +XXX,XX @@ static void arm_any_initfn(Object *obj)
17
@@ -XXX,XX +XXX,XX @@
19
set_feature(&cpu->env, ARM_FEATURE_V8_PMULL);
18
#include "hw/qdev-properties.h"
20
set_feature(&cpu->env, ARM_FEATURE_CRC);
19
#include "migration/vmstate.h"
21
set_feature(&cpu->env, ARM_FEATURE_V8_RDM);
20
#include "qapi/error.h"
22
+ set_feature(&cpu->env, ARM_FEATURE_V8_FCMA);
21
+#include "qemu/log.h"
23
cpu->midr = 0xffffffff;
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
}
24
}
33
}
25
#endif
34
@@ -XXX,XX +XXX,XX @@ static void a9_scu_write(void *opaque, hwaddr offset,
26
diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
35
case 0x54: /* SCU Non-secure Access Control Register */
27
index XXXXXXX..XXXXXXX 100644
36
/* unimplemented, fall through */
28
--- a/target/arm/cpu64.c
37
default:
29
+++ b/target/arm/cpu64.c
38
+ qemu_log_mask(LOG_UNIMP, "%s: Unsupported offset 0x%"HWADDR_PRIx
30
@@ -XXX,XX +XXX,XX @@ static void aarch64_any_initfn(Object *obj)
39
+ " value 0x%"PRIx64"\n",
31
set_feature(&cpu->env, ARM_FEATURE_CRC);
40
+ __func__, offset, value);
32
set_feature(&cpu->env, ARM_FEATURE_V8_RDM);
41
break;
33
set_feature(&cpu->env, ARM_FEATURE_V8_FP16);
42
}
34
+ set_feature(&cpu->env, ARM_FEATURE_V8_FCMA);
35
cpu->ctr = 0x80038003; /* 32 byte I and D cacheline size, VIPT icache */
36
cpu->dcz_blocksize = 7; /* 512 bytes */
37
}
43
}
38
--
44
--
39
2.16.2
45
2.20.1
40
46
41
47
diff view generated by jsdifflib
1
The function qdev_init_gpio_in_named() passes the DeviceState pointer
1
It is the responsibility of board code for an armv7m system to set
2
as the opaque data pointor for the irq handler function. Usually
2
system_clock_scale appropriately for the CPU speed of the core.
3
this is what you want, but in some cases it would be helpful to use
3
If it forgets to do this, then QEMU will hang if the guest tries
4
some other data pointer.
4
to use the systick timer in the "tick at the CPU clock frequency" mode.
5
5
6
Add a new function qdev_init_gpio_in_named_with_opaque() which allows
6
We forgot that in a couple of our boards (see commits ce4f70e81ed23c93f,
7
the caller to specify the data pointer they want.
7
e7e5a9595ab1136). Add an assertion in the systick reset method so
8
we don't let any new boards in with the same bug.
8
9
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
11
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Message-id: 20200825160847.18091-1-peter.maydell@linaro.org
12
Message-id: 20180220180325.29818-12-peter.maydell@linaro.org
13
---
13
---
14
include/hw/qdev-core.h | 30 ++++++++++++++++++++++++++++--
14
hw/timer/armv7m_systick.c | 8 ++++++++
15
hw/core/qdev.c | 8 +++++---
15
1 file changed, 8 insertions(+)
16
2 files changed, 33 insertions(+), 5 deletions(-)
17
16
18
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
17
diff --git a/hw/timer/armv7m_systick.c b/hw/timer/armv7m_systick.c
19
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
20
--- a/include/hw/qdev-core.h
19
--- a/hw/timer/armv7m_systick.c
21
+++ b/include/hw/qdev-core.h
20
+++ b/hw/timer/armv7m_systick.c
22
@@ -XXX,XX +XXX,XX @@ BusState *qdev_get_child_bus(DeviceState *dev, const char *name);
21
@@ -XXX,XX +XXX,XX @@ static void systick_reset(DeviceState *dev)
23
/* GPIO inputs also double as IRQ sinks. */
22
{
24
void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
23
SysTickState *s = SYSTICK(dev);
25
void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
24
26
-void qdev_init_gpio_in_named(DeviceState *dev, qemu_irq_handler handler,
25
+ /*
27
- const char *name, int n);
26
+ * Forgetting to set system_clock_scale is always a board code
28
void qdev_init_gpio_out_named(DeviceState *dev, qemu_irq *pins,
27
+ * bug. We can't check this earlier because for some boards
29
const char *name, int n);
28
+ * (like stellaris) it is not yet configured at the point where
30
+/**
29
+ * the systick device is realized.
31
+ * qdev_init_gpio_in_named_with_opaque: create an array of input GPIO lines
30
+ */
32
+ * for the specified device
31
+ assert(system_clock_scale != 0);
33
+ *
34
+ * @dev: Device to create input GPIOs for
35
+ * @handler: Function to call when GPIO line value is set
36
+ * @opaque: Opaque data pointer to pass to @handler
37
+ * @name: Name of the GPIO input (must be unique for this device)
38
+ * @n: Number of GPIO lines in this input set
39
+ */
40
+void qdev_init_gpio_in_named_with_opaque(DeviceState *dev,
41
+ qemu_irq_handler handler,
42
+ void *opaque,
43
+ const char *name, int n);
44
+
32
+
45
+/**
33
s->control = 0;
46
+ * qdev_init_gpio_in_named: create an array of input GPIO lines
34
s->reload = 0;
47
+ * for the specified device
35
s->tick = 0;
48
+ *
49
+ * Like qdev_init_gpio_in_named_with_opaque(), but the opaque pointer
50
+ * passed to the handler is @dev (which is the most commonly desired behaviour).
51
+ */
52
+static inline void qdev_init_gpio_in_named(DeviceState *dev,
53
+ qemu_irq_handler handler,
54
+ const char *name, int n)
55
+{
56
+ qdev_init_gpio_in_named_with_opaque(dev, handler, dev, name, n);
57
+}
58
59
void qdev_pass_gpios(DeviceState *dev, DeviceState *container,
60
const char *name);
61
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
62
index XXXXXXX..XXXXXXX 100644
63
--- a/hw/core/qdev.c
64
+++ b/hw/core/qdev.c
65
@@ -XXX,XX +XXX,XX @@ static NamedGPIOList *qdev_get_named_gpio_list(DeviceState *dev,
66
return ngl;
67
}
68
69
-void qdev_init_gpio_in_named(DeviceState *dev, qemu_irq_handler handler,
70
- const char *name, int n)
71
+void qdev_init_gpio_in_named_with_opaque(DeviceState *dev,
72
+ qemu_irq_handler handler,
73
+ void *opaque,
74
+ const char *name, int n)
75
{
76
int i;
77
NamedGPIOList *gpio_list = qdev_get_named_gpio_list(dev, name);
78
79
assert(gpio_list->num_out == 0 || !name);
80
gpio_list->in = qemu_extend_irqs(gpio_list->in, gpio_list->num_in, handler,
81
- dev, n);
82
+ opaque, n);
83
84
if (!name) {
85
name = "unnamed-gpio-in";
86
--
36
--
87
2.16.2
37
2.20.1
88
38
89
39
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Richard Henderson <richard.henderson@linaro.org>
2
2
3
Allow the translate subroutines to return false for invalid insns.
3
Only argument set members have to be C identifiers, everything
4
else gets prefixed during conversion to C. Some places just
5
checked the leading character, and some places matched a leading
6
character plus a C identifier.
4
7
5
At present we can of course invoke an invalid insn exception from within
8
Convert everything to match full identifiers, including the
6
the translate subroutine, but in the short term this consolidates code.
9
[&%@&] prefix, and drop the full C identifier requirement.
7
In the long term it would allow the decodetree language to support
8
overlapping patterns for ISA extensions.
9
10
11
Reported-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
12
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
11
Message-id: 20180227232618.2908-1-richard.henderson@linaro.org
13
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
12
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
14
Message-id: 20200903192334.1603773-1-richard.henderson@linaro.org
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
---
16
---
15
scripts/decodetree.py | 5 ++---
17
tests/decode/succ_ident1.decode | 7 +++++
16
1 file changed, 2 insertions(+), 3 deletions(-)
18
scripts/decodetree.py | 46 +++++++++++++++++++++------------
19
2 files changed, 37 insertions(+), 16 deletions(-)
20
create mode 100644 tests/decode/succ_ident1.decode
17
21
22
diff --git a/tests/decode/succ_ident1.decode b/tests/decode/succ_ident1.decode
23
new file mode 100644
24
index XXXXXXX..XXXXXXX
25
--- /dev/null
26
+++ b/tests/decode/succ_ident1.decode
27
@@ -XXX,XX +XXX,XX @@
28
+%1f 0:8
29
+%2f 8:8
30
+%3f 16:8
31
+
32
+&3arg a b c
33
+@3arg ........ ........ ........ ........ &3arg a=%1f b=%2f c=%3f
34
+3insn 00000000 ........ ........ ........ @3arg
18
diff --git a/scripts/decodetree.py b/scripts/decodetree.py
35
diff --git a/scripts/decodetree.py b/scripts/decodetree.py
19
index XXXXXXX..XXXXXXX 100755
36
index XXXXXXX..XXXXXXX 100644
20
--- a/scripts/decodetree.py
37
--- a/scripts/decodetree.py
21
+++ b/scripts/decodetree.py
38
+++ b/scripts/decodetree.py
22
@@ -XXX,XX +XXX,XX @@ class Pattern(General):
39
@@ -XXX,XX +XXX,XX @@ output_fd = None
23
global translate_prefix
40
insntype = 'uint32_t'
24
output('typedef ', self.base.base.struct_name(),
41
decode_function = 'decode'
25
' arg_', self.name, ';\n')
42
26
- output(translate_scope, 'void ', translate_prefix, '_', self.name,
43
-re_ident = '[a-zA-Z][a-zA-Z0-9_]*'
27
+ output(translate_scope, 'bool ', translate_prefix, '_', self.name,
44
+# An identifier for C.
28
'(DisasContext *ctx, arg_', self.name,
45
+re_C_ident = '[a-zA-Z][a-zA-Z0-9_]*'
29
' *a, ', insntype, ' insn);\n')
46
30
47
+# Identifiers for Arguments, Fields, Formats and Patterns.
31
@@ -XXX,XX +XXX,XX @@ class Pattern(General):
48
+re_arg_ident = '&[a-zA-Z0-9_]*'
32
output(ind, self.base.extract_name(), '(&u.f_', arg, ', insn);\n')
49
+re_fld_ident = '%[a-zA-Z0-9_]*'
33
for n, f in self.fields.items():
50
+re_fmt_ident = '@[a-zA-Z0-9_]*'
34
output(ind, 'u.f_', arg, '.', n, ' = ', f.str_extract(), ';\n')
51
+re_pat_ident = '[a-zA-Z0-9_]*'
35
- output(ind, translate_prefix, '_', self.name,
52
36
+ output(ind, 'return ', translate_prefix, '_', self.name,
53
def error_with_file(file, lineno, *args):
37
'(ctx, &u.f_', arg, ', insn);\n')
54
"""Print an error message from file:line and args and exit."""
38
- output(ind, 'return true;\n')
55
@@ -XXX,XX +XXX,XX @@ class ExcMultiPattern(MultiPattern):
39
# end Pattern
56
def parse_field(lineno, name, toks):
40
57
"""Parse one instruction field from TOKS at LINENO"""
41
58
global fields
59
- global re_ident
60
global insnwidth
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:
42
--
184
--
43
2.16.2
185
2.20.1
44
186
45
187
diff view generated by jsdifflib
1
Add a Cortex-M33 definition. The M33 is an M profile CPU
1
In the Neon instructions, some instruction formats have a 2-bit size
2
which implements the ARM v8M architecture, including the
2
field which corresponds exactly to QEMU's MO_8/16/32/64. However the
3
M profile Security Extension.
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
9
Move the handling of the 1-bit size to the decodetree file, so that
10
all these insns consistently pass a size to the trans_ function which
11
is an MO_8/16/32/64 value.
12
13
In this commit we switch over the insns using the 3same_fp and
14
3same_fp_q0 formats.
4
15
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
17
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20180220180325.29818-9-peter.maydell@linaro.org
18
Message-id: 20200903133209.5141-2-peter.maydell@linaro.org
8
---
19
---
9
target/arm/cpu.c | 31 +++++++++++++++++++++++++++++++
20
target/arm/neon-dp.decode | 15 ++++++++++-----
10
1 file changed, 31 insertions(+)
21
target/arm/translate-neon.c.inc | 16 +++++++++++-----
22
2 files changed, 21 insertions(+), 10 deletions(-)
11
23
12
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
24
diff --git a/target/arm/neon-dp.decode b/target/arm/neon-dp.decode
13
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
14
--- a/target/arm/cpu.c
26
--- a/target/arm/neon-dp.decode
15
+++ b/target/arm/cpu.c
27
+++ b/target/arm/neon-dp.decode
16
@@ -XXX,XX +XXX,XX @@ static void cortex_m4_initfn(Object *obj)
28
@@ -XXX,XX +XXX,XX @@
17
cpu->id_isar5 = 0x00000000;
29
@3same_q0 .... ... . . . size:2 .... .... .... . 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;
18
}
56
}
19
57
20
+static void cortex_m33_initfn(Object *obj)
58
+static inline int neon_3same_fp_size(DisasContext *s, int x)
21
+{
59
+{
22
+ ARMCPU *cpu = ARM_CPU(obj);
60
+ /* Convert 0==fp32, 1==fp16 into a MO_* value */
23
+
61
+ return MO_32 - x;
24
+ set_feature(&cpu->env, ARM_FEATURE_V8);
25
+ set_feature(&cpu->env, ARM_FEATURE_M);
26
+ set_feature(&cpu->env, ARM_FEATURE_M_SECURITY);
27
+ set_feature(&cpu->env, ARM_FEATURE_THUMB_DSP);
28
+ cpu->midr = 0x410fd213; /* r0p3 */
29
+ cpu->pmsav7_dregion = 16;
30
+ cpu->sau_sregion = 8;
31
+ cpu->id_pfr0 = 0x00000030;
32
+ cpu->id_pfr1 = 0x00000210;
33
+ cpu->id_dfr0 = 0x00200000;
34
+ cpu->id_afr0 = 0x00000000;
35
+ cpu->id_mmfr0 = 0x00101F40;
36
+ cpu->id_mmfr1 = 0x00000000;
37
+ cpu->id_mmfr2 = 0x01000000;
38
+ cpu->id_mmfr3 = 0x00000000;
39
+ cpu->id_isar0 = 0x01101110;
40
+ cpu->id_isar1 = 0x02212000;
41
+ cpu->id_isar2 = 0x20232232;
42
+ cpu->id_isar3 = 0x01111131;
43
+ cpu->id_isar4 = 0x01310132;
44
+ cpu->id_isar5 = 0x00000000;
45
+ cpu->clidr = 0x00000000;
46
+ cpu->ctr = 0x8000c000;
47
+}
62
+}
48
+
63
+
49
static void arm_v7m_class_init(ObjectClass *oc, void *data)
64
/* Include the generated Neon decoder */
50
{
65
#include "decode-neon-dp.c.inc"
51
CPUClass *cc = CPU_CLASS(oc);
66
#include "decode-neon-ls.c.inc"
52
@@ -XXX,XX +XXX,XX @@ static const ARMCPUInfo arm_cpus[] = {
67
@@ -XXX,XX +XXX,XX @@ DO_3SAME_VQDMULH(VQRDMULH, qrdmulh)
53
.class_init = arm_v7m_class_init },
68
WRAP_FP_GVEC(gen_##INSN##_fp16_3s, FPST_STD_F16, HFUNC) \
54
{ .name = "cortex-m4", .initfn = cortex_m4_initfn,
69
static bool trans_##INSN##_fp_3s(DisasContext *s, arg_3same *a) \
55
.class_init = arm_v7m_class_init },
70
{ \
56
+ { .name = "cortex-m33", .initfn = cortex_m33_initfn,
71
- if (a->size != 0) { \
57
+ .class_init = arm_v7m_class_init },
72
+ if (a->size == MO_16) { \
58
{ .name = "cortex-r5", .initfn = cortex_r5_initfn },
73
if (!dc_isar_feature(aa32_fp16_arith, s)) { \
59
{ .name = "cortex-a7", .initfn = cortex_a7_initfn },
74
return false; \
60
{ .name = "cortex-a8", .initfn = cortex_a8_initfn },
75
} \
76
@@ -XXX,XX +XXX,XX @@ static bool trans_VMAXNM_fp_3s(DisasContext *s, arg_3same *a)
77
return false;
78
}
79
80
- if (a->size != 0) {
81
+ if (a->size == MO_16) {
82
if (!dc_isar_feature(aa32_fp16_arith, s)) {
83
return false;
84
}
85
@@ -XXX,XX +XXX,XX @@ static bool trans_VMINNM_fp_3s(DisasContext *s, arg_3same *a)
86
return false;
87
}
88
89
- if (a->size != 0) {
90
+ if (a->size == MO_16) {
91
if (!dc_isar_feature(aa32_fp16_arith, s)) {
92
return false;
93
}
94
@@ -XXX,XX +XXX,XX @@ static bool do_3same_fp_pair(DisasContext *s, arg_3same *a,
95
assert(a->q == 0); /* enforced by decode patterns */
96
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
} \
61
--
112
--
62
2.16.2
113
2.20.1
63
114
64
115
diff view generated by jsdifflib
1
Add remaining easy registers to iotkit-secctl:
1
Convert the insns using the 2reg_vcvt and 2reg_vcvt_f16 formats
2
* NSCCFG just routes its two bits out to external GPIO lines
2
to pass the size through to the trans function as a MO_* value
3
* BRGINSTAT/BRGINTCLR/BRGINTEN can be dummies, because QEMU's
3
rather than the '0==f32, 1==f16' used in the fp 3-same encodings.
4
bus fabric can never report errors
5
4
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Message-id: 20180220180325.29818-18-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
include/hw/misc/iotkit-secctl.h | 4 ++++
9
target/arm/neon-dp.decode | 3 +--
10
hw/misc/iotkit-secctl.c | 32 ++++++++++++++++++++++++++------
10
target/arm/translate-neon.c.inc | 4 ++--
11
2 files changed, 30 insertions(+), 6 deletions(-)
11
2 files changed, 3 insertions(+), 4 deletions(-)
12
12
13
diff --git a/include/hw/misc/iotkit-secctl.h b/include/hw/misc/iotkit-secctl.h
13
diff --git a/target/arm/neon-dp.decode b/target/arm/neon-dp.decode
14
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
15
--- a/include/hw/misc/iotkit-secctl.h
15
--- a/target/arm/neon-dp.decode
16
+++ b/include/hw/misc/iotkit-secctl.h
16
+++ b/target/arm/neon-dp.decode
17
@@ -XXX,XX +XXX,XX @@
17
@@ -XXX,XX +XXX,XX @@ VMINNM_fp_3s 1111 001 1 0 . 1 . .... .... 1111 ... 1 .... @3same_fp
18
* + sysbus MMIO region 1 is the "non-secure privilege control block" registers
18
@2reg_shll_b .... ... . . . 001 shift:3 .... .... 0 . . . .... \
19
* + named GPIO output "sec_resp_cfg" indicating whether blocked accesses
19
&2reg_shift vm=%vm_dp vd=%vd_dp size=0 q=0
20
* should RAZ/WI or bus error
20
21
+ * + named GPIO output "nsc_cfg" whose value tracks the NSCCFG register value
21
-# We use size=0 for fp32 and size=1 for fp16 to match the 3-same encodings.
22
* Controlling the 2 APB PPCs in the IoTKit:
22
@2reg_vcvt .... ... . . . 1 ..... .... .... . q:1 . . .... \
23
* + named GPIO outputs apb_ppc0_nonsec[0..2] and apb_ppc1_nonsec
23
- &2reg_shift vm=%vm_dp vd=%vd_dp size=0 shift=%neon_rshift_i5
24
* + named GPIO outputs apb_ppc0_ap[0..2] and apb_ppc1_ap
24
+ &2reg_shift vm=%vm_dp vd=%vd_dp size=2 shift=%neon_rshift_i5
25
@@ -XXX,XX +XXX,XX @@ struct IoTKitSecCtl {
25
@2reg_vcvt_f16 .... ... . . . 11 .... .... .... . q:1 . . .... \
26
26
&2reg_shift vm=%vm_dp vd=%vd_dp size=1 shift=%neon_rshift_i4
27
/*< public >*/
27
28
qemu_irq sec_resp_cfg;
28
diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc
29
+ qemu_irq nsc_cfg_irq;
30
31
MemoryRegion s_regs;
32
MemoryRegion ns_regs;
33
@@ -XXX,XX +XXX,XX @@ struct IoTKitSecCtl {
34
uint32_t secppcintstat;
35
uint32_t secppcinten;
36
uint32_t secrespcfg;
37
+ uint32_t nsccfg;
38
+ uint32_t brginten;
39
40
IoTKitSecCtlPPC apb[IOTS_NUM_APB_PPC];
41
IoTKitSecCtlPPC apbexp[IOTS_NUM_APB_EXP_PPC];
42
diff --git a/hw/misc/iotkit-secctl.c b/hw/misc/iotkit-secctl.c
43
index XXXXXXX..XXXXXXX 100644
29
index XXXXXXX..XXXXXXX 100644
44
--- a/hw/misc/iotkit-secctl.c
30
--- a/target/arm/translate-neon.c.inc
45
+++ b/hw/misc/iotkit-secctl.c
31
+++ b/target/arm/translate-neon.c.inc
46
@@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_s_read(void *opaque, hwaddr addr,
32
@@ -XXX,XX +XXX,XX @@ static bool do_fp_2sh(DisasContext *s, arg_2reg_shift *a,
47
case A_SECRESPCFG:
33
return false;
48
r = s->secrespcfg;
49
break;
50
+ case A_NSCCFG:
51
+ r = s->nsccfg;
52
+ break;
53
case A_SECPPCINTSTAT:
54
r = s->secppcintstat;
55
break;
56
case A_SECPPCINTEN:
57
r = s->secppcinten;
58
break;
59
+ case A_BRGINTSTAT:
60
+ /* QEMU's bus fabric can never report errors as it doesn't buffer
61
+ * writes, so we never report bridge interrupts.
62
+ */
63
+ r = 0;
64
+ break;
65
+ case A_BRGINTEN:
66
+ r = s->brginten;
67
+ break;
68
case A_AHBNSPPCEXP0:
69
case A_AHBNSPPCEXP1:
70
case A_AHBNSPPCEXP2:
71
@@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_s_read(void *opaque, hwaddr addr,
72
case A_APBSPPPCEXP3:
73
r = s->apbexp[offset_to_ppc_idx(offset)].sp;
74
break;
75
- case A_NSCCFG:
76
case A_SECMPCINTSTATUS:
77
case A_SECMSCINTSTAT:
78
case A_SECMSCINTEN:
79
- case A_BRGINTSTAT:
80
- case A_BRGINTEN:
81
case A_NSMSCEXP:
82
qemu_log_mask(LOG_UNIMP,
83
"IoTKit SecCtl S block read: "
84
@@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr,
85
}
34
}
86
35
87
switch (offset) {
36
- if (a->size != 0) {
88
+ case A_NSCCFG:
37
+ if (a->size == MO_16) {
89
+ s->nsccfg = value & 3;
38
if (!dc_isar_feature(aa32_fp16_arith, s)) {
90
+ qemu_set_irq(s->nsc_cfg_irq, s->nsccfg);
39
return false;
91
+ break;
40
}
92
case A_SECRESPCFG:
41
@@ -XXX,XX +XXX,XX @@ static bool do_fp_2sh(DisasContext *s, arg_2reg_shift *a,
93
value &= 1;
42
return true;
94
s->secrespcfg = value;
95
@@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr,
96
s->secppcinten = value & 0x00f000f3;
97
foreach_ppc(s, iotkit_secctl_ppc_update_irq_enable);
98
break;
99
+ case A_BRGINTCLR:
100
+ break;
101
+ case A_BRGINTEN:
102
+ s->brginten = value & 0xffff0000;
103
+ break;
104
case A_AHBNSPPCEXP0:
105
case A_AHBNSPPCEXP1:
106
case A_AHBNSPPCEXP2:
107
@@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr,
108
ppc = &s->apbexp[offset_to_ppc_idx(offset)];
109
iotkit_secctl_ppc_sp_write(ppc, value);
110
break;
111
- case A_NSCCFG:
112
case A_SECMSCINTCLR:
113
case A_SECMSCINTEN:
114
- case A_BRGINTCLR:
115
- case A_BRGINTEN:
116
qemu_log_mask(LOG_UNIMP,
117
"IoTKit SecCtl S block write: "
118
"unimplemented offset 0x%x\n", offset);
119
@@ -XXX,XX +XXX,XX @@ static void iotkit_secctl_reset(DeviceState *dev)
120
s->secppcintstat = 0;
121
s->secppcinten = 0;
122
s->secrespcfg = 0;
123
+ s->nsccfg = 0;
124
+ s->brginten = 0;
125
126
foreach_ppc(s, iotkit_secctl_reset_ppc);
127
}
128
@@ -XXX,XX +XXX,XX @@ static void iotkit_secctl_init(Object *obj)
129
}
43
}
130
44
131
qdev_init_gpio_out_named(dev, &s->sec_resp_cfg, "sec_resp_cfg", 1);
45
- fpst = fpstatus_ptr(a->size ? FPST_STD_F16 : FPST_STD);
132
+ qdev_init_gpio_out_named(dev, &s->nsc_cfg_irq, "nsc_cfg", 1);
46
+ fpst = fpstatus_ptr(a->size == MO_16 ? FPST_STD_F16 : FPST_STD);
133
47
tcg_gen_gvec_2_ptr(rd_ofs, rm_ofs, fpst, vec_size, vec_size, a->shift, fn);
134
memory_region_init_io(&s->s_regs, obj, &iotkit_secctl_s_ops,
48
tcg_temp_free_ptr(fpst);
135
s, "iotkit-secctl-s-regs", 0x1000);
49
return true;
136
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription iotkit_secctl_vmstate = {
137
VMSTATE_UINT32(secppcintstat, IoTKitSecCtl),
138
VMSTATE_UINT32(secppcinten, IoTKitSecCtl),
139
VMSTATE_UINT32(secrespcfg, IoTKitSecCtl),
140
+ VMSTATE_UINT32(nsccfg, IoTKitSecCtl),
141
+ VMSTATE_UINT32(brginten, IoTKitSecCtl),
142
VMSTATE_STRUCT_ARRAY(apb, IoTKitSecCtl, IOTS_NUM_APB_PPC, 1,
143
iotkit_secctl_ppc_vmstate, IoTKitSecCtlPPC),
144
VMSTATE_STRUCT_ARRAY(apbexp, IoTKitSecCtl, IOTS_NUM_APB_EXP_PPC, 1,
145
--
50
--
146
2.16.2
51
2.20.1
147
52
148
53
diff view generated by jsdifflib
1
In v8M, the Implementation Defined Attribution Unit (IDAU) is
1
The VCMLA and VCADD insns have a size field which is 0 for fp16
2
a small piece of hardware typically implemented in the SoC
2
and 1 for fp32 (note that this is the reverse of the Neon 3-same
3
which provides board or SoC specific security attribution
3
encoding!). Convert it to MO_* values in decode for consistency.
4
information for each address that the CPU performs MPU/SAU
5
checks on. For QEMU, we model this with a QOM interface which
6
is implemented by the board or SoC object and connected to
7
the CPU using a link property.
8
9
This commit defines the new interface class, adds the link
10
property to the CPU object, and makes the SAU checking
11
code call the IDAU interface if one is present.
12
4
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
15
Message-id: 20180220180325.29818-5-peter.maydell@linaro.org
7
Message-id: 20200903133209.5141-4-peter.maydell@linaro.org
16
---
8
---
17
target/arm/cpu.h | 3 +++
9
target/arm/neon-shared.decode | 18 ++++++++++++------
18
target/arm/idau.h | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++
10
target/arm/translate-neon.c.inc | 22 ++++++++++++----------
19
target/arm/cpu.c | 15 +++++++++++++
11
2 files changed, 24 insertions(+), 16 deletions(-)
20
target/arm/helper.c | 28 +++++++++++++++++++++---
21
4 files changed, 104 insertions(+), 3 deletions(-)
22
create mode 100644 target/arm/idau.h
23
12
24
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
13
diff --git a/target/arm/neon-shared.decode b/target/arm/neon-shared.decode
25
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
26
--- a/target/arm/cpu.h
15
--- a/target/arm/neon-shared.decode
27
+++ b/target/arm/cpu.h
16
+++ b/target/arm/neon-shared.decode
28
@@ -XXX,XX +XXX,XX @@ struct ARMCPU {
17
@@ -XXX,XX +XXX,XX @@
29
/* MemoryRegion to use for secure physical accesses */
18
%vd_dp 22:1 12:4
30
MemoryRegion *secure_memory;
19
%vd_sp 12:4 22:1
31
20
32
+ /* For v8M, pointer to the IDAU interface provided by board/SoC */
21
-VCMLA 1111 110 rot:2 . 1 size:1 .... .... 1000 . q:1 . 0 .... \
33
+ Object *idau;
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
34
+
33
+
35
/* 'compatible' string for this CPU for Linux device trees */
34
+VCADD 1111 110 rot:1 1 . 0 . .... .... 1000 . q:1 . 0 .... \
36
const char *dtb_compatible;
35
+ vm=%vm_dp vn=%vn_dp vd=%vd_dp size=%vcadd_size
37
36
38
diff --git a/target/arm/idau.h b/target/arm/idau.h
37
# VUDOT and VSDOT
39
new file mode 100644
38
VDOT 1111 110 00 . 10 .... .... 1101 . q:1 . u:1 .... \
40
index XXXXXXX..XXXXXXX
39
@@ -XXX,XX +XXX,XX @@ VFML 1111 110 0 s:1 . 10 .... .... 1000 . 1 . 1 .... \
41
--- /dev/null
40
vm=%vm_dp vn=%vn_dp vd=%vd_dp q=1
42
+++ b/target/arm/idau.h
41
43
@@ -XXX,XX +XXX,XX @@
42
VCMLA_scalar 1111 1110 0 . rot:2 .... .... 1000 . q:1 index:1 0 vm:4 \
44
+/*
43
- vn=%vn_dp vd=%vd_dp size=0
45
+ * QEMU ARM CPU -- interface for the Arm v8M IDAU
44
+ vn=%vn_dp vd=%vd_dp size=1
46
+ *
45
VCMLA_scalar 1111 1110 1 . rot:2 .... .... 1000 . q:1 . 0 .... \
47
+ * Copyright (c) 2018 Linaro Ltd
46
- vm=%vm_dp vn=%vn_dp vd=%vd_dp size=1 index=0
48
+ *
47
+ vm=%vm_dp vn=%vn_dp vd=%vd_dp size=2 index=0
49
+ * This program is free software; you can redistribute it and/or
48
50
+ * modify it under the terms of the GNU General Public License
49
VDOT_scalar 1111 1110 0 . 10 .... .... 1101 . q:1 index:1 u:1 rm:4 \
51
+ * as published by the Free Software Foundation; either version 2
50
vm=%vm_dp vn=%vn_dp vd=%vd_dp
52
+ * of the License, or (at your option) any later version.
51
diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc
53
+ *
54
+ * This program is distributed in the hope that it will be useful,
55
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
56
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57
+ * GNU General Public License for more details.
58
+ *
59
+ * You should have received a copy of the GNU General Public License
60
+ * along with this program; if not, see
61
+ * <http://www.gnu.org/licenses/gpl-2.0.html>
62
+ *
63
+ * In the v8M architecture, the IDAU is a small piece of hardware
64
+ * typically implemented in the SoC which provides board or SoC
65
+ * specific security attribution information for each address that
66
+ * the CPU performs MPU/SAU checks on. For QEMU, we model this with a
67
+ * QOM interface which is implemented by the board or SoC object and
68
+ * connected to the CPU using a link property.
69
+ */
70
+
71
+#ifndef TARGET_ARM_IDAU_H
72
+#define TARGET_ARM_IDAU_H
73
+
74
+#include "qom/object.h"
75
+
76
+#define TYPE_IDAU_INTERFACE "idau-interface"
77
+#define IDAU_INTERFACE(obj) \
78
+ INTERFACE_CHECK(IDAUInterface, (obj), TYPE_IDAU_INTERFACE)
79
+#define IDAU_INTERFACE_CLASS(class) \
80
+ OBJECT_CLASS_CHECK(IDAUInterfaceClass, (class), TYPE_IDAU_INTERFACE)
81
+#define IDAU_INTERFACE_GET_CLASS(obj) \
82
+ OBJECT_GET_CLASS(IDAUInterfaceClass, (obj), TYPE_IDAU_INTERFACE)
83
+
84
+typedef struct IDAUInterface {
85
+ Object parent;
86
+} IDAUInterface;
87
+
88
+#define IREGION_NOTVALID -1
89
+
90
+typedef struct IDAUInterfaceClass {
91
+ InterfaceClass parent;
92
+
93
+ /* Check the specified address and return the IDAU security information
94
+ * for it by filling in iregion, exempt, ns and nsc:
95
+ * iregion: IDAU region number, or IREGION_NOTVALID if not valid
96
+ * exempt: true if address is exempt from security attribution
97
+ * ns: true if the address is NonSecure
98
+ * nsc: true if the address is NonSecure-callable
99
+ */
100
+ void (*check)(IDAUInterface *ii, uint32_t address, int *iregion,
101
+ bool *exempt, bool *ns, bool *nsc);
102
+} IDAUInterfaceClass;
103
+
104
+#endif
105
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
106
index XXXXXXX..XXXXXXX 100644
52
index XXXXXXX..XXXXXXX 100644
107
--- a/target/arm/cpu.c
53
--- a/target/arm/translate-neon.c.inc
108
+++ b/target/arm/cpu.c
54
+++ b/target/arm/translate-neon.c.inc
109
@@ -XXX,XX +XXX,XX @@
55
@@ -XXX,XX +XXX,XX @@ static bool trans_VCMLA(DisasContext *s, arg_VCMLA *a)
110
*/
56
gen_helper_gvec_3_ptr *fn_gvec_ptr;
111
57
112
#include "qemu/osdep.h"
58
if (!dc_isar_feature(aa32_vcma, s)
113
+#include "target/arm/idau.h"
59
- || (!a->size && !dc_isar_feature(aa32_fp16_arith, s))) {
114
#include "qemu/error-report.h"
60
+ || (a->size == MO_16 && !dc_isar_feature(aa32_fp16_arith, s))) {
115
#include "qapi/error.h"
61
return false;
116
#include "cpu.h"
117
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_post_init(Object *obj)
118
}
119
}
62
}
120
63
121
+ if (arm_feature(&cpu->env, ARM_FEATURE_M_SECURITY)) {
64
@@ -XXX,XX +XXX,XX @@ static bool trans_VCMLA(DisasContext *s, arg_VCMLA *a)
122
+ object_property_add_link(obj, "idau", TYPE_IDAU_INTERFACE, &cpu->idau,
123
+ qdev_prop_allow_set_link_before_realize,
124
+ OBJ_PROP_LINK_UNREF_ON_RELEASE,
125
+ &error_abort);
126
+ }
127
+
128
qdev_property_add_static(DEVICE(obj), &arm_cpu_cfgend_property,
129
&error_abort);
130
}
131
@@ -XXX,XX +XXX,XX @@ static const TypeInfo arm_cpu_type_info = {
132
.class_init = arm_cpu_class_init,
133
};
134
135
+static const TypeInfo idau_interface_type_info = {
136
+ .name = TYPE_IDAU_INTERFACE,
137
+ .parent = TYPE_INTERFACE,
138
+ .class_size = sizeof(IDAUInterfaceClass),
139
+};
140
+
141
static void arm_cpu_register_types(void)
142
{
143
const ARMCPUInfo *info = arm_cpus;
144
145
type_register_static(&arm_cpu_type_info);
146
+ type_register_static(&idau_interface_type_info);
147
148
while (info->name) {
149
cpu_register(info);
150
diff --git a/target/arm/helper.c b/target/arm/helper.c
151
index XXXXXXX..XXXXXXX 100644
152
--- a/target/arm/helper.c
153
+++ b/target/arm/helper.c
154
@@ -XXX,XX +XXX,XX @@
155
#include "qemu/osdep.h"
156
+#include "target/arm/idau.h"
157
#include "trace.h"
158
#include "cpu.h"
159
#include "internals.h"
160
@@ -XXX,XX +XXX,XX @@ static void v8m_security_lookup(CPUARMState *env, uint32_t address,
161
*/
162
ARMCPU *cpu = arm_env_get_cpu(env);
163
int r;
164
+ bool idau_exempt = false, idau_ns = true, idau_nsc = true;
165
+ int idau_region = IREGION_NOTVALID;
166
167
- /* TODO: implement IDAU */
168
+ if (cpu->idau) {
169
+ IDAUInterfaceClass *iic = IDAU_INTERFACE_GET_CLASS(cpu->idau);
170
+ IDAUInterface *ii = IDAU_INTERFACE(cpu->idau);
171
+
172
+ iic->check(ii, address, &idau_region, &idau_exempt, &idau_ns,
173
+ &idau_nsc);
174
+ }
175
176
if (access_type == MMU_INST_FETCH && extract32(address, 28, 4) == 0xf) {
177
/* 0xf0000000..0xffffffff is always S for insn fetches */
178
return;
179
}
65
}
180
66
181
- if (v8m_is_sau_exempt(env, address, access_type)) {
67
opr_sz = (1 + a->q) * 8;
182
+ if (idau_exempt || v8m_is_sau_exempt(env, address, access_type)) {
68
- fpst = fpstatus_ptr(a->size == 0 ? FPST_STD_F16 : FPST_STD);
183
sattrs->ns = !regime_is_secure(env, mmu_idx);
69
- fn_gvec_ptr = a->size ? gen_helper_gvec_fcmlas : gen_helper_gvec_fcmlah;
184
return;
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;
185
}
83
}
186
84
187
+ if (idau_region != IREGION_NOTVALID) {
85
@@ -XXX,XX +XXX,XX @@ static bool trans_VCADD(DisasContext *s, arg_VCADD *a)
188
+ sattrs->irvalid = true;
189
+ sattrs->iregion = idau_region;
190
+ }
191
+
192
switch (env->sau.ctrl & 3) {
193
case 0: /* SAU.ENABLE == 0, SAU.ALLNS == 0 */
194
break;
195
@@ -XXX,XX +XXX,XX @@ static void v8m_security_lookup(CPUARMState *env, uint32_t address,
196
}
197
}
198
199
- /* TODO when we support the IDAU then it may override the result here */
200
+ /* The IDAU will override the SAU lookup results if it specifies
201
+ * higher security than the SAU does.
202
+ */
203
+ if (!idau_ns) {
204
+ if (sattrs->ns || (!idau_nsc && sattrs->nsc)) {
205
+ sattrs->ns = false;
206
+ sattrs->nsc = idau_nsc;
207
+ }
208
+ }
209
break;
210
}
86
}
211
}
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),
212
--
120
--
213
2.16.2
121
2.20.1
214
122
215
123
diff view generated by jsdifflib
1
Move the definition of the struct for the unimplemented-device
1
We deprecated the support for KVM on 32-bit Arm hosts in time
2
from unimp.c to unimp.h, so that users can embed the struct
2
for release 5.0, which means that our deprecation policy allows
3
in their own device structs if they prefer.
3
us to drop it in release 5.2. Remove the code.
4
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.
4
9
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20180220180325.29818-10-peter.maydell@linaro.org
12
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
13
Message-id: 20200904154156.31943-2-peter.maydell@linaro.org
9
---
14
---
10
include/hw/misc/unimp.h | 10 ++++++++++
15
docs/system/deprecated.rst | 16 +-
11
hw/misc/unimp.c | 10 ----------
16
configure | 2 +-
12
2 files changed, 10 insertions(+), 10 deletions(-)
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
13
21
14
diff --git a/include/hw/misc/unimp.h b/include/hw/misc/unimp.h
22
diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
15
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
16
--- a/include/hw/misc/unimp.h
24
--- a/docs/system/deprecated.rst
17
+++ b/include/hw/misc/unimp.h
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
18
@@ -XXX,XX +XXX,XX @@
74
@@ -XXX,XX +XXX,XX @@
19
75
-/*
20
#define TYPE_UNIMPLEMENTED_DEVICE "unimplemented-device"
76
- * ARM implementation of KVM hooks, 32 bit specific code.
21
77
- *
22
+#define UNIMPLEMENTED_DEVICE(obj) \
78
- * Copyright Christoffer Dall 2009-2010
23
+ OBJECT_CHECK(UnimplementedDeviceState, (obj), TYPE_UNIMPLEMENTED_DEVICE)
79
- *
24
+
80
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
25
+typedef struct {
81
- * See the COPYING file in the top-level directory.
26
+ SysBusDevice parent_obj;
82
- *
27
+ MemoryRegion iomem;
83
- */
28
+ char *name;
84
-
29
+ uint64_t size;
85
-#include "qemu/osdep.h"
30
+} UnimplementedDeviceState;
86
-#include <sys/ioctl.h>
31
+
87
-
32
/**
88
-#include <linux/kvm.h>
33
* create_unimplemented_device: create and map a dummy device
89
-
34
* @name: name of the device for debug logging
90
-#include "qemu-common.h"
35
diff --git a/hw/misc/unimp.c b/hw/misc/unimp.c
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
36
index XXXXXXX..XXXXXXX 100644
671
index XXXXXXX..XXXXXXX 100644
37
--- a/hw/misc/unimp.c
672
--- a/target/arm/meson.build
38
+++ b/hw/misc/unimp.c
673
+++ b/target/arm/meson.build
39
@@ -XXX,XX +XXX,XX @@
674
@@ -XXX,XX +XXX,XX @@ arm_ss.add(zlib)
40
#include "qemu/log.h"
675
41
#include "qapi/error.h"
676
arm_ss.add(when: 'CONFIG_TCG', if_true: files('arm-semi.c'))
42
677
43
-#define UNIMPLEMENTED_DEVICE(obj) \
678
-kvm_ss = ss.source_set()
44
- OBJECT_CHECK(UnimplementedDeviceState, (obj), TYPE_UNIMPLEMENTED_DEVICE)
679
-kvm_ss.add(when: 'TARGET_AARCH64', if_true: files('kvm64.c'), if_false: files('kvm32.c'))
45
-
680
-arm_ss.add_all(when: 'CONFIG_KVM', if_true: kvm_ss)
46
-typedef struct {
681
-arm_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c'), if_false: files('kvm-stub.c'))
47
- SysBusDevice parent_obj;
682
+arm_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c', 'kvm64.c'), if_false: files('kvm-stub.c'))
48
- MemoryRegion iomem;
683
49
- char *name;
684
arm_ss.add(when: 'TARGET_AARCH64', if_true: files(
50
- uint64_t size;
685
'cpu64.c',
51
-} UnimplementedDeviceState;
52
-
53
static uint64_t unimp_read(void *opaque, hwaddr offset, unsigned size)
54
{
55
UnimplementedDeviceState *s = UNIMPLEMENTED_DEVICE(opaque);
56
--
686
--
57
2.16.2
687
2.20.1
58
688
59
689
diff view generated by jsdifflib
1
The Cortex-M33 allows the system to specify the reset value of the
1
Now that 32-bit KVM host support is gone, KVM can never
2
secure Vector Table Offset Register (VTOR) by asserting config
2
be enabled unless CONFIG_AARCH64 is true, and some code
3
signals. In particular, guest images for the MPS2 AN505 board rely
3
paths are no longer reachable and can be deleted.
4
on the MPS2's initial VTOR being correct for that board.
5
Implement a QEMU property so board and SoC code can set the reset
6
value to the correct value.
7
4
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
Message-id: 20180220180325.29818-7-peter.maydell@linaro.org
7
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
8
Message-id: 20200904154156.31943-3-peter.maydell@linaro.org
11
---
9
---
12
target/arm/cpu.h | 3 +++
10
target/arm/kvm-consts.h | 7 ---
13
target/arm/cpu.c | 18 ++++++++++++++----
11
target/arm/kvm_arm.h | 6 ---
14
2 files changed, 17 insertions(+), 4 deletions(-)
12
target/arm/cpu.c | 101 +++++++++++++++++++---------------------
15
13
target/arm/kvm.c | 7 ---
16
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
14
4 files changed, 47 insertions(+), 74 deletions(-)
17
index XXXXXXX..XXXXXXX 100644
15
18
--- a/target/arm/cpu.h
16
diff --git a/target/arm/kvm-consts.h b/target/arm/kvm-consts.h
19
+++ b/target/arm/cpu.h
17
index XXXXXXX..XXXXXXX 100644
20
@@ -XXX,XX +XXX,XX @@ struct ARMCPU {
18
--- a/target/arm/kvm-consts.h
21
*/
19
+++ b/target/arm/kvm-consts.h
22
uint32_t psci_conduit;
20
@@ -XXX,XX +XXX,XX @@ MISMATCH_CHECK(QEMU_PSCI_RET_DISABLED, PSCI_RET_DISABLED);
23
21
*/
24
+ /* For v8M, initial value of the Secure VTOR */
22
#define QEMU_KVM_ARM_TARGET_NONE UINT_MAX
25
+ uint32_t init_svtor;
23
26
+
24
-#ifdef TARGET_AARCH64
27
/* [QEMU_]KVM_ARM_TARGET_* constant for this CPU, or
25
MISMATCH_CHECK(QEMU_KVM_ARM_TARGET_AEM_V8, KVM_ARM_TARGET_AEM_V8);
28
* QEMU_KVM_ARM_TARGET_NONE if the kernel doesn't support this CPU type.
26
MISMATCH_CHECK(QEMU_KVM_ARM_TARGET_FOUNDATION_V8, KVM_ARM_TARGET_FOUNDATION_V8);
29
*/
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");
30
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
71
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
31
index XXXXXXX..XXXXXXX 100644
72
index XXXXXXX..XXXXXXX 100644
32
--- a/target/arm/cpu.c
73
--- a/target/arm/cpu.c
33
+++ b/target/arm/cpu.c
74
+++ b/target/arm/cpu.c
34
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(CPUState *s)
75
@@ -XXX,XX +XXX,XX @@ static void cortex_a15_initfn(Object *obj)
35
uint32_t initial_msp; /* Loaded from 0x0 */
76
}
36
uint32_t initial_pc; /* Loaded from 0x4 */
77
37
uint8_t *rom;
78
#ifndef TARGET_AARCH64
38
+ uint32_t vecbase;
79
-/* -cpu max: if KVM is enabled, like -cpu host (best possible with this host);
39
80
- * otherwise, a CPU with as many features enabled as our emulation supports.
40
if (arm_feature(env, ARM_FEATURE_M_SECURITY)) {
81
+/*
41
env->v7m.secure = true;
82
+ * -cpu max: a CPU with as many features enabled as our emulation supports.
42
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(CPUState *s)
83
* The version of '-cpu max' for qemu-system-aarch64 is defined in cpu64.c;
43
/* Unlike A/R profile, M profile defines the reset LR value */
84
- * this only needs to handle 32 bits.
44
env->regs[14] = 0xffffffff;
85
+ * this only needs to handle 32 bits, and need not care about KVM.
45
86
*/
46
- /* Load the initial SP and PC from the vector table at address 0 */
87
static void arm_max_initfn(Object *obj)
47
- rom = rom_ptr(0);
48
+ env->v7m.vecbase[M_REG_S] = cpu->init_svtor & 0xffffff80;
49
+
50
+ /* Load the initial SP and PC from offset 0 and 4 in the vector table */
51
+ vecbase = env->v7m.vecbase[env->v7m.secure];
52
+ rom = rom_ptr(vecbase);
53
if (rom) {
54
/* Address zero is covered by ROM which hasn't yet been
55
* copied into physical memory.
56
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(CPUState *s)
57
* it got copied into memory. In the latter case, rom_ptr
58
* will return a NULL pointer and we should use ldl_phys instead.
59
*/
60
- initial_msp = ldl_phys(s->as, 0);
61
- initial_pc = ldl_phys(s->as, 4);
62
+ initial_msp = ldl_phys(s->as, vecbase);
63
+ initial_pc = ldl_phys(s->as, vecbase + 4);
64
}
65
66
env->regs[13] = initial_msp & 0xFFFFFFFC;
67
@@ -XXX,XX +XXX,XX @@ static Property arm_cpu_pmsav7_dregion_property =
68
pmsav7_dregion,
69
qdev_prop_uint32, uint32_t);
70
71
+/* M profile: initial value of the Secure VTOR */
72
+static Property arm_cpu_initsvtor_property =
73
+ DEFINE_PROP_UINT32("init-svtor", ARMCPU, init_svtor, 0);
74
+
75
static void arm_cpu_post_init(Object *obj)
76
{
88
{
77
ARMCPU *cpu = ARM_CPU(obj);
89
ARMCPU *cpu = ARM_CPU(obj);
78
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_post_init(Object *obj)
90
79
qdev_prop_allow_set_link_before_realize,
91
- if (kvm_enabled()) {
80
OBJ_PROP_LINK_UNREF_ON_RELEASE,
92
- kvm_arm_set_cpu_features_from_host(cpu);
81
&error_abort);
93
- } else {
82
+ qdev_property_add_static(DEVICE(obj), &arm_cpu_initsvtor_property,
94
- cortex_a15_initfn(obj);
83
+ &error_abort);
95
+ cortex_a15_initfn(obj);
96
97
- /* old-style VFP short-vector support */
98
- cpu->isar.mvfr0 = FIELD_DP32(cpu->isar.mvfr0, MVFR0, FPSHVEC, 1);
99
+ /* old-style VFP short-vector support */
100
+ cpu->isar.mvfr0 = FIELD_DP32(cpu->isar.mvfr0, MVFR0, FPSHVEC, 1);
101
102
#ifdef CONFIG_USER_ONLY
103
- /* We don't set these in system emulation mode for the moment,
104
- * since we don't correctly set (all of) the ID registers to
105
- * advertise them.
106
- */
107
- set_feature(&cpu->env, ARM_FEATURE_V8);
108
- {
109
- uint32_t t;
110
+ /*
111
+ * We don't set these in system emulation mode for the moment,
112
+ * since we don't correctly set (all of) the ID registers to
113
+ * advertise them.
114
+ */
115
+ set_feature(&cpu->env, ARM_FEATURE_V8);
116
+ {
117
+ uint32_t t;
118
119
- t = cpu->isar.id_isar5;
120
- t = FIELD_DP32(t, ID_ISAR5, AES, 2);
121
- t = FIELD_DP32(t, ID_ISAR5, SHA1, 1);
122
- t = FIELD_DP32(t, ID_ISAR5, SHA2, 1);
123
- t = FIELD_DP32(t, ID_ISAR5, CRC32, 1);
124
- t = FIELD_DP32(t, ID_ISAR5, RDM, 1);
125
- t = FIELD_DP32(t, ID_ISAR5, VCMA, 1);
126
- cpu->isar.id_isar5 = t;
127
+ t = cpu->isar.id_isar5;
128
+ t = FIELD_DP32(t, ID_ISAR5, AES, 2);
129
+ t = FIELD_DP32(t, ID_ISAR5, SHA1, 1);
130
+ t = FIELD_DP32(t, ID_ISAR5, SHA2, 1);
131
+ t = FIELD_DP32(t, ID_ISAR5, CRC32, 1);
132
+ t = FIELD_DP32(t, ID_ISAR5, RDM, 1);
133
+ t = FIELD_DP32(t, ID_ISAR5, VCMA, 1);
134
+ cpu->isar.id_isar5 = t;
135
136
- t = cpu->isar.id_isar6;
137
- t = FIELD_DP32(t, ID_ISAR6, JSCVT, 1);
138
- t = FIELD_DP32(t, ID_ISAR6, DP, 1);
139
- t = FIELD_DP32(t, ID_ISAR6, FHM, 1);
140
- t = FIELD_DP32(t, ID_ISAR6, SB, 1);
141
- t = FIELD_DP32(t, ID_ISAR6, SPECRES, 1);
142
- cpu->isar.id_isar6 = t;
143
+ t = cpu->isar.id_isar6;
144
+ t = FIELD_DP32(t, ID_ISAR6, JSCVT, 1);
145
+ t = FIELD_DP32(t, ID_ISAR6, DP, 1);
146
+ t = FIELD_DP32(t, ID_ISAR6, FHM, 1);
147
+ t = FIELD_DP32(t, ID_ISAR6, SB, 1);
148
+ t = FIELD_DP32(t, ID_ISAR6, SPECRES, 1);
149
+ cpu->isar.id_isar6 = t;
150
151
- t = cpu->isar.mvfr1;
152
- t = FIELD_DP32(t, MVFR1, FPHP, 3); /* v8.2-FP16 */
153
- t = FIELD_DP32(t, MVFR1, SIMDHP, 2); /* v8.2-FP16 */
154
- cpu->isar.mvfr1 = t;
155
+ t = cpu->isar.mvfr1;
156
+ t = FIELD_DP32(t, MVFR1, FPHP, 3); /* v8.2-FP16 */
157
+ t = FIELD_DP32(t, MVFR1, SIMDHP, 2); /* v8.2-FP16 */
158
+ cpu->isar.mvfr1 = t;
159
160
- t = cpu->isar.mvfr2;
161
- t = FIELD_DP32(t, MVFR2, SIMDMISC, 3); /* SIMD MaxNum */
162
- t = FIELD_DP32(t, MVFR2, FPMISC, 4); /* FP MaxNum */
163
- cpu->isar.mvfr2 = t;
164
+ t = cpu->isar.mvfr2;
165
+ t = FIELD_DP32(t, MVFR2, SIMDMISC, 3); /* SIMD MaxNum */
166
+ t = FIELD_DP32(t, MVFR2, FPMISC, 4); /* FP MaxNum */
167
+ cpu->isar.mvfr2 = t;
168
169
- t = cpu->isar.id_mmfr3;
170
- t = FIELD_DP32(t, ID_MMFR3, PAN, 2); /* ATS1E1 */
171
- cpu->isar.id_mmfr3 = t;
172
+ t = cpu->isar.id_mmfr3;
173
+ t = FIELD_DP32(t, ID_MMFR3, PAN, 2); /* ATS1E1 */
174
+ cpu->isar.id_mmfr3 = t;
175
176
- t = cpu->isar.id_mmfr4;
177
- t = FIELD_DP32(t, ID_MMFR4, HPDS, 1); /* AA32HPD */
178
- t = FIELD_DP32(t, ID_MMFR4, AC2, 1); /* ACTLR2, HACTLR2 */
179
- t = FIELD_DP32(t, ID_MMFR4, CNP, 1); /* TTCNP */
180
- t = FIELD_DP32(t, ID_MMFR4, XNX, 1); /* TTS2UXN */
181
- cpu->isar.id_mmfr4 = t;
182
- }
183
-#endif
184
+ t = cpu->isar.id_mmfr4;
185
+ t = FIELD_DP32(t, ID_MMFR4, HPDS, 1); /* AA32HPD */
186
+ t = FIELD_DP32(t, ID_MMFR4, AC2, 1); /* ACTLR2, HACTLR2 */
187
+ t = FIELD_DP32(t, ID_MMFR4, CNP, 1); /* TTCNP */
188
+ t = FIELD_DP32(t, ID_MMFR4, XNX, 1); /* TTS2UXN */
189
+ cpu->isar.id_mmfr4 = t;
84
}
190
}
85
191
+#endif
86
qdev_property_add_static(DEVICE(obj), &arm_cpu_cfgend_property,
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)
87
--
234
--
88
2.16.2
235
2.20.1
89
236
90
237
diff view generated by jsdifflib
1
The IoTKit Security Controller includes various registers
1
Implement a model of the MPS2 with the AN386 firmware. This is
2
that expose to software the controls for the Peripheral
2
essentially identical to the AN385 firmware, but it has a
3
Protection Controllers in the system. Implement these.
3
Cortex-M4 rather than a Cortex-M3.
4
4
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20180220180325.29818-17-peter.maydell@linaro.org
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Message-id: 20200903202048.15370-2-peter.maydell@linaro.org
8
---
9
---
9
include/hw/misc/iotkit-secctl.h | 64 +++++++++-
10
docs/system/arm/mps2.rst | 8 +++++---
10
hw/misc/iotkit-secctl.c | 270 +++++++++++++++++++++++++++++++++++++---
11
hw/arm/mps2.c | 34 +++++++++++++++++++++++++++++-----
11
2 files changed, 315 insertions(+), 19 deletions(-)
12
2 files changed, 34 insertions(+), 8 deletions(-)
12
13
13
diff --git a/include/hw/misc/iotkit-secctl.h b/include/hw/misc/iotkit-secctl.h
14
diff --git a/docs/system/arm/mps2.rst b/docs/system/arm/mps2.rst
14
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
15
--- a/include/hw/misc/iotkit-secctl.h
16
--- a/docs/system/arm/mps2.rst
16
+++ b/include/hw/misc/iotkit-secctl.h
17
+++ b/docs/system/arm/mps2.rst
17
@@ -XXX,XX +XXX,XX @@
18
@@ -XXX,XX +XXX,XX @@
18
* QEMU interface:
19
-Arm MPS2 boards (``mps2-an385``, ``mps2-an505``, ``mps2-an511``, ``mps2-an521``)
19
* + sysbus MMIO region 0 is the "secure privilege control block" registers
20
-================================================================================
20
* + sysbus MMIO region 1 is the "non-secure privilege control block" registers
21
+Arm MPS2 boards (``mps2-an385``, ``mps2-an386``, ``mps2-an505``, ``mps2-an511``, ``mps2-an521``)
21
+ * + named GPIO output "sec_resp_cfg" indicating whether blocked accesses
22
+================================================================================================
22
+ * should RAZ/WI or bus error
23
23
+ * Controlling the 2 APB PPCs in the IoTKit:
24
These board models all use Arm M-profile CPUs.
24
+ * + named GPIO outputs apb_ppc0_nonsec[0..2] and apb_ppc1_nonsec
25
25
+ * + named GPIO outputs apb_ppc0_ap[0..2] and apb_ppc1_ap
26
@@ -XXX,XX +XXX,XX @@ QEMU models the following FPGA images:
26
+ * + named GPIO outputs apb_ppc{0,1}_irq_enable
27
27
+ * + named GPIO outputs apb_ppc{0,1}_irq_clear
28
``mps2-an385``
28
+ * + named GPIO inputs apb_ppc{0,1}_irq_status
29
Cortex-M3 as documented in ARM Application Note AN385
29
+ * Controlling each of the 4 expansion APB PPCs which a system using the IoTKit
30
+``mps2-an386``
30
+ * might provide:
31
+ Cortex-M4 as documented in ARM Application Note AN386
31
+ * + named GPIO outputs apb_ppcexp{0,1,2,3}_nonsec[0..15]
32
``mps2-an511``
32
+ * + named GPIO outputs apb_ppcexp{0,1,2,3}_ap[0..15]
33
Cortex-M3 'DesignStart' as documented in AN511
33
+ * + named GPIO outputs apb_ppcexp{0,1,2,3}_irq_enable
34
``mps2-an505``
34
+ * + named GPIO outputs apb_ppcexp{0,1,2,3}_irq_clear
35
@@ -XXX,XX +XXX,XX @@ QEMU models the following FPGA images:
35
+ * + named GPIO inputs apb_ppcexp{0,1,2,3}_irq_status
36
36
+ * Controlling each of the 4 expansion AHB PPCs which a system using the IoTKit
37
Differences between QEMU and real hardware:
37
+ * might provide:
38
38
+ * + named GPIO outputs ahb_ppcexp{0,1,2,3}_nonsec[0..15]
39
-- AN385 remapping of low 16K of memory to either ZBT SSRAM1 or to
39
+ * + named GPIO outputs ahb_ppcexp{0,1,2,3}_ap[0..15]
40
+- AN385/AN386 remapping of low 16K of memory to either ZBT SSRAM1 or to
40
+ * + named GPIO outputs ahb_ppcexp{0,1,2,3}_irq_enable
41
block RAM is unimplemented (QEMU always maps this to ZBT SSRAM1, as
41
+ * + named GPIO outputs ahb_ppcexp{0,1,2,3}_irq_clear
42
if zbt_boot_ctrl is always zero)
42
+ * + named GPIO inputs ahb_ppcexp{0,1,2,3}_irq_status
43
- QEMU provides a LAN9118 ethernet rather than LAN9220; the only guest
43
*/
44
diff --git a/hw/arm/mps2.c b/hw/arm/mps2.c
44
45
index XXXXXXX..XXXXXXX 100644
45
#ifndef IOTKIT_SECCTL_H
46
--- a/hw/arm/mps2.c
47
+++ b/hw/arm/mps2.c
46
@@ -XXX,XX +XXX,XX @@
48
@@ -XXX,XX +XXX,XX @@
47
#define TYPE_IOTKIT_SECCTL "iotkit-secctl"
49
* as seen by the guest depend significantly on the FPGA image.
48
#define IOTKIT_SECCTL(obj) OBJECT_CHECK(IoTKitSecCtl, (obj), TYPE_IOTKIT_SECCTL)
50
* We model the following FPGA images:
49
51
* "mps2-an385" -- Cortex-M3 as documented in ARM Application Note AN385
50
-typedef struct IoTKitSecCtl {
52
+ * "mps2-an386" -- Cortex-M4 as documented in ARM Application Note AN386
51
+#define IOTS_APB_PPC0_NUM_PORTS 3
53
* "mps2-an511" -- Cortex-M3 'DesignStart' as documented in AN511
52
+#define IOTS_APB_PPC1_NUM_PORTS 1
54
*
53
+#define IOTS_PPC_NUM_PORTS 16
55
* Links to the TRM for the board itself and to the various Application
54
+#define IOTS_NUM_APB_PPC 2
56
@@ -XXX,XX +XXX,XX @@
55
+#define IOTS_NUM_APB_EXP_PPC 4
57
56
+#define IOTS_NUM_AHB_EXP_PPC 4
58
typedef enum MPS2FPGAType {
59
FPGA_AN385,
60
+ FPGA_AN386,
61
FPGA_AN511,
62
} MPS2FPGAType;
63
64
@@ -XXX,XX +XXX,XX @@ typedef struct MPS2MachineState MPS2MachineState;
65
66
#define TYPE_MPS2_MACHINE "mps2"
67
#define TYPE_MPS2_AN385_MACHINE MACHINE_TYPE_NAME("mps2-an385")
68
+#define TYPE_MPS2_AN386_MACHINE MACHINE_TYPE_NAME("mps2-an386")
69
#define TYPE_MPS2_AN511_MACHINE MACHINE_TYPE_NAME("mps2-an511")
70
71
DECLARE_OBJ_CHECKERS(MPS2MachineState, MPS2MachineClass,
72
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
73
* tradeoffs. For QEMU they're all just RAM, though. We arbitrarily
74
* call the 16MB our "system memory", as it's the largest lump.
75
*
76
- * Common to both boards:
77
- * 0x21000000..0x21ffffff : PSRAM (16MB)
78
- * AN385 only:
79
+ * AN385/AN386/AN511:
80
+ * 0x21000000 .. 0x21ffffff : PSRAM (16MB)
81
+ * AN385/AN386 only:
82
* 0x00000000 .. 0x003fffff : ZBT SSRAM1
83
* 0x00400000 .. 0x007fffff : mirror of ZBT SSRAM1
84
* 0x20000000 .. 0x203fffff : ZBT SSRAM 2&3
85
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
86
* 0x20000000 .. 0x2001ffff : SRAM
87
* 0x20400000 .. 0x207fffff : ZBT SSRAM 2&3
88
*
89
- * The AN385 has a feature where the lowest 16K can be mapped
90
+ * The AN385/AN386 has a feature where the lowest 16K can be mapped
91
* either to the bottom of the ZBT SSRAM1 or to the block RAM.
92
* This is of no use for QEMU so we don't implement it (as if
93
* zbt_boot_ctrl is always zero).
94
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
95
96
switch (mmc->fpga_type) {
97
case FPGA_AN385:
98
+ case FPGA_AN386:
99
make_ram(&mms->ssram1, "mps.ssram1", 0x0, 0x400000);
100
make_ram_alias(&mms->ssram1_m, "mps.ssram1_m", &mms->ssram1, 0x400000);
101
make_ram(&mms->ssram23, "mps.ssram23", 0x20000000, 0x400000);
102
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
103
armv7m = DEVICE(&mms->armv7m);
104
switch (mmc->fpga_type) {
105
case FPGA_AN385:
106
+ case FPGA_AN386:
107
qdev_prop_set_uint32(armv7m, "num-irq", 32);
108
break;
109
case FPGA_AN511:
110
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
111
112
switch (mmc->fpga_type) {
113
case FPGA_AN385:
114
+ case FPGA_AN386:
115
{
116
/* The overflow IRQs for UARTs 0, 1 and 2 are ORed together.
117
* Overflow for UARTs 4 and 5 doesn't trigger any interrupt.
118
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
119
*/
120
lan9118_init(&nd_table[0], 0x40200000,
121
qdev_get_gpio_in(armv7m,
122
- mmc->fpga_type == FPGA_AN385 ? 13 : 47));
123
+ mmc->fpga_type == FPGA_AN511 ? 47 : 13));
124
125
system_clock_scale = NANOSECONDS_PER_SECOND / SYSCLK_FRQ;
126
127
@@ -XXX,XX +XXX,XX @@ static void mps2_an385_class_init(ObjectClass *oc, void *data)
128
mmc->scc_id = 0x41043850;
129
}
130
131
+static void mps2_an386_class_init(ObjectClass *oc, void *data)
132
+{
133
+ MachineClass *mc = MACHINE_CLASS(oc);
134
+ MPS2MachineClass *mmc = MPS2_MACHINE_CLASS(oc);
57
+
135
+
58
+typedef struct IoTKitSecCtl IoTKitSecCtl;
136
+ mc->desc = "ARM MPS2 with AN386 FPGA image for Cortex-M4";
59
+
137
+ mmc->fpga_type = FPGA_AN386;
60
+/* State and IRQ lines relating to a PPC. For the
138
+ mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m4");
61
+ * PPCs in the IoTKit not all the IRQ lines are used.
139
+ mmc->scc_id = 0x41043860;
62
+ */
63
+typedef struct IoTKitSecCtlPPC {
64
+ qemu_irq nonsec[IOTS_PPC_NUM_PORTS];
65
+ qemu_irq ap[IOTS_PPC_NUM_PORTS];
66
+ qemu_irq irq_enable;
67
+ qemu_irq irq_clear;
68
+
69
+ uint32_t ns;
70
+ uint32_t sp;
71
+ uint32_t nsp;
72
+
73
+ /* Number of ports actually present */
74
+ int numports;
75
+ /* Offset of this PPC's interrupt bits in SECPPCINTSTAT */
76
+ int irq_bit_offset;
77
+ IoTKitSecCtl *parent;
78
+} IoTKitSecCtlPPC;
79
+
80
+struct IoTKitSecCtl {
81
/*< private >*/
82
SysBusDevice parent_obj;
83
84
/*< public >*/
85
+ qemu_irq sec_resp_cfg;
86
87
MemoryRegion s_regs;
88
MemoryRegion ns_regs;
89
-} IoTKitSecCtl;
90
+
91
+ uint32_t secppcintstat;
92
+ uint32_t secppcinten;
93
+ uint32_t secrespcfg;
94
+
95
+ IoTKitSecCtlPPC apb[IOTS_NUM_APB_PPC];
96
+ IoTKitSecCtlPPC apbexp[IOTS_NUM_APB_EXP_PPC];
97
+ IoTKitSecCtlPPC ahbexp[IOTS_NUM_APB_EXP_PPC];
98
+};
99
100
#endif
101
diff --git a/hw/misc/iotkit-secctl.c b/hw/misc/iotkit-secctl.c
102
index XXXXXXX..XXXXXXX 100644
103
--- a/hw/misc/iotkit-secctl.c
104
+++ b/hw/misc/iotkit-secctl.c
105
@@ -XXX,XX +XXX,XX @@ static const uint8_t iotkit_secctl_ns_idregs[] = {
106
0x0d, 0xf0, 0x05, 0xb1,
107
};
108
109
+/* The register sets for the various PPCs (AHB internal, APB internal,
110
+ * AHB expansion, APB expansion) are all set up so that they are
111
+ * in 16-aligned blocks so offsets 0xN0, 0xN4, 0xN8, 0xNC are PPCs
112
+ * 0, 1, 2, 3 of that type, so we can convert a register address offset
113
+ * into an an index into a PPC array easily.
114
+ */
115
+static inline int offset_to_ppc_idx(uint32_t offset)
116
+{
117
+ return extract32(offset, 2, 2);
118
+}
140
+}
119
+
141
+
120
+typedef void PerPPCFunction(IoTKitSecCtlPPC *ppc);
142
static void mps2_an511_class_init(ObjectClass *oc, void *data)
121
+
122
+static void foreach_ppc(IoTKitSecCtl *s, PerPPCFunction *fn)
123
+{
124
+ int i;
125
+
126
+ for (i = 0; i < IOTS_NUM_APB_PPC; i++) {
127
+ fn(&s->apb[i]);
128
+ }
129
+ for (i = 0; i < IOTS_NUM_APB_EXP_PPC; i++) {
130
+ fn(&s->apbexp[i]);
131
+ }
132
+ for (i = 0; i < IOTS_NUM_AHB_EXP_PPC; i++) {
133
+ fn(&s->ahbexp[i]);
134
+ }
135
+}
136
+
137
static MemTxResult iotkit_secctl_s_read(void *opaque, hwaddr addr,
138
uint64_t *pdata,
139
unsigned size, MemTxAttrs attrs)
140
{
143
{
141
uint64_t r;
144
MachineClass *mc = MACHINE_CLASS(oc);
142
uint32_t offset = addr & ~0x3;
145
@@ -XXX,XX +XXX,XX @@ static const TypeInfo mps2_an385_info = {
143
+ IoTKitSecCtl *s = IOTKIT_SECCTL(opaque);
146
.class_init = mps2_an385_class_init,
144
145
switch (offset) {
146
case A_AHBNSPPC0:
147
@@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_s_read(void *opaque, hwaddr addr,
148
r = 0;
149
break;
150
case A_SECRESPCFG:
151
- case A_NSCCFG:
152
- case A_SECMPCINTSTATUS:
153
+ r = s->secrespcfg;
154
+ break;
155
case A_SECPPCINTSTAT:
156
+ r = s->secppcintstat;
157
+ break;
158
case A_SECPPCINTEN:
159
- case A_SECMSCINTSTAT:
160
- case A_SECMSCINTEN:
161
- case A_BRGINTSTAT:
162
- case A_BRGINTEN:
163
+ r = s->secppcinten;
164
+ break;
165
case A_AHBNSPPCEXP0:
166
case A_AHBNSPPCEXP1:
167
case A_AHBNSPPCEXP2:
168
case A_AHBNSPPCEXP3:
169
+ r = s->ahbexp[offset_to_ppc_idx(offset)].ns;
170
+ break;
171
case A_APBNSPPC0:
172
case A_APBNSPPC1:
173
+ r = s->apb[offset_to_ppc_idx(offset)].ns;
174
+ break;
175
case A_APBNSPPCEXP0:
176
case A_APBNSPPCEXP1:
177
case A_APBNSPPCEXP2:
178
case A_APBNSPPCEXP3:
179
+ r = s->apbexp[offset_to_ppc_idx(offset)].ns;
180
+ break;
181
case A_AHBSPPPCEXP0:
182
case A_AHBSPPPCEXP1:
183
case A_AHBSPPPCEXP2:
184
case A_AHBSPPPCEXP3:
185
+ r = s->apbexp[offset_to_ppc_idx(offset)].sp;
186
+ break;
187
case A_APBSPPPC0:
188
case A_APBSPPPC1:
189
+ r = s->apb[offset_to_ppc_idx(offset)].sp;
190
+ break;
191
case A_APBSPPPCEXP0:
192
case A_APBSPPPCEXP1:
193
case A_APBSPPPCEXP2:
194
case A_APBSPPPCEXP3:
195
+ r = s->apbexp[offset_to_ppc_idx(offset)].sp;
196
+ break;
197
+ case A_NSCCFG:
198
+ case A_SECMPCINTSTATUS:
199
+ case A_SECMSCINTSTAT:
200
+ case A_SECMSCINTEN:
201
+ case A_BRGINTSTAT:
202
+ case A_BRGINTEN:
203
case A_NSMSCEXP:
204
qemu_log_mask(LOG_UNIMP,
205
"IoTKit SecCtl S block read: "
206
@@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_s_read(void *opaque, hwaddr addr,
207
return MEMTX_OK;
208
}
209
210
+static void iotkit_secctl_update_ppc_ap(IoTKitSecCtlPPC *ppc)
211
+{
212
+ int i;
213
+
214
+ for (i = 0; i < ppc->numports; i++) {
215
+ bool v;
216
+
217
+ if (extract32(ppc->ns, i, 1)) {
218
+ v = extract32(ppc->nsp, i, 1);
219
+ } else {
220
+ v = extract32(ppc->sp, i, 1);
221
+ }
222
+ qemu_set_irq(ppc->ap[i], v);
223
+ }
224
+}
225
+
226
+static void iotkit_secctl_ppc_ns_write(IoTKitSecCtlPPC *ppc, uint32_t value)
227
+{
228
+ int i;
229
+
230
+ ppc->ns = value & MAKE_64BIT_MASK(0, ppc->numports);
231
+ for (i = 0; i < ppc->numports; i++) {
232
+ qemu_set_irq(ppc->nonsec[i], extract32(ppc->ns, i, 1));
233
+ }
234
+ iotkit_secctl_update_ppc_ap(ppc);
235
+}
236
+
237
+static void iotkit_secctl_ppc_sp_write(IoTKitSecCtlPPC *ppc, uint32_t value)
238
+{
239
+ ppc->sp = value & MAKE_64BIT_MASK(0, ppc->numports);
240
+ iotkit_secctl_update_ppc_ap(ppc);
241
+}
242
+
243
+static void iotkit_secctl_ppc_nsp_write(IoTKitSecCtlPPC *ppc, uint32_t value)
244
+{
245
+ ppc->nsp = value & MAKE_64BIT_MASK(0, ppc->numports);
246
+ iotkit_secctl_update_ppc_ap(ppc);
247
+}
248
+
249
+static void iotkit_secctl_ppc_update_irq_clear(IoTKitSecCtlPPC *ppc)
250
+{
251
+ uint32_t value = ppc->parent->secppcintstat;
252
+
253
+ qemu_set_irq(ppc->irq_clear, extract32(value, ppc->irq_bit_offset, 1));
254
+}
255
+
256
+static void iotkit_secctl_ppc_update_irq_enable(IoTKitSecCtlPPC *ppc)
257
+{
258
+ uint32_t value = ppc->parent->secppcinten;
259
+
260
+ qemu_set_irq(ppc->irq_enable, extract32(value, ppc->irq_bit_offset, 1));
261
+}
262
+
263
static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr,
264
uint64_t value,
265
unsigned size, MemTxAttrs attrs)
266
{
267
+ IoTKitSecCtl *s = IOTKIT_SECCTL(opaque);
268
uint32_t offset = addr;
269
+ IoTKitSecCtlPPC *ppc;
270
271
trace_iotkit_secctl_s_write(offset, value, size);
272
273
@@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr,
274
275
switch (offset) {
276
case A_SECRESPCFG:
277
- case A_NSCCFG:
278
+ value &= 1;
279
+ s->secrespcfg = value;
280
+ qemu_set_irq(s->sec_resp_cfg, s->secrespcfg);
281
+ break;
282
case A_SECPPCINTCLR:
283
+ value &= 0x00f000f3;
284
+ foreach_ppc(s, iotkit_secctl_ppc_update_irq_clear);
285
+ break;
286
case A_SECPPCINTEN:
287
- case A_SECMSCINTCLR:
288
- case A_SECMSCINTEN:
289
- case A_BRGINTCLR:
290
- case A_BRGINTEN:
291
+ s->secppcinten = value & 0x00f000f3;
292
+ foreach_ppc(s, iotkit_secctl_ppc_update_irq_enable);
293
+ break;
294
case A_AHBNSPPCEXP0:
295
case A_AHBNSPPCEXP1:
296
case A_AHBNSPPCEXP2:
297
case A_AHBNSPPCEXP3:
298
+ ppc = &s->ahbexp[offset_to_ppc_idx(offset)];
299
+ iotkit_secctl_ppc_ns_write(ppc, value);
300
+ break;
301
case A_APBNSPPC0:
302
case A_APBNSPPC1:
303
+ ppc = &s->apb[offset_to_ppc_idx(offset)];
304
+ iotkit_secctl_ppc_ns_write(ppc, value);
305
+ break;
306
case A_APBNSPPCEXP0:
307
case A_APBNSPPCEXP1:
308
case A_APBNSPPCEXP2:
309
case A_APBNSPPCEXP3:
310
+ ppc = &s->apbexp[offset_to_ppc_idx(offset)];
311
+ iotkit_secctl_ppc_ns_write(ppc, value);
312
+ break;
313
case A_AHBSPPPCEXP0:
314
case A_AHBSPPPCEXP1:
315
case A_AHBSPPPCEXP2:
316
case A_AHBSPPPCEXP3:
317
+ ppc = &s->ahbexp[offset_to_ppc_idx(offset)];
318
+ iotkit_secctl_ppc_sp_write(ppc, value);
319
+ break;
320
case A_APBSPPPC0:
321
case A_APBSPPPC1:
322
+ ppc = &s->apb[offset_to_ppc_idx(offset)];
323
+ iotkit_secctl_ppc_sp_write(ppc, value);
324
+ break;
325
case A_APBSPPPCEXP0:
326
case A_APBSPPPCEXP1:
327
case A_APBSPPPCEXP2:
328
case A_APBSPPPCEXP3:
329
+ ppc = &s->apbexp[offset_to_ppc_idx(offset)];
330
+ iotkit_secctl_ppc_sp_write(ppc, value);
331
+ break;
332
+ case A_NSCCFG:
333
+ case A_SECMSCINTCLR:
334
+ case A_SECMSCINTEN:
335
+ case A_BRGINTCLR:
336
+ case A_BRGINTEN:
337
qemu_log_mask(LOG_UNIMP,
338
"IoTKit SecCtl S block write: "
339
"unimplemented offset 0x%x\n", offset);
340
@@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_ns_read(void *opaque, hwaddr addr,
341
uint64_t *pdata,
342
unsigned size, MemTxAttrs attrs)
343
{
344
+ IoTKitSecCtl *s = IOTKIT_SECCTL(opaque);
345
uint64_t r;
346
uint32_t offset = addr & ~0x3;
347
348
@@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_ns_read(void *opaque, hwaddr addr,
349
case A_AHBNSPPPCEXP1:
350
case A_AHBNSPPPCEXP2:
351
case A_AHBNSPPPCEXP3:
352
+ r = s->ahbexp[offset_to_ppc_idx(offset)].nsp;
353
+ break;
354
case A_APBNSPPPC0:
355
case A_APBNSPPPC1:
356
+ r = s->apb[offset_to_ppc_idx(offset)].nsp;
357
+ break;
358
case A_APBNSPPPCEXP0:
359
case A_APBNSPPPCEXP1:
360
case A_APBNSPPPCEXP2:
361
case A_APBNSPPPCEXP3:
362
- qemu_log_mask(LOG_UNIMP,
363
- "IoTKit SecCtl NS block read: "
364
- "unimplemented offset 0x%x\n", offset);
365
+ r = s->apbexp[offset_to_ppc_idx(offset)].nsp;
366
break;
367
case A_PID4:
368
case A_PID5:
369
@@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_ns_write(void *opaque, hwaddr addr,
370
uint64_t value,
371
unsigned size, MemTxAttrs attrs)
372
{
373
+ IoTKitSecCtl *s = IOTKIT_SECCTL(opaque);
374
uint32_t offset = addr;
375
+ IoTKitSecCtlPPC *ppc;
376
377
trace_iotkit_secctl_ns_write(offset, value, size);
378
379
@@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_ns_write(void *opaque, hwaddr addr,
380
case A_AHBNSPPPCEXP1:
381
case A_AHBNSPPPCEXP2:
382
case A_AHBNSPPPCEXP3:
383
+ ppc = &s->ahbexp[offset_to_ppc_idx(offset)];
384
+ iotkit_secctl_ppc_nsp_write(ppc, value);
385
+ break;
386
case A_APBNSPPPC0:
387
case A_APBNSPPPC1:
388
+ ppc = &s->apb[offset_to_ppc_idx(offset)];
389
+ iotkit_secctl_ppc_nsp_write(ppc, value);
390
+ break;
391
case A_APBNSPPPCEXP0:
392
case A_APBNSPPPCEXP1:
393
case A_APBNSPPPCEXP2:
394
case A_APBNSPPPCEXP3:
395
- qemu_log_mask(LOG_UNIMP,
396
- "IoTKit SecCtl NS block write: "
397
- "unimplemented offset 0x%x\n", offset);
398
+ ppc = &s->apbexp[offset_to_ppc_idx(offset)];
399
+ iotkit_secctl_ppc_nsp_write(ppc, value);
400
break;
401
case A_AHBNSPPPC0:
402
case A_PID4:
403
@@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps iotkit_secctl_ns_ops = {
404
.impl.max_access_size = 4,
405
};
147
};
406
148
407
+static void iotkit_secctl_reset_ppc(IoTKitSecCtlPPC *ppc)
149
+static const TypeInfo mps2_an386_info = {
408
+{
150
+ .name = TYPE_MPS2_AN386_MACHINE,
409
+ ppc->ns = 0;
151
+ .parent = TYPE_MPS2_MACHINE,
410
+ ppc->sp = 0;
152
+ .class_init = mps2_an386_class_init,
411
+ ppc->nsp = 0;
412
+}
413
+
414
static void iotkit_secctl_reset(DeviceState *dev)
415
{
416
+ IoTKitSecCtl *s = IOTKIT_SECCTL(dev);
417
418
+ s->secppcintstat = 0;
419
+ s->secppcinten = 0;
420
+ s->secrespcfg = 0;
421
+
422
+ foreach_ppc(s, iotkit_secctl_reset_ppc);
423
+}
424
+
425
+static void iotkit_secctl_ppc_irqstatus(void *opaque, int n, int level)
426
+{
427
+ IoTKitSecCtlPPC *ppc = opaque;
428
+ IoTKitSecCtl *s = IOTKIT_SECCTL(ppc->parent);
429
+ int irqbit = ppc->irq_bit_offset + n;
430
+
431
+ s->secppcintstat = deposit32(s->secppcintstat, irqbit, 1, level);
432
+}
433
+
434
+static void iotkit_secctl_init_ppc(IoTKitSecCtl *s,
435
+ IoTKitSecCtlPPC *ppc,
436
+ const char *name,
437
+ int numports,
438
+ int irq_bit_offset)
439
+{
440
+ char *gpioname;
441
+ DeviceState *dev = DEVICE(s);
442
+
443
+ ppc->numports = numports;
444
+ ppc->irq_bit_offset = irq_bit_offset;
445
+ ppc->parent = s;
446
+
447
+ gpioname = g_strdup_printf("%s_nonsec", name);
448
+ qdev_init_gpio_out_named(dev, ppc->nonsec, gpioname, numports);
449
+ g_free(gpioname);
450
+ gpioname = g_strdup_printf("%s_ap", name);
451
+ qdev_init_gpio_out_named(dev, ppc->ap, gpioname, numports);
452
+ g_free(gpioname);
453
+ gpioname = g_strdup_printf("%s_irq_enable", name);
454
+ qdev_init_gpio_out_named(dev, &ppc->irq_enable, gpioname, 1);
455
+ g_free(gpioname);
456
+ gpioname = g_strdup_printf("%s_irq_clear", name);
457
+ qdev_init_gpio_out_named(dev, &ppc->irq_clear, gpioname, 1);
458
+ g_free(gpioname);
459
+ gpioname = g_strdup_printf("%s_irq_status", name);
460
+ qdev_init_gpio_in_named_with_opaque(dev, iotkit_secctl_ppc_irqstatus,
461
+ ppc, gpioname, 1);
462
+ g_free(gpioname);
463
}
464
465
static void iotkit_secctl_init(Object *obj)
466
{
467
IoTKitSecCtl *s = IOTKIT_SECCTL(obj);
468
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
469
+ DeviceState *dev = DEVICE(obj);
470
+ int i;
471
+
472
+ iotkit_secctl_init_ppc(s, &s->apb[0], "apb_ppc0",
473
+ IOTS_APB_PPC0_NUM_PORTS, 0);
474
+ iotkit_secctl_init_ppc(s, &s->apb[1], "apb_ppc1",
475
+ IOTS_APB_PPC1_NUM_PORTS, 1);
476
+
477
+ for (i = 0; i < IOTS_NUM_APB_EXP_PPC; i++) {
478
+ IoTKitSecCtlPPC *ppc = &s->apbexp[i];
479
+ char *ppcname = g_strdup_printf("apb_ppcexp%d", i);
480
+ iotkit_secctl_init_ppc(s, ppc, ppcname, IOTS_PPC_NUM_PORTS, 4 + i);
481
+ g_free(ppcname);
482
+ }
483
+ for (i = 0; i < IOTS_NUM_AHB_EXP_PPC; i++) {
484
+ IoTKitSecCtlPPC *ppc = &s->ahbexp[i];
485
+ char *ppcname = g_strdup_printf("ahb_ppcexp%d", i);
486
+ iotkit_secctl_init_ppc(s, ppc, ppcname, IOTS_PPC_NUM_PORTS, 20 + i);
487
+ g_free(ppcname);
488
+ }
489
+
490
+ qdev_init_gpio_out_named(dev, &s->sec_resp_cfg, "sec_resp_cfg", 1);
491
492
memory_region_init_io(&s->s_regs, obj, &iotkit_secctl_s_ops,
493
s, "iotkit-secctl-s-regs", 0x1000);
494
@@ -XXX,XX +XXX,XX @@ static void iotkit_secctl_init(Object *obj)
495
sysbus_init_mmio(sbd, &s->ns_regs);
496
}
497
498
+static const VMStateDescription iotkit_secctl_ppc_vmstate = {
499
+ .name = "iotkit-secctl-ppc",
500
+ .version_id = 1,
501
+ .minimum_version_id = 1,
502
+ .fields = (VMStateField[]) {
503
+ VMSTATE_UINT32(ns, IoTKitSecCtlPPC),
504
+ VMSTATE_UINT32(sp, IoTKitSecCtlPPC),
505
+ VMSTATE_UINT32(nsp, IoTKitSecCtlPPC),
506
+ VMSTATE_END_OF_LIST()
507
+ }
508
+};
153
+};
509
+
154
+
510
static const VMStateDescription iotkit_secctl_vmstate = {
155
static const TypeInfo mps2_an511_info = {
511
.name = "iotkit-secctl",
156
.name = TYPE_MPS2_AN511_MACHINE,
512
.version_id = 1,
157
.parent = TYPE_MPS2_MACHINE,
513
.minimum_version_id = 1,
158
@@ -XXX,XX +XXX,XX @@ static void mps2_machine_init(void)
514
.fields = (VMStateField[]) {
159
{
515
+ VMSTATE_UINT32(secppcintstat, IoTKitSecCtl),
160
type_register_static(&mps2_info);
516
+ VMSTATE_UINT32(secppcinten, IoTKitSecCtl),
161
type_register_static(&mps2_an385_info);
517
+ VMSTATE_UINT32(secrespcfg, IoTKitSecCtl),
162
+ type_register_static(&mps2_an386_info);
518
+ VMSTATE_STRUCT_ARRAY(apb, IoTKitSecCtl, IOTS_NUM_APB_PPC, 1,
163
type_register_static(&mps2_an511_info);
519
+ iotkit_secctl_ppc_vmstate, IoTKitSecCtlPPC),
164
}
520
+ VMSTATE_STRUCT_ARRAY(apbexp, IoTKitSecCtl, IOTS_NUM_APB_EXP_PPC, 1,
165
521
+ iotkit_secctl_ppc_vmstate, IoTKitSecCtlPPC),
522
+ VMSTATE_STRUCT_ARRAY(ahbexp, IoTKitSecCtl, IOTS_NUM_AHB_EXP_PPC, 1,
523
+ iotkit_secctl_ppc_vmstate, IoTKitSecCtlPPC),
524
VMSTATE_END_OF_LIST()
525
}
526
};
527
--
166
--
528
2.16.2
167
2.20.1
529
168
530
169
diff view generated by jsdifflib
1
Instead of loading kernels, device trees, and the like to
1
Implement a model of the MPS2 with the AN500 firmware. This is
2
the system address space, use the CPU's address space. This
2
similar to the AN385, with the following differences:
3
is important if we're trying to load the file to memory or
3
* Cortex-M7 CPU
4
via an alias memory region that is provided by an SoC
4
* PSRAM is at 0x6000_0000
5
object and thus not mapped into the system address space.
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
6
9
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
11
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Message-id: 20200903202048.15370-3-peter.maydell@linaro.org
10
Message-id: 20180220180325.29818-3-peter.maydell@linaro.org
11
---
13
---
12
hw/arm/boot.c | 119 +++++++++++++++++++++++++++++++++++++---------------------
14
docs/system/arm/mps2.rst | 6 ++--
13
1 file changed, 76 insertions(+), 43 deletions(-)
15
hw/arm/mps2.c | 67 +++++++++++++++++++++++++++++++++-------
14
16
2 files changed, 60 insertions(+), 13 deletions(-)
15
diff --git a/hw/arm/boot.c b/hw/arm/boot.c
17
18
diff --git a/docs/system/arm/mps2.rst b/docs/system/arm/mps2.rst
16
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
17
--- a/hw/arm/boot.c
20
--- a/docs/system/arm/mps2.rst
18
+++ b/hw/arm/boot.c
21
+++ b/docs/system/arm/mps2.rst
19
@@ -XXX,XX +XXX,XX @@
22
@@ -XXX,XX +XXX,XX @@
20
#define ARM64_TEXT_OFFSET_OFFSET 8
23
-Arm MPS2 boards (``mps2-an385``, ``mps2-an386``, ``mps2-an505``, ``mps2-an511``, ``mps2-an521``)
21
#define ARM64_MAGIC_OFFSET 56
24
-================================================================================================
22
25
+Arm MPS2 boards (``mps2-an385``, ``mps2-an386``, ``mps2-an500``, ``mps2-an505``, ``mps2-an511``, ``mps2-an521``)
23
+static AddressSpace *arm_boot_address_space(ARMCPU *cpu,
26
+================================================================================================================
24
+ const struct arm_boot_info *info)
27
28
These board models all use Arm M-profile CPUs.
29
30
@@ -XXX,XX +XXX,XX @@ QEMU models the following FPGA images:
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
41
--- a/hw/arm/mps2.c
42
+++ b/hw/arm/mps2.c
43
@@ -XXX,XX +XXX,XX @@
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
}
169
170
static void mps2_an386_class_init(ObjectClass *oc, void *data)
171
@@ -XXX,XX +XXX,XX @@ static void mps2_an386_class_init(ObjectClass *oc, void *data)
172
mmc->fpga_type = FPGA_AN386;
173
mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m4");
174
mmc->scc_id = 0x41043860;
175
+ mmc->psram_base = 0x21000000;
176
+ mmc->ethernet_base = 0x40200000;
177
+ mmc->has_block_ram = true;
178
+}
179
+
180
+static void mps2_an500_class_init(ObjectClass *oc, void *data)
25
+{
181
+{
26
+ /* Return the address space to use for bootloader reads and writes.
182
+ MachineClass *mc = MACHINE_CLASS(oc);
27
+ * We prefer the secure address space if the CPU has it and we're
183
+ MPS2MachineClass *mmc = MPS2_MACHINE_CLASS(oc);
28
+ * going to boot the guest into it.
184
+
29
+ */
185
+ mc->desc = "ARM MPS2 with AN500 FPGA image for Cortex-M7";
30
+ int asidx;
186
+ mmc->fpga_type = FPGA_AN500;
31
+ CPUState *cs = CPU(cpu);
187
+ mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m7");
32
+
188
+ mmc->scc_id = 0x41045000;
33
+ if (arm_feature(&cpu->env, ARM_FEATURE_EL3) && info->secure_boot) {
189
+ mmc->psram_base = 0x60000000;
34
+ asidx = ARMASIdx_S;
190
+ mmc->ethernet_base = 0xa0000000;
35
+ } else {
191
+ mmc->has_block_ram = false;
36
+ asidx = ARMASIdx_NS;
192
}
37
+ }
193
38
+
194
static void mps2_an511_class_init(ObjectClass *oc, void *data)
39
+ return cpu_get_address_space(cs, asidx);
195
@@ -XXX,XX +XXX,XX @@ static void mps2_an511_class_init(ObjectClass *oc, void *data)
40
+}
196
mmc->fpga_type = FPGA_AN511;
41
+
197
mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m3");
42
typedef enum {
198
mmc->scc_id = 0x41045110;
43
FIXUP_NONE = 0, /* do nothing */
199
+ mmc->psram_base = 0x21000000;
44
FIXUP_TERMINATOR, /* end of insns */
200
+ mmc->ethernet_base = 0x40200000;
45
@@ -XXX,XX +XXX,XX @@ static const ARMInsnFixup smpboot[] = {
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,
46
};
207
};
47
208
48
static void write_bootloader(const char *name, hwaddr addr,
209
+static const TypeInfo mps2_an500_info = {
49
- const ARMInsnFixup *insns, uint32_t *fixupcontext)
210
+ .name = TYPE_MPS2_AN500_MACHINE,
50
+ const ARMInsnFixup *insns, uint32_t *fixupcontext,
211
+ .parent = TYPE_MPS2_MACHINE,
51
+ AddressSpace *as)
212
+ .class_init = mps2_an500_class_init,
52
{
213
+};
53
/* Fix up the specified bootloader fragment and write it into
214
+
54
* guest memory using rom_add_blob_fixed(). fixupcontext is
215
static const TypeInfo mps2_an511_info = {
55
@@ -XXX,XX +XXX,XX @@ static void write_bootloader(const char *name, hwaddr addr,
216
.name = TYPE_MPS2_AN511_MACHINE,
56
code[i] = tswap32(insn);
217
.parent = TYPE_MPS2_MACHINE,
57
}
218
@@ -XXX,XX +XXX,XX @@ static void mps2_machine_init(void)
58
219
type_register_static(&mps2_info);
59
- rom_add_blob_fixed(name, code, len * sizeof(uint32_t), addr);
220
type_register_static(&mps2_an385_info);
60
+ rom_add_blob_fixed_as(name, code, len * sizeof(uint32_t), addr, as);
221
type_register_static(&mps2_an386_info);
61
222
+ type_register_static(&mps2_an500_info);
62
g_free(code);
223
type_register_static(&mps2_an511_info);
63
}
224
}
64
@@ -XXX,XX +XXX,XX @@ static void default_write_secondary(ARMCPU *cpu,
225
65
const struct arm_boot_info *info)
66
{
67
uint32_t fixupcontext[FIXUP_MAX];
68
+ AddressSpace *as = arm_boot_address_space(cpu, info);
69
70
fixupcontext[FIXUP_GIC_CPU_IF] = info->gic_cpu_if_addr;
71
fixupcontext[FIXUP_BOOTREG] = info->smp_bootreg_addr;
72
@@ -XXX,XX +XXX,XX @@ static void default_write_secondary(ARMCPU *cpu,
73
}
74
75
write_bootloader("smpboot", info->smp_loader_start,
76
- smpboot, fixupcontext);
77
+ smpboot, fixupcontext, as);
78
}
79
80
void arm_write_secure_board_setup_dummy_smc(ARMCPU *cpu,
81
const struct arm_boot_info *info,
82
hwaddr mvbar_addr)
83
{
84
+ AddressSpace *as = arm_boot_address_space(cpu, info);
85
int n;
86
uint32_t mvbar_blob[] = {
87
/* mvbar_addr: secure monitor vectors
88
@@ -XXX,XX +XXX,XX @@ void arm_write_secure_board_setup_dummy_smc(ARMCPU *cpu,
89
for (n = 0; n < ARRAY_SIZE(mvbar_blob); n++) {
90
mvbar_blob[n] = tswap32(mvbar_blob[n]);
91
}
92
- rom_add_blob_fixed("board-setup-mvbar", mvbar_blob, sizeof(mvbar_blob),
93
- mvbar_addr);
94
+ rom_add_blob_fixed_as("board-setup-mvbar", mvbar_blob, sizeof(mvbar_blob),
95
+ mvbar_addr, as);
96
97
for (n = 0; n < ARRAY_SIZE(board_setup_blob); n++) {
98
board_setup_blob[n] = tswap32(board_setup_blob[n]);
99
}
100
- rom_add_blob_fixed("board-setup", board_setup_blob,
101
- sizeof(board_setup_blob), info->board_setup_addr);
102
+ rom_add_blob_fixed_as("board-setup", board_setup_blob,
103
+ sizeof(board_setup_blob), info->board_setup_addr, as);
104
}
105
106
static void default_reset_secondary(ARMCPU *cpu,
107
const struct arm_boot_info *info)
108
{
109
+ AddressSpace *as = arm_boot_address_space(cpu, info);
110
CPUState *cs = CPU(cpu);
111
112
- address_space_stl_notdirty(&address_space_memory, info->smp_bootreg_addr,
113
+ address_space_stl_notdirty(as, info->smp_bootreg_addr,
114
0, MEMTXATTRS_UNSPECIFIED, NULL);
115
cpu_set_pc(cs, info->smp_loader_start);
116
}
117
@@ -XXX,XX +XXX,XX @@ static inline bool have_dtb(const struct arm_boot_info *info)
118
}
119
120
#define WRITE_WORD(p, value) do { \
121
- address_space_stl_notdirty(&address_space_memory, p, value, \
122
+ address_space_stl_notdirty(as, p, value, \
123
MEMTXATTRS_UNSPECIFIED, NULL); \
124
p += 4; \
125
} while (0)
126
127
-static void set_kernel_args(const struct arm_boot_info *info)
128
+static void set_kernel_args(const struct arm_boot_info *info, AddressSpace *as)
129
{
130
int initrd_size = info->initrd_size;
131
hwaddr base = info->loader_start;
132
@@ -XXX,XX +XXX,XX @@ static void set_kernel_args(const struct arm_boot_info *info)
133
int cmdline_size;
134
135
cmdline_size = strlen(info->kernel_cmdline);
136
- cpu_physical_memory_write(p + 8, info->kernel_cmdline,
137
- cmdline_size + 1);
138
+ address_space_write(as, p + 8, MEMTXATTRS_UNSPECIFIED,
139
+ (const uint8_t *)info->kernel_cmdline,
140
+ cmdline_size + 1);
141
cmdline_size = (cmdline_size >> 2) + 1;
142
WRITE_WORD(p, cmdline_size + 2);
143
WRITE_WORD(p, 0x54410009);
144
@@ -XXX,XX +XXX,XX @@ static void set_kernel_args(const struct arm_boot_info *info)
145
atag_board_len = (info->atag_board(info, atag_board_buf) + 3) & ~3;
146
WRITE_WORD(p, (atag_board_len + 8) >> 2);
147
WRITE_WORD(p, 0x414f4d50);
148
- cpu_physical_memory_write(p, atag_board_buf, atag_board_len);
149
+ address_space_write(as, p, MEMTXATTRS_UNSPECIFIED,
150
+ atag_board_buf, atag_board_len);
151
p += atag_board_len;
152
}
153
/* ATAG_END */
154
@@ -XXX,XX +XXX,XX @@ static void set_kernel_args(const struct arm_boot_info *info)
155
WRITE_WORD(p, 0);
156
}
157
158
-static void set_kernel_args_old(const struct arm_boot_info *info)
159
+static void set_kernel_args_old(const struct arm_boot_info *info,
160
+ AddressSpace *as)
161
{
162
hwaddr p;
163
const char *s;
164
@@ -XXX,XX +XXX,XX @@ static void set_kernel_args_old(const struct arm_boot_info *info)
165
}
166
s = info->kernel_cmdline;
167
if (s) {
168
- cpu_physical_memory_write(p, s, strlen(s) + 1);
169
+ address_space_write(as, p, MEMTXATTRS_UNSPECIFIED,
170
+ (const uint8_t *)s, strlen(s) + 1);
171
} else {
172
WRITE_WORD(p, 0);
173
}
174
@@ -XXX,XX +XXX,XX @@ static void fdt_add_psci_node(void *fdt)
175
* @addr: the address to load the image at
176
* @binfo: struct describing the boot environment
177
* @addr_limit: upper limit of the available memory area at @addr
178
+ * @as: address space to load image to
179
*
180
* Load a device tree supplied by the machine or by the user with the
181
* '-dtb' command line option, and put it at offset @addr in target
182
@@ -XXX,XX +XXX,XX @@ static void fdt_add_psci_node(void *fdt)
183
* Note: Must not be called unless have_dtb(binfo) is true.
184
*/
185
static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
186
- hwaddr addr_limit)
187
+ hwaddr addr_limit, AddressSpace *as)
188
{
189
void *fdt = NULL;
190
int size, rc;
191
@@ -XXX,XX +XXX,XX @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
192
/* Put the DTB into the memory map as a ROM image: this will ensure
193
* the DTB is copied again upon reset, even if addr points into RAM.
194
*/
195
- rom_add_blob_fixed("dtb", fdt, size, addr);
196
+ rom_add_blob_fixed_as("dtb", fdt, size, addr, as);
197
198
g_free(fdt);
199
200
@@ -XXX,XX +XXX,XX @@ static void do_cpu_reset(void *opaque)
201
}
202
203
if (cs == first_cpu) {
204
+ AddressSpace *as = arm_boot_address_space(cpu, info);
205
+
206
cpu_set_pc(cs, info->loader_start);
207
208
if (!have_dtb(info)) {
209
if (old_param) {
210
- set_kernel_args_old(info);
211
+ set_kernel_args_old(info, as);
212
} else {
213
- set_kernel_args(info);
214
+ set_kernel_args(info, as);
215
}
216
}
217
} else {
218
@@ -XXX,XX +XXX,XX @@ static int do_arm_linux_init(Object *obj, void *opaque)
219
220
static uint64_t arm_load_elf(struct arm_boot_info *info, uint64_t *pentry,
221
uint64_t *lowaddr, uint64_t *highaddr,
222
- int elf_machine)
223
+ int elf_machine, AddressSpace *as)
224
{
225
bool elf_is64;
226
union {
227
@@ -XXX,XX +XXX,XX @@ static uint64_t arm_load_elf(struct arm_boot_info *info, uint64_t *pentry,
228
}
229
}
230
231
- ret = load_elf(info->kernel_filename, NULL, NULL,
232
- pentry, lowaddr, highaddr, big_endian, elf_machine,
233
- 1, data_swab);
234
+ ret = load_elf_as(info->kernel_filename, NULL, NULL,
235
+ pentry, lowaddr, highaddr, big_endian, elf_machine,
236
+ 1, data_swab, as);
237
if (ret <= 0) {
238
/* The header loaded but the image didn't */
239
exit(1);
240
@@ -XXX,XX +XXX,XX @@ static uint64_t arm_load_elf(struct arm_boot_info *info, uint64_t *pentry,
241
}
242
243
static uint64_t load_aarch64_image(const char *filename, hwaddr mem_base,
244
- hwaddr *entry)
245
+ hwaddr *entry, AddressSpace *as)
246
{
247
hwaddr kernel_load_offset = KERNEL64_LOAD_ADDR;
248
uint8_t *buffer;
249
@@ -XXX,XX +XXX,XX @@ static uint64_t load_aarch64_image(const char *filename, hwaddr mem_base,
250
}
251
252
*entry = mem_base + kernel_load_offset;
253
- rom_add_blob_fixed(filename, buffer, size, *entry);
254
+ rom_add_blob_fixed_as(filename, buffer, size, *entry, as);
255
256
g_free(buffer);
257
258
@@ -XXX,XX +XXX,XX @@ static void arm_load_kernel_notify(Notifier *notifier, void *data)
259
ARMCPU *cpu = n->cpu;
260
struct arm_boot_info *info =
261
container_of(n, struct arm_boot_info, load_kernel_notifier);
262
+ AddressSpace *as = arm_boot_address_space(cpu, info);
263
264
/* The board code is not supposed to set secure_board_setup unless
265
* running its code in secure mode is actually possible, and KVM
266
@@ -XXX,XX +XXX,XX @@ static void arm_load_kernel_notify(Notifier *notifier, void *data)
267
* the kernel is supposed to be loaded by the bootloader), copy the
268
* DTB to the base of RAM for the bootloader to pick up.
269
*/
270
- if (load_dtb(info->loader_start, info, 0) < 0) {
271
+ if (load_dtb(info->loader_start, info, 0, as) < 0) {
272
exit(1);
273
}
274
}
275
@@ -XXX,XX +XXX,XX @@ static void arm_load_kernel_notify(Notifier *notifier, void *data)
276
277
/* Assume that raw images are linux kernels, and ELF images are not. */
278
kernel_size = arm_load_elf(info, &elf_entry, &elf_low_addr,
279
- &elf_high_addr, elf_machine);
280
+ &elf_high_addr, elf_machine, as);
281
if (kernel_size > 0 && have_dtb(info)) {
282
/* If there is still some room left at the base of RAM, try and put
283
* the DTB there like we do for images loaded with -bios or -pflash.
284
@@ -XXX,XX +XXX,XX @@ static void arm_load_kernel_notify(Notifier *notifier, void *data)
285
if (elf_low_addr < info->loader_start) {
286
elf_low_addr = 0;
287
}
288
- if (load_dtb(info->loader_start, info, elf_low_addr) < 0) {
289
+ if (load_dtb(info->loader_start, info, elf_low_addr, as) < 0) {
290
exit(1);
291
}
292
}
293
}
294
entry = elf_entry;
295
if (kernel_size < 0) {
296
- kernel_size = load_uimage(info->kernel_filename, &entry, NULL,
297
- &is_linux, NULL, NULL);
298
+ kernel_size = load_uimage_as(info->kernel_filename, &entry, NULL,
299
+ &is_linux, NULL, NULL, as);
300
}
301
if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64) && kernel_size < 0) {
302
kernel_size = load_aarch64_image(info->kernel_filename,
303
- info->loader_start, &entry);
304
+ info->loader_start, &entry, as);
305
is_linux = 1;
306
} else if (kernel_size < 0) {
307
/* 32-bit ARM */
308
entry = info->loader_start + KERNEL_LOAD_ADDR;
309
- kernel_size = load_image_targphys(info->kernel_filename, entry,
310
- info->ram_size - KERNEL_LOAD_ADDR);
311
+ kernel_size = load_image_targphys_as(info->kernel_filename, entry,
312
+ info->ram_size - KERNEL_LOAD_ADDR,
313
+ as);
314
is_linux = 1;
315
}
316
if (kernel_size < 0) {
317
@@ -XXX,XX +XXX,XX @@ static void arm_load_kernel_notify(Notifier *notifier, void *data)
318
uint32_t fixupcontext[FIXUP_MAX];
319
320
if (info->initrd_filename) {
321
- initrd_size = load_ramdisk(info->initrd_filename,
322
- info->initrd_start,
323
- info->ram_size -
324
- info->initrd_start);
325
+ initrd_size = load_ramdisk_as(info->initrd_filename,
326
+ info->initrd_start,
327
+ info->ram_size - info->initrd_start,
328
+ as);
329
if (initrd_size < 0) {
330
- initrd_size = load_image_targphys(info->initrd_filename,
331
- info->initrd_start,
332
- info->ram_size -
333
- info->initrd_start);
334
+ initrd_size = load_image_targphys_as(info->initrd_filename,
335
+ info->initrd_start,
336
+ info->ram_size -
337
+ info->initrd_start,
338
+ as);
339
}
340
if (initrd_size < 0) {
341
error_report("could not load initrd '%s'",
342
@@ -XXX,XX +XXX,XX @@ static void arm_load_kernel_notify(Notifier *notifier, void *data)
343
344
/* Place the DTB after the initrd in memory with alignment. */
345
dtb_start = QEMU_ALIGN_UP(info->initrd_start + initrd_size, align);
346
- if (load_dtb(dtb_start, info, 0) < 0) {
347
+ if (load_dtb(dtb_start, info, 0, as) < 0) {
348
exit(1);
349
}
350
fixupcontext[FIXUP_ARGPTR] = dtb_start;
351
@@ -XXX,XX +XXX,XX @@ static void arm_load_kernel_notify(Notifier *notifier, void *data)
352
fixupcontext[FIXUP_ENTRYPOINT] = entry;
353
354
write_bootloader("bootloader", info->loader_start,
355
- primary_loader, fixupcontext);
356
+ primary_loader, fixupcontext, as);
357
358
if (info->nb_cpus > 1) {
359
info->write_secondary_boot(cpu, info);
360
--
226
--
361
2.16.2
227
2.20.1
362
228
363
229
diff view generated by jsdifflib
1
The or-irq.h header file is missing the customary guard against
1
Make the list of MPS2 boards consistent in the phrasing of each
2
multiple inclusion, which means compilation fails if it gets
2
entry, use the correct casing of "Arm", and move the mps2-an511
3
included twice. Fix the omission.
3
entry so the list is in numeric order.
4
4
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20200903202048.15370-4-peter.maydell@linaro.org
8
Message-id: 20180220180325.29818-11-peter.maydell@linaro.org
9
---
8
---
10
include/hw/or-irq.h | 5 +++++
9
docs/system/arm/mps2.rst | 14 +++++++-------
11
1 file changed, 5 insertions(+)
10
1 file changed, 7 insertions(+), 7 deletions(-)
12
11
13
diff --git a/include/hw/or-irq.h b/include/hw/or-irq.h
12
diff --git a/docs/system/arm/mps2.rst b/docs/system/arm/mps2.rst
14
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
15
--- a/include/hw/or-irq.h
14
--- a/docs/system/arm/mps2.rst
16
+++ b/include/hw/or-irq.h
15
+++ b/docs/system/arm/mps2.rst
17
@@ -XXX,XX +XXX,XX @@
16
@@ -XXX,XX +XXX,XX @@ as seen by the guest depend significantly on the FPGA image.
18
* THE SOFTWARE.
17
QEMU models the following FPGA images:
19
*/
18
20
19
``mps2-an385``
21
+#ifndef HW_OR_IRQ_H
20
- Cortex-M3 as documented in ARM Application Note AN385
22
+#define HW_OR_IRQ_H
21
+ Cortex-M3 as documented in Arm Application Note AN385
23
+
22
``mps2-an386``
24
#include "hw/irq.h"
23
- Cortex-M4 as documented in ARM Application Note AN386
25
#include "hw/sysbus.h"
24
+ Cortex-M4 as documented in Arm Application Note AN386
26
#include "qom/object.h"
25
``mps2-an500``
27
@@ -XXX,XX +XXX,XX @@ struct OrIRQState {
26
- Cortex-M7 as documented in ARM Application Note AN500
28
bool levels[MAX_OR_LINES];
27
-``mps2-an511``
29
uint16_t num_lines;
28
- Cortex-M3 'DesignStart' as documented in AN511
30
};
29
+ Cortex-M7 as documented in Arm Application Note AN500
31
+
30
``mps2-an505``
32
+#endif
31
- Cortex-M33 as documented in ARM Application Note AN505
32
+ Cortex-M33 as documented in Arm Application Note AN505
33
+``mps2-an511``
34
+ Cortex-M3 'DesignStart' as documented in Arm Application Note AN511
35
``mps2-an521``
36
- Dual Cortex-M33 as documented in Application Note AN521
37
+ Dual Cortex-M33 as documented in Arm Application Note AN521
38
39
Differences between QEMU and real hardware:
40
33
--
41
--
34
2.16.2
42
2.20.1
35
43
36
44
diff view generated by jsdifflib
1
Create an "init-svtor" property on the armv7m container
1
Deprecate our Unicore32 target support:
2
object which we can forward to the CPU object.
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
3
11
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
13
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6
Message-id: 20180220180325.29818-8-peter.maydell@linaro.org
14
Message-id: 20200825172719.19422-1-peter.maydell@linaro.org
7
---
15
---
8
include/hw/arm/armv7m.h | 2 ++
16
docs/system/deprecated.rst | 8 ++++++++
9
hw/arm/armv7m.c | 9 +++++++++
17
1 file changed, 8 insertions(+)
10
2 files changed, 11 insertions(+)
11
18
12
diff --git a/include/hw/arm/armv7m.h b/include/hw/arm/armv7m.h
19
diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
13
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
14
--- a/include/hw/arm/armv7m.h
21
--- a/docs/system/deprecated.rst
15
+++ b/include/hw/arm/armv7m.h
22
+++ b/docs/system/deprecated.rst
16
@@ -XXX,XX +XXX,XX @@ typedef struct {
23
@@ -XXX,XX +XXX,XX @@ The above, converted to the current supported format::
17
* that CPU accesses see. (The NVIC, bitbanding and other CPU-internal
24
linux-user mode CPUs
18
* devices will be automatically layered on top of this view.)
25
--------------------
19
* + Property "idau": IDAU interface (forwarded to CPU object)
26
20
+ * + Property "init-svtor": secure VTOR reset value (forwarded to CPU object)
27
+``unicore32`` CPUs (since 5.2.0)
21
*/
28
+''''''''''''''''''''''''''''''''
22
typedef struct ARMv7MState {
29
+
23
/*< private >*/
30
+The ``unicore32`` guest CPU support is deprecated and will be removed in
24
@@ -XXX,XX +XXX,XX @@ typedef struct ARMv7MState {
31
+a future version of QEMU. Support for this CPU was removed from the
25
/* MemoryRegion the board provides to us (with its devices, RAM, etc) */
32
+upstream Linux kernel, and there is no available upstream toolchain
26
MemoryRegion *board_memory;
33
+to build binaries for it.
27
Object *idau;
34
+
28
+ uint32_t init_svtor;
35
``tilegx`` CPUs (since 5.1.0)
29
} ARMv7MState;
36
'''''''''''''''''''''''''''''
30
31
#endif
32
diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c
33
index XXXXXXX..XXXXXXX 100644
34
--- a/hw/arm/armv7m.c
35
+++ b/hw/arm/armv7m.c
36
@@ -XXX,XX +XXX,XX @@ static void armv7m_realize(DeviceState *dev, Error **errp)
37
return;
38
}
39
}
40
+ if (object_property_find(OBJECT(s->cpu), "init-svtor", NULL)) {
41
+ object_property_set_uint(OBJECT(s->cpu), s->init_svtor,
42
+ "init-svtor", &err);
43
+ if (err != NULL) {
44
+ error_propagate(errp, err);
45
+ return;
46
+ }
47
+ }
48
object_property_set_bool(OBJECT(s->cpu), true, "realized", &err);
49
if (err != NULL) {
50
error_propagate(errp, err);
51
@@ -XXX,XX +XXX,XX @@ static Property armv7m_properties[] = {
52
DEFINE_PROP_LINK("memory", ARMv7MState, board_memory, TYPE_MEMORY_REGION,
53
MemoryRegion *),
54
DEFINE_PROP_LINK("idau", ARMv7MState, idau, TYPE_IDAU_INTERFACE, Object *),
55
+ DEFINE_PROP_UINT32("init-svtor", ARMv7MState, init_svtor, 0),
56
DEFINE_PROP_END_OF_LIST(),
57
};
58
37
59
--
38
--
60
2.16.2
39
2.20.1
61
40
62
41
diff view generated by jsdifflib
1
Create an "idau" property on the armv7m container object which
1
Deprecate our lm32 target support. Michael Walle (former lm32 maintainer)
2
we can forward to the CPU object. Annoyingly, we can't use
2
suggested that we do this in 2019:
3
object_property_add_alias() because the CPU object we want to
3
https://www.mail-archive.com/qemu-devel@nongnu.org/msg605024.html
4
forward to doesn't exist until the armv7m container is realized.
4
because the only public user of the architecture is the many-years-dead
5
milkymist project. (The Linux port to lm32 was never merged upstream.)
6
7
In commit 4b4d96c776f552e (March 2020) we marked it as 'orphan' in
8
the MAINTAINERS file, but didn't officially deprecate it. Mark it
9
deprecated now, with the intention of removing it from QEMU in
10
mid-2021 before the 6.1 release.
5
11
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
13
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
8
Message-id: 20180220180325.29818-6-peter.maydell@linaro.org
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
9
---
18
---
10
include/hw/arm/armv7m.h | 3 +++
19
docs/system/deprecated.rst | 8 ++++++++
11
hw/arm/armv7m.c | 9 +++++++++
20
1 file changed, 8 insertions(+)
12
2 files changed, 12 insertions(+)
13
21
14
diff --git a/include/hw/arm/armv7m.h b/include/hw/arm/armv7m.h
22
diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
15
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
16
--- a/include/hw/arm/armv7m.h
24
--- a/docs/system/deprecated.rst
17
+++ b/include/hw/arm/armv7m.h
25
+++ b/docs/system/deprecated.rst
18
@@ -XXX,XX +XXX,XX @@
26
@@ -XXX,XX +XXX,XX @@ The above, converted to the current supported format::
19
27
linux-user mode CPUs
20
#include "hw/sysbus.h"
28
--------------------
21
#include "hw/intc/armv7m_nvic.h"
29
22
+#include "target/arm/idau.h"
30
+``lm32`` CPUs (since 5.2.0)
23
31
+'''''''''''''''''''''''''''
24
#define TYPE_BITBAND "ARM,bitband-memory"
32
+
25
#define BITBAND(obj) OBJECT_CHECK(BitBandState, (obj), TYPE_BITBAND)
33
+The ``lm32`` guest CPU support is deprecated and will be removed in
26
@@ -XXX,XX +XXX,XX @@ typedef struct {
34
+a future version of QEMU. The only public user of this architecture
27
* + Property "memory": MemoryRegion defining the physical address space
35
+was the milkymist project, which has been dead for years; there was
28
* that CPU accesses see. (The NVIC, bitbanding and other CPU-internal
36
+never an upstream Linux port.
29
* devices will be automatically layered on top of this view.)
37
+
30
+ * + Property "idau": IDAU interface (forwarded to CPU object)
38
``unicore32`` CPUs (since 5.2.0)
31
*/
39
''''''''''''''''''''''''''''''''
32
typedef struct ARMv7MState {
33
/*< private >*/
34
@@ -XXX,XX +XXX,XX @@ typedef struct ARMv7MState {
35
char *cpu_type;
36
/* MemoryRegion the board provides to us (with its devices, RAM, etc) */
37
MemoryRegion *board_memory;
38
+ Object *idau;
39
} ARMv7MState;
40
41
#endif
42
diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c
43
index XXXXXXX..XXXXXXX 100644
44
--- a/hw/arm/armv7m.c
45
+++ b/hw/arm/armv7m.c
46
@@ -XXX,XX +XXX,XX @@
47
#include "sysemu/qtest.h"
48
#include "qemu/error-report.h"
49
#include "exec/address-spaces.h"
50
+#include "target/arm/idau.h"
51
52
/* Bitbanded IO. Each word corresponds to a single bit. */
53
54
@@ -XXX,XX +XXX,XX @@ static void armv7m_realize(DeviceState *dev, Error **errp)
55
56
object_property_set_link(OBJECT(s->cpu), OBJECT(&s->container), "memory",
57
&error_abort);
58
+ if (object_property_find(OBJECT(s->cpu), "idau", NULL)) {
59
+ object_property_set_link(OBJECT(s->cpu), s->idau, "idau", &err);
60
+ if (err != NULL) {
61
+ error_propagate(errp, err);
62
+ return;
63
+ }
64
+ }
65
object_property_set_bool(OBJECT(s->cpu), true, "realized", &err);
66
if (err != NULL) {
67
error_propagate(errp, err);
68
@@ -XXX,XX +XXX,XX @@ static Property armv7m_properties[] = {
69
DEFINE_PROP_STRING("cpu-type", ARMv7MState, cpu_type),
70
DEFINE_PROP_LINK("memory", ARMv7MState, board_memory, TYPE_MEMORY_REGION,
71
MemoryRegion *),
72
+ DEFINE_PROP_LINK("idau", ARMv7MState, idau, TYPE_IDAU_INTERFACE, Object *),
73
DEFINE_PROP_END_OF_LIST(),
74
};
75
40
76
--
41
--
77
2.16.2
42
2.20.1
78
43
79
44
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Aaron Lindsay <aaron@os.amperecomputing.com>
2
2
3
The integer size check was already outside of the opcode switch;
3
This check was backwards when introduced in commit
4
move the floating-point size check outside as well. Unify the
4
033614c47de78409ad3fb39bb7bd1483b71c6789:
5
size vs index adjustment between fp and integer paths.
6
5
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
6
target/arm: Filter cycle counter based on PMCCFILTR_EL0
7
8
Cc: qemu-stable@nongnu.org
9
Signed-off-by: Aaron Lindsay <aaron@os.amperecomputing.com>
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
10
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
Message-id: 20180228193125.20577-4-richard.henderson@linaro.org
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
12
---
12
target/arm/translate-a64.c | 65 +++++++++++++++++++++++-----------------------
13
target/arm/helper.c | 2 +-
13
1 file changed, 32 insertions(+), 33 deletions(-)
14
1 file changed, 1 insertion(+), 1 deletion(-)
14
15
15
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
16
diff --git a/target/arm/helper.c b/target/arm/helper.c
16
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
17
--- a/target/arm/translate-a64.c
18
--- a/target/arm/helper.c
18
+++ b/target/arm/translate-a64.c
19
+++ b/target/arm/helper.c
19
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
20
@@ -XXX,XX +XXX,XX @@ static bool pmu_counter_enabled(CPUARMState *env, uint8_t counter)
20
case 0x05: /* FMLS */
21
case 0x09: /* FMUL */
22
case 0x19: /* FMULX */
23
- if (size == 1) {
24
- unallocated_encoding(s);
25
- return;
26
- }
27
is_fp = true;
28
break;
29
default:
30
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
31
if (is_fp) {
32
/* convert insn encoded size to TCGMemOp size */
33
switch (size) {
34
- case 2: /* single precision */
35
- size = MO_32;
36
- index = h << 1 | l;
37
- rm |= (m << 4);
38
- break;
39
- case 3: /* double precision */
40
- size = MO_64;
41
- if (l || !is_q) {
42
+ case 0: /* half-precision */
43
+ if (!arm_dc_feature(s, ARM_FEATURE_V8_FP16)) {
44
unallocated_encoding(s);
45
return;
46
}
47
- index = h;
48
- rm |= (m << 4);
49
- break;
50
- case 0: /* half precision */
51
size = MO_16;
52
- index = h << 2 | l << 1 | m;
53
- is_fp16 = true;
54
- if (arm_dc_feature(s, ARM_FEATURE_V8_FP16)) {
55
- break;
56
- }
57
- /* fallthru */
58
- default: /* unallocated */
59
- unallocated_encoding(s);
60
- return;
61
- }
62
- } else {
63
- switch (size) {
64
- case 1:
65
- index = h << 2 | l << 1 | m;
66
break;
67
- case 2:
68
- index = h << 1 | l;
69
- rm |= (m << 4);
70
+ case MO_32: /* single precision */
71
+ case MO_64: /* double precision */
72
break;
73
default:
74
unallocated_encoding(s);
75
return;
76
}
21
}
77
+ } else {
22
} else {
78
+ switch (size) {
23
prohibited = arm_feature(env, ARM_FEATURE_EL3) &&
79
+ case MO_8:
24
- (env->cp15.mdcr_el3 & MDCR_SPME);
80
+ case MO_64:
25
+ !(env->cp15.mdcr_el3 & MDCR_SPME);
81
+ unallocated_encoding(s);
82
+ return;
83
+ }
84
+ }
85
+
86
+ /* Given TCGMemOp size, adjust register and indexing. */
87
+ switch (size) {
88
+ case MO_16:
89
+ index = h << 2 | l << 1 | m;
90
+ break;
91
+ case MO_32:
92
+ index = h << 1 | l;
93
+ rm |= m << 4;
94
+ break;
95
+ case MO_64:
96
+ if (l || !is_q) {
97
+ unallocated_encoding(s);
98
+ return;
99
+ }
100
+ index = h;
101
+ rm |= m << 4;
102
+ break;
103
+ default:
104
+ g_assert_not_reached();
105
}
26
}
106
27
107
if (!fp_access_check(s)) {
28
if (prohibited && counter == 31) {
108
--
29
--
109
2.16.2
30
2.20.1
110
31
111
32
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com>
2
2
3
Enable it for the "any" CPU used by *-linux-user.
3
Correct the GEMs tx/rx clocks to use the 125Mhz fixed-clock.
4
This matches the setup with the fixed-link 100Mbit PHY.
5
It also avoids the following warnings from the Linux kernel
6
driver:
4
7
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
eth0: unable to generate target frequency: 125000000 Hz
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
7
Message-id: 20180228193125.20577-10-richard.henderson@linaro.org
10
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
11
Reviewed-by: Luc Michel <luc.michel@greensocs.com>
12
Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
13
Message-id: 20200909174647.662864-2-edgar.iglesias@gmail.com
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
15
---
10
target/arm/cpu.c | 1 +
16
hw/arm/xlnx-versal-virt.c | 2 +-
11
target/arm/cpu64.c | 1 +
17
1 file changed, 1 insertion(+), 1 deletion(-)
12
2 files changed, 2 insertions(+)
13
18
14
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
19
diff --git a/hw/arm/xlnx-versal-virt.c b/hw/arm/xlnx-versal-virt.c
15
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
16
--- a/target/arm/cpu.c
21
--- a/hw/arm/xlnx-versal-virt.c
17
+++ b/target/arm/cpu.c
22
+++ b/hw/arm/xlnx-versal-virt.c
18
@@ -XXX,XX +XXX,XX @@ static void arm_any_initfn(Object *obj)
23
@@ -XXX,XX +XXX,XX @@ static void fdt_add_gem_nodes(VersalVirt *s)
19
set_feature(&cpu->env, ARM_FEATURE_V8_SHA256);
24
s->phandle.ethernet_phy[i]);
20
set_feature(&cpu->env, ARM_FEATURE_V8_PMULL);
25
qemu_fdt_setprop_cells(s->fdt, name, "clocks",
21
set_feature(&cpu->env, ARM_FEATURE_CRC);
26
s->phandle.clk_25Mhz, s->phandle.clk_25Mhz,
22
+ set_feature(&cpu->env, ARM_FEATURE_V8_RDM);
27
- s->phandle.clk_25Mhz, s->phandle.clk_25Mhz);
23
cpu->midr = 0xffffffff;
28
+ s->phandle.clk_125Mhz, s->phandle.clk_125Mhz);
24
}
29
qemu_fdt_setprop(s->fdt, name, "clock-names",
25
#endif
30
clocknames, sizeof(clocknames));
26
diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
31
qemu_fdt_setprop_cells(s->fdt, name, "interrupts",
27
index XXXXXXX..XXXXXXX 100644
28
--- a/target/arm/cpu64.c
29
+++ b/target/arm/cpu64.c
30
@@ -XXX,XX +XXX,XX @@ static void aarch64_any_initfn(Object *obj)
31
set_feature(&cpu->env, ARM_FEATURE_V8_SM4);
32
set_feature(&cpu->env, ARM_FEATURE_V8_PMULL);
33
set_feature(&cpu->env, ARM_FEATURE_CRC);
34
+ set_feature(&cpu->env, ARM_FEATURE_V8_RDM);
35
set_feature(&cpu->env, ARM_FEATURE_V8_FP16);
36
cpu->ctr = 0x80038003; /* 32 byte I and D cacheline size, VIPT icache */
37
cpu->dcz_blocksize = 7; /* 512 bytes */
38
--
32
--
39
2.16.2
33
2.20.1
40
34
41
35
diff view generated by jsdifflib
1
The MPS2 AN505 FPGA image includes a "FPGA control block"
1
From: Havard Skinnemoen <hskinnemoen@google.com>
2
which is a small set of registers handling LEDs, buttons
2
3
and some counters.
3
Implement a device model for the System Global Control Registers in the
4
4
NPCM730 and NPCM750 BMC SoCs.
5
6
This is primarily used to enable SMP boot (the boot ROM spins reading
7
the SCRPAD register) and DDR memory initialization; other registers are
8
best effort for now.
9
10
The reset values of the MDLR and PWRON registers are determined by the
11
SoC variant (730 vs 750) and board straps respectively.
12
13
Reviewed-by: Joel Stanley <joel@jms.id.au>
14
Reviewed-by: Cédric Le Goater <clg@kaod.org>
15
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
16
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
17
Tested-by: Alexander Bulekov <alxndr@bu.edu>
18
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
19
Message-id: 20200911052101.2602693-2-hskinnemoen@google.com
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
20
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20180220180325.29818-14-peter.maydell@linaro.org
8
---
21
---
9
hw/misc/Makefile.objs | 1 +
22
include/hw/misc/npcm7xx_gcr.h | 43 ++++++
10
include/hw/misc/mps2-fpgaio.h | 43 ++++++++++
23
hw/misc/npcm7xx_gcr.c | 269 ++++++++++++++++++++++++++++++++++
11
hw/misc/mps2-fpgaio.c | 176 ++++++++++++++++++++++++++++++++++++++++
24
MAINTAINERS | 8 +
12
default-configs/arm-softmmu.mak | 1 +
25
hw/arm/Kconfig | 3 +
13
hw/misc/trace-events | 6 ++
26
hw/misc/meson.build | 3 +
14
5 files changed, 227 insertions(+)
27
hw/misc/trace-events | 4 +
15
create mode 100644 include/hw/misc/mps2-fpgaio.h
28
6 files changed, 330 insertions(+)
16
create mode 100644 hw/misc/mps2-fpgaio.c
29
create mode 100644 include/hw/misc/npcm7xx_gcr.h
17
30
create mode 100644 hw/misc/npcm7xx_gcr.c
18
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
31
19
index XXXXXXX..XXXXXXX 100644
32
diff --git a/include/hw/misc/npcm7xx_gcr.h b/include/hw/misc/npcm7xx_gcr.h
20
--- a/hw/misc/Makefile.objs
21
+++ b/hw/misc/Makefile.objs
22
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_STM32F2XX_SYSCFG) += stm32f2xx_syscfg.o
23
obj-$(CONFIG_MIPS_CPS) += mips_cmgcr.o
24
obj-$(CONFIG_MIPS_CPS) += mips_cpc.o
25
obj-$(CONFIG_MIPS_ITU) += mips_itu.o
26
+obj-$(CONFIG_MPS2_FPGAIO) += mps2-fpgaio.o
27
obj-$(CONFIG_MPS2_SCC) += mps2-scc.o
28
29
obj-$(CONFIG_PVPANIC) += pvpanic.o
30
diff --git a/include/hw/misc/mps2-fpgaio.h b/include/hw/misc/mps2-fpgaio.h
31
new file mode 100644
33
new file mode 100644
32
index XXXXXXX..XXXXXXX
34
index XXXXXXX..XXXXXXX
33
--- /dev/null
35
--- /dev/null
34
+++ b/include/hw/misc/mps2-fpgaio.h
36
+++ b/include/hw/misc/npcm7xx_gcr.h
35
@@ -XXX,XX +XXX,XX @@
37
@@ -XXX,XX +XXX,XX @@
36
+/*
38
+/*
37
+ * ARM MPS2 FPGAIO emulation
39
+ * Nuvoton NPCM7xx System Global Control Registers.
38
+ *
40
+ *
39
+ * Copyright (c) 2018 Linaro Limited
41
+ * Copyright 2020 Google LLC
40
+ * Written by Peter Maydell
42
+ *
41
+ *
43
+ * This program is free software; you can redistribute it and/or modify it
42
+ * This program is free software; you can redistribute it and/or modify
44
+ * under the terms of the GNU General Public License as published by the
43
+ * it under the terms of the GNU General Public License version 2 or
45
+ * Free Software Foundation; either version 2 of the License, or
44
+ * (at your option) any later version.
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.
45
+ */
52
+ */
46
+
53
+#ifndef NPCM7XX_GCR_H
47
+/* This is a model of the FPGAIO register block in the AN505
54
+#define NPCM7XX_GCR_H
48
+ * FPGA image for the MPS2 dev board; it is documented in the
55
+
49
+ * application note:
56
+#include "exec/memory.h"
50
+ * http://infocenter.arm.com/help/topic/com.arm.doc.dai0505b/index.html
57
+#include "hw/sysbus.h"
51
+ *
58
+
52
+ * QEMU interface:
59
+/*
53
+ * + sysbus MMIO region 0: the register bank
60
+ * Number of registers in our device state structure. Don't change this without
61
+ * incrementing the version_id in the vmstate.
54
+ */
62
+ */
55
+
63
+#define NPCM7XX_GCR_NR_REGS (0x148 / sizeof(uint32_t))
56
+#ifndef MPS2_FPGAIO_H
64
+
57
+#define MPS2_FPGAIO_H
65
+typedef struct NPCM7xxGCRState {
58
+
66
+ SysBusDevice parent;
59
+#include "hw/sysbus.h"
67
+
60
+
61
+#define TYPE_MPS2_FPGAIO "mps2-fpgaio"
62
+#define MPS2_FPGAIO(obj) OBJECT_CHECK(MPS2FPGAIO, (obj), TYPE_MPS2_FPGAIO)
63
+
64
+typedef struct {
65
+ /*< private >*/
66
+ SysBusDevice parent_obj;
67
+
68
+ /*< public >*/
69
+ MemoryRegion iomem;
68
+ MemoryRegion iomem;
70
+
69
+
71
+ uint32_t led0;
70
+ uint32_t regs[NPCM7XX_GCR_NR_REGS];
72
+ uint32_t prescale;
71
+
73
+ uint32_t misc;
72
+ uint32_t reset_pwron;
74
+
73
+ uint32_t reset_mdlr;
75
+ uint32_t prescale_clk;
74
+ uint32_t reset_intcr3;
76
+} MPS2FPGAIO;
75
+} NPCM7xxGCRState;
77
+
76
+
78
+#endif
77
+#define TYPE_NPCM7XX_GCR "npcm7xx-gcr"
79
diff --git a/hw/misc/mps2-fpgaio.c b/hw/misc/mps2-fpgaio.c
78
+#define NPCM7XX_GCR(obj) OBJECT_CHECK(NPCM7xxGCRState, (obj), TYPE_NPCM7XX_GCR)
79
+
80
+#endif /* NPCM7XX_GCR_H */
81
diff --git a/hw/misc/npcm7xx_gcr.c b/hw/misc/npcm7xx_gcr.c
80
new file mode 100644
82
new file mode 100644
81
index XXXXXXX..XXXXXXX
83
index XXXXXXX..XXXXXXX
82
--- /dev/null
84
--- /dev/null
83
+++ b/hw/misc/mps2-fpgaio.c
85
+++ b/hw/misc/npcm7xx_gcr.c
84
@@ -XXX,XX +XXX,XX @@
86
@@ -XXX,XX +XXX,XX @@
85
+/*
87
+/*
86
+ * ARM MPS2 AN505 FPGAIO emulation
88
+ * Nuvoton NPCM7xx System Global Control Registers.
87
+ *
89
+ *
88
+ * Copyright (c) 2018 Linaro Limited
90
+ * Copyright 2020 Google LLC
89
+ * Written by Peter Maydell
91
+ *
90
+ *
92
+ * This program is free software; you can redistribute it and/or modify it
91
+ * This program is free software; you can redistribute it and/or modify
93
+ * under the terms of the GNU General Public License as published by the
92
+ * it under the terms of the GNU General Public License version 2 or
94
+ * Free Software Foundation; either version 2 of the License, or
93
+ * (at your option) any later version.
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.
94
+ */
101
+ */
95
+
102
+
96
+/* This is a model of the "FPGA system control and I/O" block found
97
+ * in the AN505 FPGA image for the MPS2 devboard.
98
+ * It is documented in AN505:
99
+ * http://infocenter.arm.com/help/topic/com.arm.doc.dai0505b/index.html
100
+ */
101
+
102
+#include "qemu/osdep.h"
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"
103
+#include "qemu/log.h"
110
+#include "qemu/log.h"
104
+#include "qapi/error.h"
111
+#include "qemu/module.h"
112
+#include "qemu/units.h"
113
+
105
+#include "trace.h"
114
+#include "trace.h"
106
+#include "hw/sysbus.h"
115
+
107
+#include "hw/registerfields.h"
116
+#define NPCM7XX_GCR_MIN_DRAM_SIZE (128 * MiB)
108
+#include "hw/misc/mps2-fpgaio.h"
117
+#define NPCM7XX_GCR_MAX_DRAM_SIZE (2 * GiB)
109
+
118
+
110
+REG32(LED0, 0)
119
+enum NPCM7xxGCRRegisters {
111
+REG32(BUTTON, 8)
120
+ NPCM7XX_GCR_PDID,
112
+REG32(CLK1HZ, 0x10)
121
+ NPCM7XX_GCR_PWRON,
113
+REG32(CLK100HZ, 0x14)
122
+ NPCM7XX_GCR_MFSEL1 = 0x0c / sizeof(uint32_t),
114
+REG32(COUNTER, 0x18)
123
+ NPCM7XX_GCR_MFSEL2,
115
+REG32(PRESCALE, 0x1c)
124
+ NPCM7XX_GCR_MISCPE,
116
+REG32(PSCNTR, 0x20)
125
+ NPCM7XX_GCR_SPSWC = 0x038 / sizeof(uint32_t),
117
+REG32(MISC, 0x4c)
126
+ NPCM7XX_GCR_INTCR,
118
+
127
+ NPCM7XX_GCR_INTSR,
119
+static uint64_t mps2_fpgaio_read(void *opaque, hwaddr offset, unsigned size)
128
+ NPCM7XX_GCR_HIFCR = 0x050 / sizeof(uint32_t),
120
+{
129
+ NPCM7XX_GCR_INTCR2 = 0x060 / sizeof(uint32_t),
121
+ MPS2FPGAIO *s = MPS2_FPGAIO(opaque);
130
+ NPCM7XX_GCR_MFSEL3,
122
+ uint64_t r;
131
+ NPCM7XX_GCR_SRCNT,
123
+
132
+ NPCM7XX_GCR_RESSR,
124
+ switch (offset) {
133
+ NPCM7XX_GCR_RLOCKR1,
125
+ case A_LED0:
134
+ NPCM7XX_GCR_FLOCKR1,
126
+ r = s->led0;
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;
127
+ break;
219
+ break;
128
+ case A_BUTTON:
220
+
129
+ /* User-pressable board buttons. We don't model that, so just return
221
+ case NPCM7XX_GCR_RLOCKR1:
130
+ * zeroes.
222
+ case NPCM7XX_GCR_MDLR:
131
+ */
223
+ /* Write 1 to set */
132
+ r = 0;
224
+ value |= s->regs[reg];
133
+ break;
225
+ break;
134
+ case A_PRESCALE:
226
+ };
135
+ r = s->prescale;
227
+
136
+ break;
228
+ s->regs[reg] = value;
137
+ case A_MISC:
229
+}
138
+ r = s->misc;
230
+
139
+ break;
231
+static const struct MemoryRegionOps npcm7xx_gcr_ops = {
140
+ case A_CLK1HZ:
232
+ .read = npcm7xx_gcr_read,
141
+ case A_CLK100HZ:
233
+ .write = npcm7xx_gcr_write,
142
+ case A_COUNTER:
234
+ .endianness = DEVICE_LITTLE_ENDIAN,
143
+ case A_PSCNTR:
235
+ .valid = {
144
+ /* These are all upcounters of various frequencies. */
236
+ .min_access_size = 4,
145
+ qemu_log_mask(LOG_UNIMP, "MPS2 FPGAIO: counters unimplemented\n");
237
+ .max_access_size = 4,
146
+ r = 0;
238
+ .unaligned = false,
147
+ break;
239
+ },
148
+ default:
240
+};
149
+ qemu_log_mask(LOG_GUEST_ERROR,
241
+
150
+ "MPS2 FPGAIO read: bad offset %x\n", (int) offset);
242
+static void npcm7xx_gcr_enter_reset(Object *obj, ResetType type)
151
+ r = 0;
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;
152
+ break;
254
+ break;
153
+ }
255
+ }
154
+
256
+}
155
+ trace_mps2_fpgaio_read(offset, r, size);
257
+
156
+ return r;
258
+static void npcm7xx_gcr_realize(DeviceState *dev, Error **errp)
157
+}
259
+{
158
+
260
+ ERRP_GUARD();
159
+static void mps2_fpgaio_write(void *opaque, hwaddr offset, uint64_t value,
261
+ NPCM7xxGCRState *s = NPCM7XX_GCR(dev);
160
+ unsigned size)
262
+ uint64_t dram_size;
161
+{
263
+ Object *obj;
162
+ MPS2FPGAIO *s = MPS2_FPGAIO(opaque);
264
+
163
+
265
+ obj = object_property_get_link(OBJECT(dev), "dram-mr", errp);
164
+ trace_mps2_fpgaio_write(offset, value, size);
266
+ if (!obj) {
165
+
267
+ error_prepend(errp, "%s: required dram-mr link not found: ", __func__);
166
+ switch (offset) {
268
+ return;
167
+ case A_LED0:
168
+ /* LED bits [1:0] control board LEDs. We don't currently have
169
+ * a mechanism for displaying this graphically, so use a trace event.
170
+ */
171
+ trace_mps2_fpgaio_leds(value & 0x02 ? '*' : '.',
172
+ value & 0x01 ? '*' : '.');
173
+ s->led0 = value & 0x3;
174
+ break;
175
+ case A_PRESCALE:
176
+ s->prescale = value;
177
+ break;
178
+ case A_MISC:
179
+ /* These are control bits for some of the other devices on the
180
+ * board (SPI, CLCD, etc). We don't implement that yet, so just
181
+ * make the bits read as written.
182
+ */
183
+ qemu_log_mask(LOG_UNIMP,
184
+ "MPS2 FPGAIO: MISC control bits unimplemented\n");
185
+ s->misc = value;
186
+ break;
187
+ default:
188
+ qemu_log_mask(LOG_GUEST_ERROR,
189
+ "MPS2 FPGAIO write: bad offset 0x%x\n", (int) offset);
190
+ break;
191
+ }
269
+ }
192
+}
270
+ dram_size = memory_region_size(MEMORY_REGION(obj));
193
+
271
+ if (!is_power_of_2(dram_size) ||
194
+static const MemoryRegionOps mps2_fpgaio_ops = {
272
+ dram_size < NPCM7XX_GCR_MIN_DRAM_SIZE ||
195
+ .read = mps2_fpgaio_read,
273
+ dram_size > NPCM7XX_GCR_MAX_DRAM_SIZE) {
196
+ .write = mps2_fpgaio_write,
274
+ g_autofree char *sz = size_to_str(dram_size);
197
+ .endianness = DEVICE_LITTLE_ENDIAN,
275
+ g_autofree char *min_sz = size_to_str(NPCM7XX_GCR_MIN_DRAM_SIZE);
198
+};
276
+ g_autofree char *max_sz = size_to_str(NPCM7XX_GCR_MAX_DRAM_SIZE);
199
+
277
+ error_setg(errp, "%s: unsupported DRAM size %s", __func__, sz);
200
+static void mps2_fpgaio_reset(DeviceState *dev)
278
+ error_append_hint(errp,
201
+{
279
+ "DRAM size must be a power of two between %s and %s,"
202
+ MPS2FPGAIO *s = MPS2_FPGAIO(dev);
280
+ " inclusive.\n", min_sz, max_sz);
203
+
281
+ return;
204
+ trace_mps2_fpgaio_reset();
282
+ }
205
+ s->led0 = 0;
283
+
206
+ s->prescale = 0;
284
+ /* Power-on reset value */
207
+ s->misc = 0;
285
+ s->reset_intcr3 = 0x00001002;
208
+}
286
+
209
+
287
+ /*
210
+static void mps2_fpgaio_init(Object *obj)
288
+ * The GMMAP (Graphics Memory Map) field is used by u-boot to detect the
211
+{
289
+ * DRAM size, and is normally initialized by the boot block as part of DRAM
212
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
290
+ * training. However, since we don't have a complete emulation of the
213
+ MPS2FPGAIO *s = MPS2_FPGAIO(obj);
291
+ * memory controller and try to make it look like it has already been
214
+
292
+ * initialized, the boot block will skip this initialization, and we need
215
+ memory_region_init_io(&s->iomem, obj, &mps2_fpgaio_ops, s,
293
+ * to make sure this field is set correctly up front.
216
+ "mps2-fpgaio", 0x1000);
294
+ *
217
+ sysbus_init_mmio(sbd, &s->iomem);
295
+ * WARNING: some versions of u-boot only looks at bits 8 and 9, so 2 GiB of
218
+}
296
+ * DRAM will be interpreted as 128 MiB.
219
+
297
+ *
220
+static const VMStateDescription mps2_fpgaio_vmstate = {
298
+ * https://github.com/Nuvoton-Israel/u-boot/blob/2aef993bd2aafeb5408dbaad0f3ce099ee40c4aa/board/nuvoton/poleg/poleg.c#L244
221
+ .name = "mps2-fpgaio",
299
+ */
222
+ .version_id = 1,
300
+ s->reset_intcr3 |= ctz64(dram_size / NPCM7XX_GCR_MIN_DRAM_SIZE) << 8;
223
+ .minimum_version_id = 1,
301
+}
302
+
303
+static void npcm7xx_gcr_init(Object *obj)
304
+{
305
+ NPCM7xxGCRState *s = NPCM7XX_GCR(obj);
306
+
307
+ memory_region_init_io(&s->iomem, obj, &npcm7xx_gcr_ops, s,
308
+ TYPE_NPCM7XX_GCR, 4 * KiB);
309
+ sysbus_init_mmio(&s->parent, &s->iomem);
310
+}
311
+
312
+static const VMStateDescription vmstate_npcm7xx_gcr = {
313
+ .name = "npcm7xx-gcr",
314
+ .version_id = 0,
315
+ .minimum_version_id = 0,
224
+ .fields = (VMStateField[]) {
316
+ .fields = (VMStateField[]) {
225
+ VMSTATE_UINT32(led0, MPS2FPGAIO),
317
+ VMSTATE_UINT32_ARRAY(regs, NPCM7xxGCRState, NPCM7XX_GCR_NR_REGS),
226
+ VMSTATE_UINT32(prescale, MPS2FPGAIO),
318
+ VMSTATE_END_OF_LIST(),
227
+ VMSTATE_UINT32(misc, MPS2FPGAIO),
319
+ },
228
+ VMSTATE_END_OF_LIST()
320
+};
229
+ }
321
+
230
+};
322
+static Property npcm7xx_gcr_properties[] = {
231
+
323
+ DEFINE_PROP_UINT32("disabled-modules", NPCM7xxGCRState, reset_mdlr, 0),
232
+static Property mps2_fpgaio_properties[] = {
324
+ DEFINE_PROP_UINT32("power-on-straps", NPCM7xxGCRState, reset_pwron, 0),
233
+ /* Frequency of the prescale counter */
234
+ DEFINE_PROP_UINT32("prescale-clk", MPS2FPGAIO, prescale_clk, 20000000),
235
+ DEFINE_PROP_END_OF_LIST(),
325
+ DEFINE_PROP_END_OF_LIST(),
236
+};
326
+};
237
+
327
+
238
+static void mps2_fpgaio_class_init(ObjectClass *klass, void *data)
328
+static void npcm7xx_gcr_class_init(ObjectClass *klass, void *data)
239
+{
329
+{
330
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
240
+ DeviceClass *dc = DEVICE_CLASS(klass);
331
+ DeviceClass *dc = DEVICE_CLASS(klass);
241
+
332
+
242
+ dc->vmsd = &mps2_fpgaio_vmstate;
333
+ QEMU_BUILD_BUG_ON(NPCM7XX_GCR_REGS_END > NPCM7XX_GCR_NR_REGS);
243
+ dc->reset = mps2_fpgaio_reset;
334
+
244
+ dc->props = mps2_fpgaio_properties;
335
+ dc->desc = "NPCM7xx System Global Control Registers";
245
+}
336
+ dc->realize = npcm7xx_gcr_realize;
246
+
337
+ dc->vmsd = &vmstate_npcm7xx_gcr;
247
+static const TypeInfo mps2_fpgaio_info = {
338
+ rc->phases.enter = npcm7xx_gcr_enter_reset;
248
+ .name = TYPE_MPS2_FPGAIO,
339
+
249
+ .parent = TYPE_SYS_BUS_DEVICE,
340
+ device_class_set_props(dc, npcm7xx_gcr_properties);
250
+ .instance_size = sizeof(MPS2FPGAIO),
341
+}
251
+ .instance_init = mps2_fpgaio_init,
342
+
252
+ .class_init = mps2_fpgaio_class_init,
343
+static const TypeInfo npcm7xx_gcr_info = {
253
+};
344
+ .name = TYPE_NPCM7XX_GCR,
254
+
345
+ .parent = TYPE_SYS_BUS_DEVICE,
255
+static void mps2_fpgaio_register_types(void)
346
+ .instance_size = sizeof(NPCM7xxGCRState),
256
+{
347
+ .instance_init = npcm7xx_gcr_init,
257
+ type_register_static(&mps2_fpgaio_info);
348
+ .class_init = npcm7xx_gcr_class_init,
258
+}
349
+};
259
+
350
+
260
+type_init(mps2_fpgaio_register_types);
351
+static void npcm7xx_gcr_register_type(void)
261
diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
352
+{
353
+ type_register_static(&npcm7xx_gcr_info);
354
+}
355
+type_init(npcm7xx_gcr_register_type);
356
diff --git a/MAINTAINERS b/MAINTAINERS
262
index XXXXXXX..XXXXXXX 100644
357
index XXXXXXX..XXXXXXX 100644
263
--- a/default-configs/arm-softmmu.mak
358
--- a/MAINTAINERS
264
+++ b/default-configs/arm-softmmu.mak
359
+++ b/MAINTAINERS
265
@@ -XXX,XX +XXX,XX @@ CONFIG_STM32F205_SOC=y
360
@@ -XXX,XX +XXX,XX @@ S: Odd Fixes
266
CONFIG_CMSDK_APB_TIMER=y
361
F: hw/arm/musicpal.c
267
CONFIG_CMSDK_APB_UART=y
362
F: docs/system/arm/musicpal.rst
268
363
269
+CONFIG_MPS2_FPGAIO=y
364
+Nuvoton NPCM7xx
270
CONFIG_MPS2_SCC=y
365
+M: Havard Skinnemoen <hskinnemoen@google.com>
271
366
+M: Tyrone Ting <kfting@nuvoton.com>
272
CONFIG_VERSATILE_PCI=y
367
+L: qemu-arm@nongnu.org
368
+S: Supported
369
+F: hw/*/npcm7xx*
370
+F: include/hw/*/npcm7xx*
371
+
372
nSeries
373
M: Andrzej Zaborowski <balrogg@gmail.com>
374
M: Peter Maydell <peter.maydell@linaro.org>
375
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
376
index XXXXXXX..XXXXXXX 100644
377
--- a/hw/arm/Kconfig
378
+++ b/hw/arm/Kconfig
379
@@ -XXX,XX +XXX,XX @@ config XLNX_VERSAL
380
select VIRTIO_MMIO
381
select UNIMP
382
383
+config NPCM7XX
384
+ bool
385
+
386
config FSL_IMX25
387
bool
388
select IMX
389
diff --git a/hw/misc/meson.build b/hw/misc/meson.build
390
index XXXXXXX..XXXXXXX 100644
391
--- a/hw/misc/meson.build
392
+++ b/hw/misc/meson.build
393
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_IMX', if_true: files(
394
))
395
softmmu_ss.add(when: 'CONFIG_MILKYMIST', if_true: files('milkymist-hpdmc.c', 'milkymist-pfpu.c'))
396
softmmu_ss.add(when: 'CONFIG_MAINSTONE', if_true: files('mst_fpga.c'))
397
+softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files(
398
+ 'npcm7xx_gcr.c',
399
+))
400
softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files(
401
'omap_clk.c',
402
'omap_gpmc.c',
273
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
403
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
274
index XXXXXXX..XXXXXXX 100644
404
index XXXXXXX..XXXXXXX 100644
275
--- a/hw/misc/trace-events
405
--- a/hw/misc/trace-events
276
+++ b/hw/misc/trace-events
406
+++ b/hw/misc/trace-events
277
@@ -XXX,XX +XXX,XX @@ mps2_scc_leds(char led7, char led6, char led5, char led4, char led3, char led2,
407
@@ -XXX,XX +XXX,XX @@ mos6522_set_sr_int(void) "set sr_int"
278
mps2_scc_cfg_write(unsigned function, unsigned device, uint32_t value) "MPS2 SCC config write: function %d device %d data 0x%" PRIx32
408
mos6522_write(uint64_t addr, uint64_t val) "reg=0x%"PRIx64 " val=0x%"PRIx64
279
mps2_scc_cfg_read(unsigned function, unsigned device, uint32_t value) "MPS2 SCC config read: function %d device %d data 0x%" PRIx32
409
mos6522_read(uint64_t addr, unsigned val) "reg=0x%"PRIx64 " val=0x%x"
280
410
281
+# hw/misc/mps2_fpgaio.c
411
+# npcm7xx_gcr.c
282
+mps2_fpgaio_read(uint64_t offset, uint64_t data, unsigned size) "MPS2 FPGAIO read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
412
+npcm7xx_gcr_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
283
+mps2_fpgaio_write(uint64_t offset, uint64_t data, unsigned size) "MPS2 FPGAIO write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
413
+npcm7xx_gcr_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
284
+mps2_fpgaio_reset(void) "MPS2 FPGAIO: reset"
414
+
285
+mps2_fpgaio_leds(char led1, char led0) "MPS2 FPGAIO LEDs: %c%c"
415
# stm32f4xx_syscfg.c
286
+
416
stm32f4xx_syscfg_set_irq(int gpio, int line, int level) "Interupt: GPIO: %d, Line: %d; Level: %d"
287
# hw/misc/msf2-sysreg.c
417
stm32f4xx_pulse_exti(int irq) "Pulse EXTI: %d"
288
msf2_sysreg_write(uint64_t offset, uint32_t val, uint32_t prev) "msf2-sysreg write: addr 0x%08" HWADDR_PRIx " data 0x%" PRIx32 " prev 0x%" PRIx32
289
msf2_sysreg_read(uint64_t offset, uint32_t val) "msf2-sysreg read: addr 0x%08" HWADDR_PRIx " data 0x%08" PRIx32
290
--
418
--
291
2.16.2
419
2.20.1
292
420
293
421
diff view generated by jsdifflib
1
The Arm IoT Kit includes a "security controller" which is largely a
1
From: Havard Skinnemoen <hskinnemoen@google.com>
2
collection of registers for controlling the PPCs and other bits of
2
3
glue in the system. This commit provides the initial skeleton of the
3
Enough functionality to boot the Linux kernel has been implemented. This
4
device, implementing just the ID registers, and a couple of read-only
4
includes:
5
read-as-zero registers.
5
6
6
- Correct power-on reset values so the various clock rates can be
7
accurately calculated.
8
- Clock enables stick around when written.
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
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
21
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Message-id: 20180220180325.29818-16-peter.maydell@linaro.org
10
---
22
---
11
hw/misc/Makefile.objs | 1 +
23
include/hw/misc/npcm7xx_clk.h | 48 ++++++
12
include/hw/misc/iotkit-secctl.h | 39 ++++
24
hw/misc/npcm7xx_clk.c | 266 ++++++++++++++++++++++++++++++++++
13
hw/misc/iotkit-secctl.c | 448 ++++++++++++++++++++++++++++++++++++++++
25
hw/misc/meson.build | 1 +
14
default-configs/arm-softmmu.mak | 1 +
26
hw/misc/trace-events | 4 +
15
hw/misc/trace-events | 7 +
27
4 files changed, 319 insertions(+)
16
5 files changed, 496 insertions(+)
28
create mode 100644 include/hw/misc/npcm7xx_clk.h
17
create mode 100644 include/hw/misc/iotkit-secctl.h
29
create mode 100644 hw/misc/npcm7xx_clk.c
18
create mode 100644 hw/misc/iotkit-secctl.c
30
19
31
diff --git a/include/hw/misc/npcm7xx_clk.h b/include/hw/misc/npcm7xx_clk.h
20
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
21
index XXXXXXX..XXXXXXX 100644
22
--- a/hw/misc/Makefile.objs
23
+++ b/hw/misc/Makefile.objs
24
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_MPS2_FPGAIO) += mps2-fpgaio.o
25
obj-$(CONFIG_MPS2_SCC) += mps2-scc.o
26
27
obj-$(CONFIG_TZ_PPC) += tz-ppc.o
28
+obj-$(CONFIG_IOTKIT_SECCTL) += iotkit-secctl.o
29
30
obj-$(CONFIG_PVPANIC) += pvpanic.o
31
obj-$(CONFIG_HYPERV_TESTDEV) += hyperv_testdev.o
32
diff --git a/include/hw/misc/iotkit-secctl.h b/include/hw/misc/iotkit-secctl.h
33
new file mode 100644
32
new file mode 100644
34
index XXXXXXX..XXXXXXX
33
index XXXXXXX..XXXXXXX
35
--- /dev/null
34
--- /dev/null
36
+++ b/include/hw/misc/iotkit-secctl.h
35
+++ b/include/hw/misc/npcm7xx_clk.h
37
@@ -XXX,XX +XXX,XX @@
36
@@ -XXX,XX +XXX,XX @@
38
+/*
37
+/*
39
+ * ARM IoT Kit security controller
38
+ * Nuvoton NPCM7xx Clock Control Registers.
40
+ *
39
+ *
41
+ * Copyright (c) 2018 Linaro Limited
40
+ * Copyright 2020 Google LLC
42
+ * Written by Peter Maydell
41
+ *
43
+ *
42
+ * This program is free software; you can redistribute it and/or modify it
44
+ * This program is free software; you can redistribute it and/or modify
43
+ * under the terms of the GNU General Public License as published by the
45
+ * it under the terms of the GNU General Public License version 2 or
44
+ * Free Software Foundation; either version 2 of the License, or
46
+ * (at your option) any later version.
45
+ * (at your option) any later version.
47
+ */
46
+ *
48
+
47
+ * This program is distributed in the hope that it will be useful, but WITHOUT
49
+/* This is a model of the security controller which is part of the
48
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
50
+ * Arm IoT Kit and documented in
49
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
51
+ * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
50
+ * for more details.
52
+ *
51
+ */
53
+ * QEMU interface:
52
+#ifndef NPCM7XX_CLK_H
54
+ * + sysbus MMIO region 0 is the "secure privilege control block" registers
53
+#define NPCM7XX_CLK_H
55
+ * + sysbus MMIO region 1 is the "non-secure privilege control block" registers
54
+
56
+ */
55
+#include "exec/memory.h"
57
+
58
+#ifndef IOTKIT_SECCTL_H
59
+#define IOTKIT_SECCTL_H
60
+
61
+#include "hw/sysbus.h"
56
+#include "hw/sysbus.h"
62
+
57
+
63
+#define TYPE_IOTKIT_SECCTL "iotkit-secctl"
58
+/*
64
+#define IOTKIT_SECCTL(obj) OBJECT_CHECK(IoTKitSecCtl, (obj), TYPE_IOTKIT_SECCTL)
59
+ * The reference clock frequency for the timer modules, and the SECCNT and
65
+
60
+ * CNTR25M registers in this module, is always 25 MHz.
66
+typedef struct IoTKitSecCtl {
61
+ */
67
+ /*< private >*/
62
+#define NPCM7XX_TIMER_REF_HZ (25000000)
68
+ SysBusDevice parent_obj;
63
+
69
+
64
+/*
70
+ /*< public >*/
65
+ * Number of registers in our device state structure. Don't change this without
71
+
66
+ * incrementing the version_id in the vmstate.
72
+ MemoryRegion s_regs;
67
+ */
73
+ MemoryRegion ns_regs;
68
+#define NPCM7XX_CLK_NR_REGS (0x70 / sizeof(uint32_t))
74
+} IoTKitSecCtl;
69
+
75
+
70
+typedef struct NPCM7xxCLKState {
76
+#endif
71
+ SysBusDevice parent;
77
diff --git a/hw/misc/iotkit-secctl.c b/hw/misc/iotkit-secctl.c
72
+
73
+ MemoryRegion iomem;
74
+
75
+ uint32_t regs[NPCM7XX_CLK_NR_REGS];
76
+
77
+ /* Time reference for SECCNT and CNTR25M, initialized by power on reset */
78
+ int64_t ref_ns;
79
+} NPCM7xxCLKState;
80
+
81
+#define TYPE_NPCM7XX_CLK "npcm7xx-clk"
82
+#define NPCM7XX_CLK(obj) OBJECT_CHECK(NPCM7xxCLKState, (obj), TYPE_NPCM7XX_CLK)
83
+
84
+#endif /* NPCM7XX_CLK_H */
85
diff --git a/hw/misc/npcm7xx_clk.c b/hw/misc/npcm7xx_clk.c
78
new file mode 100644
86
new file mode 100644
79
index XXXXXXX..XXXXXXX
87
index XXXXXXX..XXXXXXX
80
--- /dev/null
88
--- /dev/null
81
+++ b/hw/misc/iotkit-secctl.c
89
+++ b/hw/misc/npcm7xx_clk.c
82
@@ -XXX,XX +XXX,XX @@
90
@@ -XXX,XX +XXX,XX @@
83
+/*
91
+/*
84
+ * Arm IoT Kit security controller
92
+ * Nuvoton NPCM7xx Clock Control Registers.
85
+ *
93
+ *
86
+ * Copyright (c) 2018 Linaro Limited
94
+ * Copyright 2020 Google LLC
87
+ * Written by Peter Maydell
95
+ *
88
+ *
96
+ * This program is free software; you can redistribute it and/or modify it
89
+ * This program is free software; you can redistribute it and/or modify
97
+ * under the terms of the GNU General Public License as published by the
90
+ * it under the terms of the GNU General Public License version 2 or
98
+ * Free Software Foundation; either version 2 of the License, or
91
+ * (at your option) any later version.
99
+ * (at your option) any later version.
100
+ *
101
+ * This program is distributed in the hope that it will be useful, but WITHOUT
102
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
103
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
104
+ * for more details.
92
+ */
105
+ */
93
+
106
+
94
+#include "qemu/osdep.h"
107
+#include "qemu/osdep.h"
108
+
109
+#include "hw/misc/npcm7xx_clk.h"
110
+#include "migration/vmstate.h"
111
+#include "qemu/error-report.h"
95
+#include "qemu/log.h"
112
+#include "qemu/log.h"
96
+#include "qapi/error.h"
113
+#include "qemu/module.h"
114
+#include "qemu/timer.h"
115
+#include "qemu/units.h"
97
+#include "trace.h"
116
+#include "trace.h"
98
+#include "hw/sysbus.h"
117
+
99
+#include "hw/registerfields.h"
118
+#define PLLCON_LOKI BIT(31)
100
+#include "hw/misc/iotkit-secctl.h"
119
+#define PLLCON_LOKS BIT(30)
101
+
120
+#define PLLCON_PWDEN BIT(12)
102
+/* Registers in the secure privilege control block */
121
+
103
+REG32(SECRESPCFG, 0x10)
122
+enum NPCM7xxCLKRegisters {
104
+REG32(NSCCFG, 0x14)
123
+ NPCM7XX_CLK_CLKEN1,
105
+REG32(SECMPCINTSTATUS, 0x1c)
124
+ NPCM7XX_CLK_CLKSEL,
106
+REG32(SECPPCINTSTAT, 0x20)
125
+ NPCM7XX_CLK_CLKDIV1,
107
+REG32(SECPPCINTCLR, 0x24)
126
+ NPCM7XX_CLK_PLLCON0,
108
+REG32(SECPPCINTEN, 0x28)
127
+ NPCM7XX_CLK_PLLCON1,
109
+REG32(SECMSCINTSTAT, 0x30)
128
+ NPCM7XX_CLK_SWRSTR,
110
+REG32(SECMSCINTCLR, 0x34)
129
+ NPCM7XX_CLK_IPSRST1 = 0x20 / sizeof(uint32_t),
111
+REG32(SECMSCINTEN, 0x38)
130
+ NPCM7XX_CLK_IPSRST2,
112
+REG32(BRGINTSTAT, 0x40)
131
+ NPCM7XX_CLK_CLKEN2,
113
+REG32(BRGINTCLR, 0x44)
132
+ NPCM7XX_CLK_CLKDIV2,
114
+REG32(BRGINTEN, 0x48)
133
+ NPCM7XX_CLK_CLKEN3,
115
+REG32(AHBNSPPC0, 0x50)
134
+ NPCM7XX_CLK_IPSRST3,
116
+REG32(AHBNSPPCEXP0, 0x60)
135
+ NPCM7XX_CLK_WD0RCR,
117
+REG32(AHBNSPPCEXP1, 0x64)
136
+ NPCM7XX_CLK_WD1RCR,
118
+REG32(AHBNSPPCEXP2, 0x68)
137
+ NPCM7XX_CLK_WD2RCR,
119
+REG32(AHBNSPPCEXP3, 0x6c)
138
+ NPCM7XX_CLK_SWRSTC1,
120
+REG32(APBNSPPC0, 0x70)
139
+ NPCM7XX_CLK_SWRSTC2,
121
+REG32(APBNSPPC1, 0x74)
140
+ NPCM7XX_CLK_SWRSTC3,
122
+REG32(APBNSPPCEXP0, 0x80)
141
+ NPCM7XX_CLK_SWRSTC4,
123
+REG32(APBNSPPCEXP1, 0x84)
142
+ NPCM7XX_CLK_PLLCON2,
124
+REG32(APBNSPPCEXP2, 0x88)
143
+ NPCM7XX_CLK_CLKDIV3,
125
+REG32(APBNSPPCEXP3, 0x8c)
144
+ NPCM7XX_CLK_CORSTC,
126
+REG32(AHBSPPPC0, 0x90)
145
+ NPCM7XX_CLK_PLLCONG,
127
+REG32(AHBSPPPCEXP0, 0xa0)
146
+ NPCM7XX_CLK_AHBCKFI,
128
+REG32(AHBSPPPCEXP1, 0xa4)
147
+ NPCM7XX_CLK_SECCNT,
129
+REG32(AHBSPPPCEXP2, 0xa8)
148
+ NPCM7XX_CLK_CNTR25M,
130
+REG32(AHBSPPPCEXP3, 0xac)
149
+ NPCM7XX_CLK_REGS_END,
131
+REG32(APBSPPPC0, 0xb0)
150
+};
132
+REG32(APBSPPPC1, 0xb4)
151
+
133
+REG32(APBSPPPCEXP0, 0xc0)
152
+/*
134
+REG32(APBSPPPCEXP1, 0xc4)
153
+ * These reset values were taken from version 0.91 of the NPCM750R data sheet.
135
+REG32(APBSPPPCEXP2, 0xc8)
154
+ *
136
+REG32(APBSPPPCEXP3, 0xcc)
155
+ * All are loaded on power-up reset. CLKENx and SWRSTR should also be loaded on
137
+REG32(NSMSCEXP, 0xd0)
156
+ * core domain reset, but this reset type is not yet supported by QEMU.
138
+REG32(PID4, 0xfd0)
157
+ */
139
+REG32(PID5, 0xfd4)
158
+static const uint32_t cold_reset_values[NPCM7XX_CLK_NR_REGS] = {
140
+REG32(PID6, 0xfd8)
159
+ [NPCM7XX_CLK_CLKEN1] = 0xffffffff,
141
+REG32(PID7, 0xfdc)
160
+ [NPCM7XX_CLK_CLKSEL] = 0x004aaaaa,
142
+REG32(PID0, 0xfe0)
161
+ [NPCM7XX_CLK_CLKDIV1] = 0x5413f855,
143
+REG32(PID1, 0xfe4)
162
+ [NPCM7XX_CLK_PLLCON0] = 0x00222101 | PLLCON_LOKI,
144
+REG32(PID2, 0xfe8)
163
+ [NPCM7XX_CLK_PLLCON1] = 0x00202101 | PLLCON_LOKI,
145
+REG32(PID3, 0xfec)
164
+ [NPCM7XX_CLK_IPSRST1] = 0x00001000,
146
+REG32(CID0, 0xff0)
165
+ [NPCM7XX_CLK_IPSRST2] = 0x80000000,
147
+REG32(CID1, 0xff4)
166
+ [NPCM7XX_CLK_CLKEN2] = 0xffffffff,
148
+REG32(CID2, 0xff8)
167
+ [NPCM7XX_CLK_CLKDIV2] = 0xaa4f8f9f,
149
+REG32(CID3, 0xffc)
168
+ [NPCM7XX_CLK_CLKEN3] = 0xffffffff,
150
+
169
+ [NPCM7XX_CLK_IPSRST3] = 0x03000000,
151
+/* Registers in the non-secure privilege control block */
170
+ [NPCM7XX_CLK_WD0RCR] = 0xffffffff,
152
+REG32(AHBNSPPPC0, 0x90)
171
+ [NPCM7XX_CLK_WD1RCR] = 0xffffffff,
153
+REG32(AHBNSPPPCEXP0, 0xa0)
172
+ [NPCM7XX_CLK_WD2RCR] = 0xffffffff,
154
+REG32(AHBNSPPPCEXP1, 0xa4)
173
+ [NPCM7XX_CLK_SWRSTC1] = 0x00000003,
155
+REG32(AHBNSPPPCEXP2, 0xa8)
174
+ [NPCM7XX_CLK_PLLCON2] = 0x00c02105 | PLLCON_LOKI,
156
+REG32(AHBNSPPPCEXP3, 0xac)
175
+ [NPCM7XX_CLK_CORSTC] = 0x04000003,
157
+REG32(APBNSPPPC0, 0xb0)
176
+ [NPCM7XX_CLK_PLLCONG] = 0x01228606 | PLLCON_LOKI,
158
+REG32(APBNSPPPC1, 0xb4)
177
+ [NPCM7XX_CLK_AHBCKFI] = 0x000000c8,
159
+REG32(APBNSPPPCEXP0, 0xc0)
178
+};
160
+REG32(APBNSPPPCEXP1, 0xc4)
179
+
161
+REG32(APBNSPPPCEXP2, 0xc8)
180
+static uint64_t npcm7xx_clk_read(void *opaque, hwaddr offset, unsigned size)
162
+REG32(APBNSPPPCEXP3, 0xcc)
181
+{
163
+/* PID and CID registers are also present in the NS block */
182
+ uint32_t reg = offset / sizeof(uint32_t);
164
+
183
+ NPCM7xxCLKState *s = opaque;
165
+static const uint8_t iotkit_secctl_s_idregs[] = {
184
+ int64_t now_ns;
166
+ 0x04, 0x00, 0x00, 0x00,
185
+ uint32_t value = 0;
167
+ 0x52, 0xb8, 0x0b, 0x00,
186
+
168
+ 0x0d, 0xf0, 0x05, 0xb1,
187
+ if (reg >= NPCM7XX_CLK_NR_REGS) {
169
+};
170
+
171
+static const uint8_t iotkit_secctl_ns_idregs[] = {
172
+ 0x04, 0x00, 0x00, 0x00,
173
+ 0x53, 0xb8, 0x0b, 0x00,
174
+ 0x0d, 0xf0, 0x05, 0xb1,
175
+};
176
+
177
+static MemTxResult iotkit_secctl_s_read(void *opaque, hwaddr addr,
178
+ uint64_t *pdata,
179
+ unsigned size, MemTxAttrs attrs)
180
+{
181
+ uint64_t r;
182
+ uint32_t offset = addr & ~0x3;
183
+
184
+ switch (offset) {
185
+ case A_AHBNSPPC0:
186
+ case A_AHBSPPPC0:
187
+ r = 0;
188
+ break;
189
+ case A_SECRESPCFG:
190
+ case A_NSCCFG:
191
+ case A_SECMPCINTSTATUS:
192
+ case A_SECPPCINTSTAT:
193
+ case A_SECPPCINTEN:
194
+ case A_SECMSCINTSTAT:
195
+ case A_SECMSCINTEN:
196
+ case A_BRGINTSTAT:
197
+ case A_BRGINTEN:
198
+ case A_AHBNSPPCEXP0:
199
+ case A_AHBNSPPCEXP1:
200
+ case A_AHBNSPPCEXP2:
201
+ case A_AHBNSPPCEXP3:
202
+ case A_APBNSPPC0:
203
+ case A_APBNSPPC1:
204
+ case A_APBNSPPCEXP0:
205
+ case A_APBNSPPCEXP1:
206
+ case A_APBNSPPCEXP2:
207
+ case A_APBNSPPCEXP3:
208
+ case A_AHBSPPPCEXP0:
209
+ case A_AHBSPPPCEXP1:
210
+ case A_AHBSPPPCEXP2:
211
+ case A_AHBSPPPCEXP3:
212
+ case A_APBSPPPC0:
213
+ case A_APBSPPPC1:
214
+ case A_APBSPPPCEXP0:
215
+ case A_APBSPPPCEXP1:
216
+ case A_APBSPPPCEXP2:
217
+ case A_APBSPPPCEXP3:
218
+ case A_NSMSCEXP:
219
+ qemu_log_mask(LOG_UNIMP,
220
+ "IoTKit SecCtl S block read: "
221
+ "unimplemented offset 0x%x\n", offset);
222
+ r = 0;
223
+ break;
224
+ case A_PID4:
225
+ case A_PID5:
226
+ case A_PID6:
227
+ case A_PID7:
228
+ case A_PID0:
229
+ case A_PID1:
230
+ case A_PID2:
231
+ case A_PID3:
232
+ case A_CID0:
233
+ case A_CID1:
234
+ case A_CID2:
235
+ case A_CID3:
236
+ r = iotkit_secctl_s_idregs[(offset - A_PID4) / 4];
237
+ break;
238
+ case A_SECPPCINTCLR:
239
+ case A_SECMSCINTCLR:
240
+ case A_BRGINTCLR:
241
+ qemu_log_mask(LOG_GUEST_ERROR,
188
+ qemu_log_mask(LOG_GUEST_ERROR,
242
+ "IotKit SecCtl S block read: write-only offset 0x%x\n",
189
+ "%s: offset 0x%04" HWADDR_PRIx " out of range\n",
243
+ offset);
190
+ __func__, offset);
244
+ r = 0;
191
+ return 0;
245
+ break;
192
+ }
193
+
194
+ switch (reg) {
195
+ case NPCM7XX_CLK_SWRSTR:
196
+ qemu_log_mask(LOG_GUEST_ERROR,
197
+ "%s: register @ 0x%04" HWADDR_PRIx " is write-only\n",
198
+ __func__, offset);
199
+ break;
200
+
201
+ case NPCM7XX_CLK_SECCNT:
202
+ now_ns = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
203
+ value = (now_ns - s->ref_ns) / NANOSECONDS_PER_SECOND;
204
+ break;
205
+
206
+ case NPCM7XX_CLK_CNTR25M:
207
+ now_ns = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
208
+ /*
209
+ * This register counts 25 MHz cycles, updating every 640 ns. It rolls
210
+ * over to zero every second.
211
+ *
212
+ * The 4 LSBs are always zero: (1e9 / 640) << 4 = 25000000.
213
+ */
214
+ value = (((now_ns - s->ref_ns) / 640) << 4) % NPCM7XX_TIMER_REF_HZ;
215
+ break;
216
+
246
+ default:
217
+ default:
218
+ value = s->regs[reg];
219
+ break;
220
+ };
221
+
222
+ trace_npcm7xx_clk_read(offset, value);
223
+
224
+ return value;
225
+}
226
+
227
+static void npcm7xx_clk_write(void *opaque, hwaddr offset,
228
+ uint64_t v, unsigned size)
229
+{
230
+ uint32_t reg = offset / sizeof(uint32_t);
231
+ NPCM7xxCLKState *s = opaque;
232
+ uint32_t value = v;
233
+
234
+ trace_npcm7xx_clk_write(offset, value);
235
+
236
+ if (reg >= NPCM7XX_CLK_NR_REGS) {
247
+ qemu_log_mask(LOG_GUEST_ERROR,
237
+ qemu_log_mask(LOG_GUEST_ERROR,
248
+ "IotKit SecCtl S block read: bad offset 0x%x\n", offset);
238
+ "%s: offset 0x%04" HWADDR_PRIx " out of range\n",
249
+ r = 0;
239
+ __func__, offset);
250
+ break;
240
+ return;
251
+ }
241
+ }
252
+
242
+
253
+ if (size != 4) {
243
+ switch (reg) {
254
+ /* None of our registers are access-sensitive, so just pull the right
244
+ case NPCM7XX_CLK_SWRSTR:
255
+ * byte out of the word read result.
245
+ qemu_log_mask(LOG_UNIMP, "%s: SW reset not implemented: 0x%02x\n",
256
+ */
246
+ __func__, value);
257
+ r = extract32(r, (addr & 3) * 8, size * 8);
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
+ }
267
+ }
268
+ break;
269
+
270
+ case NPCM7XX_CLK_CNTR25M:
271
+ qemu_log_mask(LOG_GUEST_ERROR,
272
+ "%s: register @ 0x%04" HWADDR_PRIx " is read-only\n",
273
+ __func__, offset);
274
+ return;
258
+ }
275
+ }
259
+
276
+
260
+ trace_iotkit_secctl_s_read(offset, r, size);
277
+ s->regs[reg] = value;
261
+ *pdata = r;
278
+}
262
+ return MEMTX_OK;
279
+
263
+}
280
+static const struct MemoryRegionOps npcm7xx_clk_ops = {
264
+
281
+ .read = npcm7xx_clk_read,
265
+static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr,
282
+ .write = npcm7xx_clk_write,
266
+ uint64_t value,
283
+ .endianness = DEVICE_LITTLE_ENDIAN,
267
+ unsigned size, MemTxAttrs attrs)
284
+ .valid = {
268
+{
285
+ .min_access_size = 4,
269
+ uint32_t offset = addr;
286
+ .max_access_size = 4,
270
+
287
+ .unaligned = false,
271
+ trace_iotkit_secctl_s_write(offset, value, size);
288
+ },
272
+
289
+};
273
+ if (size != 4) {
290
+
274
+ /* Byte and halfword writes are ignored */
291
+static void npcm7xx_clk_enter_reset(Object *obj, ResetType type)
275
+ qemu_log_mask(LOG_GUEST_ERROR,
292
+{
276
+ "IotKit SecCtl S block write: bad size, ignored\n");
293
+ NPCM7xxCLKState *s = NPCM7XX_CLK(obj);
277
+ return MEMTX_OK;
294
+
295
+ QEMU_BUILD_BUG_ON(sizeof(s->regs) != sizeof(cold_reset_values));
296
+
297
+ switch (type) {
298
+ case RESET_TYPE_COLD:
299
+ memcpy(s->regs, cold_reset_values, sizeof(cold_reset_values));
300
+ s->ref_ns = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
301
+ return;
278
+ }
302
+ }
279
+
303
+
280
+ switch (offset) {
304
+ /*
281
+ case A_SECRESPCFG:
305
+ * A small number of registers need to be reset on a core domain reset,
282
+ case A_NSCCFG:
306
+ * but no such reset type exists yet.
283
+ case A_SECPPCINTCLR:
307
+ */
284
+ case A_SECPPCINTEN:
308
+ qemu_log_mask(LOG_UNIMP, "%s: reset type %d not implemented.",
285
+ case A_SECMSCINTCLR:
309
+ __func__, type);
286
+ case A_SECMSCINTEN:
310
+}
287
+ case A_BRGINTCLR:
311
+
288
+ case A_BRGINTEN:
312
+static void npcm7xx_clk_init(Object *obj)
289
+ case A_AHBNSPPCEXP0:
313
+{
290
+ case A_AHBNSPPCEXP1:
314
+ NPCM7xxCLKState *s = NPCM7XX_CLK(obj);
291
+ case A_AHBNSPPCEXP2:
315
+
292
+ case A_AHBNSPPCEXP3:
316
+ memory_region_init_io(&s->iomem, obj, &npcm7xx_clk_ops, s,
293
+ case A_APBNSPPC0:
317
+ TYPE_NPCM7XX_CLK, 4 * KiB);
294
+ case A_APBNSPPC1:
318
+ sysbus_init_mmio(&s->parent, &s->iomem);
295
+ case A_APBNSPPCEXP0:
319
+}
296
+ case A_APBNSPPCEXP1:
320
+
297
+ case A_APBNSPPCEXP2:
321
+static const VMStateDescription vmstate_npcm7xx_clk = {
298
+ case A_APBNSPPCEXP3:
322
+ .name = "npcm7xx-clk",
299
+ case A_AHBSPPPCEXP0:
323
+ .version_id = 0,
300
+ case A_AHBSPPPCEXP1:
324
+ .minimum_version_id = 0,
301
+ case A_AHBSPPPCEXP2:
302
+ case A_AHBSPPPCEXP3:
303
+ case A_APBSPPPC0:
304
+ case A_APBSPPPC1:
305
+ case A_APBSPPPCEXP0:
306
+ case A_APBSPPPCEXP1:
307
+ case A_APBSPPPCEXP2:
308
+ case A_APBSPPPCEXP3:
309
+ qemu_log_mask(LOG_UNIMP,
310
+ "IoTKit SecCtl S block write: "
311
+ "unimplemented offset 0x%x\n", offset);
312
+ break;
313
+ case A_SECMPCINTSTATUS:
314
+ case A_SECPPCINTSTAT:
315
+ case A_SECMSCINTSTAT:
316
+ case A_BRGINTSTAT:
317
+ case A_AHBNSPPC0:
318
+ case A_AHBSPPPC0:
319
+ case A_NSMSCEXP:
320
+ case A_PID4:
321
+ case A_PID5:
322
+ case A_PID6:
323
+ case A_PID7:
324
+ case A_PID0:
325
+ case A_PID1:
326
+ case A_PID2:
327
+ case A_PID3:
328
+ case A_CID0:
329
+ case A_CID1:
330
+ case A_CID2:
331
+ case A_CID3:
332
+ qemu_log_mask(LOG_GUEST_ERROR,
333
+ "IoTKit SecCtl S block write: "
334
+ "read-only offset 0x%x\n", offset);
335
+ break;
336
+ default:
337
+ qemu_log_mask(LOG_GUEST_ERROR,
338
+ "IotKit SecCtl S block write: bad offset 0x%x\n",
339
+ offset);
340
+ break;
341
+ }
342
+
343
+ return MEMTX_OK;
344
+}
345
+
346
+static MemTxResult iotkit_secctl_ns_read(void *opaque, hwaddr addr,
347
+ uint64_t *pdata,
348
+ unsigned size, MemTxAttrs attrs)
349
+{
350
+ uint64_t r;
351
+ uint32_t offset = addr & ~0x3;
352
+
353
+ switch (offset) {
354
+ case A_AHBNSPPPC0:
355
+ r = 0;
356
+ break;
357
+ case A_AHBNSPPPCEXP0:
358
+ case A_AHBNSPPPCEXP1:
359
+ case A_AHBNSPPPCEXP2:
360
+ case A_AHBNSPPPCEXP3:
361
+ case A_APBNSPPPC0:
362
+ case A_APBNSPPPC1:
363
+ case A_APBNSPPPCEXP0:
364
+ case A_APBNSPPPCEXP1:
365
+ case A_APBNSPPPCEXP2:
366
+ case A_APBNSPPPCEXP3:
367
+ qemu_log_mask(LOG_UNIMP,
368
+ "IoTKit SecCtl NS block read: "
369
+ "unimplemented offset 0x%x\n", offset);
370
+ break;
371
+ case A_PID4:
372
+ case A_PID5:
373
+ case A_PID6:
374
+ case A_PID7:
375
+ case A_PID0:
376
+ case A_PID1:
377
+ case A_PID2:
378
+ case A_PID3:
379
+ case A_CID0:
380
+ case A_CID1:
381
+ case A_CID2:
382
+ case A_CID3:
383
+ r = iotkit_secctl_ns_idregs[(offset - A_PID4) / 4];
384
+ break;
385
+ default:
386
+ qemu_log_mask(LOG_GUEST_ERROR,
387
+ "IotKit SecCtl NS block write: bad offset 0x%x\n",
388
+ offset);
389
+ r = 0;
390
+ break;
391
+ }
392
+
393
+ if (size != 4) {
394
+ /* None of our registers are access-sensitive, so just pull the right
395
+ * byte out of the word read result.
396
+ */
397
+ r = extract32(r, (addr & 3) * 8, size * 8);
398
+ }
399
+
400
+ trace_iotkit_secctl_ns_read(offset, r, size);
401
+ *pdata = r;
402
+ return MEMTX_OK;
403
+}
404
+
405
+static MemTxResult iotkit_secctl_ns_write(void *opaque, hwaddr addr,
406
+ uint64_t value,
407
+ unsigned size, MemTxAttrs attrs)
408
+{
409
+ uint32_t offset = addr;
410
+
411
+ trace_iotkit_secctl_ns_write(offset, value, size);
412
+
413
+ if (size != 4) {
414
+ /* Byte and halfword writes are ignored */
415
+ qemu_log_mask(LOG_GUEST_ERROR,
416
+ "IotKit SecCtl NS block write: bad size, ignored\n");
417
+ return MEMTX_OK;
418
+ }
419
+
420
+ switch (offset) {
421
+ case A_AHBNSPPPCEXP0:
422
+ case A_AHBNSPPPCEXP1:
423
+ case A_AHBNSPPPCEXP2:
424
+ case A_AHBNSPPPCEXP3:
425
+ case A_APBNSPPPC0:
426
+ case A_APBNSPPPC1:
427
+ case A_APBNSPPPCEXP0:
428
+ case A_APBNSPPPCEXP1:
429
+ case A_APBNSPPPCEXP2:
430
+ case A_APBNSPPPCEXP3:
431
+ qemu_log_mask(LOG_UNIMP,
432
+ "IoTKit SecCtl NS block write: "
433
+ "unimplemented offset 0x%x\n", offset);
434
+ break;
435
+ case A_AHBNSPPPC0:
436
+ case A_PID4:
437
+ case A_PID5:
438
+ case A_PID6:
439
+ case A_PID7:
440
+ case A_PID0:
441
+ case A_PID1:
442
+ case A_PID2:
443
+ case A_PID3:
444
+ case A_CID0:
445
+ case A_CID1:
446
+ case A_CID2:
447
+ case A_CID3:
448
+ qemu_log_mask(LOG_GUEST_ERROR,
449
+ "IoTKit SecCtl NS block write: "
450
+ "read-only offset 0x%x\n", offset);
451
+ break;
452
+ default:
453
+ qemu_log_mask(LOG_GUEST_ERROR,
454
+ "IotKit SecCtl NS block write: bad offset 0x%x\n",
455
+ offset);
456
+ break;
457
+ }
458
+
459
+ return MEMTX_OK;
460
+}
461
+
462
+static const MemoryRegionOps iotkit_secctl_s_ops = {
463
+ .read_with_attrs = iotkit_secctl_s_read,
464
+ .write_with_attrs = iotkit_secctl_s_write,
465
+ .endianness = DEVICE_LITTLE_ENDIAN,
466
+ .valid.min_access_size = 1,
467
+ .valid.max_access_size = 4,
468
+ .impl.min_access_size = 1,
469
+ .impl.max_access_size = 4,
470
+};
471
+
472
+static const MemoryRegionOps iotkit_secctl_ns_ops = {
473
+ .read_with_attrs = iotkit_secctl_ns_read,
474
+ .write_with_attrs = iotkit_secctl_ns_write,
475
+ .endianness = DEVICE_LITTLE_ENDIAN,
476
+ .valid.min_access_size = 1,
477
+ .valid.max_access_size = 4,
478
+ .impl.min_access_size = 1,
479
+ .impl.max_access_size = 4,
480
+};
481
+
482
+static void iotkit_secctl_reset(DeviceState *dev)
483
+{
484
+
485
+}
486
+
487
+static void iotkit_secctl_init(Object *obj)
488
+{
489
+ IoTKitSecCtl *s = IOTKIT_SECCTL(obj);
490
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
491
+
492
+ memory_region_init_io(&s->s_regs, obj, &iotkit_secctl_s_ops,
493
+ s, "iotkit-secctl-s-regs", 0x1000);
494
+ memory_region_init_io(&s->ns_regs, obj, &iotkit_secctl_ns_ops,
495
+ s, "iotkit-secctl-ns-regs", 0x1000);
496
+ sysbus_init_mmio(sbd, &s->s_regs);
497
+ sysbus_init_mmio(sbd, &s->ns_regs);
498
+}
499
+
500
+static const VMStateDescription iotkit_secctl_vmstate = {
501
+ .name = "iotkit-secctl",
502
+ .version_id = 1,
503
+ .minimum_version_id = 1,
504
+ .fields = (VMStateField[]) {
325
+ .fields = (VMStateField[]) {
505
+ VMSTATE_END_OF_LIST()
326
+ VMSTATE_UINT32_ARRAY(regs, NPCM7xxCLKState, NPCM7XX_CLK_NR_REGS),
506
+ }
327
+ VMSTATE_INT64(ref_ns, NPCM7xxCLKState),
507
+};
328
+ VMSTATE_END_OF_LIST(),
508
+
329
+ },
509
+static void iotkit_secctl_class_init(ObjectClass *klass, void *data)
330
+};
510
+{
331
+
332
+static void npcm7xx_clk_class_init(ObjectClass *klass, void *data)
333
+{
334
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
511
+ DeviceClass *dc = DEVICE_CLASS(klass);
335
+ DeviceClass *dc = DEVICE_CLASS(klass);
512
+
336
+
513
+ dc->vmsd = &iotkit_secctl_vmstate;
337
+ QEMU_BUILD_BUG_ON(NPCM7XX_CLK_REGS_END > NPCM7XX_CLK_NR_REGS);
514
+ dc->reset = iotkit_secctl_reset;
338
+
515
+}
339
+ dc->desc = "NPCM7xx Clock Control Registers";
516
+
340
+ dc->vmsd = &vmstate_npcm7xx_clk;
517
+static const TypeInfo iotkit_secctl_info = {
341
+ rc->phases.enter = npcm7xx_clk_enter_reset;
518
+ .name = TYPE_IOTKIT_SECCTL,
342
+}
519
+ .parent = TYPE_SYS_BUS_DEVICE,
343
+
520
+ .instance_size = sizeof(IoTKitSecCtl),
344
+static const TypeInfo npcm7xx_clk_info = {
521
+ .instance_init = iotkit_secctl_init,
345
+ .name = TYPE_NPCM7XX_CLK,
522
+ .class_init = iotkit_secctl_class_init,
346
+ .parent = TYPE_SYS_BUS_DEVICE,
523
+};
347
+ .instance_size = sizeof(NPCM7xxCLKState),
524
+
348
+ .instance_init = npcm7xx_clk_init,
525
+static void iotkit_secctl_register_types(void)
349
+ .class_init = npcm7xx_clk_class_init,
526
+{
350
+};
527
+ type_register_static(&iotkit_secctl_info);
351
+
528
+}
352
+static void npcm7xx_clk_register_type(void)
529
+
353
+{
530
+type_init(iotkit_secctl_register_types);
354
+ type_register_static(&npcm7xx_clk_info);
531
diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
355
+}
356
+type_init(npcm7xx_clk_register_type);
357
diff --git a/hw/misc/meson.build b/hw/misc/meson.build
532
index XXXXXXX..XXXXXXX 100644
358
index XXXXXXX..XXXXXXX 100644
533
--- a/default-configs/arm-softmmu.mak
359
--- a/hw/misc/meson.build
534
+++ b/default-configs/arm-softmmu.mak
360
+++ b/hw/misc/meson.build
535
@@ -XXX,XX +XXX,XX @@ CONFIG_MPS2_FPGAIO=y
361
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_IMX', if_true: files(
536
CONFIG_MPS2_SCC=y
362
softmmu_ss.add(when: 'CONFIG_MILKYMIST', if_true: files('milkymist-hpdmc.c', 'milkymist-pfpu.c'))
537
363
softmmu_ss.add(when: 'CONFIG_MAINSTONE', if_true: files('mst_fpga.c'))
538
CONFIG_TZ_PPC=y
364
softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files(
539
+CONFIG_IOTKIT_SECCTL=y
365
+ 'npcm7xx_clk.c',
540
366
'npcm7xx_gcr.c',
541
CONFIG_VERSATILE_PCI=y
367
))
542
CONFIG_VERSATILE_I2C=y
368
softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files(
543
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
369
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
544
index XXXXXXX..XXXXXXX 100644
370
index XXXXXXX..XXXXXXX 100644
545
--- a/hw/misc/trace-events
371
--- a/hw/misc/trace-events
546
+++ b/hw/misc/trace-events
372
+++ b/hw/misc/trace-events
547
@@ -XXX,XX +XXX,XX @@ tz_ppc_irq_clear(int level) "TZ PPC: int_clear = %d"
373
@@ -XXX,XX +XXX,XX @@ mos6522_set_sr_int(void) "set sr_int"
548
tz_ppc_update_irq(int level) "TZ PPC: setting irq line to %d"
374
mos6522_write(uint64_t addr, uint64_t val) "reg=0x%"PRIx64 " val=0x%"PRIx64
549
tz_ppc_read_blocked(int n, hwaddr offset, bool secure, bool user) "TZ PPC: port %d offset 0x%" HWADDR_PRIx " read (secure %d user %d) blocked"
375
mos6522_read(uint64_t addr, unsigned val) "reg=0x%"PRIx64 " val=0x%x"
550
tz_ppc_write_blocked(int n, hwaddr offset, bool secure, bool user) "TZ PPC: port %d offset 0x%" HWADDR_PRIx " write (secure %d user %d) blocked"
376
551
+
377
+# npcm7xx_clk.c
552
+# hw/misc/iotkit-secctl.c
378
+npcm7xx_clk_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
553
+iotkit_secctl_s_read(uint32_t offset, uint64_t data, unsigned size) "IoTKit SecCtl S regs read: offset 0x%x data 0x%" PRIx64 " size %u"
379
+npcm7xx_clk_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
554
+iotkit_secctl_s_write(uint32_t offset, uint64_t data, unsigned size) "IoTKit SecCtl S regs write: offset 0x%x data 0x%" PRIx64 " size %u"
380
+
555
+iotkit_secctl_ns_read(uint32_t offset, uint64_t data, unsigned size) "IoTKit SecCtl NS regs read: offset 0x%x data 0x%" PRIx64 " size %u"
381
# npcm7xx_gcr.c
556
+iotkit_secctl_ns_write(uint32_t offset, uint64_t data, unsigned size) "IoTKit SecCtl NS regs write: offset 0x%x data 0x%" PRIx64 " size %u"
382
npcm7xx_gcr_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
557
+iotkit_secctl_reset(void) "IoTKit SecCtl: reset"
383
npcm7xx_gcr_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
558
--
384
--
559
2.16.2
385
2.20.1
560
386
561
387
diff view generated by jsdifflib
1
Add a model of the TrustZone peripheral protection controller (PPC),
1
From: Havard Skinnemoen <hskinnemoen@google.com>
2
which is used to gate transactions to non-TZ-aware peripherals so
3
that secure software can configure them to not be accessible to
4
non-secure software.
5
2
3
The NPCM730 and NPCM750 SoCs have three timer modules each holding five
4
timers and some shared registers (e.g. interrupt status).
5
6
Each timer runs at 25 MHz divided by a prescaler, and counts down from a
7
configurable initial value to zero. When zero is reached, the interrupt
8
flag for the timer is set, and the timer is disabled (one-shot mode) or
9
reloaded from its initial value (periodic mode).
10
11
This implementation is sufficient to boot a Linux kernel configured for
12
NPCM750. Note that the kernel does not seem to actually turn on the
13
interrupts.
14
15
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
16
Reviewed-by: Joel Stanley <joel@jms.id.au>
17
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
18
Tested-by: Alexander Bulekov <alxndr@bu.edu>
19
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
20
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
21
Message-id: 20200911052101.2602693-4-hskinnemoen@google.com
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
22
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20180220180325.29818-15-peter.maydell@linaro.org
9
---
23
---
10
hw/misc/Makefile.objs | 2 +
24
include/hw/timer/npcm7xx_timer.h | 78 +++++
11
include/hw/misc/tz-ppc.h | 101 ++++++++++++++
25
hw/timer/npcm7xx_timer.c | 543 +++++++++++++++++++++++++++++++
12
hw/misc/tz-ppc.c | 302 ++++++++++++++++++++++++++++++++++++++++
26
hw/timer/meson.build | 1 +
13
default-configs/arm-softmmu.mak | 2 +
27
hw/timer/trace-events | 5 +
14
hw/misc/trace-events | 11 ++
28
4 files changed, 627 insertions(+)
15
5 files changed, 418 insertions(+)
29
create mode 100644 include/hw/timer/npcm7xx_timer.h
16
create mode 100644 include/hw/misc/tz-ppc.h
30
create mode 100644 hw/timer/npcm7xx_timer.c
17
create mode 100644 hw/misc/tz-ppc.c
18
31
19
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
32
diff --git a/include/hw/timer/npcm7xx_timer.h b/include/hw/timer/npcm7xx_timer.h
20
index XXXXXXX..XXXXXXX 100644
21
--- a/hw/misc/Makefile.objs
22
+++ b/hw/misc/Makefile.objs
23
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_MIPS_ITU) += mips_itu.o
24
obj-$(CONFIG_MPS2_FPGAIO) += mps2-fpgaio.o
25
obj-$(CONFIG_MPS2_SCC) += mps2-scc.o
26
27
+obj-$(CONFIG_TZ_PPC) += tz-ppc.o
28
+
29
obj-$(CONFIG_PVPANIC) += pvpanic.o
30
obj-$(CONFIG_HYPERV_TESTDEV) += hyperv_testdev.o
31
obj-$(CONFIG_AUX) += auxbus.o
32
diff --git a/include/hw/misc/tz-ppc.h b/include/hw/misc/tz-ppc.h
33
new file mode 100644
33
new file mode 100644
34
index XXXXXXX..XXXXXXX
34
index XXXXXXX..XXXXXXX
35
--- /dev/null
35
--- /dev/null
36
+++ b/include/hw/misc/tz-ppc.h
36
+++ b/include/hw/timer/npcm7xx_timer.h
37
@@ -XXX,XX +XXX,XX @@
37
@@ -XXX,XX +XXX,XX @@
38
+/*
38
+/*
39
+ * ARM TrustZone peripheral protection controller emulation
39
+ * Nuvoton NPCM7xx Timer Controller
40
+ *
40
+ *
41
+ * Copyright (c) 2018 Linaro Limited
41
+ * Copyright 2020 Google LLC
42
+ * Written by Peter Maydell
43
+ *
42
+ *
44
+ * This program is free software; you can redistribute it and/or modify
43
+ * This program is free software; you can redistribute it and/or modify it
45
+ * it under the terms of the GNU General Public License version 2 or
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.
46
+ * (at your option) any later version.
47
+ */
48
+
49
+/* This is a model of the TrustZone peripheral protection controller (PPC).
50
+ * It is documented in the ARM CoreLink SIE-200 System IP for Embedded TRM
51
+ * (DDI 0571G):
52
+ * https://developer.arm.com/products/architecture/m-profile/docs/ddi0571/g
53
+ *
47
+ *
54
+ * The PPC sits in front of peripherals and allows secure software to
48
+ * This program is distributed in the hope that it will be useful, but WITHOUT
55
+ * configure it to either pass through or reject transactions.
49
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
56
+ * Rejected transactions may be configured to either be aborted, or to
50
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
57
+ * behave as RAZ/WI. An interrupt can be signalled for a rejected transaction.
51
+ * for more details.
58
+ *
52
+ */
59
+ * The PPC has no register interface -- it is configured purely by a
53
+#ifndef NPCM7XX_TIMER_H
60
+ * collection of input signals from other hardware in the system. Typically
54
+#define NPCM7XX_TIMER_H
61
+ * they are either hardwired or exposed in an ad-hoc register interface by
55
+
62
+ * the SoC that uses the PPC.
56
+#include "exec/memory.h"
63
+ *
64
+ * This QEMU model can be used to model either the AHB5 or APB4 TZ PPC,
65
+ * since the only difference between them is that the AHB version has a
66
+ * "default" port which has no security checks applied. In QEMU the default
67
+ * port can be emulated simply by wiring its downstream devices directly
68
+ * into the parent address space, since the PPC does not need to intercept
69
+ * transactions there.
70
+ *
71
+ * In the hardware, selection of which downstream port to use is done by
72
+ * the user's decode logic asserting one of the hsel[] signals. In QEMU,
73
+ * we provide 16 MMIO regions, one per port, and the user maps these into
74
+ * the desired addresses to implement the address decode.
75
+ *
76
+ * QEMU interface:
77
+ * + sysbus MMIO regions 0..15: MemoryRegions defining the upstream end
78
+ * of each of the 16 ports of the PPC
79
+ * + Property "port[0..15]": MemoryRegion defining the downstream device(s)
80
+ * for each of the 16 ports of the PPC
81
+ * + Named GPIO inputs "cfg_nonsec[0..15]": set to 1 if the port should be
82
+ * accessible to NonSecure transactions
83
+ * + Named GPIO inputs "cfg_ap[0..15]": set to 1 if the port should be
84
+ * accessible to non-privileged transactions
85
+ * + Named GPIO input "cfg_sec_resp": set to 1 if a rejected transaction should
86
+ * result in a transaction error, or 0 for the transaction to RAZ/WI
87
+ * + Named GPIO input "irq_enable": set to 1 to enable interrupts
88
+ * + Named GPIO input "irq_clear": set to 1 to clear a pending interrupt
89
+ * + Named GPIO output "irq": set for a transaction-failed interrupt
90
+ * + Property "NONSEC_MASK": if a bit is set in this mask then accesses to
91
+ * the associated port do not have the TZ security check performed. (This
92
+ * corresponds to the hardware allowing this to be set as a Verilog
93
+ * parameter.)
94
+ */
95
+
96
+#ifndef TZ_PPC_H
97
+#define TZ_PPC_H
98
+
99
+#include "hw/sysbus.h"
57
+#include "hw/sysbus.h"
100
+
58
+#include "qemu/timer.h"
101
+#define TYPE_TZ_PPC "tz-ppc"
59
+
102
+#define TZ_PPC(obj) OBJECT_CHECK(TZPPC, (obj), TYPE_TZ_PPC)
60
+/* Each Timer Module (TIM) instance holds five 25 MHz timers. */
103
+
61
+#define NPCM7XX_TIMERS_PER_CTRL (5)
104
+#define TZ_NUM_PORTS 16
62
+
105
+
63
+/*
106
+typedef struct TZPPC TZPPC;
64
+ * Number of registers in our device state structure. Don't change this without
107
+
65
+ * incrementing the version_id in the vmstate.
108
+typedef struct TZPPCPort {
66
+ */
109
+ TZPPC *ppc;
67
+#define NPCM7XX_TIMER_NR_REGS (0x54 / sizeof(uint32_t))
110
+ MemoryRegion upstream;
68
+
111
+ AddressSpace downstream_as;
69
+typedef struct NPCM7xxTimerCtrlState NPCM7xxTimerCtrlState;
112
+ MemoryRegion *downstream;
70
+
113
+} TZPPCPort;
71
+/**
114
+
72
+ * struct NPCM7xxTimer - Individual timer state.
115
+struct TZPPC {
73
+ * @irq: GIC interrupt line to fire on expiration (if enabled).
116
+ /*< private >*/
74
+ * @qtimer: QEMU timer that notifies us on expiration.
117
+ SysBusDevice parent_obj;
75
+ * @expires_ns: Absolute virtual expiration time.
118
+
76
+ * @remaining_ns: Remaining time until expiration if timer is paused.
119
+ /*< public >*/
77
+ * @tcsr: The Timer Control and Status Register.
120
+
78
+ * @ticr: The Timer Initial Count Register.
121
+ /* State: these just track the values of our input signals */
79
+ */
122
+ bool cfg_nonsec[TZ_NUM_PORTS];
80
+typedef struct NPCM7xxTimer {
123
+ bool cfg_ap[TZ_NUM_PORTS];
81
+ NPCM7xxTimerCtrlState *ctrl;
124
+ bool cfg_sec_resp;
82
+
125
+ bool irq_enable;
83
+ qemu_irq irq;
126
+ bool irq_clear;
84
+ QEMUTimer qtimer;
127
+ /* State: are we asserting irq ? */
85
+ int64_t expires_ns;
128
+ bool irq_status;
86
+ int64_t remaining_ns;
129
+
87
+
130
+ qemu_irq irq;
88
+ uint32_t tcsr;
131
+
89
+ uint32_t ticr;
132
+ /* Properties */
90
+} NPCM7xxTimer;
133
+ uint32_t nonsec_mask;
91
+
134
+
92
+/**
135
+ TZPPCPort port[TZ_NUM_PORTS];
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];
136
+};
109
+};
137
+
110
+
138
+#endif
111
+#define TYPE_NPCM7XX_TIMER "npcm7xx-timer"
139
diff --git a/hw/misc/tz-ppc.c b/hw/misc/tz-ppc.c
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
140
new file mode 100644
117
new file mode 100644
141
index XXXXXXX..XXXXXXX
118
index XXXXXXX..XXXXXXX
142
--- /dev/null
119
--- /dev/null
143
+++ b/hw/misc/tz-ppc.c
120
+++ b/hw/timer/npcm7xx_timer.c
144
@@ -XXX,XX +XXX,XX @@
121
@@ -XXX,XX +XXX,XX @@
145
+/*
122
+/*
146
+ * ARM TrustZone peripheral protection controller emulation
123
+ * Nuvoton NPCM7xx Timer Controller
147
+ *
124
+ *
148
+ * Copyright (c) 2018 Linaro Limited
125
+ * Copyright 2020 Google LLC
149
+ * Written by Peter Maydell
150
+ *
126
+ *
151
+ * This program is free software; you can redistribute it and/or modify
127
+ * This program is free software; you can redistribute it and/or modify it
152
+ * it under the terms of the GNU General Public License version 2 or
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
153
+ * (at your option) any later version.
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.
154
+ */
136
+ */
155
+
137
+
156
+#include "qemu/osdep.h"
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"
157
+#include "qemu/log.h"
146
+#include "qemu/log.h"
158
+#include "qapi/error.h"
147
+#include "qemu/module.h"
148
+#include "qemu/timer.h"
149
+#include "qemu/units.h"
159
+#include "trace.h"
150
+#include "trace.h"
160
+#include "hw/sysbus.h"
151
+
161
+#include "hw/registerfields.h"
152
+/* 32-bit register indices. */
162
+#include "hw/misc/tz-ppc.h"
153
+enum NPCM7xxTimerRegisters {
163
+
154
+ NPCM7XX_TIMER_TCSR0,
164
+static void tz_ppc_update_irq(TZPPC *s)
155
+ NPCM7XX_TIMER_TCSR1,
165
+{
156
+ NPCM7XX_TIMER_TICR0,
166
+ bool level = s->irq_status && s->irq_enable;
157
+ NPCM7XX_TIMER_TICR1,
167
+
158
+ NPCM7XX_TIMER_TDR0,
168
+ trace_tz_ppc_update_irq(level);
159
+ NPCM7XX_TIMER_TDR1,
169
+ qemu_set_irq(s->irq, level);
160
+ NPCM7XX_TIMER_TISR,
170
+}
161
+ NPCM7XX_TIMER_WTCR,
171
+
162
+ NPCM7XX_TIMER_TCSR2,
172
+static void tz_ppc_cfg_nonsec(void *opaque, int n, int level)
163
+ NPCM7XX_TIMER_TCSR3,
173
+{
164
+ NPCM7XX_TIMER_TICR2,
174
+ TZPPC *s = TZ_PPC(opaque);
165
+ NPCM7XX_TIMER_TICR3,
175
+
166
+ NPCM7XX_TIMER_TDR2,
176
+ assert(n < TZ_NUM_PORTS);
167
+ NPCM7XX_TIMER_TDR3,
177
+ trace_tz_ppc_cfg_nonsec(n, level);
168
+ NPCM7XX_TIMER_TCSR4 = 0x0040 / sizeof(uint32_t),
178
+ s->cfg_nonsec[n] = level;
169
+ NPCM7XX_TIMER_TICR4 = 0x0048 / sizeof(uint32_t),
179
+}
170
+ NPCM7XX_TIMER_TDR4 = 0x0050 / sizeof(uint32_t),
180
+
171
+ NPCM7XX_TIMER_REGS_END,
181
+static void tz_ppc_cfg_ap(void *opaque, int n, int level)
172
+};
182
+{
173
+
183
+ TZPPC *s = TZ_PPC(opaque);
174
+/* Register field definitions. */
184
+
175
+#define NPCM7XX_TCSR_CEN BIT(30)
185
+ assert(n < TZ_NUM_PORTS);
176
+#define NPCM7XX_TCSR_IE BIT(29)
186
+ trace_tz_ppc_cfg_ap(n, level);
177
+#define NPCM7XX_TCSR_PERIODIC BIT(27)
187
+ s->cfg_ap[n] = level;
178
+#define NPCM7XX_TCSR_CRST BIT(26)
188
+}
179
+#define NPCM7XX_TCSR_CACT BIT(25)
189
+
180
+#define NPCM7XX_TCSR_RSVD 0x01ffff00
190
+static void tz_ppc_cfg_sec_resp(void *opaque, int n, int level)
181
+#define NPCM7XX_TCSR_PRESCALE_START 0
191
+{
182
+#define NPCM7XX_TCSR_PRESCALE_LEN 8
192
+ TZPPC *s = TZ_PPC(opaque);
183
+
193
+
184
+/*
194
+ trace_tz_ppc_cfg_sec_resp(level);
185
+ * Returns the index of timer in the tc->timer array. This can be used to
195
+ s->cfg_sec_resp = level;
186
+ * locate the registers that belong to this timer.
196
+}
187
+ */
197
+
188
+static int npcm7xx_timer_index(NPCM7xxTimerCtrlState *tc, NPCM7xxTimer *timer)
198
+static void tz_ppc_irq_enable(void *opaque, int n, int level)
189
+{
199
+{
190
+ int index = timer - tc->timer;
200
+ TZPPC *s = TZ_PPC(opaque);
191
+
201
+
192
+ g_assert(index >= 0 && index < NPCM7XX_TIMERS_PER_CTRL);
202
+ trace_tz_ppc_irq_enable(level);
193
+
203
+ s->irq_enable = level;
194
+ return index;
204
+ tz_ppc_update_irq(s);
195
+}
205
+}
196
+
206
+
197
+/* Return the value by which to divide the reference clock rate. */
207
+static void tz_ppc_irq_clear(void *opaque, int n, int level)
198
+static uint32_t npcm7xx_tcsr_prescaler(uint32_t tcsr)
208
+{
199
+{
209
+ TZPPC *s = TZ_PPC(opaque);
200
+ return extract32(tcsr, NPCM7XX_TCSR_PRESCALE_START,
210
+
201
+ NPCM7XX_TCSR_PRESCALE_LEN) + 1;
211
+ trace_tz_ppc_irq_clear(level);
202
+}
212
+
203
+
213
+ s->irq_clear = level;
204
+/* Convert a timer cycle count to a time interval in nanoseconds. */
214
+ if (level) {
205
+static int64_t npcm7xx_timer_count_to_ns(NPCM7xxTimer *t, uint32_t count)
215
+ s->irq_status = false;
206
+{
216
+ tz_ppc_update_irq(s);
207
+ int64_t ns = count;
217
+ }
208
+
218
+}
209
+ ns *= NANOSECONDS_PER_SECOND / NPCM7XX_TIMER_REF_HZ;
219
+
210
+ ns *= npcm7xx_tcsr_prescaler(t->tcsr);
220
+static bool tz_ppc_check(TZPPC *s, int n, MemTxAttrs attrs)
211
+
221
+{
212
+ return ns;
222
+ /* Check whether to allow an access to port n; return true if
213
+}
223
+ * the check passes, and false if the transaction must be blocked.
214
+
224
+ * If the latter, the caller must check cfg_sec_resp to determine
215
+/* Convert a time interval in nanoseconds to a timer cycle count. */
225
+ * whether to abort or RAZ/WI the transaction.
216
+static uint32_t npcm7xx_timer_ns_to_count(NPCM7xxTimer *t, int64_t ns)
226
+ * The checks are:
217
+{
227
+ * + nonsec_mask suppresses any check of the secure attribute
218
+ int64_t count;
228
+ * + otherwise, block if cfg_nonsec is 1 and transaction is secure,
219
+
229
+ * or if cfg_nonsec is 0 and transaction is non-secure
220
+ count = ns / (NANOSECONDS_PER_SECOND / NPCM7XX_TIMER_REF_HZ);
230
+ * + block if transaction is usermode and cfg_ap is 0
221
+ count /= npcm7xx_tcsr_prescaler(t->tcsr);
231
+ */
222
+
232
+ if ((attrs.secure == s->cfg_nonsec[n] && !(s->nonsec_mask & (1 << n))) ||
223
+ return count;
233
+ (attrs.user && !s->cfg_ap[n])) {
224
+}
234
+ /* Block the transaction. */
225
+
235
+ if (!s->irq_clear) {
226
+/*
236
+ /* Note that holding irq_clear high suppresses interrupts */
227
+ * Raise the interrupt line if there's a pending interrupt and interrupts are
237
+ s->irq_status = true;
228
+ * enabled for this timer. If not, lower it.
238
+ tz_ppc_update_irq(s);
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);
239
+ }
265
+ }
240
+ return false;
266
+ } else {
241
+ }
267
+ t->tcsr &= ~(NPCM7XX_TCSR_CEN | NPCM7XX_TCSR_CACT);
242
+ return true;
268
+ }
243
+}
269
+
244
+
270
+ npcm7xx_timer_check_interrupt(t);
245
+static MemTxResult tz_ppc_read(void *opaque, hwaddr addr, uint64_t *pdata,
271
+}
246
+ unsigned size, MemTxAttrs attrs)
272
+
247
+{
273
+/* Stop counting. Record the time remaining so we can continue later. */
248
+ TZPPCPort *p = opaque;
274
+static void npcm7xx_timer_pause(NPCM7xxTimer *t)
249
+ TZPPC *s = p->ppc;
275
+{
250
+ int n = p - s->port;
276
+ int64_t now;
251
+ AddressSpace *as = &p->downstream_as;
277
+
252
+ uint64_t data;
278
+ timer_del(&t->qtimer);
253
+ MemTxResult res;
279
+ now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
254
+
280
+ t->remaining_ns = t->expires_ns - now;
255
+ if (!tz_ppc_check(s, n, attrs)) {
281
+ if (t->remaining_ns <= 0) {
256
+ trace_tz_ppc_read_blocked(n, addr, attrs.secure, attrs.user);
282
+ npcm7xx_timer_reached_zero(t);
257
+ if (s->cfg_sec_resp) {
283
+ }
258
+ return MEMTX_ERROR;
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);
259
+ } else {
360
+ } else {
260
+ *pdata = 0;
361
+ t->tcsr &= ~NPCM7XX_TCSR_CACT;
261
+ return MEMTX_OK;
362
+ npcm7xx_timer_pause(t);
262
+ }
363
+ }
263
+ }
364
+ }
264
+
365
+}
265
+ switch (size) {
366
+
266
+ case 1:
367
+static void npcm7xx_timer_write_ticr(NPCM7xxTimer *t, uint32_t new_ticr)
267
+ data = address_space_ldub(as, addr, attrs, &res);
368
+{
268
+ break;
369
+ t->ticr = new_ticr;
269
+ case 2:
370
+
270
+ data = address_space_lduw_le(as, addr, attrs, &res);
371
+ npcm7xx_timer_restart(t, t->tcsr);
271
+ break;
372
+}
272
+ case 4:
373
+
273
+ data = address_space_ldl_le(as, addr, attrs, &res);
374
+static void npcm7xx_timer_write_tisr(NPCM7xxTimerCtrlState *s, uint32_t value)
274
+ break;
375
+{
275
+ case 8:
376
+ int i;
276
+ data = address_space_ldq_le(as, addr, attrs, &res);
377
+
277
+ break;
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;
278
+ default:
399
+ default:
279
+ g_assert_not_reached();
400
+ g_assert_not_reached();
280
+ }
401
+ }
281
+ *pdata = data;
402
+}
282
+ return res;
403
+
283
+}
404
+static hwaddr npcm7xx_ticr_index(hwaddr reg)
284
+
405
+{
285
+static MemTxResult tz_ppc_write(void *opaque, hwaddr addr, uint64_t val,
406
+ switch (reg) {
286
+ unsigned size, MemTxAttrs attrs)
407
+ case NPCM7XX_TIMER_TICR0:
287
+{
408
+ return 0;
288
+ TZPPCPort *p = opaque;
409
+ case NPCM7XX_TIMER_TICR1:
289
+ TZPPC *s = p->ppc;
410
+ return 1;
290
+ AddressSpace *as = &p->downstream_as;
411
+ case NPCM7XX_TIMER_TICR2:
291
+ int n = p - s->port;
412
+ return 2;
292
+ MemTxResult res;
413
+ case NPCM7XX_TIMER_TICR3:
293
+
414
+ return 3;
294
+ if (!tz_ppc_check(s, n, attrs)) {
415
+ case NPCM7XX_TIMER_TICR4:
295
+ trace_tz_ppc_write_blocked(n, addr, attrs.secure, attrs.user);
416
+ return 4;
296
+ if (s->cfg_sec_resp) {
297
+ return MEMTX_ERROR;
298
+ } else {
299
+ return MEMTX_OK;
300
+ }
301
+ }
302
+
303
+ switch (size) {
304
+ case 1:
305
+ address_space_stb(as, addr, val, attrs, &res);
306
+ break;
307
+ case 2:
308
+ address_space_stw_le(as, addr, val, attrs, &res);
309
+ break;
310
+ case 4:
311
+ address_space_stl_le(as, addr, val, attrs, &res);
312
+ break;
313
+ case 8:
314
+ address_space_stq_le(as, addr, val, attrs, &res);
315
+ break;
316
+ default:
417
+ default:
317
+ g_assert_not_reached();
418
+ g_assert_not_reached();
318
+ }
419
+ }
319
+ return res;
420
+}
320
+}
421
+
321
+
422
+static hwaddr npcm7xx_tdr_index(hwaddr reg)
322
+static const MemoryRegionOps tz_ppc_ops = {
423
+{
323
+ .read_with_attrs = tz_ppc_read,
424
+ switch (reg) {
324
+ .write_with_attrs = tz_ppc_write,
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;
485
+ }
486
+
487
+ trace_npcm7xx_timer_read(DEVICE(s)->canonical_path, offset, value);
488
+
489
+ return value;
490
+}
491
+
492
+static void npcm7xx_timer_write(void *opaque, hwaddr offset,
493
+ uint64_t v, unsigned size)
494
+{
495
+ uint32_t reg = offset / sizeof(uint32_t);
496
+ NPCM7xxTimerCtrlState *s = opaque;
497
+ uint32_t value = v;
498
+
499
+ trace_npcm7xx_timer_write(DEVICE(s)->canonical_path, offset, value);
500
+
501
+ switch (reg) {
502
+ case NPCM7XX_TIMER_TCSR0:
503
+ case NPCM7XX_TIMER_TCSR1:
504
+ case NPCM7XX_TIMER_TCSR2:
505
+ case NPCM7XX_TIMER_TCSR3:
506
+ case NPCM7XX_TIMER_TCSR4:
507
+ npcm7xx_timer_write_tcsr(&s->timer[npcm7xx_tcsr_index(reg)], value);
508
+ return;
509
+
510
+ case NPCM7XX_TIMER_TICR0:
511
+ case NPCM7XX_TIMER_TICR1:
512
+ case NPCM7XX_TIMER_TICR2:
513
+ case NPCM7XX_TIMER_TICR3:
514
+ case NPCM7XX_TIMER_TICR4:
515
+ npcm7xx_timer_write_ticr(&s->timer[npcm7xx_ticr_index(reg)], value);
516
+ return;
517
+
518
+ case NPCM7XX_TIMER_TDR0:
519
+ case NPCM7XX_TIMER_TDR1:
520
+ case NPCM7XX_TIMER_TDR2:
521
+ case NPCM7XX_TIMER_TDR3:
522
+ case NPCM7XX_TIMER_TDR4:
523
+ qemu_log_mask(LOG_GUEST_ERROR,
524
+ "%s: register @ 0x%04" HWADDR_PRIx " is read-only\n",
525
+ __func__, offset);
526
+ return;
527
+
528
+ case NPCM7XX_TIMER_TISR:
529
+ npcm7xx_timer_write_tisr(s, value);
530
+ return;
531
+
532
+ case NPCM7XX_TIMER_WTCR:
533
+ qemu_log_mask(LOG_UNIMP, "%s: WTCR write not implemented: 0x%08x\n",
534
+ __func__, value);
535
+ return;
536
+ }
537
+
538
+ qemu_log_mask(LOG_GUEST_ERROR,
539
+ "%s: invalid offset 0x%04" HWADDR_PRIx "\n",
540
+ __func__, offset);
541
+}
542
+
543
+static const struct MemoryRegionOps npcm7xx_timer_ops = {
544
+ .read = npcm7xx_timer_read,
545
+ .write = npcm7xx_timer_write,
325
+ .endianness = DEVICE_LITTLE_ENDIAN,
546
+ .endianness = DEVICE_LITTLE_ENDIAN,
547
+ .valid = {
548
+ .min_access_size = 4,
549
+ .max_access_size = 4,
550
+ .unaligned = false,
551
+ },
326
+};
552
+};
327
+
553
+
328
+static void tz_ppc_reset(DeviceState *dev)
554
+/* Called when the QEMU timer expires. */
329
+{
555
+static void npcm7xx_timer_expired(void *opaque)
330
+ TZPPC *s = TZ_PPC(dev);
556
+{
331
+
557
+ NPCM7xxTimer *t = opaque;
332
+ trace_tz_ppc_reset();
558
+
333
+ s->cfg_sec_resp = false;
559
+ if (t->tcsr & NPCM7XX_TCSR_CEN) {
334
+ memset(s->cfg_nonsec, 0, sizeof(s->cfg_nonsec));
560
+ npcm7xx_timer_reached_zero(t);
335
+ memset(s->cfg_ap, 0, sizeof(s->cfg_ap));
561
+ }
336
+}
562
+}
337
+
563
+
338
+static void tz_ppc_init(Object *obj)
564
+static void npcm7xx_timer_enter_reset(Object *obj, ResetType type)
339
+{
565
+{
340
+ DeviceState *dev = DEVICE(obj);
566
+ NPCM7xxTimerCtrlState *s = NPCM7XX_TIMER(obj);
341
+ TZPPC *s = TZ_PPC(obj);
342
+
343
+ qdev_init_gpio_in_named(dev, tz_ppc_cfg_nonsec, "cfg_nonsec", TZ_NUM_PORTS);
344
+ qdev_init_gpio_in_named(dev, tz_ppc_cfg_ap, "cfg_ap", TZ_NUM_PORTS);
345
+ qdev_init_gpio_in_named(dev, tz_ppc_cfg_sec_resp, "cfg_sec_resp", 1);
346
+ qdev_init_gpio_in_named(dev, tz_ppc_irq_enable, "irq_enable", 1);
347
+ qdev_init_gpio_in_named(dev, tz_ppc_irq_clear, "irq_clear", 1);
348
+ qdev_init_gpio_out_named(dev, &s->irq, "irq", 1);
349
+}
350
+
351
+static void tz_ppc_realize(DeviceState *dev, Error **errp)
352
+{
353
+ Object *obj = OBJECT(dev);
354
+ SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
355
+ TZPPC *s = TZ_PPC(dev);
356
+ int i;
567
+ int i;
357
+
568
+
358
+ /* We can't create the upstream end of the port until realize,
569
+ for (i = 0; i < NPCM7XX_TIMERS_PER_CTRL; i++) {
359
+ * as we don't know the size of the MR used as the downstream until then.
570
+ NPCM7xxTimer *t = &s->timer[i];
360
+ */
571
+
361
+ for (i = 0; i < TZ_NUM_PORTS; i++) {
572
+ timer_del(&t->qtimer);
362
+ TZPPCPort *port = &s->port[i];
573
+ t->expires_ns = 0;
363
+ char *name;
574
+ t->remaining_ns = 0;
364
+ uint64_t size;
575
+ t->tcsr = 0x00000005;
365
+
576
+ t->ticr = 0x00000000;
366
+ if (!port->downstream) {
577
+ }
367
+ continue;
578
+
368
+ }
579
+ s->tisr = 0x00000000;
369
+
580
+ s->wtcr = 0x00000400;
370
+ name = g_strdup_printf("tz-ppc-port[%d]", i);
581
+}
371
+
582
+
372
+ port->ppc = s;
583
+static void npcm7xx_timer_hold_reset(Object *obj)
373
+ address_space_init(&port->downstream_as, port->downstream, name);
584
+{
374
+
585
+ NPCM7xxTimerCtrlState *s = NPCM7XX_TIMER(obj);
375
+ size = memory_region_size(port->downstream);
586
+ int i;
376
+ memory_region_init_io(&port->upstream, obj, &tz_ppc_ops,
587
+
377
+ port, name, size);
588
+ for (i = 0; i < NPCM7XX_TIMERS_PER_CTRL; i++) {
378
+ sysbus_init_mmio(sbd, &port->upstream);
589
+ qemu_irq_lower(s->timer[i].irq);
379
+ g_free(name);
590
+ }
380
+ }
591
+}
381
+}
592
+
382
+
593
+static void npcm7xx_timer_realize(DeviceState *dev, Error **errp)
383
+static const VMStateDescription tz_ppc_vmstate = {
594
+{
384
+ .name = "tz-ppc",
595
+ NPCM7xxTimerCtrlState *s = NPCM7XX_TIMER(dev);
385
+ .version_id = 1,
596
+ SysBusDevice *sbd = &s->parent;
386
+ .minimum_version_id = 1,
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,
387
+ .fields = (VMStateField[]) {
615
+ .fields = (VMStateField[]) {
388
+ VMSTATE_BOOL_ARRAY(cfg_nonsec, TZPPC, 16),
616
+ VMSTATE_TIMER(qtimer, NPCM7xxTimer),
389
+ VMSTATE_BOOL_ARRAY(cfg_ap, TZPPC, 16),
617
+ VMSTATE_INT64(expires_ns, NPCM7xxTimer),
390
+ VMSTATE_BOOL(cfg_sec_resp, TZPPC),
618
+ VMSTATE_INT64(remaining_ns, NPCM7xxTimer),
391
+ VMSTATE_BOOL(irq_enable, TZPPC),
619
+ VMSTATE_UINT32(tcsr, NPCM7xxTimer),
392
+ VMSTATE_BOOL(irq_clear, TZPPC),
620
+ VMSTATE_UINT32(ticr, NPCM7xxTimer),
393
+ VMSTATE_BOOL(irq_status, TZPPC),
621
+ VMSTATE_END_OF_LIST(),
394
+ VMSTATE_END_OF_LIST()
622
+ },
395
+ }
396
+};
623
+};
397
+
624
+
398
+#define DEFINE_PORT(N) \
625
+static const VMStateDescription vmstate_npcm7xx_timer_ctrl = {
399
+ DEFINE_PROP_LINK("port[" #N "]", TZPPC, port[N].downstream, \
626
+ .name = "npcm7xx-timer-ctrl",
400
+ TYPE_MEMORY_REGION, MemoryRegion *)
627
+ .version_id = 0,
401
+
628
+ .minimum_version_id = 0,
402
+static Property tz_ppc_properties[] = {
629
+ .fields = (VMStateField[]) {
403
+ DEFINE_PROP_UINT32("NONSEC_MASK", TZPPC, nonsec_mask, 0),
630
+ VMSTATE_UINT32(tisr, NPCM7xxTimerCtrlState),
404
+ DEFINE_PORT(0),
631
+ VMSTATE_UINT32(wtcr, NPCM7xxTimerCtrlState),
405
+ DEFINE_PORT(1),
632
+ VMSTATE_STRUCT_ARRAY(timer, NPCM7xxTimerCtrlState,
406
+ DEFINE_PORT(2),
633
+ NPCM7XX_TIMERS_PER_CTRL, 0, vmstate_npcm7xx_timer,
407
+ DEFINE_PORT(3),
634
+ NPCM7xxTimer),
408
+ DEFINE_PORT(4),
635
+ VMSTATE_END_OF_LIST(),
409
+ DEFINE_PORT(5),
636
+ },
410
+ DEFINE_PORT(6),
411
+ DEFINE_PORT(7),
412
+ DEFINE_PORT(8),
413
+ DEFINE_PORT(9),
414
+ DEFINE_PORT(10),
415
+ DEFINE_PORT(11),
416
+ DEFINE_PORT(12),
417
+ DEFINE_PORT(13),
418
+ DEFINE_PORT(14),
419
+ DEFINE_PORT(15),
420
+ DEFINE_PROP_END_OF_LIST(),
421
+};
637
+};
422
+
638
+
423
+static void tz_ppc_class_init(ObjectClass *klass, void *data)
639
+static void npcm7xx_timer_class_init(ObjectClass *klass, void *data)
424
+{
640
+{
641
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
425
+ DeviceClass *dc = DEVICE_CLASS(klass);
642
+ DeviceClass *dc = DEVICE_CLASS(klass);
426
+
643
+
427
+ dc->realize = tz_ppc_realize;
644
+ QEMU_BUILD_BUG_ON(NPCM7XX_TIMER_REGS_END > NPCM7XX_TIMER_NR_REGS);
428
+ dc->vmsd = &tz_ppc_vmstate;
645
+
429
+ dc->reset = tz_ppc_reset;
646
+ dc->desc = "NPCM7xx Timer Controller";
430
+ dc->props = tz_ppc_properties;
647
+ dc->realize = npcm7xx_timer_realize;
431
+}
648
+ dc->vmsd = &vmstate_npcm7xx_timer_ctrl;
432
+
649
+ rc->phases.enter = npcm7xx_timer_enter_reset;
433
+static const TypeInfo tz_ppc_info = {
650
+ rc->phases.hold = npcm7xx_timer_hold_reset;
434
+ .name = TYPE_TZ_PPC,
651
+}
435
+ .parent = TYPE_SYS_BUS_DEVICE,
652
+
436
+ .instance_size = sizeof(TZPPC),
653
+static const TypeInfo npcm7xx_timer_info = {
437
+ .instance_init = tz_ppc_init,
654
+ .name = TYPE_NPCM7XX_TIMER,
438
+ .class_init = tz_ppc_class_init,
655
+ .parent = TYPE_SYS_BUS_DEVICE,
656
+ .instance_size = sizeof(NPCM7xxTimerCtrlState),
657
+ .class_init = npcm7xx_timer_class_init,
439
+};
658
+};
440
+
659
+
441
+static void tz_ppc_register_types(void)
660
+static void npcm7xx_timer_register_type(void)
442
+{
661
+{
443
+ type_register_static(&tz_ppc_info);
662
+ type_register_static(&npcm7xx_timer_info);
444
+}
663
+}
445
+
664
+type_init(npcm7xx_timer_register_type);
446
+type_init(tz_ppc_register_types);
665
diff --git a/hw/timer/meson.build b/hw/timer/meson.build
447
diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
448
index XXXXXXX..XXXXXXX 100644
666
index XXXXXXX..XXXXXXX 100644
449
--- a/default-configs/arm-softmmu.mak
667
--- a/hw/timer/meson.build
450
+++ b/default-configs/arm-softmmu.mak
668
+++ b/hw/timer/meson.build
451
@@ -XXX,XX +XXX,XX @@ CONFIG_CMSDK_APB_UART=y
669
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_LM32', if_true: files('lm32_timer.c'))
452
CONFIG_MPS2_FPGAIO=y
670
softmmu_ss.add(when: 'CONFIG_MILKYMIST', if_true: files('milkymist-sysctl.c'))
453
CONFIG_MPS2_SCC=y
671
softmmu_ss.add(when: 'CONFIG_MIPS_CPS', if_true: files('mips_gictimer.c'))
454
672
softmmu_ss.add(when: 'CONFIG_MSF2', if_true: files('mss-timer.c'))
455
+CONFIG_TZ_PPC=y
673
+softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_timer.c'))
456
+
674
softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_timer.c'))
457
CONFIG_VERSATILE_PCI=y
675
softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_gptimer.c'))
458
CONFIG_VERSATILE_I2C=y
676
softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_synctimer.c'))
459
677
diff --git a/hw/timer/trace-events b/hw/timer/trace-events
460
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
461
index XXXXXXX..XXXXXXX 100644
678
index XXXXXXX..XXXXXXX 100644
462
--- a/hw/misc/trace-events
679
--- a/hw/timer/trace-events
463
+++ b/hw/misc/trace-events
680
+++ b/hw/timer/trace-events
464
@@ -XXX,XX +XXX,XX @@ mos6522_get_next_irq_time(uint16_t latch, int64_t d, int64_t delta) "latch=%d co
681
@@ -XXX,XX +XXX,XX @@ cmsdk_apb_dualtimer_read(uint64_t offset, uint64_t data, unsigned size) "CMSDK A
465
mos6522_set_sr_int(void) "set sr_int"
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"
466
mos6522_write(uint64_t addr, uint64_t val) "reg=0x%"PRIx64 " val=0x%"PRIx64
683
cmsdk_apb_dualtimer_reset(void) "CMSDK APB dualtimer: reset"
467
mos6522_read(uint64_t addr, unsigned val) "reg=0x%"PRIx64 " val=0x%x"
684
468
+
685
+# npcm7xx_timer.c
469
+# hw/misc/tz-ppc.c
686
+npcm7xx_timer_read(const char *id, uint64_t offset, uint64_t value) " %s offset: 0x%04" PRIx64 " value 0x%08" PRIx64
470
+tz_ppc_reset(void) "TZ PPC: reset"
687
+npcm7xx_timer_write(const char *id, uint64_t offset, uint64_t value) "%s offset: 0x%04" PRIx64 " value 0x%08" PRIx64
471
+tz_ppc_cfg_nonsec(int n, int level) "TZ PPC: cfg_nonsec[%d] = %d"
688
+npcm7xx_timer_irq(const char *id, int timer, int state) "%s timer %d state %d"
472
+tz_ppc_cfg_ap(int n, int level) "TZ PPC: cfg_ap[%d] = %d"
689
+
473
+tz_ppc_cfg_sec_resp(int level) "TZ PPC: cfg_sec_resp = %d"
690
# nrf51_timer.c
474
+tz_ppc_irq_enable(int level) "TZ PPC: int_enable = %d"
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"
475
+tz_ppc_irq_clear(int level) "TZ PPC: int_clear = %d"
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"
476
+tz_ppc_update_irq(int level) "TZ PPC: setting irq line to %d"
477
+tz_ppc_read_blocked(int n, hwaddr offset, bool secure, bool user) "TZ PPC: port %d offset 0x%" HWADDR_PRIx " read (secure %d user %d) blocked"
478
+tz_ppc_write_blocked(int n, hwaddr offset, bool secure, bool user) "TZ PPC: port %d offset 0x%" HWADDR_PRIx " write (secure %d user %d) blocked"
479
--
693
--
480
2.16.2
694
2.20.1
481
695
482
696
diff view generated by jsdifflib
1
Model the Arm IoT Kit documented in
1
From: Havard Skinnemoen <hskinnemoen@google.com>
2
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
2
3
3
The Nuvoton NPCM7xx SoC family are used to implement Baseboard
4
The Arm IoT Kit is a subsystem which includes a CPU and some devices,
4
Management Controllers in servers. While the family includes four SoCs,
5
and is intended be extended by adding extra devices to form a
5
this patch implements limited support for two of them: NPCM730 (targeted
6
complete system. It is used in the MPS2 board's AN505 image for the
6
for Data Center applications) and NPCM750 (targeted for Enterprise
7
Cortex-M33.
7
applications).
8
8
9
This patch includes little more than the bare minimum needed to boot a
10
Linux kernel built with NPCM7xx support in direct-kernel mode:
11
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
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
28
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
11
Message-id: 20180220180325.29818-19-peter.maydell@linaro.org
12
---
29
---
13
hw/arm/Makefile.objs | 1 +
30
include/hw/arm/npcm7xx.h | 85 ++++++++
14
include/hw/arm/iotkit.h | 109 ++++++++
31
hw/arm/npcm7xx.c | 407 +++++++++++++++++++++++++++++++++++++++
15
hw/arm/iotkit.c | 598 ++++++++++++++++++++++++++++++++++++++++
32
hw/arm/Kconfig | 5 +
16
default-configs/arm-softmmu.mak | 1 +
33
hw/arm/meson.build | 1 +
17
4 files changed, 709 insertions(+)
34
4 files changed, 498 insertions(+)
18
create mode 100644 include/hw/arm/iotkit.h
35
create mode 100644 include/hw/arm/npcm7xx.h
19
create mode 100644 hw/arm/iotkit.c
36
create mode 100644 hw/arm/npcm7xx.c
20
37
21
diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
38
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
22
index XXXXXXX..XXXXXXX 100644
23
--- a/hw/arm/Makefile.objs
24
+++ b/hw/arm/Makefile.objs
25
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_FSL_IMX6) += fsl-imx6.o sabrelite.o
26
obj-$(CONFIG_ASPEED_SOC) += aspeed_soc.o aspeed.o
27
obj-$(CONFIG_MPS2) += mps2.o
28
obj-$(CONFIG_MSF2) += msf2-soc.o msf2-som.o
29
+obj-$(CONFIG_IOTKIT) += iotkit.o
30
diff --git a/include/hw/arm/iotkit.h b/include/hw/arm/iotkit.h
31
new file mode 100644
39
new file mode 100644
32
index XXXXXXX..XXXXXXX
40
index XXXXXXX..XXXXXXX
33
--- /dev/null
41
--- /dev/null
34
+++ b/include/hw/arm/iotkit.h
42
+++ b/include/hw/arm/npcm7xx.h
35
@@ -XXX,XX +XXX,XX @@
43
@@ -XXX,XX +XXX,XX @@
36
+/*
44
+/*
37
+ * ARM IoT Kit
45
+ * Nuvoton NPCM7xx SoC family.
38
+ *
46
+ *
39
+ * Copyright (c) 2018 Linaro Limited
47
+ * Copyright 2020 Google LLC
40
+ * Written by Peter Maydell
48
+ *
41
+ *
49
+ * This program is free software; you can redistribute it and/or modify it
42
+ * This program is free software; you can redistribute it and/or modify
50
+ * under the terms of the GNU General Public License as published by the
43
+ * it under the terms of the GNU General Public License version 2 or
51
+ * Free Software Foundation; either version 2 of the License, or
44
+ * (at your option) any later version.
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.
45
+ */
58
+ */
46
+
59
+#ifndef NPCM7XX_H
47
+/* This is a model of the Arm IoT Kit which is documented in
60
+#define NPCM7XX_H
48
+ * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
61
+
49
+ * It contains:
62
+#include "hw/boards.h"
50
+ * a Cortex-M33
63
+#include "hw/cpu/a9mpcore.h"
51
+ * the IDAU
64
+#include "hw/misc/npcm7xx_clk.h"
52
+ * some timers and watchdogs
65
+#include "hw/misc/npcm7xx_gcr.h"
53
+ * two peripheral protection controllers
66
+#include "hw/timer/npcm7xx_timer.h"
54
+ * a memory protection controller
67
+#include "target/arm/cpu.h"
55
+ * a security controller
68
+
56
+ * a bus fabric which arranges that some parts of the address
69
+#define NPCM7XX_MAX_NUM_CPUS (2)
57
+ * space are secure and non-secure aliases of each other
70
+
58
+ *
71
+/* The first half of the address space is reserved for DDR4 DRAM. */
59
+ * QEMU interface:
72
+#define NPCM7XX_DRAM_BA (0x00000000)
60
+ * + QOM property "memory" is a MemoryRegion containing the devices provided
73
+#define NPCM7XX_DRAM_SZ (2 * GiB)
61
+ * by the board model.
74
+
62
+ * + QOM property "MAINCLK" is the frequency of the main system clock
75
+/* Magic addresses for setting up direct kernel booting and SMP boot stubs. */
63
+ * + QOM property "EXP_NUMIRQ" sets the number of expansion interrupts
76
+#define NPCM7XX_LOADER_START (0x00000000) /* Start of SDRAM */
64
+ * + Named GPIO inputs "EXP_IRQ" 0..n are the expansion interrupts, which
77
+#define NPCM7XX_SMP_LOADER_START (0xffff0000) /* Boot ROM */
65
+ * are wired to the NVIC lines 32 .. n+32
78
+#define NPCM7XX_SMP_BOOTREG_ADDR (0xf080013c) /* GCR.SCRPAD */
66
+ * Controlling up to 4 AHB expansion PPBs which a system using the IoTKit
79
+#define NPCM7XX_GIC_CPU_IF_ADDR (0xf03fe100) /* GIC within A9 */
67
+ * might provide:
80
+
68
+ * + named GPIO outputs apb_ppcexp{0,1,2,3}_nonsec[0..15]
81
+typedef struct NPCM7xxState {
69
+ * + named GPIO outputs apb_ppcexp{0,1,2,3}_ap[0..15]
82
+ DeviceState parent;
70
+ * + named GPIO outputs apb_ppcexp{0,1,2,3}_irq_enable
83
+
71
+ * + named GPIO outputs apb_ppcexp{0,1,2,3}_irq_clear
84
+ ARMCPU cpu[NPCM7XX_MAX_NUM_CPUS];
72
+ * + named GPIO inputs apb_ppcexp{0,1,2,3}_irq_status
85
+ A9MPPrivState a9mpcore;
73
+ * Controlling each of the 4 expansion AHB PPCs which a system using the IoTKit
86
+
74
+ * might provide:
87
+ MemoryRegion sram;
75
+ * + named GPIO outputs ahb_ppcexp{0,1,2,3}_nonsec[0..15]
88
+ MemoryRegion irom;
76
+ * + named GPIO outputs ahb_ppcexp{0,1,2,3}_ap[0..15]
89
+ MemoryRegion ram3;
77
+ * + named GPIO outputs ahb_ppcexp{0,1,2,3}_irq_enable
90
+ MemoryRegion *dram;
78
+ * + named GPIO outputs ahb_ppcexp{0,1,2,3}_irq_clear
91
+
79
+ * + named GPIO inputs ahb_ppcexp{0,1,2,3}_irq_status
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.
80
+ */
125
+ */
81
+
126
+void npcm7xx_load_kernel(MachineState *machine, NPCM7xxState *soc);
82
+#ifndef IOTKIT_H
127
+
83
+#define IOTKIT_H
128
+#endif /* NPCM7XX_H */
84
+
129
diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c
85
+#include "hw/sysbus.h"
86
+#include "hw/arm/armv7m.h"
87
+#include "hw/misc/iotkit-secctl.h"
88
+#include "hw/misc/tz-ppc.h"
89
+#include "hw/timer/cmsdk-apb-timer.h"
90
+#include "hw/misc/unimp.h"
91
+#include "hw/or-irq.h"
92
+#include "hw/core/split-irq.h"
93
+
94
+#define TYPE_IOTKIT "iotkit"
95
+#define IOTKIT(obj) OBJECT_CHECK(IoTKit, (obj), TYPE_IOTKIT)
96
+
97
+/* We have an IRQ splitter and an OR gate input for each external PPC
98
+ * and the 2 internal PPCs
99
+ */
100
+#define NUM_EXTERNAL_PPCS (IOTS_NUM_AHB_EXP_PPC + IOTS_NUM_APB_EXP_PPC)
101
+#define NUM_PPCS (NUM_EXTERNAL_PPCS + 2)
102
+
103
+typedef struct IoTKit {
104
+ /*< private >*/
105
+ SysBusDevice parent_obj;
106
+
107
+ /*< public >*/
108
+ ARMv7MState armv7m;
109
+ IoTKitSecCtl secctl;
110
+ TZPPC apb_ppc0;
111
+ TZPPC apb_ppc1;
112
+ CMSDKAPBTIMER timer0;
113
+ CMSDKAPBTIMER timer1;
114
+ qemu_or_irq ppc_irq_orgate;
115
+ SplitIRQ sec_resp_splitter;
116
+ SplitIRQ ppc_irq_splitter[NUM_PPCS];
117
+
118
+ UnimplementedDeviceState dualtimer;
119
+ UnimplementedDeviceState s32ktimer;
120
+
121
+ MemoryRegion container;
122
+ MemoryRegion alias1;
123
+ MemoryRegion alias2;
124
+ MemoryRegion alias3;
125
+ MemoryRegion sram0;
126
+
127
+ qemu_irq *exp_irqs;
128
+ qemu_irq ppc0_irq;
129
+ qemu_irq ppc1_irq;
130
+ qemu_irq sec_resp_cfg;
131
+ qemu_irq sec_resp_cfg_in;
132
+ qemu_irq nsc_cfg_in;
133
+
134
+ qemu_irq irq_status_in[NUM_EXTERNAL_PPCS];
135
+
136
+ uint32_t nsccfg;
137
+
138
+ /* Properties */
139
+ MemoryRegion *board_memory;
140
+ uint32_t exp_numirq;
141
+ uint32_t mainclk_frq;
142
+} IoTKit;
143
+
144
+#endif
145
diff --git a/hw/arm/iotkit.c b/hw/arm/iotkit.c
146
new file mode 100644
130
new file mode 100644
147
index XXXXXXX..XXXXXXX
131
index XXXXXXX..XXXXXXX
148
--- /dev/null
132
--- /dev/null
149
+++ b/hw/arm/iotkit.c
133
+++ b/hw/arm/npcm7xx.c
150
@@ -XXX,XX +XXX,XX @@
134
@@ -XXX,XX +XXX,XX @@
151
+/*
135
+/*
152
+ * Arm IoT Kit
136
+ * Nuvoton NPCM7xx SoC family.
153
+ *
137
+ *
154
+ * Copyright (c) 2018 Linaro Limited
138
+ * Copyright 2020 Google LLC
155
+ * Written by Peter Maydell
139
+ *
156
+ *
140
+ * This program is free software; you can redistribute it and/or modify it
157
+ * This program is free software; you can redistribute it and/or modify
141
+ * under the terms of the GNU General Public License as published by the
158
+ * it under the terms of the GNU General Public License version 2 or
142
+ * Free Software Foundation; either version 2 of the License, or
159
+ * (at your option) any later version.
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.
160
+ */
149
+ */
161
+
150
+
162
+#include "qemu/osdep.h"
151
+#include "qemu/osdep.h"
163
+#include "qemu/log.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"
164
+#include "qapi/error.h"
160
+#include "qapi/error.h"
165
+#include "trace.h"
161
+#include "qemu/units.h"
166
+#include "hw/sysbus.h"
162
+#include "sysemu/sysemu.h"
167
+#include "hw/registerfields.h"
163
+
168
+#include "hw/arm/iotkit.h"
164
+/*
169
+#include "hw/misc/unimp.h"
165
+ * This covers the whole MMIO space. We'll use this to catch any MMIO accesses
170
+#include "hw/arm/arm.h"
166
+ * that aren't handled by any device.
171
+
172
+/* Create an alias region of @size bytes starting at @base
173
+ * which mirrors the memory starting at @orig.
174
+ */
167
+ */
175
+static void make_alias(IoTKit *s, MemoryRegion *mr, const char *name,
168
+#define NPCM7XX_MMIO_BA (0x80000000)
176
+ hwaddr base, hwaddr size, hwaddr orig)
169
+#define NPCM7XX_MMIO_SZ (0x7ffd0000)
177
+{
170
+
178
+ memory_region_init_alias(mr, NULL, name, &s->container, orig, size);
171
+/* Core system modules. */
179
+ /* The alias is even lower priority than unimplemented_device regions */
172
+#define NPCM7XX_L2C_BA (0xf03fc000)
180
+ memory_region_add_subregion_overlap(&s->container, base, mr, -1500);
173
+#define NPCM7XX_CPUP_BA (0xf03fe000)
181
+}
174
+#define NPCM7XX_GCR_BA (0xf0800000)
182
+
175
+#define NPCM7XX_CLK_BA (0xf0801000)
183
+static void init_sysbus_child(Object *parent, const char *childname,
176
+
184
+ void *child, size_t childsize,
177
+/* Internal AHB SRAM */
185
+ const char *childtype)
178
+#define NPCM7XX_RAM3_BA (0xc0008000)
186
+{
179
+#define NPCM7XX_RAM3_SZ (4 * KiB)
187
+ object_initialize(child, childsize, childtype);
180
+
188
+ object_property_add_child(parent, childname, OBJECT(child), &error_abort);
181
+/* Memory blocks at the end of the address space */
189
+ qdev_set_parent_bus(DEVICE(child), sysbus_get_default());
182
+#define NPCM7XX_RAM2_BA (0xfffd0000)
190
+}
183
+#define NPCM7XX_RAM2_SZ (128 * KiB)
191
+
184
+#define NPCM7XX_ROM_BA (0xffff0000)
192
+static void irq_status_forwarder(void *opaque, int n, int level)
185
+#define NPCM7XX_ROM_SZ (64 * KiB)
193
+{
186
+
194
+ qemu_irq destirq = opaque;
187
+/*
195
+
188
+ * Interrupt lines going into the GIC. This does not include internal Cortex-A9
196
+ qemu_set_irq(destirq, level);
189
+ * interrupts.
197
+}
190
+ */
198
+
191
+enum NPCM7xxInterrupt {
199
+static void nsccfg_handler(void *opaque, int n, int level)
192
+ NPCM7XX_UART0_IRQ = 2,
200
+{
193
+ NPCM7XX_UART1_IRQ,
201
+ IoTKit *s = IOTKIT(opaque);
194
+ NPCM7XX_UART2_IRQ,
202
+
195
+ NPCM7XX_UART3_IRQ,
203
+ s->nsccfg = level;
196
+ NPCM7XX_TIMER0_IRQ = 32, /* Timer Module 0 */
204
+}
197
+ NPCM7XX_TIMER1_IRQ,
205
+
198
+ NPCM7XX_TIMER2_IRQ,
206
+static void iotkit_forward_ppc(IoTKit *s, const char *ppcname, int ppcnum)
199
+ NPCM7XX_TIMER3_IRQ,
207
+{
200
+ NPCM7XX_TIMER4_IRQ,
208
+ /* Each of the 4 AHB and 4 APB PPCs that might be present in a
201
+ NPCM7XX_TIMER5_IRQ, /* Timer Module 1 */
209
+ * system using the IoTKit has a collection of control lines which
202
+ NPCM7XX_TIMER6_IRQ,
210
+ * are provided by the security controller and which we want to
203
+ NPCM7XX_TIMER7_IRQ,
211
+ * expose as control lines on the IoTKit device itself, so the
204
+ NPCM7XX_TIMER8_IRQ,
212
+ * code using the IoTKit can wire them up to the PPCs.
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.
213
+ */
240
+ */
214
+ SplitIRQ *splitter = &s->ppc_irq_splitter[ppcnum];
241
+ uint32_t smpboot[] = {
215
+ DeviceState *iotkitdev = DEVICE(s);
242
+ 0xe59f2018, /* ldr r2, bootreg_addr */
216
+ DeviceState *dev_secctl = DEVICE(&s->secctl);
243
+ 0xe3a00000, /* mov r0, #0 */
217
+ DeviceState *dev_splitter = DEVICE(splitter);
244
+ 0xe5820000, /* str r0, [r2] */
218
+ char *name;
245
+ 0xe320f002, /* wfe */
219
+
246
+ 0xe5921000, /* ldr r1, [r2] */
220
+ name = g_strdup_printf("%s_nonsec", ppcname);
247
+ 0xe1110001, /* tst r1, r1 */
221
+ qdev_pass_gpios(dev_secctl, iotkitdev, name);
248
+ 0x0afffffb, /* beq <wfe> */
222
+ g_free(name);
249
+ 0xe12fff11, /* bx r1 */
223
+ name = g_strdup_printf("%s_ap", ppcname);
250
+ NPCM7XX_SMP_BOOTREG_ADDR,
224
+ qdev_pass_gpios(dev_secctl, iotkitdev, name);
251
+ };
225
+ g_free(name);
226
+ name = g_strdup_printf("%s_irq_enable", ppcname);
227
+ qdev_pass_gpios(dev_secctl, iotkitdev, name);
228
+ g_free(name);
229
+ name = g_strdup_printf("%s_irq_clear", ppcname);
230
+ qdev_pass_gpios(dev_secctl, iotkitdev, name);
231
+ g_free(name);
232
+
233
+ /* irq_status is a little more tricky, because we need to
234
+ * split it so we can send it both to the security controller
235
+ * and to our OR gate for the NVIC interrupt line.
236
+ * Connect up the splitter's outputs, and create a GPIO input
237
+ * which will pass the line state to the input splitter.
238
+ */
239
+ name = g_strdup_printf("%s_irq_status", ppcname);
240
+ qdev_connect_gpio_out(dev_splitter, 0,
241
+ qdev_get_gpio_in_named(dev_secctl,
242
+ name, 0));
243
+ qdev_connect_gpio_out(dev_splitter, 1,
244
+ qdev_get_gpio_in(DEVICE(&s->ppc_irq_orgate), ppcnum));
245
+ s->irq_status_in[ppcnum] = qdev_get_gpio_in(dev_splitter, 0);
246
+ qdev_init_gpio_in_named_with_opaque(iotkitdev, irq_status_forwarder,
247
+ s->irq_status_in[ppcnum], name, 1);
248
+ g_free(name);
249
+}
250
+
251
+static void iotkit_forward_sec_resp_cfg(IoTKit *s)
252
+{
253
+ /* Forward the 3rd output from the splitter device as a
254
+ * named GPIO output of the iotkit object.
255
+ */
256
+ DeviceState *dev = DEVICE(s);
257
+ DeviceState *dev_splitter = DEVICE(&s->sec_resp_splitter);
258
+
259
+ qdev_init_gpio_out_named(dev, &s->sec_resp_cfg, "sec_resp_cfg", 1);
260
+ s->sec_resp_cfg_in = qemu_allocate_irq(irq_status_forwarder,
261
+ s->sec_resp_cfg, 1);
262
+ qdev_connect_gpio_out(dev_splitter, 2, s->sec_resp_cfg_in);
263
+}
264
+
265
+static void iotkit_init(Object *obj)
266
+{
267
+ IoTKit *s = IOTKIT(obj);
268
+ int i;
252
+ int i;
269
+
253
+
270
+ memory_region_init(&s->container, obj, "iotkit-container", UINT64_MAX);
254
+ for (i = 0; i < ARRAY_SIZE(smpboot); i++) {
271
+
255
+ smpboot[i] = tswap32(smpboot[i]);
272
+ init_sysbus_child(obj, "armv7m", &s->armv7m, sizeof(s->armv7m),
256
+ }
273
+ TYPE_ARMV7M);
257
+
274
+ qdev_prop_set_string(DEVICE(&s->armv7m), "cpu-type",
258
+ rom_add_blob_fixed("smpboot", smpboot, sizeof(smpboot),
275
+ ARM_CPU_TYPE_NAME("cortex-m33"));
259
+ NPCM7XX_SMP_LOADER_START);
276
+
260
+}
277
+ init_sysbus_child(obj, "secctl", &s->secctl, sizeof(s->secctl),
261
+
278
+ TYPE_IOTKIT_SECCTL);
262
+static struct arm_boot_info npcm7xx_binfo = {
279
+ init_sysbus_child(obj, "apb-ppc0", &s->apb_ppc0, sizeof(s->apb_ppc0),
263
+ .loader_start = NPCM7XX_LOADER_START,
280
+ TYPE_TZ_PPC);
264
+ .smp_loader_start = NPCM7XX_SMP_LOADER_START,
281
+ init_sysbus_child(obj, "apb-ppc1", &s->apb_ppc1, sizeof(s->apb_ppc1),
265
+ .smp_bootreg_addr = NPCM7XX_SMP_BOOTREG_ADDR,
282
+ TYPE_TZ_PPC);
266
+ .gic_cpu_if_addr = NPCM7XX_GIC_CPU_IF_ADDR,
283
+ init_sysbus_child(obj, "timer0", &s->timer0, sizeof(s->timer0),
267
+ .write_secondary_boot = npcm7xx_write_secondary_boot,
284
+ TYPE_CMSDK_APB_TIMER);
268
+ .board_id = -1,
285
+ init_sysbus_child(obj, "timer1", &s->timer1, sizeof(s->timer1),
269
+};
286
+ TYPE_CMSDK_APB_TIMER);
270
+
287
+ init_sysbus_child(obj, "dualtimer", &s->dualtimer, sizeof(s->dualtimer),
271
+void npcm7xx_load_kernel(MachineState *machine, NPCM7xxState *soc)
288
+ TYPE_UNIMPLEMENTED_DEVICE);
272
+{
289
+ object_initialize(&s->ppc_irq_orgate, sizeof(s->ppc_irq_orgate),
273
+ NPCM7xxClass *sc = NPCM7XX_GET_CLASS(soc);
290
+ TYPE_OR_IRQ);
274
+
291
+ object_property_add_child(obj, "ppc-irq-orgate",
275
+ npcm7xx_binfo.ram_size = machine->ram_size;
292
+ OBJECT(&s->ppc_irq_orgate), &error_abort);
276
+ npcm7xx_binfo.nb_cpus = sc->num_cpus;
293
+ object_initialize(&s->sec_resp_splitter, sizeof(s->sec_resp_splitter),
277
+
294
+ TYPE_SPLIT_IRQ);
278
+ arm_load_kernel(&soc->cpu[0], machine, &npcm7xx_binfo);
295
+ object_property_add_child(obj, "sec-resp-splitter",
279
+}
296
+ OBJECT(&s->sec_resp_splitter), &error_abort);
280
+
297
+ for (i = 0; i < ARRAY_SIZE(s->ppc_irq_splitter); i++) {
281
+static qemu_irq npcm7xx_irq(NPCM7xxState *s, int n)
298
+ char *name = g_strdup_printf("ppc-irq-splitter-%d", i);
282
+{
299
+ SplitIRQ *splitter = &s->ppc_irq_splitter[i];
283
+ return qdev_get_gpio_in(DEVICE(&s->a9mpcore), n);
300
+
284
+}
301
+ object_initialize(splitter, sizeof(*splitter), TYPE_SPLIT_IRQ);
285
+
302
+ object_property_add_child(obj, name, OBJECT(splitter), &error_abort);
286
+static void npcm7xx_init(Object *obj)
303
+ }
287
+{
304
+ init_sysbus_child(obj, "s32ktimer", &s->s32ktimer, sizeof(s->s32ktimer),
288
+ NPCM7xxState *s = NPCM7XX(obj);
305
+ TYPE_UNIMPLEMENTED_DEVICE);
306
+}
307
+
308
+static void iotkit_exp_irq(void *opaque, int n, int level)
309
+{
310
+ IoTKit *s = IOTKIT(opaque);
311
+
312
+ qemu_set_irq(s->exp_irqs[n], level);
313
+}
314
+
315
+static void iotkit_realize(DeviceState *dev, Error **errp)
316
+{
317
+ IoTKit *s = IOTKIT(dev);
318
+ int i;
289
+ int i;
319
+ MemoryRegion *mr;
290
+
320
+ Error *err = NULL;
291
+ for (i = 0; i < NPCM7XX_MAX_NUM_CPUS; i++) {
321
+ SysBusDevice *sbd_apb_ppc0;
292
+ object_initialize_child(obj, "cpu[*]", &s->cpu[i],
322
+ SysBusDevice *sbd_secctl;
293
+ ARM_CPU_TYPE_NAME("cortex-a9"));
323
+ DeviceState *dev_apb_ppc0;
294
+ }
324
+ DeviceState *dev_apb_ppc1;
295
+
325
+ DeviceState *dev_secctl;
296
+ object_initialize_child(obj, "a9mpcore", &s->a9mpcore, TYPE_A9MPCORE_PRIV);
326
+ DeviceState *dev_splitter;
297
+ object_initialize_child(obj, "gcr", &s->gcr, TYPE_NPCM7XX_GCR);
327
+
298
+ object_property_add_alias(obj, "power-on-straps", OBJECT(&s->gcr),
328
+ if (!s->board_memory) {
299
+ "power-on-straps");
329
+ error_setg(errp, "memory property was not set");
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);
330
+ return;
316
+ return;
331
+ }
317
+ }
332
+
318
+
333
+ if (!s->mainclk_frq) {
319
+ /* CPUs */
334
+ error_setg(errp, "MAINCLK property was not set");
320
+ for (i = 0; i < nc->num_cpus; i++) {
335
+ return;
321
+ object_property_set_int(OBJECT(&s->cpu[i]), "mp-affinity",
336
+ }
322
+ arm_cpu_mp_affinity(i, NPCM7XX_MAX_NUM_CPUS),
337
+
323
+ &error_abort);
338
+ /* Handling of which devices should be available only to secure
324
+ object_property_set_int(OBJECT(&s->cpu[i]), "reset-cbar",
339
+ * code is usually done differently for M profile than for A profile.
325
+ NPCM7XX_GIC_CPU_IF_ADDR, &error_abort);
340
+ * Instead of putting some devices only into the secure address space,
326
+ object_property_set_bool(OBJECT(&s->cpu[i]), "reset-hivecs", true,
341
+ * devices exist in both address spaces but with hard-wired security
327
+ &error_abort);
342
+ * permissions that will cause the CPU to fault for non-secure accesses.
328
+
343
+ *
329
+ /* Disable security extensions. */
344
+ * The IoTKit has an IDAU (Implementation Defined Access Unit),
330
+ object_property_set_bool(OBJECT(&s->cpu[i]), "has_el3", false,
345
+ * which specifies hard-wired security permissions for different
331
+ &error_abort);
346
+ * areas of the physical address space. For the IoTKit IDAU, the
332
+
347
+ * top 4 bits of the physical address are the IDAU region ID, and
333
+ if (!qdev_realize(DEVICE(&s->cpu[i]), NULL, errp)) {
348
+ * if bit 28 (ie the lowest bit of the ID) is 0 then this is an NS
349
+ * region, otherwise it is an S region.
350
+ *
351
+ * The various devices and RAMs are generally all mapped twice,
352
+ * once into a region that the IDAU defines as secure and once
353
+ * into a non-secure region. They sit behind either a Memory
354
+ * Protection Controller (for RAM) or a Peripheral Protection
355
+ * Controller (for devices), which allow a more fine grained
356
+ * configuration of whether non-secure accesses are permitted.
357
+ *
358
+ * (The other place that guest software can configure security
359
+ * permissions is in the architected SAU (Security Attribution
360
+ * Unit), which is entirely inside the CPU. The IDAU can upgrade
361
+ * the security attributes for a region to more restrictive than
362
+ * the SAU specifies, but cannot downgrade them.)
363
+ *
364
+ * 0x10000000..0x1fffffff alias of 0x00000000..0x0fffffff
365
+ * 0x20000000..0x2007ffff 32KB FPGA block RAM
366
+ * 0x30000000..0x3fffffff alias of 0x20000000..0x2fffffff
367
+ * 0x40000000..0x4000ffff base peripheral region 1
368
+ * 0x40010000..0x4001ffff CPU peripherals (none for IoTKit)
369
+ * 0x40020000..0x4002ffff system control element peripherals
370
+ * 0x40080000..0x400fffff base peripheral region 2
371
+ * 0x50000000..0x5fffffff alias of 0x40000000..0x4fffffff
372
+ */
373
+
374
+ memory_region_add_subregion_overlap(&s->container, 0, s->board_memory, -1);
375
+
376
+ qdev_prop_set_uint32(DEVICE(&s->armv7m), "num-irq", s->exp_numirq + 32);
377
+ /* In real hardware the initial Secure VTOR is set from the INITSVTOR0
378
+ * register in the IoT Kit System Control Register block, and the
379
+ * initial value of that is in turn specifiable by the FPGA that
380
+ * instantiates the IoT Kit. In QEMU we don't implement this wrinkle,
381
+ * and simply set the CPU's init-svtor to the IoT Kit default value.
382
+ */
383
+ qdev_prop_set_uint32(DEVICE(&s->armv7m), "init-svtor", 0x10000000);
384
+ object_property_set_link(OBJECT(&s->armv7m), OBJECT(&s->container),
385
+ "memory", &err);
386
+ if (err) {
387
+ error_propagate(errp, err);
388
+ return;
389
+ }
390
+ object_property_set_link(OBJECT(&s->armv7m), OBJECT(s), "idau", &err);
391
+ if (err) {
392
+ error_propagate(errp, err);
393
+ return;
394
+ }
395
+ object_property_set_bool(OBJECT(&s->armv7m), true, "realized", &err);
396
+ if (err) {
397
+ error_propagate(errp, err);
398
+ return;
399
+ }
400
+
401
+ /* Connect our EXP_IRQ GPIOs to the NVIC's lines 32 and up. */
402
+ s->exp_irqs = g_new(qemu_irq, s->exp_numirq);
403
+ for (i = 0; i < s->exp_numirq; i++) {
404
+ s->exp_irqs[i] = qdev_get_gpio_in(DEVICE(&s->armv7m), i + 32);
405
+ }
406
+ qdev_init_gpio_in_named(dev, iotkit_exp_irq, "EXP_IRQ", s->exp_numirq);
407
+
408
+ /* Set up the big aliases first */
409
+ make_alias(s, &s->alias1, "alias 1", 0x10000000, 0x10000000, 0x00000000);
410
+ make_alias(s, &s->alias2, "alias 2", 0x30000000, 0x10000000, 0x20000000);
411
+ /* The 0x50000000..0x5fffffff region is not a pure alias: it has
412
+ * a few extra devices that only appear there (generally the
413
+ * control interfaces for the protection controllers).
414
+ * We implement this by mapping those devices over the top of this
415
+ * alias MR at a higher priority.
416
+ */
417
+ make_alias(s, &s->alias3, "alias 3", 0x50000000, 0x10000000, 0x40000000);
418
+
419
+ /* This RAM should be behind a Memory Protection Controller, but we
420
+ * don't implement that yet.
421
+ */
422
+ memory_region_init_ram(&s->sram0, NULL, "iotkit.sram0", 0x00008000, &err);
423
+ if (err) {
424
+ error_propagate(errp, err);
425
+ return;
426
+ }
427
+ memory_region_add_subregion(&s->container, 0x20000000, &s->sram0);
428
+
429
+ /* Security controller */
430
+ object_property_set_bool(OBJECT(&s->secctl), true, "realized", &err);
431
+ if (err) {
432
+ error_propagate(errp, err);
433
+ return;
434
+ }
435
+ sbd_secctl = SYS_BUS_DEVICE(&s->secctl);
436
+ dev_secctl = DEVICE(&s->secctl);
437
+ sysbus_mmio_map(sbd_secctl, 0, 0x50080000);
438
+ sysbus_mmio_map(sbd_secctl, 1, 0x40080000);
439
+
440
+ s->nsc_cfg_in = qemu_allocate_irq(nsccfg_handler, s, 1);
441
+ qdev_connect_gpio_out_named(dev_secctl, "nsc_cfg", 0, s->nsc_cfg_in);
442
+
443
+ /* The sec_resp_cfg output from the security controller must be split into
444
+ * multiple lines, one for each of the PPCs within the IoTKit and one
445
+ * that will be an output from the IoTKit to the system.
446
+ */
447
+ object_property_set_int(OBJECT(&s->sec_resp_splitter), 3,
448
+ "num-lines", &err);
449
+ if (err) {
450
+ error_propagate(errp, err);
451
+ return;
452
+ }
453
+ object_property_set_bool(OBJECT(&s->sec_resp_splitter), true,
454
+ "realized", &err);
455
+ if (err) {
456
+ error_propagate(errp, err);
457
+ return;
458
+ }
459
+ dev_splitter = DEVICE(&s->sec_resp_splitter);
460
+ qdev_connect_gpio_out_named(dev_secctl, "sec_resp_cfg", 0,
461
+ qdev_get_gpio_in(dev_splitter, 0));
462
+
463
+ /* Devices behind APB PPC0:
464
+ * 0x40000000: timer0
465
+ * 0x40001000: timer1
466
+ * 0x40002000: dual timer
467
+ * We must configure and realize each downstream device and connect
468
+ * it to the appropriate PPC port; then we can realize the PPC and
469
+ * map its upstream ends to the right place in the container.
470
+ */
471
+ qdev_prop_set_uint32(DEVICE(&s->timer0), "pclk-frq", s->mainclk_frq);
472
+ object_property_set_bool(OBJECT(&s->timer0), true, "realized", &err);
473
+ if (err) {
474
+ error_propagate(errp, err);
475
+ return;
476
+ }
477
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->timer0), 0,
478
+ qdev_get_gpio_in(DEVICE(&s->armv7m), 3));
479
+ mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->timer0), 0);
480
+ object_property_set_link(OBJECT(&s->apb_ppc0), OBJECT(mr), "port[0]", &err);
481
+ if (err) {
482
+ error_propagate(errp, err);
483
+ return;
484
+ }
485
+
486
+ qdev_prop_set_uint32(DEVICE(&s->timer1), "pclk-frq", s->mainclk_frq);
487
+ object_property_set_bool(OBJECT(&s->timer1), true, "realized", &err);
488
+ if (err) {
489
+ error_propagate(errp, err);
490
+ return;
491
+ }
492
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->timer1), 0,
493
+ qdev_get_gpio_in(DEVICE(&s->armv7m), 3));
494
+ mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->timer1), 0);
495
+ object_property_set_link(OBJECT(&s->apb_ppc0), OBJECT(mr), "port[1]", &err);
496
+ if (err) {
497
+ error_propagate(errp, err);
498
+ return;
499
+ }
500
+
501
+ qdev_prop_set_string(DEVICE(&s->dualtimer), "name", "Dual timer");
502
+ qdev_prop_set_uint64(DEVICE(&s->dualtimer), "size", 0x1000);
503
+ object_property_set_bool(OBJECT(&s->dualtimer), true, "realized", &err);
504
+ if (err) {
505
+ error_propagate(errp, err);
506
+ return;
507
+ }
508
+ mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->dualtimer), 0);
509
+ object_property_set_link(OBJECT(&s->apb_ppc0), OBJECT(mr), "port[2]", &err);
510
+ if (err) {
511
+ error_propagate(errp, err);
512
+ return;
513
+ }
514
+
515
+ object_property_set_bool(OBJECT(&s->apb_ppc0), true, "realized", &err);
516
+ if (err) {
517
+ error_propagate(errp, err);
518
+ return;
519
+ }
520
+
521
+ sbd_apb_ppc0 = SYS_BUS_DEVICE(&s->apb_ppc0);
522
+ dev_apb_ppc0 = DEVICE(&s->apb_ppc0);
523
+
524
+ mr = sysbus_mmio_get_region(sbd_apb_ppc0, 0);
525
+ memory_region_add_subregion(&s->container, 0x40000000, mr);
526
+ mr = sysbus_mmio_get_region(sbd_apb_ppc0, 1);
527
+ memory_region_add_subregion(&s->container, 0x40001000, mr);
528
+ mr = sysbus_mmio_get_region(sbd_apb_ppc0, 2);
529
+ memory_region_add_subregion(&s->container, 0x40002000, mr);
530
+ for (i = 0; i < IOTS_APB_PPC0_NUM_PORTS; i++) {
531
+ qdev_connect_gpio_out_named(dev_secctl, "apb_ppc0_nonsec", i,
532
+ qdev_get_gpio_in_named(dev_apb_ppc0,
533
+ "cfg_nonsec", i));
534
+ qdev_connect_gpio_out_named(dev_secctl, "apb_ppc0_ap", i,
535
+ qdev_get_gpio_in_named(dev_apb_ppc0,
536
+ "cfg_ap", i));
537
+ }
538
+ qdev_connect_gpio_out_named(dev_secctl, "apb_ppc0_irq_enable", 0,
539
+ qdev_get_gpio_in_named(dev_apb_ppc0,
540
+ "irq_enable", 0));
541
+ qdev_connect_gpio_out_named(dev_secctl, "apb_ppc0_irq_clear", 0,
542
+ qdev_get_gpio_in_named(dev_apb_ppc0,
543
+ "irq_clear", 0));
544
+ qdev_connect_gpio_out(dev_splitter, 0,
545
+ qdev_get_gpio_in_named(dev_apb_ppc0,
546
+ "cfg_sec_resp", 0));
547
+
548
+ /* All the PPC irq lines (from the 2 internal PPCs and the 8 external
549
+ * ones) are sent individually to the security controller, and also
550
+ * ORed together to give a single combined PPC interrupt to the NVIC.
551
+ */
552
+ object_property_set_int(OBJECT(&s->ppc_irq_orgate),
553
+ NUM_PPCS, "num-lines", &err);
554
+ if (err) {
555
+ error_propagate(errp, err);
556
+ return;
557
+ }
558
+ object_property_set_bool(OBJECT(&s->ppc_irq_orgate), true,
559
+ "realized", &err);
560
+ if (err) {
561
+ error_propagate(errp, err);
562
+ return;
563
+ }
564
+ qdev_connect_gpio_out(DEVICE(&s->ppc_irq_orgate), 0,
565
+ qdev_get_gpio_in(DEVICE(&s->armv7m), 10));
566
+
567
+ /* 0x40010000 .. 0x4001ffff: private CPU region: unused in IoTKit */
568
+
569
+ /* 0x40020000 .. 0x4002ffff : IoTKit system control peripheral region */
570
+ /* Devices behind APB PPC1:
571
+ * 0x4002f000: S32K timer
572
+ */
573
+ qdev_prop_set_string(DEVICE(&s->s32ktimer), "name", "S32KTIMER");
574
+ qdev_prop_set_uint64(DEVICE(&s->s32ktimer), "size", 0x1000);
575
+ object_property_set_bool(OBJECT(&s->s32ktimer), true, "realized", &err);
576
+ if (err) {
577
+ error_propagate(errp, err);
578
+ return;
579
+ }
580
+ mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->s32ktimer), 0);
581
+ object_property_set_link(OBJECT(&s->apb_ppc1), OBJECT(mr), "port[0]", &err);
582
+ if (err) {
583
+ error_propagate(errp, err);
584
+ return;
585
+ }
586
+
587
+ object_property_set_bool(OBJECT(&s->apb_ppc1), true, "realized", &err);
588
+ if (err) {
589
+ error_propagate(errp, err);
590
+ return;
591
+ }
592
+ mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->apb_ppc1), 0);
593
+ memory_region_add_subregion(&s->container, 0x4002f000, mr);
594
+
595
+ dev_apb_ppc1 = DEVICE(&s->apb_ppc1);
596
+ qdev_connect_gpio_out_named(dev_secctl, "apb_ppc1_nonsec", 0,
597
+ qdev_get_gpio_in_named(dev_apb_ppc1,
598
+ "cfg_nonsec", 0));
599
+ qdev_connect_gpio_out_named(dev_secctl, "apb_ppc1_ap", 0,
600
+ qdev_get_gpio_in_named(dev_apb_ppc1,
601
+ "cfg_ap", 0));
602
+ qdev_connect_gpio_out_named(dev_secctl, "apb_ppc1_irq_enable", 0,
603
+ qdev_get_gpio_in_named(dev_apb_ppc1,
604
+ "irq_enable", 0));
605
+ qdev_connect_gpio_out_named(dev_secctl, "apb_ppc1_irq_clear", 0,
606
+ qdev_get_gpio_in_named(dev_apb_ppc1,
607
+ "irq_clear", 0));
608
+ qdev_connect_gpio_out(dev_splitter, 1,
609
+ qdev_get_gpio_in_named(dev_apb_ppc1,
610
+ "cfg_sec_resp", 0));
611
+
612
+ /* Using create_unimplemented_device() maps the stub into the
613
+ * system address space rather than into our container, but the
614
+ * overall effect to the guest is the same.
615
+ */
616
+ create_unimplemented_device("SYSINFO", 0x40020000, 0x1000);
617
+
618
+ create_unimplemented_device("SYSCONTROL", 0x50021000, 0x1000);
619
+ create_unimplemented_device("S32KWATCHDOG", 0x5002e000, 0x1000);
620
+
621
+ /* 0x40080000 .. 0x4008ffff : IoTKit second Base peripheral region */
622
+
623
+ create_unimplemented_device("NS watchdog", 0x40081000, 0x1000);
624
+ create_unimplemented_device("S watchdog", 0x50081000, 0x1000);
625
+
626
+ create_unimplemented_device("SRAM0 MPC", 0x50083000, 0x1000);
627
+
628
+ for (i = 0; i < ARRAY_SIZE(s->ppc_irq_splitter); i++) {
629
+ Object *splitter = OBJECT(&s->ppc_irq_splitter[i]);
630
+
631
+ object_property_set_int(splitter, 2, "num-lines", &err);
632
+ if (err) {
633
+ error_propagate(errp, err);
634
+ return;
334
+ return;
635
+ }
335
+ }
636
+ object_property_set_bool(splitter, true, "realized", &err);
336
+ }
637
+ if (err) {
337
+
638
+ error_propagate(errp, err);
338
+ /* A9MPCORE peripherals. Can only fail if we pass bad parameters here. */
639
+ return;
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);
640
+ }
383
+ }
641
+ }
384
+ }
642
+
385
+
643
+ for (i = 0; i < IOTS_NUM_AHB_EXP_PPC; i++) {
386
+ /* UART0..3 (16550 compatible) */
644
+ char *ppcname = g_strdup_printf("ahb_ppcexp%d", i);
387
+ for (i = 0; i < ARRAY_SIZE(npcm7xx_uart_addr); i++) {
645
+
388
+ serial_mm_init(get_system_memory(), npcm7xx_uart_addr[i], 2,
646
+ iotkit_forward_ppc(s, ppcname, i);
389
+ npcm7xx_irq(s, NPCM7XX_UART0_IRQ + i), 115200,
647
+ g_free(ppcname);
390
+ serial_hd(i), DEVICE_LITTLE_ENDIAN);
648
+ }
391
+ }
649
+
392
+
650
+ for (i = 0; i < IOTS_NUM_APB_EXP_PPC; i++) {
393
+ /* RAM2 (SRAM) */
651
+ char *ppcname = g_strdup_printf("apb_ppcexp%d", i);
394
+ memory_region_init_ram(&s->sram, OBJECT(dev), "ram2",
652
+
395
+ NPCM7XX_RAM2_SZ, &error_abort);
653
+ iotkit_forward_ppc(s, ppcname, i + IOTS_NUM_AHB_EXP_PPC);
396
+ memory_region_add_subregion(get_system_memory(), NPCM7XX_RAM2_BA, &s->sram);
654
+ g_free(ppcname);
397
+
655
+ }
398
+ /* RAM3 (SRAM) */
656
+
399
+ memory_region_init_ram(&s->ram3, OBJECT(dev), "ram3",
657
+ for (i = NUM_EXTERNAL_PPCS; i < NUM_PPCS; i++) {
400
+ NPCM7XX_RAM3_SZ, &error_abort);
658
+ /* Wire up IRQ splitter for internal PPCs */
401
+ memory_region_add_subregion(get_system_memory(), NPCM7XX_RAM3_BA, &s->ram3);
659
+ DeviceState *devs = DEVICE(&s->ppc_irq_splitter[i]);
402
+
660
+ char *gpioname = g_strdup_printf("apb_ppc%d_irq_status",
403
+ /* Internal ROM */
661
+ i - NUM_EXTERNAL_PPCS);
404
+ memory_region_init_rom(&s->irom, OBJECT(dev), "irom", NPCM7XX_ROM_SZ,
662
+ TZPPC *ppc = (i == NUM_EXTERNAL_PPCS) ? &s->apb_ppc0 : &s->apb_ppc1;
405
+ &error_abort);
663
+
406
+ memory_region_add_subregion(get_system_memory(), NPCM7XX_ROM_BA, &s->irom);
664
+ qdev_connect_gpio_out(devs, 0,
407
+
665
+ qdev_get_gpio_in_named(dev_secctl, gpioname, 0));
408
+ create_unimplemented_device("npcm7xx.shm", 0xc0001000, 4 * KiB);
666
+ qdev_connect_gpio_out(devs, 1,
409
+ create_unimplemented_device("npcm7xx.vdmx", 0xe0800000, 4 * KiB);
667
+ qdev_get_gpio_in(DEVICE(&s->ppc_irq_orgate), i));
410
+ create_unimplemented_device("npcm7xx.pcierc", 0xe1000000, 64 * KiB);
668
+ qdev_connect_gpio_out_named(DEVICE(ppc), "irq", 0,
411
+ create_unimplemented_device("npcm7xx.kcs", 0xf0007000, 4 * KiB);
669
+ qdev_get_gpio_in(devs, 0));
412
+ create_unimplemented_device("npcm7xx.rng", 0xf000b000, 4 * KiB);
670
+ }
413
+ create_unimplemented_device("npcm7xx.adc", 0xf000c000, 4 * KiB);
671
+
414
+ create_unimplemented_device("npcm7xx.gfxi", 0xf000e000, 4 * KiB);
672
+ iotkit_forward_sec_resp_cfg(s);
415
+ create_unimplemented_device("npcm7xx.gpio[0]", 0xf0010000, 4 * KiB);
673
+
416
+ create_unimplemented_device("npcm7xx.gpio[1]", 0xf0011000, 4 * KiB);
674
+ system_clock_scale = NANOSECONDS_PER_SECOND / s->mainclk_frq;
417
+ create_unimplemented_device("npcm7xx.gpio[2]", 0xf0012000, 4 * KiB);
675
+}
418
+ create_unimplemented_device("npcm7xx.gpio[3]", 0xf0013000, 4 * KiB);
676
+
419
+ create_unimplemented_device("npcm7xx.gpio[4]", 0xf0014000, 4 * KiB);
677
+static void iotkit_idau_check(IDAUInterface *ii, uint32_t address,
420
+ create_unimplemented_device("npcm7xx.gpio[5]", 0xf0015000, 4 * KiB);
678
+ int *iregion, bool *exempt, bool *ns, bool *nsc)
421
+ create_unimplemented_device("npcm7xx.gpio[6]", 0xf0016000, 4 * KiB);
679
+{
422
+ create_unimplemented_device("npcm7xx.gpio[7]", 0xf0017000, 4 * KiB);
680
+ /* For IoTKit systems the IDAU responses are simple logical functions
423
+ create_unimplemented_device("npcm7xx.smbus[0]", 0xf0080000, 4 * KiB);
681
+ * of the address bits. The NSC attribute is guest-adjustable via the
424
+ create_unimplemented_device("npcm7xx.smbus[1]", 0xf0081000, 4 * KiB);
682
+ * NSCCFG register in the security controller.
425
+ create_unimplemented_device("npcm7xx.smbus[2]", 0xf0082000, 4 * KiB);
683
+ */
426
+ create_unimplemented_device("npcm7xx.smbus[3]", 0xf0083000, 4 * KiB);
684
+ IoTKit *s = IOTKIT(ii);
427
+ create_unimplemented_device("npcm7xx.smbus[4]", 0xf0084000, 4 * KiB);
685
+ int region = extract32(address, 28, 4);
428
+ create_unimplemented_device("npcm7xx.smbus[5]", 0xf0085000, 4 * KiB);
686
+
429
+ create_unimplemented_device("npcm7xx.smbus[6]", 0xf0086000, 4 * KiB);
687
+ *ns = !(region & 1);
430
+ create_unimplemented_device("npcm7xx.smbus[7]", 0xf0087000, 4 * KiB);
688
+ *nsc = (region == 1 && (s->nsccfg & 1)) || (region == 3 && (s->nsccfg & 2));
431
+ create_unimplemented_device("npcm7xx.smbus[8]", 0xf0088000, 4 * KiB);
689
+ /* 0xe0000000..0xe00fffff and 0xf0000000..0xf00fffff are exempt */
432
+ create_unimplemented_device("npcm7xx.smbus[9]", 0xf0089000, 4 * KiB);
690
+ *exempt = (address & 0xeff00000) == 0xe0000000;
433
+ create_unimplemented_device("npcm7xx.smbus[10]", 0xf008a000, 4 * KiB);
691
+ *iregion = region;
434
+ create_unimplemented_device("npcm7xx.smbus[11]", 0xf008b000, 4 * KiB);
692
+}
435
+ create_unimplemented_device("npcm7xx.smbus[12]", 0xf008c000, 4 * KiB);
693
+
436
+ create_unimplemented_device("npcm7xx.smbus[13]", 0xf008d000, 4 * KiB);
694
+static const VMStateDescription iotkit_vmstate = {
437
+ create_unimplemented_device("npcm7xx.smbus[14]", 0xf008e000, 4 * KiB);
695
+ .name = "iotkit",
438
+ create_unimplemented_device("npcm7xx.smbus[15]", 0xf008f000, 4 * KiB);
696
+ .version_id = 1,
439
+ create_unimplemented_device("npcm7xx.espi", 0xf009f000, 4 * KiB);
697
+ .minimum_version_id = 1,
440
+ create_unimplemented_device("npcm7xx.peci", 0xf0100000, 4 * KiB);
698
+ .fields = (VMStateField[]) {
441
+ create_unimplemented_device("npcm7xx.siox[1]", 0xf0101000, 4 * KiB);
699
+ VMSTATE_UINT32(nsccfg, IoTKit),
442
+ create_unimplemented_device("npcm7xx.siox[2]", 0xf0102000, 4 * KiB);
700
+ VMSTATE_END_OF_LIST()
443
+ create_unimplemented_device("npcm7xx.pwm[0]", 0xf0103000, 4 * KiB);
701
+ }
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(),
702
+};
492
+};
703
+
493
+
704
+static Property iotkit_properties[] = {
494
+static void npcm7xx_class_init(ObjectClass *oc, void *data)
705
+ DEFINE_PROP_LINK("memory", IoTKit, board_memory, TYPE_MEMORY_REGION,
495
+{
706
+ MemoryRegion *),
496
+ DeviceClass *dc = DEVICE_CLASS(oc);
707
+ DEFINE_PROP_UINT32("EXP_NUMIRQ", IoTKit, exp_numirq, 64),
497
+
708
+ DEFINE_PROP_UINT32("MAINCLK", IoTKit, mainclk_frq, 0),
498
+ dc->realize = npcm7xx_realize;
709
+ DEFINE_PROP_END_OF_LIST()
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
+ },
710
+};
539
+};
711
+
540
+
712
+static void iotkit_reset(DeviceState *dev)
541
+DEFINE_TYPES(npcm7xx_soc_types);
713
+{
542
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
714
+ IoTKit *s = IOTKIT(dev);
715
+
716
+ s->nsccfg = 0;
717
+}
718
+
719
+static void iotkit_class_init(ObjectClass *klass, void *data)
720
+{
721
+ DeviceClass *dc = DEVICE_CLASS(klass);
722
+ IDAUInterfaceClass *iic = IDAU_INTERFACE_CLASS(klass);
723
+
724
+ dc->realize = iotkit_realize;
725
+ dc->vmsd = &iotkit_vmstate;
726
+ dc->props = iotkit_properties;
727
+ dc->reset = iotkit_reset;
728
+ iic->check = iotkit_idau_check;
729
+}
730
+
731
+static const TypeInfo iotkit_info = {
732
+ .name = TYPE_IOTKIT,
733
+ .parent = TYPE_SYS_BUS_DEVICE,
734
+ .instance_size = sizeof(IoTKit),
735
+ .instance_init = iotkit_init,
736
+ .class_init = iotkit_class_init,
737
+ .interfaces = (InterfaceInfo[]) {
738
+ { TYPE_IDAU_INTERFACE },
739
+ { }
740
+ }
741
+};
742
+
743
+static void iotkit_register_types(void)
744
+{
745
+ type_register_static(&iotkit_info);
746
+}
747
+
748
+type_init(iotkit_register_types);
749
diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
750
index XXXXXXX..XXXXXXX 100644
543
index XXXXXXX..XXXXXXX 100644
751
--- a/default-configs/arm-softmmu.mak
544
--- a/hw/arm/Kconfig
752
+++ b/default-configs/arm-softmmu.mak
545
+++ b/hw/arm/Kconfig
753
@@ -XXX,XX +XXX,XX @@ CONFIG_MPS2_FPGAIO=y
546
@@ -XXX,XX +XXX,XX @@ config XLNX_VERSAL
754
CONFIG_MPS2_SCC=y
547
755
548
config NPCM7XX
756
CONFIG_TZ_PPC=y
549
bool
757
+CONFIG_IOTKIT=y
550
+ select A9MPCORE
758
CONFIG_IOTKIT_SECCTL=y
551
+ select ARM_GIC
759
552
+ select PL310 # cache controller
760
CONFIG_VERSATILE_PCI=y
553
+ select SERIAL
554
+ select UNIMP
555
556
config FSL_IMX25
557
bool
558
diff --git a/hw/arm/meson.build b/hw/arm/meson.build
559
index XXXXXXX..XXXXXXX 100644
560
--- a/hw/arm/meson.build
561
+++ b/hw/arm/meson.build
562
@@ -XXX,XX +XXX,XX @@ arm_ss.add(when: 'CONFIG_MICROBIT', if_true: files('microbit.c'))
563
arm_ss.add(when: 'CONFIG_MUSICPAL', if_true: files('musicpal.c'))
564
arm_ss.add(when: 'CONFIG_NETDUINO2', if_true: files('netduino2.c'))
565
arm_ss.add(when: 'CONFIG_NETDUINOPLUS2', if_true: files('netduinoplus2.c'))
566
+arm_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx.c'))
567
arm_ss.add(when: 'CONFIG_NSERIES', if_true: files('nseries.c'))
568
arm_ss.add(when: 'CONFIG_SX1', if_true: files('omap_sx1.c'))
569
arm_ss.add(when: 'CONFIG_CHEETAH', if_true: files('palm.c'))
761
--
570
--
762
2.16.2
571
2.20.1
763
572
764
573
diff view generated by jsdifflib
1
Define a new board model for the MPS2 with an AN505 FPGA image
1
From: Havard Skinnemoen <hskinnemoen@google.com>
2
containing a Cortex-M33. Since the FPGA images for TrustZone
2
3
cores (AN505, and the similar AN519 for Cortex-M23) have a
3
This adds two new machines, both supported by OpenBMC:
4
significantly different layout of devices to the non-TrustZone
4
5
images, we use a new source file rather than shoehorning them
5
- npcm750-evb: Nuvoton NPCM750 Evaluation Board.
6
into the existing mps2.c.
6
- quanta-gsj: A board with a NPCM730 chip.
7
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
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
24
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
Message-id: 20180220180325.29818-20-peter.maydell@linaro.org
11
---
25
---
12
hw/arm/Makefile.objs | 1 +
26
default-configs/arm-softmmu.mak | 1 +
13
hw/arm/mps2-tz.c | 503 +++++++++++++++++++++++++++++++++++++++++++++++++++
27
include/hw/arm/npcm7xx.h | 19 +++++
14
2 files changed, 504 insertions(+)
28
hw/arm/npcm7xx_boards.c | 145 ++++++++++++++++++++++++++++++++
15
create mode 100644 hw/arm/mps2-tz.c
29
hw/arm/meson.build | 2 +-
16
30
4 files changed, 166 insertions(+), 1 deletion(-)
17
diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
31
create mode 100644 hw/arm/npcm7xx_boards.c
32
33
diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
18
index XXXXXXX..XXXXXXX 100644
34
index XXXXXXX..XXXXXXX 100644
19
--- a/hw/arm/Makefile.objs
35
--- a/default-configs/arm-softmmu.mak
20
+++ b/hw/arm/Makefile.objs
36
+++ b/default-configs/arm-softmmu.mak
21
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o kzm.o
37
@@ -XXX,XX +XXX,XX @@ CONFIG_GUMSTIX=y
22
obj-$(CONFIG_FSL_IMX6) += fsl-imx6.o sabrelite.o
38
CONFIG_SPITZ=y
23
obj-$(CONFIG_ASPEED_SOC) += aspeed_soc.o aspeed.o
39
CONFIG_TOSA=y
24
obj-$(CONFIG_MPS2) += mps2.o
40
CONFIG_Z2=y
25
+obj-$(CONFIG_MPS2) += mps2-tz.o
41
+CONFIG_NPCM7XX=y
26
obj-$(CONFIG_MSF2) += msf2-soc.o msf2-som.o
42
CONFIG_COLLIE=y
27
obj-$(CONFIG_IOTKIT) += iotkit.o
43
CONFIG_ASPEED_SOC=y
28
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
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 @@
50
#define NPCM7XX_SMP_BOOTREG_ADDR (0xf080013c) /* GCR.SCRPAD */
51
#define NPCM7XX_GIC_CPU_IF_ADDR (0xf03fe100) /* GIC within A9 */
52
53
+typedef struct NPCM7xxMachine {
54
+ MachineState parent;
55
+} NPCM7xxMachine;
56
+
57
+#define TYPE_NPCM7XX_MACHINE MACHINE_TYPE_NAME("npcm7xx")
58
+#define NPCM7XX_MACHINE(obj) \
59
+ OBJECT_CHECK(NPCM7xxMachine, (obj), TYPE_NPCM7XX_MACHINE)
60
+
61
+typedef struct NPCM7xxMachineClass {
62
+ MachineClass parent;
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
29
new file mode 100644
76
new file mode 100644
30
index XXXXXXX..XXXXXXX
77
index XXXXXXX..XXXXXXX
31
--- /dev/null
78
--- /dev/null
32
+++ b/hw/arm/mps2-tz.c
79
+++ b/hw/arm/npcm7xx_boards.c
33
@@ -XXX,XX +XXX,XX @@
80
@@ -XXX,XX +XXX,XX @@
34
+/*
81
+/*
35
+ * ARM V2M MPS2 board emulation, trustzone aware FPGA images
82
+ * Machine definitions for boards featuring an NPCM7xx SoC.
36
+ *
83
+ *
37
+ * Copyright (c) 2017 Linaro Limited
84
+ * Copyright 2020 Google LLC
38
+ * Written by Peter Maydell
39
+ *
85
+ *
40
+ * This program is free software; you can redistribute it and/or modify
86
+ * This program is free software; you can redistribute it and/or modify it
41
+ * it under the terms of the GNU General Public License version 2 or
87
+ * under the terms of the GNU General Public License as published by the
42
+ * (at your option) any later version.
88
+ * Free Software Foundation; either version 2 of the License, or
89
+ * (at your option) any later version.
90
+ *
91
+ * This program is distributed in the hope that it will be useful, but WITHOUT
92
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
93
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
94
+ * for more details.
43
+ */
95
+ */
44
+
96
+
45
+/* The MPS2 and MPS2+ dev boards are FPGA based (the 2+ has a bigger
46
+ * FPGA but is otherwise the same as the 2). Since the CPU itself
47
+ * and most of the devices are in the FPGA, the details of the board
48
+ * as seen by the guest depend significantly on the FPGA image.
49
+ * This source file covers the following FPGA images, for TrustZone cores:
50
+ * "mps2-an505" -- Cortex-M33 as documented in ARM Application Note AN505
51
+ *
52
+ * Links to the TRM for the board itself and to the various Application
53
+ * Notes which document the FPGA images can be found here:
54
+ * https://developer.arm.com/products/system-design/development-boards/fpga-prototyping-boards/mps2
55
+ *
56
+ * Board TRM:
57
+ * http://infocenter.arm.com/help/topic/com.arm.doc.100112_0200_06_en/versatile_express_cortex_m_prototyping_systems_v2m_mps2_and_v2m_mps2plus_technical_reference_100112_0200_06_en.pdf
58
+ * Application Note AN505:
59
+ * http://infocenter.arm.com/help/topic/com.arm.doc.dai0505b/index.html
60
+ *
61
+ * The AN505 defers to the Cortex-M33 processor ARMv8M IoT Kit FVP User Guide
62
+ * (ARM ECM0601256) for the details of some of the device layout:
63
+ * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
64
+ */
65
+
66
+#include "qemu/osdep.h"
97
+#include "qemu/osdep.h"
98
+
99
+#include "exec/address-spaces.h"
100
+#include "hw/arm/npcm7xx.h"
101
+#include "hw/core/cpu.h"
67
+#include "qapi/error.h"
102
+#include "qapi/error.h"
68
+#include "qemu/error-report.h"
103
+#include "qemu/units.h"
69
+#include "hw/arm/arm.h"
104
+
70
+#include "hw/arm/armv7m.h"
105
+#define NPCM750_EVB_POWER_ON_STRAPS 0x00001ff7
71
+#include "hw/or-irq.h"
106
+#define QUANTA_GSJ_POWER_ON_STRAPS 0x00001fff
72
+#include "hw/boards.h"
107
+
73
+#include "exec/address-spaces.h"
108
+static void npcm7xx_connect_dram(NPCM7xxState *soc, MemoryRegion *dram)
74
+#include "sysemu/sysemu.h"
109
+{
75
+#include "hw/misc/unimp.h"
110
+ memory_region_add_subregion(get_system_memory(), NPCM7XX_DRAM_BA, dram);
76
+#include "hw/char/cmsdk-apb-uart.h"
111
+
77
+#include "hw/timer/cmsdk-apb-timer.h"
112
+ object_property_set_link(OBJECT(soc), "dram-mr", OBJECT(dram),
78
+#include "hw/misc/mps2-scc.h"
113
+ &error_abort);
79
+#include "hw/misc/mps2-fpgaio.h"
114
+}
80
+#include "hw/arm/iotkit.h"
115
+
81
+#include "hw/devices.h"
116
+static NPCM7xxState *npcm7xx_create_soc(MachineState *machine,
82
+#include "net/net.h"
117
+ uint32_t hw_straps)
83
+#include "hw/core/split-irq.h"
118
+{
84
+
119
+ NPCM7xxMachineClass *nmc = NPCM7XX_MACHINE_GET_CLASS(machine);
85
+typedef enum MPS2TZFPGAType {
120
+ MachineClass *mc = &nmc->parent;
86
+ FPGA_AN505,
121
+ Object *obj;
87
+} MPS2TZFPGAType;
88
+
89
+typedef struct {
90
+ MachineClass parent;
91
+ MPS2TZFPGAType fpga_type;
92
+ uint32_t scc_id;
93
+} MPS2TZMachineClass;
94
+
95
+typedef struct {
96
+ MachineState parent;
97
+
98
+ IoTKit iotkit;
99
+ MemoryRegion psram;
100
+ MemoryRegion ssram1;
101
+ MemoryRegion ssram1_m;
102
+ MemoryRegion ssram23;
103
+ MPS2SCC scc;
104
+ MPS2FPGAIO fpgaio;
105
+ TZPPC ppc[5];
106
+ UnimplementedDeviceState ssram_mpc[3];
107
+ UnimplementedDeviceState spi[5];
108
+ UnimplementedDeviceState i2c[4];
109
+ UnimplementedDeviceState i2s_audio;
110
+ UnimplementedDeviceState gpio[5];
111
+ UnimplementedDeviceState dma[4];
112
+ UnimplementedDeviceState gfx;
113
+ CMSDKAPBUART uart[5];
114
+ SplitIRQ sec_resp_splitter;
115
+ qemu_or_irq uart_irq_orgate;
116
+} MPS2TZMachineState;
117
+
118
+#define TYPE_MPS2TZ_MACHINE "mps2tz"
119
+#define TYPE_MPS2TZ_AN505_MACHINE MACHINE_TYPE_NAME("mps2-an505")
120
+
121
+#define MPS2TZ_MACHINE(obj) \
122
+ OBJECT_CHECK(MPS2TZMachineState, obj, TYPE_MPS2TZ_MACHINE)
123
+#define MPS2TZ_MACHINE_GET_CLASS(obj) \
124
+ OBJECT_GET_CLASS(MPS2TZMachineClass, obj, TYPE_MPS2TZ_MACHINE)
125
+#define MPS2TZ_MACHINE_CLASS(klass) \
126
+ OBJECT_CLASS_CHECK(MPS2TZMachineClass, klass, TYPE_MPS2TZ_MACHINE)
127
+
128
+/* Main SYSCLK frequency in Hz */
129
+#define SYSCLK_FRQ 20000000
130
+
131
+/* Initialize the auxiliary RAM region @mr and map it into
132
+ * the memory map at @base.
133
+ */
134
+static void make_ram(MemoryRegion *mr, const char *name,
135
+ hwaddr base, hwaddr size)
136
+{
137
+ memory_region_init_ram(mr, NULL, name, size, &error_fatal);
138
+ memory_region_add_subregion(get_system_memory(), base, mr);
139
+}
140
+
141
+/* Create an alias of an entire original MemoryRegion @orig
142
+ * located at @base in the memory map.
143
+ */
144
+static void make_ram_alias(MemoryRegion *mr, const char *name,
145
+ MemoryRegion *orig, hwaddr base)
146
+{
147
+ memory_region_init_alias(mr, NULL, name, orig, 0,
148
+ memory_region_size(orig));
149
+ memory_region_add_subregion(get_system_memory(), base, mr);
150
+}
151
+
152
+static void init_sysbus_child(Object *parent, const char *childname,
153
+ void *child, size_t childsize,
154
+ const char *childtype)
155
+{
156
+ object_initialize(child, childsize, childtype);
157
+ object_property_add_child(parent, childname, OBJECT(child), &error_abort);
158
+ qdev_set_parent_bus(DEVICE(child), sysbus_get_default());
159
+
160
+}
161
+
162
+/* Most of the devices in the AN505 FPGA image sit behind
163
+ * Peripheral Protection Controllers. These data structures
164
+ * define the layout of which devices sit behind which PPCs.
165
+ * The devfn for each port is a function which creates, configures
166
+ * and initializes the device, returning the MemoryRegion which
167
+ * needs to be plugged into the downstream end of the PPC port.
168
+ */
169
+typedef MemoryRegion *MakeDevFn(MPS2TZMachineState *mms, void *opaque,
170
+ const char *name, hwaddr size);
171
+
172
+typedef struct PPCPortInfo {
173
+ const char *name;
174
+ MakeDevFn *devfn;
175
+ void *opaque;
176
+ hwaddr addr;
177
+ hwaddr size;
178
+} PPCPortInfo;
179
+
180
+typedef struct PPCInfo {
181
+ const char *name;
182
+ PPCPortInfo ports[TZ_NUM_PORTS];
183
+} PPCInfo;
184
+
185
+static MemoryRegion *make_unimp_dev(MPS2TZMachineState *mms,
186
+ void *opaque,
187
+ const char *name, hwaddr size)
188
+{
189
+ /* Initialize, configure and realize a TYPE_UNIMPLEMENTED_DEVICE,
190
+ * and return a pointer to its MemoryRegion.
191
+ */
192
+ UnimplementedDeviceState *uds = opaque;
193
+
194
+ init_sysbus_child(OBJECT(mms), name, uds,
195
+ sizeof(UnimplementedDeviceState),
196
+ TYPE_UNIMPLEMENTED_DEVICE);
197
+ qdev_prop_set_string(DEVICE(uds), "name", name);
198
+ qdev_prop_set_uint64(DEVICE(uds), "size", size);
199
+ object_property_set_bool(OBJECT(uds), true, "realized", &error_fatal);
200
+ return sysbus_mmio_get_region(SYS_BUS_DEVICE(uds), 0);
201
+}
202
+
203
+static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
204
+ const char *name, hwaddr size)
205
+{
206
+ CMSDKAPBUART *uart = opaque;
207
+ int i = uart - &mms->uart[0];
208
+ Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hds[i] : NULL;
209
+ int rxirqno = i * 2;
210
+ int txirqno = i * 2 + 1;
211
+ int combirqno = i + 10;
212
+ SysBusDevice *s;
213
+ DeviceState *iotkitdev = DEVICE(&mms->iotkit);
214
+ DeviceState *orgate_dev = DEVICE(&mms->uart_irq_orgate);
215
+
216
+ init_sysbus_child(OBJECT(mms), name, uart,
217
+ sizeof(mms->uart[0]), TYPE_CMSDK_APB_UART);
218
+ qdev_prop_set_chr(DEVICE(uart), "chardev", uartchr);
219
+ qdev_prop_set_uint32(DEVICE(uart), "pclk-frq", SYSCLK_FRQ);
220
+ object_property_set_bool(OBJECT(uart), true, "realized", &error_fatal);
221
+ s = SYS_BUS_DEVICE(uart);
222
+ sysbus_connect_irq(s, 0, qdev_get_gpio_in_named(iotkitdev,
223
+ "EXP_IRQ", txirqno));
224
+ sysbus_connect_irq(s, 1, qdev_get_gpio_in_named(iotkitdev,
225
+ "EXP_IRQ", rxirqno));
226
+ sysbus_connect_irq(s, 2, qdev_get_gpio_in(orgate_dev, i * 2));
227
+ sysbus_connect_irq(s, 3, qdev_get_gpio_in(orgate_dev, i * 2 + 1));
228
+ sysbus_connect_irq(s, 4, qdev_get_gpio_in_named(iotkitdev,
229
+ "EXP_IRQ", combirqno));
230
+ return sysbus_mmio_get_region(SYS_BUS_DEVICE(uart), 0);
231
+}
232
+
233
+static MemoryRegion *make_scc(MPS2TZMachineState *mms, void *opaque,
234
+ const char *name, hwaddr size)
235
+{
236
+ MPS2SCC *scc = opaque;
237
+ DeviceState *sccdev;
238
+ MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
239
+
240
+ object_initialize(scc, sizeof(mms->scc), TYPE_MPS2_SCC);
241
+ sccdev = DEVICE(scc);
242
+ qdev_set_parent_bus(sccdev, sysbus_get_default());
243
+ qdev_prop_set_uint32(sccdev, "scc-cfg4", 0x2);
244
+ qdev_prop_set_uint32(sccdev, "scc-aid", 0x02000008);
245
+ qdev_prop_set_uint32(sccdev, "scc-id", mmc->scc_id);
246
+ object_property_set_bool(OBJECT(scc), true, "realized", &error_fatal);
247
+ return sysbus_mmio_get_region(SYS_BUS_DEVICE(sccdev), 0);
248
+}
249
+
250
+static MemoryRegion *make_fpgaio(MPS2TZMachineState *mms, void *opaque,
251
+ const char *name, hwaddr size)
252
+{
253
+ MPS2FPGAIO *fpgaio = opaque;
254
+
255
+ object_initialize(fpgaio, sizeof(mms->fpgaio), TYPE_MPS2_FPGAIO);
256
+ qdev_set_parent_bus(DEVICE(fpgaio), sysbus_get_default());
257
+ object_property_set_bool(OBJECT(fpgaio), true, "realized", &error_fatal);
258
+ return sysbus_mmio_get_region(SYS_BUS_DEVICE(fpgaio), 0);
259
+}
260
+
261
+static void mps2tz_common_init(MachineState *machine)
262
+{
263
+ MPS2TZMachineState *mms = MPS2TZ_MACHINE(machine);
264
+ MachineClass *mc = MACHINE_GET_CLASS(machine);
265
+ MemoryRegion *system_memory = get_system_memory();
266
+ DeviceState *iotkitdev;
267
+ DeviceState *dev_splitter;
268
+ int i;
269
+
122
+
270
+ if (strcmp(machine->cpu_type, mc->default_cpu_type) != 0) {
123
+ if (strcmp(machine->cpu_type, mc->default_cpu_type) != 0) {
271
+ error_report("This board can only be used with CPU %s",
124
+ error_report("This board can only be used with %s",
272
+ mc->default_cpu_type);
125
+ mc->default_cpu_type);
273
+ exit(1);
126
+ exit(1);
274
+ }
127
+ }
275
+
128
+
276
+ init_sysbus_child(OBJECT(machine), "iotkit", &mms->iotkit,
129
+ obj = object_new_with_props(nmc->soc_type, OBJECT(machine), "soc",
277
+ sizeof(mms->iotkit), TYPE_IOTKIT);
130
+ &error_abort, NULL);
278
+ iotkitdev = DEVICE(&mms->iotkit);
131
+ object_property_set_uint(obj, "power-on-straps", hw_straps, &error_abort);
279
+ object_property_set_link(OBJECT(&mms->iotkit), OBJECT(system_memory),
132
+
280
+ "memory", &error_abort);
133
+ return NPCM7XX(obj);
281
+ qdev_prop_set_uint32(iotkitdev, "EXP_NUMIRQ", 92);
134
+}
282
+ qdev_prop_set_uint32(iotkitdev, "MAINCLK", SYSCLK_FRQ);
135
+
283
+ object_property_set_bool(OBJECT(&mms->iotkit), true, "realized",
136
+static void npcm750_evb_init(MachineState *machine)
284
+ &error_fatal);
137
+{
285
+
138
+ NPCM7xxState *soc;
286
+ /* The sec_resp_cfg output from the IoTKit must be split into multiple
139
+
287
+ * lines, one for each of the PPCs we create here.
140
+ soc = npcm7xx_create_soc(machine, NPCM750_EVB_POWER_ON_STRAPS);
288
+ */
141
+ npcm7xx_connect_dram(soc, machine->ram);
289
+ object_initialize(&mms->sec_resp_splitter, sizeof(mms->sec_resp_splitter),
142
+ qdev_realize(DEVICE(soc), NULL, &error_fatal);
290
+ TYPE_SPLIT_IRQ);
143
+
291
+ object_property_add_child(OBJECT(machine), "sec-resp-splitter",
144
+ npcm7xx_load_kernel(machine, soc);
292
+ OBJECT(&mms->sec_resp_splitter), &error_abort);
145
+}
293
+ object_property_set_int(OBJECT(&mms->sec_resp_splitter), 5,
146
+
294
+ "num-lines", &error_fatal);
147
+static void quanta_gsj_init(MachineState *machine)
295
+ object_property_set_bool(OBJECT(&mms->sec_resp_splitter), true,
148
+{
296
+ "realized", &error_fatal);
149
+ NPCM7xxState *soc;
297
+ dev_splitter = DEVICE(&mms->sec_resp_splitter);
150
+
298
+ qdev_connect_gpio_out_named(iotkitdev, "sec_resp_cfg", 0,
151
+ soc = npcm7xx_create_soc(machine, QUANTA_GSJ_POWER_ON_STRAPS);
299
+ qdev_get_gpio_in(dev_splitter, 0));
152
+ npcm7xx_connect_dram(soc, machine->ram);
300
+
153
+ qdev_realize(DEVICE(soc), NULL, &error_fatal);
301
+ /* The IoTKit sets up much of the memory layout, including
154
+
302
+ * the aliases between secure and non-secure regions in the
155
+ npcm7xx_load_kernel(machine, soc);
303
+ * address space. The FPGA itself contains:
156
+}
304
+ *
157
+
305
+ * 0x00000000..0x003fffff SSRAM1
158
+static void npcm7xx_set_soc_type(NPCM7xxMachineClass *nmc, const char *type)
306
+ * 0x00400000..0x007fffff alias of SSRAM1
159
+{
307
+ * 0x28000000..0x283fffff 4MB SSRAM2 + SSRAM3
160
+ NPCM7xxClass *sc = NPCM7XX_CLASS(object_class_by_name(type));
308
+ * 0x40100000..0x4fffffff AHB Master Expansion 1 interface devices
161
+ MachineClass *mc = MACHINE_CLASS(nmc);
309
+ * 0x80000000..0x80ffffff 16MB PSRAM
162
+
310
+ */
163
+ nmc->soc_type = type;
311
+
164
+ mc->default_cpus = mc->min_cpus = mc->max_cpus = sc->num_cpus;
312
+ /* The FPGA images have an odd combination of different RAMs,
165
+}
313
+ * because in hardware they are different implementations and
166
+
314
+ * connected to different buses, giving varying performance/size
167
+static void npcm7xx_machine_class_init(ObjectClass *oc, void *data)
315
+ * tradeoffs. For QEMU they're all just RAM, though. We arbitrarily
316
+ * call the 16MB our "system memory", as it's the largest lump.
317
+ */
318
+ memory_region_allocate_system_memory(&mms->psram,
319
+ NULL, "mps.ram", 0x01000000);
320
+ memory_region_add_subregion(system_memory, 0x80000000, &mms->psram);
321
+
322
+ /* The SSRAM memories should all be behind Memory Protection Controllers,
323
+ * but we don't implement that yet.
324
+ */
325
+ make_ram(&mms->ssram1, "mps.ssram1", 0x00000000, 0x00400000);
326
+ make_ram_alias(&mms->ssram1_m, "mps.ssram1_m", &mms->ssram1, 0x00400000);
327
+
328
+ make_ram(&mms->ssram23, "mps.ssram23", 0x28000000, 0x00400000);
329
+
330
+ /* The overflow IRQs for all UARTs are ORed together.
331
+ * Tx, Rx and "combined" IRQs are sent to the NVIC separately.
332
+ * Create the OR gate for this.
333
+ */
334
+ object_initialize(&mms->uart_irq_orgate, sizeof(mms->uart_irq_orgate),
335
+ TYPE_OR_IRQ);
336
+ object_property_add_child(OBJECT(mms), "uart-irq-orgate",
337
+ OBJECT(&mms->uart_irq_orgate), &error_abort);
338
+ object_property_set_int(OBJECT(&mms->uart_irq_orgate), 10, "num-lines",
339
+ &error_fatal);
340
+ object_property_set_bool(OBJECT(&mms->uart_irq_orgate), true,
341
+ "realized", &error_fatal);
342
+ qdev_connect_gpio_out(DEVICE(&mms->uart_irq_orgate), 0,
343
+ qdev_get_gpio_in_named(iotkitdev, "EXP_IRQ", 15));
344
+
345
+ /* Most of the devices in the FPGA are behind Peripheral Protection
346
+ * Controllers. The required order for initializing things is:
347
+ * + initialize the PPC
348
+ * + initialize, configure and realize downstream devices
349
+ * + connect downstream device MemoryRegions to the PPC
350
+ * + realize the PPC
351
+ * + map the PPC's MemoryRegions to the places in the address map
352
+ * where the downstream devices should appear
353
+ * + wire up the PPC's control lines to the IoTKit object
354
+ */
355
+
356
+ const PPCInfo ppcs[] = { {
357
+ .name = "apb_ppcexp0",
358
+ .ports = {
359
+ { "ssram-mpc0", make_unimp_dev, &mms->ssram_mpc[0],
360
+ 0x58007000, 0x1000 },
361
+ { "ssram-mpc1", make_unimp_dev, &mms->ssram_mpc[1],
362
+ 0x58008000, 0x1000 },
363
+ { "ssram-mpc2", make_unimp_dev, &mms->ssram_mpc[2],
364
+ 0x58009000, 0x1000 },
365
+ },
366
+ }, {
367
+ .name = "apb_ppcexp1",
368
+ .ports = {
369
+ { "spi0", make_unimp_dev, &mms->spi[0], 0x40205000, 0x1000 },
370
+ { "spi1", make_unimp_dev, &mms->spi[1], 0x40206000, 0x1000 },
371
+ { "spi2", make_unimp_dev, &mms->spi[2], 0x40209000, 0x1000 },
372
+ { "spi3", make_unimp_dev, &mms->spi[3], 0x4020a000, 0x1000 },
373
+ { "spi4", make_unimp_dev, &mms->spi[4], 0x4020b000, 0x1000 },
374
+ { "uart0", make_uart, &mms->uart[0], 0x40200000, 0x1000 },
375
+ { "uart1", make_uart, &mms->uart[1], 0x40201000, 0x1000 },
376
+ { "uart2", make_uart, &mms->uart[2], 0x40202000, 0x1000 },
377
+ { "uart3", make_uart, &mms->uart[3], 0x40203000, 0x1000 },
378
+ { "uart4", make_uart, &mms->uart[4], 0x40204000, 0x1000 },
379
+ { "i2c0", make_unimp_dev, &mms->i2c[0], 0x40207000, 0x1000 },
380
+ { "i2c1", make_unimp_dev, &mms->i2c[1], 0x40208000, 0x1000 },
381
+ { "i2c2", make_unimp_dev, &mms->i2c[2], 0x4020c000, 0x1000 },
382
+ { "i2c3", make_unimp_dev, &mms->i2c[3], 0x4020d000, 0x1000 },
383
+ },
384
+ }, {
385
+ .name = "apb_ppcexp2",
386
+ .ports = {
387
+ { "scc", make_scc, &mms->scc, 0x40300000, 0x1000 },
388
+ { "i2s-audio", make_unimp_dev, &mms->i2s_audio,
389
+ 0x40301000, 0x1000 },
390
+ { "fpgaio", make_fpgaio, &mms->fpgaio, 0x40302000, 0x1000 },
391
+ },
392
+ }, {
393
+ .name = "ahb_ppcexp0",
394
+ .ports = {
395
+ { "gfx", make_unimp_dev, &mms->gfx, 0x41000000, 0x140000 },
396
+ { "gpio0", make_unimp_dev, &mms->gpio[0], 0x40100000, 0x1000 },
397
+ { "gpio1", make_unimp_dev, &mms->gpio[1], 0x40101000, 0x1000 },
398
+ { "gpio2", make_unimp_dev, &mms->gpio[2], 0x40102000, 0x1000 },
399
+ { "gpio3", make_unimp_dev, &mms->gpio[3], 0x40103000, 0x1000 },
400
+ { "gpio4", make_unimp_dev, &mms->gpio[4], 0x40104000, 0x1000 },
401
+ },
402
+ }, {
403
+ .name = "ahb_ppcexp1",
404
+ .ports = {
405
+ { "dma0", make_unimp_dev, &mms->dma[0], 0x40110000, 0x1000 },
406
+ { "dma1", make_unimp_dev, &mms->dma[1], 0x40111000, 0x1000 },
407
+ { "dma2", make_unimp_dev, &mms->dma[2], 0x40112000, 0x1000 },
408
+ { "dma3", make_unimp_dev, &mms->dma[3], 0x40113000, 0x1000 },
409
+ },
410
+ },
411
+ };
412
+
413
+ for (i = 0; i < ARRAY_SIZE(ppcs); i++) {
414
+ const PPCInfo *ppcinfo = &ppcs[i];
415
+ TZPPC *ppc = &mms->ppc[i];
416
+ DeviceState *ppcdev;
417
+ int port;
418
+ char *gpioname;
419
+
420
+ init_sysbus_child(OBJECT(machine), ppcinfo->name, ppc,
421
+ sizeof(TZPPC), TYPE_TZ_PPC);
422
+ ppcdev = DEVICE(ppc);
423
+
424
+ for (port = 0; port < TZ_NUM_PORTS; port++) {
425
+ const PPCPortInfo *pinfo = &ppcinfo->ports[port];
426
+ MemoryRegion *mr;
427
+ char *portname;
428
+
429
+ if (!pinfo->devfn) {
430
+ continue;
431
+ }
432
+
433
+ mr = pinfo->devfn(mms, pinfo->opaque, pinfo->name, pinfo->size);
434
+ portname = g_strdup_printf("port[%d]", port);
435
+ object_property_set_link(OBJECT(ppc), OBJECT(mr),
436
+ portname, &error_fatal);
437
+ g_free(portname);
438
+ }
439
+
440
+ object_property_set_bool(OBJECT(ppc), true, "realized", &error_fatal);
441
+
442
+ for (port = 0; port < TZ_NUM_PORTS; port++) {
443
+ const PPCPortInfo *pinfo = &ppcinfo->ports[port];
444
+
445
+ if (!pinfo->devfn) {
446
+ continue;
447
+ }
448
+ sysbus_mmio_map(SYS_BUS_DEVICE(ppc), port, pinfo->addr);
449
+
450
+ gpioname = g_strdup_printf("%s_nonsec", ppcinfo->name);
451
+ qdev_connect_gpio_out_named(iotkitdev, gpioname, port,
452
+ qdev_get_gpio_in_named(ppcdev,
453
+ "cfg_nonsec",
454
+ port));
455
+ g_free(gpioname);
456
+ gpioname = g_strdup_printf("%s_ap", ppcinfo->name);
457
+ qdev_connect_gpio_out_named(iotkitdev, gpioname, port,
458
+ qdev_get_gpio_in_named(ppcdev,
459
+ "cfg_ap", port));
460
+ g_free(gpioname);
461
+ }
462
+
463
+ gpioname = g_strdup_printf("%s_irq_enable", ppcinfo->name);
464
+ qdev_connect_gpio_out_named(iotkitdev, gpioname, 0,
465
+ qdev_get_gpio_in_named(ppcdev,
466
+ "irq_enable", 0));
467
+ g_free(gpioname);
468
+ gpioname = g_strdup_printf("%s_irq_clear", ppcinfo->name);
469
+ qdev_connect_gpio_out_named(iotkitdev, gpioname, 0,
470
+ qdev_get_gpio_in_named(ppcdev,
471
+ "irq_clear", 0));
472
+ g_free(gpioname);
473
+ gpioname = g_strdup_printf("%s_irq_status", ppcinfo->name);
474
+ qdev_connect_gpio_out_named(ppcdev, "irq", 0,
475
+ qdev_get_gpio_in_named(iotkitdev,
476
+ gpioname, 0));
477
+ g_free(gpioname);
478
+
479
+ qdev_connect_gpio_out(dev_splitter, i,
480
+ qdev_get_gpio_in_named(ppcdev,
481
+ "cfg_sec_resp", 0));
482
+ }
483
+
484
+ /* In hardware this is a LAN9220; the LAN9118 is software compatible
485
+ * except that it doesn't support the checksum-offload feature.
486
+ * The ethernet controller is not behind a PPC.
487
+ */
488
+ lan9118_init(&nd_table[0], 0x42000000,
489
+ qdev_get_gpio_in_named(iotkitdev, "EXP_IRQ", 16));
490
+
491
+ create_unimplemented_device("FPGA NS PC", 0x48007000, 0x1000);
492
+
493
+ armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename, 0x400000);
494
+}
495
+
496
+static void mps2tz_class_init(ObjectClass *oc, void *data)
497
+{
168
+{
498
+ MachineClass *mc = MACHINE_CLASS(oc);
169
+ MachineClass *mc = MACHINE_CLASS(oc);
499
+
170
+
500
+ mc->init = mps2tz_common_init;
171
+ mc->no_floppy = 1;
501
+ mc->max_cpus = 1;
172
+ mc->no_cdrom = 1;
502
+}
173
+ mc->no_parallel = 1;
503
+
174
+ mc->default_ram_id = "ram";
504
+static void mps2tz_an505_class_init(ObjectClass *oc, void *data)
175
+ mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a9");
505
+{
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);
506
+ MachineClass *mc = MACHINE_CLASS(oc);
185
+ MachineClass *mc = MACHINE_CLASS(oc);
507
+ MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_CLASS(oc);
186
+
508
+
187
+ npcm7xx_set_soc_type(nmc, TYPE_NPCM750);
509
+ mc->desc = "ARM MPS2 with AN505 FPGA image for Cortex-M33";
188
+
510
+ mmc->fpga_type = FPGA_AN505;
189
+ mc->desc = "Nuvoton NPCM750 Evaluation Board (Cortex A9)";
511
+ mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m33");
190
+ mc->init = npcm750_evb_init;
512
+ mmc->scc_id = 0x41040000 | (505 << 4);
191
+ mc->default_ram_size = 512 * MiB;
513
+}
514
+
515
+static const TypeInfo mps2tz_info = {
516
+ .name = TYPE_MPS2TZ_MACHINE,
517
+ .parent = TYPE_MACHINE,
518
+ .abstract = true,
519
+ .instance_size = sizeof(MPS2TZMachineState),
520
+ .class_size = sizeof(MPS2TZMachineClass),
521
+ .class_init = mps2tz_class_init,
522
+};
192
+};
523
+
193
+
524
+static const TypeInfo mps2tz_an505_info = {
194
+static void gsj_machine_class_init(ObjectClass *oc, void *data)
525
+ .name = TYPE_MPS2TZ_AN505_MACHINE,
195
+{
526
+ .parent = TYPE_MPS2TZ_MACHINE,
196
+ NPCM7xxMachineClass *nmc = NPCM7XX_MACHINE_CLASS(oc);
527
+ .class_init = mps2tz_an505_class_init,
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;
528
+};
204
+};
529
+
205
+
530
+static void mps2tz_machine_init(void)
206
+static const TypeInfo npcm7xx_machine_types[] = {
531
+{
207
+ {
532
+ type_register_static(&mps2tz_info);
208
+ .name = TYPE_NPCM7XX_MACHINE,
533
+ type_register_static(&mps2tz_an505_info);
209
+ .parent = TYPE_MACHINE,
534
+}
210
+ .instance_size = sizeof(NPCM7xxMachine),
535
+
211
+ .class_size = sizeof(NPCM7xxMachineClass),
536
+type_init(mps2tz_machine_init);
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'))
537
--
239
--
538
2.16.2
240
2.20.1
539
241
540
242
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Havard Skinnemoen <hskinnemoen@google.com>
2
3
This is a minimalistic boot ROM written specifically for use with QEMU.
4
It supports loading the second-stage loader from SPI flash into RAM, SMP
5
boot, and not much else.
2
6
3
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
5
Message-id: 20180228193125.20577-9-richard.henderson@linaro.org
9
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
10
Message-id: 20200911052101.2602693-7-hskinnemoen@google.com
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
---
12
---
8
target/arm/translate.c | 46 ++++++++++++++++++++++++++++++++++++++++++----
13
.gitmodules | 3 +++
9
1 file changed, 42 insertions(+), 4 deletions(-)
14
MAINTAINERS | 2 ++
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
10
23
11
diff --git a/target/arm/translate.c b/target/arm/translate.c
24
diff --git a/.gitmodules b/.gitmodules
12
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
13
--- a/target/arm/translate.c
26
--- a/.gitmodules
14
+++ b/target/arm/translate.c
27
+++ b/.gitmodules
15
@@ -XXX,XX +XXX,XX @@ static const char *regnames[] =
28
@@ -XXX,XX +XXX,XX @@
16
{ "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
29
[submodule "meson"]
17
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "pc" };
30
    path = meson
18
31
    url = https://github.com/mesonbuild/meson/
19
+/* Function prototypes for gen_ functions calling Neon helpers. */
32
+[submodule "roms/vbootrom"]
20
+typedef void NeonGenThreeOpEnvFn(TCGv_i32, TCGv_env, TCGv_i32,
33
+    path = roms/vbootrom
21
+ TCGv_i32, TCGv_i32);
34
+    url = https://github.com/google/vbootrom.git
35
diff --git a/MAINTAINERS b/MAINTAINERS
36
index XXXXXXX..XXXXXXX 100644
37
--- a/MAINTAINERS
38
+++ b/MAINTAINERS
39
@@ -XXX,XX +XXX,XX @@ L: qemu-arm@nongnu.org
40
S: Supported
41
F: hw/*/npcm7xx*
42
F: include/hw/*/npcm7xx*
43
+F: pc-bios/npcm7xx_bootrom.bin
44
+F: roms/vbootrom
45
46
nSeries
47
M: Andrzej Zaborowski <balrogg@gmail.com>
48
diff --git a/pc-bios/README b/pc-bios/README
49
index XXXXXXX..XXXXXXX 100644
50
--- a/pc-bios/README
51
+++ b/pc-bios/README
52
@@ -XXX,XX +XXX,XX @@
53
("Simplified BSD License" or "FreeBSD License", SPDX: BSD-2-Clause). OpenSBI
54
source code also contains code reused from other projects desribed here:
55
https://github.com/riscv/opensbi/blob/master/ThirdPartyNotices.md.
22
+
56
+
23
/* initialize TCG globals. */
57
+- npcm7xx_bootrom.bin is a simplified, free (Apache 2.0) boot ROM for Nuvoton
24
void arm_translate_init(void)
58
+ NPCM7xx BMC devices. It currently implements the bare minimum to load, parse,
25
{
59
+ initialize and run boot images stored in SPI flash, but may grow more
26
@@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn)
60
+ features over time as needed. The source code is available at:
27
}
61
+ https://github.com/google/vbootrom
28
neon_store_reg64(cpu_V0, rd + pass);
62
diff --git a/pc-bios/meson.build b/pc-bios/meson.build
29
}
63
index XXXXXXX..XXXXXXX 100644
30
-
64
--- a/pc-bios/meson.build
31
-
65
+++ b/pc-bios/meson.build
32
break;
66
@@ -XXX,XX +XXX,XX @@ blobs = files(
33
- default: /* 14 and 15 are RESERVED */
67
'opensbi-riscv64-generic-fw_dynamic.bin',
34
- return 1;
68
'opensbi-riscv32-generic-fw_dynamic.elf',
35
+ case 14: /* VQRDMLAH scalar */
69
'opensbi-riscv64-generic-fw_dynamic.elf',
36
+ case 15: /* VQRDMLSH scalar */
70
+ 'npcm7xx_bootrom.bin',
37
+ {
71
)
38
+ NeonGenThreeOpEnvFn *fn;
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
39
+
119
+
40
+ if (!arm_dc_feature(s, ARM_FEATURE_V8_RDM)) {
120
clean:
41
+ return 1;
121
    rm -rf seabios/.config seabios/out seabios/builds
42
+ }
122
    $(MAKE) -C sgabios clean
43
+ if (u && ((rd | rn) & 1)) {
123
@@ -XXX,XX +XXX,XX @@ clean:
44
+ return 1;
124
    $(MAKE) -f Makefile.edk2 clean
45
+ }
125
    $(MAKE) -C opensbi clean
46
+ if (op == 14) {
126
    $(MAKE) -C qboot clean
47
+ if (size == 1) {
127
+    $(MAKE) -C vbootrom clean
48
+ fn = gen_helper_neon_qrdmlah_s16;
128
diff --git a/roms/vbootrom b/roms/vbootrom
49
+ } else {
129
new file mode 160000
50
+ fn = gen_helper_neon_qrdmlah_s32;
130
index XXXXXXX..XXXXXXX
51
+ }
131
--- /dev/null
52
+ } else {
132
+++ b/roms/vbootrom
53
+ if (size == 1) {
133
@@ -0,0 +1 @@
54
+ fn = gen_helper_neon_qrdmlsh_s16;
134
+Subproject commit 0c37a43527f0ee2b9584e7fb2fdc805e902635ac
55
+ } else {
56
+ fn = gen_helper_neon_qrdmlsh_s32;
57
+ }
58
+ }
59
+
60
+ tmp2 = neon_get_scalar(size, rm);
61
+ for (pass = 0; pass < (u ? 4 : 2); pass++) {
62
+ tmp = neon_load_reg(rn, pass);
63
+ tmp3 = neon_load_reg(rd, pass);
64
+ fn(tmp, cpu_env, tmp, tmp2, tmp3);
65
+ tcg_temp_free_i32(tmp3);
66
+ neon_store_reg(rd, pass, tmp);
67
+ }
68
+ tcg_temp_free_i32(tmp2);
69
+ }
70
+ break;
71
+ default:
72
+ g_assert_not_reached();
73
}
74
}
75
} else { /* size == 3 */
76
--
135
--
77
2.16.2
136
2.20.1
78
137
79
138
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Havard Skinnemoen <hskinnemoen@google.com>
2
2
3
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
3
If a -bios option is specified on the command line, load the image into
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
4
the internal ROM memory region, which contains the first instructions
5
Message-id: 20180228193125.20577-6-richard.henderson@linaro.org
5
run by the CPU after reset.
6
7
If -bios is not specified, the vbootrom included with qemu is loaded by
8
default.
9
10
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
11
Reviewed-by: Cédric Le Goater <clg@kaod.org>
12
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
13
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
14
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
15
Message-id: 20200911052101.2602693-8-hskinnemoen@google.com
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
---
17
---
8
target/arm/helper.h | 9 +++++
18
hw/arm/npcm7xx_boards.c | 32 ++++++++++++++++++++++++++++++++
9
target/arm/translate-a64.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++
19
1 file changed, 32 insertions(+)
10
target/arm/vec_helper.c | 74 +++++++++++++++++++++++++++++++++++++++++
11
3 files changed, 166 insertions(+)
12
20
13
diff --git a/target/arm/helper.h b/target/arm/helper.h
21
diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c
14
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
15
--- a/target/arm/helper.h
23
--- a/hw/arm/npcm7xx_boards.c
16
+++ b/target/arm/helper.h
24
+++ b/hw/arm/npcm7xx_boards.c
17
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_2(dc_zva, void, env, i64)
25
@@ -XXX,XX +XXX,XX @@
18
DEF_HELPER_FLAGS_2(neon_pmull_64_lo, TCG_CALL_NO_RWG_SE, i64, i64, i64)
26
#include "exec/address-spaces.h"
19
DEF_HELPER_FLAGS_2(neon_pmull_64_hi, TCG_CALL_NO_RWG_SE, i64, i64, i64)
27
#include "hw/arm/npcm7xx.h"
20
28
#include "hw/core/cpu.h"
21
+DEF_HELPER_FLAGS_5(gvec_qrdmlah_s16, TCG_CALL_NO_RWG,
29
+#include "hw/loader.h"
22
+ void, ptr, ptr, ptr, ptr, i32)
30
#include "qapi/error.h"
23
+DEF_HELPER_FLAGS_5(gvec_qrdmlsh_s16, TCG_CALL_NO_RWG,
31
+#include "qemu-common.h"
24
+ void, ptr, ptr, ptr, ptr, i32)
32
#include "qemu/units.h"
25
+DEF_HELPER_FLAGS_5(gvec_qrdmlah_s32, TCG_CALL_NO_RWG,
33
+#include "sysemu/sysemu.h"
26
+ void, ptr, ptr, ptr, ptr, i32)
34
27
+DEF_HELPER_FLAGS_5(gvec_qrdmlsh_s32, TCG_CALL_NO_RWG,
35
#define NPCM750_EVB_POWER_ON_STRAPS 0x00001ff7
28
+ void, ptr, ptr, ptr, ptr, i32)
36
#define QUANTA_GSJ_POWER_ON_STRAPS 0x00001fff
37
38
+static const char npcm7xx_default_bootrom[] = "npcm7xx_bootrom.bin";
29
+
39
+
30
#ifdef TARGET_AARCH64
40
+static void npcm7xx_load_bootrom(MachineState *machine, NPCM7xxState *soc)
31
#include "helper-a64.h"
32
#endif
33
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
34
index XXXXXXX..XXXXXXX 100644
35
--- a/target/arm/translate-a64.c
36
+++ b/target/arm/translate-a64.c
37
@@ -XXX,XX +XXX,XX @@ static void gen_gvec_op3(DisasContext *s, bool is_q, int rd,
38
vec_full_reg_size(s), gvec_op);
39
}
40
41
+/* Expand a 3-operand + env pointer operation using
42
+ * an out-of-line helper.
43
+ */
44
+static void gen_gvec_op3_env(DisasContext *s, bool is_q, int rd,
45
+ int rn, int rm, gen_helper_gvec_3_ptr *fn)
46
+{
41
+{
47
+ tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, rd),
42
+ g_autofree char *filename = NULL;
48
+ vec_full_reg_offset(s, rn),
43
+ int ret;
49
+ vec_full_reg_offset(s, rm), cpu_env,
50
+ is_q ? 16 : 8, vec_full_reg_size(s), 0, fn);
51
+}
52
+
44
+
53
/* Set ZF and NF based on a 64 bit result. This is alas fiddlier
45
+ if (!bios_name) {
54
* than the 32 bit equivalent.
46
+ bios_name = npcm7xx_default_bootrom;
55
*/
47
+ }
56
@@ -XXX,XX +XXX,XX @@ static void disas_simd_three_reg_same_fp16(DisasContext *s, uint32_t insn)
57
clear_vec_high(s, is_q, rd);
58
}
59
60
+/* AdvSIMD three same extra
61
+ * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
62
+ * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
63
+ * | 0 | Q | U | 0 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
64
+ * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
65
+ */
66
+static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn)
67
+{
68
+ int rd = extract32(insn, 0, 5);
69
+ int rn = extract32(insn, 5, 5);
70
+ int opcode = extract32(insn, 11, 4);
71
+ int rm = extract32(insn, 16, 5);
72
+ int size = extract32(insn, 22, 2);
73
+ bool u = extract32(insn, 29, 1);
74
+ bool is_q = extract32(insn, 30, 1);
75
+ int feature;
76
+
48
+
77
+ switch (u * 16 + opcode) {
49
+ filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
78
+ case 0x10: /* SQRDMLAH (vector) */
50
+ if (!filename) {
79
+ case 0x11: /* SQRDMLSH (vector) */
51
+ error_report("Could not find ROM image '%s'", bios_name);
80
+ if (size != 1 && size != 2) {
52
+ if (!machine->kernel_filename) {
81
+ unallocated_encoding(s);
53
+ /* We can't boot without a bootrom or a kernel image. */
82
+ return;
54
+ exit(1);
83
+ }
55
+ }
84
+ feature = ARM_FEATURE_V8_RDM;
85
+ break;
86
+ default:
87
+ unallocated_encoding(s);
88
+ return;
56
+ return;
89
+ }
57
+ }
90
+ if (!arm_dc_feature(s, feature)) {
58
+ ret = load_image_mr(filename, &soc->irom);
91
+ unallocated_encoding(s);
59
+ if (ret < 0) {
92
+ return;
60
+ error_report("Failed to load ROM image '%s'", filename);
93
+ }
61
+ exit(1);
94
+ if (!fp_access_check(s)) {
95
+ return;
96
+ }
97
+
98
+ switch (opcode) {
99
+ case 0x0: /* SQRDMLAH (vector) */
100
+ switch (size) {
101
+ case 1:
102
+ gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlah_s16);
103
+ break;
104
+ case 2:
105
+ gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlah_s32);
106
+ break;
107
+ default:
108
+ g_assert_not_reached();
109
+ }
110
+ return;
111
+
112
+ case 0x1: /* SQRDMLSH (vector) */
113
+ switch (size) {
114
+ case 1:
115
+ gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlsh_s16);
116
+ break;
117
+ case 2:
118
+ gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlsh_s32);
119
+ break;
120
+ default:
121
+ g_assert_not_reached();
122
+ }
123
+ return;
124
+
125
+ default:
126
+ g_assert_not_reached();
127
+ }
62
+ }
128
+}
63
+}
129
+
64
+
130
static void handle_2misc_widening(DisasContext *s, int opcode, bool is_q,
65
static void npcm7xx_connect_dram(NPCM7xxState *soc, MemoryRegion *dram)
131
int size, int rn, int rd)
132
{
66
{
133
@@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_imm2(DisasContext *s, uint32_t insn)
67
memory_region_add_subregion(get_system_memory(), NPCM7XX_DRAM_BA, dram);
134
static const AArch64DecodeTable data_proc_simd[] = {
68
@@ -XXX,XX +XXX,XX @@ static void npcm750_evb_init(MachineState *machine)
135
/* pattern , mask , fn */
69
npcm7xx_connect_dram(soc, machine->ram);
136
{ 0x0e200400, 0x9f200400, disas_simd_three_reg_same },
70
qdev_realize(DEVICE(soc), NULL, &error_fatal);
137
+ { 0x0e008400, 0x9f208400, disas_simd_three_reg_same_extra },
71
138
{ 0x0e200000, 0x9f200c00, disas_simd_three_reg_diff },
72
+ npcm7xx_load_bootrom(machine, soc);
139
{ 0x0e200800, 0x9f3e0c00, disas_simd_two_reg_misc },
73
npcm7xx_load_kernel(machine, soc);
140
{ 0x0e300800, 0x9f3e0c00, disas_simd_across_lanes },
141
diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c
142
index XXXXXXX..XXXXXXX 100644
143
--- a/target/arm/vec_helper.c
144
+++ b/target/arm/vec_helper.c
145
@@ -XXX,XX +XXX,XX @@
146
147
#define SET_QC() env->vfp.xregs[ARM_VFP_FPSCR] |= CPSR_Q
148
149
+static void clear_tail(void *vd, uintptr_t opr_sz, uintptr_t max_sz)
150
+{
151
+ uint64_t *d = vd + opr_sz;
152
+ uintptr_t i;
153
+
154
+ for (i = opr_sz; i < max_sz; i += 8) {
155
+ *d++ = 0;
156
+ }
157
+}
158
+
159
/* Signed saturating rounding doubling multiply-accumulate high half, 16-bit */
160
static uint16_t inl_qrdmlah_s16(CPUARMState *env, int16_t src1,
161
int16_t src2, int16_t src3)
162
@@ -XXX,XX +XXX,XX @@ uint32_t HELPER(neon_qrdmlah_s16)(CPUARMState *env, uint32_t src1,
163
return deposit32(e1, 16, 16, e2);
164
}
74
}
165
75
166
+void HELPER(gvec_qrdmlah_s16)(void *vd, void *vn, void *vm,
76
@@ -XXX,XX +XXX,XX @@ static void quanta_gsj_init(MachineState *machine)
167
+ void *ve, uint32_t desc)
77
npcm7xx_connect_dram(soc, machine->ram);
168
+{
78
qdev_realize(DEVICE(soc), NULL, &error_fatal);
169
+ uintptr_t opr_sz = simd_oprsz(desc);
79
170
+ int16_t *d = vd;
80
+ npcm7xx_load_bootrom(machine, soc);
171
+ int16_t *n = vn;
81
npcm7xx_load_kernel(machine, soc);
172
+ int16_t *m = vm;
173
+ CPUARMState *env = ve;
174
+ uintptr_t i;
175
+
176
+ for (i = 0; i < opr_sz / 2; ++i) {
177
+ d[i] = inl_qrdmlah_s16(env, n[i], m[i], d[i]);
178
+ }
179
+ clear_tail(d, opr_sz, simd_maxsz(desc));
180
+}
181
+
182
/* Signed saturating rounding doubling multiply-subtract high half, 16-bit */
183
static uint16_t inl_qrdmlsh_s16(CPUARMState *env, int16_t src1,
184
int16_t src2, int16_t src3)
185
@@ -XXX,XX +XXX,XX @@ uint32_t HELPER(neon_qrdmlsh_s16)(CPUARMState *env, uint32_t src1,
186
return deposit32(e1, 16, 16, e2);
187
}
82
}
188
83
189
+void HELPER(gvec_qrdmlsh_s16)(void *vd, void *vn, void *vm,
190
+ void *ve, uint32_t desc)
191
+{
192
+ uintptr_t opr_sz = simd_oprsz(desc);
193
+ int16_t *d = vd;
194
+ int16_t *n = vn;
195
+ int16_t *m = vm;
196
+ CPUARMState *env = ve;
197
+ uintptr_t i;
198
+
199
+ for (i = 0; i < opr_sz / 2; ++i) {
200
+ d[i] = inl_qrdmlsh_s16(env, n[i], m[i], d[i]);
201
+ }
202
+ clear_tail(d, opr_sz, simd_maxsz(desc));
203
+}
204
+
205
/* Signed saturating rounding doubling multiply-accumulate high half, 32-bit */
206
uint32_t HELPER(neon_qrdmlah_s32)(CPUARMState *env, int32_t src1,
207
int32_t src2, int32_t src3)
208
@@ -XXX,XX +XXX,XX @@ uint32_t HELPER(neon_qrdmlah_s32)(CPUARMState *env, int32_t src1,
209
return ret;
210
}
211
212
+void HELPER(gvec_qrdmlah_s32)(void *vd, void *vn, void *vm,
213
+ void *ve, uint32_t desc)
214
+{
215
+ uintptr_t opr_sz = simd_oprsz(desc);
216
+ int32_t *d = vd;
217
+ int32_t *n = vn;
218
+ int32_t *m = vm;
219
+ CPUARMState *env = ve;
220
+ uintptr_t i;
221
+
222
+ for (i = 0; i < opr_sz / 4; ++i) {
223
+ d[i] = helper_neon_qrdmlah_s32(env, n[i], m[i], d[i]);
224
+ }
225
+ clear_tail(d, opr_sz, simd_maxsz(desc));
226
+}
227
+
228
/* Signed saturating rounding doubling multiply-subtract high half, 32-bit */
229
uint32_t HELPER(neon_qrdmlsh_s32)(CPUARMState *env, int32_t src1,
230
int32_t src2, int32_t src3)
231
@@ -XXX,XX +XXX,XX @@ uint32_t HELPER(neon_qrdmlsh_s32)(CPUARMState *env, int32_t src1,
232
}
233
return ret;
234
}
235
+
236
+void HELPER(gvec_qrdmlsh_s32)(void *vd, void *vn, void *vm,
237
+ void *ve, uint32_t desc)
238
+{
239
+ uintptr_t opr_sz = simd_oprsz(desc);
240
+ int32_t *d = vd;
241
+ int32_t *n = vn;
242
+ int32_t *m = vm;
243
+ CPUARMState *env = ve;
244
+ uintptr_t i;
245
+
246
+ for (i = 0; i < opr_sz / 4; ++i) {
247
+ d[i] = helper_neon_qrdmlsh_s32(env, n[i], m[i], d[i]);
248
+ }
249
+ clear_tail(d, opr_sz, simd_maxsz(desc));
250
+}
251
--
84
--
252
2.16.2
85
2.20.1
253
86
254
87
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Havard Skinnemoen <hskinnemoen@google.com>
2
2
3
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
3
This supports reading and writing OTP fuses and keys. Only fuse reading
4
Message-id: 20180228193125.20577-15-richard.henderson@linaro.org
4
has been tested. Protection is not implemented.
5
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
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
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
---
13
---
8
target/arm/translate.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++
14
include/hw/arm/npcm7xx.h | 3 +
9
1 file changed, 61 insertions(+)
15
include/hw/nvram/npcm7xx_otp.h | 79 ++++++
16
hw/arm/npcm7xx.c | 29 +++
17
hw/nvram/npcm7xx_otp.c | 440 +++++++++++++++++++++++++++++++++
18
hw/nvram/meson.build | 1 +
19
5 files changed, 552 insertions(+)
20
create mode 100644 include/hw/nvram/npcm7xx_otp.h
21
create mode 100644 hw/nvram/npcm7xx_otp.c
10
22
11
diff --git a/target/arm/translate.c b/target/arm/translate.c
23
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
12
index XXXXXXX..XXXXXXX 100644
24
index XXXXXXX..XXXXXXX 100644
13
--- a/target/arm/translate.c
25
--- a/include/hw/arm/npcm7xx.h
14
+++ b/target/arm/translate.c
26
+++ b/include/hw/arm/npcm7xx.h
15
@@ -XXX,XX +XXX,XX @@ static int disas_neon_insn_3same_ext(DisasContext *s, uint32_t insn)
27
@@ -XXX,XX +XXX,XX @@
16
return 0;
28
#include "hw/cpu/a9mpcore.h"
29
#include "hw/misc/npcm7xx_clk.h"
30
#include "hw/misc/npcm7xx_gcr.h"
31
+#include "hw/nvram/npcm7xx_otp.h"
32
#include "hw/timer/npcm7xx_timer.h"
33
#include "target/arm/cpu.h"
34
35
@@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState {
36
NPCM7xxGCRState gcr;
37
NPCM7xxCLKState clk;
38
NPCM7xxTimerCtrlState tim[3];
39
+ NPCM7xxOTPState key_storage;
40
+ NPCM7xxOTPState fuse_array;
41
} NPCM7xxState;
42
43
#define TYPE_NPCM7XX "npcm7xx"
44
diff --git a/include/hw/nvram/npcm7xx_otp.h b/include/hw/nvram/npcm7xx_otp.h
45
new file mode 100644
46
index XXXXXXX..XXXXXXX
47
--- /dev/null
48
+++ b/include/hw/nvram/npcm7xx_otp.h
49
@@ -XXX,XX +XXX,XX @@
50
+/*
51
+ * Nuvoton NPCM7xx OTP (Fuse Array) Interface
52
+ *
53
+ * Copyright 2020 Google LLC
54
+ *
55
+ * This program is free software; you can redistribute it and/or modify it
56
+ * under the terms of the GNU General Public License as published by the
57
+ * Free Software Foundation; either version 2 of the License, or
58
+ * (at your option) any later version.
59
+ *
60
+ * This program is distributed in the hope that it will be useful, but WITHOUT
61
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
62
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
63
+ * for more details.
64
+ */
65
+#ifndef NPCM7XX_OTP_H
66
+#define NPCM7XX_OTP_H
67
+
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
131
--- a/hw/arm/npcm7xx.c
132
+++ b/hw/arm/npcm7xx.c
133
@@ -XXX,XX +XXX,XX @@
134
#define NPCM7XX_MMIO_BA (0x80000000)
135
#define NPCM7XX_MMIO_SZ (0x7ffd0000)
136
137
+/* OTP key storage and fuse strap array */
138
+#define NPCM7XX_OTP1_BA (0xf0189000)
139
+#define NPCM7XX_OTP2_BA (0xf018a000)
140
+
141
/* Core system modules. */
142
#define NPCM7XX_L2C_BA (0xf03fc000)
143
#define NPCM7XX_CPUP_BA (0xf03fe000)
144
@@ -XXX,XX +XXX,XX @@ void npcm7xx_load_kernel(MachineState *machine, NPCM7xxState *soc)
145
arm_load_kernel(&soc->cpu[0], machine, &npcm7xx_binfo);
17
}
146
}
18
147
19
+/* Advanced SIMD two registers and a scalar extension.
148
+static void npcm7xx_init_fuses(NPCM7xxState *s)
20
+ * 31 24 23 22 20 16 12 11 10 9 8 3 0
149
+{
21
+ * +-----------------+----+---+----+----+----+---+----+---+----+---------+----+
150
+ NPCM7xxClass *nc = NPCM7XX_GET_CLASS(s);
22
+ * | 1 1 1 1 1 1 1 0 | o1 | D | o2 | Vn | Vd | 1 | o3 | 0 | o4 | N Q M U | Vm |
151
+ uint32_t value;
23
+ * +-----------------+----+---+----+----+----+---+----+---+----+---------+----+
152
+
24
+ *
153
+ /*
154
+ * The initial mask of disabled modules indicates the chip derivative (e.g.
155
+ * NPCM750 or NPCM730).
156
+ */
157
+ value = tswap32(nc->disabled_modules);
158
+ npcm7xx_otp_array_write(&s->fuse_array, &value, NPCM7XX_FUSE_DERIVATIVE,
159
+ sizeof(value));
160
+}
161
+
162
static qemu_irq npcm7xx_irq(NPCM7xxState *s, int n)
163
{
164
return qdev_get_gpio_in(DEVICE(&s->a9mpcore), n);
165
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj)
166
object_property_add_alias(obj, "power-on-straps", OBJECT(&s->gcr),
167
"power-on-straps");
168
object_initialize_child(obj, "clk", &s->clk, TYPE_NPCM7XX_CLK);
169
+ object_initialize_child(obj, "otp1", &s->key_storage,
170
+ TYPE_NPCM7XX_KEY_STORAGE);
171
+ object_initialize_child(obj, "otp2", &s->fuse_array,
172
+ TYPE_NPCM7XX_FUSE_ARRAY);
173
174
for (i = 0; i < ARRAY_SIZE(s->tim); i++) {
175
object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER);
176
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
177
sysbus_realize(SYS_BUS_DEVICE(&s->clk), &error_abort);
178
sysbus_mmio_map(SYS_BUS_DEVICE(&s->clk), 0, NPCM7XX_CLK_BA);
179
180
+ /* OTP key storage and fuse strap array. Cannot fail. */
181
+ sysbus_realize(SYS_BUS_DEVICE(&s->key_storage), &error_abort);
182
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->key_storage), 0, NPCM7XX_OTP1_BA);
183
+ sysbus_realize(SYS_BUS_DEVICE(&s->fuse_array), &error_abort);
184
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->fuse_array), 0, NPCM7XX_OTP2_BA);
185
+ npcm7xx_init_fuses(s);
186
+
187
/* Timer Modules (TIM). Cannot fail. */
188
QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_tim_addr) != ARRAY_SIZE(s->tim));
189
for (i = 0; i < ARRAY_SIZE(s->tim); i++) {
190
diff --git a/hw/nvram/npcm7xx_otp.c b/hw/nvram/npcm7xx_otp.c
191
new file mode 100644
192
index XXXXXXX..XXXXXXX
193
--- /dev/null
194
+++ b/hw/nvram/npcm7xx_otp.c
195
@@ -XXX,XX +XXX,XX @@
196
+/*
197
+ * Nuvoton NPCM7xx OTP (Fuse Array) Interface
198
+ *
199
+ * Copyright 2020 Google LLC
200
+ *
201
+ * This program is free software; you can redistribute it and/or modify it
202
+ * under the terms of the GNU General Public License as published by the
203
+ * Free Software Foundation; either version 2 of the License, or
204
+ * (at your option) any later version.
205
+ *
206
+ * This program is distributed in the hope that it will be useful, but WITHOUT
207
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
208
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
209
+ * for more details.
25
+ */
210
+ */
26
+
211
+
27
+static int disas_neon_insn_2reg_scalar_ext(DisasContext *s, uint32_t insn)
212
+#include "qemu/osdep.h"
28
+{
213
+
29
+ int rd, rn, rm, rot, size, opr_sz;
214
+#include "hw/nvram/npcm7xx_otp.h"
30
+ TCGv_ptr fpst;
215
+#include "migration/vmstate.h"
31
+ bool q;
216
+#include "qapi/error.h"
32
+
217
+#include "qemu/bitops.h"
33
+ q = extract32(insn, 6, 1);
218
+#include "qemu/log.h"
34
+ VFP_DREG_D(rd, insn);
219
+#include "qemu/module.h"
35
+ VFP_DREG_N(rn, insn);
220
+#include "qemu/units.h"
36
+ VFP_DREG_M(rm, insn);
221
+
37
+ if ((rd | rn) & q) {
222
+/* Each module has 4 KiB of register space. Only a fraction of it is used. */
38
+ return 1;
223
+#define NPCM7XX_OTP_REGS_SIZE (4 * KiB)
224
+
225
+/* 32-bit register indices. */
226
+typedef enum NPCM7xxOTPRegister {
227
+ NPCM7XX_OTP_FST,
228
+ NPCM7XX_OTP_FADDR,
229
+ NPCM7XX_OTP_FDATA,
230
+ NPCM7XX_OTP_FCFG,
231
+ /* Offset 0x10 is FKEYIND in OTP1, FUSTRAP in OTP2 */
232
+ NPCM7XX_OTP_FKEYIND = 0x0010 / sizeof(uint32_t),
233
+ NPCM7XX_OTP_FUSTRAP = 0x0010 / sizeof(uint32_t),
234
+ NPCM7XX_OTP_FCTL,
235
+ NPCM7XX_OTP_REGS_END,
236
+} NPCM7xxOTPRegister;
237
+
238
+/* Register field definitions. */
239
+#define FST_RIEN BIT(2)
240
+#define FST_RDST BIT(1)
241
+#define FST_RDY BIT(0)
242
+#define FST_RO_MASK (FST_RDST | FST_RDY)
243
+
244
+#define FADDR_BYTEADDR(rv) extract32((rv), 0, 10)
245
+#define FADDR_BITPOS(rv) extract32((rv), 10, 3)
246
+
247
+#define FDATA_CLEAR 0x00000001
248
+
249
+#define FCFG_FDIS BIT(31)
250
+#define FCFG_FCFGLK_MASK 0x00ff0000
251
+
252
+#define FCTL_PROG_CMD1 0x00000001
253
+#define FCTL_PROG_CMD2 0xbf79e5d0
254
+#define FCTL_READ_CMD 0x00000002
255
+
256
+/**
257
+ * struct NPCM7xxOTPClass - OTP module class.
258
+ * @parent: System bus device class.
259
+ * @mmio_ops: MMIO register operations for this type of module.
260
+ *
261
+ * The two OTP modules (key-storage and fuse-array) have slightly different
262
+ * behavior, so we give them different MMIO register operations.
263
+ */
264
+struct NPCM7xxOTPClass {
265
+ SysBusDeviceClass parent;
266
+
267
+ const MemoryRegionOps *mmio_ops;
268
+};
269
+
270
+#define NPCM7XX_OTP_CLASS(klass) \
271
+ OBJECT_CLASS_CHECK(NPCM7xxOTPClass, (klass), TYPE_NPCM7XX_OTP)
272
+#define NPCM7XX_OTP_GET_CLASS(obj) \
273
+ OBJECT_GET_CLASS(NPCM7xxOTPClass, (obj), TYPE_NPCM7XX_OTP)
274
+
275
+static uint8_t ecc_encode_nibble(uint8_t n)
276
+{
277
+ uint8_t result = n;
278
+
279
+ result |= (((n >> 0) & 1) ^ ((n >> 1) & 1)) << 4;
280
+ result |= (((n >> 2) & 1) ^ ((n >> 3) & 1)) << 5;
281
+ result |= (((n >> 0) & 1) ^ ((n >> 2) & 1)) << 6;
282
+ result |= (((n >> 1) & 1) ^ ((n >> 3) & 1)) << 7;
283
+
284
+ return result;
285
+}
286
+
287
+void npcm7xx_otp_array_write(NPCM7xxOTPState *s, const void *data,
288
+ unsigned int offset, unsigned int len)
289
+{
290
+ const uint8_t *src = data;
291
+ uint8_t *dst = &s->array[offset];
292
+
293
+ while (len-- > 0) {
294
+ uint8_t c = *src++;
295
+
296
+ *dst++ = ecc_encode_nibble(extract8(c, 0, 4));
297
+ *dst++ = ecc_encode_nibble(extract8(c, 4, 4));
39
+ }
298
+ }
40
+
299
+}
41
+ if ((insn & 0xff000f10) == 0xfe000800) {
300
+
42
+ /* VCMLA (indexed) -- 1111 1110 S.RR .... .... 1000 ...0 .... */
301
+/* Common register read handler for both OTP classes. */
43
+ rot = extract32(insn, 20, 2);
302
+static uint64_t npcm7xx_otp_read(NPCM7xxOTPState *s, NPCM7xxOTPRegister reg)
44
+ size = extract32(insn, 23, 1);
303
+{
45
+ if (!arm_dc_feature(s, ARM_FEATURE_V8_FCMA)
304
+ uint32_t value = 0;
46
+ || (!size && !arm_dc_feature(s, ARM_FEATURE_V8_FP16))) {
305
+
47
+ return 1;
306
+ switch (reg) {
307
+ case NPCM7XX_OTP_FST:
308
+ case NPCM7XX_OTP_FADDR:
309
+ case NPCM7XX_OTP_FDATA:
310
+ case NPCM7XX_OTP_FCFG:
311
+ value = s->regs[reg];
312
+ break;
313
+
314
+ case NPCM7XX_OTP_FCTL:
315
+ qemu_log_mask(LOG_GUEST_ERROR,
316
+ "%s: read from write-only FCTL register\n",
317
+ DEVICE(s)->canonical_path);
318
+ break;
319
+
320
+ default:
321
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: read from invalid offset 0x%zx\n",
322
+ DEVICE(s)->canonical_path, reg * sizeof(uint32_t));
323
+ break;
324
+ }
325
+
326
+ return value;
327
+}
328
+
329
+/* Read a byte from the OTP array into the data register. */
330
+static void npcm7xx_otp_read_array(NPCM7xxOTPState *s)
331
+{
332
+ uint32_t faddr = s->regs[NPCM7XX_OTP_FADDR];
333
+
334
+ s->regs[NPCM7XX_OTP_FDATA] = s->array[FADDR_BYTEADDR(faddr)];
335
+ s->regs[NPCM7XX_OTP_FST] |= FST_RDST | FST_RDY;
336
+}
337
+
338
+/* Program a byte from the data register into the OTP array. */
339
+static void npcm7xx_otp_program_array(NPCM7xxOTPState *s)
340
+{
341
+ uint32_t faddr = s->regs[NPCM7XX_OTP_FADDR];
342
+
343
+ /* Bits can only go 0->1, never 1->0. */
344
+ s->array[FADDR_BYTEADDR(faddr)] |= (1U << FADDR_BITPOS(faddr));
345
+ s->regs[NPCM7XX_OTP_FST] |= FST_RDST | FST_RDY;
346
+}
347
+
348
+/* Compute the next value of the FCFG register. */
349
+static uint32_t npcm7xx_otp_compute_fcfg(uint32_t cur_value, uint32_t new_value)
350
+{
351
+ uint32_t lock_mask;
352
+ uint32_t value;
353
+
354
+ /*
355
+ * FCFGLK holds sticky bits 16..23, indicating which bits in FPRGLK (8..15)
356
+ * and FRDLK (0..7) that are read-only.
357
+ */
358
+ lock_mask = (cur_value & FCFG_FCFGLK_MASK) >> 8;
359
+ lock_mask |= lock_mask >> 8;
360
+ /* FDIS and FCFGLK bits are sticky (write 1 to set; can't clear). */
361
+ value = cur_value & (FCFG_FDIS | FCFG_FCFGLK_MASK);
362
+ /* Preserve read-only bits in FPRGLK and FRDLK */
363
+ value |= cur_value & lock_mask;
364
+ /* Set all bits that aren't read-only. */
365
+ value |= new_value & ~lock_mask;
366
+
367
+ return value;
368
+}
369
+
370
+/* Common register write handler for both OTP classes. */
371
+static void npcm7xx_otp_write(NPCM7xxOTPState *s, NPCM7xxOTPRegister reg,
372
+ uint32_t value)
373
+{
374
+ switch (reg) {
375
+ case NPCM7XX_OTP_FST:
376
+ /* RDST is cleared by writing 1 to it. */
377
+ if (value & FST_RDST) {
378
+ s->regs[NPCM7XX_OTP_FST] &= ~FST_RDST;
48
+ }
379
+ }
380
+ /* Preserve read-only and write-one-to-clear bits */
381
+ value &= ~FST_RO_MASK;
382
+ value |= s->regs[NPCM7XX_OTP_FST] & FST_RO_MASK;
383
+ break;
384
+
385
+ case NPCM7XX_OTP_FADDR:
386
+ break;
387
+
388
+ case NPCM7XX_OTP_FDATA:
389
+ /*
390
+ * This register is cleared by writing a magic value to it; no other
391
+ * values can be written.
392
+ */
393
+ if (value == FDATA_CLEAR) {
394
+ value = 0;
395
+ } else {
396
+ value = s->regs[NPCM7XX_OTP_FDATA];
397
+ }
398
+ break;
399
+
400
+ case NPCM7XX_OTP_FCFG:
401
+ value = npcm7xx_otp_compute_fcfg(s->regs[NPCM7XX_OTP_FCFG], value);
402
+ break;
403
+
404
+ case NPCM7XX_OTP_FCTL:
405
+ switch (value) {
406
+ case FCTL_READ_CMD:
407
+ npcm7xx_otp_read_array(s);
408
+ break;
409
+
410
+ case FCTL_PROG_CMD1:
411
+ /*
412
+ * Programming requires writing two separate magic values to this
413
+ * register; this is the first one. Just store it so it can be
414
+ * verified later when the second magic value is received.
415
+ */
416
+ break;
417
+
418
+ case FCTL_PROG_CMD2:
419
+ /*
420
+ * Only initiate programming if we received the first half of the
421
+ * command immediately before this one.
422
+ */
423
+ if (s->regs[NPCM7XX_OTP_FCTL] == FCTL_PROG_CMD1) {
424
+ npcm7xx_otp_program_array(s);
425
+ }
426
+ break;
427
+
428
+ default:
429
+ qemu_log_mask(LOG_GUEST_ERROR,
430
+ "%s: unrecognized FCNTL value 0x%" PRIx32 "\n",
431
+ DEVICE(s)->canonical_path, value);
432
+ break;
433
+ }
434
+ if (value != FCTL_PROG_CMD1) {
435
+ value = 0;
436
+ }
437
+ break;
438
+
439
+ default:
440
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: write to invalid offset 0x%zx\n",
441
+ DEVICE(s)->canonical_path, reg * sizeof(uint32_t));
442
+ return;
443
+ }
444
+
445
+ s->regs[reg] = value;
446
+}
447
+
448
+/* Register read handler specific to the fuse array OTP module. */
449
+static uint64_t npcm7xx_fuse_array_read(void *opaque, hwaddr addr,
450
+ unsigned int size)
451
+{
452
+ NPCM7xxOTPRegister reg = addr / sizeof(uint32_t);
453
+ NPCM7xxOTPState *s = opaque;
454
+ uint32_t value;
455
+
456
+ /*
457
+ * Only the Fuse Strap register needs special handling; all other registers
458
+ * work the same way for both kinds of OTP modules.
459
+ */
460
+ if (reg != NPCM7XX_OTP_FUSTRAP) {
461
+ value = npcm7xx_otp_read(s, reg);
49
+ } else {
462
+ } else {
50
+ return 1;
463
+ /* FUSTRAP is stored as three copies in the OTP array. */
464
+ uint32_t fustrap[3];
465
+
466
+ memcpy(fustrap, &s->array[0], sizeof(fustrap));
467
+
468
+ /* Determine value by a majority vote on each bit. */
469
+ value = (fustrap[0] & fustrap[1]) | (fustrap[0] & fustrap[2]) |
470
+ (fustrap[1] & fustrap[2]);
51
+ }
471
+ }
52
+
472
+
53
+ if (s->fp_excp_el) {
473
+ return value;
54
+ gen_exception_insn(s, 4, EXCP_UDEF,
474
+}
55
+ syn_fp_access_trap(1, 0xe, false), s->fp_excp_el);
475
+
56
+ return 0;
476
+/* Register write handler specific to the fuse array OTP module. */
477
+static void npcm7xx_fuse_array_write(void *opaque, hwaddr addr, uint64_t v,
478
+ unsigned int size)
479
+{
480
+ NPCM7xxOTPRegister reg = addr / sizeof(uint32_t);
481
+ NPCM7xxOTPState *s = opaque;
482
+
483
+ /*
484
+ * The Fuse Strap register is read-only. Other registers are handled by
485
+ * common code.
486
+ */
487
+ if (reg != NPCM7XX_OTP_FUSTRAP) {
488
+ npcm7xx_otp_write(s, reg, v);
57
+ }
489
+ }
58
+ if (!s->vfp_enabled) {
490
+}
59
+ return 1;
491
+
492
+static const MemoryRegionOps npcm7xx_fuse_array_ops = {
493
+ .read = npcm7xx_fuse_array_read,
494
+ .write = npcm7xx_fuse_array_write,
495
+ .endianness = DEVICE_LITTLE_ENDIAN,
496
+ .valid = {
497
+ .min_access_size = 4,
498
+ .max_access_size = 4,
499
+ .unaligned = false,
500
+ },
501
+};
502
+
503
+/* Register read handler specific to the key storage OTP module. */
504
+static uint64_t npcm7xx_key_storage_read(void *opaque, hwaddr addr,
505
+ unsigned int size)
506
+{
507
+ NPCM7xxOTPRegister reg = addr / sizeof(uint32_t);
508
+ NPCM7xxOTPState *s = opaque;
509
+
510
+ /*
511
+ * Only the Fuse Key Index register needs special handling; all other
512
+ * registers work the same way for both kinds of OTP modules.
513
+ */
514
+ if (reg != NPCM7XX_OTP_FKEYIND) {
515
+ return npcm7xx_otp_read(s, reg);
60
+ }
516
+ }
61
+
517
+
62
+ opr_sz = (1 + q) * 8;
518
+ qemu_log_mask(LOG_UNIMP, "%s: FKEYIND is not implemented\n", __func__);
63
+ fpst = get_fpstatus_ptr(1);
519
+
64
+ tcg_gen_gvec_3_ptr(vfp_reg_offset(1, rd),
520
+ return s->regs[NPCM7XX_OTP_FKEYIND];
65
+ vfp_reg_offset(1, rn),
521
+}
66
+ vfp_reg_offset(1, rm), fpst,
522
+
67
+ opr_sz, opr_sz, rot,
523
+/* Register write handler specific to the key storage OTP module. */
68
+ size ? gen_helper_gvec_fcmlas_idx
524
+static void npcm7xx_key_storage_write(void *opaque, hwaddr addr, uint64_t v,
69
+ : gen_helper_gvec_fcmlah_idx);
525
+ unsigned int size)
70
+ tcg_temp_free_ptr(fpst);
526
+{
71
+ return 0;
527
+ NPCM7xxOTPRegister reg = addr / sizeof(uint32_t);
72
+}
528
+ NPCM7xxOTPState *s = opaque;
73
+
529
+
74
static int disas_coproc_insn(DisasContext *s, uint32_t insn)
530
+ /*
75
{
531
+ * Only the Fuse Key Index register needs special handling; all other
76
int cpnum, is64, crn, crm, opc1, opc2, isread, rt, rt2;
532
+ * registers work the same way for both kinds of OTP modules.
77
@@ -XXX,XX +XXX,XX @@ static void disas_arm_insn(DisasContext *s, unsigned int insn)
533
+ */
78
goto illegal_op;
534
+ if (reg != NPCM7XX_OTP_FKEYIND) {
79
}
535
+ npcm7xx_otp_write(s, reg, v);
80
return;
536
+ return;
81
+ } else if ((insn & 0x0f000a00) == 0x0e000800
537
+ }
82
+ && arm_dc_feature(s, ARM_FEATURE_V8)) {
538
+
83
+ if (disas_neon_insn_2reg_scalar_ext(s, insn)) {
539
+ qemu_log_mask(LOG_UNIMP, "%s: FKEYIND is not implemented\n", __func__);
84
+ goto illegal_op;
540
+
85
+ }
541
+ s->regs[NPCM7XX_OTP_FKEYIND] = v;
86
+ return;
542
+}
87
} else if ((insn & 0x0fe00000) == 0x0c400000) {
543
+
88
/* Coprocessor double register transfer. */
544
+static const MemoryRegionOps npcm7xx_key_storage_ops = {
89
ARCH(5TE);
545
+ .read = npcm7xx_key_storage_read,
546
+ .write = npcm7xx_key_storage_write,
547
+ .endianness = DEVICE_LITTLE_ENDIAN,
548
+ .valid = {
549
+ .min_access_size = 4,
550
+ .max_access_size = 4,
551
+ .unaligned = false,
552
+ },
553
+};
554
+
555
+static void npcm7xx_otp_enter_reset(Object *obj, ResetType type)
556
+{
557
+ NPCM7xxOTPState *s = NPCM7XX_OTP(obj);
558
+
559
+ memset(s->regs, 0, sizeof(s->regs));
560
+
561
+ s->regs[NPCM7XX_OTP_FST] = 0x00000001;
562
+ s->regs[NPCM7XX_OTP_FCFG] = 0x20000000;
563
+}
564
+
565
+static void npcm7xx_otp_realize(DeviceState *dev, Error **errp)
566
+{
567
+ NPCM7xxOTPClass *oc = NPCM7XX_OTP_GET_CLASS(dev);
568
+ NPCM7xxOTPState *s = NPCM7XX_OTP(dev);
569
+ SysBusDevice *sbd = &s->parent;
570
+
571
+ memset(s->array, 0, sizeof(s->array));
572
+
573
+ memory_region_init_io(&s->mmio, OBJECT(s), oc->mmio_ops, s, "regs",
574
+ NPCM7XX_OTP_REGS_SIZE);
575
+ sysbus_init_mmio(sbd, &s->mmio);
576
+}
577
+
578
+static const VMStateDescription vmstate_npcm7xx_otp = {
579
+ .name = "npcm7xx-otp",
580
+ .version_id = 0,
581
+ .minimum_version_id = 0,
582
+ .fields = (VMStateField[]) {
583
+ VMSTATE_UINT32_ARRAY(regs, NPCM7xxOTPState, NPCM7XX_OTP_NR_REGS),
584
+ VMSTATE_UINT8_ARRAY(array, NPCM7xxOTPState, NPCM7XX_OTP_ARRAY_BYTES),
585
+ VMSTATE_END_OF_LIST(),
586
+ },
587
+};
588
+
589
+static void npcm7xx_otp_class_init(ObjectClass *klass, void *data)
590
+{
591
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
592
+ DeviceClass *dc = DEVICE_CLASS(klass);
593
+
594
+ QEMU_BUILD_BUG_ON(NPCM7XX_OTP_REGS_END > NPCM7XX_OTP_NR_REGS);
595
+
596
+ dc->realize = npcm7xx_otp_realize;
597
+ dc->vmsd = &vmstate_npcm7xx_otp;
598
+ rc->phases.enter = npcm7xx_otp_enter_reset;
599
+}
600
+
601
+static void npcm7xx_key_storage_class_init(ObjectClass *klass, void *data)
602
+{
603
+ NPCM7xxOTPClass *oc = NPCM7XX_OTP_CLASS(klass);
604
+
605
+ oc->mmio_ops = &npcm7xx_key_storage_ops;
606
+}
607
+
608
+static void npcm7xx_fuse_array_class_init(ObjectClass *klass, void *data)
609
+{
610
+ NPCM7xxOTPClass *oc = NPCM7XX_OTP_CLASS(klass);
611
+
612
+ oc->mmio_ops = &npcm7xx_fuse_array_ops;
613
+}
614
+
615
+static const TypeInfo npcm7xx_otp_types[] = {
616
+ {
617
+ .name = TYPE_NPCM7XX_OTP,
618
+ .parent = TYPE_SYS_BUS_DEVICE,
619
+ .instance_size = sizeof(NPCM7xxOTPState),
620
+ .class_size = sizeof(NPCM7xxOTPClass),
621
+ .class_init = npcm7xx_otp_class_init,
622
+ .abstract = true,
623
+ },
624
+ {
625
+ .name = TYPE_NPCM7XX_KEY_STORAGE,
626
+ .parent = TYPE_NPCM7XX_OTP,
627
+ .class_init = npcm7xx_key_storage_class_init,
628
+ },
629
+ {
630
+ .name = TYPE_NPCM7XX_FUSE_ARRAY,
631
+ .parent = TYPE_NPCM7XX_OTP,
632
+ .class_init = npcm7xx_fuse_array_class_init,
633
+ },
634
+};
635
+DEFINE_TYPES(npcm7xx_otp_types);
636
diff --git a/hw/nvram/meson.build b/hw/nvram/meson.build
637
index XXXXXXX..XXXXXXX 100644
638
--- a/hw/nvram/meson.build
639
+++ b/hw/nvram/meson.build
640
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_DS1225Y', if_true: files('ds1225y.c'))
641
softmmu_ss.add(when: 'CONFIG_NMC93XX_EEPROM', if_true: files('eeprom93xx.c'))
642
softmmu_ss.add(when: 'CONFIG_AT24C', if_true: files('eeprom_at24c.c'))
643
softmmu_ss.add(when: 'CONFIG_MAC_NVRAM', if_true: files('mac_nvram.c'))
644
+softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_otp.c'))
645
softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_nvm.c'))
646
647
specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_nvram.c'))
90
--
648
--
91
2.16.2
649
2.20.1
92
650
93
651
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Havard Skinnemoen <hskinnemoen@google.com>
2
2
3
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
3
This just implements the bare minimum to cause the boot block to skip
4
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
4
memory initialization.
5
Message-id: 20180228193125.20577-14-richard.henderson@linaro.org
5
6
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
7
Reviewed-by: Cédric Le Goater <clg@kaod.org>
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
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
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
---
14
---
8
target/arm/translate.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++
15
include/hw/arm/npcm7xx.h | 2 +
9
1 file changed, 68 insertions(+)
16
include/hw/mem/npcm7xx_mc.h | 36 ++++++++++++++++
10
17
hw/arm/npcm7xx.c | 6 +++
11
diff --git a/target/arm/translate.c b/target/arm/translate.c
18
hw/mem/npcm7xx_mc.c | 84 +++++++++++++++++++++++++++++++++++++
19
hw/mem/meson.build | 1 +
20
5 files changed, 129 insertions(+)
21
create mode 100644 include/hw/mem/npcm7xx_mc.h
22
create mode 100644 hw/mem/npcm7xx_mc.c
23
24
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
12
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
13
--- a/target/arm/translate.c
26
--- a/include/hw/arm/npcm7xx.h
14
+++ b/target/arm/translate.c
27
+++ b/include/hw/arm/npcm7xx.h
15
@@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn)
28
@@ -XXX,XX +XXX,XX @@
16
return 0;
29
17
}
30
#include "hw/boards.h"
18
31
#include "hw/cpu/a9mpcore.h"
19
+/* Advanced SIMD three registers of the same length extension.
32
+#include "hw/mem/npcm7xx_mc.h"
20
+ * 31 25 23 22 20 16 12 11 10 9 8 3 0
33
#include "hw/misc/npcm7xx_clk.h"
21
+ * +---------------+-----+---+-----+----+----+---+----+---+----+---------+----+
34
#include "hw/misc/npcm7xx_gcr.h"
22
+ * | 1 1 1 1 1 1 0 | op1 | D | op2 | Vn | Vd | 1 | o3 | 0 | o4 | N Q M U | Vm |
35
#include "hw/nvram/npcm7xx_otp.h"
23
+ * +---------------+-----+---+-----+----+----+---+----+---+----+---------+----+
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.
24
+ */
64
+ */
25
+static int disas_neon_insn_3same_ext(DisasContext *s, uint32_t insn)
65
+#ifndef NPCM7XX_MC_H
26
+{
66
+#define NPCM7XX_MC_H
27
+ gen_helper_gvec_3_ptr *fn_gvec_ptr;
67
+
28
+ int rd, rn, rm, rot, size, opr_sz;
68
+#include "exec/memory.h"
29
+ TCGv_ptr fpst;
69
+#include "hw/sysbus.h"
30
+ bool q;
70
+
31
+
71
+/**
32
+ q = extract32(insn, 6, 1);
72
+ * struct NPCM7xxMCState - Device state for the memory controller.
33
+ VFP_DREG_D(rd, insn);
73
+ * @parent: System bus device.
34
+ VFP_DREG_N(rn, insn);
74
+ * @mmio: Memory region through which registers are accessed.
35
+ VFP_DREG_M(rm, insn);
75
+ */
36
+ if ((rd | rn | rm) & q) {
76
+typedef struct NPCM7xxMCState {
37
+ return 1;
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;
38
+ }
157
+ }
39
+
158
+
40
+ if ((insn & 0xfe200f10) == 0xfc200800) {
159
+ qemu_log_mask(LOG_UNIMP, "%s: mostly unimplemented\n", __func__);
41
+ /* VCMLA -- 1111 110R R.1S .... .... 1000 ...0 .... */
160
+
42
+ size = extract32(insn, 20, 1);
43
+ rot = extract32(insn, 23, 2);
44
+ if (!arm_dc_feature(s, ARM_FEATURE_V8_FCMA)
45
+ || (!size && !arm_dc_feature(s, ARM_FEATURE_V8_FP16))) {
46
+ return 1;
47
+ }
48
+ fn_gvec_ptr = size ? gen_helper_gvec_fcmlas : gen_helper_gvec_fcmlah;
49
+ } else if ((insn & 0xfea00f10) == 0xfc800800) {
50
+ /* VCADD -- 1111 110R 1.0S .... .... 1000 ...0 .... */
51
+ size = extract32(insn, 20, 1);
52
+ rot = extract32(insn, 24, 1);
53
+ if (!arm_dc_feature(s, ARM_FEATURE_V8_FCMA)
54
+ || (!size && !arm_dc_feature(s, ARM_FEATURE_V8_FP16))) {
55
+ return 1;
56
+ }
57
+ fn_gvec_ptr = size ? gen_helper_gvec_fcadds : gen_helper_gvec_fcaddh;
58
+ } else {
59
+ return 1;
60
+ }
61
+
62
+ if (s->fp_excp_el) {
63
+ gen_exception_insn(s, 4, EXCP_UDEF,
64
+ syn_fp_access_trap(1, 0xe, false), s->fp_excp_el);
65
+ return 0;
66
+ }
67
+ if (!s->vfp_enabled) {
68
+ return 1;
69
+ }
70
+
71
+ opr_sz = (1 + q) * 8;
72
+ fpst = get_fpstatus_ptr(1);
73
+ tcg_gen_gvec_3_ptr(vfp_reg_offset(1, rd),
74
+ vfp_reg_offset(1, rn),
75
+ vfp_reg_offset(1, rm), fpst,
76
+ opr_sz, opr_sz, rot, fn_gvec_ptr);
77
+ tcg_temp_free_ptr(fpst);
78
+ return 0;
161
+ return 0;
79
+}
162
+}
80
+
163
+
81
static int disas_coproc_insn(DisasContext *s, uint32_t insn)
164
+static void npcm7xx_mc_write(void *opaque, hwaddr addr, uint64_t v,
82
{
165
+ unsigned int size)
83
int cpnum, is64, crn, crm, opc1, opc2, isread, rt, rt2;
166
+{
84
@@ -XXX,XX +XXX,XX @@ static void disas_arm_insn(DisasContext *s, unsigned int insn)
167
+ qemu_log_mask(LOG_UNIMP, "%s: mostly unimplemented\n", __func__);
85
}
168
+}
86
}
169
+
87
}
170
+static const MemoryRegionOps npcm7xx_mc_ops = {
88
+ } else if ((insn & 0x0e000a00) == 0x0c000800
171
+ .read = npcm7xx_mc_read,
89
+ && arm_dc_feature(s, ARM_FEATURE_V8)) {
172
+ .write = npcm7xx_mc_write,
90
+ if (disas_neon_insn_3same_ext(s, insn)) {
173
+ .endianness = DEVICE_LITTLE_ENDIAN,
91
+ goto illegal_op;
174
+ .valid = {
92
+ }
175
+ .min_access_size = 4,
93
+ return;
176
+ .max_access_size = 4,
94
} else if ((insn & 0x0fe00000) == 0x0c400000) {
177
+ .unaligned = false,
95
/* Coprocessor double register transfer. */
178
+ },
96
ARCH(5TE);
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)
97
--
219
--
98
2.16.2
220
2.20.1
99
221
100
222
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Havard Skinnemoen <hskinnemoen@google.com>
2
2
3
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
3
This implements a device model for the NPCM7xx SPI flash controller.
4
Message-id: 20180228193125.20577-13-richard.henderson@linaro.org
4
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
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
18
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
[PMM: renamed e1/e2/e3/e4 to use the same naming as the version
7
of the pseudocode in the Arm ARM]
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
---
19
---
10
target/arm/helper.h | 11 ++++
20
include/hw/arm/npcm7xx.h | 2 +
11
target/arm/translate-a64.c | 94 +++++++++++++++++++++++++---
21
include/hw/ssi/npcm7xx_fiu.h | 73 +++++
12
target/arm/vec_helper.c | 149 +++++++++++++++++++++++++++++++++++++++++++++
22
hw/arm/npcm7xx.c | 58 ++++
13
3 files changed, 246 insertions(+), 8 deletions(-)
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
14
30
15
diff --git a/target/arm/helper.h b/target/arm/helper.h
31
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
16
index XXXXXXX..XXXXXXX 100644
32
index XXXXXXX..XXXXXXX 100644
17
--- a/target/arm/helper.h
33
--- a/include/hw/arm/npcm7xx.h
18
+++ b/target/arm/helper.h
34
+++ b/include/hw/arm/npcm7xx.h
19
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_5(gvec_fcadds, TCG_CALL_NO_RWG,
35
@@ -XXX,XX +XXX,XX @@
20
DEF_HELPER_FLAGS_5(gvec_fcaddd, TCG_CALL_NO_RWG,
36
#include "hw/misc/npcm7xx_gcr.h"
21
void, ptr, ptr, ptr, ptr, i32)
37
#include "hw/nvram/npcm7xx_otp.h"
22
38
#include "hw/timer/npcm7xx_timer.h"
23
+DEF_HELPER_FLAGS_5(gvec_fcmlah, TCG_CALL_NO_RWG,
39
+#include "hw/ssi/npcm7xx_fiu.h"
24
+ void, ptr, ptr, ptr, ptr, i32)
40
#include "target/arm/cpu.h"
25
+DEF_HELPER_FLAGS_5(gvec_fcmlah_idx, TCG_CALL_NO_RWG,
41
26
+ void, ptr, ptr, ptr, ptr, i32)
42
#define NPCM7XX_MAX_NUM_CPUS (2)
27
+DEF_HELPER_FLAGS_5(gvec_fcmlas, TCG_CALL_NO_RWG,
43
@@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState {
28
+ void, ptr, ptr, ptr, ptr, i32)
44
NPCM7xxOTPState key_storage;
29
+DEF_HELPER_FLAGS_5(gvec_fcmlas_idx, TCG_CALL_NO_RWG,
45
NPCM7xxOTPState fuse_array;
30
+ void, ptr, ptr, ptr, ptr, i32)
46
NPCM7xxMCState mc;
31
+DEF_HELPER_FLAGS_5(gvec_fcmlad, TCG_CALL_NO_RWG,
47
+ NPCM7xxFIUState fiu[2];
32
+ void, ptr, ptr, ptr, ptr, i32)
48
} NPCM7xxState;
33
+
49
34
#ifdef TARGET_AARCH64
50
#define TYPE_NPCM7XX "npcm7xx"
35
#include "helper-a64.h"
51
diff --git a/include/hw/ssi/npcm7xx_fiu.h b/include/hw/ssi/npcm7xx_fiu.h
36
#endif
52
new file mode 100644
37
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
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
38
index XXXXXXX..XXXXXXX 100644
131
index XXXXXXX..XXXXXXX 100644
39
--- a/target/arm/translate-a64.c
132
--- a/hw/arm/npcm7xx.c
40
+++ b/target/arm/translate-a64.c
133
+++ b/hw/arm/npcm7xx.c
41
@@ -XXX,XX +XXX,XX @@ static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn)
134
@@ -XXX,XX +XXX,XX @@ static const hwaddr npcm7xx_uart_addr[] = {
42
}
135
0xf0004000,
43
feature = ARM_FEATURE_V8_RDM;
136
};
44
break;
137
45
+ case 0x8: /* FCMLA, #0 */
138
+/* Direct memory-mapped access to SPI0 CS0-1. */
46
+ case 0x9: /* FCMLA, #90 */
139
+static const hwaddr npcm7xx_fiu0_flash_addr[] = {
47
+ case 0xa: /* FCMLA, #180 */
140
+ 0x80000000, /* CS0 */
48
+ case 0xb: /* FCMLA, #270 */
141
+ 0x88000000, /* CS1 */
49
case 0xc: /* FCADD, #90 */
142
+};
50
case 0xe: /* FCADD, #270 */
143
+
51
if (size == 0
144
+/* Direct memory-mapped access to SPI3 CS0-3. */
52
@@ -XXX,XX +XXX,XX @@ static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn)
145
+static const hwaddr npcm7xx_fiu3_flash_addr[] = {
53
}
146
+ 0xa0000000, /* CS0 */
54
return;
147
+ 0xa8000000, /* CS1 */
55
148
+ 0xb0000000, /* CS2 */
56
+ case 0x8: /* FCMLA, #0 */
149
+ 0xb8000000, /* CS3 */
57
+ case 0x9: /* FCMLA, #90 */
150
+};
58
+ case 0xa: /* FCMLA, #180 */
151
+
59
+ case 0xb: /* FCMLA, #270 */
152
+static const struct {
60
+ rot = extract32(opcode, 0, 2);
153
+ const char *name;
61
+ switch (size) {
154
+ hwaddr regs_addr;
62
+ case 1:
155
+ int cs_count;
63
+ gen_gvec_op3_fpst(s, is_q, rd, rn, rm, true, rot,
156
+ const hwaddr *flash_addr;
64
+ gen_helper_gvec_fcmlah);
157
+} npcm7xx_fiu[] = {
65
+ break;
158
+ {
66
+ case 2:
159
+ .name = "fiu0",
67
+ gen_gvec_op3_fpst(s, is_q, rd, rn, rm, false, rot,
160
+ .regs_addr = 0xfb000000,
68
+ gen_helper_gvec_fcmlas);
161
+ .cs_count = ARRAY_SIZE(npcm7xx_fiu0_flash_addr),
69
+ break;
162
+ .flash_addr = npcm7xx_fiu0_flash_addr,
70
+ case 3:
163
+ }, {
71
+ gen_gvec_op3_fpst(s, is_q, rd, rn, rm, false, rot,
164
+ .name = "fiu3",
72
+ gen_helper_gvec_fcmlad);
165
+ .regs_addr = 0xc0000000,
73
+ break;
166
+ .cs_count = ARRAY_SIZE(npcm7xx_fiu3_flash_addr),
74
+ default:
167
+ .flash_addr = npcm7xx_fiu3_flash_addr,
75
+ g_assert_not_reached();
168
+ },
169
+};
170
+
171
static void npcm7xx_write_secondary_boot(ARMCPU *cpu,
172
const struct arm_boot_info *info)
173
{
174
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj)
175
for (i = 0; i < ARRAY_SIZE(s->tim); i++) {
176
object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER);
177
}
178
+
179
+ QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_fiu) != ARRAY_SIZE(s->fiu));
180
+ for (i = 0; i < ARRAY_SIZE(s->fiu); i++) {
181
+ object_initialize_child(obj, npcm7xx_fiu[i].name, &s->fiu[i],
182
+ TYPE_NPCM7XX_FIU);
183
+ }
184
}
185
186
static void npcm7xx_realize(DeviceState *dev, Error **errp)
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]);
76
+ }
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
+{
326
+ int index = flash - fiu->flash;
327
+
328
+ g_assert(index >= 0 && index < fiu->cs_count);
329
+
330
+ return index;
331
+}
332
+
333
+/* Assert the chip select specified in the UMA Control/Status Register. */
334
+static void npcm7xx_fiu_select(NPCM7xxFIUState *s, int cs_id)
335
+{
336
+ trace_npcm7xx_fiu_select(DEVICE(s)->canonical_path, cs_id);
337
+
338
+ if (cs_id < s->cs_count) {
339
+ qemu_irq_lower(s->cs_lines[cs_id]);
340
+ } else {
341
+ qemu_log_mask(LOG_GUEST_ERROR,
342
+ "%s: UMA to CS%d; this module has only %d chip selects",
343
+ DEVICE(s)->canonical_path, cs_id, s->cs_count);
344
+ cs_id = -1;
345
+ }
346
+
347
+ s->active_cs = cs_id;
348
+}
349
+
350
+/* Deassert the currently active chip select. */
351
+static void npcm7xx_fiu_deselect(NPCM7xxFIUState *s)
352
+{
353
+ if (s->active_cs < 0) {
77
+ return;
354
+ return;
78
+
355
+ }
79
case 0xc: /* FCADD, #90 */
356
+
80
case 0xe: /* FCADD, #270 */
357
+ trace_npcm7xx_fiu_deselect(DEVICE(s)->canonical_path, s->active_cs);
81
rot = extract32(opcode, 1, 1);
358
+
82
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
359
+ qemu_irq_raise(s->cs_lines[s->active_cs]);
83
int rn = extract32(insn, 5, 5);
360
+ s->active_cs = -1;
84
int rd = extract32(insn, 0, 5);
361
+}
85
bool is_long = false;
362
+
86
- bool is_fp = false;
363
+/* Direct flash memory read handler. */
87
+ int is_fp = 0;
364
+static uint64_t npcm7xx_fiu_flash_read(void *opaque, hwaddr addr,
88
bool is_fp16 = false;
365
+ unsigned int size)
89
int index;
366
+{
90
TCGv_ptr fpst;
367
+ NPCM7xxFIUFlash *f = opaque;
91
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
368
+ NPCM7xxFIUState *fiu = f->fiu;
92
case 0x05: /* FMLS */
369
+ uint64_t value = 0;
93
case 0x09: /* FMUL */
370
+ uint32_t drd_cfg;
94
case 0x19: /* FMULX */
371
+ int dummy_cycles;
95
- is_fp = true;
372
+ int i;
96
+ is_fp = 1;
373
+
97
break;
374
+ if (fiu->active_cs != -1) {
98
case 0x1d: /* SQRDMLAH */
375
+ qemu_log_mask(LOG_GUEST_ERROR,
99
case 0x1f: /* SQRDMLSH */
376
+ "%s: direct flash read with CS%d already active",
100
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
377
+ DEVICE(fiu)->canonical_path, fiu->active_cs);
101
return;
378
+ }
102
}
379
+
103
break;
380
+ npcm7xx_fiu_select(fiu, npcm7xx_fiu_cs_index(fiu, f));
104
+ case 0x11: /* FCMLA #0 */
381
+
105
+ case 0x13: /* FCMLA #90 */
382
+ drd_cfg = fiu->regs[NPCM7XX_FIU_DRD_CFG];
106
+ case 0x15: /* FCMLA #180 */
383
+ ssi_transfer(fiu->spi, FIU_DRD_CFG_RDCMD(drd_cfg));
107
+ case 0x17: /* FCMLA #270 */
384
+
108
+ if (!arm_dc_feature(s, ARM_FEATURE_V8_FCMA)) {
385
+ switch (FIU_DRD_CFG_ADDSIZ(drd_cfg)) {
109
+ unallocated_encoding(s);
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);
110
+ return;
619
+ return;
111
+ }
620
+ }
112
+ is_fp = 2;
621
+ s->regs[reg] = value;
113
+ break;
622
+ break;
114
default:
623
+
115
unallocated_encoding(s);
624
+ case NPCM7XX_FIU_UMA_CTS:
116
return;
625
+ if (value & FIU_UMA_CTS_RDYST) {
117
}
626
+ value &= ~FIU_UMA_CTS_RDYST;
118
627
+ } else {
119
- if (is_fp) {
628
+ value |= s->regs[reg] & FIU_UMA_CTS_RDYST;
120
+ switch (is_fp) {
629
+ }
121
+ case 1: /* normal fp */
630
+ if ((s->regs[reg] ^ value) & FIU_UMA_CTS_SW_CS) {
122
/* convert insn encoded size to TCGMemOp size */
631
+ if (value & FIU_UMA_CTS_SW_CS) {
123
switch (size) {
632
+ /*
124
case 0: /* half-precision */
633
+ * Don't drop CS if there's a transfer in progress, or we're
125
- if (!arm_dc_feature(s, ARM_FEATURE_V8_FP16)) {
634
+ * about to start one.
126
- unallocated_encoding(s);
635
+ */
127
- return;
636
+ if (!((value | s->regs[reg]) & FIU_UMA_CTS_EXEC_DONE)) {
128
- }
637
+ npcm7xx_fiu_deselect(s);
129
size = MO_16;
638
+ }
130
+ is_fp16 = true;
639
+ } else {
131
break;
640
+ int cs_id = FIU_UMA_CTS_DEV_NUM(s->regs[NPCM7XX_FIU_UMA_CTS]);
132
case MO_32: /* single precision */
641
+ npcm7xx_fiu_select(s, cs_id);
133
case MO_64: /* double precision */
134
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
135
unallocated_encoding(s);
136
return;
137
}
138
- } else {
139
+ break;
140
+
141
+ case 2: /* complex fp */
142
+ /* Each indexable element is a complex pair. */
143
+ size <<= 1;
144
+ switch (size) {
145
+ case MO_32:
146
+ if (h && !is_q) {
147
+ unallocated_encoding(s);
148
+ return;
149
+ }
642
+ }
150
+ is_fp16 = true;
643
+ }
151
+ break;
644
+ s->regs[reg] = value | (s->regs[reg] & FIU_UMA_CTS_EXEC_DONE);
152
+ case MO_64:
645
+ if (value & FIU_UMA_CTS_EXEC_DONE) {
153
+ break;
646
+ npcm7xx_fiu_uma_transaction(s);
154
+ default:
155
+ unallocated_encoding(s);
156
+ return;
157
+ }
647
+ }
158
+ break;
648
+ break;
159
+
649
+
160
+ default: /* integer */
650
+ case NPCM7XX_FIU_UMA_DR0 ... NPCM7XX_FIU_UMA_DR3:
161
switch (size) {
651
+ qemu_log_mask(LOG_GUEST_ERROR,
162
case MO_8:
652
+ "%s: write to read-only register @ 0x%" PRIx64 "\n",
163
case MO_64:
653
+ DEVICE(s)->canonical_path, addr);
164
unallocated_encoding(s);
654
+ return;
165
return;
655
+
166
}
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__);
167
+ break;
659
+ break;
168
+ }
660
+
169
+ if (is_fp16 && !arm_dc_feature(s, ARM_FEATURE_V8_FP16)) {
661
+ case NPCM7XX_FIU_UMA_CMD:
170
+ unallocated_encoding(s);
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);
171
+ return;
672
+ return;
172
}
673
+ }
173
674
+}
174
/* Given TCGMemOp size, adjust register and indexing. */
675
+
175
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
676
+static const MemoryRegionOps npcm7xx_fiu_ctrl_ops = {
176
fpst = NULL;
677
+ .read = npcm7xx_fiu_ctrl_read,
177
}
678
+ .write = npcm7xx_fiu_ctrl_write,
178
679
+ .endianness = DEVICE_LITTLE_ENDIAN,
179
+ switch (16 * u + opcode) {
680
+ .valid = {
180
+ case 0x11: /* FCMLA #0 */
681
+ .min_access_size = 4,
181
+ case 0x13: /* FCMLA #90 */
682
+ .max_access_size = 4,
182
+ case 0x15: /* FCMLA #180 */
683
+ .unaligned = false,
183
+ case 0x17: /* FCMLA #270 */
684
+ },
184
+ tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, rd),
685
+};
185
+ vec_full_reg_offset(s, rn),
686
+
186
+ vec_reg_offset(s, rm, index, size), fpst,
687
+static void npcm7xx_fiu_enter_reset(Object *obj, ResetType type)
187
+ is_q ? 16 : 8, vec_full_reg_size(s),
688
+{
188
+ extract32(insn, 13, 2), /* rot */
689
+ NPCM7xxFIUState *s = NPCM7XX_FIU(obj);
189
+ size == MO_64
690
+
190
+ ? gen_helper_gvec_fcmlas_idx
691
+ trace_npcm7xx_fiu_enter_reset(DEVICE(obj)->canonical_path, type);
191
+ : gen_helper_gvec_fcmlah_idx);
692
+
192
+ tcg_temp_free_ptr(fpst);
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);
193
+ return;
725
+ return;
194
+ }
726
+ }
195
+
727
+
196
if (size == 3) {
728
+ s->spi = ssi_create_bus(dev, "spi");
197
TCGv_i64 tcg_idx = tcg_temp_new_i64();
729
+ s->cs_lines = g_new0(qemu_irq, s->cs_count);
198
int pass;
730
+ qdev_init_gpio_out_named(DEVICE(s), s->cs_lines, "cs", s->cs_count);
199
diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c
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
200
index XXXXXXX..XXXXXXX 100644
792
index XXXXXXX..XXXXXXX 100644
201
--- a/target/arm/vec_helper.c
793
--- a/hw/arm/Kconfig
202
+++ b/target/arm/vec_helper.c
794
+++ b/hw/arm/Kconfig
203
@@ -XXX,XX +XXX,XX @@ void HELPER(gvec_fcaddd)(void *vd, void *vn, void *vm,
795
@@ -XXX,XX +XXX,XX @@ config NPCM7XX
204
}
796
select ARM_GIC
205
clear_tail(d, opr_sz, simd_maxsz(desc));
797
select PL310 # cache controller
206
}
798
select SERIAL
207
+
799
+ select SSI
208
+void HELPER(gvec_fcmlah)(void *vd, void *vn, void *vm,
800
select UNIMP
209
+ void *vfpst, uint32_t desc)
801
210
+{
802
config FSL_IMX25
211
+ uintptr_t opr_sz = simd_oprsz(desc);
803
diff --git a/hw/ssi/meson.build b/hw/ssi/meson.build
212
+ float16 *d = vd;
804
index XXXXXXX..XXXXXXX 100644
213
+ float16 *n = vn;
805
--- a/hw/ssi/meson.build
214
+ float16 *m = vm;
806
+++ b/hw/ssi/meson.build
215
+ float_status *fpst = vfpst;
807
@@ -XXX,XX +XXX,XX @@
216
+ intptr_t flip = extract32(desc, SIMD_DATA_SHIFT, 1);
808
softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_smc.c'))
217
+ uint32_t neg_imag = extract32(desc, SIMD_DATA_SHIFT + 1, 1);
809
softmmu_ss.add(when: 'CONFIG_MSF2', if_true: files('mss-spi.c'))
218
+ uint32_t neg_real = flip ^ neg_imag;
810
+softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_fiu.c'))
219
+ uintptr_t i;
811
softmmu_ss.add(when: 'CONFIG_PL022', if_true: files('pl022.c'))
220
+
812
softmmu_ss.add(when: 'CONFIG_SSI', if_true: files('ssi.c'))
221
+ /* Shift boolean to the sign bit so we can xor to negate. */
813
softmmu_ss.add(when: 'CONFIG_STM32F2XX_SPI', if_true: files('stm32f2xx_spi.c'))
222
+ neg_real <<= 15;
814
diff --git a/hw/ssi/trace-events b/hw/ssi/trace-events
223
+ neg_imag <<= 15;
815
index XXXXXXX..XXXXXXX 100644
224
+
816
--- a/hw/ssi/trace-events
225
+ for (i = 0; i < opr_sz / 2; i += 2) {
817
+++ b/hw/ssi/trace-events
226
+ float16 e2 = n[H2(i + flip)];
818
@@ -XXX,XX +XXX,XX @@ aspeed_smc_dma_checksum(uint32_t addr, uint32_t data) "0x%08x: 0x%08x"
227
+ float16 e1 = m[H2(i + flip)] ^ neg_real;
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"
228
+ float16 e4 = e2;
820
aspeed_smc_write(uint64_t addr, uint32_t size, uint64_t data) "@0x%" PRIx64 " size %u: 0x%" PRIx64
229
+ float16 e3 = m[H2(i + 1 - flip)] ^ neg_imag;
821
aspeed_smc_flash_select(int cs, const char *prefix) "CS%d %sselect"
230
+
822
+
231
+ d[H2(i)] = float16_muladd(e2, e1, d[H2(i)], 0, fpst);
823
+# npcm7xx_fiu.c
232
+ d[H2(i + 1)] = float16_muladd(e4, e3, d[H2(i + 1)], 0, fpst);
824
+
233
+ }
825
+npcm7xx_fiu_enter_reset(const char *id, int reset_type) "%s reset type: %d"
234
+ clear_tail(d, opr_sz, simd_maxsz(desc));
826
+npcm7xx_fiu_hold_reset(const char *id) "%s"
235
+}
827
+npcm7xx_fiu_select(const char *id, int cs) "%s select CS%d"
236
+
828
+npcm7xx_fiu_deselect(const char *id, int cs) "%s deselect CS%d"
237
+void HELPER(gvec_fcmlah_idx)(void *vd, void *vn, void *vm,
829
+npcm7xx_fiu_ctrl_read(const char *id, uint64_t addr, uint32_t data) "%s offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
238
+ void *vfpst, uint32_t desc)
830
+npcm7xx_fiu_ctrl_write(const char *id, uint64_t addr, uint32_t data) "%s offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
239
+{
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
240
+ uintptr_t opr_sz = simd_oprsz(desc);
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
241
+ float16 *d = vd;
242
+ float16 *n = vn;
243
+ float16 *m = vm;
244
+ float_status *fpst = vfpst;
245
+ intptr_t flip = extract32(desc, SIMD_DATA_SHIFT, 1);
246
+ uint32_t neg_imag = extract32(desc, SIMD_DATA_SHIFT + 1, 1);
247
+ uint32_t neg_real = flip ^ neg_imag;
248
+ uintptr_t i;
249
+ float16 e1 = m[H2(flip)];
250
+ float16 e3 = m[H2(1 - flip)];
251
+
252
+ /* Shift boolean to the sign bit so we can xor to negate. */
253
+ neg_real <<= 15;
254
+ neg_imag <<= 15;
255
+ e1 ^= neg_real;
256
+ e3 ^= neg_imag;
257
+
258
+ for (i = 0; i < opr_sz / 2; i += 2) {
259
+ float16 e2 = n[H2(i + flip)];
260
+ float16 e4 = e2;
261
+
262
+ d[H2(i)] = float16_muladd(e2, e1, d[H2(i)], 0, fpst);
263
+ d[H2(i + 1)] = float16_muladd(e4, e3, d[H2(i + 1)], 0, fpst);
264
+ }
265
+ clear_tail(d, opr_sz, simd_maxsz(desc));
266
+}
267
+
268
+void HELPER(gvec_fcmlas)(void *vd, void *vn, void *vm,
269
+ void *vfpst, uint32_t desc)
270
+{
271
+ uintptr_t opr_sz = simd_oprsz(desc);
272
+ float32 *d = vd;
273
+ float32 *n = vn;
274
+ float32 *m = vm;
275
+ float_status *fpst = vfpst;
276
+ intptr_t flip = extract32(desc, SIMD_DATA_SHIFT, 1);
277
+ uint32_t neg_imag = extract32(desc, SIMD_DATA_SHIFT + 1, 1);
278
+ uint32_t neg_real = flip ^ neg_imag;
279
+ uintptr_t i;
280
+
281
+ /* Shift boolean to the sign bit so we can xor to negate. */
282
+ neg_real <<= 31;
283
+ neg_imag <<= 31;
284
+
285
+ for (i = 0; i < opr_sz / 4; i += 2) {
286
+ float32 e2 = n[H4(i + flip)];
287
+ float32 e1 = m[H4(i + flip)] ^ neg_real;
288
+ float32 e4 = e2;
289
+ float32 e3 = m[H4(i + 1 - flip)] ^ neg_imag;
290
+
291
+ d[H4(i)] = float32_muladd(e2, e1, d[H4(i)], 0, fpst);
292
+ d[H4(i + 1)] = float32_muladd(e4, e3, d[H4(i + 1)], 0, fpst);
293
+ }
294
+ clear_tail(d, opr_sz, simd_maxsz(desc));
295
+}
296
+
297
+void HELPER(gvec_fcmlas_idx)(void *vd, void *vn, void *vm,
298
+ void *vfpst, uint32_t desc)
299
+{
300
+ uintptr_t opr_sz = simd_oprsz(desc);
301
+ float32 *d = vd;
302
+ float32 *n = vn;
303
+ float32 *m = vm;
304
+ float_status *fpst = vfpst;
305
+ intptr_t flip = extract32(desc, SIMD_DATA_SHIFT, 1);
306
+ uint32_t neg_imag = extract32(desc, SIMD_DATA_SHIFT + 1, 1);
307
+ uint32_t neg_real = flip ^ neg_imag;
308
+ uintptr_t i;
309
+ float32 e1 = m[H4(flip)];
310
+ float32 e3 = m[H4(1 - flip)];
311
+
312
+ /* Shift boolean to the sign bit so we can xor to negate. */
313
+ neg_real <<= 31;
314
+ neg_imag <<= 31;
315
+ e1 ^= neg_real;
316
+ e3 ^= neg_imag;
317
+
318
+ for (i = 0; i < opr_sz / 4; i += 2) {
319
+ float32 e2 = n[H4(i + flip)];
320
+ float32 e4 = e2;
321
+
322
+ d[H4(i)] = float32_muladd(e2, e1, d[H4(i)], 0, fpst);
323
+ d[H4(i + 1)] = float32_muladd(e4, e3, d[H4(i + 1)], 0, fpst);
324
+ }
325
+ clear_tail(d, opr_sz, simd_maxsz(desc));
326
+}
327
+
328
+void HELPER(gvec_fcmlad)(void *vd, void *vn, void *vm,
329
+ void *vfpst, uint32_t desc)
330
+{
331
+ uintptr_t opr_sz = simd_oprsz(desc);
332
+ float64 *d = vd;
333
+ float64 *n = vn;
334
+ float64 *m = vm;
335
+ float_status *fpst = vfpst;
336
+ intptr_t flip = extract32(desc, SIMD_DATA_SHIFT, 1);
337
+ uint64_t neg_imag = extract32(desc, SIMD_DATA_SHIFT + 1, 1);
338
+ uint64_t neg_real = flip ^ neg_imag;
339
+ uintptr_t i;
340
+
341
+ /* Shift boolean to the sign bit so we can xor to negate. */
342
+ neg_real <<= 63;
343
+ neg_imag <<= 63;
344
+
345
+ for (i = 0; i < opr_sz / 8; i += 2) {
346
+ float64 e2 = n[i + flip];
347
+ float64 e1 = m[i + flip] ^ neg_real;
348
+ float64 e4 = e2;
349
+ float64 e3 = m[i + 1 - flip] ^ neg_imag;
350
+
351
+ d[i] = float64_muladd(e2, e1, d[i], 0, fpst);
352
+ d[i + 1] = float64_muladd(e4, e3, d[i + 1], 0, fpst);
353
+ }
354
+ clear_tail(d, opr_sz, simd_maxsz(desc));
355
+}
356
--
833
--
357
2.16.2
834
2.20.1
358
835
359
836
diff view generated by jsdifflib
1
From: Alistair Francis <alistair.francis@xilinx.com>
1
From: Havard Skinnemoen <hskinnemoen@google.com>
2
2
3
Allow the guest to determine the time set from the QEMU command line.
3
This allows these NPCM7xx-based boards to boot from a flash image, e.g.
4
one built with OpenBMC. For example like this:
4
5
5
This includes adding a trace event to debug the new time.
6
IMAGE=${OPENBMC}/build/tmp/deploy/images/gsj/image-bmc
7
qemu-system-arm -machine quanta-gsj -nographic \
8
    -drive file=${IMAGE},if=mtd,bus=0,unit=0,format=raw,snapshot=on
6
9
7
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
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>
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
15
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
16
Message-id: 20200911052101.2602693-12-hskinnemoen@google.com
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
18
---
12
include/hw/timer/xlnx-zynqmp-rtc.h | 2 ++
19
hw/arm/npcm7xx_boards.c | 20 ++++++++++++++++++++
13
hw/timer/xlnx-zynqmp-rtc.c | 58 ++++++++++++++++++++++++++++++++++++++
20
1 file changed, 20 insertions(+)
14
hw/timer/trace-events | 3 ++
15
3 files changed, 63 insertions(+)
16
21
17
diff --git a/include/hw/timer/xlnx-zynqmp-rtc.h b/include/hw/timer/xlnx-zynqmp-rtc.h
22
diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c
18
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
19
--- a/include/hw/timer/xlnx-zynqmp-rtc.h
24
--- a/hw/arm/npcm7xx_boards.c
20
+++ b/include/hw/timer/xlnx-zynqmp-rtc.h
25
+++ b/hw/arm/npcm7xx_boards.c
21
@@ -XXX,XX +XXX,XX @@ typedef struct XlnxZynqMPRTC {
26
@@ -XXX,XX +XXX,XX @@
22
qemu_irq irq_rtc_int;
27
#include "hw/arm/npcm7xx.h"
23
qemu_irq irq_addr_error_int;
28
#include "hw/core/cpu.h"
24
29
#include "hw/loader.h"
25
+ uint32_t tick_offset;
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
}
36
}
37
38
+static void npcm7xx_connect_flash(NPCM7xxFIUState *fiu, int cs_no,
39
+ const char *flash_type, DriveInfo *dinfo)
40
+{
41
+ DeviceState *flash;
42
+ qemu_irq flash_cs;
26
+
43
+
27
uint32_t regs[XLNX_ZYNQMP_RTC_R_MAX];
44
+ flash = qdev_new(flash_type);
28
RegisterInfo regs_info[XLNX_ZYNQMP_RTC_R_MAX];
45
+ if (dinfo) {
29
} XlnxZynqMPRTC;
46
+ qdev_prop_set_drive(flash, "drive", blk_by_legacy_dinfo(dinfo));
30
diff --git a/hw/timer/xlnx-zynqmp-rtc.c b/hw/timer/xlnx-zynqmp-rtc.c
47
+ }
31
index XXXXXXX..XXXXXXX 100644
48
+ qdev_realize_and_unref(flash, BUS(fiu->spi), &error_fatal);
32
--- a/hw/timer/xlnx-zynqmp-rtc.c
49
+
33
+++ b/hw/timer/xlnx-zynqmp-rtc.c
50
+ flash_cs = qdev_get_gpio_in_named(flash, SSI_GPIO_CS, 0);
34
@@ -XXX,XX +XXX,XX @@
51
+ qdev_connect_gpio_out_named(DEVICE(fiu), "cs", cs_no, flash_cs);
35
#include "hw/register.h"
36
#include "qemu/bitops.h"
37
#include "qemu/log.h"
38
+#include "hw/ptimer.h"
39
+#include "qemu/cutils.h"
40
+#include "sysemu/sysemu.h"
41
+#include "trace.h"
42
#include "hw/timer/xlnx-zynqmp-rtc.h"
43
44
#ifndef XLNX_ZYNQMP_RTC_ERR_DEBUG
45
@@ -XXX,XX +XXX,XX @@ static void addr_error_int_update_irq(XlnxZynqMPRTC *s)
46
qemu_set_irq(s->irq_addr_error_int, pending);
47
}
48
49
+static uint32_t rtc_get_count(XlnxZynqMPRTC *s)
50
+{
51
+ int64_t now = qemu_clock_get_ns(rtc_clock);
52
+ return s->tick_offset + now / NANOSECONDS_PER_SECOND;
53
+}
52
+}
54
+
53
+
55
+static uint64_t current_time_postr(RegisterInfo *reg, uint64_t val64)
54
static void npcm7xx_connect_dram(NPCM7xxState *soc, MemoryRegion *dram)
56
+{
57
+ XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(reg->opaque);
58
+
59
+ return rtc_get_count(s);
60
+}
61
+
62
static void rtc_int_status_postw(RegisterInfo *reg, uint64_t val64)
63
{
55
{
64
XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(reg->opaque);
56
memory_region_add_subregion(get_system_memory(), NPCM7XX_DRAM_BA, dram);
65
@@ -XXX,XX +XXX,XX @@ static uint64_t addr_error_int_dis_prew(RegisterInfo *reg, uint64_t val64)
57
@@ -XXX,XX +XXX,XX @@ static void npcm750_evb_init(MachineState *machine)
66
58
qdev_realize(DEVICE(soc), NULL, &error_fatal);
67
static const RegisterAccessInfo rtc_regs_info[] = {
59
68
{ .name = "SET_TIME_WRITE", .addr = A_SET_TIME_WRITE,
60
npcm7xx_load_bootrom(machine, soc);
69
+ .unimp = MAKE_64BIT_MASK(0, 32),
61
+ npcm7xx_connect_flash(&soc->fiu[0], 0, "w25q256", drive_get(IF_MTD, 0, 0));
70
},{ .name = "SET_TIME_READ", .addr = A_SET_TIME_READ,
62
npcm7xx_load_kernel(machine, soc);
71
.ro = 0xffffffff,
72
+ .post_read = current_time_postr,
73
},{ .name = "CALIB_WRITE", .addr = A_CALIB_WRITE,
74
+ .unimp = MAKE_64BIT_MASK(0, 32),
75
},{ .name = "CALIB_READ", .addr = A_CALIB_READ,
76
.ro = 0x1fffff,
77
},{ .name = "CURRENT_TIME", .addr = A_CURRENT_TIME,
78
.ro = 0xffffffff,
79
+ .post_read = current_time_postr,
80
},{ .name = "CURRENT_TICK", .addr = A_CURRENT_TICK,
81
.ro = 0xffff,
82
},{ .name = "ALARM", .addr = A_ALARM,
83
@@ -XXX,XX +XXX,XX @@ static void rtc_init(Object *obj)
84
XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(obj);
85
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
86
RegisterInfoArray *reg_array;
87
+ struct tm current_tm;
88
89
memory_region_init(&s->iomem, obj, TYPE_XLNX_ZYNQMP_RTC,
90
XLNX_ZYNQMP_RTC_R_MAX * 4);
91
@@ -XXX,XX +XXX,XX @@ static void rtc_init(Object *obj)
92
sysbus_init_mmio(sbd, &s->iomem);
93
sysbus_init_irq(sbd, &s->irq_rtc_int);
94
sysbus_init_irq(sbd, &s->irq_addr_error_int);
95
+
96
+ qemu_get_timedate(&current_tm, 0);
97
+ s->tick_offset = mktimegm(&current_tm) -
98
+ qemu_clock_get_ns(rtc_clock) / NANOSECONDS_PER_SECOND;
99
+
100
+ trace_xlnx_zynqmp_rtc_gettime(current_tm.tm_year, current_tm.tm_mon,
101
+ current_tm.tm_mday, current_tm.tm_hour,
102
+ current_tm.tm_min, current_tm.tm_sec);
103
+}
104
+
105
+static int rtc_pre_save(void *opaque)
106
+{
107
+ XlnxZynqMPRTC *s = opaque;
108
+ int64_t now = qemu_clock_get_ns(rtc_clock) / NANOSECONDS_PER_SECOND;
109
+
110
+ /* Add the time at migration */
111
+ s->tick_offset = s->tick_offset + now;
112
+
113
+ return 0;
114
+}
115
+
116
+static int rtc_post_load(void *opaque, int version_id)
117
+{
118
+ XlnxZynqMPRTC *s = opaque;
119
+ int64_t now = qemu_clock_get_ns(rtc_clock) / NANOSECONDS_PER_SECOND;
120
+
121
+ /* Subtract the time after migration. This combined with the pre_save
122
+ * action results in us having subtracted the time that the guest was
123
+ * stopped to the offset.
124
+ */
125
+ s->tick_offset = s->tick_offset - now;
126
+
127
+ return 0;
128
}
63
}
129
64
130
static const VMStateDescription vmstate_rtc = {
65
@@ -XXX,XX +XXX,XX @@ static void quanta_gsj_init(MachineState *machine)
131
.name = TYPE_XLNX_ZYNQMP_RTC,
66
qdev_realize(DEVICE(soc), NULL, &error_fatal);
132
.version_id = 1,
67
133
.minimum_version_id = 1,
68
npcm7xx_load_bootrom(machine, soc);
134
+ .pre_save = rtc_pre_save,
69
+ npcm7xx_connect_flash(&soc->fiu[0], 0, "mx25l25635e",
135
+ .post_load = rtc_post_load,
70
+ drive_get(IF_MTD, 0, 0));
136
.fields = (VMStateField[]) {
71
npcm7xx_load_kernel(machine, soc);
137
VMSTATE_UINT32_ARRAY(regs, XlnxZynqMPRTC, XLNX_ZYNQMP_RTC_R_MAX),
72
}
138
+ VMSTATE_UINT32(tick_offset, XlnxZynqMPRTC),
73
139
VMSTATE_END_OF_LIST(),
140
}
141
};
142
diff --git a/hw/timer/trace-events b/hw/timer/trace-events
143
index XXXXXXX..XXXXXXX 100644
144
--- a/hw/timer/trace-events
145
+++ b/hw/timer/trace-events
146
@@ -XXX,XX +XXX,XX @@ systick_write(uint64_t addr, uint32_t value, unsigned size) "systick write addr
147
cmsdk_apb_timer_read(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB timer read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
148
cmsdk_apb_timer_write(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB timer write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
149
cmsdk_apb_timer_reset(void) "CMSDK APB timer: reset"
150
+
151
+# hw/timer/xlnx-zynqmp-rtc.c
152
+xlnx_zynqmp_rtc_gettime(int year, int month, int day, int hour, int min, int sec) "Get time from host: %d-%d-%d %2d:%02d:%02d"
153
--
74
--
154
2.16.2
75
2.20.1
155
76
156
77
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Havard Skinnemoen <hskinnemoen@google.com>
2
2
3
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
3
When booting directly into a kernel, bypassing the boot loader, the CPU and
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
4
UART clocks are not set up correctly. This makes the system appear very
5
Message-id: 20180228193125.20577-8-richard.henderson@linaro.org
5
slow, and causes the initrd boot test to fail when optimization is off.
6
7
The UART clock must run at 24 MHz. The default 25 MHz reference clock
8
cannot achieve this, so switch to PLL2/2 @ 480 MHz, which works
9
perfectly with the default /20 divider.
10
11
The CPU clock should run at 800 MHz, so switch it to PLL1/2. PLL1 runs
12
at 800 MHz by default, so we need to double the feedback divider as well
13
to make it run at 1600 MHz (so PLL1/2 runs at 800 MHz).
14
15
We don't bother checking for PLL lock because we know our emulated PLLs
16
lock instantly.
17
18
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
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
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
22
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
---
23
---
8
target/arm/translate.c | 86 +++++++++++++++++++++++++++++++++++++++-----------
24
include/hw/arm/npcm7xx.h | 1 +
9
1 file changed, 67 insertions(+), 19 deletions(-)
25
hw/arm/npcm7xx.c | 32 ++++++++++++++++++++++++++++++++
26
2 files changed, 33 insertions(+)
10
27
11
diff --git a/target/arm/translate.c b/target/arm/translate.c
28
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
12
index XXXXXXX..XXXXXXX 100644
29
index XXXXXXX..XXXXXXX 100644
13
--- a/target/arm/translate.c
30
--- a/include/hw/arm/npcm7xx.h
14
+++ b/target/arm/translate.c
31
+++ b/include/hw/arm/npcm7xx.h
15
@@ -XXX,XX +XXX,XX @@
32
@@ -XXX,XX +XXX,XX @@
16
#include "disas/disas.h"
33
#define NPCM7XX_SMP_LOADER_START (0xffff0000) /* Boot ROM */
17
#include "exec/exec-all.h"
34
#define NPCM7XX_SMP_BOOTREG_ADDR (0xf080013c) /* GCR.SCRPAD */
18
#include "tcg-op.h"
35
#define NPCM7XX_GIC_CPU_IF_ADDR (0xf03fe100) /* GIC within A9 */
19
+#include "tcg-op-gvec.h"
36
+#define NPCM7XX_BOARD_SETUP_ADDR (0xffff1000) /* Boot ROM */
20
#include "qemu/log.h"
37
21
#include "qemu/bitops.h"
38
typedef struct NPCM7xxMachine {
22
#include "arm_ldst.h"
39
MachineState parent;
23
@@ -XXX,XX +XXX,XX @@ static void gen_neon_narrow_op(int op, int u, int size,
40
diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c
24
#define NEON_3R_VPMAX 20
41
index XXXXXXX..XXXXXXX 100644
25
#define NEON_3R_VPMIN 21
42
--- a/hw/arm/npcm7xx.c
26
#define NEON_3R_VQDMULH_VQRDMULH 22
43
+++ b/hw/arm/npcm7xx.c
27
-#define NEON_3R_VPADD 23
44
@@ -XXX,XX +XXX,XX @@
28
+#define NEON_3R_VPADD_VQRDMLAH 23
45
#define NPCM7XX_ROM_BA (0xffff0000)
29
#define NEON_3R_SHA 24 /* SHA1C,SHA1P,SHA1M,SHA1SU0,SHA256H{2},SHA256SU1 */
46
#define NPCM7XX_ROM_SZ (64 * KiB)
30
-#define NEON_3R_VFM 25 /* VFMA, VFMS : float fused multiply-add */
47
31
+#define NEON_3R_VFM_VQRDMLSH 25 /* VFMA, VFMS, VQRDMLSH */
48
+/* Clock configuration values to be fixed up when bypassing bootloader */
32
#define NEON_3R_FLOAT_ARITH 26 /* float VADD, VSUB, VPADD, VABD */
49
+
33
#define NEON_3R_FLOAT_MULTIPLY 27 /* float VMLA, VMLS, VMUL */
50
+/* Run PLL1 at 1600 MHz */
34
#define NEON_3R_FLOAT_CMP 28 /* float VCEQ, VCGE, VCGT */
51
+#define NPCM7XX_PLLCON1_FIXUP_VAL (0x00402101)
35
@@ -XXX,XX +XXX,XX @@ static const uint8_t neon_3r_sizes[] = {
52
+/* Run the CPU from PLL1 and UART from PLL2 */
36
[NEON_3R_VPMAX] = 0x7,
53
+#define NPCM7XX_CLKSEL_FIXUP_VAL (0x004aaba9)
37
[NEON_3R_VPMIN] = 0x7,
54
+
38
[NEON_3R_VQDMULH_VQRDMULH] = 0x6,
55
/*
39
- [NEON_3R_VPADD] = 0x7,
56
* Interrupt lines going into the GIC. This does not include internal Cortex-A9
40
+ [NEON_3R_VPADD_VQRDMLAH] = 0x7,
57
* interrupts.
41
[NEON_3R_SHA] = 0xf, /* size field encodes op type */
58
@@ -XXX,XX +XXX,XX @@ static const struct {
42
- [NEON_3R_VFM] = 0x5, /* size bit 1 encodes op */
59
},
43
+ [NEON_3R_VFM_VQRDMLSH] = 0x7, /* For VFM, size bit 1 encodes op */
44
[NEON_3R_FLOAT_ARITH] = 0x5, /* size bit 1 encodes op */
45
[NEON_3R_FLOAT_MULTIPLY] = 0x5, /* size bit 1 encodes op */
46
[NEON_3R_FLOAT_CMP] = 0x5, /* size bit 1 encodes op */
47
@@ -XXX,XX +XXX,XX @@ static const uint8_t neon_2rm_sizes[] = {
48
[NEON_2RM_VCVT_UF] = 0x4,
49
};
60
};
50
61
62
+static void npcm7xx_write_board_setup(ARMCPU *cpu,
63
+ const struct arm_boot_info *info)
64
+{
65
+ uint32_t board_setup[] = {
66
+ 0xe59f0010, /* ldr r0, clk_base_addr */
67
+ 0xe59f1010, /* ldr r1, pllcon1_value */
68
+ 0xe5801010, /* str r1, [r0, #16] */
69
+ 0xe59f100c, /* ldr r1, clksel_value */
70
+ 0xe5801004, /* str r1, [r0, #4] */
71
+ 0xe12fff1e, /* bx lr */
72
+ NPCM7XX_CLK_BA,
73
+ NPCM7XX_PLLCON1_FIXUP_VAL,
74
+ NPCM7XX_CLKSEL_FIXUP_VAL,
75
+ };
76
+ int i;
51
+
77
+
52
+/* Expand v8.1 simd helper. */
78
+ for (i = 0; i < ARRAY_SIZE(board_setup); i++) {
53
+static int do_v81_helper(DisasContext *s, gen_helper_gvec_3_ptr *fn,
79
+ board_setup[i] = tswap32(board_setup[i]);
54
+ int q, int rd, int rn, int rm)
55
+{
56
+ if (arm_dc_feature(s, ARM_FEATURE_V8_RDM)) {
57
+ int opr_sz = (1 + q) * 8;
58
+ tcg_gen_gvec_3_ptr(vfp_reg_offset(1, rd),
59
+ vfp_reg_offset(1, rn),
60
+ vfp_reg_offset(1, rm), cpu_env,
61
+ opr_sz, opr_sz, 0, fn);
62
+ return 0;
63
+ }
80
+ }
64
+ return 1;
81
+ rom_add_blob_fixed("board-setup", board_setup, sizeof(board_setup),
82
+ info->board_setup_addr);
65
+}
83
+}
66
+
84
+
67
/* Translate a NEON data processing instruction. Return nonzero if the
85
static void npcm7xx_write_secondary_boot(ARMCPU *cpu,
68
instruction is invalid.
86
const struct arm_boot_info *info)
69
We process data in a mixture of 32-bit and 64-bit chunks.
87
{
70
@@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn)
88
@@ -XXX,XX +XXX,XX @@ static struct arm_boot_info npcm7xx_binfo = {
71
if (q && ((rd | rn | rm) & 1)) {
89
.gic_cpu_if_addr = NPCM7XX_GIC_CPU_IF_ADDR,
72
return 1;
90
.write_secondary_boot = npcm7xx_write_secondary_boot,
73
}
91
.board_id = -1,
74
- /*
92
+ .board_setup_addr = NPCM7XX_BOARD_SETUP_ADDR,
75
- * The SHA-1/SHA-256 3-register instructions require special treatment
93
+ .write_board_setup = npcm7xx_write_board_setup,
76
- * here, as their size field is overloaded as an op type selector, and
94
};
77
- * they all consume their input in a single pass.
95
78
- */
96
void npcm7xx_load_kernel(MachineState *machine, NPCM7xxState *soc)
79
- if (op == NEON_3R_SHA) {
80
+ switch (op) {
81
+ case NEON_3R_SHA:
82
+ /* The SHA-1/SHA-256 3-register instructions require special
83
+ * treatment here, as their size field is overloaded as an
84
+ * op type selector, and they all consume their input in a
85
+ * single pass.
86
+ */
87
if (!q) {
88
return 1;
89
}
90
@@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn)
91
tcg_temp_free_ptr(ptr2);
92
tcg_temp_free_ptr(ptr3);
93
return 0;
94
+
95
+ case NEON_3R_VPADD_VQRDMLAH:
96
+ if (!u) {
97
+ break; /* VPADD */
98
+ }
99
+ /* VQRDMLAH */
100
+ switch (size) {
101
+ case 1:
102
+ return do_v81_helper(s, gen_helper_gvec_qrdmlah_s16,
103
+ q, rd, rn, rm);
104
+ case 2:
105
+ return do_v81_helper(s, gen_helper_gvec_qrdmlah_s32,
106
+ q, rd, rn, rm);
107
+ }
108
+ return 1;
109
+
110
+ case NEON_3R_VFM_VQRDMLSH:
111
+ if (!u) {
112
+ /* VFM, VFMS */
113
+ if (size == 1) {
114
+ return 1;
115
+ }
116
+ break;
117
+ }
118
+ /* VQRDMLSH */
119
+ switch (size) {
120
+ case 1:
121
+ return do_v81_helper(s, gen_helper_gvec_qrdmlsh_s16,
122
+ q, rd, rn, rm);
123
+ case 2:
124
+ return do_v81_helper(s, gen_helper_gvec_qrdmlsh_s32,
125
+ q, rd, rn, rm);
126
+ }
127
+ return 1;
128
}
129
if (size == 3 && op != NEON_3R_LOGIC) {
130
/* 64-bit element instructions. */
131
@@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn)
132
rm = rtmp;
133
}
134
break;
135
- case NEON_3R_VPADD:
136
- if (u) {
137
- return 1;
138
- }
139
- /* Fall through */
140
+ case NEON_3R_VPADD_VQRDMLAH:
141
case NEON_3R_VPMAX:
142
case NEON_3R_VPMIN:
143
pairwise = 1;
144
@@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn)
145
return 1;
146
}
147
break;
148
- case NEON_3R_VFM:
149
- if (!arm_dc_feature(s, ARM_FEATURE_VFP4) || u) {
150
+ case NEON_3R_VFM_VQRDMLSH:
151
+ if (!arm_dc_feature(s, ARM_FEATURE_VFP4)) {
152
return 1;
153
}
154
break;
155
@@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn)
156
}
157
}
158
break;
159
- case NEON_3R_VPADD:
160
+ case NEON_3R_VPADD_VQRDMLAH:
161
switch (size) {
162
case 0: gen_helper_neon_padd_u8(tmp, tmp, tmp2); break;
163
case 1: gen_helper_neon_padd_u16(tmp, tmp, tmp2); break;
164
@@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn)
165
}
166
}
167
break;
168
- case NEON_3R_VFM:
169
+ case NEON_3R_VFM_VQRDMLSH:
170
{
171
/* VFMA, VFMS: fused multiply-add */
172
TCGv_ptr fpstatus = get_fpstatus_ptr(1);
173
--
97
--
174
2.16.2
98
2.20.1
175
99
176
100
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Havard Skinnemoen <hskinnemoen@google.com>
2
2
3
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
3
Reviewed-by: Cédric Le Goater <clg@kaod.org>
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
4
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
5
Message-id: 20180228193125.20577-5-richard.henderson@linaro.org
5
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
6
Message-id: 20200911052101.2602693-14-hskinnemoen@google.com
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
---
8
---
8
target/arm/Makefile.objs | 2 +-
9
docs/system/arm/nuvoton.rst | 92 +++++++++++++++++++++++++++++++++++++
9
target/arm/helper.h | 4 ++
10
docs/system/target-arm.rst | 1 +
10
target/arm/translate-a64.c | 84 ++++++++++++++++++++++++++++++++++
11
2 files changed, 93 insertions(+)
11
target/arm/vec_helper.c | 109 +++++++++++++++++++++++++++++++++++++++++++++
12
create mode 100644 docs/system/arm/nuvoton.rst
12
4 files changed, 198 insertions(+), 1 deletion(-)
13
create mode 100644 target/arm/vec_helper.c
14
13
15
diff --git a/target/arm/Makefile.objs b/target/arm/Makefile.objs
14
diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst
16
index XXXXXXX..XXXXXXX 100644
17
--- a/target/arm/Makefile.objs
18
+++ b/target/arm/Makefile.objs
19
@@ -XXX,XX +XXX,XX @@ obj-$(call land,$(CONFIG_KVM),$(call lnot,$(TARGET_AARCH64))) += kvm32.o
20
obj-$(call land,$(CONFIG_KVM),$(TARGET_AARCH64)) += kvm64.o
21
obj-$(call lnot,$(CONFIG_KVM)) += kvm-stub.o
22
obj-y += translate.o op_helper.o helper.o cpu.o
23
-obj-y += neon_helper.o iwmmxt_helper.o
24
+obj-y += neon_helper.o iwmmxt_helper.o vec_helper.o
25
obj-y += gdbstub.o
26
obj-$(TARGET_AARCH64) += cpu64.o translate-a64.o helper-a64.o gdbstub64.o
27
obj-y += crypto_helper.o
28
diff --git a/target/arm/helper.h b/target/arm/helper.h
29
index XXXXXXX..XXXXXXX 100644
30
--- a/target/arm/helper.h
31
+++ b/target/arm/helper.h
32
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_1(neon_rbit_u8, TCG_CALL_NO_RWG_SE, i32, i32)
33
34
DEF_HELPER_3(neon_qdmulh_s16, i32, env, i32, i32)
35
DEF_HELPER_3(neon_qrdmulh_s16, i32, env, i32, i32)
36
+DEF_HELPER_4(neon_qrdmlah_s16, i32, env, i32, i32, i32)
37
+DEF_HELPER_4(neon_qrdmlsh_s16, i32, env, i32, i32, i32)
38
DEF_HELPER_3(neon_qdmulh_s32, i32, env, i32, i32)
39
DEF_HELPER_3(neon_qrdmulh_s32, i32, env, i32, i32)
40
+DEF_HELPER_4(neon_qrdmlah_s32, i32, env, s32, s32, s32)
41
+DEF_HELPER_4(neon_qrdmlsh_s32, i32, env, s32, s32, s32)
42
43
DEF_HELPER_1(neon_narrow_u8, i32, i64)
44
DEF_HELPER_1(neon_narrow_u16, i32, i64)
45
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
46
index XXXXXXX..XXXXXXX 100644
47
--- a/target/arm/translate-a64.c
48
+++ b/target/arm/translate-a64.c
49
@@ -XXX,XX +XXX,XX @@ static void disas_simd_scalar_three_reg_same_fp16(DisasContext *s,
50
tcg_temp_free_ptr(fpst);
51
}
52
53
+/* AdvSIMD scalar three same extra
54
+ * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
55
+ * +-----+---+-----------+------+---+------+---+--------+---+----+----+
56
+ * | 0 1 | U | 1 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
57
+ * +-----+---+-----------+------+---+------+---+--------+---+----+----+
58
+ */
59
+static void disas_simd_scalar_three_reg_same_extra(DisasContext *s,
60
+ uint32_t insn)
61
+{
62
+ int rd = extract32(insn, 0, 5);
63
+ int rn = extract32(insn, 5, 5);
64
+ int opcode = extract32(insn, 11, 4);
65
+ int rm = extract32(insn, 16, 5);
66
+ int size = extract32(insn, 22, 2);
67
+ bool u = extract32(insn, 29, 1);
68
+ TCGv_i32 ele1, ele2, ele3;
69
+ TCGv_i64 res;
70
+ int feature;
71
+
72
+ switch (u * 16 + opcode) {
73
+ case 0x10: /* SQRDMLAH (vector) */
74
+ case 0x11: /* SQRDMLSH (vector) */
75
+ if (size != 1 && size != 2) {
76
+ unallocated_encoding(s);
77
+ return;
78
+ }
79
+ feature = ARM_FEATURE_V8_RDM;
80
+ break;
81
+ default:
82
+ unallocated_encoding(s);
83
+ return;
84
+ }
85
+ if (!arm_dc_feature(s, feature)) {
86
+ unallocated_encoding(s);
87
+ return;
88
+ }
89
+ if (!fp_access_check(s)) {
90
+ return;
91
+ }
92
+
93
+ /* Do a single operation on the lowest element in the vector.
94
+ * We use the standard Neon helpers and rely on 0 OP 0 == 0
95
+ * with no side effects for all these operations.
96
+ * OPTME: special-purpose helpers would avoid doing some
97
+ * unnecessary work in the helper for the 16 bit cases.
98
+ */
99
+ ele1 = tcg_temp_new_i32();
100
+ ele2 = tcg_temp_new_i32();
101
+ ele3 = tcg_temp_new_i32();
102
+
103
+ read_vec_element_i32(s, ele1, rn, 0, size);
104
+ read_vec_element_i32(s, ele2, rm, 0, size);
105
+ read_vec_element_i32(s, ele3, rd, 0, size);
106
+
107
+ switch (opcode) {
108
+ case 0x0: /* SQRDMLAH */
109
+ if (size == 1) {
110
+ gen_helper_neon_qrdmlah_s16(ele3, cpu_env, ele1, ele2, ele3);
111
+ } else {
112
+ gen_helper_neon_qrdmlah_s32(ele3, cpu_env, ele1, ele2, ele3);
113
+ }
114
+ break;
115
+ case 0x1: /* SQRDMLSH */
116
+ if (size == 1) {
117
+ gen_helper_neon_qrdmlsh_s16(ele3, cpu_env, ele1, ele2, ele3);
118
+ } else {
119
+ gen_helper_neon_qrdmlsh_s32(ele3, cpu_env, ele1, ele2, ele3);
120
+ }
121
+ break;
122
+ default:
123
+ g_assert_not_reached();
124
+ }
125
+ tcg_temp_free_i32(ele1);
126
+ tcg_temp_free_i32(ele2);
127
+
128
+ res = tcg_temp_new_i64();
129
+ tcg_gen_extu_i32_i64(res, ele3);
130
+ tcg_temp_free_i32(ele3);
131
+
132
+ write_fp_dreg(s, rd, res);
133
+ tcg_temp_free_i64(res);
134
+}
135
+
136
static void handle_2misc_64(DisasContext *s, int opcode, bool u,
137
TCGv_i64 tcg_rd, TCGv_i64 tcg_rn,
138
TCGv_i32 tcg_rmode, TCGv_ptr tcg_fpstatus)
139
@@ -XXX,XX +XXX,XX @@ static const AArch64DecodeTable data_proc_simd[] = {
140
{ 0x0e000800, 0xbf208c00, disas_simd_zip_trn },
141
{ 0x2e000000, 0xbf208400, disas_simd_ext },
142
{ 0x5e200400, 0xdf200400, disas_simd_scalar_three_reg_same },
143
+ { 0x5e008400, 0xdf208400, disas_simd_scalar_three_reg_same_extra },
144
{ 0x5e200000, 0xdf200c00, disas_simd_scalar_three_reg_diff },
145
{ 0x5e200800, 0xdf3e0c00, disas_simd_scalar_two_reg_misc },
146
{ 0x5e300800, 0xdf3e0c00, disas_simd_scalar_pairwise },
147
diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c
148
new file mode 100644
15
new file mode 100644
149
index XXXXXXX..XXXXXXX
16
index XXXXXXX..XXXXXXX
150
--- /dev/null
17
--- /dev/null
151
+++ b/target/arm/vec_helper.c
18
+++ b/docs/system/arm/nuvoton.rst
152
@@ -XXX,XX +XXX,XX @@
19
@@ -XXX,XX +XXX,XX @@
153
+/*
20
+Nuvoton iBMC boards (``npcm750-evb``, ``quanta-gsj``)
154
+ * ARM AdvSIMD / SVE Vector Operations
21
+=====================================================
155
+ *
156
+ * Copyright (c) 2018 Linaro
157
+ *
158
+ * This library is free software; you can redistribute it and/or
159
+ * modify it under the terms of the GNU Lesser General Public
160
+ * License as published by the Free Software Foundation; either
161
+ * version 2 of the License, or (at your option) any later version.
162
+ *
163
+ * This library is distributed in the hope that it will be useful,
164
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
165
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
166
+ * Lesser General Public License for more details.
167
+ *
168
+ * You should have received a copy of the GNU Lesser General Public
169
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
170
+ */
171
+
22
+
172
+#include "qemu/osdep.h"
23
+The `Nuvoton iBMC`_ chips (NPCM7xx) are a family of ARM-based SoCs that are
173
+#include "cpu.h"
24
+designed to be used as Baseboard Management Controllers (BMCs) in various
174
+#include "exec/exec-all.h"
25
+servers. They all feature one or two ARM Cortex A9 CPU cores, as well as an
175
+#include "exec/helper-proto.h"
26
+assortment of peripherals targeted for either Enterprise or Data Center /
176
+#include "tcg/tcg-gvec-desc.h"
27
+Hyperscale applications. The former is a superset of the latter, so NPCM750 has
28
+all the peripherals of NPCM730 and more.
177
+
29
+
30
+.. _Nuvoton iBMC: https://www.nuvoton.com/products/cloud-computing/ibmc/
178
+
31
+
179
+#define SET_QC() env->vfp.xregs[ARM_VFP_FPSCR] |= CPSR_Q
32
+The NPCM750 SoC has two Cortex A9 cores and is targeted for the Enterprise
33
+segment. The following machines are based on this chip :
180
+
34
+
181
+/* Signed saturating rounding doubling multiply-accumulate high half, 16-bit */
35
+- ``npcm750-evb`` Nuvoton NPCM750 Evaluation board
182
+static uint16_t inl_qrdmlah_s16(CPUARMState *env, int16_t src1,
183
+ int16_t src2, int16_t src3)
184
+{
185
+ /* Simplify:
186
+ * = ((a3 << 16) + ((e1 * e2) << 1) + (1 << 15)) >> 16
187
+ * = ((a3 << 15) + (e1 * e2) + (1 << 14)) >> 15
188
+ */
189
+ int32_t ret = (int32_t)src1 * src2;
190
+ ret = ((int32_t)src3 << 15) + ret + (1 << 14);
191
+ ret >>= 15;
192
+ if (ret != (int16_t)ret) {
193
+ SET_QC();
194
+ ret = (ret < 0 ? -0x8000 : 0x7fff);
195
+ }
196
+ return ret;
197
+}
198
+
36
+
199
+uint32_t HELPER(neon_qrdmlah_s16)(CPUARMState *env, uint32_t src1,
37
+The NPCM730 SoC has two Cortex A9 cores and is targeted for Data Center and
200
+ uint32_t src2, uint32_t src3)
38
+Hyperscale applications. The following machines are based on this chip :
201
+{
202
+ uint16_t e1 = inl_qrdmlah_s16(env, src1, src2, src3);
203
+ uint16_t e2 = inl_qrdmlah_s16(env, src1 >> 16, src2 >> 16, src3 >> 16);
204
+ return deposit32(e1, 16, 16, e2);
205
+}
206
+
39
+
207
+/* Signed saturating rounding doubling multiply-subtract high half, 16-bit */
40
+- ``quanta-gsj`` Quanta GSJ server BMC
208
+static uint16_t inl_qrdmlsh_s16(CPUARMState *env, int16_t src1,
209
+ int16_t src2, int16_t src3)
210
+{
211
+ /* Similarly, using subtraction:
212
+ * = ((a3 << 16) - ((e1 * e2) << 1) + (1 << 15)) >> 16
213
+ * = ((a3 << 15) - (e1 * e2) + (1 << 14)) >> 15
214
+ */
215
+ int32_t ret = (int32_t)src1 * src2;
216
+ ret = ((int32_t)src3 << 15) - ret + (1 << 14);
217
+ ret >>= 15;
218
+ if (ret != (int16_t)ret) {
219
+ SET_QC();
220
+ ret = (ret < 0 ? -0x8000 : 0x7fff);
221
+ }
222
+ return ret;
223
+}
224
+
41
+
225
+uint32_t HELPER(neon_qrdmlsh_s16)(CPUARMState *env, uint32_t src1,
42
+There are also two more SoCs, NPCM710 and NPCM705, which are single-core
226
+ uint32_t src2, uint32_t src3)
43
+variants of NPCM750 and NPCM730, respectively. These are currently not
227
+{
44
+supported by QEMU.
228
+ uint16_t e1 = inl_qrdmlsh_s16(env, src1, src2, src3);
229
+ uint16_t e2 = inl_qrdmlsh_s16(env, src1 >> 16, src2 >> 16, src3 >> 16);
230
+ return deposit32(e1, 16, 16, e2);
231
+}
232
+
45
+
233
+/* Signed saturating rounding doubling multiply-accumulate high half, 32-bit */
46
+Supported devices
234
+uint32_t HELPER(neon_qrdmlah_s32)(CPUARMState *env, int32_t src1,
47
+-----------------
235
+ int32_t src2, int32_t src3)
236
+{
237
+ /* Simplify similarly to int_qrdmlah_s16 above. */
238
+ int64_t ret = (int64_t)src1 * src2;
239
+ ret = ((int64_t)src3 << 31) + ret + (1 << 30);
240
+ ret >>= 31;
241
+ if (ret != (int32_t)ret) {
242
+ SET_QC();
243
+ ret = (ret < 0 ? INT32_MIN : INT32_MAX);
244
+ }
245
+ return ret;
246
+}
247
+
48
+
248
+/* Signed saturating rounding doubling multiply-subtract high half, 32-bit */
49
+ * SMP (Dual Core Cortex-A9)
249
+uint32_t HELPER(neon_qrdmlsh_s32)(CPUARMState *env, int32_t src1,
50
+ * Cortex-A9MPCore built-in peripherals: SCU, GIC, Global Timer, Private Timer
250
+ int32_t src2, int32_t src3)
51
+ and Watchdog.
251
+{
52
+ * SRAM, ROM and DRAM mappings
252
+ /* Simplify similarly to int_qrdmlsh_s16 above. */
53
+ * System Global Control Registers (GCR)
253
+ int64_t ret = (int64_t)src1 * src2;
54
+ * Clock and reset controller (CLK)
254
+ ret = ((int64_t)src3 << 31) - ret + (1 << 30);
55
+ * Timer controller (TIM)
255
+ ret >>= 31;
56
+ * Serial ports (16550-based)
256
+ if (ret != (int32_t)ret) {
57
+ * DDR4 memory controller (dummy interface indicating memory training is done)
257
+ SET_QC();
58
+ * OTP controllers (no protection features)
258
+ ret = (ret < 0 ? INT32_MIN : INT32_MAX);
59
+ * Flash Interface Unit (FIU; no protection features)
259
+ }
60
+
260
+ return ret;
61
+Missing devices
261
+}
62
+---------------
63
+
64
+ * GPIO controller
65
+ * LPC/eSPI host-to-BMC interface, including
66
+
67
+ * Keyboard and mouse controller interface (KBCI)
68
+ * Keyboard Controller Style (KCS) channels
69
+ * BIOS POST code FIFO
70
+ * System Wake-up Control (SWC)
71
+ * Shared memory (SHM)
72
+ * eSPI slave interface
73
+
74
+ * Ethernet controllers (GMAC and EMC)
75
+ * USB host (USBH)
76
+ * USB device (USBD)
77
+ * SMBus controller (SMBF)
78
+ * Peripheral SPI controller (PSPI)
79
+ * Analog to Digital Converter (ADC)
80
+ * SD/MMC host
81
+ * Random Number Generator (RNG)
82
+ * PECI interface
83
+ * Pulse Width Modulation (PWM)
84
+ * Tachometer
85
+ * PCI and PCIe root complex and bridges
86
+ * VDM and MCTP support
87
+ * Serial I/O expansion
88
+ * LPC/eSPI host
89
+ * Coprocessor
90
+ * Graphics
91
+ * Video capture
92
+ * Encoding compression engine
93
+ * Security features
94
+
95
+Boot options
96
+------------
97
+
98
+The Nuvoton machines can boot from an OpenBMC firmware image, or directly into
99
+a kernel using the ``-kernel`` option. OpenBMC images for `quanta-gsj` and
100
+possibly others can be downloaded from the OpenPOWER jenkins :
101
+
102
+ https://openpower.xyz/
103
+
104
+The firmware image should be attached as an MTD drive. Example :
105
+
106
+.. code-block:: bash
107
+
108
+ $ qemu-system-arm -machine quanta-gsj -nographic \
109
+ -drive file=image-bmc,if=mtd,bus=0,unit=0,format=raw
110
+
111
+The default root password for test images is usually ``0penBmc``.
112
diff --git a/docs/system/target-arm.rst b/docs/system/target-arm.rst
113
index XXXXXXX..XXXXXXX 100644
114
--- a/docs/system/target-arm.rst
115
+++ b/docs/system/target-arm.rst
116
@@ -XXX,XX +XXX,XX @@ undocumented; you can get a complete list by running
117
arm/musicpal
118
arm/gumstix
119
arm/nseries
120
+ arm/nuvoton
121
arm/orangepi
122
arm/palm
123
arm/xscale
262
--
124
--
263
2.16.2
125
2.20.1
264
126
265
127
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Havard Skinnemoen <hskinnemoen@google.com>
2
2
3
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
3
This adds two acceptance tests for the quanta-gsj machine.
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
4
5
Message-id: 20180228193125.20577-7-richard.henderson@linaro.org
5
One test downloads a lightly patched openbmc flash image from github and
6
verifies that it boots all the way to the login prompt.
7
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
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
---
18
---
8
target/arm/translate-a64.c | 29 +++++++++++++++++++++++++++++
19
tests/acceptance/boot_linux_console.py | 83 ++++++++++++++++++++++++++
9
1 file changed, 29 insertions(+)
20
1 file changed, 83 insertions(+)
10
21
11
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
22
diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
12
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
13
--- a/target/arm/translate-a64.c
24
--- a/tests/acceptance/boot_linux_console.py
14
+++ b/target/arm/translate-a64.c
25
+++ b/tests/acceptance/boot_linux_console.py
15
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
26
@@ -XXX,XX +XXX,XX @@ class BootLinuxConsole(LinuxKernelTest):
16
case 0x19: /* FMULX */
27
'sda')
17
is_fp = true;
28
# cubieboard's reboot is not functioning; omit reboot test.
18
break;
29
19
+ case 0x1d: /* SQRDMLAH */
30
+ def test_arm_quanta_gsj(self):
20
+ case 0x1f: /* SQRDMLSH */
31
+ """
21
+ if (!arm_dc_feature(s, ARM_FEATURE_V8_RDM)) {
32
+ :avocado: tags=arch:arm
22
+ unallocated_encoding(s);
33
+ :avocado: tags=machine:quanta-gsj
23
+ return;
34
+ """
24
+ }
35
+ # 25 MiB compressed, 32 MiB uncompressed.
25
+ break;
36
+ image_url = (
26
default:
37
+ 'https://github.com/hskinnemoen/openbmc/releases/download/'
27
unallocated_encoding(s);
38
+ '20200711-gsj-qemu-0/obmc-phosphor-image-gsj.static.mtd.gz')
28
return;
39
+ image_hash = '14895e634923345cb5c8776037ff7876df96f6b1'
29
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
40
+ image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash)
30
tcg_op, tcg_idx);
41
+ image_name = 'obmc.mtd'
31
}
42
+ image_path = os.path.join(self.workdir, image_name)
32
break;
43
+ archive.gzip_uncompress(image_path_gz, image_path)
33
+ case 0x1d: /* SQRDMLAH */
44
+
34
+ read_vec_element_i32(s, tcg_res, rd, pass,
45
+ self.vm.set_console()
35
+ is_scalar ? size : MO_32);
46
+ drive_args = 'file=' + image_path + ',if=mtd,bus=0,unit=0'
36
+ if (size == 1) {
47
+ self.vm.add_args('-drive', drive_args)
37
+ gen_helper_neon_qrdmlah_s16(tcg_res, cpu_env,
48
+ self.vm.launch()
38
+ tcg_op, tcg_idx, tcg_res);
49
+
39
+ } else {
50
+ # Disable drivers and services that stall for a long time during boot,
40
+ gen_helper_neon_qrdmlah_s32(tcg_res, cpu_env,
51
+ # to avoid running past the 90-second timeout. These may be removed
41
+ tcg_op, tcg_idx, tcg_res);
52
+ # as the corresponding device support is added.
42
+ }
53
+ kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + (
43
+ break;
54
+ 'console=${console} '
44
+ case 0x1f: /* SQRDMLSH */
55
+ 'mem=${mem} '
45
+ read_vec_element_i32(s, tcg_res, rd, pass,
56
+ 'initcall_blacklist=npcm_i2c_bus_driver_init '
46
+ is_scalar ? size : MO_32);
57
+ 'systemd.mask=systemd-random-seed.service '
47
+ if (size == 1) {
58
+ 'systemd.mask=dropbearkey.service '
48
+ gen_helper_neon_qrdmlsh_s16(tcg_res, cpu_env,
59
+ )
49
+ tcg_op, tcg_idx, tcg_res);
60
+
50
+ } else {
61
+ self.wait_for_console_pattern('> BootBlock by Nuvoton')
51
+ gen_helper_neon_qrdmlsh_s32(tcg_res, cpu_env,
62
+ self.wait_for_console_pattern('>Device: Poleg BMC NPCM730')
52
+ tcg_op, tcg_idx, tcg_res);
63
+ self.wait_for_console_pattern('>Skip DDR init.')
53
+ }
64
+ self.wait_for_console_pattern('U-Boot ')
54
+ break;
65
+ interrupt_interactive_console_until_pattern(
55
default:
66
+ self, 'Hit any key to stop autoboot:', 'U-Boot>')
56
g_assert_not_reached();
67
+ exec_command_and_wait_for_pattern(
57
}
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
58
--
116
--
59
2.16.2
117
2.20.1
60
118
61
119
diff view generated by jsdifflib
1
From: Alistair Francis <alistair.francis@xilinx.com>
1
From: Vikram Garhwal <fnu.vikram@xilinx.com>
2
2
3
Initial commit of the ZynqMP RTC device.
3
The Xilinx ZynqMP CAN controller is developed based on SocketCAN, QEMU CAN bus
4
implementation. Bus connection and socketCAN connection for each CAN module
5
can be set through command lines.
4
6
5
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
7
Example for using single CAN:
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
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]
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
27
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
---
28
---
9
hw/timer/Makefile.objs | 1 +
29
include/hw/net/xlnx-zynqmp-can.h | 78 ++
10
include/hw/timer/xlnx-zynqmp-rtc.h | 84 +++++++++++++++
30
hw/net/can/xlnx-zynqmp-can.c | 1165 ++++++++++++++++++++++++++++++
11
hw/timer/xlnx-zynqmp-rtc.c | 214 +++++++++++++++++++++++++++++++++++++
31
hw/net/can/meson.build | 1 +
12
3 files changed, 299 insertions(+)
32
3 files changed, 1244 insertions(+)
13
create mode 100644 include/hw/timer/xlnx-zynqmp-rtc.h
33
create mode 100644 include/hw/net/xlnx-zynqmp-can.h
14
create mode 100644 hw/timer/xlnx-zynqmp-rtc.c
34
create mode 100644 hw/net/can/xlnx-zynqmp-can.c
15
35
16
diff --git a/hw/timer/Makefile.objs b/hw/timer/Makefile.objs
36
diff --git a/include/hw/net/xlnx-zynqmp-can.h b/include/hw/net/xlnx-zynqmp-can.h
17
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/timer/Makefile.objs
19
+++ b/hw/timer/Makefile.objs
20
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_IMX) += imx_epit.o
21
common-obj-$(CONFIG_IMX) += imx_gpt.o
22
common-obj-$(CONFIG_LM32) += lm32_timer.o
23
common-obj-$(CONFIG_MILKYMIST) += milkymist-sysctl.o
24
+common-obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-zynqmp-rtc.o
25
26
obj-$(CONFIG_ALTERA_TIMER) += altera_timer.o
27
obj-$(CONFIG_EXYNOS4) += exynos4210_mct.o
28
diff --git a/include/hw/timer/xlnx-zynqmp-rtc.h b/include/hw/timer/xlnx-zynqmp-rtc.h
29
new file mode 100644
37
new file mode 100644
30
index XXXXXXX..XXXXXXX
38
index XXXXXXX..XXXXXXX
31
--- /dev/null
39
--- /dev/null
32
+++ b/include/hw/timer/xlnx-zynqmp-rtc.h
40
+++ b/include/hw/net/xlnx-zynqmp-can.h
33
@@ -XXX,XX +XXX,XX @@
41
@@ -XXX,XX +XXX,XX @@
34
+/*
42
+/*
35
+ * QEMU model of the Xilinx ZynqMP Real Time Clock (RTC).
43
+ * QEMU model of the Xilinx ZynqMP CAN controller.
36
+ *
44
+ *
37
+ * Copyright (c) 2017 Xilinx Inc.
45
+ * Copyright (c) 2020 Xilinx Inc.
38
+ *
46
+ *
39
+ * Written-by: Alistair Francis <alistair.francis@xilinx.com>
47
+ * Written-by: Vikram Garhwal<fnu.vikram@xilinx.com>
48
+ *
49
+ * Based on QEMU CAN Device emulation implemented by Jin Yang, Deniz Eren and
50
+ * Pavel Pisa.
40
+ *
51
+ *
41
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
52
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
42
+ * of this software and associated documentation files (the "Software"), to deal
53
+ * of this software and associated documentation files (the "Software"), to deal
43
+ * in the Software without restriction, including without limitation the rights
54
+ * in the Software without restriction, including without limitation the rights
44
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
55
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
...
...
55
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
66
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
56
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
67
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
57
+ * THE SOFTWARE.
68
+ * THE SOFTWARE.
58
+ */
69
+ */
59
+
70
+
71
+#ifndef XLNX_ZYNQMP_CAN_H
72
+#define XLNX_ZYNQMP_CAN_H
73
+
60
+#include "hw/register.h"
74
+#include "hw/register.h"
61
+
75
+#include "net/can_emu.h"
62
+#define TYPE_XLNX_ZYNQMP_RTC "xlnx-zynmp.rtc"
76
+#include "net/can_host.h"
63
+
77
+#include "qemu/fifo32.h"
64
+#define XLNX_ZYNQMP_RTC(obj) \
78
+#include "hw/ptimer.h"
65
+ OBJECT_CHECK(XlnxZynqMPRTC, (obj), TYPE_XLNX_ZYNQMP_RTC)
79
+#include "hw/qdev-clock.h"
66
+
80
+
67
+REG32(SET_TIME_WRITE, 0x0)
81
+#define TYPE_XLNX_ZYNQMP_CAN "xlnx.zynqmp-can"
68
+REG32(SET_TIME_READ, 0x4)
82
+
69
+REG32(CALIB_WRITE, 0x8)
83
+#define XLNX_ZYNQMP_CAN(obj) \
70
+ FIELD(CALIB_WRITE, FRACTION_EN, 20, 1)
84
+ OBJECT_CHECK(XlnxZynqMPCANState, (obj), TYPE_XLNX_ZYNQMP_CAN)
71
+ FIELD(CALIB_WRITE, FRACTION_DATA, 16, 4)
85
+
72
+ FIELD(CALIB_WRITE, MAX_TICK, 0, 16)
86
+#define MAX_CAN_CTRLS 2
73
+REG32(CALIB_READ, 0xc)
87
+#define XLNX_ZYNQMP_CAN_R_MAX (0x84 / 4)
74
+ FIELD(CALIB_READ, FRACTION_EN, 20, 1)
88
+#define MAILBOX_CAPACITY 64
75
+ FIELD(CALIB_READ, FRACTION_DATA, 16, 4)
89
+#define CAN_TIMER_MAX 0XFFFFUL
76
+ FIELD(CALIB_READ, MAX_TICK, 0, 16)
90
+#define CAN_DEFAULT_CLOCK (24 * 1000 * 1000)
77
+REG32(CURRENT_TIME, 0x10)
91
+
78
+REG32(CURRENT_TICK, 0x14)
92
+/* Each CAN_FRAME will have 4 * 32bit size. */
79
+ FIELD(CURRENT_TICK, VALUE, 0, 16)
93
+#define CAN_FRAME_SIZE 4
80
+REG32(ALARM, 0x18)
94
+#define RXFIFO_SIZE (MAILBOX_CAPACITY * CAN_FRAME_SIZE)
81
+REG32(RTC_INT_STATUS, 0x20)
95
+
82
+ FIELD(RTC_INT_STATUS, ALARM, 1, 1)
96
+typedef struct XlnxZynqMPCANState {
83
+ FIELD(RTC_INT_STATUS, SECONDS, 0, 1)
97
+ SysBusDevice parent_obj;
84
+REG32(RTC_INT_MASK, 0x24)
98
+ MemoryRegion iomem;
85
+ FIELD(RTC_INT_MASK, ALARM, 1, 1)
99
+
86
+ FIELD(RTC_INT_MASK, SECONDS, 0, 1)
100
+ qemu_irq irq;
87
+REG32(RTC_INT_EN, 0x28)
101
+
88
+ FIELD(RTC_INT_EN, ALARM, 1, 1)
102
+ CanBusClientState bus_client;
89
+ FIELD(RTC_INT_EN, SECONDS, 0, 1)
103
+ CanBusState *canbus;
90
+REG32(RTC_INT_DIS, 0x2c)
104
+
91
+ FIELD(RTC_INT_DIS, ALARM, 1, 1)
105
+ struct {
92
+ FIELD(RTC_INT_DIS, SECONDS, 0, 1)
106
+ uint32_t ext_clk_freq;
93
+REG32(ADDR_ERROR, 0x30)
107
+ } cfg;
94
+ FIELD(ADDR_ERROR, STATUS, 0, 1)
108
+
95
+REG32(ADDR_ERROR_INT_MASK, 0x34)
109
+ RegisterInfo reg_info[XLNX_ZYNQMP_CAN_R_MAX];
96
+ FIELD(ADDR_ERROR_INT_MASK, MASK, 0, 1)
110
+ uint32_t regs[XLNX_ZYNQMP_CAN_R_MAX];
97
+REG32(ADDR_ERROR_INT_EN, 0x38)
111
+
98
+ FIELD(ADDR_ERROR_INT_EN, MASK, 0, 1)
112
+ Fifo32 rx_fifo;
99
+REG32(ADDR_ERROR_INT_DIS, 0x3c)
113
+ Fifo32 tx_fifo;
100
+ FIELD(ADDR_ERROR_INT_DIS, MASK, 0, 1)
114
+ Fifo32 txhpb_fifo;
101
+REG32(CONTROL, 0x40)
115
+
102
+ FIELD(CONTROL, BATTERY_DISABLE, 31, 1)
116
+ ptimer_state *can_timer;
103
+ FIELD(CONTROL, OSC_CNTRL, 24, 4)
117
+} XlnxZynqMPCANState;
104
+ FIELD(CONTROL, SLVERR_ENABLE, 0, 1)
118
+
105
+REG32(SAFETY_CHK, 0x50)
119
+#endif
106
+
120
diff --git a/hw/net/can/xlnx-zynqmp-can.c b/hw/net/can/xlnx-zynqmp-can.c
107
+#define XLNX_ZYNQMP_RTC_R_MAX (R_SAFETY_CHK + 1)
108
+
109
+typedef struct XlnxZynqMPRTC {
110
+ SysBusDevice parent_obj;
111
+ MemoryRegion iomem;
112
+ qemu_irq irq_rtc_int;
113
+ qemu_irq irq_addr_error_int;
114
+
115
+ uint32_t regs[XLNX_ZYNQMP_RTC_R_MAX];
116
+ RegisterInfo regs_info[XLNX_ZYNQMP_RTC_R_MAX];
117
+} XlnxZynqMPRTC;
118
diff --git a/hw/timer/xlnx-zynqmp-rtc.c b/hw/timer/xlnx-zynqmp-rtc.c
119
new file mode 100644
121
new file mode 100644
120
index XXXXXXX..XXXXXXX
122
index XXXXXXX..XXXXXXX
121
--- /dev/null
123
--- /dev/null
122
+++ b/hw/timer/xlnx-zynqmp-rtc.c
124
+++ b/hw/net/can/xlnx-zynqmp-can.c
123
@@ -XXX,XX +XXX,XX @@
125
@@ -XXX,XX +XXX,XX @@
124
+/*
126
+/*
125
+ * QEMU model of the Xilinx ZynqMP Real Time Clock (RTC).
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
126
+ *
130
+ *
127
+ * Copyright (c) 2017 Xilinx Inc.
131
+ * Copyright (c) 2020 Xilinx Inc.
128
+ *
132
+ *
129
+ * Written-by: Alistair Francis <alistair.francis@xilinx.com>
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
130
+ *
137
+ *
131
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
138
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
132
+ * of this software and associated documentation files (the "Software"), to deal
139
+ * of this software and associated documentation files (the "Software"), to deal
133
+ * in the Software without restriction, including without limitation the rights
140
+ * in the Software without restriction, including without limitation the rights
134
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
141
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
...
...
148
+ */
155
+ */
149
+
156
+
150
+#include "qemu/osdep.h"
157
+#include "qemu/osdep.h"
151
+#include "hw/sysbus.h"
158
+#include "hw/sysbus.h"
152
+#include "hw/register.h"
159
+#include "hw/register.h"
160
+#include "hw/irq.h"
161
+#include "qapi/error.h"
153
+#include "qemu/bitops.h"
162
+#include "qemu/bitops.h"
154
+#include "qemu/log.h"
163
+#include "qemu/log.h"
155
+#include "hw/timer/xlnx-zynqmp-rtc.h"
164
+#include "qemu/cutils.h"
156
+
165
+#include "sysemu/sysemu.h"
157
+#ifndef XLNX_ZYNQMP_RTC_ERR_DEBUG
166
+#include "migration/vmstate.h"
158
+#define XLNX_ZYNQMP_RTC_ERR_DEBUG 0
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
159
+#endif
176
+#endif
160
+
177
+
161
+static void rtc_int_update_irq(XlnxZynqMPRTC *s)
178
+#define DB_PRINT(dev, ...) do { \
162
+{
179
+ if (XLNX_ZYNQMP_CAN_ERR_DEBUG) { \
163
+ bool pending = s->regs[R_RTC_INT_STATUS] & ~s->regs[R_RTC_INT_MASK];
180
+ g_autofree char *path = object_get_canonical_path(OBJECT(dev)); \
164
+ qemu_set_irq(s->irq_rtc_int, pending);
181
+ qemu_log("%s: %s", path, ## __VA_ARGS__); \
165
+}
182
+ } \
166
+
183
+} while (0)
167
+static void addr_error_int_update_irq(XlnxZynqMPRTC *s)
184
+
168
+{
185
+#define MAX_DLC 8
169
+ bool pending = s->regs[R_ADDR_ERROR] & ~s->regs[R_ADDR_ERROR_INT_MASK];
186
+#undef ERROR
170
+ qemu_set_irq(s->irq_addr_error_int, pending);
187
+
171
+}
188
+REG32(SOFTWARE_RESET_REGISTER, 0x0)
172
+
189
+ FIELD(SOFTWARE_RESET_REGISTER, CEN, 1, 1)
173
+static void rtc_int_status_postw(RegisterInfo *reg, uint64_t val64)
190
+ FIELD(SOFTWARE_RESET_REGISTER, SRST, 0, 1)
174
+{
191
+REG32(MODE_SELECT_REGISTER, 0x4)
175
+ XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(reg->opaque);
192
+ FIELD(MODE_SELECT_REGISTER, SNOOP, 2, 1)
176
+ rtc_int_update_irq(s);
193
+ FIELD(MODE_SELECT_REGISTER, LBACK, 1, 1)
177
+}
194
+ FIELD(MODE_SELECT_REGISTER, SLEEP, 0, 1)
178
+
195
+REG32(ARBITRATION_PHASE_BAUD_RATE_PRESCALER_REGISTER, 0x8)
179
+static uint64_t rtc_int_en_prew(RegisterInfo *reg, uint64_t val64)
196
+ FIELD(ARBITRATION_PHASE_BAUD_RATE_PRESCALER_REGISTER, BRP, 0, 8)
180
+{
197
+REG32(ARBITRATION_PHASE_BIT_TIMING_REGISTER, 0xc)
181
+ XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(reg->opaque);
198
+ FIELD(ARBITRATION_PHASE_BIT_TIMING_REGISTER, SJW, 7, 2)
182
+
199
+ FIELD(ARBITRATION_PHASE_BIT_TIMING_REGISTER, TS2, 4, 3)
183
+ s->regs[R_RTC_INT_MASK] &= (uint32_t) ~val64;
200
+ FIELD(ARBITRATION_PHASE_BIT_TIMING_REGISTER, TS1, 0, 4)
184
+ rtc_int_update_irq(s);
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
+{
387
+ uint32_t irq;
388
+
389
+ /* Watermark register interrupts. */
390
+ if ((fifo32_num_free(&s->tx_fifo) / CAN_FRAME_SIZE) >
391
+ ARRAY_FIELD_EX32(s->regs, WIR, EW)) {
392
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, TXFWMEMP, 1);
393
+ }
394
+
395
+ if ((fifo32_num_used(&s->rx_fifo) / CAN_FRAME_SIZE) >
396
+ ARRAY_FIELD_EX32(s->regs, WIR, FW)) {
397
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, RXFWMFLL, 1);
398
+ }
399
+
400
+ /* RX Interrupts. */
401
+ if (fifo32_num_used(&s->rx_fifo) >= CAN_FRAME_SIZE) {
402
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, RXNEMP, 1);
403
+ }
404
+
405
+ /* TX interrupts. */
406
+ if (fifo32_is_empty(&s->tx_fifo)) {
407
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, TXFEMP, 1);
408
+ }
409
+
410
+ if (fifo32_is_full(&s->tx_fifo)) {
411
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, TXFLL, 1);
412
+ }
413
+
414
+ if (fifo32_is_full(&s->txhpb_fifo)) {
415
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, TXBFLL, 1);
416
+ }
417
+
418
+ irq = s->regs[R_INTERRUPT_STATUS_REGISTER];
419
+ irq &= s->regs[R_INTERRUPT_ENABLE_REGISTER];
420
+
421
+ qemu_set_irq(s->irq, irq);
422
+}
423
+
424
+static void can_ier_post_write(RegisterInfo *reg, uint64_t val64)
425
+{
426
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
427
+
428
+ can_update_irq(s);
429
+}
430
+
431
+static uint64_t can_icr_pre_write(RegisterInfo *reg, uint64_t val64)
432
+{
433
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
434
+ uint32_t val = val64;
435
+
436
+ s->regs[R_INTERRUPT_STATUS_REGISTER] &= ~val;
437
+ can_update_irq(s);
438
+
185
+ return 0;
439
+ return 0;
186
+}
440
+}
187
+
441
+
188
+static uint64_t rtc_int_dis_prew(RegisterInfo *reg, uint64_t val64)
442
+static void can_config_reset(XlnxZynqMPCANState *s)
189
+{
443
+{
190
+ XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(reg->opaque);
444
+ /* Reset all the configuration registers. */
191
+
445
+ register_reset(&s->reg_info[R_SOFTWARE_RESET_REGISTER]);
192
+ s->regs[R_RTC_INT_MASK] |= (uint32_t) val64;
446
+ register_reset(&s->reg_info[R_MODE_SELECT_REGISTER]);
193
+ rtc_int_update_irq(s);
447
+ register_reset(
448
+ &s->reg_info[R_ARBITRATION_PHASE_BAUD_RATE_PRESCALER_REGISTER]);
449
+ register_reset(&s->reg_info[R_ARBITRATION_PHASE_BIT_TIMING_REGISTER]);
450
+ register_reset(&s->reg_info[R_STATUS_REGISTER]);
451
+ register_reset(&s->reg_info[R_INTERRUPT_STATUS_REGISTER]);
452
+ register_reset(&s->reg_info[R_INTERRUPT_ENABLE_REGISTER]);
453
+ register_reset(&s->reg_info[R_INTERRUPT_CLEAR_REGISTER]);
454
+ register_reset(&s->reg_info[R_WIR]);
455
+}
456
+
457
+static void can_config_mode(XlnxZynqMPCANState *s)
458
+{
459
+ register_reset(&s->reg_info[R_ERROR_COUNTER_REGISTER]);
460
+ register_reset(&s->reg_info[R_ERROR_STATUS_REGISTER]);
461
+
462
+ /* Put XlnxZynqMPCAN in configuration mode. */
463
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, CONFIG, 1);
464
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, WKUP, 0);
465
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, SLP, 0);
466
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, BSOFF, 0);
467
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, ERROR, 0);
468
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, RXOFLW, 0);
469
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, RXOK, 0);
470
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, TXOK, 0);
471
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, ARBLST, 0);
472
+
473
+ can_update_irq(s);
474
+}
475
+
476
+static void update_status_register_mode_bits(XlnxZynqMPCANState *s)
477
+{
478
+ bool sleep_status = ARRAY_FIELD_EX32(s->regs, STATUS_REGISTER, SLEEP);
479
+ bool sleep_mode = ARRAY_FIELD_EX32(s->regs, MODE_SELECT_REGISTER, SLEEP);
480
+ /* Wake up interrupt bit. */
481
+ bool wakeup_irq_val = sleep_status && (sleep_mode == 0);
482
+ /* Sleep interrupt bit. */
483
+ bool sleep_irq_val = sleep_mode && (sleep_status == 0);
484
+
485
+ /* Clear previous core mode status bits. */
486
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, LBACK, 0);
487
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, SLEEP, 0);
488
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, SNOOP, 0);
489
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, NORMAL, 0);
490
+
491
+ /* set current mode bit and generate irqs accordingly. */
492
+ if (ARRAY_FIELD_EX32(s->regs, MODE_SELECT_REGISTER, LBACK)) {
493
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, LBACK, 1);
494
+ } else if (ARRAY_FIELD_EX32(s->regs, MODE_SELECT_REGISTER, SLEEP)) {
495
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, SLEEP, 1);
496
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, SLP,
497
+ sleep_irq_val);
498
+ } else if (ARRAY_FIELD_EX32(s->regs, MODE_SELECT_REGISTER, SNOOP)) {
499
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, SNOOP, 1);
500
+ } else {
501
+ /*
502
+ * If all bits are zero then XlnxZynqMPCAN is set in normal mode.
503
+ */
504
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, NORMAL, 1);
505
+ /* Set wakeup interrupt bit. */
506
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, WKUP,
507
+ wakeup_irq_val);
508
+ }
509
+
510
+ can_update_irq(s);
511
+}
512
+
513
+static void can_exit_sleep_mode(XlnxZynqMPCANState *s)
514
+{
515
+ ARRAY_FIELD_DP32(s->regs, MODE_SELECT_REGISTER, SLEEP, 0);
516
+ update_status_register_mode_bits(s);
517
+}
518
+
519
+static void generate_frame(qemu_can_frame *frame, uint32_t *data)
520
+{
521
+ frame->can_id = data[0];
522
+ frame->can_dlc = FIELD_EX32(data[1], TXFIFO_DLC, DLC);
523
+
524
+ frame->data[0] = FIELD_EX32(data[2], TXFIFO_DATA1, DB3);
525
+ frame->data[1] = FIELD_EX32(data[2], TXFIFO_DATA1, DB2);
526
+ frame->data[2] = FIELD_EX32(data[2], TXFIFO_DATA1, DB1);
527
+ frame->data[3] = FIELD_EX32(data[2], TXFIFO_DATA1, DB0);
528
+
529
+ frame->data[4] = FIELD_EX32(data[3], TXFIFO_DATA2, DB7);
530
+ frame->data[5] = FIELD_EX32(data[3], TXFIFO_DATA2, DB6);
531
+ frame->data[6] = FIELD_EX32(data[3], TXFIFO_DATA2, DB5);
532
+ frame->data[7] = FIELD_EX32(data[3], TXFIFO_DATA2, DB4);
533
+}
534
+
535
+static bool tx_ready_check(XlnxZynqMPCANState *s)
536
+{
537
+ if (ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, SRST)) {
538
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
539
+
540
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Attempting to transfer data while"
541
+ " data while controller is in reset mode.\n",
542
+ path);
543
+ return false;
544
+ }
545
+
546
+ if (ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, CEN) == 0) {
547
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
548
+
549
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Attempting to transfer"
550
+ " data while controller is in configuration mode. Reset"
551
+ " the core so operations can start fresh.\n",
552
+ path);
553
+ return false;
554
+ }
555
+
556
+ if (ARRAY_FIELD_EX32(s->regs, STATUS_REGISTER, SNOOP)) {
557
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
558
+
559
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Attempting to transfer"
560
+ " data while controller is in SNOOP MODE.\n",
561
+ path);
562
+ return false;
563
+ }
564
+
565
+ return true;
566
+}
567
+
568
+static void transfer_fifo(XlnxZynqMPCANState *s, Fifo32 *fifo)
569
+{
570
+ qemu_can_frame frame;
571
+ uint32_t data[CAN_FRAME_SIZE];
572
+ int i;
573
+ bool can_tx = tx_ready_check(s);
574
+
575
+ if (can_tx) {
576
+ while (!fifo32_is_empty(fifo)) {
577
+ for (i = 0; i < CAN_FRAME_SIZE; i++) {
578
+ data[i] = fifo32_pop(fifo);
579
+ }
580
+
581
+ if (ARRAY_FIELD_EX32(s->regs, STATUS_REGISTER, LBACK)) {
582
+ /*
583
+ * Controller is in loopback. In Loopback mode, the CAN core
584
+ * transmits a recessive bitstream on to the XlnxZynqMPCAN Bus.
585
+ * Any message transmitted is looped back to the RX line and
586
+ * acknowledged. The XlnxZynqMPCAN core receives any message
587
+ * that it transmits.
588
+ */
589
+ if (fifo32_is_full(&s->rx_fifo)) {
590
+ DB_PRINT(s, "Loopback: RX FIFO is full."
591
+ " TX FIFO will be flushed.\n");
592
+
593
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER,
594
+ RXOFLW, 1);
595
+ } else {
596
+ for (i = 0; i < CAN_FRAME_SIZE; i++) {
597
+ fifo32_push(&s->rx_fifo, data[i]);
598
+ }
599
+
600
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER,
601
+ RXOK, 1);
602
+ }
603
+ } else {
604
+ /* Normal mode Tx. */
605
+ generate_frame(&frame, data);
606
+
607
+ can_bus_client_send(&s->bus_client, &frame, 1);
608
+ }
609
+ }
610
+
611
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, TXOK, 1);
612
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, TXBFLL, 0);
613
+
614
+ if (ARRAY_FIELD_EX32(s->regs, STATUS_REGISTER, SLEEP)) {
615
+ can_exit_sleep_mode(s);
616
+ }
617
+ } else {
618
+ DB_PRINT(s, "Not enabled for data transfer.\n");
619
+ }
620
+
621
+ can_update_irq(s);
622
+}
623
+
624
+static uint64_t can_srr_pre_write(RegisterInfo *reg, uint64_t val64)
625
+{
626
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
627
+ uint32_t val = val64;
628
+
629
+ ARRAY_FIELD_DP32(s->regs, SOFTWARE_RESET_REGISTER, CEN,
630
+ FIELD_EX32(val, SOFTWARE_RESET_REGISTER, CEN));
631
+
632
+ if (FIELD_EX32(val, SOFTWARE_RESET_REGISTER, SRST)) {
633
+ DB_PRINT(s, "Resetting controller.\n");
634
+
635
+ /* First, core will do software reset then will enter in config mode. */
636
+ can_config_reset(s);
637
+ }
638
+
639
+ if (ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, CEN) == 0) {
640
+ can_config_mode(s);
641
+ } else {
642
+ /*
643
+ * Leave config mode. Now XlnxZynqMPCAN core will enter normal,
644
+ * sleep, snoop or loopback mode depending upon LBACK, SLEEP, SNOOP
645
+ * register states.
646
+ */
647
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, CONFIG, 0);
648
+
649
+ ptimer_transaction_begin(s->can_timer);
650
+ ptimer_set_count(s->can_timer, 0);
651
+ ptimer_transaction_commit(s->can_timer);
652
+
653
+ /* XlnxZynqMPCAN is out of config mode. It will send pending data. */
654
+ transfer_fifo(s, &s->txhpb_fifo);
655
+ transfer_fifo(s, &s->tx_fifo);
656
+ }
657
+
658
+ update_status_register_mode_bits(s);
659
+
660
+ return s->regs[R_SOFTWARE_RESET_REGISTER];
661
+}
662
+
663
+static uint64_t can_msr_pre_write(RegisterInfo *reg, uint64_t val64)
664
+{
665
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
666
+ uint32_t val = val64;
667
+ uint8_t multi_mode;
668
+
669
+ /*
670
+ * Multiple mode set check. This is done to make sure user doesn't set
671
+ * multiple modes.
672
+ */
673
+ multi_mode = FIELD_EX32(val, MODE_SELECT_REGISTER, LBACK) +
674
+ FIELD_EX32(val, MODE_SELECT_REGISTER, SLEEP) +
675
+ FIELD_EX32(val, MODE_SELECT_REGISTER, SNOOP);
676
+
677
+ if (multi_mode > 1) {
678
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
679
+
680
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Attempting to config"
681
+ " several modes simultaneously. One mode will be selected"
682
+ " according to their priority: LBACK > SLEEP > SNOOP.\n",
683
+ path);
684
+ }
685
+
686
+ if (ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, CEN) == 0) {
687
+ /* We are in configuration mode, any mode can be selected. */
688
+ s->regs[R_MODE_SELECT_REGISTER] = val;
689
+ } else {
690
+ bool sleep_mode_bit = FIELD_EX32(val, MODE_SELECT_REGISTER, SLEEP);
691
+
692
+ ARRAY_FIELD_DP32(s->regs, MODE_SELECT_REGISTER, SLEEP, sleep_mode_bit);
693
+
694
+ if (FIELD_EX32(val, MODE_SELECT_REGISTER, LBACK)) {
695
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
696
+
697
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Attempting to set"
698
+ " LBACK mode without setting CEN bit as 0.\n",
699
+ path);
700
+ } else if (FIELD_EX32(val, MODE_SELECT_REGISTER, SNOOP)) {
701
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
702
+
703
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Attempting to set"
704
+ " SNOOP mode without setting CEN bit as 0.\n",
705
+ path);
706
+ }
707
+
708
+ update_status_register_mode_bits(s);
709
+ }
710
+
711
+ return s->regs[R_MODE_SELECT_REGISTER];
712
+}
713
+
714
+static uint64_t can_brpr_pre_write(RegisterInfo *reg, uint64_t val64)
715
+{
716
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
717
+ uint32_t val = val64;
718
+
719
+ /* Only allow writes when in config mode. */
720
+ if (ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, CEN)) {
721
+ val = s->regs[R_ARBITRATION_PHASE_BAUD_RATE_PRESCALER_REGISTER];
722
+ }
723
+
724
+ return val;
725
+}
726
+
727
+static uint64_t can_btr_pre_write(RegisterInfo *reg, uint64_t val64)
728
+{
729
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
730
+ uint32_t val = val64;
731
+
732
+ /* Only allow writes when in config mode. */
733
+ if (ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, CEN)) {
734
+ val = s->regs[R_ARBITRATION_PHASE_BIT_TIMING_REGISTER];
735
+ }
736
+
737
+ return val;
738
+}
739
+
740
+static uint64_t can_tcr_pre_write(RegisterInfo *reg, uint64_t val64)
741
+{
742
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
743
+ uint32_t val = val64;
744
+
745
+ if (FIELD_EX32(val, TIMESTAMP_REGISTER, CTS)) {
746
+ ptimer_transaction_begin(s->can_timer);
747
+ ptimer_set_count(s->can_timer, 0);
748
+ ptimer_transaction_commit(s->can_timer);
749
+ }
750
+
194
+ return 0;
751
+ return 0;
195
+}
752
+}
196
+
753
+
197
+static void addr_error_postw(RegisterInfo *reg, uint64_t val64)
754
+static void update_rx_fifo(XlnxZynqMPCANState *s, const qemu_can_frame *frame)
198
+{
755
+{
199
+ XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(reg->opaque);
756
+ bool filter_pass = false;
200
+ addr_error_int_update_irq(s);
757
+ uint16_t timestamp = 0;
201
+}
758
+
202
+
759
+ /* If no filter is enabled. Message will be stored in FIFO. */
203
+static uint64_t addr_error_int_en_prew(RegisterInfo *reg, uint64_t val64)
760
+ if (!((ARRAY_FIELD_EX32(s->regs, AFR, UAF1)) |
204
+{
761
+ (ARRAY_FIELD_EX32(s->regs, AFR, UAF2)) |
205
+ XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(reg->opaque);
762
+ (ARRAY_FIELD_EX32(s->regs, AFR, UAF3)) |
206
+
763
+ (ARRAY_FIELD_EX32(s->regs, AFR, UAF4)))) {
207
+ s->regs[R_ADDR_ERROR_INT_MASK] &= (uint32_t) ~val64;
764
+ filter_pass = true;
208
+ addr_error_int_update_irq(s);
765
+ }
209
+ return 0;
766
+
210
+}
767
+ /*
211
+
768
+ * Messages that pass any of the acceptance filters will be stored in
212
+static uint64_t addr_error_int_dis_prew(RegisterInfo *reg, uint64_t val64)
769
+ * the RX FIFO.
213
+{
770
+ */
214
+ XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(reg->opaque);
771
+ if (ARRAY_FIELD_EX32(s->regs, AFR, UAF1)) {
215
+
772
+ uint32_t id_masked = s->regs[R_AFMR1] & frame->can_id;
216
+ s->regs[R_ADDR_ERROR_INT_MASK] |= (uint32_t) val64;
773
+ uint32_t filter_id_masked = s->regs[R_AFMR1] & s->regs[R_AFIR1];
217
+ addr_error_int_update_irq(s);
774
+
218
+ return 0;
775
+ if (filter_id_masked == id_masked) {
219
+}
776
+ filter_pass = true;
220
+
777
+ }
221
+static const RegisterAccessInfo rtc_regs_info[] = {
778
+ }
222
+ { .name = "SET_TIME_WRITE", .addr = A_SET_TIME_WRITE,
779
+
223
+ },{ .name = "SET_TIME_READ", .addr = A_SET_TIME_READ,
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,
224
+ .ro = 0xffffffff,
986
+ .ro = 0xffffffff,
225
+ },{ .name = "CALIB_WRITE", .addr = A_CALIB_WRITE,
987
+ },{ .name = "ERROR_STATUS_REGISTER",
226
+ },{ .name = "CALIB_READ", .addr = A_CALIB_READ,
988
+ .addr = A_ERROR_STATUS_REGISTER,
227
+ .ro = 0x1fffff,
989
+ .rsvd = 0xffffffe0,
228
+ },{ .name = "CURRENT_TIME", .addr = A_CURRENT_TIME,
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,
229
+ .ro = 0xffffffff,
1034
+ .ro = 0xffffffff,
230
+ },{ .name = "CURRENT_TICK", .addr = A_CURRENT_TICK,
1035
+ .post_read = can_rxfifo_pre_read,
231
+ .ro = 0xffff,
1036
+ },{ .name = "RXFIFO_DLC", .addr = A_RXFIFO_DLC,
232
+ },{ .name = "ALARM", .addr = A_ALARM,
1037
+ .rsvd = 0xfff0000,
233
+ },{ .name = "RTC_INT_STATUS", .addr = A_RTC_INT_STATUS,
1038
+ .post_read = can_rxfifo_pre_read,
234
+ .w1c = 0x3,
1039
+ },{ .name = "RXFIFO_DATA1", .addr = A_RXFIFO_DATA1,
235
+ .post_write = rtc_int_status_postw,
1040
+ .post_read = can_rxfifo_pre_read,
236
+ },{ .name = "RTC_INT_MASK", .addr = A_RTC_INT_MASK,
1041
+ },{ .name = "RXFIFO_DATA2", .addr = A_RXFIFO_DATA2,
237
+ .reset = 0x3,
1042
+ .post_read = can_rxfifo_pre_read,
238
+ .ro = 0x3,
1043
+ },{ .name = "AFR", .addr = A_AFR,
239
+ },{ .name = "RTC_INT_EN", .addr = A_RTC_INT_EN,
1044
+ .rsvd = 0xfffffff0,
240
+ .pre_write = rtc_int_en_prew,
1045
+ .post_write = can_filter_enable_post_write,
241
+ },{ .name = "RTC_INT_DIS", .addr = A_RTC_INT_DIS,
1046
+ },{ .name = "AFMR1", .addr = A_AFMR1,
242
+ .pre_write = rtc_int_dis_prew,
1047
+ .pre_write = can_filter_mask_pre_write,
243
+ },{ .name = "ADDR_ERROR", .addr = A_ADDR_ERROR,
1048
+ },{ .name = "AFIR1", .addr = A_AFIR1,
244
+ .w1c = 0x1,
1049
+ .pre_write = can_filter_id_pre_write,
245
+ .post_write = addr_error_postw,
1050
+ },{ .name = "AFMR2", .addr = A_AFMR2,
246
+ },{ .name = "ADDR_ERROR_INT_MASK", .addr = A_ADDR_ERROR_INT_MASK,
1051
+ .pre_write = can_filter_mask_pre_write,
247
+ .reset = 0x1,
1052
+ },{ .name = "AFIR2", .addr = A_AFIR2,
248
+ .ro = 0x1,
1053
+ .pre_write = can_filter_id_pre_write,
249
+ },{ .name = "ADDR_ERROR_INT_EN", .addr = A_ADDR_ERROR_INT_EN,
1054
+ },{ .name = "AFMR3", .addr = A_AFMR3,
250
+ .pre_write = addr_error_int_en_prew,
1055
+ .pre_write = can_filter_mask_pre_write,
251
+ },{ .name = "ADDR_ERROR_INT_DIS", .addr = A_ADDR_ERROR_INT_DIS,
1056
+ },{ .name = "AFIR3", .addr = A_AFIR3,
252
+ .pre_write = addr_error_int_dis_prew,
1057
+ .pre_write = can_filter_id_pre_write,
253
+ },{ .name = "CONTROL", .addr = A_CONTROL,
1058
+ },{ .name = "AFMR4", .addr = A_AFMR4,
254
+ .reset = 0x1000000,
1059
+ .pre_write = can_filter_mask_pre_write,
255
+ .rsvd = 0x70fffffe,
1060
+ },{ .name = "AFIR4", .addr = A_AFIR4,
256
+ },{ .name = "SAFETY_CHK", .addr = A_SAFETY_CHK,
1061
+ .pre_write = can_filter_id_pre_write,
257
+ }
1062
+ }
258
+};
1063
+};
259
+
1064
+
260
+static void rtc_reset(DeviceState *dev)
1065
+static void xlnx_zynqmp_can_ptimer_cb(void *opaque)
261
+{
1066
+{
262
+ XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(dev);
1067
+ /* No action required on the timer rollover. */
263
+ unsigned int i;
1068
+}
264
+
1069
+
265
+ for (i = 0; i < ARRAY_SIZE(s->regs_info); ++i) {
1070
+static const MemoryRegionOps can_ops = {
266
+ register_reset(&s->regs_info[i]);
267
+ }
268
+
269
+ rtc_int_update_irq(s);
270
+ addr_error_int_update_irq(s);
271
+}
272
+
273
+static const MemoryRegionOps rtc_ops = {
274
+ .read = register_read_memory,
1071
+ .read = register_read_memory,
275
+ .write = register_write_memory,
1072
+ .write = register_write_memory,
276
+ .endianness = DEVICE_LITTLE_ENDIAN,
1073
+ .endianness = DEVICE_LITTLE_ENDIAN,
277
+ .valid = {
1074
+ .valid = {
278
+ .min_access_size = 4,
1075
+ .min_access_size = 4,
279
+ .max_access_size = 4,
1076
+ .max_access_size = 4,
280
+ },
1077
+ },
281
+};
1078
+};
282
+
1079
+
283
+static void rtc_init(Object *obj)
1080
+static void xlnx_zynqmp_can_reset_init(Object *obj, ResetType type)
284
+{
1081
+{
285
+ XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(obj);
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);
286
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
1225
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
1226
+
287
+ RegisterInfoArray *reg_array;
1227
+ RegisterInfoArray *reg_array;
288
+
1228
+
289
+ memory_region_init(&s->iomem, obj, TYPE_XLNX_ZYNQMP_RTC,
1229
+ memory_region_init(&s->iomem, obj, TYPE_XLNX_ZYNQMP_CAN,
290
+ XLNX_ZYNQMP_RTC_R_MAX * 4);
1230
+ XLNX_ZYNQMP_CAN_R_MAX * 4);
291
+ reg_array =
1231
+ reg_array = register_init_block32(DEVICE(obj), can_regs_info,
292
+ register_init_block32(DEVICE(obj), rtc_regs_info,
1232
+ ARRAY_SIZE(can_regs_info),
293
+ ARRAY_SIZE(rtc_regs_info),
1233
+ s->reg_info, s->regs,
294
+ s->regs_info, s->regs,
1234
+ &can_ops,
295
+ &rtc_ops,
1235
+ XLNX_ZYNQMP_CAN_ERR_DEBUG,
296
+ XLNX_ZYNQMP_RTC_ERR_DEBUG,
1236
+ XLNX_ZYNQMP_CAN_R_MAX * 4);
297
+ XLNX_ZYNQMP_RTC_R_MAX * 4);
1237
+
298
+ memory_region_add_subregion(&s->iomem,
1238
+ memory_region_add_subregion(&s->iomem, 0x00, &reg_array->mem);
299
+ 0x0,
300
+ &reg_array->mem);
301
+ sysbus_init_mmio(sbd, &s->iomem);
1239
+ sysbus_init_mmio(sbd, &s->iomem);
302
+ sysbus_init_irq(sbd, &s->irq_rtc_int);
1240
+ sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->irq);
303
+ sysbus_init_irq(sbd, &s->irq_addr_error_int);
1241
+}
304
+}
1242
+
305
+
1243
+static const VMStateDescription vmstate_can = {
306
+static const VMStateDescription vmstate_rtc = {
1244
+ .name = TYPE_XLNX_ZYNQMP_CAN,
307
+ .name = TYPE_XLNX_ZYNQMP_RTC,
308
+ .version_id = 1,
1245
+ .version_id = 1,
309
+ .minimum_version_id = 1,
1246
+ .minimum_version_id = 1,
310
+ .fields = (VMStateField[]) {
1247
+ .fields = (VMStateField[]) {
311
+ VMSTATE_UINT32_ARRAY(regs, XlnxZynqMPRTC, XLNX_ZYNQMP_RTC_R_MAX),
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),
312
+ VMSTATE_END_OF_LIST(),
1253
+ VMSTATE_END_OF_LIST(),
313
+ }
1254
+ }
314
+};
1255
+};
315
+
1256
+
316
+static void rtc_class_init(ObjectClass *klass, void *data)
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)
317
+{
1266
+{
318
+ DeviceClass *dc = DEVICE_CLASS(klass);
1267
+ DeviceClass *dc = DEVICE_CLASS(klass);
319
+
1268
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
320
+ dc->reset = rtc_reset;
1269
+
321
+ dc->vmsd = &vmstate_rtc;
1270
+ rc->phases.enter = xlnx_zynqmp_can_reset_init;
322
+}
1271
+ rc->phases.hold = xlnx_zynqmp_can_reset_hold;
323
+
1272
+ dc->realize = xlnx_zynqmp_can_realize;
324
+static const TypeInfo rtc_info = {
1273
+ device_class_set_props(dc, xlnx_zynqmp_can_properties);
325
+ .name = TYPE_XLNX_ZYNQMP_RTC,
1274
+ dc->vmsd = &vmstate_can;
1275
+}
1276
+
1277
+static const TypeInfo can_info = {
1278
+ .name = TYPE_XLNX_ZYNQMP_CAN,
326
+ .parent = TYPE_SYS_BUS_DEVICE,
1279
+ .parent = TYPE_SYS_BUS_DEVICE,
327
+ .instance_size = sizeof(XlnxZynqMPRTC),
1280
+ .instance_size = sizeof(XlnxZynqMPCANState),
328
+ .class_init = rtc_class_init,
1281
+ .class_init = xlnx_zynqmp_can_class_init,
329
+ .instance_init = rtc_init,
1282
+ .instance_init = xlnx_zynqmp_can_init,
330
+};
1283
+};
331
+
1284
+
332
+static void rtc_register_types(void)
1285
+static void can_register_types(void)
333
+{
1286
+{
334
+ type_register_static(&rtc_info);
1287
+ type_register_static(&can_info);
335
+}
1288
+}
336
+
1289
+
337
+type_init(rtc_register_types)
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'))
338
--
1300
--
339
2.16.2
1301
2.20.1
340
1302
341
1303
diff view generated by jsdifflib
1
From: Alistair Francis <alistair.francis@xilinx.com>
1
From: Vikram Garhwal <fnu.vikram@xilinx.com>
2
2
3
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
3
Connect CAN0 and CAN1 on the ZynqMP.
4
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
4
5
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
5
Reviewed-by: Francisco Iglesias <francisco.iglesias@xilinx.com>
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
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
---
10
---
8
include/hw/arm/xlnx-zynqmp.h | 2 ++
11
include/hw/arm/xlnx-zynqmp.h | 8 ++++++++
9
hw/arm/xlnx-zynqmp.c | 14 ++++++++++++++
12
hw/arm/xlnx-zcu102.c | 20 ++++++++++++++++++++
10
2 files changed, 16 insertions(+)
13
hw/arm/xlnx-zynqmp.c | 34 ++++++++++++++++++++++++++++++++++
14
3 files changed, 62 insertions(+)
11
15
12
diff --git a/include/hw/arm/xlnx-zynqmp.h b/include/hw/arm/xlnx-zynqmp.h
16
diff --git a/include/hw/arm/xlnx-zynqmp.h b/include/hw/arm/xlnx-zynqmp.h
13
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
14
--- a/include/hw/arm/xlnx-zynqmp.h
18
--- a/include/hw/arm/xlnx-zynqmp.h
15
+++ b/include/hw/arm/xlnx-zynqmp.h
19
+++ b/include/hw/arm/xlnx-zynqmp.h
16
@@ -XXX,XX +XXX,XX @@
20
@@ -XXX,XX +XXX,XX @@
17
#include "hw/dma/xlnx_dpdma.h"
21
#include "hw/intc/arm_gic.h"
18
#include "hw/display/xlnx_dp.h"
22
#include "hw/net/cadence_gem.h"
19
#include "hw/intc/xlnx-zynqmp-ipi.h"
23
#include "hw/char/cadence_uart.h"
20
+#include "hw/timer/xlnx-zynqmp-rtc.h"
24
+#include "hw/net/xlnx-zynqmp-can.h"
25
#include "hw/ide/ahci.h"
26
#include "hw/sd/sdhci.h"
27
#include "hw/ssi/xilinx_spips.h"
28
@@ -XXX,XX +XXX,XX @@
29
#include "hw/cpu/cluster.h"
30
#include "target/arm/cpu.h"
31
#include "qom/object.h"
32
+#include "net/can_emu.h"
21
33
22
#define TYPE_XLNX_ZYNQMP "xlnx,zynqmp"
34
#define TYPE_XLNX_ZYNQMP "xlnx,zynqmp"
23
#define XLNX_ZYNQMP(obj) OBJECT_CHECK(XlnxZynqMPState, (obj), \
35
typedef struct XlnxZynqMPState XlnxZynqMPState;
24
@@ -XXX,XX +XXX,XX @@ typedef struct XlnxZynqMPState {
36
@@ -XXX,XX +XXX,XX @@ DECLARE_INSTANCE_CHECKER(XlnxZynqMPState, XLNX_ZYNQMP,
25
XlnxDPState dp;
37
#define XLNX_ZYNQMP_NUM_RPU_CPUS 2
26
XlnxDPDMAState dpdma;
38
#define XLNX_ZYNQMP_NUM_GEMS 4
27
XlnxZynqMPIPI ipi;
39
#define XLNX_ZYNQMP_NUM_UARTS 2
28
+ XlnxZynqMPRTC rtc;
40
+#define XLNX_ZYNQMP_NUM_CAN 2
29
41
+#define XLNX_ZYNQMP_CAN_REF_CLK (24 * 1000 * 1000)
30
char *boot_cpu;
42
#define XLNX_ZYNQMP_NUM_SDHCI 2
31
ARMCPU *boot_cpu_ptr;
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
};
61
62
#endif
63
diff --git a/hw/arm/xlnx-zcu102.c b/hw/arm/xlnx-zcu102.c
64
index XXXXXXX..XXXXXXX 100644
65
--- a/hw/arm/xlnx-zcu102.c
66
+++ b/hw/arm/xlnx-zcu102.c
67
@@ -XXX,XX +XXX,XX @@
68
#include "sysemu/qtest.h"
69
#include "sysemu/device_tree.h"
70
#include "qom/object.h"
71
+#include "net/can_emu.h"
72
73
struct XlnxZCU102 {
74
MachineState parent_obj;
75
@@ -XXX,XX +XXX,XX @@ struct XlnxZCU102 {
76
bool secure;
77
bool virt;
78
79
+ CanBusState *canbus[XLNX_ZYNQMP_NUM_CAN];
80
+
81
struct arm_boot_info binfo;
82
};
83
typedef struct XlnxZCU102 XlnxZCU102;
84
@@ -XXX,XX +XXX,XX @@ static void xlnx_zcu102_init(MachineState *machine)
85
object_property_set_bool(OBJECT(&s->soc), "virtualization", s->virt,
86
&error_fatal);
87
88
+ for (i = 0; i < XLNX_ZYNQMP_NUM_CAN; i++) {
89
+ gchar *bus_name = g_strdup_printf("canbus%d", i);
90
+
91
+ object_property_set_link(OBJECT(&s->soc), bus_name,
92
+ OBJECT(s->canbus[i]), &error_fatal);
93
+ g_free(bus_name);
94
+ }
95
+
96
qdev_realize(DEVICE(&s->soc), NULL, &error_fatal);
97
98
/* Create and plug in the SD cards */
99
@@ -XXX,XX +XXX,XX @@ static void xlnx_zcu102_machine_instance_init(Object *obj)
100
"Set on/off to enable/disable emulating a "
101
"guest CPU which implements the ARM "
102
"Virtualization Extensions");
103
+ object_property_add_link(obj, "xlnx-zcu102.canbus0", TYPE_CAN_BUS,
104
+ (Object **)&s->canbus[0],
105
+ object_property_allow_set_link,
106
+ 0);
107
+
108
+ object_property_add_link(obj, "xlnx-zcu102.canbus1", TYPE_CAN_BUS,
109
+ (Object **)&s->canbus[1],
110
+ object_property_allow_set_link,
111
+ 0);
112
}
113
114
static void xlnx_zcu102_machine_class_init(ObjectClass *oc, void *data)
32
diff --git a/hw/arm/xlnx-zynqmp.c b/hw/arm/xlnx-zynqmp.c
115
diff --git a/hw/arm/xlnx-zynqmp.c b/hw/arm/xlnx-zynqmp.c
33
index XXXXXXX..XXXXXXX 100644
116
index XXXXXXX..XXXXXXX 100644
34
--- a/hw/arm/xlnx-zynqmp.c
117
--- a/hw/arm/xlnx-zynqmp.c
35
+++ b/hw/arm/xlnx-zynqmp.c
118
+++ b/hw/arm/xlnx-zynqmp.c
36
@@ -XXX,XX +XXX,XX @@
119
@@ -XXX,XX +XXX,XX @@ static const int uart_intr[XLNX_ZYNQMP_NUM_UARTS] = {
37
#define IPI_ADDR 0xFF300000
120
21, 22,
38
#define IPI_IRQ 64
121
};
39
122
40
+#define RTC_ADDR 0xffa60000
123
+static const uint64_t can_addr[XLNX_ZYNQMP_NUM_CAN] = {
41
+#define RTC_IRQ 26
124
+ 0xFF060000, 0xFF070000,
125
+};
42
+
126
+
43
#define SDHCI_CAPABILITIES 0x280737ec6481 /* Datasheet: UG1085 (v1.7) */
127
+static const int can_intr[XLNX_ZYNQMP_NUM_CAN] = {
44
128
+ 23, 24,
45
static const uint64_t gem_addr[XLNX_ZYNQMP_NUM_GEMS] = {
129
+};
130
+
131
static const uint64_t sdhci_addr[XLNX_ZYNQMP_NUM_SDHCI] = {
132
0xFF160000, 0xFF170000,
133
};
46
@@ -XXX,XX +XXX,XX @@ static void xlnx_zynqmp_init(Object *obj)
134
@@ -XXX,XX +XXX,XX @@ static void xlnx_zynqmp_init(Object *obj)
47
135
TYPE_CADENCE_UART);
48
object_initialize(&s->ipi, sizeof(s->ipi), TYPE_XLNX_ZYNQMP_IPI);
136
}
49
qdev_set_parent_bus(DEVICE(&s->ipi), sysbus_get_default());
137
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
+ }
50
+
142
+
51
+ object_initialize(&s->rtc, sizeof(s->rtc), TYPE_XLNX_ZYNQMP_RTC);
143
object_initialize_child(obj, "sata", &s->sata, TYPE_SYSBUS_AHCI);
52
+ qdev_set_parent_bus(DEVICE(&s->rtc), sysbus_get_default());
144
53
}
145
for (i = 0; i < XLNX_ZYNQMP_NUM_SDHCI; i++) {
54
55
static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
56
@@ -XXX,XX +XXX,XX @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
146
@@ -XXX,XX +XXX,XX @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
147
gic_spi[uart_intr[i]]);
57
}
148
}
58
sysbus_mmio_map(SYS_BUS_DEVICE(&s->ipi), 0, IPI_ADDR);
149
59
sysbus_connect_irq(SYS_BUS_DEVICE(&s->ipi), 0, gic_spi[IPI_IRQ]);
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);
60
+
153
+
61
+ object_property_set_bool(OBJECT(&s->rtc), true, "realized", &err);
154
+ object_property_set_link(OBJECT(&s->can[i]), "canbus",
62
+ if (err) {
155
+ OBJECT(s->canbus[i]), &error_fatal);
63
+ error_propagate(errp, err);
156
+
64
+ return;
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]]);
65
+ }
165
+ }
66
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->rtc), 0, RTC_ADDR);
166
+
67
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->rtc), 0, gic_spi[RTC_IRQ]);
167
object_property_set_int(OBJECT(&s->sata), "num-ports", SATA_NUM_PORTS,
68
}
168
&error_abort);
69
169
if (!sysbus_realize(SYS_BUS_DEVICE(&s->sata), errp)) {
70
static Property xlnx_zynqmp_props[] = {
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
71
--
181
--
72
2.16.2
182
2.20.1
73
183
74
184
diff view generated by jsdifflib
Deleted patch
1
Add a function load_ramdisk_as() which behaves like the existing
2
load_ramdisk() but allows the caller to specify the AddressSpace
3
to use. This matches the pattern we have already for various
4
other loader functions.
5
1
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Message-id: 20180220180325.29818-2-peter.maydell@linaro.org
10
---
11
include/hw/loader.h | 12 +++++++++++-
12
hw/core/loader.c | 8 +++++++-
13
2 files changed, 18 insertions(+), 2 deletions(-)
14
15
diff --git a/include/hw/loader.h b/include/hw/loader.h
16
index XXXXXXX..XXXXXXX 100644
17
--- a/include/hw/loader.h
18
+++ b/include/hw/loader.h
19
@@ -XXX,XX +XXX,XX @@ int load_uimage(const char *filename, hwaddr *ep,
20
void *translate_opaque);
21
22
/**
23
- * load_ramdisk:
24
+ * load_ramdisk_as:
25
* @filename: Path to the ramdisk image
26
* @addr: Memory address to load the ramdisk to
27
* @max_sz: Maximum allowed ramdisk size (for non-u-boot ramdisks)
28
+ * @as: The AddressSpace to load the ELF to. The value of address_space_memory
29
+ * is used if nothing is supplied here.
30
*
31
* Load a ramdisk image with U-Boot header to the specified memory
32
* address.
33
*
34
* Returns the size of the loaded image on success, -1 otherwise.
35
*/
36
+int load_ramdisk_as(const char *filename, hwaddr addr, uint64_t max_sz,
37
+ AddressSpace *as);
38
+
39
+/**
40
+ * load_ramdisk:
41
+ * Same as load_ramdisk_as(), but doesn't allow the caller to specify
42
+ * an AddressSpace.
43
+ */
44
int load_ramdisk(const char *filename, hwaddr addr, uint64_t max_sz);
45
46
ssize_t gunzip(void *dst, size_t dstlen, uint8_t *src, size_t srclen);
47
diff --git a/hw/core/loader.c b/hw/core/loader.c
48
index XXXXXXX..XXXXXXX 100644
49
--- a/hw/core/loader.c
50
+++ b/hw/core/loader.c
51
@@ -XXX,XX +XXX,XX @@ int load_uimage_as(const char *filename, hwaddr *ep, hwaddr *loadaddr,
52
53
/* Load a ramdisk. */
54
int load_ramdisk(const char *filename, hwaddr addr, uint64_t max_sz)
55
+{
56
+ return load_ramdisk_as(filename, addr, max_sz, NULL);
57
+}
58
+
59
+int load_ramdisk_as(const char *filename, hwaddr addr, uint64_t max_sz,
60
+ AddressSpace *as)
61
{
62
return load_uboot_image(filename, NULL, &addr, NULL, IH_TYPE_RAMDISK,
63
- NULL, NULL, NULL);
64
+ NULL, NULL, as);
65
}
66
67
/* Load a gzip-compressed kernel to a dynamically allocated buffer. */
68
--
69
2.16.2
70
71
diff view generated by jsdifflib
Deleted patch
1
Instead of loading guest images to the system address space, use the
2
CPU's address space. This is important if we're trying to load the
3
file to memory or via an alias memory region that is provided by an
4
SoC object and thus not mapped into the system address space.
5
1
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Message-id: 20180220180325.29818-4-peter.maydell@linaro.org
10
---
11
hw/arm/armv7m.c | 17 ++++++++++++++---
12
1 file changed, 14 insertions(+), 3 deletions(-)
13
14
diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/arm/armv7m.c
17
+++ b/hw/arm/armv7m.c
18
@@ -XXX,XX +XXX,XX @@ void armv7m_load_kernel(ARMCPU *cpu, const char *kernel_filename, int mem_size)
19
uint64_t entry;
20
uint64_t lowaddr;
21
int big_endian;
22
+ AddressSpace *as;
23
+ int asidx;
24
+ CPUState *cs = CPU(cpu);
25
26
#ifdef TARGET_WORDS_BIGENDIAN
27
big_endian = 1;
28
@@ -XXX,XX +XXX,XX @@ void armv7m_load_kernel(ARMCPU *cpu, const char *kernel_filename, int mem_size)
29
exit(1);
30
}
31
32
+ if (arm_feature(&cpu->env, ARM_FEATURE_EL3)) {
33
+ asidx = ARMASIdx_S;
34
+ } else {
35
+ asidx = ARMASIdx_NS;
36
+ }
37
+ as = cpu_get_address_space(cs, asidx);
38
+
39
if (kernel_filename) {
40
- image_size = load_elf(kernel_filename, NULL, NULL, &entry, &lowaddr,
41
- NULL, big_endian, EM_ARM, 1, 0);
42
+ image_size = load_elf_as(kernel_filename, NULL, NULL, &entry, &lowaddr,
43
+ NULL, big_endian, EM_ARM, 1, 0, as);
44
if (image_size < 0) {
45
- image_size = load_image_targphys(kernel_filename, 0, mem_size);
46
+ image_size = load_image_targphys_as(kernel_filename, 0,
47
+ mem_size, as);
48
lowaddr = 0;
49
}
50
if (image_size < 0) {
51
--
52
2.16.2
53
54
diff view generated by jsdifflib
1
In some board or SoC models it is necessary to split a qemu_irq line
1
From: Vikram Garhwal <fnu.vikram@xilinx.com>
2
so that one input can feed multiple outputs. We currently have
2
3
qemu_irq_split() for this, but that has several deficiencies:
3
The QTests perform five tests on the Xilinx ZynqMP CAN controller:
4
* it can only handle splitting a line into two
4
Tests the CAN controller in loopback, sleep and snoop mode.
5
* it unavoidably leaks memory, so it can't be used
5
Tests filtering of incoming CAN messages.
6
in a device that can be deleted
6
7
7
Reviewed-by: Francisco Iglesias <francisco.iglesias@xilinx.com>
8
Implement a qdev device that encapsulates splitting of IRQs, with a
8
Signed-off-by: Vikram Garhwal <fnu.vikram@xilinx.com>
9
configurable number of outputs. (This is in some ways the inverse of
9
Message-id: 1597278668-339715-4-git-send-email-fnu.vikram@xilinx.com
10
the TYPE_OR_IRQ device.)
10
[PMM: updated to meson build system]
11
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
14
Message-id: 20180220180325.29818-13-peter.maydell@linaro.org
15
---
12
---
16
hw/core/Makefile.objs | 1 +
13
tests/qtest/xlnx-can-test.c | 359 ++++++++++++++++++++++++++++++++++++
17
include/hw/core/split-irq.h | 57 +++++++++++++++++++++++++++++
14
tests/qtest/meson.build | 1 +
18
include/hw/irq.h | 4 +-
15
2 files changed, 360 insertions(+)
19
hw/core/split-irq.c | 89 +++++++++++++++++++++++++++++++++++++++++++++
16
create mode 100644 tests/qtest/xlnx-can-test.c
20
4 files changed, 150 insertions(+), 1 deletion(-)
17
21
create mode 100644 include/hw/core/split-irq.h
18
diff --git a/tests/qtest/xlnx-can-test.c b/tests/qtest/xlnx-can-test.c
22
create mode 100644 hw/core/split-irq.c
23
24
diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs
25
index XXXXXXX..XXXXXXX 100644
26
--- a/hw/core/Makefile.objs
27
+++ b/hw/core/Makefile.objs
28
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_FITLOADER) += loader-fit.o
29
common-obj-$(CONFIG_SOFTMMU) += qdev-properties-system.o
30
common-obj-$(CONFIG_SOFTMMU) += register.o
31
common-obj-$(CONFIG_SOFTMMU) += or-irq.o
32
+common-obj-$(CONFIG_SOFTMMU) += split-irq.o
33
common-obj-$(CONFIG_PLATFORM_BUS) += platform-bus.o
34
35
obj-$(CONFIG_SOFTMMU) += generic-loader.o
36
diff --git a/include/hw/core/split-irq.h b/include/hw/core/split-irq.h
37
new file mode 100644
19
new file mode 100644
38
index XXXXXXX..XXXXXXX
20
index XXXXXXX..XXXXXXX
39
--- /dev/null
21
--- /dev/null
40
+++ b/include/hw/core/split-irq.h
22
+++ b/tests/qtest/xlnx-can-test.c
41
@@ -XXX,XX +XXX,XX @@
23
@@ -XXX,XX +XXX,XX @@
42
+/*
24
+/*
43
+ * IRQ splitter device.
25
+ * QTests for the Xilinx ZynqMP CAN controller.
44
+ *
26
+ *
45
+ * Copyright (c) 2018 Linaro Limited.
27
+ * Copyright (c) 2020 Xilinx Inc.
46
+ * Written by Peter Maydell
28
+ *
29
+ * Written-by: Vikram Garhwal<fnu.vikram@xilinx.com>
47
+ *
30
+ *
48
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
31
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
49
+ * of this software and associated documentation files (the "Software"), to deal
32
+ * of this software and associated documentation files (the "Software"), to deal
50
+ * in the Software without restriction, including without limitation the rights
33
+ * in the Software without restriction, including without limitation the rights
51
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
34
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
...
...
62
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
45
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
63
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
46
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
64
+ * THE SOFTWARE.
47
+ * THE SOFTWARE.
65
+ */
48
+ */
66
+
49
+
67
+/* This is a simple device which has one GPIO input line and multiple
50
+#include "qemu/osdep.h"
68
+ * GPIO output lines. Any change on the input line is forwarded to all
51
+#include "libqos/libqtest.h"
69
+ * of the outputs.
52
+
70
+ *
53
+/* Base address. */
71
+ * QEMU interface:
54
+#define CAN0_BASE_ADDR 0xFF060000
72
+ * + one unnamed GPIO input: the input line
55
+#define CAN1_BASE_ADDR 0xFF070000
73
+ * + N unnamed GPIO outputs: the output lines
56
+
74
+ * + QOM property "num-lines": sets the number of output lines
57
+/* Register addresses. */
58
+#define R_SRR_OFFSET 0x00
59
+#define R_MSR_OFFSET 0x04
60
+#define R_SR_OFFSET 0x18
61
+#define R_ISR_OFFSET 0x1C
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.
75
+ */
154
+ */
76
+#ifndef HW_SPLIT_IRQ_H
155
+static void test_can_bus(void)
77
+#define HW_SPLIT_IRQ_H
156
+{
78
+
157
+ uint32_t buf_tx[4] = { 0xFF, 0x80000000, 0x12345678, 0x87654321 };
79
+#include "hw/irq.h"
158
+ uint32_t buf_rx[4] = { 0x00, 0x00, 0x00, 0x00 };
80
+#include "hw/sysbus.h"
159
+ uint32_t status = 0;
81
+#include "qom/object.h"
160
+ uint8_t can_timestamp = 1;
82
+
161
+
83
+#define TYPE_SPLIT_IRQ "split-irq"
162
+ QTestState *qts = qtest_init("-machine xlnx-zcu102"
84
+
163
+ " -object can-bus,id=canbus0"
85
+#define MAX_SPLIT_LINES 16
164
+ " -machine xlnx-zcu102.canbus0=canbus0"
86
+
165
+ " -machine xlnx-zcu102.canbus1=canbus0"
87
+typedef struct SplitIRQ SplitIRQ;
166
+ );
88
+
167
+
89
+#define SPLIT_IRQ(obj) OBJECT_CHECK(SplitIRQ, (obj), TYPE_SPLIT_IRQ)
168
+ /* Configure the CAN0 and CAN1. */
90
+
169
+ qtest_writel(qts, CAN0_BASE_ADDR + R_SRR_OFFSET, ENABLE_CAN);
91
+struct SplitIRQ {
170
+ qtest_writel(qts, CAN0_BASE_ADDR + R_MSR_OFFSET, NORMAL_MODE);
92
+ DeviceState parent_obj;
171
+ qtest_writel(qts, CAN1_BASE_ADDR + R_SRR_OFFSET, ENABLE_CAN);
93
+
172
+ qtest_writel(qts, CAN1_BASE_ADDR + R_MSR_OFFSET, NORMAL_MODE);
94
+ qemu_irq out_irq[MAX_SPLIT_LINES];
173
+
95
+ uint16_t num_lines;
174
+ /* Check here if CAN0 and CAN1 are in normal mode. */
96
+};
175
+ status = qtest_readl(qts, CAN0_BASE_ADDR + R_SR_OFFSET);
97
+
176
+ g_assert_cmpint(status, ==, STATUS_NORMAL_MODE);
98
+#endif
177
+
99
diff --git a/include/hw/irq.h b/include/hw/irq.h
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
100
index XXXXXXX..XXXXXXX 100644
384
index XXXXXXX..XXXXXXX 100644
101
--- a/include/hw/irq.h
385
--- a/tests/qtest/meson.build
102
+++ b/include/hw/irq.h
386
+++ b/tests/qtest/meson.build
103
@@ -XXX,XX +XXX,XX @@ void qemu_free_irq(qemu_irq irq);
387
@@ -XXX,XX +XXX,XX @@ qtests_aarch64 = \
104
/* Returns a new IRQ with opposite polarity. */
388
(config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? ['tpm-tis-device-swtpm-test'] : []) + \
105
qemu_irq qemu_irq_invert(qemu_irq irq);
389
['numa-test',
106
390
'boot-serial-test',
107
-/* Returns a new IRQ which feeds into both the passed IRQs */
391
+ 'xlnx-can-test',
108
+/* Returns a new IRQ which feeds into both the passed IRQs.
392
'migration-test']
109
+ * It's probably better to use the TYPE_SPLIT_IRQ device instead.
393
110
+ */
394
qtests_s390x = \
111
qemu_irq qemu_irq_split(qemu_irq irq1, qemu_irq irq2);
112
113
/* Returns a new IRQ set which connects 1:1 to another IRQ set, which
114
diff --git a/hw/core/split-irq.c b/hw/core/split-irq.c
115
new file mode 100644
116
index XXXXXXX..XXXXXXX
117
--- /dev/null
118
+++ b/hw/core/split-irq.c
119
@@ -XXX,XX +XXX,XX @@
120
+/*
121
+ * IRQ splitter device.
122
+ *
123
+ * Copyright (c) 2018 Linaro Limited.
124
+ * Written by Peter Maydell
125
+ *
126
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
127
+ * of this software and associated documentation files (the "Software"), to deal
128
+ * in the Software without restriction, including without limitation the rights
129
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
130
+ * copies of the Software, and to permit persons to whom the Software is
131
+ * furnished to do so, subject to the following conditions:
132
+ *
133
+ * The above copyright notice and this permission notice shall be included in
134
+ * all copies or substantial portions of the Software.
135
+ *
136
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
137
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
138
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
139
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
140
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
141
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
142
+ * THE SOFTWARE.
143
+ */
144
+
145
+#include "qemu/osdep.h"
146
+#include "hw/core/split-irq.h"
147
+#include "qapi/error.h"
148
+
149
+static void split_irq_handler(void *opaque, int n, int level)
150
+{
151
+ SplitIRQ *s = SPLIT_IRQ(opaque);
152
+ int i;
153
+
154
+ for (i = 0; i < s->num_lines; i++) {
155
+ qemu_set_irq(s->out_irq[i], level);
156
+ }
157
+}
158
+
159
+static void split_irq_init(Object *obj)
160
+{
161
+ qdev_init_gpio_in(DEVICE(obj), split_irq_handler, 1);
162
+}
163
+
164
+static void split_irq_realize(DeviceState *dev, Error **errp)
165
+{
166
+ SplitIRQ *s = SPLIT_IRQ(dev);
167
+
168
+ if (s->num_lines < 1 || s->num_lines >= MAX_SPLIT_LINES) {
169
+ error_setg(errp,
170
+ "IRQ splitter number of lines %d is not between 1 and %d",
171
+ s->num_lines, MAX_SPLIT_LINES);
172
+ return;
173
+ }
174
+
175
+ qdev_init_gpio_out(dev, s->out_irq, s->num_lines);
176
+}
177
+
178
+static Property split_irq_properties[] = {
179
+ DEFINE_PROP_UINT16("num-lines", SplitIRQ, num_lines, 1),
180
+ DEFINE_PROP_END_OF_LIST(),
181
+};
182
+
183
+static void split_irq_class_init(ObjectClass *klass, void *data)
184
+{
185
+ DeviceClass *dc = DEVICE_CLASS(klass);
186
+
187
+ /* No state to reset or migrate */
188
+ dc->props = split_irq_properties;
189
+ dc->realize = split_irq_realize;
190
+
191
+ /* Reason: Needs to be wired up to work */
192
+ dc->user_creatable = false;
193
+}
194
+
195
+static const TypeInfo split_irq_type_info = {
196
+ .name = TYPE_SPLIT_IRQ,
197
+ .parent = TYPE_DEVICE,
198
+ .instance_size = sizeof(SplitIRQ),
199
+ .instance_init = split_irq_init,
200
+ .class_init = split_irq_class_init,
201
+};
202
+
203
+static void split_irq_register_types(void)
204
+{
205
+ type_register_static(&split_irq_type_info);
206
+}
207
+
208
+type_init(split_irq_register_types)
209
--
395
--
210
2.16.2
396
2.20.1
211
397
212
398
diff view generated by jsdifflib
Deleted patch
1
From: Richard Henderson <richard.henderson@linaro.org>
2
1
3
Not enabled anywhere yet.
4
5
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20180228193125.20577-2-richard.henderson@linaro.org
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
11
target/arm/cpu.h | 1 +
12
linux-user/elfload.c | 1 +
13
2 files changed, 2 insertions(+)
14
15
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
16
index XXXXXXX..XXXXXXX 100644
17
--- a/target/arm/cpu.h
18
+++ b/target/arm/cpu.h
19
@@ -XXX,XX +XXX,XX @@ enum arm_features {
20
ARM_FEATURE_V8_SHA3, /* implements SHA3 part of v8 Crypto Extensions */
21
ARM_FEATURE_V8_SM3, /* implements SM3 part of v8 Crypto Extensions */
22
ARM_FEATURE_V8_SM4, /* implements SM4 part of v8 Crypto Extensions */
23
+ ARM_FEATURE_V8_RDM, /* implements v8.1 simd round multiply */
24
ARM_FEATURE_V8_FP16, /* implements v8.2 half-precision float */
25
};
26
27
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
28
index XXXXXXX..XXXXXXX 100644
29
--- a/linux-user/elfload.c
30
+++ b/linux-user/elfload.c
31
@@ -XXX,XX +XXX,XX @@ static uint32_t get_elf_hwcap(void)
32
GET_FEATURE(ARM_FEATURE_V8_SHA512, ARM_HWCAP_A64_SHA512);
33
GET_FEATURE(ARM_FEATURE_V8_FP16,
34
ARM_HWCAP_A64_FPHP | ARM_HWCAP_A64_ASIMDHP);
35
+ GET_FEATURE(ARM_FEATURE_V8_RDM, ARM_HWCAP_A64_ASIMDRDM);
36
#undef GET_FEATURE
37
38
return hwcaps;
39
--
40
2.16.2
41
42
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Vikram Garhwal <fnu.vikram@xilinx.com>
2
2
3
Include the U bit in the switches rather than testing separately.
3
Reviewed-by: Francisco Iglesias <francisco.iglesias@xilinx.com>
4
4
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
Signed-off-by: Vikram Garhwal <fnu.vikram@xilinx.com>
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
6
Message-id: 1597278668-339715-5-git-send-email-fnu.vikram@xilinx.com
7
Message-id: 20180228193125.20577-3-richard.henderson@linaro.org
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
8
---
10
target/arm/translate-a64.c | 129 +++++++++++++++++++++------------------------
9
MAINTAINERS | 8 ++++++++
11
1 file changed, 61 insertions(+), 68 deletions(-)
10
1 file changed, 8 insertions(+)
12
11
13
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
12
diff --git a/MAINTAINERS b/MAINTAINERS
14
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
15
--- a/target/arm/translate-a64.c
14
--- a/MAINTAINERS
16
+++ b/target/arm/translate-a64.c
15
+++ b/MAINTAINERS
17
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
16
@@ -XXX,XX +XXX,XX @@ F: hw/net/opencores_eth.c
18
int index;
17
19
TCGv_ptr fpst;
18
Devices
20
19
-------
21
- switch (opcode) {
20
+Xilinx CAN
22
- case 0x0: /* MLA */
21
+M: Vikram Garhwal <fnu.vikram@xilinx.com>
23
- case 0x4: /* MLS */
22
+M: Francisco Iglesias <francisco.iglesias@xilinx.com>
24
- if (!u || is_scalar) {
23
+S: Maintained
25
+ switch (16 * u + opcode) {
24
+F: hw/net/can/xlnx-*
26
+ case 0x08: /* MUL */
25
+F: include/hw/net/xlnx-*
27
+ case 0x10: /* MLA */
26
+F: tests/qtest/xlnx-can-test*
28
+ case 0x14: /* MLS */
27
+
29
+ if (is_scalar) {
28
EDU
30
unallocated_encoding(s);
29
M: Jiri Slaby <jslaby@suse.cz>
31
return;
30
S: Maintained
32
}
33
break;
34
- case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
35
- case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
36
- case 0xa: /* SMULL, SMULL2, UMULL, UMULL2 */
37
+ case 0x02: /* SMLAL, SMLAL2 */
38
+ case 0x12: /* UMLAL, UMLAL2 */
39
+ case 0x06: /* SMLSL, SMLSL2 */
40
+ case 0x16: /* UMLSL, UMLSL2 */
41
+ case 0x0a: /* SMULL, SMULL2 */
42
+ case 0x1a: /* UMULL, UMULL2 */
43
if (is_scalar) {
44
unallocated_encoding(s);
45
return;
46
}
47
is_long = true;
48
break;
49
- case 0x3: /* SQDMLAL, SQDMLAL2 */
50
- case 0x7: /* SQDMLSL, SQDMLSL2 */
51
- case 0xb: /* SQDMULL, SQDMULL2 */
52
+ case 0x03: /* SQDMLAL, SQDMLAL2 */
53
+ case 0x07: /* SQDMLSL, SQDMLSL2 */
54
+ case 0x0b: /* SQDMULL, SQDMULL2 */
55
is_long = true;
56
- /* fall through */
57
- case 0xc: /* SQDMULH */
58
- case 0xd: /* SQRDMULH */
59
- if (u) {
60
- unallocated_encoding(s);
61
- return;
62
- }
63
break;
64
- case 0x8: /* MUL */
65
- if (u || is_scalar) {
66
- unallocated_encoding(s);
67
- return;
68
- }
69
+ case 0x0c: /* SQDMULH */
70
+ case 0x0d: /* SQRDMULH */
71
break;
72
- case 0x1: /* FMLA */
73
- case 0x5: /* FMLS */
74
- if (u) {
75
- unallocated_encoding(s);
76
- return;
77
- }
78
- /* fall through */
79
- case 0x9: /* FMUL, FMULX */
80
+ case 0x01: /* FMLA */
81
+ case 0x05: /* FMLS */
82
+ case 0x09: /* FMUL */
83
+ case 0x19: /* FMULX */
84
if (size == 1) {
85
unallocated_encoding(s);
86
return;
87
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
88
89
read_vec_element(s, tcg_op, rn, pass, MO_64);
90
91
- switch (opcode) {
92
- case 0x5: /* FMLS */
93
+ switch (16 * u + opcode) {
94
+ case 0x05: /* FMLS */
95
/* As usual for ARM, separate negation for fused multiply-add */
96
gen_helper_vfp_negd(tcg_op, tcg_op);
97
/* fall through */
98
- case 0x1: /* FMLA */
99
+ case 0x01: /* FMLA */
100
read_vec_element(s, tcg_res, rd, pass, MO_64);
101
gen_helper_vfp_muladdd(tcg_res, tcg_op, tcg_idx, tcg_res, fpst);
102
break;
103
- case 0x9: /* FMUL, FMULX */
104
- if (u) {
105
- gen_helper_vfp_mulxd(tcg_res, tcg_op, tcg_idx, fpst);
106
- } else {
107
- gen_helper_vfp_muld(tcg_res, tcg_op, tcg_idx, fpst);
108
- }
109
+ case 0x09: /* FMUL */
110
+ gen_helper_vfp_muld(tcg_res, tcg_op, tcg_idx, fpst);
111
+ break;
112
+ case 0x19: /* FMULX */
113
+ gen_helper_vfp_mulxd(tcg_res, tcg_op, tcg_idx, fpst);
114
break;
115
default:
116
g_assert_not_reached();
117
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
118
119
read_vec_element_i32(s, tcg_op, rn, pass, is_scalar ? size : MO_32);
120
121
- switch (opcode) {
122
- case 0x0: /* MLA */
123
- case 0x4: /* MLS */
124
- case 0x8: /* MUL */
125
+ switch (16 * u + opcode) {
126
+ case 0x08: /* MUL */
127
+ case 0x10: /* MLA */
128
+ case 0x14: /* MLS */
129
{
130
static NeonGenTwoOpFn * const fns[2][2] = {
131
{ gen_helper_neon_add_u16, gen_helper_neon_sub_u16 },
132
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
133
genfn(tcg_res, tcg_op, tcg_res);
134
break;
135
}
136
- case 0x5: /* FMLS */
137
- case 0x1: /* FMLA */
138
+ case 0x05: /* FMLS */
139
+ case 0x01: /* FMLA */
140
read_vec_element_i32(s, tcg_res, rd, pass,
141
is_scalar ? size : MO_32);
142
switch (size) {
143
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
144
g_assert_not_reached();
145
}
146
break;
147
- case 0x9: /* FMUL, FMULX */
148
+ case 0x09: /* FMUL */
149
switch (size) {
150
case 1:
151
- if (u) {
152
- if (is_scalar) {
153
- gen_helper_advsimd_mulxh(tcg_res, tcg_op,
154
- tcg_idx, fpst);
155
- } else {
156
- gen_helper_advsimd_mulx2h(tcg_res, tcg_op,
157
- tcg_idx, fpst);
158
- }
159
+ if (is_scalar) {
160
+ gen_helper_advsimd_mulh(tcg_res, tcg_op,
161
+ tcg_idx, fpst);
162
} else {
163
- if (is_scalar) {
164
- gen_helper_advsimd_mulh(tcg_res, tcg_op,
165
- tcg_idx, fpst);
166
- } else {
167
- gen_helper_advsimd_mul2h(tcg_res, tcg_op,
168
- tcg_idx, fpst);
169
- }
170
+ gen_helper_advsimd_mul2h(tcg_res, tcg_op,
171
+ tcg_idx, fpst);
172
}
173
break;
174
case 2:
175
- if (u) {
176
- gen_helper_vfp_mulxs(tcg_res, tcg_op, tcg_idx, fpst);
177
- } else {
178
- gen_helper_vfp_muls(tcg_res, tcg_op, tcg_idx, fpst);
179
- }
180
+ gen_helper_vfp_muls(tcg_res, tcg_op, tcg_idx, fpst);
181
break;
182
default:
183
g_assert_not_reached();
184
}
185
break;
186
- case 0xc: /* SQDMULH */
187
+ case 0x19: /* FMULX */
188
+ switch (size) {
189
+ case 1:
190
+ if (is_scalar) {
191
+ gen_helper_advsimd_mulxh(tcg_res, tcg_op,
192
+ tcg_idx, fpst);
193
+ } else {
194
+ gen_helper_advsimd_mulx2h(tcg_res, tcg_op,
195
+ tcg_idx, fpst);
196
+ }
197
+ break;
198
+ case 2:
199
+ gen_helper_vfp_mulxs(tcg_res, tcg_op, tcg_idx, fpst);
200
+ break;
201
+ default:
202
+ g_assert_not_reached();
203
+ }
204
+ break;
205
+ case 0x0c: /* SQDMULH */
206
if (size == 1) {
207
gen_helper_neon_qdmulh_s16(tcg_res, cpu_env,
208
tcg_op, tcg_idx);
209
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
210
tcg_op, tcg_idx);
211
}
212
break;
213
- case 0xd: /* SQRDMULH */
214
+ case 0x0d: /* SQRDMULH */
215
if (size == 1) {
216
gen_helper_neon_qrdmulh_s16(tcg_res, cpu_env,
217
tcg_op, tcg_idx);
218
--
31
--
219
2.16.2
32
2.20.1
220
33
221
34
diff view generated by jsdifflib