1/* 2 * Copyright © 2018 Broadcom 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 * DEALINGS IN THE SOFTWARE. 22 */ 23 24#include <stdio.h> 25#include <sys/ioctl.h> 26#include "drm-uapi/v3d_drm.h" 27#include "drm-shim/drm_shim.h" 28#include "v3d.h" 29#include "v3d_simulator_wrapper.h" 30 31bool drm_shim_driver_prefers_first_render_node = false; 32 33static struct v3d_device_info devinfo; 34struct v3d_shim_device v3d = { 35 .devinfo = &devinfo 36}; 37 38struct v3d_bo *v3d_bo_lookup(struct shim_fd *shim_fd, int handle) 39{ 40 return v3d_bo(drm_shim_bo_lookup(shim_fd, handle)); 41} 42 43int 44v3d_ioctl_wait_bo(int fd, unsigned long request, void *arg) 45{ 46 /* No need to wait on anything yet, given that we submit 47 * synchronously. 48 */ 49 return 0; 50} 51 52int 53v3d_ioctl_mmap_bo(int fd, unsigned long request, void *arg) 54{ 55 struct shim_fd *shim_fd = drm_shim_fd_lookup(fd); 56 struct drm_v3d_mmap_bo *map = arg; 57 struct shim_bo *bo = drm_shim_bo_lookup(shim_fd, map->handle); 58 59 map->offset = drm_shim_bo_get_mmap_offset(shim_fd, bo); 60 61 drm_shim_bo_put(bo); 62 63 return 0; 64} 65 66int 67v3d_ioctl_get_bo_offset(int fd, unsigned long request, void *arg) 68{ 69 struct shim_fd *shim_fd = drm_shim_fd_lookup(fd); 70 struct drm_v3d_get_bo_offset *get = arg; 71 struct v3d_bo *bo = v3d_bo_lookup(shim_fd, get->handle); 72 73 get->offset = bo->offset; 74 75 drm_shim_bo_put(&bo->base); 76 77 return 0; 78} 79 80void 81drm_shim_driver_init(void) 82{ 83 shim_device.bus_type = DRM_BUS_PLATFORM; 84 shim_device.driver_name = "v3d"; 85 86 drm_shim_override_file("OF_FULLNAME=/rdb/v3d\n" 87 "OF_COMPATIBLE_N=1\n" 88 "OF_COMPATIBLE_0=brcm,7278-v3d\n", 89 "/sys/dev/char/%d:%d/device/uevent", 90 DRM_MAJOR, render_node_minor); 91 92 v3d.hw = v3d_hw_auto_new(NULL); 93 v3d.devinfo->ver = v3d_hw_get_version(v3d.hw); 94 95 if (v3d.devinfo->ver >= 42) 96 v3d42_drm_shim_driver_init(); 97 else if (v3d.devinfo->ver >= 41) 98 v3d41_drm_shim_driver_init(); 99 else 100 v3d33_drm_shim_driver_init(); 101} 102