diff options
Diffstat (limited to 'module/kernel-module-evklib/evk_lib.c')
-rwxr-xr-x | module/kernel-module-evklib/evk_lib.c | 236 |
1 files changed, 228 insertions, 8 deletions
diff --git a/module/kernel-module-evklib/evk_lib.c b/module/kernel-module-evklib/evk_lib.c index 05d881a..e6dd238 100755 --- a/module/kernel-module-evklib/evk_lib.c +++ b/module/kernel-module-evklib/evk_lib.c @@ -3,11 +3,11 @@ * * Event library (kernel space part) * - * @copyright Copyright (c) 2016-2019 TOYOTA MOTOR CORPORATION. + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License published - * by the Free Software Foundation. + * This file is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License + * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -15,11 +15,10 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include <generated/autoconf.h> #include <linux/module.h> #include <linux/init.h> #include <linux/version.h> @@ -39,6 +38,9 @@ #include <linux/device.h> #include <linux/cdev.h> +#include <linux/types.h> +#include <linux/ioctl.h> + #ifndef STANDARD_INT_DEFINITIONS #define STANDARD_INT_DEFINITIONS typedef __u8 UINT8; @@ -53,7 +55,212 @@ typedef __s64 INT64; #define ENABLE_PROC_FS 1 -#include <agldd/evk_lib.h> +#define EVK_NAME "evk" +#define EVK_DEV_NAME "/dev/agl/"EVK_NAME +#define EVK_DEV_MAJOR (1033 % 256) +#define EVK_IOC_MAGIC 0xE7 + +#define EVK_IOC_CREATE_FLAG _IO(EVK_IOC_MAGIC, 0x00) +#define EVK_IOC_CREATE_FLAG64 _IO(EVK_IOC_MAGIC, 0x01) +#define EVK_IOC_CREATE_MESSAGE_QUEUE _IO(EVK_IOC_MAGIC, 0x02) +#define EVK_IOC_ALLOC_FLAG_ID _IO(EVK_IOC_MAGIC, 0x03) +#define EVK_IOC_ALLOC_FLAG64_ID _IO(EVK_IOC_MAGIC, 0x04) +#define EVK_IOC_ALLOC_QUEUE_ID _IO(EVK_IOC_MAGIC, 0x05) +#define EVK_IOC_DESTROY_QUEUE _IO(EVK_IOC_MAGIC, 0x06) +#define EVK_IOC_STORE_FLAG _IO(EVK_IOC_MAGIC, 0x07) +#define EVK_IOC_STORE_FLAG64 _IO(EVK_IOC_MAGIC, 0x08) +#define EVK_IOC_STORE_MESSAGE _IO(EVK_IOC_MAGIC, 0x09) +#define EVK_IOC_SET_POLL _IO(EVK_IOC_MAGIC, 0x0a) +#define EVK_IOC_GET_EVENT _IO(EVK_IOC_MAGIC, 0x0b) +#define EVK_IOC_PEEK_EVENT _IO(EVK_IOC_MAGIC, 0x0c) +#define EVK_IOC_WAIT_EVENT _IO(EVK_IOC_MAGIC, 0x0d) +#define EVK_IOC_GET_NEXT_EVENT _IO(EVK_IOC_MAGIC, 0x0e) +#define EVK_IOC_PEEK_NEXT_EVENT _IO(EVK_IOC_MAGIC, 0x0f) +#define EVK_IOC_DEBUG_LIST _IO(EVK_IOC_MAGIC, 0x10) + +/** @brief Flag ID and queue ID types used when sending and receiving events + * + * Assign a 32-bit value as follows + * + * - Most significant 8 bits: Reserved + * - Next 16 bits: Modue ID + * - Lower 8 bits: Define in module + * + * Where module is the modules that creates the queue. + * The modules define ID according to the above assignments using EV_Flag_ID_Base and EV_Queue_ID_Base macros. + * @see EV_Flag_ID_Base + * @see EV_Queue_ID_Base + */ +typedef UINT32 EV_ID; + +#define EV_ID_BIT 0x80000000UL +#define EV_FLAG64_BIT 0x40000000UL +#define EV_FLAG_BIT 0x20000000UL +#define EV_QUEUE_BIT 0x10000000UL +#define EV_AUTO_ID_BIT 0x08000000UL +#define EV_RESERVED_BIT 0xff000000UL +#define EV_INVALID_ID EV_ID_BIT +#define EV_NO_ID EV_INVALID_ID + +#define EV_ID_IS_FLAG(queueID) \ + (((queueID) & (EV_ID_BIT|EV_FLAG_BIT)) == (EV_ID_BIT|EV_FLAG_BIT)) +#define EV_ID_IS_FLAG64(queueID) \ + (((queueID) & (EV_ID_BIT|EV_FLAG64_BIT)) == (EV_ID_BIT|EV_FLAG64_BIT)) +#define EV_ID_IS_QUEUE(queueID) \ + (((queueID) & (EV_ID_BIT|EV_QUEUE_BIT)) == (EV_ID_BIT|EV_QUEUE_BIT)) +#define EV_ID_IS_AUTO_ID(queueID) \ + (((queueID) & (EV_ID_BIT|EV_AUTO_ID_BIT)) == (EV_ID_BIT|EV_AUTO_ID_BIT)) +#define EV_ID_IS_VALID(queueID) \ + (EV_ID_IS_FLAG(queueID) || EV_ID_IS_FLAG64(queueID) || EV_ID_IS_QUEUE(queueID)) + +/** @brief Macros for defining flag ID + * + * Define the module ID as an argument as follows. + * - #define XXX_Module_ID 1 + * - #define XXX_Flag_ID_Base EV_Flag_ID_Base(XXX_Module_ID) + * - + * - #define XXX_Flag_foo (XXX_Flag_ID_Base + 1) + * - #define XXX_Flag_bar (XXX_Flag_ID_Base + 2) + * + * The module ID is 16 bits and 0 to 65535 can be specified. + * In addition, 0 to 255 added to Base can be defined as ID. + */ +#define EV_Flag_ID_Base(mod) (EV_ID_BIT|EV_FLAG_BIT|((mod)<<8)) + +/** @brief Macros for defining 64 bits flag ID + * + * Define the module ID as an argument as follows. + * - #define XXX_Module_ID 1 + * - #define XXX_Flag64_ID_Base EV_Flag64_ID_Base(XXX_Module_ID) + * - + * - #define XXX_Flag64_foo (XXX_Flag64_ID_Base + 1) + * - #define XXX_Flag64_bar (XXX_Flag64_ID_Base + 2) + * + * The module ID is 16 bits and 0 to 65535 can be specified. + * In addition, 0 to 255 added to Base can be defined as ID. + */ +#define EV_Flag64_ID_Base(mod) (EV_ID_BIT|EV_FLAG64_BIT|((mod)<<8)) + +/** @brief Macros for defining mesage queue ID + * + * Define the module ID as an argument as follows. + * - #define XXX_Module_ID 1 + * - #define XXX_Queue_ID_Base EV_Queue_ID_Base(XXX_Module_ID) + * - + * - #define XXX_Queue_foo (XXX_Queue_ID_Base + 1) + * - #define XXX_Queue_bar (XXX_Queue_ID_Base + 2) + * + * The module ID is 16 bits and 0 to 65535 can be specified. + * In addition, 0 to 255 added to Base can be defined as ID. + */ +#define EV_Queue_ID_Base(mod) (EV_ID_BIT|EV_QUEUE_BIT|((mod)<<8)) + +/** @brief Maximum number of bytes for message event */ +#define EV_MAX_MESSAGE_LENGTH 2048 + +/** @brief -Maximum number of flag queue that can be created within a thread */ +#define EV_MAX_IDS_IN_THREAD 24 + +/** @brief -Muximum number of threads that can be registered to the EV in a process */ +#define EV_MAX_THREADS_IN_PROCESS 16 + +/** @brief -Maximum number of flag queue that can be creat within a process + */ +#define EV_MAX_IDS_IN_PROCESS \ + (EV_MAX_IDS_IN_THREAD * EV_MAX_THREADS_IN_PROCESS) + +/** @brief Return values for even library function + * + * @see EV_ERR + */ +enum ev_err +{ + EV_OK = 0, /**< Normal completion */ + EV_ERR_Exist, /**< The specified flag message queue does exist */ + EV_ERR_Invalid_ID, /**< The specified flag message queue does not exist */ + EV_ERR_Busy, /**< Message queue full failed to send */ + EV_ERR_Interrupted, /**< Waiting function was interrupted by an interrupt */ + EV_ERR_Thread_Over, /**< Exceeding the number of threads in the process */ + EV_ERR_Invalid_Thread, /**< Invalid thread ID */ + EV_ERR_Fatal, /**< Fatal error */ +}; +/** @brief Return values type for even library function + * + * @see ev_err + */ +typedef INT32 EV_ERR; + +/** @brief Event type + * + * Use in the type of EV_Event structs + * @see ev_type + */ +typedef UINT32 EV_Type; + +/** @brief Bit value representing the type of event */ +enum ev_type { + EV_EVENT_None = 0x00000000, + + /** Flag event: Judged by EV_EVENT_IS_FLAG() */ + EV_EVENT_Flag = 0x0001, +#define EV_EVENT_IS_FLAG(tp) (((tp) & EV_EVENT_Flag) != 0) + + /** Message event: Judged by EV_EVENT_IS_MESSAGE() */ + EV_EVENT_Message = 0x0002, +#define EV_EVENT_IS_MESSAGE(tp) (((tp) & EV_EVENT_Message) != 0) + + /** 64bit flag event: Judged by EV_EVENT_IS_FLAG64() */ + EV_EVENT_Flag64 = 0x0003, +#define EV_EVENT_IS_FLAG64(tp) (((tp) & EV_EVENT_Flag64) != 0) + +}; + +/** @brief Flag event structure */ +typedef struct { + EV_ID flagID;/**< Flag ID */ + UINT32 bits;/**< Bit pattern */ +} EV_Flag; + +/** @brief 64bit flag event structure */ +typedef struct { + EV_ID flagID;/**< Flag ID */ + UINT64 bits;/**< Bit pattern */ +} EV_Flag64; + +/** @brief Message event structure */ +typedef struct { + EV_ID queueID;/**< queue ID */ + UINT32 senderInfo;/**< Source information */ + UINT32 length;/**< Number of bytes in the message */ + UINT32 dummy;/** dummy for pading */ + UINT8 message[EV_MAX_MESSAGE_LENGTH];/**< Message */ +} EV_Message; + +/** @brief Event structure */ +typedef struct { + EV_Type type; /**< Event type */ + union { + EV_Flag flag; /**< Flag event structure */ + EV_Flag64 flag64; /**< Flag event structure */ + EV_Message message; /**< Message event structure */ + } u; /**< Union of structures per eventtype */ +} EV_Event; + +/** @brief Message event queue type + * + * Specify the action to be taken when the queue overflows (more events are received when the queue is full). + */ +enum ev_message_queue_type { + EV_MESSAGE_QUEUE_TYPE_BUSY,/**< Return a BUSY to the source */ + EV_MESSAGE_QUEUE_TYPE_FIFO,/**< Delete the oldest event */ + EV_MESSAGE_QUEUE_TYPE_REPLACE,/**< Replace the most recent event */ +}; + +/** @brief Messge event queue type + * + * @see ev_message_queue_type + */ +typedef UINT8 EV_Message_Queue_Type; /** @addtogroup EV_in */ /** @{ */ @@ -248,6 +455,19 @@ static EV_ID sequence_id = 0; /** @brief Number to be assigned in order of occurrence of the event */ static UINT32 sequence_number = 0; +typedef struct { + EV_ID queueID;/**< Queue ID */ + UINT32 max_bytes;/**< Maximum number of bytes for an event */ + UINT8 length;/**< Queue length */ + EV_Message_Queue_Type type;/**< Type */ +} EVK_Message_Queue_Request; + +typedef struct { + INT32 num; /**< Number of queue ID of search */ + EV_ID ids[EV_MAX_IDS_IN_PROCESS]; /**< Queue ID of search */ + EV_Event ev; /**< [OUT] First event that occured */ +} EVK_Next_Event_Query; + unsigned int evk_get_queue_entry(struct list_head **entries) { |