1 /* Copyright (c) Imagination Technologies Ltd.
2  *
3  * The contents of this file are subject to the MIT license as set out below.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the 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 THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21  * THE SOFTWARE.
22  */
23 
24 #ifndef HAL_PUBLIC_H
25 #define HAL_PUBLIC_H
26 
27 /* Authors of third party hardware composer (HWC) modules will need to include
28  * this header to access functionality in the gralloc and framebuffer HALs.
29  */
30 
31 #include <hardware/gralloc.h>
32 
33 #define ALIGN(x,a)	(((x) + (a) - 1L) & ~((a) - 1L))
34 #define HW_ALIGN	32
35 
36 /* This can be tuned down as appropriate for the SOC.
37  *
38  * IMG formats are usually a single sub-alloc.
39  * Some OEM video formats are two sub-allocs (Y, UV planes).
40  * Future OEM video formats might be three sub-allocs (Y, U, V planes).
41  */
42 #define MAX_SUB_ALLOCS 3
43 
44 typedef struct
45 {
46 	native_handle_t base;
47 
48 	/* These fields can be sent cross process. They are also valid
49 	 * to duplicate within the same process.
50 	 *
51 	 * A table is stored within psPrivateData on gralloc_module_t (this
52 	 * is obviously per-process) which maps stamps to a mapped
53 	 * PVRSRV_CLIENT_MEM_INFO in that process. Each map entry has a lock
54 	 * count associated with it, satisfying the requirements of the
55 	 * Android API. This also prevents us from leaking maps/allocations.
56 	 *
57 	 * This table has entries inserted either by alloc()
58 	 * (alloc_device_t) or map() (gralloc_module_t). Entries are removed
59 	 * by free() (alloc_device_t) and unmap() (gralloc_module_t).
60 	 *
61 	 * As a special case for framebuffer_device_t, framebuffer_open()
62 	 * will add and framebuffer_close() will remove from this table.
63 	 */
64 
65 #define IMG_NATIVE_HANDLE_NUMFDS MAX_SUB_ALLOCS
66 	/* The `fd' field is used to "export" a meminfo to another process.
67 	 * Therefore, it is allocated by alloc_device_t, and consumed by
68 	 * gralloc_module_t. The framebuffer_device_t does not need a handle,
69 	 * and the special value IMG_FRAMEBUFFER_FD is used instead.
70 	 */
71 	int fd[MAX_SUB_ALLOCS];
72 
73 #define IMG_NATIVE_HANDLE_NUMINTS ((sizeof(unsigned long long) / sizeof(int)) + 5)
74 	/* A KERNEL unique identifier for any exported kernel meminfo. Each
75 	 * exported kernel meminfo will have a unique stamp, but note that in
76 	 * userspace, several meminfos across multiple processes could have
77 	 * the same stamp. As the native_handle can be dup(2)'d, there could be
78 	 * multiple handles with the same stamp but different file descriptors.
79 	 */
80 	unsigned long long ui64Stamp;
81 
82 	/* This is used for buffer usage validation when locking a buffer,
83 	 * and also in WSEGL (for the composition bypass feature).
84 	 */
85 	int usage;
86 
87 	/* In order to do efficient cache flushes we need the buffer dimensions
88 	 * and format. These are available on the ANativeWindowBuffer,
89 	 * but the platform doesn't pass them down to the graphics HAL.
90 	 *
91 	 * These fields are also used in the composition bypass. In this
92 	 * capacity, these are the "real" values for the backing allocation.
93 	 */
94 	int iWidth;
95 	int iHeight;
96 	int iFormat;
97 	unsigned int uiBpp;
98 }
99 __attribute__((aligned(sizeof(int)),packed)) IMG_native_handle_t;
100 
101 typedef struct
102 {
103 	framebuffer_device_t base;
104 
105 	/* The HWC was loaded. post() is no longer responsible for presents */
106 	int bBypassPost;
107 
108 	/* HWC path for present posts */
109 	int (*Post2)(framebuffer_device_t *fb, buffer_handle_t *buffers,
110 				 int num_buffers, void *data, int data_length);
111 }
112 IMG_framebuffer_device_public_t;
113 
114 typedef struct IMG_gralloc_module_public_t
115 {
116 	gralloc_module_t base;
117 
118 	/* If the framebuffer has been opened, this will point to the
119 	 * framebuffer device data required by the allocator, WSEGL
120 	 * modules and composerhal.
121 	 */
122 	IMG_framebuffer_device_public_t *psFrameBufferDevice;
123 
124 	int (*GetPhyAddrs)(struct IMG_gralloc_module_public_t const* module,
125 					   buffer_handle_t handle,
126 					   unsigned int auiPhyAddr[MAX_SUB_ALLOCS]);
127 
128 	/* Custom-blit components in lieu of overlay hardware */
129 	int (*Blit)(struct IMG_gralloc_module_public_t const *module,
130 				buffer_handle_t src,
131 				void *dest[MAX_SUB_ALLOCS], int format);
132 
133 	int (*Blit2)(struct IMG_gralloc_module_public_t const *module,
134 				 buffer_handle_t src, buffer_handle_t dest,
135 				 int w, int h, int x, int y);
136 }
137 IMG_gralloc_module_public_t;
138 
139 typedef struct
140 {
141 	int l, t, w, h;
142 }
143 IMG_write_lock_rect_t;
144 
145 typedef struct IMG_buffer_format_public_t
146 {
147 	/* Buffer formats are returned as a linked list */
148 	struct IMG_buffer_format_public_t *psNext;
149 
150 	/* HAL_PIXEL_FORMAT_... enumerant */
151 	int iHalPixelFormat;
152 
153 	/* WSEGL_PIXELFORMAT_... enumerant */
154 	int iWSEGLPixelFormat;
155 
156 	/* Friendly name for format */
157 	const char *const szName;
158 
159 	/* Bits (not bytes) per pixel */
160 	unsigned int uiBpp;
161 
162 	/* GPU output format (creates EGLConfig for format) */
163 	int bGPURenderable;
164 }
165 IMG_buffer_format_public_t;
166 
167 #endif /* HAL_PUBLIC_H */
168