intel bufmgr: reinstate buffer handle tracking
[profile/ivi/libdrm.git] / libdrm / intel / intel_bufmgr.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.h
30  *
31  * Public definitions of Intel-specific bufmgr functions.
32  */
33
34 #ifndef INTEL_BUFMGR_H
35 #define INTEL_BUFMGR_H
36
37 #include <stdint.h>
38
39 typedef struct _dri_bufmgr dri_bufmgr;
40 typedef struct _dri_bo dri_bo;
41
42 struct _dri_bo {
43     /**
44      * Size in bytes of the buffer object.
45      *
46      * The size may be larger than the size originally requested for the
47      * allocation, such as being aligned to page size.
48      */
49     unsigned long size;
50     /**
51      * Card virtual address (offset from the beginning of the aperture) for the
52      * object.  Only valid while validated.
53      */
54     unsigned long offset;
55     /**
56      * Virtual address for accessing the buffer data.  Only valid while mapped.
57      */
58     void *virtual;
59
60     /** Buffer manager context associated with this buffer object */
61     dri_bufmgr *bufmgr;
62     /**
63      * MM-specific handle for accessing object
64      */
65     int handle;
66 };
67
68 dri_bo *dri_bo_alloc(dri_bufmgr *bufmgr, const char *name, unsigned long size,
69                      unsigned int alignment);
70 void dri_bo_reference(dri_bo *bo);
71 void dri_bo_unreference(dri_bo *bo);
72 int dri_bo_map(dri_bo *buf, int write_enable);
73 int dri_bo_unmap(dri_bo *buf);
74
75 int dri_bo_subdata(dri_bo *bo, unsigned long offset,
76                    unsigned long size, const void *data);
77 int dri_bo_get_subdata(dri_bo *bo, unsigned long offset,
78                        unsigned long size, void *data);
79 void dri_bo_wait_rendering(dri_bo *bo);
80
81 void dri_bufmgr_set_debug(dri_bufmgr *bufmgr, int enable_debug);
82 void dri_bufmgr_destroy(dri_bufmgr *bufmgr);
83 int dri_bo_exec(dri_bo *bo, int used,
84                 drm_clip_rect_t *cliprects, int num_cliprects,
85                 int DR4);
86 int dri_bufmgr_check_aperture_space(dri_bo **bo_array, int count);
87
88 int dri_bo_emit_reloc(dri_bo *reloc_buf,
89                       uint32_t read_domains, uint32_t write_domain,
90                       uint32_t delta, uint32_t offset, dri_bo *target_buf);
91 int dri_bo_pin(dri_bo *buf, uint32_t alignment);
92 int dri_bo_unpin(dri_bo *buf);
93 int dri_bo_set_tiling(dri_bo *buf, uint32_t *tiling_mode);
94 int dri_bo_flink(dri_bo *buf, uint32_t *name);
95
96 /* intel_bufmgr_gem.c */
97 dri_bufmgr *intel_bufmgr_gem_init(int fd, int batch_size);
98 dri_bo *intel_bo_gem_create_from_name(dri_bufmgr *bufmgr, const char *name,
99                                       unsigned int handle);
100 void intel_bufmgr_gem_enable_reuse(dri_bufmgr *bufmgr);
101
102 /* intel_bufmgr_fake.c */
103 dri_bufmgr *intel_bufmgr_fake_init(int fd,
104                                    unsigned long low_offset, void *low_virtual,
105                                    unsigned long size,
106                                    volatile unsigned int *last_dispatch);
107 void intel_bufmgr_fake_set_last_dispatch(dri_bufmgr *bufmgr,
108                                          volatile unsigned int *last_dispatch);
109 void intel_bufmgr_fake_set_exec_callback(dri_bufmgr *bufmgr,
110                                          int (*exec)(dri_bo *bo,
111                                                      unsigned int used,
112                                                      void *priv),
113                                          void *priv);
114 void intel_bufmgr_fake_set_fence_callback(dri_bufmgr *bufmgr,
115                                           unsigned int (*emit)(void *priv),
116                                           void (*wait)(unsigned int fence,
117                                                        void *priv),
118                                           void *priv);
119 dri_bo *intel_bo_fake_alloc_static(dri_bufmgr *bufmgr, const char *name,
120                                    unsigned long offset, unsigned long size,
121                                    void *virtual);
122 void intel_bo_fake_disable_backing_store(dri_bo *bo,
123                                          void (*invalidate_cb)(dri_bo *bo,
124                                                                void *ptr),
125                                          void *ptr);
126
127 void intel_bufmgr_fake_contended_lock_take(dri_bufmgr *bufmgr);
128 void intel_bufmgr_fake_evict_all(dri_bufmgr *bufmgr);
129
130 #endif /* INTEL_BUFMGR_H */
131