2
* Copyright (C) 2021 Icecream95
3
* Copyright (C) 2019 Google LLC
5
* Permission is hereby granted, free of charge, to any person obtaining a
6
* copy of this software and associated documentation files (the "Software"),
7
* to deal in the Software without restriction, including without limitation
8
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
* and/or sell copies of the Software, and to permit persons to whom the
10
* Software is furnished to do so, subject to the following conditions:
12
* The above copyright notice and this permission notice (including the next
13
* paragraph) shall be included in all copies or substantial portions of the
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
* DEALINGS IN THE SOFTWARE.
28
#include "drm-shim/drm_shim.h"
29
#include "drm-uapi/lima_drm.h"
31
#include "util/u_math.h"
33
bool drm_shim_driver_prefers_first_render_node = true;
36
lima_ioctl_noop(int fd, unsigned long request, void *arg)
42
lima_ioctl_get_param(int fd, unsigned long request, void *arg)
44
struct drm_lima_get_param *gp = arg;
47
case DRM_LIMA_PARAM_GPU_ID:
48
gp->value = DRM_LIMA_PARAM_GPU_ID_MALI450;
50
case DRM_LIMA_PARAM_NUM_PP:
54
fprintf(stderr, "Unknown DRM_IOCTL_LIMA_GET_PARAM %d\n", gp->param);
60
lima_ioctl_gem_create(int fd, unsigned long request, void *arg)
62
struct drm_lima_gem_create *create = arg;
64
struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
65
struct shim_bo *bo = calloc(1, sizeof(*bo));
66
size_t size = ALIGN(create->size, 4096);
68
drm_shim_bo_init(bo, size);
70
create->handle = drm_shim_bo_get_handle(shim_fd, bo);
78
lima_ioctl_gem_info(int fd, unsigned long request, void *arg)
80
struct drm_lima_gem_info *gem_info = arg;
82
struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
83
struct shim_bo *bo = drm_shim_bo_lookup(shim_fd, gem_info->handle);
85
gem_info->va = bo->mem_addr;
86
gem_info->offset = drm_shim_bo_get_mmap_offset(shim_fd, bo);
91
static ioctl_fn_t driver_ioctls[] = {
92
[DRM_LIMA_GET_PARAM] = lima_ioctl_get_param,
93
[DRM_LIMA_GEM_CREATE] = lima_ioctl_gem_create,
94
[DRM_LIMA_GEM_INFO] = lima_ioctl_gem_info,
95
[DRM_LIMA_GEM_SUBMIT] = lima_ioctl_noop,
96
[DRM_LIMA_GEM_WAIT] = lima_ioctl_noop,
97
[DRM_LIMA_CTX_CREATE] = lima_ioctl_noop,
98
[DRM_LIMA_CTX_FREE] = lima_ioctl_noop,
102
drm_shim_driver_init(void)
104
shim_device.bus_type = DRM_BUS_PLATFORM;
105
shim_device.driver_name = "lima";
106
shim_device.driver_ioctls = driver_ioctls;
107
shim_device.driver_ioctl_count = ARRAY_SIZE(driver_ioctls);
109
/* lima uses the DRM version to expose features, instead of getparam. */
110
shim_device.version_major = 1;
111
shim_device.version_minor = 1;
112
shim_device.version_patchlevel = 0;
114
drm_shim_override_file("DRIVER=lima\n"
115
"OF_FULLNAME=/soc/mali\n"
116
"OF_COMPATIBLE_0=arm,mali-450\n"
117
"OF_COMPATIBLE_N=1\n",
118
"/sys/dev/char/%d:%d/device/uevent", DRM_MAJOR,