1bf215546Sopenharmony_ci/* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) OR MIT */ 2bf215546Sopenharmony_ci/* Copyright 2017-2018 Qiang Yu <yuq825@gmail.com> */ 3bf215546Sopenharmony_ci 4bf215546Sopenharmony_ci#ifndef __LIMA_DRM_H__ 5bf215546Sopenharmony_ci#define __LIMA_DRM_H__ 6bf215546Sopenharmony_ci 7bf215546Sopenharmony_ci#include "drm.h" 8bf215546Sopenharmony_ci 9bf215546Sopenharmony_ci#if defined(__cplusplus) 10bf215546Sopenharmony_ciextern "C" { 11bf215546Sopenharmony_ci#endif 12bf215546Sopenharmony_ci 13bf215546Sopenharmony_cienum drm_lima_param_gpu_id { 14bf215546Sopenharmony_ci DRM_LIMA_PARAM_GPU_ID_UNKNOWN, 15bf215546Sopenharmony_ci DRM_LIMA_PARAM_GPU_ID_MALI400, 16bf215546Sopenharmony_ci DRM_LIMA_PARAM_GPU_ID_MALI450, 17bf215546Sopenharmony_ci}; 18bf215546Sopenharmony_ci 19bf215546Sopenharmony_cienum drm_lima_param { 20bf215546Sopenharmony_ci DRM_LIMA_PARAM_GPU_ID, 21bf215546Sopenharmony_ci DRM_LIMA_PARAM_NUM_PP, 22bf215546Sopenharmony_ci DRM_LIMA_PARAM_GP_VERSION, 23bf215546Sopenharmony_ci DRM_LIMA_PARAM_PP_VERSION, 24bf215546Sopenharmony_ci}; 25bf215546Sopenharmony_ci 26bf215546Sopenharmony_ci/** 27bf215546Sopenharmony_ci * get various information of the GPU 28bf215546Sopenharmony_ci */ 29bf215546Sopenharmony_cistruct drm_lima_get_param { 30bf215546Sopenharmony_ci __u32 param; /* in, value in enum drm_lima_param */ 31bf215546Sopenharmony_ci __u32 pad; /* pad, must be zero */ 32bf215546Sopenharmony_ci __u64 value; /* out, parameter value */ 33bf215546Sopenharmony_ci}; 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_ci/* 36bf215546Sopenharmony_ci * heap buffer dynamically increase backup memory size when GP task fail 37bf215546Sopenharmony_ci * due to lack of heap memory. size field of heap buffer is an up bound of 38bf215546Sopenharmony_ci * the backup memory which can be set to a fairly large value. 39bf215546Sopenharmony_ci */ 40bf215546Sopenharmony_ci#define LIMA_BO_FLAG_HEAP (1 << 0) 41bf215546Sopenharmony_ci 42bf215546Sopenharmony_ci/** 43bf215546Sopenharmony_ci * create a buffer for used by GPU 44bf215546Sopenharmony_ci */ 45bf215546Sopenharmony_cistruct drm_lima_gem_create { 46bf215546Sopenharmony_ci __u32 size; /* in, buffer size */ 47bf215546Sopenharmony_ci __u32 flags; /* in, buffer flags */ 48bf215546Sopenharmony_ci __u32 handle; /* out, GEM buffer handle */ 49bf215546Sopenharmony_ci __u32 pad; /* pad, must be zero */ 50bf215546Sopenharmony_ci}; 51bf215546Sopenharmony_ci 52bf215546Sopenharmony_ci/** 53bf215546Sopenharmony_ci * get information of a buffer 54bf215546Sopenharmony_ci */ 55bf215546Sopenharmony_cistruct drm_lima_gem_info { 56bf215546Sopenharmony_ci __u32 handle; /* in, GEM buffer handle */ 57bf215546Sopenharmony_ci __u32 va; /* out, virtual address mapped into GPU MMU */ 58bf215546Sopenharmony_ci __u64 offset; /* out, used to mmap this buffer to CPU */ 59bf215546Sopenharmony_ci}; 60bf215546Sopenharmony_ci 61bf215546Sopenharmony_ci#define LIMA_SUBMIT_BO_READ 0x01 62bf215546Sopenharmony_ci#define LIMA_SUBMIT_BO_WRITE 0x02 63bf215546Sopenharmony_ci 64bf215546Sopenharmony_ci/* buffer information used by one task */ 65bf215546Sopenharmony_cistruct drm_lima_gem_submit_bo { 66bf215546Sopenharmony_ci __u32 handle; /* in, GEM buffer handle */ 67bf215546Sopenharmony_ci __u32 flags; /* in, buffer read/write by GPU */ 68bf215546Sopenharmony_ci}; 69bf215546Sopenharmony_ci 70bf215546Sopenharmony_ci#define LIMA_GP_FRAME_REG_NUM 6 71bf215546Sopenharmony_ci 72bf215546Sopenharmony_ci/* frame used to setup GP for each task */ 73bf215546Sopenharmony_cistruct drm_lima_gp_frame { 74bf215546Sopenharmony_ci __u32 frame[LIMA_GP_FRAME_REG_NUM]; 75bf215546Sopenharmony_ci}; 76bf215546Sopenharmony_ci 77bf215546Sopenharmony_ci#define LIMA_PP_FRAME_REG_NUM 23 78bf215546Sopenharmony_ci#define LIMA_PP_WB_REG_NUM 12 79bf215546Sopenharmony_ci 80bf215546Sopenharmony_ci/* frame used to setup mali400 GPU PP for each task */ 81bf215546Sopenharmony_cistruct drm_lima_m400_pp_frame { 82bf215546Sopenharmony_ci __u32 frame[LIMA_PP_FRAME_REG_NUM]; 83bf215546Sopenharmony_ci __u32 num_pp; 84bf215546Sopenharmony_ci __u32 wb[3 * LIMA_PP_WB_REG_NUM]; 85bf215546Sopenharmony_ci __u32 plbu_array_address[4]; 86bf215546Sopenharmony_ci __u32 fragment_stack_address[4]; 87bf215546Sopenharmony_ci}; 88bf215546Sopenharmony_ci 89bf215546Sopenharmony_ci/* frame used to setup mali450 GPU PP for each task */ 90bf215546Sopenharmony_cistruct drm_lima_m450_pp_frame { 91bf215546Sopenharmony_ci __u32 frame[LIMA_PP_FRAME_REG_NUM]; 92bf215546Sopenharmony_ci __u32 num_pp; 93bf215546Sopenharmony_ci __u32 wb[3 * LIMA_PP_WB_REG_NUM]; 94bf215546Sopenharmony_ci __u32 use_dlbu; 95bf215546Sopenharmony_ci __u32 _pad; 96bf215546Sopenharmony_ci union { 97bf215546Sopenharmony_ci __u32 plbu_array_address[8]; 98bf215546Sopenharmony_ci __u32 dlbu_regs[4]; 99bf215546Sopenharmony_ci }; 100bf215546Sopenharmony_ci __u32 fragment_stack_address[8]; 101bf215546Sopenharmony_ci}; 102bf215546Sopenharmony_ci 103bf215546Sopenharmony_ci#define LIMA_PIPE_GP 0x00 104bf215546Sopenharmony_ci#define LIMA_PIPE_PP 0x01 105bf215546Sopenharmony_ci 106bf215546Sopenharmony_ci#define LIMA_SUBMIT_FLAG_EXPLICIT_FENCE (1 << 0) 107bf215546Sopenharmony_ci 108bf215546Sopenharmony_ci/** 109bf215546Sopenharmony_ci * submit a task to GPU 110bf215546Sopenharmony_ci * 111bf215546Sopenharmony_ci * User can always merge multi sync_file and drm_syncobj 112bf215546Sopenharmony_ci * into one drm_syncobj as in_sync[0], but we reserve 113bf215546Sopenharmony_ci * in_sync[1] for another task's out_sync to avoid the 114bf215546Sopenharmony_ci * export/import/merge pass when explicit sync. 115bf215546Sopenharmony_ci */ 116bf215546Sopenharmony_cistruct drm_lima_gem_submit { 117bf215546Sopenharmony_ci __u32 ctx; /* in, context handle task is submitted to */ 118bf215546Sopenharmony_ci __u32 pipe; /* in, which pipe to use, GP/PP */ 119bf215546Sopenharmony_ci __u32 nr_bos; /* in, array length of bos field */ 120bf215546Sopenharmony_ci __u32 frame_size; /* in, size of frame field */ 121bf215546Sopenharmony_ci __u64 bos; /* in, array of drm_lima_gem_submit_bo */ 122bf215546Sopenharmony_ci __u64 frame; /* in, GP/PP frame */ 123bf215546Sopenharmony_ci __u32 flags; /* in, submit flags */ 124bf215546Sopenharmony_ci __u32 out_sync; /* in, drm_syncobj handle used to wait task finish after submission */ 125bf215546Sopenharmony_ci __u32 in_sync[2]; /* in, drm_syncobj handle used to wait before start this task */ 126bf215546Sopenharmony_ci}; 127bf215546Sopenharmony_ci 128bf215546Sopenharmony_ci#define LIMA_GEM_WAIT_READ 0x01 129bf215546Sopenharmony_ci#define LIMA_GEM_WAIT_WRITE 0x02 130bf215546Sopenharmony_ci 131bf215546Sopenharmony_ci/** 132bf215546Sopenharmony_ci * wait pending GPU task finish of a buffer 133bf215546Sopenharmony_ci */ 134bf215546Sopenharmony_cistruct drm_lima_gem_wait { 135bf215546Sopenharmony_ci __u32 handle; /* in, GEM buffer handle */ 136bf215546Sopenharmony_ci __u32 op; /* in, CPU want to read/write this buffer */ 137bf215546Sopenharmony_ci __s64 timeout_ns; /* in, wait timeout in absulute time */ 138bf215546Sopenharmony_ci}; 139bf215546Sopenharmony_ci 140bf215546Sopenharmony_ci/** 141bf215546Sopenharmony_ci * create a context 142bf215546Sopenharmony_ci */ 143bf215546Sopenharmony_cistruct drm_lima_ctx_create { 144bf215546Sopenharmony_ci __u32 id; /* out, context handle */ 145bf215546Sopenharmony_ci __u32 _pad; /* pad, must be zero */ 146bf215546Sopenharmony_ci}; 147bf215546Sopenharmony_ci 148bf215546Sopenharmony_ci/** 149bf215546Sopenharmony_ci * free a context 150bf215546Sopenharmony_ci */ 151bf215546Sopenharmony_cistruct drm_lima_ctx_free { 152bf215546Sopenharmony_ci __u32 id; /* in, context handle */ 153bf215546Sopenharmony_ci __u32 _pad; /* pad, must be zero */ 154bf215546Sopenharmony_ci}; 155bf215546Sopenharmony_ci 156bf215546Sopenharmony_ci#define DRM_LIMA_GET_PARAM 0x00 157bf215546Sopenharmony_ci#define DRM_LIMA_GEM_CREATE 0x01 158bf215546Sopenharmony_ci#define DRM_LIMA_GEM_INFO 0x02 159bf215546Sopenharmony_ci#define DRM_LIMA_GEM_SUBMIT 0x03 160bf215546Sopenharmony_ci#define DRM_LIMA_GEM_WAIT 0x04 161bf215546Sopenharmony_ci#define DRM_LIMA_CTX_CREATE 0x05 162bf215546Sopenharmony_ci#define DRM_LIMA_CTX_FREE 0x06 163bf215546Sopenharmony_ci 164bf215546Sopenharmony_ci#define DRM_IOCTL_LIMA_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_LIMA_GET_PARAM, struct drm_lima_get_param) 165bf215546Sopenharmony_ci#define DRM_IOCTL_LIMA_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_LIMA_GEM_CREATE, struct drm_lima_gem_create) 166bf215546Sopenharmony_ci#define DRM_IOCTL_LIMA_GEM_INFO DRM_IOWR(DRM_COMMAND_BASE + DRM_LIMA_GEM_INFO, struct drm_lima_gem_info) 167bf215546Sopenharmony_ci#define DRM_IOCTL_LIMA_GEM_SUBMIT DRM_IOW(DRM_COMMAND_BASE + DRM_LIMA_GEM_SUBMIT, struct drm_lima_gem_submit) 168bf215546Sopenharmony_ci#define DRM_IOCTL_LIMA_GEM_WAIT DRM_IOW(DRM_COMMAND_BASE + DRM_LIMA_GEM_WAIT, struct drm_lima_gem_wait) 169bf215546Sopenharmony_ci#define DRM_IOCTL_LIMA_CTX_CREATE DRM_IOR(DRM_COMMAND_BASE + DRM_LIMA_CTX_CREATE, struct drm_lima_ctx_create) 170bf215546Sopenharmony_ci#define DRM_IOCTL_LIMA_CTX_FREE DRM_IOW(DRM_COMMAND_BASE + DRM_LIMA_CTX_FREE, struct drm_lima_ctx_free) 171bf215546Sopenharmony_ci 172bf215546Sopenharmony_ci#if defined(__cplusplus) 173bf215546Sopenharmony_ci} 174bf215546Sopenharmony_ci#endif 175bf215546Sopenharmony_ci 176bf215546Sopenharmony_ci#endif /* __LIMA_DRM_H__ */ 177