SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -Werror")
INCLUDE(FindPkgConfig)
-pkg_check_modules(hal-backend-device-visionfive2_pkgs REQUIRED dlog)
+pkg_check_modules(hal-backend-device-visionfive2_pkgs REQUIRED hal-rootstrap)
+
+FOREACH(flag ${hal-backend-device-visionfive2_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
IF(ENABLE_DLOG STREQUAL on)
ADD_DEFINITIONS("-DFEATURE_DLOG")
ENDIF()
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.Apache-2.0 DESTINATION ${HAL_LICENSE_DIR}/${PROJECT_NAME})
ADD_SUBDIRECTORY(hw/display)
-ADD_SUBDIRECTORY(hw/memory)
\ No newline at end of file
+ADD_SUBDIRECTORY(hw/memory)
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
INCLUDE(FindPkgConfig)
-pkg_check_modules(hal-backend-device-display_pkgs REQUIRED dlog)
+pkg_check_modules(hal-backend-device-display_pkgs REQUIRED hal-rootstrap)
FOREACH(flag ${hal-backend-device-display_pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
#include <hal/hal-device-display-interface.h>
#include <hal/hal-common-interface.h>
-#include "hal-backend-device-visionfive2-common.h"
+#include "util.h"
static int display_get_max_brightness(int *val)
{
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+
INCLUDE(FindPkgConfig)
-pkg_check_modules(hal-backend-device-memory_pkgs REQUIRED dlog)
+pkg_check_modules(hal-backend-device-memory_pkgs REQUIRED hal-rootstrap)
FOREACH(flag ${hal-backend-device-memory_pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
#include <hal/hal-device-memory-interface.h>
#include <hal/hal-common-interface.h>
-#include "hal-backend-device-visionfive2-common.h"
+#include "util.h"
static int memory_get_gpu_info(const int pid, hal_device_memory_gpu_info_s *info)
{
+++ /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_BACKEND_DEVICE_VISIONFIVE2_COMMON_H__
-#define __HAL_BACKEND_DEVICE_VISIONFIVE2_COMMON_H__
-
-#ifdef FEATURE_DLOG
- #define LOG_TAG "HAL_BACKEND_DEVICE_VISIONFIVE2"
- #include <dlog.h>
- #define _D(fmt, args...) SLOGD(fmt, ##args)
- #define _I(fmt, args...) SLOGI(fmt, ##args)
- #define _W(fmt, args...) SLOGW(fmt, ##args)
- #define _E(fmt, args...) SLOGE(fmt, ##args)
-#else
- #define _D(x, ...)
- #define _I(x, ...)
- #define _W(x, ...)
- #define _E(x, ...)
-#endif
-
-#define EXPORT __attribute__ ((visibility("default")))
-
-#define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
-#endif /* __HAL_BACKEND_DEVICE_VISIONFIVE2_COMMON_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2024 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.
+ */
+
+#ifdef FEATURE_DLOG
+ #define LOG_TAG "HAL_BACKEND_DEVICE_VISIONFIVE2"
+ #include <dlog.h>
+ #define _D(fmt, args...) dlog_print(DLOG_DEBUG, LOG_TAG, fmt, ##args)
+ #define _I(fmt, args...) dlog_print(DLOG_INFO, LOG_TAG, fmt, ##args)
+ #define _W(fmt, args...) dlog_print(DLOG_WARN, LOG_TAG, fmt, ##args)
+ #define _E(fmt, args...) dlog_print(DLOG_ERROR, LOG_TAG, fmt, ##args)
+#else
+ #define _D(x, ...)
+ #define _I(x, ...)
+ #define _W(x, ...)
+ #define _E(x, ...)
+#endif
+
+#define EXPORT __attribute__ ((visibility("default")))
+
+#define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0]))
+#define MAX_BUF_SIZE 255
+
+int sysfs_read_int(char *path, int *val);
+int sysfs_read_str(char *path, char *str, int len);
+int sysfs_write_buf(char *path, char *buf);
+int sysfs_write_int(char *path, int val);
+int sysfs_write_str(char *path, char *str);
+
+/**
+ * @brief Parse format from /proc/cmdline
+ *
+ * @param[in] format Format string
+ * @param[out] ... Variable argument
+ *
+ * @return zero if cannot read else the number of matched and assigned items
+ */
+int parse_cmdline_scanf(const char *format, ...);
Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig
BuildRequires: cmake
-BuildRequires: pkgconfig(hal-api-common)
-BuildRequires: pkgconfig(hal-api-device)
-BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(hal-rootstrap)
%description
Device HAL backend drivers for RISC-V VisionFive2 targets
--- /dev/null
+/*
+ * Copyright (c) 2024 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 <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "util.h"
+
+static int sysfs_read_buf(char *path, char *buf, int len)
+{
+ int r, fd;
+
+ if ((!path) || (!buf) || (len < 0))
+ return -EINVAL;
+
+ fd = open(path, O_RDONLY);
+ if (fd == -1)
+ return -ENOENT;
+
+ r = read(fd, buf, len);
+ close(fd);
+
+ if ((r < 0) || (r > len))
+ return -EIO;
+
+ /* Replace '\n' with space (ascii code is 32) */
+ buf[strcspn(buf, "\n")] = (char)32;
+ buf[r] = '\0';
+
+ return 0;
+}
+
+int sysfs_write_buf(char *path, char *buf)
+{
+ int w, fd;
+
+ if ((!path) || (!buf))
+ return -EINVAL;
+
+ fd = open(path, O_WRONLY);
+ if (fd == -1)
+ return -ENOENT;
+
+ w = write(fd, buf, strlen(buf));
+ close(fd);
+
+ if (w < 0)
+ return -EIO;
+
+ return 0;
+}
+
+int sysfs_read_int(char *path, int *val)
+{
+ char buf[MAX_BUF_SIZE + 1];
+ int r;
+
+ if ((!path) || (!val))
+ return -EINVAL;
+
+ r = sysfs_read_buf(path, buf, MAX_BUF_SIZE);
+ if (r < 0)
+ return r;
+
+ *val = atoi(buf);
+ return 0;
+}
+
+int sysfs_read_str(char *path, char *str, int len)
+{
+ int r;
+
+ if ((!path) || (!str) || (len <= 0))
+ return -EINVAL;
+
+ r = sysfs_read_buf(path, str, len);
+ if (r < 0)
+ return r;
+
+ return 0;
+}
+
+int sysfs_write_int(char *path, int val)
+{
+ char buf[MAX_BUF_SIZE + 1];
+ int w;
+
+ if (!path)
+ return -EINVAL;
+
+ snprintf(buf, MAX_BUF_SIZE, "%d", val);
+ w = sysfs_write_buf(path, buf);
+ if (w < 0)
+ return w;
+
+ return 0;
+}
+
+int sysfs_write_str(char *path, char *str)
+{
+ int w;
+
+ if ((!path) || (!str))
+ return -EINVAL;
+
+ w = sysfs_write_buf(path, str);
+ if (w < 0)
+ return w;
+
+ return 0;
+}
+
+int parse_cmdline_scanf(const char *format, ...)
+{
+ FILE *fp = NULL;
+ char *token = NULL;
+ size_t len = 0;
+ va_list ap;
+ int ret = 0;
+ char buffer[MAX_BUF_SIZE + 1];
+
+ fp = fopen("/proc/cmdline", "r");
+ if (!fp)
+ return 0;
+
+ va_start(ap, format);
+
+ while (getdelim(&token, &len, ' ', fp) != EOF) {
+ if (len > MAX_BUF_SIZE)
+ len = MAX_BUF_SIZE;
+ strncpy(buffer, token, len);
+ buffer[MAX_BUF_SIZE] = '\0';
+ ret = vsscanf(buffer, format, ap);
+ memset(buffer, 0, sizeof(buffer));
+ if (ret > 0)
+ break;
+ }
+
+ free(token);
+ va_end(ap);
+ fclose(fp);
+
+ return ret;
+}
\ No newline at end of file