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