• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (C) 2023 Google LLC
4  * Author: Mostafa Saleh <smostafa@google.com>
5  */
6 #ifndef __PVIOMMU_HOST_H
7 #define __PVIOMMU_HOST_H
8 
9 #include <linux/kvm_host.h>
10 #include <nvhe/pkvm.h>
11 
12 /* Ideally these are dynamically allocated. */
13 #define MAX_NR_PVIOMMU					32
14 #define MAX_NR_SID_PER_PVIOMMU				16
15 
16 struct pviommu_route {
17 	pkvm_handle_t iommu;
18 	u32 sid;
19 };
20 
21 int pkvm_pviommu_attach(struct kvm *host_kvm, int pviommu);
22 int pkvm_pviommu_add_vsid(struct kvm *host_kvm, int pviommu,
23 			  pkvm_handle_t iommu, u32 sid, u32 vsid);
24 int pkvm_pviommu_finalise(struct pkvm_hyp_vm *hyp_vm);
25 void pkvm_pviommu_teardown(struct pkvm_hyp_vm *hyp_vm);
26 int pkvm_pviommu_get_route(struct pkvm_hyp_vm *hyp_vm, pkvm_handle_t pviommu, u32 vsid,
27 			   struct pviommu_route *route);
28 
29 /**
30  * struct pviommu_entry - A single entry (endpoint) in a pvIOMMU
31  * @iommu:		physical IOMMU ID as defined by the pKVM IOMMU module.
32  * @sid:		Physical endpoint ID
33  * @vsid:		Virtual endpoint ID
34  */
35 struct pviommu_entry {
36 	pkvm_handle_t iommu;
37 	u32 sid;
38 	u32 vsid;
39 };
40 
41 /**
42  * struct pviommu_host - pvIOMMU created by host
43  * @kvm:		VM which pvIOMMU is attached to.
44  * @pviommu_id:	ID of the pvIOMMU which is seen by guest.
45  * @nr_entries:	Number of struct pviommu_entry in the pvIOMMU.
46  * @entries:	Entries connected to pvIOMMU (Endpoints)
47  * @list:		list used to connected pvIOMMU in the same VM.
48  * @finalized:	Mark that pvIOMMU can't be changed by host anymore.
49  */
50 struct pviommu_host {
51 	struct kvm *kvm;
52 	int pviommu_id;
53 	int nr_entries;
54 	struct pviommu_entry entries[MAX_NR_SID_PER_PVIOMMU];
55 	struct list_head list;
56 	bool finalized;
57 };
58 
59 #endif /* __PVIOMMU_HOST_H */
60