summaryrefslogtreecommitdiff
path: root/amavutils/amdrmutils.c (plain)
blob: 7d3ba2b5f81dbef2e4f68110b9c66749de3fffc2
1/*
2 * Copyright (c) 2014 Amlogic, Inc. All rights reserved.
3 *
4 * This source code is subject to the terms and conditions defined in the
5 * file 'LICENSE' which is part of this source code package.
6 *
7 * Description:
8 */
9
10
11
12#define LOG_TAG "amdrmutils"
13
14#include <string.h>
15#include <stdlib.h>
16#include <fcntl.h>
17#include <errno.h>
18#include <strings.h>
19#include <cutils/log.h>
20#include <cutils/properties.h>
21#include <sys/ioctl.h>
22#include "include/Amsyswrite.h"
23#include "include/amdrmutils.h"
24
25#define TVP_ENABLE_PATH "/sys/class/codec_mm/tvp_enable"
26#define TVP_REGION_PATH "/sys/class/codec_mm/tvp_region"
27#define FREE_KEEP_BUFFER_PATH "/sys/class/video/free_keep_buffer"
28#define FREE_CMA_BUFFER_PATH "/sys/class/video/free_cma_buffer"
29#define VFM_DEF_MAP_PATH "/sys/class/vfm/map"
30#define DI_TVP_REGION_PATH "/sys/class/deinterlace/di0/tvp_region"
31#define DISABLE_VIDEO_PATH "/sys/class/video/disable_video"
32
33#ifndef LOGD
34#define LOGV ALOGV
35#define LOGD ALOGD
36#define LOGI ALOGI
37#define LOGW ALOGW
38#define LOGE ALOGE
39#endif
40
41//#define LOG_FUNCTION_NAME LOGI("%s-%d\n",__FUNCTION__,__LINE__);
42#define LOG_FUNCTION_NAME
43#define BUF_LEN 512
44#define MAX_REGION 6
45
46int set_tvp_enable(int enable)
47{
48 int fd;
49 char bcmd[16];
50 fd = open(TVP_ENABLE_PATH, O_CREAT | O_RDWR | O_TRUNC, 0644);
51 if (fd >= 0) {
52 sprintf(bcmd, "%d", enable);
53 write(fd, bcmd, strlen(bcmd));
54 close(fd);
55 return 0;
56 }
57
58 return -1;
59}
60
61int free_keep_buffer(void)
62{
63 int fd;
64 char bcmd[16];
65 fd = open(FREE_KEEP_BUFFER_PATH, O_CREAT | O_RDWR | O_TRUNC, 0644);
66 if (fd >= 0) {
67 sprintf(bcmd, "%d", 1);
68 write(fd, bcmd, strlen(bcmd));
69 close(fd);
70 return 0;
71 }
72
73 return -1;
74}
75
76int free_cma_buffer(void)
77{
78 int fd;
79 char bcmd[16];
80 fd = open(FREE_CMA_BUFFER_PATH, O_CREAT | O_RDWR | O_TRUNC, 0644);
81 if (fd >= 0) {
82 sprintf(bcmd, "%d", 1);
83 write(fd, bcmd, strlen(bcmd));
84 close(fd);
85 return 0;
86 }
87
88 return -1;
89}
90
91int set_vfmmap_ppmgr_di(int enable)
92{
93 int fd;
94 char bcmd[128];
95 fd = open(VFM_DEF_MAP_PATH, O_CREAT | O_RDWR | O_TRUNC, 0644);
96 if (fd >= 0) {
97 sprintf(bcmd, "rm default");
98 write(fd, bcmd, strlen(bcmd));
99 if (enable)
100 sprintf(bcmd, "add default decoder ppmgr deinterlace amvideo");
101 else
102 sprintf(bcmd, "add default decoder amvideo");
103 write(fd, bcmd, strlen(bcmd));
104 close(fd);
105 return 0;
106 }
107 return -1;
108}
109
110int set_disable_video(int mode)
111{
112 int fd;
113 char bcmd[16];
114 fd = open(DISABLE_VIDEO_PATH, O_CREAT | O_RDWR | O_TRUNC, 0644);
115 if (fd >= 0) {
116 sprintf(bcmd, "%d", mode);
117 write(fd, bcmd, strlen(bcmd));
118 close(fd);
119 return 0;
120 }
121
122 return -1;
123}
124
125int tvp_mm_enable(int flags)
126{
127 //flags: bit 1---4k ;
128 int is_4k= flags &TVP_MM_ENABLE_FLAGS_FOR_4K;
129 free_keep_buffer();
130 //set_vfmmap_ppmgr_di(0);
131 if (is_4k)
132 set_tvp_enable(2);
133 else
134 set_tvp_enable(1);
135 return 0;
136
137}
138
139int tvp_mm_disable(int flags)
140{
141 set_disable_video(0);
142 free_keep_buffer();
143 //set_vfmmap_ppmgr_di(1);
144 set_tvp_enable(0);
145 /*unused flags*/
146 return 0;
147}
148
149int tvp_mm_get_mem_region(struct tvp_region* region, int region_size)
150{
151 int fd, len;
152 char buf[BUF_LEN];
153 uint32_t n=0, i=0, rnum = 0, siz;
154 uint64_t start=0, end=0;
155
156 //rnum = min(region_size/sizeof(struct tvp_region), MAX_REGION);
157 rnum = region_size/sizeof(struct tvp_region);
158
159#if 0
160 fd = open(DI_TVP_REGION_PATH, O_RDONLY, 0644);
161 if (fd >=0 && rnum >= 1) {
162 len = read(fd, buf, BUF_LEN);
163 close(fd);
164 if (3 == sscanf(buf, "segment DI:%llx - %llx (size:0x%x)",
165 &start, &end, &siz)) {
166 region->start = start;
167 region->end = end;
168 region->mem_flags = 0;
169 region++;
170 ALOGE("segment DI: [%llx-%llx]\n", i, start, end);
171 }
172 }
173#endif
174
175 fd = open(TVP_REGION_PATH, O_RDONLY, 0644);
176 if (fd >= 0) {
177 len = read(fd, buf, BUF_LEN);
178 close(fd);
179 for (i=0,n=0; (n < len) && (i < rnum); i++, region++) {
180 if (4 == sscanf(buf+n, "segment%d:%llx - %llx (size:%x)",
181 &i, &start, &end, &siz))
182 {
183 ALOGE("segment %d: [%llx-%llx]\n", i, start, end);
184 region->start = start;
185 region->end = end;
186 region->mem_flags = 0;
187 n += strcspn(buf+n, "\n") + 1;
188 }
189 }
190 return i;
191 }
192 return -1;
193}
194
195
196