Commit | Line | Data |
---|---|---|
a11c3198 BS |
1 | /* |
2 | * Copyright 2010 Red Hat Inc. | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining a | |
5 | * copy of this software and associated documentation files (the "Software"), | |
6 | * to deal in the Software without restriction, including without limitation | |
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
8 | * and/or sell copies of the Software, and to permit persons to whom the | |
9 | * Software is furnished to do so, subject to the following conditions: | |
10 | * | |
11 | * The above copyright notice and this permission notice shall be included in | |
12 | * all copies or substantial portions of the Software. | |
13 | * | |
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
17 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
20 | * OTHER DEALINGS IN THE SOFTWARE. | |
21 | * | |
22 | * Authors: Ben Skeggs | |
23 | */ | |
24 | ||
25 | #ifndef __NOUVEAU_VM_H__ | |
26 | #define __NOUVEAU_VM_H__ | |
27 | ||
3863c9bc BS |
28 | #include <core/object.h> |
29 | #include <core/subdev.h> | |
30 | #include <core/device.h> | |
02a841d4 | 31 | #include <core/mm.h> |
a11c3198 BS |
32 | |
33 | struct nouveau_vm_pgt { | |
3ee01281 BS |
34 | struct nouveau_gpuobj *obj[2]; |
35 | u32 refcount[2]; | |
a11c3198 BS |
36 | }; |
37 | ||
38 | struct nouveau_vm_pgd { | |
39 | struct list_head head; | |
40 | struct nouveau_gpuobj *obj; | |
41 | }; | |
3863c9bc BS |
42 | |
43 | struct nouveau_gpuobj; | |
44 | struct nouveau_mem; | |
a11c3198 BS |
45 | |
46 | struct nouveau_vma { | |
fd2871af | 47 | struct list_head head; |
2fd3db6f | 48 | int refcount; |
a11c3198 BS |
49 | struct nouveau_vm *vm; |
50 | struct nouveau_mm_node *node; | |
51 | u64 offset; | |
52 | u32 access; | |
53 | }; | |
54 | ||
55 | struct nouveau_vm { | |
3863c9bc | 56 | struct nouveau_vmmgr *vmm; |
987eec10 | 57 | struct nouveau_mm mm; |
e0bacd2f | 58 | struct kref refcount; |
a11c3198 BS |
59 | |
60 | struct list_head pgd_list; | |
c3032adb | 61 | atomic_t engref[NVDEV_SUBDEV_NR]; |
a11c3198 BS |
62 | |
63 | struct nouveau_vm_pgt *pgt; | |
64 | u32 fpde; | |
65 | u32 lpde; | |
3863c9bc BS |
66 | }; |
67 | ||
3863c9bc BS |
68 | struct nouveau_vmmgr { |
69 | struct nouveau_subdev base; | |
a11c3198 | 70 | |
ebb945a9 | 71 | u64 limit; |
dc73b45a | 72 | u8 dma_bits; |
a11c3198 BS |
73 | u32 pgt_bits; |
74 | u8 spg_shift; | |
75 | u8 lpg_shift; | |
76 | ||
3863c9bc BS |
77 | int (*create)(struct nouveau_vmmgr *, u64 offset, u64 length, |
78 | u64 mm_offset, struct nouveau_vm **); | |
79 | ||
3ee01281 BS |
80 | void (*map_pgt)(struct nouveau_gpuobj *pgd, u32 pde, |
81 | struct nouveau_gpuobj *pgt[2]); | |
a11c3198 | 82 | void (*map)(struct nouveau_vma *, struct nouveau_gpuobj *, |
8f7286f8 BS |
83 | struct nouveau_mem *, u32 pte, u32 cnt, |
84 | u64 phys, u64 delta); | |
a11c3198 | 85 | void (*map_sg)(struct nouveau_vma *, struct nouveau_gpuobj *, |
26c0c9e3 | 86 | struct nouveau_mem *, u32 pte, u32 cnt, dma_addr_t *); |
a11c3198 BS |
87 | void (*unmap)(struct nouveau_gpuobj *pgt, u32 pte, u32 cnt); |
88 | void (*flush)(struct nouveau_vm *); | |
89 | }; | |
90 | ||
3863c9bc BS |
91 | static inline struct nouveau_vmmgr * |
92 | nouveau_vmmgr(void *obj) | |
93 | { | |
94 | return (void *)nv_device(obj)->subdev[NVDEV_SUBDEV_VM]; | |
95 | } | |
96 | ||
97 | #define nouveau_vmmgr_create(p,e,o,i,f,d) \ | |
98 | nouveau_subdev_create((p), (e), (o), 0, (i), (f), (d)) | |
99 | #define nouveau_vmmgr_destroy(p) \ | |
100 | nouveau_subdev_destroy(&(p)->base) | |
101 | #define nouveau_vmmgr_init(p) \ | |
102 | nouveau_subdev_init(&(p)->base) | |
103 | #define nouveau_vmmgr_fini(p,s) \ | |
104 | nouveau_subdev_fini(&(p)->base, (s)) | |
105 | ||
106 | #define _nouveau_vmmgr_dtor _nouveau_subdev_dtor | |
107 | #define _nouveau_vmmgr_init _nouveau_subdev_init | |
108 | #define _nouveau_vmmgr_fini _nouveau_subdev_fini | |
109 | ||
110 | extern struct nouveau_oclass nv04_vmmgr_oclass; | |
111 | extern struct nouveau_oclass nv41_vmmgr_oclass; | |
112 | extern struct nouveau_oclass nv44_vmmgr_oclass; | |
113 | extern struct nouveau_oclass nv50_vmmgr_oclass; | |
114 | extern struct nouveau_oclass nvc0_vmmgr_oclass; | |
115 | ||
116 | int nv04_vm_create(struct nouveau_vmmgr *, u64, u64, u64, | |
a11c3198 | 117 | struct nouveau_vm **); |
3863c9bc BS |
118 | void nv04_vmmgr_dtor(struct nouveau_object *); |
119 | ||
3863c9bc BS |
120 | /* nouveau_vm.c */ |
121 | int nouveau_vm_create(struct nouveau_vmmgr *, u64 offset, u64 length, | |
122 | u64 mm_offset, u32 block, struct nouveau_vm **); | |
123 | int nouveau_vm_new(struct nouveau_device *, u64 offset, u64 length, | |
124 | u64 mm_offset, struct nouveau_vm **); | |
a11c3198 BS |
125 | int nouveau_vm_ref(struct nouveau_vm *, struct nouveau_vm **, |
126 | struct nouveau_gpuobj *pgd); | |
127 | int nouveau_vm_get(struct nouveau_vm *, u64 size, u32 page_shift, | |
128 | u32 access, struct nouveau_vma *); | |
129 | void nouveau_vm_put(struct nouveau_vma *); | |
d5f42394 BS |
130 | void nouveau_vm_map(struct nouveau_vma *, struct nouveau_mem *); |
131 | void nouveau_vm_map_at(struct nouveau_vma *, u64 offset, struct nouveau_mem *); | |
a11c3198 BS |
132 | void nouveau_vm_unmap(struct nouveau_vma *); |
133 | void nouveau_vm_unmap_at(struct nouveau_vma *, u64 offset, u64 length); | |
134 | void nouveau_vm_map_sg(struct nouveau_vma *, u64 offset, u64 length, | |
f7b24c42 | 135 | struct nouveau_mem *); |
22b33e8e | 136 | void nouveau_vm_map_sg_table(struct nouveau_vma *vma, u64 delta, u64 length, |
3863c9bc | 137 | struct nouveau_mem *mem); |
4c74eb7f | 138 | |
a11c3198 | 139 | #endif |