1
target-arm queue for softfreeze: this is quite big as I
1
arm queue; dunno if this will be the last before softfreeze
2
was on holiday last week, so this is all just sneaking in
2
or not, but anyway probably the last large one. New orangepi-pc
3
under the wire. I particularly wanted to get Philippe's
3
board model is the big item here.
4
patches in before freeze as that sort of code-movement
5
patchset is painful to have to rebase.
6
4
7
thanks
5
thanks
8
-- PMM
6
-- PMM
9
7
10
The following changes since commit ae9108f8f0746ce64d02afb1a216153a50926132:
8
The following changes since commit 67d9ef7d541c3d21a25796c51c26da096a433565:
11
9
12
Merge remote-tracking branch 'remotes/vivier2/tags/linux-user-for-4.1-pull-request' into staging (2019-07-01 15:55:40 +0100)
10
Merge remote-tracking branch 'remotes/pmaydell/tags/pull-docs-20200312' into staging (2020-03-12 15:20:52 +0000)
13
11
14
are available in the Git repository at:
12
are available in the Git repository at:
15
13
16
https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20190701
14
https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20200312
17
15
18
for you to fetch changes up to 787a7e76c2e93a48c47b324fea592c9910a70483:
16
for you to fetch changes up to aca53be34ac3e7cac5f39396a51a338860a5a837:
19
17
20
target/arm: Declare some M-profile functions publicly (2019-07-01 17:29:01 +0100)
18
target/arm: kvm: Inject events at the last stage of sync (2020-03-12 16:31:10 +0000)
21
19
22
----------------------------------------------------------------
20
----------------------------------------------------------------
23
target-arm queue:
21
target-arm queue:
24
* hw/arm/boot: fix direct kernel boot with initrd
22
* Fix various bugs that might result in an assert() due to
25
* hw/arm/msf2-som: Exit when the cpu is not the expected one
23
incorrect hflags for M-profile CPUs
26
* i.mx7: fix bugs in PCI controller needed to boot recent kernels
24
* Fix Aspeed SMC Controller user-mode select handling
27
* aspeed: add RTC device
25
* Report correct (with-tag) address in fault address register
28
* aspeed: fix some timer device bugs
26
when TBI is enabled
29
* aspeed: add swift-bmc board
27
* cubieboard: make sure SOC object isn't leaked
30
* aspeed: vic: Add support for legacy register interface
28
* fsl-imx25: Wire up eSDHC controllers
31
* aspeed: add aspeed-xdma device
29
* fsl-imx25: Wire up USB controllers
32
* Add new sbsa-ref board for aarch64
30
* New board model: orangepi-pc (OrangePi PC)
33
* target/arm: code refactoring in preparation for support of
31
* ARM/KVM: if user doesn't select GIC version and the
34
compilation with TCG disabled
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
35
35
36
----------------------------------------------------------------
36
----------------------------------------------------------------
37
Adriana Kobylak (1):
37
Beata Michalska (1):
38
aspeed: Add support for the swift-bmc board
38
target/arm: kvm: Inject events at the last stage of sync
39
39
40
Andrew Jeffery (3):
40
Cédric Le Goater (2):
41
aspeed/timer: Status register contains reload for stopped timer
41
aspeed/smc: Add some tracing
42
aspeed/timer: Fix match calculations
42
aspeed/smc: Fix User mode select/unselect scheme
43
aspeed: vic: Add support for legacy register interface
44
43
45
Andrew Jones (1):
44
Eric Auger (6):
46
hw/arm/boot: fix direct kernel boot with initrd
45
hw/arm/virt: Document 'max' value in gic-version property description
46
hw/arm/virt: Introduce VirtGICType enum type
47
hw/arm/virt: Introduce finalize_gic_version()
48
target/arm/kvm: Let kvm_arm_vgic_probe() return a bitmap
49
hw/arm/virt: kvm: Restructure finalize_gic_version()
50
hw/arm/virt: kvm: allow gicv3 by default if v2 cannot work
47
51
48
Andrey Smirnov (5):
52
Guenter Roeck (2):
49
i.mx7d: Add no-op/unimplemented APBH DMA module
53
hw/arm/fsl-imx25: Wire up eSDHC controllers
50
i.mx7d: Add no-op/unimplemented PCIE PHY IP block
54
hw/arm/fsl-imx25: Wire up USB controllers
51
pci: designware: Update MSI mapping unconditionally
52
pci: designware: Update MSI mapping when MSI address changes
53
i.mx7d: pci: Update PCI IRQ mapping to match HW
54
55
55
Christian Svensson (1):
56
Igor Mammedov (1):
56
aspeed/timer: Ensure positive muldiv delta
57
hw/arm/cubieboard: make sure SOC object isn't leaked
57
58
58
Cédric Le Goater (7):
59
Niek Linnenbank (13):
59
aspeed: add a per SoC mapping for the interrupt space
60
hw/arm: add Allwinner H3 System-on-Chip
60
aspeed: add a per SoC mapping for the memory space
61
hw/arm: add Xunlong Orange Pi PC machine
61
aspeed: introduce a configurable number of CPU per machine
62
hw/arm/allwinner-h3: add Clock Control Unit
62
aspeed: add support for multiple NICs
63
hw/arm/allwinner-h3: add USB host controller
63
aspeed: remove the "ram" link
64
hw/arm/allwinner-h3: add System Control module
64
aspeed: add a RAM memory region container
65
hw/arm/allwinner: add CPU Configuration module
65
aspeed/smc: add a 'sdram_base' property
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
66
73
67
Eddie James (1):
74
Peter Maydell (4):
68
hw/misc/aspeed_xdma: New device
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
69
79
70
Hongbo Zhang (2):
80
Philippe Mathieu-Daudé (5):
71
hw/arm: Add arm SBSA reference machine, skeleton part
81
tests/boot_linux_console: Add a quick test for the OrangePi PC board
72
hw/arm: Add arm SBSA reference machine, devices part
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
73
86
74
Jan Kiszka (1):
87
Richard Henderson (2):
75
hw/arm/virt: Add support for Cortex-A7
88
target/arm: Check addresses for disabled regimes
89
target/arm: Disable clean_data_tbi for system mode
76
90
77
Joel Stanley (4):
91
Makefile.objs | 1 +
78
hw: timer: Add ASPEED RTC device
92
hw/arm/Makefile.objs | 1 +
79
hw/arm/aspeed: Add RTC to SoC
93
hw/misc/Makefile.objs | 5 +
80
aspeed/timer: Fix behaviour running Linux
94
hw/net/Makefile.objs | 1 +
81
aspeed: Link SCU to the watchdog
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
82
170
83
Philippe Mathieu-Daudé (19):
84
hw/arm/msf2-som: Exit when the cpu is not the expected one
85
target/arm: Makefile cleanup (Aarch64)
86
target/arm: Makefile cleanup (ARM)
87
target/arm: Makefile cleanup (KVM)
88
target/arm: Makefile cleanup (softmmu)
89
target/arm: Add copyright boilerplate
90
target/arm/helper: Remove unused include
91
target/arm: Fix multiline comment syntax
92
target/arm: Fix coding style issues
93
target/arm: Move CPU state dumping routines to cpu.c
94
target/arm: Declare get_phys_addr() function publicly
95
target/arm: Move TLB related routines to tlb_helper.c
96
target/arm/vfp_helper: Move code around
97
target/arm/vfp_helper: Extract vfp_set_fpscr_to_host()
98
target/arm/vfp_helper: Extract vfp_set_fpscr_from_host()
99
target/arm/vfp_helper: Restrict the SoftFloat use to TCG
100
target/arm: Restrict PSCI to TCG
101
target/arm: Declare arm_log_exception() function publicly
102
target/arm: Declare some M-profile functions publicly
103
104
Samuel Ortiz (1):
105
target/arm: Move the DC ZVA helper into op_helper
106
107
hw/arm/Makefile.objs | 1 +
108
hw/misc/Makefile.objs | 1 +
109
hw/timer/Makefile.objs | 2 +-
110
target/arm/Makefile.objs | 24 +-
111
include/hw/arm/aspeed_soc.h | 53 ++-
112
include/hw/arm/fsl-imx7.h | 14 +-
113
include/hw/misc/aspeed_xdma.h | 30 ++
114
include/hw/ssi/aspeed_smc.h | 3 +
115
include/hw/timer/aspeed_rtc.h | 31 ++
116
include/hw/watchdog/wdt_aspeed.h | 1 +
117
target/arm/cpu.h | 2 -
118
target/arm/internals.h | 69 ++-
119
target/arm/translate.h | 5 -
120
hw/arm/aspeed.c | 76 +++-
121
hw/arm/aspeed_soc.c | 262 +++++++++---
122
hw/arm/boot.c | 3 +-
123
hw/arm/fsl-imx7.c | 11 +
124
hw/arm/msf2-som.c | 1 +
125
hw/arm/sbsa-ref.c | 806 ++++++++++++++++++++++++++++++++++++
126
hw/arm/virt.c | 1 +
127
hw/intc/aspeed_vic.c | 105 +++--
128
hw/misc/aspeed_xdma.c | 165 ++++++++
129
hw/pci-host/designware.c | 18 +-
130
hw/ssi/aspeed_smc.c | 1 +
131
hw/timer/aspeed_rtc.c | 180 ++++++++
132
hw/timer/aspeed_timer.c | 76 ++--
133
hw/watchdog/wdt_aspeed.c | 20 +
134
target/arm/cpu.c | 232 ++++++++++-
135
target/arm/helper.c | 498 +++++++++-------------
136
target/arm/op_helper.c | 262 ++++++------
137
target/arm/tlb_helper.c | 200 +++++++++
138
target/arm/translate-a64.c | 128 ------
139
target/arm/translate.c | 91 +---
140
target/arm/vfp_helper.c | 199 +++++----
141
MAINTAINERS | 8 +
142
default-configs/aarch64-softmmu.mak | 1 +
143
hw/arm/Kconfig | 14 +
144
hw/misc/trace-events | 3 +
145
hw/timer/trace-events | 4 +
146
39 files changed, 2675 insertions(+), 926 deletions(-)
147
create mode 100644 include/hw/misc/aspeed_xdma.h
148
create mode 100644 include/hw/timer/aspeed_rtc.h
149
create mode 100644 hw/arm/sbsa-ref.c
150
create mode 100644 hw/misc/aspeed_xdma.c
151
create mode 100644 hw/timer/aspeed_rtc.c
152
create mode 100644 target/arm/tlb_helper.c
153
diff view generated by jsdifflib
1
From: Andrey Smirnov <andrew.smirnov@gmail.com>
1
Some of an M-profile CPU's cached hflags state depends on state that's
2
in our NVIC object. We already do an hflags rebuild when the NVIC
3
registers are written, but we also need to do this on NVIC reset,
4
because there's no guarantee that this will happen before the
5
CPU reset.
2
6
3
Instantiate no-op APBH DMA module. Needed to boot latest Linux kernel.
7
This fixes an assertion due to mismatched hflags which happens if
8
the CPU is reset from inside a HardFault handler.
4
9
5
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
6
Cc: Peter Maydell <peter.maydell@linaro.org>
7
Cc: Michael S. Tsirkin <mst@redhat.com>
8
Cc: qemu-devel@nongnu.org
9
Cc: qemu-arm@nongnu.org
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Message-id: 20200303174950.3298-2-peter.maydell@linaro.org
12
---
13
---
13
include/hw/arm/fsl-imx7.h | 3 +++
14
hw/intc/armv7m_nvic.c | 6 ++++++
14
hw/arm/fsl-imx7.c | 6 ++++++
15
1 file changed, 6 insertions(+)
15
2 files changed, 9 insertions(+)
16
16
17
diff --git a/include/hw/arm/fsl-imx7.h b/include/hw/arm/fsl-imx7.h
17
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
18
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
19
--- a/include/hw/arm/fsl-imx7.h
19
--- a/hw/intc/armv7m_nvic.c
20
+++ b/include/hw/arm/fsl-imx7.h
20
+++ b/hw/intc/armv7m_nvic.c
21
@@ -XXX,XX +XXX,XX @@ enum FslIMX7MemoryMap {
21
@@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_reset(DeviceState *dev)
22
FSL_IMX7_PCIE_REG_SIZE = 16 * 1024,
22
s->itns[i] = true;
23
23
}
24
FSL_IMX7_GPR_ADDR = 0x30340000,
24
}
25
+
26
+ FSL_IMX7_DMA_APBH_ADDR = 0x33000000,
27
+ FSL_IMX7_DMA_APBH_SIZE = 0x2000,
28
};
29
30
enum FslIMX7IRQs {
31
diff --git a/hw/arm/fsl-imx7.c b/hw/arm/fsl-imx7.c
32
index XXXXXXX..XXXXXXX 100644
33
--- a/hw/arm/fsl-imx7.c
34
+++ b/hw/arm/fsl-imx7.c
35
@@ -XXX,XX +XXX,XX @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp)
36
*/
37
create_unimplemented_device("lcdif", FSL_IMX7_LCDIF_ADDR,
38
FSL_IMX7_LCDIF_SIZE);
39
+
25
+
40
+ /*
26
+ /*
41
+ * DMA APBH
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.
42
+ */
29
+ */
43
+ create_unimplemented_device("dma-apbh", FSL_IMX7_DMA_APBH_ADDR,
30
+ arm_rebuild_hflags(&s->cpu->env);
44
+ FSL_IMX7_DMA_APBH_SIZE);
45
}
31
}
46
32
47
static void fsl_imx7_class_init(ObjectClass *oc, void *data)
33
static void nvic_systick_trigger(void *opaque, int n, int level)
48
--
34
--
49
2.20.1
35
2.20.1
50
36
51
37
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
1
For M-profile CPUs, the FAULTMASK value affects the CPU's MMU index
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().
2
5
3
Since we'll move this code around, fix its style first.
4
5
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
6
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
7
Message-id: 20190701132516.26392-9-philmd@redhat.com
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20200303174950.3298-3-peter.maydell@linaro.org
9
---
9
---
10
target/arm/translate.c | 11 ++++++-----
10
target/arm/translate.c | 5 ++++-
11
target/arm/vfp_helper.c | 36 ++++++++++++++++++++++++------------
11
1 file changed, 4 insertions(+), 1 deletion(-)
12
2 files changed, 30 insertions(+), 17 deletions(-)
13
12
14
diff --git a/target/arm/translate.c b/target/arm/translate.c
13
diff --git a/target/arm/translate.c b/target/arm/translate.c
15
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
16
--- a/target/arm/translate.c
15
--- a/target/arm/translate.c
17
+++ b/target/arm/translate.c
16
+++ b/target/arm/translate.c
18
@@ -XXX,XX +XXX,XX @@ static void disas_arm_insn(DisasContext *s, unsigned int insn)
17
@@ -XXX,XX +XXX,XX @@ static bool trans_CPS(DisasContext *s, arg_CPS *a)
19
loaded_base = 0;
18
20
loaded_var = NULL;
19
static bool trans_CPS_v7m(DisasContext *s, arg_CPS_v7m *a)
21
n = 0;
20
{
22
- for(i=0;i<16;i++) {
21
- TCGv_i32 tmp, addr;
23
+ for (i = 0; i < 16; i++) {
22
+ TCGv_i32 tmp, addr, el;
24
if (insn & (1 << i))
23
25
n++;
24
if (!arm_dc_feature(s, ARM_FEATURE_M)) {
26
}
25
return false;
27
@@ -XXX,XX +XXX,XX @@ static void disas_arm_insn(DisasContext *s, unsigned int insn)
26
@@ -XXX,XX +XXX,XX @@ static bool trans_CPS_v7m(DisasContext *s, arg_CPS_v7m *a)
28
}
27
gen_helper_v7m_msr(cpu_env, addr, tmp);
29
}
28
tcg_temp_free_i32(addr);
30
j = 0;
31
- for(i=0;i<16;i++) {
32
+ for (i = 0; i < 16; i++) {
33
if (insn & (1 << i)) {
34
if (is_load) {
35
/* load */
36
@@ -XXX,XX +XXX,XX @@ void arm_cpu_dump_state(CPUState *cs, FILE *f, int flags)
37
return;
38
}
29
}
39
30
+ el = tcg_const_i32(s->current_el);
40
- for(i=0;i<16;i++) {
31
+ gen_helper_rebuild_hflags_m32(cpu_env, el);
41
+ for (i = 0; i < 16; i++) {
32
+ tcg_temp_free_i32(el);
42
qemu_fprintf(f, "R%02d=%08x", i, env->regs[i]);
33
tcg_temp_free_i32(tmp);
43
- if ((i % 4) == 3)
34
gen_lookup_tb(s);
44
+ if ((i % 4) == 3) {
35
return true;
45
qemu_fprintf(f, "\n");
46
- else
47
+ } else {
48
qemu_fprintf(f, " ");
49
+ }
50
}
51
52
if (arm_feature(env, ARM_FEATURE_M)) {
53
diff --git a/target/arm/vfp_helper.c b/target/arm/vfp_helper.c
54
index XXXXXXX..XXXXXXX 100644
55
--- a/target/arm/vfp_helper.c
56
+++ b/target/arm/vfp_helper.c
57
@@ -XXX,XX +XXX,XX @@ static inline int vfp_exceptbits_from_host(int host_bits)
58
{
59
int target_bits = 0;
60
61
- if (host_bits & float_flag_invalid)
62
+ if (host_bits & float_flag_invalid) {
63
target_bits |= 1;
64
- if (host_bits & float_flag_divbyzero)
65
+ }
66
+ if (host_bits & float_flag_divbyzero) {
67
target_bits |= 2;
68
- if (host_bits & float_flag_overflow)
69
+ }
70
+ if (host_bits & float_flag_overflow) {
71
target_bits |= 4;
72
- if (host_bits & (float_flag_underflow | float_flag_output_denormal))
73
+ }
74
+ if (host_bits & (float_flag_underflow | float_flag_output_denormal)) {
75
target_bits |= 8;
76
- if (host_bits & float_flag_inexact)
77
+ }
78
+ if (host_bits & float_flag_inexact) {
79
target_bits |= 0x10;
80
- if (host_bits & float_flag_input_denormal)
81
+ }
82
+ if (host_bits & float_flag_input_denormal) {
83
target_bits |= 0x80;
84
+ }
85
return target_bits;
86
}
87
88
@@ -XXX,XX +XXX,XX @@ static inline int vfp_exceptbits_to_host(int target_bits)
89
{
90
int host_bits = 0;
91
92
- if (target_bits & 1)
93
+ if (target_bits & 1) {
94
host_bits |= float_flag_invalid;
95
- if (target_bits & 2)
96
+ }
97
+ if (target_bits & 2) {
98
host_bits |= float_flag_divbyzero;
99
- if (target_bits & 4)
100
+ }
101
+ if (target_bits & 4) {
102
host_bits |= float_flag_overflow;
103
- if (target_bits & 8)
104
+ }
105
+ if (target_bits & 8) {
106
host_bits |= float_flag_underflow;
107
- if (target_bits & 0x10)
108
+ }
109
+ if (target_bits & 0x10) {
110
host_bits |= float_flag_inexact;
111
- if (target_bits & 0x80)
112
+ }
113
+ if (target_bits & 0x80) {
114
host_bits |= float_flag_input_denormal;
115
+ }
116
return host_bits;
117
}
118
119
--
36
--
120
2.20.1
37
2.20.1
121
38
122
39
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
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.
2
5
3
In few commits we will split the M-profile functions from this
6
Add a new helper rebuild_hflags_m32_newel() which, like the
4
file, and this function will also be called in the new file.
7
existing rebuild_hflags_a32_newel(), recalculates the current
5
Declare it in the "internals.h" header.
8
EL from scratch, and use it in trans_MSR_v7m().
6
Since it is in the middle of a block of M profile functions,
7
move it previous to this block to ease the later refactor.
8
9
9
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
10
This fixes an assertion about an hflags mismatch when the
10
Message-id: 20190701132516.26392-21-philmd@redhat.com
11
guest changes privilege by writing to CONTROL.
11
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
12
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
15
Message-id: 20200303174950.3298-4-peter.maydell@linaro.org
13
---
16
---
14
target/arm/internals.h | 2 ++
17
target/arm/helper.h | 1 +
15
target/arm/helper.c | 76 +++++++++++++++++++++---------------------
18
target/arm/helper.c | 12 ++++++++++++
16
2 files changed, 40 insertions(+), 38 deletions(-)
19
target/arm/translate.c | 7 +++----
20
3 files changed, 16 insertions(+), 4 deletions(-)
17
21
18
diff --git a/target/arm/internals.h b/target/arm/internals.h
22
diff --git a/target/arm/helper.h b/target/arm/helper.h
19
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
20
--- a/target/arm/internals.h
24
--- a/target/arm/helper.h
21
+++ b/target/arm/internals.h
25
+++ b/target/arm/helper.h
22
@@ -XXX,XX +XXX,XX @@ bool get_phys_addr(CPUARMState *env, target_ulong address,
26
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_4(msr_banked, void, env, i32, i32, i32)
23
target_ulong *page_size,
27
DEF_HELPER_2(get_user_reg, i32, env, i32)
24
ARMMMUFaultInfo *fi, ARMCacheAttrs *cacheattrs);
28
DEF_HELPER_3(set_user_reg, void, env, i32, i32)
25
29
26
+void arm_log_exception(int idx);
30
+DEF_HELPER_FLAGS_1(rebuild_hflags_m32_newel, TCG_CALL_NO_RWG, void, env)
27
+
31
DEF_HELPER_FLAGS_2(rebuild_hflags_m32, TCG_CALL_NO_RWG, void, env, int)
28
#endif /* !CONFIG_USER_ONLY */
32
DEF_HELPER_FLAGS_1(rebuild_hflags_a32_newel, TCG_CALL_NO_RWG, void, env)
29
33
DEF_HELPER_FLAGS_2(rebuild_hflags_a32, TCG_CALL_NO_RWG, void, env, int)
30
#endif
31
diff --git a/target/arm/helper.c b/target/arm/helper.c
34
diff --git a/target/arm/helper.c b/target/arm/helper.c
32
index XXXXXXX..XXXXXXX 100644
35
index XXXXXXX..XXXXXXX 100644
33
--- a/target/arm/helper.c
36
--- a/target/arm/helper.c
34
+++ b/target/arm/helper.c
37
+++ b/target/arm/helper.c
35
@@ -XXX,XX +XXX,XX @@ uint32_t arm_phys_excp_target_el(CPUState *cs, uint32_t excp_idx,
38
@@ -XXX,XX +XXX,XX @@ void arm_rebuild_hflags(CPUARMState *env)
36
return target_el;
39
env->hflags = rebuild_hflags_internal(env);
37
}
40
}
38
41
39
+void arm_log_exception(int idx)
42
+/*
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)
40
+{
47
+{
41
+ if (qemu_loglevel_mask(CPU_LOG_INT)) {
48
+ int el = arm_current_el(env);
42
+ const char *exc = NULL;
49
+ int fp_el = fp_exception_el(env, el);
43
+ static const char * const excnames[] = {
50
+ ARMMMUIdx mmu_idx = arm_mmu_idx_el(env, el);
44
+ [EXCP_UDEF] = "Undefined Instruction",
51
+ env->hflags = rebuild_hflags_m32(env, fp_el, mmu_idx);
45
+ [EXCP_SWI] = "SVC",
46
+ [EXCP_PREFETCH_ABORT] = "Prefetch Abort",
47
+ [EXCP_DATA_ABORT] = "Data Abort",
48
+ [EXCP_IRQ] = "IRQ",
49
+ [EXCP_FIQ] = "FIQ",
50
+ [EXCP_BKPT] = "Breakpoint",
51
+ [EXCP_EXCEPTION_EXIT] = "QEMU v7M exception exit",
52
+ [EXCP_KERNEL_TRAP] = "QEMU intercept of kernel commpage",
53
+ [EXCP_HVC] = "Hypervisor Call",
54
+ [EXCP_HYP_TRAP] = "Hypervisor Trap",
55
+ [EXCP_SMC] = "Secure Monitor Call",
56
+ [EXCP_VIRQ] = "Virtual IRQ",
57
+ [EXCP_VFIQ] = "Virtual FIQ",
58
+ [EXCP_SEMIHOST] = "Semihosting call",
59
+ [EXCP_NOCP] = "v7M NOCP UsageFault",
60
+ [EXCP_INVSTATE] = "v7M INVSTATE UsageFault",
61
+ [EXCP_STKOF] = "v8M STKOF UsageFault",
62
+ [EXCP_LAZYFP] = "v7M exception during lazy FP stacking",
63
+ [EXCP_LSERR] = "v8M LSERR UsageFault",
64
+ [EXCP_UNALIGNED] = "v7M UNALIGNED UsageFault",
65
+ };
66
+
67
+ if (idx >= 0 && idx < ARRAY_SIZE(excnames)) {
68
+ exc = excnames[idx];
69
+ }
70
+ if (!exc) {
71
+ exc = "unknown";
72
+ }
73
+ qemu_log_mask(CPU_LOG_INT, "Taking exception %d [%s]\n", idx, exc);
74
+ }
75
+}
52
+}
76
+
53
+
77
/*
54
void HELPER(rebuild_hflags_m32)(CPUARMState *env, int el)
78
* Return true if the v7M CPACR permits access to the FPU for the specified
55
{
79
* security state and privilege level.
56
int fp_el = fp_exception_el(env, el);
80
@@ -XXX,XX +XXX,XX @@ static bool do_v7m_function_return(ARMCPU *cpu)
57
diff --git a/target/arm/translate.c b/target/arm/translate.c
58
index XXXXXXX..XXXXXXX 100644
59
--- a/target/arm/translate.c
60
+++ b/target/arm/translate.c
61
@@ -XXX,XX +XXX,XX @@ static bool trans_MRS_v7m(DisasContext *s, arg_MRS_v7m *a)
62
63
static bool trans_MSR_v7m(DisasContext *s, arg_MSR_v7m *a)
64
{
65
- TCGv_i32 addr, reg, el;
66
+ TCGv_i32 addr, reg;
67
68
if (!arm_dc_feature(s, ARM_FEATURE_M)) {
69
return false;
70
@@ -XXX,XX +XXX,XX @@ static bool trans_MSR_v7m(DisasContext *s, arg_MSR_v7m *a)
71
gen_helper_v7m_msr(cpu_env, addr, reg);
72
tcg_temp_free_i32(addr);
73
tcg_temp_free_i32(reg);
74
- el = tcg_const_i32(s->current_el);
75
- gen_helper_rebuild_hflags_m32(cpu_env, el);
76
- tcg_temp_free_i32(el);
77
+ /* If we wrote to CONTROL, the EL might have changed */
78
+ gen_helper_rebuild_hflags_m32_newel(cpu_env);
79
gen_lookup_tb(s);
81
return true;
80
return true;
82
}
81
}
83
84
-static void arm_log_exception(int idx)
85
-{
86
- if (qemu_loglevel_mask(CPU_LOG_INT)) {
87
- const char *exc = NULL;
88
- static const char * const excnames[] = {
89
- [EXCP_UDEF] = "Undefined Instruction",
90
- [EXCP_SWI] = "SVC",
91
- [EXCP_PREFETCH_ABORT] = "Prefetch Abort",
92
- [EXCP_DATA_ABORT] = "Data Abort",
93
- [EXCP_IRQ] = "IRQ",
94
- [EXCP_FIQ] = "FIQ",
95
- [EXCP_BKPT] = "Breakpoint",
96
- [EXCP_EXCEPTION_EXIT] = "QEMU v7M exception exit",
97
- [EXCP_KERNEL_TRAP] = "QEMU intercept of kernel commpage",
98
- [EXCP_HVC] = "Hypervisor Call",
99
- [EXCP_HYP_TRAP] = "Hypervisor Trap",
100
- [EXCP_SMC] = "Secure Monitor Call",
101
- [EXCP_VIRQ] = "Virtual IRQ",
102
- [EXCP_VFIQ] = "Virtual FIQ",
103
- [EXCP_SEMIHOST] = "Semihosting call",
104
- [EXCP_NOCP] = "v7M NOCP UsageFault",
105
- [EXCP_INVSTATE] = "v7M INVSTATE UsageFault",
106
- [EXCP_STKOF] = "v8M STKOF UsageFault",
107
- [EXCP_LAZYFP] = "v7M exception during lazy FP stacking",
108
- [EXCP_LSERR] = "v8M LSERR UsageFault",
109
- [EXCP_UNALIGNED] = "v7M UNALIGNED UsageFault",
110
- };
111
-
112
- if (idx >= 0 && idx < ARRAY_SIZE(excnames)) {
113
- exc = excnames[idx];
114
- }
115
- if (!exc) {
116
- exc = "unknown";
117
- }
118
- qemu_log_mask(CPU_LOG_INT, "Taking exception %d [%s]\n", idx, exc);
119
- }
120
-}
121
-
122
static bool v7m_read_half_insn(ARMCPU *cpu, ARMMMUIdx mmu_idx,
123
uint32_t addr, uint16_t *insn)
124
{
125
--
82
--
126
2.20.1
83
2.20.1
127
84
128
85
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
1
Fix a couple of comment typos.
2
2
3
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
4
Message-id: 20190701132516.26392-7-philmd@redhat.com
5
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
3
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
Message-id: 20200303174950.3298-5-peter.maydell@linaro.org
7
---
6
---
8
target/arm/helper.c | 2 --
7
target/arm/helper.c | 2 +-
9
1 file changed, 2 deletions(-)
8
target/arm/translate.c | 2 +-
9
2 files changed, 2 insertions(+), 2 deletions(-)
10
10
11
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
12
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
13
--- a/target/arm/helper.c
13
--- a/target/arm/helper.c
14
+++ b/target/arm/helper.c
14
+++ b/target/arm/helper.c
15
@@ -XXX,XX +XXX,XX @@
15
@@ -XXX,XX +XXX,XX @@ void HELPER(rebuild_hflags_m32)(CPUARMState *env, int el)
16
#include "exec/gdbstub.h"
16
17
#include "exec/helper-proto.h"
17
/*
18
#include "qemu/host-utils.h"
18
* If we have triggered a EL state change we can't rely on the
19
-#include "sysemu/arch_init.h"
19
- * translator having passed it too us, we need to recompute.
20
#include "sysemu/sysemu.h"
20
+ * translator having passed it to us, we need to recompute.
21
#include "qemu/bitops.h"
21
*/
22
#include "qemu/crc32c.h"
22
void HELPER(rebuild_hflags_a32_newel)(CPUARMState *env)
23
@@ -XXX,XX +XXX,XX @@
23
{
24
#include "hw/semihosting/semihost.h"
24
diff --git a/target/arm/translate.c b/target/arm/translate.c
25
#include "sysemu/cpus.h"
25
index XXXXXXX..XXXXXXX 100644
26
#include "sysemu/kvm.h"
26
--- a/target/arm/translate.c
27
-#include "fpu/softfloat.h"
27
+++ b/target/arm/translate.c
28
#include "qemu/range.h"
28
@@ -XXX,XX +XXX,XX @@ static int disas_coproc_insn(DisasContext *s, uint32_t insn)
29
#include "qapi/qapi-commands-target.h"
29
30
#include "qapi/error.h"
30
if (!isread && !(ri->type & ARM_CP_SUPPRESS_TB_END)) {
31
/*
32
- * A write to any coprocessor regiser that ends a TB
33
+ * A write to any coprocessor register that ends a TB
34
* must rebuild the hflags for the next TB.
35
*/
36
TCGv_i32 tcg_el = tcg_const_i32(s->current_el);
31
--
37
--
32
2.20.1
38
2.20.1
33
39
34
40
diff view generated by jsdifflib
1
From: Cédric Le Goater <clg@kaod.org>
1
From: Cédric Le Goater <clg@kaod.org>
2
2
3
The DRAM address of a DMA transaction depends on the DRAM base address
4
of the SoC. Inform the SMC controller model with this value.
5
6
Signed-off-by: Cédric Le Goater <clg@kaod.org>
3
Signed-off-by: Cédric Le Goater <clg@kaod.org>
4
Reviewed-by: Andrew Jeffery <andrew@aj.id.au>
7
Reviewed-by: Joel Stanley <joel@jms.id.au>
5
Reviewed-by: Joel Stanley <joel@jms.id.au>
8
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
6
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
9
Message-id: 20190618165311.27066-15-clg@kaod.org
7
Message-id: 20200206112645.21275-2-clg@kaod.org
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
9
---
12
include/hw/ssi/aspeed_smc.h | 3 +++
10
Makefile.objs | 1 +
13
hw/arm/aspeed_soc.c | 6 ++++++
11
hw/ssi/aspeed_smc.c | 17 +++++++++++++++++
14
hw/ssi/aspeed_smc.c | 1 +
12
hw/ssi/trace-events | 9 +++++++++
15
3 files changed, 10 insertions(+)
13
3 files changed, 27 insertions(+)
14
create mode 100644 hw/ssi/trace-events
16
15
17
diff --git a/include/hw/ssi/aspeed_smc.h b/include/hw/ssi/aspeed_smc.h
16
diff --git a/Makefile.objs b/Makefile.objs
18
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
19
--- a/include/hw/ssi/aspeed_smc.h
18
--- a/Makefile.objs
20
+++ b/include/hw/ssi/aspeed_smc.h
19
+++ b/Makefile.objs
21
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedSMCState {
20
@@ -XXX,XX +XXX,XX @@ trace-events-subdirs += hw/scsi
22
uint8_t r_timings;
21
trace-events-subdirs += hw/sd
23
uint8_t conf_enable_w0;
22
trace-events-subdirs += hw/sparc
24
23
trace-events-subdirs += hw/sparc64
25
+ /* for DMA support */
24
+trace-events-subdirs += hw/ssi
26
+ uint64_t sdram_base;
25
trace-events-subdirs += hw/timer
27
+
26
trace-events-subdirs += hw/tpm
28
AspeedSMCFlash *flashes;
27
trace-events-subdirs += hw/usb
29
30
uint8_t snoop_index;
31
diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c
32
index XXXXXXX..XXXXXXX 100644
33
--- a/hw/arm/aspeed_soc.c
34
+++ b/hw/arm/aspeed_soc.c
35
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
36
aspeed_soc_get_irq(s, ASPEED_I2C));
37
38
/* FMC, The number of CS is set at the board level */
39
+ object_property_set_int(OBJECT(&s->fmc), sc->info->memmap[ASPEED_SDRAM],
40
+ "sdram-base", &err);
41
+ if (err) {
42
+ error_propagate(errp, err);
43
+ return;
44
+ }
45
object_property_set_bool(OBJECT(&s->fmc), true, "realized", &err);
46
if (err) {
47
error_propagate(errp, err);
48
diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c
28
diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c
49
index XXXXXXX..XXXXXXX 100644
29
index XXXXXXX..XXXXXXX 100644
50
--- a/hw/ssi/aspeed_smc.c
30
--- a/hw/ssi/aspeed_smc.c
51
+++ b/hw/ssi/aspeed_smc.c
31
+++ b/hw/ssi/aspeed_smc.c
52
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_aspeed_smc = {
32
@@ -XXX,XX +XXX,XX @@
53
33
#include "qapi/error.h"
54
static Property aspeed_smc_properties[] = {
34
#include "exec/address-spaces.h"
55
DEFINE_PROP_UINT32("num-cs", AspeedSMCState, num_cs, 1),
35
#include "qemu/units.h"
56
+ DEFINE_PROP_UINT64("sdram-base", AspeedSMCState, sdram_base, 0),
36
+#include "trace.h"
57
DEFINE_PROP_END_OF_LIST(),
37
58
};
38
#include "hw/irq.h"
59
39
#include "hw/qdev-properties.h"
40
@@ -XXX,XX +XXX,XX @@ static void aspeed_smc_flash_set_segment(AspeedSMCState *s, int cs,
41
42
s->ctrl->reg_to_segment(s, new, &seg);
43
44
+ trace_aspeed_smc_flash_set_segment(cs, new, seg.addr, seg.addr + seg.size);
45
+
46
/* The start address of CS0 is read-only */
47
if (cs == 0 && seg.addr != s->ctrl->flash_window_base) {
48
qemu_log_mask(LOG_GUEST_ERROR,
49
@@ -XXX,XX +XXX,XX @@ static uint64_t aspeed_smc_flash_read(void *opaque, hwaddr addr, unsigned size)
50
__func__, aspeed_smc_flash_mode(fl));
51
}
52
53
+ trace_aspeed_smc_flash_read(fl->id, addr, size, ret,
54
+ aspeed_smc_flash_mode(fl));
55
return ret;
56
}
57
58
@@ -XXX,XX +XXX,XX @@ static bool aspeed_smc_do_snoop(AspeedSMCFlash *fl, uint64_t data,
59
AspeedSMCState *s = fl->controller;
60
uint8_t addr_width = aspeed_smc_flash_is_4byte(fl) ? 4 : 3;
61
62
+ trace_aspeed_smc_do_snoop(fl->id, s->snoop_index, s->snoop_dummies,
63
+ (uint8_t) data & 0xff);
64
+
65
if (s->snoop_index == SNOOP_OFF) {
66
return false; /* Do nothing */
67
68
@@ -XXX,XX +XXX,XX @@ static void aspeed_smc_flash_write(void *opaque, hwaddr addr, uint64_t data,
69
AspeedSMCState *s = fl->controller;
70
int i;
71
72
+ trace_aspeed_smc_flash_write(fl->id, addr, size, data,
73
+ aspeed_smc_flash_mode(fl));
74
+
75
if (!aspeed_smc_is_writable(fl)) {
76
qemu_log_mask(LOG_GUEST_ERROR, "%s: flash is not writable at 0x%"
77
HWADDR_PRIx "\n", __func__, addr);
78
@@ -XXX,XX +XXX,XX @@ static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size)
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
60
--
120
--
61
2.20.1
121
2.20.1
62
122
63
123
diff view generated by jsdifflib
1
From: Cédric Le Goater <clg@kaod.org>
1
From: Cédric Le Goater <clg@kaod.org>
2
2
3
This will simplify the definition of new SoCs, like the AST2600 which
3
The Aspeed SMC Controller can operate in different modes : Read, Fast
4
should use a different CPU and a different IRQ number layout.
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.
5
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)")
6
Signed-off-by: Cédric Le Goater <clg@kaod.org>
17
Signed-off-by: Cédric Le Goater <clg@kaod.org>
7
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
18
Reviewed-by: Andrew Jeffery <andrew@aj.id.au>
8
Reviewed-by: Joel Stanley <joel@jms.id.au>
19
Message-id: 20200206112645.21275-3-clg@kaod.org
9
Message-id: 20190618165311.27066-2-clg@kaod.org
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
20
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
21
---
12
include/hw/arm/aspeed_soc.h | 36 +++++++++++++++++++++++
22
hw/ssi/aspeed_smc.c | 39 +++++++++++++++++++++++----------------
13
hw/arm/aspeed_soc.c | 57 +++++++++++++++++++++++++++++++------
23
hw/ssi/trace-events | 1 +
14
2 files changed, 85 insertions(+), 8 deletions(-)
24
2 files changed, 24 insertions(+), 16 deletions(-)
15
25
16
diff --git a/include/hw/arm/aspeed_soc.h b/include/hw/arm/aspeed_soc.h
26
diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c
17
index XXXXXXX..XXXXXXX 100644
27
index XXXXXXX..XXXXXXX 100644
18
--- a/include/hw/arm/aspeed_soc.h
28
--- a/hw/ssi/aspeed_smc.c
19
+++ b/include/hw/arm/aspeed_soc.h
29
+++ b/hw/ssi/aspeed_smc.c
20
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedSoCInfo {
30
@@ -XXX,XX +XXX,XX @@ static inline int aspeed_smc_flash_is_4byte(const AspeedSMCFlash *fl)
21
const char *fmc_typename;
31
}
22
const char **spi_typename;
32
}
23
int wdts_num;
33
24
+ const int *irqmap;
34
-static inline bool aspeed_smc_is_ce_stop_active(const AspeedSMCFlash *fl)
25
} AspeedSoCInfo;
35
+static void aspeed_smc_flash_do_select(AspeedSMCFlash *fl, bool unselect)
26
36
{
27
typedef struct AspeedSoCClass {
37
- const AspeedSMCState *s = fl->controller;
28
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedSoCClass {
38
+ AspeedSMCState *s = fl->controller;
29
#define ASPEED_SOC_GET_CLASS(obj) \
39
30
OBJECT_GET_CLASS(AspeedSoCClass, (obj), TYPE_ASPEED_SOC)
40
- return s->regs[s->r_ctrl0 + fl->id] & CTRL_CE_STOP_ACTIVE;
31
41
+ trace_aspeed_smc_flash_select(fl->id, unselect ? "un" : "");
32
+enum {
33
+ ASPEED_IOMEM,
34
+ ASPEED_UART1,
35
+ ASPEED_UART2,
36
+ ASPEED_UART3,
37
+ ASPEED_UART4,
38
+ ASPEED_UART5,
39
+ ASPEED_VUART,
40
+ ASPEED_FMC,
41
+ ASPEED_SPI1,
42
+ ASPEED_SPI2,
43
+ ASPEED_VIC,
44
+ ASPEED_SDMC,
45
+ ASPEED_SCU,
46
+ ASPEED_ADC,
47
+ ASPEED_SRAM,
48
+ ASPEED_GPIO,
49
+ ASPEED_RTC,
50
+ ASPEED_TIMER1,
51
+ ASPEED_TIMER2,
52
+ ASPEED_TIMER3,
53
+ ASPEED_TIMER4,
54
+ ASPEED_TIMER5,
55
+ ASPEED_TIMER6,
56
+ ASPEED_TIMER7,
57
+ ASPEED_TIMER8,
58
+ ASPEED_WDT,
59
+ ASPEED_PWM,
60
+ ASPEED_LPC,
61
+ ASPEED_IBT,
62
+ ASPEED_I2C,
63
+ ASPEED_ETH1,
64
+ ASPEED_ETH2,
65
+};
66
+
42
+
67
#endif /* ASPEED_SOC_H */
43
+ qemu_set_irq(s->cs_lines[fl->id], unselect);
68
diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c
44
}
69
index XXXXXXX..XXXXXXX 100644
45
70
--- a/hw/arm/aspeed_soc.c
46
static void aspeed_smc_flash_select(AspeedSMCFlash *fl)
71
+++ b/hw/arm/aspeed_soc.c
47
{
72
@@ -XXX,XX +XXX,XX @@
48
- AspeedSMCState *s = fl->controller;
73
#define ASPEED_SOC_ETH1_BASE 0x1E660000
49
-
74
#define ASPEED_SOC_ETH2_BASE 0x1E680000
50
- s->regs[s->r_ctrl0 + fl->id] &= ~CTRL_CE_STOP_ACTIVE;
75
51
- qemu_set_irq(s->cs_lines[fl->id], aspeed_smc_is_ce_stop_active(fl));
76
-static const int uart_irqs[] = { 9, 32, 33, 34, 10 };
52
+ aspeed_smc_flash_do_select(fl, false);
77
-static const int timer_irqs[] = { 16, 17, 18, 35, 36, 37, 38, 39, };
53
}
78
+static const int aspeed_soc_ast2400_irqmap[] = {
54
79
+ [ASPEED_UART1] = 9,
55
static void aspeed_smc_flash_unselect(AspeedSMCFlash *fl)
80
+ [ASPEED_UART2] = 32,
56
{
81
+ [ASPEED_UART3] = 33,
57
- AspeedSMCState *s = fl->controller;
82
+ [ASPEED_UART4] = 34,
58
-
83
+ [ASPEED_UART5] = 10,
59
- s->regs[s->r_ctrl0 + fl->id] |= CTRL_CE_STOP_ACTIVE;
84
+ [ASPEED_VUART] = 8,
60
- qemu_set_irq(s->cs_lines[fl->id], aspeed_smc_is_ce_stop_active(fl));
85
+ [ASPEED_FMC] = 19,
61
+ aspeed_smc_flash_do_select(fl, true);
86
+ [ASPEED_SDMC] = 0,
62
}
87
+ [ASPEED_SCU] = 21,
63
88
+ [ASPEED_ADC] = 31,
64
static uint32_t aspeed_smc_check_segment_addr(const AspeedSMCFlash *fl,
89
+ [ASPEED_GPIO] = 20,
65
@@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps aspeed_smc_flash_ops = {
90
+ [ASPEED_RTC] = 22,
91
+ [ASPEED_TIMER1] = 16,
92
+ [ASPEED_TIMER2] = 17,
93
+ [ASPEED_TIMER3] = 18,
94
+ [ASPEED_TIMER4] = 35,
95
+ [ASPEED_TIMER5] = 36,
96
+ [ASPEED_TIMER6] = 37,
97
+ [ASPEED_TIMER7] = 38,
98
+ [ASPEED_TIMER8] = 39,
99
+ [ASPEED_WDT] = 27,
100
+ [ASPEED_PWM] = 28,
101
+ [ASPEED_LPC] = 8,
102
+ [ASPEED_IBT] = 8, /* LPC */
103
+ [ASPEED_I2C] = 12,
104
+ [ASPEED_ETH1] = 2,
105
+ [ASPEED_ETH2] = 3,
106
+};
107
108
#define AST2400_SDRAM_BASE 0x40000000
109
#define AST2500_SDRAM_BASE 0x80000000
110
111
+/* AST2500 uses the same IRQs as the AST2400 */
112
+#define aspeed_soc_ast2500_irqmap aspeed_soc_ast2400_irqmap
113
+
114
static const hwaddr aspeed_soc_ast2400_spi_bases[] = { ASPEED_SOC_SPI_BASE };
115
static const char *aspeed_soc_ast2400_typenames[] = { "aspeed.smc.spi" };
116
117
@@ -XXX,XX +XXX,XX @@ static const AspeedSoCInfo aspeed_socs[] = {
118
.fmc_typename = "aspeed.smc.fmc",
119
.spi_typename = aspeed_soc_ast2400_typenames,
120
.wdts_num = 2,
121
+ .irqmap = aspeed_soc_ast2400_irqmap,
122
}, {
123
.name = "ast2400-a1",
124
.cpu_type = ARM_CPU_TYPE_NAME("arm926"),
125
@@ -XXX,XX +XXX,XX @@ static const AspeedSoCInfo aspeed_socs[] = {
126
.fmc_typename = "aspeed.smc.fmc",
127
.spi_typename = aspeed_soc_ast2400_typenames,
128
.wdts_num = 2,
129
+ .irqmap = aspeed_soc_ast2400_irqmap,
130
}, {
131
.name = "ast2400",
132
.cpu_type = ARM_CPU_TYPE_NAME("arm926"),
133
@@ -XXX,XX +XXX,XX @@ static const AspeedSoCInfo aspeed_socs[] = {
134
.fmc_typename = "aspeed.smc.fmc",
135
.spi_typename = aspeed_soc_ast2400_typenames,
136
.wdts_num = 2,
137
+ .irqmap = aspeed_soc_ast2400_irqmap,
138
}, {
139
.name = "ast2500-a1",
140
.cpu_type = ARM_CPU_TYPE_NAME("arm1176"),
141
@@ -XXX,XX +XXX,XX @@ static const AspeedSoCInfo aspeed_socs[] = {
142
.fmc_typename = "aspeed.smc.ast2500-fmc",
143
.spi_typename = aspeed_soc_ast2500_typenames,
144
.wdts_num = 3,
145
+ .irqmap = aspeed_soc_ast2500_irqmap,
146
},
66
},
147
};
67
};
148
68
149
+static qemu_irq aspeed_soc_get_irq(AspeedSoCState *s, int ctrl)
69
-static void aspeed_smc_flash_update_cs(AspeedSMCFlash *fl)
150
+{
70
+static void aspeed_smc_flash_update_ctrl(AspeedSMCFlash *fl, uint32_t value)
151
+ AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s);
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;
84
+ }
152
+
85
+
153
+ return qdev_get_gpio_in(DEVICE(&s->vic), sc->info->irqmap[ctrl]);
86
+ s->regs[s->r_ctrl0 + fl->id] = value;
154
+}
155
+
87
+
156
static void aspeed_soc_init(Object *obj)
88
+ s->snoop_index = unselect ? SNOOP_OFF : SNOOP_START;
157
{
89
+
158
AspeedSoCState *s = ASPEED_SOC(obj);
90
+ aspeed_smc_flash_do_select(fl, unselect);
159
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
160
return;
161
}
162
sysbus_mmio_map(SYS_BUS_DEVICE(&s->timerctrl), 0, ASPEED_SOC_TIMER_BASE);
163
- for (i = 0; i < ARRAY_SIZE(timer_irqs); i++) {
164
- qemu_irq irq = qdev_get_gpio_in(DEVICE(&s->vic), timer_irqs[i]);
165
+ for (i = 0; i < ASPEED_TIMER_NR_TIMERS; i++) {
166
+ qemu_irq irq = aspeed_soc_get_irq(s, ASPEED_TIMER1 + i);
167
sysbus_connect_irq(SYS_BUS_DEVICE(&s->timerctrl), i, irq);
168
}
169
170
/* UART - attach an 8250 to the IO space as our UART5 */
171
if (serial_hd(0)) {
172
- qemu_irq uart5 = qdev_get_gpio_in(DEVICE(&s->vic), uart_irqs[4]);
173
+ qemu_irq uart5 = aspeed_soc_get_irq(s, ASPEED_UART5);
174
serial_mm_init(get_system_memory(),
175
ASPEED_SOC_IOMEM_BASE + ASPEED_SOC_UART_5_BASE, 2,
176
uart5, 38400, serial_hd(0), DEVICE_LITTLE_ENDIAN);
177
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
178
}
179
sysbus_mmio_map(SYS_BUS_DEVICE(&s->i2c), 0, ASPEED_SOC_I2C_BASE);
180
sysbus_connect_irq(SYS_BUS_DEVICE(&s->i2c), 0,
181
- qdev_get_gpio_in(DEVICE(&s->vic), 12));
182
+ aspeed_soc_get_irq(s, ASPEED_I2C));
183
184
/* FMC, The number of CS is set at the board level */
185
object_property_set_bool(OBJECT(&s->fmc), true, "realized", &err);
186
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
187
sysbus_mmio_map(SYS_BUS_DEVICE(&s->fmc), 1,
188
s->fmc.ctrl->flash_window_base);
189
sysbus_connect_irq(SYS_BUS_DEVICE(&s->fmc), 0,
190
- qdev_get_gpio_in(DEVICE(&s->vic), 19));
191
+ aspeed_soc_get_irq(s, ASPEED_FMC));
192
193
/* SPI */
194
for (i = 0; i < sc->info->spis_num; i++) {
195
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
196
}
197
sysbus_mmio_map(SYS_BUS_DEVICE(&s->ftgmac100), 0, ASPEED_SOC_ETH1_BASE);
198
sysbus_connect_irq(SYS_BUS_DEVICE(&s->ftgmac100), 0,
199
- qdev_get_gpio_in(DEVICE(&s->vic), 2));
200
+ aspeed_soc_get_irq(s, ASPEED_ETH1));
201
}
91
}
202
92
203
static void aspeed_soc_class_init(ObjectClass *oc, void *data)
93
static void aspeed_smc_reset(DeviceState *d)
94
@@ -XXX,XX +XXX,XX @@ static void aspeed_smc_write(void *opaque, hwaddr addr, uint64_t data,
95
s->regs[addr] = value;
96
} else if (addr >= s->r_ctrl0 && addr < s->r_ctrl0 + s->num_cs) {
97
int cs = addr - s->r_ctrl0;
98
- s->regs[addr] = value;
99
- aspeed_smc_flash_update_cs(&s->flashes[cs]);
100
+ aspeed_smc_flash_update_ctrl(&s->flashes[cs], value);
101
} else if (addr >= R_SEG_ADDR0 &&
102
addr < R_SEG_ADDR0 + s->ctrl->max_slaves) {
103
int cs = addr - R_SEG_ADDR0;
104
diff --git a/hw/ssi/trace-events b/hw/ssi/trace-events
105
index XXXXXXX..XXXXXXX 100644
106
--- a/hw/ssi/trace-events
107
+++ b/hw/ssi/trace-events
108
@@ -XXX,XX +XXX,XX @@ aspeed_smc_flash_write(int cs, uint64_t addr, uint32_t size, uint64_t data, int
109
aspeed_smc_read(uint64_t addr, uint32_t size, uint64_t data) "@0x%" PRIx64 " size %u: 0x%" PRIx64
110
aspeed_smc_dma_checksum(uint32_t addr, uint32_t data) "0x%08x: 0x%08x"
111
aspeed_smc_write(uint64_t addr, uint32_t size, uint64_t data) "@0x%" PRIx64 " size %u: 0x%" PRIx64
112
+aspeed_smc_flash_select(int cs, const char *prefix) "CS%d %sselect"
204
--
113
--
205
2.20.1
114
2.20.1
206
115
207
116
diff view generated by jsdifflib
1
From: Samuel Ortiz <sameo@linux.intel.com>
1
From: Richard Henderson <richard.henderson@linaro.org>
2
2
3
Those helpers are a software implementation of the ARM v8 memory zeroing
3
We fail to validate the upper bits of a virtual address on a
4
op code. They should be moved to the op helper file, which is going to
4
translation disabled regime, as per AArch64.TranslateAddressS1Off.
5
eventually be built only when TCG is enabled.
6
5
7
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
6
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
Reviewed-by: Robert Bradford <robert.bradford@intel.com>
7
Message-id: 20200308012946.16303-2-richard.henderson@linaro.org
9
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
10
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
11
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
12
Message-id: 20190701132516.26392-10-philmd@redhat.com
13
[PMD: Rebased]
14
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
15
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
---
10
---
18
target/arm/helper.c | 92 -----------------------------------------
11
target/arm/helper.c | 35 ++++++++++++++++++++++++++++++++++-
19
target/arm/op_helper.c | 93 ++++++++++++++++++++++++++++++++++++++++++
12
1 file changed, 34 insertions(+), 1 deletion(-)
20
2 files changed, 93 insertions(+), 92 deletions(-)
21
13
22
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
23
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
24
--- a/target/arm/helper.c
16
--- a/target/arm/helper.c
25
+++ b/target/arm/helper.c
17
+++ b/target/arm/helper.c
26
@@ -XXX,XX +XXX,XX @@ bool arm_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
18
@@ -XXX,XX +XXX,XX @@ bool get_phys_addr(CPUARMState *env, target_ulong address,
27
#endif
19
/* Definitely a real MMU, not an MPU */
28
}
20
29
21
if (regime_translation_disabled(env, mmu_idx)) {
30
-void HELPER(dc_zva)(CPUARMState *env, uint64_t vaddr_in)
22
- /* MMU disabled. */
31
-{
23
+ /*
32
- /*
24
+ * MMU disabled. S1 addresses within aa64 translation regimes are
33
- * Implement DC ZVA, which zeroes a fixed-length block of memory.
25
+ * still checked for bounds -- see AArch64.TranslateAddressS1Off.
34
- * Note that we do not implement the (architecturally mandated)
26
+ */
35
- * alignment fault for attempts to use this on Device memory
27
+ if (mmu_idx != ARMMMUIdx_Stage2) {
36
- * (which matches the usual QEMU behaviour of not implementing either
28
+ int r_el = regime_el(env, mmu_idx);
37
- * alignment faults or any memory attribute handling).
29
+ if (arm_el_is_aa64(env, r_el)) {
38
- */
30
+ int pamax = arm_pamax(env_archcpu(env));
39
-
31
+ uint64_t tcr = env->cp15.tcr_el[r_el].raw_tcr;
40
- ARMCPU *cpu = env_archcpu(env);
32
+ int addrtop, tbi;
41
- uint64_t blocklen = 4 << cpu->dcz_blocksize;
42
- uint64_t vaddr = vaddr_in & ~(blocklen - 1);
43
-
44
-#ifndef CONFIG_USER_ONLY
45
- {
46
- /*
47
- * Slightly awkwardly, QEMU's TARGET_PAGE_SIZE may be less than
48
- * the block size so we might have to do more than one TLB lookup.
49
- * We know that in fact for any v8 CPU the page size is at least 4K
50
- * and the block size must be 2K or less, but TARGET_PAGE_SIZE is only
51
- * 1K as an artefact of legacy v5 subpage support being present in the
52
- * same QEMU executable. So in practice the hostaddr[] array has
53
- * two entries, given the current setting of TARGET_PAGE_BITS_MIN.
54
- */
55
- int maxidx = DIV_ROUND_UP(blocklen, TARGET_PAGE_SIZE);
56
- void *hostaddr[DIV_ROUND_UP(2 * KiB, 1 << TARGET_PAGE_BITS_MIN)];
57
- int try, i;
58
- unsigned mmu_idx = cpu_mmu_index(env, false);
59
- TCGMemOpIdx oi = make_memop_idx(MO_UB, mmu_idx);
60
-
61
- assert(maxidx <= ARRAY_SIZE(hostaddr));
62
-
63
- for (try = 0; try < 2; try++) {
64
-
65
- for (i = 0; i < maxidx; i++) {
66
- hostaddr[i] = tlb_vaddr_to_host(env,
67
- vaddr + TARGET_PAGE_SIZE * i,
68
- 1, mmu_idx);
69
- if (!hostaddr[i]) {
70
- break;
71
- }
72
- }
73
- if (i == maxidx) {
74
- /*
75
- * If it's all in the TLB it's fair game for just writing to;
76
- * we know we don't need to update dirty status, etc.
77
- */
78
- for (i = 0; i < maxidx - 1; i++) {
79
- memset(hostaddr[i], 0, TARGET_PAGE_SIZE);
80
- }
81
- memset(hostaddr[i], 0, blocklen - (i * TARGET_PAGE_SIZE));
82
- return;
83
- }
84
- /*
85
- * OK, try a store and see if we can populate the tlb. This
86
- * might cause an exception if the memory isn't writable,
87
- * in which case we will longjmp out of here. We must for
88
- * this purpose use the actual register value passed to us
89
- * so that we get the fault address right.
90
- */
91
- helper_ret_stb_mmu(env, vaddr_in, 0, oi, GETPC());
92
- /* Now we can populate the other TLB entries, if any */
93
- for (i = 0; i < maxidx; i++) {
94
- uint64_t va = vaddr + TARGET_PAGE_SIZE * i;
95
- if (va != (vaddr_in & TARGET_PAGE_MASK)) {
96
- helper_ret_stb_mmu(env, va, 0, oi, GETPC());
97
- }
98
- }
99
- }
100
-
101
- /*
102
- * Slow path (probably attempt to do this to an I/O device or
103
- * similar, or clearing of a block of code we have translations
104
- * cached for). Just do a series of byte writes as the architecture
105
- * demands. It's not worth trying to use a cpu_physical_memory_map(),
106
- * memset(), unmap() sequence here because:
107
- * + we'd need to account for the blocksize being larger than a page
108
- * + the direct-RAM access case is almost always going to be dealt
109
- * with in the fastpath code above, so there's no speed benefit
110
- * + we would have to deal with the map returning NULL because the
111
- * bounce buffer was in use
112
- */
113
- for (i = 0; i < blocklen; i++) {
114
- helper_ret_stb_mmu(env, vaddr + i, 0, oi, GETPC());
115
- }
116
- }
117
-#else
118
- memset(g2h(vaddr), 0, blocklen);
119
-#endif
120
-}
121
-
122
/* Note that signed overflow is undefined in C. The following routines are
123
careful to use unsigned types where modulo arithmetic is required.
124
Failure to do so _will_ break on newer gcc. */
125
diff --git a/target/arm/op_helper.c b/target/arm/op_helper.c
126
index XXXXXXX..XXXXXXX 100644
127
--- a/target/arm/op_helper.c
128
+++ b/target/arm/op_helper.c
129
@@ -XXX,XX +XXX,XX @@
130
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
131
*/
132
#include "qemu/osdep.h"
133
+#include "qemu/units.h"
134
#include "qemu/log.h"
135
#include "qemu/main-loop.h"
136
#include "cpu.h"
137
@@ -XXX,XX +XXX,XX @@ uint32_t HELPER(ror_cc)(CPUARMState *env, uint32_t x, uint32_t i)
138
return ((uint32_t)x >> shift) | (x << (32 - shift));
139
}
140
}
141
+
33
+
142
+void HELPER(dc_zva)(CPUARMState *env, uint64_t vaddr_in)
34
+ tbi = aa64_va_parameter_tbi(tcr, mmu_idx);
143
+{
35
+ if (access_type == MMU_INST_FETCH) {
144
+ /*
36
+ tbi &= ~aa64_va_parameter_tbid(tcr, mmu_idx);
145
+ * Implement DC ZVA, which zeroes a fixed-length block of memory.
37
+ }
146
+ * Note that we do not implement the (architecturally mandated)
38
+ tbi = (tbi >> extract64(address, 55, 1)) & 1;
147
+ * alignment fault for attempts to use this on Device memory
39
+ addrtop = (tbi ? 55 : 63);
148
+ * (which matches the usual QEMU behaviour of not implementing either
149
+ * alignment faults or any memory attribute handling).
150
+ */
151
+
40
+
152
+ ARMCPU *cpu = env_archcpu(env);
41
+ if (extract64(address, pamax, addrtop - pamax + 1) != 0) {
153
+ uint64_t blocklen = 4 << cpu->dcz_blocksize;
42
+ fi->type = ARMFault_AddressSize;
154
+ uint64_t vaddr = vaddr_in & ~(blocklen - 1);
43
+ fi->level = 0;
44
+ fi->stage2 = false;
45
+ return 1;
46
+ }
155
+
47
+
156
+#ifndef CONFIG_USER_ONLY
157
+ {
158
+ /*
159
+ * Slightly awkwardly, QEMU's TARGET_PAGE_SIZE may be less than
160
+ * the block size so we might have to do more than one TLB lookup.
161
+ * We know that in fact for any v8 CPU the page size is at least 4K
162
+ * and the block size must be 2K or less, but TARGET_PAGE_SIZE is only
163
+ * 1K as an artefact of legacy v5 subpage support being present in the
164
+ * same QEMU executable. So in practice the hostaddr[] array has
165
+ * two entries, given the current setting of TARGET_PAGE_BITS_MIN.
166
+ */
167
+ int maxidx = DIV_ROUND_UP(blocklen, TARGET_PAGE_SIZE);
168
+ void *hostaddr[DIV_ROUND_UP(2 * KiB, 1 << TARGET_PAGE_BITS_MIN)];
169
+ int try, i;
170
+ unsigned mmu_idx = cpu_mmu_index(env, false);
171
+ TCGMemOpIdx oi = make_memop_idx(MO_UB, mmu_idx);
172
+
173
+ assert(maxidx <= ARRAY_SIZE(hostaddr));
174
+
175
+ for (try = 0; try < 2; try++) {
176
+
177
+ for (i = 0; i < maxidx; i++) {
178
+ hostaddr[i] = tlb_vaddr_to_host(env,
179
+ vaddr + TARGET_PAGE_SIZE * i,
180
+ 1, mmu_idx);
181
+ if (!hostaddr[i]) {
182
+ break;
183
+ }
184
+ }
185
+ if (i == maxidx) {
186
+ /*
48
+ /*
187
+ * If it's all in the TLB it's fair game for just writing to;
49
+ * When TBI is disabled, we've just validated that all of the
188
+ * we know we don't need to update dirty status, etc.
50
+ * bits above PAMax are zero, so logically we only need to
51
+ * clear the top byte for TBI. But it's clearer to follow
52
+ * the pseudocode set of addrdesc.paddress.
189
+ */
53
+ */
190
+ for (i = 0; i < maxidx - 1; i++) {
54
+ address = extract64(address, 0, 52);
191
+ memset(hostaddr[i], 0, TARGET_PAGE_SIZE);
192
+ }
193
+ memset(hostaddr[i], 0, blocklen - (i * TARGET_PAGE_SIZE));
194
+ return;
195
+ }
196
+ /*
197
+ * OK, try a store and see if we can populate the tlb. This
198
+ * might cause an exception if the memory isn't writable,
199
+ * in which case we will longjmp out of here. We must for
200
+ * this purpose use the actual register value passed to us
201
+ * so that we get the fault address right.
202
+ */
203
+ helper_ret_stb_mmu(env, vaddr_in, 0, oi, GETPC());
204
+ /* Now we can populate the other TLB entries, if any */
205
+ for (i = 0; i < maxidx; i++) {
206
+ uint64_t va = vaddr + TARGET_PAGE_SIZE * i;
207
+ if (va != (vaddr_in & TARGET_PAGE_MASK)) {
208
+ helper_ret_stb_mmu(env, va, 0, oi, GETPC());
209
+ }
210
+ }
55
+ }
211
+ }
56
+ }
212
+
57
*phys_ptr = address;
213
+ /*
58
*prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
214
+ * Slow path (probably attempt to do this to an I/O device or
59
*page_size = TARGET_PAGE_SIZE;
215
+ * similar, or clearing of a block of code we have translations
216
+ * cached for). Just do a series of byte writes as the architecture
217
+ * demands. It's not worth trying to use a cpu_physical_memory_map(),
218
+ * memset(), unmap() sequence here because:
219
+ * + we'd need to account for the blocksize being larger than a page
220
+ * + the direct-RAM access case is almost always going to be dealt
221
+ * with in the fastpath code above, so there's no speed benefit
222
+ * + we would have to deal with the map returning NULL because the
223
+ * bounce buffer was in use
224
+ */
225
+ for (i = 0; i < blocklen; i++) {
226
+ helper_ret_stb_mmu(env, vaddr + i, 0, oi, GETPC());
227
+ }
228
+ }
229
+#else
230
+ memset(g2h(vaddr), 0, blocklen);
231
+#endif
232
+}
233
--
60
--
234
2.20.1
61
2.20.1
235
62
236
63
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
1
From: Richard Henderson <richard.henderson@linaro.org>
2
2
3
Suggested-by: Samuel Ortiz <sameo@linux.intel.com>
3
We must include the tag in the FAR_ELx register when raising
4
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
4
an addressing exception. Which means that we should not clear
5
Message-id: 20190701132516.26392-11-philmd@redhat.com
5
out the tag during translation.
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
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
16
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
---
18
---
9
target/arm/cpu.h | 2 -
19
target/arm/translate-a64.c | 11 +++++++++++
10
target/arm/translate.h | 5 -
20
1 file changed, 11 insertions(+)
11
target/arm/cpu.c | 226 +++++++++++++++++++++++++++++++++++++
12
target/arm/translate-a64.c | 128 ---------------------
13
target/arm/translate.c | 88 ---------------
14
5 files changed, 226 insertions(+), 223 deletions(-)
15
21
16
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
17
index XXXXXXX..XXXXXXX 100644
18
--- a/target/arm/cpu.h
19
+++ b/target/arm/cpu.h
20
@@ -XXX,XX +XXX,XX @@ void arm_cpu_do_interrupt(CPUState *cpu);
21
void arm_v7m_cpu_do_interrupt(CPUState *cpu);
22
bool arm_cpu_exec_interrupt(CPUState *cpu, int int_req);
23
24
-void arm_cpu_dump_state(CPUState *cs, FILE *f, int flags);
25
-
26
hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
27
MemTxAttrs *attrs);
28
29
diff --git a/target/arm/translate.h b/target/arm/translate.h
30
index XXXXXXX..XXXXXXX 100644
31
--- a/target/arm/translate.h
32
+++ b/target/arm/translate.h
33
@@ -XXX,XX +XXX,XX @@ static inline void disas_set_insn_syndrome(DisasContext *s, uint32_t syn)
34
#ifdef TARGET_AARCH64
35
void a64_translate_init(void);
36
void gen_a64_set_pc_im(uint64_t val);
37
-void aarch64_cpu_dump_state(CPUState *cs, FILE *f, int flags);
38
extern const TranslatorOps aarch64_translator_ops;
39
#else
40
static inline void a64_translate_init(void)
41
@@ -XXX,XX +XXX,XX @@ static inline void a64_translate_init(void)
42
static inline void gen_a64_set_pc_im(uint64_t val)
43
{
44
}
45
-
46
-static inline void aarch64_cpu_dump_state(CPUState *cs, FILE *f, int flags)
47
-{
48
-}
49
#endif
50
51
void arm_test_cc(DisasCompare *cmp, int cc);
52
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
53
index XXXXXXX..XXXXXXX 100644
54
--- a/target/arm/cpu.c
55
+++ b/target/arm/cpu.c
56
@@ -XXX,XX +XXX,XX @@
57
*/
58
59
#include "qemu/osdep.h"
60
+#include "qemu/qemu-print.h"
61
#include "qemu-common.h"
62
#include "target/arm/idau.h"
63
#include "qemu/module.h"
64
@@ -XXX,XX +XXX,XX @@ static void arm_disas_set_info(CPUState *cpu, disassemble_info *info)
65
#endif
66
}
67
68
+#ifdef TARGET_AARCH64
69
+
70
+static void aarch64_cpu_dump_state(CPUState *cs, FILE *f, int flags)
71
+{
72
+ ARMCPU *cpu = ARM_CPU(cs);
73
+ CPUARMState *env = &cpu->env;
74
+ uint32_t psr = pstate_read(env);
75
+ int i;
76
+ int el = arm_current_el(env);
77
+ const char *ns_status;
78
+
79
+ qemu_fprintf(f, " PC=%016" PRIx64 " ", env->pc);
80
+ for (i = 0; i < 32; i++) {
81
+ if (i == 31) {
82
+ qemu_fprintf(f, " SP=%016" PRIx64 "\n", env->xregs[i]);
83
+ } else {
84
+ qemu_fprintf(f, "X%02d=%016" PRIx64 "%s", i, env->xregs[i],
85
+ (i + 2) % 3 ? " " : "\n");
86
+ }
87
+ }
88
+
89
+ if (arm_feature(env, ARM_FEATURE_EL3) && el != 3) {
90
+ ns_status = env->cp15.scr_el3 & SCR_NS ? "NS " : "S ";
91
+ } else {
92
+ ns_status = "";
93
+ }
94
+ qemu_fprintf(f, "PSTATE=%08x %c%c%c%c %sEL%d%c",
95
+ psr,
96
+ psr & PSTATE_N ? 'N' : '-',
97
+ psr & PSTATE_Z ? 'Z' : '-',
98
+ psr & PSTATE_C ? 'C' : '-',
99
+ psr & PSTATE_V ? 'V' : '-',
100
+ ns_status,
101
+ el,
102
+ psr & PSTATE_SP ? 'h' : 't');
103
+
104
+ if (cpu_isar_feature(aa64_bti, cpu)) {
105
+ qemu_fprintf(f, " BTYPE=%d", (psr & PSTATE_BTYPE) >> 10);
106
+ }
107
+ if (!(flags & CPU_DUMP_FPU)) {
108
+ qemu_fprintf(f, "\n");
109
+ return;
110
+ }
111
+ if (fp_exception_el(env, el) != 0) {
112
+ qemu_fprintf(f, " FPU disabled\n");
113
+ return;
114
+ }
115
+ qemu_fprintf(f, " FPCR=%08x FPSR=%08x\n",
116
+ vfp_get_fpcr(env), vfp_get_fpsr(env));
117
+
118
+ if (cpu_isar_feature(aa64_sve, cpu) && sve_exception_el(env, el) == 0) {
119
+ int j, zcr_len = sve_zcr_len_for_el(env, el);
120
+
121
+ for (i = 0; i <= FFR_PRED_NUM; i++) {
122
+ bool eol;
123
+ if (i == FFR_PRED_NUM) {
124
+ qemu_fprintf(f, "FFR=");
125
+ /* It's last, so end the line. */
126
+ eol = true;
127
+ } else {
128
+ qemu_fprintf(f, "P%02d=", i);
129
+ switch (zcr_len) {
130
+ case 0:
131
+ eol = i % 8 == 7;
132
+ break;
133
+ case 1:
134
+ eol = i % 6 == 5;
135
+ break;
136
+ case 2:
137
+ case 3:
138
+ eol = i % 3 == 2;
139
+ break;
140
+ default:
141
+ /* More than one quadword per predicate. */
142
+ eol = true;
143
+ break;
144
+ }
145
+ }
146
+ for (j = zcr_len / 4; j >= 0; j--) {
147
+ int digits;
148
+ if (j * 4 + 4 <= zcr_len + 1) {
149
+ digits = 16;
150
+ } else {
151
+ digits = (zcr_len % 4 + 1) * 4;
152
+ }
153
+ qemu_fprintf(f, "%0*" PRIx64 "%s", digits,
154
+ env->vfp.pregs[i].p[j],
155
+ j ? ":" : eol ? "\n" : " ");
156
+ }
157
+ }
158
+
159
+ for (i = 0; i < 32; i++) {
160
+ if (zcr_len == 0) {
161
+ qemu_fprintf(f, "Z%02d=%016" PRIx64 ":%016" PRIx64 "%s",
162
+ i, env->vfp.zregs[i].d[1],
163
+ env->vfp.zregs[i].d[0], i & 1 ? "\n" : " ");
164
+ } else if (zcr_len == 1) {
165
+ qemu_fprintf(f, "Z%02d=%016" PRIx64 ":%016" PRIx64
166
+ ":%016" PRIx64 ":%016" PRIx64 "\n",
167
+ i, env->vfp.zregs[i].d[3], env->vfp.zregs[i].d[2],
168
+ env->vfp.zregs[i].d[1], env->vfp.zregs[i].d[0]);
169
+ } else {
170
+ for (j = zcr_len; j >= 0; j--) {
171
+ bool odd = (zcr_len - j) % 2 != 0;
172
+ if (j == zcr_len) {
173
+ qemu_fprintf(f, "Z%02d[%x-%x]=", i, j, j - 1);
174
+ } else if (!odd) {
175
+ if (j > 0) {
176
+ qemu_fprintf(f, " [%x-%x]=", j, j - 1);
177
+ } else {
178
+ qemu_fprintf(f, " [%x]=", j);
179
+ }
180
+ }
181
+ qemu_fprintf(f, "%016" PRIx64 ":%016" PRIx64 "%s",
182
+ env->vfp.zregs[i].d[j * 2 + 1],
183
+ env->vfp.zregs[i].d[j * 2],
184
+ odd || j == 0 ? "\n" : ":");
185
+ }
186
+ }
187
+ }
188
+ } else {
189
+ for (i = 0; i < 32; i++) {
190
+ uint64_t *q = aa64_vfp_qreg(env, i);
191
+ qemu_fprintf(f, "Q%02d=%016" PRIx64 ":%016" PRIx64 "%s",
192
+ i, q[1], q[0], (i & 1 ? "\n" : " "));
193
+ }
194
+ }
195
+}
196
+
197
+#else
198
+
199
+static inline void aarch64_cpu_dump_state(CPUState *cs, FILE *f, int flags)
200
+{
201
+ g_assert_not_reached();
202
+}
203
+
204
+#endif
205
+
206
+static void arm_cpu_dump_state(CPUState *cs, FILE *f, int flags)
207
+{
208
+ ARMCPU *cpu = ARM_CPU(cs);
209
+ CPUARMState *env = &cpu->env;
210
+ int i;
211
+
212
+ if (is_a64(env)) {
213
+ aarch64_cpu_dump_state(cs, f, flags);
214
+ return;
215
+ }
216
+
217
+ for (i = 0; i < 16; i++) {
218
+ qemu_fprintf(f, "R%02d=%08x", i, env->regs[i]);
219
+ if ((i % 4) == 3) {
220
+ qemu_fprintf(f, "\n");
221
+ } else {
222
+ qemu_fprintf(f, " ");
223
+ }
224
+ }
225
+
226
+ if (arm_feature(env, ARM_FEATURE_M)) {
227
+ uint32_t xpsr = xpsr_read(env);
228
+ const char *mode;
229
+ const char *ns_status = "";
230
+
231
+ if (arm_feature(env, ARM_FEATURE_M_SECURITY)) {
232
+ ns_status = env->v7m.secure ? "S " : "NS ";
233
+ }
234
+
235
+ if (xpsr & XPSR_EXCP) {
236
+ mode = "handler";
237
+ } else {
238
+ if (env->v7m.control[env->v7m.secure] & R_V7M_CONTROL_NPRIV_MASK) {
239
+ mode = "unpriv-thread";
240
+ } else {
241
+ mode = "priv-thread";
242
+ }
243
+ }
244
+
245
+ qemu_fprintf(f, "XPSR=%08x %c%c%c%c %c %s%s\n",
246
+ xpsr,
247
+ xpsr & XPSR_N ? 'N' : '-',
248
+ xpsr & XPSR_Z ? 'Z' : '-',
249
+ xpsr & XPSR_C ? 'C' : '-',
250
+ xpsr & XPSR_V ? 'V' : '-',
251
+ xpsr & XPSR_T ? 'T' : 'A',
252
+ ns_status,
253
+ mode);
254
+ } else {
255
+ uint32_t psr = cpsr_read(env);
256
+ const char *ns_status = "";
257
+
258
+ if (arm_feature(env, ARM_FEATURE_EL3) &&
259
+ (psr & CPSR_M) != ARM_CPU_MODE_MON) {
260
+ ns_status = env->cp15.scr_el3 & SCR_NS ? "NS " : "S ";
261
+ }
262
+
263
+ qemu_fprintf(f, "PSR=%08x %c%c%c%c %c %s%s%d\n",
264
+ psr,
265
+ psr & CPSR_N ? 'N' : '-',
266
+ psr & CPSR_Z ? 'Z' : '-',
267
+ psr & CPSR_C ? 'C' : '-',
268
+ psr & CPSR_V ? 'V' : '-',
269
+ psr & CPSR_T ? 'T' : 'A',
270
+ ns_status,
271
+ aarch32_mode_name(psr), (psr & 0x10) ? 32 : 26);
272
+ }
273
+
274
+ if (flags & CPU_DUMP_FPU) {
275
+ int numvfpregs = 0;
276
+ if (arm_feature(env, ARM_FEATURE_VFP)) {
277
+ numvfpregs += 16;
278
+ }
279
+ if (arm_feature(env, ARM_FEATURE_VFP3)) {
280
+ numvfpregs += 16;
281
+ }
282
+ for (i = 0; i < numvfpregs; i++) {
283
+ uint64_t v = *aa32_vfp_dreg(env, i);
284
+ qemu_fprintf(f, "s%02d=%08x s%02d=%08x d%02d=%016" PRIx64 "\n",
285
+ i * 2, (uint32_t)v,
286
+ i * 2 + 1, (uint32_t)(v >> 32),
287
+ i, v);
288
+ }
289
+ qemu_fprintf(f, "FPSCR: %08x\n", vfp_get_fpscr(env));
290
+ }
291
+}
292
+
293
uint64_t arm_cpu_mp_affinity(int idx, uint8_t clustersz)
294
{
295
uint32_t Aff1 = idx / clustersz;
296
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
297
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
298
--- a/target/arm/translate-a64.c
24
--- a/target/arm/translate-a64.c
299
+++ b/target/arm/translate-a64.c
25
+++ b/target/arm/translate-a64.c
300
@@ -XXX,XX +XXX,XX @@
26
@@ -XXX,XX +XXX,XX @@ static void gen_a64_set_pc(DisasContext *s, TCGv_i64 src)
301
#include "translate.h"
27
static TCGv_i64 clean_data_tbi(DisasContext *s, TCGv_i64 addr)
302
#include "internals.h"
28
{
303
#include "qemu/host-utils.h"
29
TCGv_i64 clean = new_tmp_a64(s);
304
-#include "qemu/qemu-print.h"
30
+ /*
305
31
+ * In order to get the correct value in the FAR_ELx register,
306
#include "hw/semihosting/semihost.h"
32
+ * we must present the memory subsystem with the "dirty" address
307
#include "exec/gen-icount.h"
33
+ * including the TBI. In system mode we can make this work via
308
@@ -XXX,XX +XXX,XX @@ static void set_btype(DisasContext *s, int val)
34
+ * the TLB, dropping the TBI during translation. But for user-only
309
s->btype = -1;
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;
310
}
43
}
311
44
312
-void aarch64_cpu_dump_state(CPUState *cs, FILE *f, int flags)
313
-{
314
- ARMCPU *cpu = ARM_CPU(cs);
315
- CPUARMState *env = &cpu->env;
316
- uint32_t psr = pstate_read(env);
317
- int i;
318
- int el = arm_current_el(env);
319
- const char *ns_status;
320
-
321
- qemu_fprintf(f, " PC=%016" PRIx64 " ", env->pc);
322
- for (i = 0; i < 32; i++) {
323
- if (i == 31) {
324
- qemu_fprintf(f, " SP=%016" PRIx64 "\n", env->xregs[i]);
325
- } else {
326
- qemu_fprintf(f, "X%02d=%016" PRIx64 "%s", i, env->xregs[i],
327
- (i + 2) % 3 ? " " : "\n");
328
- }
329
- }
330
-
331
- if (arm_feature(env, ARM_FEATURE_EL3) && el != 3) {
332
- ns_status = env->cp15.scr_el3 & SCR_NS ? "NS " : "S ";
333
- } else {
334
- ns_status = "";
335
- }
336
- qemu_fprintf(f, "PSTATE=%08x %c%c%c%c %sEL%d%c",
337
- psr,
338
- psr & PSTATE_N ? 'N' : '-',
339
- psr & PSTATE_Z ? 'Z' : '-',
340
- psr & PSTATE_C ? 'C' : '-',
341
- psr & PSTATE_V ? 'V' : '-',
342
- ns_status,
343
- el,
344
- psr & PSTATE_SP ? 'h' : 't');
345
-
346
- if (cpu_isar_feature(aa64_bti, cpu)) {
347
- qemu_fprintf(f, " BTYPE=%d", (psr & PSTATE_BTYPE) >> 10);
348
- }
349
- if (!(flags & CPU_DUMP_FPU)) {
350
- qemu_fprintf(f, "\n");
351
- return;
352
- }
353
- if (fp_exception_el(env, el) != 0) {
354
- qemu_fprintf(f, " FPU disabled\n");
355
- return;
356
- }
357
- qemu_fprintf(f, " FPCR=%08x FPSR=%08x\n",
358
- vfp_get_fpcr(env), vfp_get_fpsr(env));
359
-
360
- if (cpu_isar_feature(aa64_sve, cpu) && sve_exception_el(env, el) == 0) {
361
- int j, zcr_len = sve_zcr_len_for_el(env, el);
362
-
363
- for (i = 0; i <= FFR_PRED_NUM; i++) {
364
- bool eol;
365
- if (i == FFR_PRED_NUM) {
366
- qemu_fprintf(f, "FFR=");
367
- /* It's last, so end the line. */
368
- eol = true;
369
- } else {
370
- qemu_fprintf(f, "P%02d=", i);
371
- switch (zcr_len) {
372
- case 0:
373
- eol = i % 8 == 7;
374
- break;
375
- case 1:
376
- eol = i % 6 == 5;
377
- break;
378
- case 2:
379
- case 3:
380
- eol = i % 3 == 2;
381
- break;
382
- default:
383
- /* More than one quadword per predicate. */
384
- eol = true;
385
- break;
386
- }
387
- }
388
- for (j = zcr_len / 4; j >= 0; j--) {
389
- int digits;
390
- if (j * 4 + 4 <= zcr_len + 1) {
391
- digits = 16;
392
- } else {
393
- digits = (zcr_len % 4 + 1) * 4;
394
- }
395
- qemu_fprintf(f, "%0*" PRIx64 "%s", digits,
396
- env->vfp.pregs[i].p[j],
397
- j ? ":" : eol ? "\n" : " ");
398
- }
399
- }
400
-
401
- for (i = 0; i < 32; i++) {
402
- if (zcr_len == 0) {
403
- qemu_fprintf(f, "Z%02d=%016" PRIx64 ":%016" PRIx64 "%s",
404
- i, env->vfp.zregs[i].d[1],
405
- env->vfp.zregs[i].d[0], i & 1 ? "\n" : " ");
406
- } else if (zcr_len == 1) {
407
- qemu_fprintf(f, "Z%02d=%016" PRIx64 ":%016" PRIx64
408
- ":%016" PRIx64 ":%016" PRIx64 "\n",
409
- i, env->vfp.zregs[i].d[3], env->vfp.zregs[i].d[2],
410
- env->vfp.zregs[i].d[1], env->vfp.zregs[i].d[0]);
411
- } else {
412
- for (j = zcr_len; j >= 0; j--) {
413
- bool odd = (zcr_len - j) % 2 != 0;
414
- if (j == zcr_len) {
415
- qemu_fprintf(f, "Z%02d[%x-%x]=", i, j, j - 1);
416
- } else if (!odd) {
417
- if (j > 0) {
418
- qemu_fprintf(f, " [%x-%x]=", j, j - 1);
419
- } else {
420
- qemu_fprintf(f, " [%x]=", j);
421
- }
422
- }
423
- qemu_fprintf(f, "%016" PRIx64 ":%016" PRIx64 "%s",
424
- env->vfp.zregs[i].d[j * 2 + 1],
425
- env->vfp.zregs[i].d[j * 2],
426
- odd || j == 0 ? "\n" : ":");
427
- }
428
- }
429
- }
430
- } else {
431
- for (i = 0; i < 32; i++) {
432
- uint64_t *q = aa64_vfp_qreg(env, i);
433
- qemu_fprintf(f, "Q%02d=%016" PRIx64 ":%016" PRIx64 "%s",
434
- i, q[1], q[0], (i & 1 ? "\n" : " "));
435
- }
436
- }
437
-}
438
-
439
void gen_a64_set_pc_im(uint64_t val)
440
{
441
tcg_gen_movi_i64(cpu_pc, val);
442
diff --git a/target/arm/translate.c b/target/arm/translate.c
443
index XXXXXXX..XXXXXXX 100644
444
--- a/target/arm/translate.c
445
+++ b/target/arm/translate.c
446
@@ -XXX,XX +XXX,XX @@
447
#include "tcg-op-gvec.h"
448
#include "qemu/log.h"
449
#include "qemu/bitops.h"
450
-#include "qemu/qemu-print.h"
451
#include "arm_ldst.h"
452
#include "hw/semihosting/semihost.h"
453
454
@@ -XXX,XX +XXX,XX @@ void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns)
455
translator_loop(ops, &dc.base, cpu, tb, max_insns);
456
}
457
458
-void arm_cpu_dump_state(CPUState *cs, FILE *f, int flags)
459
-{
460
- ARMCPU *cpu = ARM_CPU(cs);
461
- CPUARMState *env = &cpu->env;
462
- int i;
463
-
464
- if (is_a64(env)) {
465
- aarch64_cpu_dump_state(cs, f, flags);
466
- return;
467
- }
468
-
469
- for (i = 0; i < 16; i++) {
470
- qemu_fprintf(f, "R%02d=%08x", i, env->regs[i]);
471
- if ((i % 4) == 3) {
472
- qemu_fprintf(f, "\n");
473
- } else {
474
- qemu_fprintf(f, " ");
475
- }
476
- }
477
-
478
- if (arm_feature(env, ARM_FEATURE_M)) {
479
- uint32_t xpsr = xpsr_read(env);
480
- const char *mode;
481
- const char *ns_status = "";
482
-
483
- if (arm_feature(env, ARM_FEATURE_M_SECURITY)) {
484
- ns_status = env->v7m.secure ? "S " : "NS ";
485
- }
486
-
487
- if (xpsr & XPSR_EXCP) {
488
- mode = "handler";
489
- } else {
490
- if (env->v7m.control[env->v7m.secure] & R_V7M_CONTROL_NPRIV_MASK) {
491
- mode = "unpriv-thread";
492
- } else {
493
- mode = "priv-thread";
494
- }
495
- }
496
-
497
- qemu_fprintf(f, "XPSR=%08x %c%c%c%c %c %s%s\n",
498
- xpsr,
499
- xpsr & XPSR_N ? 'N' : '-',
500
- xpsr & XPSR_Z ? 'Z' : '-',
501
- xpsr & XPSR_C ? 'C' : '-',
502
- xpsr & XPSR_V ? 'V' : '-',
503
- xpsr & XPSR_T ? 'T' : 'A',
504
- ns_status,
505
- mode);
506
- } else {
507
- uint32_t psr = cpsr_read(env);
508
- const char *ns_status = "";
509
-
510
- if (arm_feature(env, ARM_FEATURE_EL3) &&
511
- (psr & CPSR_M) != ARM_CPU_MODE_MON) {
512
- ns_status = env->cp15.scr_el3 & SCR_NS ? "NS " : "S ";
513
- }
514
-
515
- qemu_fprintf(f, "PSR=%08x %c%c%c%c %c %s%s%d\n",
516
- psr,
517
- psr & CPSR_N ? 'N' : '-',
518
- psr & CPSR_Z ? 'Z' : '-',
519
- psr & CPSR_C ? 'C' : '-',
520
- psr & CPSR_V ? 'V' : '-',
521
- psr & CPSR_T ? 'T' : 'A',
522
- ns_status,
523
- aarch32_mode_name(psr), (psr & 0x10) ? 32 : 26);
524
- }
525
-
526
- if (flags & CPU_DUMP_FPU) {
527
- int numvfpregs = 0;
528
- if (arm_feature(env, ARM_FEATURE_VFP)) {
529
- numvfpregs += 16;
530
- }
531
- if (arm_feature(env, ARM_FEATURE_VFP3)) {
532
- numvfpregs += 16;
533
- }
534
- for (i = 0; i < numvfpregs; i++) {
535
- uint64_t v = *aa32_vfp_dreg(env, i);
536
- qemu_fprintf(f, "s%02d=%08x s%02d=%08x d%02d=%016" PRIx64 "\n",
537
- i * 2, (uint32_t)v,
538
- i * 2 + 1, (uint32_t)(v >> 32),
539
- i, v);
540
- }
541
- qemu_fprintf(f, "FPSCR: %08x\n", vfp_get_fpscr(env));
542
- }
543
-}
544
-
545
void restore_state_to_opc(CPUARMState *env, TranslationBlock *tb,
546
target_ulong *data)
547
{
548
--
45
--
549
2.20.1
46
2.20.1
550
47
551
48
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
1
From: Igor Mammedov <imammedo@redhat.com>
2
2
3
Under KVM, the kernel gets the HVC call and handle the PSCI requests.
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.
4
7
5
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
8
The SOC object will be kept alive by its parent (machine) and
6
Message-id: 20190701132516.26392-20-philmd@redhat.com
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
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
15
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
17
---
10
target/arm/internals.h | 6 +++++-
18
hw/arm/cubieboard.c | 3 +++
11
1 file changed, 5 insertions(+), 1 deletion(-)
19
1 file changed, 3 insertions(+)
12
20
13
diff --git a/target/arm/internals.h b/target/arm/internals.h
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/target/arm/internals.h
23
--- a/hw/arm/cubieboard.c
16
+++ b/target/arm/internals.h
24
+++ b/hw/arm/cubieboard.c
17
@@ -XXX,XX +XXX,XX @@ vaddr arm_adjust_watchpoint_address(CPUState *cs, vaddr addr, int len);
25
@@ -XXX,XX +XXX,XX @@ static void cubieboard_init(MachineState *machine)
18
/* Callback function for when a watchpoint or breakpoint triggers. */
26
}
19
void arm_debug_excp_handler(CPUState *cs);
27
20
28
a10 = AW_A10(object_new(TYPE_AW_A10));
21
-#ifdef CONFIG_USER_ONLY
29
+ object_property_add_child(OBJECT(machine), "soc", OBJECT(a10),
22
+#if defined(CONFIG_USER_ONLY) || !defined(CONFIG_TCG)
30
+ &error_abort);
23
static inline bool arm_is_psci_call(ARMCPU *cpu, int excp_type)
31
+ object_unref(OBJECT(a10));
24
{
32
25
return false;
33
object_property_set_int(OBJECT(&a10->emac), 1, "phy-addr", &err);
26
}
34
if (err != NULL) {
27
+static inline void arm_handle_psci_call(ARMCPU *cpu)
28
+{
29
+ g_assert_not_reached();
30
+}
31
#else
32
/* Return true if the r0/x0 value indicates that this SMC/HVC is a PSCI call. */
33
bool arm_is_psci_call(ARMCPU *cpu, int excp_type);
34
--
35
--
35
2.20.1
36
2.20.1
36
37
37
38
diff view generated by jsdifflib
1
From: Cédric Le Goater <clg@kaod.org>
1
From: Guenter Roeck <linux@roeck-us.net>
2
2
3
The Aspeed SoCs have two MACs. Extend the Aspeed model to support a
3
Wire up eSDHC controllers in fsl-imx25. For imx25-pdk, connect drives
4
second NIC.
4
provided on the command line to available eSDHC controllers.
5
5
6
Signed-off-by: Cédric Le Goater <clg@kaod.org>
6
This patch enables booting the imx25-pdk emulation from SD card.
7
Reviewed-by: Joel Stanley <joel@jms.id.au>
7
8
Message-id: 20190618165311.27066-7-clg@kaod.org
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]
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
13
---
11
include/hw/arm/aspeed_soc.h | 3 ++-
14
include/hw/arm/fsl-imx25.h | 9 +++++++++
12
hw/arm/aspeed_soc.c | 33 +++++++++++++++++++--------------
15
hw/arm/fsl-imx25.c | 32 ++++++++++++++++++++++++++++++++
13
2 files changed, 21 insertions(+), 15 deletions(-)
16
hw/arm/imx25_pdk.c | 16 ++++++++++++++++
17
3 files changed, 57 insertions(+)
14
18
15
diff --git a/include/hw/arm/aspeed_soc.h b/include/hw/arm/aspeed_soc.h
19
diff --git a/include/hw/arm/fsl-imx25.h b/include/hw/arm/fsl-imx25.h
16
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
17
--- a/include/hw/arm/aspeed_soc.h
21
--- a/include/hw/arm/fsl-imx25.h
18
+++ b/include/hw/arm/aspeed_soc.h
22
+++ b/include/hw/arm/fsl-imx25.h
19
@@ -XXX,XX +XXX,XX @@
23
@@ -XXX,XX +XXX,XX @@
20
#define ASPEED_SPIS_NUM 2
24
#include "hw/misc/imx_rngc.h"
21
#define ASPEED_WDTS_NUM 3
25
#include "hw/i2c/imx_i2c.h"
22
#define ASPEED_CPUS_NUM 2
26
#include "hw/gpio/imx_gpio.h"
23
+#define ASPEED_MACS_NUM 2
27
+#include "hw/sd/sdhci.h"
24
28
#include "exec/memory.h"
25
typedef struct AspeedSoCState {
29
#include "target/arm/cpu.h"
30
31
@@ -XXX,XX +XXX,XX @@
32
#define FSL_IMX25_NUM_EPITS 2
33
#define FSL_IMX25_NUM_I2CS 3
34
#define FSL_IMX25_NUM_GPIOS 4
35
+#define FSL_IMX25_NUM_ESDHCS 2
36
37
typedef struct FslIMX25State {
26
/*< private >*/
38
/*< private >*/
27
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedSoCState {
39
@@ -XXX,XX +XXX,XX @@ typedef struct FslIMX25State {
28
AspeedSMCState spi[ASPEED_SPIS_NUM];
40
IMXRNGCState rngc;
29
AspeedSDMCState sdmc;
41
IMXI2CState i2c[FSL_IMX25_NUM_I2CS];
30
AspeedWDTState wdt[ASPEED_WDTS_NUM];
42
IMXGPIOState gpio[FSL_IMX25_NUM_GPIOS];
31
- FTGMAC100State ftgmac100;
43
+ SDHCIState esdhc[FSL_IMX25_NUM_ESDHCS];
32
+ FTGMAC100State ftgmac100[ASPEED_MACS_NUM];
44
MemoryRegion rom[2];
33
} AspeedSoCState;
45
MemoryRegion iram;
34
46
MemoryRegion iram_alias;
35
#define TYPE_ASPEED_SOC "aspeed-soc"
47
@@ -XXX,XX +XXX,XX @@ typedef struct FslIMX25State {
36
diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c
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
37
index XXXXXXX..XXXXXXX 100644
67
index XXXXXXX..XXXXXXX 100644
38
--- a/hw/arm/aspeed_soc.c
68
--- a/hw/arm/fsl-imx25.c
39
+++ b/hw/arm/aspeed_soc.c
69
+++ b/hw/arm/fsl-imx25.c
40
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_init(Object *obj)
70
@@ -XXX,XX +XXX,XX @@
41
sc->info->silicon_rev);
71
#include "hw/qdev-properties.h"
72
#include "chardev/char.h"
73
74
+#define IMX25_ESDHC_CAPABILITIES 0x07e20000
75
+
76
static void fsl_imx25_init(Object *obj)
77
{
78
FslIMX25State *s = FSL_IMX25(obj);
79
@@ -XXX,XX +XXX,XX @@ static void fsl_imx25_init(Object *obj)
80
sysbus_init_child_obj(obj, "gpio[*]", &s->gpio[i], sizeof(s->gpio[i]),
81
TYPE_IMX_GPIO);
42
}
82
}
43
83
+
44
- sysbus_init_child_obj(obj, "ftgmac100", OBJECT(&s->ftgmac100),
84
+ for (i = 0; i < FSL_IMX25_NUM_ESDHCS; i++) {
45
- sizeof(s->ftgmac100), TYPE_FTGMAC100);
85
+ sysbus_init_child_obj(obj, "sdhc[*]", &s->esdhc[i], sizeof(s->esdhc[i]),
46
+ for (i = 0; i < ASPEED_MACS_NUM; i++) {
86
+ TYPE_IMX_USDHC);
47
+ sysbus_init_child_obj(obj, "ftgmac100[*]", OBJECT(&s->ftgmac100[i]),
48
+ sizeof(s->ftgmac100[i]), TYPE_FTGMAC100);
49
+ }
87
+ }
50
}
88
}
51
89
52
static void aspeed_soc_realize(DeviceState *dev, Error **errp)
90
static void fsl_imx25_realize(DeviceState *dev, Error **errp)
53
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
91
@@ -XXX,XX +XXX,XX @@ static void fsl_imx25_realize(DeviceState *dev, Error **errp)
92
gpio_table[i].irq));
54
}
93
}
55
94
56
/* Net */
95
+ /* Initialize all SDHC */
57
- qdev_set_nic_properties(DEVICE(&s->ftgmac100), &nd_table[0]);
96
+ for (i = 0; i < FSL_IMX25_NUM_ESDHCS; i++) {
58
- object_property_set_bool(OBJECT(&s->ftgmac100), true, "aspeed", &err);
97
+ static const struct {
59
- object_property_set_bool(OBJECT(&s->ftgmac100), true, "realized",
98
+ hwaddr addr;
60
- &local_err);
99
+ unsigned int irq;
61
- error_propagate(&err, local_err);
100
+ } esdhc_table[FSL_IMX25_NUM_ESDHCS] = {
62
- if (err) {
101
+ { FSL_IMX25_ESDHC1_ADDR, FSL_IMX25_ESDHC1_IRQ },
63
- error_propagate(errp, err);
102
+ { FSL_IMX25_ESDHC2_ADDR, FSL_IMX25_ESDHC2_IRQ },
64
- return;
103
+ };
65
+ for (i = 0; i < nb_nics; i++) {
104
+
66
+ qdev_set_nic_properties(DEVICE(&s->ftgmac100[i]), &nd_table[i]);
105
+ object_property_set_uint(OBJECT(&s->esdhc[i]), 2, "sd-spec-version",
67
+ object_property_set_bool(OBJECT(&s->ftgmac100[i]), true, "aspeed",
68
+ &err);
106
+ &err);
69
+ object_property_set_bool(OBJECT(&s->ftgmac100[i]), true, "realized",
107
+ object_property_set_uint(OBJECT(&s->esdhc[i]), IMX25_ESDHC_CAPABILITIES,
70
+ &local_err);
108
+ "capareg", &err);
71
+ error_propagate(&err, local_err);
109
+ object_property_set_bool(OBJECT(&s->esdhc[i]), true, "realized", &err);
72
+ if (err) {
110
+ if (err) {
73
+ error_propagate(errp, err);
111
+ error_propagate(errp, err);
74
+ return;
112
+ return;
75
+ }
113
+ }
76
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->ftgmac100[i]), 0,
114
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->esdhc[i]), 0, esdhc_table[i].addr);
77
+ sc->info->memmap[ASPEED_ETH1 + i]);
115
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->esdhc[i]), 0,
78
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->ftgmac100[i]), 0,
116
+ qdev_get_gpio_in(DEVICE(&s->avic),
79
+ aspeed_soc_get_irq(s, ASPEED_ETH1 + i));
117
+ esdhc_table[i].irq));
80
}
118
+ }
81
- sysbus_mmio_map(SYS_BUS_DEVICE(&s->ftgmac100), 0,
119
+
82
- sc->info->memmap[ASPEED_ETH1]);
120
/* initialize 2 x 16 KB ROM */
83
- sysbus_connect_irq(SYS_BUS_DEVICE(&s->ftgmac100), 0,
121
memory_region_init_rom(&s->rom[0], NULL,
84
- aspeed_soc_get_irq(s, ASPEED_ETH1));
122
"imx25.rom0", FSL_IMX25_ROM0_SIZE, &err);
85
}
123
diff --git a/hw/arm/imx25_pdk.c b/hw/arm/imx25_pdk.c
86
static Property aspeed_soc_properties[] = {
124
index XXXXXXX..XXXXXXX 100644
87
DEFINE_PROP_UINT32("num-cpus", AspeedSoCState, num_cpus, 0),
125
--- a/hw/arm/imx25_pdk.c
126
+++ b/hw/arm/imx25_pdk.c
127
@@ -XXX,XX +XXX,XX @@
128
#include "qemu/osdep.h"
129
#include "qapi/error.h"
130
#include "cpu.h"
131
+#include "hw/qdev-properties.h"
132
#include "hw/arm/fsl-imx25.h"
133
#include "hw/boards.h"
134
#include "qemu/error-report.h"
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
88
--
157
--
89
2.20.1
158
2.20.1
90
159
91
160
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
1
From: Guenter Roeck <linux@roeck-us.net>
2
2
3
This code is specific to the SoftFloat floating-point
3
i.MX25 supports two USB controllers. Let's wire them up.
4
implementation, which is only used by TCG.
5
4
6
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
5
With this patch, imx25-pdk can boot from both USB ports.
7
Message-id: 20190701132516.26392-18-philmd@redhat.com
6
7
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
8
Message-id: 20200310215146.19688-3-linux@roeck-us.net
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
11
---
11
target/arm/vfp_helper.c | 26 +++++++++++++++++++++++---
12
include/hw/arm/fsl-imx25.h | 9 +++++++++
12
1 file changed, 23 insertions(+), 3 deletions(-)
13
hw/arm/fsl-imx25.c | 24 ++++++++++++++++++++++++
14
2 files changed, 33 insertions(+)
13
15
14
diff --git a/target/arm/vfp_helper.c b/target/arm/vfp_helper.c
16
diff --git a/include/hw/arm/fsl-imx25.h b/include/hw/arm/fsl-imx25.h
15
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
16
--- a/target/arm/vfp_helper.c
18
--- a/include/hw/arm/fsl-imx25.h
17
+++ b/target/arm/vfp_helper.c
19
+++ b/include/hw/arm/fsl-imx25.h
18
@@ -XXX,XX +XXX,XX @@
20
@@ -XXX,XX +XXX,XX @@
19
*/
21
#include "hw/i2c/imx_i2c.h"
20
22
#include "hw/gpio/imx_gpio.h"
21
#include "qemu/osdep.h"
23
#include "hw/sd/sdhci.h"
22
-#include "qemu/log.h"
24
+#include "hw/usb/chipidea.h"
23
#include "cpu.h"
25
#include "exec/memory.h"
24
#include "exec/helper-proto.h"
26
#include "target/arm/cpu.h"
25
-#include "fpu/softfloat.h"
27
26
#include "internals.h"
28
@@ -XXX,XX +XXX,XX @@
27
-
29
#define FSL_IMX25_NUM_I2CS 3
28
+#ifdef CONFIG_TCG
30
#define FSL_IMX25_NUM_GPIOS 4
29
+#include "qemu/log.h"
31
#define FSL_IMX25_NUM_ESDHCS 2
30
+#include "fpu/softfloat.h"
32
+#define FSL_IMX25_NUM_USBS 2
31
+#endif
33
32
34
typedef struct FslIMX25State {
33
/* VFP support. We follow the convention used for VFP instructions:
35
/*< private >*/
34
Single precision routines have a "s" suffix, double precision a
36
@@ -XXX,XX +XXX,XX @@ typedef struct FslIMX25State {
35
"d" suffix. */
37
IMXI2CState i2c[FSL_IMX25_NUM_I2CS];
36
38
IMXGPIOState gpio[FSL_IMX25_NUM_GPIOS];
37
+#ifdef CONFIG_TCG
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
64
index XXXXXXX..XXXXXXX 100644
65
--- a/hw/arm/fsl-imx25.c
66
+++ b/hw/arm/fsl-imx25.c
67
@@ -XXX,XX +XXX,XX @@ static void fsl_imx25_init(Object *obj)
68
sysbus_init_child_obj(obj, "sdhc[*]", &s->esdhc[i], sizeof(s->esdhc[i]),
69
TYPE_IMX_USDHC);
70
}
38
+
71
+
39
/* Convert host exception flags to vfp form. */
72
+ for (i = 0; i < FSL_IMX25_NUM_USBS; i++) {
40
static inline int vfp_exceptbits_from_host(int host_bits)
73
+ sysbus_init_child_obj(obj, "usb[*]", &s->usb[i], sizeof(s->usb[i]),
41
{
74
+ TYPE_CHIPIDEA);
42
@@ -XXX,XX +XXX,XX @@ static void vfp_set_fpscr_to_host(CPUARMState *env, uint32_t val)
75
+ }
43
set_float_exception_flags(0, &env->vfp.standard_fp_status);
76
+
44
}
77
}
45
78
46
+#else
79
static void fsl_imx25_realize(DeviceState *dev, Error **errp)
80
@@ -XXX,XX +XXX,XX @@ static void fsl_imx25_realize(DeviceState *dev, Error **errp)
81
esdhc_table[i].irq));
82
}
83
84
+ /* USB */
85
+ for (i = 0; i < FSL_IMX25_NUM_USBS; i++) {
86
+ static const struct {
87
+ hwaddr addr;
88
+ unsigned int irq;
89
+ } usb_table[FSL_IMX25_NUM_USBS] = {
90
+ { FSL_IMX25_USB1_ADDR, FSL_IMX25_USB1_IRQ },
91
+ { FSL_IMX25_USB2_ADDR, FSL_IMX25_USB2_IRQ },
92
+ };
47
+
93
+
48
+static uint32_t vfp_get_fpscr_from_host(CPUARMState *env)
94
+ object_property_set_bool(OBJECT(&s->usb[i]), true, "realized",
49
+{
95
+ &error_abort);
50
+ return 0;
96
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->usb[i]), 0, usb_table[i].addr);
51
+}
97
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->usb[i]), 0,
98
+ qdev_get_gpio_in(DEVICE(&s->avic),
99
+ usb_table[i].irq));
100
+ }
52
+
101
+
53
+static void vfp_set_fpscr_to_host(CPUARMState *env, uint32_t val)
102
/* initialize 2 x 16 KB ROM */
54
+{
103
memory_region_init_rom(&s->rom[0], NULL,
55
+}
104
"imx25.rom0", FSL_IMX25_ROM0_SIZE, &err);
56
+
57
+#endif
58
+
59
uint32_t HELPER(vfp_get_fpscr)(CPUARMState *env)
60
{
61
uint32_t i, fpscr;
62
@@ -XXX,XX +XXX,XX @@ void vfp_set_fpscr(CPUARMState *env, uint32_t val)
63
HELPER(vfp_set_fpscr)(env, val);
64
}
65
66
+#ifdef CONFIG_TCG
67
+
68
#define VFP_HELPER(name, p) HELPER(glue(glue(vfp_,name),p))
69
70
#define VFP_BINOP(name) \
71
@@ -XXX,XX +XXX,XX @@ float64 HELPER(frint64_d)(float64 f, void *fpst)
72
{
73
return frint_d(f, fpst, 64);
74
}
75
+
76
+#endif
77
--
105
--
78
2.20.1
106
2.20.1
79
107
80
108
diff view generated by jsdifflib
1
From: Hongbo Zhang <hongbo.zhang@linaro.org>
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
2
2
3
Following the previous patch, this patch adds peripheral devices to the
3
The Allwinner H3 is a System on Chip containing four ARM Cortex A7
4
newly introduced SBSA-ref machine.
4
processor cores. Features and specifications include DDR2/DDR3 memory,
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.
5
8
6
Signed-off-by: Hongbo Zhang <hongbo.zhang@linaro.org>
9
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
7
Message-id: 1561890034-15921-3-git-send-email-hongbo.zhang@linaro.org
10
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
12
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
13
Message-id: 20200311221854.30370-2-nieklinnenbank@gmail.com
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
15
---
11
hw/arm/sbsa-ref.c | 535 ++++++++++++++++++++++++++++++++++++++++++++++
16
hw/arm/Makefile.objs | 1 +
12
1 file changed, 535 insertions(+)
17
include/hw/arm/allwinner-h3.h | 106 +++++++++++
18
hw/arm/allwinner-h3.c | 327 ++++++++++++++++++++++++++++++++
19
MAINTAINERS | 7 +
20
default-configs/arm-softmmu.mak | 1 +
21
hw/arm/Kconfig | 8 +
22
6 files changed, 450 insertions(+)
23
create mode 100644 include/hw/arm/allwinner-h3.h
24
create mode 100644 hw/arm/allwinner-h3.c
13
25
14
diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
26
diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
15
index XXXXXXX..XXXXXXX 100644
27
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/arm/sbsa-ref.c
28
--- a/hw/arm/Makefile.objs
17
+++ b/hw/arm/sbsa-ref.c
29
+++ b/hw/arm/Makefile.objs
30
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_DIGIC) += digic.o
31
obj-$(CONFIG_OMAP) += omap1.o omap2.o
32
obj-$(CONFIG_STRONGARM) += strongarm.o
33
obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o
34
+obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3.o
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
39
new file mode 100644
40
index XXXXXXX..XXXXXXX
41
--- /dev/null
42
+++ b/include/hw/arm/allwinner-h3.h
18
@@ -XXX,XX +XXX,XX @@
43
@@ -XXX,XX +XXX,XX @@
19
*/
20
21
#include "qemu/osdep.h"
22
+#include "qemu-common.h"
23
#include "qapi/error.h"
24
#include "qemu/error-report.h"
25
#include "qemu/units.h"
26
+#include "sysemu/device_tree.h"
27
#include "sysemu/numa.h"
28
#include "sysemu/sysemu.h"
29
#include "exec/address-spaces.h"
30
#include "exec/hwaddr.h"
31
#include "kvm_arm.h"
32
#include "hw/arm/boot.h"
33
+#include "hw/block/flash.h"
34
#include "hw/boards.h"
35
+#include "hw/ide/internal.h"
36
+#include "hw/ide/ahci_internal.h"
37
#include "hw/intc/arm_gicv3_common.h"
38
+#include "hw/loader.h"
39
+#include "hw/pci-host/gpex.h"
40
+#include "hw/usb.h"
41
+#include "net/net.h"
42
43
#define RAMLIMIT_GB 8192
44
#define RAMLIMIT_BYTES (RAMLIMIT_GB * GiB)
45
46
+#define NUM_IRQS 256
47
+#define NUM_SMMU_IRQS 4
48
+#define NUM_SATA_PORTS 6
49
+
50
+#define VIRTUAL_PMU_IRQ 7
51
+#define ARCH_GIC_MAINT_IRQ 9
52
+#define ARCH_TIMER_VIRT_IRQ 11
53
+#define ARCH_TIMER_S_EL1_IRQ 13
54
+#define ARCH_TIMER_NS_EL1_IRQ 14
55
+#define ARCH_TIMER_NS_EL2_IRQ 10
56
+
57
enum {
58
SBSA_FLASH,
59
SBSA_MEM,
60
@@ -XXX,XX +XXX,XX @@ typedef struct {
61
void *fdt;
62
int fdt_size;
63
int psci_conduit;
64
+ PFlashCFI01 *flash[2];
65
} SBSAMachineState;
66
67
#define TYPE_SBSA_MACHINE MACHINE_TYPE_NAME("sbsa-ref")
68
@@ -XXX,XX +XXX,XX @@ static const MemMapEntry sbsa_ref_memmap[] = {
69
[SBSA_MEM] = { 0x10000000000ULL, RAMLIMIT_BYTES },
70
};
71
72
+static const int sbsa_ref_irqmap[] = {
73
+ [SBSA_UART] = 1,
74
+ [SBSA_RTC] = 2,
75
+ [SBSA_PCIE] = 3, /* ... to 6 */
76
+ [SBSA_GPIO] = 7,
77
+ [SBSA_SECURE_UART] = 8,
78
+ [SBSA_SECURE_UART_MM] = 9,
79
+ [SBSA_AHCI] = 10,
80
+ [SBSA_EHCI] = 11,
81
+};
82
+
83
+/*
44
+/*
84
+ * Firmware on this machine only uses ACPI table to load OS, these limited
45
+ * Allwinner H3 System on Chip emulation
85
+ * device tree nodes are just to let firmware know the info which varies from
46
+ *
86
+ * command line parameters, so it is not necessary to be fully compatible
47
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
87
+ * with the kernel CPU and NUMA binding rules.
48
+ *
49
+ * This program is free software: you can redistribute it and/or modify
50
+ * it under the terms of the GNU General Public License as published by
51
+ * the Free Software Foundation, either version 2 of the License, or
52
+ * (at your option) any later version.
53
+ *
54
+ * This program is distributed in the hope that it will be useful,
55
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
56
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57
+ * GNU General Public License for more details.
58
+ *
59
+ * You should have received a copy of the GNU General Public License
60
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
88
+ */
61
+ */
89
+static void create_fdt(SBSAMachineState *sms)
62
+
63
+/*
64
+ * The Allwinner H3 is a System on Chip containing four ARM Cortex A7
65
+ * processor cores. Features and specifications include DDR2/DDR3 memory,
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
76
+ */
77
+
78
+#ifndef HW_ARM_ALLWINNER_H3_H
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 {
136
+ /*< private >*/
137
+ DeviceState parent_obj;
138
+ /*< public >*/
139
+
140
+ ARMCPU cpus[AW_H3_NUM_CPUS];
141
+ const hwaddr *memmap;
142
+ AwA10PITState timer;
143
+ GICState gic;
144
+ MemoryRegion sram_a1;
145
+ MemoryRegion sram_a2;
146
+ MemoryRegion sram_c;
147
+} AwH3State;
148
+
149
+#endif /* HW_ARM_ALLWINNER_H3_H */
150
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
151
new file mode 100644
152
index XXXXXXX..XXXXXXX
153
--- /dev/null
154
+++ b/hw/arm/allwinner-h3.c
155
@@ -XXX,XX +XXX,XX @@
156
+/*
157
+ * Allwinner H3 System on Chip emulation
158
+ *
159
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
160
+ *
161
+ * This program is free software: you can redistribute it and/or modify
162
+ * it under the terms of the GNU General Public License as published by
163
+ * the Free Software Foundation, either version 2 of the License, or
164
+ * (at your option) any later version.
165
+ *
166
+ * This program is distributed in the hope that it will be useful,
167
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
168
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
169
+ * GNU General Public License for more details.
170
+ *
171
+ * You should have received a copy of the GNU General Public License
172
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
173
+ */
174
+
175
+#include "qemu/osdep.h"
176
+#include "exec/address-spaces.h"
177
+#include "qapi/error.h"
178
+#include "qemu/error-report.h"
179
+#include "qemu/module.h"
180
+#include "qemu/units.h"
181
+#include "hw/qdev-core.h"
182
+#include "cpu.h"
183
+#include "hw/sysbus.h"
184
+#include "hw/char/serial.h"
185
+#include "hw/misc/unimp.h"
186
+#include "sysemu/sysemu.h"
187
+#include "hw/arm/allwinner-h3.h"
188
+
189
+/* Memory map */
190
+const hwaddr allwinner_h3_memmap[] = {
191
+ [AW_H3_SRAM_A1] = 0x00000000,
192
+ [AW_H3_SRAM_A2] = 0x00044000,
193
+ [AW_H3_SRAM_C] = 0x00010000,
194
+ [AW_H3_PIT] = 0x01c20c00,
195
+ [AW_H3_UART0] = 0x01c28000,
196
+ [AW_H3_UART1] = 0x01c28400,
197
+ [AW_H3_UART2] = 0x01c28800,
198
+ [AW_H3_UART3] = 0x01c28c00,
199
+ [AW_H3_GIC_DIST] = 0x01c81000,
200
+ [AW_H3_GIC_CPU] = 0x01c82000,
201
+ [AW_H3_GIC_HYP] = 0x01c84000,
202
+ [AW_H3_GIC_VCPU] = 0x01c86000,
203
+ [AW_H3_SDRAM] = 0x40000000
204
+};
205
+
206
+/* List of unimplemented devices */
207
+struct AwH3Unimplemented {
208
+ const char *device_name;
209
+ hwaddr base;
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)
90
+{
310
+{
91
+ void *fdt = create_device_tree(&sms->fdt_size);
311
+ AwH3State *s = AW_H3(obj);
92
+ const MachineState *ms = MACHINE(sms);
312
+
93
+ int cpu;
313
+ s->memmap = allwinner_h3_memmap;
94
+
314
+
95
+ if (!fdt) {
315
+ for (int i = 0; i < AW_H3_NUM_CPUS; i++) {
96
+ error_report("create_device_tree() failed");
316
+ object_initialize_child(obj, "cpu[*]", &s->cpus[i], sizeof(s->cpus[i]),
97
+ exit(1);
317
+ ARM_CPU_TYPE_NAME("cortex-a7"),
318
+ &error_abort, NULL);
98
+ }
319
+ }
99
+
320
+
100
+ sms->fdt = fdt;
321
+ sysbus_init_child_obj(obj, "gic", &s->gic, sizeof(s->gic),
101
+
322
+ TYPE_ARM_GIC);
102
+ qemu_fdt_setprop_string(fdt, "/", "compatible", "linux,sbsa-ref");
323
+
103
+ qemu_fdt_setprop_cell(fdt, "/", "#address-cells", 0x2);
324
+ sysbus_init_child_obj(obj, "timer", &s->timer, sizeof(s->timer),
104
+ qemu_fdt_setprop_cell(fdt, "/", "#size-cells", 0x2);
325
+ TYPE_AW_A10_PIT);
105
+
326
+ object_property_add_alias(obj, "clk0-freq", OBJECT(&s->timer),
106
+ if (have_numa_distance) {
327
+ "clk0-freq", &error_abort);
107
+ int size = nb_numa_nodes * nb_numa_nodes * 3 * sizeof(uint32_t);
328
+ object_property_add_alias(obj, "clk1-freq", OBJECT(&s->timer),
108
+ uint32_t *matrix = g_malloc0(size);
329
+ "clk1-freq", &error_abort);
109
+ int idx, i, j;
330
+}
110
+
331
+
111
+ for (i = 0; i < nb_numa_nodes; i++) {
332
+static void allwinner_h3_realize(DeviceState *dev, Error **errp)
112
+ for (j = 0; j < nb_numa_nodes; j++) {
333
+{
113
+ idx = (i * nb_numa_nodes + j) * 3;
334
+ AwH3State *s = AW_H3(dev);
114
+ matrix[idx + 0] = cpu_to_be32(i);
335
+ unsigned i;
115
+ matrix[idx + 1] = cpu_to_be32(j);
336
+
116
+ matrix[idx + 2] = cpu_to_be32(numa_info[i].distance[j]);
337
+ /* CPUs */
117
+ }
338
+ for (i = 0; i < AW_H3_NUM_CPUS; i++) {
118
+ }
339
+
119
+
340
+ /* Provide Power State Coordination Interface */
120
+ qemu_fdt_add_subnode(fdt, "/distance-map");
341
+ qdev_prop_set_int32(DEVICE(&s->cpus[i]), "psci-conduit",
121
+ qemu_fdt_setprop(fdt, "/distance-map", "distance-matrix",
342
+ QEMU_PSCI_CONDUIT_HVC);
122
+ matrix, size);
343
+
123
+ g_free(matrix);
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]));
124
+ }
354
+ }
125
+
355
+
126
+ qemu_fdt_add_subnode(sms->fdt, "/cpus");
356
+ /* Generic Interrupt Controller */
127
+
357
+ qdev_prop_set_uint32(DEVICE(&s->gic), "num-irq", AW_H3_GIC_NUM_SPI +
128
+ for (cpu = sms->smp_cpus - 1; cpu >= 0; cpu--) {
358
+ GIC_INTERNAL);
129
+ char *nodename = g_strdup_printf("/cpus/cpu@%d", cpu);
359
+ qdev_prop_set_uint32(DEVICE(&s->gic), "revision", 2);
130
+ ARMCPU *armcpu = ARM_CPU(qemu_get_cpu(cpu));
360
+ qdev_prop_set_uint32(DEVICE(&s->gic), "num-cpu", AW_H3_NUM_CPUS);
131
+ CPUState *cs = CPU(armcpu);
361
+ qdev_prop_set_bit(DEVICE(&s->gic), "has-security-extensions", false);
132
+
362
+ qdev_prop_set_bit(DEVICE(&s->gic), "has-virtualization-extensions", true);
133
+ qemu_fdt_add_subnode(sms->fdt, nodename);
363
+ qdev_init_nofail(DEVICE(&s->gic));
134
+
364
+
135
+ if (ms->possible_cpus->cpus[cs->cpu_index].props.has_node_id) {
365
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->gic), 0, s->memmap[AW_H3_GIC_DIST]);
136
+ qemu_fdt_setprop_cell(sms->fdt, nodename, "numa-node-id",
366
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->gic), 1, s->memmap[AW_H3_GIC_CPU]);
137
+ ms->possible_cpus->cpus[cs->cpu_index].props.node_id);
367
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->gic), 2, s->memmap[AW_H3_GIC_HYP]);
138
+ }
368
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->gic), 3, s->memmap[AW_H3_GIC_VCPU]);
139
+
140
+ g_free(nodename);
141
+ }
142
+}
143
+
144
+#define SBSA_FLASH_SECTOR_SIZE (256 * KiB)
145
+
146
+static PFlashCFI01 *sbsa_flash_create1(SBSAMachineState *sms,
147
+ const char *name,
148
+ const char *alias_prop_name)
149
+{
150
+ /*
151
+ * Create a single flash device. We use the same parameters as
152
+ * the flash devices on the Versatile Express board.
153
+ */
154
+ DeviceState *dev = qdev_create(NULL, TYPE_PFLASH_CFI01);
155
+
156
+ qdev_prop_set_uint64(dev, "sector-length", SBSA_FLASH_SECTOR_SIZE);
157
+ qdev_prop_set_uint8(dev, "width", 4);
158
+ qdev_prop_set_uint8(dev, "device-width", 2);
159
+ qdev_prop_set_bit(dev, "big-endian", false);
160
+ qdev_prop_set_uint16(dev, "id0", 0x89);
161
+ qdev_prop_set_uint16(dev, "id1", 0x18);
162
+ qdev_prop_set_uint16(dev, "id2", 0x00);
163
+ qdev_prop_set_uint16(dev, "id3", 0x00);
164
+ qdev_prop_set_string(dev, "name", name);
165
+ object_property_add_child(OBJECT(sms), name, OBJECT(dev),
166
+ &error_abort);
167
+ object_property_add_alias(OBJECT(sms), alias_prop_name,
168
+ OBJECT(dev), "drive", &error_abort);
169
+ return PFLASH_CFI01(dev);
170
+}
171
+
172
+static void sbsa_flash_create(SBSAMachineState *sms)
173
+{
174
+ sms->flash[0] = sbsa_flash_create1(sms, "sbsa.flash0", "pflash0");
175
+ sms->flash[1] = sbsa_flash_create1(sms, "sbsa.flash1", "pflash1");
176
+}
177
+
178
+static void sbsa_flash_map1(PFlashCFI01 *flash,
179
+ hwaddr base, hwaddr size,
180
+ MemoryRegion *sysmem)
181
+{
182
+ DeviceState *dev = DEVICE(flash);
183
+
184
+ assert(size % SBSA_FLASH_SECTOR_SIZE == 0);
185
+ assert(size / SBSA_FLASH_SECTOR_SIZE <= UINT32_MAX);
186
+ qdev_prop_set_uint32(dev, "num-blocks", size / SBSA_FLASH_SECTOR_SIZE);
187
+ qdev_init_nofail(dev);
188
+
189
+ memory_region_add_subregion(sysmem, base,
190
+ sysbus_mmio_get_region(SYS_BUS_DEVICE(dev),
191
+ 0));
192
+}
193
+
194
+static void sbsa_flash_map(SBSAMachineState *sms,
195
+ MemoryRegion *sysmem,
196
+ MemoryRegion *secure_sysmem)
197
+{
198
+ /*
199
+ * Map two flash devices to fill the SBSA_FLASH space in the memmap.
200
+ * sysmem is the system memory space. secure_sysmem is the secure view
201
+ * of the system, and the first flash device should be made visible only
202
+ * there. The second flash device is visible to both secure and nonsecure.
203
+ * If sysmem == secure_sysmem this means there is no separate Secure
204
+ * address space and both flash devices are generally visible.
205
+ */
206
+ hwaddr flashsize = sbsa_ref_memmap[SBSA_FLASH].size / 2;
207
+ hwaddr flashbase = sbsa_ref_memmap[SBSA_FLASH].base;
208
+
209
+ sbsa_flash_map1(sms->flash[0], flashbase, flashsize,
210
+ secure_sysmem);
211
+ sbsa_flash_map1(sms->flash[1], flashbase + flashsize, flashsize,
212
+ sysmem);
213
+}
214
+
215
+static bool sbsa_firmware_init(SBSAMachineState *sms,
216
+ MemoryRegion *sysmem,
217
+ MemoryRegion *secure_sysmem)
218
+{
219
+ int i;
220
+ BlockBackend *pflash_blk0;
221
+
222
+ /* Map legacy -drive if=pflash to machine properties */
223
+ for (i = 0; i < ARRAY_SIZE(sms->flash); i++) {
224
+ pflash_cfi01_legacy_drive(sms->flash[i],
225
+ drive_get(IF_PFLASH, 0, i));
226
+ }
227
+
228
+ sbsa_flash_map(sms, sysmem, secure_sysmem);
229
+
230
+ pflash_blk0 = pflash_cfi01_get_blk(sms->flash[0]);
231
+
232
+ if (bios_name) {
233
+ char *fname;
234
+ MemoryRegion *mr;
235
+ int image_size;
236
+
237
+ if (pflash_blk0) {
238
+ error_report("The contents of the first flash device may be "
239
+ "specified with -bios or with -drive if=pflash... "
240
+ "but you cannot use both options at once");
241
+ exit(1);
242
+ }
243
+
244
+ /* Fall back to -bios */
245
+
246
+ fname = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
247
+ if (!fname) {
248
+ error_report("Could not find ROM image '%s'", bios_name);
249
+ exit(1);
250
+ }
251
+ mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(sms->flash[0]), 0);
252
+ image_size = load_image_mr(fname, mr);
253
+ g_free(fname);
254
+ if (image_size < 0) {
255
+ error_report("Could not load ROM image '%s'", bios_name);
256
+ exit(1);
257
+ }
258
+ }
259
+
260
+ return pflash_blk0 || bios_name;
261
+}
262
+
263
+static void create_secure_ram(SBSAMachineState *sms,
264
+ MemoryRegion *secure_sysmem)
265
+{
266
+ MemoryRegion *secram = g_new(MemoryRegion, 1);
267
+ hwaddr base = sbsa_ref_memmap[SBSA_SECURE_MEM].base;
268
+ hwaddr size = sbsa_ref_memmap[SBSA_SECURE_MEM].size;
269
+
270
+ memory_region_init_ram(secram, NULL, "sbsa-ref.secure-ram", size,
271
+ &error_fatal);
272
+ memory_region_add_subregion(secure_sysmem, base, secram);
273
+}
274
+
275
+static void create_gic(SBSAMachineState *sms, qemu_irq *pic)
276
+{
277
+ DeviceState *gicdev;
278
+ SysBusDevice *gicbusdev;
279
+ const char *gictype;
280
+ uint32_t redist0_capacity, redist0_count;
281
+ int i;
282
+
283
+ gictype = gicv3_class_name();
284
+
285
+ gicdev = qdev_create(NULL, gictype);
286
+ qdev_prop_set_uint32(gicdev, "revision", 3);
287
+ qdev_prop_set_uint32(gicdev, "num-cpu", smp_cpus);
288
+ /*
289
+ * Note that the num-irq property counts both internal and external
290
+ * interrupts; there are always 32 of the former (mandated by GIC spec).
291
+ */
292
+ qdev_prop_set_uint32(gicdev, "num-irq", NUM_IRQS + 32);
293
+ qdev_prop_set_bit(gicdev, "has-security-extensions", true);
294
+
295
+ redist0_capacity =
296
+ sbsa_ref_memmap[SBSA_GIC_REDIST].size / GICV3_REDIST_SIZE;
297
+ redist0_count = MIN(smp_cpus, redist0_capacity);
298
+
299
+ qdev_prop_set_uint32(gicdev, "len-redist-region-count", 1);
300
+ qdev_prop_set_uint32(gicdev, "redist-region-count[0]", redist0_count);
301
+
302
+ qdev_init_nofail(gicdev);
303
+ gicbusdev = SYS_BUS_DEVICE(gicdev);
304
+ sysbus_mmio_map(gicbusdev, 0, sbsa_ref_memmap[SBSA_GIC_DIST].base);
305
+ sysbus_mmio_map(gicbusdev, 1, sbsa_ref_memmap[SBSA_GIC_REDIST].base);
306
+
369
+
307
+ /*
370
+ /*
308
+ * Wire the outputs from each CPU's generic timer and the GICv3
371
+ * Wire the outputs from each CPU's generic timer and the GICv3
309
+ * maintenance interrupt signal to the appropriate GIC PPI inputs,
372
+ * maintenance interrupt signal to the appropriate GIC PPI inputs,
310
+ * and the GIC's IRQ/FIQ/VIRQ/VFIQ interrupt outputs to the CPU's inputs.
373
+ * and the GIC's IRQ/FIQ/VIRQ/VFIQ interrupt outputs to the CPU's inputs.
311
+ */
374
+ */
312
+ for (i = 0; i < smp_cpus; i++) {
375
+ for (i = 0; i < AW_H3_NUM_CPUS; i++) {
313
+ DeviceState *cpudev = DEVICE(qemu_get_cpu(i));
376
+ DeviceState *cpudev = DEVICE(&s->cpus[i]);
314
+ int ppibase = NUM_IRQS + i * GIC_INTERNAL + GIC_NR_SGIS;
377
+ int ppibase = AW_H3_GIC_NUM_SPI + i * GIC_INTERNAL + GIC_NR_SGIS;
315
+ int irq;
378
+ int irq;
316
+ /*
379
+ /*
317
+ * Mapping from the output timer irq lines from the CPU to the
380
+ * Mapping from the output timer irq lines from the CPU to the
318
+ * GIC PPI inputs used for this board.
381
+ * GIC PPI inputs used for this board.
319
+ */
382
+ */
320
+ const int timer_irq[] = {
383
+ const int timer_irq[] = {
321
+ [GTIMER_PHYS] = ARCH_TIMER_NS_EL1_IRQ,
384
+ [GTIMER_PHYS] = AW_H3_GIC_PPI_PHYSTIMER,
322
+ [GTIMER_VIRT] = ARCH_TIMER_VIRT_IRQ,
385
+ [GTIMER_VIRT] = AW_H3_GIC_PPI_VIRTTIMER,
323
+ [GTIMER_HYP] = ARCH_TIMER_NS_EL2_IRQ,
386
+ [GTIMER_HYP] = AW_H3_GIC_PPI_HYPTIMER,
324
+ [GTIMER_SEC] = ARCH_TIMER_S_EL1_IRQ,
387
+ [GTIMER_SEC] = AW_H3_GIC_PPI_SECTIMER,
325
+ };
388
+ };
326
+
389
+
390
+ /* Connect CPU timer outputs to GIC PPI inputs */
327
+ for (irq = 0; irq < ARRAY_SIZE(timer_irq); irq++) {
391
+ for (irq = 0; irq < ARRAY_SIZE(timer_irq); irq++) {
328
+ qdev_connect_gpio_out(cpudev, irq,
392
+ qdev_connect_gpio_out(cpudev, irq,
329
+ qdev_get_gpio_in(gicdev,
393
+ qdev_get_gpio_in(DEVICE(&s->gic),
330
+ ppibase + timer_irq[irq]));
394
+ ppibase + timer_irq[irq]));
331
+ }
395
+ }
332
+
396
+
333
+ qdev_connect_gpio_out_named(cpudev, "gicv3-maintenance-interrupt", 0,
397
+ /* Connect GIC outputs to CPU interrupt inputs */
334
+ qdev_get_gpio_in(gicdev, ppibase
398
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i,
335
+ + ARCH_GIC_MAINT_IRQ));
399
+ qdev_get_gpio_in(cpudev, ARM_CPU_IRQ));
336
+ qdev_connect_gpio_out_named(cpudev, "pmu-interrupt", 0,
400
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i + AW_H3_NUM_CPUS,
337
+ qdev_get_gpio_in(gicdev, ppibase
338
+ + VIRTUAL_PMU_IRQ));
339
+
340
+ sysbus_connect_irq(gicbusdev, i, qdev_get_gpio_in(cpudev, ARM_CPU_IRQ));
341
+ sysbus_connect_irq(gicbusdev, i + smp_cpus,
342
+ qdev_get_gpio_in(cpudev, ARM_CPU_FIQ));
401
+ qdev_get_gpio_in(cpudev, ARM_CPU_FIQ));
343
+ sysbus_connect_irq(gicbusdev, i + 2 * smp_cpus,
402
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i + (2 * AW_H3_NUM_CPUS),
344
+ qdev_get_gpio_in(cpudev, ARM_CPU_VIRQ));
403
+ qdev_get_gpio_in(cpudev, ARM_CPU_VIRQ));
345
+ sysbus_connect_irq(gicbusdev, i + 3 * smp_cpus,
404
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i + (3 * AW_H3_NUM_CPUS),
346
+ qdev_get_gpio_in(cpudev, ARM_CPU_VFIQ));
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));
347
+ }
411
+ }
348
+
412
+
349
+ for (i = 0; i < NUM_IRQS; i++) {
413
+ /* Timer */
350
+ pic[i] = qdev_get_gpio_in(gicdev, i);
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);
351
+ }
457
+ }
352
+}
458
+}
353
+
459
+
354
+static void create_uart(const SBSAMachineState *sms, qemu_irq *pic, int uart,
460
+static void allwinner_h3_class_init(ObjectClass *oc, void *data)
355
+ MemoryRegion *mem, Chardev *chr)
356
+{
461
+{
357
+ hwaddr base = sbsa_ref_memmap[uart].base;
462
+ DeviceClass *dc = DEVICE_CLASS(oc);
358
+ int irq = sbsa_ref_irqmap[uart];
463
+
359
+ DeviceState *dev = qdev_create(NULL, "pl011");
464
+ dc->realize = allwinner_h3_realize;
360
+ SysBusDevice *s = SYS_BUS_DEVICE(dev);
465
+ /* Reason: uses serial_hd() in realize function */
361
+
466
+ dc->user_creatable = false;
362
+ qdev_prop_set_chr(dev, "chardev", chr);
363
+ qdev_init_nofail(dev);
364
+ memory_region_add_subregion(mem, base,
365
+ sysbus_mmio_get_region(s, 0));
366
+ sysbus_connect_irq(s, 0, pic[irq]);
367
+}
467
+}
368
+
468
+
369
+static void create_rtc(const SBSAMachineState *sms, qemu_irq *pic)
469
+static const TypeInfo allwinner_h3_type_info = {
470
+ .name = TYPE_AW_H3,
471
+ .parent = TYPE_DEVICE,
472
+ .instance_size = sizeof(AwH3State),
473
+ .instance_init = allwinner_h3_init,
474
+ .class_init = allwinner_h3_class_init,
475
+};
476
+
477
+static void allwinner_h3_register_types(void)
370
+{
478
+{
371
+ hwaddr base = sbsa_ref_memmap[SBSA_RTC].base;
479
+ type_register_static(&allwinner_h3_type_info);
372
+ int irq = sbsa_ref_irqmap[SBSA_RTC];
373
+
374
+ sysbus_create_simple("pl031", base, pic[irq]);
375
+}
480
+}
376
+
481
+
377
+static DeviceState *gpio_key_dev;
482
+type_init(allwinner_h3_register_types)
378
+static void sbsa_ref_powerdown_req(Notifier *n, void *opaque)
483
diff --git a/MAINTAINERS b/MAINTAINERS
379
+{
484
index XXXXXXX..XXXXXXX 100644
380
+ /* use gpio Pin 3 for power button event */
485
--- a/MAINTAINERS
381
+ qemu_set_irq(qdev_get_gpio_in(gpio_key_dev, 0), 1);
486
+++ b/MAINTAINERS
382
+}
487
@@ -XXX,XX +XXX,XX @@ F: hw/*/allwinner*
383
+
488
F: include/hw/*/allwinner*
384
+static Notifier sbsa_ref_powerdown_notifier = {
489
F: hw/arm/cubieboard.c
385
+ .notify = sbsa_ref_powerdown_req
490
386
+};
491
+Allwinner-h3
387
+
492
+M: Niek Linnenbank <nieklinnenbank@gmail.com>
388
+static void create_gpio(const SBSAMachineState *sms, qemu_irq *pic)
493
+L: qemu-arm@nongnu.org
389
+{
494
+S: Maintained
390
+ DeviceState *pl061_dev;
495
+F: hw/*/allwinner-h3*
391
+ hwaddr base = sbsa_ref_memmap[SBSA_GPIO].base;
496
+F: include/hw/*/allwinner-h3*
392
+ int irq = sbsa_ref_irqmap[SBSA_GPIO];
497
+
393
+
498
ARM PrimeCell and CMSDK devices
394
+ pl061_dev = sysbus_create_simple("pl061", base, pic[irq]);
499
M: Peter Maydell <peter.maydell@linaro.org>
395
+
500
L: qemu-arm@nongnu.org
396
+ gpio_key_dev = sysbus_create_simple("gpio-key", -1,
501
diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
397
+ qdev_get_gpio_in(pl061_dev, 3));
502
index XXXXXXX..XXXXXXX 100644
398
+
503
--- a/default-configs/arm-softmmu.mak
399
+ /* connect powerdown request */
504
+++ b/default-configs/arm-softmmu.mak
400
+ qemu_register_powerdown_notifier(&sbsa_ref_powerdown_notifier);
505
@@ -XXX,XX +XXX,XX @@ CONFIG_FSL_IMX25=y
401
+}
506
CONFIG_FSL_IMX7=y
402
+
507
CONFIG_FSL_IMX6UL=y
403
+static void create_ahci(const SBSAMachineState *sms, qemu_irq *pic)
508
CONFIG_SEMIHOSTING=y
404
+{
509
+CONFIG_ALLWINNER_H3=y
405
+ hwaddr base = sbsa_ref_memmap[SBSA_AHCI].base;
510
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
406
+ int irq = sbsa_ref_irqmap[SBSA_AHCI];
511
index XXXXXXX..XXXXXXX 100644
407
+ DeviceState *dev;
512
--- a/hw/arm/Kconfig
408
+ DriveInfo *hd[NUM_SATA_PORTS];
513
+++ b/hw/arm/Kconfig
409
+ SysbusAHCIState *sysahci;
514
@@ -XXX,XX +XXX,XX @@ config ALLWINNER_A10
410
+ AHCIState *ahci;
515
select SERIAL
411
+ int i;
516
select UNIMP
412
+
517
413
+ dev = qdev_create(NULL, "sysbus-ahci");
518
+config ALLWINNER_H3
414
+ qdev_prop_set_uint32(dev, "num-ports", NUM_SATA_PORTS);
519
+ bool
415
+ qdev_init_nofail(dev);
520
+ select ALLWINNER_A10_PIT
416
+ sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
521
+ select SERIAL
417
+ sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, pic[irq]);
522
+ select ARM_TIMER
418
+
523
+ select ARM_GIC
419
+ sysahci = SYSBUS_AHCI(dev);
524
+ select UNIMP
420
+ ahci = &sysahci->ahci;
525
+
421
+ ide_drive_get(hd, ARRAY_SIZE(hd));
526
config RASPI
422
+ for (i = 0; i < ahci->ports; i++) {
527
bool
423
+ if (hd[i] == NULL) {
528
select FRAMEBUFFER
424
+ continue;
425
+ }
426
+ ide_create_drive(&ahci->dev[i].port, 0, hd[i]);
427
+ }
428
+}
429
+
430
+static void create_ehci(const SBSAMachineState *sms, qemu_irq *pic)
431
+{
432
+ hwaddr base = sbsa_ref_memmap[SBSA_EHCI].base;
433
+ int irq = sbsa_ref_irqmap[SBSA_EHCI];
434
+
435
+ sysbus_create_simple("platform-ehci-usb", base, pic[irq]);
436
+}
437
+
438
+static void create_smmu(const SBSAMachineState *sms, qemu_irq *pic,
439
+ PCIBus *bus)
440
+{
441
+ hwaddr base = sbsa_ref_memmap[SBSA_SMMU].base;
442
+ int irq = sbsa_ref_irqmap[SBSA_SMMU];
443
+ DeviceState *dev;
444
+ int i;
445
+
446
+ dev = qdev_create(NULL, "arm-smmuv3");
447
+
448
+ object_property_set_link(OBJECT(dev), OBJECT(bus), "primary-bus",
449
+ &error_abort);
450
+ qdev_init_nofail(dev);
451
+ sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
452
+ for (i = 0; i < NUM_SMMU_IRQS; i++) {
453
+ sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, pic[irq + i]);
454
+ }
455
+}
456
+
457
+static void create_pcie(SBSAMachineState *sms, qemu_irq *pic)
458
+{
459
+ hwaddr base_ecam = sbsa_ref_memmap[SBSA_PCIE_ECAM].base;
460
+ hwaddr size_ecam = sbsa_ref_memmap[SBSA_PCIE_ECAM].size;
461
+ hwaddr base_mmio = sbsa_ref_memmap[SBSA_PCIE_MMIO].base;
462
+ hwaddr size_mmio = sbsa_ref_memmap[SBSA_PCIE_MMIO].size;
463
+ hwaddr base_mmio_high = sbsa_ref_memmap[SBSA_PCIE_MMIO_HIGH].base;
464
+ hwaddr size_mmio_high = sbsa_ref_memmap[SBSA_PCIE_MMIO_HIGH].size;
465
+ hwaddr base_pio = sbsa_ref_memmap[SBSA_PCIE_PIO].base;
466
+ int irq = sbsa_ref_irqmap[SBSA_PCIE];
467
+ MemoryRegion *mmio_alias, *mmio_alias_high, *mmio_reg;
468
+ MemoryRegion *ecam_alias, *ecam_reg;
469
+ DeviceState *dev;
470
+ PCIHostState *pci;
471
+ int i;
472
+
473
+ dev = qdev_create(NULL, TYPE_GPEX_HOST);
474
+ qdev_init_nofail(dev);
475
+
476
+ /* Map ECAM space */
477
+ ecam_alias = g_new0(MemoryRegion, 1);
478
+ ecam_reg = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0);
479
+ memory_region_init_alias(ecam_alias, OBJECT(dev), "pcie-ecam",
480
+ ecam_reg, 0, size_ecam);
481
+ memory_region_add_subregion(get_system_memory(), base_ecam, ecam_alias);
482
+
483
+ /* Map the MMIO space */
484
+ mmio_alias = g_new0(MemoryRegion, 1);
485
+ mmio_reg = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 1);
486
+ memory_region_init_alias(mmio_alias, OBJECT(dev), "pcie-mmio",
487
+ mmio_reg, base_mmio, size_mmio);
488
+ memory_region_add_subregion(get_system_memory(), base_mmio, mmio_alias);
489
+
490
+ /* Map the MMIO_HIGH space */
491
+ mmio_alias_high = g_new0(MemoryRegion, 1);
492
+ memory_region_init_alias(mmio_alias_high, OBJECT(dev), "pcie-mmio-high",
493
+ mmio_reg, base_mmio_high, size_mmio_high);
494
+ memory_region_add_subregion(get_system_memory(), base_mmio_high,
495
+ mmio_alias_high);
496
+
497
+ /* Map IO port space */
498
+ sysbus_mmio_map(SYS_BUS_DEVICE(dev), 2, base_pio);
499
+
500
+ for (i = 0; i < GPEX_NUM_IRQS; i++) {
501
+ sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, pic[irq + i]);
502
+ gpex_set_irq_num(GPEX_HOST(dev), i, irq + i);
503
+ }
504
+
505
+ pci = PCI_HOST_BRIDGE(dev);
506
+ if (pci->bus) {
507
+ for (i = 0; i < nb_nics; i++) {
508
+ NICInfo *nd = &nd_table[i];
509
+
510
+ if (!nd->model) {
511
+ nd->model = g_strdup("e1000e");
512
+ }
513
+
514
+ pci_nic_init_nofail(nd, pci->bus, nd->model, NULL);
515
+ }
516
+ }
517
+
518
+ pci_create_simple(pci->bus, -1, "VGA");
519
+
520
+ create_smmu(sms, pic, pci->bus);
521
+}
522
+
523
+static void *sbsa_ref_dtb(const struct arm_boot_info *binfo, int *fdt_size)
524
+{
525
+ const SBSAMachineState *board = container_of(binfo, SBSAMachineState,
526
+ bootinfo);
527
+
528
+ *fdt_size = board->fdt_size;
529
+ return board->fdt;
530
+}
531
+
532
static void sbsa_ref_init(MachineState *machine)
533
{
534
SBSAMachineState *sms = SBSA_MACHINE(machine);
535
@@ -XXX,XX +XXX,XX @@ static void sbsa_ref_init(MachineState *machine)
536
MemoryRegion *sysmem = get_system_memory();
537
MemoryRegion *secure_sysmem = NULL;
538
MemoryRegion *ram = g_new(MemoryRegion, 1);
539
+ bool firmware_loaded;
540
const CPUArchIdList *possible_cpus;
541
int n, sbsa_max_cpus;
542
+ qemu_irq pic[NUM_IRQS];
543
544
if (strcmp(machine->cpu_type, ARM_CPU_TYPE_NAME("cortex-a57"))) {
545
error_report("sbsa-ref: CPU type other than the built-in "
546
@@ -XXX,XX +XXX,XX @@ static void sbsa_ref_init(MachineState *machine)
547
exit(1);
548
}
549
550
+ /*
551
+ * The Secure view of the world is the same as the NonSecure,
552
+ * but with a few extra devices. Create it as a container region
553
+ * containing the system memory at low priority; any secure-only
554
+ * devices go in at higher priority and take precedence.
555
+ */
556
+ secure_sysmem = g_new(MemoryRegion, 1);
557
+ memory_region_init(secure_sysmem, OBJECT(machine), "secure-memory",
558
+ UINT64_MAX);
559
+ memory_region_add_subregion_overlap(secure_sysmem, 0, sysmem, -1);
560
+
561
+ firmware_loaded = sbsa_firmware_init(sms, sysmem,
562
+ secure_sysmem ?: sysmem);
563
+
564
+ if (machine->kernel_filename && firmware_loaded) {
565
+ error_report("sbsa-ref: No fw_cfg device on this machine, "
566
+ "so -kernel option is not supported when firmware loaded, "
567
+ "please load OS from hard disk instead");
568
+ exit(1);
569
+ }
570
+
571
/*
572
* This machine has EL3 enabled, external firmware should supply PSCI
573
* implementation, so the QEMU's internal PSCI is disabled.
574
@@ -XXX,XX +XXX,XX @@ static void sbsa_ref_init(MachineState *machine)
575
machine->ram_size);
576
memory_region_add_subregion(sysmem, sbsa_ref_memmap[SBSA_MEM].base, ram);
577
578
+ create_fdt(sms);
579
+
580
+ create_secure_ram(sms, secure_sysmem);
581
+
582
+ create_gic(sms, pic);
583
+
584
+ create_uart(sms, pic, SBSA_UART, sysmem, serial_hd(0));
585
+ create_uart(sms, pic, SBSA_SECURE_UART, secure_sysmem, serial_hd(1));
586
+ /* Second secure UART for RAS and MM from EL0 */
587
+ create_uart(sms, pic, SBSA_SECURE_UART_MM, secure_sysmem, serial_hd(2));
588
+
589
+ create_rtc(sms, pic);
590
+
591
+ create_gpio(sms, pic);
592
+
593
+ create_ahci(sms, pic);
594
+
595
+ create_ehci(sms, pic);
596
+
597
+ create_pcie(sms, pic);
598
+
599
sms->bootinfo.ram_size = machine->ram_size;
600
sms->bootinfo.kernel_filename = machine->kernel_filename;
601
sms->bootinfo.nb_cpus = smp_cpus;
602
sms->bootinfo.board_id = -1;
603
sms->bootinfo.loader_start = sbsa_ref_memmap[SBSA_MEM].base;
604
+ sms->bootinfo.get_dtb = sbsa_ref_dtb;
605
+ sms->bootinfo.firmware_loaded = firmware_loaded;
606
arm_load_kernel(ARM_CPU(first_cpu), &sms->bootinfo);
607
}
608
609
@@ -XXX,XX +XXX,XX @@ sbsa_ref_get_default_cpu_node_id(const MachineState *ms, int idx)
610
return idx % nb_numa_nodes;
611
}
612
613
+static void sbsa_ref_instance_init(Object *obj)
614
+{
615
+ SBSAMachineState *sms = SBSA_MACHINE(obj);
616
+
617
+ sbsa_flash_create(sms);
618
+}
619
+
620
static void sbsa_ref_class_init(ObjectClass *oc, void *data)
621
{
622
MachineClass *mc = MACHINE_CLASS(oc);
623
@@ -XXX,XX +XXX,XX @@ static void sbsa_ref_class_init(ObjectClass *oc, void *data)
624
static const TypeInfo sbsa_ref_info = {
625
.name = TYPE_SBSA_MACHINE,
626
.parent = TYPE_MACHINE,
627
+ .instance_init = sbsa_ref_instance_init,
628
.class_init = sbsa_ref_class_init,
629
.instance_size = sizeof(SBSAMachineState),
630
};
631
--
529
--
632
2.20.1
530
2.20.1
633
531
634
532
diff view generated by jsdifflib
1
From: Hongbo Zhang <hongbo.zhang@linaro.org>
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
2
2
3
For AArch64, the existing "virt" machine is primarily meant to
3
The Xunlong Orange Pi PC is an Allwinner H3 System on Chip
4
run on KVM and execute virtualization workloads, but we need an
4
based embedded computer with mainline support in both U-Boot
5
environment as faithful as possible to physical hardware, for supporting
5
and Linux. The board comes with a Quad Core Cortex A7 @ 1.3GHz,
6
firmware and OS development for physical Aarch64 machines.
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.
7
9
8
This patch introduces new machine type 'sbsa-ref' with main features:
10
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
9
- Based on 'virt' machine type.
11
Tested-by: KONRAD Frederic <frederic.konrad@adacore.com>
10
- A new memory map.
12
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
11
- CPU type cortex-a57.
13
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
12
- EL2 and EL3 are enabled.
14
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
13
- GIC version 3.
15
Acked-by: Igor Mammedov <imammedo@redhat.com>
14
- System bus AHCI controller.
16
Message-id: 20200311221854.30370-3-nieklinnenbank@gmail.com
15
- System bus EHCI controller.
16
- CDROM and hard disc on AHCI bus.
17
- E1000E ethernet card on PCIE bus.
18
- VGA display adaptor on PCIE bus.
19
- No virtio devices.
20
- No fw_cfg device.
21
- No ACPI table supplied.
22
- Only minimal device tree nodes.
23
24
Arm Trusted Firmware and UEFI porting to this are done accordingly,
25
and the firmware should supply ACPI tables to the guest OS. The
26
minimal device tree nodes supplied by QEMU for this platform are only
27
to pass the dynamic info reflecting command line input to firmware,
28
not for loading the guest OS.
29
30
To make the review easier, this task is split into two patches, the
31
fundamental skeleton part and the peripheral devices part; this patch is
32
the first part.
33
34
Signed-off-by: Hongbo Zhang <hongbo.zhang@linaro.org>
35
Message-id: 1561890034-15921-2-git-send-email-hongbo.zhang@linaro.org
36
[PMM: commit message tweaks; moved some bits between patch 1 and 2
37
to ensure patch 1 builds cleanly; removed unneeded lines from
38
Kconfig stanza; only provide board for qemu-system-aarch64, not
39
qemu-system-arm; added MAINTAINERS entry]
40
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
41
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
42
---
18
---
43
hw/arm/Makefile.objs | 1 +
19
hw/arm/Makefile.objs | 2 +-
44
hw/arm/sbsa-ref.c | 271 ++++++++++++++++++++++++++++
20
hw/arm/orangepi.c | 92 ++++++++++++++++++++++++++++++++++++++++++++
45
MAINTAINERS | 8 +
21
MAINTAINERS | 1 +
46
default-configs/aarch64-softmmu.mak | 1 +
22
3 files changed, 94 insertions(+), 1 deletion(-)
47
hw/arm/Kconfig | 14 ++
23
create mode 100644 hw/arm/orangepi.c
48
5 files changed, 295 insertions(+)
49
create mode 100644 hw/arm/sbsa-ref.c
50
24
51
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
52
index XXXXXXX..XXXXXXX 100644
26
index XXXXXXX..XXXXXXX 100644
53
--- a/hw/arm/Makefile.objs
27
--- a/hw/arm/Makefile.objs
54
+++ b/hw/arm/Makefile.objs
28
+++ b/hw/arm/Makefile.objs
55
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_SPITZ) += spitz.o
29
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_DIGIC) += digic.o
56
obj-$(CONFIG_TOSA) += tosa.o
30
obj-$(CONFIG_OMAP) += omap1.o omap2.o
57
obj-$(CONFIG_Z2) += z2.o
31
obj-$(CONFIG_STRONGARM) += strongarm.o
58
obj-$(CONFIG_REALVIEW) += realview.o
32
obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o
59
+obj-$(CONFIG_SBSA_REF) += sbsa-ref.o
33
-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3.o
60
obj-$(CONFIG_STELLARIS) += stellaris.o
34
+obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3.o orangepi.o
61
obj-$(CONFIG_COLLIE) += collie.o
35
obj-$(CONFIG_RASPI) += bcm2835_peripherals.o bcm2836.o raspi.o
62
obj-$(CONFIG_VERSATILE) += versatilepb.o
36
obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o
63
diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
37
obj-$(CONFIG_STM32F405_SOC) += stm32f405_soc.o
38
diff --git a/hw/arm/orangepi.c b/hw/arm/orangepi.c
64
new file mode 100644
39
new file mode 100644
65
index XXXXXXX..XXXXXXX
40
index XXXXXXX..XXXXXXX
66
--- /dev/null
41
--- /dev/null
67
+++ b/hw/arm/sbsa-ref.c
42
+++ b/hw/arm/orangepi.c
68
@@ -XXX,XX +XXX,XX @@
43
@@ -XXX,XX +XXX,XX @@
69
+/*
44
+/*
70
+ * ARM SBSA Reference Platform emulation
45
+ * Orange Pi emulation
71
+ *
46
+ *
72
+ * Copyright (c) 2018 Linaro Limited
47
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
73
+ * Written by Hongbo Zhang <hongbo.zhang@linaro.org>
74
+ *
48
+ *
75
+ * This program is free software; you can redistribute it and/or modify it
49
+ * This program is free software: you can redistribute it and/or modify
76
+ * under the terms and conditions of the GNU General Public License,
50
+ * it under the terms of the GNU General Public License as published by
77
+ * version 2 or later, as published by the Free Software Foundation.
51
+ * the Free Software Foundation, either version 2 of the License, or
52
+ * (at your option) any later version.
78
+ *
53
+ *
79
+ * This program is distributed in the hope it will be useful, but WITHOUT
54
+ * This program is distributed in the hope that it will be useful,
80
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
55
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
81
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
56
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
82
+ * more details.
57
+ * GNU General Public License for more details.
83
+ *
58
+ *
84
+ * You should have received a copy of the GNU General Public License along with
59
+ * You should have received a copy of the GNU General Public License
85
+ * this program. If not, see <http://www.gnu.org/licenses/>.
60
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
86
+ */
61
+ */
87
+
62
+
88
+#include "qemu/osdep.h"
63
+#include "qemu/osdep.h"
64
+#include "qemu/units.h"
65
+#include "exec/address-spaces.h"
89
+#include "qapi/error.h"
66
+#include "qapi/error.h"
90
+#include "qemu/error-report.h"
67
+#include "cpu.h"
91
+#include "qemu/units.h"
68
+#include "hw/sysbus.h"
92
+#include "sysemu/numa.h"
69
+#include "hw/boards.h"
70
+#include "hw/qdev-properties.h"
71
+#include "hw/arm/allwinner-h3.h"
93
+#include "sysemu/sysemu.h"
72
+#include "sysemu/sysemu.h"
94
+#include "exec/address-spaces.h"
95
+#include "exec/hwaddr.h"
96
+#include "kvm_arm.h"
97
+#include "hw/arm/boot.h"
98
+#include "hw/boards.h"
99
+#include "hw/intc/arm_gicv3_common.h"
100
+
73
+
101
+#define RAMLIMIT_GB 8192
74
+static struct arm_boot_info orangepi_binfo = {
102
+#define RAMLIMIT_BYTES (RAMLIMIT_GB * GiB)
75
+ .nb_cpus = AW_H3_NUM_CPUS,
103
+
104
+enum {
105
+ SBSA_FLASH,
106
+ SBSA_MEM,
107
+ SBSA_CPUPERIPHS,
108
+ SBSA_GIC_DIST,
109
+ SBSA_GIC_REDIST,
110
+ SBSA_SMMU,
111
+ SBSA_UART,
112
+ SBSA_RTC,
113
+ SBSA_PCIE,
114
+ SBSA_PCIE_MMIO,
115
+ SBSA_PCIE_MMIO_HIGH,
116
+ SBSA_PCIE_PIO,
117
+ SBSA_PCIE_ECAM,
118
+ SBSA_GPIO,
119
+ SBSA_SECURE_UART,
120
+ SBSA_SECURE_UART_MM,
121
+ SBSA_SECURE_MEM,
122
+ SBSA_AHCI,
123
+ SBSA_EHCI,
124
+};
76
+};
125
+
77
+
126
+typedef struct MemMapEntry {
78
+static void orangepi_init(MachineState *machine)
127
+ hwaddr base;
79
+{
128
+ hwaddr size;
80
+ AwH3State *h3;
129
+} MemMapEntry;
130
+
81
+
131
+typedef struct {
82
+ /* BIOS is not supported by this board */
132
+ MachineState parent;
83
+ if (bios_name) {
133
+ struct arm_boot_info bootinfo;
84
+ error_report("BIOS not supported for this machine");
134
+ int smp_cpus;
135
+ void *fdt;
136
+ int fdt_size;
137
+ int psci_conduit;
138
+} SBSAMachineState;
139
+
140
+#define TYPE_SBSA_MACHINE MACHINE_TYPE_NAME("sbsa-ref")
141
+#define SBSA_MACHINE(obj) \
142
+ OBJECT_CHECK(SBSAMachineState, (obj), TYPE_SBSA_MACHINE)
143
+
144
+static const MemMapEntry sbsa_ref_memmap[] = {
145
+ /* 512M boot ROM */
146
+ [SBSA_FLASH] = { 0, 0x20000000 },
147
+ /* 512M secure memory */
148
+ [SBSA_SECURE_MEM] = { 0x20000000, 0x20000000 },
149
+ /* Space reserved for CPU peripheral devices */
150
+ [SBSA_CPUPERIPHS] = { 0x40000000, 0x00040000 },
151
+ [SBSA_GIC_DIST] = { 0x40060000, 0x00010000 },
152
+ [SBSA_GIC_REDIST] = { 0x40080000, 0x04000000 },
153
+ [SBSA_UART] = { 0x60000000, 0x00001000 },
154
+ [SBSA_RTC] = { 0x60010000, 0x00001000 },
155
+ [SBSA_GPIO] = { 0x60020000, 0x00001000 },
156
+ [SBSA_SECURE_UART] = { 0x60030000, 0x00001000 },
157
+ [SBSA_SECURE_UART_MM] = { 0x60040000, 0x00001000 },
158
+ [SBSA_SMMU] = { 0x60050000, 0x00020000 },
159
+ /* Space here reserved for more SMMUs */
160
+ [SBSA_AHCI] = { 0x60100000, 0x00010000 },
161
+ [SBSA_EHCI] = { 0x60110000, 0x00010000 },
162
+ /* Space here reserved for other devices */
163
+ [SBSA_PCIE_PIO] = { 0x7fff0000, 0x00010000 },
164
+ /* 32-bit address PCIE MMIO space */
165
+ [SBSA_PCIE_MMIO] = { 0x80000000, 0x70000000 },
166
+ /* 256M PCIE ECAM space */
167
+ [SBSA_PCIE_ECAM] = { 0xf0000000, 0x10000000 },
168
+ /* ~1TB PCIE MMIO space (4GB to 1024GB boundary) */
169
+ [SBSA_PCIE_MMIO_HIGH] = { 0x100000000ULL, 0xFF00000000ULL },
170
+ [SBSA_MEM] = { 0x10000000000ULL, RAMLIMIT_BYTES },
171
+};
172
+
173
+static void sbsa_ref_init(MachineState *machine)
174
+{
175
+ SBSAMachineState *sms = SBSA_MACHINE(machine);
176
+ MachineClass *mc = MACHINE_GET_CLASS(machine);
177
+ MemoryRegion *sysmem = get_system_memory();
178
+ MemoryRegion *secure_sysmem = NULL;
179
+ MemoryRegion *ram = g_new(MemoryRegion, 1);
180
+ const CPUArchIdList *possible_cpus;
181
+ int n, sbsa_max_cpus;
182
+
183
+ if (strcmp(machine->cpu_type, ARM_CPU_TYPE_NAME("cortex-a57"))) {
184
+ error_report("sbsa-ref: CPU type other than the built-in "
185
+ "cortex-a57 not supported");
186
+ exit(1);
85
+ exit(1);
187
+ }
86
+ }
188
+
87
+
189
+ if (kvm_enabled()) {
88
+ /* This board has fixed size RAM */
190
+ error_report("sbsa-ref: KVM is not supported for this machine");
89
+ if (machine->ram_size != 1 * GiB) {
90
+ error_report("This machine can only be used with 1GiB of RAM");
191
+ exit(1);
91
+ exit(1);
192
+ }
92
+ }
193
+
93
+
194
+ /*
94
+ /* Only allow Cortex-A7 for this board */
195
+ * This machine has EL3 enabled, external firmware should supply PSCI
95
+ if (strcmp(machine->cpu_type, ARM_CPU_TYPE_NAME("cortex-a7")) != 0) {
196
+ * implementation, so the QEMU's internal PSCI is disabled.
96
+ error_report("This board can only be used with cortex-a7 CPU");
197
+ */
198
+ sms->psci_conduit = QEMU_PSCI_CONDUIT_DISABLED;
199
+
200
+ sbsa_max_cpus = sbsa_ref_memmap[SBSA_GIC_REDIST].size / GICV3_REDIST_SIZE;
201
+
202
+ if (max_cpus > sbsa_max_cpus) {
203
+ error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
204
+ "supported by machine 'sbsa-ref' (%d)",
205
+ max_cpus, sbsa_max_cpus);
206
+ exit(1);
97
+ exit(1);
207
+ }
98
+ }
208
+
99
+
209
+ sms->smp_cpus = smp_cpus;
100
+ h3 = AW_H3(object_new(TYPE_AW_H3));
101
+ object_property_add_child(OBJECT(machine), "soc", OBJECT(h3),
102
+ &error_abort);
103
+ object_unref(OBJECT(h3));
210
+
104
+
211
+ if (machine->ram_size > sbsa_ref_memmap[SBSA_MEM].size) {
105
+ /* Setup timer properties */
212
+ error_report("sbsa-ref: cannot model more than %dGB RAM", RAMLIMIT_GB);
106
+ object_property_set_int(OBJECT(h3), 32768, "clk0-freq",
213
+ exit(1);
107
+ &error_abort);
214
+ }
108
+ object_property_set_int(OBJECT(h3), 24 * 1000 * 1000, "clk1-freq",
109
+ &error_abort);
215
+
110
+
216
+ possible_cpus = mc->possible_cpu_arch_ids(machine);
111
+ /* Mark H3 object realized */
217
+ for (n = 0; n < possible_cpus->len; n++) {
112
+ object_property_set_bool(OBJECT(h3), true, "realized", &error_abort);
218
+ Object *cpuobj;
219
+ CPUState *cs;
220
+
113
+
221
+ if (n >= smp_cpus) {
114
+ /* SDRAM */
222
+ break;
115
+ memory_region_add_subregion(get_system_memory(), h3->memmap[AW_H3_SDRAM],
223
+ }
116
+ machine->ram);
224
+
117
+
225
+ cpuobj = object_new(possible_cpus->cpus[n].type);
118
+ orangepi_binfo.loader_start = h3->memmap[AW_H3_SDRAM];
226
+ object_property_set_int(cpuobj, possible_cpus->cpus[n].arch_id,
119
+ orangepi_binfo.ram_size = machine->ram_size;
227
+ "mp-affinity", NULL);
120
+ arm_load_kernel(ARM_CPU(first_cpu), machine, &orangepi_binfo);
228
+
229
+ cs = CPU(cpuobj);
230
+ cs->cpu_index = n;
231
+
232
+ numa_cpu_pre_plug(&possible_cpus->cpus[cs->cpu_index], DEVICE(cpuobj),
233
+ &error_fatal);
234
+
235
+ if (object_property_find(cpuobj, "reset-cbar", NULL)) {
236
+ object_property_set_int(cpuobj,
237
+ sbsa_ref_memmap[SBSA_CPUPERIPHS].base,
238
+ "reset-cbar", &error_abort);
239
+ }
240
+
241
+ object_property_set_link(cpuobj, OBJECT(sysmem), "memory",
242
+ &error_abort);
243
+
244
+ object_property_set_link(cpuobj, OBJECT(secure_sysmem),
245
+ "secure-memory", &error_abort);
246
+
247
+ object_property_set_bool(cpuobj, true, "realized", &error_fatal);
248
+ object_unref(cpuobj);
249
+ }
250
+
251
+ memory_region_allocate_system_memory(ram, NULL, "sbsa-ref.ram",
252
+ machine->ram_size);
253
+ memory_region_add_subregion(sysmem, sbsa_ref_memmap[SBSA_MEM].base, ram);
254
+
255
+ sms->bootinfo.ram_size = machine->ram_size;
256
+ sms->bootinfo.kernel_filename = machine->kernel_filename;
257
+ sms->bootinfo.nb_cpus = smp_cpus;
258
+ sms->bootinfo.board_id = -1;
259
+ sms->bootinfo.loader_start = sbsa_ref_memmap[SBSA_MEM].base;
260
+ arm_load_kernel(ARM_CPU(first_cpu), &sms->bootinfo);
261
+}
121
+}
262
+
122
+
263
+static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx)
123
+static void orangepi_machine_init(MachineClass *mc)
264
+{
124
+{
265
+ uint8_t clustersz = ARM_DEFAULT_CPUS_PER_CLUSTER;
125
+ mc->desc = "Orange Pi PC";
266
+ return arm_cpu_mp_affinity(idx, clustersz);
126
+ mc->init = orangepi_init;
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";
267
+}
133
+}
268
+
134
+
269
+static const CPUArchIdList *sbsa_ref_possible_cpu_arch_ids(MachineState *ms)
135
+DEFINE_MACHINE("orangepi-pc", orangepi_machine_init)
270
+{
271
+ SBSAMachineState *sms = SBSA_MACHINE(ms);
272
+ int n;
273
+
274
+ if (ms->possible_cpus) {
275
+ assert(ms->possible_cpus->len == max_cpus);
276
+ return ms->possible_cpus;
277
+ }
278
+
279
+ ms->possible_cpus = g_malloc0(sizeof(CPUArchIdList) +
280
+ sizeof(CPUArchId) * max_cpus);
281
+ ms->possible_cpus->len = max_cpus;
282
+ for (n = 0; n < ms->possible_cpus->len; n++) {
283
+ ms->possible_cpus->cpus[n].type = ms->cpu_type;
284
+ ms->possible_cpus->cpus[n].arch_id =
285
+ sbsa_ref_cpu_mp_affinity(sms, n);
286
+ ms->possible_cpus->cpus[n].props.has_thread_id = true;
287
+ ms->possible_cpus->cpus[n].props.thread_id = n;
288
+ }
289
+ return ms->possible_cpus;
290
+}
291
+
292
+static CpuInstanceProperties
293
+sbsa_ref_cpu_index_to_props(MachineState *ms, unsigned cpu_index)
294
+{
295
+ MachineClass *mc = MACHINE_GET_CLASS(ms);
296
+ const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(ms);
297
+
298
+ assert(cpu_index < possible_cpus->len);
299
+ return possible_cpus->cpus[cpu_index].props;
300
+}
301
+
302
+static int64_t
303
+sbsa_ref_get_default_cpu_node_id(const MachineState *ms, int idx)
304
+{
305
+ return idx % nb_numa_nodes;
306
+}
307
+
308
+static void sbsa_ref_class_init(ObjectClass *oc, void *data)
309
+{
310
+ MachineClass *mc = MACHINE_CLASS(oc);
311
+
312
+ mc->init = sbsa_ref_init;
313
+ mc->desc = "QEMU 'SBSA Reference' ARM Virtual Machine";
314
+ mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a57");
315
+ mc->max_cpus = 512;
316
+ mc->pci_allow_0_address = true;
317
+ mc->minimum_page_bits = 12;
318
+ mc->block_default_type = IF_IDE;
319
+ mc->no_cdrom = 1;
320
+ mc->default_ram_size = 1 * GiB;
321
+ mc->default_cpus = 4;
322
+ mc->possible_cpu_arch_ids = sbsa_ref_possible_cpu_arch_ids;
323
+ mc->cpu_index_to_instance_props = sbsa_ref_cpu_index_to_props;
324
+ mc->get_default_cpu_node_id = sbsa_ref_get_default_cpu_node_id;
325
+}
326
+
327
+static const TypeInfo sbsa_ref_info = {
328
+ .name = TYPE_SBSA_MACHINE,
329
+ .parent = TYPE_MACHINE,
330
+ .class_init = sbsa_ref_class_init,
331
+ .instance_size = sizeof(SBSAMachineState),
332
+};
333
+
334
+static void sbsa_ref_machine_init(void)
335
+{
336
+ type_register_static(&sbsa_ref_info);
337
+}
338
+
339
+type_init(sbsa_ref_machine_init);
340
diff --git a/MAINTAINERS b/MAINTAINERS
136
diff --git a/MAINTAINERS b/MAINTAINERS
341
index XXXXXXX..XXXXXXX 100644
137
index XXXXXXX..XXXXXXX 100644
342
--- a/MAINTAINERS
138
--- a/MAINTAINERS
343
+++ b/MAINTAINERS
139
+++ b/MAINTAINERS
344
@@ -XXX,XX +XXX,XX @@ F: include/hw/arm/fsl-imx6.h
140
@@ -XXX,XX +XXX,XX @@ L: qemu-arm@nongnu.org
345
F: include/hw/misc/imx6_*.h
141
S: Maintained
346
F: include/hw/ssi/imx_spi.h
142
F: hw/*/allwinner-h3*
347
143
F: include/hw/*/allwinner-h3*
348
+SBSA-REF
144
+F: hw/arm/orangepi.c
349
+M: Radoslaw Biernacki <radoslaw.biernacki@linaro.org>
145
350
+M: Peter Maydell <peter.maydell@linaro.org>
146
ARM PrimeCell and CMSDK devices
351
+R: Leif Lindholm <leif.lindholm@linaro.org>
352
+L: qemu-arm@nongnu.org
353
+S: Maintained
354
+F: hw/arm/sbsa-ref.c
355
+
356
Sharp SL-5500 (Collie) PDA
357
M: Peter Maydell <peter.maydell@linaro.org>
147
M: Peter Maydell <peter.maydell@linaro.org>
358
L: qemu-arm@nongnu.org
359
diff --git a/default-configs/aarch64-softmmu.mak b/default-configs/aarch64-softmmu.mak
360
index XXXXXXX..XXXXXXX 100644
361
--- a/default-configs/aarch64-softmmu.mak
362
+++ b/default-configs/aarch64-softmmu.mak
363
@@ -XXX,XX +XXX,XX @@ include arm-softmmu.mak
364
365
CONFIG_XLNX_ZYNQMP_ARM=y
366
CONFIG_XLNX_VERSAL=y
367
+CONFIG_SBSA_REF=y
368
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
369
index XXXXXXX..XXXXXXX 100644
370
--- a/hw/arm/Kconfig
371
+++ b/hw/arm/Kconfig
372
@@ -XXX,XX +XXX,XX @@ config REALVIEW
373
select DS1338 # I2C RTC+NVRAM
374
select USB_OHCI
375
376
+config SBSA_REF
377
+ bool
378
+ imply PCI_DEVICES
379
+ select AHCI
380
+ select ARM_SMMUV3
381
+ select GPIO_KEY
382
+ select PCI_EXPRESS
383
+ select PCI_EXPRESS_GENERIC_BRIDGE
384
+ select PFLASH_CFI01
385
+ select PL011 # UART
386
+ select PL031 # RTC
387
+ select PL061 # GPIO
388
+ select USB_EHCI_SYSBUS
389
+
390
config SABRELITE
391
bool
392
select FSL_IMX6
393
--
148
--
394
2.20.1
149
2.20.1
395
150
396
151
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
2
2
3
The vfp_set_fpscr() helper contains code specific to the host
3
The Clock Control Unit is responsible for clock signal generation,
4
floating point implementation (here the SoftFloat library).
4
configuration and distribution in the Allwinner H3 System on Chip.
5
Extract this code to vfp_set_fpscr_to_host().
5
This commit adds support for the Clock Control Unit which emulates
6
a simple read/write register interface.
6
7
7
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
8
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
8
Message-id: 20190701132516.26392-16-philmd@redhat.com
9
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
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
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
14
---
12
target/arm/vfp_helper.c | 127 +++++++++++++++++++++-------------------
15
hw/misc/Makefile.objs | 1 +
13
1 file changed, 66 insertions(+), 61 deletions(-)
16
include/hw/arm/allwinner-h3.h | 3 +
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
14
23
15
diff --git a/target/arm/vfp_helper.c b/target/arm/vfp_helper.c
24
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
16
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
17
--- a/target/arm/vfp_helper.c
26
--- a/hw/misc/Makefile.objs
18
+++ b/target/arm/vfp_helper.c
27
+++ b/hw/misc/Makefile.objs
19
@@ -XXX,XX +XXX,XX @@ static inline int vfp_exceptbits_to_host(int target_bits)
28
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_MACIO) += macio/
20
return host_bits;
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
40
@@ -XXX,XX +XXX,XX @@
41
#include "hw/arm/boot.h"
42
#include "hw/timer/allwinner-a10-pit.h"
43
#include "hw/intc/arm_gic.h"
44
+#include "hw/misc/allwinner-h3-ccu.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_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);
21
}
163
}
22
164
23
-uint32_t HELPER(vfp_get_fpscr)(CPUARMState *env)
165
static void allwinner_h3_realize(DeviceState *dev, Error **errp)
24
-{
166
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
25
- uint32_t i, fpscr;
167
memory_region_add_subregion(get_system_memory(), s->memmap[AW_H3_SRAM_C],
26
-
168
&s->sram_c);
27
- fpscr = env->vfp.xregs[ARM_VFP_FPSCR]
169
28
- | (env->vfp.vec_len << 16)
170
+ /* Clock Control Unit */
29
- | (env->vfp.vec_stride << 20);
171
+ qdev_init_nofail(DEVICE(&s->ccu));
30
-
172
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->ccu), 0, s->memmap[AW_H3_CCU]);
31
- i = get_float_exception_flags(&env->vfp.fp_status);
173
+
32
- i |= get_float_exception_flags(&env->vfp.standard_fp_status);
174
/* UART0. For future clocktree API: All UARTS are connected to APB2_CLK. */
33
- /* FZ16 does not generate an input denormal exception. */
175
serial_mm_init(get_system_memory(), s->memmap[AW_H3_UART0], 2,
34
- i |= (get_float_exception_flags(&env->vfp.fp_status_f16)
176
qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_UART0),
35
- & ~float_flag_input_denormal);
177
diff --git a/hw/misc/allwinner-h3-ccu.c b/hw/misc/allwinner-h3-ccu.c
36
- fpscr |= vfp_exceptbits_from_host(i);
178
new file mode 100644
37
-
179
index XXXXXXX..XXXXXXX
38
- i = env->vfp.qc[0] | env->vfp.qc[1] | env->vfp.qc[2] | env->vfp.qc[3];
180
--- /dev/null
39
- fpscr |= i ? FPCR_QC : 0;
181
+++ b/hw/misc/allwinner-h3-ccu.c
40
-
182
@@ -XXX,XX +XXX,XX @@
41
- return fpscr;
183
+/*
42
-}
184
+ * Allwinner H3 Clock Control Unit emulation
43
-
185
+ *
44
-uint32_t vfp_get_fpscr(CPUARMState *env)
186
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
45
-{
187
+ *
46
- return HELPER(vfp_get_fpscr)(env);
188
+ * This program is free software: you can redistribute it and/or modify
47
-}
189
+ * it under the terms of the GNU General Public License as published by
48
-
190
+ * the Free Software Foundation, either version 2 of the License, or
49
-void HELPER(vfp_set_fpscr)(CPUARMState *env, uint32_t val)
191
+ * (at your option) any later version.
50
+static void vfp_set_fpscr_to_host(CPUARMState *env, uint32_t val)
192
+ *
51
{
193
+ * This program is distributed in the hope that it will be useful,
52
int i;
194
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
53
uint32_t changed = env->vfp.xregs[ARM_VFP_FPSCR];
195
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
54
196
+ * GNU General Public License for more details.
55
- /* When ARMv8.2-FP16 is not supported, FZ16 is RES0. */
197
+ *
56
- if (!cpu_isar_feature(aa64_fp16, env_archcpu(env))) {
198
+ * You should have received a copy of the GNU General Public License
57
- val &= ~FPCR_FZ16;
199
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
58
- }
200
+ */
59
-
201
+
60
- if (arm_feature(env, ARM_FEATURE_M)) {
202
+#include "qemu/osdep.h"
61
- /*
203
+#include "qemu/units.h"
62
- * M profile FPSCR is RES0 for the QC, STRIDE, FZ16, LEN bits
204
+#include "hw/sysbus.h"
63
- * and also for the trapped-exception-handling bits IxE.
205
+#include "migration/vmstate.h"
64
- */
206
+#include "qemu/log.h"
65
- val &= 0xf7c0009f;
207
+#include "qemu/module.h"
66
- }
208
+#include "hw/misc/allwinner-h3-ccu.h"
67
-
209
+
68
- /*
210
+/* CCU register offsets */
69
- * We don't implement trapped exception handling, so the
211
+enum {
70
- * trap enable bits, IDE|IXE|UFE|OFE|DZE|IOE are all RAZ/WI (not RES0!)
212
+ REG_PLL_CPUX = 0x0000, /* PLL CPUX Control */
71
- *
213
+ REG_PLL_AUDIO = 0x0008, /* PLL Audio Control */
72
- * If we exclude the exception flags, IOC|DZC|OFC|UFC|IXC|IDC
214
+ REG_PLL_VIDEO = 0x0010, /* PLL Video Control */
73
- * (which are stored in fp_status), and the other RES0 bits
215
+ REG_PLL_VE = 0x0018, /* PLL VE Control */
74
- * in between, then we clear all of the low 16 bits.
216
+ REG_PLL_DDR = 0x0020, /* PLL DDR Control */
75
- */
217
+ REG_PLL_PERIPH0 = 0x0028, /* PLL Peripherals 0 Control */
76
- env->vfp.xregs[ARM_VFP_FPSCR] = val & 0xf7c80000;
218
+ REG_PLL_GPU = 0x0038, /* PLL GPU Control */
77
- env->vfp.vec_len = (val >> 16) & 7;
219
+ REG_PLL_PERIPH1 = 0x0044, /* PLL Peripherals 1 Control */
78
- env->vfp.vec_stride = (val >> 20) & 3;
220
+ REG_PLL_DE = 0x0048, /* PLL Display Engine Control */
79
-
221
+ REG_CPUX_AXI = 0x0050, /* CPUX/AXI Configuration */
80
- /*
222
+ REG_APB1 = 0x0054, /* ARM Peripheral Bus 1 Config */
81
- * The bit we set within fpscr_q is arbitrary; the register as a
223
+ REG_APB2 = 0x0058, /* ARM Peripheral Bus 2 Config */
82
- * whole being zero/non-zero is what counts.
224
+ REG_DRAM_CFG = 0x00F4, /* DRAM Configuration */
83
- */
225
+ REG_MBUS = 0x00FC, /* MBUS Reset */
84
- env->vfp.qc[0] = val & FPCR_QC;
226
+ REG_PLL_TIME0 = 0x0200, /* PLL Stable Time 0 */
85
- env->vfp.qc[1] = 0;
227
+ REG_PLL_TIME1 = 0x0204, /* PLL Stable Time 1 */
86
- env->vfp.qc[2] = 0;
228
+ REG_PLL_CPUX_BIAS = 0x0220, /* PLL CPUX Bias */
87
- env->vfp.qc[3] = 0;
229
+ REG_PLL_AUDIO_BIAS = 0x0224, /* PLL Audio Bias */
88
-
230
+ REG_PLL_VIDEO_BIAS = 0x0228, /* PLL Video Bias */
89
changed ^= val;
231
+ REG_PLL_VE_BIAS = 0x022C, /* PLL VE Bias */
90
if (changed & (3 << 22)) {
232
+ REG_PLL_DDR_BIAS = 0x0230, /* PLL DDR Bias */
91
i = (val >> 22) & 3;
233
+ REG_PLL_PERIPH0_BIAS = 0x0234, /* PLL Peripherals 0 Bias */
92
@@ -XXX,XX +XXX,XX @@ void HELPER(vfp_set_fpscr)(CPUARMState *env, uint32_t val)
234
+ REG_PLL_GPU_BIAS = 0x023C, /* PLL GPU Bias */
93
set_float_exception_flags(0, &env->vfp.standard_fp_status);
235
+ REG_PLL_PERIPH1_BIAS = 0x0244, /* PLL Peripherals 1 Bias */
94
}
236
+ REG_PLL_DE_BIAS = 0x0248, /* PLL Display Engine Bias */
95
237
+ REG_PLL_CPUX_TUNING = 0x0250, /* PLL CPUX Tuning */
96
+uint32_t HELPER(vfp_get_fpscr)(CPUARMState *env)
238
+ REG_PLL_DDR_TUNING = 0x0260, /* PLL DDR Tuning */
97
+{
239
+};
98
+ uint32_t i, fpscr;
240
+
99
+
241
+#define REG_INDEX(offset) (offset / sizeof(uint32_t))
100
+ fpscr = env->vfp.xregs[ARM_VFP_FPSCR]
242
+
101
+ | (env->vfp.vec_len << 16)
243
+/* CCU register flags */
102
+ | (env->vfp.vec_stride << 20);
244
+enum {
103
+
245
+ REG_DRAM_CFG_UPDATE = (1 << 16),
104
+ i = get_float_exception_flags(&env->vfp.fp_status);
246
+};
105
+ i |= get_float_exception_flags(&env->vfp.standard_fp_status);
247
+
106
+ /* FZ16 does not generate an input denormal exception. */
248
+enum {
107
+ i |= (get_float_exception_flags(&env->vfp.fp_status_f16)
249
+ REG_PLL_ENABLE = (1 << 31),
108
+ & ~float_flag_input_denormal);
250
+ REG_PLL_LOCK = (1 << 28),
109
+ fpscr |= vfp_exceptbits_from_host(i);
251
+};
110
+
252
+
111
+ i = env->vfp.qc[0] | env->vfp.qc[1] | env->vfp.qc[2] | env->vfp.qc[3];
253
+
112
+ fpscr |= i ? FPCR_QC : 0;
254
+/* CCU register reset values */
113
+
255
+enum {
114
+ return fpscr;
256
+ REG_PLL_CPUX_RST = 0x00001000,
115
+}
257
+ REG_PLL_AUDIO_RST = 0x00035514,
116
+
258
+ REG_PLL_VIDEO_RST = 0x03006207,
117
+uint32_t vfp_get_fpscr(CPUARMState *env)
259
+ REG_PLL_VE_RST = 0x03006207,
118
+{
260
+ REG_PLL_DDR_RST = 0x00001000,
119
+ return HELPER(vfp_get_fpscr)(env);
261
+ REG_PLL_PERIPH0_RST = 0x00041811,
120
+}
262
+ REG_PLL_GPU_RST = 0x03006207,
121
+
263
+ REG_PLL_PERIPH1_RST = 0x00041811,
122
+void HELPER(vfp_set_fpscr)(CPUARMState *env, uint32_t val)
264
+ REG_PLL_DE_RST = 0x03006207,
123
+{
265
+ REG_CPUX_AXI_RST = 0x00010000,
124
+ /* When ARMv8.2-FP16 is not supported, FZ16 is RES0. */
266
+ REG_APB1_RST = 0x00001010,
125
+ if (!cpu_isar_feature(aa64_fp16, env_archcpu(env))) {
267
+ REG_APB2_RST = 0x01000000,
126
+ val &= ~FPCR_FZ16;
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;
127
+ }
296
+ }
128
+
297
+
129
+ if (arm_feature(env, ARM_FEATURE_M)) {
298
+ return s->regs[idx];
130
+ /*
299
+}
131
+ * M profile FPSCR is RES0 for the QC, STRIDE, FZ16, LEN bits
300
+
132
+ * and also for the trapped-exception-handling bits IxE.
301
+static void allwinner_h3_ccu_write(void *opaque, hwaddr offset,
133
+ */
302
+ uint64_t val, unsigned size)
134
+ val &= 0xf7c0009f;
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;
135
+ }
332
+ }
136
+
333
+
137
+ /*
334
+ s->regs[idx] = (uint32_t) val;
138
+ * We don't implement trapped exception handling, so the
335
+}
139
+ * trap enable bits, IDE|IXE|UFE|OFE|DZE|IOE are all RAZ/WI (not RES0!)
336
+
140
+ *
337
+static const MemoryRegionOps allwinner_h3_ccu_ops = {
141
+ * If we exclude the exception flags, IOC|DZC|OFC|UFC|IXC|IDC
338
+ .read = allwinner_h3_ccu_read,
142
+ * (which are stored in fp_status), and the other RES0 bits
339
+ .write = allwinner_h3_ccu_write,
143
+ * in between, then we clear all of the low 16 bits.
340
+ .endianness = DEVICE_NATIVE_ENDIAN,
144
+ */
341
+ .valid = {
145
+ env->vfp.xregs[ARM_VFP_FPSCR] = val & 0xf7c80000;
342
+ .min_access_size = 4,
146
+ env->vfp.vec_len = (val >> 16) & 7;
343
+ .max_access_size = 4,
147
+ env->vfp.vec_stride = (val >> 20) & 3;
344
+ },
148
+
345
+ .impl.min_access_size = 4,
149
+ /*
346
+};
150
+ * The bit we set within fpscr_q is arbitrary; the register as a
347
+
151
+ * whole being zero/non-zero is what counts.
348
+static void allwinner_h3_ccu_reset(DeviceState *dev)
152
+ */
349
+{
153
+ env->vfp.qc[0] = val & FPCR_QC;
350
+ AwH3ClockCtlState *s = AW_H3_CCU(dev);
154
+ env->vfp.qc[1] = 0;
351
+
155
+ env->vfp.qc[2] = 0;
352
+ /* Set default values for registers */
156
+ env->vfp.qc[3] = 0;
353
+ s->regs[REG_INDEX(REG_PLL_CPUX)] = REG_PLL_CPUX_RST;
157
+
354
+ s->regs[REG_INDEX(REG_PLL_AUDIO)] = REG_PLL_AUDIO_RST;
158
+ vfp_set_fpscr_to_host(env, val);
355
+ s->regs[REG_INDEX(REG_PLL_VIDEO)] = REG_PLL_VIDEO_RST;
159
+}
356
+ s->regs[REG_INDEX(REG_PLL_VE)] = REG_PLL_VE_RST;
160
+
357
+ s->regs[REG_INDEX(REG_PLL_DDR)] = REG_PLL_DDR_RST;
161
void vfp_set_fpscr(CPUARMState *env, uint32_t val)
358
+ s->regs[REG_INDEX(REG_PLL_PERIPH0)] = REG_PLL_PERIPH0_RST;
162
{
359
+ s->regs[REG_INDEX(REG_PLL_GPU)] = REG_PLL_GPU_RST;
163
HELPER(vfp_set_fpscr)(env, val);
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()
400
+ }
401
+};
402
+
403
+static void allwinner_h3_ccu_class_init(ObjectClass *klass, void *data)
404
+{
405
+ DeviceClass *dc = DEVICE_CLASS(klass);
406
+
407
+ dc->reset = allwinner_h3_ccu_reset;
408
+ dc->vmsd = &allwinner_h3_ccu_vmstate;
409
+}
410
+
411
+static const TypeInfo allwinner_h3_ccu_info = {
412
+ .name = TYPE_AW_H3_CCU,
413
+ .parent = TYPE_SYS_BUS_DEVICE,
414
+ .instance_init = allwinner_h3_ccu_init,
415
+ .instance_size = sizeof(AwH3ClockCtlState),
416
+ .class_init = allwinner_h3_ccu_class_init,
417
+};
418
+
419
+static void allwinner_h3_ccu_register(void)
420
+{
421
+ type_register_static(&allwinner_h3_ccu_info);
422
+}
423
+
424
+type_init(allwinner_h3_ccu_register)
164
--
425
--
165
2.20.1
426
2.20.1
166
427
167
428
diff view generated by jsdifflib
1
From: Cédric Le Goater <clg@kaod.org>
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
2
2
3
This will simplify the definition of new SoCs, like the AST2600 which
3
The Allwinner H3 System on Chip contains multiple USB 2.0 bus
4
should use a slightly different address space and have a different set
4
connections which provide software access using the Enhanced
5
of controllers.
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.
6
8
7
Signed-off-by: Cédric Le Goater <clg@kaod.org>
9
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
10
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
8
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
11
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
9
Reviewed-by: Joel Stanley <joel@jms.id.au>
12
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
10
Message-id: 20190618165311.27066-3-clg@kaod.org
13
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
14
Message-id: 20200311221854.30370-5-nieklinnenbank@gmail.com
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
16
---
13
include/hw/arm/aspeed_soc.h | 4 +-
17
hw/usb/hcd-ehci.h | 1 +
14
hw/arm/aspeed.c | 8 +--
18
include/hw/arm/allwinner-h3.h | 8 +++++++
15
hw/arm/aspeed_soc.c | 117 ++++++++++++++++++++++--------------
19
hw/arm/allwinner-h3.c | 44 +++++++++++++++++++++++++++++++++++
16
3 files changed, 78 insertions(+), 51 deletions(-)
20
hw/usb/hcd-ehci-sysbus.c | 17 ++++++++++++++
21
hw/arm/Kconfig | 2 ++
22
5 files changed, 72 insertions(+)
17
23
18
diff --git a/include/hw/arm/aspeed_soc.h b/include/hw/arm/aspeed_soc.h
24
diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h
19
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
20
--- a/include/hw/arm/aspeed_soc.h
26
--- a/hw/usb/hcd-ehci.h
21
+++ b/include/hw/arm/aspeed_soc.h
27
+++ b/hw/usb/hcd-ehci.h
22
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedSoCInfo {
28
@@ -XXX,XX +XXX,XX @@ typedef struct EHCIPCIState {
23
const char *name;
29
#define TYPE_SYS_BUS_EHCI "sysbus-ehci-usb"
24
const char *cpu_type;
30
#define TYPE_PLATFORM_EHCI "platform-ehci-usb"
25
uint32_t silicon_rev;
31
#define TYPE_EXYNOS4210_EHCI "exynos4210-ehci-usb"
26
- hwaddr sdram_base;
32
+#define TYPE_AW_H3_EHCI "aw-h3-ehci-usb"
27
uint64_t sram_size;
33
#define TYPE_TEGRA2_EHCI "tegra2-ehci-usb"
28
int spis_num;
34
#define TYPE_PPC4xx_EHCI "ppc4xx-ehci-usb"
29
- const hwaddr *spi_bases;
35
#define TYPE_FUSBH200_EHCI "fusbh200-ehci-usb"
30
const char *fmc_typename;
36
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
31
const char **spi_typename;
37
index XXXXXXX..XXXXXXX 100644
32
int wdts_num;
38
--- a/include/hw/arm/allwinner-h3.h
33
const int *irqmap;
39
+++ b/include/hw/arm/allwinner-h3.h
34
+ const hwaddr *memmap;
35
} AspeedSoCInfo;
36
37
typedef struct AspeedSoCClass {
38
@@ -XXX,XX +XXX,XX @@ enum {
40
@@ -XXX,XX +XXX,XX @@ enum {
39
ASPEED_I2C,
41
AW_H3_SRAM_A1,
40
ASPEED_ETH1,
42
AW_H3_SRAM_A2,
41
ASPEED_ETH2,
43
AW_H3_SRAM_C,
42
+ ASPEED_SDRAM,
44
+ AW_H3_EHCI0,
45
+ AW_H3_OHCI0,
46
+ AW_H3_EHCI1,
47
+ AW_H3_OHCI1,
48
+ AW_H3_EHCI2,
49
+ AW_H3_OHCI2,
50
+ AW_H3_EHCI3,
51
+ AW_H3_OHCI3,
52
AW_H3_CCU,
53
AW_H3_PIT,
54
AW_H3_UART0,
55
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
56
index XXXXXXX..XXXXXXX 100644
57
--- a/hw/arm/allwinner-h3.c
58
+++ b/hw/arm/allwinner-h3.c
59
@@ -XXX,XX +XXX,XX @@
60
#include "hw/sysbus.h"
61
#include "hw/char/serial.h"
62
#include "hw/misc/unimp.h"
63
+#include "hw/usb/hcd-ehci.h"
64
#include "sysemu/sysemu.h"
65
#include "hw/arm/allwinner-h3.h"
66
67
@@ -XXX,XX +XXX,XX @@ const hwaddr allwinner_h3_memmap[] = {
68
[AW_H3_SRAM_A1] = 0x00000000,
69
[AW_H3_SRAM_A2] = 0x00044000,
70
[AW_H3_SRAM_C] = 0x00010000,
71
+ [AW_H3_EHCI0] = 0x01c1a000,
72
+ [AW_H3_OHCI0] = 0x01c1a400,
73
+ [AW_H3_EHCI1] = 0x01c1b000,
74
+ [AW_H3_OHCI1] = 0x01c1b400,
75
+ [AW_H3_EHCI2] = 0x01c1c000,
76
+ [AW_H3_OHCI2] = 0x01c1c400,
77
+ [AW_H3_EHCI3] = 0x01c1d000,
78
+ [AW_H3_OHCI3] = 0x01c1d400,
79
[AW_H3_CCU] = 0x01c20000,
80
[AW_H3_PIT] = 0x01c20c00,
81
[AW_H3_UART0] = 0x01c28000,
82
@@ -XXX,XX +XXX,XX @@ enum {
83
AW_H3_GIC_SPI_UART3 = 3,
84
AW_H3_GIC_SPI_TIMER0 = 18,
85
AW_H3_GIC_SPI_TIMER1 = 19,
86
+ AW_H3_GIC_SPI_EHCI0 = 72,
87
+ AW_H3_GIC_SPI_OHCI0 = 73,
88
+ AW_H3_GIC_SPI_EHCI1 = 74,
89
+ AW_H3_GIC_SPI_OHCI1 = 75,
90
+ AW_H3_GIC_SPI_EHCI2 = 76,
91
+ AW_H3_GIC_SPI_OHCI2 = 77,
92
+ AW_H3_GIC_SPI_EHCI3 = 78,
93
+ AW_H3_GIC_SPI_OHCI3 = 79,
43
};
94
};
44
95
45
#endif /* ASPEED_SOC_H */
96
/* Allwinner H3 general constants */
46
diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c
97
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
98
qdev_init_nofail(DEVICE(&s->ccu));
99
sysbus_mmio_map(SYS_BUS_DEVICE(&s->ccu), 0, s->memmap[AW_H3_CCU]);
100
101
+ /* Universal Serial Bus */
102
+ sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0],
103
+ qdev_get_gpio_in(DEVICE(&s->gic),
104
+ AW_H3_GIC_SPI_EHCI0));
105
+ sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI1],
106
+ qdev_get_gpio_in(DEVICE(&s->gic),
107
+ AW_H3_GIC_SPI_EHCI1));
108
+ sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI2],
109
+ qdev_get_gpio_in(DEVICE(&s->gic),
110
+ AW_H3_GIC_SPI_EHCI2));
111
+ sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI3],
112
+ qdev_get_gpio_in(DEVICE(&s->gic),
113
+ AW_H3_GIC_SPI_EHCI3));
114
+
115
+ sysbus_create_simple("sysbus-ohci", s->memmap[AW_H3_OHCI0],
116
+ qdev_get_gpio_in(DEVICE(&s->gic),
117
+ AW_H3_GIC_SPI_OHCI0));
118
+ sysbus_create_simple("sysbus-ohci", s->memmap[AW_H3_OHCI1],
119
+ qdev_get_gpio_in(DEVICE(&s->gic),
120
+ AW_H3_GIC_SPI_OHCI1));
121
+ sysbus_create_simple("sysbus-ohci", s->memmap[AW_H3_OHCI2],
122
+ qdev_get_gpio_in(DEVICE(&s->gic),
123
+ AW_H3_GIC_SPI_OHCI2));
124
+ sysbus_create_simple("sysbus-ohci", s->memmap[AW_H3_OHCI3],
125
+ qdev_get_gpio_in(DEVICE(&s->gic),
126
+ AW_H3_GIC_SPI_OHCI3));
127
+
128
/* UART0. For future clocktree API: All UARTS are connected to APB2_CLK. */
129
serial_mm_init(get_system_memory(), s->memmap[AW_H3_UART0], 2,
130
qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_UART0),
131
diff --git a/hw/usb/hcd-ehci-sysbus.c b/hw/usb/hcd-ehci-sysbus.c
47
index XXXXXXX..XXXXXXX 100644
132
index XXXXXXX..XXXXXXX 100644
48
--- a/hw/arm/aspeed.c
133
--- a/hw/usb/hcd-ehci-sysbus.c
49
+++ b/hw/arm/aspeed.c
134
+++ b/hw/usb/hcd-ehci-sysbus.c
50
@@ -XXX,XX +XXX,XX @@ static void aspeed_board_init(MachineState *machine,
135
@@ -XXX,XX +XXX,XX @@ static const TypeInfo ehci_exynos4210_type_info = {
51
&error_abort);
136
.class_init = ehci_exynos4210_class_init,
52
137
};
53
memory_region_allocate_system_memory(&bmc->ram, NULL, "ram", ram_size);
138
54
- memory_region_add_subregion(get_system_memory(), sc->info->sdram_base,
139
+static void ehci_aw_h3_class_init(ObjectClass *oc, void *data)
55
- &bmc->ram);
140
+{
56
+ memory_region_add_subregion(get_system_memory(),
141
+ SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc);
57
+ sc->info->memmap[ASPEED_SDRAM], &bmc->ram);
142
+ DeviceClass *dc = DEVICE_CLASS(oc);
58
object_property_add_const_link(OBJECT(&bmc->soc), "ram", OBJECT(&bmc->ram),
59
&error_abort);
60
61
@@ -XXX,XX +XXX,XX @@ static void aspeed_board_init(MachineState *machine,
62
memory_region_init_io(&bmc->max_ram, NULL, &max_ram_ops, NULL,
63
"max_ram", max_ram_size - ram_size);
64
memory_region_add_subregion(get_system_memory(),
65
- sc->info->sdram_base + ram_size,
66
+ sc->info->memmap[ASPEED_SDRAM] + ram_size,
67
&bmc->max_ram);
68
69
aspeed_board_init_flashes(&bmc->soc.fmc, cfg->fmc_model, &error_abort);
70
@@ -XXX,XX +XXX,XX @@ static void aspeed_board_init(MachineState *machine,
71
aspeed_board_binfo.initrd_filename = machine->initrd_filename;
72
aspeed_board_binfo.kernel_cmdline = machine->kernel_cmdline;
73
aspeed_board_binfo.ram_size = ram_size;
74
- aspeed_board_binfo.loader_start = sc->info->sdram_base;
75
+ aspeed_board_binfo.loader_start = sc->info->memmap[ASPEED_SDRAM];
76
77
if (cfg->i2c_init) {
78
cfg->i2c_init(bmc);
79
diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c
80
index XXXXXXX..XXXXXXX 100644
81
--- a/hw/arm/aspeed_soc.c
82
+++ b/hw/arm/aspeed_soc.c
83
@@ -XXX,XX +XXX,XX @@
84
#include "hw/i2c/aspeed_i2c.h"
85
#include "net/net.h"
86
87
-#define ASPEED_SOC_UART_5_BASE 0x00184000
88
#define ASPEED_SOC_IOMEM_SIZE 0x00200000
89
-#define ASPEED_SOC_IOMEM_BASE 0x1E600000
90
-#define ASPEED_SOC_FMC_BASE 0x1E620000
91
-#define ASPEED_SOC_SPI_BASE 0x1E630000
92
-#define ASPEED_SOC_SPI2_BASE 0x1E631000
93
-#define ASPEED_SOC_VIC_BASE 0x1E6C0000
94
-#define ASPEED_SOC_SDMC_BASE 0x1E6E0000
95
-#define ASPEED_SOC_SCU_BASE 0x1E6E2000
96
-#define ASPEED_SOC_SRAM_BASE 0x1E720000
97
-#define ASPEED_SOC_TIMER_BASE 0x1E782000
98
-#define ASPEED_SOC_WDT_BASE 0x1E785000
99
-#define ASPEED_SOC_I2C_BASE 0x1E78A000
100
-#define ASPEED_SOC_ETH1_BASE 0x1E660000
101
-#define ASPEED_SOC_ETH2_BASE 0x1E680000
102
+
143
+
103
+static const hwaddr aspeed_soc_ast2400_memmap[] = {
144
+ sec->capsbase = 0x0;
104
+ [ASPEED_IOMEM] = 0x1E600000,
145
+ sec->opregbase = 0x10;
105
+ [ASPEED_FMC] = 0x1E620000,
146
+ set_bit(DEVICE_CATEGORY_USB, dc->categories);
106
+ [ASPEED_SPI1] = 0x1E630000,
147
+}
107
+ [ASPEED_VIC] = 0x1E6C0000,
148
+
108
+ [ASPEED_SDMC] = 0x1E6E0000,
149
+static const TypeInfo ehci_aw_h3_type_info = {
109
+ [ASPEED_SCU] = 0x1E6E2000,
150
+ .name = TYPE_AW_H3_EHCI,
110
+ [ASPEED_ADC] = 0x1E6E9000,
151
+ .parent = TYPE_SYS_BUS_EHCI,
111
+ [ASPEED_SRAM] = 0x1E720000,
152
+ .class_init = ehci_aw_h3_class_init,
112
+ [ASPEED_GPIO] = 0x1E780000,
113
+ [ASPEED_RTC] = 0x1E781000,
114
+ [ASPEED_TIMER1] = 0x1E782000,
115
+ [ASPEED_WDT] = 0x1E785000,
116
+ [ASPEED_PWM] = 0x1E786000,
117
+ [ASPEED_LPC] = 0x1E789000,
118
+ [ASPEED_IBT] = 0x1E789140,
119
+ [ASPEED_I2C] = 0x1E78A000,
120
+ [ASPEED_ETH1] = 0x1E660000,
121
+ [ASPEED_ETH2] = 0x1E680000,
122
+ [ASPEED_UART1] = 0x1E783000,
123
+ [ASPEED_UART5] = 0x1E784000,
124
+ [ASPEED_VUART] = 0x1E787000,
125
+ [ASPEED_SDRAM] = 0x40000000,
126
+};
153
+};
127
+
154
+
128
+static const hwaddr aspeed_soc_ast2500_memmap[] = {
155
static void ehci_tegra2_class_init(ObjectClass *oc, void *data)
129
+ [ASPEED_IOMEM] = 0x1E600000,
156
{
130
+ [ASPEED_FMC] = 0x1E620000,
157
SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc);
131
+ [ASPEED_SPI1] = 0x1E630000,
158
@@ -XXX,XX +XXX,XX @@ static void ehci_sysbus_register_types(void)
132
+ [ASPEED_SPI2] = 0x1E631000,
159
type_register_static(&ehci_type_info);
133
+ [ASPEED_VIC] = 0x1E6C0000,
160
type_register_static(&ehci_platform_type_info);
134
+ [ASPEED_SDMC] = 0x1E6E0000,
161
type_register_static(&ehci_exynos4210_type_info);
135
+ [ASPEED_SCU] = 0x1E6E2000,
162
+ type_register_static(&ehci_aw_h3_type_info);
136
+ [ASPEED_ADC] = 0x1E6E9000,
163
type_register_static(&ehci_tegra2_type_info);
137
+ [ASPEED_SRAM] = 0x1E720000,
164
type_register_static(&ehci_ppc4xx_type_info);
138
+ [ASPEED_GPIO] = 0x1E780000,
165
type_register_static(&ehci_fusbh200_type_info);
139
+ [ASPEED_RTC] = 0x1E781000,
166
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
140
+ [ASPEED_TIMER1] = 0x1E782000,
167
index XXXXXXX..XXXXXXX 100644
141
+ [ASPEED_WDT] = 0x1E785000,
168
--- a/hw/arm/Kconfig
142
+ [ASPEED_PWM] = 0x1E786000,
169
+++ b/hw/arm/Kconfig
143
+ [ASPEED_LPC] = 0x1E789000,
170
@@ -XXX,XX +XXX,XX @@ config ALLWINNER_H3
144
+ [ASPEED_IBT] = 0x1E789140,
171
select ARM_TIMER
145
+ [ASPEED_I2C] = 0x1E78A000,
172
select ARM_GIC
146
+ [ASPEED_ETH1] = 0x1E660000,
173
select UNIMP
147
+ [ASPEED_ETH2] = 0x1E680000,
174
+ select USB_OHCI
148
+ [ASPEED_UART1] = 0x1E783000,
175
+ select USB_EHCI_SYSBUS
149
+ [ASPEED_UART5] = 0x1E784000,
176
150
+ [ASPEED_VUART] = 0x1E787000,
177
config RASPI
151
+ [ASPEED_SDRAM] = 0x80000000,
178
bool
152
+};
153
154
static const int aspeed_soc_ast2400_irqmap[] = {
155
[ASPEED_UART1] = 9,
156
@@ -XXX,XX +XXX,XX @@ static const int aspeed_soc_ast2400_irqmap[] = {
157
[ASPEED_ETH2] = 3,
158
};
159
160
-#define AST2400_SDRAM_BASE 0x40000000
161
-#define AST2500_SDRAM_BASE 0x80000000
162
-
163
-/* AST2500 uses the same IRQs as the AST2400 */
164
#define aspeed_soc_ast2500_irqmap aspeed_soc_ast2400_irqmap
165
166
-static const hwaddr aspeed_soc_ast2400_spi_bases[] = { ASPEED_SOC_SPI_BASE };
167
static const char *aspeed_soc_ast2400_typenames[] = { "aspeed.smc.spi" };
168
-
169
-static const hwaddr aspeed_soc_ast2500_spi_bases[] = { ASPEED_SOC_SPI_BASE,
170
- ASPEED_SOC_SPI2_BASE};
171
static const char *aspeed_soc_ast2500_typenames[] = {
172
"aspeed.smc.ast2500-spi1", "aspeed.smc.ast2500-spi2" };
173
174
@@ -XXX,XX +XXX,XX @@ static const AspeedSoCInfo aspeed_socs[] = {
175
.name = "ast2400-a0",
176
.cpu_type = ARM_CPU_TYPE_NAME("arm926"),
177
.silicon_rev = AST2400_A0_SILICON_REV,
178
- .sdram_base = AST2400_SDRAM_BASE,
179
.sram_size = 0x8000,
180
.spis_num = 1,
181
- .spi_bases = aspeed_soc_ast2400_spi_bases,
182
.fmc_typename = "aspeed.smc.fmc",
183
.spi_typename = aspeed_soc_ast2400_typenames,
184
.wdts_num = 2,
185
.irqmap = aspeed_soc_ast2400_irqmap,
186
+ .memmap = aspeed_soc_ast2400_memmap,
187
}, {
188
.name = "ast2400-a1",
189
.cpu_type = ARM_CPU_TYPE_NAME("arm926"),
190
.silicon_rev = AST2400_A1_SILICON_REV,
191
- .sdram_base = AST2400_SDRAM_BASE,
192
.sram_size = 0x8000,
193
.spis_num = 1,
194
- .spi_bases = aspeed_soc_ast2400_spi_bases,
195
.fmc_typename = "aspeed.smc.fmc",
196
.spi_typename = aspeed_soc_ast2400_typenames,
197
.wdts_num = 2,
198
.irqmap = aspeed_soc_ast2400_irqmap,
199
+ .memmap = aspeed_soc_ast2400_memmap,
200
}, {
201
.name = "ast2400",
202
.cpu_type = ARM_CPU_TYPE_NAME("arm926"),
203
.silicon_rev = AST2400_A0_SILICON_REV,
204
- .sdram_base = AST2400_SDRAM_BASE,
205
.sram_size = 0x8000,
206
.spis_num = 1,
207
- .spi_bases = aspeed_soc_ast2400_spi_bases,
208
.fmc_typename = "aspeed.smc.fmc",
209
.spi_typename = aspeed_soc_ast2400_typenames,
210
.wdts_num = 2,
211
.irqmap = aspeed_soc_ast2400_irqmap,
212
+ .memmap = aspeed_soc_ast2400_memmap,
213
}, {
214
.name = "ast2500-a1",
215
.cpu_type = ARM_CPU_TYPE_NAME("arm1176"),
216
.silicon_rev = AST2500_A1_SILICON_REV,
217
- .sdram_base = AST2500_SDRAM_BASE,
218
.sram_size = 0x9000,
219
.spis_num = 2,
220
- .spi_bases = aspeed_soc_ast2500_spi_bases,
221
.fmc_typename = "aspeed.smc.ast2500-fmc",
222
.spi_typename = aspeed_soc_ast2500_typenames,
223
.wdts_num = 3,
224
.irqmap = aspeed_soc_ast2500_irqmap,
225
+ .memmap = aspeed_soc_ast2500_memmap,
226
},
227
};
228
229
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
230
Error *err = NULL, *local_err = NULL;
231
232
/* IO space */
233
- create_unimplemented_device("aspeed_soc.io",
234
- ASPEED_SOC_IOMEM_BASE, ASPEED_SOC_IOMEM_SIZE);
235
+ create_unimplemented_device("aspeed_soc.io", sc->info->memmap[ASPEED_IOMEM],
236
+ ASPEED_SOC_IOMEM_SIZE);
237
238
/* CPU */
239
object_property_set_bool(OBJECT(&s->cpu), true, "realized", &err);
240
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
241
error_propagate(errp, err);
242
return;
243
}
244
- memory_region_add_subregion(get_system_memory(), ASPEED_SOC_SRAM_BASE,
245
- &s->sram);
246
+ memory_region_add_subregion(get_system_memory(),
247
+ sc->info->memmap[ASPEED_SRAM], &s->sram);
248
249
/* SCU */
250
object_property_set_bool(OBJECT(&s->scu), true, "realized", &err);
251
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
252
error_propagate(errp, err);
253
return;
254
}
255
- sysbus_mmio_map(SYS_BUS_DEVICE(&s->scu), 0, ASPEED_SOC_SCU_BASE);
256
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->scu), 0, sc->info->memmap[ASPEED_SCU]);
257
258
/* VIC */
259
object_property_set_bool(OBJECT(&s->vic), true, "realized", &err);
260
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
261
error_propagate(errp, err);
262
return;
263
}
264
- sysbus_mmio_map(SYS_BUS_DEVICE(&s->vic), 0, ASPEED_SOC_VIC_BASE);
265
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->vic), 0, sc->info->memmap[ASPEED_VIC]);
266
sysbus_connect_irq(SYS_BUS_DEVICE(&s->vic), 0,
267
qdev_get_gpio_in(DEVICE(&s->cpu), ARM_CPU_IRQ));
268
sysbus_connect_irq(SYS_BUS_DEVICE(&s->vic), 1,
269
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
270
error_propagate(errp, err);
271
return;
272
}
273
- sysbus_mmio_map(SYS_BUS_DEVICE(&s->timerctrl), 0, ASPEED_SOC_TIMER_BASE);
274
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->timerctrl), 0,
275
+ sc->info->memmap[ASPEED_TIMER1]);
276
for (i = 0; i < ASPEED_TIMER_NR_TIMERS; i++) {
277
qemu_irq irq = aspeed_soc_get_irq(s, ASPEED_TIMER1 + i);
278
sysbus_connect_irq(SYS_BUS_DEVICE(&s->timerctrl), i, irq);
279
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
280
/* UART - attach an 8250 to the IO space as our UART5 */
281
if (serial_hd(0)) {
282
qemu_irq uart5 = aspeed_soc_get_irq(s, ASPEED_UART5);
283
- serial_mm_init(get_system_memory(),
284
- ASPEED_SOC_IOMEM_BASE + ASPEED_SOC_UART_5_BASE, 2,
285
+ serial_mm_init(get_system_memory(), sc->info->memmap[ASPEED_UART5], 2,
286
uart5, 38400, serial_hd(0), DEVICE_LITTLE_ENDIAN);
287
}
288
289
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
290
error_propagate(errp, err);
291
return;
292
}
293
- sysbus_mmio_map(SYS_BUS_DEVICE(&s->i2c), 0, ASPEED_SOC_I2C_BASE);
294
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->i2c), 0, sc->info->memmap[ASPEED_I2C]);
295
sysbus_connect_irq(SYS_BUS_DEVICE(&s->i2c), 0,
296
aspeed_soc_get_irq(s, ASPEED_I2C));
297
298
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
299
error_propagate(errp, err);
300
return;
301
}
302
- sysbus_mmio_map(SYS_BUS_DEVICE(&s->fmc), 0, ASPEED_SOC_FMC_BASE);
303
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->fmc), 0, sc->info->memmap[ASPEED_FMC]);
304
sysbus_mmio_map(SYS_BUS_DEVICE(&s->fmc), 1,
305
s->fmc.ctrl->flash_window_base);
306
sysbus_connect_irq(SYS_BUS_DEVICE(&s->fmc), 0,
307
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
308
error_propagate(errp, err);
309
return;
310
}
311
- sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi[i]), 0, sc->info->spi_bases[i]);
312
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi[i]), 0,
313
+ sc->info->memmap[ASPEED_SPI1 + i]);
314
sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi[i]), 1,
315
s->spi[i].ctrl->flash_window_base);
316
}
317
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
318
error_propagate(errp, err);
319
return;
320
}
321
- sysbus_mmio_map(SYS_BUS_DEVICE(&s->sdmc), 0, ASPEED_SOC_SDMC_BASE);
322
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->sdmc), 0, sc->info->memmap[ASPEED_SDMC]);
323
324
/* Watch dog */
325
for (i = 0; i < sc->info->wdts_num; i++) {
326
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
327
return;
328
}
329
sysbus_mmio_map(SYS_BUS_DEVICE(&s->wdt[i]), 0,
330
- ASPEED_SOC_WDT_BASE + i * 0x20);
331
+ sc->info->memmap[ASPEED_WDT] + i * 0x20);
332
}
333
334
/* Net */
335
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
336
error_propagate(errp, err);
337
return;
338
}
339
- sysbus_mmio_map(SYS_BUS_DEVICE(&s->ftgmac100), 0, ASPEED_SOC_ETH1_BASE);
340
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->ftgmac100), 0,
341
+ sc->info->memmap[ASPEED_ETH1]);
342
sysbus_connect_irq(SYS_BUS_DEVICE(&s->ftgmac100), 0,
343
aspeed_soc_get_irq(s, ASPEED_ETH1));
344
}
345
--
179
--
346
2.20.1
180
2.20.1
347
181
348
182
diff view generated by jsdifflib
1
From: Joel Stanley <joel@jms.id.au>
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
2
2
3
The Linux kernel driver was updated in commit 4451d3f59f2a
3
The Allwinner H3 System on Chip has an System Control
4
("clocksource/drivers/fttmr010: Fix set_next_event handler) to fix an
4
module that provides system wide generic controls and
5
issue observed on hardware:
5
device information. This commit adds support for the
6
6
Allwinner H3 System Control module.
7
> RELOAD register is loaded into COUNT register when the aspeed timer
7
8
> is enabled, which means the next event may be delayed because timer
8
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
9
> interrupt won't be generated until <0xFFFFFFFF - current_count +
9
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
10
> cycles>.
10
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
11
11
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
12
When running under Qemu, the system appeared "laggy". The guest is now
12
Message-id: 20200311221854.30370-6-nieklinnenbank@gmail.com
13
scheduling timer events too regularly, starving the host of CPU time.
14
15
This patch modifies the timer model to attempt to schedule the timer
16
expiry as the guest requests, but if we have missed the deadline we
17
re interrupt and try again, which allows the guest to catch up.
18
19
Provides expected behaviour with old and new guest code.
20
21
Fixes: c04bd47db6b9 ("hw/timer: Add ASPEED timer device model")
22
Signed-off-by: Joel Stanley <joel@jms.id.au>
23
Signed-off-by: Cédric Le Goater <clg@kaod.org>
24
Message-id: 20190618165311.27066-8-clg@kaod.org
25
[clg: - merged a fix from Andrew Jeffery <andrew@aj.id.au>
26
"Fire interrupt on failure to meet deadline"
27
https://lists.ozlabs.org/pipermail/openbmc/2019-January/014641.html
28
- adapted commit log
29
- checkpatch fixes ]
30
Signed-off-by: Cédric Le Goater <clg@kaod.org>
31
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
32
---
14
---
33
hw/timer/aspeed_timer.c | 57 ++++++++++++++++++++++-------------------
15
hw/misc/Makefile.objs | 1 +
34
1 file changed, 30 insertions(+), 27 deletions(-)
16
include/hw/arm/allwinner-h3.h | 3 +
35
17
include/hw/misc/allwinner-h3-sysctrl.h | 67 ++++++++++++
36
diff --git a/hw/timer/aspeed_timer.c b/hw/timer/aspeed_timer.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
37
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
38
--- a/hw/timer/aspeed_timer.c
26
--- a/hw/misc/Makefile.objs
39
+++ b/hw/timer/aspeed_timer.c
27
+++ b/hw/misc/Makefile.objs
40
@@ -XXX,XX +XXX,XX @@ static inline uint64_t calculate_time(struct AspeedTimer *t, uint32_t ticks)
28
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_MACIO) += macio/
41
29
common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o
42
static uint64_t calculate_next(struct AspeedTimer *t)
30
43
{
31
common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o
44
- uint64_t next = 0;
32
+common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-sysctrl.o
45
- uint32_t rate = calculate_rate(t);
33
common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o
46
+ uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
34
common-obj-$(CONFIG_NSERIES) += cbus.o
47
+ uint64_t next;
35
common-obj-$(CONFIG_ECCMEMCTL) += eccmemctl.o
48
36
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
49
- while (!next) {
37
index XXXXXXX..XXXXXXX 100644
50
- /* We don't know the relationship between the values in the match
38
--- a/include/hw/arm/allwinner-h3.h
51
- * registers, so sort using MAX/MIN/zero. We sort in that order as the
39
+++ b/include/hw/arm/allwinner-h3.h
52
- * timer counts down to zero. */
40
@@ -XXX,XX +XXX,XX @@
53
- uint64_t seq[] = {
41
#include "hw/timer/allwinner-a10-pit.h"
54
- calculate_time(t, MAX(t->match[0], t->match[1])),
42
#include "hw/intc/arm_gic.h"
55
- calculate_time(t, MIN(t->match[0], t->match[1])),
43
#include "hw/misc/allwinner-h3-ccu.h"
56
- calculate_time(t, 0),
44
+#include "hw/misc/allwinner-h3-sysctrl.h"
57
- };
45
#include "target/arm/cpu.h"
58
- uint64_t reload_ns;
46
59
- uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
47
/**
60
+ /*
48
@@ -XXX,XX +XXX,XX @@ enum {
61
+ * We don't know the relationship between the values in the match
49
AW_H3_SRAM_A1,
62
+ * registers, so sort using MAX/MIN/zero. We sort in that order as
50
AW_H3_SRAM_A2,
63
+ * the timer counts down to zero.
51
AW_H3_SRAM_C,
64
+ */
52
+ AW_H3_SYSCTRL,
65
53
AW_H3_EHCI0,
66
- if (now < seq[0]) {
54
AW_H3_OHCI0,
67
- next = seq[0];
55
AW_H3_EHCI1,
68
- } else if (now < seq[1]) {
56
@@ -XXX,XX +XXX,XX @@ typedef struct AwH3State {
69
- next = seq[1];
57
const hwaddr *memmap;
70
- } else if (now < seq[2]) {
58
AwA10PITState timer;
71
- next = seq[2];
59
AwH3ClockCtlState ccu;
72
- } else if (t->reload) {
60
+ AwH3SysCtrlState sysctrl;
73
- reload_ns = muldiv64(t->reload, NANOSECONDS_PER_SECOND, rate);
61
GICState gic;
74
- t->start = now - ((now - t->start) % reload_ns);
62
MemoryRegion sram_a1;
75
- } else {
63
MemoryRegion sram_a2;
76
- /* no reload value, return 0 */
64
diff --git a/include/hw/misc/allwinner-h3-sysctrl.h b/include/hw/misc/allwinner-h3-sysctrl.h
77
- break;
65
new file mode 100644
78
- }
66
index XXXXXXX..XXXXXXX
79
+ next = calculate_time(t, MAX(t->match[0], t->match[1]));
67
--- /dev/null
80
+ if (now < next) {
68
+++ b/include/hw/misc/allwinner-h3-sysctrl.h
81
+ return next;
69
@@ -XXX,XX +XXX,XX @@
82
}
70
+/*
83
71
+ * Allwinner H3 System Control emulation
84
- return next;
72
+ *
85
+ next = calculate_time(t, MIN(t->match[0], t->match[1]));
73
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
86
+ if (now < next) {
74
+ *
87
+ return next;
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);
164
}
165
166
static void allwinner_h3_realize(DeviceState *dev, Error **errp)
167
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
168
qdev_init_nofail(DEVICE(&s->ccu));
169
sysbus_mmio_map(SYS_BUS_DEVICE(&s->ccu), 0, s->memmap[AW_H3_CCU]);
170
171
+ /* System Control */
172
+ qdev_init_nofail(DEVICE(&s->sysctrl));
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;
88
+ }
235
+ }
89
+
236
+
90
+ next = calculate_time(t, 0);
237
+ return s->regs[idx];
91
+ if (now < next) {
238
+}
92
+ return next;
239
+
240
+static void allwinner_h3_sysctrl_write(void *opaque, hwaddr offset,
241
+ uint64_t val, unsigned size)
242
+{
243
+ AwH3SysCtrlState *s = AW_H3_SYSCTRL(opaque);
244
+ const uint32_t idx = REG_INDEX(offset);
245
+
246
+ if (idx >= AW_H3_SYSCTRL_REGS_NUM) {
247
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
248
+ __func__, (uint32_t)offset);
249
+ return;
93
+ }
250
+ }
94
+
251
+
95
+ /* We've missed all deadlines, fire interrupt and try again */
252
+ switch (offset) {
96
+ timer_del(&t->timer);
253
+ case REG_VER: /* Version */
97
+
254
+ break;
98
+ if (timer_overflow_interrupt(t)) {
255
+ default:
99
+ t->level = !t->level;
256
+ s->regs[idx] = (uint32_t) val;
100
+ qemu_set_irq(t->irq, t->level);
257
+ break;
101
+ }
258
+ }
102
+
259
+}
103
+ t->start = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
260
+
104
+ return calculate_time(t, MAX(MAX(t->match[0], t->match[1]), 0));
261
+static const MemoryRegionOps allwinner_h3_sysctrl_ops = {
105
}
262
+ .read = allwinner_h3_sysctrl_read,
106
263
+ .write = allwinner_h3_sysctrl_write,
107
static void aspeed_timer_mod(AspeedTimer *t)
264
+ .endianness = DEVICE_NATIVE_ENDIAN,
265
+ .valid = {
266
+ .min_access_size = 4,
267
+ .max_access_size = 4,
268
+ },
269
+ .impl.min_access_size = 4,
270
+};
271
+
272
+static void allwinner_h3_sysctrl_reset(DeviceState *dev)
273
+{
274
+ AwH3SysCtrlState *s = AW_H3_SYSCTRL(dev);
275
+
276
+ /* Set default values for registers */
277
+ s->regs[REG_INDEX(REG_VER)] = REG_VER_RST;
278
+ s->regs[REG_INDEX(REG_EMAC_PHY_CLK)] = REG_EMAC_PHY_CLK_RST;
279
+}
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)
108
--
324
--
109
2.20.1
325
2.20.1
110
326
111
327
diff view generated by jsdifflib
1
From: Eddie James <eajames@linux.ibm.com>
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
2
2
3
The XDMA engine embedded in the Aspeed SOCs performs PCI DMA operations
3
Various Allwinner System on Chip designs contain multiple processors
4
between the SOC (acting as a BMC) and a host processor in a server.
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
The XDMA engine exists on the AST2400, AST2500, and AST2600 SOCs, so
6
configuration interface which emulates the following features:
7
enable it for all of those. Add trace events on the important register
7
8
writes in the XDMA engine.
8
* CPU reset
9
9
* CPU status
10
Signed-off-by: Eddie James <eajames@linux.ibm.com>
10
11
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
11
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
12
Signed-off-by: Cédric Le Goater <clg@kaod.org>
12
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
13
Message-id: 20190618165311.27066-21-clg@kaod.org
13
Message-id: 20200311221854.30370-7-nieklinnenbank@gmail.com
14
[clg: - changed title ]
15
Signed-off-by: Cédric Le Goater <clg@kaod.org>
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
---
15
---
18
hw/misc/Makefile.objs | 1 +
16
hw/misc/Makefile.objs | 1 +
19
include/hw/arm/aspeed_soc.h | 3 +
17
include/hw/arm/allwinner-h3.h | 3 +
20
include/hw/misc/aspeed_xdma.h | 30 +++++++
18
include/hw/misc/allwinner-cpucfg.h | 52 ++++++
21
hw/arm/aspeed_soc.c | 17 ++++
19
hw/arm/allwinner-h3.c | 9 +-
22
hw/misc/aspeed_xdma.c | 165 ++++++++++++++++++++++++++++++++++
20
hw/misc/allwinner-cpucfg.c | 282 +++++++++++++++++++++++++++++
23
hw/misc/trace-events | 3 +
21
hw/misc/trace-events | 5 +
24
6 files changed, 219 insertions(+)
22
6 files changed, 351 insertions(+), 1 deletion(-)
25
create mode 100644 include/hw/misc/aspeed_xdma.h
23
create mode 100644 include/hw/misc/allwinner-cpucfg.h
26
create mode 100644 hw/misc/aspeed_xdma.c
24
create mode 100644 hw/misc/allwinner-cpucfg.c
27
25
28
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
29
index XXXXXXX..XXXXXXX 100644
27
index XXXXXXX..XXXXXXX 100644
30
--- a/hw/misc/Makefile.objs
28
--- a/hw/misc/Makefile.objs
31
+++ b/hw/misc/Makefile.objs
29
+++ b/hw/misc/Makefile.objs
32
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_ARMSSE_MHU) += armsse-mhu.o
30
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_MACIO) += macio/
33
31
common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o
34
obj-$(CONFIG_PVPANIC) += pvpanic.o
32
35
obj-$(CONFIG_AUX) += auxbus.o
33
common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o
36
+obj-$(CONFIG_ASPEED_SOC) += aspeed_xdma.o
34
+obj-$(CONFIG_ALLWINNER_H3) += allwinner-cpucfg.o
37
obj-$(CONFIG_ASPEED_SOC) += aspeed_scu.o aspeed_sdmc.o
35
common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-sysctrl.o
38
obj-$(CONFIG_MSF2) += msf2-sysreg.o
36
common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o
39
obj-$(CONFIG_NRF51_SOC) += nrf51_rng.o
37
common-obj-$(CONFIG_NSERIES) += cbus.o
40
diff --git a/include/hw/arm/aspeed_soc.h b/include/hw/arm/aspeed_soc.h
38
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
41
index XXXXXXX..XXXXXXX 100644
39
index XXXXXXX..XXXXXXX 100644
42
--- a/include/hw/arm/aspeed_soc.h
40
--- a/include/hw/arm/allwinner-h3.h
43
+++ b/include/hw/arm/aspeed_soc.h
41
+++ b/include/hw/arm/allwinner-h3.h
44
@@ -XXX,XX +XXX,XX @@
42
@@ -XXX,XX +XXX,XX @@
45
#include "hw/intc/aspeed_vic.h"
43
#include "hw/timer/allwinner-a10-pit.h"
46
#include "hw/misc/aspeed_scu.h"
44
#include "hw/intc/arm_gic.h"
47
#include "hw/misc/aspeed_sdmc.h"
45
#include "hw/misc/allwinner-h3-ccu.h"
48
+#include "hw/misc/aspeed_xdma.h"
46
+#include "hw/misc/allwinner-cpucfg.h"
49
#include "hw/timer/aspeed_timer.h"
47
#include "hw/misc/allwinner-h3-sysctrl.h"
50
#include "hw/timer/aspeed_rtc.h"
48
#include "target/arm/cpu.h"
51
#include "hw/i2c/aspeed_i2c.h"
49
52
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedSoCState {
53
AspeedTimerCtrlState timerctrl;
54
AspeedI2CState i2c;
55
AspeedSCUState scu;
56
+ AspeedXDMAState xdma;
57
AspeedSMCState fmc;
58
AspeedSMCState spi[ASPEED_SPIS_NUM];
59
AspeedSDMCState sdmc;
60
@@ -XXX,XX +XXX,XX @@ enum {
50
@@ -XXX,XX +XXX,XX @@ enum {
61
ASPEED_ETH1,
51
AW_H3_GIC_CPU,
62
ASPEED_ETH2,
52
AW_H3_GIC_HYP,
63
ASPEED_SDRAM,
53
AW_H3_GIC_VCPU,
64
+ ASPEED_XDMA,
54
+ AW_H3_CPUCFG,
55
AW_H3_SDRAM
65
};
56
};
66
57
67
#endif /* ASPEED_SOC_H */
58
@@ -XXX,XX +XXX,XX @@ typedef struct AwH3State {
68
diff --git a/include/hw/misc/aspeed_xdma.h b/include/hw/misc/aspeed_xdma.h
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
69
new file mode 100644
67
new file mode 100644
70
index XXXXXXX..XXXXXXX
68
index XXXXXXX..XXXXXXX
71
--- /dev/null
69
--- /dev/null
72
+++ b/include/hw/misc/aspeed_xdma.h
70
+++ b/include/hw/misc/allwinner-cpucfg.h
73
@@ -XXX,XX +XXX,XX @@
71
@@ -XXX,XX +XXX,XX @@
74
+/*
72
+/*
75
+ * ASPEED XDMA Controller
73
+ * Allwinner CPU Configuration Module emulation
76
+ * Eddie James <eajames@linux.ibm.com>
74
+ *
77
+ *
75
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
78
+ * Copyright (C) 2019 IBM Corp.
76
+ *
79
+ * SPDX-License-Identifer: GPL-2.0-or-later
77
+ * This program is free software: you can redistribute it and/or modify
78
+ * it under the terms of the GNU General Public License as published by
79
+ * the Free Software Foundation, either version 2 of the License, or
80
+ * (at your option) any later version.
81
+ *
82
+ * This program is distributed in the hope that it will be useful,
83
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
84
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
85
+ * GNU General Public License for more details.
86
+ *
87
+ * You should have received a copy of the GNU General Public License
88
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
80
+ */
89
+ */
81
+
90
+
82
+#ifndef ASPEED_XDMA_H
91
+#ifndef HW_MISC_ALLWINNER_CPUCFG_H
83
+#define ASPEED_XDMA_H
92
+#define HW_MISC_ALLWINNER_CPUCFG_H
84
+
93
+
94
+#include "qom/object.h"
85
+#include "hw/sysbus.h"
95
+#include "hw/sysbus.h"
86
+
96
+
87
+#define TYPE_ASPEED_XDMA "aspeed.xdma"
97
+/**
88
+#define ASPEED_XDMA(obj) OBJECT_CHECK(AspeedXDMAState, (obj), TYPE_ASPEED_XDMA)
98
+ * Object model
89
+
99
+ * @{
90
+#define ASPEED_XDMA_NUM_REGS (ASPEED_XDMA_REG_SIZE / sizeof(uint32_t))
100
+ */
91
+#define ASPEED_XDMA_REG_SIZE 0x7C
101
+
92
+
102
+#define TYPE_AW_CPUCFG "allwinner-cpucfg"
93
+typedef struct AspeedXDMAState {
103
+#define AW_CPUCFG(obj) \
94
+ SysBusDevice parent;
104
+ OBJECT_CHECK(AwCpuCfgState, (obj), TYPE_AW_CPUCFG)
105
+
106
+/** @} */
107
+
108
+/**
109
+ * Allwinner CPU Configuration Module instance state
110
+ */
111
+typedef struct AwCpuCfgState {
112
+ /*< private >*/
113
+ SysBusDevice parent_obj;
114
+ /*< public >*/
95
+
115
+
96
+ MemoryRegion iomem;
116
+ MemoryRegion iomem;
97
+ qemu_irq irq;
117
+ uint32_t gen_ctrl;
98
+
118
+ uint32_t super_standby;
99
+ char bmc_cmdq_readp_set;
119
+ uint32_t entry_addr;
100
+ uint32_t regs[ASPEED_XDMA_NUM_REGS];
120
+
101
+} AspeedXDMAState;
121
+} AwCpuCfgState;
102
+
122
+
103
+#endif /* ASPEED_XDMA_H */
123
+#endif /* HW_MISC_ALLWINNER_CPUCFG_H */
104
diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c
124
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
105
index XXXXXXX..XXXXXXX 100644
125
index XXXXXXX..XXXXXXX 100644
106
--- a/hw/arm/aspeed_soc.c
126
--- a/hw/arm/allwinner-h3.c
107
+++ b/hw/arm/aspeed_soc.c
127
+++ b/hw/arm/allwinner-h3.c
108
@@ -XXX,XX +XXX,XX @@ static const hwaddr aspeed_soc_ast2400_memmap[] = {
128
@@ -XXX,XX +XXX,XX @@ const hwaddr allwinner_h3_memmap[] = {
109
[ASPEED_VIC] = 0x1E6C0000,
129
[AW_H3_GIC_CPU] = 0x01c82000,
110
[ASPEED_SDMC] = 0x1E6E0000,
130
[AW_H3_GIC_HYP] = 0x01c84000,
111
[ASPEED_SCU] = 0x1E6E2000,
131
[AW_H3_GIC_VCPU] = 0x01c86000,
112
+ [ASPEED_XDMA] = 0x1E6E7000,
132
+ [AW_H3_CPUCFG] = 0x01f01c00,
113
[ASPEED_ADC] = 0x1E6E9000,
133
[AW_H3_SDRAM] = 0x40000000
114
[ASPEED_SRAM] = 0x1E720000,
115
[ASPEED_GPIO] = 0x1E780000,
116
@@ -XXX,XX +XXX,XX @@ static const hwaddr aspeed_soc_ast2500_memmap[] = {
117
[ASPEED_VIC] = 0x1E6C0000,
118
[ASPEED_SDMC] = 0x1E6E0000,
119
[ASPEED_SCU] = 0x1E6E2000,
120
+ [ASPEED_XDMA] = 0x1E6E7000,
121
[ASPEED_ADC] = 0x1E6E9000,
122
[ASPEED_SRAM] = 0x1E720000,
123
[ASPEED_GPIO] = 0x1E780000,
124
@@ -XXX,XX +XXX,XX @@ static const int aspeed_soc_ast2400_irqmap[] = {
125
[ASPEED_I2C] = 12,
126
[ASPEED_ETH1] = 2,
127
[ASPEED_ETH2] = 3,
128
+ [ASPEED_XDMA] = 6,
129
};
134
};
130
135
131
#define aspeed_soc_ast2500_irqmap aspeed_soc_ast2400_irqmap
136
@@ -XXX,XX +XXX,XX @@ struct AwH3Unimplemented {
132
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_init(Object *obj)
137
{ "r_wdog", 0x01f01000, 1 * KiB },
133
sysbus_init_child_obj(obj, "ftgmac100[*]", OBJECT(&s->ftgmac100[i]),
138
{ "r_prcm", 0x01f01400, 1 * KiB },
134
sizeof(s->ftgmac100[i]), TYPE_FTGMAC100);
139
{ "r_twd", 0x01f01800, 1 * KiB },
135
}
140
- { "r_cpucfg", 0x01f01c00, 1 * KiB },
136
+
141
{ "r_cir-rx", 0x01f02000, 1 * KiB },
137
+ sysbus_init_child_obj(obj, "xdma", OBJECT(&s->xdma), sizeof(s->xdma),
142
{ "r_twi", 0x01f02400, 1 * KiB },
138
+ TYPE_ASPEED_XDMA);
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);
139
}
151
}
140
152
141
static void aspeed_soc_realize(DeviceState *dev, Error **errp)
153
static void allwinner_h3_realize(DeviceState *dev, Error **errp)
142
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
154
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
143
sysbus_connect_irq(SYS_BUS_DEVICE(&s->ftgmac100[i]), 0,
155
qdev_init_nofail(DEVICE(&s->sysctrl));
144
aspeed_soc_get_irq(s, ASPEED_ETH1 + i));
156
sysbus_mmio_map(SYS_BUS_DEVICE(&s->sysctrl), 0, s->memmap[AW_H3_SYSCTRL]);
145
}
157
146
+
158
+ /* CPU Configuration */
147
+ /* XDMA */
159
+ qdev_init_nofail(DEVICE(&s->cpucfg));
148
+ object_property_set_bool(OBJECT(&s->xdma), true, "realized", &err);
160
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->cpucfg), 0, s->memmap[AW_H3_CPUCFG]);
149
+ if (err) {
161
+
150
+ error_propagate(errp, err);
162
/* Universal Serial Bus */
151
+ return;
163
sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0],
152
+ }
164
qdev_get_gpio_in(DEVICE(&s->gic),
153
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->xdma), 0,
165
diff --git a/hw/misc/allwinner-cpucfg.c b/hw/misc/allwinner-cpucfg.c
154
+ sc->info->memmap[ASPEED_XDMA]);
155
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->xdma), 0,
156
+ aspeed_soc_get_irq(s, ASPEED_XDMA));
157
}
158
static Property aspeed_soc_properties[] = {
159
DEFINE_PROP_UINT32("num-cpus", AspeedSoCState, num_cpus, 0),
160
diff --git a/hw/misc/aspeed_xdma.c b/hw/misc/aspeed_xdma.c
161
new file mode 100644
166
new file mode 100644
162
index XXXXXXX..XXXXXXX
167
index XXXXXXX..XXXXXXX
163
--- /dev/null
168
--- /dev/null
164
+++ b/hw/misc/aspeed_xdma.c
169
+++ b/hw/misc/allwinner-cpucfg.c
165
@@ -XXX,XX +XXX,XX @@
170
@@ -XXX,XX +XXX,XX @@
166
+/*
171
+/*
167
+ * ASPEED XDMA Controller
172
+ * Allwinner CPU Configuration Module emulation
168
+ * Eddie James <eajames@linux.ibm.com>
173
+ *
169
+ *
174
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
170
+ * Copyright (C) 2019 IBM Corp
175
+ *
171
+ * SPDX-License-Identifer: GPL-2.0-or-later
176
+ * This program is free software: you can redistribute it and/or modify
177
+ * it under the terms of the GNU General Public License as published by
178
+ * the Free Software Foundation, either version 2 of the License, or
179
+ * (at your option) any later version.
180
+ *
181
+ * This program is distributed in the hope that it will be useful,
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/>.
172
+ */
188
+ */
173
+
189
+
174
+#include "qemu/osdep.h"
190
+#include "qemu/osdep.h"
191
+#include "qemu/units.h"
192
+#include "hw/sysbus.h"
193
+#include "migration/vmstate.h"
175
+#include "qemu/log.h"
194
+#include "qemu/log.h"
195
+#include "qemu/module.h"
176
+#include "qemu/error-report.h"
196
+#include "qemu/error-report.h"
177
+#include "hw/misc/aspeed_xdma.h"
197
+#include "qemu/timer.h"
178
+#include "qapi/error.h"
198
+#include "hw/core/cpu.h"
179
+
199
+#include "target/arm/arm-powerctl.h"
200
+#include "target/arm/cpu.h"
201
+#include "hw/misc/allwinner-cpucfg.h"
180
+#include "trace.h"
202
+#include "trace.h"
181
+
203
+
182
+#define XDMA_BMC_CMDQ_ADDR 0x10
204
+/* CPUCFG register offsets */
183
+#define XDMA_BMC_CMDQ_ENDP 0x14
205
+enum {
184
+#define XDMA_BMC_CMDQ_WRP 0x18
206
+ REG_CPUS_RST_CTRL = 0x0000, /* CPUs Reset Control */
185
+#define XDMA_BMC_CMDQ_W_MASK 0x0003FFFF
207
+ REG_CPU0_RST_CTRL = 0x0040, /* CPU#0 Reset Control */
186
+#define XDMA_BMC_CMDQ_RDP 0x1C
208
+ REG_CPU0_CTRL = 0x0044, /* CPU#0 Control */
187
+#define XDMA_BMC_CMDQ_RDP_MAGIC 0xEE882266
209
+ REG_CPU0_STATUS = 0x0048, /* CPU#0 Status */
188
+#define XDMA_IRQ_ENG_CTRL 0x20
210
+ REG_CPU1_RST_CTRL = 0x0080, /* CPU#1 Reset Control */
189
+#define XDMA_IRQ_ENG_CTRL_US_COMP BIT(4)
211
+ REG_CPU1_CTRL = 0x0084, /* CPU#1 Control */
190
+#define XDMA_IRQ_ENG_CTRL_DS_COMP BIT(5)
212
+ REG_CPU1_STATUS = 0x0088, /* CPU#1 Status */
191
+#define XDMA_IRQ_ENG_CTRL_W_MASK 0xBFEFF07F
213
+ REG_CPU2_RST_CTRL = 0x00C0, /* CPU#2 Reset Control */
192
+#define XDMA_IRQ_ENG_STAT 0x24
214
+ REG_CPU2_CTRL = 0x00C4, /* CPU#2 Control */
193
+#define XDMA_IRQ_ENG_STAT_US_COMP BIT(4)
215
+ REG_CPU2_STATUS = 0x00C8, /* CPU#2 Status */
194
+#define XDMA_IRQ_ENG_STAT_DS_COMP BIT(5)
216
+ REG_CPU3_RST_CTRL = 0x0100, /* CPU#3 Reset Control */
195
+#define XDMA_IRQ_ENG_STAT_RESET 0xF8000000
217
+ REG_CPU3_CTRL = 0x0104, /* CPU#3 Control */
196
+#define XDMA_MEM_SIZE 0x1000
218
+ REG_CPU3_STATUS = 0x0108, /* CPU#3 Status */
197
+
219
+ REG_CPU_SYS_RST = 0x0140, /* CPU System Reset */
198
+#define TO_REG(addr) ((addr) / sizeof(uint32_t))
220
+ REG_CLK_GATING = 0x0144, /* CPU Clock Gating */
199
+
221
+ REG_GEN_CTRL = 0x0184, /* General Control */
200
+static uint64_t aspeed_xdma_read(void *opaque, hwaddr addr, unsigned int size)
222
+ REG_SUPER_STANDBY = 0x01A0, /* Super Standby Flag */
201
+{
223
+ REG_ENTRY_ADDR = 0x01A4, /* Reset Entry Address */
202
+ uint32_t val = 0;
224
+ REG_DBG_EXTERN = 0x01E4, /* Debug External */
203
+ AspeedXDMAState *xdma = opaque;
225
+ REG_CNT64_CTRL = 0x0280, /* 64-bit Counter Control */
204
+
226
+ REG_CNT64_LOW = 0x0284, /* 64-bit Counter Low */
205
+ if (addr < ASPEED_XDMA_REG_SIZE) {
227
+ REG_CNT64_HIGH = 0x0288, /* 64-bit Counter High */
206
+ val = xdma->regs[TO_REG(addr)];
228
+};
207
+ }
229
+
208
+
230
+/* CPUCFG register flags */
209
+ return (uint64_t)val;
231
+enum {
210
+}
232
+ CPUX_RESET_RELEASED = ((1 << 1) | (1 << 0)),
211
+
233
+ CPUX_STATUS_SMP = (1 << 0),
212
+static void aspeed_xdma_write(void *opaque, hwaddr addr, uint64_t val,
234
+ CPU_SYS_RESET_RELEASED = (1 << 0),
213
+ unsigned int size)
235
+ CLK_GATING_ENABLE = ((1 << 8) | 0xF),
214
+{
236
+};
215
+ unsigned int idx;
237
+
216
+ uint32_t val32 = (uint32_t)val;
238
+/* CPUCFG register reset values */
217
+ AspeedXDMAState *xdma = opaque;
239
+enum {
218
+
240
+ REG_CLK_GATING_RST = 0x0000010F,
219
+ if (addr >= ASPEED_XDMA_REG_SIZE) {
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
+ */
220
+ return;
263
+ return;
221
+ }
264
+ }
222
+
265
+ bool target_aa64 = arm_feature(&target_cpu->env, ARM_FEATURE_AARCH64);
223
+ switch (addr) {
266
+
224
+ case XDMA_BMC_CMDQ_ENDP:
267
+ ret = arm_set_cpu_on(cpu_id, s->entry_addr, 0,
225
+ xdma->regs[TO_REG(addr)] = val32 & XDMA_BMC_CMDQ_W_MASK;
268
+ CPU_EXCEPTION_LEVEL_ON_RESET, target_aa64);
226
+ break;
269
+ if (ret != QEMU_ARM_POWERCTL_RET_SUCCESS) {
227
+ case XDMA_BMC_CMDQ_WRP:
270
+ error_report("%s: failed to bring up CPU %d: err %d",
228
+ idx = TO_REG(addr);
271
+ __func__, cpu_id, ret);
229
+ xdma->regs[idx] = val32 & XDMA_BMC_CMDQ_W_MASK;
272
+ return;
230
+ xdma->regs[TO_REG(XDMA_BMC_CMDQ_RDP)] = xdma->regs[idx];
273
+ }
231
+
274
+}
232
+ trace_aspeed_xdma_write(addr, val);
275
+
233
+
276
+static uint64_t allwinner_cpucfg_read(void *opaque, hwaddr offset,
234
+ if (xdma->bmc_cmdq_readp_set) {
277
+ unsigned size)
235
+ xdma->bmc_cmdq_readp_set = 0;
278
+{
236
+ } else {
279
+ const AwCpuCfgState *s = AW_CPUCFG(opaque);
237
+ xdma->regs[TO_REG(XDMA_IRQ_ENG_STAT)] |=
280
+ uint64_t val = 0;
238
+ XDMA_IRQ_ENG_STAT_US_COMP | XDMA_IRQ_ENG_STAT_DS_COMP;
281
+
239
+
282
+ switch (offset) {
240
+ if (xdma->regs[TO_REG(XDMA_IRQ_ENG_CTRL)] &
283
+ case REG_CPUS_RST_CTRL: /* CPUs Reset Control */
241
+ (XDMA_IRQ_ENG_CTRL_US_COMP | XDMA_IRQ_ENG_CTRL_DS_COMP))
284
+ case REG_CPU_SYS_RST: /* CPU System Reset */
242
+ qemu_irq_raise(xdma->irq);
285
+ val = CPU_SYS_RESET_RELEASED;
286
+ break;
287
+ case REG_CPU0_RST_CTRL: /* CPU#0 Reset Control */
288
+ case REG_CPU1_RST_CTRL: /* CPU#1 Reset Control */
289
+ case REG_CPU2_RST_CTRL: /* CPU#2 Reset Control */
290
+ case REG_CPU3_RST_CTRL: /* CPU#3 Reset Control */
291
+ val = CPUX_RESET_RELEASED;
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);
243
+ }
352
+ }
244
+ break;
353
+ break;
245
+ case XDMA_BMC_CMDQ_RDP:
354
+ case REG_CPU0_CTRL: /* CPU#0 Control */
246
+ trace_aspeed_xdma_write(addr, val);
355
+ case REG_CPU1_CTRL: /* CPU#1 Control */
247
+
356
+ case REG_CPU2_CTRL: /* CPU#2 Control */
248
+ if (val32 == XDMA_BMC_CMDQ_RDP_MAGIC) {
357
+ case REG_CPU3_CTRL: /* CPU#3 Control */
249
+ xdma->bmc_cmdq_readp_set = 1;
358
+ case REG_CPU0_STATUS: /* CPU#0 Status */
250
+ }
359
+ case REG_CPU1_STATUS: /* CPU#1 Status */
251
+ break;
360
+ case REG_CPU2_STATUS: /* CPU#2 Status */
252
+ case XDMA_IRQ_ENG_CTRL:
361
+ case REG_CPU3_STATUS: /* CPU#3 Status */
253
+ xdma->regs[TO_REG(addr)] = val32 & XDMA_IRQ_ENG_CTRL_W_MASK;
362
+ case REG_CLK_GATING: /* CPU Clock Gating */
254
+ break;
363
+ break;
255
+ case XDMA_IRQ_ENG_STAT:
364
+ case REG_GEN_CTRL: /* General Control */
256
+ trace_aspeed_xdma_write(addr, val);
365
+ s->gen_ctrl = val;
257
+
366
+ break;
258
+ idx = TO_REG(addr);
367
+ case REG_SUPER_STANDBY: /* Super Standby Flag */
259
+ if (val32 & (XDMA_IRQ_ENG_STAT_US_COMP | XDMA_IRQ_ENG_STAT_DS_COMP)) {
368
+ s->super_standby = val;
260
+ xdma->regs[idx] &=
369
+ break;
261
+ ~(XDMA_IRQ_ENG_STAT_US_COMP | XDMA_IRQ_ENG_STAT_DS_COMP);
370
+ case REG_ENTRY_ADDR: /* Reset Entry Address */
262
+ qemu_irq_lower(xdma->irq);
371
+ s->entry_addr = val;
263
+ }
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);
264
+ break;
379
+ break;
265
+ default:
380
+ default:
266
+ xdma->regs[TO_REG(addr)] = val32;
381
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
382
+ __func__, (uint32_t)offset);
267
+ break;
383
+ break;
268
+ }
384
+ }
269
+}
385
+}
270
+
386
+
271
+static const MemoryRegionOps aspeed_xdma_ops = {
387
+static const MemoryRegionOps allwinner_cpucfg_ops = {
272
+ .read = aspeed_xdma_read,
388
+ .read = allwinner_cpucfg_read,
273
+ .write = aspeed_xdma_write,
389
+ .write = allwinner_cpucfg_write,
274
+ .endianness = DEVICE_NATIVE_ENDIAN,
390
+ .endianness = DEVICE_NATIVE_ENDIAN,
275
+ .valid.min_access_size = 4,
391
+ .valid = {
276
+ .valid.max_access_size = 4,
392
+ .min_access_size = 4,
277
+};
393
+ .max_access_size = 4,
278
+
394
+ },
279
+static void aspeed_xdma_realize(DeviceState *dev, Error **errp)
395
+ .impl.min_access_size = 4,
280
+{
396
+};
281
+ SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
397
+
282
+ AspeedXDMAState *xdma = ASPEED_XDMA(dev);
398
+static void allwinner_cpucfg_reset(DeviceState *dev)
283
+
399
+{
284
+ sysbus_init_irq(sbd, &xdma->irq);
400
+ AwCpuCfgState *s = AW_CPUCFG(dev);
285
+ memory_region_init_io(&xdma->iomem, OBJECT(xdma), &aspeed_xdma_ops, xdma,
401
+
286
+ TYPE_ASPEED_XDMA, XDMA_MEM_SIZE);
402
+ /* Set default values for registers */
287
+ sysbus_init_mmio(sbd, &xdma->iomem);
403
+ s->gen_ctrl = REG_GEN_CTRL_RST;
288
+}
404
+ s->super_standby = REG_SUPER_STANDBY_RST;
289
+
405
+ s->entry_addr = 0;
290
+static void aspeed_xdma_reset(DeviceState *dev)
406
+}
291
+{
407
+
292
+ AspeedXDMAState *xdma = ASPEED_XDMA(dev);
408
+static void allwinner_cpucfg_init(Object *obj)
293
+
409
+{
294
+ xdma->bmc_cmdq_readp_set = 0;
410
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
295
+ memset(xdma->regs, 0, ASPEED_XDMA_REG_SIZE);
411
+ AwCpuCfgState *s = AW_CPUCFG(obj);
296
+ xdma->regs[TO_REG(XDMA_IRQ_ENG_STAT)] = XDMA_IRQ_ENG_STAT_RESET;
412
+
297
+
413
+ /* Memory mapping */
298
+ qemu_irq_lower(xdma->irq);
414
+ memory_region_init_io(&s->iomem, OBJECT(s), &allwinner_cpucfg_ops, s,
299
+}
415
+ TYPE_AW_CPUCFG, 1 * KiB);
300
+
416
+ sysbus_init_mmio(sbd, &s->iomem);
301
+static const VMStateDescription aspeed_xdma_vmstate = {
417
+}
302
+ .name = TYPE_ASPEED_XDMA,
418
+
419
+static const VMStateDescription allwinner_cpucfg_vmstate = {
420
+ .name = "allwinner-cpucfg",
303
+ .version_id = 1,
421
+ .version_id = 1,
422
+ .minimum_version_id = 1,
304
+ .fields = (VMStateField[]) {
423
+ .fields = (VMStateField[]) {
305
+ VMSTATE_UINT32_ARRAY(regs, AspeedXDMAState, ASPEED_XDMA_NUM_REGS),
424
+ VMSTATE_UINT32(gen_ctrl, AwCpuCfgState),
306
+ VMSTATE_END_OF_LIST(),
425
+ VMSTATE_UINT32(super_standby, AwCpuCfgState),
307
+ },
426
+ VMSTATE_UINT32(entry_addr, AwCpuCfgState),
308
+};
427
+ VMSTATE_END_OF_LIST()
309
+
428
+ }
310
+static void aspeed_xdma_class_init(ObjectClass *classp, void *data)
429
+};
311
+{
430
+
312
+ DeviceClass *dc = DEVICE_CLASS(classp);
431
+static void allwinner_cpucfg_class_init(ObjectClass *klass, void *data)
313
+
432
+{
314
+ dc->realize = aspeed_xdma_realize;
433
+ DeviceClass *dc = DEVICE_CLASS(klass);
315
+ dc->reset = aspeed_xdma_reset;
434
+
316
+ dc->vmsd = &aspeed_xdma_vmstate;
435
+ dc->reset = allwinner_cpucfg_reset;
317
+}
436
+ dc->vmsd = &allwinner_cpucfg_vmstate;
318
+
437
+}
319
+static const TypeInfo aspeed_xdma_info = {
438
+
320
+ .name = TYPE_ASPEED_XDMA,
439
+static const TypeInfo allwinner_cpucfg_info = {
440
+ .name = TYPE_AW_CPUCFG,
321
+ .parent = TYPE_SYS_BUS_DEVICE,
441
+ .parent = TYPE_SYS_BUS_DEVICE,
322
+ .instance_size = sizeof(AspeedXDMAState),
442
+ .instance_init = allwinner_cpucfg_init,
323
+ .class_init = aspeed_xdma_class_init,
443
+ .instance_size = sizeof(AwCpuCfgState),
324
+};
444
+ .class_init = allwinner_cpucfg_class_init,
325
+
445
+};
326
+static void aspeed_xdma_register_type(void)
446
+
327
+{
447
+static void allwinner_cpucfg_register(void)
328
+ type_register_static(&aspeed_xdma_info);
448
+{
329
+}
449
+ type_register_static(&allwinner_cpucfg_info);
330
+type_init(aspeed_xdma_register_type);
450
+}
451
+
452
+type_init(allwinner_cpucfg_register)
331
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
332
index XXXXXXX..XXXXXXX 100644
454
index XXXXXXX..XXXXXXX 100644
333
--- a/hw/misc/trace-events
455
--- a/hw/misc/trace-events
334
+++ b/hw/misc/trace-events
456
+++ b/hw/misc/trace-events
335
@@ -XXX,XX +XXX,XX @@ armsse_cpuid_write(uint64_t offset, uint64_t data, unsigned size) "SSE-200 CPU_I
457
@@ -XXX,XX +XXX,XX @@
336
# armsse-mhu.c
458
# See docs/devel/tracing.txt for syntax documentation.
337
armsse_mhu_read(uint64_t offset, uint64_t data, unsigned size) "SSE-200 MHU read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
459
338
armsse_mhu_write(uint64_t offset, uint64_t data, unsigned size) "SSE-200 MHU write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
460
+# allwinner-cpucfg.c
339
+
461
+allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t reset_addr) "id %u, reset_addr 0x%" PRIu32
340
+# aspeed_xdma.c
462
+allwinner_cpucfg_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
341
+aspeed_xdma_write(uint64_t offset, uint64_t data) "XDMA write: offset 0x%" PRIx64 " data 0x%" PRIx64
463
+allwinner_cpucfg_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
464
+
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"
342
--
468
--
343
2.20.1
469
2.20.1
344
470
345
471
diff view generated by jsdifflib
1
From: Joel Stanley <joel@jms.id.au>
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
2
2
3
The RTC is modeled to provide time and date functionality. It is
3
The Security Identifier device found in various Allwinner System on Chip
4
initialised at zero to match the hardware.
4
designs gives applications a per-board unique identifier. This commit
5
5
adds support for the Allwinner Security Identifier using a 128-bit
6
There is no modelling of the alarm functionality, which includes the IRQ
6
UUID value as input.
7
line. As there is no guest code to exercise this function that is
7
8
acceptable for now.
8
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
9
9
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
10
Signed-off-by: Joel Stanley <joel@jms.id.au>
10
Message-id: 20200311221854.30370-8-nieklinnenbank@gmail.com
11
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
12
Message-id: 20190618165311.27066-4-clg@kaod.org
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
---
12
---
15
hw/timer/Makefile.objs | 2 +-
13
hw/misc/Makefile.objs | 1 +
16
include/hw/timer/aspeed_rtc.h | 31 ++++++
14
include/hw/arm/allwinner-h3.h | 3 +
17
hw/timer/aspeed_rtc.c | 180 ++++++++++++++++++++++++++++++++++
15
include/hw/misc/allwinner-sid.h | 60 ++++++++++++
18
hw/timer/trace-events | 4 +
16
hw/arm/allwinner-h3.c | 11 ++-
19
4 files changed, 216 insertions(+), 1 deletion(-)
17
hw/arm/orangepi.c | 8 ++
20
create mode 100644 include/hw/timer/aspeed_rtc.h
18
hw/misc/allwinner-sid.c | 168 ++++++++++++++++++++++++++++++++
21
create mode 100644 hw/timer/aspeed_rtc.c
19
hw/misc/trace-events | 4 +
22
20
7 files changed, 254 insertions(+), 1 deletion(-)
23
diff --git a/hw/timer/Makefile.objs b/hw/timer/Makefile.objs
21
create mode 100644 include/hw/misc/allwinner-sid.h
24
index XXXXXXX..XXXXXXX 100644
22
create mode 100644 hw/misc/allwinner-sid.c
25
--- a/hw/timer/Makefile.objs
23
26
+++ b/hw/timer/Makefile.objs
24
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
27
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_MC146818RTC) += mc146818rtc.o
25
index XXXXXXX..XXXXXXX 100644
28
obj-$(CONFIG_ALLWINNER_A10_PIT) += allwinner-a10-pit.o
26
--- a/hw/misc/Makefile.objs
29
27
+++ b/hw/misc/Makefile.objs
30
common-obj-$(CONFIG_STM32F2XX_TIMER) += stm32f2xx_timer.o
28
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o
31
-common-obj-$(CONFIG_ASPEED_SOC) += aspeed_timer.o
29
common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o
32
+common-obj-$(CONFIG_ASPEED_SOC) += aspeed_timer.o aspeed_rtc.o
30
obj-$(CONFIG_ALLWINNER_H3) += allwinner-cpucfg.o
33
31
common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-sysctrl.o
34
common-obj-$(CONFIG_SUN4V_RTC) += sun4v-rtc.o
32
+common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-sid.o
35
common-obj-$(CONFIG_CMSDK_APB_TIMER) += cmsdk-apb-timer.o
33
common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o
36
diff --git a/include/hw/timer/aspeed_rtc.h b/include/hw/timer/aspeed_rtc.h
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
37
new file mode 100644
65
new file mode 100644
38
index XXXXXXX..XXXXXXX
66
index XXXXXXX..XXXXXXX
39
--- /dev/null
67
--- /dev/null
40
+++ b/include/hw/timer/aspeed_rtc.h
68
+++ b/include/hw/misc/allwinner-sid.h
41
@@ -XXX,XX +XXX,XX @@
69
@@ -XXX,XX +XXX,XX @@
42
+/*
70
+/*
43
+ * ASPEED Real Time Clock
71
+ * Allwinner Security ID emulation
44
+ * Joel Stanley <joel@jms.id.au>
72
+ *
45
+ *
73
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
46
+ * Copyright 2019 IBM Corp
74
+ *
47
+ * SPDX-License-Identifier: GPL-2.0-or-later
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/>.
48
+ */
87
+ */
49
+#ifndef ASPEED_RTC_H
88
+
50
+#define ASPEED_RTC_H
89
+#ifndef HW_MISC_ALLWINNER_SID_H
51
+
90
+#define HW_MISC_ALLWINNER_SID_H
52
+#include <stdint.h>
91
+
53
+
92
+#include "qom/object.h"
54
+#include "hw/hw.h"
55
+#include "hw/irq.h"
56
+#include "hw/sysbus.h"
93
+#include "hw/sysbus.h"
57
+
94
+#include "qemu/uuid.h"
58
+typedef struct AspeedRtcState {
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 >*/
59
+ SysBusDevice parent_obj;
112
+ SysBusDevice parent_obj;
60
+
113
+ /*< public >*/
114
+
115
+ /** Maps I/O registers in physical memory */
61
+ MemoryRegion iomem;
116
+ MemoryRegion iomem;
62
+ qemu_irq irq;
117
+
63
+
118
+ /** Control register defines how and what to read */
64
+ uint32_t reg[0x18];
119
+ uint32_t control;
65
+ int offset;
120
+
66
+
121
+ /** RdKey register contains the data retrieved by the device */
67
+} AspeedRtcState;
122
+ uint32_t rdkey;
68
+
123
+
69
+#define TYPE_ASPEED_RTC "aspeed.rtc"
124
+ /** Stores the emulated device identifier */
70
+#define ASPEED_RTC(obj) OBJECT_CHECK(AspeedRtcState, (obj), TYPE_ASPEED_RTC)
125
+ QemuUUID identifier;
71
+
126
+
72
+#endif /* ASPEED_RTC_H */
127
+} AwSidState;
73
diff --git a/hw/timer/aspeed_rtc.c b/hw/timer/aspeed_rtc.c
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);
159
}
160
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
74
new file mode 100644
193
new file mode 100644
75
index XXXXXXX..XXXXXXX
194
index XXXXXXX..XXXXXXX
76
--- /dev/null
195
--- /dev/null
77
+++ b/hw/timer/aspeed_rtc.c
196
+++ b/hw/misc/allwinner-sid.c
78
@@ -XXX,XX +XXX,XX @@
197
@@ -XXX,XX +XXX,XX @@
79
+/*
198
+/*
80
+ * ASPEED Real Time Clock
199
+ * Allwinner Security ID emulation
81
+ * Joel Stanley <joel@jms.id.au>
200
+ *
82
+ *
201
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
83
+ * Copyright 2019 IBM Corp
202
+ *
84
+ * SPDX-License-Identifier: GPL-2.0-or-later
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/>.
85
+ */
215
+ */
86
+
216
+
87
+#include "qemu/osdep.h"
217
+#include "qemu/osdep.h"
88
+#include "qemu-common.h"
218
+#include "qemu/units.h"
89
+#include "hw/timer/aspeed_rtc.h"
219
+#include "hw/sysbus.h"
220
+#include "migration/vmstate.h"
90
+#include "qemu/log.h"
221
+#include "qemu/log.h"
91
+#include "qemu/timer.h"
222
+#include "qemu/module.h"
92
+
223
+#include "qemu/guest-random.h"
224
+#include "qapi/error.h"
225
+#include "hw/qdev-properties.h"
226
+#include "hw/misc/allwinner-sid.h"
93
+#include "trace.h"
227
+#include "trace.h"
94
+
228
+
95
+#define COUNTER1 (0x00 / 4)
229
+/* SID register offsets */
96
+#define COUNTER2 (0x04 / 4)
230
+enum {
97
+#define ALARM (0x08 / 4)
231
+ REG_PRCTL = 0x40, /* Control */
98
+#define CONTROL (0x10 / 4)
232
+ REG_RDKEY = 0x60, /* Read Key */
99
+#define ALARM_STATUS (0x14 / 4)
233
+};
100
+
234
+
101
+#define RTC_UNLOCKED BIT(1)
235
+/* SID register flags */
102
+#define RTC_ENABLED BIT(0)
236
+enum {
103
+
237
+ REG_PRCTL_WRITE = 0x0002, /* Unknown write flag */
104
+static void aspeed_rtc_calc_offset(AspeedRtcState *rtc)
238
+ REG_PRCTL_OP_LOCK = 0xAC00, /* Lock operation */
105
+{
239
+};
106
+ struct tm tm;
240
+
107
+ uint32_t year, cent;
241
+static uint64_t allwinner_sid_read(void *opaque, hwaddr offset,
108
+ uint32_t reg1 = rtc->reg[COUNTER1];
242
+ unsigned size)
109
+ uint32_t reg2 = rtc->reg[COUNTER2];
243
+{
110
+
244
+ const AwSidState *s = AW_SID(opaque);
111
+ tm.tm_mday = (reg1 >> 24) & 0x1f;
245
+ uint64_t val = 0;
112
+ tm.tm_hour = (reg1 >> 16) & 0x1f;
246
+
113
+ tm.tm_min = (reg1 >> 8) & 0x3f;
247
+ switch (offset) {
114
+ tm.tm_sec = (reg1 >> 0) & 0x3f;
248
+ case REG_PRCTL: /* Control */
115
+
249
+ val = s->control;
116
+ cent = (reg2 >> 16) & 0x1f;
250
+ break;
117
+ year = (reg2 >> 8) & 0x7f;
251
+ case REG_RDKEY: /* Read Key */
118
+ tm.tm_mon = ((reg2 >> 0) & 0x0f) - 1;
252
+ val = s->rdkey;
119
+ tm.tm_year = year + (cent * 100) - 1900;
253
+ break;
120
+
121
+ rtc->offset = qemu_timedate_diff(&tm);
122
+}
123
+
124
+static uint32_t aspeed_rtc_get_counter(AspeedRtcState *rtc, int r)
125
+{
126
+ uint32_t year, cent;
127
+ struct tm now;
128
+
129
+ qemu_get_timedate(&now, rtc->offset);
130
+
131
+ switch (r) {
132
+ case COUNTER1:
133
+ return (now.tm_mday << 24) | (now.tm_hour << 16) |
134
+ (now.tm_min << 8) | now.tm_sec;
135
+ case COUNTER2:
136
+ cent = (now.tm_year + 1900) / 100;
137
+ year = now.tm_year % 100;
138
+ return ((cent & 0x1f) << 16) | ((year & 0x7f) << 8) |
139
+ ((now.tm_mon + 1) & 0xf);
140
+ default:
254
+ default:
141
+ g_assert_not_reached();
255
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
142
+ }
256
+ __func__, (uint32_t)offset);
143
+}
144
+
145
+static uint64_t aspeed_rtc_read(void *opaque, hwaddr addr,
146
+ unsigned size)
147
+{
148
+ AspeedRtcState *rtc = opaque;
149
+ uint64_t val;
150
+ uint32_t r = addr >> 2;
151
+
152
+ switch (r) {
153
+ case COUNTER1:
154
+ case COUNTER2:
155
+ if (rtc->reg[CONTROL] & RTC_ENABLED) {
156
+ rtc->reg[r] = aspeed_rtc_get_counter(rtc, r);
157
+ }
158
+ /* fall through */
159
+ case CONTROL:
160
+ val = rtc->reg[r];
161
+ break;
162
+ case ALARM:
163
+ case ALARM_STATUS:
164
+ default:
165
+ qemu_log_mask(LOG_UNIMP, "%s: 0x%" HWADDR_PRIx "\n", __func__, addr);
166
+ return 0;
257
+ return 0;
167
+ }
258
+ }
168
+
259
+
169
+ trace_aspeed_rtc_read(addr, val);
260
+ trace_allwinner_sid_read(offset, val, size);
170
+
261
+
171
+ return val;
262
+ return val;
172
+}
263
+}
173
+
264
+
174
+static void aspeed_rtc_write(void *opaque, hwaddr addr,
265
+static void allwinner_sid_write(void *opaque, hwaddr offset,
175
+ uint64_t val, unsigned size)
266
+ uint64_t val, unsigned size)
176
+{
267
+{
177
+ AspeedRtcState *rtc = opaque;
268
+ AwSidState *s = AW_SID(opaque);
178
+ uint32_t r = addr >> 2;
269
+
179
+
270
+ trace_allwinner_sid_write(offset, val, size);
180
+ switch (r) {
271
+
181
+ case COUNTER1:
272
+ switch (offset) {
182
+ case COUNTER2:
273
+ case REG_PRCTL: /* Control */
183
+ if (!(rtc->reg[CONTROL] & RTC_UNLOCKED)) {
274
+ s->control = val;
184
+ break;
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
+ }
185
+ }
283
+ }
186
+ /* fall through */
284
+ s->control &= ~REG_PRCTL_WRITE;
187
+ case CONTROL:
285
+ break;
188
+ rtc->reg[r] = val;
286
+ case REG_RDKEY: /* Read Key */
189
+ aspeed_rtc_calc_offset(rtc);
287
+ break;
190
+ break;
191
+ case ALARM:
192
+ case ALARM_STATUS:
193
+ default:
288
+ default:
194
+ qemu_log_mask(LOG_UNIMP, "%s: 0x%" HWADDR_PRIx "\n", __func__, addr);
289
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
290
+ __func__, (uint32_t)offset);
195
+ break;
291
+ break;
196
+ }
292
+ }
197
+ trace_aspeed_rtc_write(addr, val);
293
+}
198
+}
294
+
199
+
295
+static const MemoryRegionOps allwinner_sid_ops = {
200
+static void aspeed_rtc_reset(DeviceState *d)
296
+ .read = allwinner_sid_read,
201
+{
297
+ .write = allwinner_sid_write,
202
+ AspeedRtcState *rtc = ASPEED_RTC(d);
203
+
204
+ rtc->offset = 0;
205
+ memset(rtc->reg, 0, sizeof(rtc->reg));
206
+}
207
+
208
+static const MemoryRegionOps aspeed_rtc_ops = {
209
+ .read = aspeed_rtc_read,
210
+ .write = aspeed_rtc_write,
211
+ .endianness = DEVICE_NATIVE_ENDIAN,
298
+ .endianness = DEVICE_NATIVE_ENDIAN,
212
+};
299
+ .valid = {
213
+
300
+ .min_access_size = 4,
214
+static const VMStateDescription vmstate_aspeed_rtc = {
301
+ .max_access_size = 4,
215
+ .name = TYPE_ASPEED_RTC,
302
+ },
303
+ .impl.min_access_size = 4,
304
+};
305
+
306
+static void allwinner_sid_reset(DeviceState *dev)
307
+{
308
+ AwSidState *s = AW_SID(dev);
309
+
310
+ /* Set default values for registers */
311
+ s->control = 0;
312
+ s->rdkey = 0;
313
+}
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",
216
+ .version_id = 1,
333
+ .version_id = 1,
334
+ .minimum_version_id = 1,
217
+ .fields = (VMStateField[]) {
335
+ .fields = (VMStateField[]) {
218
+ VMSTATE_UINT32_ARRAY(reg, AspeedRtcState, 0x18),
336
+ VMSTATE_UINT32(control, AwSidState),
219
+ VMSTATE_INT32(offset, AspeedRtcState),
337
+ VMSTATE_UINT32(rdkey, AwSidState),
220
+ VMSTATE_INT32(offset, AspeedRtcState),
338
+ VMSTATE_UINT8_ARRAY_V(identifier.data, AwSidState, sizeof(QemuUUID), 1),
221
+ VMSTATE_END_OF_LIST()
339
+ VMSTATE_END_OF_LIST()
222
+ }
340
+ }
223
+};
341
+};
224
+
342
+
225
+static void aspeed_rtc_realize(DeviceState *dev, Error **errp)
343
+static void allwinner_sid_class_init(ObjectClass *klass, void *data)
226
+{
227
+ SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
228
+ AspeedRtcState *s = ASPEED_RTC(dev);
229
+
230
+ sysbus_init_irq(sbd, &s->irq);
231
+
232
+ memory_region_init_io(&s->iomem, OBJECT(s), &aspeed_rtc_ops, s,
233
+ "aspeed-rtc", 0x18ULL);
234
+ sysbus_init_mmio(sbd, &s->iomem);
235
+}
236
+
237
+static void aspeed_rtc_class_init(ObjectClass *klass, void *data)
238
+{
344
+{
239
+ DeviceClass *dc = DEVICE_CLASS(klass);
345
+ DeviceClass *dc = DEVICE_CLASS(klass);
240
+
346
+
241
+ dc->realize = aspeed_rtc_realize;
347
+ dc->reset = allwinner_sid_reset;
242
+ dc->vmsd = &vmstate_aspeed_rtc;
348
+ dc->vmsd = &allwinner_sid_vmstate;
243
+ dc->reset = aspeed_rtc_reset;
349
+ device_class_set_props(dc, allwinner_sid_properties);
244
+}
350
+}
245
+
351
+
246
+static const TypeInfo aspeed_rtc_info = {
352
+static const TypeInfo allwinner_sid_info = {
247
+ .name = TYPE_ASPEED_RTC,
353
+ .name = TYPE_AW_SID,
248
+ .parent = TYPE_SYS_BUS_DEVICE,
354
+ .parent = TYPE_SYS_BUS_DEVICE,
249
+ .instance_size = sizeof(AspeedRtcState),
355
+ .instance_init = allwinner_sid_init,
250
+ .class_init = aspeed_rtc_class_init,
356
+ .instance_size = sizeof(AwSidState),
251
+};
357
+ .class_init = allwinner_sid_class_init,
252
+
358
+};
253
+static void aspeed_rtc_register_types(void)
359
+
254
+{
360
+static void allwinner_sid_register(void)
255
+ type_register_static(&aspeed_rtc_info);
361
+{
256
+}
362
+ type_register_static(&allwinner_sid_info);
257
+
363
+}
258
+type_init(aspeed_rtc_register_types)
364
+
259
diff --git a/hw/timer/trace-events b/hw/timer/trace-events
365
+type_init(allwinner_sid_register)
260
index XXXXXXX..XXXXXXX 100644
366
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
261
--- a/hw/timer/trace-events
367
index XXXXXXX..XXXXXXX 100644
262
+++ b/hw/timer/trace-events
368
--- a/hw/misc/trace-events
263
@@ -XXX,XX +XXX,XX @@ cmsdk_apb_dualtimer_read(uint64_t offset, uint64_t data, unsigned size) "CMSDK A
369
+++ b/hw/misc/trace-events
264
cmsdk_apb_dualtimer_write(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB dualtimer write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
370
@@ -XXX,XX +XXX,XX @@ allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t reset_addr) "id %u, reset_ad
265
cmsdk_apb_dualtimer_reset(void) "CMSDK APB dualtimer: reset"
371
allwinner_cpucfg_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
266
372
allwinner_cpucfg_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
267
+# hw/timer/aspeed-rtc.c
373
268
+aspeed_rtc_read(uint64_t addr, uint64_t value) "addr 0x%02" PRIx64 " value 0x%08" PRIx64
374
+# allwinner-sid.c
269
+aspeed_rtc_write(uint64_t addr, uint64_t value) "addr 0x%02" PRIx64 " value 0x%08" PRIx64
375
+allwinner_sid_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
270
+
376
+allwinner_sid_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
271
# sun4v-rtc.c
377
+
272
sun4v_rtc_read(uint64_t addr, uint64_t value) "read: addr 0x%" PRIx64 " value 0x%" PRIx64
378
# eccmemctl.c
273
sun4v_rtc_write(uint64_t addr, uint64_t value) "write: addr 0x%" PRIx64 " value 0x%" PRIx64
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"
274
--
381
--
275
2.20.1
382
2.20.1
276
383
277
384
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
2
2
3
Since commit 8c06fbdf36b checkpatch.pl enforce a new multiline
3
The Allwinner System on Chip families sun4i and above contain
4
comment syntax. Since we'll move this code around, fix its style
4
an integrated storage controller for Secure Digital (SD) and
5
first.
5
Multi Media Card (MMC) interfaces. This commit adds support
6
for the Allwinner SD/MMC storage controller with the following
7
emulated features:
6
8
9
* DMA transfers
10
* Direct FIFO I/O
11
* Short/Long format command responses
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>
7
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
21
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
8
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
22
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
9
Message-id: 20190701132516.26392-8-philmd@redhat.com
23
Message-id: 20200311221854.30370-9-nieklinnenbank@gmail.com
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
24
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
25
---
12
target/arm/helper.c | 237 ++++++++++++++++++++++++++--------------
26
hw/sd/Makefile.objs | 1 +
13
target/arm/op_helper.c | 54 ++++++---
27
include/hw/arm/allwinner-a10.h | 2 +
14
target/arm/vfp_helper.c | 3 +-
28
include/hw/arm/allwinner-h3.h | 3 +
15
3 files changed, 196 insertions(+), 98 deletions(-)
29
include/hw/sd/allwinner-sdhost.h | 135 +++++
30
hw/arm/allwinner-a10.c | 11 +
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
16
40
17
diff --git a/target/arm/helper.c b/target/arm/helper.c
41
diff --git a/hw/sd/Makefile.objs b/hw/sd/Makefile.objs
18
index XXXXXXX..XXXXXXX 100644
42
index XXXXXXX..XXXXXXX 100644
19
--- a/target/arm/helper.c
43
--- a/hw/sd/Makefile.objs
20
+++ b/target/arm/helper.c
44
+++ b/hw/sd/Makefile.objs
21
@@ -XXX,XX +XXX,XX @@ void HELPER(v7m_vlldm)(CPUARMState *env, uint32_t fptr)
45
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_SD) += sd.o core.o sdmmc-internal.o
22
46
common-obj-$(CONFIG_SDHCI) += sdhci.o
23
uint32_t HELPER(v7m_tt)(CPUARMState *env, uint32_t addr, uint32_t op)
47
common-obj-$(CONFIG_SDHCI_PCI) += sdhci-pci.o
24
{
48
25
- /* The TT instructions can be used by unprivileged code, but in
49
+common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-sdhost.o
26
+ /*
50
common-obj-$(CONFIG_MILKYMIST) += milkymist-memcard.o
27
+ * The TT instructions can be used by unprivileged code, but in
51
common-obj-$(CONFIG_OMAP) += omap_mmc.o
28
* user-only emulation we don't have the MPU.
52
common-obj-$(CONFIG_PXA2XX) += pxa2xx_mmci.o
29
* Luckily since we know we are NonSecure unprivileged (and that in
53
diff --git a/include/hw/arm/allwinner-a10.h b/include/hw/arm/allwinner-a10.h
30
* turn means that the A flag wasn't specified), all the bits in the
54
index XXXXXXX..XXXXXXX 100644
31
@@ -XXX,XX +XXX,XX @@ static bool v7m_stack_write(ARMCPU *cpu, uint32_t addr, uint32_t value,
55
--- a/include/hw/arm/allwinner-a10.h
32
return true;
56
+++ b/include/hw/arm/allwinner-a10.h
33
57
@@ -XXX,XX +XXX,XX @@
34
pend_fault:
58
#include "hw/timer/allwinner-a10-pit.h"
35
- /* By pending the exception at this point we are making
59
#include "hw/intc/allwinner-a10-pic.h"
36
+ /*
60
#include "hw/net/allwinner_emac.h"
37
+ * By pending the exception at this point we are making
61
+#include "hw/sd/allwinner-sdhost.h"
38
* the IMPDEF choice "overridden exceptions pended" (see the
62
#include "hw/ide/ahci.h"
39
* MergeExcInfo() pseudocode). The other choice would be to not
63
#include "hw/usb/hcd-ohci.h"
40
* pend them now and then make a choice about which to throw away
64
#include "hw/usb/hcd-ehci.h"
41
@@ -XXX,XX +XXX,XX @@ static bool v7m_stack_read(ARMCPU *cpu, uint32_t *dest, uint32_t addr,
65
@@ -XXX,XX +XXX,XX @@ typedef struct AwA10State {
42
return true;
66
AwA10PICState intc;
43
67
AwEmacState emac;
44
pend_fault:
68
AllwinnerAHCIState sata;
45
- /* By pending the exception at this point we are making
69
+ AwSdHostState mmc0;
46
+ /*
70
MemoryRegion sram_a;
47
+ * By pending the exception at this point we are making
71
EHCISysBusState ehci[AW_A10_NUM_USB];
48
* the IMPDEF choice "overridden exceptions pended" (see the
72
OHCISysBusState ohci[AW_A10_NUM_USB];
49
* MergeExcInfo() pseudocode). The other choice would be to not
73
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
50
* pend them now and then make a choice about which to throw away
74
index XXXXXXX..XXXXXXX 100644
51
@@ -XXX,XX +XXX,XX @@ void HELPER(v7m_preserve_fp_state)(CPUARMState *env)
75
--- a/include/hw/arm/allwinner-h3.h
52
*/
76
+++ b/include/hw/arm/allwinner-h3.h
53
}
77
@@ -XXX,XX +XXX,XX @@
54
78
#include "hw/misc/allwinner-cpucfg.h"
55
-/* Write to v7M CONTROL.SPSEL bit for the specified security bank.
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
102
new file mode 100644
103
index XXXXXXX..XXXXXXX
104
--- /dev/null
105
+++ b/include/hw/sd/allwinner-sdhost.h
106
@@ -XXX,XX +XXX,XX @@
56
+/*
107
+/*
57
+ * Write to v7M CONTROL.SPSEL bit for the specified security bank.
108
+ * Allwinner (sun4i and above) SD Host Controller emulation
58
* This may change the current stack pointer between Main and Process
109
+ *
59
* stack pointers if it is done for the CONTROL register for the current
110
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
60
* security state.
111
+ *
61
@@ -XXX,XX +XXX,XX @@ static void write_v7m_control_spsel_for_secstate(CPUARMState *env,
112
+ * This program is free software: you can redistribute it and/or modify
62
}
113
+ * it under the terms of the GNU General Public License as published by
63
}
114
+ * the Free Software Foundation, either version 2 of the License, or
64
115
+ * (at your option) any later version.
65
-/* Write to v7M CONTROL.SPSEL bit. This may change the current
116
+ *
66
+/*
117
+ * This program is distributed in the hope that it will be useful,
67
+ * Write to v7M CONTROL.SPSEL bit. This may change the current
118
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
68
* stack pointer between Main and Process stack pointers.
119
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69
*/
120
+ * GNU General Public License for more details.
70
static void write_v7m_control_spsel(CPUARMState *env, bool new_spsel)
121
+ *
71
@@ -XXX,XX +XXX,XX @@ static void write_v7m_control_spsel(CPUARMState *env, bool new_spsel)
122
+ * You should have received a copy of the GNU General Public License
72
123
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
73
void write_v7m_exception(CPUARMState *env, uint32_t new_exc)
124
+ */
74
{
125
+
75
- /* Write a new value to v7m.exception, thus transitioning into or out
126
+#ifndef HW_SD_ALLWINNER_SDHOST_H
76
+ /*
127
+#define HW_SD_ALLWINNER_SDHOST_H
77
+ * Write a new value to v7m.exception, thus transitioning into or out
128
+
78
* of Handler mode; this may result in a change of active stack pointer.
129
+#include "qom/object.h"
79
*/
130
+#include "hw/sysbus.h"
80
bool new_is_psp, old_is_psp = v7m_using_psp(env);
131
+#include "hw/sd/sd.h"
81
@@ -XXX,XX +XXX,XX @@ static void switch_v7m_security_state(CPUARMState *env, bool new_secstate)
132
+
82
return;
133
+/**
83
}
134
+ * Object model types
84
135
+ * @{
85
- /* All the banked state is accessed by looking at env->v7m.secure
136
+ */
86
+ /*
137
+
87
+ * All the banked state is accessed by looking at env->v7m.secure
138
+/** Generic Allwinner SD Host Controller (abstract) */
88
* except for the stack pointer; rearrange the SP appropriately.
139
+#define TYPE_AW_SDHOST "allwinner-sdhost"
89
*/
140
+
90
new_ss_msp = env->v7m.other_ss_msp;
141
+/** Allwinner sun4i family (A10, A12) */
91
@@ -XXX,XX +XXX,XX @@ static void switch_v7m_security_state(CPUARMState *env, bool new_secstate)
142
+#define TYPE_AW_SDHOST_SUN4I TYPE_AW_SDHOST "-sun4i"
92
143
+
93
void HELPER(v7m_bxns)(CPUARMState *env, uint32_t dest)
144
+/** Allwinner sun5i family and newer (A13, H2+, H3, etc) */
94
{
145
+#define TYPE_AW_SDHOST_SUN5I TYPE_AW_SDHOST "-sun5i"
95
- /* Handle v7M BXNS:
146
+
96
+ /*
147
+/** @} */
97
+ * Handle v7M BXNS:
148
+
98
* - if the return value is a magic value, do exception return (like BX)
149
+/**
99
* - otherwise bit 0 of the return value is the target security state
150
+ * Object model macros
100
*/
151
+ * @{
101
@@ -XXX,XX +XXX,XX @@ void HELPER(v7m_bxns)(CPUARMState *env, uint32_t dest)
152
+ */
102
}
153
+
103
154
+#define AW_SDHOST(obj) \
104
if (dest >= min_magic) {
155
+ OBJECT_CHECK(AwSdHostState, (obj), TYPE_AW_SDHOST)
105
- /* This is an exception return magic value; put it where
156
+#define AW_SDHOST_CLASS(klass) \
106
+ /*
157
+ OBJECT_CLASS_CHECK(AwSdHostClass, (klass), TYPE_AW_SDHOST)
107
+ * This is an exception return magic value; put it where
158
+#define AW_SDHOST_GET_CLASS(obj) \
108
* do_v7m_exception_exit() expects and raise EXCEPTION_EXIT.
159
+ OBJECT_GET_CLASS(AwSdHostClass, (obj), TYPE_AW_SDHOST)
109
* Note that if we ever add gen_ss_advance() singlestep support to
160
+
110
* M profile this should count as an "instruction execution complete"
161
+/** @} */
111
@@ -XXX,XX +XXX,XX @@ void HELPER(v7m_bxns)(CPUARMState *env, uint32_t dest)
162
+
112
163
+/**
113
void HELPER(v7m_blxns)(CPUARMState *env, uint32_t dest)
164
+ * Allwinner SD Host Controller object instance state.
114
{
165
+ */
115
- /* Handle v7M BLXNS:
166
+typedef struct AwSdHostState {
116
+ /*
167
+ /*< private >*/
117
+ * Handle v7M BLXNS:
168
+ SysBusDevice busdev;
118
* - bit 0 of the destination address is the target security state
169
+ /*< public >*/
119
*/
170
+
120
171
+ /** Secure Digital (SD) bus, which connects to SD card (if present) */
121
@@ -XXX,XX +XXX,XX @@ void HELPER(v7m_blxns)(CPUARMState *env, uint32_t dest)
172
+ SDBus sdbus;
122
assert(env->v7m.secure);
173
+
123
174
+ /** Maps I/O registers in physical memory */
124
if (dest & 1) {
175
+ MemoryRegion iomem;
125
- /* target is Secure, so this is just a normal BLX,
176
+
126
+ /*
177
+ /** Interrupt output signal to notify CPU */
127
+ * Target is Secure, so this is just a normal BLX,
178
+ qemu_irq irq;
128
* except that the low bit doesn't indicate Thumb/not.
179
+
129
*/
180
+ /** Number of bytes left in current DMA transfer */
130
env->regs[14] = nextinst;
181
+ uint32_t transfer_cnt;
131
@@ -XXX,XX +XXX,XX @@ void HELPER(v7m_blxns)(CPUARMState *env, uint32_t dest)
182
+
132
env->regs[13] = sp;
183
+ /**
133
env->regs[14] = 0xfeffffff;
184
+ * @name Hardware Registers
134
if (arm_v7m_is_handler_mode(env)) {
185
+ * @{
135
- /* Write a dummy value to IPSR, to avoid leaking the current secure
186
+ */
136
+ /*
187
+
137
+ * Write a dummy value to IPSR, to avoid leaking the current secure
188
+ uint32_t global_ctl; /**< Global Control */
138
* exception number to non-secure code. This is guaranteed not
189
+ uint32_t clock_ctl; /**< Clock Control */
139
* to cause write_v7m_exception() to actually change stacks.
190
+ uint32_t timeout; /**< Timeout */
140
*/
191
+ uint32_t bus_width; /**< Bus Width */
141
@@ -XXX,XX +XXX,XX @@ void HELPER(v7m_blxns)(CPUARMState *env, uint32_t dest)
192
+ uint32_t block_size; /**< Block Size */
142
static uint32_t *get_v7m_sp_ptr(CPUARMState *env, bool secure, bool threadmode,
193
+ uint32_t byte_count; /**< Byte Count */
143
bool spsel)
194
+
144
{
195
+ uint32_t command; /**< Command */
145
- /* Return a pointer to the location where we currently store the
196
+ uint32_t command_arg; /**< Command Argument */
146
+ /*
197
+ uint32_t response[4]; /**< Command Response */
147
+ * Return a pointer to the location where we currently store the
198
+
148
* stack pointer for the requested security state and thread mode.
199
+ uint32_t irq_mask; /**< Interrupt Mask */
149
* This pointer will become invalid if the CPU state is updated
200
+ uint32_t irq_status; /**< Raw Interrupt Status */
150
* such that the stack pointers are switched around (eg changing
201
+ uint32_t status; /**< Status */
151
@@ -XXX,XX +XXX,XX @@ static bool arm_v7m_load_vector(ARMCPU *cpu, int exc, bool targets_secure,
202
+
152
203
+ uint32_t fifo_wlevel; /**< FIFO Water Level */
153
mmu_idx = arm_v7m_mmu_idx_for_secstate_and_priv(env, targets_secure, true);
204
+ uint32_t fifo_func_sel; /**< FIFO Function Select */
154
205
+ uint32_t debug_enable; /**< Debug Enable */
155
- /* We don't do a get_phys_addr() here because the rules for vector
206
+ uint32_t auto12_arg; /**< Auto Command 12 Argument */
156
+ /*
207
+ uint32_t newtiming_set; /**< SD New Timing Set */
157
+ * We don't do a get_phys_addr() here because the rules for vector
208
+ uint32_t newtiming_debug; /**< SD New Timing Debug */
158
* loads are special: they always use the default memory map, and
209
+ uint32_t hardware_rst; /**< Hardware Reset */
159
* the default memory map permits reads from all addresses.
210
+ uint32_t dmac; /**< Internal DMA Controller Control */
160
* Since there's no easy way to pass through to pmsav8_mpu_lookup()
211
+ uint32_t desc_base; /**< Descriptor List Base Address */
161
@@ -XXX,XX +XXX,XX @@ static bool arm_v7m_load_vector(ARMCPU *cpu, int exc, bool targets_secure,
212
+ uint32_t dmac_status; /**< Internal DMA Controller Status */
162
return true;
213
+ uint32_t dmac_irq; /**< Internal DMA Controller IRQ Enable */
163
214
+ uint32_t card_threshold; /**< Card Threshold Control */
164
load_fail:
215
+ uint32_t startbit_detect; /**< eMMC DDR Start Bit Detection Control */
165
- /* All vector table fetch fails are reported as HardFault, with
216
+ uint32_t response_crc; /**< Response CRC */
166
+ /*
217
+ uint32_t data_crc[8]; /**< Data CRC */
167
+ * All vector table fetch fails are reported as HardFault, with
218
+ uint32_t status_crc; /**< Status CRC */
168
* HFSR.VECTTBL and .FORCED set. (FORCED is set because
219
+
169
* technically the underlying exception is a MemManage or BusFault
220
+ /** @} */
170
* that is escalated to HardFault.) This is a terminal exception,
221
+
171
@@ -XXX,XX +XXX,XX @@ static uint32_t v7m_integrity_sig(CPUARMState *env, uint32_t lr)
222
+} AwSdHostState;
172
static bool v7m_push_callee_stack(ARMCPU *cpu, uint32_t lr, bool dotailchain,
223
+
173
bool ignore_faults)
224
+/**
174
{
225
+ * Allwinner SD Host Controller class-level struct.
175
- /* For v8M, push the callee-saves register part of the stack frame.
226
+ *
176
+ /*
227
+ * This struct is filled by each sunxi device specific code
177
+ * For v8M, push the callee-saves register part of the stack frame.
228
+ * such that the generic code can use this struct to support
178
* Compare the v8M pseudocode PushCalleeStack().
229
+ * all devices.
179
* In the tailchaining case this may not be the current stack.
230
+ */
180
*/
231
+typedef struct AwSdHostClass {
181
@@ -XXX,XX +XXX,XX @@ static bool v7m_push_callee_stack(ARMCPU *cpu, uint32_t lr, bool dotailchain,
232
+ /*< private >*/
182
return true;
233
+ SysBusDeviceClass parent_class;
183
}
234
+ /*< public >*/
184
235
+
185
- /* Write as much of the stack frame as we can. A write failure may
236
+ /** Maximum buffer size in bytes per DMA descriptor */
186
+ /*
237
+ size_t max_desc_size;
187
+ * Write as much of the stack frame as we can. A write failure may
238
+
188
* cause us to pend a derived exception.
239
+} AwSdHostClass;
189
*/
240
+
190
sig = v7m_integrity_sig(env, lr);
241
+#endif /* HW_SD_ALLWINNER_SDHOST_H */
191
@@ -XXX,XX +XXX,XX @@ static bool v7m_push_callee_stack(ARMCPU *cpu, uint32_t lr, bool dotailchain,
242
diff --git a/hw/arm/allwinner-a10.c b/hw/arm/allwinner-a10.c
192
static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain,
243
index XXXXXXX..XXXXXXX 100644
193
bool ignore_stackfaults)
244
--- a/hw/arm/allwinner-a10.c
194
{
245
+++ b/hw/arm/allwinner-a10.c
195
- /* Do the "take the exception" parts of exception entry,
246
@@ -XXX,XX +XXX,XX @@
196
+ /*
247
#include "hw/boards.h"
197
+ * Do the "take the exception" parts of exception entry,
248
#include "hw/usb/hcd-ohci.h"
198
* but not the pushing of state to the stack. This is
249
199
* similar to the pseudocode ExceptionTaken() function.
250
+#define AW_A10_MMC0_BASE 0x01c0f000
200
*/
251
#define AW_A10_PIC_REG_BASE 0x01c20400
201
@@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain,
252
#define AW_A10_PIT_REG_BASE 0x01c20c00
202
if (arm_feature(env, ARM_FEATURE_V8)) {
253
#define AW_A10_UART0_REG_BASE 0x01c28000
203
if (arm_feature(env, ARM_FEATURE_M_SECURITY) &&
254
@@ -XXX,XX +XXX,XX @@ static void aw_a10_init(Object *obj)
204
(lr & R_V7M_EXCRET_S_MASK)) {
255
sizeof(s->ohci[i]), TYPE_SYSBUS_OHCI);
205
- /* The background code (the owner of the registers in the
206
+ /*
207
+ * The background code (the owner of the registers in the
208
* exception frame) is Secure. This means it may either already
209
* have or now needs to push callee-saves registers.
210
*/
211
if (targets_secure) {
212
if (dotailchain && !(lr & R_V7M_EXCRET_ES_MASK)) {
213
- /* We took an exception from Secure to NonSecure
214
+ /*
215
+ * We took an exception from Secure to NonSecure
216
* (which means the callee-saved registers got stacked)
217
* and are now tailchaining to a Secure exception.
218
* Clear DCRS so eventual return from this Secure
219
@@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain,
220
lr &= ~R_V7M_EXCRET_DCRS_MASK;
221
}
222
} else {
223
- /* We're going to a non-secure exception; push the
224
+ /*
225
+ * We're going to a non-secure exception; push the
226
* callee-saves registers to the stack now, if they're
227
* not already saved.
228
*/
229
@@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain,
230
lr |= R_V7M_EXCRET_SPSEL_MASK;
231
}
232
233
- /* Clear registers if necessary to prevent non-secure exception
234
+ /*
235
+ * Clear registers if necessary to prevent non-secure exception
236
* code being able to see register values from secure code.
237
* Where register values become architecturally UNKNOWN we leave
238
* them with their previous values.
239
*/
240
if (arm_feature(env, ARM_FEATURE_M_SECURITY)) {
241
if (!targets_secure) {
242
- /* Always clear the caller-saved registers (they have been
243
+ /*
244
+ * Always clear the caller-saved registers (they have been
245
* pushed to the stack earlier in v7m_push_stack()).
246
* Clear callee-saved registers if the background code is
247
* Secure (in which case these regs were saved in
248
@@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain,
249
}
250
251
if (push_failed && !ignore_stackfaults) {
252
- /* Derived exception on callee-saves register stacking:
253
+ /*
254
+ * Derived exception on callee-saves register stacking:
255
* we might now want to take a different exception which
256
* targets a different security state, so try again from the top.
257
*/
258
@@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain,
259
return;
260
}
261
262
- /* Now we've done everything that might cause a derived exception
263
+ /*
264
+ * Now we've done everything that might cause a derived exception
265
* we can go ahead and activate whichever exception we're going to
266
* take (which might now be the derived exception).
267
*/
268
@@ -XXX,XX +XXX,XX @@ void HELPER(v7m_vlldm)(CPUARMState *env, uint32_t fptr)
269
270
static bool v7m_push_stack(ARMCPU *cpu)
271
{
272
- /* Do the "set up stack frame" part of exception entry,
273
+ /*
274
+ * Do the "set up stack frame" part of exception entry,
275
* similar to pseudocode PushStack().
276
* Return true if we generate a derived exception (and so
277
* should ignore further stack faults trying to process
278
@@ -XXX,XX +XXX,XX @@ static bool v7m_push_stack(ARMCPU *cpu)
279
}
256
}
280
}
257
}
281
258
+
282
- /* Write as much of the stack frame as we can. If we fail a stack
259
+ sysbus_init_child_obj(obj, "mmc0", &s->mmc0, sizeof(s->mmc0),
283
+ /*
260
+ TYPE_AW_SDHOST_SUN4I);
284
+ * Write as much of the stack frame as we can. If we fail a stack
285
* write this will result in a derived exception being pended
286
* (which may be taken in preference to the one we started with
287
* if it has higher priority).
288
@@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu)
289
bool ftype;
290
bool restore_s16_s31;
291
292
- /* If we're not in Handler mode then jumps to magic exception-exit
293
+ /*
294
+ * If we're not in Handler mode then jumps to magic exception-exit
295
* addresses don't have magic behaviour. However for the v8M
296
* security extensions the magic secure-function-return has to
297
* work in thread mode too, so to avoid doing an extra check in
298
@@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu)
299
return;
300
}
301
302
- /* In the spec pseudocode ExceptionReturn() is called directly
303
+ /*
304
+ * In the spec pseudocode ExceptionReturn() is called directly
305
* from BXWritePC() and gets the full target PC value including
306
* bit zero. In QEMU's implementation we treat it as a normal
307
* jump-to-register (which is then caught later on), and so split
308
@@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu)
309
}
310
311
if (arm_feature(env, ARM_FEATURE_M_SECURITY)) {
312
- /* EXC_RETURN.ES validation check (R_SMFL). We must do this before
313
+ /*
314
+ * EXC_RETURN.ES validation check (R_SMFL). We must do this before
315
* we pick which FAULTMASK to clear.
316
*/
317
if (!env->v7m.secure &&
318
@@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu)
319
}
320
321
if (env->v7m.exception != ARMV7M_EXCP_NMI) {
322
- /* Auto-clear FAULTMASK on return from other than NMI.
323
+ /*
324
+ * Auto-clear FAULTMASK on return from other than NMI.
325
* If the security extension is implemented then this only
326
* happens if the raw execution priority is >= 0; the
327
* value of the ES bit in the exception return value indicates
328
@@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu)
329
/* still an irq active now */
330
break;
331
case 1:
332
- /* we returned to base exception level, no nesting.
333
+ /*
334
+ * We returned to base exception level, no nesting.
335
* (In the pseudocode this is written using "NestedActivation != 1"
336
* where we have 'rettobase == false'.)
337
*/
338
@@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu)
339
340
if (arm_feature(env, ARM_FEATURE_V8)) {
341
if (!arm_feature(env, ARM_FEATURE_M_SECURITY)) {
342
- /* UNPREDICTABLE if S == 1 or DCRS == 0 or ES == 1 (R_XLCP);
343
+ /*
344
+ * UNPREDICTABLE if S == 1 or DCRS == 0 or ES == 1 (R_XLCP);
345
* we choose to take the UsageFault.
346
*/
347
if ((excret & R_V7M_EXCRET_S_MASK) ||
348
@@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu)
349
break;
350
case 13: /* Return to Thread using Process stack */
351
case 9: /* Return to Thread using Main stack */
352
- /* We only need to check NONBASETHRDENA for v7M, because in
353
+ /*
354
+ * We only need to check NONBASETHRDENA for v7M, because in
355
* v8M this bit does not exist (it is RES1).
356
*/
357
if (!rettobase &&
358
@@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu)
359
}
360
361
if (ufault) {
362
- /* Bad exception return: instead of popping the exception
363
+ /*
364
+ * Bad exception return: instead of popping the exception
365
* stack, directly take a usage fault on the current stack.
366
*/
367
env->v7m.cfsr[env->v7m.secure] |= R_V7M_CFSR_INVPC_MASK;
368
@@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu)
369
switch_v7m_security_state(env, return_to_secure);
370
371
{
372
- /* The stack pointer we should be reading the exception frame from
373
+ /*
374
+ * The stack pointer we should be reading the exception frame from
375
* depends on bits in the magic exception return type value (and
376
* for v8M isn't necessarily the stack pointer we will eventually
377
* end up resuming execution with). Get a pointer to the location
378
@@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu)
379
v7m_stack_read(cpu, &xpsr, frameptr + 0x1c, mmu_idx);
380
381
if (!pop_ok) {
382
- /* v7m_stack_read() pended a fault, so take it (as a tail
383
+ /*
384
+ * v7m_stack_read() pended a fault, so take it (as a tail
385
* chained exception on the same stack frame)
386
*/
387
qemu_log_mask(CPU_LOG_INT, "...derived exception on unstacking\n");
388
@@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu)
389
return;
390
}
391
392
- /* Returning from an exception with a PC with bit 0 set is defined
393
+ /*
394
+ * Returning from an exception with a PC with bit 0 set is defined
395
* behaviour on v8M (bit 0 is ignored), but for v7M it was specified
396
* to be UNPREDICTABLE. In practice actual v7M hardware seems to ignore
397
* the lsbit, and there are several RTOSes out there which incorrectly
398
@@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu)
399
}
400
401
if (arm_feature(env, ARM_FEATURE_V8)) {
402
- /* For v8M we have to check whether the xPSR exception field
403
+ /*
404
+ * For v8M we have to check whether the xPSR exception field
405
* matches the EXCRET value for return to handler/thread
406
* before we commit to changing the SP and xPSR.
407
*/
408
bool will_be_handler = (xpsr & XPSR_EXCP) != 0;
409
if (return_to_handler != will_be_handler) {
410
- /* Take an INVPC UsageFault on the current stack.
411
+ /*
412
+ * Take an INVPC UsageFault on the current stack.
413
* By this point we will have switched to the security state
414
* for the background state, so this UsageFault will target
415
* that state.
416
@@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu)
417
frameptr += 0x40;
418
}
419
}
420
- /* Undo stack alignment (the SPREALIGN bit indicates that the original
421
+ /*
422
+ * Undo stack alignment (the SPREALIGN bit indicates that the original
423
* pre-exception SP was not 8-aligned and we added a padding word to
424
* align it, so we undo this by ORing in the bit that increases it
425
* from the current 8-aligned value to the 8-unaligned value. (Adding 4
426
@@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu)
427
V7M_CONTROL, SFPA, sfpa);
428
}
429
430
- /* The restored xPSR exception field will be zero if we're
431
+ /*
432
+ * The restored xPSR exception field will be zero if we're
433
* resuming in Thread mode. If that doesn't match what the
434
* exception return excret specified then this is a UsageFault.
435
* v7M requires we make this check here; v8M did it earlier.
436
*/
437
if (return_to_handler != arm_v7m_is_handler_mode(env)) {
438
- /* Take an INVPC UsageFault by pushing the stack again;
439
+ /*
440
+ * Take an INVPC UsageFault by pushing the stack again;
441
* we know we're v7M so this is never a Secure UsageFault.
442
*/
443
bool ignore_stackfaults;
444
@@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu)
445
446
static bool do_v7m_function_return(ARMCPU *cpu)
447
{
448
- /* v8M security extensions magic function return.
449
+ /*
450
+ * v8M security extensions magic function return.
451
* We may either:
452
* (1) throw an exception (longjump)
453
* (2) return true if we successfully handled the function return
454
@@ -XXX,XX +XXX,XX @@ static bool do_v7m_function_return(ARMCPU *cpu)
455
frame_sp_p = get_v7m_sp_ptr(env, true, threadmode, spsel);
456
frameptr = *frame_sp_p;
457
458
- /* These loads may throw an exception (for MPU faults). We want to
459
+ /*
460
+ * These loads may throw an exception (for MPU faults). We want to
461
* do them as secure, so work out what MMU index that is.
462
*/
463
mmu_idx = arm_v7m_mmu_idx_for_secstate(env, true);
464
@@ -XXX,XX +XXX,XX @@ static void arm_log_exception(int idx)
465
static bool v7m_read_half_insn(ARMCPU *cpu, ARMMMUIdx mmu_idx,
466
uint32_t addr, uint16_t *insn)
467
{
468
- /* Load a 16-bit portion of a v7M instruction, returning true on success,
469
+ /*
470
+ * Load a 16-bit portion of a v7M instruction, returning true on success,
471
* or false on failure (in which case we will have pended the appropriate
472
* exception).
473
* We need to do the instruction fetch's MPU and SAU checks
474
@@ -XXX,XX +XXX,XX @@ static bool v7m_read_half_insn(ARMCPU *cpu, ARMMMUIdx mmu_idx,
475
476
v8m_security_lookup(env, addr, MMU_INST_FETCH, mmu_idx, &sattrs);
477
if (!sattrs.nsc || sattrs.ns) {
478
- /* This must be the second half of the insn, and it straddles a
479
+ /*
480
+ * This must be the second half of the insn, and it straddles a
481
* region boundary with the second half not being S&NSC.
482
*/
483
env->v7m.sfsr |= R_V7M_SFSR_INVEP_MASK;
484
@@ -XXX,XX +XXX,XX @@ static bool v7m_read_half_insn(ARMCPU *cpu, ARMMMUIdx mmu_idx,
485
486
static bool v7m_handle_execute_nsc(ARMCPU *cpu)
487
{
488
- /* Check whether this attempt to execute code in a Secure & NS-Callable
489
+ /*
490
+ * Check whether this attempt to execute code in a Secure & NS-Callable
491
* memory region is for an SG instruction; if so, then emulate the
492
* effect of the SG instruction and return true. Otherwise pend
493
* the correct kind of exception and return false.
494
@@ -XXX,XX +XXX,XX @@ static bool v7m_handle_execute_nsc(ARMCPU *cpu)
495
ARMMMUIdx mmu_idx;
496
uint16_t insn;
497
498
- /* We should never get here unless get_phys_addr_pmsav8() caused
499
+ /*
500
+ * We should never get here unless get_phys_addr_pmsav8() caused
501
* an exception for NS executing in S&NSC memory.
502
*/
503
assert(!env->v7m.secure);
504
@@ -XXX,XX +XXX,XX @@ static bool v7m_handle_execute_nsc(ARMCPU *cpu)
505
}
506
507
if (insn != 0xe97f) {
508
- /* Not an SG instruction first half (we choose the IMPDEF
509
+ /*
510
+ * Not an SG instruction first half (we choose the IMPDEF
511
* early-SG-check option).
512
*/
513
goto gen_invep;
514
@@ -XXX,XX +XXX,XX @@ static bool v7m_handle_execute_nsc(ARMCPU *cpu)
515
}
516
517
if (insn != 0xe97f) {
518
- /* Not an SG instruction second half (yes, both halves of the SG
519
+ /*
520
+ * Not an SG instruction second half (yes, both halves of the SG
521
* insn have the same hex value)
522
*/
523
goto gen_invep;
524
}
525
526
- /* OK, we have confirmed that we really have an SG instruction.
527
+ /*
528
+ * OK, we have confirmed that we really have an SG instruction.
529
* We know we're NS in S memory so don't need to repeat those checks.
530
*/
531
qemu_log_mask(CPU_LOG_INT, "...really an SG instruction at 0x%08" PRIx32
532
@@ -XXX,XX +XXX,XX @@ void arm_v7m_cpu_do_interrupt(CPUState *cs)
533
534
arm_log_exception(cs->exception_index);
535
536
- /* For exceptions we just mark as pending on the NVIC, and let that
537
- handle it. */
538
+ /*
539
+ * For exceptions we just mark as pending on the NVIC, and let that
540
+ * handle it.
541
+ */
542
switch (cs->exception_index) {
543
case EXCP_UDEF:
544
armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE, env->v7m.secure);
545
@@ -XXX,XX +XXX,XX @@ void arm_v7m_cpu_do_interrupt(CPUState *cs)
546
break;
547
case EXCP_PREFETCH_ABORT:
548
case EXCP_DATA_ABORT:
549
- /* Note that for M profile we don't have a guest facing FSR, but
550
+ /*
551
+ * Note that for M profile we don't have a guest facing FSR, but
552
* the env->exception.fsr will be populated by the code that
553
* raises the fault, in the A profile short-descriptor format.
554
*/
555
switch (env->exception.fsr & 0xf) {
556
case M_FAKE_FSR_NSC_EXEC:
557
- /* Exception generated when we try to execute code at an address
558
+ /*
559
+ * Exception generated when we try to execute code at an address
560
* which is marked as Secure & Non-Secure Callable and the CPU
561
* is in the Non-Secure state. The only instruction which can
562
* be executed like this is SG (and that only if both halves of
563
@@ -XXX,XX +XXX,XX @@ void arm_v7m_cpu_do_interrupt(CPUState *cs)
564
}
565
break;
566
case M_FAKE_FSR_SFAULT:
567
- /* Various flavours of SecureFault for attempts to execute or
568
+ /*
569
+ * Various flavours of SecureFault for attempts to execute or
570
* access data in the wrong security state.
571
*/
572
switch (cs->exception_index) {
573
@@ -XXX,XX +XXX,XX @@ void arm_v7m_cpu_do_interrupt(CPUState *cs)
574
armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_BUS, false);
575
break;
576
default:
577
- /* All other FSR values are either MPU faults or "can't happen
578
+ /*
579
+ * All other FSR values are either MPU faults or "can't happen
580
* for M profile" cases.
581
*/
582
switch (cs->exception_index) {
583
@@ -XXX,XX +XXX,XX @@ void arm_v7m_cpu_do_interrupt(CPUState *cs)
584
if (arm_feature(env, ARM_FEATURE_V8)) {
585
lr = R_V7M_EXCRET_RES1_MASK |
586
R_V7M_EXCRET_DCRS_MASK;
587
- /* The S bit indicates whether we should return to Secure
588
+ /*
589
+ * The S bit indicates whether we should return to Secure
590
* or NonSecure (ie our current state).
591
* The ES bit indicates whether we're taking this exception
592
* to Secure or NonSecure (ie our target state). We set it
593
@@ -XXX,XX +XXX,XX @@ void arm_v7m_cpu_do_interrupt(CPUState *cs)
594
v7m_exception_taken(cpu, lr, false, ignore_stackfaults);
595
}
261
}
596
262
597
-/* Function used to synchronize QEMU's AArch64 register set with AArch32
263
static void aw_a10_realize(DeviceState *dev, Error **errp)
598
+/*
264
@@ -XXX,XX +XXX,XX @@ static void aw_a10_realize(DeviceState *dev, Error **errp)
599
+ * Function used to synchronize QEMU's AArch64 register set with AArch32
265
qdev_get_gpio_in(dev, 64 + i));
600
* register set. This is necessary when switching between AArch32 and AArch64
601
* execution state.
602
*/
603
@@ -XXX,XX +XXX,XX @@ void aarch64_sync_32_to_64(CPUARMState *env)
604
env->xregs[i] = env->regs[i];
605
}
606
607
- /* Unless we are in FIQ mode, x8-x12 come from the user registers r8-r12.
608
+ /*
609
+ * Unless we are in FIQ mode, x8-x12 come from the user registers r8-r12.
610
* Otherwise, they come from the banked user regs.
611
*/
612
if (mode == ARM_CPU_MODE_FIQ) {
613
@@ -XXX,XX +XXX,XX @@ void aarch64_sync_32_to_64(CPUARMState *env)
614
}
266
}
615
}
267
}
616
268
+
617
- /* Registers x13-x23 are the various mode SP and FP registers. Registers
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
414
new file mode 100644
415
index XXXXXXX..XXXXXXX
416
--- /dev/null
417
+++ b/hw/sd/allwinner-sdhost.c
418
@@ -XXX,XX +XXX,XX @@
419
+/*
420
+ * Allwinner (sun4i and above) SD Host Controller emulation
421
+ *
422
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
423
+ *
424
+ * This program is free software: you can redistribute it and/or modify
425
+ * it under the terms of the GNU General Public License as published by
426
+ * the Free Software Foundation, either version 2 of the License, or
427
+ * (at your option) any later version.
428
+ *
429
+ * This program is distributed in the hope that it will be useful,
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.
433
+ *
434
+ * You should have received a copy of the GNU General Public License
435
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
436
+ */
437
+
438
+#include "qemu/osdep.h"
439
+#include "qemu/log.h"
440
+#include "qemu/module.h"
441
+#include "qemu/units.h"
442
+#include "sysemu/blockdev.h"
443
+#include "hw/irq.h"
444
+#include "hw/sd/allwinner-sdhost.h"
445
+#include "migration/vmstate.h"
446
+#include "trace.h"
447
+
448
+#define TYPE_AW_SDHOST_BUS "allwinner-sdhost-bus"
449
+#define AW_SDHOST_BUS(obj) \
450
+ OBJECT_CHECK(SDBus, (obj), TYPE_AW_SDHOST_BUS)
451
+
452
+/* SD Host register offsets */
453
+enum {
454
+ REG_SD_GCTL = 0x00, /* Global Control */
455
+ REG_SD_CKCR = 0x04, /* Clock Control */
456
+ REG_SD_TMOR = 0x08, /* Timeout */
457
+ REG_SD_BWDR = 0x0C, /* Bus Width */
458
+ REG_SD_BKSR = 0x10, /* Block Size */
459
+ REG_SD_BYCR = 0x14, /* Byte Count */
460
+ REG_SD_CMDR = 0x18, /* Command */
461
+ REG_SD_CAGR = 0x1C, /* Command Argument */
462
+ REG_SD_RESP0 = 0x20, /* Response Zero */
463
+ REG_SD_RESP1 = 0x24, /* Response One */
464
+ REG_SD_RESP2 = 0x28, /* Response Two */
465
+ REG_SD_RESP3 = 0x2C, /* Response Three */
466
+ REG_SD_IMKR = 0x30, /* Interrupt Mask */
467
+ REG_SD_MISR = 0x34, /* Masked Interrupt Status */
468
+ REG_SD_RISR = 0x38, /* Raw Interrupt Status */
469
+ REG_SD_STAR = 0x3C, /* Status */
470
+ REG_SD_FWLR = 0x40, /* FIFO Water Level */
471
+ REG_SD_FUNS = 0x44, /* FIFO Function Select */
472
+ REG_SD_DBGC = 0x50, /* Debug Enable */
473
+ REG_SD_A12A = 0x58, /* Auto command 12 argument */
474
+ REG_SD_NTSR = 0x5C, /* SD NewTiming Set */
475
+ REG_SD_SDBG = 0x60, /* SD newTiming Set Debug */
476
+ REG_SD_HWRST = 0x78, /* Hardware Reset Register */
477
+ REG_SD_DMAC = 0x80, /* Internal DMA Controller Control */
478
+ REG_SD_DLBA = 0x84, /* Descriptor List Base Address */
479
+ REG_SD_IDST = 0x88, /* Internal DMA Controller Status */
480
+ REG_SD_IDIE = 0x8C, /* Internal DMA Controller IRQ Enable */
481
+ REG_SD_THLDC = 0x100, /* Card Threshold Control */
482
+ REG_SD_DSBD = 0x10C, /* eMMC DDR Start Bit Detection Control */
483
+ REG_SD_RES_CRC = 0x110, /* Response CRC from card/eMMC */
484
+ REG_SD_DATA7_CRC = 0x114, /* CRC Data 7 from card/eMMC */
485
+ REG_SD_DATA6_CRC = 0x118, /* CRC Data 6 from card/eMMC */
486
+ REG_SD_DATA5_CRC = 0x11C, /* CRC Data 5 from card/eMMC */
487
+ REG_SD_DATA4_CRC = 0x120, /* CRC Data 4 from card/eMMC */
488
+ REG_SD_DATA3_CRC = 0x124, /* CRC Data 3 from card/eMMC */
489
+ REG_SD_DATA2_CRC = 0x128, /* CRC Data 2 from card/eMMC */
490
+ REG_SD_DATA1_CRC = 0x12C, /* CRC Data 1 from card/eMMC */
491
+ REG_SD_DATA0_CRC = 0x130, /* CRC Data 0 from card/eMMC */
492
+ REG_SD_CRC_STA = 0x134, /* CRC status from card/eMMC during write */
493
+ REG_SD_FIFO = 0x200, /* Read/Write FIFO */
494
+};
495
+
496
+/* SD Host register flags */
497
+enum {
498
+ SD_GCTL_FIFO_AC_MOD = (1 << 31),
499
+ SD_GCTL_DDR_MOD_SEL = (1 << 10),
500
+ SD_GCTL_CD_DBC_ENB = (1 << 8),
501
+ SD_GCTL_DMA_ENB = (1 << 5),
502
+ SD_GCTL_INT_ENB = (1 << 4),
503
+ SD_GCTL_DMA_RST = (1 << 2),
504
+ SD_GCTL_FIFO_RST = (1 << 1),
505
+ SD_GCTL_SOFT_RST = (1 << 0),
506
+};
507
+
508
+enum {
509
+ SD_CMDR_LOAD = (1 << 31),
510
+ SD_CMDR_CLKCHANGE = (1 << 21),
511
+ SD_CMDR_WRITE = (1 << 10),
512
+ SD_CMDR_AUTOSTOP = (1 << 12),
513
+ SD_CMDR_DATA = (1 << 9),
514
+ SD_CMDR_RESPONSE_LONG = (1 << 7),
515
+ SD_CMDR_RESPONSE = (1 << 6),
516
+ SD_CMDR_CMDID_MASK = (0x3f),
517
+};
518
+
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;
600
+ } else {
601
+ irq = 0;
602
+ }
603
+
604
+ trace_allwinner_sdhost_update_irq(irq);
605
+ qemu_set_irq(s->irq, irq);
606
+}
607
+
608
+static void allwinner_sdhost_update_transfer_cnt(AwSdHostState *s,
609
+ uint32_t bytes)
610
+{
611
+ if (s->transfer_cnt > bytes) {
612
+ s->transfer_cnt -= bytes;
613
+ } else {
614
+ s->transfer_cnt = 0;
615
+ }
616
+
617
+ if (!s->transfer_cnt) {
618
+ s->irq_status |= SD_RISR_DATA_COMPLETE;
619
+ }
620
+}
621
+
622
+static void allwinner_sdhost_set_inserted(DeviceState *dev, bool inserted)
623
+{
624
+ AwSdHostState *s = AW_SDHOST(dev);
625
+
626
+ trace_allwinner_sdhost_set_inserted(inserted);
627
+
628
+ if (inserted) {
629
+ s->irq_status |= SD_RISR_CARD_INSERT;
630
+ s->irq_status &= ~SD_RISR_CARD_REMOVE;
631
+ s->status |= SD_STAR_CARD_PRESENT;
632
+ } else {
633
+ s->irq_status &= ~SD_RISR_CARD_INSERT;
634
+ s->irq_status |= SD_RISR_CARD_REMOVE;
635
+ s->status &= ~SD_STAR_CARD_PRESENT;
636
+ }
637
+
638
+ allwinner_sdhost_update_irq(s);
639
+}
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;
661
+ }
662
+
663
+ /* If the command has a response, store it in the response registers */
664
+ if ((s->command & SD_CMDR_RESPONSE)) {
665
+ if (rlen == 4 && !(s->command & SD_CMDR_RESPONSE_LONG)) {
666
+ s->response[0] = ldl_be_p(&resp[0]);
667
+ s->response[1] = s->response[2] = s->response[3] = 0;
668
+
669
+ } else if (rlen == 16 && (s->command & SD_CMDR_RESPONSE_LONG)) {
670
+ s->response[0] = ldl_be_p(&resp[12]);
671
+ s->response[1] = ldl_be_p(&resp[8]);
672
+ s->response[2] = ldl_be_p(&resp[4]);
673
+ s->response[3] = ldl_be_p(&resp[0]);
674
+ } else {
675
+ goto error;
676
+ }
677
+ }
678
+ }
679
+
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
+{
618
+ /*
690
+ /*
619
+ * Registers x13-x23 are the various mode SP and FP registers. Registers
691
+ * The stop command (CMD12) ensures the SD bus
620
* r13 and r14 are only copied if we are in that mode, otherwise we copy
692
+ * returns to the transfer state.
621
* from the mode banked register.
693
+ */
622
*/
694
+ if ((s->command & SD_CMDR_AUTOSTOP) && (s->transfer_cnt == 0)) {
623
@@ -XXX,XX +XXX,XX @@ void aarch64_sync_32_to_64(CPUARMState *env)
695
+ /* First save current command registers */
624
env->xregs[23] = env->banked_r13[bank_number(ARM_CPU_MODE_UND)];
696
+ uint32_t saved_cmd = s->command;
625
}
697
+ uint32_t saved_arg = s->command_arg;
626
698
+
627
- /* Registers x24-x30 are mapped to r8-r14 in FIQ mode. If we are in FIQ
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);
748
+ }
749
+
750
+ /* Write to SD bus */
751
+ if (is_write) {
752
+ cpu_physical_memory_read((desc->addr & DESC_SIZE_MASK) + num_done,
753
+ buf, buf_bytes);
754
+
755
+ for (uint32_t i = 0; i < buf_bytes; i++) {
756
+ sdbus_write_data(&s->sdbus, buf[i]);
757
+ }
758
+
759
+ /* Read from SD bus */
760
+ } else {
761
+ for (uint32_t i = 0; i < buf_bytes; i++) {
762
+ buf[i] = sdbus_read_data(&s->sdbus);
763
+ }
764
+ cpu_physical_memory_write((desc->addr & DESC_SIZE_MASK) + num_done,
765
+ buf, buf_bytes);
766
+ }
767
+ num_done += buf_bytes;
768
+ }
769
+
770
+ /* Clear hold flag and flush descriptor */
771
+ desc->status &= ~DESC_STATUS_HOLD;
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
+
628
+ /*
790
+ /*
629
+ * Registers x24-x30 are mapped to r8-r14 in FIQ mode. If we are in FIQ
791
+ * For read operations, data must be available on the SD bus
630
* mode, then we can copy from r8-r14. Otherwise, we copy from the
792
+ * If not, it is an error and we should not act at all
631
* FIQ bank for r8-r14.
793
+ */
632
*/
794
+ if (!is_write && !sdbus_data_ready(&s->sdbus)) {
633
@@ -XXX,XX +XXX,XX @@ void aarch64_sync_32_to_64(CPUARMState *env)
795
+ return;
634
env->pc = env->regs[15];
796
+ }
635
}
797
+
636
798
+ /* Process the DMA descriptors until all data is copied */
637
-/* Function used to synchronize QEMU's AArch32 register set with AArch64
799
+ while (s->byte_count > 0) {
638
+/*
800
+ bytes_done = allwinner_sdhost_process_desc(s, desc_addr, &desc,
639
+ * Function used to synchronize QEMU's AArch32 register set with AArch64
801
+ is_write, s->byte_count);
640
* register set. This is necessary when switching between AArch32 and AArch64
802
+ allwinner_sdhost_update_transfer_cnt(s, bytes_done);
641
* execution state.
803
+
642
*/
804
+ if (bytes_done <= s->byte_count) {
643
@@ -XXX,XX +XXX,XX @@ void aarch64_sync_64_to_32(CPUARMState *env)
805
+ s->byte_count -= bytes_done;
644
env->regs[i] = env->xregs[i];
806
+ } else {
645
}
807
+ s->byte_count = 0;
646
808
+ }
647
- /* Unless we are in FIQ mode, r8-r12 come from the user registers x8-x12.
809
+
648
+ /*
810
+ if (desc.status & DESC_STATUS_LAST) {
649
+ * Unless we are in FIQ mode, r8-r12 come from the user registers x8-x12.
811
+ break;
650
* Otherwise, we copy x8-x12 into the banked user regs.
812
+ } else {
651
*/
813
+ desc_addr = desc.next;
652
if (mode == ARM_CPU_MODE_FIQ) {
814
+ }
653
@@ -XXX,XX +XXX,XX @@ void aarch64_sync_64_to_32(CPUARMState *env)
815
+ }
654
}
816
+
655
}
817
+ /* Raise IRQ to signal DMA is completed */
656
818
+ s->irq_status |= SD_RISR_DATA_COMPLETE | SD_RISR_SDIO_INTR;
657
- /* Registers r13 & r14 depend on the current mode.
819
+
658
+ /*
820
+ /* Update DMAC bits */
659
+ * Registers r13 & r14 depend on the current mode.
821
+ s->dmac_status |= SD_IDST_INT_SUMMARY;
660
* If we are in a given mode, we copy the corresponding x registers to r13
822
+
661
* and r14. Otherwise, we copy the x register to the banked r13 and r14
823
+ if (is_write) {
662
* for the mode.
824
+ s->dmac_status |= SD_IDST_TRANSMIT_IRQ;
663
@@ -XXX,XX +XXX,XX @@ void aarch64_sync_64_to_32(CPUARMState *env)
825
+ } else {
664
} else {
826
+ s->dmac_status |= SD_IDST_RECEIVE_IRQ;
665
env->banked_r13[bank_number(ARM_CPU_MODE_USR)] = env->xregs[13];
827
+ }
666
828
+}
667
- /* HYP is an exception in that it does not have its own banked r14 but
829
+
668
+ /*
830
+static uint64_t allwinner_sdhost_read(void *opaque, hwaddr offset,
669
+ * HYP is an exception in that it does not have its own banked r14 but
831
+ unsigned size)
670
* shares the USR r14
832
+{
671
*/
833
+ AwSdHostState *s = AW_SDHOST(opaque);
672
if (mode == ARM_CPU_MODE_HYP) {
834
+ uint32_t res = 0;
673
@@ -XXX,XX +XXX,XX @@ uint32_t HELPER(v7m_mrs)(CPUARMState *env, uint32_t reg)
835
+
674
return value;
836
+ switch (offset) {
675
}
837
+ case REG_SD_GCTL: /* Global Control */
676
case 0x94: /* CONTROL_NS */
838
+ res = s->global_ctl;
677
- /* We have to handle this here because unprivileged Secure code
839
+ break;
678
+ /*
840
+ case REG_SD_CKCR: /* Clock Control */
679
+ * We have to handle this here because unprivileged Secure code
841
+ res = s->clock_ctl;
680
* can read the NS CONTROL register.
842
+ break;
681
*/
843
+ case REG_SD_TMOR: /* Timeout */
682
if (!env->v7m.secure) {
844
+ res = s->timeout;
683
@@ -XXX,XX +XXX,XX @@ uint32_t HELPER(v7m_mrs)(CPUARMState *env, uint32_t reg)
845
+ break;
684
return env->v7m.faultmask[M_REG_NS];
846
+ case REG_SD_BWDR: /* Bus Width */
685
case 0x98: /* SP_NS */
847
+ res = s->bus_width;
686
{
848
+ break;
687
- /* This gives the non-secure SP selected based on whether we're
849
+ case REG_SD_BKSR: /* Block Size */
688
+ /*
850
+ res = s->block_size;
689
+ * This gives the non-secure SP selected based on whether we're
851
+ break;
690
* currently in handler mode or not, using the NS CONTROL.SPSEL.
852
+ case REG_SD_BYCR: /* Byte Count */
691
*/
853
+ res = s->byte_count;
692
bool spsel = env->v7m.control[M_REG_NS] & R_V7M_CONTROL_SPSEL_MASK;
854
+ break;
693
@@ -XXX,XX +XXX,XX @@ uint32_t HELPER(v7m_mrs)(CPUARMState *env, uint32_t reg)
855
+ case REG_SD_CMDR: /* Command */
694
856
+ res = s->command;
695
void HELPER(v7m_msr)(CPUARMState *env, uint32_t maskreg, uint32_t val)
857
+ break;
696
{
858
+ case REG_SD_CAGR: /* Command Argument */
697
- /* We're passed bits [11..0] of the instruction; extract
859
+ res = s->command_arg;
698
+ /*
860
+ break;
699
+ * We're passed bits [11..0] of the instruction; extract
861
+ case REG_SD_RESP0: /* Response Zero */
700
* SYSm and the mask bits.
862
+ res = s->response[0];
701
* Invalid combinations of SYSm and mask are UNPREDICTABLE;
863
+ break;
702
* we choose to treat them as if the mask bits were valid.
864
+ case REG_SD_RESP1: /* Response One */
703
@@ -XXX,XX +XXX,XX @@ void HELPER(v7m_msr)(CPUARMState *env, uint32_t maskreg, uint32_t val)
865
+ res = s->response[1];
704
return;
866
+ break;
705
case 0x98: /* SP_NS */
867
+ case REG_SD_RESP2: /* Response Two */
706
{
868
+ res = s->response[2];
707
- /* This gives the non-secure SP selected based on whether we're
869
+ break;
708
+ /*
870
+ case REG_SD_RESP3: /* Response Three */
709
+ * This gives the non-secure SP selected based on whether we're
871
+ res = s->response[3];
710
* currently in handler mode or not, using the NS CONTROL.SPSEL.
872
+ break;
711
*/
873
+ case REG_SD_IMKR: /* Interrupt Mask */
712
bool spsel = env->v7m.control[M_REG_NS] & R_V7M_CONTROL_SPSEL_MASK;
874
+ res = s->irq_mask;
713
@@ -XXX,XX +XXX,XX @@ uint32_t HELPER(v7m_tt)(CPUARMState *env, uint32_t addr, uint32_t op)
875
+ break;
714
bool targetsec = env->v7m.secure;
876
+ case REG_SD_MISR: /* Masked Interrupt Status */
715
bool is_subpage;
877
+ res = s->irq_status & s->irq_mask;
716
878
+ break;
717
- /* Work out what the security state and privilege level we're
879
+ case REG_SD_RISR: /* Raw Interrupt Status */
718
+ /*
880
+ res = s->irq_status;
719
+ * Work out what the security state and privilege level we're
881
+ break;
720
* interested in is...
882
+ case REG_SD_STAR: /* Status */
721
*/
883
+ res = s->status;
722
if (alt) {
884
+ break;
723
@@ -XXX,XX +XXX,XX @@ uint32_t HELPER(v7m_tt)(CPUARMState *env, uint32_t addr, uint32_t op)
885
+ case REG_SD_FWLR: /* FIFO Water Level */
724
/* ...and then figure out which MMU index this is */
886
+ res = s->fifo_wlevel;
725
mmu_idx = arm_v7m_mmu_idx_for_secstate_and_priv(env, targetsec, targetpriv);
887
+ break;
726
888
+ case REG_SD_FUNS: /* FIFO Function Select */
727
- /* We know that the MPU and SAU don't care about the access type
889
+ res = s->fifo_func_sel;
728
+ /*
890
+ break;
729
+ * We know that the MPU and SAU don't care about the access type
891
+ case REG_SD_DBGC: /* Debug Enable */
730
* for our purposes beyond that we don't want to claim to be
892
+ res = s->debug_enable;
731
* an insn fetch, so we arbitrarily call this a read.
893
+ break;
732
*/
894
+ case REG_SD_A12A: /* Auto command 12 argument */
733
895
+ res = s->auto12_arg;
734
- /* MPU region info only available for privileged or if
896
+ break;
735
+ /*
897
+ case REG_SD_NTSR: /* SD NewTiming Set */
736
+ * MPU region info only available for privileged or if
898
+ res = s->newtiming_set;
737
* inspecting the other MPU state.
899
+ break;
738
*/
900
+ case REG_SD_SDBG: /* SD newTiming Set Debug */
739
if (arm_current_el(env) != 0 || alt) {
901
+ res = s->newtiming_debug;
740
@@ -XXX,XX +XXX,XX @@ bool arm_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
902
+ break;
741
903
+ case REG_SD_HWRST: /* Hardware Reset Register */
742
void HELPER(dc_zva)(CPUARMState *env, uint64_t vaddr_in)
904
+ res = s->hardware_rst;
743
{
905
+ break;
744
- /* Implement DC ZVA, which zeroes a fixed-length block of memory.
906
+ case REG_SD_DMAC: /* Internal DMA Controller Control */
745
+ /*
907
+ res = s->dmac;
746
+ * Implement DC ZVA, which zeroes a fixed-length block of memory.
908
+ break;
747
* Note that we do not implement the (architecturally mandated)
909
+ case REG_SD_DLBA: /* Descriptor List Base Address */
748
* alignment fault for attempts to use this on Device memory
910
+ res = s->desc_base;
749
* (which matches the usual QEMU behaviour of not implementing either
911
+ break;
750
@@ -XXX,XX +XXX,XX @@ void HELPER(dc_zva)(CPUARMState *env, uint64_t vaddr_in)
912
+ case REG_SD_IDST: /* Internal DMA Controller Status */
751
913
+ res = s->dmac_status;
752
#ifndef CONFIG_USER_ONLY
914
+ break;
753
{
915
+ case REG_SD_IDIE: /* Internal DMA Controller Interrupt Enable */
754
- /* Slightly awkwardly, QEMU's TARGET_PAGE_SIZE may be less than
916
+ res = s->dmac_irq;
755
+ /*
917
+ break;
756
+ * Slightly awkwardly, QEMU's TARGET_PAGE_SIZE may be less than
918
+ case REG_SD_THLDC: /* Card Threshold Control */
757
* the block size so we might have to do more than one TLB lookup.
919
+ res = s->card_threshold;
758
* We know that in fact for any v8 CPU the page size is at least 4K
920
+ break;
759
* and the block size must be 2K or less, but TARGET_PAGE_SIZE is only
921
+ case REG_SD_DSBD: /* eMMC DDR Start Bit Detection Control */
760
@@ -XXX,XX +XXX,XX @@ void HELPER(dc_zva)(CPUARMState *env, uint64_t vaddr_in)
922
+ res = s->startbit_detect;
761
}
923
+ break;
762
}
924
+ case REG_SD_RES_CRC: /* Response CRC from card/eMMC */
763
if (i == maxidx) {
925
+ res = s->response_crc;
764
- /* If it's all in the TLB it's fair game for just writing to;
926
+ break;
765
+ /*
927
+ case REG_SD_DATA7_CRC: /* CRC Data 7 from card/eMMC */
766
+ * If it's all in the TLB it's fair game for just writing to;
928
+ case REG_SD_DATA6_CRC: /* CRC Data 6 from card/eMMC */
767
* we know we don't need to update dirty status, etc.
929
+ case REG_SD_DATA5_CRC: /* CRC Data 5 from card/eMMC */
768
*/
930
+ case REG_SD_DATA4_CRC: /* CRC Data 4 from card/eMMC */
769
for (i = 0; i < maxidx - 1; i++) {
931
+ case REG_SD_DATA3_CRC: /* CRC Data 3 from card/eMMC */
770
@@ -XXX,XX +XXX,XX @@ void HELPER(dc_zva)(CPUARMState *env, uint64_t vaddr_in)
932
+ case REG_SD_DATA2_CRC: /* CRC Data 2 from card/eMMC */
771
memset(hostaddr[i], 0, blocklen - (i * TARGET_PAGE_SIZE));
933
+ case REG_SD_DATA1_CRC: /* CRC Data 1 from card/eMMC */
772
return;
934
+ case REG_SD_DATA0_CRC: /* CRC Data 0 from card/eMMC */
773
}
935
+ res = s->data_crc[((offset - REG_SD_DATA7_CRC) / sizeof(uint32_t))];
774
- /* OK, try a store and see if we can populate the tlb. This
936
+ break;
775
+ /*
937
+ case REG_SD_CRC_STA: /* CRC status from card/eMMC in write operation */
776
+ * OK, try a store and see if we can populate the tlb. This
938
+ res = s->status_crc;
777
* might cause an exception if the memory isn't writable,
939
+ break;
778
* in which case we will longjmp out of here. We must for
940
+ case REG_SD_FIFO: /* Read/Write FIFO */
779
* this purpose use the actual register value passed to us
941
+ if (sdbus_data_ready(&s->sdbus)) {
780
@@ -XXX,XX +XXX,XX @@ void HELPER(dc_zva)(CPUARMState *env, uint64_t vaddr_in)
942
+ res = sdbus_read_data(&s->sdbus);
781
}
943
+ res |= sdbus_read_data(&s->sdbus) << 8;
782
}
944
+ res |= sdbus_read_data(&s->sdbus) << 16;
783
945
+ res |= sdbus_read_data(&s->sdbus) << 24;
784
- /* Slow path (probably attempt to do this to an I/O device or
946
+ allwinner_sdhost_update_transfer_cnt(s, sizeof(uint32_t));
785
+ /*
947
+ allwinner_sdhost_auto_stop(s);
786
+ * Slow path (probably attempt to do this to an I/O device or
948
+ allwinner_sdhost_update_irq(s);
787
* similar, or clearing of a block of code we have translations
949
+ } else {
788
* cached for). Just do a series of byte writes as the architecture
950
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: no data ready on SD bus\n",
789
* demands. It's not worth trying to use a cpu_physical_memory_map(),
951
+ __func__);
790
diff --git a/target/arm/op_helper.c b/target/arm/op_helper.c
952
+ }
953
+ break;
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);
1001
+ }
1002
+ allwinner_sdhost_update_irq(s);
1003
+ break;
1004
+ case REG_SD_CAGR: /* Command Argument */
1005
+ s->command_arg = value;
1006
+ break;
1007
+ case REG_SD_RESP0: /* Response Zero */
1008
+ s->response[0] = value;
1009
+ break;
1010
+ case REG_SD_RESP1: /* Response One */
1011
+ s->response[1] = value;
1012
+ break;
1013
+ case REG_SD_RESP2: /* Response Two */
1014
+ s->response[2] = value;
1015
+ break;
1016
+ case REG_SD_RESP3: /* Response Three */
1017
+ s->response[3] = value;
1018
+ break;
1019
+ case REG_SD_IMKR: /* Interrupt Mask */
1020
+ s->irq_mask = value;
1021
+ allwinner_sdhost_update_irq(s);
1022
+ break;
1023
+ case REG_SD_MISR: /* Masked Interrupt Status */
1024
+ case REG_SD_RISR: /* Raw Interrupt Status */
1025
+ s->irq_status &= ~value;
1026
+ allwinner_sdhost_update_irq(s);
1027
+ break;
1028
+ case REG_SD_STAR: /* Status */
1029
+ s->status &= ~value;
1030
+ allwinner_sdhost_update_irq(s);
1031
+ break;
1032
+ case REG_SD_FWLR: /* FIFO Water Level */
1033
+ s->fifo_wlevel = value;
1034
+ break;
1035
+ case REG_SD_FUNS: /* FIFO Function Select */
1036
+ s->fifo_func_sel = value;
1037
+ break;
1038
+ case REG_SD_DBGC: /* Debug Enable */
1039
+ s->debug_enable = value;
1040
+ break;
1041
+ case REG_SD_A12A: /* Auto command 12 argument */
1042
+ s->auto12_arg = value;
1043
+ break;
1044
+ case REG_SD_NTSR: /* SD NewTiming Set */
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;
1094
+ default:
1095
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset %"
1096
+ HWADDR_PRIx"\n", __func__, offset);
1097
+ break;
1098
+ }
1099
+}
1100
+
1101
+static const MemoryRegionOps allwinner_sdhost_ops = {
1102
+ .read = allwinner_sdhost_read,
1103
+ .write = allwinner_sdhost_write,
1104
+ .endianness = DEVICE_NATIVE_ENDIAN,
1105
+ .valid = {
1106
+ .min_access_size = 4,
1107
+ .max_access_size = 4,
1108
+ },
1109
+ .impl.min_access_size = 4,
1110
+};
1111
+
1112
+static const VMStateDescription vmstate_allwinner_sdhost = {
1113
+ .name = "allwinner-sdhost",
1114
+ .version_id = 1,
1115
+ .minimum_version_id = 1,
1116
+ .fields = (VMStateField[]) {
1117
+ VMSTATE_UINT32(global_ctl, AwSdHostState),
1118
+ VMSTATE_UINT32(clock_ctl, AwSdHostState),
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),
1146
+ VMSTATE_END_OF_LIST()
1147
+ }
1148
+};
1149
+
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)
1216
+{
1217
+ DeviceClass *dc = DEVICE_CLASS(klass);
1218
+
1219
+ dc->reset = allwinner_sdhost_reset;
1220
+ dc->vmsd = &vmstate_allwinner_sdhost;
1221
+}
1222
+
1223
+static void allwinner_sdhost_sun4i_class_init(ObjectClass *klass, void *data)
1224
+{
1225
+ AwSdHostClass *sc = AW_SDHOST_CLASS(klass);
1226
+ sc->max_desc_size = 8 * KiB;
1227
+}
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,
1243
+};
1244
+
1245
+static const TypeInfo allwinner_sdhost_sun4i_info = {
1246
+ .name = TYPE_AW_SDHOST_SUN4I,
1247
+ .parent = TYPE_AW_SDHOST,
1248
+ .class_init = allwinner_sdhost_sun4i_class_init,
1249
+};
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
791
index XXXXXXX..XXXXXXX 100644
1274
index XXXXXXX..XXXXXXX 100644
792
--- a/target/arm/op_helper.c
1275
--- a/hw/arm/Kconfig
793
+++ b/target/arm/op_helper.c
1276
+++ b/hw/arm/Kconfig
794
@@ -XXX,XX +XXX,XX @@ static inline uint32_t merge_syn_data_abort(uint32_t template_syn,
1277
@@ -XXX,XX +XXX,XX @@ config ALLWINNER_H3
795
{
1278
select UNIMP
796
uint32_t syn;
1279
select USB_OHCI
797
1280
select USB_EHCI_SYSBUS
798
- /* ISV is only set for data aborts routed to EL2 and
1281
+ select SD
799
+ /*
1282
800
+ * ISV is only set for data aborts routed to EL2 and
1283
config RASPI
801
* never for stage-1 page table walks faulting on stage 2.
1284
bool
802
*
1285
diff --git a/hw/sd/trace-events b/hw/sd/trace-events
803
* Furthermore, ISV is only set for certain kinds of load/stores.
804
@@ -XXX,XX +XXX,XX @@ static inline uint32_t merge_syn_data_abort(uint32_t template_syn,
805
syn = syn_data_abort_no_iss(same_el,
806
ea, 0, s1ptw, is_write, fsc);
807
} else {
808
- /* Fields: IL, ISV, SAS, SSE, SRT, SF and AR come from the template
809
+ /*
810
+ * Fields: IL, ISV, SAS, SSE, SRT, SF and AR come from the template
811
* syndrome created at translation time.
812
* Now we create the runtime syndrome with the remaining fields.
813
*/
814
@@ -XXX,XX +XXX,XX @@ void arm_deliver_fault(ARMCPU *cpu, vaddr addr, MMUAccessType access_type,
815
816
if (target_el == 2 || arm_el_is_aa64(env, target_el) ||
817
arm_s1_regime_using_lpae_format(env, arm_mmu_idx)) {
818
- /* LPAE format fault status register : bottom 6 bits are
819
+ /*
820
+ * LPAE format fault status register : bottom 6 bits are
821
* status code in the same form as needed for syndrome
822
*/
823
fsr = arm_fi_to_lfsc(fi);
824
fsc = extract32(fsr, 0, 6);
825
} else {
826
fsr = arm_fi_to_sfsc(fi);
827
- /* Short format FSR : this fault will never actually be reported
828
+ /*
829
+ * Short format FSR : this fault will never actually be reported
830
* to an EL that uses a syndrome register. Use a (currently)
831
* reserved FSR code in case the constructed syndrome does leak
832
* into the guest somehow.
833
@@ -XXX,XX +XXX,XX @@ void arm_cpu_do_unaligned_access(CPUState *cs, vaddr vaddr,
834
arm_deliver_fault(cpu, vaddr, access_type, mmu_idx, &fi);
835
}
836
837
-/* arm_cpu_do_transaction_failed: handle a memory system error response
838
+/*
839
+ * arm_cpu_do_transaction_failed: handle a memory system error response
840
* (eg "no device/memory present at address") by raising an external abort
841
* exception
842
*/
843
@@ -XXX,XX +XXX,XX @@ static bool linked_bp_matches(ARMCPU *cpu, int lbn)
844
int bt;
845
uint32_t contextidr;
846
847
- /* Links to unimplemented or non-context aware breakpoints are
848
+ /*
849
+ * Links to unimplemented or non-context aware breakpoints are
850
* CONSTRAINED UNPREDICTABLE: either behave as if disabled, or
851
* as if linked to an UNKNOWN context-aware breakpoint (in which
852
* case DBGWCR<n>_EL1.LBN must indicate that breakpoint).
853
@@ -XXX,XX +XXX,XX @@ static bool linked_bp_matches(ARMCPU *cpu, int lbn)
854
855
bt = extract64(bcr, 20, 4);
856
857
- /* We match the whole register even if this is AArch32 using the
858
+ /*
859
+ * We match the whole register even if this is AArch32 using the
860
* short descriptor format (in which case it holds both PROCID and ASID),
861
* since we don't implement the optional v7 context ID masking.
862
*/
863
@@ -XXX,XX +XXX,XX @@ static bool linked_bp_matches(ARMCPU *cpu, int lbn)
864
case 9: /* linked VMID match (reserved if no EL2) */
865
case 11: /* linked context ID and VMID match (reserved if no EL2) */
866
default:
867
- /* Links to Unlinked context breakpoints must generate no
868
+ /*
869
+ * Links to Unlinked context breakpoints must generate no
870
* events; we choose to do the same for reserved values too.
871
*/
872
return false;
873
@@ -XXX,XX +XXX,XX @@ static bool bp_wp_matches(ARMCPU *cpu, int n, bool is_wp)
874
CPUARMState *env = &cpu->env;
875
uint64_t cr;
876
int pac, hmc, ssc, wt, lbn;
877
- /* Note that for watchpoints the check is against the CPU security
878
+ /*
879
+ * Note that for watchpoints the check is against the CPU security
880
* state, not the S/NS attribute on the offending data access.
881
*/
882
bool is_secure = arm_is_secure(env);
883
@@ -XXX,XX +XXX,XX @@ static bool bp_wp_matches(ARMCPU *cpu, int n, bool is_wp)
884
}
885
cr = env->cp15.dbgwcr[n];
886
if (wp->hitattrs.user) {
887
- /* The LDRT/STRT/LDT/STT "unprivileged access" instructions should
888
+ /*
889
+ * The LDRT/STRT/LDT/STT "unprivileged access" instructions should
890
* match watchpoints as if they were accesses done at EL0, even if
891
* the CPU is at EL1 or higher.
892
*/
893
@@ -XXX,XX +XXX,XX @@ static bool bp_wp_matches(ARMCPU *cpu, int n, bool is_wp)
894
}
895
cr = env->cp15.dbgbcr[n];
896
}
897
- /* The WATCHPOINT_HIT flag guarantees us that the watchpoint is
898
+ /*
899
+ * The WATCHPOINT_HIT flag guarantees us that the watchpoint is
900
* enabled and that the address and access type match; for breakpoints
901
* we know the address matched; check the remaining fields, including
902
* linked breakpoints. We rely on WCR and BCR having the same layout
903
@@ -XXX,XX +XXX,XX @@ static bool check_watchpoints(ARMCPU *cpu)
904
CPUARMState *env = &cpu->env;
905
int n;
906
907
- /* If watchpoints are disabled globally or we can't take debug
908
+ /*
909
+ * If watchpoints are disabled globally or we can't take debug
910
* exceptions here then watchpoint firings are ignored.
911
*/
912
if (extract32(env->cp15.mdscr_el1, 15, 1) == 0
913
@@ -XXX,XX +XXX,XX @@ static bool check_breakpoints(ARMCPU *cpu)
914
CPUARMState *env = &cpu->env;
915
int n;
916
917
- /* If breakpoints are disabled globally or we can't take debug
918
+ /*
919
+ * If breakpoints are disabled globally or we can't take debug
920
* exceptions here then breakpoint firings are ignored.
921
*/
922
if (extract32(env->cp15.mdscr_el1, 15, 1) == 0
923
@@ -XXX,XX +XXX,XX @@ void HELPER(check_breakpoints)(CPUARMState *env)
924
925
bool arm_debug_check_watchpoint(CPUState *cs, CPUWatchpoint *wp)
926
{
927
- /* Called by core code when a CPU watchpoint fires; need to check if this
928
+ /*
929
+ * Called by core code when a CPU watchpoint fires; need to check if this
930
* is also an architectural watchpoint match.
931
*/
932
ARMCPU *cpu = ARM_CPU(cs);
933
@@ -XXX,XX +XXX,XX @@ vaddr arm_adjust_watchpoint_address(CPUState *cs, vaddr addr, int len)
934
ARMCPU *cpu = ARM_CPU(cs);
935
CPUARMState *env = &cpu->env;
936
937
- /* In BE32 system mode, target memory is stored byteswapped (on a
938
+ /*
939
+ * In BE32 system mode, target memory is stored byteswapped (on a
940
* little-endian host system), and by the time we reach here (via an
941
* opcode helper) the addresses of subword accesses have been adjusted
942
* to account for that, which means that watchpoints will not match.
943
@@ -XXX,XX +XXX,XX @@ vaddr arm_adjust_watchpoint_address(CPUState *cs, vaddr addr, int len)
944
945
void arm_debug_excp_handler(CPUState *cs)
946
{
947
- /* Called by core code when a watchpoint or breakpoint fires;
948
+ /*
949
+ * Called by core code when a watchpoint or breakpoint fires;
950
* need to check which one and raise the appropriate exception.
951
*/
952
ARMCPU *cpu = ARM_CPU(cs);
953
@@ -XXX,XX +XXX,XX @@ void arm_debug_excp_handler(CPUState *cs)
954
uint64_t pc = is_a64(env) ? env->pc : env->regs[15];
955
bool same_el = (arm_debug_target_el(env) == arm_current_el(env));
956
957
- /* (1) GDB breakpoints should be handled first.
958
+ /*
959
+ * (1) GDB breakpoints should be handled first.
960
* (2) Do not raise a CPU exception if no CPU breakpoint has fired,
961
* since singlestep is also done by generating a debug internal
962
* exception.
963
@@ -XXX,XX +XXX,XX @@ void arm_debug_excp_handler(CPUState *cs)
964
}
965
966
env->exception.fsr = arm_debug_exception_fsr(env);
967
- /* FAR is UNKNOWN: clear vaddress to avoid potentially exposing
968
+ /*
969
+ * FAR is UNKNOWN: clear vaddress to avoid potentially exposing
970
* values to the guest that it shouldn't be able to see at its
971
* exception/security level.
972
*/
973
diff --git a/target/arm/vfp_helper.c b/target/arm/vfp_helper.c
974
index XXXXXXX..XXXXXXX 100644
1286
index XXXXXXX..XXXXXXX 100644
975
--- a/target/arm/vfp_helper.c
1287
--- a/hw/sd/trace-events
976
+++ b/target/arm/vfp_helper.c
1288
+++ b/hw/sd/trace-events
977
@@ -XXX,XX +XXX,XX @@ void HELPER(vfp_set_fpscr)(CPUARMState *env, uint32_t val)
1289
@@ -XXX,XX +XXX,XX @@
978
set_default_nan_mode(dnan_enabled, &env->vfp.fp_status_f16);
1290
# See docs/devel/tracing.txt for syntax documentation.
979
}
1291
980
1292
+# allwinner-sdhost.c
981
- /* The exception flags are ORed together when we read fpscr so we
1293
+allwinner_sdhost_set_inserted(bool inserted) "inserted %u"
982
+ /*
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
983
+ * The exception flags are ORed together when we read fpscr so we
1295
+allwinner_sdhost_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
984
* only need to preserve the current state in one of our
1296
+allwinner_sdhost_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
985
* float_status values.
1297
+allwinner_sdhost_update_irq(uint32_t irq) "IRQ bits 0x%" PRIx32
986
*/
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"
987
--
1302
--
988
2.20.1
1303
2.20.1
989
1304
990
1305
diff view generated by jsdifflib
1
From: Andrew Jeffery <andrew@aj.id.au>
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
2
2
3
If the match value exceeds reload then we don't want to include it in
3
The Allwinner Sun8i System on Chip family includes an Ethernet MAC (EMAC)
4
calculations for the next event.
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:
5
7
6
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
8
* DMA transfers
7
Signed-off-by: Cédric Le Goater <clg@kaod.org>
9
* MII interface
8
Message-id: 20190618165311.27066-10-clg@kaod.org
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
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
16
---
11
hw/timer/aspeed_timer.c | 13 ++++++++++---
17
hw/net/Makefile.objs | 1 +
12
1 file changed, 10 insertions(+), 3 deletions(-)
18
include/hw/arm/allwinner-h3.h | 3 +
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
13
29
14
diff --git a/hw/timer/aspeed_timer.c b/hw/timer/aspeed_timer.c
30
diff --git a/hw/net/Makefile.objs b/hw/net/Makefile.objs
15
index XXXXXXX..XXXXXXX 100644
31
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/timer/aspeed_timer.c
32
--- a/hw/net/Makefile.objs
17
+++ b/hw/timer/aspeed_timer.c
33
+++ b/hw/net/Makefile.objs
18
@@ -XXX,XX +XXX,XX @@ static inline uint64_t calculate_time(struct AspeedTimer *t, uint32_t ticks)
34
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_XGMAC) += xgmac.o
19
return t->start + delta_ns;
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
46
@@ -XXX,XX +XXX,XX @@
47
#include "hw/misc/allwinner-h3-sysctrl.h"
48
#include "hw/misc/allwinner-sid.h"
49
#include "hw/sd/allwinner-sdhost.h"
50
+#include "hw/net/allwinner-sun8i-emac.h"
51
#include "target/arm/cpu.h"
52
53
/**
54
@@ -XXX,XX +XXX,XX @@ enum {
55
AW_H3_UART1,
56
AW_H3_UART2,
57
AW_H3_UART3,
58
+ AW_H3_EMAC,
59
AW_H3_GIC_DIST,
60
AW_H3_GIC_CPU,
61
AW_H3_GIC_HYP,
62
@@ -XXX,XX +XXX,XX @@ typedef struct AwH3State {
63
AwH3SysCtrlState sysctrl;
64
AwSidState sid;
65
AwSdHostState mmc0;
66
+ AwSun8iEmacState emac;
67
GICState gic;
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
+ * @{
136
+ */
137
+
138
+ uint8_t mii_phy_addr; /**< PHY address */
139
+ uint32_t mii_cr; /**< Control */
140
+ uint32_t mii_st; /**< Status */
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
176
index XXXXXXX..XXXXXXX 100644
177
--- a/hw/arm/allwinner-h3.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);
20
}
210
}
21
211
22
+static inline uint32_t calculate_match(struct AspeedTimer *t, int i)
212
static void allwinner_h3_realize(DeviceState *dev, Error **errp)
23
+{
213
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
24
+ return t->match[i] < t->reload ? t->match[i] : 0;
214
object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->mmc0),
25
+}
215
"sd-bus", &error_abort);
26
+
216
27
static uint64_t calculate_next(struct AspeedTimer *t)
217
+ /* EMAC */
28
{
218
+ if (nd_table[0].used) {
29
uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
219
+ qemu_check_nic_model(&nd_table[0], TYPE_AW_SUN8I_EMAC);
30
@@ -XXX,XX +XXX,XX @@ static uint64_t calculate_next(struct AspeedTimer *t)
220
+ qdev_set_nic_properties(DEVICE(&s->emac), &nd_table[0]);
31
* the timer counts down to zero.
221
+ }
32
*/
222
+ qdev_init_nofail(DEVICE(&s->emac));
33
223
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->emac), 0, s->memmap[AW_H3_EMAC]);
34
- next = calculate_time(t, MAX(t->match[0], t->match[1]));
224
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->emac), 0,
35
+ next = calculate_time(t, MAX(calculate_match(t, 0), calculate_match(t, 1)));
225
+ qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_EMAC));
36
if (now < next) {
226
+
37
return next;
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");
38
}
236
}
39
237
40
- next = calculate_time(t, MIN(t->match[0], t->match[1]));
238
+ /* Setup EMAC properties */
41
+ next = calculate_time(t, MIN(calculate_match(t, 0), calculate_match(t, 1)));
239
+ object_property_set_int(OBJECT(&h3->emac), 1, "phy-addr", &error_abort);
42
if (now < next) {
240
+
43
return next;
241
/* Mark H3 object realized */
44
}
242
object_property_set_bool(OBJECT(h3), true, "realized", &error_abort);
45
@@ -XXX,XX +XXX,XX @@ static uint64_t calculate_next(struct AspeedTimer *t)
243
46
qemu_set_irq(t->irq, t->level);
244
diff --git a/hw/net/allwinner-sun8i-emac.c b/hw/net/allwinner-sun8i-emac.c
47
}
245
new file mode 100644
48
246
index XXXXXXX..XXXXXXX
49
+ next = MAX(MAX(calculate_match(t, 0), calculate_match(t, 1)), 0);
247
--- /dev/null
50
t->start = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
248
+++ b/hw/net/allwinner-sun8i-emac.c
51
- return calculate_time(t, MAX(MAX(t->match[0], t->match[1]), 0));
249
@@ -XXX,XX +XXX,XX @@
52
+
250
+/*
53
+ return calculate_time(t, next);
251
+ * Allwinner Sun8i Ethernet MAC emulation
54
}
252
+ *
55
253
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
56
static void aspeed_timer_mod(AspeedTimer *t)
254
+ *
255
+ * This program is free software: you can redistribute it and/or modify
256
+ * it under the terms of the GNU General Public License as published by
257
+ * the Free Software Foundation, either version 2 of the License, or
258
+ * (at your option) any later version.
259
+ *
260
+ * This program is distributed in the hope that it will be useful,
261
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
262
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
263
+ * GNU General Public License for more details.
264
+ *
265
+ * You should have received a copy of the GNU General Public License
266
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
267
+ */
268
+
269
+#include "qemu/osdep.h"
270
+#include "qemu/units.h"
271
+#include "hw/sysbus.h"
272
+#include "migration/vmstate.h"
273
+#include "net/net.h"
274
+#include "hw/irq.h"
275
+#include "hw/qdev-properties.h"
276
+#include "qemu/log.h"
277
+#include "trace.h"
278
+#include "net/checksum.h"
279
+#include "qemu/module.h"
280
+#include "exec/cpu-common.h"
281
+#include "hw/net/allwinner-sun8i-emac.h"
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
+
624
+ return 0;
625
+}
626
+
627
+static uint32_t allwinner_sun8i_emac_rx_desc(AwSun8iEmacState *s,
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",
1069
+ .version_id = 1,
1070
+ .minimum_version_id = 1,
1071
+ .post_load = allwinner_sun8i_emac_post_load,
1072
+ .fields = (VMStateField[]) {
1073
+ VMSTATE_UINT8(mii_phy_addr, AwSun8iEmacState),
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),
1093
+ VMSTATE_END_OF_LIST()
1094
+ }
1095
+};
1096
+
1097
+static void allwinner_sun8i_emac_class_init(ObjectClass *klass, void *data)
1098
+{
1099
+ DeviceClass *dc = DEVICE_CLASS(klass);
1100
+
1101
+ dc->realize = allwinner_sun8i_emac_realize;
1102
+ dc->reset = allwinner_sun8i_emac_reset;
1103
+ dc->vmsd = &vmstate_aw_emac;
1104
+ device_class_set_props(dc, allwinner_sun8i_emac_properties);
1105
+}
1106
+
1107
+static const TypeInfo allwinner_sun8i_emac_info = {
1108
+ .name = TYPE_AW_SUN8I_EMAC,
1109
+ .parent = TYPE_SYS_BUS_DEVICE,
1110
+ .instance_size = sizeof(AwSun8iEmacState),
1111
+ .instance_init = allwinner_sun8i_emac_init,
1112
+ .class_init = allwinner_sun8i_emac_class_init,
1113
+};
1114
+
1115
+static void allwinner_sun8i_emac_register_types(void)
1116
+{
1117
+ type_register_static(&allwinner_sun8i_emac_info);
1118
+}
1119
+
1120
+type_init(allwinner_sun8i_emac_register_types)
1121
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
1122
index XXXXXXX..XXXXXXX 100644
1123
--- a/hw/arm/Kconfig
1124
+++ b/hw/arm/Kconfig
1125
@@ -XXX,XX +XXX,XX @@ config ALLWINNER_A10
1126
config ALLWINNER_H3
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"
57
--
1167
--
58
2.20.1
1168
2.20.1
59
1169
60
1170
diff view generated by jsdifflib
1
From: Cédric Le Goater <clg@kaod.org>
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
2
2
3
The current models of the Aspeed SoCs only have one CPU but future
3
A real Allwinner H3 SoC contains a Boot ROM which is the
4
ones will support SMP. Introduce a new num_cpus field at the SoC class
4
first code that runs right after the SoC is powered on.
5
level to define the number of available CPUs per SoC and also
5
The Boot ROM is responsible for loading user code (e.g. a bootloader)
6
introduce a 'num-cpus' property to activate the CPUs configured for
6
from any of the supported external devices and writing the downloaded
7
the machine.
7
code to internal SRAM. After loading the SoC begins executing the code
8
written to SRAM.
8
9
9
The max_cpus limit of the machine should depend on the SoC definition
10
This commits adds emulation of the Boot ROM firmware setup functionality
10
but, unfortunately, these values are not available when the machine
11
by loading user code from SD card in the A1 SRAM. While the A1 SRAM is
11
class is initialized. This is the reason why we add a check on
12
64KiB, we limit the size to 32KiB because the real H3 Boot ROM also rejects
12
num_cpus in the AspeedSoC realize handler.
13
sizes larger than 32KiB. For reference, this behaviour is documented
14
by the Linux Sunxi project wiki at:
13
15
14
SMP support will be activated when models for such SoCs are implemented.
16
https://linux-sunxi.org/BROM#U-Boot_SPL_limitations
15
17
16
Signed-off-by: Cédric Le Goater <clg@kaod.org>
18
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
17
Reviewed-by: Joel Stanley <joel@jms.id.au>
19
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
18
Message-id: 20190618165311.27066-6-clg@kaod.org
20
Message-id: 20200311221854.30370-11-nieklinnenbank@gmail.com
19
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
21
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
20
---
22
---
21
include/hw/arm/aspeed_soc.h | 5 ++++-
23
include/hw/arm/allwinner-h3.h | 21 +++++++++++++++++++++
22
hw/arm/aspeed.c | 7 +++++--
24
hw/arm/allwinner-h3.c | 17 +++++++++++++++++
23
hw/arm/aspeed_soc.c | 33 +++++++++++++++++++++++++++------
25
hw/arm/orangepi.c | 5 +++++
24
3 files changed, 36 insertions(+), 9 deletions(-)
26
3 files changed, 43 insertions(+)
25
27
26
diff --git a/include/hw/arm/aspeed_soc.h b/include/hw/arm/aspeed_soc.h
28
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
27
index XXXXXXX..XXXXXXX 100644
29
index XXXXXXX..XXXXXXX 100644
28
--- a/include/hw/arm/aspeed_soc.h
30
--- a/include/hw/arm/allwinner-h3.h
29
+++ b/include/hw/arm/aspeed_soc.h
31
+++ b/include/hw/arm/allwinner-h3.h
30
@@ -XXX,XX +XXX,XX @@
32
@@ -XXX,XX +XXX,XX @@
31
33
#include "hw/sd/allwinner-sdhost.h"
32
#define ASPEED_SPIS_NUM 2
34
#include "hw/net/allwinner-sun8i-emac.h"
33
#define ASPEED_WDTS_NUM 3
35
#include "target/arm/cpu.h"
34
+#define ASPEED_CPUS_NUM 2
36
+#include "sysemu/block-backend.h"
35
37
36
typedef struct AspeedSoCState {
38
/**
37
/*< private >*/
39
* Allwinner H3 device list
38
DeviceState parent;
40
@@ -XXX,XX +XXX,XX @@ typedef struct AwH3State {
39
41
MemoryRegion sram_c;
40
/*< public >*/
42
} AwH3State;
41
- ARMCPU cpu;
43
42
+ ARMCPU cpu[ASPEED_CPUS_NUM];
44
+/**
43
+ uint32_t num_cpus;
45
+ * Emulate Boot ROM firmware setup functionality.
44
MemoryRegion sram;
46
+ *
45
AspeedVICState vic;
47
+ * A real Allwinner H3 SoC contains a Boot ROM
46
AspeedRtcState rtc;
48
+ * which is the first code that runs right after
47
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedSoCInfo {
49
+ * the SoC is powered on. The Boot ROM is responsible
48
int wdts_num;
50
+ * for loading user code (e.g. a bootloader) from any
49
const int *irqmap;
51
+ * of the supported external devices and writing the
50
const hwaddr *memmap;
52
+ * downloaded code to internal SRAM. After loading the SoC
51
+ uint32_t num_cpus;
53
+ * begins executing the code written to SRAM.
52
} AspeedSoCInfo;
54
+ *
53
55
+ * This function emulates the Boot ROM by copying 32 KiB
54
typedef struct AspeedSoCClass {
56
+ * of data from the given block device and writes it to
55
diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c
57
+ * the start of the first internal SRAM memory.
58
+ *
59
+ * @s: Allwinner H3 state object pointer
60
+ * @blk: Block backend device object pointer
61
+ */
62
+void allwinner_h3_bootrom_setup(AwH3State *s, BlockBackend *blk);
63
+
64
#endif /* HW_ARM_ALLWINNER_H3_H */
65
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
56
index XXXXXXX..XXXXXXX 100644
66
index XXXXXXX..XXXXXXX 100644
57
--- a/hw/arm/aspeed.c
67
--- a/hw/arm/allwinner-h3.c
58
+++ b/hw/arm/aspeed.c
68
+++ b/hw/arm/allwinner-h3.c
59
@@ -XXX,XX +XXX,XX @@
60
#include "hw/misc/tmp105.h"
61
#include "qemu/log.h"
62
#include "sysemu/block-backend.h"
63
+#include "sysemu/sysemu.h"
64
#include "hw/loader.h"
65
#include "qemu/error-report.h"
66
#include "qemu/units.h"
67
68
static struct arm_boot_info aspeed_board_binfo = {
69
.board_id = -1, /* device-tree-only board */
70
- .nb_cpus = 1,
71
};
72
73
struct AspeedBoardState {
74
@@ -XXX,XX +XXX,XX @@ static void aspeed_board_init(MachineState *machine,
75
&error_abort);
76
object_property_set_int(OBJECT(&bmc->soc), cfg->num_cs, "num-cs",
77
&error_abort);
78
+ object_property_set_int(OBJECT(&bmc->soc), smp_cpus, "num-cpus",
79
+ &error_abort);
80
if (machine->kernel_filename) {
81
/*
82
* When booting with a -kernel command line there is no u-boot
83
@@ -XXX,XX +XXX,XX @@ static void aspeed_board_init(MachineState *machine,
84
aspeed_board_binfo.kernel_cmdline = machine->kernel_cmdline;
85
aspeed_board_binfo.ram_size = ram_size;
86
aspeed_board_binfo.loader_start = sc->info->memmap[ASPEED_SDRAM];
87
+ aspeed_board_binfo.nb_cpus = bmc->soc.num_cpus;
88
89
if (cfg->i2c_init) {
90
cfg->i2c_init(bmc);
91
@@ -XXX,XX +XXX,XX @@ static void aspeed_machine_class_init(ObjectClass *oc, void *data)
92
93
mc->desc = board->desc;
94
mc->init = aspeed_machine_init;
95
- mc->max_cpus = 1;
96
+ mc->max_cpus = ASPEED_CPUS_NUM;
97
mc->no_sdcard = 1;
98
mc->no_floppy = 1;
99
mc->no_cdrom = 1;
100
diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c
101
index XXXXXXX..XXXXXXX 100644
102
--- a/hw/arm/aspeed_soc.c
103
+++ b/hw/arm/aspeed_soc.c
104
@@ -XXX,XX +XXX,XX @@
69
@@ -XXX,XX +XXX,XX @@
105
#include "hw/char/serial.h"
70
#include "hw/char/serial.h"
106
#include "qemu/log.h"
71
#include "hw/misc/unimp.h"
107
#include "qemu/module.h"
72
#include "hw/usb/hcd-ehci.h"
108
+#include "qemu/error-report.h"
73
+#include "hw/loader.h"
109
#include "hw/i2c/aspeed_i2c.h"
74
#include "sysemu/sysemu.h"
110
#include "net/net.h"
75
#include "hw/arm/allwinner-h3.h"
111
76
112
@@ -XXX,XX +XXX,XX @@ static const AspeedSoCInfo aspeed_socs[] = {
77
@@ -XXX,XX +XXX,XX @@ enum {
113
.wdts_num = 2,
78
AW_H3_GIC_NUM_SPI = 128
114
.irqmap = aspeed_soc_ast2400_irqmap,
115
.memmap = aspeed_soc_ast2400_memmap,
116
+ .num_cpus = 1,
117
}, {
118
.name = "ast2400-a1",
119
.cpu_type = ARM_CPU_TYPE_NAME("arm926"),
120
@@ -XXX,XX +XXX,XX @@ static const AspeedSoCInfo aspeed_socs[] = {
121
.wdts_num = 2,
122
.irqmap = aspeed_soc_ast2400_irqmap,
123
.memmap = aspeed_soc_ast2400_memmap,
124
+ .num_cpus = 1,
125
}, {
126
.name = "ast2400",
127
.cpu_type = ARM_CPU_TYPE_NAME("arm926"),
128
@@ -XXX,XX +XXX,XX @@ static const AspeedSoCInfo aspeed_socs[] = {
129
.wdts_num = 2,
130
.irqmap = aspeed_soc_ast2400_irqmap,
131
.memmap = aspeed_soc_ast2400_memmap,
132
+ .num_cpus = 1,
133
}, {
134
.name = "ast2500-a1",
135
.cpu_type = ARM_CPU_TYPE_NAME("arm1176"),
136
@@ -XXX,XX +XXX,XX @@ static const AspeedSoCInfo aspeed_socs[] = {
137
.wdts_num = 3,
138
.irqmap = aspeed_soc_ast2500_irqmap,
139
.memmap = aspeed_soc_ast2500_memmap,
140
+ .num_cpus = 1,
141
},
142
};
79
};
143
80
144
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_init(Object *obj)
81
+void allwinner_h3_bootrom_setup(AwH3State *s, BlockBackend *blk)
145
AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s);
82
+{
146
int i;
83
+ const int64_t rom_size = 32 * KiB;
147
84
+ g_autofree uint8_t *buffer = g_new0(uint8_t, rom_size);
148
- object_initialize_child(obj, "cpu", OBJECT(&s->cpu), sizeof(s->cpu),
85
+
149
- sc->info->cpu_type, &error_abort, NULL);
86
+ if (blk_pread(blk, 8 * KiB, buffer, rom_size) < 0) {
150
+ for (i = 0; i < sc->info->num_cpus; i++) {
87
+ error_setg(&error_fatal, "%s: failed to read BlockBackend data",
151
+ object_initialize_child(obj, "cpu[*]", OBJECT(&s->cpu[i]),
88
+ __func__);
152
+ sizeof(s->cpu[i]), sc->info->cpu_type,
89
+ return;
153
+ &error_abort, NULL);
154
+ }
155
156
sysbus_init_child_obj(obj, "scu", OBJECT(&s->scu), sizeof(s->scu),
157
TYPE_ASPEED_SCU);
158
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
159
create_unimplemented_device("aspeed_soc.io", sc->info->memmap[ASPEED_IOMEM],
160
ASPEED_SOC_IOMEM_SIZE);
161
162
+ if (s->num_cpus > sc->info->num_cpus) {
163
+ warn_report("%s: invalid number of CPUs %d, using default %d",
164
+ sc->info->name, s->num_cpus, sc->info->num_cpus);
165
+ s->num_cpus = sc->info->num_cpus;
166
+ }
90
+ }
167
+
91
+
168
/* CPU */
92
+ rom_add_blob("allwinner-h3.bootrom", buffer, rom_size,
169
- object_property_set_bool(OBJECT(&s->cpu), true, "realized", &err);
93
+ rom_size, s->memmap[AW_H3_SRAM_A1],
170
- if (err) {
94
+ NULL, NULL, NULL, NULL, false);
171
- error_propagate(errp, err);
95
+}
172
- return;
96
+
173
+ for (i = 0; i < s->num_cpus; i++) {
97
static void allwinner_h3_init(Object *obj)
174
+ object_property_set_bool(OBJECT(&s->cpu[i]), true, "realized", &err);
175
+ if (err) {
176
+ error_propagate(errp, err);
177
+ return;
178
+ }
179
}
180
181
/* SRAM */
182
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
183
sysbus_connect_irq(SYS_BUS_DEVICE(&s->ftgmac100), 0,
184
aspeed_soc_get_irq(s, ASPEED_ETH1));
185
}
186
+static Property aspeed_soc_properties[] = {
187
+ DEFINE_PROP_UINT32("num-cpus", AspeedSoCState, num_cpus, 0),
188
+ DEFINE_PROP_END_OF_LIST(),
189
+};
190
191
static void aspeed_soc_class_init(ObjectClass *oc, void *data)
192
{
98
{
193
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_class_init(ObjectClass *oc, void *data)
99
AwH3State *s = AW_H3(obj);
194
dc->realize = aspeed_soc_realize;
100
diff --git a/hw/arm/orangepi.c b/hw/arm/orangepi.c
195
/* Reason: Uses serial_hds and nd_table in realize() directly */
101
index XXXXXXX..XXXXXXX 100644
196
dc->user_creatable = false;
102
--- a/hw/arm/orangepi.c
197
+ dc->props = aspeed_soc_properties;
103
+++ b/hw/arm/orangepi.c
198
}
104
@@ -XXX,XX +XXX,XX @@ static void orangepi_init(MachineState *machine)
199
105
memory_region_add_subregion(get_system_memory(), h3->memmap[AW_H3_SDRAM],
200
static const TypeInfo aspeed_soc_type_info = {
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);
201
--
116
--
202
2.20.1
117
2.20.1
203
118
204
119
diff view generated by jsdifflib
1
From: Joel Stanley <joel@jms.id.au>
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
2
2
3
The ast2500 uses the watchdog to reset the SDRAM controller. This
3
In the Allwinner H3 SoC the SDRAM controller is responsible
4
operation is usually performed by u-boot's memory training procedure,
4
for interfacing with the external Synchronous Dynamic Random
5
and it is enabled by setting a bit in the SCU and then causing the
5
Access Memory (SDRAM). Types of memory that the SDRAM controller
6
watchdog to expire. Therefore, we need the watchdog to be able to
6
supports are DDR2/DDR3 and capacities of up to 2GiB. This commit
7
access the SCU's register space.
7
adds emulation support of the Allwinner H3 SDRAM controller.
8
8
9
This causes the watchdog to not perform a system reset when the bit is
9
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
10
set. In the future it could perform a reset of the SDMC model.
10
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
11
11
Message-id: 20200311221854.30370-12-nieklinnenbank@gmail.com
12
Signed-off-by: Joel Stanley <joel@jms.id.au>
13
Signed-off-by: Cédric Le Goater <clg@kaod.org>
14
Reviewed-by: Cédric Le Goater <clg@kaod.org>
15
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
16
Message-id: 20190621065242.32535-1-joel@jms.id.au
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
18
---
13
---
19
include/hw/watchdog/wdt_aspeed.h | 1 +
14
hw/misc/Makefile.objs | 1 +
20
hw/arm/aspeed_soc.c | 2 ++
15
include/hw/arm/allwinner-h3.h | 5 +
21
hw/watchdog/wdt_aspeed.c | 20 ++++++++++++++++++++
16
include/hw/misc/allwinner-h3-dramc.h | 106 ++++++++
22
3 files changed, 23 insertions(+)
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/include/hw/watchdog/wdt_aspeed.h b/include/hw/watchdog/wdt_aspeed.h
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/include/hw/watchdog/wdt_aspeed.h
27
--- a/hw/misc/Makefile.objs
27
+++ b/include/hw/watchdog/wdt_aspeed.h
28
+++ b/hw/misc/Makefile.objs
28
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedWDTState {
29
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o
29
MemoryRegion iomem;
30
30
uint32_t regs[ASPEED_WDT_REGS_MAX];
31
common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o
31
32
obj-$(CONFIG_ALLWINNER_H3) += allwinner-cpucfg.o
32
+ AspeedSCUState *scu;
33
+common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-dramc.o
33
uint32_t pclk_freq;
34
common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-sysctrl.o
34
uint32_t silicon_rev;
35
common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-sid.o
35
uint32_t ext_pulse_width_mask;
36
common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o
36
diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c
37
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
37
index XXXXXXX..XXXXXXX 100644
38
index XXXXXXX..XXXXXXX 100644
38
--- a/hw/arm/aspeed_soc.c
39
--- a/include/hw/arm/allwinner-h3.h
39
+++ b/hw/arm/aspeed_soc.c
40
+++ b/include/hw/arm/allwinner-h3.h
40
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_init(Object *obj)
41
@@ -XXX,XX +XXX,XX @@
41
sizeof(s->wdt[i]), TYPE_ASPEED_WDT);
42
#include "hw/intc/arm_gic.h"
42
qdev_prop_set_uint32(DEVICE(&s->wdt[i]), "silicon-rev",
43
#include "hw/misc/allwinner-h3-ccu.h"
43
sc->info->silicon_rev);
44
#include "hw/misc/allwinner-cpucfg.h"
44
+ object_property_add_const_link(OBJECT(&s->wdt[i]), "scu",
45
+#include "hw/misc/allwinner-h3-dramc.h"
45
+ OBJECT(&s->scu), &error_abort);
46
#include "hw/misc/allwinner-h3-sysctrl.h"
46
}
47
#include "hw/misc/allwinner-sid.h"
47
48
#include "hw/sd/allwinner-sdhost.h"
48
for (i = 0; i < ASPEED_MACS_NUM; i++) {
49
@@ -XXX,XX +XXX,XX @@ enum {
49
diff --git a/hw/watchdog/wdt_aspeed.c b/hw/watchdog/wdt_aspeed.c
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
50
index XXXXXXX..XXXXXXX 100644
180
index XXXXXXX..XXXXXXX 100644
51
--- a/hw/watchdog/wdt_aspeed.c
181
--- a/hw/arm/allwinner-h3.c
52
+++ b/hw/watchdog/wdt_aspeed.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
53
@@ -XXX,XX +XXX,XX @@
252
@@ -XXX,XX +XXX,XX @@
54
253
+/*
55
#define WDT_RESTART_MAGIC 0x4755
254
+ * Allwinner H3 SDRAM Controller emulation
56
255
+ *
57
+#define SCU_RESET_CONTROL1 (0x04 / 4)
256
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
58
+#define SCU_RESET_SDRAM BIT(0)
257
+ *
59
+
258
+ * This program is free software: you can redistribute it and/or modify
60
static bool aspeed_wdt_is_enabled(const AspeedWDTState *s)
259
+ * it under the terms of the GNU General Public License as published by
61
{
260
+ * the Free Software Foundation, either version 2 of the License, or
62
return s->regs[WDT_CTRL] & WDT_CTRL_ENABLE;
261
+ * (at your option) any later version.
63
@@ -XXX,XX +XXX,XX @@ static void aspeed_wdt_timer_expired(void *dev)
262
+ *
64
{
263
+ * This program is distributed in the hope that it will be useful,
65
AspeedWDTState *s = ASPEED_WDT(dev);
264
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
66
265
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67
+ /* Do not reset on SDRAM controller reset */
266
+ * GNU General Public License for more details.
68
+ if (s->scu->regs[SCU_RESET_CONTROL1] & SCU_RESET_SDRAM) {
267
+ *
69
+ timer_del(s->timer);
268
+ * You should have received a copy of the GNU General Public License
70
+ s->regs[WDT_CTRL] = 0;
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;
330
+ }
331
+ }
332
+
333
+ if (s->ram_size == (1 << (row_bits - 3))) {
334
+ /* When row bits is the expected value, remove the mirror */
335
+ memory_region_set_enabled(&s->row_mirror_alias, false);
336
+ trace_allwinner_h3_dramc_rowmirror_disable();
337
+
338
+ } else if (row_bits_actual) {
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);
71
+ return;
378
+ return;
72
+ }
379
+ }
73
+
380
+
74
qemu_log_mask(CPU_LOG_RESET, "Watchdog timer expired.\n");
381
+ switch (offset) {
75
watchdog_perform_action();
382
+ case REG_DRAMCOM_CR: /* Control Register */
76
timer_del(s->timer);
383
+ allwinner_h3_dramc_map_rows(s, ((val >> 4) & 0xf) + 1,
77
@@ -XXX,XX +XXX,XX @@ static void aspeed_wdt_realize(DeviceState *dev, Error **errp)
384
+ ((val >> 2) & 0x1) + 2,
78
{
385
+ 1 << (((val >> 8) & 0xf) + 3));
79
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
386
+ break;
80
AspeedWDTState *s = ASPEED_WDT(dev);
387
+ default:
81
+ Error *err = NULL;
388
+ break;
82
+ Object *obj;
389
+ };
83
+
390
+
84
+ obj = object_property_get_link(OBJECT(dev), "scu", &err);
391
+ s->dramcom[idx] = (uint32_t) val;
85
+ if (!obj) {
392
+}
86
+ error_propagate(errp, err);
393
+
87
+ error_prepend(errp, "required link 'scu' not found: ");
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);
88
+ return;
422
+ return;
89
+ }
423
+ }
90
+ s->scu = ASPEED_SCU(obj);
424
+
91
425
+ switch (offset) {
92
if (!is_supported_silicon_rev(s->silicon_rev)) {
426
+ case REG_DRAMCTL_PIR: /* PHY Initialization Register */
93
error_setg(errp, "Unknown silicon revision: 0x%" PRIx32,
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);
526
+ }
527
+ }
528
+
529
+ /* Setup row mirror mappings */
530
+ memory_region_init_ram(&s->row_mirror, OBJECT(s),
531
+ "allwinner-h3-dramc.row-mirror",
532
+ 4 * KiB, &error_abort);
533
+ memory_region_add_subregion_overlap(get_system_memory(), s->ram_addr,
534
+ &s->row_mirror, 10);
535
+
536
+ memory_region_init_alias(&s->row_mirror_alias, OBJECT(s),
537
+ "allwinner-h3-dramc.row-mirror-alias",
538
+ &s->row_mirror, 0, 4 * KiB);
539
+ memory_region_add_subregion_overlap(get_system_memory(),
540
+ s->ram_addr + 1 * MiB,
541
+ &s->row_mirror_alias, 10);
542
+ memory_region_set_enabled(&s->row_mirror_alias, false);
543
+}
544
+
545
+static void allwinner_h3_dramc_init(Object *obj)
546
+{
547
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
548
+ AwH3DramCtlState *s = AW_H3_DRAMC(obj);
549
+
550
+ /* DRAMCOM registers */
551
+ memory_region_init_io(&s->dramcom_iomem, OBJECT(s),
552
+ &allwinner_h3_dramcom_ops, s,
553
+ TYPE_AW_H3_DRAMC, 4 * KiB);
554
+ sysbus_init_mmio(sbd, &s->dramcom_iomem);
555
+
556
+ /* DRAMCTL registers */
557
+ memory_region_init_io(&s->dramctl_iomem, OBJECT(s),
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
94
--
632
--
95
2.20.1
633
2.20.1
96
634
97
635
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
2
2
3
To ease the review of the next commit,
3
Allwinner System-on-Chips usually contain a Real Time Clock (RTC)
4
move the vfp_exceptbits_to_host() function directly after
4
for non-volatile system date and time keeping. This commit adds a generic
5
vfp_exceptbits_from_host(). Amusingly the diff shows we
5
Allwinner RTC device that supports the RTC devices found in Allwinner SoC
6
are moving vfp_get_fpscr().
6
family sun4i (A10), sun7i (A20) and sun6i and newer (A31, H2+, H3, etc).
7
The following RTC functionality and features are implemented:
7
8
8
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
9
* Year-Month-Day read/write
9
Message-id: 20190701132516.26392-15-philmd@redhat.com
10
* Hour-Minute-Second read/write
10
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
11
* General Purpose storage
12
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
target/arm/vfp_helper.c | 52 ++++++++++++++++++++---------------------
23
hw/rtc/Makefile.objs | 1 +
14
1 file changed, 26 insertions(+), 26 deletions(-)
24
include/hw/arm/allwinner-a10.h | 2 +
25
include/hw/arm/allwinner-h3.h | 3 +
26
include/hw/rtc/allwinner-rtc.h | 134 +++++++++++
27
hw/arm/allwinner-a10.c | 8 +
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
15
34
16
diff --git a/target/arm/vfp_helper.c b/target/arm/vfp_helper.c
35
diff --git a/hw/rtc/Makefile.objs b/hw/rtc/Makefile.objs
17
index XXXXXXX..XXXXXXX 100644
36
index XXXXXXX..XXXXXXX 100644
18
--- a/target/arm/vfp_helper.c
37
--- a/hw/rtc/Makefile.objs
19
+++ b/target/arm/vfp_helper.c
38
+++ b/hw/rtc/Makefile.objs
20
@@ -XXX,XX +XXX,XX @@ static inline int vfp_exceptbits_from_host(int host_bits)
39
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_MC146818RTC) += mc146818rtc.o
21
return target_bits;
40
common-obj-$(CONFIG_SUN4V_RTC) += sun4v-rtc.o
41
common-obj-$(CONFIG_ASPEED_SOC) += aspeed_rtc.o
42
common-obj-$(CONFIG_GOLDFISH_RTC) += goldfish_rtc.o
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
93
new file mode 100644
94
index XXXXXXX..XXXXXXX
95
--- /dev/null
96
+++ b/include/hw/rtc/allwinner-rtc.h
97
@@ -XXX,XX +XXX,XX @@
98
+/*
99
+ * Allwinner Real Time Clock emulation
100
+ *
101
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
102
+ *
103
+ * This program is free software: you can redistribute it and/or modify
104
+ * it under the terms of the GNU General Public License as published by
105
+ * the Free Software Foundation, either version 2 of the License, or
106
+ * (at your option) any later version.
107
+ *
108
+ * This program is distributed in the hope that it will be useful,
109
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
110
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
111
+ * GNU General Public License for more details.
112
+ *
113
+ * You should have received a copy of the GNU General Public License
114
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
115
+ */
116
+
117
+#ifndef HW_MISC_ALLWINNER_RTC_H
118
+#define HW_MISC_ALLWINNER_RTC_H
119
+
120
+#include "qom/object.h"
121
+#include "hw/sysbus.h"
122
+
123
+/**
124
+ * Constants
125
+ * @{
126
+ */
127
+
128
+/** Highest register address used by RTC device */
129
+#define AW_RTC_REGS_MAXADDR (0x200)
130
+
131
+/** Total number of known registers */
132
+#define AW_RTC_REGS_NUM (AW_RTC_REGS_MAXADDR / sizeof(uint32_t))
133
+
134
+/** @} */
135
+
136
+/**
137
+ * Object model types
138
+ * @{
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 >*/
174
+ SysBusDevice parent_obj;
175
+ /*< public >*/
176
+
177
+ /**
178
+ * Actual year represented by the device when year counter is zero
179
+ *
180
+ * Can be overridden by the user using the corresponding 'base-year'
181
+ * property. The base year used by the target OS driver can vary, for
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);
22
}
251
}
23
252
24
-uint32_t HELPER(vfp_get_fpscr)(CPUARMState *env)
253
static void aw_a10_realize(DeviceState *dev, Error **errp)
25
-{
254
@@ -XXX,XX +XXX,XX @@ static void aw_a10_realize(DeviceState *dev, Error **errp)
26
- uint32_t i, fpscr;
255
sysbus_connect_irq(SYS_BUS_DEVICE(&s->mmc0), 0, qdev_get_gpio_in(dev, 32));
27
-
256
object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->mmc0),
28
- fpscr = env->vfp.xregs[ARM_VFP_FPSCR]
257
"sd-bus", &error_abort);
29
- | (env->vfp.vec_len << 16)
258
+
30
- | (env->vfp.vec_stride << 20);
259
+ /* RTC */
31
-
260
+ qdev_init_nofail(DEVICE(&s->rtc));
32
- i = get_float_exception_flags(&env->vfp.fp_status);
261
+ sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->rtc), 0, AW_A10_RTC_BASE, 10);
33
- i |= get_float_exception_flags(&env->vfp.standard_fp_status);
34
- /* FZ16 does not generate an input denormal exception. */
35
- i |= (get_float_exception_flags(&env->vfp.fp_status_f16)
36
- & ~float_flag_input_denormal);
37
- fpscr |= vfp_exceptbits_from_host(i);
38
-
39
- i = env->vfp.qc[0] | env->vfp.qc[1] | env->vfp.qc[2] | env->vfp.qc[3];
40
- fpscr |= i ? FPCR_QC : 0;
41
-
42
- return fpscr;
43
-}
44
-
45
-uint32_t vfp_get_fpscr(CPUARMState *env)
46
-{
47
- return HELPER(vfp_get_fpscr)(env);
48
-}
49
-
50
/* Convert vfp exception flags to target form. */
51
static inline int vfp_exceptbits_to_host(int target_bits)
52
{
53
@@ -XXX,XX +XXX,XX @@ static inline int vfp_exceptbits_to_host(int target_bits)
54
return host_bits;
55
}
262
}
56
263
57
+uint32_t HELPER(vfp_get_fpscr)(CPUARMState *env)
264
static void aw_a10_class_init(ObjectClass *oc, void *data)
58
+{
265
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
59
+ uint32_t i, fpscr;
266
index XXXXXXX..XXXXXXX 100644
60
+
267
--- a/hw/arm/allwinner-h3.c
61
+ fpscr = env->vfp.xregs[ARM_VFP_FPSCR]
268
+++ b/hw/arm/allwinner-h3.c
62
+ | (env->vfp.vec_len << 16)
269
@@ -XXX,XX +XXX,XX @@ const hwaddr allwinner_h3_memmap[] = {
63
+ | (env->vfp.vec_stride << 20);
270
[AW_H3_GIC_CPU] = 0x01c82000,
64
+
271
[AW_H3_GIC_HYP] = 0x01c84000,
65
+ i = get_float_exception_flags(&env->vfp.fp_status);
272
[AW_H3_GIC_VCPU] = 0x01c86000,
66
+ i |= get_float_exception_flags(&env->vfp.standard_fp_status);
273
+ [AW_H3_RTC] = 0x01f00000,
67
+ /* FZ16 does not generate an input denormal exception. */
274
[AW_H3_CPUCFG] = 0x01f01c00,
68
+ i |= (get_float_exception_flags(&env->vfp.fp_status_f16)
275
[AW_H3_SDRAM] = 0x40000000
69
+ & ~float_flag_input_denormal);
276
};
70
+ fpscr |= vfp_exceptbits_from_host(i);
277
@@ -XXX,XX +XXX,XX @@ struct AwH3Unimplemented {
71
+
278
{ "csi", 0x01cb0000, 320 * KiB },
72
+ i = env->vfp.qc[0] | env->vfp.qc[1] | env->vfp.qc[2] | env->vfp.qc[3];
279
{ "tve", 0x01e00000, 64 * KiB },
73
+ fpscr |= i ? FPCR_QC : 0;
280
{ "hdmi", 0x01ee0000, 128 * KiB },
74
+
281
- { "rtc", 0x01f00000, 1 * KiB },
75
+ return fpscr;
282
{ "r_timer", 0x01f00800, 1 * KiB },
76
+}
283
{ "r_intc", 0x01f00c00, 1 * KiB },
77
+
284
{ "r_wdog", 0x01f01000, 1 * KiB },
78
+uint32_t vfp_get_fpscr(CPUARMState *env)
285
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_init(Object *obj)
79
+{
286
"ram-addr", &error_abort);
80
+ return HELPER(vfp_get_fpscr)(env);
287
object_property_add_alias(obj, "ram-size", OBJECT(&s->dramc),
81
+}
288
"ram-size", &error_abort);
82
+
289
+
83
void HELPER(vfp_set_fpscr)(CPUARMState *env, uint32_t val)
290
+ sysbus_init_child_obj(obj, "rtc", &s->rtc, sizeof(s->rtc),
84
{
291
+ TYPE_AW_RTC_SUN6I);
85
int i;
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
307
new file mode 100644
308
index XXXXXXX..XXXXXXX
309
--- /dev/null
310
+++ b/hw/rtc/allwinner-rtc.c
311
@@ -XXX,XX +XXX,XX @@
312
+/*
313
+ * Allwinner Real Time Clock emulation
314
+ *
315
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
316
+ *
317
+ * This program is free software: you can redistribute it and/or modify
318
+ * it under the terms of the GNU General Public License as published by
319
+ * the Free Software Foundation, either version 2 of the License, or
320
+ * (at your option) any later version.
321
+ *
322
+ * This program is distributed in the hope that it will be useful,
323
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
324
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
325
+ * GNU General Public License for more details.
326
+ *
327
+ * You should have received a copy of the GNU General Public License
328
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
329
+ */
330
+
331
+#include "qemu/osdep.h"
332
+#include "qemu/units.h"
333
+#include "hw/sysbus.h"
334
+#include "migration/vmstate.h"
335
+#include "qemu/log.h"
336
+#include "qemu/module.h"
337
+#include "qemu-common.h"
338
+#include "hw/qdev-properties.h"
339
+#include "hw/rtc/allwinner-rtc.h"
340
+#include "trace.h"
341
+
342
+/* RTC registers */
343
+enum {
344
+ REG_LOSC = 1, /* Low Oscillator Control */
345
+ REG_YYMMDD, /* RTC Year-Month-Day */
346
+ REG_HHMMSS, /* RTC Hour-Minute-Second */
347
+ REG_ALARM1_WKHHMMSS, /* Alarm1 Week Hour-Minute-Second */
348
+ REG_ALARM1_EN, /* Alarm1 Enable */
349
+ REG_ALARM1_IRQ_EN, /* Alarm1 IRQ Enable */
350
+ REG_ALARM1_IRQ_STA, /* Alarm1 IRQ Status */
351
+ REG_GP0, /* General Purpose Register 0 */
352
+ REG_GP1, /* General Purpose Register 1 */
353
+ REG_GP2, /* General Purpose Register 2 */
354
+ REG_GP3, /* General Purpose Register 3 */
355
+
356
+ /* sun4i registers */
357
+ REG_ALARM1_DDHHMMSS, /* Alarm1 Day Hour-Minute-Second */
358
+ REG_CPUCFG, /* CPU Configuration Register */
359
+
360
+ /* sun6i registers */
361
+ REG_LOSC_AUTOSTA, /* LOSC Auto Switch Status */
362
+ REG_INT_OSC_PRE, /* Internal OSC Clock Prescaler */
363
+ REG_ALARM0_COUNTER, /* Alarm0 Counter */
364
+ REG_ALARM0_CUR_VLU, /* Alarm0 Counter Current Value */
365
+ REG_ALARM0_ENABLE, /* Alarm0 Enable */
366
+ REG_ALARM0_IRQ_EN, /* Alarm0 IRQ Enable */
367
+ REG_ALARM0_IRQ_STA, /* Alarm0 IRQ Status */
368
+ REG_ALARM_CONFIG, /* Alarm Config */
369
+ REG_LOSC_OUT_GATING, /* LOSC Output Gating Register */
370
+ REG_GP4, /* General Purpose Register 4 */
371
+ REG_GP5, /* General Purpose Register 5 */
372
+ REG_GP6, /* General Purpose Register 6 */
373
+ REG_GP7, /* General Purpose Register 7 */
374
+ REG_RTC_DBG, /* RTC Debug Register */
375
+ REG_GPL_HOLD_OUT, /* GPL Hold Output Register */
376
+ REG_VDD_RTC, /* VDD RTC Regulate Register */
377
+ REG_IC_CHARA, /* IC Characteristics Register */
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);
535
+ return;
536
+ }
537
+
538
+ if (!c->regmap[offset]) {
539
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid register 0x%04x\n",
540
+ __func__, (uint32_t)offset);
541
+ return;
542
+ }
543
+
544
+ trace_allwinner_rtc_write(offset, val);
545
+
546
+ switch (c->regmap[offset]) {
547
+ case REG_YYMMDD: /* RTC Year-Month-Day */
548
+ s->regs[REG_YYMMDD] = val;
549
+ s->regs[REG_LOSC] |= REG_LOSC_YMD;
550
+ break;
551
+ case REG_HHMMSS: /* RTC Hour-Minute-Second */
552
+ s->regs[REG_HHMMSS] = val;
553
+ s->regs[REG_LOSC] |= REG_LOSC_HMS;
554
+ break;
555
+ case REG_GP0: /* General Purpose Register 0 */
556
+ case REG_GP1: /* General Purpose Register 1 */
557
+ case REG_GP2: /* General Purpose Register 2 */
558
+ case REG_GP3: /* General Purpose Register 3 */
559
+ s->regs[c->regmap[offset]] = val;
560
+ break;
561
+ default:
562
+ if (!c->write(s, offset, val)) {
563
+ qemu_log_mask(LOG_UNIMP, "%s: unimplemented register 0x%04x\n",
564
+ __func__, (uint32_t)offset);
565
+ }
566
+ break;
567
+ }
568
+}
569
+
570
+static const MemoryRegionOps allwinner_rtc_ops = {
571
+ .read = allwinner_rtc_read,
572
+ .write = allwinner_rtc_write,
573
+ .endianness = DEVICE_NATIVE_ENDIAN,
574
+ .valid = {
575
+ .min_access_size = 4,
576
+ .max_access_size = 4,
577
+ },
578
+ .impl.min_access_size = 4,
579
+};
580
+
581
+static void allwinner_rtc_reset(DeviceState *dev)
582
+{
583
+ AwRtcState *s = AW_RTC(dev);
584
+ struct tm now;
585
+
586
+ /* Clear registers */
587
+ memset(s->regs, 0, sizeof(s->regs));
588
+
589
+ /* Get current datetime */
590
+ qemu_get_timedate(&now, 0);
591
+
592
+ /* Set RTC with current datetime */
593
+ if (s->base_year > 1900) {
594
+ s->regs[REG_YYMMDD] = ((now.tm_year + 1900 - s->base_year) << 16) |
595
+ ((now.tm_mon + 1) << 8) |
596
+ now.tm_mday;
597
+ s->regs[REG_HHMMSS] = (((now.tm_wday + 6) % 7) << 29) |
598
+ (now.tm_hour << 16) |
599
+ (now.tm_min << 8) |
600
+ now.tm_sec;
601
+ }
602
+}
603
+
604
+static void allwinner_rtc_init(Object *obj)
605
+{
606
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
607
+ AwRtcState *s = AW_RTC(obj);
608
+
609
+ /* Memory mapping */
610
+ memory_region_init_io(&s->iomem, OBJECT(s), &allwinner_rtc_ops, s,
611
+ TYPE_AW_RTC, 1 * KiB);
612
+ sysbus_init_mmio(sbd, &s->iomem);
613
+}
614
+
615
+static const VMStateDescription allwinner_rtc_vmstate = {
616
+ .name = "allwinner-rtc",
617
+ .version_id = 1,
618
+ .minimum_version_id = 1,
619
+ .fields = (VMStateField[]) {
620
+ VMSTATE_UINT32_ARRAY(regs, AwRtcState, AW_RTC_REGS_NUM),
621
+ VMSTATE_END_OF_LIST()
622
+ }
623
+};
624
+
625
+static Property allwinner_rtc_properties[] = {
626
+ DEFINE_PROP_INT32("base-year", AwRtcState, base_year, 0),
627
+ DEFINE_PROP_END_OF_LIST(),
628
+};
629
+
630
+static void allwinner_rtc_class_init(ObjectClass *klass, void *data)
631
+{
632
+ DeviceClass *dc = DEVICE_CLASS(klass);
633
+
634
+ dc->reset = allwinner_rtc_reset;
635
+ dc->vmsd = &allwinner_rtc_vmstate;
636
+ device_class_set_props(dc, allwinner_rtc_properties);
637
+}
638
+
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,
685
+ .parent = TYPE_SYS_BUS_DEVICE,
686
+ .instance_init = allwinner_rtc_init,
687
+ .instance_size = sizeof(AwRtcState),
688
+ .class_init = allwinner_rtc_class_init,
689
+ .class_size = sizeof(AwRtcClass),
690
+ .abstract = true,
691
+};
692
+
693
+static const TypeInfo allwinner_rtc_sun4i_info = {
694
+ .name = TYPE_AW_RTC_SUN4I,
695
+ .parent = TYPE_AW_RTC,
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
86
--
737
--
87
2.20.1
738
2.20.1
88
739
89
740
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
The vfp_set_fpscr() helper contains code specific to the host
3
This test boots a Linux kernel on a OrangePi PC board and verify
4
floating point implementation (here the SoftFloat library).
4
the serial output is working.
5
Extract this code to vfp_set_fpscr_from_host().
6
5
7
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
6
The kernel image and DeviceTree blob are built by the Armbian
8
Message-id: 20190701132516.26392-17-philmd@redhat.com
7
project (based on Debian):
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
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()]
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
47
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
48
---
12
target/arm/vfp_helper.c | 19 +++++++++++++------
49
tests/acceptance/boot_linux_console.py | 25 +++++++++++++++++++++++++
13
1 file changed, 13 insertions(+), 6 deletions(-)
50
1 file changed, 25 insertions(+)
14
51
15
diff --git a/target/arm/vfp_helper.c b/target/arm/vfp_helper.c
52
diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
16
index XXXXXXX..XXXXXXX 100644
53
index XXXXXXX..XXXXXXX 100644
17
--- a/target/arm/vfp_helper.c
54
--- a/tests/acceptance/boot_linux_console.py
18
+++ b/target/arm/vfp_helper.c
55
+++ b/tests/acceptance/boot_linux_console.py
19
@@ -XXX,XX +XXX,XX @@ static inline int vfp_exceptbits_to_host(int target_bits)
56
@@ -XXX,XX +XXX,XX @@ class BootLinuxConsole(Test):
20
return host_bits;
57
exec_command_and_wait_for_pattern(self, 'reboot',
21
}
58
'reboot: Restarting system')
22
59
23
+static uint32_t vfp_get_fpscr_from_host(CPUARMState *env)
60
+ def test_arm_orangepi(self):
24
+{
61
+ """
25
+ uint32_t i;
62
+ :avocado: tags=arch:arm
63
+ :avocado: tags=machine:orangepi-pc
64
+ """
65
+ deb_url = ('https://apt.armbian.com/pool/main/l/'
66
+ 'linux-4.20.7-sunxi/linux-image-dev-sunxi_5.75_armhf.deb')
67
+ deb_hash = '1334c29c44d984ffa05ed10de8c3361f33d78315'
68
+ deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
69
+ kernel_path = self.extract_from_deb(deb_path,
70
+ '/boot/vmlinuz-4.20.7-sunxi')
71
+ dtb_path = '/usr/lib/linux-image-dev-sunxi/sun8i-h3-orangepi-pc.dtb'
72
+ dtb_path = self.extract_from_deb(deb_path, dtb_path)
26
+
73
+
27
+ i = get_float_exception_flags(&env->vfp.fp_status);
74
+ self.vm.set_console()
28
+ i |= get_float_exception_flags(&env->vfp.standard_fp_status);
75
+ kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
29
+ /* FZ16 does not generate an input denormal exception. */
76
+ 'console=ttyS0,115200n8 '
30
+ i |= (get_float_exception_flags(&env->vfp.fp_status_f16)
77
+ 'earlycon=uart,mmio32,0x1c28000')
31
+ & ~float_flag_input_denormal);
78
+ self.vm.add_args('-kernel', kernel_path,
32
+ return vfp_exceptbits_from_host(i);
79
+ '-dtb', dtb_path,
33
+}
80
+ '-append', kernel_command_line)
81
+ self.vm.launch()
82
+ console_pattern = 'Kernel command line: %s' % kernel_command_line
83
+ self.wait_for_console_pattern(console_pattern)
34
+
84
+
35
static void vfp_set_fpscr_to_host(CPUARMState *env, uint32_t val)
85
def test_s390x_s390_ccw_virtio(self):
36
{
86
"""
37
int i;
87
:avocado: tags=arch:s390x
38
@@ -XXX,XX +XXX,XX @@ uint32_t HELPER(vfp_get_fpscr)(CPUARMState *env)
39
| (env->vfp.vec_len << 16)
40
| (env->vfp.vec_stride << 20);
41
42
- i = get_float_exception_flags(&env->vfp.fp_status);
43
- i |= get_float_exception_flags(&env->vfp.standard_fp_status);
44
- /* FZ16 does not generate an input denormal exception. */
45
- i |= (get_float_exception_flags(&env->vfp.fp_status_f16)
46
- & ~float_flag_input_denormal);
47
- fpscr |= vfp_exceptbits_from_host(i);
48
+ fpscr |= vfp_get_fpscr_from_host(env);
49
50
i = env->vfp.qc[0] | env->vfp.qc[1] | env->vfp.qc[2] | env->vfp.qc[3];
51
fpscr |= i ? FPCR_QC : 0;
52
--
88
--
53
2.20.1
89
2.20.1
54
90
55
91
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
In the next commit we will split the TLB related routines of
3
This test boots a Linux kernel on a OrangePi PC board and verify
4
this file, and this function will also be called in the new
4
the serial output is working.
5
file. Declare it in the "internals.h" header.
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
6
86
7
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
87
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
8
Message-id: 20190701132516.26392-12-philmd@redhat.com
88
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
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()]
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
93
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
94
---
12
target/arm/internals.h | 16 ++++++++++++++++
95
tests/acceptance/boot_linux_console.py | 40 ++++++++++++++++++++++++++
13
target/arm/helper.c | 21 +++++----------------
96
1 file changed, 40 insertions(+)
14
2 files changed, 21 insertions(+), 16 deletions(-)
15
97
16
diff --git a/target/arm/internals.h b/target/arm/internals.h
98
diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
17
index XXXXXXX..XXXXXXX 100644
99
index XXXXXXX..XXXXXXX 100644
18
--- a/target/arm/internals.h
100
--- a/tests/acceptance/boot_linux_console.py
19
+++ b/target/arm/internals.h
101
+++ b/tests/acceptance/boot_linux_console.py
20
@@ -XXX,XX +XXX,XX @@ static inline int exception_target_el(CPUARMState *env)
102
@@ -XXX,XX +XXX,XX @@ class BootLinuxConsole(Test):
21
return target_el;
103
console_pattern = 'Kernel command line: %s' % kernel_command_line
22
}
104
self.wait_for_console_pattern(console_pattern)
23
105
24
+#ifndef CONFIG_USER_ONLY
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)
25
+
126
+
26
+/* Cacheability and shareability attributes for a memory access */
127
+ self.vm.set_console()
27
+typedef struct ARMCacheAttrs {
128
+ kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
28
+ unsigned int attrs:8; /* as in the MAIR register encoding */
129
+ 'console=ttyS0,115200 '
29
+ unsigned int shareability:2; /* as in the SH field of the VMSAv8-64 PTEs */
130
+ 'panic=-1 noreboot')
30
+} ARMCacheAttrs;
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.')
31
+
138
+
32
+bool get_phys_addr(CPUARMState *env, target_ulong address,
139
+ exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
33
+ MMUAccessType access_type, ARMMMUIdx mmu_idx,
140
+ 'Allwinner sun8i Family')
34
+ hwaddr *phys_ptr, MemTxAttrs *attrs, int *prot,
141
+ exec_command_and_wait_for_pattern(self, 'cat /proc/iomem',
35
+ target_ulong *page_size,
142
+ 'system-control@1c00000')
36
+ ARMMMUFaultInfo *fi, ARMCacheAttrs *cacheattrs);
143
+ exec_command_and_wait_for_pattern(self, 'reboot',
144
+ 'reboot: Restarting system')
37
+
145
+
38
+#endif /* !CONFIG_USER_ONLY */
146
def test_s390x_s390_ccw_virtio(self):
39
+
147
"""
40
#endif
148
:avocado: tags=arch:s390x
41
diff --git a/target/arm/helper.c b/target/arm/helper.c
42
index XXXXXXX..XXXXXXX 100644
43
--- a/target/arm/helper.c
44
+++ b/target/arm/helper.c
45
@@ -XXX,XX +XXX,XX @@
46
#define ARM_CPU_FREQ 1000000000 /* FIXME: 1 GHz, should be configurable */
47
48
#ifndef CONFIG_USER_ONLY
49
-/* Cacheability and shareability attributes for a memory access */
50
-typedef struct ARMCacheAttrs {
51
- unsigned int attrs:8; /* as in the MAIR register encoding */
52
- unsigned int shareability:2; /* as in the SH field of the VMSAv8-64 PTEs */
53
-} ARMCacheAttrs;
54
-
55
-static bool get_phys_addr(CPUARMState *env, target_ulong address,
56
- MMUAccessType access_type, ARMMMUIdx mmu_idx,
57
- hwaddr *phys_ptr, MemTxAttrs *attrs, int *prot,
58
- target_ulong *page_size,
59
- ARMMMUFaultInfo *fi, ARMCacheAttrs *cacheattrs);
60
61
static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address,
62
MMUAccessType access_type, ARMMMUIdx mmu_idx,
63
@@ -XXX,XX +XXX,XX @@ static ARMCacheAttrs combine_cacheattrs(ARMCacheAttrs s1, ARMCacheAttrs s2)
64
* @fi: set to fault info if the translation fails
65
* @cacheattrs: (if non-NULL) set to the cacheability/shareability attributes
66
*/
67
-static bool get_phys_addr(CPUARMState *env, target_ulong address,
68
- MMUAccessType access_type, ARMMMUIdx mmu_idx,
69
- hwaddr *phys_ptr, MemTxAttrs *attrs, int *prot,
70
- target_ulong *page_size,
71
- ARMMMUFaultInfo *fi, ARMCacheAttrs *cacheattrs)
72
+bool get_phys_addr(CPUARMState *env, target_ulong address,
73
+ MMUAccessType access_type, ARMMMUIdx mmu_idx,
74
+ hwaddr *phys_ptr, MemTxAttrs *attrs, int *prot,
75
+ target_ulong *page_size,
76
+ ARMMMUFaultInfo *fi, ARMCacheAttrs *cacheattrs)
77
{
78
if (mmu_idx == ARMMMUIdx_S12NSE0 || mmu_idx == ARMMMUIdx_S12NSE1) {
79
/* Call ourselves recursively to do the stage 1 and then stage 2
80
--
149
--
81
2.20.1
150
2.20.1
82
151
83
152
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
Reviewed-by: Robert Bradford <robert.bradford@intel.com>
3
The kernel image and DeviceTree blob are built by the Armbian
4
Reviewed-by: Samuel Ortiz <sameo@linux.intel.com>
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>
5
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
66
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
6
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
67
Tested-by: Alex Bennée <alex.bennee@linaro.org>
7
Message-id: 20190701132516.26392-6-philmd@redhat.com
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]
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
71
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
72
---
10
target/arm/helper.c | 7 +++++++
73
tests/acceptance/boot_linux_console.py | 47 ++++++++++++++++++++++++++
11
1 file changed, 7 insertions(+)
74
1 file changed, 47 insertions(+)
12
75
13
diff --git a/target/arm/helper.c b/target/arm/helper.c
76
diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
14
index XXXXXXX..XXXXXXX 100644
77
index XXXXXXX..XXXXXXX 100644
15
--- a/target/arm/helper.c
78
--- a/tests/acceptance/boot_linux_console.py
16
+++ b/target/arm/helper.c
79
+++ b/tests/acceptance/boot_linux_console.py
17
@@ -XXX,XX +XXX,XX @@
80
@@ -XXX,XX +XXX,XX @@ class BootLinuxConsole(Test):
18
+/*
81
exec_command_and_wait_for_pattern(self, 'reboot',
19
+ * ARM generic helpers.
82
'reboot: Restarting system')
20
+ *
83
21
+ * This code is licensed under the GNU GPL v2 or later.
84
+ def test_arm_orangepi_sd(self):
22
+ *
85
+ """
23
+ * SPDX-License-Identifier: GPL-2.0-or-later
86
+ :avocado: tags=arch:arm
24
+ */
87
+ :avocado: tags=machine:orangepi-pc
25
#include "qemu/osdep.h"
88
+ """
26
#include "qemu/units.h"
89
+ deb_url = ('https://apt.armbian.com/pool/main/l/'
27
#include "target/arm/idau.h"
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
28
--
134
--
29
2.20.1
135
2.20.1
30
136
31
137
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
Group SOFTMMU objects together.
3
This test boots Ubuntu Bionic on a OrangePi PC board.
4
Since PSCI is TCG specific, keep it separate.
5
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>
6
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
52
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
7
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
53
Tested-by: Alex Bennée <alex.bennee@linaro.org>
8
Message-id: 20190701132516.26392-5-philmd@redhat.com
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]
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
57
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
58
---
11
target/arm/Makefile.objs | 5 ++++-
59
tests/acceptance/boot_linux_console.py | 48 ++++++++++++++++++++++++++
12
1 file changed, 4 insertions(+), 1 deletion(-)
60
1 file changed, 48 insertions(+)
13
61
14
diff --git a/target/arm/Makefile.objs b/target/arm/Makefile.objs
62
diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
15
index XXXXXXX..XXXXXXX 100644
63
index XXXXXXX..XXXXXXX 100644
16
--- a/target/arm/Makefile.objs
64
--- a/tests/acceptance/boot_linux_console.py
17
+++ b/target/arm/Makefile.objs
65
+++ b/tests/acceptance/boot_linux_console.py
18
@@ -XXX,XX +XXX,XX @@
66
@@ -XXX,XX +XXX,XX @@ from avocado_qemu import exec_command_and_wait_for_pattern
19
obj-y += arm-semi.o
67
from avocado_qemu import wait_for_console_pattern
20
-obj-$(CONFIG_SOFTMMU) += machine.o psci.o arch_dump.o monitor.o
68
from avocado.utils import process
21
obj-y += helper.o vfp_helper.o
69
from avocado.utils import archive
22
obj-y += cpu.o gdbstub.o
70
+from avocado.utils.path import find_command, CmdNotFoundError
23
obj-$(TARGET_AARCH64) += cpu64.o gdbstub64.o
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
+ """
24
+
91
+
25
+obj-$(CONFIG_SOFTMMU) += machine.o arch_dump.o monitor.o
92
+ # This test download a 196MB compressed image and expand it to 932MB...
26
obj-$(CONFIG_SOFTMMU) += arm-powerctl.o
93
+ image_url = ('https://dl.armbian.com/orangepipc/archive/'
27
94
+ 'Armbian_19.11.3_Orangepipc_bionic_current_5.3.9.7z')
28
obj-$(CONFIG_KVM) += kvm.o
95
+ image_hash = '196a8ffb72b0123d92cea4a070894813d305c71e'
29
@@ -XXX,XX +XXX,XX @@ obj-y += translate.o op_helper.o
96
+ image_path_7z = self.fetch_asset(image_url, asset_hash=image_hash)
30
obj-y += crypto_helper.o
97
+ image_name = 'Armbian_19.11.3_Orangepipc_bionic_current_5.3.9.img'
31
obj-y += iwmmxt_helper.o vec_helper.o neon_helper.o
98
+ image_path = os.path.join(self.workdir, image_name)
32
99
+ process.run("7z e -o%s %s" % (self.workdir, image_path_7z))
33
+obj-$(CONFIG_SOFTMMU) += psci.o
34
+
100
+
35
obj-$(TARGET_AARCH64) += translate-a64.o helper-a64.o
101
+ self.vm.set_console()
36
obj-$(TARGET_AARCH64) += translate-sve.o sve_helper.o
102
+ self.vm.add_args('-drive', 'file=' + image_path + ',if=sd,format=raw',
37
obj-$(TARGET_AARCH64) += pauth_helper.o
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
38
--
129
--
39
2.20.1
130
2.20.1
40
131
41
132
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
Group KVM rules together.
3
This test boots U-Boot then NetBSD (stored on a SD card) on
4
a OrangePi PC board.
4
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>
5
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
75
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
6
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
76
Tested-by: Alex Bennée <alex.bennee@linaro.org>
7
Message-id: 20190701132516.26392-4-philmd@redhat.com
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]
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
79
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
80
---
10
target/arm/Makefile.objs | 9 +++++----
81
tests/acceptance/boot_linux_console.py | 70 ++++++++++++++++++++++++++
11
1 file changed, 5 insertions(+), 4 deletions(-)
82
1 file changed, 70 insertions(+)
12
83
13
diff --git a/target/arm/Makefile.objs b/target/arm/Makefile.objs
84
diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
14
index XXXXXXX..XXXXXXX 100644
85
index XXXXXXX..XXXXXXX 100644
15
--- a/target/arm/Makefile.objs
86
--- a/tests/acceptance/boot_linux_console.py
16
+++ b/target/arm/Makefile.objs
87
+++ b/tests/acceptance/boot_linux_console.py
17
@@ -XXX,XX +XXX,XX @@
88
@@ -XXX,XX +XXX,XX @@ import shutil
18
obj-y += arm-semi.o
89
from avocado import skipUnless
19
obj-$(CONFIG_SOFTMMU) += machine.o psci.o arch_dump.o monitor.o
90
from avocado_qemu import Test
20
-obj-$(CONFIG_KVM) += kvm.o
91
from avocado_qemu import exec_command_and_wait_for_pattern
21
-obj-$(call land,$(CONFIG_KVM),$(call lnot,$(TARGET_AARCH64))) += kvm32.o
92
+from avocado_qemu import interrupt_interactive_console_until_pattern
22
-obj-$(call land,$(CONFIG_KVM),$(TARGET_AARCH64)) += kvm64.o
93
from avocado_qemu import wait_for_console_pattern
23
-obj-$(call lnot,$(CONFIG_KVM)) += kvm-stub.o
94
from avocado.utils import process
24
obj-y += helper.o vfp_helper.o
95
from avocado.utils import archive
25
obj-y += cpu.o gdbstub.o
96
@@ -XXX,XX +XXX,XX @@ class BootLinuxConsole(Test):
26
obj-$(TARGET_AARCH64) += cpu64.o gdbstub64.o
97
'to <orangepipc>')
27
obj-$(CONFIG_SOFTMMU) += arm-powerctl.o
98
self.wait_for_console_pattern('Starting Load Kernel Modules...')
28
99
29
+obj-$(CONFIG_KVM) += kvm.o
100
+ @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited')
30
+obj-$(call land,$(CONFIG_KVM),$(call lnot,$(TARGET_AARCH64))) += kvm32.o
101
+ def test_arm_orangepi_uboot_netbsd9(self):
31
+obj-$(call land,$(CONFIG_KVM),$(TARGET_AARCH64)) += kvm64.o
102
+ """
32
+obj-$(call lnot,$(CONFIG_KVM)) += kvm-stub.o
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)
33
+
125
+
34
DECODETREE = $(SRC_PATH)/scripts/decodetree.py
126
+ # dd if=u-boot-sunxi-with-spl.bin of=armv7.img bs=1K seek=8 conv=notrunc
35
127
+ with open(uboot_path, 'rb') as f_in:
36
target/arm/decode-sve.inc.c: $(SRC_PATH)/target/arm/sve.decode $(DECODETREE)
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
37
--
172
--
38
2.20.1
173
2.20.1
39
174
40
175
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
2
2
3
These routines are TCG specific.
3
The Xunlong Orange Pi PC machine is a functional ARM machine
4
The arm_deliver_fault() function is only used within the new
4
based on the Allwinner H3 System-on-Chip. It supports mainline
5
helper. Make it static.
5
Linux, U-Boot, NetBSD and is covered by acceptance tests.
6
6
7
Suggested-by: Alex Bennée <alex.bennee@linaro.org>
7
This commit adds a documentation text file with a description
8
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
8
of the machine and instructions for the user.
9
Message-id: 20190701132516.26392-13-philmd@redhat.com
9
10
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
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]
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
17
---
13
target/arm/Makefile.objs | 1 +
18
MAINTAINERS | 1 +
14
target/arm/internals.h | 3 -
19
docs/system/arm/orangepi.rst | 253 +++++++++++++++++++++++++++++++++++
15
target/arm/cpu.c | 6 +-
20
docs/system/target-arm.rst | 2 +
16
target/arm/helper.c | 53 -----------
21
3 files changed, 256 insertions(+)
17
target/arm/op_helper.c | 135 --------------------------
22
create mode 100644 docs/system/arm/orangepi.rst
18
target/arm/tlb_helper.c | 200 +++++++++++++++++++++++++++++++++++++++
23
19
6 files changed, 205 insertions(+), 193 deletions(-)
24
diff --git a/MAINTAINERS b/MAINTAINERS
20
create mode 100644 target/arm/tlb_helper.c
21
22
diff --git a/target/arm/Makefile.objs b/target/arm/Makefile.objs
23
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
24
--- a/target/arm/Makefile.objs
26
--- a/MAINTAINERS
25
+++ b/target/arm/Makefile.objs
27
+++ b/MAINTAINERS
26
@@ -XXX,XX +XXX,XX @@ target/arm/translate-sve.o: target/arm/decode-sve.inc.c
28
@@ -XXX,XX +XXX,XX @@ S: Maintained
27
target/arm/translate.o: target/arm/decode-vfp.inc.c
29
F: hw/*/allwinner-h3*
28
target/arm/translate.o: target/arm/decode-vfp-uncond.inc.c
30
F: include/hw/*/allwinner-h3*
29
31
F: hw/arm/orangepi.c
30
+obj-y += tlb_helper.o
32
+F: docs/system/orangepi.rst
31
obj-y += translate.o op_helper.o
33
32
obj-y += crypto_helper.o
34
ARM PrimeCell and CMSDK devices
33
obj-y += iwmmxt_helper.o vec_helper.o neon_helper.o
35
M: Peter Maydell <peter.maydell@linaro.org>
34
diff --git a/target/arm/internals.h b/target/arm/internals.h
36
diff --git a/docs/system/arm/orangepi.rst b/docs/system/arm/orangepi.rst
35
index XXXXXXX..XXXXXXX 100644
36
--- a/target/arm/internals.h
37
+++ b/target/arm/internals.h
38
@@ -XXX,XX +XXX,XX @@ bool arm_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
39
MMUAccessType access_type, int mmu_idx,
40
bool probe, uintptr_t retaddr);
41
42
-void arm_deliver_fault(ARMCPU *cpu, vaddr addr, MMUAccessType access_type,
43
- int mmu_idx, ARMMMUFaultInfo *fi) QEMU_NORETURN;
44
-
45
/* Return true if the stage 1 translation regime is using LPAE format page
46
* tables */
47
bool arm_s1_regime_using_lpae_format(CPUARMState *env, ARMMMUIdx mmu_idx);
48
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
49
index XXXXXXX..XXXXXXX 100644
50
--- a/target/arm/cpu.c
51
+++ b/target/arm/cpu.c
52
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_class_init(ObjectClass *oc, void *data)
53
cc->gdb_write_register = arm_cpu_gdb_write_register;
54
#ifndef CONFIG_USER_ONLY
55
cc->do_interrupt = arm_cpu_do_interrupt;
56
- cc->do_unaligned_access = arm_cpu_do_unaligned_access;
57
- cc->do_transaction_failed = arm_cpu_do_transaction_failed;
58
cc->get_phys_page_attrs_debug = arm_cpu_get_phys_page_attrs_debug;
59
cc->asidx_from_attrs = arm_asidx_from_attrs;
60
cc->vmsd = &vmstate_arm_cpu;
61
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_class_init(ObjectClass *oc, void *data)
62
#ifdef CONFIG_TCG
63
cc->tcg_initialize = arm_translate_init;
64
cc->tlb_fill = arm_cpu_tlb_fill;
65
+#if !defined(CONFIG_USER_ONLY)
66
+ cc->do_unaligned_access = arm_cpu_do_unaligned_access;
67
+ cc->do_transaction_failed = arm_cpu_do_transaction_failed;
68
+#endif /* CONFIG_TCG && !CONFIG_USER_ONLY */
69
#endif
70
}
71
72
diff --git a/target/arm/helper.c b/target/arm/helper.c
73
index XXXXXXX..XXXXXXX 100644
74
--- a/target/arm/helper.c
75
+++ b/target/arm/helper.c
76
@@ -XXX,XX +XXX,XX @@ uint32_t HELPER(v7m_tt)(CPUARMState *env, uint32_t addr, uint32_t op)
77
78
#endif
79
80
-bool arm_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
81
- MMUAccessType access_type, int mmu_idx,
82
- bool probe, uintptr_t retaddr)
83
-{
84
- ARMCPU *cpu = ARM_CPU(cs);
85
-
86
-#ifdef CONFIG_USER_ONLY
87
- cpu->env.exception.vaddress = address;
88
- if (access_type == MMU_INST_FETCH) {
89
- cs->exception_index = EXCP_PREFETCH_ABORT;
90
- } else {
91
- cs->exception_index = EXCP_DATA_ABORT;
92
- }
93
- cpu_loop_exit_restore(cs, retaddr);
94
-#else
95
- hwaddr phys_addr;
96
- target_ulong page_size;
97
- int prot, ret;
98
- MemTxAttrs attrs = {};
99
- ARMMMUFaultInfo fi = {};
100
-
101
- /*
102
- * Walk the page table and (if the mapping exists) add the page
103
- * to the TLB. On success, return true. Otherwise, if probing,
104
- * return false. Otherwise populate fsr with ARM DFSR/IFSR fault
105
- * register format, and signal the fault.
106
- */
107
- ret = get_phys_addr(&cpu->env, address, access_type,
108
- core_to_arm_mmu_idx(&cpu->env, mmu_idx),
109
- &phys_addr, &attrs, &prot, &page_size, &fi, NULL);
110
- if (likely(!ret)) {
111
- /*
112
- * Map a single [sub]page. Regions smaller than our declared
113
- * target page size are handled specially, so for those we
114
- * pass in the exact addresses.
115
- */
116
- if (page_size >= TARGET_PAGE_SIZE) {
117
- phys_addr &= TARGET_PAGE_MASK;
118
- address &= TARGET_PAGE_MASK;
119
- }
120
- tlb_set_page_with_attrs(cs, address, phys_addr, attrs,
121
- prot, mmu_idx, page_size);
122
- return true;
123
- } else if (probe) {
124
- return false;
125
- } else {
126
- /* now we have a real cpu fault */
127
- cpu_restore_state(cs, retaddr, true);
128
- arm_deliver_fault(cpu, address, access_type, mmu_idx, &fi);
129
- }
130
-#endif
131
-}
132
-
133
/* Note that signed overflow is undefined in C. The following routines are
134
careful to use unsigned types where modulo arithmetic is required.
135
Failure to do so _will_ break on newer gcc. */
136
diff --git a/target/arm/op_helper.c b/target/arm/op_helper.c
137
index XXXXXXX..XXXXXXX 100644
138
--- a/target/arm/op_helper.c
139
+++ b/target/arm/op_helper.c
140
@@ -XXX,XX +XXX,XX @@ uint32_t HELPER(neon_tbl)(uint32_t ireg, uint32_t def, void *vn,
141
return val;
142
}
143
144
-#if !defined(CONFIG_USER_ONLY)
145
-
146
-static inline uint32_t merge_syn_data_abort(uint32_t template_syn,
147
- unsigned int target_el,
148
- bool same_el, bool ea,
149
- bool s1ptw, bool is_write,
150
- int fsc)
151
-{
152
- uint32_t syn;
153
-
154
- /*
155
- * ISV is only set for data aborts routed to EL2 and
156
- * never for stage-1 page table walks faulting on stage 2.
157
- *
158
- * Furthermore, ISV is only set for certain kinds of load/stores.
159
- * If the template syndrome does not have ISV set, we should leave
160
- * it cleared.
161
- *
162
- * See ARMv8 specs, D7-1974:
163
- * ISS encoding for an exception from a Data Abort, the
164
- * ISV field.
165
- */
166
- if (!(template_syn & ARM_EL_ISV) || target_el != 2 || s1ptw) {
167
- syn = syn_data_abort_no_iss(same_el,
168
- ea, 0, s1ptw, is_write, fsc);
169
- } else {
170
- /*
171
- * Fields: IL, ISV, SAS, SSE, SRT, SF and AR come from the template
172
- * syndrome created at translation time.
173
- * Now we create the runtime syndrome with the remaining fields.
174
- */
175
- syn = syn_data_abort_with_iss(same_el,
176
- 0, 0, 0, 0, 0,
177
- ea, 0, s1ptw, is_write, fsc,
178
- false);
179
- /* Merge the runtime syndrome with the template syndrome. */
180
- syn |= template_syn;
181
- }
182
- return syn;
183
-}
184
-
185
-void arm_deliver_fault(ARMCPU *cpu, vaddr addr, MMUAccessType access_type,
186
- int mmu_idx, ARMMMUFaultInfo *fi)
187
-{
188
- CPUARMState *env = &cpu->env;
189
- int target_el;
190
- bool same_el;
191
- uint32_t syn, exc, fsr, fsc;
192
- ARMMMUIdx arm_mmu_idx = core_to_arm_mmu_idx(env, mmu_idx);
193
-
194
- target_el = exception_target_el(env);
195
- if (fi->stage2) {
196
- target_el = 2;
197
- env->cp15.hpfar_el2 = extract64(fi->s2addr, 12, 47) << 4;
198
- }
199
- same_el = (arm_current_el(env) == target_el);
200
-
201
- if (target_el == 2 || arm_el_is_aa64(env, target_el) ||
202
- arm_s1_regime_using_lpae_format(env, arm_mmu_idx)) {
203
- /*
204
- * LPAE format fault status register : bottom 6 bits are
205
- * status code in the same form as needed for syndrome
206
- */
207
- fsr = arm_fi_to_lfsc(fi);
208
- fsc = extract32(fsr, 0, 6);
209
- } else {
210
- fsr = arm_fi_to_sfsc(fi);
211
- /*
212
- * Short format FSR : this fault will never actually be reported
213
- * to an EL that uses a syndrome register. Use a (currently)
214
- * reserved FSR code in case the constructed syndrome does leak
215
- * into the guest somehow.
216
- */
217
- fsc = 0x3f;
218
- }
219
-
220
- if (access_type == MMU_INST_FETCH) {
221
- syn = syn_insn_abort(same_el, fi->ea, fi->s1ptw, fsc);
222
- exc = EXCP_PREFETCH_ABORT;
223
- } else {
224
- syn = merge_syn_data_abort(env->exception.syndrome, target_el,
225
- same_el, fi->ea, fi->s1ptw,
226
- access_type == MMU_DATA_STORE,
227
- fsc);
228
- if (access_type == MMU_DATA_STORE
229
- && arm_feature(env, ARM_FEATURE_V6)) {
230
- fsr |= (1 << 11);
231
- }
232
- exc = EXCP_DATA_ABORT;
233
- }
234
-
235
- env->exception.vaddress = addr;
236
- env->exception.fsr = fsr;
237
- raise_exception(env, exc, syn, target_el);
238
-}
239
-
240
-/* Raise a data fault alignment exception for the specified virtual address */
241
-void arm_cpu_do_unaligned_access(CPUState *cs, vaddr vaddr,
242
- MMUAccessType access_type,
243
- int mmu_idx, uintptr_t retaddr)
244
-{
245
- ARMCPU *cpu = ARM_CPU(cs);
246
- ARMMMUFaultInfo fi = {};
247
-
248
- /* now we have a real cpu fault */
249
- cpu_restore_state(cs, retaddr, true);
250
-
251
- fi.type = ARMFault_Alignment;
252
- arm_deliver_fault(cpu, vaddr, access_type, mmu_idx, &fi);
253
-}
254
-
255
-/*
256
- * arm_cpu_do_transaction_failed: handle a memory system error response
257
- * (eg "no device/memory present at address") by raising an external abort
258
- * exception
259
- */
260
-void arm_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr,
261
- vaddr addr, unsigned size,
262
- MMUAccessType access_type,
263
- int mmu_idx, MemTxAttrs attrs,
264
- MemTxResult response, uintptr_t retaddr)
265
-{
266
- ARMCPU *cpu = ARM_CPU(cs);
267
- ARMMMUFaultInfo fi = {};
268
-
269
- /* now we have a real cpu fault */
270
- cpu_restore_state(cs, retaddr, true);
271
-
272
- fi.ea = arm_extabort_type(response);
273
- fi.type = ARMFault_SyncExternal;
274
- arm_deliver_fault(cpu, addr, access_type, mmu_idx, &fi);
275
-}
276
-
277
-#endif /* !defined(CONFIG_USER_ONLY) */
278
-
279
void HELPER(v8m_stackcheck)(CPUARMState *env, uint32_t newvalue)
280
{
281
/*
282
diff --git a/target/arm/tlb_helper.c b/target/arm/tlb_helper.c
283
new file mode 100644
37
new file mode 100644
284
index XXXXXXX..XXXXXXX
38
index XXXXXXX..XXXXXXX
285
--- /dev/null
39
--- /dev/null
286
+++ b/target/arm/tlb_helper.c
40
+++ b/docs/system/arm/orangepi.rst
287
@@ -XXX,XX +XXX,XX @@
41
@@ -XXX,XX +XXX,XX @@
288
+/*
42
+Orange Pi PC (``orangepi-pc``)
289
+ * ARM TLB (Translation lookaside buffer) helpers.
43
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
290
+ *
44
+
291
+ * This code is licensed under the GNU GPL v2 or later.
45
+The Xunlong Orange Pi PC is an Allwinner H3 System on Chip
292
+ *
46
+based embedded computer with mainline support in both U-Boot
293
+ * SPDX-License-Identifier: GPL-2.0-or-later
47
+and Linux. The board comes with a Quad Core Cortex-A7 @ 1.3GHz,
294
+ */
48
+1GiB RAM, 100Mbit ethernet, USB, SD/MMC, USB, HDMI and
295
+#include "qemu/osdep.h"
49
+various other I/O.
296
+#include "cpu.h"
50
+
297
+#include "internals.h"
51
+Supported devices
298
+#include "exec/exec-all.h"
52
+"""""""""""""""""
299
+
53
+
300
+#if !defined(CONFIG_USER_ONLY)
54
+The Orange Pi PC machine supports the following devices:
301
+
55
+
302
+static inline uint32_t merge_syn_data_abort(uint32_t template_syn,
56
+ * SMP (Quad Core Cortex-A7)
303
+ unsigned int target_el,
57
+ * Generic Interrupt Controller configuration
304
+ bool same_el, bool ea,
58
+ * SRAM mappings
305
+ bool s1ptw, bool is_write,
59
+ * SDRAM controller
306
+ int fsc)
60
+ * Real Time Clock
307
+{
61
+ * Timer device (re-used from Allwinner A10)
308
+ uint32_t syn;
62
+ * UART
309
+
63
+ * SD/MMC storage controller
310
+ /*
64
+ * EMAC ethernet
311
+ * ISV is only set for data aborts routed to EL2 and
65
+ * USB 2.0 interfaces
312
+ * never for stage-1 page table walks faulting on stage 2.
66
+ * Clock Control Unit
313
+ *
67
+ * System Control module
314
+ * Furthermore, ISV is only set for certain kinds of load/stores.
68
+ * Security Identifier device
315
+ * If the template syndrome does not have ISV set, we should leave
69
+
316
+ * it cleared.
70
+Limitations
317
+ *
71
+"""""""""""
318
+ * See ARMv8 specs, D7-1974:
72
+
319
+ * ISS encoding for an exception from a Data Abort, the
73
+Currently, Orange Pi PC does *not* support the following features:
320
+ * ISV field.
74
+
321
+ */
75
+- Graphical output via HDMI, GPU and/or the Display Engine
322
+ if (!(template_syn & ARM_EL_ISV) || target_el != 2 || s1ptw) {
76
+- Audio output
323
+ syn = syn_data_abort_no_iss(same_el,
77
+- Hardware Watchdog
324
+ ea, 0, s1ptw, is_write, fsc);
78
+
325
+ } else {
79
+Also see the 'unimplemented' array in the Allwinner H3 SoC module
326
+ /*
80
+for a complete list of unimplemented I/O devices: ``./hw/arm/allwinner-h3.c``
327
+ * Fields: IL, ISV, SAS, SSE, SRT, SF and AR come from the template
81
+
328
+ * syndrome created at translation time.
82
+Boot options
329
+ * Now we create the runtime syndrome with the remaining fields.
83
+""""""""""""
330
+ */
84
+
331
+ syn = syn_data_abort_with_iss(same_el,
85
+The Orange Pi PC machine can start using the standard -kernel functionality
332
+ 0, 0, 0, 0, 0,
86
+for loading a Linux kernel or ELF executable. Additionally, the Orange Pi PC
333
+ ea, 0, s1ptw, is_write, fsc,
87
+machine can also emulate the BootROM which is present on an actual Allwinner H3
334
+ false);
88
+based SoC, which loads the bootloader from a SD card, specified via the -sd argument
335
+ /* Merge the runtime syndrome with the template syndrome. */
89
+to qemu-system-arm.
336
+ syn |= template_syn;
90
+
337
+ }
91
+Machine-specific options
338
+ return syn;
92
+""""""""""""""""""""""""
339
+}
93
+
340
+
94
+The following machine-specific options are supported:
341
+static void QEMU_NORETURN arm_deliver_fault(ARMCPU *cpu, vaddr addr,
95
+
342
+ MMUAccessType access_type,
96
+- allwinner-rtc.base-year=YYYY
343
+ int mmu_idx, ARMMMUFaultInfo *fi)
97
+
344
+{
98
+ The Allwinner RTC device is automatically created by the Orange Pi PC machine
345
+ CPUARMState *env = &cpu->env;
99
+ and uses a default base year value which can be overridden using the 'base-year' property.
346
+ int target_el;
100
+ The base year is the actual represented year when the RTC year value is zero.
347
+ bool same_el;
101
+ This option can be used in case the target operating system driver uses a different
348
+ uint32_t syn, exc, fsr, fsc;
102
+ base year value. The minimum value for the base year is 1900.
349
+ ARMMMUIdx arm_mmu_idx = core_to_arm_mmu_idx(env, mmu_idx);
103
+
350
+
104
+- allwinner-sid.identifier=abcd1122-a000-b000-c000-12345678ffff
351
+ target_el = exception_target_el(env);
105
+
352
+ if (fi->stage2) {
106
+ The Security Identifier value can be read by the guest.
353
+ target_el = 2;
107
+ For example, U-Boot uses it to determine a unique MAC address.
354
+ env->cp15.hpfar_el2 = extract64(fi->s2addr, 12, 47) << 4;
108
+
355
+ }
109
+The above machine-specific options can be specified in qemu-system-arm
356
+ same_el = (arm_current_el(env) == target_el);
110
+via the '-global' argument, for example:
357
+
111
+
358
+ if (target_el == 2 || arm_el_is_aa64(env, target_el) ||
112
+.. code-block:: bash
359
+ arm_s1_regime_using_lpae_format(env, arm_mmu_idx)) {
113
+
360
+ /*
114
+ $ qemu-system-arm -M orangepi-pc -sd mycard.img \
361
+ * LPAE format fault status register : bottom 6 bits are
115
+ -global allwinner-rtc.base-year=2000
362
+ * status code in the same form as needed for syndrome
116
+
363
+ */
117
+Running mainline Linux
364
+ fsr = arm_fi_to_lfsc(fi);
118
+""""""""""""""""""""""
365
+ fsc = extract32(fsr, 0, 6);
119
+
366
+ } else {
120
+Mainline Linux kernels from 4.19 up to latest master are known to work.
367
+ fsr = arm_fi_to_sfsc(fi);
121
+To build a Linux mainline kernel that can be booted by the Orange Pi PC machine,
368
+ /*
122
+simply configure the kernel using the sunxi_defconfig configuration:
369
+ * Short format FSR : this fault will never actually be reported
123
+
370
+ * to an EL that uses a syndrome register. Use a (currently)
124
+.. code-block:: bash
371
+ * reserved FSR code in case the constructed syndrome does leak
125
+
372
+ * into the guest somehow.
126
+ $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make mrproper
373
+ */
127
+ $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make sunxi_defconfig
374
+ fsc = 0x3f;
128
+
375
+ }
129
+To be able to use USB storage, you need to manually enable the corresponding
376
+
130
+configuration item. Start the kconfig configuration tool:
377
+ if (access_type == MMU_INST_FETCH) {
131
+
378
+ syn = syn_insn_abort(same_el, fi->ea, fi->s1ptw, fsc);
132
+.. code-block:: bash
379
+ exc = EXCP_PREFETCH_ABORT;
133
+
380
+ } else {
134
+ $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make menuconfig
381
+ syn = merge_syn_data_abort(env->exception.syndrome, target_el,
135
+
382
+ same_el, fi->ea, fi->s1ptw,
136
+Navigate to the following item, enable it and save your configuration:
383
+ access_type == MMU_DATA_STORE,
137
+
384
+ fsc);
138
+ Device Drivers > USB support > USB Mass Storage support
385
+ if (access_type == MMU_DATA_STORE
139
+
386
+ && arm_feature(env, ARM_FEATURE_V6)) {
140
+Build the Linux kernel with:
387
+ fsr |= (1 << 11);
141
+
388
+ }
142
+.. code-block:: bash
389
+ exc = EXCP_DATA_ABORT;
143
+
390
+ }
144
+ $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make
391
+
145
+
392
+ env->exception.vaddress = addr;
146
+To boot the newly build linux kernel in QEMU with the Orange Pi PC machine, use:
393
+ env->exception.fsr = fsr;
147
+
394
+ raise_exception(env, exc, syn, target_el);
148
+.. code-block:: bash
395
+}
149
+
396
+
150
+ $ qemu-system-arm -M orangepi-pc -nic user -nographic \
397
+/* Raise a data fault alignment exception for the specified virtual address */
151
+ -kernel /path/to/linux/arch/arm/boot/zImage \
398
+void arm_cpu_do_unaligned_access(CPUState *cs, vaddr vaddr,
152
+ -append 'console=ttyS0,115200' \
399
+ MMUAccessType access_type,
153
+ -dtb /path/to/linux/arch/arm/boot/dts/sun8i-h3-orangepi-pc.dtb
400
+ int mmu_idx, uintptr_t retaddr)
154
+
401
+{
155
+Orange Pi PC images
402
+ ARMCPU *cpu = ARM_CPU(cs);
156
+"""""""""""""""""""
403
+ ARMMMUFaultInfo fi = {};
157
+
404
+
158
+Note that the mainline kernel does not have a root filesystem. You may provide it
405
+ /* now we have a real cpu fault */
159
+with an official Orange Pi PC image from the official website:
406
+ cpu_restore_state(cs, retaddr, true);
160
+
407
+
161
+ http://www.orangepi.org/downloadresources/
408
+ fi.type = ARMFault_Alignment;
162
+
409
+ arm_deliver_fault(cpu, vaddr, access_type, mmu_idx, &fi);
163
+Another possibility is to run an Armbian image for Orange Pi PC which
410
+}
164
+can be downloaded from:
411
+
165
+
412
+/*
166
+ https://www.armbian.com/orange-pi-pc/
413
+ * arm_cpu_do_transaction_failed: handle a memory system error response
167
+
414
+ * (eg "no device/memory present at address") by raising an external abort
168
+Alternatively, you can also choose to build you own image with buildroot
415
+ * exception
169
+using the orangepi_pc_defconfig. Also see https://buildroot.org for more information.
416
+ */
170
+
417
+void arm_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr,
171
+You can choose to attach the selected image either as an SD card or as USB mass storage.
418
+ vaddr addr, unsigned size,
172
+For example, to boot using the Orange Pi PC Debian image on SD card, simply add the -sd
419
+ MMUAccessType access_type,
173
+argument and provide the proper root= kernel parameter:
420
+ int mmu_idx, MemTxAttrs attrs,
174
+
421
+ MemTxResult response, uintptr_t retaddr)
175
+.. code-block:: bash
422
+{
176
+
423
+ ARMCPU *cpu = ARM_CPU(cs);
177
+ $ qemu-system-arm -M orangepi-pc -nic user -nographic \
424
+ ARMMMUFaultInfo fi = {};
178
+ -kernel /path/to/linux/arch/arm/boot/zImage \
425
+
179
+ -append 'console=ttyS0,115200 root=/dev/mmcblk0p2' \
426
+ /* now we have a real cpu fault */
180
+ -dtb /path/to/linux/arch/arm/boot/dts/sun8i-h3-orangepi-pc.dtb \
427
+ cpu_restore_state(cs, retaddr, true);
181
+ -sd OrangePi_pc_debian_stretch_server_linux5.3.5_v1.0.img
428
+
182
+
429
+ fi.ea = arm_extabort_type(response);
183
+To attach the image as an USB mass storage device to the machine,
430
+ fi.type = ARMFault_SyncExternal;
184
+simply append to the command:
431
+ arm_deliver_fault(cpu, addr, access_type, mmu_idx, &fi);
185
+
432
+}
186
+.. code-block:: bash
433
+
187
+
434
+#endif /* !defined(CONFIG_USER_ONLY) */
188
+ -drive if=none,id=stick,file=myimage.img \
435
+
189
+ -device usb-storage,bus=usb-bus.0,drive=stick
436
+bool arm_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
190
+
437
+ MMUAccessType access_type, int mmu_idx,
191
+Instead of providing a custom Linux kernel via the -kernel command you may also
438
+ bool probe, uintptr_t retaddr)
192
+choose to let the Orange Pi PC machine load the bootloader from SD card, just like
439
+{
193
+a real board would do using the BootROM. Simply pass the selected image via the -sd
440
+ ARMCPU *cpu = ARM_CPU(cs);
194
+argument and remove the -kernel, -append, -dbt and -initrd arguments:
441
+
195
+
442
+#ifdef CONFIG_USER_ONLY
196
+.. code-block:: bash
443
+ cpu->env.exception.vaddress = address;
197
+
444
+ if (access_type == MMU_INST_FETCH) {
198
+ $ qemu-system-arm -M orangepi-pc -nic user -nographic \
445
+ cs->exception_index = EXCP_PREFETCH_ABORT;
199
+ -sd Armbian_19.11.3_Orangepipc_buster_current_5.3.9.img
446
+ } else {
200
+
447
+ cs->exception_index = EXCP_DATA_ABORT;
201
+Note that both the official Orange Pi PC images and Armbian images start
448
+ }
202
+a lot of userland programs via systemd. Depending on the host hardware and OS,
449
+ cpu_loop_exit_restore(cs, retaddr);
203
+they may be slow to emulate, especially due to emulating the 4 cores.
450
+#else
204
+To help reduce the performance slow down due to emulating the 4 cores, you can
451
+ hwaddr phys_addr;
205
+give the following kernel parameters via U-Boot (or via -append):
452
+ target_ulong page_size;
206
+
453
+ int prot, ret;
207
+.. code-block:: bash
454
+ MemTxAttrs attrs = {};
208
+
455
+ ARMMMUFaultInfo fi = {};
209
+ => setenv extraargs 'systemd.default_timeout_start_sec=9000 loglevel=7 nosmp console=ttyS0,115200'
456
+
210
+
457
+ /*
211
+Running U-Boot
458
+ * Walk the page table and (if the mapping exists) add the page
212
+""""""""""""""
459
+ * to the TLB. On success, return true. Otherwise, if probing,
213
+
460
+ * return false. Otherwise populate fsr with ARM DFSR/IFSR fault
214
+U-Boot mainline can be build and configured using the orangepi_pc_defconfig
461
+ * register format, and signal the fault.
215
+using similar commands as describe above for Linux. Note that it is recommended
462
+ */
216
+for development/testing to select the following configuration setting in U-Boot:
463
+ ret = get_phys_addr(&cpu->env, address, access_type,
217
+
464
+ core_to_arm_mmu_idx(&cpu->env, mmu_idx),
218
+ Device Tree Control > Provider for DTB for DT Control > Embedded DTB
465
+ &phys_addr, &attrs, &prot, &page_size, &fi, NULL);
219
+
466
+ if (likely(!ret)) {
220
+To start U-Boot using the Orange Pi PC machine, provide the
467
+ /*
221
+u-boot binary to the -kernel argument:
468
+ * Map a single [sub]page. Regions smaller than our declared
222
+
469
+ * target page size are handled specially, so for those we
223
+.. code-block:: bash
470
+ * pass in the exact addresses.
224
+
471
+ */
225
+ $ qemu-system-arm -M orangepi-pc -nic user -nographic \
472
+ if (page_size >= TARGET_PAGE_SIZE) {
226
+ -kernel /path/to/uboot/u-boot -sd disk.img
473
+ phys_addr &= TARGET_PAGE_MASK;
227
+
474
+ address &= TARGET_PAGE_MASK;
228
+Use the following U-boot commands to load and boot a Linux kernel from SD card:
475
+ }
229
+
476
+ tlb_set_page_with_attrs(cs, address, phys_addr, attrs,
230
+.. code-block:: bash
477
+ prot, mmu_idx, page_size);
231
+
478
+ return true;
232
+ => setenv bootargs console=ttyS0,115200
479
+ } else if (probe) {
233
+ => ext2load mmc 0 0x42000000 zImage
480
+ return false;
234
+ => ext2load mmc 0 0x43000000 sun8i-h3-orangepi-pc.dtb
481
+ } else {
235
+ => bootz 0x42000000 - 0x43000000
482
+ /* now we have a real cpu fault */
236
+
483
+ cpu_restore_state(cs, retaddr, true);
237
+Running NetBSD
484
+ arm_deliver_fault(cpu, address, access_type, mmu_idx, &fi);
238
+""""""""""""""
485
+ }
239
+
486
+#endif
240
+The NetBSD operating system also includes support for Allwinner H3 based boards,
487
+}
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
================
488
--
315
--
489
2.20.1
316
2.20.1
490
317
491
318
diff view generated by jsdifflib
1
From: Andrew Jones <drjones@redhat.com>
1
From: Eric Auger <eric.auger@redhat.com>
2
2
3
Fix the condition used to check whether the initrd fits
3
Mention 'max' value in the gic-version property description.
4
into RAM; in some cases if an initrd was also passed on
5
the command line we would get an error stating that it
6
was too big to fit into RAM after the kernel. Despite the
7
error the loader continued anyway, though, so also add an
8
exit(1) when the initrd is actually too big.
9
4
10
Fixes: 852dc64d665f ("hw/arm/boot: Diagnose layouts that put initrd or
5
Signed-off-by: Eric Auger <eric.auger@redhat.com>
11
DTB off the end of RAM")
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Signed-off-by: Andrew Jones <drjones@redhat.com>
7
Reviewed-by: Andrew Jones <drjones@redhat.com>
13
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
8
Message-id: 20200311131618.7187-2-eric.auger@redhat.com
14
Message-id: 20190618125844.4863-1-drjones@redhat.com
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
---
10
---
17
hw/arm/boot.c | 3 ++-
11
hw/arm/virt.c | 3 ++-
18
1 file changed, 2 insertions(+), 1 deletion(-)
12
1 file changed, 2 insertions(+), 1 deletion(-)
19
13
20
diff --git a/hw/arm/boot.c b/hw/arm/boot.c
14
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
21
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
22
--- a/hw/arm/boot.c
16
--- a/hw/arm/virt.c
23
+++ b/hw/arm/boot.c
17
+++ b/hw/arm/virt.c
24
@@ -XXX,XX +XXX,XX @@ static void arm_setup_direct_kernel_boot(ARMCPU *cpu,
18
@@ -XXX,XX +XXX,XX @@ static void virt_instance_init(Object *obj)
25
info->initrd_filename);
19
virt_set_gic_version, NULL);
26
exit(1);
20
object_property_set_description(obj, "gic-version",
27
}
21
"Set GIC version. "
28
- if (info->initrd_start + initrd_size > info->ram_size) {
22
- "Valid values are 2, 3 and host", NULL);
29
+ if (info->initrd_start + initrd_size > ram_end) {
23
+ "Valid values are 2, 3, host and max",
30
error_report("could not load initrd '%s': "
24
+ NULL);
31
"too big to fit into RAM after the kernel",
25
32
info->initrd_filename);
26
vms->highmem_ecam = !vmc->no_highmem_ecam;
33
+ exit(1);
27
34
}
35
} else {
36
initrd_size = 0;
37
--
28
--
38
2.20.1
29
2.20.1
39
30
40
31
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
1
From: Eric Auger <eric.auger@redhat.com>
2
2
3
This machine correctly defines its default_cpu_type to cortex-m3
3
We plan to introduce yet another value for the gic version (nosel).
4
and report an error if the user requested another cpu_type,
4
As we already use exotic values such as 0 and -1, let's introduce
5
however it does not exit, and this can confuse users trying
5
a dedicated enum type and let vms->gic_version take this
6
to use another core:
6
type.
7
7
8
$ qemu-system-arm -M emcraft-sf2 -cpu cortex-m4 -kernel test-m4.elf
8
Signed-off-by: Eric Auger <eric.auger@redhat.com>
9
qemu-system-arm: This board can only be used with CPU cortex-m3-arm-cpu
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
[output related to M3 core ...]
10
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
11
11
Reviewed-by: Andrew Jones <drjones@redhat.com>
12
The CPU is indeed a M3 core:
12
Message-id: 20200311131618.7187-3-eric.auger@redhat.com
13
14
(qemu) info qom-tree
15
/machine (emcraft-sf2-machine)
16
/unattached (container)
17
/device[0] (msf2-soc)
18
/armv7m (armv7m)
19
/cpu (cortex-m3-arm-cpu)
20
21
Add the missing exit() call to return to the shell.
22
23
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
24
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
25
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
26
Message-id: 20190617160136.29930-1-philmd@redhat.com
27
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
28
---
14
---
29
hw/arm/msf2-som.c | 1 +
15
include/hw/arm/virt.h | 11 +++++++++--
30
1 file changed, 1 insertion(+)
16
hw/arm/virt.c | 30 +++++++++++++++---------------
17
2 files changed, 24 insertions(+), 17 deletions(-)
31
18
32
diff --git a/hw/arm/msf2-som.c b/hw/arm/msf2-som.c
19
diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h
33
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
34
--- a/hw/arm/msf2-som.c
21
--- a/include/hw/arm/virt.h
35
+++ b/hw/arm/msf2-som.c
22
+++ b/include/hw/arm/virt.h
36
@@ -XXX,XX +XXX,XX @@ static void emcraft_sf2_s2s010_init(MachineState *machine)
23
@@ -XXX,XX +XXX,XX @@ typedef enum VirtIOMMUType {
37
if (strcmp(machine->cpu_type, mc->default_cpu_type) != 0) {
24
VIRT_IOMMU_VIRTIO,
38
error_report("This board can only be used with CPU %s",
25
} VirtIOMMUType;
39
mc->default_cpu_type);
26
40
+ exit(1);
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;
41
}
61
}
42
62
43
memory_region_init_ram(ddr, NULL, "ddr-ram", DDR_SIZE,
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)
78
}
79
}
80
81
- if (vms->gic_version == 2) {
82
+ if (vms->gic_version == VIRT_GIC_VERSION_2) {
83
irqflags = deposit32(irqflags, GIC_FDT_IRQ_PPI_CPU_START,
84
GIC_FDT_IRQ_PPI_CPU_WIDTH,
85
(1 << vms->smp_cpus) - 1);
86
@@ -XXX,XX +XXX,XX @@ static uint64_t virt_cpu_mp_affinity(VirtMachineState *vms, int idx)
87
* purposes are to make TCG consistent (with 64-bit KVM hosts)
88
* and to improve SGI efficiency.
89
*/
90
- if (vms->gic_version == 3) {
91
+ if (vms->gic_version == VIRT_GIC_VERSION_3) {
92
clustersz = GICV3_TARGETLIST_BITS;
93
} else {
94
clustersz = GIC_TARGETLIST_BITS;
95
@@ -XXX,XX +XXX,XX @@ static void machvirt_init(MachineState *machine)
96
/* We can probe only here because during property set
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);
108
} else {
109
/* "max": currently means 3 for TCG */
110
- vms->gic_version = 3;
111
+ vms->gic_version = VIRT_GIC_VERSION_3;
112
}
113
} else {
114
vms->gic_version = kvm_arm_vgic_probe();
115
@@ -XXX,XX +XXX,XX @@ static void machvirt_init(MachineState *machine)
116
/* The maximum number of CPUs depends on the GIC version, or on how
117
* many redistributors we can fit into the memory map.
118
*/
119
- if (vms->gic_version == 3) {
120
+ if (vms->gic_version == VIRT_GIC_VERSION_3) {
121
virt_max_cpus =
122
vms->memmap[VIRT_GIC_REDIST].size / GICV3_REDIST_SIZE;
123
virt_max_cpus +=
124
@@ -XXX,XX +XXX,XX @@ static void virt_set_its(Object *obj, bool value, Error **errp)
125
static char *virt_get_gic_version(Object *obj, Error **errp)
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",
44
--
160
--
45
2.20.1
161
2.20.1
46
162
47
163
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
1
From: Eric Auger <eric.auger@redhat.com>
2
2
3
In the next commit we will split the M-profile functions from this
3
Let's move the code which freezes which gic-version to
4
file. Some function will be called out of helper.c. Declare them in
4
be applied in a dedicated function. We also now set by
5
the "internals.h" header.
5
default the VIRT_GIC_VERSION_NO_SET. This eventually
6
turns into the legacy v2 choice in the finalize() function.
6
7
7
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
8
Signed-off-by: Eric Auger <eric.auger@redhat.com>
8
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Message-id: 20190701132516.26392-22-philmd@redhat.com
10
Reviewed-by: Andrew Jones <drjones@redhat.com>
11
Message-id: 20200311131618.7187-4-eric.auger@redhat.com
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
13
---
12
target/arm/internals.h | 42 ++++++++++++++++++++++++++++++++++++++++++
14
include/hw/arm/virt.h | 1 +
13
target/arm/helper.c | 38 ++------------------------------------
15
hw/arm/virt.c | 54 ++++++++++++++++++++++++++-----------------
14
2 files changed, 44 insertions(+), 36 deletions(-)
16
2 files changed, 34 insertions(+), 21 deletions(-)
15
17
16
diff --git a/target/arm/internals.h b/target/arm/internals.h
18
diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h
17
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
18
--- a/target/arm/internals.h
20
--- a/include/hw/arm/virt.h
19
+++ b/target/arm/internals.h
21
+++ b/include/hw/arm/virt.h
20
@@ -XXX,XX +XXX,XX @@ static inline uint32_t v7m_sp_limit(CPUARMState *env)
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)
21
}
35
}
22
}
36
}
23
37
24
+/**
38
+/*
25
+ * v7m_cpacr_pass:
39
+ * finalize_gic_version - Determines the final gic_version
26
+ * Return true if the v7M CPACR permits access to the FPU for the specified
40
+ * according to the gic-version property
27
+ * security state and privilege level.
41
+ *
42
+ * Default GIC type is v2
28
+ */
43
+ */
29
+static inline bool v7m_cpacr_pass(CPUARMState *env,
44
+static void finalize_gic_version(VirtMachineState *vms)
30
+ bool is_secure, bool is_priv)
31
+{
45
+{
32
+ switch (extract32(env->v7m.cpacr[is_secure], 20, 2)) {
46
+ if (vms->gic_version == VIRT_GIC_VERSION_HOST ||
33
+ case 0:
47
+ vms->gic_version == VIRT_GIC_VERSION_MAX) {
34
+ case 2: /* UNPREDICTABLE: we treat like 0 */
48
+ if (!kvm_enabled()) {
35
+ return false;
49
+ if (vms->gic_version == VIRT_GIC_VERSION_HOST) {
36
+ case 1:
50
+ error_report("gic-version=host requires KVM");
37
+ return is_priv;
51
+ exit(1);
38
+ case 3:
52
+ } else {
39
+ return true;
53
+ /* "max": currently means 3 for TCG */
40
+ default:
54
+ vms->gic_version = VIRT_GIC_VERSION_3;
41
+ g_assert_not_reached();
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;
42
+ }
66
+ }
43
+}
67
+}
44
+
68
+
45
/**
69
static void machvirt_init(MachineState *machine)
46
* aarch32_mode_name(): Return name of the AArch32 CPU mode
70
{
47
* @psr: Program Status Register indicating CPU mode
71
VirtMachineState *vms = VIRT_MACHINE(machine);
48
@@ -XXX,XX +XXX,XX @@ static inline int exception_target_el(CPUARMState *env)
72
@@ -XXX,XX +XXX,XX @@ static void machvirt_init(MachineState *machine)
49
73
/* We can probe only here because during property set
50
#ifndef CONFIG_USER_ONLY
74
* KVM is not available yet
51
75
*/
52
+/* Security attributes for an address, as returned by v8m_security_lookup. */
76
- if (vms->gic_version == VIRT_GIC_VERSION_HOST ||
53
+typedef struct V8M_SAttributes {
77
- vms->gic_version == VIRT_GIC_VERSION_MAX) {
54
+ bool subpage; /* true if these attrs don't cover the whole TARGET_PAGE */
78
- if (!kvm_enabled()) {
55
+ bool ns;
79
- if (vms->gic_version == VIRT_GIC_VERSION_HOST) {
56
+ bool nsc;
80
- error_report("gic-version=host requires KVM");
57
+ uint8_t sregion;
81
- exit(1);
58
+ bool srvalid;
82
- } else {
59
+ uint8_t iregion;
83
- /* "max": currently means 3 for TCG */
60
+ bool irvalid;
84
- vms->gic_version = VIRT_GIC_VERSION_3;
61
+} V8M_SAttributes;
85
- }
62
+
86
- } else {
63
+void v8m_security_lookup(CPUARMState *env, uint32_t address,
87
- vms->gic_version = kvm_arm_vgic_probe();
64
+ MMUAccessType access_type, ARMMMUIdx mmu_idx,
88
- if (!vms->gic_version) {
65
+ V8M_SAttributes *sattrs);
89
- error_report(
66
+
90
- "Unable to determine GIC version supported by host");
67
+bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address,
91
- exit(1);
68
+ MMUAccessType access_type, ARMMMUIdx mmu_idx,
92
- }
69
+ hwaddr *phys_ptr, MemTxAttrs *txattrs,
93
- }
70
+ int *prot, bool *is_subpage,
71
+ ARMMMUFaultInfo *fi, uint32_t *mregion);
72
+
73
/* Cacheability and shareability attributes for a memory access */
74
typedef struct ARMCacheAttrs {
75
unsigned int attrs:8; /* as in the MAIR register encoding */
76
diff --git a/target/arm/helper.c b/target/arm/helper.c
77
index XXXXXXX..XXXXXXX 100644
78
--- a/target/arm/helper.c
79
+++ b/target/arm/helper.c
80
@@ -XXX,XX +XXX,XX @@ static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address,
81
hwaddr *phys_ptr, MemTxAttrs *txattrs, int *prot,
82
target_ulong *page_size_ptr,
83
ARMMMUFaultInfo *fi, ARMCacheAttrs *cacheattrs);
84
-
85
-/* Security attributes for an address, as returned by v8m_security_lookup. */
86
-typedef struct V8M_SAttributes {
87
- bool subpage; /* true if these attrs don't cover the whole TARGET_PAGE */
88
- bool ns;
89
- bool nsc;
90
- uint8_t sregion;
91
- bool srvalid;
92
- uint8_t iregion;
93
- bool irvalid;
94
-} V8M_SAttributes;
95
-
96
-static void v8m_security_lookup(CPUARMState *env, uint32_t address,
97
- MMUAccessType access_type, ARMMMUIdx mmu_idx,
98
- V8M_SAttributes *sattrs);
99
#endif
100
101
static void switch_mode(CPUARMState *env, int mode);
102
@@ -XXX,XX +XXX,XX @@ void arm_log_exception(int idx)
103
}
104
}
105
106
-/*
107
- * Return true if the v7M CPACR permits access to the FPU for the specified
108
- * security state and privilege level.
109
- */
110
-static bool v7m_cpacr_pass(CPUARMState *env, bool is_secure, bool is_priv)
111
-{
112
- switch (extract32(env->v7m.cpacr[is_secure], 20, 2)) {
113
- case 0:
114
- case 2: /* UNPREDICTABLE: we treat like 0 */
115
- return false;
116
- case 1:
117
- return is_priv;
118
- case 3:
119
- return true;
120
- default:
121
- g_assert_not_reached();
122
- }
94
- }
123
-}
95
+ finalize_gic_version(vms);
124
-
96
125
/*
97
if (!cpu_type_valid(machine->cpu_type)) {
126
* What kind of stack write are we doing? This affects how exceptions
98
error_report("mach-virt: CPU type %s not supported", machine->cpu_type);
127
* generated during the stacking are treated.
99
@@ -XXX,XX +XXX,XX @@ static void virt_instance_init(Object *obj)
128
@@ -XXX,XX +XXX,XX @@ static bool v8m_is_sau_exempt(CPUARMState *env,
100
"Set on/off to enable/disable using "
129
(address >= 0xe00ff000 && address <= 0xe00fffff);
101
"physical address space above 32 bits",
130
}
102
NULL);
131
103
- /* Default GIC type is v2 */
132
-static void v8m_security_lookup(CPUARMState *env, uint32_t address,
104
- vms->gic_version = VIRT_GIC_VERSION_2;
133
+void v8m_security_lookup(CPUARMState *env, uint32_t address,
105
+ vms->gic_version = VIRT_GIC_VERSION_NOSEL;
134
MMUAccessType access_type, ARMMMUIdx mmu_idx,
106
object_property_add_str(obj, "gic-version", virt_get_gic_version,
135
V8M_SAttributes *sattrs)
107
virt_set_gic_version, NULL);
136
{
108
object_property_set_description(obj, "gic-version",
137
@@ -XXX,XX +XXX,XX @@ static void v8m_security_lookup(CPUARMState *env, uint32_t address,
138
}
139
}
140
141
-static bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address,
142
+bool pmsav8_mpu_lookup(CPUARMState *env, uint32_t address,
143
MMUAccessType access_type, ARMMMUIdx mmu_idx,
144
hwaddr *phys_ptr, MemTxAttrs *txattrs,
145
int *prot, bool *is_subpage,
146
--
109
--
147
2.20.1
110
2.20.1
148
111
149
112
diff view generated by jsdifflib
1
From: Adriana Kobylak <anoo@us.ibm.com>
1
From: Eric Auger <eric.auger@redhat.com>
2
2
3
The Swift board is an OpenPOWER system hosting POWER processors.
3
Convert kvm_arm_vgic_probe() so that it returns a
4
Add support for their BMC including the I2C devices as found on HW.
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.
5
9
6
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
10
Signed-off-by: Eric Auger <eric.auger@redhat.com>
7
Reviewed-by: Cédric Le Goater <clg@kaod.org>
11
Reviewed-by: Andrew Jones <drjones@redhat.com>
8
Reviewed-by: Joel Stanley <joel@jms.id.au>
12
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Message-id: 20190618165311.27066-20-clg@kaod.org
13
Message-id: 20200311131618.7187-5-eric.auger@redhat.com
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
15
---
12
hw/arm/aspeed.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++
16
target/arm/kvm_arm.h | 3 +++
13
1 file changed, 50 insertions(+)
17
hw/arm/virt.c | 11 +++++++++--
18
target/arm/kvm.c | 14 ++++++++------
19
3 files changed, 20 insertions(+), 8 deletions(-)
14
20
15
diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c
21
diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h
16
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
17
--- a/hw/arm/aspeed.c
23
--- a/target/arm/kvm_arm.h
18
+++ b/hw/arm/aspeed.c
24
+++ b/target/arm/kvm_arm.h
19
@@ -XXX,XX +XXX,XX @@ struct AspeedBoardState {
25
@@ -XXX,XX +XXX,XX @@
20
SCU_AST2500_HW_STRAP_ACPI_ENABLE | \
26
#include "exec/memory.h"
21
SCU_HW_STRAP_SPI_MODE(SCU_HW_STRAP_SPI_MASTER))
27
#include "qemu/error-report.h"
22
28
23
+/* Swift hardware value: 0xF11AD206 */
29
+#define KVM_ARM_VGIC_V2 (1 << 0)
24
+#define SWIFT_BMC_HW_STRAP1 ( \
30
+#define KVM_ARM_VGIC_V3 (1 << 1)
25
+ AST2500_HW_STRAP1_DEFAULTS | \
26
+ SCU_AST2500_HW_STRAP_SPI_AUTOFETCH_ENABLE | \
27
+ SCU_AST2500_HW_STRAP_GPIO_STRAP_ENABLE | \
28
+ SCU_AST2500_HW_STRAP_UART_DEBUG | \
29
+ SCU_AST2500_HW_STRAP_DDR4_ENABLE | \
30
+ SCU_H_PLL_BYPASS_EN | \
31
+ SCU_AST2500_HW_STRAP_ACPI_ENABLE | \
32
+ SCU_HW_STRAP_SPI_MODE(SCU_HW_STRAP_SPI_MASTER))
33
+
31
+
34
/* Witherspoon hardware value: 0xF10AD216 (but use romulus definition) */
32
/**
35
#define WITHERSPOON_BMC_HW_STRAP1 ROMULUS_BMC_HW_STRAP1
33
* kvm_arm_vcpu_init:
36
34
* @cs: CPUState
37
@@ -XXX,XX +XXX,XX @@ static void romulus_bmc_i2c_init(AspeedBoardState *bmc)
35
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
38
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), "ds1338", 0x32);
36
index XXXXXXX..XXXXXXX 100644
37
--- a/hw/arm/virt.c
38
+++ b/hw/arm/virt.c
39
@@ -XXX,XX +XXX,XX @@ static void finalize_gic_version(VirtMachineState *vms)
40
vms->gic_version = VIRT_GIC_VERSION_3;
41
}
42
} else {
43
- vms->gic_version = kvm_arm_vgic_probe();
44
- if (!vms->gic_version) {
45
+ int probe_bitmap = kvm_arm_vgic_probe();
46
+
47
+ if (!probe_bitmap) {
48
error_report(
49
"Unable to determine GIC version supported by host");
50
exit(1);
51
+ } else {
52
+ if (probe_bitmap & KVM_ARM_VGIC_V3) {
53
+ vms->gic_version = VIRT_GIC_VERSION_3;
54
+ } else {
55
+ vms->gic_version = VIRT_GIC_VERSION_2;
56
+ }
57
}
58
}
59
} else if (vms->gic_version == VIRT_GIC_VERSION_NOSEL) {
60
diff --git a/target/arm/kvm.c b/target/arm/kvm.c
61
index XXXXXXX..XXXXXXX 100644
62
--- a/target/arm/kvm.c
63
+++ b/target/arm/kvm.c
64
@@ -XXX,XX +XXX,XX @@ int kvm_arch_irqchip_create(KVMState *s)
65
66
int kvm_arm_vgic_probe(void)
67
{
68
+ int val = 0;
69
+
70
if (kvm_create_device(kvm_state,
71
KVM_DEV_TYPE_ARM_VGIC_V3, true) == 0) {
72
- return 3;
73
- } else if (kvm_create_device(kvm_state,
74
- KVM_DEV_TYPE_ARM_VGIC_V2, true) == 0) {
75
- return 2;
76
- } else {
77
- return 0;
78
+ val |= KVM_ARM_VGIC_V3;
79
}
80
+ if (kvm_create_device(kvm_state,
81
+ KVM_DEV_TYPE_ARM_VGIC_V2, true) == 0) {
82
+ val |= KVM_ARM_VGIC_V2;
83
+ }
84
+ return val;
39
}
85
}
40
86
41
+static void swift_bmc_i2c_init(AspeedBoardState *bmc)
87
int kvm_arm_set_irq(int cpu, int irqtype, int irq, int level)
42
+{
43
+ AspeedSoCState *soc = &bmc->soc;
44
+
45
+ i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 3), "pca9552", 0x60);
46
+
47
+ /* The swift board expects a TMP275 but a TMP105 is compatible */
48
+ i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 7), "tmp105", 0x48);
49
+ /* The swift board expects a pca9551 but a pca9552 is compatible */
50
+ i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 7), "pca9552", 0x60);
51
+
52
+ /* The swift board expects an Epson RX8900 RTC but a ds1338 is compatible */
53
+ i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 8), "ds1338", 0x32);
54
+ i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 8), "pca9552", 0x60);
55
+
56
+ i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 9), "tmp423", 0x4c);
57
+ /* The swift board expects a pca9539 but a pca9552 is compatible */
58
+ i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 9), "pca9552", 0x74);
59
+
60
+ i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 10), "tmp423", 0x4c);
61
+ /* The swift board expects a pca9539 but a pca9552 is compatible */
62
+ i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 10), "pca9552",
63
+ 0x74);
64
+
65
+ /* The swift board expects a TMP275 but a TMP105 is compatible */
66
+ i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 12), "tmp105", 0x48);
67
+ i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 12), "tmp105", 0x4a);
68
+}
69
+
70
static void witherspoon_bmc_i2c_init(AspeedBoardState *bmc)
71
{
72
AspeedSoCState *soc = &bmc->soc;
73
@@ -XXX,XX +XXX,XX @@ static const AspeedBoardConfig aspeed_boards[] = {
74
.num_cs = 2,
75
.i2c_init = romulus_bmc_i2c_init,
76
.ram = 512 * MiB,
77
+ }, {
78
+ .name = MACHINE_TYPE_NAME("swift-bmc"),
79
+ .desc = "OpenPOWER Swift BMC (ARM1176)",
80
+ .soc_name = "ast2500-a1",
81
+ .hw_strap1 = SWIFT_BMC_HW_STRAP1,
82
+ .fmc_model = "mx66l1g45g",
83
+ .spi_model = "mx66l1g45g",
84
+ .num_cs = 2,
85
+ .i2c_init = swift_bmc_i2c_init,
86
+ .ram = 512 * MiB,
87
}, {
88
.name = MACHINE_TYPE_NAME("witherspoon-bmc"),
89
.desc = "OpenPOWER Witherspoon BMC (ARM1176)",
90
--
88
--
91
2.20.1
89
2.20.1
92
90
93
91
diff view generated by jsdifflib
1
From: Andrey Smirnov <andrew.smirnov@gmail.com>
1
From: Eric Auger <eric.auger@redhat.com>
2
2
3
Datasheet for i.MX7 is incorrect and i.MX7's PCI IRQ mapping matches
3
Restructure the finalize_gic_version with switch cases and
4
that of i.MX6:
4
clearly separate the following cases:
5
5
6
* INTD/MSI 122
6
- KVM mode / in-kernel irqchip
7
* INTC 123
7
- KVM mode / userspace irqchip
8
* INTB 124
8
- TCG mode
9
* INTA 125
10
9
11
Fix all of the relevant code to reflect that fact. Needed by latest
10
In KVM mode / in-kernel irqchip , we explictly check whether
12
Linux kernels.
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.
13
17
14
(Reference: Linux kernel commit 538d6e9d597584e80 from an
18
In KVM mode / userspace irqchip we immediatly output an error
15
NXP employee confirming that the datasheet is incorrect and
19
in case the end-user explicitly selected v3. Also we warn the
16
with a report of a test against hardware.)
20
end-user about the unexpected usage of gic-version=host in
21
that case as only userspace GICv2 is supported.
17
22
18
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
23
Signed-off-by: Eric Auger <eric.auger@redhat.com>
19
Cc: Peter Maydell <peter.maydell@linaro.org>
24
Reviewed-by: Andrew Jones <drjones@redhat.com>
20
Cc: Michael S. Tsirkin <mst@redhat.com>
25
Message-id: 20200311131618.7187-6-eric.auger@redhat.com
21
Cc: qemu-devel@nongnu.org
22
Cc: qemu-arm@nongnu.org
23
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
24
[PMM: added ref to kernel commit confirming the datasheet error]
25
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
26
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
26
---
27
---
27
include/hw/arm/fsl-imx7.h | 8 ++++----
28
hw/arm/virt.c | 88 +++++++++++++++++++++++++++++++++++++++------------
28
hw/pci-host/designware.c | 6 ++++--
29
1 file changed, 67 insertions(+), 21 deletions(-)
29
2 files changed, 8 insertions(+), 6 deletions(-)
30
30
31
diff --git a/include/hw/arm/fsl-imx7.h b/include/hw/arm/fsl-imx7.h
31
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
32
index XXXXXXX..XXXXXXX 100644
32
index XXXXXXX..XXXXXXX 100644
33
--- a/include/hw/arm/fsl-imx7.h
33
--- a/hw/arm/virt.c
34
+++ b/include/hw/arm/fsl-imx7.h
34
+++ b/hw/arm/virt.c
35
@@ -XXX,XX +XXX,XX @@ enum FslIMX7IRQs {
35
@@ -XXX,XX +XXX,XX @@ static void virt_set_memmap(VirtMachineState *vms)
36
FSL_IMX7_USB2_IRQ = 42,
36
*/
37
FSL_IMX7_USB3_IRQ = 40,
37
static void finalize_gic_version(VirtMachineState *vms)
38
38
{
39
- FSL_IMX7_PCI_INTA_IRQ = 122,
39
- if (vms->gic_version == VIRT_GIC_VERSION_HOST ||
40
- FSL_IMX7_PCI_INTB_IRQ = 123,
40
- vms->gic_version == VIRT_GIC_VERSION_MAX) {
41
- FSL_IMX7_PCI_INTC_IRQ = 124,
41
- if (!kvm_enabled()) {
42
- FSL_IMX7_PCI_INTD_IRQ = 125,
42
- if (vms->gic_version == VIRT_GIC_VERSION_HOST) {
43
+ FSL_IMX7_PCI_INTA_IRQ = 125,
43
- error_report("gic-version=host requires KVM");
44
+ FSL_IMX7_PCI_INTB_IRQ = 124,
44
- exit(1);
45
+ FSL_IMX7_PCI_INTC_IRQ = 123,
45
- } else {
46
+ FSL_IMX7_PCI_INTD_IRQ = 122,
46
- /* "max": currently means 3 for TCG */
47
47
- vms->gic_version = VIRT_GIC_VERSION_3;
48
FSL_IMX7_UART7_IRQ = 126,
48
- }
49
49
- } else {
50
diff --git a/hw/pci-host/designware.c b/hw/pci-host/designware.c
50
- int probe_bitmap = kvm_arm_vgic_probe();
51
index XXXXXXX..XXXXXXX 100644
51
+ if (kvm_enabled()) {
52
--- a/hw/pci-host/designware.c
52
+ int probe_bitmap;
53
+++ b/hw/pci-host/designware.c
53
54
@@ -XXX,XX +XXX,XX @@
54
- if (!probe_bitmap) {
55
#define DESIGNWARE_PCIE_ATU_DEVFN(x) (((x) >> 16) & 0xff)
55
+ if (!kvm_irqchip_in_kernel()) {
56
#define DESIGNWARE_PCIE_ATU_UPPER_TARGET 0x91C
56
+ switch (vms->gic_version) {
57
57
+ case VIRT_GIC_VERSION_HOST:
58
+#define DESIGNWARE_PCIE_IRQ_MSI 3
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) {
59
+
82
+
60
static DesignwarePCIEHost *
83
+ probe_bitmap = kvm_arm_vgic_probe();
61
designware_pcie_root_to_host(DesignwarePCIERoot *root)
84
+ if (!probe_bitmap) {
62
{
85
+ error_report("Unable to determine GIC version supported by host");
63
@@ -XXX,XX +XXX,XX @@ static void designware_pcie_root_msi_write(void *opaque, hwaddr addr,
86
+ exit(1);
64
root->msi.intr[0].status |= BIT(val) & root->msi.intr[0].enable;
87
+ }
65
88
+
66
if (root->msi.intr[0].status & ~root->msi.intr[0].mask) {
89
+ switch (vms->gic_version) {
67
- qemu_set_irq(host->pci.irqs[0], 1);
90
+ case VIRT_GIC_VERSION_HOST:
68
+ qemu_set_irq(host->pci.irqs[DESIGNWARE_PCIE_IRQ_MSI], 1);
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;
117
+ }
118
+
119
+ /* TCG mode */
120
+ switch (vms->gic_version) {
121
+ case VIRT_GIC_VERSION_NOSEL:
122
vms->gic_version = VIRT_GIC_VERSION_2;
123
+ break;
124
+ case VIRT_GIC_VERSION_MAX:
125
+ vms->gic_version = VIRT_GIC_VERSION_3;
126
+ break;
127
+ case VIRT_GIC_VERSION_HOST:
128
+ error_report("gic-version=host requires KVM");
129
+ exit(1);
130
+ case VIRT_GIC_VERSION_2:
131
+ case VIRT_GIC_VERSION_3:
132
+ break;
69
}
133
}
70
}
134
}
71
72
@@ -XXX,XX +XXX,XX @@ static void designware_pcie_root_config_write(PCIDevice *d, uint32_t address,
73
case DESIGNWARE_PCIE_MSI_INTR0_STATUS:
74
root->msi.intr[0].status ^= val;
75
if (!root->msi.intr[0].status) {
76
- qemu_set_irq(host->pci.irqs[0], 0);
77
+ qemu_set_irq(host->pci.irqs[DESIGNWARE_PCIE_IRQ_MSI], 0);
78
}
79
break;
80
135
81
--
136
--
82
2.20.1
137
2.20.1
83
138
84
139
diff view generated by jsdifflib
1
From: Jan Kiszka <jan.kiszka@siemens.com>
1
From: Eric Auger <eric.auger@redhat.com>
2
2
3
Allow cortex-a7 to be used with the virt board; it supports
3
At the moment if the end-user does not specify the gic-version along
4
the v7VE features and there is no reason to deny this type.
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.
5
7
6
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
8
This patch keeps the default v2 selection in all cases except
7
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
9
in the KVM accelerated mode when either
8
Message-id: fc5404f7-4d1d-c28f-6e48-d8799c82acc0@web.de
10
- the host does not support GICv2 in-kernel emulation or
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
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
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
20
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
21
---
12
hw/arm/virt.c | 1 +
22
hw/arm/virt.c | 17 ++++++++++++++++-
13
1 file changed, 1 insertion(+)
23
1 file changed, 16 insertions(+), 1 deletion(-)
14
24
15
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
25
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
16
index XXXXXXX..XXXXXXX 100644
26
index XXXXXXX..XXXXXXX 100644
17
--- a/hw/arm/virt.c
27
--- a/hw/arm/virt.c
18
+++ b/hw/arm/virt.c
28
+++ b/hw/arm/virt.c
19
@@ -XXX,XX +XXX,XX @@ static const int a15irqmap[] = {
29
@@ -XXX,XX +XXX,XX @@ static void virt_set_memmap(VirtMachineState *vms)
20
};
30
*/
21
31
static void finalize_gic_version(VirtMachineState *vms)
22
static const char *valid_cpus[] = {
32
{
23
+ ARM_CPU_TYPE_NAME("cortex-a7"),
33
+ unsigned int max_cpus = MACHINE(vms)->smp.max_cpus;
24
ARM_CPU_TYPE_NAME("cortex-a15"),
34
+
25
ARM_CPU_TYPE_NAME("cortex-a53"),
35
if (kvm_enabled()) {
26
ARM_CPU_TYPE_NAME("cortex-a57"),
36
int probe_bitmap;
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:
27
--
60
--
28
2.20.1
61
2.20.1
29
62
30
63
diff view generated by jsdifflib
Deleted patch
1
From: Andrey Smirnov <andrew.smirnov@gmail.com>
2
1
3
Add no-op/unimplemented PCIE PHY IP block. Needed by new kernels to
4
use PCIE.
5
6
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
7
Cc: Peter Maydell <peter.maydell@linaro.org>
8
Cc: Michael S. Tsirkin <mst@redhat.com>
9
Cc: qemu-devel@nongnu.org
10
Cc: qemu-arm@nongnu.org
11
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
---
14
include/hw/arm/fsl-imx7.h | 3 +++
15
hw/arm/fsl-imx7.c | 5 +++++
16
2 files changed, 8 insertions(+)
17
18
diff --git a/include/hw/arm/fsl-imx7.h b/include/hw/arm/fsl-imx7.h
19
index XXXXXXX..XXXXXXX 100644
20
--- a/include/hw/arm/fsl-imx7.h
21
+++ b/include/hw/arm/fsl-imx7.h
22
@@ -XXX,XX +XXX,XX @@ enum FslIMX7MemoryMap {
23
FSL_IMX7_ADC2_ADDR = 0x30620000,
24
FSL_IMX7_ADCn_SIZE = 0x1000,
25
26
+ FSL_IMX7_PCIE_PHY_ADDR = 0x306D0000,
27
+ FSL_IMX7_PCIE_PHY_SIZE = 0x10000,
28
+
29
FSL_IMX7_GPC_ADDR = 0x303A0000,
30
31
FSL_IMX7_I2C1_ADDR = 0x30A20000,
32
diff --git a/hw/arm/fsl-imx7.c b/hw/arm/fsl-imx7.c
33
index XXXXXXX..XXXXXXX 100644
34
--- a/hw/arm/fsl-imx7.c
35
+++ b/hw/arm/fsl-imx7.c
36
@@ -XXX,XX +XXX,XX @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp)
37
*/
38
create_unimplemented_device("dma-apbh", FSL_IMX7_DMA_APBH_ADDR,
39
FSL_IMX7_DMA_APBH_SIZE);
40
+ /*
41
+ * PCIe PHY
42
+ */
43
+ create_unimplemented_device("pcie-phy", FSL_IMX7_PCIE_PHY_ADDR,
44
+ FSL_IMX7_PCIE_PHY_SIZE);
45
}
46
47
static void fsl_imx7_class_init(ObjectClass *oc, void *data)
48
--
49
2.20.1
50
51
diff view generated by jsdifflib
Deleted patch
1
From: Andrey Smirnov <andrew.smirnov@gmail.com>
2
1
3
Expression to calculate update_msi_mapping in code handling writes to
4
DESIGNWARE_PCIE_MSI_INTR0_ENABLE is missing an ! operator and should
5
be:
6
7
!!root->msi.intr[0].enable ^ !!val;
8
9
so that MSI mapping is updated when enabled transitions from either
10
"none" -> "any" or "any" -> "none". Since that register shouldn't be
11
written to very often, change the code to update MSI mapping
12
unconditionally instead of trying to fix the update_msi_mapping logic.
13
14
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
15
Cc: Peter Maydell <peter.maydell@linaro.org>
16
Cc: Michael S. Tsirkin <mst@redhat.com>
17
Cc: qemu-devel@nongnu.org
18
Cc: qemu-arm@nongnu.org
19
Acked-by: Michael S. Tsirkin <mst@redhat.com>
20
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
21
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
22
---
23
hw/pci-host/designware.c | 10 ++--------
24
1 file changed, 2 insertions(+), 8 deletions(-)
25
26
diff --git a/hw/pci-host/designware.c b/hw/pci-host/designware.c
27
index XXXXXXX..XXXXXXX 100644
28
--- a/hw/pci-host/designware.c
29
+++ b/hw/pci-host/designware.c
30
@@ -XXX,XX +XXX,XX @@ static void designware_pcie_root_config_write(PCIDevice *d, uint32_t address,
31
root->msi.base |= (uint64_t)val << 32;
32
break;
33
34
- case DESIGNWARE_PCIE_MSI_INTR0_ENABLE: {
35
- const bool update_msi_mapping = !root->msi.intr[0].enable ^ !!val;
36
-
37
+ case DESIGNWARE_PCIE_MSI_INTR0_ENABLE:
38
root->msi.intr[0].enable = val;
39
-
40
- if (update_msi_mapping) {
41
- designware_pcie_root_update_msi_mapping(root);
42
- }
43
+ designware_pcie_root_update_msi_mapping(root);
44
break;
45
- }
46
47
case DESIGNWARE_PCIE_MSI_INTR0_MASK:
48
root->msi.intr[0].mask = val;
49
--
50
2.20.1
51
52
diff view generated by jsdifflib
Deleted patch
1
From: Andrey Smirnov <andrew.smirnov@gmail.com>
2
1
3
MSI mapping needs to be update when MSI address changes, so add the
4
code to do so.
5
6
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
7
Cc: Peter Maydell <peter.maydell@linaro.org>
8
Cc: Michael S. Tsirkin <mst@redhat.com>
9
Cc: qemu-devel@nongnu.org
10
Cc: qemu-arm@nongnu.org
11
Acked-by: Michael S. Tsirkin <mst@redhat.com>
12
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
---
15
hw/pci-host/designware.c | 2 ++
16
1 file changed, 2 insertions(+)
17
18
diff --git a/hw/pci-host/designware.c b/hw/pci-host/designware.c
19
index XXXXXXX..XXXXXXX 100644
20
--- a/hw/pci-host/designware.c
21
+++ b/hw/pci-host/designware.c
22
@@ -XXX,XX +XXX,XX @@ static void designware_pcie_root_config_write(PCIDevice *d, uint32_t address,
23
case DESIGNWARE_PCIE_MSI_ADDR_LO:
24
root->msi.base &= 0xFFFFFFFF00000000ULL;
25
root->msi.base |= val;
26
+ designware_pcie_root_update_msi_mapping(root);
27
break;
28
29
case DESIGNWARE_PCIE_MSI_ADDR_HI:
30
root->msi.base &= 0x00000000FFFFFFFFULL;
31
root->msi.base |= (uint64_t)val << 32;
32
+ designware_pcie_root_update_msi_mapping(root);
33
break;
34
35
case DESIGNWARE_PCIE_MSI_INTR0_ENABLE:
36
--
37
2.20.1
38
39
diff view generated by jsdifflib
Deleted patch
1
From: Joel Stanley <joel@jms.id.au>
2
1
3
All systems have an RTC.
4
5
The IRQ is hooked up but the model does not use it at this stage. There
6
is no guest code that uses it, so this limitation is acceptable.
7
8
Signed-off-by: Joel Stanley <joel@jms.id.au>
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
10
Message-id: 20190618165311.27066-5-clg@kaod.org
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
13
include/hw/arm/aspeed_soc.h | 2 ++
14
hw/arm/aspeed_soc.c | 13 +++++++++++++
15
2 files changed, 15 insertions(+)
16
17
diff --git a/include/hw/arm/aspeed_soc.h b/include/hw/arm/aspeed_soc.h
18
index XXXXXXX..XXXXXXX 100644
19
--- a/include/hw/arm/aspeed_soc.h
20
+++ b/include/hw/arm/aspeed_soc.h
21
@@ -XXX,XX +XXX,XX @@
22
#include "hw/misc/aspeed_scu.h"
23
#include "hw/misc/aspeed_sdmc.h"
24
#include "hw/timer/aspeed_timer.h"
25
+#include "hw/timer/aspeed_rtc.h"
26
#include "hw/i2c/aspeed_i2c.h"
27
#include "hw/ssi/aspeed_smc.h"
28
#include "hw/watchdog/wdt_aspeed.h"
29
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedSoCState {
30
ARMCPU cpu;
31
MemoryRegion sram;
32
AspeedVICState vic;
33
+ AspeedRtcState rtc;
34
AspeedTimerCtrlState timerctrl;
35
AspeedI2CState i2c;
36
AspeedSCUState scu;
37
diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c
38
index XXXXXXX..XXXXXXX 100644
39
--- a/hw/arm/aspeed_soc.c
40
+++ b/hw/arm/aspeed_soc.c
41
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_init(Object *obj)
42
sysbus_init_child_obj(obj, "vic", OBJECT(&s->vic), sizeof(s->vic),
43
TYPE_ASPEED_VIC);
44
45
+ sysbus_init_child_obj(obj, "rtc", OBJECT(&s->rtc), sizeof(s->rtc),
46
+ TYPE_ASPEED_RTC);
47
+
48
sysbus_init_child_obj(obj, "timerctrl", OBJECT(&s->timerctrl),
49
sizeof(s->timerctrl), TYPE_ASPEED_TIMER);
50
object_property_add_const_link(OBJECT(&s->timerctrl), "scu",
51
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
52
sysbus_connect_irq(SYS_BUS_DEVICE(&s->vic), 1,
53
qdev_get_gpio_in(DEVICE(&s->cpu), ARM_CPU_FIQ));
54
55
+ /* RTC */
56
+ object_property_set_bool(OBJECT(&s->rtc), true, "realized", &err);
57
+ if (err) {
58
+ error_propagate(errp, err);
59
+ return;
60
+ }
61
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->rtc), 0, sc->info->memmap[ASPEED_RTC]);
62
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->rtc), 0,
63
+ aspeed_soc_get_irq(s, ASPEED_RTC));
64
+
65
/* Timer */
66
object_property_set_bool(OBJECT(&s->timerctrl), true, "realized", &err);
67
if (err) {
68
--
69
2.20.1
70
71
diff view generated by jsdifflib
Deleted patch
1
From: Andrew Jeffery <andrew@aj.id.au>
2
1
3
From the datasheet:
4
5
This register stores the current status of counter #N. When timer
6
enable bit TMC30[N * b] is disabled, the reload register will be
7
loaded into this counter. When timer bit TMC30[N * b] is set, the
8
counter will start to decrement. CPU can update this register value
9
when enable bit is set.
10
11
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
12
Signed-off-by: Cédric Le Goater <clg@kaod.org>
13
Reviewed-by: Joel Stanley <joel@jms.id.au>
14
Message-id: 20190618165311.27066-9-clg@kaod.org
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
---
17
hw/timer/aspeed_timer.c | 6 +++++-
18
1 file changed, 5 insertions(+), 1 deletion(-)
19
20
diff --git a/hw/timer/aspeed_timer.c b/hw/timer/aspeed_timer.c
21
index XXXXXXX..XXXXXXX 100644
22
--- a/hw/timer/aspeed_timer.c
23
+++ b/hw/timer/aspeed_timer.c
24
@@ -XXX,XX +XXX,XX @@ static uint64_t aspeed_timer_get_value(AspeedTimer *t, int reg)
25
26
switch (reg) {
27
case TIMER_REG_STATUS:
28
- value = calculate_ticks(t, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
29
+ if (timer_enabled(t)) {
30
+ value = calculate_ticks(t, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
31
+ } else {
32
+ value = t->reload;
33
+ }
34
break;
35
case TIMER_REG_RELOAD:
36
value = t->reload;
37
--
38
2.20.1
39
40
diff view generated by jsdifflib
Deleted patch
1
From: Christian Svensson <bluecmd@google.com>
2
1
3
If the host decrements the counter register that results in a negative
4
delta. This is then passed to muldiv64 which only handles unsigned
5
numbers resulting in bogus results.
6
7
This fix ensures the delta being operated on is positive.
8
9
Test case: kexec a kernel using aspeed_timer and it will freeze on the
10
second bootup when the kernel initializes the timer. With this patch
11
that no longer happens and the timer appears to run OK.
12
13
Signed-off-by: Christian Svensson <bluecmd@google.com>
14
Signed-off-by: Cédric Le Goater <clg@kaod.org>
15
Reviewed-by: Joel Stanley <joel@jms.id.au>
16
Reviewed-by: Andrew Jeffery <andrew@aj.id.au>
17
Message-id: 20190618165311.27066-12-clg@kaod.org
18
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
19
---
20
hw/timer/aspeed_timer.c | 6 +++++-
21
1 file changed, 5 insertions(+), 1 deletion(-)
22
23
diff --git a/hw/timer/aspeed_timer.c b/hw/timer/aspeed_timer.c
24
index XXXXXXX..XXXXXXX 100644
25
--- a/hw/timer/aspeed_timer.c
26
+++ b/hw/timer/aspeed_timer.c
27
@@ -XXX,XX +XXX,XX @@ static void aspeed_timer_set_value(AspeedTimerCtrlState *s, int timer, int reg,
28
int64_t delta = (int64_t) value - (int64_t) calculate_ticks(t, now);
29
uint32_t rate = calculate_rate(t);
30
31
- t->start += muldiv64(delta, NANOSECONDS_PER_SECOND, rate);
32
+ if (delta >= 0) {
33
+ t->start += muldiv64(delta, NANOSECONDS_PER_SECOND, rate);
34
+ } else {
35
+ t->start -= muldiv64(-delta, NANOSECONDS_PER_SECOND, rate);
36
+ }
37
aspeed_timer_mod(t);
38
}
39
break;
40
--
41
2.20.1
42
43
diff view generated by jsdifflib
Deleted patch
1
From: Cédric Le Goater <clg@kaod.org>
2
1
3
It has never been used as far as I can tell from the git history.
4
5
Signed-off-by: Cédric Le Goater <clg@kaod.org>
6
Reviewed-by: Joel Stanley <joel@jms.id.au>
7
Message-id: 20190618165311.27066-13-clg@kaod.org
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
10
hw/arm/aspeed.c | 2 --
11
1 file changed, 2 deletions(-)
12
13
diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c
14
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/arm/aspeed.c
16
+++ b/hw/arm/aspeed.c
17
@@ -XXX,XX +XXX,XX @@ static void aspeed_board_init(MachineState *machine,
18
memory_region_allocate_system_memory(&bmc->ram, NULL, "ram", ram_size);
19
memory_region_add_subregion(get_system_memory(),
20
sc->info->memmap[ASPEED_SDRAM], &bmc->ram);
21
- object_property_add_const_link(OBJECT(&bmc->soc), "ram", OBJECT(&bmc->ram),
22
- &error_abort);
23
24
max_ram_size = object_property_get_uint(OBJECT(&bmc->soc), "max-ram-size",
25
&error_abort);
26
--
27
2.20.1
28
29
diff view generated by jsdifflib
Deleted patch
1
From: Cédric Le Goater <clg@kaod.org>
2
1
3
The RAM memory region is defined after the SoC is realized when the
4
SDMC controller has checked that the defined RAM size for the machine
5
is correct. This is problematic for controller models requiring a link
6
on the RAM region, for DMA support in the SMC controller for instance.
7
8
Introduce a container memory region for the RAM that we can link into
9
the controllers early, before the SoC is realized. It will be
10
populated with the RAM region after the checks have be done.
11
12
Signed-off-by: Cédric Le Goater <clg@kaod.org>
13
Reviewed-by: Joel Stanley <joel@jms.id.au>
14
Message-id: 20190618165311.27066-14-clg@kaod.org
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
---
17
hw/arm/aspeed.c | 13 +++++++++----
18
1 file changed, 9 insertions(+), 4 deletions(-)
19
20
diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c
21
index XXXXXXX..XXXXXXX 100644
22
--- a/hw/arm/aspeed.c
23
+++ b/hw/arm/aspeed.c
24
@@ -XXX,XX +XXX,XX @@ static struct arm_boot_info aspeed_board_binfo = {
25
26
struct AspeedBoardState {
27
AspeedSoCState soc;
28
+ MemoryRegion ram_container;
29
MemoryRegion ram;
30
MemoryRegion max_ram;
31
};
32
@@ -XXX,XX +XXX,XX @@ static void aspeed_board_init(MachineState *machine,
33
ram_addr_t max_ram_size;
34
35
bmc = g_new0(AspeedBoardState, 1);
36
+
37
+ memory_region_init(&bmc->ram_container, NULL, "aspeed-ram-container",
38
+ UINT32_MAX);
39
+
40
object_initialize_child(OBJECT(machine), "soc", &bmc->soc,
41
(sizeof(bmc->soc)), cfg->soc_name, &error_abort,
42
NULL);
43
@@ -XXX,XX +XXX,XX @@ static void aspeed_board_init(MachineState *machine,
44
&error_abort);
45
46
memory_region_allocate_system_memory(&bmc->ram, NULL, "ram", ram_size);
47
+ memory_region_add_subregion(&bmc->ram_container, 0, &bmc->ram);
48
memory_region_add_subregion(get_system_memory(),
49
- sc->info->memmap[ASPEED_SDRAM], &bmc->ram);
50
+ sc->info->memmap[ASPEED_SDRAM],
51
+ &bmc->ram_container);
52
53
max_ram_size = object_property_get_uint(OBJECT(&bmc->soc), "max-ram-size",
54
&error_abort);
55
memory_region_init_io(&bmc->max_ram, NULL, &max_ram_ops, NULL,
56
"max_ram", max_ram_size - ram_size);
57
- memory_region_add_subregion(get_system_memory(),
58
- sc->info->memmap[ASPEED_SDRAM] + ram_size,
59
- &bmc->max_ram);
60
+ memory_region_add_subregion(&bmc->ram_container, ram_size, &bmc->max_ram);
61
62
aspeed_board_init_flashes(&bmc->soc.fmc, cfg->fmc_model, &error_abort);
63
aspeed_board_init_flashes(&bmc->soc.spi[0], cfg->spi_model, &error_abort);
64
--
65
2.20.1
66
67
diff view generated by jsdifflib
1
From: Andrew Jeffery <andrew@aj.id.au>
1
From: Beata Michalska <beata.michalska@linaro.org>
2
2
3
The legacy interface only supported up to 32 IRQs, which became
3
KVM_SET_VCPU_EVENTS might actually lead to vcpu registers being modified.
4
restrictive around the AST2400 generation. QEMU support for the SoCs
4
As such this should be the last step of sync to avoid potential overwriting
5
started with the AST2400 along with an effort to reimplement and
5
of whatever changes KVM might have done.
6
upstream drivers for Linux, so up until this point the consumers of the
7
QEMU ASPEED support only required the 64 IRQ register interface.
8
6
9
In an effort to support older BMC firmware, add support for the 32 IRQ
7
Signed-off-by: Beata Michalska <beata.michalska@linaro.org>
10
interface.
8
Reviewed-by: Andrew Jones <drjones@redhat.com>
11
9
Message-id: 20200312003401.29017-2-beata.michalska@linaro.org
12
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
13
Signed-off-by: Cédric Le Goater <clg@kaod.org>
14
Reviewed-by: Joel Stanley <joel@jms.id.au>
15
Message-id: 20190618165311.27066-22-clg@kaod.org
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
---
11
---
18
hw/intc/aspeed_vic.c | 105 ++++++++++++++++++++++++++-----------------
12
target/arm/kvm32.c | 15 ++++++++++-----
19
1 file changed, 63 insertions(+), 42 deletions(-)
13
target/arm/kvm64.c | 15 ++++++++++-----
14
2 files changed, 20 insertions(+), 10 deletions(-)
20
15
21
diff --git a/hw/intc/aspeed_vic.c b/hw/intc/aspeed_vic.c
16
diff --git a/target/arm/kvm32.c b/target/arm/kvm32.c
22
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
23
--- a/hw/intc/aspeed_vic.c
18
--- a/target/arm/kvm32.c
24
+++ b/hw/intc/aspeed_vic.c
19
+++ b/target/arm/kvm32.c
25
@@ -XXX,XX +XXX,XX @@ static void aspeed_vic_set_irq(void *opaque, int irq, int level)
20
@@ -XXX,XX +XXX,XX @@ int kvm_arch_put_registers(CPUState *cs, int level)
26
21
return ret;
27
static uint64_t aspeed_vic_read(void *opaque, hwaddr offset, unsigned size)
28
{
29
- uint64_t val;
30
- const bool high = !!(offset & 0x4);
31
- hwaddr n_offset = (offset & ~0x4);
32
AspeedVICState *s = (AspeedVICState *)opaque;
33
+ hwaddr n_offset;
34
+ uint64_t val;
35
+ bool high;
36
37
if (offset < AVIC_NEW_BASE_OFFSET) {
38
- qemu_log_mask(LOG_UNIMP, "%s: Ignoring read from legacy registers "
39
- "at 0x%" HWADDR_PRIx "[%u]\n", __func__, offset, size);
40
- return 0;
41
+ high = false;
42
+ n_offset = offset;
43
+ } else {
44
+ high = !!(offset & 0x4);
45
+ n_offset = (offset & ~0x4);
46
}
22
}
47
23
48
- n_offset -= AVIC_NEW_BASE_OFFSET;
24
- ret = kvm_put_vcpu_events(cpu);
25
- if (ret) {
26
- return ret;
27
- }
49
-
28
-
50
switch (n_offset) {
29
write_cpustate_to_list(cpu, true);
51
- case 0x0: /* IRQ Status */
30
52
+ case 0x80: /* IRQ Status */
31
if (!write_list_to_kvmstate(cpu, level)) {
53
+ case 0x00:
32
return EINVAL;
54
val = s->raw & ~s->select & s->enable;
55
break;
56
- case 0x08: /* FIQ Status */
57
+ case 0x88: /* FIQ Status */
58
+ case 0x04:
59
val = s->raw & s->select & s->enable;
60
break;
61
- case 0x10: /* Raw Interrupt Status */
62
+ case 0x90: /* Raw Interrupt Status */
63
+ case 0x08:
64
val = s->raw;
65
break;
66
- case 0x18: /* Interrupt Selection */
67
+ case 0x98: /* Interrupt Selection */
68
+ case 0x0c:
69
val = s->select;
70
break;
71
- case 0x20: /* Interrupt Enable */
72
+ case 0xa0: /* Interrupt Enable */
73
+ case 0x10:
74
val = s->enable;
75
break;
76
- case 0x30: /* Software Interrupt */
77
+ case 0xb0: /* Software Interrupt */
78
+ case 0x18:
79
val = s->trigger;
80
break;
81
- case 0x40: /* Interrupt Sensitivity */
82
+ case 0xc0: /* Interrupt Sensitivity */
83
+ case 0x24:
84
val = s->sense;
85
break;
86
- case 0x48: /* Interrupt Both Edge Trigger Control */
87
+ case 0xc8: /* Interrupt Both Edge Trigger Control */
88
+ case 0x28:
89
val = s->dual_edge;
90
break;
91
- case 0x50: /* Interrupt Event */
92
+ case 0xd0: /* Interrupt Event */
93
+ case 0x2c:
94
val = s->event;
95
break;
96
- case 0x60: /* Edge Triggered Interrupt Status */
97
+ case 0xe0: /* Edge Triggered Interrupt Status */
98
val = s->raw & ~s->sense;
99
break;
100
/* Illegal */
101
- case 0x28: /* Interrupt Enable Clear */
102
- case 0x38: /* Software Interrupt Clear */
103
- case 0x58: /* Edge Triggered Interrupt Clear */
104
+ case 0xa8: /* Interrupt Enable Clear */
105
+ case 0xb8: /* Software Interrupt Clear */
106
+ case 0xd8: /* Edge Triggered Interrupt Clear */
107
qemu_log_mask(LOG_GUEST_ERROR,
108
"%s: Read of write-only register with offset 0x%"
109
HWADDR_PRIx "\n", __func__, offset);
110
@@ -XXX,XX +XXX,XX @@ static uint64_t aspeed_vic_read(void *opaque, hwaddr offset, unsigned size)
111
}
33
}
112
if (high) {
34
113
val = extract64(val, 32, 19);
35
+ /*
114
+ } else {
36
+ * Setting VCPU events should be triggered after syncing the registers
115
+ val = extract64(val, 0, 32);
37
+ * to avoid overwriting potential changes made by KVM upon calling
38
+ * KVM_SET_VCPU_EVENTS ioctl
39
+ */
40
+ ret = kvm_put_vcpu_events(cpu);
41
+ if (ret) {
42
+ return ret;
43
+ }
44
+
45
kvm_arm_sync_mpstate_to_kvm(cpu);
46
47
return ret;
48
diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c
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;
116
}
54
}
117
trace_aspeed_vic_read(offset, size, val);
55
118
return val;
56
- ret = kvm_put_vcpu_events(cpu);
119
@@ -XXX,XX +XXX,XX @@ static uint64_t aspeed_vic_read(void *opaque, hwaddr offset, unsigned size)
57
- if (ret) {
120
static void aspeed_vic_write(void *opaque, hwaddr offset, uint64_t data,
58
- return ret;
121
unsigned size)
59
- }
122
{
60
-
123
- const bool high = !!(offset & 0x4);
61
write_cpustate_to_list(cpu, true);
124
- hwaddr n_offset = (offset & ~0x4);
62
125
AspeedVICState *s = (AspeedVICState *)opaque;
63
if (!write_list_to_kvmstate(cpu, level)) {
126
+ hwaddr n_offset;
64
return -EINVAL;
127
+ bool high;
128
129
if (offset < AVIC_NEW_BASE_OFFSET) {
130
- qemu_log_mask(LOG_UNIMP,
131
- "%s: Ignoring write to legacy registers at 0x%"
132
- HWADDR_PRIx "[%u] <- 0x%" PRIx64 "\n", __func__, offset,
133
- size, data);
134
- return;
135
+ high = false;
136
+ n_offset = offset;
137
+ } else {
138
+ high = !!(offset & 0x4);
139
+ n_offset = (offset & ~0x4);
140
}
65
}
141
66
142
- n_offset -= AVIC_NEW_BASE_OFFSET;
67
+ /*
143
trace_aspeed_vic_write(offset, size, data);
68
+ * Setting VCPU events should be triggered after syncing the registers
144
69
+ * to avoid overwriting potential changes made by KVM upon calling
145
/* Given we have members using separate enable/clear registers, deposit64()
70
+ * KVM_SET_VCPU_EVENTS ioctl
146
@@ -XXX,XX +XXX,XX @@ static void aspeed_vic_write(void *opaque, hwaddr offset, uint64_t data,
71
+ */
147
}
72
+ ret = kvm_put_vcpu_events(cpu);
148
73
+ if (ret) {
149
switch (n_offset) {
74
+ return ret;
150
- case 0x18: /* Interrupt Selection */
75
+ }
151
+ case 0x98: /* Interrupt Selection */
76
+
152
+ case 0x0c:
77
kvm_arm_sync_mpstate_to_kvm(cpu);
153
/* Register has deposit64() semantics - overwrite requested 32 bits */
78
154
if (high) {
79
return ret;
155
s->select &= AVIC_L_MASK;
156
@@ -XXX,XX +XXX,XX @@ static void aspeed_vic_write(void *opaque, hwaddr offset, uint64_t data,
157
}
158
s->select |= data;
159
break;
160
- case 0x20: /* Interrupt Enable */
161
+ case 0xa0: /* Interrupt Enable */
162
+ case 0x10:
163
s->enable |= data;
164
break;
165
- case 0x28: /* Interrupt Enable Clear */
166
+ case 0xa8: /* Interrupt Enable Clear */
167
+ case 0x14:
168
s->enable &= ~data;
169
break;
170
- case 0x30: /* Software Interrupt */
171
+ case 0xb0: /* Software Interrupt */
172
+ case 0x18:
173
qemu_log_mask(LOG_UNIMP, "%s: Software interrupts unavailable. "
174
"IRQs requested: 0x%016" PRIx64 "\n", __func__, data);
175
break;
176
- case 0x38: /* Software Interrupt Clear */
177
+ case 0xb8: /* Software Interrupt Clear */
178
+ case 0x1c:
179
qemu_log_mask(LOG_UNIMP, "%s: Software interrupts unavailable. "
180
"IRQs to be cleared: 0x%016" PRIx64 "\n", __func__, data);
181
break;
182
- case 0x50: /* Interrupt Event */
183
+ case 0xd0: /* Interrupt Event */
184
/* Register has deposit64() semantics - overwrite the top four valid
185
* IRQ bits, as only the top four IRQs (GPIOs) can change their event
186
* type */
187
@@ -XXX,XX +XXX,XX @@ static void aspeed_vic_write(void *opaque, hwaddr offset, uint64_t data,
188
"Ignoring invalid write to interrupt event register");
189
}
190
break;
191
- case 0x58: /* Edge Triggered Interrupt Clear */
192
+ case 0xd8: /* Edge Triggered Interrupt Clear */
193
+ case 0x38:
194
s->raw &= ~(data & ~s->sense);
195
break;
196
- case 0x00: /* IRQ Status */
197
- case 0x08: /* FIQ Status */
198
- case 0x10: /* Raw Interrupt Status */
199
- case 0x40: /* Interrupt Sensitivity */
200
- case 0x48: /* Interrupt Both Edge Trigger Control */
201
- case 0x60: /* Edge Triggered Interrupt Status */
202
+ case 0x80: /* IRQ Status */
203
+ case 0x00:
204
+ case 0x88: /* FIQ Status */
205
+ case 0x04:
206
+ case 0x90: /* Raw Interrupt Status */
207
+ case 0x08:
208
+ case 0xc0: /* Interrupt Sensitivity */
209
+ case 0x24:
210
+ case 0xc8: /* Interrupt Both Edge Trigger Control */
211
+ case 0x28:
212
+ case 0xe0: /* Edge Triggered Interrupt Status */
213
qemu_log_mask(LOG_GUEST_ERROR,
214
"%s: Write of read-only register with offset 0x%"
215
HWADDR_PRIx "\n", __func__, offset);
216
--
80
--
217
2.20.1
81
2.20.1
218
82
219
83
diff view generated by jsdifflib
Deleted patch
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
2
1
3
Group Aarch64 rules together, TCG related ones at the bottom.
4
This will help when restricting TCG-only objects.
5
6
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
7
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
8
Message-id: 20190701132516.26392-2-philmd@redhat.com
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
11
target/arm/Makefile.objs | 5 +++--
12
1 file changed, 3 insertions(+), 2 deletions(-)
13
14
diff --git a/target/arm/Makefile.objs b/target/arm/Makefile.objs
15
index XXXXXXX..XXXXXXX 100644
16
--- a/target/arm/Makefile.objs
17
+++ b/target/arm/Makefile.objs
18
@@ -XXX,XX +XXX,XX @@ obj-$(call lnot,$(CONFIG_KVM)) += kvm-stub.o
19
obj-y += translate.o op_helper.o helper.o cpu.o
20
obj-y += neon_helper.o iwmmxt_helper.o vec_helper.o vfp_helper.o
21
obj-y += gdbstub.o
22
-obj-$(TARGET_AARCH64) += cpu64.o translate-a64.o helper-a64.o gdbstub64.o
23
-obj-$(TARGET_AARCH64) += pauth_helper.o
24
+obj-$(TARGET_AARCH64) += cpu64.o gdbstub64.o
25
obj-y += crypto_helper.o
26
obj-$(CONFIG_SOFTMMU) += arm-powerctl.o
27
28
@@ -XXX,XX +XXX,XX @@ target/arm/translate-sve.o: target/arm/decode-sve.inc.c
29
target/arm/translate.o: target/arm/decode-vfp.inc.c
30
target/arm/translate.o: target/arm/decode-vfp-uncond.inc.c
31
32
+obj-$(TARGET_AARCH64) += translate-a64.o helper-a64.o
33
obj-$(TARGET_AARCH64) += translate-sve.o sve_helper.o
34
+obj-$(TARGET_AARCH64) += pauth_helper.o
35
--
36
2.20.1
37
38
diff view generated by jsdifflib
Deleted patch
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
2
1
3
Group ARM objects together, TCG related ones at the bottom.
4
This will help when restricting TCG-only objects.
5
6
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
7
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
8
Message-id: 20190701132516.26392-3-philmd@redhat.com
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
11
target/arm/Makefile.objs | 10 ++++++----
12
1 file changed, 6 insertions(+), 4 deletions(-)
13
14
diff --git a/target/arm/Makefile.objs b/target/arm/Makefile.objs
15
index XXXXXXX..XXXXXXX 100644
16
--- a/target/arm/Makefile.objs
17
+++ b/target/arm/Makefile.objs
18
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_KVM) += kvm.o
19
obj-$(call land,$(CONFIG_KVM),$(call lnot,$(TARGET_AARCH64))) += kvm32.o
20
obj-$(call land,$(CONFIG_KVM),$(TARGET_AARCH64)) += kvm64.o
21
obj-$(call lnot,$(CONFIG_KVM)) += kvm-stub.o
22
-obj-y += translate.o op_helper.o helper.o cpu.o
23
-obj-y += neon_helper.o iwmmxt_helper.o vec_helper.o vfp_helper.o
24
-obj-y += gdbstub.o
25
+obj-y += helper.o vfp_helper.o
26
+obj-y += cpu.o gdbstub.o
27
obj-$(TARGET_AARCH64) += cpu64.o gdbstub64.o
28
-obj-y += crypto_helper.o
29
obj-$(CONFIG_SOFTMMU) += arm-powerctl.o
30
31
DECODETREE = $(SRC_PATH)/scripts/decodetree.py
32
@@ -XXX,XX +XXX,XX @@ target/arm/translate-sve.o: target/arm/decode-sve.inc.c
33
target/arm/translate.o: target/arm/decode-vfp.inc.c
34
target/arm/translate.o: target/arm/decode-vfp-uncond.inc.c
35
36
+obj-y += translate.o op_helper.o
37
+obj-y += crypto_helper.o
38
+obj-y += iwmmxt_helper.o vec_helper.o neon_helper.o
39
+
40
obj-$(TARGET_AARCH64) += translate-a64.o helper-a64.o
41
obj-$(TARGET_AARCH64) += translate-sve.o sve_helper.o
42
obj-$(TARGET_AARCH64) += pauth_helper.o
43
--
44
2.20.1
45
46
diff view generated by jsdifflib