#-1# SPDX-License-Identifier: BSD-2-Clause2#:3# Copyright (c) 2020 Ruslan Bukin <[email protected]>4#5# This software was developed by SRI International and the University of6# Cambridge Computer Laboratory (Department of Computer Science and7# Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the8# DARPA SSITH research programme.9#10# Redistribution and use in source and binary forms, with or without11# modification, are permitted provided that the following conditions12# are met:13# 1. Redistributions of source code must retain the above copyright14# notice, this list of conditions and the following disclaimer.15# 2. Redistributions in binary form must reproduce the above copyright16# notice, this list of conditions and the following disclaimer in the17# documentation and/or other materials provided with the distribution.18#19# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND20# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE21# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE22# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE23# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL24# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS25# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)26# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT27# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY28# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF29# SUCH DAMAGE.30#31#3233#include "opt_platform.h"3435#include <sys/types.h>36#include <sys/taskqueue.h>37#include <sys/bus.h>38#include <sys/sysctl.h>39#include <sys/tree.h>40#include <vm/vm.h>41#include <dev/pci/pcireg.h>42#include <dev/pci/pcivar.h>43#include <dev/iommu/iommu.h>4445#ifdef FDT46#include <dev/fdt/fdt_common.h>47#include <dev/ofw/ofw_bus.h>48#include <dev/ofw/ofw_bus_subr.h>49#endif5051INTERFACE iommu;5253#54# Check if the iommu controller dev is responsible to serve traffic55# for a given child.56#57METHOD int find {58device_t dev;59device_t child;60};6162#63# Map a virtual address VA to a physical address PA.64#65METHOD int map {66device_t dev;67struct iommu_domain *iodom;68vm_offset_t va;69vm_page_t *ma;70bus_size_t size;71vm_prot_t prot;72};7374#75# Unmap a virtual address VA.76#77METHOD int unmap {78device_t dev;79struct iommu_domain *iodom;80vm_offset_t va;81bus_size_t size;82};8384#85# Allocate an IOMMU domain.86#87METHOD struct iommu_domain * domain_alloc {88device_t dev;89struct iommu_unit *iommu;90};9192#93# Release all the resources held by IOMMU domain.94#95METHOD void domain_free {96device_t dev;97struct iommu_domain *iodom;98};99100#101# Find a domain allocated for a dev.102#103METHOD struct iommu_domain * domain_lookup {104device_t dev;105};106107#108# Find an allocated context for a device.109#110METHOD struct iommu_ctx * ctx_lookup {111device_t dev;112device_t child;113};114115#116# Allocate a new iommu context.117#118METHOD struct iommu_ctx * ctx_alloc {119device_t dev;120struct iommu_domain *iodom;121device_t child;122bool disabled;123};124125#126# Initialize the new iommu context.127#128METHOD int ctx_init {129device_t dev;130struct iommu_ctx *ioctx;131};132133#134# Free the iommu context.135#136METHOD void ctx_free {137device_t dev;138struct iommu_ctx *ioctx;139};140141#ifdef FDT142#143# Notify controller we have machine-dependent data.144#145METHOD int ofw_md_data {146device_t dev;147struct iommu_ctx *ioctx;148pcell_t *cells;149int ncells;150};151#endif152153154