100 Commits
Author SHA1 Message Date
Andrew Turner e82b2913b7 arm64/acpica: Fix the IORT MSI xref type
The acpi IORT code incorrectly uses a u_int as the MSI xref type, while
INTRNG expects an intptr_t. Switch to using intptr_t to help document
this value is the xref for the MSI controller.

Reviewed by:	dsl
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D60653
2026-11-06 15:38:51 +00:00
Andrew Turner ac64294143 arm64: Relax memory barriers around DMA operations
Before and after DMA operations we need memory barriers to ensure
stores on the CPU are observed by the device, and stores by the device
are observed by the CPU.

Previously we used a "dsb sy" instruction, however this is too strong
and can lead to slower performance.

Drew Gallatin found and tested the issue with cache-coherent devices,
reducing the barriers to dmb instructions in the outer-shareable
domain. After discussing the issue with the Arm Linux DMA maintainer I
concluded it was safe for non-coherent devices as the only dsb
instructions we need are after cache operations and these already exist.

Replace the dsb before DMA with a "dmb oshst" when cache-coherent, or
the existing dsb after invalidating the cache when not coherent. This
ensures earlier stores have completed before we signal the device.

Replace the dsb after DMA with "dmb oshld" in both cases. This ensures
later loads or stores are ordered after earlier device register loads.

Co-Authored-By:	Andrew Gallatin <[email protected]>
Sponsored by:	Arm Ltd
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D60407
2026-10-13 16:44:34 +01:00
Andrew Turner 406a74f780 bhyve: Use the new spelling of MPIDR_Aff*
Fixes:	6bf6fe1d70 ("arm64: Fix the MPIDR_EL1 field names")
 Sponsored by:	Arm Ltd
2026-10-09 15:59:37 +01:00
Andrew Turner 6bf6fe1d70 arm64: Fix the MPIDR_EL1 field names
Use the field names from the Arm Documentation for the MPIDR_EL1
register. These will later be generated from a BSD Licensed JSON file
so to reduce the diff for that rename now.

Reviewed by:	kajetan.puchalski_arm.com
Sponsored by:   Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D59176
2026-10-09 12:55:14 +01:00
Andrew Turner e8997a4e44 arm64: Use sysinsn.h to generate tlbi instructions
Some toolchains may not understand the .arch_extension.

Reviewed by:	jhb
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D59148
2026-10-09 12:55:06 +01:00
Andrew Turner 3864fe9317 arm64: Add a header for system instructions
Like armreg.h for system registers add a header to hold macros for
system instructions.

Reviewed by:	jhb
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D59147
2026-10-09 12:54:56 +01:00
Andrew Turner 412c3a0370 arm64/gicv5: Use ArmMpidr to find the correct CPU
The GICv5 ACPI code uses CpuInterfaceNumber to as the CPU ID. This a
GICv5 CPU ID and may not be the same as the appropriate FreeBSD value.

It is also possible the target CPU is disabled, e.g. when the hw.ncpu
tunable is uses to limit CPUs. If this is the case we don't want to
enable the CPU in the cpu set as it is offline so cannot handle
interrupts.

Switch to use ArmMpidr to find which pcpu to use when finding which
CPUs the IRS is attached to.

Fixes:	9556306213 ("arm64: Add ACPI support to GICv5 driver")
Differential Revision:	https://reviews.freebsd.org/D59993
Sponsored by:	Arm Ltd
2026-10-05 15:13:06 +01:00
Andrew Turner a856958cab arm64/smmu: Fix the SMMU-600 errata check
Fixes:	6dca6e2aa8 ("arm64/smmu: Start handling errata")
Sponsored by:	Arm Ltd
2026-09-18 20:54:16 +01:00
Andrew Turner 50e01b6351 arm64/smmu: Only MSI poll when cache-coherent
Only use the MSI polling method when we support MSIs and the SMMU is
cache-coherent.

The SMMU writes to a memory location. If it is not cache-coherent then
the CPU may read the existing value in its cache and miss the signal
the sync operation has completed.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D59489
2026-09-18 12:29:19 +01:00
Andrew Turner 0689a5ea45 arm64/smmu: Support polling for sync completion
When the hardware doesn't support MSIs we need to poll to wait for
sync operations to complete. Add support for this to support booting
on this hardware.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D59488
2026-09-18 12:29:02 +01:00
Andrew Turner 54393bf536 arm64/smmu: Split out waiting for sync completion
In preparation for adding a non-MSI method split out waiting for sync
completions from smmu_sync.

