1 | Another lump of target-arm patches. I still have some patches in | 1 | Hi; here's the latest round of arm patches. I have included also |
---|---|---|---|
2 | my to-review queue, but this is a big enough set that I wanted | 2 | my patchset for the RTC devices to avoid keeping time_t and |
3 | to send it out. | 3 | time_t diffs in 32-bit variables. |
4 | 4 | ||
5 | thanks | 5 | thanks |
6 | -- PMM | 6 | -- PMM |
7 | 7 | ||
8 | The following changes since commit 04bb7fe2bf55bdf66d5b7a5a719b40bbb4048178: | 8 | The following changes since commit 156618d9ea67f2f2e31d9dedd97f2dcccbe6808c: |
9 | 9 | ||
10 | Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20180208' into staging (2018-02-08 17:41:15 +0000) | 10 | Merge tag 'block-pull-request' of https://gitlab.com/stefanha/qemu into staging (2023-08-30 09:20:27 -0400) |
11 | 11 | ||
12 | are available in the Git repository at: | 12 | are available in the Git repository at: |
13 | 13 | ||
14 | git://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20180209 | 14 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20230831 |
15 | 15 | ||
16 | for you to fetch changes up to bbba7757bacc9f890a3f028d328b4b429dbe78ec: | 16 | for you to fetch changes up to e73b8bb8a3e9a162f70e9ffbf922d4fafc96bbfb: |
17 | 17 | ||
18 | hw/core/generic-loader: Allow PC to be set on command line (2018-02-09 10:55:40 +0000) | 18 | hw/arm: Set number of MPU regions correctly for an505, an521, an524 (2023-08-31 11:07:02 +0100) |
19 | 19 | ||
20 | ---------------------------------------------------------------- | 20 | ---------------------------------------------------------------- |
21 | target-arm queue: | 21 | target-arm queue: |
22 | * Support M profile derived exceptions on exception entry and exit | 22 | * Some of the preliminary patches for Cortex-A710 support |
23 | * Implement AArch64 v8.2 crypto insns (SHA-512, SHA-3, SM3, SM4) | 23 | * i.MX7 and i.MX6UL refactoring |
24 | * Implement working i.MX6 SD controller | 24 | * Implement SRC device for i.MX7 |
25 | * Various devices preparatory to i.MX7 support | 25 | * Catch illegal-exception-return from EL3 with bad NSE/NS |
26 | * Preparatory patches for SVE emulation | 26 | * Use 64-bit offsets for holding time_t differences in RTC devices |
27 | * v8M: Fix bug in implementation of 'TT' insn | 27 | * Model correct number of MPU regions for an505, an521, an524 boards |
28 | * Give useful error if user tries to use userspace GICv3 with KVM | ||
29 | 28 | ||
30 | ---------------------------------------------------------------- | 29 | ---------------------------------------------------------------- |
31 | Andrey Smirnov (10): | 30 | Alex Bennée (1): |
32 | sdhci: Add i.MX specific subtype of SDHCI | 31 | target/arm: properly document FEAT_CRC32 |
33 | hw: i.MX: Convert i.MX6 to use TYPE_IMX_USDHC | ||
34 | i.MX: Add code to emulate i.MX7 CCM, PMU and ANALOG IP blocks | ||
35 | i.MX: Add code to emulate i.MX2 watchdog IP block | ||
36 | i.MX: Add code to emulate i.MX7 SNVS IP-block | ||
37 | i.MX: Add code to emulate GPCv2 IP block | ||
38 | i.MX: Add i.MX7 GPT variant | ||
39 | i.MX: Add implementation of i.MX7 GPR IP block | ||
40 | usb: Add basic code to emulate Chipidea USB IP | ||
41 | hw/arm: Move virt's PSCI DT fixup code to arm/boot.c | ||
42 | 32 | ||
43 | Ard Biesheuvel (5): | 33 | Jean-Christophe Dubois (6): |
44 | target/arm: implement SHA-512 instructions | 34 | Remove i.MX7 IOMUX GPR device from i.MX6UL |
45 | target/arm: implement SHA-3 instructions | 35 | Refactor i.MX6UL processor code |
46 | target/arm: implement SM3 instructions | 36 | Add i.MX6UL missing devices. |
47 | target/arm: implement SM4 instructions | 37 | Refactor i.MX7 processor code |
48 | target/arm: enable user-mode SHA-3, SM3, SM4 and SHA-512 instruction support | 38 | Add i.MX7 missing TZ devices and memory regions |
39 | Add i.MX7 SRC device implementation | ||
49 | 40 | ||
50 | Christoffer Dall (1): | 41 | Peter Maydell (8): |
51 | target/arm/kvm: gic: Prevent creating userspace GICv3 with KVM | 42 | target/arm: Catch illegal-exception-return from EL3 with bad NSE/NS |
43 | hw/rtc/m48t59: Use 64-bit arithmetic in set_alarm() | ||
44 | hw/rtc/twl92230: Use int64_t for sec_offset and alm_sec | ||
45 | hw/rtc/aspeed_rtc: Use 64-bit offset for holding time_t difference | ||
46 | rtc: Use time_t for passing and returning time offsets | ||
47 | target/arm: Do all "ARM_FEATURE_X implies Y" checks in post_init | ||
48 | hw/arm/armv7m: Add mpu-ns-regions and mpu-s-regions properties | ||
49 | hw/arm: Set number of MPU regions correctly for an505, an521, an524 | ||
52 | 50 | ||
53 | Peter Maydell (9): | 51 | Richard Henderson (9): |
54 | target/arm: Add armv7m_nvic_set_pending_derived() | 52 | target/arm: Reduce dcz_blocksize to uint8_t |
55 | target/arm: Split "get pending exception info" from "acknowledge it" | 53 | target/arm: Allow cpu to configure GM blocksize |
56 | target/arm: Add ignore_stackfaults argument to v7m_exception_taken() | 54 | target/arm: Support more GM blocksizes |
57 | target/arm: Make v7M exception entry stack push check MPU | 55 | target/arm: When tag memory is not present, set MTE=1 |
58 | target/arm: Make v7m_push_callee_stack() honour MPU | 56 | target/arm: Introduce make_ccsidr64 |
59 | target/arm: Make exception vector loads honour the SAU | 57 | target/arm: Apply access checks to neoverse-n1 special registers |
60 | target/arm: Handle exceptions during exception stack pop | 58 | target/arm: Apply access checks to neoverse-v1 special registers |
61 | target/arm/translate.c: Fix missing 'break' for TT insns | 59 | target/arm: Suppress FEAT_TRBE (Trace Buffer Extension) |
62 | hw/core/generic-loader: Allow PC to be set on command line | 60 | target/arm: Implement FEAT_HPDS2 as a no-op |
63 | 61 | ||
64 | Richard Henderson (5): | 62 | docs/system/arm/emulation.rst | 2 + |
65 | target/arm: Expand vector registers for SVE | 63 | include/hw/arm/armsse.h | 5 + |
66 | target/arm: Add predicate registers for SVE | 64 | include/hw/arm/armv7m.h | 8 + |
67 | target/arm: Add SVE to migration state | 65 | include/hw/arm/fsl-imx6ul.h | 158 ++++++++++++++++--- |
68 | target/arm: Add ZCR_ELx | 66 | include/hw/arm/fsl-imx7.h | 338 ++++++++++++++++++++++++++++++----------- |
69 | target/arm: Add SVE state to TB->FLAGS | 67 | include/hw/misc/imx7_src.h | 66 ++++++++ |
68 | include/hw/rtc/aspeed_rtc.h | 2 +- | ||
69 | include/sysemu/rtc.h | 4 +- | ||
70 | target/arm/cpregs.h | 2 + | ||
71 | target/arm/cpu.h | 5 +- | ||
72 | target/arm/internals.h | 6 - | ||
73 | target/arm/tcg/translate.h | 2 + | ||
74 | hw/arm/armsse.c | 16 ++ | ||
75 | hw/arm/armv7m.c | 21 +++ | ||
76 | hw/arm/fsl-imx6ul.c | 174 +++++++++++++-------- | ||
77 | hw/arm/fsl-imx7.c | 201 +++++++++++++++++++----- | ||
78 | hw/arm/mps2-tz.c | 29 ++++ | ||
79 | hw/misc/imx7_src.c | 276 +++++++++++++++++++++++++++++++++ | ||
80 | hw/rtc/aspeed_rtc.c | 5 +- | ||
81 | hw/rtc/m48t59.c | 2 +- | ||
82 | hw/rtc/twl92230.c | 4 +- | ||
83 | softmmu/rtc.c | 4 +- | ||
84 | target/arm/cpu.c | 207 ++++++++++++++----------- | ||
85 | target/arm/helper.c | 15 +- | ||
86 | target/arm/tcg/cpu32.c | 2 +- | ||
87 | target/arm/tcg/cpu64.c | 102 +++++++++---- | ||
88 | target/arm/tcg/helper-a64.c | 9 ++ | ||
89 | target/arm/tcg/mte_helper.c | 90 ++++++++--- | ||
90 | target/arm/tcg/translate-a64.c | 5 +- | ||
91 | hw/misc/meson.build | 1 + | ||
92 | hw/misc/trace-events | 4 + | ||
93 | 31 files changed, 1393 insertions(+), 372 deletions(-) | ||
94 | create mode 100644 include/hw/misc/imx7_src.h | ||
95 | create mode 100644 hw/misc/imx7_src.c | ||
70 | 96 | ||
71 | hw/intc/Makefile.objs | 2 +- | ||
72 | hw/misc/Makefile.objs | 4 + | ||
73 | hw/usb/Makefile.objs | 1 + | ||
74 | hw/sd/sdhci-internal.h | 23 ++ | ||
75 | include/hw/intc/imx_gpcv2.h | 22 ++ | ||
76 | include/hw/misc/imx2_wdt.h | 33 +++ | ||
77 | include/hw/misc/imx7_ccm.h | 139 +++++++++++ | ||
78 | include/hw/misc/imx7_gpr.h | 28 +++ | ||
79 | include/hw/misc/imx7_snvs.h | 35 +++ | ||
80 | include/hw/sd/sdhci.h | 13 ++ | ||
81 | include/hw/timer/imx_gpt.h | 1 + | ||
82 | include/hw/usb/chipidea.h | 16 ++ | ||
83 | target/arm/cpu.h | 120 ++++++++-- | ||
84 | target/arm/helper.h | 12 + | ||
85 | target/arm/kvm_arm.h | 4 + | ||
86 | target/arm/translate.h | 2 + | ||
87 | hw/arm/boot.c | 65 ++++++ | ||
88 | hw/arm/fsl-imx6.c | 2 +- | ||
89 | hw/arm/virt.c | 61 ----- | ||
90 | hw/core/generic-loader.c | 2 +- | ||
91 | hw/intc/armv7m_nvic.c | 98 +++++++- | ||
92 | hw/intc/imx_gpcv2.c | 125 ++++++++++ | ||
93 | hw/misc/imx2_wdt.c | 89 +++++++ | ||
94 | hw/misc/imx7_ccm.c | 277 ++++++++++++++++++++++ | ||
95 | hw/misc/imx7_gpr.c | 124 ++++++++++ | ||
96 | hw/misc/imx7_snvs.c | 83 +++++++ | ||
97 | hw/sd/sdhci.c | 230 ++++++++++++++++++- | ||
98 | hw/timer/imx_gpt.c | 25 ++ | ||
99 | hw/usb/chipidea.c | 176 ++++++++++++++ | ||
100 | linux-user/elfload.c | 19 ++ | ||
101 | target/arm/cpu64.c | 4 + | ||
102 | target/arm/crypto_helper.c | 277 +++++++++++++++++++++- | ||
103 | target/arm/helper.c | 548 +++++++++++++++++++++++++++++++++++++------- | ||
104 | target/arm/machine.c | 88 ++++++- | ||
105 | target/arm/translate-a64.c | 350 +++++++++++++++++++++++++++- | ||
106 | target/arm/translate.c | 8 +- | ||
107 | hw/intc/trace-events | 5 +- | ||
108 | hw/misc/trace-events | 4 + | ||
109 | 38 files changed, 2928 insertions(+), 187 deletions(-) | ||
110 | create mode 100644 include/hw/intc/imx_gpcv2.h | ||
111 | create mode 100644 include/hw/misc/imx2_wdt.h | ||
112 | create mode 100644 include/hw/misc/imx7_ccm.h | ||
113 | create mode 100644 include/hw/misc/imx7_gpr.h | ||
114 | create mode 100644 include/hw/misc/imx7_snvs.h | ||
115 | create mode 100644 include/hw/usb/chipidea.h | ||
116 | create mode 100644 hw/intc/imx_gpcv2.c | ||
117 | create mode 100644 hw/misc/imx2_wdt.c | ||
118 | create mode 100644 hw/misc/imx7_ccm.c | ||
119 | create mode 100644 hw/misc/imx7_gpr.c | ||
120 | create mode 100644 hw/misc/imx7_snvs.c | ||
121 | create mode 100644 hw/usb/chipidea.c | ||
122 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | In order to support derived exceptions (exceptions generated in | ||
2 | the course of trying to take an exception), we need to be able | ||
3 | to handle prioritizing whether to take the original exception | ||
4 | or the derived exception. | ||
5 | 1 | ||
6 | We do this by introducing a new function | ||
7 | armv7m_nvic_set_pending_derived() which the exception-taking code in | ||
8 | helper.c will call when a derived exception occurs. Derived | ||
9 | exceptions are dealt with mostly like normal pending exceptions, so | ||
10 | we share the implementation with the armv7m_nvic_set_pending() | ||
11 | function. | ||
12 | |||
13 | Note that the way we structure this is significantly different | ||
14 | from the v8M Arm ARM pseudocode: that does all the prioritization | ||
15 | logic in the DerivedLateArrival() function, whereas we choose to | ||
16 | let the existing "identify highest priority exception" logic | ||
17 | do the prioritization for us. The effect is the same, though. | ||
18 | |||
19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
20 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
21 | Message-id: 1517324542-6607-2-git-send-email-peter.maydell@linaro.org | ||
22 | --- | ||
23 | target/arm/cpu.h | 13 ++++++++++ | ||
24 | hw/intc/armv7m_nvic.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++-- | ||
25 | hw/intc/trace-events | 2 +- | ||
26 | 3 files changed, 80 insertions(+), 3 deletions(-) | ||
27 | |||
28 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | ||
29 | index XXXXXXX..XXXXXXX 100644 | ||
30 | --- a/target/arm/cpu.h | ||
31 | +++ b/target/arm/cpu.h | ||
32 | @@ -XXX,XX +XXX,XX @@ static inline bool armv7m_nvic_can_take_pending_exception(void *opaque) | ||
33 | * of architecturally banked exceptions. | ||
34 | */ | ||
35 | void armv7m_nvic_set_pending(void *opaque, int irq, bool secure); | ||
36 | +/** | ||
37 | + * armv7m_nvic_set_pending_derived: mark this derived exception as pending | ||
38 | + * @opaque: the NVIC | ||
39 | + * @irq: the exception number to mark pending | ||
40 | + * @secure: false for non-banked exceptions or for the nonsecure | ||
41 | + * version of a banked exception, true for the secure version of a banked | ||
42 | + * exception. | ||
43 | + * | ||
44 | + * Similar to armv7m_nvic_set_pending(), but specifically for derived | ||
45 | + * exceptions (exceptions generated in the course of trying to take | ||
46 | + * a different exception). | ||
47 | + */ | ||
48 | +void armv7m_nvic_set_pending_derived(void *opaque, int irq, bool secure); | ||
49 | /** | ||
50 | * armv7m_nvic_acknowledge_irq: make highest priority pending exception active | ||
51 | * @opaque: the NVIC | ||
52 | diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c | ||
53 | index XXXXXXX..XXXXXXX 100644 | ||
54 | --- a/hw/intc/armv7m_nvic.c | ||
55 | +++ b/hw/intc/armv7m_nvic.c | ||
56 | @@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_clear_pending(void *opaque, int irq, bool secure) | ||
57 | } | ||
58 | } | ||
59 | |||
60 | -void armv7m_nvic_set_pending(void *opaque, int irq, bool secure) | ||
61 | +static void do_armv7m_nvic_set_pending(void *opaque, int irq, bool secure, | ||
62 | + bool derived) | ||
63 | { | ||
64 | + /* Pend an exception, including possibly escalating it to HardFault. | ||
65 | + * | ||
66 | + * This function handles both "normal" pending of interrupts and | ||
67 | + * exceptions, and also derived exceptions (ones which occur as | ||
68 | + * a result of trying to take some other exception). | ||
69 | + * | ||
70 | + * If derived == true, the caller guarantees that we are part way through | ||
71 | + * trying to take an exception (but have not yet called | ||
72 | + * armv7m_nvic_acknowledge_irq() to make it active), and so: | ||
73 | + * - s->vectpending is the "original exception" we were trying to take | ||
74 | + * - irq is the "derived exception" | ||
75 | + * - nvic_exec_prio(s) gives the priority before exception entry | ||
76 | + * Here we handle the prioritization logic which the pseudocode puts | ||
77 | + * in the DerivedLateArrival() function. | ||
78 | + */ | ||
79 | + | ||
80 | NVICState *s = (NVICState *)opaque; | ||
81 | bool banked = exc_is_banked(irq); | ||
82 | VecInfo *vec; | ||
83 | @@ -XXX,XX +XXX,XX @@ void armv7m_nvic_set_pending(void *opaque, int irq, bool secure) | ||
84 | |||
85 | vec = (banked && secure) ? &s->sec_vectors[irq] : &s->vectors[irq]; | ||
86 | |||
87 | - trace_nvic_set_pending(irq, secure, vec->enabled, vec->prio); | ||
88 | + trace_nvic_set_pending(irq, secure, derived, vec->enabled, vec->prio); | ||
89 | + | ||
90 | + if (derived) { | ||
91 | + /* Derived exceptions are always synchronous. */ | ||
92 | + assert(irq >= ARMV7M_EXCP_HARD && irq < ARMV7M_EXCP_PENDSV); | ||
93 | + | ||
94 | + if (irq == ARMV7M_EXCP_DEBUG && | ||
95 | + exc_group_prio(s, vec->prio, secure) >= nvic_exec_prio(s)) { | ||
96 | + /* DebugMonitorFault, but its priority is lower than the | ||
97 | + * preempted exception priority: just ignore it. | ||
98 | + */ | ||
99 | + return; | ||
100 | + } | ||
101 | + | ||
102 | + if (irq == ARMV7M_EXCP_HARD && vec->prio >= s->vectpending_prio) { | ||
103 | + /* If this is a terminal exception (one which means we cannot | ||
104 | + * take the original exception, like a failure to read its | ||
105 | + * vector table entry), then we must take the derived exception. | ||
106 | + * If the derived exception can't take priority over the | ||
107 | + * original exception, then we go into Lockup. | ||
108 | + * | ||
109 | + * For QEMU, we rely on the fact that a derived exception is | ||
110 | + * terminal if and only if it's reported to us as HardFault, | ||
111 | + * which saves having to have an extra argument is_terminal | ||
112 | + * that we'd only use in one place. | ||
113 | + */ | ||
114 | + cpu_abort(&s->cpu->parent_obj, | ||
115 | + "Lockup: can't take terminal derived exception " | ||
116 | + "(original exception priority %d)\n", | ||
117 | + s->vectpending_prio); | ||
118 | + } | ||
119 | + /* We now continue with the same code as for a normal pending | ||
120 | + * exception, which will cause us to pend the derived exception. | ||
121 | + * We'll then take either the original or the derived exception | ||
122 | + * based on which is higher priority by the usual mechanism | ||
123 | + * for selecting the highest priority pending interrupt. | ||
124 | + */ | ||
125 | + } | ||
126 | |||
127 | if (irq >= ARMV7M_EXCP_HARD && irq < ARMV7M_EXCP_PENDSV) { | ||
128 | /* If a synchronous exception is pending then it may be | ||
129 | @@ -XXX,XX +XXX,XX @@ void armv7m_nvic_set_pending(void *opaque, int irq, bool secure) | ||
130 | } | ||
131 | } | ||
132 | |||
133 | +void armv7m_nvic_set_pending(void *opaque, int irq, bool secure) | ||
134 | +{ | ||
135 | + do_armv7m_nvic_set_pending(opaque, irq, secure, false); | ||
136 | +} | ||
137 | + | ||
138 | +void armv7m_nvic_set_pending_derived(void *opaque, int irq, bool secure) | ||
139 | +{ | ||
140 | + do_armv7m_nvic_set_pending(opaque, irq, secure, true); | ||
141 | +} | ||
142 | + | ||
143 | /* Make pending IRQ active. */ | ||
144 | bool armv7m_nvic_acknowledge_irq(void *opaque) | ||
145 | { | ||
146 | diff --git a/hw/intc/trace-events b/hw/intc/trace-events | ||
147 | index XXXXXXX..XXXXXXX 100644 | ||
148 | --- a/hw/intc/trace-events | ||
149 | +++ b/hw/intc/trace-events | ||
150 | @@ -XXX,XX +XXX,XX @@ nvic_set_prio(int irq, bool secure, uint8_t prio) "NVIC set irq %d secure-bank % | ||
151 | nvic_irq_update(int vectpending, int pendprio, int exception_prio, int level) "NVIC vectpending %d pending prio %d exception_prio %d: setting irq line to %d" | ||
152 | nvic_escalate_prio(int irq, int irqprio, int runprio) "NVIC escalating irq %d to HardFault: insufficient priority %d >= %d" | ||
153 | nvic_escalate_disabled(int irq) "NVIC escalating irq %d to HardFault: disabled" | ||
154 | -nvic_set_pending(int irq, bool secure, int en, int prio) "NVIC set pending irq %d secure-bank %d (enabled: %d priority %d)" | ||
155 | +nvic_set_pending(int irq, bool secure, bool derived, int en, int prio) "NVIC set pending irq %d secure-bank %d derived %d (enabled: %d priority %d)" | ||
156 | nvic_clear_pending(int irq, bool secure, int en, int prio) "NVIC clear pending irq %d secure-bank %d (enabled: %d priority %d)" | ||
157 | nvic_set_pending_level(int irq) "NVIC set pending: irq %d higher prio than vectpending: setting irq line to 1" | ||
158 | nvic_acknowledge_irq(int irq, int prio, bool targets_secure) "NVIC acknowledge IRQ: %d now active (prio %d targets_secure %d)" | ||
159 | -- | ||
160 | 2.16.1 | ||
161 | |||
162 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | This value is only 4 bits wide. | ||
4 | |||
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Message-id: 20230811214031.171020-2-richard.henderson@linaro.org |
6 | Message-id: 20180123035349.24538-3-richard.henderson@linaro.org | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | --- | 10 | --- |
9 | target/arm/cpu.h | 12 ++++++++++++ | 11 | target/arm/cpu.h | 3 ++- |
10 | 1 file changed, 12 insertions(+) | 12 | 1 file changed, 2 insertions(+), 1 deletion(-) |
11 | 13 | ||
12 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 14 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
13 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/target/arm/cpu.h | 16 | --- a/target/arm/cpu.h |
15 | +++ b/target/arm/cpu.h | 17 | +++ b/target/arm/cpu.h |
16 | @@ -XXX,XX +XXX,XX @@ typedef struct ARMVectorReg { | 18 | @@ -XXX,XX +XXX,XX @@ struct ArchCPU { |
17 | uint64_t d[2 * ARM_MAX_VQ] QEMU_ALIGNED(16); | 19 | bool prop_lpa2; |
18 | } ARMVectorReg; | 20 | |
19 | 21 | /* DCZ blocksize, in log_2(words), ie low 4 bits of DCZID_EL0 */ | |
20 | +/* In AArch32 mode, predicate registers do not exist at all. */ | 22 | - uint32_t dcz_blocksize; |
21 | +#ifdef TARGET_AARCH64 | 23 | + uint8_t dcz_blocksize; |
22 | +typedef struct ARMPredicateReg { | ||
23 | + uint64_t p[2 * ARM_MAX_VQ / 8] QEMU_ALIGNED(16); | ||
24 | +} ARMPredicateReg; | ||
25 | +#endif | ||
26 | + | 24 | + |
27 | 25 | uint64_t rvbar_prop; /* Property/input signals. */ | |
28 | typedef struct CPUARMState { | 26 | |
29 | /* Regs for current mode. */ | 27 | /* Configurable aspects of GIC cpu interface (which is part of the CPU) */ |
30 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUARMState { | ||
31 | struct { | ||
32 | ARMVectorReg zregs[32]; | ||
33 | |||
34 | +#ifdef TARGET_AARCH64 | ||
35 | + /* Store FFR as pregs[16] to make it easier to treat as any other. */ | ||
36 | + ARMPredicateReg pregs[17]; | ||
37 | +#endif | ||
38 | + | ||
39 | uint32_t xregs[16]; | ||
40 | /* We store these fpcsr fields separately for convenience. */ | ||
41 | int vec_len; | ||
42 | -- | 28 | -- |
43 | 2.16.1 | 29 | 2.34.1 |
44 | 30 | ||
45 | 31 | diff view generated by jsdifflib |
1 | Currently armv7m_nvic_acknowledge_irq() does three things: | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | * make the current highest priority pending interrupt active | 2 | |
3 | * return a bool indicating whether that interrupt is targeting | 3 | Previously we hard-coded the blocksize with GMID_EL1_BS. |
4 | Secure or NonSecure state | 4 | But the value we choose for -cpu max does not match the |
5 | * implicitly tell the caller which is the highest priority | 5 | value that cortex-a710 uses. |
6 | pending interrupt by setting env->v7m.exception | 6 | |
7 | 7 | Mirror the way we handle dcz_blocksize. | |
8 | We need to split these jobs, because v7m_exception_taken() | 8 | |
9 | needs to know whether the pending interrupt targets Secure so | 9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
10 | it can choose to stack callee-saves registers or not, but it | 10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
11 | must not make the interrupt active until after it has done | 11 | Message-id: 20230811214031.171020-3-richard.henderson@linaro.org |
12 | that stacking, in case the stacking causes a derived exception. | ||
13 | Similarly, it needs to know the number of the pending interrupt | ||
14 | so it can read the correct vector table entry before the | ||
15 | interrupt is made active, because vector table reads might | ||
16 | also cause a derived exception. | ||
17 | |||
18 | Create a new armv7m_nvic_get_pending_irq_info() function which simply | ||
19 | returns information about the highest priority pending interrupt, and | ||
20 | use it to rearrange the v7m_exception_taken() code so we don't | ||
21 | acknowledge the exception until we've done all the things which could | ||
22 | possibly cause a derived exception. | ||
23 | |||
24 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
25 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
26 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
27 | Message-id: 1517324542-6607-3-git-send-email-peter.maydell@linaro.org | ||
28 | --- | 13 | --- |
29 | target/arm/cpu.h | 19 ++++++++++++++++--- | 14 | target/arm/cpu.h | 2 ++ |
30 | hw/intc/armv7m_nvic.c | 30 +++++++++++++++++++++++------- | 15 | target/arm/internals.h | 6 ----- |
31 | target/arm/helper.c | 16 ++++++++++++---- | 16 | target/arm/tcg/translate.h | 2 ++ |
32 | hw/intc/trace-events | 3 ++- | 17 | target/arm/helper.c | 11 +++++--- |
33 | 4 files changed, 53 insertions(+), 15 deletions(-) | 18 | target/arm/tcg/cpu64.c | 1 + |
19 | target/arm/tcg/mte_helper.c | 46 ++++++++++++++++++++++------------ | ||
20 | target/arm/tcg/translate-a64.c | 5 ++-- | ||
21 | 7 files changed, 45 insertions(+), 28 deletions(-) | ||
34 | 22 | ||
35 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 23 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
36 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
37 | --- a/target/arm/cpu.h | 25 | --- a/target/arm/cpu.h |
38 | +++ b/target/arm/cpu.h | 26 | +++ b/target/arm/cpu.h |
39 | @@ -XXX,XX +XXX,XX @@ void armv7m_nvic_set_pending(void *opaque, int irq, bool secure); | 27 | @@ -XXX,XX +XXX,XX @@ struct ArchCPU { |
40 | * a different exception). | 28 | |
41 | */ | 29 | /* DCZ blocksize, in log_2(words), ie low 4 bits of DCZID_EL0 */ |
42 | void armv7m_nvic_set_pending_derived(void *opaque, int irq, bool secure); | 30 | uint8_t dcz_blocksize; |
43 | +/** | 31 | + /* GM blocksize, in log_2(words), ie low 4 bits of GMID_EL0 */ |
44 | + * armv7m_nvic_get_pending_irq_info: return highest priority pending | 32 | + uint8_t gm_blocksize; |
45 | + * exception, and whether it targets Secure state | 33 | |
46 | + * @opaque: the NVIC | 34 | uint64_t rvbar_prop; /* Property/input signals. */ |
47 | + * @pirq: set to pending exception number | 35 | |
48 | + * @ptargets_secure: set to whether pending exception targets Secure | 36 | diff --git a/target/arm/internals.h b/target/arm/internals.h |
49 | + * | 37 | index XXXXXXX..XXXXXXX 100644 |
50 | + * This function writes the number of the highest priority pending | 38 | --- a/target/arm/internals.h |
51 | + * exception (the one which would be made active by | 39 | +++ b/target/arm/internals.h |
52 | + * armv7m_nvic_acknowledge_irq()) to @pirq, and sets @ptargets_secure | 40 | @@ -XXX,XX +XXX,XX @@ void arm_log_exception(CPUState *cs); |
53 | + * to true if the current highest priority pending exception should | 41 | |
54 | + * be taken to Secure state, false for NS. | 42 | #endif /* !CONFIG_USER_ONLY */ |
55 | + */ | 43 | |
56 | +void armv7m_nvic_get_pending_irq_info(void *opaque, int *pirq, | 44 | -/* |
57 | + bool *ptargets_secure); | 45 | - * The log2 of the words in the tag block, for GMID_EL1.BS. |
58 | /** | 46 | - * The is the maximum, 256 bytes, which manipulates 64-bits of tags. |
59 | * armv7m_nvic_acknowledge_irq: make highest priority pending exception active | 47 | - */ |
60 | * @opaque: the NVIC | 48 | -#define GMID_EL1_BS 6 |
61 | @@ -XXX,XX +XXX,XX @@ void armv7m_nvic_set_pending_derived(void *opaque, int irq, bool secure); | 49 | - |
62 | * Move the current highest priority pending exception from the pending | 50 | /* |
63 | * state to the active state, and update v7m.exception to indicate that | 51 | * SVE predicates are 1/8 the size of SVE vectors, and cannot use |
64 | * it is the exception currently being handled. | 52 | * the same simd_desc() encoding due to restrictions on size. |
65 | - * | 53 | diff --git a/target/arm/tcg/translate.h b/target/arm/tcg/translate.h |
66 | - * Returns: true if exception should be taken to Secure state, false for NS | 54 | index XXXXXXX..XXXXXXX 100644 |
67 | */ | 55 | --- a/target/arm/tcg/translate.h |
68 | -bool armv7m_nvic_acknowledge_irq(void *opaque); | 56 | +++ b/target/arm/tcg/translate.h |
69 | +void armv7m_nvic_acknowledge_irq(void *opaque); | 57 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { |
70 | /** | 58 | int8_t btype; |
71 | * armv7m_nvic_complete_irq: complete specified interrupt or exception | 59 | /* A copy of cpu->dcz_blocksize. */ |
72 | * @opaque: the NVIC | 60 | uint8_t dcz_blocksize; |
73 | diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c | 61 | + /* A copy of cpu->gm_blocksize. */ |
74 | index XXXXXXX..XXXXXXX 100644 | 62 | + uint8_t gm_blocksize; |
75 | --- a/hw/intc/armv7m_nvic.c | 63 | /* True if this page is guarded. */ |
76 | +++ b/hw/intc/armv7m_nvic.c | 64 | bool guarded_page; |
77 | @@ -XXX,XX +XXX,XX @@ void armv7m_nvic_set_pending_derived(void *opaque, int irq, bool secure) | 65 | /* Bottom two bits of XScale c15_cpar coprocessor access control reg */ |
78 | } | ||
79 | |||
80 | /* Make pending IRQ active. */ | ||
81 | -bool armv7m_nvic_acknowledge_irq(void *opaque) | ||
82 | +void armv7m_nvic_acknowledge_irq(void *opaque) | ||
83 | { | ||
84 | NVICState *s = (NVICState *)opaque; | ||
85 | CPUARMState *env = &s->cpu->env; | ||
86 | const int pending = s->vectpending; | ||
87 | const int running = nvic_exec_prio(s); | ||
88 | VecInfo *vec; | ||
89 | - bool targets_secure; | ||
90 | |||
91 | assert(pending > ARMV7M_EXCP_RESET && pending < s->num_irq); | ||
92 | |||
93 | if (s->vectpending_is_s_banked) { | ||
94 | vec = &s->sec_vectors[pending]; | ||
95 | - targets_secure = true; | ||
96 | } else { | ||
97 | vec = &s->vectors[pending]; | ||
98 | - targets_secure = !exc_is_banked(s->vectpending) && | ||
99 | - exc_targets_secure(s, s->vectpending); | ||
100 | } | ||
101 | |||
102 | assert(vec->enabled); | ||
103 | @@ -XXX,XX +XXX,XX @@ bool armv7m_nvic_acknowledge_irq(void *opaque) | ||
104 | |||
105 | assert(s->vectpending_prio < running); | ||
106 | |||
107 | - trace_nvic_acknowledge_irq(pending, s->vectpending_prio, targets_secure); | ||
108 | + trace_nvic_acknowledge_irq(pending, s->vectpending_prio); | ||
109 | |||
110 | vec->active = 1; | ||
111 | vec->pending = 0; | ||
112 | @@ -XXX,XX +XXX,XX @@ bool armv7m_nvic_acknowledge_irq(void *opaque) | ||
113 | write_v7m_exception(env, s->vectpending); | ||
114 | |||
115 | nvic_irq_update(s); | ||
116 | +} | ||
117 | + | ||
118 | +void armv7m_nvic_get_pending_irq_info(void *opaque, | ||
119 | + int *pirq, bool *ptargets_secure) | ||
120 | +{ | ||
121 | + NVICState *s = (NVICState *)opaque; | ||
122 | + const int pending = s->vectpending; | ||
123 | + bool targets_secure; | ||
124 | + | ||
125 | + assert(pending > ARMV7M_EXCP_RESET && pending < s->num_irq); | ||
126 | + | ||
127 | + if (s->vectpending_is_s_banked) { | ||
128 | + targets_secure = true; | ||
129 | + } else { | ||
130 | + targets_secure = !exc_is_banked(pending) && | ||
131 | + exc_targets_secure(s, pending); | ||
132 | + } | ||
133 | + | ||
134 | + trace_nvic_get_pending_irq_info(pending, targets_secure); | ||
135 | |||
136 | - return targets_secure; | ||
137 | + *ptargets_secure = targets_secure; | ||
138 | + *pirq = pending; | ||
139 | } | ||
140 | |||
141 | int armv7m_nvic_complete_irq(void *opaque, int irq, bool secure) | ||
142 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 66 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
143 | index XXXXXXX..XXXXXXX 100644 | 67 | index XXXXXXX..XXXXXXX 100644 |
144 | --- a/target/arm/helper.c | 68 | --- a/target/arm/helper.c |
145 | +++ b/target/arm/helper.c | 69 | +++ b/target/arm/helper.c |
146 | @@ -XXX,XX +XXX,XX @@ static uint32_t *get_v7m_sp_ptr(CPUARMState *env, bool secure, bool threadmode, | 70 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo mte_reginfo[] = { |
71 | .opc0 = 3, .opc1 = 0, .crn = 1, .crm = 0, .opc2 = 6, | ||
72 | .access = PL1_RW, .accessfn = access_mte, | ||
73 | .fieldoffset = offsetof(CPUARMState, cp15.gcr_el1) }, | ||
74 | - { .name = "GMID_EL1", .state = ARM_CP_STATE_AA64, | ||
75 | - .opc0 = 3, .opc1 = 1, .crn = 0, .crm = 0, .opc2 = 4, | ||
76 | - .access = PL1_R, .accessfn = access_aa64_tid5, | ||
77 | - .type = ARM_CP_CONST, .resetvalue = GMID_EL1_BS }, | ||
78 | { .name = "TCO", .state = ARM_CP_STATE_AA64, | ||
79 | .opc0 = 3, .opc1 = 3, .crn = 4, .crm = 2, .opc2 = 7, | ||
80 | .type = ARM_CP_NO_RAW, | ||
81 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
82 | * then define only a RAZ/WI version of PSTATE.TCO. | ||
83 | */ | ||
84 | if (cpu_isar_feature(aa64_mte, cpu)) { | ||
85 | + ARMCPRegInfo gmid_reginfo = { | ||
86 | + .name = "GMID_EL1", .state = ARM_CP_STATE_AA64, | ||
87 | + .opc0 = 3, .opc1 = 1, .crn = 0, .crm = 0, .opc2 = 4, | ||
88 | + .access = PL1_R, .accessfn = access_aa64_tid5, | ||
89 | + .type = ARM_CP_CONST, .resetvalue = cpu->gm_blocksize, | ||
90 | + }; | ||
91 | + define_one_arm_cp_reg(cpu, &gmid_reginfo); | ||
92 | define_arm_cp_regs(cpu, mte_reginfo); | ||
93 | define_arm_cp_regs(cpu, mte_el0_cacheop_reginfo); | ||
94 | } else if (cpu_isar_feature(aa64_mte_insn_reg, cpu)) { | ||
95 | diff --git a/target/arm/tcg/cpu64.c b/target/arm/tcg/cpu64.c | ||
96 | index XXXXXXX..XXXXXXX 100644 | ||
97 | --- a/target/arm/tcg/cpu64.c | ||
98 | +++ b/target/arm/tcg/cpu64.c | ||
99 | @@ -XXX,XX +XXX,XX @@ void aarch64_max_tcg_initfn(Object *obj) | ||
100 | cpu->ctr = 0x80038003; /* 32 byte I and D cacheline size, VIPT icache */ | ||
101 | cpu->dcz_blocksize = 7; /* 512 bytes */ | ||
102 | #endif | ||
103 | + cpu->gm_blocksize = 6; /* 256 bytes */ | ||
104 | |||
105 | cpu->sve_vq.supported = MAKE_64BIT_MASK(0, ARM_MAX_VQ); | ||
106 | cpu->sme_vq.supported = SVE_VQ_POW2_MAP; | ||
107 | diff --git a/target/arm/tcg/mte_helper.c b/target/arm/tcg/mte_helper.c | ||
108 | index XXXXXXX..XXXXXXX 100644 | ||
109 | --- a/target/arm/tcg/mte_helper.c | ||
110 | +++ b/target/arm/tcg/mte_helper.c | ||
111 | @@ -XXX,XX +XXX,XX @@ void HELPER(st2g_stub)(CPUARMState *env, uint64_t ptr) | ||
147 | } | 112 | } |
148 | } | 113 | } |
149 | 114 | ||
150 | -static uint32_t arm_v7m_load_vector(ARMCPU *cpu, bool targets_secure) | 115 | -#define LDGM_STGM_SIZE (4 << GMID_EL1_BS) |
151 | +static uint32_t arm_v7m_load_vector(ARMCPU *cpu, int exc, bool targets_secure) | 116 | - |
117 | uint64_t HELPER(ldgm)(CPUARMState *env, uint64_t ptr) | ||
152 | { | 118 | { |
153 | CPUState *cs = CPU(cpu); | 119 | int mmu_idx = cpu_mmu_index(env, false); |
154 | CPUARMState *env = &cpu->env; | 120 | uintptr_t ra = GETPC(); |
155 | MemTxResult result; | 121 | + int gm_bs = env_archcpu(env)->gm_blocksize; |
156 | - hwaddr vec = env->v7m.vecbase[targets_secure] + env->v7m.exception * 4; | 122 | + int gm_bs_bytes = 4 << gm_bs; |
157 | + hwaddr vec = env->v7m.vecbase[targets_secure] + exc * 4; | 123 | void *tag_mem; |
158 | uint32_t addr; | 124 | |
159 | 125 | - ptr = QEMU_ALIGN_DOWN(ptr, LDGM_STGM_SIZE); | |
160 | addr = address_space_ldl(cs->as, vec, | 126 | + ptr = QEMU_ALIGN_DOWN(ptr, gm_bs_bytes); |
161 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain) | 127 | |
162 | CPUARMState *env = &cpu->env; | 128 | /* Trap if accessing an invalid page. */ |
163 | uint32_t addr; | 129 | tag_mem = allocation_tag_mem(env, mmu_idx, ptr, MMU_DATA_LOAD, |
164 | bool targets_secure; | 130 | - LDGM_STGM_SIZE, MMU_DATA_LOAD, |
165 | + int exc; | 131 | - LDGM_STGM_SIZE / (2 * TAG_GRANULE), ra); |
166 | 132 | + gm_bs_bytes, MMU_DATA_LOAD, | |
167 | - targets_secure = armv7m_nvic_acknowledge_irq(env->nvic); | 133 | + gm_bs_bytes / (2 * TAG_GRANULE), ra); |
168 | + armv7m_nvic_get_pending_irq_info(env->nvic, &exc, &targets_secure); | 134 | |
169 | 135 | /* The tag is squashed to zero if the page does not support tags. */ | |
170 | if (arm_feature(env, ARM_FEATURE_V8)) { | 136 | if (!tag_mem) { |
171 | if (arm_feature(env, ARM_FEATURE_M_SECURITY) && | 137 | return 0; |
172 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain) | ||
173 | } | ||
174 | } | 138 | } |
175 | 139 | ||
176 | + addr = arm_v7m_load_vector(cpu, exc, targets_secure); | 140 | - QEMU_BUILD_BUG_ON(GMID_EL1_BS != 6); |
177 | + | 141 | /* |
178 | + /* Now we've done everything that might cause a derived exception | 142 | - * We are loading 64-bits worth of tags. The ordering of elements |
179 | + * we can go ahead and activate whichever exception we're going to | 143 | - * within the word corresponds to a 64-bit little-endian operation. |
180 | + * take (which might now be the derived exception). | 144 | + * The ordering of elements within the word corresponds to |
181 | + */ | 145 | + * a little-endian operation. |
182 | + armv7m_nvic_acknowledge_irq(env->nvic); | 146 | */ |
183 | + | 147 | - return ldq_le_p(tag_mem); |
184 | /* Switch to target security state -- must do this before writing SPSEL */ | 148 | + switch (gm_bs) { |
185 | switch_v7m_security_state(env, targets_secure); | 149 | + case 6: |
186 | write_v7m_control_spsel(env, 0); | 150 | + /* 256 bytes -> 16 tags -> 64 result bits */ |
187 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain) | 151 | + return ldq_le_p(tag_mem); |
188 | /* Clear IT bits */ | 152 | + default: |
189 | env->condexec_bits = 0; | 153 | + /* cpu configured with unsupported gm blocksize. */ |
190 | env->regs[14] = lr; | 154 | + g_assert_not_reached(); |
191 | - addr = arm_v7m_load_vector(cpu, targets_secure); | 155 | + } |
192 | env->regs[15] = addr & 0xfffffffe; | ||
193 | env->thumb = addr & 1; | ||
194 | } | 156 | } |
195 | diff --git a/hw/intc/trace-events b/hw/intc/trace-events | 157 | |
196 | index XXXXXXX..XXXXXXX 100644 | 158 | void HELPER(stgm)(CPUARMState *env, uint64_t ptr, uint64_t val) |
197 | --- a/hw/intc/trace-events | 159 | { |
198 | +++ b/hw/intc/trace-events | 160 | int mmu_idx = cpu_mmu_index(env, false); |
199 | @@ -XXX,XX +XXX,XX @@ nvic_escalate_disabled(int irq) "NVIC escalating irq %d to HardFault: disabled" | 161 | uintptr_t ra = GETPC(); |
200 | nvic_set_pending(int irq, bool secure, bool derived, int en, int prio) "NVIC set pending irq %d secure-bank %d derived %d (enabled: %d priority %d)" | 162 | + int gm_bs = env_archcpu(env)->gm_blocksize; |
201 | nvic_clear_pending(int irq, bool secure, int en, int prio) "NVIC clear pending irq %d secure-bank %d (enabled: %d priority %d)" | 163 | + int gm_bs_bytes = 4 << gm_bs; |
202 | nvic_set_pending_level(int irq) "NVIC set pending: irq %d higher prio than vectpending: setting irq line to 1" | 164 | void *tag_mem; |
203 | -nvic_acknowledge_irq(int irq, int prio, bool targets_secure) "NVIC acknowledge IRQ: %d now active (prio %d targets_secure %d)" | 165 | |
204 | +nvic_acknowledge_irq(int irq, int prio) "NVIC acknowledge IRQ: %d now active (prio %d)" | 166 | - ptr = QEMU_ALIGN_DOWN(ptr, LDGM_STGM_SIZE); |
205 | +nvic_get_pending_irq_info(int irq, bool secure) "NVIC next IRQ %d: targets_secure: %d" | 167 | + ptr = QEMU_ALIGN_DOWN(ptr, gm_bs_bytes); |
206 | nvic_complete_irq(int irq, bool secure) "NVIC complete IRQ %d (secure %d)" | 168 | |
207 | nvic_set_irq_level(int irq, int level) "NVIC external irq %d level set to %d" | 169 | /* Trap if accessing an invalid page. */ |
208 | nvic_sysreg_read(uint64_t addr, uint32_t value, unsigned size) "NVIC sysreg read addr 0x%" PRIx64 " data 0x%" PRIx32 " size %u" | 170 | tag_mem = allocation_tag_mem(env, mmu_idx, ptr, MMU_DATA_STORE, |
171 | - LDGM_STGM_SIZE, MMU_DATA_LOAD, | ||
172 | - LDGM_STGM_SIZE / (2 * TAG_GRANULE), ra); | ||
173 | + gm_bs_bytes, MMU_DATA_LOAD, | ||
174 | + gm_bs_bytes / (2 * TAG_GRANULE), ra); | ||
175 | |||
176 | /* | ||
177 | * Tag store only happens if the page support tags, | ||
178 | @@ -XXX,XX +XXX,XX @@ void HELPER(stgm)(CPUARMState *env, uint64_t ptr, uint64_t val) | ||
179 | return; | ||
180 | } | ||
181 | |||
182 | - QEMU_BUILD_BUG_ON(GMID_EL1_BS != 6); | ||
183 | /* | ||
184 | - * We are storing 64-bits worth of tags. The ordering of elements | ||
185 | - * within the word corresponds to a 64-bit little-endian operation. | ||
186 | + * The ordering of elements within the word corresponds to | ||
187 | + * a little-endian operation. | ||
188 | */ | ||
189 | - stq_le_p(tag_mem, val); | ||
190 | + switch (gm_bs) { | ||
191 | + case 6: | ||
192 | + stq_le_p(tag_mem, val); | ||
193 | + break; | ||
194 | + default: | ||
195 | + /* cpu configured with unsupported gm blocksize. */ | ||
196 | + g_assert_not_reached(); | ||
197 | + } | ||
198 | } | ||
199 | |||
200 | void HELPER(stzgm_tags)(CPUARMState *env, uint64_t ptr, uint64_t val) | ||
201 | diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c | ||
202 | index XXXXXXX..XXXXXXX 100644 | ||
203 | --- a/target/arm/tcg/translate-a64.c | ||
204 | +++ b/target/arm/tcg/translate-a64.c | ||
205 | @@ -XXX,XX +XXX,XX @@ static bool trans_STGM(DisasContext *s, arg_ldst_tag *a) | ||
206 | gen_helper_stgm(cpu_env, addr, tcg_rt); | ||
207 | } else { | ||
208 | MMUAccessType acc = MMU_DATA_STORE; | ||
209 | - int size = 4 << GMID_EL1_BS; | ||
210 | + int size = 4 << s->gm_blocksize; | ||
211 | |||
212 | clean_addr = clean_data_tbi(s, addr); | ||
213 | tcg_gen_andi_i64(clean_addr, clean_addr, -size); | ||
214 | @@ -XXX,XX +XXX,XX @@ static bool trans_LDGM(DisasContext *s, arg_ldst_tag *a) | ||
215 | gen_helper_ldgm(tcg_rt, cpu_env, addr); | ||
216 | } else { | ||
217 | MMUAccessType acc = MMU_DATA_LOAD; | ||
218 | - int size = 4 << GMID_EL1_BS; | ||
219 | + int size = 4 << s->gm_blocksize; | ||
220 | |||
221 | clean_addr = clean_data_tbi(s, addr); | ||
222 | tcg_gen_andi_i64(clean_addr, clean_addr, -size); | ||
223 | @@ -XXX,XX +XXX,XX @@ static void aarch64_tr_init_disas_context(DisasContextBase *dcbase, | ||
224 | dc->cp_regs = arm_cpu->cp_regs; | ||
225 | dc->features = env->features; | ||
226 | dc->dcz_blocksize = arm_cpu->dcz_blocksize; | ||
227 | + dc->gm_blocksize = arm_cpu->gm_blocksize; | ||
228 | |||
229 | #ifdef CONFIG_USER_ONLY | ||
230 | /* In sve_probe_page, we assume TBI is enabled. */ | ||
209 | -- | 231 | -- |
210 | 2.16.1 | 232 | 2.34.1 |
211 | |||
212 | diff view generated by jsdifflib |
1 | Make the load of the exception vector from the vector table honour | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | the SAU and any bus error on the load (possibly provoking a derived | ||
3 | exception), rather than simply aborting if the load fails. | ||
4 | 2 | ||
3 | Support all of the easy GM block sizes. | ||
4 | Use direct memory operations, since the pointers are aligned. | ||
5 | |||
6 | While BS=2 (16 bytes, 1 tag) is a legal setting, that requires | ||
7 | an atomic store of one nibble. This is not difficult, but there | ||
8 | is also no point in supporting it until required. | ||
9 | |||
10 | Note that cortex-a710 sets GM blocksize to match its cacheline | ||
11 | size of 64 bytes. I expect many implementations will also | ||
12 | match the cacheline, which makes 16 bytes very unlikely. | ||
13 | |||
14 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
15 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
16 | Message-id: 20230811214031.171020-4-richard.henderson@linaro.org | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 1517324542-6607-7-git-send-email-peter.maydell@linaro.org | ||
8 | --- | 18 | --- |
9 | target/arm/helper.c | 71 +++++++++++++++++++++++++++++++++++++++++------------ | 19 | target/arm/cpu.c | 18 +++++++++--- |
10 | 1 file changed, 55 insertions(+), 16 deletions(-) | 20 | target/arm/tcg/mte_helper.c | 56 +++++++++++++++++++++++++++++++------ |
21 | 2 files changed, 62 insertions(+), 12 deletions(-) | ||
11 | 22 | ||
12 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 23 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c |
13 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/target/arm/helper.c | 25 | --- a/target/arm/cpu.c |
15 | +++ b/target/arm/helper.c | 26 | +++ b/target/arm/cpu.c |
16 | @@ -XXX,XX +XXX,XX @@ static uint32_t *get_v7m_sp_ptr(CPUARMState *env, bool secure, bool threadmode, | 27 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) |
28 | ID_PFR1, VIRTUALIZATION, 0); | ||
17 | } | 29 | } |
30 | |||
31 | + if (cpu_isar_feature(aa64_mte, cpu)) { | ||
32 | + /* | ||
33 | + * The architectural range of GM blocksize is 2-6, however qemu | ||
34 | + * doesn't support blocksize of 2 (see HELPER(ldgm)). | ||
35 | + */ | ||
36 | + if (tcg_enabled()) { | ||
37 | + assert(cpu->gm_blocksize >= 3 && cpu->gm_blocksize <= 6); | ||
38 | + } | ||
39 | + | ||
40 | #ifndef CONFIG_USER_ONLY | ||
41 | - if (cpu->tag_memory == NULL && cpu_isar_feature(aa64_mte, cpu)) { | ||
42 | /* | ||
43 | * Disable the MTE feature bits if we do not have tag-memory | ||
44 | * provided by the machine. | ||
45 | */ | ||
46 | - cpu->isar.id_aa64pfr1 = | ||
47 | - FIELD_DP64(cpu->isar.id_aa64pfr1, ID_AA64PFR1, MTE, 0); | ||
48 | - } | ||
49 | + if (cpu->tag_memory == NULL) { | ||
50 | + cpu->isar.id_aa64pfr1 = | ||
51 | + FIELD_DP64(cpu->isar.id_aa64pfr1, ID_AA64PFR1, MTE, 0); | ||
52 | + } | ||
53 | #endif | ||
54 | + } | ||
55 | |||
56 | if (tcg_enabled()) { | ||
57 | /* | ||
58 | diff --git a/target/arm/tcg/mte_helper.c b/target/arm/tcg/mte_helper.c | ||
59 | index XXXXXXX..XXXXXXX 100644 | ||
60 | --- a/target/arm/tcg/mte_helper.c | ||
61 | +++ b/target/arm/tcg/mte_helper.c | ||
62 | @@ -XXX,XX +XXX,XX @@ uint64_t HELPER(ldgm)(CPUARMState *env, uint64_t ptr) | ||
63 | int gm_bs = env_archcpu(env)->gm_blocksize; | ||
64 | int gm_bs_bytes = 4 << gm_bs; | ||
65 | void *tag_mem; | ||
66 | + uint64_t ret; | ||
67 | + int shift; | ||
68 | |||
69 | ptr = QEMU_ALIGN_DOWN(ptr, gm_bs_bytes); | ||
70 | |||
71 | @@ -XXX,XX +XXX,XX @@ uint64_t HELPER(ldgm)(CPUARMState *env, uint64_t ptr) | ||
72 | |||
73 | /* | ||
74 | * The ordering of elements within the word corresponds to | ||
75 | - * a little-endian operation. | ||
76 | + * a little-endian operation. Computation of shift comes from | ||
77 | + * | ||
78 | + * index = address<LOG2_TAG_GRANULE+3:LOG2_TAG_GRANULE> | ||
79 | + * data<index*4+3:index*4> = tag | ||
80 | + * | ||
81 | + * Because of the alignment of ptr above, BS=6 has shift=0. | ||
82 | + * All memory operations are aligned. Defer support for BS=2, | ||
83 | + * requiring insertion or extraction of a nibble, until we | ||
84 | + * support a cpu that requires it. | ||
85 | */ | ||
86 | switch (gm_bs) { | ||
87 | + case 3: | ||
88 | + /* 32 bytes -> 2 tags -> 8 result bits */ | ||
89 | + ret = *(uint8_t *)tag_mem; | ||
90 | + break; | ||
91 | + case 4: | ||
92 | + /* 64 bytes -> 4 tags -> 16 result bits */ | ||
93 | + ret = cpu_to_le16(*(uint16_t *)tag_mem); | ||
94 | + break; | ||
95 | + case 5: | ||
96 | + /* 128 bytes -> 8 tags -> 32 result bits */ | ||
97 | + ret = cpu_to_le32(*(uint32_t *)tag_mem); | ||
98 | + break; | ||
99 | case 6: | ||
100 | /* 256 bytes -> 16 tags -> 64 result bits */ | ||
101 | - return ldq_le_p(tag_mem); | ||
102 | + return cpu_to_le64(*(uint64_t *)tag_mem); | ||
103 | default: | ||
104 | - /* cpu configured with unsupported gm blocksize. */ | ||
105 | + /* | ||
106 | + * CPU configured with unsupported/invalid gm blocksize. | ||
107 | + * This is detected early in arm_cpu_realizefn. | ||
108 | + */ | ||
109 | g_assert_not_reached(); | ||
110 | } | ||
111 | + shift = extract64(ptr, LOG2_TAG_GRANULE, 4) * 4; | ||
112 | + return ret << shift; | ||
18 | } | 113 | } |
19 | 114 | ||
20 | -static uint32_t arm_v7m_load_vector(ARMCPU *cpu, int exc, bool targets_secure) | 115 | void HELPER(stgm)(CPUARMState *env, uint64_t ptr, uint64_t val) |
21 | +static bool arm_v7m_load_vector(ARMCPU *cpu, int exc, bool targets_secure, | 116 | @@ -XXX,XX +XXX,XX @@ void HELPER(stgm)(CPUARMState *env, uint64_t ptr, uint64_t val) |
22 | + uint32_t *pvec) | 117 | int gm_bs = env_archcpu(env)->gm_blocksize; |
23 | { | 118 | int gm_bs_bytes = 4 << gm_bs; |
24 | CPUState *cs = CPU(cpu); | 119 | void *tag_mem; |
25 | CPUARMState *env = &cpu->env; | 120 | + int shift; |
26 | MemTxResult result; | 121 | |
27 | - hwaddr vec = env->v7m.vecbase[targets_secure] + exc * 4; | 122 | ptr = QEMU_ALIGN_DOWN(ptr, gm_bs_bytes); |
28 | - uint32_t addr; | 123 | |
29 | + uint32_t addr = env->v7m.vecbase[targets_secure] + exc * 4; | 124 | @@ -XXX,XX +XXX,XX @@ void HELPER(stgm)(CPUARMState *env, uint64_t ptr, uint64_t val) |
30 | + uint32_t vector_entry; | ||
31 | + MemTxAttrs attrs = {}; | ||
32 | + ARMMMUIdx mmu_idx; | ||
33 | + bool exc_secure; | ||
34 | + | ||
35 | + mmu_idx = arm_v7m_mmu_idx_for_secstate_and_priv(env, targets_secure, true); | ||
36 | |||
37 | - addr = address_space_ldl(cs->as, vec, | ||
38 | - MEMTXATTRS_UNSPECIFIED, &result); | ||
39 | + /* We don't do a get_phys_addr() here because the rules for vector | ||
40 | + * loads are special: they always use the default memory map, and | ||
41 | + * the default memory map permits reads from all addresses. | ||
42 | + * Since there's no easy way to pass through to pmsav8_mpu_lookup() | ||
43 | + * that we want this special case which would always say "yes", | ||
44 | + * we just do the SAU lookup here followed by a direct physical load. | ||
45 | + */ | ||
46 | + attrs.secure = targets_secure; | ||
47 | + attrs.user = false; | ||
48 | + | ||
49 | + if (arm_feature(env, ARM_FEATURE_M_SECURITY)) { | ||
50 | + V8M_SAttributes sattrs = {}; | ||
51 | + | ||
52 | + v8m_security_lookup(env, addr, MMU_DATA_LOAD, mmu_idx, &sattrs); | ||
53 | + if (sattrs.ns) { | ||
54 | + attrs.secure = false; | ||
55 | + } else if (!targets_secure) { | ||
56 | + /* NS access to S memory */ | ||
57 | + goto load_fail; | ||
58 | + } | ||
59 | + } | ||
60 | + | ||
61 | + vector_entry = address_space_ldl(arm_addressspace(cs, attrs), addr, | ||
62 | + attrs, &result); | ||
63 | if (result != MEMTX_OK) { | ||
64 | - /* Architecturally this should cause a HardFault setting HSFR.VECTTBL, | ||
65 | - * which would then be immediately followed by our failing to load | ||
66 | - * the entry vector for that HardFault, which is a Lockup case. | ||
67 | - * Since we don't model Lockup, we just report this guest error | ||
68 | - * via cpu_abort(). | ||
69 | - */ | ||
70 | - cpu_abort(cs, "Failed to read from %s exception vector table " | ||
71 | - "entry %08x\n", targets_secure ? "secure" : "nonsecure", | ||
72 | - (unsigned)vec); | ||
73 | + goto load_fail; | ||
74 | } | ||
75 | - return addr; | ||
76 | + *pvec = vector_entry; | ||
77 | + return true; | ||
78 | + | ||
79 | +load_fail: | ||
80 | + /* All vector table fetch fails are reported as HardFault, with | ||
81 | + * HFSR.VECTTBL and .FORCED set. (FORCED is set because | ||
82 | + * technically the underlying exception is a MemManage or BusFault | ||
83 | + * that is escalated to HardFault.) This is a terminal exception, | ||
84 | + * so we will either take the HardFault immediately or else enter | ||
85 | + * lockup (the latter case is handled in armv7m_nvic_set_pending_derived()). | ||
86 | + */ | ||
87 | + exc_secure = targets_secure || | ||
88 | + !(cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK); | ||
89 | + env->v7m.hfsr |= R_V7M_HFSR_VECTTBL_MASK | R_V7M_HFSR_FORCED_MASK; | ||
90 | + armv7m_nvic_set_pending_derived(env->nvic, ARMV7M_EXCP_HARD, exc_secure); | ||
91 | + return false; | ||
92 | } | ||
93 | |||
94 | static bool v7m_push_callee_stack(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
95 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
96 | return; | 125 | return; |
97 | } | 126 | } |
98 | 127 | ||
99 | - addr = arm_v7m_load_vector(cpu, exc, targets_secure); | 128 | - /* |
100 | + if (!arm_v7m_load_vector(cpu, exc, targets_secure, &addr)) { | 129 | - * The ordering of elements within the word corresponds to |
101 | + /* Vector load failed: derived exception */ | 130 | - * a little-endian operation. |
102 | + v7m_exception_taken(cpu, lr, true, true); | 131 | - */ |
103 | + return; | 132 | + /* See LDGM for comments on BS and on shift. */ |
104 | + } | 133 | + shift = extract64(ptr, LOG2_TAG_GRANULE, 4) * 4; |
105 | 134 | + val >>= shift; | |
106 | /* Now we've done everything that might cause a derived exception | 135 | switch (gm_bs) { |
107 | * we can go ahead and activate whichever exception we're going to | 136 | + case 3: |
137 | + /* 32 bytes -> 2 tags -> 8 result bits */ | ||
138 | + *(uint8_t *)tag_mem = val; | ||
139 | + break; | ||
140 | + case 4: | ||
141 | + /* 64 bytes -> 4 tags -> 16 result bits */ | ||
142 | + *(uint16_t *)tag_mem = cpu_to_le16(val); | ||
143 | + break; | ||
144 | + case 5: | ||
145 | + /* 128 bytes -> 8 tags -> 32 result bits */ | ||
146 | + *(uint32_t *)tag_mem = cpu_to_le32(val); | ||
147 | + break; | ||
148 | case 6: | ||
149 | - stq_le_p(tag_mem, val); | ||
150 | + /* 256 bytes -> 16 tags -> 64 result bits */ | ||
151 | + *(uint64_t *)tag_mem = cpu_to_le64(val); | ||
152 | break; | ||
153 | default: | ||
154 | /* cpu configured with unsupported gm blocksize. */ | ||
108 | -- | 155 | -- |
109 | 2.16.1 | 156 | 2.34.1 |
110 | |||
111 | diff view generated by jsdifflib |
1 | From: Christoffer Dall <christoffer.dall@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | KVM doesn't support emulating a GICv3 in userspace, only GICv2. We | 3 | When the cpu support MTE, but the system does not, reduce cpu |
4 | currently attempt this anyway, and as a result a KVM guest doesn't | 4 | support to user instructions at EL0 instead of completely |
5 | receive interrupts and the user is left wondering why. Report an error | 5 | disabling MTE. If we encounter a cpu implementation which does |
6 | to the user if this particular combination is requested. | 6 | something else, we can revisit this setting. |
7 | 7 | ||
8 | Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org> | 8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
10 | Message-id: 20180201205307.30343-1-christoffer.dall@linaro.org | 10 | Message-id: 20230811214031.171020-5-richard.henderson@linaro.org |
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
12 | --- | 12 | --- |
13 | target/arm/kvm_arm.h | 4 ++++ | 13 | target/arm/cpu.c | 7 ++++--- |
14 | 1 file changed, 4 insertions(+) | 14 | 1 file changed, 4 insertions(+), 3 deletions(-) |
15 | 15 | ||
16 | diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h | 16 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c |
17 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/arm/kvm_arm.h | 18 | --- a/target/arm/cpu.c |
19 | +++ b/target/arm/kvm_arm.h | 19 | +++ b/target/arm/cpu.c |
20 | @@ -XXX,XX +XXX,XX @@ static inline const char *gicv3_class_name(void) | 20 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) |
21 | exit(1); | 21 | |
22 | #ifndef CONFIG_USER_ONLY | ||
23 | /* | ||
24 | - * Disable the MTE feature bits if we do not have tag-memory | ||
25 | - * provided by the machine. | ||
26 | + * If we do not have tag-memory provided by the machine, | ||
27 | + * reduce MTE support to instructions enabled at EL0. | ||
28 | + * This matches Cortex-A710 BROADCASTMTE input being LOW. | ||
29 | */ | ||
30 | if (cpu->tag_memory == NULL) { | ||
31 | cpu->isar.id_aa64pfr1 = | ||
32 | - FIELD_DP64(cpu->isar.id_aa64pfr1, ID_AA64PFR1, MTE, 0); | ||
33 | + FIELD_DP64(cpu->isar.id_aa64pfr1, ID_AA64PFR1, MTE, 1); | ||
34 | } | ||
22 | #endif | 35 | #endif |
23 | } else { | ||
24 | + if (kvm_enabled()) { | ||
25 | + error_report("Userspace GICv3 is not supported with KVM"); | ||
26 | + exit(1); | ||
27 | + } | ||
28 | return "arm-gicv3"; | ||
29 | } | 36 | } |
30 | } | ||
31 | -- | 37 | -- |
32 | 2.16.1 | 38 | 2.34.1 |
33 | |||
34 | diff view generated by jsdifflib |
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Add minimal code needed to allow upstream Linux guest to boot. | 3 | Do not hard-code the constants for Neoverse V1. |
4 | 4 | ||
5 | Cc: Peter Maydell <peter.maydell@linaro.org> | 5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
6 | Cc: Jason Wang <jasowang@redhat.com> | ||
7 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | ||
9 | Cc: Michael S. Tsirkin <mst@redhat.com> | ||
10 | Cc: qemu-devel@nongnu.org | ||
11 | Cc: qemu-arm@nongnu.org | ||
12 | Cc: yurovsky@gmail.com | ||
13 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
14 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | 7 | Message-id: 20230811214031.171020-6-richard.henderson@linaro.org |
15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
16 | --- | 9 | --- |
17 | hw/misc/Makefile.objs | 1 + | 10 | target/arm/tcg/cpu64.c | 48 ++++++++++++++++++++++++++++-------------- |
18 | include/hw/misc/imx7_ccm.h | 139 +++++++++++++++++++++++ | 11 | 1 file changed, 32 insertions(+), 16 deletions(-) |
19 | hw/misc/imx7_ccm.c | 277 +++++++++++++++++++++++++++++++++++++++++++++ | ||
20 | 3 files changed, 417 insertions(+) | ||
21 | create mode 100644 include/hw/misc/imx7_ccm.h | ||
22 | create mode 100644 hw/misc/imx7_ccm.c | ||
23 | 12 | ||
24 | diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs | 13 | diff --git a/target/arm/tcg/cpu64.c b/target/arm/tcg/cpu64.c |
25 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/hw/misc/Makefile.objs | 15 | --- a/target/arm/tcg/cpu64.c |
27 | +++ b/hw/misc/Makefile.objs | 16 | +++ b/target/arm/tcg/cpu64.c |
28 | @@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_IMX) += imx31_ccm.o | ||
29 | obj-$(CONFIG_IMX) += imx25_ccm.o | ||
30 | obj-$(CONFIG_IMX) += imx6_ccm.o | ||
31 | obj-$(CONFIG_IMX) += imx6_src.o | ||
32 | +obj-$(CONFIG_IMX) += imx7_ccm.o | ||
33 | obj-$(CONFIG_MILKYMIST) += milkymist-hpdmc.o | ||
34 | obj-$(CONFIG_MILKYMIST) += milkymist-pfpu.o | ||
35 | obj-$(CONFIG_MAINSTONE) += mst_fpga.o | ||
36 | diff --git a/include/hw/misc/imx7_ccm.h b/include/hw/misc/imx7_ccm.h | ||
37 | new file mode 100644 | ||
38 | index XXXXXXX..XXXXXXX | ||
39 | --- /dev/null | ||
40 | +++ b/include/hw/misc/imx7_ccm.h | ||
41 | @@ -XXX,XX +XXX,XX @@ | 17 | @@ -XXX,XX +XXX,XX @@ |
42 | +/* | 18 | #include "qemu/module.h" |
43 | + * Copyright (c) 2017, Impinj, Inc. | 19 | #include "qapi/visitor.h" |
44 | + * | 20 | #include "hw/qdev-properties.h" |
45 | + * i.MX7 CCM, PMU and ANALOG IP blocks emulation code | 21 | +#include "qemu/units.h" |
46 | + * | 22 | #include "internals.h" |
47 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | 23 | #include "cpregs.h" |
48 | + * | 24 | |
49 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 25 | +static uint64_t make_ccsidr64(unsigned assoc, unsigned linesize, |
50 | + * See the COPYING file in the top-level directory. | 26 | + unsigned cachesize) |
51 | + */ | ||
52 | + | ||
53 | +#ifndef IMX7_CCM_H | ||
54 | +#define IMX7_CCM_H | ||
55 | + | ||
56 | +#include "hw/misc/imx_ccm.h" | ||
57 | +#include "qemu/bitops.h" | ||
58 | + | ||
59 | +enum IMX7AnalogRegisters { | ||
60 | + ANALOG_PLL_ARM, | ||
61 | + ANALOG_PLL_ARM_SET, | ||
62 | + ANALOG_PLL_ARM_CLR, | ||
63 | + ANALOG_PLL_ARM_TOG, | ||
64 | + ANALOG_PLL_DDR, | ||
65 | + ANALOG_PLL_DDR_SET, | ||
66 | + ANALOG_PLL_DDR_CLR, | ||
67 | + ANALOG_PLL_DDR_TOG, | ||
68 | + ANALOG_PLL_DDR_SS, | ||
69 | + ANALOG_PLL_DDR_SS_SET, | ||
70 | + ANALOG_PLL_DDR_SS_CLR, | ||
71 | + ANALOG_PLL_DDR_SS_TOG, | ||
72 | + ANALOG_PLL_DDR_NUM, | ||
73 | + ANALOG_PLL_DDR_NUM_SET, | ||
74 | + ANALOG_PLL_DDR_NUM_CLR, | ||
75 | + ANALOG_PLL_DDR_NUM_TOG, | ||
76 | + ANALOG_PLL_DDR_DENOM, | ||
77 | + ANALOG_PLL_DDR_DENOM_SET, | ||
78 | + ANALOG_PLL_DDR_DENOM_CLR, | ||
79 | + ANALOG_PLL_DDR_DENOM_TOG, | ||
80 | + ANALOG_PLL_480, | ||
81 | + ANALOG_PLL_480_SET, | ||
82 | + ANALOG_PLL_480_CLR, | ||
83 | + ANALOG_PLL_480_TOG, | ||
84 | + ANALOG_PLL_480A, | ||
85 | + ANALOG_PLL_480A_SET, | ||
86 | + ANALOG_PLL_480A_CLR, | ||
87 | + ANALOG_PLL_480A_TOG, | ||
88 | + ANALOG_PLL_480B, | ||
89 | + ANALOG_PLL_480B_SET, | ||
90 | + ANALOG_PLL_480B_CLR, | ||
91 | + ANALOG_PLL_480B_TOG, | ||
92 | + ANALOG_PLL_ENET, | ||
93 | + ANALOG_PLL_ENET_SET, | ||
94 | + ANALOG_PLL_ENET_CLR, | ||
95 | + ANALOG_PLL_ENET_TOG, | ||
96 | + ANALOG_PLL_AUDIO, | ||
97 | + ANALOG_PLL_AUDIO_SET, | ||
98 | + ANALOG_PLL_AUDIO_CLR, | ||
99 | + ANALOG_PLL_AUDIO_TOG, | ||
100 | + ANALOG_PLL_AUDIO_SS, | ||
101 | + ANALOG_PLL_AUDIO_SS_SET, | ||
102 | + ANALOG_PLL_AUDIO_SS_CLR, | ||
103 | + ANALOG_PLL_AUDIO_SS_TOG, | ||
104 | + ANALOG_PLL_AUDIO_NUM, | ||
105 | + ANALOG_PLL_AUDIO_NUM_SET, | ||
106 | + ANALOG_PLL_AUDIO_NUM_CLR, | ||
107 | + ANALOG_PLL_AUDIO_NUM_TOG, | ||
108 | + ANALOG_PLL_AUDIO_DENOM, | ||
109 | + ANALOG_PLL_AUDIO_DENOM_SET, | ||
110 | + ANALOG_PLL_AUDIO_DENOM_CLR, | ||
111 | + ANALOG_PLL_AUDIO_DENOM_TOG, | ||
112 | + ANALOG_PLL_VIDEO, | ||
113 | + ANALOG_PLL_VIDEO_SET, | ||
114 | + ANALOG_PLL_VIDEO_CLR, | ||
115 | + ANALOG_PLL_VIDEO_TOG, | ||
116 | + ANALOG_PLL_VIDEO_SS, | ||
117 | + ANALOG_PLL_VIDEO_SS_SET, | ||
118 | + ANALOG_PLL_VIDEO_SS_CLR, | ||
119 | + ANALOG_PLL_VIDEO_SS_TOG, | ||
120 | + ANALOG_PLL_VIDEO_NUM, | ||
121 | + ANALOG_PLL_VIDEO_NUM_SET, | ||
122 | + ANALOG_PLL_VIDEO_NUM_CLR, | ||
123 | + ANALOG_PLL_VIDEO_NUM_TOG, | ||
124 | + ANALOG_PLL_VIDEO_DENOM, | ||
125 | + ANALOG_PLL_VIDEO_DENOM_SET, | ||
126 | + ANALOG_PLL_VIDEO_DENOM_CLR, | ||
127 | + ANALOG_PLL_VIDEO_DENOM_TOG, | ||
128 | + ANALOG_PLL_MISC0, | ||
129 | + ANALOG_PLL_MISC0_SET, | ||
130 | + ANALOG_PLL_MISC0_CLR, | ||
131 | + ANALOG_PLL_MISC0_TOG, | ||
132 | + | ||
133 | + ANALOG_DIGPROG = 0x800 / sizeof(uint32_t), | ||
134 | + ANALOG_MAX, | ||
135 | + | ||
136 | + ANALOG_PLL_LOCK = BIT(31) | ||
137 | +}; | ||
138 | + | ||
139 | +enum IMX7CCMRegisters { | ||
140 | + CCM_MAX = 0xBE00 / sizeof(uint32_t) + 1, | ||
141 | +}; | ||
142 | + | ||
143 | +enum IMX7PMURegisters { | ||
144 | + PMU_MAX = 0x140 / sizeof(uint32_t), | ||
145 | +}; | ||
146 | + | ||
147 | +#define TYPE_IMX7_CCM "imx7.ccm" | ||
148 | +#define IMX7_CCM(obj) OBJECT_CHECK(IMX7CCMState, (obj), TYPE_IMX7_CCM) | ||
149 | + | ||
150 | +typedef struct IMX7CCMState { | ||
151 | + /* <private> */ | ||
152 | + IMXCCMState parent_obj; | ||
153 | + | ||
154 | + /* <public> */ | ||
155 | + MemoryRegion iomem; | ||
156 | + | ||
157 | + uint32_t ccm[CCM_MAX]; | ||
158 | +} IMX7CCMState; | ||
159 | + | ||
160 | + | ||
161 | +#define TYPE_IMX7_ANALOG "imx7.analog" | ||
162 | +#define IMX7_ANALOG(obj) OBJECT_CHECK(IMX7AnalogState, (obj), TYPE_IMX7_ANALOG) | ||
163 | + | ||
164 | +typedef struct IMX7AnalogState { | ||
165 | + /* <private> */ | ||
166 | + IMXCCMState parent_obj; | ||
167 | + | ||
168 | + /* <public> */ | ||
169 | + struct { | ||
170 | + MemoryRegion container; | ||
171 | + MemoryRegion analog; | ||
172 | + MemoryRegion digprog; | ||
173 | + MemoryRegion pmu; | ||
174 | + } mmio; | ||
175 | + | ||
176 | + uint32_t analog[ANALOG_MAX]; | ||
177 | + uint32_t pmu[PMU_MAX]; | ||
178 | +} IMX7AnalogState; | ||
179 | + | ||
180 | +#endif /* IMX7_CCM_H */ | ||
181 | diff --git a/hw/misc/imx7_ccm.c b/hw/misc/imx7_ccm.c | ||
182 | new file mode 100644 | ||
183 | index XXXXXXX..XXXXXXX | ||
184 | --- /dev/null | ||
185 | +++ b/hw/misc/imx7_ccm.c | ||
186 | @@ -XXX,XX +XXX,XX @@ | ||
187 | +/* | ||
188 | + * Copyright (c) 2018, Impinj, Inc. | ||
189 | + * | ||
190 | + * i.MX7 CCM, PMU and ANALOG IP blocks emulation code | ||
191 | + * | ||
192 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
193 | + * | ||
194 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
195 | + * See the COPYING file in the top-level directory. | ||
196 | + */ | ||
197 | + | ||
198 | +#include "qemu/osdep.h" | ||
199 | +#include "qemu/log.h" | ||
200 | + | ||
201 | +#include "hw/misc/imx7_ccm.h" | ||
202 | + | ||
203 | +static void imx7_analog_reset(DeviceState *dev) | ||
204 | +{ | 27 | +{ |
205 | + IMX7AnalogState *s = IMX7_ANALOG(dev); | 28 | + unsigned lg_linesize = ctz32(linesize); |
206 | + | 29 | + unsigned sets; |
207 | + memset(s->pmu, 0, sizeof(s->pmu)); | ||
208 | + memset(s->analog, 0, sizeof(s->analog)); | ||
209 | + | ||
210 | + s->analog[ANALOG_PLL_ARM] = 0x00002042; | ||
211 | + s->analog[ANALOG_PLL_DDR] = 0x0060302c; | ||
212 | + s->analog[ANALOG_PLL_DDR_SS] = 0x00000000; | ||
213 | + s->analog[ANALOG_PLL_DDR_NUM] = 0x06aaac4d; | ||
214 | + s->analog[ANALOG_PLL_DDR_DENOM] = 0x100003ec; | ||
215 | + s->analog[ANALOG_PLL_480] = 0x00002000; | ||
216 | + s->analog[ANALOG_PLL_480A] = 0x52605a56; | ||
217 | + s->analog[ANALOG_PLL_480B] = 0x52525216; | ||
218 | + s->analog[ANALOG_PLL_ENET] = 0x00001fc0; | ||
219 | + s->analog[ANALOG_PLL_AUDIO] = 0x0001301b; | ||
220 | + s->analog[ANALOG_PLL_AUDIO_SS] = 0x00000000; | ||
221 | + s->analog[ANALOG_PLL_AUDIO_NUM] = 0x05f5e100; | ||
222 | + s->analog[ANALOG_PLL_AUDIO_DENOM] = 0x2964619c; | ||
223 | + s->analog[ANALOG_PLL_VIDEO] = 0x0008201b; | ||
224 | + s->analog[ANALOG_PLL_VIDEO_SS] = 0x00000000; | ||
225 | + s->analog[ANALOG_PLL_VIDEO_NUM] = 0x0000f699; | ||
226 | + s->analog[ANALOG_PLL_VIDEO_DENOM] = 0x000f4240; | ||
227 | + s->analog[ANALOG_PLL_MISC0] = 0x00000000; | ||
228 | + | ||
229 | + /* all PLLs need to be locked */ | ||
230 | + s->analog[ANALOG_PLL_ARM] |= ANALOG_PLL_LOCK; | ||
231 | + s->analog[ANALOG_PLL_DDR] |= ANALOG_PLL_LOCK; | ||
232 | + s->analog[ANALOG_PLL_480] |= ANALOG_PLL_LOCK; | ||
233 | + s->analog[ANALOG_PLL_480A] |= ANALOG_PLL_LOCK; | ||
234 | + s->analog[ANALOG_PLL_480B] |= ANALOG_PLL_LOCK; | ||
235 | + s->analog[ANALOG_PLL_ENET] |= ANALOG_PLL_LOCK; | ||
236 | + s->analog[ANALOG_PLL_AUDIO] |= ANALOG_PLL_LOCK; | ||
237 | + s->analog[ANALOG_PLL_VIDEO] |= ANALOG_PLL_LOCK; | ||
238 | + s->analog[ANALOG_PLL_MISC0] |= ANALOG_PLL_LOCK; | ||
239 | + | 30 | + |
240 | + /* | 31 | + /* |
241 | + * Since I couldn't find any info about this in the reference | 32 | + * The 64-bit CCSIDR_EL1 format is: |
242 | + * manual the value of this register is based strictly on matching | 33 | + * [55:32] number of sets - 1 |
243 | + * what Linux kernel expects it to be. | 34 | + * [23:3] associativity - 1 |
35 | + * [2:0] log2(linesize) - 4 | ||
36 | + * so 0 == 16 bytes, 1 == 32 bytes, 2 == 64 bytes, etc | ||
244 | + */ | 37 | + */ |
245 | + s->analog[ANALOG_DIGPROG] = 0x720000; | 38 | + assert(assoc != 0); |
246 | + /* | 39 | + assert(is_power_of_2(linesize)); |
247 | + * Set revision to be 1.0 (Arbitrary choice, no particular | 40 | + assert(lg_linesize >= 4 && lg_linesize <= 7 + 4); |
248 | + * reason). | 41 | + |
249 | + */ | 42 | + /* sets * associativity * linesize == cachesize. */ |
250 | + s->analog[ANALOG_DIGPROG] |= 0x000010; | 43 | + sets = cachesize / (assoc * linesize); |
44 | + assert(cachesize % (assoc * linesize) == 0); | ||
45 | + | ||
46 | + return ((uint64_t)(sets - 1) << 32) | ||
47 | + | ((assoc - 1) << 3) | ||
48 | + | (lg_linesize - 4); | ||
251 | +} | 49 | +} |
252 | + | 50 | + |
253 | +static void imx7_ccm_reset(DeviceState *dev) | 51 | static void aarch64_a35_initfn(Object *obj) |
254 | +{ | 52 | { |
255 | + IMX7CCMState *s = IMX7_CCM(dev); | 53 | ARMCPU *cpu = ARM_CPU(obj); |
256 | + | 54 | @@ -XXX,XX +XXX,XX @@ static void aarch64_neoverse_v1_initfn(Object *obj) |
257 | + memset(s->ccm, 0, sizeof(s->ccm)); | 55 | * The Neoverse-V1 r1p2 TRM lists 32-bit format CCSIDR_EL1 values, |
258 | +} | 56 | * but also says it implements CCIDX, which means they should be |
259 | + | 57 | * 64-bit format. So we here use values which are based on the textual |
260 | +#define CCM_INDEX(offset) (((offset) & ~(hwaddr)0xF) / sizeof(uint32_t)) | 58 | - * information in chapter 2 of the TRM (and on the fact that |
261 | +#define CCM_BITOP(offset) ((offset) & (hwaddr)0xF) | 59 | - * sets * associativity * linesize == cachesize). |
262 | + | 60 | - * |
263 | +enum { | 61 | - * The 64-bit CCSIDR_EL1 format is: |
264 | + CCM_BITOP_NONE = 0x00, | 62 | - * [55:32] number of sets - 1 |
265 | + CCM_BITOP_SET = 0x04, | 63 | - * [23:3] associativity - 1 |
266 | + CCM_BITOP_CLR = 0x08, | 64 | - * [2:0] log2(linesize) - 4 |
267 | + CCM_BITOP_TOG = 0x0C, | 65 | - * so 0 == 16 bytes, 1 == 32 bytes, 2 == 64 bytes, etc |
268 | +}; | 66 | - * |
269 | + | 67 | - * L1: 4-way set associative 64-byte line size, total size 64K, |
270 | +static uint64_t imx7_set_clr_tog_read(void *opaque, hwaddr offset, | 68 | - * so sets is 256. |
271 | + unsigned size) | 69 | + * information in chapter 2 of the TRM: |
272 | +{ | 70 | * |
273 | + const uint32_t *mmio = opaque; | 71 | + * L1: 4-way set associative 64-byte line size, total size 64K. |
274 | + | 72 | * L2: 8-way set associative, 64 byte line size, either 512K or 1MB. |
275 | + return mmio[CCM_INDEX(offset)]; | 73 | - * We pick 1MB, so this has 2048 sets. |
276 | +} | 74 | - * |
277 | + | 75 | * L3: No L3 (this matches the CLIDR_EL1 value). |
278 | +static void imx7_set_clr_tog_write(void *opaque, hwaddr offset, | 76 | */ |
279 | + uint64_t value, unsigned size) | 77 | - cpu->ccsidr[0] = 0x000000ff0000001aull; /* 64KB L1 dcache */ |
280 | +{ | 78 | - cpu->ccsidr[1] = 0x000000ff0000001aull; /* 64KB L1 icache */ |
281 | + const uint8_t bitop = CCM_BITOP(offset); | 79 | - cpu->ccsidr[2] = 0x000007ff0000003aull; /* 1MB L2 cache */ |
282 | + const uint32_t index = CCM_INDEX(offset); | 80 | + cpu->ccsidr[0] = make_ccsidr64(4, 64, 64 * KiB); /* L1 dcache */ |
283 | + uint32_t *mmio = opaque; | 81 | + cpu->ccsidr[1] = cpu->ccsidr[0]; /* L1 icache */ |
284 | + | 82 | + cpu->ccsidr[2] = make_ccsidr64(8, 64, 1 * MiB); /* L2 cache */ |
285 | + switch (bitop) { | 83 | |
286 | + case CCM_BITOP_NONE: | 84 | /* From 3.2.115 SCTLR_EL3 */ |
287 | + mmio[index] = value; | 85 | cpu->reset_sctlr = 0x30c50838; |
288 | + break; | ||
289 | + case CCM_BITOP_SET: | ||
290 | + mmio[index] |= value; | ||
291 | + break; | ||
292 | + case CCM_BITOP_CLR: | ||
293 | + mmio[index] &= ~value; | ||
294 | + break; | ||
295 | + case CCM_BITOP_TOG: | ||
296 | + mmio[index] ^= value; | ||
297 | + break; | ||
298 | + }; | ||
299 | +} | ||
300 | + | ||
301 | +static const struct MemoryRegionOps imx7_set_clr_tog_ops = { | ||
302 | + .read = imx7_set_clr_tog_read, | ||
303 | + .write = imx7_set_clr_tog_write, | ||
304 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
305 | + .impl = { | ||
306 | + /* | ||
307 | + * Our device would not work correctly if the guest was doing | ||
308 | + * unaligned access. This might not be a limitation on the real | ||
309 | + * device but in practice there is no reason for a guest to access | ||
310 | + * this device unaligned. | ||
311 | + */ | ||
312 | + .min_access_size = 4, | ||
313 | + .max_access_size = 4, | ||
314 | + .unaligned = false, | ||
315 | + }, | ||
316 | +}; | ||
317 | + | ||
318 | +static const struct MemoryRegionOps imx7_digprog_ops = { | ||
319 | + .read = imx7_set_clr_tog_read, | ||
320 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
321 | + .impl = { | ||
322 | + .min_access_size = 4, | ||
323 | + .max_access_size = 4, | ||
324 | + .unaligned = false, | ||
325 | + }, | ||
326 | +}; | ||
327 | + | ||
328 | +static void imx7_ccm_init(Object *obj) | ||
329 | +{ | ||
330 | + SysBusDevice *sd = SYS_BUS_DEVICE(obj); | ||
331 | + IMX7CCMState *s = IMX7_CCM(obj); | ||
332 | + | ||
333 | + memory_region_init_io(&s->iomem, | ||
334 | + obj, | ||
335 | + &imx7_set_clr_tog_ops, | ||
336 | + s->ccm, | ||
337 | + TYPE_IMX7_CCM ".ccm", | ||
338 | + sizeof(s->ccm)); | ||
339 | + | ||
340 | + sysbus_init_mmio(sd, &s->iomem); | ||
341 | +} | ||
342 | + | ||
343 | +static void imx7_analog_init(Object *obj) | ||
344 | +{ | ||
345 | + SysBusDevice *sd = SYS_BUS_DEVICE(obj); | ||
346 | + IMX7AnalogState *s = IMX7_ANALOG(obj); | ||
347 | + | ||
348 | + memory_region_init(&s->mmio.container, obj, TYPE_IMX7_ANALOG, | ||
349 | + 0x10000); | ||
350 | + | ||
351 | + memory_region_init_io(&s->mmio.analog, | ||
352 | + obj, | ||
353 | + &imx7_set_clr_tog_ops, | ||
354 | + s->analog, | ||
355 | + TYPE_IMX7_ANALOG, | ||
356 | + sizeof(s->analog)); | ||
357 | + | ||
358 | + memory_region_add_subregion(&s->mmio.container, | ||
359 | + 0x60, &s->mmio.analog); | ||
360 | + | ||
361 | + memory_region_init_io(&s->mmio.pmu, | ||
362 | + obj, | ||
363 | + &imx7_set_clr_tog_ops, | ||
364 | + s->pmu, | ||
365 | + TYPE_IMX7_ANALOG ".pmu", | ||
366 | + sizeof(s->pmu)); | ||
367 | + | ||
368 | + memory_region_add_subregion(&s->mmio.container, | ||
369 | + 0x200, &s->mmio.pmu); | ||
370 | + | ||
371 | + memory_region_init_io(&s->mmio.digprog, | ||
372 | + obj, | ||
373 | + &imx7_digprog_ops, | ||
374 | + &s->analog[ANALOG_DIGPROG], | ||
375 | + TYPE_IMX7_ANALOG ".digprog", | ||
376 | + sizeof(uint32_t)); | ||
377 | + | ||
378 | + memory_region_add_subregion_overlap(&s->mmio.container, | ||
379 | + 0x800, &s->mmio.digprog, 10); | ||
380 | + | ||
381 | + | ||
382 | + sysbus_init_mmio(sd, &s->mmio.container); | ||
383 | +} | ||
384 | + | ||
385 | +static const VMStateDescription vmstate_imx7_ccm = { | ||
386 | + .name = TYPE_IMX7_CCM, | ||
387 | + .version_id = 1, | ||
388 | + .minimum_version_id = 1, | ||
389 | + .fields = (VMStateField[]) { | ||
390 | + VMSTATE_UINT32_ARRAY(ccm, IMX7CCMState, CCM_MAX), | ||
391 | + VMSTATE_END_OF_LIST() | ||
392 | + }, | ||
393 | +}; | ||
394 | + | ||
395 | +static uint32_t imx7_ccm_get_clock_frequency(IMXCCMState *dev, IMXClk clock) | ||
396 | +{ | ||
397 | + /* | ||
398 | + * This function is "consumed" by GPT emulation code, however on | ||
399 | + * i.MX7 each GPT block can have their own clock root. This means | ||
400 | + * that this functions needs somehow to know requester's identity | ||
401 | + * and the way to pass it: be it via additional IMXClk constants | ||
402 | + * or by adding another argument to this method needs to be | ||
403 | + * figured out | ||
404 | + */ | ||
405 | + qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: Not implemented\n", | ||
406 | + TYPE_IMX7_CCM, __func__); | ||
407 | + return 0; | ||
408 | +} | ||
409 | + | ||
410 | +static void imx7_ccm_class_init(ObjectClass *klass, void *data) | ||
411 | +{ | ||
412 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
413 | + IMXCCMClass *ccm = IMX_CCM_CLASS(klass); | ||
414 | + | ||
415 | + dc->reset = imx7_ccm_reset; | ||
416 | + dc->vmsd = &vmstate_imx7_ccm; | ||
417 | + dc->desc = "i.MX7 Clock Control Module"; | ||
418 | + | ||
419 | + ccm->get_clock_frequency = imx7_ccm_get_clock_frequency; | ||
420 | +} | ||
421 | + | ||
422 | +static const TypeInfo imx7_ccm_info = { | ||
423 | + .name = TYPE_IMX7_CCM, | ||
424 | + .parent = TYPE_IMX_CCM, | ||
425 | + .instance_size = sizeof(IMX7CCMState), | ||
426 | + .instance_init = imx7_ccm_init, | ||
427 | + .class_init = imx7_ccm_class_init, | ||
428 | +}; | ||
429 | + | ||
430 | +static const VMStateDescription vmstate_imx7_analog = { | ||
431 | + .name = TYPE_IMX7_ANALOG, | ||
432 | + .version_id = 1, | ||
433 | + .minimum_version_id = 1, | ||
434 | + .fields = (VMStateField[]) { | ||
435 | + VMSTATE_UINT32_ARRAY(analog, IMX7AnalogState, ANALOG_MAX), | ||
436 | + VMSTATE_UINT32_ARRAY(pmu, IMX7AnalogState, PMU_MAX), | ||
437 | + VMSTATE_END_OF_LIST() | ||
438 | + }, | ||
439 | +}; | ||
440 | + | ||
441 | +static void imx7_analog_class_init(ObjectClass *klass, void *data) | ||
442 | +{ | ||
443 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
444 | + | ||
445 | + dc->reset = imx7_analog_reset; | ||
446 | + dc->vmsd = &vmstate_imx7_analog; | ||
447 | + dc->desc = "i.MX7 Analog Module"; | ||
448 | +} | ||
449 | + | ||
450 | +static const TypeInfo imx7_analog_info = { | ||
451 | + .name = TYPE_IMX7_ANALOG, | ||
452 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
453 | + .instance_size = sizeof(IMX7AnalogState), | ||
454 | + .instance_init = imx7_analog_init, | ||
455 | + .class_init = imx7_analog_class_init, | ||
456 | +}; | ||
457 | + | ||
458 | +static void imx7_ccm_register_type(void) | ||
459 | +{ | ||
460 | + type_register_static(&imx7_ccm_info); | ||
461 | + type_register_static(&imx7_analog_info); | ||
462 | +} | ||
463 | +type_init(imx7_ccm_register_type) | ||
464 | -- | 86 | -- |
465 | 2.16.1 | 87 | 2.34.1 |
466 | |||
467 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Define ZCR_EL[1-3]. | 3 | Access to many of the special registers is enabled or disabled |
4 | by ACTLR_EL[23], which we implement as constant 0, which means | ||
5 | that all writes outside EL3 should trap. | ||
4 | 6 | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Message-id: 20180123035349.24538-5-richard.henderson@linaro.org | 9 | Message-id: 20230811214031.171020-7-richard.henderson@linaro.org |
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 11 | --- |
10 | target/arm/cpu.h | 5 ++ | 12 | target/arm/cpregs.h | 2 ++ |
11 | target/arm/helper.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++++ | 13 | target/arm/helper.c | 4 ++-- |
12 | 2 files changed, 136 insertions(+) | 14 | target/arm/tcg/cpu64.c | 46 +++++++++++++++++++++++++++++++++--------- |
15 | 3 files changed, 41 insertions(+), 11 deletions(-) | ||
13 | 16 | ||
14 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 17 | diff --git a/target/arm/cpregs.h b/target/arm/cpregs.h |
15 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/arm/cpu.h | 19 | --- a/target/arm/cpregs.h |
17 | +++ b/target/arm/cpu.h | 20 | +++ b/target/arm/cpregs.h |
18 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUARMState { | 21 | @@ -XXX,XX +XXX,XX @@ static inline void define_cortex_a72_a57_a53_cp_reginfo(ARMCPU *cpu) { } |
19 | */ | 22 | void define_cortex_a72_a57_a53_cp_reginfo(ARMCPU *cpu); |
20 | float_status fp_status; | 23 | #endif |
21 | float_status standard_fp_status; | 24 | |
25 | +CPAccessResult access_tvm_trvm(CPUARMState *, const ARMCPRegInfo *, bool); | ||
22 | + | 26 | + |
23 | + /* ZCR_EL[1-3] */ | 27 | #endif /* TARGET_ARM_CPREGS_H */ |
24 | + uint64_t zcr_el[4]; | ||
25 | } vfp; | ||
26 | uint64_t exclusive_addr; | ||
27 | uint64_t exclusive_val; | ||
28 | @@ -XXX,XX +XXX,XX @@ void pmccntr_sync(CPUARMState *env); | ||
29 | #define CPTR_TCPAC (1U << 31) | ||
30 | #define CPTR_TTA (1U << 20) | ||
31 | #define CPTR_TFP (1U << 10) | ||
32 | +#define CPTR_TZ (1U << 8) /* CPTR_EL2 */ | ||
33 | +#define CPTR_EZ (1U << 8) /* CPTR_EL3 */ | ||
34 | |||
35 | #define MDCR_EPMAD (1U << 21) | ||
36 | #define MDCR_EDAD (1U << 20) | ||
37 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 28 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
38 | index XXXXXXX..XXXXXXX 100644 | 29 | index XXXXXXX..XXXXXXX 100644 |
39 | --- a/target/arm/helper.c | 30 | --- a/target/arm/helper.c |
40 | +++ b/target/arm/helper.c | 31 | +++ b/target/arm/helper.c |
41 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo debug_lpae_cp_reginfo[] = { | 32 | @@ -XXX,XX +XXX,XX @@ static CPAccessResult access_tpm(CPUARMState *env, const ARMCPRegInfo *ri, |
42 | REGINFO_SENTINEL | 33 | } |
43 | }; | 34 | |
44 | 35 | /* Check for traps from EL1 due to HCR_EL2.TVM and HCR_EL2.TRVM. */ | |
45 | +/* Return the exception level to which SVE-disabled exceptions should | 36 | -static CPAccessResult access_tvm_trvm(CPUARMState *env, const ARMCPRegInfo *ri, |
46 | + * be taken, or 0 if SVE is enabled. | 37 | - bool isread) |
47 | + */ | 38 | +CPAccessResult access_tvm_trvm(CPUARMState *env, const ARMCPRegInfo *ri, |
48 | +static int sve_exception_el(CPUARMState *env) | 39 | + bool isread) |
40 | { | ||
41 | if (arm_current_el(env) == 1) { | ||
42 | uint64_t trap = isread ? HCR_TRVM : HCR_TVM; | ||
43 | diff --git a/target/arm/tcg/cpu64.c b/target/arm/tcg/cpu64.c | ||
44 | index XXXXXXX..XXXXXXX 100644 | ||
45 | --- a/target/arm/tcg/cpu64.c | ||
46 | +++ b/target/arm/tcg/cpu64.c | ||
47 | @@ -XXX,XX +XXX,XX @@ static void aarch64_a64fx_initfn(Object *obj) | ||
48 | /* TODO: Add A64FX specific HPC extension registers */ | ||
49 | } | ||
50 | |||
51 | +static CPAccessResult access_actlr_w(CPUARMState *env, const ARMCPRegInfo *r, | ||
52 | + bool read) | ||
49 | +{ | 53 | +{ |
50 | +#ifndef CONFIG_USER_ONLY | 54 | + if (!read) { |
51 | + unsigned current_el = arm_current_el(env); | 55 | + int el = arm_current_el(env); |
52 | + | 56 | + |
53 | + /* The CPACR.ZEN controls traps to EL1: | 57 | + /* Because ACTLR_EL2 is constant 0, writes below EL2 trap to EL2. */ |
54 | + * 0, 2 : trap EL0 and EL1 accesses | 58 | + if (el < 2 && arm_is_el2_enabled(env)) { |
55 | + * 1 : trap only EL0 accesses | 59 | + return CP_ACCESS_TRAP_EL2; |
56 | + * 3 : trap no accesses | ||
57 | + */ | ||
58 | + switch (extract32(env->cp15.cpacr_el1, 16, 2)) { | ||
59 | + default: | ||
60 | + if (current_el <= 1) { | ||
61 | + /* Trap to PL1, which might be EL1 or EL3 */ | ||
62 | + if (arm_is_secure(env) && !arm_el_is_aa64(env, 3)) { | ||
63 | + return 3; | ||
64 | + } | ||
65 | + return 1; | ||
66 | + } | 60 | + } |
67 | + break; | 61 | + /* Because ACTLR_EL3 is constant 0, writes below EL3 trap to EL3. */ |
68 | + case 1: | 62 | + if (el < 3 && arm_feature(env, ARM_FEATURE_EL3)) { |
69 | + if (current_el == 0) { | 63 | + return CP_ACCESS_TRAP_EL3; |
70 | + return 1; | ||
71 | + } | 64 | + } |
72 | + break; | ||
73 | + case 3: | ||
74 | + break; | ||
75 | + } | ||
76 | + | ||
77 | + /* Similarly for CPACR.FPEN, after having checked ZEN. */ | ||
78 | + switch (extract32(env->cp15.cpacr_el1, 20, 2)) { | ||
79 | + default: | ||
80 | + if (current_el <= 1) { | ||
81 | + if (arm_is_secure(env) && !arm_el_is_aa64(env, 3)) { | ||
82 | + return 3; | ||
83 | + } | ||
84 | + return 1; | ||
85 | + } | ||
86 | + break; | ||
87 | + case 1: | ||
88 | + if (current_el == 0) { | ||
89 | + return 1; | ||
90 | + } | ||
91 | + break; | ||
92 | + case 3: | ||
93 | + break; | ||
94 | + } | ||
95 | + | ||
96 | + /* CPTR_EL2. Check both TZ and TFP. */ | ||
97 | + if (current_el <= 2 | ||
98 | + && (env->cp15.cptr_el[2] & (CPTR_TFP | CPTR_TZ)) | ||
99 | + && !arm_is_secure_below_el3(env)) { | ||
100 | + return 2; | ||
101 | + } | ||
102 | + | ||
103 | + /* CPTR_EL3. Check both EZ and TFP. */ | ||
104 | + if (!(env->cp15.cptr_el[3] & CPTR_EZ) | ||
105 | + || (env->cp15.cptr_el[3] & CPTR_TFP)) { | ||
106 | + return 3; | ||
107 | + } | ||
108 | +#endif | ||
109 | + return 0; | ||
110 | +} | ||
111 | + | ||
112 | +static CPAccessResult zcr_access(CPUARMState *env, const ARMCPRegInfo *ri, | ||
113 | + bool isread) | ||
114 | +{ | ||
115 | + switch (sve_exception_el(env)) { | ||
116 | + case 3: | ||
117 | + return CP_ACCESS_TRAP_EL3; | ||
118 | + case 2: | ||
119 | + return CP_ACCESS_TRAP_EL2; | ||
120 | + case 1: | ||
121 | + return CP_ACCESS_TRAP; | ||
122 | + } | 65 | + } |
123 | + return CP_ACCESS_OK; | 66 | + return CP_ACCESS_OK; |
124 | +} | 67 | +} |
125 | + | 68 | + |
126 | +static void zcr_write(CPUARMState *env, const ARMCPRegInfo *ri, | 69 | static const ARMCPRegInfo neoverse_n1_cp_reginfo[] = { |
127 | + uint64_t value) | 70 | { .name = "ATCR_EL1", .state = ARM_CP_STATE_AA64, |
128 | +{ | 71 | .opc0 = 3, .opc1 = 0, .crn = 15, .crm = 7, .opc2 = 0, |
129 | + /* Bits other than [3:0] are RAZ/WI. */ | 72 | - .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 }, |
130 | + raw_write(env, ri, value & 0xf); | 73 | + .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0, |
131 | +} | 74 | + /* Traps and enables are the same as for TCR_EL1. */ |
132 | + | 75 | + .accessfn = access_tvm_trvm, .fgt = FGT_TCR_EL1, }, |
133 | +static const ARMCPRegInfo zcr_el1_reginfo = { | 76 | { .name = "ATCR_EL2", .state = ARM_CP_STATE_AA64, |
134 | + .name = "ZCR_EL1", .state = ARM_CP_STATE_AA64, | 77 | .opc0 = 3, .opc1 = 4, .crn = 15, .crm = 7, .opc2 = 0, |
135 | + .opc0 = 3, .opc1 = 0, .crn = 1, .crm = 2, .opc2 = 0, | 78 | .access = PL2_RW, .type = ARM_CP_CONST, .resetvalue = 0 }, |
136 | + .access = PL1_RW, .accessfn = zcr_access, .type = ARM_CP_64BIT, | 79 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo neoverse_n1_cp_reginfo[] = { |
137 | + .fieldoffset = offsetof(CPUARMState, vfp.zcr_el[1]), | 80 | .access = PL2_RW, .type = ARM_CP_CONST, .resetvalue = 0 }, |
138 | + .writefn = zcr_write, .raw_writefn = raw_write | 81 | { .name = "CPUACTLR_EL1", .state = ARM_CP_STATE_AA64, |
139 | +}; | 82 | .opc0 = 3, .opc1 = 0, .crn = 15, .crm = 1, .opc2 = 0, |
140 | + | 83 | - .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 }, |
141 | +static const ARMCPRegInfo zcr_el2_reginfo = { | 84 | + .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0, |
142 | + .name = "ZCR_EL2", .state = ARM_CP_STATE_AA64, | 85 | + .accessfn = access_actlr_w }, |
143 | + .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 2, .opc2 = 0, | 86 | { .name = "CPUACTLR2_EL1", .state = ARM_CP_STATE_AA64, |
144 | + .access = PL2_RW, .accessfn = zcr_access, .type = ARM_CP_64BIT, | 87 | .opc0 = 3, .opc1 = 0, .crn = 15, .crm = 1, .opc2 = 1, |
145 | + .fieldoffset = offsetof(CPUARMState, vfp.zcr_el[2]), | 88 | - .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 }, |
146 | + .writefn = zcr_write, .raw_writefn = raw_write | 89 | + .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0, |
147 | +}; | 90 | + .accessfn = access_actlr_w }, |
148 | + | 91 | { .name = "CPUACTLR3_EL1", .state = ARM_CP_STATE_AA64, |
149 | +static const ARMCPRegInfo zcr_no_el2_reginfo = { | 92 | .opc0 = 3, .opc1 = 0, .crn = 15, .crm = 1, .opc2 = 2, |
150 | + .name = "ZCR_EL2", .state = ARM_CP_STATE_AA64, | 93 | - .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 }, |
151 | + .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 2, .opc2 = 0, | 94 | + .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0, |
152 | + .access = PL2_RW, .type = ARM_CP_64BIT, | 95 | + .accessfn = access_actlr_w }, |
153 | + .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore | 96 | /* |
154 | +}; | 97 | * Report CPUCFR_EL1.SCU as 1, as we do not implement the DSU |
155 | + | 98 | * (and in particular its system registers). |
156 | +static const ARMCPRegInfo zcr_el3_reginfo = { | 99 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo neoverse_n1_cp_reginfo[] = { |
157 | + .name = "ZCR_EL3", .state = ARM_CP_STATE_AA64, | 100 | .access = PL1_R, .type = ARM_CP_CONST, .resetvalue = 4 }, |
158 | + .opc0 = 3, .opc1 = 6, .crn = 1, .crm = 2, .opc2 = 0, | 101 | { .name = "CPUECTLR_EL1", .state = ARM_CP_STATE_AA64, |
159 | + .access = PL3_RW, .accessfn = zcr_access, .type = ARM_CP_64BIT, | 102 | .opc0 = 3, .opc1 = 0, .crn = 15, .crm = 1, .opc2 = 4, |
160 | + .fieldoffset = offsetof(CPUARMState, vfp.zcr_el[3]), | 103 | - .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0x961563010 }, |
161 | + .writefn = zcr_write, .raw_writefn = raw_write | 104 | + .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0x961563010, |
162 | +}; | 105 | + .accessfn = access_actlr_w }, |
163 | + | 106 | { .name = "CPUPCR_EL3", .state = ARM_CP_STATE_AA64, |
164 | void hw_watchpoint_update(ARMCPU *cpu, int n) | 107 | .opc0 = 3, .opc1 = 6, .crn = 15, .crm = 8, .opc2 = 1, |
165 | { | 108 | .access = PL3_RW, .type = ARM_CP_CONST, .resetvalue = 0 }, |
166 | CPUARMState *env = &cpu->env; | 109 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo neoverse_n1_cp_reginfo[] = { |
167 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | 110 | .access = PL3_RW, .type = ARM_CP_CONST, .resetvalue = 0 }, |
168 | } | 111 | { .name = "CPUPWRCTLR_EL1", .state = ARM_CP_STATE_AA64, |
169 | define_one_arm_cp_reg(cpu, &sctlr); | 112 | .opc0 = 3, .opc1 = 0, .crn = 15, .crm = 2, .opc2 = 7, |
170 | } | 113 | - .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 }, |
171 | + | 114 | + .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0, |
172 | + if (arm_feature(env, ARM_FEATURE_SVE)) { | 115 | + .accessfn = access_actlr_w }, |
173 | + define_one_arm_cp_reg(cpu, &zcr_el1_reginfo); | 116 | { .name = "ERXPFGCDN_EL1", .state = ARM_CP_STATE_AA64, |
174 | + if (arm_feature(env, ARM_FEATURE_EL2)) { | 117 | .opc0 = 3, .opc1 = 0, .crn = 15, .crm = 2, .opc2 = 2, |
175 | + define_one_arm_cp_reg(cpu, &zcr_el2_reginfo); | 118 | - .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 }, |
176 | + } else { | 119 | + .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0, |
177 | + define_one_arm_cp_reg(cpu, &zcr_no_el2_reginfo); | 120 | + .accessfn = access_actlr_w }, |
178 | + } | 121 | { .name = "ERXPFGCTL_EL1", .state = ARM_CP_STATE_AA64, |
179 | + if (arm_feature(env, ARM_FEATURE_EL3)) { | 122 | .opc0 = 3, .opc1 = 0, .crn = 15, .crm = 2, .opc2 = 1, |
180 | + define_one_arm_cp_reg(cpu, &zcr_el3_reginfo); | 123 | - .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 }, |
181 | + } | 124 | + .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0, |
182 | + } | 125 | + .accessfn = access_actlr_w }, |
183 | } | 126 | { .name = "ERXPFGF_EL1", .state = ARM_CP_STATE_AA64, |
184 | 127 | .opc0 = 3, .opc1 = 0, .crn = 15, .crm = 2, .opc2 = 0, | |
185 | void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu) | 128 | - .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 }, |
129 | + .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0, | ||
130 | + .accessfn = access_actlr_w }, | ||
131 | }; | ||
132 | |||
133 | static void define_neoverse_n1_cp_reginfo(ARMCPU *cpu) | ||
186 | -- | 134 | -- |
187 | 2.16.1 | 135 | 2.34.1 |
188 | |||
189 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Add both SVE exception state and vector length. | 3 | There is only one additional EL1 register modeled, which |
4 | also needs to use access_actlr_w. | ||
4 | 5 | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Message-id: 20180123035349.24538-6-richard.henderson@linaro.org | 8 | Message-id: 20230811214031.171020-8-richard.henderson@linaro.org |
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 10 | --- |
10 | target/arm/cpu.h | 8 ++++++++ | 11 | target/arm/tcg/cpu64.c | 3 ++- |
11 | target/arm/translate.h | 2 ++ | 12 | 1 file changed, 2 insertions(+), 1 deletion(-) |
12 | target/arm/helper.c | 25 ++++++++++++++++++++++++- | ||
13 | target/arm/translate-a64.c | 2 ++ | ||
14 | 4 files changed, 36 insertions(+), 1 deletion(-) | ||
15 | 13 | ||
16 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 14 | diff --git a/target/arm/tcg/cpu64.c b/target/arm/tcg/cpu64.c |
17 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/arm/cpu.h | 16 | --- a/target/arm/tcg/cpu64.c |
19 | +++ b/target/arm/cpu.h | 17 | +++ b/target/arm/tcg/cpu64.c |
20 | @@ -XXX,XX +XXX,XX @@ static inline bool arm_cpu_data_is_big_endian(CPUARMState *env) | 18 | @@ -XXX,XX +XXX,XX @@ static void define_neoverse_n1_cp_reginfo(ARMCPU *cpu) |
21 | #define ARM_TBFLAG_TBI0_MASK (0x1ull << ARM_TBFLAG_TBI0_SHIFT) | 19 | static const ARMCPRegInfo neoverse_v1_cp_reginfo[] = { |
22 | #define ARM_TBFLAG_TBI1_SHIFT 1 /* TBI1 for EL0/1 */ | 20 | { .name = "CPUECTLR2_EL1", .state = ARM_CP_STATE_AA64, |
23 | #define ARM_TBFLAG_TBI1_MASK (0x1ull << ARM_TBFLAG_TBI1_SHIFT) | 21 | .opc0 = 3, .opc1 = 0, .crn = 15, .crm = 1, .opc2 = 5, |
24 | +#define ARM_TBFLAG_SVEEXC_EL_SHIFT 2 | 22 | - .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 }, |
25 | +#define ARM_TBFLAG_SVEEXC_EL_MASK (0x3 << ARM_TBFLAG_SVEEXC_EL_SHIFT) | 23 | + .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0, |
26 | +#define ARM_TBFLAG_ZCR_LEN_SHIFT 4 | 24 | + .accessfn = access_actlr_w }, |
27 | +#define ARM_TBFLAG_ZCR_LEN_MASK (0xf << ARM_TBFLAG_ZCR_LEN_SHIFT) | 25 | { .name = "CPUPPMCR_EL3", .state = ARM_CP_STATE_AA64, |
28 | 26 | .opc0 = 3, .opc1 = 6, .crn = 15, .crm = 2, .opc2 = 0, | |
29 | /* some convenience accessor macros */ | 27 | .access = PL3_RW, .type = ARM_CP_CONST, .resetvalue = 0 }, |
30 | #define ARM_TBFLAG_AARCH64_STATE(F) \ | ||
31 | @@ -XXX,XX +XXX,XX @@ static inline bool arm_cpu_data_is_big_endian(CPUARMState *env) | ||
32 | (((F) & ARM_TBFLAG_TBI0_MASK) >> ARM_TBFLAG_TBI0_SHIFT) | ||
33 | #define ARM_TBFLAG_TBI1(F) \ | ||
34 | (((F) & ARM_TBFLAG_TBI1_MASK) >> ARM_TBFLAG_TBI1_SHIFT) | ||
35 | +#define ARM_TBFLAG_SVEEXC_EL(F) \ | ||
36 | + (((F) & ARM_TBFLAG_SVEEXC_EL_MASK) >> ARM_TBFLAG_SVEEXC_EL_SHIFT) | ||
37 | +#define ARM_TBFLAG_ZCR_LEN(F) \ | ||
38 | + (((F) & ARM_TBFLAG_ZCR_LEN_MASK) >> ARM_TBFLAG_ZCR_LEN_SHIFT) | ||
39 | |||
40 | static inline bool bswap_code(bool sctlr_b) | ||
41 | { | ||
42 | diff --git a/target/arm/translate.h b/target/arm/translate.h | ||
43 | index XXXXXXX..XXXXXXX 100644 | ||
44 | --- a/target/arm/translate.h | ||
45 | +++ b/target/arm/translate.h | ||
46 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { | ||
47 | bool tbi1; /* TBI1 for EL0/1, not used for EL2/3 */ | ||
48 | bool ns; /* Use non-secure CPREG bank on access */ | ||
49 | int fp_excp_el; /* FP exception EL or 0 if enabled */ | ||
50 | + int sve_excp_el; /* SVE exception EL or 0 if enabled */ | ||
51 | + int sve_len; /* SVE vector length in bytes */ | ||
52 | /* Flag indicating that exceptions from secure mode are routed to EL3. */ | ||
53 | bool secure_routed_to_el3; | ||
54 | bool vfp_enabled; /* FP enabled via FPSCR.EN */ | ||
55 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
56 | index XXXXXXX..XXXXXXX 100644 | ||
57 | --- a/target/arm/helper.c | ||
58 | +++ b/target/arm/helper.c | ||
59 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, | ||
60 | target_ulong *cs_base, uint32_t *pflags) | ||
61 | { | ||
62 | ARMMMUIdx mmu_idx = core_to_arm_mmu_idx(env, cpu_mmu_index(env, false)); | ||
63 | + int fp_el = fp_exception_el(env); | ||
64 | uint32_t flags; | ||
65 | |||
66 | if (is_a64(env)) { | ||
67 | + int sve_el = sve_exception_el(env); | ||
68 | + uint32_t zcr_len; | ||
69 | + | ||
70 | *pc = env->pc; | ||
71 | flags = ARM_TBFLAG_AARCH64_STATE_MASK; | ||
72 | /* Get control bits for tagged addresses */ | ||
73 | flags |= (arm_regime_tbi0(env, mmu_idx) << ARM_TBFLAG_TBI0_SHIFT); | ||
74 | flags |= (arm_regime_tbi1(env, mmu_idx) << ARM_TBFLAG_TBI1_SHIFT); | ||
75 | + flags |= sve_el << ARM_TBFLAG_SVEEXC_EL_SHIFT; | ||
76 | + | ||
77 | + /* If SVE is disabled, but FP is enabled, | ||
78 | + then the effective len is 0. */ | ||
79 | + if (sve_el != 0 && fp_el == 0) { | ||
80 | + zcr_len = 0; | ||
81 | + } else { | ||
82 | + int current_el = arm_current_el(env); | ||
83 | + | ||
84 | + zcr_len = env->vfp.zcr_el[current_el <= 1 ? 1 : current_el]; | ||
85 | + zcr_len &= 0xf; | ||
86 | + if (current_el < 2 && arm_feature(env, ARM_FEATURE_EL2)) { | ||
87 | + zcr_len = MIN(zcr_len, 0xf & (uint32_t)env->vfp.zcr_el[2]); | ||
88 | + } | ||
89 | + if (current_el < 3 && arm_feature(env, ARM_FEATURE_EL3)) { | ||
90 | + zcr_len = MIN(zcr_len, 0xf & (uint32_t)env->vfp.zcr_el[3]); | ||
91 | + } | ||
92 | + } | ||
93 | + flags |= zcr_len << ARM_TBFLAG_ZCR_LEN_SHIFT; | ||
94 | } else { | ||
95 | *pc = env->regs[15]; | ||
96 | flags = (env->thumb << ARM_TBFLAG_THUMB_SHIFT) | ||
97 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, | ||
98 | if (arm_cpu_data_is_big_endian(env)) { | ||
99 | flags |= ARM_TBFLAG_BE_DATA_MASK; | ||
100 | } | ||
101 | - flags |= fp_exception_el(env) << ARM_TBFLAG_FPEXC_EL_SHIFT; | ||
102 | + flags |= fp_el << ARM_TBFLAG_FPEXC_EL_SHIFT; | ||
103 | |||
104 | if (arm_v7m_is_handler_mode(env)) { | ||
105 | flags |= ARM_TBFLAG_HANDLER_MASK; | ||
106 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
107 | index XXXXXXX..XXXXXXX 100644 | ||
108 | --- a/target/arm/translate-a64.c | ||
109 | +++ b/target/arm/translate-a64.c | ||
110 | @@ -XXX,XX +XXX,XX @@ static int aarch64_tr_init_disas_context(DisasContextBase *dcbase, | ||
111 | dc->user = (dc->current_el == 0); | ||
112 | #endif | ||
113 | dc->fp_excp_el = ARM_TBFLAG_FPEXC_EL(dc->base.tb->flags); | ||
114 | + dc->sve_excp_el = ARM_TBFLAG_SVEEXC_EL(dc->base.tb->flags); | ||
115 | + dc->sve_len = (ARM_TBFLAG_ZCR_LEN(dc->base.tb->flags) + 1) * 16; | ||
116 | dc->vec_len = 0; | ||
117 | dc->vec_stride = 0; | ||
118 | dc->cp_regs = arm_cpu->cp_regs; | ||
119 | -- | 28 | -- |
120 | 2.16.1 | 29 | 2.34.1 |
121 | |||
122 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Save the high parts of the Zregs and all of the Pregs. | 3 | Like FEAT_TRF (Self-hosted Trace Extension), suppress tracing |
4 | The ZCR_ELx registers are migrated via the CP mechanism. | 4 | external to the cpu, which is out of scope for QEMU. |
5 | 5 | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Message-id: 20180123035349.24538-4-richard.henderson@linaro.org | 8 | Message-id: 20230811214031.171020-10-richard.henderson@linaro.org |
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 10 | --- |
12 | target/arm/machine.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ | 11 | target/arm/cpu.c | 3 +++ |
13 | 1 file changed, 53 insertions(+) | 12 | 1 file changed, 3 insertions(+) |
14 | 13 | ||
15 | diff --git a/target/arm/machine.c b/target/arm/machine.c | 14 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c |
16 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/machine.c | 16 | --- a/target/arm/cpu.c |
18 | +++ b/target/arm/machine.c | 17 | +++ b/target/arm/cpu.c |
19 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_iwmmxt = { | 18 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) |
20 | } | 19 | /* FEAT_SPE (Statistical Profiling Extension) */ |
21 | }; | 20 | cpu->isar.id_aa64dfr0 = |
22 | 21 | FIELD_DP64(cpu->isar.id_aa64dfr0, ID_AA64DFR0, PMSVER, 0); | |
23 | +#ifdef TARGET_AARCH64 | 22 | + /* FEAT_TRBE (Trace Buffer Extension) */ |
24 | +/* The expression ARM_MAX_VQ - 2 is 0 for pure AArch32 build, | 23 | + cpu->isar.id_aa64dfr0 = |
25 | + * and ARMPredicateReg is actively empty. This triggers errors | 24 | + FIELD_DP64(cpu->isar.id_aa64dfr0, ID_AA64DFR0, TRACEBUFFER, 0); |
26 | + * in the expansion of the VMSTATE macros. | 25 | /* FEAT_TRF (Self-hosted Trace Extension) */ |
27 | + */ | 26 | cpu->isar.id_aa64dfr0 = |
28 | + | 27 | FIELD_DP64(cpu->isar.id_aa64dfr0, ID_AA64DFR0, TRACEFILT, 0); |
29 | +static bool sve_needed(void *opaque) | ||
30 | +{ | ||
31 | + ARMCPU *cpu = opaque; | ||
32 | + CPUARMState *env = &cpu->env; | ||
33 | + | ||
34 | + return arm_feature(env, ARM_FEATURE_SVE); | ||
35 | +} | ||
36 | + | ||
37 | +/* The first two words of each Zreg is stored in VFP state. */ | ||
38 | +static const VMStateDescription vmstate_zreg_hi_reg = { | ||
39 | + .name = "cpu/sve/zreg_hi", | ||
40 | + .version_id = 1, | ||
41 | + .minimum_version_id = 1, | ||
42 | + .fields = (VMStateField[]) { | ||
43 | + VMSTATE_UINT64_SUB_ARRAY(d, ARMVectorReg, 2, ARM_MAX_VQ - 2), | ||
44 | + VMSTATE_END_OF_LIST() | ||
45 | + } | ||
46 | +}; | ||
47 | + | ||
48 | +static const VMStateDescription vmstate_preg_reg = { | ||
49 | + .name = "cpu/sve/preg", | ||
50 | + .version_id = 1, | ||
51 | + .minimum_version_id = 1, | ||
52 | + .fields = (VMStateField[]) { | ||
53 | + VMSTATE_UINT64_ARRAY(p, ARMPredicateReg, 2 * ARM_MAX_VQ / 8), | ||
54 | + VMSTATE_END_OF_LIST() | ||
55 | + } | ||
56 | +}; | ||
57 | + | ||
58 | +static const VMStateDescription vmstate_sve = { | ||
59 | + .name = "cpu/sve", | ||
60 | + .version_id = 1, | ||
61 | + .minimum_version_id = 1, | ||
62 | + .needed = sve_needed, | ||
63 | + .fields = (VMStateField[]) { | ||
64 | + VMSTATE_STRUCT_ARRAY(env.vfp.zregs, ARMCPU, 32, 0, | ||
65 | + vmstate_zreg_hi_reg, ARMVectorReg), | ||
66 | + VMSTATE_STRUCT_ARRAY(env.vfp.pregs, ARMCPU, 17, 0, | ||
67 | + vmstate_preg_reg, ARMPredicateReg), | ||
68 | + VMSTATE_END_OF_LIST() | ||
69 | + } | ||
70 | +}; | ||
71 | +#endif /* AARCH64 */ | ||
72 | + | ||
73 | static bool m_needed(void *opaque) | ||
74 | { | ||
75 | ARMCPU *cpu = opaque; | ||
76 | @@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_arm_cpu = { | ||
77 | &vmstate_pmsav7, | ||
78 | &vmstate_pmsav8, | ||
79 | &vmstate_m_security, | ||
80 | +#ifdef TARGET_AARCH64 | ||
81 | + &vmstate_sve, | ||
82 | +#endif | ||
83 | NULL | ||
84 | } | ||
85 | }; | ||
86 | -- | 28 | -- |
87 | 2.16.1 | 29 | 2.34.1 |
88 | |||
89 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Change vfp.regs as a uint64_t to vfp.zregs as an ARMVectorReg. | 3 | This feature allows the operating system to set TCR_ELx.HWU* |
4 | The previous patches have made the change in representation | 4 | to allow the implementation to use the PBHA bits from the |
5 | relatively painless. | 5 | block and page descriptors for for IMPLEMENTATION DEFINED |
6 | purposes. Since QEMU has no need to use these bits, we may | ||
7 | simply ignore them. | ||
6 | 8 | ||
7 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
10 | Message-id: 20180123035349.24538-2-richard.henderson@linaro.org | 11 | Message-id: 20230811214031.171020-11-richard.henderson@linaro.org |
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
12 | --- | 13 | --- |
13 | target/arm/cpu.h | 59 +++++++++++++++++++++++++++++++--------------- | 14 | docs/system/arm/emulation.rst | 1 + |
14 | target/arm/machine.c | 35 ++++++++++++++++++++++++++- | 15 | target/arm/tcg/cpu32.c | 2 +- |
15 | target/arm/translate-a64.c | 8 +++---- | 16 | target/arm/tcg/cpu64.c | 2 +- |
16 | target/arm/translate.c | 7 +++--- | 17 | 3 files changed, 3 insertions(+), 2 deletions(-) |
17 | 4 files changed, 81 insertions(+), 28 deletions(-) | ||
18 | 18 | ||
19 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 19 | diff --git a/docs/system/arm/emulation.rst b/docs/system/arm/emulation.rst |
20 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/arm/cpu.h | 21 | --- a/docs/system/arm/emulation.rst |
22 | +++ b/target/arm/cpu.h | 22 | +++ b/docs/system/arm/emulation.rst |
23 | @@ -XXX,XX +XXX,XX @@ typedef struct { | 23 | @@ -XXX,XX +XXX,XX @@ the following architecture extensions: |
24 | uint32_t base_mask; | 24 | - FEAT_HAFDBS (Hardware management of the access flag and dirty bit state) |
25 | } TCR; | 25 | - FEAT_HCX (Support for the HCRX_EL2 register) |
26 | 26 | - FEAT_HPDS (Hierarchical permission disables) | |
27 | +/* Define a maximum sized vector register. | 27 | +- FEAT_HPDS2 (Translation table page-based hardware attributes) |
28 | + * For 32-bit, this is a 128-bit NEON/AdvSIMD register. | 28 | - FEAT_I8MM (AArch64 Int8 matrix multiplication instructions) |
29 | + * For 64-bit, this is a 2048-bit SVE register. | 29 | - FEAT_IDST (ID space trap handling) |
30 | + * | 30 | - FEAT_IESB (Implicit error synchronization event) |
31 | + * Note that the mapping between S, D, and Q views of the register bank | 31 | diff --git a/target/arm/tcg/cpu32.c b/target/arm/tcg/cpu32.c |
32 | + * differs between AArch64 and AArch32. | ||
33 | + * In AArch32: | ||
34 | + * Qn = regs[n].d[1]:regs[n].d[0] | ||
35 | + * Dn = regs[n / 2].d[n & 1] | ||
36 | + * Sn = regs[n / 4].d[n % 4 / 2], | ||
37 | + * bits 31..0 for even n, and bits 63..32 for odd n | ||
38 | + * (and regs[16] to regs[31] are inaccessible) | ||
39 | + * In AArch64: | ||
40 | + * Zn = regs[n].d[*] | ||
41 | + * Qn = regs[n].d[1]:regs[n].d[0] | ||
42 | + * Dn = regs[n].d[0] | ||
43 | + * Sn = regs[n].d[0] bits 31..0 | ||
44 | + * | ||
45 | + * This corresponds to the architecturally defined mapping between | ||
46 | + * the two execution states, and means we do not need to explicitly | ||
47 | + * map these registers when changing states. | ||
48 | + * | ||
49 | + * Align the data for use with TCG host vector operations. | ||
50 | + */ | ||
51 | + | ||
52 | +#ifdef TARGET_AARCH64 | ||
53 | +# define ARM_MAX_VQ 16 | ||
54 | +#else | ||
55 | +# define ARM_MAX_VQ 1 | ||
56 | +#endif | ||
57 | + | ||
58 | +typedef struct ARMVectorReg { | ||
59 | + uint64_t d[2 * ARM_MAX_VQ] QEMU_ALIGNED(16); | ||
60 | +} ARMVectorReg; | ||
61 | + | ||
62 | + | ||
63 | typedef struct CPUARMState { | ||
64 | /* Regs for current mode. */ | ||
65 | uint32_t regs[16]; | ||
66 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUARMState { | ||
67 | |||
68 | /* VFP coprocessor state. */ | ||
69 | struct { | ||
70 | - /* VFP/Neon register state. Note that the mapping between S, D and Q | ||
71 | - * views of the register bank differs between AArch64 and AArch32: | ||
72 | - * In AArch32: | ||
73 | - * Qn = regs[2n+1]:regs[2n] | ||
74 | - * Dn = regs[n] | ||
75 | - * Sn = regs[n/2] bits 31..0 for even n, and bits 63..32 for odd n | ||
76 | - * (and regs[32] to regs[63] are inaccessible) | ||
77 | - * In AArch64: | ||
78 | - * Qn = regs[2n+1]:regs[2n] | ||
79 | - * Dn = regs[2n] | ||
80 | - * Sn = regs[2n] bits 31..0 | ||
81 | - * This corresponds to the architecturally defined mapping between | ||
82 | - * the two execution states, and means we do not need to explicitly | ||
83 | - * map these registers when changing states. | ||
84 | - */ | ||
85 | - uint64_t regs[64] QEMU_ALIGNED(16); | ||
86 | + ARMVectorReg zregs[32]; | ||
87 | |||
88 | uint32_t xregs[16]; | ||
89 | /* We store these fpcsr fields separately for convenience. */ | ||
90 | @@ -XXX,XX +XXX,XX @@ static inline void *arm_get_el_change_hook_opaque(ARMCPU *cpu) | ||
91 | */ | ||
92 | static inline uint64_t *aa32_vfp_dreg(CPUARMState *env, unsigned regno) | ||
93 | { | ||
94 | - return &env->vfp.regs[regno]; | ||
95 | + return &env->vfp.zregs[regno >> 1].d[regno & 1]; | ||
96 | } | ||
97 | |||
98 | /** | ||
99 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t *aa32_vfp_dreg(CPUARMState *env, unsigned regno) | ||
100 | */ | ||
101 | static inline uint64_t *aa32_vfp_qreg(CPUARMState *env, unsigned regno) | ||
102 | { | ||
103 | - return &env->vfp.regs[2 * regno]; | ||
104 | + return &env->vfp.zregs[regno].d[0]; | ||
105 | } | ||
106 | |||
107 | /** | ||
108 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t *aa32_vfp_qreg(CPUARMState *env, unsigned regno) | ||
109 | */ | ||
110 | static inline uint64_t *aa64_vfp_qreg(CPUARMState *env, unsigned regno) | ||
111 | { | ||
112 | - return &env->vfp.regs[2 * regno]; | ||
113 | + return &env->vfp.zregs[regno].d[0]; | ||
114 | } | ||
115 | |||
116 | #endif | ||
117 | diff --git a/target/arm/machine.c b/target/arm/machine.c | ||
118 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
119 | --- a/target/arm/machine.c | 33 | --- a/target/arm/tcg/cpu32.c |
120 | +++ b/target/arm/machine.c | 34 | +++ b/target/arm/tcg/cpu32.c |
121 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_vfp = { | 35 | @@ -XXX,XX +XXX,XX @@ void aa32_max_features(ARMCPU *cpu) |
122 | .minimum_version_id = 3, | 36 | cpu->isar.id_mmfr3 = t; |
123 | .needed = vfp_needed, | 37 | |
124 | .fields = (VMStateField[]) { | 38 | t = cpu->isar.id_mmfr4; |
125 | - VMSTATE_UINT64_ARRAY(env.vfp.regs, ARMCPU, 64), | 39 | - t = FIELD_DP32(t, ID_MMFR4, HPDS, 1); /* FEAT_AA32HPD */ |
126 | + /* For compatibility, store Qn out of Zn here. */ | 40 | + t = FIELD_DP32(t, ID_MMFR4, HPDS, 2); /* FEAT_HPDS2 */ |
127 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[0].d, ARMCPU, 0, 2), | 41 | t = FIELD_DP32(t, ID_MMFR4, AC2, 1); /* ACTLR2, HACTLR2 */ |
128 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[1].d, ARMCPU, 0, 2), | 42 | t = FIELD_DP32(t, ID_MMFR4, CNP, 1); /* FEAT_TTCNP */ |
129 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[2].d, ARMCPU, 0, 2), | 43 | t = FIELD_DP32(t, ID_MMFR4, XNX, 1); /* FEAT_XNX */ |
130 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[3].d, ARMCPU, 0, 2), | 44 | diff --git a/target/arm/tcg/cpu64.c b/target/arm/tcg/cpu64.c |
131 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[4].d, ARMCPU, 0, 2), | ||
132 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[5].d, ARMCPU, 0, 2), | ||
133 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[6].d, ARMCPU, 0, 2), | ||
134 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[7].d, ARMCPU, 0, 2), | ||
135 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[8].d, ARMCPU, 0, 2), | ||
136 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[9].d, ARMCPU, 0, 2), | ||
137 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[10].d, ARMCPU, 0, 2), | ||
138 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[11].d, ARMCPU, 0, 2), | ||
139 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[12].d, ARMCPU, 0, 2), | ||
140 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[13].d, ARMCPU, 0, 2), | ||
141 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[14].d, ARMCPU, 0, 2), | ||
142 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[15].d, ARMCPU, 0, 2), | ||
143 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[16].d, ARMCPU, 0, 2), | ||
144 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[17].d, ARMCPU, 0, 2), | ||
145 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[18].d, ARMCPU, 0, 2), | ||
146 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[19].d, ARMCPU, 0, 2), | ||
147 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[20].d, ARMCPU, 0, 2), | ||
148 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[21].d, ARMCPU, 0, 2), | ||
149 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[22].d, ARMCPU, 0, 2), | ||
150 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[23].d, ARMCPU, 0, 2), | ||
151 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[24].d, ARMCPU, 0, 2), | ||
152 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[25].d, ARMCPU, 0, 2), | ||
153 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[26].d, ARMCPU, 0, 2), | ||
154 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[27].d, ARMCPU, 0, 2), | ||
155 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[28].d, ARMCPU, 0, 2), | ||
156 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[29].d, ARMCPU, 0, 2), | ||
157 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[30].d, ARMCPU, 0, 2), | ||
158 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[31].d, ARMCPU, 0, 2), | ||
159 | + | ||
160 | /* The xregs array is a little awkward because element 1 (FPSCR) | ||
161 | * requires a specific accessor, so we have to split it up in | ||
162 | * the vmstate: | ||
163 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
164 | index XXXXXXX..XXXXXXX 100644 | 45 | index XXXXXXX..XXXXXXX 100644 |
165 | --- a/target/arm/translate-a64.c | 46 | --- a/target/arm/tcg/cpu64.c |
166 | +++ b/target/arm/translate-a64.c | 47 | +++ b/target/arm/tcg/cpu64.c |
167 | @@ -XXX,XX +XXX,XX @@ static inline int vec_reg_offset(DisasContext *s, int regno, | 48 | @@ -XXX,XX +XXX,XX @@ void aarch64_max_tcg_initfn(Object *obj) |
168 | { | 49 | t = FIELD_DP64(t, ID_AA64MMFR1, HAFDBS, 2); /* FEAT_HAFDBS */ |
169 | int offs = 0; | 50 | t = FIELD_DP64(t, ID_AA64MMFR1, VMIDBITS, 2); /* FEAT_VMID16 */ |
170 | #ifdef HOST_WORDS_BIGENDIAN | 51 | t = FIELD_DP64(t, ID_AA64MMFR1, VH, 1); /* FEAT_VHE */ |
171 | - /* This is complicated slightly because vfp.regs[2n] is | 52 | - t = FIELD_DP64(t, ID_AA64MMFR1, HPDS, 1); /* FEAT_HPDS */ |
172 | - * still the low half and vfp.regs[2n+1] the high half | 53 | + t = FIELD_DP64(t, ID_AA64MMFR1, HPDS, 2); /* FEAT_HPDS2 */ |
173 | + /* This is complicated slightly because vfp.zregs[n].d[0] is | 54 | t = FIELD_DP64(t, ID_AA64MMFR1, LO, 1); /* FEAT_LOR */ |
174 | + * still the low half and vfp.zregs[n].d[1] the high half | 55 | t = FIELD_DP64(t, ID_AA64MMFR1, PAN, 3); /* FEAT_PAN3 */ |
175 | * of the 128 bit vector, even on big endian systems. | 56 | t = FIELD_DP64(t, ID_AA64MMFR1, XNX, 1); /* FEAT_XNX */ |
176 | * Calculate the offset assuming a fully bigendian 128 bits, | ||
177 | * then XOR to account for the order of the two 64 bit halves. | ||
178 | @@ -XXX,XX +XXX,XX @@ static inline int vec_reg_offset(DisasContext *s, int regno, | ||
179 | #else | ||
180 | offs += element * (1 << size); | ||
181 | #endif | ||
182 | - offs += offsetof(CPUARMState, vfp.regs[regno * 2]); | ||
183 | + offs += offsetof(CPUARMState, vfp.zregs[regno]); | ||
184 | assert_fp_access_checked(s); | ||
185 | return offs; | ||
186 | } | ||
187 | @@ -XXX,XX +XXX,XX @@ static inline int vec_reg_offset(DisasContext *s, int regno, | ||
188 | static inline int vec_full_reg_offset(DisasContext *s, int regno) | ||
189 | { | ||
190 | assert_fp_access_checked(s); | ||
191 | - return offsetof(CPUARMState, vfp.regs[regno * 2]); | ||
192 | + return offsetof(CPUARMState, vfp.zregs[regno]); | ||
193 | } | ||
194 | |||
195 | /* Return a newly allocated pointer to the vector register. */ | ||
196 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
197 | index XXXXXXX..XXXXXXX 100644 | ||
198 | --- a/target/arm/translate.c | ||
199 | +++ b/target/arm/translate.c | ||
200 | @@ -XXX,XX +XXX,XX @@ static inline void gen_vfp_st(DisasContext *s, int dp, TCGv_i32 addr) | ||
201 | } | ||
202 | } | ||
203 | |||
204 | -static inline long | ||
205 | -vfp_reg_offset (int dp, int reg) | ||
206 | +static inline long vfp_reg_offset(bool dp, unsigned reg) | ||
207 | { | ||
208 | if (dp) { | ||
209 | - return offsetof(CPUARMState, vfp.regs[reg]); | ||
210 | + return offsetof(CPUARMState, vfp.zregs[reg >> 1].d[reg & 1]); | ||
211 | } else { | ||
212 | - long ofs = offsetof(CPUARMState, vfp.regs[reg >> 1]); | ||
213 | + long ofs = offsetof(CPUARMState, vfp.zregs[reg >> 2].d[(reg >> 1) & 1]); | ||
214 | if (reg & 1) { | ||
215 | ofs += offsetof(CPU_DoubleU, l.upper); | ||
216 | } else { | ||
217 | -- | 57 | -- |
218 | 2.16.1 | 58 | 2.34.1 |
219 | |||
220 | diff view generated by jsdifflib |
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | 1 | From: Alex Bennée <alex.bennee@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Move virt's PSCI DT fixup code to arm/boot.c and set this fixup to | 3 | This is a mandatory feature for Armv8.1 architectures but we don't |
4 | happen automatically for every board that doesn't mark "psci-conduit" | 4 | state the feature clearly in our emulation list. Also include |
5 | as disabled. This way emulated boards other than "virt" that rely on | 5 | FEAT_CRC32 comment in aarch64_max_tcg_initfn for ease of grepping. |
6 | PSIC for SMP could benefit from that code. | ||
7 | 6 | ||
8 | Cc: Peter Maydell <peter.maydell@linaro.org> | 7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
9 | Cc: Jason Wang <jasowang@redhat.com> | 8 | Signed-off-by: Alex Bennée <alex.bennee@linaro.org> |
10 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | 9 | Message-id: 20230824075406.1515566-1-alex.bennee@linaro.org |
11 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | 10 | Cc: qemu-stable@nongnu.org |
12 | Cc: Michael S. Tsirkin <mst@redhat.com> | 11 | Message-Id: <20230222110104.3996971-1-alex.bennee@linaro.org> |
13 | Cc: qemu-devel@nongnu.org | 12 | [PMM: pluralize 'instructions' in docs] |
14 | Cc: qemu-arm@nongnu.org | ||
15 | Cc: yurovsky@gmail.com | ||
16 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
17 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
18 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
20 | --- | 14 | --- |
21 | hw/arm/boot.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 15 | docs/system/arm/emulation.rst | 1 + |
22 | hw/arm/virt.c | 61 ------------------------------------------------------- | 16 | target/arm/tcg/cpu64.c | 2 +- |
23 | 2 files changed, 65 insertions(+), 61 deletions(-) | 17 | 2 files changed, 2 insertions(+), 1 deletion(-) |
24 | 18 | ||
25 | diff --git a/hw/arm/boot.c b/hw/arm/boot.c | 19 | diff --git a/docs/system/arm/emulation.rst b/docs/system/arm/emulation.rst |
26 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/hw/arm/boot.c | 21 | --- a/docs/system/arm/emulation.rst |
28 | +++ b/hw/arm/boot.c | 22 | +++ b/docs/system/arm/emulation.rst |
29 | @@ -XXX,XX +XXX,XX @@ static void set_kernel_args_old(const struct arm_boot_info *info) | 23 | @@ -XXX,XX +XXX,XX @@ the following architecture extensions: |
30 | } | 24 | - FEAT_BBM at level 2 (Translation table break-before-make levels) |
31 | } | 25 | - FEAT_BF16 (AArch64 BFloat16 instructions) |
32 | 26 | - FEAT_BTI (Branch Target Identification) | |
33 | +static void fdt_add_psci_node(void *fdt) | 27 | +- FEAT_CRC32 (CRC32 instructions) |
34 | +{ | 28 | - FEAT_CSV2 (Cache speculation variant 2) |
35 | + uint32_t cpu_suspend_fn; | 29 | - FEAT_CSV2_1p1 (Cache speculation variant 2, version 1.1) |
36 | + uint32_t cpu_off_fn; | 30 | - FEAT_CSV2_1p2 (Cache speculation variant 2, version 1.2) |
37 | + uint32_t cpu_on_fn; | 31 | diff --git a/target/arm/tcg/cpu64.c b/target/arm/tcg/cpu64.c |
38 | + uint32_t migrate_fn; | ||
39 | + ARMCPU *armcpu = ARM_CPU(qemu_get_cpu(0)); | ||
40 | + const char *psci_method; | ||
41 | + int64_t psci_conduit; | ||
42 | + | ||
43 | + psci_conduit = object_property_get_int(OBJECT(armcpu), | ||
44 | + "psci-conduit", | ||
45 | + &error_abort); | ||
46 | + switch (psci_conduit) { | ||
47 | + case QEMU_PSCI_CONDUIT_DISABLED: | ||
48 | + return; | ||
49 | + case QEMU_PSCI_CONDUIT_HVC: | ||
50 | + psci_method = "hvc"; | ||
51 | + break; | ||
52 | + case QEMU_PSCI_CONDUIT_SMC: | ||
53 | + psci_method = "smc"; | ||
54 | + break; | ||
55 | + default: | ||
56 | + g_assert_not_reached(); | ||
57 | + } | ||
58 | + | ||
59 | + qemu_fdt_add_subnode(fdt, "/psci"); | ||
60 | + if (armcpu->psci_version == 2) { | ||
61 | + const char comp[] = "arm,psci-0.2\0arm,psci"; | ||
62 | + qemu_fdt_setprop(fdt, "/psci", "compatible", comp, sizeof(comp)); | ||
63 | + | ||
64 | + cpu_off_fn = QEMU_PSCI_0_2_FN_CPU_OFF; | ||
65 | + if (arm_feature(&armcpu->env, ARM_FEATURE_AARCH64)) { | ||
66 | + cpu_suspend_fn = QEMU_PSCI_0_2_FN64_CPU_SUSPEND; | ||
67 | + cpu_on_fn = QEMU_PSCI_0_2_FN64_CPU_ON; | ||
68 | + migrate_fn = QEMU_PSCI_0_2_FN64_MIGRATE; | ||
69 | + } else { | ||
70 | + cpu_suspend_fn = QEMU_PSCI_0_2_FN_CPU_SUSPEND; | ||
71 | + cpu_on_fn = QEMU_PSCI_0_2_FN_CPU_ON; | ||
72 | + migrate_fn = QEMU_PSCI_0_2_FN_MIGRATE; | ||
73 | + } | ||
74 | + } else { | ||
75 | + qemu_fdt_setprop_string(fdt, "/psci", "compatible", "arm,psci"); | ||
76 | + | ||
77 | + cpu_suspend_fn = QEMU_PSCI_0_1_FN_CPU_SUSPEND; | ||
78 | + cpu_off_fn = QEMU_PSCI_0_1_FN_CPU_OFF; | ||
79 | + cpu_on_fn = QEMU_PSCI_0_1_FN_CPU_ON; | ||
80 | + migrate_fn = QEMU_PSCI_0_1_FN_MIGRATE; | ||
81 | + } | ||
82 | + | ||
83 | + /* We adopt the PSCI spec's nomenclature, and use 'conduit' to refer | ||
84 | + * to the instruction that should be used to invoke PSCI functions. | ||
85 | + * However, the device tree binding uses 'method' instead, so that is | ||
86 | + * what we should use here. | ||
87 | + */ | ||
88 | + qemu_fdt_setprop_string(fdt, "/psci", "method", psci_method); | ||
89 | + | ||
90 | + qemu_fdt_setprop_cell(fdt, "/psci", "cpu_suspend", cpu_suspend_fn); | ||
91 | + qemu_fdt_setprop_cell(fdt, "/psci", "cpu_off", cpu_off_fn); | ||
92 | + qemu_fdt_setprop_cell(fdt, "/psci", "cpu_on", cpu_on_fn); | ||
93 | + qemu_fdt_setprop_cell(fdt, "/psci", "migrate", migrate_fn); | ||
94 | +} | ||
95 | + | ||
96 | /** | ||
97 | * load_dtb() - load a device tree binary image into memory | ||
98 | * @addr: the address to load the image at | ||
99 | @@ -XXX,XX +XXX,XX @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo, | ||
100 | } | ||
101 | } | ||
102 | |||
103 | + fdt_add_psci_node(fdt); | ||
104 | + | ||
105 | if (binfo->modify_dtb) { | ||
106 | binfo->modify_dtb(binfo, fdt); | ||
107 | } | ||
108 | diff --git a/hw/arm/virt.c b/hw/arm/virt.c | ||
109 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
110 | --- a/hw/arm/virt.c | 33 | --- a/target/arm/tcg/cpu64.c |
111 | +++ b/hw/arm/virt.c | 34 | +++ b/target/arm/tcg/cpu64.c |
112 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(VirtMachineState *vms) | 35 | @@ -XXX,XX +XXX,XX @@ void aarch64_max_tcg_initfn(Object *obj) |
113 | } | 36 | t = FIELD_DP64(t, ID_AA64ISAR0, AES, 2); /* FEAT_PMULL */ |
114 | } | 37 | t = FIELD_DP64(t, ID_AA64ISAR0, SHA1, 1); /* FEAT_SHA1 */ |
115 | 38 | t = FIELD_DP64(t, ID_AA64ISAR0, SHA2, 2); /* FEAT_SHA512 */ | |
116 | -static void fdt_add_psci_node(const VirtMachineState *vms) | 39 | - t = FIELD_DP64(t, ID_AA64ISAR0, CRC32, 1); |
117 | -{ | 40 | + t = FIELD_DP64(t, ID_AA64ISAR0, CRC32, 1); /* FEAT_CRC32 */ |
118 | - uint32_t cpu_suspend_fn; | 41 | t = FIELD_DP64(t, ID_AA64ISAR0, ATOMIC, 2); /* FEAT_LSE */ |
119 | - uint32_t cpu_off_fn; | 42 | t = FIELD_DP64(t, ID_AA64ISAR0, RDM, 1); /* FEAT_RDM */ |
120 | - uint32_t cpu_on_fn; | 43 | t = FIELD_DP64(t, ID_AA64ISAR0, SHA3, 1); /* FEAT_SHA3 */ |
121 | - uint32_t migrate_fn; | ||
122 | - void *fdt = vms->fdt; | ||
123 | - ARMCPU *armcpu = ARM_CPU(qemu_get_cpu(0)); | ||
124 | - const char *psci_method; | ||
125 | - | ||
126 | - switch (vms->psci_conduit) { | ||
127 | - case QEMU_PSCI_CONDUIT_DISABLED: | ||
128 | - return; | ||
129 | - case QEMU_PSCI_CONDUIT_HVC: | ||
130 | - psci_method = "hvc"; | ||
131 | - break; | ||
132 | - case QEMU_PSCI_CONDUIT_SMC: | ||
133 | - psci_method = "smc"; | ||
134 | - break; | ||
135 | - default: | ||
136 | - g_assert_not_reached(); | ||
137 | - } | ||
138 | - | ||
139 | - qemu_fdt_add_subnode(fdt, "/psci"); | ||
140 | - if (armcpu->psci_version == 2) { | ||
141 | - const char comp[] = "arm,psci-0.2\0arm,psci"; | ||
142 | - qemu_fdt_setprop(fdt, "/psci", "compatible", comp, sizeof(comp)); | ||
143 | - | ||
144 | - cpu_off_fn = QEMU_PSCI_0_2_FN_CPU_OFF; | ||
145 | - if (arm_feature(&armcpu->env, ARM_FEATURE_AARCH64)) { | ||
146 | - cpu_suspend_fn = QEMU_PSCI_0_2_FN64_CPU_SUSPEND; | ||
147 | - cpu_on_fn = QEMU_PSCI_0_2_FN64_CPU_ON; | ||
148 | - migrate_fn = QEMU_PSCI_0_2_FN64_MIGRATE; | ||
149 | - } else { | ||
150 | - cpu_suspend_fn = QEMU_PSCI_0_2_FN_CPU_SUSPEND; | ||
151 | - cpu_on_fn = QEMU_PSCI_0_2_FN_CPU_ON; | ||
152 | - migrate_fn = QEMU_PSCI_0_2_FN_MIGRATE; | ||
153 | - } | ||
154 | - } else { | ||
155 | - qemu_fdt_setprop_string(fdt, "/psci", "compatible", "arm,psci"); | ||
156 | - | ||
157 | - cpu_suspend_fn = QEMU_PSCI_0_1_FN_CPU_SUSPEND; | ||
158 | - cpu_off_fn = QEMU_PSCI_0_1_FN_CPU_OFF; | ||
159 | - cpu_on_fn = QEMU_PSCI_0_1_FN_CPU_ON; | ||
160 | - migrate_fn = QEMU_PSCI_0_1_FN_MIGRATE; | ||
161 | - } | ||
162 | - | ||
163 | - /* We adopt the PSCI spec's nomenclature, and use 'conduit' to refer | ||
164 | - * to the instruction that should be used to invoke PSCI functions. | ||
165 | - * However, the device tree binding uses 'method' instead, so that is | ||
166 | - * what we should use here. | ||
167 | - */ | ||
168 | - qemu_fdt_setprop_string(fdt, "/psci", "method", psci_method); | ||
169 | - | ||
170 | - qemu_fdt_setprop_cell(fdt, "/psci", "cpu_suspend", cpu_suspend_fn); | ||
171 | - qemu_fdt_setprop_cell(fdt, "/psci", "cpu_off", cpu_off_fn); | ||
172 | - qemu_fdt_setprop_cell(fdt, "/psci", "cpu_on", cpu_on_fn); | ||
173 | - qemu_fdt_setprop_cell(fdt, "/psci", "migrate", migrate_fn); | ||
174 | -} | ||
175 | - | ||
176 | static void fdt_add_timer_nodes(const VirtMachineState *vms) | ||
177 | { | ||
178 | /* On real hardware these interrupts are level-triggered. | ||
179 | @@ -XXX,XX +XXX,XX @@ static void machvirt_init(MachineState *machine) | ||
180 | } | ||
181 | fdt_add_timer_nodes(vms); | ||
182 | fdt_add_cpu_nodes(vms); | ||
183 | - fdt_add_psci_node(vms); | ||
184 | |||
185 | memory_region_allocate_system_memory(ram, NULL, "mach-virt.ram", | ||
186 | machine->ram_size); | ||
187 | -- | 44 | -- |
188 | 2.16.1 | 45 | 2.34.1 |
189 | 46 | ||
190 | 47 | diff view generated by jsdifflib |
1 | From: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 1 | From: Jean-Christophe Dubois <jcd@tribudubois.net> |
---|---|---|---|
2 | 2 | ||
3 | This implements emulation of the new SM3 instructions that have | 3 | i.MX7 IOMUX GPR device is not equivalent to i.MX6UL IOMUXC GPR device. |
4 | been added as an optional extension to the ARMv8 Crypto Extensions | 4 | In particular, register 22 is not present on i.MX6UL and this is actualy |
5 | in ARM v8.2. | 5 | The only register that is really emulated in the i.MX7 IOMUX GPR device. |
6 | 6 | ||
7 | Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 7 | Note: The i.MX6UL code is actually also implementing the IOMUX GPR device |
8 | Message-id: 20180207111729.15737-4-ard.biesheuvel@linaro.org | 8 | as an unimplemented device at the same bus adress and the 2 instantiations |
9 | were actualy colliding. So we go back to the unimplemented device for now. | ||
10 | |||
11 | Signed-off-by: Jean-Christophe Dubois <jcd@tribudubois.net> | ||
12 | Message-id: 48681bf51ee97646479bb261bee19abebbc8074e.1692964892.git.jcd@tribudubois.net | ||
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 15 | --- |
12 | target/arm/cpu.h | 1 + | 16 | include/hw/arm/fsl-imx6ul.h | 2 -- |
13 | target/arm/helper.h | 4 ++ | 17 | hw/arm/fsl-imx6ul.c | 11 ----------- |
14 | target/arm/crypto_helper.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++ | 18 | 2 files changed, 13 deletions(-) |
15 | target/arm/translate-a64.c | 88 ++++++++++++++++++++++++++++++++++++++++-- | ||
16 | 4 files changed, 186 insertions(+), 3 deletions(-) | ||
17 | 19 | ||
18 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 20 | diff --git a/include/hw/arm/fsl-imx6ul.h b/include/hw/arm/fsl-imx6ul.h |
19 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/target/arm/cpu.h | 22 | --- a/include/hw/arm/fsl-imx6ul.h |
21 | +++ b/target/arm/cpu.h | 23 | +++ b/include/hw/arm/fsl-imx6ul.h |
22 | @@ -XXX,XX +XXX,XX @@ enum arm_features { | 24 | @@ -XXX,XX +XXX,XX @@ |
23 | ARM_FEATURE_SVE, /* has Scalable Vector Extension */ | 25 | #include "hw/misc/imx6ul_ccm.h" |
24 | ARM_FEATURE_V8_SHA512, /* implements SHA512 part of v8 Crypto Extensions */ | 26 | #include "hw/misc/imx6_src.h" |
25 | ARM_FEATURE_V8_SHA3, /* implements SHA3 part of v8 Crypto Extensions */ | 27 | #include "hw/misc/imx7_snvs.h" |
26 | + ARM_FEATURE_V8_SM3, /* implements SM3 part of v8 Crypto Extensions */ | 28 | -#include "hw/misc/imx7_gpr.h" |
27 | }; | 29 | #include "hw/intc/imx_gpcv2.h" |
28 | 30 | #include "hw/watchdog/wdt_imx2.h" | |
29 | static inline int arm_feature(CPUARMState *env, int feature) | 31 | #include "hw/gpio/imx_gpio.h" |
30 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 32 | @@ -XXX,XX +XXX,XX @@ struct FslIMX6ULState { |
33 | IMX6SRCState src; | ||
34 | IMX7SNVSState snvs; | ||
35 | IMXGPCv2State gpcv2; | ||
36 | - IMX7GPRState gpr; | ||
37 | IMXSPIState spi[FSL_IMX6UL_NUM_ECSPIS]; | ||
38 | IMXI2CState i2c[FSL_IMX6UL_NUM_I2CS]; | ||
39 | IMXSerialState uart[FSL_IMX6UL_NUM_UARTS]; | ||
40 | diff --git a/hw/arm/fsl-imx6ul.c b/hw/arm/fsl-imx6ul.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | 41 | index XXXXXXX..XXXXXXX 100644 |
32 | --- a/target/arm/helper.h | 42 | --- a/hw/arm/fsl-imx6ul.c |
33 | +++ b/target/arm/helper.h | 43 | +++ b/hw/arm/fsl-imx6ul.c |
34 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(crypto_sha512h2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 44 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6ul_init(Object *obj) |
35 | DEF_HELPER_FLAGS_2(crypto_sha512su0, TCG_CALL_NO_RWG, void, ptr, ptr) | 45 | */ |
36 | DEF_HELPER_FLAGS_3(crypto_sha512su1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 46 | object_initialize_child(obj, "snvs", &s->snvs, TYPE_IMX7_SNVS); |
37 | 47 | ||
38 | +DEF_HELPER_FLAGS_5(crypto_sm3tt, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32, i32) | 48 | - /* |
39 | +DEF_HELPER_FLAGS_3(crypto_sm3partw1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 49 | - * GPR |
40 | +DEF_HELPER_FLAGS_3(crypto_sm3partw2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 50 | - */ |
41 | + | 51 | - object_initialize_child(obj, "gpr", &s->gpr, TYPE_IMX7_GPR); |
42 | DEF_HELPER_FLAGS_3(crc32, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) | 52 | - |
43 | DEF_HELPER_FLAGS_3(crc32c, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) | 53 | /* |
44 | DEF_HELPER_2(dc_zva, void, env, i64) | 54 | * GPIOs 1 to 5 |
45 | diff --git a/target/arm/crypto_helper.c b/target/arm/crypto_helper.c | 55 | */ |
46 | index XXXXXXX..XXXXXXX 100644 | 56 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp) |
47 | --- a/target/arm/crypto_helper.c | 57 | FSL_IMX6UL_WDOGn_IRQ[i])); |
48 | +++ b/target/arm/crypto_helper.c | ||
49 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sha512su1)(void *vd, void *vn, void *vm) | ||
50 | rd[0] += s1_512(rn[0]) + rm[0]; | ||
51 | rd[1] += s1_512(rn[1]) + rm[1]; | ||
52 | } | ||
53 | + | ||
54 | +void HELPER(crypto_sm3partw1)(void *vd, void *vn, void *vm) | ||
55 | +{ | ||
56 | + uint64_t *rd = vd; | ||
57 | + uint64_t *rn = vn; | ||
58 | + uint64_t *rm = vm; | ||
59 | + union CRYPTO_STATE d = { .l = { rd[0], rd[1] } }; | ||
60 | + union CRYPTO_STATE n = { .l = { rn[0], rn[1] } }; | ||
61 | + union CRYPTO_STATE m = { .l = { rm[0], rm[1] } }; | ||
62 | + uint32_t t; | ||
63 | + | ||
64 | + t = CR_ST_WORD(d, 0) ^ CR_ST_WORD(n, 0) ^ ror32(CR_ST_WORD(m, 1), 17); | ||
65 | + CR_ST_WORD(d, 0) = t ^ ror32(t, 17) ^ ror32(t, 9); | ||
66 | + | ||
67 | + t = CR_ST_WORD(d, 1) ^ CR_ST_WORD(n, 1) ^ ror32(CR_ST_WORD(m, 2), 17); | ||
68 | + CR_ST_WORD(d, 1) = t ^ ror32(t, 17) ^ ror32(t, 9); | ||
69 | + | ||
70 | + t = CR_ST_WORD(d, 2) ^ CR_ST_WORD(n, 2) ^ ror32(CR_ST_WORD(m, 3), 17); | ||
71 | + CR_ST_WORD(d, 2) = t ^ ror32(t, 17) ^ ror32(t, 9); | ||
72 | + | ||
73 | + t = CR_ST_WORD(d, 3) ^ CR_ST_WORD(n, 3) ^ ror32(CR_ST_WORD(d, 0), 17); | ||
74 | + CR_ST_WORD(d, 3) = t ^ ror32(t, 17) ^ ror32(t, 9); | ||
75 | + | ||
76 | + rd[0] = d.l[0]; | ||
77 | + rd[1] = d.l[1]; | ||
78 | +} | ||
79 | + | ||
80 | +void HELPER(crypto_sm3partw2)(void *vd, void *vn, void *vm) | ||
81 | +{ | ||
82 | + uint64_t *rd = vd; | ||
83 | + uint64_t *rn = vn; | ||
84 | + uint64_t *rm = vm; | ||
85 | + union CRYPTO_STATE d = { .l = { rd[0], rd[1] } }; | ||
86 | + union CRYPTO_STATE n = { .l = { rn[0], rn[1] } }; | ||
87 | + union CRYPTO_STATE m = { .l = { rm[0], rm[1] } }; | ||
88 | + uint32_t t = CR_ST_WORD(n, 0) ^ ror32(CR_ST_WORD(m, 0), 25); | ||
89 | + | ||
90 | + CR_ST_WORD(d, 0) ^= t; | ||
91 | + CR_ST_WORD(d, 1) ^= CR_ST_WORD(n, 1) ^ ror32(CR_ST_WORD(m, 1), 25); | ||
92 | + CR_ST_WORD(d, 2) ^= CR_ST_WORD(n, 2) ^ ror32(CR_ST_WORD(m, 2), 25); | ||
93 | + CR_ST_WORD(d, 3) ^= CR_ST_WORD(n, 3) ^ ror32(CR_ST_WORD(m, 3), 25) ^ | ||
94 | + ror32(t, 17) ^ ror32(t, 2) ^ ror32(t, 26); | ||
95 | + | ||
96 | + rd[0] = d.l[0]; | ||
97 | + rd[1] = d.l[1]; | ||
98 | +} | ||
99 | + | ||
100 | +void HELPER(crypto_sm3tt)(void *vd, void *vn, void *vm, uint32_t imm2, | ||
101 | + uint32_t opcode) | ||
102 | +{ | ||
103 | + uint64_t *rd = vd; | ||
104 | + uint64_t *rn = vn; | ||
105 | + uint64_t *rm = vm; | ||
106 | + union CRYPTO_STATE d = { .l = { rd[0], rd[1] } }; | ||
107 | + union CRYPTO_STATE n = { .l = { rn[0], rn[1] } }; | ||
108 | + union CRYPTO_STATE m = { .l = { rm[0], rm[1] } }; | ||
109 | + uint32_t t; | ||
110 | + | ||
111 | + assert(imm2 < 4); | ||
112 | + | ||
113 | + if (opcode == 0 || opcode == 2) { | ||
114 | + /* SM3TT1A, SM3TT2A */ | ||
115 | + t = par(CR_ST_WORD(d, 3), CR_ST_WORD(d, 2), CR_ST_WORD(d, 1)); | ||
116 | + } else if (opcode == 1) { | ||
117 | + /* SM3TT1B */ | ||
118 | + t = maj(CR_ST_WORD(d, 3), CR_ST_WORD(d, 2), CR_ST_WORD(d, 1)); | ||
119 | + } else if (opcode == 3) { | ||
120 | + /* SM3TT2B */ | ||
121 | + t = cho(CR_ST_WORD(d, 3), CR_ST_WORD(d, 2), CR_ST_WORD(d, 1)); | ||
122 | + } else { | ||
123 | + g_assert_not_reached(); | ||
124 | + } | ||
125 | + | ||
126 | + t += CR_ST_WORD(d, 0) + CR_ST_WORD(m, imm2); | ||
127 | + | ||
128 | + CR_ST_WORD(d, 0) = CR_ST_WORD(d, 1); | ||
129 | + | ||
130 | + if (opcode < 2) { | ||
131 | + /* SM3TT1A, SM3TT1B */ | ||
132 | + t += CR_ST_WORD(n, 3) ^ ror32(CR_ST_WORD(d, 3), 20); | ||
133 | + | ||
134 | + CR_ST_WORD(d, 1) = ror32(CR_ST_WORD(d, 2), 23); | ||
135 | + } else { | ||
136 | + /* SM3TT2A, SM3TT2B */ | ||
137 | + t += CR_ST_WORD(n, 3); | ||
138 | + t ^= rol32(t, 9) ^ rol32(t, 17); | ||
139 | + | ||
140 | + CR_ST_WORD(d, 1) = ror32(CR_ST_WORD(d, 2), 13); | ||
141 | + } | ||
142 | + | ||
143 | + CR_ST_WORD(d, 2) = CR_ST_WORD(d, 3); | ||
144 | + CR_ST_WORD(d, 3) = t; | ||
145 | + | ||
146 | + rd[0] = d.l[0]; | ||
147 | + rd[1] = d.l[1]; | ||
148 | +} | ||
149 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
150 | index XXXXXXX..XXXXXXX 100644 | ||
151 | --- a/target/arm/translate-a64.c | ||
152 | +++ b/target/arm/translate-a64.c | ||
153 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | ||
154 | break; | ||
155 | } | ||
156 | } else { | ||
157 | - unallocated_encoding(s); | ||
158 | - return; | ||
159 | + switch (opcode) { | ||
160 | + case 0: /* SM3PARTW1 */ | ||
161 | + feature = ARM_FEATURE_V8_SM3; | ||
162 | + genfn = gen_helper_crypto_sm3partw1; | ||
163 | + break; | ||
164 | + case 1: /* SM3PARTW2 */ | ||
165 | + feature = ARM_FEATURE_V8_SM3; | ||
166 | + genfn = gen_helper_crypto_sm3partw2; | ||
167 | + break; | ||
168 | + default: | ||
169 | + unallocated_encoding(s); | ||
170 | + return; | ||
171 | + } | ||
172 | } | 58 | } |
173 | 59 | ||
174 | if (!arm_dc_feature(s, feature)) { | 60 | - /* |
175 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_four_reg(DisasContext *s, uint32_t insn) | 61 | - * GPR |
176 | case 1: /* BCAX */ | 62 | - */ |
177 | feature = ARM_FEATURE_V8_SHA3; | 63 | - sysbus_realize(SYS_BUS_DEVICE(&s->gpr), &error_abort); |
178 | break; | 64 | - sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpr), 0, FSL_IMX6UL_IOMUXC_GPR_ADDR); |
179 | + case 2: /* SM3SS1 */ | 65 | - |
180 | + feature = ARM_FEATURE_V8_SM3; | 66 | /* |
181 | + break; | 67 | * SDMA |
182 | default: | 68 | */ |
183 | unallocated_encoding(s); | ||
184 | return; | ||
185 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_four_reg(DisasContext *s, uint32_t insn) | ||
186 | tcg_temp_free_i64(tcg_res[0]); | ||
187 | tcg_temp_free_i64(tcg_res[1]); | ||
188 | } else { | ||
189 | - g_assert_not_reached(); | ||
190 | + TCGv_i32 tcg_op1, tcg_op2, tcg_op3, tcg_res, tcg_zero; | ||
191 | + | ||
192 | + tcg_op1 = tcg_temp_new_i32(); | ||
193 | + tcg_op2 = tcg_temp_new_i32(); | ||
194 | + tcg_op3 = tcg_temp_new_i32(); | ||
195 | + tcg_res = tcg_temp_new_i32(); | ||
196 | + tcg_zero = tcg_const_i32(0); | ||
197 | + | ||
198 | + read_vec_element_i32(s, tcg_op1, rn, 3, MO_32); | ||
199 | + read_vec_element_i32(s, tcg_op2, rm, 3, MO_32); | ||
200 | + read_vec_element_i32(s, tcg_op3, ra, 3, MO_32); | ||
201 | + | ||
202 | + tcg_gen_rotri_i32(tcg_res, tcg_op1, 20); | ||
203 | + tcg_gen_add_i32(tcg_res, tcg_res, tcg_op2); | ||
204 | + tcg_gen_add_i32(tcg_res, tcg_res, tcg_op3); | ||
205 | + tcg_gen_rotri_i32(tcg_res, tcg_res, 25); | ||
206 | + | ||
207 | + write_vec_element_i32(s, tcg_zero, rd, 0, MO_32); | ||
208 | + write_vec_element_i32(s, tcg_zero, rd, 1, MO_32); | ||
209 | + write_vec_element_i32(s, tcg_zero, rd, 2, MO_32); | ||
210 | + write_vec_element_i32(s, tcg_res, rd, 3, MO_32); | ||
211 | + | ||
212 | + tcg_temp_free_i32(tcg_op1); | ||
213 | + tcg_temp_free_i32(tcg_op2); | ||
214 | + tcg_temp_free_i32(tcg_op3); | ||
215 | + tcg_temp_free_i32(tcg_res); | ||
216 | + tcg_temp_free_i32(tcg_zero); | ||
217 | } | ||
218 | } | ||
219 | |||
220 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_xar(DisasContext *s, uint32_t insn) | ||
221 | tcg_temp_free_i64(tcg_res[1]); | ||
222 | } | ||
223 | |||
224 | +/* Crypto three-reg imm2 | ||
225 | + * 31 21 20 16 15 14 13 12 11 10 9 5 4 0 | ||
226 | + * +-----------------------+------+-----+------+--------+------+------+ | ||
227 | + * | 1 1 0 0 1 1 1 0 0 1 0 | Rm | 1 0 | imm2 | opcode | Rn | Rd | | ||
228 | + * +-----------------------+------+-----+------+--------+------+------+ | ||
229 | + */ | ||
230 | +static void disas_crypto_three_reg_imm2(DisasContext *s, uint32_t insn) | ||
231 | +{ | ||
232 | + int opcode = extract32(insn, 10, 2); | ||
233 | + int imm2 = extract32(insn, 12, 2); | ||
234 | + int rm = extract32(insn, 16, 5); | ||
235 | + int rn = extract32(insn, 5, 5); | ||
236 | + int rd = extract32(insn, 0, 5); | ||
237 | + TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr; | ||
238 | + TCGv_i32 tcg_imm2, tcg_opcode; | ||
239 | + | ||
240 | + if (!arm_dc_feature(s, ARM_FEATURE_V8_SM3)) { | ||
241 | + unallocated_encoding(s); | ||
242 | + return; | ||
243 | + } | ||
244 | + | ||
245 | + if (!fp_access_check(s)) { | ||
246 | + return; | ||
247 | + } | ||
248 | + | ||
249 | + tcg_rd_ptr = vec_full_reg_ptr(s, rd); | ||
250 | + tcg_rn_ptr = vec_full_reg_ptr(s, rn); | ||
251 | + tcg_rm_ptr = vec_full_reg_ptr(s, rm); | ||
252 | + tcg_imm2 = tcg_const_i32(imm2); | ||
253 | + tcg_opcode = tcg_const_i32(opcode); | ||
254 | + | ||
255 | + gen_helper_crypto_sm3tt(tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr, tcg_imm2, | ||
256 | + tcg_opcode); | ||
257 | + | ||
258 | + tcg_temp_free_ptr(tcg_rd_ptr); | ||
259 | + tcg_temp_free_ptr(tcg_rn_ptr); | ||
260 | + tcg_temp_free_ptr(tcg_rm_ptr); | ||
261 | + tcg_temp_free_i32(tcg_imm2); | ||
262 | + tcg_temp_free_i32(tcg_opcode); | ||
263 | +} | ||
264 | + | ||
265 | /* C3.6 Data processing - SIMD, inc Crypto | ||
266 | * | ||
267 | * As the decode gets a little complex we are using a table based | ||
268 | @@ -XXX,XX +XXX,XX @@ static const AArch64DecodeTable data_proc_simd[] = { | ||
269 | { 0xcec08000, 0xfffff000, disas_crypto_two_reg_sha512 }, | ||
270 | { 0xce000000, 0xff808000, disas_crypto_four_reg }, | ||
271 | { 0xce800000, 0xffe00000, disas_crypto_xar }, | ||
272 | + { 0xce408000, 0xffe0c000, disas_crypto_three_reg_imm2 }, | ||
273 | { 0x00000000, 0x00000000, NULL } | ||
274 | }; | ||
275 | |||
276 | -- | 69 | -- |
277 | 2.16.1 | 70 | 2.34.1 |
278 | |||
279 | diff view generated by jsdifflib |
1 | From: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 1 | From: Jean-Christophe Dubois <jcd@tribudubois.net> |
---|---|---|---|
2 | 2 | ||
3 | Add support for the new ARMv8.2 SHA-3, SM3, SM4 and SHA-512 instructions to | 3 | * Add Addr and size definition for most i.MX6UL devices in i.MX6UL header file. |
4 | AArch64 user mode emulation. | 4 | * Use those newly defined named constants whenever possible. |
5 | * Standardize the way we init a familly of unimplemented devices | ||
6 | - SAI | ||
7 | - PWM | ||
8 | - CAN | ||
9 | * Add/rework few comments | ||
5 | 10 | ||
6 | Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 11 | Signed-off-by: Jean-Christophe Dubois <jcd@tribudubois.net> |
7 | Message-id: 20180207111729.15737-6-ard.biesheuvel@linaro.org | 12 | Message-id: d579043fbd4e4b490370783fda43fc02c8e9be75.1692964892.git.jcd@tribudubois.net |
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 15 | --- |
11 | linux-user/elfload.c | 19 +++++++++++++++++++ | 16 | include/hw/arm/fsl-imx6ul.h | 156 +++++++++++++++++++++++++++++++----- |
12 | target/arm/cpu64.c | 4 ++++ | 17 | hw/arm/fsl-imx6ul.c | 147 ++++++++++++++++++++++----------- |
13 | 2 files changed, 23 insertions(+) | 18 | 2 files changed, 232 insertions(+), 71 deletions(-) |
14 | 19 | ||
15 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | 20 | diff --git a/include/hw/arm/fsl-imx6ul.h b/include/hw/arm/fsl-imx6ul.h |
16 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/linux-user/elfload.c | 22 | --- a/include/hw/arm/fsl-imx6ul.h |
18 | +++ b/linux-user/elfload.c | 23 | +++ b/include/hw/arm/fsl-imx6ul.h |
19 | @@ -XXX,XX +XXX,XX @@ enum { | 24 | @@ -XXX,XX +XXX,XX @@ |
20 | ARM_HWCAP_A64_SHA1 = 1 << 5, | 25 | #include "exec/memory.h" |
21 | ARM_HWCAP_A64_SHA2 = 1 << 6, | 26 | #include "cpu.h" |
22 | ARM_HWCAP_A64_CRC32 = 1 << 7, | 27 | #include "qom/object.h" |
23 | + ARM_HWCAP_A64_ATOMICS = 1 << 8, | 28 | +#include "qemu/units.h" |
24 | + ARM_HWCAP_A64_FPHP = 1 << 9, | 29 | |
25 | + ARM_HWCAP_A64_ASIMDHP = 1 << 10, | 30 | #define TYPE_FSL_IMX6UL "fsl-imx6ul" |
26 | + ARM_HWCAP_A64_CPUID = 1 << 11, | 31 | OBJECT_DECLARE_SIMPLE_TYPE(FslIMX6ULState, FSL_IMX6UL) |
27 | + ARM_HWCAP_A64_ASIMDRDM = 1 << 12, | 32 | @@ -XXX,XX +XXX,XX @@ enum FslIMX6ULConfiguration { |
28 | + ARM_HWCAP_A64_JSCVT = 1 << 13, | 33 | FSL_IMX6UL_NUM_ADCS = 2, |
29 | + ARM_HWCAP_A64_FCMA = 1 << 14, | 34 | FSL_IMX6UL_NUM_USB_PHYS = 2, |
30 | + ARM_HWCAP_A64_LRCPC = 1 << 15, | 35 | FSL_IMX6UL_NUM_USBS = 2, |
31 | + ARM_HWCAP_A64_DCPOP = 1 << 16, | 36 | + FSL_IMX6UL_NUM_SAIS = 3, |
32 | + ARM_HWCAP_A64_SHA3 = 1 << 17, | 37 | + FSL_IMX6UL_NUM_CANS = 2, |
33 | + ARM_HWCAP_A64_SM3 = 1 << 18, | 38 | + FSL_IMX6UL_NUM_PWMS = 4, |
34 | + ARM_HWCAP_A64_SM4 = 1 << 19, | ||
35 | + ARM_HWCAP_A64_ASIMDDP = 1 << 20, | ||
36 | + ARM_HWCAP_A64_SHA512 = 1 << 21, | ||
37 | + ARM_HWCAP_A64_SVE = 1 << 22, | ||
38 | }; | 39 | }; |
39 | 40 | ||
40 | #define ELF_HWCAP get_elf_hwcap() | 41 | struct FslIMX6ULState { |
41 | @@ -XXX,XX +XXX,XX @@ static uint32_t get_elf_hwcap(void) | 42 | @@ -XXX,XX +XXX,XX @@ struct FslIMX6ULState { |
42 | GET_FEATURE(ARM_FEATURE_V8_SHA1, ARM_HWCAP_A64_SHA1); | 43 | |
43 | GET_FEATURE(ARM_FEATURE_V8_SHA256, ARM_HWCAP_A64_SHA2); | 44 | enum FslIMX6ULMemoryMap { |
44 | GET_FEATURE(ARM_FEATURE_CRC, ARM_HWCAP_A64_CRC32); | 45 | FSL_IMX6UL_MMDC_ADDR = 0x80000000, |
45 | + GET_FEATURE(ARM_FEATURE_V8_SHA3, ARM_HWCAP_A64_SHA3); | 46 | - FSL_IMX6UL_MMDC_SIZE = 2 * 1024 * 1024 * 1024UL, |
46 | + GET_FEATURE(ARM_FEATURE_V8_SM3, ARM_HWCAP_A64_SM3); | 47 | + FSL_IMX6UL_MMDC_SIZE = (2 * GiB), |
47 | + GET_FEATURE(ARM_FEATURE_V8_SM4, ARM_HWCAP_A64_SM4); | 48 | |
48 | + GET_FEATURE(ARM_FEATURE_V8_SHA512, ARM_HWCAP_A64_SHA512); | 49 | FSL_IMX6UL_QSPI1_MEM_ADDR = 0x60000000, |
49 | #undef GET_FEATURE | 50 | - FSL_IMX6UL_EIM_ALIAS_ADDR = 0x58000000, |
50 | 51 | - FSL_IMX6UL_EIM_CS_ADDR = 0x50000000, | |
51 | return hwcaps; | 52 | - FSL_IMX6UL_AES_ENCRYPT_ADDR = 0x10000000, |
52 | diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c | 53 | - FSL_IMX6UL_QSPI1_RX_ADDR = 0x0C000000, |
54 | + FSL_IMX6UL_QSPI1_MEM_SIZE = (256 * MiB), | ||
55 | |||
56 | - /* AIPS-2 */ | ||
57 | + FSL_IMX6UL_EIM_ALIAS_ADDR = 0x58000000, | ||
58 | + FSL_IMX6UL_EIM_ALIAS_SIZE = (128 * MiB), | ||
59 | + | ||
60 | + FSL_IMX6UL_EIM_CS_ADDR = 0x50000000, | ||
61 | + FSL_IMX6UL_EIM_CS_SIZE = (128 * MiB), | ||
62 | + | ||
63 | + FSL_IMX6UL_AES_ENCRYPT_ADDR = 0x10000000, | ||
64 | + FSL_IMX6UL_AES_ENCRYPT_SIZE = (1 * MiB), | ||
65 | + | ||
66 | + FSL_IMX6UL_QSPI1_RX_ADDR = 0x0C000000, | ||
67 | + FSL_IMX6UL_QSPI1_RX_SIZE = (32 * MiB), | ||
68 | + | ||
69 | + /* AIPS-2 Begin */ | ||
70 | FSL_IMX6UL_UART6_ADDR = 0x021FC000, | ||
71 | + | ||
72 | FSL_IMX6UL_I2C4_ADDR = 0x021F8000, | ||
73 | + | ||
74 | FSL_IMX6UL_UART5_ADDR = 0x021F4000, | ||
75 | FSL_IMX6UL_UART4_ADDR = 0x021F0000, | ||
76 | FSL_IMX6UL_UART3_ADDR = 0x021EC000, | ||
77 | FSL_IMX6UL_UART2_ADDR = 0x021E8000, | ||
78 | + | ||
79 | FSL_IMX6UL_WDOG3_ADDR = 0x021E4000, | ||
80 | + | ||
81 | FSL_IMX6UL_QSPI_ADDR = 0x021E0000, | ||
82 | + FSL_IMX6UL_QSPI_SIZE = 0x500, | ||
83 | + | ||
84 | FSL_IMX6UL_SYS_CNT_CTRL_ADDR = 0x021DC000, | ||
85 | + FSL_IMX6UL_SYS_CNT_CTRL_SIZE = (16 * KiB), | ||
86 | + | ||
87 | FSL_IMX6UL_SYS_CNT_CMP_ADDR = 0x021D8000, | ||
88 | + FSL_IMX6UL_SYS_CNT_CMP_SIZE = (16 * KiB), | ||
89 | + | ||
90 | FSL_IMX6UL_SYS_CNT_RD_ADDR = 0x021D4000, | ||
91 | + FSL_IMX6UL_SYS_CNT_RD_SIZE = (16 * KiB), | ||
92 | + | ||
93 | FSL_IMX6UL_TZASC_ADDR = 0x021D0000, | ||
94 | + FSL_IMX6UL_TZASC_SIZE = (16 * KiB), | ||
95 | + | ||
96 | FSL_IMX6UL_PXP_ADDR = 0x021CC000, | ||
97 | + FSL_IMX6UL_PXP_SIZE = (16 * KiB), | ||
98 | + | ||
99 | FSL_IMX6UL_LCDIF_ADDR = 0x021C8000, | ||
100 | + FSL_IMX6UL_LCDIF_SIZE = 0x100, | ||
101 | + | ||
102 | FSL_IMX6UL_CSI_ADDR = 0x021C4000, | ||
103 | + FSL_IMX6UL_CSI_SIZE = 0x100, | ||
104 | + | ||
105 | FSL_IMX6UL_CSU_ADDR = 0x021C0000, | ||
106 | + FSL_IMX6UL_CSU_SIZE = (16 * KiB), | ||
107 | + | ||
108 | FSL_IMX6UL_OCOTP_CTRL_ADDR = 0x021BC000, | ||
109 | + FSL_IMX6UL_OCOTP_CTRL_SIZE = (4 * KiB), | ||
110 | + | ||
111 | FSL_IMX6UL_EIM_ADDR = 0x021B8000, | ||
112 | + FSL_IMX6UL_EIM_SIZE = 0x100, | ||
113 | + | ||
114 | FSL_IMX6UL_SIM2_ADDR = 0x021B4000, | ||
115 | + | ||
116 | FSL_IMX6UL_MMDC_CFG_ADDR = 0x021B0000, | ||
117 | + FSL_IMX6UL_MMDC_CFG_SIZE = (4 * KiB), | ||
118 | + | ||
119 | FSL_IMX6UL_ROMCP_ADDR = 0x021AC000, | ||
120 | + FSL_IMX6UL_ROMCP_SIZE = 0x300, | ||
121 | + | ||
122 | FSL_IMX6UL_I2C3_ADDR = 0x021A8000, | ||
123 | FSL_IMX6UL_I2C2_ADDR = 0x021A4000, | ||
124 | FSL_IMX6UL_I2C1_ADDR = 0x021A0000, | ||
125 | + | ||
126 | FSL_IMX6UL_ADC2_ADDR = 0x0219C000, | ||
127 | FSL_IMX6UL_ADC1_ADDR = 0x02198000, | ||
128 | + FSL_IMX6UL_ADCn_SIZE = 0x100, | ||
129 | + | ||
130 | FSL_IMX6UL_USDHC2_ADDR = 0x02194000, | ||
131 | FSL_IMX6UL_USDHC1_ADDR = 0x02190000, | ||
132 | - FSL_IMX6UL_SIM1_ADDR = 0x0218C000, | ||
133 | - FSL_IMX6UL_ENET1_ADDR = 0x02188000, | ||
134 | - FSL_IMX6UL_USBO2_USBMISC_ADDR = 0x02184800, | ||
135 | - FSL_IMX6UL_USBO2_USB_ADDR = 0x02184000, | ||
136 | - FSL_IMX6UL_USBO2_PL301_ADDR = 0x02180000, | ||
137 | - FSL_IMX6UL_AIPS2_CFG_ADDR = 0x0217C000, | ||
138 | - FSL_IMX6UL_CAAM_ADDR = 0x02140000, | ||
139 | - FSL_IMX6UL_A7MPCORE_DAP_ADDR = 0x02100000, | ||
140 | |||
141 | - /* AIPS-1 */ | ||
142 | + FSL_IMX6UL_SIM1_ADDR = 0x0218C000, | ||
143 | + FSL_IMX6UL_SIMn_SIZE = (16 * KiB), | ||
144 | + | ||
145 | + FSL_IMX6UL_ENET1_ADDR = 0x02188000, | ||
146 | + | ||
147 | + FSL_IMX6UL_USBO2_USBMISC_ADDR = 0x02184800, | ||
148 | + FSL_IMX6UL_USBO2_USB1_ADDR = 0x02184000, | ||
149 | + FSL_IMX6UL_USBO2_USB2_ADDR = 0x02184200, | ||
150 | + | ||
151 | + FSL_IMX6UL_USBO2_PL301_ADDR = 0x02180000, | ||
152 | + FSL_IMX6UL_USBO2_PL301_SIZE = (16 * KiB), | ||
153 | + | ||
154 | + FSL_IMX6UL_AIPS2_CFG_ADDR = 0x0217C000, | ||
155 | + FSL_IMX6UL_AIPS2_CFG_SIZE = 0x100, | ||
156 | + | ||
157 | + FSL_IMX6UL_CAAM_ADDR = 0x02140000, | ||
158 | + FSL_IMX6UL_CAAM_SIZE = (16 * KiB), | ||
159 | + | ||
160 | + FSL_IMX6UL_A7MPCORE_DAP_ADDR = 0x02100000, | ||
161 | + FSL_IMX6UL_A7MPCORE_DAP_SIZE = (4 * KiB), | ||
162 | + /* AIPS-2 End */ | ||
163 | + | ||
164 | + /* AIPS-1 Begin */ | ||
165 | FSL_IMX6UL_PWM8_ADDR = 0x020FC000, | ||
166 | FSL_IMX6UL_PWM7_ADDR = 0x020F8000, | ||
167 | FSL_IMX6UL_PWM6_ADDR = 0x020F4000, | ||
168 | FSL_IMX6UL_PWM5_ADDR = 0x020F0000, | ||
169 | + | ||
170 | FSL_IMX6UL_SDMA_ADDR = 0x020EC000, | ||
171 | + FSL_IMX6UL_SDMA_SIZE = 0x300, | ||
172 | + | ||
173 | FSL_IMX6UL_GPT2_ADDR = 0x020E8000, | ||
174 | + | ||
175 | FSL_IMX6UL_IOMUXC_GPR_ADDR = 0x020E4000, | ||
176 | + FSL_IMX6UL_IOMUXC_GPR_SIZE = 0x40, | ||
177 | + | ||
178 | FSL_IMX6UL_IOMUXC_ADDR = 0x020E0000, | ||
179 | + FSL_IMX6UL_IOMUXC_SIZE = 0x700, | ||
180 | + | ||
181 | FSL_IMX6UL_GPC_ADDR = 0x020DC000, | ||
182 | + | ||
183 | FSL_IMX6UL_SRC_ADDR = 0x020D8000, | ||
184 | + | ||
185 | FSL_IMX6UL_EPIT2_ADDR = 0x020D4000, | ||
186 | FSL_IMX6UL_EPIT1_ADDR = 0x020D0000, | ||
187 | + | ||
188 | FSL_IMX6UL_SNVS_HP_ADDR = 0x020CC000, | ||
189 | + | ||
190 | FSL_IMX6UL_USBPHY2_ADDR = 0x020CA000, | ||
191 | - FSL_IMX6UL_USBPHY2_SIZE = (4 * 1024), | ||
192 | FSL_IMX6UL_USBPHY1_ADDR = 0x020C9000, | ||
193 | - FSL_IMX6UL_USBPHY1_SIZE = (4 * 1024), | ||
194 | + | ||
195 | FSL_IMX6UL_ANALOG_ADDR = 0x020C8000, | ||
196 | + FSL_IMX6UL_ANALOG_SIZE = 0x300, | ||
197 | + | ||
198 | FSL_IMX6UL_CCM_ADDR = 0x020C4000, | ||
199 | + | ||
200 | FSL_IMX6UL_WDOG2_ADDR = 0x020C0000, | ||
201 | FSL_IMX6UL_WDOG1_ADDR = 0x020BC000, | ||
202 | + | ||
203 | FSL_IMX6UL_KPP_ADDR = 0x020B8000, | ||
204 | + FSL_IMX6UL_KPP_SIZE = 0x10, | ||
205 | + | ||
206 | FSL_IMX6UL_ENET2_ADDR = 0x020B4000, | ||
207 | + | ||
208 | FSL_IMX6UL_SNVS_LP_ADDR = 0x020B0000, | ||
209 | + FSL_IMX6UL_SNVS_LP_SIZE = (16 * KiB), | ||
210 | + | ||
211 | FSL_IMX6UL_GPIO5_ADDR = 0x020AC000, | ||
212 | FSL_IMX6UL_GPIO4_ADDR = 0x020A8000, | ||
213 | FSL_IMX6UL_GPIO3_ADDR = 0x020A4000, | ||
214 | FSL_IMX6UL_GPIO2_ADDR = 0x020A0000, | ||
215 | FSL_IMX6UL_GPIO1_ADDR = 0x0209C000, | ||
216 | + | ||
217 | FSL_IMX6UL_GPT1_ADDR = 0x02098000, | ||
218 | + | ||
219 | FSL_IMX6UL_CAN2_ADDR = 0x02094000, | ||
220 | FSL_IMX6UL_CAN1_ADDR = 0x02090000, | ||
221 | + FSL_IMX6UL_CANn_SIZE = (4 * KiB), | ||
222 | + | ||
223 | FSL_IMX6UL_PWM4_ADDR = 0x0208C000, | ||
224 | FSL_IMX6UL_PWM3_ADDR = 0x02088000, | ||
225 | FSL_IMX6UL_PWM2_ADDR = 0x02084000, | ||
226 | FSL_IMX6UL_PWM1_ADDR = 0x02080000, | ||
227 | + FSL_IMX6UL_PWMn_SIZE = 0x20, | ||
228 | + | ||
229 | FSL_IMX6UL_AIPS1_CFG_ADDR = 0x0207C000, | ||
230 | + FSL_IMX6UL_AIPS1_CFG_SIZE = (16 * KiB), | ||
231 | + | ||
232 | FSL_IMX6UL_BEE_ADDR = 0x02044000, | ||
233 | + FSL_IMX6UL_BEE_SIZE = (16 * KiB), | ||
234 | + | ||
235 | FSL_IMX6UL_TOUCH_CTRL_ADDR = 0x02040000, | ||
236 | + FSL_IMX6UL_TOUCH_CTRL_SIZE = 0x100, | ||
237 | + | ||
238 | FSL_IMX6UL_SPBA_ADDR = 0x0203C000, | ||
239 | + FSL_IMX6UL_SPBA_SIZE = 0x100, | ||
240 | + | ||
241 | FSL_IMX6UL_ASRC_ADDR = 0x02034000, | ||
242 | + FSL_IMX6UL_ASRC_SIZE = 0x100, | ||
243 | + | ||
244 | FSL_IMX6UL_SAI3_ADDR = 0x02030000, | ||
245 | FSL_IMX6UL_SAI2_ADDR = 0x0202C000, | ||
246 | FSL_IMX6UL_SAI1_ADDR = 0x02028000, | ||
247 | + FSL_IMX6UL_SAIn_SIZE = 0x200, | ||
248 | + | ||
249 | FSL_IMX6UL_UART8_ADDR = 0x02024000, | ||
250 | FSL_IMX6UL_UART1_ADDR = 0x02020000, | ||
251 | FSL_IMX6UL_UART7_ADDR = 0x02018000, | ||
252 | + | ||
253 | FSL_IMX6UL_ECSPI4_ADDR = 0x02014000, | ||
254 | FSL_IMX6UL_ECSPI3_ADDR = 0x02010000, | ||
255 | FSL_IMX6UL_ECSPI2_ADDR = 0x0200C000, | ||
256 | FSL_IMX6UL_ECSPI1_ADDR = 0x02008000, | ||
257 | + | ||
258 | FSL_IMX6UL_SPDIF_ADDR = 0x02004000, | ||
259 | + FSL_IMX6UL_SPDIF_SIZE = 0x100, | ||
260 | + /* AIPS-1 End */ | ||
261 | + | ||
262 | + FSL_IMX6UL_BCH_ADDR = 0x01808000, | ||
263 | + FSL_IMX6UL_BCH_SIZE = 0x200, | ||
264 | + | ||
265 | + FSL_IMX6UL_GPMI_ADDR = 0x01806000, | ||
266 | + FSL_IMX6UL_GPMI_SIZE = 0x200, | ||
267 | |||
268 | FSL_IMX6UL_APBH_DMA_ADDR = 0x01804000, | ||
269 | - FSL_IMX6UL_APBH_DMA_SIZE = (32 * 1024), | ||
270 | + FSL_IMX6UL_APBH_DMA_SIZE = (4 * KiB), | ||
271 | |||
272 | FSL_IMX6UL_A7MPCORE_ADDR = 0x00A00000, | ||
273 | |||
274 | FSL_IMX6UL_OCRAM_ALIAS_ADDR = 0x00920000, | ||
275 | - FSL_IMX6UL_OCRAM_ALIAS_SIZE = 0x00060000, | ||
276 | + FSL_IMX6UL_OCRAM_ALIAS_SIZE = (384 * KiB), | ||
277 | + | ||
278 | FSL_IMX6UL_OCRAM_MEM_ADDR = 0x00900000, | ||
279 | - FSL_IMX6UL_OCRAM_MEM_SIZE = 0x00020000, | ||
280 | + FSL_IMX6UL_OCRAM_MEM_SIZE = (128 * KiB), | ||
281 | + | ||
282 | FSL_IMX6UL_CAAM_MEM_ADDR = 0x00100000, | ||
283 | - FSL_IMX6UL_CAAM_MEM_SIZE = 0x00008000, | ||
284 | + FSL_IMX6UL_CAAM_MEM_SIZE = (32 * KiB), | ||
285 | + | ||
286 | FSL_IMX6UL_ROM_ADDR = 0x00000000, | ||
287 | - FSL_IMX6UL_ROM_SIZE = 0x00018000, | ||
288 | + FSL_IMX6UL_ROM_SIZE = (96 * KiB), | ||
289 | }; | ||
290 | |||
291 | enum FslIMX6ULIRQs { | ||
292 | diff --git a/hw/arm/fsl-imx6ul.c b/hw/arm/fsl-imx6ul.c | ||
53 | index XXXXXXX..XXXXXXX 100644 | 293 | index XXXXXXX..XXXXXXX 100644 |
54 | --- a/target/arm/cpu64.c | 294 | --- a/hw/arm/fsl-imx6ul.c |
55 | +++ b/target/arm/cpu64.c | 295 | +++ b/hw/arm/fsl-imx6ul.c |
56 | @@ -XXX,XX +XXX,XX @@ static void aarch64_any_initfn(Object *obj) | 296 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6ul_init(Object *obj) |
57 | set_feature(&cpu->env, ARM_FEATURE_V8_AES); | 297 | object_initialize_child(obj, "snvs", &s->snvs, TYPE_IMX7_SNVS); |
58 | set_feature(&cpu->env, ARM_FEATURE_V8_SHA1); | 298 | |
59 | set_feature(&cpu->env, ARM_FEATURE_V8_SHA256); | 299 | /* |
60 | + set_feature(&cpu->env, ARM_FEATURE_V8_SHA512); | 300 | - * GPIOs 1 to 5 |
61 | + set_feature(&cpu->env, ARM_FEATURE_V8_SHA3); | 301 | + * GPIOs |
62 | + set_feature(&cpu->env, ARM_FEATURE_V8_SM3); | 302 | */ |
63 | + set_feature(&cpu->env, ARM_FEATURE_V8_SM4); | 303 | for (i = 0; i < FSL_IMX6UL_NUM_GPIOS; i++) { |
64 | set_feature(&cpu->env, ARM_FEATURE_V8_PMULL); | 304 | snprintf(name, NAME_SIZE, "gpio%d", i); |
65 | set_feature(&cpu->env, ARM_FEATURE_CRC); | 305 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6ul_init(Object *obj) |
66 | cpu->ctr = 0x80038003; /* 32 byte I and D cacheline size, VIPT icache */ | 306 | } |
307 | |||
308 | /* | ||
309 | - * GPT 1, 2 | ||
310 | + * GPTs | ||
311 | */ | ||
312 | for (i = 0; i < FSL_IMX6UL_NUM_GPTS; i++) { | ||
313 | snprintf(name, NAME_SIZE, "gpt%d", i); | ||
314 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6ul_init(Object *obj) | ||
315 | } | ||
316 | |||
317 | /* | ||
318 | - * EPIT 1, 2 | ||
319 | + * EPITs | ||
320 | */ | ||
321 | for (i = 0; i < FSL_IMX6UL_NUM_EPITS; i++) { | ||
322 | snprintf(name, NAME_SIZE, "epit%d", i + 1); | ||
323 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6ul_init(Object *obj) | ||
324 | } | ||
325 | |||
326 | /* | ||
327 | - * eCSPI | ||
328 | + * eCSPIs | ||
329 | */ | ||
330 | for (i = 0; i < FSL_IMX6UL_NUM_ECSPIS; i++) { | ||
331 | snprintf(name, NAME_SIZE, "spi%d", i + 1); | ||
332 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6ul_init(Object *obj) | ||
333 | } | ||
334 | |||
335 | /* | ||
336 | - * I2C | ||
337 | + * I2Cs | ||
338 | */ | ||
339 | for (i = 0; i < FSL_IMX6UL_NUM_I2CS; i++) { | ||
340 | snprintf(name, NAME_SIZE, "i2c%d", i + 1); | ||
341 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6ul_init(Object *obj) | ||
342 | } | ||
343 | |||
344 | /* | ||
345 | - * UART | ||
346 | + * UARTs | ||
347 | */ | ||
348 | for (i = 0; i < FSL_IMX6UL_NUM_UARTS; i++) { | ||
349 | snprintf(name, NAME_SIZE, "uart%d", i); | ||
350 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6ul_init(Object *obj) | ||
351 | } | ||
352 | |||
353 | /* | ||
354 | - * Ethernet | ||
355 | + * Ethernets | ||
356 | */ | ||
357 | for (i = 0; i < FSL_IMX6UL_NUM_ETHS; i++) { | ||
358 | snprintf(name, NAME_SIZE, "eth%d", i); | ||
359 | object_initialize_child(obj, name, &s->eth[i], TYPE_IMX_ENET); | ||
360 | } | ||
361 | |||
362 | - /* USB */ | ||
363 | + /* | ||
364 | + * USB PHYs | ||
365 | + */ | ||
366 | for (i = 0; i < FSL_IMX6UL_NUM_USB_PHYS; i++) { | ||
367 | snprintf(name, NAME_SIZE, "usbphy%d", i); | ||
368 | object_initialize_child(obj, name, &s->usbphy[i], TYPE_IMX_USBPHY); | ||
369 | } | ||
370 | + | ||
371 | + /* | ||
372 | + * USBs | ||
373 | + */ | ||
374 | for (i = 0; i < FSL_IMX6UL_NUM_USBS; i++) { | ||
375 | snprintf(name, NAME_SIZE, "usb%d", i); | ||
376 | object_initialize_child(obj, name, &s->usb[i], TYPE_CHIPIDEA); | ||
377 | } | ||
378 | |||
379 | /* | ||
380 | - * SDHCI | ||
381 | + * SDHCIs | ||
382 | */ | ||
383 | for (i = 0; i < FSL_IMX6UL_NUM_USDHCS; i++) { | ||
384 | snprintf(name, NAME_SIZE, "usdhc%d", i); | ||
385 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6ul_init(Object *obj) | ||
386 | } | ||
387 | |||
388 | /* | ||
389 | - * Watchdog | ||
390 | + * Watchdogs | ||
391 | */ | ||
392 | for (i = 0; i < FSL_IMX6UL_NUM_WDTS; i++) { | ||
393 | snprintf(name, NAME_SIZE, "wdt%d", i); | ||
394 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp) | ||
395 | * A7MPCORE DAP | ||
396 | */ | ||
397 | create_unimplemented_device("a7mpcore-dap", FSL_IMX6UL_A7MPCORE_DAP_ADDR, | ||
398 | - 0x100000); | ||
399 | + FSL_IMX6UL_A7MPCORE_DAP_SIZE); | ||
400 | |||
401 | /* | ||
402 | - * GPT 1, 2 | ||
403 | + * GPTs | ||
404 | */ | ||
405 | for (i = 0; i < FSL_IMX6UL_NUM_GPTS; i++) { | ||
406 | static const hwaddr FSL_IMX6UL_GPTn_ADDR[FSL_IMX6UL_NUM_GPTS] = { | ||
407 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp) | ||
408 | } | ||
409 | |||
410 | /* | ||
411 | - * EPIT 1, 2 | ||
412 | + * EPITs | ||
413 | */ | ||
414 | for (i = 0; i < FSL_IMX6UL_NUM_EPITS; i++) { | ||
415 | static const hwaddr FSL_IMX6UL_EPITn_ADDR[FSL_IMX6UL_NUM_EPITS] = { | ||
416 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp) | ||
417 | } | ||
418 | |||
419 | /* | ||
420 | - * GPIO | ||
421 | + * GPIOs | ||
422 | */ | ||
423 | for (i = 0; i < FSL_IMX6UL_NUM_GPIOS; i++) { | ||
424 | static const hwaddr FSL_IMX6UL_GPIOn_ADDR[FSL_IMX6UL_NUM_GPIOS] = { | ||
425 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp) | ||
426 | } | ||
427 | |||
428 | /* | ||
429 | - * IOMUXC and IOMUXC_GPR | ||
430 | + * IOMUXC | ||
431 | */ | ||
432 | - for (i = 0; i < 1; i++) { | ||
433 | - static const hwaddr FSL_IMX6UL_IOMUXCn_ADDR[FSL_IMX6UL_NUM_IOMUXCS] = { | ||
434 | - FSL_IMX6UL_IOMUXC_ADDR, | ||
435 | - FSL_IMX6UL_IOMUXC_GPR_ADDR, | ||
436 | - }; | ||
437 | - | ||
438 | - snprintf(name, NAME_SIZE, "iomuxc%d", i); | ||
439 | - create_unimplemented_device(name, FSL_IMX6UL_IOMUXCn_ADDR[i], 0x4000); | ||
440 | - } | ||
441 | + create_unimplemented_device("iomuxc", FSL_IMX6UL_IOMUXC_ADDR, | ||
442 | + FSL_IMX6UL_IOMUXC_SIZE); | ||
443 | + create_unimplemented_device("iomuxc_gpr", FSL_IMX6UL_IOMUXC_GPR_ADDR, | ||
444 | + FSL_IMX6UL_IOMUXC_GPR_SIZE); | ||
445 | |||
446 | /* | ||
447 | * CCM | ||
448 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp) | ||
449 | sysbus_realize(SYS_BUS_DEVICE(&s->gpcv2), &error_abort); | ||
450 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpcv2), 0, FSL_IMX6UL_GPC_ADDR); | ||
451 | |||
452 | - /* Initialize all ECSPI */ | ||
453 | + /* | ||
454 | + * ECSPIs | ||
455 | + */ | ||
456 | for (i = 0; i < FSL_IMX6UL_NUM_ECSPIS; i++) { | ||
457 | static const hwaddr FSL_IMX6UL_SPIn_ADDR[FSL_IMX6UL_NUM_ECSPIS] = { | ||
458 | FSL_IMX6UL_ECSPI1_ADDR, | ||
459 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp) | ||
460 | } | ||
461 | |||
462 | /* | ||
463 | - * I2C | ||
464 | + * I2Cs | ||
465 | */ | ||
466 | for (i = 0; i < FSL_IMX6UL_NUM_I2CS; i++) { | ||
467 | static const hwaddr FSL_IMX6UL_I2Cn_ADDR[FSL_IMX6UL_NUM_I2CS] = { | ||
468 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp) | ||
469 | } | ||
470 | |||
471 | /* | ||
472 | - * UART | ||
473 | + * UARTs | ||
474 | */ | ||
475 | for (i = 0; i < FSL_IMX6UL_NUM_UARTS; i++) { | ||
476 | static const hwaddr FSL_IMX6UL_UARTn_ADDR[FSL_IMX6UL_NUM_UARTS] = { | ||
477 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp) | ||
478 | } | ||
479 | |||
480 | /* | ||
481 | - * Ethernet | ||
482 | + * Ethernets | ||
483 | * | ||
484 | * We must use two loops since phy_connected affects the other interface | ||
485 | * and we have to set all properties before calling sysbus_realize(). | ||
486 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp) | ||
487 | FSL_IMX6UL_ENETn_TIMER_IRQ[i])); | ||
488 | } | ||
489 | |||
490 | - /* USB */ | ||
491 | + /* | ||
492 | + * USB PHYs | ||
493 | + */ | ||
494 | for (i = 0; i < FSL_IMX6UL_NUM_USB_PHYS; i++) { | ||
495 | + static const hwaddr | ||
496 | + FSL_IMX6UL_USB_PHYn_ADDR[FSL_IMX6UL_NUM_USB_PHYS] = { | ||
497 | + FSL_IMX6UL_USBPHY1_ADDR, | ||
498 | + FSL_IMX6UL_USBPHY2_ADDR, | ||
499 | + }; | ||
500 | + | ||
501 | sysbus_realize(SYS_BUS_DEVICE(&s->usbphy[i]), &error_abort); | ||
502 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->usbphy[i]), 0, | ||
503 | - FSL_IMX6UL_USBPHY1_ADDR + i * 0x1000); | ||
504 | + FSL_IMX6UL_USB_PHYn_ADDR[i]); | ||
505 | } | ||
506 | |||
507 | + /* | ||
508 | + * USBs | ||
509 | + */ | ||
510 | for (i = 0; i < FSL_IMX6UL_NUM_USBS; i++) { | ||
511 | + static const hwaddr FSL_IMX6UL_USB02_USBn_ADDR[FSL_IMX6UL_NUM_USBS] = { | ||
512 | + FSL_IMX6UL_USBO2_USB1_ADDR, | ||
513 | + FSL_IMX6UL_USBO2_USB2_ADDR, | ||
514 | + }; | ||
515 | + | ||
516 | static const int FSL_IMX6UL_USBn_IRQ[] = { | ||
517 | FSL_IMX6UL_USB1_IRQ, | ||
518 | FSL_IMX6UL_USB2_IRQ, | ||
519 | }; | ||
520 | + | ||
521 | sysbus_realize(SYS_BUS_DEVICE(&s->usb[i]), &error_abort); | ||
522 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->usb[i]), 0, | ||
523 | - FSL_IMX6UL_USBO2_USB_ADDR + i * 0x200); | ||
524 | + FSL_IMX6UL_USB02_USBn_ADDR[i]); | ||
525 | sysbus_connect_irq(SYS_BUS_DEVICE(&s->usb[i]), 0, | ||
526 | qdev_get_gpio_in(DEVICE(&s->a7mpcore), | ||
527 | FSL_IMX6UL_USBn_IRQ[i])); | ||
528 | } | ||
529 | |||
530 | /* | ||
531 | - * USDHC | ||
532 | + * USDHCs | ||
533 | */ | ||
534 | for (i = 0; i < FSL_IMX6UL_NUM_USDHCS; i++) { | ||
535 | static const hwaddr FSL_IMX6UL_USDHCn_ADDR[FSL_IMX6UL_NUM_USDHCS] = { | ||
536 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp) | ||
537 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->snvs), 0, FSL_IMX6UL_SNVS_HP_ADDR); | ||
538 | |||
539 | /* | ||
540 | - * Watchdog | ||
541 | + * Watchdogs | ||
542 | */ | ||
543 | for (i = 0; i < FSL_IMX6UL_NUM_WDTS; i++) { | ||
544 | static const hwaddr FSL_IMX6UL_WDOGn_ADDR[FSL_IMX6UL_NUM_WDTS] = { | ||
545 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp) | ||
546 | FSL_IMX6UL_WDOG2_ADDR, | ||
547 | FSL_IMX6UL_WDOG3_ADDR, | ||
548 | }; | ||
549 | + | ||
550 | static const int FSL_IMX6UL_WDOGn_IRQ[FSL_IMX6UL_NUM_WDTS] = { | ||
551 | FSL_IMX6UL_WDOG1_IRQ, | ||
552 | FSL_IMX6UL_WDOG2_IRQ, | ||
553 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp) | ||
554 | /* | ||
555 | * SDMA | ||
556 | */ | ||
557 | - create_unimplemented_device("sdma", FSL_IMX6UL_SDMA_ADDR, 0x4000); | ||
558 | + create_unimplemented_device("sdma", FSL_IMX6UL_SDMA_ADDR, | ||
559 | + FSL_IMX6UL_SDMA_SIZE); | ||
560 | |||
561 | /* | ||
562 | - * SAI (Audio SSI (Synchronous Serial Interface)) | ||
563 | + * SAIs (Audio SSI (Synchronous Serial Interface)) | ||
564 | */ | ||
565 | - create_unimplemented_device("sai1", FSL_IMX6UL_SAI1_ADDR, 0x4000); | ||
566 | - create_unimplemented_device("sai2", FSL_IMX6UL_SAI2_ADDR, 0x4000); | ||
567 | - create_unimplemented_device("sai3", FSL_IMX6UL_SAI3_ADDR, 0x4000); | ||
568 | + for (i = 0; i < FSL_IMX6UL_NUM_SAIS; i++) { | ||
569 | + static const hwaddr FSL_IMX6UL_SAIn_ADDR[FSL_IMX6UL_NUM_SAIS] = { | ||
570 | + FSL_IMX6UL_SAI1_ADDR, | ||
571 | + FSL_IMX6UL_SAI2_ADDR, | ||
572 | + FSL_IMX6UL_SAI3_ADDR, | ||
573 | + }; | ||
574 | + | ||
575 | + snprintf(name, NAME_SIZE, "sai%d", i); | ||
576 | + create_unimplemented_device(name, FSL_IMX6UL_SAIn_ADDR[i], | ||
577 | + FSL_IMX6UL_SAIn_SIZE); | ||
578 | + } | ||
579 | |||
580 | /* | ||
581 | - * PWM | ||
582 | + * PWMs | ||
583 | */ | ||
584 | - create_unimplemented_device("pwm1", FSL_IMX6UL_PWM1_ADDR, 0x4000); | ||
585 | - create_unimplemented_device("pwm2", FSL_IMX6UL_PWM2_ADDR, 0x4000); | ||
586 | - create_unimplemented_device("pwm3", FSL_IMX6UL_PWM3_ADDR, 0x4000); | ||
587 | - create_unimplemented_device("pwm4", FSL_IMX6UL_PWM4_ADDR, 0x4000); | ||
588 | + for (i = 0; i < FSL_IMX6UL_NUM_PWMS; i++) { | ||
589 | + static const hwaddr FSL_IMX6UL_PWMn_ADDR[FSL_IMX6UL_NUM_PWMS] = { | ||
590 | + FSL_IMX6UL_PWM1_ADDR, | ||
591 | + FSL_IMX6UL_PWM2_ADDR, | ||
592 | + FSL_IMX6UL_PWM3_ADDR, | ||
593 | + FSL_IMX6UL_PWM4_ADDR, | ||
594 | + }; | ||
595 | + | ||
596 | + snprintf(name, NAME_SIZE, "pwm%d", i); | ||
597 | + create_unimplemented_device(name, FSL_IMX6UL_PWMn_ADDR[i], | ||
598 | + FSL_IMX6UL_PWMn_SIZE); | ||
599 | + } | ||
600 | |||
601 | /* | ||
602 | * Audio ASRC (asynchronous sample rate converter) | ||
603 | */ | ||
604 | - create_unimplemented_device("asrc", FSL_IMX6UL_ASRC_ADDR, 0x4000); | ||
605 | + create_unimplemented_device("asrc", FSL_IMX6UL_ASRC_ADDR, | ||
606 | + FSL_IMX6UL_ASRC_SIZE); | ||
607 | |||
608 | /* | ||
609 | - * CAN | ||
610 | + * CANs | ||
611 | */ | ||
612 | - create_unimplemented_device("can1", FSL_IMX6UL_CAN1_ADDR, 0x4000); | ||
613 | - create_unimplemented_device("can2", FSL_IMX6UL_CAN2_ADDR, 0x4000); | ||
614 | + for (i = 0; i < FSL_IMX6UL_NUM_CANS; i++) { | ||
615 | + static const hwaddr FSL_IMX6UL_CANn_ADDR[FSL_IMX6UL_NUM_CANS] = { | ||
616 | + FSL_IMX6UL_CAN1_ADDR, | ||
617 | + FSL_IMX6UL_CAN2_ADDR, | ||
618 | + }; | ||
619 | + | ||
620 | + snprintf(name, NAME_SIZE, "can%d", i); | ||
621 | + create_unimplemented_device(name, FSL_IMX6UL_CANn_ADDR[i], | ||
622 | + FSL_IMX6UL_CANn_SIZE); | ||
623 | + } | ||
624 | |||
625 | /* | ||
626 | * APHB_DMA | ||
627 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp) | ||
628 | }; | ||
629 | |||
630 | snprintf(name, NAME_SIZE, "adc%d", i); | ||
631 | - create_unimplemented_device(name, FSL_IMX6UL_ADCn_ADDR[i], 0x4000); | ||
632 | + create_unimplemented_device(name, FSL_IMX6UL_ADCn_ADDR[i], | ||
633 | + FSL_IMX6UL_ADCn_SIZE); | ||
634 | } | ||
635 | |||
636 | /* | ||
637 | * LCD | ||
638 | */ | ||
639 | - create_unimplemented_device("lcdif", FSL_IMX6UL_LCDIF_ADDR, 0x4000); | ||
640 | + create_unimplemented_device("lcdif", FSL_IMX6UL_LCDIF_ADDR, | ||
641 | + FSL_IMX6UL_LCDIF_SIZE); | ||
642 | |||
643 | /* | ||
644 | * ROM memory | ||
67 | -- | 645 | -- |
68 | 2.16.1 | 646 | 2.34.1 |
69 | |||
70 | diff view generated by jsdifflib |
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | 1 | From: Jean-Christophe Dubois <jcd@tribudubois.net> |
---|---|---|---|
2 | 2 | ||
3 | Add code to emulate Chipidea USB IP (used in i.MX SoCs). Tested to | 3 | * Add TZASC as unimplemented device. |
4 | work against: | 4 | - Allow bare metal application to access this (unimplemented) device |
5 | * Add CSU as unimplemented device. | ||
6 | - Allow bare metal application to access this (unimplemented) device | ||
7 | * Add 4 missing PWM devices | ||
5 | 8 | ||
6 | -usb -drive if=none,id=stick,file=usb.img,format=raw -device \ | 9 | Signed-off-by: Jean-Christophe Dubois <jcd@tribudubois.net> |
7 | usb-storage,bus=usb-bus.0,drive=stick | 10 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
8 | 11 | Message-id: 59e4dc56e14eccfefd379275ec19048dff9c10b3.1692964892.git.jcd@tribudubois.net | |
9 | Cc: Peter Maydell <peter.maydell@linaro.org> | ||
10 | Cc: Jason Wang <jasowang@redhat.com> | ||
11 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
12 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | ||
13 | Cc: Michael S. Tsirkin <mst@redhat.com> | ||
14 | Cc: qemu-devel@nongnu.org | ||
15 | Cc: qemu-arm@nongnu.org | ||
16 | Cc: yurovsky@gmail.com | ||
17 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
18 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
20 | --- | 13 | --- |
21 | hw/usb/Makefile.objs | 1 + | 14 | include/hw/arm/fsl-imx6ul.h | 2 +- |
22 | include/hw/usb/chipidea.h | 16 +++++ | 15 | hw/arm/fsl-imx6ul.c | 16 ++++++++++++++++ |
23 | hw/usb/chipidea.c | 176 ++++++++++++++++++++++++++++++++++++++++++++++ | 16 | 2 files changed, 17 insertions(+), 1 deletion(-) |
24 | 3 files changed, 193 insertions(+) | ||
25 | create mode 100644 include/hw/usb/chipidea.h | ||
26 | create mode 100644 hw/usb/chipidea.c | ||
27 | 17 | ||
28 | diff --git a/hw/usb/Makefile.objs b/hw/usb/Makefile.objs | 18 | diff --git a/include/hw/arm/fsl-imx6ul.h b/include/hw/arm/fsl-imx6ul.h |
29 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/hw/usb/Makefile.objs | 20 | --- a/include/hw/arm/fsl-imx6ul.h |
31 | +++ b/hw/usb/Makefile.objs | 21 | +++ b/include/hw/arm/fsl-imx6ul.h |
32 | @@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_USB_XHCI_NEC) += hcd-xhci-nec.o | 22 | @@ -XXX,XX +XXX,XX @@ enum FslIMX6ULConfiguration { |
33 | common-obj-$(CONFIG_USB_MUSB) += hcd-musb.o | 23 | FSL_IMX6UL_NUM_USBS = 2, |
34 | 24 | FSL_IMX6UL_NUM_SAIS = 3, | |
35 | obj-$(CONFIG_TUSB6010) += tusb6010.o | 25 | FSL_IMX6UL_NUM_CANS = 2, |
36 | +obj-$(CONFIG_IMX) += chipidea.o | 26 | - FSL_IMX6UL_NUM_PWMS = 4, |
37 | 27 | + FSL_IMX6UL_NUM_PWMS = 8, | |
38 | # emulated usb devices | 28 | }; |
39 | common-obj-$(CONFIG_USB) += dev-hub.o | 29 | |
40 | diff --git a/include/hw/usb/chipidea.h b/include/hw/usb/chipidea.h | 30 | struct FslIMX6ULState { |
41 | new file mode 100644 | 31 | diff --git a/hw/arm/fsl-imx6ul.c b/hw/arm/fsl-imx6ul.c |
42 | index XXXXXXX..XXXXXXX | 32 | index XXXXXXX..XXXXXXX 100644 |
43 | --- /dev/null | 33 | --- a/hw/arm/fsl-imx6ul.c |
44 | +++ b/include/hw/usb/chipidea.h | 34 | +++ b/hw/arm/fsl-imx6ul.c |
45 | @@ -XXX,XX +XXX,XX @@ | 35 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp) |
46 | +#ifndef CHIPIDEA_H | 36 | FSL_IMX6UL_PWM2_ADDR, |
47 | +#define CHIPIDEA_H | 37 | FSL_IMX6UL_PWM3_ADDR, |
48 | + | 38 | FSL_IMX6UL_PWM4_ADDR, |
49 | +#include "hw/usb/hcd-ehci.h" | 39 | + FSL_IMX6UL_PWM5_ADDR, |
50 | + | 40 | + FSL_IMX6UL_PWM6_ADDR, |
51 | +typedef struct ChipideaState { | 41 | + FSL_IMX6UL_PWM7_ADDR, |
52 | + /*< private >*/ | 42 | + FSL_IMX6UL_PWM8_ADDR, |
53 | + EHCISysBusState parent_obj; | 43 | }; |
54 | + | 44 | |
55 | + MemoryRegion iomem[3]; | 45 | snprintf(name, NAME_SIZE, "pwm%d", i); |
56 | +} ChipideaState; | 46 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp) |
57 | + | 47 | create_unimplemented_device("lcdif", FSL_IMX6UL_LCDIF_ADDR, |
58 | +#define TYPE_CHIPIDEA "usb-chipidea" | 48 | FSL_IMX6UL_LCDIF_SIZE); |
59 | +#define CHIPIDEA(obj) OBJECT_CHECK(ChipideaState, (obj), TYPE_CHIPIDEA) | 49 | |
60 | + | 50 | + /* |
61 | +#endif /* CHIPIDEA_H */ | 51 | + * CSU |
62 | diff --git a/hw/usb/chipidea.c b/hw/usb/chipidea.c | 52 | + */ |
63 | new file mode 100644 | 53 | + create_unimplemented_device("csu", FSL_IMX6UL_CSU_ADDR, |
64 | index XXXXXXX..XXXXXXX | 54 | + FSL_IMX6UL_CSU_SIZE); |
65 | --- /dev/null | ||
66 | +++ b/hw/usb/chipidea.c | ||
67 | @@ -XXX,XX +XXX,XX @@ | ||
68 | +/* | ||
69 | + * Copyright (c) 2018, Impinj, Inc. | ||
70 | + * | ||
71 | + * Chipidea USB block emulation code | ||
72 | + * | ||
73 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
74 | + * | ||
75 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
76 | + * See the COPYING file in the top-level directory. | ||
77 | + */ | ||
78 | + | ||
79 | +#include "qemu/osdep.h" | ||
80 | +#include "hw/usb/hcd-ehci.h" | ||
81 | +#include "hw/usb/chipidea.h" | ||
82 | +#include "qemu/log.h" | ||
83 | + | ||
84 | +enum { | ||
85 | + CHIPIDEA_USBx_DCIVERSION = 0x000, | ||
86 | + CHIPIDEA_USBx_DCCPARAMS = 0x004, | ||
87 | + CHIPIDEA_USBx_DCCPARAMS_HC = BIT(8), | ||
88 | +}; | ||
89 | + | ||
90 | +static uint64_t chipidea_read(void *opaque, hwaddr offset, | ||
91 | + unsigned size) | ||
92 | +{ | ||
93 | + return 0; | ||
94 | +} | ||
95 | + | ||
96 | +static void chipidea_write(void *opaque, hwaddr offset, | ||
97 | + uint64_t value, unsigned size) | ||
98 | +{ | ||
99 | +} | ||
100 | + | ||
101 | +static const struct MemoryRegionOps chipidea_ops = { | ||
102 | + .read = chipidea_read, | ||
103 | + .write = chipidea_write, | ||
104 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
105 | + .impl = { | ||
106 | + /* | ||
107 | + * Our device would not work correctly if the guest was doing | ||
108 | + * unaligned access. This might not be a limitation on the | ||
109 | + * real device but in practice there is no reason for a guest | ||
110 | + * to access this device unaligned. | ||
111 | + */ | ||
112 | + .min_access_size = 4, | ||
113 | + .max_access_size = 4, | ||
114 | + .unaligned = false, | ||
115 | + }, | ||
116 | +}; | ||
117 | + | ||
118 | +static uint64_t chipidea_dc_read(void *opaque, hwaddr offset, | ||
119 | + unsigned size) | ||
120 | +{ | ||
121 | + switch (offset) { | ||
122 | + case CHIPIDEA_USBx_DCIVERSION: | ||
123 | + return 0x1; | ||
124 | + case CHIPIDEA_USBx_DCCPARAMS: | ||
125 | + /* | ||
126 | + * Real hardware (at least i.MX7) will also report the | ||
127 | + * controller as "Device Capable" (and 8 supported endpoints), | ||
128 | + * but there doesn't seem to be much point in doing so, since | ||
129 | + * we don't emulate that part. | ||
130 | + */ | ||
131 | + return CHIPIDEA_USBx_DCCPARAMS_HC; | ||
132 | + } | ||
133 | + | ||
134 | + return 0; | ||
135 | +} | ||
136 | + | ||
137 | +static void chipidea_dc_write(void *opaque, hwaddr offset, | ||
138 | + uint64_t value, unsigned size) | ||
139 | +{ | ||
140 | +} | ||
141 | + | ||
142 | +static const struct MemoryRegionOps chipidea_dc_ops = { | ||
143 | + .read = chipidea_dc_read, | ||
144 | + .write = chipidea_dc_write, | ||
145 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
146 | + .impl = { | ||
147 | + /* | ||
148 | + * Our device would not work correctly if the guest was doing | ||
149 | + * unaligned access. This might not be a limitation on the real | ||
150 | + * device but in practice there is no reason for a guest to access | ||
151 | + * this device unaligned. | ||
152 | + */ | ||
153 | + .min_access_size = 4, | ||
154 | + .max_access_size = 4, | ||
155 | + .unaligned = false, | ||
156 | + }, | ||
157 | +}; | ||
158 | + | ||
159 | +static void chipidea_init(Object *obj) | ||
160 | +{ | ||
161 | + EHCIState *ehci = &SYS_BUS_EHCI(obj)->ehci; | ||
162 | + ChipideaState *ci = CHIPIDEA(obj); | ||
163 | + int i; | ||
164 | + | ||
165 | + for (i = 0; i < ARRAY_SIZE(ci->iomem); i++) { | ||
166 | + const struct { | ||
167 | + const char *name; | ||
168 | + hwaddr offset; | ||
169 | + uint64_t size; | ||
170 | + const struct MemoryRegionOps *ops; | ||
171 | + } regions[ARRAY_SIZE(ci->iomem)] = { | ||
172 | + /* | ||
173 | + * Registers located between offsets 0x000 and 0xFC | ||
174 | + */ | ||
175 | + { | ||
176 | + .name = TYPE_CHIPIDEA ".misc", | ||
177 | + .offset = 0x000, | ||
178 | + .size = 0x100, | ||
179 | + .ops = &chipidea_ops, | ||
180 | + }, | ||
181 | + /* | ||
182 | + * Registers located between offsets 0x1A4 and 0x1DC | ||
183 | + */ | ||
184 | + { | ||
185 | + .name = TYPE_CHIPIDEA ".endpoints", | ||
186 | + .offset = 0x1A4, | ||
187 | + .size = 0x1DC - 0x1A4 + 4, | ||
188 | + .ops = &chipidea_ops, | ||
189 | + }, | ||
190 | + /* | ||
191 | + * USB_x_DCIVERSION and USB_x_DCCPARAMS | ||
192 | + */ | ||
193 | + { | ||
194 | + .name = TYPE_CHIPIDEA ".dc", | ||
195 | + .offset = 0x120, | ||
196 | + .size = 8, | ||
197 | + .ops = &chipidea_dc_ops, | ||
198 | + }, | ||
199 | + }; | ||
200 | + | ||
201 | + memory_region_init_io(&ci->iomem[i], | ||
202 | + obj, | ||
203 | + regions[i].ops, | ||
204 | + ci, | ||
205 | + regions[i].name, | ||
206 | + regions[i].size); | ||
207 | + | ||
208 | + memory_region_add_subregion(&ehci->mem, | ||
209 | + regions[i].offset, | ||
210 | + &ci->iomem[i]); | ||
211 | + } | ||
212 | +} | ||
213 | + | ||
214 | +static void chipidea_class_init(ObjectClass *klass, void *data) | ||
215 | +{ | ||
216 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
217 | + SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(klass); | ||
218 | + | 55 | + |
219 | + /* | 56 | + /* |
220 | + * Offsets used were taken from i.MX7Dual Applications Processor | 57 | + * TZASC |
221 | + * Reference Manual, Rev 0.1, p. 3177, Table 11-59 | ||
222 | + */ | 58 | + */ |
223 | + sec->capsbase = 0x100; | 59 | + create_unimplemented_device("tzasc", FSL_IMX6UL_TZASC_ADDR, |
224 | + sec->opregbase = 0x140; | 60 | + FSL_IMX6UL_TZASC_SIZE); |
225 | + sec->portnr = 1; | ||
226 | + | 61 | + |
227 | + set_bit(DEVICE_CATEGORY_USB, dc->categories); | 62 | /* |
228 | + dc->desc = "Chipidea USB Module"; | 63 | * ROM memory |
229 | +} | 64 | */ |
230 | + | ||
231 | +static const TypeInfo chipidea_info = { | ||
232 | + .name = TYPE_CHIPIDEA, | ||
233 | + .parent = TYPE_SYS_BUS_EHCI, | ||
234 | + .instance_size = sizeof(ChipideaState), | ||
235 | + .instance_init = chipidea_init, | ||
236 | + .class_init = chipidea_class_init, | ||
237 | +}; | ||
238 | + | ||
239 | +static void chipidea_register_type(void) | ||
240 | +{ | ||
241 | + type_register_static(&chipidea_info); | ||
242 | +} | ||
243 | +type_init(chipidea_register_type) | ||
244 | -- | 65 | -- |
245 | 2.16.1 | 66 | 2.34.1 |
246 | 67 | ||
247 | 68 | diff view generated by jsdifflib |
1 | From: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 1 | From: Jean-Christophe Dubois <jcd@tribudubois.net> |
---|---|---|---|
2 | 2 | ||
3 | This implements emulation of the new SHA-3 instructions that have | 3 | * Add Addr and size definition for all i.MX7 devices in i.MX7 header file. |
4 | been added as an optional extensions to the ARMv8 Crypto Extensions | 4 | * Use those newly defined named constants whenever possible. |
5 | in ARM v8.2. | 5 | * Standardize the way we init a familly of unimplemented devices |
6 | - SAI | ||
7 | - PWM | ||
8 | - CAN | ||
9 | * Add/rework few comments | ||
6 | 10 | ||
7 | Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 11 | Signed-off-by: Jean-Christophe Dubois <jcd@tribudubois.net> |
8 | Message-id: 20180207111729.15737-3-ard.biesheuvel@linaro.org | 12 | Message-id: 59e195d33e4d486a8d131392acd46633c8c10ed7.1692964892.git.jcd@tribudubois.net |
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 15 | --- |
12 | target/arm/cpu.h | 1 + | 16 | include/hw/arm/fsl-imx7.h | 330 ++++++++++++++++++++++++++++---------- |
13 | target/arm/translate-a64.c | 148 +++++++++++++++++++++++++++++++++++++++++++-- | 17 | hw/arm/fsl-imx7.c | 130 ++++++++++----- |
14 | 2 files changed, 145 insertions(+), 4 deletions(-) | 18 | 2 files changed, 335 insertions(+), 125 deletions(-) |
15 | 19 | ||
16 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 20 | diff --git a/include/hw/arm/fsl-imx7.h b/include/hw/arm/fsl-imx7.h |
17 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/arm/cpu.h | 22 | --- a/include/hw/arm/fsl-imx7.h |
19 | +++ b/target/arm/cpu.h | 23 | +++ b/include/hw/arm/fsl-imx7.h |
20 | @@ -XXX,XX +XXX,XX @@ enum arm_features { | 24 | @@ -XXX,XX +XXX,XX @@ |
21 | ARM_FEATURE_JAZELLE, /* has (trivial) Jazelle implementation */ | 25 | #include "hw/misc/imx7_ccm.h" |
22 | ARM_FEATURE_SVE, /* has Scalable Vector Extension */ | 26 | #include "hw/misc/imx7_snvs.h" |
23 | ARM_FEATURE_V8_SHA512, /* implements SHA512 part of v8 Crypto Extensions */ | 27 | #include "hw/misc/imx7_gpr.h" |
24 | + ARM_FEATURE_V8_SHA3, /* implements SHA3 part of v8 Crypto Extensions */ | 28 | -#include "hw/misc/imx6_src.h" |
29 | #include "hw/watchdog/wdt_imx2.h" | ||
30 | #include "hw/gpio/imx_gpio.h" | ||
31 | #include "hw/char/imx_serial.h" | ||
32 | @@ -XXX,XX +XXX,XX @@ | ||
33 | #include "hw/usb/chipidea.h" | ||
34 | #include "cpu.h" | ||
35 | #include "qom/object.h" | ||
36 | +#include "qemu/units.h" | ||
37 | |||
38 | #define TYPE_FSL_IMX7 "fsl-imx7" | ||
39 | OBJECT_DECLARE_SIMPLE_TYPE(FslIMX7State, FSL_IMX7) | ||
40 | @@ -XXX,XX +XXX,XX @@ enum FslIMX7Configuration { | ||
41 | FSL_IMX7_NUM_ECSPIS = 4, | ||
42 | FSL_IMX7_NUM_USBS = 3, | ||
43 | FSL_IMX7_NUM_ADCS = 2, | ||
44 | + FSL_IMX7_NUM_SAIS = 3, | ||
45 | + FSL_IMX7_NUM_CANS = 2, | ||
46 | + FSL_IMX7_NUM_PWMS = 4, | ||
25 | }; | 47 | }; |
26 | 48 | ||
27 | static inline int arm_feature(CPUARMState *env, int feature) | 49 | struct FslIMX7State { |
28 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 50 | @@ -XXX,XX +XXX,XX @@ struct FslIMX7State { |
51 | |||
52 | enum FslIMX7MemoryMap { | ||
53 | FSL_IMX7_MMDC_ADDR = 0x80000000, | ||
54 | - FSL_IMX7_MMDC_SIZE = 2 * 1024 * 1024 * 1024UL, | ||
55 | + FSL_IMX7_MMDC_SIZE = (2 * GiB), | ||
56 | |||
57 | - FSL_IMX7_GPIO1_ADDR = 0x30200000, | ||
58 | - FSL_IMX7_GPIO2_ADDR = 0x30210000, | ||
59 | - FSL_IMX7_GPIO3_ADDR = 0x30220000, | ||
60 | - FSL_IMX7_GPIO4_ADDR = 0x30230000, | ||
61 | - FSL_IMX7_GPIO5_ADDR = 0x30240000, | ||
62 | - FSL_IMX7_GPIO6_ADDR = 0x30250000, | ||
63 | - FSL_IMX7_GPIO7_ADDR = 0x30260000, | ||
64 | + FSL_IMX7_QSPI1_MEM_ADDR = 0x60000000, | ||
65 | + FSL_IMX7_QSPI1_MEM_SIZE = (256 * MiB), | ||
66 | |||
67 | - FSL_IMX7_IOMUXC_LPSR_GPR_ADDR = 0x30270000, | ||
68 | + FSL_IMX7_PCIE1_MEM_ADDR = 0x40000000, | ||
69 | + FSL_IMX7_PCIE1_MEM_SIZE = (256 * MiB), | ||
70 | |||
71 | - FSL_IMX7_WDOG1_ADDR = 0x30280000, | ||
72 | - FSL_IMX7_WDOG2_ADDR = 0x30290000, | ||
73 | - FSL_IMX7_WDOG3_ADDR = 0x302A0000, | ||
74 | - FSL_IMX7_WDOG4_ADDR = 0x302B0000, | ||
75 | + FSL_IMX7_QSPI1_RX_BUF_ADDR = 0x34000000, | ||
76 | + FSL_IMX7_QSPI1_RX_BUF_SIZE = (32 * MiB), | ||
77 | |||
78 | - FSL_IMX7_IOMUXC_LPSR_ADDR = 0x302C0000, | ||
79 | + /* PCIe Peripherals */ | ||
80 | + FSL_IMX7_PCIE_REG_ADDR = 0x33800000, | ||
81 | |||
82 | - FSL_IMX7_GPT1_ADDR = 0x302D0000, | ||
83 | - FSL_IMX7_GPT2_ADDR = 0x302E0000, | ||
84 | - FSL_IMX7_GPT3_ADDR = 0x302F0000, | ||
85 | - FSL_IMX7_GPT4_ADDR = 0x30300000, | ||
86 | + /* MMAP Peripherals */ | ||
87 | + FSL_IMX7_DMA_APBH_ADDR = 0x33000000, | ||
88 | + FSL_IMX7_DMA_APBH_SIZE = 0x8000, | ||
89 | |||
90 | - FSL_IMX7_IOMUXC_ADDR = 0x30330000, | ||
91 | - FSL_IMX7_IOMUXC_GPR_ADDR = 0x30340000, | ||
92 | - FSL_IMX7_IOMUXCn_SIZE = 0x1000, | ||
93 | + /* GPV configuration */ | ||
94 | + FSL_IMX7_GPV6_ADDR = 0x32600000, | ||
95 | + FSL_IMX7_GPV5_ADDR = 0x32500000, | ||
96 | + FSL_IMX7_GPV4_ADDR = 0x32400000, | ||
97 | + FSL_IMX7_GPV3_ADDR = 0x32300000, | ||
98 | + FSL_IMX7_GPV2_ADDR = 0x32200000, | ||
99 | + FSL_IMX7_GPV1_ADDR = 0x32100000, | ||
100 | + FSL_IMX7_GPV0_ADDR = 0x32000000, | ||
101 | + FSL_IMX7_GPVn_SIZE = (1 * MiB), | ||
102 | |||
103 | - FSL_IMX7_OCOTP_ADDR = 0x30350000, | ||
104 | - FSL_IMX7_OCOTP_SIZE = 0x10000, | ||
105 | + /* Arm Peripherals */ | ||
106 | + FSL_IMX7_A7MPCORE_ADDR = 0x31000000, | ||
107 | |||
108 | - FSL_IMX7_ANALOG_ADDR = 0x30360000, | ||
109 | - FSL_IMX7_SNVS_ADDR = 0x30370000, | ||
110 | - FSL_IMX7_CCM_ADDR = 0x30380000, | ||
111 | + /* AIPS-3 Begin */ | ||
112 | |||
113 | - FSL_IMX7_SRC_ADDR = 0x30390000, | ||
114 | - FSL_IMX7_SRC_SIZE = 0x1000, | ||
115 | + FSL_IMX7_ENET2_ADDR = 0x30BF0000, | ||
116 | + FSL_IMX7_ENET1_ADDR = 0x30BE0000, | ||
117 | |||
118 | - FSL_IMX7_ADC1_ADDR = 0x30610000, | ||
119 | - FSL_IMX7_ADC2_ADDR = 0x30620000, | ||
120 | - FSL_IMX7_ADCn_SIZE = 0x1000, | ||
121 | + FSL_IMX7_SDMA_ADDR = 0x30BD0000, | ||
122 | + FSL_IMX7_SDMA_SIZE = (4 * KiB), | ||
123 | |||
124 | - FSL_IMX7_PWM1_ADDR = 0x30660000, | ||
125 | - FSL_IMX7_PWM2_ADDR = 0x30670000, | ||
126 | - FSL_IMX7_PWM3_ADDR = 0x30680000, | ||
127 | - FSL_IMX7_PWM4_ADDR = 0x30690000, | ||
128 | - FSL_IMX7_PWMn_SIZE = 0x10000, | ||
129 | + FSL_IMX7_EIM_ADDR = 0x30BC0000, | ||
130 | + FSL_IMX7_EIM_SIZE = (4 * KiB), | ||
131 | |||
132 | - FSL_IMX7_PCIE_PHY_ADDR = 0x306D0000, | ||
133 | - FSL_IMX7_PCIE_PHY_SIZE = 0x10000, | ||
134 | + FSL_IMX7_QSPI_ADDR = 0x30BB0000, | ||
135 | + FSL_IMX7_QSPI_SIZE = 0x8000, | ||
136 | |||
137 | - FSL_IMX7_GPC_ADDR = 0x303A0000, | ||
138 | + FSL_IMX7_SIM2_ADDR = 0x30BA0000, | ||
139 | + FSL_IMX7_SIM1_ADDR = 0x30B90000, | ||
140 | + FSL_IMX7_SIMn_SIZE = (4 * KiB), | ||
141 | + | ||
142 | + FSL_IMX7_USDHC3_ADDR = 0x30B60000, | ||
143 | + FSL_IMX7_USDHC2_ADDR = 0x30B50000, | ||
144 | + FSL_IMX7_USDHC1_ADDR = 0x30B40000, | ||
145 | + | ||
146 | + FSL_IMX7_USB3_ADDR = 0x30B30000, | ||
147 | + FSL_IMX7_USBMISC3_ADDR = 0x30B30200, | ||
148 | + FSL_IMX7_USB2_ADDR = 0x30B20000, | ||
149 | + FSL_IMX7_USBMISC2_ADDR = 0x30B20200, | ||
150 | + FSL_IMX7_USB1_ADDR = 0x30B10000, | ||
151 | + FSL_IMX7_USBMISC1_ADDR = 0x30B10200, | ||
152 | + FSL_IMX7_USBMISCn_SIZE = 0x200, | ||
153 | + | ||
154 | + FSL_IMX7_USB_PL301_ADDR = 0x30AD0000, | ||
155 | + FSL_IMX7_USB_PL301_SIZE = (64 * KiB), | ||
156 | + | ||
157 | + FSL_IMX7_SEMAPHORE_HS_ADDR = 0x30AC0000, | ||
158 | + FSL_IMX7_SEMAPHORE_HS_SIZE = (64 * KiB), | ||
159 | + | ||
160 | + FSL_IMX7_MUB_ADDR = 0x30AB0000, | ||
161 | + FSL_IMX7_MUA_ADDR = 0x30AA0000, | ||
162 | + FSL_IMX7_MUn_SIZE = (KiB), | ||
163 | + | ||
164 | + FSL_IMX7_UART7_ADDR = 0x30A90000, | ||
165 | + FSL_IMX7_UART6_ADDR = 0x30A80000, | ||
166 | + FSL_IMX7_UART5_ADDR = 0x30A70000, | ||
167 | + FSL_IMX7_UART4_ADDR = 0x30A60000, | ||
168 | + | ||
169 | + FSL_IMX7_I2C4_ADDR = 0x30A50000, | ||
170 | + FSL_IMX7_I2C3_ADDR = 0x30A40000, | ||
171 | + FSL_IMX7_I2C2_ADDR = 0x30A30000, | ||
172 | + FSL_IMX7_I2C1_ADDR = 0x30A20000, | ||
173 | + | ||
174 | + FSL_IMX7_CAN2_ADDR = 0x30A10000, | ||
175 | + FSL_IMX7_CAN1_ADDR = 0x30A00000, | ||
176 | + FSL_IMX7_CANn_SIZE = (4 * KiB), | ||
177 | + | ||
178 | + FSL_IMX7_AIPS3_CONF_ADDR = 0x309F0000, | ||
179 | + FSL_IMX7_AIPS3_CONF_SIZE = (64 * KiB), | ||
180 | |||
181 | FSL_IMX7_CAAM_ADDR = 0x30900000, | ||
182 | - FSL_IMX7_CAAM_SIZE = 0x40000, | ||
183 | + FSL_IMX7_CAAM_SIZE = (256 * KiB), | ||
184 | |||
185 | - FSL_IMX7_CAN1_ADDR = 0x30A00000, | ||
186 | - FSL_IMX7_CAN2_ADDR = 0x30A10000, | ||
187 | - FSL_IMX7_CANn_SIZE = 0x10000, | ||
188 | + FSL_IMX7_SPBA_ADDR = 0x308F0000, | ||
189 | + FSL_IMX7_SPBA_SIZE = (4 * KiB), | ||
190 | |||
191 | - FSL_IMX7_I2C1_ADDR = 0x30A20000, | ||
192 | - FSL_IMX7_I2C2_ADDR = 0x30A30000, | ||
193 | - FSL_IMX7_I2C3_ADDR = 0x30A40000, | ||
194 | - FSL_IMX7_I2C4_ADDR = 0x30A50000, | ||
195 | + FSL_IMX7_SAI3_ADDR = 0x308C0000, | ||
196 | + FSL_IMX7_SAI2_ADDR = 0x308B0000, | ||
197 | + FSL_IMX7_SAI1_ADDR = 0x308A0000, | ||
198 | + FSL_IMX7_SAIn_SIZE = (4 * KiB), | ||
199 | |||
200 | - FSL_IMX7_ECSPI1_ADDR = 0x30820000, | ||
201 | - FSL_IMX7_ECSPI2_ADDR = 0x30830000, | ||
202 | - FSL_IMX7_ECSPI3_ADDR = 0x30840000, | ||
203 | - FSL_IMX7_ECSPI4_ADDR = 0x30630000, | ||
204 | - | ||
205 | - FSL_IMX7_LCDIF_ADDR = 0x30730000, | ||
206 | - FSL_IMX7_LCDIF_SIZE = 0x1000, | ||
207 | - | ||
208 | - FSL_IMX7_UART1_ADDR = 0x30860000, | ||
209 | + FSL_IMX7_UART3_ADDR = 0x30880000, | ||
210 | /* | ||
211 | * Some versions of the reference manual claim that UART2 is @ | ||
212 | * 0x30870000, but experiments with HW + DT files in upstream | ||
213 | @@ -XXX,XX +XXX,XX @@ enum FslIMX7MemoryMap { | ||
214 | * actually located @ 0x30890000 | ||
215 | */ | ||
216 | FSL_IMX7_UART2_ADDR = 0x30890000, | ||
217 | - FSL_IMX7_UART3_ADDR = 0x30880000, | ||
218 | - FSL_IMX7_UART4_ADDR = 0x30A60000, | ||
219 | - FSL_IMX7_UART5_ADDR = 0x30A70000, | ||
220 | - FSL_IMX7_UART6_ADDR = 0x30A80000, | ||
221 | - FSL_IMX7_UART7_ADDR = 0x30A90000, | ||
222 | + FSL_IMX7_UART1_ADDR = 0x30860000, | ||
223 | |||
224 | - FSL_IMX7_SAI1_ADDR = 0x308A0000, | ||
225 | - FSL_IMX7_SAI2_ADDR = 0x308B0000, | ||
226 | - FSL_IMX7_SAI3_ADDR = 0x308C0000, | ||
227 | - FSL_IMX7_SAIn_SIZE = 0x10000, | ||
228 | + FSL_IMX7_ECSPI3_ADDR = 0x30840000, | ||
229 | + FSL_IMX7_ECSPI2_ADDR = 0x30830000, | ||
230 | + FSL_IMX7_ECSPI1_ADDR = 0x30820000, | ||
231 | + FSL_IMX7_ECSPIn_SIZE = (4 * KiB), | ||
232 | |||
233 | - FSL_IMX7_ENET1_ADDR = 0x30BE0000, | ||
234 | - FSL_IMX7_ENET2_ADDR = 0x30BF0000, | ||
235 | + /* AIPS-3 End */ | ||
236 | |||
237 | - FSL_IMX7_USB1_ADDR = 0x30B10000, | ||
238 | - FSL_IMX7_USBMISC1_ADDR = 0x30B10200, | ||
239 | - FSL_IMX7_USB2_ADDR = 0x30B20000, | ||
240 | - FSL_IMX7_USBMISC2_ADDR = 0x30B20200, | ||
241 | - FSL_IMX7_USB3_ADDR = 0x30B30000, | ||
242 | - FSL_IMX7_USBMISC3_ADDR = 0x30B30200, | ||
243 | - FSL_IMX7_USBMISCn_SIZE = 0x200, | ||
244 | + /* AIPS-2 Begin */ | ||
245 | |||
246 | - FSL_IMX7_USDHC1_ADDR = 0x30B40000, | ||
247 | - FSL_IMX7_USDHC2_ADDR = 0x30B50000, | ||
248 | - FSL_IMX7_USDHC3_ADDR = 0x30B60000, | ||
249 | + FSL_IMX7_AXI_DEBUG_MON_ADDR = 0x307E0000, | ||
250 | + FSL_IMX7_AXI_DEBUG_MON_SIZE = (64 * KiB), | ||
251 | |||
252 | - FSL_IMX7_SDMA_ADDR = 0x30BD0000, | ||
253 | - FSL_IMX7_SDMA_SIZE = 0x1000, | ||
254 | + FSL_IMX7_PERFMON2_ADDR = 0x307D0000, | ||
255 | + FSL_IMX7_PERFMON1_ADDR = 0x307C0000, | ||
256 | + FSL_IMX7_PERFMONn_SIZE = (64 * KiB), | ||
257 | + | ||
258 | + FSL_IMX7_DDRC_ADDR = 0x307A0000, | ||
259 | + FSL_IMX7_DDRC_SIZE = (4 * KiB), | ||
260 | + | ||
261 | + FSL_IMX7_DDRC_PHY_ADDR = 0x30790000, | ||
262 | + FSL_IMX7_DDRC_PHY_SIZE = (4 * KiB), | ||
263 | + | ||
264 | + FSL_IMX7_TZASC_ADDR = 0x30780000, | ||
265 | + FSL_IMX7_TZASC_SIZE = (64 * KiB), | ||
266 | + | ||
267 | + FSL_IMX7_MIPI_DSI_ADDR = 0x30760000, | ||
268 | + FSL_IMX7_MIPI_DSI_SIZE = (4 * KiB), | ||
269 | + | ||
270 | + FSL_IMX7_MIPI_CSI_ADDR = 0x30750000, | ||
271 | + FSL_IMX7_MIPI_CSI_SIZE = 0x4000, | ||
272 | + | ||
273 | + FSL_IMX7_LCDIF_ADDR = 0x30730000, | ||
274 | + FSL_IMX7_LCDIF_SIZE = 0x8000, | ||
275 | + | ||
276 | + FSL_IMX7_CSI_ADDR = 0x30710000, | ||
277 | + FSL_IMX7_CSI_SIZE = (4 * KiB), | ||
278 | + | ||
279 | + FSL_IMX7_PXP_ADDR = 0x30700000, | ||
280 | + FSL_IMX7_PXP_SIZE = 0x4000, | ||
281 | + | ||
282 | + FSL_IMX7_EPDC_ADDR = 0x306F0000, | ||
283 | + FSL_IMX7_EPDC_SIZE = (4 * KiB), | ||
284 | + | ||
285 | + FSL_IMX7_PCIE_PHY_ADDR = 0x306D0000, | ||
286 | + FSL_IMX7_PCIE_PHY_SIZE = (4 * KiB), | ||
287 | + | ||
288 | + FSL_IMX7_SYSCNT_CTRL_ADDR = 0x306C0000, | ||
289 | + FSL_IMX7_SYSCNT_CMP_ADDR = 0x306B0000, | ||
290 | + FSL_IMX7_SYSCNT_RD_ADDR = 0x306A0000, | ||
291 | + | ||
292 | + FSL_IMX7_PWM4_ADDR = 0x30690000, | ||
293 | + FSL_IMX7_PWM3_ADDR = 0x30680000, | ||
294 | + FSL_IMX7_PWM2_ADDR = 0x30670000, | ||
295 | + FSL_IMX7_PWM1_ADDR = 0x30660000, | ||
296 | + FSL_IMX7_PWMn_SIZE = (4 * KiB), | ||
297 | + | ||
298 | + FSL_IMX7_FlEXTIMER2_ADDR = 0x30650000, | ||
299 | + FSL_IMX7_FlEXTIMER1_ADDR = 0x30640000, | ||
300 | + FSL_IMX7_FLEXTIMERn_SIZE = (4 * KiB), | ||
301 | + | ||
302 | + FSL_IMX7_ECSPI4_ADDR = 0x30630000, | ||
303 | + | ||
304 | + FSL_IMX7_ADC2_ADDR = 0x30620000, | ||
305 | + FSL_IMX7_ADC1_ADDR = 0x30610000, | ||
306 | + FSL_IMX7_ADCn_SIZE = (4 * KiB), | ||
307 | + | ||
308 | + FSL_IMX7_AIPS2_CONF_ADDR = 0x305F0000, | ||
309 | + FSL_IMX7_AIPS2_CONF_SIZE = (64 * KiB), | ||
310 | + | ||
311 | + /* AIPS-2 End */ | ||
312 | + | ||
313 | + /* AIPS-1 Begin */ | ||
314 | + | ||
315 | + FSL_IMX7_CSU_ADDR = 0x303E0000, | ||
316 | + FSL_IMX7_CSU_SIZE = (64 * KiB), | ||
317 | + | ||
318 | + FSL_IMX7_RDC_ADDR = 0x303D0000, | ||
319 | + FSL_IMX7_RDC_SIZE = (4 * KiB), | ||
320 | + | ||
321 | + FSL_IMX7_SEMAPHORE2_ADDR = 0x303C0000, | ||
322 | + FSL_IMX7_SEMAPHORE1_ADDR = 0x303B0000, | ||
323 | + FSL_IMX7_SEMAPHOREn_SIZE = (4 * KiB), | ||
324 | + | ||
325 | + FSL_IMX7_GPC_ADDR = 0x303A0000, | ||
326 | + | ||
327 | + FSL_IMX7_SRC_ADDR = 0x30390000, | ||
328 | + FSL_IMX7_SRC_SIZE = (4 * KiB), | ||
329 | + | ||
330 | + FSL_IMX7_CCM_ADDR = 0x30380000, | ||
331 | + | ||
332 | + FSL_IMX7_SNVS_HP_ADDR = 0x30370000, | ||
333 | + | ||
334 | + FSL_IMX7_ANALOG_ADDR = 0x30360000, | ||
335 | + | ||
336 | + FSL_IMX7_OCOTP_ADDR = 0x30350000, | ||
337 | + FSL_IMX7_OCOTP_SIZE = 0x10000, | ||
338 | + | ||
339 | + FSL_IMX7_IOMUXC_GPR_ADDR = 0x30340000, | ||
340 | + FSL_IMX7_IOMUXC_GPR_SIZE = (4 * KiB), | ||
341 | + | ||
342 | + FSL_IMX7_IOMUXC_ADDR = 0x30330000, | ||
343 | + FSL_IMX7_IOMUXC_SIZE = (4 * KiB), | ||
344 | + | ||
345 | + FSL_IMX7_KPP_ADDR = 0x30320000, | ||
346 | + FSL_IMX7_KPP_SIZE = (4 * KiB), | ||
347 | + | ||
348 | + FSL_IMX7_ROMCP_ADDR = 0x30310000, | ||
349 | + FSL_IMX7_ROMCP_SIZE = (4 * KiB), | ||
350 | + | ||
351 | + FSL_IMX7_GPT4_ADDR = 0x30300000, | ||
352 | + FSL_IMX7_GPT3_ADDR = 0x302F0000, | ||
353 | + FSL_IMX7_GPT2_ADDR = 0x302E0000, | ||
354 | + FSL_IMX7_GPT1_ADDR = 0x302D0000, | ||
355 | + | ||
356 | + FSL_IMX7_IOMUXC_LPSR_ADDR = 0x302C0000, | ||
357 | + FSL_IMX7_IOMUXC_LPSR_SIZE = (4 * KiB), | ||
358 | + | ||
359 | + FSL_IMX7_WDOG4_ADDR = 0x302B0000, | ||
360 | + FSL_IMX7_WDOG3_ADDR = 0x302A0000, | ||
361 | + FSL_IMX7_WDOG2_ADDR = 0x30290000, | ||
362 | + FSL_IMX7_WDOG1_ADDR = 0x30280000, | ||
363 | + | ||
364 | + FSL_IMX7_IOMUXC_LPSR_GPR_ADDR = 0x30270000, | ||
365 | + | ||
366 | + FSL_IMX7_GPIO7_ADDR = 0x30260000, | ||
367 | + FSL_IMX7_GPIO6_ADDR = 0x30250000, | ||
368 | + FSL_IMX7_GPIO5_ADDR = 0x30240000, | ||
369 | + FSL_IMX7_GPIO4_ADDR = 0x30230000, | ||
370 | + FSL_IMX7_GPIO3_ADDR = 0x30220000, | ||
371 | + FSL_IMX7_GPIO2_ADDR = 0x30210000, | ||
372 | + FSL_IMX7_GPIO1_ADDR = 0x30200000, | ||
373 | + | ||
374 | + FSL_IMX7_AIPS1_CONF_ADDR = 0x301F0000, | ||
375 | + FSL_IMX7_AIPS1_CONF_SIZE = (64 * KiB), | ||
376 | |||
377 | - FSL_IMX7_A7MPCORE_ADDR = 0x31000000, | ||
378 | FSL_IMX7_A7MPCORE_DAP_ADDR = 0x30000000, | ||
379 | + FSL_IMX7_A7MPCORE_DAP_SIZE = (1 * MiB), | ||
380 | |||
381 | - FSL_IMX7_PCIE_REG_ADDR = 0x33800000, | ||
382 | - FSL_IMX7_PCIE_REG_SIZE = 16 * 1024, | ||
383 | + /* AIPS-1 End */ | ||
384 | |||
385 | - FSL_IMX7_GPR_ADDR = 0x30340000, | ||
386 | + FSL_IMX7_EIM_CS0_ADDR = 0x28000000, | ||
387 | + FSL_IMX7_EIM_CS0_SIZE = (128 * MiB), | ||
388 | |||
389 | - FSL_IMX7_DMA_APBH_ADDR = 0x33000000, | ||
390 | - FSL_IMX7_DMA_APBH_SIZE = 0x2000, | ||
391 | + FSL_IMX7_OCRAM_PXP_ADDR = 0x00940000, | ||
392 | + FSL_IMX7_OCRAM_PXP_SIZE = (32 * KiB), | ||
393 | + | ||
394 | + FSL_IMX7_OCRAM_EPDC_ADDR = 0x00920000, | ||
395 | + FSL_IMX7_OCRAM_EPDC_SIZE = (128 * KiB), | ||
396 | + | ||
397 | + FSL_IMX7_OCRAM_MEM_ADDR = 0x00900000, | ||
398 | + FSL_IMX7_OCRAM_MEM_SIZE = (128 * KiB), | ||
399 | + | ||
400 | + FSL_IMX7_TCMU_ADDR = 0x00800000, | ||
401 | + FSL_IMX7_TCMU_SIZE = (32 * KiB), | ||
402 | + | ||
403 | + FSL_IMX7_TCML_ADDR = 0x007F8000, | ||
404 | + FSL_IMX7_TCML_SIZE = (32 * KiB), | ||
405 | + | ||
406 | + FSL_IMX7_OCRAM_S_ADDR = 0x00180000, | ||
407 | + FSL_IMX7_OCRAM_S_SIZE = (32 * KiB), | ||
408 | + | ||
409 | + FSL_IMX7_CAAM_MEM_ADDR = 0x00100000, | ||
410 | + FSL_IMX7_CAAM_MEM_SIZE = (32 * KiB), | ||
411 | + | ||
412 | + FSL_IMX7_ROM_ADDR = 0x00000000, | ||
413 | + FSL_IMX7_ROM_SIZE = (96 * KiB), | ||
414 | }; | ||
415 | |||
416 | enum FslIMX7IRQs { | ||
417 | diff --git a/hw/arm/fsl-imx7.c b/hw/arm/fsl-imx7.c | ||
29 | index XXXXXXX..XXXXXXX 100644 | 418 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/target/arm/translate-a64.c | 419 | --- a/hw/arm/fsl-imx7.c |
31 | +++ b/target/arm/translate-a64.c | 420 | +++ b/hw/arm/fsl-imx7.c |
32 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | 421 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx7_init(Object *obj) |
33 | feature = ARM_FEATURE_V8_SHA512; | 422 | char name[NAME_SIZE]; |
34 | genfn = gen_helper_crypto_sha512su1; | 423 | int i; |
35 | break; | 424 | |
36 | - default: | 425 | + /* |
37 | - unallocated_encoding(s); | 426 | + * CPUs |
38 | - return; | 427 | + */ |
39 | + case 3: /* RAX1 */ | 428 | for (i = 0; i < MIN(ms->smp.cpus, FSL_IMX7_NUM_CPUS); i++) { |
40 | + feature = ARM_FEATURE_V8_SHA3; | 429 | snprintf(name, NAME_SIZE, "cpu%d", i); |
41 | + genfn = NULL; | 430 | object_initialize_child(obj, name, &s->cpu[i], |
42 | + break; | 431 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx7_init(Object *obj) |
43 | } | 432 | TYPE_A15MPCORE_PRIV); |
44 | } else { | 433 | |
45 | unallocated_encoding(s); | 434 | /* |
46 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | 435 | - * GPIOs 1 to 7 |
47 | tcg_temp_free_ptr(tcg_rn_ptr); | 436 | + * GPIOs |
48 | tcg_temp_free_ptr(tcg_rm_ptr); | 437 | */ |
49 | } else { | 438 | for (i = 0; i < FSL_IMX7_NUM_GPIOS; i++) { |
50 | - g_assert_not_reached(); | 439 | snprintf(name, NAME_SIZE, "gpio%d", i); |
51 | + TCGv_i64 tcg_op1, tcg_op2, tcg_res[2]; | 440 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx7_init(Object *obj) |
52 | + int pass; | 441 | } |
53 | + | 442 | |
54 | + tcg_op1 = tcg_temp_new_i64(); | 443 | /* |
55 | + tcg_op2 = tcg_temp_new_i64(); | 444 | - * GPT1, 2, 3, 4 |
56 | + tcg_res[0] = tcg_temp_new_i64(); | 445 | + * GPTs |
57 | + tcg_res[1] = tcg_temp_new_i64(); | 446 | */ |
58 | + | 447 | for (i = 0; i < FSL_IMX7_NUM_GPTS; i++) { |
59 | + for (pass = 0; pass < 2; pass++) { | 448 | snprintf(name, NAME_SIZE, "gpt%d", i); |
60 | + read_vec_element(s, tcg_op1, rn, pass, MO_64); | 449 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx7_init(Object *obj) |
61 | + read_vec_element(s, tcg_op2, rm, pass, MO_64); | 450 | */ |
62 | + | 451 | object_initialize_child(obj, "gpcv2", &s->gpcv2, TYPE_IMX_GPCV2); |
63 | + tcg_gen_rotli_i64(tcg_res[pass], tcg_op2, 1); | 452 | |
64 | + tcg_gen_xor_i64(tcg_res[pass], tcg_res[pass], tcg_op1); | 453 | + /* |
65 | + } | 454 | + * ECSPIs |
66 | + write_vec_element(s, tcg_res[0], rd, 0, MO_64); | 455 | + */ |
67 | + write_vec_element(s, tcg_res[1], rd, 1, MO_64); | 456 | for (i = 0; i < FSL_IMX7_NUM_ECSPIS; i++) { |
68 | + | 457 | snprintf(name, NAME_SIZE, "spi%d", i + 1); |
69 | + tcg_temp_free_i64(tcg_op1); | 458 | object_initialize_child(obj, name, &s->spi[i], TYPE_IMX_SPI); |
70 | + tcg_temp_free_i64(tcg_op2); | 459 | } |
71 | + tcg_temp_free_i64(tcg_res[0]); | 460 | |
72 | + tcg_temp_free_i64(tcg_res[1]); | 461 | - |
73 | } | 462 | + /* |
463 | + * I2Cs | ||
464 | + */ | ||
465 | for (i = 0; i < FSL_IMX7_NUM_I2CS; i++) { | ||
466 | snprintf(name, NAME_SIZE, "i2c%d", i + 1); | ||
467 | object_initialize_child(obj, name, &s->i2c[i], TYPE_IMX_I2C); | ||
468 | } | ||
469 | |||
470 | /* | ||
471 | - * UART | ||
472 | + * UARTs | ||
473 | */ | ||
474 | for (i = 0; i < FSL_IMX7_NUM_UARTS; i++) { | ||
475 | snprintf(name, NAME_SIZE, "uart%d", i); | ||
476 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx7_init(Object *obj) | ||
477 | } | ||
478 | |||
479 | /* | ||
480 | - * Ethernet | ||
481 | + * Ethernets | ||
482 | */ | ||
483 | for (i = 0; i < FSL_IMX7_NUM_ETHS; i++) { | ||
484 | snprintf(name, NAME_SIZE, "eth%d", i); | ||
485 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx7_init(Object *obj) | ||
486 | } | ||
487 | |||
488 | /* | ||
489 | - * SDHCI | ||
490 | + * SDHCIs | ||
491 | */ | ||
492 | for (i = 0; i < FSL_IMX7_NUM_USDHCS; i++) { | ||
493 | snprintf(name, NAME_SIZE, "usdhc%d", i); | ||
494 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx7_init(Object *obj) | ||
495 | object_initialize_child(obj, "snvs", &s->snvs, TYPE_IMX7_SNVS); | ||
496 | |||
497 | /* | ||
498 | - * Watchdog | ||
499 | + * Watchdogs | ||
500 | */ | ||
501 | for (i = 0; i < FSL_IMX7_NUM_WDTS; i++) { | ||
502 | snprintf(name, NAME_SIZE, "wdt%d", i); | ||
503 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx7_init(Object *obj) | ||
504 | */ | ||
505 | object_initialize_child(obj, "gpr", &s->gpr, TYPE_IMX7_GPR); | ||
506 | |||
507 | + /* | ||
508 | + * PCIE | ||
509 | + */ | ||
510 | object_initialize_child(obj, "pcie", &s->pcie, TYPE_DESIGNWARE_PCIE_HOST); | ||
511 | |||
512 | + /* | ||
513 | + * USBs | ||
514 | + */ | ||
515 | for (i = 0; i < FSL_IMX7_NUM_USBS; i++) { | ||
516 | snprintf(name, NAME_SIZE, "usb%d", i); | ||
517 | object_initialize_child(obj, name, &s->usb[i], TYPE_CHIPIDEA); | ||
518 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp) | ||
519 | return; | ||
520 | } | ||
521 | |||
522 | + /* | ||
523 | + * CPUs | ||
524 | + */ | ||
525 | for (i = 0; i < smp_cpus; i++) { | ||
526 | o = OBJECT(&s->cpu[i]); | ||
527 | |||
528 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp) | ||
529 | * A7MPCORE DAP | ||
530 | */ | ||
531 | create_unimplemented_device("a7mpcore-dap", FSL_IMX7_A7MPCORE_DAP_ADDR, | ||
532 | - 0x100000); | ||
533 | + FSL_IMX7_A7MPCORE_DAP_SIZE); | ||
534 | |||
535 | /* | ||
536 | - * GPT1, 2, 3, 4 | ||
537 | + * GPTs | ||
538 | */ | ||
539 | for (i = 0; i < FSL_IMX7_NUM_GPTS; i++) { | ||
540 | static const hwaddr FSL_IMX7_GPTn_ADDR[FSL_IMX7_NUM_GPTS] = { | ||
541 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp) | ||
542 | FSL_IMX7_GPTn_IRQ[i])); | ||
543 | } | ||
544 | |||
545 | + /* | ||
546 | + * GPIOs | ||
547 | + */ | ||
548 | for (i = 0; i < FSL_IMX7_NUM_GPIOS; i++) { | ||
549 | static const hwaddr FSL_IMX7_GPIOn_ADDR[FSL_IMX7_NUM_GPIOS] = { | ||
550 | FSL_IMX7_GPIO1_ADDR, | ||
551 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp) | ||
552 | /* | ||
553 | * IOMUXC and IOMUXC_LPSR | ||
554 | */ | ||
555 | - for (i = 0; i < FSL_IMX7_NUM_IOMUXCS; i++) { | ||
556 | - static const hwaddr FSL_IMX7_IOMUXCn_ADDR[FSL_IMX7_NUM_IOMUXCS] = { | ||
557 | - FSL_IMX7_IOMUXC_ADDR, | ||
558 | - FSL_IMX7_IOMUXC_LPSR_ADDR, | ||
559 | - }; | ||
560 | - | ||
561 | - snprintf(name, NAME_SIZE, "iomuxc%d", i); | ||
562 | - create_unimplemented_device(name, FSL_IMX7_IOMUXCn_ADDR[i], | ||
563 | - FSL_IMX7_IOMUXCn_SIZE); | ||
564 | - } | ||
565 | + create_unimplemented_device("iomuxc", FSL_IMX7_IOMUXC_ADDR, | ||
566 | + FSL_IMX7_IOMUXC_SIZE); | ||
567 | + create_unimplemented_device("iomuxc_lspr", FSL_IMX7_IOMUXC_LPSR_ADDR, | ||
568 | + FSL_IMX7_IOMUXC_LPSR_SIZE); | ||
569 | |||
570 | /* | ||
571 | * CCM | ||
572 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp) | ||
573 | sysbus_realize(SYS_BUS_DEVICE(&s->gpcv2), &error_abort); | ||
574 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpcv2), 0, FSL_IMX7_GPC_ADDR); | ||
575 | |||
576 | - /* Initialize all ECSPI */ | ||
577 | + /* | ||
578 | + * ECSPIs | ||
579 | + */ | ||
580 | for (i = 0; i < FSL_IMX7_NUM_ECSPIS; i++) { | ||
581 | static const hwaddr FSL_IMX7_SPIn_ADDR[FSL_IMX7_NUM_ECSPIS] = { | ||
582 | FSL_IMX7_ECSPI1_ADDR, | ||
583 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp) | ||
584 | FSL_IMX7_SPIn_IRQ[i])); | ||
585 | } | ||
586 | |||
587 | + /* | ||
588 | + * I2Cs | ||
589 | + */ | ||
590 | for (i = 0; i < FSL_IMX7_NUM_I2CS; i++) { | ||
591 | static const hwaddr FSL_IMX7_I2Cn_ADDR[FSL_IMX7_NUM_I2CS] = { | ||
592 | FSL_IMX7_I2C1_ADDR, | ||
593 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp) | ||
594 | } | ||
595 | |||
596 | /* | ||
597 | - * UART | ||
598 | + * UARTs | ||
599 | */ | ||
600 | for (i = 0; i < FSL_IMX7_NUM_UARTS; i++) { | ||
601 | static const hwaddr FSL_IMX7_UARTn_ADDR[FSL_IMX7_NUM_UARTS] = { | ||
602 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp) | ||
603 | } | ||
604 | |||
605 | /* | ||
606 | - * Ethernet | ||
607 | + * Ethernets | ||
608 | * | ||
609 | * We must use two loops since phy_connected affects the other interface | ||
610 | * and we have to set all properties before calling sysbus_realize(). | ||
611 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp) | ||
612 | } | ||
613 | |||
614 | /* | ||
615 | - * USDHC | ||
616 | + * USDHCs | ||
617 | */ | ||
618 | for (i = 0; i < FSL_IMX7_NUM_USDHCS; i++) { | ||
619 | static const hwaddr FSL_IMX7_USDHCn_ADDR[FSL_IMX7_NUM_USDHCS] = { | ||
620 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp) | ||
621 | * SNVS | ||
622 | */ | ||
623 | sysbus_realize(SYS_BUS_DEVICE(&s->snvs), &error_abort); | ||
624 | - sysbus_mmio_map(SYS_BUS_DEVICE(&s->snvs), 0, FSL_IMX7_SNVS_ADDR); | ||
625 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->snvs), 0, FSL_IMX7_SNVS_HP_ADDR); | ||
626 | |||
627 | /* | ||
628 | * SRC | ||
629 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp) | ||
630 | create_unimplemented_device("src", FSL_IMX7_SRC_ADDR, FSL_IMX7_SRC_SIZE); | ||
631 | |||
632 | /* | ||
633 | - * Watchdog | ||
634 | + * Watchdogs | ||
635 | */ | ||
636 | for (i = 0; i < FSL_IMX7_NUM_WDTS; i++) { | ||
637 | static const hwaddr FSL_IMX7_WDOGn_ADDR[FSL_IMX7_NUM_WDTS] = { | ||
638 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp) | ||
639 | create_unimplemented_device("caam", FSL_IMX7_CAAM_ADDR, FSL_IMX7_CAAM_SIZE); | ||
640 | |||
641 | /* | ||
642 | - * PWM | ||
643 | + * PWMs | ||
644 | */ | ||
645 | - create_unimplemented_device("pwm1", FSL_IMX7_PWM1_ADDR, FSL_IMX7_PWMn_SIZE); | ||
646 | - create_unimplemented_device("pwm2", FSL_IMX7_PWM2_ADDR, FSL_IMX7_PWMn_SIZE); | ||
647 | - create_unimplemented_device("pwm3", FSL_IMX7_PWM3_ADDR, FSL_IMX7_PWMn_SIZE); | ||
648 | - create_unimplemented_device("pwm4", FSL_IMX7_PWM4_ADDR, FSL_IMX7_PWMn_SIZE); | ||
649 | + for (i = 0; i < FSL_IMX7_NUM_PWMS; i++) { | ||
650 | + static const hwaddr FSL_IMX7_PWMn_ADDR[FSL_IMX7_NUM_PWMS] = { | ||
651 | + FSL_IMX7_PWM1_ADDR, | ||
652 | + FSL_IMX7_PWM2_ADDR, | ||
653 | + FSL_IMX7_PWM3_ADDR, | ||
654 | + FSL_IMX7_PWM4_ADDR, | ||
655 | + }; | ||
656 | + | ||
657 | + snprintf(name, NAME_SIZE, "pwm%d", i); | ||
658 | + create_unimplemented_device(name, FSL_IMX7_PWMn_ADDR[i], | ||
659 | + FSL_IMX7_PWMn_SIZE); | ||
660 | + } | ||
661 | |||
662 | /* | ||
663 | - * CAN | ||
664 | + * CANs | ||
665 | */ | ||
666 | - create_unimplemented_device("can1", FSL_IMX7_CAN1_ADDR, FSL_IMX7_CANn_SIZE); | ||
667 | - create_unimplemented_device("can2", FSL_IMX7_CAN2_ADDR, FSL_IMX7_CANn_SIZE); | ||
668 | + for (i = 0; i < FSL_IMX7_NUM_CANS; i++) { | ||
669 | + static const hwaddr FSL_IMX7_CANn_ADDR[FSL_IMX7_NUM_CANS] = { | ||
670 | + FSL_IMX7_CAN1_ADDR, | ||
671 | + FSL_IMX7_CAN2_ADDR, | ||
672 | + }; | ||
673 | + | ||
674 | + snprintf(name, NAME_SIZE, "can%d", i); | ||
675 | + create_unimplemented_device(name, FSL_IMX7_CANn_ADDR[i], | ||
676 | + FSL_IMX7_CANn_SIZE); | ||
677 | + } | ||
678 | |||
679 | /* | ||
680 | - * SAI (Audio SSI (Synchronous Serial Interface)) | ||
681 | + * SAIs (Audio SSI (Synchronous Serial Interface)) | ||
682 | */ | ||
683 | - create_unimplemented_device("sai1", FSL_IMX7_SAI1_ADDR, FSL_IMX7_SAIn_SIZE); | ||
684 | - create_unimplemented_device("sai2", FSL_IMX7_SAI2_ADDR, FSL_IMX7_SAIn_SIZE); | ||
685 | - create_unimplemented_device("sai2", FSL_IMX7_SAI3_ADDR, FSL_IMX7_SAIn_SIZE); | ||
686 | + for (i = 0; i < FSL_IMX7_NUM_SAIS; i++) { | ||
687 | + static const hwaddr FSL_IMX7_SAIn_ADDR[FSL_IMX7_NUM_SAIS] = { | ||
688 | + FSL_IMX7_SAI1_ADDR, | ||
689 | + FSL_IMX7_SAI2_ADDR, | ||
690 | + FSL_IMX7_SAI3_ADDR, | ||
691 | + }; | ||
692 | + | ||
693 | + snprintf(name, NAME_SIZE, "sai%d", i); | ||
694 | + create_unimplemented_device(name, FSL_IMX7_SAIn_ADDR[i], | ||
695 | + FSL_IMX7_SAIn_SIZE); | ||
696 | + } | ||
697 | |||
698 | /* | ||
699 | * OCOTP | ||
700 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp) | ||
701 | create_unimplemented_device("ocotp", FSL_IMX7_OCOTP_ADDR, | ||
702 | FSL_IMX7_OCOTP_SIZE); | ||
703 | |||
704 | + /* | ||
705 | + * GPR | ||
706 | + */ | ||
707 | sysbus_realize(SYS_BUS_DEVICE(&s->gpr), &error_abort); | ||
708 | - sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpr), 0, FSL_IMX7_GPR_ADDR); | ||
709 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpr), 0, FSL_IMX7_IOMUXC_GPR_ADDR); | ||
710 | |||
711 | + /* | ||
712 | + * PCIE | ||
713 | + */ | ||
714 | sysbus_realize(SYS_BUS_DEVICE(&s->pcie), &error_abort); | ||
715 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->pcie), 0, FSL_IMX7_PCIE_REG_ADDR); | ||
716 | |||
717 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp) | ||
718 | irq = qdev_get_gpio_in(DEVICE(&s->a7mpcore), FSL_IMX7_PCI_INTD_IRQ); | ||
719 | sysbus_connect_irq(SYS_BUS_DEVICE(&s->pcie), 3, irq); | ||
720 | |||
721 | - | ||
722 | + /* | ||
723 | + * USBs | ||
724 | + */ | ||
725 | for (i = 0; i < FSL_IMX7_NUM_USBS; i++) { | ||
726 | static const hwaddr FSL_IMX7_USBMISCn_ADDR[FSL_IMX7_NUM_USBS] = { | ||
727 | FSL_IMX7_USBMISC1_ADDR, | ||
728 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp) | ||
729 | */ | ||
730 | create_unimplemented_device("pcie-phy", FSL_IMX7_PCIE_PHY_ADDR, | ||
731 | FSL_IMX7_PCIE_PHY_SIZE); | ||
732 | + | ||
74 | } | 733 | } |
75 | 734 | ||
76 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_two_reg_sha512(DisasContext *s, uint32_t insn) | 735 | static Property fsl_imx7_properties[] = { |
77 | tcg_temp_free_ptr(tcg_rn_ptr); | ||
78 | } | ||
79 | |||
80 | +/* Crypto four-register | ||
81 | + * 31 23 22 21 20 16 15 14 10 9 5 4 0 | ||
82 | + * +-------------------+-----+------+---+------+------+------+ | ||
83 | + * | 1 1 0 0 1 1 1 0 0 | Op0 | Rm | 0 | Ra | Rn | Rd | | ||
84 | + * +-------------------+-----+------+---+------+------+------+ | ||
85 | + */ | ||
86 | +static void disas_crypto_four_reg(DisasContext *s, uint32_t insn) | ||
87 | +{ | ||
88 | + int op0 = extract32(insn, 21, 2); | ||
89 | + int rm = extract32(insn, 16, 5); | ||
90 | + int ra = extract32(insn, 10, 5); | ||
91 | + int rn = extract32(insn, 5, 5); | ||
92 | + int rd = extract32(insn, 0, 5); | ||
93 | + int feature; | ||
94 | + | ||
95 | + switch (op0) { | ||
96 | + case 0: /* EOR3 */ | ||
97 | + case 1: /* BCAX */ | ||
98 | + feature = ARM_FEATURE_V8_SHA3; | ||
99 | + break; | ||
100 | + default: | ||
101 | + unallocated_encoding(s); | ||
102 | + return; | ||
103 | + } | ||
104 | + | ||
105 | + if (!arm_dc_feature(s, feature)) { | ||
106 | + unallocated_encoding(s); | ||
107 | + return; | ||
108 | + } | ||
109 | + | ||
110 | + if (!fp_access_check(s)) { | ||
111 | + return; | ||
112 | + } | ||
113 | + | ||
114 | + if (op0 < 2) { | ||
115 | + TCGv_i64 tcg_op1, tcg_op2, tcg_op3, tcg_res[2]; | ||
116 | + int pass; | ||
117 | + | ||
118 | + tcg_op1 = tcg_temp_new_i64(); | ||
119 | + tcg_op2 = tcg_temp_new_i64(); | ||
120 | + tcg_op3 = tcg_temp_new_i64(); | ||
121 | + tcg_res[0] = tcg_temp_new_i64(); | ||
122 | + tcg_res[1] = tcg_temp_new_i64(); | ||
123 | + | ||
124 | + for (pass = 0; pass < 2; pass++) { | ||
125 | + read_vec_element(s, tcg_op1, rn, pass, MO_64); | ||
126 | + read_vec_element(s, tcg_op2, rm, pass, MO_64); | ||
127 | + read_vec_element(s, tcg_op3, ra, pass, MO_64); | ||
128 | + | ||
129 | + if (op0 == 0) { | ||
130 | + /* EOR3 */ | ||
131 | + tcg_gen_xor_i64(tcg_res[pass], tcg_op2, tcg_op3); | ||
132 | + } else { | ||
133 | + /* BCAX */ | ||
134 | + tcg_gen_andc_i64(tcg_res[pass], tcg_op2, tcg_op3); | ||
135 | + } | ||
136 | + tcg_gen_xor_i64(tcg_res[pass], tcg_res[pass], tcg_op1); | ||
137 | + } | ||
138 | + write_vec_element(s, tcg_res[0], rd, 0, MO_64); | ||
139 | + write_vec_element(s, tcg_res[1], rd, 1, MO_64); | ||
140 | + | ||
141 | + tcg_temp_free_i64(tcg_op1); | ||
142 | + tcg_temp_free_i64(tcg_op2); | ||
143 | + tcg_temp_free_i64(tcg_op3); | ||
144 | + tcg_temp_free_i64(tcg_res[0]); | ||
145 | + tcg_temp_free_i64(tcg_res[1]); | ||
146 | + } else { | ||
147 | + g_assert_not_reached(); | ||
148 | + } | ||
149 | +} | ||
150 | + | ||
151 | +/* Crypto XAR | ||
152 | + * 31 21 20 16 15 10 9 5 4 0 | ||
153 | + * +-----------------------+------+--------+------+------+ | ||
154 | + * | 1 1 0 0 1 1 1 0 1 0 0 | Rm | imm6 | Rn | Rd | | ||
155 | + * +-----------------------+------+--------+------+------+ | ||
156 | + */ | ||
157 | +static void disas_crypto_xar(DisasContext *s, uint32_t insn) | ||
158 | +{ | ||
159 | + int rm = extract32(insn, 16, 5); | ||
160 | + int imm6 = extract32(insn, 10, 6); | ||
161 | + int rn = extract32(insn, 5, 5); | ||
162 | + int rd = extract32(insn, 0, 5); | ||
163 | + TCGv_i64 tcg_op1, tcg_op2, tcg_res[2]; | ||
164 | + int pass; | ||
165 | + | ||
166 | + if (!arm_dc_feature(s, ARM_FEATURE_V8_SHA3)) { | ||
167 | + unallocated_encoding(s); | ||
168 | + return; | ||
169 | + } | ||
170 | + | ||
171 | + if (!fp_access_check(s)) { | ||
172 | + return; | ||
173 | + } | ||
174 | + | ||
175 | + tcg_op1 = tcg_temp_new_i64(); | ||
176 | + tcg_op2 = tcg_temp_new_i64(); | ||
177 | + tcg_res[0] = tcg_temp_new_i64(); | ||
178 | + tcg_res[1] = tcg_temp_new_i64(); | ||
179 | + | ||
180 | + for (pass = 0; pass < 2; pass++) { | ||
181 | + read_vec_element(s, tcg_op1, rn, pass, MO_64); | ||
182 | + read_vec_element(s, tcg_op2, rm, pass, MO_64); | ||
183 | + | ||
184 | + tcg_gen_xor_i64(tcg_res[pass], tcg_op1, tcg_op2); | ||
185 | + tcg_gen_rotri_i64(tcg_res[pass], tcg_res[pass], imm6); | ||
186 | + } | ||
187 | + write_vec_element(s, tcg_res[0], rd, 0, MO_64); | ||
188 | + write_vec_element(s, tcg_res[1], rd, 1, MO_64); | ||
189 | + | ||
190 | + tcg_temp_free_i64(tcg_op1); | ||
191 | + tcg_temp_free_i64(tcg_op2); | ||
192 | + tcg_temp_free_i64(tcg_res[0]); | ||
193 | + tcg_temp_free_i64(tcg_res[1]); | ||
194 | +} | ||
195 | + | ||
196 | /* C3.6 Data processing - SIMD, inc Crypto | ||
197 | * | ||
198 | * As the decode gets a little complex we are using a table based | ||
199 | @@ -XXX,XX +XXX,XX @@ static const AArch64DecodeTable data_proc_simd[] = { | ||
200 | { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha }, | ||
201 | { 0xce608000, 0xffe0b000, disas_crypto_three_reg_sha512 }, | ||
202 | { 0xcec08000, 0xfffff000, disas_crypto_two_reg_sha512 }, | ||
203 | + { 0xce000000, 0xff808000, disas_crypto_four_reg }, | ||
204 | + { 0xce800000, 0xffe00000, disas_crypto_xar }, | ||
205 | { 0x00000000, 0x00000000, NULL } | ||
206 | }; | ||
207 | |||
208 | -- | 736 | -- |
209 | 2.16.1 | 737 | 2.34.1 |
210 | |||
211 | diff view generated by jsdifflib |
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | 1 | From: Jean-Christophe Dubois <jcd@tribudubois.net> |
---|---|---|---|
2 | 2 | ||
3 | Add minimal code needed to allow upstream Linux guest to boot. | 3 | * Add TZASC as unimplemented device. |
4 | - Allow bare metal application to access this (unimplemented) device | ||
5 | * Add CSU as unimplemented device. | ||
6 | - Allow bare metal application to access this (unimplemented) device | ||
7 | * Add various memory segments | ||
8 | - OCRAM | ||
9 | - OCRAM EPDC | ||
10 | - OCRAM PXP | ||
11 | - OCRAM S | ||
12 | - ROM | ||
13 | - CAAM | ||
4 | 14 | ||
5 | Cc: Peter Maydell <peter.maydell@linaro.org> | 15 | Signed-off-by: Jean-Christophe Dubois <jcd@tribudubois.net> |
6 | Cc: Jason Wang <jasowang@redhat.com> | 16 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
7 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | 17 | Message-id: f887a3483996ba06d40bd62ffdfb0ecf68621987.1692964892.git.jcd@tribudubois.net |
8 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | ||
9 | Cc: Michael S. Tsirkin <mst@redhat.com> | ||
10 | Cc: qemu-devel@nongnu.org | ||
11 | Cc: qemu-arm@nongnu.org | ||
12 | Cc: yurovsky@gmail.com | ||
13 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
14 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
15 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 18 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
17 | --- | 19 | --- |
18 | include/hw/timer/imx_gpt.h | 1 + | 20 | include/hw/arm/fsl-imx7.h | 7 +++++ |
19 | hw/timer/imx_gpt.c | 25 +++++++++++++++++++++++++ | 21 | hw/arm/fsl-imx7.c | 63 +++++++++++++++++++++++++++++++++++++++ |
20 | 2 files changed, 26 insertions(+) | 22 | 2 files changed, 70 insertions(+) |
21 | 23 | ||
22 | diff --git a/include/hw/timer/imx_gpt.h b/include/hw/timer/imx_gpt.h | 24 | diff --git a/include/hw/arm/fsl-imx7.h b/include/hw/arm/fsl-imx7.h |
23 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/include/hw/timer/imx_gpt.h | 26 | --- a/include/hw/arm/fsl-imx7.h |
25 | +++ b/include/hw/timer/imx_gpt.h | 27 | +++ b/include/hw/arm/fsl-imx7.h |
26 | @@ -XXX,XX +XXX,XX @@ | 28 | @@ -XXX,XX +XXX,XX @@ struct FslIMX7State { |
27 | #define TYPE_IMX25_GPT "imx25.gpt" | 29 | IMX7GPRState gpr; |
28 | #define TYPE_IMX31_GPT "imx31.gpt" | 30 | ChipideaState usb[FSL_IMX7_NUM_USBS]; |
29 | #define TYPE_IMX6_GPT "imx6.gpt" | 31 | DesignwarePCIEHost pcie; |
30 | +#define TYPE_IMX7_GPT "imx7.gpt" | 32 | + MemoryRegion rom; |
31 | 33 | + MemoryRegion caam; | |
32 | #define TYPE_IMX_GPT TYPE_IMX25_GPT | 34 | + MemoryRegion ocram; |
33 | 35 | + MemoryRegion ocram_epdc; | |
34 | diff --git a/hw/timer/imx_gpt.c b/hw/timer/imx_gpt.c | 36 | + MemoryRegion ocram_pxp; |
37 | + MemoryRegion ocram_s; | ||
38 | + | ||
39 | uint32_t phy_num[FSL_IMX7_NUM_ETHS]; | ||
40 | bool phy_connected[FSL_IMX7_NUM_ETHS]; | ||
41 | }; | ||
42 | diff --git a/hw/arm/fsl-imx7.c b/hw/arm/fsl-imx7.c | ||
35 | index XXXXXXX..XXXXXXX 100644 | 43 | index XXXXXXX..XXXXXXX 100644 |
36 | --- a/hw/timer/imx_gpt.c | 44 | --- a/hw/arm/fsl-imx7.c |
37 | +++ b/hw/timer/imx_gpt.c | 45 | +++ b/hw/arm/fsl-imx7.c |
38 | @@ -XXX,XX +XXX,XX @@ static const IMXClk imx6_gpt_clocks[] = { | 46 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp) |
39 | CLK_HIGH, /* 111 reference clock */ | 47 | create_unimplemented_device("pcie-phy", FSL_IMX7_PCIE_PHY_ADDR, |
40 | }; | 48 | FSL_IMX7_PCIE_PHY_SIZE); |
41 | 49 | ||
42 | +static const IMXClk imx7_gpt_clocks[] = { | 50 | + /* |
43 | + CLK_NONE, /* 000 No clock source */ | 51 | + * CSU |
44 | + CLK_IPG, /* 001 ipg_clk, 532MHz*/ | 52 | + */ |
45 | + CLK_IPG_HIGH, /* 010 ipg_clk_highfreq */ | 53 | + create_unimplemented_device("csu", FSL_IMX7_CSU_ADDR, |
46 | + CLK_EXT, /* 011 External clock */ | 54 | + FSL_IMX7_CSU_SIZE); |
47 | + CLK_32k, /* 100 ipg_clk_32k */ | ||
48 | + CLK_HIGH, /* 101 reference clock */ | ||
49 | + CLK_NONE, /* 110 not defined */ | ||
50 | + CLK_NONE, /* 111 not defined */ | ||
51 | +}; | ||
52 | + | 55 | + |
53 | static void imx_gpt_set_freq(IMXGPTState *s) | 56 | + /* |
54 | { | 57 | + * TZASC |
55 | uint32_t clksrc = extract32(s->cr, GPT_CR_CLKSRC_SHIFT, 3); | 58 | + */ |
56 | @@ -XXX,XX +XXX,XX @@ static void imx6_gpt_init(Object *obj) | 59 | + create_unimplemented_device("tzasc", FSL_IMX7_TZASC_ADDR, |
57 | s->clocks = imx6_gpt_clocks; | 60 | + FSL_IMX7_TZASC_SIZE); |
61 | + | ||
62 | + /* | ||
63 | + * OCRAM memory | ||
64 | + */ | ||
65 | + memory_region_init_ram(&s->ocram, NULL, "imx7.ocram", | ||
66 | + FSL_IMX7_OCRAM_MEM_SIZE, | ||
67 | + &error_abort); | ||
68 | + memory_region_add_subregion(get_system_memory(), FSL_IMX7_OCRAM_MEM_ADDR, | ||
69 | + &s->ocram); | ||
70 | + | ||
71 | + /* | ||
72 | + * OCRAM EPDC memory | ||
73 | + */ | ||
74 | + memory_region_init_ram(&s->ocram_epdc, NULL, "imx7.ocram_epdc", | ||
75 | + FSL_IMX7_OCRAM_EPDC_SIZE, | ||
76 | + &error_abort); | ||
77 | + memory_region_add_subregion(get_system_memory(), FSL_IMX7_OCRAM_EPDC_ADDR, | ||
78 | + &s->ocram_epdc); | ||
79 | + | ||
80 | + /* | ||
81 | + * OCRAM PXP memory | ||
82 | + */ | ||
83 | + memory_region_init_ram(&s->ocram_pxp, NULL, "imx7.ocram_pxp", | ||
84 | + FSL_IMX7_OCRAM_PXP_SIZE, | ||
85 | + &error_abort); | ||
86 | + memory_region_add_subregion(get_system_memory(), FSL_IMX7_OCRAM_PXP_ADDR, | ||
87 | + &s->ocram_pxp); | ||
88 | + | ||
89 | + /* | ||
90 | + * OCRAM_S memory | ||
91 | + */ | ||
92 | + memory_region_init_ram(&s->ocram_s, NULL, "imx7.ocram_s", | ||
93 | + FSL_IMX7_OCRAM_S_SIZE, | ||
94 | + &error_abort); | ||
95 | + memory_region_add_subregion(get_system_memory(), FSL_IMX7_OCRAM_S_ADDR, | ||
96 | + &s->ocram_s); | ||
97 | + | ||
98 | + /* | ||
99 | + * ROM memory | ||
100 | + */ | ||
101 | + memory_region_init_rom(&s->rom, OBJECT(dev), "imx7.rom", | ||
102 | + FSL_IMX7_ROM_SIZE, &error_abort); | ||
103 | + memory_region_add_subregion(get_system_memory(), FSL_IMX7_ROM_ADDR, | ||
104 | + &s->rom); | ||
105 | + | ||
106 | + /* | ||
107 | + * CAAM memory | ||
108 | + */ | ||
109 | + memory_region_init_rom(&s->caam, OBJECT(dev), "imx7.caam", | ||
110 | + FSL_IMX7_CAAM_MEM_SIZE, &error_abort); | ||
111 | + memory_region_add_subregion(get_system_memory(), FSL_IMX7_CAAM_MEM_ADDR, | ||
112 | + &s->caam); | ||
58 | } | 113 | } |
59 | 114 | ||
60 | +static void imx7_gpt_init(Object *obj) | 115 | static Property fsl_imx7_properties[] = { |
61 | +{ | ||
62 | + IMXGPTState *s = IMX_GPT(obj); | ||
63 | + | ||
64 | + s->clocks = imx7_gpt_clocks; | ||
65 | +} | ||
66 | + | ||
67 | static const TypeInfo imx25_gpt_info = { | ||
68 | .name = TYPE_IMX25_GPT, | ||
69 | .parent = TYPE_SYS_BUS_DEVICE, | ||
70 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo imx6_gpt_info = { | ||
71 | .instance_init = imx6_gpt_init, | ||
72 | }; | ||
73 | |||
74 | +static const TypeInfo imx7_gpt_info = { | ||
75 | + .name = TYPE_IMX7_GPT, | ||
76 | + .parent = TYPE_IMX25_GPT, | ||
77 | + .instance_init = imx7_gpt_init, | ||
78 | +}; | ||
79 | + | ||
80 | static void imx_gpt_register_types(void) | ||
81 | { | ||
82 | type_register_static(&imx25_gpt_info); | ||
83 | type_register_static(&imx31_gpt_info); | ||
84 | type_register_static(&imx6_gpt_info); | ||
85 | + type_register_static(&imx7_gpt_info); | ||
86 | } | ||
87 | |||
88 | type_init(imx_gpt_register_types) | ||
89 | -- | 116 | -- |
90 | 2.16.1 | 117 | 2.34.1 |
91 | 118 | ||
92 | 119 | diff view generated by jsdifflib |
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | 1 | From: Jean-Christophe Dubois <jcd@tribudubois.net> |
---|---|---|---|
2 | 2 | ||
3 | Add minimal code needed to allow upstream Linux guest to boot. | 3 | The SRC device is normally used to start the secondary CPU. |
4 | 4 | ||
5 | Cc: Peter Maydell <peter.maydell@linaro.org> | 5 | When running Linux directly, QEMU is emulating a PSCI interface that UBOOT |
6 | Cc: Jason Wang <jasowang@redhat.com> | 6 | is installing at boot time and therefore the fact that the SRC device is |
7 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | 7 | unimplemented is hidden as Qemu respond directly to PSCI requets without |
8 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | 8 | using the SRC device. |
9 | Cc: Michael S. Tsirkin <mst@redhat.com> | 9 | |
10 | Cc: qemu-devel@nongnu.org | 10 | But if you try to run a more bare metal application (maybe uboot itself), |
11 | Cc: qemu-arm@nongnu.org | 11 | then it is not possible to start the secondary CPU as the SRC is an |
12 | Cc: yurovsky@gmail.com | 12 | unimplemented device. |
13 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 13 | |
14 | This patch adds the ability to start the secondary CPU through the SRC | ||
15 | device so that you can use this feature in bare metal applications. | ||
16 | |||
17 | Signed-off-by: Jean-Christophe Dubois <jcd@tribudubois.net> | ||
14 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 18 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
15 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | 19 | Message-id: ce9a0162defd2acee5dc7f8a674743de0cded569.1692964892.git.jcd@tribudubois.net |
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 20 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
17 | --- | 21 | --- |
18 | hw/misc/Makefile.objs | 1 + | 22 | include/hw/arm/fsl-imx7.h | 3 +- |
19 | include/hw/misc/imx7_gpr.h | 28 ++++++++++ | 23 | include/hw/misc/imx7_src.h | 66 +++++++++ |
20 | hw/misc/imx7_gpr.c | 124 +++++++++++++++++++++++++++++++++++++++++++++ | 24 | hw/arm/fsl-imx7.c | 8 +- |
21 | hw/misc/trace-events | 4 ++ | 25 | hw/misc/imx7_src.c | 276 +++++++++++++++++++++++++++++++++++++ |
22 | 4 files changed, 157 insertions(+) | 26 | hw/misc/meson.build | 1 + |
23 | create mode 100644 include/hw/misc/imx7_gpr.h | 27 | hw/misc/trace-events | 4 + |
24 | create mode 100644 hw/misc/imx7_gpr.c | 28 | 6 files changed, 356 insertions(+), 2 deletions(-) |
25 | 29 | create mode 100644 include/hw/misc/imx7_src.h | |
26 | diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs | 30 | create mode 100644 hw/misc/imx7_src.c |
31 | |||
32 | diff --git a/include/hw/arm/fsl-imx7.h b/include/hw/arm/fsl-imx7.h | ||
27 | index XXXXXXX..XXXXXXX 100644 | 33 | index XXXXXXX..XXXXXXX 100644 |
28 | --- a/hw/misc/Makefile.objs | 34 | --- a/include/hw/arm/fsl-imx7.h |
29 | +++ b/hw/misc/Makefile.objs | 35 | +++ b/include/hw/arm/fsl-imx7.h |
30 | @@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_IMX) += imx6_src.o | 36 | @@ -XXX,XX +XXX,XX @@ |
31 | obj-$(CONFIG_IMX) += imx7_ccm.o | 37 | #include "hw/misc/imx7_ccm.h" |
32 | obj-$(CONFIG_IMX) += imx2_wdt.o | 38 | #include "hw/misc/imx7_snvs.h" |
33 | obj-$(CONFIG_IMX) += imx7_snvs.o | 39 | #include "hw/misc/imx7_gpr.h" |
34 | +obj-$(CONFIG_IMX) += imx7_gpr.o | 40 | +#include "hw/misc/imx7_src.h" |
35 | obj-$(CONFIG_MILKYMIST) += milkymist-hpdmc.o | 41 | #include "hw/watchdog/wdt_imx2.h" |
36 | obj-$(CONFIG_MILKYMIST) += milkymist-pfpu.o | 42 | #include "hw/gpio/imx_gpio.h" |
37 | obj-$(CONFIG_MAINSTONE) += mst_fpga.o | 43 | #include "hw/char/imx_serial.h" |
38 | diff --git a/include/hw/misc/imx7_gpr.h b/include/hw/misc/imx7_gpr.h | 44 | @@ -XXX,XX +XXX,XX @@ struct FslIMX7State { |
45 | IMX7CCMState ccm; | ||
46 | IMX7AnalogState analog; | ||
47 | IMX7SNVSState snvs; | ||
48 | + IMX7SRCState src; | ||
49 | IMXGPCv2State gpcv2; | ||
50 | IMXSPIState spi[FSL_IMX7_NUM_ECSPIS]; | ||
51 | IMXI2CState i2c[FSL_IMX7_NUM_I2CS]; | ||
52 | @@ -XXX,XX +XXX,XX @@ enum FslIMX7MemoryMap { | ||
53 | FSL_IMX7_GPC_ADDR = 0x303A0000, | ||
54 | |||
55 | FSL_IMX7_SRC_ADDR = 0x30390000, | ||
56 | - FSL_IMX7_SRC_SIZE = (4 * KiB), | ||
57 | |||
58 | FSL_IMX7_CCM_ADDR = 0x30380000, | ||
59 | |||
60 | diff --git a/include/hw/misc/imx7_src.h b/include/hw/misc/imx7_src.h | ||
39 | new file mode 100644 | 61 | new file mode 100644 |
40 | index XXXXXXX..XXXXXXX | 62 | index XXXXXXX..XXXXXXX |
41 | --- /dev/null | 63 | --- /dev/null |
42 | +++ b/include/hw/misc/imx7_gpr.h | 64 | +++ b/include/hw/misc/imx7_src.h |
43 | @@ -XXX,XX +XXX,XX @@ | 65 | @@ -XXX,XX +XXX,XX @@ |
44 | +/* | 66 | +/* |
45 | + * Copyright (c) 2017, Impinj, Inc. | 67 | + * IMX7 System Reset Controller |
46 | + * | 68 | + * |
47 | + * i.MX7 GPR IP block emulation code | 69 | + * Copyright (C) 2023 Jean-Christophe Dubois <jcd@tribudubois.net> |
48 | + * | ||
49 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
50 | + * | 70 | + * |
51 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 71 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. |
52 | + * See the COPYING file in the top-level directory. | 72 | + * See the COPYING file in the top-level directory. |
53 | + */ | 73 | + */ |
54 | + | 74 | + |
55 | +#ifndef IMX7_GPR_H | 75 | +#ifndef IMX7_SRC_H |
56 | +#define IMX7_GPR_H | 76 | +#define IMX7_SRC_H |
57 | + | 77 | + |
78 | +#include "hw/sysbus.h" | ||
58 | +#include "qemu/bitops.h" | 79 | +#include "qemu/bitops.h" |
59 | +#include "hw/sysbus.h" | 80 | +#include "qom/object.h" |
60 | + | 81 | + |
61 | +#define TYPE_IMX7_GPR "imx7.gpr" | 82 | +#define SRC_SCR 0 |
62 | +#define IMX7_GPR(obj) OBJECT_CHECK(IMX7GPRState, (obj), TYPE_IMX7_GPR) | 83 | +#define SRC_A7RCR0 1 |
63 | + | 84 | +#define SRC_A7RCR1 2 |
64 | +typedef struct IMX7GPRState { | 85 | +#define SRC_M4RCR 3 |
86 | +#define SRC_ERCR 5 | ||
87 | +#define SRC_HSICPHY_RCR 7 | ||
88 | +#define SRC_USBOPHY1_RCR 8 | ||
89 | +#define SRC_USBOPHY2_RCR 9 | ||
90 | +#define SRC_MPIPHY_RCR 10 | ||
91 | +#define SRC_PCIEPHY_RCR 11 | ||
92 | +#define SRC_SBMR1 22 | ||
93 | +#define SRC_SRSR 23 | ||
94 | +#define SRC_SISR 26 | ||
95 | +#define SRC_SIMR 27 | ||
96 | +#define SRC_SBMR2 28 | ||
97 | +#define SRC_GPR1 29 | ||
98 | +#define SRC_GPR2 30 | ||
99 | +#define SRC_GPR3 31 | ||
100 | +#define SRC_GPR4 32 | ||
101 | +#define SRC_GPR5 33 | ||
102 | +#define SRC_GPR6 34 | ||
103 | +#define SRC_GPR7 35 | ||
104 | +#define SRC_GPR8 36 | ||
105 | +#define SRC_GPR9 37 | ||
106 | +#define SRC_GPR10 38 | ||
107 | +#define SRC_MAX 39 | ||
108 | + | ||
109 | +/* SRC_A7SCR1 */ | ||
110 | +#define R_CORE1_ENABLE_SHIFT 1 | ||
111 | +#define R_CORE1_ENABLE_LENGTH 1 | ||
112 | +/* SRC_A7SCR0 */ | ||
113 | +#define R_CORE1_RST_SHIFT 5 | ||
114 | +#define R_CORE1_RST_LENGTH 1 | ||
115 | +#define R_CORE0_RST_SHIFT 4 | ||
116 | +#define R_CORE0_RST_LENGTH 1 | ||
117 | + | ||
118 | +#define TYPE_IMX7_SRC "imx7.src" | ||
119 | +OBJECT_DECLARE_SIMPLE_TYPE(IMX7SRCState, IMX7_SRC) | ||
120 | + | ||
121 | +struct IMX7SRCState { | ||
65 | + /* <private> */ | 122 | + /* <private> */ |
66 | + SysBusDevice parent_obj; | 123 | + SysBusDevice parent_obj; |
67 | + | 124 | + |
68 | + MemoryRegion mmio; | 125 | + /* <public> */ |
69 | +} IMX7GPRState; | 126 | + MemoryRegion iomem; |
70 | + | 127 | + |
71 | +#endif /* IMX7_GPR_H */ | 128 | + uint32_t regs[SRC_MAX]; |
72 | diff --git a/hw/misc/imx7_gpr.c b/hw/misc/imx7_gpr.c | 129 | +}; |
130 | + | ||
131 | +#endif /* IMX7_SRC_H */ | ||
132 | diff --git a/hw/arm/fsl-imx7.c b/hw/arm/fsl-imx7.c | ||
133 | index XXXXXXX..XXXXXXX 100644 | ||
134 | --- a/hw/arm/fsl-imx7.c | ||
135 | +++ b/hw/arm/fsl-imx7.c | ||
136 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx7_init(Object *obj) | ||
137 | */ | ||
138 | object_initialize_child(obj, "gpcv2", &s->gpcv2, TYPE_IMX_GPCV2); | ||
139 | |||
140 | + /* | ||
141 | + * SRC | ||
142 | + */ | ||
143 | + object_initialize_child(obj, "src", &s->src, TYPE_IMX7_SRC); | ||
144 | + | ||
145 | /* | ||
146 | * ECSPIs | ||
147 | */ | ||
148 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp) | ||
149 | /* | ||
150 | * SRC | ||
151 | */ | ||
152 | - create_unimplemented_device("src", FSL_IMX7_SRC_ADDR, FSL_IMX7_SRC_SIZE); | ||
153 | + sysbus_realize(SYS_BUS_DEVICE(&s->src), &error_abort); | ||
154 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->src), 0, FSL_IMX7_SRC_ADDR); | ||
155 | |||
156 | /* | ||
157 | * Watchdogs | ||
158 | diff --git a/hw/misc/imx7_src.c b/hw/misc/imx7_src.c | ||
73 | new file mode 100644 | 159 | new file mode 100644 |
74 | index XXXXXXX..XXXXXXX | 160 | index XXXXXXX..XXXXXXX |
75 | --- /dev/null | 161 | --- /dev/null |
76 | +++ b/hw/misc/imx7_gpr.c | 162 | +++ b/hw/misc/imx7_src.c |
77 | @@ -XXX,XX +XXX,XX @@ | 163 | @@ -XXX,XX +XXX,XX @@ |
78 | +/* | 164 | +/* |
79 | + * Copyright (c) 2018, Impinj, Inc. | 165 | + * IMX7 System Reset Controller |
80 | + * | 166 | + * |
81 | + * i.MX7 GPR IP block emulation code | 167 | + * Copyright (c) 2023 Jean-Christophe Dubois <jcd@tribudubois.net> |
82 | + * | ||
83 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
84 | + * | 168 | + * |
85 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 169 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. |
86 | + * See the COPYING file in the top-level directory. | 170 | + * See the COPYING file in the top-level directory. |
87 | + * | 171 | + * |
88 | + * Bare minimum emulation code needed to support being able to shut | ||
89 | + * down linux guest gracefully. | ||
90 | + */ | 172 | + */ |
91 | + | 173 | + |
92 | +#include "qemu/osdep.h" | 174 | +#include "qemu/osdep.h" |
93 | +#include "hw/misc/imx7_gpr.h" | 175 | +#include "hw/misc/imx7_src.h" |
176 | +#include "migration/vmstate.h" | ||
177 | +#include "qemu/bitops.h" | ||
94 | +#include "qemu/log.h" | 178 | +#include "qemu/log.h" |
95 | +#include "sysemu/sysemu.h" | 179 | +#include "qemu/main-loop.h" |
180 | +#include "qemu/module.h" | ||
181 | +#include "target/arm/arm-powerctl.h" | ||
182 | +#include "hw/core/cpu.h" | ||
183 | +#include "hw/registerfields.h" | ||
96 | + | 184 | + |
97 | +#include "trace.h" | 185 | +#include "trace.h" |
98 | + | 186 | + |
99 | +enum IMX7GPRRegisters { | 187 | +static const char *imx7_src_reg_name(uint32_t reg) |
100 | + IOMUXC_GPR0 = 0x00, | 188 | +{ |
101 | + IOMUXC_GPR1 = 0x04, | 189 | + static char unknown[20]; |
102 | + IOMUXC_GPR2 = 0x08, | 190 | + |
103 | + IOMUXC_GPR3 = 0x0c, | 191 | + switch (reg) { |
104 | + IOMUXC_GPR4 = 0x10, | 192 | + case SRC_SCR: |
105 | + IOMUXC_GPR5 = 0x14, | 193 | + return "SRC_SCR"; |
106 | + IOMUXC_GPR6 = 0x18, | 194 | + case SRC_A7RCR0: |
107 | + IOMUXC_GPR7 = 0x1c, | 195 | + return "SRC_A7RCR0"; |
108 | + IOMUXC_GPR8 = 0x20, | 196 | + case SRC_A7RCR1: |
109 | + IOMUXC_GPR9 = 0x24, | 197 | + return "SRC_A7RCR1"; |
110 | + IOMUXC_GPR10 = 0x28, | 198 | + case SRC_M4RCR: |
111 | + IOMUXC_GPR11 = 0x2c, | 199 | + return "SRC_M4RCR"; |
112 | + IOMUXC_GPR12 = 0x30, | 200 | + case SRC_ERCR: |
113 | + IOMUXC_GPR13 = 0x34, | 201 | + return "SRC_ERCR"; |
114 | + IOMUXC_GPR14 = 0x38, | 202 | + case SRC_HSICPHY_RCR: |
115 | + IOMUXC_GPR15 = 0x3c, | 203 | + return "SRC_HSICPHY_RCR"; |
116 | + IOMUXC_GPR16 = 0x40, | 204 | + case SRC_USBOPHY1_RCR: |
117 | + IOMUXC_GPR17 = 0x44, | 205 | + return "SRC_USBOPHY1_RCR"; |
118 | + IOMUXC_GPR18 = 0x48, | 206 | + case SRC_USBOPHY2_RCR: |
119 | + IOMUXC_GPR19 = 0x4c, | 207 | + return "SRC_USBOPHY2_RCR"; |
120 | + IOMUXC_GPR20 = 0x50, | 208 | + case SRC_PCIEPHY_RCR: |
121 | + IOMUXC_GPR21 = 0x54, | 209 | + return "SRC_PCIEPHY_RCR"; |
122 | + IOMUXC_GPR22 = 0x58, | 210 | + case SRC_SBMR1: |
211 | + return "SRC_SBMR1"; | ||
212 | + case SRC_SRSR: | ||
213 | + return "SRC_SRSR"; | ||
214 | + case SRC_SISR: | ||
215 | + return "SRC_SISR"; | ||
216 | + case SRC_SIMR: | ||
217 | + return "SRC_SIMR"; | ||
218 | + case SRC_SBMR2: | ||
219 | + return "SRC_SBMR2"; | ||
220 | + case SRC_GPR1: | ||
221 | + return "SRC_GPR1"; | ||
222 | + case SRC_GPR2: | ||
223 | + return "SRC_GPR2"; | ||
224 | + case SRC_GPR3: | ||
225 | + return "SRC_GPR3"; | ||
226 | + case SRC_GPR4: | ||
227 | + return "SRC_GPR4"; | ||
228 | + case SRC_GPR5: | ||
229 | + return "SRC_GPR5"; | ||
230 | + case SRC_GPR6: | ||
231 | + return "SRC_GPR6"; | ||
232 | + case SRC_GPR7: | ||
233 | + return "SRC_GPR7"; | ||
234 | + case SRC_GPR8: | ||
235 | + return "SRC_GPR8"; | ||
236 | + case SRC_GPR9: | ||
237 | + return "SRC_GPR9"; | ||
238 | + case SRC_GPR10: | ||
239 | + return "SRC_GPR10"; | ||
240 | + default: | ||
241 | + sprintf(unknown, "%u ?", reg); | ||
242 | + return unknown; | ||
243 | + } | ||
244 | +} | ||
245 | + | ||
246 | +static const VMStateDescription vmstate_imx7_src = { | ||
247 | + .name = TYPE_IMX7_SRC, | ||
248 | + .version_id = 1, | ||
249 | + .minimum_version_id = 1, | ||
250 | + .fields = (VMStateField[]) { | ||
251 | + VMSTATE_UINT32_ARRAY(regs, IMX7SRCState, SRC_MAX), | ||
252 | + VMSTATE_END_OF_LIST() | ||
253 | + }, | ||
123 | +}; | 254 | +}; |
124 | + | 255 | + |
125 | +#define IMX7D_GPR1_IRQ_MASK BIT(12) | 256 | +static void imx7_src_reset(DeviceState *dev) |
126 | +#define IMX7D_GPR1_ENET1_TX_CLK_SEL_MASK BIT(13) | 257 | +{ |
127 | +#define IMX7D_GPR1_ENET2_TX_CLK_SEL_MASK BIT(14) | 258 | + IMX7SRCState *s = IMX7_SRC(dev); |
128 | +#define IMX7D_GPR1_ENET_TX_CLK_SEL_MASK (0x3 << 13) | 259 | + |
129 | +#define IMX7D_GPR1_ENET1_CLK_DIR_MASK BIT(17) | 260 | + memset(s->regs, 0, sizeof(s->regs)); |
130 | +#define IMX7D_GPR1_ENET2_CLK_DIR_MASK BIT(18) | 261 | + |
131 | +#define IMX7D_GPR1_ENET_CLK_DIR_MASK (0x3 << 17) | 262 | + /* Set reset values */ |
132 | + | 263 | + s->regs[SRC_SCR] = 0xA0; |
133 | +#define IMX7D_GPR5_CSI_MUX_CONTROL_MIPI BIT(4) | 264 | + s->regs[SRC_SRSR] = 0x1; |
134 | +#define IMX7D_GPR12_PCIE_PHY_REFCLK_SEL BIT(5) | 265 | + s->regs[SRC_SIMR] = 0x1F; |
135 | +#define IMX7D_GPR22_PCIE_PHY_PLL_LOCKED BIT(31) | 266 | +} |
136 | + | 267 | + |
137 | + | 268 | +static uint64_t imx7_src_read(void *opaque, hwaddr offset, unsigned size) |
138 | +static uint64_t imx7_gpr_read(void *opaque, hwaddr offset, unsigned size) | 269 | +{ |
139 | +{ | 270 | + uint32_t value = 0; |
140 | + trace_imx7_gpr_read(offset); | 271 | + IMX7SRCState *s = (IMX7SRCState *)opaque; |
141 | + | 272 | + uint32_t index = offset >> 2; |
142 | + if (offset == IOMUXC_GPR22) { | 273 | + |
143 | + return IMX7D_GPR22_PCIE_PHY_PLL_LOCKED; | 274 | + if (index < SRC_MAX) { |
275 | + value = s->regs[index]; | ||
276 | + } else { | ||
277 | + qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: Bad register at offset 0x%" | ||
278 | + HWADDR_PRIx "\n", TYPE_IMX7_SRC, __func__, offset); | ||
144 | + } | 279 | + } |
145 | + | 280 | + |
146 | + return 0; | 281 | + trace_imx7_src_read(imx7_src_reg_name(index), value); |
147 | +} | 282 | + |
148 | + | 283 | + return value; |
149 | +static void imx7_gpr_write(void *opaque, hwaddr offset, | 284 | +} |
150 | + uint64_t v, unsigned size) | 285 | + |
151 | +{ | 286 | + |
152 | + trace_imx7_gpr_write(offset, v); | 287 | +/* |
153 | +} | 288 | + * The reset is asynchronous so we need to defer clearing the reset |
154 | + | 289 | + * bit until the work is completed. |
155 | +static const struct MemoryRegionOps imx7_gpr_ops = { | 290 | + */ |
156 | + .read = imx7_gpr_read, | 291 | + |
157 | + .write = imx7_gpr_write, | 292 | +struct SRCSCRResetInfo { |
293 | + IMX7SRCState *s; | ||
294 | + uint32_t reset_bit; | ||
295 | +}; | ||
296 | + | ||
297 | +static void imx7_clear_reset_bit(CPUState *cpu, run_on_cpu_data data) | ||
298 | +{ | ||
299 | + struct SRCSCRResetInfo *ri = data.host_ptr; | ||
300 | + IMX7SRCState *s = ri->s; | ||
301 | + | ||
302 | + assert(qemu_mutex_iothread_locked()); | ||
303 | + | ||
304 | + s->regs[SRC_A7RCR0] = deposit32(s->regs[SRC_A7RCR0], ri->reset_bit, 1, 0); | ||
305 | + | ||
306 | + trace_imx7_src_write(imx7_src_reg_name(SRC_A7RCR0), s->regs[SRC_A7RCR0]); | ||
307 | + | ||
308 | + g_free(ri); | ||
309 | +} | ||
310 | + | ||
311 | +static void imx7_defer_clear_reset_bit(uint32_t cpuid, | ||
312 | + IMX7SRCState *s, | ||
313 | + uint32_t reset_shift) | ||
314 | +{ | ||
315 | + struct SRCSCRResetInfo *ri; | ||
316 | + CPUState *cpu = arm_get_cpu_by_id(cpuid); | ||
317 | + | ||
318 | + if (!cpu) { | ||
319 | + return; | ||
320 | + } | ||
321 | + | ||
322 | + ri = g_new(struct SRCSCRResetInfo, 1); | ||
323 | + ri->s = s; | ||
324 | + ri->reset_bit = reset_shift; | ||
325 | + | ||
326 | + async_run_on_cpu(cpu, imx7_clear_reset_bit, RUN_ON_CPU_HOST_PTR(ri)); | ||
327 | +} | ||
328 | + | ||
329 | + | ||
330 | +static void imx7_src_write(void *opaque, hwaddr offset, uint64_t value, | ||
331 | + unsigned size) | ||
332 | +{ | ||
333 | + IMX7SRCState *s = (IMX7SRCState *)opaque; | ||
334 | + uint32_t index = offset >> 2; | ||
335 | + long unsigned int change_mask; | ||
336 | + uint32_t current_value = value; | ||
337 | + | ||
338 | + if (index >= SRC_MAX) { | ||
339 | + qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: Bad register at offset 0x%" | ||
340 | + HWADDR_PRIx "\n", TYPE_IMX7_SRC, __func__, offset); | ||
341 | + return; | ||
342 | + } | ||
343 | + | ||
344 | + trace_imx7_src_write(imx7_src_reg_name(SRC_A7RCR0), s->regs[SRC_A7RCR0]); | ||
345 | + | ||
346 | + change_mask = s->regs[index] ^ (uint32_t)current_value; | ||
347 | + | ||
348 | + switch (index) { | ||
349 | + case SRC_A7RCR0: | ||
350 | + if (FIELD_EX32(change_mask, CORE0, RST)) { | ||
351 | + arm_reset_cpu(0); | ||
352 | + imx7_defer_clear_reset_bit(0, s, R_CORE0_RST_SHIFT); | ||
353 | + } | ||
354 | + if (FIELD_EX32(change_mask, CORE1, RST)) { | ||
355 | + arm_reset_cpu(1); | ||
356 | + imx7_defer_clear_reset_bit(1, s, R_CORE1_RST_SHIFT); | ||
357 | + } | ||
358 | + s->regs[index] = current_value; | ||
359 | + break; | ||
360 | + case SRC_A7RCR1: | ||
361 | + /* | ||
362 | + * On real hardware when the system reset controller starts a | ||
363 | + * secondary CPU it runs through some boot ROM code which reads | ||
364 | + * the SRC_GPRX registers controlling the start address and branches | ||
365 | + * to it. | ||
366 | + * Here we are taking a short cut and branching directly to the | ||
367 | + * requested address (we don't want to run the boot ROM code inside | ||
368 | + * QEMU) | ||
369 | + */ | ||
370 | + if (FIELD_EX32(change_mask, CORE1, ENABLE)) { | ||
371 | + if (FIELD_EX32(current_value, CORE1, ENABLE)) { | ||
372 | + /* CORE 1 is brought up */ | ||
373 | + arm_set_cpu_on(1, s->regs[SRC_GPR3], s->regs[SRC_GPR4], | ||
374 | + 3, false); | ||
375 | + } else { | ||
376 | + /* CORE 1 is shut down */ | ||
377 | + arm_set_cpu_off(1); | ||
378 | + } | ||
379 | + /* We clear the reset bits as the processor changed state */ | ||
380 | + imx7_defer_clear_reset_bit(1, s, R_CORE1_RST_SHIFT); | ||
381 | + clear_bit(R_CORE1_RST_SHIFT, &change_mask); | ||
382 | + } | ||
383 | + s->regs[index] = current_value; | ||
384 | + break; | ||
385 | + default: | ||
386 | + s->regs[index] = current_value; | ||
387 | + break; | ||
388 | + } | ||
389 | +} | ||
390 | + | ||
391 | +static const struct MemoryRegionOps imx7_src_ops = { | ||
392 | + .read = imx7_src_read, | ||
393 | + .write = imx7_src_write, | ||
158 | + .endianness = DEVICE_NATIVE_ENDIAN, | 394 | + .endianness = DEVICE_NATIVE_ENDIAN, |
159 | + .impl = { | 395 | + .valid = { |
160 | + /* | 396 | + /* |
161 | + * Our device would not work correctly if the guest was doing | 397 | + * Our device would not work correctly if the guest was doing |
162 | + * unaligned access. This might not be a limitation on the | 398 | + * unaligned access. This might not be a limitation on the real |
163 | + * real device but in practice there is no reason for a guest | 399 | + * device but in practice there is no reason for a guest to access |
164 | + * to access this device unaligned. | 400 | + * this device unaligned. |
165 | + */ | 401 | + */ |
166 | + .min_access_size = 4, | 402 | + .min_access_size = 4, |
167 | + .max_access_size = 4, | 403 | + .max_access_size = 4, |
168 | + .unaligned = false, | 404 | + .unaligned = false, |
169 | + }, | 405 | + }, |
170 | +}; | 406 | +}; |
171 | + | 407 | + |
172 | +static void imx7_gpr_init(Object *obj) | 408 | +static void imx7_src_realize(DeviceState *dev, Error **errp) |
173 | +{ | 409 | +{ |
174 | + SysBusDevice *sd = SYS_BUS_DEVICE(obj); | 410 | + IMX7SRCState *s = IMX7_SRC(dev); |
175 | + IMX7GPRState *s = IMX7_GPR(obj); | 411 | + |
176 | + | 412 | + memory_region_init_io(&s->iomem, OBJECT(dev), &imx7_src_ops, s, |
177 | + memory_region_init_io(&s->mmio, obj, &imx7_gpr_ops, s, | 413 | + TYPE_IMX7_SRC, 0x1000); |
178 | + TYPE_IMX7_GPR, 64 * 1024); | 414 | + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem); |
179 | + sysbus_init_mmio(sd, &s->mmio); | 415 | +} |
180 | +} | 416 | + |
181 | + | 417 | +static void imx7_src_class_init(ObjectClass *klass, void *data) |
182 | +static void imx7_gpr_class_init(ObjectClass *klass, void *data) | ||
183 | +{ | 418 | +{ |
184 | + DeviceClass *dc = DEVICE_CLASS(klass); | 419 | + DeviceClass *dc = DEVICE_CLASS(klass); |
185 | + | 420 | + |
186 | + dc->desc = "i.MX7 General Purpose Registers Module"; | 421 | + dc->realize = imx7_src_realize; |
187 | +} | 422 | + dc->reset = imx7_src_reset; |
188 | + | 423 | + dc->vmsd = &vmstate_imx7_src; |
189 | +static const TypeInfo imx7_gpr_info = { | 424 | + dc->desc = "i.MX6 System Reset Controller"; |
190 | + .name = TYPE_IMX7_GPR, | 425 | +} |
426 | + | ||
427 | +static const TypeInfo imx7_src_info = { | ||
428 | + .name = TYPE_IMX7_SRC, | ||
191 | + .parent = TYPE_SYS_BUS_DEVICE, | 429 | + .parent = TYPE_SYS_BUS_DEVICE, |
192 | + .instance_size = sizeof(IMX7GPRState), | 430 | + .instance_size = sizeof(IMX7SRCState), |
193 | + .instance_init = imx7_gpr_init, | 431 | + .class_init = imx7_src_class_init, |
194 | + .class_init = imx7_gpr_class_init, | ||
195 | +}; | 432 | +}; |
196 | + | 433 | + |
197 | +static void imx7_gpr_register_type(void) | 434 | +static void imx7_src_register_types(void) |
198 | +{ | 435 | +{ |
199 | + type_register_static(&imx7_gpr_info); | 436 | + type_register_static(&imx7_src_info); |
200 | +} | 437 | +} |
201 | +type_init(imx7_gpr_register_type) | 438 | + |
439 | +type_init(imx7_src_register_types) | ||
440 | diff --git a/hw/misc/meson.build b/hw/misc/meson.build | ||
441 | index XXXXXXX..XXXXXXX 100644 | ||
442 | --- a/hw/misc/meson.build | ||
443 | +++ b/hw/misc/meson.build | ||
444 | @@ -XXX,XX +XXX,XX @@ system_ss.add(when: 'CONFIG_IMX', if_true: files( | ||
445 | 'imx6_src.c', | ||
446 | 'imx6ul_ccm.c', | ||
447 | 'imx7_ccm.c', | ||
448 | + 'imx7_src.c', | ||
449 | 'imx7_gpr.c', | ||
450 | 'imx7_snvs.c', | ||
451 | 'imx_ccm.c', | ||
202 | diff --git a/hw/misc/trace-events b/hw/misc/trace-events | 452 | diff --git a/hw/misc/trace-events b/hw/misc/trace-events |
203 | index XXXXXXX..XXXXXXX 100644 | 453 | index XXXXXXX..XXXXXXX 100644 |
204 | --- a/hw/misc/trace-events | 454 | --- a/hw/misc/trace-events |
205 | +++ b/hw/misc/trace-events | 455 | +++ b/hw/misc/trace-events |
206 | @@ -XXX,XX +XXX,XX @@ mps2_scc_cfg_read(unsigned function, unsigned device, uint32_t value) "MPS2 SCC | 456 | @@ -XXX,XX +XXX,XX @@ ccm_clock_freq(uint32_t clock, uint32_t freq) "(Clock = %d) = %d" |
207 | msf2_sysreg_write(uint64_t offset, uint32_t val, uint32_t prev) "msf2-sysreg write: addr 0x%08" HWADDR_PRIx " data 0x%" PRIx32 " prev 0x%" PRIx32 | 457 | ccm_read_reg(const char *reg_name, uint32_t value) "reg[%s] <= 0x%" PRIx32 |
208 | msf2_sysreg_read(uint64_t offset, uint32_t val) "msf2-sysreg read: addr 0x%08" HWADDR_PRIx " data 0x%08" PRIx32 | 458 | ccm_write_reg(const char *reg_name, uint32_t value) "reg[%s] => 0x%" PRIx32 |
209 | msf2_sysreg_write_pll_status(void) "Invalid write to read only PLL status register" | 459 | |
210 | + | 460 | +# imx7_src.c |
211 | +#hw/misc/imx7_gpr.c | 461 | +imx7_src_read(const char *reg_name, uint32_t value) "reg[%s] => 0x%" PRIx32 |
212 | +imx7_gpr_read(uint64_t offset) "addr 0x%08" HWADDR_PRIx | 462 | +imx7_src_write(const char *reg_name, uint32_t value) "reg[%s] <= 0x%" PRIx32 |
213 | +imx7_gpr_write(uint64_t offset, uint64_t value) "addr 0x%08" HWADDR_PRIx "value 0x%08" HWADDR_PRIx | 463 | + |
464 | # iotkit-sysinfo.c | ||
465 | iotkit_sysinfo_read(uint64_t offset, uint64_t data, unsigned size) "IoTKit SysInfo read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" | ||
466 | iotkit_sysinfo_write(uint64_t offset, uint64_t data, unsigned size) "IoTKit SysInfo write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" | ||
214 | -- | 467 | -- |
215 | 2.16.1 | 468 | 2.34.1 |
216 | |||
217 | diff view generated by jsdifflib |
1 | Make v7m_push_callee_stack() honour the MPU by using the | 1 | The architecture requires (R_TYTWB) that an attempt to return from EL3 |
---|---|---|---|
2 | new v7m_stack_write() function. We return a flag to indicate | 2 | when SCR_EL3.{NSE,NS} are {1,0} is an illegal exception return. (This |
3 | whether the pushes failed, which we can then use in | 3 | enforces that the CPU can't ever be executing below EL3 with the |
4 | v7m_exception_taken() to cause us to handle the derived | 4 | NSE,NS bits indicating an invalid security state.) |
5 | exception correctly. | 5 | |
6 | We were missing this check; add it. | ||
6 | 7 | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 10 | Message-id: 20230807150618.101357-1-peter.maydell@linaro.org |
10 | Message-id: 1517324542-6607-6-git-send-email-peter.maydell@linaro.org | ||
11 | --- | 11 | --- |
12 | target/arm/helper.c | 64 ++++++++++++++++++++++++++++++++++++++++------------- | 12 | target/arm/tcg/helper-a64.c | 9 +++++++++ |
13 | 1 file changed, 49 insertions(+), 15 deletions(-) | 13 | 1 file changed, 9 insertions(+) |
14 | 14 | ||
15 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 15 | diff --git a/target/arm/tcg/helper-a64.c b/target/arm/tcg/helper-a64.c |
16 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/helper.c | 17 | --- a/target/arm/tcg/helper-a64.c |
18 | +++ b/target/arm/helper.c | 18 | +++ b/target/arm/tcg/helper-a64.c |
19 | @@ -XXX,XX +XXX,XX @@ static uint32_t arm_v7m_load_vector(ARMCPU *cpu, int exc, bool targets_secure) | 19 | @@ -XXX,XX +XXX,XX @@ void HELPER(exception_return)(CPUARMState *env, uint64_t new_pc) |
20 | return addr; | 20 | spsr &= ~PSTATE_SS; |
21 | } | ||
22 | |||
23 | -static void v7m_push_callee_stack(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
24 | +static bool v7m_push_callee_stack(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
25 | bool ignore_faults) | ||
26 | { | ||
27 | /* For v8M, push the callee-saves register part of the stack frame. | ||
28 | @@ -XXX,XX +XXX,XX @@ static void v7m_push_callee_stack(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
29 | * In the tailchaining case this may not be the current stack. | ||
30 | */ | ||
31 | CPUARMState *env = &cpu->env; | ||
32 | - CPUState *cs = CPU(cpu); | ||
33 | uint32_t *frame_sp_p; | ||
34 | uint32_t frameptr; | ||
35 | + ARMMMUIdx mmu_idx; | ||
36 | + bool stacked_ok; | ||
37 | |||
38 | if (dotailchain) { | ||
39 | - frame_sp_p = get_v7m_sp_ptr(env, true, | ||
40 | - lr & R_V7M_EXCRET_MODE_MASK, | ||
41 | + bool mode = lr & R_V7M_EXCRET_MODE_MASK; | ||
42 | + bool priv = !(env->v7m.control[M_REG_S] & R_V7M_CONTROL_NPRIV_MASK) || | ||
43 | + !mode; | ||
44 | + | ||
45 | + mmu_idx = arm_v7m_mmu_idx_for_secstate_and_priv(env, M_REG_S, priv); | ||
46 | + frame_sp_p = get_v7m_sp_ptr(env, M_REG_S, mode, | ||
47 | lr & R_V7M_EXCRET_SPSEL_MASK); | ||
48 | } else { | ||
49 | + mmu_idx = core_to_arm_mmu_idx(env, cpu_mmu_index(env, false)); | ||
50 | frame_sp_p = &env->regs[13]; | ||
51 | } | 21 | } |
52 | 22 | ||
53 | frameptr = *frame_sp_p - 0x28; | 23 | + /* |
54 | 24 | + * FEAT_RME forbids return from EL3 with an invalid security state. | |
55 | - stl_phys(cs->as, frameptr, 0xfefa125b); | 25 | + * We don't need an explicit check for FEAT_RME here because we enforce |
56 | - stl_phys(cs->as, frameptr + 0x8, env->regs[4]); | 26 | + * in scr_write() that you can't set the NSE bit without it. |
57 | - stl_phys(cs->as, frameptr + 0xc, env->regs[5]); | ||
58 | - stl_phys(cs->as, frameptr + 0x10, env->regs[6]); | ||
59 | - stl_phys(cs->as, frameptr + 0x14, env->regs[7]); | ||
60 | - stl_phys(cs->as, frameptr + 0x18, env->regs[8]); | ||
61 | - stl_phys(cs->as, frameptr + 0x1c, env->regs[9]); | ||
62 | - stl_phys(cs->as, frameptr + 0x20, env->regs[10]); | ||
63 | - stl_phys(cs->as, frameptr + 0x24, env->regs[11]); | ||
64 | + /* Write as much of the stack frame as we can. A write failure may | ||
65 | + * cause us to pend a derived exception. | ||
66 | + */ | 27 | + */ |
67 | + stacked_ok = | 28 | + if (cur_el == 3 && (env->cp15.scr_el3 & (SCR_NS | SCR_NSE)) == SCR_NSE) { |
68 | + v7m_stack_write(cpu, frameptr, 0xfefa125b, mmu_idx, ignore_faults) && | 29 | + goto illegal_return; |
69 | + v7m_stack_write(cpu, frameptr + 0x8, env->regs[4], mmu_idx, | ||
70 | + ignore_faults) && | ||
71 | + v7m_stack_write(cpu, frameptr + 0xc, env->regs[5], mmu_idx, | ||
72 | + ignore_faults) && | ||
73 | + v7m_stack_write(cpu, frameptr + 0x10, env->regs[6], mmu_idx, | ||
74 | + ignore_faults) && | ||
75 | + v7m_stack_write(cpu, frameptr + 0x14, env->regs[7], mmu_idx, | ||
76 | + ignore_faults) && | ||
77 | + v7m_stack_write(cpu, frameptr + 0x18, env->regs[8], mmu_idx, | ||
78 | + ignore_faults) && | ||
79 | + v7m_stack_write(cpu, frameptr + 0x1c, env->regs[9], mmu_idx, | ||
80 | + ignore_faults) && | ||
81 | + v7m_stack_write(cpu, frameptr + 0x20, env->regs[10], mmu_idx, | ||
82 | + ignore_faults) && | ||
83 | + v7m_stack_write(cpu, frameptr + 0x24, env->regs[11], mmu_idx, | ||
84 | + ignore_faults); | ||
85 | |||
86 | + /* Update SP regardless of whether any of the stack accesses failed. | ||
87 | + * When we implement v8M stack limit checking then this attempt to | ||
88 | + * update SP might also fail and result in a derived exception. | ||
89 | + */ | ||
90 | *frame_sp_p = frameptr; | ||
91 | + | ||
92 | + return !stacked_ok; | ||
93 | } | ||
94 | |||
95 | static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
96 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
97 | uint32_t addr; | ||
98 | bool targets_secure; | ||
99 | int exc; | ||
100 | + bool push_failed = false; | ||
101 | |||
102 | armv7m_nvic_get_pending_irq_info(env->nvic, &exc, &targets_secure); | ||
103 | |||
104 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
105 | */ | ||
106 | if (lr & R_V7M_EXCRET_DCRS_MASK && | ||
107 | !(dotailchain && (lr & R_V7M_EXCRET_ES_MASK))) { | ||
108 | - v7m_push_callee_stack(cpu, lr, dotailchain, | ||
109 | - ignore_stackfaults); | ||
110 | + push_failed = v7m_push_callee_stack(cpu, lr, dotailchain, | ||
111 | + ignore_stackfaults); | ||
112 | } | ||
113 | lr |= R_V7M_EXCRET_DCRS_MASK; | ||
114 | } | ||
115 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
116 | } | ||
117 | } | ||
118 | |||
119 | + if (push_failed && !ignore_stackfaults) { | ||
120 | + /* Derived exception on callee-saves register stacking: | ||
121 | + * we might now want to take a different exception which | ||
122 | + * targets a different security state, so try again from the top. | ||
123 | + */ | ||
124 | + v7m_exception_taken(cpu, lr, true, true); | ||
125 | + return; | ||
126 | + } | 30 | + } |
127 | + | 31 | + |
128 | addr = arm_v7m_load_vector(cpu, exc, targets_secure); | 32 | new_el = el_from_spsr(spsr); |
129 | 33 | if (new_el == -1) { | |
130 | /* Now we've done everything that might cause a derived exception | 34 | goto illegal_return; |
131 | -- | 35 | -- |
132 | 2.16.1 | 36 | 2.34.1 |
133 | |||
134 | diff view generated by jsdifflib |
1 | The documentation for the generic loader claims that you can | 1 | In the m48t59 device we almost always use 64-bit arithmetic when |
---|---|---|---|
2 | set the PC for a CPU with an option of the form | 2 | dealing with time_t deltas. The one exception is in set_alarm(), |
3 | -device loader,cpu-num=0,addr=0x10000004 | 3 | which currently uses a plain 'int' to hold the difference between two |
4 | 4 | time_t values. Switch to int64_t instead to avoid any possible | |
5 | However if you try this QEMU complains: | 5 | overflow issues. |
6 | cpu_num must be specified when setting a program counter | ||
7 | |||
8 | This is because we were testing against 0 rather than CPU_NONE. | ||
9 | 6 | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | 8 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
12 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
13 | Message-id: 20180205150426.20542-1-peter.maydell@linaro.org | ||
14 | --- | 9 | --- |
15 | hw/core/generic-loader.c | 2 +- | 10 | hw/rtc/m48t59.c | 2 +- |
16 | 1 file changed, 1 insertion(+), 1 deletion(-) | 11 | 1 file changed, 1 insertion(+), 1 deletion(-) |
17 | 12 | ||
18 | diff --git a/hw/core/generic-loader.c b/hw/core/generic-loader.c | 13 | diff --git a/hw/rtc/m48t59.c b/hw/rtc/m48t59.c |
19 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/hw/core/generic-loader.c | 15 | --- a/hw/rtc/m48t59.c |
21 | +++ b/hw/core/generic-loader.c | 16 | +++ b/hw/rtc/m48t59.c |
22 | @@ -XXX,XX +XXX,XX @@ static void generic_loader_realize(DeviceState *dev, Error **errp) | 17 | @@ -XXX,XX +XXX,XX @@ static void alarm_cb (void *opaque) |
23 | error_setg(errp, "data can not be specified when setting a " | 18 | |
24 | "program counter"); | 19 | static void set_alarm(M48t59State *NVRAM) |
25 | return; | 20 | { |
26 | - } else if (!s->cpu_num) { | 21 | - int diff; |
27 | + } else if (s->cpu_num == CPU_NONE) { | 22 | + int64_t diff; |
28 | error_setg(errp, "cpu_num must be specified when setting a " | 23 | if (NVRAM->alrm_timer != NULL) { |
29 | "program counter"); | 24 | timer_del(NVRAM->alrm_timer); |
30 | return; | 25 | diff = qemu_timedate_diff(&NVRAM->alarm) - NVRAM->time_offset; |
31 | -- | 26 | -- |
32 | 2.16.1 | 27 | 2.34.1 |
33 | 28 | ||
34 | 29 | diff view generated by jsdifflib |
1 | The code where we added the TT instruction was accidentally | 1 | In the twl92230 device, use int64_t for the two state fields |
---|---|---|---|
2 | missing a 'break', which meant that after generating the code | 2 | sec_offset and alm_sec, because we set these to values that |
3 | to execute the TT we would fall through to 'goto illegal_op' | 3 | are either time_t or differences between two time_t values. |
4 | and generate code to take an UNDEF insn. | 4 | |
5 | These fields aren't saved in vmstate anywhere, so we can | ||
6 | safely widen them. | ||
5 | 7 | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 9 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
8 | Message-id: 20180206103941.13985-1-peter.maydell@linaro.org | ||
9 | --- | 10 | --- |
10 | target/arm/translate.c | 1 + | 11 | hw/rtc/twl92230.c | 4 ++-- |
11 | 1 file changed, 1 insertion(+) | 12 | 1 file changed, 2 insertions(+), 2 deletions(-) |
12 | 13 | ||
13 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 14 | diff --git a/hw/rtc/twl92230.c b/hw/rtc/twl92230.c |
14 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/translate.c | 16 | --- a/hw/rtc/twl92230.c |
16 | +++ b/target/arm/translate.c | 17 | +++ b/hw/rtc/twl92230.c |
17 | @@ -XXX,XX +XXX,XX @@ static void disas_thumb2_insn(DisasContext *s, uint32_t insn) | 18 | @@ -XXX,XX +XXX,XX @@ struct MenelausState { |
18 | tcg_temp_free_i32(addr); | 19 | struct tm tm; |
19 | tcg_temp_free_i32(op); | 20 | struct tm new; |
20 | store_reg(s, rd, ttresp); | 21 | struct tm alm; |
21 | + break; | 22 | - int sec_offset; |
22 | } | 23 | - int alm_sec; |
23 | goto illegal_op; | 24 | + int64_t sec_offset; |
24 | } | 25 | + int64_t alm_sec; |
26 | int next_comp; | ||
27 | } rtc; | ||
28 | uint16_t rtc_next_vmstate; | ||
25 | -- | 29 | -- |
26 | 2.16.1 | 30 | 2.34.1 |
27 | 31 | ||
28 | 32 | diff view generated by jsdifflib |
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | 1 | In the aspeed_rtc device we store a difference between two time_t |
---|---|---|---|
2 | values in an 'int'. This is not really correct when time_t could | ||
3 | be 64 bits. Enlarge the field to 'int64_t'. | ||
2 | 4 | ||
3 | IP block found on several generations of i.MX family does not use | 5 | This is a migration compatibility break for the aspeed boards. |
4 | vanilla SDHCI implementation and it comes with a number of quirks. | 6 | While we are changing the vmstate, remove the accidental |
7 | duplicate of the offset field. | ||
5 | 8 | ||
6 | Introduce i.MX SDHCI subtype of SDHCI block to add code necessary to | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | support unmodified Linux guest driver. | 10 | Reviewed-by: Cédric Le Goater <clg@kaod.org> |
11 | --- | ||
12 | include/hw/rtc/aspeed_rtc.h | 2 +- | ||
13 | hw/rtc/aspeed_rtc.c | 5 ++--- | ||
14 | 2 files changed, 3 insertions(+), 4 deletions(-) | ||
8 | 15 | ||
9 | Cc: Peter Maydell <peter.maydell@linaro.org> | 16 | diff --git a/include/hw/rtc/aspeed_rtc.h b/include/hw/rtc/aspeed_rtc.h |
10 | Cc: Jason Wang <jasowang@redhat.com> | ||
11 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
12 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | ||
13 | Cc: Michael S. Tsirkin <mst@redhat.com> | ||
14 | Cc: qemu-devel@nongnu.org | ||
15 | Cc: qemu-arm@nongnu.org | ||
16 | Cc: yurovsky@gmail.com | ||
17 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
18 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
19 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
20 | [PMM: define and use ESDHC_UNDOCUMENTED_REG27] | ||
21 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
22 | --- | ||
23 | hw/sd/sdhci-internal.h | 23 +++++ | ||
24 | include/hw/sd/sdhci.h | 13 +++ | ||
25 | hw/sd/sdhci.c | 230 ++++++++++++++++++++++++++++++++++++++++++++++++- | ||
26 | 3 files changed, 265 insertions(+), 1 deletion(-) | ||
27 | |||
28 | diff --git a/hw/sd/sdhci-internal.h b/hw/sd/sdhci-internal.h | ||
29 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/hw/sd/sdhci-internal.h | 18 | --- a/include/hw/rtc/aspeed_rtc.h |
31 | +++ b/hw/sd/sdhci-internal.h | 19 | +++ b/include/hw/rtc/aspeed_rtc.h |
32 | @@ -XXX,XX +XXX,XX @@ | 20 | @@ -XXX,XX +XXX,XX @@ struct AspeedRtcState { |
33 | 21 | qemu_irq irq; | |
34 | /* R/W Host control Register 0x0 */ | 22 | |
35 | #define SDHC_HOSTCTL 0x28 | 23 | uint32_t reg[0x18]; |
36 | +#define SDHC_CTRL_LED 0x01 | 24 | - int offset; |
37 | #define SDHC_CTRL_DMA_CHECK_MASK 0x18 | 25 | + int64_t offset; |
38 | #define SDHC_CTRL_SDMA 0x00 | 26 | |
39 | #define SDHC_CTRL_ADMA1_32 0x08 | ||
40 | #define SDHC_CTRL_ADMA2_32 0x10 | ||
41 | #define SDHC_CTRL_ADMA2_64 0x18 | ||
42 | #define SDHC_DMA_TYPE(x) ((x) & SDHC_CTRL_DMA_CHECK_MASK) | ||
43 | +#define SDHC_CTRL_4BITBUS 0x02 | ||
44 | +#define SDHC_CTRL_8BITBUS 0x20 | ||
45 | +#define SDHC_CTRL_CDTEST_INS 0x40 | ||
46 | +#define SDHC_CTRL_CDTEST_EN 0x80 | ||
47 | + | ||
48 | |||
49 | /* R/W Power Control Register 0x0 */ | ||
50 | #define SDHC_PWRCON 0x29 | ||
51 | @@ -XXX,XX +XXX,XX @@ enum { | ||
52 | sdhc_gap_write = 2 /* SDHC stopped at block gap during write operation */ | ||
53 | }; | 27 | }; |
54 | 28 | ||
55 | +extern const VMStateDescription sdhci_vmstate; | 29 | diff --git a/hw/rtc/aspeed_rtc.c b/hw/rtc/aspeed_rtc.c |
56 | + | ||
57 | + | ||
58 | +#define ESDHC_MIX_CTRL 0x48 | ||
59 | +#define ESDHC_VENDOR_SPEC 0xc0 | ||
60 | +#define ESDHC_DLL_CTRL 0x60 | ||
61 | + | ||
62 | +#define ESDHC_TUNING_CTRL 0xcc | ||
63 | +#define ESDHC_TUNE_CTRL_STATUS 0x68 | ||
64 | +#define ESDHC_WTMK_LVL 0x44 | ||
65 | + | ||
66 | +/* Undocumented register used by guests working around erratum ERR004536 */ | ||
67 | +#define ESDHC_UNDOCUMENTED_REG27 0x6c | ||
68 | + | ||
69 | +#define ESDHC_CTRL_4BITBUS (0x1 << 1) | ||
70 | +#define ESDHC_CTRL_8BITBUS (0x2 << 1) | ||
71 | + | ||
72 | #endif | ||
73 | diff --git a/include/hw/sd/sdhci.h b/include/hw/sd/sdhci.h | ||
74 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
75 | --- a/include/hw/sd/sdhci.h | 31 | --- a/hw/rtc/aspeed_rtc.c |
76 | +++ b/include/hw/sd/sdhci.h | 32 | +++ b/hw/rtc/aspeed_rtc.c |
77 | @@ -XXX,XX +XXX,XX @@ typedef struct SDHCIState { | 33 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps aspeed_rtc_ops = { |
78 | AddressSpace sysbus_dma_as; | 34 | |
79 | AddressSpace *dma_as; | 35 | static const VMStateDescription vmstate_aspeed_rtc = { |
80 | MemoryRegion *dma_mr; | 36 | .name = TYPE_ASPEED_RTC, |
81 | + const MemoryRegionOps *io_ops; | 37 | - .version_id = 1, |
82 | 38 | + .version_id = 2, | |
83 | QEMUTimer *insert_timer; /* timer for 'changing' sd card. */ | 39 | .fields = (VMStateField[]) { |
84 | QEMUTimer *transfer_timer; | 40 | VMSTATE_UINT32_ARRAY(reg, AspeedRtcState, 0x18), |
85 | @@ -XXX,XX +XXX,XX @@ typedef struct SDHCIState { | 41 | - VMSTATE_INT32(offset, AspeedRtcState), |
86 | 42 | - VMSTATE_INT32(offset, AspeedRtcState), | |
87 | /* Configurable properties */ | 43 | + VMSTATE_INT64(offset, AspeedRtcState), |
88 | bool pending_insert_quirk; /* Quirk for Raspberry Pi card insert int */ | 44 | VMSTATE_END_OF_LIST() |
89 | + uint32_t quirks; | ||
90 | } SDHCIState; | ||
91 | |||
92 | +/* | ||
93 | + * Controller does not provide transfer-complete interrupt when not | ||
94 | + * busy. | ||
95 | + * | ||
96 | + * NOTE: This definition is taken out of Linux kernel and so the | ||
97 | + * original bit number is preserved | ||
98 | + */ | ||
99 | +#define SDHCI_QUIRK_NO_BUSY_IRQ BIT(14) | ||
100 | + | ||
101 | #define TYPE_PCI_SDHCI "sdhci-pci" | ||
102 | #define PCI_SDHCI(obj) OBJECT_CHECK(SDHCIState, (obj), TYPE_PCI_SDHCI) | ||
103 | |||
104 | @@ -XXX,XX +XXX,XX @@ typedef struct SDHCIState { | ||
105 | #define SYSBUS_SDHCI(obj) \ | ||
106 | OBJECT_CHECK(SDHCIState, (obj), TYPE_SYSBUS_SDHCI) | ||
107 | |||
108 | +#define TYPE_IMX_USDHC "imx-usdhc" | ||
109 | + | ||
110 | #endif /* SDHCI_H */ | ||
111 | diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c | ||
112 | index XXXXXXX..XXXXXXX 100644 | ||
113 | --- a/hw/sd/sdhci.c | ||
114 | +++ b/hw/sd/sdhci.c | ||
115 | @@ -XXX,XX +XXX,XX @@ static void sdhci_send_command(SDHCIState *s) | ||
116 | } | ||
117 | } | ||
118 | |||
119 | - if ((s->norintstsen & SDHC_NISEN_TRSCMP) && | ||
120 | + if (!(s->quirks & SDHCI_QUIRK_NO_BUSY_IRQ) && | ||
121 | + (s->norintstsen & SDHC_NISEN_TRSCMP) && | ||
122 | (s->cmdreg & SDHC_CMD_RESPONSE) == SDHC_CMD_RSP_WITH_BUSY) { | ||
123 | s->norintsts |= SDHC_NIS_TRSCMP; | ||
124 | } | ||
125 | @@ -XXX,XX +XXX,XX @@ static void sdhci_initfn(SDHCIState *s) | ||
126 | |||
127 | s->insert_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, sdhci_raise_insertion_irq, s); | ||
128 | s->transfer_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, sdhci_data_transfer, s); | ||
129 | + | ||
130 | + s->io_ops = &sdhci_mmio_ops; | ||
131 | } | ||
132 | |||
133 | static void sdhci_uninitfn(SDHCIState *s) | ||
134 | @@ -XXX,XX +XXX,XX @@ static void sdhci_sysbus_realize(DeviceState *dev, Error ** errp) | ||
135 | } | 45 | } |
136 | |||
137 | sysbus_init_irq(sbd, &s->irq); | ||
138 | + | ||
139 | + memory_region_init_io(&s->iomem, OBJECT(s), s->io_ops, s, "sdhci", | ||
140 | + SDHC_REGISTERS_MAP_SIZE); | ||
141 | + | ||
142 | sysbus_init_mmio(sbd, &s->iomem); | ||
143 | } | ||
144 | |||
145 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo sdhci_bus_info = { | ||
146 | .class_init = sdhci_bus_class_init, | ||
147 | }; | 46 | }; |
148 | |||
149 | +static uint64_t usdhc_read(void *opaque, hwaddr offset, unsigned size) | ||
150 | +{ | ||
151 | + SDHCIState *s = SYSBUS_SDHCI(opaque); | ||
152 | + uint32_t ret; | ||
153 | + uint16_t hostctl; | ||
154 | + | ||
155 | + switch (offset) { | ||
156 | + default: | ||
157 | + return sdhci_read(opaque, offset, size); | ||
158 | + | ||
159 | + case SDHC_HOSTCTL: | ||
160 | + /* | ||
161 | + * For a detailed explanation on the following bit | ||
162 | + * manipulation code see comments in a similar part of | ||
163 | + * usdhc_write() | ||
164 | + */ | ||
165 | + hostctl = SDHC_DMA_TYPE(s->hostctl) << (8 - 3); | ||
166 | + | ||
167 | + if (s->hostctl & SDHC_CTRL_8BITBUS) { | ||
168 | + hostctl |= ESDHC_CTRL_8BITBUS; | ||
169 | + } | ||
170 | + | ||
171 | + if (s->hostctl & SDHC_CTRL_4BITBUS) { | ||
172 | + hostctl |= ESDHC_CTRL_4BITBUS; | ||
173 | + } | ||
174 | + | ||
175 | + ret = hostctl; | ||
176 | + ret |= (uint32_t)s->blkgap << 16; | ||
177 | + ret |= (uint32_t)s->wakcon << 24; | ||
178 | + | ||
179 | + break; | ||
180 | + | ||
181 | + case ESDHC_DLL_CTRL: | ||
182 | + case ESDHC_TUNE_CTRL_STATUS: | ||
183 | + case ESDHC_UNDOCUMENTED_REG27: | ||
184 | + case ESDHC_TUNING_CTRL: | ||
185 | + case ESDHC_VENDOR_SPEC: | ||
186 | + case ESDHC_MIX_CTRL: | ||
187 | + case ESDHC_WTMK_LVL: | ||
188 | + ret = 0; | ||
189 | + break; | ||
190 | + } | ||
191 | + | ||
192 | + return ret; | ||
193 | +} | ||
194 | + | ||
195 | +static void | ||
196 | +usdhc_write(void *opaque, hwaddr offset, uint64_t val, unsigned size) | ||
197 | +{ | ||
198 | + SDHCIState *s = SYSBUS_SDHCI(opaque); | ||
199 | + uint8_t hostctl; | ||
200 | + uint32_t value = (uint32_t)val; | ||
201 | + | ||
202 | + switch (offset) { | ||
203 | + case ESDHC_DLL_CTRL: | ||
204 | + case ESDHC_TUNE_CTRL_STATUS: | ||
205 | + case ESDHC_UNDOCUMENTED_REG27: | ||
206 | + case ESDHC_TUNING_CTRL: | ||
207 | + case ESDHC_WTMK_LVL: | ||
208 | + case ESDHC_VENDOR_SPEC: | ||
209 | + break; | ||
210 | + | ||
211 | + case SDHC_HOSTCTL: | ||
212 | + /* | ||
213 | + * Here's What ESDHCI has at offset 0x28 (SDHC_HOSTCTL) | ||
214 | + * | ||
215 | + * 7 6 5 4 3 2 1 0 | ||
216 | + * |-----------+--------+--------+-----------+----------+---------| | ||
217 | + * | Card | Card | Endian | DATA3 | Data | Led | | ||
218 | + * | Detect | Detect | Mode | as Card | Transfer | Control | | ||
219 | + * | Signal | Test | | Detection | Width | | | ||
220 | + * | Selection | Level | | Pin | | | | ||
221 | + * |-----------+--------+--------+-----------+----------+---------| | ||
222 | + * | ||
223 | + * and 0x29 | ||
224 | + * | ||
225 | + * 15 10 9 8 | ||
226 | + * |----------+------| | ||
227 | + * | Reserved | DMA | | ||
228 | + * | | Sel. | | ||
229 | + * | | | | ||
230 | + * |----------+------| | ||
231 | + * | ||
232 | + * and here's what SDCHI spec expects those offsets to be: | ||
233 | + * | ||
234 | + * 0x28 (Host Control Register) | ||
235 | + * | ||
236 | + * 7 6 5 4 3 2 1 0 | ||
237 | + * |--------+--------+----------+------+--------+----------+---------| | ||
238 | + * | Card | Card | Extended | DMA | High | Data | LED | | ||
239 | + * | Detect | Detect | Data | Sel. | Speed | Transfer | Control | | ||
240 | + * | Signal | Test | Transfer | | Enable | Width | | | ||
241 | + * | Sel. | Level | Width | | | | | | ||
242 | + * |--------+--------+----------+------+--------+----------+---------| | ||
243 | + * | ||
244 | + * and 0x29 (Power Control Register) | ||
245 | + * | ||
246 | + * |----------------------------------| | ||
247 | + * | Power Control Register | | ||
248 | + * | | | ||
249 | + * | Description omitted, | | ||
250 | + * | since it has no analog in ESDHCI | | ||
251 | + * | | | ||
252 | + * |----------------------------------| | ||
253 | + * | ||
254 | + * Since offsets 0x2A and 0x2B should be compatible between | ||
255 | + * both IP specs we only need to reconcile least 16-bit of the | ||
256 | + * word we've been given. | ||
257 | + */ | ||
258 | + | ||
259 | + /* | ||
260 | + * First, save bits 7 6 and 0 since they are identical | ||
261 | + */ | ||
262 | + hostctl = value & (SDHC_CTRL_LED | | ||
263 | + SDHC_CTRL_CDTEST_INS | | ||
264 | + SDHC_CTRL_CDTEST_EN); | ||
265 | + /* | ||
266 | + * Second, split "Data Transfer Width" from bits 2 and 1 in to | ||
267 | + * bits 5 and 1 | ||
268 | + */ | ||
269 | + if (value & ESDHC_CTRL_8BITBUS) { | ||
270 | + hostctl |= SDHC_CTRL_8BITBUS; | ||
271 | + } | ||
272 | + | ||
273 | + if (value & ESDHC_CTRL_4BITBUS) { | ||
274 | + hostctl |= ESDHC_CTRL_4BITBUS; | ||
275 | + } | ||
276 | + | ||
277 | + /* | ||
278 | + * Third, move DMA select from bits 9 and 8 to bits 4 and 3 | ||
279 | + */ | ||
280 | + hostctl |= SDHC_DMA_TYPE(value >> (8 - 3)); | ||
281 | + | ||
282 | + /* | ||
283 | + * Now place the corrected value into low 16-bit of the value | ||
284 | + * we are going to give standard SDHCI write function | ||
285 | + * | ||
286 | + * NOTE: This transformation should be the inverse of what can | ||
287 | + * be found in drivers/mmc/host/sdhci-esdhc-imx.c in Linux | ||
288 | + * kernel | ||
289 | + */ | ||
290 | + value &= ~UINT16_MAX; | ||
291 | + value |= hostctl; | ||
292 | + value |= (uint16_t)s->pwrcon << 8; | ||
293 | + | ||
294 | + sdhci_write(opaque, offset, value, size); | ||
295 | + break; | ||
296 | + | ||
297 | + case ESDHC_MIX_CTRL: | ||
298 | + /* | ||
299 | + * So, when SD/MMC stack in Linux tries to write to "Transfer | ||
300 | + * Mode Register", ESDHC i.MX quirk code will translate it | ||
301 | + * into a write to ESDHC_MIX_CTRL, so we do the opposite in | ||
302 | + * order to get where we started | ||
303 | + * | ||
304 | + * Note that Auto CMD23 Enable bit is located in a wrong place | ||
305 | + * on i.MX, but since it is not used by QEMU we do not care. | ||
306 | + * | ||
307 | + * We don't want to call sdhci_write(.., SDHC_TRNMOD, ...) | ||
308 | + * here becuase it will result in a call to | ||
309 | + * sdhci_send_command(s) which we don't want. | ||
310 | + * | ||
311 | + */ | ||
312 | + s->trnmod = value & UINT16_MAX; | ||
313 | + break; | ||
314 | + case SDHC_TRNMOD: | ||
315 | + /* | ||
316 | + * Similar to above, but this time a write to "Command | ||
317 | + * Register" will be translated into a 4-byte write to | ||
318 | + * "Transfer Mode register" where lower 16-bit of value would | ||
319 | + * be set to zero. So what we do is fill those bits with | ||
320 | + * cached value from s->trnmod and let the SDHCI | ||
321 | + * infrastructure handle the rest | ||
322 | + */ | ||
323 | + sdhci_write(opaque, offset, val | s->trnmod, size); | ||
324 | + break; | ||
325 | + case SDHC_BLKSIZE: | ||
326 | + /* | ||
327 | + * ESDHCI does not implement "Host SDMA Buffer Boundary", and | ||
328 | + * Linux driver will try to zero this field out which will | ||
329 | + * break the rest of SDHCI emulation. | ||
330 | + * | ||
331 | + * Linux defaults to maximum possible setting (512K boundary) | ||
332 | + * and it seems to be the only option that i.MX IP implements, | ||
333 | + * so we artificially set it to that value. | ||
334 | + */ | ||
335 | + val |= 0x7 << 12; | ||
336 | + /* FALLTHROUGH */ | ||
337 | + default: | ||
338 | + sdhci_write(opaque, offset, val, size); | ||
339 | + break; | ||
340 | + } | ||
341 | +} | ||
342 | + | ||
343 | + | ||
344 | +static const MemoryRegionOps usdhc_mmio_ops = { | ||
345 | + .read = usdhc_read, | ||
346 | + .write = usdhc_write, | ||
347 | + .valid = { | ||
348 | + .min_access_size = 1, | ||
349 | + .max_access_size = 4, | ||
350 | + .unaligned = false | ||
351 | + }, | ||
352 | + .endianness = DEVICE_LITTLE_ENDIAN, | ||
353 | +}; | ||
354 | + | ||
355 | +static void imx_usdhc_init(Object *obj) | ||
356 | +{ | ||
357 | + SDHCIState *s = SYSBUS_SDHCI(obj); | ||
358 | + | ||
359 | + s->io_ops = &usdhc_mmio_ops; | ||
360 | + s->quirks = SDHCI_QUIRK_NO_BUSY_IRQ; | ||
361 | +} | ||
362 | + | ||
363 | +static const TypeInfo imx_usdhc_info = { | ||
364 | + .name = TYPE_IMX_USDHC, | ||
365 | + .parent = TYPE_SYSBUS_SDHCI, | ||
366 | + .instance_init = imx_usdhc_init, | ||
367 | +}; | ||
368 | + | ||
369 | static void sdhci_register_types(void) | ||
370 | { | ||
371 | type_register_static(&sdhci_pci_info); | ||
372 | type_register_static(&sdhci_sysbus_info); | ||
373 | type_register_static(&sdhci_bus_info); | ||
374 | + type_register_static(&imx_usdhc_info); | ||
375 | } | ||
376 | |||
377 | type_init(sdhci_register_types) | ||
378 | -- | 47 | -- |
379 | 2.16.1 | 48 | 2.34.1 |
380 | 49 | ||
381 | 50 | diff view generated by jsdifflib |
1 | In the v8M architecture, if the process of taking an exception | 1 | The functions qemu_get_timedate() and qemu_timedate_diff() take |
---|---|---|---|
2 | results in a further exception this is called a derived exception | 2 | and return a time offset as an integer. Coverity points out that |
3 | (for example, an MPU exception when writing the exception frame to | 3 | means that when an RTC device implementation holds an offset |
4 | memory). If the derived exception happens while pushing the initial | 4 | as a time_t, as the m48t59 does, the time_t will get truncated. |
5 | stack frame, we must ignore any subsequent possible exception | 5 | (CID 1507157, 1517772). |
6 | pushing the callee-saves registers. | ||
7 | 6 | ||
8 | In preparation for making the stack writes check for exceptions, | 7 | The functions work with time_t internally, so make them use that type |
9 | add a return value from v7m_push_stack() and a new parameter to | 8 | in their APIs. |
10 | v7m_exception_taken(), so that the former can tell the latter that | ||
11 | it needs to ignore failures to write to the stack. We also plumb | ||
12 | the argument through to v7m_push_callee_stack(), which is where | ||
13 | the code to ignore the failures will be. | ||
14 | 9 | ||
15 | (Note that the v8M ARM pseudocode structures this slightly differently: | 10 | Note that this won't help any Y2038 issues where either the device |
16 | derived exceptions cause the attempt to process the original | 11 | model itself is keeping the offset in a 32-bit integer, or where the |
17 | exception to be abandoned; then at the top level it calls | 12 | hardware under emulation has Y2038 or other rollover problems. If we |
18 | DerivedLateArrival to prioritize the derived exception and call | 13 | missed any cases of the former then hopefully Coverity will warn us |
19 | TakeException from there. We choose to let the NVIC do the prioritization | 14 | about them since after this patch we'd be truncating a time_t in |
20 | and continue forward with a call to TakeException which will then | 15 | assignments from qemu_timedate_diff().) |
21 | take either the original or the derived exception. The effect is | ||
22 | the same, but this structure works better for QEMU because we don't | ||
23 | have a convenient top level place to do the abandon-and-retry logic.) | ||
24 | 16 | ||
25 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
26 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 18 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
27 | Message-id: 1517324542-6607-4-git-send-email-peter.maydell@linaro.org | ||
28 | --- | 19 | --- |
29 | target/arm/helper.c | 35 +++++++++++++++++++++++------------ | 20 | include/sysemu/rtc.h | 4 ++-- |
30 | 1 file changed, 23 insertions(+), 12 deletions(-) | 21 | softmmu/rtc.c | 4 ++-- |
22 | 2 files changed, 4 insertions(+), 4 deletions(-) | ||
31 | 23 | ||
32 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 24 | diff --git a/include/sysemu/rtc.h b/include/sysemu/rtc.h |
33 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
34 | --- a/target/arm/helper.c | 26 | --- a/include/sysemu/rtc.h |
35 | +++ b/target/arm/helper.c | 27 | +++ b/include/sysemu/rtc.h |
36 | @@ -XXX,XX +XXX,XX @@ static uint32_t arm_v7m_load_vector(ARMCPU *cpu, int exc, bool targets_secure) | 28 | @@ -XXX,XX +XXX,XX @@ |
37 | return addr; | 29 | * The behaviour of the clock whose value this function returns will |
30 | * depend on the -rtc command line option passed by the user. | ||
31 | */ | ||
32 | -void qemu_get_timedate(struct tm *tm, int offset); | ||
33 | +void qemu_get_timedate(struct tm *tm, time_t offset); | ||
34 | |||
35 | /** | ||
36 | * qemu_timedate_diff: Return difference between a struct tm and the RTC | ||
37 | @@ -XXX,XX +XXX,XX @@ void qemu_get_timedate(struct tm *tm, int offset); | ||
38 | * a timestamp one hour further ahead than the current RTC time | ||
39 | * then this function will return 3600. | ||
40 | */ | ||
41 | -int qemu_timedate_diff(struct tm *tm); | ||
42 | +time_t qemu_timedate_diff(struct tm *tm); | ||
43 | |||
44 | #endif | ||
45 | diff --git a/softmmu/rtc.c b/softmmu/rtc.c | ||
46 | index XXXXXXX..XXXXXXX 100644 | ||
47 | --- a/softmmu/rtc.c | ||
48 | +++ b/softmmu/rtc.c | ||
49 | @@ -XXX,XX +XXX,XX @@ static time_t qemu_ref_timedate(QEMUClockType clock) | ||
50 | return value; | ||
38 | } | 51 | } |
39 | 52 | ||
40 | -static void v7m_push_callee_stack(ARMCPU *cpu, uint32_t lr, bool dotailchain) | 53 | -void qemu_get_timedate(struct tm *tm, int offset) |
41 | +static void v7m_push_callee_stack(ARMCPU *cpu, uint32_t lr, bool dotailchain, | 54 | +void qemu_get_timedate(struct tm *tm, time_t offset) |
42 | + bool ignore_faults) | ||
43 | { | 55 | { |
44 | /* For v8M, push the callee-saves register part of the stack frame. | 56 | time_t ti = qemu_ref_timedate(rtc_clock); |
45 | * Compare the v8M pseudocode PushCalleeStack(). | 57 | |
46 | @@ -XXX,XX +XXX,XX @@ static void v7m_push_callee_stack(ARMCPU *cpu, uint32_t lr, bool dotailchain) | 58 | @@ -XXX,XX +XXX,XX @@ void qemu_get_timedate(struct tm *tm, int offset) |
47 | *frame_sp_p = frameptr; | 59 | } |
48 | } | 60 | } |
49 | 61 | ||
50 | -static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain) | 62 | -int qemu_timedate_diff(struct tm *tm) |
51 | +static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain, | 63 | +time_t qemu_timedate_diff(struct tm *tm) |
52 | + bool ignore_stackfaults) | ||
53 | { | 64 | { |
54 | /* Do the "take the exception" parts of exception entry, | 65 | time_t seconds; |
55 | * but not the pushing of state to the stack. This is | ||
56 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain) | ||
57 | */ | ||
58 | if (lr & R_V7M_EXCRET_DCRS_MASK && | ||
59 | !(dotailchain && (lr & R_V7M_EXCRET_ES_MASK))) { | ||
60 | - v7m_push_callee_stack(cpu, lr, dotailchain); | ||
61 | + v7m_push_callee_stack(cpu, lr, dotailchain, | ||
62 | + ignore_stackfaults); | ||
63 | } | ||
64 | lr |= R_V7M_EXCRET_DCRS_MASK; | ||
65 | } | ||
66 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain) | ||
67 | env->thumb = addr & 1; | ||
68 | } | ||
69 | |||
70 | -static void v7m_push_stack(ARMCPU *cpu) | ||
71 | +static bool v7m_push_stack(ARMCPU *cpu) | ||
72 | { | ||
73 | /* Do the "set up stack frame" part of exception entry, | ||
74 | * similar to pseudocode PushStack(). | ||
75 | + * Return true if we generate a derived exception (and so | ||
76 | + * should ignore further stack faults trying to process | ||
77 | + * that derived exception.) | ||
78 | */ | ||
79 | CPUARMState *env = &cpu->env; | ||
80 | uint32_t xpsr = xpsr_read(env); | ||
81 | @@ -XXX,XX +XXX,XX @@ static void v7m_push_stack(ARMCPU *cpu) | ||
82 | v7m_push(env, env->regs[2]); | ||
83 | v7m_push(env, env->regs[1]); | ||
84 | v7m_push(env, env->regs[0]); | ||
85 | + | ||
86 | + return false; | ||
87 | } | ||
88 | |||
89 | static void do_v7m_exception_exit(ARMCPU *cpu) | ||
90 | @@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu) | ||
91 | if (sfault) { | ||
92 | env->v7m.sfsr |= R_V7M_SFSR_INVER_MASK; | ||
93 | armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_SECURE, false); | ||
94 | - v7m_exception_taken(cpu, excret, true); | ||
95 | + v7m_exception_taken(cpu, excret, true, false); | ||
96 | qemu_log_mask(CPU_LOG_INT, "...taking SecureFault on existing " | ||
97 | "stackframe: failed EXC_RETURN.ES validity check\n"); | ||
98 | return; | ||
99 | @@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu) | ||
100 | */ | ||
101 | env->v7m.cfsr[env->v7m.secure] |= R_V7M_CFSR_INVPC_MASK; | ||
102 | armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE, env->v7m.secure); | ||
103 | - v7m_exception_taken(cpu, excret, true); | ||
104 | + v7m_exception_taken(cpu, excret, true, false); | ||
105 | qemu_log_mask(CPU_LOG_INT, "...taking UsageFault on existing " | ||
106 | "stackframe: failed exception return integrity check\n"); | ||
107 | return; | ||
108 | @@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu) | ||
109 | /* Take a SecureFault on the current stack */ | ||
110 | env->v7m.sfsr |= R_V7M_SFSR_INVIS_MASK; | ||
111 | armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_SECURE, false); | ||
112 | - v7m_exception_taken(cpu, excret, true); | ||
113 | + v7m_exception_taken(cpu, excret, true, false); | ||
114 | qemu_log_mask(CPU_LOG_INT, "...taking SecureFault on existing " | ||
115 | "stackframe: failed exception return integrity " | ||
116 | "signature check\n"); | ||
117 | @@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu) | ||
118 | armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE, | ||
119 | env->v7m.secure); | ||
120 | env->v7m.cfsr[env->v7m.secure] |= R_V7M_CFSR_INVPC_MASK; | ||
121 | - v7m_exception_taken(cpu, excret, true); | ||
122 | + v7m_exception_taken(cpu, excret, true, false); | ||
123 | qemu_log_mask(CPU_LOG_INT, "...taking UsageFault on existing " | ||
124 | "stackframe: failed exception return integrity " | ||
125 | "check\n"); | ||
126 | @@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu) | ||
127 | /* Take an INVPC UsageFault by pushing the stack again; | ||
128 | * we know we're v7M so this is never a Secure UsageFault. | ||
129 | */ | ||
130 | + bool ignore_stackfaults; | ||
131 | + | ||
132 | assert(!arm_feature(env, ARM_FEATURE_V8)); | ||
133 | armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE, false); | ||
134 | env->v7m.cfsr[env->v7m.secure] |= R_V7M_CFSR_INVPC_MASK; | ||
135 | - v7m_push_stack(cpu); | ||
136 | - v7m_exception_taken(cpu, excret, false); | ||
137 | + ignore_stackfaults = v7m_push_stack(cpu); | ||
138 | + v7m_exception_taken(cpu, excret, false, ignore_stackfaults); | ||
139 | qemu_log_mask(CPU_LOG_INT, "...taking UsageFault on new stackframe: " | ||
140 | "failed exception return integrity check\n"); | ||
141 | return; | ||
142 | @@ -XXX,XX +XXX,XX @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) | ||
143 | ARMCPU *cpu = ARM_CPU(cs); | ||
144 | CPUARMState *env = &cpu->env; | ||
145 | uint32_t lr; | ||
146 | + bool ignore_stackfaults; | ||
147 | |||
148 | arm_log_exception(cs->exception_index); | ||
149 | |||
150 | @@ -XXX,XX +XXX,XX @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) | ||
151 | lr |= R_V7M_EXCRET_MODE_MASK; | ||
152 | } | ||
153 | |||
154 | - v7m_push_stack(cpu); | ||
155 | - v7m_exception_taken(cpu, lr, false); | ||
156 | + ignore_stackfaults = v7m_push_stack(cpu); | ||
157 | + v7m_exception_taken(cpu, lr, false, ignore_stackfaults); | ||
158 | qemu_log_mask(CPU_LOG_INT, "... as %d\n", env->v7m.exception); | ||
159 | } | ||
160 | 66 | ||
161 | -- | 67 | -- |
162 | 2.16.1 | 68 | 2.34.1 |
163 | 69 | ||
164 | 70 | diff view generated by jsdifflib |
1 | Handle possible MPU faults, SAU faults or bus errors when | 1 | Where architecturally one ARM_FEATURE_X flag implies another |
---|---|---|---|
2 | popping register state off the stack during exception return. | 2 | ARM_FEATURE_Y, we allow the CPU init function to only set X, and then |
3 | set Y for it. Currently we do this in two places -- we set a few | ||
4 | flags in arm_cpu_post_init() because we need them to decide which | ||
5 | properties to create on the CPU object, and then we do the rest in | ||
6 | arm_cpu_realizefn(). However, this is fragile, because it's easy to | ||
7 | add a new property and not notice that this means that an X-implies-Y | ||
8 | check now has to move from realize to post-init. | ||
9 | |||
10 | As a specific example, the pmsav7-dregion property is conditional | ||
11 | on ARM_FEATURE_PMSA && ARM_FEATURE_V7, which means it won't appear | ||
12 | on the Cortex-M33 and -M55, because they set ARM_FEATURE_V8 and | ||
13 | rely on V8-implies-V7, which doesn't happen until the realizefn. | ||
14 | |||
15 | Move all of these X-implies-Y checks into a new function, which | ||
16 | we call at the top of arm_cpu_post_init(), so the feature bits | ||
17 | are available at that point. | ||
18 | |||
19 | This does now give us the reverse issue, that if there's a feature | ||
20 | bit which is enabled or disabled by the setting of a property then | ||
21 | then X-implies-Y features that are dependent on that property need to | ||
22 | be in realize, not in this new function. But the only one of those | ||
23 | is the "EL3 implies VBAR" which is already in the right place, so | ||
24 | putting things this way round seems better to me. | ||
3 | 25 | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 26 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 27 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
6 | Message-id: 1517324542-6607-8-git-send-email-peter.maydell@linaro.org | 28 | Message-id: 20230724174335.2150499-2-peter.maydell@linaro.org |
7 | --- | 29 | --- |
8 | target/arm/helper.c | 115 ++++++++++++++++++++++++++++++++++++++++++---------- | 30 | target/arm/cpu.c | 179 +++++++++++++++++++++++++---------------------- |
9 | 1 file changed, 94 insertions(+), 21 deletions(-) | 31 | 1 file changed, 97 insertions(+), 82 deletions(-) |
10 | 32 | ||
11 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 33 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c |
12 | index XXXXXXX..XXXXXXX 100644 | 34 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/arm/helper.c | 35 | --- a/target/arm/cpu.c |
14 | +++ b/target/arm/helper.c | 36 | +++ b/target/arm/cpu.c |
15 | @@ -XXX,XX +XXX,XX @@ pend_fault: | 37 | @@ -XXX,XX +XXX,XX @@ unsigned int gt_cntfrq_period_ns(ARMCPU *cpu) |
16 | return false; | 38 | NANOSECONDS_PER_SECOND / cpu->gt_cntfrq_hz : 1; |
17 | } | 39 | } |
18 | 40 | ||
19 | +static bool v7m_stack_read(ARMCPU *cpu, uint32_t *dest, uint32_t addr, | 41 | +static void arm_cpu_propagate_feature_implications(ARMCPU *cpu) |
20 | + ARMMMUIdx mmu_idx) | ||
21 | +{ | 42 | +{ |
22 | + CPUState *cs = CPU(cpu); | ||
23 | + CPUARMState *env = &cpu->env; | 43 | + CPUARMState *env = &cpu->env; |
24 | + MemTxAttrs attrs = {}; | 44 | + bool no_aa32 = false; |
25 | + MemTxResult txres; | 45 | + |
26 | + target_ulong page_size; | 46 | + /* |
27 | + hwaddr physaddr; | 47 | + * Some features automatically imply others: set the feature |
28 | + int prot; | 48 | + * bits explicitly for these cases. |
29 | + ARMMMUFaultInfo fi; | 49 | + */ |
30 | + bool secure = mmu_idx & ARM_MMU_IDX_M_S; | 50 | + |
31 | + int exc; | 51 | + if (arm_feature(env, ARM_FEATURE_M)) { |
32 | + bool exc_secure; | 52 | + set_feature(env, ARM_FEATURE_PMSA); |
33 | + uint32_t value; | 53 | + } |
34 | + | 54 | + |
35 | + if (get_phys_addr(env, addr, MMU_DATA_LOAD, mmu_idx, &physaddr, | 55 | + if (arm_feature(env, ARM_FEATURE_V8)) { |
36 | + &attrs, &prot, &page_size, &fi, NULL)) { | 56 | + if (arm_feature(env, ARM_FEATURE_M)) { |
37 | + /* MPU/SAU lookup failed */ | 57 | + set_feature(env, ARM_FEATURE_V7); |
38 | + if (fi.type == ARMFault_QEMU_SFault) { | ||
39 | + qemu_log_mask(CPU_LOG_INT, | ||
40 | + "...SecureFault with SFSR.AUVIOL during unstack\n"); | ||
41 | + env->v7m.sfsr |= R_V7M_SFSR_AUVIOL_MASK | R_V7M_SFSR_SFARVALID_MASK; | ||
42 | + env->v7m.sfar = addr; | ||
43 | + exc = ARMV7M_EXCP_SECURE; | ||
44 | + exc_secure = false; | ||
45 | + } else { | 58 | + } else { |
46 | + qemu_log_mask(CPU_LOG_INT, | 59 | + set_feature(env, ARM_FEATURE_V7VE); |
47 | + "...MemManageFault with CFSR.MUNSTKERR\n"); | ||
48 | + env->v7m.cfsr[secure] |= R_V7M_CFSR_MUNSTKERR_MASK; | ||
49 | + exc = ARMV7M_EXCP_MEM; | ||
50 | + exc_secure = secure; | ||
51 | + } | 60 | + } |
52 | + goto pend_fault; | 61 | + } |
53 | + } | 62 | + |
54 | + | 63 | + /* |
55 | + value = address_space_ldl(arm_addressspace(cs, attrs), physaddr, | 64 | + * There exist AArch64 cpus without AArch32 support. When KVM |
56 | + attrs, &txres); | 65 | + * queries ID_ISAR0_EL1 on such a host, the value is UNKNOWN. |
57 | + if (txres != MEMTX_OK) { | 66 | + * Similarly, we cannot check ID_AA64PFR0 without AArch64 support. |
58 | + /* BusFault trying to read the data */ | 67 | + * As a general principle, we also do not make ID register |
59 | + qemu_log_mask(CPU_LOG_INT, "...BusFault with BFSR.UNSTKERR\n"); | 68 | + * consistency checks anywhere unless using TCG, because only |
60 | + env->v7m.cfsr[M_REG_NS] |= R_V7M_CFSR_UNSTKERR_MASK; | 69 | + * for TCG would a consistency-check failure be a QEMU bug. |
61 | + exc = ARMV7M_EXCP_BUS; | ||
62 | + exc_secure = false; | ||
63 | + goto pend_fault; | ||
64 | + } | ||
65 | + | ||
66 | + *dest = value; | ||
67 | + return true; | ||
68 | + | ||
69 | +pend_fault: | ||
70 | + /* By pending the exception at this point we are making | ||
71 | + * the IMPDEF choice "overridden exceptions pended" (see the | ||
72 | + * MergeExcInfo() pseudocode). The other choice would be to not | ||
73 | + * pend them now and then make a choice about which to throw away | ||
74 | + * later if we have two derived exceptions. | ||
75 | + */ | 70 | + */ |
76 | + armv7m_nvic_set_pending(env->nvic, exc, exc_secure); | 71 | + if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) { |
77 | + return false; | 72 | + no_aa32 = !cpu_isar_feature(aa64_aa32, cpu); |
73 | + } | ||
74 | + | ||
75 | + if (arm_feature(env, ARM_FEATURE_V7VE)) { | ||
76 | + /* | ||
77 | + * v7 Virtualization Extensions. In real hardware this implies | ||
78 | + * EL2 and also the presence of the Security Extensions. | ||
79 | + * For QEMU, for backwards-compatibility we implement some | ||
80 | + * CPUs or CPU configs which have no actual EL2 or EL3 but do | ||
81 | + * include the various other features that V7VE implies. | ||
82 | + * Presence of EL2 itself is ARM_FEATURE_EL2, and of the | ||
83 | + * Security Extensions is ARM_FEATURE_EL3. | ||
84 | + */ | ||
85 | + assert(!tcg_enabled() || no_aa32 || | ||
86 | + cpu_isar_feature(aa32_arm_div, cpu)); | ||
87 | + set_feature(env, ARM_FEATURE_LPAE); | ||
88 | + set_feature(env, ARM_FEATURE_V7); | ||
89 | + } | ||
90 | + if (arm_feature(env, ARM_FEATURE_V7)) { | ||
91 | + set_feature(env, ARM_FEATURE_VAPA); | ||
92 | + set_feature(env, ARM_FEATURE_THUMB2); | ||
93 | + set_feature(env, ARM_FEATURE_MPIDR); | ||
94 | + if (!arm_feature(env, ARM_FEATURE_M)) { | ||
95 | + set_feature(env, ARM_FEATURE_V6K); | ||
96 | + } else { | ||
97 | + set_feature(env, ARM_FEATURE_V6); | ||
98 | + } | ||
99 | + | ||
100 | + /* | ||
101 | + * Always define VBAR for V7 CPUs even if it doesn't exist in | ||
102 | + * non-EL3 configs. This is needed by some legacy boards. | ||
103 | + */ | ||
104 | + set_feature(env, ARM_FEATURE_VBAR); | ||
105 | + } | ||
106 | + if (arm_feature(env, ARM_FEATURE_V6K)) { | ||
107 | + set_feature(env, ARM_FEATURE_V6); | ||
108 | + set_feature(env, ARM_FEATURE_MVFR); | ||
109 | + } | ||
110 | + if (arm_feature(env, ARM_FEATURE_V6)) { | ||
111 | + set_feature(env, ARM_FEATURE_V5); | ||
112 | + if (!arm_feature(env, ARM_FEATURE_M)) { | ||
113 | + assert(!tcg_enabled() || no_aa32 || | ||
114 | + cpu_isar_feature(aa32_jazelle, cpu)); | ||
115 | + set_feature(env, ARM_FEATURE_AUXCR); | ||
116 | + } | ||
117 | + } | ||
118 | + if (arm_feature(env, ARM_FEATURE_V5)) { | ||
119 | + set_feature(env, ARM_FEATURE_V4T); | ||
120 | + } | ||
121 | + if (arm_feature(env, ARM_FEATURE_LPAE)) { | ||
122 | + set_feature(env, ARM_FEATURE_V7MP); | ||
123 | + } | ||
124 | + if (arm_feature(env, ARM_FEATURE_CBAR_RO)) { | ||
125 | + set_feature(env, ARM_FEATURE_CBAR); | ||
126 | + } | ||
127 | + if (arm_feature(env, ARM_FEATURE_THUMB2) && | ||
128 | + !arm_feature(env, ARM_FEATURE_M)) { | ||
129 | + set_feature(env, ARM_FEATURE_THUMB_DSP); | ||
130 | + } | ||
78 | +} | 131 | +} |
79 | + | 132 | + |
80 | /* Return true if we're using the process stack pointer (not the MSP) */ | 133 | void arm_cpu_post_init(Object *obj) |
81 | static bool v7m_using_psp(CPUARMState *env) | ||
82 | { | 134 | { |
83 | @@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu) | 135 | ARMCPU *cpu = ARM_CPU(obj); |
84 | !return_to_handler, | 136 | |
85 | return_to_sp_process); | 137 | - /* M profile implies PMSA. We have to do this here rather than |
86 | uint32_t frameptr = *frame_sp_p; | 138 | - * in realize with the other feature-implication checks because |
87 | + bool pop_ok = true; | 139 | - * we look at the PMSA bit to see if we should add some properties. |
88 | + ARMMMUIdx mmu_idx; | 140 | + /* |
89 | + | 141 | + * Some features imply others. Figure this out now, because we |
90 | + mmu_idx = arm_v7m_mmu_idx_for_secstate_and_priv(env, return_to_secure, | 142 | + * are going to look at the feature bits in deciding which |
91 | + !return_to_handler); | 143 | + * properties to add. |
92 | 144 | */ | |
93 | if (!QEMU_IS_ALIGNED(frameptr, 8) && | 145 | - if (arm_feature(&cpu->env, ARM_FEATURE_M)) { |
94 | arm_feature(env, ARM_FEATURE_V8)) { | 146 | - set_feature(&cpu->env, ARM_FEATURE_PMSA); |
95 | @@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu) | 147 | - } |
96 | return; | 148 | + arm_cpu_propagate_feature_implications(cpu); |
97 | } | 149 | |
98 | 150 | if (arm_feature(&cpu->env, ARM_FEATURE_CBAR) || | |
99 | - env->regs[4] = ldl_phys(cs->as, frameptr + 0x8); | 151 | arm_feature(&cpu->env, ARM_FEATURE_CBAR_RO)) { |
100 | - env->regs[5] = ldl_phys(cs->as, frameptr + 0xc); | 152 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) |
101 | - env->regs[6] = ldl_phys(cs->as, frameptr + 0x10); | 153 | CPUARMState *env = &cpu->env; |
102 | - env->regs[7] = ldl_phys(cs->as, frameptr + 0x14); | 154 | int pagebits; |
103 | - env->regs[8] = ldl_phys(cs->as, frameptr + 0x18); | 155 | Error *local_err = NULL; |
104 | - env->regs[9] = ldl_phys(cs->as, frameptr + 0x1c); | 156 | - bool no_aa32 = false; |
105 | - env->regs[10] = ldl_phys(cs->as, frameptr + 0x20); | 157 | |
106 | - env->regs[11] = ldl_phys(cs->as, frameptr + 0x24); | 158 | /* Use pc-relative instructions in system-mode */ |
107 | + pop_ok = | 159 | #ifndef CONFIG_USER_ONLY |
108 | + v7m_stack_read(cpu, &env->regs[4], frameptr + 0x8, mmu_idx) && | 160 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) |
109 | + v7m_stack_read(cpu, &env->regs[4], frameptr + 0x8, mmu_idx) && | 161 | cpu->isar.id_isar3 = u; |
110 | + v7m_stack_read(cpu, &env->regs[5], frameptr + 0xc, mmu_idx) && | 162 | } |
111 | + v7m_stack_read(cpu, &env->regs[6], frameptr + 0x10, mmu_idx) && | 163 | |
112 | + v7m_stack_read(cpu, &env->regs[7], frameptr + 0x14, mmu_idx) && | 164 | - /* Some features automatically imply others: */ |
113 | + v7m_stack_read(cpu, &env->regs[8], frameptr + 0x18, mmu_idx) && | 165 | - if (arm_feature(env, ARM_FEATURE_V8)) { |
114 | + v7m_stack_read(cpu, &env->regs[9], frameptr + 0x1c, mmu_idx) && | 166 | - if (arm_feature(env, ARM_FEATURE_M)) { |
115 | + v7m_stack_read(cpu, &env->regs[10], frameptr + 0x20, mmu_idx) && | 167 | - set_feature(env, ARM_FEATURE_V7); |
116 | + v7m_stack_read(cpu, &env->regs[11], frameptr + 0x24, mmu_idx); | 168 | - } else { |
117 | 169 | - set_feature(env, ARM_FEATURE_V7VE); | |
118 | frameptr += 0x28; | 170 | - } |
119 | } | 171 | - } |
120 | 172 | - | |
121 | - /* Pop registers. TODO: make these accesses use the correct | 173 | - /* |
122 | - * attributes and address space (S/NS, priv/unpriv) and handle | 174 | - * There exist AArch64 cpus without AArch32 support. When KVM |
123 | - * memory transaction failures. | 175 | - * queries ID_ISAR0_EL1 on such a host, the value is UNKNOWN. |
176 | - * Similarly, we cannot check ID_AA64PFR0 without AArch64 support. | ||
177 | - * As a general principle, we also do not make ID register | ||
178 | - * consistency checks anywhere unless using TCG, because only | ||
179 | - * for TCG would a consistency-check failure be a QEMU bug. | ||
180 | - */ | ||
181 | - if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) { | ||
182 | - no_aa32 = !cpu_isar_feature(aa64_aa32, cpu); | ||
183 | - } | ||
184 | - | ||
185 | - if (arm_feature(env, ARM_FEATURE_V7VE)) { | ||
186 | - /* v7 Virtualization Extensions. In real hardware this implies | ||
187 | - * EL2 and also the presence of the Security Extensions. | ||
188 | - * For QEMU, for backwards-compatibility we implement some | ||
189 | - * CPUs or CPU configs which have no actual EL2 or EL3 but do | ||
190 | - * include the various other features that V7VE implies. | ||
191 | - * Presence of EL2 itself is ARM_FEATURE_EL2, and of the | ||
192 | - * Security Extensions is ARM_FEATURE_EL3. | ||
124 | - */ | 193 | - */ |
125 | - env->regs[0] = ldl_phys(cs->as, frameptr); | 194 | - assert(!tcg_enabled() || no_aa32 || |
126 | - env->regs[1] = ldl_phys(cs->as, frameptr + 0x4); | 195 | - cpu_isar_feature(aa32_arm_div, cpu)); |
127 | - env->regs[2] = ldl_phys(cs->as, frameptr + 0x8); | 196 | - set_feature(env, ARM_FEATURE_LPAE); |
128 | - env->regs[3] = ldl_phys(cs->as, frameptr + 0xc); | 197 | - set_feature(env, ARM_FEATURE_V7); |
129 | - env->regs[12] = ldl_phys(cs->as, frameptr + 0x10); | 198 | - } |
130 | - env->regs[14] = ldl_phys(cs->as, frameptr + 0x14); | 199 | - if (arm_feature(env, ARM_FEATURE_V7)) { |
131 | - env->regs[15] = ldl_phys(cs->as, frameptr + 0x18); | 200 | - set_feature(env, ARM_FEATURE_VAPA); |
132 | + /* Pop registers */ | 201 | - set_feature(env, ARM_FEATURE_THUMB2); |
133 | + pop_ok = pop_ok && | 202 | - set_feature(env, ARM_FEATURE_MPIDR); |
134 | + v7m_stack_read(cpu, &env->regs[0], frameptr, mmu_idx) && | 203 | - if (!arm_feature(env, ARM_FEATURE_M)) { |
135 | + v7m_stack_read(cpu, &env->regs[1], frameptr + 0x4, mmu_idx) && | 204 | - set_feature(env, ARM_FEATURE_V6K); |
136 | + v7m_stack_read(cpu, &env->regs[2], frameptr + 0x8, mmu_idx) && | 205 | - } else { |
137 | + v7m_stack_read(cpu, &env->regs[3], frameptr + 0xc, mmu_idx) && | 206 | - set_feature(env, ARM_FEATURE_V6); |
138 | + v7m_stack_read(cpu, &env->regs[12], frameptr + 0x10, mmu_idx) && | 207 | - } |
139 | + v7m_stack_read(cpu, &env->regs[14], frameptr + 0x14, mmu_idx) && | ||
140 | + v7m_stack_read(cpu, &env->regs[15], frameptr + 0x18, mmu_idx) && | ||
141 | + v7m_stack_read(cpu, &xpsr, frameptr + 0x1c, mmu_idx); | ||
142 | + | ||
143 | + if (!pop_ok) { | ||
144 | + /* v7m_stack_read() pended a fault, so take it (as a tail | ||
145 | + * chained exception on the same stack frame) | ||
146 | + */ | ||
147 | + v7m_exception_taken(cpu, excret, true, false); | ||
148 | + return; | ||
149 | + } | ||
150 | |||
151 | /* Returning from an exception with a PC with bit 0 set is defined | ||
152 | * behaviour on v8M (bit 0 is ignored), but for v7M it was specified | ||
153 | @@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu) | ||
154 | } | ||
155 | } | ||
156 | |||
157 | - xpsr = ldl_phys(cs->as, frameptr + 0x1c); | ||
158 | - | 208 | - |
159 | if (arm_feature(env, ARM_FEATURE_V8)) { | 209 | - /* Always define VBAR for V7 CPUs even if it doesn't exist in |
160 | /* For v8M we have to check whether the xPSR exception field | 210 | - * non-EL3 configs. This is needed by some legacy boards. |
161 | * matches the EXCRET value for return to handler/thread | 211 | - */ |
212 | - set_feature(env, ARM_FEATURE_VBAR); | ||
213 | - } | ||
214 | - if (arm_feature(env, ARM_FEATURE_V6K)) { | ||
215 | - set_feature(env, ARM_FEATURE_V6); | ||
216 | - set_feature(env, ARM_FEATURE_MVFR); | ||
217 | - } | ||
218 | - if (arm_feature(env, ARM_FEATURE_V6)) { | ||
219 | - set_feature(env, ARM_FEATURE_V5); | ||
220 | - if (!arm_feature(env, ARM_FEATURE_M)) { | ||
221 | - assert(!tcg_enabled() || no_aa32 || | ||
222 | - cpu_isar_feature(aa32_jazelle, cpu)); | ||
223 | - set_feature(env, ARM_FEATURE_AUXCR); | ||
224 | - } | ||
225 | - } | ||
226 | - if (arm_feature(env, ARM_FEATURE_V5)) { | ||
227 | - set_feature(env, ARM_FEATURE_V4T); | ||
228 | - } | ||
229 | - if (arm_feature(env, ARM_FEATURE_LPAE)) { | ||
230 | - set_feature(env, ARM_FEATURE_V7MP); | ||
231 | - } | ||
232 | - if (arm_feature(env, ARM_FEATURE_CBAR_RO)) { | ||
233 | - set_feature(env, ARM_FEATURE_CBAR); | ||
234 | - } | ||
235 | - if (arm_feature(env, ARM_FEATURE_THUMB2) && | ||
236 | - !arm_feature(env, ARM_FEATURE_M)) { | ||
237 | - set_feature(env, ARM_FEATURE_THUMB_DSP); | ||
238 | - } | ||
239 | |||
240 | /* | ||
241 | * We rely on no XScale CPU having VFP so we can use the same bits in the | ||
162 | -- | 242 | -- |
163 | 2.16.1 | 243 | 2.34.1 |
164 | |||
165 | diff view generated by jsdifflib |
1 | From: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 1 | M-profile CPUs generally allow configuration of the number of MPU |
---|---|---|---|
2 | regions that they have. We don't currently model this, so our | ||
3 | implementations of some of the board models provide CPUs with the | ||
4 | wrong number of regions. RTOSes like Zephyr that hardcode the | ||
5 | expected number of regions may therefore not run on the model if they | ||
6 | are set up to run on real hardware. | ||
2 | 7 | ||
3 | This implements emulation of the new SHA-512 instructions that have | 8 | Add properties mpu-ns-regions and mpu-s-regions to the ARMV7M object, |
4 | been added as an optional extensions to the ARMv8 Crypto Extensions | 9 | matching the ability of hardware to configure the number of Secure |
5 | in ARM v8.2. | 10 | and NonSecure regions separately. Our actual CPU implementation |
11 | doesn't currently support that, and it happens that none of the MPS | ||
12 | boards we model set the number of regions differently for Secure vs | ||
13 | NonSecure, so we provide an interface to the boards and SoCs that | ||
14 | won't need to change if we ever do add that functionality in future, | ||
15 | but make it an error to configure the two properties to different | ||
16 | values. | ||
6 | 17 | ||
7 | Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 18 | (The property name on the CPU is the somewhat misnamed-for-M-profile |
8 | Message-id: 20180207111729.15737-2-ard.biesheuvel@linaro.org | 19 | "pmsav7-dregion", so we don't follow that naming convention for |
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 20 | the properties here. The TRM doesn't say what the CPU configuration |
21 | variable names are, so we pick something, and follow the lowercase | ||
22 | convention we already have for properties here.) | ||
23 | |||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 24 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
25 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
26 | Message-id: 20230724174335.2150499-3-peter.maydell@linaro.org | ||
11 | --- | 27 | --- |
12 | target/arm/cpu.h | 1 + | 28 | include/hw/arm/armv7m.h | 8 ++++++++ |
13 | target/arm/helper.h | 5 +++ | 29 | hw/arm/armv7m.c | 21 +++++++++++++++++++++ |
14 | target/arm/crypto_helper.c | 90 ++++++++++++++++++++++++++++++++++++- | 30 | 2 files changed, 29 insertions(+) |
15 | target/arm/translate-a64.c | 110 +++++++++++++++++++++++++++++++++++++++++++++ | ||
16 | 4 files changed, 205 insertions(+), 1 deletion(-) | ||
17 | 31 | ||
18 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 32 | diff --git a/include/hw/arm/armv7m.h b/include/hw/arm/armv7m.h |
19 | index XXXXXXX..XXXXXXX 100644 | 33 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/target/arm/cpu.h | 34 | --- a/include/hw/arm/armv7m.h |
21 | +++ b/target/arm/cpu.h | 35 | +++ b/include/hw/arm/armv7m.h |
22 | @@ -XXX,XX +XXX,XX @@ enum arm_features { | 36 | @@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_SIMPLE_TYPE(ARMv7MState, ARMV7M) |
23 | ARM_FEATURE_M_SECURITY, /* M profile Security Extension */ | 37 | * + Property "vfp": enable VFP (forwarded to CPU object) |
24 | ARM_FEATURE_JAZELLE, /* has (trivial) Jazelle implementation */ | 38 | * + Property "dsp": enable DSP (forwarded to CPU object) |
25 | ARM_FEATURE_SVE, /* has Scalable Vector Extension */ | 39 | * + Property "enable-bitband": expose bitbanded IO |
26 | + ARM_FEATURE_V8_SHA512, /* implements SHA512 part of v8 Crypto Extensions */ | 40 | + * + Property "mpu-ns-regions": number of Non-Secure MPU regions (forwarded |
27 | }; | 41 | + * to CPU object pmsav7-dregion property; default is whatever the default |
28 | 42 | + * for the CPU is) | |
29 | static inline int arm_feature(CPUARMState *env, int feature) | 43 | + * + Property "mpu-s-regions": number of Secure MPU regions (default is |
30 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 44 | + * whatever the default for the CPU is; must currently be set to the same |
45 | + * value as mpu-ns-regions if the CPU implements the Security Extension) | ||
46 | * + Clock input "refclk" is the external reference clock for the systick timers | ||
47 | * + Clock input "cpuclk" is the main CPU clock | ||
48 | */ | ||
49 | @@ -XXX,XX +XXX,XX @@ struct ARMv7MState { | ||
50 | Object *idau; | ||
51 | uint32_t init_svtor; | ||
52 | uint32_t init_nsvtor; | ||
53 | + uint32_t mpu_ns_regions; | ||
54 | + uint32_t mpu_s_regions; | ||
55 | bool enable_bitband; | ||
56 | bool start_powered_off; | ||
57 | bool vfp; | ||
58 | diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | 59 | index XXXXXXX..XXXXXXX 100644 |
32 | --- a/target/arm/helper.h | 60 | --- a/hw/arm/armv7m.c |
33 | +++ b/target/arm/helper.h | 61 | +++ b/hw/arm/armv7m.c |
34 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(crypto_sha256h2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 62 | @@ -XXX,XX +XXX,XX @@ static void armv7m_realize(DeviceState *dev, Error **errp) |
35 | DEF_HELPER_FLAGS_2(crypto_sha256su0, TCG_CALL_NO_RWG, void, ptr, ptr) | 63 | } |
36 | DEF_HELPER_FLAGS_3(crypto_sha256su1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 64 | } |
37 | 65 | ||
38 | +DEF_HELPER_FLAGS_3(crypto_sha512h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 66 | + /* |
39 | +DEF_HELPER_FLAGS_3(crypto_sha512h2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 67 | + * Real M-profile hardware can be configured with a different number of |
40 | +DEF_HELPER_FLAGS_2(crypto_sha512su0, TCG_CALL_NO_RWG, void, ptr, ptr) | 68 | + * MPU regions for Secure vs NonSecure. QEMU's CPU implementation doesn't |
41 | +DEF_HELPER_FLAGS_3(crypto_sha512su1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 69 | + * support that yet, so catch attempts to select that. |
42 | + | 70 | + */ |
43 | DEF_HELPER_FLAGS_3(crc32, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) | 71 | + if (arm_feature(&s->cpu->env, ARM_FEATURE_M_SECURITY) && |
44 | DEF_HELPER_FLAGS_3(crc32c, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) | 72 | + s->mpu_ns_regions != s->mpu_s_regions) { |
45 | DEF_HELPER_2(dc_zva, void, env, i64) | 73 | + error_setg(errp, |
46 | diff --git a/target/arm/crypto_helper.c b/target/arm/crypto_helper.c | 74 | + "mpu-ns-regions and mpu-s-regions properties must have the same value"); |
47 | index XXXXXXX..XXXXXXX 100644 | 75 | + return; |
48 | --- a/target/arm/crypto_helper.c | 76 | + } |
49 | +++ b/target/arm/crypto_helper.c | 77 | + if (s->mpu_ns_regions != UINT_MAX && |
50 | @@ -XXX,XX +XXX,XX @@ | 78 | + object_property_find(OBJECT(s->cpu), "pmsav7-dregion")) { |
51 | /* | 79 | + if (!object_property_set_uint(OBJECT(s->cpu), "pmsav7-dregion", |
52 | * crypto_helper.c - emulate v8 Crypto Extensions instructions | 80 | + s->mpu_ns_regions, errp)) { |
53 | * | ||
54 | - * Copyright (C) 2013 - 2014 Linaro Ltd <ard.biesheuvel@linaro.org> | ||
55 | + * Copyright (C) 2013 - 2018 Linaro Ltd <ard.biesheuvel@linaro.org> | ||
56 | * | ||
57 | * This library is free software; you can redistribute it and/or | ||
58 | * modify it under the terms of the GNU Lesser General Public | ||
59 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sha256su1)(void *vd, void *vn, void *vm) | ||
60 | rd[0] = d.l[0]; | ||
61 | rd[1] = d.l[1]; | ||
62 | } | ||
63 | + | ||
64 | +/* | ||
65 | + * The SHA-512 logical functions (same as above but using 64-bit operands) | ||
66 | + */ | ||
67 | + | ||
68 | +static uint64_t cho512(uint64_t x, uint64_t y, uint64_t z) | ||
69 | +{ | ||
70 | + return (x & (y ^ z)) ^ z; | ||
71 | +} | ||
72 | + | ||
73 | +static uint64_t maj512(uint64_t x, uint64_t y, uint64_t z) | ||
74 | +{ | ||
75 | + return (x & y) | ((x | y) & z); | ||
76 | +} | ||
77 | + | ||
78 | +static uint64_t S0_512(uint64_t x) | ||
79 | +{ | ||
80 | + return ror64(x, 28) ^ ror64(x, 34) ^ ror64(x, 39); | ||
81 | +} | ||
82 | + | ||
83 | +static uint64_t S1_512(uint64_t x) | ||
84 | +{ | ||
85 | + return ror64(x, 14) ^ ror64(x, 18) ^ ror64(x, 41); | ||
86 | +} | ||
87 | + | ||
88 | +static uint64_t s0_512(uint64_t x) | ||
89 | +{ | ||
90 | + return ror64(x, 1) ^ ror64(x, 8) ^ (x >> 7); | ||
91 | +} | ||
92 | + | ||
93 | +static uint64_t s1_512(uint64_t x) | ||
94 | +{ | ||
95 | + return ror64(x, 19) ^ ror64(x, 61) ^ (x >> 6); | ||
96 | +} | ||
97 | + | ||
98 | +void HELPER(crypto_sha512h)(void *vd, void *vn, void *vm) | ||
99 | +{ | ||
100 | + uint64_t *rd = vd; | ||
101 | + uint64_t *rn = vn; | ||
102 | + uint64_t *rm = vm; | ||
103 | + uint64_t d0 = rd[0]; | ||
104 | + uint64_t d1 = rd[1]; | ||
105 | + | ||
106 | + d1 += S1_512(rm[1]) + cho512(rm[1], rn[0], rn[1]); | ||
107 | + d0 += S1_512(d1 + rm[0]) + cho512(d1 + rm[0], rm[1], rn[0]); | ||
108 | + | ||
109 | + rd[0] = d0; | ||
110 | + rd[1] = d1; | ||
111 | +} | ||
112 | + | ||
113 | +void HELPER(crypto_sha512h2)(void *vd, void *vn, void *vm) | ||
114 | +{ | ||
115 | + uint64_t *rd = vd; | ||
116 | + uint64_t *rn = vn; | ||
117 | + uint64_t *rm = vm; | ||
118 | + uint64_t d0 = rd[0]; | ||
119 | + uint64_t d1 = rd[1]; | ||
120 | + | ||
121 | + d1 += S0_512(rm[0]) + maj512(rn[0], rm[1], rm[0]); | ||
122 | + d0 += S0_512(d1) + maj512(d1, rm[0], rm[1]); | ||
123 | + | ||
124 | + rd[0] = d0; | ||
125 | + rd[1] = d1; | ||
126 | +} | ||
127 | + | ||
128 | +void HELPER(crypto_sha512su0)(void *vd, void *vn) | ||
129 | +{ | ||
130 | + uint64_t *rd = vd; | ||
131 | + uint64_t *rn = vn; | ||
132 | + uint64_t d0 = rd[0]; | ||
133 | + uint64_t d1 = rd[1]; | ||
134 | + | ||
135 | + d0 += s0_512(rd[1]); | ||
136 | + d1 += s0_512(rn[0]); | ||
137 | + | ||
138 | + rd[0] = d0; | ||
139 | + rd[1] = d1; | ||
140 | +} | ||
141 | + | ||
142 | +void HELPER(crypto_sha512su1)(void *vd, void *vn, void *vm) | ||
143 | +{ | ||
144 | + uint64_t *rd = vd; | ||
145 | + uint64_t *rn = vn; | ||
146 | + uint64_t *rm = vm; | ||
147 | + | ||
148 | + rd[0] += s1_512(rn[0]) + rm[0]; | ||
149 | + rd[1] += s1_512(rn[1]) + rm[1]; | ||
150 | +} | ||
151 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
152 | index XXXXXXX..XXXXXXX 100644 | ||
153 | --- a/target/arm/translate-a64.c | ||
154 | +++ b/target/arm/translate-a64.c | ||
155 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_two_reg_sha(DisasContext *s, uint32_t insn) | ||
156 | tcg_temp_free_ptr(tcg_rn_ptr); | ||
157 | } | ||
158 | |||
159 | +/* Crypto three-reg SHA512 | ||
160 | + * 31 21 20 16 15 14 13 12 11 10 9 5 4 0 | ||
161 | + * +-----------------------+------+---+---+-----+--------+------+------+ | ||
162 | + * | 1 1 0 0 1 1 1 0 0 1 1 | Rm | 1 | O | 0 0 | opcode | Rn | Rd | | ||
163 | + * +-----------------------+------+---+---+-----+--------+------+------+ | ||
164 | + */ | ||
165 | +static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | ||
166 | +{ | ||
167 | + int opcode = extract32(insn, 10, 2); | ||
168 | + int o = extract32(insn, 14, 1); | ||
169 | + int rm = extract32(insn, 16, 5); | ||
170 | + int rn = extract32(insn, 5, 5); | ||
171 | + int rd = extract32(insn, 0, 5); | ||
172 | + int feature; | ||
173 | + CryptoThreeOpFn *genfn; | ||
174 | + | ||
175 | + if (o == 0) { | ||
176 | + switch (opcode) { | ||
177 | + case 0: /* SHA512H */ | ||
178 | + feature = ARM_FEATURE_V8_SHA512; | ||
179 | + genfn = gen_helper_crypto_sha512h; | ||
180 | + break; | ||
181 | + case 1: /* SHA512H2 */ | ||
182 | + feature = ARM_FEATURE_V8_SHA512; | ||
183 | + genfn = gen_helper_crypto_sha512h2; | ||
184 | + break; | ||
185 | + case 2: /* SHA512SU1 */ | ||
186 | + feature = ARM_FEATURE_V8_SHA512; | ||
187 | + genfn = gen_helper_crypto_sha512su1; | ||
188 | + break; | ||
189 | + default: | ||
190 | + unallocated_encoding(s); | ||
191 | + return; | 81 | + return; |
192 | + } | 82 | + } |
193 | + } else { | ||
194 | + unallocated_encoding(s); | ||
195 | + return; | ||
196 | + } | 83 | + } |
197 | + | 84 | + |
198 | + if (!arm_dc_feature(s, feature)) { | 85 | /* |
199 | + unallocated_encoding(s); | 86 | * Tell the CPU where the NVIC is; it will fail realize if it doesn't |
200 | + return; | 87 | * have one. Similarly, tell the NVIC where its CPU is. |
201 | + } | 88 | @@ -XXX,XX +XXX,XX @@ static Property armv7m_properties[] = { |
202 | + | 89 | false), |
203 | + if (!fp_access_check(s)) { | 90 | DEFINE_PROP_BOOL("vfp", ARMv7MState, vfp, true), |
204 | + return; | 91 | DEFINE_PROP_BOOL("dsp", ARMv7MState, dsp, true), |
205 | + } | 92 | + DEFINE_PROP_UINT32("mpu-ns-regions", ARMv7MState, mpu_ns_regions, UINT_MAX), |
206 | + | 93 | + DEFINE_PROP_UINT32("mpu-s-regions", ARMv7MState, mpu_s_regions, UINT_MAX), |
207 | + if (genfn) { | 94 | DEFINE_PROP_END_OF_LIST(), |
208 | + TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr; | ||
209 | + | ||
210 | + tcg_rd_ptr = vec_full_reg_ptr(s, rd); | ||
211 | + tcg_rn_ptr = vec_full_reg_ptr(s, rn); | ||
212 | + tcg_rm_ptr = vec_full_reg_ptr(s, rm); | ||
213 | + | ||
214 | + genfn(tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr); | ||
215 | + | ||
216 | + tcg_temp_free_ptr(tcg_rd_ptr); | ||
217 | + tcg_temp_free_ptr(tcg_rn_ptr); | ||
218 | + tcg_temp_free_ptr(tcg_rm_ptr); | ||
219 | + } else { | ||
220 | + g_assert_not_reached(); | ||
221 | + } | ||
222 | +} | ||
223 | + | ||
224 | +/* Crypto two-reg SHA512 | ||
225 | + * 31 12 11 10 9 5 4 0 | ||
226 | + * +-----------------------------------------+--------+------+------+ | ||
227 | + * | 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 0 1 0 0 0 | opcode | Rn | Rd | | ||
228 | + * +-----------------------------------------+--------+------+------+ | ||
229 | + */ | ||
230 | +static void disas_crypto_two_reg_sha512(DisasContext *s, uint32_t insn) | ||
231 | +{ | ||
232 | + int opcode = extract32(insn, 10, 2); | ||
233 | + int rn = extract32(insn, 5, 5); | ||
234 | + int rd = extract32(insn, 0, 5); | ||
235 | + TCGv_ptr tcg_rd_ptr, tcg_rn_ptr; | ||
236 | + int feature; | ||
237 | + CryptoTwoOpFn *genfn; | ||
238 | + | ||
239 | + switch (opcode) { | ||
240 | + case 0: /* SHA512SU0 */ | ||
241 | + feature = ARM_FEATURE_V8_SHA512; | ||
242 | + genfn = gen_helper_crypto_sha512su0; | ||
243 | + break; | ||
244 | + default: | ||
245 | + unallocated_encoding(s); | ||
246 | + return; | ||
247 | + } | ||
248 | + | ||
249 | + if (!arm_dc_feature(s, feature)) { | ||
250 | + unallocated_encoding(s); | ||
251 | + return; | ||
252 | + } | ||
253 | + | ||
254 | + if (!fp_access_check(s)) { | ||
255 | + return; | ||
256 | + } | ||
257 | + | ||
258 | + tcg_rd_ptr = vec_full_reg_ptr(s, rd); | ||
259 | + tcg_rn_ptr = vec_full_reg_ptr(s, rn); | ||
260 | + | ||
261 | + genfn(tcg_rd_ptr, tcg_rn_ptr); | ||
262 | + | ||
263 | + tcg_temp_free_ptr(tcg_rd_ptr); | ||
264 | + tcg_temp_free_ptr(tcg_rn_ptr); | ||
265 | +} | ||
266 | + | ||
267 | /* C3.6 Data processing - SIMD, inc Crypto | ||
268 | * | ||
269 | * As the decode gets a little complex we are using a table based | ||
270 | @@ -XXX,XX +XXX,XX @@ static const AArch64DecodeTable data_proc_simd[] = { | ||
271 | { 0x4e280800, 0xff3e0c00, disas_crypto_aes }, | ||
272 | { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha }, | ||
273 | { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha }, | ||
274 | + { 0xce608000, 0xffe0b000, disas_crypto_three_reg_sha512 }, | ||
275 | + { 0xcec08000, 0xfffff000, disas_crypto_two_reg_sha512 }, | ||
276 | { 0x00000000, 0x00000000, NULL } | ||
277 | }; | 95 | }; |
278 | 96 | ||
279 | -- | 97 | -- |
280 | 2.16.1 | 98 | 2.34.1 |
281 | 99 | ||
282 | 100 | diff view generated by jsdifflib |
1 | The memory writes done to push registers on the stack | 1 | The IoTKit, SSE200 and SSE300 all default to 8 MPU regions. The |
---|---|---|---|
2 | on exception entry in M profile CPUs are supposed to | 2 | MPS2/MPS3 FPGA images don't override these except in the case of |
3 | go via MPU permissions checks, which may cause us to | 3 | AN547, which uses 16 MPU regions. |
4 | take a derived exception instead of the original one of | 4 | |
5 | the MPU lookup fails. We were implementing these as | 5 | Define properties on the ARMSSE object for the MPU regions (using the |
6 | always-succeeds direct writes to physical memory. | 6 | same names as the documented RTL configuration settings, and |
7 | Rewrite v7m_push_stack() to do the necessary checks. | 7 | following the pattern we already have for this device of using |
8 | 8 | all-caps names as the RTL does), and set them in the board code. | |
9 | |||
10 | We don't actually need to override the default except on AN547, | ||
11 | but it's simpler code to have the board code set them always | ||
12 | rather than tracking which board subtypes want to set them to | ||
13 | a non-default value separately from what that value is. | ||
14 | |||
15 | Tho overall effect is that for mps2-an505, mps2-an521 and mps3-an524 | ||
16 | we now correctly use 8 MPU regions, while mps3-an547 stays at its | ||
17 | current 16 regions. | ||
18 | |||
19 | It's possible some guest code wrongly depended on the previous | ||
20 | incorrectly modeled number of memory regions. (Such guest code | ||
21 | should ideally check the number of regions via the MPU_TYPE | ||
22 | register.) The old behaviour can be obtained with additional | ||
23 | -global arguments to QEMU: | ||
24 | |||
25 | For mps2-an521 and mps2-an524: | ||
26 | -global sse-200.CPU0_MPU_NS=16 -global sse-200.CPU0_MPU_S=16 -global sse-200.CPU1_MPU_NS=16 -global sse-200.CPU1_MPU_S=16 | ||
27 | |||
28 | For mps2-an505: | ||
29 | -global sse-200.CPU0_MPU_NS=16 -global sse-200.CPU0_MPU_S=16 | ||
30 | |||
31 | NB that the way the implementation allows this use of -global | ||
32 | is slightly fragile: if the board code explicitly sets the | ||
33 | properties on the sse-200 object, this overrides the -global | ||
34 | command line option. So we rely on: | ||
35 | - the boards that need fixing all happen to use the SSE defaults | ||
36 | - we can write the board code to only set the property if it | ||
37 | is different from the default, rather than having all boards | ||
38 | explicitly set the property | ||
39 | - the board that does need to use a non-default value happens | ||
40 | to need to set it to the same value (16) we previously used | ||
41 | This works, but there are some kinds of refactoring of the | ||
42 | mps2-tz.c code that would break the support for -global here. | ||
43 | |||
44 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1772 | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 45 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 46 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
11 | Message-id: 1517324542-6607-5-git-send-email-peter.maydell@linaro.org | 47 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
48 | Message-id: 20230724174335.2150499-4-peter.maydell@linaro.org | ||
12 | --- | 49 | --- |
13 | target/arm/helper.c | 103 ++++++++++++++++++++++++++++++++++++++++++++-------- | 50 | include/hw/arm/armsse.h | 5 +++++ |
14 | 1 file changed, 87 insertions(+), 16 deletions(-) | 51 | hw/arm/armsse.c | 16 ++++++++++++++++ |
15 | 52 | hw/arm/mps2-tz.c | 29 +++++++++++++++++++++++++++++ | |
16 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 53 | 3 files changed, 50 insertions(+) |
54 | |||
55 | diff --git a/include/hw/arm/armsse.h b/include/hw/arm/armsse.h | ||
17 | index XXXXXXX..XXXXXXX 100644 | 56 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/arm/helper.c | 57 | --- a/include/hw/arm/armsse.h |
19 | +++ b/target/arm/helper.c | 58 | +++ b/include/hw/arm/armsse.h |
20 | @@ -XXX,XX +XXX,XX @@ uint32_t arm_phys_excp_target_el(CPUState *cs, uint32_t excp_idx, | 59 | @@ -XXX,XX +XXX,XX @@ |
21 | return target_el; | 60 | * (matching the hardware) is that for CPU0 in an IoTKit and CPU1 in an |
61 | * SSE-200 both are present; CPU0 in an SSE-200 has neither. | ||
62 | * Since the IoTKit has only one CPU, it does not have the CPU1_* properties. | ||
63 | + * + QOM properties "CPU0_MPU_NS", "CPU0_MPU_S", "CPU1_MPU_NS" and "CPU1_MPU_S" | ||
64 | + * which set the number of MPU regions on the CPUs. If there is only one | ||
65 | + * CPU the CPU1 properties are not present. | ||
66 | * + Named GPIO inputs "EXP_IRQ" 0..n are the expansion interrupts for CPU 0, | ||
67 | * which are wired to its NVIC lines 32 .. n+32 | ||
68 | * + Named GPIO inputs "EXP_CPU1_IRQ" 0..n are the expansion interrupts for | ||
69 | @@ -XXX,XX +XXX,XX @@ struct ARMSSE { | ||
70 | uint32_t exp_numirq; | ||
71 | uint32_t sram_addr_width; | ||
72 | uint32_t init_svtor; | ||
73 | + uint32_t cpu_mpu_ns[SSE_MAX_CPUS]; | ||
74 | + uint32_t cpu_mpu_s[SSE_MAX_CPUS]; | ||
75 | bool cpu_fpu[SSE_MAX_CPUS]; | ||
76 | bool cpu_dsp[SSE_MAX_CPUS]; | ||
77 | }; | ||
78 | diff --git a/hw/arm/armsse.c b/hw/arm/armsse.c | ||
79 | index XXXXXXX..XXXXXXX 100644 | ||
80 | --- a/hw/arm/armsse.c | ||
81 | +++ b/hw/arm/armsse.c | ||
82 | @@ -XXX,XX +XXX,XX @@ static Property iotkit_properties[] = { | ||
83 | DEFINE_PROP_UINT32("init-svtor", ARMSSE, init_svtor, 0x10000000), | ||
84 | DEFINE_PROP_BOOL("CPU0_FPU", ARMSSE, cpu_fpu[0], true), | ||
85 | DEFINE_PROP_BOOL("CPU0_DSP", ARMSSE, cpu_dsp[0], true), | ||
86 | + DEFINE_PROP_UINT32("CPU0_MPU_NS", ARMSSE, cpu_mpu_ns[0], 8), | ||
87 | + DEFINE_PROP_UINT32("CPU0_MPU_S", ARMSSE, cpu_mpu_s[0], 8), | ||
88 | DEFINE_PROP_END_OF_LIST() | ||
89 | }; | ||
90 | |||
91 | @@ -XXX,XX +XXX,XX @@ static Property sse200_properties[] = { | ||
92 | DEFINE_PROP_BOOL("CPU0_DSP", ARMSSE, cpu_dsp[0], false), | ||
93 | DEFINE_PROP_BOOL("CPU1_FPU", ARMSSE, cpu_fpu[1], true), | ||
94 | DEFINE_PROP_BOOL("CPU1_DSP", ARMSSE, cpu_dsp[1], true), | ||
95 | + DEFINE_PROP_UINT32("CPU0_MPU_NS", ARMSSE, cpu_mpu_ns[0], 8), | ||
96 | + DEFINE_PROP_UINT32("CPU0_MPU_S", ARMSSE, cpu_mpu_s[0], 8), | ||
97 | + DEFINE_PROP_UINT32("CPU1_MPU_NS", ARMSSE, cpu_mpu_ns[1], 8), | ||
98 | + DEFINE_PROP_UINT32("CPU1_MPU_S", ARMSSE, cpu_mpu_s[1], 8), | ||
99 | DEFINE_PROP_END_OF_LIST() | ||
100 | }; | ||
101 | |||
102 | @@ -XXX,XX +XXX,XX @@ static Property sse300_properties[] = { | ||
103 | DEFINE_PROP_UINT32("init-svtor", ARMSSE, init_svtor, 0x10000000), | ||
104 | DEFINE_PROP_BOOL("CPU0_FPU", ARMSSE, cpu_fpu[0], true), | ||
105 | DEFINE_PROP_BOOL("CPU0_DSP", ARMSSE, cpu_dsp[0], true), | ||
106 | + DEFINE_PROP_UINT32("CPU0_MPU_NS", ARMSSE, cpu_mpu_ns[0], 8), | ||
107 | + DEFINE_PROP_UINT32("CPU0_MPU_S", ARMSSE, cpu_mpu_s[0], 8), | ||
108 | DEFINE_PROP_END_OF_LIST() | ||
109 | }; | ||
110 | |||
111 | @@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp) | ||
112 | return; | ||
113 | } | ||
114 | } | ||
115 | + if (!object_property_set_uint(cpuobj, "mpu-ns-regions", | ||
116 | + s->cpu_mpu_ns[i], errp)) { | ||
117 | + return; | ||
118 | + } | ||
119 | + if (!object_property_set_uint(cpuobj, "mpu-s-regions", | ||
120 | + s->cpu_mpu_s[i], errp)) { | ||
121 | + return; | ||
122 | + } | ||
123 | |||
124 | if (i > 0) { | ||
125 | memory_region_add_subregion_overlap(&s->cpu_container[i], 0, | ||
126 | diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c | ||
127 | index XXXXXXX..XXXXXXX 100644 | ||
128 | --- a/hw/arm/mps2-tz.c | ||
129 | +++ b/hw/arm/mps2-tz.c | ||
130 | @@ -XXX,XX +XXX,XX @@ struct MPS2TZMachineClass { | ||
131 | int uart_overflow_irq; /* number of the combined UART overflow IRQ */ | ||
132 | uint32_t init_svtor; /* init-svtor setting for SSE */ | ||
133 | uint32_t sram_addr_width; /* SRAM_ADDR_WIDTH setting for SSE */ | ||
134 | + uint32_t cpu0_mpu_ns; /* CPU0_MPU_NS setting for SSE */ | ||
135 | + uint32_t cpu0_mpu_s; /* CPU0_MPU_S setting for SSE */ | ||
136 | + uint32_t cpu1_mpu_ns; /* CPU1_MPU_NS setting for SSE */ | ||
137 | + uint32_t cpu1_mpu_s; /* CPU1_MPU_S setting for SSE */ | ||
138 | const RAMInfo *raminfo; | ||
139 | const char *armsse_type; | ||
140 | uint32_t boot_ram_size; /* size of ram at address 0; 0 == find in raminfo */ | ||
141 | @@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_TYPE(MPS2TZMachineState, MPS2TZMachineClass, MPS2TZ_MACHINE) | ||
142 | #define MPS3_DDR_SIZE (2 * GiB) | ||
143 | #endif | ||
144 | |||
145 | +/* For cpu{0,1}_mpu_{ns,s}, means "leave at SSE's default value" */ | ||
146 | +#define MPU_REGION_DEFAULT UINT32_MAX | ||
147 | + | ||
148 | static const uint32_t an505_oscclk[] = { | ||
149 | 40000000, | ||
150 | 24580000, | ||
151 | @@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine) | ||
152 | OBJECT(system_memory), &error_abort); | ||
153 | qdev_prop_set_uint32(iotkitdev, "EXP_NUMIRQ", mmc->numirq); | ||
154 | qdev_prop_set_uint32(iotkitdev, "init-svtor", mmc->init_svtor); | ||
155 | + if (mmc->cpu0_mpu_ns != MPU_REGION_DEFAULT) { | ||
156 | + qdev_prop_set_uint32(iotkitdev, "CPU0_MPU_NS", mmc->cpu0_mpu_ns); | ||
157 | + } | ||
158 | + if (mmc->cpu0_mpu_s != MPU_REGION_DEFAULT) { | ||
159 | + qdev_prop_set_uint32(iotkitdev, "CPU0_MPU_S", mmc->cpu0_mpu_s); | ||
160 | + } | ||
161 | + if (object_property_find(OBJECT(iotkitdev), "CPU1_MPU_NS")) { | ||
162 | + if (mmc->cpu1_mpu_ns != MPU_REGION_DEFAULT) { | ||
163 | + qdev_prop_set_uint32(iotkitdev, "CPU1_MPU_NS", mmc->cpu1_mpu_ns); | ||
164 | + } | ||
165 | + if (mmc->cpu1_mpu_s != MPU_REGION_DEFAULT) { | ||
166 | + qdev_prop_set_uint32(iotkitdev, "CPU1_MPU_S", mmc->cpu1_mpu_s); | ||
167 | + } | ||
168 | + } | ||
169 | qdev_prop_set_uint32(iotkitdev, "SRAM_ADDR_WIDTH", mmc->sram_addr_width); | ||
170 | qdev_connect_clock_in(iotkitdev, "MAINCLK", mms->sysclk); | ||
171 | qdev_connect_clock_in(iotkitdev, "S32KCLK", mms->s32kclk); | ||
172 | @@ -XXX,XX +XXX,XX @@ static void mps2tz_class_init(ObjectClass *oc, void *data) | ||
173 | { | ||
174 | MachineClass *mc = MACHINE_CLASS(oc); | ||
175 | IDAUInterfaceClass *iic = IDAU_INTERFACE_CLASS(oc); | ||
176 | + MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_CLASS(oc); | ||
177 | |||
178 | mc->init = mps2tz_common_init; | ||
179 | mc->reset = mps2_machine_reset; | ||
180 | iic->check = mps2_tz_idau_check; | ||
181 | + | ||
182 | + /* Most machines leave these at the SSE defaults */ | ||
183 | + mmc->cpu0_mpu_ns = MPU_REGION_DEFAULT; | ||
184 | + mmc->cpu0_mpu_s = MPU_REGION_DEFAULT; | ||
185 | + mmc->cpu1_mpu_ns = MPU_REGION_DEFAULT; | ||
186 | + mmc->cpu1_mpu_s = MPU_REGION_DEFAULT; | ||
22 | } | 187 | } |
23 | 188 | ||
24 | -static void v7m_push(CPUARMState *env, uint32_t val) | 189 | static void mps2tz_set_default_ram_info(MPS2TZMachineClass *mmc) |
25 | +static bool v7m_stack_write(ARMCPU *cpu, uint32_t addr, uint32_t value, | 190 | @@ -XXX,XX +XXX,XX @@ static void mps3tz_an547_class_init(ObjectClass *oc, void *data) |
26 | + ARMMMUIdx mmu_idx, bool ignfault) | 191 | mmc->numirq = 96; |
27 | { | 192 | mmc->uart_overflow_irq = 48; |
28 | - CPUState *cs = CPU(arm_env_get_cpu(env)); | 193 | mmc->init_svtor = 0x00000000; |
29 | + CPUState *cs = CPU(cpu); | 194 | + mmc->cpu0_mpu_s = mmc->cpu0_mpu_ns = 16; |
30 | + CPUARMState *env = &cpu->env; | 195 | mmc->sram_addr_width = 21; |
31 | + MemTxAttrs attrs = {}; | 196 | mmc->raminfo = an547_raminfo; |
32 | + MemTxResult txres; | 197 | mmc->armsse_type = TYPE_SSE300; |
33 | + target_ulong page_size; | ||
34 | + hwaddr physaddr; | ||
35 | + int prot; | ||
36 | + ARMMMUFaultInfo fi; | ||
37 | + bool secure = mmu_idx & ARM_MMU_IDX_M_S; | ||
38 | + int exc; | ||
39 | + bool exc_secure; | ||
40 | |||
41 | - env->regs[13] -= 4; | ||
42 | - stl_phys(cs->as, env->regs[13], val); | ||
43 | + if (get_phys_addr(env, addr, MMU_DATA_STORE, mmu_idx, &physaddr, | ||
44 | + &attrs, &prot, &page_size, &fi, NULL)) { | ||
45 | + /* MPU/SAU lookup failed */ | ||
46 | + if (fi.type == ARMFault_QEMU_SFault) { | ||
47 | + qemu_log_mask(CPU_LOG_INT, | ||
48 | + "...SecureFault with SFSR.AUVIOL during stacking\n"); | ||
49 | + env->v7m.sfsr |= R_V7M_SFSR_AUVIOL_MASK | R_V7M_SFSR_SFARVALID_MASK; | ||
50 | + env->v7m.sfar = addr; | ||
51 | + exc = ARMV7M_EXCP_SECURE; | ||
52 | + exc_secure = false; | ||
53 | + } else { | ||
54 | + qemu_log_mask(CPU_LOG_INT, "...MemManageFault with CFSR.MSTKERR\n"); | ||
55 | + env->v7m.cfsr[secure] |= R_V7M_CFSR_MSTKERR_MASK; | ||
56 | + exc = ARMV7M_EXCP_MEM; | ||
57 | + exc_secure = secure; | ||
58 | + } | ||
59 | + goto pend_fault; | ||
60 | + } | ||
61 | + address_space_stl_le(arm_addressspace(cs, attrs), physaddr, value, | ||
62 | + attrs, &txres); | ||
63 | + if (txres != MEMTX_OK) { | ||
64 | + /* BusFault trying to write the data */ | ||
65 | + qemu_log_mask(CPU_LOG_INT, "...BusFault with BFSR.STKERR\n"); | ||
66 | + env->v7m.cfsr[M_REG_NS] |= R_V7M_CFSR_STKERR_MASK; | ||
67 | + exc = ARMV7M_EXCP_BUS; | ||
68 | + exc_secure = false; | ||
69 | + goto pend_fault; | ||
70 | + } | ||
71 | + return true; | ||
72 | + | ||
73 | +pend_fault: | ||
74 | + /* By pending the exception at this point we are making | ||
75 | + * the IMPDEF choice "overridden exceptions pended" (see the | ||
76 | + * MergeExcInfo() pseudocode). The other choice would be to not | ||
77 | + * pend them now and then make a choice about which to throw away | ||
78 | + * later if we have two derived exceptions. | ||
79 | + * The only case when we must not pend the exception but instead | ||
80 | + * throw it away is if we are doing the push of the callee registers | ||
81 | + * and we've already generated a derived exception. Even in this | ||
82 | + * case we will still update the fault status registers. | ||
83 | + */ | ||
84 | + if (!ignfault) { | ||
85 | + armv7m_nvic_set_pending_derived(env->nvic, exc, exc_secure); | ||
86 | + } | ||
87 | + return false; | ||
88 | } | ||
89 | |||
90 | /* Return true if we're using the process stack pointer (not the MSP) */ | ||
91 | @@ -XXX,XX +XXX,XX @@ static bool v7m_push_stack(ARMCPU *cpu) | ||
92 | * should ignore further stack faults trying to process | ||
93 | * that derived exception.) | ||
94 | */ | ||
95 | + bool stacked_ok; | ||
96 | CPUARMState *env = &cpu->env; | ||
97 | uint32_t xpsr = xpsr_read(env); | ||
98 | + uint32_t frameptr = env->regs[13]; | ||
99 | + ARMMMUIdx mmu_idx = core_to_arm_mmu_idx(env, cpu_mmu_index(env, false)); | ||
100 | |||
101 | /* Align stack pointer if the guest wants that */ | ||
102 | - if ((env->regs[13] & 4) && | ||
103 | + if ((frameptr & 4) && | ||
104 | (env->v7m.ccr[env->v7m.secure] & R_V7M_CCR_STKALIGN_MASK)) { | ||
105 | - env->regs[13] -= 4; | ||
106 | + frameptr -= 4; | ||
107 | xpsr |= XPSR_SPREALIGN; | ||
108 | } | ||
109 | - /* Switch to the handler mode. */ | ||
110 | - v7m_push(env, xpsr); | ||
111 | - v7m_push(env, env->regs[15]); | ||
112 | - v7m_push(env, env->regs[14]); | ||
113 | - v7m_push(env, env->regs[12]); | ||
114 | - v7m_push(env, env->regs[3]); | ||
115 | - v7m_push(env, env->regs[2]); | ||
116 | - v7m_push(env, env->regs[1]); | ||
117 | - v7m_push(env, env->regs[0]); | ||
118 | |||
119 | - return false; | ||
120 | + frameptr -= 0x20; | ||
121 | + | ||
122 | + /* Write as much of the stack frame as we can. If we fail a stack | ||
123 | + * write this will result in a derived exception being pended | ||
124 | + * (which may be taken in preference to the one we started with | ||
125 | + * if it has higher priority). | ||
126 | + */ | ||
127 | + stacked_ok = | ||
128 | + v7m_stack_write(cpu, frameptr, env->regs[0], mmu_idx, false) && | ||
129 | + v7m_stack_write(cpu, frameptr + 4, env->regs[1], mmu_idx, false) && | ||
130 | + v7m_stack_write(cpu, frameptr + 8, env->regs[2], mmu_idx, false) && | ||
131 | + v7m_stack_write(cpu, frameptr + 12, env->regs[3], mmu_idx, false) && | ||
132 | + v7m_stack_write(cpu, frameptr + 16, env->regs[12], mmu_idx, false) && | ||
133 | + v7m_stack_write(cpu, frameptr + 20, env->regs[14], mmu_idx, false) && | ||
134 | + v7m_stack_write(cpu, frameptr + 24, env->regs[15], mmu_idx, false) && | ||
135 | + v7m_stack_write(cpu, frameptr + 28, xpsr, mmu_idx, false); | ||
136 | + | ||
137 | + /* Update SP regardless of whether any of the stack accesses failed. | ||
138 | + * When we implement v8M stack limit checking then this attempt to | ||
139 | + * update SP might also fail and result in a derived exception. | ||
140 | + */ | ||
141 | + env->regs[13] = frameptr; | ||
142 | + | ||
143 | + return !stacked_ok; | ||
144 | } | ||
145 | |||
146 | static void do_v7m_exception_exit(ARMCPU *cpu) | ||
147 | -- | 198 | -- |
148 | 2.16.1 | 199 | 2.34.1 |
149 | 200 | ||
150 | 201 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Ard Biesheuvel <ard.biesheuvel@linaro.org> | ||
2 | 1 | ||
3 | This implements emulation of the new SM4 instructions that have | ||
4 | been added as an optional extension to the ARMv8 Crypto Extensions | ||
5 | in ARM v8.2. | ||
6 | |||
7 | Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> | ||
8 | Message-id: 20180207111729.15737-5-ard.biesheuvel@linaro.org | ||
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | --- | ||
12 | target/arm/cpu.h | 1 + | ||
13 | target/arm/helper.h | 3 ++ | ||
14 | target/arm/crypto_helper.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++ | ||
15 | target/arm/translate-a64.c | 8 ++++ | ||
16 | 4 files changed, 103 insertions(+) | ||
17 | |||
18 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/target/arm/cpu.h | ||
21 | +++ b/target/arm/cpu.h | ||
22 | @@ -XXX,XX +XXX,XX @@ enum arm_features { | ||
23 | ARM_FEATURE_V8_SHA512, /* implements SHA512 part of v8 Crypto Extensions */ | ||
24 | ARM_FEATURE_V8_SHA3, /* implements SHA3 part of v8 Crypto Extensions */ | ||
25 | ARM_FEATURE_V8_SM3, /* implements SM3 part of v8 Crypto Extensions */ | ||
26 | + ARM_FEATURE_V8_SM4, /* implements SM4 part of v8 Crypto Extensions */ | ||
27 | }; | ||
28 | |||
29 | static inline int arm_feature(CPUARMState *env, int feature) | ||
30 | diff --git a/target/arm/helper.h b/target/arm/helper.h | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/target/arm/helper.h | ||
33 | +++ b/target/arm/helper.h | ||
34 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_5(crypto_sm3tt, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32, i32) | ||
35 | DEF_HELPER_FLAGS_3(crypto_sm3partw1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | ||
36 | DEF_HELPER_FLAGS_3(crypto_sm3partw2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | ||
37 | |||
38 | +DEF_HELPER_FLAGS_2(crypto_sm4e, TCG_CALL_NO_RWG, void, ptr, ptr) | ||
39 | +DEF_HELPER_FLAGS_3(crypto_sm4ekey, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | ||
40 | + | ||
41 | DEF_HELPER_FLAGS_3(crc32, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) | ||
42 | DEF_HELPER_FLAGS_3(crc32c, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) | ||
43 | DEF_HELPER_2(dc_zva, void, env, i64) | ||
44 | diff --git a/target/arm/crypto_helper.c b/target/arm/crypto_helper.c | ||
45 | index XXXXXXX..XXXXXXX 100644 | ||
46 | --- a/target/arm/crypto_helper.c | ||
47 | +++ b/target/arm/crypto_helper.c | ||
48 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sm3tt)(void *vd, void *vn, void *vm, uint32_t imm2, | ||
49 | rd[0] = d.l[0]; | ||
50 | rd[1] = d.l[1]; | ||
51 | } | ||
52 | + | ||
53 | +static uint8_t const sm4_sbox[] = { | ||
54 | + 0xd6, 0x90, 0xe9, 0xfe, 0xcc, 0xe1, 0x3d, 0xb7, | ||
55 | + 0x16, 0xb6, 0x14, 0xc2, 0x28, 0xfb, 0x2c, 0x05, | ||
56 | + 0x2b, 0x67, 0x9a, 0x76, 0x2a, 0xbe, 0x04, 0xc3, | ||
57 | + 0xaa, 0x44, 0x13, 0x26, 0x49, 0x86, 0x06, 0x99, | ||
58 | + 0x9c, 0x42, 0x50, 0xf4, 0x91, 0xef, 0x98, 0x7a, | ||
59 | + 0x33, 0x54, 0x0b, 0x43, 0xed, 0xcf, 0xac, 0x62, | ||
60 | + 0xe4, 0xb3, 0x1c, 0xa9, 0xc9, 0x08, 0xe8, 0x95, | ||
61 | + 0x80, 0xdf, 0x94, 0xfa, 0x75, 0x8f, 0x3f, 0xa6, | ||
62 | + 0x47, 0x07, 0xa7, 0xfc, 0xf3, 0x73, 0x17, 0xba, | ||
63 | + 0x83, 0x59, 0x3c, 0x19, 0xe6, 0x85, 0x4f, 0xa8, | ||
64 | + 0x68, 0x6b, 0x81, 0xb2, 0x71, 0x64, 0xda, 0x8b, | ||
65 | + 0xf8, 0xeb, 0x0f, 0x4b, 0x70, 0x56, 0x9d, 0x35, | ||
66 | + 0x1e, 0x24, 0x0e, 0x5e, 0x63, 0x58, 0xd1, 0xa2, | ||
67 | + 0x25, 0x22, 0x7c, 0x3b, 0x01, 0x21, 0x78, 0x87, | ||
68 | + 0xd4, 0x00, 0x46, 0x57, 0x9f, 0xd3, 0x27, 0x52, | ||
69 | + 0x4c, 0x36, 0x02, 0xe7, 0xa0, 0xc4, 0xc8, 0x9e, | ||
70 | + 0xea, 0xbf, 0x8a, 0xd2, 0x40, 0xc7, 0x38, 0xb5, | ||
71 | + 0xa3, 0xf7, 0xf2, 0xce, 0xf9, 0x61, 0x15, 0xa1, | ||
72 | + 0xe0, 0xae, 0x5d, 0xa4, 0x9b, 0x34, 0x1a, 0x55, | ||
73 | + 0xad, 0x93, 0x32, 0x30, 0xf5, 0x8c, 0xb1, 0xe3, | ||
74 | + 0x1d, 0xf6, 0xe2, 0x2e, 0x82, 0x66, 0xca, 0x60, | ||
75 | + 0xc0, 0x29, 0x23, 0xab, 0x0d, 0x53, 0x4e, 0x6f, | ||
76 | + 0xd5, 0xdb, 0x37, 0x45, 0xde, 0xfd, 0x8e, 0x2f, | ||
77 | + 0x03, 0xff, 0x6a, 0x72, 0x6d, 0x6c, 0x5b, 0x51, | ||
78 | + 0x8d, 0x1b, 0xaf, 0x92, 0xbb, 0xdd, 0xbc, 0x7f, | ||
79 | + 0x11, 0xd9, 0x5c, 0x41, 0x1f, 0x10, 0x5a, 0xd8, | ||
80 | + 0x0a, 0xc1, 0x31, 0x88, 0xa5, 0xcd, 0x7b, 0xbd, | ||
81 | + 0x2d, 0x74, 0xd0, 0x12, 0xb8, 0xe5, 0xb4, 0xb0, | ||
82 | + 0x89, 0x69, 0x97, 0x4a, 0x0c, 0x96, 0x77, 0x7e, | ||
83 | + 0x65, 0xb9, 0xf1, 0x09, 0xc5, 0x6e, 0xc6, 0x84, | ||
84 | + 0x18, 0xf0, 0x7d, 0xec, 0x3a, 0xdc, 0x4d, 0x20, | ||
85 | + 0x79, 0xee, 0x5f, 0x3e, 0xd7, 0xcb, 0x39, 0x48, | ||
86 | +}; | ||
87 | + | ||
88 | +void HELPER(crypto_sm4e)(void *vd, void *vn) | ||
89 | +{ | ||
90 | + uint64_t *rd = vd; | ||
91 | + uint64_t *rn = vn; | ||
92 | + union CRYPTO_STATE d = { .l = { rd[0], rd[1] } }; | ||
93 | + union CRYPTO_STATE n = { .l = { rn[0], rn[1] } }; | ||
94 | + uint32_t t, i; | ||
95 | + | ||
96 | + for (i = 0; i < 4; i++) { | ||
97 | + t = CR_ST_WORD(d, (i + 1) % 4) ^ | ||
98 | + CR_ST_WORD(d, (i + 2) % 4) ^ | ||
99 | + CR_ST_WORD(d, (i + 3) % 4) ^ | ||
100 | + CR_ST_WORD(n, i); | ||
101 | + | ||
102 | + t = sm4_sbox[t & 0xff] | | ||
103 | + sm4_sbox[(t >> 8) & 0xff] << 8 | | ||
104 | + sm4_sbox[(t >> 16) & 0xff] << 16 | | ||
105 | + sm4_sbox[(t >> 24) & 0xff] << 24; | ||
106 | + | ||
107 | + CR_ST_WORD(d, i) ^= t ^ rol32(t, 2) ^ rol32(t, 10) ^ rol32(t, 18) ^ | ||
108 | + rol32(t, 24); | ||
109 | + } | ||
110 | + | ||
111 | + rd[0] = d.l[0]; | ||
112 | + rd[1] = d.l[1]; | ||
113 | +} | ||
114 | + | ||
115 | +void HELPER(crypto_sm4ekey)(void *vd, void *vn, void* vm) | ||
116 | +{ | ||
117 | + uint64_t *rd = vd; | ||
118 | + uint64_t *rn = vn; | ||
119 | + uint64_t *rm = vm; | ||
120 | + union CRYPTO_STATE d; | ||
121 | + union CRYPTO_STATE n = { .l = { rn[0], rn[1] } }; | ||
122 | + union CRYPTO_STATE m = { .l = { rm[0], rm[1] } }; | ||
123 | + uint32_t t, i; | ||
124 | + | ||
125 | + d = n; | ||
126 | + for (i = 0; i < 4; i++) { | ||
127 | + t = CR_ST_WORD(d, (i + 1) % 4) ^ | ||
128 | + CR_ST_WORD(d, (i + 2) % 4) ^ | ||
129 | + CR_ST_WORD(d, (i + 3) % 4) ^ | ||
130 | + CR_ST_WORD(m, i); | ||
131 | + | ||
132 | + t = sm4_sbox[t & 0xff] | | ||
133 | + sm4_sbox[(t >> 8) & 0xff] << 8 | | ||
134 | + sm4_sbox[(t >> 16) & 0xff] << 16 | | ||
135 | + sm4_sbox[(t >> 24) & 0xff] << 24; | ||
136 | + | ||
137 | + CR_ST_WORD(d, i) ^= t ^ rol32(t, 13) ^ rol32(t, 23); | ||
138 | + } | ||
139 | + | ||
140 | + rd[0] = d.l[0]; | ||
141 | + rd[1] = d.l[1]; | ||
142 | +} | ||
143 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
144 | index XXXXXXX..XXXXXXX 100644 | ||
145 | --- a/target/arm/translate-a64.c | ||
146 | +++ b/target/arm/translate-a64.c | ||
147 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | ||
148 | feature = ARM_FEATURE_V8_SM3; | ||
149 | genfn = gen_helper_crypto_sm3partw2; | ||
150 | break; | ||
151 | + case 2: /* SM4EKEY */ | ||
152 | + feature = ARM_FEATURE_V8_SM4; | ||
153 | + genfn = gen_helper_crypto_sm4ekey; | ||
154 | + break; | ||
155 | default: | ||
156 | unallocated_encoding(s); | ||
157 | return; | ||
158 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_two_reg_sha512(DisasContext *s, uint32_t insn) | ||
159 | feature = ARM_FEATURE_V8_SHA512; | ||
160 | genfn = gen_helper_crypto_sha512su0; | ||
161 | break; | ||
162 | + case 1: /* SM4E */ | ||
163 | + feature = ARM_FEATURE_V8_SM4; | ||
164 | + genfn = gen_helper_crypto_sm4e; | ||
165 | + break; | ||
166 | default: | ||
167 | unallocated_encoding(s); | ||
168 | return; | ||
169 | -- | ||
170 | 2.16.1 | ||
171 | |||
172 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
2 | 1 | ||
3 | Convert i.MX6 to use TYPE_IMX_USDHC since that's what real HW comes | ||
4 | with. | ||
5 | |||
6 | Cc: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Cc: Jason Wang <jasowang@redhat.com> | ||
8 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | ||
10 | Cc: Michael S. Tsirkin <mst@redhat.com> | ||
11 | Cc: qemu-devel@nongnu.org | ||
12 | Cc: qemu-arm@nongnu.org | ||
13 | Cc: yurovsky@gmail.com | ||
14 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
15 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
17 | --- | ||
18 | hw/arm/fsl-imx6.c | 2 +- | ||
19 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
20 | |||
21 | diff --git a/hw/arm/fsl-imx6.c b/hw/arm/fsl-imx6.c | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/hw/arm/fsl-imx6.c | ||
24 | +++ b/hw/arm/fsl-imx6.c | ||
25 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6_init(Object *obj) | ||
26 | } | ||
27 | |||
28 | for (i = 0; i < FSL_IMX6_NUM_ESDHCS; i++) { | ||
29 | - object_initialize(&s->esdhc[i], sizeof(s->esdhc[i]), TYPE_SYSBUS_SDHCI); | ||
30 | + object_initialize(&s->esdhc[i], sizeof(s->esdhc[i]), TYPE_IMX_USDHC); | ||
31 | qdev_set_parent_bus(DEVICE(&s->esdhc[i]), sysbus_get_default()); | ||
32 | snprintf(name, NAME_SIZE, "sdhc%d", i + 1); | ||
33 | object_property_add_child(obj, name, OBJECT(&s->esdhc[i]), NULL); | ||
34 | -- | ||
35 | 2.16.1 | ||
36 | |||
37 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
2 | 1 | ||
3 | Add enough code to emulate i.MX2 watchdog IP block so it would be | ||
4 | possible to reboot the machine running Linux Guest. | ||
5 | |||
6 | Cc: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Cc: Jason Wang <jasowang@redhat.com> | ||
8 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | ||
10 | Cc: Michael S. Tsirkin <mst@redhat.com> | ||
11 | Cc: qemu-devel@nongnu.org | ||
12 | Cc: qemu-arm@nongnu.org | ||
13 | Cc: yurovsky@gmail.com | ||
14 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
15 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
16 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
18 | --- | ||
19 | hw/misc/Makefile.objs | 1 + | ||
20 | include/hw/misc/imx2_wdt.h | 33 +++++++++++++++++ | ||
21 | hw/misc/imx2_wdt.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++ | ||
22 | 3 files changed, 123 insertions(+) | ||
23 | create mode 100644 include/hw/misc/imx2_wdt.h | ||
24 | create mode 100644 hw/misc/imx2_wdt.c | ||
25 | |||
26 | diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/hw/misc/Makefile.objs | ||
29 | +++ b/hw/misc/Makefile.objs | ||
30 | @@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_IMX) += imx25_ccm.o | ||
31 | obj-$(CONFIG_IMX) += imx6_ccm.o | ||
32 | obj-$(CONFIG_IMX) += imx6_src.o | ||
33 | obj-$(CONFIG_IMX) += imx7_ccm.o | ||
34 | +obj-$(CONFIG_IMX) += imx2_wdt.o | ||
35 | obj-$(CONFIG_MILKYMIST) += milkymist-hpdmc.o | ||
36 | obj-$(CONFIG_MILKYMIST) += milkymist-pfpu.o | ||
37 | obj-$(CONFIG_MAINSTONE) += mst_fpga.o | ||
38 | diff --git a/include/hw/misc/imx2_wdt.h b/include/hw/misc/imx2_wdt.h | ||
39 | new file mode 100644 | ||
40 | index XXXXXXX..XXXXXXX | ||
41 | --- /dev/null | ||
42 | +++ b/include/hw/misc/imx2_wdt.h | ||
43 | @@ -XXX,XX +XXX,XX @@ | ||
44 | +/* | ||
45 | + * Copyright (c) 2017, Impinj, Inc. | ||
46 | + * | ||
47 | + * i.MX2 Watchdog IP block | ||
48 | + * | ||
49 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
50 | + * | ||
51 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
52 | + * See the COPYING file in the top-level directory. | ||
53 | + */ | ||
54 | + | ||
55 | +#ifndef IMX2_WDT_H | ||
56 | +#define IMX2_WDT_H | ||
57 | + | ||
58 | +#include "hw/sysbus.h" | ||
59 | + | ||
60 | +#define TYPE_IMX2_WDT "imx2.wdt" | ||
61 | +#define IMX2_WDT(obj) OBJECT_CHECK(IMX2WdtState, (obj), TYPE_IMX2_WDT) | ||
62 | + | ||
63 | +enum IMX2WdtRegisters { | ||
64 | + IMX2_WDT_WCR = 0x0000, | ||
65 | + IMX2_WDT_REG_NUM = 0x0008 / sizeof(uint16_t) + 1, | ||
66 | +}; | ||
67 | + | ||
68 | + | ||
69 | +typedef struct IMX2WdtState { | ||
70 | + /* <private> */ | ||
71 | + SysBusDevice parent_obj; | ||
72 | + | ||
73 | + MemoryRegion mmio; | ||
74 | +} IMX2WdtState; | ||
75 | + | ||
76 | +#endif /* IMX7_SNVS_H */ | ||
77 | diff --git a/hw/misc/imx2_wdt.c b/hw/misc/imx2_wdt.c | ||
78 | new file mode 100644 | ||
79 | index XXXXXXX..XXXXXXX | ||
80 | --- /dev/null | ||
81 | +++ b/hw/misc/imx2_wdt.c | ||
82 | @@ -XXX,XX +XXX,XX @@ | ||
83 | +/* | ||
84 | + * Copyright (c) 2018, Impinj, Inc. | ||
85 | + * | ||
86 | + * i.MX2 Watchdog IP block | ||
87 | + * | ||
88 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
89 | + * | ||
90 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
91 | + * See the COPYING file in the top-level directory. | ||
92 | + */ | ||
93 | + | ||
94 | +#include "qemu/osdep.h" | ||
95 | +#include "qemu/bitops.h" | ||
96 | +#include "sysemu/watchdog.h" | ||
97 | + | ||
98 | +#include "hw/misc/imx2_wdt.h" | ||
99 | + | ||
100 | +#define IMX2_WDT_WCR_WDA BIT(5) /* -> External Reset WDOG_B */ | ||
101 | +#define IMX2_WDT_WCR_SRS BIT(4) /* -> Software Reset Signal */ | ||
102 | + | ||
103 | +static uint64_t imx2_wdt_read(void *opaque, hwaddr addr, | ||
104 | + unsigned int size) | ||
105 | +{ | ||
106 | + return 0; | ||
107 | +} | ||
108 | + | ||
109 | +static void imx2_wdt_write(void *opaque, hwaddr addr, | ||
110 | + uint64_t value, unsigned int size) | ||
111 | +{ | ||
112 | + if (addr == IMX2_WDT_WCR && | ||
113 | + (value & (IMX2_WDT_WCR_WDA | IMX2_WDT_WCR_SRS))) { | ||
114 | + watchdog_perform_action(); | ||
115 | + } | ||
116 | +} | ||
117 | + | ||
118 | +static const MemoryRegionOps imx2_wdt_ops = { | ||
119 | + .read = imx2_wdt_read, | ||
120 | + .write = imx2_wdt_write, | ||
121 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
122 | + .impl = { | ||
123 | + /* | ||
124 | + * Our device would not work correctly if the guest was doing | ||
125 | + * unaligned access. This might not be a limitation on the | ||
126 | + * real device but in practice there is no reason for a guest | ||
127 | + * to access this device unaligned. | ||
128 | + */ | ||
129 | + .min_access_size = 4, | ||
130 | + .max_access_size = 4, | ||
131 | + .unaligned = false, | ||
132 | + }, | ||
133 | +}; | ||
134 | + | ||
135 | +static void imx2_wdt_realize(DeviceState *dev, Error **errp) | ||
136 | +{ | ||
137 | + IMX2WdtState *s = IMX2_WDT(dev); | ||
138 | + | ||
139 | + memory_region_init_io(&s->mmio, OBJECT(dev), | ||
140 | + &imx2_wdt_ops, s, | ||
141 | + TYPE_IMX2_WDT".mmio", | ||
142 | + IMX2_WDT_REG_NUM * sizeof(uint16_t)); | ||
143 | + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mmio); | ||
144 | +} | ||
145 | + | ||
146 | +static void imx2_wdt_class_init(ObjectClass *klass, void *data) | ||
147 | +{ | ||
148 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
149 | + | ||
150 | + dc->realize = imx2_wdt_realize; | ||
151 | + set_bit(DEVICE_CATEGORY_MISC, dc->categories); | ||
152 | +} | ||
153 | + | ||
154 | +static const TypeInfo imx2_wdt_info = { | ||
155 | + .name = TYPE_IMX2_WDT, | ||
156 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
157 | + .instance_size = sizeof(IMX2WdtState), | ||
158 | + .class_init = imx2_wdt_class_init, | ||
159 | +}; | ||
160 | + | ||
161 | +static WatchdogTimerModel model = { | ||
162 | + .wdt_name = "imx2-watchdog", | ||
163 | + .wdt_description = "i.MX2 Watchdog", | ||
164 | +}; | ||
165 | + | ||
166 | +static void imx2_wdt_register_type(void) | ||
167 | +{ | ||
168 | + watchdog_add_model(&model); | ||
169 | + type_register_static(&imx2_wdt_info); | ||
170 | +} | ||
171 | +type_init(imx2_wdt_register_type) | ||
172 | -- | ||
173 | 2.16.1 | ||
174 | |||
175 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
2 | 1 | ||
3 | Add code to emulate SNVS IP-block. Currently only the bits needed to | ||
4 | be able to emulate machine shutdown are implemented. | ||
5 | |||
6 | Cc: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Cc: Jason Wang <jasowang@redhat.com> | ||
8 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | ||
10 | Cc: Michael S. Tsirkin <mst@redhat.com> | ||
11 | Cc: qemu-devel@nongnu.org | ||
12 | Cc: qemu-arm@nongnu.org | ||
13 | Cc: yurovsky@gmail.com | ||
14 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
15 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
17 | --- | ||
18 | hw/misc/Makefile.objs | 1 + | ||
19 | include/hw/misc/imx7_snvs.h | 35 +++++++++++++++++++ | ||
20 | hw/misc/imx7_snvs.c | 83 +++++++++++++++++++++++++++++++++++++++++++++ | ||
21 | 3 files changed, 119 insertions(+) | ||
22 | create mode 100644 include/hw/misc/imx7_snvs.h | ||
23 | create mode 100644 hw/misc/imx7_snvs.c | ||
24 | |||
25 | diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/hw/misc/Makefile.objs | ||
28 | +++ b/hw/misc/Makefile.objs | ||
29 | @@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_IMX) += imx6_ccm.o | ||
30 | obj-$(CONFIG_IMX) += imx6_src.o | ||
31 | obj-$(CONFIG_IMX) += imx7_ccm.o | ||
32 | obj-$(CONFIG_IMX) += imx2_wdt.o | ||
33 | +obj-$(CONFIG_IMX) += imx7_snvs.o | ||
34 | obj-$(CONFIG_MILKYMIST) += milkymist-hpdmc.o | ||
35 | obj-$(CONFIG_MILKYMIST) += milkymist-pfpu.o | ||
36 | obj-$(CONFIG_MAINSTONE) += mst_fpga.o | ||
37 | diff --git a/include/hw/misc/imx7_snvs.h b/include/hw/misc/imx7_snvs.h | ||
38 | new file mode 100644 | ||
39 | index XXXXXXX..XXXXXXX | ||
40 | --- /dev/null | ||
41 | +++ b/include/hw/misc/imx7_snvs.h | ||
42 | @@ -XXX,XX +XXX,XX @@ | ||
43 | +/* | ||
44 | + * Copyright (c) 2017, Impinj, Inc. | ||
45 | + * | ||
46 | + * i.MX7 SNVS block emulation code | ||
47 | + * | ||
48 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
49 | + * | ||
50 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
51 | + * See the COPYING file in the top-level directory. | ||
52 | + */ | ||
53 | + | ||
54 | +#ifndef IMX7_SNVS_H | ||
55 | +#define IMX7_SNVS_H | ||
56 | + | ||
57 | +#include "qemu/bitops.h" | ||
58 | +#include "hw/sysbus.h" | ||
59 | + | ||
60 | + | ||
61 | +enum IMX7SNVSRegisters { | ||
62 | + SNVS_LPCR = 0x38, | ||
63 | + SNVS_LPCR_TOP = BIT(6), | ||
64 | + SNVS_LPCR_DP_EN = BIT(5) | ||
65 | +}; | ||
66 | + | ||
67 | +#define TYPE_IMX7_SNVS "imx7.snvs" | ||
68 | +#define IMX7_SNVS(obj) OBJECT_CHECK(IMX7SNVSState, (obj), TYPE_IMX7_SNVS) | ||
69 | + | ||
70 | +typedef struct IMX7SNVSState { | ||
71 | + /* <private> */ | ||
72 | + SysBusDevice parent_obj; | ||
73 | + | ||
74 | + MemoryRegion mmio; | ||
75 | +} IMX7SNVSState; | ||
76 | + | ||
77 | +#endif /* IMX7_SNVS_H */ | ||
78 | diff --git a/hw/misc/imx7_snvs.c b/hw/misc/imx7_snvs.c | ||
79 | new file mode 100644 | ||
80 | index XXXXXXX..XXXXXXX | ||
81 | --- /dev/null | ||
82 | +++ b/hw/misc/imx7_snvs.c | ||
83 | @@ -XXX,XX +XXX,XX @@ | ||
84 | +/* | ||
85 | + * IMX7 Secure Non-Volatile Storage | ||
86 | + * | ||
87 | + * Copyright (c) 2018, Impinj, Inc. | ||
88 | + * | ||
89 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
90 | + * | ||
91 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
92 | + * See the COPYING file in the top-level directory. | ||
93 | + * | ||
94 | + * Bare minimum emulation code needed to support being able to shut | ||
95 | + * down linux guest gracefully. | ||
96 | + */ | ||
97 | + | ||
98 | +#include "qemu/osdep.h" | ||
99 | +#include "hw/misc/imx7_snvs.h" | ||
100 | +#include "qemu/log.h" | ||
101 | +#include "sysemu/sysemu.h" | ||
102 | + | ||
103 | +static uint64_t imx7_snvs_read(void *opaque, hwaddr offset, unsigned size) | ||
104 | +{ | ||
105 | + return 0; | ||
106 | +} | ||
107 | + | ||
108 | +static void imx7_snvs_write(void *opaque, hwaddr offset, | ||
109 | + uint64_t v, unsigned size) | ||
110 | +{ | ||
111 | + const uint32_t value = v; | ||
112 | + const uint32_t mask = SNVS_LPCR_TOP | SNVS_LPCR_DP_EN; | ||
113 | + | ||
114 | + if (offset == SNVS_LPCR && ((value & mask) == mask)) { | ||
115 | + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); | ||
116 | + } | ||
117 | +} | ||
118 | + | ||
119 | +static const struct MemoryRegionOps imx7_snvs_ops = { | ||
120 | + .read = imx7_snvs_read, | ||
121 | + .write = imx7_snvs_write, | ||
122 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
123 | + .impl = { | ||
124 | + /* | ||
125 | + * Our device would not work correctly if the guest was doing | ||
126 | + * unaligned access. This might not be a limitation on the real | ||
127 | + * device but in practice there is no reason for a guest to access | ||
128 | + * this device unaligned. | ||
129 | + */ | ||
130 | + .min_access_size = 4, | ||
131 | + .max_access_size = 4, | ||
132 | + .unaligned = false, | ||
133 | + }, | ||
134 | +}; | ||
135 | + | ||
136 | +static void imx7_snvs_init(Object *obj) | ||
137 | +{ | ||
138 | + SysBusDevice *sd = SYS_BUS_DEVICE(obj); | ||
139 | + IMX7SNVSState *s = IMX7_SNVS(obj); | ||
140 | + | ||
141 | + memory_region_init_io(&s->mmio, obj, &imx7_snvs_ops, s, | ||
142 | + TYPE_IMX7_SNVS, 0x1000); | ||
143 | + | ||
144 | + sysbus_init_mmio(sd, &s->mmio); | ||
145 | +} | ||
146 | + | ||
147 | +static void imx7_snvs_class_init(ObjectClass *klass, void *data) | ||
148 | +{ | ||
149 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
150 | + | ||
151 | + dc->desc = "i.MX7 Secure Non-Volatile Storage Module"; | ||
152 | +} | ||
153 | + | ||
154 | +static const TypeInfo imx7_snvs_info = { | ||
155 | + .name = TYPE_IMX7_SNVS, | ||
156 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
157 | + .instance_size = sizeof(IMX7SNVSState), | ||
158 | + .instance_init = imx7_snvs_init, | ||
159 | + .class_init = imx7_snvs_class_init, | ||
160 | +}; | ||
161 | + | ||
162 | +static void imx7_snvs_register_type(void) | ||
163 | +{ | ||
164 | + type_register_static(&imx7_snvs_info); | ||
165 | +} | ||
166 | +type_init(imx7_snvs_register_type) | ||
167 | -- | ||
168 | 2.16.1 | ||
169 | |||
170 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
2 | 1 | ||
3 | Add minimal code needed to allow upstream Linux guest to boot. | ||
4 | |||
5 | Cc: Peter Maydell <peter.maydell@linaro.org> | ||
6 | Cc: Jason Wang <jasowang@redhat.com> | ||
7 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | ||
9 | Cc: Michael S. Tsirkin <mst@redhat.com> | ||
10 | Cc: qemu-devel@nongnu.org | ||
11 | Cc: qemu-arm@nongnu.org | ||
12 | Cc: yurovsky@gmail.com | ||
13 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
14 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
16 | --- | ||
17 | hw/intc/Makefile.objs | 2 +- | ||
18 | include/hw/intc/imx_gpcv2.h | 22 ++++++++ | ||
19 | hw/intc/imx_gpcv2.c | 125 ++++++++++++++++++++++++++++++++++++++++++++ | ||
20 | 3 files changed, 148 insertions(+), 1 deletion(-) | ||
21 | create mode 100644 include/hw/intc/imx_gpcv2.h | ||
22 | create mode 100644 hw/intc/imx_gpcv2.c | ||
23 | |||
24 | diff --git a/hw/intc/Makefile.objs b/hw/intc/Makefile.objs | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/hw/intc/Makefile.objs | ||
27 | +++ b/hw/intc/Makefile.objs | ||
28 | @@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_XILINX) += xilinx_intc.o | ||
29 | common-obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-pmu-iomod-intc.o | ||
30 | common-obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-zynqmp-ipi.o | ||
31 | common-obj-$(CONFIG_ETRAXFS) += etraxfs_pic.o | ||
32 | -common-obj-$(CONFIG_IMX) += imx_avic.o | ||
33 | +common-obj-$(CONFIG_IMX) += imx_avic.o imx_gpcv2.o | ||
34 | common-obj-$(CONFIG_LM32) += lm32_pic.o | ||
35 | common-obj-$(CONFIG_REALVIEW) += realview_gic.o | ||
36 | common-obj-$(CONFIG_SLAVIO) += slavio_intctl.o | ||
37 | diff --git a/include/hw/intc/imx_gpcv2.h b/include/hw/intc/imx_gpcv2.h | ||
38 | new file mode 100644 | ||
39 | index XXXXXXX..XXXXXXX | ||
40 | --- /dev/null | ||
41 | +++ b/include/hw/intc/imx_gpcv2.h | ||
42 | @@ -XXX,XX +XXX,XX @@ | ||
43 | +#ifndef IMX_GPCV2_H | ||
44 | +#define IMX_GPCV2_H | ||
45 | + | ||
46 | +#include "hw/sysbus.h" | ||
47 | + | ||
48 | +enum IMXGPCv2Registers { | ||
49 | + GPC_NUM = 0xE00 / sizeof(uint32_t), | ||
50 | +}; | ||
51 | + | ||
52 | +typedef struct IMXGPCv2State { | ||
53 | + /*< private >*/ | ||
54 | + SysBusDevice parent_obj; | ||
55 | + | ||
56 | + /*< public >*/ | ||
57 | + MemoryRegion iomem; | ||
58 | + uint32_t regs[GPC_NUM]; | ||
59 | +} IMXGPCv2State; | ||
60 | + | ||
61 | +#define TYPE_IMX_GPCV2 "imx-gpcv2" | ||
62 | +#define IMX_GPCV2(obj) OBJECT_CHECK(IMXGPCv2State, (obj), TYPE_IMX_GPCV2) | ||
63 | + | ||
64 | +#endif /* IMX_GPCV2_H */ | ||
65 | diff --git a/hw/intc/imx_gpcv2.c b/hw/intc/imx_gpcv2.c | ||
66 | new file mode 100644 | ||
67 | index XXXXXXX..XXXXXXX | ||
68 | --- /dev/null | ||
69 | +++ b/hw/intc/imx_gpcv2.c | ||
70 | @@ -XXX,XX +XXX,XX @@ | ||
71 | +/* | ||
72 | + * Copyright (c) 2018, Impinj, Inc. | ||
73 | + * | ||
74 | + * i.MX7 GPCv2 block emulation code | ||
75 | + * | ||
76 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
77 | + * | ||
78 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
79 | + * See the COPYING file in the top-level directory. | ||
80 | + */ | ||
81 | + | ||
82 | +#include "qemu/osdep.h" | ||
83 | +#include "hw/intc/imx_gpcv2.h" | ||
84 | +#include "qemu/log.h" | ||
85 | + | ||
86 | +#define GPC_PU_PGC_SW_PUP_REQ 0x0f8 | ||
87 | +#define GPC_PU_PGC_SW_PDN_REQ 0x104 | ||
88 | + | ||
89 | +#define USB_HSIC_PHY_SW_Pxx_REQ BIT(4) | ||
90 | +#define USB_OTG2_PHY_SW_Pxx_REQ BIT(3) | ||
91 | +#define USB_OTG1_PHY_SW_Pxx_REQ BIT(2) | ||
92 | +#define PCIE_PHY_SW_Pxx_REQ BIT(1) | ||
93 | +#define MIPI_PHY_SW_Pxx_REQ BIT(0) | ||
94 | + | ||
95 | + | ||
96 | +static void imx_gpcv2_reset(DeviceState *dev) | ||
97 | +{ | ||
98 | + IMXGPCv2State *s = IMX_GPCV2(dev); | ||
99 | + | ||
100 | + memset(s->regs, 0, sizeof(s->regs)); | ||
101 | +} | ||
102 | + | ||
103 | +static uint64_t imx_gpcv2_read(void *opaque, hwaddr offset, | ||
104 | + unsigned size) | ||
105 | +{ | ||
106 | + IMXGPCv2State *s = opaque; | ||
107 | + | ||
108 | + return s->regs[offset / sizeof(uint32_t)]; | ||
109 | +} | ||
110 | + | ||
111 | +static void imx_gpcv2_write(void *opaque, hwaddr offset, | ||
112 | + uint64_t value, unsigned size) | ||
113 | +{ | ||
114 | + IMXGPCv2State *s = opaque; | ||
115 | + const size_t idx = offset / sizeof(uint32_t); | ||
116 | + | ||
117 | + s->regs[idx] = value; | ||
118 | + | ||
119 | + /* | ||
120 | + * Real HW will clear those bits once as a way to indicate that | ||
121 | + * power up request is complete | ||
122 | + */ | ||
123 | + if (offset == GPC_PU_PGC_SW_PUP_REQ || | ||
124 | + offset == GPC_PU_PGC_SW_PDN_REQ) { | ||
125 | + s->regs[idx] &= ~(USB_HSIC_PHY_SW_Pxx_REQ | | ||
126 | + USB_OTG2_PHY_SW_Pxx_REQ | | ||
127 | + USB_OTG1_PHY_SW_Pxx_REQ | | ||
128 | + PCIE_PHY_SW_Pxx_REQ | | ||
129 | + MIPI_PHY_SW_Pxx_REQ); | ||
130 | + } | ||
131 | +} | ||
132 | + | ||
133 | +static const struct MemoryRegionOps imx_gpcv2_ops = { | ||
134 | + .read = imx_gpcv2_read, | ||
135 | + .write = imx_gpcv2_write, | ||
136 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
137 | + .impl = { | ||
138 | + /* | ||
139 | + * Our device would not work correctly if the guest was doing | ||
140 | + * unaligned access. This might not be a limitation on the real | ||
141 | + * device but in practice there is no reason for a guest to access | ||
142 | + * this device unaligned. | ||
143 | + */ | ||
144 | + .min_access_size = 4, | ||
145 | + .max_access_size = 4, | ||
146 | + .unaligned = false, | ||
147 | + }, | ||
148 | +}; | ||
149 | + | ||
150 | +static void imx_gpcv2_init(Object *obj) | ||
151 | +{ | ||
152 | + SysBusDevice *sd = SYS_BUS_DEVICE(obj); | ||
153 | + IMXGPCv2State *s = IMX_GPCV2(obj); | ||
154 | + | ||
155 | + memory_region_init_io(&s->iomem, | ||
156 | + obj, | ||
157 | + &imx_gpcv2_ops, | ||
158 | + s, | ||
159 | + TYPE_IMX_GPCV2 ".iomem", | ||
160 | + sizeof(s->regs)); | ||
161 | + sysbus_init_mmio(sd, &s->iomem); | ||
162 | +} | ||
163 | + | ||
164 | +static const VMStateDescription vmstate_imx_gpcv2 = { | ||
165 | + .name = TYPE_IMX_GPCV2, | ||
166 | + .version_id = 1, | ||
167 | + .minimum_version_id = 1, | ||
168 | + .fields = (VMStateField[]) { | ||
169 | + VMSTATE_UINT32_ARRAY(regs, IMXGPCv2State, GPC_NUM), | ||
170 | + VMSTATE_END_OF_LIST() | ||
171 | + }, | ||
172 | +}; | ||
173 | + | ||
174 | +static void imx_gpcv2_class_init(ObjectClass *klass, void *data) | ||
175 | +{ | ||
176 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
177 | + | ||
178 | + dc->reset = imx_gpcv2_reset; | ||
179 | + dc->vmsd = &vmstate_imx_gpcv2; | ||
180 | + dc->desc = "i.MX GPCv2 Module"; | ||
181 | +} | ||
182 | + | ||
183 | +static const TypeInfo imx_gpcv2_info = { | ||
184 | + .name = TYPE_IMX_GPCV2, | ||
185 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
186 | + .instance_size = sizeof(IMXGPCv2State), | ||
187 | + .instance_init = imx_gpcv2_init, | ||
188 | + .class_init = imx_gpcv2_class_init, | ||
189 | +}; | ||
190 | + | ||
191 | +static void imx_gpcv2_register_type(void) | ||
192 | +{ | ||
193 | + type_register_static(&imx_gpcv2_info); | ||
194 | +} | ||
195 | +type_init(imx_gpcv2_register_type) | ||
196 | -- | ||
197 | 2.16.1 | ||
198 | |||
199 | diff view generated by jsdifflib |