Path: blob/21.2-virgl/src/broadcom/drm-shim/vc4_noop.c
4560 views
/*1* Copyright (c) 2021 Etnaviv Project2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER20* DEALINGS IN THE SOFTWARE.21*/2223#include <limits.h>24#include <stdio.h>25#include <stdlib.h>26#include <sys/ioctl.h>27#include "drm-uapi/vc4_drm.h"28#include "drm-shim/drm_shim.h"2930bool drm_shim_driver_prefers_first_render_node = true;3132static int33vc4_ioctl_noop(int fd, unsigned long request, void *arg)34{35return 0;36}3738static int39vc4_ioctl_create_bo(int fd, unsigned long request, void *arg)40{41struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);42struct drm_vc4_create_bo *create = arg;43struct shim_bo *bo = calloc(1, sizeof(*bo));4445drm_shim_bo_init(bo, create->size);46create->handle = drm_shim_bo_get_handle(shim_fd, bo);47drm_shim_bo_put(bo);4849return 0;50}5152static int53vc4_ioctl_mmap_bo(int fd, unsigned long request, void *arg)54{55struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);56struct drm_vc4_mmap_bo *map = arg;57struct shim_bo *bo = drm_shim_bo_lookup(shim_fd, map->handle);5859map->offset = drm_shim_bo_get_mmap_offset(shim_fd, bo);6061drm_shim_bo_put(bo);6263return 0;64}6566static int67vc4_ioctl_get_param(int fd, unsigned long request, void *arg)68{69struct drm_vc4_get_param *gp = arg;70static const uint32_t param_map[] = {71[DRM_VC4_PARAM_V3D_IDENT0] = 0x2000000,72[DRM_VC4_PARAM_V3D_IDENT1] = 0x0000001,73};7475switch (gp->param) {76case DRM_VC4_PARAM_SUPPORTS_BRANCHES:77case DRM_VC4_PARAM_SUPPORTS_ETC1:78case DRM_VC4_PARAM_SUPPORTS_THREADED_FS:79case DRM_VC4_PARAM_SUPPORTS_FIXED_RCL_ORDER:80gp->value = 1;81return 0;8283case DRM_VC4_PARAM_SUPPORTS_MADVISE:84case DRM_VC4_PARAM_SUPPORTS_PERFMON:85gp->value = 0;86return 0;8788default:89break;90}9192if (gp->param < ARRAY_SIZE(param_map) && param_map[gp->param]) {93gp->value = param_map[gp->param];94return 0;95}9697fprintf(stderr, "Unknown DRM_IOCTL_VC4_GET_PARAM %d\n", gp->param);98return -1;99}100101static ioctl_fn_t driver_ioctls[] = {102[DRM_VC4_CREATE_BO] = vc4_ioctl_create_bo,103[DRM_VC4_MMAP_BO] = vc4_ioctl_mmap_bo,104[DRM_VC4_GET_PARAM] = vc4_ioctl_get_param,105[DRM_VC4_GET_TILING] = vc4_ioctl_noop,106[DRM_VC4_LABEL_BO] = vc4_ioctl_noop,107};108109void110drm_shim_driver_init(void)111{112shim_device.bus_type = DRM_BUS_PLATFORM;113shim_device.driver_name = "vc4";114shim_device.driver_ioctls = driver_ioctls;115shim_device.driver_ioctl_count = ARRAY_SIZE(driver_ioctls);116117drm_shim_override_file("OF_FULLNAME=/rdb/vc4\n"118"OF_COMPATIBLE_N=1\n"119"OF_COMPATIBLE_0=brcm,7278-vc4\n",120"/sys/dev/char/%d:%d/device/uevent",121DRM_MAJOR, render_node_minor);122}123124125