While here fix the loop to wait for sync timeout to the worst case
Linux uses.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D59487
2026-09-18 12:28:51 +01:00
Andrew Turner 6dca6e2aa8 arm64/smmu: Start handling errata
Handle the Arm MMU-600 erratum 1076982 where when we poll for a sync
command completion we can't use the wait-for-event instruction.

This is in preparation for later adding support for polling for sync
command completion and is not an issue on stable branches.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D59486
2026-09-18 12:28:41 +01:00
Andrew Turner 0bcd0616ff arm64/smmu: Move smmu later
We need to wait for the interrupt drivers to attach before the smmu
driver. As both of these happened at BUS_PASS_INTERRUPT +
BUS_PASS_ORDER_MIDDLE there was no guarantee this would happen in the
correct order.

Fix by moving the smmu driver to BUS_PASS_ORDER_LATE.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D59485
2026-09-18 12:28:31 +01:00
Andrew Turner d95b62db76 arm64: Add a wfe function
And replace inline assembly

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D59482
2026-09-18 12:27:25 +01:00
Andrew Turner 93a08bf12c arm64: Move the CNTV_CTL_EL0 fields to armreg.h
They are architecturally defined, so should be in the common location.

Reviewed by:	emaste, Kajetan Puchalski <[email protected]>
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D59181
2026-09-08 04:05:27 +01:00
Andrew Turner deb43dafdc arm64: Fix the capitalization of CurrentEL
Use the same capitalization as the Arm documentation.

Reviewed by:	Kajetan Puchalski <[email protected]>
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D59180
2026-09-08 04:05:27 +01:00
Andrew Turner 5c9daa5451 arm64: Add ICC_SGI1R_IRM_VAL and use it
This will be the name of the generated macro. As we only need to check
if this field is set or not use the common ICC_SGI1R_IRM_VAL name.

Reviewed by:	Kajetan Puchalski <[email protected]>
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D59179
2026-09-08 04:05:27 +01:00
Andrew Turner fe659a8896 arm64: Rename some ID_AA64DFR0_EL1 macros
These macros are used to extract the number of breakpoints and
watchpoints from the register. Rename them to not conflict with the
common meaning of an _VAL macro in this file.

Reviewed by:	Kajetan Puchalski <[email protected]>
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D59178
2026-09-08 04:05:27 +01:00
Andrew Turner d9106d74ff arm64: Remove ID_AA64PFR0_GIC_BITS
It's unused since 05f6f65c3b ("arm64: add CHECK_CPU_FEAT() for
checking feature support in assembly"). It's been replaces with a
commonly named ID_AA64PFR0_GIC_WIDTH macro.

Reviewed by:	Kajetan Puchalski <[email protected]>
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D59177
2026-09-08 04:05:27 +01:00
Andrew Turner 4837a14b08 arm64: Fix the ID_AA64MMFR1_EL1.CMOW name
This was incorrectly names CMOVW. Remove the unneeded 'V'.

Reviewed by:	Kajetan Puchalski <[email protected]>
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D59175
2026-09-08 04:05:27 +01:00
Andrew Turner e1f684a160 arm64: Fix the ICC_SGI1R_EL1 field names
Use the field names from the Arm Documentation for the ICC_SGI1R_EL1
register. These will later be generated from a BSD Licensed JSON file
so to reduce the diff for that rename now.

Reviewed by:	Kajetan Puchalski <[email protected]>
Sponsored by:   Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D59174
2026-09-08 04:05:27 +01:00
Andrew Turner 747c377963 arm64: Fix the CTR_EL0 field names
Use the field names from the Arm Documentation for the CTR_EL0
register. These will later be generated from a BSD Licensed JSON file
so to reduce the diff for that rename now.

Reviewed by:	Kajetan Puchalski <[email protected]>
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D59173
2026-09-08 04:05:26 +01:00
Andrew Turner 57775b3be6 arm64/smmu: Fix undefined behaviour in Q_OVF
"1 << 31" is a signed int left shift 31 which is undefined as the shift
is too large. Use an unsigned int to make the value defined.

