| 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 | |
| 28 | #include <core/object.h> |
| 29 | #include <core/subdev.h> |
| 30 | #include <core/device.h> |
| 31 | #include <core/mm.h> |
| 32 | |
| 33 | #define NOUVEAU_GPU_PAGE_SIZE 4096 |
| 34 | #define NOUVEAU_GPU_PAGE_MASK (NOUVEAU_GPU_PAGE_SIZE - 1) |
| 35 | #define NOUVEAU_GPU_PAGE_SHIFT 12 |
| 36 | #define NOUVEAU_GPU_PAGE_ALIGN(a) (((a) + NOUVEAU_GPU_PAGE_MASK) & ~NOUVEAU_GPU_PAGE_MASK) |
| 37 | |
| 38 | struct nouveau_vm_pgt { |
| 39 | struct nouveau_gpuobj *obj[2]; |
| 40 | u32 refcount[2]; |
| 41 | }; |
| 42 | |
| 43 | struct nouveau_vm_pgd { |
| 44 | struct list_head head; |
| 45 | struct nouveau_gpuobj *obj; |
| 46 | }; |
| 47 | |
| 48 | struct nouveau_gpuobj; |
| 49 | struct nouveau_mem; |
| 50 | |
| 51 | struct nouveau_vma { |
| 52 | struct list_head head; |
| 53 | int refcount; |
| 54 | struct nouveau_vm *vm; |
| 55 | struct nouveau_mm_node *node; |
| 56 | u64 offset; |
| 57 | u32 access; |
| 58 | }; |
| 59 | |
| 60 | struct nouveau_vm { |
| 61 | struct nouveau_vmmgr *vmm; |
| 62 | struct nouveau_mm mm; |
| 63 | struct kref refcount; |
| 64 | |
| 65 | struct list_head pgd_list; |
| 66 | atomic_t engref[NVDEV_SUBDEV_NR]; |
| 67 | |
| 68 | struct nouveau_vm_pgt *pgt; |
| 69 | u32 fpde; |
| 70 | u32 lpde; |
| 71 | }; |
| 72 | |
| 73 | struct nouveau_vmmgr { |
| 74 | struct nouveau_subdev base; |
| 75 | |
| 76 | u64 limit; |
| 77 | u8 dma_bits; |
| 78 | u32 pgt_bits; |
| 79 | u8 spg_shift; |
| 80 | u8 lpg_shift; |
| 81 | |
| 82 | int (*create)(struct nouveau_vmmgr *, u64 offset, u64 length, |
| 83 | u64 mm_offset, struct nouveau_vm **); |
| 84 | |
| 85 | void (*map_pgt)(struct nouveau_gpuobj *pgd, u32 pde, |
| 86 | struct nouveau_gpuobj *pgt[2]); |
| 87 | void (*map)(struct nouveau_vma *, struct nouveau_gpuobj *, |
| 88 | struct nouveau_mem *, u32 pte, u32 cnt, |
| 89 | u64 phys, u64 delta); |
| 90 | void (*map_sg)(struct nouveau_vma *, struct nouveau_gpuobj *, |
| 91 | struct nouveau_mem *, u32 pte, u32 cnt, dma_addr_t *); |
| 92 | void (*unmap)(struct nouveau_gpuobj *pgt, u32 pte, u32 cnt); |
| 93 | void (*flush)(struct nouveau_vm *); |
| 94 | }; |
| 95 | |
| 96 | static inline struct nouveau_vmmgr * |
| 97 | nouveau_vmmgr(void *obj) |
| 98 | { |
| 99 | return (void *)nv_device(obj)->subdev[NVDEV_SUBDEV_VM]; |
| 100 | } |
| 101 | |
| 102 | #define nouveau_vmmgr_create(p,e,o,i,f,d) \ |
| 103 | nouveau_subdev_create((p), (e), (o), 0, (i), (f), (d)) |
| 104 | #define nouveau_vmmgr_destroy(p) \ |
| 105 | nouveau_subdev_destroy(&(p)->base) |
| 106 | #define nouveau_vmmgr_init(p) \ |
| 107 | nouveau_subdev_init(&(p)->base) |
| 108 | #define nouveau_vmmgr_fini(p,s) \ |
| 109 | nouveau_subdev_fini(&(p)->base, (s)) |
| 110 | |
| 111 | #define _nouveau_vmmgr_dtor _nouveau_subdev_dtor |
| 112 | #define _nouveau_vmmgr_init _nouveau_subdev_init |
| 113 | #define _nouveau_vmmgr_fini _nouveau_subdev_fini |
| 114 | |
| 115 | extern struct nouveau_oclass nv04_vmmgr_oclass; |
| 116 | extern struct nouveau_oclass nv41_vmmgr_oclass; |
| 117 | extern struct nouveau_oclass nv44_vmmgr_oclass; |
| 118 | extern struct nouveau_oclass nv50_vmmgr_oclass; |
| 119 | extern struct nouveau_oclass nvc0_vmmgr_oclass; |
| 120 | |
| 121 | int nv04_vm_create(struct nouveau_vmmgr *, u64, u64, u64, |
| 122 | struct nouveau_vm **); |
| 123 | void nv04_vmmgr_dtor(struct nouveau_object *); |
| 124 | |
| 125 | /* nouveau_vm.c */ |
| 126 | int nouveau_vm_create(struct nouveau_vmmgr *, u64 offset, u64 length, |
| 127 | u64 mm_offset, u32 block, struct nouveau_vm **); |
| 128 | int nouveau_vm_new(struct nouveau_device *, u64 offset, u64 length, |
| 129 | u64 mm_offset, struct nouveau_vm **); |
| 130 | int nouveau_vm_ref(struct nouveau_vm *, struct nouveau_vm **, |
| 131 | struct nouveau_gpuobj *pgd); |
| 132 | int nouveau_vm_get(struct nouveau_vm *, u64 size, u32 page_shift, |
| 133 | u32 access, struct nouveau_vma *); |
| 134 | void nouveau_vm_put(struct nouveau_vma *); |
| 135 | void nouveau_vm_map(struct nouveau_vma *, struct nouveau_mem *); |
| 136 | void nouveau_vm_map_at(struct nouveau_vma *, u64 offset, struct nouveau_mem *); |
| 137 | void nouveau_vm_unmap(struct nouveau_vma *); |
| 138 | void nouveau_vm_unmap_at(struct nouveau_vma *, u64 offset, u64 length); |
| 139 | |
| 140 | #endif |
| 141 | |