blob: 005b694ee4b9a51ddd9577ac55acde964130c4ae [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#ifdef BOARD_USE_V4L2_ION
38#include <ion.h>
39#include "s5p_fimc_v4l2.h"
40#include "sec_utils_v4l2.h"
41#else
42#include <linux/videodev.h>
43#include "s5p_fimc.h"
44#include "sec_utils.h"
45#endif
46
47#include <linux/android_pmem.h>
48#include <sys/ioctl.h>
49#include <sys/mman.h>
50#include <hardware/gralloc.h>
51
52#include "linux/fb.h"
53
54#include "s3c_lcd.h"
55#include "s3c_mem.h"
56#include "sec_format.h"
57
58//#define HWC_DEBUG
59#if defined(BOARD_USES_FIMGAPI)
60#include "sec_g2d.h"
61//#define SUB_TITLES_HWC
62#endif
63
64#define NUM_OF_WIN (2)
65#define NUM_OF_WIN_BUF (2)
66#define NUM_OF_MEM_OBJ (1)
67
68#if (NUM_OF_WIN_BUF < 2)
69 #define ENABLE_FIMD_VSYNC
70#endif
71
72#define MAX_RESIZING_RATIO_LIMIT (63)
73
74#ifdef SAMSUNG_EXYNOS4x12
75#ifdef BOARD_USE_V4L2_ION
76#define PP_DEVICE_DEV_NAME "/dev/video4"
77#else
78#define PP_DEVICE_DEV_NAME "/dev/video3"
79#endif
80#endif
81
82#ifdef SAMSUNG_EXYNOS4210
83#define PP_DEVICE_DEV_NAME "/dev/video1"
84#endif
85
86#define S3C_MEM_DEV_NAME "/dev/s3c-mem"
87#define PMEM_DEVICE_DEV_NAME "/dev/pmem_gpu1"
88
89#ifdef BOARD_USE_V4L2_ION
90#undef USE_HW_PMEM
91#else
92#define USE_HW_PMEM
93#endif
94
95#define PMEM_SIZE (1920 * 1280 * 2)
96
97struct sec_rect {
98 int32_t x;
99 int32_t y;
100 int32_t w;
101 int32_t h;
102};
103
104struct sec_img {
105 uint32_t f_w;
106 uint32_t f_h;
107 uint32_t w;
108 uint32_t h;
109 uint32_t format;
110 uint32_t base;
111 uint32_t offset;
112 uint32_t paddr;
113 uint32_t uoffset;
114 uint32_t voffset;
115 int usage;
116 int mem_id;
117 int mem_type;
118};
119
120inline int SEC_MIN(int x, int y)
121{
122 return ((x < y) ? x : y);
123}
124
125inline int SEC_MAX(int x, int y)
126{
127 return ((x > y) ? x : y);
128}
129
130struct s3c_mem_t {
131 int fd;
132 struct s3c_mem_alloc mem_alloc[NUM_OF_MEM_OBJ];
133};
134
135#ifdef USE_HW_PMEM
136typedef struct __sec_pmem_alloc {
137 int fd;
138 int total_size;
139 int offset;
140 int size;
141 unsigned int virt_addr;
142 unsigned int phys_addr;
143} sec_pmem_alloc_t;
144
145typedef struct __sec_pmem {
146 int pmem_master_fd;
147 void *pmem_master_base;
148 int pmem_total_size;
149 sec_pmem_alloc_t sec_pmem_alloc[NUM_OF_MEM_OBJ];
150} sec_pmem_t;
151
152inline size_t roundUpToPageSize(size_t x)
153{
154 return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1);
155}
156#endif
157
158struct hwc_win_info_t {
159 int fd;
160 int size;
161 sec_rect rect_info;
162 uint32_t addr[NUM_OF_WIN_BUF];
163 int buf_index;
164
165 int power_state;
166 int blending;
167 int layer_index;
168 int status;
169 int vsync;
170#ifdef BOARD_USE_V4L2_ION
171 int ion_fd;
172#endif
173
174 struct fb_fix_screeninfo fix_info;
175 struct fb_var_screeninfo var_info;
176 struct fb_var_screeninfo lcd_info;
177};
178
179enum {
180 HWC_WIN_FREE = 0,
181 HWC_WIN_RESERVED,
182};
183
184enum {
185 HWC_UNKNOWN_MEM_TYPE = 0,
186 HWC_PHYS_MEM_TYPE,
187 HWC_VIRT_MEM_TYPE,
188};
189
190struct hwc_context_t {
191 hwc_composer_device_t device;
192
193 /* our private state goes below here */
194 struct hwc_win_info_t win[NUM_OF_WIN];
195 struct fb_var_screeninfo lcd_info;
196 s5p_fimc_t fimc;
197#ifdef SUB_TITLES_HWC
198 sec_g2d_t g2d;
199#endif
200 struct s3c_mem_t s3c_mem;
201#ifdef USE_HW_PMEM
202 sec_pmem_t sec_pmem;
203#endif
204 int num_of_fb_layer;
205 int num_of_hwc_layer;
206 int num_2d_blit_layer;
207 uint32_t layer_prev_buf[NUM_OF_WIN];
208};
209
210typedef enum _LOG_LEVEL {
211 HWC_LOG_DEBUG,
212 HWC_LOG_WARNING,
213 HWC_LOG_ERROR,
214} HWC_LOG_LEVEL;
215
216#define SEC_HWC_LOG_TAG "SECHWC_LOG"
217
218#ifdef HWC_DEBUG
219#define SEC_HWC_Log(a, ...) ((void)_SEC_HWC_Log(a, SEC_HWC_LOG_TAG, __VA_ARGS__))
220#else
221#define SEC_HWC_Log(a, ...) \
222 do { \
223 if (a == HWC_LOG_ERROR) \
224 ((void)_SEC_HWC_Log(a, SEC_HWC_LOG_TAG, __VA_ARGS__)); \
225 } while (0)
226#endif
227
228extern void _SEC_HWC_Log(HWC_LOG_LEVEL logLevel, const char *tag, const char *msg, ...);
229
230/* copied from gralloc module ..*/
231typedef struct {
232 native_handle_t base;
233
234 /* These fields can be sent cross process. They are also valid
235 * to duplicate within the same process.
236 *
237 * A table is stored within psPrivateData on gralloc_module_t (this
238 * is obviously per-process) which maps stamps to a mapped
239 * PVRSRV_CLIENT_MEM_INFO in that process. Each map entry has a lock
240 * count associated with it, satisfying the requirements of the
241 * Android API. This also prevents us from leaking maps/allocations.
242 *
243 * This table has entries inserted either by alloc()
244 * (alloc_device_t) or map() (gralloc_module_t). Entries are removed
245 * by free() (alloc_device_t) and unmap() (gralloc_module_t).
246 *
247 * As a special case for framebuffer_device_t, framebuffer_open()
248 * will add and framebuffer_close() will remove from this table.
249 */
250
251#define IMG_NATIVE_HANDLE_NUMFDS 1
252 /* The `fd' field is used to "export" a meminfo to another process.
253 * Therefore, it is allocated by alloc_device_t, and consumed by
254 * gralloc_module_t. The framebuffer_device_t does not need a handle,
255 * and the special value IMG_FRAMEBUFFER_FD is used instead.
256 */
257 int fd;
258
259#if 1
260 int format;
261 int magic;
262 int flags;
263 int size;
264 int offset;
265 int base_addr;
266#define IMG_NATIVE_HANDLE_NUMINTS ((sizeof(uint64_t) / sizeof(int)) + 4 + 6)
267#else
268#define IMG_NATIVE_HANDLE_NUMINTS ((sizeof(IMG_UINT64) / sizeof(int)) + 4)
269#endif
270 /* A KERNEL unique identifier for any exported kernel meminfo. Each
271 * exported kernel meminfo will have a unique stamp, but note that in
272 * userspace, several meminfos across multiple processes could have
273 * the same stamp. As the native_handle can be dup(2)'d, there could be
274 * multiple handles with the same stamp but different file descriptors.
275 */
276 uint64_t ui64Stamp;
277
278 /* We could live without this, but it lets us perform some additional
279 * validation on the client side. Normally, we'd have no visibility
280 * of the allocated usage, just the lock usage.
281 */
282 int usage;
283
284 /* In order to do efficient cache flushes we need the buffer dimensions
285 * and format. These are available on the android_native_buffer_t,
286 * but the platform doesn't pass them down to the graphics HAL.
287 *
288 * TODO: Ideally the platform would be modified to not require this.
289 */
290 int width;
291 int height;
292 int bpp;
293}
294__attribute__((aligned(sizeof(int)),packed)) sec_native_handle_t;
295
296int window_open (struct hwc_win_info_t *win, int id);
297int window_close (struct hwc_win_info_t *win);
298int window_set_pos (struct hwc_win_info_t *win);
299int window_get_info (struct hwc_win_info_t *win, int win_num);
300int window_pan_display(struct hwc_win_info_t *win);
301int window_show (struct hwc_win_info_t *win);
302int window_hide (struct hwc_win_info_t *win);
303int window_get_global_lcd_info(int fd, struct fb_var_screeninfo *lcd_info);
304
305int createFimc (s5p_fimc_t *fimc);
306int destroyFimc(s5p_fimc_t *fimc);
307int runFimc(struct hwc_context_t *ctx,
308 struct sec_img *src_img, struct sec_rect *src_rect,
309 struct sec_img *dst_img, struct sec_rect *dst_rect,
310 uint32_t transform);
311
312#ifdef SUB_TITLES_HWC
313int runG2d(struct hwc_context_t *ctx,
314 g2d_rect *src_rect, g2d_rect *dst_rect,
315 uint32_t transform);
316
317int destroyG2d(sec_g2d_t *g2d);
318int createG2d(sec_g2d_t *g2d);
319#endif
320
321int createMem (struct s3c_mem_t *mem, unsigned int index, unsigned int size);
322int destroyMem(struct s3c_mem_t *mem);
323int checkMem (struct s3c_mem_t *mem, unsigned int index, unsigned int size);
324
325#ifdef USE_HW_PMEM
326int createPmem (sec_pmem_t *pm, unsigned int size);
327int destroyPmem(sec_pmem_t *pm);
328int checkPmem (sec_pmem_t *pm, unsigned int index, unsigned int size);
329#endif
330
331#endif /* ANDROID_SEC_HWC_UTILS_H_*/