Sponsored by:	Arm Ltd
2026-08-26 12:31:36 +01:00
Andrew Turner 1ecf7d5b38 arm64: vmm: Split out VGIC register handling to a common file
Reviewed by:	Sarah Walker <[email protected]>
Sponsored by:	Arm Ltd
2026-08-26 12:17:18 +01:00
Andrew Turner 7823d306d3 arm64: vmm: Move vgic_v3 structures to header file
Move vgic_v3 structures in preparation for vgic interface rework for GICv5
support.

Reviewed by:	Sarah Walker <[email protected]>
Sponsored by:	Arm Ltd
2026-08-26 12:17:17 +01:00
Andrew Turner 91867042ec arm64: Fix the indentation of ID_AA64ISAR2_EL1
Some ID_AA64ISAR2_EL1 fields values are incorrectly indented. Values
have an extra space before the macro to make scanning for them easier.

Add this extra space to the two fields that were missing it.

Sponsored by:	Arm Ltd
2026-08-25 14:47:53 +01:00
Andrew Turner 137ce1e2b2 arm64: Use decimal values for op and CR macros
Using hex here breaks the instruction generated by MRS_REG_ALT_NAME.
Switch to a decimal value.

Sponsored by:	Arm Ltd
2026-08-25 14:47:53 +01:00
Andrew Turner d1bd7d37cd arm64: Stop trashing the padding after boot_el
When building struct arm64_bootparams to pass to initarm we store the
boot_el field as a 64-bit value, however it is defined as an int which
is 32-bits.

Switch to store using the 'w' register as this will store a correctly
sized value.

Previously this would trash the trailing padding, so is only a
correctness issue.

Reviewed by:	emaste
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D58988
2026-08-24 15:45:18 +01:00
Andrew Turner f1e8b0ff4e bsd.cpu.mk: Add a workaround for erratum 843419
Add a workaround for the Arm Cortex-A53 erratum 843419. This has been
targeted when the build is either unoptimised for any CPU/architecture
or targets the Cortex-A53 or ARMv8.0 architecture.

PR:		296240
PR:		296395
Reported by:	Hal Murray <[email protected]>
Reported by:	Andreas Schuh <[email protected]>
Reviewed by:	cognet, mmel
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D58212
2026-07-14 16:47:15 +01:00
Andrew Turner 237c69a990 acpi_einj: Add acpi_if.h to SRCS
This is included via acpivar.h so needs to be in SRCS to be generated.

Reported by:	bz
Fixes:	bc49842769 ("acpi_einj: Support for ACPI error injection")
Sponsored by:	Arm Ltd
2026-07-08 07:13:43 +01:00
Andrew Turner cbef29bde7 arm64: Add an initial GICv5 IWB driver
Add a driver to support the GICv5 interrupt wire bridge (IWB). The IWB
translates the change in state of an input wire and sends a MSI to
the interrupt translation service (ITS) to be translated to an LPI.

Unlike other MSI sources each wire has a fixed Event ID value it will
write in the MSI data.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D54252
2026-06-18 15:56:53 +01:00
Andrew Turner 06d64ee0ec arm64: Add an initial GICv5 ITS driver
Add a driver to support the GICv5 interrupt translation service (ITS).
The ITS is responsible to handling ITS events & translating them to an
interrupt to be delivered to the interrupt routing service (IRS).

An example event is a MSI or MSI-X is delivered. The ITS will generate
an LPI depending on which device sent the interrupt and the value the
device wrote.

This is a similar concept to the GICv3 ITS, however the implementation
details are different so it needs a new driver.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D54251
2026-06-18 15:56:53 +01:00
Andrew Turner c84261da6f arm64: Add an initial GICv5 driver
Add an initial driver for the GICv5 interrupt controller.

This provides host-only support for the GICv5 interrupt controller. It
is specified in the ARM-AES-0070 document & based on version 00eac0.

In the GICv5 there are 3 interrupt spaces: PPI, SPI, and LPI. Unlike
previous interrupt controllers they don't share a single interrupt
ID range, so PPI IRQ 1 and SPI IRQ 1 are different interrupts. There
is a common irqsrc stricture that encodes this information as it is
common across the interrupt types.

Unlike previous GIC versions there are no software generated interrupts
that can target a configurable collection of CPUs. These have been
replaced with LPIs, where each CPU will have one allocated for each
IPI type.

