pass-hal: standard: Add new library for memory h/w device 48/146348/4 accepted/tizen/unified/20170913.070639 submit/tizen/20170911.052326
authorChanwoo Choi <cw00.choi@samsung.com>
Mon, 28 Aug 2017 04:53:30 +0000 (13:53 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Thu, 7 Sep 2017 04:55:09 +0000 (13:55 +0900)
This patch adds the new library (memory.so) in order to
support the memory[1] h/w device. And the struct pass_resource_memory
supports the 'fault_around_bytes'[2] feature.

The 'fault_around_bytes'[2] was supported from Linux Kernel v3.15.

[1] https://en.wikipedia.org/wiki/Computer_memory
[2] https://lkml.org/lkml/2016/4/18/612

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

index e77331a..e519c0d 100644 (file)
@@ -18,5 +18,6 @@ SET(DEST_DIR ${LIB_INSTALL_DIR}/pass)
 ADD_SUBDIRECTORY(src/cpu)
 ADD_SUBDIRECTORY(src/bus)
 ADD_SUBDIRECTORY(src/gpu)
+ADD_SUBDIRECTORY(src/memory)
 
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/scripts/pass-hal.conf DESTINATION /usr/lib/tmpfiles.d)
index 3afd2eb..c7c66f1 100644 (file)
@@ -34,3 +34,5 @@ z     /sys/devices/platform/soc/*/devfreq/*/max_freq  0660    root    system_fw       -
 t      /sys/devices/platform/soc/*/devfreq/*/max_freq  -       -       -       -       security.SMACK64="System"
 z      /sys/devices/platform/soc/*/devfreq/*/available_frequencies     0440    root    system_fw       -
 t      /sys/devices/platform/soc/*/devfreq/*/available_frequencies     -       -       -       -       security.SMACK64="System"
+z      /sys/kernel/debug/fault_around_bytes    0660    root    system_fw       -
+t      /sys/kernel/debug/fault_around_bytes    -       -       -       -       security.SMACK64="System"
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..efc0569
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * PASS (Power Aware System Service)
+ *
+ * Copyright (c) 2017 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 standard_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 standard_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 standard_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 = standard_memory_get_fault_around_bytes;
+       res->set_fault_around_bytes = standard_memory_set_fault_around_bytes;
+
+       *common = (struct pass_resource_common *)res;
+
+       return 0;
+}
+
+static int standard_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 = standard_memory_open,
+       .close = standard_memory_close,
+};