Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch Add support for EFI runtime services on aarch64.
details: https://anonhg.NetBSD.org/src/rev/a5001091d21f
branches: trunk
changeset: 445415:a5001091d21f
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Sun Oct 28 10:21:42 2018 +0000
description:
Add support for EFI runtime services on aarch64.
diffstat:
sys/arch/aarch64/aarch64/efi_machdep.c | 58 +++++++++++
sys/arch/aarch64/conf/files.aarch64 | 9 +-
sys/arch/arm/acpi/acpi_platform.c | 17 ++-
sys/arch/arm/arm/efi_runtime.c | 128 ++++++++++++++++++++++++
sys/arch/arm/arm/efi_runtime.h | 44 ++++++++
sys/arch/arm/conf/files.arm | 6 +-
sys/arch/arm/fdt/acpi_fdt.c | 99 ++++++++++++++++++-
sys/arch/arm/include/efi.h | 174 +++++++++++++++++++++++++++++++++
sys/arch/evbarm/conf/GENERIC64 | 5 +-
sys/arch/evbarm/fdt/fdt_machdep.c | 39 +++++++-
10 files changed, 568 insertions(+), 11 deletions(-)
diffs (truncated from 770 to 300 lines):
diff -r ccb76da625bc -r a5001091d21f sys/arch/aarch64/aarch64/efi_machdep.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/aarch64/aarch64/efi_machdep.c Sun Oct 28 10:21:42 2018 +0000
@@ -0,0 +1,58 @@
+/* $NetBSD: efi_machdep.c,v 1.1 2018/10/28 10:21:42 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jared McNeill <jmcneill%invisible.ca@localhost>.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: efi_machdep.c,v 1.1 2018/10/28 10:21:42 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <uvm/uvm_extern.h>
+#include <machine/cpufunc.h>
+
+#include <arm/arm/efi_runtime.h>
+
+void
+arm_efirt_md_map_range(vaddr_t va, paddr_t pa, size_t sz, bool exec)
+{
+ pt_entry_t attr;
+
+ attr = LX_BLKPAG_OS_READ | LX_BLKPAG_AF | LX_BLKPAG_UXN | LX_BLKPAG_ATTR_NORMAL_WB;
+ if (exec)
+ attr |= LX_BLKPAG_AP_RO;
+ else
+ attr |= LX_BLKPAG_AP_RW | LX_BLKPAG_OS_WRITE | LX_BLKPAG_PXN;
+
+ pmapboot_enter(va, pa, sz, L3_SIZE, attr, 0, bootpage_alloc, NULL);
+ while (sz >= PAGE_SIZE) {
+ aarch64_tlbi_by_va(va);
+ va += PAGE_SIZE;
+ sz -= PAGE_SIZE;
+ }
+}
diff -r ccb76da625bc -r a5001091d21f sys/arch/aarch64/conf/files.aarch64
--- a/sys/arch/aarch64/conf/files.aarch64 Sun Oct 28 10:18:34 2018 +0000
+++ b/sys/arch/aarch64/conf/files.aarch64 Sun Oct 28 10:21:42 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.aarch64,v 1.8 2018/10/18 09:01:51 skrll Exp $
+# $NetBSD: files.aarch64,v 1.9 2018/10/28 10:21:42 jmcneill Exp $
defflag opt_cpuoptions.h AARCH64_ALIGNMENT_CHECK
defflag opt_cpuoptions.h AARCH64_EL0_STACK_ALIGNMENT_CHECK
@@ -45,6 +45,10 @@
file arch/arm/arm/psci.c psci
file arch/arm/arm/psci_arm.S psci
+# EFI support
+defflag opt_efi.h EFI_RUNTIME
+file arch/arm/arm/efi_runtime.c efi_runtime
+
# PMAP_DEBUG (heavily abused option)
defflag PMAP_DEBUG
@@ -110,6 +114,9 @@
file arch/aarch64/aarch64/pmap_page.S
#file uvm/pmap/pmap_pvt.c
+# EFI runtime (machdep)
+file arch/aarch64/aarch64/efi_machdep.c efi_runtime
+
# cyclecounter
#file arch/aarch64/aarch64/cctr_machdep.c
#file kern/kern_cctr.c
diff -r ccb76da625bc -r a5001091d21f sys/arch/arm/acpi/acpi_platform.c
--- a/sys/arch/arm/acpi/acpi_platform.c Sun Oct 28 10:18:34 2018 +0000
+++ b/sys/arch/arm/acpi/acpi_platform.c Sun Oct 28 10:21:42 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_platform.c,v 1.4 2018/10/19 15:29:00 jmcneill Exp $ */
+/* $NetBSD: acpi_platform.c,v 1.5 2018/10/28 10:21:42 jmcneill Exp $ */
/*-
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -31,9 +31,10 @@
#include "com.h"
#include "plcom.h"
+#include "opt_efi.h"
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_platform.c,v 1.4 2018/10/19 15:29:00 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_platform.c,v 1.5 2018/10/28 10:21:42 jmcneill Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -63,9 +64,15 @@
#include <dev/ic/comreg.h>
#include <dev/ic/comvar.h>
+#ifdef EFI_RUNTIME
+#include <arm/arm/efi_runtime.h>
+#endif
+
#include <dev/acpi/acpireg.h>
#include <dev/acpi/acpivar.h>
-#include <arch/arm/acpi/acpi_table.h>
+#include <arm/acpi/acpi_table.h>
+
+#include <libfdt.h>
#define SPCR_INTERFACE_TYPE_PL011 0x0003
#define SPCR_INTERFACE_TYPE_SBSA_32BIT 0x000d
@@ -219,6 +226,10 @@
static void
acpi_platform_reset(void)
{
+#ifdef EFI_RUNTIME
+ if (arm_efirt_reset(EFI_RESET_COLD) == 0)
+ return;
+#endif
if (psci_available())
psci_system_reset();
}
diff -r ccb76da625bc -r a5001091d21f sys/arch/arm/arm/efi_runtime.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/arm/efi_runtime.c Sun Oct 28 10:21:42 2018 +0000
@@ -0,0 +1,128 @@
+/* $NetBSD: efi_runtime.c,v 1.1 2018/10/28 10:21:42 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jared McNeill <jmcneill%invisible.ca@localhost>.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: efi_runtime.c,v 1.1 2018/10/28 10:21:42 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/mutex.h>
+
+#include <uvm/uvm_extern.h>
+
+#include <arm/arm/efi_runtime.h>
+
+static kmutex_t efi_lock;
+
+static struct efi_systbl *ST = NULL;
+static struct efi_rt *RT = NULL;
+
+int
+arm_efirt_init(paddr_t efi_system_table)
+{
+ const size_t sz = PAGE_SIZE * 2;
+ vaddr_t va, cva;
+ paddr_t cpa;
+
+ va = uvm_km_alloc(kernel_map, sz, 0, UVM_KMF_VAONLY);
+ if (va == 0) {
+ aprint_error("%s: can't allocate VA\n", __func__);
+ return ENOMEM;
+ }
+ for (cva = va, cpa = trunc_page(efi_system_table);
+ cva < va + sz;
+ cva += PAGE_SIZE, cpa += PAGE_SIZE) {
+ pmap_kenter_pa(cva, cpa, VM_PROT_READ, 0);
+ }
+ pmap_update(pmap_kernel());
+
+ ST = (void *)(va + (efi_system_table - trunc_page(efi_system_table)));
+ if (ST->st_hdr.th_sig != EFI_SYSTBL_SIG) {
+ aprint_error("EFI: signature mismatch (%#lx != %#lx)\n",
+ ST->st_hdr.th_sig, EFI_SYSTBL_SIG);
+ return EINVAL;
+ }
+
+ RT = ST->st_rt;
+ mutex_init(&efi_lock, MUTEX_DEFAULT, IPL_HIGH);
+
+ return 0;
+}
+
+int
+arm_efirt_gettime(struct efi_tm *tm)
+{
+ efi_status status;
+
+ if (RT == NULL || RT->rt_gettime == NULL)
+ return ENXIO;
+
+ mutex_enter(&efi_lock);
+ status = RT->rt_gettime(tm, NULL);
+ mutex_exit(&efi_lock);
+ if (status)
+ return EIO;
+
+ return 0;
+}
+
+int
+arm_efirt_settime(struct efi_tm *tm)
+{
+ efi_status status;
+
+ if (RT == NULL || RT->rt_settime == NULL)
+ return ENXIO;
+
+ mutex_enter(&efi_lock);
+ status = RT->rt_settime(tm);
+ mutex_exit(&efi_lock);
+ if (status)
+ return EIO;
+
+ return 0;
+}
+
+int
+arm_efirt_reset(enum efi_reset type)
+{
+ efi_status status;
+
+ if (RT == NULL || RT->rt_reset == NULL)
+ return ENXIO;
+
+ mutex_enter(&efi_lock);
+ status = RT->rt_reset(type, 0, 0, NULL);
+ mutex_exit(&efi_lock);
+ if (status)
+ return EIO;
+
+ return 0;
+}
diff -r ccb76da625bc -r a5001091d21f sys/arch/arm/arm/efi_runtime.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/arm/efi_runtime.h Sun Oct 28 10:21:42 2018 +0000
@@ -0,0 +1,44 @@
+/* $NetBSD: efi_runtime.h,v 1.1 2018/10/28 10:21:42 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jared McNeill <jmcneill%invisible.ca@localhost>.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Home |
Main Index |
Thread Index |
Old Index