xref: /freebsd/sys/arm64/iommu/iommu_if.m (revision 315ee00f)
1#-
2# SPDX-License-Identifier: BSD-2-Clause
3#:
4# Copyright (c) 2020 Ruslan Bukin <br@bsdpad.com>
5#
6# This software was developed by SRI International and the University of
7# Cambridge Computer Laboratory (Department of Computer Science and
8# Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the
9# DARPA SSITH research programme.
10#
11# Redistribution and use in source and binary forms, with or without
12# modification, are permitted provided that the following conditions
13# are met:
14# 1. Redistributions of source code must retain the above copyright
15#    notice, this list of conditions and the following disclaimer.
16# 2. Redistributions in binary form must reproduce the above copyright
17#    notice, this list of conditions and the following disclaimer in the
18#    documentation and/or other materials provided with the distribution.
19#
20# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30# SUCH DAMAGE.
31#
32#
33
34#include "opt_platform.h"
35
36#include <sys/types.h>
37#include <sys/taskqueue.h>
38#include <sys/bus.h>
39#include <sys/sysctl.h>
40#include <sys/tree.h>
41#include <vm/vm.h>
42#include <dev/pci/pcireg.h>
43#include <dev/pci/pcivar.h>
44#include <dev/iommu/iommu.h>
45
46#ifdef FDT
47#include <dev/fdt/fdt_common.h>
48#include <dev/ofw/ofw_bus.h>
49#include <dev/ofw/ofw_bus_subr.h>
50#endif
51
52INTERFACE iommu;
53
54#
55# Check if the iommu controller dev is responsible to serve traffic
56# for a given child.
57#
58METHOD int find {
59	device_t		dev;
60	device_t		child;
61};
62
63#
64# Map a virtual address VA to a physical address PA.
65#
66METHOD int map {
67	device_t		dev;
68	struct iommu_domain	*iodom;
69	vm_offset_t		va;
70	vm_page_t		*ma;
71	bus_size_t		size;
72	vm_prot_t		prot;
73};
74
75#
76# Unmap a virtual address VA.
77#
78METHOD int unmap {
79	device_t		dev;
80	struct iommu_domain	*iodom;
81	vm_offset_t		va;
82	bus_size_t		size;
83};
84
85#
86# Allocate an IOMMU domain.
87#
88METHOD struct iommu_domain * domain_alloc {
89	device_t		dev;
90	struct iommu_unit	*iommu;
91};
92
93#
94# Release all the resources held by IOMMU domain.
95#
96METHOD void domain_free {
97	device_t		dev;
98	struct iommu_domain	*iodom;
99};
100
101#
102# Find a domain allocated for a dev.
103#
104METHOD struct iommu_domain * domain_lookup {
105	device_t		dev;
106};
107
108#
109# Find an allocated context for a device.
110#
111METHOD struct iommu_ctx * ctx_lookup {
112	device_t		dev;
113	device_t		child;
114};
115
116#
117# Allocate a new iommu context.
118#
119METHOD struct iommu_ctx * ctx_alloc {
120	device_t		dev;
121	struct iommu_domain	*iodom;
122	device_t		child;
123	bool			disabled;
124};
125
126#
127# Initialize the new iommu context.
128#
129METHOD int ctx_init {
130	device_t		dev;
131	struct iommu_ctx	*ioctx;
132};
133
134#
135# Free the iommu context.
136#
137METHOD void ctx_free {
138	device_t		dev;
139	struct iommu_ctx	*ioctx;
140};
141
142#ifdef FDT
143#
144# Notify controller we have machine-dependent data.
145#
146METHOD int ofw_md_data {
147	device_t dev;
148	struct iommu_ctx *ioctx;
149	pcell_t *cells;
150	int ncells;
151};
152#endif
153