History log of /openbsd-current/sys/arch/arm64/conf/files.arm64
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.70 02-Jul-2024 kettenis

The traditional LL/SC atomics perform poorly on modern arm64 systems with
many CPU cores. With the recent conversion of the sched lock to a mutex
some systems appear to hang if the sched lock is contended. ARMv8.1
introduced an LSE feature that provides atomic instructions such as CAS
that perform much better. Unfortunately these can't be used on older
ARMv8.0 systems. Use -moutline-atomics to make the compiler generate
function calls for atomic operations and provide an implementation for
the functions we use in the kernel that use LSE when available and fall
back on LL/SC.

Fixes regressions seen on Ampere Altra and Apple M2 Pro/Max/Ultra since
the conversion of the sched lock to a mutex.

tested by claudio@, phessler@, mpi@
ok patrick@


# 1.69 25-Mar-2024 patrick

Add rpigpio(4), a driver for the RP1 GPIO controller on the Raspberry Pi 5.

With this, GPIOs can be correctly configured and engaged. Complete pinctrl
as well as IRQ functionality is yet to be implemented.

ok kettenis@


Revision tags: OPENBSD_7_5_BASE
# 1.68 01-Jan-2024 kettenis

Move fdt attachment into sys/conf/files.conf instead of duplicating it on
an MD basis.

ok patrick@


# 1.67 11-Dec-2023 claudio

Add ampchwm(4) a driver to access the Ampere Altra Fine-Grained Power Telemetry

This adds per core energy sensors (in Joules) and one per SoC temparature
sensor.
OK kettenis@ deraadt@


Revision tags: OPENBSD_7_3_BASE OPENBSD_7_4_BASE
# 1.66 14-Jan-2023 kettenis

Implement access to EFI variables and ESRT through an ioctl(2) interface
that is compatible with what FreeBSD and NetBSD have. Setting EFI
variables is only allowed at securelevel 0 and below.

Heavily based on work done by Sergii Dmytruk.

ok yasuoka@


# 1.65 17-Dec-2022 kettenis

Add aplefuse(4), a driver for the eFuses on Apple Silicon SoCs.

ok patrick@


# 1.64 21-Nov-2022 kettenis

Add aplpwm(4), a driver for the PWM controller found on Apple silicon.

ok tobhe@


# 1.63 08-Nov-2022 patrick

Tedu spmi bus definition that moved over to the fdt files.


# 1.62 06-Nov-2022 kettenis

Make EFI runtime calls more robust on arm64 as well. While I have not seen
any broken implementations yet, Linux developers claim that arm64 machines
intended to run Windows are not much better than x86 machines. And I
totally believe that.

ok patrick@


# 1.61 03-Oct-2022 kettenis

Reorganize the EFI code a bit. Move the efi.h header from dev/acpi to
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@


Revision tags: OPENBSD_7_2_BASE
# 1.60 03-Sep-2022 kettenis

Add apldcms(4), a driver for the touchpad on M2 laptops. This driver
needs firmware that is provided on the ESP by the Asahi installer and
copied into /etc/firmware/apple by the OpenBSD installer.

ok tobhe@


# 1.59 31-Aug-2022 kettenis

Add apldc(4), apldchidev(4), apldckdb(4) and aplrtkit(4). Together these
drivers implement support for the Dockchannel-base keyboard found on
Apple M2 laptops.

ok mlarkin@, patrick@


# 1.58 03-Aug-2022 kettenis

Add aplaudio(4) and aplmca(4). The aplmca(4) driver controls the hardware
block that takes data from apldma(4), serializes it and sends it out on
the i2s ports. The aplaudio(4) driver ties together aplmca(4) and various
codecs to present an audio(4) interface to the system.

This is still WIP, but good enough to play back audio on the speaker in the
M1 mini.

ok patrick@


# 1.57 12-Jun-2022 kettenis

The NVMe firmware distributed with the macOS 13 developer beta does not
like some of the shortcuts we've taken in the code that talks to RTKit.
In particular it does not like our NAK of the request for ioreport buffers.
So allocate the requested buffers and ACK the request instead.

However, the hardware implements a address filter between the coprocessor
that the firmware runs on and main memory. So we have to add a mapping
into this address filter such that the firmware can access these buffers.
Support for this address filter is implemented in a new aplsart(4) driver.

ok dlg@


Revision tags: OPENBSD_7_1_BASE
# 1.56 20-Feb-2022 kettenis

Add aplcpu(4), a driver to control the CPU performance levels on Apple SoCs.

ok gnezdo@


# 1.55 02-Feb-2022 kettenis

Add apldma(4), a driver for the DMA controller found on Apple SoCs.
This driver implements an interface for using DMA for audio output.

ok ratchov@


# 1.54 30-Jan-2022 kettenis

Add aplnco(4), a driver for the Numerically-controlled oscillator (NCO)
clock that drives the audio clocks on Apple silicon.

ok patrick@


# 1.53 10-Jan-2022 kettenis

Add aplsmc(4), a driver for the SMC found on Apple M1 SoCs.

The SMC implements a lot of functionality. For now the driver only
implements a bunch of sensors. This is a small subset of the sensors
that are made available by the SMC as we don't know what measurments
are provided for most sensors.

ok patrick@


# 1.52 08-Jan-2022 kettenis

Remove apldwusb(4). This driver is now unused.


# 1.51 01-Jan-2022 kettenis

Rewrite the kernel FPU handling code. The new code saves the FPU state
in cpu_switch() instead of at the kernel edge and gets rid of the FPU
state tracking in struct cpu_info and struct pcb. This fixes the random
crashes seen with SMP kernels on Apple M1.

ok patrick@


# 1.50 24-Dec-2021 patrick

Add apliic(4), a driver for the I2C controller found on various Apple SoCs.

ok kettenis@


# 1.49 19-Dec-2021 kettenis

Add an implementation for the protocol to communicate with coprocessors
running firmware based Apple's RTKit OS. Use this code to bring up the
storage controller that implements Apple's flavour of NVMe.

ok dlg@, patrick@


# 1.48 19-Dec-2021 kettenis

Enable aplmbox(4).


# 1.47 09-Dec-2021 kettenis

Add aplpmgr(4), a driver for the power management controller found on
various Apple SoCs.

ok patrick@


# 1.46 01-Nov-2021 kettenis

Add support for the keyboard/touchpad on Apple M1 laptops.

ok patrick@


# 1.45 31-Oct-2021 kettenis

Add aplspi(4), a driver for the SPI controller found on the Apple M1 SoC.

ok patrick@


Revision tags: OPENBSD_7_0_BASE
# 1.44 31-Aug-2021 kettenis

Add aplpinctrl(4), a driver for the Apple GPIO controller found on M1 SoCs.

ok patrick@


# 1.43 28-May-2021 dlg

start working on support for Apple NVME Storage as found in apple M1 devs

the Apple NVME Storage (aka ans) controller is almost but not quite
a vanilla nvme controller. one difference is that it doesnt attach
to a pci bus, so it needs this custom bus glue. this custom bus
glue also provides us with a nice way to provide a different set
of functions to handle other things that ans does differently to
vanilla nvme controllers.

this is different to how linux deals with ans. the linux support
fakes a pci controller for ans to attach to. i assumed that at some
point a vendor would include nvme in an soc directly and made it a
bus independent driver from day 1. turns out i was right, but i
would never have guessed that the vendor would be apple.

some of the other differences between vanilla nvme and ans are
around command submission and completion. ans nvme command submission
is done via an array of command slots where the host picks a slot
and then posts every slot number it fills in to a doorbell. this
is different to vanilla nvme controllers which use a ring, and post
the producer index in that ring to a doorbell. ans also includes
some weird iommu, the handling of which we wrap up into the command
submission and completion functions.

this code is not yet enabled because it is incomplete. i'm getting
what i've done in so people with actual hardware can start poking
it more seriously.

this implementation is based on information figured out by the guys
porting linux to apple hardware.


# 1.42 26-May-2021 kettenis

Add aplspmi(4), a driver for the Apple SPMI controller, and aplpmu(4)
a driver for the Apple "sera" SPMI power management unit that contains
the RTC on Apple M1 systems.

ok patrick@


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.69 25-Mar-2024 patrick

Add rpigpio(4), a driver for the RP1 GPIO controller on the Raspberry Pi 5.

With this, GPIOs can be correctly configured and engaged. Complete pinctrl
as well as IRQ functionality is yet to be implemented.

ok kettenis@


Revision tags: OPENBSD_7_5_BASE
# 1.68 01-Jan-2024 kettenis

Move fdt attachment into sys/conf/files.conf instead of duplicating it on
an MD basis.

ok patrick@


# 1.67 11-Dec-2023 claudio

Add ampchwm(4) a driver to access the Ampere Altra Fine-Grained Power Telemetry

This adds per core energy sensors (in Joules) and one per SoC temparature
sensor.
OK kettenis@ deraadt@


Revision tags: OPENBSD_7_3_BASE OPENBSD_7_4_BASE
# 1.66 14-Jan-2023 kettenis

Implement access to EFI variables and ESRT through an ioctl(2) interface
that is compatible with what FreeBSD and NetBSD have. Setting EFI
variables is only allowed at securelevel 0 and below.

Heavily based on work done by Sergii Dmytruk.

ok yasuoka@


# 1.65 17-Dec-2022 kettenis

Add aplefuse(4), a driver for the eFuses on Apple Silicon SoCs.

ok patrick@


# 1.64 21-Nov-2022 kettenis

Add aplpwm(4), a driver for the PWM controller found on Apple silicon.

ok tobhe@


# 1.63 08-Nov-2022 patrick

Tedu spmi bus definition that moved over to the fdt files.


# 1.62 06-Nov-2022 kettenis

Make EFI runtime calls more robust on arm64 as well. While I have not seen
any broken implementations yet, Linux developers claim that arm64 machines
intended to run Windows are not much better than x86 machines. And I
totally believe that.

ok patrick@


# 1.61 03-Oct-2022 kettenis

Reorganize the EFI code a bit. Move the efi.h header from dev/acpi to
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@


Revision tags: OPENBSD_7_2_BASE
# 1.60 03-Sep-2022 kettenis

Add apldcms(4), a driver for the touchpad on M2 laptops. This driver
needs firmware that is provided on the ESP by the Asahi installer and
copied into /etc/firmware/apple by the OpenBSD installer.

ok tobhe@


# 1.59 31-Aug-2022 kettenis

Add apldc(4), apldchidev(4), apldckdb(4) and aplrtkit(4). Together these
drivers implement support for the Dockchannel-base keyboard found on
Apple M2 laptops.

ok mlarkin@, patrick@


# 1.58 03-Aug-2022 kettenis

Add aplaudio(4) and aplmca(4). The aplmca(4) driver controls the hardware
block that takes data from apldma(4), serializes it and sends it out on
the i2s ports. The aplaudio(4) driver ties together aplmca(4) and various
codecs to present an audio(4) interface to the system.

This is still WIP, but good enough to play back audio on the speaker in the
M1 mini.

ok patrick@


# 1.57 12-Jun-2022 kettenis

The NVMe firmware distributed with the macOS 13 developer beta does not
like some of the shortcuts we've taken in the code that talks to RTKit.
In particular it does not like our NAK of the request for ioreport buffers.
So allocate the requested buffers and ACK the request instead.

However, the hardware implements a address filter between the coprocessor
that the firmware runs on and main memory. So we have to add a mapping
into this address filter such that the firmware can access these buffers.
Support for this address filter is implemented in a new aplsart(4) driver.

ok dlg@


Revision tags: OPENBSD_7_1_BASE
# 1.56 20-Feb-2022 kettenis

Add aplcpu(4), a driver to control the CPU performance levels on Apple SoCs.

ok gnezdo@


# 1.55 02-Feb-2022 kettenis

Add apldma(4), a driver for the DMA controller found on Apple SoCs.
This driver implements an interface for using DMA for audio output.

ok ratchov@


# 1.54 30-Jan-2022 kettenis

Add aplnco(4), a driver for the Numerically-controlled oscillator (NCO)
clock that drives the audio clocks on Apple silicon.

ok patrick@


# 1.53 10-Jan-2022 kettenis

Add aplsmc(4), a driver for the SMC found on Apple M1 SoCs.

The SMC implements a lot of functionality. For now the driver only
implements a bunch of sensors. This is a small subset of the sensors
that are made available by the SMC as we don't know what measurments
are provided for most sensors.

ok patrick@


# 1.52 08-Jan-2022 kettenis

Remove apldwusb(4). This driver is now unused.


# 1.51 01-Jan-2022 kettenis

Rewrite the kernel FPU handling code. The new code saves the FPU state
in cpu_switch() instead of at the kernel edge and gets rid of the FPU
state tracking in struct cpu_info and struct pcb. This fixes the random
crashes seen with SMP kernels on Apple M1.

ok patrick@


# 1.50 24-Dec-2021 patrick

Add apliic(4), a driver for the I2C controller found on various Apple SoCs.

ok kettenis@


# 1.49 19-Dec-2021 kettenis

Add an implementation for the protocol to communicate with coprocessors
running firmware based Apple's RTKit OS. Use this code to bring up the
storage controller that implements Apple's flavour of NVMe.

ok dlg@, patrick@


# 1.48 19-Dec-2021 kettenis

Enable aplmbox(4).


# 1.47 09-Dec-2021 kettenis

Add aplpmgr(4), a driver for the power management controller found on
various Apple SoCs.

ok patrick@


# 1.46 01-Nov-2021 kettenis

Add support for the keyboard/touchpad on Apple M1 laptops.

ok patrick@


# 1.45 31-Oct-2021 kettenis

Add aplspi(4), a driver for the SPI controller found on the Apple M1 SoC.

ok patrick@


Revision tags: OPENBSD_7_0_BASE
# 1.44 31-Aug-2021 kettenis

Add aplpinctrl(4), a driver for the Apple GPIO controller found on M1 SoCs.

ok patrick@


# 1.43 28-May-2021 dlg

start working on support for Apple NVME Storage as found in apple M1 devs

the Apple NVME Storage (aka ans) controller is almost but not quite
a vanilla nvme controller. one difference is that it doesnt attach
to a pci bus, so it needs this custom bus glue. this custom bus
glue also provides us with a nice way to provide a different set
of functions to handle other things that ans does differently to
vanilla nvme controllers.

this is different to how linux deals with ans. the linux support
fakes a pci controller for ans to attach to. i assumed that at some
point a vendor would include nvme in an soc directly and made it a
bus independent driver from day 1. turns out i was right, but i
would never have guessed that the vendor would be apple.

some of the other differences between vanilla nvme and ans are
around command submission and completion. ans nvme command submission
is done via an array of command slots where the host picks a slot
and then posts every slot number it fills in to a doorbell. this
is different to vanilla nvme controllers which use a ring, and post
the producer index in that ring to a doorbell. ans also includes
some weird iommu, the handling of which we wrap up into the command
submission and completion functions.

this code is not yet enabled because it is incomplete. i'm getting
what i've done in so people with actual hardware can start poking
it more seriously.

this implementation is based on information figured out by the guys
porting linux to apple hardware.


# 1.42 26-May-2021 kettenis

Add aplspmi(4), a driver for the Apple SPMI controller, and aplpmu(4)
a driver for the Apple "sera" SPMI power management unit that contains
the RTC on Apple M1 systems.

