Commit graph

38 commits

Author SHA1 Message Date
Doug Moore b0056b31e9 libkern: add ilog2 macro
The kernel source contains several definitions of an ilog2 function;
some are slower than necessary, and one of them is incorrect.
Elimininate them all and define an ilog2 macro in libkern to replace
them, in a way that is fast, correct for all argument types, and, in a
GENERIC kernel, includes a check for an invalid zero parameter.

Folks at Microsoft have verified that having a correct ilog2
definition for their MANA driver doesn't break it.

Reviewed by:	alc, markj, mhorne (older version), jhibbits (older version)
Differential Revision:	https://reviews.freebsd.org/D45170
Differential Revision:	https://reviews.freebsd.org/D45235
2024-06-03 11:37:55 -05:00
Dmitry Salychev ac4ddc467b
arm64: Fixed IOMMU compilation errors
These are missing changes after 1228b93b41 when ref_count was
removed from bus_dma_tag_common and 1e3f42b6ba, when the address
arguments were switched to pointers.

Reviewed by:		jhb
MFC after:		3 days
Differential Revision:	https://reviews.freebsd.org/D45289
2024-05-22 11:08:00 +02:00
Warner Losh fdafd315ad sys: Automated cleanup of cdefs and other formatting
Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by:		Netflix
2023-11-26 22:24:00 -07:00
Warner Losh 031beb4e23 sys: Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:58 -06:00
Warner Losh 685dc743dc sys: Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:36 -06:00
Warner Losh 95ee2897e9 sys: Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:11 -06:00
Gordon Bergling f0ab805200 arm64-iommu: Fix a typo in a kernel message
- s/endianess/endianness/

MFC after:	5 days
2023-08-04 13:52:36 +02:00
John Baldwin c3e58ace31 arm64 iommu: Fix build without INVARIANTS.
Obtained from:	CheriBSD
Sponsored by:	DARPA
2023-06-23 09:41:26 -07: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
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 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
Ruslan Bukin dc08d52d1e smmu: fix FDT and !FDT builds.
Reviewed by:	andrew
Sponsored by:	UKRI
Differential Revision:	https://reviews.freebsd.org/D37762
2022-12-21 15:53:09 +00:00
Ruslan Bukin 4b4e8cb53a smmu: set guest address space range to 48-bit, which is a hardware
limit in our configuration.

Reviewed by:	andrew
Sponsored by:	UKRI
Differential Revision:	https://reviews.freebsd.org/D37756
2022-12-21 15:53:05 +00:00
Alan Cox 4670f90846 iommu_gas: Eliminate redundant parameters and push down lock acquisition
Since IOMMU map entries store a reference to the domain in which they
reside, there is no need to pass the domain to iommu_gas_free_entry(),
iommu_gas_free_space(), and iommu_gas_free_region().

Push down the acquisition and release of the IOMMU domain lock into
iommu_gas_free_space() and iommu_gas_free_region().

Both of these changes allow for simplifications in the callers of the
functions without really complicating the functions themselves.
Moreover, the latter change eliminates the direct use of the IOMMU
domain lock from the x86-specific DMAR code.

Reviewed by:	kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D35995
2022-07-30 14:28:48 -05:00
Alan Cox 8bc3673847 iommu_gas: Eliminate a possible case of use-after-free
Eliminate a possible case of use-after-free in an error handling path
after a mapping failure.  Specifically, eliminate IOMMU_MAP_ENTRY_QI_NF
and instead perform the IOTLB invalidation synchronously.  Otherwise,
when iommu_domain_unload_entry() is called and told not to free the
IOMMU map entry, the caller could free the entry before dmar_qi_task()
is finished with it.

Reviewed by:	kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D35878
2022-07-25 11:14:58 -05:00
Ruslan Bukin 41ce5498f8 Add OFW support to arm64's IOMMU framework.
This is needed to support non-PCI devices like memory-mapped
display controllers.
Split-out some initialization code from iommu_ctx_alloc() into
iommu_ctx_init() method so we could pass controller's MD-data
obtained from DTS to the driver prior to a CTX initialization.

Tested on Morello SoC.

Sponsored by:	UKRI
2022-05-18 14:11:23 +01:00
Ruslan Bukin 182a69328d Fix stream table entry (STE) initialization and removal.
For PCI devices we have entire L1 descriptor for every session ID (SID),
but for non-PCI (e.g. Display Processing Unit DPU), a single L1
descriptor serves multiple SIDs.
So prevent re-initialization of L1 descriptor if already initialized.
Don't free entire L1 descriptor on every STE removal.

