1 | A surprisingly short target-arm queue, but no point in holding | 1 | Arm patch queue -- these are all bug fix patches but we might |
---|---|---|---|
2 | onto these waiting for more code to arrive :-) | 2 | as well put them in to rc0... |
3 | 3 | ||
4 | thanks | 4 | thanks |
5 | -- PMM | 5 | -- PMM |
6 | 6 | ||
7 | The following changes since commit 3d0bf8dfdfebd7f2ae41b6f220444b8047d6b1ee: | 7 | The following changes since commit 2c8cfc0b52b5a4d123c26c0b5fdf941be24805be: |
8 | 8 | ||
9 | Merge remote-tracking branch 'remotes/dgilbert/tags/pull-migration-20170710a' into staging (2017-07-10 18:13:03 +0100) | 9 | Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging (2018-03-19 11:44:26 +0000) |
10 | 10 | ||
11 | are available in the git repository at: | 11 | are available in the Git repository at: |
12 | 12 | ||
13 | git://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20170711 | 13 | git://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20180319 |
14 | 14 | ||
15 | for you to fetch changes up to 792dac309c8660306557ba058b8b5a6a75ab3c1f: | 15 | for you to fetch changes up to ff72cb6b46b95bb530787add5277c211af3d31c6: |
16 | 16 | ||
17 | target-arm: v7M: ignore writes to CONTROL.SPSEL from Thread mode (2017-07-11 11:21:26 +0100) | 17 | hw/arm/raspi: Provide spin-loop code for AArch64 CPUs (2018-03-19 18:23:24 +0000) |
18 | 18 | ||
19 | ---------------------------------------------------------------- | 19 | ---------------------------------------------------------------- |
20 | target-arm queue: | 20 | target-arm queue: |
21 | * v7M: ignore writes to CONTROL.SPSEL from Thread mode | 21 | * fsl-imx6: Fix incorrect Ethernet interrupt defines |
22 | * KVM: Enable in-kernel timers with user space gic | 22 | * dump: Update correct kdump phys_base field for AArch64 |
23 | * aspeed: Register all watchdogs | 23 | * char: i.MX: Add support for "TX complete" interrupt |
24 | * hw/misc: Add Exynos4210 Pseudo Random Number Generator | 24 | * bcm2836/raspi: Fix various bugs resulting in panics trying |
25 | to boot a Debian Linux kernel on raspi3 | ||
25 | 26 | ||
26 | ---------------------------------------------------------------- | 27 | ---------------------------------------------------------------- |
27 | Alexander Graf (1): | 28 | Andrey Smirnov (2): |
28 | ARM: KVM: Enable in-kernel timers with user space gic | 29 | char: i.MX: Simplify imx_update() |
30 | char: i.MX: Add support for "TX complete" interrupt | ||
29 | 31 | ||
30 | Joel Stanley (1): | 32 | Guenter Roeck (1): |
31 | aspeed: Register all watchdogs | 33 | fsl-imx6: Swap Ethernet interrupt defines |
32 | 34 | ||
33 | Krzysztof Kozlowski (1): | 35 | Peter Maydell (9): |
34 | hw/misc: Add Exynos4210 Pseudo Random Number Generator | 36 | hw/arm/raspi: Don't do board-setup or secure-boot for raspi3 |
37 | hw/arm/boot: assert that secure_boot and secure_board_setup are false for AArch64 | ||
38 | hw/arm/boot: If booting a kernel in EL2, set SCR_EL3.HCE | ||
39 | hw/arm/bcm2386: Fix parent type of bcm2386 | ||
40 | hw/arm/bcm2836: Rename bcm2836 type/struct to bcm283x | ||
41 | hw/arm/bcm2836: Create proper bcm2837 device | ||
42 | hw/arm/bcm2836: Use correct affinity values for BCM2837 | ||
43 | hw/arm/bcm2836: Hardcode correct CPU type | ||
44 | hw/arm/raspi: Provide spin-loop code for AArch64 CPUs | ||
35 | 45 | ||
36 | Peter Maydell (1): | 46 | Wei Huang (1): |
37 | target-arm: v7M: ignore writes to CONTROL.SPSEL from Thread mode | 47 | dump: Update correct kdump phys_base field for AArch64 |
38 | 48 | ||
39 | hw/misc/Makefile.objs | 2 +- | 49 | include/hw/arm/bcm2836.h | 31 +++++++++++++--- |
40 | include/hw/arm/aspeed_soc.h | 4 +- | 50 | include/hw/arm/fsl-imx6.h | 4 +- |
41 | include/sysemu/kvm.h | 11 ++ | 51 | include/hw/char/imx_serial.h | 3 ++ |
42 | target/arm/cpu.h | 3 + | 52 | dump.c | 14 +++++-- |
43 | accel/kvm/kvm-all.c | 5 + | 53 | hw/arm/bcm2836.c | 87 +++++++++++++++++++++++++++++++------------- |
44 | accel/stubs/kvm-stub.c | 5 + | 54 | hw/arm/boot.c | 12 ++++++ |
45 | hw/arm/aspeed_soc.c | 25 ++-- | 55 | hw/arm/raspi.c | 77 +++++++++++++++++++++++++++++++-------- |
46 | hw/arm/exynos4210.c | 4 + | 56 | hw/char/imx_serial.c | 44 ++++++++++++++++------ |
47 | hw/intc/arm_gic.c | 7 ++ | 57 | hw/net/imx_fec.c | 28 +++++++++++++- |
48 | hw/misc/exynos4210_rng.c | 277 ++++++++++++++++++++++++++++++++++++++++++++ | 58 | 9 files changed, 237 insertions(+), 63 deletions(-) |
49 | target/arm/helper.c | 13 ++- | ||
50 | target/arm/kvm.c | 51 ++++++++ | ||
51 | 12 files changed, 394 insertions(+), 13 deletions(-) | ||
52 | create mode 100644 hw/misc/exynos4210_rng.c | ||
53 | 59 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Guenter Roeck <linux@roeck-us.net> | ||
1 | 2 | ||
3 | The sabrelite machine model used by qemu-system-arm is based on the | ||
4 | Freescale/NXP i.MX6Q processor. This SoC has an on-board ethernet | ||
5 | controller which is supported in QEMU using the imx_fec.c module | ||
6 | (actually called imx.enet for this model.) | ||
7 | |||
8 | The include/hw/arm/fsm-imx6.h file defines the interrupt vectors for the | ||
9 | imx.enet device like this: | ||
10 | |||
11 | #define FSL_IMX6_ENET_MAC_1588_IRQ 118 | ||
12 | #define FSL_IMX6_ENET_MAC_IRQ 119 | ||
13 | |||
14 | According to https://www.nxp.com/docs/en/reference-manual/IMX6DQRM.pdf, | ||
15 | page 225, in Table 3-1. ARM Cortex A9 domain interrupt summary, | ||
16 | interrupts are as follows. | ||
17 | |||
18 | 150 ENET MAC 0 IRQ | ||
19 | 151 ENET MAC 0 1588 Timer interrupt | ||
20 | |||
21 | where | ||
22 | |||
23 | 150 - 32 == 118 | ||
24 | 151 - 32 == 119 | ||
25 | |||
26 | In other words, the vector definitions in the fsl-imx6.h file are reversed. | ||
27 | |||
28 | Fixing the interrupts alone causes problems with older Linux kernels: | ||
29 | The Ethernet interface will fail to probe with Linux v4.9 and earlier. | ||
30 | Linux v4.1 and earlier will crash due to a bug in Ethernet driver probe | ||
31 | error handling. This is a Linux kernel problem, not a qemu problem: | ||
32 | the Linux kernel only worked by accident since it requested both interrupts. | ||
33 | |||
34 | For backward compatibility, generate the Ethernet interrupt on both interrupt | ||
35 | lines. This was shown to work from all Linux kernel releases starting with | ||
36 | v3.16. | ||
37 | |||
38 | Link: https://bugs.launchpad.net/qemu/+bug/1753309 | ||
39 | Signed-off-by: Guenter Roeck <linux@roeck-us.net> | ||
40 | Message-id: 1520723090-22130-1-git-send-email-linux@roeck-us.net | ||
41 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
42 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
43 | --- | ||
44 | include/hw/arm/fsl-imx6.h | 4 ++-- | ||
45 | hw/net/imx_fec.c | 28 +++++++++++++++++++++++++++- | ||
46 | 2 files changed, 29 insertions(+), 3 deletions(-) | ||
47 | |||
48 | diff --git a/include/hw/arm/fsl-imx6.h b/include/hw/arm/fsl-imx6.h | ||
49 | index XXXXXXX..XXXXXXX 100644 | ||
50 | --- a/include/hw/arm/fsl-imx6.h | ||
51 | +++ b/include/hw/arm/fsl-imx6.h | ||
52 | @@ -XXX,XX +XXX,XX @@ typedef struct FslIMX6State { | ||
53 | #define FSL_IMX6_HDMI_MASTER_IRQ 115 | ||
54 | #define FSL_IMX6_HDMI_CEC_IRQ 116 | ||
55 | #define FSL_IMX6_MLB150_LOW_IRQ 117 | ||
56 | -#define FSL_IMX6_ENET_MAC_1588_IRQ 118 | ||
57 | -#define FSL_IMX6_ENET_MAC_IRQ 119 | ||
58 | +#define FSL_IMX6_ENET_MAC_IRQ 118 | ||
59 | +#define FSL_IMX6_ENET_MAC_1588_IRQ 119 | ||
60 | #define FSL_IMX6_PCIE1_IRQ 120 | ||
61 | #define FSL_IMX6_PCIE2_IRQ 121 | ||
62 | #define FSL_IMX6_PCIE3_IRQ 122 | ||
63 | diff --git a/hw/net/imx_fec.c b/hw/net/imx_fec.c | ||
64 | index XXXXXXX..XXXXXXX 100644 | ||
65 | --- a/hw/net/imx_fec.c | ||
66 | +++ b/hw/net/imx_fec.c | ||
67 | @@ -XXX,XX +XXX,XX @@ static void imx_enet_write_bd(IMXENETBufDesc *bd, dma_addr_t addr) | ||
68 | |||
69 | static void imx_eth_update(IMXFECState *s) | ||
70 | { | ||
71 | - if (s->regs[ENET_EIR] & s->regs[ENET_EIMR] & ENET_INT_TS_TIMER) { | ||
72 | + /* | ||
73 | + * Previous versions of qemu had the ENET_INT_MAC and ENET_INT_TS_TIMER | ||
74 | + * interrupts swapped. This worked with older versions of Linux (4.14 | ||
75 | + * and older) since Linux associated both interrupt lines with Ethernet | ||
76 | + * MAC interrupts. Specifically, | ||
77 | + * - Linux 4.15 and later have separate interrupt handlers for the MAC and | ||
78 | + * timer interrupts. Those versions of Linux fail with versions of QEMU | ||
79 | + * with swapped interrupt assignments. | ||
80 | + * - In linux 4.14, both interrupt lines were registered with the Ethernet | ||
81 | + * MAC interrupt handler. As a result, all versions of qemu happen to | ||
82 | + * work, though that is accidental. | ||
83 | + * - In Linux 4.9 and older, the timer interrupt was registered directly | ||
84 | + * with the Ethernet MAC interrupt handler. The MAC interrupt was | ||
85 | + * redirected to a GPIO interrupt to work around erratum ERR006687. | ||
86 | + * This was implemented using the SOC's IOMUX block. In qemu, this GPIO | ||
87 | + * interrupt never fired since IOMUX is currently not supported in qemu. | ||
88 | + * Linux instead received MAC interrupts on the timer interrupt. | ||
89 | + * As a result, qemu versions with the swapped interrupt assignment work, | ||
90 | + * albeit accidentally, but qemu versions with the correct interrupt | ||
91 | + * assignment fail. | ||
92 | + * | ||
93 | + * To ensure that all versions of Linux work, generate ENET_INT_MAC | ||
94 | + * interrrupts on both interrupt lines. This should be changed if and when | ||
95 | + * qemu supports IOMUX. | ||
96 | + */ | ||
97 | + if (s->regs[ENET_EIR] & s->regs[ENET_EIMR] & | ||
98 | + (ENET_INT_MAC | ENET_INT_TS_TIMER)) { | ||
99 | qemu_set_irq(s->irq[1], 1); | ||
100 | } else { | ||
101 | qemu_set_irq(s->irq[1], 0); | ||
102 | -- | ||
103 | 2.16.2 | ||
104 | |||
105 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Wei Huang <wei@redhat.com> | ||
1 | 2 | ||
3 | For guest kernel that supports KASLR, the load address can change every | ||
4 | time when guest VM runs. To find the physical base address correctly, | ||
5 | current QEMU dump searches VMCOREINFO for the string "NUMBER(phys_base)=". | ||
6 | However this string pattern is only available on x86_64. AArch64 uses a | ||
7 | different field, called "NUMBER(PHYS_OFFSET)=". This patch makes sure | ||
8 | QEMU dump uses the correct string on AArch64. | ||
9 | |||
10 | Signed-off-by: Wei Huang <wei@redhat.com> | ||
11 | Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> | ||
12 | Message-id: 1520615003-20869-1-git-send-email-wei@redhat.com | ||
13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
14 | --- | ||
15 | dump.c | 14 +++++++++++--- | ||
16 | 1 file changed, 11 insertions(+), 3 deletions(-) | ||
17 | |||
18 | diff --git a/dump.c b/dump.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/dump.c | ||
21 | +++ b/dump.c | ||
22 | @@ -XXX,XX +XXX,XX @@ static void vmcoreinfo_update_phys_base(DumpState *s) | ||
23 | |||
24 | lines = g_strsplit((char *)vmci, "\n", -1); | ||
25 | for (i = 0; lines[i]; i++) { | ||
26 | - if (g_str_has_prefix(lines[i], "NUMBER(phys_base)=")) { | ||
27 | - if (qemu_strtou64(lines[i] + 18, NULL, 16, | ||
28 | + const char *prefix = NULL; | ||
29 | + | ||
30 | + if (s->dump_info.d_machine == EM_X86_64) { | ||
31 | + prefix = "NUMBER(phys_base)="; | ||
32 | + } else if (s->dump_info.d_machine == EM_AARCH64) { | ||
33 | + prefix = "NUMBER(PHYS_OFFSET)="; | ||
34 | + } | ||
35 | + | ||
36 | + if (prefix && g_str_has_prefix(lines[i], prefix)) { | ||
37 | + if (qemu_strtou64(lines[i] + strlen(prefix), NULL, 16, | ||
38 | &phys_base) < 0) { | ||
39 | - warn_report("Failed to read NUMBER(phys_base)="); | ||
40 | + warn_report("Failed to read %s", prefix); | ||
41 | } else { | ||
42 | s->dump_info.phys_base = phys_base; | ||
43 | } | ||
44 | -- | ||
45 | 2.16.2 | ||
46 | |||
47 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
1 | 2 | ||
3 | Code of imx_update() is slightly confusing since the "flags" variable | ||
4 | doesn't really corespond to anything in real hardware and server as a | ||
5 | kitchensink accumulating events normally reported via USR1 and USR2 | ||
6 | registers. | ||
7 | |||
8 | Change the code to explicitly evaluate state of interrupts reported | ||
9 | via USR1 and USR2 against corresponding masking bits and use the to | ||
10 | detemine if IRQ line should be asserted or not. | ||
11 | |||
12 | NOTE: Check for UTS1_TXEMPTY being set has been dropped for two | ||
13 | reasons: | ||
14 | |||
15 | 1. Emulation code implements a single character FIFO, so this flag | ||
16 | will always be set since characters are trasmitted as a part of | ||
17 | the code emulating "push" into the FIFO | ||
18 | |||
19 | 2. imx_update() is really just a function doing ORing and maksing | ||
20 | of reported events, so checking for UTS1_TXEMPTY should happen, | ||
21 | if it's ever really needed should probably happen outside of | ||
22 | it. | ||
23 | |||
24 | Cc: qemu-devel@nongnu.org | ||
25 | Cc: qemu-arm@nongnu.org | ||
26 | Cc: Bill Paul <wpaul@windriver.com> | ||
27 | Cc: Peter Maydell <peter.maydell@linaro.org> | ||
28 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
29 | Message-id: 20180315191141.6789-1-andrew.smirnov@gmail.com | ||
30 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
31 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
32 | --- | ||
33 | hw/char/imx_serial.c | 24 ++++++++++++++++-------- | ||
34 | 1 file changed, 16 insertions(+), 8 deletions(-) | ||
35 | |||
36 | diff --git a/hw/char/imx_serial.c b/hw/char/imx_serial.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/hw/char/imx_serial.c | ||
39 | +++ b/hw/char/imx_serial.c | ||
40 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_imx_serial = { | ||
41 | |||
42 | static void imx_update(IMXSerialState *s) | ||
43 | { | ||
44 | - uint32_t flags; | ||
45 | + uint32_t usr1; | ||
46 | + uint32_t usr2; | ||
47 | + uint32_t mask; | ||
48 | |||
49 | - flags = (s->usr1 & s->ucr1) & (USR1_TRDY|USR1_RRDY); | ||
50 | - if (s->ucr1 & UCR1_TXMPTYEN) { | ||
51 | - flags |= (s->uts1 & UTS1_TXEMPTY); | ||
52 | - } else { | ||
53 | - flags &= ~USR1_TRDY; | ||
54 | - } | ||
55 | + /* | ||
56 | + * Lucky for us TRDY and RRDY has the same offset in both USR1 and | ||
57 | + * UCR1, so we can get away with something as simple as the | ||
58 | + * following: | ||
59 | + */ | ||
60 | + usr1 = s->usr1 & s->ucr1 & (USR1_TRDY | USR1_RRDY); | ||
61 | + /* | ||
62 | + * Bits that we want in USR2 are not as conveniently laid out, | ||
63 | + * unfortunately. | ||
64 | + */ | ||
65 | + mask = (s->ucr1 & UCR1_TXMPTYEN) ? USR2_TXFE : 0; | ||
66 | + usr2 = s->usr2 & mask; | ||
67 | |||
68 | - qemu_set_irq(s->irq, !!flags); | ||
69 | + qemu_set_irq(s->irq, usr1 || usr2); | ||
70 | } | ||
71 | |||
72 | static void imx_serial_reset(IMXSerialState *s) | ||
73 | -- | ||
74 | 2.16.2 | ||
75 | |||
76 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
1 | 2 | ||
3 | Add support for "TX complete"/TXDC interrupt generate by real HW since | ||
4 | it is needed to support guests other than Linux. | ||
5 | |||
6 | Based on the patch by Bill Paul as found here: | ||
7 | https://bugs.launchpad.net/qemu/+bug/1753314 | ||
8 | |||
9 | Cc: qemu-devel@nongnu.org | ||
10 | Cc: qemu-arm@nongnu.org | ||
11 | Cc: Bill Paul <wpaul@windriver.com> | ||
12 | Cc: Peter Maydell <peter.maydell@linaro.org> | ||
13 | Signed-off-by: Bill Paul <wpaul@windriver.com> | ||
14 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
15 | Message-id: 20180315191141.6789-2-andrew.smirnov@gmail.com | ||
16 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
18 | --- | ||
19 | include/hw/char/imx_serial.h | 3 +++ | ||
20 | hw/char/imx_serial.c | 20 +++++++++++++++++--- | ||
21 | 2 files changed, 20 insertions(+), 3 deletions(-) | ||
22 | |||
23 | diff --git a/include/hw/char/imx_serial.h b/include/hw/char/imx_serial.h | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/include/hw/char/imx_serial.h | ||
26 | +++ b/include/hw/char/imx_serial.h | ||
27 | @@ -XXX,XX +XXX,XX @@ | ||
28 | #define UCR2_RXEN (1<<1) /* Receiver enable */ | ||
29 | #define UCR2_SRST (1<<0) /* Reset complete */ | ||
30 | |||
31 | +#define UCR4_TCEN BIT(3) /* TX complete interrupt enable */ | ||
32 | + | ||
33 | #define UTS1_TXEMPTY (1<<6) | ||
34 | #define UTS1_RXEMPTY (1<<5) | ||
35 | #define UTS1_TXFULL (1<<4) | ||
36 | @@ -XXX,XX +XXX,XX @@ typedef struct IMXSerialState { | ||
37 | uint32_t ubmr; | ||
38 | uint32_t ubrc; | ||
39 | uint32_t ucr3; | ||
40 | + uint32_t ucr4; | ||
41 | |||
42 | qemu_irq irq; | ||
43 | CharBackend chr; | ||
44 | diff --git a/hw/char/imx_serial.c b/hw/char/imx_serial.c | ||
45 | index XXXXXXX..XXXXXXX 100644 | ||
46 | --- a/hw/char/imx_serial.c | ||
47 | +++ b/hw/char/imx_serial.c | ||
48 | @@ -XXX,XX +XXX,XX @@ | ||
49 | |||
50 | static const VMStateDescription vmstate_imx_serial = { | ||
51 | .name = TYPE_IMX_SERIAL, | ||
52 | - .version_id = 1, | ||
53 | - .minimum_version_id = 1, | ||
54 | + .version_id = 2, | ||
55 | + .minimum_version_id = 2, | ||
56 | .fields = (VMStateField[]) { | ||
57 | VMSTATE_INT32(readbuff, IMXSerialState), | ||
58 | VMSTATE_UINT32(usr1, IMXSerialState), | ||
59 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_imx_serial = { | ||
60 | VMSTATE_UINT32(ubmr, IMXSerialState), | ||
61 | VMSTATE_UINT32(ubrc, IMXSerialState), | ||
62 | VMSTATE_UINT32(ucr3, IMXSerialState), | ||
63 | + VMSTATE_UINT32(ucr4, IMXSerialState), | ||
64 | VMSTATE_END_OF_LIST() | ||
65 | }, | ||
66 | }; | ||
67 | @@ -XXX,XX +XXX,XX @@ static void imx_update(IMXSerialState *s) | ||
68 | * unfortunately. | ||
69 | */ | ||
70 | mask = (s->ucr1 & UCR1_TXMPTYEN) ? USR2_TXFE : 0; | ||
71 | + /* | ||
72 | + * TCEN and TXDC are both bit 3 | ||
73 | + */ | ||
74 | + mask |= s->ucr4 & UCR4_TCEN; | ||
75 | + | ||
76 | usr2 = s->usr2 & mask; | ||
77 | |||
78 | qemu_set_irq(s->irq, usr1 || usr2); | ||
79 | @@ -XXX,XX +XXX,XX @@ static uint64_t imx_serial_read(void *opaque, hwaddr offset, | ||
80 | return s->ucr3; | ||
81 | |||
82 | case 0x23: /* UCR4 */ | ||
83 | + return s->ucr4; | ||
84 | + | ||
85 | case 0x29: /* BRM Incremental */ | ||
86 | return 0x0; /* TODO */ | ||
87 | |||
88 | @@ -XXX,XX +XXX,XX @@ static void imx_serial_write(void *opaque, hwaddr offset, | ||
89 | * qemu_chr_fe_write and background I/O callbacks */ | ||
90 | qemu_chr_fe_write_all(&s->chr, &ch, 1); | ||
91 | s->usr1 &= ~USR1_TRDY; | ||
92 | + s->usr2 &= ~USR2_TXDC; | ||
93 | imx_update(s); | ||
94 | s->usr1 |= USR1_TRDY; | ||
95 | + s->usr2 |= USR2_TXDC; | ||
96 | imx_update(s); | ||
97 | } | ||
98 | break; | ||
99 | @@ -XXX,XX +XXX,XX @@ static void imx_serial_write(void *opaque, hwaddr offset, | ||
100 | s->ucr3 = value & 0xffff; | ||
101 | break; | ||
102 | |||
103 | - case 0x2d: /* UTS1 */ | ||
104 | case 0x23: /* UCR4 */ | ||
105 | + s->ucr4 = value & 0xffff; | ||
106 | + imx_update(s); | ||
107 | + break; | ||
108 | + | ||
109 | + case 0x2d: /* UTS1 */ | ||
110 | qemu_log_mask(LOG_UNIMP, "[%s]%s: Unimplemented reg 0x%" | ||
111 | HWADDR_PRIx "\n", TYPE_IMX_SERIAL, __func__, offset); | ||
112 | /* TODO */ | ||
113 | -- | ||
114 | 2.16.2 | ||
115 | |||
116 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | For the rpi1 and 2 we want to boot the Linux kernel via some | ||
2 | custom setup code that makes sure that the SMC instruction | ||
3 | acts as a no-op, because it's used for cache maintenance. | ||
4 | The rpi3 boots AArch64 kernels, which don't need SMC for | ||
5 | cache maintenance and always expect to be booted non-secure. | ||
6 | Don't fill in the aarch32-specific parts of the binfo struct. | ||
1 | 7 | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | Reviewed-by: Andrew Baumann <Andrew.Baumann@microsoft.com> | ||
10 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
11 | Message-id: 20180313153458.26822-2-peter.maydell@linaro.org | ||
12 | --- | ||
13 | hw/arm/raspi.c | 17 +++++++++++++---- | ||
14 | 1 file changed, 13 insertions(+), 4 deletions(-) | ||
15 | |||
16 | diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/hw/arm/raspi.c | ||
19 | +++ b/hw/arm/raspi.c | ||
20 | @@ -XXX,XX +XXX,XX @@ static void setup_boot(MachineState *machine, int version, size_t ram_size) | ||
21 | binfo.board_id = raspi_boardid[version]; | ||
22 | binfo.ram_size = ram_size; | ||
23 | binfo.nb_cpus = smp_cpus; | ||
24 | - binfo.board_setup_addr = BOARDSETUP_ADDR; | ||
25 | - binfo.write_board_setup = write_board_setup; | ||
26 | - binfo.secure_board_setup = true; | ||
27 | - binfo.secure_boot = true; | ||
28 | + | ||
29 | + if (version <= 2) { | ||
30 | + /* The rpi1 and 2 require some custom setup code to run in Secure | ||
31 | + * mode before booting a kernel (to set up the SMC vectors so | ||
32 | + * that we get a no-op SMC; this is used by Linux to call the | ||
33 | + * firmware for some cache maintenance operations. | ||
34 | + * The rpi3 doesn't need this. | ||
35 | + */ | ||
36 | + binfo.board_setup_addr = BOARDSETUP_ADDR; | ||
37 | + binfo.write_board_setup = write_board_setup; | ||
38 | + binfo.secure_board_setup = true; | ||
39 | + binfo.secure_boot = true; | ||
40 | + } | ||
41 | |||
42 | /* Pi2 and Pi3 requires SMP setup */ | ||
43 | if (version >= 2) { | ||
44 | -- | ||
45 | 2.16.2 | ||
46 | |||
47 | diff view generated by jsdifflib |
1 | For v7M, writes to the CONTROL register are only permitted for | 1 | Add some assertions that if we're about to boot an AArch64 kernel, |
---|---|---|---|
2 | privileged code. However even if the code is privileged, the | 2 | the board code has not mistakenly set either secure_boot or |
3 | write must not affect the SPSEL bit in the CONTROL register | 3 | secure_board_setup. It doesn't make sense to set secure_boot, |
4 | if the CPU is in Thread mode (as documented in the pseudocode | 4 | because all AArch64 kernels must be booted in non-secure mode. |
5 | for the MSR instruction). Implement this, instead of permitting | ||
6 | SPSEL to be written in all cases. | ||
7 | 5 | ||
8 | This was causing mbed applications not to run, because the | 6 | It might in theory make sense to set secure_board_setup, but |
9 | RTX RTOS they use relies on this behaviour. | 7 | we don't currently support that, because only the AArch32 |
8 | bootloader[] code calls this hook; bootloader_aarch64[] does not. | ||
9 | Since we don't have a current need for this functionality, just | ||
10 | assert that we don't try to use it. If it's needed we'll add | ||
11 | it later. | ||
10 | 12 | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
12 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 14 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
13 | Message-id: 1498820791-8130-1-git-send-email-peter.maydell@linaro.org | 15 | Message-id: 20180313153458.26822-3-peter.maydell@linaro.org |
14 | --- | 16 | --- |
15 | target/arm/helper.c | 13 ++++++++++--- | 17 | hw/arm/boot.c | 7 +++++++ |
16 | 1 file changed, 10 insertions(+), 3 deletions(-) | 18 | 1 file changed, 7 insertions(+) |
17 | 19 | ||
18 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 20 | diff --git a/hw/arm/boot.c b/hw/arm/boot.c |
19 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/target/arm/helper.c | 22 | --- a/hw/arm/boot.c |
21 | +++ b/target/arm/helper.c | 23 | +++ b/hw/arm/boot.c |
22 | @@ -XXX,XX +XXX,XX @@ void HELPER(v7m_msr)(CPUARMState *env, uint32_t maskreg, uint32_t val) | 24 | @@ -XXX,XX +XXX,XX @@ static void do_cpu_reset(void *opaque) |
23 | } | 25 | } else { |
24 | break; | 26 | env->pstate = PSTATE_MODE_EL1h; |
25 | case 20: /* CONTROL */ | 27 | } |
26 | - switch_v7m_sp(env, (val & R_V7M_CONTROL_SPSEL_MASK) != 0); | 28 | + /* AArch64 kernels never boot in secure mode */ |
27 | - env->v7m.control = val & (R_V7M_CONTROL_SPSEL_MASK | | 29 | + assert(!info->secure_boot); |
28 | - R_V7M_CONTROL_NPRIV_MASK); | 30 | + /* This hook is only supported for AArch32 currently: |
29 | + /* Writing to the SPSEL bit only has an effect if we are in | 31 | + * bootloader_aarch64[] will not call the hook, and |
30 | + * thread mode; other bits can be updated by any privileged code. | 32 | + * the code above has already dropped us into EL2 or EL1. |
31 | + * switch_v7m_sp() deals with updating the SPSEL bit in | 33 | + */ |
32 | + * env->v7m.control, so we only need update the others. | 34 | + assert(!info->secure_board_setup); |
33 | + */ | 35 | } |
34 | + if (env->v7m.exception == 0) { | 36 | |
35 | + switch_v7m_sp(env, (val & R_V7M_CONTROL_SPSEL_MASK) != 0); | 37 | /* Set to non-secure if not a secure boot */ |
36 | + } | ||
37 | + env->v7m.control &= ~R_V7M_CONTROL_NPRIV_MASK; | ||
38 | + env->v7m.control |= val & R_V7M_CONTROL_NPRIV_MASK; | ||
39 | break; | ||
40 | default: | ||
41 | qemu_log_mask(LOG_GUEST_ERROR, "Attempt to write unknown special" | ||
42 | -- | 38 | -- |
43 | 2.7.4 | 39 | 2.16.2 |
44 | 40 | ||
45 | 41 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | If we're directly booting a Linux kernel and the CPU supports both | ||
2 | EL3 and EL2, we start the kernel in EL2, as it expects. We must also | ||
3 | set the SCR_EL3.HCE bit in this situation, so that the HVC | ||
4 | instruction is enabled rather than UNDEFing. Otherwise at least some | ||
5 | kernels will panic when trying to initialize KVM in the guest. | ||
1 | 6 | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Message-id: 20180313153458.26822-4-peter.maydell@linaro.org | ||
9 | --- | ||
10 | hw/arm/boot.c | 5 +++++ | ||
11 | 1 file changed, 5 insertions(+) | ||
12 | |||
13 | diff --git a/hw/arm/boot.c b/hw/arm/boot.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/hw/arm/boot.c | ||
16 | +++ b/hw/arm/boot.c | ||
17 | @@ -XXX,XX +XXX,XX @@ static void do_cpu_reset(void *opaque) | ||
18 | assert(!info->secure_board_setup); | ||
19 | } | ||
20 | |||
21 | + if (arm_feature(env, ARM_FEATURE_EL2)) { | ||
22 | + /* If we have EL2 then Linux expects the HVC insn to work */ | ||
23 | + env->cp15.scr_el3 |= SCR_HCE; | ||
24 | + } | ||
25 | + | ||
26 | /* Set to non-secure if not a secure boot */ | ||
27 | if (!info->secure_boot && | ||
28 | (cs != first_cpu || !info->secure_board_setup)) { | ||
29 | -- | ||
30 | 2.16.2 | ||
31 | |||
32 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | The TypeInfo and state struct for bcm2386 disagree about what the | ||
2 | parent class is -- the TypeInfo says it's TYPE_SYS_BUS_DEVICE, | ||
3 | but the BCM2386State struct only defines the parent_obj field | ||
4 | as DeviceState. This would have caused problems if anything | ||
5 | actually tried to treat the object as a TYPE_SYS_BUS_DEVICE. | ||
6 | Fix the TypeInfo to use TYPE_DEVICE as the parent, since we don't | ||
7 | need any of the additional functionality TYPE_SYS_BUS_DEVICE | ||
8 | provides. | ||
1 | 9 | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | Reviewed-by: Andrew Baumann <Andrew.Baumann@microsoft.com> | ||
12 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
13 | Message-id: 20180313153458.26822-5-peter.maydell@linaro.org | ||
14 | --- | ||
15 | hw/arm/bcm2836.c | 2 +- | ||
16 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
17 | |||
18 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/hw/arm/bcm2836.c | ||
21 | +++ b/hw/arm/bcm2836.c | ||
22 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_class_init(ObjectClass *oc, void *data) | ||
23 | |||
24 | static const TypeInfo bcm2836_type_info = { | ||
25 | .name = TYPE_BCM2836, | ||
26 | - .parent = TYPE_SYS_BUS_DEVICE, | ||
27 | + .parent = TYPE_DEVICE, | ||
28 | .instance_size = sizeof(BCM2836State), | ||
29 | .instance_init = bcm2836_init, | ||
30 | .class_init = bcm2836_class_init, | ||
31 | -- | ||
32 | 2.16.2 | ||
33 | |||
34 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Our BCM2836 type is really a generic one that can be any of | ||
2 | the bcm283x family. Rename it accordingly. We change only | ||
3 | the names which are visible via the header file to the | ||
4 | rest of the QEMU code, leaving private function names | ||
5 | in bcm2836.c as they are. | ||
1 | 6 | ||
7 | This is a preliminary to making bcm283x be an abstract | ||
8 | parent class to specific types for the bcm2836 and bcm2837. | ||
9 | |||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | Reviewed-by: Andrew Baumann <Andrew.Baumann@microsoft.com> | ||
12 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
13 | Message-id: 20180313153458.26822-6-peter.maydell@linaro.org | ||
14 | --- | ||
15 | include/hw/arm/bcm2836.h | 12 ++++++------ | ||
16 | hw/arm/bcm2836.c | 17 +++++++++-------- | ||
17 | hw/arm/raspi.c | 16 ++++++++-------- | ||
18 | 3 files changed, 23 insertions(+), 22 deletions(-) | ||
19 | |||
20 | diff --git a/include/hw/arm/bcm2836.h b/include/hw/arm/bcm2836.h | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/include/hw/arm/bcm2836.h | ||
23 | +++ b/include/hw/arm/bcm2836.h | ||
24 | @@ -XXX,XX +XXX,XX @@ | ||
25 | #include "hw/arm/bcm2835_peripherals.h" | ||
26 | #include "hw/intc/bcm2836_control.h" | ||
27 | |||
28 | -#define TYPE_BCM2836 "bcm2836" | ||
29 | -#define BCM2836(obj) OBJECT_CHECK(BCM2836State, (obj), TYPE_BCM2836) | ||
30 | +#define TYPE_BCM283X "bcm283x" | ||
31 | +#define BCM283X(obj) OBJECT_CHECK(BCM283XState, (obj), TYPE_BCM283X) | ||
32 | |||
33 | -#define BCM2836_NCPUS 4 | ||
34 | +#define BCM283X_NCPUS 4 | ||
35 | |||
36 | -typedef struct BCM2836State { | ||
37 | +typedef struct BCM283XState { | ||
38 | /*< private >*/ | ||
39 | DeviceState parent_obj; | ||
40 | /*< public >*/ | ||
41 | @@ -XXX,XX +XXX,XX @@ typedef struct BCM2836State { | ||
42 | char *cpu_type; | ||
43 | uint32_t enabled_cpus; | ||
44 | |||
45 | - ARMCPU cpus[BCM2836_NCPUS]; | ||
46 | + ARMCPU cpus[BCM283X_NCPUS]; | ||
47 | BCM2836ControlState control; | ||
48 | BCM2835PeripheralState peripherals; | ||
49 | -} BCM2836State; | ||
50 | +} BCM283XState; | ||
51 | |||
52 | #endif /* BCM2836_H */ | ||
53 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c | ||
54 | index XXXXXXX..XXXXXXX 100644 | ||
55 | --- a/hw/arm/bcm2836.c | ||
56 | +++ b/hw/arm/bcm2836.c | ||
57 | @@ -XXX,XX +XXX,XX @@ | ||
58 | |||
59 | static void bcm2836_init(Object *obj) | ||
60 | { | ||
61 | - BCM2836State *s = BCM2836(obj); | ||
62 | + BCM283XState *s = BCM283X(obj); | ||
63 | |||
64 | object_initialize(&s->control, sizeof(s->control), TYPE_BCM2836_CONTROL); | ||
65 | object_property_add_child(obj, "control", OBJECT(&s->control), NULL); | ||
66 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj) | ||
67 | |||
68 | static void bcm2836_realize(DeviceState *dev, Error **errp) | ||
69 | { | ||
70 | - BCM2836State *s = BCM2836(dev); | ||
71 | + BCM283XState *s = BCM283X(dev); | ||
72 | Object *obj; | ||
73 | Error *err = NULL; | ||
74 | int n; | ||
75 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) | ||
76 | /* common peripherals from bcm2835 */ | ||
77 | |||
78 | obj = OBJECT(dev); | ||
79 | - for (n = 0; n < BCM2836_NCPUS; n++) { | ||
80 | + for (n = 0; n < BCM283X_NCPUS; n++) { | ||
81 | object_initialize(&s->cpus[n], sizeof(s->cpus[n]), | ||
82 | s->cpu_type); | ||
83 | object_property_add_child(obj, "cpu[*]", OBJECT(&s->cpus[n]), | ||
84 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) | ||
85 | sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 1, | ||
86 | qdev_get_gpio_in_named(DEVICE(&s->control), "gpu-fiq", 0)); | ||
87 | |||
88 | - for (n = 0; n < BCM2836_NCPUS; n++) { | ||
89 | + for (n = 0; n < BCM283X_NCPUS; n++) { | ||
90 | /* Mirror bcm2836, which has clusterid set to 0xf | ||
91 | * TODO: this should be converted to a property of ARM_CPU | ||
92 | */ | ||
93 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) | ||
94 | } | ||
95 | |||
96 | static Property bcm2836_props[] = { | ||
97 | - DEFINE_PROP_STRING("cpu-type", BCM2836State, cpu_type), | ||
98 | - DEFINE_PROP_UINT32("enabled-cpus", BCM2836State, enabled_cpus, BCM2836_NCPUS), | ||
99 | + DEFINE_PROP_STRING("cpu-type", BCM283XState, cpu_type), | ||
100 | + DEFINE_PROP_UINT32("enabled-cpus", BCM283XState, enabled_cpus, | ||
101 | + BCM283X_NCPUS), | ||
102 | DEFINE_PROP_END_OF_LIST() | ||
103 | }; | ||
104 | |||
105 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_class_init(ObjectClass *oc, void *data) | ||
106 | } | ||
107 | |||
108 | static const TypeInfo bcm2836_type_info = { | ||
109 | - .name = TYPE_BCM2836, | ||
110 | + .name = TYPE_BCM283X, | ||
111 | .parent = TYPE_DEVICE, | ||
112 | - .instance_size = sizeof(BCM2836State), | ||
113 | + .instance_size = sizeof(BCM283XState), | ||
114 | .instance_init = bcm2836_init, | ||
115 | .class_init = bcm2836_class_init, | ||
116 | }; | ||
117 | diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c | ||
118 | index XXXXXXX..XXXXXXX 100644 | ||
119 | --- a/hw/arm/raspi.c | ||
120 | +++ b/hw/arm/raspi.c | ||
121 | @@ -XXX,XX +XXX,XX @@ | ||
122 | static const int raspi_boardid[] = {[1] = 0xc42, [2] = 0xc43, [3] = 0xc44}; | ||
123 | |||
124 | typedef struct RasPiState { | ||
125 | - BCM2836State soc; | ||
126 | + BCM283XState soc; | ||
127 | MemoryRegion ram; | ||
128 | } RasPiState; | ||
129 | |||
130 | @@ -XXX,XX +XXX,XX @@ static void raspi_init(MachineState *machine, int version) | ||
131 | BusState *bus; | ||
132 | DeviceState *carddev; | ||
133 | |||
134 | - object_initialize(&s->soc, sizeof(s->soc), TYPE_BCM2836); | ||
135 | + object_initialize(&s->soc, sizeof(s->soc), TYPE_BCM283X); | ||
136 | object_property_add_child(OBJECT(machine), "soc", OBJECT(&s->soc), | ||
137 | &error_abort); | ||
138 | |||
139 | @@ -XXX,XX +XXX,XX @@ static void raspi2_machine_init(MachineClass *mc) | ||
140 | mc->no_floppy = 1; | ||
141 | mc->no_cdrom = 1; | ||
142 | mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a15"); | ||
143 | - mc->max_cpus = BCM2836_NCPUS; | ||
144 | - mc->min_cpus = BCM2836_NCPUS; | ||
145 | - mc->default_cpus = BCM2836_NCPUS; | ||
146 | + mc->max_cpus = BCM283X_NCPUS; | ||
147 | + mc->min_cpus = BCM283X_NCPUS; | ||
148 | + mc->default_cpus = BCM283X_NCPUS; | ||
149 | mc->default_ram_size = 1024 * 1024 * 1024; | ||
150 | mc->ignore_memory_transaction_failures = true; | ||
151 | }; | ||
152 | @@ -XXX,XX +XXX,XX @@ static void raspi3_machine_init(MachineClass *mc) | ||
153 | mc->no_floppy = 1; | ||
154 | mc->no_cdrom = 1; | ||
155 | mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a53"); | ||
156 | - mc->max_cpus = BCM2836_NCPUS; | ||
157 | - mc->min_cpus = BCM2836_NCPUS; | ||
158 | - mc->default_cpus = BCM2836_NCPUS; | ||
159 | + mc->max_cpus = BCM283X_NCPUS; | ||
160 | + mc->min_cpus = BCM283X_NCPUS; | ||
161 | + mc->default_cpus = BCM283X_NCPUS; | ||
162 | mc->default_ram_size = 1024 * 1024 * 1024; | ||
163 | } | ||
164 | DEFINE_MACHINE("raspi3", raspi3_machine_init) | ||
165 | -- | ||
166 | 2.16.2 | ||
167 | |||
168 | diff view generated by jsdifflib |
1 | From: Krzysztof Kozlowski <krzk@kernel.org> | 1 | The bcm2837 is pretty similar to the bcm2836, but it does have |
---|---|---|---|
2 | some differences. Notably, the MPIDR affinity aff1 values it | ||
3 | sets for the CPUs are 0x0, rather than the 0xf that the bcm2836 | ||
4 | uses, and if this is wrong Linux will not boot. | ||
2 | 5 | ||
3 | Add emulation for Exynos4210 Pseudo Random Number Generator which could | 6 | Rather than trying to have one device with properties that |
4 | work on fixed seeds or with seeds provided by True Random Number | 7 | configure it differently for the two cases, create two |
5 | Generator block inside the SoC. | 8 | separate QOM devices for the two SoCs. We use the same approach |
9 | as hw/arm/aspeed_soc.c and share code and have a data table | ||
10 | that might differ per-SoC. For the moment the two types don't | ||
11 | actually have different behaviour. | ||
6 | 12 | ||
7 | Implement only the fixed seeds part of it in polling mode (no | 13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | interrupts). | 14 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
15 | Message-id: 20180313153458.26822-7-peter.maydell@linaro.org | ||
16 | --- | ||
17 | include/hw/arm/bcm2836.h | 19 +++++++++++++++++++ | ||
18 | hw/arm/bcm2836.c | 37 ++++++++++++++++++++++++++++++++----- | ||
19 | hw/arm/raspi.c | 3 ++- | ||
20 | 3 files changed, 53 insertions(+), 6 deletions(-) | ||
9 | 21 | ||
10 | Emulation tested with two independent Linux kernel exynos-rng drivers: | 22 | diff --git a/include/hw/arm/bcm2836.h b/include/hw/arm/bcm2836.h |
11 | 1. New kcapi-rng interface (targeting Linux v4.12), | ||
12 | 2. Old hwrng inteface | ||
13 | # echo "exynos" > /sys/class/misc/hw_random/rng_current | ||
14 | # dd if=/dev/hwrng of=/dev/null bs=1 count=16 | ||
15 | |||
16 | Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org> | ||
17 | Message-id: 20170425180609.11004-1-krzk@kernel.org | ||
18 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
19 | [PMM: wrapped a few overlong lines; more efficient implementation | ||
20 | of exynos4210_rng_seed_ready()] | ||
21 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
22 | --- | ||
23 | hw/misc/Makefile.objs | 2 +- | ||
24 | hw/arm/exynos4210.c | 4 + | ||
25 | hw/misc/exynos4210_rng.c | 277 +++++++++++++++++++++++++++++++++++++++++++++++ | ||
26 | 3 files changed, 282 insertions(+), 1 deletion(-) | ||
27 | create mode 100644 hw/misc/exynos4210_rng.c | ||
28 | |||
29 | diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs | ||
30 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
31 | --- a/hw/misc/Makefile.objs | 24 | --- a/include/hw/arm/bcm2836.h |
32 | +++ b/hw/misc/Makefile.objs | 25 | +++ b/include/hw/arm/bcm2836.h |
33 | @@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_IVSHMEM) += ivshmem.o | 26 | @@ -XXX,XX +XXX,XX @@ |
34 | obj-$(CONFIG_REALVIEW) += arm_sysctl.o | 27 | |
35 | obj-$(CONFIG_NSERIES) += cbus.o | 28 | #define BCM283X_NCPUS 4 |
36 | obj-$(CONFIG_ECCMEMCTL) += eccmemctl.o | 29 | |
37 | -obj-$(CONFIG_EXYNOS4) += exynos4210_pmu.o exynos4210_clk.o | 30 | +/* These type names are for specific SoCs; other than instantiating |
38 | +obj-$(CONFIG_EXYNOS4) += exynos4210_pmu.o exynos4210_clk.o exynos4210_rng.o | 31 | + * them, code using these devices should always handle them via the |
39 | obj-$(CONFIG_IMX) += imx_ccm.o | 32 | + * BCM283x base class, so they have no BCM2836(obj) etc macros. |
40 | obj-$(CONFIG_IMX) += imx31_ccm.o | 33 | + */ |
41 | obj-$(CONFIG_IMX) += imx25_ccm.o | 34 | +#define TYPE_BCM2836 "bcm2836" |
42 | diff --git a/hw/arm/exynos4210.c b/hw/arm/exynos4210.c | 35 | +#define TYPE_BCM2837 "bcm2837" |
36 | + | ||
37 | typedef struct BCM283XState { | ||
38 | /*< private >*/ | ||
39 | DeviceState parent_obj; | ||
40 | @@ -XXX,XX +XXX,XX @@ typedef struct BCM283XState { | ||
41 | BCM2835PeripheralState peripherals; | ||
42 | } BCM283XState; | ||
43 | |||
44 | +typedef struct BCM283XInfo BCM283XInfo; | ||
45 | + | ||
46 | +typedef struct BCM283XClass { | ||
47 | + DeviceClass parent_class; | ||
48 | + const BCM283XInfo *info; | ||
49 | +} BCM283XClass; | ||
50 | + | ||
51 | +#define BCM283X_CLASS(klass) \ | ||
52 | + OBJECT_CLASS_CHECK(BCM283XClass, (klass), TYPE_BCM283X) | ||
53 | +#define BCM283X_GET_CLASS(obj) \ | ||
54 | + OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X) | ||
55 | + | ||
56 | #endif /* BCM2836_H */ | ||
57 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c | ||
43 | index XXXXXXX..XXXXXXX 100644 | 58 | index XXXXXXX..XXXXXXX 100644 |
44 | --- a/hw/arm/exynos4210.c | 59 | --- a/hw/arm/bcm2836.c |
45 | +++ b/hw/arm/exynos4210.c | 60 | +++ b/hw/arm/bcm2836.c |
46 | @@ -XXX,XX +XXX,XX @@ | 61 | @@ -XXX,XX +XXX,XX @@ |
47 | /* Clock controller SFR base address */ | 62 | /* "QA7" (Pi2) interrupt controller and mailboxes etc. */ |
48 | #define EXYNOS4210_CLK_BASE_ADDR 0x10030000 | 63 | #define BCM2836_CONTROL_BASE 0x40000000 |
49 | 64 | ||
50 | +/* PRNG/HASH SFR base address */ | 65 | +struct BCM283XInfo { |
51 | +#define EXYNOS4210_RNG_BASE_ADDR 0x10830400 | 66 | + const char *name; |
52 | + | ||
53 | /* Display controllers (FIMD) */ | ||
54 | #define EXYNOS4210_FIMD0_BASE_ADDR 0x11C00000 | ||
55 | |||
56 | @@ -XXX,XX +XXX,XX @@ Exynos4210State *exynos4210_init(MemoryRegion *system_mem) | ||
57 | sysbus_create_simple("exynos4210.pmu", EXYNOS4210_PMU_BASE_ADDR, NULL); | ||
58 | |||
59 | sysbus_create_simple("exynos4210.clk", EXYNOS4210_CLK_BASE_ADDR, NULL); | ||
60 | + sysbus_create_simple("exynos4210.rng", EXYNOS4210_RNG_BASE_ADDR, NULL); | ||
61 | |||
62 | /* PWM */ | ||
63 | sysbus_create_varargs("exynos4210.pwm", EXYNOS4210_PWM_BASE_ADDR, | ||
64 | diff --git a/hw/misc/exynos4210_rng.c b/hw/misc/exynos4210_rng.c | ||
65 | new file mode 100644 | ||
66 | index XXXXXXX..XXXXXXX | ||
67 | --- /dev/null | ||
68 | +++ b/hw/misc/exynos4210_rng.c | ||
69 | @@ -XXX,XX +XXX,XX @@ | ||
70 | +/* | ||
71 | + * Exynos4210 Pseudo Random Nubmer Generator Emulation | ||
72 | + * | ||
73 | + * Copyright (c) 2017 Krzysztof Kozlowski <krzk@kernel.org> | ||
74 | + * | ||
75 | + * This program is free software; you can redistribute it and/or modify it | ||
76 | + * under the terms of the GNU General Public License as published by the | ||
77 | + * Free Software Foundation; either version 2 of the License, or | ||
78 | + * (at your option) any later version. | ||
79 | + * | ||
80 | + * This program is distributed in the hope that it will be useful, but WITHOUT | ||
81 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
82 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
83 | + * for more details. | ||
84 | + * | ||
85 | + * You should have received a copy of the GNU General Public License along | ||
86 | + * with this program; if not, see <http://www.gnu.org/licenses/>. | ||
87 | + */ | ||
88 | + | ||
89 | +#include "qemu/osdep.h" | ||
90 | +#include "crypto/random.h" | ||
91 | +#include "hw/sysbus.h" | ||
92 | +#include "qemu/log.h" | ||
93 | + | ||
94 | +#define DEBUG_EXYNOS_RNG 0 | ||
95 | + | ||
96 | +#define DPRINTF(fmt, ...) \ | ||
97 | + do { \ | ||
98 | + if (DEBUG_EXYNOS_RNG) { \ | ||
99 | + printf("exynos4210_rng: " fmt, ## __VA_ARGS__); \ | ||
100 | + } \ | ||
101 | + } while (0) | ||
102 | + | ||
103 | +#define TYPE_EXYNOS4210_RNG "exynos4210.rng" | ||
104 | +#define EXYNOS4210_RNG(obj) \ | ||
105 | + OBJECT_CHECK(Exynos4210RngState, (obj), TYPE_EXYNOS4210_RNG) | ||
106 | + | ||
107 | +/* | ||
108 | + * Exynos4220, PRNG, only polling mode is supported. | ||
109 | + */ | ||
110 | + | ||
111 | +/* RNG_CONTROL_1 register bitfields, reset value: 0x0 */ | ||
112 | +#define EXYNOS4210_RNG_CONTROL_1_PRNG 0x8 | ||
113 | +#define EXYNOS4210_RNG_CONTROL_1_START_INIT BIT(4) | ||
114 | +/* RNG_STATUS register bitfields, reset value: 0x1 */ | ||
115 | +#define EXYNOS4210_RNG_STATUS_PRNG_ERROR BIT(7) | ||
116 | +#define EXYNOS4210_RNG_STATUS_PRNG_DONE BIT(5) | ||
117 | +#define EXYNOS4210_RNG_STATUS_MSG_DONE BIT(4) | ||
118 | +#define EXYNOS4210_RNG_STATUS_PARTIAL_DONE BIT(3) | ||
119 | +#define EXYNOS4210_RNG_STATUS_PRNG_BUSY BIT(2) | ||
120 | +#define EXYNOS4210_RNG_STATUS_SEED_SETTING_DONE BIT(1) | ||
121 | +#define EXYNOS4210_RNG_STATUS_BUFFER_READY BIT(0) | ||
122 | +#define EXYNOS4210_RNG_STATUS_WRITE_MASK (EXYNOS4210_RNG_STATUS_PRNG_DONE \ | ||
123 | + | EXYNOS4210_RNG_STATUS_MSG_DONE \ | ||
124 | + | EXYNOS4210_RNG_STATUS_PARTIAL_DONE) | ||
125 | + | ||
126 | +#define EXYNOS4210_RNG_CONTROL_1 0x0 | ||
127 | +#define EXYNOS4210_RNG_STATUS 0x10 | ||
128 | +#define EXYNOS4210_RNG_SEED_IN 0x140 | ||
129 | +#define EXYNOS4210_RNG_SEED_IN_OFFSET(n) (EXYNOS4210_RNG_SEED_IN + (n * 0x4)) | ||
130 | +#define EXYNOS4210_RNG_PRNG 0x160 | ||
131 | +#define EXYNOS4210_RNG_PRNG_OFFSET(n) (EXYNOS4210_RNG_PRNG + (n * 0x4)) | ||
132 | + | ||
133 | +#define EXYNOS4210_RNG_PRNG_NUM 5 | ||
134 | + | ||
135 | +#define EXYNOS4210_RNG_REGS_MEM_SIZE 0x200 | ||
136 | + | ||
137 | +typedef struct Exynos4210RngState { | ||
138 | + SysBusDevice parent_obj; | ||
139 | + MemoryRegion iomem; | ||
140 | + | ||
141 | + int32_t randr_value[EXYNOS4210_RNG_PRNG_NUM]; | ||
142 | + /* bits from 0 to EXYNOS4210_RNG_PRNG_NUM if given seed register was set */ | ||
143 | + uint32_t seed_set; | ||
144 | + | ||
145 | + /* Register values */ | ||
146 | + uint32_t reg_control; | ||
147 | + uint32_t reg_status; | ||
148 | +} Exynos4210RngState; | ||
149 | + | ||
150 | +static bool exynos4210_rng_seed_ready(const Exynos4210RngState *s) | ||
151 | +{ | ||
152 | + uint32_t mask = MAKE_64BIT_MASK(0, EXYNOS4210_RNG_PRNG_NUM); | ||
153 | + | ||
154 | + /* Return true if all the seed-set bits are set. */ | ||
155 | + return (s->seed_set & mask) == mask; | ||
156 | +} | ||
157 | + | ||
158 | +static void exynos4210_rng_set_seed(Exynos4210RngState *s, unsigned int i, | ||
159 | + uint64_t val) | ||
160 | +{ | ||
161 | + /* | ||
162 | + * We actually ignore the seed and always generate true random numbers. | ||
163 | + * Theoretically this should not match the device as Exynos has | ||
164 | + * a Pseudo Random Number Generator but testing shown that it always | ||
165 | + * generates random numbers regardless of the seed value. | ||
166 | + */ | ||
167 | + s->seed_set |= BIT(i); | ||
168 | + | ||
169 | + /* If all seeds were written, update the status to reflect it */ | ||
170 | + if (exynos4210_rng_seed_ready(s)) { | ||
171 | + s->reg_status |= EXYNOS4210_RNG_STATUS_SEED_SETTING_DONE; | ||
172 | + } else { | ||
173 | + s->reg_status &= ~EXYNOS4210_RNG_STATUS_SEED_SETTING_DONE; | ||
174 | + } | ||
175 | +} | ||
176 | + | ||
177 | +static void exynos4210_rng_run_engine(Exynos4210RngState *s) | ||
178 | +{ | ||
179 | + Error *err = NULL; | ||
180 | + int ret; | ||
181 | + | ||
182 | + /* Seed set? */ | ||
183 | + if ((s->reg_status & EXYNOS4210_RNG_STATUS_SEED_SETTING_DONE) == 0) { | ||
184 | + goto out; | ||
185 | + } | ||
186 | + | ||
187 | + /* PRNG engine chosen? */ | ||
188 | + if ((s->reg_control & EXYNOS4210_RNG_CONTROL_1_PRNG) == 0) { | ||
189 | + goto out; | ||
190 | + } | ||
191 | + | ||
192 | + /* PRNG engine started? */ | ||
193 | + if ((s->reg_control & EXYNOS4210_RNG_CONTROL_1_START_INIT) == 0) { | ||
194 | + goto out; | ||
195 | + } | ||
196 | + | ||
197 | + /* Get randoms */ | ||
198 | + ret = qcrypto_random_bytes((uint8_t *)s->randr_value, | ||
199 | + sizeof(s->randr_value), &err); | ||
200 | + if (!ret) { | ||
201 | + /* Notify that PRNG is ready */ | ||
202 | + s->reg_status |= EXYNOS4210_RNG_STATUS_PRNG_DONE; | ||
203 | + } else { | ||
204 | + error_report_err(err); | ||
205 | + } | ||
206 | + | ||
207 | +out: | ||
208 | + /* Always clear start engine bit */ | ||
209 | + s->reg_control &= ~EXYNOS4210_RNG_CONTROL_1_START_INIT; | ||
210 | +} | ||
211 | + | ||
212 | +static uint64_t exynos4210_rng_read(void *opaque, hwaddr offset, | ||
213 | + unsigned size) | ||
214 | +{ | ||
215 | + Exynos4210RngState *s = (Exynos4210RngState *)opaque; | ||
216 | + uint32_t val = 0; | ||
217 | + | ||
218 | + assert(size == 4); | ||
219 | + | ||
220 | + switch (offset) { | ||
221 | + case EXYNOS4210_RNG_CONTROL_1: | ||
222 | + val = s->reg_control; | ||
223 | + break; | ||
224 | + | ||
225 | + case EXYNOS4210_RNG_STATUS: | ||
226 | + val = s->reg_status; | ||
227 | + break; | ||
228 | + | ||
229 | + case EXYNOS4210_RNG_PRNG_OFFSET(0): | ||
230 | + case EXYNOS4210_RNG_PRNG_OFFSET(1): | ||
231 | + case EXYNOS4210_RNG_PRNG_OFFSET(2): | ||
232 | + case EXYNOS4210_RNG_PRNG_OFFSET(3): | ||
233 | + case EXYNOS4210_RNG_PRNG_OFFSET(4): | ||
234 | + val = s->randr_value[(offset - EXYNOS4210_RNG_PRNG_OFFSET(0)) / 4]; | ||
235 | + DPRINTF("returning random @0x%" HWADDR_PRIx ": 0x%" PRIx32 "\n", | ||
236 | + offset, val); | ||
237 | + break; | ||
238 | + | ||
239 | + default: | ||
240 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
241 | + "%s: bad read offset 0x%" HWADDR_PRIx "\n", | ||
242 | + __func__, offset); | ||
243 | + } | ||
244 | + | ||
245 | + return val; | ||
246 | +} | ||
247 | + | ||
248 | +static void exynos4210_rng_write(void *opaque, hwaddr offset, | ||
249 | + uint64_t val, unsigned size) | ||
250 | +{ | ||
251 | + Exynos4210RngState *s = (Exynos4210RngState *)opaque; | ||
252 | + | ||
253 | + assert(size == 4); | ||
254 | + | ||
255 | + switch (offset) { | ||
256 | + case EXYNOS4210_RNG_CONTROL_1: | ||
257 | + DPRINTF("RNG_CONTROL_1 = 0x%" PRIx64 "\n", val); | ||
258 | + s->reg_control = val; | ||
259 | + exynos4210_rng_run_engine(s); | ||
260 | + break; | ||
261 | + | ||
262 | + case EXYNOS4210_RNG_STATUS: | ||
263 | + /* For clearing status fields */ | ||
264 | + s->reg_status &= ~EXYNOS4210_RNG_STATUS_WRITE_MASK; | ||
265 | + s->reg_status |= val & EXYNOS4210_RNG_STATUS_WRITE_MASK; | ||
266 | + break; | ||
267 | + | ||
268 | + case EXYNOS4210_RNG_SEED_IN_OFFSET(0): | ||
269 | + case EXYNOS4210_RNG_SEED_IN_OFFSET(1): | ||
270 | + case EXYNOS4210_RNG_SEED_IN_OFFSET(2): | ||
271 | + case EXYNOS4210_RNG_SEED_IN_OFFSET(3): | ||
272 | + case EXYNOS4210_RNG_SEED_IN_OFFSET(4): | ||
273 | + exynos4210_rng_set_seed(s, | ||
274 | + (offset - EXYNOS4210_RNG_SEED_IN_OFFSET(0)) / 4, | ||
275 | + val); | ||
276 | + break; | ||
277 | + | ||
278 | + default: | ||
279 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
280 | + "%s: bad write offset 0x%" HWADDR_PRIx "\n", | ||
281 | + __func__, offset); | ||
282 | + } | ||
283 | +} | ||
284 | + | ||
285 | +static const MemoryRegionOps exynos4210_rng_ops = { | ||
286 | + .read = exynos4210_rng_read, | ||
287 | + .write = exynos4210_rng_write, | ||
288 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
289 | +}; | 67 | +}; |
290 | + | 68 | + |
291 | +static void exynos4210_rng_reset(DeviceState *dev) | 69 | +static const BCM283XInfo bcm283x_socs[] = { |
292 | +{ | 70 | + { |
293 | + Exynos4210RngState *s = EXYNOS4210_RNG(dev); | 71 | + .name = TYPE_BCM2836, |
294 | + | 72 | + }, |
295 | + s->reg_control = 0; | 73 | + { |
296 | + s->reg_status = EXYNOS4210_RNG_STATUS_BUFFER_READY; | 74 | + .name = TYPE_BCM2837, |
297 | + memset(s->randr_value, 0, sizeof(s->randr_value)); | 75 | + }, |
298 | + s->seed_set = 0; | ||
299 | +} | ||
300 | + | ||
301 | +static void exynos4210_rng_init(Object *obj) | ||
302 | +{ | ||
303 | + Exynos4210RngState *s = EXYNOS4210_RNG(obj); | ||
304 | + SysBusDevice *dev = SYS_BUS_DEVICE(obj); | ||
305 | + | ||
306 | + memory_region_init_io(&s->iomem, obj, &exynos4210_rng_ops, s, | ||
307 | + TYPE_EXYNOS4210_RNG, EXYNOS4210_RNG_REGS_MEM_SIZE); | ||
308 | + sysbus_init_mmio(dev, &s->iomem); | ||
309 | +} | ||
310 | + | ||
311 | +static const VMStateDescription exynos4210_rng_vmstate = { | ||
312 | + .name = TYPE_EXYNOS4210_RNG, | ||
313 | + .version_id = 1, | ||
314 | + .minimum_version_id = 1, | ||
315 | + .fields = (VMStateField[]) { | ||
316 | + VMSTATE_INT32_ARRAY(randr_value, Exynos4210RngState, | ||
317 | + EXYNOS4210_RNG_PRNG_NUM), | ||
318 | + VMSTATE_UINT32(seed_set, Exynos4210RngState), | ||
319 | + VMSTATE_UINT32(reg_status, Exynos4210RngState), | ||
320 | + VMSTATE_UINT32(reg_control, Exynos4210RngState), | ||
321 | + VMSTATE_END_OF_LIST() | ||
322 | + } | ||
323 | +}; | 76 | +}; |
324 | + | 77 | + |
325 | +static void exynos4210_rng_class_init(ObjectClass *klass, void *data) | 78 | static void bcm2836_init(Object *obj) |
326 | +{ | 79 | { |
327 | + DeviceClass *dc = DEVICE_CLASS(klass); | 80 | BCM283XState *s = BCM283X(obj); |
81 | @@ -XXX,XX +XXX,XX @@ static Property bcm2836_props[] = { | ||
82 | DEFINE_PROP_END_OF_LIST() | ||
83 | }; | ||
84 | |||
85 | -static void bcm2836_class_init(ObjectClass *oc, void *data) | ||
86 | +static void bcm283x_class_init(ObjectClass *oc, void *data) | ||
87 | { | ||
88 | DeviceClass *dc = DEVICE_CLASS(oc); | ||
89 | + BCM283XClass *bc = BCM283X_CLASS(oc); | ||
90 | |||
91 | - dc->props = bcm2836_props; | ||
92 | + bc->info = data; | ||
93 | dc->realize = bcm2836_realize; | ||
94 | + dc->props = bcm2836_props; | ||
95 | } | ||
96 | |||
97 | -static const TypeInfo bcm2836_type_info = { | ||
98 | +static const TypeInfo bcm283x_type_info = { | ||
99 | .name = TYPE_BCM283X, | ||
100 | .parent = TYPE_DEVICE, | ||
101 | .instance_size = sizeof(BCM283XState), | ||
102 | .instance_init = bcm2836_init, | ||
103 | - .class_init = bcm2836_class_init, | ||
104 | + .class_size = sizeof(BCM283XClass), | ||
105 | + .abstract = true, | ||
106 | }; | ||
107 | |||
108 | static void bcm2836_register_types(void) | ||
109 | { | ||
110 | - type_register_static(&bcm2836_type_info); | ||
111 | + int i; | ||
328 | + | 112 | + |
329 | + dc->reset = exynos4210_rng_reset; | 113 | + type_register_static(&bcm283x_type_info); |
330 | + dc->vmsd = &exynos4210_rng_vmstate; | 114 | + for (i = 0; i < ARRAY_SIZE(bcm283x_socs); i++) { |
331 | +} | 115 | + TypeInfo ti = { |
332 | + | 116 | + .name = bcm283x_socs[i].name, |
333 | +static const TypeInfo exynos4210_rng_info = { | 117 | + .parent = TYPE_BCM283X, |
334 | + .name = TYPE_EXYNOS4210_RNG, | 118 | + .class_init = bcm283x_class_init, |
335 | + .parent = TYPE_SYS_BUS_DEVICE, | 119 | + .class_data = (void *) &bcm283x_socs[i], |
336 | + .instance_size = sizeof(Exynos4210RngState), | 120 | + }; |
337 | + .instance_init = exynos4210_rng_init, | 121 | + type_register(&ti); |
338 | + .class_init = exynos4210_rng_class_init, | 122 | + } |
339 | +}; | 123 | } |
340 | + | 124 | |
341 | +static void exynos4210_rng_register(void) | 125 | type_init(bcm2836_register_types) |
342 | +{ | 126 | diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c |
343 | + type_register_static(&exynos4210_rng_info); | 127 | index XXXXXXX..XXXXXXX 100644 |
344 | +} | 128 | --- a/hw/arm/raspi.c |
345 | + | 129 | +++ b/hw/arm/raspi.c |
346 | +type_init(exynos4210_rng_register) | 130 | @@ -XXX,XX +XXX,XX @@ static void raspi_init(MachineState *machine, int version) |
131 | BusState *bus; | ||
132 | DeviceState *carddev; | ||
133 | |||
134 | - object_initialize(&s->soc, sizeof(s->soc), TYPE_BCM283X); | ||
135 | + object_initialize(&s->soc, sizeof(s->soc), | ||
136 | + version == 3 ? TYPE_BCM2837 : TYPE_BCM2836); | ||
137 | object_property_add_child(OBJECT(machine), "soc", OBJECT(&s->soc), | ||
138 | &error_abort); | ||
139 | |||
347 | -- | 140 | -- |
348 | 2.7.4 | 141 | 2.16.2 |
349 | 142 | ||
350 | 143 | diff view generated by jsdifflib |
1 | From: Joel Stanley <joel@jms.id.au> | 1 | The BCM2837 sets the Aff1 field of the MPIDR affinity values for the |
---|---|---|---|
2 | CPUs to 0, whereas the BCM2836 uses 0xf. Set this correctly, as it | ||
3 | is required for Linux to boot. | ||
2 | 4 | ||
3 | The ast2400 contains two and the ast2500 contains three watchdogs. | 5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
4 | Add this information to the AspeedSoCInfo and realise the correct number | 6 | Reviewed-by: Andrew Baumann <Andrew.Baumann@microsoft.com> |
5 | of watchdogs for that each SoC type. | 7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
8 | Message-id: 20180313153458.26822-8-peter.maydell@linaro.org | ||
9 | --- | ||
10 | hw/arm/bcm2836.c | 11 +++++++---- | ||
11 | 1 file changed, 7 insertions(+), 4 deletions(-) | ||
6 | 12 | ||
7 | Signed-off-by: Joel Stanley <joel@jms.id.au> | 13 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c |
8 | Reviewed-by: Cédric Le Goater <clg@kaod.org> | ||
9 | Tested-by: Cédric Le Goater <clg@kaod.org> | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | --- | ||
12 | include/hw/arm/aspeed_soc.h | 4 +++- | ||
13 | hw/arm/aspeed_soc.c | 25 +++++++++++++++++-------- | ||
14 | 2 files changed, 20 insertions(+), 9 deletions(-) | ||
15 | |||
16 | diff --git a/include/hw/arm/aspeed_soc.h b/include/hw/arm/aspeed_soc.h | ||
17 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/include/hw/arm/aspeed_soc.h | 15 | --- a/hw/arm/bcm2836.c |
19 | +++ b/include/hw/arm/aspeed_soc.h | 16 | +++ b/hw/arm/bcm2836.c |
20 | @@ -XXX,XX +XXX,XX @@ | 17 | @@ -XXX,XX +XXX,XX @@ |
21 | #include "hw/net/ftgmac100.h" | 18 | |
22 | 19 | struct BCM283XInfo { | |
23 | #define ASPEED_SPIS_NUM 2 | 20 | const char *name; |
24 | +#define ASPEED_WDTS_NUM 3 | 21 | + int clusterid; |
25 | 22 | }; | |
26 | typedef struct AspeedSoCState { | 23 | |
27 | /*< private >*/ | 24 | static const BCM283XInfo bcm283x_socs[] = { |
28 | @@ -XXX,XX +XXX,XX @@ typedef struct AspeedSoCState { | 25 | { |
29 | AspeedSMCState fmc; | 26 | .name = TYPE_BCM2836, |
30 | AspeedSMCState spi[ASPEED_SPIS_NUM]; | 27 | + .clusterid = 0xf, |
31 | AspeedSDMCState sdmc; | 28 | }, |
32 | - AspeedWDTState wdt; | 29 | { |
33 | + AspeedWDTState wdt[ASPEED_WDTS_NUM]; | 30 | .name = TYPE_BCM2837, |
34 | FTGMAC100State ftgmac100; | 31 | + .clusterid = 0x0, |
35 | } AspeedSoCState; | ||
36 | |||
37 | @@ -XXX,XX +XXX,XX @@ typedef struct AspeedSoCInfo { | ||
38 | const hwaddr *spi_bases; | ||
39 | const char *fmc_typename; | ||
40 | const char **spi_typename; | ||
41 | + int wdts_num; | ||
42 | } AspeedSoCInfo; | ||
43 | |||
44 | typedef struct AspeedSoCClass { | ||
45 | diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c | ||
46 | index XXXXXXX..XXXXXXX 100644 | ||
47 | --- a/hw/arm/aspeed_soc.c | ||
48 | +++ b/hw/arm/aspeed_soc.c | ||
49 | @@ -XXX,XX +XXX,XX @@ static const AspeedSoCInfo aspeed_socs[] = { | ||
50 | .spi_bases = aspeed_soc_ast2400_spi_bases, | ||
51 | .fmc_typename = "aspeed.smc.fmc", | ||
52 | .spi_typename = aspeed_soc_ast2400_typenames, | ||
53 | + .wdts_num = 2, | ||
54 | }, { | ||
55 | .name = "ast2400-a1", | ||
56 | .cpu_model = "arm926", | ||
57 | @@ -XXX,XX +XXX,XX @@ static const AspeedSoCInfo aspeed_socs[] = { | ||
58 | .spi_bases = aspeed_soc_ast2400_spi_bases, | ||
59 | .fmc_typename = "aspeed.smc.fmc", | ||
60 | .spi_typename = aspeed_soc_ast2400_typenames, | ||
61 | + .wdts_num = 2, | ||
62 | }, { | ||
63 | .name = "ast2400", | ||
64 | .cpu_model = "arm926", | ||
65 | @@ -XXX,XX +XXX,XX @@ static const AspeedSoCInfo aspeed_socs[] = { | ||
66 | .spi_bases = aspeed_soc_ast2400_spi_bases, | ||
67 | .fmc_typename = "aspeed.smc.fmc", | ||
68 | .spi_typename = aspeed_soc_ast2400_typenames, | ||
69 | + .wdts_num = 2, | ||
70 | }, { | ||
71 | .name = "ast2500-a1", | ||
72 | .cpu_model = "arm1176", | ||
73 | @@ -XXX,XX +XXX,XX @@ static const AspeedSoCInfo aspeed_socs[] = { | ||
74 | .spi_bases = aspeed_soc_ast2500_spi_bases, | ||
75 | .fmc_typename = "aspeed.smc.ast2500-fmc", | ||
76 | .spi_typename = aspeed_soc_ast2500_typenames, | ||
77 | + .wdts_num = 3, | ||
78 | }, | 32 | }, |
79 | }; | 33 | }; |
80 | 34 | ||
81 | @@ -XXX,XX +XXX,XX @@ static void aspeed_soc_init(Object *obj) | 35 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj) |
82 | object_property_add_alias(obj, "ram-size", OBJECT(&s->sdmc), | 36 | static void bcm2836_realize(DeviceState *dev, Error **errp) |
83 | "ram-size", &error_abort); | 37 | { |
84 | 38 | BCM283XState *s = BCM283X(dev); | |
85 | - object_initialize(&s->wdt, sizeof(s->wdt), TYPE_ASPEED_WDT); | 39 | + BCM283XClass *bc = BCM283X_GET_CLASS(dev); |
86 | - object_property_add_child(obj, "wdt", OBJECT(&s->wdt), NULL); | 40 | + const BCM283XInfo *info = bc->info; |
87 | - qdev_set_parent_bus(DEVICE(&s->wdt), sysbus_get_default()); | 41 | Object *obj; |
88 | + for (i = 0; i < sc->info->wdts_num; i++) { | 42 | Error *err = NULL; |
89 | + object_initialize(&s->wdt[i], sizeof(s->wdt[i]), TYPE_ASPEED_WDT); | 43 | int n; |
90 | + object_property_add_child(obj, "wdt[*]", OBJECT(&s->wdt[i]), NULL); | 44 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) |
91 | + qdev_set_parent_bus(DEVICE(&s->wdt[i]), sysbus_get_default()); | 45 | qdev_get_gpio_in_named(DEVICE(&s->control), "gpu-fiq", 0)); |
92 | + } | 46 | |
93 | 47 | for (n = 0; n < BCM283X_NCPUS; n++) { | |
94 | object_initialize(&s->ftgmac100, sizeof(s->ftgmac100), TYPE_FTGMAC100); | 48 | - /* Mirror bcm2836, which has clusterid set to 0xf |
95 | object_property_add_child(obj, "ftgmac100", OBJECT(&s->ftgmac100), NULL); | 49 | - * TODO: this should be converted to a property of ARM_CPU |
96 | @@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp) | 50 | - */ |
97 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->sdmc), 0, ASPEED_SOC_SDMC_BASE); | 51 | - s->cpus[n].mp_affinity = 0xF00 | n; |
98 | 52 | + /* TODO: this should be converted to a property of ARM_CPU */ | |
99 | /* Watch dog */ | 53 | + s->cpus[n].mp_affinity = (info->clusterid << 8) | n; |
100 | - object_property_set_bool(OBJECT(&s->wdt), true, "realized", &err); | 54 | |
101 | - if (err) { | 55 | /* set periphbase/CBAR value for CPU-local registers */ |
102 | - error_propagate(errp, err); | 56 | object_property_set_int(OBJECT(&s->cpus[n]), |
103 | - return; | ||
104 | + for (i = 0; i < sc->info->wdts_num; i++) { | ||
105 | + object_property_set_bool(OBJECT(&s->wdt[i]), true, "realized", &err); | ||
106 | + if (err) { | ||
107 | + error_propagate(errp, err); | ||
108 | + return; | ||
109 | + } | ||
110 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->wdt[i]), 0, | ||
111 | + ASPEED_SOC_WDT_BASE + i * 0x20); | ||
112 | } | ||
113 | - sysbus_mmio_map(SYS_BUS_DEVICE(&s->wdt), 0, ASPEED_SOC_WDT_BASE); | ||
114 | |||
115 | /* Net */ | ||
116 | qdev_set_nic_properties(DEVICE(&s->ftgmac100), &nd_table[0]); | ||
117 | -- | 57 | -- |
118 | 2.7.4 | 58 | 2.16.2 |
119 | 59 | ||
120 | 60 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Now we have separate types for BCM2386 and BCM2387, we might as well | ||
2 | just hard-code the CPU type they use rather than having it passed | ||
3 | through as an object property. This then lets us put the initialization | ||
4 | of the CPU object in init rather than realize. | ||
1 | 5 | ||
6 | Note that this change means that it's no longer possible on | ||
7 | the command line to use -cpu to ask for a different kind of | ||
8 | CPU than the SoC supports. This was never a supported thing to | ||
9 | do anyway; we were just not sanity-checking the command line. | ||
10 | |||
11 | This does require us to only build the bcm2837 object on | ||
12 | TARGET_AARCH64 configs, since otherwise it won't instantiate | ||
13 | due to the missing cortex-a53 device and "make check" will fail. | ||
14 | |||
15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
16 | Reviewed-by: Andrew Baumann <Andrew.Baumann@microsoft.com> | ||
17 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
18 | Message-id: 20180313153458.26822-9-peter.maydell@linaro.org | ||
19 | --- | ||
20 | hw/arm/bcm2836.c | 24 +++++++++++++++--------- | ||
21 | hw/arm/raspi.c | 2 -- | ||
22 | 2 files changed, 15 insertions(+), 11 deletions(-) | ||
23 | |||
24 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/hw/arm/bcm2836.c | ||
27 | +++ b/hw/arm/bcm2836.c | ||
28 | @@ -XXX,XX +XXX,XX @@ | ||
29 | |||
30 | struct BCM283XInfo { | ||
31 | const char *name; | ||
32 | + const char *cpu_type; | ||
33 | int clusterid; | ||
34 | }; | ||
35 | |||
36 | static const BCM283XInfo bcm283x_socs[] = { | ||
37 | { | ||
38 | .name = TYPE_BCM2836, | ||
39 | + .cpu_type = ARM_CPU_TYPE_NAME("cortex-a15"), | ||
40 | .clusterid = 0xf, | ||
41 | }, | ||
42 | +#ifdef TARGET_AARCH64 | ||
43 | { | ||
44 | .name = TYPE_BCM2837, | ||
45 | + .cpu_type = ARM_CPU_TYPE_NAME("cortex-a53"), | ||
46 | .clusterid = 0x0, | ||
47 | }, | ||
48 | +#endif | ||
49 | }; | ||
50 | |||
51 | static void bcm2836_init(Object *obj) | ||
52 | { | ||
53 | BCM283XState *s = BCM283X(obj); | ||
54 | + BCM283XClass *bc = BCM283X_GET_CLASS(obj); | ||
55 | + const BCM283XInfo *info = bc->info; | ||
56 | + int n; | ||
57 | + | ||
58 | + for (n = 0; n < BCM283X_NCPUS; n++) { | ||
59 | + object_initialize(&s->cpus[n], sizeof(s->cpus[n]), | ||
60 | + info->cpu_type); | ||
61 | + object_property_add_child(obj, "cpu[*]", OBJECT(&s->cpus[n]), | ||
62 | + &error_abort); | ||
63 | + } | ||
64 | |||
65 | object_initialize(&s->control, sizeof(s->control), TYPE_BCM2836_CONTROL); | ||
66 | object_property_add_child(obj, "control", OBJECT(&s->control), NULL); | ||
67 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) | ||
68 | |||
69 | /* common peripherals from bcm2835 */ | ||
70 | |||
71 | - obj = OBJECT(dev); | ||
72 | - for (n = 0; n < BCM283X_NCPUS; n++) { | ||
73 | - object_initialize(&s->cpus[n], sizeof(s->cpus[n]), | ||
74 | - s->cpu_type); | ||
75 | - object_property_add_child(obj, "cpu[*]", OBJECT(&s->cpus[n]), | ||
76 | - &error_abort); | ||
77 | - } | ||
78 | - | ||
79 | obj = object_property_get_link(OBJECT(dev), "ram", &err); | ||
80 | if (obj == NULL) { | ||
81 | error_setg(errp, "%s: required ram link not found: %s", | ||
82 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) | ||
83 | } | ||
84 | |||
85 | static Property bcm2836_props[] = { | ||
86 | - DEFINE_PROP_STRING("cpu-type", BCM283XState, cpu_type), | ||
87 | DEFINE_PROP_UINT32("enabled-cpus", BCM283XState, enabled_cpus, | ||
88 | BCM283X_NCPUS), | ||
89 | DEFINE_PROP_END_OF_LIST() | ||
90 | diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c | ||
91 | index XXXXXXX..XXXXXXX 100644 | ||
92 | --- a/hw/arm/raspi.c | ||
93 | +++ b/hw/arm/raspi.c | ||
94 | @@ -XXX,XX +XXX,XX @@ static void raspi_init(MachineState *machine, int version) | ||
95 | /* Setup the SOC */ | ||
96 | object_property_add_const_link(OBJECT(&s->soc), "ram", OBJECT(&s->ram), | ||
97 | &error_abort); | ||
98 | - object_property_set_str(OBJECT(&s->soc), machine->cpu_type, "cpu-type", | ||
99 | - &error_abort); | ||
100 | object_property_set_int(OBJECT(&s->soc), smp_cpus, "enabled-cpus", | ||
101 | &error_abort); | ||
102 | int board_rev = version == 3 ? 0xa02082 : 0xa21041; | ||
103 | -- | ||
104 | 2.16.2 | ||
105 | |||
106 | diff view generated by jsdifflib |
1 | From: Alexander Graf <agraf@suse.de> | 1 | The raspi3 has AArch64 CPUs, which means that our smpboot |
---|---|---|---|
2 | code for keeping the secondary CPUs in a pen needs to have | ||
3 | a version for A64 as well as A32. Without this, the | ||
4 | secondary CPUs go into an infinite loop of taking undefined | ||
5 | instruction exceptions. | ||
2 | 6 | ||
3 | When running with KVM enabled, you can choose between emulating the | 7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
4 | gic in kernel or user space. If the kernel supports in-kernel virtualization | 8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
5 | of the interrupt controller, it will default to that. If not, if will | 9 | Message-id: 20180313153458.26822-10-peter.maydell@linaro.org |
6 | default to user space emulation. | 10 | --- |
11 | hw/arm/raspi.c | 41 ++++++++++++++++++++++++++++++++++++++++- | ||
12 | 1 file changed, 40 insertions(+), 1 deletion(-) | ||
7 | 13 | ||
8 | Unfortunately when running in user mode gic emulation, we miss out on | 14 | diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c |
9 | interrupt events which are only available from kernel space, such as the timer. | ||
10 | This patch leverages the new kernel/user space pending line synchronization for | ||
11 | timer events. It does not handle PMU events yet. | ||
12 | |||
13 | Signed-off-by: Alexander Graf <agraf@suse.de> | ||
14 | Reviewed-by: Andrew Jones <drjones@redhat.com> | ||
15 | Message-id: 1498577737-130264-1-git-send-email-agraf@suse.de | ||
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
17 | --- | ||
18 | include/sysemu/kvm.h | 11 +++++++++++ | ||
19 | target/arm/cpu.h | 3 +++ | ||
20 | accel/kvm/kvm-all.c | 5 +++++ | ||
21 | accel/stubs/kvm-stub.c | 5 +++++ | ||
22 | hw/intc/arm_gic.c | 7 +++++++ | ||
23 | target/arm/kvm.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
24 | 6 files changed, 82 insertions(+) | ||
25 | |||
26 | diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h | ||
27 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
28 | --- a/include/sysemu/kvm.h | 16 | --- a/hw/arm/raspi.c |
29 | +++ b/include/sysemu/kvm.h | 17 | +++ b/hw/arm/raspi.c |
30 | @@ -XXX,XX +XXX,XX @@ int kvm_init_vcpu(CPUState *cpu); | 18 | @@ -XXX,XX +XXX,XX @@ |
31 | int kvm_cpu_exec(CPUState *cpu); | 19 | #define BOARDSETUP_ADDR (MVBAR_ADDR + 0x20) /* board setup code */ |
32 | int kvm_destroy_vcpu(CPUState *cpu); | 20 | #define FIRMWARE_ADDR_2 0x8000 /* Pi 2 loads kernel.img here by default */ |
33 | 21 | #define FIRMWARE_ADDR_3 0x80000 /* Pi 3 loads kernel.img here by default */ | |
34 | +/** | 22 | +#define SPINTABLE_ADDR 0xd8 /* Pi 3 bootloader spintable */ |
35 | + * kvm_arm_supports_user_irq | 23 | |
36 | + * | 24 | /* Table of Linux board IDs for different Pi versions */ |
37 | + * Not all KVM implementations support notifications for kernel generated | 25 | static const int raspi_boardid[] = {[1] = 0xc42, [2] = 0xc43, [3] = 0xc44}; |
38 | + * interrupt events to user space. This function indicates whether the current | 26 | @@ -XXX,XX +XXX,XX @@ static void write_smpboot(ARMCPU *cpu, const struct arm_boot_info *info) |
39 | + * KVM implementation does support them. | 27 | info->smp_loader_start); |
40 | + * | 28 | } |
41 | + * Returns: true if KVM supports using kernel generated IRQs from user space | 29 | |
42 | + */ | 30 | +static void write_smpboot64(ARMCPU *cpu, const struct arm_boot_info *info) |
43 | +bool kvm_arm_supports_user_irq(void); | 31 | +{ |
32 | + /* Unlike the AArch32 version we don't need to call the board setup hook. | ||
33 | + * The mechanism for doing the spin-table is also entirely different. | ||
34 | + * We must have four 64-bit fields at absolute addresses | ||
35 | + * 0xd8, 0xe0, 0xe8, 0xf0 in RAM, which are the flag variables for | ||
36 | + * our CPUs, and which we must ensure are zero initialized before | ||
37 | + * the primary CPU goes into the kernel. We put these variables inside | ||
38 | + * a rom blob, so that the reset for ROM contents zeroes them for us. | ||
39 | + */ | ||
40 | + static const uint32_t smpboot[] = { | ||
41 | + 0xd2801b05, /* mov x5, 0xd8 */ | ||
42 | + 0xd53800a6, /* mrs x6, mpidr_el1 */ | ||
43 | + 0x924004c6, /* and x6, x6, #0x3 */ | ||
44 | + 0xd503205f, /* spin: wfe */ | ||
45 | + 0xf86678a4, /* ldr x4, [x5,x6,lsl #3] */ | ||
46 | + 0xb4ffffc4, /* cbz x4, spin */ | ||
47 | + 0xd2800000, /* mov x0, #0x0 */ | ||
48 | + 0xd2800001, /* mov x1, #0x0 */ | ||
49 | + 0xd2800002, /* mov x2, #0x0 */ | ||
50 | + 0xd2800003, /* mov x3, #0x0 */ | ||
51 | + 0xd61f0080, /* br x4 */ | ||
52 | + }; | ||
44 | + | 53 | + |
45 | #ifdef NEED_CPU_H | 54 | + static const uint64_t spintables[] = { |
46 | #include "cpu.h" | 55 | + 0, 0, 0, 0 |
47 | 56 | + }; | |
48 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | ||
49 | index XXXXXXX..XXXXXXX 100644 | ||
50 | --- a/target/arm/cpu.h | ||
51 | +++ b/target/arm/cpu.h | ||
52 | @@ -XXX,XX +XXX,XX @@ struct ARMCPU { | ||
53 | void *el_change_hook_opaque; | ||
54 | |||
55 | int32_t node_id; /* NUMA node this CPU belongs to */ | ||
56 | + | 57 | + |
57 | + /* Used to synchronize KVM and QEMU in-kernel device levels */ | 58 | + rom_add_blob_fixed("raspi_smpboot", smpboot, sizeof(smpboot), |
58 | + uint8_t device_irq_level; | 59 | + info->smp_loader_start); |
59 | }; | 60 | + rom_add_blob_fixed("raspi_spintables", spintables, sizeof(spintables), |
60 | 61 | + SPINTABLE_ADDR); | |
61 | static inline ARMCPU *arm_env_get_cpu(CPUARMState *env) | ||
62 | diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c | ||
63 | index XXXXXXX..XXXXXXX 100644 | ||
64 | --- a/accel/kvm/kvm-all.c | ||
65 | +++ b/accel/kvm/kvm-all.c | ||
66 | @@ -XXX,XX +XXX,XX @@ int kvm_has_intx_set_mask(void) | ||
67 | return kvm_state->intx_set_mask; | ||
68 | } | ||
69 | |||
70 | +bool kvm_arm_supports_user_irq(void) | ||
71 | +{ | ||
72 | + return kvm_check_extension(kvm_state, KVM_CAP_ARM_USER_IRQ); | ||
73 | +} | 62 | +} |
74 | + | 63 | + |
75 | #ifdef KVM_CAP_SET_GUEST_DEBUG | 64 | static void write_board_setup(ARMCPU *cpu, const struct arm_boot_info *info) |
76 | struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUState *cpu, | ||
77 | target_ulong pc) | ||
78 | diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c | ||
79 | index XXXXXXX..XXXXXXX 100644 | ||
80 | --- a/accel/stubs/kvm-stub.c | ||
81 | +++ b/accel/stubs/kvm-stub.c | ||
82 | @@ -XXX,XX +XXX,XX @@ void kvm_init_cpu_signals(CPUState *cpu) | ||
83 | { | 65 | { |
84 | abort(); | 66 | arm_write_secure_board_setup_dummy_smc(cpu, info, MVBAR_ADDR); |
85 | } | 67 | @@ -XXX,XX +XXX,XX @@ static void setup_boot(MachineState *machine, int version, size_t ram_size) |
86 | + | 68 | /* Pi2 and Pi3 requires SMP setup */ |
87 | +bool kvm_arm_supports_user_irq(void) | 69 | if (version >= 2) { |
88 | +{ | 70 | binfo.smp_loader_start = SMPBOOT_ADDR; |
89 | + return false; | 71 | - binfo.write_secondary_boot = write_smpboot; |
90 | +} | 72 | + if (version == 2) { |
91 | #endif | 73 | + binfo.write_secondary_boot = write_smpboot; |
92 | diff --git a/hw/intc/arm_gic.c b/hw/intc/arm_gic.c | 74 | + } else { |
93 | index XXXXXXX..XXXXXXX 100644 | 75 | + binfo.write_secondary_boot = write_smpboot64; |
94 | --- a/hw/intc/arm_gic.c | 76 | + } |
95 | +++ b/hw/intc/arm_gic.c | 77 | binfo.secondary_cpu_reset_hook = reset_secondary; |
96 | @@ -XXX,XX +XXX,XX @@ | ||
97 | #include "qom/cpu.h" | ||
98 | #include "qemu/log.h" | ||
99 | #include "trace.h" | ||
100 | +#include "sysemu/kvm.h" | ||
101 | |||
102 | /* #define DEBUG_GIC */ | ||
103 | |||
104 | @@ -XXX,XX +XXX,XX @@ static void arm_gic_realize(DeviceState *dev, Error **errp) | ||
105 | return; | ||
106 | } | 78 | } |
107 | 79 | ||
108 | + if (kvm_enabled() && !kvm_arm_supports_user_irq()) { | ||
109 | + error_setg(errp, "KVM with user space irqchip only works when the " | ||
110 | + "host kernel supports KVM_CAP_ARM_USER_IRQ"); | ||
111 | + return; | ||
112 | + } | ||
113 | + | ||
114 | /* This creates distributor and main CPU interface (s->cpuiomem[0]) */ | ||
115 | gic_init_irqs_and_mmio(s, gic_set_irq, gic_ops); | ||
116 | |||
117 | diff --git a/target/arm/kvm.c b/target/arm/kvm.c | ||
118 | index XXXXXXX..XXXXXXX 100644 | ||
119 | --- a/target/arm/kvm.c | ||
120 | +++ b/target/arm/kvm.c | ||
121 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_init(MachineState *ms, KVMState *s) | ||
122 | */ | ||
123 | kvm_async_interrupts_allowed = true; | ||
124 | |||
125 | + /* | ||
126 | + * PSCI wakes up secondary cores, so we always need to | ||
127 | + * have vCPUs waiting in kernel space | ||
128 | + */ | ||
129 | + kvm_halt_in_kernel_allowed = true; | ||
130 | + | ||
131 | cap_has_mp_state = kvm_check_extension(s, KVM_CAP_MP_STATE); | ||
132 | |||
133 | type_register_static(&host_arm_cpu_type_info); | ||
134 | @@ -XXX,XX +XXX,XX @@ void kvm_arch_pre_run(CPUState *cs, struct kvm_run *run) | ||
135 | |||
136 | MemTxAttrs kvm_arch_post_run(CPUState *cs, struct kvm_run *run) | ||
137 | { | ||
138 | + ARMCPU *cpu; | ||
139 | + uint32_t switched_level; | ||
140 | + | ||
141 | + if (kvm_irqchip_in_kernel()) { | ||
142 | + /* | ||
143 | + * We only need to sync timer states with user-space interrupt | ||
144 | + * controllers, so return early and save cycles if we don't. | ||
145 | + */ | ||
146 | + return MEMTXATTRS_UNSPECIFIED; | ||
147 | + } | ||
148 | + | ||
149 | + cpu = ARM_CPU(cs); | ||
150 | + | ||
151 | + /* Synchronize our shadowed in-kernel device irq lines with the kvm ones */ | ||
152 | + if (run->s.regs.device_irq_level != cpu->device_irq_level) { | ||
153 | + switched_level = cpu->device_irq_level ^ run->s.regs.device_irq_level; | ||
154 | + | ||
155 | + qemu_mutex_lock_iothread(); | ||
156 | + | ||
157 | + if (switched_level & KVM_ARM_DEV_EL1_VTIMER) { | ||
158 | + qemu_set_irq(cpu->gt_timer_outputs[GTIMER_VIRT], | ||
159 | + !!(run->s.regs.device_irq_level & | ||
160 | + KVM_ARM_DEV_EL1_VTIMER)); | ||
161 | + switched_level &= ~KVM_ARM_DEV_EL1_VTIMER; | ||
162 | + } | ||
163 | + | ||
164 | + if (switched_level & KVM_ARM_DEV_EL1_PTIMER) { | ||
165 | + qemu_set_irq(cpu->gt_timer_outputs[GTIMER_PHYS], | ||
166 | + !!(run->s.regs.device_irq_level & | ||
167 | + KVM_ARM_DEV_EL1_PTIMER)); | ||
168 | + switched_level &= ~KVM_ARM_DEV_EL1_PTIMER; | ||
169 | + } | ||
170 | + | ||
171 | + /* XXX PMU IRQ is missing */ | ||
172 | + | ||
173 | + if (switched_level) { | ||
174 | + qemu_log_mask(LOG_UNIMP, "%s: unhandled in-kernel device IRQ %x\n", | ||
175 | + __func__, switched_level); | ||
176 | + } | ||
177 | + | ||
178 | + /* We also mark unknown levels as processed to not waste cycles */ | ||
179 | + cpu->device_irq_level = run->s.regs.device_irq_level; | ||
180 | + qemu_mutex_unlock_iothread(); | ||
181 | + } | ||
182 | + | ||
183 | return MEMTXATTRS_UNSPECIFIED; | ||
184 | } | ||
185 | |||
186 | -- | 80 | -- |
187 | 2.7.4 | 81 | 2.16.2 |
188 | 82 | ||
189 | 83 | diff view generated by jsdifflib |