aboutsummaryrefslogtreecommitdiff
path: root/sys/x86/iommu
Commit message (Collapse)AuthorAgeFilesLines
* sys: Don't pass RF_ALLOCATED to bus_alloc_resource*John Baldwin2026-03-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | This is a nop as eventually these flags are passed to rman_reserve_resource which unconditionally sets RF_ALLOCATED in the new flags for a region. However, it's really a layering violation to use RF_ALLOCATED in relation to struct resource objects outside of subr_rman.c as subr_rman.c uses this flag to manage it's internal tracking of allocated vs free regions. In addition, don't document this as a valid flag in the manual. I think the intention here was that if a caller didn't want to pass RF_ACTIVE or RF_SHAREABLE, they could pass RF_ALLOCATED instead of 0, but given the layering violation, I think it's best to just pass 0 instead in that case. NB: The bhnd bus uses RF_ALLOCATED (along with RF_ACTIVE) in a separate API to manage resource regions that are not struct resource objects (but a separate wrapper object). It would perhaps be cleaner if the chipc_retain_region and chipc_release_region functions used their own flag constants instead of reusing the rman(9) flags. Reviewed by: imp, kib Differential Revision: https://reviews.freebsd.org/D55683
* AMD IOMMU: fix per-device IOMMU bypass when IR is enabledJason A. Harmening2025-10-201-5/+4
| | | | | | | | | | | | | | | | | | | | | | | | When interrupt remapping (IR) is enabled, the device table entry (DTE) for a given device will likely be initialized by amdiommu_ir_find() during MSI configuration. This function directly calls amdiommu_get_ctx_for_dev() with id_mapped=false, which means that any attempt to disable DMA remapping for the device (e.g. by setting hw.busdma.pciD.B.S.F='bounce' in the loader tunables) will effectively be ignored as the paging mode field in the DTE will not be set to 0 as required for identity mapping. This will ultimately produce an unusable device, because busdma will later observe the bounce configuration through iommu_instantiate_ctx() and will employ the non-translated 'bounce' busdma methods for the device, while the DTE remains configured to enable translation. Fix this by tweaking iommu_instantiate_ctx() to always return the relevant per-device context object even if translation is disabled, and adopt it in amdiommu_ir_find() instead of directly calling amdiommu_get_ctx_for_dev(). Reviewed by: kib MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D53209
* iommu_get_requester(): make it more resilient against arbitrary dev argKonstantin Belousov2025-09-092-5/+17
| | | | | | | | | | | | | | | | | If passed the parent of a device instead of the device, the loop might end up with the host bridge in the pci local variable. If the passed device is not from the pci hierarchy, any of the calculated parents might be NULL. Change the interface to allow the caller to receive error. Instead of asserting, just issue a message and return ENXIO, allowing the caller to select appropriate action. PR: 289318 Reviewed by: jah Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D52406
* intel_idpgtbl: use FORALL macro for page walkDoug Moore2025-04-181-3/+7
| | | | | | | Change two loops to use VM_RADIX_FORALL and drop the use of vm_page_next(). Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D49891
* amd_idpgtbl: use iterator instead of vm_page_nextDoug Moore2025-04-181-1/+4
| | | | | | | | Use VM_RADIX_FORALL instead of vm_page_next in a loop in amdiommu_domain_free_pgtbl. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D49890
* x86/amdiommu: add amdiommu_is_running()Konstantin Belousov2025-04-012-0/+10
| | | | | | Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* x86/dmar: add dmar_is_running()Konstantin Belousov2025-04-012-0/+11
| | | | | | Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* amdiommu: fix typo in the bit descriptionKonstantin Belousov2025-03-031-1/+1
| | | | | | | Noted by: alc Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* amdiommu: add register definitions from IOMMU spec 48882 rev. 3.10Konstantin Belousov2025-03-021-0/+18
| | | | | | | | | Most important for us is the max interrupt remapping count report in the EFR2 register. Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* amd iommu: remove unused functionKonstantin Belousov2024-12-151-6/+0
| | | | | | Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 3 days
* amdiommu: correctly initialize iommu.unitKonstantin Belousov2024-12-071-2/+1
| | | | | | | | | The field is mostly used for display, and should match device unit, not BIOS IVHD device id, which is deprecated and is practically zero. Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 3 days
* dmar: set acpi ivar domain on identify()Konstantin Belousov2024-11-261-29/+31
| | | | | | | | Reviewed by: jhb Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D47291
* amdiommu: use static array for device table base register offsetsJason A. Harmening2024-11-261-4/+15
| | | | | | | | | | | This is a somewhat cleaner and more future-proof way to get the correct device table offsets. Reviewed by: kib Reported by: crest_freebsd_rlwinm.de Fixes: 5035db22 "amdiommu: Fix device table segment base register offsets" Differential Revision: https://reviews.freebsd.org/D47769
* amdiommu: Fix device table segment base register offsetsJason A. Harmening2024-11-261-1/+1
| | | | | | | | | | Segment base registers are at 8-byte intervals, while the register write helper takes a byte-aligned offset. This fixes DEV_TAB_HARDWARE_ERROR events and associated peripheral I/O failures on an Epyc-based system with 8-segment device tables. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D47752
* amdiommu: short-circuit all amdiommu_find_unit() functionsKonstantin Belousov2024-11-091-1/+10
| | | | | | | | | | | | for the case where amdiommu is not enabled. In this case, it does not matter if IVHD does not describe some device. Similarly, no unit can be found for a device, because units are not instantiated, but it does not matter. Reported by: mav Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 3 days
* amdiommu: hide HPET report under verboseKonstantin Belousov2024-11-091-2/+3
| | | | | | | Reported by: markj Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 3 days
* iommu: Clean up a lingering function prototypeMark Johnston2024-11-041-1/+0
| | | | | Reported by: clang Fixes: d97838b7c2a6 ("iommu: eliminate iommu_free_ctx()")
* amdiommu: print more domain information from ddb showKonstantin Belousov2024-11-031-4/+2
| | | | | | Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* iommu: eliminate iommu_free_ctx()Konstantin Belousov2024-11-038-49/+0
| | | | | | | | iommu_free_ctx_locked() alone is enough Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* x86/iommu/amd_reg.h: fix typo in commentKonstantin Belousov2024-11-031-1/+1
| | | | | | Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* AMD IOMMU driverKonstantin Belousov2024-11-027-0/+3557
| | | | | | | | | | | | | | | | | | | | | | | | | This driver is functionally equivalent to the in-tree Intel DMAR code. It handles busdma and interrupt remapping from the host OS. There is no integration with bhyve, and the stub iommu drivers in bhyve code cannot coexist with this driver (planned). The biggest architectural problem with the code is that the AMD IOMMU units are enumerated as PCIe-attached security devices, which is much later after HPET and IOAPIC drivers attached and actived interrupts. Because of this, HPET FSB interrupts and IOAPIC interrupts are always identity-mapped. The code is of late alpha quality. By default the driver is disabled. To enable for testing, set in loader.conf: hw.amdiommu.enable=1 hw.iommu.dma=1 <- to enable iommu busdma hw.iommu.ir=1 <- to enable interrupt remapping Discussed with: emaste Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D47256
* x86/iommu/amd_reg.h: AMD IOMMU registers definitionsKonstantin Belousov2024-11-021-0/+746
| | | | | | | | Reviewed by: emaste Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D47255
* DMAR: handle affinity for in-memory data structuresKonstantin Belousov2024-10-234-7/+63
| | | | | | | | Reviewed and tested by: markj Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D47254
* devices: report iommu data for the device in the dev. sysctl treeKonstantin Belousov2024-10-173-3/+30
| | | | | | | | | | | Show the iommu unit' device name/unit which translates the device' requests, if any, as parsed out from the BIOS tables. Also show the rid value for the device. Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D47098
* iommu: extract driver-independent ddb context and mapping reportingKonstantin Belousov2024-10-133-23/+42
| | | | | | Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* iommu: move context link and ref count into device-independent partsKonstantin Belousov2024-10-135-71/+75
| | | | | | | | | This also allows to move some bits of ddb print routines into iommu_utils.c common for x86 iommu drivers. Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* iommu_qi_seq_processed: use atomic to read hw-written seq numberKonstantin Belousov2024-10-031-2/+2
| | | | | | | | otherwise iommu_qi_wait_for_seq() can be legitimately optimized out. Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* dmar: on unmap, postpone freeing page table pages after the invalidation is doneKonstantin Belousov2024-09-271-13/+18
| | | | | | | | IOMMU is free to access page tables until we invalidate them Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* iommu: extend iommu_map_entry to store the list of associated freed page ↵Konstantin Belousov2024-09-273-7/+15
| | | | | | | | | | | table pages The pages are inserted into the added slist if the entry parameter is passed to iommu_pgfree(). For now it is nop. Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* iommu: change iommu_domain_map_ops to take iommu_map_entryKonstantin Belousov2024-09-272-7/+12
| | | | | | | | instead of base/size. Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* iommu: add per-unit sysctls reporting the state of DMA and interrupt remappingKonstantin Belousov2024-09-272-1/+6
| | | | | | Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* intel_idpgtbl.c: rename domain_* functions to dmar_*Konstantin Belousov2024-09-273-39/+39
| | | | | | Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* x86: always provide dummy x86_iommu virtual methodsKonstantin Belousov2024-09-051-2/+50
| | | | | | | | | | | to make configurations where vendor-specific IOMMU not yet implemented but IOMMU is enabled in config, work when calling into MSI/IOAPIC interrupt remapping. Reported by: cy Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* dmar: avoid excessive indirection in KASSERT() in domain_map_buf()Konstantin Belousov2024-09-041-1/+1
| | | | | | Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* busdma_iommu: indirect dmar-specific method calls in iommu_get_dev_ctx()Konstantin Belousov2024-09-043-0/+15
| | | | | | Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* DMAR: provide hw.iommu.ir alias for the hw.dmar.ir tunableKonstantin Belousov2024-09-041-0/+1
| | | | | | Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* DMAR: move hw.iommu.dmar.{tbl_pagecnt,batch_coalesce} sysctls up one levelKonstantin Belousov2024-09-045-9/+11
| | | | | | Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* x86 iommu: move page level related functions to common utilsKonstantin Belousov2024-09-045-75/+78
| | | | | | | | Also improve pglvl_page_size() to handle level 6. Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* x86 dmar: generalize dmar_domain_free_entry() into iommu_domain_free_entry()Konstantin Belousov2024-09-044-17/+19
| | | | | | Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* x86 iommu: move device_tag_init() to utilsKonstantin Belousov2024-09-043-20/+20
| | | | | | Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* x86 iommu: move DMAR-independent parts of the interrupt setup code into commonKonstantin Belousov2024-09-046-140/+193
| | | | | | Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* x86 iommu x86_unit_common: expand hw completion write-out area to 8 bytesKonstantin Belousov2024-09-042-4/+10
| | | | | | | | | | in preparation to share it with AMD IOMMU. AMD writes out 8 bytes. We use 32-bit completion sequence numbers, and CPUs are little-endian. So the expansion is acceptable on Intel. Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* DMAR: rename domain_{alloc,free}_pgtbl to domain_domain_$1_pgtblKonstantin Belousov2024-09-043-6/+6
| | | | | | Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* dmar_qi_emit(): use atomic_store_64() when availableKonstantin Belousov2024-09-041-0/+10
| | | | | | Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* dmar_qi_XXX_invalidate_glob(): reduce code duplicationKonstantin Belousov2024-09-041-24/+14
| | | | | | Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* x86 iommu: move DMAR-independent parts of the qi code into commonKonstantin Belousov2024-09-046-298/+413
| | | | | | Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* x86: allow to have more than one kind of IOMMUKonstantin Belousov2024-09-046-23/+173
| | | | | | Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* DMAR: use DMAR2IOMMU() for DMAR_LOCK() and related macrosKonstantin Belousov2024-09-041-3/+3
| | | | | | Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* Intel DMAR: improve X2X macros to fix failures in certain syntax contextsKonstantin Belousov2024-09-041-3/+3
| | | | | | Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* DMAR: clear dmar_devs[unit] if attach failedKonstantin Belousov2024-08-211-0/+11
| | | | | | | | | | | | This should stop attempts to use a unit which was not completely initialized, but referenced by ACPI DMAR table during scoped devices operions. PR: 280817 Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D46382