Commit Graph

2255 Commits

Author SHA1 Message Date
Mykola Hohsadze
ffa75b573f arm64/disassem.c: Add shifted register instruction definitions
Add disassembly support for the following shifted register instructions:
 * adds
 * subs
 * sub
 * neg
 * negs
 * cmp
 * cmn

The 'Mandatory Tokens' checks are relaxed to allow for the alias
instructions (e.g. cmp) which hard-code one or more registers as xzr.

Reviewed by:	mhorne
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D40006
2023-05-25 14:06:15 -03:00
Mykola Hohsadze
8a852d3e9f arm64/disassem.c: Make output lowercase
Update the few uppercase fields fields to be consistent with others.

Reviewed by:	mhorne
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D39820
2023-05-25 14:06:15 -03:00
Andrew Turner
8b709c88e5 Add brackets around GICv3 redistributor macros
The GICv3 redistributor register access macros take arguments that are
used as variables. Add brackets around them as is the style, and for
safety.

Sponsored by:	Arm Ltd
2023-05-25 09:50:34 +01:00
Andrew Turner
fa512fcd8f arm64: Print the spinlock count on panic
When the spinlock count is non-zero while taking a data abort we panic.
Print this count to help debugging.

Sponsored by:	Arm Ltd
2023-05-24 17:20:06 +01:00
Andrew Turner
0731b0a9f1 Print registers on an arm64 spinlock data abort
When checking if the spinlock count is correct in a data abort we can
panic without printing the registers. These are useful to debug the
abort, e.g. by giving the fault address register.

Reviewed by:	kib
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D40228
2023-05-24 17:20:06 +01:00
Andrew Turner
b81e1c6b72 Don't print leading 0's in the arm64 esr
We don't print leading zeros for other registers, so do the same with
ESR_EL1.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D40129
2023-05-24 17:20:06 +01:00
Andrew Turner
800b39cf99 arm64: Remove CNTHCTL_EL2 from arm64.h
It is also in hypervisor.h where it belongs.

Sponsored by:	Arm Ltd
2023-05-24 17:20:05 +01:00
Andrew Turner
255adf35c0 Export arm64 VFP handling functions
These will be used by bhyve to manage the host VFP registers, e.g.
saving the host state before entering a guest.

Reviewed by:	markj
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D40130
2023-05-24 11:55:38 +01:00
Andrew Turner
419f8fc7fb Add more arm64 special registers
These will be used by bhyve

Reviewed by:	markj
Sponsored by:	Arm Ltd
Sponsored by:	Innovate UK
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40128
2023-05-24 11:55:38 +01:00
Zachary Leaf
012ea67d2d arm64 pmap: introduce PHYS_TO_PTE macro
Introduce macro for PHYS_TO_PTE, setting the groundwork for future
support of various Arm VMSA extensions.

For extensions such as 52-bit VA/PA (FEAT_LPA2), the representation of
an address between a PTE and PA are not equivalent. This macro will
allow converting between the different representations.

Currently PHYS_TO_PTE is a NOP. Replace all instances where we go from
PA to PTE with new PHYS_TO_PTE macro.

Reviewed by:	markj
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D39828
2023-05-24 11:55:38 +01:00
Zachary Leaf
0f54e49d4b arm64 pmap: introduce PTE_TO_PHYS macro
Introduce macro for PTE_TO_PHYS, setting the groundwork for future
support of various Arm VMSA extensions.

For extensions such as 52-bit VA/PA (FEAT_LPA2), the representation of
an address between a PTE and PA are not equivalent. This macro will
allow converting between the different representations.

Currently going from PTE to PA is achieved by masking off the upper and
lower attributes. Retain this behaviour but replace all instances with
the new macro instead.

Reviewed by:	alc, markj
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D39827
2023-05-24 11:55:38 +01:00
Christos Margiolis
136b8bd610 arm64: use PSR_DAIF instead of each individual flag
No functional change intended.

Reviewed by:	mhorne, andrew
Approved by:	markj (mentor)
Differential Revision:	https://reviews.freebsd.org/D40165
2023-05-22 22:49:33 +03:00
Kyle Evans
172af24449 arm64: gicv3: setup PPIs on all APs after they're online
For all PPIs setup earlier than SI_SUB_SMP, PIC_INIT_SECONDARY ends up
cleaning these up for each AP as it comes online.  Once they're online,
we don't currently do anything to make sure they're configured for other
APs.  Fix it by using smp_rendezvous for the meaty bits of configuring a
PPI, which will just do single-thread behavior before APs are online but
do the right thing for other CPUs after.

While we're here, make sure redistributor config is correct for other
APs as they come online in gic_v3_init_secondary.

Reported/Tested by:	Souradeep Chakrabarti (Microsoft/Hyper-V)
Reviewed by:		andrew (before slight refactor)
Differential Revision:	https://reviews.freebsd.org/D40112
2023-05-22 10:23:53 -05:00
Dmitry Chagin
3d0addcd35 linux(4): Make ptrace_pokeusr machine dependent
Differential Revision:	https://reviews.freebsd.org/D40096
MFC after:		1 week
2023-05-18 20:01:12 +03:00
Dmitry Chagin
dd2a6cd701 linux(4): Make ptrace_peekusr machine dependend
And partially implement it for x86_64.

Differential Revision:	https://reviews.freebsd.org/D40095
MFC after:		1 week
2023-05-18 20:00:12 +03:00
Andrew Turner
37c1ef5ac0 Move the arm64 sigcode to .rodata
The kernel doesn't execute this code, it's only ever copied to
userspace. Move it to .rodata as we don't need to modify it.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D39399
2023-05-17 12:28:45 +01:00
Kyle Evans
b68588618b arm64: simplify expression
!a != !b -> a != b; this part was lifted from NetBSD, and I clearly did
not reconsider that these are bools (I'm guessing they were ints in an
earlier iteration of the NetBSD implementation).

while we're here, it should be easy to see that we've covered all of the
cases but let's add in an __assert_unreachable() to make it easier on
the eyes.

Reported by:	jrtc27
2023-05-15 10:54:15 -05:00
Kyle Evans
4b500174dd arm64: emulate swp/swpb instructions
Add another undefined instruction handler for compat32 and watch out for
SWP/SWPB instructions.

SWP/SWPB were deprecated in ARMv6 and declared obsolete in ARMv7, but
this implementation is motivated by some proprietary software that still
uses SWP/SWPB. Because it's deprecated, emulation is pushed back behind
a sysctl that defaults to OFF in GENERIC so that it doesn't potentially
adversely affect package builds; it's unknown whether software may test
for a functional swp/swpb instruction with the desire of using it later,
so we err on the side of caution to ensure we don't end up with swp/swpb
use in freebsd/arm packages (which are built on aarch64).

The EMUL_SWP config option may be used to enable emulation by default in
environments where emulation is desired and won't really be turned off.

