nouveau_bo.h revision 809e9447b92ffe1346b2d6ec390e212d5307f61c
1f938d2c892db0d80d144253d4a7b7083efdbedebRusty Russell#ifndef __NOUVEAU_BO_H__ 2f938d2c892db0d80d144253d4a7b7083efdbedebRusty Russell#define __NOUVEAU_BO_H__ 33c6b5bfa3cf3b4057788e08482a468cc3bc00780Rusty Russell 43c6b5bfa3cf3b4057788e08482a468cc3bc00780Rusty Russellstruct nouveau_channel; 53c6b5bfa3cf3b4057788e08482a468cc3bc00780Rusty Russellstruct nouveau_fence; 63c6b5bfa3cf3b4057788e08482a468cc3bc00780Rusty Russellstruct nouveau_vma; 7d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell 8d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellstruct nouveau_bo { 9d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell struct ttm_buffer_object bo; 10d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell struct ttm_placement placement; 11d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell u32 valid_domains; 12dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell struct ttm_place placements[3]; 13dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell struct ttm_place busy_placements[3]; 14dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell struct ttm_bo_kmap_obj kmap; 15dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell struct list_head head; 16dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell 17d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell /* protected by ttm_bo_reserve() */ 18d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell struct drm_file *reserved_by; 19dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell struct list_head entry; 20dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell int pbbo_index; 21dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell bool validate_mapped; 22dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell 23dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell struct list_head vma_list; 24dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell unsigned page_shift; 25dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell 26d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell u32 tile_mode; 27d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell u32 tile_flags; 28dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell struct nouveau_drm_tile *tile; 29dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell 30dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell /* Only valid if allocated via nouveau_gem_new() and iff you hold a 31dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell * gem reference to it! For debugging, use gem.filp != NULL to test 32dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell * whether it is valid. */ 33dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell struct drm_gem_object gem; 34dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell 35dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell /* protect by the ttm reservation lock */ 36dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell int pin_refcnt; 37d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell 38dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell struct ttm_bo_kmap_obj dma_buf_vmap; 39dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell}; 40dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell 41d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellstatic inline struct nouveau_bo * 42d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellnouveau_bo(struct ttm_buffer_object *bo) 43dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell{ 44dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell return container_of(bo, struct nouveau_bo, bo); 45dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell} 46d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell 47d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellstatic inline int 48d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellnouveau_bo_ref(struct nouveau_bo *ref, struct nouveau_bo **pnvbo) 49d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell{ 50dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell struct nouveau_bo *prev; 51d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell 52d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell if (!pnvbo) 53dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell return -EINVAL; 54d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell prev = *pnvbo; 55d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell 56d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell *pnvbo = ref ? nouveau_bo(ttm_bo_reference(&ref->bo)) : NULL; 57d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell if (prev) { 58dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell struct ttm_buffer_object *bo = &prev->bo; 59dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell 60d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell ttm_bo_unref(&bo); 61dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell } 62dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell 63dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell return 0; 64d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell} 65d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell 66d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellextern struct ttm_bo_driver nouveau_bo_driver; 67dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell 68d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellvoid nouveau_bo_move_init(struct nouveau_drm *); 69d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellint nouveau_bo_new(struct drm_device *, int size, int align, u32 flags, 70d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell u32 tile_mode, u32 tile_flags, struct sg_table *sg, 71d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell struct nouveau_bo **); 72d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellint nouveau_bo_pin(struct nouveau_bo *, u32 flags); 73d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellint nouveau_bo_unpin(struct nouveau_bo *); 74d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellint nouveau_bo_map(struct nouveau_bo *); 75d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellvoid nouveau_bo_unmap(struct nouveau_bo *); 76d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellvoid nouveau_bo_placement_set(struct nouveau_bo *, u32 type, u32 busy); 77d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellu16 nouveau_bo_rd16(struct nouveau_bo *, unsigned index); 78d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellvoid nouveau_bo_wr16(struct nouveau_bo *, unsigned index, u16 val); 79d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellu32 nouveau_bo_rd32(struct nouveau_bo *, unsigned index); 80d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellvoid nouveau_bo_wr32(struct nouveau_bo *, unsigned index, u32 val); 81d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellvoid nouveau_bo_fence(struct nouveau_bo *, struct nouveau_fence *, bool exclusive); 82d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellint nouveau_bo_validate(struct nouveau_bo *, bool interruptible, 83d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell bool no_wait_gpu); 84d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell 85d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellstruct nouveau_vma * 86d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellnouveau_bo_vma_find(struct nouveau_bo *, struct nouveau_vm *); 87d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell 88d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellint nouveau_bo_vma_add(struct nouveau_bo *, struct nouveau_vm *, 89d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell struct nouveau_vma *); 90d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellvoid nouveau_bo_vma_del(struct nouveau_bo *, struct nouveau_vma *); 91dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell 92dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell/* TODO: submit equivalent to TTM generic API upstream? */ 93d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellstatic inline void __iomem * 94d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russellnvbo_kmap_obj_iovirtual(struct nouveau_bo *nvbo) 95d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell{ 96d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell bool is_iomem; 97d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell void __iomem *ioptr = (void __force __iomem *)ttm_kmap_obj_virtual( 98d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell &nvbo->kmap, &is_iomem); 99d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell WARN_ON_ONCE(ioptr && !is_iomem); 100d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell return ioptr; 101dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell} 102dde797899ac17ebb812b7566044124d785e98dc7Rusty Russell 103d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell#endif 104d7e28ffe6c74416b54345d6004fd0964c115b12cRusty Russell