ok patrick@


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.68 01-Jan-2024 kettenis

Move fdt attachment into sys/conf/files.conf instead of duplicating it on
an MD basis.

ok patrick@


# 1.67 11-Dec-2023 claudio

Add ampchwm(4) a driver to access the Ampere Altra Fine-Grained Power Telemetry

This adds per core energy sensors (in Joules) and one per SoC temparature
sensor.
OK kettenis@ deraadt@


Revision tags: OPENBSD_7_3_BASE OPENBSD_7_4_BASE
# 1.66 14-Jan-2023 kettenis

Implement access to EFI variables and ESRT through an ioctl(2) interface
that is compatible with what FreeBSD and NetBSD have. Setting EFI
variables is only allowed at securelevel 0 and below.

Heavily based on work done by Sergii Dmytruk.

ok yasuoka@


# 1.65 17-Dec-2022 kettenis

Add aplefuse(4), a driver for the eFuses on Apple Silicon SoCs.

ok patrick@


# 1.64 21-Nov-2022 kettenis

Add aplpwm(4), a driver for the PWM controller found on Apple silicon.

ok tobhe@


# 1.63 08-Nov-2022 patrick

Tedu spmi bus definition that moved over to the fdt files.


# 1.62 06-Nov-2022 kettenis

Make EFI runtime calls more robust on arm64 as well. While I have not seen
any broken implementations yet, Linux developers claim that arm64 machines
intended to run Windows are not much better than x86 machines. And I
totally believe that.

ok patrick@


# 1.61 03-Oct-2022 kettenis

Reorganize the EFI code a bit. Move the efi.h header from dev/acpi to
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@


Revision tags: OPENBSD_7_2_BASE
# 1.60 03-Sep-2022 kettenis

Add apldcms(4), a driver for the touchpad on M2 laptops. This driver
needs firmware that is provided on the ESP by the Asahi installer and
copied into /etc/firmware/apple by the OpenBSD installer.

ok tobhe@


# 1.59 31-Aug-2022 kettenis

Add apldc(4), apldchidev(4), apldckdb(4) and aplrtkit(4). Together these
drivers implement support for the Dockchannel-base keyboard found on
Apple M2 laptops.

ok mlarkin@, patrick@


# 1.58 03-Aug-2022 kettenis

Add aplaudio(4) and aplmca(4). The aplmca(4) driver controls the hardware
block that takes data from apldma(4), serializes it and sends it out on
the i2s ports. The aplaudio(4) driver ties together aplmca(4) and various
codecs to present an audio(4) interface to the system.

This is still WIP, but good enough to play back audio on the speaker in the
M1 mini.

ok patrick@


# 1.57 12-Jun-2022 kettenis

The NVMe firmware distributed with the macOS 13 developer beta does not
like some of the shortcuts we've taken in the code that talks to RTKit.
In particular it does not like our NAK of the request for ioreport buffers.
So allocate the requested buffers and ACK the request instead.

However, the hardware implements a address filter between the coprocessor
that the firmware runs on and main memory. So we have to add a mapping
into this address filter such that the firmware can access these buffers.
Support for this address filter is implemented in a new aplsart(4) driver.

ok dlg@


Revision tags: OPENBSD_7_1_BASE
# 1.56 20-Feb-2022 kettenis

Add aplcpu(4), a driver to control the CPU performance levels on Apple SoCs.

ok gnezdo@


# 1.55 02-Feb-2022 kettenis

Add apldma(4), a driver for the DMA controller found on Apple SoCs.
This driver implements an interface for using DMA for audio output.

ok ratchov@


# 1.54 30-Jan-2022 kettenis

Add aplnco(4), a driver for the Numerically-controlled oscillator (NCO)
clock that drives the audio clocks on Apple silicon.

ok patrick@


# 1.53 10-Jan-2022 kettenis

Add aplsmc(4), a driver for the SMC found on Apple M1 SoCs.

The SMC implements a lot of functionality. For now the driver only
implements a bunch of sensors. This is a small subset of the sensors
that are made available by the SMC as we don't know what measurments
are provided for most sensors.

ok patrick@


# 1.52 08-Jan-2022 kettenis

Remove apldwusb(4). This driver is now unused.


# 1.51 01-Jan-2022 kettenis

Rewrite the kernel FPU handling code. The new code saves the FPU state
in cpu_switch() instead of at the kernel edge and gets rid of the FPU
state tracking in struct cpu_info and struct pcb. This fixes the random
crashes seen with SMP kernels on Apple M1.

ok patrick@


# 1.50 24-Dec-2021 patrick

Add apliic(4), a driver for the I2C controller found on various Apple SoCs.

ok kettenis@


# 1.49 19-Dec-2021 kettenis

Add an implementation for the protocol to communicate with coprocessors
running firmware based Apple's RTKit OS. Use this code to bring up the
storage controller that implements Apple's flavour of NVMe.

ok dlg@, patrick@


# 1.48 19-Dec-2021 kettenis

Enable aplmbox(4).


# 1.47 09-Dec-2021 kettenis

Add aplpmgr(4), a driver for the power management controller found on
various Apple SoCs.

ok patrick@


# 1.46 01-Nov-2021 kettenis

Add support for the keyboard/touchpad on Apple M1 laptops.

ok patrick@


# 1.45 31-Oct-2021 kettenis

Add aplspi(4), a driver for the SPI controller found on the Apple M1 SoC.

ok patrick@


Revision tags: OPENBSD_7_0_BASE
# 1.44 31-Aug-2021 kettenis

Add aplpinctrl(4), a driver for the Apple GPIO controller found on M1 SoCs.

ok patrick@


# 1.43 28-May-2021 dlg

start working on support for Apple NVME Storage as found in apple M1 devs

the Apple NVME Storage (aka ans) controller is almost but not quite
a vanilla nvme controller. one difference is that it doesnt attach
to a pci bus, so it needs this custom bus glue. this custom bus
glue also provides us with a nice way to provide a different set
of functions to handle other things that ans does differently to
vanilla nvme controllers.

this is different to how linux deals with ans. the linux support
fakes a pci controller for ans to attach to. i assumed that at some
point a vendor would include nvme in an soc directly and made it a
bus independent driver from day 1. turns out i was right, but i
would never have guessed that the vendor would be apple.

some of the other differences between vanilla nvme and ans are
around command submission and completion. ans nvme command submission
is done via an array of command slots where the host picks a slot
and then posts every slot number it fills in to a doorbell. this
is different to vanilla nvme controllers which use a ring, and post
the producer index in that ring to a doorbell. ans also includes
some weird iommu, the handling of which we wrap up into the command
submission and completion functions.

this code is not yet enabled because it is incomplete. i'm getting
what i've done in so people with actual hardware can start poking
it more seriously.

this implementation is based on information figured out by the guys
porting linux to apple hardware.


# 1.42 26-May-2021 kettenis

Add aplspmi(4), a driver for the Apple SPMI controller, and aplpmu(4)
a driver for the Apple "sera" SPMI power management unit that contains
the RTC on Apple M1 systems.

ok patrick@


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.67 11-Dec-2023 claudio

Add ampchwm(4) a driver to access the Ampere Altra Fine-Grained Power Telemetry

This adds per core energy sensors (in Joules) and one per SoC temparature
sensor.
OK kettenis@ deraadt@


Revision tags: OPENBSD_7_3_BASE OPENBSD_7_4_BASE
# 1.66 14-Jan-2023 kettenis

Implement access to EFI variables and ESRT through an ioctl(2) interface
that is compatible with what FreeBSD and NetBSD have. Setting EFI
variables is only allowed at securelevel 0 and below.

Heavily based on work done by Sergii Dmytruk.

ok yasuoka@


# 1.65 17-Dec-2022 kettenis

Add aplefuse(4), a driver for the eFuses on Apple Silicon SoCs.

ok patrick@


# 1.64 21-Nov-2022 kettenis

Add aplpwm(4), a driver for the PWM controller found on Apple silicon.

ok tobhe@


# 1.63 08-Nov-2022 patrick

Tedu spmi bus definition that moved over to the fdt files.


# 1.62 06-Nov-2022 kettenis

Make EFI runtime calls more robust on arm64 as well. While I have not seen
any broken implementations yet, Linux developers claim that arm64 machines
intended to run Windows are not much better than x86 machines. And I
totally believe that.

ok patrick@


# 1.61 03-Oct-2022 kettenis

Reorganize the EFI code a bit. Move the efi.h header from dev/acpi to
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@


Revision tags: OPENBSD_7_2_BASE
# 1.60 03-Sep-2022 kettenis

Add apldcms(4), a driver for the touchpad on M2 laptops. This driver
needs firmware that is provided on the ESP by the Asahi installer and
copied into /etc/firmware/apple by the OpenBSD installer.

ok tobhe@


# 1.59 31-Aug-2022 kettenis

Add apldc(4), apldchidev(4), apldckdb(4) and aplrtkit(4). Together these
drivers implement support for the Dockchannel-base keyboard found on
Apple M2 laptops.

ok mlarkin@, patrick@


# 1.58 03-Aug-2022 kettenis

Add aplaudio(4) and aplmca(4). The aplmca(4) driver controls the hardware
block that takes data from apldma(4), serializes it and sends it out on
the i2s ports. The aplaudio(4) driver ties together aplmca(4) and various
codecs to present an audio(4) interface to the system.

This is still WIP, but good enough to play back audio on the speaker in the
M1 mini.

ok patrick@


# 1.57 12-Jun-2022 kettenis

The NVMe firmware distributed with the macOS 13 developer beta does not
like some of the shortcuts we've taken in the code that talks to RTKit.
In particular it does not like our NAK of the request for ioreport buffers.
So allocate the requested buffers and ACK the request instead.

However, the hardware implements a address filter between the coprocessor
that the firmware runs on and main memory. So we have to add a mapping
into this address filter such that the firmware can access these buffers.
Support for this address filter is implemented in a new aplsart(4) driver.

ok dlg@


Revision tags: OPENBSD_7_1_BASE
# 1.56 20-Feb-2022 kettenis

Add aplcpu(4), a driver to control the CPU performance levels on Apple SoCs.

ok gnezdo@


# 1.55 02-Feb-2022 kettenis

Add apldma(4), a driver for the DMA controller found on Apple SoCs.
This driver implements an interface for using DMA for audio output.

ok ratchov@


# 1.54 30-Jan-2022 kettenis

Add aplnco(4), a driver for the Numerically-controlled oscillator (NCO)
clock that drives the audio clocks on Apple silicon.

ok patrick@


# 1.53 10-Jan-2022 kettenis

Add aplsmc(4), a driver for the SMC found on Apple M1 SoCs.

The SMC implements a lot of functionality. For now the driver only
implements a bunch of sensors. This is a small subset of the sensors
that are made available by the SMC as we don't know what measurments
are provided for most sensors.

ok patrick@


# 1.52 08-Jan-2022 kettenis

Remove apldwusb(4). This driver is now unused.


# 1.51 01-Jan-2022 kettenis

Rewrite the kernel FPU handling code. The new code saves the FPU state
in cpu_switch() instead of at the kernel edge and gets rid of the FPU
state tracking in struct cpu_info and struct pcb. This fixes the random
crashes seen with SMP kernels on Apple M1.

ok patrick@


# 1.50 24-Dec-2021 patrick

Add apliic(4), a driver for the I2C controller found on various Apple SoCs.

ok kettenis@


# 1.49 19-Dec-2021 kettenis

Add an implementation for the protocol to communicate with coprocessors
running firmware based Apple's RTKit OS. Use this code to bring up the
storage controller that implements Apple's flavour of NVMe.

ok dlg@, patrick@


# 1.48 19-Dec-2021 kettenis

Enable aplmbox(4).


# 1.47 09-Dec-2021 kettenis

Add aplpmgr(4), a driver for the power management controller found on
various Apple SoCs.

ok patrick@


# 1.46 01-Nov-2021 kettenis

Add support for the keyboard/touchpad on Apple M1 laptops.

ok patrick@


# 1.45 31-Oct-2021 kettenis

Add aplspi(4), a driver for the SPI controller found on the Apple M1 SoC.

ok patrick@


Revision tags: OPENBSD_7_0_BASE
# 1.44 31-Aug-2021 kettenis

Add aplpinctrl(4), a driver for the Apple GPIO controller found on M1 SoCs.

ok patrick@


# 1.43 28-May-2021 dlg

start working on support for Apple NVME Storage as found in apple M1 devs

the Apple NVME Storage (aka ans) controller is almost but not quite
a vanilla nvme controller. one difference is that it doesnt attach
to a pci bus, so it needs this custom bus glue. this custom bus
glue also provides us with a nice way to provide a different set
of functions to handle other things that ans does differently to
vanilla nvme controllers.

this is different to how linux deals with ans. the linux support
fakes a pci controller for ans to attach to. i assumed that at some
point a vendor would include nvme in an soc directly and made it a
bus independent driver from day 1. turns out i was right, but i
would never have guessed that the vendor would be apple.

some of the other differences between vanilla nvme and ans are
around command submission and completion. ans nvme command submission
is done via an array of command slots where the host picks a slot
and then posts every slot number it fills in to a doorbell. this
is different to vanilla nvme controllers which use a ring, and post
the producer index in that ring to a doorbell. ans also includes
some weird iommu, the handling of which we wrap up into the command
submission and completion functions.

this code is not yet enabled because it is incomplete. i'm getting
what i've done in so people with actual hardware can start poking
it more seriously.

this implementation is based on information figured out by the guys
porting linux to apple hardware.


# 1.42 26-May-2021 kettenis

Add aplspmi(4), a driver for the Apple SPMI controller, and aplpmu(4)
a driver for the Apple "sera" SPMI power management unit that contains
the RTC on Apple M1 systems.

ok patrick@


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.66 14-Jan-2023 kettenis

Implement access to EFI variables and ESRT through an ioctl(2) interface
that is compatible with what FreeBSD and NetBSD have. Setting EFI
variables is only allowed at securelevel 0 and below.

Heavily based on work done by Sergii Dmytruk.

ok yasuoka@


# 1.65 17-Dec-2022 kettenis

Add aplefuse(4), a driver for the eFuses on Apple Silicon SoCs.

ok patrick@


# 1.64 21-Nov-2022 kettenis

Add aplpwm(4), a driver for the PWM controller found on Apple silicon.

ok tobhe@


# 1.63 08-Nov-2022 patrick

Tedu spmi bus definition that moved over to the fdt files.


# 1.62 06-Nov-2022 kettenis

Make EFI runtime calls more robust on arm64 as well. While I have not seen
any broken implementations yet, Linux developers claim that arm64 machines
intended to run Windows are not much better than x86 machines. And I
totally believe that.

ok patrick@


# 1.61 03-Oct-2022 kettenis

Reorganize the EFI code a bit. Move the efi.h header from dev/acpi to
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@


Revision tags: OPENBSD_7_2_BASE
# 1.60 03-Sep-2022 kettenis

Add apldcms(4), a driver for the touchpad on M2 laptops. This driver
needs firmware that is provided on the ESP by the Asahi installer and
copied into /etc/firmware/apple by the OpenBSD installer.

ok tobhe@


# 1.59 31-Aug-2022 kettenis

Add apldc(4), apldchidev(4), apldckdb(4) and aplrtkit(4). Together these
drivers implement support for the Dockchannel-base keyboard found on
Apple M2 laptops.

