1
ARM queue: mostly patches from me, but also the Smartfusion2 board.
1
arm queue; dunno if this will be the last before softfreeze
2
or not, but anyway probably the last large one. New orangepi-pc
3
board model is the big item here.
2
4
3
thanks
5
thanks
4
-- PMM
6
-- PMM
5
7
6
The following changes since commit 9ee660e7c138595224b65ddc1c5712549f0a278c:
8
The following changes since commit 67d9ef7d541c3d21a25796c51c26da096a433565:
7
9
8
Merge remote-tracking branch 'remotes/yongbok/tags/mips-20170921' into staging (2017-09-21 14:40:32 +0100)
10
Merge remote-tracking branch 'remotes/pmaydell/tags/pull-docs-20200312' into staging (2020-03-12 15:20:52 +0000)
9
11
10
are available in the git repository at:
12
are available in the Git repository at:
11
13
12
git://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20170921
14
https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20200312
13
15
14
for you to fetch changes up to 6d262dcb7d108eda93813574c2061398084dc795:
16
for you to fetch changes up to aca53be34ac3e7cac5f39396a51a338860a5a837:
15
17
16
msf2: Add Emcraft's Smartfusion2 SOM kit (2017-09-21 16:36:56 +0100)
18
target/arm: kvm: Inject events at the last stage of sync (2020-03-12 16:31:10 +0000)
17
19
18
----------------------------------------------------------------
20
----------------------------------------------------------------
19
target-arm queue:
21
target-arm queue:
20
* more preparatory work for v8M support
22
* Fix various bugs that might result in an assert() due to
21
* convert some omap devices away from old_mmio
23
incorrect hflags for M-profile CPUs
22
* remove out of date ARM ARM section references in comments
24
* Fix Aspeed SMC Controller user-mode select handling
23
* add the Smartfusion2 board
25
* Report correct (with-tag) address in fault address register
26
when TBI is enabled
27
* cubieboard: make sure SOC object isn't leaked
28
* fsl-imx25: Wire up eSDHC controllers
29
* fsl-imx25: Wire up USB controllers
30
* New board model: orangepi-pc (OrangePi PC)
31
* ARM/KVM: if user doesn't select GIC version and the
32
host kernel can only provide GICv3, use that, rather
33
than defaulting to "fail because GICv2 isn't possible"
34
* kvm: Only do KVM_SET_VCPU_EVENTS at the last stage of sync
24
35
25
----------------------------------------------------------------
36
----------------------------------------------------------------
26
Peter Maydell (26):
37
Beata Michalska (1):
27
target/arm: Implement MSR/MRS access to NS banked registers
38
target/arm: kvm: Inject events at the last stage of sync
28
nvic: Add banked exception states
29
nvic: Add cached vectpending_is_s_banked state
30
nvic: Add cached vectpending_prio state
31
nvic: Implement AIRCR changes for v8M
32
nvic: Make ICSR.RETTOBASE handle banked exceptions
33
nvic: Implement NVIC_ITNS<n> registers
34
nvic: Handle banked exceptions in nvic_recompute_state()
35
nvic: Make set_pending and clear_pending take a secure parameter
36
nvic: Make SHPR registers banked
37
nvic: Compare group priority for escalation to HF
38
nvic: In escalation to HardFault, support HF not being priority -1
39
nvic: Implement v8M changes to fixed priority exceptions
40
nvic: Disable the non-secure HardFault if AIRCR.BFHFNMINS is clear
41
nvic: Handle v8M changes in nvic_exec_prio()
42
target/arm: Handle banking in negative-execution-priority check in cpu_mmu_index()
43
nvic: Make ICSR banked for v8M
44
nvic: Make SHCSR banked for v8M
45
nvic: Support banked exceptions in acknowledge and complete
46
target/arm: Remove out of date ARM ARM section references in A64 decoder
47
hw/arm/palm.c: Don't use old_mmio for static_ops
48
hw/gpio/omap_gpio.c: Don't use old_mmio
49
hw/timer/omap_synctimer.c: Don't use old_mmio
50
hw/timer/omap_gptimer: Don't use old_mmio
51
hw/i2c/omap_i2c.c: Don't use old_mmio
52
hw/arm/omap2.c: Don't use old_mmio
53
39
54
Subbaraya Sundeep (5):
40
Cédric Le Goater (2):
55
msf2: Add Smartfusion2 System timer
41
aspeed/smc: Add some tracing
56
msf2: Microsemi Smartfusion2 System Register block
42
aspeed/smc: Fix User mode select/unselect scheme
57
msf2: Add Smartfusion2 SPI controller
58
msf2: Add Smartfusion2 SoC
59
msf2: Add Emcraft's Smartfusion2 SOM kit
60
43
61
hw/arm/Makefile.objs | 1 +
44
Eric Auger (6):
62
hw/misc/Makefile.objs | 1 +
45
hw/arm/virt: Document 'max' value in gic-version property description
63
hw/ssi/Makefile.objs | 1 +
46
hw/arm/virt: Introduce VirtGICType enum type
64
hw/timer/Makefile.objs | 1 +
47
hw/arm/virt: Introduce finalize_gic_version()
65
include/hw/arm/msf2-soc.h | 67 +++
48
target/arm/kvm: Let kvm_arm_vgic_probe() return a bitmap
66
include/hw/intc/armv7m_nvic.h | 33 +-
49
hw/arm/virt: kvm: Restructure finalize_gic_version()
67
include/hw/misc/msf2-sysreg.h | 77 ++++
50
hw/arm/virt: kvm: allow gicv3 by default if v2 cannot work
68
include/hw/ssi/mss-spi.h | 58 +++
69
include/hw/timer/mss-timer.h | 64 +++
70
target/arm/cpu.h | 62 ++-
71
hw/arm/msf2-soc.c | 238 +++++++++++
72
hw/arm/msf2-som.c | 105 +++++
73
hw/arm/omap2.c | 49 ++-
74
hw/arm/palm.c | 30 +-
75
hw/gpio/omap_gpio.c | 26 +-
76
hw/i2c/omap_i2c.c | 44 +-
77
hw/intc/armv7m_nvic.c | 913 ++++++++++++++++++++++++++++++++++------
78
hw/misc/msf2-sysreg.c | 160 +++++++
79
hw/ssi/mss-spi.c | 404 ++++++++++++++++++
80
hw/timer/mss-timer.c | 289 +++++++++++++
81
hw/timer/omap_gptimer.c | 49 ++-
82
hw/timer/omap_synctimer.c | 35 +-
83
target/arm/cpu.c | 7 +
84
target/arm/helper.c | 142 ++++++-
85
target/arm/translate-a64.c | 227 +++++-----
86
default-configs/arm-softmmu.mak | 1 +
87
hw/intc/trace-events | 13 +-
88
hw/misc/trace-events | 5 +
89
28 files changed, 2735 insertions(+), 367 deletions(-)
90
create mode 100644 include/hw/arm/msf2-soc.h
91
create mode 100644 include/hw/misc/msf2-sysreg.h
92
create mode 100644 include/hw/ssi/mss-spi.h
93
create mode 100644 include/hw/timer/mss-timer.h
94
create mode 100644 hw/arm/msf2-soc.c
95
create mode 100644 hw/arm/msf2-som.c
96
create mode 100644 hw/misc/msf2-sysreg.c
97
create mode 100644 hw/ssi/mss-spi.c
98
create mode 100644 hw/timer/mss-timer.c
99
51
52
Guenter Roeck (2):
53
hw/arm/fsl-imx25: Wire up eSDHC controllers
54
hw/arm/fsl-imx25: Wire up USB controllers
55
56
Igor Mammedov (1):
57
hw/arm/cubieboard: make sure SOC object isn't leaked
58
59
Niek Linnenbank (13):
60
hw/arm: add Allwinner H3 System-on-Chip
61
hw/arm: add Xunlong Orange Pi PC machine
62
hw/arm/allwinner-h3: add Clock Control Unit
63
hw/arm/allwinner-h3: add USB host controller
64
hw/arm/allwinner-h3: add System Control module
65
hw/arm/allwinner: add CPU Configuration module
66
hw/arm/allwinner: add Security Identifier device
67
hw/arm/allwinner: add SD/MMC host controller
68
hw/arm/allwinner-h3: add EMAC ethernet device
69
hw/arm/allwinner-h3: add Boot ROM support
70
hw/arm/allwinner-h3: add SDRAM controller device
71
hw/arm/allwinner: add RTC device support
72
docs: add Orange Pi PC document
73
74
Peter Maydell (4):
75
hw/intc/armv7m_nvic: Rebuild hflags on reset
76
target/arm: Update hflags in trans_CPS_v7m()
77
target/arm: Recalculate hflags correctly after writes to CONTROL
78
target/arm: Fix some comment typos
79
80
Philippe Mathieu-Daudé (5):
81
tests/boot_linux_console: Add a quick test for the OrangePi PC board
82
tests/boot_linux_console: Add initrd test for the Orange Pi PC board
83
tests/boot_linux_console: Add a SD card test for the OrangePi PC board
84
tests/boot_linux_console: Add a SLOW test booting Ubuntu on OrangePi PC
85
tests/boot_linux_console: Test booting NetBSD via U-Boot on OrangePi PC
86
87
Richard Henderson (2):
88
target/arm: Check addresses for disabled regimes
89
target/arm: Disable clean_data_tbi for system mode
90
91
Makefile.objs | 1 +
92
hw/arm/Makefile.objs | 1 +
93
hw/misc/Makefile.objs | 5 +
94
hw/net/Makefile.objs | 1 +
95
hw/rtc/Makefile.objs | 1 +
96
hw/sd/Makefile.objs | 1 +
97
hw/usb/hcd-ehci.h | 1 +
98
include/hw/arm/allwinner-a10.h | 4 +
99
include/hw/arm/allwinner-h3.h | 161 ++++++
100
include/hw/arm/fsl-imx25.h | 18 +
101
include/hw/arm/virt.h | 12 +-
102
include/hw/misc/allwinner-cpucfg.h | 52 ++
103
include/hw/misc/allwinner-h3-ccu.h | 66 +++
104
include/hw/misc/allwinner-h3-dramc.h | 106 ++++
105
include/hw/misc/allwinner-h3-sysctrl.h | 67 +++
106
include/hw/misc/allwinner-sid.h | 60 +++
107
include/hw/net/allwinner-sun8i-emac.h | 99 ++++
108
include/hw/rtc/allwinner-rtc.h | 134 +++++
109
include/hw/sd/allwinner-sdhost.h | 135 +++++
110
target/arm/helper.h | 1 +
111
target/arm/kvm_arm.h | 3 +
112
hw/arm/allwinner-a10.c | 19 +
113
hw/arm/allwinner-h3.c | 465 ++++++++++++++++++
114
hw/arm/cubieboard.c | 18 +
115
hw/arm/fsl-imx25.c | 56 +++
116
hw/arm/imx25_pdk.c | 16 +
117
hw/arm/orangepi.c | 130 +++++
118
hw/arm/virt.c | 145 ++++--
119
hw/intc/armv7m_nvic.c | 6 +
120
hw/misc/allwinner-cpucfg.c | 282 +++++++++++
121
hw/misc/allwinner-h3-ccu.c | 242 +++++++++
122
hw/misc/allwinner-h3-dramc.c | 358 ++++++++++++++
123
hw/misc/allwinner-h3-sysctrl.c | 140 ++++++
124
hw/misc/allwinner-sid.c | 168 +++++++
125
hw/net/allwinner-sun8i-emac.c | 871 +++++++++++++++++++++++++++++++++
126
hw/rtc/allwinner-rtc.c | 411 ++++++++++++++++
127
hw/sd/allwinner-sdhost.c | 854 ++++++++++++++++++++++++++++++++
128
hw/ssi/aspeed_smc.c | 56 ++-
129
hw/usb/hcd-ehci-sysbus.c | 17 +
130
target/arm/helper.c | 49 +-
131
target/arm/kvm.c | 14 +-
132
target/arm/kvm32.c | 15 +-
133
target/arm/kvm64.c | 15 +-
134
target/arm/translate-a64.c | 11 +
135
target/arm/translate.c | 14 +-
136
MAINTAINERS | 9 +
137
default-configs/arm-softmmu.mak | 1 +
138
docs/system/arm/orangepi.rst | 253 ++++++++++
139
docs/system/target-arm.rst | 2 +
140
hw/arm/Kconfig | 12 +
141
hw/misc/trace-events | 19 +
142
hw/net/Kconfig | 3 +
143
hw/net/trace-events | 10 +
144
hw/rtc/trace-events | 4 +
145
hw/sd/trace-events | 7 +
146
hw/ssi/trace-events | 10 +
147
tests/acceptance/boot_linux_console.py | 230 +++++++++
148
57 files changed, 5787 insertions(+), 74 deletions(-)
149
create mode 100644 include/hw/arm/allwinner-h3.h
150
create mode 100644 include/hw/misc/allwinner-cpucfg.h
151
create mode 100644 include/hw/misc/allwinner-h3-ccu.h
152
create mode 100644 include/hw/misc/allwinner-h3-dramc.h
153
create mode 100644 include/hw/misc/allwinner-h3-sysctrl.h
154
create mode 100644 include/hw/misc/allwinner-sid.h
155
create mode 100644 include/hw/net/allwinner-sun8i-emac.h
156
create mode 100644 include/hw/rtc/allwinner-rtc.h
157
create mode 100644 include/hw/sd/allwinner-sdhost.h
158
create mode 100644 hw/arm/allwinner-h3.c
159
create mode 100644 hw/arm/orangepi.c
160
create mode 100644 hw/misc/allwinner-cpucfg.c
161
create mode 100644 hw/misc/allwinner-h3-ccu.c
162
create mode 100644 hw/misc/allwinner-h3-dramc.c
163
create mode 100644 hw/misc/allwinner-h3-sysctrl.c
164
create mode 100644 hw/misc/allwinner-sid.c
165
create mode 100644 hw/net/allwinner-sun8i-emac.c
166
create mode 100644 hw/rtc/allwinner-rtc.c
167
create mode 100644 hw/sd/allwinner-sdhost.c
168
create mode 100644 docs/system/arm/orangepi.rst
169
create mode 100644 hw/ssi/trace-events
170
diff view generated by jsdifflib
1
With banked exceptions, just the exception number in
1
Some of an M-profile CPU's cached hflags state depends on state that's
2
s->vectpending is no longer sufficient to uniquely identify
2
in our NVIC object. We already do an hflags rebuild when the NVIC
3
the pending exception. Add a vectpending_is_s_banked bool
3
registers are written, but we also need to do this on NVIC reset,
4
which is true if the exception is using the sec_vectors[]
4
because there's no guarantee that this will happen before the
5
array.
5
CPU reset.
6
7
This fixes an assertion due to mismatched hflags which happens if
8
the CPU is reset from inside a HardFault handler.
6
9
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Message-id: 1505240046-11454-4-git-send-email-peter.maydell@linaro.org
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Message-id: 20200303174950.3298-2-peter.maydell@linaro.org
9
---
13
---
10
include/hw/intc/armv7m_nvic.h | 11 +++++++++--
14
hw/intc/armv7m_nvic.c | 6 ++++++
11
hw/intc/armv7m_nvic.c | 1 +
15
1 file changed, 6 insertions(+)
12
2 files changed, 10 insertions(+), 2 deletions(-)
13
16
14
diff --git a/include/hw/intc/armv7m_nvic.h b/include/hw/intc/armv7m_nvic.h
15
index XXXXXXX..XXXXXXX 100644
16
--- a/include/hw/intc/armv7m_nvic.h
17
+++ b/include/hw/intc/armv7m_nvic.h
18
@@ -XXX,XX +XXX,XX @@ typedef struct NVICState {
19
VecInfo sec_vectors[NVIC_INTERNAL_VECTORS];
20
uint32_t prigroup;
21
22
- /* vectpending and exception_prio are both cached state that can
23
- * be recalculated from the vectors[] array and the prigroup field.
24
+ /* The following fields are all cached state that can be recalculated
25
+ * from the vectors[] and sec_vectors[] arrays and the prigroup field:
26
+ * - vectpending
27
+ * - vectpending_is_secure
28
+ * - exception_prio
29
*/
30
unsigned int vectpending; /* highest prio pending enabled exception */
31
+ /* true if vectpending is a banked secure exception, ie it is in
32
+ * sec_vectors[] rather than vectors[]
33
+ */
34
+ bool vectpending_is_s_banked;
35
int exception_prio; /* group prio of the highest prio active exception */
36
37
MemoryRegion sysregmem;
38
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
17
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
39
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
40
--- a/hw/intc/armv7m_nvic.c
19
--- a/hw/intc/armv7m_nvic.c
41
+++ b/hw/intc/armv7m_nvic.c
20
+++ b/hw/intc/armv7m_nvic.c
42
@@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_reset(DeviceState *dev)
21
@@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_reset(DeviceState *dev)
43
22
s->itns[i] = true;
44
s->exception_prio = NVIC_NOEXC_PRIO;
23
}
45
s->vectpending = 0;
24
}
46
+ s->vectpending_is_s_banked = false;
25
+
26
+ /*
27
+ * We updated state that affects the CPU's MMUidx and thus its hflags;
28
+ * and we can't guarantee that we run before the CPU reset function.
29
+ */
30
+ arm_rebuild_hflags(&s->cpu->env);
47
}
31
}
48
32
49
static void nvic_systick_trigger(void *opaque, int n, int level)
33
static void nvic_systick_trigger(void *opaque, int n, int level)
50
--
34
--
51
2.7.4
35
2.20.1
52
36
53
37
diff view generated by jsdifflib
1
Update the code in nvic_rettobase() so that it checks the
1
For M-profile CPUs, the FAULTMASK value affects the CPU's MMU index
2
sec_vectors[] array as well as the vectors[] array if needed.
2
(it changes the NegPri bit). We update the hflags after calls
3
to the v7m_msr helper in trans_MSR_v7m() but forgot to do so
4
in trans_CPS_v7m().
3
5
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
Message-id: 1505240046-11454-7-git-send-email-peter.maydell@linaro.org
8
Message-id: 20200303174950.3298-3-peter.maydell@linaro.org
7
---
9
---
8
hw/intc/armv7m_nvic.c | 5 ++++-
10
target/arm/translate.c | 5 ++++-
9
1 file changed, 4 insertions(+), 1 deletion(-)
11
1 file changed, 4 insertions(+), 1 deletion(-)
10
12
11
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
13
diff --git a/target/arm/translate.c b/target/arm/translate.c
12
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
13
--- a/hw/intc/armv7m_nvic.c
15
--- a/target/arm/translate.c
14
+++ b/hw/intc/armv7m_nvic.c
16
+++ b/target/arm/translate.c
15
@@ -XXX,XX +XXX,XX @@ static int nvic_pending_prio(NVICState *s)
17
@@ -XXX,XX +XXX,XX @@ static bool trans_CPS(DisasContext *s, arg_CPS *a)
16
static bool nvic_rettobase(NVICState *s)
18
19
static bool trans_CPS_v7m(DisasContext *s, arg_CPS_v7m *a)
17
{
20
{
18
int irq, nhand = 0;
21
- TCGv_i32 tmp, addr;
19
+ bool check_sec = arm_feature(&s->cpu->env, ARM_FEATURE_M_SECURITY);
22
+ TCGv_i32 tmp, addr, el;
20
23
21
for (irq = ARMV7M_EXCP_RESET; irq < s->num_irq; irq++) {
24
if (!arm_dc_feature(s, ARM_FEATURE_M)) {
22
- if (s->vectors[irq].active) {
25
return false;
23
+ if (s->vectors[irq].active ||
26
@@ -XXX,XX +XXX,XX @@ static bool trans_CPS_v7m(DisasContext *s, arg_CPS_v7m *a)
24
+ (check_sec && irq < NVIC_INTERNAL_VECTORS &&
27
gen_helper_v7m_msr(cpu_env, addr, tmp);
25
+ s->sec_vectors[irq].active)) {
28
tcg_temp_free_i32(addr);
26
nhand++;
29
}
27
if (nhand == 2) {
30
+ el = tcg_const_i32(s->current_el);
28
return 0;
31
+ gen_helper_rebuild_hflags_m32(cpu_env, el);
32
+ tcg_temp_free_i32(el);
33
tcg_temp_free_i32(tmp);
34
gen_lookup_tb(s);
35
return true;
29
--
36
--
30
2.7.4
37
2.20.1
31
38
32
39
diff view generated by jsdifflib
1
Don't use the old_mmio struct in memory region ops.
1
A write to the CONTROL register can change our current EL (by
2
writing to the nPRIV bit). That means that we can't assume
3
that s->current_el is still valid in trans_MSR_v7m() when
4
we try to rebuild the hflags.
5
6
Add a new helper rebuild_hflags_m32_newel() which, like the
7
existing rebuild_hflags_a32_newel(), recalculates the current
8
EL from scratch, and use it in trans_MSR_v7m().
9
10
This fixes an assertion about an hflags mismatch when the
11
guest changes privilege by writing to CONTROL.
2
12
3
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
14
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
Message-id: 1505580378-9044-5-git-send-email-peter.maydell@linaro.org
15
Message-id: 20200303174950.3298-4-peter.maydell@linaro.org
6
---
16
---
7
hw/timer/omap_gptimer.c | 49 +++++++++++++++++++++++++++++++++++++------------
17
target/arm/helper.h | 1 +
8
1 file changed, 37 insertions(+), 12 deletions(-)
18
target/arm/helper.c | 12 ++++++++++++
19
target/arm/translate.c | 7 +++----
20
3 files changed, 16 insertions(+), 4 deletions(-)
9
21
10
diff --git a/hw/timer/omap_gptimer.c b/hw/timer/omap_gptimer.c
22
diff --git a/target/arm/helper.h b/target/arm/helper.h
11
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
12
--- a/hw/timer/omap_gptimer.c
24
--- a/target/arm/helper.h
13
+++ b/hw/timer/omap_gptimer.c
25
+++ b/target/arm/helper.h
14
@@ -XXX,XX +XXX,XX @@ static void omap_gp_timer_writeh(void *opaque, hwaddr addr,
26
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_4(msr_banked, void, env, i32, i32, i32)
15
s->writeh = (uint16_t) value;
27
DEF_HELPER_2(get_user_reg, i32, env, i32)
28
DEF_HELPER_3(set_user_reg, void, env, i32, i32)
29
30
+DEF_HELPER_FLAGS_1(rebuild_hflags_m32_newel, TCG_CALL_NO_RWG, void, env)
31
DEF_HELPER_FLAGS_2(rebuild_hflags_m32, TCG_CALL_NO_RWG, void, env, int)
32
DEF_HELPER_FLAGS_1(rebuild_hflags_a32_newel, TCG_CALL_NO_RWG, void, env)
33
DEF_HELPER_FLAGS_2(rebuild_hflags_a32, TCG_CALL_NO_RWG, void, env, int)
34
diff --git a/target/arm/helper.c b/target/arm/helper.c
35
index XXXXXXX..XXXXXXX 100644
36
--- a/target/arm/helper.c
37
+++ b/target/arm/helper.c
38
@@ -XXX,XX +XXX,XX @@ void arm_rebuild_hflags(CPUARMState *env)
39
env->hflags = rebuild_hflags_internal(env);
16
}
40
}
17
41
18
+static uint64_t omap_gp_timer_readfn(void *opaque, hwaddr addr,
42
+/*
19
+ unsigned size)
43
+ * If we have triggered a EL state change we can't rely on the
44
+ * translator having passed it to us, we need to recompute.
45
+ */
46
+void HELPER(rebuild_hflags_m32_newel)(CPUARMState *env)
20
+{
47
+{
21
+ switch (size) {
48
+ int el = arm_current_el(env);
22
+ case 1:
49
+ int fp_el = fp_exception_el(env, el);
23
+ return omap_badwidth_read32(opaque, addr);
50
+ ARMMMUIdx mmu_idx = arm_mmu_idx_el(env, el);
24
+ case 2:
51
+ env->hflags = rebuild_hflags_m32(env, fp_el, mmu_idx);
25
+ return omap_gp_timer_readh(opaque, addr);
26
+ case 4:
27
+ return omap_gp_timer_readw(opaque, addr);
28
+ default:
29
+ g_assert_not_reached();
30
+ }
31
+}
52
+}
32
+
53
+
33
+static void omap_gp_timer_writefn(void *opaque, hwaddr addr,
54
void HELPER(rebuild_hflags_m32)(CPUARMState *env, int el)
34
+ uint64_t value, unsigned size)
55
{
35
+{
56
int fp_el = fp_exception_el(env, el);
36
+ switch (size) {
57
diff --git a/target/arm/translate.c b/target/arm/translate.c
37
+ case 1:
58
index XXXXXXX..XXXXXXX 100644
38
+ omap_badwidth_write32(opaque, addr, value);
59
--- a/target/arm/translate.c
39
+ break;
60
+++ b/target/arm/translate.c
40
+ case 2:
61
@@ -XXX,XX +XXX,XX @@ static bool trans_MRS_v7m(DisasContext *s, arg_MRS_v7m *a)
41
+ omap_gp_timer_writeh(opaque, addr, value);
62
42
+ break;
63
static bool trans_MSR_v7m(DisasContext *s, arg_MSR_v7m *a)
43
+ case 4:
64
{
44
+ omap_gp_timer_write(opaque, addr, value);
65
- TCGv_i32 addr, reg, el;
45
+ break;
66
+ TCGv_i32 addr, reg;
46
+ default:
67
47
+ g_assert_not_reached();
68
if (!arm_dc_feature(s, ARM_FEATURE_M)) {
48
+ }
69
return false;
49
+}
70
@@ -XXX,XX +XXX,XX @@ static bool trans_MSR_v7m(DisasContext *s, arg_MSR_v7m *a)
50
+
71
gen_helper_v7m_msr(cpu_env, addr, reg);
51
static const MemoryRegionOps omap_gp_timer_ops = {
72
tcg_temp_free_i32(addr);
52
- .old_mmio = {
73
tcg_temp_free_i32(reg);
53
- .read = {
74
- el = tcg_const_i32(s->current_el);
54
- omap_badwidth_read32,
75
- gen_helper_rebuild_hflags_m32(cpu_env, el);
55
- omap_gp_timer_readh,
76
- tcg_temp_free_i32(el);
56
- omap_gp_timer_readw,
77
+ /* If we wrote to CONTROL, the EL might have changed */
57
- },
78
+ gen_helper_rebuild_hflags_m32_newel(cpu_env);
58
- .write = {
79
gen_lookup_tb(s);
59
- omap_badwidth_write32,
80
return true;
60
- omap_gp_timer_writeh,
81
}
61
- omap_gp_timer_write,
62
- },
63
- },
64
+ .read = omap_gp_timer_readfn,
65
+ .write = omap_gp_timer_writefn,
66
+ .valid.min_access_size = 1,
67
+ .valid.max_access_size = 4,
68
.endianness = DEVICE_NATIVE_ENDIAN,
69
};
70
71
--
82
--
72
2.7.4
83
2.20.1
73
84
74
85
diff view generated by jsdifflib
1
Update armv7m_nvic_acknowledge_irq() and armv7m_nvic_complete_irq()
1
Fix a couple of comment typos.
2
to handle banked exceptions:
3
* acknowledge needs to use the correct vector, which may be
4
in sec_vectors[]
5
* acknowledge needs to return to its caller whether the
6
exception should be taken to secure or non-secure state
7
* complete needs its caller to tell it whether the exception
8
being completed is a secure one or not
9
2
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
3
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
4
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Message-id: 1505240046-11454-20-git-send-email-peter.maydell@linaro.org
5
Message-id: 20200303174950.3298-5-peter.maydell@linaro.org
13
---
6
---
14
target/arm/cpu.h | 15 +++++++++++++--
7
target/arm/helper.c | 2 +-
15
hw/intc/armv7m_nvic.c | 26 ++++++++++++++++++++------
8
target/arm/translate.c | 2 +-
16
target/arm/helper.c | 8 +++++---
9
2 files changed, 2 insertions(+), 2 deletions(-)
17
hw/intc/trace-events | 4 ++--
18
4 files changed, 40 insertions(+), 13 deletions(-)
19
10
20
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
21
index XXXXXXX..XXXXXXX 100644
22
--- a/target/arm/cpu.h
23
+++ b/target/arm/cpu.h
24
@@ -XXX,XX +XXX,XX @@ static inline bool armv7m_nvic_can_take_pending_exception(void *opaque)
25
* of architecturally banked exceptions.
26
*/
27
void armv7m_nvic_set_pending(void *opaque, int irq, bool secure);
28
-void armv7m_nvic_acknowledge_irq(void *opaque);
29
+/**
30
+ * armv7m_nvic_acknowledge_irq: make highest priority pending exception active
31
+ * @opaque: the NVIC
32
+ *
33
+ * Move the current highest priority pending exception from the pending
34
+ * state to the active state, and update v7m.exception to indicate that
35
+ * it is the exception currently being handled.
36
+ *
37
+ * Returns: true if exception should be taken to Secure state, false for NS
38
+ */
39
+bool armv7m_nvic_acknowledge_irq(void *opaque);
40
/**
41
* armv7m_nvic_complete_irq: complete specified interrupt or exception
42
* @opaque: the NVIC
43
* @irq: the exception number to complete
44
+ * @secure: true if this exception was secure
45
*
46
* Returns: -1 if the irq was not active
47
* 1 if completing this irq brought us back to base (no active irqs)
48
* 0 if there is still an irq active after this one was completed
49
* (Ignoring -1, this is the same as the RETTOBASE value before completion.)
50
*/
51
-int armv7m_nvic_complete_irq(void *opaque, int irq);
52
+int armv7m_nvic_complete_irq(void *opaque, int irq, bool secure);
53
/**
54
* armv7m_nvic_raw_execution_priority: return the raw execution priority
55
* @opaque: the NVIC
56
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
57
index XXXXXXX..XXXXXXX 100644
58
--- a/hw/intc/armv7m_nvic.c
59
+++ b/hw/intc/armv7m_nvic.c
60
@@ -XXX,XX +XXX,XX @@ void armv7m_nvic_set_pending(void *opaque, int irq, bool secure)
61
}
62
63
/* Make pending IRQ active. */
64
-void armv7m_nvic_acknowledge_irq(void *opaque)
65
+bool armv7m_nvic_acknowledge_irq(void *opaque)
66
{
67
NVICState *s = (NVICState *)opaque;
68
CPUARMState *env = &s->cpu->env;
69
const int pending = s->vectpending;
70
const int running = nvic_exec_prio(s);
71
VecInfo *vec;
72
+ bool targets_secure;
73
74
assert(pending > ARMV7M_EXCP_RESET && pending < s->num_irq);
75
76
- vec = &s->vectors[pending];
77
+ if (s->vectpending_is_s_banked) {
78
+ vec = &s->sec_vectors[pending];
79
+ targets_secure = true;
80
+ } else {
81
+ vec = &s->vectors[pending];
82
+ targets_secure = !exc_is_banked(s->vectpending) &&
83
+ exc_targets_secure(s, s->vectpending);
84
+ }
85
86
assert(vec->enabled);
87
assert(vec->pending);
88
89
assert(s->vectpending_prio < running);
90
91
- trace_nvic_acknowledge_irq(pending, s->vectpending_prio);
92
+ trace_nvic_acknowledge_irq(pending, s->vectpending_prio, targets_secure);
93
94
vec->active = 1;
95
vec->pending = 0;
96
@@ -XXX,XX +XXX,XX @@ void armv7m_nvic_acknowledge_irq(void *opaque)
97
env->v7m.exception = s->vectpending;
98
99
nvic_irq_update(s);
100
+
101
+ return targets_secure;
102
}
103
104
-int armv7m_nvic_complete_irq(void *opaque, int irq)
105
+int armv7m_nvic_complete_irq(void *opaque, int irq, bool secure)
106
{
107
NVICState *s = (NVICState *)opaque;
108
VecInfo *vec;
109
@@ -XXX,XX +XXX,XX @@ int armv7m_nvic_complete_irq(void *opaque, int irq)
110
111
assert(irq > ARMV7M_EXCP_RESET && irq < s->num_irq);
112
113
- vec = &s->vectors[irq];
114
+ if (secure && exc_is_banked(irq)) {
115
+ vec = &s->sec_vectors[irq];
116
+ } else {
117
+ vec = &s->vectors[irq];
118
+ }
119
120
- trace_nvic_complete_irq(irq);
121
+ trace_nvic_complete_irq(irq, secure);
122
123
if (!vec->active) {
124
/* Tell the caller this was an illegal exception return */
125
diff --git a/target/arm/helper.c b/target/arm/helper.c
11
diff --git a/target/arm/helper.c b/target/arm/helper.c
126
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
127
--- a/target/arm/helper.c
13
--- a/target/arm/helper.c
128
+++ b/target/arm/helper.c
14
+++ b/target/arm/helper.c
129
@@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu)
15
@@ -XXX,XX +XXX,XX @@ void HELPER(rebuild_hflags_m32)(CPUARMState *env, int el)
130
bool return_to_sp_process = false;
16
131
bool return_to_handler = false;
17
/*
132
bool rettobase = false;
18
* If we have triggered a EL state change we can't rely on the
133
+ bool exc_secure = false;
19
- * translator having passed it too us, we need to recompute.
134
20
+ * translator having passed it to us, we need to recompute.
135
/* We can only get here from an EXCP_EXCEPTION_EXIT, and
21
*/
136
* gen_bx_excret() enforces the architectural rule
22
void HELPER(rebuild_hflags_a32_newel)(CPUARMState *env)
137
@@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu)
23
{
138
* which security state's faultmask to clear. (v8M ARM ARM R_KBNF.)
24
diff --git a/target/arm/translate.c b/target/arm/translate.c
139
*/
140
if (arm_feature(env, ARM_FEATURE_M_SECURITY)) {
141
- int es = excret & R_V7M_EXCRET_ES_MASK;
142
+ exc_secure = excret & R_V7M_EXCRET_ES_MASK;
143
if (armv7m_nvic_raw_execution_priority(env->nvic) >= 0) {
144
- env->v7m.faultmask[es] = 0;
145
+ env->v7m.faultmask[exc_secure] = 0;
146
}
147
} else {
148
env->v7m.faultmask[M_REG_NS] = 0;
149
}
150
}
151
152
- switch (armv7m_nvic_complete_irq(env->nvic, env->v7m.exception)) {
153
+ switch (armv7m_nvic_complete_irq(env->nvic, env->v7m.exception,
154
+ exc_secure)) {
155
case -1:
156
/* attempt to exit an exception that isn't active */
157
ufault = true;
158
diff --git a/hw/intc/trace-events b/hw/intc/trace-events
159
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
160
--- a/hw/intc/trace-events
26
--- a/target/arm/translate.c
161
+++ b/hw/intc/trace-events
27
+++ b/target/arm/translate.c
162
@@ -XXX,XX +XXX,XX @@ nvic_escalate_disabled(int irq) "NVIC escalating irq %d to HardFault: disabled"
28
@@ -XXX,XX +XXX,XX @@ static int disas_coproc_insn(DisasContext *s, uint32_t insn)
163
nvic_set_pending(int irq, bool secure, int en, int prio) "NVIC set pending irq %d secure-bank %d (enabled: %d priority %d)"
29
164
nvic_clear_pending(int irq, bool secure, int en, int prio) "NVIC clear pending irq %d secure-bank %d (enabled: %d priority %d)"
30
if (!isread && !(ri->type & ARM_CP_SUPPRESS_TB_END)) {
165
nvic_set_pending_level(int irq) "NVIC set pending: irq %d higher prio than vectpending: setting irq line to 1"
31
/*
166
-nvic_acknowledge_irq(int irq, int prio) "NVIC acknowledge IRQ: %d now active (prio %d)"
32
- * A write to any coprocessor regiser that ends a TB
167
-nvic_complete_irq(int irq) "NVIC complete IRQ %d"
33
+ * A write to any coprocessor register that ends a TB
168
+nvic_acknowledge_irq(int irq, int prio, bool targets_secure) "NVIC acknowledge IRQ: %d now active (prio %d targets_secure %d)"
34
* must rebuild the hflags for the next TB.
169
+nvic_complete_irq(int irq, bool secure) "NVIC complete IRQ %d (secure %d)"
35
*/
170
nvic_set_irq_level(int irq, int level) "NVIC external irq %d level set to %d"
36
TCGv_i32 tcg_el = tcg_const_i32(s->current_el);
171
nvic_sysreg_read(uint64_t addr, uint32_t value, unsigned size) "NVIC sysreg read addr 0x%" PRIx64 " data 0x%" PRIx32 " size %u"
172
nvic_sysreg_write(uint64_t addr, uint32_t value, unsigned size) "NVIC sysreg write addr 0x%" PRIx64 " data 0x%" PRIx32 " size %u"
173
--
37
--
174
2.7.4
38
2.20.1
175
39
176
40
diff view generated by jsdifflib
1
Update the static_ops functions to use new-style mmio
1
From: Cédric Le Goater <clg@kaod.org>
2
rather than the legacy old_mmio functions.
3
2
3
Signed-off-by: Cédric Le Goater <clg@kaod.org>
4
Reviewed-by: Andrew Jeffery <andrew@aj.id.au>
5
Reviewed-by: Joel Stanley <joel@jms.id.au>
6
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
7
Message-id: 20200206112645.21275-2-clg@kaod.org
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
Message-id: 1505580378-9044-2-git-send-email-peter.maydell@linaro.org
7
---
9
---
8
hw/arm/palm.c | 30 ++++++++++--------------------
10
Makefile.objs | 1 +
9
1 file changed, 10 insertions(+), 20 deletions(-)
11
hw/ssi/aspeed_smc.c | 17 +++++++++++++++++
12
hw/ssi/trace-events | 9 +++++++++
13
3 files changed, 27 insertions(+)
14
create mode 100644 hw/ssi/trace-events
10
15
11
diff --git a/hw/arm/palm.c b/hw/arm/palm.c
16
diff --git a/Makefile.objs b/Makefile.objs
12
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
13
--- a/hw/arm/palm.c
18
--- a/Makefile.objs
14
+++ b/hw/arm/palm.c
19
+++ b/Makefile.objs
20
@@ -XXX,XX +XXX,XX @@ trace-events-subdirs += hw/scsi
21
trace-events-subdirs += hw/sd
22
trace-events-subdirs += hw/sparc
23
trace-events-subdirs += hw/sparc64
24
+trace-events-subdirs += hw/ssi
25
trace-events-subdirs += hw/timer
26
trace-events-subdirs += hw/tpm
27
trace-events-subdirs += hw/usb
28
diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c
29
index XXXXXXX..XXXXXXX 100644
30
--- a/hw/ssi/aspeed_smc.c
31
+++ b/hw/ssi/aspeed_smc.c
15
@@ -XXX,XX +XXX,XX @@
32
@@ -XXX,XX +XXX,XX @@
33
#include "qapi/error.h"
16
#include "exec/address-spaces.h"
34
#include "exec/address-spaces.h"
17
#include "cpu.h"
35
#include "qemu/units.h"
18
36
+#include "trace.h"
19
-static uint32_t static_readb(void *opaque, hwaddr offset)
37
20
+static uint64_t static_read(void *opaque, hwaddr offset, unsigned size)
38
#include "hw/irq.h"
21
{
39
#include "hw/qdev-properties.h"
22
- uint32_t *val = (uint32_t *) opaque;
40
@@ -XXX,XX +XXX,XX @@ static void aspeed_smc_flash_set_segment(AspeedSMCState *s, int cs,
23
- return *val >> ((offset & 3) << 3);
41
24
-}
42
s->ctrl->reg_to_segment(s, new, &seg);
25
+ uint32_t *val = (uint32_t *)opaque;
43
26
+ uint32_t sizemask = 7 >> size;
44
+ trace_aspeed_smc_flash_set_segment(cs, new, seg.addr, seg.addr + seg.size);
27
45
+
28
-static uint32_t static_readh(void *opaque, hwaddr offset)
46
/* The start address of CS0 is read-only */
29
-{
47
if (cs == 0 && seg.addr != s->ctrl->flash_window_base) {
30
- uint32_t *val = (uint32_t *) opaque;
48
qemu_log_mask(LOG_GUEST_ERROR,
31
- return *val >> ((offset & 1) << 3);
49
@@ -XXX,XX +XXX,XX @@ static uint64_t aspeed_smc_flash_read(void *opaque, hwaddr addr, unsigned size)
32
-}
50
__func__, aspeed_smc_flash_mode(fl));
33
-
51
}
34
-static uint32_t static_readw(void *opaque, hwaddr offset)
52
35
-{
53
+ trace_aspeed_smc_flash_read(fl->id, addr, size, ret,
36
- uint32_t *val = (uint32_t *) opaque;
54
+ aspeed_smc_flash_mode(fl));
37
- return *val >> ((offset & 0) << 3);
55
return ret;
38
+ return *val >> ((offset & sizemask) << 3);
39
}
56
}
40
57
41
-static void static_write(void *opaque, hwaddr offset,
58
@@ -XXX,XX +XXX,XX @@ static bool aspeed_smc_do_snoop(AspeedSMCFlash *fl, uint64_t data,
42
- uint32_t value)
59
AspeedSMCState *s = fl->controller;
43
+static void static_write(void *opaque, hwaddr offset, uint64_t value,
60
uint8_t addr_width = aspeed_smc_flash_is_4byte(fl) ? 4 : 3;
44
+ unsigned size)
61
45
{
62
+ trace_aspeed_smc_do_snoop(fl->id, s->snoop_index, s->snoop_dummies,
46
#ifdef SPY
63
+ (uint8_t) data & 0xff);
47
printf("%s: value %08lx written at " PA_FMT "\n",
64
+
48
@@ -XXX,XX +XXX,XX @@ static void static_write(void *opaque, hwaddr offset,
65
if (s->snoop_index == SNOOP_OFF) {
49
}
66
return false; /* Do nothing */
50
67
51
static const MemoryRegionOps static_ops = {
68
@@ -XXX,XX +XXX,XX @@ static void aspeed_smc_flash_write(void *opaque, hwaddr addr, uint64_t data,
52
- .old_mmio = {
69
AspeedSMCState *s = fl->controller;
53
- .read = { static_readb, static_readh, static_readw, },
70
int i;
54
- .write = { static_write, static_write, static_write, },
71
55
- },
72
+ trace_aspeed_smc_flash_write(fl->id, addr, size, data,
56
+ .read = static_read,
73
+ aspeed_smc_flash_mode(fl));
57
+ .write = static_write,
74
+
58
+ .valid.min_access_size = 1,
75
if (!aspeed_smc_is_writable(fl)) {
59
+ .valid.max_access_size = 4,
76
qemu_log_mask(LOG_GUEST_ERROR, "%s: flash is not writable at 0x%"
60
.endianness = DEVICE_NATIVE_ENDIAN,
77
HWADDR_PRIx "\n", __func__, addr);
61
};
78
@@ -XXX,XX +XXX,XX @@ static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size)
62
79
(s->ctrl->has_dma && addr == R_DMA_CHECKSUM) ||
80
(addr >= R_SEG_ADDR0 && addr < R_SEG_ADDR0 + s->ctrl->max_slaves) ||
81
(addr >= s->r_ctrl0 && addr < s->r_ctrl0 + s->ctrl->max_slaves)) {
82
+
83
+ trace_aspeed_smc_read(addr, size, s->regs[addr]);
84
+
85
return s->regs[addr];
86
} else {
87
qemu_log_mask(LOG_UNIMP, "%s: not implemented: 0x%" HWADDR_PRIx "\n",
88
@@ -XXX,XX +XXX,XX @@ static void aspeed_smc_dma_checksum(AspeedSMCState *s)
89
__func__, s->regs[R_DMA_FLASH_ADDR]);
90
return;
91
}
92
+ trace_aspeed_smc_dma_checksum(s->regs[R_DMA_FLASH_ADDR], data);
93
94
/*
95
* When the DMA is on-going, the DMA registers are updated
96
@@ -XXX,XX +XXX,XX @@ static void aspeed_smc_write(void *opaque, hwaddr addr, uint64_t data,
97
98
addr >>= 2;
99
100
+ trace_aspeed_smc_write(addr, size, data);
101
+
102
if (addr == s->r_conf ||
103
(addr >= s->r_timings &&
104
addr < s->r_timings + s->ctrl->nregs_timings) ||
105
diff --git a/hw/ssi/trace-events b/hw/ssi/trace-events
106
new file mode 100644
107
index XXXXXXX..XXXXXXX
108
--- /dev/null
109
+++ b/hw/ssi/trace-events
110
@@ -XXX,XX +XXX,XX @@
111
+# aspeed_smc.c
112
+
113
+aspeed_smc_flash_set_segment(int cs, uint64_t reg, uint64_t start, uint64_t end) "CS%d segreg=0x%"PRIx64" [ 0x%"PRIx64" - 0x%"PRIx64" ]"
114
+aspeed_smc_flash_read(int cs, uint64_t addr, uint32_t size, uint64_t data, int mode) "CS%d @0x%" PRIx64 " size %u: 0x%" PRIx64" mode:%d"
115
+aspeed_smc_do_snoop(int cs, int index, int dummies, int data) "CS%d index:0x%x dummies:%d data:0x%x"
116
+aspeed_smc_flash_write(int cs, uint64_t addr, uint32_t size, uint64_t data, int mode) "CS%d @0x%" PRIx64 " size %u: 0x%" PRIx64" mode:%d"
117
+aspeed_smc_read(uint64_t addr, uint32_t size, uint64_t data) "@0x%" PRIx64 " size %u: 0x%" PRIx64
118
+aspeed_smc_dma_checksum(uint32_t addr, uint32_t data) "0x%08x: 0x%08x"
119
+aspeed_smc_write(uint64_t addr, uint32_t size, uint64_t data) "@0x%" PRIx64 " size %u: 0x%" PRIx64
63
--
120
--
64
2.7.4
121
2.20.1
65
122
66
123
diff view generated by jsdifflib
1
Drop the use of old_mmio in the omap2_gpio memory ops.
1
From: Cédric Le Goater <clg@kaod.org>
2
2
3
The Aspeed SMC Controller can operate in different modes : Read, Fast
4
Read, Write and User modes. When the User mode is configured, it
5
selects automatically the SPI slave device until the CE_STOP_ACTIVE
6
bit is set to 1. When any other modes are configured the device is
7
unselected. The HW logic handles the chip select automatically when
8
the flash is accessed through its AHB window.
9
10
When configuring the CEx Control Register, the User mode logic to
11
select and unselect the slave is incorrect and data corruption can be
12
seen on machines using two chips, witherspoon and romulus.
13
14
Rework the handler setting the CEx Control Register to fix this issue.
15
16
Fixes: 7c1c69bca43c ("ast2400: add SMC controllers (FMC and SPI)")
17
Signed-off-by: Cédric Le Goater <clg@kaod.org>
18
Reviewed-by: Andrew Jeffery <andrew@aj.id.au>
19
Message-id: 20200206112645.21275-3-clg@kaod.org
3
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
20
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
Message-id: 1505580378-9044-3-git-send-email-peter.maydell@linaro.org
6
---
21
---
7
hw/gpio/omap_gpio.c | 26 ++++++++++++--------------
22
hw/ssi/aspeed_smc.c | 39 +++++++++++++++++++++++----------------
8
1 file changed, 12 insertions(+), 14 deletions(-)
23
hw/ssi/trace-events | 1 +
24
2 files changed, 24 insertions(+), 16 deletions(-)
9
25
10
diff --git a/hw/gpio/omap_gpio.c b/hw/gpio/omap_gpio.c
26
diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c
11
index XXXXXXX..XXXXXXX 100644
27
index XXXXXXX..XXXXXXX 100644
12
--- a/hw/gpio/omap_gpio.c
28
--- a/hw/ssi/aspeed_smc.c
13
+++ b/hw/gpio/omap_gpio.c
29
+++ b/hw/ssi/aspeed_smc.c
14
@@ -XXX,XX +XXX,XX @@ static void omap2_gpio_module_write(void *opaque, hwaddr addr,
30
@@ -XXX,XX +XXX,XX @@ static inline int aspeed_smc_flash_is_4byte(const AspeedSMCFlash *fl)
15
}
31
}
16
}
32
}
17
33
18
-static uint32_t omap2_gpio_module_readp(void *opaque, hwaddr addr)
34
-static inline bool aspeed_smc_is_ce_stop_active(const AspeedSMCFlash *fl)
19
+static uint64_t omap2_gpio_module_readp(void *opaque, hwaddr addr,
35
+static void aspeed_smc_flash_do_select(AspeedSMCFlash *fl, bool unselect)
20
+ unsigned size)
21
{
36
{
22
return omap2_gpio_module_read(opaque, addr & ~3) >> ((addr & 3) << 3);
37
- const AspeedSMCState *s = fl->controller;
38
+ AspeedSMCState *s = fl->controller;
39
40
- return s->regs[s->r_ctrl0 + fl->id] & CTRL_CE_STOP_ACTIVE;
41
+ trace_aspeed_smc_flash_select(fl->id, unselect ? "un" : "");
42
+
43
+ qemu_set_irq(s->cs_lines[fl->id], unselect);
23
}
44
}
24
45
25
static void omap2_gpio_module_writep(void *opaque, hwaddr addr,
46
static void aspeed_smc_flash_select(AspeedSMCFlash *fl)
26
- uint32_t value)
27
+ uint64_t value, unsigned size)
28
{
47
{
29
uint32_t cur = 0;
48
- AspeedSMCState *s = fl->controller;
30
uint32_t mask = 0xffff;
49
-
31
50
- s->regs[s->r_ctrl0 + fl->id] &= ~CTRL_CE_STOP_ACTIVE;
32
+ if (size == 4) {
51
- qemu_set_irq(s->cs_lines[fl->id], aspeed_smc_is_ce_stop_active(fl));
33
+ omap2_gpio_module_write(opaque, addr, value);
52
+ aspeed_smc_flash_do_select(fl, false);
34
+ return;
53
}
54
55
static void aspeed_smc_flash_unselect(AspeedSMCFlash *fl)
56
{
57
- AspeedSMCState *s = fl->controller;
58
-
59
- s->regs[s->r_ctrl0 + fl->id] |= CTRL_CE_STOP_ACTIVE;
60
- qemu_set_irq(s->cs_lines[fl->id], aspeed_smc_is_ce_stop_active(fl));
61
+ aspeed_smc_flash_do_select(fl, true);
62
}
63
64
static uint32_t aspeed_smc_check_segment_addr(const AspeedSMCFlash *fl,
65
@@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps aspeed_smc_flash_ops = {
66
},
67
};
68
69
-static void aspeed_smc_flash_update_cs(AspeedSMCFlash *fl)
70
+static void aspeed_smc_flash_update_ctrl(AspeedSMCFlash *fl, uint32_t value)
71
{
72
AspeedSMCState *s = fl->controller;
73
+ bool unselect;
74
75
- s->snoop_index = aspeed_smc_is_ce_stop_active(fl) ? SNOOP_OFF : SNOOP_START;
76
+ /* User mode selects the CS, other modes unselect */
77
+ unselect = (value & CTRL_CMD_MODE_MASK) != CTRL_USERMODE;
78
79
- qemu_set_irq(s->cs_lines[fl->id], aspeed_smc_is_ce_stop_active(fl));
80
+ /* A change of CTRL_CE_STOP_ACTIVE from 0 to 1, unselects the CS */
81
+ if (!(s->regs[s->r_ctrl0 + fl->id] & CTRL_CE_STOP_ACTIVE) &&
82
+ value & CTRL_CE_STOP_ACTIVE) {
83
+ unselect = true;
35
+ }
84
+ }
36
+
85
+
37
switch (addr & ~3) {
86
+ s->regs[s->r_ctrl0 + fl->id] = value;
38
case 0x00:    /* GPIO_REVISION */
87
+
39
case 0x14:    /* GPIO_SYSSTATUS */
88
+ s->snoop_index = unselect ? SNOOP_OFF : SNOOP_START;
40
@@ -XXX,XX +XXX,XX @@ static void omap2_gpio_module_writep(void *opaque, hwaddr addr,
89
+
90
+ aspeed_smc_flash_do_select(fl, unselect);
41
}
91
}
42
92
43
static const MemoryRegionOps omap2_gpio_module_ops = {
93
static void aspeed_smc_reset(DeviceState *d)
44
- .old_mmio = {
94
@@ -XXX,XX +XXX,XX @@ static void aspeed_smc_write(void *opaque, hwaddr addr, uint64_t data,
45
- .read = {
95
s->regs[addr] = value;
46
- omap2_gpio_module_readp,
96
} else if (addr >= s->r_ctrl0 && addr < s->r_ctrl0 + s->num_cs) {
47
- omap2_gpio_module_readp,
97
int cs = addr - s->r_ctrl0;
48
- omap2_gpio_module_read,
98
- s->regs[addr] = value;
49
- },
99
- aspeed_smc_flash_update_cs(&s->flashes[cs]);
50
- .write = {
100
+ aspeed_smc_flash_update_ctrl(&s->flashes[cs], value);
51
- omap2_gpio_module_writep,
101
} else if (addr >= R_SEG_ADDR0 &&
52
- omap2_gpio_module_writep,
102
addr < R_SEG_ADDR0 + s->ctrl->max_slaves) {
53
- omap2_gpio_module_write,
103
int cs = addr - R_SEG_ADDR0;
54
- },
104
diff --git a/hw/ssi/trace-events b/hw/ssi/trace-events
55
- },
105
index XXXXXXX..XXXXXXX 100644
56
+ .read = omap2_gpio_module_readp,
106
--- a/hw/ssi/trace-events
57
+ .write = omap2_gpio_module_writep,
107
+++ b/hw/ssi/trace-events
58
+ .valid.min_access_size = 1,
108
@@ -XXX,XX +XXX,XX @@ aspeed_smc_flash_write(int cs, uint64_t addr, uint32_t size, uint64_t data, int
59
+ .valid.max_access_size = 4,
109
aspeed_smc_read(uint64_t addr, uint32_t size, uint64_t data) "@0x%" PRIx64 " size %u: 0x%" PRIx64
60
.endianness = DEVICE_NATIVE_ENDIAN,
110
aspeed_smc_dma_checksum(uint32_t addr, uint32_t data) "0x%08x: 0x%08x"
61
};
111
aspeed_smc_write(uint64_t addr, uint32_t size, uint64_t data) "@0x%" PRIx64 " size %u: 0x%" PRIx64
62
112
+aspeed_smc_flash_select(int cs, const char *prefix) "CS%d %sselect"
63
--
113
--
64
2.7.4
114
2.20.1
65
115
66
116
diff view generated by jsdifflib
1
Make the armv7m_nvic_set_pending() and armv7m_nvic_clear_pending()
1
From: Richard Henderson <richard.henderson@linaro.org>
2
functions take a bool indicating whether to pend the secure
3
or non-secure version of a banked interrupt, and update the
4
callsites accordingly.
5
2
6
In most callsites we can simply pass the correct security
3
We fail to validate the upper bits of a virtual address on a
7
state in; in a couple of cases we use TODO comments to indicate
4
translation disabled regime, as per AArch64.TranslateAddressS1Off.
8
that we will return the code in a subsequent commit.
9
5
6
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20200308012946.16303-2-richard.henderson@linaro.org
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Message-id: 1505240046-11454-10-git-send-email-peter.maydell@linaro.org
13
---
10
---
14
target/arm/cpu.h | 14 ++++++++++-
11
target/arm/helper.c | 35 ++++++++++++++++++++++++++++++++++-
15
hw/intc/armv7m_nvic.c | 64 ++++++++++++++++++++++++++++++++++++++-------------
12
1 file changed, 34 insertions(+), 1 deletion(-)
16
target/arm/helper.c | 24 +++++++++++--------
17
hw/intc/trace-events | 4 ++--
18
4 files changed, 77 insertions(+), 29 deletions(-)
19
13
20
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
21
index XXXXXXX..XXXXXXX 100644
22
--- a/target/arm/cpu.h
23
+++ b/target/arm/cpu.h
24
@@ -XXX,XX +XXX,XX @@ static inline bool armv7m_nvic_can_take_pending_exception(void *opaque)
25
return true;
26
}
27
#endif
28
-void armv7m_nvic_set_pending(void *opaque, int irq);
29
+/**
30
+ * armv7m_nvic_set_pending: mark the specified exception as pending
31
+ * @opaque: the NVIC
32
+ * @irq: the exception number to mark pending
33
+ * @secure: false for non-banked exceptions or for the nonsecure
34
+ * version of a banked exception, true for the secure version of a banked
35
+ * exception.
36
+ *
37
+ * Marks the specified exception as pending. Note that we will assert()
38
+ * if @secure is true and @irq does not specify one of the fixed set
39
+ * of architecturally banked exceptions.
40
+ */
41
+void armv7m_nvic_set_pending(void *opaque, int irq, bool secure);
42
void armv7m_nvic_acknowledge_irq(void *opaque);
43
/**
44
* armv7m_nvic_complete_irq: complete specified interrupt or exception
45
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
46
index XXXXXXX..XXXXXXX 100644
47
--- a/hw/intc/armv7m_nvic.c
48
+++ b/hw/intc/armv7m_nvic.c
49
@@ -XXX,XX +XXX,XX @@ static void nvic_irq_update(NVICState *s)
50
qemu_set_irq(s->excpout, lvl);
51
}
52
53
-static void armv7m_nvic_clear_pending(void *opaque, int irq)
54
+/**
55
+ * armv7m_nvic_clear_pending: mark the specified exception as not pending
56
+ * @opaque: the NVIC
57
+ * @irq: the exception number to mark as not pending
58
+ * @secure: false for non-banked exceptions or for the nonsecure
59
+ * version of a banked exception, true for the secure version of a banked
60
+ * exception.
61
+ *
62
+ * Marks the specified exception as not pending. Note that we will assert()
63
+ * if @secure is true and @irq does not specify one of the fixed set
64
+ * of architecturally banked exceptions.
65
+ */
66
+static void armv7m_nvic_clear_pending(void *opaque, int irq, bool secure)
67
{
68
NVICState *s = (NVICState *)opaque;
69
VecInfo *vec;
70
71
assert(irq > ARMV7M_EXCP_RESET && irq < s->num_irq);
72
73
- vec = &s->vectors[irq];
74
- trace_nvic_clear_pending(irq, vec->enabled, vec->prio);
75
+ if (secure) {
76
+ assert(exc_is_banked(irq));
77
+ vec = &s->sec_vectors[irq];
78
+ } else {
79
+ vec = &s->vectors[irq];
80
+ }
81
+ trace_nvic_clear_pending(irq, secure, vec->enabled, vec->prio);
82
if (vec->pending) {
83
vec->pending = 0;
84
nvic_irq_update(s);
85
}
86
}
87
88
-void armv7m_nvic_set_pending(void *opaque, int irq)
89
+void armv7m_nvic_set_pending(void *opaque, int irq, bool secure)
90
{
91
NVICState *s = (NVICState *)opaque;
92
+ bool banked = exc_is_banked(irq);
93
VecInfo *vec;
94
95
assert(irq > ARMV7M_EXCP_RESET && irq < s->num_irq);
96
+ assert(!secure || banked);
97
98
- vec = &s->vectors[irq];
99
- trace_nvic_set_pending(irq, vec->enabled, vec->prio);
100
+ vec = (banked && secure) ? &s->sec_vectors[irq] : &s->vectors[irq];
101
102
+ trace_nvic_set_pending(irq, secure, vec->enabled, vec->prio);
103
104
if (irq >= ARMV7M_EXCP_HARD && irq < ARMV7M_EXCP_PENDSV) {
105
/* If a synchronous exception is pending then it may be
106
@@ -XXX,XX +XXX,XX @@ void armv7m_nvic_set_pending(void *opaque, int irq)
107
"(current priority %d)\n", irq, running);
108
}
109
110
- /* We can do the escalation, so we take HardFault instead */
111
+ /* We can do the escalation, so we take HardFault instead.
112
+ * If BFHFNMINS is set then we escalate to the banked HF for
113
+ * the target security state of the original exception; otherwise
114
+ * we take a Secure HardFault.
115
+ */
116
irq = ARMV7M_EXCP_HARD;
117
- vec = &s->vectors[irq];
118
+ if (arm_feature(&s->cpu->env, ARM_FEATURE_M_SECURITY) &&
119
+ (secure ||
120
+ !(s->cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK))) {
121
+ vec = &s->sec_vectors[irq];
122
+ } else {
123
+ vec = &s->vectors[irq];
124
+ }
125
+ /* HF may be banked but there is only one shared HFSR */
126
s->cpu->env.v7m.hfsr |= R_V7M_HFSR_FORCED_MASK;
127
}
128
}
129
@@ -XXX,XX +XXX,XX @@ static void set_irq_level(void *opaque, int n, int level)
130
if (level != vec->level) {
131
vec->level = level;
132
if (level) {
133
- armv7m_nvic_set_pending(s, n);
134
+ armv7m_nvic_set_pending(s, n, false);
135
}
136
}
137
}
138
@@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value,
139
}
140
case 0xd04: /* Interrupt Control State. */
141
if (value & (1 << 31)) {
142
- armv7m_nvic_set_pending(s, ARMV7M_EXCP_NMI);
143
+ armv7m_nvic_set_pending(s, ARMV7M_EXCP_NMI, false);
144
}
145
if (value & (1 << 28)) {
146
- armv7m_nvic_set_pending(s, ARMV7M_EXCP_PENDSV);
147
+ armv7m_nvic_set_pending(s, ARMV7M_EXCP_PENDSV, attrs.secure);
148
} else if (value & (1 << 27)) {
149
- armv7m_nvic_clear_pending(s, ARMV7M_EXCP_PENDSV);
150
+ armv7m_nvic_clear_pending(s, ARMV7M_EXCP_PENDSV, attrs.secure);
151
}
152
if (value & (1 << 26)) {
153
- armv7m_nvic_set_pending(s, ARMV7M_EXCP_SYSTICK);
154
+ armv7m_nvic_set_pending(s, ARMV7M_EXCP_SYSTICK, attrs.secure);
155
} else if (value & (1 << 25)) {
156
- armv7m_nvic_clear_pending(s, ARMV7M_EXCP_SYSTICK);
157
+ armv7m_nvic_clear_pending(s, ARMV7M_EXCP_SYSTICK, attrs.secure);
158
}
159
break;
160
case 0xd08: /* Vector Table Offset. */
161
@@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value,
162
{
163
int excnum = (value & 0x1ff) + NVIC_FIRST_IRQ;
164
if (excnum < s->num_irq) {
165
- armv7m_nvic_set_pending(s, excnum);
166
+ armv7m_nvic_set_pending(s, excnum, false);
167
}
168
break;
169
}
170
@@ -XXX,XX +XXX,XX @@ static void nvic_systick_trigger(void *opaque, int n, int level)
171
/* SysTick just asked us to pend its exception.
172
* (This is different from an external interrupt line's
173
* behaviour.)
174
+ * TODO: when we implement the banked systicks we must make
175
+ * this pend the correct banked exception.
176
*/
177
- armv7m_nvic_set_pending(s, ARMV7M_EXCP_SYSTICK);
178
+ armv7m_nvic_set_pending(s, ARMV7M_EXCP_SYSTICK, false);
179
}
180
}
181
182
diff --git a/target/arm/helper.c b/target/arm/helper.c
14
diff --git a/target/arm/helper.c b/target/arm/helper.c
183
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
184
--- a/target/arm/helper.c
16
--- a/target/arm/helper.c
185
+++ b/target/arm/helper.c
17
+++ b/target/arm/helper.c
186
@@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu)
18
@@ -XXX,XX +XXX,XX @@ bool get_phys_addr(CPUARMState *env, target_ulong address,
187
* stack, directly take a usage fault on the current stack.
19
/* Definitely a real MMU, not an MPU */
188
*/
20
189
env->v7m.cfsr[env->v7m.secure] |= R_V7M_CFSR_INVPC_MASK;
21
if (regime_translation_disabled(env, mmu_idx)) {
190
- armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE);
22
- /* MMU disabled. */
191
+ armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE, env->v7m.secure);
23
+ /*
192
v7m_exception_taken(cpu, excret);
24
+ * MMU disabled. S1 addresses within aa64 translation regimes are
193
qemu_log_mask(CPU_LOG_INT, "...taking UsageFault on existing "
25
+ * still checked for bounds -- see AArch64.TranslateAddressS1Off.
194
"stackframe: failed exception return integrity check\n");
195
@@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu)
196
* exception return excret specified then this is a UsageFault.
197
*/
198
if (return_to_handler != arm_v7m_is_handler_mode(env)) {
199
- /* Take an INVPC UsageFault by pushing the stack again. */
200
- armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE);
201
+ /* Take an INVPC UsageFault by pushing the stack again.
202
+ * TODO: the v8M version of this code should target the
203
+ * background state for this exception.
204
+ */
26
+ */
205
+ armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE, false);
27
+ if (mmu_idx != ARMMMUIdx_Stage2) {
206
env->v7m.cfsr[env->v7m.secure] |= R_V7M_CFSR_INVPC_MASK;
28
+ int r_el = regime_el(env, mmu_idx);
207
v7m_push_stack(cpu);
29
+ if (arm_el_is_aa64(env, r_el)) {
208
v7m_exception_taken(cpu, excret);
30
+ int pamax = arm_pamax(env_archcpu(env));
209
@@ -XXX,XX +XXX,XX @@ void arm_v7m_cpu_do_interrupt(CPUState *cs)
31
+ uint64_t tcr = env->cp15.tcr_el[r_el].raw_tcr;
210
handle it. */
32
+ int addrtop, tbi;
211
switch (cs->exception_index) {
33
+
212
case EXCP_UDEF:
34
+ tbi = aa64_va_parameter_tbi(tcr, mmu_idx);
213
- armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE);
35
+ if (access_type == MMU_INST_FETCH) {
214
+ armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE, env->v7m.secure);
36
+ tbi &= ~aa64_va_parameter_tbid(tcr, mmu_idx);
215
env->v7m.cfsr[env->v7m.secure] |= R_V7M_CFSR_UNDEFINSTR_MASK;
37
+ }
216
break;
38
+ tbi = (tbi >> extract64(address, 55, 1)) & 1;
217
case EXCP_NOCP:
39
+ addrtop = (tbi ? 55 : 63);
218
- armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE);
40
+
219
+ armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE, env->v7m.secure);
41
+ if (extract64(address, pamax, addrtop - pamax + 1) != 0) {
220
env->v7m.cfsr[env->v7m.secure] |= R_V7M_CFSR_NOCP_MASK;
42
+ fi->type = ARMFault_AddressSize;
221
break;
43
+ fi->level = 0;
222
case EXCP_INVSTATE:
44
+ fi->stage2 = false;
223
- armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE);
45
+ return 1;
224
+ armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE, env->v7m.secure);
46
+ }
225
env->v7m.cfsr[env->v7m.secure] |= R_V7M_CFSR_INVSTATE_MASK;
47
+
226
break;
48
+ /*
227
case EXCP_SWI:
49
+ * When TBI is disabled, we've just validated that all of the
228
/* The PC already points to the next instruction. */
50
+ * bits above PAMax are zero, so logically we only need to
229
- armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_SVC);
51
+ * clear the top byte for TBI. But it's clearer to follow
230
+ armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_SVC, env->v7m.secure);
52
+ * the pseudocode set of addrdesc.paddress.
231
break;
53
+ */
232
case EXCP_PREFETCH_ABORT:
54
+ address = extract64(address, 0, 52);
233
case EXCP_DATA_ABORT:
55
+ }
234
@@ -XXX,XX +XXX,XX @@ void arm_v7m_cpu_do_interrupt(CPUState *cs)
56
+ }
235
env->v7m.bfar);
57
*phys_ptr = address;
236
break;
58
*prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
237
}
59
*page_size = TARGET_PAGE_SIZE;
238
- armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_BUS);
239
+ armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_BUS, false);
240
break;
241
default:
242
/* All other FSR values are either MPU faults or "can't happen
243
@@ -XXX,XX +XXX,XX @@ void arm_v7m_cpu_do_interrupt(CPUState *cs)
244
env->v7m.mmfar[env->v7m.secure]);
245
break;
246
}
247
- armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_MEM);
248
+ armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_MEM,
249
+ env->v7m.secure);
250
break;
251
}
252
break;
253
@@ -XXX,XX +XXX,XX @@ void arm_v7m_cpu_do_interrupt(CPUState *cs)
254
return;
255
}
256
}
257
- armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_DEBUG);
258
+ armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_DEBUG, false);
259
break;
260
case EXCP_IRQ:
261
break;
262
diff --git a/hw/intc/trace-events b/hw/intc/trace-events
263
index XXXXXXX..XXXXXXX 100644
264
--- a/hw/intc/trace-events
265
+++ b/hw/intc/trace-events
266
@@ -XXX,XX +XXX,XX @@ nvic_set_prio(int irq, uint8_t prio) "NVIC set irq %d priority %d"
267
nvic_irq_update(int vectpending, int pendprio, int exception_prio, int level) "NVIC vectpending %d pending prio %d exception_prio %d: setting irq line to %d"
268
nvic_escalate_prio(int irq, int irqprio, int runprio) "NVIC escalating irq %d to HardFault: insufficient priority %d >= %d"
269
nvic_escalate_disabled(int irq) "NVIC escalating irq %d to HardFault: disabled"
270
-nvic_set_pending(int irq, int en, int prio) "NVIC set pending irq %d (enabled: %d priority %d)"
271
-nvic_clear_pending(int irq, int en, int prio) "NVIC clear pending irq %d (enabled: %d priority %d)"
272
+nvic_set_pending(int irq, bool secure, int en, int prio) "NVIC set pending irq %d secure-bank %d (enabled: %d priority %d)"
273
+nvic_clear_pending(int irq, bool secure, int en, int prio) "NVIC clear pending irq %d secure-bank %d (enabled: %d priority %d)"
274
nvic_set_pending_level(int irq) "NVIC set pending: irq %d higher prio than vectpending: setting irq line to 1"
275
nvic_acknowledge_irq(int irq, int prio) "NVIC acknowledge IRQ: %d now active (prio %d)"
276
nvic_complete_irq(int irq) "NVIC complete IRQ %d"
277
--
60
--
278
2.7.4
61
2.20.1
279
62
280
63
diff view generated by jsdifflib
1
In the A64 decoder, we have a lot of references to section numbers
1
From: Richard Henderson <richard.henderson@linaro.org>
2
from version A.a of the v8A ARM ARM (DDI0487). This version of the
3
document is now long obsolete (we are currently on revision B.a),
4
and various intervening versions renumbered all the sections.
5
2
6
The most recent B.a version of the document doesn't assign
3
We must include the tag in the FAR_ELx register when raising
7
section numbers at all to the individual instruction classes
4
an addressing exception. Which means that we should not clear
8
in the way that the various A.x versions did. The simplest thing
5
out the tag during translation.
9
to do is just to delete all the out of date C.x.x references.
10
6
7
We cannot at present comply with this for user mode, so we
8
retain the clean_data_tbi function for the moment, though it
9
no longer does what it says on the tin for system mode. This
10
function is to be replaced with MTE, so don't worry about the
11
slight misnaming.
12
13
Buglink: https://bugs.launchpad.net/qemu/+bug/1867072
14
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
15
Message-id: 20200308012946.16303-3-richard.henderson@linaro.org
16
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
13
Message-id: 20170915150849.23557-1-peter.maydell@linaro.org
14
---
18
---
15
target/arm/translate-a64.c | 227 +++++++++++++++++++++++----------------------
19
target/arm/translate-a64.c | 11 +++++++++++
16
1 file changed, 114 insertions(+), 113 deletions(-)
20
1 file changed, 11 insertions(+)
17
21
18
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
22
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
19
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
20
--- a/target/arm/translate-a64.c
24
--- a/target/arm/translate-a64.c
21
+++ b/target/arm/translate-a64.c
25
+++ b/target/arm/translate-a64.c
22
@@ -XXX,XX +XXX,XX @@ static inline AArch64DecodeFn *lookup_disas_fn(const AArch64DecodeTable *table,
26
@@ -XXX,XX +XXX,XX @@ static void gen_a64_set_pc(DisasContext *s, TCGv_i64 src)
27
static TCGv_i64 clean_data_tbi(DisasContext *s, TCGv_i64 addr)
28
{
29
TCGv_i64 clean = new_tmp_a64(s);
30
+ /*
31
+ * In order to get the correct value in the FAR_ELx register,
32
+ * we must present the memory subsystem with the "dirty" address
33
+ * including the TBI. In system mode we can make this work via
34
+ * the TLB, dropping the TBI during translation. But for user-only
35
+ * mode we don't have that option, and must remove the top byte now.
36
+ */
37
+#ifdef CONFIG_USER_ONLY
38
gen_top_byte_ignore(s, clean, addr, s->tbid);
39
+#else
40
+ tcg_gen_mov_i64(clean, addr);
41
+#endif
42
return clean;
23
}
43
}
24
44
25
/*
26
- * the instruction disassembly implemented here matches
27
- * the instruction encoding classifications in chapter 3 (C3)
28
- * of the ARM Architecture Reference Manual (DDI0487A_a)
29
+ * The instruction disassembly implemented here matches
30
+ * the instruction encoding classifications in chapter C4
31
+ * of the ARM Architecture Reference Manual (DDI0487B_a);
32
+ * classification names and decode diagrams here should generally
33
+ * match up with those in the manual.
34
*/
35
36
-/* C3.2.7 Unconditional branch (immediate)
37
+/* Unconditional branch (immediate)
38
* 31 30 26 25 0
39
* +----+-----------+-------------------------------------+
40
* | op | 0 0 1 0 1 | imm26 |
41
@@ -XXX,XX +XXX,XX @@ static void disas_uncond_b_imm(DisasContext *s, uint32_t insn)
42
uint64_t addr = s->pc + sextract32(insn, 0, 26) * 4 - 4;
43
44
if (insn & (1U << 31)) {
45
- /* C5.6.26 BL Branch with link */
46
+ /* BL Branch with link */
47
tcg_gen_movi_i64(cpu_reg(s, 30), s->pc);
48
}
49
50
- /* C5.6.20 B Branch / C5.6.26 BL Branch with link */
51
+ /* B Branch / BL Branch with link */
52
gen_goto_tb(s, 0, addr);
53
}
54
55
-/* C3.2.1 Compare & branch (immediate)
56
+/* Compare and branch (immediate)
57
* 31 30 25 24 23 5 4 0
58
* +----+-------------+----+---------------------+--------+
59
* | sf | 0 1 1 0 1 0 | op | imm19 | Rt |
60
@@ -XXX,XX +XXX,XX @@ static void disas_comp_b_imm(DisasContext *s, uint32_t insn)
61
gen_goto_tb(s, 1, addr);
62
}
63
64
-/* C3.2.5 Test & branch (immediate)
65
+/* Test and branch (immediate)
66
* 31 30 25 24 23 19 18 5 4 0
67
* +----+-------------+----+-------+-------------+------+
68
* | b5 | 0 1 1 0 1 1 | op | b40 | imm14 | Rt |
69
@@ -XXX,XX +XXX,XX @@ static void disas_test_b_imm(DisasContext *s, uint32_t insn)
70
gen_goto_tb(s, 1, addr);
71
}
72
73
-/* C3.2.2 / C5.6.19 Conditional branch (immediate)
74
+/* Conditional branch (immediate)
75
* 31 25 24 23 5 4 3 0
76
* +---------------+----+---------------------+----+------+
77
* | 0 1 0 1 0 1 0 | o1 | imm19 | o0 | cond |
78
@@ -XXX,XX +XXX,XX @@ static void disas_cond_b_imm(DisasContext *s, uint32_t insn)
79
}
80
}
81
82
-/* C5.6.68 HINT */
83
+/* HINT instruction group, including various allocated HINTs */
84
static void handle_hint(DisasContext *s, uint32_t insn,
85
unsigned int op1, unsigned int op2, unsigned int crm)
86
{
87
@@ -XXX,XX +XXX,XX @@ static void handle_sync(DisasContext *s, uint32_t insn,
88
}
89
}
90
91
-/* C5.6.130 MSR (immediate) - move immediate to processor state field */
92
+/* MSR (immediate) - move immediate to processor state field */
93
static void handle_msr_i(DisasContext *s, uint32_t insn,
94
unsigned int op1, unsigned int op2, unsigned int crm)
95
{
96
@@ -XXX,XX +XXX,XX @@ static void gen_set_nzcv(TCGv_i64 tcg_rt)
97
tcg_temp_free_i32(nzcv);
98
}
99
100
-/* C5.6.129 MRS - move from system register
101
- * C5.6.131 MSR (register) - move to system register
102
- * C5.6.204 SYS
103
- * C5.6.205 SYSL
104
+/* MRS - move from system register
105
+ * MSR (register) - move to system register
106
+ * SYS
107
+ * SYSL
108
* These are all essentially the same insn in 'read' and 'write'
109
* versions, with varying op0 fields.
110
*/
111
@@ -XXX,XX +XXX,XX @@ static void handle_sys(DisasContext *s, uint32_t insn, bool isread,
112
}
113
}
114
115
-/* C3.2.4 System
116
+/* System
117
* 31 22 21 20 19 18 16 15 12 11 8 7 5 4 0
118
* +---------------------+---+-----+-----+-------+-------+-----+------+
119
* | 1 1 0 1 0 1 0 1 0 0 | L | op0 | op1 | CRn | CRm | op2 | Rt |
120
@@ -XXX,XX +XXX,XX @@ static void disas_system(DisasContext *s, uint32_t insn)
121
return;
122
}
123
switch (crn) {
124
- case 2: /* C5.6.68 HINT */
125
+ case 2: /* HINT (including allocated hints like NOP, YIELD, etc) */
126
handle_hint(s, insn, op1, op2, crm);
127
break;
128
case 3: /* CLREX, DSB, DMB, ISB */
129
handle_sync(s, insn, op1, op2, crm);
130
break;
131
- case 4: /* C5.6.130 MSR (immediate) */
132
+ case 4: /* MSR (immediate) */
133
handle_msr_i(s, insn, op1, op2, crm);
134
break;
135
default:
136
@@ -XXX,XX +XXX,XX @@ static void disas_system(DisasContext *s, uint32_t insn)
137
handle_sys(s, insn, l, op0, op1, op2, crn, crm, rt);
138
}
139
140
-/* C3.2.3 Exception generation
141
+/* Exception generation
142
*
143
* 31 24 23 21 20 5 4 2 1 0
144
* +-----------------+-----+------------------------+-----+----+
145
@@ -XXX,XX +XXX,XX @@ static void disas_exc(DisasContext *s, uint32_t insn)
146
}
147
}
148
149
-/* C3.2.7 Unconditional branch (register)
150
+/* Unconditional branch (register)
151
* 31 25 24 21 20 16 15 10 9 5 4 0
152
* +---------------+-------+-------+-------+------+-------+
153
* | 1 1 0 1 0 1 1 | opc | op2 | op3 | Rn | op4 |
154
@@ -XXX,XX +XXX,XX @@ static void disas_uncond_b_reg(DisasContext *s, uint32_t insn)
155
s->base.is_jmp = DISAS_JUMP;
156
}
157
158
-/* C3.2 Branches, exception generating and system instructions */
159
+/* Branches, exception generating and system instructions */
160
static void disas_b_exc_sys(DisasContext *s, uint32_t insn)
161
{
162
switch (extract32(insn, 25, 7)) {
163
@@ -XXX,XX +XXX,XX @@ static bool disas_ldst_compute_iss_sf(int size, bool is_signed, int opc)
164
return regsize == 64;
165
}
166
167
-/* C3.3.6 Load/store exclusive
168
+/* Load/store exclusive
169
*
170
* 31 30 29 24 23 22 21 20 16 15 14 10 9 5 4 0
171
* +-----+-------------+----+---+----+------+----+-------+------+------+
172
@@ -XXX,XX +XXX,XX @@ static void disas_ldst_excl(DisasContext *s, uint32_t insn)
173
}
174
175
/*
176
- * C3.3.5 Load register (literal)
177
+ * Load register (literal)
178
*
179
* 31 30 29 27 26 25 24 23 5 4 0
180
* +-----+-------+---+-----+-------------------+-------+
181
@@ -XXX,XX +XXX,XX @@ static void disas_ld_lit(DisasContext *s, uint32_t insn)
182
}
183
184
/*
185
- * C5.6.80 LDNP (Load Pair - non-temporal hint)
186
- * C5.6.81 LDP (Load Pair - non vector)
187
- * C5.6.82 LDPSW (Load Pair Signed Word - non vector)
188
- * C5.6.176 STNP (Store Pair - non-temporal hint)
189
- * C5.6.177 STP (Store Pair - non vector)
190
- * C6.3.165 LDNP (Load Pair of SIMD&FP - non-temporal hint)
191
- * C6.3.165 LDP (Load Pair of SIMD&FP)
192
- * C6.3.284 STNP (Store Pair of SIMD&FP - non-temporal hint)
193
- * C6.3.284 STP (Store Pair of SIMD&FP)
194
+ * LDNP (Load Pair - non-temporal hint)
195
+ * LDP (Load Pair - non vector)
196
+ * LDPSW (Load Pair Signed Word - non vector)
197
+ * STNP (Store Pair - non-temporal hint)
198
+ * STP (Store Pair - non vector)
199
+ * LDNP (Load Pair of SIMD&FP - non-temporal hint)
200
+ * LDP (Load Pair of SIMD&FP)
201
+ * STNP (Store Pair of SIMD&FP - non-temporal hint)
202
+ * STP (Store Pair of SIMD&FP)
203
*
204
* 31 30 29 27 26 25 24 23 22 21 15 14 10 9 5 4 0
205
* +-----+-------+---+---+-------+---+-----------------------------+
206
@@ -XXX,XX +XXX,XX @@ static void disas_ldst_pair(DisasContext *s, uint32_t insn)
207
}
208
209
/*
210
- * C3.3.8 Load/store (immediate post-indexed)
211
- * C3.3.9 Load/store (immediate pre-indexed)
212
- * C3.3.12 Load/store (unscaled immediate)
213
+ * Load/store (immediate post-indexed)
214
+ * Load/store (immediate pre-indexed)
215
+ * Load/store (unscaled immediate)
216
*
217
* 31 30 29 27 26 25 24 23 22 21 20 12 11 10 9 5 4 0
218
* +----+-------+---+-----+-----+---+--------+-----+------+------+
219
@@ -XXX,XX +XXX,XX @@ static void disas_ldst_reg_imm9(DisasContext *s, uint32_t insn,
220
}
221
222
/*
223
- * C3.3.10 Load/store (register offset)
224
+ * Load/store (register offset)
225
*
226
* 31 30 29 27 26 25 24 23 22 21 20 16 15 13 12 11 10 9 5 4 0
227
* +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
228
@@ -XXX,XX +XXX,XX @@ static void disas_ldst_reg_roffset(DisasContext *s, uint32_t insn,
229
}
230
231
/*
232
- * C3.3.13 Load/store (unsigned immediate)
233
+ * Load/store (unsigned immediate)
234
*
235
* 31 30 29 27 26 25 24 23 22 21 10 9 5
236
* +----+-------+---+-----+-----+------------+-------+------+
237
@@ -XXX,XX +XXX,XX @@ static void disas_ldst_reg(DisasContext *s, uint32_t insn)
238
}
239
}
240
241
-/* C3.3.1 AdvSIMD load/store multiple structures
242
+/* AdvSIMD load/store multiple structures
243
*
244
* 31 30 29 23 22 21 16 15 12 11 10 9 5 4 0
245
* +---+---+---------------+---+-------------+--------+------+------+------+
246
* | 0 | Q | 0 0 1 1 0 0 0 | L | 0 0 0 0 0 0 | opcode | size | Rn | Rt |
247
* +---+---+---------------+---+-------------+--------+------+------+------+
248
*
249
- * C3.3.2 AdvSIMD load/store multiple structures (post-indexed)
250
+ * AdvSIMD load/store multiple structures (post-indexed)
251
*
252
* 31 30 29 23 22 21 20 16 15 12 11 10 9 5 4 0
253
* +---+---+---------------+---+---+---------+--------+------+------+------+
254
@@ -XXX,XX +XXX,XX @@ static void disas_ldst_multiple_struct(DisasContext *s, uint32_t insn)
255
tcg_temp_free_i64(tcg_addr);
256
}
257
258
-/* C3.3.3 AdvSIMD load/store single structure
259
+/* AdvSIMD load/store single structure
260
*
261
* 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
262
* +---+---+---------------+-----+-----------+-----+---+------+------+------+
263
* | 0 | Q | 0 0 1 1 0 1 0 | L R | 0 0 0 0 0 | opc | S | size | Rn | Rt |
264
* +---+---+---------------+-----+-----------+-----+---+------+------+------+
265
*
266
- * C3.3.4 AdvSIMD load/store single structure (post-indexed)
267
+ * AdvSIMD load/store single structure (post-indexed)
268
*
269
* 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
270
* +---+---+---------------+-----+-----------+-----+---+------+------+------+
271
@@ -XXX,XX +XXX,XX @@ static void disas_ldst_single_struct(DisasContext *s, uint32_t insn)
272
tcg_temp_free_i64(tcg_addr);
273
}
274
275
-/* C3.3 Loads and stores */
276
+/* Loads and stores */
277
static void disas_ldst(DisasContext *s, uint32_t insn)
278
{
279
switch (extract32(insn, 24, 6)) {
280
@@ -XXX,XX +XXX,XX @@ static void disas_ldst(DisasContext *s, uint32_t insn)
281
}
282
}
283
284
-/* C3.4.6 PC-rel. addressing
285
+/* PC-rel. addressing
286
* 31 30 29 28 24 23 5 4 0
287
* +----+-------+-----------+-------------------+------+
288
* | op | immlo | 1 0 0 0 0 | immhi | Rd |
289
@@ -XXX,XX +XXX,XX @@ static void disas_pc_rel_adr(DisasContext *s, uint32_t insn)
290
}
291
292
/*
293
- * C3.4.1 Add/subtract (immediate)
294
+ * Add/subtract (immediate)
295
*
296
* 31 30 29 28 24 23 22 21 10 9 5 4 0
297
* +--+--+--+-----------+-----+-------------+-----+-----+
298
@@ -XXX,XX +XXX,XX @@ static bool logic_imm_decode_wmask(uint64_t *result, unsigned int immn,
299
return true;
300
}
301
302
-/* C3.4.4 Logical (immediate)
303
+/* Logical (immediate)
304
* 31 30 29 28 23 22 21 16 15 10 9 5 4 0
305
* +----+-----+-------------+---+------+------+------+------+
306
* | sf | opc | 1 0 0 1 0 0 | N | immr | imms | Rn | Rd |
307
@@ -XXX,XX +XXX,XX @@ static void disas_logic_imm(DisasContext *s, uint32_t insn)
308
}
309
310
/*
311
- * C3.4.5 Move wide (immediate)
312
+ * Move wide (immediate)
313
*
314
* 31 30 29 28 23 22 21 20 5 4 0
315
* +--+-----+-------------+-----+----------------+------+
316
@@ -XXX,XX +XXX,XX @@ static void disas_movw_imm(DisasContext *s, uint32_t insn)
317
}
318
}
319
320
-/* C3.4.2 Bitfield
321
+/* Bitfield
322
* 31 30 29 28 23 22 21 16 15 10 9 5 4 0
323
* +----+-----+-------------+---+------+------+------+------+
324
* | sf | opc | 1 0 0 1 1 0 | N | immr | imms | Rn | Rd |
325
@@ -XXX,XX +XXX,XX @@ static void disas_bitfield(DisasContext *s, uint32_t insn)
326
}
327
}
328
329
-/* C3.4.3 Extract
330
+/* Extract
331
* 31 30 29 28 23 22 21 20 16 15 10 9 5 4 0
332
* +----+------+-------------+---+----+------+--------+------+------+
333
* | sf | op21 | 1 0 0 1 1 1 | N | o0 | Rm | imms | Rn | Rd |
334
@@ -XXX,XX +XXX,XX @@ static void disas_extract(DisasContext *s, uint32_t insn)
335
}
336
}
337
338
-/* C3.4 Data processing - immediate */
339
+/* Data processing - immediate */
340
static void disas_data_proc_imm(DisasContext *s, uint32_t insn)
341
{
342
switch (extract32(insn, 23, 6)) {
343
@@ -XXX,XX +XXX,XX @@ static void shift_reg_imm(TCGv_i64 dst, TCGv_i64 src, int sf,
344
}
345
}
346
347
-/* C3.5.10 Logical (shifted register)
348
+/* Logical (shifted register)
349
* 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
350
* +----+-----+-----------+-------+---+------+--------+------+------+
351
* | sf | opc | 0 1 0 1 0 | shift | N | Rm | imm6 | Rn | Rd |
352
@@ -XXX,XX +XXX,XX @@ static void disas_logic_reg(DisasContext *s, uint32_t insn)
353
}
354
355
/*
356
- * C3.5.1 Add/subtract (extended register)
357
+ * Add/subtract (extended register)
358
*
359
* 31|30|29|28 24|23 22|21|20 16|15 13|12 10|9 5|4 0|
360
* +--+--+--+-----------+-----+--+-------+------+------+----+----+
361
@@ -XXX,XX +XXX,XX @@ static void disas_add_sub_ext_reg(DisasContext *s, uint32_t insn)
362
}
363
364
/*
365
- * C3.5.2 Add/subtract (shifted register)
366
+ * Add/subtract (shifted register)
367
*
368
* 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
369
* +--+--+--+-----------+-----+--+-------+---------+------+------+
370
@@ -XXX,XX +XXX,XX @@ static void disas_add_sub_reg(DisasContext *s, uint32_t insn)
371
tcg_temp_free_i64(tcg_result);
372
}
373
374
-/* C3.5.9 Data-processing (3 source)
375
-
376
- 31 30 29 28 24 23 21 20 16 15 14 10 9 5 4 0
377
- +--+------+-----------+------+------+----+------+------+------+
378
- |sf| op54 | 1 1 0 1 1 | op31 | Rm | o0 | Ra | Rn | Rd |
379
- +--+------+-----------+------+------+----+------+------+------+
380
-
381
+/* Data-processing (3 source)
382
+ *
383
+ * 31 30 29 28 24 23 21 20 16 15 14 10 9 5 4 0
384
+ * +--+------+-----------+------+------+----+------+------+------+
385
+ * |sf| op54 | 1 1 0 1 1 | op31 | Rm | o0 | Ra | Rn | Rd |
386
+ * +--+------+-----------+------+------+----+------+------+------+
387
*/
388
static void disas_data_proc_3src(DisasContext *s, uint32_t insn)
389
{
390
@@ -XXX,XX +XXX,XX @@ static void disas_data_proc_3src(DisasContext *s, uint32_t insn)
391
tcg_temp_free_i64(tcg_tmp);
392
}
393
394
-/* C3.5.3 - Add/subtract (with carry)
395
+/* Add/subtract (with carry)
396
* 31 30 29 28 27 26 25 24 23 22 21 20 16 15 10 9 5 4 0
397
* +--+--+--+------------------------+------+---------+------+-----+
398
* |sf|op| S| 1 1 0 1 0 0 0 0 | rm | opcode2 | Rn | Rd |
399
@@ -XXX,XX +XXX,XX @@ static void disas_adc_sbc(DisasContext *s, uint32_t insn)
400
}
401
}
402
403
-/* C3.5.4 - C3.5.5 Conditional compare (immediate / register)
404
+/* Conditional compare (immediate / register)
405
* 31 30 29 28 27 26 25 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
406
* +--+--+--+------------------------+--------+------+----+--+------+--+-----+
407
* |sf|op| S| 1 1 0 1 0 0 1 0 |imm5/rm | cond |i/r |o2| Rn |o3|nzcv |
408
@@ -XXX,XX +XXX,XX @@ static void disas_cc(DisasContext *s, uint32_t insn)
409
tcg_temp_free_i32(tcg_t2);
410
}
411
412
-/* C3.5.6 Conditional select
413
+/* Conditional select
414
* 31 30 29 28 21 20 16 15 12 11 10 9 5 4 0
415
* +----+----+---+-----------------+------+------+-----+------+------+
416
* | sf | op | S | 1 1 0 1 0 1 0 0 | Rm | cond | op2 | Rn | Rd |
417
@@ -XXX,XX +XXX,XX @@ static void handle_rbit(DisasContext *s, unsigned int sf,
418
}
419
}
420
421
-/* C5.6.149 REV with sf==1, opcode==3 ("REV64") */
422
+/* REV with sf==1, opcode==3 ("REV64") */
423
static void handle_rev64(DisasContext *s, unsigned int sf,
424
unsigned int rn, unsigned int rd)
425
{
426
@@ -XXX,XX +XXX,XX @@ static void handle_rev64(DisasContext *s, unsigned int sf,
427
tcg_gen_bswap64_i64(cpu_reg(s, rd), cpu_reg(s, rn));
428
}
429
430
-/* C5.6.149 REV with sf==0, opcode==2
431
- * C5.6.151 REV32 (sf==1, opcode==2)
432
+/* REV with sf==0, opcode==2
433
+ * REV32 (sf==1, opcode==2)
434
*/
435
static void handle_rev32(DisasContext *s, unsigned int sf,
436
unsigned int rn, unsigned int rd)
437
@@ -XXX,XX +XXX,XX @@ static void handle_rev32(DisasContext *s, unsigned int sf,
438
}
439
}
440
441
-/* C5.6.150 REV16 (opcode==1) */
442
+/* REV16 (opcode==1) */
443
static void handle_rev16(DisasContext *s, unsigned int sf,
444
unsigned int rn, unsigned int rd)
445
{
446
@@ -XXX,XX +XXX,XX @@ static void handle_rev16(DisasContext *s, unsigned int sf,
447
tcg_temp_free_i64(tcg_tmp);
448
}
449
450
-/* C3.5.7 Data-processing (1 source)
451
+/* Data-processing (1 source)
452
* 31 30 29 28 21 20 16 15 10 9 5 4 0
453
* +----+---+---+-----------------+---------+--------+------+------+
454
* | sf | 1 | S | 1 1 0 1 0 1 1 0 | opcode2 | opcode | Rn | Rd |
455
@@ -XXX,XX +XXX,XX @@ static void handle_div(DisasContext *s, bool is_signed, unsigned int sf,
456
}
457
}
458
459
-/* C5.6.115 LSLV, C5.6.118 LSRV, C5.6.17 ASRV, C5.6.154 RORV */
460
+/* LSLV, LSRV, ASRV, RORV */
461
static void handle_shift_reg(DisasContext *s,
462
enum a64_shift_type shift_type, unsigned int sf,
463
unsigned int rm, unsigned int rn, unsigned int rd)
464
@@ -XXX,XX +XXX,XX @@ static void handle_crc32(DisasContext *s,
465
tcg_temp_free_i32(tcg_bytes);
466
}
467
468
-/* C3.5.8 Data-processing (2 source)
469
+/* Data-processing (2 source)
470
* 31 30 29 28 21 20 16 15 10 9 5 4 0
471
* +----+---+---+-----------------+------+--------+------+------+
472
* | sf | 0 | S | 1 1 0 1 0 1 1 0 | Rm | opcode | Rn | Rd |
473
@@ -XXX,XX +XXX,XX @@ static void disas_data_proc_2src(DisasContext *s, uint32_t insn)
474
}
475
}
476
477
-/* C3.5 Data processing - register */
478
+/* Data processing - register */
479
static void disas_data_proc_reg(DisasContext *s, uint32_t insn)
480
{
481
switch (extract32(insn, 24, 5)) {
482
@@ -XXX,XX +XXX,XX @@ static void handle_fp_compare(DisasContext *s, bool is_double,
483
tcg_temp_free_i64(tcg_flags);
484
}
485
486
-/* C3.6.22 Floating point compare
487
+/* Floating point compare
488
* 31 30 29 28 24 23 22 21 20 16 15 14 13 10 9 5 4 0
489
* +---+---+---+-----------+------+---+------+-----+---------+------+-------+
490
* | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | op | 1 0 0 0 | Rn | op2 |
491
@@ -XXX,XX +XXX,XX @@ static void disas_fp_compare(DisasContext *s, uint32_t insn)
492
handle_fp_compare(s, type, rn, rm, opc & 1, opc & 2);
493
}
494
495
-/* C3.6.23 Floating point conditional compare
496
+/* Floating point conditional compare
497
* 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
498
* +---+---+---+-----------+------+---+------+------+-----+------+----+------+
499
* | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 0 1 | Rn | op | nzcv |
500
@@ -XXX,XX +XXX,XX @@ static void disas_fp_ccomp(DisasContext *s, uint32_t insn)
501
}
502
}
503
504
-/* C3.6.24 Floating point conditional select
505
+/* Floating point conditional select
506
* 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
507
* +---+---+---+-----------+------+---+------+------+-----+------+------+
508
* | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 1 1 | Rn | Rd |
509
@@ -XXX,XX +XXX,XX @@ static void disas_fp_csel(DisasContext *s, uint32_t insn)
510
tcg_temp_free_i64(t_true);
511
}
512
513
-/* C3.6.25 Floating-point data-processing (1 source) - single precision */
514
+/* Floating-point data-processing (1 source) - single precision */
515
static void handle_fp_1src_single(DisasContext *s, int opcode, int rd, int rn)
516
{
517
TCGv_ptr fpst;
518
@@ -XXX,XX +XXX,XX @@ static void handle_fp_1src_single(DisasContext *s, int opcode, int rd, int rn)
519
tcg_temp_free_i32(tcg_res);
520
}
521
522
-/* C3.6.25 Floating-point data-processing (1 source) - double precision */
523
+/* Floating-point data-processing (1 source) - double precision */
524
static void handle_fp_1src_double(DisasContext *s, int opcode, int rd, int rn)
525
{
526
TCGv_ptr fpst;
527
@@ -XXX,XX +XXX,XX @@ static void handle_fp_fcvt(DisasContext *s, int opcode,
528
}
529
}
530
531
-/* C3.6.25 Floating point data-processing (1 source)
532
+/* Floating point data-processing (1 source)
533
* 31 30 29 28 24 23 22 21 20 15 14 10 9 5 4 0
534
* +---+---+---+-----------+------+---+--------+-----------+------+------+
535
* | M | 0 | S | 1 1 1 1 0 | type | 1 | opcode | 1 0 0 0 0 | Rn | Rd |
536
@@ -XXX,XX +XXX,XX @@ static void disas_fp_1src(DisasContext *s, uint32_t insn)
537
}
538
}
539
540
-/* C3.6.26 Floating-point data-processing (2 source) - single precision */
541
+/* Floating-point data-processing (2 source) - single precision */
542
static void handle_fp_2src_single(DisasContext *s, int opcode,
543
int rd, int rn, int rm)
544
{
545
@@ -XXX,XX +XXX,XX @@ static void handle_fp_2src_single(DisasContext *s, int opcode,
546
tcg_temp_free_i32(tcg_res);
547
}
548
549
-/* C3.6.26 Floating-point data-processing (2 source) - double precision */
550
+/* Floating-point data-processing (2 source) - double precision */
551
static void handle_fp_2src_double(DisasContext *s, int opcode,
552
int rd, int rn, int rm)
553
{
554
@@ -XXX,XX +XXX,XX @@ static void handle_fp_2src_double(DisasContext *s, int opcode,
555
tcg_temp_free_i64(tcg_res);
556
}
557
558
-/* C3.6.26 Floating point data-processing (2 source)
559
+/* Floating point data-processing (2 source)
560
* 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
561
* +---+---+---+-----------+------+---+------+--------+-----+------+------+
562
* | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | opcode | 1 0 | Rn | Rd |
563
@@ -XXX,XX +XXX,XX @@ static void disas_fp_2src(DisasContext *s, uint32_t insn)
564
}
565
}
566
567
-/* C3.6.27 Floating-point data-processing (3 source) - single precision */
568
+/* Floating-point data-processing (3 source) - single precision */
569
static void handle_fp_3src_single(DisasContext *s, bool o0, bool o1,
570
int rd, int rn, int rm, int ra)
571
{
572
@@ -XXX,XX +XXX,XX @@ static void handle_fp_3src_single(DisasContext *s, bool o0, bool o1,
573
tcg_temp_free_i32(tcg_res);
574
}
575
576
-/* C3.6.27 Floating-point data-processing (3 source) - double precision */
577
+/* Floating-point data-processing (3 source) - double precision */
578
static void handle_fp_3src_double(DisasContext *s, bool o0, bool o1,
579
int rd, int rn, int rm, int ra)
580
{
581
@@ -XXX,XX +XXX,XX @@ static void handle_fp_3src_double(DisasContext *s, bool o0, bool o1,
582
tcg_temp_free_i64(tcg_res);
583
}
584
585
-/* C3.6.27 Floating point data-processing (3 source)
586
+/* Floating point data-processing (3 source)
587
* 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0
588
* +---+---+---+-----------+------+----+------+----+------+------+------+
589
* | M | 0 | S | 1 1 1 1 1 | type | o1 | Rm | o0 | Ra | Rn | Rd |
590
@@ -XXX,XX +XXX,XX @@ static void disas_fp_3src(DisasContext *s, uint32_t insn)
591
}
592
}
593
594
-/* C3.6.28 Floating point immediate
595
+/* Floating point immediate
596
* 31 30 29 28 24 23 22 21 20 13 12 10 9 5 4 0
597
* +---+---+---+-----------+------+---+------------+-------+------+------+
598
* | M | 0 | S | 1 1 1 1 0 | type | 1 | imm8 | 1 0 0 | imm5 | Rd |
599
@@ -XXX,XX +XXX,XX @@ static void handle_fpfpcvt(DisasContext *s, int rd, int rn, int opcode,
600
tcg_temp_free_i32(tcg_shift);
601
}
602
603
-/* C3.6.29 Floating point <-> fixed point conversions
604
+/* Floating point <-> fixed point conversions
605
* 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
606
* +----+---+---+-----------+------+---+-------+--------+-------+------+------+
607
* | sf | 0 | S | 1 1 1 1 0 | type | 0 | rmode | opcode | scale | Rn | Rd |
608
@@ -XXX,XX +XXX,XX @@ static void handle_fmov(DisasContext *s, int rd, int rn, int type, bool itof)
609
}
610
}
611
612
-/* C3.6.30 Floating point <-> integer conversions
613
+/* Floating point <-> integer conversions
614
* 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
615
* +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
616
* | sf | 0 | S | 1 1 1 1 0 | type | 1 | rmode | opc | 0 0 0 0 0 0 | Rn | Rd |
617
@@ -XXX,XX +XXX,XX @@ static void do_ext64(DisasContext *s, TCGv_i64 tcg_left, TCGv_i64 tcg_right,
618
tcg_temp_free_i64(tcg_tmp);
619
}
620
621
-/* C3.6.1 EXT
622
+/* EXT
623
* 31 30 29 24 23 22 21 20 16 15 14 11 10 9 5 4 0
624
* +---+---+-------------+-----+---+------+---+------+---+------+------+
625
* | 0 | Q | 1 0 1 1 1 0 | op2 | 0 | Rm | 0 | imm4 | 0 | Rn | Rd |
626
@@ -XXX,XX +XXX,XX @@ static void disas_simd_ext(DisasContext *s, uint32_t insn)
627
tcg_temp_free_i64(tcg_resh);
628
}
629
630
-/* C3.6.2 TBL/TBX
631
+/* TBL/TBX
632
* 31 30 29 24 23 22 21 20 16 15 14 13 12 11 10 9 5 4 0
633
* +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
634
* | 0 | Q | 0 0 1 1 1 0 | op2 | 0 | Rm | 0 | len | op | 0 0 | Rn | Rd |
635
@@ -XXX,XX +XXX,XX @@ static void disas_simd_tb(DisasContext *s, uint32_t insn)
636
tcg_temp_free_i64(tcg_resh);
637
}
638
639
-/* C3.6.3 ZIP/UZP/TRN
640
+/* ZIP/UZP/TRN
641
* 31 30 29 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
642
* +---+---+-------------+------+---+------+---+------------------+------+
643
* | 0 | Q | 0 0 1 1 1 0 | size | 0 | Rm | 0 | opc | 1 0 | Rn | Rd |
644
@@ -XXX,XX +XXX,XX @@ static void do_minmaxop(DisasContext *s, TCGv_i32 tcg_elt1, TCGv_i32 tcg_elt2,
645
}
646
}
647
648
-/* C3.6.4 AdvSIMD across lanes
649
+/* AdvSIMD across lanes
650
* 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
651
* +---+---+---+-----------+------+-----------+--------+-----+------+------+
652
* | 0 | Q | U | 0 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
653
@@ -XXX,XX +XXX,XX @@ static void disas_simd_across_lanes(DisasContext *s, uint32_t insn)
654
tcg_temp_free_i64(tcg_res);
655
}
656
657
-/* C6.3.31 DUP (Element, Vector)
658
+/* DUP (Element, Vector)
659
*
660
* 31 30 29 21 20 16 15 10 9 5 4 0
661
* +---+---+-------------------+--------+-------------+------+------+
662
@@ -XXX,XX +XXX,XX @@ static void handle_simd_dupe(DisasContext *s, int is_q, int rd, int rn,
663
tcg_temp_free_i64(tmp);
664
}
665
666
-/* C6.3.31 DUP (element, scalar)
667
+/* DUP (element, scalar)
668
* 31 21 20 16 15 10 9 5 4 0
669
* +-----------------------+--------+-------------+------+------+
670
* | 0 1 0 1 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
671
@@ -XXX,XX +XXX,XX @@ static void handle_simd_dupes(DisasContext *s, int rd, int rn,
672
tcg_temp_free_i64(tmp);
673
}
674
675
-/* C6.3.32 DUP (General)
676
+/* DUP (General)
677
*
678
* 31 30 29 21 20 16 15 10 9 5 4 0
679
* +---+---+-------------------+--------+-------------+------+------+
680
@@ -XXX,XX +XXX,XX @@ static void handle_simd_dupg(DisasContext *s, int is_q, int rd, int rn,
681
}
682
}
683
684
-/* C6.3.150 INS (Element)
685
+/* INS (Element)
686
*
687
* 31 21 20 16 15 14 11 10 9 5 4 0
688
* +-----------------------+--------+------------+---+------+------+
689
@@ -XXX,XX +XXX,XX @@ static void handle_simd_inse(DisasContext *s, int rd, int rn,
690
}
691
692
693
-/* C6.3.151 INS (General)
694
+/* INS (General)
695
*
696
* 31 21 20 16 15 10 9 5 4 0
697
* +-----------------------+--------+-------------+------+------+
698
@@ -XXX,XX +XXX,XX @@ static void handle_simd_insg(DisasContext *s, int rd, int rn, int imm5)
699
}
700
701
/*
702
- * C6.3.321 UMOV (General)
703
- * C6.3.237 SMOV (General)
704
+ * UMOV (General)
705
+ * SMOV (General)
706
*
707
* 31 30 29 21 20 16 15 12 10 9 5 4 0
708
* +---+---+-------------------+--------+-------------+------+------+
709
@@ -XXX,XX +XXX,XX @@ static void handle_simd_umov_smov(DisasContext *s, int is_q, int is_signed,
710
}
711
}
712
713
-/* C3.6.5 AdvSIMD copy
714
+/* AdvSIMD copy
715
* 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
716
* +---+---+----+-----------------+------+---+------+---+------+------+
717
* | 0 | Q | op | 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
718
@@ -XXX,XX +XXX,XX @@ static void disas_simd_copy(DisasContext *s, uint32_t insn)
719
}
720
}
721
722
-/* C3.6.6 AdvSIMD modified immediate
723
+/* AdvSIMD modified immediate
724
* 31 30 29 28 19 18 16 15 12 11 10 9 5 4 0
725
* +---+---+----+---------------------+-----+-------+----+---+-------+------+
726
* | 0 | Q | op | 0 1 1 1 1 0 0 0 0 0 | abc | cmode | o2 | 1 | defgh | Rd |
727
@@ -XXX,XX +XXX,XX @@ static void disas_simd_mod_imm(DisasContext *s, uint32_t insn)
728
tcg_temp_free_i64(tcg_imm);
729
}
730
731
-/* C3.6.7 AdvSIMD scalar copy
732
+/* AdvSIMD scalar copy
733
* 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
734
* +-----+----+-----------------+------+---+------+---+------+------+
735
* | 0 1 | op | 1 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
736
@@ -XXX,XX +XXX,XX @@ static void disas_simd_scalar_copy(DisasContext *s, uint32_t insn)
737
handle_simd_dupes(s, rd, rn, imm5);
738
}
739
740
-/* C3.6.8 AdvSIMD scalar pairwise
741
+/* AdvSIMD scalar pairwise
742
* 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
743
* +-----+---+-----------+------+-----------+--------+-----+------+------+
744
* | 0 1 | U | 1 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
745
@@ -XXX,XX +XXX,XX @@ static void handle_simd_shift_fpint_conv(DisasContext *s, bool is_scalar,
746
tcg_temp_free_i32(tcg_rmode);
747
}
748
749
-/* C3.6.9 AdvSIMD scalar shift by immediate
750
+/* AdvSIMD scalar shift by immediate
751
* 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
752
* +-----+---+-------------+------+------+--------+---+------+------+
753
* | 0 1 | U | 1 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
754
@@ -XXX,XX +XXX,XX @@ static void disas_simd_scalar_shift_imm(DisasContext *s, uint32_t insn)
755
}
756
}
757
758
-/* C3.6.10 AdvSIMD scalar three different
759
+/* AdvSIMD scalar three different
760
* 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
761
* +-----+---+-----------+------+---+------+--------+-----+------+------+
762
* | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
763
@@ -XXX,XX +XXX,XX @@ static void handle_3same_float(DisasContext *s, int size, int elements,
764
}
765
}
766
767
-/* C3.6.11 AdvSIMD scalar three same
768
+/* AdvSIMD scalar three same
769
* 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
770
* +-----+---+-----------+------+---+------+--------+---+------+------+
771
* | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
772
@@ -XXX,XX +XXX,XX @@ static void handle_2misc_satacc(DisasContext *s, bool is_scalar, bool is_u,
773
}
774
}
775
776
-/* C3.6.12 AdvSIMD scalar two reg misc
777
+/* AdvSIMD scalar two reg misc
778
* 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
779
* +-----+---+-----------+------+-----------+--------+-----+------+------+
780
* | 0 1 | U | 1 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
781
@@ -XXX,XX +XXX,XX @@ static void handle_vec_simd_shrn(DisasContext *s, bool is_q,
782
}
783
784
785
-/* C3.6.14 AdvSIMD shift by immediate
786
+/* AdvSIMD shift by immediate
787
* 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
788
* +---+---+---+-------------+------+------+--------+---+------+------+
789
* | 0 | Q | U | 0 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
790
@@ -XXX,XX +XXX,XX @@ static void handle_pmull_64(DisasContext *s, int is_q, int rd, int rn, int rm)
791
tcg_temp_free_i64(tcg_res);
792
}
793
794
-/* C3.6.15 AdvSIMD three different
795
+/* AdvSIMD three different
796
* 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
797
* +---+---+---+-----------+------+---+------+--------+-----+------+------+
798
* | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
799
@@ -XXX,XX +XXX,XX @@ static void disas_simd_3same_int(DisasContext *s, uint32_t insn)
800
}
801
}
802
803
-/* C3.6.16 AdvSIMD three same
804
+/* AdvSIMD three same
805
* 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
806
* +---+---+---+-----------+------+---+------+--------+---+------+------+
807
* | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
808
@@ -XXX,XX +XXX,XX @@ static void handle_shll(DisasContext *s, bool is_q, int size, int rn, int rd)
809
}
810
}
811
812
-/* C3.6.17 AdvSIMD two reg misc
813
+/* AdvSIMD two reg misc
814
* 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
815
* +---+---+---+-----------+------+-----------+--------+-----+------+------+
816
* | 0 | Q | U | 0 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
817
@@ -XXX,XX +XXX,XX @@ static void disas_simd_two_reg_misc(DisasContext *s, uint32_t insn)
818
}
819
}
820
821
-/* C3.6.13 AdvSIMD scalar x indexed element
822
+/* AdvSIMD scalar x indexed element
823
* 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
824
* +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
825
* | 0 1 | U | 1 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
826
* +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
827
- * C3.6.18 AdvSIMD vector x indexed element
828
+ * AdvSIMD vector x indexed element
829
* 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
830
* +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
831
* | 0 | Q | U | 0 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
832
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
833
}
834
}
835
836
-/* C3.6.19 Crypto AES
837
+/* Crypto AES
838
* 31 24 23 22 21 17 16 12 11 10 9 5 4 0
839
* +-----------------+------+-----------+--------+-----+------+------+
840
* | 0 1 0 0 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
841
@@ -XXX,XX +XXX,XX @@ static void disas_crypto_aes(DisasContext *s, uint32_t insn)
842
tcg_temp_free_i32(tcg_decrypt);
843
}
844
845
-/* C3.6.20 Crypto three-reg SHA
846
+/* Crypto three-reg SHA
847
* 31 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
848
* +-----------------+------+---+------+---+--------+-----+------+------+
849
* | 0 1 0 1 1 1 1 0 | size | 0 | Rm | 0 | opcode | 0 0 | Rn | Rd |
850
@@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha(DisasContext *s, uint32_t insn)
851
tcg_temp_free_i32(tcg_rm_regno);
852
}
853
854
-/* C3.6.21 Crypto two-reg SHA
855
+/* Crypto two-reg SHA
856
* 31 24 23 22 21 17 16 12 11 10 9 5 4 0
857
* +-----------------+------+-----------+--------+-----+------+------+
858
* | 0 1 0 1 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
859
--
45
--
860
2.7.4
46
2.20.1
861
47
862
48
diff view generated by jsdifflib
1
If AIRCR.BFHFNMINS is clear, then although NonSecure HardFault
1
From: Igor Mammedov <imammedo@redhat.com>
2
can still be pended via SHCSR.HARDFAULTPENDED it mustn't actually
3
preempt execution. The simple way to achieve this is to clear the
4
enable bit for it, since the enable bit isn't guest visible.
5
2
3
SOC object returned by object_new() is leaked in current code.
4
Set SOC parent explicitly to board and then unref to SOC object
5
to make sure that refererence returned by object_new() is taken
6
care of.
7
8
The SOC object will be kept alive by its parent (machine) and
9
will be automatically freed when MachineState is destroyed.
10
11
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
12
Reported-by: Andrew Jones <drjones@redhat.com>
13
Tested-by: Niek Linnenbank <nieklinnenbank@gmail.com>
14
Message-id: 20200303091254.22373-1-imammedo@redhat.com
15
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 1505240046-11454-15-git-send-email-peter.maydell@linaro.org
9
---
17
---
10
hw/intc/armv7m_nvic.c | 12 ++++++++++--
18
hw/arm/cubieboard.c | 3 +++
11
1 file changed, 10 insertions(+), 2 deletions(-)
19
1 file changed, 3 insertions(+)
12
20
13
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
21
diff --git a/hw/arm/cubieboard.c b/hw/arm/cubieboard.c
14
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/intc/armv7m_nvic.c
23
--- a/hw/arm/cubieboard.c
16
+++ b/hw/intc/armv7m_nvic.c
24
+++ b/hw/arm/cubieboard.c
17
@@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value,
25
@@ -XXX,XX +XXX,XX @@ static void cubieboard_init(MachineState *machine)
18
(R_V7M_AIRCR_SYSRESETREQS_MASK |
19
R_V7M_AIRCR_BFHFNMINS_MASK |
20
R_V7M_AIRCR_PRIS_MASK);
21
- /* BFHFNMINS changes the priority of Secure HardFault */
22
+ /* BFHFNMINS changes the priority of Secure HardFault, and
23
+ * allows a pending Non-secure HardFault to preempt (which
24
+ * we implement by marking it enabled).
25
+ */
26
if (cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK) {
27
s->sec_vectors[ARMV7M_EXCP_HARD].prio = -3;
28
+ s->vectors[ARMV7M_EXCP_HARD].enabled = 1;
29
} else {
30
s->sec_vectors[ARMV7M_EXCP_HARD].prio = -1;
31
+ s->vectors[ARMV7M_EXCP_HARD].enabled = 0;
32
}
33
}
34
nvic_irq_update(s);
35
@@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_reset(DeviceState *dev)
36
NVICState *s = NVIC(dev);
37
38
s->vectors[ARMV7M_EXCP_NMI].enabled = 1;
39
- s->vectors[ARMV7M_EXCP_HARD].enabled = 1;
40
/* MEM, BUS, and USAGE are enabled through
41
* the System Handler Control register
42
*/
43
@@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_reset(DeviceState *dev)
44
45
/* AIRCR.BFHFNMINS resets to 0 so Secure HF is priority -1 (R_CMTC) */
46
s->sec_vectors[ARMV7M_EXCP_HARD].prio = -1;
47
+ /* If AIRCR.BFHFNMINS is 0 then NS HF is (effectively) disabled */
48
+ s->vectors[ARMV7M_EXCP_HARD].enabled = 0;
49
+ } else {
50
+ s->vectors[ARMV7M_EXCP_HARD].enabled = 1;
51
}
26
}
52
27
53
/* Strictly speaking the reset handler should be enabled.
28
a10 = AW_A10(object_new(TYPE_AW_A10));
29
+ object_property_add_child(OBJECT(machine), "soc", OBJECT(a10),
30
+ &error_abort);
31
+ object_unref(OBJECT(a10));
32
33
object_property_set_int(OBJECT(&a10->emac), 1, "phy-addr", &err);
34
if (err != NULL) {
54
--
35
--
55
2.7.4
36
2.20.1
56
37
57
38
diff view generated by jsdifflib
1
Instead of looking up the pending priority
1
From: Guenter Roeck <linux@roeck-us.net>
2
in nvic_pending_prio(), cache it in a new state struct
3
field. The calculation of the pending priority given
4
the interrupt number is more complicated in v8M with
5
the security extension, so the caching will be worthwhile.
6
2
7
This changes nvic_pending_prio() from returning a full
3
Wire up eSDHC controllers in fsl-imx25. For imx25-pdk, connect drives
8
(group + subpriority) priority value to returning a group
4
provided on the command line to available eSDHC controllers.
9
priority. This doesn't require changes to its callsites
10
because we use it only in comparisons of the form
11
execution_prio > nvic_pending_prio()
12
and execution priority is always a group priority, so
13
a test (exec prio > full prio) is true if and only if
14
(execprio > group_prio).
15
5
16
(Architecturally the expected comparison is with the
6
This patch enables booting the imx25-pdk emulation from SD card.
17
group priority for this sort of "would we preempt" test;
18
we were only doing a test with a full priority as an
19
optimisation to avoid the mask, which is possible
20
precisely because the two comparisons always give the
21
same answer.)
22
7
8
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
9
Message-id: 20200310215146.19688-2-linux@roeck-us.net
10
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
11
[PMM: made commit subject consistent with other patch]
23
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
24
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
25
Message-id: 1505240046-11454-5-git-send-email-peter.maydell@linaro.org
26
---
13
---
27
include/hw/intc/armv7m_nvic.h | 2 ++
14
include/hw/arm/fsl-imx25.h | 9 +++++++++
28
hw/intc/armv7m_nvic.c | 23 +++++++++++++----------
15
hw/arm/fsl-imx25.c | 32 ++++++++++++++++++++++++++++++++
29
hw/intc/trace-events | 2 +-
16
hw/arm/imx25_pdk.c | 16 ++++++++++++++++
30
3 files changed, 16 insertions(+), 11 deletions(-)
17
3 files changed, 57 insertions(+)
31
18
32
diff --git a/include/hw/intc/armv7m_nvic.h b/include/hw/intc/armv7m_nvic.h
19
diff --git a/include/hw/arm/fsl-imx25.h b/include/hw/arm/fsl-imx25.h
33
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
34
--- a/include/hw/intc/armv7m_nvic.h
21
--- a/include/hw/arm/fsl-imx25.h
35
+++ b/include/hw/intc/armv7m_nvic.h
22
+++ b/include/hw/arm/fsl-imx25.h
36
@@ -XXX,XX +XXX,XX @@ typedef struct NVICState {
23
@@ -XXX,XX +XXX,XX @@
37
* - vectpending
24
#include "hw/misc/imx_rngc.h"
38
* - vectpending_is_secure
25
#include "hw/i2c/imx_i2c.h"
39
* - exception_prio
26
#include "hw/gpio/imx_gpio.h"
40
+ * - vectpending_prio
27
+#include "hw/sd/sdhci.h"
41
*/
28
#include "exec/memory.h"
42
unsigned int vectpending; /* highest prio pending enabled exception */
29
#include "target/arm/cpu.h"
43
/* true if vectpending is a banked secure exception, ie it is in
30
44
@@ -XXX,XX +XXX,XX @@ typedef struct NVICState {
31
@@ -XXX,XX +XXX,XX @@
45
*/
32
#define FSL_IMX25_NUM_EPITS 2
46
bool vectpending_is_s_banked;
33
#define FSL_IMX25_NUM_I2CS 3
47
int exception_prio; /* group prio of the highest prio active exception */
34
#define FSL_IMX25_NUM_GPIOS 4
48
+ int vectpending_prio; /* group prio of the exeception in vectpending */
35
+#define FSL_IMX25_NUM_ESDHCS 2
49
36
50
MemoryRegion sysregmem;
37
typedef struct FslIMX25State {
51
MemoryRegion sysreg_ns_mem;
38
/*< private >*/
52
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
39
@@ -XXX,XX +XXX,XX @@ typedef struct FslIMX25State {
40
IMXRNGCState rngc;
41
IMXI2CState i2c[FSL_IMX25_NUM_I2CS];
42
IMXGPIOState gpio[FSL_IMX25_NUM_GPIOS];
43
+ SDHCIState esdhc[FSL_IMX25_NUM_ESDHCS];
44
MemoryRegion rom[2];
45
MemoryRegion iram;
46
MemoryRegion iram_alias;
47
@@ -XXX,XX +XXX,XX @@ typedef struct FslIMX25State {
48
#define FSL_IMX25_GPIO3_SIZE 0x4000
49
#define FSL_IMX25_RNGC_ADDR 0x53FB0000
50
#define FSL_IMX25_RNGC_SIZE 0x4000
51
+#define FSL_IMX25_ESDHC1_ADDR 0x53FB4000
52
+#define FSL_IMX25_ESDHC1_SIZE 0x4000
53
+#define FSL_IMX25_ESDHC2_ADDR 0x53FB8000
54
+#define FSL_IMX25_ESDHC2_SIZE 0x4000
55
#define FSL_IMX25_GPIO1_ADDR 0x53FCC000
56
#define FSL_IMX25_GPIO1_SIZE 0x4000
57
#define FSL_IMX25_GPIO2_ADDR 0x53FD0000
58
@@ -XXX,XX +XXX,XX @@ typedef struct FslIMX25State {
59
#define FSL_IMX25_GPIO2_IRQ 51
60
#define FSL_IMX25_GPIO3_IRQ 16
61
#define FSL_IMX25_GPIO4_IRQ 23
62
+#define FSL_IMX25_ESDHC1_IRQ 9
63
+#define FSL_IMX25_ESDHC2_IRQ 8
64
65
#endif /* FSL_IMX25_H */
66
diff --git a/hw/arm/fsl-imx25.c b/hw/arm/fsl-imx25.c
53
index XXXXXXX..XXXXXXX 100644
67
index XXXXXXX..XXXXXXX 100644
54
--- a/hw/intc/armv7m_nvic.c
68
--- a/hw/arm/fsl-imx25.c
55
+++ b/hw/intc/armv7m_nvic.c
69
+++ b/hw/arm/fsl-imx25.c
56
@@ -XXX,XX +XXX,XX @@ static const uint8_t nvic_id[] = {
70
@@ -XXX,XX +XXX,XX @@
57
71
#include "hw/qdev-properties.h"
58
static int nvic_pending_prio(NVICState *s)
72
#include "chardev/char.h"
73
74
+#define IMX25_ESDHC_CAPABILITIES 0x07e20000
75
+
76
static void fsl_imx25_init(Object *obj)
59
{
77
{
60
- /* return the priority of the current pending interrupt,
78
FslIMX25State *s = FSL_IMX25(obj);
61
+ /* return the group priority of the current pending interrupt,
79
@@ -XXX,XX +XXX,XX @@ static void fsl_imx25_init(Object *obj)
62
* or NVIC_NOEXC_PRIO if no interrupt is pending
80
sysbus_init_child_obj(obj, "gpio[*]", &s->gpio[i], sizeof(s->gpio[i]),
63
*/
81
TYPE_IMX_GPIO);
64
- return s->vectpending ? s->vectors[s->vectpending].prio : NVIC_NOEXC_PRIO;
82
}
65
+ return s->vectpending_prio;
83
+
84
+ for (i = 0; i < FSL_IMX25_NUM_ESDHCS; i++) {
85
+ sysbus_init_child_obj(obj, "sdhc[*]", &s->esdhc[i], sizeof(s->esdhc[i]),
86
+ TYPE_IMX_USDHC);
87
+ }
66
}
88
}
67
89
68
/* Return the value of the ISCR RETTOBASE bit:
90
static void fsl_imx25_realize(DeviceState *dev, Error **errp)
69
@@ -XXX,XX +XXX,XX @@ static void nvic_recompute_state(NVICState *s)
91
@@ -XXX,XX +XXX,XX @@ static void fsl_imx25_realize(DeviceState *dev, Error **errp)
70
active_prio &= nvic_gprio_mask(s);
92
gpio_table[i].irq));
71
}
93
}
72
94
73
+ if (pend_prio > 0) {
95
+ /* Initialize all SDHC */
74
+ pend_prio &= nvic_gprio_mask(s);
96
+ for (i = 0; i < FSL_IMX25_NUM_ESDHCS; i++) {
97
+ static const struct {
98
+ hwaddr addr;
99
+ unsigned int irq;
100
+ } esdhc_table[FSL_IMX25_NUM_ESDHCS] = {
101
+ { FSL_IMX25_ESDHC1_ADDR, FSL_IMX25_ESDHC1_IRQ },
102
+ { FSL_IMX25_ESDHC2_ADDR, FSL_IMX25_ESDHC2_IRQ },
103
+ };
104
+
105
+ object_property_set_uint(OBJECT(&s->esdhc[i]), 2, "sd-spec-version",
106
+ &err);
107
+ object_property_set_uint(OBJECT(&s->esdhc[i]), IMX25_ESDHC_CAPABILITIES,
108
+ "capareg", &err);
109
+ object_property_set_bool(OBJECT(&s->esdhc[i]), true, "realized", &err);
110
+ if (err) {
111
+ error_propagate(errp, err);
112
+ return;
113
+ }
114
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->esdhc[i]), 0, esdhc_table[i].addr);
115
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->esdhc[i]), 0,
116
+ qdev_get_gpio_in(DEVICE(&s->avic),
117
+ esdhc_table[i].irq));
75
+ }
118
+ }
76
+
119
+
77
s->vectpending = pend_irq;
120
/* initialize 2 x 16 KB ROM */
78
+ s->vectpending_prio = pend_prio;
121
memory_region_init_rom(&s->rom[0], NULL,
79
s->exception_prio = active_prio;
122
"imx25.rom0", FSL_IMX25_ROM0_SIZE, &err);
80
123
diff --git a/hw/arm/imx25_pdk.c b/hw/arm/imx25_pdk.c
81
- trace_nvic_recompute_state(s->vectpending, s->exception_prio);
82
+ trace_nvic_recompute_state(s->vectpending,
83
+ s->vectpending_prio,
84
+ s->exception_prio);
85
}
86
87
/* Return the current execution priority of the CPU
88
@@ -XXX,XX +XXX,XX @@ void armv7m_nvic_acknowledge_irq(void *opaque)
89
CPUARMState *env = &s->cpu->env;
90
const int pending = s->vectpending;
91
const int running = nvic_exec_prio(s);
92
- int pendgroupprio;
93
VecInfo *vec;
94
95
assert(pending > ARMV7M_EXCP_RESET && pending < s->num_irq);
96
@@ -XXX,XX +XXX,XX @@ void armv7m_nvic_acknowledge_irq(void *opaque)
97
assert(vec->enabled);
98
assert(vec->pending);
99
100
- pendgroupprio = vec->prio;
101
- if (pendgroupprio > 0) {
102
- pendgroupprio &= nvic_gprio_mask(s);
103
- }
104
- assert(pendgroupprio < running);
105
+ assert(s->vectpending_prio < running);
106
107
- trace_nvic_acknowledge_irq(pending, vec->prio);
108
+ trace_nvic_acknowledge_irq(pending, s->vectpending_prio);
109
110
vec->active = 1;
111
vec->pending = 0;
112
@@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_reset(DeviceState *dev)
113
s->exception_prio = NVIC_NOEXC_PRIO;
114
s->vectpending = 0;
115
s->vectpending_is_s_banked = false;
116
+ s->vectpending_prio = NVIC_NOEXC_PRIO;
117
}
118
119
static void nvic_systick_trigger(void *opaque, int n, int level)
120
diff --git a/hw/intc/trace-events b/hw/intc/trace-events
121
index XXXXXXX..XXXXXXX 100644
124
index XXXXXXX..XXXXXXX 100644
122
--- a/hw/intc/trace-events
125
--- a/hw/arm/imx25_pdk.c
123
+++ b/hw/intc/trace-events
126
+++ b/hw/arm/imx25_pdk.c
124
@@ -XXX,XX +XXX,XX @@ gicv3_redist_set_irq(uint32_t cpu, int irq, int level) "GICv3 redistributor 0x%x
127
@@ -XXX,XX +XXX,XX @@
125
gicv3_redist_send_sgi(uint32_t cpu, int irq) "GICv3 redistributor 0x%x pending SGI %d"
128
#include "qemu/osdep.h"
126
129
#include "qapi/error.h"
127
# hw/intc/armv7m_nvic.c
130
#include "cpu.h"
128
-nvic_recompute_state(int vectpending, int exception_prio) "NVIC state recomputed: vectpending %d exception_prio %d"
131
+#include "hw/qdev-properties.h"
129
+nvic_recompute_state(int vectpending, int vectpending_prio, int exception_prio) "NVIC state recomputed: vectpending %d vectpending_prio %d exception_prio %d"
132
#include "hw/arm/fsl-imx25.h"
130
nvic_set_prio(int irq, uint8_t prio) "NVIC set irq %d priority %d"
133
#include "hw/boards.h"
131
nvic_irq_update(int vectpending, int pendprio, int exception_prio, int level) "NVIC vectpending %d pending prio %d exception_prio %d: setting irq line to %d"
134
#include "qemu/error-report.h"
132
nvic_escalate_prio(int irq, int irqprio, int runprio) "NVIC escalating irq %d to HardFault: insufficient priority %d >= %d"
135
@@ -XXX,XX +XXX,XX @@ static void imx25_pdk_init(MachineState *machine)
136
imx25_pdk_binfo.board_id = 1771,
137
imx25_pdk_binfo.nb_cpus = 1;
138
139
+ for (i = 0; i < FSL_IMX25_NUM_ESDHCS; i++) {
140
+ BusState *bus;
141
+ DeviceState *carddev;
142
+ DriveInfo *di;
143
+ BlockBackend *blk;
144
+
145
+ di = drive_get_next(IF_SD);
146
+ blk = di ? blk_by_legacy_dinfo(di) : NULL;
147
+ bus = qdev_get_child_bus(DEVICE(&s->soc.esdhc[i]), "sd-bus");
148
+ carddev = qdev_create(bus, TYPE_SD_CARD);
149
+ qdev_prop_set_drive(carddev, "drive", blk, &error_fatal);
150
+ object_property_set_bool(OBJECT(carddev), true,
151
+ "realized", &error_fatal);
152
+ }
153
+
154
/*
155
* We test explicitly for qtest here as it is not done (yet?) in
156
* arm_load_kernel(). Without this the "make check" command would
133
--
157
--
134
2.7.4
158
2.20.1
135
159
136
160
diff view generated by jsdifflib
1
The Application Interrupt and Reset Control Register has some changes
1
From: Guenter Roeck <linux@roeck-us.net>
2
for v8M:
3
* new bits SYSRESETREQS, BFHFNMINS and PRIS: these all have
4
real state if the security extension is implemented and otherwise
5
are constant
6
* the PRIGROUP field is banked between security states
7
* non-secure code can be blocked from using the SYSRESET bit
8
to reset the system if SYSRESETREQS is set
9
2
10
Implement the new state and the changes to register read and write.
3
i.MX25 supports two USB controllers. Let's wire them up.
11
For the moment we ignore the effects of the secure PRIGROUP.
12
We will implement the effects of PRIS and BFHFNMIS later.
13
4
5
With this patch, imx25-pdk can boot from both USB ports.
6
7
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
8
Message-id: 20200310215146.19688-3-linux@roeck-us.net
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
16
Message-id: 1505240046-11454-6-git-send-email-peter.maydell@linaro.org
17
---
11
---
18
include/hw/intc/armv7m_nvic.h | 3 ++-
12
include/hw/arm/fsl-imx25.h | 9 +++++++++
19
target/arm/cpu.h | 12 +++++++++++
13
hw/arm/fsl-imx25.c | 24 ++++++++++++++++++++++++
20
hw/intc/armv7m_nvic.c | 49 +++++++++++++++++++++++++++++++++----------
14
2 files changed, 33 insertions(+)
21
target/arm/cpu.c | 7 +++++++
22
4 files changed, 59 insertions(+), 12 deletions(-)
23
15
24
diff --git a/include/hw/intc/armv7m_nvic.h b/include/hw/intc/armv7m_nvic.h
16
diff --git a/include/hw/arm/fsl-imx25.h b/include/hw/arm/fsl-imx25.h
25
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
26
--- a/include/hw/intc/armv7m_nvic.h
18
--- a/include/hw/arm/fsl-imx25.h
27
+++ b/include/hw/intc/armv7m_nvic.h
19
+++ b/include/hw/arm/fsl-imx25.h
28
@@ -XXX,XX +XXX,XX @@ typedef struct NVICState {
20
@@ -XXX,XX +XXX,XX @@
29
* Entries in sec_vectors[] for non-banked exception numbers are unused.
21
#include "hw/i2c/imx_i2c.h"
30
*/
22
#include "hw/gpio/imx_gpio.h"
31
VecInfo sec_vectors[NVIC_INTERNAL_VECTORS];
23
#include "hw/sd/sdhci.h"
32
- uint32_t prigroup;
24
+#include "hw/usb/chipidea.h"
33
+ /* The PRIGROUP field in AIRCR is banked */
25
#include "exec/memory.h"
34
+ uint32_t prigroup[M_REG_NUM_BANKS];
26
#include "target/arm/cpu.h"
35
27
36
/* The following fields are all cached state that can be recalculated
28
@@ -XXX,XX +XXX,XX @@
37
* from the vectors[] and sec_vectors[] arrays and the prigroup field:
29
#define FSL_IMX25_NUM_I2CS 3
38
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
30
#define FSL_IMX25_NUM_GPIOS 4
31
#define FSL_IMX25_NUM_ESDHCS 2
32
+#define FSL_IMX25_NUM_USBS 2
33
34
typedef struct FslIMX25State {
35
/*< private >*/
36
@@ -XXX,XX +XXX,XX @@ typedef struct FslIMX25State {
37
IMXI2CState i2c[FSL_IMX25_NUM_I2CS];
38
IMXGPIOState gpio[FSL_IMX25_NUM_GPIOS];
39
SDHCIState esdhc[FSL_IMX25_NUM_ESDHCS];
40
+ ChipideaState usb[FSL_IMX25_NUM_USBS];
41
MemoryRegion rom[2];
42
MemoryRegion iram;
43
MemoryRegion iram_alias;
44
@@ -XXX,XX +XXX,XX @@ typedef struct FslIMX25State {
45
#define FSL_IMX25_GPIO1_SIZE 0x4000
46
#define FSL_IMX25_GPIO2_ADDR 0x53FD0000
47
#define FSL_IMX25_GPIO2_SIZE 0x4000
48
+#define FSL_IMX25_USB1_ADDR 0x53FF4000
49
+#define FSL_IMX25_USB1_SIZE 0x0200
50
+#define FSL_IMX25_USB2_ADDR 0x53FF4400
51
+#define FSL_IMX25_USB2_SIZE 0x0200
52
#define FSL_IMX25_AVIC_ADDR 0x68000000
53
#define FSL_IMX25_AVIC_SIZE 0x4000
54
#define FSL_IMX25_IRAM_ADDR 0x78000000
55
@@ -XXX,XX +XXX,XX @@ typedef struct FslIMX25State {
56
#define FSL_IMX25_GPIO4_IRQ 23
57
#define FSL_IMX25_ESDHC1_IRQ 9
58
#define FSL_IMX25_ESDHC2_IRQ 8
59
+#define FSL_IMX25_USB1_IRQ 37
60
+#define FSL_IMX25_USB2_IRQ 35
61
62
#endif /* FSL_IMX25_H */
63
diff --git a/hw/arm/fsl-imx25.c b/hw/arm/fsl-imx25.c
39
index XXXXXXX..XXXXXXX 100644
64
index XXXXXXX..XXXXXXX 100644
40
--- a/target/arm/cpu.h
65
--- a/hw/arm/fsl-imx25.c
41
+++ b/target/arm/cpu.h
66
+++ b/hw/arm/fsl-imx25.c
42
@@ -XXX,XX +XXX,XX @@ typedef struct CPUARMState {
67
@@ -XXX,XX +XXX,XX @@ static void fsl_imx25_init(Object *obj)
43
int exception;
68
sysbus_init_child_obj(obj, "sdhc[*]", &s->esdhc[i], sizeof(s->esdhc[i]),
44
uint32_t primask[M_REG_NUM_BANKS];
69
TYPE_IMX_USDHC);
45
uint32_t faultmask[M_REG_NUM_BANKS];
70
}
46
+ uint32_t aircr; /* only holds r/w state if security extn implemented */
47
uint32_t secure; /* Is CPU in Secure state? (not guest visible) */
48
} v7m;
49
50
@@ -XXX,XX +XXX,XX @@ FIELD(V7M_CCR, STKALIGN, 9, 1)
51
FIELD(V7M_CCR, DC, 16, 1)
52
FIELD(V7M_CCR, IC, 17, 1)
53
54
+/* V7M AIRCR bits */
55
+FIELD(V7M_AIRCR, VECTRESET, 0, 1)
56
+FIELD(V7M_AIRCR, VECTCLRACTIVE, 1, 1)
57
+FIELD(V7M_AIRCR, SYSRESETREQ, 2, 1)
58
+FIELD(V7M_AIRCR, SYSRESETREQS, 3, 1)
59
+FIELD(V7M_AIRCR, PRIGROUP, 8, 3)
60
+FIELD(V7M_AIRCR, BFHFNMINS, 13, 1)
61
+FIELD(V7M_AIRCR, PRIS, 14, 1)
62
+FIELD(V7M_AIRCR, ENDIANNESS, 15, 1)
63
+FIELD(V7M_AIRCR, VECTKEY, 16, 16)
64
+
71
+
65
/* V7M CFSR bits for MMFSR */
72
+ for (i = 0; i < FSL_IMX25_NUM_USBS; i++) {
66
FIELD(V7M_CFSR, IACCVIOL, 0, 1)
73
+ sysbus_init_child_obj(obj, "usb[*]", &s->usb[i], sizeof(s->usb[i]),
67
FIELD(V7M_CFSR, DACCVIOL, 1, 1)
74
+ TYPE_CHIPIDEA);
68
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
75
+ }
69
index XXXXXXX..XXXXXXX 100644
76
+
70
--- a/hw/intc/armv7m_nvic.c
71
+++ b/hw/intc/armv7m_nvic.c
72
@@ -XXX,XX +XXX,XX @@ static bool nvic_isrpending(NVICState *s)
73
*/
74
static inline uint32_t nvic_gprio_mask(NVICState *s)
75
{
76
- return ~0U << (s->prigroup + 1);
77
+ return ~0U << (s->prigroup[M_REG_NS] + 1);
78
}
77
}
79
78
80
/* Recompute vectpending and exception_prio */
79
static void fsl_imx25_realize(DeviceState *dev, Error **errp)
81
@@ -XXX,XX +XXX,XX @@ static uint32_t nvic_readl(NVICState *s, uint32_t offset, MemTxAttrs attrs)
80
@@ -XXX,XX +XXX,XX @@ static void fsl_imx25_realize(DeviceState *dev, Error **errp)
82
return val;
81
esdhc_table[i].irq));
83
case 0xd08: /* Vector Table Offset. */
84
return cpu->env.v7m.vecbase[attrs.secure];
85
- case 0xd0c: /* Application Interrupt/Reset Control. */
86
- return 0xfa050000 | (s->prigroup << 8);
87
+ case 0xd0c: /* Application Interrupt/Reset Control (AIRCR) */
88
+ val = 0xfa050000 | (s->prigroup[attrs.secure] << 8);
89
+ if (attrs.secure) {
90
+ /* s->aircr stores PRIS, BFHFNMINS, SYSRESETREQS */
91
+ val |= cpu->env.v7m.aircr;
92
+ } else {
93
+ if (arm_feature(&cpu->env, ARM_FEATURE_V8)) {
94
+ /* BFHFNMINS is R/O from NS; other bits are RAZ/WI. If
95
+ * security isn't supported then BFHFNMINS is RAO (and
96
+ * the bit in env.v7m.aircr is always set).
97
+ */
98
+ val |= cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK;
99
+ }
100
+ }
101
+ return val;
102
case 0xd10: /* System Control. */
103
/* TODO: Implement SLEEPONEXIT. */
104
return 0;
105
@@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value,
106
case 0xd08: /* Vector Table Offset. */
107
cpu->env.v7m.vecbase[attrs.secure] = value & 0xffffff80;
108
break;
109
- case 0xd0c: /* Application Interrupt/Reset Control. */
110
- if ((value >> 16) == 0x05fa) {
111
- if (value & 4) {
112
- qemu_irq_pulse(s->sysresetreq);
113
+ case 0xd0c: /* Application Interrupt/Reset Control (AIRCR) */
114
+ if ((value >> R_V7M_AIRCR_VECTKEY_SHIFT) == 0x05fa) {
115
+ if (value & R_V7M_AIRCR_SYSRESETREQ_MASK) {
116
+ if (attrs.secure ||
117
+ !(cpu->env.v7m.aircr & R_V7M_AIRCR_SYSRESETREQS_MASK)) {
118
+ qemu_irq_pulse(s->sysresetreq);
119
+ }
120
}
121
- if (value & 2) {
122
+ if (value & R_V7M_AIRCR_VECTCLRACTIVE_MASK) {
123
qemu_log_mask(LOG_GUEST_ERROR,
124
"Setting VECTCLRACTIVE when not in DEBUG mode "
125
"is UNPREDICTABLE\n");
126
}
127
- if (value & 1) {
128
+ if (value & R_V7M_AIRCR_VECTRESET_MASK) {
129
+ /* NB: this bit is RES0 in v8M */
130
qemu_log_mask(LOG_GUEST_ERROR,
131
"Setting VECTRESET when not in DEBUG mode "
132
"is UNPREDICTABLE\n");
133
}
134
- s->prigroup = extract32(value, 8, 3);
135
+ s->prigroup[attrs.secure] = extract32(value,
136
+ R_V7M_AIRCR_PRIGROUP_SHIFT,
137
+ R_V7M_AIRCR_PRIGROUP_LENGTH);
138
+ if (attrs.secure) {
139
+ /* These bits are only writable by secure */
140
+ cpu->env.v7m.aircr = value &
141
+ (R_V7M_AIRCR_SYSRESETREQS_MASK |
142
+ R_V7M_AIRCR_BFHFNMINS_MASK |
143
+ R_V7M_AIRCR_PRIS_MASK);
144
+ }
145
nvic_irq_update(s);
146
}
147
break;
148
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_nvic_security = {
149
.fields = (VMStateField[]) {
150
VMSTATE_STRUCT_ARRAY(sec_vectors, NVICState, NVIC_INTERNAL_VECTORS, 1,
151
vmstate_VecInfo, VecInfo),
152
+ VMSTATE_UINT32(prigroup[M_REG_S], NVICState),
153
VMSTATE_END_OF_LIST()
154
}
82
}
155
};
83
156
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_nvic = {
84
+ /* USB */
157
.fields = (VMStateField[]) {
85
+ for (i = 0; i < FSL_IMX25_NUM_USBS; i++) {
158
VMSTATE_STRUCT_ARRAY(vectors, NVICState, NVIC_MAX_VECTORS, 1,
86
+ static const struct {
159
vmstate_VecInfo, VecInfo),
87
+ hwaddr addr;
160
- VMSTATE_UINT32(prigroup, NVICState),
88
+ unsigned int irq;
161
+ VMSTATE_UINT32(prigroup[M_REG_NS], NVICState),
89
+ } usb_table[FSL_IMX25_NUM_USBS] = {
162
VMSTATE_END_OF_LIST()
90
+ { FSL_IMX25_USB1_ADDR, FSL_IMX25_USB1_IRQ },
163
},
91
+ { FSL_IMX25_USB2_ADDR, FSL_IMX25_USB2_IRQ },
164
.subsections = (const VMStateDescription*[]) {
92
+ };
165
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
93
+
166
index XXXXXXX..XXXXXXX 100644
94
+ object_property_set_bool(OBJECT(&s->usb[i]), true, "realized",
167
--- a/target/arm/cpu.c
95
+ &error_abort);
168
+++ b/target/arm/cpu.c
96
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->usb[i]), 0, usb_table[i].addr);
169
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(CPUState *s)
97
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->usb[i]), 0,
170
98
+ qdev_get_gpio_in(DEVICE(&s->avic),
171
if (arm_feature(env, ARM_FEATURE_M_SECURITY)) {
99
+ usb_table[i].irq));
172
env->v7m.secure = true;
100
+ }
173
+ } else {
101
+
174
+ /* This bit resets to 0 if security is supported, but 1 if
102
/* initialize 2 x 16 KB ROM */
175
+ * it is not. The bit is not present in v7M, but we set it
103
memory_region_init_rom(&s->rom[0], NULL,
176
+ * here so we can avoid having to make checks on it conditional
104
"imx25.rom0", FSL_IMX25_ROM0_SIZE, &err);
177
+ * on ARM_FEATURE_V8 (we don't let the guest see the bit).
178
+ */
179
+ env->v7m.aircr = R_V7M_AIRCR_BFHFNMINS_MASK;
180
}
181
182
/* In v7M the reset value of this bit is IMPDEF, but ARM recommends
183
--
105
--
184
2.7.4
106
2.20.1
185
107
186
108
diff view generated by jsdifflib
1
From: Subbaraya Sundeep <sundeep.lkml@gmail.com>
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
2
2
3
Smartfusion2 SoC has hardened Microcontroller subsystem
3
The Allwinner H3 is a System on Chip containing four ARM Cortex A7
4
and flash based FPGA fabric. This patch adds support for
4
processor cores. Features and specifications include DDR2/DDR3 memory,
5
Microcontroller subsystem in the SoC.
5
SD/MMC storage cards, 10/100/1000Mbit Ethernet, USB 2.0, HDMI and
6
various I/O modules. This commit adds support for the Allwinner H3
7
System on Chip.
6
8
7
Signed-off-by: Subbaraya Sundeep <sundeep.lkml@gmail.com>
9
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
8
Reviewed-by: Alistair Francis <alistair.francis@xilinx.com>
10
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
9
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
11
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
10
Message-id: 20170920201737.25723-5-f4bug@amsat.org
12
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
11
[PMD: drop cpu_model to directly use cpu type, check m3clk non null]
13
Message-id: 20200311221854.30370-2-nieklinnenbank@gmail.com
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
---
15
---
14
hw/arm/Makefile.objs | 1 +
16
hw/arm/Makefile.objs | 1 +
15
include/hw/arm/msf2-soc.h | 67 +++++++++++
17
include/hw/arm/allwinner-h3.h | 106 +++++++++++
16
hw/arm/msf2-soc.c | 238 ++++++++++++++++++++++++++++++++++++++++
18
hw/arm/allwinner-h3.c | 327 ++++++++++++++++++++++++++++++++
19
MAINTAINERS | 7 +
17
default-configs/arm-softmmu.mak | 1 +
20
default-configs/arm-softmmu.mak | 1 +
18
4 files changed, 307 insertions(+)
21
hw/arm/Kconfig | 8 +
19
create mode 100644 include/hw/arm/msf2-soc.h
22
6 files changed, 450 insertions(+)
20
create mode 100644 hw/arm/msf2-soc.c
23
create mode 100644 include/hw/arm/allwinner-h3.h
24
create mode 100644 hw/arm/allwinner-h3.c
21
25
22
diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
26
diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
23
index XXXXXXX..XXXXXXX 100644
27
index XXXXXXX..XXXXXXX 100644
24
--- a/hw/arm/Makefile.objs
28
--- a/hw/arm/Makefile.objs
25
+++ b/hw/arm/Makefile.objs
29
+++ b/hw/arm/Makefile.objs
26
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o kzm.o
30
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_DIGIC) += digic.o
27
obj-$(CONFIG_FSL_IMX6) += fsl-imx6.o sabrelite.o
31
obj-$(CONFIG_OMAP) += omap1.o omap2.o
28
obj-$(CONFIG_ASPEED_SOC) += aspeed_soc.o aspeed.o
32
obj-$(CONFIG_STRONGARM) += strongarm.o
29
obj-$(CONFIG_MPS2) += mps2.o
33
obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o
30
+obj-$(CONFIG_MSF2) += msf2-soc.o
34
+obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3.o
31
diff --git a/include/hw/arm/msf2-soc.h b/include/hw/arm/msf2-soc.h
35
obj-$(CONFIG_RASPI) += bcm2835_peripherals.o bcm2836.o raspi.o
36
obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o
37
obj-$(CONFIG_STM32F405_SOC) += stm32f405_soc.o
38
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
32
new file mode 100644
39
new file mode 100644
33
index XXXXXXX..XXXXXXX
40
index XXXXXXX..XXXXXXX
34
--- /dev/null
41
--- /dev/null
35
+++ b/include/hw/arm/msf2-soc.h
42
+++ b/include/hw/arm/allwinner-h3.h
36
@@ -XXX,XX +XXX,XX @@
43
@@ -XXX,XX +XXX,XX @@
37
+/*
44
+/*
38
+ * Microsemi Smartfusion2 SoC
45
+ * Allwinner H3 System on Chip emulation
39
+ *
46
+ *
40
+ * Copyright (c) 2017 Subbaraya Sundeep <sundeep.lkml@gmail.com>
47
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
41
+ *
48
+ *
42
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
49
+ * This program is free software: you can redistribute it and/or modify
43
+ * of this software and associated documentation files (the "Software"), to deal
50
+ * it under the terms of the GNU General Public License as published by
44
+ * in the Software without restriction, including without limitation the rights
51
+ * the Free Software Foundation, either version 2 of the License, or
45
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
52
+ * (at your option) any later version.
46
+ * copies of the Software, and to permit persons to whom the Software is
53
+ *
47
+ * furnished to do so, subject to the following conditions:
54
+ * This program is distributed in the hope that it will be useful,
48
+ *
55
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
49
+ * The above copyright notice and this permission notice shall be included in
56
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50
+ * all copies or substantial portions of the Software.
57
+ * GNU General Public License for more details.
51
+ *
58
+ *
52
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
59
+ * You should have received a copy of the GNU General Public License
53
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
60
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
54
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
55
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
56
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
57
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
58
+ * THE SOFTWARE.
59
+ */
61
+ */
60
+
62
+
61
+#ifndef HW_ARM_MSF2_SOC_H
62
+#define HW_ARM_MSF2_SOC_H
63
+
64
+#include "hw/arm/armv7m.h"
65
+#include "hw/timer/mss-timer.h"
66
+#include "hw/misc/msf2-sysreg.h"
67
+#include "hw/ssi/mss-spi.h"
68
+
69
+#define TYPE_MSF2_SOC "msf2-soc"
70
+#define MSF2_SOC(obj) OBJECT_CHECK(MSF2State, (obj), TYPE_MSF2_SOC)
71
+
72
+#define MSF2_NUM_SPIS 2
73
+#define MSF2_NUM_UARTS 2
74
+
75
+/*
63
+/*
76
+ * System timer consists of two programmable 32-bit
64
+ * The Allwinner H3 is a System on Chip containing four ARM Cortex A7
77
+ * decrementing counters that generate individual interrupts to
65
+ * processor cores. Features and specifications include DDR2/DDR3 memory,
78
+ * the Cortex-M3 processor
66
+ * SD/MMC storage cards, 10/100/1000Mbit Ethernet, USB 2.0, HDMI and
67
+ * various I/O modules.
68
+ *
69
+ * This implementation is based on the following datasheet:
70
+ *
71
+ * https://linux-sunxi.org/File:Allwinner_H3_Datasheet_V1.2.pdf
72
+ *
73
+ * The latest datasheet and more info can be found on the Linux Sunxi wiki:
74
+ *
75
+ * https://linux-sunxi.org/H3
79
+ */
76
+ */
80
+#define MSF2_NUM_TIMERS 2
77
+
81
+
78
+#ifndef HW_ARM_ALLWINNER_H3_H
82
+typedef struct MSF2State {
79
+#define HW_ARM_ALLWINNER_H3_H
80
+
81
+#include "qom/object.h"
82
+#include "hw/arm/boot.h"
83
+#include "hw/timer/allwinner-a10-pit.h"
84
+#include "hw/intc/arm_gic.h"
85
+#include "target/arm/cpu.h"
86
+
87
+/**
88
+ * Allwinner H3 device list
89
+ *
90
+ * This enumeration is can be used refer to a particular device in the
91
+ * Allwinner H3 SoC. For example, the physical memory base address for
92
+ * each device can be found in the AwH3State object in the memmap member
93
+ * using the device enum value as index.
94
+ *
95
+ * @see AwH3State
96
+ */
97
+enum {
98
+ AW_H3_SRAM_A1,
99
+ AW_H3_SRAM_A2,
100
+ AW_H3_SRAM_C,
101
+ AW_H3_PIT,
102
+ AW_H3_UART0,
103
+ AW_H3_UART1,
104
+ AW_H3_UART2,
105
+ AW_H3_UART3,
106
+ AW_H3_GIC_DIST,
107
+ AW_H3_GIC_CPU,
108
+ AW_H3_GIC_HYP,
109
+ AW_H3_GIC_VCPU,
110
+ AW_H3_SDRAM
111
+};
112
+
113
+/** Total number of CPU cores in the H3 SoC */
114
+#define AW_H3_NUM_CPUS (4)
115
+
116
+/**
117
+ * Allwinner H3 object model
118
+ * @{
119
+ */
120
+
121
+/** Object type for the Allwinner H3 SoC */
122
+#define TYPE_AW_H3 "allwinner-h3"
123
+
124
+/** Convert input object to Allwinner H3 state object */
125
+#define AW_H3(obj) OBJECT_CHECK(AwH3State, (obj), TYPE_AW_H3)
126
+
127
+/** @} */
128
+
129
+/**
130
+ * Allwinner H3 object
131
+ *
132
+ * This struct contains the state of all the devices
133
+ * which are currently emulated by the H3 SoC code.
134
+ */
135
+typedef struct AwH3State {
83
+ /*< private >*/
136
+ /*< private >*/
84
+ SysBusDevice parent_obj;
137
+ DeviceState parent_obj;
85
+ /*< public >*/
138
+ /*< public >*/
86
+
139
+
87
+ ARMv7MState armv7m;
140
+ ARMCPU cpus[AW_H3_NUM_CPUS];
88
+
141
+ const hwaddr *memmap;
89
+ char *cpu_type;
142
+ AwA10PITState timer;
90
+ char *part_name;
143
+ GICState gic;
91
+ uint64_t envm_size;
144
+ MemoryRegion sram_a1;
92
+ uint64_t esram_size;
145
+ MemoryRegion sram_a2;
93
+
146
+ MemoryRegion sram_c;
94
+ uint32_t m3clk;
147
+} AwH3State;
95
+ uint8_t apb0div;
148
+
96
+ uint8_t apb1div;
149
+#endif /* HW_ARM_ALLWINNER_H3_H */
97
+
150
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
98
+ MSF2SysregState sysreg;
99
+ MSSTimerState timer;
100
+ MSSSpiState spi[MSF2_NUM_SPIS];
101
+} MSF2State;
102
+
103
+#endif
104
diff --git a/hw/arm/msf2-soc.c b/hw/arm/msf2-soc.c
105
new file mode 100644
151
new file mode 100644
106
index XXXXXXX..XXXXXXX
152
index XXXXXXX..XXXXXXX
107
--- /dev/null
153
--- /dev/null
108
+++ b/hw/arm/msf2-soc.c
154
+++ b/hw/arm/allwinner-h3.c
109
@@ -XXX,XX +XXX,XX @@
155
@@ -XXX,XX +XXX,XX @@
110
+/*
156
+/*
111
+ * SmartFusion2 SoC emulation.
157
+ * Allwinner H3 System on Chip emulation
112
+ *
158
+ *
113
+ * Copyright (c) 2017 Subbaraya Sundeep <sundeep.lkml@gmail.com>
159
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
114
+ *
160
+ *
115
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
161
+ * This program is free software: you can redistribute it and/or modify
116
+ * of this software and associated documentation files (the "Software"), to deal
162
+ * it under the terms of the GNU General Public License as published by
117
+ * in the Software without restriction, including without limitation the rights
163
+ * the Free Software Foundation, either version 2 of the License, or
118
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
164
+ * (at your option) any later version.
119
+ * copies of the Software, and to permit persons to whom the Software is
165
+ *
120
+ * furnished to do so, subject to the following conditions:
166
+ * This program is distributed in the hope that it will be useful,
121
+ *
167
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
122
+ * The above copyright notice and this permission notice shall be included in
168
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
123
+ * all copies or substantial portions of the Software.
169
+ * GNU General Public License for more details.
124
+ *
170
+ *
125
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
171
+ * You should have received a copy of the GNU General Public License
126
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
172
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
127
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
128
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
129
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
130
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
131
+ * THE SOFTWARE.
132
+ */
173
+ */
133
+
174
+
134
+#include "qemu/osdep.h"
175
+#include "qemu/osdep.h"
176
+#include "exec/address-spaces.h"
135
+#include "qapi/error.h"
177
+#include "qapi/error.h"
136
+#include "qemu-common.h"
178
+#include "qemu/error-report.h"
137
+#include "hw/arm/arm.h"
179
+#include "qemu/module.h"
138
+#include "exec/address-spaces.h"
180
+#include "qemu/units.h"
181
+#include "hw/qdev-core.h"
182
+#include "cpu.h"
183
+#include "hw/sysbus.h"
139
+#include "hw/char/serial.h"
184
+#include "hw/char/serial.h"
140
+#include "hw/boards.h"
141
+#include "sysemu/block-backend.h"
142
+#include "qemu/cutils.h"
143
+#include "hw/arm/msf2-soc.h"
144
+#include "hw/misc/unimp.h"
185
+#include "hw/misc/unimp.h"
145
+
186
+#include "sysemu/sysemu.h"
146
+#define MSF2_TIMER_BASE 0x40004000
187
+#include "hw/arm/allwinner-h3.h"
147
+#define MSF2_SYSREG_BASE 0x40038000
188
+
148
+
189
+/* Memory map */
149
+#define ENVM_BASE_ADDRESS 0x60000000
190
+const hwaddr allwinner_h3_memmap[] = {
150
+
191
+ [AW_H3_SRAM_A1] = 0x00000000,
151
+#define SRAM_BASE_ADDRESS 0x20000000
192
+ [AW_H3_SRAM_A2] = 0x00044000,
152
+
193
+ [AW_H3_SRAM_C] = 0x00010000,
153
+#define MSF2_ENVM_MAX_SIZE (512 * K_BYTE)
194
+ [AW_H3_PIT] = 0x01c20c00,
154
+
195
+ [AW_H3_UART0] = 0x01c28000,
155
+/*
196
+ [AW_H3_UART1] = 0x01c28400,
156
+ * eSRAM max size is 80k without SECDED(Single error correction and
197
+ [AW_H3_UART2] = 0x01c28800,
157
+ * dual error detection) feature and 64k with SECDED.
198
+ [AW_H3_UART3] = 0x01c28c00,
158
+ * We do not support SECDED now.
199
+ [AW_H3_GIC_DIST] = 0x01c81000,
159
+ */
200
+ [AW_H3_GIC_CPU] = 0x01c82000,
160
+#define MSF2_ESRAM_MAX_SIZE (80 * K_BYTE)
201
+ [AW_H3_GIC_HYP] = 0x01c84000,
161
+
202
+ [AW_H3_GIC_VCPU] = 0x01c86000,
162
+static const uint32_t spi_addr[MSF2_NUM_SPIS] = { 0x40001000 , 0x40011000 };
203
+ [AW_H3_SDRAM] = 0x40000000
163
+static const uint32_t uart_addr[MSF2_NUM_UARTS] = { 0x40000000 , 0x40010000 };
204
+};
164
+
205
+
165
+static const int spi_irq[MSF2_NUM_SPIS] = { 2, 3 };
206
+/* List of unimplemented devices */
166
+static const int uart_irq[MSF2_NUM_UARTS] = { 10, 11 };
207
+struct AwH3Unimplemented {
167
+static const int timer_irq[MSF2_NUM_TIMERS] = { 14, 15 };
208
+ const char *device_name;
168
+
209
+ hwaddr base;
169
+static void m2sxxx_soc_initfn(Object *obj)
210
+ hwaddr size;
211
+} unimplemented[] = {
212
+ { "d-engine", 0x01000000, 4 * MiB },
213
+ { "d-inter", 0x01400000, 128 * KiB },
214
+ { "syscon", 0x01c00000, 4 * KiB },
215
+ { "dma", 0x01c02000, 4 * KiB },
216
+ { "nfdc", 0x01c03000, 4 * KiB },
217
+ { "ts", 0x01c06000, 4 * KiB },
218
+ { "keymem", 0x01c0b000, 4 * KiB },
219
+ { "lcd0", 0x01c0c000, 4 * KiB },
220
+ { "lcd1", 0x01c0d000, 4 * KiB },
221
+ { "ve", 0x01c0e000, 4 * KiB },
222
+ { "mmc0", 0x01c0f000, 4 * KiB },
223
+ { "mmc1", 0x01c10000, 4 * KiB },
224
+ { "mmc2", 0x01c11000, 4 * KiB },
225
+ { "sid", 0x01c14000, 1 * KiB },
226
+ { "crypto", 0x01c15000, 4 * KiB },
227
+ { "msgbox", 0x01c17000, 4 * KiB },
228
+ { "spinlock", 0x01c18000, 4 * KiB },
229
+ { "usb0-otg", 0x01c19000, 4 * KiB },
230
+ { "usb0-phy", 0x01c1a000, 4 * KiB },
231
+ { "usb1-phy", 0x01c1b000, 4 * KiB },
232
+ { "usb2-phy", 0x01c1c000, 4 * KiB },
233
+ { "usb3-phy", 0x01c1d000, 4 * KiB },
234
+ { "smc", 0x01c1e000, 4 * KiB },
235
+ { "ccu", 0x01c20000, 1 * KiB },
236
+ { "pio", 0x01c20800, 1 * KiB },
237
+ { "owa", 0x01c21000, 1 * KiB },
238
+ { "pwm", 0x01c21400, 1 * KiB },
239
+ { "keyadc", 0x01c21800, 1 * KiB },
240
+ { "pcm0", 0x01c22000, 1 * KiB },
241
+ { "pcm1", 0x01c22400, 1 * KiB },
242
+ { "pcm2", 0x01c22800, 1 * KiB },
243
+ { "audio", 0x01c22c00, 2 * KiB },
244
+ { "smta", 0x01c23400, 1 * KiB },
245
+ { "ths", 0x01c25000, 1 * KiB },
246
+ { "uart0", 0x01c28000, 1 * KiB },
247
+ { "uart1", 0x01c28400, 1 * KiB },
248
+ { "uart2", 0x01c28800, 1 * KiB },
249
+ { "uart3", 0x01c28c00, 1 * KiB },
250
+ { "twi0", 0x01c2ac00, 1 * KiB },
251
+ { "twi1", 0x01c2b000, 1 * KiB },
252
+ { "twi2", 0x01c2b400, 1 * KiB },
253
+ { "scr", 0x01c2c400, 1 * KiB },
254
+ { "emac", 0x01c30000, 64 * KiB },
255
+ { "gpu", 0x01c40000, 64 * KiB },
256
+ { "hstmr", 0x01c60000, 4 * KiB },
257
+ { "dramcom", 0x01c62000, 4 * KiB },
258
+ { "dramctl0", 0x01c63000, 4 * KiB },
259
+ { "dramphy0", 0x01c65000, 4 * KiB },
260
+ { "spi0", 0x01c68000, 4 * KiB },
261
+ { "spi1", 0x01c69000, 4 * KiB },
262
+ { "csi", 0x01cb0000, 320 * KiB },
263
+ { "tve", 0x01e00000, 64 * KiB },
264
+ { "hdmi", 0x01ee0000, 128 * KiB },
265
+ { "rtc", 0x01f00000, 1 * KiB },
266
+ { "r_timer", 0x01f00800, 1 * KiB },
267
+ { "r_intc", 0x01f00c00, 1 * KiB },
268
+ { "r_wdog", 0x01f01000, 1 * KiB },
269
+ { "r_prcm", 0x01f01400, 1 * KiB },
270
+ { "r_twd", 0x01f01800, 1 * KiB },
271
+ { "r_cpucfg", 0x01f01c00, 1 * KiB },
272
+ { "r_cir-rx", 0x01f02000, 1 * KiB },
273
+ { "r_twi", 0x01f02400, 1 * KiB },
274
+ { "r_uart", 0x01f02800, 1 * KiB },
275
+ { "r_pio", 0x01f02c00, 1 * KiB },
276
+ { "r_pwm", 0x01f03800, 1 * KiB },
277
+ { "core-dbg", 0x3f500000, 128 * KiB },
278
+ { "tsgen-ro", 0x3f506000, 4 * KiB },
279
+ { "tsgen-ctl", 0x3f507000, 4 * KiB },
280
+ { "ddr-mem", 0x40000000, 2 * GiB },
281
+ { "n-brom", 0xffff0000, 32 * KiB },
282
+ { "s-brom", 0xffff0000, 64 * KiB }
283
+};
284
+
285
+/* Per Processor Interrupts */
286
+enum {
287
+ AW_H3_GIC_PPI_MAINT = 9,
288
+ AW_H3_GIC_PPI_HYPTIMER = 10,
289
+ AW_H3_GIC_PPI_VIRTTIMER = 11,
290
+ AW_H3_GIC_PPI_SECTIMER = 13,
291
+ AW_H3_GIC_PPI_PHYSTIMER = 14
292
+};
293
+
294
+/* Shared Processor Interrupts */
295
+enum {
296
+ AW_H3_GIC_SPI_UART0 = 0,
297
+ AW_H3_GIC_SPI_UART1 = 1,
298
+ AW_H3_GIC_SPI_UART2 = 2,
299
+ AW_H3_GIC_SPI_UART3 = 3,
300
+ AW_H3_GIC_SPI_TIMER0 = 18,
301
+ AW_H3_GIC_SPI_TIMER1 = 19,
302
+};
303
+
304
+/* Allwinner H3 general constants */
305
+enum {
306
+ AW_H3_GIC_NUM_SPI = 128
307
+};
308
+
309
+static void allwinner_h3_init(Object *obj)
170
+{
310
+{
171
+ MSF2State *s = MSF2_SOC(obj);
311
+ AwH3State *s = AW_H3(obj);
172
+ int i;
312
+
173
+
313
+ s->memmap = allwinner_h3_memmap;
174
+ object_initialize(&s->armv7m, sizeof(s->armv7m), TYPE_ARMV7M);
314
+
175
+ qdev_set_parent_bus(DEVICE(&s->armv7m), sysbus_get_default());
315
+ for (int i = 0; i < AW_H3_NUM_CPUS; i++) {
176
+
316
+ object_initialize_child(obj, "cpu[*]", &s->cpus[i], sizeof(s->cpus[i]),
177
+ object_initialize(&s->sysreg, sizeof(s->sysreg), TYPE_MSF2_SYSREG);
317
+ ARM_CPU_TYPE_NAME("cortex-a7"),
178
+ qdev_set_parent_bus(DEVICE(&s->sysreg), sysbus_get_default());
318
+ &error_abort, NULL);
179
+
319
+ }
180
+ object_initialize(&s->timer, sizeof(s->timer), TYPE_MSS_TIMER);
320
+
181
+ qdev_set_parent_bus(DEVICE(&s->timer), sysbus_get_default());
321
+ sysbus_init_child_obj(obj, "gic", &s->gic, sizeof(s->gic),
182
+
322
+ TYPE_ARM_GIC);
183
+ for (i = 0; i < MSF2_NUM_SPIS; i++) {
323
+
184
+ object_initialize(&s->spi[i], sizeof(s->spi[i]),
324
+ sysbus_init_child_obj(obj, "timer", &s->timer, sizeof(s->timer),
185
+ TYPE_MSS_SPI);
325
+ TYPE_AW_A10_PIT);
186
+ qdev_set_parent_bus(DEVICE(&s->spi[i]), sysbus_get_default());
326
+ object_property_add_alias(obj, "clk0-freq", OBJECT(&s->timer),
327
+ "clk0-freq", &error_abort);
328
+ object_property_add_alias(obj, "clk1-freq", OBJECT(&s->timer),
329
+ "clk1-freq", &error_abort);
330
+}
331
+
332
+static void allwinner_h3_realize(DeviceState *dev, Error **errp)
333
+{
334
+ AwH3State *s = AW_H3(dev);
335
+ unsigned i;
336
+
337
+ /* CPUs */
338
+ for (i = 0; i < AW_H3_NUM_CPUS; i++) {
339
+
340
+ /* Provide Power State Coordination Interface */
341
+ qdev_prop_set_int32(DEVICE(&s->cpus[i]), "psci-conduit",
342
+ QEMU_PSCI_CONDUIT_HVC);
343
+
344
+ /* Disable secondary CPUs */
345
+ qdev_prop_set_bit(DEVICE(&s->cpus[i]), "start-powered-off",
346
+ i > 0);
347
+
348
+ /* All exception levels required */
349
+ qdev_prop_set_bit(DEVICE(&s->cpus[i]), "has_el3", true);
350
+ qdev_prop_set_bit(DEVICE(&s->cpus[i]), "has_el2", true);
351
+
352
+ /* Mark realized */
353
+ qdev_init_nofail(DEVICE(&s->cpus[i]));
354
+ }
355
+
356
+ /* Generic Interrupt Controller */
357
+ qdev_prop_set_uint32(DEVICE(&s->gic), "num-irq", AW_H3_GIC_NUM_SPI +
358
+ GIC_INTERNAL);
359
+ qdev_prop_set_uint32(DEVICE(&s->gic), "revision", 2);
360
+ qdev_prop_set_uint32(DEVICE(&s->gic), "num-cpu", AW_H3_NUM_CPUS);
361
+ qdev_prop_set_bit(DEVICE(&s->gic), "has-security-extensions", false);
362
+ qdev_prop_set_bit(DEVICE(&s->gic), "has-virtualization-extensions", true);
363
+ qdev_init_nofail(DEVICE(&s->gic));
364
+
365
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->gic), 0, s->memmap[AW_H3_GIC_DIST]);
366
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->gic), 1, s->memmap[AW_H3_GIC_CPU]);
367
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->gic), 2, s->memmap[AW_H3_GIC_HYP]);
368
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->gic), 3, s->memmap[AW_H3_GIC_VCPU]);
369
+
370
+ /*
371
+ * Wire the outputs from each CPU's generic timer and the GICv3
372
+ * maintenance interrupt signal to the appropriate GIC PPI inputs,
373
+ * and the GIC's IRQ/FIQ/VIRQ/VFIQ interrupt outputs to the CPU's inputs.
374
+ */
375
+ for (i = 0; i < AW_H3_NUM_CPUS; i++) {
376
+ DeviceState *cpudev = DEVICE(&s->cpus[i]);
377
+ int ppibase = AW_H3_GIC_NUM_SPI + i * GIC_INTERNAL + GIC_NR_SGIS;
378
+ int irq;
379
+ /*
380
+ * Mapping from the output timer irq lines from the CPU to the
381
+ * GIC PPI inputs used for this board.
382
+ */
383
+ const int timer_irq[] = {
384
+ [GTIMER_PHYS] = AW_H3_GIC_PPI_PHYSTIMER,
385
+ [GTIMER_VIRT] = AW_H3_GIC_PPI_VIRTTIMER,
386
+ [GTIMER_HYP] = AW_H3_GIC_PPI_HYPTIMER,
387
+ [GTIMER_SEC] = AW_H3_GIC_PPI_SECTIMER,
388
+ };
389
+
390
+ /* Connect CPU timer outputs to GIC PPI inputs */
391
+ for (irq = 0; irq < ARRAY_SIZE(timer_irq); irq++) {
392
+ qdev_connect_gpio_out(cpudev, irq,
393
+ qdev_get_gpio_in(DEVICE(&s->gic),
394
+ ppibase + timer_irq[irq]));
395
+ }
396
+
397
+ /* Connect GIC outputs to CPU interrupt inputs */
398
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i,
399
+ qdev_get_gpio_in(cpudev, ARM_CPU_IRQ));
400
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i + AW_H3_NUM_CPUS,
401
+ qdev_get_gpio_in(cpudev, ARM_CPU_FIQ));
402
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i + (2 * AW_H3_NUM_CPUS),
403
+ qdev_get_gpio_in(cpudev, ARM_CPU_VIRQ));
404
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i + (3 * AW_H3_NUM_CPUS),
405
+ qdev_get_gpio_in(cpudev, ARM_CPU_VFIQ));
406
+
407
+ /* GIC maintenance signal */
408
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i + (4 * AW_H3_NUM_CPUS),
409
+ qdev_get_gpio_in(DEVICE(&s->gic),
410
+ ppibase + AW_H3_GIC_PPI_MAINT));
411
+ }
412
+
413
+ /* Timer */
414
+ qdev_init_nofail(DEVICE(&s->timer));
415
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->timer), 0, s->memmap[AW_H3_PIT]);
416
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->timer), 0,
417
+ qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_TIMER0));
418
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->timer), 1,
419
+ qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_TIMER1));
420
+
421
+ /* SRAM */
422
+ memory_region_init_ram(&s->sram_a1, OBJECT(dev), "sram A1",
423
+ 64 * KiB, &error_abort);
424
+ memory_region_init_ram(&s->sram_a2, OBJECT(dev), "sram A2",
425
+ 32 * KiB, &error_abort);
426
+ memory_region_init_ram(&s->sram_c, OBJECT(dev), "sram C",
427
+ 44 * KiB, &error_abort);
428
+ memory_region_add_subregion(get_system_memory(), s->memmap[AW_H3_SRAM_A1],
429
+ &s->sram_a1);
430
+ memory_region_add_subregion(get_system_memory(), s->memmap[AW_H3_SRAM_A2],
431
+ &s->sram_a2);
432
+ memory_region_add_subregion(get_system_memory(), s->memmap[AW_H3_SRAM_C],
433
+ &s->sram_c);
434
+
435
+ /* UART0. For future clocktree API: All UARTS are connected to APB2_CLK. */
436
+ serial_mm_init(get_system_memory(), s->memmap[AW_H3_UART0], 2,
437
+ qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_UART0),
438
+ 115200, serial_hd(0), DEVICE_NATIVE_ENDIAN);
439
+ /* UART1 */
440
+ serial_mm_init(get_system_memory(), s->memmap[AW_H3_UART1], 2,
441
+ qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_UART1),
442
+ 115200, serial_hd(1), DEVICE_NATIVE_ENDIAN);
443
+ /* UART2 */
444
+ serial_mm_init(get_system_memory(), s->memmap[AW_H3_UART2], 2,
445
+ qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_UART2),
446
+ 115200, serial_hd(2), DEVICE_NATIVE_ENDIAN);
447
+ /* UART3 */
448
+ serial_mm_init(get_system_memory(), s->memmap[AW_H3_UART3], 2,
449
+ qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_UART3),
450
+ 115200, serial_hd(3), DEVICE_NATIVE_ENDIAN);
451
+
452
+ /* Unimplemented devices */
453
+ for (i = 0; i < ARRAY_SIZE(unimplemented); i++) {
454
+ create_unimplemented_device(unimplemented[i].device_name,
455
+ unimplemented[i].base,
456
+ unimplemented[i].size);
187
+ }
457
+ }
188
+}
458
+}
189
+
459
+
190
+static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp)
460
+static void allwinner_h3_class_init(ObjectClass *oc, void *data)
191
+{
461
+{
192
+ MSF2State *s = MSF2_SOC(dev_soc);
462
+ DeviceClass *dc = DEVICE_CLASS(oc);
193
+ DeviceState *dev, *armv7m;
463
+
194
+ SysBusDevice *busdev;
464
+ dc->realize = allwinner_h3_realize;
195
+ Error *err = NULL;
465
+ /* Reason: uses serial_hd() in realize function */
196
+ int i;
466
+ dc->user_creatable = false;
197
+
198
+ MemoryRegion *system_memory = get_system_memory();
199
+ MemoryRegion *nvm = g_new(MemoryRegion, 1);
200
+ MemoryRegion *nvm_alias = g_new(MemoryRegion, 1);
201
+ MemoryRegion *sram = g_new(MemoryRegion, 1);
202
+
203
+ memory_region_init_rom(nvm, NULL, "MSF2.eNVM", s->envm_size,
204
+ &error_fatal);
205
+ /*
206
+ * On power-on, the eNVM region 0x60000000 is automatically
207
+ * remapped to the Cortex-M3 processor executable region
208
+ * start address (0x0). We do not support remapping other eNVM,
209
+ * eSRAM and DDR regions by guest(via Sysreg) currently.
210
+ */
211
+ memory_region_init_alias(nvm_alias, NULL, "MSF2.eNVM",
212
+ nvm, 0, s->envm_size);
213
+
214
+ memory_region_add_subregion(system_memory, ENVM_BASE_ADDRESS, nvm);
215
+ memory_region_add_subregion(system_memory, 0, nvm_alias);
216
+
217
+ memory_region_init_ram(sram, NULL, "MSF2.eSRAM", s->esram_size,
218
+ &error_fatal);
219
+ memory_region_add_subregion(system_memory, SRAM_BASE_ADDRESS, sram);
220
+
221
+ armv7m = DEVICE(&s->armv7m);
222
+ qdev_prop_set_uint32(armv7m, "num-irq", 81);
223
+ qdev_prop_set_string(armv7m, "cpu-type", s->cpu_type);
224
+ object_property_set_link(OBJECT(&s->armv7m), OBJECT(get_system_memory()),
225
+ "memory", &error_abort);
226
+ object_property_set_bool(OBJECT(&s->armv7m), true, "realized", &err);
227
+ if (err != NULL) {
228
+ error_propagate(errp, err);
229
+ return;
230
+ }
231
+
232
+ if (!s->m3clk) {
233
+ error_setg(errp, "Invalid m3clk value");
234
+ error_append_hint(errp, "m3clk can not be zero\n");
235
+ return;
236
+ }
237
+ system_clock_scale = NANOSECONDS_PER_SECOND / s->m3clk;
238
+
239
+ for (i = 0; i < MSF2_NUM_UARTS; i++) {
240
+ if (serial_hds[i]) {
241
+ serial_mm_init(get_system_memory(), uart_addr[i], 2,
242
+ qdev_get_gpio_in(armv7m, uart_irq[i]),
243
+ 115200, serial_hds[i], DEVICE_NATIVE_ENDIAN);
244
+ }
245
+ }
246
+
247
+ dev = DEVICE(&s->timer);
248
+ /* APB0 clock is the timer input clock */
249
+ qdev_prop_set_uint32(dev, "clock-frequency", s->m3clk / s->apb0div);
250
+ object_property_set_bool(OBJECT(&s->timer), true, "realized", &err);
251
+ if (err != NULL) {
252
+ error_propagate(errp, err);
253
+ return;
254
+ }
255
+ busdev = SYS_BUS_DEVICE(dev);
256
+ sysbus_mmio_map(busdev, 0, MSF2_TIMER_BASE);
257
+ sysbus_connect_irq(busdev, 0,
258
+ qdev_get_gpio_in(armv7m, timer_irq[0]));
259
+ sysbus_connect_irq(busdev, 1,
260
+ qdev_get_gpio_in(armv7m, timer_irq[1]));
261
+
262
+ dev = DEVICE(&s->sysreg);
263
+ qdev_prop_set_uint32(dev, "apb0divisor", s->apb0div);
264
+ qdev_prop_set_uint32(dev, "apb1divisor", s->apb1div);
265
+ object_property_set_bool(OBJECT(&s->sysreg), true, "realized", &err);
266
+ if (err != NULL) {
267
+ error_propagate(errp, err);
268
+ return;
269
+ }
270
+ busdev = SYS_BUS_DEVICE(dev);
271
+ sysbus_mmio_map(busdev, 0, MSF2_SYSREG_BASE);
272
+
273
+ for (i = 0; i < MSF2_NUM_SPIS; i++) {
274
+ gchar *bus_name;
275
+
276
+ object_property_set_bool(OBJECT(&s->spi[i]), true, "realized", &err);
277
+ if (err != NULL) {
278
+ error_propagate(errp, err);
279
+ return;
280
+ }
281
+
282
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi[i]), 0, spi_addr[i]);
283
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->spi[i]), 0,
284
+ qdev_get_gpio_in(armv7m, spi_irq[i]));
285
+
286
+ /* Alias controller SPI bus to the SoC itself */
287
+ bus_name = g_strdup_printf("spi%d", i);
288
+ object_property_add_alias(OBJECT(s), bus_name,
289
+ OBJECT(&s->spi[i]), "spi",
290
+ &error_abort);
291
+ g_free(bus_name);
292
+ }
293
+
294
+ /* Below devices are not modelled yet. */
295
+ create_unimplemented_device("i2c_0", 0x40002000, 0x1000);
296
+ create_unimplemented_device("dma", 0x40003000, 0x1000);
297
+ create_unimplemented_device("watchdog", 0x40005000, 0x1000);
298
+ create_unimplemented_device("i2c_1", 0x40012000, 0x1000);
299
+ create_unimplemented_device("gpio", 0x40013000, 0x1000);
300
+ create_unimplemented_device("hs-dma", 0x40014000, 0x1000);
301
+ create_unimplemented_device("can", 0x40015000, 0x1000);
302
+ create_unimplemented_device("rtc", 0x40017000, 0x1000);
303
+ create_unimplemented_device("apb_config", 0x40020000, 0x10000);
304
+ create_unimplemented_device("emac", 0x40041000, 0x1000);
305
+ create_unimplemented_device("usb", 0x40043000, 0x1000);
306
+}
467
+}
307
+
468
+
308
+static Property m2sxxx_soc_properties[] = {
469
+static const TypeInfo allwinner_h3_type_info = {
309
+ /*
470
+ .name = TYPE_AW_H3,
310
+ * part name specifies the type of SmartFusion2 device variant(this
471
+ .parent = TYPE_DEVICE,
311
+ * property is for information purpose only.
472
+ .instance_size = sizeof(AwH3State),
312
+ */
473
+ .instance_init = allwinner_h3_init,
313
+ DEFINE_PROP_STRING("cpu-type", MSF2State, cpu_type),
474
+ .class_init = allwinner_h3_class_init,
314
+ DEFINE_PROP_STRING("part-name", MSF2State, part_name),
475
+};
315
+ DEFINE_PROP_UINT64("eNVM-size", MSF2State, envm_size, MSF2_ENVM_MAX_SIZE),
476
+
316
+ DEFINE_PROP_UINT64("eSRAM-size", MSF2State, esram_size,
477
+static void allwinner_h3_register_types(void)
317
+ MSF2_ESRAM_MAX_SIZE),
318
+ /* Libero GUI shows 100Mhz as default for clocks */
319
+ DEFINE_PROP_UINT32("m3clk", MSF2State, m3clk, 100 * 1000000),
320
+ /* default divisors in Libero GUI */
321
+ DEFINE_PROP_UINT8("apb0div", MSF2State, apb0div, 2),
322
+ DEFINE_PROP_UINT8("apb1div", MSF2State, apb1div, 2),
323
+ DEFINE_PROP_END_OF_LIST(),
324
+};
325
+
326
+static void m2sxxx_soc_class_init(ObjectClass *klass, void *data)
327
+{
478
+{
328
+ DeviceClass *dc = DEVICE_CLASS(klass);
479
+ type_register_static(&allwinner_h3_type_info);
329
+
330
+ dc->realize = m2sxxx_soc_realize;
331
+ dc->props = m2sxxx_soc_properties;
332
+}
480
+}
333
+
481
+
334
+static const TypeInfo m2sxxx_soc_info = {
482
+type_init(allwinner_h3_register_types)
335
+ .name = TYPE_MSF2_SOC,
483
diff --git a/MAINTAINERS b/MAINTAINERS
336
+ .parent = TYPE_SYS_BUS_DEVICE,
484
index XXXXXXX..XXXXXXX 100644
337
+ .instance_size = sizeof(MSF2State),
485
--- a/MAINTAINERS
338
+ .instance_init = m2sxxx_soc_initfn,
486
+++ b/MAINTAINERS
339
+ .class_init = m2sxxx_soc_class_init,
487
@@ -XXX,XX +XXX,XX @@ F: hw/*/allwinner*
340
+};
488
F: include/hw/*/allwinner*
341
+
489
F: hw/arm/cubieboard.c
342
+static void m2sxxx_soc_types(void)
490
343
+{
491
+Allwinner-h3
344
+ type_register_static(&m2sxxx_soc_info);
492
+M: Niek Linnenbank <nieklinnenbank@gmail.com>
345
+}
493
+L: qemu-arm@nongnu.org
346
+
494
+S: Maintained
347
+type_init(m2sxxx_soc_types)
495
+F: hw/*/allwinner-h3*
496
+F: include/hw/*/allwinner-h3*
497
+
498
ARM PrimeCell and CMSDK devices
499
M: Peter Maydell <peter.maydell@linaro.org>
500
L: qemu-arm@nongnu.org
348
diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
501
diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
349
index XXXXXXX..XXXXXXX 100644
502
index XXXXXXX..XXXXXXX 100644
350
--- a/default-configs/arm-softmmu.mak
503
--- a/default-configs/arm-softmmu.mak
351
+++ b/default-configs/arm-softmmu.mak
504
+++ b/default-configs/arm-softmmu.mak
352
@@ -XXX,XX +XXX,XX @@ CONFIG_ACPI=y
505
@@ -XXX,XX +XXX,XX @@ CONFIG_FSL_IMX25=y
353
CONFIG_SMBIOS=y
506
CONFIG_FSL_IMX7=y
354
CONFIG_ASPEED_SOC=y
507
CONFIG_FSL_IMX6UL=y
355
CONFIG_GPIO_KEY=y
508
CONFIG_SEMIHOSTING=y
356
+CONFIG_MSF2=y
509
+CONFIG_ALLWINNER_H3=y
510
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
511
index XXXXXXX..XXXXXXX 100644
512
--- a/hw/arm/Kconfig
513
+++ b/hw/arm/Kconfig
514
@@ -XXX,XX +XXX,XX @@ config ALLWINNER_A10
515
select SERIAL
516
select UNIMP
517
518
+config ALLWINNER_H3
519
+ bool
520
+ select ALLWINNER_A10_PIT
521
+ select SERIAL
522
+ select ARM_TIMER
523
+ select ARM_GIC
524
+ select UNIMP
525
+
526
config RASPI
527
bool
528
select FRAMEBUFFER
357
--
529
--
358
2.7.4
530
2.20.1
359
531
360
532
diff view generated by jsdifflib
1
From: Subbaraya Sundeep <sundeep.lkml@gmail.com>
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
2
2
3
Emulated Emcraft's Smartfusion2 System On Module starter
3
The Xunlong Orange Pi PC is an Allwinner H3 System on Chip
4
kit.
4
based embedded computer with mainline support in both U-Boot
5
and Linux. The board comes with a Quad Core Cortex A7 @ 1.3GHz,
6
1GiB RAM, 100Mbit ethernet, USB, SD/MMC, USB, HDMI and
7
various other I/O. This commit add support for the Xunlong
8
Orange Pi PC machine.
5
9
6
Signed-off-by: Subbaraya Sundeep <sundeep.lkml@gmail.com>
10
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
7
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
11
Tested-by: KONRAD Frederic <frederic.konrad@adacore.com>
8
Message-id: 20170920201737.25723-6-f4bug@amsat.org
12
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
9
[PMD: drop cpu_model to directly use cpu type]
13
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
14
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
15
Acked-by: Igor Mammedov <imammedo@redhat.com>
16
Message-id: 20200311221854.30370-3-nieklinnenbank@gmail.com
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
18
---
12
hw/arm/Makefile.objs | 2 +-
19
hw/arm/Makefile.objs | 2 +-
13
hw/arm/msf2-som.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++
20
hw/arm/orangepi.c | 92 ++++++++++++++++++++++++++++++++++++++++++++
14
2 files changed, 106 insertions(+), 1 deletion(-)
21
MAINTAINERS | 1 +
15
create mode 100644 hw/arm/msf2-som.c
22
3 files changed, 94 insertions(+), 1 deletion(-)
23
create mode 100644 hw/arm/orangepi.c
16
24
17
diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
25
diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
18
index XXXXXXX..XXXXXXX 100644
26
index XXXXXXX..XXXXXXX 100644
19
--- a/hw/arm/Makefile.objs
27
--- a/hw/arm/Makefile.objs
20
+++ b/hw/arm/Makefile.objs
28
+++ b/hw/arm/Makefile.objs
21
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o kzm.o
29
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_DIGIC) += digic.o
22
obj-$(CONFIG_FSL_IMX6) += fsl-imx6.o sabrelite.o
30
obj-$(CONFIG_OMAP) += omap1.o omap2.o
23
obj-$(CONFIG_ASPEED_SOC) += aspeed_soc.o aspeed.o
31
obj-$(CONFIG_STRONGARM) += strongarm.o
24
obj-$(CONFIG_MPS2) += mps2.o
32
obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o
25
-obj-$(CONFIG_MSF2) += msf2-soc.o
33
-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3.o
26
+obj-$(CONFIG_MSF2) += msf2-soc.o msf2-som.o
34
+obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3.o orangepi.o
27
diff --git a/hw/arm/msf2-som.c b/hw/arm/msf2-som.c
35
obj-$(CONFIG_RASPI) += bcm2835_peripherals.o bcm2836.o raspi.o
36
obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o
37
obj-$(CONFIG_STM32F405_SOC) += stm32f405_soc.o
38
diff --git a/hw/arm/orangepi.c b/hw/arm/orangepi.c
28
new file mode 100644
39
new file mode 100644
29
index XXXXXXX..XXXXXXX
40
index XXXXXXX..XXXXXXX
30
--- /dev/null
41
--- /dev/null
31
+++ b/hw/arm/msf2-som.c
42
+++ b/hw/arm/orangepi.c
32
@@ -XXX,XX +XXX,XX @@
43
@@ -XXX,XX +XXX,XX @@
33
+/*
44
+/*
34
+ * SmartFusion2 SOM starter kit(from Emcraft) emulation.
45
+ * Orange Pi emulation
35
+ *
46
+ *
36
+ * Copyright (c) 2017 Subbaraya Sundeep <sundeep.lkml@gmail.com>
47
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
37
+ *
48
+ *
38
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
49
+ * This program is free software: you can redistribute it and/or modify
39
+ * of this software and associated documentation files (the "Software"), to deal
50
+ * it under the terms of the GNU General Public License as published by
40
+ * in the Software without restriction, including without limitation the rights
51
+ * the Free Software Foundation, either version 2 of the License, or
41
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
52
+ * (at your option) any later version.
42
+ * copies of the Software, and to permit persons to whom the Software is
43
+ * furnished to do so, subject to the following conditions:
44
+ *
53
+ *
45
+ * The above copyright notice and this permission notice shall be included in
54
+ * This program is distributed in the hope that it will be useful,
46
+ * all copies or substantial portions of the Software.
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.
47
+ *
58
+ *
48
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
59
+ * You should have received a copy of the GNU General Public License
49
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
60
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
50
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
51
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
52
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
53
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
54
+ * THE SOFTWARE.
55
+ */
61
+ */
56
+
62
+
57
+#include "qemu/osdep.h"
63
+#include "qemu/osdep.h"
64
+#include "qemu/units.h"
65
+#include "exec/address-spaces.h"
58
+#include "qapi/error.h"
66
+#include "qapi/error.h"
59
+#include "qemu/error-report.h"
67
+#include "cpu.h"
68
+#include "hw/sysbus.h"
60
+#include "hw/boards.h"
69
+#include "hw/boards.h"
61
+#include "hw/arm/arm.h"
70
+#include "hw/qdev-properties.h"
62
+#include "exec/address-spaces.h"
71
+#include "hw/arm/allwinner-h3.h"
63
+#include "qemu/cutils.h"
72
+#include "sysemu/sysemu.h"
64
+#include "hw/arm/msf2-soc.h"
65
+#include "cpu.h"
66
+
73
+
67
+#define DDR_BASE_ADDRESS 0xA0000000
74
+static struct arm_boot_info orangepi_binfo = {
68
+#define DDR_SIZE (64 * M_BYTE)
75
+ .nb_cpus = AW_H3_NUM_CPUS,
76
+};
69
+
77
+
70
+#define M2S010_ENVM_SIZE (256 * K_BYTE)
78
+static void orangepi_init(MachineState *machine)
71
+#define M2S010_ESRAM_SIZE (64 * K_BYTE)
79
+{
80
+ AwH3State *h3;
72
+
81
+
73
+static void emcraft_sf2_s2s010_init(MachineState *machine)
82
+ /* BIOS is not supported by this board */
74
+{
83
+ if (bios_name) {
75
+ DeviceState *dev;
84
+ error_report("BIOS not supported for this machine");
76
+ DeviceState *spi_flash;
85
+ exit(1);
77
+ MSF2State *soc;
78
+ MachineClass *mc = MACHINE_GET_CLASS(machine);
79
+ DriveInfo *dinfo = drive_get_next(IF_MTD);
80
+ qemu_irq cs_line;
81
+ SSIBus *spi_bus;
82
+ MemoryRegion *sysmem = get_system_memory();
83
+ MemoryRegion *ddr = g_new(MemoryRegion, 1);
84
+
85
+ if (strcmp(machine->cpu_type, mc->default_cpu_type) != 0) {
86
+ error_report("This board can only be used with CPU %s",
87
+ mc->default_cpu_type);
88
+ }
86
+ }
89
+
87
+
90
+ memory_region_init_ram(ddr, NULL, "ddr-ram", DDR_SIZE,
88
+ /* This board has fixed size RAM */
91
+ &error_fatal);
89
+ if (machine->ram_size != 1 * GiB) {
92
+ memory_region_add_subregion(sysmem, DDR_BASE_ADDRESS, ddr);
90
+ error_report("This machine can only be used with 1GiB of RAM");
91
+ exit(1);
92
+ }
93
+
93
+
94
+ dev = qdev_create(NULL, TYPE_MSF2_SOC);
94
+ /* Only allow Cortex-A7 for this board */
95
+ qdev_prop_set_string(dev, "part-name", "M2S010");
95
+ if (strcmp(machine->cpu_type, ARM_CPU_TYPE_NAME("cortex-a7")) != 0) {
96
+ qdev_prop_set_string(dev, "cpu-type", mc->default_cpu_type);
96
+ error_report("This board can only be used with cortex-a7 CPU");
97
+ exit(1);
98
+ }
97
+
99
+
98
+ qdev_prop_set_uint64(dev, "eNVM-size", M2S010_ENVM_SIZE);
100
+ h3 = AW_H3(object_new(TYPE_AW_H3));
99
+ qdev_prop_set_uint64(dev, "eSRAM-size", M2S010_ESRAM_SIZE);
101
+ object_property_add_child(OBJECT(machine), "soc", OBJECT(h3),
102
+ &error_abort);
103
+ object_unref(OBJECT(h3));
100
+
104
+
101
+ /*
105
+ /* Setup timer properties */
102
+ * CPU clock and peripheral clocks(APB0, APB1)are configurable
106
+ object_property_set_int(OBJECT(h3), 32768, "clk0-freq",
103
+ * in Libero. CPU clock is divided by APB0 and APB1 divisors for
107
+ &error_abort);
104
+ * peripherals. Emcraft's SoM kit comes with these settings by default.
108
+ object_property_set_int(OBJECT(h3), 24 * 1000 * 1000, "clk1-freq",
105
+ */
109
+ &error_abort);
106
+ qdev_prop_set_uint32(dev, "m3clk", 142 * 1000000);
107
+ qdev_prop_set_uint32(dev, "apb0div", 2);
108
+ qdev_prop_set_uint32(dev, "apb1div", 2);
109
+
110
+
110
+ object_property_set_bool(OBJECT(dev), true, "realized", &error_fatal);
111
+ /* Mark H3 object realized */
112
+ object_property_set_bool(OBJECT(h3), true, "realized", &error_abort);
111
+
113
+
112
+ soc = MSF2_SOC(dev);
114
+ /* SDRAM */
115
+ memory_region_add_subregion(get_system_memory(), h3->memmap[AW_H3_SDRAM],
116
+ machine->ram);
113
+
117
+
114
+ /* Attach SPI flash to SPI0 controller */
118
+ orangepi_binfo.loader_start = h3->memmap[AW_H3_SDRAM];
115
+ spi_bus = (SSIBus *)qdev_get_child_bus(dev, "spi0");
119
+ orangepi_binfo.ram_size = machine->ram_size;
116
+ spi_flash = ssi_create_slave_no_init(spi_bus, "s25sl12801");
120
+ arm_load_kernel(ARM_CPU(first_cpu), machine, &orangepi_binfo);
117
+ qdev_prop_set_uint8(spi_flash, "spansion-cr2nv", 1);
118
+ if (dinfo) {
119
+ qdev_prop_set_drive(spi_flash, "drive", blk_by_legacy_dinfo(dinfo),
120
+ &error_fatal);
121
+ }
122
+ qdev_init_nofail(spi_flash);
123
+ cs_line = qdev_get_gpio_in_named(spi_flash, SSI_GPIO_CS, 0);
124
+ sysbus_connect_irq(SYS_BUS_DEVICE(&soc->spi[0]), 1, cs_line);
125
+
126
+ armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename,
127
+ soc->envm_size);
128
+}
121
+}
129
+
122
+
130
+static void emcraft_sf2_machine_init(MachineClass *mc)
123
+static void orangepi_machine_init(MachineClass *mc)
131
+{
124
+{
132
+ mc->desc = "SmartFusion2 SOM kit from Emcraft (M2S010)";
125
+ mc->desc = "Orange Pi PC";
133
+ mc->init = emcraft_sf2_s2s010_init;
126
+ mc->init = orangepi_init;
134
+ mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m3");
127
+ mc->min_cpus = AW_H3_NUM_CPUS;
128
+ mc->max_cpus = AW_H3_NUM_CPUS;
129
+ mc->default_cpus = AW_H3_NUM_CPUS;
130
+ mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a7");
131
+ mc->default_ram_size = 1 * GiB;
132
+ mc->default_ram_id = "orangepi.ram";
135
+}
133
+}
136
+
134
+
137
+DEFINE_MACHINE("emcraft-sf2", emcraft_sf2_machine_init)
135
+DEFINE_MACHINE("orangepi-pc", orangepi_machine_init)
136
diff --git a/MAINTAINERS b/MAINTAINERS
137
index XXXXXXX..XXXXXXX 100644
138
--- a/MAINTAINERS
139
+++ b/MAINTAINERS
140
@@ -XXX,XX +XXX,XX @@ L: qemu-arm@nongnu.org
141
S: Maintained
142
F: hw/*/allwinner-h3*
143
F: include/hw/*/allwinner-h3*
144
+F: hw/arm/orangepi.c
145
146
ARM PrimeCell and CMSDK devices
147
M: Peter Maydell <peter.maydell@linaro.org>
138
--
148
--
139
2.7.4
149
2.20.1
140
150
141
151
diff view generated by jsdifflib
1
Update the nvic_recompute_state() code to handle the security
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
2
extension and its associated banked registers.
3
2
4
Code that uses the resulting cached state (ie the irq
3
The Clock Control Unit is responsible for clock signal generation,
5
acknowledge and complete code) will be updated in a later
4
configuration and distribution in the Allwinner H3 System on Chip.
6
commit.
5
This commit adds support for the Clock Control Unit which emulates
6
a simple read/write register interface.
7
7
8
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
9
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
10
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
11
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
12
Message-id: 20200311221854.30370-4-nieklinnenbank@gmail.com
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
Message-id: 1505240046-11454-9-git-send-email-peter.maydell@linaro.org
11
---
14
---
12
hw/intc/armv7m_nvic.c | 151 ++++++++++++++++++++++++++++++++++++++++++++++++--
15
hw/misc/Makefile.objs | 1 +
13
hw/intc/trace-events | 1 +
16
include/hw/arm/allwinner-h3.h | 3 +
14
2 files changed, 147 insertions(+), 5 deletions(-)
17
include/hw/misc/allwinner-h3-ccu.h | 66 ++++++++
18
hw/arm/allwinner-h3.c | 9 +-
19
hw/misc/allwinner-h3-ccu.c | 242 +++++++++++++++++++++++++++++
20
5 files changed, 320 insertions(+), 1 deletion(-)
21
create mode 100644 include/hw/misc/allwinner-h3-ccu.h
22
create mode 100644 hw/misc/allwinner-h3-ccu.c
15
23
16
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
24
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
17
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/intc/armv7m_nvic.c
26
--- a/hw/misc/Makefile.objs
19
+++ b/hw/intc/armv7m_nvic.c
27
+++ b/hw/misc/Makefile.objs
28
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_MACIO) += macio/
29
30
common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o
31
32
+common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o
33
common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o
34
common-obj-$(CONFIG_NSERIES) += cbus.o
35
common-obj-$(CONFIG_ECCMEMCTL) += eccmemctl.o
36
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
37
index XXXXXXX..XXXXXXX 100644
38
--- a/include/hw/arm/allwinner-h3.h
39
+++ b/include/hw/arm/allwinner-h3.h
20
@@ -XXX,XX +XXX,XX @@
40
@@ -XXX,XX +XXX,XX @@
21
* (higher than the highest possible priority value)
41
#include "hw/arm/boot.h"
22
*/
42
#include "hw/timer/allwinner-a10-pit.h"
23
#define NVIC_NOEXC_PRIO 0x100
43
#include "hw/intc/arm_gic.h"
24
+/* Maximum priority of non-secure exceptions when AIRCR.PRIS is set */
44
+#include "hw/misc/allwinner-h3-ccu.h"
25
+#define NVIC_NS_PRIO_LIMIT 0x80
45
#include "target/arm/cpu.h"
26
46
27
static const uint8_t nvic_id[] = {
47
/**
28
0x00, 0xb0, 0x1b, 0x00, 0x0d, 0xe0, 0x05, 0xb1
48
@@ -XXX,XX +XXX,XX @@ enum {
29
@@ -XXX,XX +XXX,XX @@ static bool nvic_isrpending(NVICState *s)
49
AW_H3_SRAM_A1,
30
return false;
50
AW_H3_SRAM_A2,
51
AW_H3_SRAM_C,
52
+ AW_H3_CCU,
53
AW_H3_PIT,
54
AW_H3_UART0,
55
AW_H3_UART1,
56
@@ -XXX,XX +XXX,XX @@ typedef struct AwH3State {
57
ARMCPU cpus[AW_H3_NUM_CPUS];
58
const hwaddr *memmap;
59
AwA10PITState timer;
60
+ AwH3ClockCtlState ccu;
61
GICState gic;
62
MemoryRegion sram_a1;
63
MemoryRegion sram_a2;
64
diff --git a/include/hw/misc/allwinner-h3-ccu.h b/include/hw/misc/allwinner-h3-ccu.h
65
new file mode 100644
66
index XXXXXXX..XXXXXXX
67
--- /dev/null
68
+++ b/include/hw/misc/allwinner-h3-ccu.h
69
@@ -XXX,XX +XXX,XX @@
70
+/*
71
+ * Allwinner H3 Clock Control Unit emulation
72
+ *
73
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
74
+ *
75
+ * This program is free software: you can redistribute it and/or modify
76
+ * it under the terms of the GNU General Public License as published by
77
+ * the Free Software Foundation, either version 2 of the License, or
78
+ * (at your option) any later version.
79
+ *
80
+ * This program is distributed in the hope that it will be useful,
81
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
82
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
83
+ * GNU General Public License for more details.
84
+ *
85
+ * You should have received a copy of the GNU General Public License
86
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
87
+ */
88
+
89
+#ifndef HW_MISC_ALLWINNER_H3_CCU_H
90
+#define HW_MISC_ALLWINNER_H3_CCU_H
91
+
92
+#include "qom/object.h"
93
+#include "hw/sysbus.h"
94
+
95
+/**
96
+ * @name Constants
97
+ * @{
98
+ */
99
+
100
+/** Size of register I/O address space used by CCU device */
101
+#define AW_H3_CCU_IOSIZE (0x400)
102
+
103
+/** Total number of known registers */
104
+#define AW_H3_CCU_REGS_NUM (AW_H3_CCU_IOSIZE / sizeof(uint32_t))
105
+
106
+/** @} */
107
+
108
+/**
109
+ * @name Object model
110
+ * @{
111
+ */
112
+
113
+#define TYPE_AW_H3_CCU "allwinner-h3-ccu"
114
+#define AW_H3_CCU(obj) \
115
+ OBJECT_CHECK(AwH3ClockCtlState, (obj), TYPE_AW_H3_CCU)
116
+
117
+/** @} */
118
+
119
+/**
120
+ * Allwinner H3 CCU object instance state.
121
+ */
122
+typedef struct AwH3ClockCtlState {
123
+ /*< private >*/
124
+ SysBusDevice parent_obj;
125
+ /*< public >*/
126
+
127
+ /** Maps I/O registers in physical memory */
128
+ MemoryRegion iomem;
129
+
130
+ /** Array of hardware registers */
131
+ uint32_t regs[AW_H3_CCU_REGS_NUM];
132
+
133
+} AwH3ClockCtlState;
134
+
135
+#endif /* HW_MISC_ALLWINNER_H3_CCU_H */
136
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
137
index XXXXXXX..XXXXXXX 100644
138
--- a/hw/arm/allwinner-h3.c
139
+++ b/hw/arm/allwinner-h3.c
140
@@ -XXX,XX +XXX,XX @@ const hwaddr allwinner_h3_memmap[] = {
141
[AW_H3_SRAM_A1] = 0x00000000,
142
[AW_H3_SRAM_A2] = 0x00044000,
143
[AW_H3_SRAM_C] = 0x00010000,
144
+ [AW_H3_CCU] = 0x01c20000,
145
[AW_H3_PIT] = 0x01c20c00,
146
[AW_H3_UART0] = 0x01c28000,
147
[AW_H3_UART1] = 0x01c28400,
148
@@ -XXX,XX +XXX,XX @@ struct AwH3Unimplemented {
149
{ "usb2-phy", 0x01c1c000, 4 * KiB },
150
{ "usb3-phy", 0x01c1d000, 4 * KiB },
151
{ "smc", 0x01c1e000, 4 * KiB },
152
- { "ccu", 0x01c20000, 1 * KiB },
153
{ "pio", 0x01c20800, 1 * KiB },
154
{ "owa", 0x01c21000, 1 * KiB },
155
{ "pwm", 0x01c21400, 1 * KiB },
156
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_init(Object *obj)
157
"clk0-freq", &error_abort);
158
object_property_add_alias(obj, "clk1-freq", OBJECT(&s->timer),
159
"clk1-freq", &error_abort);
160
+
161
+ sysbus_init_child_obj(obj, "ccu", &s->ccu, sizeof(s->ccu),
162
+ TYPE_AW_H3_CCU);
31
}
163
}
32
164
33
+static bool exc_is_banked(int exc)
165
static void allwinner_h3_realize(DeviceState *dev, Error **errp)
34
+{
166
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
35
+ /* Return true if this is one of the limited set of exceptions which
167
memory_region_add_subregion(get_system_memory(), s->memmap[AW_H3_SRAM_C],
36
+ * are banked (and thus have state in sec_vectors[])
168
&s->sram_c);
37
+ */
169
38
+ return exc == ARMV7M_EXCP_HARD ||
170
+ /* Clock Control Unit */
39
+ exc == ARMV7M_EXCP_MEM ||
171
+ qdev_init_nofail(DEVICE(&s->ccu));
40
+ exc == ARMV7M_EXCP_USAGE ||
172
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->ccu), 0, s->memmap[AW_H3_CCU]);
41
+ exc == ARMV7M_EXCP_SVC ||
173
+
42
+ exc == ARMV7M_EXCP_PENDSV ||
174
/* UART0. For future clocktree API: All UARTS are connected to APB2_CLK. */
43
+ exc == ARMV7M_EXCP_SYSTICK;
175
serial_mm_init(get_system_memory(), s->memmap[AW_H3_UART0], 2,
44
+}
176
qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_UART0),
45
+
177
diff --git a/hw/misc/allwinner-h3-ccu.c b/hw/misc/allwinner-h3-ccu.c
46
/* Return a mask word which clears the subpriority bits from
178
new file mode 100644
47
* a priority value for an M-profile exception, leaving only
179
index XXXXXXX..XXXXXXX
48
* the group priority.
180
--- /dev/null
49
*/
181
+++ b/hw/misc/allwinner-h3-ccu.c
50
-static inline uint32_t nvic_gprio_mask(NVICState *s)
182
@@ -XXX,XX +XXX,XX @@
51
+static inline uint32_t nvic_gprio_mask(NVICState *s, bool secure)
183
+/*
52
+{
184
+ * Allwinner H3 Clock Control Unit emulation
53
+ return ~0U << (s->prigroup[secure] + 1);
185
+ *
54
+}
186
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
55
+
187
+ *
56
+static bool exc_targets_secure(NVICState *s, int exc)
188
+ * This program is free software: you can redistribute it and/or modify
57
+{
189
+ * it under the terms of the GNU General Public License as published by
58
+ /* Return true if this non-banked exception targets Secure state. */
190
+ * the Free Software Foundation, either version 2 of the License, or
59
+ if (!arm_feature(&s->cpu->env, ARM_FEATURE_M_SECURITY)) {
191
+ * (at your option) any later version.
60
+ return false;
192
+ *
193
+ * This program is distributed in the hope that it will be useful,
194
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
195
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
196
+ * GNU General Public License for more details.
197
+ *
198
+ * You should have received a copy of the GNU General Public License
199
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
200
+ */
201
+
202
+#include "qemu/osdep.h"
203
+#include "qemu/units.h"
204
+#include "hw/sysbus.h"
205
+#include "migration/vmstate.h"
206
+#include "qemu/log.h"
207
+#include "qemu/module.h"
208
+#include "hw/misc/allwinner-h3-ccu.h"
209
+
210
+/* CCU register offsets */
211
+enum {
212
+ REG_PLL_CPUX = 0x0000, /* PLL CPUX Control */
213
+ REG_PLL_AUDIO = 0x0008, /* PLL Audio Control */
214
+ REG_PLL_VIDEO = 0x0010, /* PLL Video Control */
215
+ REG_PLL_VE = 0x0018, /* PLL VE Control */
216
+ REG_PLL_DDR = 0x0020, /* PLL DDR Control */
217
+ REG_PLL_PERIPH0 = 0x0028, /* PLL Peripherals 0 Control */
218
+ REG_PLL_GPU = 0x0038, /* PLL GPU Control */
219
+ REG_PLL_PERIPH1 = 0x0044, /* PLL Peripherals 1 Control */
220
+ REG_PLL_DE = 0x0048, /* PLL Display Engine Control */
221
+ REG_CPUX_AXI = 0x0050, /* CPUX/AXI Configuration */
222
+ REG_APB1 = 0x0054, /* ARM Peripheral Bus 1 Config */
223
+ REG_APB2 = 0x0058, /* ARM Peripheral Bus 2 Config */
224
+ REG_DRAM_CFG = 0x00F4, /* DRAM Configuration */
225
+ REG_MBUS = 0x00FC, /* MBUS Reset */
226
+ REG_PLL_TIME0 = 0x0200, /* PLL Stable Time 0 */
227
+ REG_PLL_TIME1 = 0x0204, /* PLL Stable Time 1 */
228
+ REG_PLL_CPUX_BIAS = 0x0220, /* PLL CPUX Bias */
229
+ REG_PLL_AUDIO_BIAS = 0x0224, /* PLL Audio Bias */
230
+ REG_PLL_VIDEO_BIAS = 0x0228, /* PLL Video Bias */
231
+ REG_PLL_VE_BIAS = 0x022C, /* PLL VE Bias */
232
+ REG_PLL_DDR_BIAS = 0x0230, /* PLL DDR Bias */
233
+ REG_PLL_PERIPH0_BIAS = 0x0234, /* PLL Peripherals 0 Bias */
234
+ REG_PLL_GPU_BIAS = 0x023C, /* PLL GPU Bias */
235
+ REG_PLL_PERIPH1_BIAS = 0x0244, /* PLL Peripherals 1 Bias */
236
+ REG_PLL_DE_BIAS = 0x0248, /* PLL Display Engine Bias */
237
+ REG_PLL_CPUX_TUNING = 0x0250, /* PLL CPUX Tuning */
238
+ REG_PLL_DDR_TUNING = 0x0260, /* PLL DDR Tuning */
239
+};
240
+
241
+#define REG_INDEX(offset) (offset / sizeof(uint32_t))
242
+
243
+/* CCU register flags */
244
+enum {
245
+ REG_DRAM_CFG_UPDATE = (1 << 16),
246
+};
247
+
248
+enum {
249
+ REG_PLL_ENABLE = (1 << 31),
250
+ REG_PLL_LOCK = (1 << 28),
251
+};
252
+
253
+
254
+/* CCU register reset values */
255
+enum {
256
+ REG_PLL_CPUX_RST = 0x00001000,
257
+ REG_PLL_AUDIO_RST = 0x00035514,
258
+ REG_PLL_VIDEO_RST = 0x03006207,
259
+ REG_PLL_VE_RST = 0x03006207,
260
+ REG_PLL_DDR_RST = 0x00001000,
261
+ REG_PLL_PERIPH0_RST = 0x00041811,
262
+ REG_PLL_GPU_RST = 0x03006207,
263
+ REG_PLL_PERIPH1_RST = 0x00041811,
264
+ REG_PLL_DE_RST = 0x03006207,
265
+ REG_CPUX_AXI_RST = 0x00010000,
266
+ REG_APB1_RST = 0x00001010,
267
+ REG_APB2_RST = 0x01000000,
268
+ REG_DRAM_CFG_RST = 0x00000000,
269
+ REG_MBUS_RST = 0x80000000,
270
+ REG_PLL_TIME0_RST = 0x000000FF,
271
+ REG_PLL_TIME1_RST = 0x000000FF,
272
+ REG_PLL_CPUX_BIAS_RST = 0x08100200,
273
+ REG_PLL_AUDIO_BIAS_RST = 0x10100000,
274
+ REG_PLL_VIDEO_BIAS_RST = 0x10100000,
275
+ REG_PLL_VE_BIAS_RST = 0x10100000,
276
+ REG_PLL_DDR_BIAS_RST = 0x81104000,
277
+ REG_PLL_PERIPH0_BIAS_RST = 0x10100010,
278
+ REG_PLL_GPU_BIAS_RST = 0x10100000,
279
+ REG_PLL_PERIPH1_BIAS_RST = 0x10100010,
280
+ REG_PLL_DE_BIAS_RST = 0x10100000,
281
+ REG_PLL_CPUX_TUNING_RST = 0x0A101000,
282
+ REG_PLL_DDR_TUNING_RST = 0x14880000,
283
+};
284
+
285
+static uint64_t allwinner_h3_ccu_read(void *opaque, hwaddr offset,
286
+ unsigned size)
287
+{
288
+ const AwH3ClockCtlState *s = AW_H3_CCU(opaque);
289
+ const uint32_t idx = REG_INDEX(offset);
290
+
291
+ switch (offset) {
292
+ case 0x308 ... AW_H3_CCU_IOSIZE:
293
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
294
+ __func__, (uint32_t)offset);
295
+ return 0;
61
+ }
296
+ }
62
+
297
+
63
+ if (exc >= NVIC_FIRST_IRQ) {
298
+ return s->regs[idx];
64
+ return !s->itns[exc];
299
+}
300
+
301
+static void allwinner_h3_ccu_write(void *opaque, hwaddr offset,
302
+ uint64_t val, unsigned size)
303
+{
304
+ AwH3ClockCtlState *s = AW_H3_CCU(opaque);
305
+ const uint32_t idx = REG_INDEX(offset);
306
+
307
+ switch (offset) {
308
+ case REG_DRAM_CFG: /* DRAM Configuration */
309
+ val &= ~REG_DRAM_CFG_UPDATE;
310
+ break;
311
+ case REG_PLL_CPUX: /* PLL CPUX Control */
312
+ case REG_PLL_AUDIO: /* PLL Audio Control */
313
+ case REG_PLL_VIDEO: /* PLL Video Control */
314
+ case REG_PLL_VE: /* PLL VE Control */
315
+ case REG_PLL_DDR: /* PLL DDR Control */
316
+ case REG_PLL_PERIPH0: /* PLL Peripherals 0 Control */
317
+ case REG_PLL_GPU: /* PLL GPU Control */
318
+ case REG_PLL_PERIPH1: /* PLL Peripherals 1 Control */
319
+ case REG_PLL_DE: /* PLL Display Engine Control */
320
+ if (val & REG_PLL_ENABLE) {
321
+ val |= REG_PLL_LOCK;
322
+ }
323
+ break;
324
+ case 0x308 ... AW_H3_CCU_IOSIZE:
325
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
326
+ __func__, (uint32_t)offset);
327
+ break;
328
+ default:
329
+ qemu_log_mask(LOG_UNIMP, "%s: unimplemented write offset 0x%04x\n",
330
+ __func__, (uint32_t)offset);
331
+ break;
65
+ }
332
+ }
66
+
333
+
67
+ /* Function shouldn't be called for banked exceptions. */
334
+ s->regs[idx] = (uint32_t) val;
68
+ assert(!exc_is_banked(exc));
335
+}
69
+
336
+
70
+ switch (exc) {
337
+static const MemoryRegionOps allwinner_h3_ccu_ops = {
71
+ case ARMV7M_EXCP_NMI:
338
+ .read = allwinner_h3_ccu_read,
72
+ case ARMV7M_EXCP_BUS:
339
+ .write = allwinner_h3_ccu_write,
73
+ return !(s->cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK);
340
+ .endianness = DEVICE_NATIVE_ENDIAN,
74
+ case ARMV7M_EXCP_SECURE:
341
+ .valid = {
75
+ return true;
342
+ .min_access_size = 4,
76
+ case ARMV7M_EXCP_DEBUG:
343
+ .max_access_size = 4,
77
+ /* TODO: controlled by DEMCR.SDME, which we don't yet implement */
344
+ },
78
+ return false;
345
+ .impl.min_access_size = 4,
79
+ default:
346
+};
80
+ /* reset, and reserved (unused) low exception numbers.
347
+
81
+ * We'll get called by code that loops through all the exception
348
+static void allwinner_h3_ccu_reset(DeviceState *dev)
82
+ * numbers, but it doesn't matter what we return here as these
349
+{
83
+ * non-existent exceptions will never be pended or active.
350
+ AwH3ClockCtlState *s = AW_H3_CCU(dev);
84
+ */
351
+
85
+ return true;
352
+ /* Set default values for registers */
353
+ s->regs[REG_INDEX(REG_PLL_CPUX)] = REG_PLL_CPUX_RST;
354
+ s->regs[REG_INDEX(REG_PLL_AUDIO)] = REG_PLL_AUDIO_RST;
355
+ s->regs[REG_INDEX(REG_PLL_VIDEO)] = REG_PLL_VIDEO_RST;
356
+ s->regs[REG_INDEX(REG_PLL_VE)] = REG_PLL_VE_RST;
357
+ s->regs[REG_INDEX(REG_PLL_DDR)] = REG_PLL_DDR_RST;
358
+ s->regs[REG_INDEX(REG_PLL_PERIPH0)] = REG_PLL_PERIPH0_RST;
359
+ s->regs[REG_INDEX(REG_PLL_GPU)] = REG_PLL_GPU_RST;
360
+ s->regs[REG_INDEX(REG_PLL_PERIPH1)] = REG_PLL_PERIPH1_RST;
361
+ s->regs[REG_INDEX(REG_PLL_DE)] = REG_PLL_DE_RST;
362
+ s->regs[REG_INDEX(REG_CPUX_AXI)] = REG_CPUX_AXI_RST;
363
+ s->regs[REG_INDEX(REG_APB1)] = REG_APB1_RST;
364
+ s->regs[REG_INDEX(REG_APB2)] = REG_APB2_RST;
365
+ s->regs[REG_INDEX(REG_DRAM_CFG)] = REG_DRAM_CFG_RST;
366
+ s->regs[REG_INDEX(REG_MBUS)] = REG_MBUS_RST;
367
+ s->regs[REG_INDEX(REG_PLL_TIME0)] = REG_PLL_TIME0_RST;
368
+ s->regs[REG_INDEX(REG_PLL_TIME1)] = REG_PLL_TIME1_RST;
369
+ s->regs[REG_INDEX(REG_PLL_CPUX_BIAS)] = REG_PLL_CPUX_BIAS_RST;
370
+ s->regs[REG_INDEX(REG_PLL_AUDIO_BIAS)] = REG_PLL_AUDIO_BIAS_RST;
371
+ s->regs[REG_INDEX(REG_PLL_VIDEO_BIAS)] = REG_PLL_VIDEO_BIAS_RST;
372
+ s->regs[REG_INDEX(REG_PLL_VE_BIAS)] = REG_PLL_VE_BIAS_RST;
373
+ s->regs[REG_INDEX(REG_PLL_DDR_BIAS)] = REG_PLL_DDR_BIAS_RST;
374
+ s->regs[REG_INDEX(REG_PLL_PERIPH0_BIAS)] = REG_PLL_PERIPH0_BIAS_RST;
375
+ s->regs[REG_INDEX(REG_PLL_GPU_BIAS)] = REG_PLL_GPU_BIAS_RST;
376
+ s->regs[REG_INDEX(REG_PLL_PERIPH1_BIAS)] = REG_PLL_PERIPH1_BIAS_RST;
377
+ s->regs[REG_INDEX(REG_PLL_DE_BIAS)] = REG_PLL_DE_BIAS_RST;
378
+ s->regs[REG_INDEX(REG_PLL_CPUX_TUNING)] = REG_PLL_CPUX_TUNING_RST;
379
+ s->regs[REG_INDEX(REG_PLL_DDR_TUNING)] = REG_PLL_DDR_TUNING_RST;
380
+}
381
+
382
+static void allwinner_h3_ccu_init(Object *obj)
383
+{
384
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
385
+ AwH3ClockCtlState *s = AW_H3_CCU(obj);
386
+
387
+ /* Memory mapping */
388
+ memory_region_init_io(&s->iomem, OBJECT(s), &allwinner_h3_ccu_ops, s,
389
+ TYPE_AW_H3_CCU, AW_H3_CCU_IOSIZE);
390
+ sysbus_init_mmio(sbd, &s->iomem);
391
+}
392
+
393
+static const VMStateDescription allwinner_h3_ccu_vmstate = {
394
+ .name = "allwinner-h3-ccu",
395
+ .version_id = 1,
396
+ .minimum_version_id = 1,
397
+ .fields = (VMStateField[]) {
398
+ VMSTATE_UINT32_ARRAY(regs, AwH3ClockCtlState, AW_H3_CCU_REGS_NUM),
399
+ VMSTATE_END_OF_LIST()
86
+ }
400
+ }
87
+}
401
+};
88
+
402
+
89
+static int exc_group_prio(NVICState *s, int rawprio, bool targets_secure)
403
+static void allwinner_h3_ccu_class_init(ObjectClass *klass, void *data)
90
+{
404
+{
91
+ /* Return the group priority for this exception, given its raw
405
+ DeviceClass *dc = DEVICE_CLASS(klass);
92
+ * (group-and-subgroup) priority value and whether it is targeting
406
+
93
+ * secure state or not.
407
+ dc->reset = allwinner_h3_ccu_reset;
94
+ */
408
+ dc->vmsd = &allwinner_h3_ccu_vmstate;
95
+ if (rawprio < 0) {
409
+}
96
+ return rawprio;
410
+
97
+ }
411
+static const TypeInfo allwinner_h3_ccu_info = {
98
+ rawprio &= nvic_gprio_mask(s, targets_secure);
412
+ .name = TYPE_AW_H3_CCU,
99
+ /* AIRCR.PRIS causes us to squash all NS priorities into the
413
+ .parent = TYPE_SYS_BUS_DEVICE,
100
+ * lower half of the total range
414
+ .instance_init = allwinner_h3_ccu_init,
101
+ */
415
+ .instance_size = sizeof(AwH3ClockCtlState),
102
+ if (!targets_secure &&
416
+ .class_init = allwinner_h3_ccu_class_init,
103
+ (s->cpu->env.v7m.aircr & R_V7M_AIRCR_PRIS_MASK)) {
417
+};
104
+ rawprio = (rawprio >> 1) + NVIC_NS_PRIO_LIMIT;
418
+
105
+ }
419
+static void allwinner_h3_ccu_register(void)
106
+ return rawprio;
420
+{
107
+}
421
+ type_register_static(&allwinner_h3_ccu_info);
108
+
422
+}
109
+/* Recompute vectpending and exception_prio for a CPU which implements
423
+
110
+ * the Security extension
424
+type_init(allwinner_h3_ccu_register)
111
+ */
112
+static void nvic_recompute_state_secure(NVICState *s)
113
{
114
- return ~0U << (s->prigroup[M_REG_NS] + 1);
115
+ int i, bank;
116
+ int pend_prio = NVIC_NOEXC_PRIO;
117
+ int active_prio = NVIC_NOEXC_PRIO;
118
+ int pend_irq = 0;
119
+ bool pending_is_s_banked = false;
120
+
121
+ /* R_CQRV: precedence is by:
122
+ * - lowest group priority; if both the same then
123
+ * - lowest subpriority; if both the same then
124
+ * - lowest exception number; if both the same (ie banked) then
125
+ * - secure exception takes precedence
126
+ * Compare pseudocode RawExecutionPriority.
127
+ * Annoyingly, now we have two prigroup values (for S and NS)
128
+ * we can't do the loop comparison on raw priority values.
129
+ */
130
+ for (i = 1; i < s->num_irq; i++) {
131
+ for (bank = M_REG_S; bank >= M_REG_NS; bank--) {
132
+ VecInfo *vec;
133
+ int prio;
134
+ bool targets_secure;
135
+
136
+ if (bank == M_REG_S) {
137
+ if (!exc_is_banked(i)) {
138
+ continue;
139
+ }
140
+ vec = &s->sec_vectors[i];
141
+ targets_secure = true;
142
+ } else {
143
+ vec = &s->vectors[i];
144
+ targets_secure = !exc_is_banked(i) && exc_targets_secure(s, i);
145
+ }
146
+
147
+ prio = exc_group_prio(s, vec->prio, targets_secure);
148
+ if (vec->enabled && vec->pending && prio < pend_prio) {
149
+ pend_prio = prio;
150
+ pend_irq = i;
151
+ pending_is_s_banked = (bank == M_REG_S);
152
+ }
153
+ if (vec->active && prio < active_prio) {
154
+ active_prio = prio;
155
+ }
156
+ }
157
+ }
158
+
159
+ s->vectpending_is_s_banked = pending_is_s_banked;
160
+ s->vectpending = pend_irq;
161
+ s->vectpending_prio = pend_prio;
162
+ s->exception_prio = active_prio;
163
+
164
+ trace_nvic_recompute_state_secure(s->vectpending,
165
+ s->vectpending_is_s_banked,
166
+ s->vectpending_prio,
167
+ s->exception_prio);
168
}
169
170
/* Recompute vectpending and exception_prio */
171
@@ -XXX,XX +XXX,XX @@ static void nvic_recompute_state(NVICState *s)
172
int active_prio = NVIC_NOEXC_PRIO;
173
int pend_irq = 0;
174
175
+ /* In theory we could write one function that handled both
176
+ * the "security extension present" and "not present"; however
177
+ * the security related changes significantly complicate the
178
+ * recomputation just by themselves and mixing both cases together
179
+ * would be even worse, so we retain a separate non-secure-only
180
+ * version for CPUs which don't implement the security extension.
181
+ */
182
+ if (arm_feature(&s->cpu->env, ARM_FEATURE_M_SECURITY)) {
183
+ nvic_recompute_state_secure(s);
184
+ return;
185
+ }
186
+
187
for (i = 1; i < s->num_irq; i++) {
188
VecInfo *vec = &s->vectors[i];
189
190
@@ -XXX,XX +XXX,XX @@ static void nvic_recompute_state(NVICState *s)
191
}
192
193
if (active_prio > 0) {
194
- active_prio &= nvic_gprio_mask(s);
195
+ active_prio &= nvic_gprio_mask(s, false);
196
}
197
198
if (pend_prio > 0) {
199
- pend_prio &= nvic_gprio_mask(s);
200
+ pend_prio &= nvic_gprio_mask(s, false);
201
}
202
203
s->vectpending = pend_irq;
204
@@ -XXX,XX +XXX,XX @@ static inline int nvic_exec_prio(NVICState *s)
205
} else if (env->v7m.primask[env->v7m.secure]) {
206
running = 0;
207
} else if (env->v7m.basepri[env->v7m.secure] > 0) {
208
- running = env->v7m.basepri[env->v7m.secure] & nvic_gprio_mask(s);
209
+ running = env->v7m.basepri[env->v7m.secure] &
210
+ nvic_gprio_mask(s, env->v7m.secure);
211
} else {
212
running = NVIC_NOEXC_PRIO; /* lower than any possible priority */
213
}
214
diff --git a/hw/intc/trace-events b/hw/intc/trace-events
215
index XXXXXXX..XXXXXXX 100644
216
--- a/hw/intc/trace-events
217
+++ b/hw/intc/trace-events
218
@@ -XXX,XX +XXX,XX @@ gicv3_redist_send_sgi(uint32_t cpu, int irq) "GICv3 redistributor 0x%x pending S
219
220
# hw/intc/armv7m_nvic.c
221
nvic_recompute_state(int vectpending, int vectpending_prio, int exception_prio) "NVIC state recomputed: vectpending %d vectpending_prio %d exception_prio %d"
222
+nvic_recompute_state_secure(int vectpending, bool vectpending_is_s_banked, int vectpending_prio, int exception_prio) "NVIC state recomputed: vectpending %d is_s_banked %d vectpending_prio %d exception_prio %d"
223
nvic_set_prio(int irq, uint8_t prio) "NVIC set irq %d priority %d"
224
nvic_irq_update(int vectpending, int pendprio, int exception_prio, int level) "NVIC vectpending %d pending prio %d exception_prio %d: setting irq line to %d"
225
nvic_escalate_prio(int irq, int irqprio, int runprio) "NVIC escalating irq %d to HardFault: insufficient priority %d >= %d"
226
--
425
--
227
2.7.4
426
2.20.1
228
427
229
428
diff view generated by jsdifflib
1
Handle banking of SHCSR: some register bits are banked between
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
2
Secure and Non-Secure, and some are only accessible to Secure.
3
2
3
The Allwinner H3 System on Chip contains multiple USB 2.0 bus
4
connections which provide software access using the Enhanced
5
Host Controller Interface (EHCI) and Open Host Controller
6
Interface (OHCI) interfaces. This commit adds support for
7
both interfaces in the Allwinner H3 System on Chip.
8
9
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
10
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
11
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
12
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
13
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
14
Message-id: 20200311221854.30370-5-nieklinnenbank@gmail.com
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
Message-id: 1505240046-11454-19-git-send-email-peter.maydell@linaro.org
7
---
16
---
8
hw/intc/armv7m_nvic.c | 221 ++++++++++++++++++++++++++++++++++++++------------
17
hw/usb/hcd-ehci.h | 1 +
9
1 file changed, 169 insertions(+), 52 deletions(-)
18
include/hw/arm/allwinner-h3.h | 8 +++++++
19
hw/arm/allwinner-h3.c | 44 +++++++++++++++++++++++++++++++++++
20
hw/usb/hcd-ehci-sysbus.c | 17 ++++++++++++++
21
hw/arm/Kconfig | 2 ++
22
5 files changed, 72 insertions(+)
10
23
11
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
24
diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h
12
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
13
--- a/hw/intc/armv7m_nvic.c
26
--- a/hw/usb/hcd-ehci.h
14
+++ b/hw/intc/armv7m_nvic.c
27
+++ b/hw/usb/hcd-ehci.h
15
@@ -XXX,XX +XXX,XX @@ static uint32_t nvic_readl(NVICState *s, uint32_t offset, MemTxAttrs attrs)
28
@@ -XXX,XX +XXX,XX @@ typedef struct EHCIPCIState {
16
val = cpu->env.v7m.ccr[attrs.secure];
29
#define TYPE_SYS_BUS_EHCI "sysbus-ehci-usb"
17
val |= cpu->env.v7m.ccr[M_REG_NS] & R_V7M_CCR_BFHFNMIGN_MASK;
30
#define TYPE_PLATFORM_EHCI "platform-ehci-usb"
18
return val;
31
#define TYPE_EXYNOS4210_EHCI "exynos4210-ehci-usb"
19
- case 0xd24: /* System Handler Status. */
32
+#define TYPE_AW_H3_EHCI "aw-h3-ehci-usb"
20
+ case 0xd24: /* System Handler Control and State (SHCSR) */
33
#define TYPE_TEGRA2_EHCI "tegra2-ehci-usb"
21
val = 0;
34
#define TYPE_PPC4xx_EHCI "ppc4xx-ehci-usb"
22
- if (s->vectors[ARMV7M_EXCP_MEM].active) {
35
#define TYPE_FUSBH200_EHCI "fusbh200-ehci-usb"
23
- val |= (1 << 0);
36
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
24
- }
37
index XXXXXXX..XXXXXXX 100644
25
- if (s->vectors[ARMV7M_EXCP_BUS].active) {
38
--- a/include/hw/arm/allwinner-h3.h
26
- val |= (1 << 1);
39
+++ b/include/hw/arm/allwinner-h3.h
27
- }
40
@@ -XXX,XX +XXX,XX @@ enum {
28
- if (s->vectors[ARMV7M_EXCP_USAGE].active) {
41
AW_H3_SRAM_A1,
29
- val |= (1 << 3);
42
AW_H3_SRAM_A2,
30
+ if (attrs.secure) {
43
AW_H3_SRAM_C,
31
+ if (s->sec_vectors[ARMV7M_EXCP_MEM].active) {
44
+ AW_H3_EHCI0,
32
+ val |= (1 << 0);
45
+ AW_H3_OHCI0,
33
+ }
46
+ AW_H3_EHCI1,
34
+ if (s->sec_vectors[ARMV7M_EXCP_HARD].active) {
47
+ AW_H3_OHCI1,
35
+ val |= (1 << 2);
48
+ AW_H3_EHCI2,
36
+ }
49
+ AW_H3_OHCI2,
37
+ if (s->sec_vectors[ARMV7M_EXCP_USAGE].active) {
50
+ AW_H3_EHCI3,
38
+ val |= (1 << 3);
51
+ AW_H3_OHCI3,
39
+ }
52
AW_H3_CCU,
40
+ if (s->sec_vectors[ARMV7M_EXCP_SVC].active) {
53
AW_H3_PIT,
41
+ val |= (1 << 7);
54
AW_H3_UART0,
42
+ }
55
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
43
+ if (s->sec_vectors[ARMV7M_EXCP_PENDSV].active) {
56
index XXXXXXX..XXXXXXX 100644
44
+ val |= (1 << 10);
57
--- a/hw/arm/allwinner-h3.c
45
+ }
58
+++ b/hw/arm/allwinner-h3.c
46
+ if (s->sec_vectors[ARMV7M_EXCP_SYSTICK].active) {
59
@@ -XXX,XX +XXX,XX @@
47
+ val |= (1 << 11);
60
#include "hw/sysbus.h"
48
+ }
61
#include "hw/char/serial.h"
49
+ if (s->sec_vectors[ARMV7M_EXCP_USAGE].pending) {
62
#include "hw/misc/unimp.h"
50
+ val |= (1 << 12);
63
+#include "hw/usb/hcd-ehci.h"
51
+ }
64
#include "sysemu/sysemu.h"
52
+ if (s->sec_vectors[ARMV7M_EXCP_MEM].pending) {
65
#include "hw/arm/allwinner-h3.h"
53
+ val |= (1 << 13);
66
54
+ }
67
@@ -XXX,XX +XXX,XX @@ const hwaddr allwinner_h3_memmap[] = {
55
+ if (s->sec_vectors[ARMV7M_EXCP_SVC].pending) {
68
[AW_H3_SRAM_A1] = 0x00000000,
56
+ val |= (1 << 15);
69
[AW_H3_SRAM_A2] = 0x00044000,
57
+ }
70
[AW_H3_SRAM_C] = 0x00010000,
58
+ if (s->sec_vectors[ARMV7M_EXCP_MEM].enabled) {
71
+ [AW_H3_EHCI0] = 0x01c1a000,
59
+ val |= (1 << 16);
72
+ [AW_H3_OHCI0] = 0x01c1a400,
60
+ }
73
+ [AW_H3_EHCI1] = 0x01c1b000,
61
+ if (s->sec_vectors[ARMV7M_EXCP_USAGE].enabled) {
74
+ [AW_H3_OHCI1] = 0x01c1b400,
62
+ val |= (1 << 18);
75
+ [AW_H3_EHCI2] = 0x01c1c000,
63
+ }
76
+ [AW_H3_OHCI2] = 0x01c1c400,
64
+ if (s->sec_vectors[ARMV7M_EXCP_HARD].pending) {
77
+ [AW_H3_EHCI3] = 0x01c1d000,
65
+ val |= (1 << 21);
78
+ [AW_H3_OHCI3] = 0x01c1d400,
66
+ }
79
[AW_H3_CCU] = 0x01c20000,
67
+ /* SecureFault is not banked but is always RAZ/WI to NS */
80
[AW_H3_PIT] = 0x01c20c00,
68
+ if (s->vectors[ARMV7M_EXCP_SECURE].active) {
81
[AW_H3_UART0] = 0x01c28000,
69
+ val |= (1 << 4);
82
@@ -XXX,XX +XXX,XX @@ enum {
70
+ }
83
AW_H3_GIC_SPI_UART3 = 3,
71
+ if (s->vectors[ARMV7M_EXCP_SECURE].enabled) {
84
AW_H3_GIC_SPI_TIMER0 = 18,
72
+ val |= (1 << 19);
85
AW_H3_GIC_SPI_TIMER1 = 19,
73
+ }
86
+ AW_H3_GIC_SPI_EHCI0 = 72,
74
+ if (s->vectors[ARMV7M_EXCP_SECURE].pending) {
87
+ AW_H3_GIC_SPI_OHCI0 = 73,
75
+ val |= (1 << 20);
88
+ AW_H3_GIC_SPI_EHCI1 = 74,
76
+ }
89
+ AW_H3_GIC_SPI_OHCI1 = 75,
77
+ } else {
90
+ AW_H3_GIC_SPI_EHCI2 = 76,
78
+ if (s->vectors[ARMV7M_EXCP_MEM].active) {
91
+ AW_H3_GIC_SPI_OHCI2 = 77,
79
+ val |= (1 << 0);
92
+ AW_H3_GIC_SPI_EHCI3 = 78,
80
+ }
93
+ AW_H3_GIC_SPI_OHCI3 = 79,
81
+ if (arm_feature(&cpu->env, ARM_FEATURE_V8)) {
94
};
82
+ /* HARDFAULTACT, HARDFAULTPENDED not present in v7M */
95
83
+ if (s->vectors[ARMV7M_EXCP_HARD].active) {
96
/* Allwinner H3 general constants */
84
+ val |= (1 << 2);
97
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
85
+ }
98
qdev_init_nofail(DEVICE(&s->ccu));
86
+ if (s->vectors[ARMV7M_EXCP_HARD].pending) {
99
sysbus_mmio_map(SYS_BUS_DEVICE(&s->ccu), 0, s->memmap[AW_H3_CCU]);
87
+ val |= (1 << 21);
100
88
+ }
101
+ /* Universal Serial Bus */
89
+ }
102
+ sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0],
90
+ if (s->vectors[ARMV7M_EXCP_USAGE].active) {
103
+ qdev_get_gpio_in(DEVICE(&s->gic),
91
+ val |= (1 << 3);
104
+ AW_H3_GIC_SPI_EHCI0));
92
+ }
105
+ sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI1],
93
+ if (s->vectors[ARMV7M_EXCP_SVC].active) {
106
+ qdev_get_gpio_in(DEVICE(&s->gic),
94
+ val |= (1 << 7);
107
+ AW_H3_GIC_SPI_EHCI1));
95
+ }
108
+ sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI2],
96
+ if (s->vectors[ARMV7M_EXCP_PENDSV].active) {
109
+ qdev_get_gpio_in(DEVICE(&s->gic),
97
+ val |= (1 << 10);
110
+ AW_H3_GIC_SPI_EHCI2));
98
+ }
111
+ sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI3],
99
+ if (s->vectors[ARMV7M_EXCP_SYSTICK].active) {
112
+ qdev_get_gpio_in(DEVICE(&s->gic),
100
+ val |= (1 << 11);
113
+ AW_H3_GIC_SPI_EHCI3));
101
+ }
102
+ if (s->vectors[ARMV7M_EXCP_USAGE].pending) {
103
+ val |= (1 << 12);
104
+ }
105
+ if (s->vectors[ARMV7M_EXCP_MEM].pending) {
106
+ val |= (1 << 13);
107
+ }
108
+ if (s->vectors[ARMV7M_EXCP_SVC].pending) {
109
+ val |= (1 << 15);
110
+ }
111
+ if (s->vectors[ARMV7M_EXCP_MEM].enabled) {
112
+ val |= (1 << 16);
113
+ }
114
+ if (s->vectors[ARMV7M_EXCP_USAGE].enabled) {
115
+ val |= (1 << 18);
116
+ }
117
}
118
- if (s->vectors[ARMV7M_EXCP_SVC].active) {
119
- val |= (1 << 7);
120
+ if (attrs.secure || (cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK)) {
121
+ if (s->vectors[ARMV7M_EXCP_BUS].active) {
122
+ val |= (1 << 1);
123
+ }
124
+ if (s->vectors[ARMV7M_EXCP_BUS].pending) {
125
+ val |= (1 << 14);
126
+ }
127
+ if (s->vectors[ARMV7M_EXCP_BUS].enabled) {
128
+ val |= (1 << 17);
129
+ }
130
+ if (arm_feature(&cpu->env, ARM_FEATURE_V8) &&
131
+ s->vectors[ARMV7M_EXCP_NMI].active) {
132
+ /* NMIACT is not present in v7M */
133
+ val |= (1 << 5);
134
+ }
135
}
136
+
114
+
137
+ /* TODO: this is RAZ/WI from NS if DEMCR.SDME is set */
115
+ sysbus_create_simple("sysbus-ohci", s->memmap[AW_H3_OHCI0],
138
if (s->vectors[ARMV7M_EXCP_DEBUG].active) {
116
+ qdev_get_gpio_in(DEVICE(&s->gic),
139
val |= (1 << 8);
117
+ AW_H3_GIC_SPI_OHCI0));
140
}
118
+ sysbus_create_simple("sysbus-ohci", s->memmap[AW_H3_OHCI1],
141
- if (s->vectors[ARMV7M_EXCP_PENDSV].active) {
119
+ qdev_get_gpio_in(DEVICE(&s->gic),
142
- val |= (1 << 10);
120
+ AW_H3_GIC_SPI_OHCI1));
143
- }
121
+ sysbus_create_simple("sysbus-ohci", s->memmap[AW_H3_OHCI2],
144
- if (s->vectors[ARMV7M_EXCP_SYSTICK].active) {
122
+ qdev_get_gpio_in(DEVICE(&s->gic),
145
- val |= (1 << 11);
123
+ AW_H3_GIC_SPI_OHCI2));
146
- }
124
+ sysbus_create_simple("sysbus-ohci", s->memmap[AW_H3_OHCI3],
147
- if (s->vectors[ARMV7M_EXCP_USAGE].pending) {
125
+ qdev_get_gpio_in(DEVICE(&s->gic),
148
- val |= (1 << 12);
126
+ AW_H3_GIC_SPI_OHCI3));
149
- }
150
- if (s->vectors[ARMV7M_EXCP_MEM].pending) {
151
- val |= (1 << 13);
152
- }
153
- if (s->vectors[ARMV7M_EXCP_BUS].pending) {
154
- val |= (1 << 14);
155
- }
156
- if (s->vectors[ARMV7M_EXCP_SVC].pending) {
157
- val |= (1 << 15);
158
- }
159
- if (s->vectors[ARMV7M_EXCP_MEM].enabled) {
160
- val |= (1 << 16);
161
- }
162
- if (s->vectors[ARMV7M_EXCP_BUS].enabled) {
163
- val |= (1 << 17);
164
- }
165
- if (s->vectors[ARMV7M_EXCP_USAGE].enabled) {
166
- val |= (1 << 18);
167
- }
168
return val;
169
case 0xd28: /* Configurable Fault Status. */
170
/* The BFSR bits [15:8] are shared between security states
171
@@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value,
172
173
cpu->env.v7m.ccr[attrs.secure] = value;
174
break;
175
- case 0xd24: /* System Handler Control. */
176
- s->vectors[ARMV7M_EXCP_MEM].active = (value & (1 << 0)) != 0;
177
- s->vectors[ARMV7M_EXCP_BUS].active = (value & (1 << 1)) != 0;
178
- s->vectors[ARMV7M_EXCP_USAGE].active = (value & (1 << 3)) != 0;
179
- s->vectors[ARMV7M_EXCP_SVC].active = (value & (1 << 7)) != 0;
180
+ case 0xd24: /* System Handler Control and State (SHCSR) */
181
+ if (attrs.secure) {
182
+ s->sec_vectors[ARMV7M_EXCP_MEM].active = (value & (1 << 0)) != 0;
183
+ /* Secure HardFault active bit cannot be written */
184
+ s->sec_vectors[ARMV7M_EXCP_USAGE].active = (value & (1 << 3)) != 0;
185
+ s->sec_vectors[ARMV7M_EXCP_SVC].active = (value & (1 << 7)) != 0;
186
+ s->sec_vectors[ARMV7M_EXCP_PENDSV].active =
187
+ (value & (1 << 10)) != 0;
188
+ s->sec_vectors[ARMV7M_EXCP_SYSTICK].active =
189
+ (value & (1 << 11)) != 0;
190
+ s->sec_vectors[ARMV7M_EXCP_USAGE].pending =
191
+ (value & (1 << 12)) != 0;
192
+ s->sec_vectors[ARMV7M_EXCP_MEM].pending = (value & (1 << 13)) != 0;
193
+ s->sec_vectors[ARMV7M_EXCP_SVC].pending = (value & (1 << 15)) != 0;
194
+ s->sec_vectors[ARMV7M_EXCP_MEM].enabled = (value & (1 << 16)) != 0;
195
+ s->sec_vectors[ARMV7M_EXCP_BUS].enabled = (value & (1 << 17)) != 0;
196
+ s->sec_vectors[ARMV7M_EXCP_USAGE].enabled =
197
+ (value & (1 << 18)) != 0;
198
+ /* SecureFault not banked, but RAZ/WI to NS */
199
+ s->vectors[ARMV7M_EXCP_SECURE].active = (value & (1 << 4)) != 0;
200
+ s->vectors[ARMV7M_EXCP_SECURE].enabled = (value & (1 << 19)) != 0;
201
+ s->vectors[ARMV7M_EXCP_SECURE].pending = (value & (1 << 20)) != 0;
202
+ } else {
203
+ s->vectors[ARMV7M_EXCP_MEM].active = (value & (1 << 0)) != 0;
204
+ if (arm_feature(&cpu->env, ARM_FEATURE_V8)) {
205
+ /* HARDFAULTPENDED is not present in v7M */
206
+ s->vectors[ARMV7M_EXCP_HARD].pending = (value & (1 << 21)) != 0;
207
+ }
208
+ s->vectors[ARMV7M_EXCP_USAGE].active = (value & (1 << 3)) != 0;
209
+ s->vectors[ARMV7M_EXCP_SVC].active = (value & (1 << 7)) != 0;
210
+ s->vectors[ARMV7M_EXCP_PENDSV].active = (value & (1 << 10)) != 0;
211
+ s->vectors[ARMV7M_EXCP_SYSTICK].active = (value & (1 << 11)) != 0;
212
+ s->vectors[ARMV7M_EXCP_USAGE].pending = (value & (1 << 12)) != 0;
213
+ s->vectors[ARMV7M_EXCP_MEM].pending = (value & (1 << 13)) != 0;
214
+ s->vectors[ARMV7M_EXCP_SVC].pending = (value & (1 << 15)) != 0;
215
+ s->vectors[ARMV7M_EXCP_MEM].enabled = (value & (1 << 16)) != 0;
216
+ s->vectors[ARMV7M_EXCP_USAGE].enabled = (value & (1 << 18)) != 0;
217
+ }
218
+ if (attrs.secure || (cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK)) {
219
+ s->vectors[ARMV7M_EXCP_BUS].active = (value & (1 << 1)) != 0;
220
+ s->vectors[ARMV7M_EXCP_BUS].pending = (value & (1 << 14)) != 0;
221
+ s->vectors[ARMV7M_EXCP_BUS].enabled = (value & (1 << 17)) != 0;
222
+ }
223
+ /* NMIACT can only be written if the write is of a zero, with
224
+ * BFHFNMINS 1, and by the CPU in secure state via the NS alias.
225
+ */
226
+ if (!attrs.secure && cpu->env.v7m.secure &&
227
+ (cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK) &&
228
+ (value & (1 << 5)) == 0) {
229
+ s->vectors[ARMV7M_EXCP_NMI].active = 0;
230
+ }
231
+ /* HARDFAULTACT can only be written if the write is of a zero
232
+ * to the non-secure HardFault state by the CPU in secure state.
233
+ * The only case where we can be targeting the non-secure HF state
234
+ * when in secure state is if this is a write via the NS alias
235
+ * and BFHFNMINS is 1.
236
+ */
237
+ if (!attrs.secure && cpu->env.v7m.secure &&
238
+ (cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK) &&
239
+ (value & (1 << 2)) == 0) {
240
+ s->vectors[ARMV7M_EXCP_HARD].active = 0;
241
+ }
242
+
127
+
243
+ /* TODO: this is RAZ/WI from NS if DEMCR.SDME is set */
128
/* UART0. For future clocktree API: All UARTS are connected to APB2_CLK. */
244
s->vectors[ARMV7M_EXCP_DEBUG].active = (value & (1 << 8)) != 0;
129
serial_mm_init(get_system_memory(), s->memmap[AW_H3_UART0], 2,
245
- s->vectors[ARMV7M_EXCP_PENDSV].active = (value & (1 << 10)) != 0;
130
qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_UART0),
246
- s->vectors[ARMV7M_EXCP_SYSTICK].active = (value & (1 << 11)) != 0;
131
diff --git a/hw/usb/hcd-ehci-sysbus.c b/hw/usb/hcd-ehci-sysbus.c
247
- s->vectors[ARMV7M_EXCP_USAGE].pending = (value & (1 << 12)) != 0;
132
index XXXXXXX..XXXXXXX 100644
248
- s->vectors[ARMV7M_EXCP_MEM].pending = (value & (1 << 13)) != 0;
133
--- a/hw/usb/hcd-ehci-sysbus.c
249
- s->vectors[ARMV7M_EXCP_BUS].pending = (value & (1 << 14)) != 0;
134
+++ b/hw/usb/hcd-ehci-sysbus.c
250
- s->vectors[ARMV7M_EXCP_SVC].pending = (value & (1 << 15)) != 0;
135
@@ -XXX,XX +XXX,XX @@ static const TypeInfo ehci_exynos4210_type_info = {
251
- s->vectors[ARMV7M_EXCP_MEM].enabled = (value & (1 << 16)) != 0;
136
.class_init = ehci_exynos4210_class_init,
252
- s->vectors[ARMV7M_EXCP_BUS].enabled = (value & (1 << 17)) != 0;
137
};
253
- s->vectors[ARMV7M_EXCP_USAGE].enabled = (value & (1 << 18)) != 0;
138
254
nvic_irq_update(s);
139
+static void ehci_aw_h3_class_init(ObjectClass *oc, void *data)
255
break;
140
+{
256
case 0xd28: /* Configurable Fault Status. */
141
+ SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc);
142
+ DeviceClass *dc = DEVICE_CLASS(oc);
143
+
144
+ sec->capsbase = 0x0;
145
+ sec->opregbase = 0x10;
146
+ set_bit(DEVICE_CATEGORY_USB, dc->categories);
147
+}
148
+
149
+static const TypeInfo ehci_aw_h3_type_info = {
150
+ .name = TYPE_AW_H3_EHCI,
151
+ .parent = TYPE_SYS_BUS_EHCI,
152
+ .class_init = ehci_aw_h3_class_init,
153
+};
154
+
155
static void ehci_tegra2_class_init(ObjectClass *oc, void *data)
156
{
157
SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc);
158
@@ -XXX,XX +XXX,XX @@ static void ehci_sysbus_register_types(void)
159
type_register_static(&ehci_type_info);
160
type_register_static(&ehci_platform_type_info);
161
type_register_static(&ehci_exynos4210_type_info);
162
+ type_register_static(&ehci_aw_h3_type_info);
163
type_register_static(&ehci_tegra2_type_info);
164
type_register_static(&ehci_ppc4xx_type_info);
165
type_register_static(&ehci_fusbh200_type_info);
166
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
167
index XXXXXXX..XXXXXXX 100644
168
--- a/hw/arm/Kconfig
169
+++ b/hw/arm/Kconfig
170
@@ -XXX,XX +XXX,XX @@ config ALLWINNER_H3
171
select ARM_TIMER
172
select ARM_GIC
173
select UNIMP
174
+ select USB_OHCI
175
+ select USB_EHCI_SYSBUS
176
177
config RASPI
178
bool
257
--
179
--
258
2.7.4
180
2.20.1
259
181
260
182
diff view generated by jsdifflib
1
Don't use old_mmio in the memory region ops struct.
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
2
2
3
The Allwinner H3 System on Chip has an System Control
4
module that provides system wide generic controls and
5
device information. This commit adds support for the
6
Allwinner H3 System Control module.
7
8
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
9
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
10
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
11
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
12
Message-id: 20200311221854.30370-6-nieklinnenbank@gmail.com
3
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
Message-id: 1505580378-9044-6-git-send-email-peter.maydell@linaro.org
6
---
14
---
7
hw/i2c/omap_i2c.c | 44 ++++++++++++++++++++++++++++++++------------
15
hw/misc/Makefile.objs | 1 +
8
1 file changed, 32 insertions(+), 12 deletions(-)
16
include/hw/arm/allwinner-h3.h | 3 +
9
17
include/hw/misc/allwinner-h3-sysctrl.h | 67 ++++++++++++
10
diff --git a/hw/i2c/omap_i2c.c b/hw/i2c/omap_i2c.c
18
hw/arm/allwinner-h3.c | 9 +-
19
hw/misc/allwinner-h3-sysctrl.c | 140 +++++++++++++++++++++++++
20
5 files changed, 219 insertions(+), 1 deletion(-)
21
create mode 100644 include/hw/misc/allwinner-h3-sysctrl.h
22
create mode 100644 hw/misc/allwinner-h3-sysctrl.c
23
24
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
11
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
12
--- a/hw/i2c/omap_i2c.c
26
--- a/hw/misc/Makefile.objs
13
+++ b/hw/i2c/omap_i2c.c
27
+++ b/hw/misc/Makefile.objs
14
@@ -XXX,XX +XXX,XX @@ static void omap_i2c_writeb(void *opaque, hwaddr addr,
28
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_MACIO) += macio/
15
}
29
common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o
30
31
common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o
32
+common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-sysctrl.o
33
common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o
34
common-obj-$(CONFIG_NSERIES) += cbus.o
35
common-obj-$(CONFIG_ECCMEMCTL) += eccmemctl.o
36
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
37
index XXXXXXX..XXXXXXX 100644
38
--- a/include/hw/arm/allwinner-h3.h
39
+++ b/include/hw/arm/allwinner-h3.h
40
@@ -XXX,XX +XXX,XX @@
41
#include "hw/timer/allwinner-a10-pit.h"
42
#include "hw/intc/arm_gic.h"
43
#include "hw/misc/allwinner-h3-ccu.h"
44
+#include "hw/misc/allwinner-h3-sysctrl.h"
45
#include "target/arm/cpu.h"
46
47
/**
48
@@ -XXX,XX +XXX,XX @@ enum {
49
AW_H3_SRAM_A1,
50
AW_H3_SRAM_A2,
51
AW_H3_SRAM_C,
52
+ AW_H3_SYSCTRL,
53
AW_H3_EHCI0,
54
AW_H3_OHCI0,
55
AW_H3_EHCI1,
56
@@ -XXX,XX +XXX,XX @@ typedef struct AwH3State {
57
const hwaddr *memmap;
58
AwA10PITState timer;
59
AwH3ClockCtlState ccu;
60
+ AwH3SysCtrlState sysctrl;
61
GICState gic;
62
MemoryRegion sram_a1;
63
MemoryRegion sram_a2;
64
diff --git a/include/hw/misc/allwinner-h3-sysctrl.h b/include/hw/misc/allwinner-h3-sysctrl.h
65
new file mode 100644
66
index XXXXXXX..XXXXXXX
67
--- /dev/null
68
+++ b/include/hw/misc/allwinner-h3-sysctrl.h
69
@@ -XXX,XX +XXX,XX @@
70
+/*
71
+ * Allwinner H3 System Control emulation
72
+ *
73
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
74
+ *
75
+ * This program is free software: you can redistribute it and/or modify
76
+ * it under the terms of the GNU General Public License as published by
77
+ * the Free Software Foundation, either version 2 of the License, or
78
+ * (at your option) any later version.
79
+ *
80
+ * This program is distributed in the hope that it will be useful,
81
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
82
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
83
+ * GNU General Public License for more details.
84
+ *
85
+ * You should have received a copy of the GNU General Public License
86
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
87
+ */
88
+
89
+#ifndef HW_MISC_ALLWINNER_H3_SYSCTRL_H
90
+#define HW_MISC_ALLWINNER_H3_SYSCTRL_H
91
+
92
+#include "qom/object.h"
93
+#include "hw/sysbus.h"
94
+
95
+/**
96
+ * @name Constants
97
+ * @{
98
+ */
99
+
100
+/** Highest register address used by System Control device */
101
+#define AW_H3_SYSCTRL_REGS_MAXADDR (0x30)
102
+
103
+/** Total number of known registers */
104
+#define AW_H3_SYSCTRL_REGS_NUM ((AW_H3_SYSCTRL_REGS_MAXADDR / \
105
+ sizeof(uint32_t)) + 1)
106
+
107
+/** @} */
108
+
109
+/**
110
+ * @name Object model
111
+ * @{
112
+ */
113
+
114
+#define TYPE_AW_H3_SYSCTRL "allwinner-h3-sysctrl"
115
+#define AW_H3_SYSCTRL(obj) \
116
+ OBJECT_CHECK(AwH3SysCtrlState, (obj), TYPE_AW_H3_SYSCTRL)
117
+
118
+/** @} */
119
+
120
+/**
121
+ * Allwinner H3 System Control object instance state
122
+ */
123
+typedef struct AwH3SysCtrlState {
124
+ /*< private >*/
125
+ SysBusDevice parent_obj;
126
+ /*< public >*/
127
+
128
+ /** Maps I/O registers in physical memory */
129
+ MemoryRegion iomem;
130
+
131
+ /** Array of hardware registers */
132
+ uint32_t regs[AW_H3_SYSCTRL_REGS_NUM];
133
+
134
+} AwH3SysCtrlState;
135
+
136
+#endif /* HW_MISC_ALLWINNER_H3_SYSCTRL_H */
137
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
138
index XXXXXXX..XXXXXXX 100644
139
--- a/hw/arm/allwinner-h3.c
140
+++ b/hw/arm/allwinner-h3.c
141
@@ -XXX,XX +XXX,XX @@ const hwaddr allwinner_h3_memmap[] = {
142
[AW_H3_SRAM_A1] = 0x00000000,
143
[AW_H3_SRAM_A2] = 0x00044000,
144
[AW_H3_SRAM_C] = 0x00010000,
145
+ [AW_H3_SYSCTRL] = 0x01c00000,
146
[AW_H3_EHCI0] = 0x01c1a000,
147
[AW_H3_OHCI0] = 0x01c1a400,
148
[AW_H3_EHCI1] = 0x01c1b000,
149
@@ -XXX,XX +XXX,XX @@ struct AwH3Unimplemented {
150
} unimplemented[] = {
151
{ "d-engine", 0x01000000, 4 * MiB },
152
{ "d-inter", 0x01400000, 128 * KiB },
153
- { "syscon", 0x01c00000, 4 * KiB },
154
{ "dma", 0x01c02000, 4 * KiB },
155
{ "nfdc", 0x01c03000, 4 * KiB },
156
{ "ts", 0x01c06000, 4 * KiB },
157
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_init(Object *obj)
158
159
sysbus_init_child_obj(obj, "ccu", &s->ccu, sizeof(s->ccu),
160
TYPE_AW_H3_CCU);
161
+
162
+ sysbus_init_child_obj(obj, "sysctrl", &s->sysctrl, sizeof(s->sysctrl),
163
+ TYPE_AW_H3_SYSCTRL);
16
}
164
}
17
165
18
+static uint64_t omap_i2c_readfn(void *opaque, hwaddr addr,
166
static void allwinner_h3_realize(DeviceState *dev, Error **errp)
19
+ unsigned size)
167
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
20
+{
168
qdev_init_nofail(DEVICE(&s->ccu));
21
+ switch (size) {
169
sysbus_mmio_map(SYS_BUS_DEVICE(&s->ccu), 0, s->memmap[AW_H3_CCU]);
22
+ case 2:
170
23
+ return omap_i2c_read(opaque, addr);
171
+ /* System Control */
24
+ default:
172
+ qdev_init_nofail(DEVICE(&s->sysctrl));
25
+ return omap_badwidth_read16(opaque, addr);
173
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->sysctrl), 0, s->memmap[AW_H3_SYSCTRL]);
174
+
175
/* Universal Serial Bus */
176
sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0],
177
qdev_get_gpio_in(DEVICE(&s->gic),
178
diff --git a/hw/misc/allwinner-h3-sysctrl.c b/hw/misc/allwinner-h3-sysctrl.c
179
new file mode 100644
180
index XXXXXXX..XXXXXXX
181
--- /dev/null
182
+++ b/hw/misc/allwinner-h3-sysctrl.c
183
@@ -XXX,XX +XXX,XX @@
184
+/*
185
+ * Allwinner H3 System Control emulation
186
+ *
187
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
188
+ *
189
+ * This program is free software: you can redistribute it and/or modify
190
+ * it under the terms of the GNU General Public License as published by
191
+ * the Free Software Foundation, either version 2 of the License, or
192
+ * (at your option) any later version.
193
+ *
194
+ * This program is distributed in the hope that it will be useful,
195
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
196
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
197
+ * GNU General Public License for more details.
198
+ *
199
+ * You should have received a copy of the GNU General Public License
200
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
201
+ */
202
+
203
+#include "qemu/osdep.h"
204
+#include "qemu/units.h"
205
+#include "hw/sysbus.h"
206
+#include "migration/vmstate.h"
207
+#include "qemu/log.h"
208
+#include "qemu/module.h"
209
+#include "hw/misc/allwinner-h3-sysctrl.h"
210
+
211
+/* System Control register offsets */
212
+enum {
213
+ REG_VER = 0x24, /* Version */
214
+ REG_EMAC_PHY_CLK = 0x30, /* EMAC PHY Clock */
215
+};
216
+
217
+#define REG_INDEX(offset) (offset / sizeof(uint32_t))
218
+
219
+/* System Control register reset values */
220
+enum {
221
+ REG_VER_RST = 0x0,
222
+ REG_EMAC_PHY_CLK_RST = 0x58000,
223
+};
224
+
225
+static uint64_t allwinner_h3_sysctrl_read(void *opaque, hwaddr offset,
226
+ unsigned size)
227
+{
228
+ const AwH3SysCtrlState *s = AW_H3_SYSCTRL(opaque);
229
+ const uint32_t idx = REG_INDEX(offset);
230
+
231
+ if (idx >= AW_H3_SYSCTRL_REGS_NUM) {
232
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
233
+ __func__, (uint32_t)offset);
234
+ return 0;
26
+ }
235
+ }
27
+}
236
+
28
+
237
+ return s->regs[idx];
29
+static void omap_i2c_writefn(void *opaque, hwaddr addr,
238
+}
30
+ uint64_t value, unsigned size)
239
+
31
+{
240
+static void allwinner_h3_sysctrl_write(void *opaque, hwaddr offset,
32
+ switch (size) {
241
+ uint64_t val, unsigned size)
33
+ case 1:
242
+{
34
+ /* Only the last fifo write can be 8 bit. */
243
+ AwH3SysCtrlState *s = AW_H3_SYSCTRL(opaque);
35
+ omap_i2c_writeb(opaque, addr, value);
244
+ const uint32_t idx = REG_INDEX(offset);
36
+ break;
245
+
37
+ case 2:
246
+ if (idx >= AW_H3_SYSCTRL_REGS_NUM) {
38
+ omap_i2c_write(opaque, addr, value);
247
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
248
+ __func__, (uint32_t)offset);
249
+ return;
250
+ }
251
+
252
+ switch (offset) {
253
+ case REG_VER: /* Version */
39
+ break;
254
+ break;
40
+ default:
255
+ default:
41
+ omap_badwidth_write16(opaque, addr, value);
256
+ s->regs[idx] = (uint32_t) val;
42
+ break;
257
+ break;
43
+ }
258
+ }
44
+}
259
+}
45
+
260
+
46
static const MemoryRegionOps omap_i2c_ops = {
261
+static const MemoryRegionOps allwinner_h3_sysctrl_ops = {
47
- .old_mmio = {
262
+ .read = allwinner_h3_sysctrl_read,
48
- .read = {
263
+ .write = allwinner_h3_sysctrl_write,
49
- omap_badwidth_read16,
264
+ .endianness = DEVICE_NATIVE_ENDIAN,
50
- omap_i2c_read,
265
+ .valid = {
51
- omap_badwidth_read16,
266
+ .min_access_size = 4,
52
- },
267
+ .max_access_size = 4,
53
- .write = {
268
+ },
54
- omap_i2c_writeb, /* Only the last fifo write can be 8 bit. */
269
+ .impl.min_access_size = 4,
55
- omap_i2c_write,
270
+};
56
- omap_badwidth_write16,
271
+
57
- },
272
+static void allwinner_h3_sysctrl_reset(DeviceState *dev)
58
- },
273
+{
59
+ .read = omap_i2c_readfn,
274
+ AwH3SysCtrlState *s = AW_H3_SYSCTRL(dev);
60
+ .write = omap_i2c_writefn,
275
+
61
+ .valid.min_access_size = 1,
276
+ /* Set default values for registers */
62
+ .valid.max_access_size = 4,
277
+ s->regs[REG_INDEX(REG_VER)] = REG_VER_RST;
63
.endianness = DEVICE_NATIVE_ENDIAN,
278
+ s->regs[REG_INDEX(REG_EMAC_PHY_CLK)] = REG_EMAC_PHY_CLK_RST;
64
};
279
+}
65
280
+
281
+static void allwinner_h3_sysctrl_init(Object *obj)
282
+{
283
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
284
+ AwH3SysCtrlState *s = AW_H3_SYSCTRL(obj);
285
+
286
+ /* Memory mapping */
287
+ memory_region_init_io(&s->iomem, OBJECT(s), &allwinner_h3_sysctrl_ops, s,
288
+ TYPE_AW_H3_SYSCTRL, 4 * KiB);
289
+ sysbus_init_mmio(sbd, &s->iomem);
290
+}
291
+
292
+static const VMStateDescription allwinner_h3_sysctrl_vmstate = {
293
+ .name = "allwinner-h3-sysctrl",
294
+ .version_id = 1,
295
+ .minimum_version_id = 1,
296
+ .fields = (VMStateField[]) {
297
+ VMSTATE_UINT32_ARRAY(regs, AwH3SysCtrlState, AW_H3_SYSCTRL_REGS_NUM),
298
+ VMSTATE_END_OF_LIST()
299
+ }
300
+};
301
+
302
+static void allwinner_h3_sysctrl_class_init(ObjectClass *klass, void *data)
303
+{
304
+ DeviceClass *dc = DEVICE_CLASS(klass);
305
+
306
+ dc->reset = allwinner_h3_sysctrl_reset;
307
+ dc->vmsd = &allwinner_h3_sysctrl_vmstate;
308
+}
309
+
310
+static const TypeInfo allwinner_h3_sysctrl_info = {
311
+ .name = TYPE_AW_H3_SYSCTRL,
312
+ .parent = TYPE_SYS_BUS_DEVICE,
313
+ .instance_init = allwinner_h3_sysctrl_init,
314
+ .instance_size = sizeof(AwH3SysCtrlState),
315
+ .class_init = allwinner_h3_sysctrl_class_init,
316
+};
317
+
318
+static void allwinner_h3_sysctrl_register(void)
319
+{
320
+ type_register_static(&allwinner_h3_sysctrl_info);
321
+}
322
+
323
+type_init(allwinner_h3_sysctrl_register)
66
--
324
--
67
2.7.4
325
2.20.1
68
326
69
327
diff view generated by jsdifflib
1
From: Subbaraya Sundeep <sundeep.lkml@gmail.com>
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
2
2
3
Added Sytem register block of Smartfusion2.
3
Various Allwinner System on Chip designs contain multiple processors
4
This block has PLL registers which are accessed by guest.
4
that can be configured and reset using the generic CPU Configuration
5
5
module interface. This commit adds support for the Allwinner CPU
6
Signed-off-by: Subbaraya Sundeep <sundeep.lkml@gmail.com>
6
configuration interface which emulates the following features:
7
Reviewed-by: Alistair Francis <alistair.francis@xilinx.com>
7
8
Acked-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
* CPU reset
9
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
* CPU status
10
Message-id: 20170920201737.25723-3-f4bug@amsat.org
10
11
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
12
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
13
Message-id: 20200311221854.30370-7-nieklinnenbank@gmail.com
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
15
---
13
hw/misc/Makefile.objs | 1 +
16
hw/misc/Makefile.objs | 1 +
14
include/hw/misc/msf2-sysreg.h | 77 ++++++++++++++++++++
17
include/hw/arm/allwinner-h3.h | 3 +
15
hw/misc/msf2-sysreg.c | 160 ++++++++++++++++++++++++++++++++++++++++++
18
include/hw/misc/allwinner-cpucfg.h | 52 ++++++
16
hw/misc/trace-events | 5 ++
19
hw/arm/allwinner-h3.c | 9 +-
17
4 files changed, 243 insertions(+)
20
hw/misc/allwinner-cpucfg.c | 282 +++++++++++++++++++++++++++++
18
create mode 100644 include/hw/misc/msf2-sysreg.h
21
hw/misc/trace-events | 5 +
19
create mode 100644 hw/misc/msf2-sysreg.c
22
6 files changed, 351 insertions(+), 1 deletion(-)
23
create mode 100644 include/hw/misc/allwinner-cpucfg.h
24
create mode 100644 hw/misc/allwinner-cpucfg.c
20
25
21
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
26
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
22
index XXXXXXX..XXXXXXX 100644
27
index XXXXXXX..XXXXXXX 100644
23
--- a/hw/misc/Makefile.objs
28
--- a/hw/misc/Makefile.objs
24
+++ b/hw/misc/Makefile.objs
29
+++ b/hw/misc/Makefile.objs
25
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_HYPERV_TESTDEV) += hyperv_testdev.o
30
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_MACIO) += macio/
26
obj-$(CONFIG_AUX) += auxbus.o
31
common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o
27
obj-$(CONFIG_ASPEED_SOC) += aspeed_scu.o aspeed_sdmc.o
32
28
obj-y += mmio_interface.o
33
common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o
29
+obj-$(CONFIG_MSF2) += msf2-sysreg.o
34
+obj-$(CONFIG_ALLWINNER_H3) += allwinner-cpucfg.o
30
diff --git a/include/hw/misc/msf2-sysreg.h b/include/hw/misc/msf2-sysreg.h
35
common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-sysctrl.o
36
common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o
37
common-obj-$(CONFIG_NSERIES) += cbus.o
38
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
39
index XXXXXXX..XXXXXXX 100644
40
--- a/include/hw/arm/allwinner-h3.h
41
+++ b/include/hw/arm/allwinner-h3.h
42
@@ -XXX,XX +XXX,XX @@
43
#include "hw/timer/allwinner-a10-pit.h"
44
#include "hw/intc/arm_gic.h"
45
#include "hw/misc/allwinner-h3-ccu.h"
46
+#include "hw/misc/allwinner-cpucfg.h"
47
#include "hw/misc/allwinner-h3-sysctrl.h"
48
#include "target/arm/cpu.h"
49
50
@@ -XXX,XX +XXX,XX @@ enum {
51
AW_H3_GIC_CPU,
52
AW_H3_GIC_HYP,
53
AW_H3_GIC_VCPU,
54
+ AW_H3_CPUCFG,
55
AW_H3_SDRAM
56
};
57
58
@@ -XXX,XX +XXX,XX @@ typedef struct AwH3State {
59
const hwaddr *memmap;
60
AwA10PITState timer;
61
AwH3ClockCtlState ccu;
62
+ AwCpuCfgState cpucfg;
63
AwH3SysCtrlState sysctrl;
64
GICState gic;
65
MemoryRegion sram_a1;
66
diff --git a/include/hw/misc/allwinner-cpucfg.h b/include/hw/misc/allwinner-cpucfg.h
31
new file mode 100644
67
new file mode 100644
32
index XXXXXXX..XXXXXXX
68
index XXXXXXX..XXXXXXX
33
--- /dev/null
69
--- /dev/null
34
+++ b/include/hw/misc/msf2-sysreg.h
70
+++ b/include/hw/misc/allwinner-cpucfg.h
35
@@ -XXX,XX +XXX,XX @@
71
@@ -XXX,XX +XXX,XX @@
36
+/*
72
+/*
37
+ * Microsemi SmartFusion2 SYSREG
73
+ * Allwinner CPU Configuration Module emulation
38
+ *
74
+ *
39
+ * Copyright (c) 2017 Subbaraya Sundeep <sundeep.lkml@gmail.com>
75
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
40
+ *
76
+ *
41
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
77
+ * This program is free software: you can redistribute it and/or modify
42
+ * of this software and associated documentation files (the "Software"), to deal
78
+ * it under the terms of the GNU General Public License as published by
43
+ * in the Software without restriction, including without limitation the rights
79
+ * the Free Software Foundation, either version 2 of the License, or
44
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
80
+ * (at your option) any later version.
45
+ * copies of the Software, and to permit persons to whom the Software is
81
+ *
46
+ * furnished to do so, subject to the following conditions:
82
+ * This program is distributed in the hope that it will be useful,
47
+ *
83
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
48
+ * The above copyright notice and this permission notice shall be included in
84
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49
+ * all copies or substantial portions of the Software.
85
+ * GNU General Public License for more details.
50
+ *
86
+ *
51
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
87
+ * You should have received a copy of the GNU General Public License
52
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
88
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
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
+ */
89
+ */
59
+
90
+
60
+#ifndef HW_MSF2_SYSREG_H
91
+#ifndef HW_MISC_ALLWINNER_CPUCFG_H
61
+#define HW_MSF2_SYSREG_H
92
+#define HW_MISC_ALLWINNER_CPUCFG_H
62
+
93
+
94
+#include "qom/object.h"
63
+#include "hw/sysbus.h"
95
+#include "hw/sysbus.h"
64
+
96
+
65
+enum {
97
+/**
66
+ ESRAM_CR = 0x00 / 4,
98
+ * Object model
67
+ ESRAM_MAX_LAT,
99
+ * @{
68
+ DDR_CR,
100
+ */
69
+ ENVM_CR,
101
+
70
+ ENVM_REMAP_BASE_CR,
102
+#define TYPE_AW_CPUCFG "allwinner-cpucfg"
71
+ ENVM_REMAP_FAB_CR,
103
+#define AW_CPUCFG(obj) \
72
+ CC_CR,
104
+ OBJECT_CHECK(AwCpuCfgState, (obj), TYPE_AW_CPUCFG)
73
+ CC_REGION_CR,
105
+
74
+ CC_LOCK_BASE_ADDR_CR,
106
+/** @} */
75
+ CC_FLUSH_INDX_CR,
107
+
76
+ DDRB_BUF_TIMER_CR,
108
+/**
77
+ DDRB_NB_ADDR_CR,
109
+ * Allwinner CPU Configuration Module instance state
78
+ DDRB_NB_SIZE_CR,
110
+ */
79
+ DDRB_CR,
111
+typedef struct AwCpuCfgState {
80
+
112
+ /*< private >*/
81
+ SOFT_RESET_CR = 0x48 / 4,
82
+ M3_CR,
83
+
84
+ GPIO_SYSRESET_SEL_CR = 0x58 / 4,
85
+
86
+ MDDR_CR = 0x60 / 4,
87
+
88
+ MSSDDR_PLL_STATUS_LOW_CR = 0x90 / 4,
89
+ MSSDDR_PLL_STATUS_HIGH_CR,
90
+ MSSDDR_FACC1_CR,
91
+ MSSDDR_FACC2_CR,
92
+
93
+ MSSDDR_PLL_STATUS = 0x150 / 4,
94
+};
95
+
96
+#define MSF2_SYSREG_MMIO_SIZE 0x300
97
+
98
+#define TYPE_MSF2_SYSREG "msf2-sysreg"
99
+#define MSF2_SYSREG(obj) OBJECT_CHECK(MSF2SysregState, (obj), TYPE_MSF2_SYSREG)
100
+
101
+typedef struct MSF2SysregState {
102
+ SysBusDevice parent_obj;
113
+ SysBusDevice parent_obj;
114
+ /*< public >*/
103
+
115
+
104
+ MemoryRegion iomem;
116
+ MemoryRegion iomem;
105
+
117
+ uint32_t gen_ctrl;
106
+ uint8_t apb0div;
118
+ uint32_t super_standby;
107
+ uint8_t apb1div;
119
+ uint32_t entry_addr;
108
+
120
+
109
+ uint32_t regs[MSF2_SYSREG_MMIO_SIZE / 4];
121
+} AwCpuCfgState;
110
+} MSF2SysregState;
122
+
111
+
123
+#endif /* HW_MISC_ALLWINNER_CPUCFG_H */
112
+#endif /* HW_MSF2_SYSREG_H */
124
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
113
diff --git a/hw/misc/msf2-sysreg.c b/hw/misc/msf2-sysreg.c
125
index XXXXXXX..XXXXXXX 100644
126
--- a/hw/arm/allwinner-h3.c
127
+++ b/hw/arm/allwinner-h3.c
128
@@ -XXX,XX +XXX,XX @@ const hwaddr allwinner_h3_memmap[] = {
129
[AW_H3_GIC_CPU] = 0x01c82000,
130
[AW_H3_GIC_HYP] = 0x01c84000,
131
[AW_H3_GIC_VCPU] = 0x01c86000,
132
+ [AW_H3_CPUCFG] = 0x01f01c00,
133
[AW_H3_SDRAM] = 0x40000000
134
};
135
136
@@ -XXX,XX +XXX,XX @@ struct AwH3Unimplemented {
137
{ "r_wdog", 0x01f01000, 1 * KiB },
138
{ "r_prcm", 0x01f01400, 1 * KiB },
139
{ "r_twd", 0x01f01800, 1 * KiB },
140
- { "r_cpucfg", 0x01f01c00, 1 * KiB },
141
{ "r_cir-rx", 0x01f02000, 1 * KiB },
142
{ "r_twi", 0x01f02400, 1 * KiB },
143
{ "r_uart", 0x01f02800, 1 * KiB },
144
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_init(Object *obj)
145
146
sysbus_init_child_obj(obj, "sysctrl", &s->sysctrl, sizeof(s->sysctrl),
147
TYPE_AW_H3_SYSCTRL);
148
+
149
+ sysbus_init_child_obj(obj, "cpucfg", &s->cpucfg, sizeof(s->cpucfg),
150
+ TYPE_AW_CPUCFG);
151
}
152
153
static void allwinner_h3_realize(DeviceState *dev, Error **errp)
154
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
155
qdev_init_nofail(DEVICE(&s->sysctrl));
156
sysbus_mmio_map(SYS_BUS_DEVICE(&s->sysctrl), 0, s->memmap[AW_H3_SYSCTRL]);
157
158
+ /* CPU Configuration */
159
+ qdev_init_nofail(DEVICE(&s->cpucfg));
160
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->cpucfg), 0, s->memmap[AW_H3_CPUCFG]);
161
+
162
/* Universal Serial Bus */
163
sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0],
164
qdev_get_gpio_in(DEVICE(&s->gic),
165
diff --git a/hw/misc/allwinner-cpucfg.c b/hw/misc/allwinner-cpucfg.c
114
new file mode 100644
166
new file mode 100644
115
index XXXXXXX..XXXXXXX
167
index XXXXXXX..XXXXXXX
116
--- /dev/null
168
--- /dev/null
117
+++ b/hw/misc/msf2-sysreg.c
169
+++ b/hw/misc/allwinner-cpucfg.c
118
@@ -XXX,XX +XXX,XX @@
170
@@ -XXX,XX +XXX,XX @@
119
+/*
171
+/*
120
+ * System Register block model of Microsemi SmartFusion2.
172
+ * Allwinner CPU Configuration Module emulation
121
+ *
173
+ *
122
+ * Copyright (c) 2017 Subbaraya Sundeep <sundeep.lkml@gmail.com>
174
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
123
+ *
175
+ *
124
+ * This program is free software; you can redistribute it and/or
176
+ * This program is free software: you can redistribute it and/or modify
125
+ * modify it under the terms of the GNU General Public License
177
+ * it under the terms of the GNU General Public License as published by
126
+ * as published by the Free Software Foundation; either version
178
+ * the Free Software Foundation, either version 2 of the License, or
127
+ * 2 of the License, or (at your option) any later version.
179
+ * (at your option) any later version.
128
+ *
180
+ *
129
+ * You should have received a copy of the GNU General Public License along
181
+ * This program is distributed in the hope that it will be useful,
130
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
182
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
183
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
184
+ * GNU General Public License for more details.
185
+ *
186
+ * You should have received a copy of the GNU General Public License
187
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
131
+ */
188
+ */
132
+
189
+
133
+#include "qemu/osdep.h"
190
+#include "qemu/osdep.h"
134
+#include "qapi/error.h"
191
+#include "qemu/units.h"
192
+#include "hw/sysbus.h"
193
+#include "migration/vmstate.h"
135
+#include "qemu/log.h"
194
+#include "qemu/log.h"
136
+#include "hw/misc/msf2-sysreg.h"
195
+#include "qemu/module.h"
137
+#include "qemu/error-report.h"
196
+#include "qemu/error-report.h"
197
+#include "qemu/timer.h"
198
+#include "hw/core/cpu.h"
199
+#include "target/arm/arm-powerctl.h"
200
+#include "target/arm/cpu.h"
201
+#include "hw/misc/allwinner-cpucfg.h"
138
+#include "trace.h"
202
+#include "trace.h"
139
+
203
+
140
+static inline int msf2_divbits(uint32_t div)
204
+/* CPUCFG register offsets */
141
+{
205
+enum {
142
+ int r = ctz32(div);
206
+ REG_CPUS_RST_CTRL = 0x0000, /* CPUs Reset Control */
143
+
207
+ REG_CPU0_RST_CTRL = 0x0040, /* CPU#0 Reset Control */
144
+ return (div < 8) ? r : r + 1;
208
+ REG_CPU0_CTRL = 0x0044, /* CPU#0 Control */
145
+}
209
+ REG_CPU0_STATUS = 0x0048, /* CPU#0 Status */
146
+
210
+ REG_CPU1_RST_CTRL = 0x0080, /* CPU#1 Reset Control */
147
+static void msf2_sysreg_reset(DeviceState *d)
211
+ REG_CPU1_CTRL = 0x0084, /* CPU#1 Control */
148
+{
212
+ REG_CPU1_STATUS = 0x0088, /* CPU#1 Status */
149
+ MSF2SysregState *s = MSF2_SYSREG(d);
213
+ REG_CPU2_RST_CTRL = 0x00C0, /* CPU#2 Reset Control */
150
+
214
+ REG_CPU2_CTRL = 0x00C4, /* CPU#2 Control */
151
+ s->regs[MSSDDR_PLL_STATUS_LOW_CR] = 0x021A2358;
215
+ REG_CPU2_STATUS = 0x00C8, /* CPU#2 Status */
152
+ s->regs[MSSDDR_PLL_STATUS] = 0x3;
216
+ REG_CPU3_RST_CTRL = 0x0100, /* CPU#3 Reset Control */
153
+ s->regs[MSSDDR_FACC1_CR] = msf2_divbits(s->apb0div) << 5 |
217
+ REG_CPU3_CTRL = 0x0104, /* CPU#3 Control */
154
+ msf2_divbits(s->apb1div) << 2;
218
+ REG_CPU3_STATUS = 0x0108, /* CPU#3 Status */
155
+}
219
+ REG_CPU_SYS_RST = 0x0140, /* CPU System Reset */
156
+
220
+ REG_CLK_GATING = 0x0144, /* CPU Clock Gating */
157
+static uint64_t msf2_sysreg_read(void *opaque, hwaddr offset,
221
+ REG_GEN_CTRL = 0x0184, /* General Control */
158
+ unsigned size)
222
+ REG_SUPER_STANDBY = 0x01A0, /* Super Standby Flag */
159
+{
223
+ REG_ENTRY_ADDR = 0x01A4, /* Reset Entry Address */
160
+ MSF2SysregState *s = opaque;
224
+ REG_DBG_EXTERN = 0x01E4, /* Debug External */
161
+ uint32_t ret = 0;
225
+ REG_CNT64_CTRL = 0x0280, /* 64-bit Counter Control */
162
+
226
+ REG_CNT64_LOW = 0x0284, /* 64-bit Counter Low */
163
+ offset >>= 2;
227
+ REG_CNT64_HIGH = 0x0288, /* 64-bit Counter High */
164
+ if (offset < ARRAY_SIZE(s->regs)) {
228
+};
165
+ ret = s->regs[offset];
229
+
166
+ trace_msf2_sysreg_read(offset << 2, ret);
230
+/* CPUCFG register flags */
167
+ } else {
231
+enum {
168
+ qemu_log_mask(LOG_GUEST_ERROR,
232
+ CPUX_RESET_RELEASED = ((1 << 1) | (1 << 0)),
169
+ "%s: Bad offset 0x%08" HWADDR_PRIx "\n", __func__,
233
+ CPUX_STATUS_SMP = (1 << 0),
170
+ offset << 2);
234
+ CPU_SYS_RESET_RELEASED = (1 << 0),
235
+ CLK_GATING_ENABLE = ((1 << 8) | 0xF),
236
+};
237
+
238
+/* CPUCFG register reset values */
239
+enum {
240
+ REG_CLK_GATING_RST = 0x0000010F,
241
+ REG_GEN_CTRL_RST = 0x00000020,
242
+ REG_SUPER_STANDBY_RST = 0x0,
243
+ REG_CNT64_CTRL_RST = 0x0,
244
+};
245
+
246
+/* CPUCFG constants */
247
+enum {
248
+ CPU_EXCEPTION_LEVEL_ON_RESET = 3, /* EL3 */
249
+};
250
+
251
+static void allwinner_cpucfg_cpu_reset(AwCpuCfgState *s, uint8_t cpu_id)
252
+{
253
+ int ret;
254
+
255
+ trace_allwinner_cpucfg_cpu_reset(cpu_id, s->entry_addr);
256
+
257
+ ARMCPU *target_cpu = ARM_CPU(arm_get_cpu_by_id(cpu_id));
258
+ if (!target_cpu) {
259
+ /*
260
+ * Called with a bogus value for cpu_id. Guest error will
261
+ * already have been logged, we can simply return here.
262
+ */
263
+ return;
171
+ }
264
+ }
172
+
265
+ bool target_aa64 = arm_feature(&target_cpu->env, ARM_FEATURE_AARCH64);
173
+ return ret;
266
+
174
+}
267
+ ret = arm_set_cpu_on(cpu_id, s->entry_addr, 0,
175
+
268
+ CPU_EXCEPTION_LEVEL_ON_RESET, target_aa64);
176
+static void msf2_sysreg_write(void *opaque, hwaddr offset,
269
+ if (ret != QEMU_ARM_POWERCTL_RET_SUCCESS) {
177
+ uint64_t val, unsigned size)
270
+ error_report("%s: failed to bring up CPU %d: err %d",
178
+{
271
+ __func__, cpu_id, ret);
179
+ MSF2SysregState *s = opaque;
272
+ return;
180
+ uint32_t newval = val;
273
+ }
181
+
274
+}
182
+ offset >>= 2;
275
+
276
+static uint64_t allwinner_cpucfg_read(void *opaque, hwaddr offset,
277
+ unsigned size)
278
+{
279
+ const AwCpuCfgState *s = AW_CPUCFG(opaque);
280
+ uint64_t val = 0;
183
+
281
+
184
+ switch (offset) {
282
+ switch (offset) {
185
+ case MSSDDR_PLL_STATUS:
283
+ case REG_CPUS_RST_CTRL: /* CPUs Reset Control */
186
+ trace_msf2_sysreg_write_pll_status();
284
+ case REG_CPU_SYS_RST: /* CPU System Reset */
187
+ break;
285
+ val = CPU_SYS_RESET_RELEASED;
188
+
286
+ break;
189
+ case ESRAM_CR:
287
+ case REG_CPU0_RST_CTRL: /* CPU#0 Reset Control */
190
+ case DDR_CR:
288
+ case REG_CPU1_RST_CTRL: /* CPU#1 Reset Control */
191
+ case ENVM_REMAP_BASE_CR:
289
+ case REG_CPU2_RST_CTRL: /* CPU#2 Reset Control */
192
+ if (newval != s->regs[offset]) {
290
+ case REG_CPU3_RST_CTRL: /* CPU#3 Reset Control */
193
+ qemu_log_mask(LOG_UNIMP,
291
+ val = CPUX_RESET_RELEASED;
194
+ TYPE_MSF2_SYSREG": remapping not supported\n");
292
+ break;
293
+ case REG_CPU0_CTRL: /* CPU#0 Control */
294
+ case REG_CPU1_CTRL: /* CPU#1 Control */
295
+ case REG_CPU2_CTRL: /* CPU#2 Control */
296
+ case REG_CPU3_CTRL: /* CPU#3 Control */
297
+ val = 0;
298
+ break;
299
+ case REG_CPU0_STATUS: /* CPU#0 Status */
300
+ case REG_CPU1_STATUS: /* CPU#1 Status */
301
+ case REG_CPU2_STATUS: /* CPU#2 Status */
302
+ case REG_CPU3_STATUS: /* CPU#3 Status */
303
+ val = CPUX_STATUS_SMP;
304
+ break;
305
+ case REG_CLK_GATING: /* CPU Clock Gating */
306
+ val = CLK_GATING_ENABLE;
307
+ break;
308
+ case REG_GEN_CTRL: /* General Control */
309
+ val = s->gen_ctrl;
310
+ break;
311
+ case REG_SUPER_STANDBY: /* Super Standby Flag */
312
+ val = s->super_standby;
313
+ break;
314
+ case REG_ENTRY_ADDR: /* Reset Entry Address */
315
+ val = s->entry_addr;
316
+ break;
317
+ case REG_DBG_EXTERN: /* Debug External */
318
+ case REG_CNT64_CTRL: /* 64-bit Counter Control */
319
+ case REG_CNT64_LOW: /* 64-bit Counter Low */
320
+ case REG_CNT64_HIGH: /* 64-bit Counter High */
321
+ qemu_log_mask(LOG_UNIMP, "%s: unimplemented register at 0x%04x\n",
322
+ __func__, (uint32_t)offset);
323
+ break;
324
+ default:
325
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
326
+ __func__, (uint32_t)offset);
327
+ break;
328
+ }
329
+
330
+ trace_allwinner_cpucfg_read(offset, val, size);
331
+
332
+ return val;
333
+}
334
+
335
+static void allwinner_cpucfg_write(void *opaque, hwaddr offset,
336
+ uint64_t val, unsigned size)
337
+{
338
+ AwCpuCfgState *s = AW_CPUCFG(opaque);
339
+
340
+ trace_allwinner_cpucfg_write(offset, val, size);
341
+
342
+ switch (offset) {
343
+ case REG_CPUS_RST_CTRL: /* CPUs Reset Control */
344
+ case REG_CPU_SYS_RST: /* CPU System Reset */
345
+ break;
346
+ case REG_CPU0_RST_CTRL: /* CPU#0 Reset Control */
347
+ case REG_CPU1_RST_CTRL: /* CPU#1 Reset Control */
348
+ case REG_CPU2_RST_CTRL: /* CPU#2 Reset Control */
349
+ case REG_CPU3_RST_CTRL: /* CPU#3 Reset Control */
350
+ if (val) {
351
+ allwinner_cpucfg_cpu_reset(s, (offset - REG_CPU0_RST_CTRL) >> 6);
195
+ }
352
+ }
196
+ break;
353
+ break;
197
+
354
+ case REG_CPU0_CTRL: /* CPU#0 Control */
355
+ case REG_CPU1_CTRL: /* CPU#1 Control */
356
+ case REG_CPU2_CTRL: /* CPU#2 Control */
357
+ case REG_CPU3_CTRL: /* CPU#3 Control */
358
+ case REG_CPU0_STATUS: /* CPU#0 Status */
359
+ case REG_CPU1_STATUS: /* CPU#1 Status */
360
+ case REG_CPU2_STATUS: /* CPU#2 Status */
361
+ case REG_CPU3_STATUS: /* CPU#3 Status */
362
+ case REG_CLK_GATING: /* CPU Clock Gating */
363
+ break;
364
+ case REG_GEN_CTRL: /* General Control */
365
+ s->gen_ctrl = val;
366
+ break;
367
+ case REG_SUPER_STANDBY: /* Super Standby Flag */
368
+ s->super_standby = val;
369
+ break;
370
+ case REG_ENTRY_ADDR: /* Reset Entry Address */
371
+ s->entry_addr = val;
372
+ break;
373
+ case REG_DBG_EXTERN: /* Debug External */
374
+ case REG_CNT64_CTRL: /* 64-bit Counter Control */
375
+ case REG_CNT64_LOW: /* 64-bit Counter Low */
376
+ case REG_CNT64_HIGH: /* 64-bit Counter High */
377
+ qemu_log_mask(LOG_UNIMP, "%s: unimplemented register at 0x%04x\n",
378
+ __func__, (uint32_t)offset);
379
+ break;
198
+ default:
380
+ default:
199
+ if (offset < ARRAY_SIZE(s->regs)) {
381
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
200
+ trace_msf2_sysreg_write(offset << 2, newval, s->regs[offset]);
382
+ __func__, (uint32_t)offset);
201
+ s->regs[offset] = newval;
202
+ } else {
203
+ qemu_log_mask(LOG_GUEST_ERROR,
204
+ "%s: Bad offset 0x%08" HWADDR_PRIx "\n", __func__,
205
+ offset << 2);
206
+ }
207
+ break;
383
+ break;
208
+ }
384
+ }
209
+}
385
+}
210
+
386
+
211
+static const MemoryRegionOps sysreg_ops = {
387
+static const MemoryRegionOps allwinner_cpucfg_ops = {
212
+ .read = msf2_sysreg_read,
388
+ .read = allwinner_cpucfg_read,
213
+ .write = msf2_sysreg_write,
389
+ .write = allwinner_cpucfg_write,
214
+ .endianness = DEVICE_NATIVE_ENDIAN,
390
+ .endianness = DEVICE_NATIVE_ENDIAN,
215
+};
391
+ .valid = {
216
+
392
+ .min_access_size = 4,
217
+static void msf2_sysreg_init(Object *obj)
393
+ .max_access_size = 4,
218
+{
394
+ },
219
+ MSF2SysregState *s = MSF2_SYSREG(obj);
395
+ .impl.min_access_size = 4,
220
+
396
+};
221
+ memory_region_init_io(&s->iomem, obj, &sysreg_ops, s, TYPE_MSF2_SYSREG,
397
+
222
+ MSF2_SYSREG_MMIO_SIZE);
398
+static void allwinner_cpucfg_reset(DeviceState *dev)
223
+ sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
399
+{
224
+}
400
+ AwCpuCfgState *s = AW_CPUCFG(dev);
225
+
401
+
226
+static const VMStateDescription vmstate_msf2_sysreg = {
402
+ /* Set default values for registers */
227
+ .name = TYPE_MSF2_SYSREG,
403
+ s->gen_ctrl = REG_GEN_CTRL_RST;
404
+ s->super_standby = REG_SUPER_STANDBY_RST;
405
+ s->entry_addr = 0;
406
+}
407
+
408
+static void allwinner_cpucfg_init(Object *obj)
409
+{
410
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
411
+ AwCpuCfgState *s = AW_CPUCFG(obj);
412
+
413
+ /* Memory mapping */
414
+ memory_region_init_io(&s->iomem, OBJECT(s), &allwinner_cpucfg_ops, s,
415
+ TYPE_AW_CPUCFG, 1 * KiB);
416
+ sysbus_init_mmio(sbd, &s->iomem);
417
+}
418
+
419
+static const VMStateDescription allwinner_cpucfg_vmstate = {
420
+ .name = "allwinner-cpucfg",
228
+ .version_id = 1,
421
+ .version_id = 1,
229
+ .minimum_version_id = 1,
422
+ .minimum_version_id = 1,
230
+ .fields = (VMStateField[]) {
423
+ .fields = (VMStateField[]) {
231
+ VMSTATE_UINT32_ARRAY(regs, MSF2SysregState, MSF2_SYSREG_MMIO_SIZE / 4),
424
+ VMSTATE_UINT32(gen_ctrl, AwCpuCfgState),
425
+ VMSTATE_UINT32(super_standby, AwCpuCfgState),
426
+ VMSTATE_UINT32(entry_addr, AwCpuCfgState),
232
+ VMSTATE_END_OF_LIST()
427
+ VMSTATE_END_OF_LIST()
233
+ }
428
+ }
234
+};
429
+};
235
+
430
+
236
+static Property msf2_sysreg_properties[] = {
431
+static void allwinner_cpucfg_class_init(ObjectClass *klass, void *data)
237
+ /* default divisors in Libero GUI */
238
+ DEFINE_PROP_UINT8("apb0divisor", MSF2SysregState, apb0div, 2),
239
+ DEFINE_PROP_UINT8("apb1divisor", MSF2SysregState, apb1div, 2),
240
+ DEFINE_PROP_END_OF_LIST(),
241
+};
242
+
243
+static void msf2_sysreg_realize(DeviceState *dev, Error **errp)
244
+{
245
+ MSF2SysregState *s = MSF2_SYSREG(dev);
246
+
247
+ if ((s->apb0div > 32 || !is_power_of_2(s->apb0div))
248
+ || (s->apb1div > 32 || !is_power_of_2(s->apb1div))) {
249
+ error_setg(errp, "Invalid apb divisor value");
250
+ error_append_hint(errp, "apb divisor must be a power of 2"
251
+ " and maximum value is 32\n");
252
+ }
253
+}
254
+
255
+static void msf2_sysreg_class_init(ObjectClass *klass, void *data)
256
+{
432
+{
257
+ DeviceClass *dc = DEVICE_CLASS(klass);
433
+ DeviceClass *dc = DEVICE_CLASS(klass);
258
+
434
+
259
+ dc->vmsd = &vmstate_msf2_sysreg;
435
+ dc->reset = allwinner_cpucfg_reset;
260
+ dc->reset = msf2_sysreg_reset;
436
+ dc->vmsd = &allwinner_cpucfg_vmstate;
261
+ dc->props = msf2_sysreg_properties;
437
+}
262
+ dc->realize = msf2_sysreg_realize;
438
+
263
+}
439
+static const TypeInfo allwinner_cpucfg_info = {
264
+
440
+ .name = TYPE_AW_CPUCFG,
265
+static const TypeInfo msf2_sysreg_info = {
441
+ .parent = TYPE_SYS_BUS_DEVICE,
266
+ .name = TYPE_MSF2_SYSREG,
442
+ .instance_init = allwinner_cpucfg_init,
267
+ .parent = TYPE_SYS_BUS_DEVICE,
443
+ .instance_size = sizeof(AwCpuCfgState),
268
+ .class_init = msf2_sysreg_class_init,
444
+ .class_init = allwinner_cpucfg_class_init,
269
+ .instance_size = sizeof(MSF2SysregState),
445
+};
270
+ .instance_init = msf2_sysreg_init,
446
+
271
+};
447
+static void allwinner_cpucfg_register(void)
272
+
448
+{
273
+static void msf2_sysreg_register_types(void)
449
+ type_register_static(&allwinner_cpucfg_info);
274
+{
450
+}
275
+ type_register_static(&msf2_sysreg_info);
451
+
276
+}
452
+type_init(allwinner_cpucfg_register)
277
+
278
+type_init(msf2_sysreg_register_types)
279
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
453
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
280
index XXXXXXX..XXXXXXX 100644
454
index XXXXXXX..XXXXXXX 100644
281
--- a/hw/misc/trace-events
455
--- a/hw/misc/trace-events
282
+++ b/hw/misc/trace-events
456
+++ b/hw/misc/trace-events
283
@@ -XXX,XX +XXX,XX @@ mps2_scc_reset(void) "MPS2 SCC: reset"
457
@@ -XXX,XX +XXX,XX @@
284
mps2_scc_leds(char led7, char led6, char led5, char led4, char led3, char led2, char led1, char led0) "MPS2 SCC LEDs: %c%c%c%c%c%c%c%c"
458
# See docs/devel/tracing.txt for syntax documentation.
285
mps2_scc_cfg_write(unsigned function, unsigned device, uint32_t value) "MPS2 SCC config write: function %d device %d data 0x%" PRIx32
459
286
mps2_scc_cfg_read(unsigned function, unsigned device, uint32_t value) "MPS2 SCC config read: function %d device %d data 0x%" PRIx32
460
+# allwinner-cpucfg.c
287
+
461
+allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t reset_addr) "id %u, reset_addr 0x%" PRIu32
288
+# hw/misc/msf2-sysreg.c
462
+allwinner_cpucfg_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
289
+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
463
+allwinner_cpucfg_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
290
+msf2_sysreg_read(uint64_t offset, uint32_t val) "msf2-sysreg read: addr 0x%08" HWADDR_PRIx " data 0x%08" PRIx32
464
+
291
+msf2_sysreg_write_pll_status(void) "Invalid write to read only PLL status register"
465
# eccmemctl.c
466
ecc_mem_writel_mer(uint32_t val) "Write memory enable 0x%08x"
467
ecc_mem_writel_mdr(uint32_t val) "Write memory delay 0x%08x"
292
--
468
--
293
2.7.4
469
2.20.1
294
470
295
471
diff view generated by jsdifflib
1
Don't use old_mmio in the memory region ops struct.
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
2
2
3
The Security Identifier device found in various Allwinner System on Chip
4
designs gives applications a per-board unique identifier. This commit
5
adds support for the Allwinner Security Identifier using a 128-bit
6
UUID value as input.
7
8
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
9
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
10
Message-id: 20200311221854.30370-8-nieklinnenbank@gmail.com
3
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
Message-id: 1505580378-9044-7-git-send-email-peter.maydell@linaro.org
6
---
12
---
7
hw/arm/omap2.c | 49 +++++++++++++++++++++++++++++++++++++------------
13
hw/misc/Makefile.objs | 1 +
8
1 file changed, 37 insertions(+), 12 deletions(-)
14
include/hw/arm/allwinner-h3.h | 3 +
9
15
include/hw/misc/allwinner-sid.h | 60 ++++++++++++
10
diff --git a/hw/arm/omap2.c b/hw/arm/omap2.c
16
hw/arm/allwinner-h3.c | 11 ++-
11
index XXXXXXX..XXXXXXX 100644
17
hw/arm/orangepi.c | 8 ++
12
--- a/hw/arm/omap2.c
18
hw/misc/allwinner-sid.c | 168 ++++++++++++++++++++++++++++++++
13
+++ b/hw/arm/omap2.c
19
hw/misc/trace-events | 4 +
14
@@ -XXX,XX +XXX,XX @@ static void omap_sysctl_write(void *opaque, hwaddr addr,
20
7 files changed, 254 insertions(+), 1 deletion(-)
15
}
21
create mode 100644 include/hw/misc/allwinner-sid.h
22
create mode 100644 hw/misc/allwinner-sid.c
23
24
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
25
index XXXXXXX..XXXXXXX 100644
26
--- a/hw/misc/Makefile.objs
27
+++ b/hw/misc/Makefile.objs
28
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o
29
common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o
30
obj-$(CONFIG_ALLWINNER_H3) += allwinner-cpucfg.o
31
common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-sysctrl.o
32
+common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-sid.o
33
common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o
34
common-obj-$(CONFIG_NSERIES) += cbus.o
35
common-obj-$(CONFIG_ECCMEMCTL) += eccmemctl.o
36
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
37
index XXXXXXX..XXXXXXX 100644
38
--- a/include/hw/arm/allwinner-h3.h
39
+++ b/include/hw/arm/allwinner-h3.h
40
@@ -XXX,XX +XXX,XX @@
41
#include "hw/misc/allwinner-h3-ccu.h"
42
#include "hw/misc/allwinner-cpucfg.h"
43
#include "hw/misc/allwinner-h3-sysctrl.h"
44
+#include "hw/misc/allwinner-sid.h"
45
#include "target/arm/cpu.h"
46
47
/**
48
@@ -XXX,XX +XXX,XX @@ enum {
49
AW_H3_SRAM_A2,
50
AW_H3_SRAM_C,
51
AW_H3_SYSCTRL,
52
+ AW_H3_SID,
53
AW_H3_EHCI0,
54
AW_H3_OHCI0,
55
AW_H3_EHCI1,
56
@@ -XXX,XX +XXX,XX @@ typedef struct AwH3State {
57
AwH3ClockCtlState ccu;
58
AwCpuCfgState cpucfg;
59
AwH3SysCtrlState sysctrl;
60
+ AwSidState sid;
61
GICState gic;
62
MemoryRegion sram_a1;
63
MemoryRegion sram_a2;
64
diff --git a/include/hw/misc/allwinner-sid.h b/include/hw/misc/allwinner-sid.h
65
new file mode 100644
66
index XXXXXXX..XXXXXXX
67
--- /dev/null
68
+++ b/include/hw/misc/allwinner-sid.h
69
@@ -XXX,XX +XXX,XX @@
70
+/*
71
+ * Allwinner Security ID emulation
72
+ *
73
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
74
+ *
75
+ * This program is free software: you can redistribute it and/or modify
76
+ * it under the terms of the GNU General Public License as published by
77
+ * the Free Software Foundation, either version 2 of the License, or
78
+ * (at your option) any later version.
79
+ *
80
+ * This program is distributed in the hope that it will be useful,
81
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
82
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
83
+ * GNU General Public License for more details.
84
+ *
85
+ * You should have received a copy of the GNU General Public License
86
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
87
+ */
88
+
89
+#ifndef HW_MISC_ALLWINNER_SID_H
90
+#define HW_MISC_ALLWINNER_SID_H
91
+
92
+#include "qom/object.h"
93
+#include "hw/sysbus.h"
94
+#include "qemu/uuid.h"
95
+
96
+/**
97
+ * Object model
98
+ * @{
99
+ */
100
+
101
+#define TYPE_AW_SID "allwinner-sid"
102
+#define AW_SID(obj) \
103
+ OBJECT_CHECK(AwSidState, (obj), TYPE_AW_SID)
104
+
105
+/** @} */
106
+
107
+/**
108
+ * Allwinner Security ID object instance state
109
+ */
110
+typedef struct AwSidState {
111
+ /*< private >*/
112
+ SysBusDevice parent_obj;
113
+ /*< public >*/
114
+
115
+ /** Maps I/O registers in physical memory */
116
+ MemoryRegion iomem;
117
+
118
+ /** Control register defines how and what to read */
119
+ uint32_t control;
120
+
121
+ /** RdKey register contains the data retrieved by the device */
122
+ uint32_t rdkey;
123
+
124
+ /** Stores the emulated device identifier */
125
+ QemuUUID identifier;
126
+
127
+} AwSidState;
128
+
129
+#endif /* HW_MISC_ALLWINNER_SID_H */
130
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
131
index XXXXXXX..XXXXXXX 100644
132
--- a/hw/arm/allwinner-h3.c
133
+++ b/hw/arm/allwinner-h3.c
134
@@ -XXX,XX +XXX,XX @@ const hwaddr allwinner_h3_memmap[] = {
135
[AW_H3_SRAM_A2] = 0x00044000,
136
[AW_H3_SRAM_C] = 0x00010000,
137
[AW_H3_SYSCTRL] = 0x01c00000,
138
+ [AW_H3_SID] = 0x01c14000,
139
[AW_H3_EHCI0] = 0x01c1a000,
140
[AW_H3_OHCI0] = 0x01c1a400,
141
[AW_H3_EHCI1] = 0x01c1b000,
142
@@ -XXX,XX +XXX,XX @@ struct AwH3Unimplemented {
143
{ "mmc0", 0x01c0f000, 4 * KiB },
144
{ "mmc1", 0x01c10000, 4 * KiB },
145
{ "mmc2", 0x01c11000, 4 * KiB },
146
- { "sid", 0x01c14000, 1 * KiB },
147
{ "crypto", 0x01c15000, 4 * KiB },
148
{ "msgbox", 0x01c17000, 4 * KiB },
149
{ "spinlock", 0x01c18000, 4 * KiB },
150
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_init(Object *obj)
151
152
sysbus_init_child_obj(obj, "cpucfg", &s->cpucfg, sizeof(s->cpucfg),
153
TYPE_AW_CPUCFG);
154
+
155
+ sysbus_init_child_obj(obj, "sid", &s->sid, sizeof(s->sid),
156
+ TYPE_AW_SID);
157
+ object_property_add_alias(obj, "identifier", OBJECT(&s->sid),
158
+ "identifier", &error_abort);
16
}
159
}
17
160
18
+static uint64_t omap_sysctl_readfn(void *opaque, hwaddr addr,
161
static void allwinner_h3_realize(DeviceState *dev, Error **errp)
162
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
163
qdev_init_nofail(DEVICE(&s->cpucfg));
164
sysbus_mmio_map(SYS_BUS_DEVICE(&s->cpucfg), 0, s->memmap[AW_H3_CPUCFG]);
165
166
+ /* Security Identifier */
167
+ qdev_init_nofail(DEVICE(&s->sid));
168
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->sid), 0, s->memmap[AW_H3_SID]);
169
+
170
/* Universal Serial Bus */
171
sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0],
172
qdev_get_gpio_in(DEVICE(&s->gic),
173
diff --git a/hw/arm/orangepi.c b/hw/arm/orangepi.c
174
index XXXXXXX..XXXXXXX 100644
175
--- a/hw/arm/orangepi.c
176
+++ b/hw/arm/orangepi.c
177
@@ -XXX,XX +XXX,XX @@ static void orangepi_init(MachineState *machine)
178
object_property_set_int(OBJECT(h3), 24 * 1000 * 1000, "clk1-freq",
179
&error_abort);
180
181
+ /* Setup SID properties. Currently using a default fixed SID identifier. */
182
+ if (qemu_uuid_is_null(&h3->sid.identifier)) {
183
+ qdev_prop_set_string(DEVICE(h3), "identifier",
184
+ "02c00081-1111-2222-3333-000044556677");
185
+ } else if (ldl_be_p(&h3->sid.identifier.data[0]) != 0x02c00081) {
186
+ warn_report("Security Identifier value does not include H3 prefix");
187
+ }
188
+
189
/* Mark H3 object realized */
190
object_property_set_bool(OBJECT(h3), true, "realized", &error_abort);
191
192
diff --git a/hw/misc/allwinner-sid.c b/hw/misc/allwinner-sid.c
193
new file mode 100644
194
index XXXXXXX..XXXXXXX
195
--- /dev/null
196
+++ b/hw/misc/allwinner-sid.c
197
@@ -XXX,XX +XXX,XX @@
198
+/*
199
+ * Allwinner Security ID emulation
200
+ *
201
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
202
+ *
203
+ * This program is free software: you can redistribute it and/or modify
204
+ * it under the terms of the GNU General Public License as published by
205
+ * the Free Software Foundation, either version 2 of the License, or
206
+ * (at your option) any later version.
207
+ *
208
+ * This program is distributed in the hope that it will be useful,
209
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
210
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
211
+ * GNU General Public License for more details.
212
+ *
213
+ * You should have received a copy of the GNU General Public License
214
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
215
+ */
216
+
217
+#include "qemu/osdep.h"
218
+#include "qemu/units.h"
219
+#include "hw/sysbus.h"
220
+#include "migration/vmstate.h"
221
+#include "qemu/log.h"
222
+#include "qemu/module.h"
223
+#include "qemu/guest-random.h"
224
+#include "qapi/error.h"
225
+#include "hw/qdev-properties.h"
226
+#include "hw/misc/allwinner-sid.h"
227
+#include "trace.h"
228
+
229
+/* SID register offsets */
230
+enum {
231
+ REG_PRCTL = 0x40, /* Control */
232
+ REG_RDKEY = 0x60, /* Read Key */
233
+};
234
+
235
+/* SID register flags */
236
+enum {
237
+ REG_PRCTL_WRITE = 0x0002, /* Unknown write flag */
238
+ REG_PRCTL_OP_LOCK = 0xAC00, /* Lock operation */
239
+};
240
+
241
+static uint64_t allwinner_sid_read(void *opaque, hwaddr offset,
19
+ unsigned size)
242
+ unsigned size)
20
+{
243
+{
21
+ switch (size) {
244
+ const AwSidState *s = AW_SID(opaque);
22
+ case 1:
245
+ uint64_t val = 0;
23
+ return omap_sysctl_read8(opaque, addr);
246
+
24
+ case 2:
247
+ switch (offset) {
25
+ return omap_badwidth_read32(opaque, addr); /* TODO */
248
+ case REG_PRCTL: /* Control */
26
+ case 4:
249
+ val = s->control;
27
+ return omap_sysctl_read(opaque, addr);
250
+ break;
251
+ case REG_RDKEY: /* Read Key */
252
+ val = s->rdkey;
253
+ break;
28
+ default:
254
+ default:
29
+ g_assert_not_reached();
255
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
256
+ __func__, (uint32_t)offset);
257
+ return 0;
30
+ }
258
+ }
31
+}
259
+
32
+
260
+ trace_allwinner_sid_read(offset, val, size);
33
+static void omap_sysctl_writefn(void *opaque, hwaddr addr,
261
+
34
+ uint64_t value, unsigned size)
262
+ return val;
35
+{
263
+}
36
+ switch (size) {
264
+
37
+ case 1:
265
+static void allwinner_sid_write(void *opaque, hwaddr offset,
38
+ omap_sysctl_write8(opaque, addr, value);
266
+ uint64_t val, unsigned size)
39
+ break;
267
+{
40
+ case 2:
268
+ AwSidState *s = AW_SID(opaque);
41
+ omap_badwidth_write32(opaque, addr, value); /* TODO */
269
+
42
+ break;
270
+ trace_allwinner_sid_write(offset, val, size);
43
+ case 4:
271
+
44
+ omap_sysctl_write(opaque, addr, value);
272
+ switch (offset) {
273
+ case REG_PRCTL: /* Control */
274
+ s->control = val;
275
+
276
+ if ((s->control & REG_PRCTL_OP_LOCK) &&
277
+ (s->control & REG_PRCTL_WRITE)) {
278
+ uint32_t id = s->control >> 16;
279
+
280
+ if (id <= sizeof(QemuUUID) - sizeof(s->rdkey)) {
281
+ s->rdkey = ldl_be_p(&s->identifier.data[id]);
282
+ }
283
+ }
284
+ s->control &= ~REG_PRCTL_WRITE;
285
+ break;
286
+ case REG_RDKEY: /* Read Key */
45
+ break;
287
+ break;
46
+ default:
288
+ default:
47
+ g_assert_not_reached();
289
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
290
+ __func__, (uint32_t)offset);
291
+ break;
48
+ }
292
+ }
49
+}
293
+}
50
+
294
+
51
static const MemoryRegionOps omap_sysctl_ops = {
295
+static const MemoryRegionOps allwinner_sid_ops = {
52
- .old_mmio = {
296
+ .read = allwinner_sid_read,
53
- .read = {
297
+ .write = allwinner_sid_write,
54
- omap_sysctl_read8,
298
+ .endianness = DEVICE_NATIVE_ENDIAN,
55
- omap_badwidth_read32,    /* TODO */
299
+ .valid = {
56
- omap_sysctl_read,
300
+ .min_access_size = 4,
57
- },
301
+ .max_access_size = 4,
58
- .write = {
302
+ },
59
- omap_sysctl_write8,
303
+ .impl.min_access_size = 4,
60
- omap_badwidth_write32,    /* TODO */
304
+};
61
- omap_sysctl_write,
305
+
62
- },
306
+static void allwinner_sid_reset(DeviceState *dev)
63
- },
307
+{
64
+ .read = omap_sysctl_readfn,
308
+ AwSidState *s = AW_SID(dev);
65
+ .write = omap_sysctl_writefn,
309
+
66
+ .valid.min_access_size = 1,
310
+ /* Set default values for registers */
67
+ .valid.max_access_size = 4,
311
+ s->control = 0;
68
.endianness = DEVICE_NATIVE_ENDIAN,
312
+ s->rdkey = 0;
69
};
313
+}
70
314
+
315
+static void allwinner_sid_init(Object *obj)
316
+{
317
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
318
+ AwSidState *s = AW_SID(obj);
319
+
320
+ /* Memory mapping */
321
+ memory_region_init_io(&s->iomem, OBJECT(s), &allwinner_sid_ops, s,
322
+ TYPE_AW_SID, 1 * KiB);
323
+ sysbus_init_mmio(sbd, &s->iomem);
324
+}
325
+
326
+static Property allwinner_sid_properties[] = {
327
+ DEFINE_PROP_UUID_NODEFAULT("identifier", AwSidState, identifier),
328
+ DEFINE_PROP_END_OF_LIST()
329
+};
330
+
331
+static const VMStateDescription allwinner_sid_vmstate = {
332
+ .name = "allwinner-sid",
333
+ .version_id = 1,
334
+ .minimum_version_id = 1,
335
+ .fields = (VMStateField[]) {
336
+ VMSTATE_UINT32(control, AwSidState),
337
+ VMSTATE_UINT32(rdkey, AwSidState),
338
+ VMSTATE_UINT8_ARRAY_V(identifier.data, AwSidState, sizeof(QemuUUID), 1),
339
+ VMSTATE_END_OF_LIST()
340
+ }
341
+};
342
+
343
+static void allwinner_sid_class_init(ObjectClass *klass, void *data)
344
+{
345
+ DeviceClass *dc = DEVICE_CLASS(klass);
346
+
347
+ dc->reset = allwinner_sid_reset;
348
+ dc->vmsd = &allwinner_sid_vmstate;
349
+ device_class_set_props(dc, allwinner_sid_properties);
350
+}
351
+
352
+static const TypeInfo allwinner_sid_info = {
353
+ .name = TYPE_AW_SID,
354
+ .parent = TYPE_SYS_BUS_DEVICE,
355
+ .instance_init = allwinner_sid_init,
356
+ .instance_size = sizeof(AwSidState),
357
+ .class_init = allwinner_sid_class_init,
358
+};
359
+
360
+static void allwinner_sid_register(void)
361
+{
362
+ type_register_static(&allwinner_sid_info);
363
+}
364
+
365
+type_init(allwinner_sid_register)
366
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
367
index XXXXXXX..XXXXXXX 100644
368
--- a/hw/misc/trace-events
369
+++ b/hw/misc/trace-events
370
@@ -XXX,XX +XXX,XX @@ allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t reset_addr) "id %u, reset_ad
371
allwinner_cpucfg_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
372
allwinner_cpucfg_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
373
374
+# allwinner-sid.c
375
+allwinner_sid_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
376
+allwinner_sid_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
377
+
378
# eccmemctl.c
379
ecc_mem_writel_mer(uint32_t val) "Write memory enable 0x%08x"
380
ecc_mem_writel_mdr(uint32_t val) "Write memory delay 0x%08x"
71
--
381
--
72
2.7.4
382
2.20.1
73
383
74
384
diff view generated by jsdifflib
1
From: Subbaraya Sundeep <sundeep.lkml@gmail.com>
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
2
2
3
Modelled Microsemi's Smartfusion2 SPI controller.
3
The Allwinner System on Chip families sun4i and above contain
4
an integrated storage controller for Secure Digital (SD) and
5
Multi Media Card (MMC) interfaces. This commit adds support
6
for the Allwinner SD/MMC storage controller with the following
7
emulated features:
4
8
5
Signed-off-by: Subbaraya Sundeep <sundeep.lkml@gmail.com>
9
* DMA transfers
6
Reviewed-by: Alistair Francis <alistair.francis@xilinx.com>
10
* Direct FIFO I/O
7
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
11
* Short/Long format command responses
8
Message-id: 20170920201737.25723-4-f4bug@amsat.org
12
* Auto-Stop command (CMD12)
13
* Insert & remove card detection
14
15
The following boards are extended with the SD host controller:
16
17
* Cubieboard (hw/arm/cubieboard.c)
18
* Orange Pi PC (hw/arm/orangepi.c)
19
20
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
21
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
22
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
23
Message-id: 20200311221854.30370-9-nieklinnenbank@gmail.com
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
24
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
25
---
11
hw/ssi/Makefile.objs | 1 +
26
hw/sd/Makefile.objs | 1 +
12
include/hw/ssi/mss-spi.h | 58 +++++++
27
include/hw/arm/allwinner-a10.h | 2 +
13
hw/ssi/mss-spi.c | 404 +++++++++++++++++++++++++++++++++++++++++++++++
28
include/hw/arm/allwinner-h3.h | 3 +
14
3 files changed, 463 insertions(+)
29
include/hw/sd/allwinner-sdhost.h | 135 +++++
15
create mode 100644 include/hw/ssi/mss-spi.h
30
hw/arm/allwinner-a10.c | 11 +
16
create mode 100644 hw/ssi/mss-spi.c
31
hw/arm/allwinner-h3.c | 15 +-
32
hw/arm/cubieboard.c | 15 +
33
hw/arm/orangepi.c | 16 +
34
hw/sd/allwinner-sdhost.c | 854 +++++++++++++++++++++++++++++++
35
hw/arm/Kconfig | 1 +
36
hw/sd/trace-events | 7 +
37
11 files changed, 1059 insertions(+), 1 deletion(-)
38
create mode 100644 include/hw/sd/allwinner-sdhost.h
39
create mode 100644 hw/sd/allwinner-sdhost.c
17
40
18
diff --git a/hw/ssi/Makefile.objs b/hw/ssi/Makefile.objs
41
diff --git a/hw/sd/Makefile.objs b/hw/sd/Makefile.objs
19
index XXXXXXX..XXXXXXX 100644
42
index XXXXXXX..XXXXXXX 100644
20
--- a/hw/ssi/Makefile.objs
43
--- a/hw/sd/Makefile.objs
21
+++ b/hw/ssi/Makefile.objs
44
+++ b/hw/sd/Makefile.objs
22
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_XILINX_SPI) += xilinx_spi.o
45
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_SD) += sd.o core.o sdmmc-internal.o
23
common-obj-$(CONFIG_XILINX_SPIPS) += xilinx_spips.o
46
common-obj-$(CONFIG_SDHCI) += sdhci.o
24
common-obj-$(CONFIG_ASPEED_SOC) += aspeed_smc.o
47
common-obj-$(CONFIG_SDHCI_PCI) += sdhci-pci.o
25
common-obj-$(CONFIG_STM32F2XX_SPI) += stm32f2xx_spi.o
48
26
+common-obj-$(CONFIG_MSF2) += mss-spi.o
49
+common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-sdhost.o
27
50
common-obj-$(CONFIG_MILKYMIST) += milkymist-memcard.o
28
obj-$(CONFIG_OMAP) += omap_spi.o
51
common-obj-$(CONFIG_OMAP) += omap_mmc.o
29
obj-$(CONFIG_IMX) += imx_spi.o
52
common-obj-$(CONFIG_PXA2XX) += pxa2xx_mmci.o
30
diff --git a/include/hw/ssi/mss-spi.h b/include/hw/ssi/mss-spi.h
53
diff --git a/include/hw/arm/allwinner-a10.h b/include/hw/arm/allwinner-a10.h
54
index XXXXXXX..XXXXXXX 100644
55
--- a/include/hw/arm/allwinner-a10.h
56
+++ b/include/hw/arm/allwinner-a10.h
57
@@ -XXX,XX +XXX,XX @@
58
#include "hw/timer/allwinner-a10-pit.h"
59
#include "hw/intc/allwinner-a10-pic.h"
60
#include "hw/net/allwinner_emac.h"
61
+#include "hw/sd/allwinner-sdhost.h"
62
#include "hw/ide/ahci.h"
63
#include "hw/usb/hcd-ohci.h"
64
#include "hw/usb/hcd-ehci.h"
65
@@ -XXX,XX +XXX,XX @@ typedef struct AwA10State {
66
AwA10PICState intc;
67
AwEmacState emac;
68
AllwinnerAHCIState sata;
69
+ AwSdHostState mmc0;
70
MemoryRegion sram_a;
71
EHCISysBusState ehci[AW_A10_NUM_USB];
72
OHCISysBusState ohci[AW_A10_NUM_USB];
73
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
74
index XXXXXXX..XXXXXXX 100644
75
--- a/include/hw/arm/allwinner-h3.h
76
+++ b/include/hw/arm/allwinner-h3.h
77
@@ -XXX,XX +XXX,XX @@
78
#include "hw/misc/allwinner-cpucfg.h"
79
#include "hw/misc/allwinner-h3-sysctrl.h"
80
#include "hw/misc/allwinner-sid.h"
81
+#include "hw/sd/allwinner-sdhost.h"
82
#include "target/arm/cpu.h"
83
84
/**
85
@@ -XXX,XX +XXX,XX @@ enum {
86
AW_H3_SRAM_A2,
87
AW_H3_SRAM_C,
88
AW_H3_SYSCTRL,
89
+ AW_H3_MMC0,
90
AW_H3_SID,
91
AW_H3_EHCI0,
92
AW_H3_OHCI0,
93
@@ -XXX,XX +XXX,XX @@ typedef struct AwH3State {
94
AwCpuCfgState cpucfg;
95
AwH3SysCtrlState sysctrl;
96
AwSidState sid;
97
+ AwSdHostState mmc0;
98
GICState gic;
99
MemoryRegion sram_a1;
100
MemoryRegion sram_a2;
101
diff --git a/include/hw/sd/allwinner-sdhost.h b/include/hw/sd/allwinner-sdhost.h
31
new file mode 100644
102
new file mode 100644
32
index XXXXXXX..XXXXXXX
103
index XXXXXXX..XXXXXXX
33
--- /dev/null
104
--- /dev/null
34
+++ b/include/hw/ssi/mss-spi.h
105
+++ b/include/hw/sd/allwinner-sdhost.h
35
@@ -XXX,XX +XXX,XX @@
106
@@ -XXX,XX +XXX,XX @@
36
+/*
107
+/*
37
+ * Microsemi SmartFusion2 SPI
108
+ * Allwinner (sun4i and above) SD Host Controller emulation
38
+ *
109
+ *
39
+ * Copyright (c) 2017 Subbaraya Sundeep <sundeep.lkml@gmail.com>
110
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
40
+ *
111
+ *
41
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
112
+ * This program is free software: you can redistribute it and/or modify
42
+ * of this software and associated documentation files (the "Software"), to deal
113
+ * it under the terms of the GNU General Public License as published by
43
+ * in the Software without restriction, including without limitation the rights
114
+ * the Free Software Foundation, either version 2 of the License, or
44
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
115
+ * (at your option) any later version.
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
+ *
116
+ *
48
+ * The above copyright notice and this permission notice shall be included in
117
+ * This program is distributed in the hope that it will be useful,
49
+ * all copies or substantial portions of the Software.
118
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
119
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
120
+ * GNU General Public License for more details.
50
+ *
121
+ *
51
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
122
+ * You should have received a copy of the GNU General Public License
52
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
123
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
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
+ */
124
+ */
59
+
125
+
60
+#ifndef HW_MSS_SPI_H
126
+#ifndef HW_SD_ALLWINNER_SDHOST_H
61
+#define HW_MSS_SPI_H
127
+#define HW_SD_ALLWINNER_SDHOST_H
62
+
128
+
129
+#include "qom/object.h"
63
+#include "hw/sysbus.h"
130
+#include "hw/sysbus.h"
64
+#include "hw/ssi/ssi.h"
131
+#include "hw/sd/sd.h"
65
+#include "qemu/fifo32.h"
132
+
66
+
133
+/**
67
+#define TYPE_MSS_SPI "mss-spi"
134
+ * Object model types
68
+#define MSS_SPI(obj) OBJECT_CHECK(MSSSpiState, (obj), TYPE_MSS_SPI)
135
+ * @{
69
+
136
+ */
70
+#define R_SPI_MAX 16
137
+
71
+
138
+/** Generic Allwinner SD Host Controller (abstract) */
72
+typedef struct MSSSpiState {
139
+#define TYPE_AW_SDHOST "allwinner-sdhost"
73
+ SysBusDevice parent_obj;
140
+
74
+
141
+/** Allwinner sun4i family (A10, A12) */
75
+ MemoryRegion mmio;
142
+#define TYPE_AW_SDHOST_SUN4I TYPE_AW_SDHOST "-sun4i"
76
+
143
+
144
+/** Allwinner sun5i family and newer (A13, H2+, H3, etc) */
145
+#define TYPE_AW_SDHOST_SUN5I TYPE_AW_SDHOST "-sun5i"
146
+
147
+/** @} */
148
+
149
+/**
150
+ * Object model macros
151
+ * @{
152
+ */
153
+
154
+#define AW_SDHOST(obj) \
155
+ OBJECT_CHECK(AwSdHostState, (obj), TYPE_AW_SDHOST)
156
+#define AW_SDHOST_CLASS(klass) \
157
+ OBJECT_CLASS_CHECK(AwSdHostClass, (klass), TYPE_AW_SDHOST)
158
+#define AW_SDHOST_GET_CLASS(obj) \
159
+ OBJECT_GET_CLASS(AwSdHostClass, (obj), TYPE_AW_SDHOST)
160
+
161
+/** @} */
162
+
163
+/**
164
+ * Allwinner SD Host Controller object instance state.
165
+ */
166
+typedef struct AwSdHostState {
167
+ /*< private >*/
168
+ SysBusDevice busdev;
169
+ /*< public >*/
170
+
171
+ /** Secure Digital (SD) bus, which connects to SD card (if present) */
172
+ SDBus sdbus;
173
+
174
+ /** Maps I/O registers in physical memory */
175
+ MemoryRegion iomem;
176
+
177
+ /** Interrupt output signal to notify CPU */
77
+ qemu_irq irq;
178
+ qemu_irq irq;
78
+
179
+
79
+ qemu_irq cs_line;
180
+ /** Number of bytes left in current DMA transfer */
80
+
181
+ uint32_t transfer_cnt;
81
+ SSIBus *spi;
182
+
82
+
183
+ /**
83
+ Fifo32 rx_fifo;
184
+ * @name Hardware Registers
84
+ Fifo32 tx_fifo;
185
+ * @{
85
+
186
+ */
86
+ int fifo_depth;
187
+
87
+ uint32_t frame_count;
188
+ uint32_t global_ctl; /**< Global Control */
88
+ bool enabled;
189
+ uint32_t clock_ctl; /**< Clock Control */
89
+
190
+ uint32_t timeout; /**< Timeout */
90
+ uint32_t regs[R_SPI_MAX];
191
+ uint32_t bus_width; /**< Bus Width */
91
+} MSSSpiState;
192
+ uint32_t block_size; /**< Block Size */
92
+
193
+ uint32_t byte_count; /**< Byte Count */
93
+#endif /* HW_MSS_SPI_H */
194
+
94
diff --git a/hw/ssi/mss-spi.c b/hw/ssi/mss-spi.c
195
+ uint32_t command; /**< Command */
196
+ uint32_t command_arg; /**< Command Argument */
197
+ uint32_t response[4]; /**< Command Response */
198
+
199
+ uint32_t irq_mask; /**< Interrupt Mask */
200
+ uint32_t irq_status; /**< Raw Interrupt Status */
201
+ uint32_t status; /**< Status */
202
+
203
+ uint32_t fifo_wlevel; /**< FIFO Water Level */
204
+ uint32_t fifo_func_sel; /**< FIFO Function Select */
205
+ uint32_t debug_enable; /**< Debug Enable */
206
+ uint32_t auto12_arg; /**< Auto Command 12 Argument */
207
+ uint32_t newtiming_set; /**< SD New Timing Set */
208
+ uint32_t newtiming_debug; /**< SD New Timing Debug */
209
+ uint32_t hardware_rst; /**< Hardware Reset */
210
+ uint32_t dmac; /**< Internal DMA Controller Control */
211
+ uint32_t desc_base; /**< Descriptor List Base Address */
212
+ uint32_t dmac_status; /**< Internal DMA Controller Status */
213
+ uint32_t dmac_irq; /**< Internal DMA Controller IRQ Enable */
214
+ uint32_t card_threshold; /**< Card Threshold Control */
215
+ uint32_t startbit_detect; /**< eMMC DDR Start Bit Detection Control */
216
+ uint32_t response_crc; /**< Response CRC */
217
+ uint32_t data_crc[8]; /**< Data CRC */
218
+ uint32_t status_crc; /**< Status CRC */
219
+
220
+ /** @} */
221
+
222
+} AwSdHostState;
223
+
224
+/**
225
+ * Allwinner SD Host Controller class-level struct.
226
+ *
227
+ * This struct is filled by each sunxi device specific code
228
+ * such that the generic code can use this struct to support
229
+ * all devices.
230
+ */
231
+typedef struct AwSdHostClass {
232
+ /*< private >*/
233
+ SysBusDeviceClass parent_class;
234
+ /*< public >*/
235
+
236
+ /** Maximum buffer size in bytes per DMA descriptor */
237
+ size_t max_desc_size;
238
+
239
+} AwSdHostClass;
240
+
241
+#endif /* HW_SD_ALLWINNER_SDHOST_H */
242
diff --git a/hw/arm/allwinner-a10.c b/hw/arm/allwinner-a10.c
243
index XXXXXXX..XXXXXXX 100644
244
--- a/hw/arm/allwinner-a10.c
245
+++ b/hw/arm/allwinner-a10.c
246
@@ -XXX,XX +XXX,XX @@
247
#include "hw/boards.h"
248
#include "hw/usb/hcd-ohci.h"
249
250
+#define AW_A10_MMC0_BASE 0x01c0f000
251
#define AW_A10_PIC_REG_BASE 0x01c20400
252
#define AW_A10_PIT_REG_BASE 0x01c20c00
253
#define AW_A10_UART0_REG_BASE 0x01c28000
254
@@ -XXX,XX +XXX,XX @@ static void aw_a10_init(Object *obj)
255
sizeof(s->ohci[i]), TYPE_SYSBUS_OHCI);
256
}
257
}
258
+
259
+ sysbus_init_child_obj(obj, "mmc0", &s->mmc0, sizeof(s->mmc0),
260
+ TYPE_AW_SDHOST_SUN4I);
261
}
262
263
static void aw_a10_realize(DeviceState *dev, Error **errp)
264
@@ -XXX,XX +XXX,XX @@ static void aw_a10_realize(DeviceState *dev, Error **errp)
265
qdev_get_gpio_in(dev, 64 + i));
266
}
267
}
268
+
269
+ /* SD/MMC */
270
+ qdev_init_nofail(DEVICE(&s->mmc0));
271
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->mmc0), 0, AW_A10_MMC0_BASE);
272
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->mmc0), 0, qdev_get_gpio_in(dev, 32));
273
+ object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->mmc0),
274
+ "sd-bus", &error_abort);
275
}
276
277
static void aw_a10_class_init(ObjectClass *oc, void *data)
278
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
279
index XXXXXXX..XXXXXXX 100644
280
--- a/hw/arm/allwinner-h3.c
281
+++ b/hw/arm/allwinner-h3.c
282
@@ -XXX,XX +XXX,XX @@ const hwaddr allwinner_h3_memmap[] = {
283
[AW_H3_SRAM_A2] = 0x00044000,
284
[AW_H3_SRAM_C] = 0x00010000,
285
[AW_H3_SYSCTRL] = 0x01c00000,
286
+ [AW_H3_MMC0] = 0x01c0f000,
287
[AW_H3_SID] = 0x01c14000,
288
[AW_H3_EHCI0] = 0x01c1a000,
289
[AW_H3_OHCI0] = 0x01c1a400,
290
@@ -XXX,XX +XXX,XX @@ struct AwH3Unimplemented {
291
{ "lcd0", 0x01c0c000, 4 * KiB },
292
{ "lcd1", 0x01c0d000, 4 * KiB },
293
{ "ve", 0x01c0e000, 4 * KiB },
294
- { "mmc0", 0x01c0f000, 4 * KiB },
295
{ "mmc1", 0x01c10000, 4 * KiB },
296
{ "mmc2", 0x01c11000, 4 * KiB },
297
{ "crypto", 0x01c15000, 4 * KiB },
298
@@ -XXX,XX +XXX,XX @@ enum {
299
AW_H3_GIC_SPI_UART3 = 3,
300
AW_H3_GIC_SPI_TIMER0 = 18,
301
AW_H3_GIC_SPI_TIMER1 = 19,
302
+ AW_H3_GIC_SPI_MMC0 = 60,
303
AW_H3_GIC_SPI_EHCI0 = 72,
304
AW_H3_GIC_SPI_OHCI0 = 73,
305
AW_H3_GIC_SPI_EHCI1 = 74,
306
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_init(Object *obj)
307
TYPE_AW_SID);
308
object_property_add_alias(obj, "identifier", OBJECT(&s->sid),
309
"identifier", &error_abort);
310
+
311
+ sysbus_init_child_obj(obj, "mmc0", &s->mmc0, sizeof(s->mmc0),
312
+ TYPE_AW_SDHOST_SUN5I);
313
}
314
315
static void allwinner_h3_realize(DeviceState *dev, Error **errp)
316
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
317
qdev_init_nofail(DEVICE(&s->sid));
318
sysbus_mmio_map(SYS_BUS_DEVICE(&s->sid), 0, s->memmap[AW_H3_SID]);
319
320
+ /* SD/MMC */
321
+ qdev_init_nofail(DEVICE(&s->mmc0));
322
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->mmc0), 0, s->memmap[AW_H3_MMC0]);
323
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->mmc0), 0,
324
+ qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_MMC0));
325
+
326
+ object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->mmc0),
327
+ "sd-bus", &error_abort);
328
+
329
/* Universal Serial Bus */
330
sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0],
331
qdev_get_gpio_in(DEVICE(&s->gic),
332
diff --git a/hw/arm/cubieboard.c b/hw/arm/cubieboard.c
333
index XXXXXXX..XXXXXXX 100644
334
--- a/hw/arm/cubieboard.c
335
+++ b/hw/arm/cubieboard.c
336
@@ -XXX,XX +XXX,XX @@
337
#include "sysemu/sysemu.h"
338
#include "hw/sysbus.h"
339
#include "hw/boards.h"
340
+#include "hw/qdev-properties.h"
341
#include "hw/arm/allwinner-a10.h"
342
343
static struct arm_boot_info cubieboard_binfo = {
344
@@ -XXX,XX +XXX,XX @@ static void cubieboard_init(MachineState *machine)
345
{
346
AwA10State *a10;
347
Error *err = NULL;
348
+ DriveInfo *di;
349
+ BlockBackend *blk;
350
+ BusState *bus;
351
+ DeviceState *carddev;
352
353
/* BIOS is not supported by this board */
354
if (bios_name) {
355
@@ -XXX,XX +XXX,XX @@ static void cubieboard_init(MachineState *machine)
356
exit(1);
357
}
358
359
+ /* Retrieve SD bus */
360
+ di = drive_get_next(IF_SD);
361
+ blk = di ? blk_by_legacy_dinfo(di) : NULL;
362
+ bus = qdev_get_child_bus(DEVICE(a10), "sd-bus");
363
+
364
+ /* Plug in SD card */
365
+ carddev = qdev_create(bus, TYPE_SD_CARD);
366
+ qdev_prop_set_drive(carddev, "drive", blk, &error_fatal);
367
+ object_property_set_bool(OBJECT(carddev), true, "realized", &error_fatal);
368
+
369
memory_region_add_subregion(get_system_memory(), AW_A10_SDRAM_BASE,
370
machine->ram);
371
372
diff --git a/hw/arm/orangepi.c b/hw/arm/orangepi.c
373
index XXXXXXX..XXXXXXX 100644
374
--- a/hw/arm/orangepi.c
375
+++ b/hw/arm/orangepi.c
376
@@ -XXX,XX +XXX,XX @@ static struct arm_boot_info orangepi_binfo = {
377
static void orangepi_init(MachineState *machine)
378
{
379
AwH3State *h3;
380
+ DriveInfo *di;
381
+ BlockBackend *blk;
382
+ BusState *bus;
383
+ DeviceState *carddev;
384
385
/* BIOS is not supported by this board */
386
if (bios_name) {
387
@@ -XXX,XX +XXX,XX @@ static void orangepi_init(MachineState *machine)
388
/* Mark H3 object realized */
389
object_property_set_bool(OBJECT(h3), true, "realized", &error_abort);
390
391
+ /* Retrieve SD bus */
392
+ di = drive_get_next(IF_SD);
393
+ blk = di ? blk_by_legacy_dinfo(di) : NULL;
394
+ bus = qdev_get_child_bus(DEVICE(h3), "sd-bus");
395
+
396
+ /* Plug in SD card */
397
+ carddev = qdev_create(bus, TYPE_SD_CARD);
398
+ qdev_prop_set_drive(carddev, "drive", blk, &error_fatal);
399
+ object_property_set_bool(OBJECT(carddev), true, "realized", &error_fatal);
400
+
401
/* SDRAM */
402
memory_region_add_subregion(get_system_memory(), h3->memmap[AW_H3_SDRAM],
403
machine->ram);
404
@@ -XXX,XX +XXX,XX @@ static void orangepi_machine_init(MachineClass *mc)
405
{
406
mc->desc = "Orange Pi PC";
407
mc->init = orangepi_init;
408
+ mc->block_default_type = IF_SD;
409
+ mc->units_per_default_bus = 1;
410
mc->min_cpus = AW_H3_NUM_CPUS;
411
mc->max_cpus = AW_H3_NUM_CPUS;
412
mc->default_cpus = AW_H3_NUM_CPUS;
413
diff --git a/hw/sd/allwinner-sdhost.c b/hw/sd/allwinner-sdhost.c
95
new file mode 100644
414
new file mode 100644
96
index XXXXXXX..XXXXXXX
415
index XXXXXXX..XXXXXXX
97
--- /dev/null
416
--- /dev/null
98
+++ b/hw/ssi/mss-spi.c
417
+++ b/hw/sd/allwinner-sdhost.c
99
@@ -XXX,XX +XXX,XX @@
418
@@ -XXX,XX +XXX,XX @@
100
+/*
419
+/*
101
+ * Block model of SPI controller present in
420
+ * Allwinner (sun4i and above) SD Host Controller emulation
102
+ * Microsemi's SmartFusion2 and SmartFusion SoCs.
103
+ *
421
+ *
104
+ * Copyright (C) 2017 Subbaraya Sundeep <sundeep.lkml@gmail.com>
422
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
105
+ *
423
+ *
106
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
424
+ * This program is free software: you can redistribute it and/or modify
107
+ * of this software and associated documentation files (the "Software"), to deal
425
+ * it under the terms of the GNU General Public License as published by
108
+ * in the Software without restriction, including without limitation the rights
426
+ * the Free Software Foundation, either version 2 of the License, or
109
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
427
+ * (at your option) any later version.
110
+ * copies of the Software, and to permit persons to whom the Software is
111
+ * furnished to do so, subject to the following conditions:
112
+ *
428
+ *
113
+ * The above copyright notice and this permission notice shall be included in
429
+ * This program is distributed in the hope that it will be useful,
114
+ * all copies or substantial portions of the Software.
430
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
431
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
432
+ * GNU General Public License for more details.
115
+ *
433
+ *
116
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
434
+ * You should have received a copy of the GNU General Public License
117
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
435
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
118
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
119
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
120
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
121
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
122
+ * THE SOFTWARE.
123
+ */
436
+ */
124
+
437
+
125
+#include "qemu/osdep.h"
438
+#include "qemu/osdep.h"
126
+#include "hw/ssi/mss-spi.h"
127
+#include "qemu/log.h"
439
+#include "qemu/log.h"
128
+
440
+#include "qemu/module.h"
129
+#ifndef MSS_SPI_ERR_DEBUG
441
+#include "qemu/units.h"
130
+#define MSS_SPI_ERR_DEBUG 0
442
+#include "sysemu/blockdev.h"
131
+#endif
443
+#include "hw/irq.h"
132
+
444
+#include "hw/sd/allwinner-sdhost.h"
133
+#define DB_PRINT_L(lvl, fmt, args...) do { \
445
+#include "migration/vmstate.h"
134
+ if (MSS_SPI_ERR_DEBUG >= lvl) { \
446
+#include "trace.h"
135
+ qemu_log("%s: " fmt "\n", __func__, ## args); \
447
+
136
+ } \
448
+#define TYPE_AW_SDHOST_BUS "allwinner-sdhost-bus"
137
+} while (0);
449
+#define AW_SDHOST_BUS(obj) \
138
+
450
+ OBJECT_CHECK(SDBus, (obj), TYPE_AW_SDHOST_BUS)
139
+#define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
451
+
140
+
452
+/* SD Host register offsets */
141
+#define FIFO_CAPACITY 32
453
+enum {
142
+
454
+ REG_SD_GCTL = 0x00, /* Global Control */
143
+#define R_SPI_CONTROL 0
455
+ REG_SD_CKCR = 0x04, /* Clock Control */
144
+#define R_SPI_DFSIZE 1
456
+ REG_SD_TMOR = 0x08, /* Timeout */
145
+#define R_SPI_STATUS 2
457
+ REG_SD_BWDR = 0x0C, /* Bus Width */
146
+#define R_SPI_INTCLR 3
458
+ REG_SD_BKSR = 0x10, /* Block Size */
147
+#define R_SPI_RX 4
459
+ REG_SD_BYCR = 0x14, /* Byte Count */
148
+#define R_SPI_TX 5
460
+ REG_SD_CMDR = 0x18, /* Command */
149
+#define R_SPI_CLKGEN 6
461
+ REG_SD_CAGR = 0x1C, /* Command Argument */
150
+#define R_SPI_SS 7
462
+ REG_SD_RESP0 = 0x20, /* Response Zero */
151
+#define R_SPI_MIS 8
463
+ REG_SD_RESP1 = 0x24, /* Response One */
152
+#define R_SPI_RIS 9
464
+ REG_SD_RESP2 = 0x28, /* Response Two */
153
+
465
+ REG_SD_RESP3 = 0x2C, /* Response Three */
154
+#define S_TXDONE (1 << 0)
466
+ REG_SD_IMKR = 0x30, /* Interrupt Mask */
155
+#define S_RXRDY (1 << 1)
467
+ REG_SD_MISR = 0x34, /* Masked Interrupt Status */
156
+#define S_RXCHOVRF (1 << 2)
468
+ REG_SD_RISR = 0x38, /* Raw Interrupt Status */
157
+#define S_RXFIFOFUL (1 << 4)
469
+ REG_SD_STAR = 0x3C, /* Status */
158
+#define S_RXFIFOFULNXT (1 << 5)
470
+ REG_SD_FWLR = 0x40, /* FIFO Water Level */
159
+#define S_RXFIFOEMP (1 << 6)
471
+ REG_SD_FUNS = 0x44, /* FIFO Function Select */
160
+#define S_RXFIFOEMPNXT (1 << 7)
472
+ REG_SD_DBGC = 0x50, /* Debug Enable */
161
+#define S_TXFIFOFUL (1 << 8)
473
+ REG_SD_A12A = 0x58, /* Auto command 12 argument */
162
+#define S_TXFIFOFULNXT (1 << 9)
474
+ REG_SD_NTSR = 0x5C, /* SD NewTiming Set */
163
+#define S_TXFIFOEMP (1 << 10)
475
+ REG_SD_SDBG = 0x60, /* SD newTiming Set Debug */
164
+#define S_TXFIFOEMPNXT (1 << 11)
476
+ REG_SD_HWRST = 0x78, /* Hardware Reset Register */
165
+#define S_FRAMESTART (1 << 12)
477
+ REG_SD_DMAC = 0x80, /* Internal DMA Controller Control */
166
+#define S_SSEL (1 << 13)
478
+ REG_SD_DLBA = 0x84, /* Descriptor List Base Address */
167
+#define S_ACTIVE (1 << 14)
479
+ REG_SD_IDST = 0x88, /* Internal DMA Controller Status */
168
+
480
+ REG_SD_IDIE = 0x8C, /* Internal DMA Controller IRQ Enable */
169
+#define C_ENABLE (1 << 0)
481
+ REG_SD_THLDC = 0x100, /* Card Threshold Control */
170
+#define C_MODE (1 << 1)
482
+ REG_SD_DSBD = 0x10C, /* eMMC DDR Start Bit Detection Control */
171
+#define C_INTRXDATA (1 << 4)
483
+ REG_SD_RES_CRC = 0x110, /* Response CRC from card/eMMC */
172
+#define C_INTTXDATA (1 << 5)
484
+ REG_SD_DATA7_CRC = 0x114, /* CRC Data 7 from card/eMMC */
173
+#define C_INTRXOVRFLO (1 << 6)
485
+ REG_SD_DATA6_CRC = 0x118, /* CRC Data 6 from card/eMMC */
174
+#define C_SPS (1 << 26)
486
+ REG_SD_DATA5_CRC = 0x11C, /* CRC Data 5 from card/eMMC */
175
+#define C_BIGFIFO (1 << 29)
487
+ REG_SD_DATA4_CRC = 0x120, /* CRC Data 4 from card/eMMC */
176
+#define C_RESET (1 << 31)
488
+ REG_SD_DATA3_CRC = 0x124, /* CRC Data 3 from card/eMMC */
177
+
489
+ REG_SD_DATA2_CRC = 0x128, /* CRC Data 2 from card/eMMC */
178
+#define FRAMESZ_MASK 0x1F
490
+ REG_SD_DATA1_CRC = 0x12C, /* CRC Data 1 from card/eMMC */
179
+#define FMCOUNT_MASK 0x00FFFF00
491
+ REG_SD_DATA0_CRC = 0x130, /* CRC Data 0 from card/eMMC */
180
+#define FMCOUNT_SHIFT 8
492
+ REG_SD_CRC_STA = 0x134, /* CRC status from card/eMMC during write */
181
+
493
+ REG_SD_FIFO = 0x200, /* Read/Write FIFO */
182
+static void txfifo_reset(MSSSpiState *s)
494
+};
183
+{
495
+
184
+ fifo32_reset(&s->tx_fifo);
496
+/* SD Host register flags */
185
+
497
+enum {
186
+ s->regs[R_SPI_STATUS] &= ~S_TXFIFOFUL;
498
+ SD_GCTL_FIFO_AC_MOD = (1 << 31),
187
+ s->regs[R_SPI_STATUS] |= S_TXFIFOEMP;
499
+ SD_GCTL_DDR_MOD_SEL = (1 << 10),
188
+}
500
+ SD_GCTL_CD_DBC_ENB = (1 << 8),
189
+
501
+ SD_GCTL_DMA_ENB = (1 << 5),
190
+static void rxfifo_reset(MSSSpiState *s)
502
+ SD_GCTL_INT_ENB = (1 << 4),
191
+{
503
+ SD_GCTL_DMA_RST = (1 << 2),
192
+ fifo32_reset(&s->rx_fifo);
504
+ SD_GCTL_FIFO_RST = (1 << 1),
193
+
505
+ SD_GCTL_SOFT_RST = (1 << 0),
194
+ s->regs[R_SPI_STATUS] &= ~S_RXFIFOFUL;
506
+};
195
+ s->regs[R_SPI_STATUS] |= S_RXFIFOEMP;
507
+
196
+}
508
+enum {
197
+
509
+ SD_CMDR_LOAD = (1 << 31),
198
+static void set_fifodepth(MSSSpiState *s)
510
+ SD_CMDR_CLKCHANGE = (1 << 21),
199
+{
511
+ SD_CMDR_WRITE = (1 << 10),
200
+ unsigned int size = s->regs[R_SPI_DFSIZE] & FRAMESZ_MASK;
512
+ SD_CMDR_AUTOSTOP = (1 << 12),
201
+
513
+ SD_CMDR_DATA = (1 << 9),
202
+ if (size <= 8) {
514
+ SD_CMDR_RESPONSE_LONG = (1 << 7),
203
+ s->fifo_depth = 32;
515
+ SD_CMDR_RESPONSE = (1 << 6),
204
+ } else if (size <= 16) {
516
+ SD_CMDR_CMDID_MASK = (0x3f),
205
+ s->fifo_depth = 16;
517
+};
206
+ } else if (size <= 32) {
518
+
207
+ s->fifo_depth = 8;
519
+enum {
520
+ SD_RISR_CARD_REMOVE = (1 << 31),
521
+ SD_RISR_CARD_INSERT = (1 << 30),
522
+ SD_RISR_SDIO_INTR = (1 << 16),
523
+ SD_RISR_AUTOCMD_DONE = (1 << 14),
524
+ SD_RISR_DATA_COMPLETE = (1 << 3),
525
+ SD_RISR_CMD_COMPLETE = (1 << 2),
526
+ SD_RISR_NO_RESPONSE = (1 << 1),
527
+};
528
+
529
+enum {
530
+ SD_STAR_CARD_PRESENT = (1 << 8),
531
+};
532
+
533
+enum {
534
+ SD_IDST_INT_SUMMARY = (1 << 8),
535
+ SD_IDST_RECEIVE_IRQ = (1 << 1),
536
+ SD_IDST_TRANSMIT_IRQ = (1 << 0),
537
+ SD_IDST_IRQ_MASK = (1 << 1) | (1 << 0) | (1 << 8),
538
+ SD_IDST_WR_MASK = (0x3ff),
539
+};
540
+
541
+/* SD Host register reset values */
542
+enum {
543
+ REG_SD_GCTL_RST = 0x00000300,
544
+ REG_SD_CKCR_RST = 0x0,
545
+ REG_SD_TMOR_RST = 0xFFFFFF40,
546
+ REG_SD_BWDR_RST = 0x0,
547
+ REG_SD_BKSR_RST = 0x00000200,
548
+ REG_SD_BYCR_RST = 0x00000200,
549
+ REG_SD_CMDR_RST = 0x0,
550
+ REG_SD_CAGR_RST = 0x0,
551
+ REG_SD_RESP_RST = 0x0,
552
+ REG_SD_IMKR_RST = 0x0,
553
+ REG_SD_MISR_RST = 0x0,
554
+ REG_SD_RISR_RST = 0x0,
555
+ REG_SD_STAR_RST = 0x00000100,
556
+ REG_SD_FWLR_RST = 0x000F0000,
557
+ REG_SD_FUNS_RST = 0x0,
558
+ REG_SD_DBGC_RST = 0x0,
559
+ REG_SD_A12A_RST = 0x0000FFFF,
560
+ REG_SD_NTSR_RST = 0x00000001,
561
+ REG_SD_SDBG_RST = 0x0,
562
+ REG_SD_HWRST_RST = 0x00000001,
563
+ REG_SD_DMAC_RST = 0x0,
564
+ REG_SD_DLBA_RST = 0x0,
565
+ REG_SD_IDST_RST = 0x0,
566
+ REG_SD_IDIE_RST = 0x0,
567
+ REG_SD_THLDC_RST = 0x0,
568
+ REG_SD_DSBD_RST = 0x0,
569
+ REG_SD_RES_CRC_RST = 0x0,
570
+ REG_SD_DATA_CRC_RST = 0x0,
571
+ REG_SD_CRC_STA_RST = 0x0,
572
+ REG_SD_FIFO_RST = 0x0,
573
+};
574
+
575
+/* Data transfer descriptor for DMA */
576
+typedef struct TransferDescriptor {
577
+ uint32_t status; /* Status flags */
578
+ uint32_t size; /* Data buffer size */
579
+ uint32_t addr; /* Data buffer address */
580
+ uint32_t next; /* Physical address of next descriptor */
581
+} TransferDescriptor;
582
+
583
+/* Data transfer descriptor flags */
584
+enum {
585
+ DESC_STATUS_HOLD = (1 << 31), /* Set when descriptor is in use by DMA */
586
+ DESC_STATUS_ERROR = (1 << 30), /* Set when DMA transfer error occurred */
587
+ DESC_STATUS_CHAIN = (1 << 4), /* Indicates chained descriptor. */
588
+ DESC_STATUS_FIRST = (1 << 3), /* Set on the first descriptor */
589
+ DESC_STATUS_LAST = (1 << 2), /* Set on the last descriptor */
590
+ DESC_STATUS_NOIRQ = (1 << 1), /* Skip raising interrupt after transfer */
591
+ DESC_SIZE_MASK = (0xfffffffc)
592
+};
593
+
594
+static void allwinner_sdhost_update_irq(AwSdHostState *s)
595
+{
596
+ uint32_t irq;
597
+
598
+ if (s->global_ctl & SD_GCTL_INT_ENB) {
599
+ irq = s->irq_status & s->irq_mask;
208
+ } else {
600
+ } else {
209
+ s->fifo_depth = 4;
601
+ irq = 0;
210
+ }
602
+ }
211
+}
603
+
212
+
604
+ trace_allwinner_sdhost_update_irq(irq);
213
+static void update_mis(MSSSpiState *s)
214
+{
215
+ uint32_t reg = s->regs[R_SPI_CONTROL];
216
+ uint32_t tmp;
217
+
218
+ /*
219
+ * form the Control register interrupt enable bits
220
+ * same as RIS, MIS and Interrupt clear registers for simplicity
221
+ */
222
+ tmp = ((reg & C_INTRXOVRFLO) >> 4) | ((reg & C_INTRXDATA) >> 3) |
223
+ ((reg & C_INTTXDATA) >> 5);
224
+ s->regs[R_SPI_MIS] |= tmp & s->regs[R_SPI_RIS];
225
+}
226
+
227
+static void spi_update_irq(MSSSpiState *s)
228
+{
229
+ int irq;
230
+
231
+ update_mis(s);
232
+ irq = !!(s->regs[R_SPI_MIS]);
233
+
234
+ qemu_set_irq(s->irq, irq);
605
+ qemu_set_irq(s->irq, irq);
235
+}
606
+}
236
+
607
+
237
+static void mss_spi_reset(DeviceState *d)
608
+static void allwinner_sdhost_update_transfer_cnt(AwSdHostState *s,
238
+{
609
+ uint32_t bytes)
239
+ MSSSpiState *s = MSS_SPI(d);
610
+{
240
+
611
+ if (s->transfer_cnt > bytes) {
241
+ memset(s->regs, 0, sizeof s->regs);
612
+ s->transfer_cnt -= bytes;
242
+ s->regs[R_SPI_CONTROL] = 0x80000102;
613
+ } else {
243
+ s->regs[R_SPI_DFSIZE] = 0x4;
614
+ s->transfer_cnt = 0;
244
+ s->regs[R_SPI_STATUS] = S_SSEL | S_TXFIFOEMP | S_RXFIFOEMP;
615
+ }
245
+ s->regs[R_SPI_CLKGEN] = 0x7;
616
+
246
+ s->regs[R_SPI_RIS] = 0x0;
617
+ if (!s->transfer_cnt) {
247
+
618
+ s->irq_status |= SD_RISR_DATA_COMPLETE;
248
+ s->fifo_depth = 4;
619
+ }
249
+ s->frame_count = 1;
620
+}
250
+ s->enabled = false;
621
+
251
+
622
+static void allwinner_sdhost_set_inserted(DeviceState *dev, bool inserted)
252
+ rxfifo_reset(s);
623
+{
253
+ txfifo_reset(s);
624
+ AwSdHostState *s = AW_SDHOST(dev);
254
+}
625
+
255
+
626
+ trace_allwinner_sdhost_set_inserted(inserted);
256
+static uint64_t
627
+
257
+spi_read(void *opaque, hwaddr addr, unsigned int size)
628
+ if (inserted) {
258
+{
629
+ s->irq_status |= SD_RISR_CARD_INSERT;
259
+ MSSSpiState *s = opaque;
630
+ s->irq_status &= ~SD_RISR_CARD_REMOVE;
260
+ uint32_t ret = 0;
631
+ s->status |= SD_STAR_CARD_PRESENT;
261
+
632
+ } else {
262
+ addr >>= 2;
633
+ s->irq_status &= ~SD_RISR_CARD_INSERT;
263
+ switch (addr) {
634
+ s->irq_status |= SD_RISR_CARD_REMOVE;
264
+ case R_SPI_RX:
635
+ s->status &= ~SD_STAR_CARD_PRESENT;
265
+ s->regs[R_SPI_STATUS] &= ~S_RXFIFOFUL;
636
+ }
266
+ s->regs[R_SPI_STATUS] &= ~S_RXCHOVRF;
637
+
267
+ ret = fifo32_pop(&s->rx_fifo);
638
+ allwinner_sdhost_update_irq(s);
268
+ if (fifo32_is_empty(&s->rx_fifo)) {
639
+}
269
+ s->regs[R_SPI_STATUS] |= S_RXFIFOEMP;
640
+
641
+static void allwinner_sdhost_send_command(AwSdHostState *s)
642
+{
643
+ SDRequest request;
644
+ uint8_t resp[16];
645
+ int rlen;
646
+
647
+ /* Auto clear load flag */
648
+ s->command &= ~SD_CMDR_LOAD;
649
+
650
+ /* Clock change does not actually interact with the SD bus */
651
+ if (!(s->command & SD_CMDR_CLKCHANGE)) {
652
+
653
+ /* Prepare request */
654
+ request.cmd = s->command & SD_CMDR_CMDID_MASK;
655
+ request.arg = s->command_arg;
656
+
657
+ /* Send request to SD bus */
658
+ rlen = sdbus_do_command(&s->sdbus, &request, resp);
659
+ if (rlen < 0) {
660
+ goto error;
270
+ }
661
+ }
271
+ break;
662
+
272
+
663
+ /* If the command has a response, store it in the response registers */
273
+ case R_SPI_MIS:
664
+ if ((s->command & SD_CMDR_RESPONSE)) {
274
+ update_mis(s);
665
+ if (rlen == 4 && !(s->command & SD_CMDR_RESPONSE_LONG)) {
275
+ ret = s->regs[R_SPI_MIS];
666
+ s->response[0] = ldl_be_p(&resp[0]);
276
+ break;
667
+ s->response[1] = s->response[2] = s->response[3] = 0;
277
+
668
+
278
+ default:
669
+ } else if (rlen == 16 && (s->command & SD_CMDR_RESPONSE_LONG)) {
279
+ if (addr < ARRAY_SIZE(s->regs)) {
670
+ s->response[0] = ldl_be_p(&resp[12]);
280
+ ret = s->regs[addr];
671
+ s->response[1] = ldl_be_p(&resp[8]);
281
+ } else {
672
+ s->response[2] = ldl_be_p(&resp[4]);
282
+ qemu_log_mask(LOG_GUEST_ERROR,
673
+ s->response[3] = ldl_be_p(&resp[0]);
283
+ "%s: Bad offset 0x%" HWADDR_PRIx "\n", __func__,
674
+ } else {
284
+ addr * 4);
675
+ goto error;
285
+ return ret;
286
+ }
287
+ break;
288
+ }
289
+
290
+ DB_PRINT("addr=0x%" HWADDR_PRIx " = 0x%" PRIx32, addr * 4, ret);
291
+ spi_update_irq(s);
292
+ return ret;
293
+}
294
+
295
+static void assert_cs(MSSSpiState *s)
296
+{
297
+ qemu_set_irq(s->cs_line, 0);
298
+}
299
+
300
+static void deassert_cs(MSSSpiState *s)
301
+{
302
+ qemu_set_irq(s->cs_line, 1);
303
+}
304
+
305
+static void spi_flush_txfifo(MSSSpiState *s)
306
+{
307
+ uint32_t tx;
308
+ uint32_t rx;
309
+ bool sps = !!(s->regs[R_SPI_CONTROL] & C_SPS);
310
+
311
+ /*
312
+ * Chip Select(CS) is automatically controlled by this controller.
313
+ * If SPS bit is set in Control register then CS is asserted
314
+ * until all the frames set in frame count of Control register are
315
+ * transferred. If SPS is not set then CS pulses between frames.
316
+ * Note that Slave Select register specifies which of the CS line
317
+ * has to be controlled automatically by controller. Bits SS[7:1] are for
318
+ * masters in FPGA fabric since we model only Microcontroller subsystem
319
+ * of Smartfusion2 we control only one CS(SS[0]) line.
320
+ */
321
+ while (!fifo32_is_empty(&s->tx_fifo) && s->frame_count) {
322
+ assert_cs(s);
323
+
324
+ s->regs[R_SPI_STATUS] &= ~(S_TXDONE | S_RXRDY);
325
+
326
+ tx = fifo32_pop(&s->tx_fifo);
327
+ DB_PRINT("data tx:0x%" PRIx32, tx);
328
+ rx = ssi_transfer(s->spi, tx);
329
+ DB_PRINT("data rx:0x%" PRIx32, rx);
330
+
331
+ if (fifo32_num_used(&s->rx_fifo) == s->fifo_depth) {
332
+ s->regs[R_SPI_STATUS] |= S_RXCHOVRF;
333
+ s->regs[R_SPI_RIS] |= S_RXCHOVRF;
334
+ } else {
335
+ fifo32_push(&s->rx_fifo, rx);
336
+ s->regs[R_SPI_STATUS] &= ~S_RXFIFOEMP;
337
+ if (fifo32_num_used(&s->rx_fifo) == (s->fifo_depth - 1)) {
338
+ s->regs[R_SPI_STATUS] |= S_RXFIFOFULNXT;
339
+ } else if (fifo32_num_used(&s->rx_fifo) == s->fifo_depth) {
340
+ s->regs[R_SPI_STATUS] |= S_RXFIFOFUL;
341
+ }
676
+ }
342
+ }
677
+ }
343
+ s->frame_count--;
678
+ }
344
+ if (!sps) {
679
+
345
+ deassert_cs(s);
680
+ /* Set interrupt status bits */
681
+ s->irq_status |= SD_RISR_CMD_COMPLETE;
682
+ return;
683
+
684
+error:
685
+ s->irq_status |= SD_RISR_NO_RESPONSE;
686
+}
687
+
688
+static void allwinner_sdhost_auto_stop(AwSdHostState *s)
689
+{
690
+ /*
691
+ * The stop command (CMD12) ensures the SD bus
692
+ * returns to the transfer state.
693
+ */
694
+ if ((s->command & SD_CMDR_AUTOSTOP) && (s->transfer_cnt == 0)) {
695
+ /* First save current command registers */
696
+ uint32_t saved_cmd = s->command;
697
+ uint32_t saved_arg = s->command_arg;
698
+
699
+ /* Prepare stop command (CMD12) */
700
+ s->command &= ~SD_CMDR_CMDID_MASK;
701
+ s->command |= 12; /* CMD12 */
702
+ s->command_arg = 0;
703
+
704
+ /* Put the command on SD bus */
705
+ allwinner_sdhost_send_command(s);
706
+
707
+ /* Restore command values */
708
+ s->command = saved_cmd;
709
+ s->command_arg = saved_arg;
710
+
711
+ /* Set IRQ status bit for automatic stop done */
712
+ s->irq_status |= SD_RISR_AUTOCMD_DONE;
713
+ }
714
+}
715
+
716
+static uint32_t allwinner_sdhost_process_desc(AwSdHostState *s,
717
+ hwaddr desc_addr,
718
+ TransferDescriptor *desc,
719
+ bool is_write, uint32_t max_bytes)
720
+{
721
+ AwSdHostClass *klass = AW_SDHOST_GET_CLASS(s);
722
+ uint32_t num_done = 0;
723
+ uint32_t num_bytes = max_bytes;
724
+ uint8_t buf[1024];
725
+
726
+ /* Read descriptor */
727
+ cpu_physical_memory_read(desc_addr, desc, sizeof(*desc));
728
+ if (desc->size == 0) {
729
+ desc->size = klass->max_desc_size;
730
+ } else if (desc->size > klass->max_desc_size) {
731
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: DMA descriptor buffer size "
732
+ " is out-of-bounds: %" PRIu32 " > %zu",
733
+ __func__, desc->size, klass->max_desc_size);
734
+ desc->size = klass->max_desc_size;
735
+ }
736
+ if (desc->size < num_bytes) {
737
+ num_bytes = desc->size;
738
+ }
739
+
740
+ trace_allwinner_sdhost_process_desc(desc_addr, desc->size,
741
+ is_write, max_bytes);
742
+
743
+ while (num_done < num_bytes) {
744
+ /* Try to completely fill the local buffer */
745
+ uint32_t buf_bytes = num_bytes - num_done;
746
+ if (buf_bytes > sizeof(buf)) {
747
+ buf_bytes = sizeof(buf);
346
+ }
748
+ }
347
+ }
749
+
348
+
750
+ /* Write to SD bus */
349
+ if (!s->frame_count) {
751
+ if (is_write) {
350
+ s->frame_count = (s->regs[R_SPI_CONTROL] & FMCOUNT_MASK) >>
752
+ cpu_physical_memory_read((desc->addr & DESC_SIZE_MASK) + num_done,
351
+ FMCOUNT_SHIFT;
753
+ buf, buf_bytes);
352
+ deassert_cs(s);
754
+
353
+ s->regs[R_SPI_RIS] |= S_TXDONE | S_RXRDY;
755
+ for (uint32_t i = 0; i < buf_bytes; i++) {
354
+ s->regs[R_SPI_STATUS] |= S_TXDONE | S_RXRDY;
756
+ sdbus_write_data(&s->sdbus, buf[i]);
355
+ }
757
+ }
356
+}
758
+
357
+
759
+ /* Read from SD bus */
358
+static void spi_write(void *opaque, hwaddr addr,
760
+ } else {
359
+ uint64_t val64, unsigned int size)
761
+ for (uint32_t i = 0; i < buf_bytes; i++) {
360
+{
762
+ buf[i] = sdbus_read_data(&s->sdbus);
361
+ MSSSpiState *s = opaque;
763
+ }
362
+ uint32_t value = val64;
764
+ cpu_physical_memory_write((desc->addr & DESC_SIZE_MASK) + num_done,
363
+
765
+ buf, buf_bytes);
364
+ DB_PRINT("addr=0x%" HWADDR_PRIx " =0x%" PRIx32, addr, value);
766
+ }
365
+ addr >>= 2;
767
+ num_done += buf_bytes;
366
+
768
+ }
367
+ switch (addr) {
769
+
368
+ case R_SPI_TX:
770
+ /* Clear hold flag and flush descriptor */
369
+ /* adding to already full FIFO */
771
+ desc->status &= ~DESC_STATUS_HOLD;
370
+ if (fifo32_num_used(&s->tx_fifo) == s->fifo_depth) {
772
+ cpu_physical_memory_write(desc_addr, desc, sizeof(*desc));
773
+
774
+ return num_done;
775
+}
776
+
777
+static void allwinner_sdhost_dma(AwSdHostState *s)
778
+{
779
+ TransferDescriptor desc;
780
+ hwaddr desc_addr = s->desc_base;
781
+ bool is_write = (s->command & SD_CMDR_WRITE);
782
+ uint32_t bytes_done = 0;
783
+
784
+ /* Check if DMA can be performed */
785
+ if (s->byte_count == 0 || s->block_size == 0 ||
786
+ !(s->global_ctl & SD_GCTL_DMA_ENB)) {
787
+ return;
788
+ }
789
+
790
+ /*
791
+ * For read operations, data must be available on the SD bus
792
+ * If not, it is an error and we should not act at all
793
+ */
794
+ if (!is_write && !sdbus_data_ready(&s->sdbus)) {
795
+ return;
796
+ }
797
+
798
+ /* Process the DMA descriptors until all data is copied */
799
+ while (s->byte_count > 0) {
800
+ bytes_done = allwinner_sdhost_process_desc(s, desc_addr, &desc,
801
+ is_write, s->byte_count);
802
+ allwinner_sdhost_update_transfer_cnt(s, bytes_done);
803
+
804
+ if (bytes_done <= s->byte_count) {
805
+ s->byte_count -= bytes_done;
806
+ } else {
807
+ s->byte_count = 0;
808
+ }
809
+
810
+ if (desc.status & DESC_STATUS_LAST) {
371
+ break;
811
+ break;
812
+ } else {
813
+ desc_addr = desc.next;
372
+ }
814
+ }
373
+ s->regs[R_SPI_STATUS] &= ~S_TXFIFOEMP;
815
+ }
374
+ fifo32_push(&s->tx_fifo, value);
816
+
375
+ if (fifo32_num_used(&s->tx_fifo) == (s->fifo_depth - 1)) {
817
+ /* Raise IRQ to signal DMA is completed */
376
+ s->regs[R_SPI_STATUS] |= S_TXFIFOFULNXT;
818
+ s->irq_status |= SD_RISR_DATA_COMPLETE | SD_RISR_SDIO_INTR;
377
+ } else if (fifo32_num_used(&s->tx_fifo) == s->fifo_depth) {
819
+
378
+ s->regs[R_SPI_STATUS] |= S_TXFIFOFUL;
820
+ /* Update DMAC bits */
821
+ s->dmac_status |= SD_IDST_INT_SUMMARY;
822
+
823
+ if (is_write) {
824
+ s->dmac_status |= SD_IDST_TRANSMIT_IRQ;
825
+ } else {
826
+ s->dmac_status |= SD_IDST_RECEIVE_IRQ;
827
+ }
828
+}
829
+
830
+static uint64_t allwinner_sdhost_read(void *opaque, hwaddr offset,
831
+ unsigned size)
832
+{
833
+ AwSdHostState *s = AW_SDHOST(opaque);
834
+ uint32_t res = 0;
835
+
836
+ switch (offset) {
837
+ case REG_SD_GCTL: /* Global Control */
838
+ res = s->global_ctl;
839
+ break;
840
+ case REG_SD_CKCR: /* Clock Control */
841
+ res = s->clock_ctl;
842
+ break;
843
+ case REG_SD_TMOR: /* Timeout */
844
+ res = s->timeout;
845
+ break;
846
+ case REG_SD_BWDR: /* Bus Width */
847
+ res = s->bus_width;
848
+ break;
849
+ case REG_SD_BKSR: /* Block Size */
850
+ res = s->block_size;
851
+ break;
852
+ case REG_SD_BYCR: /* Byte Count */
853
+ res = s->byte_count;
854
+ break;
855
+ case REG_SD_CMDR: /* Command */
856
+ res = s->command;
857
+ break;
858
+ case REG_SD_CAGR: /* Command Argument */
859
+ res = s->command_arg;
860
+ break;
861
+ case REG_SD_RESP0: /* Response Zero */
862
+ res = s->response[0];
863
+ break;
864
+ case REG_SD_RESP1: /* Response One */
865
+ res = s->response[1];
866
+ break;
867
+ case REG_SD_RESP2: /* Response Two */
868
+ res = s->response[2];
869
+ break;
870
+ case REG_SD_RESP3: /* Response Three */
871
+ res = s->response[3];
872
+ break;
873
+ case REG_SD_IMKR: /* Interrupt Mask */
874
+ res = s->irq_mask;
875
+ break;
876
+ case REG_SD_MISR: /* Masked Interrupt Status */
877
+ res = s->irq_status & s->irq_mask;
878
+ break;
879
+ case REG_SD_RISR: /* Raw Interrupt Status */
880
+ res = s->irq_status;
881
+ break;
882
+ case REG_SD_STAR: /* Status */
883
+ res = s->status;
884
+ break;
885
+ case REG_SD_FWLR: /* FIFO Water Level */
886
+ res = s->fifo_wlevel;
887
+ break;
888
+ case REG_SD_FUNS: /* FIFO Function Select */
889
+ res = s->fifo_func_sel;
890
+ break;
891
+ case REG_SD_DBGC: /* Debug Enable */
892
+ res = s->debug_enable;
893
+ break;
894
+ case REG_SD_A12A: /* Auto command 12 argument */
895
+ res = s->auto12_arg;
896
+ break;
897
+ case REG_SD_NTSR: /* SD NewTiming Set */
898
+ res = s->newtiming_set;
899
+ break;
900
+ case REG_SD_SDBG: /* SD newTiming Set Debug */
901
+ res = s->newtiming_debug;
902
+ break;
903
+ case REG_SD_HWRST: /* Hardware Reset Register */
904
+ res = s->hardware_rst;
905
+ break;
906
+ case REG_SD_DMAC: /* Internal DMA Controller Control */
907
+ res = s->dmac;
908
+ break;
909
+ case REG_SD_DLBA: /* Descriptor List Base Address */
910
+ res = s->desc_base;
911
+ break;
912
+ case REG_SD_IDST: /* Internal DMA Controller Status */
913
+ res = s->dmac_status;
914
+ break;
915
+ case REG_SD_IDIE: /* Internal DMA Controller Interrupt Enable */
916
+ res = s->dmac_irq;
917
+ break;
918
+ case REG_SD_THLDC: /* Card Threshold Control */
919
+ res = s->card_threshold;
920
+ break;
921
+ case REG_SD_DSBD: /* eMMC DDR Start Bit Detection Control */
922
+ res = s->startbit_detect;
923
+ break;
924
+ case REG_SD_RES_CRC: /* Response CRC from card/eMMC */
925
+ res = s->response_crc;
926
+ break;
927
+ case REG_SD_DATA7_CRC: /* CRC Data 7 from card/eMMC */
928
+ case REG_SD_DATA6_CRC: /* CRC Data 6 from card/eMMC */
929
+ case REG_SD_DATA5_CRC: /* CRC Data 5 from card/eMMC */
930
+ case REG_SD_DATA4_CRC: /* CRC Data 4 from card/eMMC */
931
+ case REG_SD_DATA3_CRC: /* CRC Data 3 from card/eMMC */
932
+ case REG_SD_DATA2_CRC: /* CRC Data 2 from card/eMMC */
933
+ case REG_SD_DATA1_CRC: /* CRC Data 1 from card/eMMC */
934
+ case REG_SD_DATA0_CRC: /* CRC Data 0 from card/eMMC */
935
+ res = s->data_crc[((offset - REG_SD_DATA7_CRC) / sizeof(uint32_t))];
936
+ break;
937
+ case REG_SD_CRC_STA: /* CRC status from card/eMMC in write operation */
938
+ res = s->status_crc;
939
+ break;
940
+ case REG_SD_FIFO: /* Read/Write FIFO */
941
+ if (sdbus_data_ready(&s->sdbus)) {
942
+ res = sdbus_read_data(&s->sdbus);
943
+ res |= sdbus_read_data(&s->sdbus) << 8;
944
+ res |= sdbus_read_data(&s->sdbus) << 16;
945
+ res |= sdbus_read_data(&s->sdbus) << 24;
946
+ allwinner_sdhost_update_transfer_cnt(s, sizeof(uint32_t));
947
+ allwinner_sdhost_auto_stop(s);
948
+ allwinner_sdhost_update_irq(s);
949
+ } else {
950
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: no data ready on SD bus\n",
951
+ __func__);
379
+ }
952
+ }
380
+ if (s->enabled) {
953
+ break;
381
+ spi_flush_txfifo(s);
954
+ default:
955
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset %"
956
+ HWADDR_PRIx"\n", __func__, offset);
957
+ res = 0;
958
+ break;
959
+ }
960
+
961
+ trace_allwinner_sdhost_read(offset, res, size);
962
+ return res;
963
+}
964
+
965
+static void allwinner_sdhost_write(void *opaque, hwaddr offset,
966
+ uint64_t value, unsigned size)
967
+{
968
+ AwSdHostState *s = AW_SDHOST(opaque);
969
+
970
+ trace_allwinner_sdhost_write(offset, value, size);
971
+
972
+ switch (offset) {
973
+ case REG_SD_GCTL: /* Global Control */
974
+ s->global_ctl = value;
975
+ s->global_ctl &= ~(SD_GCTL_DMA_RST | SD_GCTL_FIFO_RST |
976
+ SD_GCTL_SOFT_RST);
977
+ allwinner_sdhost_update_irq(s);
978
+ break;
979
+ case REG_SD_CKCR: /* Clock Control */
980
+ s->clock_ctl = value;
981
+ break;
982
+ case REG_SD_TMOR: /* Timeout */
983
+ s->timeout = value;
984
+ break;
985
+ case REG_SD_BWDR: /* Bus Width */
986
+ s->bus_width = value;
987
+ break;
988
+ case REG_SD_BKSR: /* Block Size */
989
+ s->block_size = value;
990
+ break;
991
+ case REG_SD_BYCR: /* Byte Count */
992
+ s->byte_count = value;
993
+ s->transfer_cnt = value;
994
+ break;
995
+ case REG_SD_CMDR: /* Command */
996
+ s->command = value;
997
+ if (value & SD_CMDR_LOAD) {
998
+ allwinner_sdhost_send_command(s);
999
+ allwinner_sdhost_dma(s);
1000
+ allwinner_sdhost_auto_stop(s);
382
+ }
1001
+ }
383
+ break;
1002
+ allwinner_sdhost_update_irq(s);
384
+
1003
+ break;
385
+ case R_SPI_CONTROL:
1004
+ case REG_SD_CAGR: /* Command Argument */
386
+ s->regs[R_SPI_CONTROL] = value;
1005
+ s->command_arg = value;
387
+ if (value & C_BIGFIFO) {
1006
+ break;
388
+ set_fifodepth(s);
1007
+ case REG_SD_RESP0: /* Response Zero */
389
+ } else {
1008
+ s->response[0] = value;
390
+ s->fifo_depth = 4;
1009
+ break;
391
+ }
1010
+ case REG_SD_RESP1: /* Response One */
392
+ s->enabled = value & C_ENABLE;
1011
+ s->response[1] = value;
393
+ s->frame_count = (value & FMCOUNT_MASK) >> FMCOUNT_SHIFT;
1012
+ break;
394
+ if (value & C_RESET) {
1013
+ case REG_SD_RESP2: /* Response Two */
395
+ mss_spi_reset(DEVICE(s));
1014
+ s->response[2] = value;
396
+ }
1015
+ break;
397
+ break;
1016
+ case REG_SD_RESP3: /* Response Three */
398
+
1017
+ s->response[3] = value;
399
+ case R_SPI_DFSIZE:
1018
+ break;
400
+ if (s->enabled) {
1019
+ case REG_SD_IMKR: /* Interrupt Mask */
401
+ break;
1020
+ s->irq_mask = value;
402
+ }
1021
+ allwinner_sdhost_update_irq(s);
403
+ s->regs[R_SPI_DFSIZE] = value;
1022
+ break;
404
+ break;
1023
+ case REG_SD_MISR: /* Masked Interrupt Status */
405
+
1024
+ case REG_SD_RISR: /* Raw Interrupt Status */
406
+ case R_SPI_INTCLR:
1025
+ s->irq_status &= ~value;
407
+ s->regs[R_SPI_INTCLR] = value;
1026
+ allwinner_sdhost_update_irq(s);
408
+ if (value & S_TXDONE) {
1027
+ break;
409
+ s->regs[R_SPI_RIS] &= ~S_TXDONE;
1028
+ case REG_SD_STAR: /* Status */
410
+ }
1029
+ s->status &= ~value;
411
+ if (value & S_RXRDY) {
1030
+ allwinner_sdhost_update_irq(s);
412
+ s->regs[R_SPI_RIS] &= ~S_RXRDY;
1031
+ break;
413
+ }
1032
+ case REG_SD_FWLR: /* FIFO Water Level */
414
+ if (value & S_RXCHOVRF) {
1033
+ s->fifo_wlevel = value;
415
+ s->regs[R_SPI_RIS] &= ~S_RXCHOVRF;
1034
+ break;
416
+ }
1035
+ case REG_SD_FUNS: /* FIFO Function Select */
417
+ break;
1036
+ s->fifo_func_sel = value;
418
+
1037
+ break;
419
+ case R_SPI_MIS:
1038
+ case REG_SD_DBGC: /* Debug Enable */
420
+ case R_SPI_STATUS:
1039
+ s->debug_enable = value;
421
+ case R_SPI_RIS:
1040
+ break;
422
+ qemu_log_mask(LOG_GUEST_ERROR,
1041
+ case REG_SD_A12A: /* Auto command 12 argument */
423
+ "%s: Write to read only register 0x%" HWADDR_PRIx "\n",
1042
+ s->auto12_arg = value;
424
+ __func__, addr * 4);
1043
+ break;
425
+ break;
1044
+ case REG_SD_NTSR: /* SD NewTiming Set */
426
+
1045
+ s->newtiming_set = value;
1046
+ break;
1047
+ case REG_SD_SDBG: /* SD newTiming Set Debug */
1048
+ s->newtiming_debug = value;
1049
+ break;
1050
+ case REG_SD_HWRST: /* Hardware Reset Register */
1051
+ s->hardware_rst = value;
1052
+ break;
1053
+ case REG_SD_DMAC: /* Internal DMA Controller Control */
1054
+ s->dmac = value;
1055
+ allwinner_sdhost_update_irq(s);
1056
+ break;
1057
+ case REG_SD_DLBA: /* Descriptor List Base Address */
1058
+ s->desc_base = value;
1059
+ break;
1060
+ case REG_SD_IDST: /* Internal DMA Controller Status */
1061
+ s->dmac_status &= (~SD_IDST_WR_MASK) | (~value & SD_IDST_WR_MASK);
1062
+ allwinner_sdhost_update_irq(s);
1063
+ break;
1064
+ case REG_SD_IDIE: /* Internal DMA Controller Interrupt Enable */
1065
+ s->dmac_irq = value;
1066
+ allwinner_sdhost_update_irq(s);
1067
+ break;
1068
+ case REG_SD_THLDC: /* Card Threshold Control */
1069
+ s->card_threshold = value;
1070
+ break;
1071
+ case REG_SD_DSBD: /* eMMC DDR Start Bit Detection Control */
1072
+ s->startbit_detect = value;
1073
+ break;
1074
+ case REG_SD_FIFO: /* Read/Write FIFO */
1075
+ sdbus_write_data(&s->sdbus, value & 0xff);
1076
+ sdbus_write_data(&s->sdbus, (value >> 8) & 0xff);
1077
+ sdbus_write_data(&s->sdbus, (value >> 16) & 0xff);
1078
+ sdbus_write_data(&s->sdbus, (value >> 24) & 0xff);
1079
+ allwinner_sdhost_update_transfer_cnt(s, sizeof(uint32_t));
1080
+ allwinner_sdhost_auto_stop(s);
1081
+ allwinner_sdhost_update_irq(s);
1082
+ break;
1083
+ case REG_SD_RES_CRC: /* Response CRC from card/eMMC */
1084
+ case REG_SD_DATA7_CRC: /* CRC Data 7 from card/eMMC */
1085
+ case REG_SD_DATA6_CRC: /* CRC Data 6 from card/eMMC */
1086
+ case REG_SD_DATA5_CRC: /* CRC Data 5 from card/eMMC */
1087
+ case REG_SD_DATA4_CRC: /* CRC Data 4 from card/eMMC */
1088
+ case REG_SD_DATA3_CRC: /* CRC Data 3 from card/eMMC */
1089
+ case REG_SD_DATA2_CRC: /* CRC Data 2 from card/eMMC */
1090
+ case REG_SD_DATA1_CRC: /* CRC Data 1 from card/eMMC */
1091
+ case REG_SD_DATA0_CRC: /* CRC Data 0 from card/eMMC */
1092
+ case REG_SD_CRC_STA: /* CRC status from card/eMMC in write operation */
1093
+ break;
427
+ default:
1094
+ default:
428
+ if (addr < ARRAY_SIZE(s->regs)) {
1095
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset %"
429
+ s->regs[addr] = value;
1096
+ HWADDR_PRIx"\n", __func__, offset);
430
+ } else {
1097
+ break;
431
+ qemu_log_mask(LOG_GUEST_ERROR,
1098
+ }
432
+ "%s: Bad offset 0x%" HWADDR_PRIx "\n", __func__,
1099
+}
433
+ addr * 4);
1100
+
434
+ }
1101
+static const MemoryRegionOps allwinner_sdhost_ops = {
435
+ break;
1102
+ .read = allwinner_sdhost_read,
436
+ }
1103
+ .write = allwinner_sdhost_write,
437
+
438
+ spi_update_irq(s);
439
+}
440
+
441
+static const MemoryRegionOps spi_ops = {
442
+ .read = spi_read,
443
+ .write = spi_write,
444
+ .endianness = DEVICE_NATIVE_ENDIAN,
1104
+ .endianness = DEVICE_NATIVE_ENDIAN,
445
+ .valid = {
1105
+ .valid = {
446
+ .min_access_size = 1,
1106
+ .min_access_size = 4,
447
+ .max_access_size = 4
1107
+ .max_access_size = 4,
448
+ }
1108
+ },
1109
+ .impl.min_access_size = 4,
449
+};
1110
+};
450
+
1111
+
451
+static void mss_spi_realize(DeviceState *dev, Error **errp)
1112
+static const VMStateDescription vmstate_allwinner_sdhost = {
452
+{
1113
+ .name = "allwinner-sdhost",
453
+ MSSSpiState *s = MSS_SPI(dev);
454
+ SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
455
+
456
+ s->spi = ssi_create_bus(dev, "spi");
457
+
458
+ sysbus_init_irq(sbd, &s->irq);
459
+ ssi_auto_connect_slaves(dev, &s->cs_line, s->spi);
460
+ sysbus_init_irq(sbd, &s->cs_line);
461
+
462
+ memory_region_init_io(&s->mmio, OBJECT(s), &spi_ops, s,
463
+ TYPE_MSS_SPI, R_SPI_MAX * 4);
464
+ sysbus_init_mmio(sbd, &s->mmio);
465
+
466
+ fifo32_create(&s->tx_fifo, FIFO_CAPACITY);
467
+ fifo32_create(&s->rx_fifo, FIFO_CAPACITY);
468
+}
469
+
470
+static const VMStateDescription vmstate_mss_spi = {
471
+ .name = TYPE_MSS_SPI,
472
+ .version_id = 1,
1114
+ .version_id = 1,
473
+ .minimum_version_id = 1,
1115
+ .minimum_version_id = 1,
474
+ .fields = (VMStateField[]) {
1116
+ .fields = (VMStateField[]) {
475
+ VMSTATE_FIFO32(tx_fifo, MSSSpiState),
1117
+ VMSTATE_UINT32(global_ctl, AwSdHostState),
476
+ VMSTATE_FIFO32(rx_fifo, MSSSpiState),
1118
+ VMSTATE_UINT32(clock_ctl, AwSdHostState),
477
+ VMSTATE_UINT32_ARRAY(regs, MSSSpiState, R_SPI_MAX),
1119
+ VMSTATE_UINT32(timeout, AwSdHostState),
1120
+ VMSTATE_UINT32(bus_width, AwSdHostState),
1121
+ VMSTATE_UINT32(block_size, AwSdHostState),
1122
+ VMSTATE_UINT32(byte_count, AwSdHostState),
1123
+ VMSTATE_UINT32(transfer_cnt, AwSdHostState),
1124
+ VMSTATE_UINT32(command, AwSdHostState),
1125
+ VMSTATE_UINT32(command_arg, AwSdHostState),
1126
+ VMSTATE_UINT32_ARRAY(response, AwSdHostState, 4),
1127
+ VMSTATE_UINT32(irq_mask, AwSdHostState),
1128
+ VMSTATE_UINT32(irq_status, AwSdHostState),
1129
+ VMSTATE_UINT32(status, AwSdHostState),
1130
+ VMSTATE_UINT32(fifo_wlevel, AwSdHostState),
1131
+ VMSTATE_UINT32(fifo_func_sel, AwSdHostState),
1132
+ VMSTATE_UINT32(debug_enable, AwSdHostState),
1133
+ VMSTATE_UINT32(auto12_arg, AwSdHostState),
1134
+ VMSTATE_UINT32(newtiming_set, AwSdHostState),
1135
+ VMSTATE_UINT32(newtiming_debug, AwSdHostState),
1136
+ VMSTATE_UINT32(hardware_rst, AwSdHostState),
1137
+ VMSTATE_UINT32(dmac, AwSdHostState),
1138
+ VMSTATE_UINT32(desc_base, AwSdHostState),
1139
+ VMSTATE_UINT32(dmac_status, AwSdHostState),
1140
+ VMSTATE_UINT32(dmac_irq, AwSdHostState),
1141
+ VMSTATE_UINT32(card_threshold, AwSdHostState),
1142
+ VMSTATE_UINT32(startbit_detect, AwSdHostState),
1143
+ VMSTATE_UINT32(response_crc, AwSdHostState),
1144
+ VMSTATE_UINT32_ARRAY(data_crc, AwSdHostState, 8),
1145
+ VMSTATE_UINT32(status_crc, AwSdHostState),
478
+ VMSTATE_END_OF_LIST()
1146
+ VMSTATE_END_OF_LIST()
479
+ }
1147
+ }
480
+};
1148
+};
481
+
1149
+
482
+static void mss_spi_class_init(ObjectClass *klass, void *data)
1150
+static void allwinner_sdhost_init(Object *obj)
1151
+{
1152
+ AwSdHostState *s = AW_SDHOST(obj);
1153
+
1154
+ qbus_create_inplace(&s->sdbus, sizeof(s->sdbus),
1155
+ TYPE_AW_SDHOST_BUS, DEVICE(s), "sd-bus");
1156
+
1157
+ memory_region_init_io(&s->iomem, obj, &allwinner_sdhost_ops, s,
1158
+ TYPE_AW_SDHOST, 4 * KiB);
1159
+ sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem);
1160
+ sysbus_init_irq(SYS_BUS_DEVICE(s), &s->irq);
1161
+}
1162
+
1163
+static void allwinner_sdhost_reset(DeviceState *dev)
1164
+{
1165
+ AwSdHostState *s = AW_SDHOST(dev);
1166
+
1167
+ s->global_ctl = REG_SD_GCTL_RST;
1168
+ s->clock_ctl = REG_SD_CKCR_RST;
1169
+ s->timeout = REG_SD_TMOR_RST;
1170
+ s->bus_width = REG_SD_BWDR_RST;
1171
+ s->block_size = REG_SD_BKSR_RST;
1172
+ s->byte_count = REG_SD_BYCR_RST;
1173
+ s->transfer_cnt = 0;
1174
+
1175
+ s->command = REG_SD_CMDR_RST;
1176
+ s->command_arg = REG_SD_CAGR_RST;
1177
+
1178
+ for (int i = 0; i < ARRAY_SIZE(s->response); i++) {
1179
+ s->response[i] = REG_SD_RESP_RST;
1180
+ }
1181
+
1182
+ s->irq_mask = REG_SD_IMKR_RST;
1183
+ s->irq_status = REG_SD_RISR_RST;
1184
+ s->status = REG_SD_STAR_RST;
1185
+
1186
+ s->fifo_wlevel = REG_SD_FWLR_RST;
1187
+ s->fifo_func_sel = REG_SD_FUNS_RST;
1188
+ s->debug_enable = REG_SD_DBGC_RST;
1189
+ s->auto12_arg = REG_SD_A12A_RST;
1190
+ s->newtiming_set = REG_SD_NTSR_RST;
1191
+ s->newtiming_debug = REG_SD_SDBG_RST;
1192
+ s->hardware_rst = REG_SD_HWRST_RST;
1193
+ s->dmac = REG_SD_DMAC_RST;
1194
+ s->desc_base = REG_SD_DLBA_RST;
1195
+ s->dmac_status = REG_SD_IDST_RST;
1196
+ s->dmac_irq = REG_SD_IDIE_RST;
1197
+ s->card_threshold = REG_SD_THLDC_RST;
1198
+ s->startbit_detect = REG_SD_DSBD_RST;
1199
+ s->response_crc = REG_SD_RES_CRC_RST;
1200
+
1201
+ for (int i = 0; i < ARRAY_SIZE(s->data_crc); i++) {
1202
+ s->data_crc[i] = REG_SD_DATA_CRC_RST;
1203
+ }
1204
+
1205
+ s->status_crc = REG_SD_CRC_STA_RST;
1206
+}
1207
+
1208
+static void allwinner_sdhost_bus_class_init(ObjectClass *klass, void *data)
1209
+{
1210
+ SDBusClass *sbc = SD_BUS_CLASS(klass);
1211
+
1212
+ sbc->set_inserted = allwinner_sdhost_set_inserted;
1213
+}
1214
+
1215
+static void allwinner_sdhost_class_init(ObjectClass *klass, void *data)
483
+{
1216
+{
484
+ DeviceClass *dc = DEVICE_CLASS(klass);
1217
+ DeviceClass *dc = DEVICE_CLASS(klass);
485
+
1218
+
486
+ dc->realize = mss_spi_realize;
1219
+ dc->reset = allwinner_sdhost_reset;
487
+ dc->reset = mss_spi_reset;
1220
+ dc->vmsd = &vmstate_allwinner_sdhost;
488
+ dc->vmsd = &vmstate_mss_spi;
1221
+}
489
+}
1222
+
490
+
1223
+static void allwinner_sdhost_sun4i_class_init(ObjectClass *klass, void *data)
491
+static const TypeInfo mss_spi_info = {
1224
+{
492
+ .name = TYPE_MSS_SPI,
1225
+ AwSdHostClass *sc = AW_SDHOST_CLASS(klass);
493
+ .parent = TYPE_SYS_BUS_DEVICE,
1226
+ sc->max_desc_size = 8 * KiB;
494
+ .instance_size = sizeof(MSSSpiState),
1227
+}
495
+ .class_init = mss_spi_class_init,
1228
+
1229
+static void allwinner_sdhost_sun5i_class_init(ObjectClass *klass, void *data)
1230
+{
1231
+ AwSdHostClass *sc = AW_SDHOST_CLASS(klass);
1232
+ sc->max_desc_size = 64 * KiB;
1233
+}
1234
+
1235
+static TypeInfo allwinner_sdhost_info = {
1236
+ .name = TYPE_AW_SDHOST,
1237
+ .parent = TYPE_SYS_BUS_DEVICE,
1238
+ .instance_init = allwinner_sdhost_init,
1239
+ .instance_size = sizeof(AwSdHostState),
1240
+ .class_init = allwinner_sdhost_class_init,
1241
+ .class_size = sizeof(AwSdHostClass),
1242
+ .abstract = true,
496
+};
1243
+};
497
+
1244
+
498
+static void mss_spi_register_types(void)
1245
+static const TypeInfo allwinner_sdhost_sun4i_info = {
499
+{
1246
+ .name = TYPE_AW_SDHOST_SUN4I,
500
+ type_register_static(&mss_spi_info);
1247
+ .parent = TYPE_AW_SDHOST,
501
+}
1248
+ .class_init = allwinner_sdhost_sun4i_class_init,
502
+
1249
+};
503
+type_init(mss_spi_register_types)
1250
+
1251
+static const TypeInfo allwinner_sdhost_sun5i_info = {
1252
+ .name = TYPE_AW_SDHOST_SUN5I,
1253
+ .parent = TYPE_AW_SDHOST,
1254
+ .class_init = allwinner_sdhost_sun5i_class_init,
1255
+};
1256
+
1257
+static const TypeInfo allwinner_sdhost_bus_info = {
1258
+ .name = TYPE_AW_SDHOST_BUS,
1259
+ .parent = TYPE_SD_BUS,
1260
+ .instance_size = sizeof(SDBus),
1261
+ .class_init = allwinner_sdhost_bus_class_init,
1262
+};
1263
+
1264
+static void allwinner_sdhost_register_types(void)
1265
+{
1266
+ type_register_static(&allwinner_sdhost_info);
1267
+ type_register_static(&allwinner_sdhost_sun4i_info);
1268
+ type_register_static(&allwinner_sdhost_sun5i_info);
1269
+ type_register_static(&allwinner_sdhost_bus_info);
1270
+}
1271
+
1272
+type_init(allwinner_sdhost_register_types)
1273
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
1274
index XXXXXXX..XXXXXXX 100644
1275
--- a/hw/arm/Kconfig
1276
+++ b/hw/arm/Kconfig
1277
@@ -XXX,XX +XXX,XX @@ config ALLWINNER_H3
1278
select UNIMP
1279
select USB_OHCI
1280
select USB_EHCI_SYSBUS
1281
+ select SD
1282
1283
config RASPI
1284
bool
1285
diff --git a/hw/sd/trace-events b/hw/sd/trace-events
1286
index XXXXXXX..XXXXXXX 100644
1287
--- a/hw/sd/trace-events
1288
+++ b/hw/sd/trace-events
1289
@@ -XXX,XX +XXX,XX @@
1290
# See docs/devel/tracing.txt for syntax documentation.
1291
1292
+# allwinner-sdhost.c
1293
+allwinner_sdhost_set_inserted(bool inserted) "inserted %u"
1294
+allwinner_sdhost_process_desc(uint64_t desc_addr, uint32_t desc_size, bool is_write, uint32_t max_bytes) "desc_addr 0x%" PRIx64 " desc_size %" PRIu32 " is_write %u max_bytes %" PRIu32
1295
+allwinner_sdhost_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
1296
+allwinner_sdhost_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
1297
+allwinner_sdhost_update_irq(uint32_t irq) "IRQ bits 0x%" PRIx32
1298
+
1299
# bcm2835_sdhost.c
1300
bcm2835_sdhost_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
1301
bcm2835_sdhost_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
504
--
1302
--
505
2.7.4
1303
2.20.1
506
1304
507
1305
diff view generated by jsdifflib
1
For the v8M security extension, some exceptions must be banked
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
2
between security states. Add the new vecinfo array which holds
3
the state for the banked exceptions and migrate it if the
4
CPU the NVIC is attached to implements the security extension.
5
2
3
The Allwinner Sun8i System on Chip family includes an Ethernet MAC (EMAC)
4
which provides 10M/100M/1000M Ethernet connectivity. This commit
5
adds support for the Allwinner EMAC from the Sun8i family (H2+, H3, A33, etc),
6
including emulation for the following functionality:
7
8
* DMA transfers
9
* MII interface
10
* Transmit CRC calculation
11
12
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
13
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
14
Message-id: 20200311221854.30370-10-nieklinnenbank@gmail.com
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
---
16
---
9
include/hw/intc/armv7m_nvic.h | 14 ++++++++++++
17
hw/net/Makefile.objs | 1 +
10
hw/intc/armv7m_nvic.c | 53 ++++++++++++++++++++++++++++++++++++++++++-
18
include/hw/arm/allwinner-h3.h | 3 +
11
2 files changed, 66 insertions(+), 1 deletion(-)
19
include/hw/net/allwinner-sun8i-emac.h | 99 +++
20
hw/arm/allwinner-h3.c | 16 +-
21
hw/arm/orangepi.c | 3 +
22
hw/net/allwinner-sun8i-emac.c | 871 ++++++++++++++++++++++++++
23
hw/arm/Kconfig | 1 +
24
hw/net/Kconfig | 3 +
25
hw/net/trace-events | 10 +
26
9 files changed, 1006 insertions(+), 1 deletion(-)
27
create mode 100644 include/hw/net/allwinner-sun8i-emac.h
28
create mode 100644 hw/net/allwinner-sun8i-emac.c
12
29
13
diff --git a/include/hw/intc/armv7m_nvic.h b/include/hw/intc/armv7m_nvic.h
30
diff --git a/hw/net/Makefile.objs b/hw/net/Makefile.objs
14
index XXXXXXX..XXXXXXX 100644
31
index XXXXXXX..XXXXXXX 100644
15
--- a/include/hw/intc/armv7m_nvic.h
32
--- a/hw/net/Makefile.objs
16
+++ b/include/hw/intc/armv7m_nvic.h
33
+++ b/hw/net/Makefile.objs
34
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_XGMAC) += xgmac.o
35
common-obj-$(CONFIG_MIPSNET) += mipsnet.o
36
common-obj-$(CONFIG_XILINX_AXI) += xilinx_axienet.o
37
common-obj-$(CONFIG_ALLWINNER_EMAC) += allwinner_emac.o
38
+common-obj-$(CONFIG_ALLWINNER_SUN8I_EMAC) += allwinner-sun8i-emac.o
39
common-obj-$(CONFIG_IMX_FEC) += imx_fec.o
40
41
common-obj-$(CONFIG_CADENCE) += cadence_gem.o
42
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
43
index XXXXXXX..XXXXXXX 100644
44
--- a/include/hw/arm/allwinner-h3.h
45
+++ b/include/hw/arm/allwinner-h3.h
17
@@ -XXX,XX +XXX,XX @@
46
@@ -XXX,XX +XXX,XX @@
18
47
#include "hw/misc/allwinner-h3-sysctrl.h"
19
/* Highest permitted number of exceptions (architectural limit) */
48
#include "hw/misc/allwinner-sid.h"
20
#define NVIC_MAX_VECTORS 512
49
#include "hw/sd/allwinner-sdhost.h"
21
+/* Number of internal exceptions */
50
+#include "hw/net/allwinner-sun8i-emac.h"
22
+#define NVIC_INTERNAL_VECTORS 16
51
#include "target/arm/cpu.h"
23
52
24
typedef struct VecInfo {
53
/**
25
/* Exception priorities can range from -3 to 255; only the unmodifiable
54
@@ -XXX,XX +XXX,XX @@ enum {
26
@@ -XXX,XX +XXX,XX @@ typedef struct NVICState {
55
AW_H3_UART1,
27
ARMCPU *cpu;
56
AW_H3_UART2,
28
57
AW_H3_UART3,
29
VecInfo vectors[NVIC_MAX_VECTORS];
58
+ AW_H3_EMAC,
30
+ /* If the v8M security extension is implemented, some of the internal
59
AW_H3_GIC_DIST,
31
+ * exceptions are banked between security states (ie there exists both
60
AW_H3_GIC_CPU,
32
+ * a Secure and a NonSecure version of the exception and its state):
61
AW_H3_GIC_HYP,
33
+ * HardFault, MemManage, UsageFault, SVCall, PendSV, SysTick (R_PJHV)
62
@@ -XXX,XX +XXX,XX @@ typedef struct AwH3State {
34
+ * The rest (including all the external exceptions) are not banked, though
63
AwH3SysCtrlState sysctrl;
35
+ * they may be configurable to target either Secure or NonSecure state.
64
AwSidState sid;
36
+ * We store the secure exception state in sec_vectors[] for the banked
65
AwSdHostState mmc0;
37
+ * exceptions, and otherwise use only vectors[] (including for exceptions
66
+ AwSun8iEmacState emac;
38
+ * like SecureFault that unconditionally target Secure state).
67
GICState gic;
39
+ * Entries in sec_vectors[] for non-banked exception numbers are unused.
68
MemoryRegion sram_a1;
69
MemoryRegion sram_a2;
70
diff --git a/include/hw/net/allwinner-sun8i-emac.h b/include/hw/net/allwinner-sun8i-emac.h
71
new file mode 100644
72
index XXXXXXX..XXXXXXX
73
--- /dev/null
74
+++ b/include/hw/net/allwinner-sun8i-emac.h
75
@@ -XXX,XX +XXX,XX @@
76
+/*
77
+ * Allwinner Sun8i Ethernet MAC emulation
78
+ *
79
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
80
+ *
81
+ * This program is free software: you can redistribute it and/or modify
82
+ * it under the terms of the GNU General Public License as published by
83
+ * the Free Software Foundation, either version 2 of the License, or
84
+ * (at your option) any later version.
85
+ *
86
+ * This program is distributed in the hope that it will be useful,
87
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
88
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
89
+ * GNU General Public License for more details.
90
+ *
91
+ * You should have received a copy of the GNU General Public License
92
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
93
+ */
94
+
95
+#ifndef HW_NET_ALLWINNER_SUN8I_EMAC_H
96
+#define HW_NET_ALLWINNER_SUN8I_EMAC_H
97
+
98
+#include "qom/object.h"
99
+#include "net/net.h"
100
+#include "hw/sysbus.h"
101
+
102
+/**
103
+ * Object model
104
+ * @{
105
+ */
106
+
107
+#define TYPE_AW_SUN8I_EMAC "allwinner-sun8i-emac"
108
+#define AW_SUN8I_EMAC(obj) \
109
+ OBJECT_CHECK(AwSun8iEmacState, (obj), TYPE_AW_SUN8I_EMAC)
110
+
111
+/** @} */
112
+
113
+/**
114
+ * Allwinner Sun8i EMAC object instance state
115
+ */
116
+typedef struct AwSun8iEmacState {
117
+ /*< private >*/
118
+ SysBusDevice parent_obj;
119
+ /*< public >*/
120
+
121
+ /** Maps I/O registers in physical memory */
122
+ MemoryRegion iomem;
123
+
124
+ /** Interrupt output signal to notify CPU */
125
+ qemu_irq irq;
126
+
127
+ /** Generic Network Interface Controller (NIC) for networking API */
128
+ NICState *nic;
129
+
130
+ /** Generic Network Interface Controller (NIC) configuration */
131
+ NICConf conf;
132
+
133
+ /**
134
+ * @name Media Independent Interface (MII)
135
+ * @{
40
+ */
136
+ */
41
+ VecInfo sec_vectors[NVIC_INTERNAL_VECTORS];
137
+
42
uint32_t prigroup;
138
+ uint8_t mii_phy_addr; /**< PHY address */
43
139
+ uint32_t mii_cr; /**< Control */
44
/* vectpending and exception_prio are both cached state that can
140
+ uint32_t mii_st; /**< Status */
45
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
141
+ uint32_t mii_adv; /**< Advertised Abilities */
142
+
143
+ /** @} */
144
+
145
+ /**
146
+ * @name Hardware Registers
147
+ * @{
148
+ */
149
+
150
+ uint32_t basic_ctl0; /**< Basic Control 0 */
151
+ uint32_t basic_ctl1; /**< Basic Control 1 */
152
+ uint32_t int_en; /**< Interrupt Enable */
153
+ uint32_t int_sta; /**< Interrupt Status */
154
+ uint32_t frm_flt; /**< Receive Frame Filter */
155
+
156
+ uint32_t rx_ctl0; /**< Receive Control 0 */
157
+ uint32_t rx_ctl1; /**< Receive Control 1 */
158
+ uint32_t rx_desc_head; /**< Receive Descriptor List Address */
159
+ uint32_t rx_desc_curr; /**< Current Receive Descriptor Address */
160
+
161
+ uint32_t tx_ctl0; /**< Transmit Control 0 */
162
+ uint32_t tx_ctl1; /**< Transmit Control 1 */
163
+ uint32_t tx_desc_head; /**< Transmit Descriptor List Address */
164
+ uint32_t tx_desc_curr; /**< Current Transmit Descriptor Address */
165
+ uint32_t tx_flowctl; /**< Transmit Flow Control */
166
+
167
+ uint32_t mii_cmd; /**< Management Interface Command */
168
+ uint32_t mii_data; /**< Management Interface Data */
169
+
170
+ /** @} */
171
+
172
+} AwSun8iEmacState;
173
+
174
+#endif /* HW_NET_ALLWINNER_SUN8I_H */
175
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
46
index XXXXXXX..XXXXXXX 100644
176
index XXXXXXX..XXXXXXX 100644
47
--- a/hw/intc/armv7m_nvic.c
177
--- a/hw/arm/allwinner-h3.c
48
+++ b/hw/intc/armv7m_nvic.c
178
+++ b/hw/arm/allwinner-h3.c
179
@@ -XXX,XX +XXX,XX @@ const hwaddr allwinner_h3_memmap[] = {
180
[AW_H3_UART1] = 0x01c28400,
181
[AW_H3_UART2] = 0x01c28800,
182
[AW_H3_UART3] = 0x01c28c00,
183
+ [AW_H3_EMAC] = 0x01c30000,
184
[AW_H3_GIC_DIST] = 0x01c81000,
185
[AW_H3_GIC_CPU] = 0x01c82000,
186
[AW_H3_GIC_HYP] = 0x01c84000,
187
@@ -XXX,XX +XXX,XX @@ struct AwH3Unimplemented {
188
{ "twi1", 0x01c2b000, 1 * KiB },
189
{ "twi2", 0x01c2b400, 1 * KiB },
190
{ "scr", 0x01c2c400, 1 * KiB },
191
- { "emac", 0x01c30000, 64 * KiB },
192
{ "gpu", 0x01c40000, 64 * KiB },
193
{ "hstmr", 0x01c60000, 4 * KiB },
194
{ "dramcom", 0x01c62000, 4 * KiB },
195
@@ -XXX,XX +XXX,XX @@ enum {
196
AW_H3_GIC_SPI_OHCI2 = 77,
197
AW_H3_GIC_SPI_EHCI3 = 78,
198
AW_H3_GIC_SPI_OHCI3 = 79,
199
+ AW_H3_GIC_SPI_EMAC = 82
200
};
201
202
/* Allwinner H3 general constants */
203
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_init(Object *obj)
204
205
sysbus_init_child_obj(obj, "mmc0", &s->mmc0, sizeof(s->mmc0),
206
TYPE_AW_SDHOST_SUN5I);
207
+
208
+ sysbus_init_child_obj(obj, "emac", &s->emac, sizeof(s->emac),
209
+ TYPE_AW_SUN8I_EMAC);
210
}
211
212
static void allwinner_h3_realize(DeviceState *dev, Error **errp)
213
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
214
object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->mmc0),
215
"sd-bus", &error_abort);
216
217
+ /* EMAC */
218
+ if (nd_table[0].used) {
219
+ qemu_check_nic_model(&nd_table[0], TYPE_AW_SUN8I_EMAC);
220
+ qdev_set_nic_properties(DEVICE(&s->emac), &nd_table[0]);
221
+ }
222
+ qdev_init_nofail(DEVICE(&s->emac));
223
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->emac), 0, s->memmap[AW_H3_EMAC]);
224
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->emac), 0,
225
+ qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_EMAC));
226
+
227
/* Universal Serial Bus */
228
sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0],
229
qdev_get_gpio_in(DEVICE(&s->gic),
230
diff --git a/hw/arm/orangepi.c b/hw/arm/orangepi.c
231
index XXXXXXX..XXXXXXX 100644
232
--- a/hw/arm/orangepi.c
233
+++ b/hw/arm/orangepi.c
234
@@ -XXX,XX +XXX,XX @@ static void orangepi_init(MachineState *machine)
235
warn_report("Security Identifier value does not include H3 prefix");
236
}
237
238
+ /* Setup EMAC properties */
239
+ object_property_set_int(OBJECT(&h3->emac), 1, "phy-addr", &error_abort);
240
+
241
/* Mark H3 object realized */
242
object_property_set_bool(OBJECT(h3), true, "realized", &error_abort);
243
244
diff --git a/hw/net/allwinner-sun8i-emac.c b/hw/net/allwinner-sun8i-emac.c
245
new file mode 100644
246
index XXXXXXX..XXXXXXX
247
--- /dev/null
248
+++ b/hw/net/allwinner-sun8i-emac.c
49
@@ -XXX,XX +XXX,XX @@
249
@@ -XXX,XX +XXX,XX @@
50
* For historical reasons QEMU tends to use "interrupt" and
250
+/*
51
* "exception" more or less interchangeably.
251
+ * Allwinner Sun8i Ethernet MAC emulation
52
*/
252
+ *
53
-#define NVIC_FIRST_IRQ 16
253
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
54
+#define NVIC_FIRST_IRQ NVIC_INTERNAL_VECTORS
254
+ *
55
#define NVIC_MAX_IRQ (NVIC_MAX_VECTORS - NVIC_FIRST_IRQ)
255
+ * This program is free software: you can redistribute it and/or modify
56
256
+ * it under the terms of the GNU General Public License as published by
57
/* Effective running priority of the CPU when no exception is active
257
+ * the Free Software Foundation, either version 2 of the License, or
58
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_VecInfo = {
258
+ * (at your option) any later version.
59
}
259
+ *
60
};
260
+ * This program is distributed in the hope that it will be useful,
61
261
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
62
+static bool nvic_security_needed(void *opaque)
262
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
63
+{
263
+ * GNU General Public License for more details.
64
+ NVICState *s = opaque;
264
+ *
65
+
265
+ * You should have received a copy of the GNU General Public License
66
+ return arm_feature(&s->cpu->env, ARM_FEATURE_M_SECURITY);
266
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
67
+}
267
+ */
68
+
268
+
69
+static int nvic_security_post_load(void *opaque, int version_id)
269
+#include "qemu/osdep.h"
70
+{
270
+#include "qemu/units.h"
71
+ NVICState *s = opaque;
271
+#include "hw/sysbus.h"
72
+ int i;
272
+#include "migration/vmstate.h"
73
+
273
+#include "net/net.h"
74
+ /* Check for out of range priority settings */
274
+#include "hw/irq.h"
75
+ if (s->sec_vectors[ARMV7M_EXCP_HARD].prio != -1) {
275
+#include "hw/qdev-properties.h"
76
+ return 1;
276
+#include "qemu/log.h"
77
+ }
277
+#include "trace.h"
78
+ for (i = ARMV7M_EXCP_MEM; i < ARRAY_SIZE(s->sec_vectors); i++) {
278
+#include "net/checksum.h"
79
+ if (s->sec_vectors[i].prio & ~0xff) {
279
+#include "qemu/module.h"
80
+ return 1;
280
+#include "exec/cpu-common.h"
81
+ }
281
+#include "hw/net/allwinner-sun8i-emac.h"
82
+ }
282
+
283
+/* EMAC register offsets */
284
+enum {
285
+ REG_BASIC_CTL_0 = 0x0000, /* Basic Control 0 */
286
+ REG_BASIC_CTL_1 = 0x0004, /* Basic Control 1 */
287
+ REG_INT_STA = 0x0008, /* Interrupt Status */
288
+ REG_INT_EN = 0x000C, /* Interrupt Enable */
289
+ REG_TX_CTL_0 = 0x0010, /* Transmit Control 0 */
290
+ REG_TX_CTL_1 = 0x0014, /* Transmit Control 1 */
291
+ REG_TX_FLOW_CTL = 0x001C, /* Transmit Flow Control */
292
+ REG_TX_DMA_DESC_LIST = 0x0020, /* Transmit Descriptor List Address */
293
+ REG_RX_CTL_0 = 0x0024, /* Receive Control 0 */
294
+ REG_RX_CTL_1 = 0x0028, /* Receive Control 1 */
295
+ REG_RX_DMA_DESC_LIST = 0x0034, /* Receive Descriptor List Address */
296
+ REG_FRM_FLT = 0x0038, /* Receive Frame Filter */
297
+ REG_RX_HASH_0 = 0x0040, /* Receive Hash Table 0 */
298
+ REG_RX_HASH_1 = 0x0044, /* Receive Hash Table 1 */
299
+ REG_MII_CMD = 0x0048, /* Management Interface Command */
300
+ REG_MII_DATA = 0x004C, /* Management Interface Data */
301
+ REG_ADDR_HIGH = 0x0050, /* MAC Address High */
302
+ REG_ADDR_LOW = 0x0054, /* MAC Address Low */
303
+ REG_TX_DMA_STA = 0x00B0, /* Transmit DMA Status */
304
+ REG_TX_CUR_DESC = 0x00B4, /* Transmit Current Descriptor */
305
+ REG_TX_CUR_BUF = 0x00B8, /* Transmit Current Buffer */
306
+ REG_RX_DMA_STA = 0x00C0, /* Receive DMA Status */
307
+ REG_RX_CUR_DESC = 0x00C4, /* Receive Current Descriptor */
308
+ REG_RX_CUR_BUF = 0x00C8, /* Receive Current Buffer */
309
+ REG_RGMII_STA = 0x00D0, /* RGMII Status */
310
+};
311
+
312
+/* EMAC register flags */
313
+enum {
314
+ BASIC_CTL0_100Mbps = (0b11 << 2),
315
+ BASIC_CTL0_FD = (1 << 0),
316
+ BASIC_CTL1_SOFTRST = (1 << 0),
317
+};
318
+
319
+enum {
320
+ INT_STA_RGMII_LINK = (1 << 16),
321
+ INT_STA_RX_EARLY = (1 << 13),
322
+ INT_STA_RX_OVERFLOW = (1 << 12),
323
+ INT_STA_RX_TIMEOUT = (1 << 11),
324
+ INT_STA_RX_DMA_STOP = (1 << 10),
325
+ INT_STA_RX_BUF_UA = (1 << 9),
326
+ INT_STA_RX = (1 << 8),
327
+ INT_STA_TX_EARLY = (1 << 5),
328
+ INT_STA_TX_UNDERFLOW = (1 << 4),
329
+ INT_STA_TX_TIMEOUT = (1 << 3),
330
+ INT_STA_TX_BUF_UA = (1 << 2),
331
+ INT_STA_TX_DMA_STOP = (1 << 1),
332
+ INT_STA_TX = (1 << 0),
333
+};
334
+
335
+enum {
336
+ INT_EN_RX_EARLY = (1 << 13),
337
+ INT_EN_RX_OVERFLOW = (1 << 12),
338
+ INT_EN_RX_TIMEOUT = (1 << 11),
339
+ INT_EN_RX_DMA_STOP = (1 << 10),
340
+ INT_EN_RX_BUF_UA = (1 << 9),
341
+ INT_EN_RX = (1 << 8),
342
+ INT_EN_TX_EARLY = (1 << 5),
343
+ INT_EN_TX_UNDERFLOW = (1 << 4),
344
+ INT_EN_TX_TIMEOUT = (1 << 3),
345
+ INT_EN_TX_BUF_UA = (1 << 2),
346
+ INT_EN_TX_DMA_STOP = (1 << 1),
347
+ INT_EN_TX = (1 << 0),
348
+};
349
+
350
+enum {
351
+ TX_CTL0_TX_EN = (1 << 31),
352
+ TX_CTL1_TX_DMA_START = (1 << 31),
353
+ TX_CTL1_TX_DMA_EN = (1 << 30),
354
+ TX_CTL1_TX_FLUSH = (1 << 0),
355
+};
356
+
357
+enum {
358
+ RX_CTL0_RX_EN = (1 << 31),
359
+ RX_CTL0_STRIP_FCS = (1 << 28),
360
+ RX_CTL0_CRC_IPV4 = (1 << 27),
361
+};
362
+
363
+enum {
364
+ RX_CTL1_RX_DMA_START = (1 << 31),
365
+ RX_CTL1_RX_DMA_EN = (1 << 30),
366
+ RX_CTL1_RX_MD = (1 << 1),
367
+};
368
+
369
+enum {
370
+ RX_FRM_FLT_DIS_ADDR = (1 << 31),
371
+};
372
+
373
+enum {
374
+ MII_CMD_PHY_ADDR_SHIFT = (12),
375
+ MII_CMD_PHY_ADDR_MASK = (0xf000),
376
+ MII_CMD_PHY_REG_SHIFT = (4),
377
+ MII_CMD_PHY_REG_MASK = (0xf0),
378
+ MII_CMD_PHY_RW = (1 << 1),
379
+ MII_CMD_PHY_BUSY = (1 << 0),
380
+};
381
+
382
+enum {
383
+ TX_DMA_STA_STOP = (0b000),
384
+ TX_DMA_STA_RUN_FETCH = (0b001),
385
+ TX_DMA_STA_WAIT_STA = (0b010),
386
+};
387
+
388
+enum {
389
+ RX_DMA_STA_STOP = (0b000),
390
+ RX_DMA_STA_RUN_FETCH = (0b001),
391
+ RX_DMA_STA_WAIT_FRM = (0b011),
392
+};
393
+
394
+/* EMAC register reset values */
395
+enum {
396
+ REG_BASIC_CTL_1_RST = 0x08000000,
397
+};
398
+
399
+/* EMAC constants */
400
+enum {
401
+ AW_SUN8I_EMAC_MIN_PKT_SZ = 64
402
+};
403
+
404
+/* Transmit/receive frame descriptor */
405
+typedef struct FrameDescriptor {
406
+ uint32_t status;
407
+ uint32_t status2;
408
+ uint32_t addr;
409
+ uint32_t next;
410
+} FrameDescriptor;
411
+
412
+/* Frame descriptor flags */
413
+enum {
414
+ DESC_STATUS_CTL = (1 << 31),
415
+ DESC_STATUS2_BUF_SIZE_MASK = (0x7ff),
416
+};
417
+
418
+/* Transmit frame descriptor flags */
419
+enum {
420
+ TX_DESC_STATUS_LENGTH_ERR = (1 << 14),
421
+ TX_DESC_STATUS2_FIRST_DESC = (1 << 29),
422
+ TX_DESC_STATUS2_LAST_DESC = (1 << 30),
423
+ TX_DESC_STATUS2_CHECKSUM_MASK = (0x3 << 27),
424
+};
425
+
426
+/* Receive frame descriptor flags */
427
+enum {
428
+ RX_DESC_STATUS_FIRST_DESC = (1 << 9),
429
+ RX_DESC_STATUS_LAST_DESC = (1 << 8),
430
+ RX_DESC_STATUS_FRM_LEN_MASK = (0x3fff0000),
431
+ RX_DESC_STATUS_FRM_LEN_SHIFT = (16),
432
+ RX_DESC_STATUS_NO_BUF = (1 << 14),
433
+ RX_DESC_STATUS_HEADER_ERR = (1 << 7),
434
+ RX_DESC_STATUS_LENGTH_ERR = (1 << 4),
435
+ RX_DESC_STATUS_CRC_ERR = (1 << 1),
436
+ RX_DESC_STATUS_PAYLOAD_ERR = (1 << 0),
437
+ RX_DESC_STATUS2_RX_INT_CTL = (1 << 31),
438
+};
439
+
440
+/* MII register offsets */
441
+enum {
442
+ MII_REG_CR = (0x0), /* Control */
443
+ MII_REG_ST = (0x1), /* Status */
444
+ MII_REG_ID_HIGH = (0x2), /* Identifier High */
445
+ MII_REG_ID_LOW = (0x3), /* Identifier Low */
446
+ MII_REG_ADV = (0x4), /* Advertised abilities */
447
+ MII_REG_LPA = (0x5), /* Link partner abilities */
448
+};
449
+
450
+/* MII register flags */
451
+enum {
452
+ MII_REG_CR_RESET = (1 << 15),
453
+ MII_REG_CR_POWERDOWN = (1 << 11),
454
+ MII_REG_CR_10Mbit = (0),
455
+ MII_REG_CR_100Mbit = (1 << 13),
456
+ MII_REG_CR_1000Mbit = (1 << 6),
457
+ MII_REG_CR_AUTO_NEG = (1 << 12),
458
+ MII_REG_CR_AUTO_NEG_RESTART = (1 << 9),
459
+ MII_REG_CR_FULLDUPLEX = (1 << 8),
460
+};
461
+
462
+enum {
463
+ MII_REG_ST_100BASE_T4 = (1 << 15),
464
+ MII_REG_ST_100BASE_X_FD = (1 << 14),
465
+ MII_REG_ST_100BASE_X_HD = (1 << 13),
466
+ MII_REG_ST_10_FD = (1 << 12),
467
+ MII_REG_ST_10_HD = (1 << 11),
468
+ MII_REG_ST_100BASE_T2_FD = (1 << 10),
469
+ MII_REG_ST_100BASE_T2_HD = (1 << 9),
470
+ MII_REG_ST_AUTONEG_COMPLETE = (1 << 5),
471
+ MII_REG_ST_AUTONEG_AVAIL = (1 << 3),
472
+ MII_REG_ST_LINK_UP = (1 << 2),
473
+};
474
+
475
+enum {
476
+ MII_REG_LPA_10_HD = (1 << 5),
477
+ MII_REG_LPA_10_FD = (1 << 6),
478
+ MII_REG_LPA_100_HD = (1 << 7),
479
+ MII_REG_LPA_100_FD = (1 << 8),
480
+ MII_REG_LPA_PAUSE = (1 << 10),
481
+ MII_REG_LPA_ASYMPAUSE = (1 << 11),
482
+};
483
+
484
+/* MII constants */
485
+enum {
486
+ MII_PHY_ID_HIGH = 0x0044,
487
+ MII_PHY_ID_LOW = 0x1400,
488
+};
489
+
490
+static void allwinner_sun8i_emac_mii_set_link(AwSun8iEmacState *s,
491
+ bool link_active)
492
+{
493
+ if (link_active) {
494
+ s->mii_st |= MII_REG_ST_LINK_UP;
495
+ } else {
496
+ s->mii_st &= ~MII_REG_ST_LINK_UP;
497
+ }
498
+}
499
+
500
+static void allwinner_sun8i_emac_mii_reset(AwSun8iEmacState *s,
501
+ bool link_active)
502
+{
503
+ s->mii_cr = MII_REG_CR_100Mbit | MII_REG_CR_AUTO_NEG |
504
+ MII_REG_CR_FULLDUPLEX;
505
+ s->mii_st = MII_REG_ST_100BASE_T4 | MII_REG_ST_100BASE_X_FD |
506
+ MII_REG_ST_100BASE_X_HD | MII_REG_ST_10_FD | MII_REG_ST_10_HD |
507
+ MII_REG_ST_100BASE_T2_FD | MII_REG_ST_100BASE_T2_HD |
508
+ MII_REG_ST_AUTONEG_COMPLETE | MII_REG_ST_AUTONEG_AVAIL;
509
+ s->mii_adv = 0;
510
+
511
+ allwinner_sun8i_emac_mii_set_link(s, link_active);
512
+}
513
+
514
+static void allwinner_sun8i_emac_mii_cmd(AwSun8iEmacState *s)
515
+{
516
+ uint8_t addr, reg;
517
+
518
+ addr = (s->mii_cmd & MII_CMD_PHY_ADDR_MASK) >> MII_CMD_PHY_ADDR_SHIFT;
519
+ reg = (s->mii_cmd & MII_CMD_PHY_REG_MASK) >> MII_CMD_PHY_REG_SHIFT;
520
+
521
+ if (addr != s->mii_phy_addr) {
522
+ return;
523
+ }
524
+
525
+ /* Read or write a PHY register? */
526
+ if (s->mii_cmd & MII_CMD_PHY_RW) {
527
+ trace_allwinner_sun8i_emac_mii_write_reg(reg, s->mii_data);
528
+
529
+ switch (reg) {
530
+ case MII_REG_CR:
531
+ if (s->mii_data & MII_REG_CR_RESET) {
532
+ allwinner_sun8i_emac_mii_reset(s, s->mii_st &
533
+ MII_REG_ST_LINK_UP);
534
+ } else {
535
+ s->mii_cr = s->mii_data & ~(MII_REG_CR_RESET |
536
+ MII_REG_CR_AUTO_NEG_RESTART);
537
+ }
538
+ break;
539
+ case MII_REG_ADV:
540
+ s->mii_adv = s->mii_data;
541
+ break;
542
+ case MII_REG_ID_HIGH:
543
+ case MII_REG_ID_LOW:
544
+ case MII_REG_LPA:
545
+ break;
546
+ default:
547
+ qemu_log_mask(LOG_UNIMP, "allwinner-h3-emac: write access to "
548
+ "unknown MII register 0x%x\n", reg);
549
+ break;
550
+ }
551
+ } else {
552
+ switch (reg) {
553
+ case MII_REG_CR:
554
+ s->mii_data = s->mii_cr;
555
+ break;
556
+ case MII_REG_ST:
557
+ s->mii_data = s->mii_st;
558
+ break;
559
+ case MII_REG_ID_HIGH:
560
+ s->mii_data = MII_PHY_ID_HIGH;
561
+ break;
562
+ case MII_REG_ID_LOW:
563
+ s->mii_data = MII_PHY_ID_LOW;
564
+ break;
565
+ case MII_REG_ADV:
566
+ s->mii_data = s->mii_adv;
567
+ break;
568
+ case MII_REG_LPA:
569
+ s->mii_data = MII_REG_LPA_10_HD | MII_REG_LPA_10_FD |
570
+ MII_REG_LPA_100_HD | MII_REG_LPA_100_FD |
571
+ MII_REG_LPA_PAUSE | MII_REG_LPA_ASYMPAUSE;
572
+ break;
573
+ default:
574
+ qemu_log_mask(LOG_UNIMP, "allwinner-h3-emac: read access to "
575
+ "unknown MII register 0x%x\n", reg);
576
+ s->mii_data = 0;
577
+ break;
578
+ }
579
+
580
+ trace_allwinner_sun8i_emac_mii_read_reg(reg, s->mii_data);
581
+ }
582
+}
583
+
584
+static void allwinner_sun8i_emac_update_irq(AwSun8iEmacState *s)
585
+{
586
+ qemu_set_irq(s->irq, (s->int_sta & s->int_en) != 0);
587
+}
588
+
589
+static uint32_t allwinner_sun8i_emac_next_desc(FrameDescriptor *desc,
590
+ size_t min_size)
591
+{
592
+ uint32_t paddr = desc->next;
593
+
594
+ cpu_physical_memory_read(paddr, desc, sizeof(*desc));
595
+
596
+ if ((desc->status & DESC_STATUS_CTL) &&
597
+ (desc->status2 & DESC_STATUS2_BUF_SIZE_MASK) >= min_size) {
598
+ return paddr;
599
+ } else {
600
+ return 0;
601
+ }
602
+}
603
+
604
+static uint32_t allwinner_sun8i_emac_get_desc(FrameDescriptor *desc,
605
+ uint32_t start_addr,
606
+ size_t min_size)
607
+{
608
+ uint32_t desc_addr = start_addr;
609
+
610
+ /* Note that the list is a cycle. Last entry points back to the head. */
611
+ while (desc_addr != 0) {
612
+ cpu_physical_memory_read(desc_addr, desc, sizeof(*desc));
613
+
614
+ if ((desc->status & DESC_STATUS_CTL) &&
615
+ (desc->status2 & DESC_STATUS2_BUF_SIZE_MASK) >= min_size) {
616
+ return desc_addr;
617
+ } else if (desc->next == start_addr) {
618
+ break;
619
+ } else {
620
+ desc_addr = desc->next;
621
+ }
622
+ }
623
+
83
+ return 0;
624
+ return 0;
84
+}
625
+}
85
+
626
+
86
+static const VMStateDescription vmstate_nvic_security = {
627
+static uint32_t allwinner_sun8i_emac_rx_desc(AwSun8iEmacState *s,
87
+ .name = "nvic/m-security",
628
+ FrameDescriptor *desc,
629
+ size_t min_size)
630
+{
631
+ return allwinner_sun8i_emac_get_desc(desc, s->rx_desc_curr, min_size);
632
+}
633
+
634
+static uint32_t allwinner_sun8i_emac_tx_desc(AwSun8iEmacState *s,
635
+ FrameDescriptor *desc,
636
+ size_t min_size)
637
+{
638
+ return allwinner_sun8i_emac_get_desc(desc, s->tx_desc_head, min_size);
639
+}
640
+
641
+static void allwinner_sun8i_emac_flush_desc(FrameDescriptor *desc,
642
+ uint32_t phys_addr)
643
+{
644
+ cpu_physical_memory_write(phys_addr, desc, sizeof(*desc));
645
+}
646
+
647
+static int allwinner_sun8i_emac_can_receive(NetClientState *nc)
648
+{
649
+ AwSun8iEmacState *s = qemu_get_nic_opaque(nc);
650
+ FrameDescriptor desc;
651
+
652
+ return (s->rx_ctl0 & RX_CTL0_RX_EN) &&
653
+ (allwinner_sun8i_emac_rx_desc(s, &desc, 0) != 0);
654
+}
655
+
656
+static ssize_t allwinner_sun8i_emac_receive(NetClientState *nc,
657
+ const uint8_t *buf,
658
+ size_t size)
659
+{
660
+ AwSun8iEmacState *s = qemu_get_nic_opaque(nc);
661
+ FrameDescriptor desc;
662
+ size_t bytes_left = size;
663
+ size_t desc_bytes = 0;
664
+ size_t pad_fcs_size = 4;
665
+ size_t padding = 0;
666
+
667
+ if (!(s->rx_ctl0 & RX_CTL0_RX_EN)) {
668
+ return -1;
669
+ }
670
+
671
+ s->rx_desc_curr = allwinner_sun8i_emac_rx_desc(s, &desc,
672
+ AW_SUN8I_EMAC_MIN_PKT_SZ);
673
+ if (!s->rx_desc_curr) {
674
+ s->int_sta |= INT_STA_RX_BUF_UA;
675
+ }
676
+
677
+ /* Keep filling RX descriptors until the whole frame is written */
678
+ while (s->rx_desc_curr && bytes_left > 0) {
679
+ desc.status &= ~DESC_STATUS_CTL;
680
+ desc.status &= ~RX_DESC_STATUS_FRM_LEN_MASK;
681
+
682
+ if (bytes_left == size) {
683
+ desc.status |= RX_DESC_STATUS_FIRST_DESC;
684
+ }
685
+
686
+ if ((desc.status2 & DESC_STATUS2_BUF_SIZE_MASK) <
687
+ (bytes_left + pad_fcs_size)) {
688
+ desc_bytes = desc.status2 & DESC_STATUS2_BUF_SIZE_MASK;
689
+ desc.status |= desc_bytes << RX_DESC_STATUS_FRM_LEN_SHIFT;
690
+ } else {
691
+ padding = pad_fcs_size;
692
+ if (bytes_left < AW_SUN8I_EMAC_MIN_PKT_SZ) {
693
+ padding += (AW_SUN8I_EMAC_MIN_PKT_SZ - bytes_left);
694
+ }
695
+
696
+ desc_bytes = (bytes_left);
697
+ desc.status |= RX_DESC_STATUS_LAST_DESC;
698
+ desc.status |= (bytes_left + padding)
699
+ << RX_DESC_STATUS_FRM_LEN_SHIFT;
700
+ }
701
+
702
+ cpu_physical_memory_write(desc.addr, buf, desc_bytes);
703
+ allwinner_sun8i_emac_flush_desc(&desc, s->rx_desc_curr);
704
+ trace_allwinner_sun8i_emac_receive(s->rx_desc_curr, desc.addr,
705
+ desc_bytes);
706
+
707
+ /* Check if frame needs to raise the receive interrupt */
708
+ if (!(desc.status2 & RX_DESC_STATUS2_RX_INT_CTL)) {
709
+ s->int_sta |= INT_STA_RX;
710
+ }
711
+
712
+ /* Increment variables */
713
+ buf += desc_bytes;
714
+ bytes_left -= desc_bytes;
715
+
716
+ /* Move to the next descriptor */
717
+ s->rx_desc_curr = allwinner_sun8i_emac_next_desc(&desc, 64);
718
+ if (!s->rx_desc_curr) {
719
+ /* Not enough buffer space available */
720
+ s->int_sta |= INT_STA_RX_BUF_UA;
721
+ s->rx_desc_curr = s->rx_desc_head;
722
+ break;
723
+ }
724
+ }
725
+
726
+ /* Report receive DMA is finished */
727
+ s->rx_ctl1 &= ~RX_CTL1_RX_DMA_START;
728
+ allwinner_sun8i_emac_update_irq(s);
729
+
730
+ return size;
731
+}
732
+
733
+static void allwinner_sun8i_emac_transmit(AwSun8iEmacState *s)
734
+{
735
+ NetClientState *nc = qemu_get_queue(s->nic);
736
+ FrameDescriptor desc;
737
+ size_t bytes = 0;
738
+ size_t packet_bytes = 0;
739
+ size_t transmitted = 0;
740
+ static uint8_t packet_buf[2048];
741
+
742
+ s->tx_desc_curr = allwinner_sun8i_emac_tx_desc(s, &desc, 0);
743
+
744
+ /* Read all transmit descriptors */
745
+ while (s->tx_desc_curr != 0) {
746
+
747
+ /* Read from physical memory into packet buffer */
748
+ bytes = desc.status2 & DESC_STATUS2_BUF_SIZE_MASK;
749
+ if (bytes + packet_bytes > sizeof(packet_buf)) {
750
+ desc.status |= TX_DESC_STATUS_LENGTH_ERR;
751
+ break;
752
+ }
753
+ cpu_physical_memory_read(desc.addr, packet_buf + packet_bytes, bytes);
754
+ packet_bytes += bytes;
755
+ desc.status &= ~DESC_STATUS_CTL;
756
+ allwinner_sun8i_emac_flush_desc(&desc, s->tx_desc_curr);
757
+
758
+ /* After the last descriptor, send the packet */
759
+ if (desc.status2 & TX_DESC_STATUS2_LAST_DESC) {
760
+ if (desc.status2 & TX_DESC_STATUS2_CHECKSUM_MASK) {
761
+ net_checksum_calculate(packet_buf, packet_bytes);
762
+ }
763
+
764
+ qemu_send_packet(nc, packet_buf, packet_bytes);
765
+ trace_allwinner_sun8i_emac_transmit(s->tx_desc_curr, desc.addr,
766
+ bytes);
767
+
768
+ packet_bytes = 0;
769
+ transmitted++;
770
+ }
771
+ s->tx_desc_curr = allwinner_sun8i_emac_next_desc(&desc, 0);
772
+ }
773
+
774
+ /* Raise transmit completed interrupt */
775
+ if (transmitted > 0) {
776
+ s->int_sta |= INT_STA_TX;
777
+ s->tx_ctl1 &= ~TX_CTL1_TX_DMA_START;
778
+ allwinner_sun8i_emac_update_irq(s);
779
+ }
780
+}
781
+
782
+static void allwinner_sun8i_emac_reset(DeviceState *dev)
783
+{
784
+ AwSun8iEmacState *s = AW_SUN8I_EMAC(dev);
785
+ NetClientState *nc = qemu_get_queue(s->nic);
786
+
787
+ trace_allwinner_sun8i_emac_reset();
788
+
789
+ s->mii_cmd = 0;
790
+ s->mii_data = 0;
791
+ s->basic_ctl0 = 0;
792
+ s->basic_ctl1 = REG_BASIC_CTL_1_RST;
793
+ s->int_en = 0;
794
+ s->int_sta = 0;
795
+ s->frm_flt = 0;
796
+ s->rx_ctl0 = 0;
797
+ s->rx_ctl1 = RX_CTL1_RX_MD;
798
+ s->rx_desc_head = 0;
799
+ s->rx_desc_curr = 0;
800
+ s->tx_ctl0 = 0;
801
+ s->tx_ctl1 = 0;
802
+ s->tx_desc_head = 0;
803
+ s->tx_desc_curr = 0;
804
+ s->tx_flowctl = 0;
805
+
806
+ allwinner_sun8i_emac_mii_reset(s, !nc->link_down);
807
+}
808
+
809
+static uint64_t allwinner_sun8i_emac_read(void *opaque, hwaddr offset,
810
+ unsigned size)
811
+{
812
+ AwSun8iEmacState *s = AW_SUN8I_EMAC(opaque);
813
+ uint64_t value = 0;
814
+ FrameDescriptor desc;
815
+
816
+ switch (offset) {
817
+ case REG_BASIC_CTL_0: /* Basic Control 0 */
818
+ value = s->basic_ctl0;
819
+ break;
820
+ case REG_BASIC_CTL_1: /* Basic Control 1 */
821
+ value = s->basic_ctl1;
822
+ break;
823
+ case REG_INT_STA: /* Interrupt Status */
824
+ value = s->int_sta;
825
+ break;
826
+ case REG_INT_EN: /* Interupt Enable */
827
+ value = s->int_en;
828
+ break;
829
+ case REG_TX_CTL_0: /* Transmit Control 0 */
830
+ value = s->tx_ctl0;
831
+ break;
832
+ case REG_TX_CTL_1: /* Transmit Control 1 */
833
+ value = s->tx_ctl1;
834
+ break;
835
+ case REG_TX_FLOW_CTL: /* Transmit Flow Control */
836
+ value = s->tx_flowctl;
837
+ break;
838
+ case REG_TX_DMA_DESC_LIST: /* Transmit Descriptor List Address */
839
+ value = s->tx_desc_head;
840
+ break;
841
+ case REG_RX_CTL_0: /* Receive Control 0 */
842
+ value = s->rx_ctl0;
843
+ break;
844
+ case REG_RX_CTL_1: /* Receive Control 1 */
845
+ value = s->rx_ctl1;
846
+ break;
847
+ case REG_RX_DMA_DESC_LIST: /* Receive Descriptor List Address */
848
+ value = s->rx_desc_head;
849
+ break;
850
+ case REG_FRM_FLT: /* Receive Frame Filter */
851
+ value = s->frm_flt;
852
+ break;
853
+ case REG_RX_HASH_0: /* Receive Hash Table 0 */
854
+ case REG_RX_HASH_1: /* Receive Hash Table 1 */
855
+ break;
856
+ case REG_MII_CMD: /* Management Interface Command */
857
+ value = s->mii_cmd;
858
+ break;
859
+ case REG_MII_DATA: /* Management Interface Data */
860
+ value = s->mii_data;
861
+ break;
862
+ case REG_ADDR_HIGH: /* MAC Address High */
863
+ value = *(((uint32_t *) (s->conf.macaddr.a)) + 1);
864
+ break;
865
+ case REG_ADDR_LOW: /* MAC Address Low */
866
+ value = *(uint32_t *) (s->conf.macaddr.a);
867
+ break;
868
+ case REG_TX_DMA_STA: /* Transmit DMA Status */
869
+ break;
870
+ case REG_TX_CUR_DESC: /* Transmit Current Descriptor */
871
+ value = s->tx_desc_curr;
872
+ break;
873
+ case REG_TX_CUR_BUF: /* Transmit Current Buffer */
874
+ if (s->tx_desc_curr != 0) {
875
+ cpu_physical_memory_read(s->tx_desc_curr, &desc, sizeof(desc));
876
+ value = desc.addr;
877
+ } else {
878
+ value = 0;
879
+ }
880
+ break;
881
+ case REG_RX_DMA_STA: /* Receive DMA Status */
882
+ break;
883
+ case REG_RX_CUR_DESC: /* Receive Current Descriptor */
884
+ value = s->rx_desc_curr;
885
+ break;
886
+ case REG_RX_CUR_BUF: /* Receive Current Buffer */
887
+ if (s->rx_desc_curr != 0) {
888
+ cpu_physical_memory_read(s->rx_desc_curr, &desc, sizeof(desc));
889
+ value = desc.addr;
890
+ } else {
891
+ value = 0;
892
+ }
893
+ break;
894
+ case REG_RGMII_STA: /* RGMII Status */
895
+ break;
896
+ default:
897
+ qemu_log_mask(LOG_UNIMP, "allwinner-h3-emac: read access to unknown "
898
+ "EMAC register 0x" TARGET_FMT_plx "\n",
899
+ offset);
900
+ }
901
+
902
+ trace_allwinner_sun8i_emac_read(offset, value);
903
+ return value;
904
+}
905
+
906
+static void allwinner_sun8i_emac_write(void *opaque, hwaddr offset,
907
+ uint64_t value, unsigned size)
908
+{
909
+ AwSun8iEmacState *s = AW_SUN8I_EMAC(opaque);
910
+ NetClientState *nc = qemu_get_queue(s->nic);
911
+
912
+ trace_allwinner_sun8i_emac_write(offset, value);
913
+
914
+ switch (offset) {
915
+ case REG_BASIC_CTL_0: /* Basic Control 0 */
916
+ s->basic_ctl0 = value;
917
+ break;
918
+ case REG_BASIC_CTL_1: /* Basic Control 1 */
919
+ if (value & BASIC_CTL1_SOFTRST) {
920
+ allwinner_sun8i_emac_reset(DEVICE(s));
921
+ value &= ~BASIC_CTL1_SOFTRST;
922
+ }
923
+ s->basic_ctl1 = value;
924
+ if (allwinner_sun8i_emac_can_receive(nc)) {
925
+ qemu_flush_queued_packets(nc);
926
+ }
927
+ break;
928
+ case REG_INT_STA: /* Interrupt Status */
929
+ s->int_sta &= ~value;
930
+ allwinner_sun8i_emac_update_irq(s);
931
+ break;
932
+ case REG_INT_EN: /* Interrupt Enable */
933
+ s->int_en = value;
934
+ allwinner_sun8i_emac_update_irq(s);
935
+ break;
936
+ case REG_TX_CTL_0: /* Transmit Control 0 */
937
+ s->tx_ctl0 = value;
938
+ break;
939
+ case REG_TX_CTL_1: /* Transmit Control 1 */
940
+ s->tx_ctl1 = value;
941
+ if (value & TX_CTL1_TX_DMA_EN) {
942
+ allwinner_sun8i_emac_transmit(s);
943
+ }
944
+ break;
945
+ case REG_TX_FLOW_CTL: /* Transmit Flow Control */
946
+ s->tx_flowctl = value;
947
+ break;
948
+ case REG_TX_DMA_DESC_LIST: /* Transmit Descriptor List Address */
949
+ s->tx_desc_head = value;
950
+ s->tx_desc_curr = value;
951
+ break;
952
+ case REG_RX_CTL_0: /* Receive Control 0 */
953
+ s->rx_ctl0 = value;
954
+ break;
955
+ case REG_RX_CTL_1: /* Receive Control 1 */
956
+ s->rx_ctl1 = value | RX_CTL1_RX_MD;
957
+ if ((value & RX_CTL1_RX_DMA_EN) &&
958
+ allwinner_sun8i_emac_can_receive(nc)) {
959
+ qemu_flush_queued_packets(nc);
960
+ }
961
+ break;
962
+ case REG_RX_DMA_DESC_LIST: /* Receive Descriptor List Address */
963
+ s->rx_desc_head = value;
964
+ s->rx_desc_curr = value;
965
+ break;
966
+ case REG_FRM_FLT: /* Receive Frame Filter */
967
+ s->frm_flt = value;
968
+ break;
969
+ case REG_RX_HASH_0: /* Receive Hash Table 0 */
970
+ case REG_RX_HASH_1: /* Receive Hash Table 1 */
971
+ break;
972
+ case REG_MII_CMD: /* Management Interface Command */
973
+ s->mii_cmd = value & ~MII_CMD_PHY_BUSY;
974
+ allwinner_sun8i_emac_mii_cmd(s);
975
+ break;
976
+ case REG_MII_DATA: /* Management Interface Data */
977
+ s->mii_data = value;
978
+ break;
979
+ case REG_ADDR_HIGH: /* MAC Address High */
980
+ s->conf.macaddr.a[4] = (value & 0xff);
981
+ s->conf.macaddr.a[5] = (value & 0xff00) >> 8;
982
+ break;
983
+ case REG_ADDR_LOW: /* MAC Address Low */
984
+ s->conf.macaddr.a[0] = (value & 0xff);
985
+ s->conf.macaddr.a[1] = (value & 0xff00) >> 8;
986
+ s->conf.macaddr.a[2] = (value & 0xff0000) >> 16;
987
+ s->conf.macaddr.a[3] = (value & 0xff000000) >> 24;
988
+ break;
989
+ case REG_TX_DMA_STA: /* Transmit DMA Status */
990
+ case REG_TX_CUR_DESC: /* Transmit Current Descriptor */
991
+ case REG_TX_CUR_BUF: /* Transmit Current Buffer */
992
+ case REG_RX_DMA_STA: /* Receive DMA Status */
993
+ case REG_RX_CUR_DESC: /* Receive Current Descriptor */
994
+ case REG_RX_CUR_BUF: /* Receive Current Buffer */
995
+ case REG_RGMII_STA: /* RGMII Status */
996
+ break;
997
+ default:
998
+ qemu_log_mask(LOG_UNIMP, "allwinner-h3-emac: write access to unknown "
999
+ "EMAC register 0x" TARGET_FMT_plx "\n",
1000
+ offset);
1001
+ }
1002
+}
1003
+
1004
+static void allwinner_sun8i_emac_set_link(NetClientState *nc)
1005
+{
1006
+ AwSun8iEmacState *s = qemu_get_nic_opaque(nc);
1007
+
1008
+ trace_allwinner_sun8i_emac_set_link(!nc->link_down);
1009
+ allwinner_sun8i_emac_mii_set_link(s, !nc->link_down);
1010
+}
1011
+
1012
+static const MemoryRegionOps allwinner_sun8i_emac_mem_ops = {
1013
+ .read = allwinner_sun8i_emac_read,
1014
+ .write = allwinner_sun8i_emac_write,
1015
+ .endianness = DEVICE_NATIVE_ENDIAN,
1016
+ .valid = {
1017
+ .min_access_size = 4,
1018
+ .max_access_size = 4,
1019
+ },
1020
+ .impl.min_access_size = 4,
1021
+};
1022
+
1023
+static NetClientInfo net_allwinner_sun8i_emac_info = {
1024
+ .type = NET_CLIENT_DRIVER_NIC,
1025
+ .size = sizeof(NICState),
1026
+ .can_receive = allwinner_sun8i_emac_can_receive,
1027
+ .receive = allwinner_sun8i_emac_receive,
1028
+ .link_status_changed = allwinner_sun8i_emac_set_link,
1029
+};
1030
+
1031
+static void allwinner_sun8i_emac_init(Object *obj)
1032
+{
1033
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
1034
+ AwSun8iEmacState *s = AW_SUN8I_EMAC(obj);
1035
+
1036
+ memory_region_init_io(&s->iomem, OBJECT(s), &allwinner_sun8i_emac_mem_ops,
1037
+ s, TYPE_AW_SUN8I_EMAC, 64 * KiB);
1038
+ sysbus_init_mmio(sbd, &s->iomem);
1039
+ sysbus_init_irq(sbd, &s->irq);
1040
+}
1041
+
1042
+static void allwinner_sun8i_emac_realize(DeviceState *dev, Error **errp)
1043
+{
1044
+ AwSun8iEmacState *s = AW_SUN8I_EMAC(dev);
1045
+
1046
+ qemu_macaddr_default_if_unset(&s->conf.macaddr);
1047
+ s->nic = qemu_new_nic(&net_allwinner_sun8i_emac_info, &s->conf,
1048
+ object_get_typename(OBJECT(dev)), dev->id, s);
1049
+ qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
1050
+}
1051
+
1052
+static Property allwinner_sun8i_emac_properties[] = {
1053
+ DEFINE_NIC_PROPERTIES(AwSun8iEmacState, conf),
1054
+ DEFINE_PROP_UINT8("phy-addr", AwSun8iEmacState, mii_phy_addr, 0),
1055
+ DEFINE_PROP_END_OF_LIST(),
1056
+};
1057
+
1058
+static int allwinner_sun8i_emac_post_load(void *opaque, int version_id)
1059
+{
1060
+ AwSun8iEmacState *s = opaque;
1061
+
1062
+ allwinner_sun8i_emac_set_link(qemu_get_queue(s->nic));
1063
+
1064
+ return 0;
1065
+}
1066
+
1067
+static const VMStateDescription vmstate_aw_emac = {
1068
+ .name = "allwinner-sun8i-emac",
88
+ .version_id = 1,
1069
+ .version_id = 1,
89
+ .minimum_version_id = 1,
1070
+ .minimum_version_id = 1,
90
+ .needed = nvic_security_needed,
1071
+ .post_load = allwinner_sun8i_emac_post_load,
91
+ .post_load = &nvic_security_post_load,
92
+ .fields = (VMStateField[]) {
1072
+ .fields = (VMStateField[]) {
93
+ VMSTATE_STRUCT_ARRAY(sec_vectors, NVICState, NVIC_INTERNAL_VECTORS, 1,
1073
+ VMSTATE_UINT8(mii_phy_addr, AwSun8iEmacState),
94
+ vmstate_VecInfo, VecInfo),
1074
+ VMSTATE_UINT32(mii_cmd, AwSun8iEmacState),
1075
+ VMSTATE_UINT32(mii_data, AwSun8iEmacState),
1076
+ VMSTATE_UINT32(mii_cr, AwSun8iEmacState),
1077
+ VMSTATE_UINT32(mii_st, AwSun8iEmacState),
1078
+ VMSTATE_UINT32(mii_adv, AwSun8iEmacState),
1079
+ VMSTATE_UINT32(basic_ctl0, AwSun8iEmacState),
1080
+ VMSTATE_UINT32(basic_ctl1, AwSun8iEmacState),
1081
+ VMSTATE_UINT32(int_en, AwSun8iEmacState),
1082
+ VMSTATE_UINT32(int_sta, AwSun8iEmacState),
1083
+ VMSTATE_UINT32(frm_flt, AwSun8iEmacState),
1084
+ VMSTATE_UINT32(rx_ctl0, AwSun8iEmacState),
1085
+ VMSTATE_UINT32(rx_ctl1, AwSun8iEmacState),
1086
+ VMSTATE_UINT32(rx_desc_head, AwSun8iEmacState),
1087
+ VMSTATE_UINT32(rx_desc_curr, AwSun8iEmacState),
1088
+ VMSTATE_UINT32(tx_ctl0, AwSun8iEmacState),
1089
+ VMSTATE_UINT32(tx_ctl1, AwSun8iEmacState),
1090
+ VMSTATE_UINT32(tx_desc_head, AwSun8iEmacState),
1091
+ VMSTATE_UINT32(tx_desc_curr, AwSun8iEmacState),
1092
+ VMSTATE_UINT32(tx_flowctl, AwSun8iEmacState),
95
+ VMSTATE_END_OF_LIST()
1093
+ VMSTATE_END_OF_LIST()
96
+ }
1094
+ }
97
+};
1095
+};
98
+
1096
+
99
static const VMStateDescription vmstate_nvic = {
1097
+static void allwinner_sun8i_emac_class_init(ObjectClass *klass, void *data)
100
.name = "armv7m_nvic",
1098
+{
101
.version_id = 4,
1099
+ DeviceClass *dc = DEVICE_CLASS(klass);
102
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_nvic = {
1100
+
103
vmstate_VecInfo, VecInfo),
1101
+ dc->realize = allwinner_sun8i_emac_realize;
104
VMSTATE_UINT32(prigroup, NVICState),
1102
+ dc->reset = allwinner_sun8i_emac_reset;
105
VMSTATE_END_OF_LIST()
1103
+ dc->vmsd = &vmstate_aw_emac;
106
+ },
1104
+ device_class_set_props(dc, allwinner_sun8i_emac_properties);
107
+ .subsections = (const VMStateDescription*[]) {
1105
+}
108
+ &vmstate_nvic_security,
1106
+
109
+ NULL
1107
+static const TypeInfo allwinner_sun8i_emac_info = {
110
}
1108
+ .name = TYPE_AW_SUN8I_EMAC,
111
};
1109
+ .parent = TYPE_SYS_BUS_DEVICE,
112
1110
+ .instance_size = sizeof(AwSun8iEmacState),
113
@@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_reset(DeviceState *dev)
1111
+ .instance_init = allwinner_sun8i_emac_init,
114
s->vectors[ARMV7M_EXCP_NMI].prio = -2;
1112
+ .class_init = allwinner_sun8i_emac_class_init,
115
s->vectors[ARMV7M_EXCP_HARD].prio = -1;
1113
+};
116
1114
+
117
+ if (arm_feature(&s->cpu->env, ARM_FEATURE_M_SECURITY)) {
1115
+static void allwinner_sun8i_emac_register_types(void)
118
+ s->sec_vectors[ARMV7M_EXCP_HARD].enabled = 1;
1116
+{
119
+ s->sec_vectors[ARMV7M_EXCP_SVC].enabled = 1;
1117
+ type_register_static(&allwinner_sun8i_emac_info);
120
+ s->sec_vectors[ARMV7M_EXCP_PENDSV].enabled = 1;
1118
+}
121
+ s->sec_vectors[ARMV7M_EXCP_SYSTICK].enabled = 1;
1119
+
122
+
1120
+type_init(allwinner_sun8i_emac_register_types)
123
+ /* AIRCR.BFHFNMINS resets to 0 so Secure HF is priority -1 (R_CMTC) */
1121
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
124
+ s->sec_vectors[ARMV7M_EXCP_HARD].prio = -1;
1122
index XXXXXXX..XXXXXXX 100644
125
+ }
1123
--- a/hw/arm/Kconfig
126
+
1124
+++ b/hw/arm/Kconfig
127
/* Strictly speaking the reset handler should be enabled.
1125
@@ -XXX,XX +XXX,XX @@ config ALLWINNER_A10
128
* However, we don't simulate soft resets through the NVIC,
1126
config ALLWINNER_H3
129
* and the reset vector should never be pended.
1127
bool
1128
select ALLWINNER_A10_PIT
1129
+ select ALLWINNER_SUN8I_EMAC
1130
select SERIAL
1131
select ARM_TIMER
1132
select ARM_GIC
1133
diff --git a/hw/net/Kconfig b/hw/net/Kconfig
1134
index XXXXXXX..XXXXXXX 100644
1135
--- a/hw/net/Kconfig
1136
+++ b/hw/net/Kconfig
1137
@@ -XXX,XX +XXX,XX @@ config MIPSNET
1138
config ALLWINNER_EMAC
1139
bool
1140
1141
+config ALLWINNER_SUN8I_EMAC
1142
+ bool
1143
+
1144
config IMX_FEC
1145
bool
1146
1147
diff --git a/hw/net/trace-events b/hw/net/trace-events
1148
index XXXXXXX..XXXXXXX 100644
1149
--- a/hw/net/trace-events
1150
+++ b/hw/net/trace-events
1151
@@ -XXX,XX +XXX,XX @@
1152
# See docs/devel/tracing.txt for syntax documentation.
1153
1154
+# allwinner-sun8i-emac.c
1155
+allwinner_sun8i_emac_mii_write_reg(uint32_t reg, uint32_t value) "MII write: reg=0x%" PRIx32 " value=0x%" PRIx32
1156
+allwinner_sun8i_emac_mii_read_reg(uint32_t reg, uint32_t value) "MII read: reg=0x%" PRIx32 " value=0x%" PRIx32
1157
+allwinner_sun8i_emac_receive(uint32_t desc, uint32_t paddr, uint32_t bytes) "RX packet: desc=0x%" PRIx32 " paddr=0x%" PRIx32 " bytes=%" PRIu32
1158
+allwinner_sun8i_emac_transmit(uint32_t desc, uint32_t paddr, uint32_t bytes) "TX packet: desc=0x%" PRIx32 " paddr=0x%" PRIx32 " bytes=%" PRIu32
1159
+allwinner_sun8i_emac_reset(void) "HW reset"
1160
+allwinner_sun8i_emac_set_link(bool active) "Set link: active=%u"
1161
+allwinner_sun8i_emac_read(uint64_t offset, uint64_t val) "MMIO read: offset=0x%" PRIx64 " value=0x%" PRIx64
1162
+allwinner_sun8i_emac_write(uint64_t offset, uint64_t val) "MMIO write: offset=0x%" PRIx64 " value=0x%" PRIx64
1163
+
1164
# etraxfs_eth.c
1165
mdio_phy_read(int regnum, uint16_t value) "read phy_reg:%d value:0x%04x"
1166
mdio_phy_write(int regnum, uint16_t value) "write phy_reg:%d value:0x%04x"
130
--
1167
--
131
2.7.4
1168
2.20.1
132
1169
133
1170
diff view generated by jsdifflib
1
Now that we have a banked FAULTMASK register and banked exceptions,
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
2
we can implement the correct check in cpu_mmu_index() for whether
3
the MPU_CTRL.HFNMIENA bit's effect should apply. This bit causes
4
handlers which have requested a negative execution priority to run
5
with the MPU disabled. In v8M the test has to check this for the
6
current security state and so takes account of banking.
7
2
3
A real Allwinner H3 SoC contains a Boot ROM which is the
4
first code that runs right after the SoC is powered on.
5
The Boot ROM is responsible for loading user code (e.g. a bootloader)
6
from any of the supported external devices and writing the downloaded
7
code to internal SRAM. After loading the SoC begins executing the code
8
written to SRAM.
9
10
This commits adds emulation of the Boot ROM firmware setup functionality
11
by loading user code from SD card in the A1 SRAM. While the A1 SRAM is
12
64KiB, we limit the size to 32KiB because the real H3 Boot ROM also rejects
13
sizes larger than 32KiB. For reference, this behaviour is documented
14
by the Linux Sunxi project wiki at:
15
16
https://linux-sunxi.org/BROM#U-Boot_SPL_limitations
17
18
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
19
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
20
Message-id: 20200311221854.30370-11-nieklinnenbank@gmail.com
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
21
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
Message-id: 1505240046-11454-17-git-send-email-peter.maydell@linaro.org
11
---
22
---
12
target/arm/cpu.h | 21 ++++++++++++++++-----
23
include/hw/arm/allwinner-h3.h | 21 +++++++++++++++++++++
13
hw/intc/armv7m_nvic.c | 29 +++++++++++++++++++++++++++++
24
hw/arm/allwinner-h3.c | 17 +++++++++++++++++
14
2 files changed, 45 insertions(+), 5 deletions(-)
25
hw/arm/orangepi.c | 5 +++++
26
3 files changed, 43 insertions(+)
15
27
16
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
28
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
17
index XXXXXXX..XXXXXXX 100644
29
index XXXXXXX..XXXXXXX 100644
18
--- a/target/arm/cpu.h
30
--- a/include/hw/arm/allwinner-h3.h
19
+++ b/target/arm/cpu.h
31
+++ b/include/hw/arm/allwinner-h3.h
20
@@ -XXX,XX +XXX,XX @@ int armv7m_nvic_complete_irq(void *opaque, int irq);
32
@@ -XXX,XX +XXX,XX @@
21
* (v8M ARM ARM I_PKLD.)
33
#include "hw/sd/allwinner-sdhost.h"
22
*/
34
#include "hw/net/allwinner-sun8i-emac.h"
23
int armv7m_nvic_raw_execution_priority(void *opaque);
35
#include "target/arm/cpu.h"
36
+#include "sysemu/block-backend.h"
37
38
/**
39
* Allwinner H3 device list
40
@@ -XXX,XX +XXX,XX @@ typedef struct AwH3State {
41
MemoryRegion sram_c;
42
} AwH3State;
43
24
+/**
44
+/**
25
+ * armv7m_nvic_neg_prio_requested: return true if the requested execution
45
+ * Emulate Boot ROM firmware setup functionality.
26
+ * priority is negative for the specified security state.
46
+ *
27
+ * @opaque: the NVIC
47
+ * A real Allwinner H3 SoC contains a Boot ROM
28
+ * @secure: the security state to test
48
+ * which is the first code that runs right after
29
+ * This corresponds to the pseudocode IsReqExecPriNeg().
49
+ * the SoC is powered on. The Boot ROM is responsible
50
+ * for loading user code (e.g. a bootloader) from any
51
+ * of the supported external devices and writing the
52
+ * downloaded code to internal SRAM. After loading the SoC
53
+ * begins executing the code written to SRAM.
54
+ *
55
+ * This function emulates the Boot ROM by copying 32 KiB
56
+ * of data from the given block device and writes it to
57
+ * the start of the first internal SRAM memory.
58
+ *
59
+ * @s: Allwinner H3 state object pointer
60
+ * @blk: Block backend device object pointer
30
+ */
61
+ */
31
+#ifndef CONFIG_USER_ONLY
62
+void allwinner_h3_bootrom_setup(AwH3State *s, BlockBackend *blk);
32
+bool armv7m_nvic_neg_prio_requested(void *opaque, bool secure);
63
+
33
+#else
64
#endif /* HW_ARM_ALLWINNER_H3_H */
34
+static inline bool armv7m_nvic_neg_prio_requested(void *opaque, bool secure)
65
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
66
index XXXXXXX..XXXXXXX 100644
67
--- a/hw/arm/allwinner-h3.c
68
+++ b/hw/arm/allwinner-h3.c
69
@@ -XXX,XX +XXX,XX @@
70
#include "hw/char/serial.h"
71
#include "hw/misc/unimp.h"
72
#include "hw/usb/hcd-ehci.h"
73
+#include "hw/loader.h"
74
#include "sysemu/sysemu.h"
75
#include "hw/arm/allwinner-h3.h"
76
77
@@ -XXX,XX +XXX,XX @@ enum {
78
AW_H3_GIC_NUM_SPI = 128
79
};
80
81
+void allwinner_h3_bootrom_setup(AwH3State *s, BlockBackend *blk)
35
+{
82
+{
36
+ return false;
83
+ const int64_t rom_size = 32 * KiB;
37
+}
84
+ g_autofree uint8_t *buffer = g_new0(uint8_t, rom_size);
38
+#endif
39
40
/* Interface for defining coprocessor registers.
41
* Registers are defined in tables of arm_cp_reginfo structs
42
@@ -XXX,XX +XXX,XX @@ static inline int cpu_mmu_index(CPUARMState *env, bool ifetch)
43
if (arm_feature(env, ARM_FEATURE_M)) {
44
ARMMMUIdx mmu_idx = el == 0 ? ARMMMUIdx_MUser : ARMMMUIdx_MPriv;
45
46
- /* Execution priority is negative if FAULTMASK is set or
47
- * we're in a HardFault or NMI handler.
48
- */
49
- if ((env->v7m.exception > 0 && env->v7m.exception <= 3)
50
- || env->v7m.faultmask[env->v7m.secure]) {
51
+ if (armv7m_nvic_neg_prio_requested(env->nvic, env->v7m.secure)) {
52
mmu_idx = ARMMMUIdx_MNegPri;
53
}
54
55
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
56
index XXXXXXX..XXXXXXX 100644
57
--- a/hw/intc/armv7m_nvic.c
58
+++ b/hw/intc/armv7m_nvic.c
59
@@ -XXX,XX +XXX,XX @@ static inline int nvic_exec_prio(NVICState *s)
60
return MIN(running, s->exception_prio);
61
}
62
63
+bool armv7m_nvic_neg_prio_requested(void *opaque, bool secure)
64
+{
65
+ /* Return true if the requested execution priority is negative
66
+ * for the specified security state, ie that security state
67
+ * has an active NMI or HardFault or has set its FAULTMASK.
68
+ * Note that this is not the same as whether the execution
69
+ * priority is actually negative (for instance AIRCR.PRIS may
70
+ * mean we don't allow FAULTMASK_NS to actually make the execution
71
+ * priority negative). Compare pseudocode IsReqExcPriNeg().
72
+ */
73
+ NVICState *s = opaque;
74
+
85
+
75
+ if (s->cpu->env.v7m.faultmask[secure]) {
86
+ if (blk_pread(blk, 8 * KiB, buffer, rom_size) < 0) {
76
+ return true;
87
+ error_setg(&error_fatal, "%s: failed to read BlockBackend data",
88
+ __func__);
89
+ return;
77
+ }
90
+ }
78
+
91
+
79
+ if (secure ? s->sec_vectors[ARMV7M_EXCP_HARD].active :
92
+ rom_add_blob("allwinner-h3.bootrom", buffer, rom_size,
80
+ s->vectors[ARMV7M_EXCP_HARD].active) {
93
+ rom_size, s->memmap[AW_H3_SRAM_A1],
81
+ return true;
94
+ NULL, NULL, NULL, NULL, false);
82
+ }
83
+
84
+ if (s->vectors[ARMV7M_EXCP_NMI].active &&
85
+ exc_targets_secure(s, ARMV7M_EXCP_NMI) == secure) {
86
+ return true;
87
+ }
88
+
89
+ return false;
90
+}
95
+}
91
+
96
+
92
bool armv7m_nvic_can_take_pending_exception(void *opaque)
97
static void allwinner_h3_init(Object *obj)
93
{
98
{
94
NVICState *s = opaque;
99
AwH3State *s = AW_H3(obj);
100
diff --git a/hw/arm/orangepi.c b/hw/arm/orangepi.c
101
index XXXXXXX..XXXXXXX 100644
102
--- a/hw/arm/orangepi.c
103
+++ b/hw/arm/orangepi.c
104
@@ -XXX,XX +XXX,XX @@ static void orangepi_init(MachineState *machine)
105
memory_region_add_subregion(get_system_memory(), h3->memmap[AW_H3_SDRAM],
106
machine->ram);
107
108
+ /* Load target kernel or start using BootROM */
109
+ if (!machine->kernel_filename && blk_is_available(blk)) {
110
+ /* Use Boot ROM to copy data from SD card to SRAM */
111
+ allwinner_h3_bootrom_setup(h3, blk);
112
+ }
113
orangepi_binfo.loader_start = h3->memmap[AW_H3_SDRAM];
114
orangepi_binfo.ram_size = machine->ram_size;
115
arm_load_kernel(ARM_CPU(first_cpu), machine, &orangepi_binfo);
95
--
116
--
96
2.7.4
117
2.20.1
97
118
98
119
diff view generated by jsdifflib
1
Update nvic_exec_prio() to support the v8M changes:
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
2
* BASEPRI, FAULTMASK and PRIMASK are all banked
3
* AIRCR.PRIS can affect NS priorities
4
* AIRCR.BFHFNMINS affects FAULTMASK behaviour
5
2
6
These changes mean that it's no longer possible to
3
In the Allwinner H3 SoC the SDRAM controller is responsible
7
definitely say that if FAULTMASK is set it overrides
4
for interfacing with the external Synchronous Dynamic Random
8
PRIMASK, and if PRIMASK is set it overrides BASEPRI
5
Access Memory (SDRAM). Types of memory that the SDRAM controller
9
(since if PRIMASK_NS is set and AIRCR.PRIS is set then
6
supports are DDR2/DDR3 and capacities of up to 2GiB. This commit
10
whether that 0x80 priority should take effect or the
7
adds emulation support of the Allwinner H3 SDRAM controller.
11
priority in BASEPRI_S depends on the value of BASEPRI_S,
12
for instance). So we switch to the same approach used
13
by the pseudocode of working through BASEPRI, PRIMASK
14
and FAULTMASK and overriding the previous values if
15
needed.
16
8
9
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
10
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
11
Message-id: 20200311221854.30370-12-nieklinnenbank@gmail.com
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
18
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
19
Message-id: 1505240046-11454-16-git-send-email-peter.maydell@linaro.org
20
---
13
---
21
hw/intc/armv7m_nvic.c | 51 ++++++++++++++++++++++++++++++++++++++++++---------
14
hw/misc/Makefile.objs | 1 +
22
1 file changed, 42 insertions(+), 9 deletions(-)
15
include/hw/arm/allwinner-h3.h | 5 +
16
include/hw/misc/allwinner-h3-dramc.h | 106 ++++++++
17
hw/arm/allwinner-h3.c | 19 +-
18
hw/arm/orangepi.c | 6 +
19
hw/misc/allwinner-h3-dramc.c | 358 +++++++++++++++++++++++++++
20
hw/misc/trace-events | 10 +
21
7 files changed, 502 insertions(+), 3 deletions(-)
22
create mode 100644 include/hw/misc/allwinner-h3-dramc.h
23
create mode 100644 hw/misc/allwinner-h3-dramc.c
23
24
24
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
25
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
25
index XXXXXXX..XXXXXXX 100644
26
index XXXXXXX..XXXXXXX 100644
26
--- a/hw/intc/armv7m_nvic.c
27
--- a/hw/misc/Makefile.objs
27
+++ b/hw/intc/armv7m_nvic.c
28
+++ b/hw/misc/Makefile.objs
28
@@ -XXX,XX +XXX,XX @@ static void nvic_recompute_state(NVICState *s)
29
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o
29
static inline int nvic_exec_prio(NVICState *s)
30
30
{
31
common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o
31
CPUARMState *env = &s->cpu->env;
32
obj-$(CONFIG_ALLWINNER_H3) += allwinner-cpucfg.o
32
- int running;
33
+common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-dramc.o
33
+ int running = NVIC_NOEXC_PRIO;
34
common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-sysctrl.o
34
35
common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-sid.o
35
- if (env->v7m.faultmask[env->v7m.secure]) {
36
common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o
36
- running = -1;
37
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
37
- } else if (env->v7m.primask[env->v7m.secure]) {
38
index XXXXXXX..XXXXXXX 100644
38
+ if (env->v7m.basepri[M_REG_NS] > 0) {
39
--- a/include/hw/arm/allwinner-h3.h
39
+ running = exc_group_prio(s, env->v7m.basepri[M_REG_NS], M_REG_NS);
40
+++ b/include/hw/arm/allwinner-h3.h
40
+ }
41
@@ -XXX,XX +XXX,XX @@
41
+
42
#include "hw/intc/arm_gic.h"
42
+ if (env->v7m.basepri[M_REG_S] > 0) {
43
#include "hw/misc/allwinner-h3-ccu.h"
43
+ int basepri = exc_group_prio(s, env->v7m.basepri[M_REG_S], M_REG_S);
44
#include "hw/misc/allwinner-cpucfg.h"
44
+ if (running > basepri) {
45
+#include "hw/misc/allwinner-h3-dramc.h"
45
+ running = basepri;
46
#include "hw/misc/allwinner-h3-sysctrl.h"
47
#include "hw/misc/allwinner-sid.h"
48
#include "hw/sd/allwinner-sdhost.h"
49
@@ -XXX,XX +XXX,XX @@ enum {
50
AW_H3_UART2,
51
AW_H3_UART3,
52
AW_H3_EMAC,
53
+ AW_H3_DRAMCOM,
54
+ AW_H3_DRAMCTL,
55
+ AW_H3_DRAMPHY,
56
AW_H3_GIC_DIST,
57
AW_H3_GIC_CPU,
58
AW_H3_GIC_HYP,
59
@@ -XXX,XX +XXX,XX @@ typedef struct AwH3State {
60
AwA10PITState timer;
61
AwH3ClockCtlState ccu;
62
AwCpuCfgState cpucfg;
63
+ AwH3DramCtlState dramc;
64
AwH3SysCtrlState sysctrl;
65
AwSidState sid;
66
AwSdHostState mmc0;
67
diff --git a/include/hw/misc/allwinner-h3-dramc.h b/include/hw/misc/allwinner-h3-dramc.h
68
new file mode 100644
69
index XXXXXXX..XXXXXXX
70
--- /dev/null
71
+++ b/include/hw/misc/allwinner-h3-dramc.h
72
@@ -XXX,XX +XXX,XX @@
73
+/*
74
+ * Allwinner H3 SDRAM Controller emulation
75
+ *
76
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
77
+ *
78
+ * This program is free software: you can redistribute it and/or modify
79
+ * it under the terms of the GNU General Public License as published by
80
+ * the Free Software Foundation, either version 2 of the License, or
81
+ * (at your option) any later version.
82
+ *
83
+ * This program is distributed in the hope that it will be useful,
84
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
85
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
86
+ * GNU General Public License for more details.
87
+ *
88
+ * You should have received a copy of the GNU General Public License
89
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
90
+ */
91
+
92
+#ifndef HW_MISC_ALLWINNER_H3_DRAMC_H
93
+#define HW_MISC_ALLWINNER_H3_DRAMC_H
94
+
95
+#include "qom/object.h"
96
+#include "hw/sysbus.h"
97
+#include "exec/hwaddr.h"
98
+
99
+/**
100
+ * Constants
101
+ * @{
102
+ */
103
+
104
+/** Highest register address used by DRAMCOM module */
105
+#define AW_H3_DRAMCOM_REGS_MAXADDR (0x804)
106
+
107
+/** Total number of known DRAMCOM registers */
108
+#define AW_H3_DRAMCOM_REGS_NUM (AW_H3_DRAMCOM_REGS_MAXADDR / \
109
+ sizeof(uint32_t))
110
+
111
+/** Highest register address used by DRAMCTL module */
112
+#define AW_H3_DRAMCTL_REGS_MAXADDR (0x88c)
113
+
114
+/** Total number of known DRAMCTL registers */
115
+#define AW_H3_DRAMCTL_REGS_NUM (AW_H3_DRAMCTL_REGS_MAXADDR / \
116
+ sizeof(uint32_t))
117
+
118
+/** Highest register address used by DRAMPHY module */
119
+#define AW_H3_DRAMPHY_REGS_MAXADDR (0x4)
120
+
121
+/** Total number of known DRAMPHY registers */
122
+#define AW_H3_DRAMPHY_REGS_NUM (AW_H3_DRAMPHY_REGS_MAXADDR / \
123
+ sizeof(uint32_t))
124
+
125
+/** @} */
126
+
127
+/**
128
+ * Object model
129
+ * @{
130
+ */
131
+
132
+#define TYPE_AW_H3_DRAMC "allwinner-h3-dramc"
133
+#define AW_H3_DRAMC(obj) \
134
+ OBJECT_CHECK(AwH3DramCtlState, (obj), TYPE_AW_H3_DRAMC)
135
+
136
+/** @} */
137
+
138
+/**
139
+ * Allwinner H3 SDRAM Controller object instance state.
140
+ */
141
+typedef struct AwH3DramCtlState {
142
+ /*< private >*/
143
+ SysBusDevice parent_obj;
144
+ /*< public >*/
145
+
146
+ /** Physical base address for start of RAM */
147
+ hwaddr ram_addr;
148
+
149
+ /** Total RAM size in megabytes */
150
+ uint32_t ram_size;
151
+
152
+ /**
153
+ * @name Memory Regions
154
+ * @{
155
+ */
156
+
157
+ MemoryRegion row_mirror; /**< Simulates rows for RAM size detection */
158
+ MemoryRegion row_mirror_alias; /**< Alias of the row which is mirrored */
159
+ MemoryRegion dramcom_iomem; /**< DRAMCOM module I/O registers */
160
+ MemoryRegion dramctl_iomem; /**< DRAMCTL module I/O registers */
161
+ MemoryRegion dramphy_iomem; /**< DRAMPHY module I/O registers */
162
+
163
+ /** @} */
164
+
165
+ /**
166
+ * @name Hardware Registers
167
+ * @{
168
+ */
169
+
170
+ uint32_t dramcom[AW_H3_DRAMCOM_REGS_NUM]; /**< Array of DRAMCOM registers */
171
+ uint32_t dramctl[AW_H3_DRAMCTL_REGS_NUM]; /**< Array of DRAMCTL registers */
172
+ uint32_t dramphy[AW_H3_DRAMPHY_REGS_NUM] ;/**< Array of DRAMPHY registers */
173
+
174
+ /** @} */
175
+
176
+} AwH3DramCtlState;
177
+
178
+#endif /* HW_MISC_ALLWINNER_H3_DRAMC_H */
179
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
180
index XXXXXXX..XXXXXXX 100644
181
--- a/hw/arm/allwinner-h3.c
182
+++ b/hw/arm/allwinner-h3.c
183
@@ -XXX,XX +XXX,XX @@ const hwaddr allwinner_h3_memmap[] = {
184
[AW_H3_UART2] = 0x01c28800,
185
[AW_H3_UART3] = 0x01c28c00,
186
[AW_H3_EMAC] = 0x01c30000,
187
+ [AW_H3_DRAMCOM] = 0x01c62000,
188
+ [AW_H3_DRAMCTL] = 0x01c63000,
189
+ [AW_H3_DRAMPHY] = 0x01c65000,
190
[AW_H3_GIC_DIST] = 0x01c81000,
191
[AW_H3_GIC_CPU] = 0x01c82000,
192
[AW_H3_GIC_HYP] = 0x01c84000,
193
@@ -XXX,XX +XXX,XX @@ struct AwH3Unimplemented {
194
{ "scr", 0x01c2c400, 1 * KiB },
195
{ "gpu", 0x01c40000, 64 * KiB },
196
{ "hstmr", 0x01c60000, 4 * KiB },
197
- { "dramcom", 0x01c62000, 4 * KiB },
198
- { "dramctl0", 0x01c63000, 4 * KiB },
199
- { "dramphy0", 0x01c65000, 4 * KiB },
200
{ "spi0", 0x01c68000, 4 * KiB },
201
{ "spi1", 0x01c69000, 4 * KiB },
202
{ "csi", 0x01cb0000, 320 * KiB },
203
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_init(Object *obj)
204
205
sysbus_init_child_obj(obj, "emac", &s->emac, sizeof(s->emac),
206
TYPE_AW_SUN8I_EMAC);
207
+
208
+ sysbus_init_child_obj(obj, "dramc", &s->dramc, sizeof(s->dramc),
209
+ TYPE_AW_H3_DRAMC);
210
+ object_property_add_alias(obj, "ram-addr", OBJECT(&s->dramc),
211
+ "ram-addr", &error_abort);
212
+ object_property_add_alias(obj, "ram-size", OBJECT(&s->dramc),
213
+ "ram-size", &error_abort);
214
}
215
216
static void allwinner_h3_realize(DeviceState *dev, Error **errp)
217
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
218
qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_UART3),
219
115200, serial_hd(3), DEVICE_NATIVE_ENDIAN);
220
221
+ /* DRAMC */
222
+ qdev_init_nofail(DEVICE(&s->dramc));
223
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->dramc), 0, s->memmap[AW_H3_DRAMCOM]);
224
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->dramc), 1, s->memmap[AW_H3_DRAMCTL]);
225
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->dramc), 2, s->memmap[AW_H3_DRAMPHY]);
226
+
227
/* Unimplemented devices */
228
for (i = 0; i < ARRAY_SIZE(unimplemented); i++) {
229
create_unimplemented_device(unimplemented[i].device_name,
230
diff --git a/hw/arm/orangepi.c b/hw/arm/orangepi.c
231
index XXXXXXX..XXXXXXX 100644
232
--- a/hw/arm/orangepi.c
233
+++ b/hw/arm/orangepi.c
234
@@ -XXX,XX +XXX,XX @@ static void orangepi_init(MachineState *machine)
235
/* Setup EMAC properties */
236
object_property_set_int(OBJECT(&h3->emac), 1, "phy-addr", &error_abort);
237
238
+ /* DRAMC */
239
+ object_property_set_uint(OBJECT(h3), h3->memmap[AW_H3_SDRAM],
240
+ "ram-addr", &error_abort);
241
+ object_property_set_int(OBJECT(h3), machine->ram_size / MiB, "ram-size",
242
+ &error_abort);
243
+
244
/* Mark H3 object realized */
245
object_property_set_bool(OBJECT(h3), true, "realized", &error_abort);
246
247
diff --git a/hw/misc/allwinner-h3-dramc.c b/hw/misc/allwinner-h3-dramc.c
248
new file mode 100644
249
index XXXXXXX..XXXXXXX
250
--- /dev/null
251
+++ b/hw/misc/allwinner-h3-dramc.c
252
@@ -XXX,XX +XXX,XX @@
253
+/*
254
+ * Allwinner H3 SDRAM Controller emulation
255
+ *
256
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
257
+ *
258
+ * This program is free software: you can redistribute it and/or modify
259
+ * it under the terms of the GNU General Public License as published by
260
+ * the Free Software Foundation, either version 2 of the License, or
261
+ * (at your option) any later version.
262
+ *
263
+ * This program is distributed in the hope that it will be useful,
264
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
265
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
266
+ * GNU General Public License for more details.
267
+ *
268
+ * You should have received a copy of the GNU General Public License
269
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
270
+ */
271
+
272
+#include "qemu/osdep.h"
273
+#include "qemu/units.h"
274
+#include "qemu/error-report.h"
275
+#include "hw/sysbus.h"
276
+#include "migration/vmstate.h"
277
+#include "qemu/log.h"
278
+#include "qemu/module.h"
279
+#include "exec/address-spaces.h"
280
+#include "hw/qdev-properties.h"
281
+#include "qapi/error.h"
282
+#include "hw/misc/allwinner-h3-dramc.h"
283
+#include "trace.h"
284
+
285
+#define REG_INDEX(offset) (offset / sizeof(uint32_t))
286
+
287
+/* DRAMCOM register offsets */
288
+enum {
289
+ REG_DRAMCOM_CR = 0x0000, /* Control Register */
290
+};
291
+
292
+/* DRAMCTL register offsets */
293
+enum {
294
+ REG_DRAMCTL_PIR = 0x0000, /* PHY Initialization Register */
295
+ REG_DRAMCTL_PGSR = 0x0010, /* PHY General Status Register */
296
+ REG_DRAMCTL_STATR = 0x0018, /* Status Register */
297
+};
298
+
299
+/* DRAMCTL register flags */
300
+enum {
301
+ REG_DRAMCTL_PGSR_INITDONE = (1 << 0),
302
+};
303
+
304
+enum {
305
+ REG_DRAMCTL_STATR_ACTIVE = (1 << 0),
306
+};
307
+
308
+static void allwinner_h3_dramc_map_rows(AwH3DramCtlState *s, uint8_t row_bits,
309
+ uint8_t bank_bits, uint16_t page_size)
310
+{
311
+ /*
312
+ * This function simulates row addressing behavior when bootloader
313
+ * software attempts to detect the amount of available SDRAM. In U-Boot
314
+ * the controller is configured with the widest row addressing available.
315
+ * Then a pattern is written to RAM at an offset on the row boundary size.
316
+ * If the value read back equals the value read back from the
317
+ * start of RAM, the bootloader knows the amount of row bits.
318
+ *
319
+ * This function inserts a mirrored memory region when the configured row
320
+ * bits are not matching the actual emulated memory, to simulate the
321
+ * same behavior on hardware as expected by the bootloader.
322
+ */
323
+ uint8_t row_bits_actual = 0;
324
+
325
+ /* Calculate the actual row bits using the ram_size property */
326
+ for (uint8_t i = 8; i < 12; i++) {
327
+ if (1 << i == s->ram_size) {
328
+ row_bits_actual = i + 3;
329
+ break;
46
+ }
330
+ }
47
+ }
331
+ }
48
+
332
+
49
+ if (env->v7m.primask[M_REG_NS]) {
333
+ if (s->ram_size == (1 << (row_bits - 3))) {
50
+ if (env->v7m.aircr & R_V7M_AIRCR_PRIS_MASK) {
334
+ /* When row bits is the expected value, remove the mirror */
51
+ if (running > NVIC_NS_PRIO_LIMIT) {
335
+ memory_region_set_enabled(&s->row_mirror_alias, false);
52
+ running = NVIC_NS_PRIO_LIMIT;
336
+ trace_allwinner_h3_dramc_rowmirror_disable();
53
+ }
337
+
54
+ } else {
338
+ } else if (row_bits_actual) {
55
+ running = 0;
339
+ /* Row bits not matching ram_size, install the rows mirror */
340
+ hwaddr row_mirror = s->ram_addr + ((1 << (row_bits_actual +
341
+ bank_bits)) * page_size);
342
+
343
+ memory_region_set_enabled(&s->row_mirror_alias, true);
344
+ memory_region_set_address(&s->row_mirror_alias, row_mirror);
345
+
346
+ trace_allwinner_h3_dramc_rowmirror_enable(row_mirror);
347
+ }
348
+}
349
+
350
+static uint64_t allwinner_h3_dramcom_read(void *opaque, hwaddr offset,
351
+ unsigned size)
352
+{
353
+ const AwH3DramCtlState *s = AW_H3_DRAMC(opaque);
354
+ const uint32_t idx = REG_INDEX(offset);
355
+
356
+ if (idx >= AW_H3_DRAMCOM_REGS_NUM) {
357
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
358
+ __func__, (uint32_t)offset);
359
+ return 0;
360
+ }
361
+
362
+ trace_allwinner_h3_dramcom_read(offset, s->dramcom[idx], size);
363
+
364
+ return s->dramcom[idx];
365
+}
366
+
367
+static void allwinner_h3_dramcom_write(void *opaque, hwaddr offset,
368
+ uint64_t val, unsigned size)
369
+{
370
+ AwH3DramCtlState *s = AW_H3_DRAMC(opaque);
371
+ const uint32_t idx = REG_INDEX(offset);
372
+
373
+ trace_allwinner_h3_dramcom_write(offset, val, size);
374
+
375
+ if (idx >= AW_H3_DRAMCOM_REGS_NUM) {
376
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
377
+ __func__, (uint32_t)offset);
378
+ return;
379
+ }
380
+
381
+ switch (offset) {
382
+ case REG_DRAMCOM_CR: /* Control Register */
383
+ allwinner_h3_dramc_map_rows(s, ((val >> 4) & 0xf) + 1,
384
+ ((val >> 2) & 0x1) + 2,
385
+ 1 << (((val >> 8) & 0xf) + 3));
386
+ break;
387
+ default:
388
+ break;
389
+ };
390
+
391
+ s->dramcom[idx] = (uint32_t) val;
392
+}
393
+
394
+static uint64_t allwinner_h3_dramctl_read(void *opaque, hwaddr offset,
395
+ unsigned size)
396
+{
397
+ const AwH3DramCtlState *s = AW_H3_DRAMC(opaque);
398
+ const uint32_t idx = REG_INDEX(offset);
399
+
400
+ if (idx >= AW_H3_DRAMCTL_REGS_NUM) {
401
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
402
+ __func__, (uint32_t)offset);
403
+ return 0;
404
+ }
405
+
406
+ trace_allwinner_h3_dramctl_read(offset, s->dramctl[idx], size);
407
+
408
+ return s->dramctl[idx];
409
+}
410
+
411
+static void allwinner_h3_dramctl_write(void *opaque, hwaddr offset,
412
+ uint64_t val, unsigned size)
413
+{
414
+ AwH3DramCtlState *s = AW_H3_DRAMC(opaque);
415
+ const uint32_t idx = REG_INDEX(offset);
416
+
417
+ trace_allwinner_h3_dramctl_write(offset, val, size);
418
+
419
+ if (idx >= AW_H3_DRAMCTL_REGS_NUM) {
420
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
421
+ __func__, (uint32_t)offset);
422
+ return;
423
+ }
424
+
425
+ switch (offset) {
426
+ case REG_DRAMCTL_PIR: /* PHY Initialization Register */
427
+ s->dramctl[REG_INDEX(REG_DRAMCTL_PGSR)] |= REG_DRAMCTL_PGSR_INITDONE;
428
+ s->dramctl[REG_INDEX(REG_DRAMCTL_STATR)] |= REG_DRAMCTL_STATR_ACTIVE;
429
+ break;
430
+ default:
431
+ break;
432
+ }
433
+
434
+ s->dramctl[idx] = (uint32_t) val;
435
+}
436
+
437
+static uint64_t allwinner_h3_dramphy_read(void *opaque, hwaddr offset,
438
+ unsigned size)
439
+{
440
+ const AwH3DramCtlState *s = AW_H3_DRAMC(opaque);
441
+ const uint32_t idx = REG_INDEX(offset);
442
+
443
+ if (idx >= AW_H3_DRAMPHY_REGS_NUM) {
444
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
445
+ __func__, (uint32_t)offset);
446
+ return 0;
447
+ }
448
+
449
+ trace_allwinner_h3_dramphy_read(offset, s->dramphy[idx], size);
450
+
451
+ return s->dramphy[idx];
452
+}
453
+
454
+static void allwinner_h3_dramphy_write(void *opaque, hwaddr offset,
455
+ uint64_t val, unsigned size)
456
+{
457
+ AwH3DramCtlState *s = AW_H3_DRAMC(opaque);
458
+ const uint32_t idx = REG_INDEX(offset);
459
+
460
+ trace_allwinner_h3_dramphy_write(offset, val, size);
461
+
462
+ if (idx >= AW_H3_DRAMPHY_REGS_NUM) {
463
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
464
+ __func__, (uint32_t)offset);
465
+ return;
466
+ }
467
+
468
+ s->dramphy[idx] = (uint32_t) val;
469
+}
470
+
471
+static const MemoryRegionOps allwinner_h3_dramcom_ops = {
472
+ .read = allwinner_h3_dramcom_read,
473
+ .write = allwinner_h3_dramcom_write,
474
+ .endianness = DEVICE_NATIVE_ENDIAN,
475
+ .valid = {
476
+ .min_access_size = 4,
477
+ .max_access_size = 4,
478
+ },
479
+ .impl.min_access_size = 4,
480
+};
481
+
482
+static const MemoryRegionOps allwinner_h3_dramctl_ops = {
483
+ .read = allwinner_h3_dramctl_read,
484
+ .write = allwinner_h3_dramctl_write,
485
+ .endianness = DEVICE_NATIVE_ENDIAN,
486
+ .valid = {
487
+ .min_access_size = 4,
488
+ .max_access_size = 4,
489
+ },
490
+ .impl.min_access_size = 4,
491
+};
492
+
493
+static const MemoryRegionOps allwinner_h3_dramphy_ops = {
494
+ .read = allwinner_h3_dramphy_read,
495
+ .write = allwinner_h3_dramphy_write,
496
+ .endianness = DEVICE_NATIVE_ENDIAN,
497
+ .valid = {
498
+ .min_access_size = 4,
499
+ .max_access_size = 4,
500
+ },
501
+ .impl.min_access_size = 4,
502
+};
503
+
504
+static void allwinner_h3_dramc_reset(DeviceState *dev)
505
+{
506
+ AwH3DramCtlState *s = AW_H3_DRAMC(dev);
507
+
508
+ /* Set default values for registers */
509
+ memset(&s->dramcom, 0, sizeof(s->dramcom));
510
+ memset(&s->dramctl, 0, sizeof(s->dramctl));
511
+ memset(&s->dramphy, 0, sizeof(s->dramphy));
512
+}
513
+
514
+static void allwinner_h3_dramc_realize(DeviceState *dev, Error **errp)
515
+{
516
+ AwH3DramCtlState *s = AW_H3_DRAMC(dev);
517
+
518
+ /* Only power of 2 RAM sizes from 256MiB up to 2048MiB are supported */
519
+ for (uint8_t i = 8; i < 13; i++) {
520
+ if (1 << i == s->ram_size) {
521
+ break;
522
+ } else if (i == 12) {
523
+ error_report("%s: ram-size %u MiB is not supported",
524
+ __func__, s->ram_size);
525
+ exit(1);
56
+ }
526
+ }
57
+ }
527
+ }
58
+
528
+
59
+ if (env->v7m.primask[M_REG_S]) {
529
+ /* Setup row mirror mappings */
60
running = 0;
530
+ memory_region_init_ram(&s->row_mirror, OBJECT(s),
61
- } else if (env->v7m.basepri[env->v7m.secure] > 0) {
531
+ "allwinner-h3-dramc.row-mirror",
62
- running = env->v7m.basepri[env->v7m.secure] &
532
+ 4 * KiB, &error_abort);
63
- nvic_gprio_mask(s, env->v7m.secure);
533
+ memory_region_add_subregion_overlap(get_system_memory(), s->ram_addr,
64
- } else {
534
+ &s->row_mirror, 10);
65
- running = NVIC_NOEXC_PRIO; /* lower than any possible priority */
535
+
66
}
536
+ memory_region_init_alias(&s->row_mirror_alias, OBJECT(s),
67
+
537
+ "allwinner-h3-dramc.row-mirror-alias",
68
+ if (env->v7m.faultmask[M_REG_NS]) {
538
+ &s->row_mirror, 0, 4 * KiB);
69
+ if (env->v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK) {
539
+ memory_region_add_subregion_overlap(get_system_memory(),
70
+ running = -1;
540
+ s->ram_addr + 1 * MiB,
71
+ } else {
541
+ &s->row_mirror_alias, 10);
72
+ if (env->v7m.aircr & R_V7M_AIRCR_PRIS_MASK) {
542
+ memory_region_set_enabled(&s->row_mirror_alias, false);
73
+ if (running > NVIC_NS_PRIO_LIMIT) {
543
+}
74
+ running = NVIC_NS_PRIO_LIMIT;
544
+
75
+ }
545
+static void allwinner_h3_dramc_init(Object *obj)
76
+ } else {
546
+{
77
+ running = 0;
547
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
78
+ }
548
+ AwH3DramCtlState *s = AW_H3_DRAMC(obj);
79
+ }
549
+
80
+ }
550
+ /* DRAMCOM registers */
81
+
551
+ memory_region_init_io(&s->dramcom_iomem, OBJECT(s),
82
+ if (env->v7m.faultmask[M_REG_S]) {
552
+ &allwinner_h3_dramcom_ops, s,
83
+ running = (env->v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK) ? -3 : -1;
553
+ TYPE_AW_H3_DRAMC, 4 * KiB);
84
+ }
554
+ sysbus_init_mmio(sbd, &s->dramcom_iomem);
85
+
555
+
86
/* consider priority of active handler */
556
+ /* DRAMCTL registers */
87
return MIN(running, s->exception_prio);
557
+ memory_region_init_io(&s->dramctl_iomem, OBJECT(s),
88
}
558
+ &allwinner_h3_dramctl_ops, s,
559
+ TYPE_AW_H3_DRAMC, 4 * KiB);
560
+ sysbus_init_mmio(sbd, &s->dramctl_iomem);
561
+
562
+ /* DRAMPHY registers */
563
+ memory_region_init_io(&s->dramphy_iomem, OBJECT(s),
564
+ &allwinner_h3_dramphy_ops, s,
565
+ TYPE_AW_H3_DRAMC, 4 * KiB);
566
+ sysbus_init_mmio(sbd, &s->dramphy_iomem);
567
+}
568
+
569
+static Property allwinner_h3_dramc_properties[] = {
570
+ DEFINE_PROP_UINT64("ram-addr", AwH3DramCtlState, ram_addr, 0x0),
571
+ DEFINE_PROP_UINT32("ram-size", AwH3DramCtlState, ram_size, 256 * MiB),
572
+ DEFINE_PROP_END_OF_LIST()
573
+};
574
+
575
+static const VMStateDescription allwinner_h3_dramc_vmstate = {
576
+ .name = "allwinner-h3-dramc",
577
+ .version_id = 1,
578
+ .minimum_version_id = 1,
579
+ .fields = (VMStateField[]) {
580
+ VMSTATE_UINT32_ARRAY(dramcom, AwH3DramCtlState, AW_H3_DRAMCOM_REGS_NUM),
581
+ VMSTATE_UINT32_ARRAY(dramctl, AwH3DramCtlState, AW_H3_DRAMCTL_REGS_NUM),
582
+ VMSTATE_UINT32_ARRAY(dramphy, AwH3DramCtlState, AW_H3_DRAMPHY_REGS_NUM),
583
+ VMSTATE_END_OF_LIST()
584
+ }
585
+};
586
+
587
+static void allwinner_h3_dramc_class_init(ObjectClass *klass, void *data)
588
+{
589
+ DeviceClass *dc = DEVICE_CLASS(klass);
590
+
591
+ dc->reset = allwinner_h3_dramc_reset;
592
+ dc->vmsd = &allwinner_h3_dramc_vmstate;
593
+ dc->realize = allwinner_h3_dramc_realize;
594
+ device_class_set_props(dc, allwinner_h3_dramc_properties);
595
+}
596
+
597
+static const TypeInfo allwinner_h3_dramc_info = {
598
+ .name = TYPE_AW_H3_DRAMC,
599
+ .parent = TYPE_SYS_BUS_DEVICE,
600
+ .instance_init = allwinner_h3_dramc_init,
601
+ .instance_size = sizeof(AwH3DramCtlState),
602
+ .class_init = allwinner_h3_dramc_class_init,
603
+};
604
+
605
+static void allwinner_h3_dramc_register(void)
606
+{
607
+ type_register_static(&allwinner_h3_dramc_info);
608
+}
609
+
610
+type_init(allwinner_h3_dramc_register)
611
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
612
index XXXXXXX..XXXXXXX 100644
613
--- a/hw/misc/trace-events
614
+++ b/hw/misc/trace-events
615
@@ -XXX,XX +XXX,XX @@ allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t reset_addr) "id %u, reset_ad
616
allwinner_cpucfg_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
617
allwinner_cpucfg_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
618
619
+# allwinner-h3-dramc.c
620
+allwinner_h3_dramc_rowmirror_disable(void) "Disable row mirror"
621
+allwinner_h3_dramc_rowmirror_enable(uint64_t addr) "Enable row mirror: addr 0x%" PRIx64
622
+allwinner_h3_dramcom_read(uint64_t offset, uint64_t data, unsigned size) "Read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
623
+allwinner_h3_dramcom_write(uint64_t offset, uint64_t data, unsigned size) "Write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
624
+allwinner_h3_dramctl_read(uint64_t offset, uint64_t data, unsigned size) "Read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
625
+allwinner_h3_dramctl_write(uint64_t offset, uint64_t data, unsigned size) "Write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
626
+allwinner_h3_dramphy_read(uint64_t offset, uint64_t data, unsigned size) "Read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
627
+allwinner_h3_dramphy_write(uint64_t offset, uint64_t data, unsigned size) "write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
628
+
629
# allwinner-sid.c
630
allwinner_sid_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
631
allwinner_sid_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
89
--
632
--
90
2.7.4
633
2.20.1
91
634
92
635
diff view generated by jsdifflib
1
From: Subbaraya Sundeep <sundeep.lkml@gmail.com>
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
2
2
3
Modelled System Timer in Microsemi's Smartfusion2 Soc.
3
Allwinner System-on-Chips usually contain a Real Time Clock (RTC)
4
Timer has two 32bit down counters and two interrupts.
4
for non-volatile system date and time keeping. This commit adds a generic
5
Allwinner RTC device that supports the RTC devices found in Allwinner SoC
6
family sun4i (A10), sun7i (A20) and sun6i and newer (A31, H2+, H3, etc).
7
The following RTC functionality and features are implemented:
5
8
6
Signed-off-by: Subbaraya Sundeep <sundeep.lkml@gmail.com>
9
* Year-Month-Day read/write
7
Reviewed-by: Alistair Francis <alistair.francis@xilinx.com>
10
* Hour-Minute-Second read/write
8
Acked-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
11
* General Purpose storage
9
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
12
10
Message-id: 20170920201737.25723-2-f4bug@amsat.org
13
The following boards are extended with the RTC device:
14
15
* Cubieboard (hw/arm/cubieboard.c)
16
* Orange Pi PC (hw/arm/orangepi.c)
17
18
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
19
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
20
Message-id: 20200311221854.30370-13-nieklinnenbank@gmail.com
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
21
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
22
---
13
hw/timer/Makefile.objs | 1 +
23
hw/rtc/Makefile.objs | 1 +
14
include/hw/timer/mss-timer.h | 64 ++++++++++
24
include/hw/arm/allwinner-a10.h | 2 +
15
hw/timer/mss-timer.c | 289 +++++++++++++++++++++++++++++++++++++++++++
25
include/hw/arm/allwinner-h3.h | 3 +
16
3 files changed, 354 insertions(+)
26
include/hw/rtc/allwinner-rtc.h | 134 +++++++++++
17
create mode 100644 include/hw/timer/mss-timer.h
27
hw/arm/allwinner-a10.c | 8 +
18
create mode 100644 hw/timer/mss-timer.c
28
hw/arm/allwinner-h3.c | 9 +-
29
hw/rtc/allwinner-rtc.c | 411 +++++++++++++++++++++++++++++++++
30
hw/rtc/trace-events | 4 +
31
8 files changed, 571 insertions(+), 1 deletion(-)
32
create mode 100644 include/hw/rtc/allwinner-rtc.h
33
create mode 100644 hw/rtc/allwinner-rtc.c
19
34
20
diff --git a/hw/timer/Makefile.objs b/hw/timer/Makefile.objs
35
diff --git a/hw/rtc/Makefile.objs b/hw/rtc/Makefile.objs
21
index XXXXXXX..XXXXXXX 100644
36
index XXXXXXX..XXXXXXX 100644
22
--- a/hw/timer/Makefile.objs
37
--- a/hw/rtc/Makefile.objs
23
+++ b/hw/timer/Makefile.objs
38
+++ b/hw/rtc/Makefile.objs
24
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_ASPEED_SOC) += aspeed_timer.o
39
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_MC146818RTC) += mc146818rtc.o
25
26
common-obj-$(CONFIG_SUN4V_RTC) += sun4v-rtc.o
40
common-obj-$(CONFIG_SUN4V_RTC) += sun4v-rtc.o
27
common-obj-$(CONFIG_CMSDK_APB_TIMER) += cmsdk-apb-timer.o
41
common-obj-$(CONFIG_ASPEED_SOC) += aspeed_rtc.o
28
+common-obj-$(CONFIG_MSF2) += mss-timer.o
42
common-obj-$(CONFIG_GOLDFISH_RTC) += goldfish_rtc.o
29
diff --git a/include/hw/timer/mss-timer.h b/include/hw/timer/mss-timer.h
43
+common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-rtc.o
44
diff --git a/include/hw/arm/allwinner-a10.h b/include/hw/arm/allwinner-a10.h
45
index XXXXXXX..XXXXXXX 100644
46
--- a/include/hw/arm/allwinner-a10.h
47
+++ b/include/hw/arm/allwinner-a10.h
48
@@ -XXX,XX +XXX,XX @@
49
#include "hw/ide/ahci.h"
50
#include "hw/usb/hcd-ohci.h"
51
#include "hw/usb/hcd-ehci.h"
52
+#include "hw/rtc/allwinner-rtc.h"
53
54
#include "target/arm/cpu.h"
55
56
@@ -XXX,XX +XXX,XX @@ typedef struct AwA10State {
57
AwEmacState emac;
58
AllwinnerAHCIState sata;
59
AwSdHostState mmc0;
60
+ AwRtcState rtc;
61
MemoryRegion sram_a;
62
EHCISysBusState ehci[AW_A10_NUM_USB];
63
OHCISysBusState ohci[AW_A10_NUM_USB];
64
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
65
index XXXXXXX..XXXXXXX 100644
66
--- a/include/hw/arm/allwinner-h3.h
67
+++ b/include/hw/arm/allwinner-h3.h
68
@@ -XXX,XX +XXX,XX @@
69
#include "hw/misc/allwinner-sid.h"
70
#include "hw/sd/allwinner-sdhost.h"
71
#include "hw/net/allwinner-sun8i-emac.h"
72
+#include "hw/rtc/allwinner-rtc.h"
73
#include "target/arm/cpu.h"
74
#include "sysemu/block-backend.h"
75
76
@@ -XXX,XX +XXX,XX @@ enum {
77
AW_H3_GIC_CPU,
78
AW_H3_GIC_HYP,
79
AW_H3_GIC_VCPU,
80
+ AW_H3_RTC,
81
AW_H3_CPUCFG,
82
AW_H3_SDRAM
83
};
84
@@ -XXX,XX +XXX,XX @@ typedef struct AwH3State {
85
AwSidState sid;
86
AwSdHostState mmc0;
87
AwSun8iEmacState emac;
88
+ AwRtcState rtc;
89
GICState gic;
90
MemoryRegion sram_a1;
91
MemoryRegion sram_a2;
92
diff --git a/include/hw/rtc/allwinner-rtc.h b/include/hw/rtc/allwinner-rtc.h
30
new file mode 100644
93
new file mode 100644
31
index XXXXXXX..XXXXXXX
94
index XXXXXXX..XXXXXXX
32
--- /dev/null
95
--- /dev/null
33
+++ b/include/hw/timer/mss-timer.h
96
+++ b/include/hw/rtc/allwinner-rtc.h
34
@@ -XXX,XX +XXX,XX @@
97
@@ -XXX,XX +XXX,XX @@
35
+/*
98
+/*
36
+ * Microsemi SmartFusion2 Timer.
99
+ * Allwinner Real Time Clock emulation
37
+ *
100
+ *
38
+ * Copyright (c) 2017 Subbaraya Sundeep <sundeep.lkml@gmail.com>
101
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
39
+ *
102
+ *
40
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
103
+ * This program is free software: you can redistribute it and/or modify
41
+ * of this software and associated documentation files (the "Software"), to deal
104
+ * it under the terms of the GNU General Public License as published by
42
+ * in the Software without restriction, including without limitation the rights
105
+ * the Free Software Foundation, either version 2 of the License, or
43
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
106
+ * (at your option) any later version.
44
+ * copies of the Software, and to permit persons to whom the Software is
107
+ *
45
+ * furnished to do so, subject to the following conditions:
108
+ * This program is distributed in the hope that it will be useful,
46
+ *
109
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
47
+ * The above copyright notice and this permission notice shall be included in
110
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48
+ * all copies or substantial portions of the Software.
111
+ * GNU General Public License for more details.
49
+ *
112
+ *
50
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
113
+ * You should have received a copy of the GNU General Public License
51
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
114
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
52
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
53
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
54
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
55
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
56
+ * THE SOFTWARE.
57
+ */
115
+ */
58
+
116
+
59
+#ifndef HW_MSS_TIMER_H
117
+#ifndef HW_MISC_ALLWINNER_RTC_H
60
+#define HW_MSS_TIMER_H
118
+#define HW_MISC_ALLWINNER_RTC_H
61
+
119
+
120
+#include "qom/object.h"
62
+#include "hw/sysbus.h"
121
+#include "hw/sysbus.h"
63
+#include "hw/ptimer.h"
122
+
64
+
123
+/**
65
+#define TYPE_MSS_TIMER "mss-timer"
124
+ * Constants
66
+#define MSS_TIMER(obj) OBJECT_CHECK(MSSTimerState, \
125
+ * @{
67
+ (obj), TYPE_MSS_TIMER)
68
+
69
+/*
70
+ * There are two 32-bit down counting timers.
71
+ * Timers 1 and 2 can be concatenated into a single 64-bit Timer
72
+ * that operates either in Periodic mode or in One-shot mode.
73
+ * Writing 1 to the TIM64_MODE register bit 0 sets the Timers in 64-bit mode.
74
+ * In 64-bit mode, writing to the 32-bit registers has no effect.
75
+ * Similarly, in 32-bit mode, writing to the 64-bit mode registers
76
+ * has no effect. Only two 32-bit timers are supported currently.
77
+ */
126
+ */
78
+#define NUM_TIMERS 2
127
+
79
+
128
+/** Highest register address used by RTC device */
80
+#define R_TIM1_MAX 6
129
+#define AW_RTC_REGS_MAXADDR (0x200)
81
+
130
+
82
+struct Msf2Timer {
131
+/** Total number of known registers */
83
+ QEMUBH *bh;
132
+#define AW_RTC_REGS_NUM (AW_RTC_REGS_MAXADDR / sizeof(uint32_t))
84
+ ptimer_state *ptimer;
133
+
85
+
134
+/** @} */
86
+ uint32_t regs[R_TIM1_MAX];
135
+
87
+ qemu_irq irq;
136
+/**
88
+};
137
+ * Object model types
89
+
138
+ * @{
90
+typedef struct MSSTimerState {
139
+ */
140
+
141
+/** Generic Allwinner RTC device (abstract) */
142
+#define TYPE_AW_RTC "allwinner-rtc"
143
+
144
+/** Allwinner RTC sun4i family (A10, A12) */
145
+#define TYPE_AW_RTC_SUN4I TYPE_AW_RTC "-sun4i"
146
+
147
+/** Allwinner RTC sun6i family and newer (A31, H2+, H3, etc) */
148
+#define TYPE_AW_RTC_SUN6I TYPE_AW_RTC "-sun6i"
149
+
150
+/** Allwinner RTC sun7i family (A20) */
151
+#define TYPE_AW_RTC_SUN7I TYPE_AW_RTC "-sun7i"
152
+
153
+/** @} */
154
+
155
+/**
156
+ * Object model macros
157
+ * @{
158
+ */
159
+
160
+#define AW_RTC(obj) \
161
+ OBJECT_CHECK(AwRtcState, (obj), TYPE_AW_RTC)
162
+#define AW_RTC_CLASS(klass) \
163
+ OBJECT_CLASS_CHECK(AwRtcClass, (klass), TYPE_AW_RTC)
164
+#define AW_RTC_GET_CLASS(obj) \
165
+ OBJECT_GET_CLASS(AwRtcClass, (obj), TYPE_AW_RTC)
166
+
167
+/** @} */
168
+
169
+/**
170
+ * Allwinner RTC per-object instance state.
171
+ */
172
+typedef struct AwRtcState {
173
+ /*< private >*/
91
+ SysBusDevice parent_obj;
174
+ SysBusDevice parent_obj;
92
+
175
+ /*< public >*/
93
+ MemoryRegion mmio;
176
+
94
+ uint32_t freq_hz;
177
+ /**
95
+ struct Msf2Timer timers[NUM_TIMERS];
178
+ * Actual year represented by the device when year counter is zero
96
+} MSSTimerState;
179
+ *
97
+
180
+ * Can be overridden by the user using the corresponding 'base-year'
98
+#endif /* HW_MSS_TIMER_H */
181
+ * property. The base year used by the target OS driver can vary, for
99
diff --git a/hw/timer/mss-timer.c b/hw/timer/mss-timer.c
182
+ * example the Linux driver for sun6i uses 1970 while NetBSD uses 2000.
183
+ */
184
+ int base_year;
185
+
186
+ /** Maps I/O registers in physical memory */
187
+ MemoryRegion iomem;
188
+
189
+ /** Array of hardware registers */
190
+ uint32_t regs[AW_RTC_REGS_NUM];
191
+
192
+} AwRtcState;
193
+
194
+/**
195
+ * Allwinner RTC class-level struct.
196
+ *
197
+ * This struct is filled by each sunxi device specific code
198
+ * such that the generic code can use this struct to support
199
+ * all devices.
200
+ */
201
+typedef struct AwRtcClass {
202
+ /*< private >*/
203
+ SysBusDeviceClass parent_class;
204
+ /*< public >*/
205
+
206
+ /** Defines device specific register map */
207
+ const uint8_t *regmap;
208
+
209
+ /** Size of the regmap in bytes */
210
+ size_t regmap_size;
211
+
212
+ /**
213
+ * Read device specific register
214
+ *
215
+ * @offset: register offset to read
216
+ * @return true if register read successful, false otherwise
217
+ */
218
+ bool (*read)(AwRtcState *s, uint32_t offset);
219
+
220
+ /**
221
+ * Write device specific register
222
+ *
223
+ * @offset: register offset to write
224
+ * @data: value to set in register
225
+ * @return true if register write successful, false otherwise
226
+ */
227
+ bool (*write)(AwRtcState *s, uint32_t offset, uint32_t data);
228
+
229
+} AwRtcClass;
230
+
231
+#endif /* HW_MISC_ALLWINNER_RTC_H */
232
diff --git a/hw/arm/allwinner-a10.c b/hw/arm/allwinner-a10.c
233
index XXXXXXX..XXXXXXX 100644
234
--- a/hw/arm/allwinner-a10.c
235
+++ b/hw/arm/allwinner-a10.c
236
@@ -XXX,XX +XXX,XX @@
237
#define AW_A10_EHCI_BASE 0x01c14000
238
#define AW_A10_OHCI_BASE 0x01c14400
239
#define AW_A10_SATA_BASE 0x01c18000
240
+#define AW_A10_RTC_BASE 0x01c20d00
241
242
static void aw_a10_init(Object *obj)
243
{
244
@@ -XXX,XX +XXX,XX @@ static void aw_a10_init(Object *obj)
245
246
sysbus_init_child_obj(obj, "mmc0", &s->mmc0, sizeof(s->mmc0),
247
TYPE_AW_SDHOST_SUN4I);
248
+
249
+ sysbus_init_child_obj(obj, "rtc", &s->rtc, sizeof(s->rtc),
250
+ TYPE_AW_RTC_SUN4I);
251
}
252
253
static void aw_a10_realize(DeviceState *dev, Error **errp)
254
@@ -XXX,XX +XXX,XX @@ static void aw_a10_realize(DeviceState *dev, Error **errp)
255
sysbus_connect_irq(SYS_BUS_DEVICE(&s->mmc0), 0, qdev_get_gpio_in(dev, 32));
256
object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->mmc0),
257
"sd-bus", &error_abort);
258
+
259
+ /* RTC */
260
+ qdev_init_nofail(DEVICE(&s->rtc));
261
+ sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->rtc), 0, AW_A10_RTC_BASE, 10);
262
}
263
264
static void aw_a10_class_init(ObjectClass *oc, void *data)
265
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
266
index XXXXXXX..XXXXXXX 100644
267
--- a/hw/arm/allwinner-h3.c
268
+++ b/hw/arm/allwinner-h3.c
269
@@ -XXX,XX +XXX,XX @@ const hwaddr allwinner_h3_memmap[] = {
270
[AW_H3_GIC_CPU] = 0x01c82000,
271
[AW_H3_GIC_HYP] = 0x01c84000,
272
[AW_H3_GIC_VCPU] = 0x01c86000,
273
+ [AW_H3_RTC] = 0x01f00000,
274
[AW_H3_CPUCFG] = 0x01f01c00,
275
[AW_H3_SDRAM] = 0x40000000
276
};
277
@@ -XXX,XX +XXX,XX @@ struct AwH3Unimplemented {
278
{ "csi", 0x01cb0000, 320 * KiB },
279
{ "tve", 0x01e00000, 64 * KiB },
280
{ "hdmi", 0x01ee0000, 128 * KiB },
281
- { "rtc", 0x01f00000, 1 * KiB },
282
{ "r_timer", 0x01f00800, 1 * KiB },
283
{ "r_intc", 0x01f00c00, 1 * KiB },
284
{ "r_wdog", 0x01f01000, 1 * KiB },
285
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_init(Object *obj)
286
"ram-addr", &error_abort);
287
object_property_add_alias(obj, "ram-size", OBJECT(&s->dramc),
288
"ram-size", &error_abort);
289
+
290
+ sysbus_init_child_obj(obj, "rtc", &s->rtc, sizeof(s->rtc),
291
+ TYPE_AW_RTC_SUN6I);
292
}
293
294
static void allwinner_h3_realize(DeviceState *dev, Error **errp)
295
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
296
sysbus_mmio_map(SYS_BUS_DEVICE(&s->dramc), 1, s->memmap[AW_H3_DRAMCTL]);
297
sysbus_mmio_map(SYS_BUS_DEVICE(&s->dramc), 2, s->memmap[AW_H3_DRAMPHY]);
298
299
+ /* RTC */
300
+ qdev_init_nofail(DEVICE(&s->rtc));
301
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->rtc), 0, s->memmap[AW_H3_RTC]);
302
+
303
/* Unimplemented devices */
304
for (i = 0; i < ARRAY_SIZE(unimplemented); i++) {
305
create_unimplemented_device(unimplemented[i].device_name,
306
diff --git a/hw/rtc/allwinner-rtc.c b/hw/rtc/allwinner-rtc.c
100
new file mode 100644
307
new file mode 100644
101
index XXXXXXX..XXXXXXX
308
index XXXXXXX..XXXXXXX
102
--- /dev/null
309
--- /dev/null
103
+++ b/hw/timer/mss-timer.c
310
+++ b/hw/rtc/allwinner-rtc.c
104
@@ -XXX,XX +XXX,XX @@
311
@@ -XXX,XX +XXX,XX @@
105
+/*
312
+/*
106
+ * Block model of System timer present in
313
+ * Allwinner Real Time Clock emulation
107
+ * Microsemi's SmartFusion2 and SmartFusion SoCs.
314
+ *
108
+ *
315
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
109
+ * Copyright (c) 2017 Subbaraya Sundeep <sundeep.lkml@gmail.com>.
316
+ *
110
+ *
317
+ * This program is free software: you can redistribute it and/or modify
111
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
318
+ * it under the terms of the GNU General Public License as published by
112
+ * of this software and associated documentation files (the "Software"), to deal
319
+ * the Free Software Foundation, either version 2 of the License, or
113
+ * in the Software without restriction, including without limitation the rights
320
+ * (at your option) any later version.
114
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
321
+ *
115
+ * copies of the Software, and to permit persons to whom the Software is
322
+ * This program is distributed in the hope that it will be useful,
116
+ * furnished to do so, subject to the following conditions:
323
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
117
+ *
324
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
118
+ * The above copyright notice and this permission notice shall be included in
325
+ * GNU General Public License for more details.
119
+ * all copies or substantial portions of the Software.
326
+ *
120
+ *
327
+ * You should have received a copy of the GNU General Public License
121
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
328
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
122
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
123
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
124
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
125
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
126
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
127
+ * THE SOFTWARE.
128
+ */
329
+ */
129
+
330
+
130
+#include "qemu/osdep.h"
331
+#include "qemu/osdep.h"
131
+#include "qemu/main-loop.h"
332
+#include "qemu/units.h"
333
+#include "hw/sysbus.h"
334
+#include "migration/vmstate.h"
132
+#include "qemu/log.h"
335
+#include "qemu/log.h"
133
+#include "hw/timer/mss-timer.h"
336
+#include "qemu/module.h"
134
+
337
+#include "qemu-common.h"
135
+#ifndef MSS_TIMER_ERR_DEBUG
338
+#include "hw/qdev-properties.h"
136
+#define MSS_TIMER_ERR_DEBUG 0
339
+#include "hw/rtc/allwinner-rtc.h"
137
+#endif
340
+#include "trace.h"
138
+
341
+
139
+#define DB_PRINT_L(lvl, fmt, args...) do { \
342
+/* RTC registers */
140
+ if (MSS_TIMER_ERR_DEBUG >= lvl) { \
343
+enum {
141
+ qemu_log("%s: " fmt "\n", __func__, ## args); \
344
+ REG_LOSC = 1, /* Low Oscillator Control */
142
+ } \
345
+ REG_YYMMDD, /* RTC Year-Month-Day */
143
+} while (0);
346
+ REG_HHMMSS, /* RTC Hour-Minute-Second */
144
+
347
+ REG_ALARM1_WKHHMMSS, /* Alarm1 Week Hour-Minute-Second */
145
+#define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
348
+ REG_ALARM1_EN, /* Alarm1 Enable */
146
+
349
+ REG_ALARM1_IRQ_EN, /* Alarm1 IRQ Enable */
147
+#define R_TIM_VAL 0
350
+ REG_ALARM1_IRQ_STA, /* Alarm1 IRQ Status */
148
+#define R_TIM_LOADVAL 1
351
+ REG_GP0, /* General Purpose Register 0 */
149
+#define R_TIM_BGLOADVAL 2
352
+ REG_GP1, /* General Purpose Register 1 */
150
+#define R_TIM_CTRL 3
353
+ REG_GP2, /* General Purpose Register 2 */
151
+#define R_TIM_RIS 4
354
+ REG_GP3, /* General Purpose Register 3 */
152
+#define R_TIM_MIS 5
355
+
153
+
356
+ /* sun4i registers */
154
+#define TIMER_CTRL_ENBL (1 << 0)
357
+ REG_ALARM1_DDHHMMSS, /* Alarm1 Day Hour-Minute-Second */
155
+#define TIMER_CTRL_ONESHOT (1 << 1)
358
+ REG_CPUCFG, /* CPU Configuration Register */
156
+#define TIMER_CTRL_INTR (1 << 2)
359
+
157
+#define TIMER_RIS_ACK (1 << 0)
360
+ /* sun6i registers */
158
+#define TIMER_RST_CLR (1 << 6)
361
+ REG_LOSC_AUTOSTA, /* LOSC Auto Switch Status */
159
+#define TIMER_MODE (1 << 0)
362
+ REG_INT_OSC_PRE, /* Internal OSC Clock Prescaler */
160
+
363
+ REG_ALARM0_COUNTER, /* Alarm0 Counter */
161
+static void timer_update_irq(struct Msf2Timer *st)
364
+ REG_ALARM0_CUR_VLU, /* Alarm0 Counter Current Value */
162
+{
365
+ REG_ALARM0_ENABLE, /* Alarm0 Enable */
163
+ bool isr, ier;
366
+ REG_ALARM0_IRQ_EN, /* Alarm0 IRQ Enable */
164
+
367
+ REG_ALARM0_IRQ_STA, /* Alarm0 IRQ Status */
165
+ isr = !!(st->regs[R_TIM_RIS] & TIMER_RIS_ACK);
368
+ REG_ALARM_CONFIG, /* Alarm Config */
166
+ ier = !!(st->regs[R_TIM_CTRL] & TIMER_CTRL_INTR);
369
+ REG_LOSC_OUT_GATING, /* LOSC Output Gating Register */
167
+ qemu_set_irq(st->irq, (ier && isr));
370
+ REG_GP4, /* General Purpose Register 4 */
168
+}
371
+ REG_GP5, /* General Purpose Register 5 */
169
+
372
+ REG_GP6, /* General Purpose Register 6 */
170
+static void timer_update(struct Msf2Timer *st)
373
+ REG_GP7, /* General Purpose Register 7 */
171
+{
374
+ REG_RTC_DBG, /* RTC Debug Register */
172
+ uint64_t count;
375
+ REG_GPL_HOLD_OUT, /* GPL Hold Output Register */
173
+
376
+ REG_VDD_RTC, /* VDD RTC Regulate Register */
174
+ if (!(st->regs[R_TIM_CTRL] & TIMER_CTRL_ENBL)) {
377
+ REG_IC_CHARA, /* IC Characteristics Register */
175
+ ptimer_stop(st->ptimer);
378
+};
379
+
380
+/* RTC register flags */
381
+enum {
382
+ REG_LOSC_YMD = (1 << 7),
383
+ REG_LOSC_HMS = (1 << 8),
384
+};
385
+
386
+/* RTC sun4i register map (offset to name) */
387
+const uint8_t allwinner_rtc_sun4i_regmap[] = {
388
+ [0x0000] = REG_LOSC,
389
+ [0x0004] = REG_YYMMDD,
390
+ [0x0008] = REG_HHMMSS,
391
+ [0x000C] = REG_ALARM1_DDHHMMSS,
392
+ [0x0010] = REG_ALARM1_WKHHMMSS,
393
+ [0x0014] = REG_ALARM1_EN,
394
+ [0x0018] = REG_ALARM1_IRQ_EN,
395
+ [0x001C] = REG_ALARM1_IRQ_STA,
396
+ [0x0020] = REG_GP0,
397
+ [0x0024] = REG_GP1,
398
+ [0x0028] = REG_GP2,
399
+ [0x002C] = REG_GP3,
400
+ [0x003C] = REG_CPUCFG,
401
+};
402
+
403
+/* RTC sun6i register map (offset to name) */
404
+const uint8_t allwinner_rtc_sun6i_regmap[] = {
405
+ [0x0000] = REG_LOSC,
406
+ [0x0004] = REG_LOSC_AUTOSTA,
407
+ [0x0008] = REG_INT_OSC_PRE,
408
+ [0x0010] = REG_YYMMDD,
409
+ [0x0014] = REG_HHMMSS,
410
+ [0x0020] = REG_ALARM0_COUNTER,
411
+ [0x0024] = REG_ALARM0_CUR_VLU,
412
+ [0x0028] = REG_ALARM0_ENABLE,
413
+ [0x002C] = REG_ALARM0_IRQ_EN,
414
+ [0x0030] = REG_ALARM0_IRQ_STA,
415
+ [0x0040] = REG_ALARM1_WKHHMMSS,
416
+ [0x0044] = REG_ALARM1_EN,
417
+ [0x0048] = REG_ALARM1_IRQ_EN,
418
+ [0x004C] = REG_ALARM1_IRQ_STA,
419
+ [0x0050] = REG_ALARM_CONFIG,
420
+ [0x0060] = REG_LOSC_OUT_GATING,
421
+ [0x0100] = REG_GP0,
422
+ [0x0104] = REG_GP1,
423
+ [0x0108] = REG_GP2,
424
+ [0x010C] = REG_GP3,
425
+ [0x0110] = REG_GP4,
426
+ [0x0114] = REG_GP5,
427
+ [0x0118] = REG_GP6,
428
+ [0x011C] = REG_GP7,
429
+ [0x0170] = REG_RTC_DBG,
430
+ [0x0180] = REG_GPL_HOLD_OUT,
431
+ [0x0190] = REG_VDD_RTC,
432
+ [0x01F0] = REG_IC_CHARA,
433
+};
434
+
435
+static bool allwinner_rtc_sun4i_read(AwRtcState *s, uint32_t offset)
436
+{
437
+ /* no sun4i specific registers currently implemented */
438
+ return false;
439
+}
440
+
441
+static bool allwinner_rtc_sun4i_write(AwRtcState *s, uint32_t offset,
442
+ uint32_t data)
443
+{
444
+ /* no sun4i specific registers currently implemented */
445
+ return false;
446
+}
447
+
448
+static bool allwinner_rtc_sun6i_read(AwRtcState *s, uint32_t offset)
449
+{
450
+ const AwRtcClass *c = AW_RTC_GET_CLASS(s);
451
+
452
+ switch (c->regmap[offset]) {
453
+ case REG_GP4: /* General Purpose Register 4 */
454
+ case REG_GP5: /* General Purpose Register 5 */
455
+ case REG_GP6: /* General Purpose Register 6 */
456
+ case REG_GP7: /* General Purpose Register 7 */
457
+ return true;
458
+ default:
459
+ break;
460
+ }
461
+ return false;
462
+}
463
+
464
+static bool allwinner_rtc_sun6i_write(AwRtcState *s, uint32_t offset,
465
+ uint32_t data)
466
+{
467
+ const AwRtcClass *c = AW_RTC_GET_CLASS(s);
468
+
469
+ switch (c->regmap[offset]) {
470
+ case REG_GP4: /* General Purpose Register 4 */
471
+ case REG_GP5: /* General Purpose Register 5 */
472
+ case REG_GP6: /* General Purpose Register 6 */
473
+ case REG_GP7: /* General Purpose Register 7 */
474
+ return true;
475
+ default:
476
+ break;
477
+ }
478
+ return false;
479
+}
480
+
481
+static uint64_t allwinner_rtc_read(void *opaque, hwaddr offset,
482
+ unsigned size)
483
+{
484
+ AwRtcState *s = AW_RTC(opaque);
485
+ const AwRtcClass *c = AW_RTC_GET_CLASS(s);
486
+ uint64_t val = 0;
487
+
488
+ if (offset >= c->regmap_size) {
489
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
490
+ __func__, (uint32_t)offset);
491
+ return 0;
492
+ }
493
+
494
+ if (!c->regmap[offset]) {
495
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid register 0x%04x\n",
496
+ __func__, (uint32_t)offset);
497
+ return 0;
498
+ }
499
+
500
+ switch (c->regmap[offset]) {
501
+ case REG_LOSC: /* Low Oscillator Control */
502
+ val = s->regs[REG_LOSC];
503
+ s->regs[REG_LOSC] &= ~(REG_LOSC_YMD | REG_LOSC_HMS);
504
+ break;
505
+ case REG_YYMMDD: /* RTC Year-Month-Day */
506
+ case REG_HHMMSS: /* RTC Hour-Minute-Second */
507
+ case REG_GP0: /* General Purpose Register 0 */
508
+ case REG_GP1: /* General Purpose Register 1 */
509
+ case REG_GP2: /* General Purpose Register 2 */
510
+ case REG_GP3: /* General Purpose Register 3 */
511
+ val = s->regs[c->regmap[offset]];
512
+ break;
513
+ default:
514
+ if (!c->read(s, offset)) {
515
+ qemu_log_mask(LOG_UNIMP, "%s: unimplemented register 0x%04x\n",
516
+ __func__, (uint32_t)offset);
517
+ }
518
+ val = s->regs[c->regmap[offset]];
519
+ break;
520
+ }
521
+
522
+ trace_allwinner_rtc_read(offset, val);
523
+ return val;
524
+}
525
+
526
+static void allwinner_rtc_write(void *opaque, hwaddr offset,
527
+ uint64_t val, unsigned size)
528
+{
529
+ AwRtcState *s = AW_RTC(opaque);
530
+ const AwRtcClass *c = AW_RTC_GET_CLASS(s);
531
+
532
+ if (offset >= c->regmap_size) {
533
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
534
+ __func__, (uint32_t)offset);
176
+ return;
535
+ return;
177
+ }
536
+ }
178
+
537
+
179
+ count = st->regs[R_TIM_LOADVAL];
538
+ if (!c->regmap[offset]) {
180
+ ptimer_set_limit(st->ptimer, count, 1);
539
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid register 0x%04x\n",
181
+ ptimer_run(st->ptimer, 1);
540
+ __func__, (uint32_t)offset);
182
+}
541
+ return;
183
+
542
+ }
184
+static uint64_t
543
+
185
+timer_read(void *opaque, hwaddr offset, unsigned int size)
544
+ trace_allwinner_rtc_write(offset, val);
186
+{
545
+
187
+ MSSTimerState *t = opaque;
546
+ switch (c->regmap[offset]) {
188
+ hwaddr addr;
547
+ case REG_YYMMDD: /* RTC Year-Month-Day */
189
+ struct Msf2Timer *st;
548
+ s->regs[REG_YYMMDD] = val;
190
+ uint32_t ret = 0;
549
+ s->regs[REG_LOSC] |= REG_LOSC_YMD;
191
+ int timer = 0;
550
+ break;
192
+ int isr;
551
+ case REG_HHMMSS: /* RTC Hour-Minute-Second */
193
+ int ier;
552
+ s->regs[REG_HHMMSS] = val;
194
+
553
+ s->regs[REG_LOSC] |= REG_LOSC_HMS;
195
+ addr = offset >> 2;
554
+ break;
196
+ /*
555
+ case REG_GP0: /* General Purpose Register 0 */
197
+ * Two independent timers has same base address.
556
+ case REG_GP1: /* General Purpose Register 1 */
198
+ * Based on address passed figure out which timer is being used.
557
+ case REG_GP2: /* General Purpose Register 2 */
199
+ */
558
+ case REG_GP3: /* General Purpose Register 3 */
200
+ if ((addr >= R_TIM1_MAX) && (addr < NUM_TIMERS * R_TIM1_MAX)) {
559
+ s->regs[c->regmap[offset]] = val;
201
+ timer = 1;
560
+ break;
202
+ addr -= R_TIM1_MAX;
203
+ }
204
+
205
+ st = &t->timers[timer];
206
+
207
+ switch (addr) {
208
+ case R_TIM_VAL:
209
+ ret = ptimer_get_count(st->ptimer);
210
+ break;
211
+
212
+ case R_TIM_MIS:
213
+ isr = !!(st->regs[R_TIM_RIS] & TIMER_RIS_ACK);
214
+ ier = !!(st->regs[R_TIM_CTRL] & TIMER_CTRL_INTR);
215
+ ret = ier & isr;
216
+ break;
217
+
218
+ default:
561
+ default:
219
+ if (addr < R_TIM1_MAX) {
562
+ if (!c->write(s, offset, val)) {
220
+ ret = st->regs[addr];
563
+ qemu_log_mask(LOG_UNIMP, "%s: unimplemented register 0x%04x\n",
221
+ } else {
564
+ __func__, (uint32_t)offset);
222
+ qemu_log_mask(LOG_GUEST_ERROR,
223
+ TYPE_MSS_TIMER": 64-bit mode not supported\n");
224
+ return ret;
225
+ }
565
+ }
226
+ break;
566
+ break;
227
+ }
567
+ }
228
+
568
+}
229
+ DB_PRINT("timer=%d 0x%" HWADDR_PRIx "=0x%" PRIx32, timer, offset,
569
+
230
+ ret);
570
+static const MemoryRegionOps allwinner_rtc_ops = {
231
+ return ret;
571
+ .read = allwinner_rtc_read,
232
+}
572
+ .write = allwinner_rtc_write,
233
+
234
+static void
235
+timer_write(void *opaque, hwaddr offset,
236
+ uint64_t val64, unsigned int size)
237
+{
238
+ MSSTimerState *t = opaque;
239
+ hwaddr addr;
240
+ struct Msf2Timer *st;
241
+ int timer = 0;
242
+ uint32_t value = val64;
243
+
244
+ addr = offset >> 2;
245
+ /*
246
+ * Two independent timers has same base address.
247
+ * Based on addr passed figure out which timer is being used.
248
+ */
249
+ if ((addr >= R_TIM1_MAX) && (addr < NUM_TIMERS * R_TIM1_MAX)) {
250
+ timer = 1;
251
+ addr -= R_TIM1_MAX;
252
+ }
253
+
254
+ st = &t->timers[timer];
255
+
256
+ DB_PRINT("addr=0x%" HWADDR_PRIx " val=0x%" PRIx32 " (timer=%d)", offset,
257
+ value, timer);
258
+
259
+ switch (addr) {
260
+ case R_TIM_CTRL:
261
+ st->regs[R_TIM_CTRL] = value;
262
+ timer_update(st);
263
+ break;
264
+
265
+ case R_TIM_RIS:
266
+ if (value & TIMER_RIS_ACK) {
267
+ st->regs[R_TIM_RIS] &= ~TIMER_RIS_ACK;
268
+ }
269
+ break;
270
+
271
+ case R_TIM_LOADVAL:
272
+ st->regs[R_TIM_LOADVAL] = value;
273
+ if (st->regs[R_TIM_CTRL] & TIMER_CTRL_ENBL) {
274
+ timer_update(st);
275
+ }
276
+ break;
277
+
278
+ case R_TIM_BGLOADVAL:
279
+ st->regs[R_TIM_BGLOADVAL] = value;
280
+ st->regs[R_TIM_LOADVAL] = value;
281
+ break;
282
+
283
+ case R_TIM_VAL:
284
+ case R_TIM_MIS:
285
+ break;
286
+
287
+ default:
288
+ if (addr < R_TIM1_MAX) {
289
+ st->regs[addr] = value;
290
+ } else {
291
+ qemu_log_mask(LOG_GUEST_ERROR,
292
+ TYPE_MSS_TIMER": 64-bit mode not supported\n");
293
+ return;
294
+ }
295
+ break;
296
+ }
297
+ timer_update_irq(st);
298
+}
299
+
300
+static const MemoryRegionOps timer_ops = {
301
+ .read = timer_read,
302
+ .write = timer_write,
303
+ .endianness = DEVICE_NATIVE_ENDIAN,
573
+ .endianness = DEVICE_NATIVE_ENDIAN,
304
+ .valid = {
574
+ .valid = {
305
+ .min_access_size = 1,
575
+ .min_access_size = 4,
306
+ .max_access_size = 4
576
+ .max_access_size = 4,
307
+ }
577
+ },
308
+};
578
+ .impl.min_access_size = 4,
309
+
579
+};
310
+static void timer_hit(void *opaque)
580
+
311
+{
581
+static void allwinner_rtc_reset(DeviceState *dev)
312
+ struct Msf2Timer *st = opaque;
582
+{
313
+
583
+ AwRtcState *s = AW_RTC(dev);
314
+ st->regs[R_TIM_RIS] |= TIMER_RIS_ACK;
584
+ struct tm now;
315
+
585
+
316
+ if (!(st->regs[R_TIM_CTRL] & TIMER_CTRL_ONESHOT)) {
586
+ /* Clear registers */
317
+ timer_update(st);
587
+ memset(s->regs, 0, sizeof(s->regs));
318
+ }
588
+
319
+ timer_update_irq(st);
589
+ /* Get current datetime */
320
+}
590
+ qemu_get_timedate(&now, 0);
321
+
591
+
322
+static void mss_timer_init(Object *obj)
592
+ /* Set RTC with current datetime */
323
+{
593
+ if (s->base_year > 1900) {
324
+ MSSTimerState *t = MSS_TIMER(obj);
594
+ s->regs[REG_YYMMDD] = ((now.tm_year + 1900 - s->base_year) << 16) |
325
+ int i;
595
+ ((now.tm_mon + 1) << 8) |
326
+
596
+ now.tm_mday;
327
+ /* Init all the ptimers. */
597
+ s->regs[REG_HHMMSS] = (((now.tm_wday + 6) % 7) << 29) |
328
+ for (i = 0; i < NUM_TIMERS; i++) {
598
+ (now.tm_hour << 16) |
329
+ struct Msf2Timer *st = &t->timers[i];
599
+ (now.tm_min << 8) |
330
+
600
+ now.tm_sec;
331
+ st->bh = qemu_bh_new(timer_hit, st);
601
+ }
332
+ st->ptimer = ptimer_init(st->bh, PTIMER_POLICY_DEFAULT);
602
+}
333
+ ptimer_set_freq(st->ptimer, t->freq_hz);
603
+
334
+ sysbus_init_irq(SYS_BUS_DEVICE(obj), &st->irq);
604
+static void allwinner_rtc_init(Object *obj)
335
+ }
605
+{
336
+
606
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
337
+ memory_region_init_io(&t->mmio, OBJECT(t), &timer_ops, t, TYPE_MSS_TIMER,
607
+ AwRtcState *s = AW_RTC(obj);
338
+ NUM_TIMERS * R_TIM1_MAX * 4);
608
+
339
+ sysbus_init_mmio(SYS_BUS_DEVICE(obj), &t->mmio);
609
+ /* Memory mapping */
340
+}
610
+ memory_region_init_io(&s->iomem, OBJECT(s), &allwinner_rtc_ops, s,
341
+
611
+ TYPE_AW_RTC, 1 * KiB);
342
+static const VMStateDescription vmstate_timers = {
612
+ sysbus_init_mmio(sbd, &s->iomem);
343
+ .name = "mss-timer-block",
613
+}
614
+
615
+static const VMStateDescription allwinner_rtc_vmstate = {
616
+ .name = "allwinner-rtc",
344
+ .version_id = 1,
617
+ .version_id = 1,
345
+ .minimum_version_id = 1,
618
+ .minimum_version_id = 1,
346
+ .fields = (VMStateField[]) {
619
+ .fields = (VMStateField[]) {
347
+ VMSTATE_PTIMER(ptimer, struct Msf2Timer),
620
+ VMSTATE_UINT32_ARRAY(regs, AwRtcState, AW_RTC_REGS_NUM),
348
+ VMSTATE_UINT32_ARRAY(regs, struct Msf2Timer, R_TIM1_MAX),
349
+ VMSTATE_END_OF_LIST()
621
+ VMSTATE_END_OF_LIST()
350
+ }
622
+ }
351
+};
623
+};
352
+
624
+
353
+static const VMStateDescription vmstate_mss_timer = {
625
+static Property allwinner_rtc_properties[] = {
354
+ .name = TYPE_MSS_TIMER,
626
+ DEFINE_PROP_INT32("base-year", AwRtcState, base_year, 0),
355
+ .version_id = 1,
356
+ .minimum_version_id = 1,
357
+ .fields = (VMStateField[]) {
358
+ VMSTATE_UINT32(freq_hz, MSSTimerState),
359
+ VMSTATE_STRUCT_ARRAY(timers, MSSTimerState, NUM_TIMERS, 0,
360
+ vmstate_timers, struct Msf2Timer),
361
+ VMSTATE_END_OF_LIST()
362
+ }
363
+};
364
+
365
+static Property mss_timer_properties[] = {
366
+ /* Libero GUI shows 100Mhz as default for clocks */
367
+ DEFINE_PROP_UINT32("clock-frequency", MSSTimerState, freq_hz,
368
+ 100 * 1000000),
369
+ DEFINE_PROP_END_OF_LIST(),
627
+ DEFINE_PROP_END_OF_LIST(),
370
+};
628
+};
371
+
629
+
372
+static void mss_timer_class_init(ObjectClass *klass, void *data)
630
+static void allwinner_rtc_class_init(ObjectClass *klass, void *data)
373
+{
631
+{
374
+ DeviceClass *dc = DEVICE_CLASS(klass);
632
+ DeviceClass *dc = DEVICE_CLASS(klass);
375
+
633
+
376
+ dc->props = mss_timer_properties;
634
+ dc->reset = allwinner_rtc_reset;
377
+ dc->vmsd = &vmstate_mss_timer;
635
+ dc->vmsd = &allwinner_rtc_vmstate;
378
+}
636
+ device_class_set_props(dc, allwinner_rtc_properties);
379
+
637
+}
380
+static const TypeInfo mss_timer_info = {
638
+
381
+ .name = TYPE_MSS_TIMER,
639
+static void allwinner_rtc_sun4i_init(Object *obj)
640
+{
641
+ AwRtcState *s = AW_RTC(obj);
642
+ s->base_year = 2010;
643
+}
644
+
645
+static void allwinner_rtc_sun4i_class_init(ObjectClass *klass, void *data)
646
+{
647
+ AwRtcClass *arc = AW_RTC_CLASS(klass);
648
+
649
+ arc->regmap = allwinner_rtc_sun4i_regmap;
650
+ arc->regmap_size = sizeof(allwinner_rtc_sun4i_regmap);
651
+ arc->read = allwinner_rtc_sun4i_read;
652
+ arc->write = allwinner_rtc_sun4i_write;
653
+}
654
+
655
+static void allwinner_rtc_sun6i_init(Object *obj)
656
+{
657
+ AwRtcState *s = AW_RTC(obj);
658
+ s->base_year = 1970;
659
+}
660
+
661
+static void allwinner_rtc_sun6i_class_init(ObjectClass *klass, void *data)
662
+{
663
+ AwRtcClass *arc = AW_RTC_CLASS(klass);
664
+
665
+ arc->regmap = allwinner_rtc_sun6i_regmap;
666
+ arc->regmap_size = sizeof(allwinner_rtc_sun6i_regmap);
667
+ arc->read = allwinner_rtc_sun6i_read;
668
+ arc->write = allwinner_rtc_sun6i_write;
669
+}
670
+
671
+static void allwinner_rtc_sun7i_init(Object *obj)
672
+{
673
+ AwRtcState *s = AW_RTC(obj);
674
+ s->base_year = 1970;
675
+}
676
+
677
+static void allwinner_rtc_sun7i_class_init(ObjectClass *klass, void *data)
678
+{
679
+ AwRtcClass *arc = AW_RTC_CLASS(klass);
680
+ allwinner_rtc_sun4i_class_init(klass, arc);
681
+}
682
+
683
+static const TypeInfo allwinner_rtc_info = {
684
+ .name = TYPE_AW_RTC,
382
+ .parent = TYPE_SYS_BUS_DEVICE,
685
+ .parent = TYPE_SYS_BUS_DEVICE,
383
+ .instance_size = sizeof(MSSTimerState),
686
+ .instance_init = allwinner_rtc_init,
384
+ .instance_init = mss_timer_init,
687
+ .instance_size = sizeof(AwRtcState),
385
+ .class_init = mss_timer_class_init,
688
+ .class_init = allwinner_rtc_class_init,
386
+};
689
+ .class_size = sizeof(AwRtcClass),
387
+
690
+ .abstract = true,
388
+static void mss_timer_register_types(void)
691
+};
389
+{
692
+
390
+ type_register_static(&mss_timer_info);
693
+static const TypeInfo allwinner_rtc_sun4i_info = {
391
+}
694
+ .name = TYPE_AW_RTC_SUN4I,
392
+
695
+ .parent = TYPE_AW_RTC,
393
+type_init(mss_timer_register_types)
696
+ .class_init = allwinner_rtc_sun4i_class_init,
697
+ .instance_init = allwinner_rtc_sun4i_init,
698
+};
699
+
700
+static const TypeInfo allwinner_rtc_sun6i_info = {
701
+ .name = TYPE_AW_RTC_SUN6I,
702
+ .parent = TYPE_AW_RTC,
703
+ .class_init = allwinner_rtc_sun6i_class_init,
704
+ .instance_init = allwinner_rtc_sun6i_init,
705
+};
706
+
707
+static const TypeInfo allwinner_rtc_sun7i_info = {
708
+ .name = TYPE_AW_RTC_SUN7I,
709
+ .parent = TYPE_AW_RTC,
710
+ .class_init = allwinner_rtc_sun7i_class_init,
711
+ .instance_init = allwinner_rtc_sun7i_init,
712
+};
713
+
714
+static void allwinner_rtc_register(void)
715
+{
716
+ type_register_static(&allwinner_rtc_info);
717
+ type_register_static(&allwinner_rtc_sun4i_info);
718
+ type_register_static(&allwinner_rtc_sun6i_info);
719
+ type_register_static(&allwinner_rtc_sun7i_info);
720
+}
721
+
722
+type_init(allwinner_rtc_register)
723
diff --git a/hw/rtc/trace-events b/hw/rtc/trace-events
724
index XXXXXXX..XXXXXXX 100644
725
--- a/hw/rtc/trace-events
726
+++ b/hw/rtc/trace-events
727
@@ -XXX,XX +XXX,XX @@
728
# See docs/devel/tracing.txt for syntax documentation.
729
730
+# allwinner-rtc.c
731
+allwinner_rtc_read(uint64_t addr, uint64_t value) "addr 0x%" PRIx64 " value 0x%" PRIx64
732
+allwinner_rtc_write(uint64_t addr, uint64_t value) "addr 0x%" PRIx64 " value 0x%" PRIx64
733
+
734
# sun4v-rtc.c
735
sun4v_rtc_read(uint64_t addr, uint64_t value) "read: addr 0x%" PRIx64 " value 0x%" PRIx64
736
sun4v_rtc_write(uint64_t addr, uint64_t value) "write: addr 0x%" PRIx64 " value 0x%" PRIx64
394
--
737
--
395
2.7.4
738
2.20.1
396
739
397
740
diff view generated by jsdifflib
1
The ICSR NVIC register is banked for v8M. This doesn't
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
require any new state, but it does mean that some bits
3
are controlled by BFHNFNMINS and some bits must work
4
with the correct banked exception. There is also a new
5
in v8M PENDNMICLR bit.
6
2
3
This test boots a Linux kernel on a OrangePi PC board and verify
4
the serial output is working.
5
6
The kernel image and DeviceTree blob are built by the Armbian
7
project (based on Debian):
8
https://www.armbian.com/orange-pi-pc/
9
10
If ARM is a target being built, "make check-acceptance" will
11
automatically include this test by the use of the "arch:arm" tags.
12
13
Alternatively, this test can be run using:
14
15
$ make check-venv
16
$ ./tests/venv/bin/avocado --show=console,app run -t machine:orangepi-pc tests/acceptance/boot_linux_console.py
17
JOB ID : 2e4d15eceb13c33672af406f08171e6e9de1414a
18
JOB LOG : ~/job-results/job-2019-12-17T05.46-2e4d15e/job.log
19
(1/1) tests/acceptance/boot_linux_console.py:BootLinuxConsole.test_arm_orangepi:
20
console: Uncompressing Linux... done, booting the kernel.
21
console: Booting Linux on physical CPU 0x0
22
console: Linux version 4.20.7-sunxi (root@armbian.com) (gcc version 7.2.1 20171011 (Linaro GCC 7.2-2017.11)) #5.75 SMP Fri Feb 8 09:02:10 CET 2019
23
console: CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=50c5387d
24
console: CPU: div instructions available: patching division code
25
console: CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
26
console: OF: fdt: Machine model: Xunlong Orange Pi PC
27
console: Memory policy: Data cache writealloc
28
console: OF: reserved mem: failed to allocate memory for node 'cma@4a000000'
29
console: cma: Failed to reserve 128 MiB
30
console: psci: probing for conduit method from DT.
31
console: psci: PSCIv0.2 detected in firmware.
32
console: psci: Using standard PSCI v0.2 function IDs
33
console: psci: Trusted OS migration not required
34
console: random: get_random_bytes called from start_kernel+0x8d/0x3c2 with crng_init=0
35
console: percpu: Embedded 18 pages/cpu @(ptrval) s41228 r8192 d24308 u73728
36
console: Built 1 zonelists, mobility grouping on. Total pages: 32480
37
console: Kernel command line: printk.time=0 console=ttyS0,115200
38
PASS (8.59 s)
39
JOB TIME : 8.81 s
40
41
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
42
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
43
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
44
Tested-by: Alex Bennée <alex.bennee@linaro.org>
45
Message-id: 20200311221854.30370-14-nieklinnenbank@gmail.com
46
[NL: rename in commit message Raspbian to Armbian, remove vm.set_machine()]
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
47
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Message-id: 1505240046-11454-18-git-send-email-peter.maydell@linaro.org
10
---
48
---
11
hw/intc/armv7m_nvic.c | 45 ++++++++++++++++++++++++++++++++-------------
49
tests/acceptance/boot_linux_console.py | 25 +++++++++++++++++++++++++
12
1 file changed, 32 insertions(+), 13 deletions(-)
50
1 file changed, 25 insertions(+)
13
51
14
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
52
diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
15
index XXXXXXX..XXXXXXX 100644
53
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/intc/armv7m_nvic.c
54
--- a/tests/acceptance/boot_linux_console.py
17
+++ b/hw/intc/armv7m_nvic.c
55
+++ b/tests/acceptance/boot_linux_console.py
18
@@ -XXX,XX +XXX,XX @@ static uint32_t nvic_readl(NVICState *s, uint32_t offset, MemTxAttrs attrs)
56
@@ -XXX,XX +XXX,XX @@ class BootLinuxConsole(Test):
19
}
57
exec_command_and_wait_for_pattern(self, 'reboot',
20
case 0xd00: /* CPUID Base. */
58
'reboot: Restarting system')
21
return cpu->midr;
59
22
- case 0xd04: /* Interrupt Control State. */
60
+ def test_arm_orangepi(self):
23
+ case 0xd04: /* Interrupt Control State (ICSR) */
61
+ """
24
/* VECTACTIVE */
62
+ :avocado: tags=arch:arm
25
val = cpu->env.v7m.exception;
63
+ :avocado: tags=machine:orangepi-pc
26
/* VECTPENDING */
64
+ """
27
@@ -XXX,XX +XXX,XX @@ static uint32_t nvic_readl(NVICState *s, uint32_t offset, MemTxAttrs attrs)
65
+ deb_url = ('https://apt.armbian.com/pool/main/l/'
28
if (nvic_rettobase(s)) {
66
+ 'linux-4.20.7-sunxi/linux-image-dev-sunxi_5.75_armhf.deb')
29
val |= (1 << 11);
67
+ deb_hash = '1334c29c44d984ffa05ed10de8c3361f33d78315'
30
}
68
+ deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
31
- /* PENDSTSET */
69
+ kernel_path = self.extract_from_deb(deb_path,
32
- if (s->vectors[ARMV7M_EXCP_SYSTICK].pending) {
70
+ '/boot/vmlinuz-4.20.7-sunxi')
33
- val |= (1 << 26);
71
+ dtb_path = '/usr/lib/linux-image-dev-sunxi/sun8i-h3-orangepi-pc.dtb'
34
- }
72
+ dtb_path = self.extract_from_deb(deb_path, dtb_path)
35
- /* PENDSVSET */
73
+
36
- if (s->vectors[ARMV7M_EXCP_PENDSV].pending) {
74
+ self.vm.set_console()
37
- val |= (1 << 28);
75
+ kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
38
+ if (attrs.secure) {
76
+ 'console=ttyS0,115200n8 '
39
+ /* PENDSTSET */
77
+ 'earlycon=uart,mmio32,0x1c28000')
40
+ if (s->sec_vectors[ARMV7M_EXCP_SYSTICK].pending) {
78
+ self.vm.add_args('-kernel', kernel_path,
41
+ val |= (1 << 26);
79
+ '-dtb', dtb_path,
42
+ }
80
+ '-append', kernel_command_line)
43
+ /* PENDSVSET */
81
+ self.vm.launch()
44
+ if (s->sec_vectors[ARMV7M_EXCP_PENDSV].pending) {
82
+ console_pattern = 'Kernel command line: %s' % kernel_command_line
45
+ val |= (1 << 28);
83
+ self.wait_for_console_pattern(console_pattern)
46
+ }
84
+
47
+ } else {
85
def test_s390x_s390_ccw_virtio(self):
48
+ /* PENDSTSET */
86
"""
49
+ if (s->vectors[ARMV7M_EXCP_SYSTICK].pending) {
87
:avocado: tags=arch:s390x
50
+ val |= (1 << 26);
51
+ }
52
+ /* PENDSVSET */
53
+ if (s->vectors[ARMV7M_EXCP_PENDSV].pending) {
54
+ val |= (1 << 28);
55
+ }
56
}
57
/* NMIPENDSET */
58
- if (s->vectors[ARMV7M_EXCP_NMI].pending) {
59
+ if ((cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK) &&
60
+ s->vectors[ARMV7M_EXCP_NMI].pending) {
61
val |= (1 << 31);
62
}
63
- /* ISRPREEMPT not implemented */
64
+ /* ISRPREEMPT: RES0 when halting debug not implemented */
65
+ /* STTNS: RES0 for the Main Extension */
66
return val;
67
case 0xd08: /* Vector Table Offset. */
68
return cpu->env.v7m.vecbase[attrs.secure];
69
@@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value,
70
nvic_irq_update(s);
71
break;
72
}
73
- case 0xd04: /* Interrupt Control State. */
74
- if (value & (1 << 31)) {
75
- armv7m_nvic_set_pending(s, ARMV7M_EXCP_NMI, false);
76
+ case 0xd04: /* Interrupt Control State (ICSR) */
77
+ if (cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK) {
78
+ if (value & (1 << 31)) {
79
+ armv7m_nvic_set_pending(s, ARMV7M_EXCP_NMI, false);
80
+ } else if (value & (1 << 30) &&
81
+ arm_feature(&cpu->env, ARM_FEATURE_V8)) {
82
+ /* PENDNMICLR didn't exist in v7M */
83
+ armv7m_nvic_clear_pending(s, ARMV7M_EXCP_NMI, false);
84
+ }
85
}
86
if (value & (1 << 28)) {
87
armv7m_nvic_set_pending(s, ARMV7M_EXCP_PENDSV, attrs.secure);
88
--
88
--
89
2.7.4
89
2.20.1
90
90
91
91
diff view generated by jsdifflib
New patch
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
2
3
This test boots a Linux kernel on a OrangePi PC board and verify
4
the serial output is working.
5
6
The kernel image and DeviceTree blob are built by the Armbian
7
project (based on Debian):
8
https://www.armbian.com/orange-pi-pc/
9
10
The cpio image used comes from the linux-build-test project:
11
https://github.com/groeck/linux-build-test
12
13
If ARM is a target being built, "make check-acceptance" will
14
automatically include this test by the use of the "arch:arm" tags.
15
16
Alternatively, this test can be run using:
17
18
$ avocado --show=console run -t machine:orangepi-pc tests/acceptance/boot_linux_console.py
19
console: Uncompressing Linux... done, booting the kernel.
20
console: Booting Linux on physical CPU 0x0
21
console: Linux version 4.20.7-sunxi (root@armbian.com) (gcc version 7.2.1 20171011 (Linaro GCC 7.2-2017.11)) #5.75 SMP Fri Feb 8 09:02:10 CET 2019
22
console: CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=50c5387d
23
console: CPU: div instructions available: patching division code
24
console: CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
25
console: OF: fdt: Machine model: Xunlong Orange Pi PC
26
[...]
27
console: Trying to unpack rootfs image as initramfs...
28
console: Freeing initrd memory: 3256K
29
console: Freeing unused kernel memory: 1024K
30
console: Run /init as init process
31
console: mount: mounting devtmpfs on /dev failed: Device or resource busy
32
console: Starting logging: OK
33
console: Initializing random number generator... random: dd: uninitialized urandom read (512 bytes read)
34
console: done.
35
console: Starting network: OK
36
console: Found console ttyS0
37
console: Linux version 4.20.7-sunxi (root@armbian.com) (gcc version 7.2.1 20171011 (Linaro GCC 7.2-2017.11)) #5.75 SMP Fri Feb 8 09:02:10 CET 2019
38
console: Boot successful.
39
console: cat /proc/cpuinfo
40
console: / # cat /proc/cpuinfo
41
console: processor : 0
42
console: model name : ARMv7 Processor rev 5 (v7l)
43
console: BogoMIPS : 125.00
44
console: Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm
45
console: CPU implementer : 0x41
46
console: CPU architecture: 7
47
console: CPU variant : 0x0
48
console: CPU part : 0xc07
49
console: CPU revision : 5
50
[...]
51
console: processor : 3
52
console: model name : ARMv7 Processor rev 5 (v7l)
53
console: BogoMIPS : 125.00
54
console: Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm
55
console: CPU implementer : 0x41
56
console: CPU architecture: 7
57
console: CPU variant : 0x0
58
console: CPU part : 0xc07
59
console: CPU revision : 5
60
console: Hardware : Allwinner sun8i Family
61
console: Revision : 0000
62
console: Serial : 0000000000000000
63
console: cat /proc/iomem
64
console: / # cat /proc/iomem
65
console: 01000000-010fffff : clock@1000000
66
console: 01c00000-01c00fff : system-control@1c00000
67
console: 01c02000-01c02fff : dma-controller@1c02000
68
[...]
69
console: reboot
70
console: / # reboot
71
console: / # Found console ttyS0
72
console: Stopping network: OK
73
console: hrtimer: interrupt took 21852064 ns
74
console: Saving random seed... random: dd: uninitialized urandom read (512 bytes read)
75
console: done.
76
console: Stopping logging: OK
77
console: umount: devtmpfs busy - remounted read-only
78
console: umount: can't unmount /: Invalid argument
79
console: The system is going down NOW!
80
console: Sent SIGTERM to all processes
81
console: Sent SIGKILL to all processes
82
console: Requesting system reboot
83
console: reboot: Restarting system
84
PASS (48.32 s)
85
JOB TIME : 49.16 s
86
87
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
88
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
89
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
90
Tested-by: Alex Bennée <alex.bennee@linaro.org>
91
Message-id: 20200311221854.30370-15-nieklinnenbank@gmail.com
92
[NL: rename in commit message Raspbian to Armbian, remove vm.set_machine()]
93
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
94
---
95
tests/acceptance/boot_linux_console.py | 40 ++++++++++++++++++++++++++
96
1 file changed, 40 insertions(+)
97
98
diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
99
index XXXXXXX..XXXXXXX 100644
100
--- a/tests/acceptance/boot_linux_console.py
101
+++ b/tests/acceptance/boot_linux_console.py
102
@@ -XXX,XX +XXX,XX @@ class BootLinuxConsole(Test):
103
console_pattern = 'Kernel command line: %s' % kernel_command_line
104
self.wait_for_console_pattern(console_pattern)
105
106
+ def test_arm_orangepi_initrd(self):
107
+ """
108
+ :avocado: tags=arch:arm
109
+ :avocado: tags=machine:orangepi-pc
110
+ """
111
+ deb_url = ('https://apt.armbian.com/pool/main/l/'
112
+ 'linux-4.20.7-sunxi/linux-image-dev-sunxi_5.75_armhf.deb')
113
+ deb_hash = '1334c29c44d984ffa05ed10de8c3361f33d78315'
114
+ deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
115
+ kernel_path = self.extract_from_deb(deb_path,
116
+ '/boot/vmlinuz-4.20.7-sunxi')
117
+ dtb_path = '/usr/lib/linux-image-dev-sunxi/sun8i-h3-orangepi-pc.dtb'
118
+ dtb_path = self.extract_from_deb(deb_path, dtb_path)
119
+ initrd_url = ('https://github.com/groeck/linux-build-test/raw/'
120
+ '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/'
121
+ 'arm/rootfs-armv7a.cpio.gz')
122
+ initrd_hash = '604b2e45cdf35045846b8bbfbf2129b1891bdc9c'
123
+ initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
124
+ initrd_path = os.path.join(self.workdir, 'rootfs.cpio')
125
+ archive.gzip_uncompress(initrd_path_gz, initrd_path)
126
+
127
+ self.vm.set_console()
128
+ kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
129
+ 'console=ttyS0,115200 '
130
+ 'panic=-1 noreboot')
131
+ self.vm.add_args('-kernel', kernel_path,
132
+ '-dtb', dtb_path,
133
+ '-initrd', initrd_path,
134
+ '-append', kernel_command_line,
135
+ '-no-reboot')
136
+ self.vm.launch()
137
+ self.wait_for_console_pattern('Boot successful.')
138
+
139
+ exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
140
+ 'Allwinner sun8i Family')
141
+ exec_command_and_wait_for_pattern(self, 'cat /proc/iomem',
142
+ 'system-control@1c00000')
143
+ exec_command_and_wait_for_pattern(self, 'reboot',
144
+ 'reboot: Restarting system')
145
+
146
def test_s390x_s390_ccw_virtio(self):
147
"""
148
:avocado: tags=arch:s390x
149
--
150
2.20.1
151
152
diff view generated by jsdifflib
New patch
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
2
3
The kernel image and DeviceTree blob are built by the Armbian
4
project (based on Debian):
5
https://www.armbian.com/orange-pi-pc/
6
7
The SD image is from the kernelci.org project:
8
https://kernelci.org/faq/#the-code
9
10
If ARM is a target being built, "make check-acceptance" will
11
automatically include this test by the use of the "arch:arm" tags.
12
13
Alternatively, this test can be run using:
14
15
$ avocado --show=console run -t machine:orangepi-pc tests/acceptance/boot_linux_console.py
16
console: Uncompressing Linux... done, booting the kernel.
17
console: Booting Linux on physical CPU 0x0
18
console: Linux version 4.20.7-sunxi (root@armbian.com) (gcc version 7.2.1 20171011 (Linaro GCC 7.2-2017.11)) #5.75 SMP Fri Feb 8 09:02:10 CET 2019
19
console: CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=50c5387d
20
[...]
21
console: sunxi-wdt 1c20ca0.watchdog: Watchdog enabled (timeout=16 sec, nowayout=0)
22
console: sunxi-mmc 1c0f000.mmc: Linked as a consumer to regulator.2
23
console: sunxi-mmc 1c0f000.mmc: Got CD GPIO
24
console: ledtrig-cpu: registered to indicate activity on CPUs
25
console: hidraw: raw HID events driver (C) Jiri Kosina
26
console: usbcore: registered new interface driver usbhid
27
console: usbhid: USB HID core driver
28
console: Initializing XFRM netlink socket
29
console: sunxi-mmc 1c0f000.mmc: initialized, max. request size: 16384 KB
30
console: NET: Registered protocol family 10
31
console: mmc0: host does not support reading read-only switch, assuming write-enable
32
console: mmc0: Problem switching card into high-speed mode!
33
console: mmc0: new SD card at address 4567
34
console: mmcblk0: mmc0:4567 QEMU! 60.0 MiB
35
[...]
36
console: EXT4-fs (mmcblk0): mounting ext2 file system using the ext4 subsystem
37
console: EXT4-fs (mmcblk0): mounted filesystem without journal. Opts: (null)
38
console: VFS: Mounted root (ext2 filesystem) on device 179:0.
39
console: Run /sbin/init as init process
40
console: EXT4-fs (mmcblk0): re-mounted. Opts: block_validity,barrier,user_xattr,acl
41
console: Starting syslogd: OK
42
console: Starting klogd: OK
43
console: Populating /dev using udev: udevd[203]: starting version 3.2.7
44
console: /bin/sh: can't access tty; job control turned off
45
console: cat /proc/partitions
46
console: / # cat /proc/partitions
47
console: major minor #blocks name
48
console: 1 0 4096 ram0
49
console: 1 1 4096 ram1
50
console: 1 2 4096 ram2
51
console: 1 3 4096 ram3
52
console: 179 0 61440 mmcblk0
53
console: reboot
54
console: / # reboot
55
console: umount: devtmpfs busy - remounted read-only
56
console: EXT4-fs (mmcblk0): re-mounted. Opts: (null)
57
console: The system is going down NOW!
58
console: Sent SIGTERM to all processes
59
console: Sent SIGKILL to all processes
60
console: Requesting system reboot
61
console: reboot: Restarting system
62
JOB TIME : 68.64 s
63
64
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
65
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
66
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
67
Tested-by: Alex Bennée <alex.bennee@linaro.org>
68
Message-id: 20200311221854.30370-16-nieklinnenbank@gmail.com
69
[NL: rename in commit message Raspbian to Armbian, remove vm.set_machine()]
70
[NL: extend test with ethernet device checks]
71
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
72
---
73
tests/acceptance/boot_linux_console.py | 47 ++++++++++++++++++++++++++
74
1 file changed, 47 insertions(+)
75
76
diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
77
index XXXXXXX..XXXXXXX 100644
78
--- a/tests/acceptance/boot_linux_console.py
79
+++ b/tests/acceptance/boot_linux_console.py
80
@@ -XXX,XX +XXX,XX @@ class BootLinuxConsole(Test):
81
exec_command_and_wait_for_pattern(self, 'reboot',
82
'reboot: Restarting system')
83
84
+ def test_arm_orangepi_sd(self):
85
+ """
86
+ :avocado: tags=arch:arm
87
+ :avocado: tags=machine:orangepi-pc
88
+ """
89
+ deb_url = ('https://apt.armbian.com/pool/main/l/'
90
+ 'linux-4.20.7-sunxi/linux-image-dev-sunxi_5.75_armhf.deb')
91
+ deb_hash = '1334c29c44d984ffa05ed10de8c3361f33d78315'
92
+ deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
93
+ kernel_path = self.extract_from_deb(deb_path,
94
+ '/boot/vmlinuz-4.20.7-sunxi')
95
+ dtb_path = '/usr/lib/linux-image-dev-sunxi/sun8i-h3-orangepi-pc.dtb'
96
+ dtb_path = self.extract_from_deb(deb_path, dtb_path)
97
+ rootfs_url = ('http://storage.kernelci.org/images/rootfs/buildroot/'
98
+ 'kci-2019.02/armel/base/rootfs.ext2.xz')
99
+ rootfs_hash = '692510cb625efda31640d1de0a8d60e26040f061'
100
+ rootfs_path_xz = self.fetch_asset(rootfs_url, asset_hash=rootfs_hash)
101
+ rootfs_path = os.path.join(self.workdir, 'rootfs.cpio')
102
+ archive.lzma_uncompress(rootfs_path_xz, rootfs_path)
103
+
104
+ self.vm.set_console()
105
+ kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
106
+ 'console=ttyS0,115200 '
107
+ 'root=/dev/mmcblk0 rootwait rw '
108
+ 'panic=-1 noreboot')
109
+ self.vm.add_args('-kernel', kernel_path,
110
+ '-dtb', dtb_path,
111
+ '-drive', 'file=' + rootfs_path + ',if=sd,format=raw',
112
+ '-append', kernel_command_line,
113
+ '-no-reboot')
114
+ self.vm.launch()
115
+ shell_ready = "/bin/sh: can't access tty; job control turned off"
116
+ self.wait_for_console_pattern(shell_ready)
117
+
118
+ exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
119
+ 'Allwinner sun8i Family')
120
+ exec_command_and_wait_for_pattern(self, 'cat /proc/partitions',
121
+ 'mmcblk0')
122
+ exec_command_and_wait_for_pattern(self, 'ifconfig eth0 up',
123
+ 'eth0: Link is Up')
124
+ exec_command_and_wait_for_pattern(self, 'udhcpc eth0',
125
+ 'udhcpc: lease of 10.0.2.15 obtained')
126
+ exec_command_and_wait_for_pattern(self, 'ping -c 3 10.0.2.2',
127
+ '3 packets transmitted, 3 packets received, 0% packet loss')
128
+ exec_command_and_wait_for_pattern(self, 'reboot',
129
+ 'reboot: Restarting system')
130
+
131
def test_s390x_s390_ccw_virtio(self):
132
"""
133
:avocado: tags=arch:s390x
134
--
135
2.20.1
136
137
diff view generated by jsdifflib
New patch
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
2
3
This test boots Ubuntu Bionic on a OrangePi PC board.
4
5
As it requires 1GB of storage, and is slow, this test is disabled
6
on automatic CI testing.
7
8
It is useful for workstation testing. Currently Avocado timeouts too
9
quickly, so we can't run userland commands.
10
11
The kernel image and DeviceTree blob are built by the Armbian
12
project (based on Debian):
13
https://www.armbian.com/orange-pi-pc/
14
15
The Ubuntu image is downloaded from:
16
https://dl.armbian.com/orangepipc/Bionic_current
17
18
This test can be run using:
19
20
$ AVOCADO_ALLOW_LARGE_STORAGE=yes \
21
avocado --show=app,console run -t machine:orangepi-pc \
22
tests/acceptance/boot_linux_console.py
23
console: U-Boot SPL 2019.04-armbian (Nov 18 2019 - 23:08:35 +0100)
24
console: DRAM: 1024 MiB
25
console: Failed to set core voltage! Can't set CPU frequency
26
console: Trying to boot from MMC1
27
console: U-Boot 2019.04-armbian (Nov 18 2019 - 23:08:35 +0100) Allwinner Technology
28
console: CPU: Allwinner H3 (SUN8I 0000)
29
console: Model: Xunlong Orange Pi PC
30
console: DRAM: 1 GiB
31
console: MMC: mmc@1c0f000: 0
32
[...]
33
console: Uncompressing Linux... done, booting the kernel.
34
console: Booting Linux on physical CPU 0x0
35
console: Linux version 5.3.9-sunxi (root@builder) (gcc version 8.3.0 (GNU Toolchain for the A-profile Architecture 8.3-2019.03 (arm-rel-8.36))) #19.11.3 SMP Mon Nov 18 18:49:43 CET 2019
36
console: CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=50c5387d
37
console: CPU: div instructions available: patching division code
38
console: CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
39
console: OF: fdt: Machine model: Xunlong Orange Pi PC
40
[...]
41
console: EXT4-fs (mmcblk0p1): mounted filesystem with writeback data mode. Opts: (null)
42
console: done.
43
console: Begin: Running /scripts/local-bottom ... done.
44
console: Begin: Running /scripts/init-bottom ... done.
45
console: systemd[1]: systemd 237 running in system mode. (...)
46
console: systemd[1]: Detected architecture arm.
47
console: Welcome to Ubuntu 18.04.3 LTS!
48
console: systemd[1]: Set hostname to <orangepipc>.
49
50
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
51
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
52
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
53
Tested-by: Alex Bennée <alex.bennee@linaro.org>
54
Message-id: 20200311221854.30370-17-nieklinnenbank@gmail.com
55
[NL: rename in commit message Raspbian to Armbian, remove vm.set_machine()]
56
[NL: changed test to boot from SD card via BootROM, added check for 7z]
57
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
58
---
59
tests/acceptance/boot_linux_console.py | 48 ++++++++++++++++++++++++++
60
1 file changed, 48 insertions(+)
61
62
diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
63
index XXXXXXX..XXXXXXX 100644
64
--- a/tests/acceptance/boot_linux_console.py
65
+++ b/tests/acceptance/boot_linux_console.py
66
@@ -XXX,XX +XXX,XX @@ from avocado_qemu import exec_command_and_wait_for_pattern
67
from avocado_qemu import wait_for_console_pattern
68
from avocado.utils import process
69
from avocado.utils import archive
70
+from avocado.utils.path import find_command, CmdNotFoundError
71
72
+P7ZIP_AVAILABLE = True
73
+try:
74
+ find_command('7z')
75
+except CmdNotFoundError:
76
+ P7ZIP_AVAILABLE = False
77
78
class BootLinuxConsole(Test):
79
"""
80
@@ -XXX,XX +XXX,XX @@ class BootLinuxConsole(Test):
81
exec_command_and_wait_for_pattern(self, 'reboot',
82
'reboot: Restarting system')
83
84
+ @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited')
85
+ @skipUnless(P7ZIP_AVAILABLE, '7z not installed')
86
+ def test_arm_orangepi_bionic(self):
87
+ """
88
+ :avocado: tags=arch:arm
89
+ :avocado: tags=machine:orangepi-pc
90
+ """
91
+
92
+ # This test download a 196MB compressed image and expand it to 932MB...
93
+ image_url = ('https://dl.armbian.com/orangepipc/archive/'
94
+ 'Armbian_19.11.3_Orangepipc_bionic_current_5.3.9.7z')
95
+ image_hash = '196a8ffb72b0123d92cea4a070894813d305c71e'
96
+ image_path_7z = self.fetch_asset(image_url, asset_hash=image_hash)
97
+ image_name = 'Armbian_19.11.3_Orangepipc_bionic_current_5.3.9.img'
98
+ image_path = os.path.join(self.workdir, image_name)
99
+ process.run("7z e -o%s %s" % (self.workdir, image_path_7z))
100
+
101
+ self.vm.set_console()
102
+ self.vm.add_args('-drive', 'file=' + image_path + ',if=sd,format=raw',
103
+ '-nic', 'user',
104
+ '-no-reboot')
105
+ self.vm.launch()
106
+
107
+ kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
108
+ 'console=ttyS0,115200 '
109
+ 'loglevel=7 '
110
+ 'nosmp '
111
+ 'systemd.default_timeout_start_sec=9000 '
112
+ 'systemd.mask=armbian-zram-config.service '
113
+ 'systemd.mask=armbian-ramlog.service')
114
+
115
+ self.wait_for_console_pattern('U-Boot SPL')
116
+ self.wait_for_console_pattern('Autoboot in ')
117
+ exec_command_and_wait_for_pattern(self, ' ', '=>')
118
+ exec_command_and_wait_for_pattern(self, "setenv extraargs '" +
119
+ kernel_command_line + "'", '=>')
120
+ exec_command_and_wait_for_pattern(self, 'boot', 'Starting kernel ...');
121
+
122
+ self.wait_for_console_pattern('systemd[1]: Set hostname ' +
123
+ 'to <orangepipc>')
124
+ self.wait_for_console_pattern('Starting Load Kernel Modules...')
125
+
126
def test_s390x_s390_ccw_virtio(self):
127
"""
128
:avocado: tags=arch:s390x
129
--
130
2.20.1
131
132
diff view generated by jsdifflib
New patch
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
2
3
This test boots U-Boot then NetBSD (stored on a SD card) on
4
a OrangePi PC board.
5
6
As it requires ~1.3GB of storage, it is disabled by default.
7
8
U-Boot is built by the Debian project [1], and the SD card image
9
is provided by the NetBSD organization [2].
10
11
Once the compressed SD card image is downloaded (304MB) and
12
extracted, this test is fast:
13
14
$ AVOCADO_ALLOW_LARGE_STORAGE=yes \
15
avocado --show=app,console run -t machine:orangepi-pc \
16
tests/acceptance/boot_linux_console.py
17
console: U-Boot SPL 2020.01+dfsg-1 (Jan 08 2020 - 08:19:44 +0000)
18
console: DRAM: 1024 MiB
19
console: U-Boot 2020.01+dfsg-1 (Jan 08 2020 - 08:19:44 +0000) Allwinner Technology
20
console: CPU: Allwinner H3 (SUN8I 0000)
21
console: scanning bus usb@1c1b000 for devices... 1 USB Device(s) found
22
console: scanning bus usb@1c1d000 for devices... 1 USB Device(s) found
23
console: scanning usb for storage devices... 0 Storage Device(s) found
24
console: Hit any key to stop autoboot: 0
25
console: => setenv bootargs root=ld0a
26
console: => setenv kernel netbsd-GENERIC.ub
27
console: => setenv fdtfile dtb/sun8i-h3-orangepi-pc.dtb
28
console: => boot
29
console: ## Booting kernel from Legacy Image at 42000000 ...
30
console: Image Name: NetBSD/earmv7hf 9.0_RC1
31
console: Image Type: ARM Linux Kernel Image (no loading done) (uncompressed)
32
console: XIP Kernel Image (no loading done)
33
console: Loading Device Tree to 49ff6000, end 49fffe01 ... OK
34
console: Starting kernel ...
35
console: [ 1.0000000] NetBSD/evbarm (fdt) booting ...
36
console: [ 1.0000000] NetBSD 9.0 (GENERIC) #0: Fri Feb 14 00:06:28 UTC 2020
37
console: [ 1.0000000] mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/evbarm/compile/GENERIC
38
console: [ 1.0000000] total memory = 1024 MB
39
console: [ 1.0000000] avail memory = 1003 MB
40
console: [ 1.0000000] armfdt0 (root)
41
console: [ 1.0000000] simplebus0 at armfdt0: Xunlong Orange Pi PC
42
console: [ 1.0000000] cpu0 at cpus0: Cortex-A7 r0p5 (Cortex V7A core)
43
console: [ 1.0000000] cpu0: DC enabled IC enabled WB enabled LABT branch prediction enabled
44
console: [ 1.0000000] cpu0: 32KB/64B 2-way L1 VIPT Instruction cache
45
console: [ 1.0000000] cpu0: 32KB/64B 2-way write-back-locking-C L1 PIPT Data cache
46
console: [ 1.0000000] cpu0: 2304KB/64B 16-way write-through L2 PIPT Unified cache
47
console: [ 1.0000000] vfp0 at cpu0: NEON MPE (VFP 3.0+), rounding, NaN propagation, denormals
48
...
49
console: [ 2.3812082] sdmmc0: SD card status: 4-bit, C0
50
console: [ 2.3812082] ld0 at sdmmc0: <0xaa:0x5859:QEMU!:0x01:0xdeadbeef:0x062>
51
console: [ 2.4012856] ld0: 1226 MB, 622 cyl, 64 head, 63 sec, 512 bytes/sect x 2511872 sectors
52
console: [ 2.5321222] ld0: 4-bit width, High-Speed/SDR25, 50.000 MHz
53
console: [ 3.1068718] WARNING: 4 errors while detecting hardware; check system log.
54
console: [ 3.1179868] boot device: ld0
55
console: [ 3.1470623] root on ld0a dumps on ld0b
56
console: [ 3.2464436] root file system type: ffs
57
console: [ 3.2897123] kern.module.path=/stand/evbarm/9.0/modules
58
console: Mon Feb 17 20:33:35 UTC 2020
59
console: Starting root file system check:
60
PASS (35.96 s)
61
RESULTS : PASS 1 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
62
JOB TIME : 36.09 s
63
64
Note, this test only took ~65 seconds to run on Travis-CI, see: [3].
65
66
This test is based on a description from Niek Linnenbank from [4].
67
68
[1] https://wiki.debian.org/InstallingDebianOn/Allwinner#Creating_a_bootable_SD_Card_with_u-boot
69
[2] https://wiki.netbsd.org/ports/evbarm/allwinner/
70
[3] https://travis-ci.org/philmd/qemu/jobs/638823612#L3778
71
[4] https://www.mail-archive.com/qemu-devel@nongnu.org/msg669347.html
72
73
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
74
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
75
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
76
Tested-by: Alex Bennée <alex.bennee@linaro.org>
77
Message-id: 20200311221854.30370-18-nieklinnenbank@gmail.com
78
[NL: changed test to use NetBSD 9.0 final release and -global allwinner-rtc.base-year]
79
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
80
---
81
tests/acceptance/boot_linux_console.py | 70 ++++++++++++++++++++++++++
82
1 file changed, 70 insertions(+)
83
84
diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
85
index XXXXXXX..XXXXXXX 100644
86
--- a/tests/acceptance/boot_linux_console.py
87
+++ b/tests/acceptance/boot_linux_console.py
88
@@ -XXX,XX +XXX,XX @@ import shutil
89
from avocado import skipUnless
90
from avocado_qemu import Test
91
from avocado_qemu import exec_command_and_wait_for_pattern
92
+from avocado_qemu import interrupt_interactive_console_until_pattern
93
from avocado_qemu import wait_for_console_pattern
94
from avocado.utils import process
95
from avocado.utils import archive
96
@@ -XXX,XX +XXX,XX @@ class BootLinuxConsole(Test):
97
'to <orangepipc>')
98
self.wait_for_console_pattern('Starting Load Kernel Modules...')
99
100
+ @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited')
101
+ def test_arm_orangepi_uboot_netbsd9(self):
102
+ """
103
+ :avocado: tags=arch:arm
104
+ :avocado: tags=machine:orangepi-pc
105
+ """
106
+ # This test download a 304MB compressed image and expand it to 1.3GB...
107
+ deb_url = ('http://snapshot.debian.org/archive/debian/'
108
+ '20200108T145233Z/pool/main/u/u-boot/'
109
+ 'u-boot-sunxi_2020.01%2Bdfsg-1_armhf.deb')
110
+ deb_hash = 'f67f404a80753ca3d1258f13e38f2b060e13db99'
111
+ deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
112
+ # We use the common OrangePi PC 'plus' build of U-Boot for our secondary
113
+ # program loader (SPL). We will then set the path to the more specific
114
+ # OrangePi "PC" device tree blob with 'setenv fdtfile' in U-Boot prompt,
115
+ # before to boot NetBSD.
116
+ uboot_path = '/usr/lib/u-boot/orangepi_plus/u-boot-sunxi-with-spl.bin'
117
+ uboot_path = self.extract_from_deb(deb_path, uboot_path)
118
+ image_url = ('https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.0/'
119
+ 'evbarm-earmv7hf/binary/gzimg/armv7.img.gz')
120
+ image_hash = '2babb29d36d8360adcb39c09e31060945259917a'
121
+ image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash)
122
+ image_path = os.path.join(self.workdir, 'armv7.img')
123
+ image_drive_args = 'if=sd,format=raw,snapshot=on,file=' + image_path
124
+ archive.gzip_uncompress(image_path_gz, image_path)
125
+
126
+ # dd if=u-boot-sunxi-with-spl.bin of=armv7.img bs=1K seek=8 conv=notrunc
127
+ with open(uboot_path, 'rb') as f_in:
128
+ with open(image_path, 'r+b') as f_out:
129
+ f_out.seek(8 * 1024)
130
+ shutil.copyfileobj(f_in, f_out)
131
+
132
+ # Extend image, to avoid that NetBSD thinks the partition
133
+ # inside the image is larger than device size itself
134
+ f_out.seek(0, 2)
135
+ f_out.seek(64 * 1024 * 1024, 1)
136
+ f_out.write(bytearray([0x00]))
137
+
138
+ self.vm.set_console()
139
+ self.vm.add_args('-nic', 'user',
140
+ '-drive', image_drive_args,
141
+ '-global', 'allwinner-rtc.base-year=2000',
142
+ '-no-reboot')
143
+ self.vm.launch()
144
+ wait_for_console_pattern(self, 'U-Boot 2020.01+dfsg-1')
145
+ interrupt_interactive_console_until_pattern(self,
146
+ 'Hit any key to stop autoboot:',
147
+ 'switch to partitions #0, OK')
148
+
149
+ exec_command_and_wait_for_pattern(self, '', '=>')
150
+ cmd = 'setenv bootargs root=ld0a'
151
+ exec_command_and_wait_for_pattern(self, cmd, '=>')
152
+ cmd = 'setenv kernel netbsd-GENERIC.ub'
153
+ exec_command_and_wait_for_pattern(self, cmd, '=>')
154
+ cmd = 'setenv fdtfile dtb/sun8i-h3-orangepi-pc.dtb'
155
+ exec_command_and_wait_for_pattern(self, cmd, '=>')
156
+ cmd = ("setenv bootcmd 'fatload mmc 0:1 ${kernel_addr_r} ${kernel}; "
157
+ "fatload mmc 0:1 ${fdt_addr_r} ${fdtfile}; "
158
+ "fdt addr ${fdt_addr_r}; "
159
+ "bootm ${kernel_addr_r} - ${fdt_addr_r}'")
160
+ exec_command_and_wait_for_pattern(self, cmd, '=>')
161
+
162
+ exec_command_and_wait_for_pattern(self, 'boot',
163
+ 'Booting kernel from Legacy Image')
164
+ wait_for_console_pattern(self, 'Starting kernel ...')
165
+ wait_for_console_pattern(self, 'NetBSD 9.0 (GENERIC)')
166
+ # Wait for user-space
167
+ wait_for_console_pattern(self, 'Starting root file system check')
168
+
169
def test_s390x_s390_ccw_virtio(self):
170
"""
171
:avocado: tags=arch:s390x
172
--
173
2.20.1
174
175
diff view generated by jsdifflib
New patch
1
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
2
3
The Xunlong Orange Pi PC machine is a functional ARM machine
4
based on the Allwinner H3 System-on-Chip. It supports mainline
5
Linux, U-Boot, NetBSD and is covered by acceptance tests.
6
7
This commit adds a documentation text file with a description
8
of the machine and instructions for the user.
9
10
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
11
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
12
Message-id: 20200311221854.30370-19-nieklinnenbank@gmail.com
13
[PMM: moved file into docs/system/arm to match the reorg
14
of the arm target part of the docs; tweaked heading to
15
match other boards]
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
---
18
MAINTAINERS | 1 +
19
docs/system/arm/orangepi.rst | 253 +++++++++++++++++++++++++++++++++++
20
docs/system/target-arm.rst | 2 +
21
3 files changed, 256 insertions(+)
22
create mode 100644 docs/system/arm/orangepi.rst
23
24
diff --git a/MAINTAINERS b/MAINTAINERS
25
index XXXXXXX..XXXXXXX 100644
26
--- a/MAINTAINERS
27
+++ b/MAINTAINERS
28
@@ -XXX,XX +XXX,XX @@ S: Maintained
29
F: hw/*/allwinner-h3*
30
F: include/hw/*/allwinner-h3*
31
F: hw/arm/orangepi.c
32
+F: docs/system/orangepi.rst
33
34
ARM PrimeCell and CMSDK devices
35
M: Peter Maydell <peter.maydell@linaro.org>
36
diff --git a/docs/system/arm/orangepi.rst b/docs/system/arm/orangepi.rst
37
new file mode 100644
38
index XXXXXXX..XXXXXXX
39
--- /dev/null
40
+++ b/docs/system/arm/orangepi.rst
41
@@ -XXX,XX +XXX,XX @@
42
+Orange Pi PC (``orangepi-pc``)
43
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44
+
45
+The Xunlong Orange Pi PC is an Allwinner H3 System on Chip
46
+based embedded computer with mainline support in both U-Boot
47
+and Linux. The board comes with a Quad Core Cortex-A7 @ 1.3GHz,
48
+1GiB RAM, 100Mbit ethernet, USB, SD/MMC, USB, HDMI and
49
+various other I/O.
50
+
51
+Supported devices
52
+"""""""""""""""""
53
+
54
+The Orange Pi PC machine supports the following devices:
55
+
56
+ * SMP (Quad Core Cortex-A7)
57
+ * Generic Interrupt Controller configuration
58
+ * SRAM mappings
59
+ * SDRAM controller
60
+ * Real Time Clock
61
+ * Timer device (re-used from Allwinner A10)
62
+ * UART
63
+ * SD/MMC storage controller
64
+ * EMAC ethernet
65
+ * USB 2.0 interfaces
66
+ * Clock Control Unit
67
+ * System Control module
68
+ * Security Identifier device
69
+
70
+Limitations
71
+"""""""""""
72
+
73
+Currently, Orange Pi PC does *not* support the following features:
74
+
75
+- Graphical output via HDMI, GPU and/or the Display Engine
76
+- Audio output
77
+- Hardware Watchdog
78
+
79
+Also see the 'unimplemented' array in the Allwinner H3 SoC module
80
+for a complete list of unimplemented I/O devices: ``./hw/arm/allwinner-h3.c``
81
+
82
+Boot options
83
+""""""""""""
84
+
85
+The Orange Pi PC machine can start using the standard -kernel functionality
86
+for loading a Linux kernel or ELF executable. Additionally, the Orange Pi PC
87
+machine can also emulate the BootROM which is present on an actual Allwinner H3
88
+based SoC, which loads the bootloader from a SD card, specified via the -sd argument
89
+to qemu-system-arm.
90
+
91
+Machine-specific options
92
+""""""""""""""""""""""""
93
+
94
+The following machine-specific options are supported:
95
+
96
+- allwinner-rtc.base-year=YYYY
97
+
98
+ The Allwinner RTC device is automatically created by the Orange Pi PC machine
99
+ and uses a default base year value which can be overridden using the 'base-year' property.
100
+ The base year is the actual represented year when the RTC year value is zero.
101
+ This option can be used in case the target operating system driver uses a different
102
+ base year value. The minimum value for the base year is 1900.
103
+
104
+- allwinner-sid.identifier=abcd1122-a000-b000-c000-12345678ffff
105
+
106
+ The Security Identifier value can be read by the guest.
107
+ For example, U-Boot uses it to determine a unique MAC address.
108
+
109
+The above machine-specific options can be specified in qemu-system-arm
110
+via the '-global' argument, for example:
111
+
112
+.. code-block:: bash
113
+
114
+ $ qemu-system-arm -M orangepi-pc -sd mycard.img \
115
+ -global allwinner-rtc.base-year=2000
116
+
117
+Running mainline Linux
118
+""""""""""""""""""""""
119
+
120
+Mainline Linux kernels from 4.19 up to latest master are known to work.
121
+To build a Linux mainline kernel that can be booted by the Orange Pi PC machine,
122
+simply configure the kernel using the sunxi_defconfig configuration:
123
+
124
+.. code-block:: bash
125
+
126
+ $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make mrproper
127
+ $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make sunxi_defconfig
128
+
129
+To be able to use USB storage, you need to manually enable the corresponding
130
+configuration item. Start the kconfig configuration tool:
131
+
132
+.. code-block:: bash
133
+
134
+ $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make menuconfig
135
+
136
+Navigate to the following item, enable it and save your configuration:
137
+
138
+ Device Drivers > USB support > USB Mass Storage support
139
+
140
+Build the Linux kernel with:
141
+
142
+.. code-block:: bash
143
+
144
+ $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make
145
+
146
+To boot the newly build linux kernel in QEMU with the Orange Pi PC machine, use:
147
+
148
+.. code-block:: bash
149
+
150
+ $ qemu-system-arm -M orangepi-pc -nic user -nographic \
151
+ -kernel /path/to/linux/arch/arm/boot/zImage \
152
+ -append 'console=ttyS0,115200' \
153
+ -dtb /path/to/linux/arch/arm/boot/dts/sun8i-h3-orangepi-pc.dtb
154
+
155
+Orange Pi PC images
156
+"""""""""""""""""""
157
+
158
+Note that the mainline kernel does not have a root filesystem. You may provide it
159
+with an official Orange Pi PC image from the official website:
160
+
161
+ http://www.orangepi.org/downloadresources/
162
+
163
+Another possibility is to run an Armbian image for Orange Pi PC which
164
+can be downloaded from:
165
+
166
+ https://www.armbian.com/orange-pi-pc/
167
+
168
+Alternatively, you can also choose to build you own image with buildroot
169
+using the orangepi_pc_defconfig. Also see https://buildroot.org for more information.
170
+
171
+You can choose to attach the selected image either as an SD card or as USB mass storage.
172
+For example, to boot using the Orange Pi PC Debian image on SD card, simply add the -sd
173
+argument and provide the proper root= kernel parameter:
174
+
175
+.. code-block:: bash
176
+
177
+ $ qemu-system-arm -M orangepi-pc -nic user -nographic \
178
+ -kernel /path/to/linux/arch/arm/boot/zImage \
179
+ -append 'console=ttyS0,115200 root=/dev/mmcblk0p2' \
180
+ -dtb /path/to/linux/arch/arm/boot/dts/sun8i-h3-orangepi-pc.dtb \
181
+ -sd OrangePi_pc_debian_stretch_server_linux5.3.5_v1.0.img
182
+
183
+To attach the image as an USB mass storage device to the machine,
184
+simply append to the command:
185
+
186
+.. code-block:: bash
187
+
188
+ -drive if=none,id=stick,file=myimage.img \
189
+ -device usb-storage,bus=usb-bus.0,drive=stick
190
+
191
+Instead of providing a custom Linux kernel via the -kernel command you may also
192
+choose to let the Orange Pi PC machine load the bootloader from SD card, just like
193
+a real board would do using the BootROM. Simply pass the selected image via the -sd
194
+argument and remove the -kernel, -append, -dbt and -initrd arguments:
195
+
196
+.. code-block:: bash
197
+
198
+ $ qemu-system-arm -M orangepi-pc -nic user -nographic \
199
+ -sd Armbian_19.11.3_Orangepipc_buster_current_5.3.9.img
200
+
201
+Note that both the official Orange Pi PC images and Armbian images start
202
+a lot of userland programs via systemd. Depending on the host hardware and OS,
203
+they may be slow to emulate, especially due to emulating the 4 cores.
204
+To help reduce the performance slow down due to emulating the 4 cores, you can
205
+give the following kernel parameters via U-Boot (or via -append):
206
+
207
+.. code-block:: bash
208
+
209
+ => setenv extraargs 'systemd.default_timeout_start_sec=9000 loglevel=7 nosmp console=ttyS0,115200'
210
+
211
+Running U-Boot
212
+""""""""""""""
213
+
214
+U-Boot mainline can be build and configured using the orangepi_pc_defconfig
215
+using similar commands as describe above for Linux. Note that it is recommended
216
+for development/testing to select the following configuration setting in U-Boot:
217
+
218
+ Device Tree Control > Provider for DTB for DT Control > Embedded DTB
219
+
220
+To start U-Boot using the Orange Pi PC machine, provide the
221
+u-boot binary to the -kernel argument:
222
+
223
+.. code-block:: bash
224
+
225
+ $ qemu-system-arm -M orangepi-pc -nic user -nographic \
226
+ -kernel /path/to/uboot/u-boot -sd disk.img
227
+
228
+Use the following U-boot commands to load and boot a Linux kernel from SD card:
229
+
230
+.. code-block:: bash
231
+
232
+ => setenv bootargs console=ttyS0,115200
233
+ => ext2load mmc 0 0x42000000 zImage
234
+ => ext2load mmc 0 0x43000000 sun8i-h3-orangepi-pc.dtb
235
+ => bootz 0x42000000 - 0x43000000
236
+
237
+Running NetBSD
238
+""""""""""""""
239
+
240
+The NetBSD operating system also includes support for Allwinner H3 based boards,
241
+including the Orange Pi PC. NetBSD 9.0 is known to work best for the Orange Pi PC
242
+board and provides a fully working system with serial console, networking and storage.
243
+For the Orange Pi PC machine, get the 'evbarm-earmv7hf' based image from:
244
+
245
+ https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.0/evbarm-earmv7hf/binary/gzimg/armv7.img.gz
246
+
247
+The image requires manually installing U-Boot in the image. Build U-Boot with
248
+the orangepi_pc_defconfig configuration as described in the previous section.
249
+Next, unzip the NetBSD image and write the U-Boot binary including SPL using:
250
+
251
+.. code-block:: bash
252
+
253
+ $ gunzip armv7.img.gz
254
+ $ dd if=/path/to/u-boot-sunxi-with-spl.bin of=armv7.img bs=1024 seek=8 conv=notrunc
255
+
256
+Finally, before starting the machine the SD image must be extended such
257
+that the NetBSD kernel will not conclude the NetBSD partition is larger than
258
+the emulated SD card:
259
+
260
+.. code-block:: bash
261
+
262
+ $ dd if=/dev/zero bs=1M count=64 >> armv7.img
263
+
264
+Start the machine using the following command:
265
+
266
+.. code-block:: bash
267
+
268
+ $ qemu-system-arm -M orangepi-pc -nic user -nographic \
269
+ -sd armv7.img -global allwinner-rtc.base-year=2000
270
+
271
+At the U-Boot stage, interrupt the automatic boot process by pressing a key
272
+and set the following environment variables before booting:
273
+
274
+.. code-block:: bash
275
+
276
+ => setenv bootargs root=ld0a
277
+ => setenv kernel netbsd-GENERIC.ub
278
+ => setenv fdtfile dtb/sun8i-h3-orangepi-pc.dtb
279
+ => setenv bootcmd 'fatload mmc 0:1 ${kernel_addr_r} ${kernel}; fatload mmc 0:1 ${fdt_addr_r} ${fdtfile}; fdt addr ${fdt_addr_r}; bootm ${kernel_addr_r} - ${fdt_addr_r}'
280
+
281
+Optionally you may save the environment variables to SD card with 'saveenv'.
282
+To continue booting simply give the 'boot' command and NetBSD boots.
283
+
284
+Orange Pi PC acceptance tests
285
+"""""""""""""""""""""""""""""
286
+
287
+The Orange Pi PC machine has several acceptance tests included.
288
+To run the whole set of tests, build QEMU from source and simply
289
+provide the following command:
290
+
291
+.. code-block:: bash
292
+
293
+ $ AVOCADO_ALLOW_LARGE_STORAGE=yes avocado --show=app,console run \
294
+ -t machine:orangepi-pc tests/acceptance/boot_linux_console.py
295
diff --git a/docs/system/target-arm.rst b/docs/system/target-arm.rst
296
index XXXXXXX..XXXXXXX 100644
297
--- a/docs/system/target-arm.rst
298
+++ b/docs/system/target-arm.rst
299
@@ -XXX,XX +XXX,XX @@ undocumented; you can get a complete list by running
300
``qemu-system-aarch64 --machine help``.
301
302
.. toctree::
303
+ :maxdepth: 1
304
305
arm/integratorcp
306
arm/versatile
307
@@ -XXX,XX +XXX,XX @@ undocumented; you can get a complete list by running
308
arm/stellaris
309
arm/musicpal
310
arm/sx1
311
+ arm/orangepi
312
313
Arm CPU features
314
================
315
--
316
2.20.1
317
318
diff view generated by jsdifflib
1
In v7M, the fixed-priority exceptions are:
1
From: Eric Auger <eric.auger@redhat.com>
2
Reset: -3
3
NMI: -2
4
HardFault: -1
5
2
6
In v8M, this changes because Secure HardFault may need
3
Mention 'max' value in the gic-version property description.
7
to be prioritised above NMI:
8
Reset: -4
9
Secure HardFault if AIRCR.BFHFNMINS == 1: -3
10
NMI: -2
11
Secure HardFault if AIRCR.BFHFNMINS == 0: -1
12
NonSecure HardFault: -1
13
4
14
Make these changes, including support for changing the
5
Signed-off-by: Eric Auger <eric.auger@redhat.com>
15
priority of Secure HardFault as AIRCR.BFHFNMINS changes.
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Andrew Jones <drjones@redhat.com>
8
Message-id: 20200311131618.7187-2-eric.auger@redhat.com
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
11
hw/arm/virt.c | 3 ++-
12
1 file changed, 2 insertions(+), 1 deletion(-)
16
13
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
18
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
19
Message-id: 1505240046-11454-14-git-send-email-peter.maydell@linaro.org
20
---
21
hw/intc/armv7m_nvic.c | 22 +++++++++++++++++++---
22
1 file changed, 19 insertions(+), 3 deletions(-)
23
24
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
25
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
26
--- a/hw/intc/armv7m_nvic.c
16
--- a/hw/arm/virt.c
27
+++ b/hw/intc/armv7m_nvic.c
17
+++ b/hw/arm/virt.c
28
@@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value,
18
@@ -XXX,XX +XXX,XX @@ static void virt_instance_init(Object *obj)
29
(R_V7M_AIRCR_SYSRESETREQS_MASK |
19
virt_set_gic_version, NULL);
30
R_V7M_AIRCR_BFHFNMINS_MASK |
20
object_property_set_description(obj, "gic-version",
31
R_V7M_AIRCR_PRIS_MASK);
21
"Set GIC version. "
32
+ /* BFHFNMINS changes the priority of Secure HardFault */
22
- "Valid values are 2, 3 and host", NULL);
33
+ if (cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK) {
23
+ "Valid values are 2, 3, host and max",
34
+ s->sec_vectors[ARMV7M_EXCP_HARD].prio = -3;
24
+ NULL);
35
+ } else {
25
36
+ s->sec_vectors[ARMV7M_EXCP_HARD].prio = -1;
26
vms->highmem_ecam = !vmc->no_highmem_ecam;
37
+ }
38
}
39
nvic_irq_update(s);
40
}
41
@@ -XXX,XX +XXX,XX @@ static int nvic_post_load(void *opaque, int version_id)
42
{
43
NVICState *s = opaque;
44
unsigned i;
45
+ int resetprio;
46
47
/* Check for out of range priority settings */
48
- if (s->vectors[ARMV7M_EXCP_RESET].prio != -3 ||
49
+ resetprio = arm_feature(&s->cpu->env, ARM_FEATURE_V8) ? -4 : -3;
50
+
51
+ if (s->vectors[ARMV7M_EXCP_RESET].prio != resetprio ||
52
s->vectors[ARMV7M_EXCP_NMI].prio != -2 ||
53
s->vectors[ARMV7M_EXCP_HARD].prio != -1) {
54
return 1;
55
@@ -XXX,XX +XXX,XX @@ static int nvic_security_post_load(void *opaque, int version_id)
56
int i;
57
58
/* Check for out of range priority settings */
59
- if (s->sec_vectors[ARMV7M_EXCP_HARD].prio != -1) {
60
+ if (s->sec_vectors[ARMV7M_EXCP_HARD].prio != -1
61
+ && s->sec_vectors[ARMV7M_EXCP_HARD].prio != -3) {
62
+ /* We can't cross-check against AIRCR.BFHFNMINS as we don't know
63
+ * if the CPU state has been migrated yet; a mismatch won't
64
+ * cause the emulation to blow up, though.
65
+ */
66
return 1;
67
}
68
for (i = ARMV7M_EXCP_MEM; i < ARRAY_SIZE(s->sec_vectors); i++) {
69
@@ -XXX,XX +XXX,XX @@ static Property props_nvic[] = {
70
71
static void armv7m_nvic_reset(DeviceState *dev)
72
{
73
+ int resetprio;
74
NVICState *s = NVIC(dev);
75
76
s->vectors[ARMV7M_EXCP_NMI].enabled = 1;
77
@@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_reset(DeviceState *dev)
78
s->vectors[ARMV7M_EXCP_PENDSV].enabled = 1;
79
s->vectors[ARMV7M_EXCP_SYSTICK].enabled = 1;
80
81
- s->vectors[ARMV7M_EXCP_RESET].prio = -3;
82
+ resetprio = arm_feature(&s->cpu->env, ARM_FEATURE_V8) ? -4 : -3;
83
+ s->vectors[ARMV7M_EXCP_RESET].prio = resetprio;
84
s->vectors[ARMV7M_EXCP_NMI].prio = -2;
85
s->vectors[ARMV7M_EXCP_HARD].prio = -1;
86
27
87
--
28
--
88
2.7.4
29
2.20.1
89
30
90
31
diff view generated by jsdifflib
1
When escalating to HardFault, we must go into Lockup if we
1
From: Eric Auger <eric.auger@redhat.com>
2
can't take the synchronous HardFault because the current
3
execution priority is already at or below the priority of
4
HardFault. In v7M HF is always priority -1 so a simple < 0
5
comparison sufficed; in v8M the priority of HardFault can
6
vary depending on whether it is a Secure or NonSecure
7
HardFault, so we must check against the priority of the
8
HardFault exception vector we're about to use.
9
2
3
We plan to introduce yet another value for the gic version (nosel).
4
As we already use exotic values such as 0 and -1, let's introduce
5
a dedicated enum type and let vms->gic_version take this
6
type.
7
8
Signed-off-by: Eric Auger <eric.auger@redhat.com>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
11
Reviewed-by: Andrew Jones <drjones@redhat.com>
12
Message-id: 20200311131618.7187-3-eric.auger@redhat.com
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Message-id: 1505240046-11454-13-git-send-email-peter.maydell@linaro.org
13
---
14
---
14
hw/intc/armv7m_nvic.c | 23 ++++++++++++-----------
15
include/hw/arm/virt.h | 11 +++++++++--
15
1 file changed, 12 insertions(+), 11 deletions(-)
16
hw/arm/virt.c | 30 +++++++++++++++---------------
17
2 files changed, 24 insertions(+), 17 deletions(-)
16
18
17
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
19
diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h
18
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
19
--- a/hw/intc/armv7m_nvic.c
21
--- a/include/hw/arm/virt.h
20
+++ b/hw/intc/armv7m_nvic.c
22
+++ b/include/hw/arm/virt.h
21
@@ -XXX,XX +XXX,XX @@ void armv7m_nvic_set_pending(void *opaque, int irq, bool secure)
23
@@ -XXX,XX +XXX,XX @@ typedef enum VirtIOMMUType {
24
VIRT_IOMMU_VIRTIO,
25
} VirtIOMMUType;
26
27
+typedef enum VirtGICType {
28
+ VIRT_GIC_VERSION_MAX,
29
+ VIRT_GIC_VERSION_HOST,
30
+ VIRT_GIC_VERSION_2,
31
+ VIRT_GIC_VERSION_3,
32
+} VirtGICType;
33
+
34
typedef struct MemMapEntry {
35
hwaddr base;
36
hwaddr size;
37
@@ -XXX,XX +XXX,XX @@ typedef struct {
38
bool highmem_ecam;
39
bool its;
40
bool virt;
41
- int32_t gic_version;
42
+ VirtGICType gic_version;
43
VirtIOMMUType iommu;
44
uint16_t virtio_iommu_bdf;
45
struct arm_boot_info bootinfo;
46
@@ -XXX,XX +XXX,XX @@ static inline int virt_gicv3_redist_region_count(VirtMachineState *vms)
47
uint32_t redist0_capacity =
48
vms->memmap[VIRT_GIC_REDIST].size / GICV3_REDIST_SIZE;
49
50
- assert(vms->gic_version == 3);
51
+ assert(vms->gic_version == VIRT_GIC_VERSION_3);
52
53
return vms->smp_cpus > redist0_capacity ? 2 : 1;
54
}
55
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
56
index XXXXXXX..XXXXXXX 100644
57
--- a/hw/arm/virt.c
58
+++ b/hw/arm/virt.c
59
@@ -XXX,XX +XXX,XX @@ static void fdt_add_timer_nodes(const VirtMachineState *vms)
60
irqflags = GIC_FDT_IRQ_FLAGS_EDGE_LO_HI;
61
}
62
63
- if (vms->gic_version == 2) {
64
+ if (vms->gic_version == VIRT_GIC_VERSION_2) {
65
irqflags = deposit32(irqflags, GIC_FDT_IRQ_PPI_CPU_START,
66
GIC_FDT_IRQ_PPI_CPU_WIDTH,
67
(1 << vms->smp_cpus) - 1);
68
@@ -XXX,XX +XXX,XX @@ static void fdt_add_gic_node(VirtMachineState *vms)
69
qemu_fdt_setprop_cell(vms->fdt, nodename, "#address-cells", 0x2);
70
qemu_fdt_setprop_cell(vms->fdt, nodename, "#size-cells", 0x2);
71
qemu_fdt_setprop(vms->fdt, nodename, "ranges", NULL, 0);
72
- if (vms->gic_version == 3) {
73
+ if (vms->gic_version == VIRT_GIC_VERSION_3) {
74
int nb_redist_regions = virt_gicv3_redist_region_count(vms);
75
76
qemu_fdt_setprop_string(vms->fdt, nodename, "compatible",
77
@@ -XXX,XX +XXX,XX @@ static void fdt_add_pmu_nodes(const VirtMachineState *vms)
22
}
78
}
23
79
}
24
if (escalate) {
80
25
- if (running < 0) {
81
- if (vms->gic_version == 2) {
26
- /* We want to escalate to HardFault but we can't take a
82
+ if (vms->gic_version == VIRT_GIC_VERSION_2) {
27
- * synchronous HardFault at this point either. This is a
83
irqflags = deposit32(irqflags, GIC_FDT_IRQ_PPI_CPU_START,
28
- * Lockup condition due to a guest bug. We don't model
84
GIC_FDT_IRQ_PPI_CPU_WIDTH,
29
- * Lockup, so report via cpu_abort() instead.
85
(1 << vms->smp_cpus) - 1);
30
- */
86
@@ -XXX,XX +XXX,XX @@ static uint64_t virt_cpu_mp_affinity(VirtMachineState *vms, int idx)
31
- cpu_abort(&s->cpu->parent_obj,
87
* purposes are to make TCG consistent (with 64-bit KVM hosts)
32
- "Lockup: can't escalate %d to HardFault "
88
* and to improve SGI efficiency.
33
- "(current priority %d)\n", irq, running);
89
*/
34
- }
90
- if (vms->gic_version == 3) {
35
91
+ if (vms->gic_version == VIRT_GIC_VERSION_3) {
36
- /* We can do the escalation, so we take HardFault instead.
92
clustersz = GICV3_TARGETLIST_BITS;
37
+ /* We need to escalate this exception to a synchronous HardFault.
93
} else {
38
* If BFHFNMINS is set then we escalate to the banked HF for
94
clustersz = GIC_TARGETLIST_BITS;
39
* the target security state of the original exception; otherwise
95
@@ -XXX,XX +XXX,XX @@ static void machvirt_init(MachineState *machine)
40
* we take a Secure HardFault.
96
/* We can probe only here because during property set
41
@@ -XXX,XX +XXX,XX @@ void armv7m_nvic_set_pending(void *opaque, int irq, bool secure)
97
* KVM is not available yet
98
*/
99
- if (vms->gic_version <= 0) {
100
- /* "host" or "max" */
101
+ if (vms->gic_version == VIRT_GIC_VERSION_HOST ||
102
+ vms->gic_version == VIRT_GIC_VERSION_MAX) {
103
if (!kvm_enabled()) {
104
- if (vms->gic_version == 0) {
105
+ if (vms->gic_version == VIRT_GIC_VERSION_HOST) {
106
error_report("gic-version=host requires KVM");
107
exit(1);
42
} else {
108
} else {
43
vec = &s->vectors[irq];
109
/* "max": currently means 3 for TCG */
110
- vms->gic_version = 3;
111
+ vms->gic_version = VIRT_GIC_VERSION_3;
44
}
112
}
45
+ if (running <= vec->prio) {
113
} else {
46
+ /* We want to escalate to HardFault but we can't take the
114
vms->gic_version = kvm_arm_vgic_probe();
47
+ * synchronous HardFault at this point either. This is a
115
@@ -XXX,XX +XXX,XX @@ static void machvirt_init(MachineState *machine)
48
+ * Lockup condition due to a guest bug. We don't model
116
/* The maximum number of CPUs depends on the GIC version, or on how
49
+ * Lockup, so report via cpu_abort() instead.
117
* many redistributors we can fit into the memory map.
50
+ */
118
*/
51
+ cpu_abort(&s->cpu->parent_obj,
119
- if (vms->gic_version == 3) {
52
+ "Lockup: can't escalate %d to HardFault "
120
+ if (vms->gic_version == VIRT_GIC_VERSION_3) {
53
+ "(current priority %d)\n", irq, running);
121
virt_max_cpus =
54
+ }
122
vms->memmap[VIRT_GIC_REDIST].size / GICV3_REDIST_SIZE;
55
+
123
virt_max_cpus +=
56
/* HF may be banked but there is only one shared HFSR */
124
@@ -XXX,XX +XXX,XX @@ static void virt_set_its(Object *obj, bool value, Error **errp)
57
s->cpu->env.v7m.hfsr |= R_V7M_HFSR_FORCED_MASK;
125
static char *virt_get_gic_version(Object *obj, Error **errp)
58
}
126
{
127
VirtMachineState *vms = VIRT_MACHINE(obj);
128
- const char *val = vms->gic_version == 3 ? "3" : "2";
129
+ const char *val = vms->gic_version == VIRT_GIC_VERSION_3 ? "3" : "2";
130
131
return g_strdup(val);
132
}
133
@@ -XXX,XX +XXX,XX @@ static void virt_set_gic_version(Object *obj, const char *value, Error **errp)
134
VirtMachineState *vms = VIRT_MACHINE(obj);
135
136
if (!strcmp(value, "3")) {
137
- vms->gic_version = 3;
138
+ vms->gic_version = VIRT_GIC_VERSION_3;
139
} else if (!strcmp(value, "2")) {
140
- vms->gic_version = 2;
141
+ vms->gic_version = VIRT_GIC_VERSION_2;
142
} else if (!strcmp(value, "host")) {
143
- vms->gic_version = 0; /* Will probe later */
144
+ vms->gic_version = VIRT_GIC_VERSION_HOST; /* Will probe later */
145
} else if (!strcmp(value, "max")) {
146
- vms->gic_version = -1; /* Will probe later */
147
+ vms->gic_version = VIRT_GIC_VERSION_MAX; /* Will probe later */
148
} else {
149
error_setg(errp, "Invalid gic-version value");
150
error_append_hint(errp, "Valid values are 3, 2, host, max.\n");
151
@@ -XXX,XX +XXX,XX @@ static void virt_instance_init(Object *obj)
152
"physical address space above 32 bits",
153
NULL);
154
/* Default GIC type is v2 */
155
- vms->gic_version = 2;
156
+ vms->gic_version = VIRT_GIC_VERSION_2;
157
object_property_add_str(obj, "gic-version", virt_get_gic_version,
158
virt_set_gic_version, NULL);
159
object_property_set_description(obj, "gic-version",
59
--
160
--
60
2.7.4
161
2.20.1
61
162
62
163
diff view generated by jsdifflib
1
Don't use the old_mmio in the memory region ops struct.
1
From: Eric Auger <eric.auger@redhat.com>
2
2
3
Let's move the code which freezes which gic-version to
4
be applied in a dedicated function. We also now set by
5
default the VIRT_GIC_VERSION_NO_SET. This eventually
6
turns into the legacy v2 choice in the finalize() function.
7
8
Signed-off-by: Eric Auger <eric.auger@redhat.com>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
Reviewed-by: Andrew Jones <drjones@redhat.com>
11
Message-id: 20200311131618.7187-4-eric.auger@redhat.com
3
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
Message-id: 1505580378-9044-4-git-send-email-peter.maydell@linaro.org
6
---
13
---
7
hw/timer/omap_synctimer.c | 35 +++++++++++++++++++++--------------
14
include/hw/arm/virt.h | 1 +
8
1 file changed, 21 insertions(+), 14 deletions(-)
15
hw/arm/virt.c | 54 ++++++++++++++++++++++++++-----------------
16
2 files changed, 34 insertions(+), 21 deletions(-)
9
17
10
diff --git a/hw/timer/omap_synctimer.c b/hw/timer/omap_synctimer.c
18
diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h
11
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
12
--- a/hw/timer/omap_synctimer.c
20
--- a/include/hw/arm/virt.h
13
+++ b/hw/timer/omap_synctimer.c
21
+++ b/include/hw/arm/virt.h
14
@@ -XXX,XX +XXX,XX @@ static uint32_t omap_synctimer_readh(void *opaque, hwaddr addr)
22
@@ -XXX,XX +XXX,XX @@ typedef enum VirtGICType {
23
VIRT_GIC_VERSION_HOST,
24
VIRT_GIC_VERSION_2,
25
VIRT_GIC_VERSION_3,
26
+ VIRT_GIC_VERSION_NOSEL,
27
} VirtGICType;
28
29
typedef struct MemMapEntry {
30
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
31
index XXXXXXX..XXXXXXX 100644
32
--- a/hw/arm/virt.c
33
+++ b/hw/arm/virt.c
34
@@ -XXX,XX +XXX,XX @@ static void virt_set_memmap(VirtMachineState *vms)
15
}
35
}
16
}
36
}
17
37
18
-static void omap_synctimer_write(void *opaque, hwaddr addr,
38
+/*
19
- uint32_t value)
39
+ * finalize_gic_version - Determines the final gic_version
20
+static uint64_t omap_synctimer_readfn(void *opaque, hwaddr addr,
40
+ * according to the gic-version property
21
+ unsigned size)
41
+ *
42
+ * Default GIC type is v2
43
+ */
44
+static void finalize_gic_version(VirtMachineState *vms)
22
+{
45
+{
23
+ switch (size) {
46
+ if (vms->gic_version == VIRT_GIC_VERSION_HOST ||
24
+ case 1:
47
+ vms->gic_version == VIRT_GIC_VERSION_MAX) {
25
+ return omap_badwidth_read32(opaque, addr);
48
+ if (!kvm_enabled()) {
26
+ case 2:
49
+ if (vms->gic_version == VIRT_GIC_VERSION_HOST) {
27
+ return omap_synctimer_readh(opaque, addr);
50
+ error_report("gic-version=host requires KVM");
28
+ case 4:
51
+ exit(1);
29
+ return omap_synctimer_readw(opaque, addr);
52
+ } else {
30
+ default:
53
+ /* "max": currently means 3 for TCG */
31
+ g_assert_not_reached();
54
+ vms->gic_version = VIRT_GIC_VERSION_3;
55
+ }
56
+ } else {
57
+ vms->gic_version = kvm_arm_vgic_probe();
58
+ if (!vms->gic_version) {
59
+ error_report(
60
+ "Unable to determine GIC version supported by host");
61
+ exit(1);
62
+ }
63
+ }
64
+ } else if (vms->gic_version == VIRT_GIC_VERSION_NOSEL) {
65
+ vms->gic_version = VIRT_GIC_VERSION_2;
32
+ }
66
+ }
33
+}
67
+}
34
+
68
+
35
+static void omap_synctimer_writefn(void *opaque, hwaddr addr,
69
static void machvirt_init(MachineState *machine)
36
+ uint64_t value, unsigned size)
37
{
70
{
38
OMAP_BAD_REG(addr);
71
VirtMachineState *vms = VIRT_MACHINE(machine);
39
}
72
@@ -XXX,XX +XXX,XX @@ static void machvirt_init(MachineState *machine)
40
73
/* We can probe only here because during property set
41
static const MemoryRegionOps omap_synctimer_ops = {
74
* KVM is not available yet
42
- .old_mmio = {
75
*/
43
- .read = {
76
- if (vms->gic_version == VIRT_GIC_VERSION_HOST ||
44
- omap_badwidth_read32,
77
- vms->gic_version == VIRT_GIC_VERSION_MAX) {
45
- omap_synctimer_readh,
78
- if (!kvm_enabled()) {
46
- omap_synctimer_readw,
79
- if (vms->gic_version == VIRT_GIC_VERSION_HOST) {
47
- },
80
- error_report("gic-version=host requires KVM");
48
- .write = {
81
- exit(1);
49
- omap_badwidth_write32,
82
- } else {
50
- omap_synctimer_write,
83
- /* "max": currently means 3 for TCG */
51
- omap_synctimer_write,
84
- vms->gic_version = VIRT_GIC_VERSION_3;
52
- },
85
- }
53
- },
86
- } else {
54
+ .read = omap_synctimer_readfn,
87
- vms->gic_version = kvm_arm_vgic_probe();
55
+ .write = omap_synctimer_writefn,
88
- if (!vms->gic_version) {
56
+ .valid.min_access_size = 1,
89
- error_report(
57
+ .valid.max_access_size = 4,
90
- "Unable to determine GIC version supported by host");
58
.endianness = DEVICE_NATIVE_ENDIAN,
91
- exit(1);
59
};
92
- }
60
93
- }
94
- }
95
+ finalize_gic_version(vms);
96
97
if (!cpu_type_valid(machine->cpu_type)) {
98
error_report("mach-virt: CPU type %s not supported", machine->cpu_type);
99
@@ -XXX,XX +XXX,XX @@ static void virt_instance_init(Object *obj)
100
"Set on/off to enable/disable using "
101
"physical address space above 32 bits",
102
NULL);
103
- /* Default GIC type is v2 */
104
- vms->gic_version = VIRT_GIC_VERSION_2;
105
+ vms->gic_version = VIRT_GIC_VERSION_NOSEL;
106
object_property_add_str(obj, "gic-version", virt_get_gic_version,
107
virt_set_gic_version, NULL);
108
object_property_set_description(obj, "gic-version",
61
--
109
--
62
2.7.4
110
2.20.1
63
111
64
112
diff view generated by jsdifflib
1
For v8M, the NVIC has a new set of registers per interrupt,
1
From: Eric Auger <eric.auger@redhat.com>
2
NVIC_ITNS<n>. These determine whether the interrupt targets Secure
3
or Non-secure state. Implement the register read/write code for
4
these, and make them cause NVIC_IABR, NVIC_ICER, NVIC_ISER,
5
NVIC_ICPR, NVIC_IPR and NVIC_ISPR to RAZ/WI for non-secure
6
accesses to fields corresponding to interrupts which are
7
configured to target secure state.
8
2
3
Convert kvm_arm_vgic_probe() so that it returns a
4
bitmap of supported in-kernel emulation VGIC versions instead
5
of the max version: at the moment values can be v2 and v3.
6
This allows to expose the case where the host GICv3 also
7
supports GICv2 emulation. This will be useful to choose the
8
default version in KVM accelerated mode.
9
10
Signed-off-by: Eric Auger <eric.auger@redhat.com>
11
Reviewed-by: Andrew Jones <drjones@redhat.com>
12
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
13
Message-id: 20200311131618.7187-5-eric.auger@redhat.com
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
11
Message-id: 1505240046-11454-8-git-send-email-peter.maydell@linaro.org
12
---
15
---
13
include/hw/intc/armv7m_nvic.h | 3 ++
16
target/arm/kvm_arm.h | 3 +++
14
hw/intc/armv7m_nvic.c | 74 +++++++++++++++++++++++++++++++++++++++----
17
hw/arm/virt.c | 11 +++++++++--
15
2 files changed, 70 insertions(+), 7 deletions(-)
18
target/arm/kvm.c | 14 ++++++++------
19
3 files changed, 20 insertions(+), 8 deletions(-)
16
20
17
diff --git a/include/hw/intc/armv7m_nvic.h b/include/hw/intc/armv7m_nvic.h
21
diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h
18
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
19
--- a/include/hw/intc/armv7m_nvic.h
23
--- a/target/arm/kvm_arm.h
20
+++ b/include/hw/intc/armv7m_nvic.h
24
+++ b/target/arm/kvm_arm.h
21
@@ -XXX,XX +XXX,XX @@ typedef struct NVICState {
25
@@ -XXX,XX +XXX,XX @@
22
/* The PRIGROUP field in AIRCR is banked */
26
#include "exec/memory.h"
23
uint32_t prigroup[M_REG_NUM_BANKS];
27
#include "qemu/error-report.h"
24
28
25
+ /* v8M NVIC_ITNS state (stored as a bool per bit) */
29
+#define KVM_ARM_VGIC_V2 (1 << 0)
26
+ bool itns[NVIC_MAX_VECTORS];
30
+#define KVM_ARM_VGIC_V3 (1 << 1)
27
+
31
+
28
/* The following fields are all cached state that can be recalculated
32
/**
29
* from the vectors[] and sec_vectors[] arrays and the prigroup field:
33
* kvm_arm_vcpu_init:
30
* - vectpending
34
* @cs: CPUState
31
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
35
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
32
index XXXXXXX..XXXXXXX 100644
36
index XXXXXXX..XXXXXXX 100644
33
--- a/hw/intc/armv7m_nvic.c
37
--- a/hw/arm/virt.c
34
+++ b/hw/intc/armv7m_nvic.c
38
+++ b/hw/arm/virt.c
35
@@ -XXX,XX +XXX,XX @@ static uint32_t nvic_readl(NVICState *s, uint32_t offset, MemTxAttrs attrs)
39
@@ -XXX,XX +XXX,XX @@ static void finalize_gic_version(VirtMachineState *vms)
36
switch (offset) {
40
vms->gic_version = VIRT_GIC_VERSION_3;
37
case 4: /* Interrupt Control Type. */
41
}
38
return ((s->num_irq - NVIC_FIRST_IRQ) / 32) - 1;
42
} else {
39
+ case 0x380 ... 0x3bf: /* NVIC_ITNS<n> */
43
- vms->gic_version = kvm_arm_vgic_probe();
40
+ {
44
- if (!vms->gic_version) {
41
+ int startvec = 32 * (offset - 0x380) + NVIC_FIRST_IRQ;
45
+ int probe_bitmap = kvm_arm_vgic_probe();
42
+ int i;
43
+
46
+
44
+ if (!arm_feature(&cpu->env, ARM_FEATURE_V8)) {
47
+ if (!probe_bitmap) {
45
+ goto bad_offset;
48
error_report(
46
+ }
49
"Unable to determine GIC version supported by host");
47
+ if (!attrs.secure) {
50
exit(1);
48
+ return 0;
51
+ } else {
49
+ }
52
+ if (probe_bitmap & KVM_ARM_VGIC_V3) {
50
+ val = 0;
53
+ vms->gic_version = VIRT_GIC_VERSION_3;
51
+ for (i = 0; i < 32 && startvec + i < s->num_irq; i++) {
54
+ } else {
52
+ if (s->itns[startvec + i]) {
55
+ vms->gic_version = VIRT_GIC_VERSION_2;
53
+ val |= (1 << i);
56
+ }
54
+ }
55
+ }
56
+ return val;
57
+ }
58
case 0xd00: /* CPUID Base. */
59
return cpu->midr;
60
case 0xd04: /* Interrupt Control State. */
61
@@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value,
62
ARMCPU *cpu = s->cpu;
63
64
switch (offset) {
65
+ case 0x380 ... 0x3bf: /* NVIC_ITNS<n> */
66
+ {
67
+ int startvec = 32 * (offset - 0x380) + NVIC_FIRST_IRQ;
68
+ int i;
69
+
70
+ if (!arm_feature(&cpu->env, ARM_FEATURE_V8)) {
71
+ goto bad_offset;
72
+ }
73
+ if (!attrs.secure) {
74
+ break;
75
+ }
76
+ for (i = 0; i < 32 && startvec + i < s->num_irq; i++) {
77
+ s->itns[startvec + i] = (value >> i) & 1;
78
+ }
79
+ nvic_irq_update(s);
80
+ break;
81
+ }
82
case 0xd04: /* Interrupt Control State. */
83
if (value & (1 << 31)) {
84
armv7m_nvic_set_pending(s, ARMV7M_EXCP_NMI);
85
@@ -XXX,XX +XXX,XX @@ static MemTxResult nvic_sysreg_read(void *opaque, hwaddr addr,
86
startvec = offset - 0x180 + NVIC_FIRST_IRQ; /* vector # */
87
88
for (i = 0, end = size * 8; i < end && startvec + i < s->num_irq; i++) {
89
- if (s->vectors[startvec + i].enabled) {
90
+ if (s->vectors[startvec + i].enabled &&
91
+ (attrs.secure || s->itns[startvec + i])) {
92
val |= (1 << i);
93
}
57
}
94
}
58
}
95
@@ -XXX,XX +XXX,XX @@ static MemTxResult nvic_sysreg_read(void *opaque, hwaddr addr,
59
} else if (vms->gic_version == VIRT_GIC_VERSION_NOSEL) {
96
val = 0;
60
diff --git a/target/arm/kvm.c b/target/arm/kvm.c
97
startvec = offset - 0x280 + NVIC_FIRST_IRQ; /* vector # */
61
index XXXXXXX..XXXXXXX 100644
98
for (i = 0, end = size * 8; i < end && startvec + i < s->num_irq; i++) {
62
--- a/target/arm/kvm.c
99
- if (s->vectors[startvec + i].pending) {
63
+++ b/target/arm/kvm.c
100
+ if (s->vectors[startvec + i].pending &&
64
@@ -XXX,XX +XXX,XX @@ int kvm_arch_irqchip_create(KVMState *s)
101
+ (attrs.secure || s->itns[startvec + i])) {
65
102
val |= (1 << i);
66
int kvm_arm_vgic_probe(void)
103
}
67
{
104
}
68
+ int val = 0;
105
@@ -XXX,XX +XXX,XX @@ static MemTxResult nvic_sysreg_read(void *opaque, hwaddr addr,
69
+
106
startvec = offset - 0x300 + NVIC_FIRST_IRQ; /* vector # */
70
if (kvm_create_device(kvm_state,
107
71
KVM_DEV_TYPE_ARM_VGIC_V3, true) == 0) {
108
for (i = 0, end = size * 8; i < end && startvec + i < s->num_irq; i++) {
72
- return 3;
109
- if (s->vectors[startvec + i].active) {
73
- } else if (kvm_create_device(kvm_state,
110
+ if (s->vectors[startvec + i].active &&
74
- KVM_DEV_TYPE_ARM_VGIC_V2, true) == 0) {
111
+ (attrs.secure || s->itns[startvec + i])) {
75
- return 2;
112
val |= (1 << i);
76
- } else {
113
}
77
- return 0;
114
}
78
+ val |= KVM_ARM_VGIC_V3;
115
@@ -XXX,XX +XXX,XX @@ static MemTxResult nvic_sysreg_read(void *opaque, hwaddr addr,
116
startvec = offset - 0x400 + NVIC_FIRST_IRQ; /* vector # */
117
118
for (i = 0; i < size && startvec + i < s->num_irq; i++) {
119
- val |= s->vectors[startvec + i].prio << (8 * i);
120
+ if (attrs.secure || s->itns[startvec + i]) {
121
+ val |= s->vectors[startvec + i].prio << (8 * i);
122
+ }
123
}
124
break;
125
case 0xd18 ... 0xd23: /* System Handler Priority. */
126
@@ -XXX,XX +XXX,XX @@ static MemTxResult nvic_sysreg_write(void *opaque, hwaddr addr,
127
startvec = 8 * (offset - 0x180) + NVIC_FIRST_IRQ;
128
129
for (i = 0, end = size * 8; i < end && startvec + i < s->num_irq; i++) {
130
- if (value & (1 << i)) {
131
+ if (value & (1 << i) &&
132
+ (attrs.secure || s->itns[startvec + i])) {
133
s->vectors[startvec + i].enabled = setval;
134
}
135
}
136
@@ -XXX,XX +XXX,XX @@ static MemTxResult nvic_sysreg_write(void *opaque, hwaddr addr,
137
startvec = 8 * (offset - 0x280) + NVIC_FIRST_IRQ; /* vector # */
138
139
for (i = 0, end = size * 8; i < end && startvec + i < s->num_irq; i++) {
140
- if (value & (1 << i)) {
141
+ if (value & (1 << i) &&
142
+ (attrs.secure || s->itns[startvec + i])) {
143
s->vectors[startvec + i].pending = setval;
144
}
145
}
146
@@ -XXX,XX +XXX,XX @@ static MemTxResult nvic_sysreg_write(void *opaque, hwaddr addr,
147
startvec = 8 * (offset - 0x400) + NVIC_FIRST_IRQ; /* vector # */
148
149
for (i = 0; i < size && startvec + i < s->num_irq; i++) {
150
- set_prio(s, startvec + i, (value >> (i * 8)) & 0xff);
151
+ if (attrs.secure || s->itns[startvec + i]) {
152
+ set_prio(s, startvec + i, (value >> (i * 8)) & 0xff);
153
+ }
154
}
155
nvic_irq_update(s);
156
return MEMTX_OK;
157
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_nvic_security = {
158
VMSTATE_STRUCT_ARRAY(sec_vectors, NVICState, NVIC_INTERNAL_VECTORS, 1,
159
vmstate_VecInfo, VecInfo),
160
VMSTATE_UINT32(prigroup[M_REG_S], NVICState),
161
+ VMSTATE_BOOL_ARRAY(itns, NVICState, NVIC_MAX_VECTORS),
162
VMSTATE_END_OF_LIST()
163
}
79
}
164
};
80
+ if (kvm_create_device(kvm_state,
165
@@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_reset(DeviceState *dev)
81
+ KVM_DEV_TYPE_ARM_VGIC_V2, true) == 0) {
166
s->vectpending = 0;
82
+ val |= KVM_ARM_VGIC_V2;
167
s->vectpending_is_s_banked = false;
168
s->vectpending_prio = NVIC_NOEXC_PRIO;
169
+
170
+ if (arm_feature(&s->cpu->env, ARM_FEATURE_M_SECURITY)) {
171
+ memset(s->itns, 0, sizeof(s->itns));
172
+ } else {
173
+ /* This state is constant and not guest accessible in a non-security
174
+ * NVIC; we set the bits to true to avoid having to do a feature
175
+ * bit check in the NVIC enable/pend/etc register accessors.
176
+ */
177
+ int i;
178
+
179
+ for (i = NVIC_FIRST_IRQ; i < ARRAY_SIZE(s->itns); i++) {
180
+ s->itns[i] = true;
181
+ }
182
+ }
83
+ }
84
+ return val;
183
}
85
}
184
86
185
static void nvic_systick_trigger(void *opaque, int n, int level)
87
int kvm_arm_set_irq(int cpu, int irqtype, int irq, int level)
186
--
88
--
187
2.7.4
89
2.20.1
188
90
189
91
diff view generated by jsdifflib
1
Make the set_prio() function take a bool indicating
1
From: Eric Auger <eric.auger@redhat.com>
2
whether to pend the secure or non-secure version of a banked
3
interrupt, and use this to implement the correct banking
4
semantics for the SHPR registers.
5
2
3
Restructure the finalize_gic_version with switch cases and
4
clearly separate the following cases:
5
6
- KVM mode / in-kernel irqchip
7
- KVM mode / userspace irqchip
8
- TCG mode
9
10
In KVM mode / in-kernel irqchip , we explictly check whether
11
the chosen version is supported by the host. If the end-user
12
explicitly sets v2/v3 and this is not supported by the host,
13
then the user gets an explicit error message. Note that for
14
old kernels where the CREATE_DEVICE ioctl doesn't exist then
15
we will now fail if the user specifically asked for gicv2,
16
where previously we (probably) would have succeeded.
17
18
In KVM mode / userspace irqchip we immediatly output an error
19
in case the end-user explicitly selected v3. Also we warn the
20
end-user about the unexpected usage of gic-version=host in
21
that case as only userspace GICv2 is supported.
22
23
Signed-off-by: Eric Auger <eric.auger@redhat.com>
24
Reviewed-by: Andrew Jones <drjones@redhat.com>
25
Message-id: 20200311131618.7187-6-eric.auger@redhat.com
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
26
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 1505240046-11454-11-git-send-email-peter.maydell@linaro.org
9
---
27
---
10
hw/intc/armv7m_nvic.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++-----
28
hw/arm/virt.c | 88 +++++++++++++++++++++++++++++++++++++++------------
11
hw/intc/trace-events | 2 +-
29
1 file changed, 67 insertions(+), 21 deletions(-)
12
2 files changed, 88 insertions(+), 10 deletions(-)
13
30
14
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
31
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
15
index XXXXXXX..XXXXXXX 100644
32
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/intc/armv7m_nvic.c
33
--- a/hw/arm/virt.c
17
+++ b/hw/intc/armv7m_nvic.c
34
+++ b/hw/arm/virt.c
18
@@ -XXX,XX +XXX,XX @@ int armv7m_nvic_raw_execution_priority(void *opaque)
35
@@ -XXX,XX +XXX,XX @@ static void virt_set_memmap(VirtMachineState *vms)
19
return s->exception_prio;
36
*/
20
}
37
static void finalize_gic_version(VirtMachineState *vms)
21
22
-/* caller must call nvic_irq_update() after this */
23
-static void set_prio(NVICState *s, unsigned irq, uint8_t prio)
24
+/* caller must call nvic_irq_update() after this.
25
+ * secure indicates the bank to use for banked exceptions (we assert if
26
+ * we are passed secure=true for a non-banked exception).
27
+ */
28
+static void set_prio(NVICState *s, unsigned irq, bool secure, uint8_t prio)
29
{
38
{
30
assert(irq > ARMV7M_EXCP_NMI); /* only use for configurable prios */
39
- if (vms->gic_version == VIRT_GIC_VERSION_HOST ||
31
assert(irq < s->num_irq);
40
- vms->gic_version == VIRT_GIC_VERSION_MAX) {
32
41
- if (!kvm_enabled()) {
33
- s->vectors[irq].prio = prio;
42
- if (vms->gic_version == VIRT_GIC_VERSION_HOST) {
34
+ if (secure) {
43
- error_report("gic-version=host requires KVM");
35
+ assert(exc_is_banked(irq));
44
- exit(1);
36
+ s->sec_vectors[irq].prio = prio;
45
- } else {
37
+ } else {
46
- /* "max": currently means 3 for TCG */
38
+ s->vectors[irq].prio = prio;
47
- vms->gic_version = VIRT_GIC_VERSION_3;
48
- }
49
- } else {
50
- int probe_bitmap = kvm_arm_vgic_probe();
51
+ if (kvm_enabled()) {
52
+ int probe_bitmap;
53
54
- if (!probe_bitmap) {
55
+ if (!kvm_irqchip_in_kernel()) {
56
+ switch (vms->gic_version) {
57
+ case VIRT_GIC_VERSION_HOST:
58
+ warn_report(
59
+ "gic-version=host not relevant with kernel-irqchip=off "
60
+ "as only userspace GICv2 is supported. Using v2 ...");
61
+ return;
62
+ case VIRT_GIC_VERSION_MAX:
63
+ case VIRT_GIC_VERSION_NOSEL:
64
+ vms->gic_version = VIRT_GIC_VERSION_2;
65
+ return;
66
+ case VIRT_GIC_VERSION_2:
67
+ return;
68
+ case VIRT_GIC_VERSION_3:
69
error_report(
70
- "Unable to determine GIC version supported by host");
71
+ "gic-version=3 is not supported with kernel-irqchip=off");
72
exit(1);
73
- } else {
74
- if (probe_bitmap & KVM_ARM_VGIC_V3) {
75
- vms->gic_version = VIRT_GIC_VERSION_3;
76
- } else {
77
- vms->gic_version = VIRT_GIC_VERSION_2;
78
- }
79
}
80
}
81
- } else if (vms->gic_version == VIRT_GIC_VERSION_NOSEL) {
82
+
83
+ probe_bitmap = kvm_arm_vgic_probe();
84
+ if (!probe_bitmap) {
85
+ error_report("Unable to determine GIC version supported by host");
86
+ exit(1);
87
+ }
88
+
89
+ switch (vms->gic_version) {
90
+ case VIRT_GIC_VERSION_HOST:
91
+ case VIRT_GIC_VERSION_MAX:
92
+ if (probe_bitmap & KVM_ARM_VGIC_V3) {
93
+ vms->gic_version = VIRT_GIC_VERSION_3;
94
+ } else {
95
+ vms->gic_version = VIRT_GIC_VERSION_2;
96
+ }
97
+ return;
98
+ case VIRT_GIC_VERSION_NOSEL:
99
+ vms->gic_version = VIRT_GIC_VERSION_2;
100
+ break;
101
+ case VIRT_GIC_VERSION_2:
102
+ case VIRT_GIC_VERSION_3:
103
+ break;
104
+ }
105
+
106
+ /* Check chosen version is effectively supported by the host */
107
+ if (vms->gic_version == VIRT_GIC_VERSION_2 &&
108
+ !(probe_bitmap & KVM_ARM_VGIC_V2)) {
109
+ error_report("host does not support in-kernel GICv2 emulation");
110
+ exit(1);
111
+ } else if (vms->gic_version == VIRT_GIC_VERSION_3 &&
112
+ !(probe_bitmap & KVM_ARM_VGIC_V3)) {
113
+ error_report("host does not support in-kernel GICv3 emulation");
114
+ exit(1);
115
+ }
116
+ return;
39
+ }
117
+ }
40
+
118
+
41
+ trace_nvic_set_prio(irq, secure, prio);
119
+ /* TCG mode */
42
+}
120
+ switch (vms->gic_version) {
43
+
121
+ case VIRT_GIC_VERSION_NOSEL:
44
+/* Return the current raw priority register value.
122
vms->gic_version = VIRT_GIC_VERSION_2;
45
+ * secure indicates the bank to use for banked exceptions (we assert if
123
+ break;
46
+ * we are passed secure=true for a non-banked exception).
124
+ case VIRT_GIC_VERSION_MAX:
47
+ */
125
+ vms->gic_version = VIRT_GIC_VERSION_3;
48
+static int get_prio(NVICState *s, unsigned irq, bool secure)
126
+ break;
49
+{
127
+ case VIRT_GIC_VERSION_HOST:
50
+ assert(irq > ARMV7M_EXCP_NMI); /* only use for configurable prios */
128
+ error_report("gic-version=host requires KVM");
51
+ assert(irq < s->num_irq);
129
+ exit(1);
52
130
+ case VIRT_GIC_VERSION_2:
53
- trace_nvic_set_prio(irq, prio);
131
+ case VIRT_GIC_VERSION_3:
54
+ if (secure) {
132
+ break;
55
+ assert(exc_is_banked(irq));
56
+ return s->sec_vectors[irq].prio;
57
+ } else {
58
+ return s->vectors[irq].prio;
59
+ }
60
}
61
62
/* Recompute state and assert irq line accordingly.
63
@@ -XXX,XX +XXX,XX @@ static bool nvic_user_access_ok(NVICState *s, hwaddr offset, MemTxAttrs attrs)
64
}
133
}
65
}
134
}
66
135
67
+static int shpr_bank(NVICState *s, int exc, MemTxAttrs attrs)
68
+{
69
+ /* Behaviour for the SHPR register field for this exception:
70
+ * return M_REG_NS to use the nonsecure vector (including for
71
+ * non-banked exceptions), M_REG_S for the secure version of
72
+ * a banked exception, and -1 if this field should RAZ/WI.
73
+ */
74
+ switch (exc) {
75
+ case ARMV7M_EXCP_MEM:
76
+ case ARMV7M_EXCP_USAGE:
77
+ case ARMV7M_EXCP_SVC:
78
+ case ARMV7M_EXCP_PENDSV:
79
+ case ARMV7M_EXCP_SYSTICK:
80
+ /* Banked exceptions */
81
+ return attrs.secure;
82
+ case ARMV7M_EXCP_BUS:
83
+ /* Not banked, RAZ/WI from nonsecure if BFHFNMINS is zero */
84
+ if (!attrs.secure &&
85
+ !(s->cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK)) {
86
+ return -1;
87
+ }
88
+ return M_REG_NS;
89
+ case ARMV7M_EXCP_SECURE:
90
+ /* Not banked, RAZ/WI from nonsecure */
91
+ if (!attrs.secure) {
92
+ return -1;
93
+ }
94
+ return M_REG_NS;
95
+ case ARMV7M_EXCP_DEBUG:
96
+ /* Not banked. TODO should RAZ/WI if DEMCR.SDME is set */
97
+ return M_REG_NS;
98
+ case 8 ... 10:
99
+ case 13:
100
+ /* RES0 */
101
+ return -1;
102
+ default:
103
+ /* Not reachable due to decode of SHPR register addresses */
104
+ g_assert_not_reached();
105
+ }
106
+}
107
+
108
static MemTxResult nvic_sysreg_read(void *opaque, hwaddr addr,
109
uint64_t *data, unsigned size,
110
MemTxAttrs attrs)
111
@@ -XXX,XX +XXX,XX @@ static MemTxResult nvic_sysreg_read(void *opaque, hwaddr addr,
112
}
113
}
114
break;
115
- case 0xd18 ... 0xd23: /* System Handler Priority. */
116
+ case 0xd18 ... 0xd23: /* System Handler Priority (SHPR1, SHPR2, SHPR3) */
117
val = 0;
118
for (i = 0; i < size; i++) {
119
- val |= s->vectors[(offset - 0xd14) + i].prio << (i * 8);
120
+ unsigned hdlidx = (offset - 0xd14) + i;
121
+ int sbank = shpr_bank(s, hdlidx, attrs);
122
+
123
+ if (sbank < 0) {
124
+ continue;
125
+ }
126
+ val = deposit32(val, i * 8, 8, get_prio(s, hdlidx, sbank));
127
}
128
break;
129
case 0xfe0 ... 0xfff: /* ID. */
130
@@ -XXX,XX +XXX,XX @@ static MemTxResult nvic_sysreg_write(void *opaque, hwaddr addr,
131
132
for (i = 0; i < size && startvec + i < s->num_irq; i++) {
133
if (attrs.secure || s->itns[startvec + i]) {
134
- set_prio(s, startvec + i, (value >> (i * 8)) & 0xff);
135
+ set_prio(s, startvec + i, false, (value >> (i * 8)) & 0xff);
136
}
137
}
138
nvic_irq_update(s);
139
return MEMTX_OK;
140
- case 0xd18 ... 0xd23: /* System Handler Priority. */
141
+ case 0xd18 ... 0xd23: /* System Handler Priority (SHPR1, SHPR2, SHPR3) */
142
for (i = 0; i < size; i++) {
143
unsigned hdlidx = (offset - 0xd14) + i;
144
- set_prio(s, hdlidx, (value >> (i * 8)) & 0xff);
145
+ int newprio = extract32(value, i * 8, 8);
146
+ int sbank = shpr_bank(s, hdlidx, attrs);
147
+
148
+ if (sbank < 0) {
149
+ continue;
150
+ }
151
+ set_prio(s, hdlidx, sbank, newprio);
152
}
153
nvic_irq_update(s);
154
return MEMTX_OK;
155
diff --git a/hw/intc/trace-events b/hw/intc/trace-events
156
index XXXXXXX..XXXXXXX 100644
157
--- a/hw/intc/trace-events
158
+++ b/hw/intc/trace-events
159
@@ -XXX,XX +XXX,XX @@ gicv3_redist_send_sgi(uint32_t cpu, int irq) "GICv3 redistributor 0x%x pending S
160
# hw/intc/armv7m_nvic.c
161
nvic_recompute_state(int vectpending, int vectpending_prio, int exception_prio) "NVIC state recomputed: vectpending %d vectpending_prio %d exception_prio %d"
162
nvic_recompute_state_secure(int vectpending, bool vectpending_is_s_banked, int vectpending_prio, int exception_prio) "NVIC state recomputed: vectpending %d is_s_banked %d vectpending_prio %d exception_prio %d"
163
-nvic_set_prio(int irq, uint8_t prio) "NVIC set irq %d priority %d"
164
+nvic_set_prio(int irq, bool secure, uint8_t prio) "NVIC set irq %d secure-bank %d priority %d"
165
nvic_irq_update(int vectpending, int pendprio, int exception_prio, int level) "NVIC vectpending %d pending prio %d exception_prio %d: setting irq line to %d"
166
nvic_escalate_prio(int irq, int irqprio, int runprio) "NVIC escalating irq %d to HardFault: insufficient priority %d >= %d"
167
nvic_escalate_disabled(int irq) "NVIC escalating irq %d to HardFault: disabled"
168
--
136
--
169
2.7.4
137
2.20.1
170
138
171
139
diff view generated by jsdifflib
1
In armv7m_nvic_set_pending() we have to compare the
1
From: Eric Auger <eric.auger@redhat.com>
2
priority of an exception against the execution priority
3
to decide whether it needs to be escalated to HardFault.
4
In the specification this is a comparison against the
5
exception's group priority; for v7M we implemented it
6
as a comparison against the raw exception priority
7
because the two comparisons will always give the
8
same answer. For v8M the existence of AIRCR.PRIS and
9
the possibility of different PRIGROUP values for secure
10
and nonsecure exceptions means we need to explicitly
11
calculate the vector's group priority for this check.
12
2
3
At the moment if the end-user does not specify the gic-version along
4
with KVM acceleration, v2 is set by default. However most of the
5
systems now have GICv3 and sometimes they do not support GICv2
6
compatibility.
7
8
This patch keeps the default v2 selection in all cases except
9
in the KVM accelerated mode when either
10
- the host does not support GICv2 in-kernel emulation or
11
- number of VCPUS exceeds 8.
12
13
Those cases did not work anyway so we do not break any compatibility.
14
Now we get v3 selected in such a case.
15
16
Signed-off-by: Eric Auger <eric.auger@redhat.com>
17
Reported-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
18
Reviewed-by: Andrew Jones <drjones@redhat.com>
19
Message-id: 20200311131618.7187-7-eric.auger@redhat.com
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
20
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
15
Message-id: 1505240046-11454-12-git-send-email-peter.maydell@linaro.org
16
---
21
---
17
hw/intc/armv7m_nvic.c | 2 +-
22
hw/arm/virt.c | 17 ++++++++++++++++-
18
1 file changed, 1 insertion(+), 1 deletion(-)
23
1 file changed, 16 insertions(+), 1 deletion(-)
19
24
20
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
25
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
21
index XXXXXXX..XXXXXXX 100644
26
index XXXXXXX..XXXXXXX 100644
22
--- a/hw/intc/armv7m_nvic.c
27
--- a/hw/arm/virt.c
23
+++ b/hw/intc/armv7m_nvic.c
28
+++ b/hw/arm/virt.c
24
@@ -XXX,XX +XXX,XX @@ void armv7m_nvic_set_pending(void *opaque, int irq, bool secure)
29
@@ -XXX,XX +XXX,XX @@ static void virt_set_memmap(VirtMachineState *vms)
25
int running = nvic_exec_prio(s);
30
*/
26
bool escalate = false;
31
static void finalize_gic_version(VirtMachineState *vms)
27
32
{
28
- if (vec->prio >= running) {
33
+ unsigned int max_cpus = MACHINE(vms)->smp.max_cpus;
29
+ if (exc_group_prio(s, vec->prio, secure) >= running) {
34
+
30
trace_nvic_escalate_prio(irq, vec->prio, running);
35
if (kvm_enabled()) {
31
escalate = true;
36
int probe_bitmap;
32
} else if (!vec->enabled) {
37
38
@@ -XXX,XX +XXX,XX @@ static void finalize_gic_version(VirtMachineState *vms)
39
}
40
return;
41
case VIRT_GIC_VERSION_NOSEL:
42
- vms->gic_version = VIRT_GIC_VERSION_2;
43
+ if ((probe_bitmap & KVM_ARM_VGIC_V2) && max_cpus <= GIC_NCPU) {
44
+ vms->gic_version = VIRT_GIC_VERSION_2;
45
+ } else if (probe_bitmap & KVM_ARM_VGIC_V3) {
46
+ /*
47
+ * in case the host does not support v2 in-kernel emulation or
48
+ * the end-user requested more than 8 VCPUs we now default
49
+ * to v3. In any case defaulting to v2 would be broken.
50
+ */
51
+ vms->gic_version = VIRT_GIC_VERSION_3;
52
+ } else if (max_cpus > GIC_NCPU) {
53
+ error_report("host only supports in-kernel GICv2 emulation "
54
+ "but more than 8 vcpus are requested");
55
+ exit(1);
56
+ }
57
break;
58
case VIRT_GIC_VERSION_2:
59
case VIRT_GIC_VERSION_3:
33
--
60
--
34
2.7.4
61
2.20.1
35
62
36
63
diff view generated by jsdifflib
1
In v8M the MSR and MRS instructions have extra register value
1
From: Beata Michalska <beata.michalska@linaro.org>
2
encodings to allow secure code to access the non-secure banked
3
version of various special registers.
4
2
5
(We don't implement the MSPLIM_NS or PSPLIM_NS aliases, because
3
KVM_SET_VCPU_EVENTS might actually lead to vcpu registers being modified.
6
we don't currently implement the stack limit registers at all.)
4
As such this should be the last step of sync to avoid potential overwriting
5
of whatever changes KVM might have done.
7
6
7
Signed-off-by: Beata Michalska <beata.michalska@linaro.org>
8
Reviewed-by: Andrew Jones <drjones@redhat.com>
9
Message-id: 20200312003401.29017-2-beata.michalska@linaro.org
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>
10
Message-id: 1505240046-11454-2-git-send-email-peter.maydell@linaro.org
11
---
11
---
12
target/arm/helper.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++
12
target/arm/kvm32.c | 15 ++++++++++-----
13
1 file changed, 110 insertions(+)
13
target/arm/kvm64.c | 15 ++++++++++-----
14
2 files changed, 20 insertions(+), 10 deletions(-)
14
15
15
diff --git a/target/arm/helper.c b/target/arm/helper.c
16
diff --git a/target/arm/kvm32.c b/target/arm/kvm32.c
16
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
17
--- a/target/arm/helper.c
18
--- a/target/arm/kvm32.c
18
+++ b/target/arm/helper.c
19
+++ b/target/arm/kvm32.c
19
@@ -XXX,XX +XXX,XX @@ uint32_t HELPER(v7m_mrs)(CPUARMState *env, uint32_t reg)
20
@@ -XXX,XX +XXX,XX @@ int kvm_arch_put_registers(CPUState *cs, int level)
20
break;
21
return ret;
21
case 20: /* CONTROL */
22
return env->v7m.control[env->v7m.secure];
23
+ case 0x94: /* CONTROL_NS */
24
+ /* We have to handle this here because unprivileged Secure code
25
+ * can read the NS CONTROL register.
26
+ */
27
+ if (!env->v7m.secure) {
28
+ return 0;
29
+ }
30
+ return env->v7m.control[M_REG_NS];
31
}
22
}
32
23
33
if (el == 0) {
24
- ret = kvm_put_vcpu_events(cpu);
34
return 0; /* unprivileged reads others as zero */
25
- if (ret) {
26
- return ret;
27
- }
28
-
29
write_cpustate_to_list(cpu, true);
30
31
if (!write_list_to_kvmstate(cpu, level)) {
32
return EINVAL;
35
}
33
}
36
34
37
+ if (arm_feature(env, ARM_FEATURE_M_SECURITY)) {
35
+ /*
38
+ switch (reg) {
36
+ * Setting VCPU events should be triggered after syncing the registers
39
+ case 0x88: /* MSP_NS */
37
+ * to avoid overwriting potential changes made by KVM upon calling
40
+ if (!env->v7m.secure) {
38
+ * KVM_SET_VCPU_EVENTS ioctl
41
+ return 0;
39
+ */
42
+ }
40
+ ret = kvm_put_vcpu_events(cpu);
43
+ return env->v7m.other_ss_msp;
41
+ if (ret) {
44
+ case 0x89: /* PSP_NS */
42
+ return ret;
45
+ if (!env->v7m.secure) {
46
+ return 0;
47
+ }
48
+ return env->v7m.other_ss_psp;
49
+ case 0x90: /* PRIMASK_NS */
50
+ if (!env->v7m.secure) {
51
+ return 0;
52
+ }
53
+ return env->v7m.primask[M_REG_NS];
54
+ case 0x91: /* BASEPRI_NS */
55
+ if (!env->v7m.secure) {
56
+ return 0;
57
+ }
58
+ return env->v7m.basepri[M_REG_NS];
59
+ case 0x93: /* FAULTMASK_NS */
60
+ if (!env->v7m.secure) {
61
+ return 0;
62
+ }
63
+ return env->v7m.faultmask[M_REG_NS];
64
+ case 0x98: /* SP_NS */
65
+ {
66
+ /* This gives the non-secure SP selected based on whether we're
67
+ * currently in handler mode or not, using the NS CONTROL.SPSEL.
68
+ */
69
+ bool spsel = env->v7m.control[M_REG_NS] & R_V7M_CONTROL_SPSEL_MASK;
70
+
71
+ if (!env->v7m.secure) {
72
+ return 0;
73
+ }
74
+ if (!arm_v7m_is_handler_mode(env) && spsel) {
75
+ return env->v7m.other_ss_psp;
76
+ } else {
77
+ return env->v7m.other_ss_msp;
78
+ }
79
+ }
80
+ default:
81
+ break;
82
+ }
83
+ }
43
+ }
84
+
44
+
85
switch (reg) {
45
kvm_arm_sync_mpstate_to_kvm(cpu);
86
case 8: /* MSP */
46
87
return (env->v7m.control[env->v7m.secure] & R_V7M_CONTROL_SPSEL_MASK) ?
47
return ret;
88
@@ -XXX,XX +XXX,XX @@ void HELPER(v7m_msr)(CPUARMState *env, uint32_t maskreg, uint32_t val)
48
diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c
89
return;
49
index XXXXXXX..XXXXXXX 100644
50
--- a/target/arm/kvm64.c
51
+++ b/target/arm/kvm64.c
52
@@ -XXX,XX +XXX,XX @@ int kvm_arch_put_registers(CPUState *cs, int level)
53
return ret;
90
}
54
}
91
55
92
+ if (arm_feature(env, ARM_FEATURE_M_SECURITY)) {
56
- ret = kvm_put_vcpu_events(cpu);
93
+ switch (reg) {
57
- if (ret) {
94
+ case 0x88: /* MSP_NS */
58
- return ret;
95
+ if (!env->v7m.secure) {
59
- }
96
+ return;
60
-
97
+ }
61
write_cpustate_to_list(cpu, true);
98
+ env->v7m.other_ss_msp = val;
62
99
+ return;
63
if (!write_list_to_kvmstate(cpu, level)) {
100
+ case 0x89: /* PSP_NS */
64
return -EINVAL;
101
+ if (!env->v7m.secure) {
65
}
102
+ return;
66
103
+ }
67
+ /*
104
+ env->v7m.other_ss_psp = val;
68
+ * Setting VCPU events should be triggered after syncing the registers
105
+ return;
69
+ * to avoid overwriting potential changes made by KVM upon calling
106
+ case 0x90: /* PRIMASK_NS */
70
+ * KVM_SET_VCPU_EVENTS ioctl
107
+ if (!env->v7m.secure) {
71
+ */
108
+ return;
72
+ ret = kvm_put_vcpu_events(cpu);
109
+ }
73
+ if (ret) {
110
+ env->v7m.primask[M_REG_NS] = val & 1;
74
+ return ret;
111
+ return;
112
+ case 0x91: /* BASEPRI_NS */
113
+ if (!env->v7m.secure) {
114
+ return;
115
+ }
116
+ env->v7m.basepri[M_REG_NS] = val & 0xff;
117
+ return;
118
+ case 0x93: /* FAULTMASK_NS */
119
+ if (!env->v7m.secure) {
120
+ return;
121
+ }
122
+ env->v7m.faultmask[M_REG_NS] = val & 1;
123
+ return;
124
+ case 0x98: /* SP_NS */
125
+ {
126
+ /* This gives the non-secure SP selected based on whether we're
127
+ * currently in handler mode or not, using the NS CONTROL.SPSEL.
128
+ */
129
+ bool spsel = env->v7m.control[M_REG_NS] & R_V7M_CONTROL_SPSEL_MASK;
130
+
131
+ if (!env->v7m.secure) {
132
+ return;
133
+ }
134
+ if (!arm_v7m_is_handler_mode(env) && spsel) {
135
+ env->v7m.other_ss_psp = val;
136
+ } else {
137
+ env->v7m.other_ss_msp = val;
138
+ }
139
+ return;
140
+ }
141
+ default:
142
+ break;
143
+ }
144
+ }
75
+ }
145
+
76
+
146
switch (reg) {
77
kvm_arm_sync_mpstate_to_kvm(cpu);
147
case 0 ... 7: /* xPSR sub-fields */
78
148
/* only APSR is actually writable */
79
return ret;
149
--
80
--
150
2.7.4
81
2.20.1
151
82
152
83
diff view generated by jsdifflib