From: Heesub Shin Date: Sat, 6 May 2017 08:58:00 +0000 (+0900) Subject: arch: add missing boardctl() X-Git-Tag: 1.1_Public_Release~597^2~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6778f3029849f7ad089323966d0485cdb20ba78b;p=rtos%2Ftinyara.git arch: add missing boardctl() In TizenRT, boardctl() is missing. Without it, there is no way to support shutdown, reboot, or any other board-specific control. So, this commit copies boardctl.c, IOCTL definitions and several Kconfig entries from NuttX, which were deleted in TizenRT. Change-Id: I8cbd27faa6cbfc12b65d6cba7f9c57237c81853f Signed-off-by: Heesub Shin --- diff --git a/os/arch/Kconfig.board b/os/arch/Kconfig.board index 9fa4d88..a4cc5f1 100644 --- a/os/arch/Kconfig.board +++ b/os/arch/Kconfig.board @@ -81,6 +81,51 @@ config BOARD_CRASHDUMP "machine state" in a place where on the next reset can write it to more sophisticated storage in a sane operating environment. +config LIB_BOARDCTL + bool "Enable boardctl() interface" + default n + ---help--- + Enables support for the boardctl() interface. Architecture + specific logic must provide board_app_initialize() interface. + +if LIB_BOARDCTL + +config BOARDCTL_POWEROFF + bool "Enable power off interfaces" + default n + depends on ARCH_HAVE_POWEROFF + ---help--- + Enables support for the BOARDIOC_POWEROFF boardctl() command. + Architecture specific logic must provide the board_power_off() + interface. + +config BOARDCTL_RESET + bool "Enable reset interfaces" + default n + depends on ARCH_HAVE_RESET + ---help--- + Enables support for the BOARDIOC_RESET boardctl() command. + Architecture specific logic must provide the board_reset() + interface. + +config BOARDCTL_UNIQUEID + bool "Return board unique ID" + default n + ---help--- + Enables support for the BOARDIOC_UNIQUEID boardctl() command. + Architecture specific logic must provide the board_uniqueid() + interface. + +config BOARDCTL_UNIQUEID_SIZE + int "Size of the board unique ID (bytes)" + default 16 + depends on BOARDCTL_UNIQUEID + ---help--- + Provides the size of the memory buffer that must be provided by the + caller of board_uniqueid() in which to receive the board unique ID. + +endif # LIB_BOARDCTL + config BOARD_COREDUMP_FLASH bool "Enable crashlog dump to flash" default n diff --git a/os/arch/boardctl.c b/os/arch/boardctl.c new file mode 100644 index 0000000..0928435 --- /dev/null +++ b/os/arch/boardctl.c @@ -0,0 +1,178 @@ +/**************************************************************************** + * + * Copyright 2017 Samsung Electronics 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. + * + ****************************************************************************/ +/**************************************************************************** + * configs/boardctl.c + * + * Copyright (C) 2015-2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ +#include + +#include +#include +#include +#include +#include + +#include + +#ifdef CONFIG_LIB_BOARDCTL +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: boardctl + * + * Description: + * In a small embedded system, there will typically be a much greater + * interaction between application and low-level board features. The + * canonically correct to implement such interactions is by implementing a + * character driver and performing the interactions via low level ioctl + * calls. This, however, may not be practical in many cases and will lead + * to "correct" but awkward implementations. + * + * boardctl() is non-standard OS interface to alleviate the problem. It + * basically circumvents the normal device driver ioctl interlace and allows + * the application to perform direction IOCTL-like calls to the board-specific + * logic. In it is especially useful for setting up board operational and + * test configurations. + * + * Input Parameters: + * cmd - Identifies the board command to be executed + * arg - The argument that accompanies the command. The nature of the + * argument is determined by the specific command. + * + * Returned Value: + * On success zero (OK) is returned; -1 (ERROR) is returned on failure + * with the errno variable to to indicate the nature of the failure. + * + ****************************************************************************/ +int boardctl(unsigned int cmd, uintptr_t arg) +{ + int ret; + + switch (cmd) { + /* + * CMD: BOARDIOC_INIT + * DESCRIPTION: Perform one-time application initialization. + * ARG: The boardctl() argument is passed to the + * board_app_initialize() implementation without modification. + * The argument has no meaning to NuttX; the meaning of the + * argument is a contract between the board-specific + * initalization logic and the the matching application logic. + * The value cold be such things as a mode enumeration value, + * a set of DIP switch switch settings, a pointer to + * configuration data read from a file or serial FLASH, or + * whatever you would like to do with it. Every + * implementation should accept zero/NULL as a default + * configuration. + * CONFIGURATION: CONFIG_LIB_BOARDCTL + * DEPENDENCIES: Board logic must provide board_app_initialization + */ + case BOARDIOC_INIT: + ret = board_app_initialize(); + break; + +#ifdef CONFIG_BOARDCTL_POWEROFF + /* + * CMD: BOARDIOC_POWEROFF + * DESCRIPTION: Power off the board + * ARG: Integer value providing power off status information + * CONFIGURATION: CONFIG_BOARDCTL_POWEROFF + * DEPENDENCIES: Board logic must provide board_power_off + */ + case BOARDIOC_POWEROFF: + ret = board_power_off((int)arg); + break; +#endif + +#ifdef CONFIG_BOARDCTL_RESET + /* + * CMD: BOARDIOC_RESET + * DESCRIPTION: Reset the board + * ARG: Integer value providing power off status information + * CONFIGURATION: CONFIG_BOARDCTL_RESET + * DEPENDENCIES: Board logic must provide board_reset + */ + case BOARDIOC_RESET: + ret = board_reset((int)arg); + break; +#endif + +#ifdef CONFIG_BOARDCTL_UNIQUEID + /* + * CMD: BOARDIOC_UNIQUEID + * DESCRIPTION: Return a unique ID associated with the board (such + * as a serial number or a MAC address). + * ARG: A writable array of size CONFIG_BOARDCTL_UNIQUEID_SIZE + * in which to receive the board unique ID. + * DEPENDENCIES: Board logic must provide the board_uniqueid() + * interface. + */ + case BOARDIOC_UNIQUEID: + ret = board_uniqueid((FAR uint8_t *)arg); + break; +#endif + + default: + ret = -ENOTTY; + break; + } + + /* Set the errno value on any errors */ + if (ret < 0) { + set_errno(-ret); + return ERROR; + } + + return OK; +} +#endif /* CONFIG_LIB_BOARDCTL */ diff --git a/os/include/sys/boardctl.h b/os/include/sys/boardctl.h new file mode 100644 index 0000000..4d14ee9 --- /dev/null +++ b/os/include/sys/boardctl.h @@ -0,0 +1,173 @@ +/**************************************************************************** + * + * Copyright 2017 Samsung Electronics 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/sys/boardctl.h + * + * Copyright (C) 2015-2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __INCLUDE_SYS_BOARDCTL_H +#define __INCLUDE_SYS_BOARDCTL_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ +#include +#include + +#include + +#ifdef CONFIG_LIB_BOARDCTL + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Common commands + * + * CMD: BOARDIOC_INIT + * DESCRIPTION: Perform one-time application initialization. + * ARG: The boardctl() argument is passed to the + * board_app_initialize() implementation without modification. + * The argument has no meaning to NuttX; the meaning of the + * argument is a contract between the board-specific + * initalization logic and the the matching application logic. + * The value cold be such things as a mode enumeration value, + * a set of DIP switch switch settings, a pointer to + * configuration data read from a file or serial FLASH, or + * whatever you would like to do with it. Every + * implementation should accept zero/NULL as a default + * configuration. + * CONFIGURATION: CONFIG_LIB_BOARDCTL + * DEPENDENCIES: Board logic must provide board_app_initialize() + * + * CMD: BOARDIOC_POWEROFF + * DESCRIPTION: Power off the board + * ARG: Integer value providing power off status information + * CONFIGURATION: CONFIG_BOARDCTL_POWEROFF + * DEPENDENCIES: Board logic must provide the board_power_off() interface. + * + * CMD: BOARDIOC_RESET + * DESCRIPTION: Reset the board + * ARG: Integer value providing power off status information + * CONFIGURATION: CONFIG_BOARDCTL_RESET + * DEPENDENCIES: Board logic must provide the board_reset() interface. + * + * CMD: BOARDIOC_UNIQUEID + * DESCRIPTION: Return a unique ID associated with the board (such as a + * serial number or a MAC address). + * ARG: A writable array of size CONFIG_BOARDCTL_UNIQUEID_SIZE in + * which to receive the board unique ID. + * DEPENDENCIES: Board logic must provide the board_uniqueid() interface. + */ + +#define BOARDIOC_INIT _BOARDIOC(0x0001) +#define BOARDIOC_POWEROFF _BOARDIOC(0x0002) +#define BOARDIOC_RESET _BOARDIOC(0x0003) +#define BOARDIOC_UNIQUEID _BOARDIOC(0x0004) + +/* If CONFIG_BOARDCTL_IOCTL=y, then boad-specific commands will be support. + * In this case, all commands not recognized by boardctl() will be forwarded + * to the board-provided board_ioctl() function. + * + * User defined board commands may begin with this value: + */ + +#define BOARDIOC_USER _BOARDIOC(0x000d) + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: boardctl + * + * Description: + * In a small embedded system, there will typically be a much greater + * interaction between application and low-level board features. The + * canonically correct to implement such interactions is by implementing a + * character driver and performing the interactions via low level ioctl + * calls. This, however, may not be practical in many cases and will lead + * to "correct" but awkward implementations. + * + * boardctl() is non-standard OS interface to alleviate the problem. It + * basically circumvents the normal device driver ioctl interlace and allows + * the application to perform direct IOCTL-like calls to the board-specific + * logic. It is especially useful for setting up board operational and + * test configurations. + * + * Input Parameters: + * cmd - Identifies the board command to be executed + * arg - The argument that accompanies the command. The nature of the + * argument is determined by the specific command. + * + * Returned Value: + * On success zero (OK) is returned; -1 (ERROR) is returned on failure + * with the errno variable to to indicate the nature of the failure. + * + ****************************************************************************/ +int boardctl(unsigned int cmd, uintptr_t arg); + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* CONFIG_LIB_BOARDCTL */ +#endif /* __INCLUDE_SYS_BOARDCTL_H */ diff --git a/os/include/tinyara/fs/ioctl.h b/os/include/tinyara/fs/ioctl.h index e5bea9c..04dcd58 100644 --- a/os/include/tinyara/fs/ioctl.h +++ b/os/include/tinyara/fs/ioctl.h @@ -94,6 +94,9 @@ #define _FOTABASE (0x1900) /* FOTA ioctl commands */ #define _GPIOBASE (0x2000) /* GPIO ioctl commands */ +/* boardctl() commands share the same number space */ +#define _BOARDBASE (0xff00) /* boardctl commands */ + /* Macros used to manage ioctl commands */ #define _IOC_MASK (0x00ff) @@ -331,6 +334,10 @@ #define _GPIOIOCVALID(c) (_IOC_TYPE(c) == _GPIOBASE) #define _GPIOIOC(nr) _IOC(_GPIOBASE, nr) +/* boardctl() command definitions *******************************************/ +#define _BOARDIOCVALID(c) (_IOC_TYPE(c) == _BOARDBASE) +#define _BOARDIOC(nr) _IOC(_BOARDBASE, nr) + /**************************************************************************** * Public Type Definitions ****************************************************************************/