ok mlarkin@, patrick@


# 1.58 03-Aug-2022 kettenis

Add aplaudio(4) and aplmca(4). The aplmca(4) driver controls the hardware
block that takes data from apldma(4), serializes it and sends it out on
the i2s ports. The aplaudio(4) driver ties together aplmca(4) and various
codecs to present an audio(4) interface to the system.

This is still WIP, but good enough to play back audio on the speaker in the
M1 mini.

ok patrick@


# 1.57 12-Jun-2022 kettenis

The NVMe firmware distributed with the macOS 13 developer beta does not
like some of the shortcuts we've taken in the code that talks to RTKit.
In particular it does not like our NAK of the request for ioreport buffers.
So allocate the requested buffers and ACK the request instead.

However, the hardware implements a address filter between the coprocessor
that the firmware runs on and main memory. So we have to add a mapping
into this address filter such that the firmware can access these buffers.
Support for this address filter is implemented in a new aplsart(4) driver.

ok dlg@


Revision tags: OPENBSD_7_1_BASE
# 1.56 20-Feb-2022 kettenis

Add aplcpu(4), a driver to control the CPU performance levels on Apple SoCs.

ok gnezdo@


# 1.55 02-Feb-2022 kettenis

Add apldma(4), a driver for the DMA controller found on Apple SoCs.
This driver implements an interface for using DMA for audio output.

ok ratchov@


# 1.54 30-Jan-2022 kettenis

Add aplnco(4), a driver for the Numerically-controlled oscillator (NCO)
clock that drives the audio clocks on Apple silicon.

ok patrick@


# 1.53 10-Jan-2022 kettenis

Add aplsmc(4), a driver for the SMC found on Apple M1 SoCs.

The SMC implements a lot of functionality. For now the driver only
implements a bunch of sensors. This is a small subset of the sensors
that are made available by the SMC as we don't know what measurments
are provided for most sensors.

ok patrick@


# 1.52 08-Jan-2022 kettenis

Remove apldwusb(4). This driver is now unused.


# 1.51 01-Jan-2022 kettenis

Rewrite the kernel FPU handling code. The new code saves the FPU state
in cpu_switch() instead of at the kernel edge and gets rid of the FPU
state tracking in struct cpu_info and struct pcb. This fixes the random
crashes seen with SMP kernels on Apple M1.

ok patrick@


# 1.50 24-Dec-2021 patrick

Add apliic(4), a driver for the I2C controller found on various Apple SoCs.

ok kettenis@


# 1.49 19-Dec-2021 kettenis

Add an implementation for the protocol to communicate with coprocessors
running firmware based Apple's RTKit OS. Use this code to bring up the
storage controller that implements Apple's flavour of NVMe.

ok dlg@, patrick@


# 1.48 19-Dec-2021 kettenis

Enable aplmbox(4).


# 1.47 09-Dec-2021 kettenis

Add aplpmgr(4), a driver for the power management controller found on
various Apple SoCs.

ok patrick@


# 1.46 01-Nov-2021 kettenis

Add support for the keyboard/touchpad on Apple M1 laptops.

ok patrick@


# 1.45 31-Oct-2021 kettenis

Add aplspi(4), a driver for the SPI controller found on the Apple M1 SoC.

ok patrick@


Revision tags: OPENBSD_7_0_BASE
# 1.44 31-Aug-2021 kettenis

Add aplpinctrl(4), a driver for the Apple GPIO controller found on M1 SoCs.

ok patrick@


# 1.43 28-May-2021 dlg

start working on support for Apple NVME Storage as found in apple M1 devs

the Apple NVME Storage (aka ans) controller is almost but not quite
a vanilla nvme controller. one difference is that it doesnt attach
to a pci bus, so it needs this custom bus glue. this custom bus
glue also provides us with a nice way to provide a different set
of functions to handle other things that ans does differently to
vanilla nvme controllers.

this is different to how linux deals with ans. the linux support
fakes a pci controller for ans to attach to. i assumed that at some
point a vendor would include nvme in an soc directly and made it a
bus independent driver from day 1. turns out i was right, but i
would never have guessed that the vendor would be apple.

some of the other differences between vanilla nvme and ans are
around command submission and completion. ans nvme command submission
is done via an array of command slots where the host picks a slot
and then posts every slot number it fills in to a doorbell. this
is different to vanilla nvme controllers which use a ring, and post
the producer index in that ring to a doorbell. ans also includes
some weird iommu, the handling of which we wrap up into the command
submission and completion functions.

this code is not yet enabled because it is incomplete. i'm getting
what i've done in so people with actual hardware can start poking
it more seriously.

this implementation is based on information figured out by the guys
porting linux to apple hardware.


# 1.42 26-May-2021 kettenis

Add aplspmi(4), a driver for the Apple SPMI controller, and aplpmu(4)
a driver for the Apple "sera" SPMI power management unit that contains
the RTC on Apple M1 systems.

ok patrick@


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.65 17-Dec-2022 kettenis

Add aplefuse(4), a driver for the eFuses on Apple Silicon SoCs.

ok patrick@


# 1.64 21-Nov-2022 kettenis

Add aplpwm(4), a driver for the PWM controller found on Apple silicon.

ok tobhe@


# 1.63 08-Nov-2022 patrick

Tedu spmi bus definition that moved over to the fdt files.


# 1.62 06-Nov-2022 kettenis

Make EFI runtime calls more robust on arm64 as well. While I have not seen
any broken implementations yet, Linux developers claim that arm64 machines
intended to run Windows are not much better than x86 machines. And I
totally believe that.

ok patrick@


# 1.61 03-Oct-2022 kettenis

Reorganize the EFI code a bit. Move the efi.h header from dev/acpi to
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@


Revision tags: OPENBSD_7_2_BASE
# 1.60 03-Sep-2022 kettenis

Add apldcms(4), a driver for the touchpad on M2 laptops. This driver
needs firmware that is provided on the ESP by the Asahi installer and
copied into /etc/firmware/apple by the OpenBSD installer.

ok tobhe@


# 1.59 31-Aug-2022 kettenis

Add apldc(4), apldchidev(4), apldckdb(4) and aplrtkit(4). Together these
drivers implement support for the Dockchannel-base keyboard found on
Apple M2 laptops.

ok mlarkin@, patrick@


# 1.58 03-Aug-2022 kettenis

Add aplaudio(4) and aplmca(4). The aplmca(4) driver controls the hardware
block that takes data from apldma(4), serializes it and sends it out on
the i2s ports. The aplaudio(4) driver ties together aplmca(4) and various
codecs to present an audio(4) interface to the system.

This is still WIP, but good enough to play back audio on the speaker in the
M1 mini.

ok patrick@


# 1.57 12-Jun-2022 kettenis

The NVMe firmware distributed with the macOS 13 developer beta does not
like some of the shortcuts we've taken in the code that talks to RTKit.
In particular it does not like our NAK of the request for ioreport buffers.
So allocate the requested buffers and ACK the request instead.

However, the hardware implements a address filter between the coprocessor
that the firmware runs on and main memory. So we have to add a mapping
into this address filter such that the firmware can access these buffers.
Support for this address filter is implemented in a new aplsart(4) driver.

ok dlg@


Revision tags: OPENBSD_7_1_BASE
# 1.56 20-Feb-2022 kettenis

Add aplcpu(4), a driver to control the CPU performance levels on Apple SoCs.

ok gnezdo@


# 1.55 02-Feb-2022 kettenis

Add apldma(4), a driver for the DMA controller found on Apple SoCs.
This driver implements an interface for using DMA for audio output.

ok ratchov@


# 1.54 30-Jan-2022 kettenis

Add aplnco(4), a driver for the Numerically-controlled oscillator (NCO)
clock that drives the audio clocks on Apple silicon.

ok patrick@


# 1.53 10-Jan-2022 kettenis

Add aplsmc(4), a driver for the SMC found on Apple M1 SoCs.

The SMC implements a lot of functionality. For now the driver only
implements a bunch of sensors. This is a small subset of the sensors
that are made available by the SMC as we don't know what measurments
are provided for most sensors.

ok patrick@


# 1.52 08-Jan-2022 kettenis

Remove apldwusb(4). This driver is now unused.


# 1.51 01-Jan-2022 kettenis

Rewrite the kernel FPU handling code. The new code saves the FPU state
in cpu_switch() instead of at the kernel edge and gets rid of the FPU
state tracking in struct cpu_info and struct pcb. This fixes the random
crashes seen with SMP kernels on Apple M1.

ok patrick@


# 1.50 24-Dec-2021 patrick

Add apliic(4), a driver for the I2C controller found on various Apple SoCs.

ok kettenis@


# 1.49 19-Dec-2021 kettenis

Add an implementation for the protocol to communicate with coprocessors
running firmware based Apple's RTKit OS. Use this code to bring up the
storage controller that implements Apple's flavour of NVMe.

ok dlg@, patrick@


# 1.48 19-Dec-2021 kettenis

Enable aplmbox(4).


# 1.47 09-Dec-2021 kettenis

Add aplpmgr(4), a driver for the power management controller found on
various Apple SoCs.

ok patrick@


# 1.46 01-Nov-2021 kettenis

Add support for the keyboard/touchpad on Apple M1 laptops.

ok patrick@


# 1.45 31-Oct-2021 kettenis

Add aplspi(4), a driver for the SPI controller found on the Apple M1 SoC.

ok patrick@


Revision tags: OPENBSD_7_0_BASE
# 1.44 31-Aug-2021 kettenis

Add aplpinctrl(4), a driver for the Apple GPIO controller found on M1 SoCs.

ok patrick@


# 1.43 28-May-2021 dlg

start working on support for Apple NVME Storage as found in apple M1 devs

the Apple NVME Storage (aka ans) controller is almost but not quite
a vanilla nvme controller. one difference is that it doesnt attach
to a pci bus, so it needs this custom bus glue. this custom bus
glue also provides us with a nice way to provide a different set
of functions to handle other things that ans does differently to
vanilla nvme controllers.

this is different to how linux deals with ans. the linux support
fakes a pci controller for ans to attach to. i assumed that at some
point a vendor would include nvme in an soc directly and made it a
bus independent driver from day 1. turns out i was right, but i
would never have guessed that the vendor would be apple.

some of the other differences between vanilla nvme and ans are
around command submission and completion. ans nvme command submission
is done via an array of command slots where the host picks a slot
and then posts every slot number it fills in to a doorbell. this
is different to vanilla nvme controllers which use a ring, and post
the producer index in that ring to a doorbell. ans also includes
some weird iommu, the handling of which we wrap up into the command
submission and completion functions.

this code is not yet enabled because it is incomplete. i'm getting
what i've done in so people with actual hardware can start poking
it more seriously.

this implementation is based on information figured out by the guys
porting linux to apple hardware.


# 1.42 26-May-2021 kettenis

Add aplspmi(4), a driver for the Apple SPMI controller, and aplpmu(4)
a driver for the Apple "sera" SPMI power management unit that contains
the RTC on Apple M1 systems.

ok patrick@


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.64 21-Nov-2022 kettenis

Add aplpwm(4), a driver for the PWM controller found on Apple silicon.

ok tobhe@


# 1.63 08-Nov-2022 patrick

Tedu spmi bus definition that moved over to the fdt files.


# 1.62 06-Nov-2022 kettenis

Make EFI runtime calls more robust on arm64 as well. While I have not seen
any broken implementations yet, Linux developers claim that arm64 machines
intended to run Windows are not much better than x86 machines. And I
totally believe that.

ok patrick@


# 1.61 03-Oct-2022 kettenis

Reorganize the EFI code a bit. Move the efi.h header from dev/acpi to
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@


Revision tags: OPENBSD_7_2_BASE
# 1.60 03-Sep-2022 kettenis

Add apldcms(4), a driver for the touchpad on M2 laptops. This driver
needs firmware that is provided on the ESP by the Asahi installer and
copied into /etc/firmware/apple by the OpenBSD installer.

ok tobhe@


# 1.59 31-Aug-2022 kettenis

Add apldc(4), apldchidev(4), apldckdb(4) and aplrtkit(4). Together these
drivers implement support for the Dockchannel-base keyboard found on
Apple M2 laptops.

ok mlarkin@, patrick@


# 1.58 03-Aug-2022 kettenis

Add aplaudio(4) and aplmca(4). The aplmca(4) driver controls the hardware
block that takes data from apldma(4), serializes it and sends it out on
the i2s ports. The aplaudio(4) driver ties together aplmca(4) and various
codecs to present an audio(4) interface to the system.

This is still WIP, but good enough to play back audio on the speaker in the
M1 mini.

ok patrick@


# 1.57 12-Jun-2022 kettenis

The NVMe firmware distributed with the macOS 13 developer beta does not
like some of the shortcuts we've taken in the code that talks to RTKit.
In particular it does not like our NAK of the request for ioreport buffers.
So allocate the requested buffers and ACK the request instead.

However, the hardware implements a address filter between the coprocessor
that the firmware runs on and main memory. So we have to add a mapping
into this address filter such that the firmware can access these buffers.
Support for this address filter is implemented in a new aplsart(4) driver.

ok dlg@


Revision tags: OPENBSD_7_1_BASE
# 1.56 20-Feb-2022 kettenis

Add aplcpu(4), a driver to control the CPU performance levels on Apple SoCs.

ok gnezdo@


# 1.55 02-Feb-2022 kettenis

Add apldma(4), a driver for the DMA controller found on Apple SoCs.
This driver implements an interface for using DMA for audio output.

ok ratchov@


# 1.54 30-Jan-2022 kettenis

Add aplnco(4), a driver for the Numerically-controlled oscillator (NCO)
clock that drives the audio clocks on Apple silicon.

ok patrick@


# 1.53 10-Jan-2022 kettenis

Add aplsmc(4), a driver for the SMC found on Apple M1 SoCs.

The SMC implements a lot of functionality. For now the driver only
implements a bunch of sensors. This is a small subset of the sensors
that are made available by the SMC as we don't know what measurments
are provided for most sensors.

ok patrick@


# 1.52 08-Jan-2022 kettenis

Remove apldwusb(4). This driver is now unused.


# 1.51 01-Jan-2022 kettenis

Rewrite the kernel FPU handling code. The new code saves the FPU state
in cpu_switch() instead of at the kernel edge and gets rid of the FPU
state tracking in struct cpu_info and struct pcb. This fixes the random
crashes seen with SMP kernels on Apple M1.

ok patrick@


# 1.50 24-Dec-2021 patrick

Add apliic(4), a driver for the I2C controller found on various Apple SoCs.

ok kettenis@


# 1.49 19-Dec-2021 kettenis

Add an implementation for the protocol to communicate with coprocessors
running firmware based Apple's RTKit OS. Use this code to bring up the
storage controller that implements Apple's flavour of NVMe.

ok dlg@, patrick@


# 1.48 19-Dec-2021 kettenis

Enable aplmbox(4).


# 1.47 09-Dec-2021 kettenis

Add aplpmgr(4), a driver for the power management controller found on
various Apple SoCs.

ok patrick@


# 1.46 01-Nov-2021 kettenis

Add support for the keyboard/touchpad on Apple M1 laptops.

ok patrick@


# 1.45 31-Oct-2021 kettenis

Add aplspi(4), a driver for the SPI controller found on the Apple M1 SoC.