This driver handles the CPU interface and interrupt routing service
(IRS). The CPU interface provides the interface to manage and handle
interrupts, while the IRS handles routing LPIs and SPIs to the target
CPU.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D54250
2026-06-18 15:56:53 +01:00
Andrew Turner cd94485281 arm64: Add FEAT_ALWAYS_ENABLE to cpu_feat
A use for it has been found in the GICv5 driver where we need to read
the Interrupt Affinity ID early in the boot on the secondary CPUs.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D54249
2026-06-18 15:56:53 +01:00
Andrew Turner a9e12d3ec8 arm64: Support building sys/sysl instructions
Add support to build system instructions from a macro. These are based
on the existing support for msr/mrs instructions with adjustments for
the different instruction format.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D57017
2026-06-18 15:56:52 +01:00
Andrew Turner 9c0a62df50 arm64: Workaround the following errata
- ARM C1-Premium erratum 4193780
 - ARM C1-Ultra erratum 4193780
 - ARM Cortex-A76 erratum 4193800
 - ARM Cortex-A76AE erratum 4193801
 - ARM Cortex-A77 erratum 4193798
 - ARM Cortex-A78 erratum 4193791
 - ARM Cortex-A78AE erratum 4193793
 - ARM Cortex-A78C erratum 4193794
 - ARM Cortex-A710 erratum 4193788
 - ARM Cortex-X1 erratum 4193791
 - ARM Cortex-X1C erratum 4193792
 - ARM Cortex-X2 erratum 4193788
 - ARM Cortex-X3 erratum 4193786
 - ARM Cortex-X4 erratum 4118414
 - ARM Cortex-X925 erratum 4193781
 - ARM Neoverse-N1 erratum 4193800
 - ARM Neoverse-N2 erratum 4193789
 - ARM Neoverse-V1 erratum 4193790
 - ARM Neoverse-V2 erratum 4193787
 - ARM Neoverse-V3 erratum 4193784
 - ARM Neoverse-V3AE erratum 4193784

These are all variants on an erratum where TLBI+DSB instructions on
one CPU may incorrectly complete early leading to stores to an updated
address using an incorrect translation on another CPU.

In all cases the workaround is to add a second TLBI+DSB.

Approved by:	so
Security:	FreeBSD-SA-26:31.arm64
Security:	CVE-2025-10263
Sponsored by:	Arm Ltd
2026-06-09 19:13:21 +00:00
Andrew Turner f6911b941f sys: Renumber MTE SEGV codes
Some third party software expects these to not conflict. As the MTE
support isn't fully in the tree, and these values aren't in a release
we can renumber them without any backwards compatibility issues.

Sponsored by:	Arm Ltd
2026-05-29 17:06:14 +01:00
Andrew Turner d63a62fb35 arm64: Add support for per-page flags
We need to store some extra information about a page, e.g. the state of
the MTE tags. Add a MD flags field to each page.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D55953
2026-05-27 16:22:25 +01:00
Andrew Turner 5cb511e627 arm64: Check for MTE tag failures on kernel entry
When entering the kernel from userspace we need to check for MTE tag
failures when using asynchronous MTE. This is done by checking if either
tag fault check types that have asynchronous checks are enabled, and
if so check the register the result is stored. It then sets a flag the
kernel can later use to raise a signal.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D55952
2026-05-27 16:22:25 +01:00
Andrew Turner 5a6ae4230b arm64: Manage the MTE state like pointer auth
Add the same group of functions we use to manage pointer authentication
in userspace threads.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D55951
2026-05-27 16:22:25 +01:00
Andrew Turner a780d21eab arm64: Support changing the DMAP memory type
When MTE is enabled we will use the DMAP to manage tags. To be able to
read/write them we need to change the memory attribute to
VM_MEMATTR_TAGGED.

Support changing the DMAP memory type to values known to have
equivalent cache properties.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D55949
2026-05-27 16:22:25 +01:00
Andrew Turner 48da01ad0b arm64: Add a comment about HWCAP values
They must be identical to Linux. Document this requirement to allow
userspace to depend on this.

Sponsored by:	Arm Ltd
2026-05-27 16:22:25 +01:00
Andrew Turner b8606c3406 arm64: Fix the includes for rsi.c
This depended on header pollution only present when FDT is defined. As
FDT isn't check for in this file we can remove opt_platform.h and
include the correct set of vm header files.

