1
Second pull request of the week; mostly RTH's support for some
1
target-arm queue: I have a lot more still in my to-review
2
new-in-v8.1/v8.3 instructions, and my v8M board model.
2
queue, but my rule of thumb is when I get to 50 patches or
3
so to send out what I have.
3
4
4
thanks
5
thanks
5
-- PMM
6
-- PMM
6
7
7
The following changes since commit 427cbc7e4136a061628cb4315cc8182ea36d772f:
8
The following changes since commit 9a7beaad3dbba982f7a461d676b55a5c3851d312:
8
9
9
Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging (2018-03-01 18:46:41 +0000)
10
Merge remote-tracking branch 'remotes/alistair/tags/pull-riscv-to-apply-20210304' into staging (2021-03-05 10:47:46 +0000)
10
11
11
are available in the Git repository at:
12
are available in the Git repository at:
12
13
13
git://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20180302
14
https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20210305
14
15
15
for you to fetch changes up to e66a67bf28e1b4fce2e3d72a2610dbd48d9d3078:
16
for you to fetch changes up to 2c669ff88ec6733420a000103a2b8b9e93df4945:
16
17
17
target/arm: Enable ARM_FEATURE_V8_FCMA (2018-03-02 11:03:45 +0000)
18
hw/arm/mps2: Update old infocenter.arm.com URLs (2021-03-05 15:17:38 +0000)
18
19
19
----------------------------------------------------------------
20
----------------------------------------------------------------
20
target-arm queue:
21
* sbsa-ref: remove cortex-a53 from list of supported cpus
21
* implement FCMA and RDM v8.1 and v8.3 instructions
22
* sbsa-ref: add 'max' to list of allowed cpus
22
* enable Cortex-M33 v8M core, and provide new mps2-an505 board model
23
* target/arm: Add support for FEAT_SSBS, Speculative Store Bypass Safe
23
that uses it
24
* npcm7xx: add EMC model
24
* decodetree: Propagate return value from translate subroutines
25
* xlnx-zynqmp: Remove obsolete 'has_rpu' property
25
* xlnx-zynqmp: Implement the RTC device
26
* target/arm: Speed up aarch64 TBL/TBX
27
* virtio-mmio: improve virtio-mmio get_dev_path alog
28
* target/arm: Use TCF0 and TFSRE0 for unprivileged tag checks
29
* target/arm: Restrict v8M IDAU to TCG
30
* target/arm/cpu: Update coding style to make checkpatch.pl happy
31
* musicpal, tc6393xb, omap_lcdc, tcx: drop dead code for non-32-bit-RGB surfaces
32
* Add new board: mps3-an524
26
33
27
----------------------------------------------------------------
34
----------------------------------------------------------------
28
Alistair Francis (3):
35
Doug Evans (3):
29
xlnx-zynqmp-rtc: Initial commit
36
hw/net: Add npcm7xx emc model
30
xlnx-zynqmp-rtc: Add basic time support
37
hw/arm: Add npcm7xx emc model
31
xlnx-zynqmp: Connect the RTC device
38
tests/qtests: Add npcm7xx emc model test
32
39
33
Peter Maydell (19):
40
Marcin Juszkiewicz (2):
34
loader: Add new load_ramdisk_as()
41
sbsa-ref: remove cortex-a53 from list of supported cpus
35
hw/arm/boot: Honour CPU's address space for image loads
42
sbsa-ref: add 'max' to list of allowed cpus
36
hw/arm/armv7m: Honour CPU's address space for image loads
37
target/arm: Define an IDAU interface
38
armv7m: Forward idau property to CPU object
39
target/arm: Define init-svtor property for the reset secure VTOR value
40
armv7m: Forward init-svtor property to CPU object
41
target/arm: Add Cortex-M33
42
hw/misc/unimp: Move struct to header file
43
include/hw/or-irq.h: Add missing include guard
44
qdev: Add new qdev_init_gpio_in_named_with_opaque()
45
hw/core/split-irq: Device that splits IRQ lines
46
hw/misc/mps2-fpgaio: FPGA control block for MPS2 AN505
47
hw/misc/tz-ppc: Model TrustZone peripheral protection controller
48
hw/misc/iotkit-secctl: Arm IoT Kit security controller initial skeleton
49
hw/misc/iotkit-secctl: Add handling for PPCs
50
hw/misc/iotkit-secctl: Add remaining simple registers
51
hw/arm/iotkit: Model Arm IOT Kit
52
mps2-an505: New board model: MPS2 with AN505 Cortex-M33 FPGA image
53
43
54
Richard Henderson (17):
44
Peter Collingbourne (1):
55
decodetree: Propagate return value from translate subroutines
45
target/arm: Use TCF0 and TFSRE0 for unprivileged tag checks
56
target/arm: Add ARM_FEATURE_V8_RDM
57
target/arm: Refactor disas_simd_indexed decode
58
target/arm: Refactor disas_simd_indexed size checks
59
target/arm: Decode aa64 armv8.1 scalar three same extra
60
target/arm: Decode aa64 armv8.1 three same extra
61
target/arm: Decode aa64 armv8.1 scalar/vector x indexed element
62
target/arm: Decode aa32 armv8.1 three same
63
target/arm: Decode aa32 armv8.1 two reg and a scalar
64
target/arm: Enable ARM_FEATURE_V8_RDM
65
target/arm: Add ARM_FEATURE_V8_FCMA
66
target/arm: Decode aa64 armv8.3 fcadd
67
target/arm: Decode aa64 armv8.3 fcmla
68
target/arm: Decode aa32 armv8.3 3-same
69
target/arm: Decode aa32 armv8.3 2-reg-index
70
target/arm: Decode t32 simd 3reg and 2reg_scalar extension
71
target/arm: Enable ARM_FEATURE_V8_FCMA
72
46
73
hw/arm/Makefile.objs | 2 +
47
Peter Maydell (34):
74
hw/core/Makefile.objs | 1 +
48
hw/arm/musicpal: Remove dead code for non-32-bit-RGB surfaces
75
hw/misc/Makefile.objs | 4 +
49
hw/display/tc6393xb: Remove dead code for handling non-32bpp surfaces
76
hw/timer/Makefile.objs | 1 +
50
hw/display/tc6393xb: Expand out macros in template header
77
target/arm/Makefile.objs | 2 +-
51
hw/display/tc6393xb: Inline tc6393xb_draw_graphic32() at its callsite
78
include/hw/arm/armv7m.h | 5 +
52
hw/display/omap_lcdc: Expand out macros in template header
79
include/hw/arm/iotkit.h | 109 ++++++
53
hw/display/omap_lcdc: Drop broken bigendian ifdef
80
include/hw/arm/xlnx-zynqmp.h | 2 +
54
hw/display/omap_lcdc: Fix coding style issues in template header
81
include/hw/core/split-irq.h | 57 +++
55
hw/display/omap_lcdc: Inline template header into C file
82
include/hw/irq.h | 4 +-
56
hw/display/omap_lcdc: Delete unnecessary macro
83
include/hw/loader.h | 12 +-
57
hw/display/tcx: Drop unnecessary code for handling BGR format outputs
84
include/hw/misc/iotkit-secctl.h | 103 ++++++
58
hw/arm/mps2-tz: Make SYSCLK frequency board-specific
85
include/hw/misc/mps2-fpgaio.h | 43 +++
59
hw/misc/mps2-scc: Support configurable number of OSCCLK values
86
include/hw/misc/tz-ppc.h | 101 ++++++
60
hw/arm/mps2-tz: Correct the OSCCLK settings for mps2-an505 and mps2-an511
87
include/hw/misc/unimp.h | 10 +
61
hw/arm/mps2-tz: Make the OSCCLK settings be configurable per-board
88
include/hw/or-irq.h | 5 +
62
hw/misc/mps2-fpgaio: Make number of LEDs configurable by board
89
include/hw/qdev-core.h | 30 +-
63
hw/misc/mps2-fpgaio: Support SWITCH register
90
include/hw/timer/xlnx-zynqmp-rtc.h | 86 +++++
64
hw/arm/mps2-tz: Make FPGAIO switch and LED config per-board
91
target/arm/cpu.h | 8 +
65
hw/arm/mps2-tz: Condition IRQ splitting on number of CPUs, not board type
92
target/arm/helper.h | 31 ++
66
hw/arm/mps2-tz: Make number of IRQs board-specific
93
target/arm/idau.h | 61 ++++
67
hw/misc/mps2-scc: Implement CFG_REG5 and CFG_REG6 for MPS3 AN524
94
hw/arm/armv7m.c | 35 +-
68
hw/arm/mps2-tz: Correct wrong interrupt numbers for DMA and SPI
95
hw/arm/boot.c | 119 ++++---
69
hw/arm/mps2-tz: Allow PPCPortInfo structures to specify device interrupts
96
hw/arm/iotkit.c | 598 +++++++++++++++++++++++++++++++
70
hw/arm/mps2-tz: Move device IRQ info to data structures
97
hw/arm/mps2-tz.c | 503 ++++++++++++++++++++++++++
71
hw/arm/mps2-tz: Size the uart-irq-orgate based on the number of UARTs
98
hw/arm/xlnx-zynqmp.c | 14 +
72
hw/arm/mps2-tz: Allow boards to have different PPCInfo data
99
hw/core/loader.c | 8 +-
73
hw/arm/mps2-tz: Make RAM arrangement board-specific
100
hw/core/qdev.c | 8 +-
74
hw/arm/mps2-tz: Set MachineClass default_ram info from RAMInfo data
101
hw/core/split-irq.c | 89 +++++
75
hw/arm/mps2-tz: Support ROMs as well as RAMs
102
hw/misc/iotkit-secctl.c | 704 +++++++++++++++++++++++++++++++++++++
76
hw/arm/mps2-tz: Get armv7m_load_kernel() size argument from RAMInfo
103
hw/misc/mps2-fpgaio.c | 176 ++++++++++
77
hw/arm/mps2-tz: Add new mps3-an524 board
104
hw/misc/tz-ppc.c | 302 ++++++++++++++++
78
hw/arm/mps2-tz: Stub out USB controller for mps3-an524
105
hw/misc/unimp.c | 10 -
79
hw/arm/mps2-tz: Provide PL031 RTC on mps3-an524
106
hw/timer/xlnx-zynqmp-rtc.c | 272 ++++++++++++++
80
docs/system/arm/mps2.rst: Document the new mps3-an524 board
107
linux-user/elfload.c | 2 +
81
hw/arm/mps2: Update old infocenter.arm.com URLs
108
target/arm/cpu.c | 66 +++-
109
target/arm/cpu64.c | 2 +
110
target/arm/helper.c | 28 +-
111
target/arm/translate-a64.c | 514 +++++++++++++++++++++------
112
target/arm/translate.c | 275 +++++++++++++--
113
target/arm/vec_helper.c | 429 ++++++++++++++++++++++
114
default-configs/arm-softmmu.mak | 5 +
115
hw/misc/trace-events | 24 ++
116
hw/timer/trace-events | 3 +
117
scripts/decodetree.py | 5 +-
118
45 files changed, 4668 insertions(+), 200 deletions(-)
119
create mode 100644 include/hw/arm/iotkit.h
120
create mode 100644 include/hw/core/split-irq.h
121
create mode 100644 include/hw/misc/iotkit-secctl.h
122
create mode 100644 include/hw/misc/mps2-fpgaio.h
123
create mode 100644 include/hw/misc/tz-ppc.h
124
create mode 100644 include/hw/timer/xlnx-zynqmp-rtc.h
125
create mode 100644 target/arm/idau.h
126
create mode 100644 hw/arm/iotkit.c
127
create mode 100644 hw/arm/mps2-tz.c
128
create mode 100644 hw/core/split-irq.c
129
create mode 100644 hw/misc/iotkit-secctl.c
130
create mode 100644 hw/misc/mps2-fpgaio.c
131
create mode 100644 hw/misc/tz-ppc.c
132
create mode 100644 hw/timer/xlnx-zynqmp-rtc.c
133
create mode 100644 target/arm/vec_helper.c
134
82
83
Philippe Mathieu-Daudé (4):
84
hw/arm/xlnx-zynqmp: Remove obsolete 'has_rpu' property
85
hw/i2c/npcm7xx_smbus: Simplify npcm7xx_smbus_init()
86
target/arm: Restrict v8M IDAU to TCG
87
target/arm/cpu: Update coding style to make checkpatch.pl happy
88
89
Rebecca Cran (3):
90
target/arm: Add support for FEAT_SSBS, Speculative Store Bypass Safe
91
target/arm: Enable FEAT_SSBS for "max" AARCH64 CPU
92
target/arm: Set ID_PFR2.SSBS to 1 for "max" 32-bit CPU
93
94
Richard Henderson (1):
95
target/arm: Speed up aarch64 TBL/TBX
96
97
schspa (1):
98
virtio-mmio: improve virtio-mmio get_dev_path alog
99
100
docs/system/arm/mps2.rst | 24 +-
101
docs/system/arm/nuvoton.rst | 3 +-
102
hw/display/omap_lcd_template.h | 169 --------
103
hw/display/tc6393xb_template.h | 72 ----
104
include/hw/arm/armsse.h | 4 +-
105
include/hw/arm/npcm7xx.h | 2 +
106
include/hw/arm/xlnx-zynqmp.h | 2 -
107
include/hw/misc/armsse-cpuid.h | 2 +-
108
include/hw/misc/armsse-mhu.h | 2 +-
109
include/hw/misc/iotkit-secctl.h | 2 +-
110
include/hw/misc/iotkit-sysctl.h | 2 +-
111
include/hw/misc/iotkit-sysinfo.h | 2 +-
112
include/hw/misc/mps2-fpgaio.h | 8 +-
113
include/hw/misc/mps2-scc.h | 10 +-
114
include/hw/net/npcm7xx_emc.h | 286 +++++++++++++
115
include/ui/console.h | 10 -
116
target/arm/cpu.h | 15 +-
117
target/arm/helper-a64.h | 2 +-
118
target/arm/internals.h | 6 +
119
hw/arm/mps2-tz.c | 632 +++++++++++++++++++++++-----
120
hw/arm/mps2.c | 5 +
121
hw/arm/musicpal.c | 64 ++-
122
hw/arm/npcm7xx.c | 50 ++-
123
hw/arm/sbsa-ref.c | 2 +-
124
hw/arm/xlnx-zynqmp.c | 6 -
125
hw/display/omap_lcdc.c | 129 +++++-
126
hw/display/tc6393xb.c | 48 +--
127
hw/display/tcx.c | 31 +-
128
hw/i2c/npcm7xx_smbus.c | 1 -
129
hw/misc/armsse-cpuid.c | 2 +-
130
hw/misc/armsse-mhu.c | 2 +-
131
hw/misc/iotkit-sysctl.c | 2 +-
132
hw/misc/iotkit-sysinfo.c | 2 +-
133
hw/misc/mps2-fpgaio.c | 43 +-
134
hw/misc/mps2-scc.c | 93 ++++-
135
hw/net/npcm7xx_emc.c | 857 ++++++++++++++++++++++++++++++++++++++
136
hw/virtio/virtio-mmio.c | 13 +-
137
target/arm/cpu.c | 23 +-
138
target/arm/cpu64.c | 5 +
139
target/arm/cpu_tcg.c | 8 +
140
target/arm/helper-a64.c | 32 --
141
target/arm/helper.c | 39 +-
142
target/arm/mte_helper.c | 13 +-
143
target/arm/translate-a64.c | 70 +---
144
target/arm/vec_helper.c | 48 +++
145
tests/qtest/npcm7xx_emc-test.c | 862 +++++++++++++++++++++++++++++++++++++++
146
hw/net/meson.build | 1 +
147
hw/net/trace-events | 17 +
148
tests/qtest/meson.build | 3 +-
149
49 files changed, 3098 insertions(+), 628 deletions(-)
150
delete mode 100644 hw/display/omap_lcd_template.h
151
delete mode 100644 hw/display/tc6393xb_template.h
152
create mode 100644 include/hw/net/npcm7xx_emc.h
153
create mode 100644 hw/net/npcm7xx_emc.c
154
create mode 100644 tests/qtest/npcm7xx_emc-test.c
155
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
2
2
3
Not enabled anywhere yet.
3
Cortex-A53 supports 40bits of address space. sbsa-ref's memory starts
4
above this limit.
4
5
5
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
6
Signed-off-by: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
6
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Message-id: 20180228193125.20577-11-richard.henderson@linaro.org
8
Acked-by: Leif Lindholm <leif@nuviainc.com>
9
Message-id: 20210216150122.3830863-2-marcin.juszkiewicz@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
target/arm/cpu.h | 1 +
12
hw/arm/sbsa-ref.c | 1 -
11
linux-user/elfload.c | 1 +
13
1 file changed, 1 deletion(-)
12
2 files changed, 2 insertions(+)
13
14
14
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
15
diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
15
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
16
--- a/target/arm/cpu.h
17
--- a/hw/arm/sbsa-ref.c
17
+++ b/target/arm/cpu.h
18
+++ b/hw/arm/sbsa-ref.c
18
@@ -XXX,XX +XXX,XX @@ enum arm_features {
19
@@ -XXX,XX +XXX,XX @@ static const int sbsa_ref_irqmap[] = {
19
ARM_FEATURE_V8_SM4, /* implements SM4 part of v8 Crypto Extensions */
20
ARM_FEATURE_V8_RDM, /* implements v8.1 simd round multiply */
21
ARM_FEATURE_V8_FP16, /* implements v8.2 half-precision float */
22
+ ARM_FEATURE_V8_FCMA, /* has complex number part of v8.3 extensions. */
23
};
20
};
24
21
25
static inline int arm_feature(CPUARMState *env, int feature)
22
static const char * const valid_cpus[] = {
26
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
23
- ARM_CPU_TYPE_NAME("cortex-a53"),
27
index XXXXXXX..XXXXXXX 100644
24
ARM_CPU_TYPE_NAME("cortex-a57"),
28
--- a/linux-user/elfload.c
25
ARM_CPU_TYPE_NAME("cortex-a72"),
29
+++ b/linux-user/elfload.c
26
};
30
@@ -XXX,XX +XXX,XX @@ static uint32_t get_elf_hwcap(void)
31
GET_FEATURE(ARM_FEATURE_V8_FP16,
32
ARM_HWCAP_A64_FPHP | ARM_HWCAP_A64_ASIMDHP);
33
GET_FEATURE(ARM_FEATURE_V8_RDM, ARM_HWCAP_A64_ASIMDRDM);
34
+ GET_FEATURE(ARM_FEATURE_V8_FCMA, ARM_HWCAP_A64_FCMA);
35
#undef GET_FEATURE
36
37
return hwcaps;
38
--
27
--
39
2.16.2
28
2.20.1
40
29
41
30
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
2
2
3
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
3
Let add 'max' cpu while work goes on adding newer CPU types than
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
4
Cortex-A72. This allows us to check SVE etc support.
5
Message-id: 20180228193125.20577-8-richard.henderson@linaro.org
5
6
Signed-off-by: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
7
Acked-by: Leif Lindholm <leif@nuviainc.com>
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Message-id: 20210216150122.3830863-3-marcin.juszkiewicz@linaro.org
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
---
11
---
8
target/arm/translate.c | 86 +++++++++++++++++++++++++++++++++++++++-----------
12
hw/arm/sbsa-ref.c | 1 +
9
1 file changed, 67 insertions(+), 19 deletions(-)
13
1 file changed, 1 insertion(+)
10
14
11
diff --git a/target/arm/translate.c b/target/arm/translate.c
15
diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
12
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
13
--- a/target/arm/translate.c
17
--- a/hw/arm/sbsa-ref.c
14
+++ b/target/arm/translate.c
18
+++ b/hw/arm/sbsa-ref.c
15
@@ -XXX,XX +XXX,XX @@
19
@@ -XXX,XX +XXX,XX @@ static const int sbsa_ref_irqmap[] = {
16
#include "disas/disas.h"
20
static const char * const valid_cpus[] = {
17
#include "exec/exec-all.h"
21
ARM_CPU_TYPE_NAME("cortex-a57"),
18
#include "tcg-op.h"
22
ARM_CPU_TYPE_NAME("cortex-a72"),
19
+#include "tcg-op-gvec.h"
23
+ ARM_CPU_TYPE_NAME("max"),
20
#include "qemu/log.h"
21
#include "qemu/bitops.h"
22
#include "arm_ldst.h"
23
@@ -XXX,XX +XXX,XX @@ static void gen_neon_narrow_op(int op, int u, int size,
24
#define NEON_3R_VPMAX 20
25
#define NEON_3R_VPMIN 21
26
#define NEON_3R_VQDMULH_VQRDMULH 22
27
-#define NEON_3R_VPADD 23
28
+#define NEON_3R_VPADD_VQRDMLAH 23
29
#define NEON_3R_SHA 24 /* SHA1C,SHA1P,SHA1M,SHA1SU0,SHA256H{2},SHA256SU1 */
30
-#define NEON_3R_VFM 25 /* VFMA, VFMS : float fused multiply-add */
31
+#define NEON_3R_VFM_VQRDMLSH 25 /* VFMA, VFMS, VQRDMLSH */
32
#define NEON_3R_FLOAT_ARITH 26 /* float VADD, VSUB, VPADD, VABD */
33
#define NEON_3R_FLOAT_MULTIPLY 27 /* float VMLA, VMLS, VMUL */
34
#define NEON_3R_FLOAT_CMP 28 /* float VCEQ, VCGE, VCGT */
35
@@ -XXX,XX +XXX,XX @@ static const uint8_t neon_3r_sizes[] = {
36
[NEON_3R_VPMAX] = 0x7,
37
[NEON_3R_VPMIN] = 0x7,
38
[NEON_3R_VQDMULH_VQRDMULH] = 0x6,
39
- [NEON_3R_VPADD] = 0x7,
40
+ [NEON_3R_VPADD_VQRDMLAH] = 0x7,
41
[NEON_3R_SHA] = 0xf, /* size field encodes op type */
42
- [NEON_3R_VFM] = 0x5, /* size bit 1 encodes op */
43
+ [NEON_3R_VFM_VQRDMLSH] = 0x7, /* For VFM, size bit 1 encodes op */
44
[NEON_3R_FLOAT_ARITH] = 0x5, /* size bit 1 encodes op */
45
[NEON_3R_FLOAT_MULTIPLY] = 0x5, /* size bit 1 encodes op */
46
[NEON_3R_FLOAT_CMP] = 0x5, /* size bit 1 encodes op */
47
@@ -XXX,XX +XXX,XX @@ static const uint8_t neon_2rm_sizes[] = {
48
[NEON_2RM_VCVT_UF] = 0x4,
49
};
24
};
50
25
51
+
26
static bool cpu_type_valid(const char *cpu)
52
+/* Expand v8.1 simd helper. */
53
+static int do_v81_helper(DisasContext *s, gen_helper_gvec_3_ptr *fn,
54
+ int q, int rd, int rn, int rm)
55
+{
56
+ if (arm_dc_feature(s, ARM_FEATURE_V8_RDM)) {
57
+ int opr_sz = (1 + q) * 8;
58
+ tcg_gen_gvec_3_ptr(vfp_reg_offset(1, rd),
59
+ vfp_reg_offset(1, rn),
60
+ vfp_reg_offset(1, rm), cpu_env,
61
+ opr_sz, opr_sz, 0, fn);
62
+ return 0;
63
+ }
64
+ return 1;
65
+}
66
+
67
/* Translate a NEON data processing instruction. Return nonzero if the
68
instruction is invalid.
69
We process data in a mixture of 32-bit and 64-bit chunks.
70
@@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn)
71
if (q && ((rd | rn | rm) & 1)) {
72
return 1;
73
}
74
- /*
75
- * The SHA-1/SHA-256 3-register instructions require special treatment
76
- * here, as their size field is overloaded as an op type selector, and
77
- * they all consume their input in a single pass.
78
- */
79
- if (op == NEON_3R_SHA) {
80
+ switch (op) {
81
+ case NEON_3R_SHA:
82
+ /* The SHA-1/SHA-256 3-register instructions require special
83
+ * treatment here, as their size field is overloaded as an
84
+ * op type selector, and they all consume their input in a
85
+ * single pass.
86
+ */
87
if (!q) {
88
return 1;
89
}
90
@@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn)
91
tcg_temp_free_ptr(ptr2);
92
tcg_temp_free_ptr(ptr3);
93
return 0;
94
+
95
+ case NEON_3R_VPADD_VQRDMLAH:
96
+ if (!u) {
97
+ break; /* VPADD */
98
+ }
99
+ /* VQRDMLAH */
100
+ switch (size) {
101
+ case 1:
102
+ return do_v81_helper(s, gen_helper_gvec_qrdmlah_s16,
103
+ q, rd, rn, rm);
104
+ case 2:
105
+ return do_v81_helper(s, gen_helper_gvec_qrdmlah_s32,
106
+ q, rd, rn, rm);
107
+ }
108
+ return 1;
109
+
110
+ case NEON_3R_VFM_VQRDMLSH:
111
+ if (!u) {
112
+ /* VFM, VFMS */
113
+ if (size == 1) {
114
+ return 1;
115
+ }
116
+ break;
117
+ }
118
+ /* VQRDMLSH */
119
+ switch (size) {
120
+ case 1:
121
+ return do_v81_helper(s, gen_helper_gvec_qrdmlsh_s16,
122
+ q, rd, rn, rm);
123
+ case 2:
124
+ return do_v81_helper(s, gen_helper_gvec_qrdmlsh_s32,
125
+ q, rd, rn, rm);
126
+ }
127
+ return 1;
128
}
129
if (size == 3 && op != NEON_3R_LOGIC) {
130
/* 64-bit element instructions. */
131
@@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn)
132
rm = rtmp;
133
}
134
break;
135
- case NEON_3R_VPADD:
136
- if (u) {
137
- return 1;
138
- }
139
- /* Fall through */
140
+ case NEON_3R_VPADD_VQRDMLAH:
141
case NEON_3R_VPMAX:
142
case NEON_3R_VPMIN:
143
pairwise = 1;
144
@@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn)
145
return 1;
146
}
147
break;
148
- case NEON_3R_VFM:
149
- if (!arm_dc_feature(s, ARM_FEATURE_VFP4) || u) {
150
+ case NEON_3R_VFM_VQRDMLSH:
151
+ if (!arm_dc_feature(s, ARM_FEATURE_VFP4)) {
152
return 1;
153
}
154
break;
155
@@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn)
156
}
157
}
158
break;
159
- case NEON_3R_VPADD:
160
+ case NEON_3R_VPADD_VQRDMLAH:
161
switch (size) {
162
case 0: gen_helper_neon_padd_u8(tmp, tmp, tmp2); break;
163
case 1: gen_helper_neon_padd_u16(tmp, tmp, tmp2); break;
164
@@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn)
165
}
166
}
167
break;
168
- case NEON_3R_VFM:
169
+ case NEON_3R_VFM_VQRDMLSH:
170
{
171
/* VFMA, VFMS: fused multiply-add */
172
TCGv_ptr fpstatus = get_fpstatus_ptr(1);
173
--
27
--
174
2.16.2
28
2.20.1
175
29
176
30
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Rebecca Cran <rebecca@nuviainc.com>
2
2
3
Not enabled anywhere yet.
3
Add support for FEAT_SSBS. SSBS (Speculative Store Bypass Safe) is an
4
optional feature in ARMv8.0, and mandatory in ARMv8.5.
4
5
5
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
6
Signed-off-by: Rebecca Cran <rebecca@nuviainc.com>
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20210216224543.16142-2-rebecca@nuviainc.com
8
Message-id: 20180228193125.20577-2-richard.henderson@linaro.org
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
10
---
11
target/arm/cpu.h | 1 +
11
target/arm/cpu.h | 15 ++++++++++++++-
12
linux-user/elfload.c | 1 +
12
target/arm/internals.h | 6 ++++++
13
2 files changed, 2 insertions(+)
13
target/arm/helper.c | 37 +++++++++++++++++++++++++++++++++++++
14
target/arm/translate-a64.c | 12 ++++++++++++
15
4 files changed, 69 insertions(+), 1 deletion(-)
14
16
15
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
17
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
16
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
17
--- a/target/arm/cpu.h
19
--- a/target/arm/cpu.h
18
+++ b/target/arm/cpu.h
20
+++ b/target/arm/cpu.h
19
@@ -XXX,XX +XXX,XX @@ enum arm_features {
21
@@ -XXX,XX +XXX,XX @@ void pmu_init(ARMCPU *cpu);
20
ARM_FEATURE_V8_SHA3, /* implements SHA3 part of v8 Crypto Extensions */
22
#define SCTLR_TE (1U << 30) /* AArch32 only */
21
ARM_FEATURE_V8_SM3, /* implements SM3 part of v8 Crypto Extensions */
23
#define SCTLR_EnIB (1U << 30) /* v8.3, AArch64 only */
22
ARM_FEATURE_V8_SM4, /* implements SM4 part of v8 Crypto Extensions */
24
#define SCTLR_EnIA (1U << 31) /* v8.3, AArch64 only */
23
+ ARM_FEATURE_V8_RDM, /* implements v8.1 simd round multiply */
25
+#define SCTLR_DSSBS_32 (1U << 31) /* v8.5, AArch32 only */
24
ARM_FEATURE_V8_FP16, /* implements v8.2 half-precision float */
26
#define SCTLR_BT0 (1ULL << 35) /* v8.5-BTI */
27
#define SCTLR_BT1 (1ULL << 36) /* v8.5-BTI */
28
#define SCTLR_ITFSB (1ULL << 37) /* v8.5-MemTag */
29
@@ -XXX,XX +XXX,XX @@ void pmu_init(ARMCPU *cpu);
30
#define SCTLR_TCF (3ULL << 40) /* v8.5-MemTag */
31
#define SCTLR_ATA0 (1ULL << 42) /* v8.5-MemTag */
32
#define SCTLR_ATA (1ULL << 43) /* v8.5-MemTag */
33
-#define SCTLR_DSSBS (1ULL << 44) /* v8.5 */
34
+#define SCTLR_DSSBS_64 (1ULL << 44) /* v8.5, AArch64 only */
35
36
#define CPTR_TCPAC (1U << 31)
37
#define CPTR_TTA (1U << 20)
38
@@ -XXX,XX +XXX,XX @@ void pmu_init(ARMCPU *cpu);
39
#define CPSR_IL (1U << 20)
40
#define CPSR_DIT (1U << 21)
41
#define CPSR_PAN (1U << 22)
42
+#define CPSR_SSBS (1U << 23)
43
#define CPSR_J (1U << 24)
44
#define CPSR_IT_0_1 (3U << 25)
45
#define CPSR_Q (1U << 27)
46
@@ -XXX,XX +XXX,XX @@ void pmu_init(ARMCPU *cpu);
47
#define PSTATE_A (1U << 8)
48
#define PSTATE_D (1U << 9)
49
#define PSTATE_BTYPE (3U << 10)
50
+#define PSTATE_SSBS (1U << 12)
51
#define PSTATE_IL (1U << 20)
52
#define PSTATE_SS (1U << 21)
53
#define PSTATE_PAN (1U << 22)
54
@@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa32_dit(const ARMISARegisters *id)
55
return FIELD_EX32(id->id_pfr0, ID_PFR0, DIT) != 0;
56
}
57
58
+static inline bool isar_feature_aa32_ssbs(const ARMISARegisters *id)
59
+{
60
+ return FIELD_EX32(id->id_pfr2, ID_PFR2, SSBS) != 0;
61
+}
62
+
63
/*
64
* 64-bit feature tests via id registers.
65
*/
66
@@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_dit(const ARMISARegisters *id)
67
return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, DIT) != 0;
68
}
69
70
+static inline bool isar_feature_aa64_ssbs(const ARMISARegisters *id)
71
+{
72
+ return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, SSBS) != 0;
73
+}
74
+
75
/*
76
* Feature tests for "does this exist in either 32-bit or 64-bit?"
77
*/
78
diff --git a/target/arm/internals.h b/target/arm/internals.h
79
index XXXXXXX..XXXXXXX 100644
80
--- a/target/arm/internals.h
81
+++ b/target/arm/internals.h
82
@@ -XXX,XX +XXX,XX @@ static inline uint32_t aarch32_cpsr_valid_mask(uint64_t features,
83
if (isar_feature_aa32_dit(id)) {
84
valid |= CPSR_DIT;
85
}
86
+ if (isar_feature_aa32_ssbs(id)) {
87
+ valid |= CPSR_SSBS;
88
+ }
89
90
return valid;
91
}
92
@@ -XXX,XX +XXX,XX @@ static inline uint32_t aarch64_pstate_valid_mask(const ARMISARegisters *id)
93
if (isar_feature_aa64_dit(id)) {
94
valid |= PSTATE_DIT;
95
}
96
+ if (isar_feature_aa64_ssbs(id)) {
97
+ valid |= PSTATE_SSBS;
98
+ }
99
if (isar_feature_aa64_mte(id)) {
100
valid |= PSTATE_TCO;
101
}
102
diff --git a/target/arm/helper.c b/target/arm/helper.c
103
index XXXXXXX..XXXXXXX 100644
104
--- a/target/arm/helper.c
105
+++ b/target/arm/helper.c
106
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo dit_reginfo = {
107
.readfn = aa64_dit_read, .writefn = aa64_dit_write
25
};
108
};
26
109
27
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
110
+static uint64_t aa64_ssbs_read(CPUARMState *env, const ARMCPRegInfo *ri)
111
+{
112
+ return env->pstate & PSTATE_SSBS;
113
+}
114
+
115
+static void aa64_ssbs_write(CPUARMState *env, const ARMCPRegInfo *ri,
116
+ uint64_t value)
117
+{
118
+ env->pstate = (env->pstate & ~PSTATE_SSBS) | (value & PSTATE_SSBS);
119
+}
120
+
121
+static const ARMCPRegInfo ssbs_reginfo = {
122
+ .name = "SSBS", .state = ARM_CP_STATE_AA64,
123
+ .opc0 = 3, .opc1 = 3, .crn = 4, .crm = 2, .opc2 = 6,
124
+ .type = ARM_CP_NO_RAW, .access = PL0_RW,
125
+ .readfn = aa64_ssbs_read, .writefn = aa64_ssbs_write
126
+};
127
+
128
static CPAccessResult aa64_cacheop_poc_access(CPUARMState *env,
129
const ARMCPRegInfo *ri,
130
bool isread)
131
@@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu)
132
if (cpu_isar_feature(aa64_dit, cpu)) {
133
define_one_arm_cp_reg(cpu, &dit_reginfo);
134
}
135
+ if (cpu_isar_feature(aa64_ssbs, cpu)) {
136
+ define_one_arm_cp_reg(cpu, &ssbs_reginfo);
137
+ }
138
139
if (arm_feature(env, ARM_FEATURE_EL2) && cpu_isar_feature(aa64_vh, cpu)) {
140
define_arm_cp_regs(cpu, vhe_reginfo);
141
@@ -XXX,XX +XXX,XX @@ static void take_aarch32_exception(CPUARMState *env, int new_mode,
142
env->uncached_cpsr &= ~(CPSR_IL | CPSR_J);
143
env->daif |= mask;
144
145
+ if (cpu_isar_feature(aa32_ssbs, env_archcpu(env))) {
146
+ if (env->cp15.sctlr_el[new_el] & SCTLR_DSSBS_32) {
147
+ env->uncached_cpsr |= CPSR_SSBS;
148
+ } else {
149
+ env->uncached_cpsr &= ~CPSR_SSBS;
150
+ }
151
+ }
152
+
153
if (new_mode == ARM_CPU_MODE_HYP) {
154
env->thumb = (env->cp15.sctlr_el[2] & SCTLR_TE) != 0;
155
env->elr_el[2] = env->regs[15];
156
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_do_interrupt_aarch64(CPUState *cs)
157
new_mode |= PSTATE_TCO;
158
}
159
160
+ if (cpu_isar_feature(aa64_ssbs, cpu)) {
161
+ if (env->cp15.sctlr_el[new_el] & SCTLR_DSSBS_64) {
162
+ new_mode |= PSTATE_SSBS;
163
+ } else {
164
+ new_mode &= ~PSTATE_SSBS;
165
+ }
166
+ }
167
+
168
pstate_write(env, PSTATE_DAIF | new_mode);
169
env->aarch64 = 1;
170
aarch64_restore_sp(env, new_el);
171
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
28
index XXXXXXX..XXXXXXX 100644
172
index XXXXXXX..XXXXXXX 100644
29
--- a/linux-user/elfload.c
173
--- a/target/arm/translate-a64.c
30
+++ b/linux-user/elfload.c
174
+++ b/target/arm/translate-a64.c
31
@@ -XXX,XX +XXX,XX @@ static uint32_t get_elf_hwcap(void)
175
@@ -XXX,XX +XXX,XX @@ static void handle_msr_i(DisasContext *s, uint32_t insn,
32
GET_FEATURE(ARM_FEATURE_V8_SHA512, ARM_HWCAP_A64_SHA512);
176
tcg_temp_free_i32(t1);
33
GET_FEATURE(ARM_FEATURE_V8_FP16,
177
break;
34
ARM_HWCAP_A64_FPHP | ARM_HWCAP_A64_ASIMDHP);
178
35
+ GET_FEATURE(ARM_FEATURE_V8_RDM, ARM_HWCAP_A64_ASIMDRDM);
179
+ case 0x19: /* SSBS */
36
#undef GET_FEATURE
180
+ if (!dc_isar_feature(aa64_ssbs, s)) {
37
181
+ goto do_unallocated;
38
return hwcaps;
182
+ }
183
+ if (crm & 1) {
184
+ set_pstate_bits(PSTATE_SSBS);
185
+ } else {
186
+ clear_pstate_bits(PSTATE_SSBS);
187
+ }
188
+ /* Don't need to rebuild hflags since SSBS is a nop */
189
+ break;
190
+
191
case 0x1a: /* DIT */
192
if (!dc_isar_feature(aa64_dit, s)) {
193
goto do_unallocated;
39
--
194
--
40
2.16.2
195
2.20.1
41
196
42
197
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Rebecca Cran <rebecca@nuviainc.com>
2
2
3
Enable it for the "any" CPU used by *-linux-user.
3
Set ID_AA64PFR1_EL1.SSBS to 2 and ID_PFR2.SSBS to 1.
4
4
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
Signed-off-by: Rebecca Cran <rebecca@nuviainc.com>
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20180228193125.20577-10-richard.henderson@linaro.org
7
Message-id: 20210216224543.16142-3-rebecca@nuviainc.com
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
9
---
10
target/arm/cpu.c | 1 +
10
target/arm/cpu64.c | 5 +++++
11
target/arm/cpu64.c | 1 +
11
1 file changed, 5 insertions(+)
12
2 files changed, 2 insertions(+)
13
12
14
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/target/arm/cpu.c
17
+++ b/target/arm/cpu.c
18
@@ -XXX,XX +XXX,XX @@ static void arm_any_initfn(Object *obj)
19
set_feature(&cpu->env, ARM_FEATURE_V8_SHA256);
20
set_feature(&cpu->env, ARM_FEATURE_V8_PMULL);
21
set_feature(&cpu->env, ARM_FEATURE_CRC);
22
+ set_feature(&cpu->env, ARM_FEATURE_V8_RDM);
23
cpu->midr = 0xffffffff;
24
}
25
#endif
26
diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
13
diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
27
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
28
--- a/target/arm/cpu64.c
15
--- a/target/arm/cpu64.c
29
+++ b/target/arm/cpu64.c
16
+++ b/target/arm/cpu64.c
30
@@ -XXX,XX +XXX,XX @@ static void aarch64_any_initfn(Object *obj)
17
@@ -XXX,XX +XXX,XX @@ static void aarch64_max_initfn(Object *obj)
31
set_feature(&cpu->env, ARM_FEATURE_V8_SM4);
18
32
set_feature(&cpu->env, ARM_FEATURE_V8_PMULL);
19
t = cpu->isar.id_aa64pfr1;
33
set_feature(&cpu->env, ARM_FEATURE_CRC);
20
t = FIELD_DP64(t, ID_AA64PFR1, BT, 1);
34
+ set_feature(&cpu->env, ARM_FEATURE_V8_RDM);
21
+ t = FIELD_DP64(t, ID_AA64PFR1, SSBS, 2);
35
set_feature(&cpu->env, ARM_FEATURE_V8_FP16);
22
/*
36
cpu->ctr = 0x80038003; /* 32 byte I and D cacheline size, VIPT icache */
23
* Begin with full support for MTE. This will be downgraded to MTE=0
37
cpu->dcz_blocksize = 7; /* 512 bytes */
24
* during realize if the board provides no tag memory, much like
25
@@ -XXX,XX +XXX,XX @@ static void aarch64_max_initfn(Object *obj)
26
u = FIELD_DP32(u, ID_PFR0, DIT, 1);
27
cpu->isar.id_pfr0 = u;
28
29
+ u = cpu->isar.id_pfr2;
30
+ u = FIELD_DP32(u, ID_PFR2, SSBS, 1);
31
+ cpu->isar.id_pfr2 = u;
32
+
33
u = cpu->isar.id_mmfr3;
34
u = FIELD_DP32(u, ID_MMFR3, PAN, 2); /* ATS1E1 */
35
cpu->isar.id_mmfr3 = u;
38
--
36
--
39
2.16.2
37
2.20.1
40
38
41
39
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Rebecca Cran <rebecca@nuviainc.com>
2
2
3
Enable it for the "any" CPU used by *-linux-user.
3
Enable FEAT_SSBS for the "max" 32-bit CPU.
4
4
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
Signed-off-by: Rebecca Cran <rebecca@nuviainc.com>
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20180228193125.20577-17-richard.henderson@linaro.org
7
Message-id: 20210216224543.16142-4-rebecca@nuviainc.com
8
[PMM: fix typo causing compilation failure]
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
10
---
10
target/arm/cpu.c | 1 +
11
target/arm/cpu.c | 4 ++++
11
target/arm/cpu64.c | 1 +
12
1 file changed, 4 insertions(+)
12
2 files changed, 2 insertions(+)
13
13
14
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
14
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
15
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
16
--- a/target/arm/cpu.c
16
--- a/target/arm/cpu.c
17
+++ b/target/arm/cpu.c
17
+++ b/target/arm/cpu.c
18
@@ -XXX,XX +XXX,XX @@ static void arm_any_initfn(Object *obj)
18
@@ -XXX,XX +XXX,XX @@ static void arm_max_initfn(Object *obj)
19
set_feature(&cpu->env, ARM_FEATURE_V8_PMULL);
19
t = cpu->isar.id_pfr0;
20
set_feature(&cpu->env, ARM_FEATURE_CRC);
20
t = FIELD_DP32(t, ID_PFR0, DIT, 1);
21
set_feature(&cpu->env, ARM_FEATURE_V8_RDM);
21
cpu->isar.id_pfr0 = t;
22
+ set_feature(&cpu->env, ARM_FEATURE_V8_FCMA);
22
+
23
cpu->midr = 0xffffffff;
23
+ t = cpu->isar.id_pfr2;
24
}
24
+ t = FIELD_DP32(t, ID_PFR2, SSBS, 1);
25
+ cpu->isar.id_pfr2 = t;
26
}
25
#endif
27
#endif
26
diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
27
index XXXXXXX..XXXXXXX 100644
28
--- a/target/arm/cpu64.c
29
+++ b/target/arm/cpu64.c
30
@@ -XXX,XX +XXX,XX @@ static void aarch64_any_initfn(Object *obj)
31
set_feature(&cpu->env, ARM_FEATURE_CRC);
32
set_feature(&cpu->env, ARM_FEATURE_V8_RDM);
33
set_feature(&cpu->env, ARM_FEATURE_V8_FP16);
34
+ set_feature(&cpu->env, ARM_FEATURE_V8_FCMA);
35
cpu->ctr = 0x80038003; /* 32 byte I and D cacheline size, VIPT icache */
36
cpu->dcz_blocksize = 7; /* 512 bytes */
37
}
28
}
38
--
29
--
39
2.16.2
30
2.20.1
40
31
41
32
diff view generated by jsdifflib
1
From: Alistair Francis <alistair.francis@xilinx.com>
1
From: Doug Evans <dje@google.com>
2
2
3
Initial commit of the ZynqMP RTC device.
3
This is a 10/100 ethernet device that has several features.
4
Only the ones needed by the Linux driver have been implemented.
5
See npcm7xx_emc.c for a list of unimplemented features.
4
6
5
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
7
Reviewed-by: Hao Wu <wuhaotsh@google.com>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Reviewed-by: Avi Fishman <avi.fishman@nuvoton.com>
9
Signed-off-by: Doug Evans <dje@google.com>
10
Message-id: 20210218212453.831406-2-dje@google.com
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
---
12
---
9
hw/timer/Makefile.objs | 1 +
13
include/hw/net/npcm7xx_emc.h | 286 ++++++++++++
10
include/hw/timer/xlnx-zynqmp-rtc.h | 84 +++++++++++++++
14
hw/net/npcm7xx_emc.c | 857 +++++++++++++++++++++++++++++++++++
11
hw/timer/xlnx-zynqmp-rtc.c | 214 +++++++++++++++++++++++++++++++++++++
15
hw/net/meson.build | 1 +
12
3 files changed, 299 insertions(+)
16
hw/net/trace-events | 17 +
13
create mode 100644 include/hw/timer/xlnx-zynqmp-rtc.h
17
4 files changed, 1161 insertions(+)
14
create mode 100644 hw/timer/xlnx-zynqmp-rtc.c
18
create mode 100644 include/hw/net/npcm7xx_emc.h
19
create mode 100644 hw/net/npcm7xx_emc.c
15
20
16
diff --git a/hw/timer/Makefile.objs b/hw/timer/Makefile.objs
21
diff --git a/include/hw/net/npcm7xx_emc.h b/include/hw/net/npcm7xx_emc.h
17
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/timer/Makefile.objs
19
+++ b/hw/timer/Makefile.objs
20
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_IMX) += imx_epit.o
21
common-obj-$(CONFIG_IMX) += imx_gpt.o
22
common-obj-$(CONFIG_LM32) += lm32_timer.o
23
common-obj-$(CONFIG_MILKYMIST) += milkymist-sysctl.o
24
+common-obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-zynqmp-rtc.o
25
26
obj-$(CONFIG_ALTERA_TIMER) += altera_timer.o
27
obj-$(CONFIG_EXYNOS4) += exynos4210_mct.o
28
diff --git a/include/hw/timer/xlnx-zynqmp-rtc.h b/include/hw/timer/xlnx-zynqmp-rtc.h
29
new file mode 100644
22
new file mode 100644
30
index XXXXXXX..XXXXXXX
23
index XXXXXXX..XXXXXXX
31
--- /dev/null
24
--- /dev/null
32
+++ b/include/hw/timer/xlnx-zynqmp-rtc.h
25
+++ b/include/hw/net/npcm7xx_emc.h
33
@@ -XXX,XX +XXX,XX @@
26
@@ -XXX,XX +XXX,XX @@
34
+/*
27
+/*
35
+ * QEMU model of the Xilinx ZynqMP Real Time Clock (RTC).
28
+ * Nuvoton NPCM7xx EMC Module
36
+ *
29
+ *
37
+ * Copyright (c) 2017 Xilinx Inc.
30
+ * Copyright 2020 Google LLC
38
+ *
31
+ *
39
+ * Written-by: Alistair Francis <alistair.francis@xilinx.com>
32
+ * This program is free software; you can redistribute it and/or modify it
33
+ * under the terms of the GNU General Public License as published by the
34
+ * Free Software Foundation; either version 2 of the License, or
35
+ * (at your option) any later version.
40
+ *
36
+ *
41
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
37
+ * This program is distributed in the hope that it will be useful, but WITHOUT
42
+ * of this software and associated documentation files (the "Software"), to deal
38
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43
+ * in the Software without restriction, including without limitation the rights
39
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
44
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
40
+ * for more details.
45
+ * copies of the Software, and to permit persons to whom the Software is
46
+ * furnished to do so, subject to the following conditions:
47
+ *
48
+ * The above copyright notice and this permission notice shall be included in
49
+ * all copies or substantial portions of the Software.
50
+ *
51
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
52
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
53
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
54
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
55
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
56
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
57
+ * THE SOFTWARE.
58
+ */
41
+ */
59
+
42
+
60
+#include "hw/register.h"
43
+#ifndef NPCM7XX_EMC_H
61
+
44
+#define NPCM7XX_EMC_H
62
+#define TYPE_XLNX_ZYNQMP_RTC "xlnx-zynmp.rtc"
45
+
63
+
46
+#include "hw/irq.h"
64
+#define XLNX_ZYNQMP_RTC(obj) \
47
+#include "hw/sysbus.h"
65
+ OBJECT_CHECK(XlnxZynqMPRTC, (obj), TYPE_XLNX_ZYNQMP_RTC)
48
+#include "net/net.h"
66
+
49
+
67
+REG32(SET_TIME_WRITE, 0x0)
50
+/* 32-bit register indices. */
68
+REG32(SET_TIME_READ, 0x4)
51
+enum NPCM7xxPWMRegister {
69
+REG32(CALIB_WRITE, 0x8)
52
+ /* Control registers. */
70
+ FIELD(CALIB_WRITE, FRACTION_EN, 20, 1)
53
+ REG_CAMCMR,
71
+ FIELD(CALIB_WRITE, FRACTION_DATA, 16, 4)
54
+ REG_CAMEN,
72
+ FIELD(CALIB_WRITE, MAX_TICK, 0, 16)
55
+
73
+REG32(CALIB_READ, 0xc)
56
+ /* There are 16 CAMn[ML] registers. */
74
+ FIELD(CALIB_READ, FRACTION_EN, 20, 1)
57
+ REG_CAMM_BASE,
75
+ FIELD(CALIB_READ, FRACTION_DATA, 16, 4)
58
+ REG_CAML_BASE,
76
+ FIELD(CALIB_READ, MAX_TICK, 0, 16)
59
+ REG_CAMML_LAST = 0x21,
77
+REG32(CURRENT_TIME, 0x10)
60
+
78
+REG32(CURRENT_TICK, 0x14)
61
+ REG_TXDLSA = 0x22,
79
+ FIELD(CURRENT_TICK, VALUE, 0, 16)
62
+ REG_RXDLSA,
80
+REG32(ALARM, 0x18)
63
+ REG_MCMDR,
81
+REG32(RTC_INT_STATUS, 0x20)
64
+ REG_MIID,
82
+ FIELD(RTC_INT_STATUS, ALARM, 1, 1)
65
+ REG_MIIDA,
83
+ FIELD(RTC_INT_STATUS, SECONDS, 0, 1)
66
+ REG_FFTCR,
84
+REG32(RTC_INT_MASK, 0x24)
67
+ REG_TSDR,
85
+ FIELD(RTC_INT_MASK, ALARM, 1, 1)
68
+ REG_RSDR,
86
+ FIELD(RTC_INT_MASK, SECONDS, 0, 1)
69
+ REG_DMARFC,
87
+REG32(RTC_INT_EN, 0x28)
70
+ REG_MIEN,
88
+ FIELD(RTC_INT_EN, ALARM, 1, 1)
71
+
89
+ FIELD(RTC_INT_EN, SECONDS, 0, 1)
72
+ /* Status registers. */
90
+REG32(RTC_INT_DIS, 0x2c)
73
+ REG_MISTA,
91
+ FIELD(RTC_INT_DIS, ALARM, 1, 1)
74
+ REG_MGSTA,
92
+ FIELD(RTC_INT_DIS, SECONDS, 0, 1)
75
+ REG_MPCNT,
93
+REG32(ADDR_ERROR, 0x30)
76
+ REG_MRPC,
94
+ FIELD(ADDR_ERROR, STATUS, 0, 1)
77
+ REG_MRPCC,
95
+REG32(ADDR_ERROR_INT_MASK, 0x34)
78
+ REG_MREPC,
96
+ FIELD(ADDR_ERROR_INT_MASK, MASK, 0, 1)
79
+ REG_DMARFS,
97
+REG32(ADDR_ERROR_INT_EN, 0x38)
80
+ REG_CTXDSA,
98
+ FIELD(ADDR_ERROR_INT_EN, MASK, 0, 1)
81
+ REG_CTXBSA,
99
+REG32(ADDR_ERROR_INT_DIS, 0x3c)
82
+ REG_CRXDSA,
100
+ FIELD(ADDR_ERROR_INT_DIS, MASK, 0, 1)
83
+ REG_CRXBSA,
101
+REG32(CONTROL, 0x40)
84
+
102
+ FIELD(CONTROL, BATTERY_DISABLE, 31, 1)
85
+ NPCM7XX_NUM_EMC_REGS,
103
+ FIELD(CONTROL, OSC_CNTRL, 24, 4)
86
+};
104
+ FIELD(CONTROL, SLVERR_ENABLE, 0, 1)
87
+
105
+REG32(SAFETY_CHK, 0x50)
88
+/* REG_CAMCMR fields */
106
+
89
+/* Enable CAM Compare */
107
+#define XLNX_ZYNQMP_RTC_R_MAX (R_SAFETY_CHK + 1)
90
+#define REG_CAMCMR_ECMP (1 << 4)
108
+
91
+/* Complement CAM Compare */
109
+typedef struct XlnxZynqMPRTC {
92
+#define REG_CAMCMR_CCAM (1 << 3)
110
+ SysBusDevice parent_obj;
93
+/* Accept Broadcast Packet */
94
+#define REG_CAMCMR_ABP (1 << 2)
95
+/* Accept Multicast Packet */
96
+#define REG_CAMCMR_AMP (1 << 1)
97
+/* Accept Unicast Packet */
98
+#define REG_CAMCMR_AUP (1 << 0)
99
+
100
+/* REG_MCMDR fields */
101
+/* Software Reset */
102
+#define REG_MCMDR_SWR (1 << 24)
103
+/* Internal Loopback Select */
104
+#define REG_MCMDR_LBK (1 << 21)
105
+/* Operation Mode Select */
106
+#define REG_MCMDR_OPMOD (1 << 20)
107
+/* Enable MDC Clock Generation */
108
+#define REG_MCMDR_ENMDC (1 << 19)
109
+/* Full-Duplex Mode Select */
110
+#define REG_MCMDR_FDUP (1 << 18)
111
+/* Enable SQE Checking */
112
+#define REG_MCMDR_ENSEQ (1 << 17)
113
+/* Send PAUSE Frame */
114
+#define REG_MCMDR_SDPZ (1 << 16)
115
+/* No Defer */
116
+#define REG_MCMDR_NDEF (1 << 9)
117
+/* Frame Transmission On */
118
+#define REG_MCMDR_TXON (1 << 8)
119
+/* Strip CRC Checksum */
120
+#define REG_MCMDR_SPCRC (1 << 5)
121
+/* Accept CRC Error Packet */
122
+#define REG_MCMDR_AEP (1 << 4)
123
+/* Accept Control Packet */
124
+#define REG_MCMDR_ACP (1 << 3)
125
+/* Accept Runt Packet */
126
+#define REG_MCMDR_ARP (1 << 2)
127
+/* Accept Long Packet */
128
+#define REG_MCMDR_ALP (1 << 1)
129
+/* Frame Reception On */
130
+#define REG_MCMDR_RXON (1 << 0)
131
+
132
+/* REG_MIEN fields */
133
+/* Enable Transmit Descriptor Unavailable Interrupt */
134
+#define REG_MIEN_ENTDU (1 << 23)
135
+/* Enable Transmit Completion Interrupt */
136
+#define REG_MIEN_ENTXCP (1 << 18)
137
+/* Enable Transmit Interrupt */
138
+#define REG_MIEN_ENTXINTR (1 << 16)
139
+/* Enable Receive Descriptor Unavailable Interrupt */
140
+#define REG_MIEN_ENRDU (1 << 10)
141
+/* Enable Receive Good Interrupt */
142
+#define REG_MIEN_ENRXGD (1 << 4)
143
+/* Enable Receive Interrupt */
144
+#define REG_MIEN_ENRXINTR (1 << 0)
145
+
146
+/* REG_MISTA fields */
147
+/* TODO: Add error fields and support simulated errors? */
148
+/* Transmit Bus Error Interrupt */
149
+#define REG_MISTA_TXBERR (1 << 24)
150
+/* Transmit Descriptor Unavailable Interrupt */
151
+#define REG_MISTA_TDU (1 << 23)
152
+/* Transmit Completion Interrupt */
153
+#define REG_MISTA_TXCP (1 << 18)
154
+/* Transmit Interrupt */
155
+#define REG_MISTA_TXINTR (1 << 16)
156
+/* Receive Bus Error Interrupt */
157
+#define REG_MISTA_RXBERR (1 << 11)
158
+/* Receive Descriptor Unavailable Interrupt */
159
+#define REG_MISTA_RDU (1 << 10)
160
+/* DMA Early Notification Interrupt */
161
+#define REG_MISTA_DENI (1 << 9)
162
+/* Maximum Frame Length Interrupt */
163
+#define REG_MISTA_DFOI (1 << 8)
164
+/* Receive Good Interrupt */
165
+#define REG_MISTA_RXGD (1 << 4)
166
+/* Packet Too Long Interrupt */
167
+#define REG_MISTA_PTLE (1 << 3)
168
+/* Receive Interrupt */
169
+#define REG_MISTA_RXINTR (1 << 0)
170
+
171
+/* REG_MGSTA fields */
172
+/* Transmission Halted */
173
+#define REG_MGSTA_TXHA (1 << 11)
174
+/* Receive Halted */
175
+#define REG_MGSTA_RXHA (1 << 11)
176
+
177
+/* REG_DMARFC fields */
178
+/* Maximum Receive Frame Length */
179
+#define REG_DMARFC_RXMS(word) extract32((word), 0, 16)
180
+
181
+/* REG MIIDA fields */
182
+/* Busy Bit */
183
+#define REG_MIIDA_BUSY (1 << 17)
184
+
185
+/* Transmit and receive descriptors */
186
+typedef struct NPCM7xxEMCTxDesc NPCM7xxEMCTxDesc;
187
+typedef struct NPCM7xxEMCRxDesc NPCM7xxEMCRxDesc;
188
+
189
+struct NPCM7xxEMCTxDesc {
190
+ uint32_t flags;
191
+ uint32_t txbsa;
192
+ uint32_t status_and_length;
193
+ uint32_t ntxdsa;
194
+};
195
+
196
+struct NPCM7xxEMCRxDesc {
197
+ uint32_t status_and_length;
198
+ uint32_t rxbsa;
199
+ uint32_t reserved;
200
+ uint32_t nrxdsa;
201
+};
202
+
203
+/* NPCM7xxEMCTxDesc.flags values */
204
+/* Owner: 0 = cpu, 1 = emc */
205
+#define TX_DESC_FLAG_OWNER_MASK (1 << 31)
206
+/* Transmit interrupt enable */
207
+#define TX_DESC_FLAG_INTEN (1 << 2)
208
+/* CRC append */
209
+#define TX_DESC_FLAG_CRCAPP (1 << 1)
210
+/* Padding enable */
211
+#define TX_DESC_FLAG_PADEN (1 << 0)
212
+
213
+/* NPCM7xxEMCTxDesc.status_and_length values */
214
+/* Collision count */
215
+#define TX_DESC_STATUS_CCNT_SHIFT 28
216
+#define TX_DESC_STATUS_CCNT_BITSIZE 4
217
+/* SQE error */
218
+#define TX_DESC_STATUS_SQE (1 << 26)
219
+/* Transmission paused */
220
+#define TX_DESC_STATUS_PAU (1 << 25)
221
+/* P transmission halted */
222
+#define TX_DESC_STATUS_TXHA (1 << 24)
223
+/* Late collision */
224
+#define TX_DESC_STATUS_LC (1 << 23)
225
+/* Transmission abort */
226
+#define TX_DESC_STATUS_TXABT (1 << 22)
227
+/* No carrier sense */
228
+#define TX_DESC_STATUS_NCS (1 << 21)
229
+/* Defer exceed */
230
+#define TX_DESC_STATUS_EXDEF (1 << 20)
231
+/* Transmission complete */
232
+#define TX_DESC_STATUS_TXCP (1 << 19)
233
+/* Transmission deferred */
234
+#define TX_DESC_STATUS_DEF (1 << 17)
235
+/* Transmit interrupt */
236
+#define TX_DESC_STATUS_TXINTR (1 << 16)
237
+
238
+#define TX_DESC_PKT_LEN(word) extract32((word), 0, 16)
239
+
240
+/* Transmit buffer start address */
241
+#define TX_DESC_TXBSA(word) ((uint32_t) (word) & ~3u)
242
+
243
+/* Next transmit descriptor start address */
244
+#define TX_DESC_NTXDSA(word) ((uint32_t) (word) & ~3u)
245
+
246
+/* NPCM7xxEMCRxDesc.status_and_length values */
247
+/* Owner: 0b00 = cpu, 0b01 = undefined, 0b10 = emc, 0b11 = undefined */
248
+#define RX_DESC_STATUS_OWNER_SHIFT 30
249
+#define RX_DESC_STATUS_OWNER_BITSIZE 2
250
+#define RX_DESC_STATUS_OWNER_MASK (3 << RX_DESC_STATUS_OWNER_SHIFT)
251
+/* Runt packet */
252
+#define RX_DESC_STATUS_RP (1 << 22)
253
+/* Alignment error */
254
+#define RX_DESC_STATUS_ALIE (1 << 21)
255
+/* Frame reception complete */
256
+#define RX_DESC_STATUS_RXGD (1 << 20)
257
+/* Packet too long */
258
+#define RX_DESC_STATUS_PTLE (1 << 19)
259
+/* CRC error */
260
+#define RX_DESC_STATUS_CRCE (1 << 17)
261
+/* Receive interrupt */
262
+#define RX_DESC_STATUS_RXINTR (1 << 16)
263
+
264
+#define RX_DESC_PKT_LEN(word) extract32((word), 0, 16)
265
+
266
+/* Receive buffer start address */
267
+#define RX_DESC_RXBSA(word) ((uint32_t) (word) & ~3u)
268
+
269
+/* Next receive descriptor start address */
270
+#define RX_DESC_NRXDSA(word) ((uint32_t) (word) & ~3u)
271
+
272
+/* Minimum packet length, when TX_DESC_FLAG_PADEN is set. */
273
+#define MIN_PACKET_LENGTH 64
274
+
275
+struct NPCM7xxEMCState {
276
+ /*< private >*/
277
+ SysBusDevice parent;
278
+ /*< public >*/
279
+
111
+ MemoryRegion iomem;
280
+ MemoryRegion iomem;
112
+ qemu_irq irq_rtc_int;
281
+
113
+ qemu_irq irq_addr_error_int;
282
+ qemu_irq tx_irq;
114
+
283
+ qemu_irq rx_irq;
115
+ uint32_t regs[XLNX_ZYNQMP_RTC_R_MAX];
284
+
116
+ RegisterInfo regs_info[XLNX_ZYNQMP_RTC_R_MAX];
285
+ NICState *nic;
117
+} XlnxZynqMPRTC;
286
+ NICConf conf;
118
diff --git a/hw/timer/xlnx-zynqmp-rtc.c b/hw/timer/xlnx-zynqmp-rtc.c
287
+
288
+ /* 0 or 1, for log messages */
289
+ uint8_t emc_num;
290
+
291
+ uint32_t regs[NPCM7XX_NUM_EMC_REGS];
292
+
293
+ /*
294
+ * tx is active. Set to true by TSDR and then switches off when out of
295
+ * descriptors. If the TXON bit in REG_MCMDR is off then this is off.
296
+ */
297
+ bool tx_active;
298
+
299
+ /*
300
+ * rx is active. Set to true by RSDR and then switches off when out of
301
+ * descriptors. If the RXON bit in REG_MCMDR is off then this is off.
302
+ */
303
+ bool rx_active;
304
+};
305
+
306
+typedef struct NPCM7xxEMCState NPCM7xxEMCState;
307
+
308
+#define TYPE_NPCM7XX_EMC "npcm7xx-emc"
309
+#define NPCM7XX_EMC(obj) \
310
+ OBJECT_CHECK(NPCM7xxEMCState, (obj), TYPE_NPCM7XX_EMC)
311
+
312
+#endif /* NPCM7XX_EMC_H */
313
diff --git a/hw/net/npcm7xx_emc.c b/hw/net/npcm7xx_emc.c
119
new file mode 100644
314
new file mode 100644
120
index XXXXXXX..XXXXXXX
315
index XXXXXXX..XXXXXXX
121
--- /dev/null
316
--- /dev/null
122
+++ b/hw/timer/xlnx-zynqmp-rtc.c
317
+++ b/hw/net/npcm7xx_emc.c
123
@@ -XXX,XX +XXX,XX @@
318
@@ -XXX,XX +XXX,XX @@
124
+/*
319
+/*
125
+ * QEMU model of the Xilinx ZynqMP Real Time Clock (RTC).
320
+ * Nuvoton NPCM7xx EMC Module
126
+ *
321
+ *
127
+ * Copyright (c) 2017 Xilinx Inc.
322
+ * Copyright 2020 Google LLC
128
+ *
323
+ *
129
+ * Written-by: Alistair Francis <alistair.francis@xilinx.com>
324
+ * This program is free software; you can redistribute it and/or modify it
325
+ * under the terms of the GNU General Public License as published by the
326
+ * Free Software Foundation; either version 2 of the License, or
327
+ * (at your option) any later version.
130
+ *
328
+ *
131
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
329
+ * This program is distributed in the hope that it will be useful, but WITHOUT
132
+ * of this software and associated documentation files (the "Software"), to deal
330
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
133
+ * in the Software without restriction, including without limitation the rights
331
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
134
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
332
+ * for more details.
135
+ * copies of the Software, and to permit persons to whom the Software is
136
+ * furnished to do so, subject to the following conditions:
137
+ *
333
+ *
138
+ * The above copyright notice and this permission notice shall be included in
334
+ * Unsupported/unimplemented features:
139
+ * all copies or substantial portions of the Software.
335
+ * - MCMDR.FDUP (full duplex) is ignored, half duplex is not supported
140
+ *
336
+ * - Only CAM0 is supported, CAM[1-15] are not
141
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
337
+ * - writes to CAMEN.[1-15] are ignored, these bits always read as zeroes
142
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
338
+ * - MII is not implemented, MIIDA.BUSY and MIID always return zero
143
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
339
+ * - MCMDR.LBK is not implemented
144
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
340
+ * - MCMDR.{OPMOD,ENSQE,AEP,ARP} are not supported
145
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
341
+ * - H/W FIFOs are not supported, MCMDR.FFTCR is ignored
146
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
342
+ * - MGSTA.SQE is not supported
147
+ * THE SOFTWARE.
343
+ * - pause and control frames are not implemented
344
+ * - MGSTA.CCNT is not supported
345
+ * - MPCNT, DMARFS are not implemented
148
+ */
346
+ */
149
+
347
+
150
+#include "qemu/osdep.h"
348
+#include "qemu/osdep.h"
151
+#include "hw/sysbus.h"
349
+
152
+#include "hw/register.h"
350
+/* For crc32 */
351
+#include <zlib.h>
352
+
353
+#include "qemu-common.h"
354
+#include "hw/irq.h"
355
+#include "hw/qdev-clock.h"
356
+#include "hw/qdev-properties.h"
357
+#include "hw/net/npcm7xx_emc.h"
358
+#include "net/eth.h"
359
+#include "migration/vmstate.h"
153
+#include "qemu/bitops.h"
360
+#include "qemu/bitops.h"
361
+#include "qemu/error-report.h"
154
+#include "qemu/log.h"
362
+#include "qemu/log.h"
155
+#include "hw/timer/xlnx-zynqmp-rtc.h"
363
+#include "qemu/module.h"
156
+
364
+#include "qemu/units.h"
157
+#ifndef XLNX_ZYNQMP_RTC_ERR_DEBUG
365
+#include "sysemu/dma.h"
158
+#define XLNX_ZYNQMP_RTC_ERR_DEBUG 0
366
+#include "trace.h"
159
+#endif
367
+
160
+
368
+#define CRC_LENGTH 4
161
+static void rtc_int_update_irq(XlnxZynqMPRTC *s)
369
+
162
+{
370
+/*
163
+ bool pending = s->regs[R_RTC_INT_STATUS] & ~s->regs[R_RTC_INT_MASK];
371
+ * The maximum size of a (layer 2) ethernet frame as defined by 802.3.
164
+ qemu_set_irq(s->irq_rtc_int, pending);
372
+ * 1518 = 6(dest macaddr) + 6(src macaddr) + 2(proto) + 4(crc) + 1500(payload)
165
+}
373
+ * This does not include an additional 4 for the vlan field (802.1q).
166
+
374
+ */
167
+static void addr_error_int_update_irq(XlnxZynqMPRTC *s)
375
+#define MAX_ETH_FRAME_SIZE 1518
168
+{
376
+
169
+ bool pending = s->regs[R_ADDR_ERROR] & ~s->regs[R_ADDR_ERROR_INT_MASK];
377
+static const char *emc_reg_name(int regno)
170
+ qemu_set_irq(s->irq_addr_error_int, pending);
378
+{
171
+}
379
+#define REG(name) case REG_ ## name: return #name;
172
+
380
+ switch (regno) {
173
+static void rtc_int_status_postw(RegisterInfo *reg, uint64_t val64)
381
+ REG(CAMCMR)
174
+{
382
+ REG(CAMEN)
175
+ XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(reg->opaque);
383
+ REG(TXDLSA)
176
+ rtc_int_update_irq(s);
384
+ REG(RXDLSA)
177
+}
385
+ REG(MCMDR)
178
+
386
+ REG(MIID)
179
+static uint64_t rtc_int_en_prew(RegisterInfo *reg, uint64_t val64)
387
+ REG(MIIDA)
180
+{
388
+ REG(FFTCR)
181
+ XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(reg->opaque);
389
+ REG(TSDR)
182
+
390
+ REG(RSDR)
183
+ s->regs[R_RTC_INT_MASK] &= (uint32_t) ~val64;
391
+ REG(DMARFC)
184
+ rtc_int_update_irq(s);
392
+ REG(MIEN)
393
+ REG(MISTA)
394
+ REG(MGSTA)
395
+ REG(MPCNT)
396
+ REG(MRPC)
397
+ REG(MRPCC)
398
+ REG(MREPC)
399
+ REG(DMARFS)
400
+ REG(CTXDSA)
401
+ REG(CTXBSA)
402
+ REG(CRXDSA)
403
+ REG(CRXBSA)
404
+ case REG_CAMM_BASE + 0: return "CAM0M";
405
+ case REG_CAML_BASE + 0: return "CAM0L";
406
+ case REG_CAMM_BASE + 2 ... REG_CAMML_LAST:
407
+ /* Only CAM0 is supported, fold the others into something simple. */
408
+ if (regno & 1) {
409
+ return "CAM<n>L";
410
+ } else {
411
+ return "CAM<n>M";
412
+ }
413
+ default: return "UNKNOWN";
414
+ }
415
+#undef REG
416
+}
417
+
418
+static void emc_reset(NPCM7xxEMCState *emc)
419
+{
420
+ trace_npcm7xx_emc_reset(emc->emc_num);
421
+
422
+ memset(&emc->regs[0], 0, sizeof(emc->regs));
423
+
424
+ /* These regs have non-zero reset values. */
425
+ emc->regs[REG_TXDLSA] = 0xfffffffc;
426
+ emc->regs[REG_RXDLSA] = 0xfffffffc;
427
+ emc->regs[REG_MIIDA] = 0x00900000;
428
+ emc->regs[REG_FFTCR] = 0x0101;
429
+ emc->regs[REG_DMARFC] = 0x0800;
430
+ emc->regs[REG_MPCNT] = 0x7fff;
431
+
432
+ emc->tx_active = false;
433
+ emc->rx_active = false;
434
+}
435
+
436
+static void npcm7xx_emc_reset(DeviceState *dev)
437
+{
438
+ NPCM7xxEMCState *emc = NPCM7XX_EMC(dev);
439
+ emc_reset(emc);
440
+}
441
+
442
+static void emc_soft_reset(NPCM7xxEMCState *emc)
443
+{
444
+ /*
445
+ * The docs say at least MCMDR.{LBK,OPMOD} bits are not changed during a
446
+ * soft reset, but does not go into further detail. For now, KISS.
447
+ */
448
+ uint32_t mcmdr = emc->regs[REG_MCMDR];
449
+ emc_reset(emc);
450
+ emc->regs[REG_MCMDR] = mcmdr & (REG_MCMDR_LBK | REG_MCMDR_OPMOD);
451
+
452
+ qemu_set_irq(emc->tx_irq, 0);
453
+ qemu_set_irq(emc->rx_irq, 0);
454
+}
455
+
456
+static void emc_set_link(NetClientState *nc)
457
+{
458
+ /* Nothing to do yet. */
459
+}
460
+
461
+/* MISTA.TXINTR is the union of the individual bits with their enables. */
462
+static void emc_update_mista_txintr(NPCM7xxEMCState *emc)
463
+{
464
+ /* Only look at the bits we support. */
465
+ uint32_t mask = (REG_MISTA_TXBERR |
466
+ REG_MISTA_TDU |
467
+ REG_MISTA_TXCP);
468
+ if (emc->regs[REG_MISTA] & emc->regs[REG_MIEN] & mask) {
469
+ emc->regs[REG_MISTA] |= REG_MISTA_TXINTR;
470
+ } else {
471
+ emc->regs[REG_MISTA] &= ~REG_MISTA_TXINTR;
472
+ }
473
+}
474
+
475
+/* MISTA.RXINTR is the union of the individual bits with their enables. */
476
+static void emc_update_mista_rxintr(NPCM7xxEMCState *emc)
477
+{
478
+ /* Only look at the bits we support. */
479
+ uint32_t mask = (REG_MISTA_RXBERR |
480
+ REG_MISTA_RDU |
481
+ REG_MISTA_RXGD);
482
+ if (emc->regs[REG_MISTA] & emc->regs[REG_MIEN] & mask) {
483
+ emc->regs[REG_MISTA] |= REG_MISTA_RXINTR;
484
+ } else {
485
+ emc->regs[REG_MISTA] &= ~REG_MISTA_RXINTR;
486
+ }
487
+}
488
+
489
+/* N.B. emc_update_mista_txintr must have already been called. */
490
+static void emc_update_tx_irq(NPCM7xxEMCState *emc)
491
+{
492
+ int level = !!(emc->regs[REG_MISTA] &
493
+ emc->regs[REG_MIEN] &
494
+ REG_MISTA_TXINTR);
495
+ trace_npcm7xx_emc_update_tx_irq(level);
496
+ qemu_set_irq(emc->tx_irq, level);
497
+}
498
+
499
+/* N.B. emc_update_mista_rxintr must have already been called. */
500
+static void emc_update_rx_irq(NPCM7xxEMCState *emc)
501
+{
502
+ int level = !!(emc->regs[REG_MISTA] &
503
+ emc->regs[REG_MIEN] &
504
+ REG_MISTA_RXINTR);
505
+ trace_npcm7xx_emc_update_rx_irq(level);
506
+ qemu_set_irq(emc->rx_irq, level);
507
+}
508
+
509
+/* Update IRQ states due to changes in MIEN,MISTA. */
510
+static void emc_update_irq_from_reg_change(NPCM7xxEMCState *emc)
511
+{
512
+ emc_update_mista_txintr(emc);
513
+ emc_update_tx_irq(emc);
514
+
515
+ emc_update_mista_rxintr(emc);
516
+ emc_update_rx_irq(emc);
517
+}
518
+
519
+static int emc_read_tx_desc(dma_addr_t addr, NPCM7xxEMCTxDesc *desc)
520
+{
521
+ if (dma_memory_read(&address_space_memory, addr, desc, sizeof(*desc))) {
522
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to read descriptor @ 0x%"
523
+ HWADDR_PRIx "\n", __func__, addr);
524
+ return -1;
525
+ }
526
+ desc->flags = le32_to_cpu(desc->flags);
527
+ desc->txbsa = le32_to_cpu(desc->txbsa);
528
+ desc->status_and_length = le32_to_cpu(desc->status_and_length);
529
+ desc->ntxdsa = le32_to_cpu(desc->ntxdsa);
185
+ return 0;
530
+ return 0;
186
+}
531
+}
187
+
532
+
188
+static uint64_t rtc_int_dis_prew(RegisterInfo *reg, uint64_t val64)
533
+static int emc_write_tx_desc(const NPCM7xxEMCTxDesc *desc, dma_addr_t addr)
189
+{
534
+{
190
+ XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(reg->opaque);
535
+ NPCM7xxEMCTxDesc le_desc;
191
+
536
+
192
+ s->regs[R_RTC_INT_MASK] |= (uint32_t) val64;
537
+ le_desc.flags = cpu_to_le32(desc->flags);
193
+ rtc_int_update_irq(s);
538
+ le_desc.txbsa = cpu_to_le32(desc->txbsa);
539
+ le_desc.status_and_length = cpu_to_le32(desc->status_and_length);
540
+ le_desc.ntxdsa = cpu_to_le32(desc->ntxdsa);
541
+ if (dma_memory_write(&address_space_memory, addr, &le_desc,
542
+ sizeof(le_desc))) {
543
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to write descriptor @ 0x%"
544
+ HWADDR_PRIx "\n", __func__, addr);
545
+ return -1;
546
+ }
194
+ return 0;
547
+ return 0;
195
+}
548
+}
196
+
549
+
197
+static void addr_error_postw(RegisterInfo *reg, uint64_t val64)
550
+static int emc_read_rx_desc(dma_addr_t addr, NPCM7xxEMCRxDesc *desc)
198
+{
551
+{
199
+ XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(reg->opaque);
552
+ if (dma_memory_read(&address_space_memory, addr, desc, sizeof(*desc))) {
200
+ addr_error_int_update_irq(s);
553
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to read descriptor @ 0x%"
201
+}
554
+ HWADDR_PRIx "\n", __func__, addr);
202
+
555
+ return -1;
203
+static uint64_t addr_error_int_en_prew(RegisterInfo *reg, uint64_t val64)
556
+ }
204
+{
557
+ desc->status_and_length = le32_to_cpu(desc->status_and_length);
205
+ XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(reg->opaque);
558
+ desc->rxbsa = le32_to_cpu(desc->rxbsa);
206
+
559
+ desc->reserved = le32_to_cpu(desc->reserved);
207
+ s->regs[R_ADDR_ERROR_INT_MASK] &= (uint32_t) ~val64;
560
+ desc->nrxdsa = le32_to_cpu(desc->nrxdsa);
208
+ addr_error_int_update_irq(s);
209
+ return 0;
561
+ return 0;
210
+}
562
+}
211
+
563
+
212
+static uint64_t addr_error_int_dis_prew(RegisterInfo *reg, uint64_t val64)
564
+static int emc_write_rx_desc(const NPCM7xxEMCRxDesc *desc, dma_addr_t addr)
213
+{
565
+{
214
+ XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(reg->opaque);
566
+ NPCM7xxEMCRxDesc le_desc;
215
+
567
+
216
+ s->regs[R_ADDR_ERROR_INT_MASK] |= (uint32_t) val64;
568
+ le_desc.status_and_length = cpu_to_le32(desc->status_and_length);
217
+ addr_error_int_update_irq(s);
569
+ le_desc.rxbsa = cpu_to_le32(desc->rxbsa);
570
+ le_desc.reserved = cpu_to_le32(desc->reserved);
571
+ le_desc.nrxdsa = cpu_to_le32(desc->nrxdsa);
572
+ if (dma_memory_write(&address_space_memory, addr, &le_desc,
573
+ sizeof(le_desc))) {
574
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to write descriptor @ 0x%"
575
+ HWADDR_PRIx "\n", __func__, addr);
576
+ return -1;
577
+ }
218
+ return 0;
578
+ return 0;
219
+}
579
+}
220
+
580
+
221
+static const RegisterAccessInfo rtc_regs_info[] = {
581
+static void emc_set_mista(NPCM7xxEMCState *emc, uint32_t flags)
222
+ { .name = "SET_TIME_WRITE", .addr = A_SET_TIME_WRITE,
582
+{
223
+ },{ .name = "SET_TIME_READ", .addr = A_SET_TIME_READ,
583
+ trace_npcm7xx_emc_set_mista(flags);
224
+ .ro = 0xffffffff,
584
+ emc->regs[REG_MISTA] |= flags;
225
+ },{ .name = "CALIB_WRITE", .addr = A_CALIB_WRITE,
585
+ if (extract32(flags, 16, 16)) {
226
+ },{ .name = "CALIB_READ", .addr = A_CALIB_READ,
586
+ emc_update_mista_txintr(emc);
227
+ .ro = 0x1fffff,
587
+ }
228
+ },{ .name = "CURRENT_TIME", .addr = A_CURRENT_TIME,
588
+ if (extract32(flags, 0, 16)) {
229
+ .ro = 0xffffffff,
589
+ emc_update_mista_rxintr(emc);
230
+ },{ .name = "CURRENT_TICK", .addr = A_CURRENT_TICK,
590
+ }
231
+ .ro = 0xffff,
591
+}
232
+ },{ .name = "ALARM", .addr = A_ALARM,
592
+
233
+ },{ .name = "RTC_INT_STATUS", .addr = A_RTC_INT_STATUS,
593
+static void emc_halt_tx(NPCM7xxEMCState *emc, uint32_t mista_flag)
234
+ .w1c = 0x3,
594
+{
235
+ .post_write = rtc_int_status_postw,
595
+ emc->tx_active = false;
236
+ },{ .name = "RTC_INT_MASK", .addr = A_RTC_INT_MASK,
596
+ emc_set_mista(emc, mista_flag);
237
+ .reset = 0x3,
597
+}
238
+ .ro = 0x3,
598
+
239
+ },{ .name = "RTC_INT_EN", .addr = A_RTC_INT_EN,
599
+static void emc_halt_rx(NPCM7xxEMCState *emc, uint32_t mista_flag)
240
+ .pre_write = rtc_int_en_prew,
600
+{
241
+ },{ .name = "RTC_INT_DIS", .addr = A_RTC_INT_DIS,
601
+ emc->rx_active = false;
242
+ .pre_write = rtc_int_dis_prew,
602
+ emc_set_mista(emc, mista_flag);
243
+ },{ .name = "ADDR_ERROR", .addr = A_ADDR_ERROR,
603
+}
244
+ .w1c = 0x1,
604
+
245
+ .post_write = addr_error_postw,
605
+static void emc_set_next_tx_descriptor(NPCM7xxEMCState *emc,
246
+ },{ .name = "ADDR_ERROR_INT_MASK", .addr = A_ADDR_ERROR_INT_MASK,
606
+ const NPCM7xxEMCTxDesc *tx_desc,
247
+ .reset = 0x1,
607
+ uint32_t desc_addr)
248
+ .ro = 0x1,
608
+{
249
+ },{ .name = "ADDR_ERROR_INT_EN", .addr = A_ADDR_ERROR_INT_EN,
609
+ /* Update the current descriptor, if only to reset the owner flag. */
250
+ .pre_write = addr_error_int_en_prew,
610
+ if (emc_write_tx_desc(tx_desc, desc_addr)) {
251
+ },{ .name = "ADDR_ERROR_INT_DIS", .addr = A_ADDR_ERROR_INT_DIS,
611
+ /*
252
+ .pre_write = addr_error_int_dis_prew,
612
+ * We just read it so this shouldn't generally happen.
253
+ },{ .name = "CONTROL", .addr = A_CONTROL,
613
+ * Error already reported.
254
+ .reset = 0x1000000,
614
+ */
255
+ .rsvd = 0x70fffffe,
615
+ emc_set_mista(emc, REG_MISTA_TXBERR);
256
+ },{ .name = "SAFETY_CHK", .addr = A_SAFETY_CHK,
616
+ }
257
+ }
617
+ emc->regs[REG_CTXDSA] = TX_DESC_NTXDSA(tx_desc->ntxdsa);
258
+};
618
+}
259
+
619
+
260
+static void rtc_reset(DeviceState *dev)
620
+static void emc_set_next_rx_descriptor(NPCM7xxEMCState *emc,
261
+{
621
+ const NPCM7xxEMCRxDesc *rx_desc,
262
+ XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(dev);
622
+ uint32_t desc_addr)
263
+ unsigned int i;
623
+{
264
+
624
+ /* Update the current descriptor, if only to reset the owner flag. */
265
+ for (i = 0; i < ARRAY_SIZE(s->regs_info); ++i) {
625
+ if (emc_write_rx_desc(rx_desc, desc_addr)) {
266
+ register_reset(&s->regs_info[i]);
626
+ /*
267
+ }
627
+ * We just read it so this shouldn't generally happen.
268
+
628
+ * Error already reported.
269
+ rtc_int_update_irq(s);
629
+ */
270
+ addr_error_int_update_irq(s);
630
+ emc_set_mista(emc, REG_MISTA_RXBERR);
271
+}
631
+ }
272
+
632
+ emc->regs[REG_CRXDSA] = RX_DESC_NRXDSA(rx_desc->nrxdsa);
273
+static const MemoryRegionOps rtc_ops = {
633
+}
274
+ .read = register_read_memory,
634
+
275
+ .write = register_write_memory,
635
+static void emc_try_send_next_packet(NPCM7xxEMCState *emc)
636
+{
637
+ /* Working buffer for sending out packets. Most packets fit in this. */
638
+#define TX_BUFFER_SIZE 2048
639
+ uint8_t tx_send_buffer[TX_BUFFER_SIZE];
640
+ uint32_t desc_addr = TX_DESC_NTXDSA(emc->regs[REG_CTXDSA]);
641
+ NPCM7xxEMCTxDesc tx_desc;
642
+ uint32_t next_buf_addr, length;
643
+ uint8_t *buf;
644
+ g_autofree uint8_t *malloced_buf = NULL;
645
+
646
+ if (emc_read_tx_desc(desc_addr, &tx_desc)) {
647
+ /* Error reading descriptor, already reported. */
648
+ emc_halt_tx(emc, REG_MISTA_TXBERR);
649
+ emc_update_tx_irq(emc);
650
+ return;
651
+ }
652
+
653
+ /* Nothing we can do if we don't own the descriptor. */
654
+ if (!(tx_desc.flags & TX_DESC_FLAG_OWNER_MASK)) {
655
+ trace_npcm7xx_emc_cpu_owned_desc(desc_addr);
656
+ emc_halt_tx(emc, REG_MISTA_TDU);
657
+ emc_update_tx_irq(emc);
658
+ return;
659
+ }
660
+
661
+ /* Give the descriptor back regardless of what happens. */
662
+ tx_desc.flags &= ~TX_DESC_FLAG_OWNER_MASK;
663
+ tx_desc.status_and_length &= 0xffff;
664
+
665
+ /*
666
+ * Despite the h/w documentation saying the tx buffer is word aligned,
667
+ * the linux driver does not word align the buffer. There is value in not
668
+ * aligning the buffer: See the description of NET_IP_ALIGN in linux
669
+ * kernel sources.
670
+ */
671
+ next_buf_addr = tx_desc.txbsa;
672
+ emc->regs[REG_CTXBSA] = next_buf_addr;
673
+ length = TX_DESC_PKT_LEN(tx_desc.status_and_length);
674
+ buf = &tx_send_buffer[0];
675
+
676
+ if (length > sizeof(tx_send_buffer)) {
677
+ malloced_buf = g_malloc(length);
678
+ buf = malloced_buf;
679
+ }
680
+
681
+ if (dma_memory_read(&address_space_memory, next_buf_addr, buf, length)) {
682
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to read packet @ 0x%x\n",
683
+ __func__, next_buf_addr);
684
+ emc_set_mista(emc, REG_MISTA_TXBERR);
685
+ emc_set_next_tx_descriptor(emc, &tx_desc, desc_addr);
686
+ emc_update_tx_irq(emc);
687
+ trace_npcm7xx_emc_tx_done(emc->regs[REG_CTXDSA]);
688
+ return;
689
+ }
690
+
691
+ if ((tx_desc.flags & TX_DESC_FLAG_PADEN) && (length < MIN_PACKET_LENGTH)) {
692
+ memset(buf + length, 0, MIN_PACKET_LENGTH - length);
693
+ length = MIN_PACKET_LENGTH;
694
+ }
695
+
696
+ /* N.B. emc_receive can get called here. */
697
+ qemu_send_packet(qemu_get_queue(emc->nic), buf, length);
698
+ trace_npcm7xx_emc_sent_packet(length);
699
+
700
+ tx_desc.status_and_length |= TX_DESC_STATUS_TXCP;
701
+ if (tx_desc.flags & TX_DESC_FLAG_INTEN) {
702
+ emc_set_mista(emc, REG_MISTA_TXCP);
703
+ }
704
+ if (emc->regs[REG_MISTA] & emc->regs[REG_MIEN] & REG_MISTA_TXINTR) {
705
+ tx_desc.status_and_length |= TX_DESC_STATUS_TXINTR;
706
+ }
707
+
708
+ emc_set_next_tx_descriptor(emc, &tx_desc, desc_addr);
709
+ emc_update_tx_irq(emc);
710
+ trace_npcm7xx_emc_tx_done(emc->regs[REG_CTXDSA]);
711
+}
712
+
713
+static bool emc_can_receive(NetClientState *nc)
714
+{
715
+ NPCM7xxEMCState *emc = NPCM7XX_EMC(qemu_get_nic_opaque(nc));
716
+
717
+ bool can_receive = emc->rx_active;
718
+ trace_npcm7xx_emc_can_receive(can_receive);
719
+ return can_receive;
720
+}
721
+
722
+/* If result is false then *fail_reason contains the reason. */
723
+static bool emc_receive_filter1(NPCM7xxEMCState *emc, const uint8_t *buf,
724
+ size_t len, const char **fail_reason)
725
+{
726
+ eth_pkt_types_e pkt_type = get_eth_packet_type(PKT_GET_ETH_HDR(buf));
727
+
728
+ switch (pkt_type) {
729
+ case ETH_PKT_BCAST:
730
+ if (emc->regs[REG_CAMCMR] & REG_CAMCMR_CCAM) {
731
+ return true;
732
+ } else {
733
+ *fail_reason = "Broadcast packet disabled";
734
+ return !!(emc->regs[REG_CAMCMR] & REG_CAMCMR_ABP);
735
+ }
736
+ case ETH_PKT_MCAST:
737
+ if (emc->regs[REG_CAMCMR] & REG_CAMCMR_CCAM) {
738
+ return true;
739
+ } else {
740
+ *fail_reason = "Multicast packet disabled";
741
+ return !!(emc->regs[REG_CAMCMR] & REG_CAMCMR_AMP);
742
+ }
743
+ case ETH_PKT_UCAST: {
744
+ bool matches;
745
+ if (emc->regs[REG_CAMCMR] & REG_CAMCMR_AUP) {
746
+ return true;
747
+ }
748
+ matches = ((emc->regs[REG_CAMCMR] & REG_CAMCMR_ECMP) &&
749
+ /* We only support one CAM register, CAM0. */
750
+ (emc->regs[REG_CAMEN] & (1 << 0)) &&
751
+ memcmp(buf, emc->conf.macaddr.a, ETH_ALEN) == 0);
752
+ if (emc->regs[REG_CAMCMR] & REG_CAMCMR_CCAM) {
753
+ *fail_reason = "MACADDR matched, comparison complemented";
754
+ return !matches;
755
+ } else {
756
+ *fail_reason = "MACADDR didn't match";
757
+ return matches;
758
+ }
759
+ }
760
+ default:
761
+ g_assert_not_reached();
762
+ }
763
+}
764
+
765
+static bool emc_receive_filter(NPCM7xxEMCState *emc, const uint8_t *buf,
766
+ size_t len)
767
+{
768
+ const char *fail_reason = NULL;
769
+ bool ok = emc_receive_filter1(emc, buf, len, &fail_reason);
770
+ if (!ok) {
771
+ trace_npcm7xx_emc_packet_filtered_out(fail_reason);
772
+ }
773
+ return ok;
774
+}
775
+
776
+static ssize_t emc_receive(NetClientState *nc, const uint8_t *buf, size_t len1)
777
+{
778
+ NPCM7xxEMCState *emc = NPCM7XX_EMC(qemu_get_nic_opaque(nc));
779
+ const uint32_t len = len1;
780
+ size_t max_frame_len;
781
+ bool long_frame;
782
+ uint32_t desc_addr;
783
+ NPCM7xxEMCRxDesc rx_desc;
784
+ uint32_t crc;
785
+ uint8_t *crc_ptr;
786
+ uint32_t buf_addr;
787
+
788
+ trace_npcm7xx_emc_receiving_packet(len);
789
+
790
+ if (!emc_can_receive(nc)) {
791
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Unexpected packet\n", __func__);
792
+ return -1;
793
+ }
794
+
795
+ if (len < ETH_HLEN ||
796
+ /* Defensive programming: drop unsupportable large packets. */
797
+ len > 0xffff - CRC_LENGTH) {
798
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Dropped frame of %u bytes\n",
799
+ __func__, len);
800
+ return len;
801
+ }
802
+
803
+ /*
804
+ * DENI is set if EMC received the Length/Type field of the incoming
805
+ * packet, so it will be set regardless of what happens next.
806
+ */
807
+ emc_set_mista(emc, REG_MISTA_DENI);
808
+
809
+ if (!emc_receive_filter(emc, buf, len)) {
810
+ emc_update_rx_irq(emc);
811
+ return len;
812
+ }
813
+
814
+ /* Huge frames (> DMARFC) are dropped. */
815
+ max_frame_len = REG_DMARFC_RXMS(emc->regs[REG_DMARFC]);
816
+ if (len + CRC_LENGTH > max_frame_len) {
817
+ trace_npcm7xx_emc_packet_dropped(len);
818
+ emc_set_mista(emc, REG_MISTA_DFOI);
819
+ emc_update_rx_irq(emc);
820
+ return len;
821
+ }
822
+
823
+ /*
824
+ * Long Frames (> MAX_ETH_FRAME_SIZE) are also dropped, unless MCMDR.ALP
825
+ * is set.
826
+ */
827
+ long_frame = false;
828
+ if (len + CRC_LENGTH > MAX_ETH_FRAME_SIZE) {
829
+ if (emc->regs[REG_MCMDR] & REG_MCMDR_ALP) {
830
+ long_frame = true;
831
+ } else {
832
+ trace_npcm7xx_emc_packet_dropped(len);
833
+ emc_set_mista(emc, REG_MISTA_PTLE);
834
+ emc_update_rx_irq(emc);
835
+ return len;
836
+ }
837
+ }
838
+
839
+ desc_addr = RX_DESC_NRXDSA(emc->regs[REG_CRXDSA]);
840
+ if (emc_read_rx_desc(desc_addr, &rx_desc)) {
841
+ /* Error reading descriptor, already reported. */
842
+ emc_halt_rx(emc, REG_MISTA_RXBERR);
843
+ emc_update_rx_irq(emc);
844
+ return len;
845
+ }
846
+
847
+ /* Nothing we can do if we don't own the descriptor. */
848
+ if (!(rx_desc.status_and_length & RX_DESC_STATUS_OWNER_MASK)) {
849
+ trace_npcm7xx_emc_cpu_owned_desc(desc_addr);
850
+ emc_halt_rx(emc, REG_MISTA_RDU);
851
+ emc_update_rx_irq(emc);
852
+ return len;
853
+ }
854
+
855
+ crc = 0;
856
+ crc_ptr = (uint8_t *) &crc;
857
+ if (!(emc->regs[REG_MCMDR] & REG_MCMDR_SPCRC)) {
858
+ crc = cpu_to_be32(crc32(~0, buf, len));
859
+ }
860
+
861
+ /* Give the descriptor back regardless of what happens. */
862
+ rx_desc.status_and_length &= ~RX_DESC_STATUS_OWNER_MASK;
863
+
864
+ buf_addr = rx_desc.rxbsa;
865
+ emc->regs[REG_CRXBSA] = buf_addr;
866
+ if (dma_memory_write(&address_space_memory, buf_addr, buf, len) ||
867
+ (!(emc->regs[REG_MCMDR] & REG_MCMDR_SPCRC) &&
868
+ dma_memory_write(&address_space_memory, buf_addr + len, crc_ptr,
869
+ 4))) {
870
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Bus error writing packet\n",
871
+ __func__);
872
+ emc_set_mista(emc, REG_MISTA_RXBERR);
873
+ emc_set_next_rx_descriptor(emc, &rx_desc, desc_addr);
874
+ emc_update_rx_irq(emc);
875
+ trace_npcm7xx_emc_rx_done(emc->regs[REG_CRXDSA]);
876
+ return len;
877
+ }
878
+
879
+ trace_npcm7xx_emc_received_packet(len);
880
+
881
+ /* Note: We've already verified len+4 <= 0xffff. */
882
+ rx_desc.status_and_length = len;
883
+ if (!(emc->regs[REG_MCMDR] & REG_MCMDR_SPCRC)) {
884
+ rx_desc.status_and_length += 4;
885
+ }
886
+ rx_desc.status_and_length |= RX_DESC_STATUS_RXGD;
887
+ emc_set_mista(emc, REG_MISTA_RXGD);
888
+
889
+ if (emc->regs[REG_MISTA] & emc->regs[REG_MIEN] & REG_MISTA_RXINTR) {
890
+ rx_desc.status_and_length |= RX_DESC_STATUS_RXINTR;
891
+ }
892
+ if (long_frame) {
893
+ rx_desc.status_and_length |= RX_DESC_STATUS_PTLE;
894
+ }
895
+
896
+ emc_set_next_rx_descriptor(emc, &rx_desc, desc_addr);
897
+ emc_update_rx_irq(emc);
898
+ trace_npcm7xx_emc_rx_done(emc->regs[REG_CRXDSA]);
899
+ return len;
900
+}
901
+
902
+static void emc_try_receive_next_packet(NPCM7xxEMCState *emc)
903
+{
904
+ if (emc_can_receive(qemu_get_queue(emc->nic))) {
905
+ qemu_flush_queued_packets(qemu_get_queue(emc->nic));
906
+ }
907
+}
908
+
909
+static uint64_t npcm7xx_emc_read(void *opaque, hwaddr offset, unsigned size)
910
+{
911
+ NPCM7xxEMCState *emc = opaque;
912
+ uint32_t reg = offset / sizeof(uint32_t);
913
+ uint32_t result;
914
+
915
+ if (reg >= NPCM7XX_NUM_EMC_REGS) {
916
+ qemu_log_mask(LOG_GUEST_ERROR,
917
+ "%s: Invalid offset 0x%04" HWADDR_PRIx "\n",
918
+ __func__, offset);
919
+ return 0;
920
+ }
921
+
922
+ switch (reg) {
923
+ case REG_MIID:
924
+ /*
925
+ * We don't implement MII. For determinism, always return zero as
926
+ * writes record the last value written for debugging purposes.
927
+ */
928
+ qemu_log_mask(LOG_UNIMP, "%s: Read of MIID, returning 0\n", __func__);
929
+ result = 0;
930
+ break;
931
+ case REG_TSDR:
932
+ case REG_RSDR:
933
+ qemu_log_mask(LOG_GUEST_ERROR,
934
+ "%s: Read of write-only reg, %s/%d\n",
935
+ __func__, emc_reg_name(reg), reg);
936
+ return 0;
937
+ default:
938
+ result = emc->regs[reg];
939
+ break;
940
+ }
941
+
942
+ trace_npcm7xx_emc_reg_read(emc->emc_num, result, emc_reg_name(reg), reg);
943
+ return result;
944
+}
945
+
946
+static void npcm7xx_emc_write(void *opaque, hwaddr offset,
947
+ uint64_t v, unsigned size)
948
+{
949
+ NPCM7xxEMCState *emc = opaque;
950
+ uint32_t reg = offset / sizeof(uint32_t);
951
+ uint32_t value = v;
952
+
953
+ g_assert(size == sizeof(uint32_t));
954
+
955
+ if (reg >= NPCM7XX_NUM_EMC_REGS) {
956
+ qemu_log_mask(LOG_GUEST_ERROR,
957
+ "%s: Invalid offset 0x%04" HWADDR_PRIx "\n",
958
+ __func__, offset);
959
+ return;
960
+ }
961
+
962
+ trace_npcm7xx_emc_reg_write(emc->emc_num, emc_reg_name(reg), reg, value);
963
+
964
+ switch (reg) {
965
+ case REG_CAMCMR:
966
+ emc->regs[reg] = value;
967
+ break;
968
+ case REG_CAMEN:
969
+ /* Only CAM0 is supported, don't pretend otherwise. */
970
+ if (value & ~1) {
971
+ qemu_log_mask(LOG_GUEST_ERROR,
972
+ "%s: Only CAM0 is supported, cannot enable others"
973
+ ": 0x%x\n",
974
+ __func__, value);
975
+ }
976
+ emc->regs[reg] = value & 1;
977
+ break;
978
+ case REG_CAMM_BASE + 0:
979
+ emc->regs[reg] = value;
980
+ emc->conf.macaddr.a[0] = value >> 24;
981
+ emc->conf.macaddr.a[1] = value >> 16;
982
+ emc->conf.macaddr.a[2] = value >> 8;
983
+ emc->conf.macaddr.a[3] = value >> 0;
984
+ break;
985
+ case REG_CAML_BASE + 0:
986
+ emc->regs[reg] = value;
987
+ emc->conf.macaddr.a[4] = value >> 24;
988
+ emc->conf.macaddr.a[5] = value >> 16;
989
+ break;
990
+ case REG_MCMDR: {
991
+ uint32_t prev;
992
+ if (value & REG_MCMDR_SWR) {
993
+ emc_soft_reset(emc);
994
+ /* On h/w the reset happens over multiple cycles. For now KISS. */
995
+ break;
996
+ }
997
+ prev = emc->regs[reg];
998
+ emc->regs[reg] = value;
999
+ /* Update tx state. */
1000
+ if (!(prev & REG_MCMDR_TXON) &&
1001
+ (value & REG_MCMDR_TXON)) {
1002
+ emc->regs[REG_CTXDSA] = emc->regs[REG_TXDLSA];
1003
+ /*
1004
+ * Linux kernel turns TX on with CPU still holding descriptor,
1005
+ * which suggests we should wait for a write to TSDR before trying
1006
+ * to send a packet: so we don't send one here.
1007
+ */
1008
+ } else if ((prev & REG_MCMDR_TXON) &&
1009
+ !(value & REG_MCMDR_TXON)) {
1010
+ emc->regs[REG_MGSTA] |= REG_MGSTA_TXHA;
1011
+ }
1012
+ if (!(value & REG_MCMDR_TXON)) {
1013
+ emc_halt_tx(emc, 0);
1014
+ }
1015
+ /* Update rx state. */
1016
+ if (!(prev & REG_MCMDR_RXON) &&
1017
+ (value & REG_MCMDR_RXON)) {
1018
+ emc->regs[REG_CRXDSA] = emc->regs[REG_RXDLSA];
1019
+ } else if ((prev & REG_MCMDR_RXON) &&
1020
+ !(value & REG_MCMDR_RXON)) {
1021
+ emc->regs[REG_MGSTA] |= REG_MGSTA_RXHA;
1022
+ }
1023
+ if (!(value & REG_MCMDR_RXON)) {
1024
+ emc_halt_rx(emc, 0);
1025
+ }
1026
+ break;
1027
+ }
1028
+ case REG_TXDLSA:
1029
+ case REG_RXDLSA:
1030
+ case REG_DMARFC:
1031
+ case REG_MIID:
1032
+ emc->regs[reg] = value;
1033
+ break;
1034
+ case REG_MIEN:
1035
+ emc->regs[reg] = value;
1036
+ emc_update_irq_from_reg_change(emc);
1037
+ break;
1038
+ case REG_MISTA:
1039
+ /* Clear the bits that have 1 in "value". */
1040
+ emc->regs[reg] &= ~value;
1041
+ emc_update_irq_from_reg_change(emc);
1042
+ break;
1043
+ case REG_MGSTA:
1044
+ /* Clear the bits that have 1 in "value". */
1045
+ emc->regs[reg] &= ~value;
1046
+ break;
1047
+ case REG_TSDR:
1048
+ if (emc->regs[REG_MCMDR] & REG_MCMDR_TXON) {
1049
+ emc->tx_active = true;
1050
+ /* Keep trying to send packets until we run out. */
1051
+ while (emc->tx_active) {
1052
+ emc_try_send_next_packet(emc);
1053
+ }
1054
+ }
1055
+ break;
1056
+ case REG_RSDR:
1057
+ if (emc->regs[REG_MCMDR] & REG_MCMDR_RXON) {
1058
+ emc->rx_active = true;
1059
+ emc_try_receive_next_packet(emc);
1060
+ }
1061
+ break;
1062
+ case REG_MIIDA:
1063
+ emc->regs[reg] = value & ~REG_MIIDA_BUSY;
1064
+ break;
1065
+ case REG_MRPC:
1066
+ case REG_MRPCC:
1067
+ case REG_MREPC:
1068
+ case REG_CTXDSA:
1069
+ case REG_CTXBSA:
1070
+ case REG_CRXDSA:
1071
+ case REG_CRXBSA:
1072
+ qemu_log_mask(LOG_GUEST_ERROR,
1073
+ "%s: Write to read-only reg %s/%d\n",
1074
+ __func__, emc_reg_name(reg), reg);
1075
+ break;
1076
+ default:
1077
+ qemu_log_mask(LOG_UNIMP, "%s: Write to unimplemented reg %s/%d\n",
1078
+ __func__, emc_reg_name(reg), reg);
1079
+ break;
1080
+ }
1081
+}
1082
+
1083
+static const struct MemoryRegionOps npcm7xx_emc_ops = {
1084
+ .read = npcm7xx_emc_read,
1085
+ .write = npcm7xx_emc_write,
276
+ .endianness = DEVICE_LITTLE_ENDIAN,
1086
+ .endianness = DEVICE_LITTLE_ENDIAN,
277
+ .valid = {
1087
+ .valid = {
278
+ .min_access_size = 4,
1088
+ .min_access_size = 4,
279
+ .max_access_size = 4,
1089
+ .max_access_size = 4,
1090
+ .unaligned = false,
280
+ },
1091
+ },
281
+};
1092
+};
282
+
1093
+
283
+static void rtc_init(Object *obj)
1094
+static void emc_cleanup(NetClientState *nc)
284
+{
1095
+{
285
+ XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(obj);
1096
+ /* Nothing to do yet. */
286
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
1097
+}
287
+ RegisterInfoArray *reg_array;
1098
+
288
+
1099
+static NetClientInfo net_npcm7xx_emc_info = {
289
+ memory_region_init(&s->iomem, obj, TYPE_XLNX_ZYNQMP_RTC,
1100
+ .type = NET_CLIENT_DRIVER_NIC,
290
+ XLNX_ZYNQMP_RTC_R_MAX * 4);
1101
+ .size = sizeof(NICState),
291
+ reg_array =
1102
+ .can_receive = emc_can_receive,
292
+ register_init_block32(DEVICE(obj), rtc_regs_info,
1103
+ .receive = emc_receive,
293
+ ARRAY_SIZE(rtc_regs_info),
1104
+ .cleanup = emc_cleanup,
294
+ s->regs_info, s->regs,
1105
+ .link_status_changed = emc_set_link,
295
+ &rtc_ops,
1106
+};
296
+ XLNX_ZYNQMP_RTC_ERR_DEBUG,
1107
+
297
+ XLNX_ZYNQMP_RTC_R_MAX * 4);
1108
+static void npcm7xx_emc_realize(DeviceState *dev, Error **errp)
298
+ memory_region_add_subregion(&s->iomem,
1109
+{
299
+ 0x0,
1110
+ NPCM7xxEMCState *emc = NPCM7XX_EMC(dev);
300
+ &reg_array->mem);
1111
+ SysBusDevice *sbd = SYS_BUS_DEVICE(emc);
301
+ sysbus_init_mmio(sbd, &s->iomem);
1112
+
302
+ sysbus_init_irq(sbd, &s->irq_rtc_int);
1113
+ memory_region_init_io(&emc->iomem, OBJECT(emc), &npcm7xx_emc_ops, emc,
303
+ sysbus_init_irq(sbd, &s->irq_addr_error_int);
1114
+ TYPE_NPCM7XX_EMC, 4 * KiB);
304
+}
1115
+ sysbus_init_mmio(sbd, &emc->iomem);
305
+
1116
+ sysbus_init_irq(sbd, &emc->tx_irq);
306
+static const VMStateDescription vmstate_rtc = {
1117
+ sysbus_init_irq(sbd, &emc->rx_irq);
307
+ .name = TYPE_XLNX_ZYNQMP_RTC,
1118
+
308
+ .version_id = 1,
1119
+ qemu_macaddr_default_if_unset(&emc->conf.macaddr);
309
+ .minimum_version_id = 1,
1120
+ emc->nic = qemu_new_nic(&net_npcm7xx_emc_info, &emc->conf,
1121
+ object_get_typename(OBJECT(dev)), dev->id, emc);
1122
+ qemu_format_nic_info_str(qemu_get_queue(emc->nic), emc->conf.macaddr.a);
1123
+}
1124
+
1125
+static void npcm7xx_emc_unrealize(DeviceState *dev)
1126
+{
1127
+ NPCM7xxEMCState *emc = NPCM7XX_EMC(dev);
1128
+
1129
+ qemu_del_nic(emc->nic);
1130
+}
1131
+
1132
+static const VMStateDescription vmstate_npcm7xx_emc = {
1133
+ .name = TYPE_NPCM7XX_EMC,
1134
+ .version_id = 0,
1135
+ .minimum_version_id = 0,
310
+ .fields = (VMStateField[]) {
1136
+ .fields = (VMStateField[]) {
311
+ VMSTATE_UINT32_ARRAY(regs, XlnxZynqMPRTC, XLNX_ZYNQMP_RTC_R_MAX),
1137
+ VMSTATE_UINT8(emc_num, NPCM7xxEMCState),
1138
+ VMSTATE_UINT32_ARRAY(regs, NPCM7xxEMCState, NPCM7XX_NUM_EMC_REGS),
1139
+ VMSTATE_BOOL(tx_active, NPCM7xxEMCState),
1140
+ VMSTATE_BOOL(rx_active, NPCM7xxEMCState),
312
+ VMSTATE_END_OF_LIST(),
1141
+ VMSTATE_END_OF_LIST(),
313
+ }
1142
+ },
314
+};
1143
+};
315
+
1144
+
316
+static void rtc_class_init(ObjectClass *klass, void *data)
1145
+static Property npcm7xx_emc_properties[] = {
1146
+ DEFINE_NIC_PROPERTIES(NPCM7xxEMCState, conf),
1147
+ DEFINE_PROP_END_OF_LIST(),
1148
+};
1149
+
1150
+static void npcm7xx_emc_class_init(ObjectClass *klass, void *data)
317
+{
1151
+{
318
+ DeviceClass *dc = DEVICE_CLASS(klass);
1152
+ DeviceClass *dc = DEVICE_CLASS(klass);
319
+
1153
+
320
+ dc->reset = rtc_reset;
1154
+ set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
321
+ dc->vmsd = &vmstate_rtc;
1155
+ dc->desc = "NPCM7xx EMC Controller";
322
+}
1156
+ dc->realize = npcm7xx_emc_realize;
323
+
1157
+ dc->unrealize = npcm7xx_emc_unrealize;
324
+static const TypeInfo rtc_info = {
1158
+ dc->reset = npcm7xx_emc_reset;
325
+ .name = TYPE_XLNX_ZYNQMP_RTC,
1159
+ dc->vmsd = &vmstate_npcm7xx_emc;
326
+ .parent = TYPE_SYS_BUS_DEVICE,
1160
+ device_class_set_props(dc, npcm7xx_emc_properties);
327
+ .instance_size = sizeof(XlnxZynqMPRTC),
1161
+}
328
+ .class_init = rtc_class_init,
1162
+
329
+ .instance_init = rtc_init,
1163
+static const TypeInfo npcm7xx_emc_info = {
1164
+ .name = TYPE_NPCM7XX_EMC,
1165
+ .parent = TYPE_SYS_BUS_DEVICE,
1166
+ .instance_size = sizeof(NPCM7xxEMCState),
1167
+ .class_init = npcm7xx_emc_class_init,
330
+};
1168
+};
331
+
1169
+
332
+static void rtc_register_types(void)
1170
+static void npcm7xx_emc_register_type(void)
333
+{
1171
+{
334
+ type_register_static(&rtc_info);
1172
+ type_register_static(&npcm7xx_emc_info);
335
+}
1173
+}
336
+
1174
+
337
+type_init(rtc_register_types)
1175
+type_init(npcm7xx_emc_register_type)
1176
diff --git a/hw/net/meson.build b/hw/net/meson.build
1177
index XXXXXXX..XXXXXXX 100644
1178
--- a/hw/net/meson.build
1179
+++ b/hw/net/meson.build
1180
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_I82596_COMMON', if_true: files('i82596.c'))
1181
softmmu_ss.add(when: 'CONFIG_SUNHME', if_true: files('sunhme.c'))
1182
softmmu_ss.add(when: 'CONFIG_FTGMAC100', if_true: files('ftgmac100.c'))
1183
softmmu_ss.add(when: 'CONFIG_SUNGEM', if_true: files('sungem.c'))
1184
+softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_emc.c'))
1185
1186
softmmu_ss.add(when: 'CONFIG_ETRAXFS', if_true: files('etraxfs_eth.c'))
1187
softmmu_ss.add(when: 'CONFIG_COLDFIRE', if_true: files('mcf_fec.c'))
1188
diff --git a/hw/net/trace-events b/hw/net/trace-events
1189
index XXXXXXX..XXXXXXX 100644
1190
--- a/hw/net/trace-events
1191
+++ b/hw/net/trace-events
1192
@@ -XXX,XX +XXX,XX @@ imx_fec_receive_last(int last) "rx frame flags 0x%04x"
1193
imx_enet_receive(size_t size) "len %zu"
1194
imx_enet_receive_len(uint64_t addr, int len) "rx_bd 0x%"PRIx64" length %d"
1195
imx_enet_receive_last(int last) "rx frame flags 0x%04x"
1196
+
1197
+# npcm7xx_emc.c
1198
+npcm7xx_emc_reset(int emc_num) "Resetting emc%d"
1199
+npcm7xx_emc_update_tx_irq(int level) "Setting tx irq to %d"
1200
+npcm7xx_emc_update_rx_irq(int level) "Setting rx irq to %d"
1201
+npcm7xx_emc_set_mista(uint32_t flags) "ORing 0x%x into MISTA"
1202
+npcm7xx_emc_cpu_owned_desc(uint32_t addr) "Can't process cpu-owned descriptor @0x%x"
1203
+npcm7xx_emc_sent_packet(uint32_t len) "Sent %u byte packet"
1204
+npcm7xx_emc_tx_done(uint32_t ctxdsa) "TX done, CTXDSA=0x%x"
1205
+npcm7xx_emc_can_receive(int can_receive) "Can receive: %d"
1206
+npcm7xx_emc_packet_filtered_out(const char* fail_reason) "Packet filtered out: %s"
1207
+npcm7xx_emc_packet_dropped(uint32_t len) "%u byte packet dropped"
1208
+npcm7xx_emc_receiving_packet(uint32_t len) "Receiving %u byte packet"
1209
+npcm7xx_emc_received_packet(uint32_t len) "Received %u byte packet"
1210
+npcm7xx_emc_rx_done(uint32_t crxdsa) "RX done, CRXDSA=0x%x"
1211
+npcm7xx_emc_reg_read(int emc_num, uint32_t result, const char *name, int regno) "emc%d: 0x%x = reg[%s/%d]"
1212
+npcm7xx_emc_reg_write(int emc_num, const char *name, int regno, uint32_t value) "emc%d: reg[%s/%d] = 0x%x"
338
--
1213
--
339
2.16.2
1214
2.20.1
340
1215
341
1216
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Doug Evans <dje@google.com>
2
2
3
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
3
This is a 10/100 ethernet device that has several features.
4
Message-id: 20180228193125.20577-15-richard.henderson@linaro.org
4
Only the ones needed by the Linux driver have been implemented.
5
See npcm7xx_emc.c for a list of unimplemented features.
6
7
Reviewed-by: Hao Wu <wuhaotsh@google.com>
8
Reviewed-by: Avi Fishman <avi.fishman@nuvoton.com>
5
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Doug Evans <dje@google.com>
11
Message-id: 20210218212453.831406-3-dje@google.com
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
---
13
---
8
target/arm/translate.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++
14
docs/system/arm/nuvoton.rst | 3 ++-
9
1 file changed, 61 insertions(+)
15
include/hw/arm/npcm7xx.h | 2 ++
16
hw/arm/npcm7xx.c | 50 +++++++++++++++++++++++++++++++++++--
17
3 files changed, 52 insertions(+), 3 deletions(-)
10
18
11
diff --git a/target/arm/translate.c b/target/arm/translate.c
19
diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst
12
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
13
--- a/target/arm/translate.c
21
--- a/docs/system/arm/nuvoton.rst
14
+++ b/target/arm/translate.c
22
+++ b/docs/system/arm/nuvoton.rst
15
@@ -XXX,XX +XXX,XX @@ static int disas_neon_insn_3same_ext(DisasContext *s, uint32_t insn)
23
@@ -XXX,XX +XXX,XX @@ Supported devices
16
return 0;
24
* Analog to Digital Converter (ADC)
25
* Pulse Width Modulation (PWM)
26
* SMBus controller (SMBF)
27
+ * Ethernet controller (EMC)
28
29
Missing devices
30
---------------
31
@@ -XXX,XX +XXX,XX @@ Missing devices
32
* Shared memory (SHM)
33
* eSPI slave interface
34
35
- * Ethernet controllers (GMAC and EMC)
36
+ * Ethernet controller (GMAC)
37
* USB device (USBD)
38
* Peripheral SPI controller (PSPI)
39
* SD/MMC host
40
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
41
index XXXXXXX..XXXXXXX 100644
42
--- a/include/hw/arm/npcm7xx.h
43
+++ b/include/hw/arm/npcm7xx.h
44
@@ -XXX,XX +XXX,XX @@
45
#include "hw/misc/npcm7xx_gcr.h"
46
#include "hw/misc/npcm7xx_pwm.h"
47
#include "hw/misc/npcm7xx_rng.h"
48
+#include "hw/net/npcm7xx_emc.h"
49
#include "hw/nvram/npcm7xx_otp.h"
50
#include "hw/timer/npcm7xx_timer.h"
51
#include "hw/ssi/npcm7xx_fiu.h"
52
@@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState {
53
EHCISysBusState ehci;
54
OHCISysBusState ohci;
55
NPCM7xxFIUState fiu[2];
56
+ NPCM7xxEMCState emc[2];
57
} NPCM7xxState;
58
59
#define TYPE_NPCM7XX "npcm7xx"
60
diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c
61
index XXXXXXX..XXXXXXX 100644
62
--- a/hw/arm/npcm7xx.c
63
+++ b/hw/arm/npcm7xx.c
64
@@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt {
65
NPCM7XX_UART1_IRQ,
66
NPCM7XX_UART2_IRQ,
67
NPCM7XX_UART3_IRQ,
68
+ NPCM7XX_EMC1RX_IRQ = 15,
69
+ NPCM7XX_EMC1TX_IRQ,
70
NPCM7XX_TIMER0_IRQ = 32, /* Timer Module 0 */
71
NPCM7XX_TIMER1_IRQ,
72
NPCM7XX_TIMER2_IRQ,
73
@@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt {
74
NPCM7XX_SMBUS15_IRQ,
75
NPCM7XX_PWM0_IRQ = 93, /* PWM module 0 */
76
NPCM7XX_PWM1_IRQ, /* PWM module 1 */
77
+ NPCM7XX_EMC2RX_IRQ = 114,
78
+ NPCM7XX_EMC2TX_IRQ,
79
NPCM7XX_GPIO0_IRQ = 116,
80
NPCM7XX_GPIO1_IRQ,
81
NPCM7XX_GPIO2_IRQ,
82
@@ -XXX,XX +XXX,XX @@ static const hwaddr npcm7xx_smbus_addr[] = {
83
0xf008f000,
84
};
85
86
+/* Register base address for each EMC Module */
87
+static const hwaddr npcm7xx_emc_addr[] = {
88
+ 0xf0825000,
89
+ 0xf0826000,
90
+};
91
+
92
static const struct {
93
hwaddr regs_addr;
94
uint32_t unconnected_pins;
95
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj)
96
for (i = 0; i < ARRAY_SIZE(s->pwm); i++) {
97
object_initialize_child(obj, "pwm[*]", &s->pwm[i], TYPE_NPCM7XX_PWM);
98
}
99
+
100
+ for (i = 0; i < ARRAY_SIZE(s->emc); i++) {
101
+ object_initialize_child(obj, "emc[*]", &s->emc[i], TYPE_NPCM7XX_EMC);
102
+ }
17
}
103
}
18
104
19
+/* Advanced SIMD two registers and a scalar extension.
105
static void npcm7xx_realize(DeviceState *dev, Error **errp)
20
+ * 31 24 23 22 20 16 12 11 10 9 8 3 0
106
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
21
+ * +-----------------+----+---+----+----+----+---+----+---+----+---------+----+
107
sysbus_connect_irq(sbd, i, npcm7xx_irq(s, NPCM7XX_PWM0_IRQ + i));
22
+ * | 1 1 1 1 1 1 1 0 | o1 | D | o2 | Vn | Vd | 1 | o3 | 0 | o4 | N Q M U | Vm |
108
}
23
+ * +-----------------+----+---+----+----+----+---+----+---+----+---------+----+
109
24
+ *
110
+ /*
25
+ */
111
+ * EMC Modules. Cannot fail.
26
+
112
+ * The mapping of the device to its netdev backend works as follows:
27
+static int disas_neon_insn_2reg_scalar_ext(DisasContext *s, uint32_t insn)
113
+ * emc[i] = nd_table[i]
28
+{
114
+ * This works around the inability to specify the netdev property for the
29
+ int rd, rn, rm, rot, size, opr_sz;
115
+ * emc device: it's not pluggable and thus the -device option can't be
30
+ TCGv_ptr fpst;
116
+ * used.
31
+ bool q;
117
+ */
32
+
118
+ QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_emc_addr) != ARRAY_SIZE(s->emc));
33
+ q = extract32(insn, 6, 1);
119
+ QEMU_BUILD_BUG_ON(ARRAY_SIZE(s->emc) != 2);
34
+ VFP_DREG_D(rd, insn);
120
+ for (i = 0; i < ARRAY_SIZE(s->emc); i++) {
35
+ VFP_DREG_N(rn, insn);
121
+ s->emc[i].emc_num = i;
36
+ VFP_DREG_M(rm, insn);
122
+ SysBusDevice *sbd = SYS_BUS_DEVICE(&s->emc[i]);
37
+ if ((rd | rn) & q) {
123
+ if (nd_table[i].used) {
38
+ return 1;
124
+ qemu_check_nic_model(&nd_table[i], TYPE_NPCM7XX_EMC);
125
+ qdev_set_nic_properties(DEVICE(sbd), &nd_table[i]);
126
+ }
127
+ /*
128
+ * The device exists regardless of whether it's connected to a QEMU
129
+ * netdev backend. So always instantiate it even if there is no
130
+ * backend.
131
+ */
132
+ sysbus_realize(sbd, &error_abort);
133
+ sysbus_mmio_map(sbd, 0, npcm7xx_emc_addr[i]);
134
+ int tx_irq = i == 0 ? NPCM7XX_EMC1TX_IRQ : NPCM7XX_EMC2TX_IRQ;
135
+ int rx_irq = i == 0 ? NPCM7XX_EMC1RX_IRQ : NPCM7XX_EMC2RX_IRQ;
136
+ /*
137
+ * N.B. The values for the second argument sysbus_connect_irq are
138
+ * chosen to match the registration order in npcm7xx_emc_realize.
139
+ */
140
+ sysbus_connect_irq(sbd, 0, npcm7xx_irq(s, tx_irq));
141
+ sysbus_connect_irq(sbd, 1, npcm7xx_irq(s, rx_irq));
39
+ }
142
+ }
40
+
143
+
41
+ if ((insn & 0xff000f10) == 0xfe000800) {
144
/*
42
+ /* VCMLA (indexed) -- 1111 1110 S.RR .... .... 1000 ...0 .... */
145
* Flash Interface Unit (FIU). Can fail if incorrect number of chip selects
43
+ rot = extract32(insn, 20, 2);
146
* specified, but this is a programming error.
44
+ size = extract32(insn, 23, 1);
147
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
45
+ if (!arm_dc_feature(s, ARM_FEATURE_V8_FCMA)
148
create_unimplemented_device("npcm7xx.vcd", 0xf0810000, 64 * KiB);
46
+ || (!size && !arm_dc_feature(s, ARM_FEATURE_V8_FP16))) {
149
create_unimplemented_device("npcm7xx.ece", 0xf0820000, 8 * KiB);
47
+ return 1;
150
create_unimplemented_device("npcm7xx.vdma", 0xf0822000, 8 * KiB);
48
+ }
151
- create_unimplemented_device("npcm7xx.emc1", 0xf0825000, 4 * KiB);
49
+ } else {
152
- create_unimplemented_device("npcm7xx.emc2", 0xf0826000, 4 * KiB);
50
+ return 1;
153
create_unimplemented_device("npcm7xx.usbd[0]", 0xf0830000, 4 * KiB);
51
+ }
154
create_unimplemented_device("npcm7xx.usbd[1]", 0xf0831000, 4 * KiB);
52
+
155
create_unimplemented_device("npcm7xx.usbd[2]", 0xf0832000, 4 * KiB);
53
+ if (s->fp_excp_el) {
54
+ gen_exception_insn(s, 4, EXCP_UDEF,
55
+ syn_fp_access_trap(1, 0xe, false), s->fp_excp_el);
56
+ return 0;
57
+ }
58
+ if (!s->vfp_enabled) {
59
+ return 1;
60
+ }
61
+
62
+ opr_sz = (1 + q) * 8;
63
+ fpst = get_fpstatus_ptr(1);
64
+ tcg_gen_gvec_3_ptr(vfp_reg_offset(1, rd),
65
+ vfp_reg_offset(1, rn),
66
+ vfp_reg_offset(1, rm), fpst,
67
+ opr_sz, opr_sz, rot,
68
+ size ? gen_helper_gvec_fcmlas_idx
69
+ : gen_helper_gvec_fcmlah_idx);
70
+ tcg_temp_free_ptr(fpst);
71
+ return 0;
72
+}
73
+
74
static int disas_coproc_insn(DisasContext *s, uint32_t insn)
75
{
76
int cpnum, is64, crn, crm, opc1, opc2, isread, rt, rt2;
77
@@ -XXX,XX +XXX,XX @@ static void disas_arm_insn(DisasContext *s, unsigned int insn)
78
goto illegal_op;
79
}
80
return;
81
+ } else if ((insn & 0x0f000a00) == 0x0e000800
82
+ && arm_dc_feature(s, ARM_FEATURE_V8)) {
83
+ if (disas_neon_insn_2reg_scalar_ext(s, insn)) {
84
+ goto illegal_op;
85
+ }
86
+ return;
87
} else if ((insn & 0x0fe00000) == 0x0c400000) {
88
/* Coprocessor double register transfer. */
89
ARCH(5TE);
90
--
156
--
91
2.16.2
157
2.20.1
92
158
93
159
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Doug Evans <dje@google.com>
2
2
3
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
3
Reviewed-by: Hao Wu <wuhaotsh@google.com>
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
4
Reviewed-by: Avi Fishman <avi.fishman@nuvoton.com>
5
Message-id: 20180228193125.20577-5-richard.henderson@linaro.org
5
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Doug Evans <dje@google.com>
7
Message-id: 20210218212453.831406-4-dje@google.com
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
---
9
---
8
target/arm/Makefile.objs | 2 +-
10
tests/qtest/npcm7xx_emc-test.c | 862 +++++++++++++++++++++++++++++++++
9
target/arm/helper.h | 4 ++
11
tests/qtest/meson.build | 3 +-
10
target/arm/translate-a64.c | 84 ++++++++++++++++++++++++++++++++++
12
2 files changed, 864 insertions(+), 1 deletion(-)
11
target/arm/vec_helper.c | 109 +++++++++++++++++++++++++++++++++++++++++++++
13
create mode 100644 tests/qtest/npcm7xx_emc-test.c
12
4 files changed, 198 insertions(+), 1 deletion(-)
13
create mode 100644 target/arm/vec_helper.c
14
14
15
diff --git a/target/arm/Makefile.objs b/target/arm/Makefile.objs
15
diff --git a/tests/qtest/npcm7xx_emc-test.c b/tests/qtest/npcm7xx_emc-test.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/target/arm/Makefile.objs
18
+++ b/target/arm/Makefile.objs
19
@@ -XXX,XX +XXX,XX @@ obj-$(call land,$(CONFIG_KVM),$(call lnot,$(TARGET_AARCH64))) += kvm32.o
20
obj-$(call land,$(CONFIG_KVM),$(TARGET_AARCH64)) += kvm64.o
21
obj-$(call lnot,$(CONFIG_KVM)) += kvm-stub.o
22
obj-y += translate.o op_helper.o helper.o cpu.o
23
-obj-y += neon_helper.o iwmmxt_helper.o
24
+obj-y += neon_helper.o iwmmxt_helper.o vec_helper.o
25
obj-y += gdbstub.o
26
obj-$(TARGET_AARCH64) += cpu64.o translate-a64.o helper-a64.o gdbstub64.o
27
obj-y += crypto_helper.o
28
diff --git a/target/arm/helper.h b/target/arm/helper.h
29
index XXXXXXX..XXXXXXX 100644
30
--- a/target/arm/helper.h
31
+++ b/target/arm/helper.h
32
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_1(neon_rbit_u8, TCG_CALL_NO_RWG_SE, i32, i32)
33
34
DEF_HELPER_3(neon_qdmulh_s16, i32, env, i32, i32)
35
DEF_HELPER_3(neon_qrdmulh_s16, i32, env, i32, i32)
36
+DEF_HELPER_4(neon_qrdmlah_s16, i32, env, i32, i32, i32)
37
+DEF_HELPER_4(neon_qrdmlsh_s16, i32, env, i32, i32, i32)
38
DEF_HELPER_3(neon_qdmulh_s32, i32, env, i32, i32)
39
DEF_HELPER_3(neon_qrdmulh_s32, i32, env, i32, i32)
40
+DEF_HELPER_4(neon_qrdmlah_s32, i32, env, s32, s32, s32)
41
+DEF_HELPER_4(neon_qrdmlsh_s32, i32, env, s32, s32, s32)
42
43
DEF_HELPER_1(neon_narrow_u8, i32, i64)
44
DEF_HELPER_1(neon_narrow_u16, i32, i64)
45
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
46
index XXXXXXX..XXXXXXX 100644
47
--- a/target/arm/translate-a64.c
48
+++ b/target/arm/translate-a64.c
49
@@ -XXX,XX +XXX,XX @@ static void disas_simd_scalar_three_reg_same_fp16(DisasContext *s,
50
tcg_temp_free_ptr(fpst);
51
}
52
53
+/* AdvSIMD scalar three same extra
54
+ * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
55
+ * +-----+---+-----------+------+---+------+---+--------+---+----+----+
56
+ * | 0 1 | U | 1 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
57
+ * +-----+---+-----------+------+---+------+---+--------+---+----+----+
58
+ */
59
+static void disas_simd_scalar_three_reg_same_extra(DisasContext *s,
60
+ uint32_t insn)
61
+{
62
+ int rd = extract32(insn, 0, 5);
63
+ int rn = extract32(insn, 5, 5);
64
+ int opcode = extract32(insn, 11, 4);
65
+ int rm = extract32(insn, 16, 5);
66
+ int size = extract32(insn, 22, 2);
67
+ bool u = extract32(insn, 29, 1);
68
+ TCGv_i32 ele1, ele2, ele3;
69
+ TCGv_i64 res;
70
+ int feature;
71
+
72
+ switch (u * 16 + opcode) {
73
+ case 0x10: /* SQRDMLAH (vector) */
74
+ case 0x11: /* SQRDMLSH (vector) */
75
+ if (size != 1 && size != 2) {
76
+ unallocated_encoding(s);
77
+ return;
78
+ }
79
+ feature = ARM_FEATURE_V8_RDM;
80
+ break;
81
+ default:
82
+ unallocated_encoding(s);
83
+ return;
84
+ }
85
+ if (!arm_dc_feature(s, feature)) {
86
+ unallocated_encoding(s);
87
+ return;
88
+ }
89
+ if (!fp_access_check(s)) {
90
+ return;
91
+ }
92
+
93
+ /* Do a single operation on the lowest element in the vector.
94
+ * We use the standard Neon helpers and rely on 0 OP 0 == 0
95
+ * with no side effects for all these operations.
96
+ * OPTME: special-purpose helpers would avoid doing some
97
+ * unnecessary work in the helper for the 16 bit cases.
98
+ */
99
+ ele1 = tcg_temp_new_i32();
100
+ ele2 = tcg_temp_new_i32();
101
+ ele3 = tcg_temp_new_i32();
102
+
103
+ read_vec_element_i32(s, ele1, rn, 0, size);
104
+ read_vec_element_i32(s, ele2, rm, 0, size);
105
+ read_vec_element_i32(s, ele3, rd, 0, size);
106
+
107
+ switch (opcode) {
108
+ case 0x0: /* SQRDMLAH */
109
+ if (size == 1) {
110
+ gen_helper_neon_qrdmlah_s16(ele3, cpu_env, ele1, ele2, ele3);
111
+ } else {
112
+ gen_helper_neon_qrdmlah_s32(ele3, cpu_env, ele1, ele2, ele3);
113
+ }
114
+ break;
115
+ case 0x1: /* SQRDMLSH */
116
+ if (size == 1) {
117
+ gen_helper_neon_qrdmlsh_s16(ele3, cpu_env, ele1, ele2, ele3);
118
+ } else {
119
+ gen_helper_neon_qrdmlsh_s32(ele3, cpu_env, ele1, ele2, ele3);
120
+ }
121
+ break;
122
+ default:
123
+ g_assert_not_reached();
124
+ }
125
+ tcg_temp_free_i32(ele1);
126
+ tcg_temp_free_i32(ele2);
127
+
128
+ res = tcg_temp_new_i64();
129
+ tcg_gen_extu_i32_i64(res, ele3);
130
+ tcg_temp_free_i32(ele3);
131
+
132
+ write_fp_dreg(s, rd, res);
133
+ tcg_temp_free_i64(res);
134
+}
135
+
136
static void handle_2misc_64(DisasContext *s, int opcode, bool u,
137
TCGv_i64 tcg_rd, TCGv_i64 tcg_rn,
138
TCGv_i32 tcg_rmode, TCGv_ptr tcg_fpstatus)
139
@@ -XXX,XX +XXX,XX @@ static const AArch64DecodeTable data_proc_simd[] = {
140
{ 0x0e000800, 0xbf208c00, disas_simd_zip_trn },
141
{ 0x2e000000, 0xbf208400, disas_simd_ext },
142
{ 0x5e200400, 0xdf200400, disas_simd_scalar_three_reg_same },
143
+ { 0x5e008400, 0xdf208400, disas_simd_scalar_three_reg_same_extra },
144
{ 0x5e200000, 0xdf200c00, disas_simd_scalar_three_reg_diff },
145
{ 0x5e200800, 0xdf3e0c00, disas_simd_scalar_two_reg_misc },
146
{ 0x5e300800, 0xdf3e0c00, disas_simd_scalar_pairwise },
147
diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c
148
new file mode 100644
16
new file mode 100644
149
index XXXXXXX..XXXXXXX
17
index XXXXXXX..XXXXXXX
150
--- /dev/null
18
--- /dev/null
151
+++ b/target/arm/vec_helper.c
19
+++ b/tests/qtest/npcm7xx_emc-test.c
152
@@ -XXX,XX +XXX,XX @@
20
@@ -XXX,XX +XXX,XX @@
153
+/*
21
+/*
154
+ * ARM AdvSIMD / SVE Vector Operations
22
+ * QTests for Nuvoton NPCM7xx EMC Modules.
155
+ *
23
+ *
156
+ * Copyright (c) 2018 Linaro
24
+ * Copyright 2020 Google LLC
157
+ *
25
+ *
158
+ * This library is free software; you can redistribute it and/or
26
+ * This program is free software; you can redistribute it and/or modify it
159
+ * modify it under the terms of the GNU Lesser General Public
27
+ * under the terms of the GNU General Public License as published by the
160
+ * License as published by the Free Software Foundation; either
28
+ * Free Software Foundation; either version 2 of the License, or
161
+ * version 2 of the License, or (at your option) any later version.
29
+ * (at your option) any later version.
162
+ *
30
+ *
163
+ * This library is distributed in the hope that it will be useful,
31
+ * This program is distributed in the hope that it will be useful, but WITHOUT
164
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
32
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
165
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
166
+ * Lesser General Public License for more details.
34
+ * for more details.
167
+ *
168
+ * You should have received a copy of the GNU Lesser General Public
169
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
170
+ */
35
+ */
171
+
36
+
172
+#include "qemu/osdep.h"
37
+#include "qemu/osdep.h"
173
+#include "cpu.h"
38
+#include "qemu-common.h"
174
+#include "exec/exec-all.h"
39
+#include "libqos/libqos.h"
175
+#include "exec/helper-proto.h"
40
+#include "qapi/qmp/qdict.h"
176
+#include "tcg/tcg-gvec-desc.h"
41
+#include "qapi/qmp/qnum.h"
177
+
42
+#include "qemu/bitops.h"
178
+
43
+#include "qemu/iov.h"
179
+#define SET_QC() env->vfp.xregs[ARM_VFP_FPSCR] |= CPSR_Q
44
+
180
+
45
+/* Name of the emc device. */
181
+/* Signed saturating rounding doubling multiply-accumulate high half, 16-bit */
46
+#define TYPE_NPCM7XX_EMC "npcm7xx-emc"
182
+static uint16_t inl_qrdmlah_s16(CPUARMState *env, int16_t src1,
47
+
183
+ int16_t src2, int16_t src3)
48
+/* Timeout for various operations, in seconds. */
184
+{
49
+#define TIMEOUT_SECONDS 10
185
+ /* Simplify:
50
+
186
+ * = ((a3 << 16) + ((e1 * e2) << 1) + (1 << 15)) >> 16
51
+/* Address in memory of the descriptor. */
187
+ * = ((a3 << 15) + (e1 * e2) + (1 << 14)) >> 15
52
+#define DESC_ADDR (1 << 20) /* 1 MiB */
53
+
54
+/* Address in memory of the data packet. */
55
+#define DATA_ADDR (DESC_ADDR + 4096)
56
+
57
+#define CRC_LENGTH 4
58
+
59
+#define NUM_TX_DESCRIPTORS 3
60
+#define NUM_RX_DESCRIPTORS 2
61
+
62
+/* Size of tx,rx test buffers. */
63
+#define TX_DATA_LEN 64
64
+#define RX_DATA_LEN 64
65
+
66
+#define TX_STEP_COUNT 10000
67
+#define RX_STEP_COUNT 10000
68
+
69
+/* 32-bit register indices. */
70
+typedef enum NPCM7xxPWMRegister {
71
+ /* Control registers. */
72
+ REG_CAMCMR,
73
+ REG_CAMEN,
74
+
75
+ /* There are 16 CAMn[ML] registers. */
76
+ REG_CAMM_BASE,
77
+ REG_CAML_BASE,
78
+
79
+ REG_TXDLSA = 0x22,
80
+ REG_RXDLSA,
81
+ REG_MCMDR,
82
+ REG_MIID,
83
+ REG_MIIDA,
84
+ REG_FFTCR,
85
+ REG_TSDR,
86
+ REG_RSDR,
87
+ REG_DMARFC,
88
+ REG_MIEN,
89
+
90
+ /* Status registers. */
91
+ REG_MISTA,
92
+ REG_MGSTA,
93
+ REG_MPCNT,
94
+ REG_MRPC,
95
+ REG_MRPCC,
96
+ REG_MREPC,
97
+ REG_DMARFS,
98
+ REG_CTXDSA,
99
+ REG_CTXBSA,
100
+ REG_CRXDSA,
101
+ REG_CRXBSA,
102
+
103
+ NPCM7XX_NUM_EMC_REGS,
104
+} NPCM7xxPWMRegister;
105
+
106
+enum { NUM_CAMML_REGS = 16 };
107
+
108
+/* REG_CAMCMR fields */
109
+/* Enable CAM Compare */
110
+#define REG_CAMCMR_ECMP (1 << 4)
111
+/* Accept Unicast Packet */
112
+#define REG_CAMCMR_AUP (1 << 0)
113
+
114
+/* REG_MCMDR fields */
115
+/* Software Reset */
116
+#define REG_MCMDR_SWR (1 << 24)
117
+/* Frame Transmission On */
118
+#define REG_MCMDR_TXON (1 << 8)
119
+/* Accept Long Packet */
120
+#define REG_MCMDR_ALP (1 << 1)
121
+/* Frame Reception On */
122
+#define REG_MCMDR_RXON (1 << 0)
123
+
124
+/* REG_MIEN fields */
125
+/* Enable Transmit Completion Interrupt */
126
+#define REG_MIEN_ENTXCP (1 << 18)
127
+/* Enable Transmit Interrupt */
128
+#define REG_MIEN_ENTXINTR (1 << 16)
129
+/* Enable Receive Good Interrupt */
130
+#define REG_MIEN_ENRXGD (1 << 4)
131
+/* ENable Receive Interrupt */
132
+#define REG_MIEN_ENRXINTR (1 << 0)
133
+
134
+/* REG_MISTA fields */
135
+/* Transmit Bus Error Interrupt */
136
+#define REG_MISTA_TXBERR (1 << 24)
137
+/* Transmit Descriptor Unavailable Interrupt */
138
+#define REG_MISTA_TDU (1 << 23)
139
+/* Transmit Completion Interrupt */
140
+#define REG_MISTA_TXCP (1 << 18)
141
+/* Transmit Interrupt */
142
+#define REG_MISTA_TXINTR (1 << 16)
143
+/* Receive Bus Error Interrupt */
144
+#define REG_MISTA_RXBERR (1 << 11)
145
+/* Receive Descriptor Unavailable Interrupt */
146
+#define REG_MISTA_RDU (1 << 10)
147
+/* DMA Early Notification Interrupt */
148
+#define REG_MISTA_DENI (1 << 9)
149
+/* Maximum Frame Length Interrupt */
150
+#define REG_MISTA_DFOI (1 << 8)
151
+/* Receive Good Interrupt */
152
+#define REG_MISTA_RXGD (1 << 4)
153
+/* Packet Too Long Interrupt */
154
+#define REG_MISTA_PTLE (1 << 3)
155
+/* Receive Interrupt */
156
+#define REG_MISTA_RXINTR (1 << 0)
157
+
158
+typedef struct NPCM7xxEMCTxDesc NPCM7xxEMCTxDesc;
159
+typedef struct NPCM7xxEMCRxDesc NPCM7xxEMCRxDesc;
160
+
161
+struct NPCM7xxEMCTxDesc {
162
+ uint32_t flags;
163
+ uint32_t txbsa;
164
+ uint32_t status_and_length;
165
+ uint32_t ntxdsa;
166
+};
167
+
168
+struct NPCM7xxEMCRxDesc {
169
+ uint32_t status_and_length;
170
+ uint32_t rxbsa;
171
+ uint32_t reserved;
172
+ uint32_t nrxdsa;
173
+};
174
+
175
+/* NPCM7xxEMCTxDesc.flags values */
176
+/* Owner: 0 = cpu, 1 = emc */
177
+#define TX_DESC_FLAG_OWNER_MASK (1 << 31)
178
+/* Transmit interrupt enable */
179
+#define TX_DESC_FLAG_INTEN (1 << 2)
180
+
181
+/* NPCM7xxEMCTxDesc.status_and_length values */
182
+/* Transmission complete */
183
+#define TX_DESC_STATUS_TXCP (1 << 19)
184
+/* Transmit interrupt */
185
+#define TX_DESC_STATUS_TXINTR (1 << 16)
186
+
187
+/* NPCM7xxEMCRxDesc.status_and_length values */
188
+/* Owner: 0b00 = cpu, 0b10 = emc */
189
+#define RX_DESC_STATUS_OWNER_SHIFT 30
190
+#define RX_DESC_STATUS_OWNER_MASK 0xc0000000
191
+/* Frame Reception Complete */
192
+#define RX_DESC_STATUS_RXGD (1 << 20)
193
+/* Packet too long */
194
+#define RX_DESC_STATUS_PTLE (1 << 19)
195
+/* Receive Interrupt */
196
+#define RX_DESC_STATUS_RXINTR (1 << 16)
197
+
198
+#define RX_DESC_PKT_LEN(word) ((uint32_t) (word) & 0xffff)
199
+
200
+typedef struct EMCModule {
201
+ int rx_irq;
202
+ int tx_irq;
203
+ uint64_t base_addr;
204
+} EMCModule;
205
+
206
+typedef struct TestData {
207
+ const EMCModule *module;
208
+} TestData;
209
+
210
+static const EMCModule emc_module_list[] = {
211
+ {
212
+ .rx_irq = 15,
213
+ .tx_irq = 16,
214
+ .base_addr = 0xf0825000
215
+ },
216
+ {
217
+ .rx_irq = 114,
218
+ .tx_irq = 115,
219
+ .base_addr = 0xf0826000
220
+ }
221
+};
222
+
223
+/* Returns the index of the EMC module. */
224
+static int emc_module_index(const EMCModule *mod)
225
+{
226
+ ptrdiff_t diff = mod - emc_module_list;
227
+
228
+ g_assert_true(diff >= 0 && diff < ARRAY_SIZE(emc_module_list));
229
+
230
+ return diff;
231
+}
232
+
233
+static void packet_test_clear(void *sockets)
234
+{
235
+ int *test_sockets = sockets;
236
+
237
+ close(test_sockets[0]);
238
+ g_free(test_sockets);
239
+}
240
+
241
+static int *packet_test_init(int module_num, GString *cmd_line)
242
+{
243
+ int *test_sockets = g_new(int, 2);
244
+ int ret = socketpair(PF_UNIX, SOCK_STREAM, 0, test_sockets);
245
+ g_assert_cmpint(ret, != , -1);
246
+
247
+ /*
248
+ * KISS and use -nic. We specify two nics (both emc{0,1}) because there's
249
+ * currently no way to specify only emc1: The driver implicitly relies on
250
+ * emc[i] == nd_table[i].
188
+ */
251
+ */
189
+ int32_t ret = (int32_t)src1 * src2;
252
+ if (module_num == 0) {
190
+ ret = ((int32_t)src3 << 15) + ret + (1 << 14);
253
+ g_string_append_printf(cmd_line,
191
+ ret >>= 15;
254
+ " -nic socket,fd=%d,model=" TYPE_NPCM7XX_EMC " "
192
+ if (ret != (int16_t)ret) {
255
+ " -nic user,model=" TYPE_NPCM7XX_EMC " ",
193
+ SET_QC();
256
+ test_sockets[1]);
194
+ ret = (ret < 0 ? -0x8000 : 0x7fff);
257
+ } else {
195
+ }
258
+ g_string_append_printf(cmd_line,
196
+ return ret;
259
+ " -nic user,model=" TYPE_NPCM7XX_EMC " "
197
+}
260
+ " -nic socket,fd=%d,model=" TYPE_NPCM7XX_EMC " ",
198
+
261
+ test_sockets[1]);
199
+uint32_t HELPER(neon_qrdmlah_s16)(CPUARMState *env, uint32_t src1,
262
+ }
200
+ uint32_t src2, uint32_t src3)
263
+
201
+{
264
+ g_test_queue_destroy(packet_test_clear, test_sockets);
202
+ uint16_t e1 = inl_qrdmlah_s16(env, src1, src2, src3);
265
+ return test_sockets;
203
+ uint16_t e2 = inl_qrdmlah_s16(env, src1 >> 16, src2 >> 16, src3 >> 16);
266
+}
204
+ return deposit32(e1, 16, 16, e2);
267
+
205
+}
268
+static uint32_t emc_read(QTestState *qts, const EMCModule *mod,
206
+
269
+ NPCM7xxPWMRegister regno)
207
+/* Signed saturating rounding doubling multiply-subtract high half, 16-bit */
270
+{
208
+static uint16_t inl_qrdmlsh_s16(CPUARMState *env, int16_t src1,
271
+ return qtest_readl(qts, mod->base_addr + regno * sizeof(uint32_t));
209
+ int16_t src2, int16_t src3)
272
+}
210
+{
273
+
211
+ /* Similarly, using subtraction:
274
+static void emc_write(QTestState *qts, const EMCModule *mod,
212
+ * = ((a3 << 16) - ((e1 * e2) << 1) + (1 << 15)) >> 16
275
+ NPCM7xxPWMRegister regno, uint32_t value)
213
+ * = ((a3 << 15) - (e1 * e2) + (1 << 14)) >> 15
276
+{
277
+ qtest_writel(qts, mod->base_addr + regno * sizeof(uint32_t), value);
278
+}
279
+
280
+static void emc_read_tx_desc(QTestState *qts, uint32_t addr,
281
+ NPCM7xxEMCTxDesc *desc)
282
+{
283
+ qtest_memread(qts, addr, desc, sizeof(*desc));
284
+ desc->flags = le32_to_cpu(desc->flags);
285
+ desc->txbsa = le32_to_cpu(desc->txbsa);
286
+ desc->status_and_length = le32_to_cpu(desc->status_and_length);
287
+ desc->ntxdsa = le32_to_cpu(desc->ntxdsa);
288
+}
289
+
290
+static void emc_write_tx_desc(QTestState *qts, const NPCM7xxEMCTxDesc *desc,
291
+ uint32_t addr)
292
+{
293
+ NPCM7xxEMCTxDesc le_desc;
294
+
295
+ le_desc.flags = cpu_to_le32(desc->flags);
296
+ le_desc.txbsa = cpu_to_le32(desc->txbsa);
297
+ le_desc.status_and_length = cpu_to_le32(desc->status_and_length);
298
+ le_desc.ntxdsa = cpu_to_le32(desc->ntxdsa);
299
+ qtest_memwrite(qts, addr, &le_desc, sizeof(le_desc));
300
+}
301
+
302
+static void emc_read_rx_desc(QTestState *qts, uint32_t addr,
303
+ NPCM7xxEMCRxDesc *desc)
304
+{
305
+ qtest_memread(qts, addr, desc, sizeof(*desc));
306
+ desc->status_and_length = le32_to_cpu(desc->status_and_length);
307
+ desc->rxbsa = le32_to_cpu(desc->rxbsa);
308
+ desc->reserved = le32_to_cpu(desc->reserved);
309
+ desc->nrxdsa = le32_to_cpu(desc->nrxdsa);
310
+}
311
+
312
+static void emc_write_rx_desc(QTestState *qts, const NPCM7xxEMCRxDesc *desc,
313
+ uint32_t addr)
314
+{
315
+ NPCM7xxEMCRxDesc le_desc;
316
+
317
+ le_desc.status_and_length = cpu_to_le32(desc->status_and_length);
318
+ le_desc.rxbsa = cpu_to_le32(desc->rxbsa);
319
+ le_desc.reserved = cpu_to_le32(desc->reserved);
320
+ le_desc.nrxdsa = cpu_to_le32(desc->nrxdsa);
321
+ qtest_memwrite(qts, addr, &le_desc, sizeof(le_desc));
322
+}
323
+
324
+/*
325
+ * Reset the EMC module.
326
+ * The module must be reset before, e.g., TXDLSA,RXDLSA are changed.
327
+ */
328
+static bool emc_soft_reset(QTestState *qts, const EMCModule *mod)
329
+{
330
+ uint32_t val;
331
+ uint64_t end_time;
332
+
333
+ emc_write(qts, mod, REG_MCMDR, REG_MCMDR_SWR);
334
+
335
+ /*
336
+ * Wait for device to reset as the linux driver does.
337
+ * During reset the AHB reads 0 for all registers. So first wait for
338
+ * something that resets to non-zero, and then wait for SWR becoming 0.
214
+ */
339
+ */
215
+ int32_t ret = (int32_t)src1 * src2;
340
+ end_time = g_get_monotonic_time() + TIMEOUT_SECONDS * G_TIME_SPAN_SECOND;
216
+ ret = ((int32_t)src3 << 15) - ret + (1 << 14);
341
+
217
+ ret >>= 15;
342
+ do {
218
+ if (ret != (int16_t)ret) {
343
+ qtest_clock_step(qts, 100);
219
+ SET_QC();
344
+ val = emc_read(qts, mod, REG_FFTCR);
220
+ ret = (ret < 0 ? -0x8000 : 0x7fff);
345
+ } while (val == 0 && g_get_monotonic_time() < end_time);
221
+ }
346
+ if (val != 0) {
222
+ return ret;
347
+ do {
223
+}
348
+ qtest_clock_step(qts, 100);
224
+
349
+ val = emc_read(qts, mod, REG_MCMDR);
225
+uint32_t HELPER(neon_qrdmlsh_s16)(CPUARMState *env, uint32_t src1,
350
+ if ((val & REG_MCMDR_SWR) == 0) {
226
+ uint32_t src2, uint32_t src3)
351
+ /*
227
+{
352
+ * N.B. The CAMs have been reset here, so macaddr matching of
228
+ uint16_t e1 = inl_qrdmlsh_s16(env, src1, src2, src3);
353
+ * incoming packets will not work.
229
+ uint16_t e2 = inl_qrdmlsh_s16(env, src1 >> 16, src2 >> 16, src3 >> 16);
354
+ */
230
+ return deposit32(e1, 16, 16, e2);
355
+ return true;
231
+}
356
+ }
232
+
357
+ } while (g_get_monotonic_time() < end_time);
233
+/* Signed saturating rounding doubling multiply-accumulate high half, 32-bit */
358
+ }
234
+uint32_t HELPER(neon_qrdmlah_s32)(CPUARMState *env, int32_t src1,
359
+
235
+ int32_t src2, int32_t src3)
360
+ g_message("%s: Timeout expired", __func__);
236
+{
361
+ return false;
237
+ /* Simplify similarly to int_qrdmlah_s16 above. */
362
+}
238
+ int64_t ret = (int64_t)src1 * src2;
363
+
239
+ ret = ((int64_t)src3 << 31) + ret + (1 << 30);
364
+/* Check emc registers are reset to default value. */
240
+ ret >>= 31;
365
+static void test_init(gconstpointer test_data)
241
+ if (ret != (int32_t)ret) {
366
+{
242
+ SET_QC();
367
+ const TestData *td = test_data;
243
+ ret = (ret < 0 ? INT32_MIN : INT32_MAX);
368
+ const EMCModule *mod = td->module;
244
+ }
369
+ QTestState *qts = qtest_init("-machine quanta-gsj");
245
+ return ret;
370
+ int i;
246
+}
371
+
247
+
372
+#define CHECK_REG(regno, value) \
248
+/* Signed saturating rounding doubling multiply-subtract high half, 32-bit */
373
+ do { \
249
+uint32_t HELPER(neon_qrdmlsh_s32)(CPUARMState *env, int32_t src1,
374
+ g_assert_cmphex(emc_read(qts, mod, (regno)), ==, (value)); \
250
+ int32_t src2, int32_t src3)
375
+ } while (0)
251
+{
376
+
252
+ /* Simplify similarly to int_qrdmlsh_s16 above. */
377
+ CHECK_REG(REG_CAMCMR, 0);
253
+ int64_t ret = (int64_t)src1 * src2;
378
+ CHECK_REG(REG_CAMEN, 0);
254
+ ret = ((int64_t)src3 << 31) - ret + (1 << 30);
379
+ CHECK_REG(REG_TXDLSA, 0xfffffffc);
255
+ ret >>= 31;
380
+ CHECK_REG(REG_RXDLSA, 0xfffffffc);
256
+ if (ret != (int32_t)ret) {
381
+ CHECK_REG(REG_MCMDR, 0);
257
+ SET_QC();
382
+ CHECK_REG(REG_MIID, 0);
258
+ ret = (ret < 0 ? INT32_MIN : INT32_MAX);
383
+ CHECK_REG(REG_MIIDA, 0x00900000);
259
+ }
384
+ CHECK_REG(REG_FFTCR, 0x0101);
260
+ return ret;
385
+ CHECK_REG(REG_DMARFC, 0x0800);
261
+}
386
+ CHECK_REG(REG_MIEN, 0);
387
+ CHECK_REG(REG_MISTA, 0);
388
+ CHECK_REG(REG_MGSTA, 0);
389
+ CHECK_REG(REG_MPCNT, 0x7fff);
390
+ CHECK_REG(REG_MRPC, 0);
391
+ CHECK_REG(REG_MRPCC, 0);
392
+ CHECK_REG(REG_MREPC, 0);
393
+ CHECK_REG(REG_DMARFS, 0);
394
+ CHECK_REG(REG_CTXDSA, 0);
395
+ CHECK_REG(REG_CTXBSA, 0);
396
+ CHECK_REG(REG_CRXDSA, 0);
397
+ CHECK_REG(REG_CRXBSA, 0);
398
+
399
+#undef CHECK_REG
400
+
401
+ for (i = 0; i < NUM_CAMML_REGS; ++i) {
402
+ g_assert_cmpuint(emc_read(qts, mod, REG_CAMM_BASE + i * 2), ==,
403
+ 0);
404
+ g_assert_cmpuint(emc_read(qts, mod, REG_CAML_BASE + i * 2), ==,
405
+ 0);
406
+ }
407
+
408
+ qtest_quit(qts);
409
+}
410
+
411
+static bool emc_wait_irq(QTestState *qts, const EMCModule *mod, int step,
412
+ bool is_tx)
413
+{
414
+ uint64_t end_time =
415
+ g_get_monotonic_time() + TIMEOUT_SECONDS * G_TIME_SPAN_SECOND;
416
+
417
+ do {
418
+ if (qtest_get_irq(qts, is_tx ? mod->tx_irq : mod->rx_irq)) {
419
+ return true;
420
+ }
421
+ qtest_clock_step(qts, step);
422
+ } while (g_get_monotonic_time() < end_time);
423
+
424
+ g_message("%s: Timeout expired", __func__);
425
+ return false;
426
+}
427
+
428
+static bool emc_wait_mista(QTestState *qts, const EMCModule *mod, int step,
429
+ uint32_t flag)
430
+{
431
+ uint64_t end_time =
432
+ g_get_monotonic_time() + TIMEOUT_SECONDS * G_TIME_SPAN_SECOND;
433
+
434
+ do {
435
+ uint32_t mista = emc_read(qts, mod, REG_MISTA);
436
+ if (mista & flag) {
437
+ return true;
438
+ }
439
+ qtest_clock_step(qts, step);
440
+ } while (g_get_monotonic_time() < end_time);
441
+
442
+ g_message("%s: Timeout expired", __func__);
443
+ return false;
444
+}
445
+
446
+static bool wait_socket_readable(int fd)
447
+{
448
+ fd_set read_fds;
449
+ struct timeval tv;
450
+ int rv;
451
+
452
+ FD_ZERO(&read_fds);
453
+ FD_SET(fd, &read_fds);
454
+ tv.tv_sec = TIMEOUT_SECONDS;
455
+ tv.tv_usec = 0;
456
+ rv = select(fd + 1, &read_fds, NULL, NULL, &tv);
457
+ if (rv == -1) {
458
+ perror("select");
459
+ } else if (rv == 0) {
460
+ g_message("%s: Timeout expired", __func__);
461
+ }
462
+ return rv == 1;
463
+}
464
+
465
+/* Initialize *desc (in host endian format). */
466
+static void init_tx_desc(NPCM7xxEMCTxDesc *desc, size_t count,
467
+ uint32_t desc_addr)
468
+{
469
+ g_assert(count >= 2);
470
+ memset(&desc[0], 0, sizeof(*desc) * count);
471
+ /* Leave the last one alone, owned by the cpu -> stops transmission. */
472
+ for (size_t i = 0; i < count - 1; ++i) {
473
+ desc[i].flags =
474
+ (TX_DESC_FLAG_OWNER_MASK | /* owner = 1: emc */
475
+ TX_DESC_FLAG_INTEN |
476
+ 0 | /* crc append = 0 */
477
+ 0 /* padding enable = 0 */);
478
+ desc[i].status_and_length =
479
+ (0 | /* collision count = 0 */
480
+ 0 | /* SQE = 0 */
481
+ 0 | /* PAU = 0 */
482
+ 0 | /* TXHA = 0 */
483
+ 0 | /* LC = 0 */
484
+ 0 | /* TXABT = 0 */
485
+ 0 | /* NCS = 0 */
486
+ 0 | /* EXDEF = 0 */
487
+ 0 | /* TXCP = 0 */
488
+ 0 | /* DEF = 0 */
489
+ 0 | /* TXINTR = 0 */
490
+ 0 /* length filled in later */);
491
+ desc[i].ntxdsa = desc_addr + (i + 1) * sizeof(*desc);
492
+ }
493
+}
494
+
495
+static void enable_tx(QTestState *qts, const EMCModule *mod,
496
+ const NPCM7xxEMCTxDesc *desc, size_t count,
497
+ uint32_t desc_addr, uint32_t mien_flags)
498
+{
499
+ /* Write the descriptors to guest memory. */
500
+ for (size_t i = 0; i < count; ++i) {
501
+ emc_write_tx_desc(qts, desc + i, desc_addr + i * sizeof(*desc));
502
+ }
503
+
504
+ /* Trigger sending the packet. */
505
+ /* The module must be reset before changing TXDLSA. */
506
+ g_assert(emc_soft_reset(qts, mod));
507
+ emc_write(qts, mod, REG_TXDLSA, desc_addr);
508
+ emc_write(qts, mod, REG_CTXDSA, ~0);
509
+ emc_write(qts, mod, REG_MIEN, REG_MIEN_ENTXCP | mien_flags);
510
+ {
511
+ uint32_t mcmdr = emc_read(qts, mod, REG_MCMDR);
512
+ mcmdr |= REG_MCMDR_TXON;
513
+ emc_write(qts, mod, REG_MCMDR, mcmdr);
514
+ }
515
+
516
+ /* Prod the device to send the packet. */
517
+ emc_write(qts, mod, REG_TSDR, 1);
518
+}
519
+
520
+static void emc_send_verify1(QTestState *qts, const EMCModule *mod, int fd,
521
+ bool with_irq, uint32_t desc_addr,
522
+ uint32_t next_desc_addr,
523
+ const char *test_data, int test_size)
524
+{
525
+ NPCM7xxEMCTxDesc result_desc;
526
+ uint32_t expected_mask, expected_value, recv_len;
527
+ int ret;
528
+ char buffer[TX_DATA_LEN];
529
+
530
+ g_assert(wait_socket_readable(fd));
531
+
532
+ /* Read the descriptor back. */
533
+ emc_read_tx_desc(qts, desc_addr, &result_desc);
534
+ /* Descriptor should be owned by cpu now. */
535
+ g_assert((result_desc.flags & TX_DESC_FLAG_OWNER_MASK) == 0);
536
+ /* Test the status bits, ignoring the length field. */
537
+ expected_mask = 0xffff << 16;
538
+ expected_value = TX_DESC_STATUS_TXCP;
539
+ if (with_irq) {
540
+ expected_value |= TX_DESC_STATUS_TXINTR;
541
+ }
542
+ g_assert_cmphex((result_desc.status_and_length & expected_mask), ==,
543
+ expected_value);
544
+
545
+ /* Check data sent to the backend. */
546
+ recv_len = ~0;
547
+ ret = qemu_recv(fd, &recv_len, sizeof(recv_len), MSG_DONTWAIT);
548
+ g_assert_cmpint(ret, == , sizeof(recv_len));
549
+
550
+ g_assert(wait_socket_readable(fd));
551
+ memset(buffer, 0xff, sizeof(buffer));
552
+ ret = qemu_recv(fd, buffer, test_size, MSG_DONTWAIT);
553
+ g_assert_cmpmem(buffer, ret, test_data, test_size);
554
+}
555
+
556
+static void emc_send_verify(QTestState *qts, const EMCModule *mod, int fd,
557
+ bool with_irq)
558
+{
559
+ NPCM7xxEMCTxDesc desc[NUM_TX_DESCRIPTORS];
560
+ uint32_t desc_addr = DESC_ADDR;
561
+ static const char test1_data[] = "TEST1";
562
+ static const char test2_data[] = "Testing 1 2 3 ...";
563
+ uint32_t data1_addr = DATA_ADDR;
564
+ uint32_t data2_addr = data1_addr + sizeof(test1_data);
565
+ bool got_tdu;
566
+ uint32_t end_desc_addr;
567
+
568
+ /* Prepare test data buffer. */
569
+ qtest_memwrite(qts, data1_addr, test1_data, sizeof(test1_data));
570
+ qtest_memwrite(qts, data2_addr, test2_data, sizeof(test2_data));
571
+
572
+ init_tx_desc(&desc[0], NUM_TX_DESCRIPTORS, desc_addr);
573
+ desc[0].txbsa = data1_addr;
574
+ desc[0].status_and_length |= sizeof(test1_data);
575
+ desc[1].txbsa = data2_addr;
576
+ desc[1].status_and_length |= sizeof(test2_data);
577
+
578
+ enable_tx(qts, mod, &desc[0], NUM_TX_DESCRIPTORS, desc_addr,
579
+ with_irq ? REG_MIEN_ENTXINTR : 0);
580
+
581
+ /*
582
+ * It's problematic to observe the interrupt for each packet.
583
+ * Instead just wait until all the packets go out.
584
+ */
585
+ got_tdu = false;
586
+ while (!got_tdu) {
587
+ if (with_irq) {
588
+ g_assert_true(emc_wait_irq(qts, mod, TX_STEP_COUNT,
589
+ /*is_tx=*/true));
590
+ } else {
591
+ g_assert_true(emc_wait_mista(qts, mod, TX_STEP_COUNT,
592
+ REG_MISTA_TXINTR));
593
+ }
594
+ got_tdu = !!(emc_read(qts, mod, REG_MISTA) & REG_MISTA_TDU);
595
+ /* If we don't have TDU yet, reset the interrupt. */
596
+ if (!got_tdu) {
597
+ emc_write(qts, mod, REG_MISTA,
598
+ emc_read(qts, mod, REG_MISTA) & 0xffff0000);
599
+ }
600
+ }
601
+
602
+ end_desc_addr = desc_addr + 2 * sizeof(desc[0]);
603
+ g_assert_cmphex(emc_read(qts, mod, REG_CTXDSA), ==, end_desc_addr);
604
+ g_assert_cmphex(emc_read(qts, mod, REG_MISTA), ==,
605
+ REG_MISTA_TXCP | REG_MISTA_TXINTR | REG_MISTA_TDU);
606
+
607
+ emc_send_verify1(qts, mod, fd, with_irq,
608
+ desc_addr, end_desc_addr,
609
+ test1_data, sizeof(test1_data));
610
+ emc_send_verify1(qts, mod, fd, with_irq,
611
+ desc_addr + sizeof(desc[0]), end_desc_addr,
612
+ test2_data, sizeof(test2_data));
613
+}
614
+
615
+/* Initialize *desc (in host endian format). */
616
+static void init_rx_desc(NPCM7xxEMCRxDesc *desc, size_t count,
617
+ uint32_t desc_addr, uint32_t data_addr)
618
+{
619
+ g_assert_true(count >= 2);
620
+ memset(desc, 0, sizeof(*desc) * count);
621
+ desc[0].rxbsa = data_addr;
622
+ desc[0].status_and_length =
623
+ (0b10 << RX_DESC_STATUS_OWNER_SHIFT | /* owner = 10: emc */
624
+ 0 | /* RP = 0 */
625
+ 0 | /* ALIE = 0 */
626
+ 0 | /* RXGD = 0 */
627
+ 0 | /* PTLE = 0 */
628
+ 0 | /* CRCE = 0 */
629
+ 0 | /* RXINTR = 0 */
630
+ 0 /* length (filled in later) */);
631
+ /* Leave the last one alone, owned by the cpu -> stops transmission. */
632
+ desc[0].nrxdsa = desc_addr + sizeof(*desc);
633
+}
634
+
635
+static void enable_rx(QTestState *qts, const EMCModule *mod,
636
+ const NPCM7xxEMCRxDesc *desc, size_t count,
637
+ uint32_t desc_addr, uint32_t mien_flags,
638
+ uint32_t mcmdr_flags)
639
+{
640
+ /*
641
+ * Write the descriptor to guest memory.
642
+ * FWIW, IWBN if the docs said the buffer needs to be at least DMARFC
643
+ * bytes.
644
+ */
645
+ for (size_t i = 0; i < count; ++i) {
646
+ emc_write_rx_desc(qts, desc + i, desc_addr + i * sizeof(*desc));
647
+ }
648
+
649
+ /* Trigger receiving the packet. */
650
+ /* The module must be reset before changing RXDLSA. */
651
+ g_assert(emc_soft_reset(qts, mod));
652
+ emc_write(qts, mod, REG_RXDLSA, desc_addr);
653
+ emc_write(qts, mod, REG_MIEN, REG_MIEN_ENRXGD | mien_flags);
654
+
655
+ /*
656
+ * We don't know what the device's macaddr is, so just accept all
657
+ * unicast packets (AUP).
658
+ */
659
+ emc_write(qts, mod, REG_CAMCMR, REG_CAMCMR_AUP);
660
+ emc_write(qts, mod, REG_CAMEN, 1 << 0);
661
+ {
662
+ uint32_t mcmdr = emc_read(qts, mod, REG_MCMDR);
663
+ mcmdr |= REG_MCMDR_RXON | mcmdr_flags;
664
+ emc_write(qts, mod, REG_MCMDR, mcmdr);
665
+ }
666
+
667
+ /* Prod the device to accept a packet. */
668
+ emc_write(qts, mod, REG_RSDR, 1);
669
+}
670
+
671
+static void emc_recv_verify(QTestState *qts, const EMCModule *mod, int fd,
672
+ bool with_irq)
673
+{
674
+ NPCM7xxEMCRxDesc desc[NUM_RX_DESCRIPTORS];
675
+ uint32_t desc_addr = DESC_ADDR;
676
+ uint32_t data_addr = DATA_ADDR;
677
+ int ret;
678
+ uint32_t expected_mask, expected_value;
679
+ NPCM7xxEMCRxDesc result_desc;
680
+
681
+ /* Prepare test data buffer. */
682
+ const char test[RX_DATA_LEN] = "TEST";
683
+ int len = htonl(sizeof(test));
684
+ const struct iovec iov[] = {
685
+ {
686
+ .iov_base = &len,
687
+ .iov_len = sizeof(len),
688
+ },{
689
+ .iov_base = (char *) test,
690
+ .iov_len = sizeof(test),
691
+ },
692
+ };
693
+
694
+ /*
695
+ * Reset the device BEFORE sending a test packet, otherwise the packet
696
+ * may get swallowed by an active device of an earlier test.
697
+ */
698
+ init_rx_desc(&desc[0], NUM_RX_DESCRIPTORS, desc_addr, data_addr);
699
+ enable_rx(qts, mod, &desc[0], NUM_RX_DESCRIPTORS, desc_addr,
700
+ with_irq ? REG_MIEN_ENRXINTR : 0, 0);
701
+
702
+ /* Send test packet to device's socket. */
703
+ ret = iov_send(fd, iov, 2, 0, sizeof(len) + sizeof(test));
704
+ g_assert_cmpint(ret, == , sizeof(test) + sizeof(len));
705
+
706
+ /* Wait for RX interrupt. */
707
+ if (with_irq) {
708
+ g_assert_true(emc_wait_irq(qts, mod, RX_STEP_COUNT, /*is_tx=*/false));
709
+ } else {
710
+ g_assert_true(emc_wait_mista(qts, mod, RX_STEP_COUNT, REG_MISTA_RXGD));
711
+ }
712
+
713
+ g_assert_cmphex(emc_read(qts, mod, REG_CRXDSA), ==,
714
+ desc_addr + sizeof(desc[0]));
715
+
716
+ expected_mask = 0xffff;
717
+ expected_value = (REG_MISTA_DENI |
718
+ REG_MISTA_RXGD |
719
+ REG_MISTA_RXINTR);
720
+ g_assert_cmphex((emc_read(qts, mod, REG_MISTA) & expected_mask),
721
+ ==, expected_value);
722
+
723
+ /* Read the descriptor back. */
724
+ emc_read_rx_desc(qts, desc_addr, &result_desc);
725
+ /* Descriptor should be owned by cpu now. */
726
+ g_assert((result_desc.status_and_length & RX_DESC_STATUS_OWNER_MASK) == 0);
727
+ /* Test the status bits, ignoring the length field. */
728
+ expected_mask = 0xffff << 16;
729
+ expected_value = RX_DESC_STATUS_RXGD;
730
+ if (with_irq) {
731
+ expected_value |= RX_DESC_STATUS_RXINTR;
732
+ }
733
+ g_assert_cmphex((result_desc.status_and_length & expected_mask), ==,
734
+ expected_value);
735
+ g_assert_cmpint(RX_DESC_PKT_LEN(result_desc.status_and_length), ==,
736
+ RX_DATA_LEN + CRC_LENGTH);
737
+
738
+ {
739
+ char buffer[RX_DATA_LEN];
740
+ qtest_memread(qts, data_addr, buffer, sizeof(buffer));
741
+ g_assert_cmpstr(buffer, == , "TEST");
742
+ }
743
+}
744
+
745
+static void emc_test_ptle(QTestState *qts, const EMCModule *mod, int fd)
746
+{
747
+ NPCM7xxEMCRxDesc desc[NUM_RX_DESCRIPTORS];
748
+ uint32_t desc_addr = DESC_ADDR;
749
+ uint32_t data_addr = DATA_ADDR;
750
+ int ret;
751
+ NPCM7xxEMCRxDesc result_desc;
752
+ uint32_t expected_mask, expected_value;
753
+
754
+ /* Prepare test data buffer. */
755
+#define PTLE_DATA_LEN 1600
756
+ char test_data[PTLE_DATA_LEN];
757
+ int len = htonl(sizeof(test_data));
758
+ const struct iovec iov[] = {
759
+ {
760
+ .iov_base = &len,
761
+ .iov_len = sizeof(len),
762
+ },{
763
+ .iov_base = (char *) test_data,
764
+ .iov_len = sizeof(test_data),
765
+ },
766
+ };
767
+ memset(test_data, 42, sizeof(test_data));
768
+
769
+ /*
770
+ * Reset the device BEFORE sending a test packet, otherwise the packet
771
+ * may get swallowed by an active device of an earlier test.
772
+ */
773
+ init_rx_desc(&desc[0], NUM_RX_DESCRIPTORS, desc_addr, data_addr);
774
+ enable_rx(qts, mod, &desc[0], NUM_RX_DESCRIPTORS, desc_addr,
775
+ REG_MIEN_ENRXINTR, REG_MCMDR_ALP);
776
+
777
+ /* Send test packet to device's socket. */
778
+ ret = iov_send(fd, iov, 2, 0, sizeof(len) + sizeof(test_data));
779
+ g_assert_cmpint(ret, == , sizeof(test_data) + sizeof(len));
780
+
781
+ /* Wait for RX interrupt. */
782
+ g_assert_true(emc_wait_irq(qts, mod, RX_STEP_COUNT, /*is_tx=*/false));
783
+
784
+ /* Read the descriptor back. */
785
+ emc_read_rx_desc(qts, desc_addr, &result_desc);
786
+ /* Descriptor should be owned by cpu now. */
787
+ g_assert((result_desc.status_and_length & RX_DESC_STATUS_OWNER_MASK) == 0);
788
+ /* Test the status bits, ignoring the length field. */
789
+ expected_mask = 0xffff << 16;
790
+ expected_value = (RX_DESC_STATUS_RXGD |
791
+ RX_DESC_STATUS_PTLE |
792
+ RX_DESC_STATUS_RXINTR);
793
+ g_assert_cmphex((result_desc.status_and_length & expected_mask), ==,
794
+ expected_value);
795
+ g_assert_cmpint(RX_DESC_PKT_LEN(result_desc.status_and_length), ==,
796
+ PTLE_DATA_LEN + CRC_LENGTH);
797
+
798
+ {
799
+ char buffer[PTLE_DATA_LEN];
800
+ qtest_memread(qts, data_addr, buffer, sizeof(buffer));
801
+ g_assert(memcmp(buffer, test_data, PTLE_DATA_LEN) == 0);
802
+ }
803
+}
804
+
805
+static void test_tx(gconstpointer test_data)
806
+{
807
+ const TestData *td = test_data;
808
+ GString *cmd_line = g_string_new("-machine quanta-gsj");
809
+ int *test_sockets = packet_test_init(emc_module_index(td->module),
810
+ cmd_line);
811
+ QTestState *qts = qtest_init(cmd_line->str);
812
+
813
+ /*
814
+ * TODO: For pedantic correctness test_sockets[0] should be closed after
815
+ * the fork and before the exec, but that will require some harness
816
+ * improvements.
817
+ */
818
+ close(test_sockets[1]);
819
+ /* Defensive programming */
820
+ test_sockets[1] = -1;
821
+
822
+ qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic");
823
+
824
+ emc_send_verify(qts, td->module, test_sockets[0], /*with_irq=*/false);
825
+ emc_send_verify(qts, td->module, test_sockets[0], /*with_irq=*/true);
826
+
827
+ qtest_quit(qts);
828
+}
829
+
830
+static void test_rx(gconstpointer test_data)
831
+{
832
+ const TestData *td = test_data;
833
+ GString *cmd_line = g_string_new("-machine quanta-gsj");
834
+ int *test_sockets = packet_test_init(emc_module_index(td->module),
835
+ cmd_line);
836
+ QTestState *qts = qtest_init(cmd_line->str);
837
+
838
+ /*
839
+ * TODO: For pedantic correctness test_sockets[0] should be closed after
840
+ * the fork and before the exec, but that will require some harness
841
+ * improvements.
842
+ */
843
+ close(test_sockets[1]);
844
+ /* Defensive programming */
845
+ test_sockets[1] = -1;
846
+
847
+ qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic");
848
+
849
+ emc_recv_verify(qts, td->module, test_sockets[0], /*with_irq=*/false);
850
+ emc_recv_verify(qts, td->module, test_sockets[0], /*with_irq=*/true);
851
+ emc_test_ptle(qts, td->module, test_sockets[0]);
852
+
853
+ qtest_quit(qts);
854
+}
855
+
856
+static void emc_add_test(const char *name, const TestData* td,
857
+ GTestDataFunc fn)
858
+{
859
+ g_autofree char *full_name = g_strdup_printf(
860
+ "npcm7xx_emc/emc[%d]/%s", emc_module_index(td->module), name);
861
+ qtest_add_data_func(full_name, td, fn);
862
+}
863
+#define add_test(name, td) emc_add_test(#name, td, test_##name)
864
+
865
+int main(int argc, char **argv)
866
+{
867
+ TestData test_data_list[ARRAY_SIZE(emc_module_list)];
868
+
869
+ g_test_init(&argc, &argv, NULL);
870
+
871
+ for (int i = 0; i < ARRAY_SIZE(emc_module_list); ++i) {
872
+ TestData *td = &test_data_list[i];
873
+
874
+ td->module = &emc_module_list[i];
875
+
876
+ add_test(init, td);
877
+ add_test(tx, td);
878
+ add_test(rx, td);
879
+ }
880
+
881
+ return g_test_run();
882
+}
883
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
884
index XXXXXXX..XXXXXXX 100644
885
--- a/tests/qtest/meson.build
886
+++ b/tests/qtest/meson.build
887
@@ -XXX,XX +XXX,XX @@ qtests_npcm7xx = \
888
'npcm7xx_rng-test',
889
'npcm7xx_smbus-test',
890
'npcm7xx_timer-test',
891
- 'npcm7xx_watchdog_timer-test']
892
+ 'npcm7xx_watchdog_timer-test'] + \
893
+ (slirp.found() ? ['npcm7xx_emc-test'] : [])
894
qtests_arm = \
895
(config_all_devices.has_key('CONFIG_CMSDK_APB_DUALTIMER') ? ['cmsdk-apb-dualtimer-test'] : []) + \
896
(config_all_devices.has_key('CONFIG_CMSDK_APB_TIMER') ? ['cmsdk-apb-timer-test'] : []) + \
262
--
897
--
263
2.16.2
898
2.20.1
264
899
265
900
diff view generated by jsdifflib
1
From: Alistair Francis <alistair.francis@xilinx.com>
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
3
We hint the 'has_rpu' property is no longer required since commit
4
6908ec448b4 ("xlnx-zynqmp: Properly support the smp command line
5
option") which was released in QEMU v2.11.0.
6
7
Beside, this device is marked 'user_creatable = false', so the
8
only thing that could be setting the property is the board code
9
that creates the device.
10
11
Since the property is not user-facing, we can remove it without
12
going through the deprecation process.
13
4
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
14
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
15
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
16
Message-id: 20210219144350.1979905-1-f4bug@amsat.org
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
---
18
---
8
include/hw/arm/xlnx-zynqmp.h | 2 ++
19
include/hw/arm/xlnx-zynqmp.h | 2 --
9
hw/arm/xlnx-zynqmp.c | 14 ++++++++++++++
20
hw/arm/xlnx-zynqmp.c | 6 ------
10
2 files changed, 16 insertions(+)
21
2 files changed, 8 deletions(-)
11
22
12
diff --git a/include/hw/arm/xlnx-zynqmp.h b/include/hw/arm/xlnx-zynqmp.h
23
diff --git a/include/hw/arm/xlnx-zynqmp.h b/include/hw/arm/xlnx-zynqmp.h
13
index XXXXXXX..XXXXXXX 100644
24
index XXXXXXX..XXXXXXX 100644
14
--- a/include/hw/arm/xlnx-zynqmp.h
25
--- a/include/hw/arm/xlnx-zynqmp.h
15
+++ b/include/hw/arm/xlnx-zynqmp.h
26
+++ b/include/hw/arm/xlnx-zynqmp.h
16
@@ -XXX,XX +XXX,XX @@
27
@@ -XXX,XX +XXX,XX @@ struct XlnxZynqMPState {
17
#include "hw/dma/xlnx_dpdma.h"
28
bool secure;
18
#include "hw/display/xlnx_dp.h"
29
/* Has the ARM Virtualization extensions? */
19
#include "hw/intc/xlnx-zynqmp-ipi.h"
30
bool virt;
20
+#include "hw/timer/xlnx-zynqmp-rtc.h"
31
- /* Has the RPU subsystem? */
21
32
- bool has_rpu;
22
#define TYPE_XLNX_ZYNQMP "xlnx,zynqmp"
33
23
#define XLNX_ZYNQMP(obj) OBJECT_CHECK(XlnxZynqMPState, (obj), \
34
/* CAN bus. */
24
@@ -XXX,XX +XXX,XX @@ typedef struct XlnxZynqMPState {
35
CanBusState *canbus[XLNX_ZYNQMP_NUM_CAN];
25
XlnxDPState dp;
26
XlnxDPDMAState dpdma;
27
XlnxZynqMPIPI ipi;
28
+ XlnxZynqMPRTC rtc;
29
30
char *boot_cpu;
31
ARMCPU *boot_cpu_ptr;
32
diff --git a/hw/arm/xlnx-zynqmp.c b/hw/arm/xlnx-zynqmp.c
36
diff --git a/hw/arm/xlnx-zynqmp.c b/hw/arm/xlnx-zynqmp.c
33
index XXXXXXX..XXXXXXX 100644
37
index XXXXXXX..XXXXXXX 100644
34
--- a/hw/arm/xlnx-zynqmp.c
38
--- a/hw/arm/xlnx-zynqmp.c
35
+++ b/hw/arm/xlnx-zynqmp.c
39
+++ b/hw/arm/xlnx-zynqmp.c
36
@@ -XXX,XX +XXX,XX @@
37
#define IPI_ADDR 0xFF300000
38
#define IPI_IRQ 64
39
40
+#define RTC_ADDR 0xffa60000
41
+#define RTC_IRQ 26
42
+
43
#define SDHCI_CAPABILITIES 0x280737ec6481 /* Datasheet: UG1085 (v1.7) */
44
45
static const uint64_t gem_addr[XLNX_ZYNQMP_NUM_GEMS] = {
46
@@ -XXX,XX +XXX,XX @@ static void xlnx_zynqmp_init(Object *obj)
47
48
object_initialize(&s->ipi, sizeof(s->ipi), TYPE_XLNX_ZYNQMP_IPI);
49
qdev_set_parent_bus(DEVICE(&s->ipi), sysbus_get_default());
50
+
51
+ object_initialize(&s->rtc, sizeof(s->rtc), TYPE_XLNX_ZYNQMP_RTC);
52
+ qdev_set_parent_bus(DEVICE(&s->rtc), sysbus_get_default());
53
}
54
55
static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
56
@@ -XXX,XX +XXX,XX @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
40
@@ -XXX,XX +XXX,XX @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
41
}
57
}
42
}
58
sysbus_mmio_map(SYS_BUS_DEVICE(&s->ipi), 0, IPI_ADDR);
43
59
sysbus_connect_irq(SYS_BUS_DEVICE(&s->ipi), 0, gic_spi[IPI_IRQ]);
44
- if (s->has_rpu) {
60
+
45
- info_report("The 'has_rpu' property is no longer required, to use the "
61
+ object_property_set_bool(OBJECT(&s->rtc), true, "realized", &err);
46
- "RPUs just use -smp 6.");
62
+ if (err) {
47
- }
63
+ error_propagate(errp, err);
48
-
64
+ return;
49
xlnx_zynqmp_create_rpu(ms, s, boot_cpu, &err);
65
+ }
50
if (err) {
66
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->rtc), 0, RTC_ADDR);
51
error_propagate(errp, err);
67
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->rtc), 0, gic_spi[RTC_IRQ]);
52
@@ -XXX,XX +XXX,XX @@ static Property xlnx_zynqmp_props[] = {
68
}
53
DEFINE_PROP_STRING("boot-cpu", XlnxZynqMPState, boot_cpu),
69
54
DEFINE_PROP_BOOL("secure", XlnxZynqMPState, secure, false),
70
static Property xlnx_zynqmp_props[] = {
55
DEFINE_PROP_BOOL("virtualization", XlnxZynqMPState, virt, false),
56
- DEFINE_PROP_BOOL("has_rpu", XlnxZynqMPState, has_rpu, false),
57
DEFINE_PROP_LINK("ddr-ram", XlnxZynqMPState, ddr_ram, TYPE_MEMORY_REGION,
58
MemoryRegion *),
59
DEFINE_PROP_LINK("canbus0", XlnxZynqMPState, canbus[0], TYPE_CAN_BUS,
71
--
60
--
72
2.16.2
61
2.20.1
73
62
74
63
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Richard Henderson <richard.henderson@linaro.org>
2
2
3
Always perform one call instead of two for 16-byte operands.
4
Use byte loads/stores directly into the vector register file
5
instead of extractions and deposits to a 64-bit local variable.
6
7
In order to easily receive pointers into the vector register file,
8
convert the helper to the gvec out-of-line signature. Move the
9
helper into vec_helper.c, where it can make use of H1 and clear_tail.
10
3
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
11
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
4
Message-id: 20180228193125.20577-13-richard.henderson@linaro.org
12
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
13
Tested-by: Alex Bennée <alex.bennee@linaro.org>
14
Message-id: 20210224230532.276878-1-richard.henderson@linaro.org
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
[PMM: renamed e1/e2/e3/e4 to use the same naming as the version
7
of the pseudocode in the Arm ARM]
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
---
16
---
10
target/arm/helper.h | 11 ++++
17
target/arm/helper-a64.h | 2 +-
11
target/arm/translate-a64.c | 94 +++++++++++++++++++++++++---
18
target/arm/helper-a64.c | 32 ---------------------
12
target/arm/vec_helper.c | 149 +++++++++++++++++++++++++++++++++++++++++++++
19
target/arm/translate-a64.c | 58 +++++---------------------------------
13
3 files changed, 246 insertions(+), 8 deletions(-)
20
target/arm/vec_helper.c | 48 +++++++++++++++++++++++++++++++
14
21
4 files changed, 56 insertions(+), 84 deletions(-)
15
diff --git a/target/arm/helper.h b/target/arm/helper.h
22
16
index XXXXXXX..XXXXXXX 100644
23
diff --git a/target/arm/helper-a64.h b/target/arm/helper-a64.h
17
--- a/target/arm/helper.h
24
index XXXXXXX..XXXXXXX 100644
18
+++ b/target/arm/helper.h
25
--- a/target/arm/helper-a64.h
19
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_5(gvec_fcadds, TCG_CALL_NO_RWG,
26
+++ b/target/arm/helper-a64.h
20
DEF_HELPER_FLAGS_5(gvec_fcaddd, TCG_CALL_NO_RWG,
27
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_3(vfp_cmps_a64, i64, f32, f32, ptr)
21
void, ptr, ptr, ptr, ptr, i32)
28
DEF_HELPER_3(vfp_cmpes_a64, i64, f32, f32, ptr)
22
29
DEF_HELPER_3(vfp_cmpd_a64, i64, f64, f64, ptr)
23
+DEF_HELPER_FLAGS_5(gvec_fcmlah, TCG_CALL_NO_RWG,
30
DEF_HELPER_3(vfp_cmped_a64, i64, f64, f64, ptr)
24
+ void, ptr, ptr, ptr, ptr, i32)
31
-DEF_HELPER_FLAGS_5(simd_tbl, TCG_CALL_NO_RWG_SE, i64, env, i64, i64, i32, i32)
25
+DEF_HELPER_FLAGS_5(gvec_fcmlah_idx, TCG_CALL_NO_RWG,
32
+DEF_HELPER_FLAGS_4(simd_tblx, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
26
+ void, ptr, ptr, ptr, ptr, i32)
33
DEF_HELPER_FLAGS_3(vfp_mulxs, TCG_CALL_NO_RWG, f32, f32, f32, ptr)
27
+DEF_HELPER_FLAGS_5(gvec_fcmlas, TCG_CALL_NO_RWG,
34
DEF_HELPER_FLAGS_3(vfp_mulxd, TCG_CALL_NO_RWG, f64, f64, f64, ptr)
28
+ void, ptr, ptr, ptr, ptr, i32)
35
DEF_HELPER_FLAGS_3(neon_ceq_f64, TCG_CALL_NO_RWG, i64, i64, i64, ptr)
29
+DEF_HELPER_FLAGS_5(gvec_fcmlas_idx, TCG_CALL_NO_RWG,
36
diff --git a/target/arm/helper-a64.c b/target/arm/helper-a64.c
30
+ void, ptr, ptr, ptr, ptr, i32)
37
index XXXXXXX..XXXXXXX 100644
31
+DEF_HELPER_FLAGS_5(gvec_fcmlad, TCG_CALL_NO_RWG,
38
--- a/target/arm/helper-a64.c
32
+ void, ptr, ptr, ptr, ptr, i32)
39
+++ b/target/arm/helper-a64.c
33
+
40
@@ -XXX,XX +XXX,XX @@ float64 HELPER(vfp_mulxd)(float64 a, float64 b, void *fpstp)
34
#ifdef TARGET_AARCH64
41
return float64_mul(a, b, fpst);
35
#include "helper-a64.h"
42
}
36
#endif
43
44
-uint64_t HELPER(simd_tbl)(CPUARMState *env, uint64_t result, uint64_t indices,
45
- uint32_t rn, uint32_t numregs)
46
-{
47
- /* Helper function for SIMD TBL and TBX. We have to do the table
48
- * lookup part for the 64 bits worth of indices we're passed in.
49
- * result is the initial results vector (either zeroes for TBL
50
- * or some guest values for TBX), rn the register number where
51
- * the table starts, and numregs the number of registers in the table.
52
- * We return the results of the lookups.
53
- */
54
- int shift;
55
-
56
- for (shift = 0; shift < 64; shift += 8) {
57
- int index = extract64(indices, shift, 8);
58
- if (index < 16 * numregs) {
59
- /* Convert index (a byte offset into the virtual table
60
- * which is a series of 128-bit vectors concatenated)
61
- * into the correct register element plus a bit offset
62
- * into that element, bearing in mind that the table
63
- * can wrap around from V31 to V0.
64
- */
65
- int elt = (rn * 2 + (index >> 3)) % 64;
66
- int bitidx = (index & 7) * 8;
67
- uint64_t *q = aa64_vfp_qreg(env, elt >> 1);
68
- uint64_t val = extract64(q[elt & 1], bitidx, 8);
69
-
70
- result = deposit64(result, shift, 8, val);
71
- }
72
- }
73
- return result;
74
-}
75
-
76
/* 64bit/double versions of the neon float compare functions */
77
uint64_t HELPER(neon_ceq_f64)(float64 a, float64 b, void *fpstp)
78
{
37
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
79
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
38
index XXXXXXX..XXXXXXX 100644
80
index XXXXXXX..XXXXXXX 100644
39
--- a/target/arm/translate-a64.c
81
--- a/target/arm/translate-a64.c
40
+++ b/target/arm/translate-a64.c
82
+++ b/target/arm/translate-a64.c
41
@@ -XXX,XX +XXX,XX @@ static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn)
83
@@ -XXX,XX +XXX,XX @@ static void disas_simd_tb(DisasContext *s, uint32_t insn)
42
}
84
int rm = extract32(insn, 16, 5);
43
feature = ARM_FEATURE_V8_RDM;
44
break;
45
+ case 0x8: /* FCMLA, #0 */
46
+ case 0x9: /* FCMLA, #90 */
47
+ case 0xa: /* FCMLA, #180 */
48
+ case 0xb: /* FCMLA, #270 */
49
case 0xc: /* FCADD, #90 */
50
case 0xe: /* FCADD, #270 */
51
if (size == 0
52
@@ -XXX,XX +XXX,XX @@ static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn)
53
}
54
return;
55
56
+ case 0x8: /* FCMLA, #0 */
57
+ case 0x9: /* FCMLA, #90 */
58
+ case 0xa: /* FCMLA, #180 */
59
+ case 0xb: /* FCMLA, #270 */
60
+ rot = extract32(opcode, 0, 2);
61
+ switch (size) {
62
+ case 1:
63
+ gen_gvec_op3_fpst(s, is_q, rd, rn, rm, true, rot,
64
+ gen_helper_gvec_fcmlah);
65
+ break;
66
+ case 2:
67
+ gen_gvec_op3_fpst(s, is_q, rd, rn, rm, false, rot,
68
+ gen_helper_gvec_fcmlas);
69
+ break;
70
+ case 3:
71
+ gen_gvec_op3_fpst(s, is_q, rd, rn, rm, false, rot,
72
+ gen_helper_gvec_fcmlad);
73
+ break;
74
+ default:
75
+ g_assert_not_reached();
76
+ }
77
+ return;
78
+
79
case 0xc: /* FCADD, #90 */
80
case 0xe: /* FCADD, #270 */
81
rot = extract32(opcode, 1, 1);
82
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
83
int rn = extract32(insn, 5, 5);
85
int rn = extract32(insn, 5, 5);
84
int rd = extract32(insn, 0, 5);
86
int rd = extract32(insn, 0, 5);
85
bool is_long = false;
87
- int is_tblx = extract32(insn, 12, 1);
86
- bool is_fp = false;
88
- int len = extract32(insn, 13, 2);
87
+ int is_fp = 0;
89
- TCGv_i64 tcg_resl, tcg_resh, tcg_idx;
88
bool is_fp16 = false;
90
- TCGv_i32 tcg_regno, tcg_numregs;
89
int index;
91
+ int is_tbx = extract32(insn, 12, 1);
90
TCGv_ptr fpst;
92
+ int len = (extract32(insn, 13, 2) + 1) * 16;
91
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
93
92
case 0x05: /* FMLS */
94
if (op2 != 0) {
93
case 0x09: /* FMUL */
94
case 0x19: /* FMULX */
95
- is_fp = true;
96
+ is_fp = 1;
97
break;
98
case 0x1d: /* SQRDMLAH */
99
case 0x1f: /* SQRDMLSH */
100
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
101
return;
102
}
103
break;
104
+ case 0x11: /* FCMLA #0 */
105
+ case 0x13: /* FCMLA #90 */
106
+ case 0x15: /* FCMLA #180 */
107
+ case 0x17: /* FCMLA #270 */
108
+ if (!arm_dc_feature(s, ARM_FEATURE_V8_FCMA)) {
109
+ unallocated_encoding(s);
110
+ return;
111
+ }
112
+ is_fp = 2;
113
+ break;
114
default:
115
unallocated_encoding(s);
95
unallocated_encoding(s);
96
@@ -XXX,XX +XXX,XX @@ static void disas_simd_tb(DisasContext *s, uint32_t insn)
116
return;
97
return;
117
}
98
}
118
99
119
- if (is_fp) {
100
- /* This does a table lookup: for every byte element in the input
120
+ switch (is_fp) {
101
- * we index into a table formed from up to four vector registers,
121
+ case 1: /* normal fp */
102
- * and then the output is the result of the lookups. Our helper
122
/* convert insn encoded size to TCGMemOp size */
103
- * function does the lookup operation for a single 64 bit part of
123
switch (size) {
104
- * the input.
124
case 0: /* half-precision */
105
- */
125
- if (!arm_dc_feature(s, ARM_FEATURE_V8_FP16)) {
106
- tcg_resl = tcg_temp_new_i64();
126
- unallocated_encoding(s);
107
- tcg_resh = NULL;
127
- return;
108
-
128
- }
109
- if (is_tblx) {
129
size = MO_16;
110
- read_vec_element(s, tcg_resl, rd, 0, MO_64);
130
+ is_fp16 = true;
131
break;
132
case MO_32: /* single precision */
133
case MO_64: /* double precision */
134
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
135
unallocated_encoding(s);
136
return;
137
}
138
- } else {
111
- } else {
139
+ break;
112
- tcg_gen_movi_i64(tcg_resl, 0);
140
+
113
- }
141
+ case 2: /* complex fp */
114
-
142
+ /* Each indexable element is a complex pair. */
115
- if (is_q) {
143
+ size <<= 1;
116
- tcg_resh = tcg_temp_new_i64();
144
+ switch (size) {
117
- if (is_tblx) {
145
+ case MO_32:
118
- read_vec_element(s, tcg_resh, rd, 1, MO_64);
146
+ if (h && !is_q) {
119
- } else {
147
+ unallocated_encoding(s);
120
- tcg_gen_movi_i64(tcg_resh, 0);
148
+ return;
121
- }
149
+ }
122
- }
150
+ is_fp16 = true;
123
-
151
+ break;
124
- tcg_idx = tcg_temp_new_i64();
152
+ case MO_64:
125
- tcg_regno = tcg_const_i32(rn);
153
+ break;
126
- tcg_numregs = tcg_const_i32(len + 1);
154
+ default:
127
- read_vec_element(s, tcg_idx, rm, 0, MO_64);
155
+ unallocated_encoding(s);
128
- gen_helper_simd_tbl(tcg_resl, cpu_env, tcg_resl, tcg_idx,
156
+ return;
129
- tcg_regno, tcg_numregs);
157
+ }
130
- if (is_q) {
158
+ break;
131
- read_vec_element(s, tcg_idx, rm, 1, MO_64);
159
+
132
- gen_helper_simd_tbl(tcg_resh, cpu_env, tcg_resh, tcg_idx,
160
+ default: /* integer */
133
- tcg_regno, tcg_numregs);
161
switch (size) {
134
- }
162
case MO_8:
135
- tcg_temp_free_i64(tcg_idx);
163
case MO_64:
136
- tcg_temp_free_i32(tcg_regno);
164
unallocated_encoding(s);
137
- tcg_temp_free_i32(tcg_numregs);
165
return;
138
-
166
}
139
- write_vec_element(s, tcg_resl, rd, 0, MO_64);
167
+ break;
140
- tcg_temp_free_i64(tcg_resl);
168
+ }
141
-
169
+ if (is_fp16 && !arm_dc_feature(s, ARM_FEATURE_V8_FP16)) {
142
- if (is_q) {
170
+ unallocated_encoding(s);
143
- write_vec_element(s, tcg_resh, rd, 1, MO_64);
171
+ return;
144
- tcg_temp_free_i64(tcg_resh);
172
}
145
- }
173
146
- clear_vec_high(s, is_q, rd);
174
/* Given TCGMemOp size, adjust register and indexing. */
147
+ tcg_gen_gvec_2_ptr(vec_full_reg_offset(s, rd),
175
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
148
+ vec_full_reg_offset(s, rm), cpu_env,
176
fpst = NULL;
149
+ is_q ? 16 : 8, vec_full_reg_size(s),
177
}
150
+ (len << 6) | (is_tbx << 5) | rn,
178
151
+ gen_helper_simd_tblx);
179
+ switch (16 * u + opcode) {
152
}
180
+ case 0x11: /* FCMLA #0 */
153
181
+ case 0x13: /* FCMLA #90 */
154
/* ZIP/UZP/TRN
182
+ case 0x15: /* FCMLA #180 */
183
+ case 0x17: /* FCMLA #270 */
184
+ tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, rd),
185
+ vec_full_reg_offset(s, rn),
186
+ vec_reg_offset(s, rm, index, size), fpst,
187
+ is_q ? 16 : 8, vec_full_reg_size(s),
188
+ extract32(insn, 13, 2), /* rot */
189
+ size == MO_64
190
+ ? gen_helper_gvec_fcmlas_idx
191
+ : gen_helper_gvec_fcmlah_idx);
192
+ tcg_temp_free_ptr(fpst);
193
+ return;
194
+ }
195
+
196
if (size == 3) {
197
TCGv_i64 tcg_idx = tcg_temp_new_i64();
198
int pass;
199
diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c
155
diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c
200
index XXXXXXX..XXXXXXX 100644
156
index XXXXXXX..XXXXXXX 100644
201
--- a/target/arm/vec_helper.c
157
--- a/target/arm/vec_helper.c
202
+++ b/target/arm/vec_helper.c
158
+++ b/target/arm/vec_helper.c
203
@@ -XXX,XX +XXX,XX @@ void HELPER(gvec_fcaddd)(void *vd, void *vn, void *vm,
159
@@ -XXX,XX +XXX,XX @@ DO_VRINT_RMODE(gvec_vrint_rm_h, helper_rinth, uint16_t)
204
}
160
DO_VRINT_RMODE(gvec_vrint_rm_s, helper_rints, uint32_t)
205
clear_tail(d, opr_sz, simd_maxsz(desc));
161
206
}
162
#undef DO_VRINT_RMODE
207
+
163
+
208
+void HELPER(gvec_fcmlah)(void *vd, void *vn, void *vm,
164
+#ifdef TARGET_AARCH64
209
+ void *vfpst, uint32_t desc)
165
+void HELPER(simd_tblx)(void *vd, void *vm, void *venv, uint32_t desc)
210
+{
166
+{
211
+ uintptr_t opr_sz = simd_oprsz(desc);
167
+ const uint8_t *indices = vm;
212
+ float16 *d = vd;
168
+ CPUARMState *env = venv;
213
+ float16 *n = vn;
169
+ size_t oprsz = simd_oprsz(desc);
214
+ float16 *m = vm;
170
+ uint32_t rn = extract32(desc, SIMD_DATA_SHIFT, 5);
215
+ float_status *fpst = vfpst;
171
+ bool is_tbx = extract32(desc, SIMD_DATA_SHIFT + 5, 1);
216
+ intptr_t flip = extract32(desc, SIMD_DATA_SHIFT, 1);
172
+ uint32_t table_len = desc >> (SIMD_DATA_SHIFT + 6);
217
+ uint32_t neg_imag = extract32(desc, SIMD_DATA_SHIFT + 1, 1);
173
+ union {
218
+ uint32_t neg_real = flip ^ neg_imag;
174
+ uint8_t b[16];
219
+ uintptr_t i;
175
+ uint64_t d[2];
220
+
176
+ } result;
221
+ /* Shift boolean to the sign bit so we can xor to negate. */
177
+
222
+ neg_real <<= 15;
178
+ /*
223
+ neg_imag <<= 15;
179
+ * We must construct the final result in a temp, lest the output
224
+
180
+ * overlaps the input table. For TBL, begin with zero; for TBX,
225
+ for (i = 0; i < opr_sz / 2; i += 2) {
181
+ * begin with the original register contents. Note that we always
226
+ float16 e2 = n[H2(i + flip)];
182
+ * copy 16 bytes here to avoid an extra branch; clearing the high
227
+ float16 e1 = m[H2(i + flip)] ^ neg_real;
183
+ * bits of the register for oprsz == 8 is handled below.
228
+ float16 e4 = e2;
184
+ */
229
+ float16 e3 = m[H2(i + 1 - flip)] ^ neg_imag;
185
+ if (is_tbx) {
230
+
186
+ memcpy(&result, vd, 16);
231
+ d[H2(i)] = float16_muladd(e2, e1, d[H2(i)], 0, fpst);
187
+ } else {
232
+ d[H2(i + 1)] = float16_muladd(e4, e3, d[H2(i + 1)], 0, fpst);
188
+ memset(&result, 0, 16);
233
+ }
189
+ }
234
+ clear_tail(d, opr_sz, simd_maxsz(desc));
190
+
191
+ for (size_t i = 0; i < oprsz; ++i) {
192
+ uint32_t index = indices[H1(i)];
193
+
194
+ if (index < table_len) {
195
+ /*
196
+ * Convert index (a byte offset into the virtual table
197
+ * which is a series of 128-bit vectors concatenated)
198
+ * into the correct register element, bearing in mind
199
+ * that the table can wrap around from V31 to V0.
200
+ */
201
+ const uint8_t *table = (const uint8_t *)
202
+ aa64_vfp_qreg(env, (rn + (index >> 4)) % 32);
203
+ result.b[H1(i)] = table[H1(index % 16)];
204
+ }
205
+ }
206
+
207
+ memcpy(vd, &result, 16);
208
+ clear_tail(vd, oprsz, simd_maxsz(desc));
235
+}
209
+}
236
+
210
+#endif
237
+void HELPER(gvec_fcmlah_idx)(void *vd, void *vn, void *vm,
238
+ void *vfpst, uint32_t desc)
239
+{
240
+ uintptr_t opr_sz = simd_oprsz(desc);
241
+ float16 *d = vd;
242
+ float16 *n = vn;
243
+ float16 *m = vm;
244
+ float_status *fpst = vfpst;
245
+ intptr_t flip = extract32(desc, SIMD_DATA_SHIFT, 1);
246
+ uint32_t neg_imag = extract32(desc, SIMD_DATA_SHIFT + 1, 1);
247
+ uint32_t neg_real = flip ^ neg_imag;
248
+ uintptr_t i;
249
+ float16 e1 = m[H2(flip)];
250
+ float16 e3 = m[H2(1 - flip)];
251
+
252
+ /* Shift boolean to the sign bit so we can xor to negate. */
253
+ neg_real <<= 15;
254
+ neg_imag <<= 15;
255
+ e1 ^= neg_real;
256
+ e3 ^= neg_imag;
257
+
258
+ for (i = 0; i < opr_sz / 2; i += 2) {
259
+ float16 e2 = n[H2(i + flip)];
260
+ float16 e4 = e2;
261
+
262
+ d[H2(i)] = float16_muladd(e2, e1, d[H2(i)], 0, fpst);
263
+ d[H2(i + 1)] = float16_muladd(e4, e3, d[H2(i + 1)], 0, fpst);
264
+ }
265
+ clear_tail(d, opr_sz, simd_maxsz(desc));
266
+}
267
+
268
+void HELPER(gvec_fcmlas)(void *vd, void *vn, void *vm,
269
+ void *vfpst, uint32_t desc)
270
+{
271
+ uintptr_t opr_sz = simd_oprsz(desc);
272
+ float32 *d = vd;
273
+ float32 *n = vn;
274
+ float32 *m = vm;
275
+ float_status *fpst = vfpst;
276
+ intptr_t flip = extract32(desc, SIMD_DATA_SHIFT, 1);
277
+ uint32_t neg_imag = extract32(desc, SIMD_DATA_SHIFT + 1, 1);
278
+ uint32_t neg_real = flip ^ neg_imag;
279
+ uintptr_t i;
280
+
281
+ /* Shift boolean to the sign bit so we can xor to negate. */
282
+ neg_real <<= 31;
283
+ neg_imag <<= 31;
284
+
285
+ for (i = 0; i < opr_sz / 4; i += 2) {
286
+ float32 e2 = n[H4(i + flip)];
287
+ float32 e1 = m[H4(i + flip)] ^ neg_real;
288
+ float32 e4 = e2;
289
+ float32 e3 = m[H4(i + 1 - flip)] ^ neg_imag;
290
+
291
+ d[H4(i)] = float32_muladd(e2, e1, d[H4(i)], 0, fpst);
292
+ d[H4(i + 1)] = float32_muladd(e4, e3, d[H4(i + 1)], 0, fpst);
293
+ }
294
+ clear_tail(d, opr_sz, simd_maxsz(desc));
295
+}
296
+
297
+void HELPER(gvec_fcmlas_idx)(void *vd, void *vn, void *vm,
298
+ void *vfpst, uint32_t desc)
299
+{
300
+ uintptr_t opr_sz = simd_oprsz(desc);
301
+ float32 *d = vd;
302
+ float32 *n = vn;
303
+ float32 *m = vm;
304
+ float_status *fpst = vfpst;
305
+ intptr_t flip = extract32(desc, SIMD_DATA_SHIFT, 1);
306
+ uint32_t neg_imag = extract32(desc, SIMD_DATA_SHIFT + 1, 1);
307
+ uint32_t neg_real = flip ^ neg_imag;
308
+ uintptr_t i;
309
+ float32 e1 = m[H4(flip)];
310
+ float32 e3 = m[H4(1 - flip)];
311
+
312
+ /* Shift boolean to the sign bit so we can xor to negate. */
313
+ neg_real <<= 31;
314
+ neg_imag <<= 31;
315
+ e1 ^= neg_real;
316
+ e3 ^= neg_imag;
317
+
318
+ for (i = 0; i < opr_sz / 4; i += 2) {
319
+ float32 e2 = n[H4(i + flip)];
320
+ float32 e4 = e2;
321
+
322
+ d[H4(i)] = float32_muladd(e2, e1, d[H4(i)], 0, fpst);
323
+ d[H4(i + 1)] = float32_muladd(e4, e3, d[H4(i + 1)], 0, fpst);
324
+ }
325
+ clear_tail(d, opr_sz, simd_maxsz(desc));
326
+}
327
+
328
+void HELPER(gvec_fcmlad)(void *vd, void *vn, void *vm,
329
+ void *vfpst, uint32_t desc)
330
+{
331
+ uintptr_t opr_sz = simd_oprsz(desc);
332
+ float64 *d = vd;
333
+ float64 *n = vn;
334
+ float64 *m = vm;
335
+ float_status *fpst = vfpst;
336
+ intptr_t flip = extract32(desc, SIMD_DATA_SHIFT, 1);
337
+ uint64_t neg_imag = extract32(desc, SIMD_DATA_SHIFT + 1, 1);
338
+ uint64_t neg_real = flip ^ neg_imag;
339
+ uintptr_t i;
340
+
341
+ /* Shift boolean to the sign bit so we can xor to negate. */
342
+ neg_real <<= 63;
343
+ neg_imag <<= 63;
344
+
345
+ for (i = 0; i < opr_sz / 8; i += 2) {
346
+ float64 e2 = n[i + flip];
347
+ float64 e1 = m[i + flip] ^ neg_real;
348
+ float64 e4 = e2;
349
+ float64 e3 = m[i + 1 - flip] ^ neg_imag;
350
+
351
+ d[i] = float64_muladd(e2, e1, d[i], 0, fpst);
352
+ d[i + 1] = float64_muladd(e4, e3, d[i + 1], 0, fpst);
353
+ }
354
+ clear_tail(d, opr_sz, simd_maxsz(desc));
355
+}
356
--
211
--
357
2.16.2
212
2.20.1
358
213
359
214
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
3
The STATUS register will be reset to IDLE in
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
4
cnpcm7xx_smbus_enter_reset(), no need to preset
5
Message-id: 20180228193125.20577-7-richard.henderson@linaro.org
5
it in instance_init().
6
7
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Reviewed-by: Hao Wu <wuhaotsh@google.com>
9
Message-id: 20210228224813.312532-1-f4bug@amsat.org
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
---
11
---
8
target/arm/translate-a64.c | 29 +++++++++++++++++++++++++++++
12
hw/i2c/npcm7xx_smbus.c | 1 -
9
1 file changed, 29 insertions(+)
13
1 file changed, 1 deletion(-)
10
14
11
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
15
diff --git a/hw/i2c/npcm7xx_smbus.c b/hw/i2c/npcm7xx_smbus.c
12
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
13
--- a/target/arm/translate-a64.c
17
--- a/hw/i2c/npcm7xx_smbus.c
14
+++ b/target/arm/translate-a64.c
18
+++ b/hw/i2c/npcm7xx_smbus.c
15
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
19
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_init(Object *obj)
16
case 0x19: /* FMULX */
20
sysbus_init_mmio(sbd, &s->iomem);
17
is_fp = true;
21
18
break;
22
s->bus = i2c_init_bus(DEVICE(s), "i2c-bus");
19
+ case 0x1d: /* SQRDMLAH */
23
- s->status = NPCM7XX_SMBUS_STATUS_IDLE;
20
+ case 0x1f: /* SQRDMLSH */
24
}
21
+ if (!arm_dc_feature(s, ARM_FEATURE_V8_RDM)) {
25
22
+ unallocated_encoding(s);
26
static const VMStateDescription vmstate_npcm7xx_smbus = {
23
+ return;
24
+ }
25
+ break;
26
default:
27
unallocated_encoding(s);
28
return;
29
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
30
tcg_op, tcg_idx);
31
}
32
break;
33
+ case 0x1d: /* SQRDMLAH */
34
+ read_vec_element_i32(s, tcg_res, rd, pass,
35
+ is_scalar ? size : MO_32);
36
+ if (size == 1) {
37
+ gen_helper_neon_qrdmlah_s16(tcg_res, cpu_env,
38
+ tcg_op, tcg_idx, tcg_res);
39
+ } else {
40
+ gen_helper_neon_qrdmlah_s32(tcg_res, cpu_env,
41
+ tcg_op, tcg_idx, tcg_res);
42
+ }
43
+ break;
44
+ case 0x1f: /* SQRDMLSH */
45
+ read_vec_element_i32(s, tcg_res, rd, pass,
46
+ is_scalar ? size : MO_32);
47
+ if (size == 1) {
48
+ gen_helper_neon_qrdmlsh_s16(tcg_res, cpu_env,
49
+ tcg_op, tcg_idx, tcg_res);
50
+ } else {
51
+ gen_helper_neon_qrdmlsh_s32(tcg_res, cpu_env,
52
+ tcg_op, tcg_idx, tcg_res);
53
+ }
54
+ break;
55
default:
56
g_assert_not_reached();
57
}
58
--
27
--
59
2.16.2
28
2.20.1
60
29
61
30
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: schspa <schspa@gmail.com>
2
2
3
Happily, the bits are in the same places compared to a32.
3
At the moment the following QEMU command line triggers an assertion
4
failure On xlnx-versal SOC:
5
qemu-system-aarch64 \
6
-machine xlnx-versal-virt -nographic -smp 2 -m 128 \
7
-fsdev local,id=shareid,path=${HOME}/work,security_model=none \
8
-device virtio-9p-device,fsdev=shareid,mount_tag=share \
9
-fsdev local,id=shareid1,path=${HOME}/Music,security_model=none \
10
-device virtio-9p-device,fsdev=shareid1,mount_tag=share1
4
11
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
12
qemu-system-aarch64: ../migration/savevm.c:860:
6
Message-id: 20180228193125.20577-16-richard.henderson@linaro.org
13
vmstate_register_with_alias_id:
14
Assertion `!se->compat || se->instance_id == 0' failed.
15
16
This problem was fixed on arm virt platform in commit f58b39d2d5b
17
("virtio-mmio: format transport base address in BusClass.get_dev_path")
18
19
It works perfectly on arm virt platform. but there is still there on
20
xlnx-versal SOC.
21
22
The main difference between arm virt and xlnx-versal is they use
23
different way to create virtio-mmio qdev. on arm virt, it calls
24
sysbus_create_simple("virtio-mmio", base, pic[irq]); which will call
25
sysbus_mmio_map internally and assign base address to subsys device
26
mmio correctly. but xlnx-versal's implements won't do this.
27
28
However, xlnx-versal can't switch to sysbus_create_simple() to create
29
virtio-mmio device. It's because xlnx-versal's cpu use
30
VersalVirt.soc.fpd.apu.mr as it's memory. which is subregion of
31
system_memory. sysbus_create_simple will add virtio to system_memory,
32
which can't be accessed by cpu.
33
34
Besides, xlnx-versal can't add sysbus_mmio_map api call too, because
35
this will add memory region to system_memory, and it can't be added
36
to VersalVirt.soc.fpd.apu.mr again.
37
38
We can solve this by assign correct base address offset on dev_path.
39
40
This path was test on aarch64 virt & xlnx-versal platform.
41
42
Signed-off-by: schspa <schspa@gmail.com>
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
43
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
44
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
45
---
10
target/arm/translate.c | 14 +++++++++++++-
46
hw/virtio/virtio-mmio.c | 13 +++++++------
11
1 file changed, 13 insertions(+), 1 deletion(-)
47
1 file changed, 7 insertions(+), 6 deletions(-)
12
48
13
diff --git a/target/arm/translate.c b/target/arm/translate.c
49
diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c
14
index XXXXXXX..XXXXXXX 100644
50
index XXXXXXX..XXXXXXX 100644
15
--- a/target/arm/translate.c
51
--- a/hw/virtio/virtio-mmio.c
16
+++ b/target/arm/translate.c
52
+++ b/hw/virtio/virtio-mmio.c
17
@@ -XXX,XX +XXX,XX @@ static void disas_thumb2_insn(DisasContext *s, uint32_t insn)
53
@@ -XXX,XX +XXX,XX @@ static char *virtio_mmio_bus_get_dev_path(DeviceState *dev)
18
default_exception_el(s));
54
BusState *virtio_mmio_bus;
19
break;
55
VirtIOMMIOProxy *virtio_mmio_proxy;
20
}
56
char *proxy_path;
21
- if (((insn >> 24) & 3) == 3) {
57
- SysBusDevice *proxy_sbd;
22
+ if ((insn & 0xfe000a00) == 0xfc000800
58
char *path;
23
+ && arm_dc_feature(s, ARM_FEATURE_V8)) {
59
+ MemoryRegionSection section;
24
+ /* The Thumb2 and ARM encodings are identical. */
60
25
+ if (disas_neon_insn_3same_ext(s, insn)) {
61
virtio_mmio_bus = qdev_get_parent_bus(dev);
26
+ goto illegal_op;
62
virtio_mmio_proxy = VIRTIO_MMIO(virtio_mmio_bus->parent);
27
+ }
63
@@ -XXX,XX +XXX,XX @@ static char *virtio_mmio_bus_get_dev_path(DeviceState *dev)
28
+ } else if ((insn & 0xff000a00) == 0xfe000800
64
}
29
+ && arm_dc_feature(s, ARM_FEATURE_V8)) {
65
30
+ /* The Thumb2 and ARM encodings are identical. */
66
/* Otherwise, we append the base address of the transport. */
31
+ if (disas_neon_insn_2reg_scalar_ext(s, insn)) {
67
- proxy_sbd = SYS_BUS_DEVICE(virtio_mmio_proxy);
32
+ goto illegal_op;
68
- assert(proxy_sbd->num_mmio == 1);
33
+ }
69
- assert(proxy_sbd->mmio[0].memory == &virtio_mmio_proxy->iomem);
34
+ } else if (((insn >> 24) & 3) == 3) {
70
+ section = memory_region_find(&virtio_mmio_proxy->iomem, 0, 0x200);
35
/* Translate into the equivalent ARM encoding. */
71
+ assert(section.mr);
36
insn = (insn & 0xe2ffffff) | ((insn & (1 << 28)) >> 4) | (1 << 28);
72
37
if (disas_neon_data_insn(s, insn)) {
73
if (proxy_path) {
74
path = g_strdup_printf("%s/virtio-mmio@" TARGET_FMT_plx, proxy_path,
75
- proxy_sbd->mmio[0].addr);
76
+ section.offset_within_address_space);
77
} else {
78
path = g_strdup_printf("virtio-mmio@" TARGET_FMT_plx,
79
- proxy_sbd->mmio[0].addr);
80
+ section.offset_within_address_space);
81
}
82
+ memory_region_unref(section.mr);
83
+
84
g_free(proxy_path);
85
return path;
86
}
38
--
87
--
39
2.16.2
88
2.20.1
40
89
41
90
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Peter Collingbourne <pcc@google.com>
2
2
3
Allow the translate subroutines to return false for invalid insns.
3
Section D6.7 of the ARM ARM states:
4
4
5
At present we can of course invoke an invalid insn exception from within
5
For the purpose of determining Tag Check Fault handling, unprivileged
6
the translate subroutine, but in the short term this consolidates code.
6
load and store instructions are treated as if executed at EL0 when
7
In the long term it would allow the decodetree language to support
7
executed at either:
8
overlapping patterns for ISA extensions.
8
- EL1, when the Effective value of PSTATE.UAO is 0.
9
- EL2, when both the Effective value of HCR_EL2.{E2H, TGE} is {1, 1}
10
and the Effective value of PSTATE.UAO is 0.
9
11
10
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
12
ARM has confirmed a defect in the pseudocode function
11
Message-id: 20180227232618.2908-1-richard.henderson@linaro.org
13
AArch64.TagCheckFault that makes it inconsistent with the above
14
wording. The remedy is to adjust references to PSTATE.EL in that
15
function to instead refer to AArch64.AccessUsesEL(acctype), so
16
that unprivileged instructions use SCTLR_EL1.TCF0 and TFSRE0_EL1.
17
The exception type for synchronous tag check faults remains unchanged.
18
19
This patch implements the described change by partially reverting
20
commits 50244cc76abc and cc97b0019bb5.
21
22
Signed-off-by: Peter Collingbourne <pcc@google.com>
23
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
24
Message-id: 20210219201820.2672077-1-pcc@google.com
12
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
25
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
26
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
---
27
---
15
scripts/decodetree.py | 5 ++---
28
target/arm/helper.c | 2 +-
16
1 file changed, 2 insertions(+), 3 deletions(-)
29
target/arm/mte_helper.c | 13 +++++++++----
30
2 files changed, 10 insertions(+), 5 deletions(-)
17
31
18
diff --git a/scripts/decodetree.py b/scripts/decodetree.py
32
diff --git a/target/arm/helper.c b/target/arm/helper.c
19
index XXXXXXX..XXXXXXX 100755
33
index XXXXXXX..XXXXXXX 100644
20
--- a/scripts/decodetree.py
34
--- a/target/arm/helper.c
21
+++ b/scripts/decodetree.py
35
+++ b/target/arm/helper.c
22
@@ -XXX,XX +XXX,XX @@ class Pattern(General):
36
@@ -XXX,XX +XXX,XX @@ static uint32_t rebuild_hflags_a64(CPUARMState *env, int el, int fp_el,
23
global translate_prefix
37
if (FIELD_EX32(flags, TBFLAG_A64, UNPRIV)
24
output('typedef ', self.base.base.struct_name(),
38
&& tbid
25
' arg_', self.name, ';\n')
39
&& !(env->pstate & PSTATE_TCO)
26
- output(translate_scope, 'void ', translate_prefix, '_', self.name,
40
- && (sctlr & SCTLR_TCF)
27
+ output(translate_scope, 'bool ', translate_prefix, '_', self.name,
41
+ && (sctlr & SCTLR_TCF0)
28
'(DisasContext *ctx, arg_', self.name,
42
&& allocation_tag_access_enabled(env, 0, sctlr)) {
29
' *a, ', insntype, ' insn);\n')
43
flags = FIELD_DP32(flags, TBFLAG_A64, MTE0_ACTIVE, 1);
30
44
}
31
@@ -XXX,XX +XXX,XX @@ class Pattern(General):
45
diff --git a/target/arm/mte_helper.c b/target/arm/mte_helper.c
32
output(ind, self.base.extract_name(), '(&u.f_', arg, ', insn);\n')
46
index XXXXXXX..XXXXXXX 100644
33
for n, f in self.fields.items():
47
--- a/target/arm/mte_helper.c
34
output(ind, 'u.f_', arg, '.', n, ' = ', f.str_extract(), ';\n')
48
+++ b/target/arm/mte_helper.c
35
- output(ind, translate_prefix, '_', self.name,
49
@@ -XXX,XX +XXX,XX @@ static void mte_check_fail(CPUARMState *env, uint32_t desc,
36
+ output(ind, 'return ', translate_prefix, '_', self.name,
50
reg_el = regime_el(env, arm_mmu_idx);
37
'(ctx, &u.f_', arg, ', insn);\n')
51
sctlr = env->cp15.sctlr_el[reg_el];
38
- output(ind, 'return true;\n')
52
39
# end Pattern
53
- el = arm_current_el(env);
40
54
- if (el == 0) {
55
+ switch (arm_mmu_idx) {
56
+ case ARMMMUIdx_E10_0:
57
+ case ARMMMUIdx_E20_0:
58
+ el = 0;
59
tcf = extract64(sctlr, 38, 2);
60
- } else {
61
+ break;
62
+ default:
63
+ el = reg_el;
64
tcf = extract64(sctlr, 40, 2);
65
}
66
67
@@ -XXX,XX +XXX,XX @@ static void mte_check_fail(CPUARMState *env, uint32_t desc,
68
env->exception.vaddress = dirty_ptr;
69
70
is_write = FIELD_EX32(desc, MTEDESC, WRITE);
71
- syn = syn_data_abort_no_iss(el != 0, 0, 0, 0, 0, is_write, 0x11);
72
+ syn = syn_data_abort_no_iss(arm_current_el(env) != 0, 0, 0, 0, 0,
73
+ is_write, 0x11);
74
raise_exception(env, EXCP_DATA_ABORT, syn, exception_target_el(env));
75
/* noreturn, but fall through to the assert anyway */
41
76
42
--
77
--
43
2.16.2
78
2.20.1
44
79
45
80
diff view generated by jsdifflib
1
In v8M, the Implementation Defined Attribution Unit (IDAU) is
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
a small piece of hardware typically implemented in the SoC
3
which provides board or SoC specific security attribution
4
information for each address that the CPU performs MPU/SAU
5
checks on. For QEMU, we model this with a QOM interface which
6
is implemented by the board or SoC object and connected to
7
the CPU using a link property.
8
2
9
This commit defines the new interface class, adds the link
3
IDAU is specific to M-profile. KVM only supports A-profile.
10
property to the CPU object, and makes the SAU checking
4
Restrict this interface to TCG, as it is pointless (and
11
code call the IDAU interface if one is present.
5
confusing) on a KVM-only build.
12
6
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
10
Message-id: 20210221222617.2579610-2-f4bug@amsat.org
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
15
Message-id: 20180220180325.29818-5-peter.maydell@linaro.org
16
---
12
---
17
target/arm/cpu.h | 3 +++
13
target/arm/cpu.c | 7 -------
18
target/arm/idau.h | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++
14
target/arm/cpu_tcg.c | 8 ++++++++
19
target/arm/cpu.c | 15 +++++++++++++
15
2 files changed, 8 insertions(+), 7 deletions(-)
20
target/arm/helper.c | 28 +++++++++++++++++++++---
21
4 files changed, 104 insertions(+), 3 deletions(-)
22
create mode 100644 target/arm/idau.h
23
16
24
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
25
index XXXXXXX..XXXXXXX 100644
26
--- a/target/arm/cpu.h
27
+++ b/target/arm/cpu.h
28
@@ -XXX,XX +XXX,XX @@ struct ARMCPU {
29
/* MemoryRegion to use for secure physical accesses */
30
MemoryRegion *secure_memory;
31
32
+ /* For v8M, pointer to the IDAU interface provided by board/SoC */
33
+ Object *idau;
34
+
35
/* 'compatible' string for this CPU for Linux device trees */
36
const char *dtb_compatible;
37
38
diff --git a/target/arm/idau.h b/target/arm/idau.h
39
new file mode 100644
40
index XXXXXXX..XXXXXXX
41
--- /dev/null
42
+++ b/target/arm/idau.h
43
@@ -XXX,XX +XXX,XX @@
44
+/*
45
+ * QEMU ARM CPU -- interface for the Arm v8M IDAU
46
+ *
47
+ * Copyright (c) 2018 Linaro Ltd
48
+ *
49
+ * This program is free software; you can redistribute it and/or
50
+ * modify it under the terms of the GNU General Public License
51
+ * as published by the Free Software Foundation; either version 2
52
+ * of the License, or (at your option) any later version.
53
+ *
54
+ * This program is distributed in the hope that it will be useful,
55
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
56
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57
+ * GNU General Public License for more details.
58
+ *
59
+ * You should have received a copy of the GNU General Public License
60
+ * along with this program; if not, see
61
+ * <http://www.gnu.org/licenses/gpl-2.0.html>
62
+ *
63
+ * In the v8M architecture, the IDAU is a small piece of hardware
64
+ * typically implemented in the SoC which provides board or SoC
65
+ * specific security attribution information for each address that
66
+ * the CPU performs MPU/SAU checks on. For QEMU, we model this with a
67
+ * QOM interface which is implemented by the board or SoC object and
68
+ * connected to the CPU using a link property.
69
+ */
70
+
71
+#ifndef TARGET_ARM_IDAU_H
72
+#define TARGET_ARM_IDAU_H
73
+
74
+#include "qom/object.h"
75
+
76
+#define TYPE_IDAU_INTERFACE "idau-interface"
77
+#define IDAU_INTERFACE(obj) \
78
+ INTERFACE_CHECK(IDAUInterface, (obj), TYPE_IDAU_INTERFACE)
79
+#define IDAU_INTERFACE_CLASS(class) \
80
+ OBJECT_CLASS_CHECK(IDAUInterfaceClass, (class), TYPE_IDAU_INTERFACE)
81
+#define IDAU_INTERFACE_GET_CLASS(obj) \
82
+ OBJECT_GET_CLASS(IDAUInterfaceClass, (obj), TYPE_IDAU_INTERFACE)
83
+
84
+typedef struct IDAUInterface {
85
+ Object parent;
86
+} IDAUInterface;
87
+
88
+#define IREGION_NOTVALID -1
89
+
90
+typedef struct IDAUInterfaceClass {
91
+ InterfaceClass parent;
92
+
93
+ /* Check the specified address and return the IDAU security information
94
+ * for it by filling in iregion, exempt, ns and nsc:
95
+ * iregion: IDAU region number, or IREGION_NOTVALID if not valid
96
+ * exempt: true if address is exempt from security attribution
97
+ * ns: true if the address is NonSecure
98
+ * nsc: true if the address is NonSecure-callable
99
+ */
100
+ void (*check)(IDAUInterface *ii, uint32_t address, int *iregion,
101
+ bool *exempt, bool *ns, bool *nsc);
102
+} IDAUInterfaceClass;
103
+
104
+#endif
105
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
17
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
106
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
107
--- a/target/arm/cpu.c
19
--- a/target/arm/cpu.c
108
+++ b/target/arm/cpu.c
20
+++ b/target/arm/cpu.c
109
@@ -XXX,XX +XXX,XX @@
110
*/
111
112
#include "qemu/osdep.h"
113
+#include "target/arm/idau.h"
114
#include "qemu/error-report.h"
115
#include "qapi/error.h"
116
#include "cpu.h"
117
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_post_init(Object *obj)
118
}
119
}
120
121
+ if (arm_feature(&cpu->env, ARM_FEATURE_M_SECURITY)) {
122
+ object_property_add_link(obj, "idau", TYPE_IDAU_INTERFACE, &cpu->idau,
123
+ qdev_prop_allow_set_link_before_realize,
124
+ OBJ_PROP_LINK_UNREF_ON_RELEASE,
125
+ &error_abort);
126
+ }
127
+
128
qdev_property_add_static(DEVICE(obj), &arm_cpu_cfgend_property,
129
&error_abort);
130
}
131
@@ -XXX,XX +XXX,XX @@ static const TypeInfo arm_cpu_type_info = {
21
@@ -XXX,XX +XXX,XX @@ static const TypeInfo arm_cpu_type_info = {
132
.class_init = arm_cpu_class_init,
22
.class_init = arm_cpu_class_init,
133
};
23
};
24
25
-static const TypeInfo idau_interface_type_info = {
26
- .name = TYPE_IDAU_INTERFACE,
27
- .parent = TYPE_INTERFACE,
28
- .class_size = sizeof(IDAUInterfaceClass),
29
-};
30
-
31
static void arm_cpu_register_types(void)
32
{
33
const size_t cpu_count = ARRAY_SIZE(arm_cpus);
34
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_register_types(void)
35
if (cpu_count) {
36
size_t i;
37
38
- type_register_static(&idau_interface_type_info);
39
for (i = 0; i < cpu_count; ++i) {
40
arm_cpu_register(&arm_cpus[i]);
41
}
42
diff --git a/target/arm/cpu_tcg.c b/target/arm/cpu_tcg.c
43
index XXXXXXX..XXXXXXX 100644
44
--- a/target/arm/cpu_tcg.c
45
+++ b/target/arm/cpu_tcg.c
46
@@ -XXX,XX +XXX,XX @@
47
#include "hw/core/tcg-cpu-ops.h"
48
#endif /* CONFIG_TCG */
49
#include "internals.h"
50
+#include "target/arm/idau.h"
51
52
/* CPU models. These are not needed for the AArch64 linux-user build. */
53
#if !defined(CONFIG_USER_ONLY) || !defined(TARGET_AARCH64)
54
@@ -XXX,XX +XXX,XX @@ static const ARMCPUInfo arm_tcg_cpus[] = {
55
{ .name = "pxa270-c5", .initfn = pxa270c5_initfn },
56
};
134
57
135
+static const TypeInfo idau_interface_type_info = {
58
+static const TypeInfo idau_interface_type_info = {
136
+ .name = TYPE_IDAU_INTERFACE,
59
+ .name = TYPE_IDAU_INTERFACE,
137
+ .parent = TYPE_INTERFACE,
60
+ .parent = TYPE_INTERFACE,
138
+ .class_size = sizeof(IDAUInterfaceClass),
61
+ .class_size = sizeof(IDAUInterfaceClass),
139
+};
62
+};
140
+
63
+
141
static void arm_cpu_register_types(void)
64
static void arm_tcg_cpu_register_types(void)
142
{
65
{
143
const ARMCPUInfo *info = arm_cpus;
66
size_t i;
144
67
145
type_register_static(&arm_cpu_type_info);
146
+ type_register_static(&idau_interface_type_info);
68
+ type_register_static(&idau_interface_type_info);
147
69
for (i = 0; i < ARRAY_SIZE(arm_tcg_cpus); ++i) {
148
while (info->name) {
70
arm_cpu_register(&arm_tcg_cpus[i]);
149
cpu_register(info);
150
diff --git a/target/arm/helper.c b/target/arm/helper.c
151
index XXXXXXX..XXXXXXX 100644
152
--- a/target/arm/helper.c
153
+++ b/target/arm/helper.c
154
@@ -XXX,XX +XXX,XX @@
155
#include "qemu/osdep.h"
156
+#include "target/arm/idau.h"
157
#include "trace.h"
158
#include "cpu.h"
159
#include "internals.h"
160
@@ -XXX,XX +XXX,XX @@ static void v8m_security_lookup(CPUARMState *env, uint32_t address,
161
*/
162
ARMCPU *cpu = arm_env_get_cpu(env);
163
int r;
164
+ bool idau_exempt = false, idau_ns = true, idau_nsc = true;
165
+ int idau_region = IREGION_NOTVALID;
166
167
- /* TODO: implement IDAU */
168
+ if (cpu->idau) {
169
+ IDAUInterfaceClass *iic = IDAU_INTERFACE_GET_CLASS(cpu->idau);
170
+ IDAUInterface *ii = IDAU_INTERFACE(cpu->idau);
171
+
172
+ iic->check(ii, address, &idau_region, &idau_exempt, &idau_ns,
173
+ &idau_nsc);
174
+ }
175
176
if (access_type == MMU_INST_FETCH && extract32(address, 28, 4) == 0xf) {
177
/* 0xf0000000..0xffffffff is always S for insn fetches */
178
return;
179
}
71
}
180
181
- if (v8m_is_sau_exempt(env, address, access_type)) {
182
+ if (idau_exempt || v8m_is_sau_exempt(env, address, access_type)) {
183
sattrs->ns = !regime_is_secure(env, mmu_idx);
184
return;
185
}
186
187
+ if (idau_region != IREGION_NOTVALID) {
188
+ sattrs->irvalid = true;
189
+ sattrs->iregion = idau_region;
190
+ }
191
+
192
switch (env->sau.ctrl & 3) {
193
case 0: /* SAU.ENABLE == 0, SAU.ALLNS == 0 */
194
break;
195
@@ -XXX,XX +XXX,XX @@ static void v8m_security_lookup(CPUARMState *env, uint32_t address,
196
}
197
}
198
199
- /* TODO when we support the IDAU then it may override the result here */
200
+ /* The IDAU will override the SAU lookup results if it specifies
201
+ * higher security than the SAU does.
202
+ */
203
+ if (!idau_ns) {
204
+ if (sattrs->ns || (!idau_nsc && sattrs->nsc)) {
205
+ sattrs->ns = false;
206
+ sattrs->nsc = idau_nsc;
207
+ }
208
+ }
209
break;
210
}
211
}
212
--
72
--
213
2.16.2
73
2.20.1
214
74
215
75
diff view generated by jsdifflib
1
Add a Cortex-M33 definition. The M33 is an M profile CPU
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
which implements the ARM v8M architecture, including the
3
M profile Security Extension.
4
2
3
We will move this code in the next commit. Clean it up
4
first to avoid checkpatch.pl errors.
5
6
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Message-id: 20210221222617.2579610-3-f4bug@amsat.org
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20180220180325.29818-9-peter.maydell@linaro.org
8
---
10
---
9
target/arm/cpu.c | 31 +++++++++++++++++++++++++++++++
11
target/arm/cpu.c | 12 ++++++++----
10
1 file changed, 31 insertions(+)
12
1 file changed, 8 insertions(+), 4 deletions(-)
11
13
12
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
14
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
13
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
14
--- a/target/arm/cpu.c
16
--- a/target/arm/cpu.c
15
+++ b/target/arm/cpu.c
17
+++ b/target/arm/cpu.c
16
@@ -XXX,XX +XXX,XX @@ static void cortex_m4_initfn(Object *obj)
18
@@ -XXX,XX +XXX,XX @@ static void cortex_a8_initfn(Object *obj)
17
cpu->id_isar5 = 0x00000000;
18
}
19
}
19
20
20
+static void cortex_m33_initfn(Object *obj)
21
static const ARMCPRegInfo cortexa9_cp_reginfo[] = {
21
+{
22
- /* power_control should be set to maximum latency. Again,
22
+ ARMCPU *cpu = ARM_CPU(obj);
23
+ /*
23
+
24
+ * power_control should be set to maximum latency. Again,
24
+ set_feature(&cpu->env, ARM_FEATURE_V8);
25
* default to 0 and set by private hook
25
+ set_feature(&cpu->env, ARM_FEATURE_M);
26
*/
26
+ set_feature(&cpu->env, ARM_FEATURE_M_SECURITY);
27
{ .name = "A9_PWRCTL", .cp = 15, .crn = 15, .crm = 0, .opc1 = 0, .opc2 = 0,
27
+ set_feature(&cpu->env, ARM_FEATURE_THUMB_DSP);
28
@@ -XXX,XX +XXX,XX @@ static void cortex_a9_initfn(Object *obj)
28
+ cpu->midr = 0x410fd213; /* r0p3 */
29
set_feature(&cpu->env, ARM_FEATURE_NEON);
29
+ cpu->pmsav7_dregion = 16;
30
set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
30
+ cpu->sau_sregion = 8;
31
set_feature(&cpu->env, ARM_FEATURE_EL3);
31
+ cpu->id_pfr0 = 0x00000030;
32
- /* Note that A9 supports the MP extensions even for
32
+ cpu->id_pfr1 = 0x00000210;
33
+ /*
33
+ cpu->id_dfr0 = 0x00200000;
34
+ * Note that A9 supports the MP extensions even for
34
+ cpu->id_afr0 = 0x00000000;
35
* A9UP and single-core A9MP (which are both different
35
+ cpu->id_mmfr0 = 0x00101F40;
36
* and valid configurations; we don't model A9UP).
36
+ cpu->id_mmfr1 = 0x00000000;
37
*/
37
+ cpu->id_mmfr2 = 0x01000000;
38
@@ -XXX,XX +XXX,XX @@ static uint64_t a15_l2ctlr_read(CPUARMState *env, const ARMCPRegInfo *ri)
38
+ cpu->id_mmfr3 = 0x00000000;
39
+ cpu->id_isar0 = 0x01101110;
40
+ cpu->id_isar1 = 0x02212000;
41
+ cpu->id_isar2 = 0x20232232;
42
+ cpu->id_isar3 = 0x01111131;
43
+ cpu->id_isar4 = 0x01310132;
44
+ cpu->id_isar5 = 0x00000000;
45
+ cpu->clidr = 0x00000000;
46
+ cpu->ctr = 0x8000c000;
47
+}
48
+
49
static void arm_v7m_class_init(ObjectClass *oc, void *data)
50
{
39
{
51
CPUClass *cc = CPU_CLASS(oc);
40
MachineState *ms = MACHINE(qdev_get_machine());
52
@@ -XXX,XX +XXX,XX @@ static const ARMCPUInfo arm_cpus[] = {
41
53
.class_init = arm_v7m_class_init },
42
- /* Linux wants the number of processors from here.
54
{ .name = "cortex-m4", .initfn = cortex_m4_initfn,
43
+ /*
55
.class_init = arm_v7m_class_init },
44
+ * Linux wants the number of processors from here.
56
+ { .name = "cortex-m33", .initfn = cortex_m33_initfn,
45
* Might as well set the interrupt-controller bit too.
57
+ .class_init = arm_v7m_class_init },
46
*/
58
{ .name = "cortex-r5", .initfn = cortex_r5_initfn },
47
return ((ms->smp.cpus - 1) << 24) | (1 << 23);
59
{ .name = "cortex-a7", .initfn = cortex_a7_initfn },
48
@@ -XXX,XX +XXX,XX @@ static void cortex_a7_initfn(Object *obj)
60
{ .name = "cortex-a8", .initfn = cortex_a8_initfn },
49
cpu->isar.id_mmfr1 = 0x40000000;
50
cpu->isar.id_mmfr2 = 0x01240000;
51
cpu->isar.id_mmfr3 = 0x02102211;
52
- /* a7_mpcore_r0p5_trm, page 4-4 gives 0x01101110; but
53
+ /*
54
+ * a7_mpcore_r0p5_trm, page 4-4 gives 0x01101110; but
55
* table 4-41 gives 0x02101110, which includes the arm div insns.
56
*/
57
cpu->isar.id_isar0 = 0x02101110;
61
--
58
--
62
2.16.2
59
2.20.1
63
60
64
61
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
For a long time now the UI layer has guaranteed that the console
2
surface is always 32 bits per pixel RGB. Remove the legacy dead
3
code from the milkymist display device which was handling the
4
possibility that the console surface was some other format.
2
5
3
The integer size check was already outside of the opcode switch;
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
move the floating-point size check outside as well. Unify the
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
size vs index adjustment between fp and integer paths.
8
Message-id: 20210215103215.4944-2-peter.maydell@linaro.org
9
---
10
hw/arm/musicpal.c | 64 ++++++++++++++++++-----------------------------
11
1 file changed, 24 insertions(+), 40 deletions(-)
6
12
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
13
diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
Message-id: 20180228193125.20577-4-richard.henderson@linaro.org
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
12
target/arm/translate-a64.c | 65 +++++++++++++++++++++++-----------------------
13
1 file changed, 32 insertions(+), 33 deletions(-)
14
15
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
16
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
17
--- a/target/arm/translate-a64.c
15
--- a/hw/arm/musicpal.c
18
+++ b/target/arm/translate-a64.c
16
+++ b/hw/arm/musicpal.c
19
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
17
@@ -XXX,XX +XXX,XX @@ static uint8_t scale_lcd_color(musicpal_lcd_state *s, uint8_t col)
20
case 0x05: /* FMLS */
18
}
21
case 0x09: /* FMUL */
19
}
22
case 0x19: /* FMULX */
20
23
- if (size == 1) {
21
-#define SET_LCD_PIXEL(depth, type) \
24
- unallocated_encoding(s);
22
-static inline void glue(set_lcd_pixel, depth) \
25
- return;
23
- (musicpal_lcd_state *s, int x, int y, type col) \
26
- }
24
-{ \
27
is_fp = true;
25
- int dx, dy; \
28
break;
26
- DisplaySurface *surface = qemu_console_surface(s->con); \
29
default:
27
- type *pixel = &((type *) surface_data(surface))[(y * 128 * 3 + x) * 3]; \
30
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
28
-\
31
if (is_fp) {
29
- for (dy = 0; dy < 3; dy++, pixel += 127 * 3) \
32
/* convert insn encoded size to TCGMemOp size */
30
- for (dx = 0; dx < 3; dx++, pixel++) \
33
switch (size) {
31
- *pixel = col; \
34
- case 2: /* single precision */
32
+static inline void set_lcd_pixel32(musicpal_lcd_state *s,
35
- size = MO_32;
33
+ int x, int y, uint32_t col)
36
- index = h << 1 | l;
34
+{
37
- rm |= (m << 4);
35
+ int dx, dy;
38
- break;
36
+ DisplaySurface *surface = qemu_console_surface(s->con);
39
- case 3: /* double precision */
37
+ uint32_t *pixel =
40
- size = MO_64;
38
+ &((uint32_t *) surface_data(surface))[(y * 128 * 3 + x) * 3];
41
- if (l || !is_q) {
39
+
42
+ case 0: /* half-precision */
40
+ for (dy = 0; dy < 3; dy++, pixel += 127 * 3) {
43
+ if (!arm_dc_feature(s, ARM_FEATURE_V8_FP16)) {
41
+ for (dx = 0; dx < 3; dx++, pixel++) {
44
unallocated_encoding(s);
42
+ *pixel = col;
45
return;
46
}
47
- index = h;
48
- rm |= (m << 4);
49
- break;
50
- case 0: /* half precision */
51
size = MO_16;
52
- index = h << 2 | l << 1 | m;
53
- is_fp16 = true;
54
- if (arm_dc_feature(s, ARM_FEATURE_V8_FP16)) {
55
- break;
56
- }
57
- /* fallthru */
58
- default: /* unallocated */
59
- unallocated_encoding(s);
60
- return;
61
- }
62
- } else {
63
- switch (size) {
64
- case 1:
65
- index = h << 2 | l << 1 | m;
66
break;
67
- case 2:
68
- index = h << 1 | l;
69
- rm |= (m << 4);
70
+ case MO_32: /* single precision */
71
+ case MO_64: /* double precision */
72
break;
73
default:
74
unallocated_encoding(s);
75
return;
76
}
77
+ } else {
78
+ switch (size) {
79
+ case MO_8:
80
+ case MO_64:
81
+ unallocated_encoding(s);
82
+ return;
83
+ }
43
+ }
84
+ }
44
+ }
85
+
45
}
86
+ /* Given TCGMemOp size, adjust register and indexing. */
46
-SET_LCD_PIXEL(8, uint8_t)
87
+ switch (size) {
47
-SET_LCD_PIXEL(16, uint16_t)
88
+ case MO_16:
48
-SET_LCD_PIXEL(32, uint32_t)
89
+ index = h << 2 | l << 1 | m;
49
90
+ break;
50
static void lcd_refresh(void *opaque)
91
+ case MO_32:
51
{
92
+ index = h << 1 | l;
52
musicpal_lcd_state *s = opaque;
93
+ rm |= m << 4;
53
- DisplaySurface *surface = qemu_console_surface(s->con);
94
+ break;
54
int x, y, col;
95
+ case MO_64:
55
96
+ if (l || !is_q) {
56
- switch (surface_bits_per_pixel(surface)) {
97
+ unallocated_encoding(s);
57
- case 0:
98
+ return;
58
- return;
59
-#define LCD_REFRESH(depth, func) \
60
- case depth: \
61
- col = func(scale_lcd_color(s, (MP_LCD_TEXTCOLOR >> 16) & 0xff), \
62
- scale_lcd_color(s, (MP_LCD_TEXTCOLOR >> 8) & 0xff), \
63
- scale_lcd_color(s, MP_LCD_TEXTCOLOR & 0xff)); \
64
- for (x = 0; x < 128; x++) { \
65
- for (y = 0; y < 64; y++) { \
66
- if (s->video_ram[x + (y/8)*128] & (1 << (y % 8))) { \
67
- glue(set_lcd_pixel, depth)(s, x, y, col); \
68
- } else { \
69
- glue(set_lcd_pixel, depth)(s, x, y, 0); \
70
- } \
71
- } \
72
- } \
73
- break;
74
- LCD_REFRESH(8, rgb_to_pixel8)
75
- LCD_REFRESH(16, rgb_to_pixel16)
76
- LCD_REFRESH(32, (is_surface_bgr(surface) ?
77
- rgb_to_pixel32bgr : rgb_to_pixel32))
78
- default:
79
- hw_error("unsupported colour depth %i\n",
80
- surface_bits_per_pixel(surface));
81
+ col = rgb_to_pixel32(scale_lcd_color(s, (MP_LCD_TEXTCOLOR >> 16) & 0xff),
82
+ scale_lcd_color(s, (MP_LCD_TEXTCOLOR >> 8) & 0xff),
83
+ scale_lcd_color(s, MP_LCD_TEXTCOLOR & 0xff));
84
+ for (x = 0; x < 128; x++) {
85
+ for (y = 0; y < 64; y++) {
86
+ if (s->video_ram[x + (y / 8) * 128] & (1 << (y % 8))) {
87
+ set_lcd_pixel32(s, x, y, col);
88
+ } else {
89
+ set_lcd_pixel32(s, x, y, 0);
90
+ }
99
+ }
91
+ }
100
+ index = h;
101
+ rm |= m << 4;
102
+ break;
103
+ default:
104
+ g_assert_not_reached();
105
}
92
}
106
93
107
if (!fp_access_check(s)) {
94
dpy_gfx_update(s->con, 0, 0, 128*3, 64*3);
108
--
95
--
109
2.16.2
96
2.20.1
110
97
111
98
diff view generated by jsdifflib
New patch
1
For a long time now the UI layer has guaranteed that the console
2
surface is always 32 bits per pixel RGB. Remove the legacy dead
3
code from the tc6393xb display device which was handling the
4
possibility that the console surface was some other format.
1
5
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20210215103215.4944-3-peter.maydell@linaro.org
9
---
10
include/ui/console.h | 10 ----------
11
hw/display/tc6393xb.c | 33 +--------------------------------
12
2 files changed, 1 insertion(+), 42 deletions(-)
13
14
diff --git a/include/ui/console.h b/include/ui/console.h
15
index XXXXXXX..XXXXXXX 100644
16
--- a/include/ui/console.h
17
+++ b/include/ui/console.h
18
@@ -XXX,XX +XXX,XX @@ PixelFormat qemu_default_pixelformat(int bpp);
19
DisplaySurface *qemu_create_displaysurface(int width, int height);
20
void qemu_free_displaysurface(DisplaySurface *surface);
21
22
-static inline int is_surface_bgr(DisplaySurface *surface)
23
-{
24
- if (PIXMAN_FORMAT_BPP(surface->format) == 32 &&
25
- PIXMAN_FORMAT_TYPE(surface->format) == PIXMAN_TYPE_ABGR) {
26
- return 1;
27
- } else {
28
- return 0;
29
- }
30
-}
31
-
32
static inline int is_buffer_shared(DisplaySurface *surface)
33
{
34
return !(surface->flags & QEMU_ALLOCATED_FLAG);
35
diff --git a/hw/display/tc6393xb.c b/hw/display/tc6393xb.c
36
index XXXXXXX..XXXXXXX 100644
37
--- a/hw/display/tc6393xb.c
38
+++ b/hw/display/tc6393xb.c
39
@@ -XXX,XX +XXX,XX @@ static void tc6393xb_nand_writeb(TC6393xbState *s, hwaddr addr, uint32_t value)
40
(uint32_t) addr, value & 0xff);
41
}
42
43
-#define BITS 8
44
-#include "tc6393xb_template.h"
45
-#define BITS 15
46
-#include "tc6393xb_template.h"
47
-#define BITS 16
48
-#include "tc6393xb_template.h"
49
-#define BITS 24
50
-#include "tc6393xb_template.h"
51
#define BITS 32
52
#include "tc6393xb_template.h"
53
54
static void tc6393xb_draw_graphic(TC6393xbState *s, int full_update)
55
{
56
- DisplaySurface *surface = qemu_console_surface(s->con);
57
-
58
- switch (surface_bits_per_pixel(surface)) {
59
- case 8:
60
- tc6393xb_draw_graphic8(s);
61
- break;
62
- case 15:
63
- tc6393xb_draw_graphic15(s);
64
- break;
65
- case 16:
66
- tc6393xb_draw_graphic16(s);
67
- break;
68
- case 24:
69
- tc6393xb_draw_graphic24(s);
70
- break;
71
- case 32:
72
- tc6393xb_draw_graphic32(s);
73
- break;
74
- default:
75
- printf("tc6393xb: unknown depth %d\n",
76
- surface_bits_per_pixel(surface));
77
- return;
78
- }
79
-
80
+ tc6393xb_draw_graphic32(s);
81
dpy_gfx_update_full(s->con);
82
}
83
84
--
85
2.20.1
86
87
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
Now the template header is included only for BITS==32, expand
2
out all the macros that depended on the BITS setting.
2
3
3
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
Message-id: 20180228193125.20577-9-richard.henderson@linaro.org
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
Message-id: 20210215103215.4944-4-peter.maydell@linaro.org
7
---
7
---
8
target/arm/translate.c | 46 ++++++++++++++++++++++++++++++++++++++++++----
8
hw/display/tc6393xb_template.h | 35 ++++------------------------------
9
1 file changed, 42 insertions(+), 4 deletions(-)
9
1 file changed, 4 insertions(+), 31 deletions(-)
10
10
11
diff --git a/target/arm/translate.c b/target/arm/translate.c
11
diff --git a/hw/display/tc6393xb_template.h b/hw/display/tc6393xb_template.h
12
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
13
--- a/target/arm/translate.c
13
--- a/hw/display/tc6393xb_template.h
14
+++ b/target/arm/translate.c
14
+++ b/hw/display/tc6393xb_template.h
15
@@ -XXX,XX +XXX,XX @@ static const char *regnames[] =
15
@@ -XXX,XX +XXX,XX @@
16
{ "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
16
* with this program; if not, see <http://www.gnu.org/licenses/>.
17
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "pc" };
17
*/
18
18
19
+/* Function prototypes for gen_ functions calling Neon helpers. */
19
-#if BITS == 8
20
+typedef void NeonGenThreeOpEnvFn(TCGv_i32, TCGv_env, TCGv_i32,
20
-# define SET_PIXEL(addr, color) (*(uint8_t *)addr = color)
21
+ TCGv_i32, TCGv_i32);
21
-#elif BITS == 15 || BITS == 16
22
+
22
-# define SET_PIXEL(addr, color) (*(uint16_t *)addr = color)
23
/* initialize TCG globals. */
23
-#elif BITS == 24
24
void arm_translate_init(void)
24
-# define SET_PIXEL(addr, color) \
25
{
25
- do { \
26
@@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn)
26
- addr[0] = color; \
27
}
27
- addr[1] = (color) >> 8; \
28
neon_store_reg64(cpu_V0, rd + pass);
28
- addr[2] = (color) >> 16; \
29
}
29
- } while (0)
30
-#elif BITS == 32
31
-# define SET_PIXEL(addr, color) (*(uint32_t *)addr = color)
32
-#else
33
-# error unknown bit depth
34
-#endif
30
-
35
-
31
-
36
-
32
break;
37
-static void glue(tc6393xb_draw_graphic, BITS)(TC6393xbState *s)
33
- default: /* 14 and 15 are RESERVED */
38
+static void tc6393xb_draw_graphic32(TC6393xbState *s)
34
- return 1;
39
{
35
+ case 14: /* VQRDMLAH scalar */
40
DisplaySurface *surface = qemu_console_surface(s->con);
36
+ case 15: /* VQRDMLSH scalar */
41
int i;
37
+ {
42
@@ -XXX,XX +XXX,XX @@ static void glue(tc6393xb_draw_graphic, BITS)(TC6393xbState *s)
38
+ NeonGenThreeOpEnvFn *fn;
43
data_buffer = s->vram_ptr;
39
+
44
data_display = surface_data(surface);
40
+ if (!arm_dc_feature(s, ARM_FEATURE_V8_RDM)) {
45
for(i = 0; i < s->scr_height; i++) {
41
+ return 1;
46
-#if (BITS == 16)
42
+ }
47
- memcpy(data_display, data_buffer, s->scr_width * 2);
43
+ if (u && ((rd | rn) & 1)) {
48
- data_buffer += s->scr_width;
44
+ return 1;
49
- data_display += surface_stride(surface);
45
+ }
50
-#else
46
+ if (op == 14) {
51
int j;
47
+ if (size == 1) {
52
- for (j = 0; j < s->scr_width; j++, data_display += BITS / 8, data_buffer++) {
48
+ fn = gen_helper_neon_qrdmlah_s16;
53
+ for (j = 0; j < s->scr_width; j++, data_display += 4, data_buffer++) {
49
+ } else {
54
uint16_t color = *data_buffer;
50
+ fn = gen_helper_neon_qrdmlah_s32;
55
- uint32_t dest_color = glue(rgb_to_pixel, BITS)(
51
+ }
56
+ uint32_t dest_color = rgb_to_pixel32(
52
+ } else {
57
((color & 0xf800) * 0x108) >> 11,
53
+ if (size == 1) {
58
((color & 0x7e0) * 0x41) >> 9,
54
+ fn = gen_helper_neon_qrdmlsh_s16;
59
((color & 0x1f) * 0x21) >> 2
55
+ } else {
60
);
56
+ fn = gen_helper_neon_qrdmlsh_s32;
61
- SET_PIXEL(data_display, dest_color);
57
+ }
62
+ *(uint32_t *)data_display = dest_color;
58
+ }
63
}
59
+
64
-#endif
60
+ tmp2 = neon_get_scalar(size, rm);
65
}
61
+ for (pass = 0; pass < (u ? 4 : 2); pass++) {
66
}
62
+ tmp = neon_load_reg(rn, pass);
67
-
63
+ tmp3 = neon_load_reg(rd, pass);
68
-#undef BITS
64
+ fn(tmp, cpu_env, tmp, tmp2, tmp3);
69
-#undef SET_PIXEL
65
+ tcg_temp_free_i32(tmp3);
66
+ neon_store_reg(rd, pass, tmp);
67
+ }
68
+ tcg_temp_free_i32(tmp2);
69
+ }
70
+ break;
71
+ default:
72
+ g_assert_not_reached();
73
}
74
}
75
} else { /* size == 3 */
76
--
70
--
77
2.16.2
71
2.20.1
78
72
79
73
diff view generated by jsdifflib
New patch
1
The function tc6393xb_draw_graphic32() is called in exactly one place,
2
so just inline the function body at its callsite. This allows us to
3
drop the template header entirely.
1
4
5
The code move includes a single added space after 'for' to fix
6
the coding style.
7
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
11
Message-id: 20210215103215.4944-5-peter.maydell@linaro.org
12
---
13
hw/display/tc6393xb_template.h | 45 ----------------------------------
14
hw/display/tc6393xb.c | 23 ++++++++++++++---
15
2 files changed, 19 insertions(+), 49 deletions(-)
16
delete mode 100644 hw/display/tc6393xb_template.h
17
18
diff --git a/hw/display/tc6393xb_template.h b/hw/display/tc6393xb_template.h
19
deleted file mode 100644
20
index XXXXXXX..XXXXXXX
21
--- a/hw/display/tc6393xb_template.h
22
+++ /dev/null
23
@@ -XXX,XX +XXX,XX @@
24
-/*
25
- * Toshiba TC6393XB I/O Controller.
26
- * Found in Sharp Zaurus SL-6000 (tosa) or some
27
- * Toshiba e-Series PDAs.
28
- *
29
- * FB support code. Based on G364 fb emulator
30
- *
31
- * Copyright (c) 2007 Hervé Poussineau
32
- *
33
- * This program is free software; you can redistribute it and/or
34
- * modify it under the terms of the GNU General Public License as
35
- * published by the Free Software Foundation; either version 2 of
36
- * the License, or (at your option) any later version.
37
- *
38
- * This program is distributed in the hope that it will be useful,
39
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
40
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41
- * GNU General Public License for more details.
42
- *
43
- * You should have received a copy of the GNU General Public License along
44
- * with this program; if not, see <http://www.gnu.org/licenses/>.
45
- */
46
-
47
-static void tc6393xb_draw_graphic32(TC6393xbState *s)
48
-{
49
- DisplaySurface *surface = qemu_console_surface(s->con);
50
- int i;
51
- uint16_t *data_buffer;
52
- uint8_t *data_display;
53
-
54
- data_buffer = s->vram_ptr;
55
- data_display = surface_data(surface);
56
- for(i = 0; i < s->scr_height; i++) {
57
- int j;
58
- for (j = 0; j < s->scr_width; j++, data_display += 4, data_buffer++) {
59
- uint16_t color = *data_buffer;
60
- uint32_t dest_color = rgb_to_pixel32(
61
- ((color & 0xf800) * 0x108) >> 11,
62
- ((color & 0x7e0) * 0x41) >> 9,
63
- ((color & 0x1f) * 0x21) >> 2
64
- );
65
- *(uint32_t *)data_display = dest_color;
66
- }
67
- }
68
-}
69
diff --git a/hw/display/tc6393xb.c b/hw/display/tc6393xb.c
70
index XXXXXXX..XXXXXXX 100644
71
--- a/hw/display/tc6393xb.c
72
+++ b/hw/display/tc6393xb.c
73
@@ -XXX,XX +XXX,XX @@ static void tc6393xb_nand_writeb(TC6393xbState *s, hwaddr addr, uint32_t value)
74
(uint32_t) addr, value & 0xff);
75
}
76
77
-#define BITS 32
78
-#include "tc6393xb_template.h"
79
-
80
static void tc6393xb_draw_graphic(TC6393xbState *s, int full_update)
81
{
82
- tc6393xb_draw_graphic32(s);
83
+ DisplaySurface *surface = qemu_console_surface(s->con);
84
+ int i;
85
+ uint16_t *data_buffer;
86
+ uint8_t *data_display;
87
+
88
+ data_buffer = s->vram_ptr;
89
+ data_display = surface_data(surface);
90
+ for (i = 0; i < s->scr_height; i++) {
91
+ int j;
92
+ for (j = 0; j < s->scr_width; j++, data_display += 4, data_buffer++) {
93
+ uint16_t color = *data_buffer;
94
+ uint32_t dest_color = rgb_to_pixel32(
95
+ ((color & 0xf800) * 0x108) >> 11,
96
+ ((color & 0x7e0) * 0x41) >> 9,
97
+ ((color & 0x1f) * 0x21) >> 2
98
+ );
99
+ *(uint32_t *)data_display = dest_color;
100
+ }
101
+ }
102
dpy_gfx_update_full(s->con);
103
}
104
105
--
106
2.20.1
107
108
diff view generated by jsdifflib
New patch
1
The omap_lcdc template header is already only included once, for
2
DEPTH==32, but it still has all the macro-driven parameterization
3
for other depths. Expand out all the macros in the header.
1
4
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Message-id: 20210215103215.4944-6-peter.maydell@linaro.org
9
---
10
hw/display/omap_lcd_template.h | 67 ++++++++++++++--------------------
11
1 file changed, 28 insertions(+), 39 deletions(-)
12
13
diff --git a/hw/display/omap_lcd_template.h b/hw/display/omap_lcd_template.h
14
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/display/omap_lcd_template.h
16
+++ b/hw/display/omap_lcd_template.h
17
@@ -XXX,XX +XXX,XX @@
18
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19
*/
20
21
-#if DEPTH == 32
22
-# define BPP 4
23
-# define PIXEL_TYPE uint32_t
24
-#else
25
-# error unsupport depth
26
-#endif
27
-
28
/*
29
* 2-bit colour
30
*/
31
-static void glue(draw_line2_, DEPTH)(void *opaque,
32
- uint8_t *d, const uint8_t *s, int width, int deststep)
33
+static void draw_line2_32(void *opaque, uint8_t *d, const uint8_t *s,
34
+ int width, int deststep)
35
{
36
uint16_t *pal = opaque;
37
uint8_t v, r, g, b;
38
@@ -XXX,XX +XXX,XX @@ static void glue(draw_line2_, DEPTH)(void *opaque,
39
r = (pal[v & 3] >> 4) & 0xf0;
40
g = pal[v & 3] & 0xf0;
41
b = (pal[v & 3] << 4) & 0xf0;
42
- ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
43
- d += BPP;
44
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
45
+ d += 4;
46
v >>= 2;
47
r = (pal[v & 3] >> 4) & 0xf0;
48
g = pal[v & 3] & 0xf0;
49
b = (pal[v & 3] << 4) & 0xf0;
50
- ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
51
- d += BPP;
52
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
53
+ d += 4;
54
v >>= 2;
55
r = (pal[v & 3] >> 4) & 0xf0;
56
g = pal[v & 3] & 0xf0;
57
b = (pal[v & 3] << 4) & 0xf0;
58
- ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
59
- d += BPP;
60
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
61
+ d += 4;
62
v >>= 2;
63
r = (pal[v & 3] >> 4) & 0xf0;
64
g = pal[v & 3] & 0xf0;
65
b = (pal[v & 3] << 4) & 0xf0;
66
- ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
67
- d += BPP;
68
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
69
+ d += 4;
70
s ++;
71
width -= 4;
72
} while (width > 0);
73
@@ -XXX,XX +XXX,XX @@ static void glue(draw_line2_, DEPTH)(void *opaque,
74
/*
75
* 4-bit colour
76
*/
77
-static void glue(draw_line4_, DEPTH)(void *opaque,
78
- uint8_t *d, const uint8_t *s, int width, int deststep)
79
+static void draw_line4_32(void *opaque, uint8_t *d, const uint8_t *s,
80
+ int width, int deststep)
81
{
82
uint16_t *pal = opaque;
83
uint8_t v, r, g, b;
84
@@ -XXX,XX +XXX,XX @@ static void glue(draw_line4_, DEPTH)(void *opaque,
85
r = (pal[v & 0xf] >> 4) & 0xf0;
86
g = pal[v & 0xf] & 0xf0;
87
b = (pal[v & 0xf] << 4) & 0xf0;
88
- ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
89
- d += BPP;
90
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
91
+ d += 4;
92
v >>= 4;
93
r = (pal[v & 0xf] >> 4) & 0xf0;
94
g = pal[v & 0xf] & 0xf0;
95
b = (pal[v & 0xf] << 4) & 0xf0;
96
- ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
97
- d += BPP;
98
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
99
+ d += 4;
100
s ++;
101
width -= 2;
102
} while (width > 0);
103
@@ -XXX,XX +XXX,XX @@ static void glue(draw_line4_, DEPTH)(void *opaque,
104
/*
105
* 8-bit colour
106
*/
107
-static void glue(draw_line8_, DEPTH)(void *opaque,
108
- uint8_t *d, const uint8_t *s, int width, int deststep)
109
+static void draw_line8_32(void *opaque, uint8_t *d, const uint8_t *s,
110
+ int width, int deststep)
111
{
112
uint16_t *pal = opaque;
113
uint8_t v, r, g, b;
114
@@ -XXX,XX +XXX,XX @@ static void glue(draw_line8_, DEPTH)(void *opaque,
115
r = (pal[v] >> 4) & 0xf0;
116
g = pal[v] & 0xf0;
117
b = (pal[v] << 4) & 0xf0;
118
- ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
119
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
120
s ++;
121
- d += BPP;
122
+ d += 4;
123
} while (-- width != 0);
124
}
125
126
/*
127
* 12-bit colour
128
*/
129
-static void glue(draw_line12_, DEPTH)(void *opaque,
130
- uint8_t *d, const uint8_t *s, int width, int deststep)
131
+static void draw_line12_32(void *opaque, uint8_t *d, const uint8_t *s,
132
+ int width, int deststep)
133
{
134
uint16_t v;
135
uint8_t r, g, b;
136
@@ -XXX,XX +XXX,XX @@ static void glue(draw_line12_, DEPTH)(void *opaque,
137
r = (v >> 4) & 0xf0;
138
g = v & 0xf0;
139
b = (v << 4) & 0xf0;
140
- ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
141
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
142
s += 2;
143
- d += BPP;
144
+ d += 4;
145
} while (-- width != 0);
146
}
147
148
/*
149
* 16-bit colour
150
*/
151
-static void glue(draw_line16_, DEPTH)(void *opaque,
152
- uint8_t *d, const uint8_t *s, int width, int deststep)
153
+static void draw_line16_32(void *opaque, uint8_t *d, const uint8_t *s,
154
+ int width, int deststep)
155
{
156
#if defined(HOST_WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN)
157
memcpy(d, s, width * 2);
158
@@ -XXX,XX +XXX,XX @@ static void glue(draw_line16_, DEPTH)(void *opaque,
159
r = (v >> 8) & 0xf8;
160
g = (v >> 3) & 0xfc;
161
b = (v << 3) & 0xf8;
162
- ((PIXEL_TYPE *) d)[0] = glue(rgb_to_pixel, DEPTH)(r, g, b);
163
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
164
s += 2;
165
- d += BPP;
166
+ d += 4;
167
} while (-- width != 0);
168
#endif
169
}
170
-
171
-#undef DEPTH
172
-#undef BPP
173
-#undef PIXEL_TYPE
174
--
175
2.20.1
176
177
diff view generated by jsdifflib
New patch
1
The draw_line16_32() function in the omap_lcdc template header
2
includes an ifdef for the case where HOST_WORDS_BIGENDIAN matches
3
TARGET_WORDS_BIGENDIAN. This is trying to optimise for "source
4
bitmap and destination bitmap format match", but it is broken,
5
because in this function the formats don't match: the source is
6
16-bit colour and the destination is 32-bit colour, so a memcpy()
7
will produce corrupted graphics output. Drop the bogus ifdef.
1
8
9
This bug was introduced in commit ea644cf343129, when we dropped
10
support for DEPTH values other than 32 from the template header.
11
The old #if line was
12
#if DEPTH == 16 && defined(HOST_WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN)
13
and this was mistakenly changed to
14
#if defined(HOST_WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN)
15
rather than deleting the #if as now having an always-false condition.
16
17
Fixes: ea644cf343129
18
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
19
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
20
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
21
Message-id: 20210215103215.4944-7-peter.maydell@linaro.org
22
---
23
hw/display/omap_lcd_template.h | 4 ----
24
1 file changed, 4 deletions(-)
25
26
diff --git a/hw/display/omap_lcd_template.h b/hw/display/omap_lcd_template.h
27
index XXXXXXX..XXXXXXX 100644
28
--- a/hw/display/omap_lcd_template.h
29
+++ b/hw/display/omap_lcd_template.h
30
@@ -XXX,XX +XXX,XX @@ static void draw_line12_32(void *opaque, uint8_t *d, const uint8_t *s,
31
static void draw_line16_32(void *opaque, uint8_t *d, const uint8_t *s,
32
int width, int deststep)
33
{
34
-#if defined(HOST_WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN)
35
- memcpy(d, s, width * 2);
36
-#else
37
uint16_t v;
38
uint8_t r, g, b;
39
40
@@ -XXX,XX +XXX,XX @@ static void draw_line16_32(void *opaque, uint8_t *d, const uint8_t *s,
41
s += 2;
42
d += 4;
43
} while (-- width != 0);
44
-#endif
45
}
46
--
47
2.20.1
48
49
diff view generated by jsdifflib
New patch
1
Fix some minor coding style issues in the template header,
2
so checkpatch doesn't complain when we move the code.
1
3
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Message-id: 20210215103215.4944-8-peter.maydell@linaro.org
8
---
9
hw/display/omap_lcd_template.h | 6 +++---
10
1 file changed, 3 insertions(+), 3 deletions(-)
11
12
diff --git a/hw/display/omap_lcd_template.h b/hw/display/omap_lcd_template.h
13
index XXXXXXX..XXXXXXX 100644
14
--- a/hw/display/omap_lcd_template.h
15
+++ b/hw/display/omap_lcd_template.h
16
@@ -XXX,XX +XXX,XX @@ static void draw_line2_32(void *opaque, uint8_t *d, const uint8_t *s,
17
b = (pal[v & 3] << 4) & 0xf0;
18
((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
19
d += 4;
20
- s ++;
21
+ s++;
22
width -= 4;
23
} while (width > 0);
24
}
25
@@ -XXX,XX +XXX,XX @@ static void draw_line4_32(void *opaque, uint8_t *d, const uint8_t *s,
26
b = (pal[v & 0xf] << 4) & 0xf0;
27
((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
28
d += 4;
29
- s ++;
30
+ s++;
31
width -= 2;
32
} while (width > 0);
33
}
34
@@ -XXX,XX +XXX,XX @@ static void draw_line8_32(void *opaque, uint8_t *d, const uint8_t *s,
35
g = pal[v] & 0xf0;
36
b = (pal[v] << 4) & 0xf0;
37
((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
38
- s ++;
39
+ s++;
40
d += 4;
41
} while (-- width != 0);
42
}
43
--
44
2.20.1
45
46
diff view generated by jsdifflib
New patch
1
We only include the template header once, so just inline it into the
2
source file for the device.
1
3
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Message-id: 20210215103215.4944-9-peter.maydell@linaro.org
8
---
9
hw/display/omap_lcd_template.h | 154 ---------------------------------
10
hw/display/omap_lcdc.c | 127 ++++++++++++++++++++++++++-
11
2 files changed, 125 insertions(+), 156 deletions(-)
12
delete mode 100644 hw/display/omap_lcd_template.h
13
14
diff --git a/hw/display/omap_lcd_template.h b/hw/display/omap_lcd_template.h
15
deleted file mode 100644
16
index XXXXXXX..XXXXXXX
17
--- a/hw/display/omap_lcd_template.h
18
+++ /dev/null
19
@@ -XXX,XX +XXX,XX @@
20
-/*
21
- * QEMU OMAP LCD Emulator templates
22
- *
23
- * Copyright (c) 2006 Andrzej Zaborowski <balrog@zabor.org>
24
- *
25
- * Redistribution and use in source and binary forms, with or without
26
- * modification, are permitted provided that the following conditions
27
- * are met:
28
- *
29
- * 1. Redistributions of source code must retain the above copyright
30
- * notice, this list of conditions and the following disclaimer.
31
- * 2. Redistributions in binary form must reproduce the above copyright
32
- * notice, this list of conditions and the following disclaimer in
33
- * the documentation and/or other materials provided with the
34
- * distribution.
35
- *
36
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
37
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
38
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
39
- * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
40
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
41
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
42
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
43
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
44
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
45
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
46
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47
- */
48
-
49
-/*
50
- * 2-bit colour
51
- */
52
-static void draw_line2_32(void *opaque, uint8_t *d, const uint8_t *s,
53
- int width, int deststep)
54
-{
55
- uint16_t *pal = opaque;
56
- uint8_t v, r, g, b;
57
-
58
- do {
59
- v = ldub_p((void *) s);
60
- r = (pal[v & 3] >> 4) & 0xf0;
61
- g = pal[v & 3] & 0xf0;
62
- b = (pal[v & 3] << 4) & 0xf0;
63
- ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
64
- d += 4;
65
- v >>= 2;
66
- r = (pal[v & 3] >> 4) & 0xf0;
67
- g = pal[v & 3] & 0xf0;
68
- b = (pal[v & 3] << 4) & 0xf0;
69
- ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
70
- d += 4;
71
- v >>= 2;
72
- r = (pal[v & 3] >> 4) & 0xf0;
73
- g = pal[v & 3] & 0xf0;
74
- b = (pal[v & 3] << 4) & 0xf0;
75
- ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
76
- d += 4;
77
- v >>= 2;
78
- r = (pal[v & 3] >> 4) & 0xf0;
79
- g = pal[v & 3] & 0xf0;
80
- b = (pal[v & 3] << 4) & 0xf0;
81
- ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
82
- d += 4;
83
- s++;
84
- width -= 4;
85
- } while (width > 0);
86
-}
87
-
88
-/*
89
- * 4-bit colour
90
- */
91
-static void draw_line4_32(void *opaque, uint8_t *d, const uint8_t *s,
92
- int width, int deststep)
93
-{
94
- uint16_t *pal = opaque;
95
- uint8_t v, r, g, b;
96
-
97
- do {
98
- v = ldub_p((void *) s);
99
- r = (pal[v & 0xf] >> 4) & 0xf0;
100
- g = pal[v & 0xf] & 0xf0;
101
- b = (pal[v & 0xf] << 4) & 0xf0;
102
- ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
103
- d += 4;
104
- v >>= 4;
105
- r = (pal[v & 0xf] >> 4) & 0xf0;
106
- g = pal[v & 0xf] & 0xf0;
107
- b = (pal[v & 0xf] << 4) & 0xf0;
108
- ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
109
- d += 4;
110
- s++;
111
- width -= 2;
112
- } while (width > 0);
113
-}
114
-
115
-/*
116
- * 8-bit colour
117
- */
118
-static void draw_line8_32(void *opaque, uint8_t *d, const uint8_t *s,
119
- int width, int deststep)
120
-{
121
- uint16_t *pal = opaque;
122
- uint8_t v, r, g, b;
123
-
124
- do {
125
- v = ldub_p((void *) s);
126
- r = (pal[v] >> 4) & 0xf0;
127
- g = pal[v] & 0xf0;
128
- b = (pal[v] << 4) & 0xf0;
129
- ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
130
- s++;
131
- d += 4;
132
- } while (-- width != 0);
133
-}
134
-
135
-/*
136
- * 12-bit colour
137
- */
138
-static void draw_line12_32(void *opaque, uint8_t *d, const uint8_t *s,
139
- int width, int deststep)
140
-{
141
- uint16_t v;
142
- uint8_t r, g, b;
143
-
144
- do {
145
- v = lduw_le_p((void *) s);
146
- r = (v >> 4) & 0xf0;
147
- g = v & 0xf0;
148
- b = (v << 4) & 0xf0;
149
- ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
150
- s += 2;
151
- d += 4;
152
- } while (-- width != 0);
153
-}
154
-
155
-/*
156
- * 16-bit colour
157
- */
158
-static void draw_line16_32(void *opaque, uint8_t *d, const uint8_t *s,
159
- int width, int deststep)
160
-{
161
- uint16_t v;
162
- uint8_t r, g, b;
163
-
164
- do {
165
- v = lduw_le_p((void *) s);
166
- r = (v >> 8) & 0xf8;
167
- g = (v >> 3) & 0xfc;
168
- b = (v << 3) & 0xf8;
169
- ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
170
- s += 2;
171
- d += 4;
172
- } while (-- width != 0);
173
-}
174
diff --git a/hw/display/omap_lcdc.c b/hw/display/omap_lcdc.c
175
index XXXXXXX..XXXXXXX 100644
176
--- a/hw/display/omap_lcdc.c
177
+++ b/hw/display/omap_lcdc.c
178
@@ -XXX,XX +XXX,XX @@ static void omap_lcd_interrupts(struct omap_lcd_panel_s *s)
179
180
#define draw_line_func drawfn
181
182
-#define DEPTH 32
183
-#include "omap_lcd_template.h"
184
+/*
185
+ * 2-bit colour
186
+ */
187
+static void draw_line2_32(void *opaque, uint8_t *d, const uint8_t *s,
188
+ int width, int deststep)
189
+{
190
+ uint16_t *pal = opaque;
191
+ uint8_t v, r, g, b;
192
+
193
+ do {
194
+ v = ldub_p((void *) s);
195
+ r = (pal[v & 3] >> 4) & 0xf0;
196
+ g = pal[v & 3] & 0xf0;
197
+ b = (pal[v & 3] << 4) & 0xf0;
198
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
199
+ d += 4;
200
+ v >>= 2;
201
+ r = (pal[v & 3] >> 4) & 0xf0;
202
+ g = pal[v & 3] & 0xf0;
203
+ b = (pal[v & 3] << 4) & 0xf0;
204
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
205
+ d += 4;
206
+ v >>= 2;
207
+ r = (pal[v & 3] >> 4) & 0xf0;
208
+ g = pal[v & 3] & 0xf0;
209
+ b = (pal[v & 3] << 4) & 0xf0;
210
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
211
+ d += 4;
212
+ v >>= 2;
213
+ r = (pal[v & 3] >> 4) & 0xf0;
214
+ g = pal[v & 3] & 0xf0;
215
+ b = (pal[v & 3] << 4) & 0xf0;
216
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
217
+ d += 4;
218
+ s++;
219
+ width -= 4;
220
+ } while (width > 0);
221
+}
222
+
223
+/*
224
+ * 4-bit colour
225
+ */
226
+static void draw_line4_32(void *opaque, uint8_t *d, const uint8_t *s,
227
+ int width, int deststep)
228
+{
229
+ uint16_t *pal = opaque;
230
+ uint8_t v, r, g, b;
231
+
232
+ do {
233
+ v = ldub_p((void *) s);
234
+ r = (pal[v & 0xf] >> 4) & 0xf0;
235
+ g = pal[v & 0xf] & 0xf0;
236
+ b = (pal[v & 0xf] << 4) & 0xf0;
237
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
238
+ d += 4;
239
+ v >>= 4;
240
+ r = (pal[v & 0xf] >> 4) & 0xf0;
241
+ g = pal[v & 0xf] & 0xf0;
242
+ b = (pal[v & 0xf] << 4) & 0xf0;
243
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
244
+ d += 4;
245
+ s++;
246
+ width -= 2;
247
+ } while (width > 0);
248
+}
249
+
250
+/*
251
+ * 8-bit colour
252
+ */
253
+static void draw_line8_32(void *opaque, uint8_t *d, const uint8_t *s,
254
+ int width, int deststep)
255
+{
256
+ uint16_t *pal = opaque;
257
+ uint8_t v, r, g, b;
258
+
259
+ do {
260
+ v = ldub_p((void *) s);
261
+ r = (pal[v] >> 4) & 0xf0;
262
+ g = pal[v] & 0xf0;
263
+ b = (pal[v] << 4) & 0xf0;
264
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
265
+ s++;
266
+ d += 4;
267
+ } while (-- width != 0);
268
+}
269
+
270
+/*
271
+ * 12-bit colour
272
+ */
273
+static void draw_line12_32(void *opaque, uint8_t *d, const uint8_t *s,
274
+ int width, int deststep)
275
+{
276
+ uint16_t v;
277
+ uint8_t r, g, b;
278
+
279
+ do {
280
+ v = lduw_le_p((void *) s);
281
+ r = (v >> 4) & 0xf0;
282
+ g = v & 0xf0;
283
+ b = (v << 4) & 0xf0;
284
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
285
+ s += 2;
286
+ d += 4;
287
+ } while (-- width != 0);
288
+}
289
+
290
+/*
291
+ * 16-bit colour
292
+ */
293
+static void draw_line16_32(void *opaque, uint8_t *d, const uint8_t *s,
294
+ int width, int deststep)
295
+{
296
+ uint16_t v;
297
+ uint8_t r, g, b;
298
+
299
+ do {
300
+ v = lduw_le_p((void *) s);
301
+ r = (v >> 8) & 0xf8;
302
+ g = (v >> 3) & 0xfc;
303
+ b = (v << 3) & 0xf8;
304
+ ((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
305
+ s += 2;
306
+ d += 4;
307
+ } while (-- width != 0);
308
+}
309
310
static void omap_update_display(void *opaque)
311
{
312
--
313
2.20.1
314
315
diff view generated by jsdifflib
New patch
1
The macro draw_line_func is used only once; just expand it.
1
2
3
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Message-id: 20210215103215.4944-10-peter.maydell@linaro.org
7
---
8
hw/display/omap_lcdc.c | 4 +---
9
1 file changed, 1 insertion(+), 3 deletions(-)
10
11
diff --git a/hw/display/omap_lcdc.c b/hw/display/omap_lcdc.c
12
index XXXXXXX..XXXXXXX 100644
13
--- a/hw/display/omap_lcdc.c
14
+++ b/hw/display/omap_lcdc.c
15
@@ -XXX,XX +XXX,XX @@ static void omap_lcd_interrupts(struct omap_lcd_panel_s *s)
16
qemu_irq_lower(s->irq);
17
}
18
19
-#define draw_line_func drawfn
20
-
21
/*
22
* 2-bit colour
23
*/
24
@@ -XXX,XX +XXX,XX @@ static void omap_update_display(void *opaque)
25
{
26
struct omap_lcd_panel_s *omap_lcd = (struct omap_lcd_panel_s *) opaque;
27
DisplaySurface *surface;
28
- draw_line_func draw_line;
29
+ drawfn draw_line;
30
int size, height, first, last;
31
int width, linesize, step, bpp, frame_offset;
32
hwaddr frame_base;
33
--
34
2.20.1
35
36
diff view generated by jsdifflib
New patch
1
For a long time now the UI layer has guaranteed that the console
2
surface is always 32 bits per pixel, RGB. The TCX code already
3
assumes 32bpp, but it still has some checks of is_surface_bgr()
4
in an attempt to support 32bpp BGR. is_surface_bgr() will always
5
return false for the qemu_console_surface(), unless the display
6
device itself has deliberately created an alternate-format
7
surface via a function like qemu_create_displaysurface_from().
1
8
9
Drop the never-used BGR-handling code, and assert that we have
10
a 32-bit surface rather than just doing nothing if it isn't.
11
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
14
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
15
Message-id: 20210215102149.20513-1-peter.maydell@linaro.org
16
---
17
hw/display/tcx.c | 31 ++++++++-----------------------
18
1 file changed, 8 insertions(+), 23 deletions(-)
19
20
diff --git a/hw/display/tcx.c b/hw/display/tcx.c
21
index XXXXXXX..XXXXXXX 100644
22
--- a/hw/display/tcx.c
23
+++ b/hw/display/tcx.c
24
@@ -XXX,XX +XXX,XX @@ static int tcx_check_dirty(TCXState *s, DirtyBitmapSnapshot *snap,
25
26
static void update_palette_entries(TCXState *s, int start, int end)
27
{
28
- DisplaySurface *surface = qemu_console_surface(s->con);
29
int i;
30
31
for (i = start; i < end; i++) {
32
- if (is_surface_bgr(surface)) {
33
- s->palette[i] = rgb_to_pixel32bgr(s->r[i], s->g[i], s->b[i]);
34
- } else {
35
- s->palette[i] = rgb_to_pixel32(s->r[i], s->g[i], s->b[i]);
36
- }
37
+ s->palette[i] = rgb_to_pixel32(s->r[i], s->g[i], s->b[i]);
38
}
39
tcx_set_dirty(s, 0, memory_region_size(&s->vram_mem));
40
}
41
@@ -XXX,XX +XXX,XX @@ static void tcx_draw_cursor32(TCXState *s1, uint8_t *d,
42
}
43
44
/*
45
- XXX Could be much more optimal:
46
- * detect if line/page/whole screen is in 24 bit mode
47
- * if destination is also BGR, use memcpy
48
- */
49
+ * XXX Could be much more optimal:
50
+ * detect if line/page/whole screen is in 24 bit mode
51
+ */
52
static inline void tcx24_draw_line32(TCXState *s1, uint8_t *d,
53
const uint8_t *s, int width,
54
const uint32_t *cplane,
55
const uint32_t *s24)
56
{
57
- DisplaySurface *surface = qemu_console_surface(s1->con);
58
- int x, bgr, r, g, b;
59
+ int x, r, g, b;
60
uint8_t val, *p8;
61
uint32_t *p = (uint32_t *)d;
62
uint32_t dval;
63
- bgr = is_surface_bgr(surface);
64
for(x = 0; x < width; x++, s++, s24++) {
65
if (be32_to_cpu(*cplane) & 0x03000000) {
66
/* 24-bit direct, BGR order */
67
@@ -XXX,XX +XXX,XX @@ static inline void tcx24_draw_line32(TCXState *s1, uint8_t *d,
68
b = *p8++;
69
g = *p8++;
70
r = *p8;
71
- if (bgr)
72
- dval = rgb_to_pixel32bgr(r, g, b);
73
- else
74
- dval = rgb_to_pixel32(r, g, b);
75
+ dval = rgb_to_pixel32(r, g, b);
76
} else {
77
/* 8-bit pseudocolor */
78
val = *s;
79
@@ -XXX,XX +XXX,XX @@ static void tcx_update_display(void *opaque)
80
int y, y_start, dd, ds;
81
uint8_t *d, *s;
82
83
- if (surface_bits_per_pixel(surface) != 32) {
84
- return;
85
- }
86
+ assert(surface_bits_per_pixel(surface) == 32);
87
88
page = 0;
89
y_start = -1;
90
@@ -XXX,XX +XXX,XX @@ static void tcx24_update_display(void *opaque)
91
uint8_t *d, *s;
92
uint32_t *cptr, *s24;
93
94
- if (surface_bits_per_pixel(surface) != 32) {
95
- return;
96
- }
97
+ assert(surface_bits_per_pixel(surface) == 32);
98
99
page = 0;
100
y_start = -1;
101
--
102
2.20.1
103
104
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
The AN524 has a different SYSCLK frequency from the AN505 and AN521;
2
make the SYSCLK frequency a field in the MPS2TZMachineClass rather
3
than a compile-time constant so we can support the AN524.
2
4
3
Include the U bit in the switches rather than testing separately.
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20210215115138.20465-2-peter.maydell@linaro.org
9
---
10
hw/arm/mps2-tz.c | 10 ++++++----
11
1 file changed, 6 insertions(+), 4 deletions(-)
4
12
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
13
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
7
Message-id: 20180228193125.20577-3-richard.henderson@linaro.org
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
10
target/arm/translate-a64.c | 129 +++++++++++++++++++++------------------------
11
1 file changed, 61 insertions(+), 68 deletions(-)
12
13
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
14
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
15
--- a/target/arm/translate-a64.c
15
--- a/hw/arm/mps2-tz.c
16
+++ b/target/arm/translate-a64.c
16
+++ b/hw/arm/mps2-tz.c
17
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
17
@@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineClass {
18
int index;
18
MachineClass parent;
19
TCGv_ptr fpst;
19
MPS2TZFPGAType fpga_type;
20
20
uint32_t scc_id;
21
- switch (opcode) {
21
+ uint32_t sysclk_frq; /* Main SYSCLK frequency in Hz */
22
- case 0x0: /* MLA */
22
const char *armsse_type;
23
- case 0x4: /* MLS */
23
};
24
- if (!u || is_scalar) {
24
25
+ switch (16 * u + opcode) {
25
@@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineState {
26
+ case 0x08: /* MUL */
26
27
+ case 0x10: /* MLA */
27
OBJECT_DECLARE_TYPE(MPS2TZMachineState, MPS2TZMachineClass, MPS2TZ_MACHINE)
28
+ case 0x14: /* MLS */
28
29
+ if (is_scalar) {
29
-/* Main SYSCLK frequency in Hz */
30
unallocated_encoding(s);
30
-#define SYSCLK_FRQ 20000000
31
return;
31
/* Slow 32Khz S32KCLK frequency in Hz */
32
}
32
#define S32KCLK_FRQ (32 * 1000)
33
break;
33
34
- case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
34
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_unimp_dev(MPS2TZMachineState *mms,
35
- case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
35
static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
36
- case 0xa: /* SMULL, SMULL2, UMULL, UMULL2 */
36
const char *name, hwaddr size)
37
+ case 0x02: /* SMLAL, SMLAL2 */
37
{
38
+ case 0x12: /* UMLAL, UMLAL2 */
38
+ MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
39
+ case 0x06: /* SMLSL, SMLSL2 */
39
CMSDKAPBUART *uart = opaque;
40
+ case 0x16: /* UMLSL, UMLSL2 */
40
int i = uart - &mms->uart[0];
41
+ case 0x0a: /* SMULL, SMULL2 */
41
int rxirqno = i * 2;
42
+ case 0x1a: /* UMULL, UMULL2 */
42
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
43
if (is_scalar) {
43
44
unallocated_encoding(s);
44
object_initialize_child(OBJECT(mms), name, uart, TYPE_CMSDK_APB_UART);
45
return;
45
qdev_prop_set_chr(DEVICE(uart), "chardev", serial_hd(i));
46
}
46
- qdev_prop_set_uint32(DEVICE(uart), "pclk-frq", SYSCLK_FRQ);
47
is_long = true;
47
+ qdev_prop_set_uint32(DEVICE(uart), "pclk-frq", mmc->sysclk_frq);
48
break;
48
sysbus_realize(SYS_BUS_DEVICE(uart), &error_fatal);
49
- case 0x3: /* SQDMLAL, SQDMLAL2 */
49
s = SYS_BUS_DEVICE(uart);
50
- case 0x7: /* SQDMLSL, SQDMLSL2 */
50
sysbus_connect_irq(s, 0, get_sse_irq_in(mms, txirqno));
51
- case 0xb: /* SQDMULL, SQDMULL2 */
51
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
52
+ case 0x03: /* SQDMLAL, SQDMLAL2 */
52
53
+ case 0x07: /* SQDMLSL, SQDMLSL2 */
53
/* These clocks don't need migration because they are fixed-frequency */
54
+ case 0x0b: /* SQDMULL, SQDMULL2 */
54
mms->sysclk = clock_new(OBJECT(machine), "SYSCLK");
55
is_long = true;
55
- clock_set_hz(mms->sysclk, SYSCLK_FRQ);
56
- /* fall through */
56
+ clock_set_hz(mms->sysclk, mmc->sysclk_frq);
57
- case 0xc: /* SQDMULH */
57
mms->s32kclk = clock_new(OBJECT(machine), "S32KCLK");
58
- case 0xd: /* SQRDMULH */
58
clock_set_hz(mms->s32kclk, S32KCLK_FRQ);
59
- if (u) {
59
60
- unallocated_encoding(s);
60
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an505_class_init(ObjectClass *oc, void *data)
61
- return;
61
mmc->fpga_type = FPGA_AN505;
62
- }
62
mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m33");
63
break;
63
mmc->scc_id = 0x41045050;
64
- case 0x8: /* MUL */
64
+ mmc->sysclk_frq = 20 * 1000 * 1000; /* 20MHz */
65
- if (u || is_scalar) {
65
mmc->armsse_type = TYPE_IOTKIT;
66
- unallocated_encoding(s);
66
}
67
- return;
67
68
- }
68
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an521_class_init(ObjectClass *oc, void *data)
69
+ case 0x0c: /* SQDMULH */
69
mmc->fpga_type = FPGA_AN521;
70
+ case 0x0d: /* SQRDMULH */
70
mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m33");
71
break;
71
mmc->scc_id = 0x41045210;
72
- case 0x1: /* FMLA */
72
+ mmc->sysclk_frq = 20 * 1000 * 1000; /* 20MHz */
73
- case 0x5: /* FMLS */
73
mmc->armsse_type = TYPE_SSE200;
74
- if (u) {
74
}
75
- unallocated_encoding(s);
75
76
- return;
77
- }
78
- /* fall through */
79
- case 0x9: /* FMUL, FMULX */
80
+ case 0x01: /* FMLA */
81
+ case 0x05: /* FMLS */
82
+ case 0x09: /* FMUL */
83
+ case 0x19: /* FMULX */
84
if (size == 1) {
85
unallocated_encoding(s);
86
return;
87
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
88
89
read_vec_element(s, tcg_op, rn, pass, MO_64);
90
91
- switch (opcode) {
92
- case 0x5: /* FMLS */
93
+ switch (16 * u + opcode) {
94
+ case 0x05: /* FMLS */
95
/* As usual for ARM, separate negation for fused multiply-add */
96
gen_helper_vfp_negd(tcg_op, tcg_op);
97
/* fall through */
98
- case 0x1: /* FMLA */
99
+ case 0x01: /* FMLA */
100
read_vec_element(s, tcg_res, rd, pass, MO_64);
101
gen_helper_vfp_muladdd(tcg_res, tcg_op, tcg_idx, tcg_res, fpst);
102
break;
103
- case 0x9: /* FMUL, FMULX */
104
- if (u) {
105
- gen_helper_vfp_mulxd(tcg_res, tcg_op, tcg_idx, fpst);
106
- } else {
107
- gen_helper_vfp_muld(tcg_res, tcg_op, tcg_idx, fpst);
108
- }
109
+ case 0x09: /* FMUL */
110
+ gen_helper_vfp_muld(tcg_res, tcg_op, tcg_idx, fpst);
111
+ break;
112
+ case 0x19: /* FMULX */
113
+ gen_helper_vfp_mulxd(tcg_res, tcg_op, tcg_idx, fpst);
114
break;
115
default:
116
g_assert_not_reached();
117
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
118
119
read_vec_element_i32(s, tcg_op, rn, pass, is_scalar ? size : MO_32);
120
121
- switch (opcode) {
122
- case 0x0: /* MLA */
123
- case 0x4: /* MLS */
124
- case 0x8: /* MUL */
125
+ switch (16 * u + opcode) {
126
+ case 0x08: /* MUL */
127
+ case 0x10: /* MLA */
128
+ case 0x14: /* MLS */
129
{
130
static NeonGenTwoOpFn * const fns[2][2] = {
131
{ gen_helper_neon_add_u16, gen_helper_neon_sub_u16 },
132
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
133
genfn(tcg_res, tcg_op, tcg_res);
134
break;
135
}
136
- case 0x5: /* FMLS */
137
- case 0x1: /* FMLA */
138
+ case 0x05: /* FMLS */
139
+ case 0x01: /* FMLA */
140
read_vec_element_i32(s, tcg_res, rd, pass,
141
is_scalar ? size : MO_32);
142
switch (size) {
143
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
144
g_assert_not_reached();
145
}
146
break;
147
- case 0x9: /* FMUL, FMULX */
148
+ case 0x09: /* FMUL */
149
switch (size) {
150
case 1:
151
- if (u) {
152
- if (is_scalar) {
153
- gen_helper_advsimd_mulxh(tcg_res, tcg_op,
154
- tcg_idx, fpst);
155
- } else {
156
- gen_helper_advsimd_mulx2h(tcg_res, tcg_op,
157
- tcg_idx, fpst);
158
- }
159
+ if (is_scalar) {
160
+ gen_helper_advsimd_mulh(tcg_res, tcg_op,
161
+ tcg_idx, fpst);
162
} else {
163
- if (is_scalar) {
164
- gen_helper_advsimd_mulh(tcg_res, tcg_op,
165
- tcg_idx, fpst);
166
- } else {
167
- gen_helper_advsimd_mul2h(tcg_res, tcg_op,
168
- tcg_idx, fpst);
169
- }
170
+ gen_helper_advsimd_mul2h(tcg_res, tcg_op,
171
+ tcg_idx, fpst);
172
}
173
break;
174
case 2:
175
- if (u) {
176
- gen_helper_vfp_mulxs(tcg_res, tcg_op, tcg_idx, fpst);
177
- } else {
178
- gen_helper_vfp_muls(tcg_res, tcg_op, tcg_idx, fpst);
179
- }
180
+ gen_helper_vfp_muls(tcg_res, tcg_op, tcg_idx, fpst);
181
break;
182
default:
183
g_assert_not_reached();
184
}
185
break;
186
- case 0xc: /* SQDMULH */
187
+ case 0x19: /* FMULX */
188
+ switch (size) {
189
+ case 1:
190
+ if (is_scalar) {
191
+ gen_helper_advsimd_mulxh(tcg_res, tcg_op,
192
+ tcg_idx, fpst);
193
+ } else {
194
+ gen_helper_advsimd_mulx2h(tcg_res, tcg_op,
195
+ tcg_idx, fpst);
196
+ }
197
+ break;
198
+ case 2:
199
+ gen_helper_vfp_mulxs(tcg_res, tcg_op, tcg_idx, fpst);
200
+ break;
201
+ default:
202
+ g_assert_not_reached();
203
+ }
204
+ break;
205
+ case 0x0c: /* SQDMULH */
206
if (size == 1) {
207
gen_helper_neon_qdmulh_s16(tcg_res, cpu_env,
208
tcg_op, tcg_idx);
209
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
210
tcg_op, tcg_idx);
211
}
212
break;
213
- case 0xd: /* SQRDMULH */
214
+ case 0x0d: /* SQRDMULH */
215
if (size == 1) {
216
gen_helper_neon_qrdmulh_s16(tcg_res, cpu_env,
217
tcg_op, tcg_idx);
218
--
76
--
219
2.16.2
77
2.20.1
220
78
221
79
diff view generated by jsdifflib
1
Create an "idau" property on the armv7m container object which
1
Currently the MPS2 SCC device implements a fixed number of OSCCLK
2
we can forward to the CPU object. Annoyingly, we can't use
2
values (3). The variant of this device in the MPS3 AN524 board has 6
3
object_property_add_alias() because the CPU object we want to
3
OSCCLK values. Switch to using a PROP_ARRAY, which allows board code
4
forward to doesn't exist until the armv7m container is realized.
4
to specify how large the OSCCLK array should be as well as its
5
values.
6
7
With a variable-length property array, the SCC no longer specifies
8
default values for the OSCCLKs, so we must set them explicitly in the
9
board code. This defaults are actually incorrect for the an521 and
10
an505; we will correct this bug in a following patch.
11
12
This is a migration compatibility break for all the mps boards.
5
13
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
16
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20180220180325.29818-6-peter.maydell@linaro.org
17
Message-id: 20210215115138.20465-3-peter.maydell@linaro.org
9
---
18
---
10
include/hw/arm/armv7m.h | 3 +++
19
include/hw/misc/mps2-scc.h | 7 +++----
11
hw/arm/armv7m.c | 9 +++++++++
20
hw/arm/mps2-tz.c | 5 +++++
12
2 files changed, 12 insertions(+)
21
hw/arm/mps2.c | 5 +++++
22
hw/misc/mps2-scc.c | 24 +++++++++++++-----------
23
4 files changed, 26 insertions(+), 15 deletions(-)
13
24
14
diff --git a/include/hw/arm/armv7m.h b/include/hw/arm/armv7m.h
25
diff --git a/include/hw/misc/mps2-scc.h b/include/hw/misc/mps2-scc.h
15
index XXXXXXX..XXXXXXX 100644
26
index XXXXXXX..XXXXXXX 100644
16
--- a/include/hw/arm/armv7m.h
27
--- a/include/hw/misc/mps2-scc.h
17
+++ b/include/hw/arm/armv7m.h
28
+++ b/include/hw/misc/mps2-scc.h
18
@@ -XXX,XX +XXX,XX @@
29
@@ -XXX,XX +XXX,XX @@
19
30
#define TYPE_MPS2_SCC "mps2-scc"
20
#include "hw/sysbus.h"
31
OBJECT_DECLARE_SIMPLE_TYPE(MPS2SCC, MPS2_SCC)
21
#include "hw/intc/armv7m_nvic.h"
32
22
+#include "target/arm/idau.h"
33
-#define NUM_OSCCLK 3
23
34
-
24
#define TYPE_BITBAND "ARM,bitband-memory"
35
struct MPS2SCC {
25
#define BITBAND(obj) OBJECT_CHECK(BitBandState, (obj), TYPE_BITBAND)
26
@@ -XXX,XX +XXX,XX @@ typedef struct {
27
* + Property "memory": MemoryRegion defining the physical address space
28
* that CPU accesses see. (The NVIC, bitbanding and other CPU-internal
29
* devices will be automatically layered on top of this view.)
30
+ * + Property "idau": IDAU interface (forwarded to CPU object)
31
*/
32
typedef struct ARMv7MState {
33
/*< private >*/
36
/*< private >*/
34
@@ -XXX,XX +XXX,XX @@ typedef struct ARMv7MState {
37
SysBusDevice parent_obj;
35
char *cpu_type;
38
@@ -XXX,XX +XXX,XX @@ struct MPS2SCC {
36
/* MemoryRegion the board provides to us (with its devices, RAM, etc) */
39
uint32_t dll;
37
MemoryRegion *board_memory;
40
uint32_t aid;
38
+ Object *idau;
41
uint32_t id;
39
} ARMv7MState;
42
- uint32_t oscclk[NUM_OSCCLK];
43
- uint32_t oscclk_reset[NUM_OSCCLK];
44
+ uint32_t num_oscclk;
45
+ uint32_t *oscclk;
46
+ uint32_t *oscclk_reset;
47
};
40
48
41
#endif
49
#endif
42
diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c
50
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
43
index XXXXXXX..XXXXXXX 100644
51
index XXXXXXX..XXXXXXX 100644
44
--- a/hw/arm/armv7m.c
52
--- a/hw/arm/mps2-tz.c
45
+++ b/hw/arm/armv7m.c
53
+++ b/hw/arm/mps2-tz.c
46
@@ -XXX,XX +XXX,XX @@
54
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_scc(MPS2TZMachineState *mms, void *opaque,
47
#include "sysemu/qtest.h"
55
qdev_prop_set_uint32(sccdev, "scc-cfg4", 0x2);
48
#include "qemu/error-report.h"
56
qdev_prop_set_uint32(sccdev, "scc-aid", 0x00200008);
49
#include "exec/address-spaces.h"
57
qdev_prop_set_uint32(sccdev, "scc-id", mmc->scc_id);
50
+#include "target/arm/idau.h"
58
+ /* This will need to be per-FPGA image eventually */
51
59
+ qdev_prop_set_uint32(sccdev, "len-oscclk", 3);
52
/* Bitbanded IO. Each word corresponds to a single bit. */
60
+ qdev_prop_set_uint32(sccdev, "oscclk[0]", 50000000);
53
61
+ qdev_prop_set_uint32(sccdev, "oscclk[1]", 24576000);
54
@@ -XXX,XX +XXX,XX @@ static void armv7m_realize(DeviceState *dev, Error **errp)
62
+ qdev_prop_set_uint32(sccdev, "oscclk[2]", 25000000);
55
63
sysbus_realize(SYS_BUS_DEVICE(scc), &error_fatal);
56
object_property_set_link(OBJECT(s->cpu), OBJECT(&s->container), "memory",
64
return sysbus_mmio_get_region(SYS_BUS_DEVICE(sccdev), 0);
57
&error_abort);
65
}
58
+ if (object_property_find(OBJECT(s->cpu), "idau", NULL)) {
66
diff --git a/hw/arm/mps2.c b/hw/arm/mps2.c
59
+ object_property_set_link(OBJECT(s->cpu), s->idau, "idau", &err);
67
index XXXXXXX..XXXXXXX 100644
60
+ if (err != NULL) {
68
--- a/hw/arm/mps2.c
61
+ error_propagate(errp, err);
69
+++ b/hw/arm/mps2.c
62
+ return;
70
@@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine)
63
+ }
71
qdev_prop_set_uint32(sccdev, "scc-cfg4", 0x2);
64
+ }
72
qdev_prop_set_uint32(sccdev, "scc-aid", 0x00200008);
65
object_property_set_bool(OBJECT(s->cpu), true, "realized", &err);
73
qdev_prop_set_uint32(sccdev, "scc-id", mmc->scc_id);
66
if (err != NULL) {
74
+ /* All these FPGA images have the same OSCCLK configuration */
67
error_propagate(errp, err);
75
+ qdev_prop_set_uint32(sccdev, "len-oscclk", 3);
68
@@ -XXX,XX +XXX,XX @@ static Property armv7m_properties[] = {
76
+ qdev_prop_set_uint32(sccdev, "oscclk[0]", 50000000);
69
DEFINE_PROP_STRING("cpu-type", ARMv7MState, cpu_type),
77
+ qdev_prop_set_uint32(sccdev, "oscclk[1]", 24576000);
70
DEFINE_PROP_LINK("memory", ARMv7MState, board_memory, TYPE_MEMORY_REGION,
78
+ qdev_prop_set_uint32(sccdev, "oscclk[2]", 25000000);
71
MemoryRegion *),
79
sysbus_realize(SYS_BUS_DEVICE(&mms->scc), &error_fatal);
72
+ DEFINE_PROP_LINK("idau", ARMv7MState, idau, TYPE_IDAU_INTERFACE, Object *),
80
sysbus_mmio_map(SYS_BUS_DEVICE(sccdev), 0, 0x4002f000);
81
object_initialize_child(OBJECT(mms), "fpgaio",
82
diff --git a/hw/misc/mps2-scc.c b/hw/misc/mps2-scc.c
83
index XXXXXXX..XXXXXXX 100644
84
--- a/hw/misc/mps2-scc.c
85
+++ b/hw/misc/mps2-scc.c
86
@@ -XXX,XX +XXX,XX @@ static bool scc_cfg_write(MPS2SCC *s, unsigned function,
87
{
88
trace_mps2_scc_cfg_write(function, device, value);
89
90
- if (function != 1 || device >= NUM_OSCCLK) {
91
+ if (function != 1 || device >= s->num_oscclk) {
92
qemu_log_mask(LOG_GUEST_ERROR,
93
"MPS2 SCC config write: bad function %d device %d\n",
94
function, device);
95
@@ -XXX,XX +XXX,XX @@ static bool scc_cfg_write(MPS2SCC *s, unsigned function,
96
static bool scc_cfg_read(MPS2SCC *s, unsigned function,
97
unsigned device, uint32_t *value)
98
{
99
- if (function != 1 || device >= NUM_OSCCLK) {
100
+ if (function != 1 || device >= s->num_oscclk) {
101
qemu_log_mask(LOG_GUEST_ERROR,
102
"MPS2 SCC config read: bad function %d device %d\n",
103
function, device);
104
@@ -XXX,XX +XXX,XX @@ static void mps2_scc_reset(DeviceState *dev)
105
s->cfgctrl = 0x100000;
106
s->cfgstat = 0;
107
s->dll = 0xffff0001;
108
- for (i = 0; i < NUM_OSCCLK; i++) {
109
+ for (i = 0; i < s->num_oscclk; i++) {
110
s->oscclk[i] = s->oscclk_reset[i];
111
}
112
for (i = 0; i < ARRAY_SIZE(s->led); i++) {
113
@@ -XXX,XX +XXX,XX @@ static void mps2_scc_realize(DeviceState *dev, Error **errp)
114
LED_COLOR_GREEN, name);
115
g_free(name);
116
}
117
+
118
+ s->oscclk = g_new0(uint32_t, s->num_oscclk);
119
}
120
121
static const VMStateDescription mps2_scc_vmstate = {
122
.name = "mps2-scc",
123
- .version_id = 1,
124
- .minimum_version_id = 1,
125
+ .version_id = 2,
126
+ .minimum_version_id = 2,
127
.fields = (VMStateField[]) {
128
VMSTATE_UINT32(cfg0, MPS2SCC),
129
VMSTATE_UINT32(cfg1, MPS2SCC),
130
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription mps2_scc_vmstate = {
131
VMSTATE_UINT32(cfgctrl, MPS2SCC),
132
VMSTATE_UINT32(cfgstat, MPS2SCC),
133
VMSTATE_UINT32(dll, MPS2SCC),
134
- VMSTATE_UINT32_ARRAY(oscclk, MPS2SCC, NUM_OSCCLK),
135
+ VMSTATE_VARRAY_UINT32(oscclk, MPS2SCC, num_oscclk,
136
+ 0, vmstate_info_uint32, uint32_t),
137
VMSTATE_END_OF_LIST()
138
}
139
};
140
@@ -XXX,XX +XXX,XX @@ static Property mps2_scc_properties[] = {
141
DEFINE_PROP_UINT32("scc-cfg4", MPS2SCC, cfg4, 0),
142
DEFINE_PROP_UINT32("scc-aid", MPS2SCC, aid, 0),
143
DEFINE_PROP_UINT32("scc-id", MPS2SCC, id, 0),
144
- /* These are the initial settings for the source clocks on the board.
145
+ /*
146
+ * These are the initial settings for the source clocks on the board.
147
* In hardware they can be configured via a config file read by the
148
* motherboard configuration controller to suit the FPGA image.
149
- * These default values are used by most of the standard FPGA images.
150
*/
151
- DEFINE_PROP_UINT32("oscclk0", MPS2SCC, oscclk_reset[0], 50000000),
152
- DEFINE_PROP_UINT32("oscclk1", MPS2SCC, oscclk_reset[1], 24576000),
153
- DEFINE_PROP_UINT32("oscclk2", MPS2SCC, oscclk_reset[2], 25000000),
154
+ DEFINE_PROP_ARRAY("oscclk", MPS2SCC, num_oscclk, oscclk_reset,
155
+ qdev_prop_uint32, uint32_t),
73
DEFINE_PROP_END_OF_LIST(),
156
DEFINE_PROP_END_OF_LIST(),
74
};
157
};
75
158
76
--
159
--
77
2.16.2
160
2.20.1
78
161
79
162
diff view generated by jsdifflib
New patch
1
We were previously using the default OSCCLK settings, which are
2
correct for the older MPS2 boards (mps2-an385, mps2-an386,
3
mps2-an500, mps2-an511), but wrong for the mps2-an505 and mps2-511
4
implemented in mps2-tz.c. Now we're setting the values explicitly we
5
can fix them to be correct.
1
6
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
Message-id: 20210215115138.20465-4-peter.maydell@linaro.org
11
---
12
hw/arm/mps2-tz.c | 4 ++--
13
1 file changed, 2 insertions(+), 2 deletions(-)
14
15
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/hw/arm/mps2-tz.c
18
+++ b/hw/arm/mps2-tz.c
19
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_scc(MPS2TZMachineState *mms, void *opaque,
20
qdev_prop_set_uint32(sccdev, "scc-id", mmc->scc_id);
21
/* This will need to be per-FPGA image eventually */
22
qdev_prop_set_uint32(sccdev, "len-oscclk", 3);
23
- qdev_prop_set_uint32(sccdev, "oscclk[0]", 50000000);
24
- qdev_prop_set_uint32(sccdev, "oscclk[1]", 24576000);
25
+ qdev_prop_set_uint32(sccdev, "oscclk[0]", 40000000);
26
+ qdev_prop_set_uint32(sccdev, "oscclk[1]", 24580000);
27
qdev_prop_set_uint32(sccdev, "oscclk[2]", 25000000);
28
sysbus_realize(SYS_BUS_DEVICE(scc), &error_fatal);
29
return sysbus_mmio_get_region(SYS_BUS_DEVICE(sccdev), 0);
30
--
31
2.20.1
32
33
diff view generated by jsdifflib
1
The or-irq.h header file is missing the customary guard against
1
The AN505 and AN511 happen to share the same OSCCLK values, but the
2
multiple inclusion, which means compilation fails if it gets
2
AN524 will have a different set (and more of them), so split the
3
included twice. Fix the omission.
3
settings out to be per-board.
4
4
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20180220180325.29818-11-peter.maydell@linaro.org
8
Message-id: 20210215115138.20465-5-peter.maydell@linaro.org
9
---
9
---
10
include/hw/or-irq.h | 5 +++++
10
hw/arm/mps2-tz.c | 23 ++++++++++++++++++-----
11
1 file changed, 5 insertions(+)
11
1 file changed, 18 insertions(+), 5 deletions(-)
12
12
13
diff --git a/include/hw/or-irq.h b/include/hw/or-irq.h
13
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
14
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
15
--- a/include/hw/or-irq.h
15
--- a/hw/arm/mps2-tz.c
16
+++ b/include/hw/or-irq.h
16
+++ b/hw/arm/mps2-tz.c
17
@@ -XXX,XX +XXX,XX @@
17
@@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineClass {
18
* THE SOFTWARE.
18
MPS2TZFPGAType fpga_type;
19
uint32_t scc_id;
20
uint32_t sysclk_frq; /* Main SYSCLK frequency in Hz */
21
+ uint32_t len_oscclk;
22
+ const uint32_t *oscclk;
23
const char *armsse_type;
24
};
25
26
@@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_TYPE(MPS2TZMachineState, MPS2TZMachineClass, MPS2TZ_MACHINE)
27
/* Slow 32Khz S32KCLK frequency in Hz */
28
#define S32KCLK_FRQ (32 * 1000)
29
30
+static const uint32_t an505_oscclk[] = {
31
+ 40000000,
32
+ 24580000,
33
+ 25000000,
34
+};
35
+
36
/* Create an alias of an entire original MemoryRegion @orig
37
* located at @base in the memory map.
19
*/
38
*/
20
39
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_scc(MPS2TZMachineState *mms, void *opaque,
21
+#ifndef HW_OR_IRQ_H
40
MPS2SCC *scc = opaque;
22
+#define HW_OR_IRQ_H
41
DeviceState *sccdev;
23
+
42
MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
24
#include "hw/irq.h"
43
+ uint32_t i;
25
#include "hw/sysbus.h"
44
26
#include "qom/object.h"
45
object_initialize_child(OBJECT(mms), "scc", scc, TYPE_MPS2_SCC);
27
@@ -XXX,XX +XXX,XX @@ struct OrIRQState {
46
sccdev = DEVICE(scc);
28
bool levels[MAX_OR_LINES];
47
qdev_prop_set_uint32(sccdev, "scc-cfg4", 0x2);
29
uint16_t num_lines;
48
qdev_prop_set_uint32(sccdev, "scc-aid", 0x00200008);
30
};
49
qdev_prop_set_uint32(sccdev, "scc-id", mmc->scc_id);
31
+
50
- /* This will need to be per-FPGA image eventually */
32
+#endif
51
- qdev_prop_set_uint32(sccdev, "len-oscclk", 3);
52
- qdev_prop_set_uint32(sccdev, "oscclk[0]", 40000000);
53
- qdev_prop_set_uint32(sccdev, "oscclk[1]", 24580000);
54
- qdev_prop_set_uint32(sccdev, "oscclk[2]", 25000000);
55
+ qdev_prop_set_uint32(sccdev, "len-oscclk", mmc->len_oscclk);
56
+ for (i = 0; i < mmc->len_oscclk; i++) {
57
+ g_autofree char *propname = g_strdup_printf("oscclk[%u]", i);
58
+ qdev_prop_set_uint32(sccdev, propname, mmc->oscclk[i]);
59
+ }
60
sysbus_realize(SYS_BUS_DEVICE(scc), &error_fatal);
61
return sysbus_mmio_get_region(SYS_BUS_DEVICE(sccdev), 0);
62
}
63
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an505_class_init(ObjectClass *oc, void *data)
64
mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m33");
65
mmc->scc_id = 0x41045050;
66
mmc->sysclk_frq = 20 * 1000 * 1000; /* 20MHz */
67
+ mmc->oscclk = an505_oscclk;
68
+ mmc->len_oscclk = ARRAY_SIZE(an505_oscclk);
69
mmc->armsse_type = TYPE_IOTKIT;
70
}
71
72
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an521_class_init(ObjectClass *oc, void *data)
73
mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m33");
74
mmc->scc_id = 0x41045210;
75
mmc->sysclk_frq = 20 * 1000 * 1000; /* 20MHz */
76
+ mmc->oscclk = an505_oscclk; /* AN521 is the same as AN505 here */
77
+ mmc->len_oscclk = ARRAY_SIZE(an505_oscclk);
78
mmc->armsse_type = TYPE_SSE200;
79
}
80
33
--
81
--
34
2.16.2
82
2.20.1
35
83
36
84
diff view generated by jsdifflib
1
The IoTKit Security Controller includes various registers
1
The MPS2 board has 2 LEDs, but the MPS3 board has 10 LEDs. The
2
that expose to software the controls for the Peripheral
2
FPGAIO device is similar on both sets of boards, but the LED0
3
Protection Controllers in the system. Implement these.
3
register has correspondingly more bits that have an effect. Add a
4
device property for number of LEDs.
4
5
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20180220180325.29818-17-peter.maydell@linaro.org
9
Message-id: 20210215115138.20465-6-peter.maydell@linaro.org
8
---
10
---
9
include/hw/misc/iotkit-secctl.h | 64 +++++++++-
11
include/hw/misc/mps2-fpgaio.h | 5 ++++-
10
hw/misc/iotkit-secctl.c | 270 +++++++++++++++++++++++++++++++++++++---
12
hw/misc/mps2-fpgaio.c | 31 +++++++++++++++++++++++--------
11
2 files changed, 315 insertions(+), 19 deletions(-)
13
2 files changed, 27 insertions(+), 9 deletions(-)
12
14
13
diff --git a/include/hw/misc/iotkit-secctl.h b/include/hw/misc/iotkit-secctl.h
15
diff --git a/include/hw/misc/mps2-fpgaio.h b/include/hw/misc/mps2-fpgaio.h
14
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
15
--- a/include/hw/misc/iotkit-secctl.h
17
--- a/include/hw/misc/mps2-fpgaio.h
16
+++ b/include/hw/misc/iotkit-secctl.h
18
+++ b/include/hw/misc/mps2-fpgaio.h
17
@@ -XXX,XX +XXX,XX @@
19
@@ -XXX,XX +XXX,XX @@
18
* QEMU interface:
20
#define TYPE_MPS2_FPGAIO "mps2-fpgaio"
19
* + sysbus MMIO region 0 is the "secure privilege control block" registers
21
OBJECT_DECLARE_SIMPLE_TYPE(MPS2FPGAIO, MPS2_FPGAIO)
20
* + sysbus MMIO region 1 is the "non-secure privilege control block" registers
22
21
+ * + named GPIO output "sec_resp_cfg" indicating whether blocked accesses
23
+#define MPS2FPGAIO_MAX_LEDS 32
22
+ * should RAZ/WI or bus error
23
+ * Controlling the 2 APB PPCs in the IoTKit:
24
+ * + named GPIO outputs apb_ppc0_nonsec[0..2] and apb_ppc1_nonsec
25
+ * + named GPIO outputs apb_ppc0_ap[0..2] and apb_ppc1_ap
26
+ * + named GPIO outputs apb_ppc{0,1}_irq_enable
27
+ * + named GPIO outputs apb_ppc{0,1}_irq_clear
28
+ * + named GPIO inputs apb_ppc{0,1}_irq_status
29
+ * Controlling each of the 4 expansion APB PPCs which a system using the IoTKit
30
+ * might provide:
31
+ * + named GPIO outputs apb_ppcexp{0,1,2,3}_nonsec[0..15]
32
+ * + named GPIO outputs apb_ppcexp{0,1,2,3}_ap[0..15]
33
+ * + named GPIO outputs apb_ppcexp{0,1,2,3}_irq_enable
34
+ * + named GPIO outputs apb_ppcexp{0,1,2,3}_irq_clear
35
+ * + named GPIO inputs apb_ppcexp{0,1,2,3}_irq_status
36
+ * Controlling each of the 4 expansion AHB PPCs which a system using the IoTKit
37
+ * might provide:
38
+ * + named GPIO outputs ahb_ppcexp{0,1,2,3}_nonsec[0..15]
39
+ * + named GPIO outputs ahb_ppcexp{0,1,2,3}_ap[0..15]
40
+ * + named GPIO outputs ahb_ppcexp{0,1,2,3}_irq_enable
41
+ * + named GPIO outputs ahb_ppcexp{0,1,2,3}_irq_clear
42
+ * + named GPIO inputs ahb_ppcexp{0,1,2,3}_irq_status
43
*/
44
45
#ifndef IOTKIT_SECCTL_H
46
@@ -XXX,XX +XXX,XX @@
47
#define TYPE_IOTKIT_SECCTL "iotkit-secctl"
48
#define IOTKIT_SECCTL(obj) OBJECT_CHECK(IoTKitSecCtl, (obj), TYPE_IOTKIT_SECCTL)
49
50
-typedef struct IoTKitSecCtl {
51
+#define IOTS_APB_PPC0_NUM_PORTS 3
52
+#define IOTS_APB_PPC1_NUM_PORTS 1
53
+#define IOTS_PPC_NUM_PORTS 16
54
+#define IOTS_NUM_APB_PPC 2
55
+#define IOTS_NUM_APB_EXP_PPC 4
56
+#define IOTS_NUM_AHB_EXP_PPC 4
57
+
24
+
58
+typedef struct IoTKitSecCtl IoTKitSecCtl;
25
struct MPS2FPGAIO {
59
+
60
+/* State and IRQ lines relating to a PPC. For the
61
+ * PPCs in the IoTKit not all the IRQ lines are used.
62
+ */
63
+typedef struct IoTKitSecCtlPPC {
64
+ qemu_irq nonsec[IOTS_PPC_NUM_PORTS];
65
+ qemu_irq ap[IOTS_PPC_NUM_PORTS];
66
+ qemu_irq irq_enable;
67
+ qemu_irq irq_clear;
68
+
69
+ uint32_t ns;
70
+ uint32_t sp;
71
+ uint32_t nsp;
72
+
73
+ /* Number of ports actually present */
74
+ int numports;
75
+ /* Offset of this PPC's interrupt bits in SECPPCINTSTAT */
76
+ int irq_bit_offset;
77
+ IoTKitSecCtl *parent;
78
+} IoTKitSecCtlPPC;
79
+
80
+struct IoTKitSecCtl {
81
/*< private >*/
26
/*< private >*/
82
SysBusDevice parent_obj;
27
SysBusDevice parent_obj;
83
28
84
/*< public >*/
29
/*< public >*/
85
+ qemu_irq sec_resp_cfg;
30
MemoryRegion iomem;
86
31
- LEDState *led[2];
87
MemoryRegion s_regs;
32
+ LEDState *led[MPS2FPGAIO_MAX_LEDS];
88
MemoryRegion ns_regs;
33
+ uint32_t num_leds;
89
-} IoTKitSecCtl;
34
35
uint32_t led0;
36
uint32_t prescale;
37
diff --git a/hw/misc/mps2-fpgaio.c b/hw/misc/mps2-fpgaio.c
38
index XXXXXXX..XXXXXXX 100644
39
--- a/hw/misc/mps2-fpgaio.c
40
+++ b/hw/misc/mps2-fpgaio.c
41
@@ -XXX,XX +XXX,XX @@ static void mps2_fpgaio_write(void *opaque, hwaddr offset, uint64_t value,
42
43
switch (offset) {
44
case A_LED0:
45
- s->led0 = value & 0x3;
46
- led_set_state(s->led[0], value & 0x01);
47
- led_set_state(s->led[1], value & 0x02);
48
+ if (s->num_leds != 0) {
49
+ uint32_t i;
90
+
50
+
91
+ uint32_t secppcintstat;
51
+ s->led0 = value & MAKE_64BIT_MASK(0, s->num_leds);
92
+ uint32_t secppcinten;
52
+ for (i = 0; i < s->num_leds; i++) {
93
+ uint32_t secrespcfg;
53
+ led_set_state(s->led[i], value & (1 << i));
94
+
54
+ }
95
+ IoTKitSecCtlPPC apb[IOTS_NUM_APB_PPC];
55
+ }
96
+ IoTKitSecCtlPPC apbexp[IOTS_NUM_APB_EXP_PPC];
56
break;
97
+ IoTKitSecCtlPPC ahbexp[IOTS_NUM_APB_EXP_PPC];
57
case A_PRESCALE:
98
+};
58
resync_counter(s);
99
59
@@ -XXX,XX +XXX,XX @@ static void mps2_fpgaio_reset(DeviceState *dev)
100
#endif
60
s->pscntr = 0;
101
diff --git a/hw/misc/iotkit-secctl.c b/hw/misc/iotkit-secctl.c
61
s->pscntr_sync_ticks = now;
102
index XXXXXXX..XXXXXXX 100644
62
103
--- a/hw/misc/iotkit-secctl.c
63
- for (size_t i = 0; i < ARRAY_SIZE(s->led); i++) {
104
+++ b/hw/misc/iotkit-secctl.c
64
+ for (size_t i = 0; i < s->num_leds; i++) {
105
@@ -XXX,XX +XXX,XX @@ static const uint8_t iotkit_secctl_ns_idregs[] = {
65
device_cold_reset(DEVICE(s->led[i]));
106
0x0d, 0xf0, 0x05, 0xb1,
66
}
107
};
67
}
108
68
@@ -XXX,XX +XXX,XX @@ static void mps2_fpgaio_init(Object *obj)
109
+/* The register sets for the various PPCs (AHB internal, APB internal,
69
static void mps2_fpgaio_realize(DeviceState *dev, Error **errp)
110
+ * AHB expansion, APB expansion) are all set up so that they are
111
+ * in 16-aligned blocks so offsets 0xN0, 0xN4, 0xN8, 0xNC are PPCs
112
+ * 0, 1, 2, 3 of that type, so we can convert a register address offset
113
+ * into an an index into a PPC array easily.
114
+ */
115
+static inline int offset_to_ppc_idx(uint32_t offset)
116
+{
117
+ return extract32(offset, 2, 2);
118
+}
119
+
120
+typedef void PerPPCFunction(IoTKitSecCtlPPC *ppc);
121
+
122
+static void foreach_ppc(IoTKitSecCtl *s, PerPPCFunction *fn)
123
+{
124
+ int i;
125
+
126
+ for (i = 0; i < IOTS_NUM_APB_PPC; i++) {
127
+ fn(&s->apb[i]);
128
+ }
129
+ for (i = 0; i < IOTS_NUM_APB_EXP_PPC; i++) {
130
+ fn(&s->apbexp[i]);
131
+ }
132
+ for (i = 0; i < IOTS_NUM_AHB_EXP_PPC; i++) {
133
+ fn(&s->ahbexp[i]);
134
+ }
135
+}
136
+
137
static MemTxResult iotkit_secctl_s_read(void *opaque, hwaddr addr,
138
uint64_t *pdata,
139
unsigned size, MemTxAttrs attrs)
140
{
70
{
141
uint64_t r;
71
MPS2FPGAIO *s = MPS2_FPGAIO(dev);
142
uint32_t offset = addr & ~0x3;
72
+ uint32_t i;
143
+ IoTKitSecCtl *s = IOTKIT_SECCTL(opaque);
73
144
74
- s->led[0] = led_create_simple(OBJECT(dev), GPIO_POLARITY_ACTIVE_HIGH,
145
switch (offset) {
75
- LED_COLOR_GREEN, "USERLED0");
146
case A_AHBNSPPC0:
76
- s->led[1] = led_create_simple(OBJECT(dev), GPIO_POLARITY_ACTIVE_HIGH,
147
@@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_s_read(void *opaque, hwaddr addr,
77
- LED_COLOR_GREEN, "USERLED1");
148
r = 0;
78
+ if (s->num_leds > MPS2FPGAIO_MAX_LEDS) {
149
break;
79
+ error_setg(errp, "num-leds cannot be greater than %d",
150
case A_SECRESPCFG:
80
+ MPS2FPGAIO_MAX_LEDS);
151
- case A_NSCCFG:
81
+ return;
152
- case A_SECMPCINTSTATUS:
153
+ r = s->secrespcfg;
154
+ break;
155
case A_SECPPCINTSTAT:
156
+ r = s->secppcintstat;
157
+ break;
158
case A_SECPPCINTEN:
159
- case A_SECMSCINTSTAT:
160
- case A_SECMSCINTEN:
161
- case A_BRGINTSTAT:
162
- case A_BRGINTEN:
163
+ r = s->secppcinten;
164
+ break;
165
case A_AHBNSPPCEXP0:
166
case A_AHBNSPPCEXP1:
167
case A_AHBNSPPCEXP2:
168
case A_AHBNSPPCEXP3:
169
+ r = s->ahbexp[offset_to_ppc_idx(offset)].ns;
170
+ break;
171
case A_APBNSPPC0:
172
case A_APBNSPPC1:
173
+ r = s->apb[offset_to_ppc_idx(offset)].ns;
174
+ break;
175
case A_APBNSPPCEXP0:
176
case A_APBNSPPCEXP1:
177
case A_APBNSPPCEXP2:
178
case A_APBNSPPCEXP3:
179
+ r = s->apbexp[offset_to_ppc_idx(offset)].ns;
180
+ break;
181
case A_AHBSPPPCEXP0:
182
case A_AHBSPPPCEXP1:
183
case A_AHBSPPPCEXP2:
184
case A_AHBSPPPCEXP3:
185
+ r = s->apbexp[offset_to_ppc_idx(offset)].sp;
186
+ break;
187
case A_APBSPPPC0:
188
case A_APBSPPPC1:
189
+ r = s->apb[offset_to_ppc_idx(offset)].sp;
190
+ break;
191
case A_APBSPPPCEXP0:
192
case A_APBSPPPCEXP1:
193
case A_APBSPPPCEXP2:
194
case A_APBSPPPCEXP3:
195
+ r = s->apbexp[offset_to_ppc_idx(offset)].sp;
196
+ break;
197
+ case A_NSCCFG:
198
+ case A_SECMPCINTSTATUS:
199
+ case A_SECMSCINTSTAT:
200
+ case A_SECMSCINTEN:
201
+ case A_BRGINTSTAT:
202
+ case A_BRGINTEN:
203
case A_NSMSCEXP:
204
qemu_log_mask(LOG_UNIMP,
205
"IoTKit SecCtl S block read: "
206
@@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_s_read(void *opaque, hwaddr addr,
207
return MEMTX_OK;
208
}
209
210
+static void iotkit_secctl_update_ppc_ap(IoTKitSecCtlPPC *ppc)
211
+{
212
+ int i;
213
+
214
+ for (i = 0; i < ppc->numports; i++) {
215
+ bool v;
216
+
217
+ if (extract32(ppc->ns, i, 1)) {
218
+ v = extract32(ppc->nsp, i, 1);
219
+ } else {
220
+ v = extract32(ppc->sp, i, 1);
221
+ }
222
+ qemu_set_irq(ppc->ap[i], v);
223
+ }
224
+}
225
+
226
+static void iotkit_secctl_ppc_ns_write(IoTKitSecCtlPPC *ppc, uint32_t value)
227
+{
228
+ int i;
229
+
230
+ ppc->ns = value & MAKE_64BIT_MASK(0, ppc->numports);
231
+ for (i = 0; i < ppc->numports; i++) {
232
+ qemu_set_irq(ppc->nonsec[i], extract32(ppc->ns, i, 1));
233
+ }
234
+ iotkit_secctl_update_ppc_ap(ppc);
235
+}
236
+
237
+static void iotkit_secctl_ppc_sp_write(IoTKitSecCtlPPC *ppc, uint32_t value)
238
+{
239
+ ppc->sp = value & MAKE_64BIT_MASK(0, ppc->numports);
240
+ iotkit_secctl_update_ppc_ap(ppc);
241
+}
242
+
243
+static void iotkit_secctl_ppc_nsp_write(IoTKitSecCtlPPC *ppc, uint32_t value)
244
+{
245
+ ppc->nsp = value & MAKE_64BIT_MASK(0, ppc->numports);
246
+ iotkit_secctl_update_ppc_ap(ppc);
247
+}
248
+
249
+static void iotkit_secctl_ppc_update_irq_clear(IoTKitSecCtlPPC *ppc)
250
+{
251
+ uint32_t value = ppc->parent->secppcintstat;
252
+
253
+ qemu_set_irq(ppc->irq_clear, extract32(value, ppc->irq_bit_offset, 1));
254
+}
255
+
256
+static void iotkit_secctl_ppc_update_irq_enable(IoTKitSecCtlPPC *ppc)
257
+{
258
+ uint32_t value = ppc->parent->secppcinten;
259
+
260
+ qemu_set_irq(ppc->irq_enable, extract32(value, ppc->irq_bit_offset, 1));
261
+}
262
+
263
static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr,
264
uint64_t value,
265
unsigned size, MemTxAttrs attrs)
266
{
267
+ IoTKitSecCtl *s = IOTKIT_SECCTL(opaque);
268
uint32_t offset = addr;
269
+ IoTKitSecCtlPPC *ppc;
270
271
trace_iotkit_secctl_s_write(offset, value, size);
272
273
@@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr,
274
275
switch (offset) {
276
case A_SECRESPCFG:
277
- case A_NSCCFG:
278
+ value &= 1;
279
+ s->secrespcfg = value;
280
+ qemu_set_irq(s->sec_resp_cfg, s->secrespcfg);
281
+ break;
282
case A_SECPPCINTCLR:
283
+ value &= 0x00f000f3;
284
+ foreach_ppc(s, iotkit_secctl_ppc_update_irq_clear);
285
+ break;
286
case A_SECPPCINTEN:
287
- case A_SECMSCINTCLR:
288
- case A_SECMSCINTEN:
289
- case A_BRGINTCLR:
290
- case A_BRGINTEN:
291
+ s->secppcinten = value & 0x00f000f3;
292
+ foreach_ppc(s, iotkit_secctl_ppc_update_irq_enable);
293
+ break;
294
case A_AHBNSPPCEXP0:
295
case A_AHBNSPPCEXP1:
296
case A_AHBNSPPCEXP2:
297
case A_AHBNSPPCEXP3:
298
+ ppc = &s->ahbexp[offset_to_ppc_idx(offset)];
299
+ iotkit_secctl_ppc_ns_write(ppc, value);
300
+ break;
301
case A_APBNSPPC0:
302
case A_APBNSPPC1:
303
+ ppc = &s->apb[offset_to_ppc_idx(offset)];
304
+ iotkit_secctl_ppc_ns_write(ppc, value);
305
+ break;
306
case A_APBNSPPCEXP0:
307
case A_APBNSPPCEXP1:
308
case A_APBNSPPCEXP2:
309
case A_APBNSPPCEXP3:
310
+ ppc = &s->apbexp[offset_to_ppc_idx(offset)];
311
+ iotkit_secctl_ppc_ns_write(ppc, value);
312
+ break;
313
case A_AHBSPPPCEXP0:
314
case A_AHBSPPPCEXP1:
315
case A_AHBSPPPCEXP2:
316
case A_AHBSPPPCEXP3:
317
+ ppc = &s->ahbexp[offset_to_ppc_idx(offset)];
318
+ iotkit_secctl_ppc_sp_write(ppc, value);
319
+ break;
320
case A_APBSPPPC0:
321
case A_APBSPPPC1:
322
+ ppc = &s->apb[offset_to_ppc_idx(offset)];
323
+ iotkit_secctl_ppc_sp_write(ppc, value);
324
+ break;
325
case A_APBSPPPCEXP0:
326
case A_APBSPPPCEXP1:
327
case A_APBSPPPCEXP2:
328
case A_APBSPPPCEXP3:
329
+ ppc = &s->apbexp[offset_to_ppc_idx(offset)];
330
+ iotkit_secctl_ppc_sp_write(ppc, value);
331
+ break;
332
+ case A_NSCCFG:
333
+ case A_SECMSCINTCLR:
334
+ case A_SECMSCINTEN:
335
+ case A_BRGINTCLR:
336
+ case A_BRGINTEN:
337
qemu_log_mask(LOG_UNIMP,
338
"IoTKit SecCtl S block write: "
339
"unimplemented offset 0x%x\n", offset);
340
@@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_ns_read(void *opaque, hwaddr addr,
341
uint64_t *pdata,
342
unsigned size, MemTxAttrs attrs)
343
{
344
+ IoTKitSecCtl *s = IOTKIT_SECCTL(opaque);
345
uint64_t r;
346
uint32_t offset = addr & ~0x3;
347
348
@@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_ns_read(void *opaque, hwaddr addr,
349
case A_AHBNSPPPCEXP1:
350
case A_AHBNSPPPCEXP2:
351
case A_AHBNSPPPCEXP3:
352
+ r = s->ahbexp[offset_to_ppc_idx(offset)].nsp;
353
+ break;
354
case A_APBNSPPPC0:
355
case A_APBNSPPPC1:
356
+ r = s->apb[offset_to_ppc_idx(offset)].nsp;
357
+ break;
358
case A_APBNSPPPCEXP0:
359
case A_APBNSPPPCEXP1:
360
case A_APBNSPPPCEXP2:
361
case A_APBNSPPPCEXP3:
362
- qemu_log_mask(LOG_UNIMP,
363
- "IoTKit SecCtl NS block read: "
364
- "unimplemented offset 0x%x\n", offset);
365
+ r = s->apbexp[offset_to_ppc_idx(offset)].nsp;
366
break;
367
case A_PID4:
368
case A_PID5:
369
@@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_ns_write(void *opaque, hwaddr addr,
370
uint64_t value,
371
unsigned size, MemTxAttrs attrs)
372
{
373
+ IoTKitSecCtl *s = IOTKIT_SECCTL(opaque);
374
uint32_t offset = addr;
375
+ IoTKitSecCtlPPC *ppc;
376
377
trace_iotkit_secctl_ns_write(offset, value, size);
378
379
@@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_ns_write(void *opaque, hwaddr addr,
380
case A_AHBNSPPPCEXP1:
381
case A_AHBNSPPPCEXP2:
382
case A_AHBNSPPPCEXP3:
383
+ ppc = &s->ahbexp[offset_to_ppc_idx(offset)];
384
+ iotkit_secctl_ppc_nsp_write(ppc, value);
385
+ break;
386
case A_APBNSPPPC0:
387
case A_APBNSPPPC1:
388
+ ppc = &s->apb[offset_to_ppc_idx(offset)];
389
+ iotkit_secctl_ppc_nsp_write(ppc, value);
390
+ break;
391
case A_APBNSPPPCEXP0:
392
case A_APBNSPPPCEXP1:
393
case A_APBNSPPPCEXP2:
394
case A_APBNSPPPCEXP3:
395
- qemu_log_mask(LOG_UNIMP,
396
- "IoTKit SecCtl NS block write: "
397
- "unimplemented offset 0x%x\n", offset);
398
+ ppc = &s->apbexp[offset_to_ppc_idx(offset)];
399
+ iotkit_secctl_ppc_nsp_write(ppc, value);
400
break;
401
case A_AHBNSPPPC0:
402
case A_PID4:
403
@@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps iotkit_secctl_ns_ops = {
404
.impl.max_access_size = 4,
405
};
406
407
+static void iotkit_secctl_reset_ppc(IoTKitSecCtlPPC *ppc)
408
+{
409
+ ppc->ns = 0;
410
+ ppc->sp = 0;
411
+ ppc->nsp = 0;
412
+}
413
+
414
static void iotkit_secctl_reset(DeviceState *dev)
415
{
416
+ IoTKitSecCtl *s = IOTKIT_SECCTL(dev);
417
418
+ s->secppcintstat = 0;
419
+ s->secppcinten = 0;
420
+ s->secrespcfg = 0;
421
+
422
+ foreach_ppc(s, iotkit_secctl_reset_ppc);
423
+}
424
+
425
+static void iotkit_secctl_ppc_irqstatus(void *opaque, int n, int level)
426
+{
427
+ IoTKitSecCtlPPC *ppc = opaque;
428
+ IoTKitSecCtl *s = IOTKIT_SECCTL(ppc->parent);
429
+ int irqbit = ppc->irq_bit_offset + n;
430
+
431
+ s->secppcintstat = deposit32(s->secppcintstat, irqbit, 1, level);
432
+}
433
+
434
+static void iotkit_secctl_init_ppc(IoTKitSecCtl *s,
435
+ IoTKitSecCtlPPC *ppc,
436
+ const char *name,
437
+ int numports,
438
+ int irq_bit_offset)
439
+{
440
+ char *gpioname;
441
+ DeviceState *dev = DEVICE(s);
442
+
443
+ ppc->numports = numports;
444
+ ppc->irq_bit_offset = irq_bit_offset;
445
+ ppc->parent = s;
446
+
447
+ gpioname = g_strdup_printf("%s_nonsec", name);
448
+ qdev_init_gpio_out_named(dev, ppc->nonsec, gpioname, numports);
449
+ g_free(gpioname);
450
+ gpioname = g_strdup_printf("%s_ap", name);
451
+ qdev_init_gpio_out_named(dev, ppc->ap, gpioname, numports);
452
+ g_free(gpioname);
453
+ gpioname = g_strdup_printf("%s_irq_enable", name);
454
+ qdev_init_gpio_out_named(dev, &ppc->irq_enable, gpioname, 1);
455
+ g_free(gpioname);
456
+ gpioname = g_strdup_printf("%s_irq_clear", name);
457
+ qdev_init_gpio_out_named(dev, &ppc->irq_clear, gpioname, 1);
458
+ g_free(gpioname);
459
+ gpioname = g_strdup_printf("%s_irq_status", name);
460
+ qdev_init_gpio_in_named_with_opaque(dev, iotkit_secctl_ppc_irqstatus,
461
+ ppc, gpioname, 1);
462
+ g_free(gpioname);
463
}
464
465
static void iotkit_secctl_init(Object *obj)
466
{
467
IoTKitSecCtl *s = IOTKIT_SECCTL(obj);
468
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
469
+ DeviceState *dev = DEVICE(obj);
470
+ int i;
471
+
472
+ iotkit_secctl_init_ppc(s, &s->apb[0], "apb_ppc0",
473
+ IOTS_APB_PPC0_NUM_PORTS, 0);
474
+ iotkit_secctl_init_ppc(s, &s->apb[1], "apb_ppc1",
475
+ IOTS_APB_PPC1_NUM_PORTS, 1);
476
+
477
+ for (i = 0; i < IOTS_NUM_APB_EXP_PPC; i++) {
478
+ IoTKitSecCtlPPC *ppc = &s->apbexp[i];
479
+ char *ppcname = g_strdup_printf("apb_ppcexp%d", i);
480
+ iotkit_secctl_init_ppc(s, ppc, ppcname, IOTS_PPC_NUM_PORTS, 4 + i);
481
+ g_free(ppcname);
482
+ }
483
+ for (i = 0; i < IOTS_NUM_AHB_EXP_PPC; i++) {
484
+ IoTKitSecCtlPPC *ppc = &s->ahbexp[i];
485
+ char *ppcname = g_strdup_printf("ahb_ppcexp%d", i);
486
+ iotkit_secctl_init_ppc(s, ppc, ppcname, IOTS_PPC_NUM_PORTS, 20 + i);
487
+ g_free(ppcname);
488
+ }
82
+ }
489
+
83
+
490
+ qdev_init_gpio_out_named(dev, &s->sec_resp_cfg, "sec_resp_cfg", 1);
84
+ for (i = 0; i < s->num_leds; i++) {
491
85
+ g_autofree char *ledname = g_strdup_printf("USERLED%d", i);
492
memory_region_init_io(&s->s_regs, obj, &iotkit_secctl_s_ops,
86
+ s->led[i] = led_create_simple(OBJECT(dev), GPIO_POLARITY_ACTIVE_HIGH,
493
s, "iotkit-secctl-s-regs", 0x1000);
87
+ LED_COLOR_GREEN, ledname);
494
@@ -XXX,XX +XXX,XX @@ static void iotkit_secctl_init(Object *obj)
88
+ }
495
sysbus_init_mmio(sbd, &s->ns_regs);
496
}
89
}
497
90
498
+static const VMStateDescription iotkit_secctl_ppc_vmstate = {
91
static bool mps2_fpgaio_counters_needed(void *opaque)
499
+ .name = "iotkit-secctl-ppc",
92
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription mps2_fpgaio_vmstate = {
500
+ .version_id = 1,
93
static Property mps2_fpgaio_properties[] = {
501
+ .minimum_version_id = 1,
94
/* Frequency of the prescale counter */
502
+ .fields = (VMStateField[]) {
95
DEFINE_PROP_UINT32("prescale-clk", MPS2FPGAIO, prescale_clk, 20000000),
503
+ VMSTATE_UINT32(ns, IoTKitSecCtlPPC),
96
+ /* Number of LEDs controlled by LED0 register */
504
+ VMSTATE_UINT32(sp, IoTKitSecCtlPPC),
97
+ DEFINE_PROP_UINT32("num-leds", MPS2FPGAIO, num_leds, 2),
505
+ VMSTATE_UINT32(nsp, IoTKitSecCtlPPC),
98
DEFINE_PROP_END_OF_LIST(),
506
+ VMSTATE_END_OF_LIST()
507
+ }
508
+};
509
+
510
static const VMStateDescription iotkit_secctl_vmstate = {
511
.name = "iotkit-secctl",
512
.version_id = 1,
513
.minimum_version_id = 1,
514
.fields = (VMStateField[]) {
515
+ VMSTATE_UINT32(secppcintstat, IoTKitSecCtl),
516
+ VMSTATE_UINT32(secppcinten, IoTKitSecCtl),
517
+ VMSTATE_UINT32(secrespcfg, IoTKitSecCtl),
518
+ VMSTATE_STRUCT_ARRAY(apb, IoTKitSecCtl, IOTS_NUM_APB_PPC, 1,
519
+ iotkit_secctl_ppc_vmstate, IoTKitSecCtlPPC),
520
+ VMSTATE_STRUCT_ARRAY(apbexp, IoTKitSecCtl, IOTS_NUM_APB_EXP_PPC, 1,
521
+ iotkit_secctl_ppc_vmstate, IoTKitSecCtlPPC),
522
+ VMSTATE_STRUCT_ARRAY(ahbexp, IoTKitSecCtl, IOTS_NUM_AHB_EXP_PPC, 1,
523
+ iotkit_secctl_ppc_vmstate, IoTKitSecCtlPPC),
524
VMSTATE_END_OF_LIST()
525
}
526
};
99
};
100
527
--
101
--
528
2.16.2
102
2.20.1
529
103
530
104
diff view generated by jsdifflib
1
Create an "init-svtor" property on the armv7m container
1
MPS3 boards have an extra SWITCH register in the FPGAIO block which
2
object which we can forward to the CPU object.
2
reports the value of some switches. Implement this, governed by a
3
property the board code can use to specify whether whether it exists.
3
4
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
Message-id: 20180220180325.29818-8-peter.maydell@linaro.org
8
Message-id: 20210215115138.20465-7-peter.maydell@linaro.org
7
---
9
---
8
include/hw/arm/armv7m.h | 2 ++
10
include/hw/misc/mps2-fpgaio.h | 1 +
9
hw/arm/armv7m.c | 9 +++++++++
11
hw/misc/mps2-fpgaio.c | 10 ++++++++++
10
2 files changed, 11 insertions(+)
12
2 files changed, 11 insertions(+)
11
13
12
diff --git a/include/hw/arm/armv7m.h b/include/hw/arm/armv7m.h
14
diff --git a/include/hw/misc/mps2-fpgaio.h b/include/hw/misc/mps2-fpgaio.h
13
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
14
--- a/include/hw/arm/armv7m.h
16
--- a/include/hw/misc/mps2-fpgaio.h
15
+++ b/include/hw/arm/armv7m.h
17
+++ b/include/hw/misc/mps2-fpgaio.h
16
@@ -XXX,XX +XXX,XX @@ typedef struct {
18
@@ -XXX,XX +XXX,XX @@ struct MPS2FPGAIO {
17
* that CPU accesses see. (The NVIC, bitbanding and other CPU-internal
19
MemoryRegion iomem;
18
* devices will be automatically layered on top of this view.)
20
LEDState *led[MPS2FPGAIO_MAX_LEDS];
19
* + Property "idau": IDAU interface (forwarded to CPU object)
21
uint32_t num_leds;
20
+ * + Property "init-svtor": secure VTOR reset value (forwarded to CPU object)
22
+ bool has_switches;
21
*/
23
22
typedef struct ARMv7MState {
24
uint32_t led0;
23
/*< private >*/
25
uint32_t prescale;
24
@@ -XXX,XX +XXX,XX @@ typedef struct ARMv7MState {
26
diff --git a/hw/misc/mps2-fpgaio.c b/hw/misc/mps2-fpgaio.c
25
/* MemoryRegion the board provides to us (with its devices, RAM, etc) */
26
MemoryRegion *board_memory;
27
Object *idau;
28
+ uint32_t init_svtor;
29
} ARMv7MState;
30
31
#endif
32
diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c
33
index XXXXXXX..XXXXXXX 100644
27
index XXXXXXX..XXXXXXX 100644
34
--- a/hw/arm/armv7m.c
28
--- a/hw/misc/mps2-fpgaio.c
35
+++ b/hw/arm/armv7m.c
29
+++ b/hw/misc/mps2-fpgaio.c
36
@@ -XXX,XX +XXX,XX @@ static void armv7m_realize(DeviceState *dev, Error **errp)
30
@@ -XXX,XX +XXX,XX @@ REG32(CLK100HZ, 0x14)
37
return;
31
REG32(COUNTER, 0x18)
38
}
32
REG32(PRESCALE, 0x1c)
39
}
33
REG32(PSCNTR, 0x20)
40
+ if (object_property_find(OBJECT(s->cpu), "init-svtor", NULL)) {
34
+REG32(SWITCH, 0x28)
41
+ object_property_set_uint(OBJECT(s->cpu), s->init_svtor,
35
REG32(MISC, 0x4c)
42
+ "init-svtor", &err);
36
43
+ if (err != NULL) {
37
static uint32_t counter_from_tickoff(int64_t now, int64_t tick_offset, int frq)
44
+ error_propagate(errp, err);
38
@@ -XXX,XX +XXX,XX @@ static uint64_t mps2_fpgaio_read(void *opaque, hwaddr offset, unsigned size)
45
+ return;
39
resync_counter(s);
40
r = s->pscntr;
41
break;
42
+ case A_SWITCH:
43
+ if (!s->has_switches) {
44
+ goto bad_offset;
46
+ }
45
+ }
47
+ }
46
+ /* User-togglable board switches. We don't model that, so report 0. */
48
object_property_set_bool(OBJECT(s->cpu), true, "realized", &err);
47
+ r = 0;
49
if (err != NULL) {
48
+ break;
50
error_propagate(errp, err);
49
default:
51
@@ -XXX,XX +XXX,XX @@ static Property armv7m_properties[] = {
50
+ bad_offset:
52
DEFINE_PROP_LINK("memory", ARMv7MState, board_memory, TYPE_MEMORY_REGION,
51
qemu_log_mask(LOG_GUEST_ERROR,
53
MemoryRegion *),
52
"MPS2 FPGAIO read: bad offset %x\n", (int) offset);
54
DEFINE_PROP_LINK("idau", ARMv7MState, idau, TYPE_IDAU_INTERFACE, Object *),
53
r = 0;
55
+ DEFINE_PROP_UINT32("init-svtor", ARMv7MState, init_svtor, 0),
54
@@ -XXX,XX +XXX,XX @@ static Property mps2_fpgaio_properties[] = {
55
DEFINE_PROP_UINT32("prescale-clk", MPS2FPGAIO, prescale_clk, 20000000),
56
/* Number of LEDs controlled by LED0 register */
57
DEFINE_PROP_UINT32("num-leds", MPS2FPGAIO, num_leds, 2),
58
+ DEFINE_PROP_BOOL("has-switches", MPS2FPGAIO, has_switches, false),
56
DEFINE_PROP_END_OF_LIST(),
59
DEFINE_PROP_END_OF_LIST(),
57
};
60
};
58
61
59
--
62
--
60
2.16.2
63
2.20.1
61
64
62
65
diff view generated by jsdifflib
1
Instead of loading kernels, device trees, and the like to
1
Set the FPGAIO num-leds and have-switches properties explicitly
2
the system address space, use the CPU's address space. This
2
per-board, rather than relying on the defaults. The AN505 and AN521
3
is important if we're trying to load the file to memory or
3
both have the same settings as the default values, but the AN524 will
4
via an alias memory region that is provided by an SoC
4
be different.
5
object and thus not mapped into the system address space.
6
5
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
Message-id: 20180220180325.29818-3-peter.maydell@linaro.org
9
Message-id: 20210215115138.20465-8-peter.maydell@linaro.org
11
---
10
---
12
hw/arm/boot.c | 119 +++++++++++++++++++++++++++++++++++++---------------------
11
hw/arm/mps2-tz.c | 9 +++++++++
13
1 file changed, 76 insertions(+), 43 deletions(-)
12
1 file changed, 9 insertions(+)
14
13
15
diff --git a/hw/arm/boot.c b/hw/arm/boot.c
14
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
16
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
17
--- a/hw/arm/boot.c
16
--- a/hw/arm/mps2-tz.c
18
+++ b/hw/arm/boot.c
17
+++ b/hw/arm/mps2-tz.c
19
@@ -XXX,XX +XXX,XX @@
18
@@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineClass {
20
#define ARM64_TEXT_OFFSET_OFFSET 8
19
uint32_t sysclk_frq; /* Main SYSCLK frequency in Hz */
21
#define ARM64_MAGIC_OFFSET 56
20
uint32_t len_oscclk;
22
21
const uint32_t *oscclk;
23
+static AddressSpace *arm_boot_address_space(ARMCPU *cpu,
22
+ uint32_t fpgaio_num_leds; /* Number of LEDs in FPGAIO LED0 register */
24
+ const struct arm_boot_info *info)
23
+ bool fpgaio_has_switches; /* Does FPGAIO have SWITCH register? */
25
+{
24
const char *armsse_type;
26
+ /* Return the address space to use for bootloader reads and writes.
27
+ * We prefer the secure address space if the CPU has it and we're
28
+ * going to boot the guest into it.
29
+ */
30
+ int asidx;
31
+ CPUState *cs = CPU(cpu);
32
+
33
+ if (arm_feature(&cpu->env, ARM_FEATURE_EL3) && info->secure_boot) {
34
+ asidx = ARMASIdx_S;
35
+ } else {
36
+ asidx = ARMASIdx_NS;
37
+ }
38
+
39
+ return cpu_get_address_space(cs, asidx);
40
+}
41
+
42
typedef enum {
43
FIXUP_NONE = 0, /* do nothing */
44
FIXUP_TERMINATOR, /* end of insns */
45
@@ -XXX,XX +XXX,XX @@ static const ARMInsnFixup smpboot[] = {
46
};
25
};
47
26
48
static void write_bootloader(const char *name, hwaddr addr,
27
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_fpgaio(MPS2TZMachineState *mms, void *opaque,
49
- const ARMInsnFixup *insns, uint32_t *fixupcontext)
28
const char *name, hwaddr size)
50
+ const ARMInsnFixup *insns, uint32_t *fixupcontext,
51
+ AddressSpace *as)
52
{
29
{
53
/* Fix up the specified bootloader fragment and write it into
30
MPS2FPGAIO *fpgaio = opaque;
54
* guest memory using rom_add_blob_fixed(). fixupcontext is
31
+ MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
55
@@ -XXX,XX +XXX,XX @@ static void write_bootloader(const char *name, hwaddr addr,
32
56
code[i] = tswap32(insn);
33
object_initialize_child(OBJECT(mms), "fpgaio", fpgaio, TYPE_MPS2_FPGAIO);
57
}
34
+ qdev_prop_set_uint32(DEVICE(fpgaio), "num-leds", mmc->fpgaio_num_leds);
58
35
+ qdev_prop_set_bit(DEVICE(fpgaio), "has-switches", mmc->fpgaio_has_switches);
59
- rom_add_blob_fixed(name, code, len * sizeof(uint32_t), addr);
36
sysbus_realize(SYS_BUS_DEVICE(fpgaio), &error_fatal);
60
+ rom_add_blob_fixed_as(name, code, len * sizeof(uint32_t), addr, as);
37
return sysbus_mmio_get_region(SYS_BUS_DEVICE(fpgaio), 0);
61
62
g_free(code);
63
}
38
}
64
@@ -XXX,XX +XXX,XX @@ static void default_write_secondary(ARMCPU *cpu,
39
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an505_class_init(ObjectClass *oc, void *data)
65
const struct arm_boot_info *info)
40
mmc->sysclk_frq = 20 * 1000 * 1000; /* 20MHz */
66
{
41
mmc->oscclk = an505_oscclk;
67
uint32_t fixupcontext[FIXUP_MAX];
42
mmc->len_oscclk = ARRAY_SIZE(an505_oscclk);
68
+ AddressSpace *as = arm_boot_address_space(cpu, info);
43
+ mmc->fpgaio_num_leds = 2;
69
44
+ mmc->fpgaio_has_switches = false;
70
fixupcontext[FIXUP_GIC_CPU_IF] = info->gic_cpu_if_addr;
45
mmc->armsse_type = TYPE_IOTKIT;
71
fixupcontext[FIXUP_BOOTREG] = info->smp_bootreg_addr;
72
@@ -XXX,XX +XXX,XX @@ static void default_write_secondary(ARMCPU *cpu,
73
}
74
75
write_bootloader("smpboot", info->smp_loader_start,
76
- smpboot, fixupcontext);
77
+ smpboot, fixupcontext, as);
78
}
46
}
79
47
80
void arm_write_secure_board_setup_dummy_smc(ARMCPU *cpu,
48
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an521_class_init(ObjectClass *oc, void *data)
81
const struct arm_boot_info *info,
49
mmc->sysclk_frq = 20 * 1000 * 1000; /* 20MHz */
82
hwaddr mvbar_addr)
50
mmc->oscclk = an505_oscclk; /* AN521 is the same as AN505 here */
83
{
51
mmc->len_oscclk = ARRAY_SIZE(an505_oscclk);
84
+ AddressSpace *as = arm_boot_address_space(cpu, info);
52
+ mmc->fpgaio_num_leds = 2;
85
int n;
53
+ mmc->fpgaio_has_switches = false;
86
uint32_t mvbar_blob[] = {
54
mmc->armsse_type = TYPE_SSE200;
87
/* mvbar_addr: secure monitor vectors
88
@@ -XXX,XX +XXX,XX @@ void arm_write_secure_board_setup_dummy_smc(ARMCPU *cpu,
89
for (n = 0; n < ARRAY_SIZE(mvbar_blob); n++) {
90
mvbar_blob[n] = tswap32(mvbar_blob[n]);
91
}
92
- rom_add_blob_fixed("board-setup-mvbar", mvbar_blob, sizeof(mvbar_blob),
93
- mvbar_addr);
94
+ rom_add_blob_fixed_as("board-setup-mvbar", mvbar_blob, sizeof(mvbar_blob),
95
+ mvbar_addr, as);
96
97
for (n = 0; n < ARRAY_SIZE(board_setup_blob); n++) {
98
board_setup_blob[n] = tswap32(board_setup_blob[n]);
99
}
100
- rom_add_blob_fixed("board-setup", board_setup_blob,
101
- sizeof(board_setup_blob), info->board_setup_addr);
102
+ rom_add_blob_fixed_as("board-setup", board_setup_blob,
103
+ sizeof(board_setup_blob), info->board_setup_addr, as);
104
}
55
}
105
56
106
static void default_reset_secondary(ARMCPU *cpu,
107
const struct arm_boot_info *info)
108
{
109
+ AddressSpace *as = arm_boot_address_space(cpu, info);
110
CPUState *cs = CPU(cpu);
111
112
- address_space_stl_notdirty(&address_space_memory, info->smp_bootreg_addr,
113
+ address_space_stl_notdirty(as, info->smp_bootreg_addr,
114
0, MEMTXATTRS_UNSPECIFIED, NULL);
115
cpu_set_pc(cs, info->smp_loader_start);
116
}
117
@@ -XXX,XX +XXX,XX @@ static inline bool have_dtb(const struct arm_boot_info *info)
118
}
119
120
#define WRITE_WORD(p, value) do { \
121
- address_space_stl_notdirty(&address_space_memory, p, value, \
122
+ address_space_stl_notdirty(as, p, value, \
123
MEMTXATTRS_UNSPECIFIED, NULL); \
124
p += 4; \
125
} while (0)
126
127
-static void set_kernel_args(const struct arm_boot_info *info)
128
+static void set_kernel_args(const struct arm_boot_info *info, AddressSpace *as)
129
{
130
int initrd_size = info->initrd_size;
131
hwaddr base = info->loader_start;
132
@@ -XXX,XX +XXX,XX @@ static void set_kernel_args(const struct arm_boot_info *info)
133
int cmdline_size;
134
135
cmdline_size = strlen(info->kernel_cmdline);
136
- cpu_physical_memory_write(p + 8, info->kernel_cmdline,
137
- cmdline_size + 1);
138
+ address_space_write(as, p + 8, MEMTXATTRS_UNSPECIFIED,
139
+ (const uint8_t *)info->kernel_cmdline,
140
+ cmdline_size + 1);
141
cmdline_size = (cmdline_size >> 2) + 1;
142
WRITE_WORD(p, cmdline_size + 2);
143
WRITE_WORD(p, 0x54410009);
144
@@ -XXX,XX +XXX,XX @@ static void set_kernel_args(const struct arm_boot_info *info)
145
atag_board_len = (info->atag_board(info, atag_board_buf) + 3) & ~3;
146
WRITE_WORD(p, (atag_board_len + 8) >> 2);
147
WRITE_WORD(p, 0x414f4d50);
148
- cpu_physical_memory_write(p, atag_board_buf, atag_board_len);
149
+ address_space_write(as, p, MEMTXATTRS_UNSPECIFIED,
150
+ atag_board_buf, atag_board_len);
151
p += atag_board_len;
152
}
153
/* ATAG_END */
154
@@ -XXX,XX +XXX,XX @@ static void set_kernel_args(const struct arm_boot_info *info)
155
WRITE_WORD(p, 0);
156
}
157
158
-static void set_kernel_args_old(const struct arm_boot_info *info)
159
+static void set_kernel_args_old(const struct arm_boot_info *info,
160
+ AddressSpace *as)
161
{
162
hwaddr p;
163
const char *s;
164
@@ -XXX,XX +XXX,XX @@ static void set_kernel_args_old(const struct arm_boot_info *info)
165
}
166
s = info->kernel_cmdline;
167
if (s) {
168
- cpu_physical_memory_write(p, s, strlen(s) + 1);
169
+ address_space_write(as, p, MEMTXATTRS_UNSPECIFIED,
170
+ (const uint8_t *)s, strlen(s) + 1);
171
} else {
172
WRITE_WORD(p, 0);
173
}
174
@@ -XXX,XX +XXX,XX @@ static void fdt_add_psci_node(void *fdt)
175
* @addr: the address to load the image at
176
* @binfo: struct describing the boot environment
177
* @addr_limit: upper limit of the available memory area at @addr
178
+ * @as: address space to load image to
179
*
180
* Load a device tree supplied by the machine or by the user with the
181
* '-dtb' command line option, and put it at offset @addr in target
182
@@ -XXX,XX +XXX,XX @@ static void fdt_add_psci_node(void *fdt)
183
* Note: Must not be called unless have_dtb(binfo) is true.
184
*/
185
static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
186
- hwaddr addr_limit)
187
+ hwaddr addr_limit, AddressSpace *as)
188
{
189
void *fdt = NULL;
190
int size, rc;
191
@@ -XXX,XX +XXX,XX @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
192
/* Put the DTB into the memory map as a ROM image: this will ensure
193
* the DTB is copied again upon reset, even if addr points into RAM.
194
*/
195
- rom_add_blob_fixed("dtb", fdt, size, addr);
196
+ rom_add_blob_fixed_as("dtb", fdt, size, addr, as);
197
198
g_free(fdt);
199
200
@@ -XXX,XX +XXX,XX @@ static void do_cpu_reset(void *opaque)
201
}
202
203
if (cs == first_cpu) {
204
+ AddressSpace *as = arm_boot_address_space(cpu, info);
205
+
206
cpu_set_pc(cs, info->loader_start);
207
208
if (!have_dtb(info)) {
209
if (old_param) {
210
- set_kernel_args_old(info);
211
+ set_kernel_args_old(info, as);
212
} else {
213
- set_kernel_args(info);
214
+ set_kernel_args(info, as);
215
}
216
}
217
} else {
218
@@ -XXX,XX +XXX,XX @@ static int do_arm_linux_init(Object *obj, void *opaque)
219
220
static uint64_t arm_load_elf(struct arm_boot_info *info, uint64_t *pentry,
221
uint64_t *lowaddr, uint64_t *highaddr,
222
- int elf_machine)
223
+ int elf_machine, AddressSpace *as)
224
{
225
bool elf_is64;
226
union {
227
@@ -XXX,XX +XXX,XX @@ static uint64_t arm_load_elf(struct arm_boot_info *info, uint64_t *pentry,
228
}
229
}
230
231
- ret = load_elf(info->kernel_filename, NULL, NULL,
232
- pentry, lowaddr, highaddr, big_endian, elf_machine,
233
- 1, data_swab);
234
+ ret = load_elf_as(info->kernel_filename, NULL, NULL,
235
+ pentry, lowaddr, highaddr, big_endian, elf_machine,
236
+ 1, data_swab, as);
237
if (ret <= 0) {
238
/* The header loaded but the image didn't */
239
exit(1);
240
@@ -XXX,XX +XXX,XX @@ static uint64_t arm_load_elf(struct arm_boot_info *info, uint64_t *pentry,
241
}
242
243
static uint64_t load_aarch64_image(const char *filename, hwaddr mem_base,
244
- hwaddr *entry)
245
+ hwaddr *entry, AddressSpace *as)
246
{
247
hwaddr kernel_load_offset = KERNEL64_LOAD_ADDR;
248
uint8_t *buffer;
249
@@ -XXX,XX +XXX,XX @@ static uint64_t load_aarch64_image(const char *filename, hwaddr mem_base,
250
}
251
252
*entry = mem_base + kernel_load_offset;
253
- rom_add_blob_fixed(filename, buffer, size, *entry);
254
+ rom_add_blob_fixed_as(filename, buffer, size, *entry, as);
255
256
g_free(buffer);
257
258
@@ -XXX,XX +XXX,XX @@ static void arm_load_kernel_notify(Notifier *notifier, void *data)
259
ARMCPU *cpu = n->cpu;
260
struct arm_boot_info *info =
261
container_of(n, struct arm_boot_info, load_kernel_notifier);
262
+ AddressSpace *as = arm_boot_address_space(cpu, info);
263
264
/* The board code is not supposed to set secure_board_setup unless
265
* running its code in secure mode is actually possible, and KVM
266
@@ -XXX,XX +XXX,XX @@ static void arm_load_kernel_notify(Notifier *notifier, void *data)
267
* the kernel is supposed to be loaded by the bootloader), copy the
268
* DTB to the base of RAM for the bootloader to pick up.
269
*/
270
- if (load_dtb(info->loader_start, info, 0) < 0) {
271
+ if (load_dtb(info->loader_start, info, 0, as) < 0) {
272
exit(1);
273
}
274
}
275
@@ -XXX,XX +XXX,XX @@ static void arm_load_kernel_notify(Notifier *notifier, void *data)
276
277
/* Assume that raw images are linux kernels, and ELF images are not. */
278
kernel_size = arm_load_elf(info, &elf_entry, &elf_low_addr,
279
- &elf_high_addr, elf_machine);
280
+ &elf_high_addr, elf_machine, as);
281
if (kernel_size > 0 && have_dtb(info)) {
282
/* If there is still some room left at the base of RAM, try and put
283
* the DTB there like we do for images loaded with -bios or -pflash.
284
@@ -XXX,XX +XXX,XX @@ static void arm_load_kernel_notify(Notifier *notifier, void *data)
285
if (elf_low_addr < info->loader_start) {
286
elf_low_addr = 0;
287
}
288
- if (load_dtb(info->loader_start, info, elf_low_addr) < 0) {
289
+ if (load_dtb(info->loader_start, info, elf_low_addr, as) < 0) {
290
exit(1);
291
}
292
}
293
}
294
entry = elf_entry;
295
if (kernel_size < 0) {
296
- kernel_size = load_uimage(info->kernel_filename, &entry, NULL,
297
- &is_linux, NULL, NULL);
298
+ kernel_size = load_uimage_as(info->kernel_filename, &entry, NULL,
299
+ &is_linux, NULL, NULL, as);
300
}
301
if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64) && kernel_size < 0) {
302
kernel_size = load_aarch64_image(info->kernel_filename,
303
- info->loader_start, &entry);
304
+ info->loader_start, &entry, as);
305
is_linux = 1;
306
} else if (kernel_size < 0) {
307
/* 32-bit ARM */
308
entry = info->loader_start + KERNEL_LOAD_ADDR;
309
- kernel_size = load_image_targphys(info->kernel_filename, entry,
310
- info->ram_size - KERNEL_LOAD_ADDR);
311
+ kernel_size = load_image_targphys_as(info->kernel_filename, entry,
312
+ info->ram_size - KERNEL_LOAD_ADDR,
313
+ as);
314
is_linux = 1;
315
}
316
if (kernel_size < 0) {
317
@@ -XXX,XX +XXX,XX @@ static void arm_load_kernel_notify(Notifier *notifier, void *data)
318
uint32_t fixupcontext[FIXUP_MAX];
319
320
if (info->initrd_filename) {
321
- initrd_size = load_ramdisk(info->initrd_filename,
322
- info->initrd_start,
323
- info->ram_size -
324
- info->initrd_start);
325
+ initrd_size = load_ramdisk_as(info->initrd_filename,
326
+ info->initrd_start,
327
+ info->ram_size - info->initrd_start,
328
+ as);
329
if (initrd_size < 0) {
330
- initrd_size = load_image_targphys(info->initrd_filename,
331
- info->initrd_start,
332
- info->ram_size -
333
- info->initrd_start);
334
+ initrd_size = load_image_targphys_as(info->initrd_filename,
335
+ info->initrd_start,
336
+ info->ram_size -
337
+ info->initrd_start,
338
+ as);
339
}
340
if (initrd_size < 0) {
341
error_report("could not load initrd '%s'",
342
@@ -XXX,XX +XXX,XX @@ static void arm_load_kernel_notify(Notifier *notifier, void *data)
343
344
/* Place the DTB after the initrd in memory with alignment. */
345
dtb_start = QEMU_ALIGN_UP(info->initrd_start + initrd_size, align);
346
- if (load_dtb(dtb_start, info, 0) < 0) {
347
+ if (load_dtb(dtb_start, info, 0, as) < 0) {
348
exit(1);
349
}
350
fixupcontext[FIXUP_ARGPTR] = dtb_start;
351
@@ -XXX,XX +XXX,XX @@ static void arm_load_kernel_notify(Notifier *notifier, void *data)
352
fixupcontext[FIXUP_ENTRYPOINT] = entry;
353
354
write_bootloader("bootloader", info->loader_start,
355
- primary_loader, fixupcontext);
356
+ primary_loader, fixupcontext, as);
357
358
if (info->nb_cpus > 1) {
359
info->write_secondary_boot(cpu, info);
360
--
57
--
361
2.16.2
58
2.20.1
362
59
363
60
diff view generated by jsdifflib
1
The function qdev_init_gpio_in_named() passes the DeviceState pointer
1
In the mps2-tz board code, we handle devices whose interrupt lines
2
as the opaque data pointor for the irq handler function. Usually
2
must be wired to all CPUs by creating IRQ splitter devices for the
3
this is what you want, but in some cases it would be helpful to use
3
AN521, because it has 2 CPUs, but wiring the device IRQ directly to
4
some other data pointer.
4
the SSE/IoTKit input for the AN505, which has only 1 CPU.
5
5
6
Add a new function qdev_init_gpio_in_named_with_opaque() which allows
6
We can avoid making an explicit check on the board type constant by
7
the caller to specify the data pointer they want.
7
instead creating and using the IRQ splitters for any board with more
8
than 1 CPU. This avoids having to add extra cases to the
9
conditionals every time we add new boards.
8
10
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
12
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
13
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Message-id: 20180220180325.29818-12-peter.maydell@linaro.org
14
Message-id: 20210215115138.20465-9-peter.maydell@linaro.org
13
---
15
---
14
include/hw/qdev-core.h | 30 ++++++++++++++++++++++++++++--
16
hw/arm/mps2-tz.c | 19 +++++++++----------
15
hw/core/qdev.c | 8 +++++---
17
1 file changed, 9 insertions(+), 10 deletions(-)
16
2 files changed, 33 insertions(+), 5 deletions(-)
17
18
18
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
19
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
19
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
20
--- a/include/hw/qdev-core.h
21
--- a/hw/arm/mps2-tz.c
21
+++ b/include/hw/qdev-core.h
22
+++ b/hw/arm/mps2-tz.c
22
@@ -XXX,XX +XXX,XX @@ BusState *qdev_get_child_bus(DeviceState *dev, const char *name);
23
@@ -XXX,XX +XXX,XX @@ static void make_ram_alias(MemoryRegion *mr, const char *name,
23
/* GPIO inputs also double as IRQ sinks. */
24
static qemu_irq get_sse_irq_in(MPS2TZMachineState *mms, int irqno)
24
void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
25
{
25
void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
26
/* Return a qemu_irq which will signal IRQ n to all CPUs in the SSE. */
26
-void qdev_init_gpio_in_named(DeviceState *dev, qemu_irq_handler handler,
27
- MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
27
- const char *name, int n);
28
+ MachineClass *mc = MACHINE_GET_CLASS(mms);
28
void qdev_init_gpio_out_named(DeviceState *dev, qemu_irq *pins,
29
29
const char *name, int n);
30
assert(irqno < MPS2TZ_NUMIRQ);
30
+/**
31
31
+ * qdev_init_gpio_in_named_with_opaque: create an array of input GPIO lines
32
- switch (mmc->fpga_type) {
32
+ * for the specified device
33
- case FPGA_AN505:
33
+ *
34
- return qdev_get_gpio_in_named(DEVICE(&mms->iotkit), "EXP_IRQ", irqno);
34
+ * @dev: Device to create input GPIOs for
35
- case FPGA_AN521:
35
+ * @handler: Function to call when GPIO line value is set
36
+ if (mc->max_cpus > 1) {
36
+ * @opaque: Opaque data pointer to pass to @handler
37
return qdev_get_gpio_in(DEVICE(&mms->cpu_irq_splitter[irqno]), 0);
37
+ * @name: Name of the GPIO input (must be unique for this device)
38
- default:
38
+ * @n: Number of GPIO lines in this input set
39
- g_assert_not_reached();
39
+ */
40
+ } else {
40
+void qdev_init_gpio_in_named_with_opaque(DeviceState *dev,
41
+ return qdev_get_gpio_in_named(DEVICE(&mms->iotkit), "EXP_IRQ", irqno);
41
+ qemu_irq_handler handler,
42
}
42
+ void *opaque,
43
+ const char *name, int n);
44
+
45
+/**
46
+ * qdev_init_gpio_in_named: create an array of input GPIO lines
47
+ * for the specified device
48
+ *
49
+ * Like qdev_init_gpio_in_named_with_opaque(), but the opaque pointer
50
+ * passed to the handler is @dev (which is the most commonly desired behaviour).
51
+ */
52
+static inline void qdev_init_gpio_in_named(DeviceState *dev,
53
+ qemu_irq_handler handler,
54
+ const char *name, int n)
55
+{
56
+ qdev_init_gpio_in_named_with_opaque(dev, handler, dev, name, n);
57
+}
58
59
void qdev_pass_gpios(DeviceState *dev, DeviceState *container,
60
const char *name);
61
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
62
index XXXXXXX..XXXXXXX 100644
63
--- a/hw/core/qdev.c
64
+++ b/hw/core/qdev.c
65
@@ -XXX,XX +XXX,XX @@ static NamedGPIOList *qdev_get_named_gpio_list(DeviceState *dev,
66
return ngl;
67
}
43
}
68
44
69
-void qdev_init_gpio_in_named(DeviceState *dev, qemu_irq_handler handler,
45
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
70
- const char *name, int n)
46
sysbus_realize(SYS_BUS_DEVICE(&mms->iotkit), &error_fatal);
71
+void qdev_init_gpio_in_named_with_opaque(DeviceState *dev,
47
72
+ qemu_irq_handler handler,
48
/*
73
+ void *opaque,
49
- * The AN521 needs us to create splitters to feed the IRQ inputs
74
+ const char *name, int n)
50
- * for each CPU in the SSE-200 from each device in the board.
75
{
51
+ * If this board has more than one CPU, then we need to create splitters
76
int i;
52
+ * to feed the IRQ inputs for each CPU in the SSE from each device in the
77
NamedGPIOList *gpio_list = qdev_get_named_gpio_list(dev, name);
53
+ * board. If there is only one CPU, we can just wire the device IRQ
78
54
+ * directly to the SSE's IRQ input.
79
assert(gpio_list->num_out == 0 || !name);
55
*/
80
gpio_list->in = qemu_extend_irqs(gpio_list->in, gpio_list->num_in, handler,
56
- if (mmc->fpga_type == FPGA_AN521) {
81
- dev, n);
57
+ if (mc->max_cpus > 1) {
82
+ opaque, n);
58
for (i = 0; i < MPS2TZ_NUMIRQ; i++) {
83
59
char *name = g_strdup_printf("mps2-irq-splitter%d", i);
84
if (!name) {
60
SplitIRQ *splitter = &mms->cpu_irq_splitter[i];
85
name = "unnamed-gpio-in";
86
--
61
--
87
2.16.2
62
2.20.1
88
63
89
64
diff view generated by jsdifflib
1
Move the definition of the struct for the unimplemented-device
1
The AN524 has more interrupt lines than the AN505 and AN521; make
2
from unimp.c to unimp.h, so that users can embed the struct
2
numirq board-specific rather than a compile-time constant.
3
in their own device structs if they prefer.
3
4
Since the difference is small (92 on the current boards and 95 on the
5
new one) we don't dynamically allocate the cpu_irq_splitter[] array
6
but leave it as a fixed length array whose size is the maximum needed
7
for any of the boards.
4
8
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
10
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20180220180325.29818-10-peter.maydell@linaro.org
12
Message-id: 20210215115138.20465-10-peter.maydell@linaro.org
9
---
13
---
10
include/hw/misc/unimp.h | 10 ++++++++++
14
hw/arm/mps2-tz.c | 15 ++++++++++-----
11
hw/misc/unimp.c | 10 ----------
15
1 file changed, 10 insertions(+), 5 deletions(-)
12
2 files changed, 10 insertions(+), 10 deletions(-)
13
16
14
diff --git a/include/hw/misc/unimp.h b/include/hw/misc/unimp.h
17
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
15
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
16
--- a/include/hw/misc/unimp.h
19
--- a/hw/arm/mps2-tz.c
17
+++ b/include/hw/misc/unimp.h
20
+++ b/hw/arm/mps2-tz.c
18
@@ -XXX,XX +XXX,XX @@
21
@@ -XXX,XX +XXX,XX @@
19
22
#include "hw/qdev-clock.h"
20
#define TYPE_UNIMPLEMENTED_DEVICE "unimplemented-device"
23
#include "qom/object.h"
21
24
22
+#define UNIMPLEMENTED_DEVICE(obj) \
25
-#define MPS2TZ_NUMIRQ 92
23
+ OBJECT_CHECK(UnimplementedDeviceState, (obj), TYPE_UNIMPLEMENTED_DEVICE)
26
+#define MPS2TZ_NUMIRQ_MAX 92
24
+
27
25
+typedef struct {
28
typedef enum MPS2TZFPGAType {
26
+ SysBusDevice parent_obj;
29
FPGA_AN505,
27
+ MemoryRegion iomem;
30
@@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineClass {
28
+ char *name;
31
const uint32_t *oscclk;
29
+ uint64_t size;
32
uint32_t fpgaio_num_leds; /* Number of LEDs in FPGAIO LED0 register */
30
+} UnimplementedDeviceState;
33
bool fpgaio_has_switches; /* Does FPGAIO have SWITCH register? */
31
+
34
+ int numirq; /* Number of external interrupts */
32
/**
35
const char *armsse_type;
33
* create_unimplemented_device: create and map a dummy device
36
};
34
* @name: name of the device for debug logging
37
35
diff --git a/hw/misc/unimp.c b/hw/misc/unimp.c
38
@@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineState {
36
index XXXXXXX..XXXXXXX 100644
39
SplitIRQ sec_resp_splitter;
37
--- a/hw/misc/unimp.c
40
qemu_or_irq uart_irq_orgate;
38
+++ b/hw/misc/unimp.c
41
DeviceState *lan9118;
39
@@ -XXX,XX +XXX,XX @@
42
- SplitIRQ cpu_irq_splitter[MPS2TZ_NUMIRQ];
40
#include "qemu/log.h"
43
+ SplitIRQ cpu_irq_splitter[MPS2TZ_NUMIRQ_MAX];
41
#include "qapi/error.h"
44
Clock *sysclk;
42
45
Clock *s32kclk;
43
-#define UNIMPLEMENTED_DEVICE(obj) \
46
};
44
- OBJECT_CHECK(UnimplementedDeviceState, (obj), TYPE_UNIMPLEMENTED_DEVICE)
47
@@ -XXX,XX +XXX,XX @@ static qemu_irq get_sse_irq_in(MPS2TZMachineState *mms, int irqno)
45
-
46
-typedef struct {
47
- SysBusDevice parent_obj;
48
- MemoryRegion iomem;
49
- char *name;
50
- uint64_t size;
51
-} UnimplementedDeviceState;
52
-
53
static uint64_t unimp_read(void *opaque, hwaddr offset, unsigned size)
54
{
48
{
55
UnimplementedDeviceState *s = UNIMPLEMENTED_DEVICE(opaque);
49
/* Return a qemu_irq which will signal IRQ n to all CPUs in the SSE. */
50
MachineClass *mc = MACHINE_GET_CLASS(mms);
51
+ MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
52
53
- assert(irqno < MPS2TZ_NUMIRQ);
54
+ assert(irqno < mmc->numirq);
55
56
if (mc->max_cpus > 1) {
57
return qdev_get_gpio_in(DEVICE(&mms->cpu_irq_splitter[irqno]), 0);
58
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
59
iotkitdev = DEVICE(&mms->iotkit);
60
object_property_set_link(OBJECT(&mms->iotkit), "memory",
61
OBJECT(system_memory), &error_abort);
62
- qdev_prop_set_uint32(iotkitdev, "EXP_NUMIRQ", MPS2TZ_NUMIRQ);
63
+ qdev_prop_set_uint32(iotkitdev, "EXP_NUMIRQ", mmc->numirq);
64
qdev_connect_clock_in(iotkitdev, "MAINCLK", mms->sysclk);
65
qdev_connect_clock_in(iotkitdev, "S32KCLK", mms->s32kclk);
66
sysbus_realize(SYS_BUS_DEVICE(&mms->iotkit), &error_fatal);
67
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
68
* board. If there is only one CPU, we can just wire the device IRQ
69
* directly to the SSE's IRQ input.
70
*/
71
+ assert(mmc->numirq <= MPS2TZ_NUMIRQ_MAX);
72
if (mc->max_cpus > 1) {
73
- for (i = 0; i < MPS2TZ_NUMIRQ; i++) {
74
+ for (i = 0; i < mmc->numirq; i++) {
75
char *name = g_strdup_printf("mps2-irq-splitter%d", i);
76
SplitIRQ *splitter = &mms->cpu_irq_splitter[i];
77
78
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an505_class_init(ObjectClass *oc, void *data)
79
mmc->len_oscclk = ARRAY_SIZE(an505_oscclk);
80
mmc->fpgaio_num_leds = 2;
81
mmc->fpgaio_has_switches = false;
82
+ mmc->numirq = 92;
83
mmc->armsse_type = TYPE_IOTKIT;
84
}
85
86
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an521_class_init(ObjectClass *oc, void *data)
87
mmc->len_oscclk = ARRAY_SIZE(an505_oscclk);
88
mmc->fpgaio_num_leds = 2;
89
mmc->fpgaio_has_switches = false;
90
+ mmc->numirq = 92;
91
mmc->armsse_type = TYPE_SSE200;
92
}
93
56
--
94
--
57
2.16.2
95
2.20.1
58
96
59
97
diff view generated by jsdifflib
1
The Arm IoT Kit includes a "security controller" which is largely a
1
The AN524 version of the SCC interface has different behaviour for
2
collection of registers for controlling the PPCs and other bits of
2
some of the CFG registers; implement it.
3
glue in the system. This commit provides the initial skeleton of the
3
4
device, implementing just the ID registers, and a couple of read-only
4
Each board in this family can have minor differences in the meaning
5
read-as-zero registers.
5
of the CFG registers, so rather than trying to specify all the
6
possible semantics via individual device properties, we make the
7
behaviour conditional on the part-number field of the SCC_ID register
8
which the board code already passes us.
9
10
For the AN524, the differences are:
11
* CFG3 is reserved rather than being board switches
12
* CFG5 is a new register ("ACLK Frequency in Hz")
13
* CFG6 is a new register ("Clock divider for BRAM")
14
15
We implement both of the new registers as reads-as-written.
6
16
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
18
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Message-id: 20180220180325.29818-16-peter.maydell@linaro.org
19
Message-id: 20210215115138.20465-11-peter.maydell@linaro.org
10
---
20
---
11
hw/misc/Makefile.objs | 1 +
21
include/hw/misc/mps2-scc.h | 3 ++
12
include/hw/misc/iotkit-secctl.h | 39 ++++
22
hw/misc/mps2-scc.c | 71 ++++++++++++++++++++++++++++++++++++--
13
hw/misc/iotkit-secctl.c | 448 ++++++++++++++++++++++++++++++++++++++++
23
2 files changed, 72 insertions(+), 2 deletions(-)
14
default-configs/arm-softmmu.mak | 1 +
15
hw/misc/trace-events | 7 +
16
5 files changed, 496 insertions(+)
17
create mode 100644 include/hw/misc/iotkit-secctl.h
18
create mode 100644 hw/misc/iotkit-secctl.c
19
24
20
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
25
diff --git a/include/hw/misc/mps2-scc.h b/include/hw/misc/mps2-scc.h
21
index XXXXXXX..XXXXXXX 100644
26
index XXXXXXX..XXXXXXX 100644
22
--- a/hw/misc/Makefile.objs
27
--- a/include/hw/misc/mps2-scc.h
23
+++ b/hw/misc/Makefile.objs
28
+++ b/include/hw/misc/mps2-scc.h
24
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_MPS2_FPGAIO) += mps2-fpgaio.o
29
@@ -XXX,XX +XXX,XX @@ struct MPS2SCC {
25
obj-$(CONFIG_MPS2_SCC) += mps2-scc.o
30
26
31
uint32_t cfg0;
27
obj-$(CONFIG_TZ_PPC) += tz-ppc.o
32
uint32_t cfg1;
28
+obj-$(CONFIG_IOTKIT_SECCTL) += iotkit-secctl.o
33
+ uint32_t cfg2;
29
34
uint32_t cfg4;
30
obj-$(CONFIG_PVPANIC) += pvpanic.o
35
+ uint32_t cfg5;
31
obj-$(CONFIG_HYPERV_TESTDEV) += hyperv_testdev.o
36
+ uint32_t cfg6;
32
diff --git a/include/hw/misc/iotkit-secctl.h b/include/hw/misc/iotkit-secctl.h
37
uint32_t cfgdata_rtn;
33
new file mode 100644
38
uint32_t cfgdata_out;
34
index XXXXXXX..XXXXXXX
39
uint32_t cfgctrl;
35
--- /dev/null
40
diff --git a/hw/misc/mps2-scc.c b/hw/misc/mps2-scc.c
36
+++ b/include/hw/misc/iotkit-secctl.h
41
index XXXXXXX..XXXXXXX 100644
42
--- a/hw/misc/mps2-scc.c
43
+++ b/hw/misc/mps2-scc.c
37
@@ -XXX,XX +XXX,XX @@
44
@@ -XXX,XX +XXX,XX @@
38
+/*
45
39
+ * ARM IoT Kit security controller
46
REG32(CFG0, 0)
40
+ *
47
REG32(CFG1, 4)
41
+ * Copyright (c) 2018 Linaro Limited
48
+REG32(CFG2, 8)
42
+ * Written by Peter Maydell
49
REG32(CFG3, 0xc)
43
+ *
50
REG32(CFG4, 0x10)
44
+ * This program is free software; you can redistribute it and/or modify
51
+REG32(CFG5, 0x14)
45
+ * it under the terms of the GNU General Public License version 2 or
52
+REG32(CFG6, 0x18)
46
+ * (at your option) any later version.
53
REG32(CFGDATA_RTN, 0xa0)
47
+ */
54
REG32(CFGDATA_OUT, 0xa4)
48
+
55
REG32(CFGCTRL, 0xa8)
49
+/* This is a model of the security controller which is part of the
56
@@ -XXX,XX +XXX,XX @@ REG32(DLL, 0x100)
50
+ * Arm IoT Kit and documented in
57
REG32(AID, 0xFF8)
51
+ * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
58
REG32(ID, 0xFFC)
52
+ *
59
53
+ * QEMU interface:
60
+static int scc_partno(MPS2SCC *s)
54
+ * + sysbus MMIO region 0 is the "secure privilege control block" registers
55
+ * + sysbus MMIO region 1 is the "non-secure privilege control block" registers
56
+ */
57
+
58
+#ifndef IOTKIT_SECCTL_H
59
+#define IOTKIT_SECCTL_H
60
+
61
+#include "hw/sysbus.h"
62
+
63
+#define TYPE_IOTKIT_SECCTL "iotkit-secctl"
64
+#define IOTKIT_SECCTL(obj) OBJECT_CHECK(IoTKitSecCtl, (obj), TYPE_IOTKIT_SECCTL)
65
+
66
+typedef struct IoTKitSecCtl {
67
+ /*< private >*/
68
+ SysBusDevice parent_obj;
69
+
70
+ /*< public >*/
71
+
72
+ MemoryRegion s_regs;
73
+ MemoryRegion ns_regs;
74
+} IoTKitSecCtl;
75
+
76
+#endif
77
diff --git a/hw/misc/iotkit-secctl.c b/hw/misc/iotkit-secctl.c
78
new file mode 100644
79
index XXXXXXX..XXXXXXX
80
--- /dev/null
81
+++ b/hw/misc/iotkit-secctl.c
82
@@ -XXX,XX +XXX,XX @@
83
+/*
84
+ * Arm IoT Kit security controller
85
+ *
86
+ * Copyright (c) 2018 Linaro Limited
87
+ * Written by Peter Maydell
88
+ *
89
+ * This program is free software; you can redistribute it and/or modify
90
+ * it under the terms of the GNU General Public License version 2 or
91
+ * (at your option) any later version.
92
+ */
93
+
94
+#include "qemu/osdep.h"
95
+#include "qemu/log.h"
96
+#include "qapi/error.h"
97
+#include "trace.h"
98
+#include "hw/sysbus.h"
99
+#include "hw/registerfields.h"
100
+#include "hw/misc/iotkit-secctl.h"
101
+
102
+/* Registers in the secure privilege control block */
103
+REG32(SECRESPCFG, 0x10)
104
+REG32(NSCCFG, 0x14)
105
+REG32(SECMPCINTSTATUS, 0x1c)
106
+REG32(SECPPCINTSTAT, 0x20)
107
+REG32(SECPPCINTCLR, 0x24)
108
+REG32(SECPPCINTEN, 0x28)
109
+REG32(SECMSCINTSTAT, 0x30)
110
+REG32(SECMSCINTCLR, 0x34)
111
+REG32(SECMSCINTEN, 0x38)
112
+REG32(BRGINTSTAT, 0x40)
113
+REG32(BRGINTCLR, 0x44)
114
+REG32(BRGINTEN, 0x48)
115
+REG32(AHBNSPPC0, 0x50)
116
+REG32(AHBNSPPCEXP0, 0x60)
117
+REG32(AHBNSPPCEXP1, 0x64)
118
+REG32(AHBNSPPCEXP2, 0x68)
119
+REG32(AHBNSPPCEXP3, 0x6c)
120
+REG32(APBNSPPC0, 0x70)
121
+REG32(APBNSPPC1, 0x74)
122
+REG32(APBNSPPCEXP0, 0x80)
123
+REG32(APBNSPPCEXP1, 0x84)
124
+REG32(APBNSPPCEXP2, 0x88)
125
+REG32(APBNSPPCEXP3, 0x8c)
126
+REG32(AHBSPPPC0, 0x90)
127
+REG32(AHBSPPPCEXP0, 0xa0)
128
+REG32(AHBSPPPCEXP1, 0xa4)
129
+REG32(AHBSPPPCEXP2, 0xa8)
130
+REG32(AHBSPPPCEXP3, 0xac)
131
+REG32(APBSPPPC0, 0xb0)
132
+REG32(APBSPPPC1, 0xb4)
133
+REG32(APBSPPPCEXP0, 0xc0)
134
+REG32(APBSPPPCEXP1, 0xc4)
135
+REG32(APBSPPPCEXP2, 0xc8)
136
+REG32(APBSPPPCEXP3, 0xcc)
137
+REG32(NSMSCEXP, 0xd0)
138
+REG32(PID4, 0xfd0)
139
+REG32(PID5, 0xfd4)
140
+REG32(PID6, 0xfd8)
141
+REG32(PID7, 0xfdc)
142
+REG32(PID0, 0xfe0)
143
+REG32(PID1, 0xfe4)
144
+REG32(PID2, 0xfe8)
145
+REG32(PID3, 0xfec)
146
+REG32(CID0, 0xff0)
147
+REG32(CID1, 0xff4)
148
+REG32(CID2, 0xff8)
149
+REG32(CID3, 0xffc)
150
+
151
+/* Registers in the non-secure privilege control block */
152
+REG32(AHBNSPPPC0, 0x90)
153
+REG32(AHBNSPPPCEXP0, 0xa0)
154
+REG32(AHBNSPPPCEXP1, 0xa4)
155
+REG32(AHBNSPPPCEXP2, 0xa8)
156
+REG32(AHBNSPPPCEXP3, 0xac)
157
+REG32(APBNSPPPC0, 0xb0)
158
+REG32(APBNSPPPC1, 0xb4)
159
+REG32(APBNSPPPCEXP0, 0xc0)
160
+REG32(APBNSPPPCEXP1, 0xc4)
161
+REG32(APBNSPPPCEXP2, 0xc8)
162
+REG32(APBNSPPPCEXP3, 0xcc)
163
+/* PID and CID registers are also present in the NS block */
164
+
165
+static const uint8_t iotkit_secctl_s_idregs[] = {
166
+ 0x04, 0x00, 0x00, 0x00,
167
+ 0x52, 0xb8, 0x0b, 0x00,
168
+ 0x0d, 0xf0, 0x05, 0xb1,
169
+};
170
+
171
+static const uint8_t iotkit_secctl_ns_idregs[] = {
172
+ 0x04, 0x00, 0x00, 0x00,
173
+ 0x53, 0xb8, 0x0b, 0x00,
174
+ 0x0d, 0xf0, 0x05, 0xb1,
175
+};
176
+
177
+static MemTxResult iotkit_secctl_s_read(void *opaque, hwaddr addr,
178
+ uint64_t *pdata,
179
+ unsigned size, MemTxAttrs attrs)
180
+{
61
+{
181
+ uint64_t r;
62
+ /* Return the partno field of the SCC_ID (0x524, 0x511, etc) */
182
+ uint32_t offset = addr & ~0x3;
63
+ return extract32(s->id, 4, 8);
183
+
184
+ switch (offset) {
185
+ case A_AHBNSPPC0:
186
+ case A_AHBSPPPC0:
187
+ r = 0;
188
+ break;
189
+ case A_SECRESPCFG:
190
+ case A_NSCCFG:
191
+ case A_SECMPCINTSTATUS:
192
+ case A_SECPPCINTSTAT:
193
+ case A_SECPPCINTEN:
194
+ case A_SECMSCINTSTAT:
195
+ case A_SECMSCINTEN:
196
+ case A_BRGINTSTAT:
197
+ case A_BRGINTEN:
198
+ case A_AHBNSPPCEXP0:
199
+ case A_AHBNSPPCEXP1:
200
+ case A_AHBNSPPCEXP2:
201
+ case A_AHBNSPPCEXP3:
202
+ case A_APBNSPPC0:
203
+ case A_APBNSPPC1:
204
+ case A_APBNSPPCEXP0:
205
+ case A_APBNSPPCEXP1:
206
+ case A_APBNSPPCEXP2:
207
+ case A_APBNSPPCEXP3:
208
+ case A_AHBSPPPCEXP0:
209
+ case A_AHBSPPPCEXP1:
210
+ case A_AHBSPPPCEXP2:
211
+ case A_AHBSPPPCEXP3:
212
+ case A_APBSPPPC0:
213
+ case A_APBSPPPC1:
214
+ case A_APBSPPPCEXP0:
215
+ case A_APBSPPPCEXP1:
216
+ case A_APBSPPPCEXP2:
217
+ case A_APBSPPPCEXP3:
218
+ case A_NSMSCEXP:
219
+ qemu_log_mask(LOG_UNIMP,
220
+ "IoTKit SecCtl S block read: "
221
+ "unimplemented offset 0x%x\n", offset);
222
+ r = 0;
223
+ break;
224
+ case A_PID4:
225
+ case A_PID5:
226
+ case A_PID6:
227
+ case A_PID7:
228
+ case A_PID0:
229
+ case A_PID1:
230
+ case A_PID2:
231
+ case A_PID3:
232
+ case A_CID0:
233
+ case A_CID1:
234
+ case A_CID2:
235
+ case A_CID3:
236
+ r = iotkit_secctl_s_idregs[(offset - A_PID4) / 4];
237
+ break;
238
+ case A_SECPPCINTCLR:
239
+ case A_SECMSCINTCLR:
240
+ case A_BRGINTCLR:
241
+ qemu_log_mask(LOG_GUEST_ERROR,
242
+ "IotKit SecCtl S block read: write-only offset 0x%x\n",
243
+ offset);
244
+ r = 0;
245
+ break;
246
+ default:
247
+ qemu_log_mask(LOG_GUEST_ERROR,
248
+ "IotKit SecCtl S block read: bad offset 0x%x\n", offset);
249
+ r = 0;
250
+ break;
251
+ }
252
+
253
+ if (size != 4) {
254
+ /* None of our registers are access-sensitive, so just pull the right
255
+ * byte out of the word read result.
256
+ */
257
+ r = extract32(r, (addr & 3) * 8, size * 8);
258
+ }
259
+
260
+ trace_iotkit_secctl_s_read(offset, r, size);
261
+ *pdata = r;
262
+ return MEMTX_OK;
263
+}
64
+}
264
+
65
+
265
+static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr,
66
/* Handle a write via the SYS_CFG channel to the specified function/device.
266
+ uint64_t value,
67
* Return false on error (reported to guest via SYS_CFGCTRL ERROR bit).
267
+ unsigned size, MemTxAttrs attrs)
68
*/
268
+{
69
@@ -XXX,XX +XXX,XX @@ static uint64_t mps2_scc_read(void *opaque, hwaddr offset, unsigned size)
269
+ uint32_t offset = addr;
70
case A_CFG1:
270
+
71
r = s->cfg1;
271
+ trace_iotkit_secctl_s_write(offset, value, size);
72
break;
272
+
73
+ case A_CFG2:
273
+ if (size != 4) {
74
+ if (scc_partno(s) != 0x524) {
274
+ /* Byte and halfword writes are ignored */
75
+ /* CFG2 reserved on other boards */
275
+ qemu_log_mask(LOG_GUEST_ERROR,
76
+ goto bad_offset;
276
+ "IotKit SecCtl S block write: bad size, ignored\n");
77
+ }
277
+ return MEMTX_OK;
78
+ r = s->cfg2;
278
+ }
279
+
280
+ switch (offset) {
281
+ case A_SECRESPCFG:
282
+ case A_NSCCFG:
283
+ case A_SECPPCINTCLR:
284
+ case A_SECPPCINTEN:
285
+ case A_SECMSCINTCLR:
286
+ case A_SECMSCINTEN:
287
+ case A_BRGINTCLR:
288
+ case A_BRGINTEN:
289
+ case A_AHBNSPPCEXP0:
290
+ case A_AHBNSPPCEXP1:
291
+ case A_AHBNSPPCEXP2:
292
+ case A_AHBNSPPCEXP3:
293
+ case A_APBNSPPC0:
294
+ case A_APBNSPPC1:
295
+ case A_APBNSPPCEXP0:
296
+ case A_APBNSPPCEXP1:
297
+ case A_APBNSPPCEXP2:
298
+ case A_APBNSPPCEXP3:
299
+ case A_AHBSPPPCEXP0:
300
+ case A_AHBSPPPCEXP1:
301
+ case A_AHBSPPPCEXP2:
302
+ case A_AHBSPPPCEXP3:
303
+ case A_APBSPPPC0:
304
+ case A_APBSPPPC1:
305
+ case A_APBSPPPCEXP0:
306
+ case A_APBSPPPCEXP1:
307
+ case A_APBSPPPCEXP2:
308
+ case A_APBSPPPCEXP3:
309
+ qemu_log_mask(LOG_UNIMP,
310
+ "IoTKit SecCtl S block write: "
311
+ "unimplemented offset 0x%x\n", offset);
312
+ break;
79
+ break;
313
+ case A_SECMPCINTSTATUS:
80
case A_CFG3:
314
+ case A_SECPPCINTSTAT:
81
+ if (scc_partno(s) == 0x524) {
315
+ case A_SECMSCINTSTAT:
82
+ /* CFG3 reserved on AN524 */
316
+ case A_BRGINTSTAT:
83
+ goto bad_offset;
317
+ case A_AHBNSPPC0:
84
+ }
318
+ case A_AHBSPPPC0:
85
/* These are user-settable DIP switches on the board. We don't
319
+ case A_NSMSCEXP:
86
* model that, so just return zeroes.
320
+ case A_PID4:
87
*/
321
+ case A_PID5:
88
@@ -XXX,XX +XXX,XX @@ static uint64_t mps2_scc_read(void *opaque, hwaddr offset, unsigned size)
322
+ case A_PID6:
89
case A_CFG4:
323
+ case A_PID7:
90
r = s->cfg4;
324
+ case A_PID0:
91
break;
325
+ case A_PID1:
92
+ case A_CFG5:
326
+ case A_PID2:
93
+ if (scc_partno(s) != 0x524) {
327
+ case A_PID3:
94
+ /* CFG5 reserved on other boards */
328
+ case A_CID0:
95
+ goto bad_offset;
329
+ case A_CID1:
96
+ }
330
+ case A_CID2:
97
+ r = s->cfg5;
331
+ case A_CID3:
332
+ qemu_log_mask(LOG_GUEST_ERROR,
333
+ "IoTKit SecCtl S block write: "
334
+ "read-only offset 0x%x\n", offset);
335
+ break;
98
+ break;
336
+ default:
99
+ case A_CFG6:
337
+ qemu_log_mask(LOG_GUEST_ERROR,
100
+ if (scc_partno(s) != 0x524) {
338
+ "IotKit SecCtl S block write: bad offset 0x%x\n",
101
+ /* CFG6 reserved on other boards */
339
+ offset);
102
+ goto bad_offset;
103
+ }
104
+ r = s->cfg6;
340
+ break;
105
+ break;
341
+ }
106
case A_CFGDATA_RTN:
342
+
107
r = s->cfgdata_rtn;
343
+ return MEMTX_OK;
108
break;
344
+}
109
@@ -XXX,XX +XXX,XX @@ static uint64_t mps2_scc_read(void *opaque, hwaddr offset, unsigned size)
345
+
110
r = s->id;
346
+static MemTxResult iotkit_secctl_ns_read(void *opaque, hwaddr addr,
111
break;
347
+ uint64_t *pdata,
112
default:
348
+ unsigned size, MemTxAttrs attrs)
113
+ bad_offset:
349
+{
114
qemu_log_mask(LOG_GUEST_ERROR,
350
+ uint64_t r;
115
"MPS2 SCC read: bad offset %x\n", (int) offset);
351
+ uint32_t offset = addr & ~0x3;
116
r = 0;
352
+
117
@@ -XXX,XX +XXX,XX @@ static void mps2_scc_write(void *opaque, hwaddr offset, uint64_t value,
353
+ switch (offset) {
118
led_set_state(s->led[i], extract32(value, i, 1));
354
+ case A_AHBNSPPPC0:
119
}
355
+ r = 0;
120
break;
121
+ case A_CFG2:
122
+ if (scc_partno(s) != 0x524) {
123
+ /* CFG2 reserved on other boards */
124
+ goto bad_offset;
125
+ }
126
+ /* AN524: QSPI Select signal */
127
+ s->cfg2 = value;
356
+ break;
128
+ break;
357
+ case A_AHBNSPPPCEXP0:
129
+ case A_CFG5:
358
+ case A_AHBNSPPPCEXP1:
130
+ if (scc_partno(s) != 0x524) {
359
+ case A_AHBNSPPPCEXP2:
131
+ /* CFG5 reserved on other boards */
360
+ case A_AHBNSPPPCEXP3:
132
+ goto bad_offset;
361
+ case A_APBNSPPPC0:
133
+ }
362
+ case A_APBNSPPPC1:
134
+ /* AN524: ACLK frequency in Hz */
363
+ case A_APBNSPPPCEXP0:
135
+ s->cfg5 = value;
364
+ case A_APBNSPPPCEXP1:
365
+ case A_APBNSPPPCEXP2:
366
+ case A_APBNSPPPCEXP3:
367
+ qemu_log_mask(LOG_UNIMP,
368
+ "IoTKit SecCtl NS block read: "
369
+ "unimplemented offset 0x%x\n", offset);
370
+ break;
136
+ break;
371
+ case A_PID4:
137
+ case A_CFG6:
372
+ case A_PID5:
138
+ if (scc_partno(s) != 0x524) {
373
+ case A_PID6:
139
+ /* CFG6 reserved on other boards */
374
+ case A_PID7:
140
+ goto bad_offset;
375
+ case A_PID0:
141
+ }
376
+ case A_PID1:
142
+ /* AN524: Clock divider for BRAM */
377
+ case A_PID2:
143
+ s->cfg6 = value;
378
+ case A_PID3:
379
+ case A_CID0:
380
+ case A_CID1:
381
+ case A_CID2:
382
+ case A_CID3:
383
+ r = iotkit_secctl_ns_idregs[(offset - A_PID4) / 4];
384
+ break;
144
+ break;
385
+ default:
145
case A_CFGDATA_OUT:
386
+ qemu_log_mask(LOG_GUEST_ERROR,
146
s->cfgdata_out = value;
387
+ "IotKit SecCtl NS block write: bad offset 0x%x\n",
147
break;
388
+ offset);
148
@@ -XXX,XX +XXX,XX @@ static void mps2_scc_write(void *opaque, hwaddr offset, uint64_t value,
389
+ r = 0;
149
s->dll = deposit32(s->dll, 24, 8, extract32(value, 24, 8));
390
+ break;
150
break;
391
+ }
151
default:
392
+
152
+ bad_offset:
393
+ if (size != 4) {
153
qemu_log_mask(LOG_GUEST_ERROR,
394
+ /* None of our registers are access-sensitive, so just pull the right
154
"MPS2 SCC write: bad offset 0x%x\n", (int) offset);
395
+ * byte out of the word read result.
155
break;
396
+ */
156
@@ -XXX,XX +XXX,XX @@ static void mps2_scc_reset(DeviceState *dev)
397
+ r = extract32(r, (addr & 3) * 8, size * 8);
157
trace_mps2_scc_reset();
398
+ }
158
s->cfg0 = 0;
399
+
159
s->cfg1 = 0;
400
+ trace_iotkit_secctl_ns_read(offset, r, size);
160
+ s->cfg2 = 0;
401
+ *pdata = r;
161
+ s->cfg5 = 0;
402
+ return MEMTX_OK;
162
+ s->cfg6 = 0;
403
+}
163
s->cfgdata_rtn = 0;
404
+
164
s->cfgdata_out = 0;
405
+static MemTxResult iotkit_secctl_ns_write(void *opaque, hwaddr addr,
165
s->cfgctrl = 0x100000;
406
+ uint64_t value,
166
@@ -XXX,XX +XXX,XX @@ static void mps2_scc_realize(DeviceState *dev, Error **errp)
407
+ unsigned size, MemTxAttrs attrs)
167
408
+{
168
static const VMStateDescription mps2_scc_vmstate = {
409
+ uint32_t offset = addr;
169
.name = "mps2-scc",
410
+
170
- .version_id = 2,
411
+ trace_iotkit_secctl_ns_write(offset, value, size);
171
- .minimum_version_id = 2,
412
+
172
+ .version_id = 3,
413
+ if (size != 4) {
173
+ .minimum_version_id = 3,
414
+ /* Byte and halfword writes are ignored */
174
.fields = (VMStateField[]) {
415
+ qemu_log_mask(LOG_GUEST_ERROR,
175
VMSTATE_UINT32(cfg0, MPS2SCC),
416
+ "IotKit SecCtl NS block write: bad size, ignored\n");
176
VMSTATE_UINT32(cfg1, MPS2SCC),
417
+ return MEMTX_OK;
177
+ VMSTATE_UINT32(cfg2, MPS2SCC),
418
+ }
178
+ /* cfg3, cfg4 are read-only so need not be migrated */
419
+
179
+ VMSTATE_UINT32(cfg5, MPS2SCC),
420
+ switch (offset) {
180
+ VMSTATE_UINT32(cfg6, MPS2SCC),
421
+ case A_AHBNSPPPCEXP0:
181
VMSTATE_UINT32(cfgdata_rtn, MPS2SCC),
422
+ case A_AHBNSPPPCEXP1:
182
VMSTATE_UINT32(cfgdata_out, MPS2SCC),
423
+ case A_AHBNSPPPCEXP2:
183
VMSTATE_UINT32(cfgctrl, MPS2SCC),
424
+ case A_AHBNSPPPCEXP3:
425
+ case A_APBNSPPPC0:
426
+ case A_APBNSPPPC1:
427
+ case A_APBNSPPPCEXP0:
428
+ case A_APBNSPPPCEXP1:
429
+ case A_APBNSPPPCEXP2:
430
+ case A_APBNSPPPCEXP3:
431
+ qemu_log_mask(LOG_UNIMP,
432
+ "IoTKit SecCtl NS block write: "
433
+ "unimplemented offset 0x%x\n", offset);
434
+ break;
435
+ case A_AHBNSPPPC0:
436
+ case A_PID4:
437
+ case A_PID5:
438
+ case A_PID6:
439
+ case A_PID7:
440
+ case A_PID0:
441
+ case A_PID1:
442
+ case A_PID2:
443
+ case A_PID3:
444
+ case A_CID0:
445
+ case A_CID1:
446
+ case A_CID2:
447
+ case A_CID3:
448
+ qemu_log_mask(LOG_GUEST_ERROR,
449
+ "IoTKit SecCtl NS block write: "
450
+ "read-only offset 0x%x\n", offset);
451
+ break;
452
+ default:
453
+ qemu_log_mask(LOG_GUEST_ERROR,
454
+ "IotKit SecCtl NS block write: bad offset 0x%x\n",
455
+ offset);
456
+ break;
457
+ }
458
+
459
+ return MEMTX_OK;
460
+}
461
+
462
+static const MemoryRegionOps iotkit_secctl_s_ops = {
463
+ .read_with_attrs = iotkit_secctl_s_read,
464
+ .write_with_attrs = iotkit_secctl_s_write,
465
+ .endianness = DEVICE_LITTLE_ENDIAN,
466
+ .valid.min_access_size = 1,
467
+ .valid.max_access_size = 4,
468
+ .impl.min_access_size = 1,
469
+ .impl.max_access_size = 4,
470
+};
471
+
472
+static const MemoryRegionOps iotkit_secctl_ns_ops = {
473
+ .read_with_attrs = iotkit_secctl_ns_read,
474
+ .write_with_attrs = iotkit_secctl_ns_write,
475
+ .endianness = DEVICE_LITTLE_ENDIAN,
476
+ .valid.min_access_size = 1,
477
+ .valid.max_access_size = 4,
478
+ .impl.min_access_size = 1,
479
+ .impl.max_access_size = 4,
480
+};
481
+
482
+static void iotkit_secctl_reset(DeviceState *dev)
483
+{
484
+
485
+}
486
+
487
+static void iotkit_secctl_init(Object *obj)
488
+{
489
+ IoTKitSecCtl *s = IOTKIT_SECCTL(obj);
490
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
491
+
492
+ memory_region_init_io(&s->s_regs, obj, &iotkit_secctl_s_ops,
493
+ s, "iotkit-secctl-s-regs", 0x1000);
494
+ memory_region_init_io(&s->ns_regs, obj, &iotkit_secctl_ns_ops,
495
+ s, "iotkit-secctl-ns-regs", 0x1000);
496
+ sysbus_init_mmio(sbd, &s->s_regs);
497
+ sysbus_init_mmio(sbd, &s->ns_regs);
498
+}
499
+
500
+static const VMStateDescription iotkit_secctl_vmstate = {
501
+ .name = "iotkit-secctl",
502
+ .version_id = 1,
503
+ .minimum_version_id = 1,
504
+ .fields = (VMStateField[]) {
505
+ VMSTATE_END_OF_LIST()
506
+ }
507
+};
508
+
509
+static void iotkit_secctl_class_init(ObjectClass *klass, void *data)
510
+{
511
+ DeviceClass *dc = DEVICE_CLASS(klass);
512
+
513
+ dc->vmsd = &iotkit_secctl_vmstate;
514
+ dc->reset = iotkit_secctl_reset;
515
+}
516
+
517
+static const TypeInfo iotkit_secctl_info = {
518
+ .name = TYPE_IOTKIT_SECCTL,
519
+ .parent = TYPE_SYS_BUS_DEVICE,
520
+ .instance_size = sizeof(IoTKitSecCtl),
521
+ .instance_init = iotkit_secctl_init,
522
+ .class_init = iotkit_secctl_class_init,
523
+};
524
+
525
+static void iotkit_secctl_register_types(void)
526
+{
527
+ type_register_static(&iotkit_secctl_info);
528
+}
529
+
530
+type_init(iotkit_secctl_register_types);
531
diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
532
index XXXXXXX..XXXXXXX 100644
533
--- a/default-configs/arm-softmmu.mak
534
+++ b/default-configs/arm-softmmu.mak
535
@@ -XXX,XX +XXX,XX @@ CONFIG_MPS2_FPGAIO=y
536
CONFIG_MPS2_SCC=y
537
538
CONFIG_TZ_PPC=y
539
+CONFIG_IOTKIT_SECCTL=y
540
541
CONFIG_VERSATILE_PCI=y
542
CONFIG_VERSATILE_I2C=y
543
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
544
index XXXXXXX..XXXXXXX 100644
545
--- a/hw/misc/trace-events
546
+++ b/hw/misc/trace-events
547
@@ -XXX,XX +XXX,XX @@ tz_ppc_irq_clear(int level) "TZ PPC: int_clear = %d"
548
tz_ppc_update_irq(int level) "TZ PPC: setting irq line to %d"
549
tz_ppc_read_blocked(int n, hwaddr offset, bool secure, bool user) "TZ PPC: port %d offset 0x%" HWADDR_PRIx " read (secure %d user %d) blocked"
550
tz_ppc_write_blocked(int n, hwaddr offset, bool secure, bool user) "TZ PPC: port %d offset 0x%" HWADDR_PRIx " write (secure %d user %d) blocked"
551
+
552
+# hw/misc/iotkit-secctl.c
553
+iotkit_secctl_s_read(uint32_t offset, uint64_t data, unsigned size) "IoTKit SecCtl S regs read: offset 0x%x data 0x%" PRIx64 " size %u"
554
+iotkit_secctl_s_write(uint32_t offset, uint64_t data, unsigned size) "IoTKit SecCtl S regs write: offset 0x%x data 0x%" PRIx64 " size %u"
555
+iotkit_secctl_ns_read(uint32_t offset, uint64_t data, unsigned size) "IoTKit SecCtl NS regs read: offset 0x%x data 0x%" PRIx64 " size %u"
556
+iotkit_secctl_ns_write(uint32_t offset, uint64_t data, unsigned size) "IoTKit SecCtl NS regs write: offset 0x%x data 0x%" PRIx64 " size %u"
557
+iotkit_secctl_reset(void) "IoTKit SecCtl: reset"
558
--
184
--
559
2.16.2
185
2.20.1
560
186
561
187
diff view generated by jsdifflib
New patch
1
On the MPS2 boards, the first 32 interrupt lines are entirely
2
internal to the SSE; interrupt lines for devices outside the SSE
3
start at 32. In the application notes that document each FPGA image,
4
the interrupt wiring is documented from the point of view of the CPU,
5
so '0' is the first of the SSE's interrupts and the devices in the
6
FPGA image itself are '32' and up: so the UART 0 Receive interrupt is
7
32, the SPI #0 interrupt is 51, and so on.
1
8
9
Within our implementation, because the external interrupts must be
10
connected to the EXP_IRQ[0...n] lines of the SSE object, we made the
11
get_sse_irq_in() function take an irqno whose values start at 0 for
12
the first FPGA device interrupt. In this numbering scheme the UART 0
13
Receive interrupt is 0, the SPI #0 interrupt is 19, and so on.
14
15
The result of these two different numbering schemes has been that
16
half of the devices were wired up to the wrong IRQs: the UART IRQs
17
are wired up correctly, but the DMA and SPI devices were passing
18
start-at-32 values to get_sse_irq_in() and so being mis-connected.
19
20
Fix the bug by making get_sse_irq_in() take values specified with the
21
same scheme that the hardware manuals use, to avoid confusion.
22
23
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
24
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
25
Message-id: 20210215115138.20465-12-peter.maydell@linaro.org
26
---
27
hw/arm/mps2-tz.c | 24 +++++++++++++++++-------
28
1 file changed, 17 insertions(+), 7 deletions(-)
29
30
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
31
index XXXXXXX..XXXXXXX 100644
32
--- a/hw/arm/mps2-tz.c
33
+++ b/hw/arm/mps2-tz.c
34
@@ -XXX,XX +XXX,XX @@ static void make_ram_alias(MemoryRegion *mr, const char *name,
35
36
static qemu_irq get_sse_irq_in(MPS2TZMachineState *mms, int irqno)
37
{
38
- /* Return a qemu_irq which will signal IRQ n to all CPUs in the SSE. */
39
+ /*
40
+ * Return a qemu_irq which will signal IRQ n to all CPUs in the
41
+ * SSE. The irqno should be as the CPU sees it, so the first
42
+ * external-to-the-SSE interrupt is 32.
43
+ */
44
MachineClass *mc = MACHINE_GET_CLASS(mms);
45
MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
46
47
- assert(irqno < mmc->numirq);
48
+ assert(irqno >= 32 && irqno < (mmc->numirq + 32));
49
+
50
+ /*
51
+ * Convert from "CPU irq number" (as listed in the FPGA image
52
+ * documentation) to the SSE external-interrupt number.
53
+ */
54
+ irqno -= 32;
55
56
if (mc->max_cpus > 1) {
57
return qdev_get_gpio_in(DEVICE(&mms->cpu_irq_splitter[irqno]), 0);
58
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
59
MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
60
CMSDKAPBUART *uart = opaque;
61
int i = uart - &mms->uart[0];
62
- int rxirqno = i * 2;
63
- int txirqno = i * 2 + 1;
64
- int combirqno = i + 10;
65
+ int rxirqno = i * 2 + 32;
66
+ int txirqno = i * 2 + 33;
67
+ int combirqno = i + 42;
68
SysBusDevice *s;
69
DeviceState *orgate_dev = DEVICE(&mms->uart_irq_orgate);
70
71
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_eth_dev(MPS2TZMachineState *mms, void *opaque,
72
73
s = SYS_BUS_DEVICE(mms->lan9118);
74
sysbus_realize_and_unref(s, &error_fatal);
75
- sysbus_connect_irq(s, 0, get_sse_irq_in(mms, 16));
76
+ sysbus_connect_irq(s, 0, get_sse_irq_in(mms, 48));
77
return sysbus_mmio_get_region(s, 0);
78
}
79
80
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
81
&error_fatal);
82
qdev_realize(DEVICE(&mms->uart_irq_orgate), NULL, &error_fatal);
83
qdev_connect_gpio_out(DEVICE(&mms->uart_irq_orgate), 0,
84
- get_sse_irq_in(mms, 15));
85
+ get_sse_irq_in(mms, 47));
86
87
/* Most of the devices in the FPGA are behind Peripheral Protection
88
* Controllers. The required order for initializing things is:
89
--
90
2.20.1
91
92
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
The mps2-tz code uses PPCPortInfo data structures to define what
2
devices are present and how they are wired up. Currently we use
3
these to specify device types and addresses, but hard-code the
4
interrupt line wiring in each make_* helper function. This works for
5
the two boards we have at the moment, but the AN524 has some devices
6
with different interrupt assignments.
2
7
3
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
This commit adds the framework to allow PPCPortInfo structures to
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
9
specify interrupt numbers. We add an array of interrupt numbers to
5
Message-id: 20180228193125.20577-6-richard.henderson@linaro.org
10
the PPCPortInfo struct, and pass it through to the make_* helpers.
11
The following commit will change the make_* helpers over to using the
12
framework.
13
6
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: 20210215115138.20465-13-peter.maydell@linaro.org
7
---
17
---
8
target/arm/helper.h | 9 +++++
18
hw/arm/mps2-tz.c | 36 ++++++++++++++++++++++++------------
9
target/arm/translate-a64.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++
19
1 file changed, 24 insertions(+), 12 deletions(-)
10
target/arm/vec_helper.c | 74 +++++++++++++++++++++++++++++++++++++++++
11
3 files changed, 166 insertions(+)
12
20
13
diff --git a/target/arm/helper.h b/target/arm/helper.h
21
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
14
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
15
--- a/target/arm/helper.h
23
--- a/hw/arm/mps2-tz.c
16
+++ b/target/arm/helper.h
24
+++ b/hw/arm/mps2-tz.c
17
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_2(dc_zva, void, env, i64)
25
@@ -XXX,XX +XXX,XX @@ static qemu_irq get_sse_irq_in(MPS2TZMachineState *mms, int irqno)
18
DEF_HELPER_FLAGS_2(neon_pmull_64_lo, TCG_CALL_NO_RWG_SE, i64, i64, i64)
26
* needs to be plugged into the downstream end of the PPC port.
19
DEF_HELPER_FLAGS_2(neon_pmull_64_hi, TCG_CALL_NO_RWG_SE, i64, i64, i64)
27
*/
20
28
typedef MemoryRegion *MakeDevFn(MPS2TZMachineState *mms, void *opaque,
21
+DEF_HELPER_FLAGS_5(gvec_qrdmlah_s16, TCG_CALL_NO_RWG,
29
- const char *name, hwaddr size);
22
+ void, ptr, ptr, ptr, ptr, i32)
30
+ const char *name, hwaddr size,
23
+DEF_HELPER_FLAGS_5(gvec_qrdmlsh_s16, TCG_CALL_NO_RWG,
31
+ const int *irqs);
24
+ void, ptr, ptr, ptr, ptr, i32)
32
25
+DEF_HELPER_FLAGS_5(gvec_qrdmlah_s32, TCG_CALL_NO_RWG,
33
typedef struct PPCPortInfo {
26
+ void, ptr, ptr, ptr, ptr, i32)
34
const char *name;
27
+DEF_HELPER_FLAGS_5(gvec_qrdmlsh_s32, TCG_CALL_NO_RWG,
35
@@ -XXX,XX +XXX,XX @@ typedef struct PPCPortInfo {
28
+ void, ptr, ptr, ptr, ptr, i32)
36
void *opaque;
29
+
37
hwaddr addr;
30
#ifdef TARGET_AARCH64
38
hwaddr size;
31
#include "helper-a64.h"
39
+ int irqs[3]; /* currently no device needs more IRQ lines than this */
32
#endif
40
} PPCPortInfo;
33
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
41
34
index XXXXXXX..XXXXXXX 100644
42
typedef struct PPCInfo {
35
--- a/target/arm/translate-a64.c
43
@@ -XXX,XX +XXX,XX @@ typedef struct PPCInfo {
36
+++ b/target/arm/translate-a64.c
44
} PPCInfo;
37
@@ -XXX,XX +XXX,XX @@ static void gen_gvec_op3(DisasContext *s, bool is_q, int rd,
45
38
vec_full_reg_size(s), gvec_op);
46
static MemoryRegion *make_unimp_dev(MPS2TZMachineState *mms,
47
- void *opaque,
48
- const char *name, hwaddr size)
49
+ void *opaque,
50
+ const char *name, hwaddr size,
51
+ const int *irqs)
52
{
53
/* Initialize, configure and realize a TYPE_UNIMPLEMENTED_DEVICE,
54
* and return a pointer to its MemoryRegion.
55
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_unimp_dev(MPS2TZMachineState *mms,
39
}
56
}
40
57
41
+/* Expand a 3-operand + env pointer operation using
58
static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
42
+ * an out-of-line helper.
59
- const char *name, hwaddr size)
43
+ */
60
+ const char *name, hwaddr size,
44
+static void gen_gvec_op3_env(DisasContext *s, bool is_q, int rd,
61
+ const int *irqs)
45
+ int rn, int rm, gen_helper_gvec_3_ptr *fn)
62
{
46
+{
63
MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
47
+ tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, rd),
64
CMSDKAPBUART *uart = opaque;
48
+ vec_full_reg_offset(s, rn),
65
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
49
+ vec_full_reg_offset(s, rm), cpu_env,
50
+ is_q ? 16 : 8, vec_full_reg_size(s), 0, fn);
51
+}
52
+
53
/* Set ZF and NF based on a 64 bit result. This is alas fiddlier
54
* than the 32 bit equivalent.
55
*/
56
@@ -XXX,XX +XXX,XX @@ static void disas_simd_three_reg_same_fp16(DisasContext *s, uint32_t insn)
57
clear_vec_high(s, is_q, rd);
58
}
66
}
59
67
60
+/* AdvSIMD three same extra
68
static MemoryRegion *make_scc(MPS2TZMachineState *mms, void *opaque,
61
+ * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
69
- const char *name, hwaddr size)
62
+ * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
70
+ const char *name, hwaddr size,
63
+ * | 0 | Q | U | 0 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
71
+ const int *irqs)
64
+ * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
65
+ */
66
+static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn)
67
+{
68
+ int rd = extract32(insn, 0, 5);
69
+ int rn = extract32(insn, 5, 5);
70
+ int opcode = extract32(insn, 11, 4);
71
+ int rm = extract32(insn, 16, 5);
72
+ int size = extract32(insn, 22, 2);
73
+ bool u = extract32(insn, 29, 1);
74
+ bool is_q = extract32(insn, 30, 1);
75
+ int feature;
76
+
77
+ switch (u * 16 + opcode) {
78
+ case 0x10: /* SQRDMLAH (vector) */
79
+ case 0x11: /* SQRDMLSH (vector) */
80
+ if (size != 1 && size != 2) {
81
+ unallocated_encoding(s);
82
+ return;
83
+ }
84
+ feature = ARM_FEATURE_V8_RDM;
85
+ break;
86
+ default:
87
+ unallocated_encoding(s);
88
+ return;
89
+ }
90
+ if (!arm_dc_feature(s, feature)) {
91
+ unallocated_encoding(s);
92
+ return;
93
+ }
94
+ if (!fp_access_check(s)) {
95
+ return;
96
+ }
97
+
98
+ switch (opcode) {
99
+ case 0x0: /* SQRDMLAH (vector) */
100
+ switch (size) {
101
+ case 1:
102
+ gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlah_s16);
103
+ break;
104
+ case 2:
105
+ gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlah_s32);
106
+ break;
107
+ default:
108
+ g_assert_not_reached();
109
+ }
110
+ return;
111
+
112
+ case 0x1: /* SQRDMLSH (vector) */
113
+ switch (size) {
114
+ case 1:
115
+ gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlsh_s16);
116
+ break;
117
+ case 2:
118
+ gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlsh_s32);
119
+ break;
120
+ default:
121
+ g_assert_not_reached();
122
+ }
123
+ return;
124
+
125
+ default:
126
+ g_assert_not_reached();
127
+ }
128
+}
129
+
130
static void handle_2misc_widening(DisasContext *s, int opcode, bool is_q,
131
int size, int rn, int rd)
132
{
72
{
133
@@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_imm2(DisasContext *s, uint32_t insn)
73
MPS2SCC *scc = opaque;
134
static const AArch64DecodeTable data_proc_simd[] = {
74
DeviceState *sccdev;
135
/* pattern , mask , fn */
75
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_scc(MPS2TZMachineState *mms, void *opaque,
136
{ 0x0e200400, 0x9f200400, disas_simd_three_reg_same },
137
+ { 0x0e008400, 0x9f208400, disas_simd_three_reg_same_extra },
138
{ 0x0e200000, 0x9f200c00, disas_simd_three_reg_diff },
139
{ 0x0e200800, 0x9f3e0c00, disas_simd_two_reg_misc },
140
{ 0x0e300800, 0x9f3e0c00, disas_simd_across_lanes },
141
diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c
142
index XXXXXXX..XXXXXXX 100644
143
--- a/target/arm/vec_helper.c
144
+++ b/target/arm/vec_helper.c
145
@@ -XXX,XX +XXX,XX @@
146
147
#define SET_QC() env->vfp.xregs[ARM_VFP_FPSCR] |= CPSR_Q
148
149
+static void clear_tail(void *vd, uintptr_t opr_sz, uintptr_t max_sz)
150
+{
151
+ uint64_t *d = vd + opr_sz;
152
+ uintptr_t i;
153
+
154
+ for (i = opr_sz; i < max_sz; i += 8) {
155
+ *d++ = 0;
156
+ }
157
+}
158
+
159
/* Signed saturating rounding doubling multiply-accumulate high half, 16-bit */
160
static uint16_t inl_qrdmlah_s16(CPUARMState *env, int16_t src1,
161
int16_t src2, int16_t src3)
162
@@ -XXX,XX +XXX,XX @@ uint32_t HELPER(neon_qrdmlah_s16)(CPUARMState *env, uint32_t src1,
163
return deposit32(e1, 16, 16, e2);
164
}
76
}
165
77
166
+void HELPER(gvec_qrdmlah_s16)(void *vd, void *vn, void *vm,
78
static MemoryRegion *make_fpgaio(MPS2TZMachineState *mms, void *opaque,
167
+ void *ve, uint32_t desc)
79
- const char *name, hwaddr size)
168
+{
80
+ const char *name, hwaddr size,
169
+ uintptr_t opr_sz = simd_oprsz(desc);
81
+ const int *irqs)
170
+ int16_t *d = vd;
82
{
171
+ int16_t *n = vn;
83
MPS2FPGAIO *fpgaio = opaque;
172
+ int16_t *m = vm;
84
MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
173
+ CPUARMState *env = ve;
85
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_fpgaio(MPS2TZMachineState *mms, void *opaque,
174
+ uintptr_t i;
175
+
176
+ for (i = 0; i < opr_sz / 2; ++i) {
177
+ d[i] = inl_qrdmlah_s16(env, n[i], m[i], d[i]);
178
+ }
179
+ clear_tail(d, opr_sz, simd_maxsz(desc));
180
+}
181
+
182
/* Signed saturating rounding doubling multiply-subtract high half, 16-bit */
183
static uint16_t inl_qrdmlsh_s16(CPUARMState *env, int16_t src1,
184
int16_t src2, int16_t src3)
185
@@ -XXX,XX +XXX,XX @@ uint32_t HELPER(neon_qrdmlsh_s16)(CPUARMState *env, uint32_t src1,
186
return deposit32(e1, 16, 16, e2);
187
}
86
}
188
87
189
+void HELPER(gvec_qrdmlsh_s16)(void *vd, void *vn, void *vm,
88
static MemoryRegion *make_eth_dev(MPS2TZMachineState *mms, void *opaque,
190
+ void *ve, uint32_t desc)
89
- const char *name, hwaddr size)
191
+{
90
+ const char *name, hwaddr size,
192
+ uintptr_t opr_sz = simd_oprsz(desc);
91
+ const int *irqs)
193
+ int16_t *d = vd;
92
{
194
+ int16_t *n = vn;
93
SysBusDevice *s;
195
+ int16_t *m = vm;
94
NICInfo *nd = &nd_table[0];
196
+ CPUARMState *env = ve;
95
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_eth_dev(MPS2TZMachineState *mms, void *opaque,
197
+ uintptr_t i;
198
+
199
+ for (i = 0; i < opr_sz / 2; ++i) {
200
+ d[i] = inl_qrdmlsh_s16(env, n[i], m[i], d[i]);
201
+ }
202
+ clear_tail(d, opr_sz, simd_maxsz(desc));
203
+}
204
+
205
/* Signed saturating rounding doubling multiply-accumulate high half, 32-bit */
206
uint32_t HELPER(neon_qrdmlah_s32)(CPUARMState *env, int32_t src1,
207
int32_t src2, int32_t src3)
208
@@ -XXX,XX +XXX,XX @@ uint32_t HELPER(neon_qrdmlah_s32)(CPUARMState *env, int32_t src1,
209
return ret;
210
}
96
}
211
97
212
+void HELPER(gvec_qrdmlah_s32)(void *vd, void *vn, void *vm,
98
static MemoryRegion *make_mpc(MPS2TZMachineState *mms, void *opaque,
213
+ void *ve, uint32_t desc)
99
- const char *name, hwaddr size)
214
+{
100
+ const char *name, hwaddr size,
215
+ uintptr_t opr_sz = simd_oprsz(desc);
101
+ const int *irqs)
216
+ int32_t *d = vd;
102
{
217
+ int32_t *n = vn;
103
TZMPC *mpc = opaque;
218
+ int32_t *m = vm;
104
int i = mpc - &mms->ssram_mpc[0];
219
+ CPUARMState *env = ve;
105
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_mpc(MPS2TZMachineState *mms, void *opaque,
220
+ uintptr_t i;
221
+
222
+ for (i = 0; i < opr_sz / 4; ++i) {
223
+ d[i] = helper_neon_qrdmlah_s32(env, n[i], m[i], d[i]);
224
+ }
225
+ clear_tail(d, opr_sz, simd_maxsz(desc));
226
+}
227
+
228
/* Signed saturating rounding doubling multiply-subtract high half, 32-bit */
229
uint32_t HELPER(neon_qrdmlsh_s32)(CPUARMState *env, int32_t src1,
230
int32_t src2, int32_t src3)
231
@@ -XXX,XX +XXX,XX @@ uint32_t HELPER(neon_qrdmlsh_s32)(CPUARMState *env, int32_t src1,
232
}
233
return ret;
234
}
106
}
235
+
107
236
+void HELPER(gvec_qrdmlsh_s32)(void *vd, void *vn, void *vm,
108
static MemoryRegion *make_dma(MPS2TZMachineState *mms, void *opaque,
237
+ void *ve, uint32_t desc)
109
- const char *name, hwaddr size)
238
+{
110
+ const char *name, hwaddr size,
239
+ uintptr_t opr_sz = simd_oprsz(desc);
111
+ const int *irqs)
240
+ int32_t *d = vd;
112
{
241
+ int32_t *n = vn;
113
PL080State *dma = opaque;
242
+ int32_t *m = vm;
114
int i = dma - &mms->dma[0];
243
+ CPUARMState *env = ve;
115
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_dma(MPS2TZMachineState *mms, void *opaque,
244
+ uintptr_t i;
116
}
245
+
117
246
+ for (i = 0; i < opr_sz / 4; ++i) {
118
static MemoryRegion *make_spi(MPS2TZMachineState *mms, void *opaque,
247
+ d[i] = helper_neon_qrdmlsh_s32(env, n[i], m[i], d[i]);
119
- const char *name, hwaddr size)
248
+ }
120
+ const char *name, hwaddr size,
249
+ clear_tail(d, opr_sz, simd_maxsz(desc));
121
+ const int *irqs)
250
+}
122
{
123
/*
124
* The AN505 has five PL022 SPI controllers.
125
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_spi(MPS2TZMachineState *mms, void *opaque,
126
}
127
128
static MemoryRegion *make_i2c(MPS2TZMachineState *mms, void *opaque,
129
- const char *name, hwaddr size)
130
+ const char *name, hwaddr size,
131
+ const int *irqs)
132
{
133
ArmSbconI2CState *i2c = opaque;
134
SysBusDevice *s;
135
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
136
continue;
137
}
138
139
- mr = pinfo->devfn(mms, pinfo->opaque, pinfo->name, pinfo->size);
140
+ mr = pinfo->devfn(mms, pinfo->opaque, pinfo->name, pinfo->size,
141
+ pinfo->irqs);
142
portname = g_strdup_printf("port[%d]", port);
143
object_property_set_link(OBJECT(ppc), portname, OBJECT(mr),
144
&error_fatal);
251
--
145
--
252
2.16.2
146
2.20.1
253
147
254
148
diff view generated by jsdifflib
1
From: Alistair Francis <alistair.francis@xilinx.com>
1
Move the specification of the IRQ information for the uart, ethernet,
2
dma and spi devices to the data structures. (The other devices
3
handled by the PPCPortInfo structures don't have any interrupt lines
4
we need to wire up.)
2
5
3
Allow the guest to determine the time set from the QEMU command line.
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20210215115138.20465-14-peter.maydell@linaro.org
9
---
10
hw/arm/mps2-tz.c | 52 +++++++++++++++++++++++-------------------------
11
1 file changed, 25 insertions(+), 27 deletions(-)
4
12
5
This includes adding a trace event to debug the new time.
13
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
6
7
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
12
include/hw/timer/xlnx-zynqmp-rtc.h | 2 ++
13
hw/timer/xlnx-zynqmp-rtc.c | 58 ++++++++++++++++++++++++++++++++++++++
14
hw/timer/trace-events | 3 ++
15
3 files changed, 63 insertions(+)
16
17
diff --git a/include/hw/timer/xlnx-zynqmp-rtc.h b/include/hw/timer/xlnx-zynqmp-rtc.h
18
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
19
--- a/include/hw/timer/xlnx-zynqmp-rtc.h
15
--- a/hw/arm/mps2-tz.c
20
+++ b/include/hw/timer/xlnx-zynqmp-rtc.h
16
+++ b/hw/arm/mps2-tz.c
21
@@ -XXX,XX +XXX,XX @@ typedef struct XlnxZynqMPRTC {
17
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
22
qemu_irq irq_rtc_int;
18
const char *name, hwaddr size,
23
qemu_irq irq_addr_error_int;
19
const int *irqs)
24
20
{
25
+ uint32_t tick_offset;
21
+ /* The irq[] array is tx, rx, combined, in that order */
26
+
22
MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
27
uint32_t regs[XLNX_ZYNQMP_RTC_R_MAX];
23
CMSDKAPBUART *uart = opaque;
28
RegisterInfo regs_info[XLNX_ZYNQMP_RTC_R_MAX];
24
int i = uart - &mms->uart[0];
29
} XlnxZynqMPRTC;
25
- int rxirqno = i * 2 + 32;
30
diff --git a/hw/timer/xlnx-zynqmp-rtc.c b/hw/timer/xlnx-zynqmp-rtc.c
26
- int txirqno = i * 2 + 33;
31
index XXXXXXX..XXXXXXX 100644
27
- int combirqno = i + 42;
32
--- a/hw/timer/xlnx-zynqmp-rtc.c
28
SysBusDevice *s;
33
+++ b/hw/timer/xlnx-zynqmp-rtc.c
29
DeviceState *orgate_dev = DEVICE(&mms->uart_irq_orgate);
34
@@ -XXX,XX +XXX,XX @@
30
35
#include "hw/register.h"
31
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
36
#include "qemu/bitops.h"
32
qdev_prop_set_uint32(DEVICE(uart), "pclk-frq", mmc->sysclk_frq);
37
#include "qemu/log.h"
33
sysbus_realize(SYS_BUS_DEVICE(uart), &error_fatal);
38
+#include "hw/ptimer.h"
34
s = SYS_BUS_DEVICE(uart);
39
+#include "qemu/cutils.h"
35
- sysbus_connect_irq(s, 0, get_sse_irq_in(mms, txirqno));
40
+#include "sysemu/sysemu.h"
36
- sysbus_connect_irq(s, 1, get_sse_irq_in(mms, rxirqno));
41
+#include "trace.h"
37
+ sysbus_connect_irq(s, 0, get_sse_irq_in(mms, irqs[0]));
42
#include "hw/timer/xlnx-zynqmp-rtc.h"
38
+ sysbus_connect_irq(s, 1, get_sse_irq_in(mms, irqs[1]));
43
39
sysbus_connect_irq(s, 2, qdev_get_gpio_in(orgate_dev, i * 2));
44
#ifndef XLNX_ZYNQMP_RTC_ERR_DEBUG
40
sysbus_connect_irq(s, 3, qdev_get_gpio_in(orgate_dev, i * 2 + 1));
45
@@ -XXX,XX +XXX,XX @@ static void addr_error_int_update_irq(XlnxZynqMPRTC *s)
41
- sysbus_connect_irq(s, 4, get_sse_irq_in(mms, combirqno));
46
qemu_set_irq(s->irq_addr_error_int, pending);
42
+ sysbus_connect_irq(s, 4, get_sse_irq_in(mms, irqs[2]));
43
return sysbus_mmio_get_region(SYS_BUS_DEVICE(uart), 0);
47
}
44
}
48
45
49
+static uint32_t rtc_get_count(XlnxZynqMPRTC *s)
46
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_eth_dev(MPS2TZMachineState *mms, void *opaque,
50
+{
47
51
+ int64_t now = qemu_clock_get_ns(rtc_clock);
48
s = SYS_BUS_DEVICE(mms->lan9118);
52
+ return s->tick_offset + now / NANOSECONDS_PER_SECOND;
49
sysbus_realize_and_unref(s, &error_fatal);
53
+}
50
- sysbus_connect_irq(s, 0, get_sse_irq_in(mms, 48));
54
+
51
+ sysbus_connect_irq(s, 0, get_sse_irq_in(mms, irqs[0]));
55
+static uint64_t current_time_postr(RegisterInfo *reg, uint64_t val64)
52
return sysbus_mmio_get_region(s, 0);
56
+{
53
}
57
+ XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(reg->opaque);
54
58
+
55
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_dma(MPS2TZMachineState *mms, void *opaque,
59
+ return rtc_get_count(s);
56
const char *name, hwaddr size,
60
+}
57
const int *irqs)
61
+
62
static void rtc_int_status_postw(RegisterInfo *reg, uint64_t val64)
63
{
58
{
64
XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(reg->opaque);
59
+ /* The irq[] array is DMACINTR, DMACINTERR, DMACINTTC, in that order */
65
@@ -XXX,XX +XXX,XX @@ static uint64_t addr_error_int_dis_prew(RegisterInfo *reg, uint64_t val64)
60
PL080State *dma = opaque;
66
61
int i = dma - &mms->dma[0];
67
static const RegisterAccessInfo rtc_regs_info[] = {
62
SysBusDevice *s;
68
{ .name = "SET_TIME_WRITE", .addr = A_SET_TIME_WRITE,
63
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_dma(MPS2TZMachineState *mms, void *opaque,
69
+ .unimp = MAKE_64BIT_MASK(0, 32),
64
70
},{ .name = "SET_TIME_READ", .addr = A_SET_TIME_READ,
65
s = SYS_BUS_DEVICE(dma);
71
.ro = 0xffffffff,
66
/* Wire up DMACINTR, DMACINTERR, DMACINTTC */
72
+ .post_read = current_time_postr,
67
- sysbus_connect_irq(s, 0, get_sse_irq_in(mms, 58 + i * 3));
73
},{ .name = "CALIB_WRITE", .addr = A_CALIB_WRITE,
68
- sysbus_connect_irq(s, 1, get_sse_irq_in(mms, 56 + i * 3));
74
+ .unimp = MAKE_64BIT_MASK(0, 32),
69
- sysbus_connect_irq(s, 2, get_sse_irq_in(mms, 57 + i * 3));
75
},{ .name = "CALIB_READ", .addr = A_CALIB_READ,
70
+ sysbus_connect_irq(s, 0, get_sse_irq_in(mms, irqs[0]));
76
.ro = 0x1fffff,
71
+ sysbus_connect_irq(s, 1, get_sse_irq_in(mms, irqs[1]));
77
},{ .name = "CURRENT_TIME", .addr = A_CURRENT_TIME,
72
+ sysbus_connect_irq(s, 2, get_sse_irq_in(mms, irqs[2]));
78
.ro = 0xffffffff,
73
79
+ .post_read = current_time_postr,
74
g_free(mscname);
80
},{ .name = "CURRENT_TICK", .addr = A_CURRENT_TICK,
75
return sysbus_mmio_get_region(s, 0);
81
.ro = 0xffff,
76
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_spi(MPS2TZMachineState *mms, void *opaque,
82
},{ .name = "ALARM", .addr = A_ALARM,
77
* lines are set via the "MISC" register in the MPS2 FPGAIO device.
83
@@ -XXX,XX +XXX,XX @@ static void rtc_init(Object *obj)
78
*/
84
XlnxZynqMPRTC *s = XLNX_ZYNQMP_RTC(obj);
79
PL022State *spi = opaque;
85
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
80
- int i = spi - &mms->spi[0];
86
RegisterInfoArray *reg_array;
81
SysBusDevice *s;
87
+ struct tm current_tm;
82
88
83
object_initialize_child(OBJECT(mms), name, spi, TYPE_PL022);
89
memory_region_init(&s->iomem, obj, TYPE_XLNX_ZYNQMP_RTC,
84
sysbus_realize(SYS_BUS_DEVICE(spi), &error_fatal);
90
XLNX_ZYNQMP_RTC_R_MAX * 4);
85
s = SYS_BUS_DEVICE(spi);
91
@@ -XXX,XX +XXX,XX @@ static void rtc_init(Object *obj)
86
- sysbus_connect_irq(s, 0, get_sse_irq_in(mms, 51 + i));
92
sysbus_init_mmio(sbd, &s->iomem);
87
+ sysbus_connect_irq(s, 0, get_sse_irq_in(mms, irqs[0]));
93
sysbus_init_irq(sbd, &s->irq_rtc_int);
88
return sysbus_mmio_get_region(s, 0);
94
sysbus_init_irq(sbd, &s->irq_addr_error_int);
95
+
96
+ qemu_get_timedate(&current_tm, 0);
97
+ s->tick_offset = mktimegm(&current_tm) -
98
+ qemu_clock_get_ns(rtc_clock) / NANOSECONDS_PER_SECOND;
99
+
100
+ trace_xlnx_zynqmp_rtc_gettime(current_tm.tm_year, current_tm.tm_mon,
101
+ current_tm.tm_mday, current_tm.tm_hour,
102
+ current_tm.tm_min, current_tm.tm_sec);
103
+}
104
+
105
+static int rtc_pre_save(void *opaque)
106
+{
107
+ XlnxZynqMPRTC *s = opaque;
108
+ int64_t now = qemu_clock_get_ns(rtc_clock) / NANOSECONDS_PER_SECOND;
109
+
110
+ /* Add the time at migration */
111
+ s->tick_offset = s->tick_offset + now;
112
+
113
+ return 0;
114
+}
115
+
116
+static int rtc_post_load(void *opaque, int version_id)
117
+{
118
+ XlnxZynqMPRTC *s = opaque;
119
+ int64_t now = qemu_clock_get_ns(rtc_clock) / NANOSECONDS_PER_SECOND;
120
+
121
+ /* Subtract the time after migration. This combined with the pre_save
122
+ * action results in us having subtracted the time that the guest was
123
+ * stopped to the offset.
124
+ */
125
+ s->tick_offset = s->tick_offset - now;
126
+
127
+ return 0;
128
}
89
}
129
90
130
static const VMStateDescription vmstate_rtc = {
91
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
131
.name = TYPE_XLNX_ZYNQMP_RTC,
92
}, {
132
.version_id = 1,
93
.name = "apb_ppcexp1",
133
.minimum_version_id = 1,
94
.ports = {
134
+ .pre_save = rtc_pre_save,
95
- { "spi0", make_spi, &mms->spi[0], 0x40205000, 0x1000 },
135
+ .post_load = rtc_post_load,
96
- { "spi1", make_spi, &mms->spi[1], 0x40206000, 0x1000 },
136
.fields = (VMStateField[]) {
97
- { "spi2", make_spi, &mms->spi[2], 0x40209000, 0x1000 },
137
VMSTATE_UINT32_ARRAY(regs, XlnxZynqMPRTC, XLNX_ZYNQMP_RTC_R_MAX),
98
- { "spi3", make_spi, &mms->spi[3], 0x4020a000, 0x1000 },
138
+ VMSTATE_UINT32(tick_offset, XlnxZynqMPRTC),
99
- { "spi4", make_spi, &mms->spi[4], 0x4020b000, 0x1000 },
139
VMSTATE_END_OF_LIST(),
100
- { "uart0", make_uart, &mms->uart[0], 0x40200000, 0x1000 },
140
}
101
- { "uart1", make_uart, &mms->uart[1], 0x40201000, 0x1000 },
141
};
102
- { "uart2", make_uart, &mms->uart[2], 0x40202000, 0x1000 },
142
diff --git a/hw/timer/trace-events b/hw/timer/trace-events
103
- { "uart3", make_uart, &mms->uart[3], 0x40203000, 0x1000 },
143
index XXXXXXX..XXXXXXX 100644
104
- { "uart4", make_uart, &mms->uart[4], 0x40204000, 0x1000 },
144
--- a/hw/timer/trace-events
105
+ { "spi0", make_spi, &mms->spi[0], 0x40205000, 0x1000, { 51 } },
145
+++ b/hw/timer/trace-events
106
+ { "spi1", make_spi, &mms->spi[1], 0x40206000, 0x1000, { 52 } },
146
@@ -XXX,XX +XXX,XX @@ systick_write(uint64_t addr, uint32_t value, unsigned size) "systick write addr
107
+ { "spi2", make_spi, &mms->spi[2], 0x40209000, 0x1000, { 53 } },
147
cmsdk_apb_timer_read(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB timer read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
108
+ { "spi3", make_spi, &mms->spi[3], 0x4020a000, 0x1000, { 54 } },
148
cmsdk_apb_timer_write(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB timer write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
109
+ { "spi4", make_spi, &mms->spi[4], 0x4020b000, 0x1000, { 55 } },
149
cmsdk_apb_timer_reset(void) "CMSDK APB timer: reset"
110
+ { "uart0", make_uart, &mms->uart[0], 0x40200000, 0x1000, { 32, 33, 42 } },
150
+
111
+ { "uart1", make_uart, &mms->uart[1], 0x40201000, 0x1000, { 34, 35, 43 } },
151
+# hw/timer/xlnx-zynqmp-rtc.c
112
+ { "uart2", make_uart, &mms->uart[2], 0x40202000, 0x1000, { 36, 37, 44 } },
152
+xlnx_zynqmp_rtc_gettime(int year, int month, int day, int hour, int min, int sec) "Get time from host: %d-%d-%d %2d:%02d:%02d"
113
+ { "uart3", make_uart, &mms->uart[3], 0x40203000, 0x1000, { 38, 39, 45 } },
114
+ { "uart4", make_uart, &mms->uart[4], 0x40204000, 0x1000, { 40, 41, 46 } },
115
{ "i2c0", make_i2c, &mms->i2c[0], 0x40207000, 0x1000 },
116
{ "i2c1", make_i2c, &mms->i2c[1], 0x40208000, 0x1000 },
117
{ "i2c2", make_i2c, &mms->i2c[2], 0x4020c000, 0x1000 },
118
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
119
{ "gpio1", make_unimp_dev, &mms->gpio[1], 0x40101000, 0x1000 },
120
{ "gpio2", make_unimp_dev, &mms->gpio[2], 0x40102000, 0x1000 },
121
{ "gpio3", make_unimp_dev, &mms->gpio[3], 0x40103000, 0x1000 },
122
- { "eth", make_eth_dev, NULL, 0x42000000, 0x100000 },
123
+ { "eth", make_eth_dev, NULL, 0x42000000, 0x100000, { 48 } },
124
},
125
}, {
126
.name = "ahb_ppcexp1",
127
.ports = {
128
- { "dma0", make_dma, &mms->dma[0], 0x40110000, 0x1000 },
129
- { "dma1", make_dma, &mms->dma[1], 0x40111000, 0x1000 },
130
- { "dma2", make_dma, &mms->dma[2], 0x40112000, 0x1000 },
131
- { "dma3", make_dma, &mms->dma[3], 0x40113000, 0x1000 },
132
+ { "dma0", make_dma, &mms->dma[0], 0x40110000, 0x1000, { 58, 56, 57 } },
133
+ { "dma1", make_dma, &mms->dma[1], 0x40111000, 0x1000, { 61, 59, 60 } },
134
+ { "dma2", make_dma, &mms->dma[2], 0x40112000, 0x1000, { 64, 62, 63 } },
135
+ { "dma3", make_dma, &mms->dma[3], 0x40113000, 0x1000, { 67, 65, 66 } },
136
},
137
},
138
};
153
--
139
--
154
2.16.2
140
2.20.1
155
141
156
142
diff view generated by jsdifflib
1
In some board or SoC models it is necessary to split a qemu_irq line
1
We create an OR gate to wire together the overflow IRQs for all the
2
so that one input can feed multiple outputs. We currently have
2
UARTs on the board; this has to have twice the number of inputs as
3
qemu_irq_split() for this, but that has several deficiencies:
3
there are UARTs, since each UART feeds it a TX overflow and an RX
4
* it can only handle splitting a line into two
4
overflow interrupt line. Replace the hardcoded '10' with a
5
* it unavoidably leaks memory, so it can't be used
5
calculation based on the size of the uart[] array in the
6
in a device that can be deleted
6
MPS2TZMachineState. (We rely on OR gate inputs that are never wired
7
7
up or asserted being treated as always-zero.)
8
Implement a qdev device that encapsulates splitting of IRQs, with a
9
configurable number of outputs. (This is in some ways the inverse of
10
the TYPE_OR_IRQ device.)
11
8
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
14
Message-id: 20180220180325.29818-13-peter.maydell@linaro.org
11
Message-id: 20210215115138.20465-15-peter.maydell@linaro.org
15
---
12
---
16
hw/core/Makefile.objs | 1 +
13
hw/arm/mps2-tz.c | 11 ++++++++---
17
include/hw/core/split-irq.h | 57 +++++++++++++++++++++++++++++
14
1 file changed, 8 insertions(+), 3 deletions(-)
18
include/hw/irq.h | 4 +-
19
hw/core/split-irq.c | 89 +++++++++++++++++++++++++++++++++++++++++++++
20
4 files changed, 150 insertions(+), 1 deletion(-)
21
create mode 100644 include/hw/core/split-irq.h
22
create mode 100644 hw/core/split-irq.c
23
15
24
diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs
16
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
25
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
26
--- a/hw/core/Makefile.objs
18
--- a/hw/arm/mps2-tz.c
27
+++ b/hw/core/Makefile.objs
19
+++ b/hw/arm/mps2-tz.c
28
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_FITLOADER) += loader-fit.o
20
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
29
common-obj-$(CONFIG_SOFTMMU) += qdev-properties-system.o
21
*/
30
common-obj-$(CONFIG_SOFTMMU) += register.o
22
memory_region_add_subregion(system_memory, 0x80000000, machine->ram);
31
common-obj-$(CONFIG_SOFTMMU) += or-irq.o
23
32
+common-obj-$(CONFIG_SOFTMMU) += split-irq.o
24
- /* The overflow IRQs for all UARTs are ORed together.
33
common-obj-$(CONFIG_PLATFORM_BUS) += platform-bus.o
25
+ /*
34
26
+ * The overflow IRQs for all UARTs are ORed together.
35
obj-$(CONFIG_SOFTMMU) += generic-loader.o
27
* Tx, Rx and "combined" IRQs are sent to the NVIC separately.
36
diff --git a/include/hw/core/split-irq.h b/include/hw/core/split-irq.h
28
- * Create the OR gate for this.
37
new file mode 100644
29
+ * Create the OR gate for this: it has one input for the TX overflow
38
index XXXXXXX..XXXXXXX
30
+ * and one for the RX overflow for each UART we might have.
39
--- /dev/null
31
+ * (If the board has fewer than the maximum possible number of UARTs
40
+++ b/include/hw/core/split-irq.h
32
+ * those inputs are never wired up and are treated as always-zero.)
41
@@ -XXX,XX +XXX,XX @@
33
*/
42
+/*
34
object_initialize_child(OBJECT(mms), "uart-irq-orgate",
43
+ * IRQ splitter device.
35
&mms->uart_irq_orgate, TYPE_OR_IRQ);
44
+ *
36
- object_property_set_int(OBJECT(&mms->uart_irq_orgate), "num-lines", 10,
45
+ * Copyright (c) 2018 Linaro Limited.
37
+ object_property_set_int(OBJECT(&mms->uart_irq_orgate), "num-lines",
46
+ * Written by Peter Maydell
38
+ 2 * ARRAY_SIZE(mms->uart),
47
+ *
39
&error_fatal);
48
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
40
qdev_realize(DEVICE(&mms->uart_irq_orgate), NULL, &error_fatal);
49
+ * of this software and associated documentation files (the "Software"), to deal
41
qdev_connect_gpio_out(DEVICE(&mms->uart_irq_orgate), 0,
50
+ * in the Software without restriction, including without limitation the rights
51
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
52
+ * copies of the Software, and to permit persons to whom the Software is
53
+ * furnished to do so, subject to the following conditions:
54
+ *
55
+ * The above copyright notice and this permission notice shall be included in
56
+ * all copies or substantial portions of the Software.
57
+ *
58
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
59
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
60
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
61
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
62
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
63
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
64
+ * THE SOFTWARE.
65
+ */
66
+
67
+/* This is a simple device which has one GPIO input line and multiple
68
+ * GPIO output lines. Any change on the input line is forwarded to all
69
+ * of the outputs.
70
+ *
71
+ * QEMU interface:
72
+ * + one unnamed GPIO input: the input line
73
+ * + N unnamed GPIO outputs: the output lines
74
+ * + QOM property "num-lines": sets the number of output lines
75
+ */
76
+#ifndef HW_SPLIT_IRQ_H
77
+#define HW_SPLIT_IRQ_H
78
+
79
+#include "hw/irq.h"
80
+#include "hw/sysbus.h"
81
+#include "qom/object.h"
82
+
83
+#define TYPE_SPLIT_IRQ "split-irq"
84
+
85
+#define MAX_SPLIT_LINES 16
86
+
87
+typedef struct SplitIRQ SplitIRQ;
88
+
89
+#define SPLIT_IRQ(obj) OBJECT_CHECK(SplitIRQ, (obj), TYPE_SPLIT_IRQ)
90
+
91
+struct SplitIRQ {
92
+ DeviceState parent_obj;
93
+
94
+ qemu_irq out_irq[MAX_SPLIT_LINES];
95
+ uint16_t num_lines;
96
+};
97
+
98
+#endif
99
diff --git a/include/hw/irq.h b/include/hw/irq.h
100
index XXXXXXX..XXXXXXX 100644
101
--- a/include/hw/irq.h
102
+++ b/include/hw/irq.h
103
@@ -XXX,XX +XXX,XX @@ void qemu_free_irq(qemu_irq irq);
104
/* Returns a new IRQ with opposite polarity. */
105
qemu_irq qemu_irq_invert(qemu_irq irq);
106
107
-/* Returns a new IRQ which feeds into both the passed IRQs */
108
+/* Returns a new IRQ which feeds into both the passed IRQs.
109
+ * It's probably better to use the TYPE_SPLIT_IRQ device instead.
110
+ */
111
qemu_irq qemu_irq_split(qemu_irq irq1, qemu_irq irq2);
112
113
/* Returns a new IRQ set which connects 1:1 to another IRQ set, which
114
diff --git a/hw/core/split-irq.c b/hw/core/split-irq.c
115
new file mode 100644
116
index XXXXXXX..XXXXXXX
117
--- /dev/null
118
+++ b/hw/core/split-irq.c
119
@@ -XXX,XX +XXX,XX @@
120
+/*
121
+ * IRQ splitter device.
122
+ *
123
+ * Copyright (c) 2018 Linaro Limited.
124
+ * Written by Peter Maydell
125
+ *
126
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
127
+ * of this software and associated documentation files (the "Software"), to deal
128
+ * in the Software without restriction, including without limitation the rights
129
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
130
+ * copies of the Software, and to permit persons to whom the Software is
131
+ * furnished to do so, subject to the following conditions:
132
+ *
133
+ * The above copyright notice and this permission notice shall be included in
134
+ * all copies or substantial portions of the Software.
135
+ *
136
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
137
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
138
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
139
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
140
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
141
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
142
+ * THE SOFTWARE.
143
+ */
144
+
145
+#include "qemu/osdep.h"
146
+#include "hw/core/split-irq.h"
147
+#include "qapi/error.h"
148
+
149
+static void split_irq_handler(void *opaque, int n, int level)
150
+{
151
+ SplitIRQ *s = SPLIT_IRQ(opaque);
152
+ int i;
153
+
154
+ for (i = 0; i < s->num_lines; i++) {
155
+ qemu_set_irq(s->out_irq[i], level);
156
+ }
157
+}
158
+
159
+static void split_irq_init(Object *obj)
160
+{
161
+ qdev_init_gpio_in(DEVICE(obj), split_irq_handler, 1);
162
+}
163
+
164
+static void split_irq_realize(DeviceState *dev, Error **errp)
165
+{
166
+ SplitIRQ *s = SPLIT_IRQ(dev);
167
+
168
+ if (s->num_lines < 1 || s->num_lines >= MAX_SPLIT_LINES) {
169
+ error_setg(errp,
170
+ "IRQ splitter number of lines %d is not between 1 and %d",
171
+ s->num_lines, MAX_SPLIT_LINES);
172
+ return;
173
+ }
174
+
175
+ qdev_init_gpio_out(dev, s->out_irq, s->num_lines);
176
+}
177
+
178
+static Property split_irq_properties[] = {
179
+ DEFINE_PROP_UINT16("num-lines", SplitIRQ, num_lines, 1),
180
+ DEFINE_PROP_END_OF_LIST(),
181
+};
182
+
183
+static void split_irq_class_init(ObjectClass *klass, void *data)
184
+{
185
+ DeviceClass *dc = DEVICE_CLASS(klass);
186
+
187
+ /* No state to reset or migrate */
188
+ dc->props = split_irq_properties;
189
+ dc->realize = split_irq_realize;
190
+
191
+ /* Reason: Needs to be wired up to work */
192
+ dc->user_creatable = false;
193
+}
194
+
195
+static const TypeInfo split_irq_type_info = {
196
+ .name = TYPE_SPLIT_IRQ,
197
+ .parent = TYPE_DEVICE,
198
+ .instance_size = sizeof(SplitIRQ),
199
+ .instance_init = split_irq_init,
200
+ .class_init = split_irq_class_init,
201
+};
202
+
203
+static void split_irq_register_types(void)
204
+{
205
+ type_register_static(&split_irq_type_info);
206
+}
207
+
208
+type_init(split_irq_register_types)
209
--
42
--
210
2.16.2
43
2.20.1
211
44
212
45
diff view generated by jsdifflib
1
The MPS2 AN505 FPGA image includes a "FPGA control block"
1
The AN505 and AN521 have the same device layout, but the AN524 is
2
which is a small set of registers handling LEDs, buttons
2
somewhat different. Allow for more than one PPCInfo array, which can
3
and some counters.
3
be selected based on the board type.
4
4
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20180220180325.29818-14-peter.maydell@linaro.org
7
Message-id: 20210215115138.20465-16-peter.maydell@linaro.org
8
---
8
---
9
hw/misc/Makefile.objs | 1 +
9
hw/arm/mps2-tz.c | 16 ++++++++++++++--
10
include/hw/misc/mps2-fpgaio.h | 43 ++++++++++
10
1 file changed, 14 insertions(+), 2 deletions(-)
11
hw/misc/mps2-fpgaio.c | 176 ++++++++++++++++++++++++++++++++++++++++
12
default-configs/arm-softmmu.mak | 1 +
13
hw/misc/trace-events | 6 ++
14
5 files changed, 227 insertions(+)
15
create mode 100644 include/hw/misc/mps2-fpgaio.h
16
create mode 100644 hw/misc/mps2-fpgaio.c
17
11
18
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
12
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
19
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
20
--- a/hw/misc/Makefile.objs
14
--- a/hw/arm/mps2-tz.c
21
+++ b/hw/misc/Makefile.objs
15
+++ b/hw/arm/mps2-tz.c
22
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_STM32F2XX_SYSCFG) += stm32f2xx_syscfg.o
16
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
23
obj-$(CONFIG_MIPS_CPS) += mips_cmgcr.o
17
MemoryRegion *system_memory = get_system_memory();
24
obj-$(CONFIG_MIPS_CPS) += mips_cpc.o
18
DeviceState *iotkitdev;
25
obj-$(CONFIG_MIPS_ITU) += mips_itu.o
19
DeviceState *dev_splitter;
26
+obj-$(CONFIG_MPS2_FPGAIO) += mps2-fpgaio.o
20
+ const PPCInfo *ppcs;
27
obj-$(CONFIG_MPS2_SCC) += mps2-scc.o
21
+ int num_ppcs;
28
22
int i;
29
obj-$(CONFIG_PVPANIC) += pvpanic.o
23
30
diff --git a/include/hw/misc/mps2-fpgaio.h b/include/hw/misc/mps2-fpgaio.h
24
if (strcmp(machine->cpu_type, mc->default_cpu_type) != 0) {
31
new file mode 100644
25
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
32
index XXXXXXX..XXXXXXX
26
* + wire up the PPC's control lines to the IoTKit object
33
--- /dev/null
27
*/
34
+++ b/include/hw/misc/mps2-fpgaio.h
28
35
@@ -XXX,XX +XXX,XX @@
29
- const PPCInfo ppcs[] = { {
36
+/*
30
+ const PPCInfo an505_ppcs[] = { {
37
+ * ARM MPS2 FPGAIO emulation
31
.name = "apb_ppcexp0",
38
+ *
32
.ports = {
39
+ * Copyright (c) 2018 Linaro Limited
33
{ "ssram-0", make_mpc, &mms->ssram_mpc[0], 0x58007000, 0x1000 },
40
+ * Written by Peter Maydell
34
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
41
+ *
35
},
42
+ * This program is free software; you can redistribute it and/or modify
36
};
43
+ * it under the terms of the GNU General Public License version 2 or
37
44
+ * (at your option) any later version.
38
- for (i = 0; i < ARRAY_SIZE(ppcs); i++) {
45
+ */
39
+ switch (mmc->fpga_type) {
46
+
40
+ case FPGA_AN505:
47
+/* This is a model of the FPGAIO register block in the AN505
41
+ case FPGA_AN521:
48
+ * FPGA image for the MPS2 dev board; it is documented in the
42
+ ppcs = an505_ppcs;
49
+ * application note:
43
+ num_ppcs = ARRAY_SIZE(an505_ppcs);
50
+ * http://infocenter.arm.com/help/topic/com.arm.doc.dai0505b/index.html
51
+ *
52
+ * QEMU interface:
53
+ * + sysbus MMIO region 0: the register bank
54
+ */
55
+
56
+#ifndef MPS2_FPGAIO_H
57
+#define MPS2_FPGAIO_H
58
+
59
+#include "hw/sysbus.h"
60
+
61
+#define TYPE_MPS2_FPGAIO "mps2-fpgaio"
62
+#define MPS2_FPGAIO(obj) OBJECT_CHECK(MPS2FPGAIO, (obj), TYPE_MPS2_FPGAIO)
63
+
64
+typedef struct {
65
+ /*< private >*/
66
+ SysBusDevice parent_obj;
67
+
68
+ /*< public >*/
69
+ MemoryRegion iomem;
70
+
71
+ uint32_t led0;
72
+ uint32_t prescale;
73
+ uint32_t misc;
74
+
75
+ uint32_t prescale_clk;
76
+} MPS2FPGAIO;
77
+
78
+#endif
79
diff --git a/hw/misc/mps2-fpgaio.c b/hw/misc/mps2-fpgaio.c
80
new file mode 100644
81
index XXXXXXX..XXXXXXX
82
--- /dev/null
83
+++ b/hw/misc/mps2-fpgaio.c
84
@@ -XXX,XX +XXX,XX @@
85
+/*
86
+ * ARM MPS2 AN505 FPGAIO emulation
87
+ *
88
+ * Copyright (c) 2018 Linaro Limited
89
+ * Written by Peter Maydell
90
+ *
91
+ * This program is free software; you can redistribute it and/or modify
92
+ * it under the terms of the GNU General Public License version 2 or
93
+ * (at your option) any later version.
94
+ */
95
+
96
+/* This is a model of the "FPGA system control and I/O" block found
97
+ * in the AN505 FPGA image for the MPS2 devboard.
98
+ * It is documented in AN505:
99
+ * http://infocenter.arm.com/help/topic/com.arm.doc.dai0505b/index.html
100
+ */
101
+
102
+#include "qemu/osdep.h"
103
+#include "qemu/log.h"
104
+#include "qapi/error.h"
105
+#include "trace.h"
106
+#include "hw/sysbus.h"
107
+#include "hw/registerfields.h"
108
+#include "hw/misc/mps2-fpgaio.h"
109
+
110
+REG32(LED0, 0)
111
+REG32(BUTTON, 8)
112
+REG32(CLK1HZ, 0x10)
113
+REG32(CLK100HZ, 0x14)
114
+REG32(COUNTER, 0x18)
115
+REG32(PRESCALE, 0x1c)
116
+REG32(PSCNTR, 0x20)
117
+REG32(MISC, 0x4c)
118
+
119
+static uint64_t mps2_fpgaio_read(void *opaque, hwaddr offset, unsigned size)
120
+{
121
+ MPS2FPGAIO *s = MPS2_FPGAIO(opaque);
122
+ uint64_t r;
123
+
124
+ switch (offset) {
125
+ case A_LED0:
126
+ r = s->led0;
127
+ break;
128
+ case A_BUTTON:
129
+ /* User-pressable board buttons. We don't model that, so just return
130
+ * zeroes.
131
+ */
132
+ r = 0;
133
+ break;
134
+ case A_PRESCALE:
135
+ r = s->prescale;
136
+ break;
137
+ case A_MISC:
138
+ r = s->misc;
139
+ break;
140
+ case A_CLK1HZ:
141
+ case A_CLK100HZ:
142
+ case A_COUNTER:
143
+ case A_PSCNTR:
144
+ /* These are all upcounters of various frequencies. */
145
+ qemu_log_mask(LOG_UNIMP, "MPS2 FPGAIO: counters unimplemented\n");
146
+ r = 0;
147
+ break;
44
+ break;
148
+ default:
45
+ default:
149
+ qemu_log_mask(LOG_GUEST_ERROR,
46
+ g_assert_not_reached();
150
+ "MPS2 FPGAIO read: bad offset %x\n", (int) offset);
151
+ r = 0;
152
+ break;
153
+ }
47
+ }
154
+
48
+
155
+ trace_mps2_fpgaio_read(offset, r, size);
49
+ for (i = 0; i < num_ppcs; i++) {
156
+ return r;
50
const PPCInfo *ppcinfo = &ppcs[i];
157
+}
51
TZPPC *ppc = &mms->ppc[i];
158
+
52
DeviceState *ppcdev;
159
+static void mps2_fpgaio_write(void *opaque, hwaddr offset, uint64_t value,
160
+ unsigned size)
161
+{
162
+ MPS2FPGAIO *s = MPS2_FPGAIO(opaque);
163
+
164
+ trace_mps2_fpgaio_write(offset, value, size);
165
+
166
+ switch (offset) {
167
+ case A_LED0:
168
+ /* LED bits [1:0] control board LEDs. We don't currently have
169
+ * a mechanism for displaying this graphically, so use a trace event.
170
+ */
171
+ trace_mps2_fpgaio_leds(value & 0x02 ? '*' : '.',
172
+ value & 0x01 ? '*' : '.');
173
+ s->led0 = value & 0x3;
174
+ break;
175
+ case A_PRESCALE:
176
+ s->prescale = value;
177
+ break;
178
+ case A_MISC:
179
+ /* These are control bits for some of the other devices on the
180
+ * board (SPI, CLCD, etc). We don't implement that yet, so just
181
+ * make the bits read as written.
182
+ */
183
+ qemu_log_mask(LOG_UNIMP,
184
+ "MPS2 FPGAIO: MISC control bits unimplemented\n");
185
+ s->misc = value;
186
+ break;
187
+ default:
188
+ qemu_log_mask(LOG_GUEST_ERROR,
189
+ "MPS2 FPGAIO write: bad offset 0x%x\n", (int) offset);
190
+ break;
191
+ }
192
+}
193
+
194
+static const MemoryRegionOps mps2_fpgaio_ops = {
195
+ .read = mps2_fpgaio_read,
196
+ .write = mps2_fpgaio_write,
197
+ .endianness = DEVICE_LITTLE_ENDIAN,
198
+};
199
+
200
+static void mps2_fpgaio_reset(DeviceState *dev)
201
+{
202
+ MPS2FPGAIO *s = MPS2_FPGAIO(dev);
203
+
204
+ trace_mps2_fpgaio_reset();
205
+ s->led0 = 0;
206
+ s->prescale = 0;
207
+ s->misc = 0;
208
+}
209
+
210
+static void mps2_fpgaio_init(Object *obj)
211
+{
212
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
213
+ MPS2FPGAIO *s = MPS2_FPGAIO(obj);
214
+
215
+ memory_region_init_io(&s->iomem, obj, &mps2_fpgaio_ops, s,
216
+ "mps2-fpgaio", 0x1000);
217
+ sysbus_init_mmio(sbd, &s->iomem);
218
+}
219
+
220
+static const VMStateDescription mps2_fpgaio_vmstate = {
221
+ .name = "mps2-fpgaio",
222
+ .version_id = 1,
223
+ .minimum_version_id = 1,
224
+ .fields = (VMStateField[]) {
225
+ VMSTATE_UINT32(led0, MPS2FPGAIO),
226
+ VMSTATE_UINT32(prescale, MPS2FPGAIO),
227
+ VMSTATE_UINT32(misc, MPS2FPGAIO),
228
+ VMSTATE_END_OF_LIST()
229
+ }
230
+};
231
+
232
+static Property mps2_fpgaio_properties[] = {
233
+ /* Frequency of the prescale counter */
234
+ DEFINE_PROP_UINT32("prescale-clk", MPS2FPGAIO, prescale_clk, 20000000),
235
+ DEFINE_PROP_END_OF_LIST(),
236
+};
237
+
238
+static void mps2_fpgaio_class_init(ObjectClass *klass, void *data)
239
+{
240
+ DeviceClass *dc = DEVICE_CLASS(klass);
241
+
242
+ dc->vmsd = &mps2_fpgaio_vmstate;
243
+ dc->reset = mps2_fpgaio_reset;
244
+ dc->props = mps2_fpgaio_properties;
245
+}
246
+
247
+static const TypeInfo mps2_fpgaio_info = {
248
+ .name = TYPE_MPS2_FPGAIO,
249
+ .parent = TYPE_SYS_BUS_DEVICE,
250
+ .instance_size = sizeof(MPS2FPGAIO),
251
+ .instance_init = mps2_fpgaio_init,
252
+ .class_init = mps2_fpgaio_class_init,
253
+};
254
+
255
+static void mps2_fpgaio_register_types(void)
256
+{
257
+ type_register_static(&mps2_fpgaio_info);
258
+}
259
+
260
+type_init(mps2_fpgaio_register_types);
261
diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
262
index XXXXXXX..XXXXXXX 100644
263
--- a/default-configs/arm-softmmu.mak
264
+++ b/default-configs/arm-softmmu.mak
265
@@ -XXX,XX +XXX,XX @@ CONFIG_STM32F205_SOC=y
266
CONFIG_CMSDK_APB_TIMER=y
267
CONFIG_CMSDK_APB_UART=y
268
269
+CONFIG_MPS2_FPGAIO=y
270
CONFIG_MPS2_SCC=y
271
272
CONFIG_VERSATILE_PCI=y
273
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
274
index XXXXXXX..XXXXXXX 100644
275
--- a/hw/misc/trace-events
276
+++ b/hw/misc/trace-events
277
@@ -XXX,XX +XXX,XX @@ mps2_scc_leds(char led7, char led6, char led5, char led4, char led3, char led2,
278
mps2_scc_cfg_write(unsigned function, unsigned device, uint32_t value) "MPS2 SCC config write: function %d device %d data 0x%" PRIx32
279
mps2_scc_cfg_read(unsigned function, unsigned device, uint32_t value) "MPS2 SCC config read: function %d device %d data 0x%" PRIx32
280
281
+# hw/misc/mps2_fpgaio.c
282
+mps2_fpgaio_read(uint64_t offset, uint64_t data, unsigned size) "MPS2 FPGAIO read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
283
+mps2_fpgaio_write(uint64_t offset, uint64_t data, unsigned size) "MPS2 FPGAIO write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
284
+mps2_fpgaio_reset(void) "MPS2 FPGAIO: reset"
285
+mps2_fpgaio_leds(char led1, char led0) "MPS2 FPGAIO LEDs: %c%c"
286
+
287
# hw/misc/msf2-sysreg.c
288
msf2_sysreg_write(uint64_t offset, uint32_t val, uint32_t prev) "msf2-sysreg write: addr 0x%08" HWADDR_PRIx " data 0x%" PRIx32 " prev 0x%" PRIx32
289
msf2_sysreg_read(uint64_t offset, uint32_t val) "msf2-sysreg read: addr 0x%08" HWADDR_PRIx " data 0x%08" PRIx32
290
--
53
--
291
2.16.2
54
2.20.1
292
55
293
56
diff view generated by jsdifflib
1
Add a model of the TrustZone peripheral protection controller (PPC),
1
The AN505 and AN521 have the same layout of RAM; the AN524 does not.
2
which is used to gate transactions to non-TZ-aware peripherals so
2
Replace the current hard-coding of where the RAM is and which parts
3
that secure software can configure them to not be accessible to
3
of it are behind which MPCs with a data-driven approach.
4
non-secure software.
5
4
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20180220180325.29818-15-peter.maydell@linaro.org
7
Message-id: 20210215115138.20465-17-peter.maydell@linaro.org
9
---
8
---
10
hw/misc/Makefile.objs | 2 +
9
hw/arm/mps2-tz.c | 175 +++++++++++++++++++++++++++++++++++++----------
11
include/hw/misc/tz-ppc.h | 101 ++++++++++++++
10
1 file changed, 138 insertions(+), 37 deletions(-)
12
hw/misc/tz-ppc.c | 302 ++++++++++++++++++++++++++++++++++++++++
11
13
default-configs/arm-softmmu.mak | 2 +
12
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
14
hw/misc/trace-events | 11 ++
15
5 files changed, 418 insertions(+)
16
create mode 100644 include/hw/misc/tz-ppc.h
17
create mode 100644 hw/misc/tz-ppc.c
18
19
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
20
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
21
--- a/hw/misc/Makefile.objs
14
--- a/hw/arm/mps2-tz.c
22
+++ b/hw/misc/Makefile.objs
15
+++ b/hw/arm/mps2-tz.c
23
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_MIPS_ITU) += mips_itu.o
24
obj-$(CONFIG_MPS2_FPGAIO) += mps2-fpgaio.o
25
obj-$(CONFIG_MPS2_SCC) += mps2-scc.o
26
27
+obj-$(CONFIG_TZ_PPC) += tz-ppc.o
28
+
29
obj-$(CONFIG_PVPANIC) += pvpanic.o
30
obj-$(CONFIG_HYPERV_TESTDEV) += hyperv_testdev.o
31
obj-$(CONFIG_AUX) += auxbus.o
32
diff --git a/include/hw/misc/tz-ppc.h b/include/hw/misc/tz-ppc.h
33
new file mode 100644
34
index XXXXXXX..XXXXXXX
35
--- /dev/null
36
+++ b/include/hw/misc/tz-ppc.h
37
@@ -XXX,XX +XXX,XX @@
16
@@ -XXX,XX +XXX,XX @@
17
#include "qom/object.h"
18
19
#define MPS2TZ_NUMIRQ_MAX 92
20
+#define MPS2TZ_RAM_MAX 4
21
22
typedef enum MPS2TZFPGAType {
23
FPGA_AN505,
24
FPGA_AN521,
25
} MPS2TZFPGAType;
26
38
+/*
27
+/*
39
+ * ARM TrustZone peripheral protection controller emulation
28
+ * Define the layout of RAM in a board, including which parts are
40
+ *
29
+ * behind which MPCs.
41
+ * Copyright (c) 2018 Linaro Limited
30
+ * mrindex specifies the index into mms->ram[] to use for the backing RAM;
42
+ * Written by Peter Maydell
31
+ * -1 means "use the system RAM".
43
+ *
44
+ * This program is free software; you can redistribute it and/or modify
45
+ * it under the terms of the GNU General Public License version 2 or
46
+ * (at your option) any later version.
47
+ */
32
+ */
48
+
33
+typedef struct RAMInfo {
49
+/* This is a model of the TrustZone peripheral protection controller (PPC).
34
+ const char *name;
50
+ * It is documented in the ARM CoreLink SIE-200 System IP for Embedded TRM
35
+ uint32_t base;
51
+ * (DDI 0571G):
36
+ uint32_t size;
52
+ * https://developer.arm.com/products/architecture/m-profile/docs/ddi0571/g
37
+ int mpc; /* MPC number, -1 for "not behind an MPC" */
53
+ *
38
+ int mrindex;
54
+ * The PPC sits in front of peripherals and allows secure software to
39
+ int flags;
55
+ * configure it to either pass through or reject transactions.
40
+} RAMInfo;
56
+ * Rejected transactions may be configured to either be aborted, or to
41
+
57
+ * behave as RAZ/WI. An interrupt can be signalled for a rejected transaction.
42
+/*
58
+ *
43
+ * Flag values:
59
+ * The PPC has no register interface -- it is configured purely by a
44
+ * IS_ALIAS: this RAM area is an alias to the upstream end of the
60
+ * collection of input signals from other hardware in the system. Typically
45
+ * MPC specified by its .mpc value
61
+ * they are either hardwired or exposed in an ad-hoc register interface by
62
+ * the SoC that uses the PPC.
63
+ *
64
+ * This QEMU model can be used to model either the AHB5 or APB4 TZ PPC,
65
+ * since the only difference between them is that the AHB version has a
66
+ * "default" port which has no security checks applied. In QEMU the default
67
+ * port can be emulated simply by wiring its downstream devices directly
68
+ * into the parent address space, since the PPC does not need to intercept
69
+ * transactions there.
70
+ *
71
+ * In the hardware, selection of which downstream port to use is done by
72
+ * the user's decode logic asserting one of the hsel[] signals. In QEMU,
73
+ * we provide 16 MMIO regions, one per port, and the user maps these into
74
+ * the desired addresses to implement the address decode.
75
+ *
76
+ * QEMU interface:
77
+ * + sysbus MMIO regions 0..15: MemoryRegions defining the upstream end
78
+ * of each of the 16 ports of the PPC
79
+ * + Property "port[0..15]": MemoryRegion defining the downstream device(s)
80
+ * for each of the 16 ports of the PPC
81
+ * + Named GPIO inputs "cfg_nonsec[0..15]": set to 1 if the port should be
82
+ * accessible to NonSecure transactions
83
+ * + Named GPIO inputs "cfg_ap[0..15]": set to 1 if the port should be
84
+ * accessible to non-privileged transactions
85
+ * + Named GPIO input "cfg_sec_resp": set to 1 if a rejected transaction should
86
+ * result in a transaction error, or 0 for the transaction to RAZ/WI
87
+ * + Named GPIO input "irq_enable": set to 1 to enable interrupts
88
+ * + Named GPIO input "irq_clear": set to 1 to clear a pending interrupt
89
+ * + Named GPIO output "irq": set for a transaction-failed interrupt
90
+ * + Property "NONSEC_MASK": if a bit is set in this mask then accesses to
91
+ * the associated port do not have the TZ security check performed. (This
92
+ * corresponds to the hardware allowing this to be set as a Verilog
93
+ * parameter.)
94
+ */
46
+ */
95
+
47
+#define IS_ALIAS 1
96
+#ifndef TZ_PPC_H
48
+
97
+#define TZ_PPC_H
49
struct MPS2TZMachineClass {
98
+
50
MachineClass parent;
99
+#include "hw/sysbus.h"
51
MPS2TZFPGAType fpga_type;
100
+
52
@@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineClass {
101
+#define TYPE_TZ_PPC "tz-ppc"
53
uint32_t fpgaio_num_leds; /* Number of LEDs in FPGAIO LED0 register */
102
+#define TZ_PPC(obj) OBJECT_CHECK(TZPPC, (obj), TYPE_TZ_PPC)
54
bool fpgaio_has_switches; /* Does FPGAIO have SWITCH register? */
103
+
55
int numirq; /* Number of external interrupts */
104
+#define TZ_NUM_PORTS 16
56
+ const RAMInfo *raminfo;
105
+
57
const char *armsse_type;
106
+typedef struct TZPPC TZPPC;
58
};
107
+
59
108
+typedef struct TZPPCPort {
60
@@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineState {
109
+ TZPPC *ppc;
61
MachineState parent;
110
+ MemoryRegion upstream;
62
111
+ AddressSpace downstream_as;
63
ARMSSE iotkit;
112
+ MemoryRegion *downstream;
64
- MemoryRegion ssram[3];
113
+} TZPPCPort;
65
- MemoryRegion ssram1_m;
114
+
66
+ MemoryRegion ram[MPS2TZ_RAM_MAX];
115
+struct TZPPC {
67
MPS2SCC scc;
116
+ /*< private >*/
68
MPS2FPGAIO fpgaio;
117
+ SysBusDevice parent_obj;
69
TZPPC ppc[5];
118
+
70
- TZMPC ssram_mpc[3];
119
+ /*< public >*/
71
+ TZMPC mpc[3];
120
+
72
PL022State spi[5];
121
+ /* State: these just track the values of our input signals */
73
ArmSbconI2CState i2c[4];
122
+ bool cfg_nonsec[TZ_NUM_PORTS];
74
UnimplementedDeviceState i2s_audio;
123
+ bool cfg_ap[TZ_NUM_PORTS];
75
@@ -XXX,XX +XXX,XX @@ static const uint32_t an505_oscclk[] = {
124
+ bool cfg_sec_resp;
76
25000000,
125
+ bool irq_enable;
77
};
126
+ bool irq_clear;
78
127
+ /* State: are we asserting irq ? */
79
+static const RAMInfo an505_raminfo[] = { {
128
+ bool irq_status;
80
+ .name = "ssram-0",
129
+
81
+ .base = 0x00000000,
130
+ qemu_irq irq;
82
+ .size = 0x00400000,
131
+
83
+ .mpc = 0,
132
+ /* Properties */
84
+ .mrindex = 0,
133
+ uint32_t nonsec_mask;
85
+ }, {
134
+
86
+ .name = "ssram-1",
135
+ TZPPCPort port[TZ_NUM_PORTS];
87
+ .base = 0x28000000,
88
+ .size = 0x00200000,
89
+ .mpc = 1,
90
+ .mrindex = 1,
91
+ }, {
92
+ .name = "ssram-2",
93
+ .base = 0x28200000,
94
+ .size = 0x00200000,
95
+ .mpc = 2,
96
+ .mrindex = 2,
97
+ }, {
98
+ .name = "ssram-0-alias",
99
+ .base = 0x00400000,
100
+ .size = 0x00400000,
101
+ .mpc = 0,
102
+ .mrindex = 3,
103
+ .flags = IS_ALIAS,
104
+ }, {
105
+ /* Use the largest bit of contiguous RAM as our "system memory" */
106
+ .name = "mps.ram",
107
+ .base = 0x80000000,
108
+ .size = 16 * MiB,
109
+ .mpc = -1,
110
+ .mrindex = -1,
111
+ }, {
112
+ .name = NULL,
113
+ },
136
+};
114
+};
137
+
115
+
138
+#endif
116
+static const RAMInfo *find_raminfo_for_mpc(MPS2TZMachineState *mms, int mpc)
139
diff --git a/hw/misc/tz-ppc.c b/hw/misc/tz-ppc.c
140
new file mode 100644
141
index XXXXXXX..XXXXXXX
142
--- /dev/null
143
+++ b/hw/misc/tz-ppc.c
144
@@ -XXX,XX +XXX,XX @@
145
+/*
146
+ * ARM TrustZone peripheral protection controller emulation
147
+ *
148
+ * Copyright (c) 2018 Linaro Limited
149
+ * Written by Peter Maydell
150
+ *
151
+ * This program is free software; you can redistribute it and/or modify
152
+ * it under the terms of the GNU General Public License version 2 or
153
+ * (at your option) any later version.
154
+ */
155
+
156
+#include "qemu/osdep.h"
157
+#include "qemu/log.h"
158
+#include "qapi/error.h"
159
+#include "trace.h"
160
+#include "hw/sysbus.h"
161
+#include "hw/registerfields.h"
162
+#include "hw/misc/tz-ppc.h"
163
+
164
+static void tz_ppc_update_irq(TZPPC *s)
165
+{
117
+{
166
+ bool level = s->irq_status && s->irq_enable;
118
+ MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
167
+
119
+ const RAMInfo *p;
168
+ trace_tz_ppc_update_irq(level);
120
+
169
+ qemu_set_irq(s->irq, level);
121
+ for (p = mmc->raminfo; p->name; p++) {
122
+ if (p->mpc == mpc && !(p->flags & IS_ALIAS)) {
123
+ return p;
124
+ }
125
+ }
126
+ /* if raminfo array doesn't have an entry for each MPC this is a bug */
127
+ g_assert_not_reached();
170
+}
128
+}
171
+
129
+
172
+static void tz_ppc_cfg_nonsec(void *opaque, int n, int level)
130
+static MemoryRegion *mr_for_raminfo(MPS2TZMachineState *mms,
131
+ const RAMInfo *raminfo)
173
+{
132
+{
174
+ TZPPC *s = TZ_PPC(opaque);
133
+ /* Return an initialized MemoryRegion for the RAMInfo. */
175
+
134
+ MemoryRegion *ram;
176
+ assert(n < TZ_NUM_PORTS);
135
+
177
+ trace_tz_ppc_cfg_nonsec(n, level);
136
+ if (raminfo->mrindex < 0) {
178
+ s->cfg_nonsec[n] = level;
137
+ /* Means this RAMInfo is for QEMU's "system memory" */
138
+ MachineState *machine = MACHINE(mms);
139
+ return machine->ram;
140
+ }
141
+
142
+ assert(raminfo->mrindex < MPS2TZ_RAM_MAX);
143
+ ram = &mms->ram[raminfo->mrindex];
144
+
145
+ memory_region_init_ram(ram, NULL, raminfo->name,
146
+ raminfo->size, &error_fatal);
147
+ return ram;
179
+}
148
+}
180
+
149
+
181
+static void tz_ppc_cfg_ap(void *opaque, int n, int level)
150
/* Create an alias of an entire original MemoryRegion @orig
151
* located at @base in the memory map.
152
*/
153
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_mpc(MPS2TZMachineState *mms, void *opaque,
154
const int *irqs)
155
{
156
TZMPC *mpc = opaque;
157
- int i = mpc - &mms->ssram_mpc[0];
158
- MemoryRegion *ssram = &mms->ssram[i];
159
+ int i = mpc - &mms->mpc[0];
160
MemoryRegion *upstream;
161
- char *mpcname = g_strdup_printf("%s-mpc", name);
162
- static uint32_t ramsize[] = { 0x00400000, 0x00200000, 0x00200000 };
163
- static uint32_t rambase[] = { 0x00000000, 0x28000000, 0x28200000 };
164
+ const RAMInfo *raminfo = find_raminfo_for_mpc(mms, i);
165
+ MemoryRegion *ram = mr_for_raminfo(mms, raminfo);
166
167
- memory_region_init_ram(ssram, NULL, name, ramsize[i], &error_fatal);
168
-
169
- object_initialize_child(OBJECT(mms), mpcname, mpc, TYPE_TZ_MPC);
170
- object_property_set_link(OBJECT(mpc), "downstream", OBJECT(ssram),
171
+ object_initialize_child(OBJECT(mms), name, mpc, TYPE_TZ_MPC);
172
+ object_property_set_link(OBJECT(mpc), "downstream", OBJECT(ram),
173
&error_fatal);
174
sysbus_realize(SYS_BUS_DEVICE(mpc), &error_fatal);
175
/* Map the upstream end of the MPC into system memory */
176
upstream = sysbus_mmio_get_region(SYS_BUS_DEVICE(mpc), 1);
177
- memory_region_add_subregion(get_system_memory(), rambase[i], upstream);
178
+ memory_region_add_subregion(get_system_memory(), raminfo->base, upstream);
179
/* and connect its interrupt to the IoTKit */
180
qdev_connect_gpio_out_named(DEVICE(mpc), "irq", 0,
181
qdev_get_gpio_in_named(DEVICE(&mms->iotkit),
182
"mpcexp_status", i));
183
184
- /* The first SSRAM is a special case as it has an alias; accesses to
185
- * the alias region at 0x00400000 must also go to the MPC upstream.
186
- */
187
- if (i == 0) {
188
- make_ram_alias(&mms->ssram1_m, "mps.ssram1_m", upstream, 0x00400000);
189
- }
190
-
191
- g_free(mpcname);
192
/* Return the register interface MR for our caller to map behind the PPC */
193
return sysbus_mmio_get_region(SYS_BUS_DEVICE(mpc), 0);
194
}
195
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_i2c(MPS2TZMachineState *mms, void *opaque,
196
return sysbus_mmio_get_region(s, 0);
197
}
198
199
+static void create_non_mpc_ram(MPS2TZMachineState *mms)
182
+{
200
+{
183
+ TZPPC *s = TZ_PPC(opaque);
201
+ /*
184
+
202
+ * Handle the RAMs which are either not behind MPCs or which are
185
+ assert(n < TZ_NUM_PORTS);
203
+ * aliases to another MPC.
186
+ trace_tz_ppc_cfg_ap(n, level);
204
+ */
187
+ s->cfg_ap[n] = level;
205
+ const RAMInfo *p;
188
+}
206
+ MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
189
+
207
+
190
+static void tz_ppc_cfg_sec_resp(void *opaque, int n, int level)
208
+ for (p = mmc->raminfo; p->name; p++) {
191
+{
209
+ if (p->flags & IS_ALIAS) {
192
+ TZPPC *s = TZ_PPC(opaque);
210
+ SysBusDevice *mpc_sbd = SYS_BUS_DEVICE(&mms->mpc[p->mpc]);
193
+
211
+ MemoryRegion *upstream = sysbus_mmio_get_region(mpc_sbd, 1);
194
+ trace_tz_ppc_cfg_sec_resp(level);
212
+ make_ram_alias(&mms->ram[p->mrindex], p->name, upstream, p->base);
195
+ s->cfg_sec_resp = level;
213
+ } else if (p->mpc == -1) {
196
+}
214
+ /* RAM not behind an MPC */
197
+
215
+ MemoryRegion *mr = mr_for_raminfo(mms, p);
198
+static void tz_ppc_irq_enable(void *opaque, int n, int level)
216
+ memory_region_add_subregion(get_system_memory(), p->base, mr);
199
+{
217
+ }
200
+ TZPPC *s = TZ_PPC(opaque);
201
+
202
+ trace_tz_ppc_irq_enable(level);
203
+ s->irq_enable = level;
204
+ tz_ppc_update_irq(s);
205
+}
206
+
207
+static void tz_ppc_irq_clear(void *opaque, int n, int level)
208
+{
209
+ TZPPC *s = TZ_PPC(opaque);
210
+
211
+ trace_tz_ppc_irq_clear(level);
212
+
213
+ s->irq_clear = level;
214
+ if (level) {
215
+ s->irq_status = false;
216
+ tz_ppc_update_irq(s);
217
+ }
218
+ }
218
+}
219
+}
219
+
220
+
220
+static bool tz_ppc_check(TZPPC *s, int n, MemTxAttrs attrs)
221
static void mps2tz_common_init(MachineState *machine)
221
+{
222
{
222
+ /* Check whether to allow an access to port n; return true if
223
MPS2TZMachineState *mms = MPS2TZ_MACHINE(machine);
223
+ * the check passes, and false if the transaction must be blocked.
224
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
224
+ * If the latter, the caller must check cfg_sec_resp to determine
225
qdev_connect_gpio_out_named(iotkitdev, "sec_resp_cfg", 0,
225
+ * whether to abort or RAZ/WI the transaction.
226
qdev_get_gpio_in(dev_splitter, 0));
226
+ * The checks are:
227
227
+ * + nonsec_mask suppresses any check of the secure attribute
228
- /* The IoTKit sets up much of the memory layout, including
228
+ * + otherwise, block if cfg_nonsec is 1 and transaction is secure,
229
+ /*
229
+ * or if cfg_nonsec is 0 and transaction is non-secure
230
+ * The IoTKit sets up much of the memory layout, including
230
+ * + block if transaction is usermode and cfg_ap is 0
231
* the aliases between secure and non-secure regions in the
231
+ */
232
- * address space. The FPGA itself contains:
232
+ if ((attrs.secure == s->cfg_nonsec[n] && !(s->nonsec_mask & (1 << n))) ||
233
- *
233
+ (attrs.user && !s->cfg_ap[n])) {
234
- * 0x00000000..0x003fffff SSRAM1
234
+ /* Block the transaction. */
235
- * 0x00400000..0x007fffff alias of SSRAM1
235
+ if (!s->irq_clear) {
236
- * 0x28000000..0x283fffff 4MB SSRAM2 + SSRAM3
236
+ /* Note that holding irq_clear high suppresses interrupts */
237
- * 0x40100000..0x4fffffff AHB Master Expansion 1 interface devices
237
+ s->irq_status = true;
238
- * 0x80000000..0x80ffffff 16MB PSRAM
238
+ tz_ppc_update_irq(s);
239
- */
239
+ }
240
-
240
+ return false;
241
- /* The FPGA images have an odd combination of different RAMs,
241
+ }
242
+ * address space, and also most of the devices in the system.
242
+ return true;
243
+ * The FPGA itself contains various RAMs and some additional devices.
243
+}
244
+ * The FPGA images have an odd combination of different RAMs,
244
+
245
* because in hardware they are different implementations and
245
+static MemTxResult tz_ppc_read(void *opaque, hwaddr addr, uint64_t *pdata,
246
* connected to different buses, giving varying performance/size
246
+ unsigned size, MemTxAttrs attrs)
247
* tradeoffs. For QEMU they're all just RAM, though. We arbitrarily
247
+{
248
- * call the 16MB our "system memory", as it's the largest lump.
248
+ TZPPCPort *p = opaque;
249
+ * call the largest lump our "system memory".
249
+ TZPPC *s = p->ppc;
250
*/
250
+ int n = p - s->port;
251
- memory_region_add_subregion(system_memory, 0x80000000, machine->ram);
251
+ AddressSpace *as = &p->downstream_as;
252
252
+ uint64_t data;
253
/*
253
+ MemTxResult res;
254
* The overflow IRQs for all UARTs are ORed together.
254
+
255
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
255
+ if (!tz_ppc_check(s, n, attrs)) {
256
const PPCInfo an505_ppcs[] = { {
256
+ trace_tz_ppc_read_blocked(n, addr, attrs.secure, attrs.user);
257
.name = "apb_ppcexp0",
257
+ if (s->cfg_sec_resp) {
258
.ports = {
258
+ return MEMTX_ERROR;
259
- { "ssram-0", make_mpc, &mms->ssram_mpc[0], 0x58007000, 0x1000 },
259
+ } else {
260
- { "ssram-1", make_mpc, &mms->ssram_mpc[1], 0x58008000, 0x1000 },
260
+ *pdata = 0;
261
- { "ssram-2", make_mpc, &mms->ssram_mpc[2], 0x58009000, 0x1000 },
261
+ return MEMTX_OK;
262
+ { "ssram-0-mpc", make_mpc, &mms->mpc[0], 0x58007000, 0x1000 },
262
+ }
263
+ { "ssram-1-mpc", make_mpc, &mms->mpc[1], 0x58008000, 0x1000 },
263
+ }
264
+ { "ssram-2-mpc", make_mpc, &mms->mpc[2], 0x58009000, 0x1000 },
264
+
265
},
265
+ switch (size) {
266
}, {
266
+ case 1:
267
.name = "apb_ppcexp1",
267
+ data = address_space_ldub(as, addr, attrs, &res);
268
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
268
+ break;
269
269
+ case 2:
270
create_unimplemented_device("FPGA NS PC", 0x48007000, 0x1000);
270
+ data = address_space_lduw_le(as, addr, attrs, &res);
271
271
+ break;
272
+ create_non_mpc_ram(mms);
272
+ case 4:
273
+
273
+ data = address_space_ldl_le(as, addr, attrs, &res);
274
armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename, 0x400000);
274
+ break;
275
}
275
+ case 8:
276
276
+ data = address_space_ldq_le(as, addr, attrs, &res);
277
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an505_class_init(ObjectClass *oc, void *data)
277
+ break;
278
mmc->fpgaio_num_leds = 2;
278
+ default:
279
mmc->fpgaio_has_switches = false;
279
+ g_assert_not_reached();
280
mmc->numirq = 92;
280
+ }
281
+ mmc->raminfo = an505_raminfo;
281
+ *pdata = data;
282
mmc->armsse_type = TYPE_IOTKIT;
282
+ return res;
283
}
283
+}
284
284
+
285
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an521_class_init(ObjectClass *oc, void *data)
285
+static MemTxResult tz_ppc_write(void *opaque, hwaddr addr, uint64_t val,
286
mmc->fpgaio_num_leds = 2;
286
+ unsigned size, MemTxAttrs attrs)
287
mmc->fpgaio_has_switches = false;
287
+{
288
mmc->numirq = 92;
288
+ TZPPCPort *p = opaque;
289
+ mmc->raminfo = an505_raminfo; /* AN521 is the same as AN505 here */
289
+ TZPPC *s = p->ppc;
290
mmc->armsse_type = TYPE_SSE200;
290
+ AddressSpace *as = &p->downstream_as;
291
}
291
+ int n = p - s->port;
292
292
+ MemTxResult res;
293
+
294
+ if (!tz_ppc_check(s, n, attrs)) {
295
+ trace_tz_ppc_write_blocked(n, addr, attrs.secure, attrs.user);
296
+ if (s->cfg_sec_resp) {
297
+ return MEMTX_ERROR;
298
+ } else {
299
+ return MEMTX_OK;
300
+ }
301
+ }
302
+
303
+ switch (size) {
304
+ case 1:
305
+ address_space_stb(as, addr, val, attrs, &res);
306
+ break;
307
+ case 2:
308
+ address_space_stw_le(as, addr, val, attrs, &res);
309
+ break;
310
+ case 4:
311
+ address_space_stl_le(as, addr, val, attrs, &res);
312
+ break;
313
+ case 8:
314
+ address_space_stq_le(as, addr, val, attrs, &res);
315
+ break;
316
+ default:
317
+ g_assert_not_reached();
318
+ }
319
+ return res;
320
+}
321
+
322
+static const MemoryRegionOps tz_ppc_ops = {
323
+ .read_with_attrs = tz_ppc_read,
324
+ .write_with_attrs = tz_ppc_write,
325
+ .endianness = DEVICE_LITTLE_ENDIAN,
326
+};
327
+
328
+static void tz_ppc_reset(DeviceState *dev)
329
+{
330
+ TZPPC *s = TZ_PPC(dev);
331
+
332
+ trace_tz_ppc_reset();
333
+ s->cfg_sec_resp = false;
334
+ memset(s->cfg_nonsec, 0, sizeof(s->cfg_nonsec));
335
+ memset(s->cfg_ap, 0, sizeof(s->cfg_ap));
336
+}
337
+
338
+static void tz_ppc_init(Object *obj)
339
+{
340
+ DeviceState *dev = DEVICE(obj);
341
+ TZPPC *s = TZ_PPC(obj);
342
+
343
+ qdev_init_gpio_in_named(dev, tz_ppc_cfg_nonsec, "cfg_nonsec", TZ_NUM_PORTS);
344
+ qdev_init_gpio_in_named(dev, tz_ppc_cfg_ap, "cfg_ap", TZ_NUM_PORTS);
345
+ qdev_init_gpio_in_named(dev, tz_ppc_cfg_sec_resp, "cfg_sec_resp", 1);
346
+ qdev_init_gpio_in_named(dev, tz_ppc_irq_enable, "irq_enable", 1);
347
+ qdev_init_gpio_in_named(dev, tz_ppc_irq_clear, "irq_clear", 1);
348
+ qdev_init_gpio_out_named(dev, &s->irq, "irq", 1);
349
+}
350
+
351
+static void tz_ppc_realize(DeviceState *dev, Error **errp)
352
+{
353
+ Object *obj = OBJECT(dev);
354
+ SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
355
+ TZPPC *s = TZ_PPC(dev);
356
+ int i;
357
+
358
+ /* We can't create the upstream end of the port until realize,
359
+ * as we don't know the size of the MR used as the downstream until then.
360
+ */
361
+ for (i = 0; i < TZ_NUM_PORTS; i++) {
362
+ TZPPCPort *port = &s->port[i];
363
+ char *name;
364
+ uint64_t size;
365
+
366
+ if (!port->downstream) {
367
+ continue;
368
+ }
369
+
370
+ name = g_strdup_printf("tz-ppc-port[%d]", i);
371
+
372
+ port->ppc = s;
373
+ address_space_init(&port->downstream_as, port->downstream, name);
374
+
375
+ size = memory_region_size(port->downstream);
376
+ memory_region_init_io(&port->upstream, obj, &tz_ppc_ops,
377
+ port, name, size);
378
+ sysbus_init_mmio(sbd, &port->upstream);
379
+ g_free(name);
380
+ }
381
+}
382
+
383
+static const VMStateDescription tz_ppc_vmstate = {
384
+ .name = "tz-ppc",
385
+ .version_id = 1,
386
+ .minimum_version_id = 1,
387
+ .fields = (VMStateField[]) {
388
+ VMSTATE_BOOL_ARRAY(cfg_nonsec, TZPPC, 16),
389
+ VMSTATE_BOOL_ARRAY(cfg_ap, TZPPC, 16),
390
+ VMSTATE_BOOL(cfg_sec_resp, TZPPC),
391
+ VMSTATE_BOOL(irq_enable, TZPPC),
392
+ VMSTATE_BOOL(irq_clear, TZPPC),
393
+ VMSTATE_BOOL(irq_status, TZPPC),
394
+ VMSTATE_END_OF_LIST()
395
+ }
396
+};
397
+
398
+#define DEFINE_PORT(N) \
399
+ DEFINE_PROP_LINK("port[" #N "]", TZPPC, port[N].downstream, \
400
+ TYPE_MEMORY_REGION, MemoryRegion *)
401
+
402
+static Property tz_ppc_properties[] = {
403
+ DEFINE_PROP_UINT32("NONSEC_MASK", TZPPC, nonsec_mask, 0),
404
+ DEFINE_PORT(0),
405
+ DEFINE_PORT(1),
406
+ DEFINE_PORT(2),
407
+ DEFINE_PORT(3),
408
+ DEFINE_PORT(4),
409
+ DEFINE_PORT(5),
410
+ DEFINE_PORT(6),
411
+ DEFINE_PORT(7),
412
+ DEFINE_PORT(8),
413
+ DEFINE_PORT(9),
414
+ DEFINE_PORT(10),
415
+ DEFINE_PORT(11),
416
+ DEFINE_PORT(12),
417
+ DEFINE_PORT(13),
418
+ DEFINE_PORT(14),
419
+ DEFINE_PORT(15),
420
+ DEFINE_PROP_END_OF_LIST(),
421
+};
422
+
423
+static void tz_ppc_class_init(ObjectClass *klass, void *data)
424
+{
425
+ DeviceClass *dc = DEVICE_CLASS(klass);
426
+
427
+ dc->realize = tz_ppc_realize;
428
+ dc->vmsd = &tz_ppc_vmstate;
429
+ dc->reset = tz_ppc_reset;
430
+ dc->props = tz_ppc_properties;
431
+}
432
+
433
+static const TypeInfo tz_ppc_info = {
434
+ .name = TYPE_TZ_PPC,
435
+ .parent = TYPE_SYS_BUS_DEVICE,
436
+ .instance_size = sizeof(TZPPC),
437
+ .instance_init = tz_ppc_init,
438
+ .class_init = tz_ppc_class_init,
439
+};
440
+
441
+static void tz_ppc_register_types(void)
442
+{
443
+ type_register_static(&tz_ppc_info);
444
+}
445
+
446
+type_init(tz_ppc_register_types);
447
diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
448
index XXXXXXX..XXXXXXX 100644
449
--- a/default-configs/arm-softmmu.mak
450
+++ b/default-configs/arm-softmmu.mak
451
@@ -XXX,XX +XXX,XX @@ CONFIG_CMSDK_APB_UART=y
452
CONFIG_MPS2_FPGAIO=y
453
CONFIG_MPS2_SCC=y
454
455
+CONFIG_TZ_PPC=y
456
+
457
CONFIG_VERSATILE_PCI=y
458
CONFIG_VERSATILE_I2C=y
459
460
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
461
index XXXXXXX..XXXXXXX 100644
462
--- a/hw/misc/trace-events
463
+++ b/hw/misc/trace-events
464
@@ -XXX,XX +XXX,XX @@ mos6522_get_next_irq_time(uint16_t latch, int64_t d, int64_t delta) "latch=%d co
465
mos6522_set_sr_int(void) "set sr_int"
466
mos6522_write(uint64_t addr, uint64_t val) "reg=0x%"PRIx64 " val=0x%"PRIx64
467
mos6522_read(uint64_t addr, unsigned val) "reg=0x%"PRIx64 " val=0x%x"
468
+
469
+# hw/misc/tz-ppc.c
470
+tz_ppc_reset(void) "TZ PPC: reset"
471
+tz_ppc_cfg_nonsec(int n, int level) "TZ PPC: cfg_nonsec[%d] = %d"
472
+tz_ppc_cfg_ap(int n, int level) "TZ PPC: cfg_ap[%d] = %d"
473
+tz_ppc_cfg_sec_resp(int level) "TZ PPC: cfg_sec_resp = %d"
474
+tz_ppc_irq_enable(int level) "TZ PPC: int_enable = %d"
475
+tz_ppc_irq_clear(int level) "TZ PPC: int_clear = %d"
476
+tz_ppc_update_irq(int level) "TZ PPC: setting irq line to %d"
477
+tz_ppc_read_blocked(int n, hwaddr offset, bool secure, bool user) "TZ PPC: port %d offset 0x%" HWADDR_PRIx " read (secure %d user %d) blocked"
478
+tz_ppc_write_blocked(int n, hwaddr offset, bool secure, bool user) "TZ PPC: port %d offset 0x%" HWADDR_PRIx " write (secure %d user %d) blocked"
479
--
293
--
480
2.16.2
294
2.20.1
481
295
482
296
diff view generated by jsdifflib
1
Model the Arm IoT Kit documented in
1
Instead of hardcoding the MachineClass default_ram_size and
2
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
2
default_ram_id fields, set them on class creation by finding the
3
3
entry in the RAMInfo array which is marked as being the QEMU system
4
The Arm IoT Kit is a subsystem which includes a CPU and some devices,
4
RAM.
5
and is intended be extended by adding extra devices to form a
6
complete system. It is used in the MPS2 board's AN505 image for the
7
Cortex-M33.
8
5
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
11
Message-id: 20180220180325.29818-19-peter.maydell@linaro.org
8
Message-id: 20210215115138.20465-18-peter.maydell@linaro.org
12
---
9
---
13
hw/arm/Makefile.objs | 1 +
10
hw/arm/mps2-tz.c | 24 ++++++++++++++++++++++--
14
include/hw/arm/iotkit.h | 109 ++++++++
11
1 file changed, 22 insertions(+), 2 deletions(-)
15
hw/arm/iotkit.c | 598 ++++++++++++++++++++++++++++++++++++++++
16
default-configs/arm-softmmu.mak | 1 +
17
4 files changed, 709 insertions(+)
18
create mode 100644 include/hw/arm/iotkit.h
19
create mode 100644 hw/arm/iotkit.c
20
12
21
diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
13
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
22
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
23
--- a/hw/arm/Makefile.objs
15
--- a/hw/arm/mps2-tz.c
24
+++ b/hw/arm/Makefile.objs
16
+++ b/hw/arm/mps2-tz.c
25
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_FSL_IMX6) += fsl-imx6.o sabrelite.o
17
@@ -XXX,XX +XXX,XX @@ static void mps2tz_class_init(ObjectClass *oc, void *data)
26
obj-$(CONFIG_ASPEED_SOC) += aspeed_soc.o aspeed.o
18
27
obj-$(CONFIG_MPS2) += mps2.o
19
mc->init = mps2tz_common_init;
28
obj-$(CONFIG_MSF2) += msf2-soc.o msf2-som.o
20
iic->check = mps2_tz_idau_check;
29
+obj-$(CONFIG_IOTKIT) += iotkit.o
21
- mc->default_ram_size = 16 * MiB;
30
diff --git a/include/hw/arm/iotkit.h b/include/hw/arm/iotkit.h
22
- mc->default_ram_id = "mps.ram";
31
new file mode 100644
32
index XXXXXXX..XXXXXXX
33
--- /dev/null
34
+++ b/include/hw/arm/iotkit.h
35
@@ -XXX,XX +XXX,XX @@
36
+/*
37
+ * ARM IoT Kit
38
+ *
39
+ * Copyright (c) 2018 Linaro Limited
40
+ * Written by Peter Maydell
41
+ *
42
+ * This program is free software; you can redistribute it and/or modify
43
+ * it under the terms of the GNU General Public License version 2 or
44
+ * (at your option) any later version.
45
+ */
46
+
47
+/* This is a model of the Arm IoT Kit which is documented in
48
+ * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
49
+ * It contains:
50
+ * a Cortex-M33
51
+ * the IDAU
52
+ * some timers and watchdogs
53
+ * two peripheral protection controllers
54
+ * a memory protection controller
55
+ * a security controller
56
+ * a bus fabric which arranges that some parts of the address
57
+ * space are secure and non-secure aliases of each other
58
+ *
59
+ * QEMU interface:
60
+ * + QOM property "memory" is a MemoryRegion containing the devices provided
61
+ * by the board model.
62
+ * + QOM property "MAINCLK" is the frequency of the main system clock
63
+ * + QOM property "EXP_NUMIRQ" sets the number of expansion interrupts
64
+ * + Named GPIO inputs "EXP_IRQ" 0..n are the expansion interrupts, which
65
+ * are wired to the NVIC lines 32 .. n+32
66
+ * Controlling up to 4 AHB expansion PPBs which a system using the IoTKit
67
+ * might provide:
68
+ * + named GPIO outputs apb_ppcexp{0,1,2,3}_nonsec[0..15]
69
+ * + named GPIO outputs apb_ppcexp{0,1,2,3}_ap[0..15]
70
+ * + named GPIO outputs apb_ppcexp{0,1,2,3}_irq_enable
71
+ * + named GPIO outputs apb_ppcexp{0,1,2,3}_irq_clear
72
+ * + named GPIO inputs apb_ppcexp{0,1,2,3}_irq_status
73
+ * Controlling each of the 4 expansion AHB PPCs which a system using the IoTKit
74
+ * might provide:
75
+ * + named GPIO outputs ahb_ppcexp{0,1,2,3}_nonsec[0..15]
76
+ * + named GPIO outputs ahb_ppcexp{0,1,2,3}_ap[0..15]
77
+ * + named GPIO outputs ahb_ppcexp{0,1,2,3}_irq_enable
78
+ * + named GPIO outputs ahb_ppcexp{0,1,2,3}_irq_clear
79
+ * + named GPIO inputs ahb_ppcexp{0,1,2,3}_irq_status
80
+ */
81
+
82
+#ifndef IOTKIT_H
83
+#define IOTKIT_H
84
+
85
+#include "hw/sysbus.h"
86
+#include "hw/arm/armv7m.h"
87
+#include "hw/misc/iotkit-secctl.h"
88
+#include "hw/misc/tz-ppc.h"
89
+#include "hw/timer/cmsdk-apb-timer.h"
90
+#include "hw/misc/unimp.h"
91
+#include "hw/or-irq.h"
92
+#include "hw/core/split-irq.h"
93
+
94
+#define TYPE_IOTKIT "iotkit"
95
+#define IOTKIT(obj) OBJECT_CHECK(IoTKit, (obj), TYPE_IOTKIT)
96
+
97
+/* We have an IRQ splitter and an OR gate input for each external PPC
98
+ * and the 2 internal PPCs
99
+ */
100
+#define NUM_EXTERNAL_PPCS (IOTS_NUM_AHB_EXP_PPC + IOTS_NUM_APB_EXP_PPC)
101
+#define NUM_PPCS (NUM_EXTERNAL_PPCS + 2)
102
+
103
+typedef struct IoTKit {
104
+ /*< private >*/
105
+ SysBusDevice parent_obj;
106
+
107
+ /*< public >*/
108
+ ARMv7MState armv7m;
109
+ IoTKitSecCtl secctl;
110
+ TZPPC apb_ppc0;
111
+ TZPPC apb_ppc1;
112
+ CMSDKAPBTIMER timer0;
113
+ CMSDKAPBTIMER timer1;
114
+ qemu_or_irq ppc_irq_orgate;
115
+ SplitIRQ sec_resp_splitter;
116
+ SplitIRQ ppc_irq_splitter[NUM_PPCS];
117
+
118
+ UnimplementedDeviceState dualtimer;
119
+ UnimplementedDeviceState s32ktimer;
120
+
121
+ MemoryRegion container;
122
+ MemoryRegion alias1;
123
+ MemoryRegion alias2;
124
+ MemoryRegion alias3;
125
+ MemoryRegion sram0;
126
+
127
+ qemu_irq *exp_irqs;
128
+ qemu_irq ppc0_irq;
129
+ qemu_irq ppc1_irq;
130
+ qemu_irq sec_resp_cfg;
131
+ qemu_irq sec_resp_cfg_in;
132
+ qemu_irq nsc_cfg_in;
133
+
134
+ qemu_irq irq_status_in[NUM_EXTERNAL_PPCS];
135
+
136
+ uint32_t nsccfg;
137
+
138
+ /* Properties */
139
+ MemoryRegion *board_memory;
140
+ uint32_t exp_numirq;
141
+ uint32_t mainclk_frq;
142
+} IoTKit;
143
+
144
+#endif
145
diff --git a/hw/arm/iotkit.c b/hw/arm/iotkit.c
146
new file mode 100644
147
index XXXXXXX..XXXXXXX
148
--- /dev/null
149
+++ b/hw/arm/iotkit.c
150
@@ -XXX,XX +XXX,XX @@
151
+/*
152
+ * Arm IoT Kit
153
+ *
154
+ * Copyright (c) 2018 Linaro Limited
155
+ * Written by Peter Maydell
156
+ *
157
+ * This program is free software; you can redistribute it and/or modify
158
+ * it under the terms of the GNU General Public License version 2 or
159
+ * (at your option) any later version.
160
+ */
161
+
162
+#include "qemu/osdep.h"
163
+#include "qemu/log.h"
164
+#include "qapi/error.h"
165
+#include "trace.h"
166
+#include "hw/sysbus.h"
167
+#include "hw/registerfields.h"
168
+#include "hw/arm/iotkit.h"
169
+#include "hw/misc/unimp.h"
170
+#include "hw/arm/arm.h"
171
+
172
+/* Create an alias region of @size bytes starting at @base
173
+ * which mirrors the memory starting at @orig.
174
+ */
175
+static void make_alias(IoTKit *s, MemoryRegion *mr, const char *name,
176
+ hwaddr base, hwaddr size, hwaddr orig)
177
+{
178
+ memory_region_init_alias(mr, NULL, name, &s->container, orig, size);
179
+ /* The alias is even lower priority than unimplemented_device regions */
180
+ memory_region_add_subregion_overlap(&s->container, base, mr, -1500);
181
+}
23
+}
182
+
24
+
183
+static void init_sysbus_child(Object *parent, const char *childname,
25
+static void mps2tz_set_default_ram_info(MPS2TZMachineClass *mmc)
184
+ void *child, size_t childsize,
185
+ const char *childtype)
186
+{
26
+{
187
+ object_initialize(child, childsize, childtype);
27
+ /*
188
+ object_property_add_child(parent, childname, OBJECT(child), &error_abort);
28
+ * Set mc->default_ram_size and default_ram_id from the
189
+ qdev_set_parent_bus(DEVICE(child), sysbus_get_default());
29
+ * information in mmc->raminfo.
190
+}
30
+ */
31
+ MachineClass *mc = MACHINE_CLASS(mmc);
32
+ const RAMInfo *p;
191
+
33
+
192
+static void irq_status_forwarder(void *opaque, int n, int level)
34
+ for (p = mmc->raminfo; p->name; p++) {
193
+{
35
+ if (p->mrindex < 0) {
194
+ qemu_irq destirq = opaque;
36
+ /* Found the entry for "system memory" */
195
+
37
+ mc->default_ram_size = p->size;
196
+ qemu_set_irq(destirq, level);
38
+ mc->default_ram_id = p->name;
197
+}
198
+
199
+static void nsccfg_handler(void *opaque, int n, int level)
200
+{
201
+ IoTKit *s = IOTKIT(opaque);
202
+
203
+ s->nsccfg = level;
204
+}
205
+
206
+static void iotkit_forward_ppc(IoTKit *s, const char *ppcname, int ppcnum)
207
+{
208
+ /* Each of the 4 AHB and 4 APB PPCs that might be present in a
209
+ * system using the IoTKit has a collection of control lines which
210
+ * are provided by the security controller and which we want to
211
+ * expose as control lines on the IoTKit device itself, so the
212
+ * code using the IoTKit can wire them up to the PPCs.
213
+ */
214
+ SplitIRQ *splitter = &s->ppc_irq_splitter[ppcnum];
215
+ DeviceState *iotkitdev = DEVICE(s);
216
+ DeviceState *dev_secctl = DEVICE(&s->secctl);
217
+ DeviceState *dev_splitter = DEVICE(splitter);
218
+ char *name;
219
+
220
+ name = g_strdup_printf("%s_nonsec", ppcname);
221
+ qdev_pass_gpios(dev_secctl, iotkitdev, name);
222
+ g_free(name);
223
+ name = g_strdup_printf("%s_ap", ppcname);
224
+ qdev_pass_gpios(dev_secctl, iotkitdev, name);
225
+ g_free(name);
226
+ name = g_strdup_printf("%s_irq_enable", ppcname);
227
+ qdev_pass_gpios(dev_secctl, iotkitdev, name);
228
+ g_free(name);
229
+ name = g_strdup_printf("%s_irq_clear", ppcname);
230
+ qdev_pass_gpios(dev_secctl, iotkitdev, name);
231
+ g_free(name);
232
+
233
+ /* irq_status is a little more tricky, because we need to
234
+ * split it so we can send it both to the security controller
235
+ * and to our OR gate for the NVIC interrupt line.
236
+ * Connect up the splitter's outputs, and create a GPIO input
237
+ * which will pass the line state to the input splitter.
238
+ */
239
+ name = g_strdup_printf("%s_irq_status", ppcname);
240
+ qdev_connect_gpio_out(dev_splitter, 0,
241
+ qdev_get_gpio_in_named(dev_secctl,
242
+ name, 0));
243
+ qdev_connect_gpio_out(dev_splitter, 1,
244
+ qdev_get_gpio_in(DEVICE(&s->ppc_irq_orgate), ppcnum));
245
+ s->irq_status_in[ppcnum] = qdev_get_gpio_in(dev_splitter, 0);
246
+ qdev_init_gpio_in_named_with_opaque(iotkitdev, irq_status_forwarder,
247
+ s->irq_status_in[ppcnum], name, 1);
248
+ g_free(name);
249
+}
250
+
251
+static void iotkit_forward_sec_resp_cfg(IoTKit *s)
252
+{
253
+ /* Forward the 3rd output from the splitter device as a
254
+ * named GPIO output of the iotkit object.
255
+ */
256
+ DeviceState *dev = DEVICE(s);
257
+ DeviceState *dev_splitter = DEVICE(&s->sec_resp_splitter);
258
+
259
+ qdev_init_gpio_out_named(dev, &s->sec_resp_cfg, "sec_resp_cfg", 1);
260
+ s->sec_resp_cfg_in = qemu_allocate_irq(irq_status_forwarder,
261
+ s->sec_resp_cfg, 1);
262
+ qdev_connect_gpio_out(dev_splitter, 2, s->sec_resp_cfg_in);
263
+}
264
+
265
+static void iotkit_init(Object *obj)
266
+{
267
+ IoTKit *s = IOTKIT(obj);
268
+ int i;
269
+
270
+ memory_region_init(&s->container, obj, "iotkit-container", UINT64_MAX);
271
+
272
+ init_sysbus_child(obj, "armv7m", &s->armv7m, sizeof(s->armv7m),
273
+ TYPE_ARMV7M);
274
+ qdev_prop_set_string(DEVICE(&s->armv7m), "cpu-type",
275
+ ARM_CPU_TYPE_NAME("cortex-m33"));
276
+
277
+ init_sysbus_child(obj, "secctl", &s->secctl, sizeof(s->secctl),
278
+ TYPE_IOTKIT_SECCTL);
279
+ init_sysbus_child(obj, "apb-ppc0", &s->apb_ppc0, sizeof(s->apb_ppc0),
280
+ TYPE_TZ_PPC);
281
+ init_sysbus_child(obj, "apb-ppc1", &s->apb_ppc1, sizeof(s->apb_ppc1),
282
+ TYPE_TZ_PPC);
283
+ init_sysbus_child(obj, "timer0", &s->timer0, sizeof(s->timer0),
284
+ TYPE_CMSDK_APB_TIMER);
285
+ init_sysbus_child(obj, "timer1", &s->timer1, sizeof(s->timer1),
286
+ TYPE_CMSDK_APB_TIMER);
287
+ init_sysbus_child(obj, "dualtimer", &s->dualtimer, sizeof(s->dualtimer),
288
+ TYPE_UNIMPLEMENTED_DEVICE);
289
+ object_initialize(&s->ppc_irq_orgate, sizeof(s->ppc_irq_orgate),
290
+ TYPE_OR_IRQ);
291
+ object_property_add_child(obj, "ppc-irq-orgate",
292
+ OBJECT(&s->ppc_irq_orgate), &error_abort);
293
+ object_initialize(&s->sec_resp_splitter, sizeof(s->sec_resp_splitter),
294
+ TYPE_SPLIT_IRQ);
295
+ object_property_add_child(obj, "sec-resp-splitter",
296
+ OBJECT(&s->sec_resp_splitter), &error_abort);
297
+ for (i = 0; i < ARRAY_SIZE(s->ppc_irq_splitter); i++) {
298
+ char *name = g_strdup_printf("ppc-irq-splitter-%d", i);
299
+ SplitIRQ *splitter = &s->ppc_irq_splitter[i];
300
+
301
+ object_initialize(splitter, sizeof(*splitter), TYPE_SPLIT_IRQ);
302
+ object_property_add_child(obj, name, OBJECT(splitter), &error_abort);
303
+ }
304
+ init_sysbus_child(obj, "s32ktimer", &s->s32ktimer, sizeof(s->s32ktimer),
305
+ TYPE_UNIMPLEMENTED_DEVICE);
306
+}
307
+
308
+static void iotkit_exp_irq(void *opaque, int n, int level)
309
+{
310
+ IoTKit *s = IOTKIT(opaque);
311
+
312
+ qemu_set_irq(s->exp_irqs[n], level);
313
+}
314
+
315
+static void iotkit_realize(DeviceState *dev, Error **errp)
316
+{
317
+ IoTKit *s = IOTKIT(dev);
318
+ int i;
319
+ MemoryRegion *mr;
320
+ Error *err = NULL;
321
+ SysBusDevice *sbd_apb_ppc0;
322
+ SysBusDevice *sbd_secctl;
323
+ DeviceState *dev_apb_ppc0;
324
+ DeviceState *dev_apb_ppc1;
325
+ DeviceState *dev_secctl;
326
+ DeviceState *dev_splitter;
327
+
328
+ if (!s->board_memory) {
329
+ error_setg(errp, "memory property was not set");
330
+ return;
331
+ }
332
+
333
+ if (!s->mainclk_frq) {
334
+ error_setg(errp, "MAINCLK property was not set");
335
+ return;
336
+ }
337
+
338
+ /* Handling of which devices should be available only to secure
339
+ * code is usually done differently for M profile than for A profile.
340
+ * Instead of putting some devices only into the secure address space,
341
+ * devices exist in both address spaces but with hard-wired security
342
+ * permissions that will cause the CPU to fault for non-secure accesses.
343
+ *
344
+ * The IoTKit has an IDAU (Implementation Defined Access Unit),
345
+ * which specifies hard-wired security permissions for different
346
+ * areas of the physical address space. For the IoTKit IDAU, the
347
+ * top 4 bits of the physical address are the IDAU region ID, and
348
+ * if bit 28 (ie the lowest bit of the ID) is 0 then this is an NS
349
+ * region, otherwise it is an S region.
350
+ *
351
+ * The various devices and RAMs are generally all mapped twice,
352
+ * once into a region that the IDAU defines as secure and once
353
+ * into a non-secure region. They sit behind either a Memory
354
+ * Protection Controller (for RAM) or a Peripheral Protection
355
+ * Controller (for devices), which allow a more fine grained
356
+ * configuration of whether non-secure accesses are permitted.
357
+ *
358
+ * (The other place that guest software can configure security
359
+ * permissions is in the architected SAU (Security Attribution
360
+ * Unit), which is entirely inside the CPU. The IDAU can upgrade
361
+ * the security attributes for a region to more restrictive than
362
+ * the SAU specifies, but cannot downgrade them.)
363
+ *
364
+ * 0x10000000..0x1fffffff alias of 0x00000000..0x0fffffff
365
+ * 0x20000000..0x2007ffff 32KB FPGA block RAM
366
+ * 0x30000000..0x3fffffff alias of 0x20000000..0x2fffffff
367
+ * 0x40000000..0x4000ffff base peripheral region 1
368
+ * 0x40010000..0x4001ffff CPU peripherals (none for IoTKit)
369
+ * 0x40020000..0x4002ffff system control element peripherals
370
+ * 0x40080000..0x400fffff base peripheral region 2
371
+ * 0x50000000..0x5fffffff alias of 0x40000000..0x4fffffff
372
+ */
373
+
374
+ memory_region_add_subregion_overlap(&s->container, 0, s->board_memory, -1);
375
+
376
+ qdev_prop_set_uint32(DEVICE(&s->armv7m), "num-irq", s->exp_numirq + 32);
377
+ /* In real hardware the initial Secure VTOR is set from the INITSVTOR0
378
+ * register in the IoT Kit System Control Register block, and the
379
+ * initial value of that is in turn specifiable by the FPGA that
380
+ * instantiates the IoT Kit. In QEMU we don't implement this wrinkle,
381
+ * and simply set the CPU's init-svtor to the IoT Kit default value.
382
+ */
383
+ qdev_prop_set_uint32(DEVICE(&s->armv7m), "init-svtor", 0x10000000);
384
+ object_property_set_link(OBJECT(&s->armv7m), OBJECT(&s->container),
385
+ "memory", &err);
386
+ if (err) {
387
+ error_propagate(errp, err);
388
+ return;
389
+ }
390
+ object_property_set_link(OBJECT(&s->armv7m), OBJECT(s), "idau", &err);
391
+ if (err) {
392
+ error_propagate(errp, err);
393
+ return;
394
+ }
395
+ object_property_set_bool(OBJECT(&s->armv7m), true, "realized", &err);
396
+ if (err) {
397
+ error_propagate(errp, err);
398
+ return;
399
+ }
400
+
401
+ /* Connect our EXP_IRQ GPIOs to the NVIC's lines 32 and up. */
402
+ s->exp_irqs = g_new(qemu_irq, s->exp_numirq);
403
+ for (i = 0; i < s->exp_numirq; i++) {
404
+ s->exp_irqs[i] = qdev_get_gpio_in(DEVICE(&s->armv7m), i + 32);
405
+ }
406
+ qdev_init_gpio_in_named(dev, iotkit_exp_irq, "EXP_IRQ", s->exp_numirq);
407
+
408
+ /* Set up the big aliases first */
409
+ make_alias(s, &s->alias1, "alias 1", 0x10000000, 0x10000000, 0x00000000);
410
+ make_alias(s, &s->alias2, "alias 2", 0x30000000, 0x10000000, 0x20000000);
411
+ /* The 0x50000000..0x5fffffff region is not a pure alias: it has
412
+ * a few extra devices that only appear there (generally the
413
+ * control interfaces for the protection controllers).
414
+ * We implement this by mapping those devices over the top of this
415
+ * alias MR at a higher priority.
416
+ */
417
+ make_alias(s, &s->alias3, "alias 3", 0x50000000, 0x10000000, 0x40000000);
418
+
419
+ /* This RAM should be behind a Memory Protection Controller, but we
420
+ * don't implement that yet.
421
+ */
422
+ memory_region_init_ram(&s->sram0, NULL, "iotkit.sram0", 0x00008000, &err);
423
+ if (err) {
424
+ error_propagate(errp, err);
425
+ return;
426
+ }
427
+ memory_region_add_subregion(&s->container, 0x20000000, &s->sram0);
428
+
429
+ /* Security controller */
430
+ object_property_set_bool(OBJECT(&s->secctl), true, "realized", &err);
431
+ if (err) {
432
+ error_propagate(errp, err);
433
+ return;
434
+ }
435
+ sbd_secctl = SYS_BUS_DEVICE(&s->secctl);
436
+ dev_secctl = DEVICE(&s->secctl);
437
+ sysbus_mmio_map(sbd_secctl, 0, 0x50080000);
438
+ sysbus_mmio_map(sbd_secctl, 1, 0x40080000);
439
+
440
+ s->nsc_cfg_in = qemu_allocate_irq(nsccfg_handler, s, 1);
441
+ qdev_connect_gpio_out_named(dev_secctl, "nsc_cfg", 0, s->nsc_cfg_in);
442
+
443
+ /* The sec_resp_cfg output from the security controller must be split into
444
+ * multiple lines, one for each of the PPCs within the IoTKit and one
445
+ * that will be an output from the IoTKit to the system.
446
+ */
447
+ object_property_set_int(OBJECT(&s->sec_resp_splitter), 3,
448
+ "num-lines", &err);
449
+ if (err) {
450
+ error_propagate(errp, err);
451
+ return;
452
+ }
453
+ object_property_set_bool(OBJECT(&s->sec_resp_splitter), true,
454
+ "realized", &err);
455
+ if (err) {
456
+ error_propagate(errp, err);
457
+ return;
458
+ }
459
+ dev_splitter = DEVICE(&s->sec_resp_splitter);
460
+ qdev_connect_gpio_out_named(dev_secctl, "sec_resp_cfg", 0,
461
+ qdev_get_gpio_in(dev_splitter, 0));
462
+
463
+ /* Devices behind APB PPC0:
464
+ * 0x40000000: timer0
465
+ * 0x40001000: timer1
466
+ * 0x40002000: dual timer
467
+ * We must configure and realize each downstream device and connect
468
+ * it to the appropriate PPC port; then we can realize the PPC and
469
+ * map its upstream ends to the right place in the container.
470
+ */
471
+ qdev_prop_set_uint32(DEVICE(&s->timer0), "pclk-frq", s->mainclk_frq);
472
+ object_property_set_bool(OBJECT(&s->timer0), true, "realized", &err);
473
+ if (err) {
474
+ error_propagate(errp, err);
475
+ return;
476
+ }
477
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->timer0), 0,
478
+ qdev_get_gpio_in(DEVICE(&s->armv7m), 3));
479
+ mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->timer0), 0);
480
+ object_property_set_link(OBJECT(&s->apb_ppc0), OBJECT(mr), "port[0]", &err);
481
+ if (err) {
482
+ error_propagate(errp, err);
483
+ return;
484
+ }
485
+
486
+ qdev_prop_set_uint32(DEVICE(&s->timer1), "pclk-frq", s->mainclk_frq);
487
+ object_property_set_bool(OBJECT(&s->timer1), true, "realized", &err);
488
+ if (err) {
489
+ error_propagate(errp, err);
490
+ return;
491
+ }
492
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->timer1), 0,
493
+ qdev_get_gpio_in(DEVICE(&s->armv7m), 3));
494
+ mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->timer1), 0);
495
+ object_property_set_link(OBJECT(&s->apb_ppc0), OBJECT(mr), "port[1]", &err);
496
+ if (err) {
497
+ error_propagate(errp, err);
498
+ return;
499
+ }
500
+
501
+ qdev_prop_set_string(DEVICE(&s->dualtimer), "name", "Dual timer");
502
+ qdev_prop_set_uint64(DEVICE(&s->dualtimer), "size", 0x1000);
503
+ object_property_set_bool(OBJECT(&s->dualtimer), true, "realized", &err);
504
+ if (err) {
505
+ error_propagate(errp, err);
506
+ return;
507
+ }
508
+ mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->dualtimer), 0);
509
+ object_property_set_link(OBJECT(&s->apb_ppc0), OBJECT(mr), "port[2]", &err);
510
+ if (err) {
511
+ error_propagate(errp, err);
512
+ return;
513
+ }
514
+
515
+ object_property_set_bool(OBJECT(&s->apb_ppc0), true, "realized", &err);
516
+ if (err) {
517
+ error_propagate(errp, err);
518
+ return;
519
+ }
520
+
521
+ sbd_apb_ppc0 = SYS_BUS_DEVICE(&s->apb_ppc0);
522
+ dev_apb_ppc0 = DEVICE(&s->apb_ppc0);
523
+
524
+ mr = sysbus_mmio_get_region(sbd_apb_ppc0, 0);
525
+ memory_region_add_subregion(&s->container, 0x40000000, mr);
526
+ mr = sysbus_mmio_get_region(sbd_apb_ppc0, 1);
527
+ memory_region_add_subregion(&s->container, 0x40001000, mr);
528
+ mr = sysbus_mmio_get_region(sbd_apb_ppc0, 2);
529
+ memory_region_add_subregion(&s->container, 0x40002000, mr);
530
+ for (i = 0; i < IOTS_APB_PPC0_NUM_PORTS; i++) {
531
+ qdev_connect_gpio_out_named(dev_secctl, "apb_ppc0_nonsec", i,
532
+ qdev_get_gpio_in_named(dev_apb_ppc0,
533
+ "cfg_nonsec", i));
534
+ qdev_connect_gpio_out_named(dev_secctl, "apb_ppc0_ap", i,
535
+ qdev_get_gpio_in_named(dev_apb_ppc0,
536
+ "cfg_ap", i));
537
+ }
538
+ qdev_connect_gpio_out_named(dev_secctl, "apb_ppc0_irq_enable", 0,
539
+ qdev_get_gpio_in_named(dev_apb_ppc0,
540
+ "irq_enable", 0));
541
+ qdev_connect_gpio_out_named(dev_secctl, "apb_ppc0_irq_clear", 0,
542
+ qdev_get_gpio_in_named(dev_apb_ppc0,
543
+ "irq_clear", 0));
544
+ qdev_connect_gpio_out(dev_splitter, 0,
545
+ qdev_get_gpio_in_named(dev_apb_ppc0,
546
+ "cfg_sec_resp", 0));
547
+
548
+ /* All the PPC irq lines (from the 2 internal PPCs and the 8 external
549
+ * ones) are sent individually to the security controller, and also
550
+ * ORed together to give a single combined PPC interrupt to the NVIC.
551
+ */
552
+ object_property_set_int(OBJECT(&s->ppc_irq_orgate),
553
+ NUM_PPCS, "num-lines", &err);
554
+ if (err) {
555
+ error_propagate(errp, err);
556
+ return;
557
+ }
558
+ object_property_set_bool(OBJECT(&s->ppc_irq_orgate), true,
559
+ "realized", &err);
560
+ if (err) {
561
+ error_propagate(errp, err);
562
+ return;
563
+ }
564
+ qdev_connect_gpio_out(DEVICE(&s->ppc_irq_orgate), 0,
565
+ qdev_get_gpio_in(DEVICE(&s->armv7m), 10));
566
+
567
+ /* 0x40010000 .. 0x4001ffff: private CPU region: unused in IoTKit */
568
+
569
+ /* 0x40020000 .. 0x4002ffff : IoTKit system control peripheral region */
570
+ /* Devices behind APB PPC1:
571
+ * 0x4002f000: S32K timer
572
+ */
573
+ qdev_prop_set_string(DEVICE(&s->s32ktimer), "name", "S32KTIMER");
574
+ qdev_prop_set_uint64(DEVICE(&s->s32ktimer), "size", 0x1000);
575
+ object_property_set_bool(OBJECT(&s->s32ktimer), true, "realized", &err);
576
+ if (err) {
577
+ error_propagate(errp, err);
578
+ return;
579
+ }
580
+ mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->s32ktimer), 0);
581
+ object_property_set_link(OBJECT(&s->apb_ppc1), OBJECT(mr), "port[0]", &err);
582
+ if (err) {
583
+ error_propagate(errp, err);
584
+ return;
585
+ }
586
+
587
+ object_property_set_bool(OBJECT(&s->apb_ppc1), true, "realized", &err);
588
+ if (err) {
589
+ error_propagate(errp, err);
590
+ return;
591
+ }
592
+ mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->apb_ppc1), 0);
593
+ memory_region_add_subregion(&s->container, 0x4002f000, mr);
594
+
595
+ dev_apb_ppc1 = DEVICE(&s->apb_ppc1);
596
+ qdev_connect_gpio_out_named(dev_secctl, "apb_ppc1_nonsec", 0,
597
+ qdev_get_gpio_in_named(dev_apb_ppc1,
598
+ "cfg_nonsec", 0));
599
+ qdev_connect_gpio_out_named(dev_secctl, "apb_ppc1_ap", 0,
600
+ qdev_get_gpio_in_named(dev_apb_ppc1,
601
+ "cfg_ap", 0));
602
+ qdev_connect_gpio_out_named(dev_secctl, "apb_ppc1_irq_enable", 0,
603
+ qdev_get_gpio_in_named(dev_apb_ppc1,
604
+ "irq_enable", 0));
605
+ qdev_connect_gpio_out_named(dev_secctl, "apb_ppc1_irq_clear", 0,
606
+ qdev_get_gpio_in_named(dev_apb_ppc1,
607
+ "irq_clear", 0));
608
+ qdev_connect_gpio_out(dev_splitter, 1,
609
+ qdev_get_gpio_in_named(dev_apb_ppc1,
610
+ "cfg_sec_resp", 0));
611
+
612
+ /* Using create_unimplemented_device() maps the stub into the
613
+ * system address space rather than into our container, but the
614
+ * overall effect to the guest is the same.
615
+ */
616
+ create_unimplemented_device("SYSINFO", 0x40020000, 0x1000);
617
+
618
+ create_unimplemented_device("SYSCONTROL", 0x50021000, 0x1000);
619
+ create_unimplemented_device("S32KWATCHDOG", 0x5002e000, 0x1000);
620
+
621
+ /* 0x40080000 .. 0x4008ffff : IoTKit second Base peripheral region */
622
+
623
+ create_unimplemented_device("NS watchdog", 0x40081000, 0x1000);
624
+ create_unimplemented_device("S watchdog", 0x50081000, 0x1000);
625
+
626
+ create_unimplemented_device("SRAM0 MPC", 0x50083000, 0x1000);
627
+
628
+ for (i = 0; i < ARRAY_SIZE(s->ppc_irq_splitter); i++) {
629
+ Object *splitter = OBJECT(&s->ppc_irq_splitter[i]);
630
+
631
+ object_property_set_int(splitter, 2, "num-lines", &err);
632
+ if (err) {
633
+ error_propagate(errp, err);
634
+ return;
635
+ }
636
+ object_property_set_bool(splitter, true, "realized", &err);
637
+ if (err) {
638
+ error_propagate(errp, err);
639
+ return;
39
+ return;
640
+ }
40
+ }
641
+ }
41
+ }
642
+
42
+ g_assert_not_reached();
643
+ for (i = 0; i < IOTS_NUM_AHB_EXP_PPC; i++) {
43
}
644
+ char *ppcname = g_strdup_printf("ahb_ppcexp%d", i);
44
645
+
45
static void mps2tz_an505_class_init(ObjectClass *oc, void *data)
646
+ iotkit_forward_ppc(s, ppcname, i);
46
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an505_class_init(ObjectClass *oc, void *data)
647
+ g_free(ppcname);
47
mmc->numirq = 92;
648
+ }
48
mmc->raminfo = an505_raminfo;
649
+
49
mmc->armsse_type = TYPE_IOTKIT;
650
+ for (i = 0; i < IOTS_NUM_APB_EXP_PPC; i++) {
50
+ mps2tz_set_default_ram_info(mmc);
651
+ char *ppcname = g_strdup_printf("apb_ppcexp%d", i);
51
}
652
+
52
653
+ iotkit_forward_ppc(s, ppcname, i + IOTS_NUM_AHB_EXP_PPC);
53
static void mps2tz_an521_class_init(ObjectClass *oc, void *data)
654
+ g_free(ppcname);
54
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an521_class_init(ObjectClass *oc, void *data)
655
+ }
55
mmc->numirq = 92;
656
+
56
mmc->raminfo = an505_raminfo; /* AN521 is the same as AN505 here */
657
+ for (i = NUM_EXTERNAL_PPCS; i < NUM_PPCS; i++) {
57
mmc->armsse_type = TYPE_SSE200;
658
+ /* Wire up IRQ splitter for internal PPCs */
58
+ mps2tz_set_default_ram_info(mmc);
659
+ DeviceState *devs = DEVICE(&s->ppc_irq_splitter[i]);
59
}
660
+ char *gpioname = g_strdup_printf("apb_ppc%d_irq_status",
60
661
+ i - NUM_EXTERNAL_PPCS);
61
static const TypeInfo mps2tz_info = {
662
+ TZPPC *ppc = (i == NUM_EXTERNAL_PPCS) ? &s->apb_ppc0 : &s->apb_ppc1;
663
+
664
+ qdev_connect_gpio_out(devs, 0,
665
+ qdev_get_gpio_in_named(dev_secctl, gpioname, 0));
666
+ qdev_connect_gpio_out(devs, 1,
667
+ qdev_get_gpio_in(DEVICE(&s->ppc_irq_orgate), i));
668
+ qdev_connect_gpio_out_named(DEVICE(ppc), "irq", 0,
669
+ qdev_get_gpio_in(devs, 0));
670
+ }
671
+
672
+ iotkit_forward_sec_resp_cfg(s);
673
+
674
+ system_clock_scale = NANOSECONDS_PER_SECOND / s->mainclk_frq;
675
+}
676
+
677
+static void iotkit_idau_check(IDAUInterface *ii, uint32_t address,
678
+ int *iregion, bool *exempt, bool *ns, bool *nsc)
679
+{
680
+ /* For IoTKit systems the IDAU responses are simple logical functions
681
+ * of the address bits. The NSC attribute is guest-adjustable via the
682
+ * NSCCFG register in the security controller.
683
+ */
684
+ IoTKit *s = IOTKIT(ii);
685
+ int region = extract32(address, 28, 4);
686
+
687
+ *ns = !(region & 1);
688
+ *nsc = (region == 1 && (s->nsccfg & 1)) || (region == 3 && (s->nsccfg & 2));
689
+ /* 0xe0000000..0xe00fffff and 0xf0000000..0xf00fffff are exempt */
690
+ *exempt = (address & 0xeff00000) == 0xe0000000;
691
+ *iregion = region;
692
+}
693
+
694
+static const VMStateDescription iotkit_vmstate = {
695
+ .name = "iotkit",
696
+ .version_id = 1,
697
+ .minimum_version_id = 1,
698
+ .fields = (VMStateField[]) {
699
+ VMSTATE_UINT32(nsccfg, IoTKit),
700
+ VMSTATE_END_OF_LIST()
701
+ }
702
+};
703
+
704
+static Property iotkit_properties[] = {
705
+ DEFINE_PROP_LINK("memory", IoTKit, board_memory, TYPE_MEMORY_REGION,
706
+ MemoryRegion *),
707
+ DEFINE_PROP_UINT32("EXP_NUMIRQ", IoTKit, exp_numirq, 64),
708
+ DEFINE_PROP_UINT32("MAINCLK", IoTKit, mainclk_frq, 0),
709
+ DEFINE_PROP_END_OF_LIST()
710
+};
711
+
712
+static void iotkit_reset(DeviceState *dev)
713
+{
714
+ IoTKit *s = IOTKIT(dev);
715
+
716
+ s->nsccfg = 0;
717
+}
718
+
719
+static void iotkit_class_init(ObjectClass *klass, void *data)
720
+{
721
+ DeviceClass *dc = DEVICE_CLASS(klass);
722
+ IDAUInterfaceClass *iic = IDAU_INTERFACE_CLASS(klass);
723
+
724
+ dc->realize = iotkit_realize;
725
+ dc->vmsd = &iotkit_vmstate;
726
+ dc->props = iotkit_properties;
727
+ dc->reset = iotkit_reset;
728
+ iic->check = iotkit_idau_check;
729
+}
730
+
731
+static const TypeInfo iotkit_info = {
732
+ .name = TYPE_IOTKIT,
733
+ .parent = TYPE_SYS_BUS_DEVICE,
734
+ .instance_size = sizeof(IoTKit),
735
+ .instance_init = iotkit_init,
736
+ .class_init = iotkit_class_init,
737
+ .interfaces = (InterfaceInfo[]) {
738
+ { TYPE_IDAU_INTERFACE },
739
+ { }
740
+ }
741
+};
742
+
743
+static void iotkit_register_types(void)
744
+{
745
+ type_register_static(&iotkit_info);
746
+}
747
+
748
+type_init(iotkit_register_types);
749
diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
750
index XXXXXXX..XXXXXXX 100644
751
--- a/default-configs/arm-softmmu.mak
752
+++ b/default-configs/arm-softmmu.mak
753
@@ -XXX,XX +XXX,XX @@ CONFIG_MPS2_FPGAIO=y
754
CONFIG_MPS2_SCC=y
755
756
CONFIG_TZ_PPC=y
757
+CONFIG_IOTKIT=y
758
CONFIG_IOTKIT_SECCTL=y
759
760
CONFIG_VERSATILE_PCI=y
761
--
62
--
762
2.16.2
63
2.20.1
763
64
764
65
diff view generated by jsdifflib
1
The Cortex-M33 allows the system to specify the reset value of the
1
The AN505 and AN521 don't have any read-only memory, but the AN524
2
secure Vector Table Offset Register (VTOR) by asserting config
2
does; add a flag to ROMInfo to mark a region as ROM.
3
signals. In particular, guest images for the MPS2 AN505 board rely
4
on the MPS2's initial VTOR being correct for that board.
5
Implement a QEMU property so board and SoC code can set the reset
6
value to the correct value.
7
3
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
Message-id: 20180220180325.29818-7-peter.maydell@linaro.org
6
Message-id: 20210215115138.20465-19-peter.maydell@linaro.org
11
---
7
---
12
target/arm/cpu.h | 3 +++
8
hw/arm/mps2-tz.c | 6 ++++++
13
target/arm/cpu.c | 18 ++++++++++++++----
9
1 file changed, 6 insertions(+)
14
2 files changed, 17 insertions(+), 4 deletions(-)
15
10
16
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
11
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
17
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
18
--- a/target/arm/cpu.h
13
--- a/hw/arm/mps2-tz.c
19
+++ b/target/arm/cpu.h
14
+++ b/hw/arm/mps2-tz.c
20
@@ -XXX,XX +XXX,XX @@ struct ARMCPU {
15
@@ -XXX,XX +XXX,XX @@ typedef struct RAMInfo {
21
*/
16
* Flag values:
22
uint32_t psci_conduit;
17
* IS_ALIAS: this RAM area is an alias to the upstream end of the
23
18
* MPC specified by its .mpc value
24
+ /* For v8M, initial value of the Secure VTOR */
19
+ * IS_ROM: this RAM area is read-only
25
+ uint32_t init_svtor;
20
*/
26
+
21
#define IS_ALIAS 1
27
/* [QEMU_]KVM_ARM_TARGET_* constant for this CPU, or
22
+#define IS_ROM 2
28
* QEMU_KVM_ARM_TARGET_NONE if the kernel doesn't support this CPU type.
23
29
*/
24
struct MPS2TZMachineClass {
30
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
25
MachineClass parent;
31
index XXXXXXX..XXXXXXX 100644
26
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *mr_for_raminfo(MPS2TZMachineState *mms,
32
--- a/target/arm/cpu.c
27
if (raminfo->mrindex < 0) {
33
+++ b/target/arm/cpu.c
28
/* Means this RAMInfo is for QEMU's "system memory" */
34
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(CPUState *s)
29
MachineState *machine = MACHINE(mms);
35
uint32_t initial_msp; /* Loaded from 0x0 */
30
+ assert(!(raminfo->flags & IS_ROM));
36
uint32_t initial_pc; /* Loaded from 0x4 */
31
return machine->ram;
37
uint8_t *rom;
38
+ uint32_t vecbase;
39
40
if (arm_feature(env, ARM_FEATURE_M_SECURITY)) {
41
env->v7m.secure = true;
42
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(CPUState *s)
43
/* Unlike A/R profile, M profile defines the reset LR value */
44
env->regs[14] = 0xffffffff;
45
46
- /* Load the initial SP and PC from the vector table at address 0 */
47
- rom = rom_ptr(0);
48
+ env->v7m.vecbase[M_REG_S] = cpu->init_svtor & 0xffffff80;
49
+
50
+ /* Load the initial SP and PC from offset 0 and 4 in the vector table */
51
+ vecbase = env->v7m.vecbase[env->v7m.secure];
52
+ rom = rom_ptr(vecbase);
53
if (rom) {
54
/* Address zero is covered by ROM which hasn't yet been
55
* copied into physical memory.
56
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(CPUState *s)
57
* it got copied into memory. In the latter case, rom_ptr
58
* will return a NULL pointer and we should use ldl_phys instead.
59
*/
60
- initial_msp = ldl_phys(s->as, 0);
61
- initial_pc = ldl_phys(s->as, 4);
62
+ initial_msp = ldl_phys(s->as, vecbase);
63
+ initial_pc = ldl_phys(s->as, vecbase + 4);
64
}
65
66
env->regs[13] = initial_msp & 0xFFFFFFFC;
67
@@ -XXX,XX +XXX,XX @@ static Property arm_cpu_pmsav7_dregion_property =
68
pmsav7_dregion,
69
qdev_prop_uint32, uint32_t);
70
71
+/* M profile: initial value of the Secure VTOR */
72
+static Property arm_cpu_initsvtor_property =
73
+ DEFINE_PROP_UINT32("init-svtor", ARMCPU, init_svtor, 0);
74
+
75
static void arm_cpu_post_init(Object *obj)
76
{
77
ARMCPU *cpu = ARM_CPU(obj);
78
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_post_init(Object *obj)
79
qdev_prop_allow_set_link_before_realize,
80
OBJ_PROP_LINK_UNREF_ON_RELEASE,
81
&error_abort);
82
+ qdev_property_add_static(DEVICE(obj), &arm_cpu_initsvtor_property,
83
+ &error_abort);
84
}
32
}
85
33
86
qdev_property_add_static(DEVICE(obj), &arm_cpu_cfgend_property,
34
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *mr_for_raminfo(MPS2TZMachineState *mms,
35
36
memory_region_init_ram(ram, NULL, raminfo->name,
37
raminfo->size, &error_fatal);
38
+ if (raminfo->flags & IS_ROM) {
39
+ memory_region_set_readonly(ram, true);
40
+ }
41
return ram;
42
}
43
87
--
44
--
88
2.16.2
45
2.20.1
89
46
90
47
diff view generated by jsdifflib
1
Add a function load_ramdisk_as() which behaves like the existing
1
The armv7m_load_kernel() function takes a mem_size argument which it
2
load_ramdisk() but allows the caller to specify the AddressSpace
2
expects to be the size of the memory region at guest address 0. (It
3
to use. This matches the pattern we have already for various
3
uses this argument only as a limit on how large a raw image file it
4
other loader functions.
4
can load at address zero).
5
6
Instead of hardcoding this value, find the RAMInfo corresponding to
7
the 0 address and extract its size.
5
8
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
10
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Message-id: 20180220180325.29818-2-peter.maydell@linaro.org
12
Message-id: 20210215115138.20465-20-peter.maydell@linaro.org
10
---
13
---
11
include/hw/loader.h | 12 +++++++++++-
14
hw/arm/mps2-tz.c | 17 ++++++++++++++++-
12
hw/core/loader.c | 8 +++++++-
15
1 file changed, 16 insertions(+), 1 deletion(-)
13
2 files changed, 18 insertions(+), 2 deletions(-)
14
16
15
diff --git a/include/hw/loader.h b/include/hw/loader.h
17
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
16
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
17
--- a/include/hw/loader.h
19
--- a/hw/arm/mps2-tz.c
18
+++ b/include/hw/loader.h
20
+++ b/hw/arm/mps2-tz.c
19
@@ -XXX,XX +XXX,XX @@ int load_uimage(const char *filename, hwaddr *ep,
21
@@ -XXX,XX +XXX,XX @@ static void create_non_mpc_ram(MPS2TZMachineState *mms)
20
void *translate_opaque);
22
}
21
23
}
22
/**
24
23
- * load_ramdisk:
25
+static uint32_t boot_ram_size(MPS2TZMachineState *mms)
24
+ * load_ramdisk_as:
26
+{
25
* @filename: Path to the ramdisk image
27
+ /* Return the size of the RAM block at guest address zero */
26
* @addr: Memory address to load the ramdisk to
28
+ const RAMInfo *p;
27
* @max_sz: Maximum allowed ramdisk size (for non-u-boot ramdisks)
29
+ MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
28
+ * @as: The AddressSpace to load the ELF to. The value of address_space_memory
29
+ * is used if nothing is supplied here.
30
*
31
* Load a ramdisk image with U-Boot header to the specified memory
32
* address.
33
*
34
* Returns the size of the loaded image on success, -1 otherwise.
35
*/
36
+int load_ramdisk_as(const char *filename, hwaddr addr, uint64_t max_sz,
37
+ AddressSpace *as);
38
+
30
+
39
+/**
31
+ for (p = mmc->raminfo; p->name; p++) {
40
+ * load_ramdisk:
32
+ if (p->base == 0) {
41
+ * Same as load_ramdisk_as(), but doesn't allow the caller to specify
33
+ return p->size;
42
+ * an AddressSpace.
34
+ }
43
+ */
35
+ }
44
int load_ramdisk(const char *filename, hwaddr addr, uint64_t max_sz);
36
+ g_assert_not_reached();
45
46
ssize_t gunzip(void *dst, size_t dstlen, uint8_t *src, size_t srclen);
47
diff --git a/hw/core/loader.c b/hw/core/loader.c
48
index XXXXXXX..XXXXXXX 100644
49
--- a/hw/core/loader.c
50
+++ b/hw/core/loader.c
51
@@ -XXX,XX +XXX,XX @@ int load_uimage_as(const char *filename, hwaddr *ep, hwaddr *loadaddr,
52
53
/* Load a ramdisk. */
54
int load_ramdisk(const char *filename, hwaddr addr, uint64_t max_sz)
55
+{
56
+ return load_ramdisk_as(filename, addr, max_sz, NULL);
57
+}
37
+}
58
+
38
+
59
+int load_ramdisk_as(const char *filename, hwaddr addr, uint64_t max_sz,
39
static void mps2tz_common_init(MachineState *machine)
60
+ AddressSpace *as)
61
{
40
{
62
return load_uboot_image(filename, NULL, &addr, NULL, IH_TYPE_RAMDISK,
41
MPS2TZMachineState *mms = MPS2TZ_MACHINE(machine);
63
- NULL, NULL, NULL);
42
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
64
+ NULL, NULL, as);
43
44
create_non_mpc_ram(mms);
45
46
- armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename, 0x400000);
47
+ armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename,
48
+ boot_ram_size(mms));
65
}
49
}
66
50
67
/* Load a gzip-compressed kernel to a dynamically allocated buffer. */
51
static void mps2_tz_idau_check(IDAUInterface *ii, uint32_t address,
68
--
52
--
69
2.16.2
53
2.20.1
70
54
71
55
diff view generated by jsdifflib
1
Define a new board model for the MPS2 with an AN505 FPGA image
1
Add support for the mps3-an524 board; this is an SSE-200 based FPGA
2
containing a Cortex-M33. Since the FPGA images for TrustZone
2
image, like the existing mps2-an521. It has a usefully larger amount
3
cores (AN505, and the similar AN519 for Cortex-M23) have a
3
of RAM, and a PL031 RTC, as well as some more minor differences.
4
significantly different layout of devices to the non-TrustZone
4
5
images, we use a new source file rather than shoehorning them
5
In real hardware this image runs on a newer generation of the FPGA
6
into the existing mps2.c.
6
board, the MPS3 rather than the older MPS2. Architecturally the two
7
boards are similar, so we implement the MPS3 boards in the mps2-tz.c
8
file as variations of the existing MPS2 boards.
7
9
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
Message-id: 20180220180325.29818-20-peter.maydell@linaro.org
12
Message-id: 20210215115138.20465-21-peter.maydell@linaro.org
11
---
13
---
12
hw/arm/Makefile.objs | 1 +
14
hw/arm/mps2-tz.c | 139 +++++++++++++++++++++++++++++++++++++++++++++--
13
hw/arm/mps2-tz.c | 503 +++++++++++++++++++++++++++++++++++++++++++++++++++
15
1 file changed, 135 insertions(+), 4 deletions(-)
14
2 files changed, 504 insertions(+)
16
15
create mode 100644 hw/arm/mps2-tz.c
17
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
16
17
diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
18
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
19
--- a/hw/arm/Makefile.objs
19
--- a/hw/arm/mps2-tz.c
20
+++ b/hw/arm/Makefile.objs
21
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o kzm.o
22
obj-$(CONFIG_FSL_IMX6) += fsl-imx6.o sabrelite.o
23
obj-$(CONFIG_ASPEED_SOC) += aspeed_soc.o aspeed.o
24
obj-$(CONFIG_MPS2) += mps2.o
25
+obj-$(CONFIG_MPS2) += mps2-tz.o
26
obj-$(CONFIG_MSF2) += msf2-soc.o msf2-som.o
27
obj-$(CONFIG_IOTKIT) += iotkit.o
28
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
29
new file mode 100644
30
index XXXXXXX..XXXXXXX
31
--- /dev/null
32
+++ b/hw/arm/mps2-tz.c
20
+++ b/hw/arm/mps2-tz.c
33
@@ -XXX,XX +XXX,XX @@
21
@@ -XXX,XX +XXX,XX @@
34
+/*
22
* This source file covers the following FPGA images, for TrustZone cores:
35
+ * ARM V2M MPS2 board emulation, trustzone aware FPGA images
23
* "mps2-an505" -- Cortex-M33 as documented in ARM Application Note AN505
36
+ *
24
* "mps2-an521" -- Dual Cortex-M33 as documented in Application Note AN521
37
+ * Copyright (c) 2017 Linaro Limited
25
+ * "mps2-an524" -- Dual Cortex-M33 as documented in Application Note AN524
38
+ * Written by Peter Maydell
26
*
39
+ *
27
* Links to the TRM for the board itself and to the various Application
40
+ * This program is free software; you can redistribute it and/or modify
28
* Notes which document the FPGA images can be found here:
41
+ * it under the terms of the GNU General Public License version 2 or
29
@@ -XXX,XX +XXX,XX @@
42
+ * (at your option) any later version.
30
* http://infocenter.arm.com/help/topic/com.arm.doc.dai0505b/index.html
43
+ */
31
* Application Note AN521:
44
+
32
* http://infocenter.arm.com/help/topic/com.arm.doc.dai0521c/index.html
45
+/* The MPS2 and MPS2+ dev boards are FPGA based (the 2+ has a bigger
33
+ * Application Note AN524:
46
+ * FPGA but is otherwise the same as the 2). Since the CPU itself
34
+ * https://developer.arm.com/documentation/dai0524/latest/
47
+ * and most of the devices are in the FPGA, the details of the board
35
*
48
+ * as seen by the guest depend significantly on the FPGA image.
36
* The AN505 defers to the Cortex-M33 processor ARMv8M IoT Kit FVP User Guide
49
+ * This source file covers the following FPGA images, for TrustZone cores:
37
* (ARM ECM0601256) for the details of some of the device layout:
50
+ * "mps2-an505" -- Cortex-M33 as documented in ARM Application Note AN505
38
* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
51
+ *
39
- * Similarly, the AN521 uses the SSE-200, and the SSE-200 TRM defines
52
+ * Links to the TRM for the board itself and to the various Application
40
+ * Similarly, the AN521 and AN524 use the SSE-200, and the SSE-200 TRM defines
53
+ * Notes which document the FPGA images can be found here:
41
* most of the device layout:
54
+ * https://developer.arm.com/products/system-design/development-boards/fpga-prototyping-boards/mps2
42
* http://infocenter.arm.com/help/topic/com.arm.doc.101104_0100_00_en/corelink_sse200_subsystem_for_embedded_technical_reference_manual_101104_0100_00_en.pdf
55
+ *
43
*
56
+ * Board TRM:
44
@@ -XXX,XX +XXX,XX @@
57
+ * http://infocenter.arm.com/help/topic/com.arm.doc.100112_0200_06_en/versatile_express_cortex_m_prototyping_systems_v2m_mps2_and_v2m_mps2plus_technical_reference_100112_0200_06_en.pdf
45
#include "hw/qdev-clock.h"
58
+ * Application Note AN505:
46
#include "qom/object.h"
59
+ * http://infocenter.arm.com/help/topic/com.arm.doc.dai0505b/index.html
47
60
+ *
48
-#define MPS2TZ_NUMIRQ_MAX 92
61
+ * The AN505 defers to the Cortex-M33 processor ARMv8M IoT Kit FVP User Guide
49
+#define MPS2TZ_NUMIRQ_MAX 95
62
+ * (ARM ECM0601256) for the details of some of the device layout:
50
#define MPS2TZ_RAM_MAX 4
63
+ * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
51
64
+ */
52
typedef enum MPS2TZFPGAType {
65
+
53
FPGA_AN505,
66
+#include "qemu/osdep.h"
54
FPGA_AN521,
67
+#include "qapi/error.h"
55
+ FPGA_AN524,
68
+#include "qemu/error-report.h"
56
} MPS2TZFPGAType;
69
+#include "hw/arm/arm.h"
57
70
+#include "hw/arm/armv7m.h"
58
/*
71
+#include "hw/or-irq.h"
59
@@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineState {
72
+#include "hw/boards.h"
60
TZPPC ppc[5];
73
+#include "exec/address-spaces.h"
61
TZMPC mpc[3];
74
+#include "sysemu/sysemu.h"
62
PL022State spi[5];
75
+#include "hw/misc/unimp.h"
63
- ArmSbconI2CState i2c[4];
76
+#include "hw/char/cmsdk-apb-uart.h"
64
+ ArmSbconI2CState i2c[5];
77
+#include "hw/timer/cmsdk-apb-timer.h"
65
UnimplementedDeviceState i2s_audio;
78
+#include "hw/misc/mps2-scc.h"
66
UnimplementedDeviceState gpio[4];
79
+#include "hw/misc/mps2-fpgaio.h"
67
UnimplementedDeviceState gfx;
80
+#include "hw/arm/iotkit.h"
68
+ UnimplementedDeviceState cldc;
81
+#include "hw/devices.h"
69
+ UnimplementedDeviceState rtc;
82
+#include "net/net.h"
70
PL080State dma[4];
83
+#include "hw/core/split-irq.h"
71
TZMSC msc[4];
84
+
72
- CMSDKAPBUART uart[5];
85
+typedef enum MPS2TZFPGAType {
73
+ CMSDKAPBUART uart[6];
86
+ FPGA_AN505,
74
SplitIRQ sec_resp_splitter;
87
+} MPS2TZFPGAType;
75
qemu_or_irq uart_irq_orgate;
88
+
76
DeviceState *lan9118;
89
+typedef struct {
77
@@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineState {
90
+ MachineClass parent;
78
#define TYPE_MPS2TZ_MACHINE "mps2tz"
91
+ MPS2TZFPGAType fpga_type;
79
#define TYPE_MPS2TZ_AN505_MACHINE MACHINE_TYPE_NAME("mps2-an505")
92
+ uint32_t scc_id;
80
#define TYPE_MPS2TZ_AN521_MACHINE MACHINE_TYPE_NAME("mps2-an521")
93
+} MPS2TZMachineClass;
81
+#define TYPE_MPS3TZ_AN524_MACHINE MACHINE_TYPE_NAME("mps3-an524")
94
+
82
95
+typedef struct {
83
OBJECT_DECLARE_TYPE(MPS2TZMachineState, MPS2TZMachineClass, MPS2TZ_MACHINE)
96
+ MachineState parent;
84
97
+
85
@@ -XXX,XX +XXX,XX @@ static const uint32_t an505_oscclk[] = {
98
+ IoTKit iotkit;
86
25000000,
99
+ MemoryRegion psram;
87
};
100
+ MemoryRegion ssram1;
88
101
+ MemoryRegion ssram1_m;
89
+static const uint32_t an524_oscclk[] = {
102
+ MemoryRegion ssram23;
90
+ 24000000,
103
+ MPS2SCC scc;
91
+ 32000000,
104
+ MPS2FPGAIO fpgaio;
92
+ 50000000,
105
+ TZPPC ppc[5];
93
+ 50000000,
106
+ UnimplementedDeviceState ssram_mpc[3];
94
+ 24576000,
107
+ UnimplementedDeviceState spi[5];
95
+ 23750000,
108
+ UnimplementedDeviceState i2c[4];
96
+};
109
+ UnimplementedDeviceState i2s_audio;
97
+
110
+ UnimplementedDeviceState gpio[5];
98
static const RAMInfo an505_raminfo[] = { {
111
+ UnimplementedDeviceState dma[4];
99
.name = "ssram-0",
112
+ UnimplementedDeviceState gfx;
100
.base = 0x00000000,
113
+ CMSDKAPBUART uart[5];
101
@@ -XXX,XX +XXX,XX @@ static const RAMInfo an505_raminfo[] = { {
114
+ SplitIRQ sec_resp_splitter;
102
},
115
+ qemu_or_irq uart_irq_orgate;
103
};
116
+} MPS2TZMachineState;
104
117
+
105
+static const RAMInfo an524_raminfo[] = { {
118
+#define TYPE_MPS2TZ_MACHINE "mps2tz"
106
+ .name = "bram",
119
+#define TYPE_MPS2TZ_AN505_MACHINE MACHINE_TYPE_NAME("mps2-an505")
107
+ .base = 0x00000000,
120
+
108
+ .size = 512 * KiB,
121
+#define MPS2TZ_MACHINE(obj) \
109
+ .mpc = 0,
122
+ OBJECT_CHECK(MPS2TZMachineState, obj, TYPE_MPS2TZ_MACHINE)
110
+ .mrindex = 0,
123
+#define MPS2TZ_MACHINE_GET_CLASS(obj) \
111
+ }, {
124
+ OBJECT_GET_CLASS(MPS2TZMachineClass, obj, TYPE_MPS2TZ_MACHINE)
112
+ .name = "sram",
125
+#define MPS2TZ_MACHINE_CLASS(klass) \
113
+ .base = 0x20000000,
126
+ OBJECT_CLASS_CHECK(MPS2TZMachineClass, klass, TYPE_MPS2TZ_MACHINE)
114
+ .size = 32 * 4 * KiB,
127
+
115
+ .mpc = 1,
128
+/* Main SYSCLK frequency in Hz */
116
+ .mrindex = 1,
129
+#define SYSCLK_FRQ 20000000
117
+ }, {
130
+
118
+ /* We don't model QSPI flash yet; for now expose it as simple ROM */
131
+/* Initialize the auxiliary RAM region @mr and map it into
119
+ .name = "QSPI",
132
+ * the memory map at @base.
120
+ .base = 0x28000000,
133
+ */
121
+ .size = 8 * MiB,
134
+static void make_ram(MemoryRegion *mr, const char *name,
122
+ .mpc = 1,
135
+ hwaddr base, hwaddr size)
123
+ .mrindex = 2,
136
+{
124
+ .flags = IS_ROM,
137
+ memory_region_init_ram(mr, NULL, name, size, &error_fatal);
125
+ }, {
138
+ memory_region_add_subregion(get_system_memory(), base, mr);
126
+ .name = "DDR",
139
+}
127
+ .base = 0x60000000,
140
+
128
+ .size = 2 * GiB,
141
+/* Create an alias of an entire original MemoryRegion @orig
129
+ .mpc = 2,
142
+ * located at @base in the memory map.
130
+ .mrindex = -1,
143
+ */
131
+ }, {
144
+static void make_ram_alias(MemoryRegion *mr, const char *name,
132
+ .name = NULL,
145
+ MemoryRegion *orig, hwaddr base)
133
+ },
146
+{
134
+};
147
+ memory_region_init_alias(mr, NULL, name, orig, 0,
135
+
148
+ memory_region_size(orig));
136
static const RAMInfo *find_raminfo_for_mpc(MPS2TZMachineState *mms, int mpc)
149
+ memory_region_add_subregion(get_system_memory(), base, mr);
137
{
150
+}
138
MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
151
+
139
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
152
+static void init_sysbus_child(Object *parent, const char *childname,
140
},
153
+ void *child, size_t childsize,
141
};
154
+ const char *childtype)
142
155
+{
143
+ const PPCInfo an524_ppcs[] = { {
156
+ object_initialize(child, childsize, childtype);
157
+ object_property_add_child(parent, childname, OBJECT(child), &error_abort);
158
+ qdev_set_parent_bus(DEVICE(child), sysbus_get_default());
159
+
160
+}
161
+
162
+/* Most of the devices in the AN505 FPGA image sit behind
163
+ * Peripheral Protection Controllers. These data structures
164
+ * define the layout of which devices sit behind which PPCs.
165
+ * The devfn for each port is a function which creates, configures
166
+ * and initializes the device, returning the MemoryRegion which
167
+ * needs to be plugged into the downstream end of the PPC port.
168
+ */
169
+typedef MemoryRegion *MakeDevFn(MPS2TZMachineState *mms, void *opaque,
170
+ const char *name, hwaddr size);
171
+
172
+typedef struct PPCPortInfo {
173
+ const char *name;
174
+ MakeDevFn *devfn;
175
+ void *opaque;
176
+ hwaddr addr;
177
+ hwaddr size;
178
+} PPCPortInfo;
179
+
180
+typedef struct PPCInfo {
181
+ const char *name;
182
+ PPCPortInfo ports[TZ_NUM_PORTS];
183
+} PPCInfo;
184
+
185
+static MemoryRegion *make_unimp_dev(MPS2TZMachineState *mms,
186
+ void *opaque,
187
+ const char *name, hwaddr size)
188
+{
189
+ /* Initialize, configure and realize a TYPE_UNIMPLEMENTED_DEVICE,
190
+ * and return a pointer to its MemoryRegion.
191
+ */
192
+ UnimplementedDeviceState *uds = opaque;
193
+
194
+ init_sysbus_child(OBJECT(mms), name, uds,
195
+ sizeof(UnimplementedDeviceState),
196
+ TYPE_UNIMPLEMENTED_DEVICE);
197
+ qdev_prop_set_string(DEVICE(uds), "name", name);
198
+ qdev_prop_set_uint64(DEVICE(uds), "size", size);
199
+ object_property_set_bool(OBJECT(uds), true, "realized", &error_fatal);
200
+ return sysbus_mmio_get_region(SYS_BUS_DEVICE(uds), 0);
201
+}
202
+
203
+static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
204
+ const char *name, hwaddr size)
205
+{
206
+ CMSDKAPBUART *uart = opaque;
207
+ int i = uart - &mms->uart[0];
208
+ Chardev *uartchr = i < MAX_SERIAL_PORTS ? serial_hds[i] : NULL;
209
+ int rxirqno = i * 2;
210
+ int txirqno = i * 2 + 1;
211
+ int combirqno = i + 10;
212
+ SysBusDevice *s;
213
+ DeviceState *iotkitdev = DEVICE(&mms->iotkit);
214
+ DeviceState *orgate_dev = DEVICE(&mms->uart_irq_orgate);
215
+
216
+ init_sysbus_child(OBJECT(mms), name, uart,
217
+ sizeof(mms->uart[0]), TYPE_CMSDK_APB_UART);
218
+ qdev_prop_set_chr(DEVICE(uart), "chardev", uartchr);
219
+ qdev_prop_set_uint32(DEVICE(uart), "pclk-frq", SYSCLK_FRQ);
220
+ object_property_set_bool(OBJECT(uart), true, "realized", &error_fatal);
221
+ s = SYS_BUS_DEVICE(uart);
222
+ sysbus_connect_irq(s, 0, qdev_get_gpio_in_named(iotkitdev,
223
+ "EXP_IRQ", txirqno));
224
+ sysbus_connect_irq(s, 1, qdev_get_gpio_in_named(iotkitdev,
225
+ "EXP_IRQ", rxirqno));
226
+ sysbus_connect_irq(s, 2, qdev_get_gpio_in(orgate_dev, i * 2));
227
+ sysbus_connect_irq(s, 3, qdev_get_gpio_in(orgate_dev, i * 2 + 1));
228
+ sysbus_connect_irq(s, 4, qdev_get_gpio_in_named(iotkitdev,
229
+ "EXP_IRQ", combirqno));
230
+ return sysbus_mmio_get_region(SYS_BUS_DEVICE(uart), 0);
231
+}
232
+
233
+static MemoryRegion *make_scc(MPS2TZMachineState *mms, void *opaque,
234
+ const char *name, hwaddr size)
235
+{
236
+ MPS2SCC *scc = opaque;
237
+ DeviceState *sccdev;
238
+ MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
239
+
240
+ object_initialize(scc, sizeof(mms->scc), TYPE_MPS2_SCC);
241
+ sccdev = DEVICE(scc);
242
+ qdev_set_parent_bus(sccdev, sysbus_get_default());
243
+ qdev_prop_set_uint32(sccdev, "scc-cfg4", 0x2);
244
+ qdev_prop_set_uint32(sccdev, "scc-aid", 0x02000008);
245
+ qdev_prop_set_uint32(sccdev, "scc-id", mmc->scc_id);
246
+ object_property_set_bool(OBJECT(scc), true, "realized", &error_fatal);
247
+ return sysbus_mmio_get_region(SYS_BUS_DEVICE(sccdev), 0);
248
+}
249
+
250
+static MemoryRegion *make_fpgaio(MPS2TZMachineState *mms, void *opaque,
251
+ const char *name, hwaddr size)
252
+{
253
+ MPS2FPGAIO *fpgaio = opaque;
254
+
255
+ object_initialize(fpgaio, sizeof(mms->fpgaio), TYPE_MPS2_FPGAIO);
256
+ qdev_set_parent_bus(DEVICE(fpgaio), sysbus_get_default());
257
+ object_property_set_bool(OBJECT(fpgaio), true, "realized", &error_fatal);
258
+ return sysbus_mmio_get_region(SYS_BUS_DEVICE(fpgaio), 0);
259
+}
260
+
261
+static void mps2tz_common_init(MachineState *machine)
262
+{
263
+ MPS2TZMachineState *mms = MPS2TZ_MACHINE(machine);
264
+ MachineClass *mc = MACHINE_GET_CLASS(machine);
265
+ MemoryRegion *system_memory = get_system_memory();
266
+ DeviceState *iotkitdev;
267
+ DeviceState *dev_splitter;
268
+ int i;
269
+
270
+ if (strcmp(machine->cpu_type, mc->default_cpu_type) != 0) {
271
+ error_report("This board can only be used with CPU %s",
272
+ mc->default_cpu_type);
273
+ exit(1);
274
+ }
275
+
276
+ init_sysbus_child(OBJECT(machine), "iotkit", &mms->iotkit,
277
+ sizeof(mms->iotkit), TYPE_IOTKIT);
278
+ iotkitdev = DEVICE(&mms->iotkit);
279
+ object_property_set_link(OBJECT(&mms->iotkit), OBJECT(system_memory),
280
+ "memory", &error_abort);
281
+ qdev_prop_set_uint32(iotkitdev, "EXP_NUMIRQ", 92);
282
+ qdev_prop_set_uint32(iotkitdev, "MAINCLK", SYSCLK_FRQ);
283
+ object_property_set_bool(OBJECT(&mms->iotkit), true, "realized",
284
+ &error_fatal);
285
+
286
+ /* The sec_resp_cfg output from the IoTKit must be split into multiple
287
+ * lines, one for each of the PPCs we create here.
288
+ */
289
+ object_initialize(&mms->sec_resp_splitter, sizeof(mms->sec_resp_splitter),
290
+ TYPE_SPLIT_IRQ);
291
+ object_property_add_child(OBJECT(machine), "sec-resp-splitter",
292
+ OBJECT(&mms->sec_resp_splitter), &error_abort);
293
+ object_property_set_int(OBJECT(&mms->sec_resp_splitter), 5,
294
+ "num-lines", &error_fatal);
295
+ object_property_set_bool(OBJECT(&mms->sec_resp_splitter), true,
296
+ "realized", &error_fatal);
297
+ dev_splitter = DEVICE(&mms->sec_resp_splitter);
298
+ qdev_connect_gpio_out_named(iotkitdev, "sec_resp_cfg", 0,
299
+ qdev_get_gpio_in(dev_splitter, 0));
300
+
301
+ /* The IoTKit sets up much of the memory layout, including
302
+ * the aliases between secure and non-secure regions in the
303
+ * address space. The FPGA itself contains:
304
+ *
305
+ * 0x00000000..0x003fffff SSRAM1
306
+ * 0x00400000..0x007fffff alias of SSRAM1
307
+ * 0x28000000..0x283fffff 4MB SSRAM2 + SSRAM3
308
+ * 0x40100000..0x4fffffff AHB Master Expansion 1 interface devices
309
+ * 0x80000000..0x80ffffff 16MB PSRAM
310
+ */
311
+
312
+ /* The FPGA images have an odd combination of different RAMs,
313
+ * because in hardware they are different implementations and
314
+ * connected to different buses, giving varying performance/size
315
+ * tradeoffs. For QEMU they're all just RAM, though. We arbitrarily
316
+ * call the 16MB our "system memory", as it's the largest lump.
317
+ */
318
+ memory_region_allocate_system_memory(&mms->psram,
319
+ NULL, "mps.ram", 0x01000000);
320
+ memory_region_add_subregion(system_memory, 0x80000000, &mms->psram);
321
+
322
+ /* The SSRAM memories should all be behind Memory Protection Controllers,
323
+ * but we don't implement that yet.
324
+ */
325
+ make_ram(&mms->ssram1, "mps.ssram1", 0x00000000, 0x00400000);
326
+ make_ram_alias(&mms->ssram1_m, "mps.ssram1_m", &mms->ssram1, 0x00400000);
327
+
328
+ make_ram(&mms->ssram23, "mps.ssram23", 0x28000000, 0x00400000);
329
+
330
+ /* The overflow IRQs for all UARTs are ORed together.
331
+ * Tx, Rx and "combined" IRQs are sent to the NVIC separately.
332
+ * Create the OR gate for this.
333
+ */
334
+ object_initialize(&mms->uart_irq_orgate, sizeof(mms->uart_irq_orgate),
335
+ TYPE_OR_IRQ);
336
+ object_property_add_child(OBJECT(mms), "uart-irq-orgate",
337
+ OBJECT(&mms->uart_irq_orgate), &error_abort);
338
+ object_property_set_int(OBJECT(&mms->uart_irq_orgate), 10, "num-lines",
339
+ &error_fatal);
340
+ object_property_set_bool(OBJECT(&mms->uart_irq_orgate), true,
341
+ "realized", &error_fatal);
342
+ qdev_connect_gpio_out(DEVICE(&mms->uart_irq_orgate), 0,
343
+ qdev_get_gpio_in_named(iotkitdev, "EXP_IRQ", 15));
344
+
345
+ /* Most of the devices in the FPGA are behind Peripheral Protection
346
+ * Controllers. The required order for initializing things is:
347
+ * + initialize the PPC
348
+ * + initialize, configure and realize downstream devices
349
+ * + connect downstream device MemoryRegions to the PPC
350
+ * + realize the PPC
351
+ * + map the PPC's MemoryRegions to the places in the address map
352
+ * where the downstream devices should appear
353
+ * + wire up the PPC's control lines to the IoTKit object
354
+ */
355
+
356
+ const PPCInfo ppcs[] = { {
357
+ .name = "apb_ppcexp0",
144
+ .name = "apb_ppcexp0",
358
+ .ports = {
145
+ .ports = {
359
+ { "ssram-mpc0", make_unimp_dev, &mms->ssram_mpc[0],
146
+ { "bram-mpc", make_mpc, &mms->mpc[0], 0x58007000, 0x1000 },
360
+ 0x58007000, 0x1000 },
147
+ { "qspi-mpc", make_mpc, &mms->mpc[1], 0x58008000, 0x1000 },
361
+ { "ssram-mpc1", make_unimp_dev, &mms->ssram_mpc[1],
148
+ { "ddr-mpc", make_mpc, &mms->mpc[2], 0x58009000, 0x1000 },
362
+ 0x58008000, 0x1000 },
363
+ { "ssram-mpc2", make_unimp_dev, &mms->ssram_mpc[2],
364
+ 0x58009000, 0x1000 },
365
+ },
149
+ },
366
+ }, {
150
+ }, {
367
+ .name = "apb_ppcexp1",
151
+ .name = "apb_ppcexp1",
368
+ .ports = {
152
+ .ports = {
369
+ { "spi0", make_unimp_dev, &mms->spi[0], 0x40205000, 0x1000 },
153
+ { "i2c0", make_i2c, &mms->i2c[0], 0x41200000, 0x1000 },
370
+ { "spi1", make_unimp_dev, &mms->spi[1], 0x40206000, 0x1000 },
154
+ { "i2c1", make_i2c, &mms->i2c[1], 0x41201000, 0x1000 },
371
+ { "spi2", make_unimp_dev, &mms->spi[2], 0x40209000, 0x1000 },
155
+ { "spi0", make_spi, &mms->spi[0], 0x41202000, 0x1000, { 52 } },
372
+ { "spi3", make_unimp_dev, &mms->spi[3], 0x4020a000, 0x1000 },
156
+ { "spi1", make_spi, &mms->spi[1], 0x41203000, 0x1000, { 53 } },
373
+ { "spi4", make_unimp_dev, &mms->spi[4], 0x4020b000, 0x1000 },
157
+ { "spi2", make_spi, &mms->spi[2], 0x41204000, 0x1000, { 54 } },
374
+ { "uart0", make_uart, &mms->uart[0], 0x40200000, 0x1000 },
158
+ { "i2c2", make_i2c, &mms->i2c[2], 0x41205000, 0x1000 },
375
+ { "uart1", make_uart, &mms->uart[1], 0x40201000, 0x1000 },
159
+ { "i2c3", make_i2c, &mms->i2c[3], 0x41206000, 0x1000 },
376
+ { "uart2", make_uart, &mms->uart[2], 0x40202000, 0x1000 },
160
+ { /* port 7 reserved */ },
377
+ { "uart3", make_uart, &mms->uart[3], 0x40203000, 0x1000 },
161
+ { "i2c4", make_i2c, &mms->i2c[4], 0x41208000, 0x1000 },
378
+ { "uart4", make_uart, &mms->uart[4], 0x40204000, 0x1000 },
379
+ { "i2c0", make_unimp_dev, &mms->i2c[0], 0x40207000, 0x1000 },
380
+ { "i2c1", make_unimp_dev, &mms->i2c[1], 0x40208000, 0x1000 },
381
+ { "i2c2", make_unimp_dev, &mms->i2c[2], 0x4020c000, 0x1000 },
382
+ { "i2c3", make_unimp_dev, &mms->i2c[3], 0x4020d000, 0x1000 },
383
+ },
162
+ },
384
+ }, {
163
+ }, {
385
+ .name = "apb_ppcexp2",
164
+ .name = "apb_ppcexp2",
386
+ .ports = {
165
+ .ports = {
387
+ { "scc", make_scc, &mms->scc, 0x40300000, 0x1000 },
166
+ { "scc", make_scc, &mms->scc, 0x41300000, 0x1000 },
388
+ { "i2s-audio", make_unimp_dev, &mms->i2s_audio,
167
+ { "i2s-audio", make_unimp_dev, &mms->i2s_audio,
389
+ 0x40301000, 0x1000 },
168
+ 0x41301000, 0x1000 },
390
+ { "fpgaio", make_fpgaio, &mms->fpgaio, 0x40302000, 0x1000 },
169
+ { "fpgaio", make_fpgaio, &mms->fpgaio, 0x41302000, 0x1000 },
170
+ { "uart0", make_uart, &mms->uart[0], 0x41303000, 0x1000, { 32, 33, 42 } },
171
+ { "uart1", make_uart, &mms->uart[1], 0x41304000, 0x1000, { 34, 35, 43 } },
172
+ { "uart2", make_uart, &mms->uart[2], 0x41305000, 0x1000, { 36, 37, 44 } },
173
+ { "uart3", make_uart, &mms->uart[3], 0x41306000, 0x1000, { 38, 39, 45 } },
174
+ { "uart4", make_uart, &mms->uart[4], 0x41307000, 0x1000, { 40, 41, 46 } },
175
+ { "uart5", make_uart, &mms->uart[5], 0x41308000, 0x1000, { 124, 125, 126 } },
176
+
177
+ { /* port 9 reserved */ },
178
+ { "clcd", make_unimp_dev, &mms->cldc, 0x4130a000, 0x1000 },
179
+ { "rtc", make_unimp_dev, &mms->rtc, 0x4130b000, 0x1000 },
391
+ },
180
+ },
392
+ }, {
181
+ }, {
393
+ .name = "ahb_ppcexp0",
182
+ .name = "ahb_ppcexp0",
394
+ .ports = {
183
+ .ports = {
395
+ { "gfx", make_unimp_dev, &mms->gfx, 0x41000000, 0x140000 },
184
+ { "gpio0", make_unimp_dev, &mms->gpio[0], 0x41100000, 0x1000 },
396
+ { "gpio0", make_unimp_dev, &mms->gpio[0], 0x40100000, 0x1000 },
185
+ { "gpio1", make_unimp_dev, &mms->gpio[1], 0x41101000, 0x1000 },
397
+ { "gpio1", make_unimp_dev, &mms->gpio[1], 0x40101000, 0x1000 },
186
+ { "gpio2", make_unimp_dev, &mms->gpio[2], 0x41102000, 0x1000 },
398
+ { "gpio2", make_unimp_dev, &mms->gpio[2], 0x40102000, 0x1000 },
187
+ { "gpio3", make_unimp_dev, &mms->gpio[3], 0x41103000, 0x1000 },
399
+ { "gpio3", make_unimp_dev, &mms->gpio[3], 0x40103000, 0x1000 },
188
+ { "eth", make_eth_dev, NULL, 0x41400000, 0x100000, { 48 } },
400
+ { "gpio4", make_unimp_dev, &mms->gpio[4], 0x40104000, 0x1000 },
401
+ },
402
+ }, {
403
+ .name = "ahb_ppcexp1",
404
+ .ports = {
405
+ { "dma0", make_unimp_dev, &mms->dma[0], 0x40110000, 0x1000 },
406
+ { "dma1", make_unimp_dev, &mms->dma[1], 0x40111000, 0x1000 },
407
+ { "dma2", make_unimp_dev, &mms->dma[2], 0x40112000, 0x1000 },
408
+ { "dma3", make_unimp_dev, &mms->dma[3], 0x40113000, 0x1000 },
409
+ },
189
+ },
410
+ },
190
+ },
411
+ };
191
+ };
412
+
192
+
413
+ for (i = 0; i < ARRAY_SIZE(ppcs); i++) {
193
switch (mmc->fpga_type) {
414
+ const PPCInfo *ppcinfo = &ppcs[i];
194
case FPGA_AN505:
415
+ TZPPC *ppc = &mms->ppc[i];
195
case FPGA_AN521:
416
+ DeviceState *ppcdev;
196
ppcs = an505_ppcs;
417
+ int port;
197
num_ppcs = ARRAY_SIZE(an505_ppcs);
418
+ char *gpioname;
198
break;
419
+
199
+ case FPGA_AN524:
420
+ init_sysbus_child(OBJECT(machine), ppcinfo->name, ppc,
200
+ ppcs = an524_ppcs;
421
+ sizeof(TZPPC), TYPE_TZ_PPC);
201
+ num_ppcs = ARRAY_SIZE(an524_ppcs);
422
+ ppcdev = DEVICE(ppc);
202
+ break;
423
+
203
default:
424
+ for (port = 0; port < TZ_NUM_PORTS; port++) {
204
g_assert_not_reached();
425
+ const PPCPortInfo *pinfo = &ppcinfo->ports[port];
205
}
426
+ MemoryRegion *mr;
206
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an521_class_init(ObjectClass *oc, void *data)
427
+ char *portname;
207
mps2tz_set_default_ram_info(mmc);
428
+
208
}
429
+ if (!pinfo->devfn) {
209
430
+ continue;
210
+static void mps3tz_an524_class_init(ObjectClass *oc, void *data)
431
+ }
432
+
433
+ mr = pinfo->devfn(mms, pinfo->opaque, pinfo->name, pinfo->size);
434
+ portname = g_strdup_printf("port[%d]", port);
435
+ object_property_set_link(OBJECT(ppc), OBJECT(mr),
436
+ portname, &error_fatal);
437
+ g_free(portname);
438
+ }
439
+
440
+ object_property_set_bool(OBJECT(ppc), true, "realized", &error_fatal);
441
+
442
+ for (port = 0; port < TZ_NUM_PORTS; port++) {
443
+ const PPCPortInfo *pinfo = &ppcinfo->ports[port];
444
+
445
+ if (!pinfo->devfn) {
446
+ continue;
447
+ }
448
+ sysbus_mmio_map(SYS_BUS_DEVICE(ppc), port, pinfo->addr);
449
+
450
+ gpioname = g_strdup_printf("%s_nonsec", ppcinfo->name);
451
+ qdev_connect_gpio_out_named(iotkitdev, gpioname, port,
452
+ qdev_get_gpio_in_named(ppcdev,
453
+ "cfg_nonsec",
454
+ port));
455
+ g_free(gpioname);
456
+ gpioname = g_strdup_printf("%s_ap", ppcinfo->name);
457
+ qdev_connect_gpio_out_named(iotkitdev, gpioname, port,
458
+ qdev_get_gpio_in_named(ppcdev,
459
+ "cfg_ap", port));
460
+ g_free(gpioname);
461
+ }
462
+
463
+ gpioname = g_strdup_printf("%s_irq_enable", ppcinfo->name);
464
+ qdev_connect_gpio_out_named(iotkitdev, gpioname, 0,
465
+ qdev_get_gpio_in_named(ppcdev,
466
+ "irq_enable", 0));
467
+ g_free(gpioname);
468
+ gpioname = g_strdup_printf("%s_irq_clear", ppcinfo->name);
469
+ qdev_connect_gpio_out_named(iotkitdev, gpioname, 0,
470
+ qdev_get_gpio_in_named(ppcdev,
471
+ "irq_clear", 0));
472
+ g_free(gpioname);
473
+ gpioname = g_strdup_printf("%s_irq_status", ppcinfo->name);
474
+ qdev_connect_gpio_out_named(ppcdev, "irq", 0,
475
+ qdev_get_gpio_in_named(iotkitdev,
476
+ gpioname, 0));
477
+ g_free(gpioname);
478
+
479
+ qdev_connect_gpio_out(dev_splitter, i,
480
+ qdev_get_gpio_in_named(ppcdev,
481
+ "cfg_sec_resp", 0));
482
+ }
483
+
484
+ /* In hardware this is a LAN9220; the LAN9118 is software compatible
485
+ * except that it doesn't support the checksum-offload feature.
486
+ * The ethernet controller is not behind a PPC.
487
+ */
488
+ lan9118_init(&nd_table[0], 0x42000000,
489
+ qdev_get_gpio_in_named(iotkitdev, "EXP_IRQ", 16));
490
+
491
+ create_unimplemented_device("FPGA NS PC", 0x48007000, 0x1000);
492
+
493
+ armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename, 0x400000);
494
+}
495
+
496
+static void mps2tz_class_init(ObjectClass *oc, void *data)
497
+{
498
+ MachineClass *mc = MACHINE_CLASS(oc);
499
+
500
+ mc->init = mps2tz_common_init;
501
+ mc->max_cpus = 1;
502
+}
503
+
504
+static void mps2tz_an505_class_init(ObjectClass *oc, void *data)
505
+{
211
+{
506
+ MachineClass *mc = MACHINE_CLASS(oc);
212
+ MachineClass *mc = MACHINE_CLASS(oc);
507
+ MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_CLASS(oc);
213
+ MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_CLASS(oc);
508
+
214
+
509
+ mc->desc = "ARM MPS2 with AN505 FPGA image for Cortex-M33";
215
+ mc->desc = "ARM MPS3 with AN524 FPGA image for dual Cortex-M33";
510
+ mmc->fpga_type = FPGA_AN505;
216
+ mc->default_cpus = 2;
217
+ mc->min_cpus = mc->default_cpus;
218
+ mc->max_cpus = mc->default_cpus;
219
+ mmc->fpga_type = FPGA_AN524;
511
+ mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m33");
220
+ mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m33");
512
+ mmc->scc_id = 0x41040000 | (505 << 4);
221
+ mmc->scc_id = 0x41045240;
222
+ mmc->sysclk_frq = 32 * 1000 * 1000; /* 32MHz */
223
+ mmc->oscclk = an524_oscclk;
224
+ mmc->len_oscclk = ARRAY_SIZE(an524_oscclk);
225
+ mmc->fpgaio_num_leds = 10;
226
+ mmc->fpgaio_has_switches = true;
227
+ mmc->numirq = 95;
228
+ mmc->raminfo = an524_raminfo;
229
+ mmc->armsse_type = TYPE_SSE200;
230
+ mps2tz_set_default_ram_info(mmc);
513
+}
231
+}
514
+
232
+
515
+static const TypeInfo mps2tz_info = {
233
static const TypeInfo mps2tz_info = {
516
+ .name = TYPE_MPS2TZ_MACHINE,
234
.name = TYPE_MPS2TZ_MACHINE,
517
+ .parent = TYPE_MACHINE,
235
.parent = TYPE_MACHINE,
518
+ .abstract = true,
236
@@ -XXX,XX +XXX,XX @@ static const TypeInfo mps2tz_an521_info = {
519
+ .instance_size = sizeof(MPS2TZMachineState),
237
.class_init = mps2tz_an521_class_init,
520
+ .class_size = sizeof(MPS2TZMachineClass),
238
};
521
+ .class_init = mps2tz_class_init,
239
240
+static const TypeInfo mps3tz_an524_info = {
241
+ .name = TYPE_MPS3TZ_AN524_MACHINE,
242
+ .parent = TYPE_MPS2TZ_MACHINE,
243
+ .class_init = mps3tz_an524_class_init,
522
+};
244
+};
523
+
245
+
524
+static const TypeInfo mps2tz_an505_info = {
246
static void mps2tz_machine_init(void)
525
+ .name = TYPE_MPS2TZ_AN505_MACHINE,
247
{
526
+ .parent = TYPE_MPS2TZ_MACHINE,
248
type_register_static(&mps2tz_info);
527
+ .class_init = mps2tz_an505_class_init,
249
type_register_static(&mps2tz_an505_info);
528
+};
250
type_register_static(&mps2tz_an521_info);
529
+
251
+ type_register_static(&mps3tz_an524_info);
530
+static void mps2tz_machine_init(void)
252
}
531
+{
253
532
+ type_register_static(&mps2tz_info);
254
type_init(mps2tz_machine_init);
533
+ type_register_static(&mps2tz_an505_info);
534
+}
535
+
536
+type_init(mps2tz_machine_init);
537
--
255
--
538
2.16.2
256
2.20.1
539
257
540
258
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
The AN524 has a USB controller (an ISP1763); we don't have a model of
2
it but we should provide a stub "unimplemented-device" for it. This
3
is slightly complicated because the USB controller shares a PPC port
4
with the ethernet controller.
2
5
3
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
6
Implement a make_* function which provides creates a container
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
MemoryRegion with both the ethernet controller and an
5
Message-id: 20180228193125.20577-12-richard.henderson@linaro.org
8
unimplemented-device stub for the USB controller.
9
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
12
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
13
Message-id: 20210215115138.20465-22-peter.maydell@linaro.org
7
---
14
---
8
target/arm/helper.h | 7 ++++
15
hw/arm/mps2-tz.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
9
target/arm/translate-a64.c | 48 ++++++++++++++++++++++-
16
1 file changed, 47 insertions(+), 1 deletion(-)
10
target/arm/vec_helper.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++
11
3 files changed, 151 insertions(+), 1 deletion(-)
12
17
13
diff --git a/target/arm/helper.h b/target/arm/helper.h
18
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
14
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
15
--- a/target/arm/helper.h
20
--- a/hw/arm/mps2-tz.c
16
+++ b/target/arm/helper.h
21
+++ b/hw/arm/mps2-tz.c
17
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_5(gvec_qrdmlah_s32, TCG_CALL_NO_RWG,
22
@@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineState {
18
DEF_HELPER_FLAGS_5(gvec_qrdmlsh_s32, TCG_CALL_NO_RWG,
23
19
void, ptr, ptr, ptr, ptr, i32)
24
ARMSSE iotkit;
20
25
MemoryRegion ram[MPS2TZ_RAM_MAX];
21
+DEF_HELPER_FLAGS_5(gvec_fcaddh, TCG_CALL_NO_RWG,
26
+ MemoryRegion eth_usb_container;
22
+ void, ptr, ptr, ptr, ptr, i32)
23
+DEF_HELPER_FLAGS_5(gvec_fcadds, TCG_CALL_NO_RWG,
24
+ void, ptr, ptr, ptr, ptr, i32)
25
+DEF_HELPER_FLAGS_5(gvec_fcaddd, TCG_CALL_NO_RWG,
26
+ void, ptr, ptr, ptr, ptr, i32)
27
+
27
+
28
#ifdef TARGET_AARCH64
28
MPS2SCC scc;
29
#include "helper-a64.h"
29
MPS2FPGAIO fpgaio;
30
#endif
30
TZPPC ppc[5];
31
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
31
@@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineState {
32
index XXXXXXX..XXXXXXX 100644
32
UnimplementedDeviceState gfx;
33
--- a/target/arm/translate-a64.c
33
UnimplementedDeviceState cldc;
34
+++ b/target/arm/translate-a64.c
34
UnimplementedDeviceState rtc;
35
@@ -XXX,XX +XXX,XX @@ static void gen_gvec_op3_env(DisasContext *s, bool is_q, int rd,
35
+ UnimplementedDeviceState usb;
36
is_q ? 16 : 8, vec_full_reg_size(s), 0, fn);
36
PL080State dma[4];
37
TZMSC msc[4];
38
CMSDKAPBUART uart[6];
39
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_eth_dev(MPS2TZMachineState *mms, void *opaque,
40
return sysbus_mmio_get_region(s, 0);
37
}
41
}
38
42
39
+/* Expand a 3-operand + fpstatus pointer + simd data value operation using
43
+static MemoryRegion *make_eth_usb(MPS2TZMachineState *mms, void *opaque,
40
+ * an out-of-line helper.
44
+ const char *name, hwaddr size,
41
+ */
45
+ const int *irqs)
42
+static void gen_gvec_op3_fpst(DisasContext *s, bool is_q, int rd, int rn,
43
+ int rm, bool is_fp16, int data,
44
+ gen_helper_gvec_3_ptr *fn)
45
+{
46
+{
46
+ TCGv_ptr fpst = get_fpstatus_ptr(is_fp16);
47
+ /*
47
+ tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, rd),
48
+ * The AN524 makes the ethernet and USB share a PPC port.
48
+ vec_full_reg_offset(s, rn),
49
+ * irqs[] is the ethernet IRQ.
49
+ vec_full_reg_offset(s, rm), fpst,
50
+ */
50
+ is_q ? 16 : 8, vec_full_reg_size(s), data, fn);
51
+ SysBusDevice *s;
51
+ tcg_temp_free_ptr(fpst);
52
+ NICInfo *nd = &nd_table[0];
53
+
54
+ memory_region_init(&mms->eth_usb_container, OBJECT(mms),
55
+ "mps2-tz-eth-usb-container", 0x200000);
56
+
57
+ /*
58
+ * In hardware this is a LAN9220; the LAN9118 is software compatible
59
+ * except that it doesn't support the checksum-offload feature.
60
+ */
61
+ qemu_check_nic_model(nd, "lan9118");
62
+ mms->lan9118 = qdev_new(TYPE_LAN9118);
63
+ qdev_set_nic_properties(mms->lan9118, nd);
64
+
65
+ s = SYS_BUS_DEVICE(mms->lan9118);
66
+ sysbus_realize_and_unref(s, &error_fatal);
67
+ sysbus_connect_irq(s, 0, get_sse_irq_in(mms, irqs[0]));
68
+
69
+ memory_region_add_subregion(&mms->eth_usb_container,
70
+ 0, sysbus_mmio_get_region(s, 0));
71
+
72
+ /* The USB OTG controller is an ISP1763; we don't have a model of it. */
73
+ object_initialize_child(OBJECT(mms), "usb-otg",
74
+ &mms->usb, TYPE_UNIMPLEMENTED_DEVICE);
75
+ qdev_prop_set_string(DEVICE(&mms->usb), "name", "usb-otg");
76
+ qdev_prop_set_uint64(DEVICE(&mms->usb), "size", 0x100000);
77
+ s = SYS_BUS_DEVICE(&mms->usb);
78
+ sysbus_realize(s, &error_fatal);
79
+
80
+ memory_region_add_subregion(&mms->eth_usb_container,
81
+ 0x100000, sysbus_mmio_get_region(s, 0));
82
+
83
+ return &mms->eth_usb_container;
52
+}
84
+}
53
+
85
+
54
/* Set ZF and NF based on a 64 bit result. This is alas fiddlier
86
static MemoryRegion *make_mpc(MPS2TZMachineState *mms, void *opaque,
55
* than the 32 bit equivalent.
87
const char *name, hwaddr size,
56
*/
88
const int *irqs)
57
@@ -XXX,XX +XXX,XX @@ static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn)
89
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
58
int size = extract32(insn, 22, 2);
90
{ "gpio1", make_unimp_dev, &mms->gpio[1], 0x41101000, 0x1000 },
59
bool u = extract32(insn, 29, 1);
91
{ "gpio2", make_unimp_dev, &mms->gpio[2], 0x41102000, 0x1000 },
60
bool is_q = extract32(insn, 30, 1);
92
{ "gpio3", make_unimp_dev, &mms->gpio[3], 0x41103000, 0x1000 },
61
- int feature;
93
- { "eth", make_eth_dev, NULL, 0x41400000, 0x100000, { 48 } },
62
+ int feature, rot;
94
+ { "eth-usb", make_eth_usb, NULL, 0x41400000, 0x200000, { 48 } },
63
95
},
64
switch (u * 16 + opcode) {
96
},
65
case 0x10: /* SQRDMLAH (vector) */
97
};
66
@@ -XXX,XX +XXX,XX @@ static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn)
67
}
68
feature = ARM_FEATURE_V8_RDM;
69
break;
70
+ case 0xc: /* FCADD, #90 */
71
+ case 0xe: /* FCADD, #270 */
72
+ if (size == 0
73
+ || (size == 1 && !arm_dc_feature(s, ARM_FEATURE_V8_FP16))
74
+ || (size == 3 && !is_q)) {
75
+ unallocated_encoding(s);
76
+ return;
77
+ }
78
+ feature = ARM_FEATURE_V8_FCMA;
79
+ break;
80
default:
81
unallocated_encoding(s);
82
return;
83
@@ -XXX,XX +XXX,XX @@ static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn)
84
}
85
return;
86
87
+ case 0xc: /* FCADD, #90 */
88
+ case 0xe: /* FCADD, #270 */
89
+ rot = extract32(opcode, 1, 1);
90
+ switch (size) {
91
+ case 1:
92
+ gen_gvec_op3_fpst(s, is_q, rd, rn, rm, size == 1, rot,
93
+ gen_helper_gvec_fcaddh);
94
+ break;
95
+ case 2:
96
+ gen_gvec_op3_fpst(s, is_q, rd, rn, rm, size == 1, rot,
97
+ gen_helper_gvec_fcadds);
98
+ break;
99
+ case 3:
100
+ gen_gvec_op3_fpst(s, is_q, rd, rn, rm, size == 1, rot,
101
+ gen_helper_gvec_fcaddd);
102
+ break;
103
+ default:
104
+ g_assert_not_reached();
105
+ }
106
+ return;
107
+
108
default:
109
g_assert_not_reached();
110
}
111
diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c
112
index XXXXXXX..XXXXXXX 100644
113
--- a/target/arm/vec_helper.c
114
+++ b/target/arm/vec_helper.c
115
@@ -XXX,XX +XXX,XX @@
116
#include "exec/exec-all.h"
117
#include "exec/helper-proto.h"
118
#include "tcg/tcg-gvec-desc.h"
119
+#include "fpu/softfloat.h"
120
121
122
+/* Note that vector data is stored in host-endian 64-bit chunks,
123
+ so addressing units smaller than that needs a host-endian fixup. */
124
+#ifdef HOST_WORDS_BIGENDIAN
125
+#define H1(x) ((x) ^ 7)
126
+#define H2(x) ((x) ^ 3)
127
+#define H4(x) ((x) ^ 1)
128
+#else
129
+#define H1(x) (x)
130
+#define H2(x) (x)
131
+#define H4(x) (x)
132
+#endif
133
+
134
#define SET_QC() env->vfp.xregs[ARM_VFP_FPSCR] |= CPSR_Q
135
136
static void clear_tail(void *vd, uintptr_t opr_sz, uintptr_t max_sz)
137
@@ -XXX,XX +XXX,XX @@ void HELPER(gvec_qrdmlsh_s32)(void *vd, void *vn, void *vm,
138
}
139
clear_tail(d, opr_sz, simd_maxsz(desc));
140
}
141
+
142
+void HELPER(gvec_fcaddh)(void *vd, void *vn, void *vm,
143
+ void *vfpst, uint32_t desc)
144
+{
145
+ uintptr_t opr_sz = simd_oprsz(desc);
146
+ float16 *d = vd;
147
+ float16 *n = vn;
148
+ float16 *m = vm;
149
+ float_status *fpst = vfpst;
150
+ uint32_t neg_real = extract32(desc, SIMD_DATA_SHIFT, 1);
151
+ uint32_t neg_imag = neg_real ^ 1;
152
+ uintptr_t i;
153
+
154
+ /* Shift boolean to the sign bit so we can xor to negate. */
155
+ neg_real <<= 15;
156
+ neg_imag <<= 15;
157
+
158
+ for (i = 0; i < opr_sz / 2; i += 2) {
159
+ float16 e0 = n[H2(i)];
160
+ float16 e1 = m[H2(i + 1)] ^ neg_imag;
161
+ float16 e2 = n[H2(i + 1)];
162
+ float16 e3 = m[H2(i)] ^ neg_real;
163
+
164
+ d[H2(i)] = float16_add(e0, e1, fpst);
165
+ d[H2(i + 1)] = float16_add(e2, e3, fpst);
166
+ }
167
+ clear_tail(d, opr_sz, simd_maxsz(desc));
168
+}
169
+
170
+void HELPER(gvec_fcadds)(void *vd, void *vn, void *vm,
171
+ void *vfpst, uint32_t desc)
172
+{
173
+ uintptr_t opr_sz = simd_oprsz(desc);
174
+ float32 *d = vd;
175
+ float32 *n = vn;
176
+ float32 *m = vm;
177
+ float_status *fpst = vfpst;
178
+ uint32_t neg_real = extract32(desc, SIMD_DATA_SHIFT, 1);
179
+ uint32_t neg_imag = neg_real ^ 1;
180
+ uintptr_t i;
181
+
182
+ /* Shift boolean to the sign bit so we can xor to negate. */
183
+ neg_real <<= 31;
184
+ neg_imag <<= 31;
185
+
186
+ for (i = 0; i < opr_sz / 4; i += 2) {
187
+ float32 e0 = n[H4(i)];
188
+ float32 e1 = m[H4(i + 1)] ^ neg_imag;
189
+ float32 e2 = n[H4(i + 1)];
190
+ float32 e3 = m[H4(i)] ^ neg_real;
191
+
192
+ d[H4(i)] = float32_add(e0, e1, fpst);
193
+ d[H4(i + 1)] = float32_add(e2, e3, fpst);
194
+ }
195
+ clear_tail(d, opr_sz, simd_maxsz(desc));
196
+}
197
+
198
+void HELPER(gvec_fcaddd)(void *vd, void *vn, void *vm,
199
+ void *vfpst, uint32_t desc)
200
+{
201
+ uintptr_t opr_sz = simd_oprsz(desc);
202
+ float64 *d = vd;
203
+ float64 *n = vn;
204
+ float64 *m = vm;
205
+ float_status *fpst = vfpst;
206
+ uint64_t neg_real = extract64(desc, SIMD_DATA_SHIFT, 1);
207
+ uint64_t neg_imag = neg_real ^ 1;
208
+ uintptr_t i;
209
+
210
+ /* Shift boolean to the sign bit so we can xor to negate. */
211
+ neg_real <<= 63;
212
+ neg_imag <<= 63;
213
+
214
+ for (i = 0; i < opr_sz / 8; i += 2) {
215
+ float64 e0 = n[i];
216
+ float64 e1 = m[i + 1] ^ neg_imag;
217
+ float64 e2 = n[i + 1];
218
+ float64 e3 = m[i] ^ neg_real;
219
+
220
+ d[i] = float64_add(e0, e1, fpst);
221
+ d[i + 1] = float64_add(e2, e3, fpst);
222
+ }
223
+ clear_tail(d, opr_sz, simd_maxsz(desc));
224
+}
225
--
98
--
226
2.16.2
99
2.20.1
227
100
228
101
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
The AN524 has a PL031 RTC, which we have a model of; provide it
2
rather than an unimplemented-device stub.
2
3
3
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
4
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
5
Message-id: 20180228193125.20577-14-richard.henderson@linaro.org
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20210215115138.20465-23-peter.maydell@linaro.org
7
---
8
---
8
target/arm/translate.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++
9
hw/arm/mps2-tz.c | 22 ++++++++++++++++++++--
9
1 file changed, 68 insertions(+)
10
1 file changed, 20 insertions(+), 2 deletions(-)
10
11
11
diff --git a/target/arm/translate.c b/target/arm/translate.c
12
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
12
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
13
--- a/target/arm/translate.c
14
--- a/hw/arm/mps2-tz.c
14
+++ b/target/arm/translate.c
15
+++ b/hw/arm/mps2-tz.c
15
@@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn)
16
@@ -XXX,XX +XXX,XX @@
16
return 0;
17
#include "hw/misc/tz-msc.h"
18
#include "hw/arm/armsse.h"
19
#include "hw/dma/pl080.h"
20
+#include "hw/rtc/pl031.h"
21
#include "hw/ssi/pl022.h"
22
#include "hw/i2c/arm_sbcon_i2c.h"
23
#include "hw/net/lan9118.h"
24
@@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineState {
25
UnimplementedDeviceState gpio[4];
26
UnimplementedDeviceState gfx;
27
UnimplementedDeviceState cldc;
28
- UnimplementedDeviceState rtc;
29
UnimplementedDeviceState usb;
30
+ PL031State rtc;
31
PL080State dma[4];
32
TZMSC msc[4];
33
CMSDKAPBUART uart[6];
34
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_i2c(MPS2TZMachineState *mms, void *opaque,
35
return sysbus_mmio_get_region(s, 0);
17
}
36
}
18
37
19
+/* Advanced SIMD three registers of the same length extension.
38
+static MemoryRegion *make_rtc(MPS2TZMachineState *mms, void *opaque,
20
+ * 31 25 23 22 20 16 12 11 10 9 8 3 0
39
+ const char *name, hwaddr size,
21
+ * +---------------+-----+---+-----+----+----+---+----+---+----+---------+----+
40
+ const int *irqs)
22
+ * | 1 1 1 1 1 1 0 | op1 | D | op2 | Vn | Vd | 1 | o3 | 0 | o4 | N Q M U | Vm |
23
+ * +---------------+-----+---+-----+----+----+---+----+---+----+---------+----+
24
+ */
25
+static int disas_neon_insn_3same_ext(DisasContext *s, uint32_t insn)
26
+{
41
+{
27
+ gen_helper_gvec_3_ptr *fn_gvec_ptr;
42
+ PL031State *pl031 = opaque;
28
+ int rd, rn, rm, rot, size, opr_sz;
43
+ SysBusDevice *s;
29
+ TCGv_ptr fpst;
30
+ bool q;
31
+
44
+
32
+ q = extract32(insn, 6, 1);
45
+ object_initialize_child(OBJECT(mms), name, pl031, TYPE_PL031);
33
+ VFP_DREG_D(rd, insn);
46
+ s = SYS_BUS_DEVICE(pl031);
34
+ VFP_DREG_N(rn, insn);
47
+ sysbus_realize(s, &error_fatal);
35
+ VFP_DREG_M(rm, insn);
48
+ /*
36
+ if ((rd | rn | rm) & q) {
49
+ * The board docs don't give an IRQ number for the PL031, so
37
+ return 1;
50
+ * presumably it is not connected.
38
+ }
51
+ */
39
+
52
+ return sysbus_mmio_get_region(s, 0);
40
+ if ((insn & 0xfe200f10) == 0xfc200800) {
41
+ /* VCMLA -- 1111 110R R.1S .... .... 1000 ...0 .... */
42
+ size = extract32(insn, 20, 1);
43
+ rot = extract32(insn, 23, 2);
44
+ if (!arm_dc_feature(s, ARM_FEATURE_V8_FCMA)
45
+ || (!size && !arm_dc_feature(s, ARM_FEATURE_V8_FP16))) {
46
+ return 1;
47
+ }
48
+ fn_gvec_ptr = size ? gen_helper_gvec_fcmlas : gen_helper_gvec_fcmlah;
49
+ } else if ((insn & 0xfea00f10) == 0xfc800800) {
50
+ /* VCADD -- 1111 110R 1.0S .... .... 1000 ...0 .... */
51
+ size = extract32(insn, 20, 1);
52
+ rot = extract32(insn, 24, 1);
53
+ if (!arm_dc_feature(s, ARM_FEATURE_V8_FCMA)
54
+ || (!size && !arm_dc_feature(s, ARM_FEATURE_V8_FP16))) {
55
+ return 1;
56
+ }
57
+ fn_gvec_ptr = size ? gen_helper_gvec_fcadds : gen_helper_gvec_fcaddh;
58
+ } else {
59
+ return 1;
60
+ }
61
+
62
+ if (s->fp_excp_el) {
63
+ gen_exception_insn(s, 4, EXCP_UDEF,
64
+ syn_fp_access_trap(1, 0xe, false), s->fp_excp_el);
65
+ return 0;
66
+ }
67
+ if (!s->vfp_enabled) {
68
+ return 1;
69
+ }
70
+
71
+ opr_sz = (1 + q) * 8;
72
+ fpst = get_fpstatus_ptr(1);
73
+ tcg_gen_gvec_3_ptr(vfp_reg_offset(1, rd),
74
+ vfp_reg_offset(1, rn),
75
+ vfp_reg_offset(1, rm), fpst,
76
+ opr_sz, opr_sz, rot, fn_gvec_ptr);
77
+ tcg_temp_free_ptr(fpst);
78
+ return 0;
79
+}
53
+}
80
+
54
+
81
static int disas_coproc_insn(DisasContext *s, uint32_t insn)
55
static void create_non_mpc_ram(MPS2TZMachineState *mms)
82
{
56
{
83
int cpnum, is64, crn, crm, opc1, opc2, isread, rt, rt2;
57
/*
84
@@ -XXX,XX +XXX,XX @@ static void disas_arm_insn(DisasContext *s, unsigned int insn)
58
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
85
}
59
86
}
60
{ /* port 9 reserved */ },
87
}
61
{ "clcd", make_unimp_dev, &mms->cldc, 0x4130a000, 0x1000 },
88
+ } else if ((insn & 0x0e000a00) == 0x0c000800
62
- { "rtc", make_unimp_dev, &mms->rtc, 0x4130b000, 0x1000 },
89
+ && arm_dc_feature(s, ARM_FEATURE_V8)) {
63
+ { "rtc", make_rtc, &mms->rtc, 0x4130b000, 0x1000 },
90
+ if (disas_neon_insn_3same_ext(s, insn)) {
64
},
91
+ goto illegal_op;
65
}, {
92
+ }
66
.name = "ahb_ppcexp0",
93
+ return;
94
} else if ((insn & 0x0fe00000) == 0x0c400000) {
95
/* Coprocessor double register transfer. */
96
ARCH(5TE);
97
--
67
--
98
2.16.2
68
2.20.1
99
69
100
70
diff view generated by jsdifflib
1
Instead of loading guest images to the system address space, use the
1
Add brief documentation of the new mps3-an524 board.
2
CPU's address space. This is important if we're trying to load the
3
file to memory or via an alias memory region that is provided by an
4
SoC object and thus not mapped into the system address space.
5
2
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
3
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
4
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Message-id: 20180220180325.29818-4-peter.maydell@linaro.org
6
Message-id: 20210215115138.20465-24-peter.maydell@linaro.org
10
---
7
---
11
hw/arm/armv7m.c | 17 ++++++++++++++---
8
docs/system/arm/mps2.rst | 24 ++++++++++++++++++------
12
1 file changed, 14 insertions(+), 3 deletions(-)
9
1 file changed, 18 insertions(+), 6 deletions(-)
13
10
14
diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c
11
diff --git a/docs/system/arm/mps2.rst b/docs/system/arm/mps2.rst
15
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/arm/armv7m.c
13
--- a/docs/system/arm/mps2.rst
17
+++ b/hw/arm/armv7m.c
14
+++ b/docs/system/arm/mps2.rst
18
@@ -XXX,XX +XXX,XX @@ void armv7m_load_kernel(ARMCPU *cpu, const char *kernel_filename, int mem_size)
15
@@ -XXX,XX +XXX,XX @@
19
uint64_t entry;
16
-Arm MPS2 boards (``mps2-an385``, ``mps2-an386``, ``mps2-an500``, ``mps2-an505``, ``mps2-an511``, ``mps2-an521``)
20
uint64_t lowaddr;
17
-================================================================================================================
21
int big_endian;
18
+Arm MPS2 and MPS3 boards (``mps2-an385``, ``mps2-an386``, ``mps2-an500``, ``mps2-an505``, ``mps2-an511``, ``mps2-an521``, ``mps3-an524``)
22
+ AddressSpace *as;
19
+=========================================================================================================================================
23
+ int asidx;
20
24
+ CPUState *cs = CPU(cpu);
21
These board models all use Arm M-profile CPUs.
25
22
26
#ifdef TARGET_WORDS_BIGENDIAN
23
-The Arm MPS2 and MPS2+ dev boards are FPGA based (the 2+ has a bigger
27
big_endian = 1;
24
-FPGA but is otherwise the same as the 2). Since the CPU itself
28
@@ -XXX,XX +XXX,XX @@ void armv7m_load_kernel(ARMCPU *cpu, const char *kernel_filename, int mem_size)
25
-and most of the devices are in the FPGA, the details of the board
29
exit(1);
26
-as seen by the guest depend significantly on the FPGA image.
30
}
27
+The Arm MPS2, MPS2+ and MPS3 dev boards are FPGA based (the 2+ has a
31
28
+bigger FPGA but is otherwise the same as the 2; the 3 has a bigger
32
+ if (arm_feature(&cpu->env, ARM_FEATURE_EL3)) {
29
+FPGA again, can handle 4GB of RAM and has a USB controller and QSPI flash).
33
+ asidx = ARMASIdx_S;
34
+ } else {
35
+ asidx = ARMASIdx_NS;
36
+ }
37
+ as = cpu_get_address_space(cs, asidx);
38
+
30
+
39
if (kernel_filename) {
31
+Since the CPU itself and most of the devices are in the FPGA, the
40
- image_size = load_elf(kernel_filename, NULL, NULL, &entry, &lowaddr,
32
+details of the board as seen by the guest depend significantly on the
41
- NULL, big_endian, EM_ARM, 1, 0);
33
+FPGA image.
42
+ image_size = load_elf_as(kernel_filename, NULL, NULL, &entry, &lowaddr,
34
43
+ NULL, big_endian, EM_ARM, 1, 0, as);
35
QEMU models the following FPGA images:
44
if (image_size < 0) {
36
45
- image_size = load_image_targphys(kernel_filename, 0, mem_size);
37
@@ -XXX,XX +XXX,XX @@ QEMU models the following FPGA images:
46
+ image_size = load_image_targphys_as(kernel_filename, 0,
38
Cortex-M3 'DesignStart' as documented in Arm Application Note AN511
47
+ mem_size, as);
39
``mps2-an521``
48
lowaddr = 0;
40
Dual Cortex-M33 as documented in Arm Application Note AN521
49
}
41
+``mps3-an524``
50
if (image_size < 0) {
42
+ Dual Cortex-M33 on an MPS3, as documented in Arm Application Note AN524
43
44
Differences between QEMU and real hardware:
45
46
- AN385/AN386 remapping of low 16K of memory to either ZBT SSRAM1 or to
47
block RAM is unimplemented (QEMU always maps this to ZBT SSRAM1, as
48
if zbt_boot_ctrl is always zero)
49
+- AN524 remapping of low memory to either BRAM or to QSPI flash is
50
+ unimplemented (QEMU always maps this to BRAM, ignoring the
51
+ SCC CFG_REG0 memory-remap bit)
52
- QEMU provides a LAN9118 ethernet rather than LAN9220; the only guest
53
visible difference is that the LAN9118 doesn't support checksum
54
offloading
55
+- QEMU does not model the QSPI flash in MPS3 boards as real QSPI
56
+ flash, but only as simple ROM, so attempting to rewrite the flash
57
+ from the guest will fail
58
+- QEMU does not model the USB controller in MPS3 boards
51
--
59
--
52
2.16.2
60
2.20.1
53
61
54
62
diff view generated by jsdifflib
1
Add remaining easy registers to iotkit-secctl:
1
Update old infocenter.arm.com URLs to the equivalent developer.arm.com
2
* NSCCFG just routes its two bits out to external GPIO lines
2
ones (the old URLs should redirect, but we might as well avoid the
3
* BRGINSTAT/BRGINTCLR/BRGINTEN can be dummies, because QEMU's
3
redirection notice, and the new URLs are pleasantly shorter).
4
bus fabric can never report errors
4
5
This commit covers the links to the MPS2 board TRM, the various
6
Application Notes, the IoTKit and SSE-200 documents.
5
7
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Message-id: 20180220180325.29818-18-peter.maydell@linaro.org
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
Message-id: 20210215115138.20465-25-peter.maydell@linaro.org
8
---
11
---
9
include/hw/misc/iotkit-secctl.h | 4 ++++
12
include/hw/arm/armsse.h | 4 ++--
10
hw/misc/iotkit-secctl.c | 32 ++++++++++++++++++++++++++------
13
include/hw/misc/armsse-cpuid.h | 2 +-
11
2 files changed, 30 insertions(+), 6 deletions(-)
14
include/hw/misc/armsse-mhu.h | 2 +-
12
15
include/hw/misc/iotkit-secctl.h | 2 +-
16
include/hw/misc/iotkit-sysctl.h | 2 +-
17
include/hw/misc/iotkit-sysinfo.h | 2 +-
18
include/hw/misc/mps2-fpgaio.h | 2 +-
19
hw/arm/mps2-tz.c | 11 +++++------
20
hw/misc/armsse-cpuid.c | 2 +-
21
hw/misc/armsse-mhu.c | 2 +-
22
hw/misc/iotkit-sysctl.c | 2 +-
23
hw/misc/iotkit-sysinfo.c | 2 +-
24
hw/misc/mps2-fpgaio.c | 2 +-
25
hw/misc/mps2-scc.c | 2 +-
26
14 files changed, 19 insertions(+), 20 deletions(-)
27
28
diff --git a/include/hw/arm/armsse.h b/include/hw/arm/armsse.h
29
index XXXXXXX..XXXXXXX 100644
30
--- a/include/hw/arm/armsse.h
31
+++ b/include/hw/arm/armsse.h
32
@@ -XXX,XX +XXX,XX @@
33
* hardware, which include the IoT Kit and the SSE-050, SSE-100 and
34
* SSE-200. Currently we model:
35
* - the Arm IoT Kit which is documented in
36
- * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
37
+ * https://developer.arm.com/documentation/ecm0601256/latest
38
* - the SSE-200 which is documented in
39
- * http://infocenter.arm.com/help/topic/com.arm.doc.101104_0100_00_en/corelink_sse200_subsystem_for_embedded_technical_reference_manual_101104_0100_00_en.pdf
40
+ * https://developer.arm.com/documentation/101104/latest/
41
*
42
* The IoTKit contains:
43
* a Cortex-M33
44
diff --git a/include/hw/misc/armsse-cpuid.h b/include/hw/misc/armsse-cpuid.h
45
index XXXXXXX..XXXXXXX 100644
46
--- a/include/hw/misc/armsse-cpuid.h
47
+++ b/include/hw/misc/armsse-cpuid.h
48
@@ -XXX,XX +XXX,XX @@
49
/*
50
* This is a model of the "CPU_IDENTITY" register block which is part of the
51
* Arm SSE-200 and documented in
52
- * http://infocenter.arm.com/help/topic/com.arm.doc.101104_0100_00_en/corelink_sse200_subsystem_for_embedded_technical_reference_manual_101104_0100_00_en.pdf
53
+ * https://developer.arm.com/documentation/101104/latest/
54
*
55
* QEMU interface:
56
* + QOM property "CPUID": the value to use for the CPUID register
57
diff --git a/include/hw/misc/armsse-mhu.h b/include/hw/misc/armsse-mhu.h
58
index XXXXXXX..XXXXXXX 100644
59
--- a/include/hw/misc/armsse-mhu.h
60
+++ b/include/hw/misc/armsse-mhu.h
61
@@ -XXX,XX +XXX,XX @@
62
/*
63
* This is a model of the Message Handling Unit (MHU) which is part of the
64
* Arm SSE-200 and documented in
65
- * http://infocenter.arm.com/help/topic/com.arm.doc.101104_0100_00_en/corelink_sse200_subsystem_for_embedded_technical_reference_manual_101104_0100_00_en.pdf
66
+ * https://developer.arm.com/documentation/101104/latest/
67
*
68
* QEMU interface:
69
* + sysbus MMIO region 0: the system information register bank
13
diff --git a/include/hw/misc/iotkit-secctl.h b/include/hw/misc/iotkit-secctl.h
70
diff --git a/include/hw/misc/iotkit-secctl.h b/include/hw/misc/iotkit-secctl.h
14
index XXXXXXX..XXXXXXX 100644
71
index XXXXXXX..XXXXXXX 100644
15
--- a/include/hw/misc/iotkit-secctl.h
72
--- a/include/hw/misc/iotkit-secctl.h
16
+++ b/include/hw/misc/iotkit-secctl.h
73
+++ b/include/hw/misc/iotkit-secctl.h
17
@@ -XXX,XX +XXX,XX @@
74
@@ -XXX,XX +XXX,XX @@
18
* + sysbus MMIO region 1 is the "non-secure privilege control block" registers
75
19
* + named GPIO output "sec_resp_cfg" indicating whether blocked accesses
76
/* This is a model of the security controller which is part of the
20
* should RAZ/WI or bus error
77
* Arm IoT Kit and documented in
21
+ * + named GPIO output "nsc_cfg" whose value tracks the NSCCFG register value
78
- * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
22
* Controlling the 2 APB PPCs in the IoTKit:
79
+ * https://developer.arm.com/documentation/ecm0601256/latest
23
* + named GPIO outputs apb_ppc0_nonsec[0..2] and apb_ppc1_nonsec
80
*
24
* + named GPIO outputs apb_ppc0_ap[0..2] and apb_ppc1_ap
81
* QEMU interface:
25
@@ -XXX,XX +XXX,XX @@ struct IoTKitSecCtl {
82
* + sysbus MMIO region 0 is the "secure privilege control block" registers
26
83
diff --git a/include/hw/misc/iotkit-sysctl.h b/include/hw/misc/iotkit-sysctl.h
27
/*< public >*/
84
index XXXXXXX..XXXXXXX 100644
28
qemu_irq sec_resp_cfg;
85
--- a/include/hw/misc/iotkit-sysctl.h
29
+ qemu_irq nsc_cfg_irq;
86
+++ b/include/hw/misc/iotkit-sysctl.h
30
87
@@ -XXX,XX +XXX,XX @@
31
MemoryRegion s_regs;
88
/*
32
MemoryRegion ns_regs;
89
* This is a model of the "system control element" which is part of the
33
@@ -XXX,XX +XXX,XX @@ struct IoTKitSecCtl {
90
* Arm IoTKit and documented in
34
uint32_t secppcintstat;
91
- * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
35
uint32_t secppcinten;
92
+ * https://developer.arm.com/documentation/ecm0601256/latest
36
uint32_t secrespcfg;
93
* Specifically, it implements the "system information block" and
37
+ uint32_t nsccfg;
94
* "system control register" blocks.
38
+ uint32_t brginten;
95
*
39
96
diff --git a/include/hw/misc/iotkit-sysinfo.h b/include/hw/misc/iotkit-sysinfo.h
40
IoTKitSecCtlPPC apb[IOTS_NUM_APB_PPC];
97
index XXXXXXX..XXXXXXX 100644
41
IoTKitSecCtlPPC apbexp[IOTS_NUM_APB_EXP_PPC];
98
--- a/include/hw/misc/iotkit-sysinfo.h
42
diff --git a/hw/misc/iotkit-secctl.c b/hw/misc/iotkit-secctl.c
99
+++ b/include/hw/misc/iotkit-sysinfo.h
43
index XXXXXXX..XXXXXXX 100644
100
@@ -XXX,XX +XXX,XX @@
44
--- a/hw/misc/iotkit-secctl.c
101
/*
45
+++ b/hw/misc/iotkit-secctl.c
102
* This is a model of the "system information block" which is part of the
46
@@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_s_read(void *opaque, hwaddr addr,
103
* Arm IoTKit and documented in
47
case A_SECRESPCFG:
104
- * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
48
r = s->secrespcfg;
105
+ * https://developer.arm.com/documentation/ecm0601256/latest
49
break;
106
* QEMU interface:
50
+ case A_NSCCFG:
107
* + QOM property "SYS_VERSION": value to use for SYS_VERSION register
51
+ r = s->nsccfg;
108
* + QOM property "SYS_CONFIG": value to use for SYS_CONFIG register
52
+ break;
109
diff --git a/include/hw/misc/mps2-fpgaio.h b/include/hw/misc/mps2-fpgaio.h
53
case A_SECPPCINTSTAT:
110
index XXXXXXX..XXXXXXX 100644
54
r = s->secppcintstat;
111
--- a/include/hw/misc/mps2-fpgaio.h
55
break;
112
+++ b/include/hw/misc/mps2-fpgaio.h
56
case A_SECPPCINTEN:
113
@@ -XXX,XX +XXX,XX @@
57
r = s->secppcinten;
114
/* This is a model of the FPGAIO register block in the AN505
58
break;
115
* FPGA image for the MPS2 dev board; it is documented in the
59
+ case A_BRGINTSTAT:
116
* application note:
60
+ /* QEMU's bus fabric can never report errors as it doesn't buffer
117
- * http://infocenter.arm.com/help/topic/com.arm.doc.dai0505b/index.html
61
+ * writes, so we never report bridge interrupts.
118
+ * https://developer.arm.com/documentation/dai0505/latest/
62
+ */
119
*
63
+ r = 0;
120
* QEMU interface:
64
+ break;
121
* + sysbus MMIO region 0: the register bank
65
+ case A_BRGINTEN:
122
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
66
+ r = s->brginten;
123
index XXXXXXX..XXXXXXX 100644
67
+ break;
124
--- a/hw/arm/mps2-tz.c
68
case A_AHBNSPPCEXP0:
125
+++ b/hw/arm/mps2-tz.c
69
case A_AHBNSPPCEXP1:
126
@@ -XXX,XX +XXX,XX @@
70
case A_AHBNSPPCEXP2:
127
* https://developer.arm.com/products/system-design/development-boards/fpga-prototyping-boards/mps2
71
@@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_s_read(void *opaque, hwaddr addr,
128
*
72
case A_APBSPPPCEXP3:
129
* Board TRM:
73
r = s->apbexp[offset_to_ppc_idx(offset)].sp;
130
- * http://infocenter.arm.com/help/topic/com.arm.doc.100112_0200_06_en/versatile_express_cortex_m_prototyping_systems_v2m_mps2_and_v2m_mps2plus_technical_reference_100112_0200_06_en.pdf
74
break;
131
+ * https://developer.arm.com/documentation/100112/latest/
75
- case A_NSCCFG:
132
* Application Note AN505:
76
case A_SECMPCINTSTATUS:
133
- * http://infocenter.arm.com/help/topic/com.arm.doc.dai0505b/index.html
77
case A_SECMSCINTSTAT:
134
+ * https://developer.arm.com/documentation/dai0505/latest/
78
case A_SECMSCINTEN:
135
* Application Note AN521:
79
- case A_BRGINTSTAT:
136
- * http://infocenter.arm.com/help/topic/com.arm.doc.dai0521c/index.html
80
- case A_BRGINTEN:
137
+ * https://developer.arm.com/documentation/dai0521/latest/
81
case A_NSMSCEXP:
138
* Application Note AN524:
82
qemu_log_mask(LOG_UNIMP,
139
* https://developer.arm.com/documentation/dai0524/latest/
83
"IoTKit SecCtl S block read: "
140
*
84
@@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr,
141
* The AN505 defers to the Cortex-M33 processor ARMv8M IoT Kit FVP User Guide
85
}
142
* (ARM ECM0601256) for the details of some of the device layout:
86
143
- * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
87
switch (offset) {
144
+ * https://developer.arm.com/documentation/ecm0601256/latest
88
+ case A_NSCCFG:
145
* Similarly, the AN521 and AN524 use the SSE-200, and the SSE-200 TRM defines
89
+ s->nsccfg = value & 3;
146
* most of the device layout:
90
+ qemu_set_irq(s->nsc_cfg_irq, s->nsccfg);
147
- * http://infocenter.arm.com/help/topic/com.arm.doc.101104_0100_00_en/corelink_sse200_subsystem_for_embedded_technical_reference_manual_101104_0100_00_en.pdf
91
+ break;
148
- *
92
case A_SECRESPCFG:
149
+ * https://developer.arm.com/documentation/101104/latest/
93
value &= 1;
150
*/
94
s->secrespcfg = value;
151
95
@@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr,
152
#include "qemu/osdep.h"
96
s->secppcinten = value & 0x00f000f3;
153
diff --git a/hw/misc/armsse-cpuid.c b/hw/misc/armsse-cpuid.c
97
foreach_ppc(s, iotkit_secctl_ppc_update_irq_enable);
154
index XXXXXXX..XXXXXXX 100644
98
break;
155
--- a/hw/misc/armsse-cpuid.c
99
+ case A_BRGINTCLR:
156
+++ b/hw/misc/armsse-cpuid.c
100
+ break;
157
@@ -XXX,XX +XXX,XX @@
101
+ case A_BRGINTEN:
158
/*
102
+ s->brginten = value & 0xffff0000;
159
* This is a model of the "CPU_IDENTITY" register block which is part of the
103
+ break;
160
* Arm SSE-200 and documented in
104
case A_AHBNSPPCEXP0:
161
- * http://infocenter.arm.com/help/topic/com.arm.doc.101104_0100_00_en/corelink_sse200_subsystem_for_embedded_technical_reference_manual_101104_0100_00_en.pdf
105
case A_AHBNSPPCEXP1:
162
+ * https://developer.arm.com/documentation/101104/latest/
106
case A_AHBNSPPCEXP2:
163
*
107
@@ -XXX,XX +XXX,XX @@ static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr,
164
* It consists of one read-only CPUID register (set by QOM property), plus the
108
ppc = &s->apbexp[offset_to_ppc_idx(offset)];
165
* usual ID registers.
109
iotkit_secctl_ppc_sp_write(ppc, value);
166
diff --git a/hw/misc/armsse-mhu.c b/hw/misc/armsse-mhu.c
110
break;
167
index XXXXXXX..XXXXXXX 100644
111
- case A_NSCCFG:
168
--- a/hw/misc/armsse-mhu.c
112
case A_SECMSCINTCLR:
169
+++ b/hw/misc/armsse-mhu.c
113
case A_SECMSCINTEN:
170
@@ -XXX,XX +XXX,XX @@
114
- case A_BRGINTCLR:
171
/*
115
- case A_BRGINTEN:
172
* This is a model of the Message Handling Unit (MHU) which is part of the
116
qemu_log_mask(LOG_UNIMP,
173
* Arm SSE-200 and documented in
117
"IoTKit SecCtl S block write: "
174
- * http://infocenter.arm.com/help/topic/com.arm.doc.101104_0100_00_en/corelink_sse200_subsystem_for_embedded_technical_reference_manual_101104_0100_00_en.pdf
118
"unimplemented offset 0x%x\n", offset);
175
+ * https://developer.arm.com/documentation/101104/latest/
119
@@ -XXX,XX +XXX,XX @@ static void iotkit_secctl_reset(DeviceState *dev)
176
*/
120
s->secppcintstat = 0;
177
121
s->secppcinten = 0;
178
#include "qemu/osdep.h"
122
s->secrespcfg = 0;
179
diff --git a/hw/misc/iotkit-sysctl.c b/hw/misc/iotkit-sysctl.c
123
+ s->nsccfg = 0;
180
index XXXXXXX..XXXXXXX 100644
124
+ s->brginten = 0;
181
--- a/hw/misc/iotkit-sysctl.c
125
182
+++ b/hw/misc/iotkit-sysctl.c
126
foreach_ppc(s, iotkit_secctl_reset_ppc);
183
@@ -XXX,XX +XXX,XX @@
127
}
184
/*
128
@@ -XXX,XX +XXX,XX @@ static void iotkit_secctl_init(Object *obj)
185
* This is a model of the "system control element" which is part of the
129
}
186
* Arm IoTKit and documented in
130
187
- * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
131
qdev_init_gpio_out_named(dev, &s->sec_resp_cfg, "sec_resp_cfg", 1);
188
+ * https://developer.arm.com/documentation/ecm0601256/latest
132
+ qdev_init_gpio_out_named(dev, &s->nsc_cfg_irq, "nsc_cfg", 1);
189
* Specifically, it implements the "system control register" blocks.
133
190
*/
134
memory_region_init_io(&s->s_regs, obj, &iotkit_secctl_s_ops,
191
135
s, "iotkit-secctl-s-regs", 0x1000);
192
diff --git a/hw/misc/iotkit-sysinfo.c b/hw/misc/iotkit-sysinfo.c
136
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription iotkit_secctl_vmstate = {
193
index XXXXXXX..XXXXXXX 100644
137
VMSTATE_UINT32(secppcintstat, IoTKitSecCtl),
194
--- a/hw/misc/iotkit-sysinfo.c
138
VMSTATE_UINT32(secppcinten, IoTKitSecCtl),
195
+++ b/hw/misc/iotkit-sysinfo.c
139
VMSTATE_UINT32(secrespcfg, IoTKitSecCtl),
196
@@ -XXX,XX +XXX,XX @@
140
+ VMSTATE_UINT32(nsccfg, IoTKitSecCtl),
197
/*
141
+ VMSTATE_UINT32(brginten, IoTKitSecCtl),
198
* This is a model of the "system information block" which is part of the
142
VMSTATE_STRUCT_ARRAY(apb, IoTKitSecCtl, IOTS_NUM_APB_PPC, 1,
199
* Arm IoTKit and documented in
143
iotkit_secctl_ppc_vmstate, IoTKitSecCtlPPC),
200
- * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
144
VMSTATE_STRUCT_ARRAY(apbexp, IoTKitSecCtl, IOTS_NUM_APB_EXP_PPC, 1,
201
+ * https://developer.arm.com/documentation/ecm0601256/latest
202
* It consists of 2 read-only version/config registers, plus the
203
* usual ID registers.
204
*/
205
diff --git a/hw/misc/mps2-fpgaio.c b/hw/misc/mps2-fpgaio.c
206
index XXXXXXX..XXXXXXX 100644
207
--- a/hw/misc/mps2-fpgaio.c
208
+++ b/hw/misc/mps2-fpgaio.c
209
@@ -XXX,XX +XXX,XX @@
210
/* This is a model of the "FPGA system control and I/O" block found
211
* in the AN505 FPGA image for the MPS2 devboard.
212
* It is documented in AN505:
213
- * http://infocenter.arm.com/help/topic/com.arm.doc.dai0505b/index.html
214
+ * https://developer.arm.com/documentation/dai0505/latest/
215
*/
216
217
#include "qemu/osdep.h"
218
diff --git a/hw/misc/mps2-scc.c b/hw/misc/mps2-scc.c
219
index XXXXXXX..XXXXXXX 100644
220
--- a/hw/misc/mps2-scc.c
221
+++ b/hw/misc/mps2-scc.c
222
@@ -XXX,XX +XXX,XX @@
223
* found in the FPGA images of MPS2 development boards.
224
*
225
* Documentation of it can be found in the MPS2 TRM:
226
- * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.100112_0100_03_en/index.html
227
+ * https://developer.arm.com/documentation/100112/latest/
228
* and also in the Application Notes documenting individual FPGA images.
229
*/
230
145
--
231
--
146
2.16.2
232
2.20.1
147
233
148
234
diff view generated by jsdifflib