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