Path: blob/21.2-virgl/src/broadcom/drm-shim/v3d.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 <stdio.h>24#include <sys/ioctl.h>25#include "drm-uapi/v3d_drm.h"26#include "drm-shim/drm_shim.h"27#include "v3d.h"28#include "v3d_simulator_wrapper.h"2930bool drm_shim_driver_prefers_first_render_node = false;3132static struct v3d_device_info devinfo;33struct v3d_shim_device v3d = {34.devinfo = &devinfo35};3637struct v3d_bo *v3d_bo_lookup(struct shim_fd *shim_fd, int handle)38{39return v3d_bo(drm_shim_bo_lookup(shim_fd, handle));40}4142int43v3d_ioctl_wait_bo(int fd, unsigned long request, void *arg)44{45/* No need to wait on anything yet, given that we submit46* synchronously.47*/48return 0;49}5051int52v3d_ioctl_mmap_bo(int fd, unsigned long request, void *arg)53{54struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);55struct drm_v3d_mmap_bo *map = arg;56struct shim_bo *bo = drm_shim_bo_lookup(shim_fd, map->handle);5758map->offset = drm_shim_bo_get_mmap_offset(shim_fd, bo);5960drm_shim_bo_put(bo);6162return 0;63}6465int66v3d_ioctl_get_bo_offset(int fd, unsigned long request, void *arg)67{68struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);69struct drm_v3d_get_bo_offset *get = arg;70struct v3d_bo *bo = v3d_bo_lookup(shim_fd, get->handle);7172get->offset = bo->offset;7374drm_shim_bo_put(&bo->base);7576return 0;77}7879void80drm_shim_driver_init(void)81{82shim_device.bus_type = DRM_BUS_PLATFORM;83shim_device.driver_name = "v3d";8485drm_shim_override_file("OF_FULLNAME=/rdb/v3d\n"86"OF_COMPATIBLE_N=1\n"87"OF_COMPATIBLE_0=brcm,7278-v3d\n",88"/sys/dev/char/%d:%d/device/uevent",89DRM_MAJOR, render_node_minor);9091v3d.hw = v3d_hw_auto_new(NULL);92v3d.devinfo->ver = v3d_hw_get_version(v3d.hw);9394if (v3d.devinfo->ver >= 42)95v3d42_drm_shim_driver_init();96else if (v3d.devinfo->ver >= 41)97v3d41_drm_shim_driver_init();98else99v3d33_drm_shim_driver_init();100}101102103