Reported by:	ivy
Fixes:	76a2904c35 ("arm64: Add RSI detection for CCA")
Sponsored by:	Arm Ltd
2026-05-14 10:25:14 +01:00
Andrew Turner dc00f11840 Revert "virtio_net: Use bus_dma for rxq/txq buffers"
This reverts commit c16c95192f.

Revert until we can fix reported issues
2026-05-05 10:18:14 +01:00
Andrew Turner c8167ebb74 Revert "virtio_net: Use bus_dma for command/ack buffers"
This reverts commit b5bad6df46.

Revert until we can fix reported issues
2026-05-05 10:18:14 +01:00
Andrew Turner 2783fb7e73 arm64: Fix a MTE check
It should be for FEAT_MTE2 as the registers aren't implemented for
FEAT_MTE.

While here fix the style of the comment explaining the check.

Reported by:	markj
Fixes:		58de791536 ("arm64: mte: configure initial state for system registers")
Sponsored by:	Arm Ltd
2026-04-29 12:39:29 +01:00
Andrew Turner 01ff0fa77d arm64: Support some per-thread sctlr_el1 fields
This will be used to enable MTE from userspace.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D55950
2026-04-29 12:34:39 +01:00
Andrew Turner 04e4268f60 arm64: Remove cpu_tlb_flushID now it's unused
Reviewed by:	alc
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D52185
2026-04-27 12:37:54 +01:00
Andrew Turner 4bdbb6f7f7 arm64: Stop using cpu_tlb_flushID in kexec
It will be removed soon & replaces with pmap_s1_invalidate_all_kernel.
This allows us to handle errata that cpu_tlb_flushID is missing
workarounds for.

Sponsored by:	Arm Ltd
2026-04-27 12:37:54 +01:00
Andrew Turner e63eee84ca libgcc_s: Add a linker script to link to libgcc
When using outline atomics on arm64 the compiler will create a call to
a function that performs the atomic operation. This allows us to use
the fastest operation depending on the hardware.

As these functions are implemented in libgcc create a linker script
so libraries that link against libgcc_s will include libgcc to pull
them in.

Reviewed by:	imp, jhb
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D45268
2026-04-27 12:37:53 +01:00
Andrew Turner 5809584275 arm64: Handle changing self-referential DMAP pages
Support changing the property of a DMAP page that holds it's own page
table entry.

Because we need to perform a break-before-make sequence to change the
properties of pages a page that also holds it's own page table entry
will fault in the make part of the sequence.

Handle this by mapping the page with a temporary mapping as we already
do when demoting a superpage.

Reviewed by:	kib
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D55943
2026-04-13 15:23:05 +01:00
Andrew Turner c208439cdb arm64: Add a cmap page to pmap
When modifying mappings in pmap we may need to perform a
break-before-make sequence. This creates an invalid mapping, then
recreates it with the changes.

When modifying DMAP mappings we may be changing the mapping that
contains its own page table then after breaking the old entry we are
unable to create the new entry.

To fix this create a map that can be used & won't be affected by the
break-before-make sequence.

Reviewed by:	kib
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D56306
2026-04-13 15:23:05 +01:00
Andrew Turner 0ddaa4c86d arm64: Add arm64 SVE tests
Add the tests/sys/arch directory for architecture-specific tests and
use it to add arm64 SVE tests. These test the kernel is managing the
SVE state in a way we expect.

These tests require SVE hardware support to run so will skip when they
can't detect it.

Reviewed by:	markj
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D43311
2026-04-08 15:20:52 +01:00
Andrew Turner 14e97448fc arm64: Have a common call to userret
Rather than each exception calling userret use a common copy. As
syscallret already calls userret we need to skip it in that case.

Reviewed by:	kib
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D55250
2026-03-17 17:10:40 +00:00
Andrew Turner 522012c8bd Revert "virtio: Restore mb() calls"
This reverts commit d99e725c26.
2026-03-10 19:09:41 +00:00
Andrew Turner d99e725c26 virtio: Restore mb() calls
Until an issue seen on amd64 can be investigated restore two mb() calls
to virtio.

