186be9f0dSKonstantin Belousov /*- 286be9f0dSKonstantin Belousov * Copyright (c) 2013 The FreeBSD Foundation 386be9f0dSKonstantin Belousov * All rights reserved. 486be9f0dSKonstantin Belousov * 586be9f0dSKonstantin Belousov * This software was developed by Konstantin Belousov <kib@FreeBSD.org> 686be9f0dSKonstantin Belousov * under sponsorship from the FreeBSD Foundation. 786be9f0dSKonstantin Belousov * 886be9f0dSKonstantin Belousov * Redistribution and use in source and binary forms, with or without 986be9f0dSKonstantin Belousov * modification, are permitted provided that the following conditions 1086be9f0dSKonstantin Belousov * are met: 1186be9f0dSKonstantin Belousov * 1. Redistributions of source code must retain the above copyright 1286be9f0dSKonstantin Belousov * notice, this list of conditions and the following disclaimer. 1386be9f0dSKonstantin Belousov * 2. Redistributions in binary form must reproduce the above copyright 1486be9f0dSKonstantin Belousov * notice, this list of conditions and the following disclaimer in the 1586be9f0dSKonstantin Belousov * documentation and/or other materials provided with the distribution. 1686be9f0dSKonstantin Belousov * 1786be9f0dSKonstantin Belousov * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1886be9f0dSKonstantin Belousov * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1986be9f0dSKonstantin Belousov * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2086be9f0dSKonstantin Belousov * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2186be9f0dSKonstantin Belousov * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2286be9f0dSKonstantin Belousov * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2386be9f0dSKonstantin Belousov * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2486be9f0dSKonstantin Belousov * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2586be9f0dSKonstantin Belousov * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2686be9f0dSKonstantin Belousov * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2786be9f0dSKonstantin Belousov * SUCH DAMAGE. 2886be9f0dSKonstantin Belousov */ 2986be9f0dSKonstantin Belousov 3086be9f0dSKonstantin Belousov #include <sys/cdefs.h> 3186be9f0dSKonstantin Belousov __FBSDID("$FreeBSD$"); 3286be9f0dSKonstantin Belousov 3386be9f0dSKonstantin Belousov #include <sys/param.h> 3486be9f0dSKonstantin Belousov #include <sys/bus.h> 3586be9f0dSKonstantin Belousov #include <sys/kernel.h> 3686be9f0dSKonstantin Belousov #include <sys/lock.h> 3786be9f0dSKonstantin Belousov #include <sys/malloc.h> 3886be9f0dSKonstantin Belousov #include <sys/memdesc.h> 3986be9f0dSKonstantin Belousov #include <sys/mutex.h> 4086be9f0dSKonstantin Belousov #include <sys/proc.h> 4186be9f0dSKonstantin Belousov #include <sys/queue.h> 4286be9f0dSKonstantin Belousov #include <sys/rman.h> 4386be9f0dSKonstantin Belousov #include <sys/rwlock.h> 4486be9f0dSKonstantin Belousov #include <sys/sched.h> 4586be9f0dSKonstantin Belousov #include <sys/sf_buf.h> 4686be9f0dSKonstantin Belousov #include <sys/sysctl.h> 4786be9f0dSKonstantin Belousov #include <sys/systm.h> 4886be9f0dSKonstantin Belousov #include <sys/taskqueue.h> 4986be9f0dSKonstantin Belousov #include <sys/tree.h> 50*0a110d5bSKonstantin Belousov #include <sys/vmem.h> 5167499354SRyan Stone #include <dev/pci/pcivar.h> 5286be9f0dSKonstantin Belousov #include <vm/vm.h> 5386be9f0dSKonstantin Belousov #include <vm/vm_extern.h> 5486be9f0dSKonstantin Belousov #include <vm/vm_kern.h> 5586be9f0dSKonstantin Belousov #include <vm/vm_object.h> 5686be9f0dSKonstantin Belousov #include <vm/vm_page.h> 5786be9f0dSKonstantin Belousov #include <vm/vm_map.h> 5886be9f0dSKonstantin Belousov #include <vm/vm_pageout.h> 5986be9f0dSKonstantin Belousov #include <machine/bus.h> 6086be9f0dSKonstantin Belousov #include <machine/cpu.h> 61*0a110d5bSKonstantin Belousov #include <machine/intr_machdep.h> 62*0a110d5bSKonstantin Belousov #include <x86/include/apicvar.h> 6386be9f0dSKonstantin Belousov #include <x86/include/busdma_impl.h> 6486be9f0dSKonstantin Belousov #include <x86/iommu/intel_reg.h> 6586be9f0dSKonstantin Belousov #include <x86/iommu/busdma_dmar.h> 6686be9f0dSKonstantin Belousov #include <x86/iommu/intel_dmar.h> 6786be9f0dSKonstantin Belousov 6886be9f0dSKonstantin Belousov u_int 6986be9f0dSKonstantin Belousov dmar_nd2mask(u_int nd) 7086be9f0dSKonstantin Belousov { 7186be9f0dSKonstantin Belousov static const u_int masks[] = { 7286be9f0dSKonstantin Belousov 0x000f, /* nd == 0 */ 7386be9f0dSKonstantin Belousov 0x002f, /* nd == 1 */ 7486be9f0dSKonstantin Belousov 0x00ff, /* nd == 2 */ 7586be9f0dSKonstantin Belousov 0x02ff, /* nd == 3 */ 7686be9f0dSKonstantin Belousov 0x0fff, /* nd == 4 */ 7786be9f0dSKonstantin Belousov 0x2fff, /* nd == 5 */ 7886be9f0dSKonstantin Belousov 0xffff, /* nd == 6 */ 7986be9f0dSKonstantin Belousov 0x0000, /* nd == 7 reserved */ 8086be9f0dSKonstantin Belousov }; 8186be9f0dSKonstantin Belousov 8286be9f0dSKonstantin Belousov KASSERT(nd <= 6, ("number of domains %d", nd)); 8386be9f0dSKonstantin Belousov return (masks[nd]); 8486be9f0dSKonstantin Belousov } 8586be9f0dSKonstantin Belousov 8686be9f0dSKonstantin Belousov static const struct sagaw_bits_tag { 8786be9f0dSKonstantin Belousov int agaw; 8886be9f0dSKonstantin Belousov int cap; 8986be9f0dSKonstantin Belousov int awlvl; 9086be9f0dSKonstantin Belousov int pglvl; 9186be9f0dSKonstantin Belousov } sagaw_bits[] = { 9286be9f0dSKonstantin Belousov {.agaw = 30, .cap = DMAR_CAP_SAGAW_2LVL, .awlvl = DMAR_CTX2_AW_2LVL, 9386be9f0dSKonstantin Belousov .pglvl = 2}, 9486be9f0dSKonstantin Belousov {.agaw = 39, .cap = DMAR_CAP_SAGAW_3LVL, .awlvl = DMAR_CTX2_AW_3LVL, 9586be9f0dSKonstantin Belousov .pglvl = 3}, 9686be9f0dSKonstantin Belousov {.agaw = 48, .cap = DMAR_CAP_SAGAW_4LVL, .awlvl = DMAR_CTX2_AW_4LVL, 9786be9f0dSKonstantin Belousov .pglvl = 4}, 9886be9f0dSKonstantin Belousov {.agaw = 57, .cap = DMAR_CAP_SAGAW_5LVL, .awlvl = DMAR_CTX2_AW_5LVL, 9986be9f0dSKonstantin Belousov .pglvl = 5}, 10086be9f0dSKonstantin Belousov {.agaw = 64, .cap = DMAR_CAP_SAGAW_6LVL, .awlvl = DMAR_CTX2_AW_6LVL, 10186be9f0dSKonstantin Belousov .pglvl = 6} 10286be9f0dSKonstantin Belousov }; 10386be9f0dSKonstantin Belousov #define SIZEOF_SAGAW_BITS (sizeof(sagaw_bits) / sizeof(sagaw_bits[0])) 10486be9f0dSKonstantin Belousov 10586be9f0dSKonstantin Belousov bool 10686be9f0dSKonstantin Belousov dmar_pglvl_supported(struct dmar_unit *unit, int pglvl) 10786be9f0dSKonstantin Belousov { 10886be9f0dSKonstantin Belousov int i; 10986be9f0dSKonstantin Belousov 11086be9f0dSKonstantin Belousov for (i = 0; i < SIZEOF_SAGAW_BITS; i++) { 11186be9f0dSKonstantin Belousov if (sagaw_bits[i].pglvl != pglvl) 11286be9f0dSKonstantin Belousov continue; 11386be9f0dSKonstantin Belousov if ((DMAR_CAP_SAGAW(unit->hw_cap) & sagaw_bits[i].cap) != 0) 11486be9f0dSKonstantin Belousov return (true); 11586be9f0dSKonstantin Belousov } 11686be9f0dSKonstantin Belousov return (false); 11786be9f0dSKonstantin Belousov } 11886be9f0dSKonstantin Belousov 11986be9f0dSKonstantin Belousov int 12086be9f0dSKonstantin Belousov ctx_set_agaw(struct dmar_ctx *ctx, int mgaw) 12186be9f0dSKonstantin Belousov { 12286be9f0dSKonstantin Belousov int sagaw, i; 12386be9f0dSKonstantin Belousov 12486be9f0dSKonstantin Belousov ctx->mgaw = mgaw; 12586be9f0dSKonstantin Belousov sagaw = DMAR_CAP_SAGAW(ctx->dmar->hw_cap); 12686be9f0dSKonstantin Belousov for (i = 0; i < SIZEOF_SAGAW_BITS; i++) { 12786be9f0dSKonstantin Belousov if (sagaw_bits[i].agaw >= mgaw) { 12886be9f0dSKonstantin Belousov ctx->agaw = sagaw_bits[i].agaw; 12986be9f0dSKonstantin Belousov ctx->pglvl = sagaw_bits[i].pglvl; 13086be9f0dSKonstantin Belousov ctx->awlvl = sagaw_bits[i].awlvl; 13186be9f0dSKonstantin Belousov return (0); 13286be9f0dSKonstantin Belousov } 13386be9f0dSKonstantin Belousov } 13486be9f0dSKonstantin Belousov device_printf(ctx->dmar->dev, 13586be9f0dSKonstantin Belousov "context request mgaw %d for pci%d:%d:%d:%d, " 13667499354SRyan Stone "no agaw found, sagaw %x\n", mgaw, ctx->dmar->segment, 13767499354SRyan Stone pci_get_bus(ctx->ctx_tag.owner), 13867499354SRyan Stone pci_get_slot(ctx->ctx_tag.owner), 13967499354SRyan Stone pci_get_function(ctx->ctx_tag.owner), sagaw); 14086be9f0dSKonstantin Belousov return (EINVAL); 14186be9f0dSKonstantin Belousov } 14286be9f0dSKonstantin Belousov 14386be9f0dSKonstantin Belousov /* 14486be9f0dSKonstantin Belousov * Find a best fit mgaw for the given maxaddr: 14586be9f0dSKonstantin Belousov * - if allow_less is false, must find sagaw which maps all requested 14686be9f0dSKonstantin Belousov * addresses (used by identity mappings); 14786be9f0dSKonstantin Belousov * - if allow_less is true, and no supported sagaw can map all requested 14886be9f0dSKonstantin Belousov * address space, accept the biggest sagaw, whatever is it. 14986be9f0dSKonstantin Belousov */ 15086be9f0dSKonstantin Belousov int 15186be9f0dSKonstantin Belousov dmar_maxaddr2mgaw(struct dmar_unit *unit, dmar_gaddr_t maxaddr, bool allow_less) 15286be9f0dSKonstantin Belousov { 15386be9f0dSKonstantin Belousov int i; 15486be9f0dSKonstantin Belousov 15586be9f0dSKonstantin Belousov for (i = 0; i < SIZEOF_SAGAW_BITS; i++) { 15686be9f0dSKonstantin Belousov if ((1ULL << sagaw_bits[i].agaw) >= maxaddr && 15786be9f0dSKonstantin Belousov (DMAR_CAP_SAGAW(unit->hw_cap) & sagaw_bits[i].cap) != 0) 15886be9f0dSKonstantin Belousov break; 15986be9f0dSKonstantin Belousov } 16086be9f0dSKonstantin Belousov if (allow_less && i == SIZEOF_SAGAW_BITS) { 16186be9f0dSKonstantin Belousov do { 16286be9f0dSKonstantin Belousov i--; 16386be9f0dSKonstantin Belousov } while ((DMAR_CAP_SAGAW(unit->hw_cap) & sagaw_bits[i].cap) 16486be9f0dSKonstantin Belousov == 0); 16586be9f0dSKonstantin Belousov } 16686be9f0dSKonstantin Belousov if (i < SIZEOF_SAGAW_BITS) 16786be9f0dSKonstantin Belousov return (sagaw_bits[i].agaw); 16886be9f0dSKonstantin Belousov KASSERT(0, ("no mgaw for maxaddr %jx allow_less %d", 16986be9f0dSKonstantin Belousov (uintmax_t) maxaddr, allow_less)); 17086be9f0dSKonstantin Belousov return (-1); 17186be9f0dSKonstantin Belousov } 17286be9f0dSKonstantin Belousov 17386be9f0dSKonstantin Belousov /* 17486be9f0dSKonstantin Belousov * Calculate the total amount of page table pages needed to map the 17586be9f0dSKonstantin Belousov * whole bus address space on the context with the selected agaw. 17686be9f0dSKonstantin Belousov */ 17786be9f0dSKonstantin Belousov vm_pindex_t 17886be9f0dSKonstantin Belousov pglvl_max_pages(int pglvl) 17986be9f0dSKonstantin Belousov { 18086be9f0dSKonstantin Belousov vm_pindex_t res; 18186be9f0dSKonstantin Belousov int i; 18286be9f0dSKonstantin Belousov 18386be9f0dSKonstantin Belousov for (res = 0, i = pglvl; i > 0; i--) { 18486be9f0dSKonstantin Belousov res *= DMAR_NPTEPG; 18586be9f0dSKonstantin Belousov res++; 18686be9f0dSKonstantin Belousov } 18786be9f0dSKonstantin Belousov return (res); 18886be9f0dSKonstantin Belousov } 18986be9f0dSKonstantin Belousov 19086be9f0dSKonstantin Belousov /* 19186be9f0dSKonstantin Belousov * Return true if the page table level lvl supports the superpage for 19286be9f0dSKonstantin Belousov * the context ctx. 19386be9f0dSKonstantin Belousov */ 19486be9f0dSKonstantin Belousov int 19586be9f0dSKonstantin Belousov ctx_is_sp_lvl(struct dmar_ctx *ctx, int lvl) 19686be9f0dSKonstantin Belousov { 19786be9f0dSKonstantin Belousov int alvl, cap_sps; 19886be9f0dSKonstantin Belousov static const int sagaw_sp[] = { 19986be9f0dSKonstantin Belousov DMAR_CAP_SPS_2M, 20086be9f0dSKonstantin Belousov DMAR_CAP_SPS_1G, 20186be9f0dSKonstantin Belousov DMAR_CAP_SPS_512G, 20286be9f0dSKonstantin Belousov DMAR_CAP_SPS_1T 20386be9f0dSKonstantin Belousov }; 20486be9f0dSKonstantin Belousov 20586be9f0dSKonstantin Belousov alvl = ctx->pglvl - lvl - 1; 20686be9f0dSKonstantin Belousov cap_sps = DMAR_CAP_SPS(ctx->dmar->hw_cap); 20786be9f0dSKonstantin Belousov return (alvl < sizeof(sagaw_sp) / sizeof(sagaw_sp[0]) && 20886be9f0dSKonstantin Belousov (sagaw_sp[alvl] & cap_sps) != 0); 20986be9f0dSKonstantin Belousov } 21086be9f0dSKonstantin Belousov 21186be9f0dSKonstantin Belousov dmar_gaddr_t 21286be9f0dSKonstantin Belousov pglvl_page_size(int total_pglvl, int lvl) 21386be9f0dSKonstantin Belousov { 21486be9f0dSKonstantin Belousov int rlvl; 21586be9f0dSKonstantin Belousov static const dmar_gaddr_t pg_sz[] = { 21686be9f0dSKonstantin Belousov (dmar_gaddr_t)DMAR_PAGE_SIZE, 21786be9f0dSKonstantin Belousov (dmar_gaddr_t)DMAR_PAGE_SIZE << DMAR_NPTEPGSHIFT, 21886be9f0dSKonstantin Belousov (dmar_gaddr_t)DMAR_PAGE_SIZE << (2 * DMAR_NPTEPGSHIFT), 21986be9f0dSKonstantin Belousov (dmar_gaddr_t)DMAR_PAGE_SIZE << (3 * DMAR_NPTEPGSHIFT), 22086be9f0dSKonstantin Belousov (dmar_gaddr_t)DMAR_PAGE_SIZE << (4 * DMAR_NPTEPGSHIFT), 22186be9f0dSKonstantin Belousov (dmar_gaddr_t)DMAR_PAGE_SIZE << (5 * DMAR_NPTEPGSHIFT) 22286be9f0dSKonstantin Belousov }; 22386be9f0dSKonstantin Belousov 22486be9f0dSKonstantin Belousov KASSERT(lvl >= 0 && lvl < total_pglvl, 22586be9f0dSKonstantin Belousov ("total %d lvl %d", total_pglvl, lvl)); 22686be9f0dSKonstantin Belousov rlvl = total_pglvl - lvl - 1; 22786be9f0dSKonstantin Belousov KASSERT(rlvl < sizeof(pg_sz) / sizeof(pg_sz[0]), 22886be9f0dSKonstantin Belousov ("sizeof pg_sz lvl %d", lvl)); 22986be9f0dSKonstantin Belousov return (pg_sz[rlvl]); 23086be9f0dSKonstantin Belousov } 23186be9f0dSKonstantin Belousov 23286be9f0dSKonstantin Belousov dmar_gaddr_t 23386be9f0dSKonstantin Belousov ctx_page_size(struct dmar_ctx *ctx, int lvl) 23486be9f0dSKonstantin Belousov { 23586be9f0dSKonstantin Belousov 23686be9f0dSKonstantin Belousov return (pglvl_page_size(ctx->pglvl, lvl)); 23786be9f0dSKonstantin Belousov } 23886be9f0dSKonstantin Belousov 23968eeb96aSKonstantin Belousov int 24068eeb96aSKonstantin Belousov calc_am(struct dmar_unit *unit, dmar_gaddr_t base, dmar_gaddr_t size, 24168eeb96aSKonstantin Belousov dmar_gaddr_t *isizep) 24268eeb96aSKonstantin Belousov { 24368eeb96aSKonstantin Belousov dmar_gaddr_t isize; 24468eeb96aSKonstantin Belousov int am; 24568eeb96aSKonstantin Belousov 24668eeb96aSKonstantin Belousov for (am = DMAR_CAP_MAMV(unit->hw_cap);; am--) { 24768eeb96aSKonstantin Belousov isize = 1ULL << (am + DMAR_PAGE_SHIFT); 24868eeb96aSKonstantin Belousov if ((base & (isize - 1)) == 0 && size >= isize) 24968eeb96aSKonstantin Belousov break; 25068eeb96aSKonstantin Belousov if (am == 0) 25168eeb96aSKonstantin Belousov break; 25268eeb96aSKonstantin Belousov } 25368eeb96aSKonstantin Belousov *isizep = isize; 25468eeb96aSKonstantin Belousov return (am); 25568eeb96aSKonstantin Belousov } 25668eeb96aSKonstantin Belousov 25786be9f0dSKonstantin Belousov dmar_haddr_t dmar_high; 25886be9f0dSKonstantin Belousov int haw; 25986be9f0dSKonstantin Belousov int dmar_tbl_pagecnt; 26086be9f0dSKonstantin Belousov 26186be9f0dSKonstantin Belousov vm_page_t 26286be9f0dSKonstantin Belousov dmar_pgalloc(vm_object_t obj, vm_pindex_t idx, int flags) 26386be9f0dSKonstantin Belousov { 26486be9f0dSKonstantin Belousov vm_page_t m; 26586be9f0dSKonstantin Belousov int zeroed; 26686be9f0dSKonstantin Belousov 26786be9f0dSKonstantin Belousov zeroed = (flags & DMAR_PGF_ZERO) != 0 ? VM_ALLOC_ZERO : 0; 26886be9f0dSKonstantin Belousov for (;;) { 26986be9f0dSKonstantin Belousov if ((flags & DMAR_PGF_OBJL) == 0) 27086be9f0dSKonstantin Belousov VM_OBJECT_WLOCK(obj); 27186be9f0dSKonstantin Belousov m = vm_page_lookup(obj, idx); 27286be9f0dSKonstantin Belousov if ((flags & DMAR_PGF_NOALLOC) != 0 || m != NULL) { 27386be9f0dSKonstantin Belousov if ((flags & DMAR_PGF_OBJL) == 0) 27486be9f0dSKonstantin Belousov VM_OBJECT_WUNLOCK(obj); 27586be9f0dSKonstantin Belousov break; 27686be9f0dSKonstantin Belousov } 27786be9f0dSKonstantin Belousov m = vm_page_alloc_contig(obj, idx, VM_ALLOC_NOBUSY | 27886be9f0dSKonstantin Belousov VM_ALLOC_SYSTEM | VM_ALLOC_NODUMP | zeroed, 1, 0, 27986be9f0dSKonstantin Belousov dmar_high, PAGE_SIZE, 0, VM_MEMATTR_DEFAULT); 28086be9f0dSKonstantin Belousov if ((flags & DMAR_PGF_OBJL) == 0) 28186be9f0dSKonstantin Belousov VM_OBJECT_WUNLOCK(obj); 28286be9f0dSKonstantin Belousov if (m != NULL) { 28386be9f0dSKonstantin Belousov if (zeroed && (m->flags & PG_ZERO) == 0) 28486be9f0dSKonstantin Belousov pmap_zero_page(m); 28586be9f0dSKonstantin Belousov atomic_add_int(&dmar_tbl_pagecnt, 1); 28686be9f0dSKonstantin Belousov break; 28786be9f0dSKonstantin Belousov } 28886be9f0dSKonstantin Belousov if ((flags & DMAR_PGF_WAITOK) == 0) 28986be9f0dSKonstantin Belousov break; 29086be9f0dSKonstantin Belousov if ((flags & DMAR_PGF_OBJL) != 0) 29186be9f0dSKonstantin Belousov VM_OBJECT_WUNLOCK(obj); 29286be9f0dSKonstantin Belousov VM_WAIT; 29386be9f0dSKonstantin Belousov if ((flags & DMAR_PGF_OBJL) != 0) 29486be9f0dSKonstantin Belousov VM_OBJECT_WLOCK(obj); 29586be9f0dSKonstantin Belousov } 29686be9f0dSKonstantin Belousov return (m); 29786be9f0dSKonstantin Belousov } 29886be9f0dSKonstantin Belousov 29986be9f0dSKonstantin Belousov void 30086be9f0dSKonstantin Belousov dmar_pgfree(vm_object_t obj, vm_pindex_t idx, int flags) 30186be9f0dSKonstantin Belousov { 30286be9f0dSKonstantin Belousov vm_page_t m; 30386be9f0dSKonstantin Belousov 30486be9f0dSKonstantin Belousov if ((flags & DMAR_PGF_OBJL) == 0) 30586be9f0dSKonstantin Belousov VM_OBJECT_WLOCK(obj); 30686be9f0dSKonstantin Belousov m = vm_page_lookup(obj, idx); 30786be9f0dSKonstantin Belousov if (m != NULL) { 30886be9f0dSKonstantin Belousov vm_page_free(m); 30986be9f0dSKonstantin Belousov atomic_subtract_int(&dmar_tbl_pagecnt, 1); 31086be9f0dSKonstantin Belousov } 31186be9f0dSKonstantin Belousov if ((flags & DMAR_PGF_OBJL) == 0) 31286be9f0dSKonstantin Belousov VM_OBJECT_WUNLOCK(obj); 31386be9f0dSKonstantin Belousov } 31486be9f0dSKonstantin Belousov 31586be9f0dSKonstantin Belousov void * 31686be9f0dSKonstantin Belousov dmar_map_pgtbl(vm_object_t obj, vm_pindex_t idx, int flags, 31786be9f0dSKonstantin Belousov struct sf_buf **sf) 31886be9f0dSKonstantin Belousov { 31986be9f0dSKonstantin Belousov vm_page_t m; 32086be9f0dSKonstantin Belousov bool allocated; 32186be9f0dSKonstantin Belousov 32286be9f0dSKonstantin Belousov if ((flags & DMAR_PGF_OBJL) == 0) 32386be9f0dSKonstantin Belousov VM_OBJECT_WLOCK(obj); 32486be9f0dSKonstantin Belousov m = vm_page_lookup(obj, idx); 32586be9f0dSKonstantin Belousov if (m == NULL && (flags & DMAR_PGF_ALLOC) != 0) { 32686be9f0dSKonstantin Belousov m = dmar_pgalloc(obj, idx, flags | DMAR_PGF_OBJL); 32786be9f0dSKonstantin Belousov allocated = true; 32886be9f0dSKonstantin Belousov } else 32986be9f0dSKonstantin Belousov allocated = false; 33086be9f0dSKonstantin Belousov if (m == NULL) { 33186be9f0dSKonstantin Belousov if ((flags & DMAR_PGF_OBJL) == 0) 33286be9f0dSKonstantin Belousov VM_OBJECT_WUNLOCK(obj); 33386be9f0dSKonstantin Belousov return (NULL); 33486be9f0dSKonstantin Belousov } 33586be9f0dSKonstantin Belousov /* Sleepable allocations cannot fail. */ 33686be9f0dSKonstantin Belousov if ((flags & DMAR_PGF_WAITOK) != 0) 33786be9f0dSKonstantin Belousov VM_OBJECT_WUNLOCK(obj); 33886be9f0dSKonstantin Belousov sched_pin(); 33986be9f0dSKonstantin Belousov *sf = sf_buf_alloc(m, SFB_CPUPRIVATE | ((flags & DMAR_PGF_WAITOK) 34086be9f0dSKonstantin Belousov == 0 ? SFB_NOWAIT : 0)); 34186be9f0dSKonstantin Belousov if (*sf == NULL) { 34286be9f0dSKonstantin Belousov sched_unpin(); 34386be9f0dSKonstantin Belousov if (allocated) { 34486be9f0dSKonstantin Belousov VM_OBJECT_ASSERT_WLOCKED(obj); 34586be9f0dSKonstantin Belousov dmar_pgfree(obj, m->pindex, flags | DMAR_PGF_OBJL); 34686be9f0dSKonstantin Belousov } 34786be9f0dSKonstantin Belousov if ((flags & DMAR_PGF_OBJL) == 0) 34886be9f0dSKonstantin Belousov VM_OBJECT_WUNLOCK(obj); 34986be9f0dSKonstantin Belousov return (NULL); 35086be9f0dSKonstantin Belousov } 35186be9f0dSKonstantin Belousov if ((flags & (DMAR_PGF_WAITOK | DMAR_PGF_OBJL)) == 35286be9f0dSKonstantin Belousov (DMAR_PGF_WAITOK | DMAR_PGF_OBJL)) 35386be9f0dSKonstantin Belousov VM_OBJECT_WLOCK(obj); 35486be9f0dSKonstantin Belousov else if ((flags & (DMAR_PGF_WAITOK | DMAR_PGF_OBJL)) == 0) 35586be9f0dSKonstantin Belousov VM_OBJECT_WUNLOCK(obj); 35686be9f0dSKonstantin Belousov return ((void *)sf_buf_kva(*sf)); 35786be9f0dSKonstantin Belousov } 35886be9f0dSKonstantin Belousov 35986be9f0dSKonstantin Belousov void 3606b7c46afSKonstantin Belousov dmar_unmap_pgtbl(struct sf_buf *sf) 36186be9f0dSKonstantin Belousov { 36286be9f0dSKonstantin Belousov 36386be9f0dSKonstantin Belousov sf_buf_free(sf); 36486be9f0dSKonstantin Belousov sched_unpin(); 3656b7c46afSKonstantin Belousov } 36686be9f0dSKonstantin Belousov 3676b7c46afSKonstantin Belousov static void 3686b7c46afSKonstantin Belousov dmar_flush_transl_to_ram(struct dmar_unit *unit, void *dst, size_t sz) 3696b7c46afSKonstantin Belousov { 3706b7c46afSKonstantin Belousov 3716b7c46afSKonstantin Belousov if (DMAR_IS_COHERENT(unit)) 3726b7c46afSKonstantin Belousov return; 37386be9f0dSKonstantin Belousov /* 37486be9f0dSKonstantin Belousov * If DMAR does not snoop paging structures accesses, flush 37586be9f0dSKonstantin Belousov * CPU cache to memory. 37686be9f0dSKonstantin Belousov */ 3776b7c46afSKonstantin Belousov pmap_invalidate_cache_range((uintptr_t)dst, (uintptr_t)dst + sz, 3786b7c46afSKonstantin Belousov TRUE); 3796b7c46afSKonstantin Belousov } 3806b7c46afSKonstantin Belousov 3816b7c46afSKonstantin Belousov void 3826b7c46afSKonstantin Belousov dmar_flush_pte_to_ram(struct dmar_unit *unit, dmar_pte_t *dst) 3836b7c46afSKonstantin Belousov { 3846b7c46afSKonstantin Belousov 3856b7c46afSKonstantin Belousov dmar_flush_transl_to_ram(unit, dst, sizeof(*dst)); 3866b7c46afSKonstantin Belousov } 3876b7c46afSKonstantin Belousov 3886b7c46afSKonstantin Belousov void 3896b7c46afSKonstantin Belousov dmar_flush_ctx_to_ram(struct dmar_unit *unit, dmar_ctx_entry_t *dst) 3906b7c46afSKonstantin Belousov { 3916b7c46afSKonstantin Belousov 3926b7c46afSKonstantin Belousov dmar_flush_transl_to_ram(unit, dst, sizeof(*dst)); 3936b7c46afSKonstantin Belousov } 3946b7c46afSKonstantin Belousov 3956b7c46afSKonstantin Belousov void 3966b7c46afSKonstantin Belousov dmar_flush_root_to_ram(struct dmar_unit *unit, dmar_root_entry_t *dst) 3976b7c46afSKonstantin Belousov { 3986b7c46afSKonstantin Belousov 3996b7c46afSKonstantin Belousov dmar_flush_transl_to_ram(unit, dst, sizeof(*dst)); 40086be9f0dSKonstantin Belousov } 40186be9f0dSKonstantin Belousov 40286be9f0dSKonstantin Belousov /* 40386be9f0dSKonstantin Belousov * Load the root entry pointer into the hardware, busily waiting for 40486be9f0dSKonstantin Belousov * the completion. 40586be9f0dSKonstantin Belousov */ 40686be9f0dSKonstantin Belousov int 40786be9f0dSKonstantin Belousov dmar_load_root_entry_ptr(struct dmar_unit *unit) 40886be9f0dSKonstantin Belousov { 40986be9f0dSKonstantin Belousov vm_page_t root_entry; 41086be9f0dSKonstantin Belousov 41186be9f0dSKonstantin Belousov /* 41286be9f0dSKonstantin Belousov * Access to the GCMD register must be serialized while the 41386be9f0dSKonstantin Belousov * command is submitted. 41486be9f0dSKonstantin Belousov */ 41586be9f0dSKonstantin Belousov DMAR_ASSERT_LOCKED(unit); 41686be9f0dSKonstantin Belousov 4175a49ae8eSKonstantin Belousov VM_OBJECT_RLOCK(unit->ctx_obj); 41886be9f0dSKonstantin Belousov root_entry = vm_page_lookup(unit->ctx_obj, 0); 4195a49ae8eSKonstantin Belousov VM_OBJECT_RUNLOCK(unit->ctx_obj); 42086be9f0dSKonstantin Belousov dmar_write8(unit, DMAR_RTADDR_REG, VM_PAGE_TO_PHYS(root_entry)); 42186be9f0dSKonstantin Belousov dmar_write4(unit, DMAR_GCMD_REG, unit->hw_gcmd | DMAR_GCMD_SRTP); 42286be9f0dSKonstantin Belousov /* XXXKIB should have a timeout */ 42386be9f0dSKonstantin Belousov while ((dmar_read4(unit, DMAR_GSTS_REG) & DMAR_GSTS_RTPS) == 0) 42486be9f0dSKonstantin Belousov cpu_spinwait(); 42586be9f0dSKonstantin Belousov return (0); 42686be9f0dSKonstantin Belousov } 42786be9f0dSKonstantin Belousov 42886be9f0dSKonstantin Belousov /* 42986be9f0dSKonstantin Belousov * Globally invalidate the context entries cache, busily waiting for 43086be9f0dSKonstantin Belousov * the completion. 43186be9f0dSKonstantin Belousov */ 43286be9f0dSKonstantin Belousov int 43386be9f0dSKonstantin Belousov dmar_inv_ctx_glob(struct dmar_unit *unit) 43486be9f0dSKonstantin Belousov { 43586be9f0dSKonstantin Belousov 43686be9f0dSKonstantin Belousov /* 43786be9f0dSKonstantin Belousov * Access to the CCMD register must be serialized while the 43886be9f0dSKonstantin Belousov * command is submitted. 43986be9f0dSKonstantin Belousov */ 44086be9f0dSKonstantin Belousov DMAR_ASSERT_LOCKED(unit); 44168eeb96aSKonstantin Belousov KASSERT(!unit->qi_enabled, ("QI enabled")); 44286be9f0dSKonstantin Belousov 44386be9f0dSKonstantin Belousov /* 44486be9f0dSKonstantin Belousov * The DMAR_CCMD_ICC bit in the upper dword should be written 44586be9f0dSKonstantin Belousov * after the low dword write is completed. Amd64 44686be9f0dSKonstantin Belousov * dmar_write8() does not have this issue, i386 dmar_write8() 44786be9f0dSKonstantin Belousov * writes the upper dword last. 44886be9f0dSKonstantin Belousov */ 44986be9f0dSKonstantin Belousov dmar_write8(unit, DMAR_CCMD_REG, DMAR_CCMD_ICC | DMAR_CCMD_CIRG_GLOB); 45086be9f0dSKonstantin Belousov /* XXXKIB should have a timeout */ 45186be9f0dSKonstantin Belousov while ((dmar_read4(unit, DMAR_CCMD_REG + 4) & DMAR_CCMD_ICC32) != 0) 45286be9f0dSKonstantin Belousov cpu_spinwait(); 45386be9f0dSKonstantin Belousov return (0); 45486be9f0dSKonstantin Belousov } 45586be9f0dSKonstantin Belousov 45686be9f0dSKonstantin Belousov /* 45786be9f0dSKonstantin Belousov * Globally invalidate the IOTLB, busily waiting for the completion. 45886be9f0dSKonstantin Belousov */ 45986be9f0dSKonstantin Belousov int 46086be9f0dSKonstantin Belousov dmar_inv_iotlb_glob(struct dmar_unit *unit) 46186be9f0dSKonstantin Belousov { 46286be9f0dSKonstantin Belousov int reg; 46386be9f0dSKonstantin Belousov 46486be9f0dSKonstantin Belousov DMAR_ASSERT_LOCKED(unit); 46568eeb96aSKonstantin Belousov KASSERT(!unit->qi_enabled, ("QI enabled")); 46686be9f0dSKonstantin Belousov 46786be9f0dSKonstantin Belousov reg = 16 * DMAR_ECAP_IRO(unit->hw_ecap); 46886be9f0dSKonstantin Belousov /* See a comment about DMAR_CCMD_ICC in dmar_inv_ctx_glob. */ 46986be9f0dSKonstantin Belousov dmar_write8(unit, reg + DMAR_IOTLB_REG_OFF, DMAR_IOTLB_IVT | 47086be9f0dSKonstantin Belousov DMAR_IOTLB_IIRG_GLB | DMAR_IOTLB_DR | DMAR_IOTLB_DW); 47186be9f0dSKonstantin Belousov /* XXXKIB should have a timeout */ 47286be9f0dSKonstantin Belousov while ((dmar_read4(unit, reg + DMAR_IOTLB_REG_OFF + 4) & 47386be9f0dSKonstantin Belousov DMAR_IOTLB_IVT32) != 0) 47486be9f0dSKonstantin Belousov cpu_spinwait(); 47586be9f0dSKonstantin Belousov return (0); 47686be9f0dSKonstantin Belousov } 47786be9f0dSKonstantin Belousov 47886be9f0dSKonstantin Belousov /* 47986be9f0dSKonstantin Belousov * Flush the chipset write buffers. See 11.1 "Write Buffer Flushing" 48086be9f0dSKonstantin Belousov * in the architecture specification. 48186be9f0dSKonstantin Belousov */ 48286be9f0dSKonstantin Belousov int 48386be9f0dSKonstantin Belousov dmar_flush_write_bufs(struct dmar_unit *unit) 48486be9f0dSKonstantin Belousov { 48586be9f0dSKonstantin Belousov 48686be9f0dSKonstantin Belousov DMAR_ASSERT_LOCKED(unit); 48786be9f0dSKonstantin Belousov 48886be9f0dSKonstantin Belousov /* 48986be9f0dSKonstantin Belousov * DMAR_GCMD_WBF is only valid when CAP_RWBF is reported. 49086be9f0dSKonstantin Belousov */ 49186be9f0dSKonstantin Belousov KASSERT((unit->hw_cap & DMAR_CAP_RWBF) != 0, 49286be9f0dSKonstantin Belousov ("dmar%d: no RWBF", unit->unit)); 49386be9f0dSKonstantin Belousov 49486be9f0dSKonstantin Belousov dmar_write4(unit, DMAR_GCMD_REG, unit->hw_gcmd | DMAR_GCMD_WBF); 49586be9f0dSKonstantin Belousov /* XXXKIB should have a timeout */ 49686be9f0dSKonstantin Belousov while ((dmar_read4(unit, DMAR_GSTS_REG) & DMAR_GSTS_WBFS) == 0) 49786be9f0dSKonstantin Belousov cpu_spinwait(); 49886be9f0dSKonstantin Belousov return (0); 49986be9f0dSKonstantin Belousov } 50086be9f0dSKonstantin Belousov 50186be9f0dSKonstantin Belousov int 50286be9f0dSKonstantin Belousov dmar_enable_translation(struct dmar_unit *unit) 50386be9f0dSKonstantin Belousov { 50486be9f0dSKonstantin Belousov 50586be9f0dSKonstantin Belousov DMAR_ASSERT_LOCKED(unit); 50686be9f0dSKonstantin Belousov unit->hw_gcmd |= DMAR_GCMD_TE; 50786be9f0dSKonstantin Belousov dmar_write4(unit, DMAR_GCMD_REG, unit->hw_gcmd); 50886be9f0dSKonstantin Belousov /* XXXKIB should have a timeout */ 50986be9f0dSKonstantin Belousov while ((dmar_read4(unit, DMAR_GSTS_REG) & DMAR_GSTS_TES) == 0) 51086be9f0dSKonstantin Belousov cpu_spinwait(); 51186be9f0dSKonstantin Belousov return (0); 51286be9f0dSKonstantin Belousov } 51386be9f0dSKonstantin Belousov 51486be9f0dSKonstantin Belousov int 51586be9f0dSKonstantin Belousov dmar_disable_translation(struct dmar_unit *unit) 51686be9f0dSKonstantin Belousov { 51786be9f0dSKonstantin Belousov 51886be9f0dSKonstantin Belousov DMAR_ASSERT_LOCKED(unit); 51986be9f0dSKonstantin Belousov unit->hw_gcmd &= ~DMAR_GCMD_TE; 52086be9f0dSKonstantin Belousov dmar_write4(unit, DMAR_GCMD_REG, unit->hw_gcmd); 52186be9f0dSKonstantin Belousov /* XXXKIB should have a timeout */ 52286be9f0dSKonstantin Belousov while ((dmar_read4(unit, DMAR_GSTS_REG) & DMAR_GSTS_TES) != 0) 52386be9f0dSKonstantin Belousov cpu_spinwait(); 52486be9f0dSKonstantin Belousov return (0); 52586be9f0dSKonstantin Belousov } 52686be9f0dSKonstantin Belousov 527*0a110d5bSKonstantin Belousov int 528*0a110d5bSKonstantin Belousov dmar_load_irt_ptr(struct dmar_unit *unit) 529*0a110d5bSKonstantin Belousov { 530*0a110d5bSKonstantin Belousov uint64_t irta, s; 531*0a110d5bSKonstantin Belousov 532*0a110d5bSKonstantin Belousov DMAR_ASSERT_LOCKED(unit); 533*0a110d5bSKonstantin Belousov irta = unit->irt_phys; 534*0a110d5bSKonstantin Belousov if (DMAR_X2APIC(unit)) 535*0a110d5bSKonstantin Belousov irta |= DMAR_IRTA_EIME; 536*0a110d5bSKonstantin Belousov s = fls(unit->irte_cnt) - 2; 537*0a110d5bSKonstantin Belousov KASSERT(unit->irte_cnt >= 2 && s <= DMAR_IRTA_S_MASK && 538*0a110d5bSKonstantin Belousov powerof2(unit->irte_cnt), 539*0a110d5bSKonstantin Belousov ("IRTA_REG_S overflow %x", unit->irte_cnt)); 540*0a110d5bSKonstantin Belousov irta |= s; 541*0a110d5bSKonstantin Belousov dmar_write8(unit, DMAR_IRTA_REG, irta); 542*0a110d5bSKonstantin Belousov dmar_write4(unit, DMAR_GCMD_REG, unit->hw_gcmd | DMAR_GCMD_SIRTP); 543*0a110d5bSKonstantin Belousov /* XXXKIB should have a timeout */ 544*0a110d5bSKonstantin Belousov while ((dmar_read4(unit, DMAR_GSTS_REG) & DMAR_GSTS_IRTPS) == 0) 545*0a110d5bSKonstantin Belousov cpu_spinwait(); 546*0a110d5bSKonstantin Belousov return (0); 547*0a110d5bSKonstantin Belousov } 548*0a110d5bSKonstantin Belousov 549*0a110d5bSKonstantin Belousov int 550*0a110d5bSKonstantin Belousov dmar_enable_ir(struct dmar_unit *unit) 551*0a110d5bSKonstantin Belousov { 552*0a110d5bSKonstantin Belousov 553*0a110d5bSKonstantin Belousov DMAR_ASSERT_LOCKED(unit); 554*0a110d5bSKonstantin Belousov unit->hw_gcmd |= DMAR_GCMD_IRE; 555*0a110d5bSKonstantin Belousov unit->hw_gcmd &= ~DMAR_GCMD_CFI; 556*0a110d5bSKonstantin Belousov dmar_write4(unit, DMAR_GCMD_REG, unit->hw_gcmd); 557*0a110d5bSKonstantin Belousov /* XXXKIB should have a timeout */ 558*0a110d5bSKonstantin Belousov while ((dmar_read4(unit, DMAR_GSTS_REG) & DMAR_GSTS_IRES) == 0) 559*0a110d5bSKonstantin Belousov cpu_spinwait(); 560*0a110d5bSKonstantin Belousov return (0); 561*0a110d5bSKonstantin Belousov } 562*0a110d5bSKonstantin Belousov 563*0a110d5bSKonstantin Belousov int 564*0a110d5bSKonstantin Belousov dmar_disable_ir(struct dmar_unit *unit) 565*0a110d5bSKonstantin Belousov { 566*0a110d5bSKonstantin Belousov 567*0a110d5bSKonstantin Belousov DMAR_ASSERT_LOCKED(unit); 568*0a110d5bSKonstantin Belousov unit->hw_gcmd &= ~DMAR_GCMD_IRE; 569*0a110d5bSKonstantin Belousov dmar_write4(unit, DMAR_GCMD_REG, unit->hw_gcmd); 570*0a110d5bSKonstantin Belousov /* XXXKIB should have a timeout */ 571*0a110d5bSKonstantin Belousov while ((dmar_read4(unit, DMAR_GSTS_REG) & DMAR_GSTS_IRES) != 0) 572*0a110d5bSKonstantin Belousov cpu_spinwait(); 573*0a110d5bSKonstantin Belousov return (0); 574*0a110d5bSKonstantin Belousov } 575*0a110d5bSKonstantin Belousov 57686be9f0dSKonstantin Belousov #define BARRIER_F \ 57786be9f0dSKonstantin Belousov u_int f_done, f_inproc, f_wakeup; \ 57886be9f0dSKonstantin Belousov \ 57986be9f0dSKonstantin Belousov f_done = 1 << (barrier_id * 3); \ 58086be9f0dSKonstantin Belousov f_inproc = 1 << (barrier_id * 3 + 1); \ 58186be9f0dSKonstantin Belousov f_wakeup = 1 << (barrier_id * 3 + 2) 58286be9f0dSKonstantin Belousov 58386be9f0dSKonstantin Belousov bool 58486be9f0dSKonstantin Belousov dmar_barrier_enter(struct dmar_unit *dmar, u_int barrier_id) 58586be9f0dSKonstantin Belousov { 58686be9f0dSKonstantin Belousov BARRIER_F; 58786be9f0dSKonstantin Belousov 58886be9f0dSKonstantin Belousov DMAR_LOCK(dmar); 58986be9f0dSKonstantin Belousov if ((dmar->barrier_flags & f_done) != 0) { 59086be9f0dSKonstantin Belousov DMAR_UNLOCK(dmar); 59186be9f0dSKonstantin Belousov return (false); 59286be9f0dSKonstantin Belousov } 59386be9f0dSKonstantin Belousov 59486be9f0dSKonstantin Belousov if ((dmar->barrier_flags & f_inproc) != 0) { 59586be9f0dSKonstantin Belousov while ((dmar->barrier_flags & f_inproc) != 0) { 59686be9f0dSKonstantin Belousov dmar->barrier_flags |= f_wakeup; 59786be9f0dSKonstantin Belousov msleep(&dmar->barrier_flags, &dmar->lock, 0, 59886be9f0dSKonstantin Belousov "dmarb", 0); 59986be9f0dSKonstantin Belousov } 60086be9f0dSKonstantin Belousov KASSERT((dmar->barrier_flags & f_done) != 0, 60186be9f0dSKonstantin Belousov ("dmar%d barrier %d missing done", dmar->unit, barrier_id)); 60286be9f0dSKonstantin Belousov DMAR_UNLOCK(dmar); 60386be9f0dSKonstantin Belousov return (false); 60486be9f0dSKonstantin Belousov } 60586be9f0dSKonstantin Belousov 60686be9f0dSKonstantin Belousov dmar->barrier_flags |= f_inproc; 60786be9f0dSKonstantin Belousov DMAR_UNLOCK(dmar); 60886be9f0dSKonstantin Belousov return (true); 60986be9f0dSKonstantin Belousov } 61086be9f0dSKonstantin Belousov 61186be9f0dSKonstantin Belousov void 61286be9f0dSKonstantin Belousov dmar_barrier_exit(struct dmar_unit *dmar, u_int barrier_id) 61386be9f0dSKonstantin Belousov { 61486be9f0dSKonstantin Belousov BARRIER_F; 61586be9f0dSKonstantin Belousov 61686be9f0dSKonstantin Belousov DMAR_ASSERT_LOCKED(dmar); 61786be9f0dSKonstantin Belousov KASSERT((dmar->barrier_flags & (f_done | f_inproc)) == f_inproc, 61886be9f0dSKonstantin Belousov ("dmar%d barrier %d missed entry", dmar->unit, barrier_id)); 61986be9f0dSKonstantin Belousov dmar->barrier_flags |= f_done; 62086be9f0dSKonstantin Belousov if ((dmar->barrier_flags & f_wakeup) != 0) 62186be9f0dSKonstantin Belousov wakeup(&dmar->barrier_flags); 62286be9f0dSKonstantin Belousov dmar->barrier_flags &= ~(f_inproc | f_wakeup); 62386be9f0dSKonstantin Belousov DMAR_UNLOCK(dmar); 62486be9f0dSKonstantin Belousov } 62586be9f0dSKonstantin Belousov 62686be9f0dSKonstantin Belousov int dmar_match_verbose; 62786be9f0dSKonstantin Belousov 628af3b2549SHans Petter Selasky static SYSCTL_NODE(_hw, OID_AUTO, dmar, CTLFLAG_RD, NULL, ""); 629af3b2549SHans Petter Selasky SYSCTL_INT(_hw_dmar, OID_AUTO, tbl_pagecnt, CTLFLAG_RD, 63086be9f0dSKonstantin Belousov &dmar_tbl_pagecnt, 0, 63186be9f0dSKonstantin Belousov "Count of pages used for DMAR pagetables"); 632af3b2549SHans Petter Selasky SYSCTL_INT(_hw_dmar, OID_AUTO, match_verbose, CTLFLAG_RWTUN, 63386be9f0dSKonstantin Belousov &dmar_match_verbose, 0, 63486be9f0dSKonstantin Belousov "Verbose matching of the PCI devices to DMAR paths"); 63586be9f0dSKonstantin Belousov #ifdef INVARIANTS 63686be9f0dSKonstantin Belousov int dmar_check_free; 637af3b2549SHans Petter Selasky SYSCTL_INT(_hw_dmar, OID_AUTO, check_free, CTLFLAG_RWTUN, 63886be9f0dSKonstantin Belousov &dmar_check_free, 0, 63986be9f0dSKonstantin Belousov "Check the GPA RBtree for free_down and free_after validity"); 64086be9f0dSKonstantin Belousov #endif 64186be9f0dSKonstantin Belousov 642