ok patrick@


Revision tags: OPENBSD_7_0_BASE
# 1.44 31-Aug-2021 kettenis

Add aplpinctrl(4), a driver for the Apple GPIO controller found on M1 SoCs.

ok patrick@


# 1.43 28-May-2021 dlg

start working on support for Apple NVME Storage as found in apple M1 devs

the Apple NVME Storage (aka ans) controller is almost but not quite
a vanilla nvme controller. one difference is that it doesnt attach
to a pci bus, so it needs this custom bus glue. this custom bus
glue also provides us with a nice way to provide a different set
of functions to handle other things that ans does differently to
vanilla nvme controllers.

this is different to how linux deals with ans. the linux support
fakes a pci controller for ans to attach to. i assumed that at some
point a vendor would include nvme in an soc directly and made it a
bus independent driver from day 1. turns out i was right, but i
would never have guessed that the vendor would be apple.

some of the other differences between vanilla nvme and ans are
around command submission and completion. ans nvme command submission
is done via an array of command slots where the host picks a slot
and then posts every slot number it fills in to a doorbell. this
is different to vanilla nvme controllers which use a ring, and post
the producer index in that ring to a doorbell. ans also includes
some weird iommu, the handling of which we wrap up into the command
submission and completion functions.

this code is not yet enabled because it is incomplete. i'm getting
what i've done in so people with actual hardware can start poking
it more seriously.

this implementation is based on information figured out by the guys
porting linux to apple hardware.


# 1.42 26-May-2021 kettenis

Add aplspmi(4), a driver for the Apple SPMI controller, and aplpmu(4)
a driver for the Apple "sera" SPMI power management unit that contains
the RTC on Apple M1 systems.

ok patrick@


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.63 08-Nov-2022 patrick

Tedu spmi bus definition that moved over to the fdt files.


# 1.62 06-Nov-2022 kettenis

Make EFI runtime calls more robust on arm64 as well. While I have not seen
any broken implementations yet, Linux developers claim that arm64 machines
intended to run Windows are not much better than x86 machines. And I
totally believe that.

ok patrick@


# 1.61 03-Oct-2022 kettenis

Reorganize the EFI code a bit. Move the efi.h header from dev/acpi to
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@


Revision tags: OPENBSD_7_2_BASE
# 1.60 03-Sep-2022 kettenis

Add apldcms(4), a driver for the touchpad on M2 laptops. This driver
needs firmware that is provided on the ESP by the Asahi installer and
copied into /etc/firmware/apple by the OpenBSD installer.

ok tobhe@


# 1.59 31-Aug-2022 kettenis

Add apldc(4), apldchidev(4), apldckdb(4) and aplrtkit(4). Together these
drivers implement support for the Dockchannel-base keyboard found on
Apple M2 laptops.

ok mlarkin@, patrick@


# 1.58 03-Aug-2022 kettenis

Add aplaudio(4) and aplmca(4). The aplmca(4) driver controls the hardware
block that takes data from apldma(4), serializes it and sends it out on
the i2s ports. The aplaudio(4) driver ties together aplmca(4) and various
codecs to present an audio(4) interface to the system.

This is still WIP, but good enough to play back audio on the speaker in the
M1 mini.

ok patrick@


# 1.57 12-Jun-2022 kettenis

The NVMe firmware distributed with the macOS 13 developer beta does not
like some of the shortcuts we've taken in the code that talks to RTKit.
In particular it does not like our NAK of the request for ioreport buffers.
So allocate the requested buffers and ACK the request instead.

However, the hardware implements a address filter between the coprocessor
that the firmware runs on and main memory. So we have to add a mapping
into this address filter such that the firmware can access these buffers.
Support for this address filter is implemented in a new aplsart(4) driver.

ok dlg@


Revision tags: OPENBSD_7_1_BASE
# 1.56 20-Feb-2022 kettenis

Add aplcpu(4), a driver to control the CPU performance levels on Apple SoCs.

ok gnezdo@


# 1.55 02-Feb-2022 kettenis

Add apldma(4), a driver for the DMA controller found on Apple SoCs.
This driver implements an interface for using DMA for audio output.

ok ratchov@


# 1.54 30-Jan-2022 kettenis

Add aplnco(4), a driver for the Numerically-controlled oscillator (NCO)
clock that drives the audio clocks on Apple silicon.

ok patrick@


# 1.53 10-Jan-2022 kettenis

Add aplsmc(4), a driver for the SMC found on Apple M1 SoCs.

The SMC implements a lot of functionality. For now the driver only
implements a bunch of sensors. This is a small subset of the sensors
that are made available by the SMC as we don't know what measurments
are provided for most sensors.

ok patrick@


# 1.52 08-Jan-2022 kettenis

Remove apldwusb(4). This driver is now unused.


# 1.51 01-Jan-2022 kettenis

Rewrite the kernel FPU handling code. The new code saves the FPU state
in cpu_switch() instead of at the kernel edge and gets rid of the FPU
state tracking in struct cpu_info and struct pcb. This fixes the random
crashes seen with SMP kernels on Apple M1.

ok patrick@


# 1.50 24-Dec-2021 patrick

Add apliic(4), a driver for the I2C controller found on various Apple SoCs.

ok kettenis@


# 1.49 19-Dec-2021 kettenis

Add an implementation for the protocol to communicate with coprocessors
running firmware based Apple's RTKit OS. Use this code to bring up the
storage controller that implements Apple's flavour of NVMe.

ok dlg@, patrick@


# 1.48 19-Dec-2021 kettenis

Enable aplmbox(4).


# 1.47 09-Dec-2021 kettenis

Add aplpmgr(4), a driver for the power management controller found on
various Apple SoCs.

ok patrick@


# 1.46 01-Nov-2021 kettenis

Add support for the keyboard/touchpad on Apple M1 laptops.

ok patrick@


# 1.45 31-Oct-2021 kettenis

Add aplspi(4), a driver for the SPI controller found on the Apple M1 SoC.

ok patrick@


Revision tags: OPENBSD_7_0_BASE
# 1.44 31-Aug-2021 kettenis

Add aplpinctrl(4), a driver for the Apple GPIO controller found on M1 SoCs.

ok patrick@


# 1.43 28-May-2021 dlg

start working on support for Apple NVME Storage as found in apple M1 devs

the Apple NVME Storage (aka ans) controller is almost but not quite
a vanilla nvme controller. one difference is that it doesnt attach
to a pci bus, so it needs this custom bus glue. this custom bus
glue also provides us with a nice way to provide a different set
of functions to handle other things that ans does differently to
vanilla nvme controllers.

this is different to how linux deals with ans. the linux support
fakes a pci controller for ans to attach to. i assumed that at some
point a vendor would include nvme in an soc directly and made it a
bus independent driver from day 1. turns out i was right, but i
would never have guessed that the vendor would be apple.

some of the other differences between vanilla nvme and ans are
around command submission and completion. ans nvme command submission
is done via an array of command slots where the host picks a slot
and then posts every slot number it fills in to a doorbell. this
is different to vanilla nvme controllers which use a ring, and post
the producer index in that ring to a doorbell. ans also includes
some weird iommu, the handling of which we wrap up into the command
submission and completion functions.

this code is not yet enabled because it is incomplete. i'm getting
what i've done in so people with actual hardware can start poking
it more seriously.

this implementation is based on information figured out by the guys
porting linux to apple hardware.


# 1.42 26-May-2021 kettenis

Add aplspmi(4), a driver for the Apple SPMI controller, and aplpmu(4)
a driver for the Apple "sera" SPMI power management unit that contains
the RTC on Apple M1 systems.

ok patrick@


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.62 06-Nov-2022 kettenis

Make EFI runtime calls more robust on arm64 as well. While I have not seen
any broken implementations yet, Linux developers claim that arm64 machines
intended to run Windows are not much better than x86 machines. And I
totally believe that.

ok patrick@


# 1.61 03-Oct-2022 kettenis

Reorganize the EFI code a bit. Move the efi.h header from dev/acpi to
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@


Revision tags: OPENBSD_7_2_BASE
# 1.60 03-Sep-2022 kettenis

Add apldcms(4), a driver for the touchpad on M2 laptops. This driver
needs firmware that is provided on the ESP by the Asahi installer and
copied into /etc/firmware/apple by the OpenBSD installer.

ok tobhe@


# 1.59 31-Aug-2022 kettenis

Add apldc(4), apldchidev(4), apldckdb(4) and aplrtkit(4). Together these
drivers implement support for the Dockchannel-base keyboard found on
Apple M2 laptops.

ok mlarkin@, patrick@


# 1.58 03-Aug-2022 kettenis

Add aplaudio(4) and aplmca(4). The aplmca(4) driver controls the hardware
block that takes data from apldma(4), serializes it and sends it out on
the i2s ports. The aplaudio(4) driver ties together aplmca(4) and various
codecs to present an audio(4) interface to the system.

This is still WIP, but good enough to play back audio on the speaker in the
M1 mini.

ok patrick@


# 1.57 12-Jun-2022 kettenis

The NVMe firmware distributed with the macOS 13 developer beta does not
like some of the shortcuts we've taken in the code that talks to RTKit.
In particular it does not like our NAK of the request for ioreport buffers.
So allocate the requested buffers and ACK the request instead.

However, the hardware implements a address filter between the coprocessor
that the firmware runs on and main memory. So we have to add a mapping
into this address filter such that the firmware can access these buffers.
Support for this address filter is implemented in a new aplsart(4) driver.

ok dlg@


Revision tags: OPENBSD_7_1_BASE
# 1.56 20-Feb-2022 kettenis

Add aplcpu(4), a driver to control the CPU performance levels on Apple SoCs.

ok gnezdo@


# 1.55 02-Feb-2022 kettenis

Add apldma(4), a driver for the DMA controller found on Apple SoCs.
This driver implements an interface for using DMA for audio output.

ok ratchov@


# 1.54 30-Jan-2022 kettenis

Add aplnco(4), a driver for the Numerically-controlled oscillator (NCO)
clock that drives the audio clocks on Apple silicon.

ok patrick@


# 1.53 10-Jan-2022 kettenis

Add aplsmc(4), a driver for the SMC found on Apple M1 SoCs.

The SMC implements a lot of functionality. For now the driver only
implements a bunch of sensors. This is a small subset of the sensors
that are made available by the SMC as we don't know what measurments
are provided for most sensors.

ok patrick@


# 1.52 08-Jan-2022 kettenis

Remove apldwusb(4). This driver is now unused.


# 1.51 01-Jan-2022 kettenis

Rewrite the kernel FPU handling code. The new code saves the FPU state
in cpu_switch() instead of at the kernel edge and gets rid of the FPU
state tracking in struct cpu_info and struct pcb. This fixes the random
crashes seen with SMP kernels on Apple M1.

ok patrick@


# 1.50 24-Dec-2021 patrick

Add apliic(4), a driver for the I2C controller found on various Apple SoCs.

ok kettenis@


# 1.49 19-Dec-2021 kettenis

Add an implementation for the protocol to communicate with coprocessors
running firmware based Apple's RTKit OS. Use this code to bring up the
storage controller that implements Apple's flavour of NVMe.

ok dlg@, patrick@


# 1.48 19-Dec-2021 kettenis

Enable aplmbox(4).


# 1.47 09-Dec-2021 kettenis

Add aplpmgr(4), a driver for the power management controller found on
various Apple SoCs.

ok patrick@


# 1.46 01-Nov-2021 kettenis

Add support for the keyboard/touchpad on Apple M1 laptops.

ok patrick@


# 1.45 31-Oct-2021 kettenis

Add aplspi(4), a driver for the SPI controller found on the Apple M1 SoC.

ok patrick@


Revision tags: OPENBSD_7_0_BASE
# 1.44 31-Aug-2021 kettenis

Add aplpinctrl(4), a driver for the Apple GPIO controller found on M1 SoCs.

ok patrick@


# 1.43 28-May-2021 dlg

start working on support for Apple NVME Storage as found in apple M1 devs

the Apple NVME Storage (aka ans) controller is almost but not quite
a vanilla nvme controller. one difference is that it doesnt attach
to a pci bus, so it needs this custom bus glue. this custom bus
glue also provides us with a nice way to provide a different set
of functions to handle other things that ans does differently to
vanilla nvme controllers.

this is different to how linux deals with ans. the linux support
fakes a pci controller for ans to attach to. i assumed that at some
point a vendor would include nvme in an soc directly and made it a
bus independent driver from day 1. turns out i was right, but i
would never have guessed that the vendor would be apple.

some of the other differences between vanilla nvme and ans are
around command submission and completion. ans nvme command submission
is done via an array of command slots where the host picks a slot
and then posts every slot number it fills in to a doorbell. this
is different to vanilla nvme controllers which use a ring, and post
the producer index in that ring to a doorbell. ans also includes
some weird iommu, the handling of which we wrap up into the command
submission and completion functions.

this code is not yet enabled because it is incomplete. i'm getting
what i've done in so people with actual hardware can start poking
it more seriously.

this implementation is based on information figured out by the guys
porting linux to apple hardware.


# 1.42 26-May-2021 kettenis

Add aplspmi(4), a driver for the Apple SPMI controller, and aplpmu(4)
a driver for the Apple "sera" SPMI power management unit that contains
the RTC on Apple M1 systems.

ok patrick@


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.61 03-Oct-2022 kettenis

Reorganize the EFI code a bit. Move the efi.h header from dev/acpi to
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@


Revision tags: OPENBSD_7_2_BASE
# 1.60 03-Sep-2022 kettenis

Add apldcms(4), a driver for the touchpad on M2 laptops. This driver
needs firmware that is provided on the ESP by the Asahi installer and
copied into /etc/firmware/apple by the OpenBSD installer.

ok tobhe@


# 1.59 31-Aug-2022 kettenis

Add apldc(4), apldchidev(4), apldckdb(4) and aplrtkit(4). Together these
drivers implement support for the Dockchannel-base keyboard found on
Apple M2 laptops.

ok mlarkin@, patrick@


# 1.58 03-Aug-2022 kettenis

Add aplaudio(4) and aplmca(4). The aplmca(4) driver controls the hardware
block that takes data from apldma(4), serializes it and sends it out on
the i2s ports. The aplaudio(4) driver ties together aplmca(4) and various
codecs to present an audio(4) interface to the system.

This is still WIP, but good enough to play back audio on the speaker in the
M1 mini.

ok patrick@


# 1.57 12-Jun-2022 kettenis

The NVMe firmware distributed with the macOS 13 developer beta does not
like some of the shortcuts we've taken in the code that talks to RTKit.
In particular it does not like our NAK of the request for ioreport buffers.
So allocate the requested buffers and ACK the request instead.

However, the hardware implements a address filter between the coprocessor
that the firmware runs on and main memory. So we have to add a mapping
into this address filter such that the firmware can access these buffers.
Support for this address filter is implemented in a new aplsart(4) driver.

ok dlg@


Revision tags: OPENBSD_7_1_BASE
# 1.56 20-Feb-2022 kettenis

Add aplcpu(4), a driver to control the CPU performance levels on Apple SoCs.

ok gnezdo@


# 1.55 02-Feb-2022 kettenis

Add apldma(4), a driver for the DMA controller found on Apple SoCs.
This driver implements an interface for using DMA for audio output.

ok ratchov@


# 1.54 30-Jan-2022 kettenis

