18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) OR MIT */ 28c2ecf20Sopenharmony_ci/* Copyright 2017-2018 Qiang Yu <yuq825@gmail.com> */ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#ifndef __LIMA_DRM_H__ 58c2ecf20Sopenharmony_ci#define __LIMA_DRM_H__ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#include "drm.h" 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#if defined(__cplusplus) 108c2ecf20Sopenharmony_ciextern "C" { 118c2ecf20Sopenharmony_ci#endif 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_cienum drm_lima_param_gpu_id { 148c2ecf20Sopenharmony_ci DRM_LIMA_PARAM_GPU_ID_UNKNOWN, 158c2ecf20Sopenharmony_ci DRM_LIMA_PARAM_GPU_ID_MALI400, 168c2ecf20Sopenharmony_ci DRM_LIMA_PARAM_GPU_ID_MALI450, 178c2ecf20Sopenharmony_ci}; 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_cienum drm_lima_param { 208c2ecf20Sopenharmony_ci DRM_LIMA_PARAM_GPU_ID, 218c2ecf20Sopenharmony_ci DRM_LIMA_PARAM_NUM_PP, 228c2ecf20Sopenharmony_ci DRM_LIMA_PARAM_GP_VERSION, 238c2ecf20Sopenharmony_ci DRM_LIMA_PARAM_PP_VERSION, 248c2ecf20Sopenharmony_ci}; 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci/** 278c2ecf20Sopenharmony_ci * get various information of the GPU 288c2ecf20Sopenharmony_ci */ 298c2ecf20Sopenharmony_cistruct drm_lima_get_param { 308c2ecf20Sopenharmony_ci __u32 param; /* in, value in enum drm_lima_param */ 318c2ecf20Sopenharmony_ci __u32 pad; /* pad, must be zero */ 328c2ecf20Sopenharmony_ci __u64 value; /* out, parameter value */ 338c2ecf20Sopenharmony_ci}; 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci/* 368c2ecf20Sopenharmony_ci * heap buffer dynamically increase backup memory size when GP task fail 378c2ecf20Sopenharmony_ci * due to lack of heap memory. size field of heap buffer is an up bound of 388c2ecf20Sopenharmony_ci * the backup memory which can be set to a fairly large value. 398c2ecf20Sopenharmony_ci */ 408c2ecf20Sopenharmony_ci#define LIMA_BO_FLAG_HEAP (1 << 0) 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci/** 438c2ecf20Sopenharmony_ci * create a buffer for used by GPU 448c2ecf20Sopenharmony_ci */ 458c2ecf20Sopenharmony_cistruct drm_lima_gem_create { 468c2ecf20Sopenharmony_ci __u32 size; /* in, buffer size */ 478c2ecf20Sopenharmony_ci __u32 flags; /* in, buffer flags */ 488c2ecf20Sopenharmony_ci __u32 handle; /* out, GEM buffer handle */ 498c2ecf20Sopenharmony_ci __u32 pad; /* pad, must be zero */ 508c2ecf20Sopenharmony_ci}; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci/** 538c2ecf20Sopenharmony_ci * get information of a buffer 548c2ecf20Sopenharmony_ci */ 558c2ecf20Sopenharmony_cistruct drm_lima_gem_info { 568c2ecf20Sopenharmony_ci __u32 handle; /* in, GEM buffer handle */ 578c2ecf20Sopenharmony_ci __u32 va; /* out, virtual address mapped into GPU MMU */ 588c2ecf20Sopenharmony_ci __u64 offset; /* out, used to mmap this buffer to CPU */ 598c2ecf20Sopenharmony_ci}; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci#define LIMA_SUBMIT_BO_READ 0x01 628c2ecf20Sopenharmony_ci#define LIMA_SUBMIT_BO_WRITE 0x02 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci/* buffer information used by one task */ 658c2ecf20Sopenharmony_cistruct drm_lima_gem_submit_bo { 668c2ecf20Sopenharmony_ci __u32 handle; /* in, GEM buffer handle */ 678c2ecf20Sopenharmony_ci __u32 flags; /* in, buffer read/write by GPU */ 688c2ecf20Sopenharmony_ci}; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci#define LIMA_GP_FRAME_REG_NUM 6 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci/* frame used to setup GP for each task */ 738c2ecf20Sopenharmony_cistruct drm_lima_gp_frame { 748c2ecf20Sopenharmony_ci __u32 frame[LIMA_GP_FRAME_REG_NUM]; 758c2ecf20Sopenharmony_ci}; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci#define LIMA_PP_FRAME_REG_NUM 23 788c2ecf20Sopenharmony_ci#define LIMA_PP_WB_REG_NUM 12 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci/* frame used to setup mali400 GPU PP for each task */ 818c2ecf20Sopenharmony_cistruct drm_lima_m400_pp_frame { 828c2ecf20Sopenharmony_ci __u32 frame[LIMA_PP_FRAME_REG_NUM]; 838c2ecf20Sopenharmony_ci __u32 num_pp; 848c2ecf20Sopenharmony_ci __u32 wb[3 * LIMA_PP_WB_REG_NUM]; 858c2ecf20Sopenharmony_ci __u32 plbu_array_address[4]; 868c2ecf20Sopenharmony_ci __u32 fragment_stack_address[4]; 878c2ecf20Sopenharmony_ci}; 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci/* frame used to setup mali450 GPU PP for each task */ 908c2ecf20Sopenharmony_cistruct drm_lima_m450_pp_frame { 918c2ecf20Sopenharmony_ci __u32 frame[LIMA_PP_FRAME_REG_NUM]; 928c2ecf20Sopenharmony_ci __u32 num_pp; 938c2ecf20Sopenharmony_ci __u32 wb[3 * LIMA_PP_WB_REG_NUM]; 948c2ecf20Sopenharmony_ci __u32 use_dlbu; 958c2ecf20Sopenharmony_ci __u32 _pad; 968c2ecf20Sopenharmony_ci union { 978c2ecf20Sopenharmony_ci __u32 plbu_array_address[8]; 988c2ecf20Sopenharmony_ci __u32 dlbu_regs[4]; 998c2ecf20Sopenharmony_ci }; 1008c2ecf20Sopenharmony_ci __u32 fragment_stack_address[8]; 1018c2ecf20Sopenharmony_ci}; 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci#define LIMA_PIPE_GP 0x00 1048c2ecf20Sopenharmony_ci#define LIMA_PIPE_PP 0x01 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci#define LIMA_SUBMIT_FLAG_EXPLICIT_FENCE (1 << 0) 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci/** 1098c2ecf20Sopenharmony_ci * submit a task to GPU 1108c2ecf20Sopenharmony_ci * 1118c2ecf20Sopenharmony_ci * User can always merge multi sync_file and drm_syncobj 1128c2ecf20Sopenharmony_ci * into one drm_syncobj as in_sync[0], but we reserve 1138c2ecf20Sopenharmony_ci * in_sync[1] for another task's out_sync to avoid the 1148c2ecf20Sopenharmony_ci * export/import/merge pass when explicit sync. 1158c2ecf20Sopenharmony_ci */ 1168c2ecf20Sopenharmony_cistruct drm_lima_gem_submit { 1178c2ecf20Sopenharmony_ci __u32 ctx; /* in, context handle task is submitted to */ 1188c2ecf20Sopenharmony_ci __u32 pipe; /* in, which pipe to use, GP/PP */ 1198c2ecf20Sopenharmony_ci __u32 nr_bos; /* in, array length of bos field */ 1208c2ecf20Sopenharmony_ci __u32 frame_size; /* in, size of frame field */ 1218c2ecf20Sopenharmony_ci __u64 bos; /* in, array of drm_lima_gem_submit_bo */ 1228c2ecf20Sopenharmony_ci __u64 frame; /* in, GP/PP frame */ 1238c2ecf20Sopenharmony_ci __u32 flags; /* in, submit flags */ 1248c2ecf20Sopenharmony_ci __u32 out_sync; /* in, drm_syncobj handle used to wait task finish after submission */ 1258c2ecf20Sopenharmony_ci __u32 in_sync[2]; /* in, drm_syncobj handle used to wait before start this task */ 1268c2ecf20Sopenharmony_ci}; 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci#define LIMA_GEM_WAIT_READ 0x01 1298c2ecf20Sopenharmony_ci#define LIMA_GEM_WAIT_WRITE 0x02 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci/** 1328c2ecf20Sopenharmony_ci * wait pending GPU task finish of a buffer 1338c2ecf20Sopenharmony_ci */ 1348c2ecf20Sopenharmony_cistruct drm_lima_gem_wait { 1358c2ecf20Sopenharmony_ci __u32 handle; /* in, GEM buffer handle */ 1368c2ecf20Sopenharmony_ci __u32 op; /* in, CPU want to read/write this buffer */ 1378c2ecf20Sopenharmony_ci __s64 timeout_ns; /* in, wait timeout in absulute time */ 1388c2ecf20Sopenharmony_ci}; 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci/** 1418c2ecf20Sopenharmony_ci * create a context 1428c2ecf20Sopenharmony_ci */ 1438c2ecf20Sopenharmony_cistruct drm_lima_ctx_create { 1448c2ecf20Sopenharmony_ci __u32 id; /* out, context handle */ 1458c2ecf20Sopenharmony_ci __u32 _pad; /* pad, must be zero */ 1468c2ecf20Sopenharmony_ci}; 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci/** 1498c2ecf20Sopenharmony_ci * free a context 1508c2ecf20Sopenharmony_ci */ 1518c2ecf20Sopenharmony_cistruct drm_lima_ctx_free { 1528c2ecf20Sopenharmony_ci __u32 id; /* in, context handle */ 1538c2ecf20Sopenharmony_ci __u32 _pad; /* pad, must be zero */ 1548c2ecf20Sopenharmony_ci}; 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci#define DRM_LIMA_GET_PARAM 0x00 1578c2ecf20Sopenharmony_ci#define DRM_LIMA_GEM_CREATE 0x01 1588c2ecf20Sopenharmony_ci#define DRM_LIMA_GEM_INFO 0x02 1598c2ecf20Sopenharmony_ci#define DRM_LIMA_GEM_SUBMIT 0x03 1608c2ecf20Sopenharmony_ci#define DRM_LIMA_GEM_WAIT 0x04 1618c2ecf20Sopenharmony_ci#define DRM_LIMA_CTX_CREATE 0x05 1628c2ecf20Sopenharmony_ci#define DRM_LIMA_CTX_FREE 0x06 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci#define DRM_IOCTL_LIMA_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_LIMA_GET_PARAM, struct drm_lima_get_param) 1658c2ecf20Sopenharmony_ci#define DRM_IOCTL_LIMA_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_LIMA_GEM_CREATE, struct drm_lima_gem_create) 1668c2ecf20Sopenharmony_ci#define DRM_IOCTL_LIMA_GEM_INFO DRM_IOWR(DRM_COMMAND_BASE + DRM_LIMA_GEM_INFO, struct drm_lima_gem_info) 1678c2ecf20Sopenharmony_ci#define DRM_IOCTL_LIMA_GEM_SUBMIT DRM_IOW(DRM_COMMAND_BASE + DRM_LIMA_GEM_SUBMIT, struct drm_lima_gem_submit) 1688c2ecf20Sopenharmony_ci#define DRM_IOCTL_LIMA_GEM_WAIT DRM_IOW(DRM_COMMAND_BASE + DRM_LIMA_GEM_WAIT, struct drm_lima_gem_wait) 1698c2ecf20Sopenharmony_ci#define DRM_IOCTL_LIMA_CTX_CREATE DRM_IOR(DRM_COMMAND_BASE + DRM_LIMA_CTX_CREATE, struct drm_lima_ctx_create) 1708c2ecf20Sopenharmony_ci#define DRM_IOCTL_LIMA_CTX_FREE DRM_IOW(DRM_COMMAND_BASE + DRM_LIMA_CTX_FREE, struct drm_lima_ctx_free) 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci#if defined(__cplusplus) 1738c2ecf20Sopenharmony_ci} 1748c2ecf20Sopenharmony_ci#endif 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci#endif /* __LIMA_DRM_H__ */ 177