Reorganize the EFI code a bit. Move the efi.h header from dev/acpi to
authorkettenis <kettenis@openbsd.org>
Mon, 3 Oct 2022 19:32:22 +0000 (19:32 +0000)
committerkettenis <kettenis@openbsd.org>
Mon, 3 Oct 2022 19:32:22 +0000 (19:32 +0000)
dev/efi and rename the arm64 efi.c to efi_machdep.c, preparing the way
for MI EFI code and an amd64 implementation of EFI runtime support.

ok deraadt@, mlarkin@

sys/arch/arm64/arm64/machdep.c
sys/arch/arm64/conf/files.arm64
sys/arch/arm64/dev/efi.c [deleted file]
sys/arch/arm64/dev/efi_machdep.c [new file with mode: 0644]
sys/arch/armv7/armv7/armv7_machdep.c
sys/arch/riscv64/riscv64/machdep.c
sys/dev/acpi/efi.h [deleted file]
sys/dev/efi/efi.h [new file with mode: 0644]

index 41be380..01c25ad 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: machdep.c,v 1.72 2022/09/05 19:18:56 kettenis Exp $ */
+/* $OpenBSD: machdep.c,v 1.73 2022/10/03 19:32:22 kettenis Exp $ */
 /*
  * Copyright (c) 2014 Patrick Wildt <patrick@blueri.se>
  * Copyright (c) 2021 Mark Kettenis <kettenis@openbsd.org>
@@ -49,7 +49,7 @@
 #include <machine/db_machdep.h>
 #include <ddb/db_extern.h>
 
-#include <dev/acpi/efi.h>
+#include <dev/efi/efi.h>
 
 #include "softraid.h"
 #if NSOFTRAID > 0
index a7e74d8..2a7bdba 100644 (file)
@@ -1,4 +1,4 @@
-# $OpenBSD: files.arm64,v 1.60 2022/09/03 08:44:56 kettenis Exp $
+# $OpenBSD: files.arm64,v 1.61 2022/10/03 19:32:22 kettenis Exp $
 
 maxpartitions  16
 maxusers       2 8 128
@@ -65,7 +65,7 @@ file  arch/arm64/dev/simplebus.c              simplebus
 
 device efi {}
 attach efi at fdt
-file   arch/arm64/dev/efi.c                    efi
+file   arch/arm64/dev/efi_machdep.c            efi
 
 device smbios
 attach smbios at efi
diff --git a/sys/arch/arm64/dev/efi.c b/sys/arch/arm64/dev/efi.c
deleted file mode 100644 (file)
index 46034ef..0000000
+++ /dev/null
@@ -1,337 +0,0 @@
-/*     $OpenBSD: efi.c,v 1.14 2022/07/30 17:56:54 kettenis Exp $       */
-
-/*
- * Copyright (c) 2017 Mark Kettenis <kettenis@openbsd.org>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <sys/param.h>
-#include <sys/device.h>
-#include <sys/systm.h>
-
-#include <uvm/uvm_extern.h>
-
-#include <machine/cpufunc.h>
-#include <machine/bus.h>
-#include <machine/fdt.h>
-#include <machine/fpu.h>
-
-#include <dev/ofw/openfirm.h>
-#include <dev/ofw/fdt.h>
-
-#include <dev/acpi/efi.h>
-
-#include <dev/clock_subr.h>
-
-/*
- * We need a large address space to allow identity mapping of physical
- * memory on some machines.
- */
-#define EFI_SPACE_BITS 48
-
-extern todr_chip_handle_t todr_handle;
-
-extern uint32_t mmap_size;
-extern uint32_t mmap_desc_size;
-extern uint32_t mmap_desc_ver;
-
-extern EFI_MEMORY_DESCRIPTOR *mmap;
-
-uint64_t efi_acpi_table;
-uint64_t efi_smbios_table;
-
-struct efi_softc {
-       struct device   sc_dev;
-       struct pmap     *sc_pm;
-       EFI_RUNTIME_SERVICES *sc_rs;
-       u_long          sc_psw;
-
-       struct todr_chip_handle sc_todr;
-};
-
-int    efi_match(struct device *, void *, void *);
-void   efi_attach(struct device *, struct device *, void *);
-
-const struct cfattach efi_ca = {
-       sizeof(struct efi_softc), efi_match, efi_attach
-};
-
-struct cfdriver efi_cd = {
-       NULL, "efi", DV_DULL
-};
-
-void   efi_map_runtime(struct efi_softc *);
-void   efi_enter(struct efi_softc *);
-void   efi_leave(struct efi_softc *);
-int    efi_gettime(struct todr_chip_handle *, struct timeval *);
-int    efi_settime(struct todr_chip_handle *, struct timeval *);
-
-int
-efi_match(struct device *parent, void *match, void *aux)
-{
-       struct fdt_attach_args *faa = aux;
-
-       return (strcmp(faa->fa_name, "efi") == 0);
-}
-
-void
-efi_attach(struct device *parent, struct device *self, void *aux)
-{
-       struct efi_softc *sc = (struct efi_softc *)self;
-       struct fdt_attach_args *faa = aux;
-       uint64_t system_table;
-       bus_space_handle_t ioh;
-       EFI_SYSTEM_TABLE *st;
-       EFI_TIME time;
-       EFI_STATUS status;
-       uint16_t major, minor;
-       int node, i;
-
-       node = OF_finddevice("/chosen");
-       KASSERT(node != -1);
-
-       system_table = OF_getpropint64(node, "openbsd,uefi-system-table", 0);
-       KASSERT(system_table);
-
-       if (bus_space_map(faa->fa_iot, system_table, sizeof(EFI_SYSTEM_TABLE),
-           BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_CACHEABLE, &ioh)) {
-               printf(": can't map system table\n");
-               return;
-       }
-
-       st = bus_space_vaddr(faa->fa_iot, ioh);
-       sc->sc_rs = st->RuntimeServices;
-
-       major = st->Hdr.Revision >> 16;
-       minor = st->Hdr.Revision & 0xffff;
-       printf(": UEFI %d.%d", major, minor / 10);
-       if (minor % 10)
-               printf(".%d", minor % 10);
-       printf("\n");
-
-       efi_map_runtime(sc);
-
-       /*
-        * Activate our pmap such that we can access the
-        * FirmwareVendor and ConfigurationTable fields.
-        */
-       efi_enter(sc);
-       if (st->FirmwareVendor) {
-               printf("%s: ", sc->sc_dev.dv_xname);
-               for (i = 0; st->FirmwareVendor[i]; i++)
-                       printf("%c", st->FirmwareVendor[i]);
-               printf(" rev 0x%x\n", st->FirmwareRevision);
-       }
-       for (i = 0; i < st->NumberOfTableEntries; i++) {
-               EFI_CONFIGURATION_TABLE *ct = &st->ConfigurationTable[i];
-               static EFI_GUID acpi_guid = EFI_ACPI_20_TABLE_GUID;
-               static EFI_GUID smbios_guid = SMBIOS3_TABLE_GUID;
-
-               if (efi_guidcmp(&acpi_guid, &ct->VendorGuid) == 0)
-                       efi_acpi_table = (uint64_t)ct->VendorTable;
-               if (efi_guidcmp(&smbios_guid, &ct->VendorGuid) == 0)
-                       efi_smbios_table = (uint64_t)ct->VendorTable;
-       }
-       efi_leave(sc);
-
-       if (efi_smbios_table != 0) {
-               struct fdt_reg reg = { .addr = efi_smbios_table };
-               struct fdt_attach_args fa;
-
-               fa.fa_name = "smbios";
-               fa.fa_iot = faa->fa_iot;
-               fa.fa_reg = &reg;
-               fa.fa_nreg = 1;
-               config_found(self, &fa, NULL);
-       }
-       
-       efi_enter(sc);
-       status = sc->sc_rs->GetTime(&time, NULL);
-       efi_leave(sc);
-       if (status != EFI_SUCCESS)
-               return;
-
-       sc->sc_todr.cookie = sc;
-       sc->sc_todr.todr_gettime = efi_gettime;
-       sc->sc_todr.todr_settime = efi_settime;
-       todr_handle = &sc->sc_todr;
-}
-
-void
-efi_map_runtime(struct efi_softc *sc)
-{
-       EFI_MEMORY_DESCRIPTOR *desc;
-       int i;
-
-       /*
-        * We don't really want some random executable non-OpenBSD
-        * code lying around in kernel space.  So create a separate
-        * pmap and only activate it when we call runtime services.
-        */
-       sc->sc_pm = pmap_create();
-       sc->sc_pm->pm_privileged = 1;
-       sc->sc_pm->have_4_level_pt = 1;
-
-       desc = mmap;
-       for (i = 0; i < mmap_size / mmap_desc_size; i++) {
-               if (desc->Attribute & EFI_MEMORY_RUNTIME) {
-                       vaddr_t va = desc->VirtualStart;
-                       paddr_t pa = desc->PhysicalStart;
-                       int npages = desc->NumberOfPages;
-                       vm_prot_t prot = PROT_READ | PROT_WRITE;
-
-#ifdef EFI_DEBUG
-                       printf("type 0x%x pa 0x%llx va 0x%llx pages 0x%llx attr 0x%llx\n",
-                           desc->Type, desc->PhysicalStart,
-                           desc->VirtualStart, desc->NumberOfPages,
-                           desc->Attribute);
-#endif
-
-                       /*
-                        * If the virtual address is still zero, use
-                        * an identity mapping.
-                        */
-                       if (va == 0)
-                               va = pa;
-
-                       /*
-                        * Normal memory is expected to be "write
-                        * back" cacheable.  Everything else is mapped
-                        * as device memory.
-                        */
-                       if ((desc->Attribute & EFI_MEMORY_WB) == 0)
-                               pa |= PMAP_DEVICE;
-
-                       /*
-                        * Only make pages marked as runtime service code
-                        * executable.  This violates the standard but it
-                        * seems we can get away with it.
-                        */
-                       if (desc->Type == EfiRuntimeServicesCode)
-                               prot |= PROT_EXEC;
-
-                       if (desc->Attribute & EFI_MEMORY_RP)
-                               prot &= ~PROT_READ;
-                       if (desc->Attribute & EFI_MEMORY_XP)
-                               prot &= ~PROT_EXEC;
-                       if (desc->Attribute & EFI_MEMORY_RO)
-                               prot &= ~PROT_WRITE;
-
-                       while (npages--) {
-                               pmap_enter(sc->sc_pm, va, pa, prot,
-                                  prot | PMAP_WIRED);
-                               va += PAGE_SIZE;
-                               pa += PAGE_SIZE;
-                       }
-               }
-
-               desc = NextMemoryDescriptor(desc, mmap_desc_size);
-       }
-}
-
-void
-efi_enter(struct efi_softc *sc)
-{
-       struct pmap *pm = sc->sc_pm;
-       uint64_t tcr;
-
-       sc->sc_psw = intr_disable();
-       WRITE_SPECIALREG(ttbr0_el1, pmap_kernel()->pm_pt0pa);
-       __asm volatile("isb");
-       tcr = READ_SPECIALREG(tcr_el1);
-       tcr &= ~TCR_T0SZ(0x3f);
-       tcr |= TCR_T0SZ(64 - EFI_SPACE_BITS);
-       WRITE_SPECIALREG(tcr_el1, tcr);
-       cpu_setttb(pm->pm_asid, pm->pm_pt0pa);
-
-       fpu_kernel_enter();
-}
-
-void
-efi_leave(struct efi_softc *sc)
-{
-       struct pmap *pm = curcpu()->ci_curpm;
-       uint64_t tcr;
-
-       fpu_kernel_exit();
-
-       WRITE_SPECIALREG(ttbr0_el1, pmap_kernel()->pm_pt0pa);
-       __asm volatile("isb");
-       tcr = READ_SPECIALREG(tcr_el1);
-       tcr &= ~TCR_T0SZ(0x3f);
-       tcr |= TCR_T0SZ(64 - USER_SPACE_BITS);
-       WRITE_SPECIALREG(tcr_el1, tcr);
-       cpu_setttb(pm->pm_asid, pm->pm_pt0pa);
-       intr_restore(sc->sc_psw);
-}
-
-int
-efi_gettime(struct todr_chip_handle *handle, struct timeval *tv)
-{
-       struct efi_softc *sc = handle->cookie;
-       struct clock_ymdhms dt;
-       EFI_TIME time;
-       EFI_STATUS status;
-
-       efi_enter(sc);
-       status = sc->sc_rs->GetTime(&time, NULL);
-       efi_leave(sc);
-       if (status != EFI_SUCCESS)
-               return EIO;
-
-       dt.dt_year = time.Year;
-       dt.dt_mon = time.Month;
-       dt.dt_day = time.Day;
-       dt.dt_hour = time.Hour;
-       dt.dt_min = time.Minute;
-       dt.dt_sec = time.Second;
-
-       if (dt.dt_sec > 59 || dt.dt_min > 59 || dt.dt_hour > 23 ||
-           dt.dt_day > 31 || dt.dt_day == 0 ||
-           dt.dt_mon > 12 || dt.dt_mon == 0 ||
-           dt.dt_year < POSIX_BASE_YEAR)
-               return EINVAL;
-
-       tv->tv_sec = clock_ymdhms_to_secs(&dt);
-       tv->tv_usec = 0;
-       return 0;
-}
-
-int
-efi_settime(struct todr_chip_handle *handle, struct timeval *tv)
-{
-       struct efi_softc *sc = handle->cookie;
-       struct clock_ymdhms dt;
-       EFI_TIME time;
-       EFI_STATUS status;
-
-       clock_secs_to_ymdhms(tv->tv_sec, &dt);
-
-       time.Year = dt.dt_year;
-       time.Month = dt.dt_mon;
-       time.Day = dt.dt_day;
-       time.Hour = dt.dt_hour;
-       time.Minute = dt.dt_min;
-       time.Second = dt.dt_sec;
-       time.Nanosecond = 0;
-       time.TimeZone = 0;
-       time.Daylight = 0;
-
-       efi_enter(sc);
-       status = sc->sc_rs->SetTime(&time);
-       efi_leave(sc);
-       if (status != EFI_SUCCESS)
-               return EIO;
-       return 0;
-}
diff --git a/sys/arch/arm64/dev/efi_machdep.c b/sys/arch/arm64/dev/efi_machdep.c
new file mode 100644 (file)
index 0000000..5f6bbb2
--- /dev/null
@@ -0,0 +1,337 @@
+/*     $OpenBSD: efi_machdep.c,v 1.1 2022/10/03 19:32:22 kettenis Exp $        */
+
+/*
+ * Copyright (c) 2017 Mark Kettenis <kettenis@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/param.h>
+#include <sys/device.h>
+#include <sys/systm.h>
+
+#include <uvm/uvm_extern.h>
+
+#include <machine/cpufunc.h>
+#include <machine/bus.h>
+#include <machine/fdt.h>
+#include <machine/fpu.h>
+
+#include <dev/ofw/openfirm.h>
+#include <dev/ofw/fdt.h>
+
+#include <dev/efi/efi.h>
+
+#include <dev/clock_subr.h>
+
+/*
+ * We need a large address space to allow identity mapping of physical
+ * memory on some machines.
+ */
+#define EFI_SPACE_BITS 48
+
+extern todr_chip_handle_t todr_handle;
+
+extern uint32_t mmap_size;
+extern uint32_t mmap_desc_size;
+extern uint32_t mmap_desc_ver;
+
+extern EFI_MEMORY_DESCRIPTOR *mmap;
+
+uint64_t efi_acpi_table;
+uint64_t efi_smbios_table;
+
+struct efi_softc {
+       struct device   sc_dev;
+       struct pmap     *sc_pm;
+       EFI_RUNTIME_SERVICES *sc_rs;
+       u_long          sc_psw;
+
+       struct todr_chip_handle sc_todr;
+};
+
+int    efi_match(struct device *, void *, void *);
+void   efi_attach(struct device *, struct device *, void *);
+
+const struct cfattach efi_ca = {
+       sizeof(struct efi_softc), efi_match, efi_attach
+};
+
+struct cfdriver efi_cd = {
+       NULL, "efi", DV_DULL
+};
+
+void   efi_map_runtime(struct efi_softc *);
+void   efi_enter(struct efi_softc *);
+void   efi_leave(struct efi_softc *);
+int    efi_gettime(struct todr_chip_handle *, struct timeval *);
+int    efi_settime(struct todr_chip_handle *, struct timeval *);
+
+int
+efi_match(struct device *parent, void *match, void *aux)
+{
+       struct fdt_attach_args *faa = aux;
+
+       return (strcmp(faa->fa_name, "efi") == 0);
+}
+
+void
+efi_attach(struct device *parent, struct device *self, void *aux)
+{
+       struct efi_softc *sc = (struct efi_softc *)self;
+       struct fdt_attach_args *faa = aux;
+       uint64_t system_table;
+       bus_space_handle_t ioh;
+       EFI_SYSTEM_TABLE *st;
+       EFI_TIME time;
+       EFI_STATUS status;
+       uint16_t major, minor;
+       int node, i;
+
+       node = OF_finddevice("/chosen");
+       KASSERT(node != -1);
+
+       system_table = OF_getpropint64(node, "openbsd,uefi-system-table", 0);
+       KASSERT(system_table);
+
+       if (bus_space_map(faa->fa_iot, system_table, sizeof(EFI_SYSTEM_TABLE),
+           BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_CACHEABLE, &ioh)) {
+               printf(": can't map system table\n");
+               return;
+       }
+
+       st = bus_space_vaddr(faa->fa_iot, ioh);
+       sc->sc_rs = st->RuntimeServices;
+
+       major = st->Hdr.Revision >> 16;
+       minor = st->Hdr.Revision & 0xffff;
+       printf(": UEFI %d.%d", major, minor / 10);
+       if (minor % 10)
+               printf(".%d", minor % 10);
+       printf("\n");
+
+       efi_map_runtime(sc);
+
+       /*
+        * Activate our pmap such that we can access the
+        * FirmwareVendor and ConfigurationTable fields.
+        */
+       efi_enter(sc);
+       if (st->FirmwareVendor) {
+               printf("%s: ", sc->sc_dev.dv_xname);
+               for (i = 0; st->FirmwareVendor[i]; i++)
+                       printf("%c", st->FirmwareVendor[i]);
+               printf(" rev 0x%x\n", st->FirmwareRevision);
+       }
+       for (i = 0; i < st->NumberOfTableEntries; i++) {
+               EFI_CONFIGURATION_TABLE *ct = &st->ConfigurationTable[i];
+               static EFI_GUID acpi_guid = EFI_ACPI_20_TABLE_GUID;
+               static EFI_GUID smbios_guid = SMBIOS3_TABLE_GUID;
+
+               if (efi_guidcmp(&acpi_guid, &ct->VendorGuid) == 0)
+                       efi_acpi_table = (uint64_t)ct->VendorTable;
+               if (efi_guidcmp(&smbios_guid, &ct->VendorGuid) == 0)
+                       efi_smbios_table = (uint64_t)ct->VendorTable;
+       }
+       efi_leave(sc);
+
+       if (efi_smbios_table != 0) {
+               struct fdt_reg reg = { .addr = efi_smbios_table };
+               struct fdt_attach_args fa;
+
+               fa.fa_name = "smbios";
+               fa.fa_iot = faa->fa_iot;
+               fa.fa_reg = &reg;
+               fa.fa_nreg = 1;
+               config_found(self, &fa, NULL);
+       }
+       
+       efi_enter(sc);
+       status = sc->sc_rs->GetTime(&time, NULL);
+       efi_leave(sc);
+       if (status != EFI_SUCCESS)
+               return;
+
+       sc->sc_todr.cookie = sc;
+       sc->sc_todr.todr_gettime = efi_gettime;
+       sc->sc_todr.todr_settime = efi_settime;
+       todr_handle = &sc->sc_todr;
+}
+
+void
+efi_map_runtime(struct efi_softc *sc)
+{
+       EFI_MEMORY_DESCRIPTOR *desc;
+       int i;
+
+       /*
+        * We don't really want some random executable non-OpenBSD
+        * code lying around in kernel space.  So create a separate
+        * pmap and only activate it when we call runtime services.
+        */
+       sc->sc_pm = pmap_create();
+       sc->sc_pm->pm_privileged = 1;
+       sc->sc_pm->have_4_level_pt = 1;
+
+       desc = mmap;
+       for (i = 0; i < mmap_size / mmap_desc_size; i++) {
+               if (desc->Attribute & EFI_MEMORY_RUNTIME) {
+                       vaddr_t va = desc->VirtualStart;
+                       paddr_t pa = desc->PhysicalStart;
+                       int npages = desc->NumberOfPages;
+                       vm_prot_t prot = PROT_READ | PROT_WRITE;
+
+#ifdef EFI_DEBUG
+                       printf("type 0x%x pa 0x%llx va 0x%llx pages 0x%llx attr 0x%llx\n",
+                           desc->Type, desc->PhysicalStart,
+                           desc->VirtualStart, desc->NumberOfPages,
+                           desc->Attribute);
+#endif
+
+                       /*
+                        * If the virtual address is still zero, use
+                        * an identity mapping.
+                        */
+                       if (va == 0)
+                               va = pa;
+
+                       /*
+                        * Normal memory is expected to be "write
+                        * back" cacheable.  Everything else is mapped
+                        * as device memory.
+                        */
+                       if ((desc->Attribute & EFI_MEMORY_WB) == 0)
+                               pa |= PMAP_DEVICE;
+
+                       /*
+                        * Only make pages marked as runtime service code
+                        * executable.  This violates the standard but it
+                        * seems we can get away with it.
+                        */
+                       if (desc->Type == EfiRuntimeServicesCode)
+                               prot |= PROT_EXEC;
+
+                       if (desc->Attribute & EFI_MEMORY_RP)
+                               prot &= ~PROT_READ;
+                       if (desc->Attribute & EFI_MEMORY_XP)
+                               prot &= ~PROT_EXEC;
+                       if (desc->Attribute & EFI_MEMORY_RO)
+                               prot &= ~PROT_WRITE;
+
+                       while (npages--) {
+                               pmap_enter(sc->sc_pm, va, pa, prot,
+                                  prot | PMAP_WIRED);
+                               va += PAGE_SIZE;
+                               pa += PAGE_SIZE;
+                       }
+               }
+
+               desc = NextMemoryDescriptor(desc, mmap_desc_size);
+       }
+}
+
+void
+efi_enter(struct efi_softc *sc)
+{
+       struct pmap *pm = sc->sc_pm;
+       uint64_t tcr;
+
+       sc->sc_psw = intr_disable();
+       WRITE_SPECIALREG(ttbr0_el1, pmap_kernel()->pm_pt0pa);
+       __asm volatile("isb");
+       tcr = READ_SPECIALREG(tcr_el1);
+       tcr &= ~TCR_T0SZ(0x3f);
+       tcr |= TCR_T0SZ(64 - EFI_SPACE_BITS);
+       WRITE_SPECIALREG(tcr_el1, tcr);
+       cpu_setttb(pm->pm_asid, pm->pm_pt0pa);
+
+       fpu_kernel_enter();
+}
+
+void
+efi_leave(struct efi_softc *sc)
+{
+       struct pmap *pm = curcpu()->ci_curpm;
+       uint64_t tcr;
+
+       fpu_kernel_exit();
+
+       WRITE_SPECIALREG(ttbr0_el1, pmap_kernel()->pm_pt0pa);
+       __asm volatile("isb");
+       tcr = READ_SPECIALREG(tcr_el1);
+       tcr &= ~TCR_T0SZ(0x3f);
+       tcr |= TCR_T0SZ(64 - USER_SPACE_BITS);
+       WRITE_SPECIALREG(tcr_el1, tcr);
+       cpu_setttb(pm->pm_asid, pm->pm_pt0pa);
+       intr_restore(sc->sc_psw);
+}
+
+int
+efi_gettime(struct todr_chip_handle *handle, struct timeval *tv)
+{
+       struct efi_softc *sc = handle->cookie;
+       struct clock_ymdhms dt;
+       EFI_TIME time;
+       EFI_STATUS status;
+
+       efi_enter(sc);
+       status = sc->sc_rs->GetTime(&time, NULL);
+       efi_leave(sc);
+       if (status != EFI_SUCCESS)
+               return EIO;
+
+       dt.dt_year = time.Year;
+       dt.dt_mon = time.Month;
+       dt.dt_day = time.Day;
+       dt.dt_hour = time.Hour;
+       dt.dt_min = time.Minute;
+       dt.dt_sec = time.Second;
+
+       if (dt.dt_sec > 59 || dt.dt_min > 59 || dt.dt_hour > 23 ||
+           dt.dt_day > 31 || dt.dt_day == 0 ||
+           dt.dt_mon > 12 || dt.dt_mon == 0 ||
+           dt.dt_year < POSIX_BASE_YEAR)
+               return EINVAL;
+
+       tv->tv_sec = clock_ymdhms_to_secs(&dt);
+       tv->tv_usec = 0;
+       return 0;
+}
+
+int
+efi_settime(struct todr_chip_handle *handle, struct timeval *tv)
+{
+       struct efi_softc *sc = handle->cookie;
+       struct clock_ymdhms dt;
+       EFI_TIME time;
+       EFI_STATUS status;
+
+       clock_secs_to_ymdhms(tv->tv_sec, &dt);
+
+       time.Year = dt.dt_year;
+       time.Month = dt.dt_mon;
+       time.Day = dt.dt_day;
+       time.Hour = dt.dt_hour;
+       time.Minute = dt.dt_min;
+       time.Second = dt.dt_sec;
+       time.Nanosecond = 0;
+       time.TimeZone = 0;
+       time.Daylight = 0;
+
+       efi_enter(sc);
+       status = sc->sc_rs->SetTime(&time);
+       efi_leave(sc);
+       if (status != EFI_SUCCESS)
+               return EIO;
+       return 0;
+}
index b33e3f2..83c04d9 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: armv7_machdep.c,v 1.64 2021/10/06 12:50:10 visa Exp $ */
+/*     $OpenBSD: armv7_machdep.c,v 1.65 2022/10/03 19:32:22 kettenis Exp $ */
 /*     $NetBSD: lubbock_machdep.c,v 1.2 2003/07/15 00:25:06 lukem Exp $ */
 
 /*
 #include <armv7/armv7/armv7_machdep.h>
 
 #include <dev/cons.h>
+#include <dev/efi/efi.h>
 #include <dev/ofw/fdt.h>
 #include <dev/ofw/openfirm.h>
-#include <dev/acpi/efi.h>
 
 #include <net/if.h>
 
index 9e6b3cd..6685ad9 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: machdep.c,v 1.27 2022/03/22 06:48:36 miod Exp $       */
+/*     $OpenBSD: machdep.c,v 1.28 2022/10/03 19:32:22 kettenis Exp $   */
 
 /*
  * Copyright (c) 2014 Patrick Wildt <patrick@blueri.se>
@@ -49,7 +49,7 @@
 #include <machine/db_machdep.h>
 #include <ddb/db_extern.h>
 
-#include <dev/acpi/efi.h>
+#include <dev/efi/efi.h>
 
 #include "softraid.h"
 #if NSOFTRAID > 0
diff --git a/sys/dev/acpi/efi.h b/sys/dev/acpi/efi.h
deleted file mode 100644 (file)
index d15fa4c..0000000
+++ /dev/null
@@ -1,153 +0,0 @@
-/* $OpenBSD: efi.h,v 1.4 2019/08/04 09:27:09 kettenis Exp $ */
-
-/* Public Domain */
-
-#ifndef _MACHINE_EFI_H_
-#define _MACHINE_EFI_H_
-
-typedef uint8_t                UINT8;
-typedef int16_t                INT16;
-typedef uint16_t       UINT16;
-typedef uint32_t       UINT32;
-typedef uint64_t       UINT64;
-typedef u_long         UINTN;
-typedef uint16_t       CHAR16;
-typedef void           VOID;
-typedef uint64_t       EFI_PHYSICAL_ADDRESS;
-typedef uint64_t       EFI_VIRTUAL_ADDRESS;
-typedef UINTN          EFI_STATUS;
-typedef VOID           *EFI_HANDLE;
-
-typedef VOID           *EFI_SIMPLE_TEXT_INPUT_PROTOCOL;
-typedef VOID           *EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL;
-typedef VOID           *EFI_BOOT_SERVICES;
-
-typedef struct {
-       UINT32  Data1;
-       UINT16  Data2;
-       UINT16  Data3;
-       UINT8   Data4[8];
-} EFI_GUID;
-
-#define EFI_ACPI_20_TABLE_GUID \
-  { 0x8868e871, 0xe4f1, 0x11d3, \
-    { 0xbc, 0x22, 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81 } }
-
-#define SMBIOS_TABLE_GUID \
-  { 0xeb9d2d31, 0x2d88, 0x11d3, \
-    { 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } }
-
-#define SMBIOS3_TABLE_GUID \
-  { 0xf2fd1544, 0x9794, 0x4a2c, \
-    { 0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94 } }
-
-typedef enum {
-       EfiReservedMemoryType,
-       EfiLoaderCode,
-       EfiLoaderData,
-       EfiBootServicesCode,
-       EfiBootServicesData,
-       EfiRuntimeServicesCode,
-       EfiRuntimeServicesData,
-       EfiConventionalMemory,
-       EfiUnusableMemory,
-       EfiACPIReclaimMemory,
-       EfiACPIMemoryNVS,
-       EfiMemoryMappedIO,
-       EfiMemoryMappedIOPortSpace,
-       EfiPalCode,
-       EfiPersistentMemory,
-        EfiMaxMemoryType
-} EFI_MEMORY_TYPE;
-
-#define EFI_MEMORY_UC                  0x0000000000000001
-#define EFI_MEMORY_WC                  0x0000000000000002
-#define EFI_MEMORY_WT                  0x0000000000000004
-#define EFI_MEMORY_WB                  0x0000000000000008
-#define EFI_MEMORY_UCE                 0x0000000000000010
-#define EFI_MEMORY_WP                  0x0000000000001000
-#define EFI_MEMORY_RP                  0x0000000000002000
-#define EFI_MEMORY_XP                  0x0000000000004000
-#define EFI_MEMORY_NV                  0x0000000000008000
-#define EFI_MEMORY_MORE_RELIABLE       0x0000000000010000
-#define EFI_MEMORY_RO                  0x0000000000020000
-#define EFI_MEMORY_RUNTIME             0x8000000000000000
-
-#define EFI_MEMORY_DESCRIPTOR_VERSION  1
-
-typedef struct {
-       UINT32                  Type;
-       UINT32                  Pad;
-       EFI_PHYSICAL_ADDRESS    PhysicalStart;
-       EFI_VIRTUAL_ADDRESS     VirtualStart;
-       UINT64                  NumberOfPages;
-       UINT64                  Attribute;
-} EFI_MEMORY_DESCRIPTOR;
-
-#define NextMemoryDescriptor(Ptr, Size) \
-       ((EFI_MEMORY_DESCRIPTOR *)(((UINT8 *)Ptr) + Size))
-
-typedef struct {
-       UINT64                          Signature;
-       UINT32                          Revision;
-       UINT32                          HeaderSize;
-       UINT32                          CRC32;
-       UINT32                          Reserved;
-} EFI_TABLE_HEADER;
-
-typedef struct {
-       UINT16                          Year;
-       UINT8                           Month;
-       UINT8                           Day;
-       UINT8                           Hour;
-       UINT8                           Minute;
-       UINT8                           Second;
-       UINT8                           Pad1;
-       UINT32                          Nanosecond;
-       INT16                           TimeZone;
-       UINT8                           Daylight;
-       UINT8                           Pad2;
-} EFI_TIME;
-
-typedef VOID           *EFI_TIME_CAPABILITIES;
-
-typedef EFI_STATUS (*EFI_GET_TIME)(EFI_TIME *, EFI_TIME_CAPABILITIES *);
-typedef EFI_STATUS (*EFI_SET_TIME)(EFI_TIME *);
-typedef EFI_STATUS (*EFI_SET_VIRTUAL_ADDRESS_MAP)(UINTN, UINTN, UINT32, EFI_MEMORY_DESCRIPTOR *);
-
-typedef struct {
-       EFI_TABLE_HEADER                Hdr;
-       EFI_GET_TIME                    GetTime;
-       EFI_SET_TIME                    SetTime;
-       VOID                            *GetWakeupTime;
-       VOID                            *SetWakeupTime;
-
-       EFI_SET_VIRTUAL_ADDRESS_MAP     SetVirtualAddressMap;
-} EFI_RUNTIME_SERVICES;
-
-typedef struct {
-       EFI_GUID                        VendorGuid;
-       VOID                            *VendorTable;
-} EFI_CONFIGURATION_TABLE;
-
-typedef struct {
-       EFI_TABLE_HEADER                Hdr;
-       CHAR16                          *FirmwareVendor;
-       UINT32                          FirmwareRevision;
-       EFI_HANDLE                      ConsoleInHandle;
-       EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *ConIn;
-       EFI_HANDLE                      ConsoleOutHandle;
-       EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut;
-       EFI_HANDLE                      StandardErrorHandle;
-       EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *StdErr;
-       EFI_RUNTIME_SERVICES            *RuntimeServices;
-       EFI_BOOT_SERVICES               *BootServices;
-       UINTN                           NumberOfTableEntries;
-       EFI_CONFIGURATION_TABLE         *ConfigurationTable;
-} EFI_SYSTEM_TABLE;
-
-#define EFI_SUCCESS    0
-
-#define        efi_guidcmp(_a, _b)     memcmp((_a), (_b), sizeof(EFI_GUID))
-
-#endif /* _DEV_ACPI_EFI_H_ */
diff --git a/sys/dev/efi/efi.h b/sys/dev/efi/efi.h
new file mode 100644 (file)
index 0000000..3fa5b10
--- /dev/null
@@ -0,0 +1,153 @@
+/* $OpenBSD: efi.h,v 1.1 2022/10/03 19:32:22 kettenis Exp $ */
+
+/* Public Domain */
+
+#ifndef _MACHINE_EFI_H_
+#define _MACHINE_EFI_H_
+
+typedef uint8_t                UINT8;
+typedef int16_t                INT16;
+typedef uint16_t       UINT16;
+typedef uint32_t       UINT32;
+typedef uint64_t       UINT64;
+typedef u_long         UINTN;
+typedef uint16_t       CHAR16;
+typedef void           VOID;
+typedef uint64_t       EFI_PHYSICAL_ADDRESS;
+typedef uint64_t       EFI_VIRTUAL_ADDRESS;
+typedef UINTN          EFI_STATUS;
+typedef VOID           *EFI_HANDLE;
+
+typedef VOID           *EFI_SIMPLE_TEXT_INPUT_PROTOCOL;
+typedef VOID           *EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL;
+typedef VOID           *EFI_BOOT_SERVICES;
+
+typedef struct {
+       UINT32  Data1;
+       UINT16  Data2;
+       UINT16  Data3;
+       UINT8   Data4[8];
+} EFI_GUID;
+
+#define EFI_ACPI_20_TABLE_GUID \
+  { 0x8868e871, 0xe4f1, 0x11d3, \
+    { 0xbc, 0x22, 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81 } }
+
+#define SMBIOS_TABLE_GUID \
+  { 0xeb9d2d31, 0x2d88, 0x11d3, \
+    { 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } }
+
+#define SMBIOS3_TABLE_GUID \
+  { 0xf2fd1544, 0x9794, 0x4a2c, \
+    { 0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94 } }
+
+typedef enum {
+       EfiReservedMemoryType,
+       EfiLoaderCode,
+       EfiLoaderData,
+       EfiBootServicesCode,
+       EfiBootServicesData,
+       EfiRuntimeServicesCode,
+       EfiRuntimeServicesData,
+       EfiConventionalMemory,
+       EfiUnusableMemory,
+       EfiACPIReclaimMemory,
+       EfiACPIMemoryNVS,
+       EfiMemoryMappedIO,
+       EfiMemoryMappedIOPortSpace,
+       EfiPalCode,
+       EfiPersistentMemory,
+        EfiMaxMemoryType
+} EFI_MEMORY_TYPE;
+
+#define EFI_MEMORY_UC                  0x0000000000000001
+#define EFI_MEMORY_WC                  0x0000000000000002
+#define EFI_MEMORY_WT                  0x0000000000000004
+#define EFI_MEMORY_WB                  0x0000000000000008
+#define EFI_MEMORY_UCE                 0x0000000000000010
+#define EFI_MEMORY_WP                  0x0000000000001000
+#define EFI_MEMORY_RP                  0x0000000000002000
+#define EFI_MEMORY_XP                  0x0000000000004000
+#define EFI_MEMORY_NV                  0x0000000000008000
+#define EFI_MEMORY_MORE_RELIABLE       0x0000000000010000
+#define EFI_MEMORY_RO                  0x0000000000020000
+#define EFI_MEMORY_RUNTIME             0x8000000000000000
+
+#define EFI_MEMORY_DESCRIPTOR_VERSION  1
+
+typedef struct {
+       UINT32                  Type;
+       UINT32                  Pad;
+       EFI_PHYSICAL_ADDRESS    PhysicalStart;
+       EFI_VIRTUAL_ADDRESS     VirtualStart;
+       UINT64                  NumberOfPages;
+       UINT64                  Attribute;
+} EFI_MEMORY_DESCRIPTOR;
+
+#define NextMemoryDescriptor(Ptr, Size) \
+       ((EFI_MEMORY_DESCRIPTOR *)(((UINT8 *)Ptr) + Size))
+
+typedef struct {
+       UINT64                          Signature;
+       UINT32                          Revision;
+       UINT32                          HeaderSize;
+       UINT32                          CRC32;
+       UINT32                          Reserved;
+} EFI_TABLE_HEADER;
+
+typedef struct {
+       UINT16                          Year;
+       UINT8                           Month;
+       UINT8                           Day;
+       UINT8                           Hour;
+       UINT8                           Minute;
+       UINT8                           Second;
+       UINT8                           Pad1;
+       UINT32                          Nanosecond;
+       INT16                           TimeZone;
+       UINT8                           Daylight;
+       UINT8                           Pad2;
+} EFI_TIME;
+
+typedef VOID           *EFI_TIME_CAPABILITIES;
+
+typedef EFI_STATUS (*EFI_GET_TIME)(EFI_TIME *, EFI_TIME_CAPABILITIES *);
+typedef EFI_STATUS (*EFI_SET_TIME)(EFI_TIME *);
+typedef EFI_STATUS (*EFI_SET_VIRTUAL_ADDRESS_MAP)(UINTN, UINTN, UINT32, EFI_MEMORY_DESCRIPTOR *);
+
+typedef struct {
+       EFI_TABLE_HEADER                Hdr;
+       EFI_GET_TIME                    GetTime;
+       EFI_SET_TIME                    SetTime;
+       VOID                            *GetWakeupTime;
+       VOID                            *SetWakeupTime;
+
+       EFI_SET_VIRTUAL_ADDRESS_MAP     SetVirtualAddressMap;
+} EFI_RUNTIME_SERVICES;
+
+typedef struct {
+       EFI_GUID                        VendorGuid;
+       VOID                            *VendorTable;
+} EFI_CONFIGURATION_TABLE;
+
+typedef struct {
+       EFI_TABLE_HEADER                Hdr;
+       CHAR16                          *FirmwareVendor;
+       UINT32                          FirmwareRevision;
+       EFI_HANDLE                      ConsoleInHandle;
+       EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *ConIn;
+       EFI_HANDLE                      ConsoleOutHandle;
+       EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut;
+       EFI_HANDLE                      StandardErrorHandle;
+       EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *StdErr;
+       EFI_RUNTIME_SERVICES            *RuntimeServices;
+       EFI_BOOT_SERVICES               *BootServices;
+       UINTN                           NumberOfTableEntries;
+       EFI_CONFIGURATION_TABLE         *ConfigurationTable;
+} EFI_SYSTEM_TABLE;
+
+#define EFI_SUCCESS    0
+
+#define        efi_guidcmp(_a, _b)     memcmp((_a), (_b), sizeof(EFI_GUID))
+
+#endif /* _DEV_ACPI_EFI_H_ */