Reviewed by:	andrew, mmel (both earlier version)
Sponsored by:   Stormshield
Sponsored by:   Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D39667
2023-05-15 10:42:10 -05:00
Dmitry Chagin
d957343f87 linux(4): Rework signal trampoline on Aarch64
To avoid clobbering of any registers by the trampoline code use Linux
way to call signal handlers. I.e., we are out from the kernel right into
the signal handler, put return address from the signal handler into the
link register.
The mysterious NOP is required for some unwinders (e.g. libc++) that
unconditionally subtract one from the result of _Unwind_GetIP() in order
to identify the calling function.

MFC after:		1 week
2023-05-15 00:27:31 +03:00
Dmitry Chagin
5f19e18b64 linux(4): Get rid of linux_vdso_sigcode
MFC after:		1 week
2023-05-15 00:26:24 +03:00
Dmitry Chagin
2cdeb89e57 linux(4): Fix stack unwinding on arm64 [2/2]
To allow unwinders to go througth a previous to sigreturn frame we should
properly emulate the trampoline frame record which should points to the
previous frame and set the trampoline frame pointer to the emulated frame
before calling signal handler.

MFC after:		1 week
2023-05-15 00:25:57 +03:00
Dmitry Chagin
bf3a14b41a linux(4): Fix stack unwinding on arm64 [1/2]
An Aarch64 sigreturn trampoline frame can't currently be described in
a DWARF .eh_frame section, because Aarch64 does not define a register
number for PC and provide no direct way to encode PC of the previous
frame. Instead, unwinders (libgcc, gdb, libunwind) detect the sigreturn
frame by looking for the sigreturn instruction. If a sigreturn frame is
detected, unwinders restores all the gprs, SP and PC by assuming that
sp points to an rt_sigframe Linux kernel struct
When entering the kernel, the link register (lr) contains the return
address of the previous frame, the exception link register (elr) contains
the address of the next instruction after the one which generated the
exception, i.e., PC.

MFC after:		1 week
2023-05-15 00:24:57 +03:00
Warner Losh
4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:03 -06:00
Gordon Bergling
cbe88c6f3c arm64: Fix a typo in a source code comment
- s/inferface/interface/

MFC after: 3 days
2023-05-12 10:45:46 +02:00
Kyle Evans
86c31aca33 arm64: add swapueword8/32
Much like casueword*, except just a plain old swap.  Maintains a similar
interface to casu(9)- return value -1 (fault), 0 (success), or 1 (fail),
and also both ll/sc and LSE variants are implemented.

These will be used to implement 32-bit swp/swpb emulation on aarch64.

Reveiwed by:	andrew
Sponsored by:	Stormshield
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D39837
2023-05-11 13:23:14 -05:00
Zachary Leaf
2b8c4137d4 arm64: fix stack unwinding past exception handlers
Commit 281402e0a5 ("arm64: Shave off two instructions in exceptions")
removed the instruction that set the frame pointer (x29) as it appeared
to be unused.

The frame pointer is used in arm64/db_trace.c:db_stack_trace_cmd() when
unwinding state, and hence still needs to be set.

Add back the instruction to save_registers to properly update frame
pointer.

Reported by: andrew
Sponsored by: Arm Ltd
2023-05-10 12:54:54 +01:00
Mykola Hohsadze
9f60b8ce60 arm64/disassem.c: Add detection of xzr and sp
Added support to distinguish between XZR/WZR and SP/WSP registers.

Add new OP_ flags to indicate if the instruction allows the use of SP
for a given register field. "wSP" and "SP" are removed from w_reg and
x_reg, and helper functions are introduced for this purpose of detecting
the correct name of the x31 register.

mhorne: While here, adjust some whitespace issues from a previous
commit.

Reviewed by:	mhorne
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D39862
2023-05-08 10:59:35 -03:00
Mitchell Horne
aba91805aa hwpmc: use kstack_contains()
This existing helper function is preferable to the hand-rolled
calculation of the kstack bounds.

Make some small style improvements while here. Notably, rename every
instance of "r", the return address, to "ra". Tidy the includes in the
affected files.

Reviewed by:	jkoshy
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D39909
2023-05-06 14:49:19 -03:00
John Baldwin
afdb42987c ofw_cpu_early_foreach: Change callback to return bool instead of boolean_t.
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D39926
2023-05-04 12:33:39 -07:00
John Baldwin
4961faaacc pmap_{un}map_io_transient: Use bool instead of boolean_t.
Reviewed by:	imp, kib
Differential Revision:	https://reviews.freebsd.org/D39920
2023-05-04 12:29:48 -07:00
John Baldwin
407f675718 imgact_elf: Change header_supported to return bool instead of boolean_t.
Reviewed by:	imp, kib, emaste
Differential Revision:	https://reviews.freebsd.org/D39919
2023-05-04 12:29:29 -07:00
Andrew Turner
020edaea2a Split out pmap_map_delete on arm64
This will be used when supporting some extensions, e.g. Branch Target
Identification (BTI).

Sponsored by:	Arm Ltd
2023-04-28 11:54:19 +01:00
Dmitry Chagin
cd0fca82bb linux(4): Regen for mknod syscall changes 2023-04-28 11:55:04 +03:00
Dmitry Chagin
ca3333dd4a linux(4): Use Linux dev_t type for mknod syscalls dev argument
As of version 2.6.0 of the Linux kernel, dev_t is a 32-bit unsigned integer
on all platforms. Prior the 2.6 kernel dev_t type was an unsigned short.
However, since the firs commit of the Linuxulator, mknod syscall get int dev
argument.
Also, there is some confusion here, while the kernel declares a dev_t type
as a 32-bit sized, the user-space dev_t type can be size of 64 bits, e.g.,
in the Glibc library.
To avoid confusion and to help porting of the Linuxulator to other platforms
use explicit l_dev_t for dev argument of mknod syscalls.
2023-04-28 11:55:02 +03:00
Dmitry Chagin
19973638be linux(4): Move dev_t type declaration under /compat/linux
As of version 2.6.0 of the Linux kernel, dev_t is a 32-bit unsigned integer
on all platforms. Move it into the MI linux.h under /compat/linux.
2023-04-28 11:55:02 +03:00
Dmitry Chagin
e0bfe0d62c linux(4): Make struct newstat to match actual Linux one
In the struct stat the st_dev, st_rdev are unsigned long.
2023-04-28 11:55:01 +03:00
Elliott Mitchell
d7e3b05b0d arm: remove passing trapframe to intr_ipi_dispatch()
This was needed before INTRNG was in place and handling the push of
curthread->td_intr_frame.  Since INTRNG now handles this, there is no
longer and need for playing around with the frame inside IPI interrupts.
2023-04-26 20:08:30 +01:00
Elliott Mitchell
c7e5e9dc41 arm: remove interrupt nesting by ipi_preempt()/ipi_hardclock()
This was needed when intr_ipi_dispatch() was called by hardware-specific
IPI interrupt routines which didn't save the trap frame.  Now all ARM
interrupts pass through INTRNG which will have already saved the trap
frame and disabled preemption.

Remove the conditional trapframe/argument passing to the handlers.