Reviewed by:	andrew
Fixes:	c499ad6f99 ("virtio: Use bus_dma for ring and indirect buffer allocations")
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D55766
2026-03-10 19:08:38 +00:00
Andrew Turner 80b4129bef arm64: Optimise the repeated TLBI workaround
It has been reported that the overhead of repeating all TLBI
instructions is too large [1]. The Software Developer Errata Notices
(SDEN) for the relevant Arm CPUs have been updated so a single
"tlbi vale1is, xzr" followed by "dsb ish"  is sufficient to work around
the issues.

Replace the places we repeat TLBI instructions with the new sequence.

[1] https://lore.kernel.org/linux-arm-kernel/[email protected]/

Reviewed by:	kib
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D55646
2026-03-05 15:13:30 +00:00
Andrew Turner 570b8b2575 arm64: Use a canonical address when TBI is enabled
When Top Byte Ignore (TBI) is enabled in a processor we need to pass
a canonical address to the vm subsystem.

Reviewed by:	alc, kib
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D55619
2026-03-05 15:13:30 +00:00
Andrew Turner d1650d2262 arm64/vmm: Support PMU v3p9
The only new register is read-only. As the kernel just passes the
registers to the guest directly no further change should be needed.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D51764
2026-03-04 17:10:52 +00:00
Andrew Turner 3a960425df arm64: Add more HWCAP values
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D55219
2026-02-18 15:56:46 +00:00
Andrew Turner f4d1a3ab02 arm64: Fix the ESR_ELx_EC_MASK definition
Sponsored by:	Arm Ltd
2026-02-18 15:15:41 +00:00
Andrew Turner bfb7c81f93 nvmecontrol: Remove an incorrect use of PAGE_SIZE
The mdts value is in terms of the nvme page size, not the host page
size. On many architectures these are both 4k, however on arm64 it is
possible to build a system with the host page size of 16k.

Use NVME_MPS_SHIFT to get the correct nvme page shift.

Reviewed by:	imp
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D55334
2026-02-18 15:15:41 +00:00
Andrew Turner a6ad3d4ca0 CODEOWNERS: Add myself for sys/arm64/vmm
Sponsored by:	Arm Ltd
2026-02-18 15:15:41 +00:00
Andrew Turner 1ea0721e1a vtgpu: Support virtio gpu on Parallels Desktop
The Parallels Desktop Virtio GPU implementation doesn't handle
enqueuing the VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING request and
memory list together.

Work around this by splitting them before sending them to be enqueued.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D55147
2026-02-10 17:06:31 +00:00
Andrew Turner 1c41e411b5 arm64: Have get_kernel_reg return void
It now panics when it's unable to find the register, so doesn't need
to return a status.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D55106
2026-02-09 17:24:28 +00:00
Andrew Turner a8c3933840 arm64: Assume get_kernel_reg returns true
It now only returns true so this can be assumed and doesn't need to be
checked.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D55105
2026-02-09 17:24:27 +00:00
Andrew Turner 3b0b6aa2cd arm64: Panic if the ID register isn't known
This will allow for callers to be simplified & not need to check the
return status.

Keep the return type for now so this can be MFCd without breaking the
KBI.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D55104
2026-02-09 17:24:27 +00:00
Andrew Turner 0ea31fe851 arm64: Move creating the ID register views earlier
These are needed when enabling CPU features so should be processed
earlier in the boot.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D55103
2026-02-09 17:24:26 +00:00
Andrew Turner c12d6cc326 arm64: Attach the vgic even if there is no ITS
If there is no ITS device so no memory resources the gicv3 driver would
exit attaching early. This caused the vgic driver to also not be
attached, even if it could.

Reported by:	novel@
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D54791
2026-01-21 17:25:04 +00:00
Andrew Turner a4f0e93c51 arm64/vmm: Set and use the fine-grained traps
Set the Fine-grained trap registers to trap any features we don't
support. These are expected to be more useful when we support nested
virtualisation, so for now just the base features and GICv3 are not
trapped.

