linux/drivers/gpu/drm/nouveau/nouveau_bo.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0 */
   2#ifndef __NOUVEAU_BO_H__
   3#define __NOUVEAU_BO_H__
   4
   5#include <drm/drm_gem.h>
   6
   7struct nouveau_channel;
   8struct nouveau_fence;
   9struct nvkm_vma;
  10
  11struct nouveau_bo {
  12        struct ttm_buffer_object bo;
  13        struct ttm_placement placement;
  14        u32 valid_domains;
  15        struct ttm_place placements[3];
  16        struct ttm_place busy_placements[3];
  17        bool force_coherent;
  18        struct ttm_bo_kmap_obj kmap;
  19        struct list_head head;
  20
  21        /* protected by ttm_bo_reserve() */
  22        struct drm_file *reserved_by;
  23        struct list_head entry;
  24        int pbbo_index;
  25        bool validate_mapped;
  26
  27        struct list_head vma_list;
  28
  29        struct nouveau_cli *cli;
  30
  31        unsigned contig:1;
  32        unsigned page:5;
  33        unsigned kind:8;
  34        unsigned comp:3;
  35        unsigned zeta:3;
  36        unsigned mode;
  37
  38        struct nouveau_drm_tile *tile;
  39
  40        /* Only valid if allocated via nouveau_gem_new() and iff you hold a
  41         * gem reference to it! For debugging, use gem.filp != NULL to test
  42         * whether it is valid. */
  43        struct drm_gem_object gem;
  44
  45        /* protect by the ttm reservation lock */
  46        int pin_refcnt;
  47
  48        struct ttm_bo_kmap_obj dma_buf_vmap;
  49};
  50
  51static inline struct nouveau_bo *
  52nouveau_bo(struct ttm_buffer_object *bo)
  53{
  54        return container_of(bo, struct nouveau_bo, bo);
  55}
  56
  57static inline int
  58nouveau_bo_ref(struct nouveau_bo *ref, struct nouveau_bo **pnvbo)
  59{
  60        struct nouveau_bo *prev;
  61
  62        if (!pnvbo)
  63                return -EINVAL;
  64        prev = *pnvbo;
  65
  66        *pnvbo = ref ? nouveau_bo(ttm_bo_reference(&ref->bo)) : NULL;
  67        if (prev) {
  68                struct ttm_buffer_object *bo = &prev->bo;
  69
  70                ttm_bo_unref(&bo);
  71        }
  72
  73        return 0;
  74}
  75
  76extern struct ttm_bo_driver nouveau_bo_driver;
  77
  78void nouveau_bo_move_init(struct nouveau_drm *);
  79int  nouveau_bo_new(struct nouveau_cli *, u64 size, int align, u32 flags,
  80                    u32 tile_mode, u32 tile_flags, struct sg_table *sg,
  81                    struct reservation_object *robj,
  82                    struct nouveau_bo **);
  83int  nouveau_bo_pin(struct nouveau_bo *, u32 flags, bool contig);
  84int  nouveau_bo_unpin(struct nouveau_bo *);
  85int  nouveau_bo_map(struct nouveau_bo *);
  86void nouveau_bo_unmap(struct nouveau_bo *);
  87void nouveau_bo_placement_set(struct nouveau_bo *, u32 type, u32 busy);
  88void nouveau_bo_wr16(struct nouveau_bo *, unsigned index, u16 val);
  89u32  nouveau_bo_rd32(struct nouveau_bo *, unsigned index);
  90void nouveau_bo_wr32(struct nouveau_bo *, unsigned index, u32 val);
  91void nouveau_bo_fence(struct nouveau_bo *, struct nouveau_fence *, bool exclusive);
  92int  nouveau_bo_validate(struct nouveau_bo *, bool interruptible,
  93                         bool no_wait_gpu);
  94void nouveau_bo_sync_for_device(struct nouveau_bo *nvbo);
  95void nouveau_bo_sync_for_cpu(struct nouveau_bo *nvbo);
  96
  97/* TODO: submit equivalent to TTM generic API upstream? */
  98static inline void __iomem *
  99nvbo_kmap_obj_iovirtual(struct nouveau_bo *nvbo)
 100{
 101        bool is_iomem;
 102        void __iomem *ioptr = (void __force __iomem *)ttm_kmap_obj_virtual(
 103                                                &nvbo->kmap, &is_iomem);
 104        WARN_ON_ONCE(ioptr && !is_iomem);
 105        return ioptr;
 106}
 107
 108#endif
 109