Reviewed by: andrew
Differential Revision: https://reviews.freebsd.org/D37938
2023-04-26 20:08:30 +01:00
Andrew Turner
f8c451d291 Add vt_simplefb to the arm64 NOTES file
This will be picked up in the LINT-ACPI and LINT-FDT configs to check
it builds with only one option enabled

Sponsored by:	Arm Ltd
2023-04-26 14:11:36 +01:00
Andrew Turner
d5035d913c Add a simple-framebuffer vt driver
This allows us to support this hardware and, in the future, use clocks
so they are enabled past the initial kernel boot process.

Reviewed by:	ray
Differential Revision:	https://reviews.freebsd.org/D30103
2023-04-26 00:44:48 -05:00
Kyle Evans
61fd6a1ea2 Note that static hints no longer break loader hints
This commentary was carried over from the x86 version of the same code,
but has actually been inaccurate for a while now. As of FreeBSD 12.x,
all environments are used unless they disable each other. See
39d44f7f15 ("kern_environment: use any provided environments [...]")
for details.

Reviewed by:	imp
Differentiala Revision:	https://reviews.freebsd.org/D35695
2023-04-26 00:38:32 -05:00
Mykola Hohsadze
7edb7adf8c arm64/disassem.c: Add support str/strb/strh instructions
Added disassembly support for each type of str/strb/strh instruction
encoding.

Reviewed by:	mhorne
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D39336
2023-04-25 17:23:15 -03:00
Mykola Hohsadze
cb923f03fa arm64/disassem.c: Fix typo sxts to sxts and amount for TYPE_02
The current implementation is wrong, since it unconditionally sets the
amount equal to the <size> field of the instruction. However, when the
<S> bit (scale) is not set, it must be zero.

Also fix a typo, sxts to sxtx, according to the Arm64 documentation.

Reviewed by:	mhorne
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D39334
2023-04-25 17:23:15 -03:00
Mykola Hohsadze
5b61ad4b00 arm64/disassem.c: style and formatting
Reviewed by:	mhorne
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D38899
2023-04-25 17:23:15 -03:00
Andrew Turner
6a9c2e63be Add padding for future use on arm64
Allow new features to be supported without changing the size of
existing structures.

Reviewed by:	kib
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D39777
2023-04-25 10:23:15 +01:00
Andrew Turner
c3785c3eb0 Remove unneeded SMMU macros
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D39186
2023-04-24 12:48:01 +01:00
Andrew Turner
cdd34e0038 Remove virtual addresses from smmu_pmap_remove_pages
This function needs to unmap all memory in a given SMMU context. Have
it iterate over all page table entries to find what has been mapped
rather than looking at virtual addresses.

While here use SMMU specific macros.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D39185
2023-04-24 12:47:55 +01:00
Andrew Turner
b97e94d91e Move to a SMMU specific struct for the smmu pmap
This is not managed through the VM subsystem so only needs to hold the
data the SMMU driver needs.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D39184
2023-04-24 12:47:50 +01:00
Andrew Turner
49ee1a7ef0 Create a common function to get the SMMU sid
Now the PCI drivers have a common interface to read the IOMMU xref
and SID create a common function to read it. This fixes an issue where
we will call into an ACPI specific function when booting with FDT when
both are enabled.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D39183
2023-04-24 12:47:44 +01:00
Andrew Turner
117beba8a8 arm64: Clean up smmu fdt xref handling
Use the xref from OF_xref_from_node for the smmu xref. We already have
a valid xref ID, there is no need to convert this to a memory address.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D39181
2023-04-24 12:47:31 +01:00
Andrew Turner
078a69abcb Use a uint64_t to store the arm64 mpidr
Use a single uint64_t to hole the mpidr register as we can break the
KBI on 14. Keep the macro so code can still be MFCd to 13.

Sponsored by:	Arm Ltd
2023-04-24 12:33:50 +01:00
Andrew Turner
fb421e96c0 Make arm64 pcb padding explicit
There is padding between some fields. Mark those I have found so they
can be reused later if needed.

Sponsored by:	Arm Ltd
2023-04-24 12:33:50 +01:00
Andrew Turner
1bf4991bbc Remove unneeded masks from the arm64 KASAN shadow
When mapping the arm64 KASAN shadow map we use Ln_TABLE_MASK to align
physical addresses, however these should already be aligned either
by rounding to a greater alignment, or the VM subsystem is giving us
a correctly aligned page.

Remove these extra alignment masks.

Reviewed by:	kevans
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D39752
2023-04-24 12:33:50 +01:00
Mark Johnston
4b39a12830 arm64: Disable PAC when booting on a Windows Dev Kit 2023
It appears that PAC registers are configured to trap upon access, but
since the kernel starts in EL1 on this platform it has no ability to
inspect or modify this configuration.  Simply disable PAC on this
platform for now, since the kernel otherwise hangs during boot.

PR:		270472
Reviewed by:	andrew, emaste
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D39748
2023-04-23 13:55:57 -04:00
Mark Johnston
7623cc8f65 arm64: Implement bus_describe_intr() for nexus
Prompted by a compiler warning introduced by
e582d4a2b0 ("arm64: nexus code tidy-up").

Reviewed by:	mhorne, andrew
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D39749
2023-04-23 13:55:57 -04:00
Dmitry Chagin
56c5230afd linux(4): Fix LINUX_AT_COUNT comments
Differential Revision:	https://reviews.freebsd.org/D39645
MFC after:		1 month
2023-04-22 22:16:43 +03:00
Dmitry Chagin
7d8c983983 linux(4): Deduplicate linux_copyout_auxargs()
Export default MINSIGSTKSZ value for the x86 until we do not preserve AVX
registers in the signal context.

Differential Revision:	https://reviews.freebsd.org/D39644
MFC after:		1 month
2023-04-22 22:16:02 +03:00
Warner Losh
559b94a122 syscall.master: Fix comments
Have more accruate comments. While #if, #else, etc are copied to the
header files, lines that don't start with # are not.  And #include files
are only output to sysinc (which winds up at the front of init_sysent.c
which seems a bit odd). This is all radically undocumented, and likely
has drifted somewhat from 4.4BSD and what other systems do (they've
drifted too, fwiw).

Sponsored by:		Netflix
2023-04-20 16:18:02 -06:00
Konstantin Belousov
1e0e335b0f amd64: fix PKRU and swapout interaction
When vm_map_remove() is called from vm_swapout_map_deactivate_pages()
due to swapout, PKRU attributes for the removed range must be kept
intact.  Provide a variant of pmap_remove(), pmap_map_delete(), to
allow pmap to distinguish between real removes of the UVA mappings
and any other internal removes, e.g. swapout.

For non-amd64, pmap_map_delete() is stubbed by define to pmap_remove().

Reported by:	andrew
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D39556
2023-04-15 02:53:59 +03:00
Andrew Turner
421516f25e Create pmap_mask_set_locked on arm64
Create a locked version of pmap_mask_set. We will need this for BTI
support.

