1 /* SPDX-License-Identifier: MIT */
2 #ifndef __NVKM_MMU_PRIV_H__
3 #define __NVKM_MMU_PRIV_H__
4 #define nvkm_mmu(p) container_of((p), struct nvkm_mmu, subdev)
5 #include <subdev/mmu.h>
6 
7 void nvkm_mmu_ctor(const struct nvkm_mmu_func *, struct nvkm_device *,
8 		   int index, struct nvkm_mmu *);
9 int nvkm_mmu_new_(const struct nvkm_mmu_func *, struct nvkm_device *,
10 		  int index, struct nvkm_mmu **);
11 
12 struct nvkm_mmu_func {
13 	void (*init)(struct nvkm_mmu *);
14 
15 	u8  dma_bits;
16 
17 	struct {
18 		struct nvkm_sclass user;
19 	} mmu;
20 
21 	struct {
22 		struct nvkm_sclass user;
23 		int (*vram)(struct nvkm_mmu *, int type, u8 page, u64 size,
24 			    void *argv, u32 argc, struct nvkm_memory **);
25 		int (*umap)(struct nvkm_mmu *, struct nvkm_memory *, void *argv,
26 			    u32 argc, u64 *addr, u64 *size, struct nvkm_vma **);
27 	} mem;
28 
29 	struct {
30 		struct nvkm_sclass user;
31 		int (*ctor)(struct nvkm_mmu *, bool managed, u64 addr, u64 size,
32 			    void *argv, u32 argc, struct lock_class_key *,
33 			    const char *name, struct nvkm_vmm **);
34 		bool global;
35 		u32 pd_offset;
36 	} vmm;
37 
38 	const u8 *(*kind)(struct nvkm_mmu *, int *count);
39 	bool kind_sys;
40 };
41 
42 extern const struct nvkm_mmu_func nv04_mmu;
43 
44 const u8 *nv50_mmu_kind(struct nvkm_mmu *, int *count);
45 
46 const u8 *gf100_mmu_kind(struct nvkm_mmu *, int *count);
47 
48 const u8 *gm200_mmu_kind(struct nvkm_mmu *, int *);
49 
50 struct nvkm_mmu_pt {
51 	union {
52 		struct nvkm_mmu_ptc *ptc;
53 		struct nvkm_mmu_ptp *ptp;
54 	};
55 	struct nvkm_memory *memory;
56 	bool sub;
57 	u16 base;
58 	u64 addr;
59 	struct list_head head;
60 };
61 
62 void nvkm_mmu_ptc_dump(struct nvkm_mmu *);
63 struct nvkm_mmu_pt *
64 nvkm_mmu_ptc_get(struct nvkm_mmu *, u32 size, u32 align, bool zero);
65 void nvkm_mmu_ptc_put(struct nvkm_mmu *, bool force, struct nvkm_mmu_pt **);
66 #endif
67