Sponsored by:	UKRI
2022-05-18 13:42:37 +01:00
Ruslan Bukin 1cb8e38e4b Code deduplication: use SID-getting functions in smmu_find().
Sponsored by:	UKRI
2022-05-10 16:20:15 +01:00
John Baldwin bb62bc2284 arm64: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-09 14:26:45 -07:00
Ruslan Bukin b7fca06bbf Split-out SID-getting code to a separate functions.
Also ensure we are dealing with PCI-class devices.

Sponsored by:	UKRI
2022-05-09 20:13:57 +01:00
Ruslan Bukin f224006fe1 Allocate resources selectively.
One of the SMMU interrupt lines (priq) is optional and may be ommited in FDT.

Tested on ARM Morello Board, which has three SMMU units: first two have four
interrupt lines, last one has three interrupt lines.

Sponsored by: UKRI
2022-05-09 13:30:37 +01:00
Ruslan Bukin 0a8e88fa73 Change __unused to __diagused.
Pointed out by:	jhb
Sponsored by:	UKRI
2022-05-09 11:24:47 +01:00
Ruslan Bukin a5ec261a7c Add FDT attachment driver for ARM System MMU v3.2 controller.
Tested on ARM Morello Board.

Sponsored by:	UKRI
2022-05-07 11:18:35 +01:00
Ruslan Bukin 7d0bbf43fd Change iommu list lock to SX as we need a sleepable lock so we
can call to ofw_bus_iommu_map().

Sponsored by:	UKRI
2022-05-07 11:15:07 +01:00
Ruslan Bukin 59446e8ac0 Fix !INVARIANTS build.
Sponsored by:	UKRI
2022-05-07 10:45:33 +01:00
Ruslan Bukin 6ff004272a Return error code from IOMMU_MAP and fix build.
Sponsored by:	UKRI
2022-05-07 10:24:30 +01:00
Jesper Schmitz Mouridsen ea07ba1170 sys/arm64/iommu/iommu_pmap.c readd sys/systm.h
after d950c5898a UINT64_C and bzero were no longer defined

Approved by:	kib
Differential Revision:	https://reviews.freebsd.org/D34155
2022-02-03 20:03:29 +01:00
Mark Johnston ff93447d8e Use the vm_radix_init() helper when initializing pmaps
No functional change intended.

Reviewed by:	alc, kib
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D32527
2021-10-19 21:22:56 -04:00
Mark Johnston a4667e09e6 Convert vm_page_alloc() callers to use vm_page_alloc_noobj().
Remove page zeroing code from consumers and stop specifying
VM_ALLOC_NOOBJ.  In a few places, also convert an allocation loop to
simply use VM_ALLOC_WAITOK.

Similarly, convert vm_page_alloc_domain() callers.

Note that callers are now responsible for assigning the pindex.

Reviewed by:	alc, hselasky, kib
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D31986
2021-10-19 21:22:56 -04:00
Ruslan Bukin f17c4e38f5 Move IOMMU code to a separate pmap module and switch ARM System MMU
driver to use it.

Add ARM Mali Txxx (Midgard), Gxx (Bifrost) GPU page management code.

Sponsored by: UKRI
2021-04-27 19:16:09 +01:00
Ruslan Bukin 4cc8701067 Introduce IOMMU support for arm64 platform.
This adds an arm64 iommu interface and a driver for Arm System Memory
Management Unit version 3.2 (ARM SMMU v3.2) specified in ARM IHI 0070C
document.

Hardware overview is provided in the header of smmu.c file.

The support is disabled by default. To enable add 'options IOMMU' to your
kernel configuration file.

The support was developed on Arm Neoverse N1 System Development Platform
(ARM N1SDP), kindly provided by ARM Ltd.

Currently, PCI-based devices and ACPI platforms are supported only.
The support was tested on IOMMU-enabled Marvell SATA controller,
Realtek Ethernet controller and a TI xHCI USB controller with a low to
medium load only.

Many thanks to Konstantin Belousov for help forming the generic IOMMU
framework that is vital for this project; to Andrew Turner for adding
IOMMU support to MSI interrupt code; to Mark Johnston for help with SMMU
page management; to John Baldwin for explaining various IOMMU bits.

Reviewed by:	mmel
Relnotes:	yes
Sponsored by:	DARPA / AFRL
Sponsored by:	Innovate UK (Digital Security by Design programme)
Differential Revision:	https://reviews.freebsd.org/D24618
2020-11-16 21:55:52 +00:00