Sponsored by:	Arm Ltd
2023-04-12 13:10:13 +01:00
Ganbold Tsagaankhuu
37d97b10ff Fix style. 2023-04-07 03:18:42 +00:00
Ganbold Tsagaankhuu
4720afaffe Improve RK3568 pcie phy handling codes a bit.
Move phy bifurcation code to a separate function
that can be called during the attach phase.
Also initialize both pcie lanes accordingly.
2023-04-07 02:54:13 +00:00
Andrew Turner
04b4655997 Mark EENTRY as .text
To allow it to be used before ENTRY we need to ensure the symbol is
in the .text section. It also needs to be aligned correctly.

While here mark the symbol type as a function as in the ENTRY macro.

Reported by:	jrtc27
Sponsored by:	Arm Ltd
2023-04-06 16:50:54 +01:00
Dmitry Chagin
50111714f5 linux(4): Regen for close_range syscall
MFC after:		2 weeks
2023-04-04 23:23:37 +03:00
Dmitry Chagin
1c27dce1f8 linux(4): Modify close_range syscall to match Linux
MFC after:		2 weeks
2023-04-04 23:23:24 +03:00
Ganbold Tsagaankhuu
396b6914c9 Fix pcie phy enabling codes for RK3568 SoC.
Handle data-lanes property for pcie phy and set it accordingly.
This makes devices attached to pcie3 work properly.
For some RK3568 based boards, RTL8125B based device is
connected it. So with this, realtek-re-kmod driver attaches
and works.

Partially obtained from OpenBSD.
Tested on NanoPI-R5S, FireFly Station P2 boards.
2023-04-04 02:50:29 +00:00
Ganbold Tsagaankhuu
b98fbf3781 Fix driver name.
Submitted by:	Tyuryukanov S.Y.
2023-04-03 14:20:28 +00:00
Andrew Turner
41236539d8 Add non-posted device memory to the arm64 mem map
Add VM_MEMATTR_DEVICE_NP to the arm64 vm.pmap.kernel_maps sysctl.

Reviewed by:	markj
Sponsored by:	Arm Ltd
 Differential Revision:	https://reviews.freebsd.org/D39371
2023-04-03 12:59:11 +01:00
Alexander V. Chernikov
3091d980f5 netlink: add NETLINK to the DEFAULTS for each architecture
NETLINK is going to replace rtsock and a number of other ioctl/sysctl interfaces.
In-base utilies such as route(8), netstat(8) and soon ifconfig(8)
 are being converted to use netlink sockets as a transport between
 kernel and userland.
In the current configuration, it still possible have the kernel
 without NETLINK (`nooptions NETLINK`) and use the aforementioned
 utilies by buidling the world with `WITHOUT_NETLINK` src.conf knob.
However, this approach does not cover the cases when person unintentionally
 builds a custom kernel without netlink and tries to use the standard userland.

This change adds `option NETLINK` to the default options for each
 architecture, fixing the custom kernel issue.
For arm, this change uses `std.armv6` and `std.armv7` (netlink already in)
 instead of DEFAULTS.

Reviewed By: imp
Differential Revision: https://reviews.freebsd.org/D39339
2023-04-02 15:27:21 +00:00
Mitchell Horne
3462c371c2 arm64/gicv3: correct the size of the distributor resource
Use the GICD_SIZE macro (0x10000), which is half the size of the current
fixed-sized mapping (128 * 1024 == 0x20000).

In ARM64 Hyper-V instances, it seems the Distributor's registers are
located immediately preceding a range of physical memory in the bus
address space. Thus, when ram0 is attaching and attempts to reserve
SYS_RES_MEMORY resources corresponding to its physmem ranges, it fails,
because the first 0x10000 bytes of this range are already owned by gic0.

PR:		270415
Reported by:	whu
Tested by:	whu
Differential Revision:	https://reviews.freebsd.org/D39260
2023-03-31 13:26:22 -03:00
Mark Johnston
1a3cb489e5 arm64: Move the initial kernel stack out of the init_pagetables section
init_pagetables is mapped into the segment containing the BSS, but does
not get zeroed by locore.  It is used for bootstrap page table pages.

It happens that the bootstrap kernel stack is also placed in that
section, but there's no reason it shouldn't live in the BSS, so move it
there.  No functional change intended.

Reviewed by:	andrew
MFC after:	1 week
Sponsored by:	Klara, Inc.
Sponsored by:	Juniper Networks
Differential Revision:	https://reviews.freebsd.org/D39367
2023-03-31 11:57:26 -04:00
Andrew Turner
47ff149afa Move arm64 EENTRY uses before ENTRY
The ENTRY macro adds instructions to the start of a function but not
EENTRY. To use these instructions in both functions move the EENTRY
use before the ENTRY use.

Sponsored by:	Arm Ltd
2023-03-31 16:45:31 +01:00
Mark Johnston
a54370f4ab arm64: Ensure that thread0's PCB flags are initialized
On arm64, the PCB is stored at the top of the thread stack.  For thread0
this comes from the static "initstack" region, which is placed in the
.init_pagetable section, which is not part of the BSS and thus doesn't
get zeroed by locore.  (See the comment in ldscript.arm64.)  It is thus
possible for the pcb_flags field to be uninitialized, which can result
in PCB_SINGLE_STEP being set.

Fix this by simply initializing the field.  A separate commit will move
initstack out of the .init_pagetable section, since it has no reason to
be there, but it is preferable to explicitly initialize PCB fields
anyway.  In particular, regular kernel stacks are not zeroed upon
allocation, so we should be consistent here.

Reviewed by:	andrew
MFC after:	1 week
Sponsored by:	Klara, Inc.
Sponsored by:	Juniper Networks
Differential Revision:	https://reviews.freebsd.org/D39343
2023-03-31 09:50:34 -04:00
Andrew Turner
3a0cc6fe61 Handle the arm64 unknown exception separately
Rather than falling through to the default case handle the unknown
exception with its own panic message. As ESR_EL1 is zero for this
exception stop printing it.

Sponsored by:	Arm Ltd
2023-03-31 10:15:45 +01:00
Mark Johnston
ad2f2ee015 arm64: Remove duplicated function prototypes for PAC
No functional change intended.

Sponsored by:	The FreeBSD Foundation
2023-03-27 08:56:22 -04:00
Kyle Evans
ec1bc53002 arm64: cpu_switch: don't zero out pcb_onfault
Previously this would zero out x18 in the pcb, now it's attacking the
innocent pcb_onfault -- drop it entirely.

This technically fixes
e605b87a9e ("Save only callee-saved registers in pcb"), but it's
harmless until the below commit trims down pcb_x.

Reported by:	mmel
Reviewed by:	andrew, mmel
Fixes:	1c1f31a5e5 ("Remove unused registes from the arm pcb")
Differential Revision:	https://reviews.freebsd.org/D39277
2023-03-26 13:48:22 -05:00
Kyle Evans
89c52f9d59 arm64: add KASAN support
This entails:
- Marking some obvious candidates for __nosanitizeaddress
- Similar trap frame markings as amd64, for similar reasons
- Shadow map implementation