Add aplnco(4), a driver for the Numerically-controlled oscillator (NCO)
clock that drives the audio clocks on Apple silicon.

ok patrick@


# 1.53 10-Jan-2022 kettenis

Add aplsmc(4), a driver for the SMC found on Apple M1 SoCs.

The SMC implements a lot of functionality. For now the driver only
implements a bunch of sensors. This is a small subset of the sensors
that are made available by the SMC as we don't know what measurments
are provided for most sensors.

ok patrick@


# 1.52 08-Jan-2022 kettenis

Remove apldwusb(4). This driver is now unused.


# 1.51 01-Jan-2022 kettenis

Rewrite the kernel FPU handling code. The new code saves the FPU state
in cpu_switch() instead of at the kernel edge and gets rid of the FPU
state tracking in struct cpu_info and struct pcb. This fixes the random
crashes seen with SMP kernels on Apple M1.

ok patrick@


# 1.50 24-Dec-2021 patrick

Add apliic(4), a driver for the I2C controller found on various Apple SoCs.

ok kettenis@


# 1.49 19-Dec-2021 kettenis

Add an implementation for the protocol to communicate with coprocessors
running firmware based Apple's RTKit OS. Use this code to bring up the
storage controller that implements Apple's flavour of NVMe.

ok dlg@, patrick@


# 1.48 19-Dec-2021 kettenis

Enable aplmbox(4).


# 1.47 09-Dec-2021 kettenis

Add aplpmgr(4), a driver for the power management controller found on
various Apple SoCs.

ok patrick@


# 1.46 01-Nov-2021 kettenis

Add support for the keyboard/touchpad on Apple M1 laptops.

ok patrick@


# 1.45 31-Oct-2021 kettenis

Add aplspi(4), a driver for the SPI controller found on the Apple M1 SoC.

ok patrick@


Revision tags: OPENBSD_7_0_BASE
# 1.44 31-Aug-2021 kettenis

Add aplpinctrl(4), a driver for the Apple GPIO controller found on M1 SoCs.

ok patrick@


# 1.43 28-May-2021 dlg

start working on support for Apple NVME Storage as found in apple M1 devs

the Apple NVME Storage (aka ans) controller is almost but not quite
a vanilla nvme controller. one difference is that it doesnt attach
to a pci bus, so it needs this custom bus glue. this custom bus
glue also provides us with a nice way to provide a different set
of functions to handle other things that ans does differently to
vanilla nvme controllers.

this is different to how linux deals with ans. the linux support
fakes a pci controller for ans to attach to. i assumed that at some
point a vendor would include nvme in an soc directly and made it a
bus independent driver from day 1. turns out i was right, but i
would never have guessed that the vendor would be apple.

some of the other differences between vanilla nvme and ans are
around command submission and completion. ans nvme command submission
is done via an array of command slots where the host picks a slot
and then posts every slot number it fills in to a doorbell. this
is different to vanilla nvme controllers which use a ring, and post
the producer index in that ring to a doorbell. ans also includes
some weird iommu, the handling of which we wrap up into the command
submission and completion functions.

this code is not yet enabled because it is incomplete. i'm getting
what i've done in so people with actual hardware can start poking
it more seriously.

this implementation is based on information figured out by the guys
porting linux to apple hardware.


# 1.42 26-May-2021 kettenis

Add aplspmi(4), a driver for the Apple SPMI controller, and aplpmu(4)
a driver for the Apple "sera" SPMI power management unit that contains
the RTC on Apple M1 systems.

ok patrick@


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.60 03-Sep-2022 kettenis

Add apldcms(4), a driver for the touchpad on M2 laptops. This driver
needs firmware that is provided on the ESP by the Asahi installer and
copied into /etc/firmware/apple by the OpenBSD installer.

ok tobhe@


# 1.59 31-Aug-2022 kettenis

Add apldc(4), apldchidev(4), apldckdb(4) and aplrtkit(4). Together these
drivers implement support for the Dockchannel-base keyboard found on
Apple M2 laptops.

ok mlarkin@, patrick@


# 1.58 03-Aug-2022 kettenis

Add aplaudio(4) and aplmca(4). The aplmca(4) driver controls the hardware
block that takes data from apldma(4), serializes it and sends it out on
the i2s ports. The aplaudio(4) driver ties together aplmca(4) and various
codecs to present an audio(4) interface to the system.

This is still WIP, but good enough to play back audio on the speaker in the
M1 mini.

ok patrick@


# 1.57 12-Jun-2022 kettenis

The NVMe firmware distributed with the macOS 13 developer beta does not
like some of the shortcuts we've taken in the code that talks to RTKit.
In particular it does not like our NAK of the request for ioreport buffers.
So allocate the requested buffers and ACK the request instead.

However, the hardware implements a address filter between the coprocessor
that the firmware runs on and main memory. So we have to add a mapping
into this address filter such that the firmware can access these buffers.
Support for this address filter is implemented in a new aplsart(4) driver.

ok dlg@


Revision tags: OPENBSD_7_1_BASE
# 1.56 20-Feb-2022 kettenis

Add aplcpu(4), a driver to control the CPU performance levels on Apple SoCs.

ok gnezdo@


# 1.55 02-Feb-2022 kettenis

Add apldma(4), a driver for the DMA controller found on Apple SoCs.
This driver implements an interface for using DMA for audio output.

ok ratchov@


# 1.54 30-Jan-2022 kettenis

Add aplnco(4), a driver for the Numerically-controlled oscillator (NCO)
clock that drives the audio clocks on Apple silicon.

ok patrick@


# 1.53 10-Jan-2022 kettenis

Add aplsmc(4), a driver for the SMC found on Apple M1 SoCs.

The SMC implements a lot of functionality. For now the driver only
implements a bunch of sensors. This is a small subset of the sensors
that are made available by the SMC as we don't know what measurments
are provided for most sensors.

ok patrick@


# 1.52 08-Jan-2022 kettenis

Remove apldwusb(4). This driver is now unused.


# 1.51 01-Jan-2022 kettenis

Rewrite the kernel FPU handling code. The new code saves the FPU state
in cpu_switch() instead of at the kernel edge and gets rid of the FPU
state tracking in struct cpu_info and struct pcb. This fixes the random
crashes seen with SMP kernels on Apple M1.

ok patrick@


# 1.50 24-Dec-2021 patrick

Add apliic(4), a driver for the I2C controller found on various Apple SoCs.

ok kettenis@


# 1.49 19-Dec-2021 kettenis

Add an implementation for the protocol to communicate with coprocessors
running firmware based Apple's RTKit OS. Use this code to bring up the
storage controller that implements Apple's flavour of NVMe.

ok dlg@, patrick@


# 1.48 19-Dec-2021 kettenis

Enable aplmbox(4).


# 1.47 09-Dec-2021 kettenis

Add aplpmgr(4), a driver for the power management controller found on
various Apple SoCs.

ok patrick@


# 1.46 01-Nov-2021 kettenis

Add support for the keyboard/touchpad on Apple M1 laptops.

ok patrick@


# 1.45 31-Oct-2021 kettenis

Add aplspi(4), a driver for the SPI controller found on the Apple M1 SoC.

ok patrick@


Revision tags: OPENBSD_7_0_BASE
# 1.44 31-Aug-2021 kettenis

Add aplpinctrl(4), a driver for the Apple GPIO controller found on M1 SoCs.

ok patrick@


# 1.43 28-May-2021 dlg

start working on support for Apple NVME Storage as found in apple M1 devs

the Apple NVME Storage (aka ans) controller is almost but not quite
a vanilla nvme controller. one difference is that it doesnt attach
to a pci bus, so it needs this custom bus glue. this custom bus
glue also provides us with a nice way to provide a different set
of functions to handle other things that ans does differently to
vanilla nvme controllers.

this is different to how linux deals with ans. the linux support
fakes a pci controller for ans to attach to. i assumed that at some
point a vendor would include nvme in an soc directly and made it a
bus independent driver from day 1. turns out i was right, but i
would never have guessed that the vendor would be apple.

some of the other differences between vanilla nvme and ans are
around command submission and completion. ans nvme command submission
is done via an array of command slots where the host picks a slot
and then posts every slot number it fills in to a doorbell. this
is different to vanilla nvme controllers which use a ring, and post
the producer index in that ring to a doorbell. ans also includes
some weird iommu, the handling of which we wrap up into the command
submission and completion functions.

this code is not yet enabled because it is incomplete. i'm getting
what i've done in so people with actual hardware can start poking
it more seriously.

this implementation is based on information figured out by the guys
porting linux to apple hardware.


# 1.42 26-May-2021 kettenis

Add aplspmi(4), a driver for the Apple SPMI controller, and aplpmu(4)
a driver for the Apple "sera" SPMI power management unit that contains
the RTC on Apple M1 systems.

ok patrick@


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.59 31-Aug-2022 kettenis

Add apldc(4), apldchidev(4), apldckdb(4) and aplrtkit(4). Together these
drivers implement support for the Dockchannel-base keyboard found on
Apple M2 laptops.

ok mlarkin@, patrick@


# 1.58 03-Aug-2022 kettenis

Add aplaudio(4) and aplmca(4). The aplmca(4) driver controls the hardware
block that takes data from apldma(4), serializes it and sends it out on
the i2s ports. The aplaudio(4) driver ties together aplmca(4) and various
codecs to present an audio(4) interface to the system.

This is still WIP, but good enough to play back audio on the speaker in the
M1 mini.

ok patrick@


# 1.57 12-Jun-2022 kettenis

The NVMe firmware distributed with the macOS 13 developer beta does not
like some of the shortcuts we've taken in the code that talks to RTKit.
In particular it does not like our NAK of the request for ioreport buffers.
So allocate the requested buffers and ACK the request instead.

However, the hardware implements a address filter between the coprocessor
that the firmware runs on and main memory. So we have to add a mapping
into this address filter such that the firmware can access these buffers.
Support for this address filter is implemented in a new aplsart(4) driver.

ok dlg@


Revision tags: OPENBSD_7_1_BASE
# 1.56 20-Feb-2022 kettenis

Add aplcpu(4), a driver to control the CPU performance levels on Apple SoCs.

ok gnezdo@


# 1.55 02-Feb-2022 kettenis

Add apldma(4), a driver for the DMA controller found on Apple SoCs.
This driver implements an interface for using DMA for audio output.

ok ratchov@


# 1.54 30-Jan-2022 kettenis

Add aplnco(4), a driver for the Numerically-controlled oscillator (NCO)
clock that drives the audio clocks on Apple silicon.

ok patrick@


# 1.53 10-Jan-2022 kettenis

Add aplsmc(4), a driver for the SMC found on Apple M1 SoCs.

The SMC implements a lot of functionality. For now the driver only
implements a bunch of sensors. This is a small subset of the sensors
that are made available by the SMC as we don't know what measurments
are provided for most sensors.

ok patrick@


# 1.52 08-Jan-2022 kettenis

Remove apldwusb(4). This driver is now unused.


# 1.51 01-Jan-2022 kettenis

Rewrite the kernel FPU handling code. The new code saves the FPU state
in cpu_switch() instead of at the kernel edge and gets rid of the FPU
state tracking in struct cpu_info and struct pcb. This fixes the random
crashes seen with SMP kernels on Apple M1.

ok patrick@


# 1.50 24-Dec-2021 patrick

Add apliic(4), a driver for the I2C controller found on various Apple SoCs.

ok kettenis@


# 1.49 19-Dec-2021 kettenis

Add an implementation for the protocol to communicate with coprocessors
running firmware based Apple's RTKit OS. Use this code to bring up the
storage controller that implements Apple's flavour of NVMe.

ok dlg@, patrick@


# 1.48 19-Dec-2021 kettenis

Enable aplmbox(4).


# 1.47 09-Dec-2021 kettenis

Add aplpmgr(4), a driver for the power management controller found on
various Apple SoCs.

ok patrick@


# 1.46 01-Nov-2021 kettenis

Add support for the keyboard/touchpad on Apple M1 laptops.

ok patrick@


# 1.45 31-Oct-2021 kettenis

Add aplspi(4), a driver for the SPI controller found on the Apple M1 SoC.

ok patrick@


Revision tags: OPENBSD_7_0_BASE
# 1.44 31-Aug-2021 kettenis

Add aplpinctrl(4), a driver for the Apple GPIO controller found on M1 SoCs.

ok patrick@


# 1.43 28-May-2021 dlg

start working on support for Apple NVME Storage as found in apple M1 devs

the Apple NVME Storage (aka ans) controller is almost but not quite
a vanilla nvme controller. one difference is that it doesnt attach
to a pci bus, so it needs this custom bus glue. this custom bus
glue also provides us with a nice way to provide a different set
of functions to handle other things that ans does differently to
vanilla nvme controllers.

this is different to how linux deals with ans. the linux support
fakes a pci controller for ans to attach to. i assumed that at some
point a vendor would include nvme in an soc directly and made it a
bus independent driver from day 1. turns out i was right, but i
would never have guessed that the vendor would be apple.

some of the other differences between vanilla nvme and ans are
around command submission and completion. ans nvme command submission
is done via an array of command slots where the host picks a slot
and then posts every slot number it fills in to a doorbell. this
is different to vanilla nvme controllers which use a ring, and post
the producer index in that ring to a doorbell. ans also includes
some weird iommu, the handling of which we wrap up into the command
submission and completion functions.

this code is not yet enabled because it is incomplete. i'm getting
what i've done in so people with actual hardware can start poking
it more seriously.

this implementation is based on information figured out by the guys
porting linux to apple hardware.


# 1.42 26-May-2021 kettenis

Add aplspmi(4), a driver for the Apple SPMI controller, and aplpmu(4)
a driver for the Apple "sera" SPMI power management unit that contains
the RTC on Apple M1 systems.

ok patrick@


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.58 03-Aug-2022 kettenis

Add aplaudio(4) and aplmca(4). The aplmca(4) driver controls the hardware
block that takes data from apldma(4), serializes it and sends it out on
the i2s ports. The aplaudio(4) driver ties together aplmca(4) and various
codecs to present an audio(4) interface to the system.

This is still WIP, but good enough to play back audio on the speaker in the
M1 mini.

ok patrick@


# 1.57 12-Jun-2022 kettenis

The NVMe firmware distributed with the macOS 13 developer beta does not
like some of the shortcuts we've taken in the code that talks to RTKit.
In particular it does not like our NAK of the request for ioreport buffers.
So allocate the requested buffers and ACK the request instead.

However, the hardware implements a address filter between the coprocessor
that the firmware runs on and main memory. So we have to add a mapping
into this address filter such that the firmware can access these buffers.
Support for this address filter is implemented in a new aplsart(4) driver.

ok dlg@


Revision tags: OPENBSD_7_1_BASE
# 1.56 20-Feb-2022 kettenis

Add aplcpu(4), a driver to control the CPU performance levels on Apple SoCs.

ok gnezdo@


# 1.55 02-Feb-2022 kettenis

Add apldma(4), a driver for the DMA controller found on Apple SoCs.
This driver implements an interface for using DMA for audio output.

ok ratchov@


# 1.54 30-Jan-2022 kettenis

Add aplnco(4), a driver for the Numerically-controlled oscillator (NCO)
clock that drives the audio clocks on Apple silicon.

ok patrick@


# 1.53 10-Jan-2022 kettenis

