Ben Skeggs | a11c319 | 2010-08-27 10:00:25 +1000 | [diff] [blame] | 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 | |
Ben Skeggs | 3863c9b | 2012-07-14 19:09:17 +1000 | [diff] [blame^] | 28 | #ifndef XXX_THIS_IS_A_HACK |
| 29 | #include <core/object.h> |
| 30 | #include <core/subdev.h> |
| 31 | #include <core/device.h> |
| 32 | #endif |
Ben Skeggs | 02a841d | 2012-07-04 23:44:54 +1000 | [diff] [blame] | 33 | #include <core/mm.h> |
Ben Skeggs | a11c319 | 2010-08-27 10:00:25 +1000 | [diff] [blame] | 34 | |
Ben Skeggs | 3863c9b | 2012-07-14 19:09:17 +1000 | [diff] [blame^] | 35 | #ifndef XXX_THIS_IS_A_HACK |
Ben Skeggs | a11c319 | 2010-08-27 10:00:25 +1000 | [diff] [blame] | 36 | struct nouveau_vm_pgt { |
Ben Skeggs | 3ee0128 | 2010-12-15 11:04:39 +1000 | [diff] [blame] | 37 | struct nouveau_gpuobj *obj[2]; |
| 38 | u32 refcount[2]; |
Ben Skeggs | a11c319 | 2010-08-27 10:00:25 +1000 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | struct nouveau_vm_pgd { |
| 42 | struct list_head head; |
| 43 | struct nouveau_gpuobj *obj; |
| 44 | }; |
Ben Skeggs | 3863c9b | 2012-07-14 19:09:17 +1000 | [diff] [blame^] | 45 | #endif |
| 46 | |
| 47 | struct nouveau_gpuobj; |
| 48 | struct nouveau_mem; |
Ben Skeggs | a11c319 | 2010-08-27 10:00:25 +1000 | [diff] [blame] | 49 | |
| 50 | struct nouveau_vma { |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 51 | struct list_head head; |
Ben Skeggs | 2fd3db6 | 2011-06-07 15:25:12 +1000 | [diff] [blame] | 52 | int refcount; |
Ben Skeggs | a11c319 | 2010-08-27 10:00:25 +1000 | [diff] [blame] | 53 | struct nouveau_vm *vm; |
| 54 | struct nouveau_mm_node *node; |
| 55 | u64 offset; |
| 56 | u32 access; |
| 57 | }; |
| 58 | |
| 59 | struct nouveau_vm { |
Ben Skeggs | 3863c9b | 2012-07-14 19:09:17 +1000 | [diff] [blame^] | 60 | struct nouveau_vmmgr *vmm; |
Ben Skeggs | 987eec1 | 2011-06-24 10:14:07 +1000 | [diff] [blame] | 61 | struct nouveau_mm mm; |
Ben Skeggs | a11c319 | 2010-08-27 10:00:25 +1000 | [diff] [blame] | 62 | int refcount; |
| 63 | |
| 64 | struct list_head pgd_list; |
Ben Skeggs | 3863c9b | 2012-07-14 19:09:17 +1000 | [diff] [blame^] | 65 | atomic_t engref[64]; //NVDEV_SUBDEV_NR]; |
Ben Skeggs | a11c319 | 2010-08-27 10:00:25 +1000 | [diff] [blame] | 66 | |
| 67 | struct nouveau_vm_pgt *pgt; |
| 68 | u32 fpde; |
| 69 | u32 lpde; |
Ben Skeggs | 3863c9b | 2012-07-14 19:09:17 +1000 | [diff] [blame^] | 70 | }; |
| 71 | |
| 72 | #ifndef XXX_THIS_IS_A_HACK |
| 73 | struct nouveau_vmmgr { |
| 74 | struct nouveau_subdev base; |
Ben Skeggs | a11c319 | 2010-08-27 10:00:25 +1000 | [diff] [blame] | 75 | |
| 76 | u32 pgt_bits; |
| 77 | u8 spg_shift; |
| 78 | u8 lpg_shift; |
| 79 | |
Ben Skeggs | 3863c9b | 2012-07-14 19:09:17 +1000 | [diff] [blame^] | 80 | int (*create)(struct nouveau_vmmgr *, u64 offset, u64 length, |
| 81 | u64 mm_offset, struct nouveau_vm **); |
| 82 | |
Ben Skeggs | 3ee0128 | 2010-12-15 11:04:39 +1000 | [diff] [blame] | 83 | void (*map_pgt)(struct nouveau_gpuobj *pgd, u32 pde, |
| 84 | struct nouveau_gpuobj *pgt[2]); |
Ben Skeggs | a11c319 | 2010-08-27 10:00:25 +1000 | [diff] [blame] | 85 | void (*map)(struct nouveau_vma *, struct nouveau_gpuobj *, |
Ben Skeggs | 8f7286f | 2011-02-14 09:57:35 +1000 | [diff] [blame] | 86 | struct nouveau_mem *, u32 pte, u32 cnt, |
| 87 | u64 phys, u64 delta); |
Ben Skeggs | a11c319 | 2010-08-27 10:00:25 +1000 | [diff] [blame] | 88 | void (*map_sg)(struct nouveau_vma *, struct nouveau_gpuobj *, |
Ben Skeggs | 26c0c9e | 2011-02-10 12:59:51 +1000 | [diff] [blame] | 89 | struct nouveau_mem *, u32 pte, u32 cnt, dma_addr_t *); |
Ben Skeggs | a11c319 | 2010-08-27 10:00:25 +1000 | [diff] [blame] | 90 | void (*unmap)(struct nouveau_gpuobj *pgt, u32 pte, u32 cnt); |
| 91 | void (*flush)(struct nouveau_vm *); |
| 92 | }; |
| 93 | |
Ben Skeggs | 3863c9b | 2012-07-14 19:09:17 +1000 | [diff] [blame^] | 94 | static inline struct nouveau_vmmgr * |
| 95 | nouveau_vmmgr(void *obj) |
| 96 | { |
| 97 | return (void *)nv_device(obj)->subdev[NVDEV_SUBDEV_VM]; |
| 98 | } |
| 99 | |
| 100 | #define nouveau_vmmgr_create(p,e,o,i,f,d) \ |
| 101 | nouveau_subdev_create((p), (e), (o), 0, (i), (f), (d)) |
| 102 | #define nouveau_vmmgr_destroy(p) \ |
| 103 | nouveau_subdev_destroy(&(p)->base) |
| 104 | #define nouveau_vmmgr_init(p) \ |
| 105 | nouveau_subdev_init(&(p)->base) |
| 106 | #define nouveau_vmmgr_fini(p,s) \ |
| 107 | nouveau_subdev_fini(&(p)->base, (s)) |
| 108 | |
| 109 | #define _nouveau_vmmgr_dtor _nouveau_subdev_dtor |
| 110 | #define _nouveau_vmmgr_init _nouveau_subdev_init |
| 111 | #define _nouveau_vmmgr_fini _nouveau_subdev_fini |
| 112 | |
| 113 | extern struct nouveau_oclass nv04_vmmgr_oclass; |
| 114 | extern struct nouveau_oclass nv41_vmmgr_oclass; |
| 115 | extern struct nouveau_oclass nv44_vmmgr_oclass; |
| 116 | extern struct nouveau_oclass nv50_vmmgr_oclass; |
| 117 | extern struct nouveau_oclass nvc0_vmmgr_oclass; |
| 118 | |
| 119 | int nv04_vm_create(struct nouveau_vmmgr *, u64, u64, u64, |
Ben Skeggs | a11c319 | 2010-08-27 10:00:25 +1000 | [diff] [blame] | 120 | struct nouveau_vm **); |
Ben Skeggs | 3863c9b | 2012-07-14 19:09:17 +1000 | [diff] [blame^] | 121 | void nv04_vmmgr_dtor(struct nouveau_object *); |
| 122 | |
| 123 | void nv50_vm_flush_engine(struct nouveau_subdev *, int engine); |
| 124 | void nvc0_vm_flush_engine(struct nouveau_subdev *, u64 addr, int type); |
| 125 | |
| 126 | /* nouveau_vm.c */ |
| 127 | int nouveau_vm_create(struct nouveau_vmmgr *, u64 offset, u64 length, |
| 128 | u64 mm_offset, u32 block, struct nouveau_vm **); |
| 129 | int nouveau_vm_new(struct nouveau_device *, u64 offset, u64 length, |
| 130 | u64 mm_offset, struct nouveau_vm **); |
| 131 | #endif |
Ben Skeggs | a11c319 | 2010-08-27 10:00:25 +1000 | [diff] [blame] | 132 | int nouveau_vm_ref(struct nouveau_vm *, struct nouveau_vm **, |
| 133 | struct nouveau_gpuobj *pgd); |
| 134 | int nouveau_vm_get(struct nouveau_vm *, u64 size, u32 page_shift, |
| 135 | u32 access, struct nouveau_vma *); |
| 136 | void nouveau_vm_put(struct nouveau_vma *); |
Ben Skeggs | d5f4239 | 2011-02-10 12:22:52 +1000 | [diff] [blame] | 137 | void nouveau_vm_map(struct nouveau_vma *, struct nouveau_mem *); |
| 138 | void nouveau_vm_map_at(struct nouveau_vma *, u64 offset, struct nouveau_mem *); |
Ben Skeggs | a11c319 | 2010-08-27 10:00:25 +1000 | [diff] [blame] | 139 | void nouveau_vm_unmap(struct nouveau_vma *); |
| 140 | void nouveau_vm_unmap_at(struct nouveau_vma *, u64 offset, u64 length); |
| 141 | void nouveau_vm_map_sg(struct nouveau_vma *, u64 offset, u64 length, |
Ben Skeggs | f7b24c4 | 2011-12-22 15:20:21 +1000 | [diff] [blame] | 142 | struct nouveau_mem *); |
Dave Airlie | 22b33e8 | 2012-04-02 11:53:06 +0100 | [diff] [blame] | 143 | void nouveau_vm_map_sg_table(struct nouveau_vma *vma, u64 delta, u64 length, |
Ben Skeggs | 3863c9b | 2012-07-14 19:09:17 +1000 | [diff] [blame^] | 144 | struct nouveau_mem *mem); |
Ben Skeggs | 4c74eb7 | 2010-11-10 14:10:04 +1000 | [diff] [blame] | 145 | |
Ben Skeggs | a11c319 | 2010-08-27 10:00:25 +1000 | [diff] [blame] | 146 | #endif |