As nested virtualisation will require VHE we only set the fine-grained
trap registers when VHE is used.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D54687
2026-02-03 17:14:44 +00:00
Andrew Turner 095a7871f4 arm64/vmm: Add HYP_FEAT_FGT{,2}
Add the macros and detection for Fine-grained traps (FEAT_FGT and
FEAT_FGT2).

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D54686
2026-02-03 17:14:26 +00:00
Andrew Turner 4f82ce5191 arm64: Add the Fine-Grained Trap registers
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D54685
2026-02-03 17:14:03 +00:00
Andrew Turner 2f3f5055e7 virtio_p9fs: Use VIRTIO_SIMPLE_PNPINFO
This allows us to also use the common VIRTIO_SIMPLE_PROBE and to have
devmatch load the driver when detected.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D54684
2026-02-03 17:13:35 +00:00
Andrew Turner 32d1f18865 libc/aarch64: Add memset for a 64 byte dc zva
On arm64 we can use the "dc zva" instruction to zero memory. The CPU
tells software if the instruction is implemented, and if so the size
and alignment it will use.

When the size is 64-bytes the Arm Optimized Routines implementation of
memset can use dc zva to zero memory, and has a build flag to skip
checking.

Use this flag to build a version of memset that will be used when this
assumption is true.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D54776
2026-02-03 17:11:51 +00:00
Andrew Turner f0516ed465 libc/aarch64: Split out the MOPS functions
This allows static binaries to only include the functions they
reference.

Reviewed by:	imp
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D54775
2026-02-03 17:11:50 +00:00
Andrew Turner 00f6839213 libc/aarch64: Add a Makefile.inc dependency
If we update Makefile.inc it may be to change the contents of these
files.

Reviewed by:	imp
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D54774
2026-02-03 17:11:50 +00:00
Andrew Turner 6c5fdba45a arm/gic: Detect broken configurations
Some virtualization platforms provide broken configurations. There
is a GIC interrupt controller, however accessing the CPU interface
registers leads to an external data abort. As these are needed to
handle interrupts we are unable to boot further.

Detect this misconfiguration and panic to tell the user the issue.

Reviewed by:	emaste
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D54832
2026-01-23 17:02:29 +00:00
Andrew Turner fb96702a03 depend-cleanup.sh: Clean up the old arm64 memset.S
This has moved from a generated file in objdir to the source tree.
Remove the old file and any .depend files that reference it.

Reviewed by:	bapt (via IRC)
Fixes:	41ccf82b29 ("libc/aarch64: Use MOPS implementations of memcpy/memmove/memset where availble")
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D54729
2026-01-15 15:05:28 +00:00
Andrew Turner a9e77eb701 arm64: Correctly align the SVE signal context
The SVE signal context needs to be correctly aligned. Fix this by
creating a new macro to calculate the needed size to provide this
alignment, and use it when setting and checking the saved SVE signal
context.

Reported by:	cperciva
Reviewed by:	cperciva, markj
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D54396
2026-01-06 10:36:37 +00:00
Andrew Turner 7446569bbc conf: Mark vchiq as depending on fdt
Fix an ACPI only kernel by only building the vchiq files when FDT is
enabled.

Fixes:	745c4aa5e8 ("Make BRCM2837 port conform FreeBSD/ARM64 guidelines")
Sponsored by:	Arm Ltd
2025-11-18 18:00:33 +00:00
Andrew Turner a695ac2ce8 arm64: Move intr_pic_init_secondary earlier
This may have been called after intr_irq_shuffle. For most interrupt
controllers this appears to be safe, however for the GICv5 we need to
read a per-CPU ID register before we can assign interrupts to a given
CPU.

Fix the race by moving intr_pic_init_secondary earlier in the boot,
after devices have been enumerated and before the interrupts are moved
to their assigned CPUs.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D53685
2025-11-18 18:00:32 +00:00
Andrew Turner 2188e77bfd arm64: Remove gicv3_get_support_lpis
It's no longer used after moving to gic_get_support_lpis.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D53665
2025-11-18 18:00:32 +00:00
Andrew Turner 3ef673e98a arm64: Switch to gic_get_support_lpis in gicv3_its
The old gicv3_get_support_lpis will be removed.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D53664
2025-11-18 18:00:32 +00:00
Andrew Turner 8178a4e3c1 arm/gic: Make GICV3_IVAR_SUPPORT_LPIS generic
GICv5 will need this too, so move to the GIC_IVAR namespace.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D53663
2025-11-18 18:00:31 +00:00
Andrew Turner 262fadda37 arm: Handle GIC_IVAR_VGIC in the gic driver
We don't have a GICv2 vgic so can just return 0.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D53662
2025-11-18 18:00:31 +00:00
Andrew Turner 4713f54013 arm64: Add non-PCI MSI support
Add the arm64 parts to support for non-PCI MSI and MSI-X interrupts.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D53331
2025-11-18 18:00:30 +00:00
Andrew Turner 68e6422c6c dev/fdt: Add support for non-PCI MSI interrupts
Some non-PCI devices can send interrupts, e.g. the Arm SMMU or GICv5
Interrupt Wire Bridge. Add support for these by implementing pci_get_id
and pci_alloc_msi and the MSI/MSI-X parts of the PCIB interface.