Add aplsmc(4), a driver for the SMC found on Apple M1 SoCs.

The SMC implements a lot of functionality. For now the driver only
implements a bunch of sensors. This is a small subset of the sensors
that are made available by the SMC as we don't know what measurments
are provided for most sensors.

ok patrick@


# 1.52 08-Jan-2022 kettenis

Remove apldwusb(4). This driver is now unused.


# 1.51 01-Jan-2022 kettenis

Rewrite the kernel FPU handling code. The new code saves the FPU state
in cpu_switch() instead of at the kernel edge and gets rid of the FPU
state tracking in struct cpu_info and struct pcb. This fixes the random
crashes seen with SMP kernels on Apple M1.

ok patrick@


# 1.50 24-Dec-2021 patrick

Add apliic(4), a driver for the I2C controller found on various Apple SoCs.

ok kettenis@


# 1.49 19-Dec-2021 kettenis

Add an implementation for the protocol to communicate with coprocessors
running firmware based Apple's RTKit OS. Use this code to bring up the
storage controller that implements Apple's flavour of NVMe.

ok dlg@, patrick@


# 1.48 19-Dec-2021 kettenis

Enable aplmbox(4).


# 1.47 09-Dec-2021 kettenis

Add aplpmgr(4), a driver for the power management controller found on
various Apple SoCs.

ok patrick@


# 1.46 01-Nov-2021 kettenis

Add support for the keyboard/touchpad on Apple M1 laptops.

ok patrick@


# 1.45 31-Oct-2021 kettenis

Add aplspi(4), a driver for the SPI controller found on the Apple M1 SoC.

ok patrick@


Revision tags: OPENBSD_7_0_BASE
# 1.44 31-Aug-2021 kettenis

Add aplpinctrl(4), a driver for the Apple GPIO controller found on M1 SoCs.

ok patrick@


# 1.43 28-May-2021 dlg

start working on support for Apple NVME Storage as found in apple M1 devs

the Apple NVME Storage (aka ans) controller is almost but not quite
a vanilla nvme controller. one difference is that it doesnt attach
to a pci bus, so it needs this custom bus glue. this custom bus
glue also provides us with a nice way to provide a different set
of functions to handle other things that ans does differently to
vanilla nvme controllers.

this is different to how linux deals with ans. the linux support
fakes a pci controller for ans to attach to. i assumed that at some
point a vendor would include nvme in an soc directly and made it a
bus independent driver from day 1. turns out i was right, but i
would never have guessed that the vendor would be apple.

some of the other differences between vanilla nvme and ans are
around command submission and completion. ans nvme command submission
is done via an array of command slots where the host picks a slot
and then posts every slot number it fills in to a doorbell. this
is different to vanilla nvme controllers which use a ring, and post
the producer index in that ring to a doorbell. ans also includes
some weird iommu, the handling of which we wrap up into the command
submission and completion functions.

this code is not yet enabled because it is incomplete. i'm getting
what i've done in so people with actual hardware can start poking
it more seriously.

this implementation is based on information figured out by the guys
porting linux to apple hardware.


# 1.42 26-May-2021 kettenis

Add aplspmi(4), a driver for the Apple SPMI controller, and aplpmu(4)
a driver for the Apple "sera" SPMI power management unit that contains
the RTC on Apple M1 systems.

ok patrick@


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.57 12-Jun-2022 kettenis

The NVMe firmware distributed with the macOS 13 developer beta does not
like some of the shortcuts we've taken in the code that talks to RTKit.
In particular it does not like our NAK of the request for ioreport buffers.
So allocate the requested buffers and ACK the request instead.

However, the hardware implements a address filter between the coprocessor
that the firmware runs on and main memory. So we have to add a mapping
into this address filter such that the firmware can access these buffers.
Support for this address filter is implemented in a new aplsart(4) driver.

ok dlg@


Revision tags: OPENBSD_7_1_BASE
# 1.56 20-Feb-2022 kettenis

Add aplcpu(4), a driver to control the CPU performance levels on Apple SoCs.

ok gnezdo@


# 1.55 02-Feb-2022 kettenis

Add apldma(4), a driver for the DMA controller found on Apple SoCs.
This driver implements an interface for using DMA for audio output.

ok ratchov@


# 1.54 30-Jan-2022 kettenis

Add aplnco(4), a driver for the Numerically-controlled oscillator (NCO)
clock that drives the audio clocks on Apple silicon.

ok patrick@


# 1.53 10-Jan-2022 kettenis

Add aplsmc(4), a driver for the SMC found on Apple M1 SoCs.

The SMC implements a lot of functionality. For now the driver only
implements a bunch of sensors. This is a small subset of the sensors
that are made available by the SMC as we don't know what measurments
are provided for most sensors.

ok patrick@


# 1.52 08-Jan-2022 kettenis

Remove apldwusb(4). This driver is now unused.


# 1.51 01-Jan-2022 kettenis

Rewrite the kernel FPU handling code. The new code saves the FPU state
in cpu_switch() instead of at the kernel edge and gets rid of the FPU
state tracking in struct cpu_info and struct pcb. This fixes the random
crashes seen with SMP kernels on Apple M1.

ok patrick@


# 1.50 24-Dec-2021 patrick

Add apliic(4), a driver for the I2C controller found on various Apple SoCs.

ok kettenis@


# 1.49 19-Dec-2021 kettenis

Add an implementation for the protocol to communicate with coprocessors
running firmware based Apple's RTKit OS. Use this code to bring up the
storage controller that implements Apple's flavour of NVMe.

ok dlg@, patrick@


# 1.48 19-Dec-2021 kettenis

Enable aplmbox(4).


# 1.47 09-Dec-2021 kettenis

Add aplpmgr(4), a driver for the power management controller found on
various Apple SoCs.

ok patrick@


# 1.46 01-Nov-2021 kettenis

Add support for the keyboard/touchpad on Apple M1 laptops.

ok patrick@


# 1.45 31-Oct-2021 kettenis

Add aplspi(4), a driver for the SPI controller found on the Apple M1 SoC.

ok patrick@


Revision tags: OPENBSD_7_0_BASE
# 1.44 31-Aug-2021 kettenis

Add aplpinctrl(4), a driver for the Apple GPIO controller found on M1 SoCs.

ok patrick@


# 1.43 28-May-2021 dlg

start working on support for Apple NVME Storage as found in apple M1 devs

the Apple NVME Storage (aka ans) controller is almost but not quite
a vanilla nvme controller. one difference is that it doesnt attach
to a pci bus, so it needs this custom bus glue. this custom bus
glue also provides us with a nice way to provide a different set
of functions to handle other things that ans does differently to
vanilla nvme controllers.

this is different to how linux deals with ans. the linux support
fakes a pci controller for ans to attach to. i assumed that at some
point a vendor would include nvme in an soc directly and made it a
bus independent driver from day 1. turns out i was right, but i
would never have guessed that the vendor would be apple.

some of the other differences between vanilla nvme and ans are
around command submission and completion. ans nvme command submission
is done via an array of command slots where the host picks a slot
and then posts every slot number it fills in to a doorbell. this
is different to vanilla nvme controllers which use a ring, and post
the producer index in that ring to a doorbell. ans also includes
some weird iommu, the handling of which we wrap up into the command
submission and completion functions.

this code is not yet enabled because it is incomplete. i'm getting
what i've done in so people with actual hardware can start poking
it more seriously.

this implementation is based on information figured out by the guys
porting linux to apple hardware.


# 1.42 26-May-2021 kettenis

Add aplspmi(4), a driver for the Apple SPMI controller, and aplpmu(4)
a driver for the Apple "sera" SPMI power management unit that contains
the RTC on Apple M1 systems.

ok patrick@


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.56 20-Feb-2022 kettenis

Add aplcpu(4), a driver to control the CPU performance levels on Apple SoCs.

ok gnezdo@


# 1.55 02-Feb-2022 kettenis

Add apldma(4), a driver for the DMA controller found on Apple SoCs.
This driver implements an interface for using DMA for audio output.

ok ratchov@


# 1.54 30-Jan-2022 kettenis

Add aplnco(4), a driver for the Numerically-controlled oscillator (NCO)
clock that drives the audio clocks on Apple silicon.

ok patrick@


# 1.53 10-Jan-2022 kettenis

Add aplsmc(4), a driver for the SMC found on Apple M1 SoCs.

The SMC implements a lot of functionality. For now the driver only
implements a bunch of sensors. This is a small subset of the sensors
that are made available by the SMC as we don't know what measurments
are provided for most sensors.

ok patrick@


# 1.52 08-Jan-2022 kettenis

Remove apldwusb(4). This driver is now unused.


# 1.51 01-Jan-2022 kettenis

Rewrite the kernel FPU handling code. The new code saves the FPU state
in cpu_switch() instead of at the kernel edge and gets rid of the FPU
state tracking in struct cpu_info and struct pcb. This fixes the random
crashes seen with SMP kernels on Apple M1.

ok patrick@


# 1.50 24-Dec-2021 patrick

Add apliic(4), a driver for the I2C controller found on various Apple SoCs.

ok kettenis@


# 1.49 19-Dec-2021 kettenis

Add an implementation for the protocol to communicate with coprocessors
running firmware based Apple's RTKit OS. Use this code to bring up the
storage controller that implements Apple's flavour of NVMe.

ok dlg@, patrick@


# 1.48 19-Dec-2021 kettenis

Enable aplmbox(4).


# 1.47 09-Dec-2021 kettenis

Add aplpmgr(4), a driver for the power management controller found on
various Apple SoCs.

ok patrick@


# 1.46 01-Nov-2021 kettenis

Add support for the keyboard/touchpad on Apple M1 laptops.

ok patrick@


# 1.45 31-Oct-2021 kettenis

Add aplspi(4), a driver for the SPI controller found on the Apple M1 SoC.

ok patrick@


Revision tags: OPENBSD_7_0_BASE
# 1.44 31-Aug-2021 kettenis

Add aplpinctrl(4), a driver for the Apple GPIO controller found on M1 SoCs.

ok patrick@


# 1.43 28-May-2021 dlg

start working on support for Apple NVME Storage as found in apple M1 devs

the Apple NVME Storage (aka ans) controller is almost but not quite
a vanilla nvme controller. one difference is that it doesnt attach
to a pci bus, so it needs this custom bus glue. this custom bus
glue also provides us with a nice way to provide a different set
of functions to handle other things that ans does differently to
vanilla nvme controllers.

this is different to how linux deals with ans. the linux support
fakes a pci controller for ans to attach to. i assumed that at some
point a vendor would include nvme in an soc directly and made it a
bus independent driver from day 1. turns out i was right, but i
would never have guessed that the vendor would be apple.

some of the other differences between vanilla nvme and ans are
around command submission and completion. ans nvme command submission
is done via an array of command slots where the host picks a slot
and then posts every slot number it fills in to a doorbell. this
is different to vanilla nvme controllers which use a ring, and post
the producer index in that ring to a doorbell. ans also includes
some weird iommu, the handling of which we wrap up into the command
submission and completion functions.

this code is not yet enabled because it is incomplete. i'm getting
what i've done in so people with actual hardware can start poking
it more seriously.

this implementation is based on information figured out by the guys
porting linux to apple hardware.


# 1.42 26-May-2021 kettenis

Add aplspmi(4), a driver for the Apple SPMI controller, and aplpmu(4)
a driver for the Apple "sera" SPMI power management unit that contains
the RTC on Apple M1 systems.

ok patrick@


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.55 02-Feb-2022 kettenis

Add apldma(4), a driver for the DMA controller found on Apple SoCs.
This driver implements an interface for using DMA for audio output.

ok ratchov@


# 1.54 30-Jan-2022 kettenis

Add aplnco(4), a driver for the Numerically-controlled oscillator (NCO)
clock that drives the audio clocks on Apple silicon.

ok patrick@


# 1.53 10-Jan-2022 kettenis

Add aplsmc(4), a driver for the SMC found on Apple M1 SoCs.

The SMC implements a lot of functionality. For now the driver only
implements a bunch of sensors. This is a small subset of the sensors
that are made available by the SMC as we don't know what measurments
are provided for most sensors.

ok patrick@


# 1.52 08-Jan-2022 kettenis

Remove apldwusb(4). This driver is now unused.


# 1.51 01-Jan-2022 kettenis

Rewrite the kernel FPU handling code. The new code saves the FPU state
in cpu_switch() instead of at the kernel edge and gets rid of the FPU
state tracking in struct cpu_info and struct pcb. This fixes the random
crashes seen with SMP kernels on Apple M1.

ok patrick@


# 1.50 24-Dec-2021 patrick

Add apliic(4), a driver for the I2C controller found on various Apple SoCs.

ok kettenis@


# 1.49 19-Dec-2021 kettenis

Add an implementation for the protocol to communicate with coprocessors
running firmware based Apple's RTKit OS. Use this code to bring up the
storage controller that implements Apple's flavour of NVMe.

ok dlg@, patrick@


# 1.48 19-Dec-2021 kettenis

Enable aplmbox(4).


# 1.47 09-Dec-2021 kettenis

Add aplpmgr(4), a driver for the power management controller found on
various Apple SoCs.

ok patrick@


# 1.46 01-Nov-2021 kettenis

Add support for the keyboard/touchpad on Apple M1 laptops.

ok patrick@


# 1.45 31-Oct-2021 kettenis

Add aplspi(4), a driver for the SPI controller found on the Apple M1 SoC.

ok patrick@


Revision tags: OPENBSD_7_0_BASE
# 1.44 31-Aug-2021 kettenis

Add aplpinctrl(4), a driver for the Apple GPIO controller found on M1 SoCs.

ok patrick@


# 1.43 28-May-2021 dlg

start working on support for Apple NVME Storage as found in apple M1 devs

the Apple NVME Storage (aka ans) controller is almost but not quite
a vanilla nvme controller. one difference is that it doesnt attach
to a pci bus, so it needs this custom bus glue. this custom bus
glue also provides us with a nice way to provide a different set
of functions to handle other things that ans does differently to
vanilla nvme controllers.

this is different to how linux deals with ans. the linux support
fakes a pci controller for ans to attach to. i assumed that at some
point a vendor would include nvme in an soc directly and made it a
bus independent driver from day 1. turns out i was right, but i
would never have guessed that the vendor would be apple.

some of the other differences between vanilla nvme and ans are
around command submission and completion. ans nvme command submission
is done via an array of command slots where the host picks a slot
and then posts every slot number it fills in to a doorbell. this
is different to vanilla nvme controllers which use a ring, and post
the producer index in that ring to a doorbell. ans also includes
some weird iommu, the handling of which we wrap up into the command
submission and completion functions.

this code is not yet enabled because it is incomplete. i'm getting
what i've done in so people with actual hardware can start poking
it more seriously.

this implementation is based on information figured out by the guys
porting linux to apple hardware.


# 1.42 26-May-2021 kettenis

Add aplspmi(4), a driver for the Apple SPMI controller, and aplpmu(4)
a driver for the Apple "sera" SPMI power management unit that contains
the RTC on Apple M1 systems.

ok patrick@


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.54 30-Jan-2022 kettenis

Add aplnco(4), a driver for the Numerically-controlled oscillator (NCO)
clock that drives the audio clocks on Apple silicon.

ok patrick@


# 1.53 10-Jan-2022 kettenis

