diff --git a/arch/arm/mach-imx/mcc_api.c b/arch/arm/mach-imx/mcc_api.c index dafc8c1cc9ed..68c9ed0e6228 100755 --- a/arch/arm/mach-imx/mcc_api.c +++ b/arch/arm/mach-imx/mcc_api.c @@ -1,7 +1,6 @@ /* * Copyright (C) 2014 Freescale Semiconductor, Inc. * Freescale IMX Linux-specific MCC implementation. - * MCC library API functions implementation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -16,13 +15,18 @@ * this program. If not, see . */ +#include "mcc_config.h" +#if (MCC_OS_USED == MCC_MQX) #include #include "mcc_config.h" #include "mcc_common.h" #include "mcc_api.h" - -#if (MCC_OS_USED == MCC_MQX) #include "mcc_mqx.h" +#elif (MCC_OS_USED == MCC_LINUX) +#include +#include +#include +#include #endif const char * const init_string = MCC_INIT_STRING; @@ -59,7 +63,7 @@ int mcc_initialize(MCC_NODE node) { int i,j = 0; int return_value = MCC_SUCCESS; - MCC_SIGNAL tmp_signals_received = {(MCC_SIGNAL_TYPE)0, (MCC_CORE)0, (MCC_NODE)0, (MCC_PORT)0}; + MCC_SIGNAL tmp_signals_received = {(MCC_SIGNAL_TYPE)0, {(MCC_CORE)0, (MCC_NODE)0, (MCC_PORT)0}}; /* Initialize synchronization module for shared data protection */ return_value = mcc_init_semaphore(MCC_SHMEM_SEMAPHORE_NUMBER); @@ -79,12 +83,12 @@ int mcc_initialize(MCC_NODE node) return return_value; /* Initialize the bookeeping structure */ - bookeeping_data = (MCC_BOOKEEPING_STRUCT *)MCC_BASE_ADDRESS; + bookeeping_data = (MCC_BOOKEEPING_STRUCT *)mcc_get_bookeeping_data(); MCC_DCACHE_INVALIDATE_MLINES(bookeeping_data, sizeof(MCC_BOOKEEPING_STRUCT)); if(strcmp(bookeeping_data->init_string, init_string) != 0) { /* MCC not initialized yet, do it now */ /* Zero it all - no guarantee Linux or uboot didnt touch it before it was reserved */ - _mem_zero((void*) bookeeping_data, (_mem_size) sizeof(struct mcc_bookeeping_struct)); + memset((void*) bookeeping_data, 0, sizeof(struct mcc_bookeeping_struct)); /* Set init_string in case it has not been set yet by another core */ mcc_memcpy((void*)init_string, bookeeping_data->init_string, (unsigned int)sizeof(bookeeping_data->init_string)); @@ -93,12 +97,12 @@ int mcc_initialize(MCC_NODE node) mcc_memcpy((void*)version_string, bookeeping_data->version_string, (unsigned int)sizeof(bookeeping_data->version_string)); /* Initialize the free list */ - bookeeping_data->free_list.head = &bookeeping_data->r_buffers[0]; - bookeeping_data->free_list.tail = &bookeeping_data->r_buffers[MCC_ATTR_NUM_RECEIVE_BUFFERS-1]; + bookeeping_data->free_list.head = (MCC_RECEIVE_BUFFER*)MCC_MEM_VIRT_TO_PHYS(&bookeeping_data->r_buffers[0]); + bookeeping_data->free_list.tail = (MCC_RECEIVE_BUFFER*)MCC_MEM_VIRT_TO_PHYS(&bookeeping_data->r_buffers[MCC_ATTR_NUM_RECEIVE_BUFFERS-1]); /* Initialize receive buffers */ for(i=0; ir_buffers[i].next = &bookeeping_data->r_buffers[i+1]; + bookeeping_data->r_buffers[i].next = (MCC_RECEIVE_BUFFER*)MCC_MEM_VIRT_TO_PHYS(&bookeeping_data->r_buffers[i+1]); } bookeeping_data->r_buffers[MCC_ATTR_NUM_RECEIVE_BUFFERS-1].next = null; @@ -199,7 +203,7 @@ int mcc_create_endpoint(MCC_ENDPOINT *endpoint, MCC_PORT port) /* Fill the endpoint structure */ endpoint->core = (MCC_CORE)MCC_CORE_NUMBER; - endpoint->node = (MCC_NODE)MCC_MQX_NODE_NUMBER; + endpoint->node = (MCC_NODE)MCC_NODE_NUMBER; endpoint->port = (MCC_PORT)port; /* Semaphore-protected section start */ @@ -299,10 +303,6 @@ int mcc_send(MCC_ENDPOINT *src_endpoint, MCC_ENDPOINT *dest_endpoint, void *msg, if(return_value != MCC_SUCCESS) return return_value; - /* As the mcc_get_buffer_internal() returns the pointer to the data field, it - is necessary to adjust the pointer to point at the MCC buffer structure beginning. */ - buf = (MCC_RECEIVE_BUFFER *)((unsigned int)buf - (unsigned int)(&(((MCC_RECEIVE_BUFFER*)0)->data))); - /* Check if the size of the message to be sent does not exceed the size of the mcc buffer */ if(msg_size > buffer_size) { while(MCC_SUCCESS != mcc_free_buffer_internal(buf)) {}; @@ -314,6 +314,10 @@ int mcc_send(MCC_ENDPOINT *src_endpoint, MCC_ENDPOINT *dest_endpoint, void *msg, if(return_value != MCC_SUCCESS) return return_value; + /* As the mcc_get_buffer_internal() returns the pointer to the data field, it + is necessary to adjust the pointer to point at the MCC buffer structure beginning. */ + buf = (MCC_RECEIVE_BUFFER *)((unsigned int)buf - (unsigned int)(&(((MCC_RECEIVE_BUFFER*)0)->data))); + /* Copy the message into the MCC receive buffer */ MCC_DCACHE_INVALIDATE_MLINES((void*)buf, sizeof(MCC_RECEIVE_BUFFER)); mcc_memcpy(msg, (void*)buf->data, (unsigned int)msg_size); @@ -632,6 +636,7 @@ int mcc_recv(MCC_ENDPOINT *src_endpoint, MCC_ENDPOINT *dest_endpoint, void *buff mcc_memcpy((void*)list->head->data, buffer, list->head->data_len); /* Dequeue the buffer from the endpoint list */ + list->head = (MCC_RECEIVE_BUFFER*)MCC_MEM_VIRT_TO_PHYS(list->head); buf = mcc_dequeue_buffer(list); /* Enqueue the buffer into the free list */ @@ -775,13 +780,15 @@ static int mcc_recv_common_part(MCC_ENDPOINT *endpoint, unsigned int timeout_ms, /* Blocking call */ else { /* Wait for the buffer queued event */ - mcc_wait_for_buffer_queued(endpoint, timeout_ms); + return_value = mcc_wait_for_buffer_queued(endpoint, timeout_ms); if(MCC_SUCCESS != return_value) { return return_value; } } } - + else { + tmp_list->head = (MCC_RECEIVE_BUFFER*)MCC_MEM_PHYS_TO_VIRT(tmp_list->head); + } /* Clear event bit specified for the particular endpoint */ mcc_clear_os_sync_for_ep(endpoint); diff --git a/arch/arm/mach-imx/mcc_common.c b/arch/arm/mach-imx/mcc_common.c index d766976ffec0..7a54d7b2fdb3 100755 --- a/arch/arm/mach-imx/mcc_common.c +++ b/arch/arm/mach-imx/mcc_common.c @@ -1,7 +1,6 @@ /* * Copyright (C) 2014 Freescale Semiconductor, Inc. * Freescale IMX Linux-specific MCC implementation. - * MCC library common functions * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -17,15 +16,12 @@ */ #include "mcc_config.h" +#if (MCC_OS_USED == MCC_MQX) #include "mcc_common.h" - -#if (MCC_OS_USED == MCC_LINUX) -#include "linux/mcc_linux.h" -#include "linux/mcc_shm_linux.h" -#include -#include -#elif (MCC_OS_USED == MCC_MQX) #include "mcc_mqx.h" +#elif (MCC_OS_USED == MCC_LINUX) +#include +#include #endif @@ -88,10 +84,10 @@ int mcc_remove_endpoint(MCC_ENDPOINT endpoint) if(MCC_ENDPOINTS_EQUAL(bookeeping_data->endpoint_table[i].endpoint, endpoint)) { /* clear the queue */ - MCC_RECEIVE_BUFFER * buffer = mcc_dequeue_buffer((MCC_RECEIVE_LIST *)MCC_MEM_PHYS_TO_VIRT(&bookeeping_data->endpoint_table[i].list)); + MCC_RECEIVE_BUFFER * buffer = mcc_dequeue_buffer((MCC_RECEIVE_LIST *)&bookeeping_data->endpoint_table[i].list); while(buffer) { - mcc_queue_buffer((MCC_RECEIVE_LIST *)MCC_MEM_PHYS_TO_VIRT(&bookeeping_data->free_list), buffer); - buffer = mcc_dequeue_buffer((MCC_RECEIVE_LIST *)MCC_MEM_PHYS_TO_VIRT(&bookeeping_data->endpoint_table[i].list)); + mcc_queue_buffer(&bookeeping_data->free_list, buffer); + buffer = mcc_dequeue_buffer((MCC_RECEIVE_LIST *)&bookeeping_data->endpoint_table[i].list); } /* indicate free */ bookeeping_data->endpoint_table[i].endpoint.port = MCC_RESERVED_PORT_NUMBER; @@ -113,10 +109,12 @@ int mcc_remove_endpoint(MCC_ENDPOINT endpoint) */ MCC_RECEIVE_BUFFER * mcc_dequeue_buffer(MCC_RECEIVE_LIST *list) { + MCC_RECEIVE_BUFFER * next_buf, * next_buf_virt; MCC_DCACHE_INVALIDATE_MLINES((void*)list, sizeof(MCC_RECEIVE_LIST)); - MCC_RECEIVE_BUFFER * next_buf = list->head; - MCC_RECEIVE_BUFFER * next_buf_virt = (MCC_RECEIVE_BUFFER *)MCC_MEM_PHYS_TO_VIRT(next_buf); + next_buf = list->head; + + next_buf_virt = (MCC_RECEIVE_BUFFER *)MCC_MEM_PHYS_TO_VIRT(next_buf); if(next_buf) { MCC_DCACHE_INVALIDATE_MLINES((void*)&next_buf_virt->next, sizeof(MCC_RECEIVE_BUFFER*)); list->head = next_buf_virt->next; @@ -139,10 +137,13 @@ MCC_RECEIVE_BUFFER * mcc_dequeue_buffer(MCC_RECEIVE_LIST *list) */ void mcc_queue_buffer(MCC_RECEIVE_LIST *list, MCC_RECEIVE_BUFFER * r_buffer) { + MCC_RECEIVE_BUFFER * last_buf; + MCC_RECEIVE_BUFFER * r_buffer_phys; + MCC_DCACHE_INVALIDATE_MLINES((void*)list, sizeof(MCC_RECEIVE_LIST)); - MCC_RECEIVE_BUFFER * last_buf = (MCC_RECEIVE_BUFFER *)MCC_MEM_PHYS_TO_VIRT(list->tail); - MCC_RECEIVE_BUFFER * r_buffer_phys = (MCC_RECEIVE_BUFFER *)MCC_MEM_VIRT_TO_PHYS(r_buffer); + last_buf = (MCC_RECEIVE_BUFFER *)MCC_MEM_PHYS_TO_VIRT(list->tail); + r_buffer_phys = (MCC_RECEIVE_BUFFER *)MCC_MEM_VIRT_TO_PHYS(r_buffer); if(last_buf) { last_buf->next = r_buffer_phys; MCC_DCACHE_FLUSH_MLINES((void*)&last_buf->next, sizeof(MCC_RECEIVE_BUFFER*)); @@ -178,7 +179,7 @@ MCC_RECEIVE_LIST * mcc_get_endpoint_list(MCC_ENDPOINT endpoint) for(i = 0; iendpoint_table[i].endpoint, endpoint)) { - return (MCC_RECEIVE_LIST *)MCC_MEM_PHYS_TO_VIRT(&bookeeping_data->endpoint_table[i].list); + return (MCC_RECEIVE_LIST *)&bookeeping_data->endpoint_table[i].list; } } return null; @@ -204,10 +205,12 @@ MCC_RECEIVE_LIST * mcc_get_endpoint_list(MCC_ENDPOINT endpoint) */ int mcc_queue_signal(MCC_CORE core, MCC_SIGNAL signal) { + int tail, new_tail; + MCC_DCACHE_INVALIDATE_MLINES((void*)&bookeeping_data->signal_queue_head[core], sizeof(unsigned int)); MCC_DCACHE_INVALIDATE_MLINES((void*)&bookeeping_data->signal_queue_tail[core], sizeof(unsigned int)); - int tail = bookeeping_data->signal_queue_tail[core]; - int new_tail = tail == (MCC_MAX_OUTSTANDING_SIGNALS-1) ? 0 : tail+1; + tail = bookeeping_data->signal_queue_tail[core]; + new_tail = tail == (MCC_MAX_OUTSTANDING_SIGNALS-1) ? 0 : tail+1; if(MCC_SIGNAL_QUEUE_FULL(core)) return MCC_ERR_SQ_FULL; @@ -238,9 +241,11 @@ int mcc_queue_signal(MCC_CORE core, MCC_SIGNAL signal) */ int mcc_dequeue_signal(MCC_CORE core, MCC_SIGNAL *signal) { + int head; + MCC_DCACHE_INVALIDATE_MLINES((void*)&bookeeping_data->signal_queue_head[core], sizeof(unsigned int)); MCC_DCACHE_INVALIDATE_MLINES((void*)&bookeeping_data->signal_queue_tail[core], sizeof(unsigned int)); - int head = bookeeping_data->signal_queue_head[core]; + head = bookeeping_data->signal_queue_head[core]; if(MCC_SIGNAL_QUEUE_EMPTY(core)) return MCC_ERR_SQ_EMPTY; diff --git a/arch/arm/mach-imx/mcc_config.h b/arch/arm/mach-imx/mcc_config.h index c07d99fdf369..47abf7987c6f 100755 --- a/arch/arm/mach-imx/mcc_config.h +++ b/arch/arm/mach-imx/mcc_config.h @@ -1,7 +1,6 @@ /* * Copyright (C) 2014 Freescale Semiconductor, Inc. * Freescale IMX Linux-specific MCC implementation. - * The main MCC configuration file * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -19,37 +18,10 @@ #ifndef __MCC_CONFIG__ #define __MCC_CONFIG__ +#include +#include + /* used OS */ -#define MCC_OS_USED (MCC_MQX) - -/* base address of shared memory */ -#define MCC_BASE_ADDRESS (BSP_SHARED_RAM_START) - -/* size (in bytes) and number of receive buffers */ -#define MCC_ATTR_NUM_RECEIVE_BUFFERS (10) -#define MCC_ATTR_BUFFER_SIZE_IN_BYTES (1024) - -/* maximum number of receive endpoints (application specific setting), - * do not assign it to a value greater than 255 ! */ -#define MCC_ATTR_MAX_RECEIVE_ENDPOINTS (5) - -/* size of the signal queue */ -#define MCC_MAX_OUTSTANDING_SIGNALS (10) - -/* number of cores */ -#define MCC_NUM_CORES (2) - -/* core number */ -#define MCC_CORE_NUMBER (_psp_core_num()) - -/* semaphore number */ -#define MCC_SHMEM_SEMAPHORE_NUMBER (1) -#define MCC_PRINTF_SEMAPHORE_NUMBER (2) -#define MCC_I2C_SEMAPHORE_NUMBER (3) -#define MCC_RESERVED1_SEMAPHORE_NUMBER (4) -#define MCC_RESERVED2_SEMAPHORE_NUMBER (5) - -/* data non-copy mechanisms enabled */ -#define MCC_SEND_RECV_NOCOPY_API_ENABLED (1) +#define MCC_OS_USED (MCC_LINUX) #endif /* __MCC_CONFIG__ */ diff --git a/include/linux/mcc_api.h b/include/linux/mcc_api.h index 1048a101989c..a91359e009dd 100755 --- a/include/linux/mcc_api.h +++ b/include/linux/mcc_api.h @@ -1,7 +1,6 @@ /* * Copyright (C) 2014 Freescale Semiconductor, Inc. * Freescale IMX Linux-specific MCC implementation. - * MCC library API functions implementation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, diff --git a/include/linux/mcc_common.h b/include/linux/mcc_common.h index 47dc2fc3467b..7c33d84a3770 100755 --- a/include/linux/mcc_common.h +++ b/include/linux/mcc_common.h @@ -1,7 +1,6 @@ /* * Copyright (C) 2014 Freescale Semiconductor, Inc. * Freescale IMX Linux-specific MCC implementation. - * MCC library header file * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -16,7 +15,6 @@ * this program. If not, see . */ - #ifndef __MCC_COMMON__ #define __MCC_COMMON__