pass-hal: rpi: Add support of memory resource for handling fault_around_bytes 73/239673/3
authorChanwoo Choi <cw00.choi@samsung.com>
Wed, 29 Jul 2020 01:16:29 +0000 (10:16 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Wed, 29 Jul 2020 02:23:46 +0000 (11:23 +0900)
In order to handle fault_around_bytes according to the PM QoS scenario,
add code for supporting the memory h/w resource.

Change-Id: Ie7681e7528eb2eab0643f00bb5401436ff7a26bc
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
CMakeLists.txt
src/memory/CMakeLists.txt [new file with mode: 0644]
src/memory/memory.c [new file with mode: 0644]

index 8f1b264..68a02ce 100644 (file)
@@ -16,6 +16,7 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 SET(DEST_DIR ${LIB_INSTALL_DIR}/pass)
 
 ADD_SUBDIRECTORY(src/cpu)
+ADD_SUBDIRECTORY(src/memory)
 
 SET(CONF_DIR /etc/pass)
 SET(CONF_FILES
diff --git a/src/memory/CMakeLists.txt b/src/memory/CMakeLists.txt
new file mode 100644 (file)
index 0000000..e7bd0a6
--- /dev/null
@@ -0,0 +1,24 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(memory C)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED dlog glib-2.0)
+
+#HAL version
+string(REPLACE "." ";" HAL_VERSION_LIST ${HAL_VERSION})
+list(GET HAL_VERSION_LIST 0 HAL_VERSION_MAJOR)
+list(GET HAL_VERSION_LIST 1 HAL_VERSION_MINOR)
+list(GET HAL_VERSION_LIST 2 HAL_VERSION_REVISION)
+list(GET HAL_VERSION_LIST 3 HAL_VERSION_RELEASE)
+add_definitions(-DVER_MAJOR=${HAL_VERSION_MAJOR} -DVER_MINOR=${HAL_VERSION_MINOR})
+add_definitions(-DVER_REVISION=${HAL_VERSION_REVISION} -DVER_RELEASE=${HAL_VERSION_RELEASE})
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+SET(SRCS ${PROJECT_NAME}.c
+       ../shared/sysfs.c)
+
+ADD_LIBRARY(${PROJECT_NAME} MODULE ${SRCS})
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "")
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${DEST_DIR} COMPONENT RuntimeLibraries)
diff --git a/src/memory/memory.c b/src/memory/memory.c
new file mode 100644 (file)
index 0000000..54bb59a
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * PASS (Power Aware System Service)
+ *
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * 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 <errno.h>
+#include <limits.h>
+#include <pass/hal.h>
+#include <pass/hal-log.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "../shared/sysfs.h"
+
+#define FAULT_AROUND_BYTES_PATH                "/sys/kernel/debug/fault_around_bytes"
+
+static int rpi_memory_get_fault_around_bytes(char *res_name)
+{
+       int ret, fault_around_bytes;
+
+       if (!res_name)
+               return -EINVAL;
+
+       ret = sysfs_read_int(FAULT_AROUND_BYTES_PATH, &fault_around_bytes);
+       if (ret < 0)
+               return ret;
+
+       return fault_around_bytes;
+}
+
+static int rpi_memory_set_fault_around_bytes(char *res_name,
+                                               int fault_around_bytes)
+{
+       int ret;
+
+       if ((!res_name) || (fault_around_bytes <= 0))
+               return -EINVAL;
+
+       ret = sysfs_write_int(FAULT_AROUND_BYTES_PATH, fault_around_bytes);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+static int rpi_memory_open(char *res_name, struct pass_resource_info *info,
+               struct pass_resource_common **common)
+{
+       struct pass_resource_memory *res;
+
+       if (!info)
+               return -EINVAL;
+
+       res = calloc(1, sizeof(struct pass_resource_memory));
+       if (!res)
+               return -ENOMEM;
+
+       res->common.info = info;
+       res->get_fault_around_bytes = rpi_memory_get_fault_around_bytes;
+       res->set_fault_around_bytes = rpi_memory_set_fault_around_bytes;
+
+       *common = (struct pass_resource_common *)res;
+
+       return 0;
+}
+
+static int rpi_memory_close(char *res_name, struct pass_resource_common *common)
+{
+       if (!common)
+               return -EINVAL;
+
+       free(common);
+
+       return 0;
+}
+
+HAL_MODULE_STRUCTURE = {
+       .magic = HAL_INFO_TAG,
+       .id = PASS_RESOURCE_MEMORY_ID,
+       .name = PASS_RESOURCE_MEMORY_NAME,
+       .open = rpi_memory_open,
+       .close = rpi_memory_close,
+};