Add aplsmc(4), a driver for the SMC found on Apple M1 SoCs.

The SMC implements a lot of functionality. For now the driver only
implements a bunch of sensors. This is a small subset of the sensors
that are made available by the SMC as we don't know what measurments
are provided for most sensors.

ok patrick@


# 1.52 08-Jan-2022 kettenis

Remove apldwusb(4). This driver is now unused.


# 1.51 01-Jan-2022 kettenis

Rewrite the kernel FPU handling code. The new code saves the FPU state
in cpu_switch() instead of at the kernel edge and gets rid of the FPU
state tracking in struct cpu_info and struct pcb. This fixes the random
crashes seen with SMP kernels on Apple M1.

ok patrick@


# 1.50 24-Dec-2021 patrick

Add apliic(4), a driver for the I2C controller found on various Apple SoCs.

ok kettenis@


# 1.49 19-Dec-2021 kettenis

Add an implementation for the protocol to communicate with coprocessors
running firmware based Apple's RTKit OS. Use this code to bring up the
storage controller that implements Apple's flavour of NVMe.

ok dlg@, patrick@


# 1.48 19-Dec-2021 kettenis

Enable aplmbox(4).


# 1.47 09-Dec-2021 kettenis

Add aplpmgr(4), a driver for the power management controller found on
various Apple SoCs.

ok patrick@


# 1.46 01-Nov-2021 kettenis

Add support for the keyboard/touchpad on Apple M1 laptops.

ok patrick@


# 1.45 31-Oct-2021 kettenis

Add aplspi(4), a driver for the SPI controller found on the Apple M1 SoC.

ok patrick@


Revision tags: OPENBSD_7_0_BASE
# 1.44 31-Aug-2021 kettenis

Add aplpinctrl(4), a driver for the Apple GPIO controller found on M1 SoCs.

ok patrick@


# 1.43 28-May-2021 dlg

start working on support for Apple NVME Storage as found in apple M1 devs

the Apple NVME Storage (aka ans) controller is almost but not quite
a vanilla nvme controller. one difference is that it doesnt attach
to a pci bus, so it needs this custom bus glue. this custom bus
glue also provides us with a nice way to provide a different set
of functions to handle other things that ans does differently to
vanilla nvme controllers.

this is different to how linux deals with ans. the linux support
fakes a pci controller for ans to attach to. i assumed that at some
point a vendor would include nvme in an soc directly and made it a
bus independent driver from day 1. turns out i was right, but i
would never have guessed that the vendor would be apple.

some of the other differences between vanilla nvme and ans are
around command submission and completion. ans nvme command submission
is done via an array of command slots where the host picks a slot
and then posts every slot number it fills in to a doorbell. this
is different to vanilla nvme controllers which use a ring, and post
the producer index in that ring to a doorbell. ans also includes
some weird iommu, the handling of which we wrap up into the command
submission and completion functions.

this code is not yet enabled because it is incomplete. i'm getting
what i've done in so people with actual hardware can start poking
it more seriously.

this implementation is based on information figured out by the guys
porting linux to apple hardware.


# 1.42 26-May-2021 kettenis

Add aplspmi(4), a driver for the Apple SPMI controller, and aplpmu(4)
a driver for the Apple "sera" SPMI power management unit that contains
the RTC on Apple M1 systems.

ok patrick@


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.53 10-Jan-2022 kettenis

Add aplsmc(4), a driver for the SMC found on Apple M1 SoCs.

The SMC implements a lot of functionality. For now the driver only
implements a bunch of sensors. This is a small subset of the sensors
that are made available by the SMC as we don't know what measurments
are provided for most sensors.

ok patrick@


# 1.52 08-Jan-2022 kettenis

Remove apldwusb(4). This driver is now unused.


# 1.51 01-Jan-2022 kettenis

Rewrite the kernel FPU handling code. The new code saves the FPU state
in cpu_switch() instead of at the kernel edge and gets rid of the FPU
state tracking in struct cpu_info and struct pcb. This fixes the random
crashes seen with SMP kernels on Apple M1.

ok patrick@


# 1.50 24-Dec-2021 patrick

Add apliic(4), a driver for the I2C controller found on various Apple SoCs.

ok kettenis@


# 1.49 19-Dec-2021 kettenis

Add an implementation for the protocol to communicate with coprocessors
running firmware based Apple's RTKit OS. Use this code to bring up the
storage controller that implements Apple's flavour of NVMe.

ok dlg@, patrick@


# 1.48 19-Dec-2021 kettenis

Enable aplmbox(4).


# 1.47 09-Dec-2021 kettenis

Add aplpmgr(4), a driver for the power management controller found on
various Apple SoCs.

ok patrick@


# 1.46 01-Nov-2021 kettenis

Add support for the keyboard/touchpad on Apple M1 laptops.

ok patrick@


# 1.45 31-Oct-2021 kettenis

Add aplspi(4), a driver for the SPI controller found on the Apple M1 SoC.

ok patrick@


Revision tags: OPENBSD_7_0_BASE
# 1.44 31-Aug-2021 kettenis

Add aplpinctrl(4), a driver for the Apple GPIO controller found on M1 SoCs.

ok patrick@


# 1.43 28-May-2021 dlg

start working on support for Apple NVME Storage as found in apple M1 devs

the Apple NVME Storage (aka ans) controller is almost but not quite
a vanilla nvme controller. one difference is that it doesnt attach
to a pci bus, so it needs this custom bus glue. this custom bus
glue also provides us with a nice way to provide a different set
of functions to handle other things that ans does differently to
vanilla nvme controllers.

this is different to how linux deals with ans. the linux support
fakes a pci controller for ans to attach to. i assumed that at some
point a vendor would include nvme in an soc directly and made it a
bus independent driver from day 1. turns out i was right, but i
would never have guessed that the vendor would be apple.

some of the other differences between vanilla nvme and ans are
around command submission and completion. ans nvme command submission
is done via an array of command slots where the host picks a slot
and then posts every slot number it fills in to a doorbell. this
is different to vanilla nvme controllers which use a ring, and post
the producer index in that ring to a doorbell. ans also includes
some weird iommu, the handling of which we wrap up into the command
submission and completion functions.

this code is not yet enabled because it is incomplete. i'm getting
what i've done in so people with actual hardware can start poking
it more seriously.

this implementation is based on information figured out by the guys
porting linux to apple hardware.


# 1.42 26-May-2021 kettenis

Add aplspmi(4), a driver for the Apple SPMI controller, and aplpmu(4)
a driver for the Apple "sera" SPMI power management unit that contains
the RTC on Apple M1 systems.

ok patrick@


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.51 01-Jan-2022 kettenis

Rewrite the kernel FPU handling code. The new code saves the FPU state
in cpu_switch() instead of at the kernel edge and gets rid of the FPU
state tracking in struct cpu_info and struct pcb. This fixes the random
crashes seen with SMP kernels on Apple M1.

ok patrick@


# 1.50 24-Dec-2021 patrick

Add apliic(4), a driver for the I2C controller found on various Apple SoCs.

ok kettenis@


# 1.49 19-Dec-2021 kettenis

Add an implementation for the protocol to communicate with coprocessors
running firmware based Apple's RTKit OS. Use this code to bring up the
storage controller that implements Apple's flavour of NVMe.

ok dlg@, patrick@


# 1.48 19-Dec-2021 kettenis

Enable aplmbox(4).


# 1.47 09-Dec-2021 kettenis

Add aplpmgr(4), a driver for the power management controller found on
various Apple SoCs.

ok patrick@


# 1.46 01-Nov-2021 kettenis

Add support for the keyboard/touchpad on Apple M1 laptops.

ok patrick@


# 1.45 31-Oct-2021 kettenis

Add aplspi(4), a driver for the SPI controller found on the Apple M1 SoC.

ok patrick@


Revision tags: OPENBSD_7_0_BASE
# 1.44 31-Aug-2021 kettenis

Add aplpinctrl(4), a driver for the Apple GPIO controller found on M1 SoCs.

ok patrick@


# 1.43 28-May-2021 dlg

start working on support for Apple NVME Storage as found in apple M1 devs

the Apple NVME Storage (aka ans) controller is almost but not quite
a vanilla nvme controller. one difference is that it doesnt attach
to a pci bus, so it needs this custom bus glue. this custom bus
glue also provides us with a nice way to provide a different set
of functions to handle other things that ans does differently to
vanilla nvme controllers.

this is different to how linux deals with ans. the linux support
fakes a pci controller for ans to attach to. i assumed that at some
point a vendor would include nvme in an soc directly and made it a
bus independent driver from day 1. turns out i was right, but i
would never have guessed that the vendor would be apple.

some of the other differences between vanilla nvme and ans are
around command submission and completion. ans nvme command submission
is done via an array of command slots where the host picks a slot
and then posts every slot number it fills in to a doorbell. this
is different to vanilla nvme controllers which use a ring, and post
the producer index in that ring to a doorbell. ans also includes
some weird iommu, the handling of which we wrap up into the command
submission and completion functions.

this code is not yet enabled because it is incomplete. i'm getting
what i've done in so people with actual hardware can start poking
it more seriously.

this implementation is based on information figured out by the guys
porting linux to apple hardware.


# 1.42 26-May-2021 kettenis

Add aplspmi(4), a driver for the Apple SPMI controller, and aplpmu(4)
a driver for the Apple "sera" SPMI power management unit that contains
the RTC on Apple M1 systems.

ok patrick@


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.50 24-Dec-2021 patrick

Add apliic(4), a driver for the I2C controller found on various Apple SoCs.

ok kettenis@


# 1.49 19-Dec-2021 kettenis

Add an implementation for the protocol to communicate with coprocessors
running firmware based Apple's RTKit OS. Use this code to bring up the
storage controller that implements Apple's flavour of NVMe.

ok dlg@, patrick@


# 1.48 19-Dec-2021 kettenis

Enable aplmbox(4).


# 1.47 09-Dec-2021 kettenis

Add aplpmgr(4), a driver for the power management controller found on
various Apple SoCs.

ok patrick@


# 1.46 01-Nov-2021 kettenis

Add support for the keyboard/touchpad on Apple M1 laptops.

ok patrick@


# 1.45 31-Oct-2021 kettenis

Add aplspi(4), a driver for the SPI controller found on the Apple M1 SoC.

ok patrick@


Revision tags: OPENBSD_7_0_BASE
# 1.44 31-Aug-2021 kettenis

Add aplpinctrl(4), a driver for the Apple GPIO controller found on M1 SoCs.

ok patrick@


# 1.43 28-May-2021 dlg

start working on support for Apple NVME Storage as found in apple M1 devs

the Apple NVME Storage (aka ans) controller is almost but not quite
a vanilla nvme controller. one difference is that it doesnt attach
to a pci bus, so it needs this custom bus glue. this custom bus
glue also provides us with a nice way to provide a different set
of functions to handle other things that ans does differently to
vanilla nvme controllers.

this is different to how linux deals with ans. the linux support
fakes a pci controller for ans to attach to. i assumed that at some
point a vendor would include nvme in an soc directly and made it a
bus independent driver from day 1. turns out i was right, but i
would never have guessed that the vendor would be apple.

some of the other differences between vanilla nvme and ans are
around command submission and completion. ans nvme command submission
is done via an array of command slots where the host picks a slot
and then posts every slot number it fills in to a doorbell. this
is different to vanilla nvme controllers which use a ring, and post
the producer index in that ring to a doorbell. ans also includes
some weird iommu, the handling of which we wrap up into the command
submission and completion functions.

this code is not yet enabled because it is incomplete. i'm getting
what i've done in so people with actual hardware can start poking
it more seriously.

this implementation is based on information figured out by the guys
porting linux to apple hardware.


# 1.42 26-May-2021 kettenis

Add aplspmi(4), a driver for the Apple SPMI controller, and aplpmu(4)
a driver for the Apple "sera" SPMI power management unit that contains
the RTC on Apple M1 systems.

ok patrick@


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.49 19-Dec-2021 kettenis

Add an implementation for the protocol to communicate with coprocessors
running firmware based Apple's RTKit OS. Use this code to bring up the
storage controller that implements Apple's flavour of NVMe.

ok dlg@, patrick@


# 1.48 19-Dec-2021 kettenis

Enable aplmbox(4).


# 1.47 09-Dec-2021 kettenis

Add aplpmgr(4), a driver for the power management controller found on
various Apple SoCs.

ok patrick@


# 1.46 01-Nov-2021 kettenis

Add support for the keyboard/touchpad on Apple M1 laptops.

ok patrick@


# 1.45 31-Oct-2021 kettenis

Add aplspi(4), a driver for the SPI controller found on the Apple M1 SoC.

ok patrick@


Revision tags: OPENBSD_7_0_BASE
# 1.44 31-Aug-2021 kettenis

Add aplpinctrl(4), a driver for the Apple GPIO controller found on M1 SoCs.

ok patrick@


# 1.43 28-May-2021 dlg

start working on support for Apple NVME Storage as found in apple M1 devs

the Apple NVME Storage (aka ans) controller is almost but not quite
a vanilla nvme controller. one difference is that it doesnt attach
to a pci bus, so it needs this custom bus glue. this custom bus
glue also provides us with a nice way to provide a different set
of functions to handle other things that ans does differently to
vanilla nvme controllers.

this is different to how linux deals with ans. the linux support
fakes a pci controller for ans to attach to. i assumed that at some
point a vendor would include nvme in an soc directly and made it a
bus independent driver from day 1. turns out i was right, but i
would never have guessed that the vendor would be apple.

some of the other differences between vanilla nvme and ans are
around command submission and completion. ans nvme command submission
is done via an array of command slots where the host picks a slot
and then posts every slot number it fills in to a doorbell. this
is different to vanilla nvme controllers which use a ring, and post
the producer index in that ring to a doorbell. ans also includes
some weird iommu, the handling of which we wrap up into the command
submission and completion functions.

this code is not yet enabled because it is incomplete. i'm getting
what i've done in so people with actual hardware can start poking
it more seriously.

this implementation is based on information figured out by the guys
porting linux to apple hardware.


# 1.42 26-May-2021 kettenis

Add aplspmi(4), a driver for the Apple SPMI controller, and aplpmu(4)
a driver for the Apple "sera" SPMI power management unit that contains
the RTC on Apple M1 systems.

ok patrick@


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.47 09-Dec-2021 kettenis

Add aplpmgr(4), a driver for the power management controller found on
various Apple SoCs.

ok patrick@


# 1.46 01-Nov-2021 kettenis

Add support for the keyboard/touchpad on Apple M1 laptops.

ok patrick@


# 1.45 31-Oct-2021 kettenis

Add aplspi(4), a driver for the SPI controller found on the Apple M1 SoC.

ok patrick@


Revision tags: OPENBSD_7_0_BASE
# 1.44 31-Aug-2021 kettenis

Add aplpinctrl(4), a driver for the Apple GPIO controller found on M1 SoCs.

ok patrick@


# 1.43 28-May-2021 dlg

start working on support for Apple NVME Storage as found in apple M1 devs

the Apple NVME Storage (aka ans) controller is almost but not quite
a vanilla nvme controller. one difference is that it doesnt attach
to a pci bus, so it needs this custom bus glue. this custom bus
glue also provides us with a nice way to provide a different set
of functions to handle other things that ans does differently to
vanilla nvme controllers.

