cbf3b3111b6eaebf478e88333495e57a5a038b51
[profile/ivi/libdrm.git] / libdrm / intel / intel_bufmgr_priv.h
1 /*
2  * Copyright © 2008 Intel Corporation
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  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * 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 NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  *
23  * Authors:
24  *    Eric Anholt <eric@anholt.net>
25  *
26  */
27
28 /**
29  * @file intel_bufmgr_priv.h
30  *
31  * Private definitions of Intel-specific bufmgr functions and structures.
32  */
33
34 #ifndef INTEL_BUFMGR_PRIV_H
35 #define INTEL_BUFMGR_PRIV_H
36
37 /**
38  * Context for a buffer manager instance.
39  *
40  * Contains public methods followed by private storage for the buffer manager.
41  */
42 struct _dri_bufmgr {
43    /**
44     * Allocate a buffer object.
45     *
46     * Buffer objects are not necessarily initially mapped into CPU virtual
47     * address space or graphics device aperture.  They must be mapped using
48     * bo_map() to be used by the CPU, and validated for use using bo_validate()
49     * to be used from the graphics device.
50     */
51    dri_bo *(*bo_alloc)(dri_bufmgr *bufmgr_ctx, const char *name,
52                        unsigned long size, unsigned int alignment);
53
54    /** Takes a reference on a buffer object */
55    void (*bo_reference)(dri_bo *bo);
56
57    /**
58     * Releases a reference on a buffer object, freeing the data if
59     * rerefences remain.
60     */
61    void (*bo_unreference)(dri_bo *bo);
62
63    /**
64     * Maps the buffer into userspace.
65     *
66     * This function will block waiting for any existing execution on the
67     * buffer to complete, first.  The resulting mapping is available at
68     * buf->virtual.
69     */
70    int (*bo_map)(dri_bo *buf, int write_enable);
71
72    /** Reduces the refcount on the userspace mapping of the buffer object. */
73    int (*bo_unmap)(dri_bo *buf);
74
75    /**
76     * Write data into an object.
77     *
78     * This is an optional function, if missing,
79     * dri_bo will map/memcpy/unmap.
80     */
81    int (*bo_subdata) (dri_bo *buf, unsigned long offset,
82                       unsigned long size, const void *data);
83
84    /**
85     * Read data from an object
86     *
87     * This is an optional function, if missing,
88     * dri_bo will map/memcpy/unmap.
89     */
90    int (*bo_get_subdata) (dri_bo *bo, unsigned long offset,
91                           unsigned long size, void *data);
92
93    /**
94     * Waits for rendering to an object by the GPU to have completed.
95     *
96     * This is not required for any access to the BO by bo_map, bo_subdata, etc.
97     * It is merely a way for the driver to implement glFinish.
98     */
99    void (*bo_wait_rendering) (dri_bo *bo);
100
101    /**
102     * Tears down the buffer manager instance.
103     */
104    void (*destroy)(dri_bufmgr *bufmgr);
105
106     /**
107      * Add relocation entry in reloc_buf, which will be updated with the
108      * target buffer's real offset on on command submission.
109      *
110      * Relocations remain in place for the lifetime of the buffer object.
111      *
112      * \param reloc_buf Buffer to write the relocation into.
113      * \param read_domains GEM read domains which the buffer will be read into
114      *        by the command that this relocation is part of.
115      * \param write_domains GEM read domains which the buffer will be dirtied
116      *        in by the command that this relocation is part of.
117      * \param delta Constant value to be added to the relocation target's
118      *         offset.
119      * \param offset Byte offset within batch_buf of the relocated pointer.
120      * \param target Buffer whose offset should be written into the relocation
121      *       entry.
122      */
123     int (*bo_emit_reloc)(dri_bo *reloc_buf,
124                          uint32_t read_domains, uint32_t write_domain,
125                          uint32_t delta, uint32_t offset, dri_bo *target);
126
127     /** Executes the command buffer pointed to by bo. */
128     int (*bo_exec)(dri_bo *bo, int used,
129                    drm_clip_rect_t *cliprects, int num_cliprects,
130                    int DR4);
131
132     /**
133      * Pin a buffer to the aperture and fix the offset until unpinned
134      *
135      * \param buf Buffer to pin
136      * \param alignment Required alignment for aperture, in bytes
137      */
138     int (*bo_pin) (dri_bo *buf, uint32_t alignment);
139     /**
140      * Unpin a buffer from the aperture, allowing it to be removed
141      *
142      * \param buf Buffer to unpin
143      */
144     int (*bo_unpin) (dri_bo *buf);
145     /**
146      * Ask that the buffer be placed in tiling mode
147      *
148      * \param buf Buffer to set tiling mode for
149      * \param tiling_mode desired, and returned tiling mode
150      */
151     int (*bo_set_tiling) (dri_bo *bo, uint32_t *tiling_mode);
152     /**
153      * Get the current tiling (and resulting swizzling) mode for the bo.
154      *
155      * \param buf Buffer to get tiling mode for
156      * \param tiling_mode returned tiling mode
157      * \param swizzle_mode returned swizzling mode
158      */
159     int (*bo_get_tiling) (dri_bo *bo, uint32_t *tiling_mode,
160                           uint32_t *swizzle_mode);
161     /**
162      * Create a visible name for a buffer which can be used by other apps
163      *
164      * \param buf Buffer to create a name for
165      * \param name Returned name
166      */
167     int (*bo_flink) (dri_bo *buf, uint32_t *name);
168
169     int (*check_aperture_space)(dri_bo **bo_array, int count);
170     int debug; /**< Enables verbose debugging printouts */
171 };
172
173 #endif /* INTEL_BUFMGR_PRIV_H */
174