1 #ifndef __NVKM_MEMORY_H__ 2 #define __NVKM_MEMORY_H__ 3 #include <core/os.h> 4 struct nvkm_device; 5 struct nvkm_vma; 6 struct nvkm_vm; 7 8 enum nvkm_memory_target { 9 NVKM_MEM_TARGET_INST, 10 NVKM_MEM_TARGET_VRAM, 11 NVKM_MEM_TARGET_HOST, 12 }; 13 14 struct nvkm_memory { 15 const struct nvkm_memory_func *func; 16 }; 17 18 struct nvkm_memory_func { 19 void *(*dtor)(struct nvkm_memory *); 20 enum nvkm_memory_target (*target)(struct nvkm_memory *); 21 u64 (*addr)(struct nvkm_memory *); 22 u64 (*size)(struct nvkm_memory *); 23 void (*boot)(struct nvkm_memory *, struct nvkm_vm *); 24 void __iomem *(*acquire)(struct nvkm_memory *); 25 void (*release)(struct nvkm_memory *); 26 u32 (*rd32)(struct nvkm_memory *, u64 offset); 27 void (*wr32)(struct nvkm_memory *, u64 offset, u32 data); 28 void (*map)(struct nvkm_memory *, struct nvkm_vma *, u64 offset); 29 }; 30 31 void nvkm_memory_ctor(const struct nvkm_memory_func *, struct nvkm_memory *); 32 int nvkm_memory_new(struct nvkm_device *, enum nvkm_memory_target, 33 u64 size, u32 align, bool zero, struct nvkm_memory **); 34 void nvkm_memory_del(struct nvkm_memory **); 35 #define nvkm_memory_target(p) (p)->func->target(p) 36 #define nvkm_memory_addr(p) (p)->func->addr(p) 37 #define nvkm_memory_size(p) (p)->func->size(p) 38 #define nvkm_memory_boot(p,v) (p)->func->boot((p),(v)) 39 #define nvkm_memory_map(p,v,o) (p)->func->map((p),(v),(o)) 40 41 /* accessor macros - kmap()/done() must bracket use of the other accessor 42 * macros to guarantee correct behaviour across all chipsets 43 */ 44 #define nvkm_kmap(o) (o)->func->acquire(o) 45 #define nvkm_ro32(o,a) (o)->func->rd32((o), (a)) 46 #define nvkm_wo32(o,a,d) (o)->func->wr32((o), (a), (d)) 47 #define nvkm_mo32(o,a,m,d) ({ \ 48 u32 _addr = (a), _data = nvkm_ro32((o), _addr); \ 49 nvkm_wo32((o), _addr, (_data & ~(m)) | (d)); \ 50 _data; \ 51 }) 52 #define nvkm_done(o) (o)->func->release(o) 53 #endif 54