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