1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
/*
Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of The Linux Foundation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <private/android_filesystem_config.h>
#include "vendor_init.h"
#include "property_service.h"
#include "log.h"
#include "util.h"
#include "init_msm.h"
#include <sys/resource.h>
#define SOC_ID_PATH1 "/sys/devices/soc0/soc_id"
#define SOC_ID_PATH2 "/sys/devices/system/soc/soc0/id"
#define SOC_VER_PATH1 "/sys/devices/soc0/platform_version"
#define SOC_VER_PATH2 "/sys/devices/system/soc/soc0/platform_version"
#define BOARD_TYPE_PATH1 "/sys/devices/soc0/hw_platform"
#define BOARD_TYPE_PATH2 "/sys/devices/system/soc/soc0/hw_platform"
#define BUF_SIZE 64
#define STRCONV_(x) #x
#define STRCONV(x) "%" STRCONV_(x) "s"
static unsigned long msm_id;
static unsigned long msm_ver;
static char board_type[BUF_SIZE];
static char tmp[BUF_SIZE];
// sys and dev fb paths
char sys_fb_path[] = "/sys/class/graphics/";
char dev_fb_path[] = "/dev/graphics/";
#define DEV_GFX_HDMI "/dev/graphics/hdmi"
__attribute__ ((weak))
void init_msm_properties(unsigned long soc, unsigned long socrev, char *board)
{
UNUSED(soc);
UNUSED(socrev);
UNUSED(board);
}
int read_file2(const char *fname, char *data, int max_size)
{
int fd, rc;
if (max_size < 1)
return 0;
fd = open(fname, O_RDONLY);
if (fd < 0) {
ERROR("failed to open '%s'\n", fname);
return 0;
}
rc = read(fd, data, max_size - 1);
if ((rc > 0) && (rc < max_size))
data[rc] = '\0';
else
data[0] = '\0';
close(fd);
return 1;
}
/*
* setPerms: sets the permission to the file node
* @path: file node
* @mode: permissions to be set(0664)
*/
void setPerms(char *path, uint32_t mode)
{
// set the permission if the file exists
int fd = open(path, O_RDONLY | O_NOFOLLOW);
if (fd >= 0) {
if (fchmod(fd, mode) < 0)
ERROR("chmod failed for %s: errno = %d", path, errno);
close(fd);
}
}
/*
* setOwners: sets the owner and group for a file node
* @path: file node
* @owner: AID for owner
* @group: AID for group
*/
void setOwners(char *path, int owner, int group)
{
// set the permissinn if the file exists
int fd = open(path, O_RDONLY | O_NOFOLLOW);
if (fd >= 0) {
if (fchown(fd, owner, group) < 0)
ERROR(" chown failed for %s: errno = %d", path, errno);
close(fd);
}
}
/*
* Setup Display related nodes & permissions. For HDMI, it can be fb1 or fb2
* Loop through the sysfs nodes and determine the HDMI(dtv panel)
*/
void set_display_node_perms()
{
char panel_type[] = "dtv panel";
char buf[BUF_SIZE];
int num;
for (num=0; num<=2; num++) {
snprintf(tmp,sizeof(tmp),"%sfb%d/msm_fb_type", sys_fb_path, num);
if(read_file2(tmp, buf, sizeof(buf))) {
if(!strncmp(buf, panel_type, strlen(panel_type))) {
// Set appropriate permissions for the nodes
snprintf(tmp, sizeof(tmp), "%sfb%d/hpd", sys_fb_path, num);
setPerms(tmp, 0664);
setOwners(tmp, AID_SYSTEM, AID_GRAPHICS);
snprintf(tmp, sizeof(tmp), "%sfb%d/res_info", sys_fb_path, num);
setPerms(tmp, 0664);
setOwners(tmp, AID_SYSTEM, AID_GRAPHICS);
snprintf(tmp, sizeof(tmp), "%sfb%d/vendor_name", sys_fb_path,
num);
setPerms(tmp, 0664);
setOwners(tmp, AID_SYSTEM, AID_GRAPHICS);
snprintf(tmp, sizeof(tmp), "%sfb%d/product_description",
sys_fb_path, num);
setPerms(tmp, 0664);
setOwners(tmp, AID_SYSTEM, AID_GRAPHICS);
snprintf(tmp, sizeof(tmp), "%sfb%d/video_mode",
sys_fb_path, num);
setPerms(tmp, 0664);
snprintf(tmp, sizeof(tmp), "%sfb%d/format_3d", sys_fb_path,
num);
setPerms(tmp, 0664);
setOwners(tmp, AID_SYSTEM, AID_SYSTEM);
snprintf(tmp, sizeof(tmp), "%sfb%d/s3d_mode", sys_fb_path,
num);
setPerms(tmp, 0664);
setOwners(tmp, AID_SYSTEM, AID_SYSTEM);
snprintf(tmp, sizeof(tmp), "%sfb%d/hdcp/tp", sys_fb_path, num);
setPerms(tmp, 0664);
setOwners(tmp, AID_SYSTEM, AID_SYSTEM);
snprintf(tmp, sizeof(tmp), "%sfb%d/cec/enable", sys_fb_path, num);
setPerms(tmp, 0664);
setOwners(tmp, AID_SYSTEM, AID_SYSTEM);
snprintf(tmp, sizeof(tmp), "%sfb%d/cec/logical_addr", sys_fb_path, num);
setPerms(tmp, 0664);
setOwners(tmp, AID_SYSTEM, AID_SYSTEM);
snprintf(tmp, sizeof(tmp), "%sfb%d/cec/rd_msg", sys_fb_path, num);
setPerms(tmp, 0664);
setOwners(tmp, AID_SYSTEM, AID_SYSTEM);
snprintf(tmp, sizeof(tmp), "%sfb%d/pa", sys_fb_path, num);
setPerms(tmp, 0664);
setOwners(tmp, AID_SYSTEM, AID_SYSTEM);
snprintf(tmp, sizeof(tmp), "%sfb%d/cec/wr_msg", sys_fb_path, num);
setPerms(tmp, 0600);
setOwners(tmp, AID_SYSTEM, AID_SYSTEM);
snprintf(tmp, sizeof(tmp), "%sfb%d", dev_fb_path, num);
symlink(tmp, DEV_GFX_HDMI);
break;
}
}
}
// Set the permission for idle_time.
snprintf(tmp, sizeof(tmp), "%sfb0/idle_time", sys_fb_path);
setPerms(tmp, 0664);
setOwners(tmp, AID_SYSTEM, AID_GRAPHICS);
// Set the permission for mdp/bw_mode_bitmap.
snprintf(tmp, sizeof(tmp), "%sfb0/mdp/bw_mode_bitmap", sys_fb_path);
setPerms(tmp, 0664);
setOwners(tmp, AID_SYSTEM, AID_GRAPHICS);
// Set write permission for dynamic_fps node.
snprintf(tmp, sizeof(tmp), "%sfb0/dynamic_fps", sys_fb_path);
setPerms(tmp, 0664);
setOwners(tmp, AID_SYSTEM, AID_GRAPHICS);
// Set permissions for dynamic partial update
snprintf(tmp, sizeof(tmp), "%sfb0/dyn_pu", sys_fb_path);
setPerms(tmp, 0664);
setOwners(tmp, AID_SYSTEM, AID_GRAPHICS);
snprintf(tmp, sizeof(tmp), "%sfb0/modes", sys_fb_path);
setPerms(tmp, 0664);
setOwners(tmp, AID_SYSTEM, AID_GRAPHICS);
snprintf(tmp, sizeof(tmp), "%sfb0/mode", sys_fb_path);
setPerms(tmp, 0664);
setOwners(tmp, AID_SYSTEM, AID_GRAPHICS);
}
void vendor_load_properties()
{
int rc;
/* Collect MSM info */
rc = read_file2(SOC_ID_PATH1, tmp, sizeof(tmp));
if (!rc) {
rc = read_file2(SOC_ID_PATH2, tmp, sizeof(tmp));
}
if (rc) {
msm_id = strtoul(tmp, NULL, 0);
}
rc = read_file2(SOC_VER_PATH1, tmp, sizeof(tmp));
if (!rc) {
rc = read_file2(SOC_VER_PATH2, tmp, sizeof(tmp));
}
if (rc) {
msm_ver = strtoul(tmp, NULL, 0);
}
rc = read_file2(BOARD_TYPE_PATH1, tmp, sizeof(tmp));
if (!rc) {
rc = read_file2(BOARD_TYPE_PATH2, tmp, sizeof(tmp));
}
if (rc) {
sscanf(tmp, STRCONV(BUF_SIZE), board_type);
}
if (!msm_id) {
/* abort */
ERROR("MSM SOC detection failed, skipping MSM initialization\n");
return;
}
ERROR("Detected MSM SOC ID=%lu SOC VER=%lu BOARD TYPE=%s\n",
msm_id, msm_ver, board_type);
/* Define MSM family properties */
init_msm_properties(msm_id, msm_ver, board_type);
/* Set Display Node Permissions */
set_display_node_perms();
}
|