freedreno: Make the slice pitch be bytes, not pixels.
[mesa.git] / src / broadcom / drm-shim / v3d_noop.c
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 <limits.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <sys/ioctl.h>
28 #include "drm-uapi/v3d_drm.h"
29 #include "drm-shim/drm_shim.h"
30
31 struct v3d_bo {
32 struct shim_bo base;
33 uint32_t offset;
34 };
35
36 static struct v3d_bo *
37 v3d_bo(struct shim_bo *bo)
38 {
39 return (struct v3d_bo *)bo;
40 }
41
42 struct v3d_device {
43 uint32_t next_offset;
44 };
45
46 static struct v3d_device v3d = {
47 .next_offset = 0x1000,
48 };
49
50 static int
51 v3d_ioctl_noop(int fd, unsigned long request, void *arg)
52 {
53 return 0;
54 }
55
56 static int
57 v3d_ioctl_create_bo(int fd, unsigned long request, void *arg)
58 {
59 struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
60 struct drm_v3d_create_bo *create = arg;
61 struct v3d_bo *bo = calloc(1, sizeof(*bo));
62
63 drm_shim_bo_init(&bo->base, create->size);
64
65 assert(UINT_MAX - v3d.next_offset > create->size);
66 bo->offset = v3d.next_offset;
67 v3d.next_offset += create->size;
68
69 create->offset = bo->offset;
70 create->handle = drm_shim_bo_get_handle(shim_fd, &bo->base);
71
72 drm_shim_bo_put(&bo->base);
73
74 return 0;
75 }
76
77 static int
78 v3d_ioctl_get_bo_offset(int fd, unsigned long request, void *arg)
79 {
80 struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
81 struct drm_v3d_get_bo_offset *args = arg;
82 struct shim_bo *bo = drm_shim_bo_lookup(shim_fd, args->handle);
83
84 args->offset = v3d_bo(bo)->offset;
85
86 drm_shim_bo_put(bo);
87
88 return 0;
89 }
90
91 static int
92 v3d_ioctl_mmap_bo(int fd, unsigned long request, void *arg)
93 {
94 struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
95 struct drm_v3d_mmap_bo *map = arg;
96 struct shim_bo *bo = drm_shim_bo_lookup(shim_fd, map->handle);
97
98 map->offset = drm_shim_bo_get_mmap_offset(shim_fd, bo);
99
100 drm_shim_bo_put(bo);
101
102 return 0;
103 }
104
105 static int
106 v3d_ioctl_get_param(int fd, unsigned long request, void *arg)
107 {
108 struct drm_v3d_get_param *gp = arg;
109 static const uint32_t v3d42_reg_map[] = {
110 [DRM_V3D_PARAM_V3D_UIFCFG] = 0x00000045,
111 [DRM_V3D_PARAM_V3D_HUB_IDENT1] = 0x000e1124,
112 [DRM_V3D_PARAM_V3D_HUB_IDENT2] = 0x00000100,
113 [DRM_V3D_PARAM_V3D_HUB_IDENT3] = 0x00000e00,
114 [DRM_V3D_PARAM_V3D_CORE0_IDENT0] = 0x04443356,
115 [DRM_V3D_PARAM_V3D_CORE0_IDENT1] = 0x81001422,
116 [DRM_V3D_PARAM_V3D_CORE0_IDENT2] = 0x40078121,
117 };
118
119 switch (gp->param) {
120 case DRM_V3D_PARAM_SUPPORTS_TFU:
121 gp->value = 1;
122 return 0;
123 default:
124 break;
125 }
126
127 if (gp->param < ARRAY_SIZE(v3d42_reg_map) && v3d42_reg_map[gp->param]) {
128 gp->value = v3d42_reg_map[gp->param];
129 return 0;
130 }
131
132 fprintf(stderr, "Unknown DRM_IOCTL_V3D_GET_PARAM %d\n", gp->param);
133 return -1;
134 }
135
136 static ioctl_fn_t driver_ioctls[] = {
137 [DRM_V3D_SUBMIT_CL] = v3d_ioctl_noop,
138 [DRM_V3D_SUBMIT_TFU] = v3d_ioctl_noop,
139 [DRM_V3D_WAIT_BO] = v3d_ioctl_noop,
140 [DRM_V3D_CREATE_BO] = v3d_ioctl_create_bo,
141 [DRM_V3D_GET_PARAM] = v3d_ioctl_get_param,
142 [DRM_V3D_GET_BO_OFFSET] = v3d_ioctl_get_bo_offset,
143 [DRM_V3D_MMAP_BO] = v3d_ioctl_mmap_bo,
144 };
145
146 void
147 drm_shim_driver_init(void)
148 {
149 shim_device.bus_type = DRM_BUS_PLATFORM;
150 shim_device.driver_name = "v3d";
151 shim_device.driver_ioctls = driver_ioctls;
152 shim_device.driver_ioctl_count = ARRAY_SIZE(driver_ioctls);
153
154 drm_shim_override_file("OF_FULLNAME=/rdb/v3d\n"
155 "OF_COMPATIBLE_N=1\n"
156 "OF_COMPATIBLE_0=brcm,7278-v3d\n",
157 "/sys/dev/char/%d:%d/device/uevent",
158 DRM_MAJOR, render_node_minor);
159 }