Mon Dec 30 16:06:29 2019 UTC ()
Invalidate the cache just before trying to read the results from the
firmware as RPI4 A72s can fill the cache with speculation


(skrll)
diff -r1.29 -r1.30 src/sys/arch/arm/broadcom/bcm283x_platform.c

cvs diff -r1.29 -r1.30 src/sys/arch/arm/broadcom/bcm283x_platform.c (expand / switch to unified diff)

--- src/sys/arch/arm/broadcom/bcm283x_platform.c 2019/12/30 15:36:37 1.29
+++ src/sys/arch/arm/broadcom/bcm283x_platform.c 2019/12/30 16:06:29 1.30
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: bcm283x_platform.c,v 1.29 2019/12/30 15:36:37 skrll Exp $ */ 1/* $NetBSD: bcm283x_platform.c,v 1.30 2019/12/30 16:06:29 skrll Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2017 Jared D. McNeill <jmcneill@invisible.ca> 4 * Copyright (c) 2017 Jared D. McNeill <jmcneill@invisible.ca>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: bcm283x_platform.c,v 1.29 2019/12/30 15:36:37 skrll Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: bcm283x_platform.c,v 1.30 2019/12/30 16:06:29 skrll Exp $");
31 31
32#include "opt_arm_debug.h" 32#include "opt_arm_debug.h"
33#include "opt_bcm283x.h" 33#include "opt_bcm283x.h"
34#include "opt_cpuoptions.h" 34#include "opt_cpuoptions.h"
35#include "opt_ddb.h" 35#include "opt_ddb.h"
36#include "opt_evbarm_boardtype.h" 36#include "opt_evbarm_boardtype.h"
37#include "opt_kgdb.h" 37#include "opt_kgdb.h"
38#include "opt_fdt.h" 38#include "opt_fdt.h"
39#include "opt_rpi.h" 39#include "opt_rpi.h"
40#include "opt_vcprop.h" 40#include "opt_vcprop.h"
41 41
42#include "sdhc.h" 42#include "sdhc.h"
43#include "bcmsdhost.h" 43#include "bcmsdhost.h"
@@ -734,26 +734,33 @@ bcm283x_bootparams(bus_space_tag_t iot,  @@ -734,26 +734,33 @@ bcm283x_bootparams(bus_space_tag_t iot,
734 (1 << VCPM_POWER_I2C0) | (1 << VCPM_POWER_I2C1) | 734 (1 << VCPM_POWER_I2C0) | (1 << VCPM_POWER_I2C1) |
735 /* (1 << VCPM_POWER_I2C2) | */ 735 /* (1 << VCPM_POWER_I2C2) | */
736#endif 736#endif
737#if (NBCMSPI > 0) 737#if (NBCMSPI > 0)
738 (1 << VCPM_POWER_SPI) | 738 (1 << VCPM_POWER_SPI) |
739#endif 739#endif
740 0) << 4); 740 0) << 4);
741 741
742 bcm2835_mbox_write(iot, ioh, BCMMBOX_CHANARM2VC, 742 bcm2835_mbox_write(iot, ioh, BCMMBOX_CHANARM2VC,
743 KERN_VTOPHYS((vaddr_t)&vb)); 743 KERN_VTOPHYS((vaddr_t)&vb));
744 744
745 bcm2835_mbox_read(iot, ioh, BCMMBOX_CHANARM2VC, &res); 745 bcm2835_mbox_read(iot, ioh, BCMMBOX_CHANARM2VC, &res);
746 746
 747 /*
 748 * RPI4 has Cortex A72 processors which do speculation, so
 749 * we need to invalidate the cache for an updates done by
 750 * the firmware
 751 */
 752 cpu_dcache_inv_range((vaddr_t)&vb, sizeof(vb));
 753
747 if (!vcprop_buffer_success_p(&vb.vb_hdr)) { 754 if (!vcprop_buffer_success_p(&vb.vb_hdr)) {
748 bootconfig.dramblocks = 1; 755 bootconfig.dramblocks = 1;
749 bootconfig.dram[0].address = 0x0; 756 bootconfig.dram[0].address = 0x0;
750 bootconfig.dram[0].pages = atop(BCM283x_MINIMUM_SPLIT); 757 bootconfig.dram[0].pages = atop(BCM283x_MINIMUM_SPLIT);
751 return; 758 return;
752 } 759 }
753 760
754 struct vcprop_tag_memory *vptp_mem = &vb.vbt_memory; 761 struct vcprop_tag_memory *vptp_mem = &vb.vbt_memory;
755 if (vcprop_tag_success_p(&vptp_mem->tag)) { 762 if (vcprop_tag_success_p(&vptp_mem->tag)) {
756 size_t n = vcprop_tag_resplen(&vptp_mem->tag) / 763 size_t n = vcprop_tag_resplen(&vptp_mem->tag) /
757 sizeof(struct vcprop_memory); 764 sizeof(struct vcprop_memory);
758 765
759 bcm283x_memorysize = 0; 766 bcm283x_memorysize = 0;