1 /**************************************************************************
3 * Copyright © 2007 Intel Corporation
4 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
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 COPYRIGHT HOLDERS, AUTHORS AND/OR ITS 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.
23 * The above copyright notice and this permission notice (including the
24 * next paragraph) shall be included in all copies or substantial portions
28 **************************************************************************/
30 * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
31 * Keith Whitwell <keithw-at-tungstengraphics-dot-com>
32 * Eric Anholt <eric@anholt.net>
35 #ifndef _DRI_BUFMGR_H_
36 #define _DRI_BUFMGR_H_
39 typedef struct _dri_bufmgr dri_bufmgr;
40 typedef struct _dri_bo dri_bo;
44 * Size in bytes of the buffer object.
46 * The size may be larger than the size originally requested for the
47 * allocation, such as being aligned to page size.
51 * Card virtual address (offset from the beginning of the aperture) for the
52 * object. Only valid while validated.
56 * Virtual address for accessing the buffer data. Only valid while mapped.
59 /** Buffer manager context associated with this buffer object */
64 * Context for a buffer manager instance.
66 * Contains public methods followed by private storage for the buffer manager.
70 * Allocate a buffer object.
72 * Buffer objects are not necessarily initially mapped into CPU virtual
73 * address space or graphics device aperture. They must be mapped using
74 * bo_map() to be used by the CPU, and validated for use using bo_validate()
75 * to be used from the graphics device.
77 dri_bo *(*bo_alloc)(dri_bufmgr *bufmgr_ctx, const char *name,
78 unsigned long size, unsigned int alignment);
80 /** Takes a reference on a buffer object */
81 void (*bo_reference)(dri_bo *bo);
84 * Releases a reference on a buffer object, freeing the data if
87 void (*bo_unreference)(dri_bo *bo);
90 * Maps the buffer into userspace.
92 * This function will block waiting for any existing execution on the
93 * buffer to complete, first. The resulting mapping is available at
96 int (*bo_map)(dri_bo *buf, int write_enable);
98 /** Reduces the refcount on the userspace mapping of the buffer object. */
99 int (*bo_unmap)(dri_bo *buf);
102 * Write data into an object.
104 * This is an optional function, if missing,
105 * dri_bo will map/memcpy/unmap.
107 int (*bo_subdata) (dri_bo *buf, unsigned long offset,
108 unsigned long size, const void *data);
111 * Read data from an object
113 * This is an optional function, if missing,
114 * dri_bo will map/memcpy/unmap.
116 int (*bo_get_subdata) (dri_bo *bo, unsigned long offset,
117 unsigned long size, void *data);
120 * Waits for rendering to an object by the GPU to have completed.
122 * This is not required for any access to the BO by bo_map, bo_subdata, etc.
123 * It is merely a way for the driver to implement glFinish.
125 void (*bo_wait_rendering) (dri_bo *bo);
128 * Tears down the buffer manager instance.
130 void (*destroy)(dri_bufmgr *bufmgr);
133 * Processes the relocations, either in userland or by converting the list
134 * for use in batchbuffer submission.
136 * Kernel-based implementations will return a pointer to the arguments
137 * to be handed with batchbuffer submission to the kernel. The userland
138 * implementation performs the buffer validation and emits relocations
139 * into them the appopriate order.
141 * \param batch_buf buffer at the root of the tree of relocations
142 * \return argument to be completed and passed to the execbuffers ioctl
145 void *(*process_relocs)(dri_bo *batch_buf);
147 void (*post_submit)(dri_bo *batch_buf);
149 int (*check_aperture_space)(dri_bo *bo);
150 int debug; /**< Enables verbose debugging printouts */
153 dri_bo *dri_bo_alloc(dri_bufmgr *bufmgr, const char *name, unsigned long size,
154 unsigned int alignment);
155 void dri_bo_reference(dri_bo *bo);
156 void dri_bo_unreference(dri_bo *bo);
157 int dri_bo_map(dri_bo *buf, int write_enable);
158 int dri_bo_unmap(dri_bo *buf);
160 int dri_bo_subdata(dri_bo *bo, unsigned long offset,
161 unsigned long size, const void *data);
162 int dri_bo_get_subdata(dri_bo *bo, unsigned long offset,
163 unsigned long size, void *data);
164 void dri_bo_wait_rendering(dri_bo *bo);
166 void dri_bufmgr_set_debug(dri_bufmgr *bufmgr, int enable_debug);
167 void dri_bufmgr_destroy(dri_bufmgr *bufmgr);
169 void *dri_process_relocs(dri_bo *batch_buf);
170 void dri_post_process_relocs(dri_bo *batch_buf);
171 void dri_post_submit(dri_bo *batch_buf);
172 int dri_bufmgr_check_aperture_space(dri_bo *bo);