The shadow map implementation is roughly similar to what was done on
amd64, with some exceptions.  Attempting to use available space at
preinit_map_va + PMAP_PREINIT_MAPPING_SIZE (up to the end of that range,
as depicted in the physmap) results in odd failures, so we instead
search the physmap for free regions that we can carve out, fragmenting
the shadow map as necessary to try and fit as much as we need for the
initial kernel map.  pmap_bootstrap_san() is thus after
pmap_bootstrap(), which still included some technically reserved areas
of the memory map that needed to be included in the DMAP.

The odd failure noted above may be a bug, but I haven't investigated it
all that much.

Initial work by mhorne with additional fixes from kevans and markj.

Reviewed by:	andrew, markj
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D36701
2023-03-23 16:34:33 -05:00
Mitchell Horne
698dbd66fe arm64: add a GENERIC-KASAN config
Reviewed by:	andrew, markj
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D36702
2023-03-23 16:34:33 -05:00
Andrew Turner
6a4f5fdd19 Mark the arm64 PSR register fields with UL
These are for a 64 bit register. Make them 64 bit values on arm64.

Sponsored by:	Arm Ltd
2023-03-23 18:56:26 +00:00
Andrew Turner
1c1f31a5e5 Remove unused registes from the arm pcb
These were kept for ABI reasons. Remove them and bump __FreeBSD_version
so debuggers can be updated to use the new layout.

Reviewed by:	jhb
Sponsored by:	Arm Ltd
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D35378
2023-03-23 18:56:26 +00:00
Andrew Turner
4a06b28a15 Add compat support for struct reg on arm64
The size of the spsr field in struct reg has changed. Mask the bits
that userspace doesn't know about out as they may be invalid.

While here add a comment why we don't need compat support in set_regs.

Sponsored by:	Arm Ltd
2023-03-23 18:56:26 +00:00
Zachary Leaf
f4036a9234 arm64: add fault address to trapframe
It was previously possible for the fault address register to get
clobbered before it was saved. This small window occurred when an
additional exception was encountered inside the exception handler,
overwriting the previous value.

Commit f29942229d ("Read the arm64 far early in el0 exceptions")
patched this issue, but avoided changing the trapframe since this could
be considered a KBI change in FreeBSD 13.

Revert the above fix and save the fault address in the trapframe
instead. This saves the fault address even earlier in the exception
handling process, and is a more robust and simple fix.

Reviewed by:	andrew, jhb, jrtc27
Sponsored by: Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D38984
2023-03-23 18:56:26 +00:00
Zachary Leaf
2ecbbcc7ca arm64: extend ESR/SPSR registers to 64b
For the Exception Syndrome Register, ESR_ELx, the upper 32b were
previously unused, but now may contain additional exception info as of
Armv8.7 (FEAT_LS64).

Extend ESR from u32->u64 in exception handling code to support this. In
addition, also extend Saved Program Status Register SPSR_ELx in the same
way to allow for future extensions.

Reviewed by:	andrew
Sponsored by: Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D38983
2023-03-23 18:56:26 +00:00
Brooks Davis
3d2837f3bd arm64: Fix sig_atomic_t limit definitions
sig_atomic_t is defined as a long and thus is 64-bit on arm64.  For some
reason its limit was incorrectly specified as a 32-bit number.  This had
the unfortunate side effect of causing gnulib to override most of the
definitions in stdint.h.  On CheriBSD this breaks all software that uses
gnulib in annoying and hard to debug ways.

