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 "os/os_thread.h"
28#include "pipe/p_state.h"
29#include "util/list.h"
30
31#include "virgl/virgl_winsys.h"
32
33struct pipe_fence_handle;
34struct util_hash_table;
35
36struct virgl_hw_res {
37   struct pipe_reference reference;
38   uint32_t res_handle;
39   uint32_t bo_handle;
40   int num_cs_references;
41   uint32_t size;
42   void *ptr;
43   uint32_t stride;
44
45   struct list_head head;
46   uint32_t format;
47   uint32_t bind;
48   boolean cacheable;
49   int64_t start, end;
50   uint32_t flink_name;
51};
52
53struct virgl_drm_winsys
54{
55   struct virgl_winsys base;
56   int fd;
57   struct list_head delayed;
58   int num_delayed;
59   unsigned usecs;
60   mtx_t mutex;
61
62   struct util_hash_table *bo_handles;
63   struct util_hash_table *bo_names;
64   mtx_t bo_handles_mutex;
65   bool has_capset_query_fix;
66};
67
68struct virgl_drm_fence {
69   struct pipe_reference reference;
70   bool external;
71   int fd;
72   struct virgl_hw_res *hw_res;
73};
74
75struct virgl_drm_cmd_buf {
76   struct virgl_cmd_buf base;
77
78   uint32_t *buf;
79
80   int in_fence_fd;
81
82   unsigned nres;
83   unsigned cres;
84   struct virgl_hw_res **res_bo;
85   struct virgl_winsys *ws;
86   uint32_t *res_hlist;
87
88   char                        is_handle_added[512];
89   unsigned                    reloc_indices_hashlist[512];
90
91};
92
93static inline struct virgl_drm_winsys *
94virgl_drm_winsys(struct virgl_winsys *iws)
95{
96   return (struct virgl_drm_winsys *)iws;
97}
98
99static inline struct virgl_drm_fence *
100virgl_drm_fence(struct pipe_fence_handle *f)
101{
102   return (struct virgl_drm_fence *)f;
103}
104
105static inline struct virgl_drm_cmd_buf *
106virgl_drm_cmd_buf(struct virgl_cmd_buf *cbuf)
107{
108   return (struct virgl_drm_cmd_buf *)cbuf;
109}
110
111#endif
112