1 /*
2 * Copyright (C) 2013 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 #include <errno.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <utils/Log.h>
21
22 #include <hardware/memtrack.h>
23 #include "memtrack_msm.h"
24
msm_memtrack_init(const struct memtrack_module * module)25 int msm_memtrack_init(const struct memtrack_module *module)
26 {
27 if(!module)
28 return -1;
29 return 0;
30 }
31
msm_memtrack_get_memory(const struct memtrack_module * module,pid_t pid,int type,struct memtrack_record * records,size_t * num_records)32 int msm_memtrack_get_memory(const struct memtrack_module *module,
33 pid_t pid,
34 int type,
35 struct memtrack_record *records,
36 size_t *num_records)
37 {
38 if(!module)
39 return -1;
40 if (type == MEMTRACK_TYPE_GL || type == MEMTRACK_TYPE_GRAPHICS) {
41 return kgsl_memtrack_get_memory(pid, type, records, num_records);
42 }
43
44 return -EINVAL;
45 }
46
memtrack_open(const hw_module_t * module,const char * name,hw_device_t ** device)47 static int memtrack_open(const hw_module_t* module, const char* name,
48 hw_device_t** device)
49 {
50 ALOGD("%s: enter; name=%s", __FUNCTION__, name);
51 int retval = 0; /* 0 is ok; -1 is error */
52
53 if (strcmp(name, "memtrack") == 0) {
54 struct memtrack_module *dev = (struct memtrack_module *)calloc(1,
55 sizeof(struct memtrack_module));
56
57 if (dev) {
58 /* Common hw_device_t fields */
59 dev->common.tag = HARDWARE_DEVICE_TAG;
60 dev->common.module_api_version = MEMTRACK_MODULE_API_VERSION_0_1;
61 dev->common.module_api_version = HARDWARE_HAL_API_VERSION;
62
63 dev->init = msm_memtrack_init;
64 dev->getMemory = msm_memtrack_get_memory;
65
66 *device = (hw_device_t*)dev;
67 } else
68 retval = -ENOMEM;
69 } else {
70 retval = -EINVAL;
71 }
72
73 ALOGD("%s: exit %d", __FUNCTION__, retval);
74 return retval;
75 }
76
77 static struct hw_module_methods_t memtrack_module_methods = {
78 .open = memtrack_open,
79 };
80
81 struct memtrack_module HAL_MODULE_INFO_SYM = {
82 common: {
83 tag: HARDWARE_MODULE_TAG,
84 module_api_version: MEMTRACK_MODULE_API_VERSION_0_1,
85 hal_api_version: HARDWARE_HAL_API_VERSION,
86 id: MEMTRACK_HARDWARE_MODULE_ID,
87 name: "MSM Memory Tracker HAL",
88 author: "The Android Open Source Project",
89 methods: &memtrack_module_methods,
90 },
91
92 init: msm_memtrack_init,
93 getMemory: msm_memtrack_get_memory,
94 };
95
96