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