spirv: Rewrite CFG construction
[mesa.git] / src / broadcom / drm-shim / v3d.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 <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
31 static struct v3d_device_info devinfo;
32 struct v3d_shim_device v3d = {
33 .devinfo = &devinfo
34 };
35
36 struct v3d_bo *v3d_bo_lookup(struct shim_fd *shim_fd, int handle)
37 {
38 return v3d_bo(drm_shim_bo_lookup(shim_fd, handle));
39 }
40
41 int
42 v3d_ioctl_wait_bo(int fd, unsigned long request, void *arg)
43 {
44 /* No need to wait on anything yet, given that we submit
45 * synchronously.
46 */
47 return 0;
48 }
49
50 int
51 v3d_ioctl_mmap_bo(int fd, unsigned long request, void *arg)
52 {
53 struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
54 struct drm_v3d_mmap_bo *map = arg;
55 struct shim_bo *bo = drm_shim_bo_lookup(shim_fd, map->handle);
56
57 map->offset = drm_shim_bo_get_mmap_offset(shim_fd, bo);
58
59 drm_shim_bo_put(bo);
60
61 return 0;
62 }
63
64 int
65 v3d_ioctl_get_bo_offset(int fd, unsigned long request, void *arg)
66 {
67 struct shim_fd *shim_fd = drm_shim_fd_lookup(fd);
68 struct drm_v3d_get_bo_offset *get = arg;
69 struct v3d_bo *bo = v3d_bo_lookup(shim_fd, get->handle);
70
71 get->offset = bo->offset;
72
73 drm_shim_bo_put(&bo->base);
74
75 return 0;
76 }
77
78 void
79 drm_shim_driver_init(void)
80 {
81 shim_device.driver_name = "v3d";
82
83 drm_shim_override_file("OF_FULLNAME=/rdb/v3d\n"
84 "OF_COMPATIBLE_N=1\n"
85 "OF_COMPATIBLE_0=brcm,7278-v3d\n",
86 "/sys/dev/char/%d:%d/device/uevent",
87 DRM_MAJOR, render_node_minor);
88
89 v3d.hw = v3d_hw_auto_new(NULL);
90 v3d.devinfo->ver = v3d_hw_get_version(v3d.hw);
91
92 if (v3d.devinfo->ver >= 42)
93 v3d42_drm_shim_driver_init();
94 else if (v3d.devinfo->ver >= 41)
95 v3d41_drm_shim_driver_init();
96 else
97 v3d33_drm_shim_driver_init();
98 }