Technically updating the limits might be an ABI change, but these
defines are largely unused (the only use in tree is in the libc++ test
suite where it's use an assertion that will fail due to this bug).
Further, since the underlying type remains the same, we're just
increasing the range of values a paranoid program might use.

Reviewed by:	andrew, emaste
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D39193
2023-03-22 16:22:21 +00:00
Andrew Turner
787bf3bcd6 arm64: Use the new PCB macros in swtch.S
Rather than hard coding the location of these registers in the array
use the new macros to find the correct offset.

Sponsored by:	Arm Ltd
2023-03-22 15:08:03 +00:00
Andrew Turner
1c33a94ab0 Add macros for arm64 pcb register offsets
Add macros for offsets of macros we set in the arm64 pcb pcb_x array.
This will simplift reducing the size of this array in a later change.

Sponsored by:	Arm Ltd
2023-03-22 15:08:03 +00:00
Mitchell Horne
e582d4a2b0 arm64: nexus code tidy-up
Make a pass at the various nexus implementations, fixing some very minor
style issues, obsolete comments, etc.

The method declaration section has become unwieldy in many respects.
Attempt to tame it by:
 - Using generated method typedefs
 - Grouping methods roughly by category, and then alphabetically.

Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D38495
2023-03-20 17:35:47 -03:00
Dmitry Mikushin
ef9f49a21a arm64: Adding a missing include file
Adding a missing include file, which provides the definition of
SYSCTL_INT.

Reviewed by:	andrew
Differential Revision:	https://reviews.freebsd.org/D39149
2023-03-20 11:23:01 +00:00
Andrew Turner
a671f96d93 Mark arm64 mair_el1 fields as unsigned long
The register is 64-bit so the upper bits could be shifted past the
signed 32-bit size of an int the values were before.

Sponsored by:	Arm Ltd
2023-03-16 16:45:42 +00:00
Andrew Turner
3473f28322 Switch the arm64 VM_MEMATTR_DEVICE to nGnRE
Move device memory to a weaker type. The new device memory type allows
the system to acknowledge a write to a device before the write has
completed. This is inline with VM_MEMATTR_DEVICE on armv6/armv7.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D38945
2023-03-16 16:45:42 +00:00
Andrew Turner
f7acb7ed41 Allow forcing non-posted memory on arm64
To allow for debugging after changing the arm64 VM_MEMATTR_DEVICE
memory type add a new set of tunables to tell the kernel to use
non-posted memory.

This adds the following tunables:
 - kern.force_nonposted: When set to non-zero the kernel will use
   non-posted memory for all device allocations.
 - hint.<dev>.<unit>.force_nonposted: As above, however only forces
   non-posted memory on the named device.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D38944
2023-03-16 16:45:42 +00:00
Andrew Turner
bc10894757 Remove an unneeded CTASSERT in the smmu driver
We don't map the DMAP here

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D38951
2023-03-16 16:45:42 +00:00
Andrew Turner
9a5dddc94f Remove unneeded arm64 smmu macros
These aren't used by the driver so can be removed.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D38950
2023-03-16 16:45:42 +00:00
Andrew Turner
5f2070adb9 Only support a 4 level smmu page table
We only ever build a 4 level page table for the Arm SMMU. Remove the
support for a 3 level table.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D38949
2023-03-16 16:45:42 +00:00
Andrew Turner
83fb1bdbfe Rename smmu pmap functions
These are SMMU (and MALI GPU) specific. Give them a SMMU specific name.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D38948
2023-03-16 16:45:42 +00:00
Andrew Turner
cc67cd58fc arm64: Support stage 2 mappings in pmap_remove_all
This has been hit when testing bhyve.

Sponsored by:	Arm Ltd
2023-03-15 18:24:50 +00:00
Andrew Turner
51308cd29b Support the arm64 pmap_remove_write for stage 2
The fields we need to adjust are different in stage 1 and stage 2
tables. Handle this by adding variables to hold the bits to check,
set, and clear.

Reviewed by:	alc
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D37399
2023-03-15 15:49:00 +00:00
Mitchell Horne
8937bd37d0 arm64: limit EFI excluded regions to physical memory types
Consolidate add_efi_map_entry() and exclude_efi_map_entry() into a
single function, handle_efi_map_entry(), so that the exact set of entry
types handled is the same in the addition or exclusion cases. Before,
exclude_efi_map_entry() had a 'default' case that would exclude all
entry types that were not listed explicitly in the switch statement.

Logically, we do not need to exclude a range that could not possibly be
added to physmem, and we do not need to exclude bus ranges that are not
physical memory, for example EFI_MD_TYPE_IOMEM.

Since physmem's ram0 device will reserve bus memory resources for its
owned ranges, this was preventing attachment of the watchdog device on
the RPI4B. For some reason its region of memory-mapped I/O appeared in
the EFI memory map (with the aforementioned EFI_MD_TYPE_IOMEM type).
This change fixes the attachment issue, as we prevent the physmem API
from messing with this range of bus space.

PR:		270044
Reported by:	karels, Mark Millard
Reviewed by:	andrew, karels, imp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D39003
2023-03-15 12:28:35 -03:00
Andrew Turner
6419b48f7d Support arm64 stage2 TLB invalidation
To invalidate stage 2 mappings on arm64 we may need to call into the
hypervisor so add a function pointer that bhyve can use to implement
this.

Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D37254
2023-03-15 11:34:32 +00:00
Andrew Turner
ae60314c94 Fix the ofw parent check in arm64 nexus
OF_parent returns 0 for no parent. Fix the check in teh arm64
nexus_fdt_activate_resource.

Sponsored by:	Arm Ltd
2023-03-14 10:37:00 +00:00
Jessica Clarke
4f7b3120bc arm64: Delete redundant badly formatted and capitalised comment
Fixes:	9729f076e4 ("arm64: Hyper-V: enablement for ARM64 in Hyper-V (Part 3, final)")
2023-03-14 04:15:03 +00:00
Jessica Clarke
aa39abd8e5 arm64: Move Azure-specific config from std.hyperv to std.azure
Hyper-V does not provide Mellanox hardware, some of Azure's instances
do, thus the configuration to enable them does not belong in the generic
std.hyperv config.

Fixes:	15e7fa83ef ("arm64: Hyper-V: Add vPCI and Mellanox driver modules into build")
2023-03-14 04:12:31 +00:00
Wei Hu
15e7fa83ef arm64: Hyper-V: Add vPCI and Mellanox driver modules into build
These changes in conf and std.hyperv files got missed in previous commit.
Reviewed by:	whu
Tested by:	whu
Obtained from:	Souradeep Chakrabarti <schakrabarti@microsoft.com>
Sponsored by:	Microsoft
Differential Revision:	https://reviews.freebsd.org/D38529
2023-03-13 02:55:04 +00:00
Kyle Evans
1867702942 arm64: fix the LINT-ACPI build
This file uses VM_MEMATTR_DEVICE_NP, which it gets through header
pollution somewhere with FDT enabled.  Pull in vm/vm.h to make it
explicit.
2023-03-07 11:37:31 -06:00
Kyle Evans
d71a00e9f5 arm64: ofw: respect the nonposted-mmio prop in OF_decode_addr()
This is the only mapping remaining which needs to respect nonposted-mmio
to avoid breaking the boot on Apple silicon.

Reviewed by:	andrew
Differential Revision:	https://reviews.freebsd.org/D38920
2023-03-07 00:15:32 -06:00
Andrew Turner
5a91529479 Support non-posted MMIO on arm64 with FDT
To allow hardware to work around a broken memory bus where we need to
support the nonposted-mmio flag.

Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D34333
2023-03-05 20:17:21 +00:00
Andrew Turner
cb894f746c Map arm64 pci config memory as non-posted
On arm64 PCI config memory is expected to be mapped with a non-posted
device type. To handle this use the new bus_map_resource support in
arm64 to map memory with the new VM_MEMATTR_DEVICE_NP attribute. This
memory has already been allocated and activated, it just needs to be
mapped.

Reviewed by:	kevans, mmel
Differential Revision:	https://reviews.freebsd.org/D30079
2023-03-05 20:17:21 +00:00
Dmitry Chagin
cabbfb60d0 linux(4): Reduce code duplication between MD files
Move struct ifnet definitions under compat/linux.

Reviewed by:		emaste
Differential Revision:	https://reviews.freebsd.org/D38791
2023-03-04 12:11:38 +03:00
Kyle Evans
d2ae03bae2 arm64: disable the physical timer for now if HCR_EL2.E2H is set
On some hardware, we can't clear HCR_EL2.E2H so accesses to the physical
timer hopelessly trap to EL2.  Stash off the value of HCR_EL2 and use it
in has_hyp() to avoid this.

Reviewed by:	andrew
Differential Revision:	https://reviews.freebsd.org/D38884
2023-03-03 11:02:34 -06:00
John-Mark Gurney
2fee875629
abstract out the vm detection via smbios..
This makes the detection of VMs common between platforms that
have SMBios.

Reviewed by:		imp, kib
Differential Revision:	https://reviews.freebsd.org/D38800
2023-03-02 16:54:21 -08:00
John Baldwin
d90188eff5 hwpmc: Don't wrap entire files in #ifdef DEV_ACPI.
A subsequent commit will instead use existing infrastructure to
exclude the files from hwpmc.ko for non-ACPI builds.  Note that the
original commit left the files as optional in sys/conf/files.arm64.

This reverts commit 751d88119f.

Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D38736
2023-03-01 10:31:53 -08:00
Dapeng Gao
281402e0a5 arm64: Shave off two instructions in exceptions
This patch shaves off up to two three instructions in
save_registers_head in exception.S for arm64, which would make more
space for instructions that could be added in CheriBSD.

This is done by:
 1. Combining pointer arithmetic with pre-incrementing STP instructions
 2. Removing the instruction that sets the frame pointer (x29) as its
    content is unused

Differential Revision:	https://reviews.freebsd.org/D34631
2023-03-01 14:43:43 +00:00
Kyle Evans
dc8616edc5 arm64: set FPEN if we're stuck with HCR_EL2.E2H
On Apple Silicon systems, E2H can't actually be cleared; we're stuck
with it.  Check it again when we're setting up CPTR_EL2 and set FPEN
appropriately to avoid later trapping to EL2 on writes to SIMD
registers.

Reviewed by:	andrew
Differential Revision:	https://reviews.freebsd.org/D38819
2023-02-28 16:16:14 -06:00
Mike Karels
f12907d01a arm64 kernel config: clean up whitespace
Most options in kernel config files use "options<space><tab>OPTION".
This allows the option to be commented out without shifting columns.
A few options had two tabs, and some had spaces.  Make them consistent.
2023-02-24 08:36:29 -06:00
Mateusz Guzik
6b9acd1bfb Exclude MMCCAM kernels from make universe
They don't provide any value and are quite arbitrary.

Note arm64 GENERIC-MMCCAM was already excluded, just not the NODEBUG
variant.

The option is already build-tested with arm64 LINT kernel.

Reviewed by:	manu
Differential Revision:	https://reviews.freebsd.org/D38458
2023-02-16 07:29:53 +00:00
Dmitry Chagin
c8a79231a5 linux(4): Rename linux_timer.h to linux_time.h
To avoid confusing people, rename linux_timer.h to linux_time.h,
as linux_timer.c is the implementation of timer syscalls only,
while linux_time.c contains implementation of all stuff declared
in linux_time.h.

MFC after:		2 weeks
2023-02-14 17:46:33 +03:00
Dmitry Chagin
55d3e181fc linux(4): Cleanup includes under arm64/linux
Cleanup unneeded includes, sort the rest according to style(9).
No functional changes.

MFC after:		2 weeks
2023-02-14 17:46:33 +03:00
Dmitry Chagin
31e938c531 linux(4): Cleanup vm includes from linux_util.h
Include vm headers directly where they needed. The linux_util.h included
in a most source files of the Linuxulator, avoid collecting a rarely used
includes here.

MFC after:		2 weeks
2023-02-14 17:46:30 +03:00
John Baldwin
18bb97b76b arm64 pmap: Fix a buffer overrun initializing per-superpage locks.
pmap_init_pv_table makes a first pass over the memory segments to
compute the amount of address space needed to allocate per-superpage
locks.  It then makes a second pass over each segment allocating
domain-local memory to back the pages for the locks belonging to each
segment.  This second pass rounds each segment's allocation up to a
page size since the domain-local allocation has to be a multiple of
pages.  However, the first pass was only doing a single round of the
total page counts up at the end not accounting for the padding present
in each segment.  To fix, apply the rounding in each segment in the
first pass instead of just at the end.

While here, tidy the second pass a bit by trimming some
not-quite-right logic copied from amd64.  In particular, compute pages
directly at the start of the loop iteration to more closely match the
first loop.  Then, drop an always-false condition as 'end' was
computed as 'start + pages' where 'start == highest + 1'.  Thus, the
actual condition being tested was 'if (highest >= highest + 1 +
pages)'.  Finally, remove 'highest' entirely by keep the result of the
'pvd' increment in the existing loop.