this is different to how linux deals with ans. the linux support
fakes a pci controller for ans to attach to. i assumed that at some
point a vendor would include nvme in an soc directly and made it a
bus independent driver from day 1. turns out i was right, but i
would never have guessed that the vendor would be apple.

some of the other differences between vanilla nvme and ans are
around command submission and completion. ans nvme command submission
is done via an array of command slots where the host picks a slot
and then posts every slot number it fills in to a doorbell. this
is different to vanilla nvme controllers which use a ring, and post
the producer index in that ring to a doorbell. ans also includes
some weird iommu, the handling of which we wrap up into the command
submission and completion functions.

this code is not yet enabled because it is incomplete. i'm getting
what i've done in so people with actual hardware can start poking
it more seriously.

this implementation is based on information figured out by the guys
porting linux to apple hardware.


# 1.42 26-May-2021 kettenis

Add aplspmi(4), a driver for the Apple SPMI controller, and aplpmu(4)
a driver for the Apple "sera" SPMI power management unit that contains
the RTC on Apple M1 systems.

ok patrick@


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.46 01-Nov-2021 kettenis

Add support for the keyboard/touchpad on Apple M1 laptops.

ok patrick@


# 1.45 31-Oct-2021 kettenis

Add aplspi(4), a driver for the SPI controller found on the Apple M1 SoC.

ok patrick@


Revision tags: OPENBSD_7_0_BASE
# 1.44 31-Aug-2021 kettenis

Add aplpinctrl(4), a driver for the Apple GPIO controller found on M1 SoCs.

ok patrick@


# 1.43 28-May-2021 dlg

start working on support for Apple NVME Storage as found in apple M1 devs

the Apple NVME Storage (aka ans) controller is almost but not quite
a vanilla nvme controller. one difference is that it doesnt attach
to a pci bus, so it needs this custom bus glue. this custom bus
glue also provides us with a nice way to provide a different set
of functions to handle other things that ans does differently to
vanilla nvme controllers.

this is different to how linux deals with ans. the linux support
fakes a pci controller for ans to attach to. i assumed that at some
point a vendor would include nvme in an soc directly and made it a
bus independent driver from day 1. turns out i was right, but i
would never have guessed that the vendor would be apple.

some of the other differences between vanilla nvme and ans are
around command submission and completion. ans nvme command submission
is done via an array of command slots where the host picks a slot
and then posts every slot number it fills in to a doorbell. this
is different to vanilla nvme controllers which use a ring, and post
the producer index in that ring to a doorbell. ans also includes
some weird iommu, the handling of which we wrap up into the command
submission and completion functions.

this code is not yet enabled because it is incomplete. i'm getting
what i've done in so people with actual hardware can start poking
it more seriously.

this implementation is based on information figured out by the guys
porting linux to apple hardware.


# 1.42 26-May-2021 kettenis

Add aplspmi(4), a driver for the Apple SPMI controller, and aplpmu(4)
a driver for the Apple "sera" SPMI power management unit that contains
the RTC on Apple M1 systems.

ok patrick@


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.44 31-Aug-2021 kettenis

Add aplpinctrl(4), a driver for the Apple GPIO controller found on M1 SoCs.

ok patrick@


# 1.43 28-May-2021 dlg

start working on support for Apple NVME Storage as found in apple M1 devs

the Apple NVME Storage (aka ans) controller is almost but not quite
a vanilla nvme controller. one difference is that it doesnt attach
to a pci bus, so it needs this custom bus glue. this custom bus
glue also provides us with a nice way to provide a different set
of functions to handle other things that ans does differently to
vanilla nvme controllers.

this is different to how linux deals with ans. the linux support
fakes a pci controller for ans to attach to. i assumed that at some
point a vendor would include nvme in an soc directly and made it a
bus independent driver from day 1. turns out i was right, but i
would never have guessed that the vendor would be apple.

some of the other differences between vanilla nvme and ans are
around command submission and completion. ans nvme command submission
is done via an array of command slots where the host picks a slot
and then posts every slot number it fills in to a doorbell. this
is different to vanilla nvme controllers which use a ring, and post
the producer index in that ring to a doorbell. ans also includes
some weird iommu, the handling of which we wrap up into the command
submission and completion functions.

this code is not yet enabled because it is incomplete. i'm getting
what i've done in so people with actual hardware can start poking
it more seriously.

this implementation is based on information figured out by the guys
porting linux to apple hardware.


# 1.42 26-May-2021 kettenis

Add aplspmi(4), a driver for the Apple SPMI controller, and aplpmu(4)
a driver for the Apple "sera" SPMI power management unit that contains
the RTC on Apple M1 systems.

ok patrick@


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.43 28-May-2021 dlg

start working on support for Apple NVME Storage as found in apple M1 devs

the Apple NVME Storage (aka ans) controller is almost but not quite
a vanilla nvme controller. one difference is that it doesnt attach
to a pci bus, so it needs this custom bus glue. this custom bus
glue also provides us with a nice way to provide a different set
of functions to handle other things that ans does differently to
vanilla nvme controllers.

this is different to how linux deals with ans. the linux support
fakes a pci controller for ans to attach to. i assumed that at some
point a vendor would include nvme in an soc directly and made it a
bus independent driver from day 1. turns out i was right, but i
would never have guessed that the vendor would be apple.

some of the other differences between vanilla nvme and ans are
around command submission and completion. ans nvme command submission
is done via an array of command slots where the host picks a slot
and then posts every slot number it fills in to a doorbell. this
is different to vanilla nvme controllers which use a ring, and post
the producer index in that ring to a doorbell. ans also includes
some weird iommu, the handling of which we wrap up into the command
submission and completion functions.

this code is not yet enabled because it is incomplete. i'm getting
what i've done in so people with actual hardware can start poking
it more seriously.

this implementation is based on information figured out by the guys
porting linux to apple hardware.


# 1.42 26-May-2021 kettenis

Add aplspmi(4), a driver for the Apple SPMI controller, and aplpmu(4)
a driver for the Apple "sera" SPMI power management unit that contains
the RTC on Apple M1 systems.

ok patrick@


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.42 26-May-2021 kettenis

Add aplspmi(4), a driver for the Apple SPMI controller, and aplpmu(4)
a driver for the Apple "sera" SPMI power management unit that contains
the RTC on Apple M1 systems.

ok patrick@


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.41 24-May-2021 kettenis

Add apldwusb(4), a glue driver for the Synpsys DesignWare USB 3 controllers
found on the Apple M1 SoC.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.40 18-May-2021 kettenis

Move the pciecam stanza back into files.arm64 since armv7 has its own
pciecam(4) implementation hidden away in arch/armv7/vexpress.

Unbreaks armv7 kernel builds.


# 1.39 17-May-2021 kettenis

Move pciecam.c to dev/fdt/.

ok deraadt@


Revision tags: OPENBSD_6_9_BASE
# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.38 28-Feb-2021 patrick

acpiiort(4) and smmu(4)


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.37 27-Feb-2021 kettenis

Add apldart(4), a driver for the IOMMU on Apple M1 SoCs.

ok patrick@


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.36 26-Feb-2021 kettenis

Add aplcpie(4), a (minimal) driver for the PCIe host bridge on Apple M1 SoCs.

ok patrick@


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.35 23-Feb-2021 kettenis

Add aplintc(4), a driver for the interrupt controller found on
Apple M1 SoCs.

ok patrick@


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.34 22-Feb-2021 kettenis

Enable apldog(4).


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.33 21-Feb-2021 tobhe

Add cryptox(4), a driver for armv8 cryptographic extensions.
The driver currently only supports AES-CBC mode but can easily
be extended to other algorithms and modes.
The aesv8-armx.S file was generated from the CRYPTOGAMS project.

Asked to commit by and ok patrick@


Revision tags: OPENBSD_6_8_BASE
# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.32 25-Jul-2020 tobhe

Port over NetBSD's arm64 disassembler for DDB.

ok kettenis@, patrick@


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.31 14-May-2020 kettenis

The dwctwo(4) FDT glue is now identical on armv7 and arm64. Move it to
/dev/fdt.

ok patrick@, visa@


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.30 04-Aug-2019 kettenis

Implement smbios support on arm64.

ok deraadt@, jsg@


# 1.29 03-Aug-2019 deraadt

permit maxusers to grow up to 128


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.28 31-May-2019 kettenis

Add MSI-X support for acpipci(4). This splits out some generic code into
a new pci_machdep.c file such that it can be re-used by other arm64
PCI host bridge drivers in the future.

ok patrick@


Revision tags: OPENBSD_6_5_BASE
# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.27 23-Jan-2019 phessler

Add the apm(4) subsystem to arm64.

NB: acpi(4) is not hooked up to this yet.

previous version OK deraadt@ patrick@
OK jsg@


Revision tags: OPENBSD_6_4_BASE
# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.26 30-Jul-2018 kettenis

Add support for the GIC v3 ITS and use it to implement MSI support for
rkpcie(4).

ok patrick@


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.25 05-Jul-2018 kettenis

Add acpipci(4), a driver that supports generic ECAM-compatible PCI host
bridges based on information provided by ACPI.

ok mlarkin@


# 1.24 01-Jul-2018 kettenis

Hook up acpi(4) on arm64. Various bits of driver glue are still missing
but this is enough to boot multi-user on the mcbin with suitable firmware.

ok mlarkin@


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.23 05-Jun-2018 kettenis

Move pluart(4) to dev/fdt.

ok jsg@


# 1.22 31-May-2018 kettenis

Move com_fdt.c to dev/fdt since we can share it between armv7 and arm64 now.

ok patrick@


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.21 04-May-2018 visa

Add a common rules file for ofw sources to help keep the configurations
of fdt-enabled platforms in sync.

OK deraadt@


# 1.20 02-May-2018 patrick

Implement a power domain framework to turn on/off so-called power
domains. This mechanism is used by the newer i.MX8M SoCs so that
drivers can call into ATF to supply power to e.g. a USB port.

ok kettenis@


Revision tags: OPENBSD_6_3_BASE
# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.19 15-Feb-2018 jsg

use the arm64 openprom.c on arm64
ok patrick@


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.18 25-Jan-2018 mpi

Move common mutex implementations to a MI place.

Archs not yet converted can to the jump by defining __USE_MI_MUTEX.

ok visa@


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.


# 1.17 10-Jan-2018 kettenis

Implement FUCKWIT for arm64; unmap the kernel almost entirely while userland
is running. This provides protection against meltown on cores that are
vilnerable (just Cortex-A75 so far) but also seems to be an essential to
protect against spectre-like attacks against the kernel.

This implementation only exposes a single treampoline page that does not
contain any kernel virtual addresses and also hides the real virtual address
of the exception vectors, which helps on cores vulnerable to "variant 3a"
(Cortex-A57, Cortex-A72). The implementation is inspired by the work done
by Will Deacon for Linux, but there are no knobs to turn it off. The
overhead is fairly limited: around 3-4% slowdown on Cortex-A57.

ok patrick@, deraadt@


# 1.16 04-Jan-2018 kettenis

Implement support for calling EFI runtime services and use it to implement
a time-of-day clock device based on the GetTime() and SetTime() services.
The virtual memory mappings for the runtime services calls are implemented
through a separate pmap that is only activated when we make a runtime services
call.

ok tom@, visa@
tested by naddy@


Revision tags: OPENBSD_6_2_BASE
# 1.15 04-Jun-2017 patrick

Split early startup code out of locore.S into locore0.S. Adjust link
run so that this locore0.o is always at the start of the executable.
But randomize the link order of all other .o files in the kernel, so
that their exec/rodata/data/bss segments land all over the place.
Late during kernel boot, unmap the early startup code.

As a result, the internal layout of every newly build bsd kernel is
different from past kernels. Internal relative offsets are not known
to an outside attacker. The only known offsets are in the startup code,
which has been unmapped.

Ramdisk kernels cannot be compiled like this, because they are gzip'd.
When the internal pointer references change, the compression dictionary
bloats and results in poorer compression.

With guidance and ok deraadt@


# 1.14 30-Apr-2017 kettenis

Add rkgrf(4), a driver that makes the "generic register file" of the Rockchip
RK3399 available to other drivers through the regmap interface.


# 1.13 29-Apr-2017 kettenis

Add agintc(4), a driver for interrupt controllers conforming to ARM's
generic interrupt controller architecture specification v3/4.

The hard work was done by drahn@, I just cleaned it up a bit and fixed
a couple of bugs.

ok patrick@, drahn@


# 1.12 27-Apr-2017 kettenis

Add code to identify the CPUs on arm64 systems. The primary CPU is attached
and identified early on. For the secondary CPUs this happens late, such that
the drivers we need to spin up CPUs, such as psci(4), will be available.

This also fixes some code in simplebus(4) where the return value of
OF_getprop() was not properly checked.

Heavily based on an earlier diff from drahn@.

ok drahn@, jsg@


Revision tags: OPENBSD_6_1_BASE
# 1.11 25-Feb-2017 patrick

Implement ampintcmsi(4) in ampintc(4) to support MSI. The GICv2M is an
extension to the GIC controller, which is represented as subnode in the
device tree. There can be multiple GICv2Ms, so it makes sense to attach
those to ampintc(4) as some kind of simplebus. The GICv2M is simply an
interrupt generator that can be used by PCIe devices to ring the door
bell. There is no need for further configuration, we only need to find
out which SPIs we are allowed to use for MSI and to register an edge
triggered interrupt on a (randomly) allocated SPI.

ok kettenis@


# 1.10 24-Feb-2017 patrick

Hook up pciecam(4), but don't compile it yet.


# 1.9 06-Feb-2017 patrick

Move cache and tlb flush functions, which were mostly inline assembly,
into separate functions. This makes them reusable from other parts in
the kernel. Assembly and header are taken from FreeBSD, but modified
to fit our requirements and with some unnecessary stuff removed. While
there remove micro optimization for uniprocessor kernels.


# 1.8 26-Jan-2017 jsg

The only difference between armv7 and arm64 fdt virtio attachments is an
uneeded include. Remove the include and move to MI fdt directory.


# 1.7 23-Jan-2017 patrick

Make the RAMDISK kernel actually try to boot the ramdisk.


# 1.6 23-Jan-2017 kettenis

openprom(4)


# 1.5 23-Jan-2017 kettenis

Add drivers for the Raspberry Pi 3.


# 1.4 21-Jan-2017 reyk

Move virtio config from files.pci to files.pci

virtio itself is not PCI, it is a paravirtual bus on top of either PCI
or MMIO (arm). This is the first step of moving the virtio files to
dev/pv. No functional change.

arm kernel changes tested by jsg@ and patrick@
no objections from sf@ mlarkin@


# 1.3 21-Jan-2017 patrick

Add Allwinner A64 devices to OpenBSD/arm64. This means we can run
on the Pine64. While there add a few more usb and pseudo devices.


# 1.2 18-Dec-2016 patrick

Consolidate bus space tags into generic bus space code. Especially
considering we don't have a separate iobus and the a4x iobus wasn't
even compiled it does not make sense to declare those in iobus.
Improves code readability as well.


# 1.1 17-Dec-2016 patrick

Import of OpenBSD/arm64

This commit contains all the kernel files related to the OpenBSD/arm64
port. It is based on the PowerPC pmap, loongson, arm/armv7 code and
FreeBSD aarch64 code. Hard work done by Dale Rahn.