1
ARM queu; includes all the NVIC rewrite patches.
1
ARM bugfixes for rc1...
2
The QOMify-armv7m patchset hasn't got enough review just
3
yet but I may be able to sneak it in before freeze
4
tomorrow if it gets review. Didn't want to hold this lot
5
up waiting, anyway.
6
7
thanks
8
-- PMM
9
2
10
3
11
The following changes since commit 8f2d7c341184a95d05476ea3c45dbae2b9ddbe51:
4
The following changes since commit f291910db61b5812e68f1e76afb3ade41d567bea:
12
5
13
Merge remote-tracking branch 'remotes/berrange/tags/pull-qcrypto-2017-02-27-1' into staging (2017-02-27 15:33:21 +0000)
6
Merge remote-tracking branch 'remotes/ericb/tags/pull-nbd-2017-11-09' into staging (2017-11-13 13:13:12 +0000)
14
7
15
are available in the git repository at:
8
are available in the git repository at:
16
9
17
git://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20170227
10
git://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20171113
18
11
19
for you to fetch changes up to 94d5bcf5a7f3799660b62098a5183f161aad0601:
12
for you to fetch changes up to d25f2a72272b9ffe0d06710d6217d1169bc2cc7d:
20
13
21
hw/arm/exynos: Fix proper mapping of CPUs by providing real cluster ID (2017-02-27 17:23:16 +0000)
14
accel/tcg/translate-all: expand cpu_restore_state addr check (2017-11-13 13:55:27 +0000)
22
15
23
----------------------------------------------------------------
16
----------------------------------------------------------------
24
target-arm queue:
17
target-arm queue:
25
* raspi2: implement RNG module, GPIO and new SD card controller
18
* translate-a64.c: silence gcc5 warning
26
(sufficient to boot new raspbian kernels)
19
* highbank: validate register offset before access
27
* sdhci: bugfixes for block transfers
20
* MAINTAINERS: Add entries for Smartfusion2
28
* virt: fix cpu object reference leak
21
* accel/tcg/translate-all: expand cpu_restore_state addr check
29
* Add missing fp_access_check() to aarch64 crypto instructions
22
(so usermode insn aborts don't crash with an assertion failure)
30
* cputlb: Don't assume do_unassigned_access() never returns
23
* fix TCG initialization of some Arm boards by allowing them
31
* virt: Add a user option to disallow ITS instantiation
24
to specify min/default number of CPUs to create
32
* i.MX timers: fix reset handling
33
* ARMv7M NVIC: rewrite to fix broken priority handling and masking
34
* exynos: Fix proper mapping of CPUs by providing real cluster ID
35
* exynos: Fix Linux kernel division by zero for PLLs
36
25
37
----------------------------------------------------------------
26
----------------------------------------------------------------
38
Clement Deschamps (4):
27
Alex Bennée (1):
39
bcm2835_sdhost: add bcm2835 sdhost controller
28
accel/tcg/translate-all: expand cpu_restore_state addr check
40
hw/sd: add card-reparenting function
41
bcm2835_gpio: add bcm2835 gpio controller
42
bcm2835: add sdhost and gpio controllers
43
29
44
Eric Auger (1):
30
Alistair Francis (2):
45
hw/arm/virt: Add a user option to disallow ITS instantiation
31
xlnx-zynqmp: Properly support the smp command line option
32
xlnx-zcu102: Add an info message deprecating the EP108
46
33
47
Igor Mammedov (1):
34
Emilio G. Cota (4):
48
hw/arm/virt: fix cpu object reference leak
35
arm/translate-a64: mark path as unreachable to eliminate warning
36
qom: move CPUClass.tcg_initialize to a global
37
xlnx-zcu102: Specify the max number of CPUs for the EP108
38
hw: add .min_cpus and .default_cpus fields to machine_class
49
39
50
Krzysztof Kozlowski (2):
40
Prasad J Pandit (1):
51
hw/arm/exynos: Fix Linux kernel division by zero for PLLs
41
highbank: validate register offset before access
52
hw/arm/exynos: Fix proper mapping of CPUs by providing real cluster ID
53
42
54
Kurban Mallachiev (1):
43
Subbaraya Sundeep (1):
55
ARM i.MX timers: fix reset handling
44
MAINTAINERS: Add entries for Smartfusion2
56
45
57
Marcin Chojnacki (1):
46
include/exec/exec-all.h | 11 ++++++++++
58
target-arm: Implement BCM2835 hardware RNG
47
include/hw/boards.h | 5 +++++
48
include/qom/cpu.h | 1 -
49
accel/tcg/translate-all.c | 52 ++++++++++++++++++++++++++--------------------
50
exec.c | 5 +++--
51
hw/arm/exynos4_boards.c | 12 ++++-------
52
hw/arm/highbank.c | 17 +++++++++++++--
53
hw/arm/raspi.c | 2 ++
54
hw/arm/xlnx-zcu102.c | 9 +++++++-
55
hw/arm/xlnx-zynqmp.c | 26 ++++++++++++++---------
56
target/arm/translate-a64.c | 2 ++
57
vl.c | 21 ++++++++++++++++---
58
MAINTAINERS | 17 +++++++++++++++
59
qemu-doc.texi | 7 +++++++
60
14 files changed, 137 insertions(+), 50 deletions(-)
59
61
60
Michael Davidsaver (5):
61
armv7m: Rewrite NVIC to not use any GIC code
62
arm: gic: Remove references to NVIC
63
armv7m: Escalate exceptions to HardFault if necessary
64
armv7m: Simpler and faster exception start
65
armv7m: VECTCLRACTIVE and VECTRESET are UNPREDICTABLE
66
67
Nick Reilly (1):
68
Add missing fp_access_check() to aarch64 crypto instructions
69
70
Peter Maydell (10):
71
bcm2835_rng: Use qcrypto_random_bytes() rather than rand()
72
cputlb: Don't assume do_unassigned_access() never returns
73
armv7m: Rename nvic_state to NVICState
74
armv7m: Implement reading and writing of PRIGROUP
75
armv7m: Fix condition check for taking exceptions
76
armv7m: Remove unused armv7m_nvic_acknowledge_irq() return value
77
armv7m: Extract "exception taken" code into functions
78
armv7m: Check exception return consistency
79
armv7m: Raise correct kind of UsageFault for attempts to execute ARM code
80
armv7m: Allow SHCSR writes to change pending and active bits
81
82
Prasad J Pandit (4):
83
sd: sdhci: mask transfer mode register value
84
sd: sdhci: check transfer mode register in multi block transfer
85
sd: sdhci: conditionally invoke multi block transfer
86
sd: sdhci: Remove block count enable check in single block transfers
87
88
hw/gpio/Makefile.objs | 1 +
89
hw/misc/Makefile.objs | 3 +-
90
hw/sd/Makefile.objs | 1 +
91
hw/intc/gic_internal.h | 7 +-
92
include/hw/arm/bcm2835_peripherals.h | 6 +
93
include/hw/arm/virt.h | 1 +
94
include/hw/gpio/bcm2835_gpio.h | 39 ++
95
include/hw/misc/bcm2835_rng.h | 27 ++
96
include/hw/sd/bcm2835_sdhost.h | 48 ++
97
include/hw/sd/sd.h | 11 +
98
target/arm/cpu.h | 23 +-
99
cputlb.c | 15 +-
100
hw/arm/bcm2835_peripherals.c | 58 ++-
101
hw/arm/exynos4210.c | 18 +
102
hw/arm/virt.c | 32 +-
103
hw/gpio/bcm2835_gpio.c | 353 ++++++++++++++
104
hw/intc/arm_gic.c | 31 +-
105
hw/intc/arm_gic_common.c | 23 +-
106
hw/intc/armv7m_nvic.c | 885 ++++++++++++++++++++++++++++-------
107
hw/misc/bcm2835_rng.c | 149 ++++++
108
hw/misc/exynos4210_clk.c | 164 +++++++
109
hw/sd/bcm2835_sdhost.c | 429 +++++++++++++++++
110
hw/sd/core.c | 30 ++
111
hw/sd/sdhci.c | 25 +-
112
hw/timer/imx_gpt.c | 33 +-
113
linux-user/main.c | 1 +
114
target/arm/cpu.c | 16 +-
115
target/arm/helper.c | 245 +++++++---
116
target/arm/translate-a64.c | 12 +
117
target/arm/translate.c | 8 +-
118
hw/intc/trace-events | 15 +
119
31 files changed, 2376 insertions(+), 333 deletions(-)
120
create mode 100644 include/hw/gpio/bcm2835_gpio.h
121
create mode 100644 include/hw/misc/bcm2835_rng.h
122
create mode 100644 include/hw/sd/bcm2835_sdhost.h
123
create mode 100644 hw/gpio/bcm2835_gpio.c
124
create mode 100644 hw/misc/bcm2835_rng.c
125
create mode 100644 hw/misc/exynos4210_clk.c
126
create mode 100644 hw/sd/bcm2835_sdhost.c
127
diff view generated by jsdifflib
Deleted patch
1
From: Marcin Chojnacki <marcinch7@gmail.com>
2
1
3
Recent vanilla Raspberry Pi kernels started to make use of
4
the hardware random number generator in BCM2835 SoC. As a
5
result, those kernels wouldn't work anymore under QEMU
6
but rather just freeze during the boot process.
7
8
This patch implements a trivial BCM2835 compatible RNG,
9
and adds it as a peripheral to BCM2835 platform, which
10
allows to boot a vanilla Raspberry Pi kernel under Qemu.
11
12
Changes since v1:
13
* Prevented guest from writing [31..20] bits in rng_status
14
* Removed redundant minimum_version_id_old
15
* Added field entries for the state
16
* Changed realize function to reset
17
18
Signed-off-by: Marcin Chojnacki <marcinch7@gmail.com>
19
Message-id: 20170210210857.47893-1-marcinch7@gmail.com
20
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
21
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
22
---
23
hw/misc/Makefile.objs | 1 +
24
include/hw/arm/bcm2835_peripherals.h | 2 +
25
include/hw/misc/bcm2835_rng.h | 27 ++++++++
26
hw/arm/bcm2835_peripherals.c | 15 +++++
27
hw/misc/bcm2835_rng.c | 124 +++++++++++++++++++++++++++++++++++
28
5 files changed, 169 insertions(+)
29
create mode 100644 include/hw/misc/bcm2835_rng.h
30
create mode 100644 hw/misc/bcm2835_rng.c
31
32
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
33
index XXXXXXX..XXXXXXX 100644
34
--- a/hw/misc/Makefile.objs
35
+++ b/hw/misc/Makefile.objs
36
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_OMAP) += omap_sdrc.o
37
obj-$(CONFIG_OMAP) += omap_tap.o
38
obj-$(CONFIG_RASPI) += bcm2835_mbox.o
39
obj-$(CONFIG_RASPI) += bcm2835_property.o
40
+obj-$(CONFIG_RASPI) += bcm2835_rng.o
41
obj-$(CONFIG_SLAVIO) += slavio_misc.o
42
obj-$(CONFIG_ZYNQ) += zynq_slcr.o
43
obj-$(CONFIG_ZYNQ) += zynq-xadc.o
44
diff --git a/include/hw/arm/bcm2835_peripherals.h b/include/hw/arm/bcm2835_peripherals.h
45
index XXXXXXX..XXXXXXX 100644
46
--- a/include/hw/arm/bcm2835_peripherals.h
47
+++ b/include/hw/arm/bcm2835_peripherals.h
48
@@ -XXX,XX +XXX,XX @@
49
#include "hw/dma/bcm2835_dma.h"
50
#include "hw/intc/bcm2835_ic.h"
51
#include "hw/misc/bcm2835_property.h"
52
+#include "hw/misc/bcm2835_rng.h"
53
#include "hw/misc/bcm2835_mbox.h"
54
#include "hw/sd/sdhci.h"
55
56
@@ -XXX,XX +XXX,XX @@ typedef struct BCM2835PeripheralState {
57
BCM2835DMAState dma;
58
BCM2835ICState ic;
59
BCM2835PropertyState property;
60
+ BCM2835RngState rng;
61
BCM2835MboxState mboxes;
62
SDHCIState sdhci;
63
} BCM2835PeripheralState;
64
diff --git a/include/hw/misc/bcm2835_rng.h b/include/hw/misc/bcm2835_rng.h
65
new file mode 100644
66
index XXXXXXX..XXXXXXX
67
--- /dev/null
68
+++ b/include/hw/misc/bcm2835_rng.h
69
@@ -XXX,XX +XXX,XX @@
70
+/*
71
+ * BCM2835 Random Number Generator emulation
72
+ *
73
+ * Copyright (C) 2017 Marcin Chojnacki <marcinch7@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
+#ifndef BCM2835_RNG_H
80
+#define BCM2835_RNG_H
81
+
82
+#include "hw/sysbus.h"
83
+
84
+#define TYPE_BCM2835_RNG "bcm2835-rng"
85
+#define BCM2835_RNG(obj) \
86
+ OBJECT_CHECK(BCM2835RngState, (obj), TYPE_BCM2835_RNG)
87
+
88
+typedef struct {
89
+ SysBusDevice busdev;
90
+ MemoryRegion iomem;
91
+
92
+ uint32_t rng_ctrl;
93
+ uint32_t rng_status;
94
+} BCM2835RngState;
95
+
96
+#endif
97
diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c
98
index XXXXXXX..XXXXXXX 100644
99
--- a/hw/arm/bcm2835_peripherals.c
100
+++ b/hw/arm/bcm2835_peripherals.c
101
@@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_init(Object *obj)
102
object_property_add_const_link(OBJECT(&s->property), "dma-mr",
103
OBJECT(&s->gpu_bus_mr), &error_abort);
104
105
+ /* Random Number Generator */
106
+ object_initialize(&s->rng, sizeof(s->rng), TYPE_BCM2835_RNG);
107
+ object_property_add_child(obj, "rng", OBJECT(&s->rng), NULL);
108
+ qdev_set_parent_bus(DEVICE(&s->rng), sysbus_get_default());
109
+
110
/* Extended Mass Media Controller */
111
object_initialize(&s->sdhci, sizeof(s->sdhci), TYPE_SYSBUS_SDHCI);
112
object_property_add_child(obj, "sdhci", OBJECT(&s->sdhci), NULL);
113
@@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
114
sysbus_connect_irq(SYS_BUS_DEVICE(&s->property), 0,
115
qdev_get_gpio_in(DEVICE(&s->mboxes), MBOX_CHAN_PROPERTY));
116
117
+ /* Random Number Generator */
118
+ object_property_set_bool(OBJECT(&s->rng), true, "realized", &err);
119
+ if (err) {
120
+ error_propagate(errp, err);
121
+ return;
122
+ }
123
+
124
+ memory_region_add_subregion(&s->peri_mr, RNG_OFFSET,
125
+ sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->rng), 0));
126
+
127
/* Extended Mass Media Controller */
128
object_property_set_int(OBJECT(&s->sdhci), BCM2835_SDHC_CAPAREG, "capareg",
129
&err);
130
diff --git a/hw/misc/bcm2835_rng.c b/hw/misc/bcm2835_rng.c
131
new file mode 100644
132
index XXXXXXX..XXXXXXX
133
--- /dev/null
134
+++ b/hw/misc/bcm2835_rng.c
135
@@ -XXX,XX +XXX,XX @@
136
+/*
137
+ * BCM2835 Random Number Generator emulation
138
+ *
139
+ * Copyright (C) 2017 Marcin Chojnacki <marcinch7@gmail.com>
140
+ *
141
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
142
+ * See the COPYING file in the top-level directory.
143
+ */
144
+
145
+#include "qemu/osdep.h"
146
+#include "qemu/log.h"
147
+#include "hw/misc/bcm2835_rng.h"
148
+
149
+static uint64_t bcm2835_rng_read(void *opaque, hwaddr offset,
150
+ unsigned size)
151
+{
152
+ BCM2835RngState *s = (BCM2835RngState *)opaque;
153
+ uint32_t res = 0;
154
+
155
+ assert(size == 4);
156
+
157
+ switch (offset) {
158
+ case 0x0: /* rng_ctrl */
159
+ res = s->rng_ctrl;
160
+ break;
161
+ case 0x4: /* rng_status */
162
+ res = s->rng_status | (1 << 24);
163
+ break;
164
+ case 0x8: /* rng_data */
165
+ res = rand();
166
+ break;
167
+
168
+ default:
169
+ qemu_log_mask(LOG_GUEST_ERROR,
170
+ "bcm2835_rng_read: Bad offset %x\n",
171
+ (int)offset);
172
+ res = 0;
173
+ break;
174
+ }
175
+
176
+ return res;
177
+}
178
+
179
+static void bcm2835_rng_write(void *opaque, hwaddr offset,
180
+ uint64_t value, unsigned size)
181
+{
182
+ BCM2835RngState *s = (BCM2835RngState *)opaque;
183
+
184
+ assert(size == 4);
185
+
186
+ switch (offset) {
187
+ case 0x0: /* rng_ctrl */
188
+ s->rng_ctrl = value;
189
+ break;
190
+ case 0x4: /* rng_status */
191
+ /* we shouldn't let the guest write to bits [31..20] */
192
+ s->rng_status &= ~0xFFFFF; /* clear 20 lower bits */
193
+ s->rng_status |= value & 0xFFFFF; /* set them to new value */
194
+ break;
195
+
196
+ default:
197
+ qemu_log_mask(LOG_GUEST_ERROR,
198
+ "bcm2835_rng_write: Bad offset %x\n",
199
+ (int)offset);
200
+ break;
201
+ }
202
+}
203
+
204
+static const MemoryRegionOps bcm2835_rng_ops = {
205
+ .read = bcm2835_rng_read,
206
+ .write = bcm2835_rng_write,
207
+ .endianness = DEVICE_NATIVE_ENDIAN,
208
+};
209
+
210
+static const VMStateDescription vmstate_bcm2835_rng = {
211
+ .name = TYPE_BCM2835_RNG,
212
+ .version_id = 1,
213
+ .minimum_version_id = 1,
214
+ .fields = (VMStateField[]) {
215
+ VMSTATE_UINT32(rng_ctrl, BCM2835RngState),
216
+ VMSTATE_UINT32(rng_status, BCM2835RngState),
217
+ VMSTATE_END_OF_LIST()
218
+ }
219
+};
220
+
221
+static void bcm2835_rng_init(Object *obj)
222
+{
223
+ BCM2835RngState *s = BCM2835_RNG(obj);
224
+
225
+ memory_region_init_io(&s->iomem, obj, &bcm2835_rng_ops, s,
226
+ TYPE_BCM2835_RNG, 0x10);
227
+ sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem);
228
+}
229
+
230
+static void bcm2835_rng_reset(DeviceState *dev)
231
+{
232
+ BCM2835RngState *s = BCM2835_RNG(dev);
233
+
234
+ s->rng_ctrl = 0;
235
+ s->rng_status = 0;
236
+}
237
+
238
+static void bcm2835_rng_class_init(ObjectClass *klass, void *data)
239
+{
240
+ DeviceClass *dc = DEVICE_CLASS(klass);
241
+
242
+ dc->reset = bcm2835_rng_reset;
243
+ dc->vmsd = &vmstate_bcm2835_rng;
244
+}
245
+
246
+static TypeInfo bcm2835_rng_info = {
247
+ .name = TYPE_BCM2835_RNG,
248
+ .parent = TYPE_SYS_BUS_DEVICE,
249
+ .instance_size = sizeof(BCM2835RngState),
250
+ .class_init = bcm2835_rng_class_init,
251
+ .instance_init = bcm2835_rng_init,
252
+};
253
+
254
+static void bcm2835_rng_register_types(void)
255
+{
256
+ type_register_static(&bcm2835_rng_info);
257
+}
258
+
259
+type_init(bcm2835_rng_register_types)
260
--
261
2.7.4
262
263
diff view generated by jsdifflib
Deleted patch
1
Switch to using qcrypto_random_bytes() rather than rand() as
2
our source of randomness for the BCM2835 RNG.
3
1
4
If qcrypto_random_bytes() fails, we don't want to return the guest a
5
non-random value in case they're really using it for cryptographic
6
purposes, so the best we can do is a fatal error. This shouldn't
7
happen unless something's broken, though.
8
9
In theory we could implement this device's full FIFO and interrupt
10
semantics and then just stop filling the FIFO. That's a lot of work,
11
though, and doesn't really give a very nice diagnostic to the user
12
since the guest will just seem to hang.
13
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
16
---
17
hw/misc/bcm2835_rng.c | 27 ++++++++++++++++++++++++++-
18
1 file changed, 26 insertions(+), 1 deletion(-)
19
20
diff --git a/hw/misc/bcm2835_rng.c b/hw/misc/bcm2835_rng.c
21
index XXXXXXX..XXXXXXX 100644
22
--- a/hw/misc/bcm2835_rng.c
23
+++ b/hw/misc/bcm2835_rng.c
24
@@ -XXX,XX +XXX,XX @@
25
26
#include "qemu/osdep.h"
27
#include "qemu/log.h"
28
+#include "qapi/error.h"
29
+#include "crypto/random.h"
30
#include "hw/misc/bcm2835_rng.h"
31
32
+static uint32_t get_random_bytes(void)
33
+{
34
+ uint32_t res;
35
+ Error *err = NULL;
36
+
37
+ if (qcrypto_random_bytes((uint8_t *)&res, sizeof(res), &err) < 0) {
38
+ /* On failure we don't want to return the guest a non-random
39
+ * value in case they're really using it for cryptographic
40
+ * purposes, so the best we can do is die here.
41
+ * This shouldn't happen unless something's broken.
42
+ * In theory we could implement this device's full FIFO
43
+ * and interrupt semantics and then just stop filling the
44
+ * FIFO. That's a lot of work, though, so we assume any
45
+ * errors are systematic problems and trust that if we didn't
46
+ * fail as the guest inited then we won't fail later on
47
+ * mid-run.
48
+ */
49
+ error_report_err(err);
50
+ exit(1);
51
+ }
52
+ return res;
53
+}
54
+
55
static uint64_t bcm2835_rng_read(void *opaque, hwaddr offset,
56
unsigned size)
57
{
58
@@ -XXX,XX +XXX,XX @@ static uint64_t bcm2835_rng_read(void *opaque, hwaddr offset,
59
res = s->rng_status | (1 << 24);
60
break;
61
case 0x8: /* rng_data */
62
- res = rand();
63
+ res = get_random_bytes();
64
break;
65
66
default:
67
--
68
2.7.4
69
70
diff view generated by jsdifflib
Deleted patch
1
From: Prasad J Pandit <pjp@fedoraproject.org>
2
1
3
In SDHCI protocol, the transfer mode register is defined
4
to be of 6 bits. Mask its value with '0x0037' so that an
5
invalid value could not be assigned.
6
7
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
8
Reviewed-by: Alistair Francis <alistair.francis@xilinx.com>
9
Message-id: 20170214185225.7994-2-ppandit@redhat.com
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
12
hw/sd/sdhci.c | 3 ++-
13
1 file changed, 2 insertions(+), 1 deletion(-)
14
15
diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/hw/sd/sdhci.c
18
+++ b/hw/sd/sdhci.c
19
@@ -XXX,XX +XXX,XX @@
20
(SDHC_CAPAB_BASECLKFREQ << 8) | (SDHC_CAPAB_TOUNIT << 7) | \
21
(SDHC_CAPAB_TOCLKFREQ))
22
23
+#define MASK_TRNMOD 0x0037
24
#define MASKED_WRITE(reg, mask, val) (reg = (reg & (mask)) | (val))
25
26
static uint8_t sdhci_slotint(SDHCIState *s)
27
@@ -XXX,XX +XXX,XX @@ sdhci_write(void *opaque, hwaddr offset, uint64_t val, unsigned size)
28
if (!(s->capareg & SDHC_CAN_DO_DMA)) {
29
value &= ~SDHC_TRNS_DMA;
30
}
31
- MASKED_WRITE(s->trnmod, mask, value);
32
+ MASKED_WRITE(s->trnmod, mask, value & MASK_TRNMOD);
33
MASKED_WRITE(s->cmdreg, mask >> 16, value >> 16);
34
35
/* Writing to the upper byte of CMDREG triggers SD command generation */
36
--
37
2.7.4
38
39
diff view generated by jsdifflib
Deleted patch
1
From: Prasad J Pandit <pjp@fedoraproject.org>
2
1
3
In the SDHCI protocol, the transfer mode register value
4
is used during multi block transfer to check if block count
5
register is enabled and should be updated. Transfer mode
6
register could be set such that, block count register would
7
not be updated, thus leading to an infinite loop. Add check
8
to avoid it.
9
10
Reported-by: Wjjzhang <wjjzhang@tencent.com>
11
Reported-by: Jiang Xin <jiangxin1@huawei.com>
12
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
13
Message-id: 20170214185225.7994-3-ppandit@redhat.com
14
Reviewed-by: Alistair Francis <alistair.francis@xilinx.com>
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
---
17
hw/sd/sdhci.c | 10 +++++-----
18
1 file changed, 5 insertions(+), 5 deletions(-)
19
20
diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
21
index XXXXXXX..XXXXXXX 100644
22
--- a/hw/sd/sdhci.c
23
+++ b/hw/sd/sdhci.c
24
@@ -XXX,XX +XXX,XX @@ static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s)
25
uint32_t boundary_chk = 1 << (((s->blksize & 0xf000) >> 12) + 12);
26
uint32_t boundary_count = boundary_chk - (s->sdmasysad % boundary_chk);
27
28
+ if (!(s->trnmod & SDHC_TRNS_BLK_CNT_EN) || !s->blkcnt) {
29
+ qemu_log_mask(LOG_UNIMP, "infinite transfer is not supported\n");
30
+ return;
31
+ }
32
+
33
/* XXX: Some sd/mmc drivers (for example, u-boot-slp) do not account for
34
* possible stop at page boundary if initial address is not page aligned,
35
* allow them to work properly */
36
@@ -XXX,XX +XXX,XX @@ static void sdhci_data_transfer(void *opaque)
37
if (s->trnmod & SDHC_TRNS_DMA) {
38
switch (SDHC_DMA_TYPE(s->hostctl)) {
39
case SDHC_CTRL_SDMA:
40
- if ((s->trnmod & SDHC_TRNS_MULTI) &&
41
- (!(s->trnmod & SDHC_TRNS_BLK_CNT_EN) || s->blkcnt == 0)) {
42
- break;
43
- }
44
-
45
if ((s->blkcnt == 1) || !(s->trnmod & SDHC_TRNS_MULTI)) {
46
sdhci_sdma_transfer_single_block(s);
47
} else {
48
--
49
2.7.4
50
51
diff view generated by jsdifflib
Deleted patch
1
From: Prasad J Pandit <pjp@fedoraproject.org>
2
1
3
In sdhci_write invoke multi block transfer if it is enabled
4
in the transfer mode register 's->trnmod'.
5
6
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
7
Message-id: 20170214185225.7994-4-ppandit@redhat.com
8
Reviewed-by: Alistair Francis <alistair.francis@xilinx.com>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
11
hw/sd/sdhci.c | 6 +++++-
12
1 file changed, 5 insertions(+), 1 deletion(-)
13
14
diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/sd/sdhci.c
17
+++ b/hw/sd/sdhci.c
18
@@ -XXX,XX +XXX,XX @@ sdhci_write(void *opaque, hwaddr offset, uint64_t val, unsigned size)
19
/* Writing to last byte of sdmasysad might trigger transfer */
20
if (!(mask & 0xFF000000) && TRANSFERRING_DATA(s->prnsts) && s->blkcnt &&
21
s->blksize && SDHC_DMA_TYPE(s->hostctl) == SDHC_CTRL_SDMA) {
22
- sdhci_sdma_transfer_multi_blocks(s);
23
+ if (s->trnmod & SDHC_TRNS_MULTI) {
24
+ sdhci_sdma_transfer_multi_blocks(s);
25
+ } else {
26
+ sdhci_sdma_transfer_single_block(s);
27
+ }
28
}
29
break;
30
case SDHC_BLKSIZE:
31
--
32
2.7.4
33
34
diff view generated by jsdifflib
1
From: Nick Reilly <nreilly@blackberry.com>
1
From: "Emilio G. Cota" <cota@braap.org>
2
2
3
The aarch64 crypto instructions for AES and SHA are missing the
3
Fixes the following warning when compiling with gcc 5.4.0 with -O1
4
check for if the FPU is enabled.
4
optimizations and --enable-debug:
5
5
6
Signed-off-by: Nick Reilly <nreilly@blackberry.com>
6
target/arm/translate-a64.c: In function ‘aarch64_tr_translate_insn’:
7
target/arm/translate-a64.c:2361:8: error: ‘post_index’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
8
if (!post_index) {
9
^
10
target/arm/translate-a64.c:2307:10: note: ‘post_index’ was declared here
11
bool post_index;
12
^
13
target/arm/translate-a64.c:2386:8: error: ‘writeback’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
14
if (writeback) {
15
^
16
target/arm/translate-a64.c:2308:10: note: ‘writeback’ was declared here
17
bool writeback;
18
^
19
20
Note that idx comes from selecting 2 bits, and therefore its value
21
can be at most 3.
22
23
Signed-off-by: Emilio G. Cota <cota@braap.org>
24
Acked-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
25
Message-id: 1510087611-1851-1-git-send-email-cota@braap.org
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
26
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
27
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
28
---
10
target/arm/translate-a64.c | 12 ++++++++++++
29
target/arm/translate-a64.c | 2 ++
11
1 file changed, 12 insertions(+)
30
1 file changed, 2 insertions(+)
12
31
13
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
32
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
14
index XXXXXXX..XXXXXXX 100644
33
index XXXXXXX..XXXXXXX 100644
15
--- a/target/arm/translate-a64.c
34
--- a/target/arm/translate-a64.c
16
+++ b/target/arm/translate-a64.c
35
+++ b/target/arm/translate-a64.c
17
@@ -XXX,XX +XXX,XX @@ static void disas_crypto_aes(DisasContext *s, uint32_t insn)
36
@@ -XXX,XX +XXX,XX @@ static void disas_ldst_reg_imm9(DisasContext *s, uint32_t insn,
18
return;
37
post_index = false;
38
writeback = true;
39
break;
40
+ default:
41
+ g_assert_not_reached();
19
}
42
}
20
43
21
+ if (!fp_access_check(s)) {
44
if (rn == 31) {
22
+ return;
23
+ }
24
+
25
/* Note that we convert the Vx register indexes into the
26
* index within the vfp.regs[] array, so we can share the
27
* helper with the AArch32 instructions.
28
@@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha(DisasContext *s, uint32_t insn)
29
return;
30
}
31
32
+ if (!fp_access_check(s)) {
33
+ return;
34
+ }
35
+
36
tcg_rd_regno = tcg_const_i32(rd << 1);
37
tcg_rn_regno = tcg_const_i32(rn << 1);
38
tcg_rm_regno = tcg_const_i32(rm << 1);
39
@@ -XXX,XX +XXX,XX @@ static void disas_crypto_two_reg_sha(DisasContext *s, uint32_t insn)
40
return;
41
}
42
43
+ if (!fp_access_check(s)) {
44
+ return;
45
+ }
46
+
47
tcg_rd_regno = tcg_const_i32(rd << 1);
48
tcg_rn_regno = tcg_const_i32(rn << 1);
49
50
--
45
--
51
2.7.4
46
2.7.4
52
47
53
48
diff view generated by jsdifflib
1
From: Clement Deschamps <clement.deschamps@antfield.fr>
1
From: Prasad J Pandit <pjp@fedoraproject.org>
2
2
3
This adds the BCM2835 SDHost controller from Arasan.
3
An 'offset' parameter sent to highbank register r/w functions
4
could be greater than number(NUM_REGS=0x200) of hb registers,
5
leading to an OOB access issue. Add check to avoid it.
4
6
5
Signed-off-by: Clement Deschamps <clement.deschamps@antfield.fr>
7
Reported-by: Moguofang (Dennis mo) <moguofang@huawei.com>
6
Message-id: 20170224164021.9066-2-clement.deschamps@antfield.fr
8
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
9
Message-id: 20171113062658.9697-1-ppandit@redhat.com
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
10
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
12
---
10
hw/sd/Makefile.objs | 1 +
13
hw/arm/highbank.c | 17 +++++++++++++++--
11
include/hw/sd/bcm2835_sdhost.h | 48 +++++
14
1 file changed, 15 insertions(+), 2 deletions(-)
12
hw/sd/bcm2835_sdhost.c | 429 +++++++++++++++++++++++++++++++++++++++++
13
3 files changed, 478 insertions(+)
14
create mode 100644 include/hw/sd/bcm2835_sdhost.h
15
create mode 100644 hw/sd/bcm2835_sdhost.c
16
15
17
diff --git a/hw/sd/Makefile.objs b/hw/sd/Makefile.objs
16
diff --git a/hw/arm/highbank.c b/hw/arm/highbank.c
18
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
19
--- a/hw/sd/Makefile.objs
18
--- a/hw/arm/highbank.c
20
+++ b/hw/sd/Makefile.objs
19
+++ b/hw/arm/highbank.c
21
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_SDHCI) += sdhci.o
22
obj-$(CONFIG_MILKYMIST) += milkymist-memcard.o
23
obj-$(CONFIG_OMAP) += omap_mmc.o
24
obj-$(CONFIG_PXA2XX) += pxa2xx_mmci.o
25
+obj-$(CONFIG_RASPI) += bcm2835_sdhost.o
26
diff --git a/include/hw/sd/bcm2835_sdhost.h b/include/hw/sd/bcm2835_sdhost.h
27
new file mode 100644
28
index XXXXXXX..XXXXXXX
29
--- /dev/null
30
+++ b/include/hw/sd/bcm2835_sdhost.h
31
@@ -XXX,XX +XXX,XX @@
20
@@ -XXX,XX +XXX,XX @@
32
+/*
21
#include "hw/ide/ahci.h"
33
+ * Raspberry Pi (BCM2835) SD Host Controller
22
#include "hw/cpu/a9mpcore.h"
34
+ *
23
#include "hw/cpu/a15mpcore.h"
35
+ * Copyright (c) 2017 Antfield SAS
36
+ *
37
+ * Authors:
38
+ * Clement Deschamps <clement.deschamps@antfield.fr>
39
+ * Luc Michel <luc.michel@antfield.fr>
40
+ *
41
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
42
+ * See the COPYING file in the top-level directory.
43
+ */
44
+
45
+#ifndef BCM2835_SDHOST_H
46
+#define BCM2835_SDHOST_H
47
+
48
+#include "hw/sysbus.h"
49
+#include "hw/sd/sd.h"
50
+
51
+#define TYPE_BCM2835_SDHOST "bcm2835-sdhost"
52
+#define BCM2835_SDHOST(obj) \
53
+ OBJECT_CHECK(BCM2835SDHostState, (obj), TYPE_BCM2835_SDHOST)
54
+
55
+#define BCM2835_SDHOST_FIFO_LEN 16
56
+
57
+typedef struct {
58
+ SysBusDevice busdev;
59
+ SDBus sdbus;
60
+ MemoryRegion iomem;
61
+
62
+ uint32_t cmd;
63
+ uint32_t cmdarg;
64
+ uint32_t status;
65
+ uint32_t rsp[4];
66
+ uint32_t config;
67
+ uint32_t edm;
68
+ uint32_t vdd;
69
+ uint32_t hbct;
70
+ uint32_t hblc;
71
+ int32_t fifo_pos;
72
+ int32_t fifo_len;
73
+ uint32_t fifo[BCM2835_SDHOST_FIFO_LEN];
74
+ uint32_t datacnt;
75
+
76
+ qemu_irq irq;
77
+} BCM2835SDHostState;
78
+
79
+#endif
80
diff --git a/hw/sd/bcm2835_sdhost.c b/hw/sd/bcm2835_sdhost.c
81
new file mode 100644
82
index XXXXXXX..XXXXXXX
83
--- /dev/null
84
+++ b/hw/sd/bcm2835_sdhost.c
85
@@ -XXX,XX +XXX,XX @@
86
+/*
87
+ * Raspberry Pi (BCM2835) SD Host Controller
88
+ *
89
+ * Copyright (c) 2017 Antfield SAS
90
+ *
91
+ * Authors:
92
+ * Clement Deschamps <clement.deschamps@antfield.fr>
93
+ * Luc Michel <luc.michel@antfield.fr>
94
+ *
95
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
96
+ * See the COPYING file in the top-level directory.
97
+ */
98
+
99
+#include "qemu/osdep.h"
100
+#include "qemu/log.h"
24
+#include "qemu/log.h"
101
+#include "sysemu/blockdev.h"
25
102
+#include "hw/sd/bcm2835_sdhost.h"
26
#define SMP_BOOT_ADDR 0x100
103
+
27
#define SMP_BOOT_REG 0x40
104
+#define TYPE_BCM2835_SDHOST_BUS "bcm2835-sdhost-bus"
28
@@ -XXX,XX +XXX,XX @@ static void hb_regs_write(void *opaque, hwaddr offset,
105
+#define BCM2835_SDHOST_BUS(obj) \
29
}
106
+ OBJECT_CHECK(SDBus, (obj), TYPE_BCM2835_SDHOST_BUS)
30
}
107
+
31
108
+#define SDCMD 0x00 /* Command to SD card - 16 R/W */
32
- regs[offset/4] = value;
109
+#define SDARG 0x04 /* Argument to SD card - 32 R/W */
33
+ if (offset / 4 >= NUM_REGS) {
110
+#define SDTOUT 0x08 /* Start value for timeout counter - 32 R/W */
34
+ qemu_log_mask(LOG_GUEST_ERROR,
111
+#define SDCDIV 0x0c /* Start value for clock divider - 11 R/W */
35
+ "highbank: bad write offset 0x%" HWADDR_PRIx "\n", offset);
112
+#define SDRSP0 0x10 /* SD card rsp (31:0) - 32 R */
113
+#define SDRSP1 0x14 /* SD card rsp (63:32) - 32 R */
114
+#define SDRSP2 0x18 /* SD card rsp (95:64) - 32 R */
115
+#define SDRSP3 0x1c /* SD card rsp (127:96) - 32 R */
116
+#define SDHSTS 0x20 /* SD host status - 11 R */
117
+#define SDVDD 0x30 /* SD card power control - 1 R/W */
118
+#define SDEDM 0x34 /* Emergency Debug Mode - 13 R/W */
119
+#define SDHCFG 0x38 /* Host configuration - 2 R/W */
120
+#define SDHBCT 0x3c /* Host byte count (debug) - 32 R/W */
121
+#define SDDATA 0x40 /* Data to/from SD card - 32 R/W */
122
+#define SDHBLC 0x50 /* Host block count (SDIO/SDHC) - 9 R/W */
123
+
124
+#define SDCMD_NEW_FLAG 0x8000
125
+#define SDCMD_FAIL_FLAG 0x4000
126
+#define SDCMD_BUSYWAIT 0x800
127
+#define SDCMD_NO_RESPONSE 0x400
128
+#define SDCMD_LONG_RESPONSE 0x200
129
+#define SDCMD_WRITE_CMD 0x80
130
+#define SDCMD_READ_CMD 0x40
131
+#define SDCMD_CMD_MASK 0x3f
132
+
133
+#define SDCDIV_MAX_CDIV 0x7ff
134
+
135
+#define SDHSTS_BUSY_IRPT 0x400
136
+#define SDHSTS_BLOCK_IRPT 0x200
137
+#define SDHSTS_SDIO_IRPT 0x100
138
+#define SDHSTS_REW_TIME_OUT 0x80
139
+#define SDHSTS_CMD_TIME_OUT 0x40
140
+#define SDHSTS_CRC16_ERROR 0x20
141
+#define SDHSTS_CRC7_ERROR 0x10
142
+#define SDHSTS_FIFO_ERROR 0x08
143
+/* Reserved */
144
+/* Reserved */
145
+#define SDHSTS_DATA_FLAG 0x01
146
+
147
+#define SDHCFG_BUSY_IRPT_EN (1 << 10)
148
+#define SDHCFG_BLOCK_IRPT_EN (1 << 8)
149
+#define SDHCFG_SDIO_IRPT_EN (1 << 5)
150
+#define SDHCFG_DATA_IRPT_EN (1 << 4)
151
+#define SDHCFG_SLOW_CARD (1 << 3)
152
+#define SDHCFG_WIDE_EXT_BUS (1 << 2)
153
+#define SDHCFG_WIDE_INT_BUS (1 << 1)
154
+#define SDHCFG_REL_CMD_LINE (1 << 0)
155
+
156
+#define SDEDM_FORCE_DATA_MODE (1 << 19)
157
+#define SDEDM_CLOCK_PULSE (1 << 20)
158
+#define SDEDM_BYPASS (1 << 21)
159
+
160
+#define SDEDM_WRITE_THRESHOLD_SHIFT 9
161
+#define SDEDM_READ_THRESHOLD_SHIFT 14
162
+#define SDEDM_THRESHOLD_MASK 0x1f
163
+
164
+#define SDEDM_FSM_MASK 0xf
165
+#define SDEDM_FSM_IDENTMODE 0x0
166
+#define SDEDM_FSM_DATAMODE 0x1
167
+#define SDEDM_FSM_READDATA 0x2
168
+#define SDEDM_FSM_WRITEDATA 0x3
169
+#define SDEDM_FSM_READWAIT 0x4
170
+#define SDEDM_FSM_READCRC 0x5
171
+#define SDEDM_FSM_WRITECRC 0x6
172
+#define SDEDM_FSM_WRITEWAIT1 0x7
173
+#define SDEDM_FSM_POWERDOWN 0x8
174
+#define SDEDM_FSM_POWERUP 0x9
175
+#define SDEDM_FSM_WRITESTART1 0xa
176
+#define SDEDM_FSM_WRITESTART2 0xb
177
+#define SDEDM_FSM_GENPULSES 0xc
178
+#define SDEDM_FSM_WRITEWAIT2 0xd
179
+#define SDEDM_FSM_STARTPOWDOWN 0xf
180
+
181
+#define SDDATA_FIFO_WORDS 16
182
+
183
+static void bcm2835_sdhost_update_irq(BCM2835SDHostState *s)
184
+{
185
+ uint32_t irq = s->status &
186
+ (SDHSTS_BUSY_IRPT | SDHSTS_BLOCK_IRPT | SDHSTS_SDIO_IRPT);
187
+ qemu_set_irq(s->irq, !!irq);
188
+}
189
+
190
+static void bcm2835_sdhost_send_command(BCM2835SDHostState *s)
191
+{
192
+ SDRequest request;
193
+ uint8_t rsp[16];
194
+ int rlen;
195
+
196
+ request.cmd = s->cmd & SDCMD_CMD_MASK;
197
+ request.arg = s->cmdarg;
198
+
199
+ rlen = sdbus_do_command(&s->sdbus, &request, rsp);
200
+ if (rlen < 0) {
201
+ goto error;
202
+ }
203
+ if (!(s->cmd & SDCMD_NO_RESPONSE)) {
204
+#define RWORD(n) (((uint32_t)rsp[n] << 24) | (rsp[n + 1] << 16) \
205
+ | (rsp[n + 2] << 8) | rsp[n + 3])
206
+ if (rlen == 0 || (rlen == 4 && (s->cmd & SDCMD_LONG_RESPONSE))) {
207
+ goto error;
208
+ }
209
+ if (rlen != 4 && rlen != 16) {
210
+ goto error;
211
+ }
212
+ if (rlen == 4) {
213
+ s->rsp[0] = RWORD(0);
214
+ s->rsp[1] = s->rsp[2] = s->rsp[3] = 0;
215
+ } else {
216
+ s->rsp[0] = RWORD(12);
217
+ s->rsp[1] = RWORD(8);
218
+ s->rsp[2] = RWORD(4);
219
+ s->rsp[3] = RWORD(0);
220
+ }
221
+#undef RWORD
222
+ }
223
+ return;
224
+
225
+error:
226
+ s->cmd |= SDCMD_FAIL_FLAG;
227
+ s->status |= SDHSTS_CMD_TIME_OUT;
228
+}
229
+
230
+static void bcm2835_sdhost_fifo_push(BCM2835SDHostState *s, uint32_t value)
231
+{
232
+ int n;
233
+
234
+ if (s->fifo_len == BCM2835_SDHOST_FIFO_LEN) {
235
+ /* FIFO overflow */
236
+ return;
36
+ return;
237
+ }
37
+ }
238
+ n = (s->fifo_pos + s->fifo_len) & (BCM2835_SDHOST_FIFO_LEN - 1);
38
+ regs[offset / 4] = value;
239
+ s->fifo_len++;
39
}
240
+ s->fifo[n] = value;
40
241
+}
41
static uint64_t hb_regs_read(void *opaque, hwaddr offset,
42
unsigned size)
43
{
44
+ uint32_t value;
45
uint32_t *regs = opaque;
46
- uint32_t value = regs[offset/4];
242
+
47
+
243
+static uint32_t bcm2835_sdhost_fifo_pop(BCM2835SDHostState *s)
48
+ if (offset / 4 >= NUM_REGS) {
244
+{
49
+ qemu_log_mask(LOG_GUEST_ERROR,
245
+ uint32_t value;
50
+ "highbank: bad read offset 0x%" HWADDR_PRIx "\n", offset);
246
+
247
+ if (s->fifo_len == 0) {
248
+ /* FIFO underflow */
249
+ return 0;
51
+ return 0;
250
+ }
52
+ }
251
+ value = s->fifo[s->fifo_pos];
53
+ value = regs[offset / 4];
252
+ s->fifo_len--;
54
253
+ s->fifo_pos = (s->fifo_pos + 1) & (BCM2835_SDHOST_FIFO_LEN - 1);
55
if ((offset == 0x100) || (offset == 0x108) || (offset == 0x10C)) {
254
+ return value;
56
value |= 0x30000000;
255
+}
256
+
257
+static void bcm2835_sdhost_fifo_run(BCM2835SDHostState *s)
258
+{
259
+ uint32_t value = 0;
260
+ int n;
261
+ int is_read;
262
+
263
+ is_read = (s->cmd & SDCMD_READ_CMD) != 0;
264
+ if (s->datacnt != 0 && (!is_read || sdbus_data_ready(&s->sdbus))) {
265
+ if (is_read) {
266
+ n = 0;
267
+ while (s->datacnt && s->fifo_len < BCM2835_SDHOST_FIFO_LEN) {
268
+ value |= (uint32_t)sdbus_read_data(&s->sdbus) << (n * 8);
269
+ s->datacnt--;
270
+ n++;
271
+ if (n == 4) {
272
+ bcm2835_sdhost_fifo_push(s, value);
273
+ n = 0;
274
+ value = 0;
275
+ }
276
+ }
277
+ if (n != 0) {
278
+ bcm2835_sdhost_fifo_push(s, value);
279
+ }
280
+ } else { /* write */
281
+ n = 0;
282
+ while (s->datacnt > 0 && (s->fifo_len > 0 || n > 0)) {
283
+ if (n == 0) {
284
+ value = bcm2835_sdhost_fifo_pop(s);
285
+ n = 4;
286
+ }
287
+ n--;
288
+ s->datacnt--;
289
+ sdbus_write_data(&s->sdbus, value & 0xff);
290
+ value >>= 8;
291
+ }
292
+ }
293
+ }
294
+ if (s->datacnt == 0) {
295
+ s->status |= SDHSTS_DATA_FLAG;
296
+
297
+ s->edm &= ~0xf;
298
+ s->edm |= SDEDM_FSM_DATAMODE;
299
+
300
+ if (s->config & SDHCFG_DATA_IRPT_EN) {
301
+ s->status |= SDHSTS_SDIO_IRPT;
302
+ }
303
+
304
+ if ((s->cmd & SDCMD_BUSYWAIT) && (s->config & SDHCFG_BUSY_IRPT_EN)) {
305
+ s->status |= SDHSTS_BUSY_IRPT;
306
+ }
307
+
308
+ if ((s->cmd & SDCMD_WRITE_CMD) && (s->config & SDHCFG_BLOCK_IRPT_EN)) {
309
+ s->status |= SDHSTS_BLOCK_IRPT;
310
+ }
311
+
312
+ bcm2835_sdhost_update_irq(s);
313
+ }
314
+
315
+ s->edm &= ~(0x1f << 4);
316
+ s->edm |= ((s->fifo_len & 0x1f) << 4);
317
+}
318
+
319
+static uint64_t bcm2835_sdhost_read(void *opaque, hwaddr offset,
320
+ unsigned size)
321
+{
322
+ BCM2835SDHostState *s = (BCM2835SDHostState *)opaque;
323
+ uint32_t res = 0;
324
+
325
+ switch (offset) {
326
+ case SDCMD:
327
+ res = s->cmd;
328
+ break;
329
+ case SDHSTS:
330
+ res = s->status;
331
+ break;
332
+ case SDRSP0:
333
+ res = s->rsp[0];
334
+ break;
335
+ case SDRSP1:
336
+ res = s->rsp[1];
337
+ break;
338
+ case SDRSP2:
339
+ res = s->rsp[2];
340
+ break;
341
+ case SDRSP3:
342
+ res = s->rsp[3];
343
+ break;
344
+ case SDEDM:
345
+ res = s->edm;
346
+ break;
347
+ case SDVDD:
348
+ res = s->vdd;
349
+ break;
350
+ case SDDATA:
351
+ res = bcm2835_sdhost_fifo_pop(s);
352
+ bcm2835_sdhost_fifo_run(s);
353
+ break;
354
+ case SDHBCT:
355
+ res = s->hbct;
356
+ break;
357
+ case SDHBLC:
358
+ res = s->hblc;
359
+ break;
360
+
361
+ default:
362
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset %"HWADDR_PRIx"\n",
363
+ __func__, offset);
364
+ res = 0;
365
+ break;
366
+ }
367
+
368
+ return res;
369
+}
370
+
371
+static void bcm2835_sdhost_write(void *opaque, hwaddr offset,
372
+ uint64_t value, unsigned size)
373
+{
374
+ BCM2835SDHostState *s = (BCM2835SDHostState *)opaque;
375
+
376
+ switch (offset) {
377
+ case SDCMD:
378
+ s->cmd = value;
379
+ if (value & SDCMD_NEW_FLAG) {
380
+ bcm2835_sdhost_send_command(s);
381
+ bcm2835_sdhost_fifo_run(s);
382
+ s->cmd &= ~SDCMD_NEW_FLAG;
383
+ }
384
+ break;
385
+ case SDTOUT:
386
+ break;
387
+ case SDCDIV:
388
+ break;
389
+ case SDHSTS:
390
+ s->status &= ~value;
391
+ bcm2835_sdhost_update_irq(s);
392
+ break;
393
+ case SDARG:
394
+ s->cmdarg = value;
395
+ break;
396
+ case SDEDM:
397
+ if ((value & 0xf) == 0xf) {
398
+ /* power down */
399
+ value &= ~0xf;
400
+ }
401
+ s->edm = value;
402
+ break;
403
+ case SDHCFG:
404
+ s->config = value;
405
+ bcm2835_sdhost_fifo_run(s);
406
+ break;
407
+ case SDVDD:
408
+ s->vdd = value;
409
+ break;
410
+ case SDDATA:
411
+ bcm2835_sdhost_fifo_push(s, value);
412
+ bcm2835_sdhost_fifo_run(s);
413
+ break;
414
+ case SDHBCT:
415
+ s->hbct = value;
416
+ break;
417
+ case SDHBLC:
418
+ s->hblc = value;
419
+ s->datacnt = s->hblc * s->hbct;
420
+ bcm2835_sdhost_fifo_run(s);
421
+ break;
422
+
423
+ default:
424
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset %"HWADDR_PRIx"\n",
425
+ __func__, offset);
426
+ break;
427
+ }
428
+}
429
+
430
+static const MemoryRegionOps bcm2835_sdhost_ops = {
431
+ .read = bcm2835_sdhost_read,
432
+ .write = bcm2835_sdhost_write,
433
+ .endianness = DEVICE_NATIVE_ENDIAN,
434
+};
435
+
436
+static const VMStateDescription vmstate_bcm2835_sdhost = {
437
+ .name = TYPE_BCM2835_SDHOST,
438
+ .version_id = 1,
439
+ .minimum_version_id = 1,
440
+ .fields = (VMStateField[]) {
441
+ VMSTATE_UINT32(cmd, BCM2835SDHostState),
442
+ VMSTATE_UINT32(cmdarg, BCM2835SDHostState),
443
+ VMSTATE_UINT32(status, BCM2835SDHostState),
444
+ VMSTATE_UINT32_ARRAY(rsp, BCM2835SDHostState, 4),
445
+ VMSTATE_UINT32(config, BCM2835SDHostState),
446
+ VMSTATE_UINT32(edm, BCM2835SDHostState),
447
+ VMSTATE_UINT32(vdd, BCM2835SDHostState),
448
+ VMSTATE_UINT32(hbct, BCM2835SDHostState),
449
+ VMSTATE_UINT32(hblc, BCM2835SDHostState),
450
+ VMSTATE_INT32(fifo_pos, BCM2835SDHostState),
451
+ VMSTATE_INT32(fifo_len, BCM2835SDHostState),
452
+ VMSTATE_UINT32_ARRAY(fifo, BCM2835SDHostState, BCM2835_SDHOST_FIFO_LEN),
453
+ VMSTATE_UINT32(datacnt, BCM2835SDHostState),
454
+ VMSTATE_END_OF_LIST()
455
+ }
456
+};
457
+
458
+static void bcm2835_sdhost_init(Object *obj)
459
+{
460
+ BCM2835SDHostState *s = BCM2835_SDHOST(obj);
461
+
462
+ qbus_create_inplace(&s->sdbus, sizeof(s->sdbus),
463
+ TYPE_BCM2835_SDHOST_BUS, DEVICE(s), "sd-bus");
464
+
465
+ memory_region_init_io(&s->iomem, obj, &bcm2835_sdhost_ops, s,
466
+ TYPE_BCM2835_SDHOST, 0x1000);
467
+ sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem);
468
+ sysbus_init_irq(SYS_BUS_DEVICE(s), &s->irq);
469
+}
470
+
471
+static void bcm2835_sdhost_reset(DeviceState *dev)
472
+{
473
+ BCM2835SDHostState *s = BCM2835_SDHOST(dev);
474
+
475
+ s->cmd = 0;
476
+ s->cmdarg = 0;
477
+ s->edm = 0x0000c60f;
478
+ s->config = 0;
479
+ s->hbct = 0;
480
+ s->hblc = 0;
481
+ s->datacnt = 0;
482
+ s->fifo_pos = 0;
483
+ s->fifo_len = 0;
484
+}
485
+
486
+static void bcm2835_sdhost_class_init(ObjectClass *klass, void *data)
487
+{
488
+ DeviceClass *dc = DEVICE_CLASS(klass);
489
+
490
+ dc->reset = bcm2835_sdhost_reset;
491
+ dc->vmsd = &vmstate_bcm2835_sdhost;
492
+}
493
+
494
+static TypeInfo bcm2835_sdhost_info = {
495
+ .name = TYPE_BCM2835_SDHOST,
496
+ .parent = TYPE_SYS_BUS_DEVICE,
497
+ .instance_size = sizeof(BCM2835SDHostState),
498
+ .class_init = bcm2835_sdhost_class_init,
499
+ .instance_init = bcm2835_sdhost_init,
500
+};
501
+
502
+static const TypeInfo bcm2835_sdhost_bus_info = {
503
+ .name = TYPE_BCM2835_SDHOST_BUS,
504
+ .parent = TYPE_SD_BUS,
505
+ .instance_size = sizeof(SDBus),
506
+};
507
+
508
+static void bcm2835_sdhost_register_types(void)
509
+{
510
+ type_register_static(&bcm2835_sdhost_info);
511
+ type_register_static(&bcm2835_sdhost_bus_info);
512
+}
513
+
514
+type_init(bcm2835_sdhost_register_types)
515
--
57
--
516
2.7.4
58
2.7.4
517
59
518
60
diff view generated by jsdifflib
1
From: Krzysztof Kozlowski <krzk@kernel.org>
1
From: Subbaraya Sundeep <sundeep.lkml@gmail.com>
2
2
3
The Exynos4210 has cluster ID 0x9 in its MPIDR register (raw value
3
Voluntarily add myself as maintainer for Smartfusion2
4
0x8000090x). If this cluster ID is not provided, then Linux kernel
5
cannot map DeviceTree nodes to MPIDR values resulting in kernel
6
warning and lack of any secondary CPUs:
7
4
8
DT missing boot CPU MPIDR[23:0], fall back to default cpu_logical_map
5
Signed-off-by: Subbaraya Sundeep <sundeep.lkml@gmail.com>
9
...
6
Reviewed-by: Alistair Francis <alistair.francis@xilinx.com>
10
smp: Bringing up secondary CPUs ...
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
11
smp: Brought up 1 node, 1 CPU
8
Message-id: 1510552520-3566-1-git-send-email-sundeep.lkml@gmail.com
12
SMP: Total of 1 processors activated (24.00 BogoMIPS).
13
14
Provide a cluster ID so Linux will see proper MPIDR and will try to
15
bring the secondary CPU online.
16
17
Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
18
Message-id: 20170226200142.31169-2-krzk@kernel.org
19
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
20
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
21
---
10
---
22
hw/arm/exynos4210.c | 12 ++++++++++++
11
MAINTAINERS | 17 +++++++++++++++++
23
1 file changed, 12 insertions(+)
12
1 file changed, 17 insertions(+)
24
13
25
diff --git a/hw/arm/exynos4210.c b/hw/arm/exynos4210.c
14
diff --git a/MAINTAINERS b/MAINTAINERS
26
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
27
--- a/hw/arm/exynos4210.c
16
--- a/MAINTAINERS
28
+++ b/hw/arm/exynos4210.c
17
+++ b/MAINTAINERS
29
@@ -XXX,XX +XXX,XX @@ void exynos4210_write_secondary(ARMCPU *cpu,
18
@@ -XXX,XX +XXX,XX @@ M: Alistair Francis <alistair@alistair23.me>
30
info->smp_loader_start);
19
S: Maintained
31
}
20
F: hw/arm/netduino2.c
32
21
33
+static uint64_t exynos4210_calc_affinity(int cpu)
22
+SmartFusion2
34
+{
23
+M: Subbaraya Sundeep <sundeep.lkml@gmail.com>
35
+ uint64_t mp_affinity;
24
+S: Maintained
25
+F: hw/arm/msf2-soc.c
26
+F: hw/misc/msf2-sysreg.c
27
+F: hw/timer/mss-timer.c
28
+F: hw/ssi/mss-spi.c
29
+F: include/hw/arm/msf2-soc.h
30
+F: include/hw/misc/msf2-sysreg.h
31
+F: include/hw/timer/mss-timer.h
32
+F: include/hw/ssi/mss-spi.h
36
+
33
+
37
+ /* Exynos4210 has 0x9 as cluster ID */
34
+Emcraft M2S-FG484
38
+ mp_affinity = (0x9 << ARM_AFF1_SHIFT) | cpu;
35
+M: Subbaraya Sundeep <sundeep.lkml@gmail.com>
36
+S: Maintained
37
+F: hw/arm/msf2-som.c
39
+
38
+
40
+ return mp_affinity;
39
CRIS Machines
41
+}
40
-------------
42
+
41
Axis Dev88
43
Exynos4210State *exynos4210_init(MemoryRegion *system_mem,
44
unsigned long ram_size)
45
{
46
@@ -XXX,XX +XXX,XX @@ Exynos4210State *exynos4210_init(MemoryRegion *system_mem,
47
}
48
49
s->cpu[n] = ARM_CPU(cpuobj);
50
+ object_property_set_int(cpuobj, exynos4210_calc_affinity(n),
51
+ "mp-affinity", &error_abort);
52
object_property_set_int(cpuobj, EXYNOS4210_SMP_PRIVATE_BASE_ADDR,
53
"reset-cbar", &error_abort);
54
object_property_set_bool(cpuobj, true, "realized", &error_fatal);
55
--
42
--
56
2.7.4
43
2.7.4
57
44
58
45
diff view generated by jsdifflib
1
From: Clement Deschamps <clement.deschamps@antfield.fr>
1
From: "Emilio G. Cota" <cota@braap.org>
2
2
3
This adds the bcm2835_sdhost and bcm2835_gpio to the BCM2835 platform.
3
55c3cee ("qom: Introduce CPUClass.tcg_initialize", 2017-10-24)
4
introduces a per-CPUClass bool that we check so that the target CPU
5
is initialized for TCG only once. This works well except when
6
we end up creating more than one CPUClass, in which case we end
7
up incorrectly initializing TCG more than once, i.e. once for
8
each CPUClass.
4
9
5
For supporting the SD controller selection (alternate function of GPIOs
10
This can be replicated with:
6
48-53), the bcm2835_gpio now exposes an sdbus.
11
$ aarch64-softmmu/qemu-system-aarch64 -machine xlnx-zcu102 -smp 6 \
7
It also has a link to both the sdbus of sdhci and sdhost controllers,
12
-global driver=xlnx,,zynqmp,property=has_rpu,value=on
8
and the card is reparented from one bus to another when the alternate
13
In this case the class name of the "RPUs" is prefixed by "cortex-r5-",
9
function of GPIOs 48-53 is modified.
14
whereas the "regular" CPUs are prefixed by "cortex-a53-". This
15
results in two CPUClass instances being created.
10
16
11
Signed-off-by: Clement Deschamps <clement.deschamps@antfield.fr>
17
Fix it by introducing a static variable, so that only the first
12
Message-id: 20170224164021.9066-5-clement.deschamps@antfield.fr
18
target CPU being initialized will initialize the target-dependent
13
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
19
part of TCG, regardless of CPUClass instances.
20
21
Fixes: 55c3ceef61fcf06fc98ddc752b7cce788ce7680b
22
Signed-off-by: Emilio G. Cota <cota@braap.org>
23
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
24
Reviewed-by: Alistair Francis <alistair.francis@xilinx.com>
25
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
26
Tested-by: Alistair Francis <alistair.francis@xilinx.com>
27
Message-id: 1510343626-25861-2-git-send-email-cota@braap.org
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
28
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
---
29
---
16
include/hw/arm/bcm2835_peripherals.h | 4 ++++
30
include/qom/cpu.h | 1 -
17
hw/arm/bcm2835_peripherals.c | 43 ++++++++++++++++++++++++++++++++++--
31
exec.c | 5 +++--
18
2 files changed, 45 insertions(+), 2 deletions(-)
32
2 files changed, 3 insertions(+), 3 deletions(-)
19
33
20
diff --git a/include/hw/arm/bcm2835_peripherals.h b/include/hw/arm/bcm2835_peripherals.h
34
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
21
index XXXXXXX..XXXXXXX 100644
35
index XXXXXXX..XXXXXXX 100644
22
--- a/include/hw/arm/bcm2835_peripherals.h
36
--- a/include/qom/cpu.h
23
+++ b/include/hw/arm/bcm2835_peripherals.h
37
+++ b/include/qom/cpu.h
24
@@ -XXX,XX +XXX,XX @@
38
@@ -XXX,XX +XXX,XX @@ typedef struct CPUClass {
25
#include "hw/misc/bcm2835_rng.h"
39
/* Keep non-pointer data at the end to minimize holes. */
26
#include "hw/misc/bcm2835_mbox.h"
40
int gdb_num_core_regs;
27
#include "hw/sd/sdhci.h"
41
bool gdb_stop_before_watchpoint;
28
+#include "hw/sd/bcm2835_sdhost.h"
42
- bool tcg_initialized;
29
+#include "hw/gpio/bcm2835_gpio.h"
43
} CPUClass;
30
44
31
#define TYPE_BCM2835_PERIPHERALS "bcm2835-peripherals"
45
#ifdef HOST_WORDS_BIGENDIAN
32
#define BCM2835_PERIPHERALS(obj) \
46
diff --git a/exec.c b/exec.c
33
@@ -XXX,XX +XXX,XX @@ typedef struct BCM2835PeripheralState {
34
BCM2835RngState rng;
35
BCM2835MboxState mboxes;
36
SDHCIState sdhci;
37
+ BCM2835SDHostState sdhost;
38
+ BCM2835GpioState gpio;
39
} BCM2835PeripheralState;
40
41
#endif /* BCM2835_PERIPHERALS_H */
42
diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c
43
index XXXXXXX..XXXXXXX 100644
47
index XXXXXXX..XXXXXXX 100644
44
--- a/hw/arm/bcm2835_peripherals.c
48
--- a/exec.c
45
+++ b/hw/arm/bcm2835_peripherals.c
49
+++ b/exec.c
46
@@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_init(Object *obj)
50
@@ -XXX,XX +XXX,XX @@ void cpu_exec_initfn(CPUState *cpu)
47
object_property_add_child(obj, "sdhci", OBJECT(&s->sdhci), NULL);
51
void cpu_exec_realizefn(CPUState *cpu, Error **errp)
48
qdev_set_parent_bus(DEVICE(&s->sdhci), sysbus_get_default());
52
{
49
53
CPUClass *cc = CPU_GET_CLASS(cpu);
50
+ /* SDHOST */
54
+ static bool tcg_target_initialized;
51
+ object_initialize(&s->sdhost, sizeof(s->sdhost), TYPE_BCM2835_SDHOST);
55
52
+ object_property_add_child(obj, "sdhost", OBJECT(&s->sdhost), NULL);
56
cpu_list_add(cpu);
53
+ qdev_set_parent_bus(DEVICE(&s->sdhost), sysbus_get_default());
57
54
+
58
- if (tcg_enabled() && !cc->tcg_initialized) {
55
/* DMA Channels */
59
- cc->tcg_initialized = true;
56
object_initialize(&s->dma, sizeof(s->dma), TYPE_BCM2835_DMA);
60
+ if (tcg_enabled() && !tcg_target_initialized) {
57
object_property_add_child(obj, "dma", OBJECT(&s->dma), NULL);
61
+ tcg_target_initialized = true;
58
@@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_init(Object *obj)
62
cc->tcg_initialize();
59
60
object_property_add_const_link(OBJECT(&s->dma), "dma-mr",
61
OBJECT(&s->gpu_bus_mr), &error_abort);
62
+
63
+ /* GPIO */
64
+ object_initialize(&s->gpio, sizeof(s->gpio), TYPE_BCM2835_GPIO);
65
+ object_property_add_child(obj, "gpio", OBJECT(&s->gpio), NULL);
66
+ qdev_set_parent_bus(DEVICE(&s->gpio), sysbus_get_default());
67
+
68
+ object_property_add_const_link(OBJECT(&s->gpio), "sdbus-sdhci",
69
+ OBJECT(&s->sdhci.sdbus), &error_abort);
70
+ object_property_add_const_link(OBJECT(&s->gpio), "sdbus-sdhost",
71
+ OBJECT(&s->sdhost.sdbus), &error_abort);
72
}
73
74
static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
75
@@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
76
sysbus_connect_irq(SYS_BUS_DEVICE(&s->sdhci), 0,
77
qdev_get_gpio_in_named(DEVICE(&s->ic), BCM2835_IC_GPU_IRQ,
78
INTERRUPT_ARASANSDIO));
79
- object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->sdhci), "sd-bus",
80
- &err);
81
+
82
+ /* SDHOST */
83
+ object_property_set_bool(OBJECT(&s->sdhost), true, "realized", &err);
84
if (err) {
85
error_propagate(errp, err);
86
return;
87
}
63
}
88
64
89
+ memory_region_add_subregion(&s->peri_mr, MMCI0_OFFSET,
90
+ sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->sdhost), 0));
91
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->sdhost), 0,
92
+ qdev_get_gpio_in_named(DEVICE(&s->ic), BCM2835_IC_GPU_IRQ,
93
+ INTERRUPT_SDIO));
94
+
95
/* DMA Channels */
96
object_property_set_bool(OBJECT(&s->dma), true, "realized", &err);
97
if (err) {
98
@@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
99
BCM2835_IC_GPU_IRQ,
100
INTERRUPT_DMA0 + n));
101
}
102
+
103
+ /* GPIO */
104
+ object_property_set_bool(OBJECT(&s->gpio), true, "realized", &err);
105
+ if (err) {
106
+ error_propagate(errp, err);
107
+ return;
108
+ }
109
+
110
+ memory_region_add_subregion(&s->peri_mr, GPIO_OFFSET,
111
+ sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->gpio), 0));
112
+
113
+ object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->gpio), "sd-bus",
114
+ &err);
115
+ if (err) {
116
+ error_propagate(errp, err);
117
+ return;
118
+ }
119
}
120
121
static void bcm2835_peripherals_class_init(ObjectClass *oc, void *data)
122
--
65
--
123
2.7.4
66
2.7.4
124
67
125
68
diff view generated by jsdifflib
1
Implement the exception return consistency checks
1
From: Alistair Francis <alistair.francis@xilinx.com>
2
described in the v7M pseudocode ExceptionReturn().
3
2
4
Inspired by a patch from Michael Davidsaver's series, but
3
Allow the -smp command line option to control the number of CPUs we
5
this is a reimplementation from scratch based on the
4
create.
6
ARM ARM pseudocode.
7
5
6
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
7
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
8
Reviewed-by: Emilio G. Cota <cota@braap.org>
9
Tested-by: Emilio G. Cota <cota@braap.org>
10
Message-id: 1510343626-25861-3-git-send-email-cota@braap.org
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
10
---
12
---
11
target/arm/cpu.h | 12 +++++-
13
hw/arm/xlnx-zcu102.c | 3 ++-
12
hw/intc/armv7m_nvic.c | 12 +++++-
14
hw/arm/xlnx-zynqmp.c | 26 ++++++++++++++++----------
13
target/arm/helper.c | 112 +++++++++++++++++++++++++++++++++++++++++++++-----
15
2 files changed, 18 insertions(+), 11 deletions(-)
14
3 files changed, 123 insertions(+), 13 deletions(-)
15
16
16
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
17
diff --git a/hw/arm/xlnx-zcu102.c b/hw/arm/xlnx-zcu102.c
17
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
18
--- a/target/arm/cpu.h
19
--- a/hw/arm/xlnx-zcu102.c
19
+++ b/target/arm/cpu.h
20
+++ b/hw/arm/xlnx-zcu102.c
20
@@ -XXX,XX +XXX,XX @@ static inline bool armv7m_nvic_can_take_pending_exception(void *opaque)
21
@@ -XXX,XX +XXX,XX @@ static void xlnx_zcu102_machine_class_init(ObjectClass *oc, void *data)
21
#endif
22
{
22
void armv7m_nvic_set_pending(void *opaque, int irq);
23
MachineClass *mc = MACHINE_CLASS(oc);
23
void armv7m_nvic_acknowledge_irq(void *opaque);
24
24
-void armv7m_nvic_complete_irq(void *opaque, int irq);
25
- mc->desc = "Xilinx ZynqMP ZCU102 board";
25
+/**
26
+ mc->desc = "Xilinx ZynqMP ZCU102 board with 4xA53s and 2xR5s based on " \
26
+ * armv7m_nvic_complete_irq: complete specified interrupt or exception
27
+ "the value of smp";
27
+ * @opaque: the NVIC
28
mc->init = xlnx_zcu102_init;
28
+ * @irq: the exception number to complete
29
mc->block_default_type = IF_IDE;
29
+ *
30
mc->units_per_default_bus = 1;
30
+ * Returns: -1 if the irq was not active
31
diff --git a/hw/arm/xlnx-zynqmp.c b/hw/arm/xlnx-zynqmp.c
31
+ * 1 if completing this irq brought us back to base (no active irqs)
32
+ * 0 if there is still an irq active after this one was completed
33
+ * (Ignoring -1, this is the same as the RETTOBASE value before completion.)
34
+ */
35
+int armv7m_nvic_complete_irq(void *opaque, int irq);
36
37
/* Interface for defining coprocessor registers.
38
* Registers are defined in tables of arm_cp_reginfo structs
39
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
40
index XXXXXXX..XXXXXXX 100644
32
index XXXXXXX..XXXXXXX 100644
41
--- a/hw/intc/armv7m_nvic.c
33
--- a/hw/arm/xlnx-zynqmp.c
42
+++ b/hw/intc/armv7m_nvic.c
34
+++ b/hw/arm/xlnx-zynqmp.c
43
@@ -XXX,XX +XXX,XX @@ void armv7m_nvic_acknowledge_irq(void *opaque)
35
@@ -XXX,XX +XXX,XX @@ static void xlnx_zynqmp_create_rpu(XlnxZynqMPState *s, const char *boot_cpu,
44
nvic_irq_update(s);
45
}
46
47
-void armv7m_nvic_complete_irq(void *opaque, int irq)
48
+int armv7m_nvic_complete_irq(void *opaque, int irq)
49
{
36
{
50
NVICState *s = (NVICState *)opaque;
37
Error *err = NULL;
51
VecInfo *vec;
38
int i;
52
+ int ret;
39
+ int num_rpus = MIN(smp_cpus - XLNX_ZYNQMP_NUM_APU_CPUS, XLNX_ZYNQMP_NUM_RPU_CPUS);
53
40
54
assert(irq > ARMV7M_EXCP_RESET && irq < s->num_irq);
41
- for (i = 0; i < XLNX_ZYNQMP_NUM_RPU_CPUS; i++) {
55
42
+ for (i = 0; i < num_rpus; i++) {
56
@@ -XXX,XX +XXX,XX @@ void armv7m_nvic_complete_irq(void *opaque, int irq)
43
char *name;
57
44
58
trace_nvic_complete_irq(irq);
45
object_initialize(&s->rpu_cpu[i], sizeof(s->rpu_cpu[i]),
59
46
@@ -XXX,XX +XXX,XX @@ static void xlnx_zynqmp_init(Object *obj)
60
+ if (!vec->active) {
47
{
61
+ /* Tell the caller this was an illegal exception return */
48
XlnxZynqMPState *s = XLNX_ZYNQMP(obj);
62
+ return -1;
49
int i;
50
+ int num_apus = MIN(smp_cpus, XLNX_ZYNQMP_NUM_APU_CPUS);
51
52
- for (i = 0; i < XLNX_ZYNQMP_NUM_APU_CPUS; i++) {
53
+ for (i = 0; i < num_apus; i++) {
54
object_initialize(&s->apu_cpu[i], sizeof(s->apu_cpu[i]),
55
"cortex-a53-" TYPE_ARM_CPU);
56
object_property_add_child(obj, "apu-cpu[*]", OBJECT(&s->apu_cpu[i]),
57
@@ -XXX,XX +XXX,XX @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
58
MemoryRegion *system_memory = get_system_memory();
59
uint8_t i;
60
uint64_t ram_size;
61
+ int num_apus = MIN(smp_cpus, XLNX_ZYNQMP_NUM_APU_CPUS);
62
const char *boot_cpu = s->boot_cpu ? s->boot_cpu : "apu-cpu[0]";
63
ram_addr_t ddr_low_size, ddr_high_size;
64
qemu_irq gic_spi[GIC_NUM_SPI_INTR];
65
@@ -XXX,XX +XXX,XX @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
66
67
qdev_prop_set_uint32(DEVICE(&s->gic), "num-irq", GIC_NUM_SPI_INTR + 32);
68
qdev_prop_set_uint32(DEVICE(&s->gic), "revision", 2);
69
- qdev_prop_set_uint32(DEVICE(&s->gic), "num-cpu", XLNX_ZYNQMP_NUM_APU_CPUS);
70
+ qdev_prop_set_uint32(DEVICE(&s->gic), "num-cpu", num_apus);
71
72
/* Realize APUs before realizing the GIC. KVM requires this. */
73
- for (i = 0; i < XLNX_ZYNQMP_NUM_APU_CPUS; i++) {
74
+ for (i = 0; i < num_apus; i++) {
75
char *name;
76
77
object_property_set_int(OBJECT(&s->apu_cpu[i]), QEMU_PSCI_CONDUIT_SMC,
78
@@ -XXX,XX +XXX,XX @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
79
}
80
}
81
82
- for (i = 0; i < XLNX_ZYNQMP_NUM_APU_CPUS; i++) {
83
+ for (i = 0; i < num_apus; i++) {
84
qemu_irq irq;
85
86
sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i,
87
@@ -XXX,XX +XXX,XX @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)
88
}
89
90
if (s->has_rpu) {
91
- xlnx_zynqmp_create_rpu(s, boot_cpu, &err);
92
- if (err) {
93
- error_propagate(errp, err);
94
- return;
95
- }
96
+ info_report("The 'has_rpu' property is no longer required, to use the "
97
+ "RPUs just use -smp 6.");
63
+ }
98
+ }
64
+
99
+
65
+ ret = nvic_rettobase(s);
100
+ xlnx_zynqmp_create_rpu(s, boot_cpu, &err);
66
+
101
+ if (err) {
67
vec->active = 0;
102
+ error_propagate(errp, err);
68
if (vec->level) {
69
/* Re-pend the exception if it's still held high; only
70
@@ -XXX,XX +XXX,XX @@ void armv7m_nvic_complete_irq(void *opaque, int irq)
71
}
72
73
nvic_irq_update(s);
74
+
75
+ return ret;
76
}
77
78
/* callback when external interrupt line is changed */
79
diff --git a/target/arm/helper.c b/target/arm/helper.c
80
index XXXXXXX..XXXXXXX 100644
81
--- a/target/arm/helper.c
82
+++ b/target/arm/helper.c
83
@@ -XXX,XX +XXX,XX @@ static void v7m_push_stack(ARMCPU *cpu)
84
v7m_push(env, env->regs[0]);
85
}
86
87
-static void do_v7m_exception_exit(CPUARMState *env)
88
+static void do_v7m_exception_exit(ARMCPU *cpu)
89
{
90
+ CPUARMState *env = &cpu->env;
91
uint32_t type;
92
uint32_t xpsr;
93
-
94
+ bool ufault = false;
95
+ bool return_to_sp_process = false;
96
+ bool return_to_handler = false;
97
+ bool rettobase = false;
98
+
99
+ /* We can only get here from an EXCP_EXCEPTION_EXIT, and
100
+ * arm_v7m_do_unassigned_access() enforces the architectural rule
101
+ * that jumps to magic addresses don't have magic behaviour unless
102
+ * we're in Handler mode (compare pseudocode BXWritePC()).
103
+ */
104
+ assert(env->v7m.exception != 0);
105
+
106
+ /* In the spec pseudocode ExceptionReturn() is called directly
107
+ * from BXWritePC() and gets the full target PC value including
108
+ * bit zero. In QEMU's implementation we treat it as a normal
109
+ * jump-to-register (which is then caught later on), and so split
110
+ * the target value up between env->regs[15] and env->thumb in
111
+ * gen_bx(). Reconstitute it.
112
+ */
113
type = env->regs[15];
114
+ if (env->thumb) {
115
+ type |= 1;
116
+ }
117
+
118
+ qemu_log_mask(CPU_LOG_INT, "Exception return: magic PC %" PRIx32
119
+ " previous exception %d\n",
120
+ type, env->v7m.exception);
121
+
122
+ if (extract32(type, 5, 23) != extract32(-1, 5, 23)) {
123
+ qemu_log_mask(LOG_GUEST_ERROR, "M profile: zero high bits in exception "
124
+ "exit PC value 0x%" PRIx32 " are UNPREDICTABLE\n", type);
125
+ }
126
+
127
if (env->v7m.exception != ARMV7M_EXCP_NMI) {
128
/* Auto-clear FAULTMASK on return from other than NMI */
129
env->daif &= ~PSTATE_F;
130
}
131
- if (env->v7m.exception != 0) {
132
- armv7m_nvic_complete_irq(env->nvic, env->v7m.exception);
133
+
134
+ switch (armv7m_nvic_complete_irq(env->nvic, env->v7m.exception)) {
135
+ case -1:
136
+ /* attempt to exit an exception that isn't active */
137
+ ufault = true;
138
+ break;
139
+ case 0:
140
+ /* still an irq active now */
141
+ break;
142
+ case 1:
143
+ /* we returned to base exception level, no nesting.
144
+ * (In the pseudocode this is written using "NestedActivation != 1"
145
+ * where we have 'rettobase == false'.)
146
+ */
147
+ rettobase = true;
148
+ break;
149
+ default:
150
+ g_assert_not_reached();
151
+ }
152
+
153
+ switch (type & 0xf) {
154
+ case 1: /* Return to Handler */
155
+ return_to_handler = true;
156
+ break;
157
+ case 13: /* Return to Thread using Process stack */
158
+ return_to_sp_process = true;
159
+ /* fall through */
160
+ case 9: /* Return to Thread using Main stack */
161
+ if (!rettobase &&
162
+ !(env->v7m.ccr & R_V7M_CCR_NONBASETHRDENA_MASK)) {
163
+ ufault = true;
164
+ }
165
+ break;
166
+ default:
167
+ ufault = true;
168
+ }
169
+
170
+ if (ufault) {
171
+ /* Bad exception return: instead of popping the exception
172
+ * stack, directly take a usage fault on the current stack.
173
+ */
174
+ env->v7m.cfsr |= R_V7M_CFSR_INVPC_MASK;
175
+ armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE);
176
+ v7m_exception_taken(cpu, type | 0xf0000000);
177
+ qemu_log_mask(CPU_LOG_INT, "...taking UsageFault on existing "
178
+ "stackframe: failed exception return integrity check\n");
179
+ return;
103
+ return;
180
}
104
}
181
105
182
/* Switch to the target stack. */
106
if (!s->boot_cpu_ptr) {
183
- switch_v7m_sp(env, (type & 4) != 0);
184
+ switch_v7m_sp(env, return_to_sp_process);
185
/* Pop registers. */
186
env->regs[0] = v7m_pop(env);
187
env->regs[1] = v7m_pop(env);
188
@@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(CPUARMState *env)
189
/* Undo stack alignment. */
190
if (xpsr & 0x200)
191
env->regs[13] |= 4;
192
- /* ??? The exception return type specifies Thread/Handler mode. However
193
- this is also implied by the xPSR value. Not sure what to do
194
- if there is a mismatch. */
195
- /* ??? Likewise for mismatches between the CONTROL register and the stack
196
- pointer. */
197
+
198
+ /* The restored xPSR exception field will be zero if we're
199
+ * resuming in Thread mode. If that doesn't match what the
200
+ * exception return type specified then this is a UsageFault.
201
+ */
202
+ if (return_to_handler == (env->v7m.exception == 0)) {
203
+ /* Take an INVPC UsageFault by pushing the stack again. */
204
+ armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE);
205
+ env->v7m.cfsr |= R_V7M_CFSR_INVPC_MASK;
206
+ v7m_push_stack(cpu);
207
+ v7m_exception_taken(cpu, type | 0xf0000000);
208
+ qemu_log_mask(CPU_LOG_INT, "...taking UsageFault on new stackframe: "
209
+ "failed exception return integrity check\n");
210
+ return;
211
+ }
212
+
213
+ /* Otherwise, we have a successful exception exit. */
214
+ qemu_log_mask(CPU_LOG_INT, "...successful exception return\n");
215
}
216
217
static void arm_log_exception(int idx)
218
@@ -XXX,XX +XXX,XX @@ void arm_v7m_cpu_do_interrupt(CPUState *cs)
219
case EXCP_IRQ:
220
break;
221
case EXCP_EXCEPTION_EXIT:
222
- do_v7m_exception_exit(env);
223
+ do_v7m_exception_exit(cpu);
224
return;
225
default:
226
cpu_abort(cs, "Unhandled exception 0x%x\n", cs->exception_index);
227
--
107
--
228
2.7.4
108
2.7.4
229
109
230
110
diff view generated by jsdifflib
1
From: Kurban Mallachiev <mallachiev@ispras.ru>
1
From: Alistair Francis <alistair.francis@xilinx.com>
2
2
3
The i.MX timer device can be reset by writing to the SWR bit
3
The EP108 was an early access development board that is no longer used.
4
of the CR register. This has to behave differently from hard
4
Add an info message to convert any users to the ZCU102 instead. On QEMU
5
(power-on) reset because it does not reset all of the bits
5
they are both identical.
6
in the CR register.
7
6
8
We were incorrectly implementing soft reset and hard reset
7
This patch also updated the qemu-doc.texi file to indicate that the
9
the same way, and in addition had a logic error which meant
8
EP108 has been deprecated.
10
that we were clearing the bits that soft-reset is supposed
11
to preserve and not touching the bits that soft-reset clears.
12
This was not correct behaviour for either kind of reset.
13
9
14
Separate out the soft reset and hard reset code paths, and
10
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
15
correct the handling of reset of the CR register so that it
11
Reviewed-by: Emilio G. Cota <cota@braap.org>
16
is correct in both cases.
12
Message-id: 1510343626-25861-4-git-send-email-cota@braap.org
17
18
Signed-off-by: Kurban Mallachiev <mallachiev@ispras.ru>
19
[PMM: rephrased commit message, spacing on operators;
20
use bool rather than int for is_soft_reset]
21
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
22
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
23
---
14
---
24
hw/timer/imx_gpt.c | 33 +++++++++++++++++++++++++--------
15
hw/arm/xlnx-zcu102.c | 3 +++
25
1 file changed, 25 insertions(+), 8 deletions(-)
16
qemu-doc.texi | 7 +++++++
17
2 files changed, 10 insertions(+)
26
18
27
diff --git a/hw/timer/imx_gpt.c b/hw/timer/imx_gpt.c
19
diff --git a/hw/arm/xlnx-zcu102.c b/hw/arm/xlnx-zcu102.c
28
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
29
--- a/hw/timer/imx_gpt.c
21
--- a/hw/arm/xlnx-zcu102.c
30
+++ b/hw/timer/imx_gpt.c
22
+++ b/hw/arm/xlnx-zcu102.c
31
@@ -XXX,XX +XXX,XX @@ static uint64_t imx_gpt_read(void *opaque, hwaddr offset, unsigned size)
23
@@ -XXX,XX +XXX,XX @@ static void xlnx_ep108_init(MachineState *machine)
32
return reg_value;
24
{
25
XlnxZCU102 *s = EP108_MACHINE(machine);
26
27
+ info_report("The Xilinx EP108 machine is deprecated, please use the "
28
+ "ZCU102 machine instead. It has the same features supported.");
29
+
30
xlnx_zynqmp_init(s, machine);
33
}
31
}
34
32
35
-static void imx_gpt_reset(DeviceState *dev)
33
diff --git a/qemu-doc.texi b/qemu-doc.texi
36
-{
34
index XXXXXXX..XXXXXXX 100644
37
- IMXGPTState *s = IMX_GPT(dev);
35
--- a/qemu-doc.texi
38
36
+++ b/qemu-doc.texi
39
+static void imx_gpt_reset_common(IMXGPTState *s, bool is_soft_reset)
37
@@ -XXX,XX +XXX,XX @@ or ``ivshmem-doorbell`` device types.
40
+{
38
The ``spapr-pci-vfio-host-bridge'' device type is replaced by
41
/* stop timer */
39
the ``spapr-pci-host-bridge'' device type.
42
ptimer_stop(s->timer);
40
43
41
+@section System emulator machines
44
- /*
45
- * Soft reset doesn't touch some bits; hard reset clears them
46
+ /* Soft reset and hard reset differ only in their handling of the CR
47
+ * register -- soft reset preserves the values of some bits there.
48
*/
49
- s->cr &= ~(GPT_CR_EN|GPT_CR_ENMOD|GPT_CR_STOPEN|GPT_CR_DOZEN|
50
- GPT_CR_WAITEN|GPT_CR_DBGEN);
51
+ if (is_soft_reset) {
52
+ /* Clear all CR bits except those that are preserved by soft reset. */
53
+ s->cr &= GPT_CR_EN | GPT_CR_ENMOD | GPT_CR_STOPEN | GPT_CR_DOZEN |
54
+ GPT_CR_WAITEN | GPT_CR_DBGEN |
55
+ (GPT_CR_CLKSRC_MASK << GPT_CR_CLKSRC_SHIFT);
56
+ } else {
57
+ s->cr = 0;
58
+ }
59
s->sr = 0;
60
s->pr = 0;
61
s->ir = 0;
62
@@ -XXX,XX +XXX,XX @@ static void imx_gpt_reset(DeviceState *dev)
63
}
64
}
65
66
+static void imx_gpt_soft_reset(DeviceState *dev)
67
+{
68
+ IMXGPTState *s = IMX_GPT(dev);
69
+ imx_gpt_reset_common(s, true);
70
+}
71
+
42
+
72
+static void imx_gpt_reset(DeviceState *dev)
43
+@subsection Xilinx EP108 (since 2.11.0)
73
+{
74
+ IMXGPTState *s = IMX_GPT(dev);
75
+ imx_gpt_reset_common(s, false);
76
+}
77
+
44
+
78
static void imx_gpt_write(void *opaque, hwaddr offset, uint64_t value,
45
+The ``xlnx-ep108'' machine has been replaced by the ``xlnx-zcu102'' machine.
79
unsigned size)
46
+The ``xlnx-zcu102'' machine has the same features and capabilites in QEMU.
80
{
47
+
81
@@ -XXX,XX +XXX,XX @@ static void imx_gpt_write(void *opaque, hwaddr offset, uint64_t value,
48
@node License
82
s->cr = value & ~0x7c14;
49
@appendix License
83
if (s->cr & GPT_CR_SWR) { /* force reset */
50
84
/* handle the reset */
85
- imx_gpt_reset(DEVICE(s));
86
+ imx_gpt_soft_reset(DEVICE(s));
87
} else {
88
/* set our freq, as the source might have changed */
89
imx_gpt_set_freq(s);
90
--
51
--
91
2.7.4
52
2.7.4
92
53
93
54
diff view generated by jsdifflib
1
From: Clement Deschamps <clement.deschamps@antfield.fr>
1
From: "Emilio G. Cota" <cota@braap.org>
2
2
3
Provide a new function sdbus_reparent_card() in sd core for reparenting
3
Just like the zcu102, the ep108 can instantiate several CPUs.
4
a card from a SDBus to another one.
5
4
6
This function is required by the raspi platform, where the two SD
5
Signed-off-by: Emilio G. Cota <cota@braap.org>
7
controllers can be dynamically switched.
6
Reviewed-by: Alistair Francis <alistair.francis@xilinx.com>
8
7
Message-id: 1510343626-25861-5-git-send-email-cota@braap.org
9
Signed-off-by: Clement Deschamps <clement.deschamps@antfield.fr>
10
Message-id: 20170224164021.9066-3-clement.deschamps@antfield.fr
11
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
12
[PMM: added a doc comment to the header file]
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
---
9
---
15
include/hw/sd/sd.h | 11 +++++++++++
10
hw/arm/xlnx-zcu102.c | 1 +
16
hw/sd/core.c | 30 ++++++++++++++++++++++++++++++
11
1 file changed, 1 insertion(+)
17
2 files changed, 41 insertions(+)
18
12
19
diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h
13
diff --git a/hw/arm/xlnx-zcu102.c b/hw/arm/xlnx-zcu102.c
20
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
21
--- a/include/hw/sd/sd.h
15
--- a/hw/arm/xlnx-zcu102.c
22
+++ b/include/hw/sd/sd.h
16
+++ b/hw/arm/xlnx-zcu102.c
23
@@ -XXX,XX +XXX,XX @@ uint8_t sdbus_read_data(SDBus *sd);
17
@@ -XXX,XX +XXX,XX @@ static void xlnx_ep108_machine_class_init(ObjectClass *oc, void *data)
24
bool sdbus_data_ready(SDBus *sd);
18
mc->block_default_type = IF_IDE;
25
bool sdbus_get_inserted(SDBus *sd);
19
mc->units_per_default_bus = 1;
26
bool sdbus_get_readonly(SDBus *sd);
20
mc->ignore_memory_transaction_failures = true;
27
+/**
21
+ mc->max_cpus = XLNX_ZYNQMP_NUM_APU_CPUS + XLNX_ZYNQMP_NUM_RPU_CPUS;
28
+ * sdbus_reparent_card: Reparent an SD card from one controller to another
29
+ * @from: controller bus to remove card from
30
+ * @to: controller bus to move card to
31
+ *
32
+ * Reparent an SD card, effectively unplugging it from one controller
33
+ * and inserting it into another. This is useful for SoCs like the
34
+ * bcm2835 which have two SD controllers and connect a single SD card
35
+ * to them, selected by the guest reprogramming GPIO line routing.
36
+ */
37
+void sdbus_reparent_card(SDBus *from, SDBus *to);
38
39
/* Functions to be used by SD devices to report back to qdevified controllers */
40
void sdbus_set_inserted(SDBus *sd, bool inserted);
41
diff --git a/hw/sd/core.c b/hw/sd/core.c
42
index XXXXXXX..XXXXXXX 100644
43
--- a/hw/sd/core.c
44
+++ b/hw/sd/core.c
45
@@ -XXX,XX +XXX,XX @@ void sdbus_set_readonly(SDBus *sdbus, bool readonly)
46
}
47
}
22
}
48
23
49
+void sdbus_reparent_card(SDBus *from, SDBus *to)
24
static const TypeInfo xlnx_ep108_machine_init_typeinfo = {
50
+{
51
+ BusChild *kid = QTAILQ_FIRST(&from->qbus.children);
52
+ SDState *card;
53
+ SDCardClass *sc;
54
+ bool readonly;
55
+
56
+ /* We directly reparent the card object rather than implementing this
57
+ * as a hotpluggable connection because we don't want to expose SD cards
58
+ * to users as being hotpluggable, and we can get away with it in this
59
+ * limited use case. This could perhaps be implemented more cleanly in
60
+ * future by adding support to the hotplug infrastructure for "device
61
+ * can be hotplugged only via code, not by user".
62
+ */
63
+
64
+ if (!kid) {
65
+ return;
66
+ }
67
+
68
+ card = SD_CARD(kid->child);
69
+ sc = SD_CARD_GET_CLASS(card);
70
+ readonly = sc->get_readonly(card);
71
+
72
+ sdbus_set_inserted(from, false);
73
+ object_unparent(OBJECT(kid));
74
+ qdev_set_parent_bus(DEVICE(card), &to->qbus);
75
+ sdbus_set_inserted(to, true);
76
+ sdbus_set_readonly(to, readonly);
77
+}
78
+
79
static const TypeInfo sd_bus_info = {
80
.name = TYPE_SD_BUS,
81
.parent = TYPE_BUS,
82
--
25
--
83
2.7.4
26
2.7.4
84
27
85
28
diff view generated by jsdifflib
1
From: Eric Auger <eric.auger@redhat.com>
1
From: "Emilio G. Cota" <cota@braap.org>
2
2
3
In 2.9 ITS will block save/restore and migration use cases. As such,
3
max_cpus needs to be an upper bound on the number of vCPUs
4
let's introduce a user option that allows to turn its instantiation
4
initialized; otherwise TCG region initialization breaks.
5
off, along with GICv3. With the "its" option turned false, migration
6
will be possible, obviously at the expense of MSI support (with GICv3).
7
5
8
Signed-off-by: Eric Auger <eric.auger@redhat.com>
6
Some boards initialize a hard-coded number of vCPUs, which is not
9
Message-id: 1487681108-14452-1-git-send-email-eric.auger@redhat.com
7
captured by the global max_cpus and therefore breaks TCG initialization.
10
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
Fix it by adding the .min_cpus field to machine_class.
9
10
This commit also changes some user-facing behaviour: we now die if
11
-smp is below this hard-coded vCPU minimum instead of silently
12
ignoring the passed -smp value (sometimes announcing this by printing
13
a warning). However, the introduction of .default_cpus lessens the
14
likelihood that users will notice this: if -smp isn't set, we now
15
assign the value in .default_cpus to both smp_cpus and max_cpus. IOW,
16
if a user does not set -smp, they always get a correct number of vCPUs.
17
18
This change fixes 3468b59 ("tcg: enable multiple TCG contexts in
19
softmmu", 2017-10-24), which broke TCG initialization for some
20
ARM boards.
21
22
Fixes: 3468b59e18b179bc63c7ce934de912dfa9596122
23
Reported-by: Thomas Huth <thuth@redhat.com>
24
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
25
Reviewed-by: Alistair Francis <alistair.francis@xilinx.com>
26
Signed-off-by: Emilio G. Cota <cota@braap.org>
27
Message-id: 1510343626-25861-6-git-send-email-cota@braap.org
28
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
29
Signed-off-by: Emilio G. Cota <cota@braap.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
30
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
31
---
13
include/hw/arm/virt.h | 1 +
32
include/hw/boards.h | 5 +++++
14
hw/arm/virt.c | 31 +++++++++++++++++++++++++++++--
33
hw/arm/exynos4_boards.c | 12 ++++--------
15
2 files changed, 30 insertions(+), 2 deletions(-)
34
hw/arm/raspi.c | 2 ++
35
hw/arm/xlnx-zcu102.c | 2 ++
36
vl.c | 21 ++++++++++++++++++---
37
5 files changed, 31 insertions(+), 11 deletions(-)
16
38
17
diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h
39
diff --git a/include/hw/boards.h b/include/hw/boards.h
18
index XXXXXXX..XXXXXXX 100644
40
index XXXXXXX..XXXXXXX 100644
19
--- a/include/hw/arm/virt.h
41
--- a/include/hw/boards.h
20
+++ b/include/hw/arm/virt.h
42
+++ b/include/hw/boards.h
21
@@ -XXX,XX +XXX,XX @@ typedef struct {
43
@@ -XXX,XX +XXX,XX @@ typedef struct {
22
FWCfgState *fw_cfg;
44
23
bool secure;
45
/**
24
bool highmem;
46
* MachineClass:
25
+ bool its;
47
+ * @max_cpus: maximum number of CPUs supported. Default: 1
26
bool virt;
48
+ * @min_cpus: minimum number of CPUs supported. Default: 1
27
int32_t gic_version;
49
+ * @default_cpus: number of CPUs instantiated if none are specified. Default: 1
28
struct arm_boot_info bootinfo;
50
* @get_hotplug_handler: this function is called during bus-less
29
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
51
* device hotplug. If defined it returns pointer to an instance
52
* of HotplugHandler object, which handles hotplug operation
53
@@ -XXX,XX +XXX,XX @@ struct MachineClass {
54
BlockInterfaceType block_default_type;
55
int units_per_default_bus;
56
int max_cpus;
57
+ int min_cpus;
58
+ int default_cpus;
59
unsigned int no_serial:1,
60
no_parallel:1,
61
use_virtcon:1,
62
diff --git a/hw/arm/exynos4_boards.c b/hw/arm/exynos4_boards.c
30
index XXXXXXX..XXXXXXX 100644
63
index XXXXXXX..XXXXXXX 100644
31
--- a/hw/arm/virt.c
64
--- a/hw/arm/exynos4_boards.c
32
+++ b/hw/arm/virt.c
65
+++ b/hw/arm/exynos4_boards.c
33
@@ -XXX,XX +XXX,XX @@ static void create_v2m(VirtMachineState *vms, qemu_irq *pic)
66
@@ -XXX,XX +XXX,XX @@
34
static void create_gic(VirtMachineState *vms, qemu_irq *pic)
67
#include "qemu-common.h"
68
#include "cpu.h"
69
#include "sysemu/sysemu.h"
70
-#include "sysemu/qtest.h"
71
#include "hw/sysbus.h"
72
#include "net/net.h"
73
#include "hw/arm/arm.h"
74
@@ -XXX,XX +XXX,XX @@ exynos4_boards_init_common(MachineState *machine,
75
Exynos4BoardType board_type)
35
{
76
{
36
/* We create a standalone GIC */
77
Exynos4BoardState *s = g_new(Exynos4BoardState, 1);
37
- VirtMachineClass *vmc = VIRT_MACHINE_GET_CLASS(vms);
78
- MachineClass *mc = MACHINE_GET_CLASS(machine);
38
DeviceState *gicdev;
79
-
39
SysBusDevice *gicbusdev;
80
- if (smp_cpus != EXYNOS4210_NCPUS && !qtest_enabled()) {
40
const char *gictype;
81
- error_report("%s board supports only %d CPU cores, ignoring smp_cpus"
41
@@ -XXX,XX +XXX,XX @@ static void create_gic(VirtMachineState *vms, qemu_irq *pic)
82
- " value",
42
83
- mc->name, EXYNOS4210_NCPUS);
43
fdt_add_gic_node(vms);
84
- }
44
85
45
- if (type == 3 && !vmc->no_its) {
86
exynos4_board_binfo.ram_size = exynos4_board_ram_size[board_type];
46
+ if (type == 3 && vms->its) {
87
exynos4_board_binfo.board_id = exynos4_board_id[board_type];
47
create_its(vms, gicdev);
88
@@ -XXX,XX +XXX,XX @@ static void nuri_class_init(ObjectClass *oc, void *data)
48
} else if (type == 2) {
89
mc->desc = "Samsung NURI board (Exynos4210)";
49
create_v2m(vms, pic);
90
mc->init = nuri_init;
50
@@ -XXX,XX +XXX,XX @@ static void virt_set_highmem(Object *obj, bool value, Error **errp)
91
mc->max_cpus = EXYNOS4210_NCPUS;
51
vms->highmem = value;
92
+ mc->min_cpus = EXYNOS4210_NCPUS;
93
+ mc->default_cpus = EXYNOS4210_NCPUS;
94
mc->ignore_memory_transaction_failures = true;
52
}
95
}
53
96
54
+static bool virt_get_its(Object *obj, Error **errp)
97
@@ -XXX,XX +XXX,XX @@ static void smdkc210_class_init(ObjectClass *oc, void *data)
55
+{
98
mc->desc = "Samsung SMDKC210 board (Exynos4210)";
56
+ VirtMachineState *vms = VIRT_MACHINE(obj);
99
mc->init = smdkc210_init;
100
mc->max_cpus = EXYNOS4210_NCPUS;
101
+ mc->min_cpus = EXYNOS4210_NCPUS;
102
+ mc->default_cpus = EXYNOS4210_NCPUS;
103
mc->ignore_memory_transaction_failures = true;
104
}
105
106
diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
107
index XXXXXXX..XXXXXXX 100644
108
--- a/hw/arm/raspi.c
109
+++ b/hw/arm/raspi.c
110
@@ -XXX,XX +XXX,XX @@ static void raspi2_machine_init(MachineClass *mc)
111
mc->no_floppy = 1;
112
mc->no_cdrom = 1;
113
mc->max_cpus = BCM2836_NCPUS;
114
+ mc->min_cpus = BCM2836_NCPUS;
115
+ mc->default_cpus = BCM2836_NCPUS;
116
mc->default_ram_size = 1024 * 1024 * 1024;
117
mc->ignore_memory_transaction_failures = true;
118
};
119
diff --git a/hw/arm/xlnx-zcu102.c b/hw/arm/xlnx-zcu102.c
120
index XXXXXXX..XXXXXXX 100644
121
--- a/hw/arm/xlnx-zcu102.c
122
+++ b/hw/arm/xlnx-zcu102.c
123
@@ -XXX,XX +XXX,XX @@ static void xlnx_ep108_machine_class_init(ObjectClass *oc, void *data)
124
mc->units_per_default_bus = 1;
125
mc->ignore_memory_transaction_failures = true;
126
mc->max_cpus = XLNX_ZYNQMP_NUM_APU_CPUS + XLNX_ZYNQMP_NUM_RPU_CPUS;
127
+ mc->default_cpus = XLNX_ZYNQMP_NUM_APU_CPUS;
128
}
129
130
static const TypeInfo xlnx_ep108_machine_init_typeinfo = {
131
@@ -XXX,XX +XXX,XX @@ static void xlnx_zcu102_machine_class_init(ObjectClass *oc, void *data)
132
mc->units_per_default_bus = 1;
133
mc->ignore_memory_transaction_failures = true;
134
mc->max_cpus = XLNX_ZYNQMP_NUM_APU_CPUS + XLNX_ZYNQMP_NUM_RPU_CPUS;
135
+ mc->default_cpus = XLNX_ZYNQMP_NUM_APU_CPUS;
136
}
137
138
static const TypeInfo xlnx_zcu102_machine_init_typeinfo = {
139
diff --git a/vl.c b/vl.c
140
index XXXXXXX..XXXXXXX 100644
141
--- a/vl.c
142
+++ b/vl.c
143
@@ -XXX,XX +XXX,XX @@ Chardev *virtcon_hds[MAX_VIRTIO_CONSOLES];
144
Chardev *sclp_hds[MAX_SCLP_CONSOLES];
145
int win2k_install_hack = 0;
146
int singlestep = 0;
147
-int smp_cpus = 1;
148
-unsigned int max_cpus = 1;
149
+int smp_cpus;
150
+unsigned int max_cpus;
151
int smp_cores = 1;
152
int smp_threads = 1;
153
int acpi_enabled = 1;
154
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv, char **envp)
155
exit(0);
156
}
157
158
+ /* machine_class: default to UP */
159
+ machine_class->max_cpus = machine_class->max_cpus ?: 1;
160
+ machine_class->min_cpus = machine_class->min_cpus ?: 1;
161
+ machine_class->default_cpus = machine_class->default_cpus ?: 1;
57
+
162
+
58
+ return vms->its;
163
+ /* default to machine_class->default_cpus */
59
+}
164
+ smp_cpus = machine_class->default_cpus;
165
+ max_cpus = machine_class->default_cpus;
60
+
166
+
61
+static void virt_set_its(Object *obj, bool value, Error **errp)
167
smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL));
62
+{
168
63
+ VirtMachineState *vms = VIRT_MACHINE(obj);
169
- machine_class->max_cpus = machine_class->max_cpus ?: 1; /* Default to UP */
64
+
170
+ /* sanity-check smp_cpus and max_cpus against machine_class */
65
+ vms->its = value;
171
+ if (smp_cpus < machine_class->min_cpus) {
66
+}
172
+ error_report("Invalid SMP CPUs %d. The min CPUs "
67
+
173
+ "supported by machine '%s' is %d", smp_cpus,
68
static char *virt_get_gic_version(Object *obj, Error **errp)
174
+ machine_class->name, machine_class->min_cpus);
69
{
175
+ exit(1);
70
VirtMachineState *vms = VIRT_MACHINE(obj);
71
@@ -XXX,XX +XXX,XX @@ type_init(machvirt_machine_init);
72
static void virt_2_9_instance_init(Object *obj)
73
{
74
VirtMachineState *vms = VIRT_MACHINE(obj);
75
+ VirtMachineClass *vmc = VIRT_MACHINE_GET_CLASS(vms);
76
77
/* EL3 is disabled by default on virt: this makes us consistent
78
* between KVM and TCG for this board, and it also allows us to
79
@@ -XXX,XX +XXX,XX @@ static void virt_2_9_instance_init(Object *obj)
80
"Set GIC version. "
81
"Valid values are 2, 3 and host", NULL);
82
83
+ if (vmc->no_its) {
84
+ vms->its = false;
85
+ } else {
86
+ /* Default allows ITS instantiation */
87
+ vms->its = true;
88
+ object_property_add_bool(obj, "its", virt_get_its,
89
+ virt_set_its, NULL);
90
+ object_property_set_description(obj, "its",
91
+ "Set on/off to enable/disable "
92
+ "ITS instantiation",
93
+ NULL);
94
+ }
176
+ }
95
+
177
if (max_cpus > machine_class->max_cpus) {
96
vms->memmap = a15memmap;
178
error_report("Invalid SMP CPUs %d. The max CPUs "
97
vms->irqmap = a15irqmap;
179
"supported by machine '%s' is %d", max_cpus,
98
}
99
--
180
--
100
2.7.4
181
2.7.4
101
182
102
183
diff view generated by jsdifflib
1
From: Prasad J Pandit <pjp@fedoraproject.org>
1
From: Alex Bennée <alex.bennee@linaro.org>
2
2
3
In SDHCI protocol, the 'Block count enable' bit of the Transfer
3
We are still seeing signals during translation time when we walk over
4
Mode register is relevant only in multi block transfers. We need
4
a page protection boundary. This expands the check to ensure the host
5
not check it in single block transfers.
5
PC is inside the code generation buffer. The original suggestion was
6
to check versus tcg_ctx.code_gen_ptr but as we now segment the
7
translation buffer we have to settle for just a general check for
8
being inside.
6
9
7
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
10
I've also fixed up the declaration to make it clear it can deal with
8
Message-id: 20170214185225.7994-5-ppandit@redhat.com
11
invalid addresses. A later patch will fix up the call sites.
9
Reviewed-by: Alistair Francis <alistair.francis@xilinx.com>
12
13
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
14
Reported-by: Peter Maydell <peter.maydell@linaro.org>
15
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
16
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
17
Message-id: 20171108153245.20740-2-alex.bennee@linaro.org
18
Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
19
Cc: Richard Henderson <rth@twiddle.net>
20
Tested-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
21
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
22
---
12
hw/sd/sdhci.c | 6 +-----
23
include/exec/exec-all.h | 11 ++++++++++
13
1 file changed, 1 insertion(+), 5 deletions(-)
24
accel/tcg/translate-all.c | 52 ++++++++++++++++++++++++++---------------------
25
2 files changed, 40 insertions(+), 23 deletions(-)
14
26
15
diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
27
diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
16
index XXXXXXX..XXXXXXX 100644
28
index XXXXXXX..XXXXXXX 100644
17
--- a/hw/sd/sdhci.c
29
--- a/include/exec/exec-all.h
18
+++ b/hw/sd/sdhci.c
30
+++ b/include/exec/exec-all.h
19
@@ -XXX,XX +XXX,XX @@ static void sdhci_sdma_transfer_multi_blocks(SDHCIState *s)
31
@@ -XXX,XX +XXX,XX @@ void restore_state_to_opc(CPUArchState *env, struct TranslationBlock *tb,
32
target_ulong *data);
33
34
void cpu_gen_init(void);
35
+
36
+/**
37
+ * cpu_restore_state:
38
+ * @cpu: the vCPU state is to be restore to
39
+ * @searched_pc: the host PC the fault occurred at
40
+ * @return: true if state was restored, false otherwise
41
+ *
42
+ * Attempt to restore the state for a fault occurring in translated
43
+ * code. If the searched_pc is not in translated code no state is
44
+ * restored and the function returns false.
45
+ */
46
bool cpu_restore_state(CPUState *cpu, uintptr_t searched_pc);
47
48
void QEMU_NORETURN cpu_loop_exit_noexc(CPUState *cpu);
49
diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
50
index XXXXXXX..XXXXXXX 100644
51
--- a/accel/tcg/translate-all.c
52
+++ b/accel/tcg/translate-all.c
53
@@ -XXX,XX +XXX,XX @@ static int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb,
54
return 0;
20
}
55
}
21
56
22
/* single block SDMA transfer */
57
-bool cpu_restore_state(CPUState *cpu, uintptr_t retaddr)
58
+bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc)
59
{
60
TranslationBlock *tb;
61
bool r = false;
62
+ uintptr_t check_offset;
63
64
- /* A retaddr of zero is invalid so we really shouldn't have ended
65
- * up here. The target code has likely forgotten to check retaddr
66
- * != 0 before attempting to restore state. We return early to
67
- * avoid blowing up on a recursive tb_lock(). The target must have
68
- * previously survived a failed cpu_restore_state because
69
- * tb_find_pc(0) would have failed anyway. It still should be
70
- * fixed though.
71
+ /* The host_pc has to be in the region of current code buffer. If
72
+ * it is not we will not be able to resolve it here. The two cases
73
+ * where host_pc will not be correct are:
74
+ *
75
+ * - fault during translation (instruction fetch)
76
+ * - fault from helper (not using GETPC() macro)
77
+ *
78
+ * Either way we need return early to avoid blowing up on a
79
+ * recursive tb_lock() as we can't resolve it here.
80
+ *
81
+ * We are using unsigned arithmetic so if host_pc <
82
+ * tcg_init_ctx.code_gen_buffer check_offset will wrap to way
83
+ * above the code_gen_buffer_size
84
*/
23
-
85
-
24
static void sdhci_sdma_transfer_single_block(SDHCIState *s)
86
- if (!retaddr) {
25
{
87
- return r;
26
int n;
88
- }
27
@@ -XXX,XX +XXX,XX @@ static void sdhci_sdma_transfer_single_block(SDHCIState *s)
89
-
28
sdbus_write_data(&s->sdbus, s->fifo_buffer[n]);
90
- tb_lock();
91
- tb = tb_find_pc(retaddr);
92
- if (tb) {
93
- cpu_restore_state_from_tb(cpu, tb, retaddr);
94
- if (tb->cflags & CF_NOCACHE) {
95
- /* one-shot translation, invalidate it immediately */
96
- tb_phys_invalidate(tb, -1);
97
- tb_remove(tb);
98
+ check_offset = host_pc - (uintptr_t) tcg_init_ctx.code_gen_buffer;
99
+
100
+ if (check_offset < tcg_init_ctx.code_gen_buffer_size) {
101
+ tb_lock();
102
+ tb = tb_find_pc(host_pc);
103
+ if (tb) {
104
+ cpu_restore_state_from_tb(cpu, tb, host_pc);
105
+ if (tb->cflags & CF_NOCACHE) {
106
+ /* one-shot translation, invalidate it immediately */
107
+ tb_phys_invalidate(tb, -1);
108
+ tb_remove(tb);
109
+ }
110
+ r = true;
29
}
111
}
112
- r = true;
113
+ tb_unlock();
30
}
114
}
31
-
115
- tb_unlock();
32
- if (s->trnmod & SDHC_TRNS_BLK_CNT_EN) {
116
33
- s->blkcnt--;
117
return r;
34
- }
35
+ s->blkcnt--;
36
37
sdhci_end_transfer(s);
38
}
118
}
39
--
119
--
40
2.7.4
120
2.7.4
41
121
42
122
diff view generated by jsdifflib
Deleted patch
1
From: Igor Mammedov <imammedo@redhat.com>
2
1
3
object_new(FOO) returns an object with ref_cnt == 1
4
and following
5
object_property_set_bool(cpuobj, true, "realized", NULL)
6
set parent of cpuobj to '/machine/unattached' which makes
7
ref_cnt == 2.
8
9
Since machvirt_init() doesn't take ownership of cpuobj
10
returned by object_new() it should explicitly drop
11
reference to cpuobj when dangling pointer is about to
12
go out of scope like it's done pc_new_cpu() to avoid
13
object leak.
14
15
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
16
Message-id: 1487253461-269218-1-git-send-email-imammedo@redhat.com
17
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
18
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
19
---
20
hw/arm/virt.c | 1 +
21
1 file changed, 1 insertion(+)
22
23
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
24
index XXXXXXX..XXXXXXX 100644
25
--- a/hw/arm/virt.c
26
+++ b/hw/arm/virt.c
27
@@ -XXX,XX +XXX,XX @@ static void machvirt_init(MachineState *machine)
28
}
29
30
object_property_set_bool(cpuobj, true, "realized", NULL);
31
+ object_unref(cpuobj);
32
}
33
fdt_add_timer_nodes(vms);
34
fdt_add_cpu_nodes(vms);
35
--
36
2.7.4
37
38
diff view generated by jsdifflib
Deleted patch
1
In get_page_addr_code(), if the guest PC doesn't correspond to RAM
2
then we currently run the CPU's do_unassigned_access() hook if it has
3
one, and otherwise we give up and exit QEMU with a more-or-less
4
useful message. This code assumes that the do_unassigned_access hook
5
will never return, because if it does then we'll plough on attempting
6
to use a non-RAM TLB entry to get a RAM address and will abort() in
7
qemu_ram_addr_from_host_nofail(). Unfortunately some CPU
8
implementations of this hook do return: Microblaze, SPARC and the ARM
9
v7M.
10
1
11
Change the code to call report_bad_exec() if the hook returns, as
12
well as if it didn't have one. This means we can tidy it up to use
13
the cpu_unassigned_access() function which wraps the "get the CPU
14
class and call the hook if it has one" work, since we aren't trying
15
to distinguish "no hook" from "hook existed and returned" any more.
16
17
This brings the handling of this hook into line with the handling
18
used for data accesses, where "hook returned" is treated the
19
same as "no hook existed" and gets you the default behaviour.
20
21
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
22
Reviewed-by: Richard Henderson <rth@twiddle.net>
23
---
24
cputlb.c | 15 +++++++--------
25
1 file changed, 7 insertions(+), 8 deletions(-)
26
27
diff --git a/cputlb.c b/cputlb.c
28
index XXXXXXX..XXXXXXX 100644
29
--- a/cputlb.c
30
+++ b/cputlb.c
31
@@ -XXX,XX +XXX,XX @@ tb_page_addr_t get_page_addr_code(CPUArchState *env1, target_ulong addr)
32
pd = iotlbentry->addr & ~TARGET_PAGE_MASK;
33
mr = iotlb_to_region(cpu, pd, iotlbentry->attrs);
34
if (memory_region_is_unassigned(mr)) {
35
- CPUClass *cc = CPU_GET_CLASS(cpu);
36
-
37
- if (cc->do_unassigned_access) {
38
- cc->do_unassigned_access(cpu, addr, false, true, 0, 4);
39
- } else {
40
- report_bad_exec(cpu, addr);
41
- exit(1);
42
- }
43
+ cpu_unassigned_access(cpu, addr, false, true, 0, 4);
44
+ /* The CPU's unassigned access hook might have longjumped out
45
+ * with an exception. If it didn't (or there was no hook) then
46
+ * we can't proceed further.
47
+ */
48
+ report_bad_exec(cpu, addr);
49
+ exit(1);
50
}
51
p = (void *)((uintptr_t)addr + env1->tlb_table[mmu_idx][page_index].addend);
52
return qemu_ram_addr_from_host_nofail(p);
53
--
54
2.7.4
55
56
diff view generated by jsdifflib
Deleted patch
1
Rename the nvic_state struct to NVICState, to match
2
our naming conventions.
3
1
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
7
---
8
hw/intc/armv7m_nvic.c | 44 ++++++++++++++++++++++----------------------
9
1 file changed, 22 insertions(+), 22 deletions(-)
10
11
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
12
index XXXXXXX..XXXXXXX 100644
13
--- a/hw/intc/armv7m_nvic.c
14
+++ b/hw/intc/armv7m_nvic.c
15
@@ -XXX,XX +XXX,XX @@
16
#include "gic_internal.h"
17
#include "qemu/log.h"
18
19
-typedef struct {
20
+typedef struct NVICState {
21
GICState gic;
22
ARMCPU *cpu;
23
struct {
24
@@ -XXX,XX +XXX,XX @@ typedef struct {
25
MemoryRegion container;
26
uint32_t num_irq;
27
qemu_irq sysresetreq;
28
-} nvic_state;
29
+} NVICState;
30
31
#define TYPE_NVIC "armv7m_nvic"
32
/**
33
@@ -XXX,XX +XXX,XX @@ typedef struct NVICClass {
34
#define NVIC_GET_CLASS(obj) \
35
OBJECT_GET_CLASS(NVICClass, (obj), TYPE_NVIC)
36
#define NVIC(obj) \
37
- OBJECT_CHECK(nvic_state, (obj), TYPE_NVIC)
38
+ OBJECT_CHECK(NVICState, (obj), TYPE_NVIC)
39
40
static const uint8_t nvic_id[] = {
41
0x00, 0xb0, 0x1b, 0x00, 0x0d, 0xe0, 0x05, 0xb1
42
@@ -XXX,XX +XXX,XX @@ static const uint8_t nvic_id[] = {
43
int system_clock_scale;
44
45
/* Conversion factor from qemu timer to SysTick frequencies. */
46
-static inline int64_t systick_scale(nvic_state *s)
47
+static inline int64_t systick_scale(NVICState *s)
48
{
49
if (s->systick.control & SYSTICK_CLKSOURCE)
50
return system_clock_scale;
51
@@ -XXX,XX +XXX,XX @@ static inline int64_t systick_scale(nvic_state *s)
52
return 1000;
53
}
54
55
-static void systick_reload(nvic_state *s, int reset)
56
+static void systick_reload(NVICState *s, int reset)
57
{
58
/* The Cortex-M3 Devices Generic User Guide says that "When the
59
* ENABLE bit is set to 1, the counter loads the RELOAD value from the
60
@@ -XXX,XX +XXX,XX @@ static void systick_reload(nvic_state *s, int reset)
61
62
static void systick_timer_tick(void * opaque)
63
{
64
- nvic_state *s = (nvic_state *)opaque;
65
+ NVICState *s = (NVICState *)opaque;
66
s->systick.control |= SYSTICK_COUNTFLAG;
67
if (s->systick.control & SYSTICK_TICKINT) {
68
/* Trigger the interrupt. */
69
@@ -XXX,XX +XXX,XX @@ static void systick_timer_tick(void * opaque)
70
}
71
}
72
73
-static void systick_reset(nvic_state *s)
74
+static void systick_reset(NVICState *s)
75
{
76
s->systick.control = 0;
77
s->systick.reload = 0;
78
@@ -XXX,XX +XXX,XX @@ static void systick_reset(nvic_state *s)
79
IRQ is #16. The internal GIC routines use #32 as the first IRQ. */
80
void armv7m_nvic_set_pending(void *opaque, int irq)
81
{
82
- nvic_state *s = (nvic_state *)opaque;
83
+ NVICState *s = (NVICState *)opaque;
84
if (irq >= 16)
85
irq += 16;
86
gic_set_pending_private(&s->gic, 0, irq);
87
@@ -XXX,XX +XXX,XX @@ void armv7m_nvic_set_pending(void *opaque, int irq)
88
/* Make pending IRQ active. */
89
int armv7m_nvic_acknowledge_irq(void *opaque)
90
{
91
- nvic_state *s = (nvic_state *)opaque;
92
+ NVICState *s = (NVICState *)opaque;
93
uint32_t irq;
94
95
irq = gic_acknowledge_irq(&s->gic, 0, MEMTXATTRS_UNSPECIFIED);
96
@@ -XXX,XX +XXX,XX @@ int armv7m_nvic_acknowledge_irq(void *opaque)
97
98
void armv7m_nvic_complete_irq(void *opaque, int irq)
99
{
100
- nvic_state *s = (nvic_state *)opaque;
101
+ NVICState *s = (NVICState *)opaque;
102
if (irq >= 16)
103
irq += 16;
104
gic_complete_irq(&s->gic, 0, irq, MEMTXATTRS_UNSPECIFIED);
105
}
106
107
-static uint32_t nvic_readl(nvic_state *s, uint32_t offset)
108
+static uint32_t nvic_readl(NVICState *s, uint32_t offset)
109
{
110
ARMCPU *cpu = s->cpu;
111
uint32_t val;
112
@@ -XXX,XX +XXX,XX @@ static uint32_t nvic_readl(nvic_state *s, uint32_t offset)
113
}
114
}
115
116
-static void nvic_writel(nvic_state *s, uint32_t offset, uint32_t value)
117
+static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value)
118
{
119
ARMCPU *cpu = s->cpu;
120
uint32_t oldval;
121
@@ -XXX,XX +XXX,XX @@ static void nvic_writel(nvic_state *s, uint32_t offset, uint32_t value)
122
static uint64_t nvic_sysreg_read(void *opaque, hwaddr addr,
123
unsigned size)
124
{
125
- nvic_state *s = (nvic_state *)opaque;
126
+ NVICState *s = (NVICState *)opaque;
127
uint32_t offset = addr;
128
int i;
129
uint32_t val;
130
@@ -XXX,XX +XXX,XX @@ static uint64_t nvic_sysreg_read(void *opaque, hwaddr addr,
131
static void nvic_sysreg_write(void *opaque, hwaddr addr,
132
uint64_t value, unsigned size)
133
{
134
- nvic_state *s = (nvic_state *)opaque;
135
+ NVICState *s = (NVICState *)opaque;
136
uint32_t offset = addr;
137
int i;
138
139
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_nvic = {
140
.version_id = 1,
141
.minimum_version_id = 1,
142
.fields = (VMStateField[]) {
143
- VMSTATE_UINT32(systick.control, nvic_state),
144
- VMSTATE_UINT32(systick.reload, nvic_state),
145
- VMSTATE_INT64(systick.tick, nvic_state),
146
- VMSTATE_TIMER_PTR(systick.timer, nvic_state),
147
+ VMSTATE_UINT32(systick.control, NVICState),
148
+ VMSTATE_UINT32(systick.reload, NVICState),
149
+ VMSTATE_INT64(systick.tick, NVICState),
150
+ VMSTATE_TIMER_PTR(systick.timer, NVICState),
151
VMSTATE_END_OF_LIST()
152
}
153
};
154
155
static void armv7m_nvic_reset(DeviceState *dev)
156
{
157
- nvic_state *s = NVIC(dev);
158
+ NVICState *s = NVIC(dev);
159
NVICClass *nc = NVIC_GET_CLASS(s);
160
nc->parent_reset(dev);
161
/* Common GIC reset resets to disabled; the NVIC doesn't have
162
@@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_reset(DeviceState *dev)
163
164
static void armv7m_nvic_realize(DeviceState *dev, Error **errp)
165
{
166
- nvic_state *s = NVIC(dev);
167
+ NVICState *s = NVIC(dev);
168
NVICClass *nc = NVIC_GET_CLASS(s);
169
Error *local_err = NULL;
170
171
@@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_instance_init(Object *obj)
172
*/
173
GICState *s = ARM_GIC_COMMON(obj);
174
DeviceState *dev = DEVICE(obj);
175
- nvic_state *nvic = NVIC(obj);
176
+ NVICState *nvic = NVIC(obj);
177
/* The ARM v7m may have anything from 0 to 496 external interrupt
178
* IRQ lines. We default to 64. Other boards may differ and should
179
* set the num-irq property appropriately.
180
@@ -XXX,XX +XXX,XX @@ static const TypeInfo armv7m_nvic_info = {
181
.name = TYPE_NVIC,
182
.parent = TYPE_ARM_GIC_COMMON,
183
.instance_init = armv7m_nvic_instance_init,
184
- .instance_size = sizeof(nvic_state),
185
+ .instance_size = sizeof(NVICState),
186
.class_init = armv7m_nvic_class_init,
187
.class_size = sizeof(NVICClass),
188
};
189
--
190
2.7.4
191
192
diff view generated by jsdifflib
Deleted patch
1
Add a state field for the v7M PRIGROUP register and implent
2
reading and writing it. The current NVIC doesn't honour
3
the values written, but the new version will.
4
1
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
8
---
9
hw/intc/armv7m_nvic.c | 14 ++++++++------
10
1 file changed, 8 insertions(+), 6 deletions(-)
11
12
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
13
index XXXXXXX..XXXXXXX 100644
14
--- a/hw/intc/armv7m_nvic.c
15
+++ b/hw/intc/armv7m_nvic.c
16
@@ -XXX,XX +XXX,XX @@
17
typedef struct NVICState {
18
GICState gic;
19
ARMCPU *cpu;
20
+
21
+ uint32_t prigroup;
22
+
23
struct {
24
uint32_t control;
25
uint32_t reload;
26
@@ -XXX,XX +XXX,XX @@ static uint32_t nvic_readl(NVICState *s, uint32_t offset)
27
case 0xd08: /* Vector Table Offset. */
28
return cpu->env.v7m.vecbase;
29
case 0xd0c: /* Application Interrupt/Reset Control. */
30
- return 0xfa050000;
31
+ return 0xfa050000 | (s->prigroup << 8);
32
case 0xd10: /* System Control. */
33
/* TODO: Implement SLEEPONEXIT. */
34
return 0;
35
@@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value)
36
if (value & 1) {
37
qemu_log_mask(LOG_UNIMP, "AIRCR system reset unimplemented\n");
38
}
39
- if (value & 0x700) {
40
- qemu_log_mask(LOG_UNIMP, "PRIGROUP unimplemented\n");
41
- }
42
+ s->prigroup = extract32(value, 8, 3);
43
}
44
break;
45
case 0xd10: /* System Control. */
46
@@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps nvic_sysreg_ops = {
47
48
static const VMStateDescription vmstate_nvic = {
49
.name = "armv7m_nvic",
50
- .version_id = 1,
51
- .minimum_version_id = 1,
52
+ .version_id = 2,
53
+ .minimum_version_id = 2,
54
.fields = (VMStateField[]) {
55
VMSTATE_UINT32(systick.control, NVICState),
56
VMSTATE_UINT32(systick.reload, NVICState),
57
VMSTATE_INT64(systick.tick, NVICState),
58
VMSTATE_TIMER_PTR(systick.timer, NVICState),
59
+ VMSTATE_UINT32(prigroup, NVICState),
60
VMSTATE_END_OF_LIST()
61
}
62
};
63
--
64
2.7.4
65
66
diff view generated by jsdifflib
Deleted patch
1
From: Michael Davidsaver <mdavidsaver@gmail.com>
2
1
3
Despite some superficial similarities of register layout, the
4
M-profile NVIC is really very different from the A-profile GIC.
5
Our current attempt to reuse the GIC code means that we have
6
significant bugs in our NVIC.
7
8
Implement the NVIC as an entirely separate device, to give
9
us somewhere we can get the behaviour correct.
10
11
This initial commit does not attempt to implement exception
12
priority escalation, since the GIC-based code didn't either.
13
It does fix a few bugs in passing:
14
* ICSR.RETTOBASE polarity was wrong and didn't account for
15
internal exceptions
16
* ICSR.VECTPENDING was 16 too high if the pending exception
17
was for an external interrupt
18
* UsageFault, BusFault and MemFault were not disabled on reset
19
as they are supposed to be
20
21
Signed-off-by: Michael Davidsaver <mdavidsaver@gmail.com>
22
[PMM: reworked, various bugs and stylistic cleanups]
23
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
24
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
25
---
26
hw/intc/armv7m_nvic.c | 738 ++++++++++++++++++++++++++++++++++++++++----------
27
hw/intc/trace-events | 15 +
28
2 files changed, 609 insertions(+), 144 deletions(-)
29
30
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
31
index XXXXXXX..XXXXXXX 100644
32
--- a/hw/intc/armv7m_nvic.c
33
+++ b/hw/intc/armv7m_nvic.c
34
@@ -XXX,XX +XXX,XX @@
35
#include "hw/sysbus.h"
36
#include "qemu/timer.h"
37
#include "hw/arm/arm.h"
38
+#include "target/arm/cpu.h"
39
#include "exec/address-spaces.h"
40
-#include "gic_internal.h"
41
#include "qemu/log.h"
42
+#include "trace.h"
43
+
44
+/* IRQ number counting:
45
+ *
46
+ * the num-irq property counts the number of external IRQ lines
47
+ *
48
+ * NVICState::num_irq counts the total number of exceptions
49
+ * (external IRQs, the 15 internal exceptions including reset,
50
+ * and one for the unused exception number 0).
51
+ *
52
+ * NVIC_MAX_IRQ is the highest permitted number of external IRQ lines.
53
+ *
54
+ * NVIC_MAX_VECTORS is the highest permitted number of exceptions.
55
+ *
56
+ * Iterating through all exceptions should typically be done with
57
+ * for (i = 1; i < s->num_irq; i++) to avoid the unused slot 0.
58
+ *
59
+ * The external qemu_irq lines are the NVIC's external IRQ lines,
60
+ * so line 0 is exception 16.
61
+ *
62
+ * In the terminology of the architecture manual, "interrupts" are
63
+ * a subcategory of exception referring to the external interrupts
64
+ * (which are exception numbers NVIC_FIRST_IRQ and upward).
65
+ * For historical reasons QEMU tends to use "interrupt" and
66
+ * "exception" more or less interchangeably.
67
+ */
68
+#define NVIC_FIRST_IRQ 16
69
+#define NVIC_MAX_VECTORS 512
70
+#define NVIC_MAX_IRQ (NVIC_MAX_VECTORS - NVIC_FIRST_IRQ)
71
+
72
+/* Effective running priority of the CPU when no exception is active
73
+ * (higher than the highest possible priority value)
74
+ */
75
+#define NVIC_NOEXC_PRIO 0x100
76
+
77
+typedef struct VecInfo {
78
+ /* Exception priorities can range from -3 to 255; only the unmodifiable
79
+ * priority values for RESET, NMI and HardFault can be negative.
80
+ */
81
+ int16_t prio;
82
+ uint8_t enabled;
83
+ uint8_t pending;
84
+ uint8_t active;
85
+ uint8_t level; /* exceptions <=15 never set level */
86
+} VecInfo;
87
88
typedef struct NVICState {
89
- GICState gic;
90
+ /*< private >*/
91
+ SysBusDevice parent_obj;
92
+ /*< public >*/
93
+
94
ARMCPU *cpu;
95
96
+ VecInfo vectors[NVIC_MAX_VECTORS];
97
uint32_t prigroup;
98
99
+ /* vectpending and exception_prio are both cached state that can
100
+ * be recalculated from the vectors[] array and the prigroup field.
101
+ */
102
+ unsigned int vectpending; /* highest prio pending enabled exception */
103
+ int exception_prio; /* group prio of the highest prio active exception */
104
+
105
struct {
106
uint32_t control;
107
uint32_t reload;
108
int64_t tick;
109
QEMUTimer *timer;
110
} systick;
111
+
112
MemoryRegion sysregmem;
113
- MemoryRegion gic_iomem_alias;
114
MemoryRegion container;
115
+
116
uint32_t num_irq;
117
+ qemu_irq excpout;
118
qemu_irq sysresetreq;
119
} NVICState;
120
121
#define TYPE_NVIC "armv7m_nvic"
122
-/**
123
- * NVICClass:
124
- * @parent_reset: the parent class' reset handler.
125
- *
126
- * A model of the v7M NVIC and System Controller
127
- */
128
-typedef struct NVICClass {
129
- /*< private >*/
130
- ARMGICClass parent_class;
131
- /*< public >*/
132
- DeviceRealize parent_realize;
133
- void (*parent_reset)(DeviceState *dev);
134
-} NVICClass;
135
-
136
-#define NVIC_CLASS(klass) \
137
- OBJECT_CLASS_CHECK(NVICClass, (klass), TYPE_NVIC)
138
-#define NVIC_GET_CLASS(obj) \
139
- OBJECT_GET_CLASS(NVICClass, (obj), TYPE_NVIC)
140
+
141
#define NVIC(obj) \
142
OBJECT_CHECK(NVICState, (obj), TYPE_NVIC)
143
144
@@ -XXX,XX +XXX,XX @@ static void systick_reset(NVICState *s)
145
timer_del(s->systick.timer);
146
}
147
148
-/* The external routines use the hardware vector numbering, ie. the first
149
- IRQ is #16. The internal GIC routines use #32 as the first IRQ. */
150
+static int nvic_pending_prio(NVICState *s)
151
+{
152
+ /* return the priority of the current pending interrupt,
153
+ * or NVIC_NOEXC_PRIO if no interrupt is pending
154
+ */
155
+ return s->vectpending ? s->vectors[s->vectpending].prio : NVIC_NOEXC_PRIO;
156
+}
157
+
158
+/* Return the value of the ISCR RETTOBASE bit:
159
+ * 1 if there is exactly one active exception
160
+ * 0 if there is more than one active exception
161
+ * UNKNOWN if there are no active exceptions (we choose 1,
162
+ * which matches the choice Cortex-M3 is documented as making).
163
+ *
164
+ * NB: some versions of the documentation talk about this
165
+ * counting "active exceptions other than the one shown by IPSR";
166
+ * this is only different in the obscure corner case where guest
167
+ * code has manually deactivated an exception and is about
168
+ * to fail an exception-return integrity check. The definition
169
+ * above is the one from the v8M ARM ARM and is also in line
170
+ * with the behaviour documented for the Cortex-M3.
171
+ */
172
+static bool nvic_rettobase(NVICState *s)
173
+{
174
+ int irq, nhand = 0;
175
+
176
+ for (irq = ARMV7M_EXCP_RESET; irq < s->num_irq; irq++) {
177
+ if (s->vectors[irq].active) {
178
+ nhand++;
179
+ if (nhand == 2) {
180
+ return 0;
181
+ }
182
+ }
183
+ }
184
+
185
+ return 1;
186
+}
187
+
188
+/* Return the value of the ISCR ISRPENDING bit:
189
+ * 1 if an external interrupt is pending
190
+ * 0 if no external interrupt is pending
191
+ */
192
+static bool nvic_isrpending(NVICState *s)
193
+{
194
+ int irq;
195
+
196
+ /* We can shortcut if the highest priority pending interrupt
197
+ * happens to be external or if there is nothing pending.
198
+ */
199
+ if (s->vectpending > NVIC_FIRST_IRQ) {
200
+ return true;
201
+ }
202
+ if (s->vectpending == 0) {
203
+ return false;
204
+ }
205
+
206
+ for (irq = NVIC_FIRST_IRQ; irq < s->num_irq; irq++) {
207
+ if (s->vectors[irq].pending) {
208
+ return true;
209
+ }
210
+ }
211
+ return false;
212
+}
213
+
214
+/* Return a mask word which clears the subpriority bits from
215
+ * a priority value for an M-profile exception, leaving only
216
+ * the group priority.
217
+ */
218
+static inline uint32_t nvic_gprio_mask(NVICState *s)
219
+{
220
+ return ~0U << (s->prigroup + 1);
221
+}
222
+
223
+/* Recompute vectpending and exception_prio */
224
+static void nvic_recompute_state(NVICState *s)
225
+{
226
+ int i;
227
+ int pend_prio = NVIC_NOEXC_PRIO;
228
+ int active_prio = NVIC_NOEXC_PRIO;
229
+ int pend_irq = 0;
230
+
231
+ for (i = 1; i < s->num_irq; i++) {
232
+ VecInfo *vec = &s->vectors[i];
233
+
234
+ if (vec->enabled && vec->pending && vec->prio < pend_prio) {
235
+ pend_prio = vec->prio;
236
+ pend_irq = i;
237
+ }
238
+ if (vec->active && vec->prio < active_prio) {
239
+ active_prio = vec->prio;
240
+ }
241
+ }
242
+
243
+ s->vectpending = pend_irq;
244
+ s->exception_prio = active_prio & nvic_gprio_mask(s);
245
+
246
+ trace_nvic_recompute_state(s->vectpending, s->exception_prio);
247
+}
248
+
249
+/* Return the current execution priority of the CPU
250
+ * (equivalent to the pseudocode ExecutionPriority function).
251
+ * This is a value between -2 (NMI priority) and NVIC_NOEXC_PRIO.
252
+ */
253
+static inline int nvic_exec_prio(NVICState *s)
254
+{
255
+ CPUARMState *env = &s->cpu->env;
256
+ int running;
257
+
258
+ if (env->daif & PSTATE_F) { /* FAULTMASK */
259
+ running = -1;
260
+ } else if (env->daif & PSTATE_I) { /* PRIMASK */
261
+ running = 0;
262
+ } else if (env->v7m.basepri > 0) {
263
+ running = env->v7m.basepri & nvic_gprio_mask(s);
264
+ } else {
265
+ running = NVIC_NOEXC_PRIO; /* lower than any possible priority */
266
+ }
267
+ /* consider priority of active handler */
268
+ return MIN(running, s->exception_prio);
269
+}
270
+
271
+/* caller must call nvic_irq_update() after this */
272
+static void set_prio(NVICState *s, unsigned irq, uint8_t prio)
273
+{
274
+ assert(irq > ARMV7M_EXCP_NMI); /* only use for configurable prios */
275
+ assert(irq < s->num_irq);
276
+
277
+ s->vectors[irq].prio = prio;
278
+
279
+ trace_nvic_set_prio(irq, prio);
280
+}
281
+
282
+/* Recompute state and assert irq line accordingly.
283
+ * Must be called after changes to:
284
+ * vec->active, vec->enabled, vec->pending or vec->prio for any vector
285
+ * prigroup
286
+ */
287
+static void nvic_irq_update(NVICState *s)
288
+{
289
+ int lvl;
290
+ int pend_prio;
291
+
292
+ nvic_recompute_state(s);
293
+ pend_prio = nvic_pending_prio(s);
294
+
295
+ /* Raise NVIC output if this IRQ would be taken, except that we
296
+ * ignore the effects of the BASEPRI, FAULTMASK and PRIMASK (which
297
+ * will be checked for in arm_v7m_cpu_exec_interrupt()); changes
298
+ * to those CPU registers don't cause us to recalculate the NVIC
299
+ * pending info.
300
+ */
301
+ lvl = (pend_prio < s->exception_prio);
302
+ trace_nvic_irq_update(s->vectpending, pend_prio, s->exception_prio, lvl);
303
+ qemu_set_irq(s->excpout, lvl);
304
+}
305
+
306
+static void armv7m_nvic_clear_pending(void *opaque, int irq)
307
+{
308
+ NVICState *s = (NVICState *)opaque;
309
+ VecInfo *vec;
310
+
311
+ assert(irq > ARMV7M_EXCP_RESET && irq < s->num_irq);
312
+
313
+ vec = &s->vectors[irq];
314
+ trace_nvic_clear_pending(irq, vec->enabled, vec->prio);
315
+ if (vec->pending) {
316
+ vec->pending = 0;
317
+ nvic_irq_update(s);
318
+ }
319
+}
320
+
321
void armv7m_nvic_set_pending(void *opaque, int irq)
322
{
323
NVICState *s = (NVICState *)opaque;
324
- if (irq >= 16)
325
- irq += 16;
326
- gic_set_pending_private(&s->gic, 0, irq);
327
+ VecInfo *vec;
328
+
329
+ assert(irq > ARMV7M_EXCP_RESET && irq < s->num_irq);
330
+
331
+ vec = &s->vectors[irq];
332
+ trace_nvic_set_pending(irq, vec->enabled, vec->prio);
333
+ if (!vec->pending) {
334
+ vec->pending = 1;
335
+ nvic_irq_update(s);
336
+ }
337
}
338
339
/* Make pending IRQ active. */
340
int armv7m_nvic_acknowledge_irq(void *opaque)
341
{
342
NVICState *s = (NVICState *)opaque;
343
- uint32_t irq;
344
-
345
- irq = gic_acknowledge_irq(&s->gic, 0, MEMTXATTRS_UNSPECIFIED);
346
- if (irq == 1023)
347
- hw_error("Interrupt but no vector\n");
348
- if (irq >= 32)
349
- irq -= 16;
350
- return irq;
351
+ CPUARMState *env = &s->cpu->env;
352
+ const int pending = s->vectpending;
353
+ const int running = nvic_exec_prio(s);
354
+ int pendgroupprio;
355
+ VecInfo *vec;
356
+
357
+ assert(pending > ARMV7M_EXCP_RESET && pending < s->num_irq);
358
+
359
+ vec = &s->vectors[pending];
360
+
361
+ assert(vec->enabled);
362
+ assert(vec->pending);
363
+
364
+ pendgroupprio = vec->prio & nvic_gprio_mask(s);
365
+ assert(pendgroupprio < running);
366
+
367
+ trace_nvic_acknowledge_irq(pending, vec->prio);
368
+
369
+ vec->active = 1;
370
+ vec->pending = 0;
371
+
372
+ env->v7m.exception = s->vectpending;
373
+
374
+ nvic_irq_update(s);
375
+
376
+ return env->v7m.exception;
377
}
378
379
void armv7m_nvic_complete_irq(void *opaque, int irq)
380
{
381
NVICState *s = (NVICState *)opaque;
382
- if (irq >= 16)
383
- irq += 16;
384
- gic_complete_irq(&s->gic, 0, irq, MEMTXATTRS_UNSPECIFIED);
385
+ VecInfo *vec;
386
+
387
+ assert(irq > ARMV7M_EXCP_RESET && irq < s->num_irq);
388
+
389
+ vec = &s->vectors[irq];
390
+
391
+ trace_nvic_complete_irq(irq);
392
+
393
+ vec->active = 0;
394
+ if (vec->level) {
395
+ /* Re-pend the exception if it's still held high; only
396
+ * happens for extenal IRQs
397
+ */
398
+ assert(irq >= NVIC_FIRST_IRQ);
399
+ vec->pending = 1;
400
+ }
401
+
402
+ nvic_irq_update(s);
403
+}
404
+
405
+/* callback when external interrupt line is changed */
406
+static void set_irq_level(void *opaque, int n, int level)
407
+{
408
+ NVICState *s = opaque;
409
+ VecInfo *vec;
410
+
411
+ n += NVIC_FIRST_IRQ;
412
+
413
+ assert(n >= NVIC_FIRST_IRQ && n < s->num_irq);
414
+
415
+ trace_nvic_set_irq_level(n, level);
416
+
417
+ /* The pending status of an external interrupt is
418
+ * latched on rising edge and exception handler return.
419
+ *
420
+ * Pulsing the IRQ will always run the handler
421
+ * once, and the handler will re-run until the
422
+ * level is low when the handler completes.
423
+ */
424
+ vec = &s->vectors[n];
425
+ if (level != vec->level) {
426
+ vec->level = level;
427
+ if (level) {
428
+ armv7m_nvic_set_pending(s, n);
429
+ }
430
+ }
431
}
432
433
static uint32_t nvic_readl(NVICState *s, uint32_t offset)
434
{
435
ARMCPU *cpu = s->cpu;
436
uint32_t val;
437
- int irq;
438
439
switch (offset) {
440
case 4: /* Interrupt Control Type. */
441
- return (s->num_irq / 32) - 1;
442
+ return ((s->num_irq - NVIC_FIRST_IRQ) / 32) - 1;
443
case 0x10: /* SysTick Control and Status. */
444
val = s->systick.control;
445
s->systick.control &= ~SYSTICK_COUNTFLAG;
446
@@ -XXX,XX +XXX,XX @@ static uint32_t nvic_readl(NVICState *s, uint32_t offset)
447
case 0xd04: /* Interrupt Control State. */
448
/* VECTACTIVE */
449
val = cpu->env.v7m.exception;
450
- if (val == 1023) {
451
- val = 0;
452
- } else if (val >= 32) {
453
- val -= 16;
454
- }
455
/* VECTPENDING */
456
- if (s->gic.current_pending[0] != 1023)
457
- val |= (s->gic.current_pending[0] << 12);
458
- /* ISRPENDING and RETTOBASE */
459
- for (irq = 32; irq < s->num_irq; irq++) {
460
- if (s->gic.irq_state[irq].pending) {
461
- val |= (1 << 22);
462
- break;
463
- }
464
- if (irq != cpu->env.v7m.exception && s->gic.irq_state[irq].active) {
465
- val |= (1 << 11);
466
- }
467
+ val |= (s->vectpending & 0xff) << 12;
468
+ /* ISRPENDING - set if any external IRQ is pending */
469
+ if (nvic_isrpending(s)) {
470
+ val |= (1 << 22);
471
+ }
472
+ /* RETTOBASE - set if only one handler is active */
473
+ if (nvic_rettobase(s)) {
474
+ val |= (1 << 11);
475
}
476
/* PENDSTSET */
477
- if (s->gic.irq_state[ARMV7M_EXCP_SYSTICK].pending)
478
+ if (s->vectors[ARMV7M_EXCP_SYSTICK].pending) {
479
val |= (1 << 26);
480
+ }
481
/* PENDSVSET */
482
- if (s->gic.irq_state[ARMV7M_EXCP_PENDSV].pending)
483
+ if (s->vectors[ARMV7M_EXCP_PENDSV].pending) {
484
val |= (1 << 28);
485
+ }
486
/* NMIPENDSET */
487
- if (s->gic.irq_state[ARMV7M_EXCP_NMI].pending)
488
+ if (s->vectors[ARMV7M_EXCP_NMI].pending) {
489
val |= (1 << 31);
490
+ }
491
+ /* ISRPREEMPT not implemented */
492
return val;
493
case 0xd08: /* Vector Table Offset. */
494
return cpu->env.v7m.vecbase;
495
@@ -XXX,XX +XXX,XX @@ static uint32_t nvic_readl(NVICState *s, uint32_t offset)
496
return cpu->env.v7m.ccr;
497
case 0xd24: /* System Handler Status. */
498
val = 0;
499
- if (s->gic.irq_state[ARMV7M_EXCP_MEM].active) val |= (1 << 0);
500
- if (s->gic.irq_state[ARMV7M_EXCP_BUS].active) val |= (1 << 1);
501
- if (s->gic.irq_state[ARMV7M_EXCP_USAGE].active) val |= (1 << 3);
502
- if (s->gic.irq_state[ARMV7M_EXCP_SVC].active) val |= (1 << 7);
503
- if (s->gic.irq_state[ARMV7M_EXCP_DEBUG].active) val |= (1 << 8);
504
- if (s->gic.irq_state[ARMV7M_EXCP_PENDSV].active) val |= (1 << 10);
505
- if (s->gic.irq_state[ARMV7M_EXCP_SYSTICK].active) val |= (1 << 11);
506
- if (s->gic.irq_state[ARMV7M_EXCP_USAGE].pending) val |= (1 << 12);
507
- if (s->gic.irq_state[ARMV7M_EXCP_MEM].pending) val |= (1 << 13);
508
- if (s->gic.irq_state[ARMV7M_EXCP_BUS].pending) val |= (1 << 14);
509
- if (s->gic.irq_state[ARMV7M_EXCP_SVC].pending) val |= (1 << 15);
510
- if (s->gic.irq_state[ARMV7M_EXCP_MEM].enabled) val |= (1 << 16);
511
- if (s->gic.irq_state[ARMV7M_EXCP_BUS].enabled) val |= (1 << 17);
512
- if (s->gic.irq_state[ARMV7M_EXCP_USAGE].enabled) val |= (1 << 18);
513
+ if (s->vectors[ARMV7M_EXCP_MEM].active) {
514
+ val |= (1 << 0);
515
+ }
516
+ if (s->vectors[ARMV7M_EXCP_BUS].active) {
517
+ val |= (1 << 1);
518
+ }
519
+ if (s->vectors[ARMV7M_EXCP_USAGE].active) {
520
+ val |= (1 << 3);
521
+ }
522
+ if (s->vectors[ARMV7M_EXCP_SVC].active) {
523
+ val |= (1 << 7);
524
+ }
525
+ if (s->vectors[ARMV7M_EXCP_DEBUG].active) {
526
+ val |= (1 << 8);
527
+ }
528
+ if (s->vectors[ARMV7M_EXCP_PENDSV].active) {
529
+ val |= (1 << 10);
530
+ }
531
+ if (s->vectors[ARMV7M_EXCP_SYSTICK].active) {
532
+ val |= (1 << 11);
533
+ }
534
+ if (s->vectors[ARMV7M_EXCP_USAGE].pending) {
535
+ val |= (1 << 12);
536
+ }
537
+ if (s->vectors[ARMV7M_EXCP_MEM].pending) {
538
+ val |= (1 << 13);
539
+ }
540
+ if (s->vectors[ARMV7M_EXCP_BUS].pending) {
541
+ val |= (1 << 14);
542
+ }
543
+ if (s->vectors[ARMV7M_EXCP_SVC].pending) {
544
+ val |= (1 << 15);
545
+ }
546
+ if (s->vectors[ARMV7M_EXCP_MEM].enabled) {
547
+ val |= (1 << 16);
548
+ }
549
+ if (s->vectors[ARMV7M_EXCP_BUS].enabled) {
550
+ val |= (1 << 17);
551
+ }
552
+ if (s->vectors[ARMV7M_EXCP_USAGE].enabled) {
553
+ val |= (1 << 18);
554
+ }
555
return val;
556
case 0xd28: /* Configurable Fault Status. */
557
return cpu->env.v7m.cfsr;
558
@@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value)
559
if (value & (1 << 28)) {
560
armv7m_nvic_set_pending(s, ARMV7M_EXCP_PENDSV);
561
} else if (value & (1 << 27)) {
562
- s->gic.irq_state[ARMV7M_EXCP_PENDSV].pending = 0;
563
- gic_update(&s->gic);
564
+ armv7m_nvic_clear_pending(s, ARMV7M_EXCP_PENDSV);
565
}
566
if (value & (1 << 26)) {
567
armv7m_nvic_set_pending(s, ARMV7M_EXCP_SYSTICK);
568
} else if (value & (1 << 25)) {
569
- s->gic.irq_state[ARMV7M_EXCP_SYSTICK].pending = 0;
570
- gic_update(&s->gic);
571
+ armv7m_nvic_clear_pending(s, ARMV7M_EXCP_SYSTICK);
572
}
573
break;
574
case 0xd08: /* Vector Table Offset. */
575
@@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value)
576
qemu_log_mask(LOG_UNIMP, "AIRCR system reset unimplemented\n");
577
}
578
s->prigroup = extract32(value, 8, 3);
579
+ nvic_irq_update(s);
580
}
581
break;
582
case 0xd10: /* System Control. */
583
@@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value)
584
case 0xd24: /* System Handler Control. */
585
/* TODO: Real hardware allows you to set/clear the active bits
586
under some circumstances. We don't implement this. */
587
- s->gic.irq_state[ARMV7M_EXCP_MEM].enabled = (value & (1 << 16)) != 0;
588
- s->gic.irq_state[ARMV7M_EXCP_BUS].enabled = (value & (1 << 17)) != 0;
589
- s->gic.irq_state[ARMV7M_EXCP_USAGE].enabled = (value & (1 << 18)) != 0;
590
+ s->vectors[ARMV7M_EXCP_MEM].enabled = (value & (1 << 16)) != 0;
591
+ s->vectors[ARMV7M_EXCP_BUS].enabled = (value & (1 << 17)) != 0;
592
+ s->vectors[ARMV7M_EXCP_USAGE].enabled = (value & (1 << 18)) != 0;
593
+ nvic_irq_update(s);
594
break;
595
case 0xd28: /* Configurable Fault Status. */
596
cpu->env.v7m.cfsr &= ~value; /* W1C */
597
@@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value)
598
"NVIC: Aux fault status registers unimplemented\n");
599
break;
600
case 0xf00: /* Software Triggered Interrupt Register */
601
+ {
602
/* user mode can only write to STIR if CCR.USERSETMPEND permits it */
603
- if ((value & 0x1ff) < s->num_irq &&
604
+ int excnum = (value & 0x1ff) + NVIC_FIRST_IRQ;
605
+ if (excnum < s->num_irq &&
606
(arm_current_el(&cpu->env) ||
607
(cpu->env.v7m.ccr & R_V7M_CCR_USERSETMPEND_MASK))) {
608
- gic_set_pending_private(&s->gic, 0, value & 0x1ff);
609
+ armv7m_nvic_set_pending(s, excnum);
610
}
611
break;
612
+ }
613
default:
614
qemu_log_mask(LOG_GUEST_ERROR,
615
"NVIC: Bad write offset 0x%x\n", offset);
616
@@ -XXX,XX +XXX,XX @@ static uint64_t nvic_sysreg_read(void *opaque, hwaddr addr,
617
{
618
NVICState *s = (NVICState *)opaque;
619
uint32_t offset = addr;
620
- int i;
621
+ unsigned i, startvec, end;
622
uint32_t val;
623
624
switch (offset) {
625
+ /* reads of set and clear both return the status */
626
+ case 0x100 ... 0x13f: /* NVIC Set enable */
627
+ offset += 0x80;
628
+ /* fall through */
629
+ case 0x180 ... 0x1bf: /* NVIC Clear enable */
630
+ val = 0;
631
+ startvec = offset - 0x180 + NVIC_FIRST_IRQ; /* vector # */
632
+
633
+ for (i = 0, end = size * 8; i < end && startvec + i < s->num_irq; i++) {
634
+ if (s->vectors[startvec + i].enabled) {
635
+ val |= (1 << i);
636
+ }
637
+ }
638
+ break;
639
+ case 0x200 ... 0x23f: /* NVIC Set pend */
640
+ offset += 0x80;
641
+ /* fall through */
642
+ case 0x280 ... 0x2bf: /* NVIC Clear pend */
643
+ val = 0;
644
+ startvec = offset - 0x280 + NVIC_FIRST_IRQ; /* vector # */
645
+ for (i = 0, end = size * 8; i < end && startvec + i < s->num_irq; i++) {
646
+ if (s->vectors[startvec + i].pending) {
647
+ val |= (1 << i);
648
+ }
649
+ }
650
+ break;
651
+ case 0x300 ... 0x33f: /* NVIC Active */
652
+ val = 0;
653
+ startvec = offset - 0x300 + NVIC_FIRST_IRQ; /* vector # */
654
+
655
+ for (i = 0, end = size * 8; i < end && startvec + i < s->num_irq; i++) {
656
+ if (s->vectors[startvec + i].active) {
657
+ val |= (1 << i);
658
+ }
659
+ }
660
+ break;
661
+ case 0x400 ... 0x5ef: /* NVIC Priority */
662
+ val = 0;
663
+ startvec = offset - 0x400 + NVIC_FIRST_IRQ; /* vector # */
664
+
665
+ for (i = 0; i < size && startvec + i < s->num_irq; i++) {
666
+ val |= s->vectors[startvec + i].prio << (8 * i);
667
+ }
668
+ break;
669
case 0xd18 ... 0xd23: /* System Handler Priority. */
670
val = 0;
671
for (i = 0; i < size; i++) {
672
- val |= s->gic.priority1[(offset - 0xd14) + i][0] << (i * 8);
673
+ val |= s->vectors[(offset - 0xd14) + i].prio << (i * 8);
674
}
675
- return val;
676
+ break;
677
case 0xfe0 ... 0xfff: /* ID. */
678
if (offset & 3) {
679
- return 0;
680
+ val = 0;
681
+ } else {
682
+ val = nvic_id[(offset - 0xfe0) >> 2];
683
+ }
684
+ break;
685
+ default:
686
+ if (size == 4) {
687
+ val = nvic_readl(s, offset);
688
+ } else {
689
+ qemu_log_mask(LOG_GUEST_ERROR,
690
+ "NVIC: Bad read of size %d at offset 0x%x\n",
691
+ size, offset);
692
+ val = 0;
693
}
694
- return nvic_id[(offset - 0xfe0) >> 2];
695
- }
696
- if (size == 4) {
697
- return nvic_readl(s, offset);
698
}
699
- qemu_log_mask(LOG_GUEST_ERROR,
700
- "NVIC: Bad read of size %d at offset 0x%x\n", size, offset);
701
- return 0;
702
+
703
+ trace_nvic_sysreg_read(addr, val, size);
704
+ return val;
705
}
706
707
static void nvic_sysreg_write(void *opaque, hwaddr addr,
708
@@ -XXX,XX +XXX,XX @@ static void nvic_sysreg_write(void *opaque, hwaddr addr,
709
{
710
NVICState *s = (NVICState *)opaque;
711
uint32_t offset = addr;
712
- int i;
713
+ unsigned i, startvec, end;
714
+ unsigned setval = 0;
715
+
716
+ trace_nvic_sysreg_write(addr, value, size);
717
718
switch (offset) {
719
+ case 0x100 ... 0x13f: /* NVIC Set enable */
720
+ offset += 0x80;
721
+ setval = 1;
722
+ /* fall through */
723
+ case 0x180 ... 0x1bf: /* NVIC Clear enable */
724
+ startvec = 8 * (offset - 0x180) + NVIC_FIRST_IRQ;
725
+
726
+ for (i = 0, end = size * 8; i < end && startvec + i < s->num_irq; i++) {
727
+ if (value & (1 << i)) {
728
+ s->vectors[startvec + i].enabled = setval;
729
+ }
730
+ }
731
+ nvic_irq_update(s);
732
+ return;
733
+ case 0x200 ... 0x23f: /* NVIC Set pend */
734
+ /* the special logic in armv7m_nvic_set_pending()
735
+ * is not needed since IRQs are never escalated
736
+ */
737
+ offset += 0x80;
738
+ setval = 1;
739
+ /* fall through */
740
+ case 0x280 ... 0x2bf: /* NVIC Clear pend */
741
+ startvec = 8 * (offset - 0x280) + NVIC_FIRST_IRQ; /* vector # */
742
+
743
+ for (i = 0, end = size * 8; i < end && startvec + i < s->num_irq; i++) {
744
+ if (value & (1 << i)) {
745
+ s->vectors[startvec + i].pending = setval;
746
+ }
747
+ }
748
+ nvic_irq_update(s);
749
+ return;
750
+ case 0x300 ... 0x33f: /* NVIC Active */
751
+ return; /* R/O */
752
+ case 0x400 ... 0x5ef: /* NVIC Priority */
753
+ startvec = 8 * (offset - 0x400) + NVIC_FIRST_IRQ; /* vector # */
754
+
755
+ for (i = 0; i < size && startvec + i < s->num_irq; i++) {
756
+ set_prio(s, startvec + i, (value >> (i * 8)) & 0xff);
757
+ }
758
+ nvic_irq_update(s);
759
+ return;
760
case 0xd18 ... 0xd23: /* System Handler Priority. */
761
for (i = 0; i < size; i++) {
762
- s->gic.priority1[(offset - 0xd14) + i][0] =
763
- (value >> (i * 8)) & 0xff;
764
+ unsigned hdlidx = (offset - 0xd14) + i;
765
+ set_prio(s, hdlidx, (value >> (i * 8)) & 0xff);
766
}
767
- gic_update(&s->gic);
768
+ nvic_irq_update(s);
769
return;
770
}
771
if (size == 4) {
772
@@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps nvic_sysreg_ops = {
773
.endianness = DEVICE_NATIVE_ENDIAN,
774
};
775
776
+static int nvic_post_load(void *opaque, int version_id)
777
+{
778
+ NVICState *s = opaque;
779
+ unsigned i;
780
+
781
+ /* Check for out of range priority settings */
782
+ if (s->vectors[ARMV7M_EXCP_RESET].prio != -3 ||
783
+ s->vectors[ARMV7M_EXCP_NMI].prio != -2 ||
784
+ s->vectors[ARMV7M_EXCP_HARD].prio != -1) {
785
+ return 1;
786
+ }
787
+ for (i = ARMV7M_EXCP_MEM; i < s->num_irq; i++) {
788
+ if (s->vectors[i].prio & ~0xff) {
789
+ return 1;
790
+ }
791
+ }
792
+
793
+ nvic_recompute_state(s);
794
+
795
+ return 0;
796
+}
797
+
798
+static const VMStateDescription vmstate_VecInfo = {
799
+ .name = "armv7m_nvic_info",
800
+ .version_id = 1,
801
+ .minimum_version_id = 1,
802
+ .fields = (VMStateField[]) {
803
+ VMSTATE_INT16(prio, VecInfo),
804
+ VMSTATE_UINT8(enabled, VecInfo),
805
+ VMSTATE_UINT8(pending, VecInfo),
806
+ VMSTATE_UINT8(active, VecInfo),
807
+ VMSTATE_UINT8(level, VecInfo),
808
+ VMSTATE_END_OF_LIST()
809
+ }
810
+};
811
+
812
static const VMStateDescription vmstate_nvic = {
813
.name = "armv7m_nvic",
814
- .version_id = 2,
815
- .minimum_version_id = 2,
816
+ .version_id = 3,
817
+ .minimum_version_id = 3,
818
+ .post_load = &nvic_post_load,
819
.fields = (VMStateField[]) {
820
+ VMSTATE_STRUCT_ARRAY(vectors, NVICState, NVIC_MAX_VECTORS, 1,
821
+ vmstate_VecInfo, VecInfo),
822
VMSTATE_UINT32(systick.control, NVICState),
823
VMSTATE_UINT32(systick.reload, NVICState),
824
VMSTATE_INT64(systick.tick, NVICState),
825
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_nvic = {
826
}
827
};
828
829
+static Property props_nvic[] = {
830
+ /* Number of external IRQ lines (so excluding the 16 internal exceptions) */
831
+ DEFINE_PROP_UINT32("num-irq", NVICState, num_irq, 64),
832
+ DEFINE_PROP_END_OF_LIST()
833
+};
834
+
835
static void armv7m_nvic_reset(DeviceState *dev)
836
{
837
NVICState *s = NVIC(dev);
838
- NVICClass *nc = NVIC_GET_CLASS(s);
839
- nc->parent_reset(dev);
840
- /* Common GIC reset resets to disabled; the NVIC doesn't have
841
- * per-CPU interfaces so mark our non-existent CPU interface
842
- * as enabled by default, and with a priority mask which allows
843
- * all interrupts through.
844
+
845
+ s->vectors[ARMV7M_EXCP_NMI].enabled = 1;
846
+ s->vectors[ARMV7M_EXCP_HARD].enabled = 1;
847
+ /* MEM, BUS, and USAGE are enabled through
848
+ * the System Handler Control register
849
*/
850
- s->gic.cpu_ctlr[0] = GICC_CTLR_EN_GRP0;
851
- s->gic.priority_mask[0] = 0x100;
852
- /* The NVIC as a whole is always enabled. */
853
- s->gic.ctlr = 1;
854
+ s->vectors[ARMV7M_EXCP_SVC].enabled = 1;
855
+ s->vectors[ARMV7M_EXCP_DEBUG].enabled = 1;
856
+ s->vectors[ARMV7M_EXCP_PENDSV].enabled = 1;
857
+ s->vectors[ARMV7M_EXCP_SYSTICK].enabled = 1;
858
+
859
+ s->vectors[ARMV7M_EXCP_RESET].prio = -3;
860
+ s->vectors[ARMV7M_EXCP_NMI].prio = -2;
861
+ s->vectors[ARMV7M_EXCP_HARD].prio = -1;
862
+
863
+ /* Strictly speaking the reset handler should be enabled.
864
+ * However, we don't simulate soft resets through the NVIC,
865
+ * and the reset vector should never be pended.
866
+ * So we leave it disabled to catch logic errors.
867
+ */
868
+
869
+ s->exception_prio = NVIC_NOEXC_PRIO;
870
+ s->vectpending = 0;
871
+
872
systick_reset(s);
873
}
874
875
static void armv7m_nvic_realize(DeviceState *dev, Error **errp)
876
{
877
NVICState *s = NVIC(dev);
878
- NVICClass *nc = NVIC_GET_CLASS(s);
879
- Error *local_err = NULL;
880
881
s->cpu = ARM_CPU(qemu_get_cpu(0));
882
assert(s->cpu);
883
- /* The NVIC always has only one CPU */
884
- s->gic.num_cpu = 1;
885
- /* Tell the common code we're an NVIC */
886
- s->gic.revision = 0xffffffff;
887
- s->num_irq = s->gic.num_irq;
888
- nc->parent_realize(dev, &local_err);
889
- if (local_err) {
890
- error_propagate(errp, local_err);
891
+
892
+ if (s->num_irq > NVIC_MAX_IRQ) {
893
+ error_setg(errp, "num-irq %d exceeds NVIC maximum", s->num_irq);
894
return;
895
}
896
- gic_init_irqs_and_distributor(&s->gic);
897
- /* The NVIC and system controller register area looks like this:
898
- * 0..0xff : system control registers, including systick
899
- * 0x100..0xcff : GIC-like registers
900
- * 0xd00..0xfff : system control registers
901
- * We use overlaying to put the GIC like registers
902
- * over the top of the system control register region.
903
+
904
+ qdev_init_gpio_in(dev, set_irq_level, s->num_irq);
905
+
906
+ /* include space for internal exception vectors */
907
+ s->num_irq += NVIC_FIRST_IRQ;
908
+
909
+ /* The NVIC and System Control Space (SCS) starts at 0xe000e000
910
+ * and looks like this:
911
+ * 0x004 - ICTR
912
+ * 0x010 - 0x1c - systick
913
+ * 0x100..0x7ec - NVIC
914
+ * 0x7f0..0xcff - Reserved
915
+ * 0xd00..0xd3c - SCS registers
916
+ * 0xd40..0xeff - Reserved or Not implemented
917
+ * 0xf00 - STIR
918
+ *
919
+ * At the moment there is only one thing in the container region,
920
+ * but we leave it in place to allow us to pull systick out into
921
+ * its own device object later.
922
*/
923
memory_region_init(&s->container, OBJECT(s), "nvic", 0x1000);
924
/* The system register region goes at the bottom of the priority
925
@@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_realize(DeviceState *dev, Error **errp)
926
memory_region_init_io(&s->sysregmem, OBJECT(s), &nvic_sysreg_ops, s,
927
"nvic_sysregs", 0x1000);
928
memory_region_add_subregion(&s->container, 0, &s->sysregmem);
929
- /* Alias the GIC region so we can get only the section of it
930
- * we need, and layer it on top of the system register region.
931
- */
932
- memory_region_init_alias(&s->gic_iomem_alias, OBJECT(s),
933
- "nvic-gic", &s->gic.iomem,
934
- 0x100, 0xc00);
935
- memory_region_add_subregion_overlap(&s->container, 0x100,
936
- &s->gic_iomem_alias, 1);
937
+
938
/* Map the whole thing into system memory at the location required
939
* by the v7M architecture.
940
*/
941
@@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_instance_init(Object *obj)
942
* any user-specified property setting, so just modify the
943
* value in the GICState struct.
944
*/
945
- GICState *s = ARM_GIC_COMMON(obj);
946
DeviceState *dev = DEVICE(obj);
947
NVICState *nvic = NVIC(obj);
948
- /* The ARM v7m may have anything from 0 to 496 external interrupt
949
- * IRQ lines. We default to 64. Other boards may differ and should
950
- * set the num-irq property appropriately.
951
- */
952
- s->num_irq = 64;
953
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
954
+
955
+ sysbus_init_irq(sbd, &nvic->excpout);
956
qdev_init_gpio_out_named(dev, &nvic->sysresetreq, "SYSRESETREQ", 1);
957
}
958
959
static void armv7m_nvic_class_init(ObjectClass *klass, void *data)
960
{
961
- NVICClass *nc = NVIC_CLASS(klass);
962
DeviceClass *dc = DEVICE_CLASS(klass);
963
964
- nc->parent_reset = dc->reset;
965
- nc->parent_realize = dc->realize;
966
dc->vmsd = &vmstate_nvic;
967
+ dc->props = props_nvic;
968
dc->reset = armv7m_nvic_reset;
969
dc->realize = armv7m_nvic_realize;
970
}
971
972
static const TypeInfo armv7m_nvic_info = {
973
.name = TYPE_NVIC,
974
- .parent = TYPE_ARM_GIC_COMMON,
975
+ .parent = TYPE_SYS_BUS_DEVICE,
976
.instance_init = armv7m_nvic_instance_init,
977
.instance_size = sizeof(NVICState),
978
.class_init = armv7m_nvic_class_init,
979
- .class_size = sizeof(NVICClass),
980
+ .class_size = sizeof(SysBusDeviceClass),
981
};
982
983
static void armv7m_nvic_register_types(void)
984
diff --git a/hw/intc/trace-events b/hw/intc/trace-events
985
index XXXXXXX..XXXXXXX 100644
986
--- a/hw/intc/trace-events
987
+++ b/hw/intc/trace-events
988
@@ -XXX,XX +XXX,XX @@ gicv3_redist_write(uint32_t cpu, uint64_t offset, uint64_t data, unsigned size,
989
gicv3_redist_badwrite(uint32_t cpu, uint64_t offset, uint64_t data, unsigned size, bool secure) "GICv3 redistributor %x write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u secure %d: error"
990
gicv3_redist_set_irq(uint32_t cpu, int irq, int level) "GICv3 redistributor %x interrupt %d level changed to %d"
991
gicv3_redist_send_sgi(uint32_t cpu, int irq) "GICv3 redistributor %x pending SGI %d"
992
+
993
+# hw/intc/armv7m_nvic.c
994
+nvic_recompute_state(int vectpending, int exception_prio) "NVIC state recomputed: vectpending %d exception_prio %d"
995
+nvic_set_prio(int irq, uint8_t prio) "NVIC set irq %d priority %d"
996
+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"
997
+nvic_escalate_prio(int irq, int irqprio, int runprio) "NVIC escalating irq %d to HardFault: insufficient priority %d >= %d"
998
+nvic_escalate_disabled(int irq) "NVIC escalating irq %d to HardFault: disabled"
999
+nvic_set_pending(int irq, int en, int prio) "NVIC set pending irq %d (enabled: %d priority %d)"
1000
+nvic_clear_pending(int irq, int en, int prio) "NVIC clear pending irq %d (enabled: %d priority %d)"
1001
+nvic_set_pending_level(int irq) "NVIC set pending: irq %d higher prio than vectpending: setting irq line to 1"
1002
+nvic_acknowledge_irq(int irq, int prio) "NVIC acknowledge IRQ: %d now active (prio %d)"
1003
+nvic_complete_irq(int irq) "NVIC complete IRQ %d"
1004
+nvic_set_irq_level(int irq, int level) "NVIC external irq %d level set to %d"
1005
+nvic_sysreg_read(uint64_t addr, uint32_t value, unsigned size) "NVIC sysreg read addr 0x%" PRIx64 " data 0x%" PRIx32 " size %u"
1006
+nvic_sysreg_write(uint64_t addr, uint32_t value, unsigned size) "NVIC sysreg write addr 0x%" PRIx64 " data 0x%" PRIx32 " size %u"
1007
--
1008
2.7.4
1009
1010
diff view generated by jsdifflib
Deleted patch
1
The M profile condition for when we can take a pending exception or
2
interrupt is not the same as that for A/R profile. The code
3
originally copied from the A/R profile version of the
4
cpu_exec_interrupt function only worked by chance for the
5
very simple case of exceptions being masked by PRIMASK.
6
Replace it with a call to a function in the NVIC code that
7
correctly compares the priority of the pending exception
8
against the current execution priority of the CPU.
9
1
10
[Michael Davidsaver's patchset had a patch to do something
11
similar but the implementation ended up being a rewrite.]
12
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
15
---
16
target/arm/cpu.h | 8 ++++++++
17
hw/intc/armv7m_nvic.c | 7 +++++++
18
target/arm/cpu.c | 16 ++++++++--------
19
3 files changed, 23 insertions(+), 8 deletions(-)
20
21
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
22
index XXXXXXX..XXXXXXX 100644
23
--- a/target/arm/cpu.h
24
+++ b/target/arm/cpu.h
25
@@ -XXX,XX +XXX,XX @@ uint32_t arm_phys_excp_target_el(CPUState *cs, uint32_t excp_idx,
26
uint32_t cur_el, bool secure);
27
28
/* Interface between CPU and Interrupt controller. */
29
+#ifndef CONFIG_USER_ONLY
30
+bool armv7m_nvic_can_take_pending_exception(void *opaque);
31
+#else
32
+static inline bool armv7m_nvic_can_take_pending_exception(void *opaque)
33
+{
34
+ return true;
35
+}
36
+#endif
37
void armv7m_nvic_set_pending(void *opaque, int irq);
38
int armv7m_nvic_acknowledge_irq(void *opaque);
39
void armv7m_nvic_complete_irq(void *opaque, int irq);
40
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
41
index XXXXXXX..XXXXXXX 100644
42
--- a/hw/intc/armv7m_nvic.c
43
+++ b/hw/intc/armv7m_nvic.c
44
@@ -XXX,XX +XXX,XX @@ static inline int nvic_exec_prio(NVICState *s)
45
return MIN(running, s->exception_prio);
46
}
47
48
+bool armv7m_nvic_can_take_pending_exception(void *opaque)
49
+{
50
+ NVICState *s = opaque;
51
+
52
+ return nvic_exec_prio(s) > nvic_pending_prio(s);
53
+}
54
+
55
/* caller must call nvic_irq_update() after this */
56
static void set_prio(NVICState *s, unsigned irq, uint8_t prio)
57
{
58
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
59
index XXXXXXX..XXXXXXX 100644
60
--- a/target/arm/cpu.c
61
+++ b/target/arm/cpu.c
62
@@ -XXX,XX +XXX,XX @@ static bool arm_v7m_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
63
CPUARMState *env = &cpu->env;
64
bool ret = false;
65
66
-
67
- if (interrupt_request & CPU_INTERRUPT_FIQ
68
- && !(env->daif & PSTATE_F)) {
69
- cs->exception_index = EXCP_FIQ;
70
- cc->do_interrupt(cs);
71
- ret = true;
72
- }
73
/* ARMv7-M interrupt return works by loading a magic value
74
* into the PC. On real hardware the load causes the
75
* return to occur. The qemu implementation performs the
76
@@ -XXX,XX +XXX,XX @@ static bool arm_v7m_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
77
* the stack if an interrupt occurred at the wrong time.
78
* We avoid this by disabling interrupts when
79
* pc contains a magic address.
80
+ *
81
+ * ARMv7-M interrupt masking works differently than -A or -R.
82
+ * There is no FIQ/IRQ distinction. Instead of I and F bits
83
+ * masking FIQ and IRQ interrupts, an exception is taken only
84
+ * if it is higher priority than the current execution priority
85
+ * (which depends on state like BASEPRI, FAULTMASK and the
86
+ * currently active exception).
87
*/
88
if (interrupt_request & CPU_INTERRUPT_HARD
89
- && !(env->daif & PSTATE_I)
90
+ && (armv7m_nvic_can_take_pending_exception(env->nvic))
91
&& (env->regs[15] < 0xfffffff0)) {
92
cs->exception_index = EXCP_IRQ;
93
cc->do_interrupt(cs);
94
--
95
2.7.4
96
97
diff view generated by jsdifflib
Deleted patch
1
From: Michael Davidsaver <mdavidsaver@gmail.com>
2
1
3
Now that the NVIC is its own separate implementation, we can
4
clean up the GIC code by removing REV_NVIC and conditionals
5
which use it.
6
7
Signed-off-by: Michael Davidsaver <mdavidsaver@gmail.com>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
10
---
11
hw/intc/gic_internal.h | 7 ++-----
12
hw/intc/arm_gic.c | 31 +++++--------------------------
13
hw/intc/arm_gic_common.c | 23 ++++++++---------------
14
3 files changed, 15 insertions(+), 46 deletions(-)
15
16
diff --git a/hw/intc/gic_internal.h b/hw/intc/gic_internal.h
17
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/intc/gic_internal.h
19
+++ b/hw/intc/gic_internal.h
20
@@ -XXX,XX +XXX,XX @@
21
22
#define ALL_CPU_MASK ((unsigned)(((1 << GIC_NCPU) - 1)))
23
24
-/* The NVIC has 16 internal vectors. However these are not exposed
25
- through the normal GIC interface. */
26
-#define GIC_BASE_IRQ ((s->revision == REV_NVIC) ? 32 : 0)
27
+#define GIC_BASE_IRQ 0
28
29
#define GIC_SET_ENABLED(irq, cm) s->irq_state[irq].enabled |= (cm)
30
#define GIC_CLEAR_ENABLED(irq, cm) s->irq_state[irq].enabled &= ~(cm)
31
@@ -XXX,XX +XXX,XX @@
32
33
/* The special cases for the revision property: */
34
#define REV_11MPCORE 0
35
-#define REV_NVIC 0xffffffff
36
37
void gic_set_pending_private(GICState *s, int cpu, int irq);
38
uint32_t gic_acknowledge_irq(GICState *s, int cpu, MemTxAttrs attrs);
39
@@ -XXX,XX +XXX,XX @@ void gic_set_priority(GICState *s, int cpu, int irq, uint8_t val,
40
41
static inline bool gic_test_pending(GICState *s, int irq, int cm)
42
{
43
- if (s->revision == REV_NVIC || s->revision == REV_11MPCORE) {
44
+ if (s->revision == REV_11MPCORE) {
45
return s->irq_state[irq].pending & cm;
46
} else {
47
/* Edge-triggered interrupts are marked pending on a rising edge, but
48
diff --git a/hw/intc/arm_gic.c b/hw/intc/arm_gic.c
49
index XXXXXXX..XXXXXXX 100644
50
--- a/hw/intc/arm_gic.c
51
+++ b/hw/intc/arm_gic.c
52
@@ -XXX,XX +XXX,XX @@ static void gic_set_irq_11mpcore(GICState *s, int irq, int level,
53
}
54
}
55
56
-static void gic_set_irq_nvic(GICState *s, int irq, int level,
57
- int cm, int target)
58
-{
59
- if (level) {
60
- GIC_SET_LEVEL(irq, cm);
61
- GIC_SET_PENDING(irq, target);
62
- } else {
63
- GIC_CLEAR_LEVEL(irq, cm);
64
- }
65
-}
66
-
67
static void gic_set_irq_generic(GICState *s, int irq, int level,
68
int cm, int target)
69
{
70
@@ -XXX,XX +XXX,XX @@ static void gic_set_irq(void *opaque, int irq, int level)
71
72
if (s->revision == REV_11MPCORE) {
73
gic_set_irq_11mpcore(s, irq, level, cm, target);
74
- } else if (s->revision == REV_NVIC) {
75
- gic_set_irq_nvic(s, irq, level, cm, target);
76
} else {
77
gic_set_irq_generic(s, irq, level, cm, target);
78
}
79
@@ -XXX,XX +XXX,XX @@ uint32_t gic_acknowledge_irq(GICState *s, int cpu, MemTxAttrs attrs)
80
return 1023;
81
}
82
83
- if (s->revision == REV_11MPCORE || s->revision == REV_NVIC) {
84
+ if (s->revision == REV_11MPCORE) {
85
/* Clear pending flags for both level and edge triggered interrupts.
86
* Level triggered IRQs will be reasserted once they become inactive.
87
*/
88
@@ -XXX,XX +XXX,XX @@ void gic_complete_irq(GICState *s, int cpu, int irq, MemTxAttrs attrs)
89
DPRINTF("Set %d pending mask %x\n", irq, cm);
90
GIC_SET_PENDING(irq, cm);
91
}
92
- } else if (s->revision == REV_NVIC) {
93
- if (GIC_TEST_LEVEL(irq, cm)) {
94
- DPRINTF("Set nvic %d pending mask %x\n", irq, cm);
95
- GIC_SET_PENDING(irq, cm);
96
- }
97
}
98
99
group = gic_has_groups(s) && GIC_TEST_GROUP(irq, cm);
100
@@ -XXX,XX +XXX,XX @@ static uint32_t gic_dist_readb(void *opaque, hwaddr offset, MemTxAttrs attrs)
101
} else if (offset < 0xf10) {
102
goto bad_reg;
103
} else if (offset < 0xf30) {
104
- if (s->revision == REV_11MPCORE || s->revision == REV_NVIC) {
105
+ if (s->revision == REV_11MPCORE) {
106
goto bad_reg;
107
}
108
109
@@ -XXX,XX +XXX,XX @@ static uint32_t gic_dist_readb(void *opaque, hwaddr offset, MemTxAttrs attrs)
110
case 2:
111
res = gic_id_gicv2[(offset - 0xfd0) >> 2];
112
break;
113
- case REV_NVIC:
114
- /* Shouldn't be able to get here */
115
- abort();
116
default:
117
res = 0;
118
}
119
@@ -XXX,XX +XXX,XX @@ static void gic_dist_writeb(void *opaque, hwaddr offset,
120
continue; /* Ignore Non-secure access of Group0 IRQ */
121
}
122
123
- if (s->revision == REV_11MPCORE || s->revision == REV_NVIC) {
124
+ if (s->revision == REV_11MPCORE) {
125
if (value & (1 << (i * 2))) {
126
GIC_SET_MODEL(irq + i);
127
} else {
128
@@ -XXX,XX +XXX,XX @@ static void gic_dist_writeb(void *opaque, hwaddr offset,
129
goto bad_reg;
130
} else if (offset < 0xf20) {
131
/* GICD_CPENDSGIRn */
132
- if (s->revision == REV_11MPCORE || s->revision == REV_NVIC) {
133
+ if (s->revision == REV_11MPCORE) {
134
goto bad_reg;
135
}
136
irq = (offset - 0xf10);
137
@@ -XXX,XX +XXX,XX @@ static void gic_dist_writeb(void *opaque, hwaddr offset,
138
}
139
} else if (offset < 0xf30) {
140
/* GICD_SPENDSGIRn */
141
- if (s->revision == REV_11MPCORE || s->revision == REV_NVIC) {
142
+ if (s->revision == REV_11MPCORE) {
143
goto bad_reg;
144
}
145
irq = (offset - 0xf20);
146
diff --git a/hw/intc/arm_gic_common.c b/hw/intc/arm_gic_common.c
147
index XXXXXXX..XXXXXXX 100644
148
--- a/hw/intc/arm_gic_common.c
149
+++ b/hw/intc/arm_gic_common.c
150
@@ -XXX,XX +XXX,XX @@ void gic_init_irqs_and_mmio(GICState *s, qemu_irq_handler handler,
151
* [N+32..N+63] PPIs for CPU 1
152
* ...
153
*/
154
- if (s->revision != REV_NVIC) {
155
- i += (GIC_INTERNAL * s->num_cpu);
156
- }
157
+ i += (GIC_INTERNAL * s->num_cpu);
158
qdev_init_gpio_in(DEVICE(s), handler, i);
159
160
for (i = 0; i < s->num_cpu; i++) {
161
@@ -XXX,XX +XXX,XX @@ void gic_init_irqs_and_mmio(GICState *s, qemu_irq_handler handler,
162
memory_region_init_io(&s->iomem, OBJECT(s), ops, s, "gic_dist", 0x1000);
163
sysbus_init_mmio(sbd, &s->iomem);
164
165
- if (s->revision != REV_NVIC) {
166
- /* This is the main CPU interface "for this core". It is always
167
- * present because it is required by both software emulation and KVM.
168
- * NVIC is not handled here because its CPU interface is different,
169
- * neither it can use KVM.
170
- */
171
- memory_region_init_io(&s->cpuiomem[0], OBJECT(s), ops ? &ops[1] : NULL,
172
- s, "gic_cpu", s->revision == 2 ? 0x2000 : 0x100);
173
- sysbus_init_mmio(sbd, &s->cpuiomem[0]);
174
- }
175
+ /* This is the main CPU interface "for this core". It is always
176
+ * present because it is required by both software emulation and KVM.
177
+ */
178
+ memory_region_init_io(&s->cpuiomem[0], OBJECT(s), ops ? &ops[1] : NULL,
179
+ s, "gic_cpu", s->revision == 2 ? 0x2000 : 0x100);
180
+ sysbus_init_mmio(sbd, &s->cpuiomem[0]);
181
}
182
183
static void arm_gic_common_realize(DeviceState *dev, Error **errp)
184
@@ -XXX,XX +XXX,XX @@ static void arm_gic_common_realize(DeviceState *dev, Error **errp)
185
}
186
187
if (s->security_extn &&
188
- (s->revision == REV_11MPCORE || s->revision == REV_NVIC)) {
189
+ (s->revision == REV_11MPCORE)) {
190
error_setg(errp, "this GIC revision does not implement "
191
"the security extensions");
192
return;
193
@@ -XXX,XX +XXX,XX @@ static Property arm_gic_common_properties[] = {
194
DEFINE_PROP_UINT32("num-irq", GICState, num_irq, 32),
195
/* Revision can be 1 or 2 for GIC architecture specification
196
* versions 1 or 2, or 0 to indicate the legacy 11MPCore GIC.
197
- * (Internally, 0xffffffff also indicates "not a GIC but an NVIC".)
198
*/
199
DEFINE_PROP_UINT32("revision", GICState, revision, 1),
200
/* True if the GIC should implement the security extensions */
201
--
202
2.7.4
203
204
diff view generated by jsdifflib
Deleted patch
1
From: Michael Davidsaver <mdavidsaver@gmail.com>
2
1
3
The v7M exception architecture requires that if a synchronous
4
exception cannot be taken immediately (because it is disabled
5
or at too low a priority) then it should be escalated to
6
HardFault (and the HardFault exception is then taken).
7
Implement this escalation logic.
8
9
Signed-off-by: Michael Davidsaver <mdavidsaver@gmail.com>
10
[PMM: extracted from another patch]
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
13
---
14
hw/intc/armv7m_nvic.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++
15
target/arm/helper.c | 2 --
16
2 files changed, 53 insertions(+), 2 deletions(-)
17
18
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
19
index XXXXXXX..XXXXXXX 100644
20
--- a/hw/intc/armv7m_nvic.c
21
+++ b/hw/intc/armv7m_nvic.c
22
@@ -XXX,XX +XXX,XX @@ void armv7m_nvic_set_pending(void *opaque, int irq)
23
24
vec = &s->vectors[irq];
25
trace_nvic_set_pending(irq, vec->enabled, vec->prio);
26
+
27
+
28
+ if (irq >= ARMV7M_EXCP_HARD && irq < ARMV7M_EXCP_PENDSV) {
29
+ /* If a synchronous exception is pending then it may be
30
+ * escalated to HardFault if:
31
+ * * it is equal or lower priority to current execution
32
+ * * it is disabled
33
+ * (ie we need to take it immediately but we can't do so).
34
+ * Asynchronous exceptions (and interrupts) simply remain pending.
35
+ *
36
+ * For QEMU, we don't have any imprecise (asynchronous) faults,
37
+ * so we can assume that PREFETCH_ABORT and DATA_ABORT are always
38
+ * synchronous.
39
+ * Debug exceptions are awkward because only Debug exceptions
40
+ * resulting from the BKPT instruction should be escalated,
41
+ * but we don't currently implement any Debug exceptions other
42
+ * than those that result from BKPT, so we treat all debug exceptions
43
+ * as needing escalation.
44
+ *
45
+ * This all means we can identify whether to escalate based only on
46
+ * the exception number and don't (yet) need the caller to explicitly
47
+ * tell us whether this exception is synchronous or not.
48
+ */
49
+ int running = nvic_exec_prio(s);
50
+ bool escalate = false;
51
+
52
+ if (vec->prio >= running) {
53
+ trace_nvic_escalate_prio(irq, vec->prio, running);
54
+ escalate = true;
55
+ } else if (!vec->enabled) {
56
+ trace_nvic_escalate_disabled(irq);
57
+ escalate = true;
58
+ }
59
+
60
+ if (escalate) {
61
+ if (running < 0) {
62
+ /* We want to escalate to HardFault but we can't take a
63
+ * synchronous HardFault at this point either. This is a
64
+ * Lockup condition due to a guest bug. We don't model
65
+ * Lockup, so report via cpu_abort() instead.
66
+ */
67
+ cpu_abort(&s->cpu->parent_obj,
68
+ "Lockup: can't escalate %d to HardFault "
69
+ "(current priority %d)\n", irq, running);
70
+ }
71
+
72
+ /* We can do the escalation, so we take HardFault instead */
73
+ irq = ARMV7M_EXCP_HARD;
74
+ vec = &s->vectors[irq];
75
+ s->cpu->env.v7m.hfsr |= R_V7M_HFSR_FORCED_MASK;
76
+ }
77
+ }
78
+
79
if (!vec->pending) {
80
vec->pending = 1;
81
nvic_irq_update(s);
82
diff --git a/target/arm/helper.c b/target/arm/helper.c
83
index XXXXXXX..XXXXXXX 100644
84
--- a/target/arm/helper.c
85
+++ b/target/arm/helper.c
86
@@ -XXX,XX +XXX,XX @@ void arm_v7m_cpu_do_interrupt(CPUState *cs)
87
88
/* For exceptions we just mark as pending on the NVIC, and let that
89
handle it. */
90
- /* TODO: Need to escalate if the current priority is higher than the
91
- one we're raising. */
92
switch (cs->exception_index) {
93
case EXCP_UDEF:
94
armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE);
95
--
96
2.7.4
97
98
diff view generated by jsdifflib
Deleted patch
1
Having armv7m_nvic_acknowledge_irq() return the new value of
2
env->v7m.exception and its one caller assign the return value
3
back to env->v7m.exception is pointless. Just make the return
4
type void instead.
5
1
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
8
---
9
target/arm/cpu.h | 2 +-
10
hw/intc/armv7m_nvic.c | 4 +---
11
target/arm/helper.c | 2 +-
12
3 files changed, 3 insertions(+), 5 deletions(-)
13
14
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
15
index XXXXXXX..XXXXXXX 100644
16
--- a/target/arm/cpu.h
17
+++ b/target/arm/cpu.h
18
@@ -XXX,XX +XXX,XX @@ static inline bool armv7m_nvic_can_take_pending_exception(void *opaque)
19
}
20
#endif
21
void armv7m_nvic_set_pending(void *opaque, int irq);
22
-int armv7m_nvic_acknowledge_irq(void *opaque);
23
+void armv7m_nvic_acknowledge_irq(void *opaque);
24
void armv7m_nvic_complete_irq(void *opaque, int irq);
25
26
/* Interface for defining coprocessor registers.
27
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
28
index XXXXXXX..XXXXXXX 100644
29
--- a/hw/intc/armv7m_nvic.c
30
+++ b/hw/intc/armv7m_nvic.c
31
@@ -XXX,XX +XXX,XX @@ void armv7m_nvic_set_pending(void *opaque, int irq)
32
}
33
34
/* Make pending IRQ active. */
35
-int armv7m_nvic_acknowledge_irq(void *opaque)
36
+void armv7m_nvic_acknowledge_irq(void *opaque)
37
{
38
NVICState *s = (NVICState *)opaque;
39
CPUARMState *env = &s->cpu->env;
40
@@ -XXX,XX +XXX,XX @@ int armv7m_nvic_acknowledge_irq(void *opaque)
41
env->v7m.exception = s->vectpending;
42
43
nvic_irq_update(s);
44
-
45
- return env->v7m.exception;
46
}
47
48
void armv7m_nvic_complete_irq(void *opaque, int irq)
49
diff --git a/target/arm/helper.c b/target/arm/helper.c
50
index XXXXXXX..XXXXXXX 100644
51
--- a/target/arm/helper.c
52
+++ b/target/arm/helper.c
53
@@ -XXX,XX +XXX,XX @@ void arm_v7m_cpu_do_interrupt(CPUState *cs)
54
armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_DEBUG);
55
return;
56
case EXCP_IRQ:
57
- env->v7m.exception = armv7m_nvic_acknowledge_irq(env->nvic);
58
+ armv7m_nvic_acknowledge_irq(env->nvic);
59
break;
60
case EXCP_EXCEPTION_EXIT:
61
do_v7m_exception_exit(env);
62
--
63
2.7.4
64
65
diff view generated by jsdifflib
Deleted patch
1
From: Michael Davidsaver <mdavidsaver@gmail.com>
2
1
3
All the places in armv7m_cpu_do_interrupt() which pend an
4
exception in the NVIC are doing so for synchronous
5
exceptions. We know that we will always take some
6
exception in this case, so we can just acknowledge it
7
immediately, rather than returning and then immediately
8
being called again because the NVIC has raised its outbound
9
IRQ line.
10
11
Signed-off-by: Michael Davidsaver <mdavidsaver@gmail.com>
12
[PMM: tweaked commit message; added DEBUG to the set of
13
exceptions we handle immediately, since it is synchronous
14
when it results from the BKPT instruction]
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
17
---
18
target/arm/helper.c | 15 +++++++++------
19
1 file changed, 9 insertions(+), 6 deletions(-)
20
21
diff --git a/target/arm/helper.c b/target/arm/helper.c
22
index XXXXXXX..XXXXXXX 100644
23
--- a/target/arm/helper.c
24
+++ b/target/arm/helper.c
25
@@ -XXX,XX +XXX,XX @@ void arm_v7m_cpu_do_interrupt(CPUState *cs)
26
case EXCP_UDEF:
27
armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE);
28
env->v7m.cfsr |= R_V7M_CFSR_UNDEFINSTR_MASK;
29
- return;
30
+ break;
31
case EXCP_NOCP:
32
armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE);
33
env->v7m.cfsr |= R_V7M_CFSR_NOCP_MASK;
34
- return;
35
+ break;
36
case EXCP_SWI:
37
/* The PC already points to the next instruction. */
38
armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_SVC);
39
- return;
40
+ break;
41
case EXCP_PREFETCH_ABORT:
42
case EXCP_DATA_ABORT:
43
/* TODO: if we implemented the MPU registers, this is where we
44
* should set the MMFAR, etc from exception.fsr and exception.vaddress.
45
*/
46
armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_MEM);
47
- return;
48
+ break;
49
case EXCP_BKPT:
50
if (semihosting_enabled()) {
51
int nr;
52
@@ -XXX,XX +XXX,XX @@ void arm_v7m_cpu_do_interrupt(CPUState *cs)
53
}
54
}
55
armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_DEBUG);
56
- return;
57
+ break;
58
case EXCP_IRQ:
59
- armv7m_nvic_acknowledge_irq(env->nvic);
60
break;
61
case EXCP_EXCEPTION_EXIT:
62
do_v7m_exception_exit(env);
63
@@ -XXX,XX +XXX,XX @@ void arm_v7m_cpu_do_interrupt(CPUState *cs)
64
return; /* Never happens. Keep compiler happy. */
65
}
66
67
+ armv7m_nvic_acknowledge_irq(env->nvic);
68
+
69
+ qemu_log_mask(CPU_LOG_INT, "... as %d\n", env->v7m.exception);
70
+
71
/* Align stack pointer if the guest wants that */
72
if ((env->regs[13] & 4) && (env->v7m.ccr & R_V7M_CCR_STKALIGN_MASK)) {
73
env->regs[13] -= 4;
74
--
75
2.7.4
76
77
diff view generated by jsdifflib
Deleted patch
1
From: Michael Davidsaver <mdavidsaver@gmail.com>
2
1
3
The VECTCLRACTIVE and VECTRESET bits in the AIRCR are both
4
documented as UNPREDICTABLE if you write a 1 to them when
5
the processor is not halted in Debug state (ie stopped
6
and under the control of an external JTAG debugger).
7
Since we don't implement Debug state or emulated JTAG
8
these bits are always UNPREDICTABLE for us. Instead of
9
logging them as unimplemented we can simply log writes
10
as guest errors and ignore them.
11
12
Signed-off-by: Michael Davidsaver <mdavidsaver@gmail.com>
13
[PMM: change extracted from another patch; commit message
14
constructed from scratch]
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
17
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
18
---
19
hw/intc/armv7m_nvic.c | 8 ++++++--
20
1 file changed, 6 insertions(+), 2 deletions(-)
21
22
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
23
index XXXXXXX..XXXXXXX 100644
24
--- a/hw/intc/armv7m_nvic.c
25
+++ b/hw/intc/armv7m_nvic.c
26
@@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value)
27
qemu_irq_pulse(s->sysresetreq);
28
}
29
if (value & 2) {
30
- qemu_log_mask(LOG_UNIMP, "VECTCLRACTIVE unimplemented\n");
31
+ qemu_log_mask(LOG_GUEST_ERROR,
32
+ "Setting VECTCLRACTIVE when not in DEBUG mode "
33
+ "is UNPREDICTABLE\n");
34
}
35
if (value & 1) {
36
- qemu_log_mask(LOG_UNIMP, "AIRCR system reset unimplemented\n");
37
+ qemu_log_mask(LOG_GUEST_ERROR,
38
+ "Setting VECTRESET when not in DEBUG mode "
39
+ "is UNPREDICTABLE\n");
40
}
41
s->prigroup = extract32(value, 8, 3);
42
nvic_irq_update(s);
43
--
44
2.7.4
45
46
diff view generated by jsdifflib
Deleted patch
1
Extract the code from the tail end of arm_v7m_do_interrupt() which
2
enters the exception handler into a pair of utility functions
3
v7m_exception_taken() and v7m_push_stack(), which correspond roughly
4
to the pseudocode PushStack() and ExceptionTaken().
5
1
6
This also requires us to move the arm_v7m_load_vector() utility
7
routine up so we can call it.
8
9
Handling illegal exception returns has some cases where we want to
10
take a UsageFault either on an existing stack frame or with a new
11
stack frame but with a specific LR value, so we want to be able to
12
call these without having to go via arm_v7m_cpu_do_interrupt().
13
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
16
---
17
target/arm/helper.c | 118 ++++++++++++++++++++++++++++++----------------------
18
1 file changed, 68 insertions(+), 50 deletions(-)
19
20
diff --git a/target/arm/helper.c b/target/arm/helper.c
21
index XXXXXXX..XXXXXXX 100644
22
--- a/target/arm/helper.c
23
+++ b/target/arm/helper.c
24
@@ -XXX,XX +XXX,XX @@ static void switch_v7m_sp(CPUARMState *env, bool new_spsel)
25
}
26
}
27
28
+static uint32_t arm_v7m_load_vector(ARMCPU *cpu)
29
+{
30
+ CPUState *cs = CPU(cpu);
31
+ CPUARMState *env = &cpu->env;
32
+ MemTxResult result;
33
+ hwaddr vec = env->v7m.vecbase + env->v7m.exception * 4;
34
+ uint32_t addr;
35
+
36
+ addr = address_space_ldl(cs->as, vec,
37
+ MEMTXATTRS_UNSPECIFIED, &result);
38
+ if (result != MEMTX_OK) {
39
+ /* Architecturally this should cause a HardFault setting HSFR.VECTTBL,
40
+ * which would then be immediately followed by our failing to load
41
+ * the entry vector for that HardFault, which is a Lockup case.
42
+ * Since we don't model Lockup, we just report this guest error
43
+ * via cpu_abort().
44
+ */
45
+ cpu_abort(cs, "Failed to read from exception vector table "
46
+ "entry %08x\n", (unsigned)vec);
47
+ }
48
+ return addr;
49
+}
50
+
51
+static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr)
52
+{
53
+ /* Do the "take the exception" parts of exception entry,
54
+ * but not the pushing of state to the stack. This is
55
+ * similar to the pseudocode ExceptionTaken() function.
56
+ */
57
+ CPUARMState *env = &cpu->env;
58
+ uint32_t addr;
59
+
60
+ armv7m_nvic_acknowledge_irq(env->nvic);
61
+ switch_v7m_sp(env, 0);
62
+ /* Clear IT bits */
63
+ env->condexec_bits = 0;
64
+ env->regs[14] = lr;
65
+ addr = arm_v7m_load_vector(cpu);
66
+ env->regs[15] = addr & 0xfffffffe;
67
+ env->thumb = addr & 1;
68
+}
69
+
70
+static void v7m_push_stack(ARMCPU *cpu)
71
+{
72
+ /* Do the "set up stack frame" part of exception entry,
73
+ * similar to pseudocode PushStack().
74
+ */
75
+ CPUARMState *env = &cpu->env;
76
+ uint32_t xpsr = xpsr_read(env);
77
+
78
+ /* Align stack pointer if the guest wants that */
79
+ if ((env->regs[13] & 4) && (env->v7m.ccr & R_V7M_CCR_STKALIGN_MASK)) {
80
+ env->regs[13] -= 4;
81
+ xpsr |= 0x200;
82
+ }
83
+ /* Switch to the handler mode. */
84
+ v7m_push(env, xpsr);
85
+ v7m_push(env, env->regs[15]);
86
+ v7m_push(env, env->regs[14]);
87
+ v7m_push(env, env->regs[12]);
88
+ v7m_push(env, env->regs[3]);
89
+ v7m_push(env, env->regs[2]);
90
+ v7m_push(env, env->regs[1]);
91
+ v7m_push(env, env->regs[0]);
92
+}
93
+
94
static void do_v7m_exception_exit(CPUARMState *env)
95
{
96
uint32_t type;
97
@@ -XXX,XX +XXX,XX @@ static void arm_log_exception(int idx)
98
}
99
}
100
101
-static uint32_t arm_v7m_load_vector(ARMCPU *cpu)
102
-
103
-{
104
- CPUState *cs = CPU(cpu);
105
- CPUARMState *env = &cpu->env;
106
- MemTxResult result;
107
- hwaddr vec = env->v7m.vecbase + env->v7m.exception * 4;
108
- uint32_t addr;
109
-
110
- addr = address_space_ldl(cs->as, vec,
111
- MEMTXATTRS_UNSPECIFIED, &result);
112
- if (result != MEMTX_OK) {
113
- /* Architecturally this should cause a HardFault setting HSFR.VECTTBL,
114
- * which would then be immediately followed by our failing to load
115
- * the entry vector for that HardFault, which is a Lockup case.
116
- * Since we don't model Lockup, we just report this guest error
117
- * via cpu_abort().
118
- */
119
- cpu_abort(cs, "Failed to read from exception vector table "
120
- "entry %08x\n", (unsigned)vec);
121
- }
122
- return addr;
123
-}
124
-
125
void arm_v7m_cpu_do_interrupt(CPUState *cs)
126
{
127
ARMCPU *cpu = ARM_CPU(cs);
128
CPUARMState *env = &cpu->env;
129
- uint32_t xpsr = xpsr_read(env);
130
uint32_t lr;
131
- uint32_t addr;
132
133
arm_log_exception(cs->exception_index);
134
135
@@ -XXX,XX +XXX,XX @@ void arm_v7m_cpu_do_interrupt(CPUState *cs)
136
return; /* Never happens. Keep compiler happy. */
137
}
138
139
- armv7m_nvic_acknowledge_irq(env->nvic);
140
-
141
+ v7m_push_stack(cpu);
142
+ v7m_exception_taken(cpu, lr);
143
qemu_log_mask(CPU_LOG_INT, "... as %d\n", env->v7m.exception);
144
-
145
- /* Align stack pointer if the guest wants that */
146
- if ((env->regs[13] & 4) && (env->v7m.ccr & R_V7M_CCR_STKALIGN_MASK)) {
147
- env->regs[13] -= 4;
148
- xpsr |= 0x200;
149
- }
150
- /* Switch to the handler mode. */
151
- v7m_push(env, xpsr);
152
- v7m_push(env, env->regs[15]);
153
- v7m_push(env, env->regs[14]);
154
- v7m_push(env, env->regs[12]);
155
- v7m_push(env, env->regs[3]);
156
- v7m_push(env, env->regs[2]);
157
- v7m_push(env, env->regs[1]);
158
- v7m_push(env, env->regs[0]);
159
- switch_v7m_sp(env, 0);
160
- /* Clear IT bits */
161
- env->condexec_bits = 0;
162
- env->regs[14] = lr;
163
- addr = arm_v7m_load_vector(cpu);
164
- env->regs[15] = addr & 0xfffffffe;
165
- env->thumb = addr & 1;
166
}
167
168
/* Function used to synchronize QEMU's AArch64 register set with AArch32
169
--
170
2.7.4
171
172
diff view generated by jsdifflib
Deleted patch
1
M profile doesn't implement ARM, and the architecturally required
2
behaviour for attempts to execute with the Thumb bit clear is to
3
generate a UsageFault with the CFSR INVSTATE bit set. We were
4
incorrectly implementing this as generating an UNDEFINSTR UsageFault;
5
fix this.
6
1
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
9
---
10
target/arm/cpu.h | 1 +
11
linux-user/main.c | 1 +
12
target/arm/helper.c | 4 ++++
13
target/arm/translate.c | 8 ++++++--
14
4 files changed, 12 insertions(+), 2 deletions(-)
15
16
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
17
index XXXXXXX..XXXXXXX 100644
18
--- a/target/arm/cpu.h
19
+++ b/target/arm/cpu.h
20
@@ -XXX,XX +XXX,XX @@
21
#define EXCP_VFIQ 15
22
#define EXCP_SEMIHOST 16 /* semihosting call */
23
#define EXCP_NOCP 17 /* v7M NOCP UsageFault */
24
+#define EXCP_INVSTATE 18 /* v7M INVSTATE UsageFault */
25
26
#define ARMV7M_EXCP_RESET 1
27
#define ARMV7M_EXCP_NMI 2
28
diff --git a/linux-user/main.c b/linux-user/main.c
29
index XXXXXXX..XXXXXXX 100644
30
--- a/linux-user/main.c
31
+++ b/linux-user/main.c
32
@@ -XXX,XX +XXX,XX @@ void cpu_loop(CPUARMState *env)
33
switch(trapnr) {
34
case EXCP_UDEF:
35
case EXCP_NOCP:
36
+ case EXCP_INVSTATE:
37
{
38
TaskState *ts = cs->opaque;
39
uint32_t opcode;
40
diff --git a/target/arm/helper.c b/target/arm/helper.c
41
index XXXXXXX..XXXXXXX 100644
42
--- a/target/arm/helper.c
43
+++ b/target/arm/helper.c
44
@@ -XXX,XX +XXX,XX @@ void arm_v7m_cpu_do_interrupt(CPUState *cs)
45
armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE);
46
env->v7m.cfsr |= R_V7M_CFSR_NOCP_MASK;
47
break;
48
+ case EXCP_INVSTATE:
49
+ armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE);
50
+ env->v7m.cfsr |= R_V7M_CFSR_INVSTATE_MASK;
51
+ break;
52
case EXCP_SWI:
53
/* The PC already points to the next instruction. */
54
armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_SVC);
55
diff --git a/target/arm/translate.c b/target/arm/translate.c
56
index XXXXXXX..XXXXXXX 100644
57
--- a/target/arm/translate.c
58
+++ b/target/arm/translate.c
59
@@ -XXX,XX +XXX,XX @@ static void disas_arm_insn(DisasContext *s, unsigned int insn)
60
TCGv_i32 addr;
61
TCGv_i64 tmp64;
62
63
- /* M variants do not implement ARM mode. */
64
+ /* M variants do not implement ARM mode; this must raise the INVSTATE
65
+ * UsageFault exception.
66
+ */
67
if (arm_dc_feature(s, ARM_FEATURE_M)) {
68
- goto illegal_op;
69
+ gen_exception_insn(s, 4, EXCP_INVSTATE, syn_uncategorized(),
70
+ default_exception_el(s));
71
+ return;
72
}
73
cond = insn >> 28;
74
if (cond == 0xf){
75
--
76
2.7.4
77
78
diff view generated by jsdifflib
Deleted patch
1
Implement the NVIC SHCSR write behaviour which allows pending and
2
active status of some exceptions to be changed.
3
1
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
6
---
7
hw/intc/armv7m_nvic.c | 13 +++++++++++--
8
1 file changed, 11 insertions(+), 2 deletions(-)
9
10
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
11
index XXXXXXX..XXXXXXX 100644
12
--- a/hw/intc/armv7m_nvic.c
13
+++ b/hw/intc/armv7m_nvic.c
14
@@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value)
15
cpu->env.v7m.ccr = value;
16
break;
17
case 0xd24: /* System Handler Control. */
18
- /* TODO: Real hardware allows you to set/clear the active bits
19
- under some circumstances. We don't implement this. */
20
+ s->vectors[ARMV7M_EXCP_MEM].active = (value & (1 << 0)) != 0;
21
+ s->vectors[ARMV7M_EXCP_BUS].active = (value & (1 << 1)) != 0;
22
+ s->vectors[ARMV7M_EXCP_USAGE].active = (value & (1 << 3)) != 0;
23
+ s->vectors[ARMV7M_EXCP_SVC].active = (value & (1 << 7)) != 0;
24
+ s->vectors[ARMV7M_EXCP_DEBUG].active = (value & (1 << 8)) != 0;
25
+ s->vectors[ARMV7M_EXCP_PENDSV].active = (value & (1 << 10)) != 0;
26
+ s->vectors[ARMV7M_EXCP_SYSTICK].active = (value & (1 << 11)) != 0;
27
+ s->vectors[ARMV7M_EXCP_USAGE].pending = (value & (1 << 12)) != 0;
28
+ s->vectors[ARMV7M_EXCP_MEM].pending = (value & (1 << 13)) != 0;
29
+ s->vectors[ARMV7M_EXCP_BUS].pending = (value & (1 << 14)) != 0;
30
+ s->vectors[ARMV7M_EXCP_SVC].pending = (value & (1 << 15)) != 0;
31
s->vectors[ARMV7M_EXCP_MEM].enabled = (value & (1 << 16)) != 0;
32
s->vectors[ARMV7M_EXCP_BUS].enabled = (value & (1 << 17)) != 0;
33
s->vectors[ARMV7M_EXCP_USAGE].enabled = (value & (1 << 18)) != 0;
34
--
35
2.7.4
36
37
diff view generated by jsdifflib
Deleted patch
1
From: Clement Deschamps <clement.deschamps@antfield.fr>
2
1
3
This adds the BCM2835 GPIO controller.
4
5
It currently implements:
6
- The 54 GPIOs as outputs (qemu_irq)
7
- The SD controller selection via alternate function of GPIOs 48-53
8
9
Signed-off-by: Clement Deschamps <clement.deschamps@antfield.fr>
10
Message-id: 20170224164021.9066-4-clement.deschamps@antfield.fr
11
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
---
14
hw/gpio/Makefile.objs | 1 +
15
include/hw/gpio/bcm2835_gpio.h | 39 +++++
16
hw/gpio/bcm2835_gpio.c | 353 +++++++++++++++++++++++++++++++++++++++++
17
3 files changed, 393 insertions(+)
18
create mode 100644 include/hw/gpio/bcm2835_gpio.h
19
create mode 100644 hw/gpio/bcm2835_gpio.c
20
21
diff --git a/hw/gpio/Makefile.objs b/hw/gpio/Makefile.objs
22
index XXXXXXX..XXXXXXX 100644
23
--- a/hw/gpio/Makefile.objs
24
+++ b/hw/gpio/Makefile.objs
25
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_GPIO_KEY) += gpio_key.o
26
27
obj-$(CONFIG_OMAP) += omap_gpio.o
28
obj-$(CONFIG_IMX) += imx_gpio.o
29
+obj-$(CONFIG_RASPI) += bcm2835_gpio.o
30
diff --git a/include/hw/gpio/bcm2835_gpio.h b/include/hw/gpio/bcm2835_gpio.h
31
new file mode 100644
32
index XXXXXXX..XXXXXXX
33
--- /dev/null
34
+++ b/include/hw/gpio/bcm2835_gpio.h
35
@@ -XXX,XX +XXX,XX @@
36
+/*
37
+ * Raspberry Pi (BCM2835) GPIO Controller
38
+ *
39
+ * Copyright (c) 2017 Antfield SAS
40
+ *
41
+ * Authors:
42
+ * Clement Deschamps <clement.deschamps@antfield.fr>
43
+ * Luc Michel <luc.michel@antfield.fr>
44
+ *
45
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
46
+ * See the COPYING file in the top-level directory.
47
+ */
48
+
49
+#ifndef BCM2835_GPIO_H
50
+#define BCM2835_GPIO_H
51
+
52
+#include "hw/sd/sd.h"
53
+
54
+typedef struct BCM2835GpioState {
55
+ SysBusDevice parent_obj;
56
+
57
+ MemoryRegion iomem;
58
+
59
+ /* SDBus selector */
60
+ SDBus sdbus;
61
+ SDBus *sdbus_sdhci;
62
+ SDBus *sdbus_sdhost;
63
+
64
+ uint8_t fsel[54];
65
+ uint32_t lev0, lev1;
66
+ uint8_t sd_fsel;
67
+ qemu_irq out[54];
68
+} BCM2835GpioState;
69
+
70
+#define TYPE_BCM2835_GPIO "bcm2835_gpio"
71
+#define BCM2835_GPIO(obj) \
72
+ OBJECT_CHECK(BCM2835GpioState, (obj), TYPE_BCM2835_GPIO)
73
+
74
+#endif
75
diff --git a/hw/gpio/bcm2835_gpio.c b/hw/gpio/bcm2835_gpio.c
76
new file mode 100644
77
index XXXXXXX..XXXXXXX
78
--- /dev/null
79
+++ b/hw/gpio/bcm2835_gpio.c
80
@@ -XXX,XX +XXX,XX @@
81
+/*
82
+ * Raspberry Pi (BCM2835) GPIO Controller
83
+ *
84
+ * Copyright (c) 2017 Antfield SAS
85
+ *
86
+ * Authors:
87
+ * Clement Deschamps <clement.deschamps@antfield.fr>
88
+ * Luc Michel <luc.michel@antfield.fr>
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/log.h"
96
+#include "qemu/timer.h"
97
+#include "qapi/error.h"
98
+#include "hw/sysbus.h"
99
+#include "hw/sd/sd.h"
100
+#include "hw/gpio/bcm2835_gpio.h"
101
+
102
+#define GPFSEL0 0x00
103
+#define GPFSEL1 0x04
104
+#define GPFSEL2 0x08
105
+#define GPFSEL3 0x0C
106
+#define GPFSEL4 0x10
107
+#define GPFSEL5 0x14
108
+#define GPSET0 0x1C
109
+#define GPSET1 0x20
110
+#define GPCLR0 0x28
111
+#define GPCLR1 0x2C
112
+#define GPLEV0 0x34
113
+#define GPLEV1 0x38
114
+#define GPEDS0 0x40
115
+#define GPEDS1 0x44
116
+#define GPREN0 0x4C
117
+#define GPREN1 0x50
118
+#define GPFEN0 0x58
119
+#define GPFEN1 0x5C
120
+#define GPHEN0 0x64
121
+#define GPHEN1 0x68
122
+#define GPLEN0 0x70
123
+#define GPLEN1 0x74
124
+#define GPAREN0 0x7C
125
+#define GPAREN1 0x80
126
+#define GPAFEN0 0x88
127
+#define GPAFEN1 0x8C
128
+#define GPPUD 0x94
129
+#define GPPUDCLK0 0x98
130
+#define GPPUDCLK1 0x9C
131
+
132
+static uint32_t gpfsel_get(BCM2835GpioState *s, uint8_t reg)
133
+{
134
+ int i;
135
+ uint32_t value = 0;
136
+ for (i = 0; i < 10; i++) {
137
+ uint32_t index = 10 * reg + i;
138
+ if (index < sizeof(s->fsel)) {
139
+ value |= (s->fsel[index] & 0x7) << (3 * i);
140
+ }
141
+ }
142
+ return value;
143
+}
144
+
145
+static void gpfsel_set(BCM2835GpioState *s, uint8_t reg, uint32_t value)
146
+{
147
+ int i;
148
+ for (i = 0; i < 10; i++) {
149
+ uint32_t index = 10 * reg + i;
150
+ if (index < sizeof(s->fsel)) {
151
+ int fsel = (value >> (3 * i)) & 0x7;
152
+ s->fsel[index] = fsel;
153
+ }
154
+ }
155
+
156
+ /* SD controller selection (48-53) */
157
+ if (s->sd_fsel != 0
158
+ && (s->fsel[48] == 0) /* SD_CLK_R */
159
+ && (s->fsel[49] == 0) /* SD_CMD_R */
160
+ && (s->fsel[50] == 0) /* SD_DATA0_R */
161
+ && (s->fsel[51] == 0) /* SD_DATA1_R */
162
+ && (s->fsel[52] == 0) /* SD_DATA2_R */
163
+ && (s->fsel[53] == 0) /* SD_DATA3_R */
164
+ ) {
165
+ /* SDHCI controller selected */
166
+ sdbus_reparent_card(s->sdbus_sdhost, s->sdbus_sdhci);
167
+ s->sd_fsel = 0;
168
+ } else if (s->sd_fsel != 4
169
+ && (s->fsel[48] == 4) /* SD_CLK_R */
170
+ && (s->fsel[49] == 4) /* SD_CMD_R */
171
+ && (s->fsel[50] == 4) /* SD_DATA0_R */
172
+ && (s->fsel[51] == 4) /* SD_DATA1_R */
173
+ && (s->fsel[52] == 4) /* SD_DATA2_R */
174
+ && (s->fsel[53] == 4) /* SD_DATA3_R */
175
+ ) {
176
+ /* SDHost controller selected */
177
+ sdbus_reparent_card(s->sdbus_sdhci, s->sdbus_sdhost);
178
+ s->sd_fsel = 4;
179
+ }
180
+}
181
+
182
+static int gpfsel_is_out(BCM2835GpioState *s, int index)
183
+{
184
+ if (index >= 0 && index < 54) {
185
+ return s->fsel[index] == 1;
186
+ }
187
+ return 0;
188
+}
189
+
190
+static void gpset(BCM2835GpioState *s,
191
+ uint32_t val, uint8_t start, uint8_t count, uint32_t *lev)
192
+{
193
+ uint32_t changes = val & ~*lev;
194
+ uint32_t cur = 1;
195
+
196
+ int i;
197
+ for (i = 0; i < count; i++) {
198
+ if ((changes & cur) && (gpfsel_is_out(s, start + i))) {
199
+ qemu_set_irq(s->out[start + i], 1);
200
+ }
201
+ cur <<= 1;
202
+ }
203
+
204
+ *lev |= val;
205
+}
206
+
207
+static void gpclr(BCM2835GpioState *s,
208
+ uint32_t val, uint8_t start, uint8_t count, uint32_t *lev)
209
+{
210
+ uint32_t changes = val & *lev;
211
+ uint32_t cur = 1;
212
+
213
+ int i;
214
+ for (i = 0; i < count; i++) {
215
+ if ((changes & cur) && (gpfsel_is_out(s, start + i))) {
216
+ qemu_set_irq(s->out[start + i], 0);
217
+ }
218
+ cur <<= 1;
219
+ }
220
+
221
+ *lev &= ~val;
222
+}
223
+
224
+static uint64_t bcm2835_gpio_read(void *opaque, hwaddr offset,
225
+ unsigned size)
226
+{
227
+ BCM2835GpioState *s = (BCM2835GpioState *)opaque;
228
+
229
+ switch (offset) {
230
+ case GPFSEL0:
231
+ case GPFSEL1:
232
+ case GPFSEL2:
233
+ case GPFSEL3:
234
+ case GPFSEL4:
235
+ case GPFSEL5:
236
+ return gpfsel_get(s, offset / 4);
237
+ case GPSET0:
238
+ case GPSET1:
239
+ /* Write Only */
240
+ return 0;
241
+ case GPCLR0:
242
+ case GPCLR1:
243
+ /* Write Only */
244
+ return 0;
245
+ case GPLEV0:
246
+ return s->lev0;
247
+ case GPLEV1:
248
+ return s->lev1;
249
+ case GPEDS0:
250
+ case GPEDS1:
251
+ case GPREN0:
252
+ case GPREN1:
253
+ case GPFEN0:
254
+ case GPFEN1:
255
+ case GPHEN0:
256
+ case GPHEN1:
257
+ case GPLEN0:
258
+ case GPLEN1:
259
+ case GPAREN0:
260
+ case GPAREN1:
261
+ case GPAFEN0:
262
+ case GPAFEN1:
263
+ case GPPUD:
264
+ case GPPUDCLK0:
265
+ case GPPUDCLK1:
266
+ /* Not implemented */
267
+ return 0;
268
+ default:
269
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset %"HWADDR_PRIx"\n",
270
+ __func__, offset);
271
+ break;
272
+ }
273
+
274
+ return 0;
275
+}
276
+
277
+static void bcm2835_gpio_write(void *opaque, hwaddr offset,
278
+ uint64_t value, unsigned size)
279
+{
280
+ BCM2835GpioState *s = (BCM2835GpioState *)opaque;
281
+
282
+ switch (offset) {
283
+ case GPFSEL0:
284
+ case GPFSEL1:
285
+ case GPFSEL2:
286
+ case GPFSEL3:
287
+ case GPFSEL4:
288
+ case GPFSEL5:
289
+ gpfsel_set(s, offset / 4, value);
290
+ break;
291
+ case GPSET0:
292
+ gpset(s, value, 0, 32, &s->lev0);
293
+ break;
294
+ case GPSET1:
295
+ gpset(s, value, 32, 22, &s->lev1);
296
+ break;
297
+ case GPCLR0:
298
+ gpclr(s, value, 0, 32, &s->lev0);
299
+ break;
300
+ case GPCLR1:
301
+ gpclr(s, value, 32, 22, &s->lev1);
302
+ break;
303
+ case GPLEV0:
304
+ case GPLEV1:
305
+ /* Read Only */
306
+ break;
307
+ case GPEDS0:
308
+ case GPEDS1:
309
+ case GPREN0:
310
+ case GPREN1:
311
+ case GPFEN0:
312
+ case GPFEN1:
313
+ case GPHEN0:
314
+ case GPHEN1:
315
+ case GPLEN0:
316
+ case GPLEN1:
317
+ case GPAREN0:
318
+ case GPAREN1:
319
+ case GPAFEN0:
320
+ case GPAFEN1:
321
+ case GPPUD:
322
+ case GPPUDCLK0:
323
+ case GPPUDCLK1:
324
+ /* Not implemented */
325
+ break;
326
+ default:
327
+ goto err_out;
328
+ }
329
+ return;
330
+
331
+err_out:
332
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset %"HWADDR_PRIx"\n",
333
+ __func__, offset);
334
+}
335
+
336
+static void bcm2835_gpio_reset(DeviceState *dev)
337
+{
338
+ BCM2835GpioState *s = BCM2835_GPIO(dev);
339
+
340
+ int i;
341
+ for (i = 0; i < 6; i++) {
342
+ gpfsel_set(s, i, 0);
343
+ }
344
+
345
+ s->sd_fsel = 0;
346
+
347
+ /* SDHCI is selected by default */
348
+ sdbus_reparent_card(&s->sdbus, s->sdbus_sdhci);
349
+
350
+ s->lev0 = 0;
351
+ s->lev1 = 0;
352
+}
353
+
354
+static const MemoryRegionOps bcm2835_gpio_ops = {
355
+ .read = bcm2835_gpio_read,
356
+ .write = bcm2835_gpio_write,
357
+ .endianness = DEVICE_NATIVE_ENDIAN,
358
+};
359
+
360
+static const VMStateDescription vmstate_bcm2835_gpio = {
361
+ .name = "bcm2835_gpio",
362
+ .version_id = 1,
363
+ .minimum_version_id = 1,
364
+ .fields = (VMStateField[]) {
365
+ VMSTATE_UINT8_ARRAY(fsel, BCM2835GpioState, 54),
366
+ VMSTATE_UINT32(lev0, BCM2835GpioState),
367
+ VMSTATE_UINT32(lev1, BCM2835GpioState),
368
+ VMSTATE_UINT8(sd_fsel, BCM2835GpioState),
369
+ VMSTATE_END_OF_LIST()
370
+ }
371
+};
372
+
373
+static void bcm2835_gpio_init(Object *obj)
374
+{
375
+ BCM2835GpioState *s = BCM2835_GPIO(obj);
376
+ DeviceState *dev = DEVICE(obj);
377
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
378
+
379
+ qbus_create_inplace(&s->sdbus, sizeof(s->sdbus),
380
+ TYPE_SD_BUS, DEVICE(s), "sd-bus");
381
+
382
+ memory_region_init_io(&s->iomem, obj,
383
+ &bcm2835_gpio_ops, s, "bcm2835_gpio", 0x1000);
384
+ sysbus_init_mmio(sbd, &s->iomem);
385
+ qdev_init_gpio_out(dev, s->out, 54);
386
+}
387
+
388
+static void bcm2835_gpio_realize(DeviceState *dev, Error **errp)
389
+{
390
+ BCM2835GpioState *s = BCM2835_GPIO(dev);
391
+ Object *obj;
392
+ Error *err = NULL;
393
+
394
+ obj = object_property_get_link(OBJECT(dev), "sdbus-sdhci", &err);
395
+ if (obj == NULL) {
396
+ error_setg(errp, "%s: required sdhci link not found: %s",
397
+ __func__, error_get_pretty(err));
398
+ return;
399
+ }
400
+ s->sdbus_sdhci = SD_BUS(obj);
401
+
402
+ obj = object_property_get_link(OBJECT(dev), "sdbus-sdhost", &err);
403
+ if (obj == NULL) {
404
+ error_setg(errp, "%s: required sdhost link not found: %s",
405
+ __func__, error_get_pretty(err));
406
+ return;
407
+ }
408
+ s->sdbus_sdhost = SD_BUS(obj);
409
+}
410
+
411
+static void bcm2835_gpio_class_init(ObjectClass *klass, void *data)
412
+{
413
+ DeviceClass *dc = DEVICE_CLASS(klass);
414
+
415
+ dc->vmsd = &vmstate_bcm2835_gpio;
416
+ dc->realize = &bcm2835_gpio_realize;
417
+ dc->reset = &bcm2835_gpio_reset;
418
+}
419
+
420
+static const TypeInfo bcm2835_gpio_info = {
421
+ .name = TYPE_BCM2835_GPIO,
422
+ .parent = TYPE_SYS_BUS_DEVICE,
423
+ .instance_size = sizeof(BCM2835GpioState),
424
+ .instance_init = bcm2835_gpio_init,
425
+ .class_init = bcm2835_gpio_class_init,
426
+};
427
+
428
+static void bcm2835_gpio_register_types(void)
429
+{
430
+ type_register_static(&bcm2835_gpio_info);
431
+}
432
+
433
+type_init(bcm2835_gpio_register_types)
434
--
435
2.7.4
436
437
diff view generated by jsdifflib
Deleted patch
1
From: Krzysztof Kozlowski <krzk@kernel.org>
2
1
3
Without any clock controller, the Linux kernel was hitting division by
4
zero during boot or with clk_summary:
5
[ 0.000000] [<c031054c>] (unwind_backtrace) from [<c030ba6c>] (show_stack+0x10/0x14)
6
[ 0.000000] [<c030ba6c>] (show_stack) from [<c05b2660>] (dump_stack+0x88/0x9c)
7
[ 0.000000] [<c05b2660>] (dump_stack) from [<c05b11a4>] (Ldiv0+0x8/0x10)
8
[ 0.000000] [<c05b11a4>] (Ldiv0) from [<c06ad1e0>] (samsung_pll45xx_recalc_rate+0x58/0x74)
9
[ 0.000000] [<c06ad1e0>] (samsung_pll45xx_recalc_rate) from [<c0692ec0>] (clk_register+0x39c/0x63c)
10
[ 0.000000] [<c0692ec0>] (clk_register) from [<c125d360>] (samsung_clk_register_pll+0x2e0/0x3d4)
11
[ 0.000000] [<c125d360>] (samsung_clk_register_pll) from [<c125d7e8>] (exynos4_clk_init+0x1b0/0x5e4)
12
[ 0.000000] [<c125d7e8>] (exynos4_clk_init) from [<c12335f4>] (of_clk_init+0x17c/0x210)
13
[ 0.000000] [<c12335f4>] (of_clk_init) from [<c1204700>] (time_init+0x24/0x2c)
14
[ 0.000000] [<c1204700>] (time_init) from [<c1200b2c>] (start_kernel+0x24c/0x38c)
15
[ 0.000000] [<c1200b2c>] (start_kernel) from [<4020807c>] (0x4020807c)
16
17
Provide stub for clock controller returning reset values for PLLs.
18
19
Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
20
Message-id: 20170226200142.31169-1-krzk@kernel.org
21
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
22
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
23
---
24
hw/misc/Makefile.objs | 2 +-
25
hw/arm/exynos4210.c | 6 ++
26
hw/misc/exynos4210_clk.c | 164 +++++++++++++++++++++++++++++++++++++++++++++++
27
3 files changed, 171 insertions(+), 1 deletion(-)
28
create mode 100644 hw/misc/exynos4210_clk.c
29
30
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
31
index XXXXXXX..XXXXXXX 100644
32
--- a/hw/misc/Makefile.objs
33
+++ b/hw/misc/Makefile.objs
34
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_IVSHMEM) += ivshmem.o
35
obj-$(CONFIG_REALVIEW) += arm_sysctl.o
36
obj-$(CONFIG_NSERIES) += cbus.o
37
obj-$(CONFIG_ECCMEMCTL) += eccmemctl.o
38
-obj-$(CONFIG_EXYNOS4) += exynos4210_pmu.o
39
+obj-$(CONFIG_EXYNOS4) += exynos4210_pmu.o exynos4210_clk.o
40
obj-$(CONFIG_IMX) += imx_ccm.o
41
obj-$(CONFIG_IMX) += imx31_ccm.o
42
obj-$(CONFIG_IMX) += imx25_ccm.o
43
diff --git a/hw/arm/exynos4210.c b/hw/arm/exynos4210.c
44
index XXXXXXX..XXXXXXX 100644
45
--- a/hw/arm/exynos4210.c
46
+++ b/hw/arm/exynos4210.c
47
@@ -XXX,XX +XXX,XX @@
48
#include "qemu/osdep.h"
49
#include "qapi/error.h"
50
#include "qemu-common.h"
51
+#include "qemu/log.h"
52
#include "cpu.h"
53
#include "hw/boards.h"
54
#include "sysemu/sysemu.h"
55
@@ -XXX,XX +XXX,XX @@
56
/* PMU SFR base address */
57
#define EXYNOS4210_PMU_BASE_ADDR 0x10020000
58
59
+/* Clock controller SFR base address */
60
+#define EXYNOS4210_CLK_BASE_ADDR 0x10030000
61
+
62
/* Display controllers (FIMD) */
63
#define EXYNOS4210_FIMD0_BASE_ADDR 0x11C00000
64
65
@@ -XXX,XX +XXX,XX @@ Exynos4210State *exynos4210_init(MemoryRegion *system_mem,
66
*/
67
sysbus_create_simple("exynos4210.pmu", EXYNOS4210_PMU_BASE_ADDR, NULL);
68
69
+ sysbus_create_simple("exynos4210.clk", EXYNOS4210_CLK_BASE_ADDR, NULL);
70
+
71
/* PWM */
72
sysbus_create_varargs("exynos4210.pwm", EXYNOS4210_PWM_BASE_ADDR,
73
s->irq_table[exynos4210_get_irq(22, 0)],
74
diff --git a/hw/misc/exynos4210_clk.c b/hw/misc/exynos4210_clk.c
75
new file mode 100644
76
index XXXXXXX..XXXXXXX
77
--- /dev/null
78
+++ b/hw/misc/exynos4210_clk.c
79
@@ -XXX,XX +XXX,XX @@
80
+/*
81
+ * Exynos4210 Clock Controller Emulation
82
+ *
83
+ * Copyright (c) 2017 Krzysztof Kozlowski <krzk@kernel.org>
84
+ *
85
+ * This program is free software; you can redistribute it and/or modify it
86
+ * under the terms of the GNU General Public License as published by the
87
+ * Free Software Foundation; either version 2 of the License, or
88
+ * (at your option) any later version.
89
+ *
90
+ * This program is distributed in the hope that it will be useful, but WITHOUT
91
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
92
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
93
+ * for more details.
94
+ *
95
+ * You should have received a copy of the GNU General Public License along
96
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
97
+ */
98
+
99
+#include "qemu/osdep.h"
100
+#include "hw/sysbus.h"
101
+#include "qemu/log.h"
102
+
103
+#define TYPE_EXYNOS4210_CLK "exynos4210.clk"
104
+#define EXYNOS4210_CLK(obj) \
105
+ OBJECT_CHECK(Exynos4210ClkState, (obj), TYPE_EXYNOS4210_CLK)
106
+
107
+#define CLK_PLL_LOCKED BIT(29)
108
+
109
+#define EXYNOS4210_CLK_REGS_MEM_SIZE 0x15104
110
+
111
+typedef struct Exynos4210Reg {
112
+ const char *name; /* for debug only */
113
+ uint32_t offset;
114
+ uint32_t reset_value;
115
+} Exynos4210Reg;
116
+
117
+/* Clock controller register base: 0x10030000 */
118
+static const Exynos4210Reg exynos4210_clk_regs[] = {
119
+ {"EPLL_LOCK", 0xc010, 0x00000fff},
120
+ {"VPLL_LOCK", 0xc020, 0x00000fff},
121
+ {"EPLL_CON0", 0xc110, 0x00300301 | CLK_PLL_LOCKED},
122
+ {"EPLL_CON1", 0xc114, 0x00000000},
123
+ {"VPLL_CON0", 0xc120, 0x00240201 | CLK_PLL_LOCKED},
124
+ {"VPLL_CON1", 0xc124, 0x66010464},
125
+ {"APLL_LOCK", 0x14000, 0x00000fff},
126
+ {"MPLL_LOCK", 0x14004, 0x00000fff},
127
+ {"APLL_CON0", 0x14100, 0x00c80601 | CLK_PLL_LOCKED},
128
+ {"APLL_CON1", 0x14104, 0x0000001c},
129
+ {"MPLL_CON0", 0x14108, 0x00c80601 | CLK_PLL_LOCKED},
130
+ {"MPLL_CON1", 0x1410c, 0x0000001c},
131
+};
132
+
133
+#define EXYNOS4210_REGS_NUM ARRAY_SIZE(exynos4210_clk_regs)
134
+
135
+typedef struct Exynos4210ClkState {
136
+ SysBusDevice parent_obj;
137
+
138
+ MemoryRegion iomem;
139
+ uint32_t reg[EXYNOS4210_REGS_NUM];
140
+} Exynos4210ClkState;
141
+
142
+static uint64_t exynos4210_clk_read(void *opaque, hwaddr offset,
143
+ unsigned size)
144
+{
145
+ const Exynos4210ClkState *s = (Exynos4210ClkState *)opaque;
146
+ const Exynos4210Reg *regs = exynos4210_clk_regs;
147
+ unsigned int i;
148
+
149
+ for (i = 0; i < EXYNOS4210_REGS_NUM; i++) {
150
+ if (regs->offset == offset) {
151
+ return s->reg[i];
152
+ }
153
+ regs++;
154
+ }
155
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: bad read offset 0x%04x\n",
156
+ __func__, (uint32_t)offset);
157
+ return 0;
158
+}
159
+
160
+static void exynos4210_clk_write(void *opaque, hwaddr offset,
161
+ uint64_t val, unsigned size)
162
+{
163
+ Exynos4210ClkState *s = (Exynos4210ClkState *)opaque;
164
+ const Exynos4210Reg *regs = exynos4210_clk_regs;
165
+ unsigned int i;
166
+
167
+ for (i = 0; i < EXYNOS4210_REGS_NUM; i++) {
168
+ if (regs->offset == offset) {
169
+ s->reg[i] = val;
170
+ return;
171
+ }
172
+ regs++;
173
+ }
174
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: bad write offset 0x%04x\n",
175
+ __func__, (uint32_t)offset);
176
+}
177
+
178
+static const MemoryRegionOps exynos4210_clk_ops = {
179
+ .read = exynos4210_clk_read,
180
+ .write = exynos4210_clk_write,
181
+ .endianness = DEVICE_NATIVE_ENDIAN,
182
+ .valid = {
183
+ .min_access_size = 4,
184
+ .max_access_size = 4,
185
+ .unaligned = false
186
+ }
187
+};
188
+
189
+static void exynos4210_clk_reset(DeviceState *dev)
190
+{
191
+ Exynos4210ClkState *s = EXYNOS4210_CLK(dev);
192
+ unsigned int i;
193
+
194
+ /* Set default values for registers */
195
+ for (i = 0; i < EXYNOS4210_REGS_NUM; i++) {
196
+ s->reg[i] = exynos4210_clk_regs[i].reset_value;
197
+ }
198
+}
199
+
200
+static void exynos4210_clk_init(Object *obj)
201
+{
202
+ Exynos4210ClkState *s = EXYNOS4210_CLK(obj);
203
+ SysBusDevice *dev = SYS_BUS_DEVICE(obj);
204
+
205
+ /* memory mapping */
206
+ memory_region_init_io(&s->iomem, obj, &exynos4210_clk_ops, s,
207
+ TYPE_EXYNOS4210_CLK, EXYNOS4210_CLK_REGS_MEM_SIZE);
208
+ sysbus_init_mmio(dev, &s->iomem);
209
+}
210
+
211
+static const VMStateDescription exynos4210_clk_vmstate = {
212
+ .name = TYPE_EXYNOS4210_CLK,
213
+ .version_id = 1,
214
+ .minimum_version_id = 1,
215
+ .fields = (VMStateField[]) {
216
+ VMSTATE_UINT32_ARRAY(reg, Exynos4210ClkState, EXYNOS4210_REGS_NUM),
217
+ VMSTATE_END_OF_LIST()
218
+ }
219
+};
220
+
221
+static void exynos4210_clk_class_init(ObjectClass *klass, void *data)
222
+{
223
+ DeviceClass *dc = DEVICE_CLASS(klass);
224
+
225
+ dc->reset = exynos4210_clk_reset;
226
+ dc->vmsd = &exynos4210_clk_vmstate;
227
+}
228
+
229
+static const TypeInfo exynos4210_clk_info = {
230
+ .name = TYPE_EXYNOS4210_CLK,
231
+ .parent = TYPE_SYS_BUS_DEVICE,
232
+ .instance_size = sizeof(Exynos4210ClkState),
233
+ .instance_init = exynos4210_clk_init,
234
+ .class_init = exynos4210_clk_class_init,
235
+};
236
+
237
+static void exynos4210_clk_register(void)
238
+{
239
+ qemu_log_mask(LOG_GUEST_ERROR, "Clock init\n");
240
+ type_register_static(&exynos4210_clk_info);
241
+}
242
+
243
+type_init(exynos4210_clk_register)
244
--
245
2.7.4
246
247
diff view generated by jsdifflib