Reported by:	CHERI (overflow)
Reviewed by:	markj
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D38377
2023-02-13 13:19:03 -08:00
Dmitry Chagin
10d16789a3 linux(4): Get rid of the opt_compat.h include.
Since e013e369 COMPAT_LINUX, COMPAT_LINUX32 build options are removed,
so include of opt_compat.h is no more needed.

MFC after:		2 weeks
2023-02-12 20:24:32 +03:00
Elliott Mitchell
f9bdaab95e ofwbus: remove handling of resources from ofwbus
The architecture nexus should handle allocation and release of memory and
interrupts. This is to ensure that system-wide resources such as these
are available to all devices, not just children of ofwbus0.

On powerpc this moves the ownership of these resources up one level,
from ofwbus0 to nexus0. Other architectures already have the required
logic in their nexus implementation, so this eliminates the duplication
of resources. An implementation of nexus_adjust_resource() is added for
arm, arm64, and riscv.

As noted by ian@ in the review, resource handling was the main bit of
logic distinguishing ofwbus from simplebus. With some attention to
detail, it should be possible to merge the two in the future.

Co-authored by:	mhorne
MFC after:	1 month
Differential Revision: https://reviews.freebsd.org/D30554
2023-02-08 16:50:46 -04:00
Val Packett
4a1c4de232 Allow sysctl hw.machine/hw.machine_arch in capability mode
There's no harm in reading strings like 'amd64'.

Reviewed by: emaste, manu
Sponsored by: https://www.patreon.com/valpackett
Differential Revision: https://reviews.freebsd.org/D28703
2023-02-06 14:00:52 -05:00
Andrew Turner
f29942229d Read the arm64 far early in el0 exceptions
When handling userspace exceptions on arm64 we need to dereference the
current thread pointer. If this is being promoted/demoted there is a
small window where it will cause another exception to be hit. As this
second exception will set the fault address register we will read the
incorrect value in the userspace exception handler.

Fix this be always reading the fault address before dereferencing the
current thread pointer.

Reported by:	olivier@
Reviewed by:	markj
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D38196
2023-02-02 16:43:15 +00:00
Andrew Turner
03d6e03851 Check for the IORT before adding the ITS driver
Before adding the ITS interrupt controller driver to handle MSI/MSI-X
interrupts check if it is present in the IO Remapping Table (IORT).
If not don't attach as devices expect to use this table to find the
correct MSI interrupt controller.

Sponsored by: Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D37772
2023-02-02 16:43:15 +00:00
Dmitry Chagin
95b8603427 linux(4): Deduplicate linux_trans_osrel().
MFC after:		1 week
2023-02-02 17:58:07 +03:00
Dmitry Chagin
6039e966ff linux(4): Deduplicate linux_copyout_strings().
It is still present in the 32-bit Linuxulator on amd64.

MFC after:		1 week
2023-02-02 17:58:07 +03:00
Dmitry Chagin
7446514533 linux(4): Microoptimize linux_elf.h for future use.
In order to reduce code duplication move coredump support definitions
into the appropriate header and hide private definitions.

MFC after:		1 week
2023-02-02 17:58:06 +03:00
Konstantin Belousov
83a49712af kstack_contains(): account for struct pcb on stack
for arm64, arm, powerpc, and riscv

Reviewed by:	jhb
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D38320
2023-02-02 00:59:27 +02:00
Konstantin Belousov
2555f175b3 Move kstack_contains() and GET_STACK_USAGE() to MD machine/stack.h
Reviewed by:	jhb
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D38320
2023-02-02 00:59:26 +02:00
Dmitry Chagin
575e48f1c4 linux(4): Deduplicate MI futex structures.
MFC after:	1 week
2023-02-01 21:57:04 +03:00
Wei Hu
c75ae52216 arm64: Hyper-V: vPCI: Fix typo and some indentations
Fix a typo and some indentation errors in the previous commits.

Reported by:	jrtc27
Fixes:	db247798c5 ("arm64: Hyper-V: vPCI: SPI MSI mapping for gic v3 acpi in arm64")
Fixes:	6e5b082cab ("arm64: Hyper-V: vPCI: Adding Hyper-V PCI protocol 1.4")
Sponsored by:	Microsoft
2023-02-01 17:34:19 +00:00
Wei Hu
db247798c5 arm64: Hyper-V: vPCI: SPI MSI mapping for gic v3 acpi in arm64
Microsoft Azure Hyper-V uses SPI to map MSI in ARM64, instead of
using LPI IDS. To enable that we need to have gic registered with
ACPI_MSI_XREF and gic acpi to map SPI for MSI.

This is the 1st of the three patchs to enable Hyper-V vPCI support
in arm64.

