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 "pipe/p_defines.h"
29#include "pipe/p_state.h"
30#include "util/list.h"
31#include "os/os_thread.h"
32
33#include "virgl/virgl_winsys.h"
34#include "vtest_protocol.h"
35
36struct pipe_fence_handle;
37struct sw_winsys;
38struct sw_displaytarget;
39
40struct virgl_vtest_winsys {
41   struct virgl_winsys base;
42
43   struct sw_winsys *sws;
44
45   /* fd to remote renderer */
46   int sock_fd;
47
48   struct list_head delayed;
49   int num_delayed;
50   unsigned usecs;
51   pipe_mutex mutex;
52};
53
54struct virgl_hw_res {
55   struct pipe_reference reference;
56   uint32_t res_handle;
57   int num_cs_references;
58
59   void *ptr;
60   int size;
61
62   uint32_t format;
63   uint32_t stride;
64   uint32_t width;
65   uint32_t height;
66
67   struct sw_displaytarget *dt;
68   void *mapped;
69
70   struct list_head head;
71   uint32_t bind;
72   boolean cacheable;
73   int64_t start, end;
74
75};
76
77struct virgl_vtest_cmd_buf {
78   struct virgl_cmd_buf base;
79   uint32_t buf[VIRGL_MAX_CMDBUF_DWORDS];
80   unsigned nres;
81   unsigned cres;
82   struct virgl_winsys *ws;
83   struct virgl_hw_res **res_bo;
84
85   char                        is_handle_added[512];
86   unsigned                    reloc_indices_hashlist[512];
87};
88
89static inline struct virgl_hw_res *
90virgl_hw_res(struct pipe_fence_handle *f)
91{
92   return (struct virgl_hw_res *)f;
93}
94
95static inline struct virgl_vtest_winsys *
96virgl_vtest_winsys(struct virgl_winsys *iws)
97{
98   return (struct virgl_vtest_winsys *)iws;
99}
100
101static inline struct virgl_vtest_cmd_buf *
102virgl_vtest_cmd_buf(struct virgl_cmd_buf *cbuf)
103{
104   return (struct virgl_vtest_cmd_buf *)cbuf;
105}
106
107
108int virgl_vtest_connect(struct virgl_vtest_winsys *vws);
109int virgl_vtest_send_get_caps(struct virgl_vtest_winsys *vws,
110                              struct virgl_drm_caps *caps);
111
112int virgl_vtest_send_resource_create(struct virgl_vtest_winsys *vws,
113                                     uint32_t handle,
114                                     enum pipe_texture_target target,
115                                     uint32_t format,
116                                     uint32_t bind,
117                                     uint32_t width,
118                                     uint32_t height,
119                                     uint32_t depth,
120                                     uint32_t array_size,
121                                     uint32_t last_level,
122                                     uint32_t nr_samples);
123
124int virgl_vtest_send_resource_unref(struct virgl_vtest_winsys *vws,
125                                    uint32_t handle);
126int virgl_vtest_submit_cmd(struct virgl_vtest_winsys *vtws,
127                           struct virgl_vtest_cmd_buf *cbuf);
128
129int virgl_vtest_send_transfer_cmd(struct virgl_vtest_winsys *vws,
130                                  uint32_t vcmd,
131                                  uint32_t handle,
132                                  uint32_t level, uint32_t stride,
133                                  uint32_t layer_stride,
134                                  const struct pipe_box *box,
135                                  uint32_t data_size);
136
137int virgl_vtest_send_transfer_put_data(struct virgl_vtest_winsys *vws,
138                                       void *data,
139                                       uint32_t data_size);
140int virgl_vtest_recv_transfer_get_data(struct virgl_vtest_winsys *vws,
141                                       void *data,
142                                       uint32_t data_size,
143                                       uint32_t stride,
144                                       const struct pipe_box *box,
145                                       uint32_t format);
146
147int virgl_vtest_busy_wait(struct virgl_vtest_winsys *vws, int handle,
148                          int flags);
149#endif
150