linux/drivers/gpu/drm/etnaviv/etnaviv_drv.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0 */
   2/*
   3 * Copyright (C) 2015-2018 Etnaviv Project
   4 */
   5
   6#ifndef __ETNAVIV_DRV_H__
   7#define __ETNAVIV_DRV_H__
   8
   9#include <linux/list.h>
  10#include <linux/mm_types.h>
  11#include <linux/sizes.h>
  12#include <linux/time64.h>
  13#include <linux/types.h>
  14
  15#include <drm/drm_fb_helper.h>
  16#include <drm/drm_gem.h>
  17#include <drm/etnaviv_drm.h>
  18#include <drm/gpu_scheduler.h>
  19
  20struct etnaviv_cmdbuf;
  21struct etnaviv_gpu;
  22struct etnaviv_mmu;
  23struct etnaviv_gem_object;
  24struct etnaviv_gem_submit;
  25struct etnaviv_iommu_global;
  26
  27#define ETNAVIV_SOFTPIN_START_ADDRESS   SZ_4M /* must be >= SUBALLOC_SIZE */
  28
  29struct etnaviv_file_private {
  30        struct etnaviv_iommu_context    *mmu;
  31        struct drm_sched_entity         sched_entity[ETNA_MAX_PIPES];
  32};
  33
  34struct etnaviv_drm_private {
  35        int num_gpus;
  36        struct device_dma_parameters dma_parms;
  37        struct etnaviv_gpu *gpu[ETNA_MAX_PIPES];
  38        gfp_t shm_gfp_mask;
  39
  40        struct etnaviv_cmdbuf_suballoc *cmdbuf_suballoc;
  41        struct etnaviv_iommu_global *mmu_global;
  42
  43        /* list of GEM objects: */
  44        struct mutex gem_lock;
  45        struct list_head gem_list;
  46};
  47
  48int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
  49                struct drm_file *file);
  50
  51int etnaviv_gem_mmap(struct file *filp, struct vm_area_struct *vma);
  52vm_fault_t etnaviv_gem_fault(struct vm_fault *vmf);
  53int etnaviv_gem_mmap_offset(struct drm_gem_object *obj, u64 *offset);
  54struct sg_table *etnaviv_gem_prime_get_sg_table(struct drm_gem_object *obj);
  55void *etnaviv_gem_prime_vmap(struct drm_gem_object *obj);
  56void etnaviv_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
  57int etnaviv_gem_prime_mmap(struct drm_gem_object *obj,
  58                           struct vm_area_struct *vma);
  59struct drm_gem_object *etnaviv_gem_prime_import_sg_table(struct drm_device *dev,
  60        struct dma_buf_attachment *attach, struct sg_table *sg);
  61int etnaviv_gem_prime_pin(struct drm_gem_object *obj);
  62void etnaviv_gem_prime_unpin(struct drm_gem_object *obj);
  63void *etnaviv_gem_vmap(struct drm_gem_object *obj);
  64int etnaviv_gem_cpu_prep(struct drm_gem_object *obj, u32 op,
  65                struct drm_etnaviv_timespec *timeout);
  66int etnaviv_gem_cpu_fini(struct drm_gem_object *obj);
  67void etnaviv_gem_free_object(struct drm_gem_object *obj);
  68int etnaviv_gem_new_handle(struct drm_device *dev, struct drm_file *file,
  69                u32 size, u32 flags, u32 *handle);
  70int etnaviv_gem_new_userptr(struct drm_device *dev, struct drm_file *file,
  71        uintptr_t ptr, u32 size, u32 flags, u32 *handle);
  72u16 etnaviv_buffer_init(struct etnaviv_gpu *gpu);
  73u16 etnaviv_buffer_config_mmuv2(struct etnaviv_gpu *gpu, u32 mtlb_addr, u32 safe_addr);
  74u16 etnaviv_buffer_config_pta(struct etnaviv_gpu *gpu, unsigned short id);
  75void etnaviv_buffer_end(struct etnaviv_gpu *gpu);
  76void etnaviv_sync_point_queue(struct etnaviv_gpu *gpu, unsigned int event);
  77void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, u32 exec_state,
  78        struct etnaviv_iommu_context *mmu,
  79        unsigned int event, struct etnaviv_cmdbuf *cmdbuf);
  80void etnaviv_validate_init(void);
  81bool etnaviv_cmd_validate_one(struct etnaviv_gpu *gpu,
  82        u32 *stream, unsigned int size,
  83        struct drm_etnaviv_gem_submit_reloc *relocs, unsigned int reloc_size);
  84
  85#ifdef CONFIG_DEBUG_FS
  86void etnaviv_gem_describe_objects(struct etnaviv_drm_private *priv,
  87        struct seq_file *m);
  88#endif
  89
  90#define DBG(fmt, ...) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
  91#define VERB(fmt, ...) if (0) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
  92
  93/*
  94 * Return the storage size of a structure with a variable length array.
  95 * The array is nelem elements of elem_size, where the base structure
  96 * is defined by base.  If the size overflows size_t, return zero.
  97 */
  98static inline size_t size_vstruct(size_t nelem, size_t elem_size, size_t base)
  99{
 100        if (elem_size && nelem > (SIZE_MAX - base) / elem_size)
 101                return 0;
 102        return base + nelem * elem_size;
 103}
 104
 105/*
 106 * Etnaviv timeouts are specified wrt CLOCK_MONOTONIC, not jiffies.
 107 * We need to calculate the timeout in terms of number of jiffies
 108 * between the specified timeout and the current CLOCK_MONOTONIC time.
 109 */
 110static inline unsigned long etnaviv_timeout_to_jiffies(
 111        const struct drm_etnaviv_timespec *timeout)
 112{
 113        struct timespec64 ts, to = {
 114                .tv_sec = timeout->tv_sec,
 115                .tv_nsec = timeout->tv_nsec,
 116        };
 117
 118        ktime_get_ts64(&ts);
 119
 120        /* timeouts before "now" have already expired */
 121        if (timespec64_compare(&to, &ts) <= 0)
 122                return 0;
 123
 124        ts = timespec64_sub(to, ts);
 125
 126        return timespec64_to_jiffies(&ts);
 127}
 128
 129#endif /* __ETNAVIV_DRV_H__ */
 130