From 2a077421df61644882a8e63aba79dc92d8f71292 Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Tue, 2 Aug 2016 11:43:58 +0530 Subject: open-amp: porting: vf6xx_m4: Add support for Vybrid Support Vybrid in open-amp for using rpmsg for communication between A5 core running Linux and M4 core running FreeRTOS. Signed-off-by: Sanchayan Maity Signed-off-by: Stefan Agner --- .../open-amp/porting/vf6xx_m4/plat_porting.h | 47 ++++ .../multicore/open-amp/porting/vf6xx_m4/platform.c | 115 ++++++++++ .../multicore/open-amp/porting/vf6xx_m4/platform.h | 41 ++++ .../open-amp/porting/vf6xx_m4/platform_info.c | 245 +++++++++++++++++++++ 4 files changed, 448 insertions(+) create mode 100644 middleware/multicore/open-amp/porting/vf6xx_m4/plat_porting.h create mode 100644 middleware/multicore/open-amp/porting/vf6xx_m4/platform.c create mode 100644 middleware/multicore/open-amp/porting/vf6xx_m4/platform.h create mode 100644 middleware/multicore/open-amp/porting/vf6xx_m4/platform_info.c diff --git a/middleware/multicore/open-amp/porting/vf6xx_m4/plat_porting.h b/middleware/multicore/open-amp/porting/vf6xx_m4/plat_porting.h new file mode 100644 index 0000000..4b195ee --- /dev/null +++ b/middleware/multicore/open-amp/porting/vf6xx_m4/plat_porting.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2016, Toradex AG + * All rights reserved. + * + * 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 of Mentor Graphics Corporation 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 HOLDER 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. + */ + +/************************************************************************** + * FILE NAME + * + * plat_porting.h + * + * DESCRIPTION + * + * This file contains the declaration of porting related function + * and macros + * + **************************************************************************/ +#ifndef PLAT_PORTING_H_ +#define PLAT_PORTING_H_ + +/* platform specific rpmsg handler which is invoked when a notification is received from peer*/ +void rpmsg_handler(void); + +#endif /* PLAT_PORTING_H_ */ diff --git a/middleware/multicore/open-amp/porting/vf6xx_m4/platform.c b/middleware/multicore/open-amp/porting/vf6xx_m4/platform.c new file mode 100644 index 0000000..6c9fffa --- /dev/null +++ b/middleware/multicore/open-amp/porting/vf6xx_m4/platform.c @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2016, Toradex AG + * All rights reserved. + * + * 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 of Mentor Graphics Corporation 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 HOLDER 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. + */ + +/************************************************************************** + * FILE NAME + * + * platform.c + * + * DESCRIPTION + * + * This file is the Implementation of IPC hardware layer interface + * for Freescale Vybrid platform. + * + **************************************************************************/ + +#include "platform.h" +#include "plat_porting.h" +#include "sema4.h" + +extern void freertos_env_isr(int vector); + +/*--------------------------- Globals ---------------------------------- */ + +struct hil_platform_ops proc_ops = { + .enable_interrupt = _enable_interrupt, + .notify = _notify, + .boot_cpu = _boot_cpu, + .shutdown_cpu = _shutdown_cpu, +}; + +void CPU2CPUInt0_Handler(void) +{ + MSCM_IRCP1IR = MSCM_IRCP1IR_INT0_MASK; + SEMA4_Lock(SEMA4, 0); + freertos_env_isr(0); + SEMA4_Unlock(SEMA4, 0); +} + +void CPU2CPUInt1_Handler(void) +{ + MSCM_IRCP1IR = MSCM_IRCP1IR_INT1_MASK; + freertos_env_isr(1); +} + +void rpmsg_handler(void) +{ + return; +} + +int _enable_interrupt(struct proc_vring *vring_hw) { /*enable_interrupt*/ + env_register_isr(vring_hw->intr_info.vect_id, vring_hw, platform_isr); + + return 0; +} + +void _notify(int cpu_id, struct proc_intr *intr_info) +{ + uint32_t vector = intr_info->vect_id; + + MSCM_IRCPGIR = MSCM_IRCPGIR_TLF(1) | MSCM_IRCPGIR_INTID(vector); +} + +int _boot_cpu(int cpu_id, unsigned int load_addr) +{ + return 0; +} + +void _shutdown_cpu(int cpu_id) +{ +} + +void platform_isr(int vect_id, void *data) +{ + hil_isr(((struct proc_vring *) data)); +} + +void platform_interrupt_enable() +{ + MSCM_IRSPRC0 = 0x3; + MSCM_IRSPRC1 = 0x3; + NVIC_EnableIRQ(CPU2CPU_INT0_IRQ); + NVIC_EnableIRQ(CPU2CPU_INT1_IRQ); +} + +void platform_interrupt_disable() +{ + NVIC_DisableIRQ(CPU2CPU_INT0_IRQ); + NVIC_DisableIRQ(CPU2CPU_INT1_IRQ); +} diff --git a/middleware/multicore/open-amp/porting/vf6xx_m4/platform.h b/middleware/multicore/open-amp/porting/vf6xx_m4/platform.h new file mode 100644 index 0000000..14a92cc --- /dev/null +++ b/middleware/multicore/open-amp/porting/vf6xx_m4/platform.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2014, Mentor Graphics Corporation + * All rights reserved. + * + * 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 of Mentor Graphics Corporation 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 HOLDER 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 PLATFORM_H_ +#define PLATFORM_H_ + +#include "../../common/hil/hil.h" + +int _enable_interrupt(struct proc_vring *vring_hw); +void _notify(int cpu_id, struct proc_intr *intr_info); +int _boot_cpu(int cpu_id, unsigned int load_addr); +void _shutdown_cpu(int cpu_id); +void platform_isr(int vect_id, void *data); + +#endif /* PLATFORM_H_ */ diff --git a/middleware/multicore/open-amp/porting/vf6xx_m4/platform_info.c b/middleware/multicore/open-amp/porting/vf6xx_m4/platform_info.c new file mode 100644 index 0000000..76a6c63 --- /dev/null +++ b/middleware/multicore/open-amp/porting/vf6xx_m4/platform_info.c @@ -0,0 +1,245 @@ +/* + * Copyright (c) 2016, Toradex AG + * All rights reserved. + * + * 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 of Mentor Graphics Corporation 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 HOLDER 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. + */ + +/************************************************************************** + * FILE NAME + * + * platform_info.c + * + * DESCRIPTION + * + * This file implements APIs to get platform specific + * information for OpenAMP. + * + **************************************************************************/ + +#include "platform.h" +#include "../../rpmsg/rpmsg.h" + +/* Reference implementation that show cases platform_get_cpu_info and + platform_get_for_firmware API implementation for Bare metal environment */ + +extern struct hil_platform_ops proc_ops; + +/* + * Linux requirems the ALIGN to 0x1000 instead of 0x80 + */ +#define VRING_ALIGN 0x1000 + +/* + * Linux has a different alignment requirement, and its have 512 buffers instead of 32 buffers for the 2 ring + */ +#define VRING0_BASE 0x3F070000 +#define VRING1_BASE 0x3F074000 + +/* + * 32 MSG (16 rx, 16 tx), 512 bytes each, it is only used when RPMSG driver is working in master mode, otherwise + * the share memory is managed by the other side. + * When working with Linux, SHM_ADDR and SHM_SIZE is not used + */ +#define SHM_ADDR 0 +#define SHM_SIZE 0 + +/* IPI_VECT here defines VRING index in MU */ +#define VRING0_IPI_VECT 0 +#define VRING1_IPI_VECT 1 + +#define MASTER_CPU_ID 0 +#define REMOTE_CPU_ID 1 + +/** + * This array provdes defnition of CPU nodes for master and remote + * context. It contains two nodes beacuse the same file is intended + * to use with both master and remote configurations. On zynq platform + * only one node defintion is required for master/remote as there + * are only two cores present in the platform. + * + * Only platform specific info is populated here. Rest of information + * is obtained during resource table parsing.The platform specific + * information includes; + * + * -CPU ID + * -Shared Memory + * -Interrupts + * -Channel info. + * + * Although the channel info is not platform specific information + * but it is conveneient to keep it in HIL so that user can easily + * provide it without modifying the generic part. + * + * It is good idea to define hil_proc structure with platform + * specific fields populated as this can be easily copied to hil_proc + * structure passed as parameter in platform_get_processor_info. The + * other option is to populate the required structures individually + * and copy them one by one to hil_proc structure in platform_get_processor_info + * function. The first option is adopted here. + * + * + * 1) First node in the array is intended for the remote contexts and it + * defines Master CPU ID, shared memory, interrupts info, number of channels + * and there names. This node defines only one channel + * "rpmsg-data-channel". + * + * 2)Second node is required by the master and it defines remote CPU ID, + * shared memory and interrupts info. In general no channel info is required by the + * Master node, however in baremetal master and linux remote case the linux + * rpmsg bus driver behaves as master so the rpmsg driver on linux side still needs + * channel info. This information is not required by the masters for baremetal + * remotes. + * + */ +struct hil_proc proc_table []= +{ + /* CPU node for remote context */ + { + /* CPU ID of master */ + MASTER_CPU_ID, + + /* Shared memory info - Last field is not used currently */ + { + (void*)SHM_ADDR, SHM_SIZE, 0x00 + }, + + /* VirtIO device info */ /*struct proc_vdev*/ + { + 2, (1 << VIRTIO_RPMSG_F_NS), 0, /*num_vring, dfeatures, gfeatures*/ + + /* Vring info */ /*struct proc_vring*/ + { + /*[0]*/ + { /* TX */ + NULL, (void*)VRING0_BASE/*phy_addr*/, 32/*num_descs*/, VRING_ALIGN/*align*/, + /*struct virtqueue, phys_addr, num_descs, align*/ + { + /*struct proc_intr*/ + VRING0_IPI_VECT,0,0,NULL + } + }, + /*[1]*/ + { /* RX */ + NULL, (void*)VRING1_BASE, 32, VRING_ALIGN, + { + VRING1_IPI_VECT,0,0,NULL + } + } + } + }, + + /* Number of RPMSG channels */ + 1, /*num_chnls*/ + + /* RPMSG channel info - Only channel name is expected currently */ + { + {"rpmsg-openamp-demo-channel"} /*chnl name*/ + }, + + /* HIL platform ops table. */ + &proc_ops, /*struct hil_platform_ops*/ + + /* Next three fields are for future use only */ + 0, + 0, + NULL + }, + + /* CPU node for remote context */ + { + /* CPU ID of remote */ + REMOTE_CPU_ID, + + /* Shared memory info - Last field is not used currently */ + { + (void*)SHM_ADDR, SHM_SIZE, 0x00 + }, + + /* VirtIO device info */ + { + 2, (1 << VIRTIO_RPMSG_F_NS), 0, + { + {/* RX */ + NULL, (void*)VRING0_BASE, 32, VRING_ALIGN, + { + VRING0_IPI_VECT,0,0,NULL + } + }, + {/* TX */ + NULL, (void*)VRING1_BASE, 32, VRING_ALIGN, + { + VRING1_IPI_VECT,0,0,NULL + } + } + } + }, + + /* Number of RPMSG channels */ + 1, + + /* RPMSG channel info - Only channel name is expected currently */ + { + {"rpmsg-openamp-demo-channel"} + }, + + /* HIL platform ops table. */ + &proc_ops, + + /* Next three fields are for future use only */ + 0, + 0, + NULL + } +}; + +/** + * platform_get_processor_info + * + * Copies the target info from the user defined data structures to + * HIL proc data structure.In case of remote contexts this function + * is called with the reserved CPU ID HIL_RSVD_CPU_ID, because for + * remotes there is only one master. + * + * @param proc - HIL proc to populate + * @param cpu_id - CPU ID + * + * return - status of execution + */ +int platform_get_processor_info(struct hil_proc *proc , int cpu_id) { + int idx; + for(idx = 0; idx < sizeof(proc_table)/sizeof(struct hil_proc); idx++) { + if((cpu_id == HIL_RSVD_CPU_ID) || (proc_table[idx].cpu_id == cpu_id) ) { + env_memcpy(proc,&proc_table[idx], sizeof(struct hil_proc)); + return 0; + } + } + return -1; +} + +int platform_get_processor_for_fw(char *fw_name) +{ + return 1; +} -- cgit v1.2.3