1 /*
2 * Copyright © 2008 Jérôme Glisse
3 * Copyright © 2011 Marek Olšák <maraeo@gmail.com>
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS
18 * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * The above copyright notice and this permission notice (including the
24 * next paragraph) shall be included in all copies or substantial portions
25 * of the Software.
26 */
27
28 #ifndef RADEON_DRM_BO_H
29 #define RADEON_DRM_BO_H
30
31 #include "radeon_drm_winsys.h"
32 #include "os/os_thread.h"
33 #include "pipebuffer/pb_slab.h"
34
35 struct radeon_bo {
36 struct pb_buffer base;
37 union {
38 struct {
39 struct pb_cache_entry cache_entry;
40
41 void *ptr;
42 mtx_t map_mutex;
43 unsigned map_count;
44 bool use_reusable_pool;
45 } real;
46 struct {
47 struct pb_slab_entry entry;
48 struct radeon_bo *real;
49
50 unsigned num_fences;
51 unsigned max_fences;
52 struct radeon_bo **fences;
53 } slab;
54 } u;
55
56 struct radeon_drm_winsys *rws;
57 void *user_ptr; /* from buffer_from_ptr */
58
59 uint32_t handle; /* 0 for slab entries */
60 uint32_t flink_name;
61 uint64_t va;
62 uint32_t hash;
63 enum radeon_bo_domain initial_domain;
64
65 /* how many command streams is this bo referenced in? */
66 int num_cs_references;
67
68 /* how many command streams, which are being emitted in a separate
69 * thread, is this bo referenced in? */
70 int num_active_ioctls;
71 };
72
73 struct radeon_slab {
74 struct pb_slab base;
75 struct radeon_bo *buffer;
76 struct radeon_bo *entries;
77 };
78
79 void radeon_bo_destroy(void *winsys, struct pb_buffer *_buf);
80 bool radeon_bo_can_reclaim(void *winsys, struct pb_buffer *_buf);
81 void radeon_drm_bo_init_functions(struct radeon_drm_winsys *ws);
82
83 bool radeon_bo_can_reclaim_slab(void *priv, struct pb_slab_entry *entry);
84 struct pb_slab *radeon_bo_slab_alloc(void *priv, unsigned heap,
85 unsigned entry_size,
86 unsigned group_index);
87 void radeon_bo_slab_free(void *priv, struct pb_slab *slab);
88
89 static inline
radeon_ws_bo_reference(struct radeon_bo ** dst,struct radeon_bo * src)90 void radeon_ws_bo_reference(struct radeon_bo **dst, struct radeon_bo *src)
91 {
92 pb_reference((struct pb_buffer**)dst, (struct pb_buffer*)src);
93 }
94
95 void *radeon_bo_do_map(struct radeon_bo *bo);
96
97 #endif
98