Reviewed by:	andrew, emaste, whu
Tested by:	Souradeep Chakrabarti <schakrabarti@microsoft.com>
Obtained from:	Souradeep Chakrabarti <schakrabarti@microsoft.com>
Sponsored by:	Microsoft
Differential Revision:	https://reviews.freebsd.org/D37763
2023-02-01 15:40:08 +00:00
Justin Hibbits
b7459fb0ad Mechanically convert genet(4) to IfAPI
Sponsored by:	Juniper Networks, Inc.
Differential Revision: https://reviews.freebsd.org/D37832
2023-01-31 16:26:34 -05:00
Alexander V. Chernikov
e80699a809 netlink: add NETLINK to GENERIC.
This is a followup of 692e19cf51 (add netlink to GENERIC@amd64).

Netlink is a communication protocol defined in RFC 3549. It is async,
TLV-based protocol, providing 1-1 and 1-many communications between kernel
and userland. Netlink is currently used in Linux kernel to modify, read and
subscribe for nearly all networking states. Interface state, addresses, routes,
firewall, rules, fibs, etc, are controlled via Netlink.

Netlink support was added in D36002. It has got a number of improvements and
first customers since then:
* net/bird2 got netlink support, enabling route multipath in FreeBSD
* netlink-based devd notifications are being worked on ( D37574 ).
* linux(4) fully supports and depends on Netlink

Enabling Netlink in GENERIC targets two goals.
The first one is to provide stability for the third-party userland applications,
so they can rely on the fact that netlink always exists since 14.0 and potentially 13.2.
Loadable module makes life of the app delepers harder. For example, `net/bird2` can be
either build with netlink or rtsock support, but not both.

The second goal is to enable gradual conversion of the base userland tools
to use netlink(4) interfaces. Converting tools like netstat (D36529), route,
ifconfig one-by-one simplifies testing and addressing the feedback.
Othewise, switching all base to use netlink at once may be too big of a leap.

MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D37783
2023-01-31 14:22:11 +00:00
Emmanuel Vadot
5a00612149 arm64: Move device scmi to std.arm
The scmi driver in its current form requires the arm_doorbell
driver to communicate with the firmware.
The arm_doorbell is only found in ARM Juno reference board (and
apparently on Morello too).
If we want to use scmi on other platform (like some rockchip or imx
soc), the driver needs to be updated to support svc/shmem communication
with the firmware.
For now since it can be only used with arm_doorbell move the device to
std.arm otherwise kernel configs like ALLWINNER or ROCKCHIP fails to build.

Reviewed by:	br, imp
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D37953
2023-01-25 08:28:22 +01:00
Warner Losh
34784d17eb elf: Catch up with defining EF_ARM_EABI_VERSION in elf_common.h
FreeBSD defines EF_ARM_EABI_VERSION in a non-standard way (at least
differently than everybody else). We use this only in elf*machdep.c to
make sure the image is new enough. Switch to the more standard way of
defining this and adjust other constants to match.

Fixes:			c52c98e69a
Sponsored by:		Netflix
2023-01-20 19:18:15 -07:00
Allan Jude
fd5e921059 Add CPU Ident for Qualcomm Kryo 400 (used in MS Dev Kit)
Reviewed by:	imp
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D37767
2023-01-18 21:04:49 +00:00
Andrew Turner
a85cf421d1 Reduce an arm64 VFP critical section
In set_fpcontext we only need a critical section around vfp_discard.
The remainder of the code can run without it.

While here add an assert to check the passed in thread is the
current thread as the code already this.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D38000
2023-01-18 09:31:50 +00:00
Andrew Turner
61f5462fde Always store the arm64 VFP context
If a thread enters a kernel FP context the PCB_FP_STARTED may be
unset when calling get_fpcontext even if the VFP unit has been used
by the current thread.

Reduce the use of this flag to just decide when to store the VFP state.

While here add an assert to check the assumption that the passed in
thread is the current thread and remove the unneeded critical section.
The latter is unneeded as the only place we would need it is in
vfp_save_state and this already has a critical section when needed.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D37998
2023-01-18 09:31:45 +00:00
Andrew Turner
95dd6974b5 Always read the VFP regs in the arm64 fill_fpregs
The PCB_FP_STARTED is used to indicate that the current VFP context
has been used since either 1. the start of the thread, or 2. exiting
a kernel FP context.

When case 2 was added to the kernel this could cause incorrect results
to be returned when a thread exits the kernel FP context and fill_fpregs
is called before it has restored the VFP state, e.g. by trappin on a
userspace VFP instruction.

In both of the cases the base save area is still valid so reduce the
use of the PCB_FP_STARTED flag check to help decide if we need to
store the current threads VFP state.

Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D37994
2023-01-18 09:31:35 +00:00
Brooks Davis
e1b610f76c arm64: Fix thread0.td_kstack_pages init
Commit 86a994d653 initialized
thread0.td_kstack_pages to KSTACK_PAGES.  Due to the lack of an
include of opt_kstack_pages.h it used the fallback value of 4 from
machine/param.h.  This meant that increasing KSTACK_PAGES in the kernel
config resulted in a panic in _epoch_enter_preempt as the following
assertion was false during network stack setup:

        MPASS((vm_offset_t)et >= td->td_kstack &&
	    (vm_offset_t)et + sizeof(struct epoch_tracker) <=
	    td->td_kstack + td->td_kstack_pages * PAGE_SIZE);

Switch to initializing with kstack_pages following other architectures.

Reviewed by:	imp, markj
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D38048
2023-01-17 16:37:09 +00:00
Søren Schmidt
4ffe60e683 Add Combo PHY, RK817, Syr827, tcs4525 pmic devices to Rockchip specific config. 2023-01-08 03:07:18 +00:00
Søren Schmidt
11b5b9e8a5 Add delay to have things settle. 2023-01-07 07:42:44 +00:00
Ganbold Tsagaankhuu
9427c47de6 Remove unnecessary sys/cdefs.h includes. 2023-01-07 06:05:52 +00:00
Val Packett
0b4531511e copyright: chase my name and email change
Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D37945
2023-01-06 15:28:42 -05:00
Ganbold Tsagaankhuu
90737b632e Use BSD-2-Clause for the SPDX license id as -FreeBSD variant has been deprecated. 2023-01-06 08:15:44 +00:00
Ganbold Tsagaankhuu
7e2600ea7b Add SPDX-License-Identifier. 2023-01-06 04:14:49 +00:00
Ganbold Tsagaankhuu
0d4a240b0d Remove unnecessary $Id string from license.
While there add SPDX-License-Identifier.
2023-01-06 04:10:09 +00:00
Søren Schmidt
5723e5ac6d Add Naneng combo PHY support for RK3568 SoC.
It can be used as pcie-phy, usb3-phy, sata-phy or sgmii-phy.
2023-01-06 03:04:53 +00:00
Søren Schmidt
7daf96523b Add PCIe driver for RK3568 SoC.
PCIe3 ports work, however PCIe2x1 is not working yet in this case as it depends on Naneng Combo Phy driver.
2023-01-05 04:15:56 +00:00