summaryrefslogtreecommitdiffstats
path: root/pvr-source/services4/srvkm/env/linux/sysfs.c
blob: 63066ade21220779ff67d1378d808d9cef023106 (plain)
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
/*
 * Copyright (C) 2012 Texas Instruments, Inc
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published by
 * the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <linux/kobject.h>
#include <linux/sysfs.h>
#include <linux/stat.h>
#include <asm/page.h>
#include <linux/slab.h>
#include "services_headers.h"
#include "pdump_km.h"
#include "sysfs.h"

/* sysfs structures */
struct pvrsrv_attribute {
	struct attribute attr;
	int sgx_version;
	int sgx_revision;
};

static struct pvrsrv_attribute PVRSRVAttr = {
	.attr.name = "egl.cfg",
	.attr.mode = S_IRUGO,
	.sgx_version = SGXCORE,
	.sgx_revision = SGX_CORE_REV,
};

/* sysfs read function */
static ssize_t PVRSRVEglCfgShow(struct kobject *kobj, struct attribute *attr,
								char *buffer) {
	struct pvrsrv_attribute *pvrsrv_attr;

	pvrsrv_attr = container_of(attr, struct pvrsrv_attribute, attr);
	return snprintf(buffer, PAGE_SIZE, "0 0 android\n0 1 POWERVR_SGX%d_%d",
			pvrsrv_attr->sgx_version, pvrsrv_attr->sgx_revision);
}

/* sysfs write function unsupported*/
static ssize_t PVRSRVEglCfgStore(struct kobject *kobj, struct attribute *attr,
					const char *buffer, size_t size) {
	PVR_DPF((PVR_DBG_ERROR, "PVRSRVEglCfgStore not implemented"));
	return 0;
}

static struct attribute *pvrsrv_sysfs_attrs[] = {
	&PVRSRVAttr.attr,
	NULL
};

static const struct sysfs_ops pvrsrv_sysfs_ops = {
	.show = PVRSRVEglCfgShow,
	.store = PVRSRVEglCfgStore,
};

static struct kobj_type pvrsrv_ktype = {
	.sysfs_ops = &pvrsrv_sysfs_ops,
	.default_attrs = pvrsrv_sysfs_attrs,
};

/* create sysfs entry /sys/egl/egl.cfg to determine
   which gfx libraries to load */

int PVRSRVCreateSysfsEntry(void)
{
	struct kobject *egl_cfg_kobject;
	int r;

	egl_cfg_kobject = kzalloc(sizeof(*egl_cfg_kobject), GFP_KERNEL);
	r = kobject_init_and_add(egl_cfg_kobject, &pvrsrv_ktype, NULL, "egl");

	if (r) {
		PVR_DPF((PVR_DBG_ERROR,
			"Failed to create egl.cfg sysfs entry"));
		return PVRSRV_ERROR_INIT_FAILURE;
	}

	return PVRSRV_OK;
}