Only the MSI parts of the PCI interface are added as that is all I am
able to test.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D53330
2025-11-18 18:00:30 +00:00
Andrew Turner 6b12b94c8f dev/ofw: Teach ofw_cpu to find the pcpu on arm64
Use the midr value to ensure we find the correct PCPU pointer on arm64.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D53327
2025-11-18 18:00:29 +00:00
Andrew Turner d539f2d9d2 dev/ofw: Register the ofw_cpu xref
This allows it to be referenced by other devices.

Reviewed by:	jhibbits
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D53329
2025-10-27 11:36:18 +00:00
Andrew Turner 87cea227e1 dev/ofw: Move ofw_cpu earlier
Move ofw_cpu to BUS_PASS_CPU + BUS_PASS_ORDER_MIDDLE so it can be used
by other devices.

Reviewed by:	jhibbits
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D53328
2025-10-27 11:36:18 +00:00
Andrew Turner 95a5bfcee0 arm64: Use _armreg.h in cpu.h
We only needed armreg.h for the *_SPECIALREG macros. Use the new
_armreg.h directly.

Reviewed by:	emaste
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D53325
2025-10-27 11:36:17 +00:00
Andrew Turner b57a571a00 arm64: Split out accessing special registers
We shouldn't need to include armreg.h just to access special registers
that are not defined in this file. Split out the parts that should be
common with arm64.h and hypervisor.h.

Reviewed by:	emaste
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D53324
2025-10-27 11:36:17 +00:00
Andrew Turner f3ee178be2 arm64: Remove armreg.h from db_machdep.h
There is nothing in this file that needs armreg.h

Reviewed by:	imp
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D53323
2025-10-27 11:36:17 +00:00
Andrew Turner aa22b68ec7 arm64: Include armreg.h in db_disasm.c
It is needed for INSN_SIZE. Include it directly rather than depending
on header pollution.

Reviewed by:	imp
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D53322
2025-10-27 11:36:17 +00:00
Andrew Turner fddf48eb01 arm64/vmm: Remove armreg.h when not needed
Reviewed by:	imp
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D53321
2025-10-27 11:36:17 +00:00
Andrew Turner b157c28ce9 modules/dtb: Add the ARM dtb module
fvp-base-revc.dtb works with the kernel now interrupt-maps are
supported in more cases.

Reviewed by:	mhorne
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D51258
2025-10-23 11:47:05 +01:00
Andrew Turner 82778970ee share/mk: Add opencsd to the list of private libs
Reported by:	Sarah Walker <[email protected]>
Reviewed by:	emaste
Fixes:	1c52229528 ("lib: Move libopencsd to /usr/lib and make private")
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D53217
2025-10-23 11:47:05 +01:00
Andrew Turner edbbf26e26 pci/n1sdp: Disable HotPlug
Work around an issue when HotPlug is enabled where pcib3 and pcib5
continuously report the following:

pcib3: HotPlug interrupt: 0x30
pcib3: Command Completed
pcib3: HotPlug interrupt: 0x30
pcib3: Command Completed
...

As a workaround disable HotPlug on the N1SDP as it's unlikely anyone
will depend on it.

Reviewed by:	br
Fixes:	1f5c50a861 ("pci_host_generic:Add pcib_request_feature on ACPI")
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D53134
2025-10-17 16:02:19 +01:00
Andrew Turner 534aec0097 arm64/vmm: Handle debug exits
This is enough to boot FreeBSD again.

PR:		290044
Reported by:	Siva Mahadevan <[email protected]>
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D52931
2025-10-07 09:27:15 +01:00
Andrew Turner fa975e2a5b arm64: Add Debug OS Lock fields
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D52930
2025-10-07 09:25:25 +01:00