hal_public.h revision c322989ae6ff6769490828de1b5eda12b749cce9
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
44typedef 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
101typedef 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	/* Custom-blit components in lieu of overlay hardware */
109	int (*Blit)(framebuffer_device_t *device, buffer_handle_t src,
110				buffer_handle_t dest, int w, int h, int x, int y);
111
112	/* HWC path for present posts */
113	int (*Post2)(framebuffer_device_t *fb, buffer_handle_t *buffers,
114				 int num_buffers, void *data, int data_length);
115}
116IMG_framebuffer_device_public_t;
117
118typedef struct IMG_gralloc_module_public_t
119{
120	gralloc_module_t base;
121
122	/* If the framebuffer has been opened, this will point to the
123	 * framebuffer device data required by the allocator, WSEGL
124	 * modules and composerhal.
125	 */
126	IMG_framebuffer_device_public_t *psFrameBufferDevice;
127
128	int (*GetPhyAddrs)(struct IMG_gralloc_module_public_t const* module,
129					   buffer_handle_t handle,
130					   unsigned int auiPhyAddr[MAX_SUB_ALLOCS]);
131}
132IMG_gralloc_module_public_t;
133
134typedef struct
135{
136	int l, t, w, h;
137}
138IMG_write_lock_rect_t;
139
140typedef struct IMG_buffer_format_public_t
141{
142	/* Buffer formats are returned as a linked list */
143	struct IMG_buffer_format_public_t *psNext;
144
145	/* HAL_PIXEL_FORMAT_... enumerant */
146	int iHalPixelFormat;
147
148	/* WSEGL_PIXELFORMAT_... enumerant */
149	int iWSEGLPixelFormat;
150
151	/* Friendly name for format */
152	const char *const szName;
153
154	/* Bits (not bytes) per pixel */
155	unsigned int uiBpp;
156
157	/* GPU output format (creates EGLConfig for format) */
158	int bGPURenderable;
159}
160IMG_buffer_format_public_t;
161
162#endif /* HAL_PUBLIC_H */
163