1
Nuvoton new board models, and some more minor stuff. I also put
1
First pullreq for 6.0: mostly my v8.1M work, plus some other
2
in the deprecation patches for unicore32 and lm32.
2
bits and pieces. (I still have a lot of stuff in my to-review
3
folder, which I may or may not get to before the Christmas break...)
3
4
4
thanks
5
thanks
5
-- PMM
6
-- PMM
6
7
7
The following changes since commit a68694cd1f3e5448cca814ff39b871f9ebd71ed5:
8
The following changes since commit 5e7b204dbfae9a562fc73684986f936b97f63877:
8
9
9
Merge remote-tracking branch 'remotes/philmd-gitlab/tags/edk2-next-20200914' into staging (2020-09-14 12:18:58 +0100)
10
Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging (2020-12-09 20:08:54 +0000)
10
11
11
are available in the Git repository at:
12
are available in the Git repository at:
12
13
13
https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20200914
14
https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20201210
14
15
15
for you to fetch changes up to dd44ae00fc5342ed99acb68ec3508f76a71d523a:
16
for you to fetch changes up to 71f916be1c7e9ede0e37d9cabc781b5a9e8638ff:
16
17
17
MAINTAINERS: Add maintainer entry for Xilinx ZynqMP CAN controller (2020-09-14 14:27:08 +0100)
18
hw/arm/armv7m: Correct typo in QOM object name (2020-12-10 11:44:56 +0000)
18
19
19
----------------------------------------------------------------
20
----------------------------------------------------------------
20
target-arm queue:
21
target-arm queue:
21
* hw/misc/a9scu: Do not allow invalid CPU count
22
* hw/arm/smmuv3: Fix up L1STD_SPAN decoding
22
* hw/misc/a9scu: Minor cleanups
23
* xlnx-zynqmp: Support Xilinx ZynqMP CAN controllers
23
* hw/timer/armv7m_systick: assert that board code set system_clock_scale
24
* sbsa-ref: allow to use Cortex-A53/57/72 cpus
24
* decodetree: Improve identifier matching
25
* Various minor code cleanups
25
* target/arm: Clean up neon fp insn size field decode
26
* hw/intc/armv7m_nvic: Make all of system PPB range be RAZWI/BusFault
26
* target/arm: Remove KVM support for 32-bit Arm hosts
27
* Implement more pieces of ARMv8.1M support
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
34
28
35
----------------------------------------------------------------
29
----------------------------------------------------------------
36
Aaron Lindsay (1):
30
Alex Chen (4):
37
target/arm: Count PMU events when MDCR.SPME is set
31
i.MX25: Fix bad printf format specifiers
32
i.MX31: Fix bad printf format specifiers
33
i.MX6: Fix bad printf format specifiers
34
i.MX6ul: Fix bad printf format specifiers
38
35
39
Edgar E. Iglesias (1):
36
Havard Skinnemoen (1):
40
hw/arm: versal-virt: Correct the tx/rx GEM clocks
37
tests/qtest/npcm7xx_rng-test: dump random data on failure
41
38
42
Havard Skinnemoen (14):
39
Kunkun Jiang (1):
43
hw/misc: Add NPCM7xx System Global Control Registers device model
40
hw/arm/smmuv3: Fix up L1STD_SPAN decoding
44
hw/misc: Add NPCM7xx Clock Controller device model
45
hw/timer: Add NPCM7xx Timer device model
46
hw/arm: Add NPCM730 and NPCM750 SoC models
47
hw/arm: Add two NPCM7xx-based machines
48
roms: Add virtual Boot ROM for NPCM7xx SoCs
49
hw/arm: Load -bios image as a boot ROM for npcm7xx
50
hw/nvram: NPCM7xx OTP device model
51
hw/mem: Stubbed out NPCM7xx Memory Controller model
52
hw/ssi: NPCM7xx Flash Interface Unit device model
53
hw/arm: Wire up BMC boot flash for npcm750-evb and quanta-gsj
54
hw/arm/npcm7xx: add board setup stub for CPU and UART clocks
55
docs/system: Add Nuvoton machine documentation
56
tests/acceptance: console boot tests for quanta-gsj
57
41
58
Peter Maydell (11):
42
Marcin Juszkiewicz (1):
59
hw/timer/armv7m_systick: assert that board code set system_clock_scale
43
sbsa-ref: allow to use Cortex-A53/57/72 cpus
60
target/arm: Convert Neon 3-same-fp size field to MO_* in decode
61
target/arm: Convert Neon VCVT fp size field to MO_* in decode
62
target/arm: Convert VCMLA, VCADD size field to MO_* in decode
63
target/arm: Remove KVM support for 32-bit Arm hosts
64
target/arm: Remove no-longer-reachable 32-bit KVM code
65
hw/arm/mps2: New board model mps2-an386
66
hw/arm/mps2: New board model mps2-an500
67
docs/system/arm/mps2.rst: Make board list consistent
68
Deprecate Unicore32 port
69
Deprecate lm32 port
70
44
71
Philippe Mathieu-Daudé (4):
45
Peter Maydell (25):
72
hw/misc/a9scu: Do not allow invalid CPU count
46
hw/intc/armv7m_nvic: Make all of system PPB range be RAZWI/BusFault
73
hw/misc/a9scu: Simplify setting MemoryRegionOps::valid fields
47
target/arm: Implement v8.1M PXN extension
74
hw/misc/a9scu: Simplify setting MemoryRegionOps::impl fields
48
target/arm: Don't clobber ID_PFR1.Security on M-profile cores
75
hw/misc/a9scu: Report unimplemented accesses with qemu_log_mask(UNIMP)
49
target/arm: Implement VSCCLRM insn
76
50
target/arm: Implement CLRM instruction
77
Richard Henderson (1):
51
target/arm: Enforce M-profile VMRS/VMSR register restrictions
78
decodetree: Improve identifier matching
52
target/arm: Refactor M-profile VMSR/VMRS handling
53
target/arm: Move general-use constant expanders up in translate.c
54
target/arm: Implement VLDR/VSTR system register
55
target/arm: Implement M-profile FPSCR_nzcvqc
56
target/arm: Use new FPCR_NZCV_MASK constant
57
target/arm: Factor out preserve-fp-state from full_vfp_access_check()
58
target/arm: Implement FPCXT_S fp system register
59
hw/intc/armv7m_nvic: Update FPDSCR masking for v8.1M
60
target/arm: For v8.1M, always clear R0-R3, R12, APSR, EPSR on exception entry
61
target/arm: In v8.1M, don't set HFSR.FORCED on vector table fetch failures
62
target/arm: Implement v8.1M REVIDR register
63
target/arm: Implement new v8.1M NOCP check for exception return
64
target/arm: Implement new v8.1M VLLDM and VLSTM encodings
65
hw/intc/armv7m_nvic: Support v8.1M CCR.TRD bit
66
target/arm: Implement CCR_S.TRD behaviour for SG insns
67
hw/intc/armv7m_nvic: Fix "return from inactive handler" check
68
target/arm: Implement M-profile "minimal RAS implementation"
69
hw/intc/armv7m_nvic: Implement read/write for RAS register block
70
hw/arm/armv7m: Correct typo in QOM object name
79
71
80
Vikram Garhwal (4):
72
Vikram Garhwal (4):
81
hw/net/can: Introduce Xilinx ZynqMP CAN controller
73
hw/net/can: Introduce Xilinx ZynqMP CAN controller
82
xlnx-zynqmp: Connect Xilinx ZynqMP CAN controllers
74
xlnx-zynqmp: Connect Xilinx ZynqMP CAN controllers
83
tests/qtest: Introduce tests for Xilinx ZynqMP CAN controller
75
tests/qtest: Introduce tests for Xilinx ZynqMP CAN controller
84
MAINTAINERS: Add maintainer entry for Xilinx ZynqMP CAN controller
76
MAINTAINERS: Add maintainer entry for Xilinx ZynqMP CAN controller
85
77
86
docs/system/arm/mps2.rst | 20 +-
78
meson.build | 1 +
87
docs/system/arm/nuvoton.rst | 92 +++
79
hw/arm/smmuv3-internal.h | 2 +-
88
docs/system/deprecated.rst | 32 +-
80
hw/net/can/trace.h | 1 +
89
docs/system/target-arm.rst | 1 +
81
include/hw/arm/xlnx-zynqmp.h | 8 +
90
configure | 2 +-
82
include/hw/intc/armv7m_nvic.h | 2 +
91
default-configs/arm-softmmu.mak | 1 +
83
include/hw/net/xlnx-zynqmp-can.h | 78 +++
92
include/hw/arm/npcm7xx.h | 112 +++
84
target/arm/cpu.h | 46 ++
93
include/hw/arm/xlnx-zynqmp.h | 8 +
85
target/arm/m-nocp.decode | 10 +-
94
include/hw/mem/npcm7xx_mc.h | 36 +
86
target/arm/t32.decode | 10 +-
95
include/hw/misc/npcm7xx_clk.h | 48 ++
87
target/arm/vfp.decode | 14 +
96
include/hw/misc/npcm7xx_gcr.h | 43 ++
88
hw/arm/armv7m.c | 4 +-
97
include/hw/net/xlnx-zynqmp-can.h | 78 +++
89
hw/arm/sbsa-ref.c | 23 +-
98
include/hw/nvram/npcm7xx_otp.h | 79 +++
90
hw/arm/xlnx-zcu102.c | 20 +
99
include/hw/ssi/npcm7xx_fiu.h | 73 ++
91
hw/arm/xlnx-zynqmp.c | 34 ++
100
include/hw/timer/npcm7xx_timer.h | 78 +++
92
hw/intc/armv7m_nvic.c | 246 ++++++--
101
target/arm/kvm-consts.h | 7 -
93
hw/misc/imx25_ccm.c | 12 +-
102
target/arm/kvm_arm.h | 6 -
94
hw/misc/imx31_ccm.c | 14 +-
103
target/arm/neon-dp.decode | 18 +-
95
hw/misc/imx6_ccm.c | 20 +-
104
target/arm/neon-shared.decode | 18 +-
96
hw/misc/imx6_src.c | 2 +-
105
tests/decode/succ_ident1.decode | 7 +
97
hw/misc/imx6ul_ccm.c | 4 +-
106
hw/arm/mps2.c | 97 ++-
98
hw/misc/imx_ccm.c | 4 +-
107
hw/arm/npcm7xx.c | 532 +++++++++++++++
99
hw/net/can/xlnx-zynqmp-can.c | 1161 ++++++++++++++++++++++++++++++++++++++
108
hw/arm/npcm7xx_boards.c | 197 ++++++
100
target/arm/cpu.c | 5 +-
109
hw/arm/xlnx-versal-virt.c | 2 +-
101
target/arm/helper.c | 7 +-
110
hw/arm/xlnx-zcu102.c | 20 +
102
target/arm/m_helper.c | 130 ++++-
111
hw/arm/xlnx-zynqmp.c | 34 +
103
target/arm/translate.c | 105 +++-
112
hw/mem/npcm7xx_mc.c | 84 +++
104
tests/qtest/npcm7xx_rng-test.c | 12 +
113
hw/misc/a9scu.c | 59 +-
105
tests/qtest/xlnx-can-test.c | 360 ++++++++++++
114
hw/misc/npcm7xx_clk.c | 266 ++++++++
106
MAINTAINERS | 8 +
115
hw/misc/npcm7xx_gcr.c | 269 ++++++++
107
hw/Kconfig | 1 +
116
hw/net/can/xlnx-zynqmp-can.c | 1165 ++++++++++++++++++++++++++++++++
108
hw/net/can/meson.build | 1 +
117
hw/nvram/npcm7xx_otp.c | 440 ++++++++++++
109
hw/net/can/trace-events | 9 +
118
hw/ssi/npcm7xx_fiu.c | 572 ++++++++++++++++
110
target/arm/translate-vfp.c.inc | 511 ++++++++++++++++-
119
hw/timer/armv7m_systick.c | 8 +
111
tests/qtest/meson.build | 1 +
120
hw/timer/npcm7xx_timer.c | 543 +++++++++++++++
112
34 files changed, 2713 insertions(+), 153 deletions(-)
121
target/arm/cpu.c | 101 ++-
113
create mode 100644 hw/net/can/trace.h
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
114
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
115
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
116
create mode 100644 tests/qtest/xlnx-can-test.c
171
create mode 100644 pc-bios/npcm7xx_bootrom.bin
117
create mode 100644 hw/net/can/trace-events
172
create mode 160000 roms/vbootrom
173
118
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Kunkun Jiang <jiangkunkun@huawei.com>
2
2
3
Per the datasheet (DDI0407 r2p0):
3
Accroding to the SMMUv3 spec, the SPAN field of Level1 Stream Table
4
Descriptor is 5 bits([4:0]).
4
5
5
"The SCU connects one to four Cortex-A9 processors to
6
Fixes: 9bde7f0674f(hw/arm/smmuv3: Implement translate callback)
6
the memory system through the AXI interfaces."
7
Signed-off-by: Kunkun Jiang <jiangkunkun@huawei.com>
7
8
Message-id: 20201124023711.1184-1-jiangkunkun@huawei.com
8
Change the instance_init() handler to a device_realize()
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
one so we can verify the property is in range, and return
10
Acked-by: Eric Auger <eric.auger@redhat.com>
10
an error to the caller if not.
11
12
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
13
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
14
Message-id: 20200901144100.116742-2-f4bug@amsat.org
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
---
12
---
17
hw/misc/a9scu.c | 18 +++++++++++++-----
13
hw/arm/smmuv3-internal.h | 2 +-
18
1 file changed, 13 insertions(+), 5 deletions(-)
14
1 file changed, 1 insertion(+), 1 deletion(-)
19
15
20
diff --git a/hw/misc/a9scu.c b/hw/misc/a9scu.c
16
diff --git a/hw/arm/smmuv3-internal.h b/hw/arm/smmuv3-internal.h
21
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
22
--- a/hw/misc/a9scu.c
18
--- a/hw/arm/smmuv3-internal.h
23
+++ b/hw/misc/a9scu.c
19
+++ b/hw/arm/smmuv3-internal.h
24
@@ -XXX,XX +XXX,XX @@
20
@@ -XXX,XX +XXX,XX @@ static inline uint64_t l1std_l2ptr(STEDesc *desc)
25
#include "hw/misc/a9scu.h"
21
return hi << 32 | lo;
26
#include "hw/qdev-properties.h"
27
#include "migration/vmstate.h"
28
+#include "qapi/error.h"
29
#include "qemu/module.h"
30
31
+#define A9_SCU_CPU_MAX 4
32
+
33
static uint64_t a9_scu_read(void *opaque, hwaddr offset,
34
unsigned size)
35
{
36
@@ -XXX,XX +XXX,XX @@ static void a9_scu_reset(DeviceState *dev)
37
s->control = 0;
38
}
22
}
39
23
40
-static void a9_scu_init(Object *obj)
24
-#define L1STD_SPAN(stm) (extract32((stm)->word[0], 0, 4))
41
+static void a9_scu_realize(DeviceState *dev, Error **errp)
25
+#define L1STD_SPAN(stm) (extract32((stm)->word[0], 0, 5))
42
{
26
43
- A9SCUState *s = A9_SCU(obj);
27
#endif
44
- SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
45
+ A9SCUState *s = A9_SCU(dev);
46
+ SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
47
48
- memory_region_init_io(&s->iomem, obj, &a9_scu_ops, s,
49
+ if (!s->num_cpu || s->num_cpu > A9_SCU_CPU_MAX) {
50
+ error_setg(errp, "Illegal CPU count: %u", s->num_cpu);
51
+ return;
52
+ }
53
+
54
+ memory_region_init_io(&s->iomem, OBJECT(s), &a9_scu_ops, s,
55
"a9-scu", 0x100);
56
sysbus_init_mmio(sbd, &s->iomem);
57
}
58
@@ -XXX,XX +XXX,XX @@ static void a9_scu_class_init(ObjectClass *klass, void *data)
59
device_class_set_props(dc, a9_scu_properties);
60
dc->vmsd = &vmstate_a9_scu;
61
dc->reset = a9_scu_reset;
62
+ dc->realize = a9_scu_realize;
63
}
64
65
static const TypeInfo a9_scu_info = {
66
.name = TYPE_A9_SCU,
67
.parent = TYPE_SYS_BUS_DEVICE,
68
.instance_size = sizeof(A9SCUState),
69
- .instance_init = a9_scu_init,
70
.class_init = a9_scu_class_init,
71
};
72
73
--
28
--
74
2.20.1
29
2.20.1
75
30
76
31
diff view generated by jsdifflib
...
...
18
18
19
To create virtual CAN on the host machine, please check the QEMU CAN docs:
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
20
https://github.com/qemu/qemu/blob/master/docs/can.txt
21
21
22
Signed-off-by: Vikram Garhwal <fnu.vikram@xilinx.com>
22
Signed-off-by: Vikram Garhwal <fnu.vikram@xilinx.com>
23
Reviewed-by: Francisco Iglesias <francisco.iglesias@xilinx.com>
23
Message-id: 1605728926-352690-2-git-send-email-fnu.vikram@xilinx.com
24
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
24
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
25
Message-id: 1597278668-339715-2-git-send-email-fnu.vikram@xilinx.com
26
[PMM: updated to meson build system]
27
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
25
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
28
---
26
---
27
meson.build | 1 +
28
hw/net/can/trace.h | 1 +
29
include/hw/net/xlnx-zynqmp-can.h | 78 ++
29
include/hw/net/xlnx-zynqmp-can.h | 78 ++
30
hw/net/can/xlnx-zynqmp-can.c | 1165 ++++++++++++++++++++++++++++++
30
hw/net/can/xlnx-zynqmp-can.c | 1161 ++++++++++++++++++++++++++++++
31
hw/Kconfig | 1 +
31
hw/net/can/meson.build | 1 +
32
hw/net/can/meson.build | 1 +
32
3 files changed, 1244 insertions(+)
33
hw/net/can/trace-events | 9 +
34
7 files changed, 1252 insertions(+)
35
create mode 100644 hw/net/can/trace.h
33
create mode 100644 include/hw/net/xlnx-zynqmp-can.h
36
create mode 100644 include/hw/net/xlnx-zynqmp-can.h
34
create mode 100644 hw/net/can/xlnx-zynqmp-can.c
37
create mode 100644 hw/net/can/xlnx-zynqmp-can.c
38
create mode 100644 hw/net/can/trace-events
35
39
40
diff --git a/meson.build b/meson.build
41
index XXXXXXX..XXXXXXX 100644
42
--- a/meson.build
43
+++ b/meson.build
44
@@ -XXX,XX +XXX,XX @@ if have_system
45
'hw/misc',
46
'hw/misc/macio',
47
'hw/net',
48
+ 'hw/net/can',
49
'hw/nvram',
50
'hw/pci',
51
'hw/pci-host',
52
diff --git a/hw/net/can/trace.h b/hw/net/can/trace.h
53
new file mode 100644
54
index XXXXXXX..XXXXXXX
55
--- /dev/null
56
+++ b/hw/net/can/trace.h
57
@@ -0,0 +1 @@
58
+#include "trace/trace-hw_net_can.h"
36
diff --git a/include/hw/net/xlnx-zynqmp-can.h b/include/hw/net/xlnx-zynqmp-can.h
59
diff --git a/include/hw/net/xlnx-zynqmp-can.h b/include/hw/net/xlnx-zynqmp-can.h
37
new file mode 100644
60
new file mode 100644
38
index XXXXXXX..XXXXXXX
61
index XXXXXXX..XXXXXXX
39
--- /dev/null
62
--- /dev/null
40
+++ b/include/hw/net/xlnx-zynqmp-can.h
63
+++ b/include/hw/net/xlnx-zynqmp-can.h
...
...
168
+#include "net/can_emu.h"
191
+#include "net/can_emu.h"
169
+#include "net/can_host.h"
192
+#include "net/can_host.h"
170
+#include "qemu/event_notifier.h"
193
+#include "qemu/event_notifier.h"
171
+#include "qom/object_interfaces.h"
194
+#include "qom/object_interfaces.h"
172
+#include "hw/net/xlnx-zynqmp-can.h"
195
+#include "hw/net/xlnx-zynqmp-can.h"
196
+#include "trace.h"
173
+
197
+
174
+#ifndef XLNX_ZYNQMP_CAN_ERR_DEBUG
198
+#ifndef XLNX_ZYNQMP_CAN_ERR_DEBUG
175
+#define XLNX_ZYNQMP_CAN_ERR_DEBUG 0
199
+#define XLNX_ZYNQMP_CAN_ERR_DEBUG 0
176
+#endif
200
+#endif
177
+
178
+#define DB_PRINT(dev, ...) do { \
179
+ if (XLNX_ZYNQMP_CAN_ERR_DEBUG) { \
180
+ g_autofree char *path = object_get_canonical_path(OBJECT(dev)); \
181
+ qemu_log("%s: %s", path, ## __VA_ARGS__); \
182
+ } \
183
+} while (0)
184
+
201
+
185
+#define MAX_DLC 8
202
+#define MAX_DLC 8
186
+#undef ERROR
203
+#undef ERROR
187
+
204
+
188
+REG32(SOFTWARE_RESET_REGISTER, 0x0)
205
+REG32(SOFTWARE_RESET_REGISTER, 0x0)
...
...
416
+ }
433
+ }
417
+
434
+
418
+ irq = s->regs[R_INTERRUPT_STATUS_REGISTER];
435
+ irq = s->regs[R_INTERRUPT_STATUS_REGISTER];
419
+ irq &= s->regs[R_INTERRUPT_ENABLE_REGISTER];
436
+ irq &= s->regs[R_INTERRUPT_ENABLE_REGISTER];
420
+
437
+
438
+ trace_xlnx_can_update_irq(s->regs[R_INTERRUPT_STATUS_REGISTER],
439
+ s->regs[R_INTERRUPT_ENABLE_REGISTER], irq);
421
+ qemu_set_irq(s->irq, irq);
440
+ qemu_set_irq(s->irq, irq);
422
+}
441
+}
423
+
442
+
424
+static void can_ier_post_write(RegisterInfo *reg, uint64_t val64)
443
+static void can_ier_post_write(RegisterInfo *reg, uint64_t val)
425
+{
444
+{
426
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
445
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
427
+
446
+
428
+ can_update_irq(s);
447
+ can_update_irq(s);
429
+}
448
+}
430
+
449
+
431
+static uint64_t can_icr_pre_write(RegisterInfo *reg, uint64_t val64)
450
+static uint64_t can_icr_pre_write(RegisterInfo *reg, uint64_t val)
432
+{
451
+{
433
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
452
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
434
+ uint32_t val = val64;
435
+
453
+
436
+ s->regs[R_INTERRUPT_STATUS_REGISTER] &= ~val;
454
+ s->regs[R_INTERRUPT_STATUS_REGISTER] &= ~val;
437
+ can_update_irq(s);
455
+ can_update_irq(s);
438
+
456
+
439
+ return 0;
457
+ return 0;
...
...
570
+ qemu_can_frame frame;
588
+ qemu_can_frame frame;
571
+ uint32_t data[CAN_FRAME_SIZE];
589
+ uint32_t data[CAN_FRAME_SIZE];
572
+ int i;
590
+ int i;
573
+ bool can_tx = tx_ready_check(s);
591
+ bool can_tx = tx_ready_check(s);
574
+
592
+
575
+ if (can_tx) {
593
+ if (!can_tx) {
576
+ while (!fifo32_is_empty(fifo)) {
594
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
577
+ for (i = 0; i < CAN_FRAME_SIZE; i++) {
595
+
578
+ data[i] = fifo32_pop(fifo);
596
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Controller is not enabled for data"
597
+ " transfer.\n", path);
598
+ can_update_irq(s);
599
+ return;
600
+ }
601
+
602
+ while (!fifo32_is_empty(fifo)) {
603
+ for (i = 0; i < CAN_FRAME_SIZE; i++) {
604
+ data[i] = fifo32_pop(fifo);
605
+ }
606
+
607
+ if (ARRAY_FIELD_EX32(s->regs, STATUS_REGISTER, LBACK)) {
608
+ /*
609
+ * Controller is in loopback. In Loopback mode, the CAN core
610
+ * transmits a recessive bitstream on to the XlnxZynqMPCAN Bus.
611
+ * Any message transmitted is looped back to the RX line and
612
+ * acknowledged. The XlnxZynqMPCAN core receives any message
613
+ * that it transmits.
614
+ */
615
+ if (fifo32_is_full(&s->rx_fifo)) {
616
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, RXOFLW, 1);
617
+ } else {
618
+ for (i = 0; i < CAN_FRAME_SIZE; i++) {
619
+ fifo32_push(&s->rx_fifo, data[i]);
620
+ }
621
+
622
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, RXOK, 1);
579
+ }
623
+ }
580
+
624
+ } else {
581
+ if (ARRAY_FIELD_EX32(s->regs, STATUS_REGISTER, LBACK)) {
625
+ /* Normal mode Tx. */
582
+ /*
626
+ generate_frame(&frame, data);
583
+ * Controller is in loopback. In Loopback mode, the CAN core
627
+
584
+ * transmits a recessive bitstream on to the XlnxZynqMPCAN Bus.
628
+ trace_xlnx_can_tx_data(frame.can_id, frame.can_dlc,
585
+ * Any message transmitted is looped back to the RX line and
629
+ frame.data[0], frame.data[1],
586
+ * acknowledged. The XlnxZynqMPCAN core receives any message
630
+ frame.data[2], frame.data[3],
587
+ * that it transmits.
631
+ frame.data[4], frame.data[5],
588
+ */
632
+ frame.data[6], frame.data[7]);
589
+ if (fifo32_is_full(&s->rx_fifo)) {
633
+ can_bus_client_send(&s->bus_client, &frame, 1);
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
+ }
634
+ }
610
+
635
+ }
611
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, TXOK, 1);
636
+
612
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, TXBFLL, 0);
637
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, TXOK, 1);
613
+
638
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, TXBFLL, 0);
614
+ if (ARRAY_FIELD_EX32(s->regs, STATUS_REGISTER, SLEEP)) {
639
+
615
+ can_exit_sleep_mode(s);
640
+ if (ARRAY_FIELD_EX32(s->regs, STATUS_REGISTER, SLEEP)) {
616
+ }
641
+ can_exit_sleep_mode(s);
617
+ } else {
618
+ DB_PRINT(s, "Not enabled for data transfer.\n");
619
+ }
642
+ }
620
+
643
+
621
+ can_update_irq(s);
644
+ can_update_irq(s);
622
+}
645
+}
623
+
646
+
624
+static uint64_t can_srr_pre_write(RegisterInfo *reg, uint64_t val64)
647
+static uint64_t can_srr_pre_write(RegisterInfo *reg, uint64_t val)
625
+{
648
+{
626
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
649
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
627
+ uint32_t val = val64;
628
+
650
+
629
+ ARRAY_FIELD_DP32(s->regs, SOFTWARE_RESET_REGISTER, CEN,
651
+ ARRAY_FIELD_DP32(s->regs, SOFTWARE_RESET_REGISTER, CEN,
630
+ FIELD_EX32(val, SOFTWARE_RESET_REGISTER, CEN));
652
+ FIELD_EX32(val, SOFTWARE_RESET_REGISTER, CEN));
631
+
653
+
632
+ if (FIELD_EX32(val, SOFTWARE_RESET_REGISTER, SRST)) {
654
+ if (FIELD_EX32(val, SOFTWARE_RESET_REGISTER, SRST)) {
633
+ DB_PRINT(s, "Resetting controller.\n");
655
+ trace_xlnx_can_reset(val);
634
+
656
+
635
+ /* First, core will do software reset then will enter in config mode. */
657
+ /* First, core will do software reset then will enter in config mode. */
636
+ can_config_reset(s);
658
+ can_config_reset(s);
637
+ }
659
+ }
638
+
660
+
...
...
658
+ update_status_register_mode_bits(s);
680
+ update_status_register_mode_bits(s);
659
+
681
+
660
+ return s->regs[R_SOFTWARE_RESET_REGISTER];
682
+ return s->regs[R_SOFTWARE_RESET_REGISTER];
661
+}
683
+}
662
+
684
+
663
+static uint64_t can_msr_pre_write(RegisterInfo *reg, uint64_t val64)
685
+static uint64_t can_msr_pre_write(RegisterInfo *reg, uint64_t val)
664
+{
686
+{
665
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
687
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
666
+ uint32_t val = val64;
667
+ uint8_t multi_mode;
688
+ uint8_t multi_mode;
668
+
689
+
669
+ /*
690
+ /*
670
+ * Multiple mode set check. This is done to make sure user doesn't set
691
+ * Multiple mode set check. This is done to make sure user doesn't set
671
+ * multiple modes.
692
+ * multiple modes.
...
...
709
+ }
730
+ }
710
+
731
+
711
+ return s->regs[R_MODE_SELECT_REGISTER];
732
+ return s->regs[R_MODE_SELECT_REGISTER];
712
+}
733
+}
713
+
734
+
714
+static uint64_t can_brpr_pre_write(RegisterInfo *reg, uint64_t val64)
735
+static uint64_t can_brpr_pre_write(RegisterInfo *reg, uint64_t val)
715
+{
736
+{
716
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
737
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
717
+ uint32_t val = val64;
718
+
738
+
719
+ /* Only allow writes when in config mode. */
739
+ /* Only allow writes when in config mode. */
720
+ if (ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, CEN)) {
740
+ if (ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, CEN)) {
721
+ val = s->regs[R_ARBITRATION_PHASE_BAUD_RATE_PRESCALER_REGISTER];
741
+ return s->regs[R_ARBITRATION_PHASE_BAUD_RATE_PRESCALER_REGISTER];
722
+ }
742
+ }
723
+
743
+
724
+ return val;
744
+ return val;
725
+}
745
+}
726
+
746
+
727
+static uint64_t can_btr_pre_write(RegisterInfo *reg, uint64_t val64)
747
+static uint64_t can_btr_pre_write(RegisterInfo *reg, uint64_t val)
728
+{
748
+{
729
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
749
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
730
+ uint32_t val = val64;
731
+
750
+
732
+ /* Only allow writes when in config mode. */
751
+ /* Only allow writes when in config mode. */
733
+ if (ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, CEN)) {
752
+ if (ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, CEN)) {
734
+ val = s->regs[R_ARBITRATION_PHASE_BIT_TIMING_REGISTER];
753
+ return s->regs[R_ARBITRATION_PHASE_BIT_TIMING_REGISTER];
735
+ }
754
+ }
736
+
755
+
737
+ return val;
756
+ return val;
738
+}
757
+}
739
+
758
+
740
+static uint64_t can_tcr_pre_write(RegisterInfo *reg, uint64_t val64)
759
+static uint64_t can_tcr_pre_write(RegisterInfo *reg, uint64_t val)
741
+{
760
+{
742
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
761
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
743
+ uint32_t val = val64;
744
+
762
+
745
+ if (FIELD_EX32(val, TIMESTAMP_REGISTER, CTS)) {
763
+ if (FIELD_EX32(val, TIMESTAMP_REGISTER, CTS)) {
746
+ ptimer_transaction_begin(s->can_timer);
764
+ ptimer_transaction_begin(s->can_timer);
747
+ ptimer_set_count(s->can_timer, 0);
765
+ ptimer_set_count(s->can_timer, 0);
748
+ ptimer_transaction_commit(s->can_timer);
766
+ ptimer_transaction_commit(s->can_timer);
...
...
802
+ if (filter_id_masked == id_masked) {
820
+ if (filter_id_masked == id_masked) {
803
+ filter_pass = true;
821
+ filter_pass = true;
804
+ }
822
+ }
805
+ }
823
+ }
806
+
824
+
825
+ if (!filter_pass) {
826
+ trace_xlnx_can_rx_fifo_filter_reject(frame->can_id, frame->can_dlc);
827
+ return;
828
+ }
829
+
807
+ /* Store the message in fifo if it passed through any of the filters. */
830
+ /* Store the message in fifo if it passed through any of the filters. */
808
+ if (filter_pass && frame->can_dlc <= MAX_DLC) {
831
+ if (filter_pass && frame->can_dlc <= MAX_DLC) {
809
+
832
+
810
+ if (fifo32_is_full(&s->rx_fifo)) {
833
+ 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);
834
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, RXOFLW, 1);
814
+ } else {
835
+ } else {
815
+ timestamp = CAN_TIMER_MAX - ptimer_get_count(s->can_timer);
836
+ timestamp = CAN_TIMER_MAX - ptimer_get_count(s->can_timer);
816
+
837
+
817
+ fifo32_push(&s->rx_fifo, frame->can_id);
838
+ fifo32_push(&s->rx_fifo, frame->can_id);
...
...
849
+ deposit32(0, R_TXFIFO_DATA2_DB4_SHIFT,
870
+ deposit32(0, R_TXFIFO_DATA2_DB4_SHIFT,
850
+ R_TXFIFO_DATA2_DB4_LENGTH,
871
+ R_TXFIFO_DATA2_DB4_LENGTH,
851
+ frame->data[7]));
872
+ frame->data[7]));
852
+
873
+
853
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, RXOK, 1);
874
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, RXOK, 1);
875
+ trace_xlnx_can_rx_data(frame->can_id, frame->can_dlc,
876
+ frame->data[0], frame->data[1],
877
+ frame->data[2], frame->data[3],
878
+ frame->data[4], frame->data[5],
879
+ frame->data[6], frame->data[7]);
854
+ }
880
+ }
855
+
881
+
856
+ can_update_irq(s);
882
+ can_update_irq(s);
883
+ }
884
+}
885
+
886
+static uint64_t can_rxfifo_pre_read(RegisterInfo *reg, uint64_t val)
887
+{
888
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
889
+
890
+ if (!fifo32_is_empty(&s->rx_fifo)) {
891
+ val = fifo32_pop(&s->rx_fifo);
857
+ } else {
892
+ } 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);
893
+ ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, RXUFLW, 1);
874
+ }
894
+ }
875
+
895
+
876
+ can_update_irq(s);
896
+ can_update_irq(s);
877
+ return r;
897
+ return val;
878
+}
898
+}
879
+
899
+
880
+static void can_filter_enable_post_write(RegisterInfo *reg, uint64_t val64)
900
+static void can_filter_enable_post_write(RegisterInfo *reg, uint64_t val)
881
+{
901
+{
882
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
902
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
883
+
903
+
884
+ if (ARRAY_FIELD_EX32(s->regs, AFR, UAF1) &&
904
+ if (ARRAY_FIELD_EX32(s->regs, AFR, UAF1) &&
885
+ ARRAY_FIELD_EX32(s->regs, AFR, UAF2) &&
905
+ ARRAY_FIELD_EX32(s->regs, AFR, UAF2) &&
...
...
889
+ } else {
909
+ } else {
890
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, ACFBSY, 0);
910
+ ARRAY_FIELD_DP32(s->regs, STATUS_REGISTER, ACFBSY, 0);
891
+ }
911
+ }
892
+}
912
+}
893
+
913
+
894
+static uint64_t can_filter_mask_pre_write(RegisterInfo *reg, uint64_t val64)
914
+static uint64_t can_filter_mask_pre_write(RegisterInfo *reg, uint64_t val)
895
+{
915
+{
896
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
916
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
897
+ uint32_t reg_idx = (reg->access->addr) / 4;
917
+ uint32_t reg_idx = (reg->access->addr) / 4;
898
+ uint32_t val = val64;
899
+ uint32_t filter_number = (reg_idx - R_AFMR1) / 2;
918
+ uint32_t filter_number = (reg_idx - R_AFMR1) / 2;
900
+
919
+
901
+ /* modify an acceptance filter, the corresponding UAF bit should be '0.' */
920
+ /* modify an acceptance filter, the corresponding UAF bit should be '0'. */
902
+ if (!(s->regs[R_AFR] & (1 << filter_number))) {
921
+ if (!(s->regs[R_AFR] & (1 << filter_number))) {
903
+ s->regs[reg_idx] = val;
922
+ s->regs[reg_idx] = val;
923
+
924
+ trace_xlnx_can_filter_mask_pre_write(filter_number, s->regs[reg_idx]);
904
+ } else {
925
+ } else {
905
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
926
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
906
+
927
+
907
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Acceptance filter %d"
928
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Acceptance filter %d"
908
+ " mask is not set as corresponding UAF bit is not 0.\n",
929
+ " mask is not set as corresponding UAF bit is not 0.\n",
909
+ path, filter_number + 1);
930
+ path, filter_number + 1);
910
+ }
931
+ }
911
+
932
+
912
+ return s->regs[reg_idx];
933
+ return s->regs[reg_idx];
913
+}
934
+}
914
+
935
+
915
+static uint64_t can_filter_id_pre_write(RegisterInfo *reg, uint64_t val64)
936
+static uint64_t can_filter_id_pre_write(RegisterInfo *reg, uint64_t val)
916
+{
937
+{
917
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
938
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
918
+ uint32_t reg_idx = (reg->access->addr) / 4;
939
+ uint32_t reg_idx = (reg->access->addr) / 4;
919
+ uint32_t val = val64;
920
+ uint32_t filter_number = (reg_idx - R_AFIR1) / 2;
940
+ uint32_t filter_number = (reg_idx - R_AFIR1) / 2;
921
+
941
+
922
+ if (!(s->regs[R_AFR] & (1 << filter_number))) {
942
+ if (!(s->regs[R_AFR] & (1 << filter_number))) {
923
+ s->regs[reg_idx] = val;
943
+ s->regs[reg_idx] = val;
944
+
945
+ trace_xlnx_can_filter_id_pre_write(filter_number, s->regs[reg_idx]);
924
+ } else {
946
+ } else {
925
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
947
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
926
+
948
+
927
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Acceptance filter %d"
949
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Acceptance filter %d"
928
+ " id is not set as corresponding UAF bit is not 0.\n",
950
+ " id is not set as corresponding UAF bit is not 0.\n",
929
+ path, filter_number + 1);
951
+ path, filter_number + 1);
930
+ }
952
+ }
931
+
953
+
932
+ return s->regs[reg_idx];
954
+ return s->regs[reg_idx];
933
+}
955
+}
934
+
956
+
935
+static void can_tx_post_write(RegisterInfo *reg, uint64_t val64)
957
+static void can_tx_post_write(RegisterInfo *reg, uint64_t val)
936
+{
958
+{
937
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
959
+ XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(reg->opaque);
938
+ uint32_t val = val64;
939
+
960
+
940
+ bool is_txhpb = reg->access->addr > A_TXFIFO_DATA2;
961
+ bool is_txhpb = reg->access->addr > A_TXFIFO_DATA2;
941
+
962
+
942
+ bool initiate_transfer = (reg->access->addr == A_TXFIFO_DATA2) ||
963
+ bool initiate_transfer = (reg->access->addr == A_TXFIFO_DATA2) ||
943
+ (reg->access->addr == A_TXHPB_DATA2);
964
+ (reg->access->addr == A_TXHPB_DATA2);
944
+
965
+
945
+ Fifo32 *f = is_txhpb ? &s->txhpb_fifo : &s->tx_fifo;
966
+ Fifo32 *f = is_txhpb ? &s->txhpb_fifo : &s->tx_fifo;
946
+
947
+ DB_PRINT(s, "TX FIFO write.\n");
948
+
967
+
949
+ if (!fifo32_is_full(f)) {
968
+ if (!fifo32_is_full(f)) {
950
+ fifo32_push(f, val);
969
+ fifo32_push(f, val);
951
+ } else {
970
+ } else {
952
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
971
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
...
...
1115
+{
1134
+{
1116
+ XlnxZynqMPCANState *s = container_of(client, XlnxZynqMPCANState,
1135
+ XlnxZynqMPCANState *s = container_of(client, XlnxZynqMPCANState,
1117
+ bus_client);
1136
+ bus_client);
1118
+
1137
+
1119
+ if (ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, SRST)) {
1138
+ if (ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, SRST)) {
1120
+ DB_PRINT(s, "Controller is in reset.\n");
1139
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
1140
+
1141
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Controller is in reset state.\n",
1142
+ path);
1121
+ return false;
1143
+ return false;
1122
+ } else if ((ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, CEN)) == 0) {
1144
+ }
1123
+ DB_PRINT(s, "Controller is disabled. Incoming messages"
1145
+
1124
+ " will be discarded.\n");
1146
+ if ((ARRAY_FIELD_EX32(s->regs, SOFTWARE_RESET_REGISTER, CEN)) == 0) {
1147
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
1148
+
1149
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Controller is disabled. Incoming"
1150
+ " messages will be discarded.\n", path);
1125
+ return false;
1151
+ return false;
1126
+ } else {
1152
+ }
1127
+ return true;
1153
+
1128
+ }
1154
+ return true;
1129
+}
1155
+}
1130
+
1156
+
1131
+static ssize_t xlnx_zynqmp_can_receive(CanBusClientState *client,
1157
+static ssize_t xlnx_zynqmp_can_receive(CanBusClientState *client,
1132
+ const qemu_can_frame *buf, size_t buf_size) {
1158
+ const qemu_can_frame *buf, size_t buf_size) {
1133
+ XlnxZynqMPCANState *s = container_of(client, XlnxZynqMPCANState,
1159
+ XlnxZynqMPCANState *s = container_of(client, XlnxZynqMPCANState,
1134
+ bus_client);
1160
+ bus_client);
1135
+ const qemu_can_frame *frame = buf;
1161
+ const qemu_can_frame *frame = buf;
1136
+
1162
+
1137
+ DB_PRINT(s, "Incoming data.\n");
1138
+
1139
+ if (buf_size <= 0) {
1163
+ if (buf_size <= 0) {
1140
+ DB_PRINT(s, "Junk data received.\n");
1164
+ g_autofree char *path = object_get_canonical_path(OBJECT(s));
1165
+
1166
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Error in the data received.\n",
1167
+ path);
1141
+ return 0;
1168
+ return 0;
1142
+ }
1169
+ }
1143
+ if (ARRAY_FIELD_EX32(s->regs, STATUS_REGISTER, LBACK)) {
1170
+
1144
+ /*
1171
+ if (ARRAY_FIELD_EX32(s->regs, STATUS_REGISTER, SNOOP)) {
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. */
1172
+ /* Snoop Mode: Just keep the data. no response back. */
1153
+ update_rx_fifo(s, frame);
1173
+ update_rx_fifo(s, frame);
1154
+ } else if ((ARRAY_FIELD_EX32(s->regs, STATUS_REGISTER, SLEEP))) {
1174
+ } else if ((ARRAY_FIELD_EX32(s->regs, STATUS_REGISTER, SLEEP))) {
1155
+ /*
1175
+ /*
1156
+ * XlnxZynqMPCAN is in sleep mode. Any data on bus will bring it to wake
1176
+ * XlnxZynqMPCAN is in sleep mode. Any data on bus will bring it to wake
...
...
1159
+ can_exit_sleep_mode(s);
1179
+ can_exit_sleep_mode(s);
1160
+ update_rx_fifo(s, frame);
1180
+ update_rx_fifo(s, frame);
1161
+ } else if ((ARRAY_FIELD_EX32(s->regs, STATUS_REGISTER, SLEEP)) == 0) {
1181
+ } else if ((ARRAY_FIELD_EX32(s->regs, STATUS_REGISTER, SLEEP)) == 0) {
1162
+ update_rx_fifo(s, frame);
1182
+ update_rx_fifo(s, frame);
1163
+ } else {
1183
+ } else {
1164
+ DB_PRINT(s, "Cannot receive data as controller is not configured"
1184
+ /*
1165
+ " correctly.\n");
1185
+ * XlnxZynqMPCAN will not participate in normal bus communication
1186
+ * and will not receive any messages transmitted by other CAN nodes.
1187
+ */
1188
+ trace_xlnx_can_rx_discard(s->regs[R_STATUS_REGISTER]);
1166
+ }
1189
+ }
1167
+
1190
+
1168
+ return 1;
1191
+ return 1;
1169
+}
1192
+}
1170
+
1193
+
...
...
1194
+
1217
+
1195
+ error_setg(errp, "%s: xlnx_zynqmp_can_connect_to_bus"
1218
+ error_setg(errp, "%s: xlnx_zynqmp_can_connect_to_bus"
1196
+ " failed.", path);
1219
+ " failed.", path);
1197
+ return;
1220
+ return;
1198
+ }
1221
+ }
1199
+
1200
+ } else {
1201
+ /* If no bus is set. */
1202
+ DB_PRINT(s, "Canbus property is not set.\n");
1203
+ }
1222
+ }
1204
+
1223
+
1205
+ /* Create RX FIFO, TXFIFO, TXHPB storage. */
1224
+ /* Create RX FIFO, TXFIFO, TXHPB storage. */
1206
+ fifo32_create(&s->rx_fifo, RXFIFO_SIZE);
1225
+ fifo32_create(&s->rx_fifo, RXFIFO_SIZE);
1207
+ fifo32_create(&s->tx_fifo, RXFIFO_SIZE);
1226
+ fifo32_create(&s->tx_fifo, RXFIFO_SIZE);
...
...
1286
+{
1305
+{
1287
+ type_register_static(&can_info);
1306
+ type_register_static(&can_info);
1288
+}
1307
+}
1289
+
1308
+
1290
+type_init(can_register_types)
1309
+type_init(can_register_types)
1310
diff --git a/hw/Kconfig b/hw/Kconfig
1311
index XXXXXXX..XXXXXXX 100644
1312
--- a/hw/Kconfig
1313
+++ b/hw/Kconfig
1314
@@ -XXX,XX +XXX,XX @@ config XILINX_AXI
1315
config XLNX_ZYNQMP
1316
bool
1317
select REGISTER
1318
+ select CAN_BUS
1291
diff --git a/hw/net/can/meson.build b/hw/net/can/meson.build
1319
diff --git a/hw/net/can/meson.build b/hw/net/can/meson.build
1292
index XXXXXXX..XXXXXXX 100644
1320
index XXXXXXX..XXXXXXX 100644
1293
--- a/hw/net/can/meson.build
1321
--- a/hw/net/can/meson.build
1294
+++ b/hw/net/can/meson.build
1322
+++ b/hw/net/can/meson.build
1295
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_CAN_SJA1000', if_true: files('can_sja1000.c'))
1323
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_CAN_PCI', if_true: files('can_pcm3680_pci.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'))
1324
softmmu_ss.add(when: 'CONFIG_CAN_PCI', if_true: files('can_mioe3680_pci.c'))
1325
softmmu_ss.add(when: 'CONFIG_CAN_CTUCANFD', if_true: files('ctucan_core.c'))
1326
softmmu_ss.add(when: 'CONFIG_CAN_CTUCANFD_PCI', if_true: files('ctucan_pci.c'))
1299
+softmmu_ss.add(when: 'CONFIG_XLNX_ZYNQMP', if_true: files('xlnx-zynqmp-can.c'))
1327
+softmmu_ss.add(when: 'CONFIG_XLNX_ZYNQMP', if_true: files('xlnx-zynqmp-can.c'))
1328
diff --git a/hw/net/can/trace-events b/hw/net/can/trace-events
1329
new file mode 100644
1330
index XXXXXXX..XXXXXXX
1331
--- /dev/null
1332
+++ b/hw/net/can/trace-events
1333
@@ -XXX,XX +XXX,XX @@
1334
+# xlnx-zynqmp-can.c
1335
+xlnx_can_update_irq(uint32_t isr, uint32_t ier, uint32_t irq) "ISR: 0x%08x IER: 0x%08x IRQ: 0x%08x"
1336
+xlnx_can_reset(uint32_t val) "Resetting controller with value = 0x%08x"
1337
+xlnx_can_rx_fifo_filter_reject(uint32_t id, uint8_t dlc) "Frame: ID: 0x%08x DLC: 0x%02x"
1338
+xlnx_can_filter_id_pre_write(uint8_t filter_num, uint32_t value) "Filter%d ID: 0x%08x"
1339
+xlnx_can_filter_mask_pre_write(uint8_t filter_num, uint32_t value) "Filter%d MASK: 0x%08x"
1340
+xlnx_can_tx_data(uint32_t id, uint8_t dlc, uint8_t db0, uint8_t db1, uint8_t db2, uint8_t db3, uint8_t db4, uint8_t db5, uint8_t db6, uint8_t db7) "Frame: ID: 0x%08x DLC: 0x%02x DATA: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x"
1341
+xlnx_can_rx_data(uint32_t id, uint32_t dlc, uint8_t db0, uint8_t db1, uint8_t db2, uint8_t db3, uint8_t db4, uint8_t db5, uint8_t db6, uint8_t db7) "Frame: ID: 0x%08x DLC: 0x%02x DATA: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x"
1342
+xlnx_can_rx_discard(uint32_t status) "Controller is not enabled for bus communication. Status Register: 0x%08x"
1300
--
1343
--
1301
2.20.1
1344
2.20.1
1302
1345
1303
1346
diff view generated by jsdifflib
...
...
3
Connect CAN0 and CAN1 on the ZynqMP.
3
Connect CAN0 and CAN1 on the ZynqMP.
4
4
5
Reviewed-by: Francisco Iglesias <francisco.iglesias@xilinx.com>
5
Reviewed-by: Francisco Iglesias <francisco.iglesias@xilinx.com>
6
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
6
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
7
Signed-off-by: Vikram Garhwal <fnu.vikram@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
8
Message-id: 1605728926-352690-3-git-send-email-fnu.vikram@xilinx.com
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
10
---
11
include/hw/arm/xlnx-zynqmp.h | 8 ++++++++
11
include/hw/arm/xlnx-zynqmp.h | 8 ++++++++
12
hw/arm/xlnx-zcu102.c | 20 ++++++++++++++++++++
12
hw/arm/xlnx-zcu102.c | 20 ++++++++++++++++++++
13
hw/arm/xlnx-zynqmp.c | 34 ++++++++++++++++++++++++++++++++++
13
hw/arm/xlnx-zynqmp.c | 34 ++++++++++++++++++++++++++++++++++
...
...
30
#include "target/arm/cpu.h"
30
#include "target/arm/cpu.h"
31
#include "qom/object.h"
31
#include "qom/object.h"
32
+#include "net/can_emu.h"
32
+#include "net/can_emu.h"
33
33
34
#define TYPE_XLNX_ZYNQMP "xlnx,zynqmp"
34
#define TYPE_XLNX_ZYNQMP "xlnx,zynqmp"
35
typedef struct XlnxZynqMPState XlnxZynqMPState;
35
OBJECT_DECLARE_SIMPLE_TYPE(XlnxZynqMPState, XLNX_ZYNQMP)
36
@@ -XXX,XX +XXX,XX @@ DECLARE_INSTANCE_CHECKER(XlnxZynqMPState, XLNX_ZYNQMP,
36
@@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_SIMPLE_TYPE(XlnxZynqMPState, XLNX_ZYNQMP)
37
#define XLNX_ZYNQMP_NUM_RPU_CPUS 2
37
#define XLNX_ZYNQMP_NUM_RPU_CPUS 2
38
#define XLNX_ZYNQMP_NUM_GEMS 4
38
#define XLNX_ZYNQMP_NUM_GEMS 4
39
#define XLNX_ZYNQMP_NUM_UARTS 2
39
#define XLNX_ZYNQMP_NUM_UARTS 2
40
+#define XLNX_ZYNQMP_NUM_CAN 2
40
+#define XLNX_ZYNQMP_NUM_CAN 2
41
+#define XLNX_ZYNQMP_CAN_REF_CLK (24 * 1000 * 1000)
41
+#define XLNX_ZYNQMP_CAN_REF_CLK (24 * 1000 * 1000)
...
...
78
78
79
+ CanBusState *canbus[XLNX_ZYNQMP_NUM_CAN];
79
+ CanBusState *canbus[XLNX_ZYNQMP_NUM_CAN];
80
+
80
+
81
struct arm_boot_info binfo;
81
struct arm_boot_info binfo;
82
};
82
};
83
typedef struct XlnxZCU102 XlnxZCU102;
83
84
@@ -XXX,XX +XXX,XX @@ static void xlnx_zcu102_init(MachineState *machine)
84
@@ -XXX,XX +XXX,XX @@ static void xlnx_zcu102_init(MachineState *machine)
85
object_property_set_bool(OBJECT(&s->soc), "virtualization", s->virt,
85
object_property_set_bool(OBJECT(&s->soc), "virtualization", s->virt,
86
&error_fatal);
86
&error_fatal);
87
87
88
+ for (i = 0; i < XLNX_ZYNQMP_NUM_CAN; i++) {
88
+ for (i = 0; i < XLNX_ZYNQMP_NUM_CAN; i++) {
...
...
95
+
95
+
96
qdev_realize(DEVICE(&s->soc), NULL, &error_fatal);
96
qdev_realize(DEVICE(&s->soc), NULL, &error_fatal);
97
97
98
/* Create and plug in the SD cards */
98
/* Create and plug in the SD cards */
99
@@ -XXX,XX +XXX,XX @@ static void xlnx_zcu102_machine_instance_init(Object *obj)
99
@@ -XXX,XX +XXX,XX @@ static void xlnx_zcu102_machine_instance_init(Object *obj)
100
"Set on/off to enable/disable emulating a "
100
s->secure = false;
101
"guest CPU which implements the ARM "
101
/* Default to virt (EL2) being disabled */
102
"Virtualization Extensions");
102
s->virt = false;
103
+ object_property_add_link(obj, "xlnx-zcu102.canbus0", TYPE_CAN_BUS,
103
+ object_property_add_link(obj, "xlnx-zcu102.canbus0", TYPE_CAN_BUS,
104
+ (Object **)&s->canbus[0],
104
+ (Object **)&s->canbus[0],
105
+ object_property_allow_set_link,
105
+ object_property_allow_set_link,
106
+ 0);
106
+ 0);
107
+
107
+
...
...
diff view generated by jsdifflib
1
From: Vikram Garhwal <fnu.vikram@xilinx.com>
1
From: Vikram Garhwal <fnu.vikram@xilinx.com>
2
2
3
The QTests perform five tests on the Xilinx ZynqMP CAN controller:
3
The QTests perform five tests on the Xilinx ZynqMP CAN controller:
4
Tests the CAN controller in loopback, sleep and snoop mode.
4
Tests the CAN controller in loopback, sleep and snoop mode.
5
Tests filtering of incoming CAN messages.
5
Tests filtering of incoming CAN messages.
6
6
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Reviewed-by: Francisco Iglesias <francisco.iglesias@xilinx.com>
8
Reviewed-by: Francisco Iglesias <francisco.iglesias@xilinx.com>
8
Signed-off-by: Vikram Garhwal <fnu.vikram@xilinx.com>
9
Signed-off-by: Vikram Garhwal <fnu.vikram@xilinx.com>
9
Message-id: 1597278668-339715-4-git-send-email-fnu.vikram@xilinx.com
10
Message-id: 1605728926-352690-4-git-send-email-fnu.vikram@xilinx.com
10
[PMM: updated to meson build system]
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
12
---
13
tests/qtest/xlnx-can-test.c | 359 ++++++++++++++++++++++++++++++++++++
13
tests/qtest/xlnx-can-test.c | 360 ++++++++++++++++++++++++++++++++++++
14
tests/qtest/meson.build | 1 +
14
tests/qtest/meson.build | 1 +
15
2 files changed, 360 insertions(+)
15
2 files changed, 361 insertions(+)
16
create mode 100644 tests/qtest/xlnx-can-test.c
16
create mode 100644 tests/qtest/xlnx-can-test.c
17
17
18
diff --git a/tests/qtest/xlnx-can-test.c b/tests/qtest/xlnx-can-test.c
18
diff --git a/tests/qtest/xlnx-can-test.c b/tests/qtest/xlnx-can-test.c
19
new file mode 100644
19
new file mode 100644
20
index XXXXXXX..XXXXXXX
20
index XXXXXXX..XXXXXXX
...
...
90
+#define STATUS_SNOOP_MODE (1 << 12)
90
+#define STATUS_SNOOP_MODE (1 << 12)
91
+#define STATUS_SLEEP_MODE (1 << 2)
91
+#define STATUS_SLEEP_MODE (1 << 2)
92
+#define ISR_TXOK (1 << 1)
92
+#define ISR_TXOK (1 << 1)
93
+#define ISR_RXOK (1 << 4)
93
+#define ISR_RXOK (1 << 4)
94
+
94
+
95
+static void match_rx_tx_data(uint32_t *buf_tx, uint32_t *buf_rx,
95
+static void match_rx_tx_data(const uint32_t *buf_tx, const uint32_t *buf_rx,
96
+ uint8_t can_timestamp)
96
+ uint8_t can_timestamp)
97
+{
97
+{
98
+ uint16_t size = 0;
98
+ uint16_t size = 0;
99
+ uint8_t len = 4;
99
+ uint8_t len = 4;
100
+
100
+
...
...
126
+
126
+
127
+ /* Clear the RX interrupt. */
127
+ /* Clear the RX interrupt. */
128
+ qtest_writel(qts, CAN1_BASE_ADDR + R_ICR_OFFSET, ISR_RXOK);
128
+ qtest_writel(qts, CAN1_BASE_ADDR + R_ICR_OFFSET, ISR_RXOK);
129
+}
129
+}
130
+
130
+
131
+static void send_data(QTestState *qts, uint64_t can_base_addr, uint32_t *buf_tx)
131
+static void send_data(QTestState *qts, uint64_t can_base_addr,
132
+ const uint32_t *buf_tx)
132
+{
133
+{
133
+ uint32_t int_status;
134
+ uint32_t int_status;
134
+
135
+
135
+ /* Write the TX register data for CAN. */
136
+ /* 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_TXID_OFFSET, buf_tx[0]);
...
...
152
+ * initiate the data transfer to can-bus, CAN1 receives the data. Test compares
153
+ * initiate the data transfer to can-bus, CAN1 receives the data. Test compares
153
+ * the data sent from CAN0 with received on CAN1.
154
+ * the data sent from CAN0 with received on CAN1.
154
+ */
155
+ */
155
+static void test_can_bus(void)
156
+static void test_can_bus(void)
156
+{
157
+{
157
+ uint32_t buf_tx[4] = { 0xFF, 0x80000000, 0x12345678, 0x87654321 };
158
+ const uint32_t buf_tx[4] = { 0xFF, 0x80000000, 0x12345678, 0x87654321 };
158
+ uint32_t buf_rx[4] = { 0x00, 0x00, 0x00, 0x00 };
159
+ uint32_t buf_rx[4] = { 0x00, 0x00, 0x00, 0x00 };
159
+ uint32_t status = 0;
160
+ uint32_t status = 0;
160
+ uint8_t can_timestamp = 1;
161
+ uint8_t can_timestamp = 1;
161
+
162
+
162
+ QTestState *qts = qtest_init("-machine xlnx-zcu102"
163
+ QTestState *qts = qtest_init("-machine xlnx-zcu102"
...
...
383
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
384
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
384
index XXXXXXX..XXXXXXX 100644
385
index XXXXXXX..XXXXXXX 100644
385
--- a/tests/qtest/meson.build
386
--- a/tests/qtest/meson.build
386
+++ b/tests/qtest/meson.build
387
+++ b/tests/qtest/meson.build
387
@@ -XXX,XX +XXX,XX @@ qtests_aarch64 = \
388
@@ -XXX,XX +XXX,XX @@ qtests_aarch64 = \
388
(config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? ['tpm-tis-device-swtpm-test'] : []) + \
389
['arm-cpu-features',
389
['numa-test',
390
'numa-test',
390
'boot-serial-test',
391
'boot-serial-test',
391
+ 'xlnx-can-test',
392
+ 'xlnx-can-test',
392
'migration-test']
393
'migration-test']
393
394
394
qtests_s390x = \
395
qtests_s390x = \
395
--
396
--
396
2.20.1
397
2.20.1
397
398
398
399
diff view generated by jsdifflib
1
From: Vikram Garhwal <fnu.vikram@xilinx.com>
1
From: Vikram Garhwal <fnu.vikram@xilinx.com>
2
2
3
Reviewed-by: Francisco Iglesias <francisco.iglesias@xilinx.com>
3
Reviewed-by: Francisco Iglesias <francisco.iglesias@xilinx.com>
4
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
4
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
5
Signed-off-by: Vikram Garhwal <fnu.vikram@xilinx.com>
5
Signed-off-by: Vikram Garhwal <fnu.vikram@xilinx.com>
6
Message-id: 1597278668-339715-5-git-send-email-fnu.vikram@xilinx.com
6
Message-id: 1605728926-352690-5-git-send-email-fnu.vikram@xilinx.com
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
---
8
---
9
MAINTAINERS | 8 ++++++++
9
MAINTAINERS | 8 ++++++++
10
1 file changed, 8 insertions(+)
10
1 file changed, 8 insertions(+)
11
11
...
...
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
2
2
3
The NPCM730 and NPCM750 SoCs have three timer modules each holding five
3
Trusted Firmware now supports A72 on sbsa-ref by default [1] so enable
4
timers and some shared registers (e.g. interrupt status).
4
it for QEMU as well. A53 was already enabled there.
5
5
6
Each timer runs at 25 MHz divided by a prescaler, and counts down from a
6
1. https://review.trustedfirmware.org/c/TF-A/trusted-firmware-a/+/7117
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
7
11
This implementation is sufficient to boot a Linux kernel configured for
8
Signed-off-by: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
12
NPCM750. Note that the kernel does not seem to actually turn on the
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
13
interrupts.
10
Message-id: 20201120141705.246690-1-marcin.juszkiewicz@linaro.org
14
11
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
15
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
16
Reviewed-by: Joel Stanley <joel@jms.id.au>
17
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
18
Tested-by: Alexander Bulekov <alxndr@bu.edu>
19
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
20
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
21
Message-id: 20200911052101.2602693-4-hskinnemoen@google.com
22
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
23
---
13
---
24
include/hw/timer/npcm7xx_timer.h | 78 +++++
14
hw/arm/sbsa-ref.c | 23 ++++++++++++++++++++---
25
hw/timer/npcm7xx_timer.c | 543 +++++++++++++++++++++++++++++++
15
1 file changed, 20 insertions(+), 3 deletions(-)
26
hw/timer/meson.build | 1 +
27
hw/timer/trace-events | 5 +
28
4 files changed, 627 insertions(+)
29
create mode 100644 include/hw/timer/npcm7xx_timer.h
30
create mode 100644 hw/timer/npcm7xx_timer.c
31
16
32
diff --git a/include/hw/timer/npcm7xx_timer.h b/include/hw/timer/npcm7xx_timer.h
17
diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
33
new file mode 100644
18
index XXXXXXX..XXXXXXX 100644
34
index XXXXXXX..XXXXXXX
19
--- a/hw/arm/sbsa-ref.c
35
--- /dev/null
20
+++ b/hw/arm/sbsa-ref.c
36
+++ b/include/hw/timer/npcm7xx_timer.h
21
@@ -XXX,XX +XXX,XX @@ static const int sbsa_ref_irqmap[] = {
37
@@ -XXX,XX +XXX,XX @@
22
[SBSA_GWDT] = 16,
38
+/*
23
};
39
+ * Nuvoton NPCM7xx Timer Controller
24
40
+ *
25
+static const char * const valid_cpus[] = {
41
+ * Copyright 2020 Google LLC
26
+ ARM_CPU_TYPE_NAME("cortex-a53"),
42
+ *
27
+ ARM_CPU_TYPE_NAME("cortex-a57"),
43
+ * This program is free software; you can redistribute it and/or modify it
28
+ ARM_CPU_TYPE_NAME("cortex-a72"),
44
+ * under the terms of the GNU General Public License as published by the
45
+ * Free Software Foundation; either version 2 of the License, or
46
+ * (at your option) any later version.
47
+ *
48
+ * This program is distributed in the hope that it will be useful, but WITHOUT
49
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
50
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
51
+ * for more details.
52
+ */
53
+#ifndef NPCM7XX_TIMER_H
54
+#define NPCM7XX_TIMER_H
55
+
56
+#include "exec/memory.h"
57
+#include "hw/sysbus.h"
58
+#include "qemu/timer.h"
59
+
60
+/* Each Timer Module (TIM) instance holds five 25 MHz timers. */
61
+#define NPCM7XX_TIMERS_PER_CTRL (5)
62
+
63
+/*
64
+ * Number of registers in our device state structure. Don't change this without
65
+ * incrementing the version_id in the vmstate.
66
+ */
67
+#define NPCM7XX_TIMER_NR_REGS (0x54 / sizeof(uint32_t))
68
+
69
+typedef struct NPCM7xxTimerCtrlState NPCM7xxTimerCtrlState;
70
+
71
+/**
72
+ * struct NPCM7xxTimer - Individual timer state.
73
+ * @irq: GIC interrupt line to fire on expiration (if enabled).
74
+ * @qtimer: QEMU timer that notifies us on expiration.
75
+ * @expires_ns: Absolute virtual expiration time.
76
+ * @remaining_ns: Remaining time until expiration if timer is paused.
77
+ * @tcsr: The Timer Control and Status Register.
78
+ * @ticr: The Timer Initial Count Register.
79
+ */
80
+typedef struct NPCM7xxTimer {
81
+ NPCM7xxTimerCtrlState *ctrl;
82
+
83
+ qemu_irq irq;
84
+ QEMUTimer qtimer;
85
+ int64_t expires_ns;
86
+ int64_t remaining_ns;
87
+
88
+ uint32_t tcsr;
89
+ uint32_t ticr;
90
+} NPCM7xxTimer;
91
+
92
+/**
93
+ * struct NPCM7xxTimerCtrlState - Timer Module device state.
94
+ * @parent: System bus device.
95
+ * @iomem: Memory region through which registers are accessed.
96
+ * @tisr: The Timer Interrupt Status Register.
97
+ * @wtcr: The Watchdog Timer Control Register.
98
+ * @timer: The five individual timers managed by this module.
99
+ */
100
+struct NPCM7xxTimerCtrlState {
101
+ SysBusDevice parent;
102
+
103
+ MemoryRegion iomem;
104
+
105
+ uint32_t tisr;
106
+ uint32_t wtcr;
107
+
108
+ NPCM7xxTimer timer[NPCM7XX_TIMERS_PER_CTRL];
109
+};
29
+};
110
+
30
+
111
+#define TYPE_NPCM7XX_TIMER "npcm7xx-timer"
31
+static bool cpu_type_valid(const char *cpu)
112
+#define NPCM7XX_TIMER(obj) \
113
+ OBJECT_CHECK(NPCM7xxTimerCtrlState, (obj), TYPE_NPCM7XX_TIMER)
114
+
115
+#endif /* NPCM7XX_TIMER_H */
116
diff --git a/hw/timer/npcm7xx_timer.c b/hw/timer/npcm7xx_timer.c
117
new file mode 100644
118
index XXXXXXX..XXXXXXX
119
--- /dev/null
120
+++ b/hw/timer/npcm7xx_timer.c
121
@@ -XXX,XX +XXX,XX @@
122
+/*
123
+ * Nuvoton NPCM7xx Timer Controller
124
+ *
125
+ * Copyright 2020 Google LLC
126
+ *
127
+ * This program is free software; you can redistribute it and/or modify it
128
+ * under the terms of the GNU General Public License as published by the
129
+ * Free Software Foundation; either version 2 of the License, or
130
+ * (at your option) any later version.
131
+ *
132
+ * This program is distributed in the hope that it will be useful, but WITHOUT
133
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
134
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
135
+ * for more details.
136
+ */
137
+
138
+#include "qemu/osdep.h"
139
+
140
+#include "hw/irq.h"
141
+#include "hw/misc/npcm7xx_clk.h"
142
+#include "hw/timer/npcm7xx_timer.h"
143
+#include "migration/vmstate.h"
144
+#include "qemu/bitops.h"
145
+#include "qemu/error-report.h"
146
+#include "qemu/log.h"
147
+#include "qemu/module.h"
148
+#include "qemu/timer.h"
149
+#include "qemu/units.h"
150
+#include "trace.h"
151
+
152
+/* 32-bit register indices. */
153
+enum NPCM7xxTimerRegisters {
154
+ NPCM7XX_TIMER_TCSR0,
155
+ NPCM7XX_TIMER_TCSR1,
156
+ NPCM7XX_TIMER_TICR0,
157
+ NPCM7XX_TIMER_TICR1,
158
+ NPCM7XX_TIMER_TDR0,
159
+ NPCM7XX_TIMER_TDR1,
160
+ NPCM7XX_TIMER_TISR,
161
+ NPCM7XX_TIMER_WTCR,
162
+ NPCM7XX_TIMER_TCSR2,
163
+ NPCM7XX_TIMER_TCSR3,
164
+ NPCM7XX_TIMER_TICR2,
165
+ NPCM7XX_TIMER_TICR3,
166
+ NPCM7XX_TIMER_TDR2,
167
+ NPCM7XX_TIMER_TDR3,
168
+ NPCM7XX_TIMER_TCSR4 = 0x0040 / sizeof(uint32_t),
169
+ NPCM7XX_TIMER_TICR4 = 0x0048 / sizeof(uint32_t),
170
+ NPCM7XX_TIMER_TDR4 = 0x0050 / sizeof(uint32_t),
171
+ NPCM7XX_TIMER_REGS_END,
172
+};
173
+
174
+/* Register field definitions. */
175
+#define NPCM7XX_TCSR_CEN BIT(30)
176
+#define NPCM7XX_TCSR_IE BIT(29)
177
+#define NPCM7XX_TCSR_PERIODIC BIT(27)
178
+#define NPCM7XX_TCSR_CRST BIT(26)
179
+#define NPCM7XX_TCSR_CACT BIT(25)
180
+#define NPCM7XX_TCSR_RSVD 0x01ffff00
181
+#define NPCM7XX_TCSR_PRESCALE_START 0
182
+#define NPCM7XX_TCSR_PRESCALE_LEN 8
183
+
184
+/*
185
+ * Returns the index of timer in the tc->timer array. This can be used to
186
+ * locate the registers that belong to this timer.
187
+ */
188
+static int npcm7xx_timer_index(NPCM7xxTimerCtrlState *tc, NPCM7xxTimer *timer)
189
+{
190
+ int index = timer - tc->timer;
191
+
192
+ g_assert(index >= 0 && index < NPCM7XX_TIMERS_PER_CTRL);
193
+
194
+ return index;
195
+}
196
+
197
+/* Return the value by which to divide the reference clock rate. */
198
+static uint32_t npcm7xx_tcsr_prescaler(uint32_t tcsr)
199
+{
200
+ return extract32(tcsr, NPCM7XX_TCSR_PRESCALE_START,
201
+ NPCM7XX_TCSR_PRESCALE_LEN) + 1;
202
+}
203
+
204
+/* Convert a timer cycle count to a time interval in nanoseconds. */
205
+static int64_t npcm7xx_timer_count_to_ns(NPCM7xxTimer *t, uint32_t count)
206
+{
207
+ int64_t ns = count;
208
+
209
+ ns *= NANOSECONDS_PER_SECOND / NPCM7XX_TIMER_REF_HZ;
210
+ ns *= npcm7xx_tcsr_prescaler(t->tcsr);
211
+
212
+ return ns;
213
+}
214
+
215
+/* Convert a time interval in nanoseconds to a timer cycle count. */
216
+static uint32_t npcm7xx_timer_ns_to_count(NPCM7xxTimer *t, int64_t ns)
217
+{
218
+ int64_t count;
219
+
220
+ count = ns / (NANOSECONDS_PER_SECOND / NPCM7XX_TIMER_REF_HZ);
221
+ count /= npcm7xx_tcsr_prescaler(t->tcsr);
222
+
223
+ return count;
224
+}
225
+
226
+/*
227
+ * Raise the interrupt line if there's a pending interrupt and interrupts are
228
+ * enabled for this timer. If not, lower it.
229
+ */
230
+static void npcm7xx_timer_check_interrupt(NPCM7xxTimer *t)
231
+{
232
+ NPCM7xxTimerCtrlState *tc = t->ctrl;
233
+ int index = npcm7xx_timer_index(tc, t);
234
+ bool pending = (t->tcsr & NPCM7XX_TCSR_IE) && (tc->tisr & BIT(index));
235
+
236
+ qemu_set_irq(t->irq, pending);
237
+ trace_npcm7xx_timer_irq(DEVICE(tc)->canonical_path, index, pending);
238
+}
239
+
240
+/* Start or resume the timer. */
241
+static void npcm7xx_timer_start(NPCM7xxTimer *t)
242
+{
243
+ int64_t now;
244
+
245
+ now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
246
+ t->expires_ns = now + t->remaining_ns;
247
+ timer_mod(&t->qtimer, t->expires_ns);
248
+}
249
+
250
+/*
251
+ * Called when the counter reaches zero. Sets the interrupt flag, and either
252
+ * restarts or disables the timer.
253
+ */
254
+static void npcm7xx_timer_reached_zero(NPCM7xxTimer *t)
255
+{
256
+ NPCM7xxTimerCtrlState *tc = t->ctrl;
257
+ int index = npcm7xx_timer_index(tc, t);
258
+
259
+ tc->tisr |= BIT(index);
260
+
261
+ if (t->tcsr & NPCM7XX_TCSR_PERIODIC) {
262
+ t->remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr);
263
+ if (t->tcsr & NPCM7XX_TCSR_CEN) {
264
+ npcm7xx_timer_start(t);
265
+ }
266
+ } else {
267
+ t->tcsr &= ~(NPCM7XX_TCSR_CEN | NPCM7XX_TCSR_CACT);
268
+ }
269
+
270
+ npcm7xx_timer_check_interrupt(t);
271
+}
272
+
273
+/* Stop counting. Record the time remaining so we can continue later. */
274
+static void npcm7xx_timer_pause(NPCM7xxTimer *t)
275
+{
276
+ int64_t now;
277
+
278
+ timer_del(&t->qtimer);
279
+ now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
280
+ t->remaining_ns = t->expires_ns - now;
281
+ if (t->remaining_ns <= 0) {
282
+ npcm7xx_timer_reached_zero(t);
283
+ }
284
+}
285
+
286
+/*
287
+ * Restart the timer from its initial value. If the timer was enabled and stays
288
+ * enabled, adjust the QEMU timer according to the new count. If the timer is
289
+ * transitioning from disabled to enabled, the caller is expected to start the
290
+ * timer later.
291
+ */
292
+static void npcm7xx_timer_restart(NPCM7xxTimer *t, uint32_t old_tcsr)
293
+{
294
+ t->remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr);
295
+
296
+ if (old_tcsr & t->tcsr & NPCM7XX_TCSR_CEN) {
297
+ npcm7xx_timer_start(t);
298
+ }
299
+}
300
+
301
+/* Register read and write handlers */
302
+
303
+static uint32_t npcm7xx_timer_read_tdr(NPCM7xxTimer *t)
304
+{
305
+ if (t->tcsr & NPCM7XX_TCSR_CEN) {
306
+ int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
307
+
308
+ return npcm7xx_timer_ns_to_count(t, t->expires_ns - now);
309
+ }
310
+
311
+ return npcm7xx_timer_ns_to_count(t, t->remaining_ns);
312
+}
313
+
314
+static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr)
315
+{
316
+ uint32_t old_tcsr = t->tcsr;
317
+ uint32_t tdr;
318
+
319
+ if (new_tcsr & NPCM7XX_TCSR_RSVD) {
320
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: reserved bits in 0x%08x ignored\n",
321
+ __func__, new_tcsr);
322
+ new_tcsr &= ~NPCM7XX_TCSR_RSVD;
323
+ }
324
+ if (new_tcsr & NPCM7XX_TCSR_CACT) {
325
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: read-only bits in 0x%08x ignored\n",
326
+ __func__, new_tcsr);
327
+ new_tcsr &= ~NPCM7XX_TCSR_CACT;
328
+ }
329
+ if ((new_tcsr & NPCM7XX_TCSR_CRST) && (new_tcsr & NPCM7XX_TCSR_CEN)) {
330
+ qemu_log_mask(LOG_GUEST_ERROR,
331
+ "%s: both CRST and CEN set; ignoring CEN.\n",
332
+ __func__);
333
+ new_tcsr &= ~NPCM7XX_TCSR_CEN;
334
+ }
335
+
336
+ /* Calculate the value of TDR before potentially changing the prescaler. */
337
+ tdr = npcm7xx_timer_read_tdr(t);
338
+
339
+ t->tcsr = (t->tcsr & NPCM7XX_TCSR_CACT) | new_tcsr;
340
+
341
+ if (npcm7xx_tcsr_prescaler(old_tcsr) != npcm7xx_tcsr_prescaler(new_tcsr)) {
342
+ /* Recalculate time remaining based on the current TDR value. */
343
+ t->remaining_ns = npcm7xx_timer_count_to_ns(t, tdr);
344
+ if (old_tcsr & t->tcsr & NPCM7XX_TCSR_CEN) {
345
+ npcm7xx_timer_start(t);
346
+ }
347
+ }
348
+
349
+ if ((old_tcsr ^ new_tcsr) & NPCM7XX_TCSR_IE) {
350
+ npcm7xx_timer_check_interrupt(t);
351
+ }
352
+ if (new_tcsr & NPCM7XX_TCSR_CRST) {
353
+ npcm7xx_timer_restart(t, old_tcsr);
354
+ t->tcsr &= ~NPCM7XX_TCSR_CRST;
355
+ }
356
+ if ((old_tcsr ^ new_tcsr) & NPCM7XX_TCSR_CEN) {
357
+ if (new_tcsr & NPCM7XX_TCSR_CEN) {
358
+ t->tcsr |= NPCM7XX_TCSR_CACT;
359
+ npcm7xx_timer_start(t);
360
+ } else {
361
+ t->tcsr &= ~NPCM7XX_TCSR_CACT;
362
+ npcm7xx_timer_pause(t);
363
+ }
364
+ }
365
+}
366
+
367
+static void npcm7xx_timer_write_ticr(NPCM7xxTimer *t, uint32_t new_ticr)
368
+{
369
+ t->ticr = new_ticr;
370
+
371
+ npcm7xx_timer_restart(t, t->tcsr);
372
+}
373
+
374
+static void npcm7xx_timer_write_tisr(NPCM7xxTimerCtrlState *s, uint32_t value)
375
+{
32
+{
376
+ int i;
33
+ int i;
377
+
34
+
378
+ s->tisr &= ~value;
35
+ for (i = 0; i < ARRAY_SIZE(valid_cpus); i++) {
379
+ for (i = 0; i < ARRAY_SIZE(s->timer); i++) {
36
+ if (strcmp(cpu, valid_cpus[i]) == 0) {
380
+ if (value & (1U << i)) {
37
+ return true;
381
+ npcm7xx_timer_check_interrupt(&s->timer[i]);
382
+ }
38
+ }
383
+ }
39
+ }
40
+ return false;
384
+}
41
+}
385
+
42
+
386
+static hwaddr npcm7xx_tcsr_index(hwaddr reg)
43
static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx)
387
+{
44
{
388
+ switch (reg) {
45
uint8_t clustersz = ARM_DEFAULT_CPUS_PER_CLUSTER;
389
+ case NPCM7XX_TIMER_TCSR0:
46
@@ -XXX,XX +XXX,XX @@ static void sbsa_ref_init(MachineState *machine)
390
+ return 0;
47
const CPUArchIdList *possible_cpus;
391
+ case NPCM7XX_TIMER_TCSR1:
48
int n, sbsa_max_cpus;
392
+ return 1;
49
393
+ case NPCM7XX_TIMER_TCSR2:
50
- if (strcmp(machine->cpu_type, ARM_CPU_TYPE_NAME("cortex-a57"))) {
394
+ return 2;
51
- error_report("sbsa-ref: CPU type other than the built-in "
395
+ case NPCM7XX_TIMER_TCSR3:
52
- "cortex-a57 not supported");
396
+ return 3;
53
+ if (!cpu_type_valid(machine->cpu_type)) {
397
+ case NPCM7XX_TIMER_TCSR4:
54
+ error_report("mach-virt: CPU type %s not supported", machine->cpu_type);
398
+ return 4;
55
exit(1);
399
+ default:
56
}
400
+ g_assert_not_reached();
57
401
+ }
402
+}
403
+
404
+static hwaddr npcm7xx_ticr_index(hwaddr reg)
405
+{
406
+ switch (reg) {
407
+ case NPCM7XX_TIMER_TICR0:
408
+ return 0;
409
+ case NPCM7XX_TIMER_TICR1:
410
+ return 1;
411
+ case NPCM7XX_TIMER_TICR2:
412
+ return 2;
413
+ case NPCM7XX_TIMER_TICR3:
414
+ return 3;
415
+ case NPCM7XX_TIMER_TICR4:
416
+ return 4;
417
+ default:
418
+ g_assert_not_reached();
419
+ }
420
+}
421
+
422
+static hwaddr npcm7xx_tdr_index(hwaddr reg)
423
+{
424
+ switch (reg) {
425
+ case NPCM7XX_TIMER_TDR0:
426
+ return 0;
427
+ case NPCM7XX_TIMER_TDR1:
428
+ return 1;
429
+ case NPCM7XX_TIMER_TDR2:
430
+ return 2;
431
+ case NPCM7XX_TIMER_TDR3:
432
+ return 3;
433
+ case NPCM7XX_TIMER_TDR4:
434
+ return 4;
435
+ default:
436
+ g_assert_not_reached();
437
+ }
438
+}
439
+
440
+static uint64_t npcm7xx_timer_read(void *opaque, hwaddr offset, unsigned size)
441
+{
442
+ NPCM7xxTimerCtrlState *s = opaque;
443
+ uint64_t value = 0;
444
+ hwaddr reg;
445
+
446
+ reg = offset / sizeof(uint32_t);
447
+ switch (reg) {
448
+ case NPCM7XX_TIMER_TCSR0:
449
+ case NPCM7XX_TIMER_TCSR1:
450
+ case NPCM7XX_TIMER_TCSR2:
451
+ case NPCM7XX_TIMER_TCSR3:
452
+ case NPCM7XX_TIMER_TCSR4:
453
+ value = s->timer[npcm7xx_tcsr_index(reg)].tcsr;
454
+ break;
455
+
456
+ case NPCM7XX_TIMER_TICR0:
457
+ case NPCM7XX_TIMER_TICR1:
458
+ case NPCM7XX_TIMER_TICR2:
459
+ case NPCM7XX_TIMER_TICR3:
460
+ case NPCM7XX_TIMER_TICR4:
461
+ value = s->timer[npcm7xx_ticr_index(reg)].ticr;
462
+ break;
463
+
464
+ case NPCM7XX_TIMER_TDR0:
465
+ case NPCM7XX_TIMER_TDR1:
466
+ case NPCM7XX_TIMER_TDR2:
467
+ case NPCM7XX_TIMER_TDR3:
468
+ case NPCM7XX_TIMER_TDR4:
469
+ value = npcm7xx_timer_read_tdr(&s->timer[npcm7xx_tdr_index(reg)]);
470
+ break;
471
+
472
+ case NPCM7XX_TIMER_TISR:
473
+ value = s->tisr;
474
+ break;
475
+
476
+ case NPCM7XX_TIMER_WTCR:
477
+ value = s->wtcr;
478
+ break;
479
+
480
+ default:
481
+ qemu_log_mask(LOG_GUEST_ERROR,
482
+ "%s: invalid offset 0x%04" HWADDR_PRIx "\n",
483
+ __func__, offset);
484
+ break;
485
+ }
486
+
487
+ trace_npcm7xx_timer_read(DEVICE(s)->canonical_path, offset, value);
488
+
489
+ return value;
490
+}
491
+
492
+static void npcm7xx_timer_write(void *opaque, hwaddr offset,
493
+ uint64_t v, unsigned size)
494
+{
495
+ uint32_t reg = offset / sizeof(uint32_t);
496
+ NPCM7xxTimerCtrlState *s = opaque;
497
+ uint32_t value = v;
498
+
499
+ trace_npcm7xx_timer_write(DEVICE(s)->canonical_path, offset, value);
500
+
501
+ switch (reg) {
502
+ case NPCM7XX_TIMER_TCSR0:
503
+ case NPCM7XX_TIMER_TCSR1:
504
+ case NPCM7XX_TIMER_TCSR2:
505
+ case NPCM7XX_TIMER_TCSR3:
506
+ case NPCM7XX_TIMER_TCSR4:
507
+ npcm7xx_timer_write_tcsr(&s->timer[npcm7xx_tcsr_index(reg)], value);
508
+ return;
509
+
510
+ case NPCM7XX_TIMER_TICR0:
511
+ case NPCM7XX_TIMER_TICR1:
512
+ case NPCM7XX_TIMER_TICR2:
513
+ case NPCM7XX_TIMER_TICR3:
514
+ case NPCM7XX_TIMER_TICR4:
515
+ npcm7xx_timer_write_ticr(&s->timer[npcm7xx_ticr_index(reg)], value);
516
+ return;
517
+
518
+ case NPCM7XX_TIMER_TDR0:
519
+ case NPCM7XX_TIMER_TDR1:
520
+ case NPCM7XX_TIMER_TDR2:
521
+ case NPCM7XX_TIMER_TDR3:
522
+ case NPCM7XX_TIMER_TDR4:
523
+ qemu_log_mask(LOG_GUEST_ERROR,
524
+ "%s: register @ 0x%04" HWADDR_PRIx " is read-only\n",
525
+ __func__, offset);
526
+ return;
527
+
528
+ case NPCM7XX_TIMER_TISR:
529
+ npcm7xx_timer_write_tisr(s, value);
530
+ return;
531
+
532
+ case NPCM7XX_TIMER_WTCR:
533
+ qemu_log_mask(LOG_UNIMP, "%s: WTCR write not implemented: 0x%08x\n",
534
+ __func__, value);
535
+ return;
536
+ }
537
+
538
+ qemu_log_mask(LOG_GUEST_ERROR,
539
+ "%s: invalid offset 0x%04" HWADDR_PRIx "\n",
540
+ __func__, offset);
541
+}
542
+
543
+static const struct MemoryRegionOps npcm7xx_timer_ops = {
544
+ .read = npcm7xx_timer_read,
545
+ .write = npcm7xx_timer_write,
546
+ .endianness = DEVICE_LITTLE_ENDIAN,
547
+ .valid = {
548
+ .min_access_size = 4,
549
+ .max_access_size = 4,
550
+ .unaligned = false,
551
+ },
552
+};
553
+
554
+/* Called when the QEMU timer expires. */
555
+static void npcm7xx_timer_expired(void *opaque)
556
+{
557
+ NPCM7xxTimer *t = opaque;
558
+
559
+ if (t->tcsr & NPCM7XX_TCSR_CEN) {
560
+ npcm7xx_timer_reached_zero(t);
561
+ }
562
+}
563
+
564
+static void npcm7xx_timer_enter_reset(Object *obj, ResetType type)
565
+{
566
+ NPCM7xxTimerCtrlState *s = NPCM7XX_TIMER(obj);
567
+ int i;
568
+
569
+ for (i = 0; i < NPCM7XX_TIMERS_PER_CTRL; i++) {
570
+ NPCM7xxTimer *t = &s->timer[i];
571
+
572
+ timer_del(&t->qtimer);
573
+ t->expires_ns = 0;
574
+ t->remaining_ns = 0;
575
+ t->tcsr = 0x00000005;
576
+ t->ticr = 0x00000000;
577
+ }
578
+
579
+ s->tisr = 0x00000000;
580
+ s->wtcr = 0x00000400;
581
+}
582
+
583
+static void npcm7xx_timer_hold_reset(Object *obj)
584
+{
585
+ NPCM7xxTimerCtrlState *s = NPCM7XX_TIMER(obj);
586
+ int i;
587
+
588
+ for (i = 0; i < NPCM7XX_TIMERS_PER_CTRL; i++) {
589
+ qemu_irq_lower(s->timer[i].irq);
590
+ }
591
+}
592
+
593
+static void npcm7xx_timer_realize(DeviceState *dev, Error **errp)
594
+{
595
+ NPCM7xxTimerCtrlState *s = NPCM7XX_TIMER(dev);
596
+ SysBusDevice *sbd = &s->parent;
597
+ int i;
598
+
599
+ for (i = 0; i < NPCM7XX_TIMERS_PER_CTRL; i++) {
600
+ NPCM7xxTimer *t = &s->timer[i];
601
+ t->ctrl = s;
602
+ timer_init_ns(&t->qtimer, QEMU_CLOCK_VIRTUAL, npcm7xx_timer_expired, t);
603
+ sysbus_init_irq(sbd, &t->irq);
604
+ }
605
+
606
+ memory_region_init_io(&s->iomem, OBJECT(s), &npcm7xx_timer_ops, s,
607
+ TYPE_NPCM7XX_TIMER, 4 * KiB);
608
+ sysbus_init_mmio(sbd, &s->iomem);
609
+}
610
+
611
+static const VMStateDescription vmstate_npcm7xx_timer = {
612
+ .name = "npcm7xx-timer",
613
+ .version_id = 0,
614
+ .minimum_version_id = 0,
615
+ .fields = (VMStateField[]) {
616
+ VMSTATE_TIMER(qtimer, NPCM7xxTimer),
617
+ VMSTATE_INT64(expires_ns, NPCM7xxTimer),
618
+ VMSTATE_INT64(remaining_ns, NPCM7xxTimer),
619
+ VMSTATE_UINT32(tcsr, NPCM7xxTimer),
620
+ VMSTATE_UINT32(ticr, NPCM7xxTimer),
621
+ VMSTATE_END_OF_LIST(),
622
+ },
623
+};
624
+
625
+static const VMStateDescription vmstate_npcm7xx_timer_ctrl = {
626
+ .name = "npcm7xx-timer-ctrl",
627
+ .version_id = 0,
628
+ .minimum_version_id = 0,
629
+ .fields = (VMStateField[]) {
630
+ VMSTATE_UINT32(tisr, NPCM7xxTimerCtrlState),
631
+ VMSTATE_UINT32(wtcr, NPCM7xxTimerCtrlState),
632
+ VMSTATE_STRUCT_ARRAY(timer, NPCM7xxTimerCtrlState,
633
+ NPCM7XX_TIMERS_PER_CTRL, 0, vmstate_npcm7xx_timer,
634
+ NPCM7xxTimer),
635
+ VMSTATE_END_OF_LIST(),
636
+ },
637
+};
638
+
639
+static void npcm7xx_timer_class_init(ObjectClass *klass, void *data)
640
+{
641
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
642
+ DeviceClass *dc = DEVICE_CLASS(klass);
643
+
644
+ QEMU_BUILD_BUG_ON(NPCM7XX_TIMER_REGS_END > NPCM7XX_TIMER_NR_REGS);
645
+
646
+ dc->desc = "NPCM7xx Timer Controller";
647
+ dc->realize = npcm7xx_timer_realize;
648
+ dc->vmsd = &vmstate_npcm7xx_timer_ctrl;
649
+ rc->phases.enter = npcm7xx_timer_enter_reset;
650
+ rc->phases.hold = npcm7xx_timer_hold_reset;
651
+}
652
+
653
+static const TypeInfo npcm7xx_timer_info = {
654
+ .name = TYPE_NPCM7XX_TIMER,
655
+ .parent = TYPE_SYS_BUS_DEVICE,
656
+ .instance_size = sizeof(NPCM7xxTimerCtrlState),
657
+ .class_init = npcm7xx_timer_class_init,
658
+};
659
+
660
+static void npcm7xx_timer_register_type(void)
661
+{
662
+ type_register_static(&npcm7xx_timer_info);
663
+}
664
+type_init(npcm7xx_timer_register_type);
665
diff --git a/hw/timer/meson.build b/hw/timer/meson.build
666
index XXXXXXX..XXXXXXX 100644
667
--- a/hw/timer/meson.build
668
+++ b/hw/timer/meson.build
669
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_LM32', if_true: files('lm32_timer.c'))
670
softmmu_ss.add(when: 'CONFIG_MILKYMIST', if_true: files('milkymist-sysctl.c'))
671
softmmu_ss.add(when: 'CONFIG_MIPS_CPS', if_true: files('mips_gictimer.c'))
672
softmmu_ss.add(when: 'CONFIG_MSF2', if_true: files('mss-timer.c'))
673
+softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_timer.c'))
674
softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_timer.c'))
675
softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_gptimer.c'))
676
softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_synctimer.c'))
677
diff --git a/hw/timer/trace-events b/hw/timer/trace-events
678
index XXXXXXX..XXXXXXX 100644
679
--- a/hw/timer/trace-events
680
+++ b/hw/timer/trace-events
681
@@ -XXX,XX +XXX,XX @@ cmsdk_apb_dualtimer_read(uint64_t offset, uint64_t data, unsigned size) "CMSDK A
682
cmsdk_apb_dualtimer_write(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB dualtimer write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
683
cmsdk_apb_dualtimer_reset(void) "CMSDK APB dualtimer: reset"
684
685
+# npcm7xx_timer.c
686
+npcm7xx_timer_read(const char *id, uint64_t offset, uint64_t value) " %s offset: 0x%04" PRIx64 " value 0x%08" PRIx64
687
+npcm7xx_timer_write(const char *id, uint64_t offset, uint64_t value) "%s offset: 0x%04" PRIx64 " value 0x%08" PRIx64
688
+npcm7xx_timer_irq(const char *id, int timer, int state) "%s timer %d state %d"
689
+
690
# nrf51_timer.c
691
nrf51_timer_read(uint8_t timer_id, uint64_t addr, uint32_t value, unsigned size) "timer %u read addr 0x%" PRIx64 " data 0x%" PRIx32 " size %u"
692
nrf51_timer_write(uint8_t timer_id, uint64_t addr, uint32_t value, unsigned size) "timer %u write addr 0x%" PRIx64 " data 0x%" PRIx32 " size %u"
693
--
58
--
694
2.20.1
59
2.20.1
695
60
696
61
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Havard Skinnemoen <hskinnemoen@google.com>
2
2
3
If a -bios option is specified on the command line, load the image into
3
Dump the collected random data after a randomness test failure.
4
the internal ROM memory region, which contains the first instructions
5
run by the CPU after reset.
6
4
7
If -bios is not specified, the vbootrom included with qemu is loaded by
5
Note that this relies on the test having called
8
default.
6
g_test_set_nonfatal_assertions() so we don't abort immediately on the
7
assertion failure.
9
8
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>
9
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
15
Message-id: 20200911052101.2602693-8-hskinnemoen@google.com
10
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
11
[PMM: minor commit message tweak]
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
---
13
---
18
hw/arm/npcm7xx_boards.c | 32 ++++++++++++++++++++++++++++++++
14
tests/qtest/npcm7xx_rng-test.c | 12 ++++++++++++
19
1 file changed, 32 insertions(+)
15
1 file changed, 12 insertions(+)
20
16
21
diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c
17
diff --git a/tests/qtest/npcm7xx_rng-test.c b/tests/qtest/npcm7xx_rng-test.c
22
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
23
--- a/hw/arm/npcm7xx_boards.c
19
--- a/tests/qtest/npcm7xx_rng-test.c
24
+++ b/hw/arm/npcm7xx_boards.c
20
+++ b/tests/qtest/npcm7xx_rng-test.c
25
@@ -XXX,XX +XXX,XX @@
21
@@ -XXX,XX +XXX,XX @@
26
#include "exec/address-spaces.h"
22
27
#include "hw/arm/npcm7xx.h"
23
#include "libqtest-single.h"
28
#include "hw/core/cpu.h"
24
#include "qemu/bitops.h"
29
+#include "hw/loader.h"
30
#include "qapi/error.h"
31
+#include "qemu-common.h"
25
+#include "qemu-common.h"
32
#include "qemu/units.h"
26
33
+#include "sysemu/sysemu.h"
27
#define RNG_BASE_ADDR 0xf000b000
34
28
35
#define NPCM750_EVB_POWER_ON_STRAPS 0x00001ff7
29
@@ -XXX,XX +XXX,XX @@
36
#define QUANTA_GSJ_POWER_ON_STRAPS 0x00001fff
30
/* Number of bits to collect for randomness tests. */
37
31
#define TEST_INPUT_BITS (128)
38
+static const char npcm7xx_default_bootrom[] = "npcm7xx_bootrom.bin";
32
39
+
33
+static void dump_buf_if_failed(const uint8_t *buf, size_t size)
40
+static void npcm7xx_load_bootrom(MachineState *machine, NPCM7xxState *soc)
41
+{
34
+{
42
+ g_autofree char *filename = NULL;
35
+ if (g_test_failed()) {
43
+ int ret;
36
+ qemu_hexdump(stderr, "", buf, size);
44
+
45
+ if (!bios_name) {
46
+ bios_name = npcm7xx_default_bootrom;
47
+ }
48
+
49
+ filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
50
+ if (!filename) {
51
+ error_report("Could not find ROM image '%s'", bios_name);
52
+ if (!machine->kernel_filename) {
53
+ /* We can't boot without a bootrom or a kernel image. */
54
+ exit(1);
55
+ }
56
+ return;
57
+ }
58
+ ret = load_image_mr(filename, &soc->irom);
59
+ if (ret < 0) {
60
+ error_report("Failed to load ROM image '%s'", filename);
61
+ exit(1);
62
+ }
37
+ }
63
+}
38
+}
64
+
39
+
65
static void npcm7xx_connect_dram(NPCM7xxState *soc, MemoryRegion *dram)
40
static void rng_writeb(unsigned int offset, uint8_t value)
66
{
41
{
67
memory_region_add_subregion(get_system_memory(), NPCM7XX_DRAM_BA, dram);
42
writeb(RNG_BASE_ADDR + offset, value);
68
@@ -XXX,XX +XXX,XX @@ static void npcm750_evb_init(MachineState *machine)
43
@@ -XXX,XX +XXX,XX @@ static void test_continuous_monobit(void)
69
npcm7xx_connect_dram(soc, machine->ram);
44
}
70
qdev_realize(DEVICE(soc), NULL, &error_fatal);
45
71
46
g_assert_cmpfloat(calc_monobit_p(buf, sizeof(buf)), >, 0.01);
72
+ npcm7xx_load_bootrom(machine, soc);
47
+ dump_buf_if_failed(buf, sizeof(buf));
73
npcm7xx_load_kernel(machine, soc);
74
}
48
}
75
49
76
@@ -XXX,XX +XXX,XX @@ static void quanta_gsj_init(MachineState *machine)
50
/*
77
npcm7xx_connect_dram(soc, machine->ram);
51
@@ -XXX,XX +XXX,XX @@ static void test_continuous_runs(void)
78
qdev_realize(DEVICE(soc), NULL, &error_fatal);
52
}
79
53
80
+ npcm7xx_load_bootrom(machine, soc);
54
g_assert_cmpfloat(calc_runs_p(buf.l, sizeof(buf) * BITS_PER_BYTE), >, 0.01);
81
npcm7xx_load_kernel(machine, soc);
55
+ dump_buf_if_failed(buf.c, sizeof(buf));
82
}
56
}
83
57
58
/*
59
@@ -XXX,XX +XXX,XX @@ static void test_first_byte_monobit(void)
60
}
61
62
g_assert_cmpfloat(calc_monobit_p(buf, sizeof(buf)), >, 0.01);
63
+ dump_buf_if_failed(buf, sizeof(buf));
64
}
65
66
/*
67
@@ -XXX,XX +XXX,XX @@ static void test_first_byte_runs(void)
68
}
69
70
g_assert_cmpfloat(calc_runs_p(buf.l, sizeof(buf) * BITS_PER_BYTE), >, 0.01);
71
+ dump_buf_if_failed(buf.c, sizeof(buf));
72
}
73
74
int main(int argc, char **argv)
84
--
75
--
85
2.20.1
76
2.20.1
86
77
87
78
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Alex Chen <alex.chen@huawei.com>
2
2
3
This model implementation is designed for 32-bit accesses.
3
We should use printf format specifier "%u" instead of "%d" for
4
We can simplify setting the MemoryRegionOps::impl min/max
4
argument of type "unsigned int".
5
fields to 32-bit (memory::access_with_adjusted_size() will
6
take care of the 8/16-bit accesses).
7
5
8
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Reported-by: Euler Robot <euler.robot@huawei.com>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Signed-off-by: Alex Chen <alex.chen@huawei.com>
10
Message-id: 20200901144100.116742-4-f4bug@amsat.org
8
Message-id: 20201126111109.112238-2-alex.chen@huawei.com
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
11
---
13
hw/misc/a9scu.c | 16 +++++-----------
12
hw/misc/imx25_ccm.c | 12 ++++++------
14
1 file changed, 5 insertions(+), 11 deletions(-)
13
1 file changed, 6 insertions(+), 6 deletions(-)
15
14
16
diff --git a/hw/misc/a9scu.c b/hw/misc/a9scu.c
15
diff --git a/hw/misc/imx25_ccm.c b/hw/misc/imx25_ccm.c
17
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/misc/a9scu.c
17
--- a/hw/misc/imx25_ccm.c
19
+++ b/hw/misc/a9scu.c
18
+++ b/hw/misc/imx25_ccm.c
20
@@ -XXX,XX +XXX,XX @@ static uint64_t a9_scu_read(void *opaque, hwaddr offset,
19
@@ -XXX,XX +XXX,XX @@ static const char *imx25_ccm_reg_name(uint32_t reg)
21
return (((1 << s->num_cpu) - 1) << 4) | (s->num_cpu - 1);
20
case IMX25_CCM_LPIMR1_REG:
22
case 0x08: /* CPU Power Status */
21
return "lpimr1";
23
return s->status;
22
default:
24
- case 0x09: /* CPU status. */
23
- sprintf(unknown, "[%d ?]", reg);
25
- return s->status >> 8;
24
+ sprintf(unknown, "[%u ?]", reg);
26
- case 0x0a: /* CPU status. */
25
return unknown;
27
- return s->status >> 16;
26
}
28
- case 0x0b: /* CPU status. */
27
}
29
- return s->status >> 24;
28
@@ -XXX,XX +XXX,XX @@ static uint32_t imx25_ccm_get_mpll_clk(IMXCCMState *dev)
30
case 0x0c: /* Invalidate All Registers In Secure State */
29
freq = imx_ccm_calc_pll(s->reg[IMX25_CCM_MPCTL_REG], CKIH_FREQ);
31
return 0;
30
}
32
case 0x40: /* Filtering Start Address Register */
31
33
@@ -XXX,XX +XXX,XX @@ static void a9_scu_write(void *opaque, hwaddr offset,
32
- DPRINTF("freq = %d\n", freq);
34
uint64_t value, unsigned size)
33
+ DPRINTF("freq = %u\n", freq);
35
{
34
36
A9SCUState *s = (A9SCUState *)opaque;
35
return freq;
37
- uint32_t mask = MAKE_64BIT_MASK(0, size * 8);
36
}
38
- uint32_t shift;
37
@@ -XXX,XX +XXX,XX @@ static uint32_t imx25_ccm_get_mcu_clk(IMXCCMState *dev)
39
38
40
switch (offset) {
39
freq = freq / (1 + EXTRACT(s->reg[IMX25_CCM_CCTL_REG], ARM_CLK_DIV));
41
case 0x00: /* Control */
40
42
@@ -XXX,XX +XXX,XX @@ static void a9_scu_write(void *opaque, hwaddr offset,
41
- DPRINTF("freq = %d\n", freq);
43
case 0x4: /* Configuration: RO */
42
+ DPRINTF("freq = %u\n", freq);
43
44
return freq;
45
}
46
@@ -XXX,XX +XXX,XX @@ static uint32_t imx25_ccm_get_ahb_clk(IMXCCMState *dev)
47
freq = imx25_ccm_get_mcu_clk(dev)
48
/ (1 + EXTRACT(s->reg[IMX25_CCM_CCTL_REG], AHB_CLK_DIV));
49
50
- DPRINTF("freq = %d\n", freq);
51
+ DPRINTF("freq = %u\n", freq);
52
53
return freq;
54
}
55
@@ -XXX,XX +XXX,XX @@ static uint32_t imx25_ccm_get_ipg_clk(IMXCCMState *dev)
56
57
freq = imx25_ccm_get_ahb_clk(dev) / 2;
58
59
- DPRINTF("freq = %d\n", freq);
60
+ DPRINTF("freq = %u\n", freq);
61
62
return freq;
63
}
64
@@ -XXX,XX +XXX,XX @@ static uint32_t imx25_ccm_get_clock_frequency(IMXCCMState *dev, IMXClk clock)
44
break;
65
break;
45
case 0x08: case 0x09: case 0x0A: case 0x0B: /* Power Control */
66
}
46
- shift = (offset - 0x8) * 8;
67
47
- s->status &= ~(mask << shift);
68
- DPRINTF("Clock = %d) = %d\n", clock, freq);
48
- s->status |= ((value & mask) << shift);
69
+ DPRINTF("Clock = %d) = %u\n", clock, freq);
49
+ s->status = value;
70
50
break;
71
return freq;
51
case 0x0c: /* Invalidate All Registers In Secure State */
72
}
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,
64
--
73
--
65
2.20.1
74
2.20.1
66
75
67
76
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Alex Chen <alex.chen@huawei.com>
2
2
3
This allows these NPCM7xx-based boards to boot from a flash image, e.g.
3
We should use printf format specifier "%u" instead of "%d" for
4
one built with OpenBMC. For example like this:
4
argument of type "unsigned int".
5
5
6
IMAGE=${OPENBMC}/build/tmp/deploy/images/gsj/image-bmc
6
Reported-by: Euler Robot <euler.robot@huawei.com>
7
qemu-system-arm -machine quanta-gsj -nographic \
7
Signed-off-by: Alex Chen <alex.chen@huawei.com>
8
    -drive file=${IMAGE},if=mtd,bus=0,unit=0,format=raw,snapshot=on
8
Message-id: 20201126111109.112238-3-alex.chen@huawei.com
9
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
10
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
11
Reviewed-by: Cédric Le Goater <clg@kaod.org>
12
Tested-by: Cédric Le Goater <clg@kaod.org>
13
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
14
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
15
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
16
Message-id: 20200911052101.2602693-12-hskinnemoen@google.com
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
18
---
11
---
19
hw/arm/npcm7xx_boards.c | 20 ++++++++++++++++++++
12
hw/misc/imx31_ccm.c | 14 +++++++-------
20
1 file changed, 20 insertions(+)
13
hw/misc/imx_ccm.c | 4 ++--
14
2 files changed, 9 insertions(+), 9 deletions(-)
21
15
22
diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c
16
diff --git a/hw/misc/imx31_ccm.c b/hw/misc/imx31_ccm.c
23
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
24
--- a/hw/arm/npcm7xx_boards.c
18
--- a/hw/misc/imx31_ccm.c
25
+++ b/hw/arm/npcm7xx_boards.c
19
+++ b/hw/misc/imx31_ccm.c
26
@@ -XXX,XX +XXX,XX @@
20
@@ -XXX,XX +XXX,XX @@ static const char *imx31_ccm_reg_name(uint32_t reg)
27
#include "hw/arm/npcm7xx.h"
21
case IMX31_CCM_PDR2_REG:
28
#include "hw/core/cpu.h"
22
return "PDR2";
29
#include "hw/loader.h"
23
default:
30
+#include "hw/qdev-properties.h"
24
- sprintf(unknown, "[%d ?]", reg);
31
#include "qapi/error.h"
25
+ sprintf(unknown, "[%u ?]", reg);
32
#include "qemu-common.h"
26
return unknown;
33
#include "qemu/units.h"
34
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_load_bootrom(MachineState *machine, NPCM7xxState *soc)
35
}
27
}
36
}
28
}
37
29
@@ -XXX,XX +XXX,XX @@ static uint32_t imx31_ccm_get_pll_ref_clk(IMXCCMState *dev)
38
+static void npcm7xx_connect_flash(NPCM7xxFIUState *fiu, int cs_no,
30
freq = CKIH_FREQ;
39
+ const char *flash_type, DriveInfo *dinfo)
31
}
40
+{
32
41
+ DeviceState *flash;
33
- DPRINTF("freq = %d\n", freq);
42
+ qemu_irq flash_cs;
34
+ DPRINTF("freq = %u\n", freq);
43
+
35
44
+ flash = qdev_new(flash_type);
36
return freq;
45
+ if (dinfo) {
46
+ qdev_prop_set_drive(flash, "drive", blk_by_legacy_dinfo(dinfo));
47
+ }
48
+ qdev_realize_and_unref(flash, BUS(fiu->spi), &error_fatal);
49
+
50
+ flash_cs = qdev_get_gpio_in_named(flash, SSI_GPIO_CS, 0);
51
+ qdev_connect_gpio_out_named(DEVICE(fiu), "cs", cs_no, flash_cs);
52
+}
53
+
54
static void npcm7xx_connect_dram(NPCM7xxState *soc, MemoryRegion *dram)
55
{
56
memory_region_add_subregion(get_system_memory(), NPCM7XX_DRAM_BA, dram);
57
@@ -XXX,XX +XXX,XX @@ static void npcm750_evb_init(MachineState *machine)
58
qdev_realize(DEVICE(soc), NULL, &error_fatal);
59
60
npcm7xx_load_bootrom(machine, soc);
61
+ npcm7xx_connect_flash(&soc->fiu[0], 0, "w25q256", drive_get(IF_MTD, 0, 0));
62
npcm7xx_load_kernel(machine, soc);
63
}
37
}
64
38
@@ -XXX,XX +XXX,XX @@ static uint32_t imx31_ccm_get_mpll_clk(IMXCCMState *dev)
65
@@ -XXX,XX +XXX,XX @@ static void quanta_gsj_init(MachineState *machine)
39
freq = imx_ccm_calc_pll(s->reg[IMX31_CCM_MPCTL_REG],
66
qdev_realize(DEVICE(soc), NULL, &error_fatal);
40
imx31_ccm_get_pll_ref_clk(dev));
67
41
68
npcm7xx_load_bootrom(machine, soc);
42
- DPRINTF("freq = %d\n", freq);
69
+ npcm7xx_connect_flash(&soc->fiu[0], 0, "mx25l25635e",
43
+ DPRINTF("freq = %u\n", freq);
70
+ drive_get(IF_MTD, 0, 0));
44
71
npcm7xx_load_kernel(machine, soc);
45
return freq;
72
}
46
}
73
47
@@ -XXX,XX +XXX,XX @@ static uint32_t imx31_ccm_get_mcu_main_clk(IMXCCMState *dev)
48
freq = imx31_ccm_get_mpll_clk(dev);
49
}
50
51
- DPRINTF("freq = %d\n", freq);
52
+ DPRINTF("freq = %u\n", freq);
53
54
return freq;
55
}
56
@@ -XXX,XX +XXX,XX @@ static uint32_t imx31_ccm_get_hclk_clk(IMXCCMState *dev)
57
freq = imx31_ccm_get_mcu_main_clk(dev)
58
/ (1 + EXTRACT(s->reg[IMX31_CCM_PDR0_REG], MAX));
59
60
- DPRINTF("freq = %d\n", freq);
61
+ DPRINTF("freq = %u\n", freq);
62
63
return freq;
64
}
65
@@ -XXX,XX +XXX,XX @@ static uint32_t imx31_ccm_get_ipg_clk(IMXCCMState *dev)
66
freq = imx31_ccm_get_hclk_clk(dev)
67
/ (1 + EXTRACT(s->reg[IMX31_CCM_PDR0_REG], IPG));
68
69
- DPRINTF("freq = %d\n", freq);
70
+ DPRINTF("freq = %u\n", freq);
71
72
return freq;
73
}
74
@@ -XXX,XX +XXX,XX @@ static uint32_t imx31_ccm_get_clock_frequency(IMXCCMState *dev, IMXClk clock)
75
break;
76
}
77
78
- DPRINTF("Clock = %d) = %d\n", clock, freq);
79
+ DPRINTF("Clock = %d) = %u\n", clock, freq);
80
81
return freq;
82
}
83
diff --git a/hw/misc/imx_ccm.c b/hw/misc/imx_ccm.c
84
index XXXXXXX..XXXXXXX 100644
85
--- a/hw/misc/imx_ccm.c
86
+++ b/hw/misc/imx_ccm.c
87
@@ -XXX,XX +XXX,XX @@ uint32_t imx_ccm_get_clock_frequency(IMXCCMState *dev, IMXClk clock)
88
freq = klass->get_clock_frequency(dev, clock);
89
}
90
91
- DPRINTF("(clock = %d) = %d\n", clock, freq);
92
+ DPRINTF("(clock = %d) = %u\n", clock, freq);
93
94
return freq;
95
}
96
@@ -XXX,XX +XXX,XX @@ uint32_t imx_ccm_calc_pll(uint32_t pllreg, uint32_t base_freq)
97
freq = ((2 * (base_freq >> 10) * (mfi * mfd + mfn)) /
98
(mfd * pd)) << 10;
99
100
- DPRINTF("(pllreg = 0x%08x, base_freq = %d) = %d\n", pllreg, base_freq,
101
+ DPRINTF("(pllreg = 0x%08x, base_freq = %u) = %d\n", pllreg, base_freq,
102
freq);
103
104
return freq;
74
--
105
--
75
2.20.1
106
2.20.1
76
107
77
108
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Alex Chen <alex.chen@huawei.com>
2
2
3
Per the datasheet (DDI0407 r2p0):
3
We should use printf format specifier "%u" instead of "%d" for
4
argument of type "unsigned int".
4
5
5
"All SCU registers are byte accessible" and are 32-bit aligned.
6
Reported-by: Euler Robot <euler.robot@huawei.com>
6
7
Signed-off-by: Alex Chen <alex.chen@huawei.com>
7
Set MemoryRegionOps::valid min/max fields and simplify the write()
8
Message-id: 20201126111109.112238-4-alex.chen@huawei.com
8
handler.
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
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
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
---
11
---
15
hw/misc/a9scu.c | 21 +++++----------------
12
hw/misc/imx6_ccm.c | 20 ++++++++++----------
16
1 file changed, 5 insertions(+), 16 deletions(-)
13
hw/misc/imx6_src.c | 2 +-
14
2 files changed, 11 insertions(+), 11 deletions(-)
17
15
18
diff --git a/hw/misc/a9scu.c b/hw/misc/a9scu.c
16
diff --git a/hw/misc/imx6_ccm.c b/hw/misc/imx6_ccm.c
19
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
20
--- a/hw/misc/a9scu.c
18
--- a/hw/misc/imx6_ccm.c
21
+++ b/hw/misc/a9scu.c
19
+++ b/hw/misc/imx6_ccm.c
22
@@ -XXX,XX +XXX,XX @@ static void a9_scu_write(void *opaque, hwaddr offset,
20
@@ -XXX,XX +XXX,XX @@ static const char *imx6_ccm_reg_name(uint32_t reg)
23
uint64_t value, unsigned size)
21
case CCM_CMEOR:
24
{
22
return "CMEOR";
25
A9SCUState *s = (A9SCUState *)opaque;
23
default:
26
- uint32_t mask;
24
- sprintf(unknown, "%d ?", reg);
27
+ uint32_t mask = MAKE_64BIT_MASK(0, size * 8);
25
+ sprintf(unknown, "%u ?", reg);
28
uint32_t shift;
26
return unknown;
29
- switch (size) {
27
}
30
- case 1:
28
}
31
- mask = 0xff;
29
@@ -XXX,XX +XXX,XX @@ static const char *imx6_analog_reg_name(uint32_t reg)
32
- break;
30
case USB_ANALOG_DIGPROG:
33
- case 2:
31
return "USB_ANALOG_DIGPROG";
34
- mask = 0xffff;
32
default:
35
- break;
33
- sprintf(unknown, "%d ?", reg);
36
- case 4:
34
+ sprintf(unknown, "%u ?", reg);
37
- mask = 0xffffffff;
35
return unknown;
38
- break;
36
}
39
- default:
37
}
40
- fprintf(stderr, "Invalid size %u in write to a9 scu register %x\n",
38
@@ -XXX,XX +XXX,XX @@ static uint64_t imx6_analog_get_pll2_clk(IMX6CCMState *dev)
41
- size, (unsigned)offset);
39
freq *= 20;
42
- return;
40
}
43
- }
41
44
42
- DPRINTF("freq = %d\n", (uint32_t)freq);
45
switch (offset) {
43
+ DPRINTF("freq = %u\n", (uint32_t)freq);
46
case 0x00: /* Control */
44
47
@@ -XXX,XX +XXX,XX @@ static void a9_scu_write(void *opaque, hwaddr offset,
45
return freq;
48
static const MemoryRegionOps a9_scu_ops = {
46
}
49
.read = a9_scu_read,
47
@@ -XXX,XX +XXX,XX @@ static uint64_t imx6_analog_get_pll2_pfd0_clk(IMX6CCMState *dev)
50
.write = a9_scu_write,
48
freq = imx6_analog_get_pll2_clk(dev) * 18
51
+ .valid = {
49
/ EXTRACT(dev->analog[CCM_ANALOG_PFD_528], PFD0_FRAC);
52
+ .min_access_size = 1,
50
53
+ .max_access_size = 4,
51
- DPRINTF("freq = %d\n", (uint32_t)freq);
54
+ },
52
+ DPRINTF("freq = %u\n", (uint32_t)freq);
55
.endianness = DEVICE_NATIVE_ENDIAN,
53
56
};
54
return freq;
57
55
}
56
@@ -XXX,XX +XXX,XX @@ static uint64_t imx6_analog_get_pll2_pfd2_clk(IMX6CCMState *dev)
57
freq = imx6_analog_get_pll2_clk(dev) * 18
58
/ EXTRACT(dev->analog[CCM_ANALOG_PFD_528], PFD2_FRAC);
59
60
- DPRINTF("freq = %d\n", (uint32_t)freq);
61
+ DPRINTF("freq = %u\n", (uint32_t)freq);
62
63
return freq;
64
}
65
@@ -XXX,XX +XXX,XX @@ static uint64_t imx6_analog_get_periph_clk(IMX6CCMState *dev)
66
break;
67
}
68
69
- DPRINTF("freq = %d\n", (uint32_t)freq);
70
+ DPRINTF("freq = %u\n", (uint32_t)freq);
71
72
return freq;
73
}
74
@@ -XXX,XX +XXX,XX @@ static uint64_t imx6_ccm_get_ahb_clk(IMX6CCMState *dev)
75
freq = imx6_analog_get_periph_clk(dev)
76
/ (1 + EXTRACT(dev->ccm[CCM_CBCDR], AHB_PODF));
77
78
- DPRINTF("freq = %d\n", (uint32_t)freq);
79
+ DPRINTF("freq = %u\n", (uint32_t)freq);
80
81
return freq;
82
}
83
@@ -XXX,XX +XXX,XX @@ static uint64_t imx6_ccm_get_ipg_clk(IMX6CCMState *dev)
84
freq = imx6_ccm_get_ahb_clk(dev)
85
/ (1 + EXTRACT(dev->ccm[CCM_CBCDR], IPG_PODF));
86
87
- DPRINTF("freq = %d\n", (uint32_t)freq);
88
+ DPRINTF("freq = %u\n", (uint32_t)freq);
89
90
return freq;
91
}
92
@@ -XXX,XX +XXX,XX @@ static uint64_t imx6_ccm_get_per_clk(IMX6CCMState *dev)
93
freq = imx6_ccm_get_ipg_clk(dev)
94
/ (1 + EXTRACT(dev->ccm[CCM_CSCMR1], PERCLK_PODF));
95
96
- DPRINTF("freq = %d\n", (uint32_t)freq);
97
+ DPRINTF("freq = %u\n", (uint32_t)freq);
98
99
return freq;
100
}
101
@@ -XXX,XX +XXX,XX @@ static uint32_t imx6_ccm_get_clock_frequency(IMXCCMState *dev, IMXClk clock)
102
break;
103
}
104
105
- DPRINTF("Clock = %d) = %d\n", clock, freq);
106
+ DPRINTF("Clock = %d) = %u\n", clock, freq);
107
108
return freq;
109
}
110
diff --git a/hw/misc/imx6_src.c b/hw/misc/imx6_src.c
111
index XXXXXXX..XXXXXXX 100644
112
--- a/hw/misc/imx6_src.c
113
+++ b/hw/misc/imx6_src.c
114
@@ -XXX,XX +XXX,XX @@ static const char *imx6_src_reg_name(uint32_t reg)
115
case SRC_GPR10:
116
return "SRC_GPR10";
117
default:
118
- sprintf(unknown, "%d ?", reg);
119
+ sprintf(unknown, "%u ?", reg);
120
return unknown;
121
}
122
}
58
--
123
--
59
2.20.1
124
2.20.1
60
125
61
126
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Alex Chen <alex.chen@huawei.com>
2
2
3
Report unimplemented register accesses using qemu_log_mask(UNIMP).
3
We should use printf format specifier "%u" instead of "%d" for
4
argument of type "unsigned int".
4
5
5
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Reported-by: Euler Robot <euler.robot@huawei.com>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Signed-off-by: Alex Chen <alex.chen@huawei.com>
7
Message-id: 20200901144100.116742-5-f4bug@amsat.org
8
Message-id: 20201126111109.112238-5-alex.chen@huawei.com
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
11
---
10
hw/misc/a9scu.c | 6 ++++++
12
hw/misc/imx6ul_ccm.c | 4 ++--
11
1 file changed, 6 insertions(+)
13
1 file changed, 2 insertions(+), 2 deletions(-)
12
14
13
diff --git a/hw/misc/a9scu.c b/hw/misc/a9scu.c
15
diff --git a/hw/misc/imx6ul_ccm.c b/hw/misc/imx6ul_ccm.c
14
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/misc/a9scu.c
17
--- a/hw/misc/imx6ul_ccm.c
16
+++ b/hw/misc/a9scu.c
18
+++ b/hw/misc/imx6ul_ccm.c
17
@@ -XXX,XX +XXX,XX @@
19
@@ -XXX,XX +XXX,XX @@ static const char *imx6ul_ccm_reg_name(uint32_t reg)
18
#include "hw/qdev-properties.h"
20
case CCM_CMEOR:
19
#include "migration/vmstate.h"
21
return "CMEOR";
20
#include "qapi/error.h"
21
+#include "qemu/log.h"
22
#include "qemu/module.h"
23
24
#define A9_SCU_CPU_MAX 4
25
@@ -XXX,XX +XXX,XX @@ static uint64_t a9_scu_read(void *opaque, hwaddr offset,
26
case 0x54: /* SCU Non-secure Access Control Register */
27
/* unimplemented, fall through */
28
default:
22
default:
29
+ qemu_log_mask(LOG_UNIMP, "%s: Unsupported offset 0x%"HWADDR_PRIx"\n",
23
- sprintf(unknown, "%d ?", reg);
30
+ __func__, offset);
24
+ sprintf(unknown, "%u ?", reg);
31
return 0;
25
return unknown;
32
}
26
}
33
}
27
}
34
@@ -XXX,XX +XXX,XX @@ static void a9_scu_write(void *opaque, hwaddr offset,
28
@@ -XXX,XX +XXX,XX @@ static const char *imx6ul_analog_reg_name(uint32_t reg)
35
case 0x54: /* SCU Non-secure Access Control Register */
29
case USB_ANALOG_DIGPROG:
36
/* unimplemented, fall through */
30
return "USB_ANALOG_DIGPROG";
37
default:
31
default:
38
+ qemu_log_mask(LOG_UNIMP, "%s: Unsupported offset 0x%"HWADDR_PRIx
32
- sprintf(unknown, "%d ?", reg);
39
+ " value 0x%"PRIx64"\n",
33
+ sprintf(unknown, "%u ?", reg);
40
+ __func__, offset, value);
34
return unknown;
41
break;
42
}
35
}
43
}
36
}
44
--
37
--
45
2.20.1
38
2.20.1
46
39
47
40
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
For M-profile CPUs, the range from 0xe0000000 to 0xe00fffff is the
2
Private Peripheral Bus range, which includes all of the memory mapped
3
devices and registers that are part of the CPU itself, including the
4
NVIC, systick timer, and debug and trace components like the Data
5
Watchpoint and Trace unit (DWT). Within this large region, the range
6
0xe000e000 to 0xe000efff is the System Control Space (NVIC, system
7
registers, systick) and 0xe002e000 to 0exe002efff is its Non-secure
8
alias.
2
9
3
This adds two new machines, both supported by OpenBMC:
10
The architecture is clear that within the SCS unimplemented registers
11
should be RES0 for privileged accesses and generate BusFault for
12
unprivileged accesses, and we currently implement this.
4
13
5
- npcm750-evb: Nuvoton NPCM750 Evaluation Board.
14
It is less clear about how to handle accesses to unimplemented
6
- quanta-gsj: A board with a NPCM730 chip.
15
regions of the wider PPB. Unprivileged accesses should definitely
16
cause BusFaults (R_DQQS), but the behaviour of privileged accesses is
17
not given as a general rule. However, the register definitions of
18
individual registers for components like the DWT all state that they
19
are RES0 if the relevant component is not implemented, so the
20
simplest way to provide that is to provide RAZ/WI for the whole range
21
for privileged accesses. (The v7M Arm ARM does say that reserved
22
registers should be UNK/SBZP.)
7
23
8
They rely on the NPCM7xx SoC device to do the heavy lifting. They are
24
Expand the container MemoryRegion that the NVIC exposes so that
9
almost completely identical at the moment, apart from the SoC type,
25
it covers the whole PPB space. This means:
10
which currently only changes the reset contents of one register
26
* moving the address that the ARMV7M device maps it to down by
11
(GCR.MDLR), but they might grow apart a bit more as more functionality
27
0xe000 bytes
12
is added.
28
* moving the off and the offsets within the container of all the
29
subregions forward by 0xe000 bytes
30
* adding a new default MemoryRegion that covers the whole container
31
at a lower priority than anything else and which provides the
32
RAZWI/BusFault behaviour
13
33
14
Both machines can boot the Linux kernel into /bin/sh.
34
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
35
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
36
Message-id: 20201119215617.29887-2-peter.maydell@linaro.org
37
---
38
include/hw/intc/armv7m_nvic.h | 1 +
39
hw/arm/armv7m.c | 2 +-
40
hw/intc/armv7m_nvic.c | 78 ++++++++++++++++++++++++++++++-----
41
3 files changed, 69 insertions(+), 12 deletions(-)
15
42
16
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
43
diff --git a/include/hw/intc/armv7m_nvic.h b/include/hw/intc/armv7m_nvic.h
17
Reviewed-by: Joel Stanley <joel@jms.id.au>
18
Reviewed-by: Cédric Le Goater <clg@kaod.org>
19
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
20
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
21
Tested-by: Alexander Bulekov <alxndr@bu.edu>
22
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
23
Message-id: 20200911052101.2602693-6-hskinnemoen@google.com
24
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
25
---
26
default-configs/arm-softmmu.mak | 1 +
27
include/hw/arm/npcm7xx.h | 19 +++++
28
hw/arm/npcm7xx_boards.c | 145 ++++++++++++++++++++++++++++++++
29
hw/arm/meson.build | 2 +-
30
4 files changed, 166 insertions(+), 1 deletion(-)
31
create mode 100644 hw/arm/npcm7xx_boards.c
32
33
diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
34
index XXXXXXX..XXXXXXX 100644
44
index XXXXXXX..XXXXXXX 100644
35
--- a/default-configs/arm-softmmu.mak
45
--- a/include/hw/intc/armv7m_nvic.h
36
+++ b/default-configs/arm-softmmu.mak
46
+++ b/include/hw/intc/armv7m_nvic.h
37
@@ -XXX,XX +XXX,XX @@ CONFIG_GUMSTIX=y
47
@@ -XXX,XX +XXX,XX @@ struct NVICState {
38
CONFIG_SPITZ=y
48
MemoryRegion systickmem;
39
CONFIG_TOSA=y
49
MemoryRegion systick_ns_mem;
40
CONFIG_Z2=y
50
MemoryRegion container;
41
+CONFIG_NPCM7XX=y
51
+ MemoryRegion defaultmem;
42
CONFIG_COLLIE=y
52
43
CONFIG_ASPEED_SOC=y
53
uint32_t num_irq;
44
CONFIG_NETDUINO2=y
54
qemu_irq excpout;
45
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
55
diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c
46
index XXXXXXX..XXXXXXX 100644
56
index XXXXXXX..XXXXXXX 100644
47
--- a/include/hw/arm/npcm7xx.h
57
--- a/hw/arm/armv7m.c
48
+++ b/include/hw/arm/npcm7xx.h
58
+++ b/hw/arm/armv7m.c
49
@@ -XXX,XX +XXX,XX @@
59
@@ -XXX,XX +XXX,XX @@ static void armv7m_realize(DeviceState *dev, Error **errp)
50
#define NPCM7XX_SMP_BOOTREG_ADDR (0xf080013c) /* GCR.SCRPAD */
60
sysbus_connect_irq(sbd, 0,
51
#define NPCM7XX_GIC_CPU_IF_ADDR (0xf03fe100) /* GIC within A9 */
61
qdev_get_gpio_in(DEVICE(s->cpu), ARM_CPU_IRQ));
52
62
53
+typedef struct NPCM7xxMachine {
63
- memory_region_add_subregion(&s->container, 0xe000e000,
54
+ MachineState parent;
64
+ memory_region_add_subregion(&s->container, 0xe0000000,
55
+} NPCM7xxMachine;
65
sysbus_mmio_get_region(sbd, 0));
56
+
66
57
+#define TYPE_NPCM7XX_MACHINE MACHINE_TYPE_NAME("npcm7xx")
67
for (i = 0; i < ARRAY_SIZE(s->bitband); i++) {
58
+#define NPCM7XX_MACHINE(obj) \
68
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
59
+ OBJECT_CHECK(NPCM7xxMachine, (obj), TYPE_NPCM7XX_MACHINE)
69
index XXXXXXX..XXXXXXX 100644
60
+
70
--- a/hw/intc/armv7m_nvic.c
61
+typedef struct NPCM7xxMachineClass {
71
+++ b/hw/intc/armv7m_nvic.c
62
+ MachineClass parent;
72
@@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps nvic_systick_ops = {
63
+
73
.endianness = DEVICE_NATIVE_ENDIAN,
64
+ const char *soc_type;
74
};
65
+} NPCM7xxMachineClass;
75
66
+
67
+#define NPCM7XX_MACHINE_CLASS(klass) \
68
+ OBJECT_CLASS_CHECK(NPCM7xxMachineClass, (klass), TYPE_NPCM7XX_MACHINE)
69
+#define NPCM7XX_MACHINE_GET_CLASS(obj) \
70
+ OBJECT_GET_CLASS(NPCM7xxMachineClass, (obj), TYPE_NPCM7XX_MACHINE)
71
+
72
typedef struct NPCM7xxState {
73
DeviceState parent;
74
75
diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c
76
new file mode 100644
77
index XXXXXXX..XXXXXXX
78
--- /dev/null
79
+++ b/hw/arm/npcm7xx_boards.c
80
@@ -XXX,XX +XXX,XX @@
81
+/*
76
+/*
82
+ * Machine definitions for boards featuring an NPCM7xx SoC.
77
+ * Unassigned portions of the PPB space are RAZ/WI for privileged
83
+ *
78
+ * accesses, and fault for non-privileged accesses.
84
+ * Copyright 2020 Google LLC
85
+ *
86
+ * This program is free software; you can redistribute it and/or modify it
87
+ * under the terms of the GNU General Public License as published by the
88
+ * Free Software Foundation; either version 2 of the License, or
89
+ * (at your option) any later version.
90
+ *
91
+ * This program is distributed in the hope that it will be useful, but WITHOUT
92
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
93
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
94
+ * for more details.
95
+ */
79
+ */
96
+
80
+static MemTxResult ppb_default_read(void *opaque, hwaddr addr,
97
+#include "qemu/osdep.h"
81
+ uint64_t *data, unsigned size,
98
+
82
+ MemTxAttrs attrs)
99
+#include "exec/address-spaces.h"
100
+#include "hw/arm/npcm7xx.h"
101
+#include "hw/core/cpu.h"
102
+#include "qapi/error.h"
103
+#include "qemu/units.h"
104
+
105
+#define NPCM750_EVB_POWER_ON_STRAPS 0x00001ff7
106
+#define QUANTA_GSJ_POWER_ON_STRAPS 0x00001fff
107
+
108
+static void npcm7xx_connect_dram(NPCM7xxState *soc, MemoryRegion *dram)
109
+{
83
+{
110
+ memory_region_add_subregion(get_system_memory(), NPCM7XX_DRAM_BA, dram);
84
+ qemu_log_mask(LOG_UNIMP, "Read of unassigned area of PPB: offset 0x%x\n",
111
+
85
+ (uint32_t)addr);
112
+ object_property_set_link(OBJECT(soc), "dram-mr", OBJECT(dram),
86
+ if (attrs.user) {
113
+ &error_abort);
87
+ return MEMTX_ERROR;
88
+ }
89
+ *data = 0;
90
+ return MEMTX_OK;
114
+}
91
+}
115
+
92
+
116
+static NPCM7xxState *npcm7xx_create_soc(MachineState *machine,
93
+static MemTxResult ppb_default_write(void *opaque, hwaddr addr,
117
+ uint32_t hw_straps)
94
+ uint64_t value, unsigned size,
95
+ MemTxAttrs attrs)
118
+{
96
+{
119
+ NPCM7xxMachineClass *nmc = NPCM7XX_MACHINE_GET_CLASS(machine);
97
+ qemu_log_mask(LOG_UNIMP, "Write of unassigned area of PPB: offset 0x%x\n",
120
+ MachineClass *mc = &nmc->parent;
98
+ (uint32_t)addr);
121
+ Object *obj;
99
+ if (attrs.user) {
122
+
100
+ return MEMTX_ERROR;
123
+ if (strcmp(machine->cpu_type, mc->default_cpu_type) != 0) {
124
+ error_report("This board can only be used with %s",
125
+ mc->default_cpu_type);
126
+ exit(1);
127
+ }
101
+ }
128
+
102
+ return MEMTX_OK;
129
+ obj = object_new_with_props(nmc->soc_type, OBJECT(machine), "soc",
130
+ &error_abort, NULL);
131
+ object_property_set_uint(obj, "power-on-straps", hw_straps, &error_abort);
132
+
133
+ return NPCM7XX(obj);
134
+}
103
+}
135
+
104
+
136
+static void npcm750_evb_init(MachineState *machine)
105
+static const MemoryRegionOps ppb_default_ops = {
137
+{
106
+ .read_with_attrs = ppb_default_read,
138
+ NPCM7xxState *soc;
107
+ .write_with_attrs = ppb_default_write,
139
+
108
+ .endianness = DEVICE_NATIVE_ENDIAN,
140
+ soc = npcm7xx_create_soc(machine, NPCM750_EVB_POWER_ON_STRAPS);
109
+ .valid.min_access_size = 1,
141
+ npcm7xx_connect_dram(soc, machine->ram);
110
+ .valid.max_access_size = 8,
142
+ qdev_realize(DEVICE(soc), NULL, &error_fatal);
143
+
144
+ npcm7xx_load_kernel(machine, soc);
145
+}
146
+
147
+static void quanta_gsj_init(MachineState *machine)
148
+{
149
+ NPCM7xxState *soc;
150
+
151
+ soc = npcm7xx_create_soc(machine, QUANTA_GSJ_POWER_ON_STRAPS);
152
+ npcm7xx_connect_dram(soc, machine->ram);
153
+ qdev_realize(DEVICE(soc), NULL, &error_fatal);
154
+
155
+ npcm7xx_load_kernel(machine, soc);
156
+}
157
+
158
+static void npcm7xx_set_soc_type(NPCM7xxMachineClass *nmc, const char *type)
159
+{
160
+ NPCM7xxClass *sc = NPCM7XX_CLASS(object_class_by_name(type));
161
+ MachineClass *mc = MACHINE_CLASS(nmc);
162
+
163
+ nmc->soc_type = type;
164
+ mc->default_cpus = mc->min_cpus = mc->max_cpus = sc->num_cpus;
165
+}
166
+
167
+static void npcm7xx_machine_class_init(ObjectClass *oc, void *data)
168
+{
169
+ MachineClass *mc = MACHINE_CLASS(oc);
170
+
171
+ mc->no_floppy = 1;
172
+ mc->no_cdrom = 1;
173
+ mc->no_parallel = 1;
174
+ mc->default_ram_id = "ram";
175
+ mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a9");
176
+}
177
+
178
+/*
179
+ * Schematics:
180
+ * https://github.com/Nuvoton-Israel/nuvoton-info/blob/master/npcm7xx-poleg/evaluation-board/board_deliverables/NPCM750x_EB_ver.A1.1_COMPLETE.pdf
181
+ */
182
+static void npcm750_evb_machine_class_init(ObjectClass *oc, void *data)
183
+{
184
+ NPCM7xxMachineClass *nmc = NPCM7XX_MACHINE_CLASS(oc);
185
+ MachineClass *mc = MACHINE_CLASS(oc);
186
+
187
+ npcm7xx_set_soc_type(nmc, TYPE_NPCM750);
188
+
189
+ mc->desc = "Nuvoton NPCM750 Evaluation Board (Cortex A9)";
190
+ mc->init = npcm750_evb_init;
191
+ mc->default_ram_size = 512 * MiB;
192
+};
111
+};
193
+
112
+
194
+static void gsj_machine_class_init(ObjectClass *oc, void *data)
113
static int nvic_post_load(void *opaque, int version_id)
195
+{
114
{
196
+ NPCM7xxMachineClass *nmc = NPCM7XX_MACHINE_CLASS(oc);
115
NVICState *s = opaque;
197
+ MachineClass *mc = MACHINE_CLASS(oc);
116
@@ -XXX,XX +XXX,XX @@ static void nvic_systick_trigger(void *opaque, int n, int level)
198
+
117
static void armv7m_nvic_realize(DeviceState *dev, Error **errp)
199
+ npcm7xx_set_soc_type(nmc, TYPE_NPCM730);
118
{
200
+
119
NVICState *s = NVIC(dev);
201
+ mc->desc = "Quanta GSJ (Cortex A9)";
120
- int regionlen;
202
+ mc->init = quanta_gsj_init;
121
203
+ mc->default_ram_size = 512 * MiB;
122
/* The armv7m container object will have set our CPU pointer */
204
+};
123
if (!s->cpu || !arm_feature(&s->cpu->env, ARM_FEATURE_M)) {
205
+
124
@@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_realize(DeviceState *dev, Error **errp)
206
+static const TypeInfo npcm7xx_machine_types[] = {
125
M_REG_S));
207
+ {
126
}
208
+ .name = TYPE_NPCM7XX_MACHINE,
127
209
+ .parent = TYPE_MACHINE,
128
- /* The NVIC and System Control Space (SCS) starts at 0xe000e000
210
+ .instance_size = sizeof(NPCM7xxMachine),
129
+ /*
211
+ .class_size = sizeof(NPCM7xxMachineClass),
130
+ * This device provides a single sysbus memory region which
212
+ .class_init = npcm7xx_machine_class_init,
131
+ * represents the whole of the "System PPB" space. This is the
213
+ .abstract = true,
132
+ * range from 0xe0000000 to 0xe00fffff and includes the NVIC,
214
+ }, {
133
+ * the System Control Space (system registers), the systick timer,
215
+ .name = MACHINE_TYPE_NAME("npcm750-evb"),
134
+ * and for CPUs with the Security extension an NS banked version
216
+ .parent = TYPE_NPCM7XX_MACHINE,
135
+ * of all of these.
217
+ .class_init = npcm750_evb_machine_class_init,
136
+ *
218
+ }, {
137
+ * The default behaviour for unimplemented registers/ranges
219
+ .name = MACHINE_TYPE_NAME("quanta-gsj"),
138
+ * (for instance the Data Watchpoint and Trace unit at 0xe0001000)
220
+ .parent = TYPE_NPCM7XX_MACHINE,
139
+ * is to RAZ/WI for privileged access and BusFault for non-privileged
221
+ .class_init = gsj_machine_class_init,
140
+ * access.
222
+ },
141
+ *
223
+};
142
+ * The NVIC and System Control Space (SCS) starts at 0xe000e000
224
+
143
* and looks like this:
225
+DEFINE_TYPES(npcm7xx_machine_types)
144
* 0x004 - ICTR
226
diff --git a/hw/arm/meson.build b/hw/arm/meson.build
145
* 0x010 - 0xff - systick
227
index XXXXXXX..XXXXXXX 100644
146
@@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_realize(DeviceState *dev, Error **errp)
228
--- a/hw/arm/meson.build
147
* generally code determining which banked register to use should
229
+++ b/hw/arm/meson.build
148
* use attrs.secure; code determining actual behaviour of the system
230
@@ -XXX,XX +XXX,XX @@ arm_ss.add(when: 'CONFIG_MICROBIT', if_true: files('microbit.c'))
149
* should use env->v7m.secure.
231
arm_ss.add(when: 'CONFIG_MUSICPAL', if_true: files('musicpal.c'))
150
+ *
232
arm_ss.add(when: 'CONFIG_NETDUINO2', if_true: files('netduino2.c'))
151
+ * The container covers the whole PPB space. Within it the priority
233
arm_ss.add(when: 'CONFIG_NETDUINOPLUS2', if_true: files('netduinoplus2.c'))
152
+ * of overlapping regions is:
234
-arm_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx.c'))
153
+ * - default region (for RAZ/WI and BusFault) : -1
235
+arm_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx.c', 'npcm7xx_boards.c'))
154
+ * - system register regions : 0
236
arm_ss.add(when: 'CONFIG_NSERIES', if_true: files('nseries.c'))
155
+ * - systick : 1
237
arm_ss.add(when: 'CONFIG_SX1', if_true: files('omap_sx1.c'))
156
+ * This is because the systick device is a small block of registers
238
arm_ss.add(when: 'CONFIG_CHEETAH', if_true: files('palm.c'))
157
+ * in the middle of the other system control registers.
158
*/
159
- regionlen = arm_feature(&s->cpu->env, ARM_FEATURE_V8) ? 0x21000 : 0x1000;
160
- memory_region_init(&s->container, OBJECT(s), "nvic", regionlen);
161
- /* The system register region goes at the bottom of the priority
162
- * stack as it covers the whole page.
163
- */
164
+ memory_region_init(&s->container, OBJECT(s), "nvic", 0x100000);
165
+ memory_region_init_io(&s->defaultmem, OBJECT(s), &ppb_default_ops, s,
166
+ "nvic-default", 0x100000);
167
+ memory_region_add_subregion_overlap(&s->container, 0, &s->defaultmem, -1);
168
memory_region_init_io(&s->sysregmem, OBJECT(s), &nvic_sysreg_ops, s,
169
"nvic_sysregs", 0x1000);
170
- memory_region_add_subregion(&s->container, 0, &s->sysregmem);
171
+ memory_region_add_subregion(&s->container, 0xe000, &s->sysregmem);
172
173
memory_region_init_io(&s->systickmem, OBJECT(s),
174
&nvic_systick_ops, s,
175
"nvic_systick", 0xe0);
176
177
- memory_region_add_subregion_overlap(&s->container, 0x10,
178
+ memory_region_add_subregion_overlap(&s->container, 0xe010,
179
&s->systickmem, 1);
180
181
if (arm_feature(&s->cpu->env, ARM_FEATURE_V8)) {
182
memory_region_init_io(&s->sysreg_ns_mem, OBJECT(s),
183
&nvic_sysreg_ns_ops, &s->sysregmem,
184
"nvic_sysregs_ns", 0x1000);
185
- memory_region_add_subregion(&s->container, 0x20000, &s->sysreg_ns_mem);
186
+ memory_region_add_subregion(&s->container, 0x2e000, &s->sysreg_ns_mem);
187
memory_region_init_io(&s->systick_ns_mem, OBJECT(s),
188
&nvic_sysreg_ns_ops, &s->systickmem,
189
"nvic_systick_ns", 0xe0);
190
- memory_region_add_subregion_overlap(&s->container, 0x20010,
191
+ memory_region_add_subregion_overlap(&s->container, 0x2e010,
192
&s->systick_ns_mem, 1);
193
}
194
239
--
195
--
240
2.20.1
196
2.20.1
241
197
242
198
diff view generated by jsdifflib
1
From: Aaron Lindsay <aaron@os.amperecomputing.com>
1
In v8.1M the PXN architecture extension adds a new PXN bit to the
2
MPU_RLAR registers, which forbids execution of code in the region
3
from a privileged mode.
2
4
3
This check was backwards when introduced in commit
5
This is another feature which is just in the generic "in v8.1M" set
4
033614c47de78409ad3fb39bb7bd1483b71c6789:
6
and has no ID register field indicating its presence.
5
7
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>
10
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
Message-id: 20201119215617.29887-3-peter.maydell@linaro.org
12
---
11
---
13
target/arm/helper.c | 2 +-
12
target/arm/helper.c | 7 ++++++-
14
1 file changed, 1 insertion(+), 1 deletion(-)
13
1 file changed, 6 insertions(+), 1 deletion(-)
15
14
16
diff --git a/target/arm/helper.c b/target/arm/helper.c
15
diff --git a/target/arm/helper.c b/target/arm/helper.c
17
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
18
--- a/target/arm/helper.c
17
--- a/target/arm/helper.c
19
+++ b/target/arm/helper.c
18
+++ b/target/arm/helper.c
20
@@ -XXX,XX +XXX,XX @@ static bool pmu_counter_enabled(CPUARMState *env, uint8_t counter)
19
@@ -XXX,XX +XXX,XX @@ bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address,
20
} else {
21
uint32_t ap = extract32(env->pmsav8.rbar[secure][matchregion], 1, 2);
22
uint32_t xn = extract32(env->pmsav8.rbar[secure][matchregion], 0, 1);
23
+ bool pxn = false;
24
+
25
+ if (arm_feature(env, ARM_FEATURE_V8_1M)) {
26
+ pxn = extract32(env->pmsav8.rlar[secure][matchregion], 4, 1);
27
+ }
28
29
if (m_is_system_region(env, address)) {
30
/* System space is always execute never */
31
@@ -XXX,XX +XXX,XX @@ bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address,
21
}
32
}
22
} else {
33
23
prohibited = arm_feature(env, ARM_FEATURE_EL3) &&
34
*prot = simple_ap_to_rw_prot(env, mmu_idx, ap);
24
- (env->cp15.mdcr_el3 & MDCR_SPME);
35
- if (*prot && !xn) {
25
+ !(env->cp15.mdcr_el3 & MDCR_SPME);
36
+ if (*prot && !xn && !(pxn && !is_user)) {
26
}
37
*prot |= PAGE_EXEC;
27
38
}
28
if (prohibited && counter == 31) {
39
/* We don't need to look the attribute up in the MAIR0/MAIR1
29
--
40
--
30
2.20.1
41
2.20.1
31
42
32
43
diff view generated by jsdifflib
1
From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com>
1
In arm_cpu_realizefn() we check whether the board code disabled EL3
2
via the has_el3 CPU object property, which we create if the CPU
3
starts with the ARM_FEATURE_EL3 feature bit. If it is disabled, then
4
we turn off ARM_FEATURE_EL3 and also zero out the relevant fields in
5
the ID_PFR1 and ID_AA64PFR0 registers.
2
6
3
Correct the GEMs tx/rx clocks to use the 125Mhz fixed-clock.
7
This codepath was incorrectly being taken for M-profile CPUs, which
4
This matches the setup with the fixed-link 100Mbit PHY.
8
do not have an EL3 and don't set ARM_FEATURE_EL3, but which may have
5
It also avoids the following warnings from the Linux kernel
9
the M-profile Security extension and so should have non-zero values
6
driver:
10
in the ID_PFR1.Security field.
7
11
8
eth0: unable to generate target frequency: 125000000 Hz
12
Restrict the handling of the feature flag to A/R-profile cores.
9
13
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
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
16
Message-id: 20201119215617.29887-4-peter.maydell@linaro.org
15
---
17
---
16
hw/arm/xlnx-versal-virt.c | 2 +-
18
target/arm/cpu.c | 2 +-
17
1 file changed, 1 insertion(+), 1 deletion(-)
19
1 file changed, 1 insertion(+), 1 deletion(-)
18
20
19
diff --git a/hw/arm/xlnx-versal-virt.c b/hw/arm/xlnx-versal-virt.c
21
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
20
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
21
--- a/hw/arm/xlnx-versal-virt.c
23
--- a/target/arm/cpu.c
22
+++ b/hw/arm/xlnx-versal-virt.c
24
+++ b/target/arm/cpu.c
23
@@ -XXX,XX +XXX,XX @@ static void fdt_add_gem_nodes(VersalVirt *s)
25
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
24
s->phandle.ethernet_phy[i]);
26
}
25
qemu_fdt_setprop_cells(s->fdt, name, "clocks",
27
}
26
s->phandle.clk_25Mhz, s->phandle.clk_25Mhz,
28
27
- s->phandle.clk_25Mhz, s->phandle.clk_25Mhz);
29
- if (!cpu->has_el3) {
28
+ s->phandle.clk_125Mhz, s->phandle.clk_125Mhz);
30
+ if (!arm_feature(env, ARM_FEATURE_M) && !cpu->has_el3) {
29
qemu_fdt_setprop(s->fdt, name, "clock-names",
31
/* If the has_el3 CPU property is disabled then we need to disable the
30
clocknames, sizeof(clocknames));
32
* feature.
31
qemu_fdt_setprop_cells(s->fdt, name, "interrupts",
33
*/
32
--
34
--
33
2.20.1
35
2.20.1
34
36
35
37
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
Implement the v8.1M VSCCLRM insn, which zeros floating point
2
2
registers if there is an active floating point context.
3
This just implements the bare minimum to cause the boot block to skip
3
This requires support in write_neon_element32() for the MO_32
4
memory initialization.
4
element size, so add it.
5
5
6
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
6
Because we want to use arm_gen_condlabel(), we need to move
7
Reviewed-by: Cédric Le Goater <clg@kaod.org>
7
the definition of that function up in translate.c so it is
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
before the #include of translate-vfp.c.inc.
9
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
10
Tested-by: Alexander Bulekov <alxndr@bu.edu>
11
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
12
Message-id: 20200911052101.2602693-10-hskinnemoen@google.com
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Message-id: 20201119215617.29887-5-peter.maydell@linaro.org
14
---
13
---
15
include/hw/arm/npcm7xx.h | 2 +
14
target/arm/cpu.h | 9 ++++
16
include/hw/mem/npcm7xx_mc.h | 36 ++++++++++++++++
15
target/arm/m-nocp.decode | 8 +++-
17
hw/arm/npcm7xx.c | 6 +++
16
target/arm/translate.c | 21 +++++----
18
hw/mem/npcm7xx_mc.c | 84 +++++++++++++++++++++++++++++++++++++
17
target/arm/translate-vfp.c.inc | 84 ++++++++++++++++++++++++++++++++++
19
hw/mem/meson.build | 1 +
18
4 files changed, 111 insertions(+), 11 deletions(-)
20
5 files changed, 129 insertions(+)
19
21
create mode 100644 include/hw/mem/npcm7xx_mc.h
20
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
22
create mode 100644 hw/mem/npcm7xx_mc.c
21
index XXXXXXX..XXXXXXX 100644
23
22
--- a/target/arm/cpu.h
24
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
23
+++ b/target/arm/cpu.h
25
index XXXXXXX..XXXXXXX 100644
24
@@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa32_mprofile(const ARMISARegisters *id)
26
--- a/include/hw/arm/npcm7xx.h
25
return FIELD_EX32(id->id_pfr1, ID_PFR1, MPROGMOD) != 0;
27
+++ b/include/hw/arm/npcm7xx.h
26
}
28
@@ -XXX,XX +XXX,XX @@
27
29
28
+static inline bool isar_feature_aa32_m_sec_state(const ARMISARegisters *id)
30
#include "hw/boards.h"
31
#include "hw/cpu/a9mpcore.h"
32
+#include "hw/mem/npcm7xx_mc.h"
33
#include "hw/misc/npcm7xx_clk.h"
34
#include "hw/misc/npcm7xx_gcr.h"
35
#include "hw/nvram/npcm7xx_otp.h"
36
@@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState {
37
NPCM7xxTimerCtrlState tim[3];
38
NPCM7xxOTPState key_storage;
39
NPCM7xxOTPState fuse_array;
40
+ NPCM7xxMCState mc;
41
} NPCM7xxState;
42
43
#define TYPE_NPCM7XX "npcm7xx"
44
diff --git a/include/hw/mem/npcm7xx_mc.h b/include/hw/mem/npcm7xx_mc.h
45
new file mode 100644
46
index XXXXXXX..XXXXXXX
47
--- /dev/null
48
+++ b/include/hw/mem/npcm7xx_mc.h
49
@@ -XXX,XX +XXX,XX @@
50
+/*
51
+ * Nuvoton NPCM7xx Memory Controller stub
52
+ *
53
+ * Copyright 2020 Google LLC
54
+ *
55
+ * This program is free software; you can redistribute it and/or modify it
56
+ * under the terms of the GNU General Public License as published by the
57
+ * Free Software Foundation; either version 2 of the License, or
58
+ * (at your option) any later version.
59
+ *
60
+ * This program is distributed in the hope that it will be useful, but WITHOUT
61
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
62
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
63
+ * for more details.
64
+ */
65
+#ifndef NPCM7XX_MC_H
66
+#define NPCM7XX_MC_H
67
+
68
+#include "exec/memory.h"
69
+#include "hw/sysbus.h"
70
+
71
+/**
72
+ * struct NPCM7xxMCState - Device state for the memory controller.
73
+ * @parent: System bus device.
74
+ * @mmio: Memory region through which registers are accessed.
75
+ */
76
+typedef struct NPCM7xxMCState {
77
+ SysBusDevice parent;
78
+
79
+ MemoryRegion mmio;
80
+} NPCM7xxMCState;
81
+
82
+#define TYPE_NPCM7XX_MC "npcm7xx-mc"
83
+#define NPCM7XX_MC(obj) OBJECT_CHECK(NPCM7xxMCState, (obj), TYPE_NPCM7XX_MC)
84
+
85
+#endif /* NPCM7XX_MC_H */
86
diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c
87
index XXXXXXX..XXXXXXX 100644
88
--- a/hw/arm/npcm7xx.c
89
+++ b/hw/arm/npcm7xx.c
90
@@ -XXX,XX +XXX,XX @@
91
#define NPCM7XX_CPUP_BA (0xf03fe000)
92
#define NPCM7XX_GCR_BA (0xf0800000)
93
#define NPCM7XX_CLK_BA (0xf0801000)
94
+#define NPCM7XX_MC_BA (0xf0824000)
95
96
/* Internal AHB SRAM */
97
#define NPCM7XX_RAM3_BA (0xc0008000)
98
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj)
99
TYPE_NPCM7XX_KEY_STORAGE);
100
object_initialize_child(obj, "otp2", &s->fuse_array,
101
TYPE_NPCM7XX_FUSE_ARRAY);
102
+ object_initialize_child(obj, "mc", &s->mc, TYPE_NPCM7XX_MC);
103
104
for (i = 0; i < ARRAY_SIZE(s->tim); i++) {
105
object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER);
106
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
107
sysbus_mmio_map(SYS_BUS_DEVICE(&s->fuse_array), 0, NPCM7XX_OTP2_BA);
108
npcm7xx_init_fuses(s);
109
110
+ /* Fake Memory Controller (MC). Cannot fail. */
111
+ sysbus_realize(SYS_BUS_DEVICE(&s->mc), &error_abort);
112
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->mc), 0, NPCM7XX_MC_BA);
113
+
114
/* Timer Modules (TIM). Cannot fail. */
115
QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_tim_addr) != ARRAY_SIZE(s->tim));
116
for (i = 0; i < ARRAY_SIZE(s->tim); i++) {
117
diff --git a/hw/mem/npcm7xx_mc.c b/hw/mem/npcm7xx_mc.c
118
new file mode 100644
119
index XXXXXXX..XXXXXXX
120
--- /dev/null
121
+++ b/hw/mem/npcm7xx_mc.c
122
@@ -XXX,XX +XXX,XX @@
123
+/*
124
+ * Nuvoton NPCM7xx Memory Controller stub
125
+ *
126
+ * Copyright 2020 Google LLC
127
+ *
128
+ * This program is free software; you can redistribute it and/or modify it
129
+ * under the terms of the GNU General Public License as published by the
130
+ * Free Software Foundation; either version 2 of the License, or
131
+ * (at your option) any later version.
132
+ *
133
+ * This program is distributed in the hope that it will be useful, but WITHOUT
134
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
135
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
136
+ * for more details.
137
+ */
138
+
139
+#include "qemu/osdep.h"
140
+
141
+#include "hw/mem/npcm7xx_mc.h"
142
+#include "qapi/error.h"
143
+#include "qemu/log.h"
144
+#include "qemu/module.h"
145
+#include "qemu/units.h"
146
+
147
+#define NPCM7XX_MC_REGS_SIZE (4 * KiB)
148
+
149
+static uint64_t npcm7xx_mc_read(void *opaque, hwaddr addr, unsigned int size)
150
+{
29
+{
151
+ /*
30
+ /*
152
+ * If bits 8..11 @ offset 0 are not zero, the boot block thinks the memory
31
+ * Return true if M-profile state handling insns
153
+ * controller has already been initialized and will skip DDR training.
32
+ * (VSCCLRM, CLRM, FPCTX access insns) are implemented
154
+ */
33
+ */
155
+ if (addr == 0) {
34
+ return FIELD_EX32(id->id_pfr1, ID_PFR1, SECURITY) >= 3;
156
+ return 0x100;
157
+ }
158
+
159
+ qemu_log_mask(LOG_UNIMP, "%s: mostly unimplemented\n", __func__);
160
+
161
+ return 0;
162
+}
35
+}
163
+
36
+
164
+static void npcm7xx_mc_write(void *opaque, hwaddr addr, uint64_t v,
37
static inline bool isar_feature_aa32_fp16_arith(const ARMISARegisters *id)
165
+ unsigned int size)
38
{
39
/* Sadly this is encoded differently for A-profile and M-profile */
40
diff --git a/target/arm/m-nocp.decode b/target/arm/m-nocp.decode
41
index XXXXXXX..XXXXXXX 100644
42
--- a/target/arm/m-nocp.decode
43
+++ b/target/arm/m-nocp.decode
44
@@ -XXX,XX +XXX,XX @@
45
# If the coprocessor is not present or disabled then we will generate
46
# the NOCP exception; otherwise we let the insn through to the main decode.
47
48
+%vd_dp 22:1 12:4
49
+%vd_sp 12:4 22:1
50
+
51
&nocp cp
52
53
{
54
# Special cases which do not take an early NOCP: VLLDM and VLSTM
55
VLLDM_VLSTM 1110 1100 001 l:1 rn:4 0000 1010 0000 0000
56
- # TODO: VSCCLRM (new in v8.1M) is similar:
57
- #VSCCLRM 1110 1100 1-01 1111 ---- 1011 ---- ---0
58
+ # VSCCLRM (new in v8.1M) is similar:
59
+ VSCCLRM 1110 1100 1.01 1111 .... 1011 imm:7 0 vd=%vd_dp size=3
60
+ VSCCLRM 1110 1100 1.01 1111 .... 1010 imm:8 vd=%vd_sp size=2
61
62
NOCP 111- 1110 ---- ---- ---- cp:4 ---- ---- &nocp
63
NOCP 111- 110- ---- ---- ---- cp:4 ---- ---- &nocp
64
diff --git a/target/arm/translate.c b/target/arm/translate.c
65
index XXXXXXX..XXXXXXX 100644
66
--- a/target/arm/translate.c
67
+++ b/target/arm/translate.c
68
@@ -XXX,XX +XXX,XX @@ void arm_translate_init(void)
69
a64_translate_init();
70
}
71
72
+/* Generate a label used for skipping this instruction */
73
+static void arm_gen_condlabel(DisasContext *s)
166
+{
74
+{
167
+ qemu_log_mask(LOG_UNIMP, "%s: mostly unimplemented\n", __func__);
75
+ if (!s->condjmp) {
76
+ s->condlabel = gen_new_label();
77
+ s->condjmp = 1;
78
+ }
168
+}
79
+}
169
+
80
+
170
+static const MemoryRegionOps npcm7xx_mc_ops = {
81
/* Flags for the disas_set_da_iss info argument:
171
+ .read = npcm7xx_mc_read,
82
* lower bits hold the Rt register number, higher bits are flags.
172
+ .write = npcm7xx_mc_write,
83
*/
173
+ .endianness = DEVICE_LITTLE_ENDIAN,
84
@@ -XXX,XX +XXX,XX @@ static void write_neon_element64(TCGv_i64 src, int reg, int ele, MemOp memop)
174
+ .valid = {
85
long off = neon_element_offset(reg, ele, memop);
175
+ .min_access_size = 4,
86
176
+ .max_access_size = 4,
87
switch (memop) {
177
+ .unaligned = false,
88
+ case MO_32:
178
+ },
89
+ tcg_gen_st32_i64(src, cpu_env, off);
179
+};
90
+ break;
180
+
91
case MO_64:
181
+static void npcm7xx_mc_realize(DeviceState *dev, Error **errp)
92
tcg_gen_st_i64(src, cpu_env, off);
93
break;
94
@@ -XXX,XX +XXX,XX @@ static void gen_srs(DisasContext *s,
95
s->base.is_jmp = DISAS_UPDATE_EXIT;
96
}
97
98
-/* Generate a label used for skipping this instruction */
99
-static void arm_gen_condlabel(DisasContext *s)
100
-{
101
- if (!s->condjmp) {
102
- s->condlabel = gen_new_label();
103
- s->condjmp = 1;
104
- }
105
-}
106
-
107
/* Skip this instruction if the ARM condition is false */
108
static void arm_skip_unless(DisasContext *s, uint32_t cond)
109
{
110
diff --git a/target/arm/translate-vfp.c.inc b/target/arm/translate-vfp.c.inc
111
index XXXXXXX..XXXXXXX 100644
112
--- a/target/arm/translate-vfp.c.inc
113
+++ b/target/arm/translate-vfp.c.inc
114
@@ -XXX,XX +XXX,XX @@ static bool trans_VLLDM_VLSTM(DisasContext *s, arg_VLLDM_VLSTM *a)
115
return true;
116
}
117
118
+static bool trans_VSCCLRM(DisasContext *s, arg_VSCCLRM *a)
182
+{
119
+{
183
+ NPCM7xxMCState *s = NPCM7XX_MC(dev);
120
+ int btmreg, topreg;
184
+
121
+ TCGv_i64 zero;
185
+ memory_region_init_io(&s->mmio, OBJECT(s), &npcm7xx_mc_ops, s, "regs",
122
+ TCGv_i32 aspen, sfpa;
186
+ NPCM7XX_MC_REGS_SIZE);
123
+
187
+ sysbus_init_mmio(&s->parent, &s->mmio);
124
+ if (!dc_isar_feature(aa32_m_sec_state, s)) {
125
+ /* Before v8.1M, fall through in decode to NOCP check */
126
+ return false;
127
+ }
128
+
129
+ /* Explicitly UNDEF because this takes precedence over NOCP */
130
+ if (!arm_dc_feature(s, ARM_FEATURE_M_MAIN) || !s->v8m_secure) {
131
+ unallocated_encoding(s);
132
+ return true;
133
+ }
134
+
135
+ if (!dc_isar_feature(aa32_vfp_simd, s)) {
136
+ /* NOP if we have neither FP nor MVE */
137
+ return true;
138
+ }
139
+
140
+ /*
141
+ * If FPCCR.ASPEN != 0 && CONTROL_S.SFPA == 0 then there is no
142
+ * active floating point context so we must NOP (without doing
143
+ * any lazy state preservation or the NOCP check).
144
+ */
145
+ aspen = load_cpu_field(v7m.fpccr[M_REG_S]);
146
+ sfpa = load_cpu_field(v7m.control[M_REG_S]);
147
+ tcg_gen_andi_i32(aspen, aspen, R_V7M_FPCCR_ASPEN_MASK);
148
+ tcg_gen_xori_i32(aspen, aspen, R_V7M_FPCCR_ASPEN_MASK);
149
+ tcg_gen_andi_i32(sfpa, sfpa, R_V7M_CONTROL_SFPA_MASK);
150
+ tcg_gen_or_i32(sfpa, sfpa, aspen);
151
+ arm_gen_condlabel(s);
152
+ tcg_gen_brcondi_i32(TCG_COND_EQ, sfpa, 0, s->condlabel);
153
+
154
+ if (s->fp_excp_el != 0) {
155
+ gen_exception_insn(s, s->pc_curr, EXCP_NOCP,
156
+ syn_uncategorized(), s->fp_excp_el);
157
+ return true;
158
+ }
159
+
160
+ topreg = a->vd + a->imm - 1;
161
+ btmreg = a->vd;
162
+
163
+ /* Convert to Sreg numbers if the insn specified in Dregs */
164
+ if (a->size == 3) {
165
+ topreg = topreg * 2 + 1;
166
+ btmreg *= 2;
167
+ }
168
+
169
+ if (topreg > 63 || (topreg > 31 && !(topreg & 1))) {
170
+ /* UNPREDICTABLE: we choose to undef */
171
+ unallocated_encoding(s);
172
+ return true;
173
+ }
174
+
175
+ /* Silently ignore requests to clear D16-D31 if they don't exist */
176
+ if (topreg > 31 && !dc_isar_feature(aa32_simd_r32, s)) {
177
+ topreg = 31;
178
+ }
179
+
180
+ if (!vfp_access_check(s)) {
181
+ return true;
182
+ }
183
+
184
+ /* Zero the Sregs from btmreg to topreg inclusive. */
185
+ zero = tcg_const_i64(0);
186
+ if (btmreg & 1) {
187
+ write_neon_element64(zero, btmreg >> 1, 1, MO_32);
188
+ btmreg++;
189
+ }
190
+ for (; btmreg + 1 <= topreg; btmreg += 2) {
191
+ write_neon_element64(zero, btmreg >> 1, 0, MO_64);
192
+ }
193
+ if (btmreg == topreg) {
194
+ write_neon_element64(zero, btmreg >> 1, 0, MO_32);
195
+ btmreg++;
196
+ }
197
+ assert(btmreg == topreg + 1);
198
+ /* TODO: when MVE is implemented, zero VPR here */
199
+ return true;
188
+}
200
+}
189
+
201
+
190
+static void npcm7xx_mc_class_init(ObjectClass *klass, void *data)
202
static bool trans_NOCP(DisasContext *s, arg_nocp *a)
191
+{
203
{
192
+ DeviceClass *dc = DEVICE_CLASS(klass);
204
/*
193
+
194
+ dc->desc = "NPCM7xx Memory Controller stub";
195
+ dc->realize = npcm7xx_mc_realize;
196
+}
197
+
198
+static const TypeInfo npcm7xx_mc_types[] = {
199
+ {
200
+ .name = TYPE_NPCM7XX_MC,
201
+ .parent = TYPE_SYS_BUS_DEVICE,
202
+ .instance_size = sizeof(NPCM7xxMCState),
203
+ .class_init = npcm7xx_mc_class_init,
204
+ },
205
+};
206
+DEFINE_TYPES(npcm7xx_mc_types);
207
diff --git a/hw/mem/meson.build b/hw/mem/meson.build
208
index XXXXXXX..XXXXXXX 100644
209
--- a/hw/mem/meson.build
210
+++ b/hw/mem/meson.build
211
@@ -XXX,XX +XXX,XX @@
212
mem_ss = ss.source_set()
213
mem_ss.add(files('memory-device.c'))
214
mem_ss.add(when: 'CONFIG_DIMM', if_true: files('pc-dimm.c'))
215
+mem_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_mc.c'))
216
mem_ss.add(when: 'CONFIG_NVDIMM', if_true: files('nvdimm.c'))
217
218
softmmu_ss.add_all(when: 'CONFIG_MEM_DEVICE', if_true: mem_ss)
219
--
205
--
220
2.20.1
206
2.20.1
221
207
222
208
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
In v8.1M the new CLRM instruction allows zeroing an arbitrary set of
2
the general-purpose registers and APSR. Implement this.
2
3
3
Enough functionality to boot the Linux kernel has been implemented. This
4
The encoding is a subset of the LDMIA T2 encoding, using what would
4
includes:
5
be Rn=0b1111 (which UNDEFs for LDMIA).
5
6
6
- Correct power-on reset values so the various clock rates can be
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
accurately calculated.
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
- Clock enables stick around when written.
9
Message-id: 20201119215617.29887-6-peter.maydell@linaro.org
10
---
11
target/arm/t32.decode | 6 +++++-
12
target/arm/translate.c | 38 ++++++++++++++++++++++++++++++++++++++
13
2 files changed, 43 insertions(+), 1 deletion(-)
9
14
10
In addition, a best effort attempt to implement SECCNT and CNTR25M was
15
diff --git a/target/arm/t32.decode b/target/arm/t32.decode
11
made even though I don't think the kernel needs them.
16
index XXXXXXX..XXXXXXX 100644
12
17
--- a/target/arm/t32.decode
13
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
18
+++ b/target/arm/t32.decode
14
Reviewed-by: Joel Stanley <joel@jms.id.au>
19
@@ -XXX,XX +XXX,XX @@ UXTAB 1111 1010 0101 .... 1111 .... 10.. .... @rrr_rot
15
Reviewed-by: Cédric Le Goater <clg@kaod.org>
20
16
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
21
STM_t32 1110 1000 10.0 .... ................ @ldstm i=1 b=0
17
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
22
STM_t32 1110 1001 00.0 .... ................ @ldstm i=0 b=1
18
Tested-by: Alexander Bulekov <alxndr@bu.edu>
23
-LDM_t32 1110 1000 10.1 .... ................ @ldstm i=1 b=0
19
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
24
+{
20
Message-id: 20200911052101.2602693-3-hskinnemoen@google.com
25
+ # Rn=15 UNDEFs for LDM; M-profile CLRM uses that encoding
21
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
26
+ CLRM 1110 1000 1001 1111 list:16
22
---
27
+ LDM_t32 1110 1000 10.1 .... ................ @ldstm i=1 b=0
23
include/hw/misc/npcm7xx_clk.h | 48 ++++++
28
+}
24
hw/misc/npcm7xx_clk.c | 266 ++++++++++++++++++++++++++++++++++
29
LDM_t32 1110 1001 00.1 .... ................ @ldstm i=0 b=1
25
hw/misc/meson.build | 1 +
30
26
hw/misc/trace-events | 4 +
31
&rfe !extern rn w pu
27
4 files changed, 319 insertions(+)
32
diff --git a/target/arm/translate.c b/target/arm/translate.c
28
create mode 100644 include/hw/misc/npcm7xx_clk.h
33
index XXXXXXX..XXXXXXX 100644
29
create mode 100644 hw/misc/npcm7xx_clk.c
34
--- a/target/arm/translate.c
30
35
+++ b/target/arm/translate.c
31
diff --git a/include/hw/misc/npcm7xx_clk.h b/include/hw/misc/npcm7xx_clk.h
36
@@ -XXX,XX +XXX,XX @@ static bool trans_LDM_t16(DisasContext *s, arg_ldst_block *a)
32
new file mode 100644
37
return do_ldm(s, a, 1);
33
index XXXXXXX..XXXXXXX
38
}
34
--- /dev/null
39
35
+++ b/include/hw/misc/npcm7xx_clk.h
40
+static bool trans_CLRM(DisasContext *s, arg_CLRM *a)
36
@@ -XXX,XX +XXX,XX @@
41
+{
37
+/*
42
+ int i;
38
+ * Nuvoton NPCM7xx Clock Control Registers.
43
+ TCGv_i32 zero;
39
+ *
40
+ * Copyright 2020 Google LLC
41
+ *
42
+ * This program is free software; you can redistribute it and/or modify it
43
+ * under the terms of the GNU General Public License as published by the
44
+ * Free Software Foundation; either version 2 of the License, or
45
+ * (at your option) any later version.
46
+ *
47
+ * This program is distributed in the hope that it will be useful, but WITHOUT
48
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
49
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
50
+ * for more details.
51
+ */
52
+#ifndef NPCM7XX_CLK_H
53
+#define NPCM7XX_CLK_H
54
+
44
+
55
+#include "exec/memory.h"
45
+ if (!dc_isar_feature(aa32_m_sec_state, s)) {
56
+#include "hw/sysbus.h"
46
+ return false;
57
+
58
+/*
59
+ * The reference clock frequency for the timer modules, and the SECCNT and
60
+ * CNTR25M registers in this module, is always 25 MHz.
61
+ */
62
+#define NPCM7XX_TIMER_REF_HZ (25000000)
63
+
64
+/*
65
+ * Number of registers in our device state structure. Don't change this without
66
+ * incrementing the version_id in the vmstate.
67
+ */
68
+#define NPCM7XX_CLK_NR_REGS (0x70 / sizeof(uint32_t))
69
+
70
+typedef struct NPCM7xxCLKState {
71
+ SysBusDevice parent;
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
86
new file mode 100644
87
index XXXXXXX..XXXXXXX
88
--- /dev/null
89
+++ b/hw/misc/npcm7xx_clk.c
90
@@ -XXX,XX +XXX,XX @@
91
+/*
92
+ * Nuvoton NPCM7xx Clock Control Registers.
93
+ *
94
+ * Copyright 2020 Google LLC
95
+ *
96
+ * This program is free software; you can redistribute it and/or modify it
97
+ * under the terms of the GNU General Public License as published by the
98
+ * Free Software Foundation; either version 2 of the License, or
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.
105
+ */
106
+
107
+#include "qemu/osdep.h"
108
+
109
+#include "hw/misc/npcm7xx_clk.h"
110
+#include "migration/vmstate.h"
111
+#include "qemu/error-report.h"
112
+#include "qemu/log.h"
113
+#include "qemu/module.h"
114
+#include "qemu/timer.h"
115
+#include "qemu/units.h"
116
+#include "trace.h"
117
+
118
+#define PLLCON_LOKI BIT(31)
119
+#define PLLCON_LOKS BIT(30)
120
+#define PLLCON_PWDEN BIT(12)
121
+
122
+enum NPCM7xxCLKRegisters {
123
+ NPCM7XX_CLK_CLKEN1,
124
+ NPCM7XX_CLK_CLKSEL,
125
+ NPCM7XX_CLK_CLKDIV1,
126
+ NPCM7XX_CLK_PLLCON0,
127
+ NPCM7XX_CLK_PLLCON1,
128
+ NPCM7XX_CLK_SWRSTR,
129
+ NPCM7XX_CLK_IPSRST1 = 0x20 / sizeof(uint32_t),
130
+ NPCM7XX_CLK_IPSRST2,
131
+ NPCM7XX_CLK_CLKEN2,
132
+ NPCM7XX_CLK_CLKDIV2,
133
+ NPCM7XX_CLK_CLKEN3,
134
+ NPCM7XX_CLK_IPSRST3,
135
+ NPCM7XX_CLK_WD0RCR,
136
+ NPCM7XX_CLK_WD1RCR,
137
+ NPCM7XX_CLK_WD2RCR,
138
+ NPCM7XX_CLK_SWRSTC1,
139
+ NPCM7XX_CLK_SWRSTC2,
140
+ NPCM7XX_CLK_SWRSTC3,
141
+ NPCM7XX_CLK_SWRSTC4,
142
+ NPCM7XX_CLK_PLLCON2,
143
+ NPCM7XX_CLK_CLKDIV3,
144
+ NPCM7XX_CLK_CORSTC,
145
+ NPCM7XX_CLK_PLLCONG,
146
+ NPCM7XX_CLK_AHBCKFI,
147
+ NPCM7XX_CLK_SECCNT,
148
+ NPCM7XX_CLK_CNTR25M,
149
+ NPCM7XX_CLK_REGS_END,
150
+};
151
+
152
+/*
153
+ * These reset values were taken from version 0.91 of the NPCM750R data sheet.
154
+ *
155
+ * All are loaded on power-up reset. CLKENx and SWRSTR should also be loaded on
156
+ * core domain reset, but this reset type is not yet supported by QEMU.
157
+ */
158
+static const uint32_t cold_reset_values[NPCM7XX_CLK_NR_REGS] = {
159
+ [NPCM7XX_CLK_CLKEN1] = 0xffffffff,
160
+ [NPCM7XX_CLK_CLKSEL] = 0x004aaaaa,
161
+ [NPCM7XX_CLK_CLKDIV1] = 0x5413f855,
162
+ [NPCM7XX_CLK_PLLCON0] = 0x00222101 | PLLCON_LOKI,
163
+ [NPCM7XX_CLK_PLLCON1] = 0x00202101 | PLLCON_LOKI,
164
+ [NPCM7XX_CLK_IPSRST1] = 0x00001000,
165
+ [NPCM7XX_CLK_IPSRST2] = 0x80000000,
166
+ [NPCM7XX_CLK_CLKEN2] = 0xffffffff,
167
+ [NPCM7XX_CLK_CLKDIV2] = 0xaa4f8f9f,
168
+ [NPCM7XX_CLK_CLKEN3] = 0xffffffff,
169
+ [NPCM7XX_CLK_IPSRST3] = 0x03000000,
170
+ [NPCM7XX_CLK_WD0RCR] = 0xffffffff,
171
+ [NPCM7XX_CLK_WD1RCR] = 0xffffffff,
172
+ [NPCM7XX_CLK_WD2RCR] = 0xffffffff,
173
+ [NPCM7XX_CLK_SWRSTC1] = 0x00000003,
174
+ [NPCM7XX_CLK_PLLCON2] = 0x00c02105 | PLLCON_LOKI,
175
+ [NPCM7XX_CLK_CORSTC] = 0x04000003,
176
+ [NPCM7XX_CLK_PLLCONG] = 0x01228606 | PLLCON_LOKI,
177
+ [NPCM7XX_CLK_AHBCKFI] = 0x000000c8,
178
+};
179
+
180
+static uint64_t npcm7xx_clk_read(void *opaque, hwaddr offset, unsigned size)
181
+{
182
+ uint32_t reg = offset / sizeof(uint32_t);
183
+ NPCM7xxCLKState *s = opaque;
184
+ int64_t now_ns;
185
+ uint32_t value = 0;
186
+
187
+ if (reg >= NPCM7XX_CLK_NR_REGS) {
188
+ qemu_log_mask(LOG_GUEST_ERROR,
189
+ "%s: offset 0x%04" HWADDR_PRIx " out of range\n",
190
+ __func__, offset);
191
+ return 0;
192
+ }
47
+ }
193
+
48
+
194
+ switch (reg) {
49
+ if (extract32(a->list, 13, 1)) {
195
+ case NPCM7XX_CLK_SWRSTR:
50
+ return false;
196
+ qemu_log_mask(LOG_GUEST_ERROR,
51
+ }
197
+ "%s: register @ 0x%04" HWADDR_PRIx " is write-only\n",
198
+ __func__, offset);
199
+ break;
200
+
52
+
201
+ case NPCM7XX_CLK_SECCNT:
53
+ if (!a->list) {
202
+ now_ns = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
54
+ /* UNPREDICTABLE; we choose to UNDEF */
203
+ value = (now_ns - s->ref_ns) / NANOSECONDS_PER_SECOND;
55
+ return false;
204
+ break;
56
+ }
205
+
57
+
206
+ case NPCM7XX_CLK_CNTR25M:
58
+ zero = tcg_const_i32(0);
207
+ now_ns = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
59
+ for (i = 0; i < 15; i++) {
60
+ if (extract32(a->list, i, 1)) {
61
+ /* Clear R[i] */
62
+ tcg_gen_mov_i32(cpu_R[i], zero);
63
+ }
64
+ }
65
+ if (extract32(a->list, 15, 1)) {
208
+ /*
66
+ /*
209
+ * This register counts 25 MHz cycles, updating every 640 ns. It rolls
67
+ * Clear APSR (by calling the MSR helper with the same argument
210
+ * over to zero every second.
68
+ * as for "MSR APSR_nzcvqg, Rn": mask = 0b1100, SYSM=0)
211
+ *
212
+ * The 4 LSBs are always zero: (1e9 / 640) << 4 = 25000000.
213
+ */
69
+ */
214
+ value = (((now_ns - s->ref_ns) / 640) << 4) % NPCM7XX_TIMER_REF_HZ;
70
+ TCGv_i32 maskreg = tcg_const_i32(0xc << 8);
215
+ break;
71
+ gen_helper_v7m_msr(cpu_env, maskreg, zero);
216
+
72
+ tcg_temp_free_i32(maskreg);
217
+ default:
73
+ }
218
+ value = s->regs[reg];
74
+ tcg_temp_free_i32(zero);
219
+ break;
75
+ return true;
220
+ };
221
+
222
+ trace_npcm7xx_clk_read(offset, value);
223
+
224
+ return value;
225
+}
76
+}
226
+
77
+
227
+static void npcm7xx_clk_write(void *opaque, hwaddr offset,
78
/*
228
+ uint64_t v, unsigned size)
79
* Branch, branch with link
229
+{
80
*/
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) {
237
+ qemu_log_mask(LOG_GUEST_ERROR,
238
+ "%s: offset 0x%04" HWADDR_PRIx " out of range\n",
239
+ __func__, offset);
240
+ return;
241
+ }
242
+
243
+ switch (reg) {
244
+ case NPCM7XX_CLK_SWRSTR:
245
+ qemu_log_mask(LOG_UNIMP, "%s: SW reset not implemented: 0x%02x\n",
246
+ __func__, value);
247
+ value = 0;
248
+ break;
249
+
250
+ case NPCM7XX_CLK_PLLCON0:
251
+ case NPCM7XX_CLK_PLLCON1:
252
+ case NPCM7XX_CLK_PLLCON2:
253
+ case NPCM7XX_CLK_PLLCONG:
254
+ if (value & PLLCON_PWDEN) {
255
+ /* Power down -- clear lock and indicate loss of lock */
256
+ value &= ~PLLCON_LOKI;
257
+ value |= PLLCON_LOKS;
258
+ } else {
259
+ /* Normal mode -- assume always locked */
260
+ value |= PLLCON_LOKI;
261
+ /* Keep LOKS unchanged unless cleared by writing 1 */
262
+ if (value & PLLCON_LOKS) {
263
+ value &= ~PLLCON_LOKS;
264
+ } else {
265
+ value |= (value & PLLCON_LOKS);
266
+ }
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;
275
+ }
276
+
277
+ s->regs[reg] = value;
278
+}
279
+
280
+static const struct MemoryRegionOps npcm7xx_clk_ops = {
281
+ .read = npcm7xx_clk_read,
282
+ .write = npcm7xx_clk_write,
283
+ .endianness = DEVICE_LITTLE_ENDIAN,
284
+ .valid = {
285
+ .min_access_size = 4,
286
+ .max_access_size = 4,
287
+ .unaligned = false,
288
+ },
289
+};
290
+
291
+static void npcm7xx_clk_enter_reset(Object *obj, ResetType type)
292
+{
293
+ NPCM7xxCLKState *s = NPCM7XX_CLK(obj);
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;
302
+ }
303
+
304
+ /*
305
+ * A small number of registers need to be reset on a core domain reset,
306
+ * but no such reset type exists yet.
307
+ */
308
+ qemu_log_mask(LOG_UNIMP, "%s: reset type %d not implemented.",
309
+ __func__, type);
310
+}
311
+
312
+static void npcm7xx_clk_init(Object *obj)
313
+{
314
+ NPCM7xxCLKState *s = NPCM7XX_CLK(obj);
315
+
316
+ memory_region_init_io(&s->iomem, obj, &npcm7xx_clk_ops, s,
317
+ TYPE_NPCM7XX_CLK, 4 * KiB);
318
+ sysbus_init_mmio(&s->parent, &s->iomem);
319
+}
320
+
321
+static const VMStateDescription vmstate_npcm7xx_clk = {
322
+ .name = "npcm7xx-clk",
323
+ .version_id = 0,
324
+ .minimum_version_id = 0,
325
+ .fields = (VMStateField[]) {
326
+ VMSTATE_UINT32_ARRAY(regs, NPCM7xxCLKState, NPCM7XX_CLK_NR_REGS),
327
+ VMSTATE_INT64(ref_ns, NPCM7xxCLKState),
328
+ VMSTATE_END_OF_LIST(),
329
+ },
330
+};
331
+
332
+static void npcm7xx_clk_class_init(ObjectClass *klass, void *data)
333
+{
334
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
335
+ DeviceClass *dc = DEVICE_CLASS(klass);
336
+
337
+ QEMU_BUILD_BUG_ON(NPCM7XX_CLK_REGS_END > NPCM7XX_CLK_NR_REGS);
338
+
339
+ dc->desc = "NPCM7xx Clock Control Registers";
340
+ dc->vmsd = &vmstate_npcm7xx_clk;
341
+ rc->phases.enter = npcm7xx_clk_enter_reset;
342
+}
343
+
344
+static const TypeInfo npcm7xx_clk_info = {
345
+ .name = TYPE_NPCM7XX_CLK,
346
+ .parent = TYPE_SYS_BUS_DEVICE,
347
+ .instance_size = sizeof(NPCM7xxCLKState),
348
+ .instance_init = npcm7xx_clk_init,
349
+ .class_init = npcm7xx_clk_class_init,
350
+};
351
+
352
+static void npcm7xx_clk_register_type(void)
353
+{
354
+ type_register_static(&npcm7xx_clk_info);
355
+}
356
+type_init(npcm7xx_clk_register_type);
357
diff --git a/hw/misc/meson.build b/hw/misc/meson.build
358
index XXXXXXX..XXXXXXX 100644
359
--- a/hw/misc/meson.build
360
+++ b/hw/misc/meson.build
361
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_IMX', if_true: files(
362
softmmu_ss.add(when: 'CONFIG_MILKYMIST', if_true: files('milkymist-hpdmc.c', 'milkymist-pfpu.c'))
363
softmmu_ss.add(when: 'CONFIG_MAINSTONE', if_true: files('mst_fpga.c'))
364
softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files(
365
+ 'npcm7xx_clk.c',
366
'npcm7xx_gcr.c',
367
))
368
softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files(
369
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
370
index XXXXXXX..XXXXXXX 100644
371
--- a/hw/misc/trace-events
372
+++ b/hw/misc/trace-events
373
@@ -XXX,XX +XXX,XX @@ mos6522_set_sr_int(void) "set sr_int"
374
mos6522_write(uint64_t addr, uint64_t val) "reg=0x%"PRIx64 " val=0x%"PRIx64
375
mos6522_read(uint64_t addr, unsigned val) "reg=0x%"PRIx64 " val=0x%x"
376
377
+# npcm7xx_clk.c
378
+npcm7xx_clk_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
379
+npcm7xx_clk_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
380
+
381
# npcm7xx_gcr.c
382
npcm7xx_gcr_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
383
npcm7xx_gcr_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
384
--
81
--
385
2.20.1
82
2.20.1
386
83
387
84
diff view generated by jsdifflib
1
Deprecate our lm32 target support. Michael Walle (former lm32 maintainer)
1
For M-profile before v8.1M, the only valid register for VMSR/VMRS is
2
suggested that we do this in 2019:
2
the FPSCR. We have a comment that states this, but the actual logic
3
https://www.mail-archive.com/qemu-devel@nongnu.org/msg605024.html
3
to forbid accesses for any other register value is missing, so we
4
because the only public user of the architecture is the many-years-dead
4
would end up with A-profile style behaviour. Add the missing check.
5
milkymist project. (The Linux port to lm32 was never merged upstream.)
6
7
In commit 4b4d96c776f552e (March 2020) we marked it as 'orphan' in
8
the MAINTAINERS file, but didn't officially deprecate it. Mark it
9
deprecated now, with the intention of removing it from QEMU in
10
mid-2021 before the 6.1 release.
11
5
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
14
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Message-id: 20201119215617.29887-7-peter.maydell@linaro.org
15
Reviewed-by: Thomas Huth <thuth@redhat.com>
16
Acked-by: Michael Walle <michael@walle.cc>
17
Message-id: 20200827113259.25064-1-peter.maydell@linaro.org
18
---
9
---
19
docs/system/deprecated.rst | 8 ++++++++
10
target/arm/translate-vfp.c.inc | 5 ++++-
20
1 file changed, 8 insertions(+)
11
1 file changed, 4 insertions(+), 1 deletion(-)
21
12
22
diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
13
diff --git a/target/arm/translate-vfp.c.inc b/target/arm/translate-vfp.c.inc
23
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
24
--- a/docs/system/deprecated.rst
15
--- a/target/arm/translate-vfp.c.inc
25
+++ b/docs/system/deprecated.rst
16
+++ b/target/arm/translate-vfp.c.inc
26
@@ -XXX,XX +XXX,XX @@ The above, converted to the current supported format::
17
@@ -XXX,XX +XXX,XX @@ static bool trans_VMSR_VMRS(DisasContext *s, arg_VMSR_VMRS *a)
27
linux-user mode CPUs
18
* Accesses to R15 are UNPREDICTABLE; we choose to undef.
28
--------------------
19
* (FPSCR -> r15 is a special case which writes to the PSR flags.)
29
20
*/
30
+``lm32`` CPUs (since 5.2.0)
21
- if (a->rt == 15 && (!a->l || a->reg != ARM_VFP_FPSCR)) {
31
+'''''''''''''''''''''''''''
22
+ if (a->reg != ARM_VFP_FPSCR) {
32
+
23
+ return false;
33
+The ``lm32`` guest CPU support is deprecated and will be removed in
24
+ }
34
+a future version of QEMU. The only public user of this architecture
25
+ if (a->rt == 15 && !a->l) {
35
+was the milkymist project, which has been dead for years; there was
26
return false;
36
+never an upstream Linux port.
27
}
37
+
28
}
38
``unicore32`` CPUs (since 5.2.0)
39
''''''''''''''''''''''''''''''''
40
41
--
29
--
42
2.20.1
30
2.20.1
43
31
44
32
diff view generated by jsdifflib
1
The VCMLA and VCADD insns have a size field which is 0 for fp16
1
Currently M-profile borrows the A-profile code for VMSR and VMRS
2
and 1 for fp32 (note that this is the reverse of the Neon 3-same
2
(access to the FP system registers), because all it needs to support
3
encoding!). Convert it to MO_* values in decode for consistency.
3
is the FPSCR. In v8.1M things become significantly more complicated
4
in two ways:
5
6
* there are several new FP system registers; some have side effects
7
on read, and one (FPCXT_NS) needs to avoid the usual
8
vfp_access_check() and the "only if FPU implemented" check
9
10
* all sysregs are now accessible both by VMRS/VMSR (which
11
reads/writes a general purpose register) and also by VLDR/VSTR
12
(which reads/writes them directly to memory)
13
14
Refactor the structure of how we handle VMSR/VMRS to cope with this:
15
16
* keep the M-profile code entirely separate from the A-profile code
17
18
* abstract out the "read or write the general purpose register" part
19
of the code into a loadfn or storefn function pointer, so we can
20
reuse it for VLDR/VSTR.
4
21
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
22
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
23
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20200903133209.5141-4-peter.maydell@linaro.org
24
Message-id: 20201119215617.29887-8-peter.maydell@linaro.org
8
---
25
---
9
target/arm/neon-shared.decode | 18 ++++++++++++------
26
target/arm/cpu.h | 3 +
10
target/arm/translate-neon.c.inc | 22 ++++++++++++----------
27
target/arm/translate-vfp.c.inc | 182 ++++++++++++++++++++++++++++++---
11
2 files changed, 24 insertions(+), 16 deletions(-)
28
2 files changed, 171 insertions(+), 14 deletions(-)
12
29
13
diff --git a/target/arm/neon-shared.decode b/target/arm/neon-shared.decode
30
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
14
index XXXXXXX..XXXXXXX 100644
31
index XXXXXXX..XXXXXXX 100644
15
--- a/target/arm/neon-shared.decode
32
--- a/target/arm/cpu.h
16
+++ b/target/arm/neon-shared.decode
33
+++ b/target/arm/cpu.h
17
@@ -XXX,XX +XXX,XX @@
34
@@ -XXX,XX +XXX,XX @@ enum arm_cpu_mode {
18
%vd_dp 22:1 12:4
35
#define ARM_VFP_FPINST 9
19
%vd_sp 12:4 22:1
36
#define ARM_VFP_FPINST2 10
20
37
21
-VCMLA 1111 110 rot:2 . 1 size:1 .... .... 1000 . q:1 . 0 .... \
38
+/* QEMU-internal value meaning "FPSCR, but we care only about NZCV" */
22
- vm=%vm_dp vn=%vn_dp vd=%vd_dp
39
+#define QEMU_VFP_FPSCR_NZCV 0xffff
23
+# For VCMLA/VCADD insns, convert the single-bit size field
40
+
24
+# which is 0 for fp16 and 1 for fp32 into a MO_* constant.
41
/* iwMMXt coprocessor control registers. */
25
+# (Note that this is the reverse of the sense of the 1-bit size
42
#define ARM_IWMMXT_wCID 0
26
+# field in the 3same_fp Neon insns.)
43
#define ARM_IWMMXT_wCon 1
27
+%vcadd_size 20:1 !function=plus1
44
diff --git a/target/arm/translate-vfp.c.inc b/target/arm/translate-vfp.c.inc
28
29
-VCADD 1111 110 rot:1 1 . 0 size:1 .... .... 1000 . q:1 . 0 .... \
30
- vm=%vm_dp vn=%vn_dp vd=%vd_dp
31
+VCMLA 1111 110 rot:2 . 1 . .... .... 1000 . q:1 . 0 .... \
32
+ vm=%vm_dp vn=%vn_dp vd=%vd_dp size=%vcadd_size
33
+
34
+VCADD 1111 110 rot:1 1 . 0 . .... .... 1000 . q:1 . 0 .... \
35
+ vm=%vm_dp vn=%vn_dp vd=%vd_dp size=%vcadd_size
36
37
# VUDOT and VSDOT
38
VDOT 1111 110 00 . 10 .... .... 1101 . q:1 . u:1 .... \
39
@@ -XXX,XX +XXX,XX @@ VFML 1111 110 0 s:1 . 10 .... .... 1000 . 1 . 1 .... \
40
vm=%vm_dp vn=%vn_dp vd=%vd_dp q=1
41
42
VCMLA_scalar 1111 1110 0 . rot:2 .... .... 1000 . q:1 index:1 0 vm:4 \
43
- vn=%vn_dp vd=%vd_dp size=0
44
+ vn=%vn_dp vd=%vd_dp size=1
45
VCMLA_scalar 1111 1110 1 . rot:2 .... .... 1000 . q:1 . 0 .... \
46
- vm=%vm_dp vn=%vn_dp vd=%vd_dp size=1 index=0
47
+ vm=%vm_dp vn=%vn_dp vd=%vd_dp size=2 index=0
48
49
VDOT_scalar 1111 1110 0 . 10 .... .... 1101 . q:1 index:1 u:1 rm:4 \
50
vm=%vm_dp vn=%vn_dp vd=%vd_dp
51
diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc
52
index XXXXXXX..XXXXXXX 100644
45
index XXXXXXX..XXXXXXX 100644
53
--- a/target/arm/translate-neon.c.inc
46
--- a/target/arm/translate-vfp.c.inc
54
+++ b/target/arm/translate-neon.c.inc
47
+++ b/target/arm/translate-vfp.c.inc
55
@@ -XXX,XX +XXX,XX @@ static bool trans_VCMLA(DisasContext *s, arg_VCMLA *a)
48
@@ -XXX,XX +XXX,XX @@ static bool trans_VDUP(DisasContext *s, arg_VDUP *a)
56
gen_helper_gvec_3_ptr *fn_gvec_ptr;
49
return true;
57
50
}
58
if (!dc_isar_feature(aa32_vcma, s)
51
59
- || (!a->size && !dc_isar_feature(aa32_fp16_arith, s))) {
52
+/*
60
+ || (a->size == MO_16 && !dc_isar_feature(aa32_fp16_arith, s))) {
53
+ * M-profile provides two different sets of instructions that can
61
return false;
54
+ * access floating point system registers: VMSR/VMRS (which move
55
+ * to/from a general purpose register) and VLDR/VSTR sysreg (which
56
+ * move directly to/from memory). In some cases there are also side
57
+ * effects which must happen after any write to memory (which could
58
+ * cause an exception). So we implement the common logic for the
59
+ * sysreg access in gen_M_fp_sysreg_write() and gen_M_fp_sysreg_read(),
60
+ * which take pointers to callback functions which will perform the
61
+ * actual "read/write general purpose register" and "read/write
62
+ * memory" operations.
63
+ */
64
+
65
+/*
66
+ * Emit code to store the sysreg to its final destination; frees the
67
+ * TCG temp 'value' it is passed.
68
+ */
69
+typedef void fp_sysreg_storefn(DisasContext *s, void *opaque, TCGv_i32 value);
70
+/*
71
+ * Emit code to load the value to be copied to the sysreg; returns
72
+ * a new TCG temporary
73
+ */
74
+typedef TCGv_i32 fp_sysreg_loadfn(DisasContext *s, void *opaque);
75
+
76
+/* Common decode/access checks for fp sysreg read/write */
77
+typedef enum FPSysRegCheckResult {
78
+ FPSysRegCheckFailed, /* caller should return false */
79
+ FPSysRegCheckDone, /* caller should return true */
80
+ FPSysRegCheckContinue, /* caller should continue generating code */
81
+} FPSysRegCheckResult;
82
+
83
+static FPSysRegCheckResult fp_sysreg_checks(DisasContext *s, int regno)
84
+{
85
+ if (!dc_isar_feature(aa32_fpsp_v2, s)) {
86
+ return FPSysRegCheckFailed;
87
+ }
88
+
89
+ switch (regno) {
90
+ case ARM_VFP_FPSCR:
91
+ case QEMU_VFP_FPSCR_NZCV:
92
+ break;
93
+ default:
94
+ return FPSysRegCheckFailed;
95
+ }
96
+
97
+ if (!vfp_access_check(s)) {
98
+ return FPSysRegCheckDone;
99
+ }
100
+
101
+ return FPSysRegCheckContinue;
102
+}
103
+
104
+static bool gen_M_fp_sysreg_write(DisasContext *s, int regno,
105
+
106
+ fp_sysreg_loadfn *loadfn,
107
+ void *opaque)
108
+{
109
+ /* Do a write to an M-profile floating point system register */
110
+ TCGv_i32 tmp;
111
+
112
+ switch (fp_sysreg_checks(s, regno)) {
113
+ case FPSysRegCheckFailed:
114
+ return false;
115
+ case FPSysRegCheckDone:
116
+ return true;
117
+ case FPSysRegCheckContinue:
118
+ break;
119
+ }
120
+
121
+ switch (regno) {
122
+ case ARM_VFP_FPSCR:
123
+ tmp = loadfn(s, opaque);
124
+ gen_helper_vfp_set_fpscr(cpu_env, tmp);
125
+ tcg_temp_free_i32(tmp);
126
+ gen_lookup_tb(s);
127
+ break;
128
+ default:
129
+ g_assert_not_reached();
130
+ }
131
+ return true;
132
+}
133
+
134
+static bool gen_M_fp_sysreg_read(DisasContext *s, int regno,
135
+ fp_sysreg_storefn *storefn,
136
+ void *opaque)
137
+{
138
+ /* Do a read from an M-profile floating point system register */
139
+ TCGv_i32 tmp;
140
+
141
+ switch (fp_sysreg_checks(s, regno)) {
142
+ case FPSysRegCheckFailed:
143
+ return false;
144
+ case FPSysRegCheckDone:
145
+ return true;
146
+ case FPSysRegCheckContinue:
147
+ break;
148
+ }
149
+
150
+ switch (regno) {
151
+ case ARM_VFP_FPSCR:
152
+ tmp = tcg_temp_new_i32();
153
+ gen_helper_vfp_get_fpscr(tmp, cpu_env);
154
+ storefn(s, opaque, tmp);
155
+ break;
156
+ case QEMU_VFP_FPSCR_NZCV:
157
+ /*
158
+ * Read just NZCV; this is a special case to avoid the
159
+ * helper call for the "VMRS to CPSR.NZCV" insn.
160
+ */
161
+ tmp = load_cpu_field(vfp.xregs[ARM_VFP_FPSCR]);
162
+ tcg_gen_andi_i32(tmp, tmp, 0xf0000000);
163
+ storefn(s, opaque, tmp);
164
+ break;
165
+ default:
166
+ g_assert_not_reached();
167
+ }
168
+ return true;
169
+}
170
+
171
+static void fp_sysreg_to_gpr(DisasContext *s, void *opaque, TCGv_i32 value)
172
+{
173
+ arg_VMSR_VMRS *a = opaque;
174
+
175
+ if (a->rt == 15) {
176
+ /* Set the 4 flag bits in the CPSR */
177
+ gen_set_nzcv(value);
178
+ tcg_temp_free_i32(value);
179
+ } else {
180
+ store_reg(s, a->rt, value);
181
+ }
182
+}
183
+
184
+static TCGv_i32 gpr_to_fp_sysreg(DisasContext *s, void *opaque)
185
+{
186
+ arg_VMSR_VMRS *a = opaque;
187
+
188
+ return load_reg(s, a->rt);
189
+}
190
+
191
+static bool gen_M_VMSR_VMRS(DisasContext *s, arg_VMSR_VMRS *a)
192
+{
193
+ /*
194
+ * Accesses to R15 are UNPREDICTABLE; we choose to undef.
195
+ * FPSCR -> r15 is a special case which writes to the PSR flags;
196
+ * set a->reg to a special value to tell gen_M_fp_sysreg_read()
197
+ * we only care about the top 4 bits of FPSCR there.
198
+ */
199
+ if (a->rt == 15) {
200
+ if (a->l && a->reg == ARM_VFP_FPSCR) {
201
+ a->reg = QEMU_VFP_FPSCR_NZCV;
202
+ } else {
203
+ return false;
204
+ }
205
+ }
206
+
207
+ if (a->l) {
208
+ /* VMRS, move FP system register to gp register */
209
+ return gen_M_fp_sysreg_read(s, a->reg, fp_sysreg_to_gpr, a);
210
+ } else {
211
+ /* VMSR, move gp register to FP system register */
212
+ return gen_M_fp_sysreg_write(s, a->reg, gpr_to_fp_sysreg, a);
213
+ }
214
+}
215
+
216
static bool trans_VMSR_VMRS(DisasContext *s, arg_VMSR_VMRS *a)
217
{
218
TCGv_i32 tmp;
219
bool ignore_vfp_enabled = false;
220
221
- if (!dc_isar_feature(aa32_fpsp_v2, s)) {
222
- return false;
223
+ if (arm_dc_feature(s, ARM_FEATURE_M)) {
224
+ return gen_M_VMSR_VMRS(s, a);
62
}
225
}
63
226
64
@@ -XXX,XX +XXX,XX @@ static bool trans_VCMLA(DisasContext *s, arg_VCMLA *a)
227
- if (arm_dc_feature(s, ARM_FEATURE_M)) {
228
- /*
229
- * The only M-profile VFP vmrs/vmsr sysreg is FPSCR.
230
- * Accesses to R15 are UNPREDICTABLE; we choose to undef.
231
- * (FPSCR -> r15 is a special case which writes to the PSR flags.)
232
- */
233
- if (a->reg != ARM_VFP_FPSCR) {
234
- return false;
235
- }
236
- if (a->rt == 15 && !a->l) {
237
- return false;
238
- }
239
+ if (!dc_isar_feature(aa32_fpsp_v2, s)) {
240
+ return false;
65
}
241
}
66
242
67
opr_sz = (1 + a->q) * 8;
243
switch (a->reg) {
68
- fpst = fpstatus_ptr(a->size == 0 ? FPST_STD_F16 : FPST_STD);
69
- fn_gvec_ptr = a->size ? gen_helper_gvec_fcmlas : gen_helper_gvec_fcmlah;
70
+ fpst = fpstatus_ptr(a->size == MO_16 ? FPST_STD_F16 : FPST_STD);
71
+ fn_gvec_ptr = (a->size == MO_16) ?
72
+ gen_helper_gvec_fcmlah : gen_helper_gvec_fcmlas;
73
tcg_gen_gvec_3_ptr(vfp_reg_offset(1, a->vd),
74
vfp_reg_offset(1, a->vn),
75
vfp_reg_offset(1, a->vm),
76
@@ -XXX,XX +XXX,XX @@ static bool trans_VCADD(DisasContext *s, arg_VCADD *a)
77
gen_helper_gvec_3_ptr *fn_gvec_ptr;
78
79
if (!dc_isar_feature(aa32_vcma, s)
80
- || (!a->size && !dc_isar_feature(aa32_fp16_arith, s))) {
81
+ || (a->size == MO_16 && !dc_isar_feature(aa32_fp16_arith, s))) {
82
return false;
83
}
84
85
@@ -XXX,XX +XXX,XX @@ static bool trans_VCADD(DisasContext *s, arg_VCADD *a)
86
}
87
88
opr_sz = (1 + a->q) * 8;
89
- fpst = fpstatus_ptr(a->size == 0 ? FPST_STD_F16 : FPST_STD);
90
- fn_gvec_ptr = a->size ? gen_helper_gvec_fcadds : gen_helper_gvec_fcaddh;
91
+ fpst = fpstatus_ptr(a->size == MO_16 ? FPST_STD_F16 : FPST_STD);
92
+ fn_gvec_ptr = (a->size == MO_16) ?
93
+ gen_helper_gvec_fcaddh : gen_helper_gvec_fcadds;
94
tcg_gen_gvec_3_ptr(vfp_reg_offset(1, a->vd),
95
vfp_reg_offset(1, a->vn),
96
vfp_reg_offset(1, a->vm),
97
@@ -XXX,XX +XXX,XX @@ static bool trans_VCMLA_scalar(DisasContext *s, arg_VCMLA_scalar *a)
98
if (!dc_isar_feature(aa32_vcma, s)) {
99
return false;
100
}
101
- if (a->size == 0 && !dc_isar_feature(aa32_fp16_arith, s)) {
102
+ if (a->size == MO_16 && !dc_isar_feature(aa32_fp16_arith, s)) {
103
return false;
104
}
105
106
@@ -XXX,XX +XXX,XX @@ static bool trans_VCMLA_scalar(DisasContext *s, arg_VCMLA_scalar *a)
107
return true;
108
}
109
110
- fn_gvec_ptr = (a->size ? gen_helper_gvec_fcmlas_idx
111
- : gen_helper_gvec_fcmlah_idx);
112
+ fn_gvec_ptr = (a->size == MO_16) ?
113
+ gen_helper_gvec_fcmlah_idx : gen_helper_gvec_fcmlas_idx;
114
opr_sz = (1 + a->q) * 8;
115
- fpst = fpstatus_ptr(a->size == 0 ? FPST_STD_F16 : FPST_STD);
116
+ fpst = fpstatus_ptr(a->size == MO_16 ? FPST_STD_F16 : FPST_STD);
117
tcg_gen_gvec_3_ptr(vfp_reg_offset(1, a->vd),
118
vfp_reg_offset(1, a->vn),
119
vfp_reg_offset(1, a->vm),
120
--
244
--
121
2.20.1
245
2.20.1
122
246
123
247
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
The constant-expander functions like negate, plus_2, etc, are
2
generally useful; move them up in translate.c so we can use them in
3
the VFP/Neon decoders as well as in the A32/T32/T16 decoders.
2
4
3
Implement a device model for the System Global Control Registers in the
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
NPCM730 and NPCM750 BMC SoCs.
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20201119215617.29887-9-peter.maydell@linaro.org
8
---
9
target/arm/translate.c | 46 +++++++++++++++++++++++-------------------
10
1 file changed, 25 insertions(+), 21 deletions(-)
5
11
6
This is primarily used to enable SMP boot (the boot ROM spins reading
12
diff --git a/target/arm/translate.c b/target/arm/translate.c
7
the SCRPAD register) and DDR memory initialization; other registers are
13
index XXXXXXX..XXXXXXX 100644
8
best effort for now.
14
--- a/target/arm/translate.c
9
15
+++ b/target/arm/translate.c
10
The reset values of the MDLR and PWRON registers are determined by the
16
@@ -XXX,XX +XXX,XX @@ static void arm_gen_condlabel(DisasContext *s)
11
SoC variant (730 vs 750) and board straps respectively.
17
}
12
18
}
13
Reviewed-by: Joel Stanley <joel@jms.id.au>
19
14
Reviewed-by: Cédric Le Goater <clg@kaod.org>
15
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
16
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
17
Tested-by: Alexander Bulekov <alxndr@bu.edu>
18
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
19
Message-id: 20200911052101.2602693-2-hskinnemoen@google.com
20
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
21
---
22
include/hw/misc/npcm7xx_gcr.h | 43 ++++++
23
hw/misc/npcm7xx_gcr.c | 269 ++++++++++++++++++++++++++++++++++
24
MAINTAINERS | 8 +
25
hw/arm/Kconfig | 3 +
26
hw/misc/meson.build | 3 +
27
hw/misc/trace-events | 4 +
28
6 files changed, 330 insertions(+)
29
create mode 100644 include/hw/misc/npcm7xx_gcr.h
30
create mode 100644 hw/misc/npcm7xx_gcr.c
31
32
diff --git a/include/hw/misc/npcm7xx_gcr.h b/include/hw/misc/npcm7xx_gcr.h
33
new file mode 100644
34
index XXXXXXX..XXXXXXX
35
--- /dev/null
36
+++ b/include/hw/misc/npcm7xx_gcr.h
37
@@ -XXX,XX +XXX,XX @@
38
+/*
20
+/*
39
+ * Nuvoton NPCM7xx System Global Control Registers.
21
+ * Constant expanders for the decoders.
40
+ *
41
+ * Copyright 2020 Google LLC
42
+ *
43
+ * This program is free software; you can redistribute it and/or modify it
44
+ * under the terms of the GNU General Public License as published by the
45
+ * Free Software Foundation; either version 2 of the License, or
46
+ * (at your option) any later version.
47
+ *
48
+ * This program is distributed in the hope that it will be useful, but WITHOUT
49
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
50
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
51
+ * for more details.
52
+ */
53
+#ifndef NPCM7XX_GCR_H
54
+#define NPCM7XX_GCR_H
55
+
56
+#include "exec/memory.h"
57
+#include "hw/sysbus.h"
58
+
59
+/*
60
+ * Number of registers in our device state structure. Don't change this without
61
+ * incrementing the version_id in the vmstate.
62
+ */
63
+#define NPCM7XX_GCR_NR_REGS (0x148 / sizeof(uint32_t))
64
+
65
+typedef struct NPCM7xxGCRState {
66
+ SysBusDevice parent;
67
+
68
+ MemoryRegion iomem;
69
+
70
+ uint32_t regs[NPCM7XX_GCR_NR_REGS];
71
+
72
+ uint32_t reset_pwron;
73
+ uint32_t reset_mdlr;
74
+ uint32_t reset_intcr3;
75
+} NPCM7xxGCRState;
76
+
77
+#define TYPE_NPCM7XX_GCR "npcm7xx-gcr"
78
+#define NPCM7XX_GCR(obj) OBJECT_CHECK(NPCM7xxGCRState, (obj), TYPE_NPCM7XX_GCR)
79
+
80
+#endif /* NPCM7XX_GCR_H */
81
diff --git a/hw/misc/npcm7xx_gcr.c b/hw/misc/npcm7xx_gcr.c
82
new file mode 100644
83
index XXXXXXX..XXXXXXX
84
--- /dev/null
85
+++ b/hw/misc/npcm7xx_gcr.c
86
@@ -XXX,XX +XXX,XX @@
87
+/*
88
+ * Nuvoton NPCM7xx System Global Control Registers.
89
+ *
90
+ * Copyright 2020 Google LLC
91
+ *
92
+ * This program is free software; you can redistribute it and/or modify it
93
+ * under the terms of the GNU General Public License as published by the
94
+ * Free Software Foundation; either version 2 of the License, or
95
+ * (at your option) any later version.
96
+ *
97
+ * This program is distributed in the hope that it will be useful, but WITHOUT
98
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
99
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
100
+ * for more details.
101
+ */
22
+ */
102
+
23
+
103
+#include "qemu/osdep.h"
24
+static int negate(DisasContext *s, int x)
104
+
105
+#include "hw/misc/npcm7xx_gcr.h"
106
+#include "hw/qdev-properties.h"
107
+#include "migration/vmstate.h"
108
+#include "qapi/error.h"
109
+#include "qemu/cutils.h"
110
+#include "qemu/log.h"
111
+#include "qemu/module.h"
112
+#include "qemu/units.h"
113
+
114
+#include "trace.h"
115
+
116
+#define NPCM7XX_GCR_MIN_DRAM_SIZE (128 * MiB)
117
+#define NPCM7XX_GCR_MAX_DRAM_SIZE (2 * GiB)
118
+
119
+enum NPCM7xxGCRRegisters {
120
+ NPCM7XX_GCR_PDID,
121
+ NPCM7XX_GCR_PWRON,
122
+ NPCM7XX_GCR_MFSEL1 = 0x0c / sizeof(uint32_t),
123
+ NPCM7XX_GCR_MFSEL2,
124
+ NPCM7XX_GCR_MISCPE,
125
+ NPCM7XX_GCR_SPSWC = 0x038 / sizeof(uint32_t),
126
+ NPCM7XX_GCR_INTCR,
127
+ NPCM7XX_GCR_INTSR,
128
+ NPCM7XX_GCR_HIFCR = 0x050 / sizeof(uint32_t),
129
+ NPCM7XX_GCR_INTCR2 = 0x060 / sizeof(uint32_t),
130
+ NPCM7XX_GCR_MFSEL3,
131
+ NPCM7XX_GCR_SRCNT,
132
+ NPCM7XX_GCR_RESSR,
133
+ NPCM7XX_GCR_RLOCKR1,
134
+ NPCM7XX_GCR_FLOCKR1,
135
+ NPCM7XX_GCR_DSCNT,
136
+ NPCM7XX_GCR_MDLR,
137
+ NPCM7XX_GCR_SCRPAD3,
138
+ NPCM7XX_GCR_SCRPAD2,
139
+ NPCM7XX_GCR_DAVCLVLR = 0x098 / sizeof(uint32_t),
140
+ NPCM7XX_GCR_INTCR3,
141
+ NPCM7XX_GCR_VSINTR = 0x0ac / sizeof(uint32_t),
142
+ NPCM7XX_GCR_MFSEL4,
143
+ NPCM7XX_GCR_CPBPNTR = 0x0c4 / sizeof(uint32_t),
144
+ NPCM7XX_GCR_CPCTL = 0x0d0 / sizeof(uint32_t),
145
+ NPCM7XX_GCR_CP2BST,
146
+ NPCM7XX_GCR_B2CPNT,
147
+ NPCM7XX_GCR_CPPCTL,
148
+ NPCM7XX_GCR_I2CSEGSEL,
149
+ NPCM7XX_GCR_I2CSEGCTL,
150
+ NPCM7XX_GCR_VSRCR,
151
+ NPCM7XX_GCR_MLOCKR,
152
+ NPCM7XX_GCR_SCRPAD = 0x013c / sizeof(uint32_t),
153
+ NPCM7XX_GCR_USB1PHYCTL,
154
+ NPCM7XX_GCR_USB2PHYCTL,
155
+ NPCM7XX_GCR_REGS_END,
156
+};
157
+
158
+static const uint32_t cold_reset_values[NPCM7XX_GCR_NR_REGS] = {
159
+ [NPCM7XX_GCR_PDID] = 0x04a92750, /* Poleg A1 */
160
+ [NPCM7XX_GCR_MISCPE] = 0x0000ffff,
161
+ [NPCM7XX_GCR_SPSWC] = 0x00000003,
162
+ [NPCM7XX_GCR_INTCR] = 0x0000035e,
163
+ [NPCM7XX_GCR_HIFCR] = 0x0000004e,
164
+ [NPCM7XX_GCR_INTCR2] = (1U << 19), /* DDR initialized */
165
+ [NPCM7XX_GCR_RESSR] = 0x80000000,
166
+ [NPCM7XX_GCR_DSCNT] = 0x000000c0,
167
+ [NPCM7XX_GCR_DAVCLVLR] = 0x5a00f3cf,
168
+ [NPCM7XX_GCR_SCRPAD] = 0x00000008,
169
+ [NPCM7XX_GCR_USB1PHYCTL] = 0x034730e4,
170
+ [NPCM7XX_GCR_USB2PHYCTL] = 0x034730e4,
171
+};
172
+
173
+static uint64_t npcm7xx_gcr_read(void *opaque, hwaddr offset, unsigned size)
174
+{
25
+{
175
+ uint32_t reg = offset / sizeof(uint32_t);
26
+ return -x;
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
+}
27
+}
189
+
28
+
190
+static void npcm7xx_gcr_write(void *opaque, hwaddr offset,
29
+static int plus_2(DisasContext *s, int x)
191
+ uint64_t v, unsigned size)
192
+{
30
+{
193
+ uint32_t reg = offset / sizeof(uint32_t);
31
+ return x + 2;
194
+ NPCM7xxGCRState *s = opaque;
195
+ uint32_t value = v;
196
+
197
+ trace_npcm7xx_gcr_write(offset, value);
198
+
199
+ if (reg >= NPCM7XX_GCR_NR_REGS) {
200
+ qemu_log_mask(LOG_GUEST_ERROR,
201
+ "%s: offset 0x%04" HWADDR_PRIx " out of range\n",
202
+ __func__, offset);
203
+ return;
204
+ }
205
+
206
+ switch (reg) {
207
+ case NPCM7XX_GCR_PDID:
208
+ case NPCM7XX_GCR_PWRON:
209
+ case NPCM7XX_GCR_INTSR:
210
+ qemu_log_mask(LOG_GUEST_ERROR,
211
+ "%s: register @ 0x%04" HWADDR_PRIx " is read-only\n",
212
+ __func__, offset);
213
+ return;
214
+
215
+ case NPCM7XX_GCR_RESSR:
216
+ case NPCM7XX_GCR_CP2BST:
217
+ /* Write 1 to clear */
218
+ value = s->regs[reg] & ~value;
219
+ break;
220
+
221
+ case NPCM7XX_GCR_RLOCKR1:
222
+ case NPCM7XX_GCR_MDLR:
223
+ /* Write 1 to set */
224
+ value |= s->regs[reg];
225
+ break;
226
+ };
227
+
228
+ s->regs[reg] = value;
229
+}
32
+}
230
+
33
+
231
+static const struct MemoryRegionOps npcm7xx_gcr_ops = {
34
+static int times_2(DisasContext *s, int x)
232
+ .read = npcm7xx_gcr_read,
233
+ .write = npcm7xx_gcr_write,
234
+ .endianness = DEVICE_LITTLE_ENDIAN,
235
+ .valid = {
236
+ .min_access_size = 4,
237
+ .max_access_size = 4,
238
+ .unaligned = false,
239
+ },
240
+};
241
+
242
+static void npcm7xx_gcr_enter_reset(Object *obj, ResetType type)
243
+{
35
+{
244
+ NPCM7xxGCRState *s = NPCM7XX_GCR(obj);
36
+ return x * 2;
245
+
246
+ QEMU_BUILD_BUG_ON(sizeof(s->regs) != sizeof(cold_reset_values));
247
+
248
+ switch (type) {
249
+ case RESET_TYPE_COLD:
250
+ memcpy(s->regs, cold_reset_values, sizeof(s->regs));
251
+ s->regs[NPCM7XX_GCR_PWRON] = s->reset_pwron;
252
+ s->regs[NPCM7XX_GCR_MDLR] = s->reset_mdlr;
253
+ s->regs[NPCM7XX_GCR_INTCR3] = s->reset_intcr3;
254
+ break;
255
+ }
256
+}
37
+}
257
+
38
+
258
+static void npcm7xx_gcr_realize(DeviceState *dev, Error **errp)
39
+static int times_4(DisasContext *s, int x)
259
+{
40
+{
260
+ ERRP_GUARD();
41
+ return x * 4;
261
+ NPCM7xxGCRState *s = NPCM7XX_GCR(dev);
262
+ uint64_t dram_size;
263
+ Object *obj;
264
+
265
+ obj = object_property_get_link(OBJECT(dev), "dram-mr", errp);
266
+ if (!obj) {
267
+ error_prepend(errp, "%s: required dram-mr link not found: ", __func__);
268
+ return;
269
+ }
270
+ dram_size = memory_region_size(MEMORY_REGION(obj));
271
+ if (!is_power_of_2(dram_size) ||
272
+ dram_size < NPCM7XX_GCR_MIN_DRAM_SIZE ||
273
+ dram_size > NPCM7XX_GCR_MAX_DRAM_SIZE) {
274
+ g_autofree char *sz = size_to_str(dram_size);
275
+ g_autofree char *min_sz = size_to_str(NPCM7XX_GCR_MIN_DRAM_SIZE);
276
+ g_autofree char *max_sz = size_to_str(NPCM7XX_GCR_MAX_DRAM_SIZE);
277
+ error_setg(errp, "%s: unsupported DRAM size %s", __func__, sz);
278
+ error_append_hint(errp,
279
+ "DRAM size must be a power of two between %s and %s,"
280
+ " inclusive.\n", min_sz, max_sz);
281
+ return;
282
+ }
283
+
284
+ /* Power-on reset value */
285
+ s->reset_intcr3 = 0x00001002;
286
+
287
+ /*
288
+ * The GMMAP (Graphics Memory Map) field is used by u-boot to detect the
289
+ * DRAM size, and is normally initialized by the boot block as part of DRAM
290
+ * training. However, since we don't have a complete emulation of the
291
+ * memory controller and try to make it look like it has already been
292
+ * initialized, the boot block will skip this initialization, and we need
293
+ * to make sure this field is set correctly up front.
294
+ *
295
+ * WARNING: some versions of u-boot only looks at bits 8 and 9, so 2 GiB of
296
+ * DRAM will be interpreted as 128 MiB.
297
+ *
298
+ * https://github.com/Nuvoton-Israel/u-boot/blob/2aef993bd2aafeb5408dbaad0f3ce099ee40c4aa/board/nuvoton/poleg/poleg.c#L244
299
+ */
300
+ s->reset_intcr3 |= ctz64(dram_size / NPCM7XX_GCR_MIN_DRAM_SIZE) << 8;
301
+}
42
+}
302
+
43
+
303
+static void npcm7xx_gcr_init(Object *obj)
44
/* Flags for the disas_set_da_iss info argument:
304
+{
45
* lower bits hold the Rt register number, higher bits are flags.
305
+ NPCM7xxGCRState *s = NPCM7XX_GCR(obj);
46
*/
306
+
47
@@ -XXX,XX +XXX,XX @@ static void arm_skip_unless(DisasContext *s, uint32_t cond)
307
+ memory_region_init_io(&s->iomem, obj, &npcm7xx_gcr_ops, s,
48
308
+ TYPE_NPCM7XX_GCR, 4 * KiB);
49
309
+ sysbus_init_mmio(&s->parent, &s->iomem);
50
/*
310
+}
51
- * Constant expanders for the decoders.
311
+
52
+ * Constant expanders used by T16/T32 decode
312
+static const VMStateDescription vmstate_npcm7xx_gcr = {
53
*/
313
+ .name = "npcm7xx-gcr",
54
314
+ .version_id = 0,
55
-static int negate(DisasContext *s, int x)
315
+ .minimum_version_id = 0,
56
-{
316
+ .fields = (VMStateField[]) {
57
- return -x;
317
+ VMSTATE_UINT32_ARRAY(regs, NPCM7xxGCRState, NPCM7XX_GCR_NR_REGS),
58
-}
318
+ VMSTATE_END_OF_LIST(),
59
-
319
+ },
60
-static int plus_2(DisasContext *s, int x)
320
+};
61
-{
321
+
62
- return x + 2;
322
+static Property npcm7xx_gcr_properties[] = {
63
-}
323
+ DEFINE_PROP_UINT32("disabled-modules", NPCM7xxGCRState, reset_mdlr, 0),
64
-
324
+ DEFINE_PROP_UINT32("power-on-straps", NPCM7xxGCRState, reset_pwron, 0),
65
-static int times_2(DisasContext *s, int x)
325
+ DEFINE_PROP_END_OF_LIST(),
66
-{
326
+};
67
- return x * 2;
327
+
68
-}
328
+static void npcm7xx_gcr_class_init(ObjectClass *klass, void *data)
69
-
329
+{
70
-static int times_4(DisasContext *s, int x)
330
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
71
-{
331
+ DeviceClass *dc = DEVICE_CLASS(klass);
72
- return x * 4;
332
+
73
-}
333
+ QEMU_BUILD_BUG_ON(NPCM7XX_GCR_REGS_END > NPCM7XX_GCR_NR_REGS);
74
-
334
+
75
/* Return only the rotation part of T32ExpandImm. */
335
+ dc->desc = "NPCM7xx System Global Control Registers";
76
static int t32_expandimm_rot(DisasContext *s, int x)
336
+ dc->realize = npcm7xx_gcr_realize;
77
{
337
+ dc->vmsd = &vmstate_npcm7xx_gcr;
338
+ rc->phases.enter = npcm7xx_gcr_enter_reset;
339
+
340
+ device_class_set_props(dc, npcm7xx_gcr_properties);
341
+}
342
+
343
+static const TypeInfo npcm7xx_gcr_info = {
344
+ .name = TYPE_NPCM7XX_GCR,
345
+ .parent = TYPE_SYS_BUS_DEVICE,
346
+ .instance_size = sizeof(NPCM7xxGCRState),
347
+ .instance_init = npcm7xx_gcr_init,
348
+ .class_init = npcm7xx_gcr_class_init,
349
+};
350
+
351
+static void npcm7xx_gcr_register_type(void)
352
+{
353
+ type_register_static(&npcm7xx_gcr_info);
354
+}
355
+type_init(npcm7xx_gcr_register_type);
356
diff --git a/MAINTAINERS b/MAINTAINERS
357
index XXXXXXX..XXXXXXX 100644
358
--- a/MAINTAINERS
359
+++ b/MAINTAINERS
360
@@ -XXX,XX +XXX,XX @@ S: Odd Fixes
361
F: hw/arm/musicpal.c
362
F: docs/system/arm/musicpal.rst
363
364
+Nuvoton NPCM7xx
365
+M: Havard Skinnemoen <hskinnemoen@google.com>
366
+M: Tyrone Ting <kfting@nuvoton.com>
367
+L: qemu-arm@nongnu.org
368
+S: Supported
369
+F: hw/*/npcm7xx*
370
+F: include/hw/*/npcm7xx*
371
+
372
nSeries
373
M: Andrzej Zaborowski <balrogg@gmail.com>
374
M: Peter Maydell <peter.maydell@linaro.org>
375
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
376
index XXXXXXX..XXXXXXX 100644
377
--- a/hw/arm/Kconfig
378
+++ b/hw/arm/Kconfig
379
@@ -XXX,XX +XXX,XX @@ config XLNX_VERSAL
380
select VIRTIO_MMIO
381
select UNIMP
382
383
+config NPCM7XX
384
+ bool
385
+
386
config FSL_IMX25
387
bool
388
select IMX
389
diff --git a/hw/misc/meson.build b/hw/misc/meson.build
390
index XXXXXXX..XXXXXXX 100644
391
--- a/hw/misc/meson.build
392
+++ b/hw/misc/meson.build
393
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_IMX', if_true: files(
394
))
395
softmmu_ss.add(when: 'CONFIG_MILKYMIST', if_true: files('milkymist-hpdmc.c', 'milkymist-pfpu.c'))
396
softmmu_ss.add(when: 'CONFIG_MAINSTONE', if_true: files('mst_fpga.c'))
397
+softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files(
398
+ 'npcm7xx_gcr.c',
399
+))
400
softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files(
401
'omap_clk.c',
402
'omap_gpmc.c',
403
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
404
index XXXXXXX..XXXXXXX 100644
405
--- a/hw/misc/trace-events
406
+++ b/hw/misc/trace-events
407
@@ -XXX,XX +XXX,XX @@ mos6522_set_sr_int(void) "set sr_int"
408
mos6522_write(uint64_t addr, uint64_t val) "reg=0x%"PRIx64 " val=0x%"PRIx64
409
mos6522_read(uint64_t addr, unsigned val) "reg=0x%"PRIx64 " val=0x%x"
410
411
+# npcm7xx_gcr.c
412
+npcm7xx_gcr_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
413
+npcm7xx_gcr_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
414
+
415
# stm32f4xx_syscfg.c
416
stm32f4xx_syscfg_set_irq(int gpio, int line, int level) "Interupt: GPIO: %d, Line: %d; Level: %d"
417
stm32f4xx_pulse_exti(int irq) "Pulse EXTI: %d"
418
--
78
--
419
2.20.1
79
2.20.1
420
80
421
81
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
Implement the new-in-v8.1M VLDR/VSTR variants which directly
2
read or write FP system registers to memory.
2
3
3
The Nuvoton NPCM7xx SoC family are used to implement Baseboard
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
Management Controllers in servers. While the family includes four SoCs,
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
this patch implements limited support for two of them: NPCM730 (targeted
6
Message-id: 20201119215617.29887-10-peter.maydell@linaro.org
6
for Data Center applications) and NPCM750 (targeted for Enterprise
7
---
7
applications).
8
target/arm/vfp.decode | 14 ++++++
9
target/arm/translate-vfp.c.inc | 91 ++++++++++++++++++++++++++++++++++
10
2 files changed, 105 insertions(+)
8
11
9
This patch includes little more than the bare minimum needed to boot a
12
diff --git a/target/arm/vfp.decode b/target/arm/vfp.decode
10
Linux kernel built with NPCM7xx support in direct-kernel mode:
13
index XXXXXXX..XXXXXXX 100644
11
14
--- a/target/arm/vfp.decode
12
- Two Cortex-A9 CPU cores with built-in periperhals.
15
+++ b/target/arm/vfp.decode
13
- Global Configuration Registers.
16
@@ -XXX,XX +XXX,XX @@ VLDR_VSTR_hp ---- 1101 u:1 .0 l:1 rn:4 .... 1001 imm:8 vd=%vd_sp
14
- Clock Management.
17
VLDR_VSTR_sp ---- 1101 u:1 .0 l:1 rn:4 .... 1010 imm:8 vd=%vd_sp
15
- 3 Timer Modules with 5 timers each.
18
VLDR_VSTR_dp ---- 1101 u:1 .0 l:1 rn:4 .... 1011 imm:8 vd=%vd_dp
16
- 4 serial ports.
19
17
20
+# M-profile VLDR/VSTR to sysreg
18
The chips themselves have a lot more features, some of which will be
21
+%vldr_sysreg 22:1 13:3
19
added to the model at a later stage.
22
+%imm7_0x4 0:7 !function=times_4
20
21
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
22
Reviewed-by: Joel Stanley <joel@jms.id.au>
23
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
24
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
25
Tested-by: Alexander Bulekov <alxndr@bu.edu>
26
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
27
Message-id: 20200911052101.2602693-5-hskinnemoen@google.com
28
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
29
---
30
include/hw/arm/npcm7xx.h | 85 ++++++++
31
hw/arm/npcm7xx.c | 407 +++++++++++++++++++++++++++++++++++++++
32
hw/arm/Kconfig | 5 +
33
hw/arm/meson.build | 1 +
34
4 files changed, 498 insertions(+)
35
create mode 100644 include/hw/arm/npcm7xx.h
36
create mode 100644 hw/arm/npcm7xx.c
37
38
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
39
new file mode 100644
40
index XXXXXXX..XXXXXXX
41
--- /dev/null
42
+++ b/include/hw/arm/npcm7xx.h
43
@@ -XXX,XX +XXX,XX @@
44
+/*
45
+ * Nuvoton NPCM7xx SoC family.
46
+ *
47
+ * Copyright 2020 Google LLC
48
+ *
49
+ * This program is free software; you can redistribute it and/or modify it
50
+ * under the terms of the GNU General Public License as published by the
51
+ * Free Software Foundation; either version 2 of the License, or
52
+ * (at your option) any later version.
53
+ *
54
+ * This program is distributed in the hope that it will be useful, but WITHOUT
55
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
56
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
57
+ * for more details.
58
+ */
59
+#ifndef NPCM7XX_H
60
+#define NPCM7XX_H
61
+
23
+
62
+#include "hw/boards.h"
24
+&vldr_sysreg rn reg imm a w p
63
+#include "hw/cpu/a9mpcore.h"
25
+@vldr_sysreg .... ... . a:1 . . . rn:4 ... . ... .. ....... \
64
+#include "hw/misc/npcm7xx_clk.h"
26
+ reg=%vldr_sysreg imm=%imm7_0x4 &vldr_sysreg
65
+#include "hw/misc/npcm7xx_gcr.h"
66
+#include "hw/timer/npcm7xx_timer.h"
67
+#include "target/arm/cpu.h"
68
+
27
+
69
+#define NPCM7XX_MAX_NUM_CPUS (2)
28
+# P=0 W=0 is SEE "Related encodings", so split into two patterns
29
+VLDR_sysreg ---- 110 1 . . w:1 1 .... ... 0 111 11 ....... @vldr_sysreg p=1
30
+VLDR_sysreg ---- 110 0 . . 1 1 .... ... 0 111 11 ....... @vldr_sysreg p=0 w=1
31
+VSTR_sysreg ---- 110 1 . . w:1 0 .... ... 0 111 11 ....... @vldr_sysreg p=1
32
+VSTR_sysreg ---- 110 0 . . 1 0 .... ... 0 111 11 ....... @vldr_sysreg p=0 w=1
70
+
33
+
71
+/* The first half of the address space is reserved for DDR4 DRAM. */
34
# We split the load/store multiple up into two patterns to avoid
72
+#define NPCM7XX_DRAM_BA (0x00000000)
35
# overlap with other insns in the "Advanced SIMD load/store and 64-bit move"
73
+#define NPCM7XX_DRAM_SZ (2 * GiB)
36
# grouping:
37
diff --git a/target/arm/translate-vfp.c.inc b/target/arm/translate-vfp.c.inc
38
index XXXXXXX..XXXXXXX 100644
39
--- a/target/arm/translate-vfp.c.inc
40
+++ b/target/arm/translate-vfp.c.inc
41
@@ -XXX,XX +XXX,XX @@ static bool trans_VMSR_VMRS(DisasContext *s, arg_VMSR_VMRS *a)
42
return true;
43
}
44
45
+static void fp_sysreg_to_memory(DisasContext *s, void *opaque, TCGv_i32 value)
46
+{
47
+ arg_vldr_sysreg *a = opaque;
48
+ uint32_t offset = a->imm;
49
+ TCGv_i32 addr;
74
+
50
+
75
+/* Magic addresses for setting up direct kernel booting and SMP boot stubs. */
51
+ if (!a->a) {
76
+#define NPCM7XX_LOADER_START (0x00000000) /* Start of SDRAM */
52
+ offset = - offset;
77
+#define NPCM7XX_SMP_LOADER_START (0xffff0000) /* Boot ROM */
78
+#define NPCM7XX_SMP_BOOTREG_ADDR (0xf080013c) /* GCR.SCRPAD */
79
+#define NPCM7XX_GIC_CPU_IF_ADDR (0xf03fe100) /* GIC within A9 */
80
+
81
+typedef struct NPCM7xxState {
82
+ DeviceState parent;
83
+
84
+ ARMCPU cpu[NPCM7XX_MAX_NUM_CPUS];
85
+ A9MPPrivState a9mpcore;
86
+
87
+ MemoryRegion sram;
88
+ MemoryRegion irom;
89
+ MemoryRegion ram3;
90
+ MemoryRegion *dram;
91
+
92
+ NPCM7xxGCRState gcr;
93
+ NPCM7xxCLKState clk;
94
+ NPCM7xxTimerCtrlState tim[3];
95
+} NPCM7xxState;
96
+
97
+#define TYPE_NPCM7XX "npcm7xx"
98
+#define NPCM7XX(obj) OBJECT_CHECK(NPCM7xxState, (obj), TYPE_NPCM7XX)
99
+
100
+#define TYPE_NPCM730 "npcm730"
101
+#define TYPE_NPCM750 "npcm750"
102
+
103
+typedef struct NPCM7xxClass {
104
+ DeviceClass parent;
105
+
106
+ /* Bitmask of modules that are permanently disabled on this chip. */
107
+ uint32_t disabled_modules;
108
+ /* Number of CPU cores enabled in this SoC class (may be 1 or 2). */
109
+ uint32_t num_cpus;
110
+} NPCM7xxClass;
111
+
112
+#define NPCM7XX_CLASS(klass) \
113
+ OBJECT_CLASS_CHECK(NPCM7xxClass, (klass), TYPE_NPCM7XX)
114
+#define NPCM7XX_GET_CLASS(obj) \
115
+ OBJECT_GET_CLASS(NPCM7xxClass, (obj), TYPE_NPCM7XX)
116
+
117
+/**
118
+ * npcm7xx_load_kernel - Loads memory with everything needed to boot
119
+ * @machine - The machine containing the SoC to be booted.
120
+ * @soc - The SoC containing the CPU to be booted.
121
+ *
122
+ * This will set up the ARM boot info structure for the specific NPCM7xx
123
+ * derivative and call arm_load_kernel() to set up loading of the kernel, etc.
124
+ * into memory, if requested by the user.
125
+ */
126
+void npcm7xx_load_kernel(MachineState *machine, NPCM7xxState *soc);
127
+
128
+#endif /* NPCM7XX_H */
129
diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c
130
new file mode 100644
131
index XXXXXXX..XXXXXXX
132
--- /dev/null
133
+++ b/hw/arm/npcm7xx.c
134
@@ -XXX,XX +XXX,XX @@
135
+/*
136
+ * Nuvoton NPCM7xx SoC family.
137
+ *
138
+ * Copyright 2020 Google LLC
139
+ *
140
+ * This program is free software; you can redistribute it and/or modify it
141
+ * under the terms of the GNU General Public License as published by the
142
+ * Free Software Foundation; either version 2 of the License, or
143
+ * (at your option) any later version.
144
+ *
145
+ * This program is distributed in the hope that it will be useful, but WITHOUT
146
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
147
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
148
+ * for more details.
149
+ */
150
+
151
+#include "qemu/osdep.h"
152
+
153
+#include "exec/address-spaces.h"
154
+#include "hw/arm/boot.h"
155
+#include "hw/arm/npcm7xx.h"
156
+#include "hw/char/serial.h"
157
+#include "hw/loader.h"
158
+#include "hw/misc/unimp.h"
159
+#include "hw/qdev-properties.h"
160
+#include "qapi/error.h"
161
+#include "qemu/units.h"
162
+#include "sysemu/sysemu.h"
163
+
164
+/*
165
+ * This covers the whole MMIO space. We'll use this to catch any MMIO accesses
166
+ * that aren't handled by any device.
167
+ */
168
+#define NPCM7XX_MMIO_BA (0x80000000)
169
+#define NPCM7XX_MMIO_SZ (0x7ffd0000)
170
+
171
+/* Core system modules. */
172
+#define NPCM7XX_L2C_BA (0xf03fc000)
173
+#define NPCM7XX_CPUP_BA (0xf03fe000)
174
+#define NPCM7XX_GCR_BA (0xf0800000)
175
+#define NPCM7XX_CLK_BA (0xf0801000)
176
+
177
+/* Internal AHB SRAM */
178
+#define NPCM7XX_RAM3_BA (0xc0008000)
179
+#define NPCM7XX_RAM3_SZ (4 * KiB)
180
+
181
+/* Memory blocks at the end of the address space */
182
+#define NPCM7XX_RAM2_BA (0xfffd0000)
183
+#define NPCM7XX_RAM2_SZ (128 * KiB)
184
+#define NPCM7XX_ROM_BA (0xffff0000)
185
+#define NPCM7XX_ROM_SZ (64 * KiB)
186
+
187
+/*
188
+ * Interrupt lines going into the GIC. This does not include internal Cortex-A9
189
+ * interrupts.
190
+ */
191
+enum NPCM7xxInterrupt {
192
+ NPCM7XX_UART0_IRQ = 2,
193
+ NPCM7XX_UART1_IRQ,
194
+ NPCM7XX_UART2_IRQ,
195
+ NPCM7XX_UART3_IRQ,
196
+ NPCM7XX_TIMER0_IRQ = 32, /* Timer Module 0 */
197
+ NPCM7XX_TIMER1_IRQ,
198
+ NPCM7XX_TIMER2_IRQ,
199
+ NPCM7XX_TIMER3_IRQ,
200
+ NPCM7XX_TIMER4_IRQ,
201
+ NPCM7XX_TIMER5_IRQ, /* Timer Module 1 */
202
+ NPCM7XX_TIMER6_IRQ,
203
+ NPCM7XX_TIMER7_IRQ,
204
+ NPCM7XX_TIMER8_IRQ,
205
+ NPCM7XX_TIMER9_IRQ,
206
+ NPCM7XX_TIMER10_IRQ, /* Timer Module 2 */
207
+ NPCM7XX_TIMER11_IRQ,
208
+ NPCM7XX_TIMER12_IRQ,
209
+ NPCM7XX_TIMER13_IRQ,
210
+ NPCM7XX_TIMER14_IRQ,
211
+};
212
+
213
+/* Total number of GIC interrupts, including internal Cortex-A9 interrupts. */
214
+#define NPCM7XX_NUM_IRQ (160)
215
+
216
+/* Register base address for each Timer Module */
217
+static const hwaddr npcm7xx_tim_addr[] = {
218
+ 0xf0008000,
219
+ 0xf0009000,
220
+ 0xf000a000,
221
+};
222
+
223
+/* Register base address for each 16550 UART */
224
+static const hwaddr npcm7xx_uart_addr[] = {
225
+ 0xf0001000,
226
+ 0xf0002000,
227
+ 0xf0003000,
228
+ 0xf0004000,
229
+};
230
+
231
+static void npcm7xx_write_secondary_boot(ARMCPU *cpu,
232
+ const struct arm_boot_info *info)
233
+{
234
+ /*
235
+ * The default smpboot stub halts the secondary CPU with a 'wfi'
236
+ * instruction, but the arch/arm/mach-npcm/platsmp.c in the Linux kernel
237
+ * does not send an IPI to wake it up, so the second CPU fails to boot. So
238
+ * we need to provide our own smpboot stub that can not use 'wfi', it has
239
+ * to spin the secondary CPU until the first CPU writes to the SCRPAD reg.
240
+ */
241
+ uint32_t smpboot[] = {
242
+ 0xe59f2018, /* ldr r2, bootreg_addr */
243
+ 0xe3a00000, /* mov r0, #0 */
244
+ 0xe5820000, /* str r0, [r2] */
245
+ 0xe320f002, /* wfe */
246
+ 0xe5921000, /* ldr r1, [r2] */
247
+ 0xe1110001, /* tst r1, r1 */
248
+ 0x0afffffb, /* beq <wfe> */
249
+ 0xe12fff11, /* bx r1 */
250
+ NPCM7XX_SMP_BOOTREG_ADDR,
251
+ };
252
+ int i;
253
+
254
+ for (i = 0; i < ARRAY_SIZE(smpboot); i++) {
255
+ smpboot[i] = tswap32(smpboot[i]);
256
+ }
53
+ }
257
+
54
+
258
+ rom_add_blob_fixed("smpboot", smpboot, sizeof(smpboot),
55
+ addr = load_reg(s, a->rn);
259
+ NPCM7XX_SMP_LOADER_START);
56
+ if (a->p) {
260
+}
57
+ tcg_gen_addi_i32(addr, addr, offset);
261
+
262
+static struct arm_boot_info npcm7xx_binfo = {
263
+ .loader_start = NPCM7XX_LOADER_START,
264
+ .smp_loader_start = NPCM7XX_SMP_LOADER_START,
265
+ .smp_bootreg_addr = NPCM7XX_SMP_BOOTREG_ADDR,
266
+ .gic_cpu_if_addr = NPCM7XX_GIC_CPU_IF_ADDR,
267
+ .write_secondary_boot = npcm7xx_write_secondary_boot,
268
+ .board_id = -1,
269
+};
270
+
271
+void npcm7xx_load_kernel(MachineState *machine, NPCM7xxState *soc)
272
+{
273
+ NPCM7xxClass *sc = NPCM7XX_GET_CLASS(soc);
274
+
275
+ npcm7xx_binfo.ram_size = machine->ram_size;
276
+ npcm7xx_binfo.nb_cpus = sc->num_cpus;
277
+
278
+ arm_load_kernel(&soc->cpu[0], machine, &npcm7xx_binfo);
279
+}
280
+
281
+static qemu_irq npcm7xx_irq(NPCM7xxState *s, int n)
282
+{
283
+ return qdev_get_gpio_in(DEVICE(&s->a9mpcore), n);
284
+}
285
+
286
+static void npcm7xx_init(Object *obj)
287
+{
288
+ NPCM7xxState *s = NPCM7XX(obj);
289
+ int i;
290
+
291
+ for (i = 0; i < NPCM7XX_MAX_NUM_CPUS; i++) {
292
+ object_initialize_child(obj, "cpu[*]", &s->cpu[i],
293
+ ARM_CPU_TYPE_NAME("cortex-a9"));
294
+ }
58
+ }
295
+
59
+
296
+ object_initialize_child(obj, "a9mpcore", &s->a9mpcore, TYPE_A9MPCORE_PRIV);
60
+ if (s->v8m_stackcheck && a->rn == 13 && a->w) {
297
+ object_initialize_child(obj, "gcr", &s->gcr, TYPE_NPCM7XX_GCR);
61
+ gen_helper_v8m_stackcheck(cpu_env, addr);
298
+ object_property_add_alias(obj, "power-on-straps", OBJECT(&s->gcr),
62
+ }
299
+ "power-on-straps");
300
+ object_initialize_child(obj, "clk", &s->clk, TYPE_NPCM7XX_CLK);
301
+
63
+
302
+ for (i = 0; i < ARRAY_SIZE(s->tim); i++) {
64
+ gen_aa32_st_i32(s, value, addr, get_mem_index(s),
303
+ object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER);
65
+ MO_UL | MO_ALIGN | s->be_data);
66
+ tcg_temp_free_i32(value);
67
+
68
+ if (a->w) {
69
+ /* writeback */
70
+ if (!a->p) {
71
+ tcg_gen_addi_i32(addr, addr, offset);
72
+ }
73
+ store_reg(s, a->rn, addr);
74
+ } else {
75
+ tcg_temp_free_i32(addr);
304
+ }
76
+ }
305
+}
77
+}
306
+
78
+
307
+static void npcm7xx_realize(DeviceState *dev, Error **errp)
79
+static TCGv_i32 memory_to_fp_sysreg(DisasContext *s, void *opaque)
308
+{
80
+{
309
+ NPCM7xxState *s = NPCM7XX(dev);
81
+ arg_vldr_sysreg *a = opaque;
310
+ NPCM7xxClass *nc = NPCM7XX_GET_CLASS(s);
82
+ uint32_t offset = a->imm;
311
+ int i;
83
+ TCGv_i32 addr;
84
+ TCGv_i32 value = tcg_temp_new_i32();
312
+
85
+
313
+ if (memory_region_size(s->dram) > NPCM7XX_DRAM_SZ) {
86
+ if (!a->a) {
314
+ error_setg(errp, "%s: NPCM7xx cannot address more than %" PRIu64
87
+ offset = - offset;
315
+ " MiB of DRAM", __func__, NPCM7XX_DRAM_SZ / MiB);
316
+ return;
317
+ }
88
+ }
318
+
89
+
319
+ /* CPUs */
90
+ addr = load_reg(s, a->rn);
320
+ for (i = 0; i < nc->num_cpus; i++) {
91
+ if (a->p) {
321
+ object_property_set_int(OBJECT(&s->cpu[i]), "mp-affinity",
92
+ tcg_gen_addi_i32(addr, addr, offset);
322
+ arm_cpu_mp_affinity(i, NPCM7XX_MAX_NUM_CPUS),
323
+ &error_abort);
324
+ object_property_set_int(OBJECT(&s->cpu[i]), "reset-cbar",
325
+ NPCM7XX_GIC_CPU_IF_ADDR, &error_abort);
326
+ object_property_set_bool(OBJECT(&s->cpu[i]), "reset-hivecs", true,
327
+ &error_abort);
328
+
329
+ /* Disable security extensions. */
330
+ object_property_set_bool(OBJECT(&s->cpu[i]), "has_el3", false,
331
+ &error_abort);
332
+
333
+ if (!qdev_realize(DEVICE(&s->cpu[i]), NULL, errp)) {
334
+ return;
335
+ }
336
+ }
93
+ }
337
+
94
+
338
+ /* A9MPCORE peripherals. Can only fail if we pass bad parameters here. */
95
+ if (s->v8m_stackcheck && a->rn == 13 && a->w) {
339
+ object_property_set_int(OBJECT(&s->a9mpcore), "num-cpu", nc->num_cpus,
96
+ gen_helper_v8m_stackcheck(cpu_env, addr);
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
+ }
97
+ }
352
+
98
+
353
+ /* L2 cache controller */
99
+ gen_aa32_ld_i32(s, value, addr, get_mem_index(s),
354
+ sysbus_create_simple("l2x0", NPCM7XX_L2C_BA, NULL);
100
+ MO_UL | MO_ALIGN | s->be_data);
355
+
101
+
356
+ /* System Global Control Registers (GCR). Can fail due to user input. */
102
+ if (a->w) {
357
+ object_property_set_int(OBJECT(&s->gcr), "disabled-modules",
103
+ /* writeback */
358
+ nc->disabled_modules, &error_abort);
104
+ if (!a->p) {
359
+ object_property_add_const_link(OBJECT(&s->gcr), "dram-mr", OBJECT(s->dram));
105
+ tcg_gen_addi_i32(addr, addr, offset);
360
+ if (!sysbus_realize(SYS_BUS_DEVICE(&s->gcr), errp)) {
106
+ }
361
+ return;
107
+ store_reg(s, a->rn, addr);
108
+ } else {
109
+ tcg_temp_free_i32(addr);
362
+ }
110
+ }
363
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->gcr), 0, NPCM7XX_GCR_BA);
111
+ return value;
364
+
365
+ /* Clock Control Registers (CLK). Cannot fail. */
366
+ sysbus_realize(SYS_BUS_DEVICE(&s->clk), &error_abort);
367
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->clk), 0, NPCM7XX_CLK_BA);
368
+
369
+ /* Timer Modules (TIM). Cannot fail. */
370
+ QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_tim_addr) != ARRAY_SIZE(s->tim));
371
+ for (i = 0; i < ARRAY_SIZE(s->tim); i++) {
372
+ SysBusDevice *sbd = SYS_BUS_DEVICE(&s->tim[i]);
373
+ int first_irq;
374
+ int j;
375
+
376
+ sysbus_realize(sbd, &error_abort);
377
+ sysbus_mmio_map(sbd, 0, npcm7xx_tim_addr[i]);
378
+
379
+ first_irq = NPCM7XX_TIMER0_IRQ + i * NPCM7XX_TIMERS_PER_CTRL;
380
+ for (j = 0; j < NPCM7XX_TIMERS_PER_CTRL; j++) {
381
+ qemu_irq irq = npcm7xx_irq(s, first_irq + j);
382
+ sysbus_connect_irq(sbd, j, irq);
383
+ }
384
+ }
385
+
386
+ /* UART0..3 (16550 compatible) */
387
+ for (i = 0; i < ARRAY_SIZE(npcm7xx_uart_addr); i++) {
388
+ serial_mm_init(get_system_memory(), npcm7xx_uart_addr[i], 2,
389
+ npcm7xx_irq(s, NPCM7XX_UART0_IRQ + i), 115200,
390
+ serial_hd(i), DEVICE_LITTLE_ENDIAN);
391
+ }
392
+
393
+ /* RAM2 (SRAM) */
394
+ memory_region_init_ram(&s->sram, OBJECT(dev), "ram2",
395
+ NPCM7XX_RAM2_SZ, &error_abort);
396
+ memory_region_add_subregion(get_system_memory(), NPCM7XX_RAM2_BA, &s->sram);
397
+
398
+ /* RAM3 (SRAM) */
399
+ memory_region_init_ram(&s->ram3, OBJECT(dev), "ram3",
400
+ NPCM7XX_RAM3_SZ, &error_abort);
401
+ memory_region_add_subregion(get_system_memory(), NPCM7XX_RAM3_BA, &s->ram3);
402
+
403
+ /* Internal ROM */
404
+ memory_region_init_rom(&s->irom, OBJECT(dev), "irom", NPCM7XX_ROM_SZ,
405
+ &error_abort);
406
+ memory_region_add_subregion(get_system_memory(), NPCM7XX_ROM_BA, &s->irom);
407
+
408
+ create_unimplemented_device("npcm7xx.shm", 0xc0001000, 4 * KiB);
409
+ create_unimplemented_device("npcm7xx.vdmx", 0xe0800000, 4 * KiB);
410
+ create_unimplemented_device("npcm7xx.pcierc", 0xe1000000, 64 * KiB);
411
+ create_unimplemented_device("npcm7xx.kcs", 0xf0007000, 4 * KiB);
412
+ create_unimplemented_device("npcm7xx.rng", 0xf000b000, 4 * KiB);
413
+ create_unimplemented_device("npcm7xx.adc", 0xf000c000, 4 * KiB);
414
+ create_unimplemented_device("npcm7xx.gfxi", 0xf000e000, 4 * KiB);
415
+ create_unimplemented_device("npcm7xx.gpio[0]", 0xf0010000, 4 * KiB);
416
+ create_unimplemented_device("npcm7xx.gpio[1]", 0xf0011000, 4 * KiB);
417
+ create_unimplemented_device("npcm7xx.gpio[2]", 0xf0012000, 4 * KiB);
418
+ create_unimplemented_device("npcm7xx.gpio[3]", 0xf0013000, 4 * KiB);
419
+ create_unimplemented_device("npcm7xx.gpio[4]", 0xf0014000, 4 * KiB);
420
+ create_unimplemented_device("npcm7xx.gpio[5]", 0xf0015000, 4 * KiB);
421
+ create_unimplemented_device("npcm7xx.gpio[6]", 0xf0016000, 4 * KiB);
422
+ create_unimplemented_device("npcm7xx.gpio[7]", 0xf0017000, 4 * KiB);
423
+ create_unimplemented_device("npcm7xx.smbus[0]", 0xf0080000, 4 * KiB);
424
+ create_unimplemented_device("npcm7xx.smbus[1]", 0xf0081000, 4 * KiB);
425
+ create_unimplemented_device("npcm7xx.smbus[2]", 0xf0082000, 4 * KiB);
426
+ create_unimplemented_device("npcm7xx.smbus[3]", 0xf0083000, 4 * KiB);
427
+ create_unimplemented_device("npcm7xx.smbus[4]", 0xf0084000, 4 * KiB);
428
+ create_unimplemented_device("npcm7xx.smbus[5]", 0xf0085000, 4 * KiB);
429
+ create_unimplemented_device("npcm7xx.smbus[6]", 0xf0086000, 4 * KiB);
430
+ create_unimplemented_device("npcm7xx.smbus[7]", 0xf0087000, 4 * KiB);
431
+ create_unimplemented_device("npcm7xx.smbus[8]", 0xf0088000, 4 * KiB);
432
+ create_unimplemented_device("npcm7xx.smbus[9]", 0xf0089000, 4 * KiB);
433
+ create_unimplemented_device("npcm7xx.smbus[10]", 0xf008a000, 4 * KiB);
434
+ create_unimplemented_device("npcm7xx.smbus[11]", 0xf008b000, 4 * KiB);
435
+ create_unimplemented_device("npcm7xx.smbus[12]", 0xf008c000, 4 * KiB);
436
+ create_unimplemented_device("npcm7xx.smbus[13]", 0xf008d000, 4 * KiB);
437
+ create_unimplemented_device("npcm7xx.smbus[14]", 0xf008e000, 4 * KiB);
438
+ create_unimplemented_device("npcm7xx.smbus[15]", 0xf008f000, 4 * KiB);
439
+ create_unimplemented_device("npcm7xx.espi", 0xf009f000, 4 * KiB);
440
+ create_unimplemented_device("npcm7xx.peci", 0xf0100000, 4 * KiB);
441
+ create_unimplemented_device("npcm7xx.siox[1]", 0xf0101000, 4 * KiB);
442
+ create_unimplemented_device("npcm7xx.siox[2]", 0xf0102000, 4 * KiB);
443
+ create_unimplemented_device("npcm7xx.pwm[0]", 0xf0103000, 4 * KiB);
444
+ create_unimplemented_device("npcm7xx.pwm[1]", 0xf0104000, 4 * KiB);
445
+ create_unimplemented_device("npcm7xx.mft[0]", 0xf0180000, 4 * KiB);
446
+ create_unimplemented_device("npcm7xx.mft[1]", 0xf0181000, 4 * KiB);
447
+ create_unimplemented_device("npcm7xx.mft[2]", 0xf0182000, 4 * KiB);
448
+ create_unimplemented_device("npcm7xx.mft[3]", 0xf0183000, 4 * KiB);
449
+ create_unimplemented_device("npcm7xx.mft[4]", 0xf0184000, 4 * KiB);
450
+ create_unimplemented_device("npcm7xx.mft[5]", 0xf0185000, 4 * KiB);
451
+ create_unimplemented_device("npcm7xx.mft[6]", 0xf0186000, 4 * KiB);
452
+ create_unimplemented_device("npcm7xx.mft[7]", 0xf0187000, 4 * KiB);
453
+ create_unimplemented_device("npcm7xx.pspi1", 0xf0200000, 4 * KiB);
454
+ create_unimplemented_device("npcm7xx.pspi2", 0xf0201000, 4 * KiB);
455
+ create_unimplemented_device("npcm7xx.ahbpci", 0xf0400000, 1 * MiB);
456
+ create_unimplemented_device("npcm7xx.mcphy", 0xf05f0000, 64 * KiB);
457
+ create_unimplemented_device("npcm7xx.gmac1", 0xf0802000, 8 * KiB);
458
+ create_unimplemented_device("npcm7xx.gmac2", 0xf0804000, 8 * KiB);
459
+ create_unimplemented_device("npcm7xx.ehci", 0xf0806000, 4 * KiB);
460
+ create_unimplemented_device("npcm7xx.ohci", 0xf0807000, 4 * KiB);
461
+ create_unimplemented_device("npcm7xx.vcd", 0xf0810000, 64 * KiB);
462
+ create_unimplemented_device("npcm7xx.ece", 0xf0820000, 8 * KiB);
463
+ create_unimplemented_device("npcm7xx.vdma", 0xf0822000, 8 * KiB);
464
+ create_unimplemented_device("npcm7xx.emc1", 0xf0825000, 4 * KiB);
465
+ create_unimplemented_device("npcm7xx.emc2", 0xf0826000, 4 * KiB);
466
+ create_unimplemented_device("npcm7xx.usbd[0]", 0xf0830000, 4 * KiB);
467
+ create_unimplemented_device("npcm7xx.usbd[1]", 0xf0831000, 4 * KiB);
468
+ create_unimplemented_device("npcm7xx.usbd[2]", 0xf0832000, 4 * KiB);
469
+ create_unimplemented_device("npcm7xx.usbd[3]", 0xf0833000, 4 * KiB);
470
+ create_unimplemented_device("npcm7xx.usbd[4]", 0xf0834000, 4 * KiB);
471
+ create_unimplemented_device("npcm7xx.usbd[5]", 0xf0835000, 4 * KiB);
472
+ create_unimplemented_device("npcm7xx.usbd[6]", 0xf0836000, 4 * KiB);
473
+ create_unimplemented_device("npcm7xx.usbd[7]", 0xf0837000, 4 * KiB);
474
+ create_unimplemented_device("npcm7xx.usbd[8]", 0xf0838000, 4 * KiB);
475
+ create_unimplemented_device("npcm7xx.usbd[9]", 0xf0839000, 4 * KiB);
476
+ create_unimplemented_device("npcm7xx.sd", 0xf0840000, 8 * KiB);
477
+ create_unimplemented_device("npcm7xx.mmc", 0xf0842000, 8 * KiB);
478
+ create_unimplemented_device("npcm7xx.pcimbx", 0xf0848000, 512 * KiB);
479
+ create_unimplemented_device("npcm7xx.aes", 0xf0858000, 4 * KiB);
480
+ create_unimplemented_device("npcm7xx.des", 0xf0859000, 4 * KiB);
481
+ create_unimplemented_device("npcm7xx.sha", 0xf085a000, 4 * KiB);
482
+ create_unimplemented_device("npcm7xx.secacc", 0xf085b000, 4 * KiB);
483
+ create_unimplemented_device("npcm7xx.spixcs0", 0xf8000000, 16 * MiB);
484
+ create_unimplemented_device("npcm7xx.spixcs1", 0xf9000000, 16 * MiB);
485
+ create_unimplemented_device("npcm7xx.spix", 0xfb001000, 4 * KiB);
486
+}
112
+}
487
+
113
+
488
+static Property npcm7xx_properties[] = {
114
+static bool trans_VLDR_sysreg(DisasContext *s, arg_vldr_sysreg *a)
489
+ DEFINE_PROP_LINK("dram-mr", NPCM7xxState, dram, TYPE_MEMORY_REGION,
490
+ MemoryRegion *),
491
+ DEFINE_PROP_END_OF_LIST(),
492
+};
493
+
494
+static void npcm7xx_class_init(ObjectClass *oc, void *data)
495
+{
115
+{
496
+ DeviceClass *dc = DEVICE_CLASS(oc);
116
+ if (!arm_dc_feature(s, ARM_FEATURE_V8_1M)) {
497
+
117
+ return false;
498
+ dc->realize = npcm7xx_realize;
118
+ }
499
+ dc->user_creatable = false;
119
+ if (a->rn == 15) {
500
+ device_class_set_props(dc, npcm7xx_properties);
120
+ return false;
121
+ }
122
+ return gen_M_fp_sysreg_write(s, a->reg, memory_to_fp_sysreg, a);
501
+}
123
+}
502
+
124
+
503
+static void npcm730_class_init(ObjectClass *oc, void *data)
125
+static bool trans_VSTR_sysreg(DisasContext *s, arg_vldr_sysreg *a)
504
+{
126
+{
505
+ NPCM7xxClass *nc = NPCM7XX_CLASS(oc);
127
+ if (!arm_dc_feature(s, ARM_FEATURE_V8_1M)) {
506
+
128
+ return false;
507
+ /* NPCM730 is optimized for data center use, so no graphics, etc. */
129
+ }
508
+ nc->disabled_modules = 0x00300395;
130
+ if (a->rn == 15) {
509
+ nc->num_cpus = 2;
131
+ return false;
132
+ }
133
+ return gen_M_fp_sysreg_read(s, a->reg, fp_sysreg_to_memory, a);
510
+}
134
+}
511
+
135
+
512
+static void npcm750_class_init(ObjectClass *oc, void *data)
136
static bool trans_VMOV_half(DisasContext *s, arg_VMOV_single *a)
513
+{
137
{
514
+ NPCM7xxClass *nc = NPCM7XX_CLASS(oc);
138
TCGv_i32 tmp;
515
+
516
+ /* NPCM750 has 2 cores and a full set of peripherals */
517
+ nc->disabled_modules = 0x00000000;
518
+ nc->num_cpus = 2;
519
+}
520
+
521
+static const TypeInfo npcm7xx_soc_types[] = {
522
+ {
523
+ .name = TYPE_NPCM7XX,
524
+ .parent = TYPE_DEVICE,
525
+ .instance_size = sizeof(NPCM7xxState),
526
+ .instance_init = npcm7xx_init,
527
+ .class_size = sizeof(NPCM7xxClass),
528
+ .class_init = npcm7xx_class_init,
529
+ .abstract = true,
530
+ }, {
531
+ .name = TYPE_NPCM730,
532
+ .parent = TYPE_NPCM7XX,
533
+ .class_init = npcm730_class_init,
534
+ }, {
535
+ .name = TYPE_NPCM750,
536
+ .parent = TYPE_NPCM7XX,
537
+ .class_init = npcm750_class_init,
538
+ },
539
+};
540
+
541
+DEFINE_TYPES(npcm7xx_soc_types);
542
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
543
index XXXXXXX..XXXXXXX 100644
544
--- a/hw/arm/Kconfig
545
+++ b/hw/arm/Kconfig
546
@@ -XXX,XX +XXX,XX @@ config XLNX_VERSAL
547
548
config NPCM7XX
549
bool
550
+ select A9MPCORE
551
+ select ARM_GIC
552
+ select PL310 # cache controller
553
+ select SERIAL
554
+ select UNIMP
555
556
config FSL_IMX25
557
bool
558
diff --git a/hw/arm/meson.build b/hw/arm/meson.build
559
index XXXXXXX..XXXXXXX 100644
560
--- a/hw/arm/meson.build
561
+++ b/hw/arm/meson.build
562
@@ -XXX,XX +XXX,XX @@ arm_ss.add(when: 'CONFIG_MICROBIT', if_true: files('microbit.c'))
563
arm_ss.add(when: 'CONFIG_MUSICPAL', if_true: files('musicpal.c'))
564
arm_ss.add(when: 'CONFIG_NETDUINO2', if_true: files('netduino2.c'))
565
arm_ss.add(when: 'CONFIG_NETDUINOPLUS2', if_true: files('netduinoplus2.c'))
566
+arm_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx.c'))
567
arm_ss.add(when: 'CONFIG_NSERIES', if_true: files('nseries.c'))
568
arm_ss.add(when: 'CONFIG_SX1', if_true: files('omap_sx1.c'))
569
arm_ss.add(when: 'CONFIG_CHEETAH', if_true: files('palm.c'))
570
--
139
--
571
2.20.1
140
2.20.1
572
141
573
142
diff view generated by jsdifflib
1
Deprecate our Unicore32 target support:
1
v8.1M defines a new FP system register FPSCR_nzcvqc; this behaves
2
* the Linux kernel dropped support for unicore32 in commit
2
like the existing FPSCR, except that it reads and writes only bits
3
05119217a9bd199c for its 5.9 release (with rationale in the
3
[31:27] of the FPSCR (the N, Z, C, V and QC flag bits). (Unlike the
4
cover letter: https://lkml.org/lkml/2020/8/3/232 )
4
FPSCR, the special case for Rt=15 of writing the CPSR.NZCV is not
5
* there is apparently no upstream toolchain that can create unicore32
5
permitted.)
6
binaries
6
7
* the maintainer doesn't seem to have made any contributions to
7
Implement the register. Since we don't yet implement MVE, we handle
8
QEMU since the port first landed in 2012
8
the QC bit as RES0, with todo comments for where we will need to add
9
* nobody else seems to have made changes to the unicore code except
9
support later.
10
for generic cleanups either
11
10
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
12
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
14
Message-id: 20200825172719.19422-1-peter.maydell@linaro.org
13
Message-id: 20201119215617.29887-11-peter.maydell@linaro.org
15
---
14
---
16
docs/system/deprecated.rst | 8 ++++++++
15
target/arm/cpu.h | 13 +++++++++++++
17
1 file changed, 8 insertions(+)
16
target/arm/translate-vfp.c.inc | 27 +++++++++++++++++++++++++++
17
2 files changed, 40 insertions(+)
18
18
19
diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
19
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
20
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
21
--- a/docs/system/deprecated.rst
21
--- a/target/arm/cpu.h
22
+++ b/docs/system/deprecated.rst
22
+++ b/target/arm/cpu.h
23
@@ -XXX,XX +XXX,XX @@ The above, converted to the current supported format::
23
@@ -XXX,XX +XXX,XX @@ void vfp_set_fpscr(CPUARMState *env, uint32_t val);
24
linux-user mode CPUs
24
#define FPCR_FZ (1 << 24) /* Flush-to-zero enable bit */
25
--------------------
25
#define FPCR_DN (1 << 25) /* Default NaN enable bit */
26
26
#define FPCR_QC (1 << 27) /* Cumulative saturation bit */
27
+``unicore32`` CPUs (since 5.2.0)
27
+#define FPCR_V (1 << 28) /* FP overflow flag */
28
+''''''''''''''''''''''''''''''''
28
+#define FPCR_C (1 << 29) /* FP carry flag */
29
+#define FPCR_Z (1 << 30) /* FP zero flag */
30
+#define FPCR_N (1 << 31) /* FP negative flag */
29
+
31
+
30
+The ``unicore32`` guest CPU support is deprecated and will be removed in
32
+#define FPCR_NZCV_MASK (FPCR_N | FPCR_Z | FPCR_C | FPCR_V)
31
+a future version of QEMU. Support for this CPU was removed from the
33
+#define FPCR_NZCVQC_MASK (FPCR_NZCV_MASK | FPCR_QC)
32
+upstream Linux kernel, and there is no available upstream toolchain
34
33
+to build binaries for it.
35
static inline uint32_t vfp_get_fpsr(CPUARMState *env)
34
+
36
{
35
``tilegx`` CPUs (since 5.1.0)
37
@@ -XXX,XX +XXX,XX @@ enum arm_cpu_mode {
36
'''''''''''''''''''''''''''''
38
#define ARM_VFP_FPEXC 8
37
39
#define ARM_VFP_FPINST 9
40
#define ARM_VFP_FPINST2 10
41
+/* These ones are M-profile only */
42
+#define ARM_VFP_FPSCR_NZCVQC 2
43
+#define ARM_VFP_VPR 12
44
+#define ARM_VFP_P0 13
45
+#define ARM_VFP_FPCXT_NS 14
46
+#define ARM_VFP_FPCXT_S 15
47
48
/* QEMU-internal value meaning "FPSCR, but we care only about NZCV" */
49
#define QEMU_VFP_FPSCR_NZCV 0xffff
50
diff --git a/target/arm/translate-vfp.c.inc b/target/arm/translate-vfp.c.inc
51
index XXXXXXX..XXXXXXX 100644
52
--- a/target/arm/translate-vfp.c.inc
53
+++ b/target/arm/translate-vfp.c.inc
54
@@ -XXX,XX +XXX,XX @@ static FPSysRegCheckResult fp_sysreg_checks(DisasContext *s, int regno)
55
case ARM_VFP_FPSCR:
56
case QEMU_VFP_FPSCR_NZCV:
57
break;
58
+ case ARM_VFP_FPSCR_NZCVQC:
59
+ if (!arm_dc_feature(s, ARM_FEATURE_V8_1M)) {
60
+ return false;
61
+ }
62
+ break;
63
default:
64
return FPSysRegCheckFailed;
65
}
66
@@ -XXX,XX +XXX,XX @@ static bool gen_M_fp_sysreg_write(DisasContext *s, int regno,
67
tcg_temp_free_i32(tmp);
68
gen_lookup_tb(s);
69
break;
70
+ case ARM_VFP_FPSCR_NZCVQC:
71
+ {
72
+ TCGv_i32 fpscr;
73
+ tmp = loadfn(s, opaque);
74
+ /*
75
+ * TODO: when we implement MVE, write the QC bit.
76
+ * For non-MVE, QC is RES0.
77
+ */
78
+ tcg_gen_andi_i32(tmp, tmp, FPCR_NZCV_MASK);
79
+ fpscr = load_cpu_field(vfp.xregs[ARM_VFP_FPSCR]);
80
+ tcg_gen_andi_i32(fpscr, fpscr, ~FPCR_NZCV_MASK);
81
+ tcg_gen_or_i32(fpscr, fpscr, tmp);
82
+ store_cpu_field(fpscr, vfp.xregs[ARM_VFP_FPSCR]);
83
+ tcg_temp_free_i32(tmp);
84
+ break;
85
+ }
86
default:
87
g_assert_not_reached();
88
}
89
@@ -XXX,XX +XXX,XX @@ static bool gen_M_fp_sysreg_read(DisasContext *s, int regno,
90
gen_helper_vfp_get_fpscr(tmp, cpu_env);
91
storefn(s, opaque, tmp);
92
break;
93
+ case ARM_VFP_FPSCR_NZCVQC:
94
+ /*
95
+ * TODO: MVE has a QC bit, which we probably won't store
96
+ * in the xregs[] field. For non-MVE, where QC is RES0,
97
+ * we can just fall through to the FPSCR_NZCV case.
98
+ */
99
case QEMU_VFP_FPSCR_NZCV:
100
/*
101
* Read just NZCV; this is a special case to avoid the
38
--
102
--
39
2.20.1
103
2.20.1
40
104
41
105
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
We defined a constant name for the mask of NZCV bits in the FPCR/FPSCR
2
in the previous commit; use it in a couple of places in existing code,
3
where we're masking out everything except NZCV for the "load to Rt=15
4
sets CPSR.NZCV" special case.
2
5
3
This adds two acceptance tests for the quanta-gsj machine.
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20201119215617.29887-12-peter.maydell@linaro.org
9
---
10
target/arm/translate-vfp.c.inc | 4 ++--
11
1 file changed, 2 insertions(+), 2 deletions(-)
4
12
5
One test downloads a lightly patched openbmc flash image from github and
13
diff --git a/target/arm/translate-vfp.c.inc b/target/arm/translate-vfp.c.inc
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
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
18
---
19
tests/acceptance/boot_linux_console.py | 83 ++++++++++++++++++++++++++
20
1 file changed, 83 insertions(+)
21
22
diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
23
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
24
--- a/tests/acceptance/boot_linux_console.py
15
--- a/target/arm/translate-vfp.c.inc
25
+++ b/tests/acceptance/boot_linux_console.py
16
+++ b/target/arm/translate-vfp.c.inc
26
@@ -XXX,XX +XXX,XX @@ class BootLinuxConsole(LinuxKernelTest):
17
@@ -XXX,XX +XXX,XX @@ static bool gen_M_fp_sysreg_read(DisasContext *s, int regno,
27
'sda')
18
* helper call for the "VMRS to CPSR.NZCV" insn.
28
# cubieboard's reboot is not functioning; omit reboot test.
19
*/
29
20
tmp = load_cpu_field(vfp.xregs[ARM_VFP_FPSCR]);
30
+ def test_arm_quanta_gsj(self):
21
- tcg_gen_andi_i32(tmp, tmp, 0xf0000000);
31
+ """
22
+ tcg_gen_andi_i32(tmp, tmp, FPCR_NZCV_MASK);
32
+ :avocado: tags=arch:arm
23
storefn(s, opaque, tmp);
33
+ :avocado: tags=machine:quanta-gsj
24
break;
34
+ """
25
default:
35
+ # 25 MiB compressed, 32 MiB uncompressed.
26
@@ -XXX,XX +XXX,XX @@ static bool trans_VMSR_VMRS(DisasContext *s, arg_VMSR_VMRS *a)
36
+ image_url = (
27
case ARM_VFP_FPSCR:
37
+ 'https://github.com/hskinnemoen/openbmc/releases/download/'
28
if (a->rt == 15) {
38
+ '20200711-gsj-qemu-0/obmc-phosphor-image-gsj.static.mtd.gz')
29
tmp = load_cpu_field(vfp.xregs[ARM_VFP_FPSCR]);
39
+ image_hash = '14895e634923345cb5c8776037ff7876df96f6b1'
30
- tcg_gen_andi_i32(tmp, tmp, 0xf0000000);
40
+ image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash)
31
+ tcg_gen_andi_i32(tmp, tmp, FPCR_NZCV_MASK);
41
+ image_name = 'obmc.mtd'
32
} else {
42
+ image_path = os.path.join(self.workdir, image_name)
33
tmp = tcg_temp_new_i32();
43
+ archive.gzip_uncompress(image_path_gz, image_path)
34
gen_helper_vfp_get_fpscr(tmp, cpu_env);
44
+
45
+ self.vm.set_console()
46
+ drive_args = 'file=' + image_path + ',if=mtd,bus=0,unit=0'
47
+ self.vm.add_args('-drive', drive_args)
48
+ self.vm.launch()
49
+
50
+ # Disable drivers and services that stall for a long time during boot,
51
+ # to avoid running past the 90-second timeout. These may be removed
52
+ # as the corresponding device support is added.
53
+ kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + (
54
+ 'console=${console} '
55
+ 'mem=${mem} '
56
+ 'initcall_blacklist=npcm_i2c_bus_driver_init '
57
+ 'systemd.mask=systemd-random-seed.service '
58
+ 'systemd.mask=dropbearkey.service '
59
+ )
60
+
61
+ self.wait_for_console_pattern('> BootBlock by Nuvoton')
62
+ self.wait_for_console_pattern('>Device: Poleg BMC NPCM730')
63
+ self.wait_for_console_pattern('>Skip DDR init.')
64
+ self.wait_for_console_pattern('U-Boot ')
65
+ interrupt_interactive_console_until_pattern(
66
+ self, 'Hit any key to stop autoboot:', 'U-Boot>')
67
+ exec_command_and_wait_for_pattern(
68
+ self, "setenv bootargs ${bootargs} " + kernel_command_line,
69
+ 'U-Boot>')
70
+ exec_command_and_wait_for_pattern(
71
+ self, 'run romboot', 'Booting Kernel from flash')
72
+ self.wait_for_console_pattern('Booting Linux on physical CPU 0x0')
73
+ self.wait_for_console_pattern('CPU1: thread -1, cpu 1, socket 0')
74
+ self.wait_for_console_pattern('OpenBMC Project Reference Distro')
75
+ self.wait_for_console_pattern('gsj login:')
76
+
77
+ def test_arm_quanta_gsj_initrd(self):
78
+ """
79
+ :avocado: tags=arch:arm
80
+ :avocado: tags=machine:quanta-gsj
81
+ """
82
+ initrd_url = (
83
+ 'https://github.com/hskinnemoen/openbmc/releases/download/'
84
+ '20200711-gsj-qemu-0/obmc-phosphor-initramfs-gsj.cpio.xz')
85
+ initrd_hash = '98fefe5d7e56727b1eb17d5c00311b1b5c945300'
86
+ initrd_path = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
87
+ kernel_url = (
88
+ 'https://github.com/hskinnemoen/openbmc/releases/download/'
89
+ '20200711-gsj-qemu-0/uImage-gsj.bin')
90
+ kernel_hash = 'fa67b2f141d56d39b3c54305c0e8a899c99eb2c7'
91
+ kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
92
+ dtb_url = (
93
+ 'https://github.com/hskinnemoen/openbmc/releases/download/'
94
+ '20200711-gsj-qemu-0/nuvoton-npcm730-gsj.dtb')
95
+ dtb_hash = '18315f7006d7b688d8312d5c727eecd819aa36a4'
96
+ dtb_path = self.fetch_asset(dtb_url, asset_hash=dtb_hash)
97
+
98
+ self.vm.set_console()
99
+ kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
100
+ 'console=ttyS0,115200n8 '
101
+ 'earlycon=uart8250,mmio32,0xf0001000')
102
+ self.vm.add_args('-kernel', kernel_path,
103
+ '-initrd', initrd_path,
104
+ '-dtb', dtb_path,
105
+ '-append', kernel_command_line)
106
+ self.vm.launch()
107
+
108
+ self.wait_for_console_pattern('Booting Linux on physical CPU 0x0')
109
+ self.wait_for_console_pattern('CPU1: thread -1, cpu 1, socket 0')
110
+ self.wait_for_console_pattern(
111
+ 'Give root password for system maintenance')
112
+
113
def test_arm_orangepi(self):
114
"""
115
:avocado: tags=arch:arm
116
--
35
--
117
2.20.1
36
2.20.1
118
37
119
38
diff view generated by jsdifflib
1
Implement a model of the MPS2 with the AN386 firmware. This is
1
Factor out the code which handles M-profile lazy FP state preservation
2
essentially identical to the AN385 firmware, but it has a
2
from full_vfp_access_check(); accesses to the FPCXT_NS register are
3
Cortex-M4 rather than a Cortex-M3.
3
a special case which need to do just this part (corresponding in the
4
pseudocode to the PreserveFPState() function), and not the full
5
set of actions matching the pseudocode ExecuteFPCheck() which
6
normal FP instructions need to do.
4
7
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
10
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Message-id: 20200903202048.15370-2-peter.maydell@linaro.org
11
Message-id: 20201119215617.29887-13-peter.maydell@linaro.org
9
---
12
---
10
docs/system/arm/mps2.rst | 8 +++++---
13
target/arm/translate-vfp.c.inc | 45 ++++++++++++++++++++--------------
11
hw/arm/mps2.c | 34 +++++++++++++++++++++++++++++-----
14
1 file changed, 27 insertions(+), 18 deletions(-)
12
2 files changed, 34 insertions(+), 8 deletions(-)
13
15
14
diff --git a/docs/system/arm/mps2.rst b/docs/system/arm/mps2.rst
16
diff --git a/target/arm/translate-vfp.c.inc b/target/arm/translate-vfp.c.inc
15
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
16
--- a/docs/system/arm/mps2.rst
18
--- a/target/arm/translate-vfp.c.inc
17
+++ b/docs/system/arm/mps2.rst
19
+++ b/target/arm/translate-vfp.c.inc
18
@@ -XXX,XX +XXX,XX @@
20
@@ -XXX,XX +XXX,XX @@ static inline long vfp_f16_offset(unsigned reg, bool top)
19
-Arm MPS2 boards (``mps2-an385``, ``mps2-an505``, ``mps2-an511``, ``mps2-an521``)
21
return offs;
20
-================================================================================
21
+Arm MPS2 boards (``mps2-an385``, ``mps2-an386``, ``mps2-an505``, ``mps2-an511``, ``mps2-an521``)
22
+================================================================================================
23
24
These board models all use Arm M-profile CPUs.
25
26
@@ -XXX,XX +XXX,XX @@ QEMU models the following FPGA images:
27
28
``mps2-an385``
29
Cortex-M3 as documented in ARM Application Note AN385
30
+``mps2-an386``
31
+ Cortex-M4 as documented in ARM Application Note AN386
32
``mps2-an511``
33
Cortex-M3 'DesignStart' as documented in AN511
34
``mps2-an505``
35
@@ -XXX,XX +XXX,XX @@ QEMU models the following FPGA images:
36
37
Differences between QEMU and real hardware:
38
39
-- AN385 remapping of low 16K of memory to either ZBT SSRAM1 or to
40
+- AN385/AN386 remapping of low 16K of memory to either ZBT SSRAM1 or to
41
block RAM is unimplemented (QEMU always maps this to ZBT SSRAM1, as
42
if zbt_boot_ctrl is always zero)
43
- QEMU provides a LAN9118 ethernet rather than LAN9220; the only guest
44
diff --git a/hw/arm/mps2.c b/hw/arm/mps2.c
45
index XXXXXXX..XXXXXXX 100644
46
--- a/hw/arm/mps2.c
47
+++ b/hw/arm/mps2.c
48
@@ -XXX,XX +XXX,XX @@
49
* as seen by the guest depend significantly on the FPGA image.
50
* We model the following FPGA images:
51
* "mps2-an385" -- Cortex-M3 as documented in ARM Application Note AN385
52
+ * "mps2-an386" -- Cortex-M4 as documented in ARM Application Note AN386
53
* "mps2-an511" -- Cortex-M3 'DesignStart' as documented in AN511
54
*
55
* Links to the TRM for the board itself and to the various Application
56
@@ -XXX,XX +XXX,XX @@
57
58
typedef enum MPS2FPGAType {
59
FPGA_AN385,
60
+ FPGA_AN386,
61
FPGA_AN511,
62
} MPS2FPGAType;
63
64
@@ -XXX,XX +XXX,XX @@ typedef struct MPS2MachineState MPS2MachineState;
65
66
#define TYPE_MPS2_MACHINE "mps2"
67
#define TYPE_MPS2_AN385_MACHINE MACHINE_TYPE_NAME("mps2-an385")
68
+#define TYPE_MPS2_AN386_MACHINE MACHINE_TYPE_NAME("mps2-an386")
69
#define TYPE_MPS2_AN511_MACHINE MACHINE_TYPE_NAME("mps2-an511")
70
71
DECLARE_OBJ_CHECKERS(MPS2MachineState, MPS2MachineClass,
72
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
73
* tradeoffs. For QEMU they're all just RAM, though. We arbitrarily
74
* call the 16MB our "system memory", as it's the largest lump.
75
*
76
- * Common to both boards:
77
- * 0x21000000..0x21ffffff : PSRAM (16MB)
78
- * AN385 only:
79
+ * AN385/AN386/AN511:
80
+ * 0x21000000 .. 0x21ffffff : PSRAM (16MB)
81
+ * AN385/AN386 only:
82
* 0x00000000 .. 0x003fffff : ZBT SSRAM1
83
* 0x00400000 .. 0x007fffff : mirror of ZBT SSRAM1
84
* 0x20000000 .. 0x203fffff : ZBT SSRAM 2&3
85
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
86
* 0x20000000 .. 0x2001ffff : SRAM
87
* 0x20400000 .. 0x207fffff : ZBT SSRAM 2&3
88
*
89
- * The AN385 has a feature where the lowest 16K can be mapped
90
+ * The AN385/AN386 has a feature where the lowest 16K can be mapped
91
* either to the bottom of the ZBT SSRAM1 or to the block RAM.
92
* This is of no use for QEMU so we don't implement it (as if
93
* zbt_boot_ctrl is always zero).
94
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
95
96
switch (mmc->fpga_type) {
97
case FPGA_AN385:
98
+ case FPGA_AN386:
99
make_ram(&mms->ssram1, "mps.ssram1", 0x0, 0x400000);
100
make_ram_alias(&mms->ssram1_m, "mps.ssram1_m", &mms->ssram1, 0x400000);
101
make_ram(&mms->ssram23, "mps.ssram23", 0x20000000, 0x400000);
102
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
103
armv7m = DEVICE(&mms->armv7m);
104
switch (mmc->fpga_type) {
105
case FPGA_AN385:
106
+ case FPGA_AN386:
107
qdev_prop_set_uint32(armv7m, "num-irq", 32);
108
break;
109
case FPGA_AN511:
110
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
111
112
switch (mmc->fpga_type) {
113
case FPGA_AN385:
114
+ case FPGA_AN386:
115
{
116
/* The overflow IRQs for UARTs 0, 1 and 2 are ORed together.
117
* Overflow for UARTs 4 and 5 doesn't trigger any interrupt.
118
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
119
*/
120
lan9118_init(&nd_table[0], 0x40200000,
121
qdev_get_gpio_in(armv7m,
122
- mmc->fpga_type == FPGA_AN385 ? 13 : 47));
123
+ mmc->fpga_type == FPGA_AN511 ? 47 : 13));
124
125
system_clock_scale = NANOSECONDS_PER_SECOND / SYSCLK_FRQ;
126
127
@@ -XXX,XX +XXX,XX @@ static void mps2_an385_class_init(ObjectClass *oc, void *data)
128
mmc->scc_id = 0x41043850;
129
}
22
}
130
23
131
+static void mps2_an386_class_init(ObjectClass *oc, void *data)
24
+/*
25
+ * Generate code for M-profile lazy FP state preservation if needed;
26
+ * this corresponds to the pseudocode PreserveFPState() function.
27
+ */
28
+static void gen_preserve_fp_state(DisasContext *s)
132
+{
29
+{
133
+ MachineClass *mc = MACHINE_CLASS(oc);
30
+ if (s->v7m_lspact) {
134
+ MPS2MachineClass *mmc = MPS2_MACHINE_CLASS(oc);
31
+ /*
135
+
32
+ * Lazy state saving affects external memory and also the NVIC,
136
+ mc->desc = "ARM MPS2 with AN386 FPGA image for Cortex-M4";
33
+ * so we must mark it as an IO operation for icount (and cause
137
+ mmc->fpga_type = FPGA_AN386;
34
+ * this to be the last insn in the TB).
138
+ mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m4");
35
+ */
139
+ mmc->scc_id = 0x41043860;
36
+ if (tb_cflags(s->base.tb) & CF_USE_ICOUNT) {
37
+ s->base.is_jmp = DISAS_UPDATE_EXIT;
38
+ gen_io_start();
39
+ }
40
+ gen_helper_v7m_preserve_fp_state(cpu_env);
41
+ /*
42
+ * If the preserve_fp_state helper doesn't throw an exception
43
+ * then it will clear LSPACT; we don't need to repeat this for
44
+ * any further FP insns in this TB.
45
+ */
46
+ s->v7m_lspact = false;
47
+ }
140
+}
48
+}
141
+
49
+
142
static void mps2_an511_class_init(ObjectClass *oc, void *data)
50
/*
143
{
51
* Check that VFP access is enabled. If it is, do the necessary
144
MachineClass *mc = MACHINE_CLASS(oc);
52
* M-profile lazy-FP handling and then return true.
145
@@ -XXX,XX +XXX,XX @@ static const TypeInfo mps2_an385_info = {
53
@@ -XXX,XX +XXX,XX @@ static bool full_vfp_access_check(DisasContext *s, bool ignore_vfp_enabled)
146
.class_init = mps2_an385_class_init,
54
/* Handle M-profile lazy FP state mechanics */
147
};
55
148
56
/* Trigger lazy-state preservation if necessary */
149
+static const TypeInfo mps2_an386_info = {
57
- if (s->v7m_lspact) {
150
+ .name = TYPE_MPS2_AN386_MACHINE,
58
- /*
151
+ .parent = TYPE_MPS2_MACHINE,
59
- * Lazy state saving affects external memory and also the NVIC,
152
+ .class_init = mps2_an386_class_init,
60
- * so we must mark it as an IO operation for icount (and cause
153
+};
61
- * this to be the last insn in the TB).
154
+
62
- */
155
static const TypeInfo mps2_an511_info = {
63
- if (tb_cflags(s->base.tb) & CF_USE_ICOUNT) {
156
.name = TYPE_MPS2_AN511_MACHINE,
64
- s->base.is_jmp = DISAS_UPDATE_EXIT;
157
.parent = TYPE_MPS2_MACHINE,
65
- gen_io_start();
158
@@ -XXX,XX +XXX,XX @@ static void mps2_machine_init(void)
66
- }
159
{
67
- gen_helper_v7m_preserve_fp_state(cpu_env);
160
type_register_static(&mps2_info);
68
- /*
161
type_register_static(&mps2_an385_info);
69
- * If the preserve_fp_state helper doesn't throw an exception
162
+ type_register_static(&mps2_an386_info);
70
- * then it will clear LSPACT; we don't need to repeat this for
163
type_register_static(&mps2_an511_info);
71
- * any further FP insns in this TB.
164
}
72
- */
165
73
- s->v7m_lspact = false;
74
- }
75
+ gen_preserve_fp_state(s);
76
77
/* Update ownership of FP context: set FPCCR.S to match current state */
78
if (s->v8m_fpccr_s_wrong) {
166
--
79
--
167
2.20.1
80
2.20.1
168
81
169
82
diff view generated by jsdifflib
1
Convert the insns using the 2reg_vcvt and 2reg_vcvt_f16 formats
1
Implement the new-in-v8.1M FPCXT_S floating point system register.
2
to pass the size through to the trans function as a MO_* value
2
This is for saving and restoring the secure floating point context,
3
rather than the '0==f32, 1==f16' used in the fp 3-same encodings.
3
and it reads and writes bits [27:0] from the FPSCR and the
4
CONTROL.SFPA bit in bit [31].
4
5
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20200903133209.5141-3-peter.maydell@linaro.org
8
Message-id: 20201119215617.29887-14-peter.maydell@linaro.org
8
---
9
---
9
target/arm/neon-dp.decode | 3 +--
10
target/arm/translate-vfp.c.inc | 58 ++++++++++++++++++++++++++++++++++
10
target/arm/translate-neon.c.inc | 4 ++--
11
1 file changed, 58 insertions(+)
11
2 files changed, 3 insertions(+), 4 deletions(-)
12
12
13
diff --git a/target/arm/neon-dp.decode b/target/arm/neon-dp.decode
13
diff --git a/target/arm/translate-vfp.c.inc b/target/arm/translate-vfp.c.inc
14
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
15
--- a/target/arm/neon-dp.decode
15
--- a/target/arm/translate-vfp.c.inc
16
+++ b/target/arm/neon-dp.decode
16
+++ b/target/arm/translate-vfp.c.inc
17
@@ -XXX,XX +XXX,XX @@ VMINNM_fp_3s 1111 001 1 0 . 1 . .... .... 1111 ... 1 .... @3same_fp
17
@@ -XXX,XX +XXX,XX @@ static FPSysRegCheckResult fp_sysreg_checks(DisasContext *s, int regno)
18
@2reg_shll_b .... ... . . . 001 shift:3 .... .... 0 . . . .... \
19
&2reg_shift vm=%vm_dp vd=%vd_dp size=0 q=0
20
21
-# We use size=0 for fp32 and size=1 for fp16 to match the 3-same encodings.
22
@2reg_vcvt .... ... . . . 1 ..... .... .... . q:1 . . .... \
23
- &2reg_shift vm=%vm_dp vd=%vd_dp size=0 shift=%neon_rshift_i5
24
+ &2reg_shift vm=%vm_dp vd=%vd_dp size=2 shift=%neon_rshift_i5
25
@2reg_vcvt_f16 .... ... . . . 11 .... .... .... . q:1 . . .... \
26
&2reg_shift vm=%vm_dp vd=%vd_dp size=1 shift=%neon_rshift_i4
27
28
diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc
29
index XXXXXXX..XXXXXXX 100644
30
--- a/target/arm/translate-neon.c.inc
31
+++ b/target/arm/translate-neon.c.inc
32
@@ -XXX,XX +XXX,XX @@ static bool do_fp_2sh(DisasContext *s, arg_2reg_shift *a,
33
return false;
34
}
35
36
- if (a->size != 0) {
37
+ if (a->size == MO_16) {
38
if (!dc_isar_feature(aa32_fp16_arith, s)) {
39
return false;
18
return false;
40
}
19
}
41
@@ -XXX,XX +XXX,XX @@ static bool do_fp_2sh(DisasContext *s, arg_2reg_shift *a,
20
break;
42
return true;
21
+ case ARM_VFP_FPCXT_S:
22
+ if (!arm_dc_feature(s, ARM_FEATURE_V8_1M)) {
23
+ return false;
24
+ }
25
+ if (!s->v8m_secure) {
26
+ return false;
27
+ }
28
+ break;
29
default:
30
return FPSysRegCheckFailed;
43
}
31
}
44
32
@@ -XXX,XX +XXX,XX @@ static bool gen_M_fp_sysreg_write(DisasContext *s, int regno,
45
- fpst = fpstatus_ptr(a->size ? FPST_STD_F16 : FPST_STD);
33
tcg_temp_free_i32(tmp);
46
+ fpst = fpstatus_ptr(a->size == MO_16 ? FPST_STD_F16 : FPST_STD);
34
break;
47
tcg_gen_gvec_2_ptr(rd_ofs, rm_ofs, fpst, vec_size, vec_size, a->shift, fn);
35
}
48
tcg_temp_free_ptr(fpst);
36
+ case ARM_VFP_FPCXT_S:
49
return true;
37
+ {
38
+ TCGv_i32 sfpa, control, fpscr;
39
+ /* Set FPSCR[27:0] and CONTROL.SFPA from value */
40
+ tmp = loadfn(s, opaque);
41
+ sfpa = tcg_temp_new_i32();
42
+ tcg_gen_shri_i32(sfpa, tmp, 31);
43
+ control = load_cpu_field(v7m.control[M_REG_S]);
44
+ tcg_gen_deposit_i32(control, control, sfpa,
45
+ R_V7M_CONTROL_SFPA_SHIFT, 1);
46
+ store_cpu_field(control, v7m.control[M_REG_S]);
47
+ fpscr = load_cpu_field(vfp.xregs[ARM_VFP_FPSCR]);
48
+ tcg_gen_andi_i32(fpscr, fpscr, FPCR_NZCV_MASK);
49
+ tcg_gen_andi_i32(tmp, tmp, ~FPCR_NZCV_MASK);
50
+ tcg_gen_or_i32(fpscr, fpscr, tmp);
51
+ store_cpu_field(fpscr, vfp.xregs[ARM_VFP_FPSCR]);
52
+ tcg_temp_free_i32(tmp);
53
+ tcg_temp_free_i32(sfpa);
54
+ break;
55
+ }
56
default:
57
g_assert_not_reached();
58
}
59
@@ -XXX,XX +XXX,XX @@ static bool gen_M_fp_sysreg_read(DisasContext *s, int regno,
60
tcg_gen_andi_i32(tmp, tmp, FPCR_NZCV_MASK);
61
storefn(s, opaque, tmp);
62
break;
63
+ case ARM_VFP_FPCXT_S:
64
+ {
65
+ TCGv_i32 control, sfpa, fpscr;
66
+ /* Bits [27:0] from FPSCR, bit [31] from CONTROL.SFPA */
67
+ tmp = tcg_temp_new_i32();
68
+ sfpa = tcg_temp_new_i32();
69
+ gen_helper_vfp_get_fpscr(tmp, cpu_env);
70
+ tcg_gen_andi_i32(tmp, tmp, ~FPCR_NZCV_MASK);
71
+ control = load_cpu_field(v7m.control[M_REG_S]);
72
+ tcg_gen_andi_i32(sfpa, control, R_V7M_CONTROL_SFPA_MASK);
73
+ tcg_gen_shli_i32(sfpa, sfpa, 31 - R_V7M_CONTROL_SFPA_SHIFT);
74
+ tcg_gen_or_i32(tmp, tmp, sfpa);
75
+ tcg_temp_free_i32(sfpa);
76
+ /*
77
+ * Store result before updating FPSCR etc, in case
78
+ * it is a memory write which causes an exception.
79
+ */
80
+ storefn(s, opaque, tmp);
81
+ /*
82
+ * Now we must reset FPSCR from FPDSCR_NS, and clear
83
+ * CONTROL.SFPA; so we'll end the TB here.
84
+ */
85
+ tcg_gen_andi_i32(control, control, ~R_V7M_CONTROL_SFPA_MASK);
86
+ store_cpu_field(control, v7m.control[M_REG_S]);
87
+ fpscr = load_cpu_field(v7m.fpdscr[M_REG_NS]);
88
+ gen_helper_vfp_set_fpscr(cpu_env, fpscr);
89
+ tcg_temp_free_i32(fpscr);
90
+ gen_lookup_tb(s);
91
+ break;
92
+ }
93
default:
94
g_assert_not_reached();
95
}
50
--
96
--
51
2.20.1
97
2.20.1
52
98
53
99
diff view generated by jsdifflib
1
Now that 32-bit KVM host support is gone, KVM can never
1
The FPDSCR register has a similar layout to the FPSCR. In v8.1M it
2
be enabled unless CONFIG_AARCH64 is true, and some code
2
gains new fields FZ16 (if half-precision floating point is supported)
3
paths are no longer reachable and can be deleted.
3
and LTPSIZE (always reads as 4). Update the reset value and the code
4
that handles writes to this register accordingly.
4
5
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
8
Message-id: 20201119215617.29887-16-peter.maydell@linaro.org
8
Message-id: 20200904154156.31943-3-peter.maydell@linaro.org
9
---
9
---
10
target/arm/kvm-consts.h | 7 ---
10
target/arm/cpu.h | 5 +++++
11
target/arm/kvm_arm.h | 6 ---
11
hw/intc/armv7m_nvic.c | 9 ++++++++-
12
target/arm/cpu.c | 101 +++++++++++++++++++---------------------
12
target/arm/cpu.c | 3 +++
13
target/arm/kvm.c | 7 ---
13
3 files changed, 16 insertions(+), 1 deletion(-)
14
4 files changed, 47 insertions(+), 74 deletions(-)
15
14
16
diff --git a/target/arm/kvm-consts.h b/target/arm/kvm-consts.h
15
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
17
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
18
--- a/target/arm/kvm-consts.h
17
--- a/target/arm/cpu.h
19
+++ b/target/arm/kvm-consts.h
18
+++ b/target/arm/cpu.h
20
@@ -XXX,XX +XXX,XX @@ MISMATCH_CHECK(QEMU_PSCI_RET_DISABLED, PSCI_RET_DISABLED);
19
@@ -XXX,XX +XXX,XX @@ void vfp_set_fpscr(CPUARMState *env, uint32_t val);
21
*/
20
#define FPCR_IXE (1 << 12) /* Inexact exception trap enable */
22
#define QEMU_KVM_ARM_TARGET_NONE UINT_MAX
21
#define FPCR_IDE (1 << 15) /* Input Denormal exception trap enable */
23
22
#define FPCR_FZ16 (1 << 19) /* ARMv8.2+, FP16 flush-to-zero */
24
-#ifdef TARGET_AARCH64
23
+#define FPCR_RMODE_MASK (3 << 22) /* Rounding mode */
25
MISMATCH_CHECK(QEMU_KVM_ARM_TARGET_AEM_V8, KVM_ARM_TARGET_AEM_V8);
24
#define FPCR_FZ (1 << 24) /* Flush-to-zero enable bit */
26
MISMATCH_CHECK(QEMU_KVM_ARM_TARGET_FOUNDATION_V8, KVM_ARM_TARGET_FOUNDATION_V8);
25
#define FPCR_DN (1 << 25) /* Default NaN enable bit */
27
MISMATCH_CHECK(QEMU_KVM_ARM_TARGET_CORTEX_A57, KVM_ARM_TARGET_CORTEX_A57);
26
+#define FPCR_AHP (1 << 26) /* Alternative half-precision */
28
MISMATCH_CHECK(QEMU_KVM_ARM_TARGET_XGENE_POTENZA, KVM_ARM_TARGET_XGENE_POTENZA);
27
#define FPCR_QC (1 << 27) /* Cumulative saturation bit */
29
MISMATCH_CHECK(QEMU_KVM_ARM_TARGET_CORTEX_A53, KVM_ARM_TARGET_CORTEX_A53);
28
#define FPCR_V (1 << 28) /* FP overflow flag */
30
-#else
29
#define FPCR_C (1 << 29) /* FP carry flag */
31
-MISMATCH_CHECK(QEMU_KVM_ARM_TARGET_CORTEX_A15, KVM_ARM_TARGET_CORTEX_A15);
30
#define FPCR_Z (1 << 30) /* FP zero flag */
32
-MISMATCH_CHECK(QEMU_KVM_ARM_TARGET_CORTEX_A7, KVM_ARM_TARGET_CORTEX_A7);
31
#define FPCR_N (1 << 31) /* FP negative flag */
33
-#endif
32
34
33
+#define FPCR_LTPSIZE_SHIFT 16 /* LTPSIZE, M-profile only */
35
#define CP_REG_ARM64 0x6000000000000000ULL
34
+#define FPCR_LTPSIZE_MASK (7 << FPCR_LTPSIZE_SHIFT)
36
#define CP_REG_ARM_COPROC_MASK 0x000000000FFF0000
35
+
37
@@ -XXX,XX +XXX,XX @@ MISMATCH_CHECK(QEMU_KVM_ARM_TARGET_CORTEX_A7, KVM_ARM_TARGET_CORTEX_A7);
36
#define FPCR_NZCV_MASK (FPCR_N | FPCR_Z | FPCR_C | FPCR_V)
38
/* No kernel define but it's useful to QEMU */
37
#define FPCR_NZCVQC_MASK (FPCR_NZCV_MASK | FPCR_QC)
39
#define CP_REG_ARM64_SYSREG_CP (CP_REG_ARM64_SYSREG >> CP_REG_ARM_COPROC_SHIFT)
38
40
39
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
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
40
index XXXXXXX..XXXXXXX 100644
55
--- a/target/arm/kvm_arm.h
41
--- a/hw/intc/armv7m_nvic.c
56
+++ b/target/arm/kvm_arm.h
42
+++ b/hw/intc/armv7m_nvic.c
57
@@ -XXX,XX +XXX,XX @@ static inline const char *gic_class_name(void)
43
@@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value,
58
static inline const char *gicv3_class_name(void)
44
break;
59
{
45
case 0xf3c: /* FPDSCR */
60
if (kvm_irqchip_in_kernel()) {
46
if (cpu_isar_feature(aa32_vfp_simd, cpu)) {
61
-#ifdef TARGET_AARCH64
47
- value &= 0x07c00000;
62
return "kvm-arm-gicv3";
48
+ uint32_t mask = FPCR_AHP | FPCR_DN | FPCR_FZ | FPCR_RMODE_MASK;
63
-#else
49
+ if (cpu_isar_feature(any_fp16, cpu)) {
64
- error_report("KVM GICv3 acceleration is not supported on this "
50
+ mask |= FPCR_FZ16;
65
- "platform");
51
+ }
66
- exit(1);
52
+ value &= mask;
67
-#endif
53
+ if (cpu_isar_feature(aa32_lob, cpu)) {
68
} else {
54
+ value |= 4 << FPCR_LTPSIZE_SHIFT;
69
if (kvm_enabled()) {
55
+ }
70
error_report("Userspace GICv3 is not supported with KVM");
56
cpu->env.v7m.fpdscr[attrs.secure] = value;
57
}
58
break;
71
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
59
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
72
index XXXXXXX..XXXXXXX 100644
60
index XXXXXXX..XXXXXXX 100644
73
--- a/target/arm/cpu.c
61
--- a/target/arm/cpu.c
74
+++ b/target/arm/cpu.c
62
+++ b/target/arm/cpu.c
75
@@ -XXX,XX +XXX,XX @@ static void cortex_a15_initfn(Object *obj)
63
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(DeviceState *dev)
76
}
64
* always reset to 4.
77
65
*/
78
#ifndef TARGET_AARCH64
66
env->v7m.ltpsize = 4;
79
-/* -cpu max: if KVM is enabled, like -cpu host (best possible with this host);
67
+ /* The LTPSIZE field in FPDSCR is constant and reads as 4. */
80
- * otherwise, a CPU with as many features enabled as our emulation supports.
68
+ env->v7m.fpdscr[M_REG_NS] = 4 << FPCR_LTPSIZE_SHIFT;
81
+/*
69
+ env->v7m.fpdscr[M_REG_S] = 4 << FPCR_LTPSIZE_SHIFT;
82
+ * -cpu max: a CPU with as many features enabled as our emulation supports.
70
}
83
* The version of '-cpu max' for qemu-system-aarch64 is defined in cpu64.c;
71
84
- * this only needs to handle 32 bits.
72
if (arm_feature(env, ARM_FEATURE_M_SECURITY)) {
85
+ * this only needs to handle 32 bits, and need not care about KVM.
86
*/
87
static void arm_max_initfn(Object *obj)
88
{
89
ARMCPU *cpu = ARM_CPU(obj);
90
91
- if (kvm_enabled()) {
92
- kvm_arm_set_cpu_features_from_host(cpu);
93
- } else {
94
- cortex_a15_initfn(obj);
95
+ cortex_a15_initfn(obj);
96
97
- /* old-style VFP short-vector support */
98
- cpu->isar.mvfr0 = FIELD_DP32(cpu->isar.mvfr0, MVFR0, FPSHVEC, 1);
99
+ /* old-style VFP short-vector support */
100
+ cpu->isar.mvfr0 = FIELD_DP32(cpu->isar.mvfr0, MVFR0, FPSHVEC, 1);
101
102
#ifdef CONFIG_USER_ONLY
103
- /* We don't set these in system emulation mode for the moment,
104
- * since we don't correctly set (all of) the ID registers to
105
- * advertise them.
106
- */
107
- set_feature(&cpu->env, ARM_FEATURE_V8);
108
- {
109
- uint32_t t;
110
+ /*
111
+ * We don't set these in system emulation mode for the moment,
112
+ * since we don't correctly set (all of) the ID registers to
113
+ * advertise them.
114
+ */
115
+ set_feature(&cpu->env, ARM_FEATURE_V8);
116
+ {
117
+ uint32_t t;
118
119
- t = cpu->isar.id_isar5;
120
- t = FIELD_DP32(t, ID_ISAR5, AES, 2);
121
- t = FIELD_DP32(t, ID_ISAR5, SHA1, 1);
122
- t = FIELD_DP32(t, ID_ISAR5, SHA2, 1);
123
- t = FIELD_DP32(t, ID_ISAR5, CRC32, 1);
124
- t = FIELD_DP32(t, ID_ISAR5, RDM, 1);
125
- t = FIELD_DP32(t, ID_ISAR5, VCMA, 1);
126
- cpu->isar.id_isar5 = t;
127
+ t = cpu->isar.id_isar5;
128
+ t = FIELD_DP32(t, ID_ISAR5, AES, 2);
129
+ t = FIELD_DP32(t, ID_ISAR5, SHA1, 1);
130
+ t = FIELD_DP32(t, ID_ISAR5, SHA2, 1);
131
+ t = FIELD_DP32(t, ID_ISAR5, CRC32, 1);
132
+ t = FIELD_DP32(t, ID_ISAR5, RDM, 1);
133
+ t = FIELD_DP32(t, ID_ISAR5, VCMA, 1);
134
+ cpu->isar.id_isar5 = t;
135
136
- t = cpu->isar.id_isar6;
137
- t = FIELD_DP32(t, ID_ISAR6, JSCVT, 1);
138
- t = FIELD_DP32(t, ID_ISAR6, DP, 1);
139
- t = FIELD_DP32(t, ID_ISAR6, FHM, 1);
140
- t = FIELD_DP32(t, ID_ISAR6, SB, 1);
141
- t = FIELD_DP32(t, ID_ISAR6, SPECRES, 1);
142
- cpu->isar.id_isar6 = t;
143
+ t = cpu->isar.id_isar6;
144
+ t = FIELD_DP32(t, ID_ISAR6, JSCVT, 1);
145
+ t = FIELD_DP32(t, ID_ISAR6, DP, 1);
146
+ t = FIELD_DP32(t, ID_ISAR6, FHM, 1);
147
+ t = FIELD_DP32(t, ID_ISAR6, SB, 1);
148
+ t = FIELD_DP32(t, ID_ISAR6, SPECRES, 1);
149
+ cpu->isar.id_isar6 = t;
150
151
- t = cpu->isar.mvfr1;
152
- t = FIELD_DP32(t, MVFR1, FPHP, 3); /* v8.2-FP16 */
153
- t = FIELD_DP32(t, MVFR1, SIMDHP, 2); /* v8.2-FP16 */
154
- cpu->isar.mvfr1 = t;
155
+ t = cpu->isar.mvfr1;
156
+ t = FIELD_DP32(t, MVFR1, FPHP, 3); /* v8.2-FP16 */
157
+ t = FIELD_DP32(t, MVFR1, SIMDHP, 2); /* v8.2-FP16 */
158
+ cpu->isar.mvfr1 = t;
159
160
- t = cpu->isar.mvfr2;
161
- t = FIELD_DP32(t, MVFR2, SIMDMISC, 3); /* SIMD MaxNum */
162
- t = FIELD_DP32(t, MVFR2, FPMISC, 4); /* FP MaxNum */
163
- cpu->isar.mvfr2 = t;
164
+ t = cpu->isar.mvfr2;
165
+ t = FIELD_DP32(t, MVFR2, SIMDMISC, 3); /* SIMD MaxNum */
166
+ t = FIELD_DP32(t, MVFR2, FPMISC, 4); /* FP MaxNum */
167
+ cpu->isar.mvfr2 = t;
168
169
- t = cpu->isar.id_mmfr3;
170
- t = FIELD_DP32(t, ID_MMFR3, PAN, 2); /* ATS1E1 */
171
- cpu->isar.id_mmfr3 = t;
172
+ t = cpu->isar.id_mmfr3;
173
+ t = FIELD_DP32(t, ID_MMFR3, PAN, 2); /* ATS1E1 */
174
+ cpu->isar.id_mmfr3 = t;
175
176
- t = cpu->isar.id_mmfr4;
177
- t = FIELD_DP32(t, ID_MMFR4, HPDS, 1); /* AA32HPD */
178
- t = FIELD_DP32(t, ID_MMFR4, AC2, 1); /* ACTLR2, HACTLR2 */
179
- t = FIELD_DP32(t, ID_MMFR4, CNP, 1); /* TTCNP */
180
- t = FIELD_DP32(t, ID_MMFR4, XNX, 1); /* TTS2UXN */
181
- cpu->isar.id_mmfr4 = t;
182
- }
183
-#endif
184
+ t = cpu->isar.id_mmfr4;
185
+ t = FIELD_DP32(t, ID_MMFR4, HPDS, 1); /* AA32HPD */
186
+ t = FIELD_DP32(t, ID_MMFR4, AC2, 1); /* ACTLR2, HACTLR2 */
187
+ t = FIELD_DP32(t, ID_MMFR4, CNP, 1); /* TTCNP */
188
+ t = FIELD_DP32(t, ID_MMFR4, XNX, 1); /* TTS2UXN */
189
+ cpu->isar.id_mmfr4 = t;
190
}
191
+#endif
192
}
193
#endif
194
195
@@ -XXX,XX +XXX,XX @@ static void arm_host_initfn(Object *obj)
196
197
static const TypeInfo host_arm_cpu_type_info = {
198
.name = TYPE_ARM_HOST_CPU,
199
-#ifdef TARGET_AARCH64
200
.parent = TYPE_AARCH64_CPU,
201
-#else
202
- .parent = TYPE_ARM_CPU,
203
-#endif
204
.instance_init = arm_host_initfn,
205
};
206
207
diff --git a/target/arm/kvm.c b/target/arm/kvm.c
208
index XXXXXXX..XXXXXXX 100644
209
--- a/target/arm/kvm.c
210
+++ b/target/arm/kvm.c
211
@@ -XXX,XX +XXX,XX @@ int kvm_arch_process_async_events(CPUState *cs)
212
return 0;
213
}
214
215
-/* The #ifdef protections are until 32bit headers are imported and can
216
- * be removed once both 32 and 64 bit reach feature parity.
217
- */
218
void kvm_arch_update_guest_debug(CPUState *cs, struct kvm_guest_debug *dbg)
219
{
220
-#ifdef KVM_GUESTDBG_USE_SW_BP
221
if (kvm_sw_breakpoints_active(cs)) {
222
dbg->control |= KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_USE_SW_BP;
223
}
224
-#endif
225
-#ifdef KVM_GUESTDBG_USE_HW
226
if (kvm_arm_hw_debug_active(cs)) {
227
dbg->control |= KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_USE_HW;
228
kvm_arm_copy_hw_debug_data(&dbg->arch);
229
}
230
-#endif
231
}
232
233
void kvm_arch_init_irq_routing(KVMState *s)
234
--
73
--
235
2.20.1
74
2.20.1
236
75
237
76
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
In v8.0M, on exception entry the registers R0-R3, R12, APSR and EPSR
2
are zeroed for an exception taken to Non-secure state; for an
3
exception taken to Secure state they become UNKNOWN, and we chose to
4
leave them at their previous values.
2
5
3
Reviewed-by: Cédric Le Goater <clg@kaod.org>
6
In v8.1M the behaviour is specified more tightly and these registers
4
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
are always zeroed regardless of the security state that the exception
5
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
8
targets (see rule R_KPZV). Implement this.
6
Message-id: 20200911052101.2602693-14-hskinnemoen@google.com
9
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Message-id: 20201119215617.29887-17-peter.maydell@linaro.org
8
---
13
---
9
docs/system/arm/nuvoton.rst | 92 +++++++++++++++++++++++++++++++++++++
14
target/arm/m_helper.c | 16 ++++++++++++----
10
docs/system/target-arm.rst | 1 +
15
1 file changed, 12 insertions(+), 4 deletions(-)
11
2 files changed, 93 insertions(+)
12
create mode 100644 docs/system/arm/nuvoton.rst
13
16
14
diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst
17
diff --git a/target/arm/m_helper.c b/target/arm/m_helper.c
15
new file mode 100644
16
index XXXXXXX..XXXXXXX
17
--- /dev/null
18
+++ b/docs/system/arm/nuvoton.rst
19
@@ -XXX,XX +XXX,XX @@
20
+Nuvoton iBMC boards (``npcm750-evb``, ``quanta-gsj``)
21
+=====================================================
22
+
23
+The `Nuvoton iBMC`_ chips (NPCM7xx) are a family of ARM-based SoCs that are
24
+designed to be used as Baseboard Management Controllers (BMCs) in various
25
+servers. They all feature one or two ARM Cortex A9 CPU cores, as well as an
26
+assortment of peripherals targeted for either Enterprise or Data Center /
27
+Hyperscale applications. The former is a superset of the latter, so NPCM750 has
28
+all the peripherals of NPCM730 and more.
29
+
30
+.. _Nuvoton iBMC: https://www.nuvoton.com/products/cloud-computing/ibmc/
31
+
32
+The NPCM750 SoC has two Cortex A9 cores and is targeted for the Enterprise
33
+segment. The following machines are based on this chip :
34
+
35
+- ``npcm750-evb`` Nuvoton NPCM750 Evaluation board
36
+
37
+The NPCM730 SoC has two Cortex A9 cores and is targeted for Data Center and
38
+Hyperscale applications. The following machines are based on this chip :
39
+
40
+- ``quanta-gsj`` Quanta GSJ server BMC
41
+
42
+There are also two more SoCs, NPCM710 and NPCM705, which are single-core
43
+variants of NPCM750 and NPCM730, respectively. These are currently not
44
+supported by QEMU.
45
+
46
+Supported devices
47
+-----------------
48
+
49
+ * SMP (Dual Core Cortex-A9)
50
+ * Cortex-A9MPCore built-in peripherals: SCU, GIC, Global Timer, Private Timer
51
+ and Watchdog.
52
+ * SRAM, ROM and DRAM mappings
53
+ * System Global Control Registers (GCR)
54
+ * Clock and reset controller (CLK)
55
+ * Timer controller (TIM)
56
+ * Serial ports (16550-based)
57
+ * DDR4 memory controller (dummy interface indicating memory training is done)
58
+ * OTP controllers (no protection features)
59
+ * Flash Interface Unit (FIU; no protection features)
60
+
61
+Missing devices
62
+---------------
63
+
64
+ * GPIO controller
65
+ * LPC/eSPI host-to-BMC interface, including
66
+
67
+ * Keyboard and mouse controller interface (KBCI)
68
+ * Keyboard Controller Style (KCS) channels
69
+ * BIOS POST code FIFO
70
+ * System Wake-up Control (SWC)
71
+ * Shared memory (SHM)
72
+ * eSPI slave interface
73
+
74
+ * Ethernet controllers (GMAC and EMC)
75
+ * USB host (USBH)
76
+ * USB device (USBD)
77
+ * SMBus controller (SMBF)
78
+ * Peripheral SPI controller (PSPI)
79
+ * Analog to Digital Converter (ADC)
80
+ * SD/MMC host
81
+ * Random Number Generator (RNG)
82
+ * PECI interface
83
+ * Pulse Width Modulation (PWM)
84
+ * Tachometer
85
+ * PCI and PCIe root complex and bridges
86
+ * VDM and MCTP support
87
+ * Serial I/O expansion
88
+ * LPC/eSPI host
89
+ * Coprocessor
90
+ * Graphics
91
+ * Video capture
92
+ * Encoding compression engine
93
+ * Security features
94
+
95
+Boot options
96
+------------
97
+
98
+The Nuvoton machines can boot from an OpenBMC firmware image, or directly into
99
+a kernel using the ``-kernel`` option. OpenBMC images for `quanta-gsj` and
100
+possibly others can be downloaded from the OpenPOWER jenkins :
101
+
102
+ https://openpower.xyz/
103
+
104
+The firmware image should be attached as an MTD drive. Example :
105
+
106
+.. code-block:: bash
107
+
108
+ $ qemu-system-arm -machine quanta-gsj -nographic \
109
+ -drive file=image-bmc,if=mtd,bus=0,unit=0,format=raw
110
+
111
+The default root password for test images is usually ``0penBmc``.
112
diff --git a/docs/system/target-arm.rst b/docs/system/target-arm.rst
113
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
114
--- a/docs/system/target-arm.rst
19
--- a/target/arm/m_helper.c
115
+++ b/docs/system/target-arm.rst
20
+++ b/target/arm/m_helper.c
116
@@ -XXX,XX +XXX,XX @@ undocumented; you can get a complete list by running
21
@@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain,
117
arm/musicpal
22
* Clear registers if necessary to prevent non-secure exception
118
arm/gumstix
23
* code being able to see register values from secure code.
119
arm/nseries
24
* Where register values become architecturally UNKNOWN we leave
120
+ arm/nuvoton
25
- * them with their previous values.
121
arm/orangepi
26
+ * them with their previous values. v8.1M is tighter than v8.0M
122
arm/palm
27
+ * here and always zeroes the caller-saved registers regardless
123
arm/xscale
28
+ * of the security state the exception is targeting.
29
*/
30
if (arm_feature(env, ARM_FEATURE_M_SECURITY)) {
31
- if (!targets_secure) {
32
+ if (!targets_secure || arm_feature(env, ARM_FEATURE_V8_1M)) {
33
/*
34
* Always clear the caller-saved registers (they have been
35
* pushed to the stack earlier in v7m_push_stack()).
36
@@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain,
37
* v7m_push_callee_stack()).
38
*/
39
int i;
40
+ /*
41
+ * r4..r11 are callee-saves, zero only if background
42
+ * state was Secure (EXCRET.S == 1) and exception
43
+ * targets Non-secure state
44
+ */
45
+ bool zero_callee_saves = !targets_secure &&
46
+ (lr & R_V7M_EXCRET_S_MASK);
47
48
for (i = 0; i < 13; i++) {
49
- /* r4..r11 are callee-saves, zero only if EXCRET.S == 1 */
50
- if (i < 4 || i > 11 || (lr & R_V7M_EXCRET_S_MASK)) {
51
+ if (i < 4 || i > 11 || zero_callee_saves) {
52
env->regs[i] = 0;
53
}
54
}
124
--
55
--
125
2.20.1
56
2.20.1
126
57
127
58
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
In v8.1M, vector table fetch failures don't set HFSR.FORCED (see rule
2
R_LLRP). (In previous versions of the architecture this was either
3
required or IMPDEF.)
2
4
3
When booting directly into a kernel, bypassing the boot loader, the CPU and
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
UART clocks are not set up correctly. This makes the system appear very
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
slow, and causes the initrd boot test to fail when optimization is off.
7
Message-id: 20201119215617.29887-18-peter.maydell@linaro.org
8
---
9
target/arm/m_helper.c | 6 +++++-
10
1 file changed, 5 insertions(+), 1 deletion(-)
6
11
7
The UART clock must run at 24 MHz. The default 25 MHz reference clock
12
diff --git a/target/arm/m_helper.c b/target/arm/m_helper.c
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
22
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
23
---
24
include/hw/arm/npcm7xx.h | 1 +
25
hw/arm/npcm7xx.c | 32 ++++++++++++++++++++++++++++++++
26
2 files changed, 33 insertions(+)
27
28
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
29
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
30
--- a/include/hw/arm/npcm7xx.h
14
--- a/target/arm/m_helper.c
31
+++ b/include/hw/arm/npcm7xx.h
15
+++ b/target/arm/m_helper.c
32
@@ -XXX,XX +XXX,XX @@
16
@@ -XXX,XX +XXX,XX @@ load_fail:
33
#define NPCM7XX_SMP_LOADER_START (0xffff0000) /* Boot ROM */
17
* The HardFault is Secure if BFHFNMINS is 0 (meaning that all HFs are
34
#define NPCM7XX_SMP_BOOTREG_ADDR (0xf080013c) /* GCR.SCRPAD */
18
* secure); otherwise it targets the same security state as the
35
#define NPCM7XX_GIC_CPU_IF_ADDR (0xf03fe100) /* GIC within A9 */
19
* underlying exception.
36
+#define NPCM7XX_BOARD_SETUP_ADDR (0xffff1000) /* Boot ROM */
20
+ * In v8.1M HardFaults from vector table fetch fails don't set FORCED.
37
21
*/
38
typedef struct NPCM7xxMachine {
22
if (!(cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK)) {
39
MachineState parent;
23
exc_secure = true;
40
diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c
24
}
41
index XXXXXXX..XXXXXXX 100644
25
- env->v7m.hfsr |= R_V7M_HFSR_VECTTBL_MASK | R_V7M_HFSR_FORCED_MASK;
42
--- a/hw/arm/npcm7xx.c
26
+ env->v7m.hfsr |= R_V7M_HFSR_VECTTBL_MASK;
43
+++ b/hw/arm/npcm7xx.c
27
+ if (!arm_feature(env, ARM_FEATURE_V8_1M)) {
44
@@ -XXX,XX +XXX,XX @@
28
+ env->v7m.hfsr |= R_V7M_HFSR_FORCED_MASK;
45
#define NPCM7XX_ROM_BA (0xffff0000)
46
#define NPCM7XX_ROM_SZ (64 * KiB)
47
48
+/* Clock configuration values to be fixed up when bypassing bootloader */
49
+
50
+/* Run PLL1 at 1600 MHz */
51
+#define NPCM7XX_PLLCON1_FIXUP_VAL (0x00402101)
52
+/* Run the CPU from PLL1 and UART from PLL2 */
53
+#define NPCM7XX_CLKSEL_FIXUP_VAL (0x004aaba9)
54
+
55
/*
56
* Interrupt lines going into the GIC. This does not include internal Cortex-A9
57
* interrupts.
58
@@ -XXX,XX +XXX,XX @@ static const struct {
59
},
60
};
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;
77
+
78
+ for (i = 0; i < ARRAY_SIZE(board_setup); i++) {
79
+ board_setup[i] = tswap32(board_setup[i]);
80
+ }
29
+ }
81
+ rom_add_blob_fixed("board-setup", board_setup, sizeof(board_setup),
30
armv7m_nvic_set_pending_derived(env->nvic, ARMV7M_EXCP_HARD, exc_secure);
82
+ info->board_setup_addr);
31
return false;
83
+}
32
}
84
+
85
static void npcm7xx_write_secondary_boot(ARMCPU *cpu,
86
const struct arm_boot_info *info)
87
{
88
@@ -XXX,XX +XXX,XX @@ static struct arm_boot_info npcm7xx_binfo = {
89
.gic_cpu_if_addr = NPCM7XX_GIC_CPU_IF_ADDR,
90
.write_secondary_boot = npcm7xx_write_secondary_boot,
91
.board_id = -1,
92
+ .board_setup_addr = NPCM7XX_BOARD_SETUP_ADDR,
93
+ .write_board_setup = npcm7xx_write_board_setup,
94
};
95
96
void npcm7xx_load_kernel(MachineState *machine, NPCM7xxState *soc)
97
--
33
--
98
2.20.1
34
2.20.1
99
35
100
36
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
In v8.1M a REVIDR register is defined, which is at address 0xe00ecfc
2
and is a read-only IMPDEF register providing implementation specific
3
minor revision information, like the v8A REVIDR_EL1. Implement this.
2
4
3
This is a minimalistic boot ROM written specifically for use with QEMU.
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
It supports loading the second-stage loader from SPI flash into RAM, SMP
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
boot, and not much else.
7
Message-id: 20201119215617.29887-19-peter.maydell@linaro.org
8
---
9
hw/intc/armv7m_nvic.c | 5 +++++
10
1 file changed, 5 insertions(+)
6
11
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
12
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
8
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
10
Message-id: 20200911052101.2602693-7-hskinnemoen@google.com
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
13
.gitmodules | 3 +++
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
23
24
diff --git a/.gitmodules b/.gitmodules
25
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
26
--- a/.gitmodules
14
--- a/hw/intc/armv7m_nvic.c
27
+++ b/.gitmodules
15
+++ b/hw/intc/armv7m_nvic.c
28
@@ -XXX,XX +XXX,XX @@
16
@@ -XXX,XX +XXX,XX @@ static uint32_t nvic_readl(NVICState *s, uint32_t offset, MemTxAttrs attrs)
29
[submodule "meson"]
17
}
30
    path = meson
18
return val;
31
    url = https://github.com/mesonbuild/meson/
19
}
32
+[submodule "roms/vbootrom"]
20
+ case 0xcfc:
33
+    path = roms/vbootrom
21
+ if (!arm_feature(&cpu->env, ARM_FEATURE_V8_1M)) {
34
+    url = https://github.com/google/vbootrom.git
22
+ goto bad_offset;
35
diff --git a/MAINTAINERS b/MAINTAINERS
23
+ }
36
index XXXXXXX..XXXXXXX 100644
24
+ return cpu->revidr;
37
--- a/MAINTAINERS
25
case 0xd00: /* CPUID Base. */
38
+++ b/MAINTAINERS
26
return cpu->midr;
39
@@ -XXX,XX +XXX,XX @@ L: qemu-arm@nongnu.org
27
case 0xd04: /* Interrupt Control State (ICSR) */
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.
56
+
57
+- npcm7xx_bootrom.bin is a simplified, free (Apache 2.0) boot ROM for Nuvoton
58
+ NPCM7xx BMC devices. It currently implements the bare minimum to load, parse,
59
+ initialize and run boot images stored in SPI flash, but may grow more
60
+ features over time as needed. The source code is available at:
61
+ https://github.com/google/vbootrom
62
diff --git a/pc-bios/meson.build b/pc-bios/meson.build
63
index XXXXXXX..XXXXXXX 100644
64
--- a/pc-bios/meson.build
65
+++ b/pc-bios/meson.build
66
@@ -XXX,XX +XXX,XX @@ blobs = files(
67
'opensbi-riscv64-generic-fw_dynamic.bin',
68
'opensbi-riscv32-generic-fw_dynamic.elf',
69
'opensbi-riscv64-generic-fw_dynamic.elf',
70
+ 'npcm7xx_bootrom.bin',
71
)
72
73
if install_blobs
74
diff --git a/pc-bios/npcm7xx_bootrom.bin b/pc-bios/npcm7xx_bootrom.bin
75
new file mode 100644
76
index XXXXXXX..XXXXXXX
77
GIT binary patch
78
literal 768
79
zcmd5)JxClu6n-<aczPbVhZYusb8wKx;7TklHfmuZdYT9pDRLwd1p_t-DFpWpyA+8(
80
zwKtZg3J4a0aCM3_X(ZL&4g;46VVk5e$K;z;L99|b@aE%v^S$rQ8)h(Vm@cB9IYc+2
81
z2SHd4^NwTIGE%w>9S05p1#kf90Sj5Z(jG8}+)IZIp~iXK=T&)dL`%d-q*8aR#mq{7
82
z9`=6;Dr(H0ACe72R5x?!)^86Qj-X%{+!K9iZNA@*wkBAV&iZ(l^I9?!Gz=S2I_*1d
83
zr+tTQDHjvyzKnw(hu00yX`u!Fv<!~XVcX?@kr#<B0(gGU?$W{gSsQa}CF^8Cfzp2X
84
z@P}yDV-bci(K9XL$FU!som2C`c)?Uc&294s^}Wzumap{hg1X^jN|V25M5tQZ=<9lN
85
z%(zKz#t-qCwHKb;HygOCpvCNL_4@1tXV1YGf^XUE_$zr{g8zWh-6gz-teI(eibtxo
86
z?0OZI4%rU0741PgUD`2xq@H|*4=+Rs?%N)Ox5G+q>C;DilBe_YlkeSUVHA-crNk+k
87
jtiF_MudA<CB(}8|fqYwCf3re&=&@_s761P#-ID$TwgmBa
88
89
literal 0
90
HcmV?d00001
91
92
diff --git a/roms/Makefile b/roms/Makefile
93
index XXXXXXX..XXXXXXX 100644
94
--- a/roms/Makefile
95
+++ b/roms/Makefile
96
@@ -XXX,XX +XXX,XX @@ find-cross-gcc = $(firstword $(wildcard $(patsubst %ld,%gcc,$(call find-cross-ld
97
# finally strip off path + toolname so we get the prefix
98
find-cross-prefix = $(subst gcc,,$(notdir $(call find-cross-gcc,$(1))))
99
100
+arm_cross_prefix := $(call find-cross-prefix,arm)
101
powerpc64_cross_prefix := $(call find-cross-prefix,powerpc64)
102
powerpc_cross_prefix := $(call find-cross-prefix,powerpc)
103
x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
104
@@ -XXX,XX +XXX,XX @@ default help:
105
    @echo " skiboot -- update skiboot.lid"
106
    @echo " u-boot.e500 -- update u-boot.e500"
107
    @echo " u-boot.sam460 -- update u-boot.sam460"
108
+    @echo " npcm7xx_bootrom -- update vbootrom for npcm7xx"
109
    @echo " efi -- update UEFI (edk2) platform firmware"
110
    @echo " opensbi32-generic -- update OpenSBI for 32-bit generic machine"
111
    @echo " opensbi64-generic -- update OpenSBI for 64-bit generic machine"
112
@@ -XXX,XX +XXX,XX @@ bios-microvm:
113
    $(MAKE) -C qboot
114
    cp qboot/bios.bin ../pc-bios/bios-microvm.bin
115
116
+npcm7xx_bootrom:
117
+    $(MAKE) -C vbootrom CROSS_COMPILE=$(arm_cross_prefix)
118
+    cp vbootrom/npcm7xx_bootrom.bin ../pc-bios/npcm7xx_bootrom.bin
119
+
120
clean:
121
    rm -rf seabios/.config seabios/out seabios/builds
122
    $(MAKE) -C sgabios clean
123
@@ -XXX,XX +XXX,XX @@ clean:
124
    $(MAKE) -f Makefile.edk2 clean
125
    $(MAKE) -C opensbi clean
126
    $(MAKE) -C qboot clean
127
+    $(MAKE) -C vbootrom clean
128
diff --git a/roms/vbootrom b/roms/vbootrom
129
new file mode 160000
130
index XXXXXXX..XXXXXXX
131
--- /dev/null
132
+++ b/roms/vbootrom
133
@@ -0,0 +1 @@
134
+Subproject commit 0c37a43527f0ee2b9584e7fb2fdc805e902635ac
135
--
28
--
136
2.20.1
29
2.20.1
137
30
138
31
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
In v8.1M a new exception return check is added which may cause a NOCP
2
UsageFault (see rule R_XLTP): before we clear s0..s15 and the FPSCR
3
we must check whether access to CP10 from the Security state of the
4
returning exception is disabled; if it is then we must take a fault.
2
5
3
Only argument set members have to be C identifiers, everything
6
(Note that for our implementation CPPWR is always RAZ/WI and so can
4
else gets prefixed during conversion to C. Some places just
7
never cause CP10 accesses to fail.)
5
checked the leading character, and some places matched a leading
6
character plus a C identifier.
7
8
8
Convert everything to match full identifiers, including the
9
The other v8.1M change to this register-clearing code is that if MVE
9
[&%@&] prefix, and drop the full C identifier requirement.
10
is implemented VPR must also be cleared, so add a TODO comment to
11
that effect.
10
12
11
Reported-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
13
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
14
Message-id: 20200903192334.1603773-1-richard.henderson@linaro.org
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
15
Message-id: 20201119215617.29887-20-peter.maydell@linaro.org
16
---
16
---
17
tests/decode/succ_ident1.decode | 7 +++++
17
target/arm/m_helper.c | 22 +++++++++++++++++++++-
18
scripts/decodetree.py | 46 +++++++++++++++++++++------------
18
1 file changed, 21 insertions(+), 1 deletion(-)
19
2 files changed, 37 insertions(+), 16 deletions(-)
20
create mode 100644 tests/decode/succ_ident1.decode
21
19
22
diff --git a/tests/decode/succ_ident1.decode b/tests/decode/succ_ident1.decode
20
diff --git a/target/arm/m_helper.c b/target/arm/m_helper.c
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
35
diff --git a/scripts/decodetree.py b/scripts/decodetree.py
36
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
37
--- a/scripts/decodetree.py
22
--- a/target/arm/m_helper.c
38
+++ b/scripts/decodetree.py
23
+++ b/target/arm/m_helper.c
39
@@ -XXX,XX +XXX,XX @@ output_fd = None
24
@@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu)
40
insntype = 'uint32_t'
25
v7m_exception_taken(cpu, excret, true, false);
41
decode_function = 'decode'
26
return;
42
27
} else {
43
-re_ident = '[a-zA-Z][a-zA-Z0-9_]*'
28
- /* Clear s0..s15 and FPSCR */
44
+# An identifier for C.
29
+ if (arm_feature(env, ARM_FEATURE_V8_1M)) {
45
+re_C_ident = '[a-zA-Z][a-zA-Z0-9_]*'
30
+ /* v8.1M adds this NOCP check */
46
31
+ bool nsacr_pass = exc_secure ||
47
+# Identifiers for Arguments, Fields, Formats and Patterns.
32
+ extract32(env->v7m.nsacr, 10, 1);
48
+re_arg_ident = '&[a-zA-Z0-9_]*'
33
+ bool cpacr_pass = v7m_cpacr_pass(env, exc_secure, true);
49
+re_fld_ident = '%[a-zA-Z0-9_]*'
34
+ if (!nsacr_pass) {
50
+re_fmt_ident = '@[a-zA-Z0-9_]*'
35
+ armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE, true);
51
+re_pat_ident = '[a-zA-Z0-9_]*'
36
+ env->v7m.cfsr[M_REG_S] |= R_V7M_CFSR_NOCP_MASK;
52
37
+ qemu_log_mask(CPU_LOG_INT, "...taking UsageFault on existing "
53
def error_with_file(file, lineno, *args):
38
+ "stackframe: NSACR prevents clearing FPU registers\n");
54
"""Print an error message from file:line and args and exit."""
39
+ v7m_exception_taken(cpu, excret, true, false);
55
@@ -XXX,XX +XXX,XX @@ class ExcMultiPattern(MultiPattern):
40
+ } else if (!cpacr_pass) {
56
def parse_field(lineno, name, toks):
41
+ armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE,
57
"""Parse one instruction field from TOKS at LINENO"""
42
+ exc_secure);
58
global fields
43
+ env->v7m.cfsr[exc_secure] |= R_V7M_CFSR_NOCP_MASK;
59
- global re_ident
44
+ qemu_log_mask(CPU_LOG_INT, "...taking UsageFault on existing "
60
global insnwidth
45
+ "stackframe: CPACR prevents clearing FPU registers\n");
61
46
+ v7m_exception_taken(cpu, excret, true, false);
62
# A "simple" field will have only one entry;
47
+ }
63
@@ -XXX,XX +XXX,XX @@ def parse_field(lineno, name, toks):
48
+ }
64
width = 0
49
+ /* Clear s0..s15 and FPSCR; TODO also VPR when MVE is implemented */
65
func = None
50
int i;
66
for t in toks:
51
67
- if re.fullmatch('!function=' + re_ident, t):
52
for (i = 0; i < 16; i += 2) {
68
+ if re.match('^!function=', t):
69
if func:
70
error(lineno, 'duplicate function')
71
func = t.split('=')
72
@@ -XXX,XX +XXX,XX @@ def parse_field(lineno, name, toks):
73
def parse_arguments(lineno, name, toks):
74
"""Parse one argument set from TOKS at LINENO"""
75
global arguments
76
- global re_ident
77
+ global re_C_ident
78
global anyextern
79
80
flds = []
81
@@ -XXX,XX +XXX,XX @@ def parse_arguments(lineno, name, toks):
82
extern = True
83
anyextern = True
84
continue
85
- if not re.fullmatch(re_ident, t):
86
+ if not re.fullmatch(re_C_ident, t):
87
error(lineno, 'invalid argument set token "{0}"'.format(t))
88
if t in flds:
89
error(lineno, 'duplicate argument "{0}"'.format(t))
90
@@ -XXX,XX +XXX,XX @@ def parse_generic(lineno, parent_pat, name, toks):
91
global arguments
92
global formats
93
global allpatterns
94
- global re_ident
95
+ global re_arg_ident
96
+ global re_fld_ident
97
+ global re_fmt_ident
98
+ global re_C_ident
99
global insnwidth
100
global insnmask
101
global variablewidth
102
@@ -XXX,XX +XXX,XX @@ def parse_generic(lineno, parent_pat, name, toks):
103
fmt = None
104
for t in toks:
105
# '&Foo' gives a format an explcit argument set.
106
- if t[0] == '&':
107
+ if re.fullmatch(re_arg_ident, t):
108
tt = t[1:]
109
if arg:
110
error(lineno, 'multiple argument sets')
111
@@ -XXX,XX +XXX,XX @@ def parse_generic(lineno, parent_pat, name, toks):
112
continue
113
114
# '@Foo' gives a pattern an explicit format.
115
- if t[0] == '@':
116
+ if re.fullmatch(re_fmt_ident, t):
117
tt = t[1:]
118
if fmt:
119
error(lineno, 'multiple formats')
120
@@ -XXX,XX +XXX,XX @@ def parse_generic(lineno, parent_pat, name, toks):
121
continue
122
123
# '%Foo' imports a field.
124
- if t[0] == '%':
125
+ if re.fullmatch(re_fld_ident, t):
126
tt = t[1:]
127
flds = add_field_byname(lineno, flds, tt, tt)
128
continue
129
130
# 'Foo=%Bar' imports a field with a different name.
131
- if re.fullmatch(re_ident + '=%' + re_ident, t):
132
+ if re.fullmatch(re_C_ident + '=' + re_fld_ident, t):
133
(fname, iname) = t.split('=%')
134
flds = add_field_byname(lineno, flds, fname, iname)
135
continue
136
137
# 'Foo=number' sets an argument field to a constant value
138
- if re.fullmatch(re_ident + '=[+-]?[0-9]+', t):
139
+ if re.fullmatch(re_C_ident + '=[+-]?[0-9]+', t):
140
(fname, value) = t.split('=')
141
value = int(value)
142
flds = add_field(lineno, flds, fname, ConstField(value))
143
@@ -XXX,XX +XXX,XX @@ def parse_generic(lineno, parent_pat, name, toks):
144
fixedmask = (fixedmask << shift) | fms
145
undefmask = (undefmask << shift) | ubm
146
# Otherwise, fieldname:fieldwidth
147
- elif re.fullmatch(re_ident + ':s?[0-9]+', t):
148
+ elif re.fullmatch(re_C_ident + ':s?[0-9]+', t):
149
(fname, flen) = t.split(':')
150
sign = False
151
if flen[0] == 's':
152
@@ -XXX,XX +XXX,XX @@ def parse_generic(lineno, parent_pat, name, toks):
153
154
def parse_file(f, parent_pat):
155
"""Parse all of the patterns within a file"""
156
+ global re_arg_ident
157
+ global re_fld_ident
158
+ global re_fmt_ident
159
+ global re_pat_ident
160
161
# Read all of the lines of the file. Concatenate lines
162
# ending in backslash; discard empty lines and comments.
163
@@ -XXX,XX +XXX,XX @@ def parse_file(f, parent_pat):
164
continue
165
166
# Determine the type of object needing to be parsed.
167
- if name[0] == '%':
168
+ if re.fullmatch(re_fld_ident, name):
169
parse_field(start_lineno, name[1:], toks)
170
- elif name[0] == '&':
171
+ elif re.fullmatch(re_arg_ident, name):
172
parse_arguments(start_lineno, name[1:], toks)
173
- elif name[0] == '@':
174
+ elif re.fullmatch(re_fmt_ident, name):
175
parse_generic(start_lineno, None, name[1:], toks)
176
- else:
177
+ elif re.fullmatch(re_pat_ident, name):
178
parse_generic(start_lineno, parent_pat, name, toks)
179
+ else:
180
+ error(lineno, 'invalid token "{0}"'.format(name))
181
toks = []
182
183
if nesting != 0:
184
--
53
--
185
2.20.1
54
2.20.1
186
55
187
56
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
v8.1M adds new encodings of VLLDM and VLSTM (where bit 7 is set).
2
The only difference is that:
3
* the old T1 encodings UNDEF if the implementation implements 32
4
Dregs (this is currently architecturally impossible for M-profile)
5
* the new T2 encodings have the implementation-defined option to
6
read from memory (discarding the data) or write UNKNOWN values to
7
memory for the stack slots that would be D16-D31
2
8
3
This implements a device model for the NPCM7xx SPI flash controller.
9
We choose not to make those accesses, so for us the two
10
instructions behave identically assuming they don't UNDEF.
4
11
5
Direct reads and writes, and user-mode transactions have been tested in
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
various modes. Protection features are not implemented yet.
13
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
14
Message-id: 20201119215617.29887-21-peter.maydell@linaro.org
15
---
16
target/arm/m-nocp.decode | 2 +-
17
target/arm/translate-vfp.c.inc | 25 +++++++++++++++++++++++++
18
2 files changed, 26 insertions(+), 1 deletion(-)
7
19
8
All the FIU instances are available in the SoC's address space,
20
diff --git a/target/arm/m-nocp.decode b/target/arm/m-nocp.decode
9
regardless of whether or not they're connected to actual flash chips.
10
11
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
12
Reviewed-by: Cédric Le Goater <clg@kaod.org>
13
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
14
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
15
Tested-by: Alexander Bulekov <alxndr@bu.edu>
16
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
17
Message-id: 20200911052101.2602693-11-hskinnemoen@google.com
18
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
19
---
20
include/hw/arm/npcm7xx.h | 2 +
21
include/hw/ssi/npcm7xx_fiu.h | 73 +++++
22
hw/arm/npcm7xx.c | 58 ++++
23
hw/ssi/npcm7xx_fiu.c | 572 +++++++++++++++++++++++++++++++++++
24
hw/arm/Kconfig | 1 +
25
hw/ssi/meson.build | 1 +
26
hw/ssi/trace-events | 11 +
27
7 files changed, 718 insertions(+)
28
create mode 100644 include/hw/ssi/npcm7xx_fiu.h
29
create mode 100644 hw/ssi/npcm7xx_fiu.c
30
31
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
32
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
33
--- a/include/hw/arm/npcm7xx.h
22
--- a/target/arm/m-nocp.decode
34
+++ b/include/hw/arm/npcm7xx.h
23
+++ b/target/arm/m-nocp.decode
35
@@ -XXX,XX +XXX,XX @@
24
@@ -XXX,XX +XXX,XX @@
36
#include "hw/misc/npcm7xx_gcr.h"
25
37
#include "hw/nvram/npcm7xx_otp.h"
26
{
38
#include "hw/timer/npcm7xx_timer.h"
27
# Special cases which do not take an early NOCP: VLLDM and VLSTM
39
+#include "hw/ssi/npcm7xx_fiu.h"
28
- VLLDM_VLSTM 1110 1100 001 l:1 rn:4 0000 1010 0000 0000
40
#include "target/arm/cpu.h"
29
+ VLLDM_VLSTM 1110 1100 001 l:1 rn:4 0000 1010 op:1 000 0000
41
30
# VSCCLRM (new in v8.1M) is similar:
42
#define NPCM7XX_MAX_NUM_CPUS (2)
31
VSCCLRM 1110 1100 1.01 1111 .... 1011 imm:7 0 vd=%vd_dp size=3
43
@@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState {
32
VSCCLRM 1110 1100 1.01 1111 .... 1010 imm:8 vd=%vd_sp size=2
44
NPCM7xxOTPState key_storage;
33
diff --git a/target/arm/translate-vfp.c.inc b/target/arm/translate-vfp.c.inc
45
NPCM7xxOTPState fuse_array;
46
NPCM7xxMCState mc;
47
+ NPCM7xxFIUState fiu[2];
48
} NPCM7xxState;
49
50
#define TYPE_NPCM7XX "npcm7xx"
51
diff --git a/include/hw/ssi/npcm7xx_fiu.h b/include/hw/ssi/npcm7xx_fiu.h
52
new file mode 100644
53
index XXXXXXX..XXXXXXX
54
--- /dev/null
55
+++ b/include/hw/ssi/npcm7xx_fiu.h
56
@@ -XXX,XX +XXX,XX @@
57
+/*
58
+ * Nuvoton NPCM7xx Flash Interface Unit (FIU)
59
+ *
60
+ * Copyright 2020 Google LLC
61
+ *
62
+ * This program is free software; you can redistribute it and/or modify it
63
+ * under the terms of the GNU General Public License as published by the
64
+ * Free Software Foundation; either version 2 of the License, or
65
+ * (at your option) any later version.
66
+ *
67
+ * This program is distributed in the hope that it will be useful, but WITHOUT
68
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
69
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
70
+ * for more details.
71
+ */
72
+#ifndef NPCM7XX_FIU_H
73
+#define NPCM7XX_FIU_H
74
+
75
+#include "hw/ssi/ssi.h"
76
+#include "hw/sysbus.h"
77
+
78
+/*
79
+ * Number of registers in our device state structure. Don't change this without
80
+ * incrementing the version_id in the vmstate.
81
+ */
82
+#define NPCM7XX_FIU_NR_REGS (0x7c / sizeof(uint32_t))
83
+
84
+typedef struct NPCM7xxFIUState NPCM7xxFIUState;
85
+
86
+/**
87
+ * struct NPCM7xxFIUFlash - Per-chipselect flash controller state.
88
+ * @direct_access: Memory region for direct flash access.
89
+ * @fiu: Pointer to flash controller shared state.
90
+ */
91
+typedef struct NPCM7xxFIUFlash {
92
+ MemoryRegion direct_access;
93
+ NPCM7xxFIUState *fiu;
94
+} NPCM7xxFIUFlash;
95
+
96
+/**
97
+ * NPCM7xxFIUState - Device state for one Flash Interface Unit.
98
+ * @parent: System bus device.
99
+ * @mmio: Memory region for register access.
100
+ * @cs_count: Number of flash chips that may be connected to this module.
101
+ * @active_cs: Currently active chip select, or -1 if no chip is selected.
102
+ * @cs_lines: GPIO lines that may be wired to flash chips.
103
+ * @flash: Array of @cs_count per-flash-chip state objects.
104
+ * @spi: The SPI bus mastered by this controller.
105
+ * @regs: Register contents.
106
+ *
107
+ * Each FIU has a shared bank of registers, and controls up to four chip
108
+ * selects. Each chip select has a dedicated memory region which may be used to
109
+ * read and write the flash connected to that chip select as if it were memory.
110
+ */
111
+struct NPCM7xxFIUState {
112
+ SysBusDevice parent;
113
+
114
+ MemoryRegion mmio;
115
+
116
+ int32_t cs_count;
117
+ int32_t active_cs;
118
+ qemu_irq *cs_lines;
119
+ NPCM7xxFIUFlash *flash;
120
+
121
+ SSIBus *spi;
122
+
123
+ uint32_t regs[NPCM7XX_FIU_NR_REGS];
124
+};
125
+
126
+#define TYPE_NPCM7XX_FIU "npcm7xx-fiu"
127
+#define NPCM7XX_FIU(obj) OBJECT_CHECK(NPCM7xxFIUState, (obj), TYPE_NPCM7XX_FIU)
128
+
129
+#endif /* NPCM7XX_FIU_H */
130
diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c
131
index XXXXXXX..XXXXXXX 100644
34
index XXXXXXX..XXXXXXX 100644
132
--- a/hw/arm/npcm7xx.c
35
--- a/target/arm/translate-vfp.c.inc
133
+++ b/hw/arm/npcm7xx.c
36
+++ b/target/arm/translate-vfp.c.inc
134
@@ -XXX,XX +XXX,XX @@ static const hwaddr npcm7xx_uart_addr[] = {
37
@@ -XXX,XX +XXX,XX @@ static bool trans_VLLDM_VLSTM(DisasContext *s, arg_VLLDM_VLSTM *a)
135
0xf0004000,
38
!arm_dc_feature(s, ARM_FEATURE_V8)) {
136
};
39
return false;
137
138
+/* Direct memory-mapped access to SPI0 CS0-1. */
139
+static const hwaddr npcm7xx_fiu0_flash_addr[] = {
140
+ 0x80000000, /* CS0 */
141
+ 0x88000000, /* CS1 */
142
+};
143
+
144
+/* Direct memory-mapped access to SPI3 CS0-3. */
145
+static const hwaddr npcm7xx_fiu3_flash_addr[] = {
146
+ 0xa0000000, /* CS0 */
147
+ 0xa8000000, /* CS1 */
148
+ 0xb0000000, /* CS2 */
149
+ 0xb8000000, /* CS3 */
150
+};
151
+
152
+static const struct {
153
+ const char *name;
154
+ hwaddr regs_addr;
155
+ int cs_count;
156
+ const hwaddr *flash_addr;
157
+} npcm7xx_fiu[] = {
158
+ {
159
+ .name = "fiu0",
160
+ .regs_addr = 0xfb000000,
161
+ .cs_count = ARRAY_SIZE(npcm7xx_fiu0_flash_addr),
162
+ .flash_addr = npcm7xx_fiu0_flash_addr,
163
+ }, {
164
+ .name = "fiu3",
165
+ .regs_addr = 0xc0000000,
166
+ .cs_count = ARRAY_SIZE(npcm7xx_fiu3_flash_addr),
167
+ .flash_addr = npcm7xx_fiu3_flash_addr,
168
+ },
169
+};
170
+
171
static void npcm7xx_write_secondary_boot(ARMCPU *cpu,
172
const struct arm_boot_info *info)
173
{
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
}
40
}
178
+
41
+
179
+ QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_fiu) != ARRAY_SIZE(s->fiu));
42
+ if (a->op) {
180
+ for (i = 0; i < ARRAY_SIZE(s->fiu); i++) {
43
+ /*
181
+ object_initialize_child(obj, npcm7xx_fiu[i].name, &s->fiu[i],
44
+ * T2 encoding ({D0-D31} reglist): v8.1M and up. We choose not
182
+ TYPE_NPCM7XX_FIU);
45
+ * to take the IMPDEF option to make memory accesses to the stack
183
+ }
46
+ * slots that correspond to the D16-D31 registers (discarding
184
}
47
+ * read data and writing UNKNOWN values), so for us the T2
185
48
+ * encoding behaves identically to the T1 encoding.
186
static void npcm7xx_realize(DeviceState *dev, Error **errp)
49
+ */
187
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
50
+ if (!arm_dc_feature(s, ARM_FEATURE_V8_1M)) {
188
serial_hd(i), DEVICE_LITTLE_ENDIAN);
51
+ return false;
189
}
52
+ }
190
53
+ } else {
191
+ /*
54
+ /*
192
+ * Flash Interface Unit (FIU). Can fail if incorrect number of chip selects
55
+ * T1 encoding ({D0-D15} reglist); undef if we have 32 Dregs.
193
+ * specified, but this is a programming error.
56
+ * This is currently architecturally impossible, but we add the
194
+ */
57
+ * check to stay in line with the pseudocode. Note that we must
195
+ QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_fiu) != ARRAY_SIZE(s->fiu));
58
+ * emit code for the UNDEF so it takes precedence over the NOCP.
196
+ for (i = 0; i < ARRAY_SIZE(s->fiu); i++) {
59
+ */
197
+ SysBusDevice *sbd = SYS_BUS_DEVICE(&s->fiu[i]);
60
+ if (dc_isar_feature(aa32_simd_r32, s)) {
198
+ int j;
61
+ unallocated_encoding(s);
199
+
62
+ return true;
200
+ object_property_set_int(OBJECT(sbd), "cs-count",
201
+ npcm7xx_fiu[i].cs_count, &error_abort);
202
+ sysbus_realize(sbd, &error_abort);
203
+
204
+ sysbus_mmio_map(sbd, 0, npcm7xx_fiu[i].regs_addr);
205
+ for (j = 0; j < npcm7xx_fiu[i].cs_count; j++) {
206
+ sysbus_mmio_map(sbd, j + 1, npcm7xx_fiu[i].flash_addr[j]);
207
+ }
63
+ }
208
+ }
64
+ }
209
+
65
+
210
/* RAM2 (SRAM) */
66
/*
211
memory_region_init_ram(&s->sram, OBJECT(dev), "ram2",
67
* If not secure, UNDEF. We must emit code for this
212
NPCM7XX_RAM2_SZ, &error_abort);
68
* rather than returning false so that this takes
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) {
354
+ return;
355
+ }
356
+
357
+ trace_npcm7xx_fiu_deselect(DEVICE(s)->canonical_path, s->active_cs);
358
+
359
+ qemu_irq_raise(s->cs_lines[s->active_cs]);
360
+ s->active_cs = -1;
361
+}
362
+
363
+/* Direct flash memory read handler. */
364
+static uint64_t npcm7xx_fiu_flash_read(void *opaque, hwaddr addr,
365
+ unsigned int size)
366
+{
367
+ NPCM7xxFIUFlash *f = opaque;
368
+ NPCM7xxFIUState *fiu = f->fiu;
369
+ uint64_t value = 0;
370
+ uint32_t drd_cfg;
371
+ int dummy_cycles;
372
+ int i;
373
+
374
+ if (fiu->active_cs != -1) {
375
+ qemu_log_mask(LOG_GUEST_ERROR,
376
+ "%s: direct flash read with CS%d already active",
377
+ DEVICE(fiu)->canonical_path, fiu->active_cs);
378
+ }
379
+
380
+ npcm7xx_fiu_select(fiu, npcm7xx_fiu_cs_index(fiu, f));
381
+
382
+ drd_cfg = fiu->regs[NPCM7XX_FIU_DRD_CFG];
383
+ ssi_transfer(fiu->spi, FIU_DRD_CFG_RDCMD(drd_cfg));
384
+
385
+ switch (FIU_DRD_CFG_ADDSIZ(drd_cfg)) {
386
+ case FIU_ADDSIZ_4BYTES:
387
+ ssi_transfer(fiu->spi, extract32(addr, 24, 8));
388
+ /* fall through */
389
+ case FIU_ADDSIZ_3BYTES:
390
+ ssi_transfer(fiu->spi, extract32(addr, 16, 8));
391
+ ssi_transfer(fiu->spi, extract32(addr, 8, 8));
392
+ ssi_transfer(fiu->spi, extract32(addr, 0, 8));
393
+ break;
394
+
395
+ default:
396
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: bad address size %d\n",
397
+ DEVICE(fiu)->canonical_path, FIU_DRD_CFG_ADDSIZ(drd_cfg));
398
+ break;
399
+ }
400
+
401
+ /* Flash chip model expects one transfer per dummy bit, not byte */
402
+ dummy_cycles =
403
+ (FIU_DRD_CFG_DBW(drd_cfg) * 8) >> FIU_DRD_CFG_ACCTYPE(drd_cfg);
404
+ for (i = 0; i < dummy_cycles; i++) {
405
+ ssi_transfer(fiu->spi, 0);
406
+ }
407
+
408
+ for (i = 0; i < size; i++) {
409
+ value = deposit64(value, 8 * i, 8, ssi_transfer(fiu->spi, 0));
410
+ }
411
+
412
+ trace_npcm7xx_fiu_flash_read(DEVICE(fiu)->canonical_path, fiu->active_cs,
413
+ addr, size, value);
414
+
415
+ npcm7xx_fiu_deselect(fiu);
416
+
417
+ return value;
418
+}
419
+
420
+/* Direct flash memory write handler. */
421
+static void npcm7xx_fiu_flash_write(void *opaque, hwaddr addr, uint64_t v,
422
+ unsigned int size)
423
+{
424
+ NPCM7xxFIUFlash *f = opaque;
425
+ NPCM7xxFIUState *fiu = f->fiu;
426
+ uint32_t dwr_cfg;
427
+ int cs_id;
428
+ int i;
429
+
430
+ if (fiu->active_cs != -1) {
431
+ qemu_log_mask(LOG_GUEST_ERROR,
432
+ "%s: direct flash write with CS%d already active",
433
+ DEVICE(fiu)->canonical_path, fiu->active_cs);
434
+ }
435
+
436
+ cs_id = npcm7xx_fiu_cs_index(fiu, f);
437
+ trace_npcm7xx_fiu_flash_write(DEVICE(fiu)->canonical_path, cs_id, addr,
438
+ size, v);
439
+ npcm7xx_fiu_select(fiu, cs_id);
440
+
441
+ dwr_cfg = fiu->regs[NPCM7XX_FIU_DWR_CFG];
442
+ ssi_transfer(fiu->spi, FIU_DWR_CFG_WRCMD(dwr_cfg));
443
+
444
+ switch (FIU_DWR_CFG_ADDSIZ(dwr_cfg)) {
445
+ case FIU_ADDSIZ_4BYTES:
446
+ ssi_transfer(fiu->spi, extract32(addr, 24, 8));
447
+ /* fall through */
448
+ case FIU_ADDSIZ_3BYTES:
449
+ ssi_transfer(fiu->spi, extract32(addr, 16, 8));
450
+ ssi_transfer(fiu->spi, extract32(addr, 8, 8));
451
+ ssi_transfer(fiu->spi, extract32(addr, 0, 8));
452
+ break;
453
+
454
+ default:
455
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: bad address size %d\n",
456
+ DEVICE(fiu)->canonical_path, FIU_DWR_CFG_ADDSIZ(dwr_cfg));
457
+ break;
458
+ }
459
+
460
+ for (i = 0; i < size; i++) {
461
+ ssi_transfer(fiu->spi, extract64(v, i * 8, 8));
462
+ }
463
+
464
+ npcm7xx_fiu_deselect(fiu);
465
+}
466
+
467
+static const MemoryRegionOps npcm7xx_fiu_flash_ops = {
468
+ .read = npcm7xx_fiu_flash_read,
469
+ .write = npcm7xx_fiu_flash_write,
470
+ .endianness = DEVICE_LITTLE_ENDIAN,
471
+ .valid = {
472
+ .min_access_size = 1,
473
+ .max_access_size = 8,
474
+ .unaligned = true,
475
+ },
476
+};
477
+
478
+/* Control register read handler. */
479
+static uint64_t npcm7xx_fiu_ctrl_read(void *opaque, hwaddr addr,
480
+ unsigned int size)
481
+{
482
+ hwaddr reg = addr / sizeof(uint32_t);
483
+ NPCM7xxFIUState *s = opaque;
484
+ uint32_t value;
485
+
486
+ if (reg < NPCM7XX_FIU_NR_REGS) {
487
+ value = s->regs[reg];
488
+ } else {
489
+ qemu_log_mask(LOG_GUEST_ERROR,
490
+ "%s: read from invalid offset 0x%" PRIx64 "\n",
491
+ DEVICE(s)->canonical_path, addr);
492
+ value = 0;
493
+ }
494
+
495
+ trace_npcm7xx_fiu_ctrl_read(DEVICE(s)->canonical_path, addr, value);
496
+
497
+ return value;
498
+}
499
+
500
+/* Send the specified number of address bytes from the UMA address register. */
501
+static void send_address(SSIBus *spi, unsigned int addsiz, uint32_t addr)
502
+{
503
+ switch (addsiz) {
504
+ case 4:
505
+ ssi_transfer(spi, extract32(addr, 24, 8));
506
+ /* fall through */
507
+ case 3:
508
+ ssi_transfer(spi, extract32(addr, 16, 8));
509
+ /* fall through */
510
+ case 2:
511
+ ssi_transfer(spi, extract32(addr, 8, 8));
512
+ /* fall through */
513
+ case 1:
514
+ ssi_transfer(spi, extract32(addr, 0, 8));
515
+ /* fall through */
516
+ case 0:
517
+ break;
518
+ }
519
+}
520
+
521
+/* Send the number of dummy bits specified in the UMA config register. */
522
+static void send_dummy_bits(SSIBus *spi, uint32_t uma_cfg, uint32_t uma_cmd)
523
+{
524
+ unsigned int bits_per_clock = 1U << FIU_UMA_CFG_DBPCK(uma_cfg);
525
+ unsigned int i;
526
+
527
+ for (i = 0; i < FIU_UMA_CFG_DBSIZ(uma_cfg); i++) {
528
+ /* Use bytes 0 and 1 first, then keep repeating byte 2 */
529
+ unsigned int field = (i < 2) ? ((i + 1) * 8) : 24;
530
+ unsigned int j;
531
+
532
+ for (j = 0; j < 8; j += bits_per_clock) {
533
+ ssi_transfer(spi, extract32(uma_cmd, field + j, bits_per_clock));
534
+ }
535
+ }
536
+}
537
+
538
+/* Perform a User-Mode Access transaction. */
539
+static void npcm7xx_fiu_uma_transaction(NPCM7xxFIUState *s)
540
+{
541
+ uint32_t uma_cts = s->regs[NPCM7XX_FIU_UMA_CTS];
542
+ uint32_t uma_cfg;
543
+ unsigned int i;
544
+
545
+ /* SW_CS means the CS is already forced low, so don't touch it. */
546
+ if (uma_cts & FIU_UMA_CTS_SW_CS) {
547
+ int cs_id = FIU_UMA_CTS_DEV_NUM(s->regs[NPCM7XX_FIU_UMA_CTS]);
548
+ npcm7xx_fiu_select(s, cs_id);
549
+ }
550
+
551
+ /* Send command, if present. */
552
+ uma_cfg = s->regs[NPCM7XX_FIU_UMA_CFG];
553
+ if (FIU_UMA_CFG_CMDSIZ(uma_cfg) > 0) {
554
+ ssi_transfer(s->spi, extract32(s->regs[NPCM7XX_FIU_UMA_CMD], 0, 8));
555
+ }
556
+
557
+ /* Send address, if present. */
558
+ send_address(s->spi, FIU_UMA_CFG_ADDSIZ(uma_cfg),
559
+ s->regs[NPCM7XX_FIU_UMA_ADDR]);
560
+
561
+ /* Write data, if present. */
562
+ for (i = 0; i < FIU_UMA_CFG_WDATSIZ(uma_cfg); i++) {
563
+ unsigned int reg =
564
+ (i < 16) ? (NPCM7XX_FIU_UMA_DW0 + i / 4) : NPCM7XX_FIU_UMA_DW3;
565
+ unsigned int field = (i % 4) * 8;
566
+
567
+ ssi_transfer(s->spi, extract32(s->regs[reg], field, 8));
568
+ }
569
+
570
+ /* Send dummy bits, if present. */
571
+ send_dummy_bits(s->spi, uma_cfg, s->regs[NPCM7XX_FIU_UMA_CMD]);
572
+
573
+ /* Read data, if present. */
574
+ for (i = 0; i < FIU_UMA_CFG_RDATSIZ(uma_cfg); i++) {
575
+ unsigned int reg = NPCM7XX_FIU_UMA_DR0 + i / 4;
576
+ unsigned int field = (i % 4) * 8;
577
+ uint8_t c;
578
+
579
+ c = ssi_transfer(s->spi, 0);
580
+ if (reg <= NPCM7XX_FIU_UMA_DR3) {
581
+ s->regs[reg] = deposit32(s->regs[reg], field, 8, c);
582
+ }
583
+ }
584
+
585
+ /* Again, don't touch CS if the user is forcing it low. */
586
+ if (uma_cts & FIU_UMA_CTS_SW_CS) {
587
+ npcm7xx_fiu_deselect(s);
588
+ }
589
+
590
+ /* RDYST means a command has completed since it was cleared. */
591
+ s->regs[NPCM7XX_FIU_UMA_CTS] |= FIU_UMA_CTS_RDYST;
592
+ /* EXEC_DONE means Execute Command / Not Done, so clear it here. */
593
+ s->regs[NPCM7XX_FIU_UMA_CTS] &= ~FIU_UMA_CTS_EXEC_DONE;
594
+}
595
+
596
+/* Control register write handler. */
597
+static void npcm7xx_fiu_ctrl_write(void *opaque, hwaddr addr, uint64_t v,
598
+ unsigned int size)
599
+{
600
+ hwaddr reg = addr / sizeof(uint32_t);
601
+ NPCM7xxFIUState *s = opaque;
602
+ uint32_t value = v;
603
+
604
+ trace_npcm7xx_fiu_ctrl_write(DEVICE(s)->canonical_path, addr, value);
605
+
606
+ switch (reg) {
607
+ case NPCM7XX_FIU_UMA_CFG:
608
+ if (s->regs[reg] & FIU_UMA_CFG_CMMLCK) {
609
+ value &= ~FIU_UMA_CFG_CMMLCK_MASK;
610
+ value |= (s->regs[reg] & FIU_UMA_CFG_CMMLCK_MASK);
611
+ }
612
+ /* fall through */
613
+ case NPCM7XX_FIU_DRD_CFG:
614
+ case NPCM7XX_FIU_DWR_CFG:
615
+ if (s->regs[reg] & NPCM7XX_FIU_CFG_LCK) {
616
+ qemu_log_mask(LOG_GUEST_ERROR,
617
+ "%s: write to locked register @ 0x%" PRIx64 "\n",
618
+ DEVICE(s)->canonical_path, addr);
619
+ return;
620
+ }
621
+ s->regs[reg] = value;
622
+ break;
623
+
624
+ case NPCM7XX_FIU_UMA_CTS:
625
+ if (value & FIU_UMA_CTS_RDYST) {
626
+ value &= ~FIU_UMA_CTS_RDYST;
627
+ } else {
628
+ value |= s->regs[reg] & FIU_UMA_CTS_RDYST;
629
+ }
630
+ if ((s->regs[reg] ^ value) & FIU_UMA_CTS_SW_CS) {
631
+ if (value & FIU_UMA_CTS_SW_CS) {
632
+ /*
633
+ * Don't drop CS if there's a transfer in progress, or we're
634
+ * about to start one.
635
+ */
636
+ if (!((value | s->regs[reg]) & FIU_UMA_CTS_EXEC_DONE)) {
637
+ npcm7xx_fiu_deselect(s);
638
+ }
639
+ } else {
640
+ int cs_id = FIU_UMA_CTS_DEV_NUM(s->regs[NPCM7XX_FIU_UMA_CTS]);
641
+ npcm7xx_fiu_select(s, cs_id);
642
+ }
643
+ }
644
+ s->regs[reg] = value | (s->regs[reg] & FIU_UMA_CTS_EXEC_DONE);
645
+ if (value & FIU_UMA_CTS_EXEC_DONE) {
646
+ npcm7xx_fiu_uma_transaction(s);
647
+ }
648
+ break;
649
+
650
+ case NPCM7XX_FIU_UMA_DR0 ... NPCM7XX_FIU_UMA_DR3:
651
+ qemu_log_mask(LOG_GUEST_ERROR,
652
+ "%s: write to read-only register @ 0x%" PRIx64 "\n",
653
+ DEVICE(s)->canonical_path, addr);
654
+ return;
655
+
656
+ case NPCM7XX_FIU_PRT_CFG:
657
+ case NPCM7XX_FIU_PRT_CMD0 ... NPCM7XX_FIU_PRT_CMD9:
658
+ qemu_log_mask(LOG_UNIMP, "%s: PRT is not implemented\n", __func__);
659
+ break;
660
+
661
+ case NPCM7XX_FIU_UMA_CMD:
662
+ case NPCM7XX_FIU_UMA_ADDR:
663
+ case NPCM7XX_FIU_UMA_DW0 ... NPCM7XX_FIU_UMA_DW3:
664
+ case NPCM7XX_FIU_CFG:
665
+ s->regs[reg] = value;
666
+ break;
667
+
668
+ default:
669
+ qemu_log_mask(LOG_GUEST_ERROR,
670
+ "%s: write to invalid offset 0x%" PRIx64 "\n",
671
+ DEVICE(s)->canonical_path, addr);
672
+ return;
673
+ }
674
+}
675
+
676
+static const MemoryRegionOps npcm7xx_fiu_ctrl_ops = {
677
+ .read = npcm7xx_fiu_ctrl_read,
678
+ .write = npcm7xx_fiu_ctrl_write,
679
+ .endianness = DEVICE_LITTLE_ENDIAN,
680
+ .valid = {
681
+ .min_access_size = 4,
682
+ .max_access_size = 4,
683
+ .unaligned = false,
684
+ },
685
+};
686
+
687
+static void npcm7xx_fiu_enter_reset(Object *obj, ResetType type)
688
+{
689
+ NPCM7xxFIUState *s = NPCM7XX_FIU(obj);
690
+
691
+ trace_npcm7xx_fiu_enter_reset(DEVICE(obj)->canonical_path, type);
692
+
693
+ memset(s->regs, 0, sizeof(s->regs));
694
+
695
+ s->regs[NPCM7XX_FIU_DRD_CFG] = 0x0300100b;
696
+ s->regs[NPCM7XX_FIU_DWR_CFG] = 0x03000002;
697
+ s->regs[NPCM7XX_FIU_UMA_CFG] = 0x00000400;
698
+ s->regs[NPCM7XX_FIU_UMA_CTS] = 0x00010000;
699
+ s->regs[NPCM7XX_FIU_UMA_CMD] = 0x0000000b;
700
+ s->regs[NPCM7XX_FIU_PRT_CFG] = 0x00000400;
701
+ s->regs[NPCM7XX_FIU_CFG] = 0x0000000b;
702
+}
703
+
704
+static void npcm7xx_fiu_hold_reset(Object *obj)
705
+{
706
+ NPCM7xxFIUState *s = NPCM7XX_FIU(obj);
707
+ int i;
708
+
709
+ trace_npcm7xx_fiu_hold_reset(DEVICE(obj)->canonical_path);
710
+
711
+ for (i = 0; i < s->cs_count; i++) {
712
+ qemu_irq_raise(s->cs_lines[i]);
713
+ }
714
+}
715
+
716
+static void npcm7xx_fiu_realize(DeviceState *dev, Error **errp)
717
+{
718
+ NPCM7xxFIUState *s = NPCM7XX_FIU(dev);
719
+ SysBusDevice *sbd = &s->parent;
720
+ int i;
721
+
722
+ if (s->cs_count <= 0) {
723
+ error_setg(errp, "%s: %d chip selects specified, need at least one",
724
+ dev->canonical_path, s->cs_count);
725
+ return;
726
+ }
727
+
728
+ s->spi = ssi_create_bus(dev, "spi");
729
+ s->cs_lines = g_new0(qemu_irq, s->cs_count);
730
+ qdev_init_gpio_out_named(DEVICE(s), s->cs_lines, "cs", s->cs_count);
731
+ s->flash = g_new0(NPCM7xxFIUFlash, s->cs_count);
732
+
733
+ /*
734
+ * Register the control registers region first. It may be followed by one
735
+ * or more direct flash access regions.
736
+ */
737
+ memory_region_init_io(&s->mmio, OBJECT(s), &npcm7xx_fiu_ctrl_ops, s, "ctrl",
738
+ NPCM7XX_FIU_CTRL_REGS_SIZE);
739
+ sysbus_init_mmio(sbd, &s->mmio);
740
+
741
+ for (i = 0; i < s->cs_count; i++) {
742
+ NPCM7xxFIUFlash *flash = &s->flash[i];
743
+ flash->fiu = s;
744
+ memory_region_init_io(&flash->direct_access, OBJECT(s),
745
+ &npcm7xx_fiu_flash_ops, &s->flash[i], "flash",
746
+ NPCM7XX_FIU_FLASH_WINDOW_SIZE);
747
+ sysbus_init_mmio(sbd, &flash->direct_access);
748
+ }
749
+}
750
+
751
+static const VMStateDescription vmstate_npcm7xx_fiu = {
752
+ .name = "npcm7xx-fiu",
753
+ .version_id = 0,
754
+ .minimum_version_id = 0,
755
+ .fields = (VMStateField[]) {
756
+ VMSTATE_INT32(active_cs, NPCM7xxFIUState),
757
+ VMSTATE_UINT32_ARRAY(regs, NPCM7xxFIUState, NPCM7XX_FIU_NR_REGS),
758
+ VMSTATE_END_OF_LIST(),
759
+ },
760
+};
761
+
762
+static Property npcm7xx_fiu_properties[] = {
763
+ DEFINE_PROP_INT32("cs-count", NPCM7xxFIUState, cs_count, 0),
764
+ DEFINE_PROP_END_OF_LIST(),
765
+};
766
+
767
+static void npcm7xx_fiu_class_init(ObjectClass *klass, void *data)
768
+{
769
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
770
+ DeviceClass *dc = DEVICE_CLASS(klass);
771
+
772
+ QEMU_BUILD_BUG_ON(NPCM7XX_FIU_REGS_END > NPCM7XX_FIU_NR_REGS);
773
+
774
+ dc->desc = "NPCM7xx Flash Interface Unit";
775
+ dc->realize = npcm7xx_fiu_realize;
776
+ dc->vmsd = &vmstate_npcm7xx_fiu;
777
+ rc->phases.enter = npcm7xx_fiu_enter_reset;
778
+ rc->phases.hold = npcm7xx_fiu_hold_reset;
779
+ device_class_set_props(dc, npcm7xx_fiu_properties);
780
+}
781
+
782
+static const TypeInfo npcm7xx_fiu_types[] = {
783
+ {
784
+ .name = TYPE_NPCM7XX_FIU,
785
+ .parent = TYPE_SYS_BUS_DEVICE,
786
+ .instance_size = sizeof(NPCM7xxFIUState),
787
+ .class_init = npcm7xx_fiu_class_init,
788
+ },
789
+};
790
+DEFINE_TYPES(npcm7xx_fiu_types);
791
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
792
index XXXXXXX..XXXXXXX 100644
793
--- a/hw/arm/Kconfig
794
+++ b/hw/arm/Kconfig
795
@@ -XXX,XX +XXX,XX @@ config NPCM7XX
796
select ARM_GIC
797
select PL310 # cache controller
798
select SERIAL
799
+ select SSI
800
select UNIMP
801
802
config FSL_IMX25
803
diff --git a/hw/ssi/meson.build b/hw/ssi/meson.build
804
index XXXXXXX..XXXXXXX 100644
805
--- a/hw/ssi/meson.build
806
+++ b/hw/ssi/meson.build
807
@@ -XXX,XX +XXX,XX @@
808
softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_smc.c'))
809
softmmu_ss.add(when: 'CONFIG_MSF2', if_true: files('mss-spi.c'))
810
+softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_fiu.c'))
811
softmmu_ss.add(when: 'CONFIG_PL022', if_true: files('pl022.c'))
812
softmmu_ss.add(when: 'CONFIG_SSI', if_true: files('ssi.c'))
813
softmmu_ss.add(when: 'CONFIG_STM32F2XX_SPI', if_true: files('stm32f2xx_spi.c'))
814
diff --git a/hw/ssi/trace-events b/hw/ssi/trace-events
815
index XXXXXXX..XXXXXXX 100644
816
--- a/hw/ssi/trace-events
817
+++ b/hw/ssi/trace-events
818
@@ -XXX,XX +XXX,XX @@ aspeed_smc_dma_checksum(uint32_t addr, uint32_t data) "0x%08x: 0x%08x"
819
aspeed_smc_dma_rw(const char *dir, uint32_t flash_addr, uint32_t dram_addr, uint32_t size) "%s flash:@0x%08x dram:@0x%08x size:0x%08x"
820
aspeed_smc_write(uint64_t addr, uint32_t size, uint64_t data) "@0x%" PRIx64 " size %u: 0x%" PRIx64
821
aspeed_smc_flash_select(int cs, const char *prefix) "CS%d %sselect"
822
+
823
+# npcm7xx_fiu.c
824
+
825
+npcm7xx_fiu_enter_reset(const char *id, int reset_type) "%s reset type: %d"
826
+npcm7xx_fiu_hold_reset(const char *id) "%s"
827
+npcm7xx_fiu_select(const char *id, int cs) "%s select CS%d"
828
+npcm7xx_fiu_deselect(const char *id, int cs) "%s deselect CS%d"
829
+npcm7xx_fiu_ctrl_read(const char *id, uint64_t addr, uint32_t data) "%s offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
830
+npcm7xx_fiu_ctrl_write(const char *id, uint64_t addr, uint32_t data) "%s offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
831
+npcm7xx_fiu_flash_read(const char *id, int cs, uint64_t addr, unsigned int size, uint64_t value) "%s[%d] offset: 0x%08" PRIx64 " size: %u value: 0x%" PRIx64
832
+npcm7xx_fiu_flash_write(const char *id, int cs, uint64_t addr, unsigned int size, uint64_t value) "%s[%d] offset: 0x%08" PRIx64 " size: %u value: 0x%" PRIx64
833
--
69
--
834
2.20.1
70
2.20.1
835
71
836
72
diff view generated by jsdifflib
1
It is the responsibility of board code for an armv7m system to set
1
v8.1M introduces a new TRD flag in the CCR register, which enables
2
system_clock_scale appropriately for the CPU speed of the core.
2
checking for stack frame integrity signatures on SG instructions.
3
If it forgets to do this, then QEMU will hang if the guest tries
3
This bit is not banked, and is always RAZ/WI to Non-secure code.
4
to use the systick timer in the "tick at the CPU clock frequency" mode.
4
Adjust the code for handling CCR reads and writes to handle this.
5
6
We forgot that in a couple of our boards (see commits ce4f70e81ed23c93f,
7
e7e5a9595ab1136). Add an assertion in the systick reset method so
8
we don't let any new boards in with the same bug.
9
5
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Message-id: 20200825160847.18091-1-peter.maydell@linaro.org
8
Message-id: 20201119215617.29887-23-peter.maydell@linaro.org
13
---
9
---
14
hw/timer/armv7m_systick.c | 8 ++++++++
10
target/arm/cpu.h | 2 ++
15
1 file changed, 8 insertions(+)
11
hw/intc/armv7m_nvic.c | 26 ++++++++++++++++++--------
12
2 files changed, 20 insertions(+), 8 deletions(-)
16
13
17
diff --git a/hw/timer/armv7m_systick.c b/hw/timer/armv7m_systick.c
14
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
18
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
19
--- a/hw/timer/armv7m_systick.c
16
--- a/target/arm/cpu.h
20
+++ b/hw/timer/armv7m_systick.c
17
+++ b/target/arm/cpu.h
21
@@ -XXX,XX +XXX,XX @@ static void systick_reset(DeviceState *dev)
18
@@ -XXX,XX +XXX,XX @@ FIELD(V7M_CCR, STKOFHFNMIGN, 10, 1)
22
{
19
FIELD(V7M_CCR, DC, 16, 1)
23
SysTickState *s = SYSTICK(dev);
20
FIELD(V7M_CCR, IC, 17, 1)
24
21
FIELD(V7M_CCR, BP, 18, 1)
25
+ /*
22
+FIELD(V7M_CCR, LOB, 19, 1)
26
+ * Forgetting to set system_clock_scale is always a board code
23
+FIELD(V7M_CCR, TRD, 20, 1)
27
+ * bug. We can't check this earlier because for some boards
24
28
+ * (like stellaris) it is not yet configured at the point where
25
/* V7M SCR bits */
29
+ * the systick device is realized.
26
FIELD(V7M_SCR, SLEEPONEXIT, 1, 1)
30
+ */
27
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
31
+ assert(system_clock_scale != 0);
28
index XXXXXXX..XXXXXXX 100644
29
--- a/hw/intc/armv7m_nvic.c
30
+++ b/hw/intc/armv7m_nvic.c
31
@@ -XXX,XX +XXX,XX @@ static uint32_t nvic_readl(NVICState *s, uint32_t offset, MemTxAttrs attrs)
32
}
33
return cpu->env.v7m.scr[attrs.secure];
34
case 0xd14: /* Configuration Control. */
35
- /* The BFHFNMIGN bit is the only non-banked bit; we
36
- * keep it in the non-secure copy of the register.
37
+ /*
38
+ * Non-banked bits: BFHFNMIGN (stored in the NS copy of the register)
39
+ * and TRD (stored in the S copy of the register)
40
*/
41
val = cpu->env.v7m.ccr[attrs.secure];
42
val |= cpu->env.v7m.ccr[M_REG_NS] & R_V7M_CCR_BFHFNMIGN_MASK;
43
@@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value,
44
cpu->env.v7m.scr[attrs.secure] = value;
45
break;
46
case 0xd14: /* Configuration Control. */
47
+ {
48
+ uint32_t mask;
32
+
49
+
33
s->control = 0;
50
if (!arm_feature(&cpu->env, ARM_FEATURE_M_MAIN)) {
34
s->reload = 0;
51
goto bad_offset;
35
s->tick = 0;
52
}
53
54
/* Enforce RAZ/WI on reserved and must-RAZ/WI bits */
55
- value &= (R_V7M_CCR_STKALIGN_MASK |
56
- R_V7M_CCR_BFHFNMIGN_MASK |
57
- R_V7M_CCR_DIV_0_TRP_MASK |
58
- R_V7M_CCR_UNALIGN_TRP_MASK |
59
- R_V7M_CCR_USERSETMPEND_MASK |
60
- R_V7M_CCR_NONBASETHRDENA_MASK);
61
+ mask = R_V7M_CCR_STKALIGN_MASK |
62
+ R_V7M_CCR_BFHFNMIGN_MASK |
63
+ R_V7M_CCR_DIV_0_TRP_MASK |
64
+ R_V7M_CCR_UNALIGN_TRP_MASK |
65
+ R_V7M_CCR_USERSETMPEND_MASK |
66
+ R_V7M_CCR_NONBASETHRDENA_MASK;
67
+ if (arm_feature(&cpu->env, ARM_FEATURE_V8_1M) && attrs.secure) {
68
+ /* TRD is always RAZ/WI from NS */
69
+ mask |= R_V7M_CCR_TRD_MASK;
70
+ }
71
+ value &= mask;
72
73
if (arm_feature(&cpu->env, ARM_FEATURE_V8)) {
74
/* v8M makes NONBASETHRDENA and STKALIGN be RES1 */
75
@@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value,
76
77
cpu->env.v7m.ccr[attrs.secure] = value;
78
break;
79
+ }
80
case 0xd24: /* System Handler Control and State (SHCSR) */
81
if (!arm_feature(&cpu->env, ARM_FEATURE_V7)) {
82
goto bad_offset;
36
--
83
--
37
2.20.1
84
2.20.1
38
85
39
86
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
v8.1M introduces a new TRD flag in the CCR register, which enables
2
checking for stack frame integrity signatures on SG instructions.
3
Add the code in the SG insn implementation for the new behaviour.
2
4
3
This supports reading and writing OTP fuses and keys. Only fuse reading
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
has been tested. Protection is not implemented.
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20201119215617.29887-24-peter.maydell@linaro.org
8
---
9
target/arm/m_helper.c | 86 +++++++++++++++++++++++++++++++++++++++++++
10
1 file changed, 86 insertions(+)
5
11
6
Reviewed-by: Avi Fishman <avi.fishman@nuvoton.com>
12
diff --git a/target/arm/m_helper.c b/target/arm/m_helper.c
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Tested-by: Alexander Bulekov <alxndr@bu.edu>
10
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
11
Message-id: 20200911052101.2602693-9-hskinnemoen@google.com
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
---
14
include/hw/arm/npcm7xx.h | 3 +
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
22
23
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
24
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
25
--- a/include/hw/arm/npcm7xx.h
14
--- a/target/arm/m_helper.c
26
+++ b/include/hw/arm/npcm7xx.h
15
+++ b/target/arm/m_helper.c
27
@@ -XXX,XX +XXX,XX @@
16
@@ -XXX,XX +XXX,XX @@ static bool v7m_read_half_insn(ARMCPU *cpu, ARMMMUIdx mmu_idx,
28
#include "hw/cpu/a9mpcore.h"
17
return true;
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);
146
}
18
}
147
19
148
+static void npcm7xx_init_fuses(NPCM7xxState *s)
20
+static bool v7m_read_sg_stack_word(ARMCPU *cpu, ARMMMUIdx mmu_idx,
21
+ uint32_t addr, uint32_t *spdata)
149
+{
22
+{
150
+ NPCM7xxClass *nc = NPCM7XX_GET_CLASS(s);
23
+ /*
24
+ * Read a word of data from the stack for the SG instruction,
25
+ * writing the value into *spdata. If the load succeeds, return
26
+ * true; otherwise pend an appropriate exception and return false.
27
+ * (We can't use data load helpers here that throw an exception
28
+ * because of the context we're called in, which is halfway through
29
+ * arm_v7m_cpu_do_interrupt().)
30
+ */
31
+ CPUState *cs = CPU(cpu);
32
+ CPUARMState *env = &cpu->env;
33
+ MemTxAttrs attrs = {};
34
+ MemTxResult txres;
35
+ target_ulong page_size;
36
+ hwaddr physaddr;
37
+ int prot;
38
+ ARMMMUFaultInfo fi = {};
39
+ ARMCacheAttrs cacheattrs = {};
151
+ uint32_t value;
40
+ uint32_t value;
152
+
41
+
153
+ /*
42
+ if (get_phys_addr(env, addr, MMU_DATA_LOAD, mmu_idx, &physaddr,
154
+ * The initial mask of disabled modules indicates the chip derivative (e.g.
43
+ &attrs, &prot, &page_size, &fi, &cacheattrs)) {
155
+ * NPCM750 or NPCM730).
44
+ /* MPU/SAU lookup failed */
156
+ */
45
+ if (fi.type == ARMFault_QEMU_SFault) {
157
+ value = tswap32(nc->disabled_modules);
46
+ qemu_log_mask(CPU_LOG_INT,
158
+ npcm7xx_otp_array_write(&s->fuse_array, &value, NPCM7XX_FUSE_DERIVATIVE,
47
+ "...SecureFault during stack word read\n");
159
+ sizeof(value));
48
+ env->v7m.sfsr |= R_V7M_SFSR_AUVIOL_MASK | R_V7M_SFSR_SFARVALID_MASK;
49
+ env->v7m.sfar = addr;
50
+ armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_SECURE, false);
51
+ } else {
52
+ qemu_log_mask(CPU_LOG_INT,
53
+ "...MemManageFault during stack word read\n");
54
+ env->v7m.cfsr[M_REG_S] |= R_V7M_CFSR_DACCVIOL_MASK |
55
+ R_V7M_CFSR_MMARVALID_MASK;
56
+ env->v7m.mmfar[M_REG_S] = addr;
57
+ armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_MEM, false);
58
+ }
59
+ return false;
60
+ }
61
+ value = address_space_ldl(arm_addressspace(cs, attrs), physaddr,
62
+ attrs, &txres);
63
+ if (txres != MEMTX_OK) {
64
+ /* BusFault trying to read the data */
65
+ qemu_log_mask(CPU_LOG_INT,
66
+ "...BusFault during stack word read\n");
67
+ env->v7m.cfsr[M_REG_NS] |=
68
+ (R_V7M_CFSR_PRECISERR_MASK | R_V7M_CFSR_BFARVALID_MASK);
69
+ env->v7m.bfar = addr;
70
+ armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_BUS, false);
71
+ return false;
72
+ }
73
+
74
+ *spdata = value;
75
+ return true;
160
+}
76
+}
161
+
77
+
162
static qemu_irq npcm7xx_irq(NPCM7xxState *s, int n)
78
static bool v7m_handle_execute_nsc(ARMCPU *cpu)
163
{
79
{
164
return qdev_get_gpio_in(DEVICE(&s->a9mpcore), n);
80
/*
165
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj)
81
@@ -XXX,XX +XXX,XX @@ static bool v7m_handle_execute_nsc(ARMCPU *cpu)
166
object_property_add_alias(obj, "power-on-straps", OBJECT(&s->gcr),
82
*/
167
"power-on-straps");
83
qemu_log_mask(CPU_LOG_INT, "...really an SG instruction at 0x%08" PRIx32
168
object_initialize_child(obj, "clk", &s->clk, TYPE_NPCM7XX_CLK);
84
", executing it\n", env->regs[15]);
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
+
85
+
187
/* Timer Modules (TIM). Cannot fail. */
86
+ if (cpu_isar_feature(aa32_m_sec_state, cpu) &&
188
QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_tim_addr) != ARRAY_SIZE(s->tim));
87
+ !arm_v7m_is_handler_mode(env)) {
189
for (i = 0; i < ARRAY_SIZE(s->tim); i++) {
88
+ /*
190
diff --git a/hw/nvram/npcm7xx_otp.c b/hw/nvram/npcm7xx_otp.c
89
+ * v8.1M exception stack frame integrity check. Note that we
191
new file mode 100644
90
+ * must perform the memory access even if CCR_S.TRD is zero
192
index XXXXXXX..XXXXXXX
91
+ * and we aren't going to check what the data loaded is.
193
--- /dev/null
92
+ */
194
+++ b/hw/nvram/npcm7xx_otp.c
93
+ uint32_t spdata, sp;
195
@@ -XXX,XX +XXX,XX @@
196
+/*
197
+ * Nuvoton NPCM7xx OTP (Fuse Array) Interface
198
+ *
199
+ * Copyright 2020 Google LLC
200
+ *
201
+ * This program is free software; you can redistribute it and/or modify it
202
+ * under the terms of the GNU General Public License as published by the
203
+ * Free Software Foundation; either version 2 of the License, or
204
+ * (at your option) any later version.
205
+ *
206
+ * This program is distributed in the hope that it will be useful, but WITHOUT
207
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
208
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
209
+ * for more details.
210
+ */
211
+
94
+
212
+#include "qemu/osdep.h"
95
+ /*
96
+ * We know we are currently NS, so the S stack pointers must be
97
+ * in other_ss_{psp,msp}, not in regs[13]/other_sp.
98
+ */
99
+ sp = v7m_using_psp(env) ? env->v7m.other_ss_psp : env->v7m.other_ss_msp;
100
+ if (!v7m_read_sg_stack_word(cpu, mmu_idx, sp, &spdata)) {
101
+ /* Stack access failed and an exception has been pended */
102
+ return false;
103
+ }
213
+
104
+
214
+#include "hw/nvram/npcm7xx_otp.h"
105
+ if (env->v7m.ccr[M_REG_S] & R_V7M_CCR_TRD_MASK) {
215
+#include "migration/vmstate.h"
106
+ if (((spdata & ~1) == 0xfefa125a) ||
216
+#include "qapi/error.h"
107
+ !(env->v7m.control[M_REG_S] & 1)) {
217
+#include "qemu/bitops.h"
108
+ goto gen_invep;
218
+#include "qemu/log.h"
109
+ }
219
+#include "qemu/module.h"
110
+ }
220
+#include "qemu/units.h"
221
+
222
+/* Each module has 4 KiB of register space. Only a fraction of it is used. */
223
+#define NPCM7XX_OTP_REGS_SIZE (4 * KiB)
224
+
225
+/* 32-bit register indices. */
226
+typedef enum NPCM7xxOTPRegister {
227
+ NPCM7XX_OTP_FST,
228
+ NPCM7XX_OTP_FADDR,
229
+ NPCM7XX_OTP_FDATA,
230
+ NPCM7XX_OTP_FCFG,
231
+ /* Offset 0x10 is FKEYIND in OTP1, FUSTRAP in OTP2 */
232
+ NPCM7XX_OTP_FKEYIND = 0x0010 / sizeof(uint32_t),
233
+ NPCM7XX_OTP_FUSTRAP = 0x0010 / sizeof(uint32_t),
234
+ NPCM7XX_OTP_FCTL,
235
+ NPCM7XX_OTP_REGS_END,
236
+} NPCM7xxOTPRegister;
237
+
238
+/* Register field definitions. */
239
+#define FST_RIEN BIT(2)
240
+#define FST_RDST BIT(1)
241
+#define FST_RDY BIT(0)
242
+#define FST_RO_MASK (FST_RDST | FST_RDY)
243
+
244
+#define FADDR_BYTEADDR(rv) extract32((rv), 0, 10)
245
+#define FADDR_BITPOS(rv) extract32((rv), 10, 3)
246
+
247
+#define FDATA_CLEAR 0x00000001
248
+
249
+#define FCFG_FDIS BIT(31)
250
+#define FCFG_FCFGLK_MASK 0x00ff0000
251
+
252
+#define FCTL_PROG_CMD1 0x00000001
253
+#define FCTL_PROG_CMD2 0xbf79e5d0
254
+#define FCTL_READ_CMD 0x00000002
255
+
256
+/**
257
+ * struct NPCM7xxOTPClass - OTP module class.
258
+ * @parent: System bus device class.
259
+ * @mmio_ops: MMIO register operations for this type of module.
260
+ *
261
+ * The two OTP modules (key-storage and fuse-array) have slightly different
262
+ * behavior, so we give them different MMIO register operations.
263
+ */
264
+struct NPCM7xxOTPClass {
265
+ SysBusDeviceClass parent;
266
+
267
+ const MemoryRegionOps *mmio_ops;
268
+};
269
+
270
+#define NPCM7XX_OTP_CLASS(klass) \
271
+ OBJECT_CLASS_CHECK(NPCM7xxOTPClass, (klass), TYPE_NPCM7XX_OTP)
272
+#define NPCM7XX_OTP_GET_CLASS(obj) \
273
+ OBJECT_GET_CLASS(NPCM7xxOTPClass, (obj), TYPE_NPCM7XX_OTP)
274
+
275
+static uint8_t ecc_encode_nibble(uint8_t n)
276
+{
277
+ uint8_t result = n;
278
+
279
+ result |= (((n >> 0) & 1) ^ ((n >> 1) & 1)) << 4;
280
+ result |= (((n >> 2) & 1) ^ ((n >> 3) & 1)) << 5;
281
+ result |= (((n >> 0) & 1) ^ ((n >> 2) & 1)) << 6;
282
+ result |= (((n >> 1) & 1) ^ ((n >> 3) & 1)) << 7;
283
+
284
+ return result;
285
+}
286
+
287
+void npcm7xx_otp_array_write(NPCM7xxOTPState *s, const void *data,
288
+ unsigned int offset, unsigned int len)
289
+{
290
+ const uint8_t *src = data;
291
+ uint8_t *dst = &s->array[offset];
292
+
293
+ while (len-- > 0) {
294
+ uint8_t c = *src++;
295
+
296
+ *dst++ = ecc_encode_nibble(extract8(c, 0, 4));
297
+ *dst++ = ecc_encode_nibble(extract8(c, 4, 4));
298
+ }
299
+}
300
+
301
+/* Common register read handler for both OTP classes. */
302
+static uint64_t npcm7xx_otp_read(NPCM7xxOTPState *s, NPCM7xxOTPRegister reg)
303
+{
304
+ uint32_t value = 0;
305
+
306
+ switch (reg) {
307
+ case NPCM7XX_OTP_FST:
308
+ case NPCM7XX_OTP_FADDR:
309
+ case NPCM7XX_OTP_FDATA:
310
+ case NPCM7XX_OTP_FCFG:
311
+ value = s->regs[reg];
312
+ break;
313
+
314
+ case NPCM7XX_OTP_FCTL:
315
+ qemu_log_mask(LOG_GUEST_ERROR,
316
+ "%s: read from write-only FCTL register\n",
317
+ DEVICE(s)->canonical_path);
318
+ break;
319
+
320
+ default:
321
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: read from invalid offset 0x%zx\n",
322
+ DEVICE(s)->canonical_path, reg * sizeof(uint32_t));
323
+ break;
324
+ }
111
+ }
325
+
112
+
326
+ return value;
113
env->regs[14] &= ~1;
327
+}
114
env->v7m.control[M_REG_S] &= ~R_V7M_CONTROL_SFPA_MASK;
328
+
115
switch_v7m_security_state(env, true);
329
+/* Read a byte from the OTP array into the data register. */
330
+static void npcm7xx_otp_read_array(NPCM7xxOTPState *s)
331
+{
332
+ uint32_t faddr = s->regs[NPCM7XX_OTP_FADDR];
333
+
334
+ s->regs[NPCM7XX_OTP_FDATA] = s->array[FADDR_BYTEADDR(faddr)];
335
+ s->regs[NPCM7XX_OTP_FST] |= FST_RDST | FST_RDY;
336
+}
337
+
338
+/* Program a byte from the data register into the OTP array. */
339
+static void npcm7xx_otp_program_array(NPCM7xxOTPState *s)
340
+{
341
+ uint32_t faddr = s->regs[NPCM7XX_OTP_FADDR];
342
+
343
+ /* Bits can only go 0->1, never 1->0. */
344
+ s->array[FADDR_BYTEADDR(faddr)] |= (1U << FADDR_BITPOS(faddr));
345
+ s->regs[NPCM7XX_OTP_FST] |= FST_RDST | FST_RDY;
346
+}
347
+
348
+/* Compute the next value of the FCFG register. */
349
+static uint32_t npcm7xx_otp_compute_fcfg(uint32_t cur_value, uint32_t new_value)
350
+{
351
+ uint32_t lock_mask;
352
+ uint32_t value;
353
+
354
+ /*
355
+ * FCFGLK holds sticky bits 16..23, indicating which bits in FPRGLK (8..15)
356
+ * and FRDLK (0..7) that are read-only.
357
+ */
358
+ lock_mask = (cur_value & FCFG_FCFGLK_MASK) >> 8;
359
+ lock_mask |= lock_mask >> 8;
360
+ /* FDIS and FCFGLK bits are sticky (write 1 to set; can't clear). */
361
+ value = cur_value & (FCFG_FDIS | FCFG_FCFGLK_MASK);
362
+ /* Preserve read-only bits in FPRGLK and FRDLK */
363
+ value |= cur_value & lock_mask;
364
+ /* Set all bits that aren't read-only. */
365
+ value |= new_value & ~lock_mask;
366
+
367
+ return value;
368
+}
369
+
370
+/* Common register write handler for both OTP classes. */
371
+static void npcm7xx_otp_write(NPCM7xxOTPState *s, NPCM7xxOTPRegister reg,
372
+ uint32_t value)
373
+{
374
+ switch (reg) {
375
+ case NPCM7XX_OTP_FST:
376
+ /* RDST is cleared by writing 1 to it. */
377
+ if (value & FST_RDST) {
378
+ s->regs[NPCM7XX_OTP_FST] &= ~FST_RDST;
379
+ }
380
+ /* Preserve read-only and write-one-to-clear bits */
381
+ value &= ~FST_RO_MASK;
382
+ value |= s->regs[NPCM7XX_OTP_FST] & FST_RO_MASK;
383
+ break;
384
+
385
+ case NPCM7XX_OTP_FADDR:
386
+ break;
387
+
388
+ case NPCM7XX_OTP_FDATA:
389
+ /*
390
+ * This register is cleared by writing a magic value to it; no other
391
+ * values can be written.
392
+ */
393
+ if (value == FDATA_CLEAR) {
394
+ value = 0;
395
+ } else {
396
+ value = s->regs[NPCM7XX_OTP_FDATA];
397
+ }
398
+ break;
399
+
400
+ case NPCM7XX_OTP_FCFG:
401
+ value = npcm7xx_otp_compute_fcfg(s->regs[NPCM7XX_OTP_FCFG], value);
402
+ break;
403
+
404
+ case NPCM7XX_OTP_FCTL:
405
+ switch (value) {
406
+ case FCTL_READ_CMD:
407
+ npcm7xx_otp_read_array(s);
408
+ break;
409
+
410
+ case FCTL_PROG_CMD1:
411
+ /*
412
+ * Programming requires writing two separate magic values to this
413
+ * register; this is the first one. Just store it so it can be
414
+ * verified later when the second magic value is received.
415
+ */
416
+ break;
417
+
418
+ case FCTL_PROG_CMD2:
419
+ /*
420
+ * Only initiate programming if we received the first half of the
421
+ * command immediately before this one.
422
+ */
423
+ if (s->regs[NPCM7XX_OTP_FCTL] == FCTL_PROG_CMD1) {
424
+ npcm7xx_otp_program_array(s);
425
+ }
426
+ break;
427
+
428
+ default:
429
+ qemu_log_mask(LOG_GUEST_ERROR,
430
+ "%s: unrecognized FCNTL value 0x%" PRIx32 "\n",
431
+ DEVICE(s)->canonical_path, value);
432
+ break;
433
+ }
434
+ if (value != FCTL_PROG_CMD1) {
435
+ value = 0;
436
+ }
437
+ break;
438
+
439
+ default:
440
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: write to invalid offset 0x%zx\n",
441
+ DEVICE(s)->canonical_path, reg * sizeof(uint32_t));
442
+ return;
443
+ }
444
+
445
+ s->regs[reg] = value;
446
+}
447
+
448
+/* Register read handler specific to the fuse array OTP module. */
449
+static uint64_t npcm7xx_fuse_array_read(void *opaque, hwaddr addr,
450
+ unsigned int size)
451
+{
452
+ NPCM7xxOTPRegister reg = addr / sizeof(uint32_t);
453
+ NPCM7xxOTPState *s = opaque;
454
+ uint32_t value;
455
+
456
+ /*
457
+ * Only the Fuse Strap register needs special handling; all other registers
458
+ * work the same way for both kinds of OTP modules.
459
+ */
460
+ if (reg != NPCM7XX_OTP_FUSTRAP) {
461
+ value = npcm7xx_otp_read(s, reg);
462
+ } else {
463
+ /* FUSTRAP is stored as three copies in the OTP array. */
464
+ uint32_t fustrap[3];
465
+
466
+ memcpy(fustrap, &s->array[0], sizeof(fustrap));
467
+
468
+ /* Determine value by a majority vote on each bit. */
469
+ value = (fustrap[0] & fustrap[1]) | (fustrap[0] & fustrap[2]) |
470
+ (fustrap[1] & fustrap[2]);
471
+ }
472
+
473
+ return value;
474
+}
475
+
476
+/* Register write handler specific to the fuse array OTP module. */
477
+static void npcm7xx_fuse_array_write(void *opaque, hwaddr addr, uint64_t v,
478
+ unsigned int size)
479
+{
480
+ NPCM7xxOTPRegister reg = addr / sizeof(uint32_t);
481
+ NPCM7xxOTPState *s = opaque;
482
+
483
+ /*
484
+ * The Fuse Strap register is read-only. Other registers are handled by
485
+ * common code.
486
+ */
487
+ if (reg != NPCM7XX_OTP_FUSTRAP) {
488
+ npcm7xx_otp_write(s, reg, v);
489
+ }
490
+}
491
+
492
+static const MemoryRegionOps npcm7xx_fuse_array_ops = {
493
+ .read = npcm7xx_fuse_array_read,
494
+ .write = npcm7xx_fuse_array_write,
495
+ .endianness = DEVICE_LITTLE_ENDIAN,
496
+ .valid = {
497
+ .min_access_size = 4,
498
+ .max_access_size = 4,
499
+ .unaligned = false,
500
+ },
501
+};
502
+
503
+/* Register read handler specific to the key storage OTP module. */
504
+static uint64_t npcm7xx_key_storage_read(void *opaque, hwaddr addr,
505
+ unsigned int size)
506
+{
507
+ NPCM7xxOTPRegister reg = addr / sizeof(uint32_t);
508
+ NPCM7xxOTPState *s = opaque;
509
+
510
+ /*
511
+ * Only the Fuse Key Index register needs special handling; all other
512
+ * registers work the same way for both kinds of OTP modules.
513
+ */
514
+ if (reg != NPCM7XX_OTP_FKEYIND) {
515
+ return npcm7xx_otp_read(s, reg);
516
+ }
517
+
518
+ qemu_log_mask(LOG_UNIMP, "%s: FKEYIND is not implemented\n", __func__);
519
+
520
+ return s->regs[NPCM7XX_OTP_FKEYIND];
521
+}
522
+
523
+/* Register write handler specific to the key storage OTP module. */
524
+static void npcm7xx_key_storage_write(void *opaque, hwaddr addr, uint64_t v,
525
+ unsigned int size)
526
+{
527
+ NPCM7xxOTPRegister reg = addr / sizeof(uint32_t);
528
+ NPCM7xxOTPState *s = opaque;
529
+
530
+ /*
531
+ * Only the Fuse Key Index register needs special handling; all other
532
+ * registers work the same way for both kinds of OTP modules.
533
+ */
534
+ if (reg != NPCM7XX_OTP_FKEYIND) {
535
+ npcm7xx_otp_write(s, reg, v);
536
+ return;
537
+ }
538
+
539
+ qemu_log_mask(LOG_UNIMP, "%s: FKEYIND is not implemented\n", __func__);
540
+
541
+ s->regs[NPCM7XX_OTP_FKEYIND] = v;
542
+}
543
+
544
+static const MemoryRegionOps npcm7xx_key_storage_ops = {
545
+ .read = npcm7xx_key_storage_read,
546
+ .write = npcm7xx_key_storage_write,
547
+ .endianness = DEVICE_LITTLE_ENDIAN,
548
+ .valid = {
549
+ .min_access_size = 4,
550
+ .max_access_size = 4,
551
+ .unaligned = false,
552
+ },
553
+};
554
+
555
+static void npcm7xx_otp_enter_reset(Object *obj, ResetType type)
556
+{
557
+ NPCM7xxOTPState *s = NPCM7XX_OTP(obj);
558
+
559
+ memset(s->regs, 0, sizeof(s->regs));
560
+
561
+ s->regs[NPCM7XX_OTP_FST] = 0x00000001;
562
+ s->regs[NPCM7XX_OTP_FCFG] = 0x20000000;
563
+}
564
+
565
+static void npcm7xx_otp_realize(DeviceState *dev, Error **errp)
566
+{
567
+ NPCM7xxOTPClass *oc = NPCM7XX_OTP_GET_CLASS(dev);
568
+ NPCM7xxOTPState *s = NPCM7XX_OTP(dev);
569
+ SysBusDevice *sbd = &s->parent;
570
+
571
+ memset(s->array, 0, sizeof(s->array));
572
+
573
+ memory_region_init_io(&s->mmio, OBJECT(s), oc->mmio_ops, s, "regs",
574
+ NPCM7XX_OTP_REGS_SIZE);
575
+ sysbus_init_mmio(sbd, &s->mmio);
576
+}
577
+
578
+static const VMStateDescription vmstate_npcm7xx_otp = {
579
+ .name = "npcm7xx-otp",
580
+ .version_id = 0,
581
+ .minimum_version_id = 0,
582
+ .fields = (VMStateField[]) {
583
+ VMSTATE_UINT32_ARRAY(regs, NPCM7xxOTPState, NPCM7XX_OTP_NR_REGS),
584
+ VMSTATE_UINT8_ARRAY(array, NPCM7xxOTPState, NPCM7XX_OTP_ARRAY_BYTES),
585
+ VMSTATE_END_OF_LIST(),
586
+ },
587
+};
588
+
589
+static void npcm7xx_otp_class_init(ObjectClass *klass, void *data)
590
+{
591
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
592
+ DeviceClass *dc = DEVICE_CLASS(klass);
593
+
594
+ QEMU_BUILD_BUG_ON(NPCM7XX_OTP_REGS_END > NPCM7XX_OTP_NR_REGS);
595
+
596
+ dc->realize = npcm7xx_otp_realize;
597
+ dc->vmsd = &vmstate_npcm7xx_otp;
598
+ rc->phases.enter = npcm7xx_otp_enter_reset;
599
+}
600
+
601
+static void npcm7xx_key_storage_class_init(ObjectClass *klass, void *data)
602
+{
603
+ NPCM7xxOTPClass *oc = NPCM7XX_OTP_CLASS(klass);
604
+
605
+ oc->mmio_ops = &npcm7xx_key_storage_ops;
606
+}
607
+
608
+static void npcm7xx_fuse_array_class_init(ObjectClass *klass, void *data)
609
+{
610
+ NPCM7xxOTPClass *oc = NPCM7XX_OTP_CLASS(klass);
611
+
612
+ oc->mmio_ops = &npcm7xx_fuse_array_ops;
613
+}
614
+
615
+static const TypeInfo npcm7xx_otp_types[] = {
616
+ {
617
+ .name = TYPE_NPCM7XX_OTP,
618
+ .parent = TYPE_SYS_BUS_DEVICE,
619
+ .instance_size = sizeof(NPCM7xxOTPState),
620
+ .class_size = sizeof(NPCM7xxOTPClass),
621
+ .class_init = npcm7xx_otp_class_init,
622
+ .abstract = true,
623
+ },
624
+ {
625
+ .name = TYPE_NPCM7XX_KEY_STORAGE,
626
+ .parent = TYPE_NPCM7XX_OTP,
627
+ .class_init = npcm7xx_key_storage_class_init,
628
+ },
629
+ {
630
+ .name = TYPE_NPCM7XX_FUSE_ARRAY,
631
+ .parent = TYPE_NPCM7XX_OTP,
632
+ .class_init = npcm7xx_fuse_array_class_init,
633
+ },
634
+};
635
+DEFINE_TYPES(npcm7xx_otp_types);
636
diff --git a/hw/nvram/meson.build b/hw/nvram/meson.build
637
index XXXXXXX..XXXXXXX 100644
638
--- a/hw/nvram/meson.build
639
+++ b/hw/nvram/meson.build
640
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_DS1225Y', if_true: files('ds1225y.c'))
641
softmmu_ss.add(when: 'CONFIG_NMC93XX_EEPROM', if_true: files('eeprom93xx.c'))
642
softmmu_ss.add(when: 'CONFIG_AT24C', if_true: files('eeprom_at24c.c'))
643
softmmu_ss.add(when: 'CONFIG_MAC_NVRAM', if_true: files('mac_nvram.c'))
644
+softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_otp.c'))
645
softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_nvm.c'))
646
647
specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_nvram.c'))
648
--
116
--
649
2.20.1
117
2.20.1
650
118
651
119
diff view generated by jsdifflib
1
We deprecated the support for KVM on 32-bit Arm hosts in time
1
In commit 077d7449100d824a4 we added code to handle the v8M
2
for release 5.0, which means that our deprecation policy allows
2
requirement that returns from NMI or HardFault forcibly deactivate
3
us to drop it in release 5.2. Remove the code.
3
those exceptions regardless of what interrupt the guest is trying to
4
deactivate. Unfortunately this broke the handling of the "illegal
5
exception return because the returning exception number is not
6
active" check for those cases. In the pseudocode this test is done
7
on the exception the guest asks to return from, but because our
8
implementation was doing this in armv7m_nvic_complete_irq() after the
9
new "deactivate NMI/HardFault regardless" code we ended up doing the
10
test on the VecInfo for that exception instead, which usually meant
11
failing to raise the illegal exception return fault.
4
12
5
To repeat the rationale from the deprecation note: the Linux
13
In the case for "configurable exception targeting the opposite
6
kernel dropped support for 32-bit Arm KVM hosts in 5.7.
14
security state" we detected the illegal-return case but went ahead
15
and deactivated the VecInfo anyway, which is wrong because that is
16
the VecInfo for the other security state.
7
17
8
Running 32-bit guests on a 64-bit Arm host remains supported.
18
Rearrange the code so that we first identify the illegal return
19
cases, then see if we really need to deactivate NMI or HardFault
20
instead, and finally do the deactivation.
9
21
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
22
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
23
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
24
Message-id: 20201119215617.29887-25-peter.maydell@linaro.org
13
Message-id: 20200904154156.31943-2-peter.maydell@linaro.org
14
---
25
---
15
docs/system/deprecated.rst | 16 +-
26
hw/intc/armv7m_nvic.c | 59 +++++++++++++++++++++++--------------------
16
configure | 2 +-
27
1 file changed, 32 insertions(+), 27 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
21
28
22
diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
29
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
23
index XXXXXXX..XXXXXXX 100644
30
index XXXXXXX..XXXXXXX 100644
24
--- a/docs/system/deprecated.rst
31
--- a/hw/intc/armv7m_nvic.c
25
+++ b/docs/system/deprecated.rst
32
+++ b/hw/intc/armv7m_nvic.c
26
@@ -XXX,XX +XXX,XX @@ The ``compat`` property used to set backwards compatibility modes for
33
@@ -XXX,XX +XXX,XX @@ int armv7m_nvic_complete_irq(void *opaque, int irq, bool secure)
27
the processor has been deprecated. The ``max-cpu-compat`` property of
34
{
28
the ``pseries`` machine type should be used instead.
35
NVICState *s = (NVICState *)opaque;
29
36
VecInfo *vec = NULL;
30
-KVM guest support on 32-bit Arm hosts (since 5.0)
37
- int ret;
31
-'''''''''''''''''''''''''''''''''''''''''''''''''
38
+ int ret = 0;
32
-
39
33
-The Linux kernel has dropped support for allowing 32-bit Arm systems
40
assert(irq > ARMV7M_EXCP_RESET && irq < s->num_irq);
34
-to host KVM guests as of the 5.7 kernel. Accordingly, QEMU is deprecating
41
35
-its support for this configuration and will remove it in a future version.
42
+ trace_nvic_complete_irq(irq, secure);
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
+
43
+
48
+The Linux kernel has dropped support for allowing 32-bit Arm systems
44
+ if (secure && exc_is_banked(irq)) {
49
+to host KVM guests as of the 5.7 kernel. Accordingly, QEMU is deprecating
45
+ vec = &s->sec_vectors[irq];
50
+its support for this configuration and will remove it in a future version.
46
+ } else {
51
+Running 32-bit guests on a 64-bit Arm host remains supported.
47
+ vec = &s->vectors[irq];
48
+ }
52
+
49
+
53
RISC-V ISA Specific CPUs (removed in 5.1)
50
+ /*
54
'''''''''''''''''''''''''''''''''''''''''
51
+ * Identify illegal exception return cases. We can't immediately
55
52
+ * return at this point because we still need to deactivate
56
diff --git a/configure b/configure
53
+ * (either this exception or NMI/HardFault) first.
57
index XXXXXXX..XXXXXXX 100755
54
+ */
58
--- a/configure
55
+ if (!exc_is_banked(irq) && exc_targets_secure(s, irq) != secure) {
59
+++ b/configure
56
+ /*
60
@@ -XXX,XX +XXX,XX @@ supported_kvm_target() {
57
+ * Return from a configurable exception targeting the opposite
61
test "$kvm" = "yes" || return 1
58
+ * security state from the one we're trying to complete it for.
62
glob "$1" "*-softmmu" || return 1
59
+ * Clear vec because it's not really the VecInfo for this
63
case "${1%-softmmu}:$cpu" in
60
+ * (irq, secstate) so we mustn't deactivate it.
64
- arm:arm | aarch64:aarch64 | \
61
+ */
65
+ aarch64:aarch64 | \
62
+ ret = -1;
66
i386:i386 | i386:x86_64 | i386:x32 | \
63
+ vec = NULL;
67
x86_64:i386 | x86_64:x86_64 | x86_64:x32 | \
64
+ } else if (!vec->active) {
68
mips:mips | mipsel:mips | mips64:mips | mips64el:mips | \
65
+ /* Return from an inactive interrupt */
69
diff --git a/target/arm/kvm32.c b/target/arm/kvm32.c
66
+ ret = -1;
70
deleted file mode 100644
67
+ } else {
71
index XXXXXXX..XXXXXXX
68
+ /* Legal return, we will return the RETTOBASE bit value to the caller */
72
--- a/target/arm/kvm32.c
69
+ ret = nvic_rettobase(s);
73
+++ /dev/null
70
+ }
74
@@ -XXX,XX +XXX,XX @@
71
+
75
-/*
72
/*
76
- * ARM implementation of KVM hooks, 32 bit specific code.
73
* For negative priorities, v8M will forcibly deactivate the appropriate
77
- *
74
* NMI or HardFault regardless of what interrupt we're being asked to
78
- * Copyright Christoffer Dall 2009-2010
75
@@ -XXX,XX +XXX,XX @@ int armv7m_nvic_complete_irq(void *opaque, int irq, bool secure)
79
- *
76
}
80
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
77
81
- * See the COPYING file in the top-level directory.
78
if (!vec) {
82
- *
79
- if (secure && exc_is_banked(irq)) {
83
- */
80
- vec = &s->sec_vectors[irq];
84
-
81
- } else {
85
-#include "qemu/osdep.h"
82
- vec = &s->vectors[irq];
86
-#include <sys/ioctl.h>
83
- }
87
-
88
-#include <linux/kvm.h>
89
-
90
-#include "qemu-common.h"
91
-#include "cpu.h"
92
-#include "qemu/timer.h"
93
-#include "sysemu/runstate.h"
94
-#include "sysemu/kvm.h"
95
-#include "kvm_arm.h"
96
-#include "internals.h"
97
-#include "qemu/log.h"
98
-
99
-static int read_sys_reg32(int fd, uint32_t *pret, uint64_t id)
100
-{
101
- struct kvm_one_reg idreg = { .id = id, .addr = (uintptr_t)pret };
102
-
103
- assert((id & KVM_REG_SIZE_MASK) == KVM_REG_SIZE_U32);
104
- return ioctl(fd, KVM_GET_ONE_REG, &idreg);
105
-}
106
-
107
-bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
108
-{
109
- /* Identify the feature bits corresponding to the host CPU, and
110
- * fill out the ARMHostCPUClass fields accordingly. To do this
111
- * we have to create a scratch VM, create a single CPU inside it,
112
- * and then query that CPU for the relevant ID registers.
113
- */
114
- int err = 0, fdarray[3];
115
- uint32_t midr, id_pfr0;
116
- uint64_t features = 0;
117
-
118
- /* Old kernels may not know about the PREFERRED_TARGET ioctl: however
119
- * we know these will only support creating one kind of guest CPU,
120
- * which is its preferred CPU type.
121
- */
122
- static const uint32_t cpus_to_try[] = {
123
- QEMU_KVM_ARM_TARGET_CORTEX_A15,
124
- QEMU_KVM_ARM_TARGET_NONE
125
- };
126
- /*
127
- * target = -1 informs kvm_arm_create_scratch_host_vcpu()
128
- * to use the preferred target
129
- */
130
- struct kvm_vcpu_init init = { .target = -1, };
131
-
132
- if (!kvm_arm_create_scratch_host_vcpu(cpus_to_try, fdarray, &init)) {
133
- return false;
134
- }
84
- }
135
-
85
-
136
- ahcf->target = init.target;
86
- trace_nvic_complete_irq(irq, secure);
137
-
87
-
138
- /* This is not strictly blessed by the device tree binding docs yet,
88
- if (!vec->active) {
139
- * but in practice the kernel does not care about this string so
89
- /* Tell the caller this was an illegal exception return */
140
- * there is no point maintaining an KVM_ARM_TARGET_* -> string table.
90
- return -1;
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
- }
91
- }
199
-
92
-
200
- /*
93
- /*
201
- * There is no way to read DBGDIDR, because currently 32-bit KVM
94
- * If this is a configurable exception and it is currently
202
- * doesn't implement debug at all. Leave it at zero.
95
- * targeting the opposite security state from the one we're trying
96
- * to complete it for, this counts as an illegal exception return.
97
- * We still need to deactivate whatever vector the logic above has
98
- * selected, though, as it might not be the same as the one for the
99
- * requested exception number.
203
- */
100
- */
204
-
101
- if (!exc_is_banked(irq) && exc_targets_secure(s, irq) != secure) {
205
- kvm_arm_destroy_scratch_host_vcpu(fdarray);
102
- ret = -1;
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 {
103
- } else {
435
- memcpy(env->usr_regs, env->regs + 8, 5 * sizeof(uint32_t));
104
- ret = nvic_rettobase(s);
436
- }
105
+ return ret;
437
- env->banked_r13[bn] = env->regs[13];
106
}
438
- env->banked_spsr[bn] = env->spsr;
107
439
- env->banked_r14[r14_bank_number(mode)] = env->regs[14];
108
vec->active = 0;
440
-
441
- /* Now we can safely copy stuff down to the kernel */
442
- for (i = 0; i < ARRAY_SIZE(regs); i++) {
443
- r.id = regs[i].id;
444
- r.addr = (uintptr_t)(env) + regs[i].offset;
445
- ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, &r);
446
- if (ret) {
447
- return ret;
448
- }
449
- }
450
-
451
- /* Special cases which aren't a single CPUARMState field */
452
- cpsr = cpsr_read(env);
453
- r.id = KVM_REG_ARM | KVM_REG_SIZE_U32 |
454
- KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(usr_regs.ARM_cpsr);
455
- r.addr = (uintptr_t)(&cpsr);
456
- ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, &r);
457
- if (ret) {
458
- return ret;
459
- }
460
-
461
- /* VFP registers */
462
- r.id = KVM_REG_ARM | KVM_REG_SIZE_U64 | KVM_REG_ARM_VFP;
463
- for (i = 0; i < 32; i++) {
464
- r.addr = (uintptr_t)aa32_vfp_dreg(env, i);
465
- ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, &r);
466
- if (ret) {
467
- return ret;
468
- }
469
- r.id++;
470
- }
471
-
472
- r.id = KVM_REG_ARM | KVM_REG_SIZE_U32 | KVM_REG_ARM_VFP |
473
- KVM_REG_ARM_VFP_FPSCR;
474
- fpscr = vfp_get_fpscr(env);
475
- r.addr = (uintptr_t)&fpscr;
476
- ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, &r);
477
- if (ret) {
478
- return ret;
479
- }
480
-
481
- write_cpustate_to_list(cpu, true);
482
-
483
- if (!write_list_to_kvmstate(cpu, level)) {
484
- return EINVAL;
485
- }
486
-
487
- /*
488
- * Setting VCPU events should be triggered after syncing the registers
489
- * to avoid overwriting potential changes made by KVM upon calling
490
- * KVM_SET_VCPU_EVENTS ioctl
491
- */
492
- ret = kvm_put_vcpu_events(cpu);
493
- if (ret) {
494
- return ret;
495
- }
496
-
497
- kvm_arm_sync_mpstate_to_kvm(cpu);
498
-
499
- return ret;
500
-}
501
-
502
-int kvm_arch_get_registers(CPUState *cs)
503
-{
504
- ARMCPU *cpu = ARM_CPU(cs);
505
- CPUARMState *env = &cpu->env;
506
- struct kvm_one_reg r;
507
- int mode, bn;
508
- int ret, i;
509
- uint32_t cpsr, fpscr;
510
-
511
- for (i = 0; i < ARRAY_SIZE(regs); i++) {
512
- r.id = regs[i].id;
513
- r.addr = (uintptr_t)(env) + regs[i].offset;
514
- ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, &r);
515
- if (ret) {
516
- return ret;
517
- }
518
- }
519
-
520
- /* Special cases which aren't a single CPUARMState field */
521
- r.id = KVM_REG_ARM | KVM_REG_SIZE_U32 |
522
- KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(usr_regs.ARM_cpsr);
523
- r.addr = (uintptr_t)(&cpsr);
524
- ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, &r);
525
- if (ret) {
526
- return ret;
527
- }
528
- cpsr_write(env, cpsr, 0xffffffff, CPSRWriteRaw);
529
-
530
- /* Make sure the current mode regs are properly set */
531
- mode = env->uncached_cpsr & CPSR_M;
532
- bn = bank_number(mode);
533
- if (mode == ARM_CPU_MODE_FIQ) {
534
- memcpy(env->regs + 8, env->fiq_regs, 5 * sizeof(uint32_t));
535
- } else {
536
- memcpy(env->regs + 8, env->usr_regs, 5 * sizeof(uint32_t));
537
- }
538
- env->regs[13] = env->banked_r13[bn];
539
- env->spsr = env->banked_spsr[bn];
540
- env->regs[14] = env->banked_r14[r14_bank_number(mode)];
541
-
542
- /* VFP registers */
543
- r.id = KVM_REG_ARM | KVM_REG_SIZE_U64 | KVM_REG_ARM_VFP;
544
- for (i = 0; i < 32; i++) {
545
- r.addr = (uintptr_t)aa32_vfp_dreg(env, i);
546
- ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, &r);
547
- if (ret) {
548
- return ret;
549
- }
550
- r.id++;
551
- }
552
-
553
- r.id = KVM_REG_ARM | KVM_REG_SIZE_U32 | KVM_REG_ARM_VFP |
554
- KVM_REG_ARM_VFP_FPSCR;
555
- r.addr = (uintptr_t)&fpscr;
556
- ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, &r);
557
- if (ret) {
558
- return ret;
559
- }
560
- vfp_set_fpscr(env, fpscr);
561
-
562
- ret = kvm_get_vcpu_events(cpu);
563
- if (ret) {
564
- return ret;
565
- }
566
-
567
- if (!write_kvmstate_to_list(cpu)) {
568
- return EINVAL;
569
- }
570
- /* Note that it's OK to have registers which aren't in CPUState,
571
- * so we can ignore a failure return here.
572
- */
573
- write_list_to_cpustate(cpu);
574
-
575
- kvm_arm_sync_mpstate_to_qemu(cpu);
576
-
577
- return 0;
578
-}
579
-
580
-int kvm_arch_insert_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp)
581
-{
582
- qemu_log_mask(LOG_UNIMP, "%s: guest debug not yet implemented\n", __func__);
583
- return -EINVAL;
584
-}
585
-
586
-int kvm_arch_remove_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp)
587
-{
588
- qemu_log_mask(LOG_UNIMP, "%s: guest debug not yet implemented\n", __func__);
589
- return -EINVAL;
590
-}
591
-
592
-bool kvm_arm_handle_debug(CPUState *cs, struct kvm_debug_exit_arch *debug_exit)
593
-{
594
- qemu_log_mask(LOG_UNIMP, "%s: guest debug not yet implemented\n", __func__);
595
- return false;
596
-}
597
-
598
-int kvm_arch_insert_hw_breakpoint(target_ulong addr,
599
- target_ulong len, int type)
600
-{
601
- qemu_log_mask(LOG_UNIMP, "%s: not implemented\n", __func__);
602
- return -EINVAL;
603
-}
604
-
605
-int kvm_arch_remove_hw_breakpoint(target_ulong addr,
606
- target_ulong len, int type)
607
-{
608
- qemu_log_mask(LOG_UNIMP, "%s: not implemented\n", __func__);
609
- return -EINVAL;
610
-}
611
-
612
-void kvm_arch_remove_all_hw_breakpoints(void)
613
-{
614
- qemu_log_mask(LOG_UNIMP, "%s: not implemented\n", __func__);
615
-}
616
-
617
-void kvm_arm_copy_hw_debug_data(struct kvm_guest_debug_arch *ptr)
618
-{
619
- qemu_log_mask(LOG_UNIMP, "%s: not implemented\n", __func__);
620
-}
621
-
622
-bool kvm_arm_hw_debug_active(CPUState *cs)
623
-{
624
- return false;
625
-}
626
-
627
-void kvm_arm_pmu_set_irq(CPUState *cs, int irq)
628
-{
629
- qemu_log_mask(LOG_UNIMP, "%s: not implemented\n", __func__);
630
-}
631
-
632
-void kvm_arm_pmu_init(CPUState *cs)
633
-{
634
- qemu_log_mask(LOG_UNIMP, "%s: not implemented\n", __func__);
635
-}
636
-
637
-#define ARM_REG_DFSR ARM_CP15_REG32(0, 5, 0, 0)
638
-#define ARM_REG_TTBCR ARM_CP15_REG32(0, 2, 0, 2)
639
-/*
640
- *DFSR:
641
- * TTBCR.EAE == 0
642
- * FS[4] - DFSR[10]
643
- * FS[3:0] - DFSR[3:0]
644
- * TTBCR.EAE == 1
645
- * FS, bits [5:0]
646
- */
647
-#define DFSR_FSC(lpae, v) \
648
- ((lpae) ? ((v) & 0x3F) : (((v) >> 6) | ((v) & 0x1F)))
649
-
650
-#define DFSC_EXTABT(lpae) ((lpae) ? 0x10 : 0x08)
651
-
652
-bool kvm_arm_verify_ext_dabt_pending(CPUState *cs)
653
-{
654
- uint32_t dfsr_val;
655
-
656
- if (!kvm_get_one_reg(cs, ARM_REG_DFSR, &dfsr_val)) {
657
- ARMCPU *cpu = ARM_CPU(cs);
658
- CPUARMState *env = &cpu->env;
659
- uint32_t ttbcr;
660
- int lpae = 0;
661
-
662
- if (!kvm_get_one_reg(cs, ARM_REG_TTBCR, &ttbcr)) {
663
- lpae = arm_feature(env, ARM_FEATURE_LPAE) && (ttbcr & TTBCR_EAE);
664
- }
665
- /* The verification is based on FS filed of the DFSR reg only*/
666
- return (DFSR_FSC(lpae, dfsr_val) == DFSC_EXTABT(lpae));
667
- }
668
- return false;
669
-}
670
diff --git a/target/arm/meson.build b/target/arm/meson.build
671
index XXXXXXX..XXXXXXX 100644
672
--- a/target/arm/meson.build
673
+++ b/target/arm/meson.build
674
@@ -XXX,XX +XXX,XX @@ arm_ss.add(zlib)
675
676
arm_ss.add(when: 'CONFIG_TCG', if_true: files('arm-semi.c'))
677
678
-kvm_ss = ss.source_set()
679
-kvm_ss.add(when: 'TARGET_AARCH64', if_true: files('kvm64.c'), if_false: files('kvm32.c'))
680
-arm_ss.add_all(when: 'CONFIG_KVM', if_true: kvm_ss)
681
-arm_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c'), if_false: files('kvm-stub.c'))
682
+arm_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c', 'kvm64.c'), if_false: files('kvm-stub.c'))
683
684
arm_ss.add(when: 'TARGET_AARCH64', if_true: files(
685
'cpu64.c',
686
--
109
--
687
2.20.1
110
2.20.1
688
111
689
112
diff view generated by jsdifflib
1
In the Neon instructions, some instruction formats have a 2-bit size
1
For v8.1M the architecture mandates that CPUs must provide at
2
field which corresponds exactly to QEMU's MO_8/16/32/64. However the
2
least the "minimal RAS implementation" from the Reliability,
3
floating-point insns in the 3-same group have a 1-bit size field
3
Availability and Serviceability extension. This consists of:
4
which is "0 for 32-bit float and 1 for 16-bit float". Currently we
4
* an ESB instruction which is a NOP
5
pass these values directly through to trans_ functions, which means
5
-- since it is in the HINT space we need only add a comment
6
that when reading a particular trans_ function you need to know if
6
* an RFSR register which will RAZ/WI
7
that insn uses a 2-bit size or a 1-bit size.
7
* a RAZ/WI AIRCR.IESB bit
8
8
-- the code which handles writes to AIRCR does not allow setting
9
Move the handling of the 1-bit size to the decodetree file, so that
9
of RES0 bits, so we already treat this as RAZ/WI; add a comment
10
all these insns consistently pass a size to the trans_ function which
10
noting that this is deliberate
11
is an MO_8/16/32/64 value.
11
* minimal implementation of the RAS register block at 0xe0005000
12
12
-- this will be in a subsequent commit
13
In this commit we switch over the insns using the 3same_fp and
13
* setting the ID_PFR0.RAS field to 0b0010
14
3same_fp_q0 formats.
14
-- we will do this when we add the Cortex-M55 CPU model
15
15
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
17
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
18
Message-id: 20200903133209.5141-2-peter.maydell@linaro.org
18
Message-id: 20201119215617.29887-26-peter.maydell@linaro.org
19
---
19
---
20
target/arm/neon-dp.decode | 15 ++++++++++-----
20
target/arm/cpu.h | 14 ++++++++++++++
21
target/arm/translate-neon.c.inc | 16 +++++++++++-----
21
target/arm/t32.decode | 4 ++++
22
2 files changed, 21 insertions(+), 10 deletions(-)
22
hw/intc/armv7m_nvic.c | 13 +++++++++++++
23
3 files changed, 31 insertions(+)
23
24
24
diff --git a/target/arm/neon-dp.decode b/target/arm/neon-dp.decode
25
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
25
index XXXXXXX..XXXXXXX 100644
26
index XXXXXXX..XXXXXXX 100644
26
--- a/target/arm/neon-dp.decode
27
--- a/target/arm/cpu.h
27
+++ b/target/arm/neon-dp.decode
28
+++ b/target/arm/cpu.h
28
@@ -XXX,XX +XXX,XX @@
29
@@ -XXX,XX +XXX,XX @@ FIELD(ID_MMFR4, LSM, 20, 4)
29
@3same_q0 .... ... . . . size:2 .... .... .... . 0 . . .... \
30
FIELD(ID_MMFR4, CCIDX, 24, 4)
30
&3same vm=%vm_dp vn=%vn_dp vd=%vd_dp q=0
31
FIELD(ID_MMFR4, EVT, 28, 4)
31
32
32
-# For FP insns the high bit of 'size' is used as part of opcode decode
33
+FIELD(ID_PFR0, STATE0, 0, 4)
33
-@3same_fp .... ... . . . . size:1 .... .... .... . q:1 . . .... \
34
+FIELD(ID_PFR0, STATE1, 4, 4)
34
- &3same vm=%vm_dp vn=%vn_dp vd=%vd_dp
35
+FIELD(ID_PFR0, STATE2, 8, 4)
35
-@3same_fp_q0 .... ... . . . . size:1 .... .... .... . 0 . . .... \
36
+FIELD(ID_PFR0, STATE3, 12, 4)
36
- &3same vm=%vm_dp vn=%vn_dp vd=%vd_dp q=0
37
+FIELD(ID_PFR0, CSV2, 16, 4)
37
+# For FP insns the high bit of 'size' is used as part of opcode decode,
38
+FIELD(ID_PFR0, AMU, 20, 4)
38
+# and the 'size' bit is 0 for 32-bit float and 1 for 16-bit float.
39
+FIELD(ID_PFR0, DIT, 24, 4)
39
+# This converts this encoding to the same MO_8/16/32/64 values that the
40
+FIELD(ID_PFR0, RAS, 28, 4)
40
+# integer neon insns use.
41
+%3same_fp_size 20:1 !function=neon_3same_fp_size
42
+
41
+
43
+@3same_fp .... ... . . . . . .... .... .... . q:1 . . .... \
42
FIELD(ID_PFR1, PROGMOD, 0, 4)
44
+ &3same vm=%vm_dp vn=%vn_dp vd=%vd_dp size=%3same_fp_size
43
FIELD(ID_PFR1, SECURITY, 4, 4)
45
+@3same_fp_q0 .... ... . . . . . .... .... .... . 0 . . .... \
44
FIELD(ID_PFR1, MPROGMOD, 8, 4)
46
+ &3same vm=%vm_dp vn=%vn_dp vd=%vd_dp q=0 size=%3same_fp_size
45
@@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa32_predinv(const ARMISARegisters *id)
47
46
return FIELD_EX32(id->id_isar6, ID_ISAR6, SPECRES) != 0;
48
VHADD_S_3s 1111 001 0 0 . .. .... .... 0000 . . . 0 .... @3same
49
VHADD_U_3s 1111 001 1 0 . .. .... .... 0000 . . . 0 .... @3same
50
diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc
51
index XXXXXXX..XXXXXXX 100644
52
--- a/target/arm/translate-neon.c.inc
53
+++ b/target/arm/translate-neon.c.inc
54
@@ -XXX,XX +XXX,XX @@ static inline int rsub_8(DisasContext *s, int x)
55
return 8 - x;
56
}
47
}
57
48
58
+static inline int neon_3same_fp_size(DisasContext *s, int x)
49
+static inline bool isar_feature_aa32_ras(const ARMISARegisters *id)
59
+{
50
+{
60
+ /* Convert 0==fp32, 1==fp16 into a MO_* value */
51
+ return FIELD_EX32(id->id_pfr0, ID_PFR0, RAS) != 0;
61
+ return MO_32 - x;
62
+}
52
+}
63
+
53
+
64
/* Include the generated Neon decoder */
54
static inline bool isar_feature_aa32_mprofile(const ARMISARegisters *id)
65
#include "decode-neon-dp.c.inc"
55
{
66
#include "decode-neon-ls.c.inc"
56
return FIELD_EX32(id->id_pfr1, ID_PFR1, MPROGMOD) != 0;
67
@@ -XXX,XX +XXX,XX @@ DO_3SAME_VQDMULH(VQRDMULH, qrdmulh)
57
diff --git a/target/arm/t32.decode b/target/arm/t32.decode
68
WRAP_FP_GVEC(gen_##INSN##_fp16_3s, FPST_STD_F16, HFUNC) \
58
index XXXXXXX..XXXXXXX 100644
69
static bool trans_##INSN##_fp_3s(DisasContext *s, arg_3same *a) \
59
--- a/target/arm/t32.decode
70
{ \
60
+++ b/target/arm/t32.decode
71
- if (a->size != 0) { \
61
@@ -XXX,XX +XXX,XX @@ CLZ 1111 1010 1011 ---- 1111 .... 1000 .... @rdm
72
+ if (a->size == MO_16) { \
62
# SEV 1111 0011 1010 1111 1000 0000 0000 0100
73
if (!dc_isar_feature(aa32_fp16_arith, s)) { \
63
# SEVL 1111 0011 1010 1111 1000 0000 0000 0101
74
return false; \
64
75
} \
65
+ # For M-profile minimal-RAS ESB can be a NOP, which is the
76
@@ -XXX,XX +XXX,XX @@ static bool trans_VMAXNM_fp_3s(DisasContext *s, arg_3same *a)
66
+ # default behaviour since it is in the hint space.
77
return false;
67
+ # ESB 1111 0011 1010 1111 1000 0000 0001 0000
68
+
69
# The canonical nop ends in 0000 0000, but the whole rest
70
# of the space is "reserved hint, behaves as nop".
71
NOP 1111 0011 1010 1111 1000 0000 ---- ----
72
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
73
index XXXXXXX..XXXXXXX 100644
74
--- a/hw/intc/armv7m_nvic.c
75
+++ b/hw/intc/armv7m_nvic.c
76
@@ -XXX,XX +XXX,XX @@ static uint32_t nvic_readl(NVICState *s, uint32_t offset, MemTxAttrs attrs)
77
return 0;
78
}
79
return cpu->env.v7m.sfar;
80
+ case 0xf04: /* RFSR */
81
+ if (!cpu_isar_feature(aa32_ras, cpu)) {
82
+ goto bad_offset;
83
+ }
84
+ /* We provide minimal-RAS only: RFSR is RAZ/WI */
85
+ return 0;
86
case 0xf34: /* FPCCR */
87
if (!cpu_isar_feature(aa32_vfp_simd, cpu)) {
88
return 0;
89
@@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value,
90
R_V7M_AIRCR_PRIGROUP_SHIFT,
91
R_V7M_AIRCR_PRIGROUP_LENGTH);
92
}
93
+ /* AIRCR.IESB is RAZ/WI because we implement only minimal RAS */
94
if (attrs.secure) {
95
/* These bits are only writable by secure */
96
cpu->env.v7m.aircr = value &
97
@@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value,
98
}
99
break;
78
}
100
}
79
101
+ case 0xf04: /* RFSR */
80
- if (a->size != 0) {
102
+ if (!cpu_isar_feature(aa32_ras, cpu)) {
81
+ if (a->size == MO_16) {
103
+ goto bad_offset;
82
if (!dc_isar_feature(aa32_fp16_arith, s)) {
104
+ }
83
return false;
105
+ /* We provide minimal-RAS only: RFSR is RAZ/WI */
84
}
106
+ break;
85
@@ -XXX,XX +XXX,XX @@ static bool trans_VMINNM_fp_3s(DisasContext *s, arg_3same *a)
107
case 0xf34: /* FPCCR */
86
return false;
108
if (cpu_isar_feature(aa32_vfp_simd, cpu)) {
87
}
109
/* Not all bits here are banked. */
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
} \
112
--
110
--
113
2.20.1
111
2.20.1
114
112
115
113
diff view generated by jsdifflib
1
Implement a model of the MPS2 with the AN500 firmware. This is
1
The RAS feature has a block of memory-mapped registers at offset
2
similar to the AN385, with the following differences:
2
0x5000 within the PPB. For a "minimal RAS" implementation we provide
3
* Cortex-M7 CPU
3
no error records and so the only registers that exist in the block
4
* PSRAM is at 0x6000_0000
4
are ERRIIDR and ERRDEVID.
5
* Ethernet is at 0xa000_0000
5
6
* No zbt_boot_ctrl remapping of the low 16K
6
The "RAZ/WI for privileged, BusFault for nonprivileged" behaviour
7
(but QEMU doesn't implement this anyway)
7
of the "nvic-default" region is actually valid for minimal-RAS,
8
* no "block RAM" at 0x01000000
8
so the main benefit of providing an explicit implementation of
9
the register block is more accurate LOG_UNIMP messages, and a
10
framework for where we could add a real RAS implementation later
11
if necessary.
9
12
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
14
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Message-id: 20200903202048.15370-3-peter.maydell@linaro.org
15
Message-id: 20201119215617.29887-27-peter.maydell@linaro.org
13
---
16
---
14
docs/system/arm/mps2.rst | 6 ++--
17
include/hw/intc/armv7m_nvic.h | 1 +
15
hw/arm/mps2.c | 67 +++++++++++++++++++++++++++++++++-------
18
hw/intc/armv7m_nvic.c | 56 +++++++++++++++++++++++++++++++++++
16
2 files changed, 60 insertions(+), 13 deletions(-)
19
2 files changed, 57 insertions(+)
17
20
18
diff --git a/docs/system/arm/mps2.rst b/docs/system/arm/mps2.rst
21
diff --git a/include/hw/intc/armv7m_nvic.h b/include/hw/intc/armv7m_nvic.h
19
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
20
--- a/docs/system/arm/mps2.rst
23
--- a/include/hw/intc/armv7m_nvic.h
21
+++ b/docs/system/arm/mps2.rst
24
+++ b/include/hw/intc/armv7m_nvic.h
22
@@ -XXX,XX +XXX,XX @@
25
@@ -XXX,XX +XXX,XX @@ struct NVICState {
23
-Arm MPS2 boards (``mps2-an385``, ``mps2-an386``, ``mps2-an505``, ``mps2-an511``, ``mps2-an521``)
26
MemoryRegion sysreg_ns_mem;
24
-================================================================================================
27
MemoryRegion systickmem;
25
+Arm MPS2 boards (``mps2-an385``, ``mps2-an386``, ``mps2-an500``, ``mps2-an505``, ``mps2-an511``, ``mps2-an521``)
28
MemoryRegion systick_ns_mem;
26
+================================================================================================================
29
+ MemoryRegion ras_mem;
27
30
MemoryRegion container;
28
These board models all use Arm M-profile CPUs.
31
MemoryRegion defaultmem;
29
32
30
@@ -XXX,XX +XXX,XX @@ QEMU models the following FPGA images:
33
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
31
Cortex-M3 as documented in ARM Application Note AN385
32
``mps2-an386``
33
Cortex-M4 as documented in ARM Application Note AN386
34
+``mps2-an500``
35
+ Cortex-M7 as documented in ARM Application Note AN500
36
``mps2-an511``
37
Cortex-M3 'DesignStart' as documented in AN511
38
``mps2-an505``
39
diff --git a/hw/arm/mps2.c b/hw/arm/mps2.c
40
index XXXXXXX..XXXXXXX 100644
34
index XXXXXXX..XXXXXXX 100644
41
--- a/hw/arm/mps2.c
35
--- a/hw/intc/armv7m_nvic.c
42
+++ b/hw/arm/mps2.c
36
+++ b/hw/intc/armv7m_nvic.c
43
@@ -XXX,XX +XXX,XX @@
37
@@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps nvic_systick_ops = {
44
* We model the following FPGA images:
38
.endianness = DEVICE_NATIVE_ENDIAN,
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
};
39
};
67
typedef struct MPS2MachineClass MPS2MachineClass;
40
68
41
+
69
@@ -XXX,XX +XXX,XX @@ typedef struct MPS2MachineState MPS2MachineState;
42
+static MemTxResult ras_read(void *opaque, hwaddr addr,
70
#define TYPE_MPS2_MACHINE "mps2"
43
+ uint64_t *data, unsigned size,
71
#define TYPE_MPS2_AN385_MACHINE MACHINE_TYPE_NAME("mps2-an385")
44
+ MemTxAttrs attrs)
72
#define TYPE_MPS2_AN386_MACHINE MACHINE_TYPE_NAME("mps2-an386")
45
+{
73
+#define TYPE_MPS2_AN500_MACHINE MACHINE_TYPE_NAME("mps2-an500")
46
+ if (attrs.user) {
74
#define TYPE_MPS2_AN511_MACHINE MACHINE_TYPE_NAME("mps2-an511")
47
+ return MEMTX_ERROR;
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
+ }
48
+ }
123
+
49
+
124
+ switch (mmc->fpga_type) {
50
+ switch (addr) {
125
+ case FPGA_AN385:
51
+ case 0xe10: /* ERRIIDR */
126
+ case FPGA_AN386:
52
+ /* architect field = Arm; product/variant/revision 0 */
127
+ case FPGA_AN500:
53
+ *data = 0x43b;
128
+ make_ram(&mms->ssram1, "mps.ssram1", 0x0, 0x400000);
54
+ break;
129
+ make_ram_alias(&mms->ssram1_m, "mps.ssram1_m", &mms->ssram1, 0x400000);
55
+ case 0xfc8: /* ERRDEVID */
130
+ make_ram(&mms->ssram23, "mps.ssram23", 0x20000000, 0x400000);
56
+ /* Minimal RAS: we implement 0 error record indexes */
131
+ make_ram_alias(&mms->ssram23_m, "mps.ssram23_m",
57
+ *data = 0;
132
+ &mms->ssram23, 0x20400000);
58
+ break;
133
break;
59
+ default:
134
case FPGA_AN511:
60
+ qemu_log_mask(LOG_UNIMP, "Read RAS register offset 0x%x\n",
135
make_ram(&mms->blockram, "mps.blockram", 0x0, 0x40000);
61
+ (uint32_t)addr);
136
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
62
+ *data = 0;
137
switch (mmc->fpga_type) {
63
+ break;
138
case FPGA_AN385:
64
+ }
139
case FPGA_AN386:
65
+ return MEMTX_OK;
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
+}
66
+}
179
+
67
+
180
+static void mps2_an500_class_init(ObjectClass *oc, void *data)
68
+static MemTxResult ras_write(void *opaque, hwaddr addr,
69
+ uint64_t value, unsigned size,
70
+ MemTxAttrs attrs)
181
+{
71
+{
182
+ MachineClass *mc = MACHINE_CLASS(oc);
72
+ if (attrs.user) {
183
+ MPS2MachineClass *mmc = MPS2_MACHINE_CLASS(oc);
73
+ return MEMTX_ERROR;
74
+ }
184
+
75
+
185
+ mc->desc = "ARM MPS2 with AN500 FPGA image for Cortex-M7";
76
+ switch (addr) {
186
+ mmc->fpga_type = FPGA_AN500;
77
+ default:
187
+ mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m7");
78
+ qemu_log_mask(LOG_UNIMP, "Write to RAS register offset 0x%x\n",
188
+ mmc->scc_id = 0x41045000;
79
+ (uint32_t)addr);
189
+ mmc->psram_base = 0x60000000;
80
+ break;
190
+ mmc->ethernet_base = 0xa0000000;
81
+ }
191
+ mmc->has_block_ram = false;
82
+ return MEMTX_OK;
192
}
83
+}
193
84
+
194
static void mps2_an511_class_init(ObjectClass *oc, void *data)
85
+static const MemoryRegionOps ras_ops = {
195
@@ -XXX,XX +XXX,XX @@ static void mps2_an511_class_init(ObjectClass *oc, void *data)
86
+ .read_with_attrs = ras_read,
196
mmc->fpga_type = FPGA_AN511;
87
+ .write_with_attrs = ras_write,
197
mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m3");
88
+ .endianness = DEVICE_NATIVE_ENDIAN,
198
mmc->scc_id = 0x41045110;
199
+ mmc->psram_base = 0x21000000;
200
+ mmc->ethernet_base = 0x40200000;
201
+ mmc->has_block_ram = false;
202
}
203
204
static const TypeInfo mps2_info = {
205
@@ -XXX,XX +XXX,XX @@ static const TypeInfo mps2_an386_info = {
206
.class_init = mps2_an386_class_init,
207
};
208
209
+static const TypeInfo mps2_an500_info = {
210
+ .name = TYPE_MPS2_AN500_MACHINE,
211
+ .parent = TYPE_MPS2_MACHINE,
212
+ .class_init = mps2_an500_class_init,
213
+};
89
+};
214
+
90
+
215
static const TypeInfo mps2_an511_info = {
91
/*
216
.name = TYPE_MPS2_AN511_MACHINE,
92
* Unassigned portions of the PPB space are RAZ/WI for privileged
217
.parent = TYPE_MPS2_MACHINE,
93
* accesses, and fault for non-privileged accesses.
218
@@ -XXX,XX +XXX,XX @@ static void mps2_machine_init(void)
94
@@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_realize(DeviceState *dev, Error **errp)
219
type_register_static(&mps2_info);
95
&s->systick_ns_mem, 1);
220
type_register_static(&mps2_an385_info);
96
}
221
type_register_static(&mps2_an386_info);
97
222
+ type_register_static(&mps2_an500_info);
98
+ if (cpu_isar_feature(aa32_ras, s->cpu)) {
223
type_register_static(&mps2_an511_info);
99
+ memory_region_init_io(&s->ras_mem, OBJECT(s),
100
+ &ras_ops, s, "nvic_ras", 0x1000);
101
+ memory_region_add_subregion(&s->container, 0x5000, &s->ras_mem);
102
+ }
103
+
104
sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->container);
224
}
105
}
225
106
226
--
107
--
227
2.20.1
108
2.20.1
228
109
229
110
diff view generated by jsdifflib
1
Make the list of MPS2 boards consistent in the phrasing of each
1
Correct a typo in the name we give the NVIC object.
2
entry, use the correct casing of "Arm", and move the mps2-an511
3
entry so the list is in numeric order.
4
2
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
3
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
4
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Message-id: 20200903202048.15370-4-peter.maydell@linaro.org
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
Message-id: 20201119215617.29887-28-peter.maydell@linaro.org
8
---
7
---
9
docs/system/arm/mps2.rst | 14 +++++++-------
8
hw/arm/armv7m.c | 2 +-
10
1 file changed, 7 insertions(+), 7 deletions(-)
9
1 file changed, 1 insertion(+), 1 deletion(-)
11
10
12
diff --git a/docs/system/arm/mps2.rst b/docs/system/arm/mps2.rst
11
diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c
13
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
14
--- a/docs/system/arm/mps2.rst
13
--- a/hw/arm/armv7m.c
15
+++ b/docs/system/arm/mps2.rst
14
+++ b/hw/arm/armv7m.c
16
@@ -XXX,XX +XXX,XX @@ as seen by the guest depend significantly on the FPGA image.
15
@@ -XXX,XX +XXX,XX @@ static void armv7m_instance_init(Object *obj)
17
QEMU models the following FPGA images:
16
18
17
memory_region_init(&s->container, obj, "armv7m-container", UINT64_MAX);
19
``mps2-an385``
18
20
- Cortex-M3 as documented in ARM Application Note AN385
19
- object_initialize_child(obj, "nvnic", &s->nvic, TYPE_NVIC);
21
+ Cortex-M3 as documented in Arm Application Note AN385
20
+ object_initialize_child(obj, "nvic", &s->nvic, TYPE_NVIC);
22
``mps2-an386``
21
object_property_add_alias(obj, "num-irq",
23
- Cortex-M4 as documented in ARM Application Note AN386
22
OBJECT(&s->nvic), "num-irq");
24
+ Cortex-M4 as documented in Arm Application Note AN386
25
``mps2-an500``
26
- Cortex-M7 as documented in ARM Application Note AN500
27
-``mps2-an511``
28
- Cortex-M3 'DesignStart' as documented in AN511
29
+ Cortex-M7 as documented in Arm Application Note AN500
30
``mps2-an505``
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
23
41
--
24
--
42
2.20.1
25
2.20.1
43
26
44
27
diff view generated by jsdifflib