c83527206f560d40ff36e60de419f08fc44c8af2
[mesa.git] / src / gallium / winsys / virgl / drm / virgl_drm_winsys.h
1 /*
2 * Copyright 2014, 2015 Red Hat.
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23 #ifndef VIRGL_DRM_WINSYS_H
24 #define VIRGL_DRM_WINSYS_H
25
26 #include <stdint.h>
27 #include "pipe/p_compiler.h"
28 #include "drm.h"
29
30 #include "os/os_thread.h"
31 #include "util/list.h"
32 #include "util/u_inlines.h"
33 #include "util/u_hash_table.h"
34
35 #include "pipe/p_screen.h"
36 #include "pipe/p_context.h"
37 #include "pipe/p_context.h"
38
39 #include "virgl/virgl_hw.h"
40 #include "virgl/virgl_winsys.h"
41
42 struct pipe_fence_handle;
43
44 struct virgl_hw_res {
45 struct pipe_reference reference;
46 uint32_t res_handle;
47 uint32_t bo_handle;
48 uint32_t name;
49 int num_cs_references;
50 uint32_t size;
51 void *ptr;
52 uint32_t stride;
53
54 struct list_head head;
55 uint32_t format;
56 uint32_t bind;
57 boolean cacheable;
58 int64_t start, end;
59 boolean flinked;
60 uint32_t flink;
61 };
62
63 struct virgl_drm_winsys
64 {
65 struct virgl_winsys base;
66 int fd;
67 struct list_head delayed;
68 int num_delayed;
69 unsigned usecs;
70 pipe_mutex mutex;
71
72 struct util_hash_table *bo_handles;
73 pipe_mutex bo_handles_mutex;
74 };
75
76 struct virgl_drm_cmd_buf {
77 struct virgl_cmd_buf base;
78
79 uint32_t buf[VIRGL_MAX_CMDBUF_DWORDS];
80
81 unsigned nres;
82 unsigned cres;
83 struct virgl_hw_res **res_bo;
84 struct virgl_winsys *ws;
85 uint32_t *res_hlist;
86
87 char is_handle_added[512];
88 unsigned reloc_indices_hashlist[512];
89
90 };
91
92 static inline struct virgl_hw_res *
93 virgl_hw_res(struct pipe_fence_handle *f)
94 {
95 return (struct virgl_hw_res *)f;
96 }
97
98 static inline struct virgl_drm_winsys *
99 virgl_drm_winsys(struct virgl_winsys *iws)
100 {
101 return (struct virgl_drm_winsys *)iws;
102 }
103
104 static inline struct virgl_drm_cmd_buf *
105 virgl_drm_cmd_buf(struct virgl_cmd_buf *cbuf)
106 {
107 return (struct virgl_drm_cmd_buf *)cbuf;
108 }
109
110 #endif