blob: 799fc65bcded022e3a477181eba9e42ff055224e [file] [log] [blame]
codeworkx62f02ba2012-05-20 12:00:36 +02001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 *
19 * @author Rama, Meka(v.meka@samsung.com)
20 Sangwoo, Park(sw5771.park@samsung.com)
21 Jamie, Oh (jung-min.oh@samsung.com)
22 * @date 2011-03-11
23 *
24 */
25
26#ifndef ANDROID_SEC_HWC_UTILS_H_
27#define ANDROID_SEC_HWC_UTILS_H_
28
29#include <stdlib.h>
30#include <hardware/hardware.h>
31#include <hardware/hwcomposer.h>
32
33#include <fcntl.h>
34#include <errno.h>
35#include <cutils/log.h>
36
37#include <ion.h>
38#include "s5p_fimc_v4l2.h"
39#include "sec_utils_v4l2.h"
40
41#include <linux/android_pmem.h>
42#include <sys/ioctl.h>
43#include <sys/mman.h>
44#include <hardware/gralloc.h>
45
46#include "linux/fb.h"
47
48#include "s3c_lcd.h"
49#include "s3c_mem.h"
50#include "sec_format.h"
51
52//#define HWC_DEBUG
53#if defined(BOARD_USES_FIMGAPI)
54#include "sec_g2d.h"
55//#define SUB_TITLES_HWC
56#endif
57
58#define NUM_OF_WIN (2)
59#define NUM_OF_WIN_BUF (2)
60#define NUM_OF_MEM_OBJ (1)
61
62#if (NUM_OF_WIN_BUF < 2)
63 #define ENABLE_FIMD_VSYNC
64#endif
65
66#ifdef SAMSUNG_EXYNOS5250
67#define PP_DEVICE_DEV_NAME "/dev/video29"
68#endif
69
70#define S3C_MEM_DEV_NAME "/dev/s3c-mem"
71#define PMEM_DEVICE_DEV_NAME "/dev/pmem_gpu1"
72
73#define GSC_VERSION GSC_EVT1
74//#define USE_HW_PMEM
75
76#define PMEM_SIZE (1920 * 1280 * 2)
77
78struct sec_rect {
79 int32_t x;
80 int32_t y;
81 int32_t w;
82 int32_t h;
83};
84
85struct sec_img {
86 uint32_t f_w;
87 uint32_t f_h;
88 uint32_t w;
89 uint32_t h;
90 uint32_t format;
91 uint32_t base;
92 uint32_t offset;
93 uint32_t paddr;
94 uint32_t uoffset;
95 uint32_t voffset;
96 int usage;
97 int mem_id;
98};
99
100inline int SEC_MIN(int x, int y)
101{
102 return ((x < y) ? x : y);
103}
104
105inline int SEC_MAX(int x, int y)
106{
107 return ((x > y) ? x : y);
108}
109
110struct s3c_mem_t {
111 int fd;
112 struct s3c_mem_alloc mem_alloc[NUM_OF_MEM_OBJ];
113};
114
115#ifdef USE_HW_PMEM
116typedef struct __sec_pmem_alloc {
117 int fd;
118 int total_size;
119 int offset;
120 int size;
121 unsigned int virt_addr;
122 unsigned int phys_addr;
123} sec_pmem_alloc_t;
124
125typedef struct __sec_pmem {
126 int pmem_master_fd;
127 void *pmem_master_base;
128 int pmem_total_size;
129 sec_pmem_alloc_t sec_pmem_alloc[NUM_OF_MEM_OBJ];
130} sec_pmem_t;
131
132inline size_t roundUpToPageSize(size_t x)
133{
134 return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1);
135}
136#endif
137
138struct hwc_win_info_t {
139 int fd;
140 int size;
141 sec_rect rect_info;
142 uint32_t addr[NUM_OF_WIN_BUF];
143 int buf_index;
144
145 int power_state;
146 int blending;
147 int layer_index;
148 int status;
149 int vsync;
150 int ion_fd;
151
152 struct fb_fix_screeninfo fix_info;
153 struct fb_var_screeninfo var_info;
154 struct fb_var_screeninfo lcd_info;
155};
156
157enum {
158 HWC_WIN_FREE = 0,
159 HWC_WIN_RESERVED,
160};
161
162enum {
163 HWC_UNKNOWN_MEM_TYPE = 0,
164 HWC_PHYS_MEM_TYPE,
165 HWC_VIRT_MEM_TYPE,
166};
167
168struct hwc_context_t {
169 hwc_composer_device_t device;
170
171 /* our private state goes below here */
172 struct hwc_win_info_t win[NUM_OF_WIN];
173 struct fb_var_screeninfo lcd_info;
174 s5p_fimc_t fimc;
175#ifdef SUB_TITLES_HWC
176 sec_g2d_t g2d;
177#endif
178 struct s3c_mem_t s3c_mem;
179#ifdef USE_HW_PMEM
180 sec_pmem_t sec_pmem;
181#endif
182 int num_of_fb_layer;
183 int num_of_hwc_layer;
184 int num_2d_blit_layer;
185 uint32_t layer_prev_buf[NUM_OF_WIN];
186};
187
188typedef enum _LOG_LEVEL {
189 HWC_LOG_DEBUG,
190 HWC_LOG_WARNING,
191 HWC_LOG_ERROR,
192} HWC_LOG_LEVEL;
193
194#define SEC_HWC_LOG_TAG "SECHWC_LOG"
195
196#ifdef HWC_DEBUG
197#define SEC_HWC_Log(a, ...) ((void)_SEC_HWC_Log(a, SEC_HWC_LOG_TAG, __VA_ARGS__))
198#else
199#define SEC_HWC_Log(a, ...) \
200 do { \
201 if (a == HWC_LOG_ERROR) \
202 ((void)_SEC_HWC_Log(a, SEC_HWC_LOG_TAG, __VA_ARGS__)); \
203 } while (0)
204#endif
205
206extern void _SEC_HWC_Log(HWC_LOG_LEVEL logLevel, const char *tag, const char *msg, ...);
207
208/* copied from gralloc module ..*/
209typedef struct {
210 native_handle_t base;
211
212 /* These fields can be sent cross process. They are also valid
213 * to duplicate within the same process.
214 *
215 * A table is stored within psPrivateData on gralloc_module_t (this
216 * is obviously per-process) which maps stamps to a mapped
217 * PVRSRV_CLIENT_MEM_INFO in that process. Each map entry has a lock
218 * count associated with it, satisfying the requirements of the
219 * Android API. This also prevents us from leaking maps/allocations.
220 *
221 * This table has entries inserted either by alloc()
222 * (alloc_device_t) or map() (gralloc_module_t). Entries are removed
223 * by free() (alloc_device_t) and unmap() (gralloc_module_t).
224 *
225 * As a special case for framebuffer_device_t, framebuffer_open()
226 * will add and framebuffer_close() will remove from this table.
227 */
228
229#define IMG_NATIVE_HANDLE_NUMFDS 1
230 /* The `fd' field is used to "export" a meminfo to another process.
231 * Therefore, it is allocated by alloc_device_t, and consumed by
232 * gralloc_module_t. The framebuffer_device_t does not need a handle,
233 * and the special value IMG_FRAMEBUFFER_FD is used instead.
234 */
235 int fd;
236
237#if 1
238 int format;
239 int magic;
240 int flags;
241 int size;
242 int offset;
243 int base_addr;
244#define IMG_NATIVE_HANDLE_NUMINTS ((sizeof(uint64_t) / sizeof(int)) + 4 + 6)
245#else
246#define IMG_NATIVE_HANDLE_NUMINTS ((sizeof(IMG_UINT64) / sizeof(int)) + 4)
247#endif
248 /* A KERNEL unique identifier for any exported kernel meminfo. Each
249 * exported kernel meminfo will have a unique stamp, but note that in
250 * userspace, several meminfos across multiple processes could have
251 * the same stamp. As the native_handle can be dup(2)'d, there could be
252 * multiple handles with the same stamp but different file descriptors.
253 */
254 uint64_t ui64Stamp;
255
256 /* We could live without this, but it lets us perform some additional
257 * validation on the client side. Normally, we'd have no visibility
258 * of the allocated usage, just the lock usage.
259 */
260 int usage;
261
262 /* In order to do efficient cache flushes we need the buffer dimensions
263 * and format. These are available on the android_native_buffer_t,
264 * but the platform doesn't pass them down to the graphics HAL.
265 *
266 * TODO: Ideally the platform would be modified to not require this.
267 */
268 int width;
269 int height;
270 int bpp;
271}
272__attribute__((aligned(sizeof(int)),packed)) sec_native_handle_t;
273
274int window_open (struct hwc_win_info_t *win, int id);
275int window_close (struct hwc_win_info_t *win);
276int window_set_pos (struct hwc_win_info_t *win);
277int window_get_info (struct hwc_win_info_t *win, int win_num);
278int window_pan_display(struct hwc_win_info_t *win);
279int window_show (struct hwc_win_info_t *win);
280int window_hide (struct hwc_win_info_t *win);
281int window_get_global_lcd_info(int fd, struct fb_var_screeninfo *lcd_info);
282
283int createVideoDev (s5p_fimc_t *fimc);
284int destroyVideoDev(s5p_fimc_t *fimc);
285int runFimc(struct hwc_context_t *ctx,
286 struct sec_img *src_img, struct sec_rect *src_rect,
287 struct sec_img *dst_img, struct sec_rect *dst_rect,
288 uint32_t transform);
289
290#ifdef SUB_TITLES_HWC
291int runG2d(struct hwc_context_t *ctx,
292 g2d_rect *src_rect, g2d_rect *dst_rect,
293 uint32_t transform);
294
295int destroyG2d(sec_g2d_t *g2d);
296int createG2d(sec_g2d_t *g2d);
297#endif
298
299int createMem (struct s3c_mem_t *mem, unsigned int index, unsigned int size);
300int destroyMem(struct s3c_mem_t *mem);
301int checkMem (struct s3c_mem_t *mem, unsigned int index, unsigned int size);
302
303#ifdef USE_HW_PMEM
304int createPmem (sec_pmem_t *pm, unsigned int size);
305int destroyPmem(sec_pmem_t *pm);
306int checkPmem (sec_pmem_t *pm, unsigned int index, unsigned int size);
307#endif
308
309#endif /* ANDROID_SEC_HWC_UTILS_H_*/