Path: blob/21.2-virgl/src/broadcom/drm-shim/v3d_noop.c
4560 views
/*1* Copyright © 2018 Broadcom2*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/v3d_drm.h"28#include "drm-shim/drm_shim.h"2930bool drm_shim_driver_prefers_first_render_node = true;3132struct v3d_bo {33struct shim_bo base;34uint32_t offset;35};3637static struct v3d_bo *38v3d_bo(struct shim_bo *bo)39{40return (struct v3d_bo *)bo;41}4243struct v3d_device {44uint32_t next_offset;45};4647static struct v3d_device v3d = {48.next_offset = 0x1000,49};5051static int52v3d_ioctl_noop(int fd, unsigned long request, void *arg)53{54return 0;55}5657static int58v3d_ioctl_create_bo(int fd, unsigned long request, void *arg)59{60struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);61struct drm_v3d_create_bo *create = arg;62struct v3d_bo *bo = calloc(1, sizeof(*bo));6364drm_shim_bo_init(&bo->base, create->size);6566assert(UINT_MAX - v3d.next_offset > create->size);67bo->offset = v3d.next_offset;68v3d.next_offset += create->size;6970create->offset = bo->offset;71create->handle = drm_shim_bo_get_handle(shim_fd, &bo->base);7273drm_shim_bo_put(&bo->base);7475return 0;76}7778static int79v3d_ioctl_get_bo_offset(int fd, unsigned long request, void *arg)80{81struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);82struct drm_v3d_get_bo_offset *args = arg;83struct shim_bo *bo = drm_shim_bo_lookup(shim_fd, args->handle);8485args->offset = v3d_bo(bo)->offset;8687drm_shim_bo_put(bo);8889return 0;90}9192static int93v3d_ioctl_mmap_bo(int fd, unsigned long request, void *arg)94{95struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);96struct drm_v3d_mmap_bo *map = arg;97struct shim_bo *bo = drm_shim_bo_lookup(shim_fd, map->handle);9899map->offset = drm_shim_bo_get_mmap_offset(shim_fd, bo);100101drm_shim_bo_put(bo);102103return 0;104}105106static int107v3d_ioctl_get_param(int fd, unsigned long request, void *arg)108{109struct drm_v3d_get_param *gp = arg;110static const uint32_t v3d42_reg_map[] = {111[DRM_V3D_PARAM_V3D_UIFCFG] = 0x00000045,112[DRM_V3D_PARAM_V3D_HUB_IDENT1] = 0x000e1124,113[DRM_V3D_PARAM_V3D_HUB_IDENT2] = 0x00000100,114[DRM_V3D_PARAM_V3D_HUB_IDENT3] = 0x00000e00,115[DRM_V3D_PARAM_V3D_CORE0_IDENT0] = 0x04443356,116[DRM_V3D_PARAM_V3D_CORE0_IDENT1] = 0x81001422,117[DRM_V3D_PARAM_V3D_CORE0_IDENT2] = 0x40078121,118};119120switch (gp->param) {121case DRM_V3D_PARAM_SUPPORTS_TFU:122gp->value = 1;123return 0;124default:125break;126}127128if (gp->param < ARRAY_SIZE(v3d42_reg_map) && v3d42_reg_map[gp->param]) {129gp->value = v3d42_reg_map[gp->param];130return 0;131}132133fprintf(stderr, "Unknown DRM_IOCTL_V3D_GET_PARAM %d\n", gp->param);134return -1;135}136137static ioctl_fn_t driver_ioctls[] = {138[DRM_V3D_SUBMIT_CL] = v3d_ioctl_noop,139[DRM_V3D_SUBMIT_TFU] = v3d_ioctl_noop,140[DRM_V3D_WAIT_BO] = v3d_ioctl_noop,141[DRM_V3D_CREATE_BO] = v3d_ioctl_create_bo,142[DRM_V3D_GET_PARAM] = v3d_ioctl_get_param,143[DRM_V3D_GET_BO_OFFSET] = v3d_ioctl_get_bo_offset,144[DRM_V3D_MMAP_BO] = v3d_ioctl_mmap_bo,145};146147void148drm_shim_driver_init(void)149{150shim_device.bus_type = DRM_BUS_PLATFORM;151shim_device.driver_name = "v3d";152shim_device.driver_ioctls = driver_ioctls;153shim_device.driver_ioctl_count = ARRAY_SIZE(driver_ioctls);154155drm_shim_override_file("OF_FULLNAME=/rdb/v3d\n"156"OF_COMPATIBLE_N=1\n"157"OF_COMPATIBLE_0=brcm,7278-v3d\n",158"/sys/dev/char/%d:%d/device/uevent",159DRM_MAJOR, render_node_minor);160}161162163