Changeset View
Changeset View
Standalone View
Standalone View
sys/amd64/vmm/intel/vtd.c
Show First 20 Lines • Show All 430 Lines • ▼ Show 20 Lines | vtd_disable(void) | ||||
struct vtdmap *vtdmap; | struct vtdmap *vtdmap; | ||||
for (i = 0; i < drhd_num; i++) { | for (i = 0; i < drhd_num; i++) { | ||||
vtdmap = vtdmaps[i]; | vtdmap = vtdmaps[i]; | ||||
vtd_translation_disable(vtdmap); | vtd_translation_disable(vtdmap); | ||||
} | } | ||||
} | } | ||||
static void | static int | ||||
vtd_add_device(void *arg, uint16_t rid) | vtd_add_device(void *arg, device_t dev __unused, uint16_t rid) | ||||
{ | { | ||||
int idx; | int idx; | ||||
uint64_t *ctxp; | uint64_t *ctxp; | ||||
struct domain *dom = arg; | struct domain *dom = arg; | ||||
vm_paddr_t pt_paddr; | vm_paddr_t pt_paddr; | ||||
struct vtdmap *vtdmap; | struct vtdmap *vtdmap; | ||||
uint8_t bus; | uint8_t bus; | ||||
Show All 24 Lines | else | ||||
ctxp[idx] = 0; | ctxp[idx] = 0; | ||||
ctxp[idx] |= pt_paddr | VTD_CTX_PRESENT; | ctxp[idx] |= pt_paddr | VTD_CTX_PRESENT; | ||||
/* | /* | ||||
* 'Not Present' entries are not cached in either the Context Cache | * 'Not Present' entries are not cached in either the Context Cache | ||||
* or in the IOTLB, so there is no need to invalidate either of them. | * or in the IOTLB, so there is no need to invalidate either of them. | ||||
*/ | */ | ||||
return (0); | |||||
} | } | ||||
static void | static int | ||||
vtd_remove_device(void *arg, uint16_t rid) | vtd_remove_device(void *arg, device_t dev __unused, uint16_t rid) | ||||
{ | { | ||||
int i, idx; | int i, idx; | ||||
uint64_t *ctxp; | uint64_t *ctxp; | ||||
struct vtdmap *vtdmap; | struct vtdmap *vtdmap; | ||||
uint8_t bus; | uint8_t bus; | ||||
bus = PCI_RID2BUS(rid); | bus = PCI_RID2BUS(rid); | ||||
ctxp = ctx_tables[bus]; | ctxp = ctx_tables[bus]; | ||||
Show All 11 Lines | vtd_remove_device(void *arg, device_t dev __unused, uint16_t rid) | ||||
* XXX use device-selective invalidation for Context Cache | * XXX use device-selective invalidation for Context Cache | ||||
* XXX use domain-selective invalidation for IOTLB | * XXX use domain-selective invalidation for IOTLB | ||||
*/ | */ | ||||
for (i = 0; i < drhd_num; i++) { | for (i = 0; i < drhd_num; i++) { | ||||
vtdmap = vtdmaps[i]; | vtdmap = vtdmaps[i]; | ||||
vtd_ctx_global_invalidate(vtdmap); | vtd_ctx_global_invalidate(vtdmap); | ||||
vtd_iotlb_global_invalidate(vtdmap); | vtd_iotlb_global_invalidate(vtdmap); | ||||
} | } | ||||
return (0); | |||||
} | } | ||||
#define CREATE_MAPPING 0 | #define CREATE_MAPPING 0 | ||||
#define REMOVE_MAPPING 1 | #define REMOVE_MAPPING 1 | ||||
static uint64_t | static uint64_t | ||||
vtd_update_mapping(void *arg, vm_paddr_t gpa, vm_paddr_t hpa, uint64_t len, | vtd_update_mapping(void *arg, vm_paddr_t gpa, vm_paddr_t hpa, uint64_t len, | ||||
int remove) | int remove) | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | if (remove) { | ||||
if (nlevels > 0) | if (nlevels > 0) | ||||
ptp[ptpindex] |= VTD_PTE_SUPERPAGE; | ptp[ptpindex] |= VTD_PTE_SUPERPAGE; | ||||
} | } | ||||
return (1UL << ptpshift); | return (1UL << ptpshift); | ||||
} | } | ||||
static uint64_t | static int | ||||
vtd_create_mapping(void *arg, vm_paddr_t gpa, vm_paddr_t hpa, uint64_t len) | vtd_create_mapping(void *arg, vm_paddr_t gpa, vm_paddr_t hpa, uint64_t len, | ||||
uint64_t *res_len) | |||||
{ | { | ||||
return (vtd_update_mapping(arg, gpa, hpa, len, CREATE_MAPPING)); | *res_len = vtd_update_mapping(arg, gpa, hpa, len, CREATE_MAPPING); | ||||
return (0); | |||||
} | } | ||||
static uint64_t | static int | ||||
vtd_remove_mapping(void *arg, vm_paddr_t gpa, uint64_t len) | vtd_remove_mapping(void *arg, vm_paddr_t gpa, uint64_t len, uint64_t *res_len) | ||||
{ | { | ||||
return (vtd_update_mapping(arg, gpa, 0, len, REMOVE_MAPPING)); | *res_len = vtd_update_mapping(arg, gpa, 0, len, REMOVE_MAPPING); | ||||
return (0); | |||||
} | } | ||||
static void | static int | ||||
vtd_invalidate_tlb(void *dom) | vtd_invalidate_tlb(void *dom) | ||||
{ | { | ||||
int i; | int i; | ||||
struct vtdmap *vtdmap; | struct vtdmap *vtdmap; | ||||
/* | /* | ||||
* Invalidate the IOTLB. | * Invalidate the IOTLB. | ||||
* XXX use domain-selective invalidation for IOTLB | * XXX use domain-selective invalidation for IOTLB | ||||
*/ | */ | ||||
for (i = 0; i < drhd_num; i++) { | for (i = 0; i < drhd_num; i++) { | ||||
vtdmap = vtdmaps[i]; | vtdmap = vtdmaps[i]; | ||||
vtd_iotlb_global_invalidate(vtdmap); | vtd_iotlb_global_invalidate(vtdmap); | ||||
} | } | ||||
return (0); | |||||
} | } | ||||
static void * | static void * | ||||
vtd_create_domain(vm_paddr_t maxaddr) | vtd_create_domain(vm_paddr_t maxaddr, bool host_domain __unused) | ||||
{ | { | ||||
struct domain *dom; | struct domain *dom; | ||||
vm_paddr_t addr; | vm_paddr_t addr; | ||||
int tmp, i, gaw, agaw, sagaw, res, pt_levels, addrwidth; | int tmp, i, gaw, agaw, sagaw, res, pt_levels, addrwidth; | ||||
struct vtdmap *vtdmap; | struct vtdmap *vtdmap; | ||||
if (drhd_num <= 0) | if (drhd_num <= 0) | ||||
panic("vtd_create_domain: no dma remapping hardware available"); | panic("vtd_create_domain: no dma remapping hardware available"); | ||||
▲ Show 20 Lines • Show All 131 Lines • Show Last 20 Lines |