--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef __HAL_MEMORY_INTERFACE_H__
+#define __HAL_MEMORY_INTERFACE_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct gpu_info {
+ int used_pages;
+};
+
+struct gem_info {
+ int rss;
+ int pss;
+};
+
+typedef struct __hal_backend_memory_funcs {
+ int (*get_gpu_info)(const int pid, struct gpu_info *info);
+ int (*get_gem_info)(const int pid, struct gem_info *info);
+} hal_backend_memory_funcs;
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __HAL_MEMORY_INTERFACE_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef __HAL_MEMORY_H__
+#define __HAL_MEMORY_H__
+
+#include <hal/hal-common.h>
+#include "hal-memory-interface.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int hal_device_memory_get_backend(void);
+int hal_device_memory_put_backend(void);
+int hal_device_memory_get_gpu_info(int pid, struct gpu_info *info);
+int hal_device_memory_get_gem_info(int pid, struct gem_info *info);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __HAL_MEMORY_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <hal/hal-common.h>
+
+#include "hal-memory-interface.h"
+#include "common.h"
+
+static hal_backend_memory_funcs *hal_memory_funcs = NULL;
+/*
+-1 : failed to initialize
+0 : not initialized
+1 : succeeded to initialize
+*/
+static int hal_initialized = 0;
+
+int hal_device_memory_get_backend(void)
+{
+ int ret;
+
+ if (hal_memory_funcs)
+ return 0;
+
+ ret = hal_common_get_backend(HAL_MODULE_DEVICE_MEMORY, (void **)&hal_memory_funcs);
+ if (ret < 0) {
+ _E("Failed to get memory backend");
+ hal_initialized = -1;
+ return -EINVAL;
+ }
+
+ hal_initialized = 1;
+ return 0;
+}
+
+int hal_device_memory_put_backend(void)
+{
+ if (!hal_memory_funcs)
+ return 0;
+
+ hal_common_put_backend(HAL_MODULE_DEVICE_MEMORY, (void *)hal_memory_funcs);
+ hal_memory_funcs = NULL;
+ hal_initialized = 0;
+
+ return 0;
+}
+
+int hal_device_memory_get_gpu_info(int pid, struct gpu_info *info)
+{
+ int ret;
+
+ if (!hal_memory_funcs && !hal_initialized) {
+ if ((ret = hal_device_memory_get_backend()) < 0)
+ return ret;
+ }
+
+ if (!hal_memory_funcs || !hal_memory_funcs->get_gpu_info)
+ return -ENODEV;
+
+ return hal_memory_funcs->get_gpu_info(pid, info);
+}
+
+int hal_device_memory_get_gem_info(int pid, struct gem_info *info)
+{
+ int ret;
+
+ if (!hal_memory_funcs && !hal_initialized) {
+ if ((ret = hal_device_memory_get_backend()) < 0)
+ return ret;
+ }
+
+ if (!hal_memory_funcs || !hal_memory_funcs->get_gem_info)
+ return -ENODEV;
+
+ return hal_memory_funcs->get_gem_info(pid, info);
+}