1 /**********************************************************
2 * Copyright 2009 VMware, Inc. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 **********************************************************/
27 #include "vmw_screen.h"
29 #include "vmw_buffer.h"
30 #include "vmw_fence.h"
32 #include "pipebuffer/pb_buffer.h"
33 #include "pipebuffer/pb_bufmgr.h"
36 * vmw_pools_cleanup - Destroy the buffer pools.
38 * @vws: pointer to a struct vmw_winsys_screen.
41 vmw_pools_cleanup(struct vmw_winsys_screen
*vws
)
43 if (vws
->pools
.mob_shader_slab_fenced
)
44 vws
->pools
.mob_shader_slab_fenced
->destroy
45 (vws
->pools
.mob_shader_slab_fenced
);
46 if (vws
->pools
.mob_shader_slab
)
47 vws
->pools
.mob_shader_slab
->destroy(vws
->pools
.mob_shader_slab
);
48 if (vws
->pools
.mob_fenced
)
49 vws
->pools
.mob_fenced
->destroy(vws
->pools
.mob_fenced
);
50 if (vws
->pools
.mob_cache
)
51 vws
->pools
.mob_cache
->destroy(vws
->pools
.mob_cache
);
53 if (vws
->pools
.query_fenced
)
54 vws
->pools
.query_fenced
->destroy(vws
->pools
.query_fenced
);
55 if (vws
->pools
.query_mm
)
56 vws
->pools
.query_mm
->destroy(vws
->pools
.query_mm
);
58 if(vws
->pools
.gmr_fenced
)
59 vws
->pools
.gmr_fenced
->destroy(vws
->pools
.gmr_fenced
);
60 if (vws
->pools
.gmr_mm
)
61 vws
->pools
.gmr_mm
->destroy(vws
->pools
.gmr_mm
);
62 if (vws
->pools
.gmr_slab_fenced
)
63 vws
->pools
.gmr_slab_fenced
->destroy(vws
->pools
.gmr_slab_fenced
);
64 if (vws
->pools
.gmr_slab
)
65 vws
->pools
.gmr_slab
->destroy(vws
->pools
.gmr_slab
);
68 vws
->pools
.gmr
->destroy(vws
->pools
.gmr
);
73 * vmw_query_pools_init - Create a pool of query buffers.
75 * @vws: Pointer to a struct vmw_winsys_screen.
77 * Typically this pool should be created on demand when we
78 * detect that the app will be using queries. There's nothing
79 * special with this pool other than the backing kernel buffer size,
80 * which is limited to 8192.
83 vmw_query_pools_init(struct vmw_winsys_screen
*vws
)
85 vws
->pools
.query_mm
= mm_bufmgr_create(vws
->pools
.gmr
,
88 if (!vws
->pools
.query_mm
)
91 vws
->pools
.query_fenced
= simple_fenced_bufmgr_create(
92 vws
->pools
.query_mm
, vws
->fence_ops
);
94 if(!vws
->pools
.query_fenced
)
95 goto out_no_query_fenced
;
100 vws
->pools
.query_mm
->destroy(vws
->pools
.query_mm
);
105 * vmw_mob_pool_init - Create a pool of fenced kernel buffers.
107 * @vws: Pointer to a struct vmw_winsys_screen.
109 * Typically this pool should be created on demand when we
110 * detect that the app will be using MOB buffers.
113 vmw_mob_pools_init(struct vmw_winsys_screen
*vws
)
117 vws
->pools
.mob_cache
=
118 pb_cache_manager_create(vws
->pools
.gmr
, 100000, 2,
119 VMW_BUFFER_USAGE_SHARED
);
120 if (!vws
->pools
.mob_cache
)
123 vws
->pools
.mob_fenced
=
124 simple_fenced_bufmgr_create(vws
->pools
.mob_cache
,
126 if(!vws
->pools
.mob_fenced
)
127 goto out_no_mob_fenced
;
130 desc
.usage
= ~(SVGA_BUFFER_USAGE_PINNED
| VMW_BUFFER_USAGE_SHARED
|
131 VMW_BUFFER_USAGE_SYNC
);
132 vws
->pools
.mob_shader_slab
=
133 pb_slab_range_manager_create(vws
->pools
.mob_cache
,
138 if(!vws
->pools
.mob_shader_slab
)
139 goto out_no_mob_shader_slab
;
141 vws
->pools
.mob_shader_slab_fenced
=
142 simple_fenced_bufmgr_create(vws
->pools
.mob_shader_slab
,
144 if(!vws
->pools
.mob_fenced
)
145 goto out_no_mob_shader_slab_fenced
;
149 out_no_mob_shader_slab_fenced
:
150 vws
->pools
.mob_shader_slab
->destroy(vws
->pools
.mob_shader_slab
);
151 out_no_mob_shader_slab
:
152 vws
->pools
.mob_fenced
->destroy(vws
->pools
.mob_fenced
);
154 vws
->pools
.mob_cache
->destroy(vws
->pools
.mob_cache
);
159 * vmw_pools_init - Create a pool of GMR buffers.
161 * @vws: Pointer to a struct vmw_winsys_screen.
164 vmw_pools_init(struct vmw_winsys_screen
*vws
)
168 vws
->pools
.gmr
= vmw_gmr_bufmgr_create(vws
);
172 if ((vws
->base
.have_gb_objects
&& vws
->base
.have_gb_dma
) ||
173 !vws
->base
.have_gb_objects
) {
175 * A managed pool for DMA buffers.
177 vws
->pools
.gmr_mm
= mm_bufmgr_create(vws
->pools
.gmr
,
179 12 /* 4096 alignment */);
180 if(!vws
->pools
.gmr_mm
)
183 vws
->pools
.gmr_fenced
= simple_fenced_bufmgr_create
184 (vws
->pools
.gmr_mm
, vws
->fence_ops
);
187 vws
->pools
.gmr_fenced
= pb_debug_manager_create(vws
->pools
.gmr_fenced
,
191 if(!vws
->pools
.gmr_fenced
)
195 * The slab pool allocates buffers directly from the kernel except
196 * for very small buffers which are allocated from a slab in order
197 * not to waste memory, since a kernel buffer is a minimum 4096 bytes.
199 * Here we use it only for emergency in the case our pre-allocated
200 * managed buffer pool runs out of memory.
204 desc
.usage
= ~(SVGA_BUFFER_USAGE_PINNED
| SVGA_BUFFER_USAGE_SHADER
|
205 VMW_BUFFER_USAGE_SHARED
| VMW_BUFFER_USAGE_SYNC
);
206 vws
->pools
.gmr_slab
= pb_slab_range_manager_create(vws
->pools
.gmr
,
211 if (!vws
->pools
.gmr_slab
)
214 vws
->pools
.gmr_slab_fenced
=
215 simple_fenced_bufmgr_create(vws
->pools
.gmr_slab
, vws
->fence_ops
);
217 if (!vws
->pools
.gmr_slab_fenced
)
221 vws
->pools
.query_fenced
= NULL
;
222 vws
->pools
.query_mm
= NULL
;
223 vws
->pools
.mob_cache
= NULL
;
225 if (vws
->base
.have_gb_objects
&& !vmw_mob_pools_init(vws
))
231 vmw_pools_cleanup(vws
);