diff --git a/mcs/CMakeLists.txt b/mcs/CMakeLists.txt deleted file mode 100644 index 3f80ebb92eca0fc28436372253e322fb8429399d..0000000000000000000000000000000000000000 --- a/mcs/CMakeLists.txt +++ /dev/null @@ -1,46 +0,0 @@ -cmake_minimum_required(VERSION 3.19) - -project(openamp_demo) - -set(CMAKE_C_COMPILER ${CC}) -set(CMAKE_CXX_COMPILER ${CXX}) - -message(STATUS "SDKTARGETSYSROOT=$ENV{SDKTARGETSYSROOT}") -message(STATUS "DEMO_TARGET=${DEMO_TARGET}") - -set(SHARED_LINK_LIBS - $ENV{SDKTARGETSYSROOT}/usr/lib64/libopen_amp.so - $ENV{SDKTARGETSYSROOT}/usr/lib64/libmetal.so - $ENV{SDKTARGETSYSROOT}/lib64/libsysfs.so -) - -add_library(openamp STATIC - ./modules/openamp_module.c - ./modules/remoteproc_module.c - ./modules/virtio_module.c - ./modules/rpmsg_module.c -) -target_link_libraries(openamp - ${SHARED_LINK_LIBS} -) - -set(SRC_FILE - ./${DEMO_TARGET}/rpmsg_main.c -) - -if(DEMO_TARGET MATCHES "openamp_demo") -elseif(DEMO_TARGET MATCHES "latency_demo") -elseif(DEMO_TARGET MATCHES "rpmsg_pty_demo") - list(APPEND SRC_FILE "./${DEMO_TARGET}/rpmsg_pty.c") -else() - message(FATAL_ERROR "DEMO_TARGET: choose a target to build. - [openamp_demo|rpmsg_pty_demo]") #rsc_table_demo|cyclitest_demo|rpmsg_service_demo|gdb_demo -endif() - -include_directories( - $ENV{SDKTARGETSYSROOT}/usr/include - ./modules - ./${DEMO_TARGET} -) -add_executable(rpmsg_main ${SRC_FILE}) -target_link_libraries(rpmsg_main openamp) \ No newline at end of file diff --git a/mcs/README.md b/mcs/README.md deleted file mode 100644 index dbee180dce5b92bbc9f2ed58504ac70fb3b20b36..0000000000000000000000000000000000000000 --- a/mcs/README.md +++ /dev/null @@ -1,158 +0,0 @@ -# mcs - -#### 介绍 - -该模块用于提供OpenAMP样例的内核态与用户态支持。 - -#### 软件架构 - -mcs_km: 提供OpenAMP所需内核模块,支持Client OS启动、专用中断收发、管理保留内存等功能。 - -openamp_demo: 提供OpenAMP用户态程序Linux端样例,支持与指定Client OS进行通信。 - -rpmsg_pty_demo: 提供OpenAMP用户态程序Linux端样例,支持通过shell命令行访问Client OS。 - -modules: 提供OpenAMP样例必需的模块remoteproc、virtio、rpmsg、openamp,这些模块静态编译成libopenamp.a。 - -zephyr: 提供样例镜像文件,在每个demo中,zephyr_qemu.bin运行在qemu上,zephyr_rpi.bin运行在树莓派上,该文件需要被加载至设定的0x7a000000起始地址。启动后会运行OpenAMP Client端的样例程序,并与Linux端进行交互。 - -#### 原理简介 - -OpenAMP旨在通过非对称多处理器的开源解决方案来标准化异构嵌入式系统中操作环境之间的交互。 - -OpenAMP是一个软件框架,提供了为AMP系统开发软件应用程序所需的软件组件,允许操作系统在复杂的同构和异构体系结构中交互。 - -OpenAMP包括如下三大重要组件: - --virtio:该组件是rpmsg组件的实现基础。 - --rpmsg:实现多核处理器通信的通道,基于virtio组件实现。 - --remoteproc:该组件用于主机上实现对远程处理器及相关软件环境的生命周期管理、及virtio和rpmsg设备的注册等。 - -样例Demo通过提供mcs_km内核KO模块实现Linux内核启动从核的功能,并预留了OpenAMP通信所需的专用中断及其收发机制。用户可在用户态通过dev设备实现Client OS的启动,并通过rpmsg组件实现与Client OS的简单通信。 - -#### 安装教程 - -1. qemu使用openeuler-image镜像运行混合部署。 - -树莓派使用openeuler-image-uefi镜像运行混合部署,该镜像对齐tiny镜像的软件包配置,并集成openssh支持网络登录、混合部署依赖库、混合部署保留内存mcsmem dtoverlay、以及第三方UEFI固件支持PSCI功能。openeuler-image-uefi镜像的构建、烧录和启动,请参考openEuler Embedded在线文档章节:树莓派的UEFI支持和网络启动。 - -2. 根据openEuler Embedded使用手册安装SDK并设置SDK环境变量。 - -3. 编译内核模块mcs_km.ko,编译方式如下: - -```` - cd mcs_km - make -```` - -4. 编译openamp_demo用户态程序rpmsg_main,编译方式如下: - -```` - cmake -S . -B build -DDEMO_TARGET=openamp_demo - cd build - make -```` - -注意:此处定义OpenAMP通信设备保留内存起始地址为0x70000000,可根据实际内存分配进行修改。 -如果需要查看调试日志,可以给cmake增加-DDEBUG参数。 - -5. 将编译好的KO模块、用户态程序,以及zephyr_qemu.bin镜像拷贝到openEuler Embedded系统的目录下。如何拷贝可以参考使用手册中共享文件系统场景。 - -6. 将OpenAMP的依赖库libmetal.so\*,libopen_amp.so\*拷贝至文件系统/usr/lib64目录,libsysfs.so\*拷贝至文件系统/lib64目录。对应so可在sdk目录中找到,如何拷贝可以参考使用手册中共享文件系统场景。 - -#### 使用说明 - -1. 通过QEMU启动openEuler Embedded镜像,如何启动可参考使用手册中QEMU使用与调试章节。树莓派跳过这一步。 - --以上述demo为例,需要预留出地址0x70000000为起始的内存用于OpenAMP demo和Client OS启动。通过QEMU启动时,当指定-m 1G时默认使用0x40000000-0x80000000的系统内存。添加内核启动参数mem=768M,可预留地址为0x70000000-0x80000000的256M保留内存。 --在样例中在cpu 3启动Client OS,需要预留出3号cpu。 --样例中zephyr镜像默认gic版本为3,需要在QEMU中设置。 - -可参考如下命令进行启动: - -```` - qemu-system-aarch64 -M virt,gic-version=3 -m 1G -cpu cortex-a57 -nographic -kernel zImage -initrd *.rootfs.cpio.gz -append 'mem=768M maxcpus=3' -smp 4 -```` - -当使用的QEMU版本过老时可能会由于内存分布不一致导致段错误,可升级QEMU版本或手动修改DTB空出对应内存。 - -2. 在openEuler Embedded系统上插入内核KO模块mcs_km.ko。 - -```` - insmod mcs_km.ko -```` - -3. 运行rpmsg_main程序,使用方式如下: - -```` - ./rpmsg_main -c [cpu_id] -t [target_binfile] -a [target_binaddress] - eg: - ./rpmsg_main -c 3 -t zephyr_qemu.bin -a 0x7a000000 -```` - -此处定义Client OS起始地址为0x7a000000,Client OS镜像名为zephyr_qemu.bin,Client OS从3号cpu启动。树莓派换成zephyr_rpi.bin。 - -#### 用户样例开发 -mcs提供了4个API,供用户做样例开发,用户无需感知OpenAMP实现细节,接口定义在modules/openamp_module.h。 - -1. openamp_init: 初始化保留内存,加载zephyr镜像文件,初始化remoteproc、virtio、rpmsg,建立Linux与Client OS两端配对的endpoint,供消息收发使用。 -```` - int openamp_init(void); -```` - -2. receive_message: Linux端接收消息。 -```` - int receive_message(unsigned char *message, int message_len, int *real_len); -```` - message: 用户传入的消息接收buffer - message_len: 接收buffer的长度 - real_len: 实际接收到的消息长度 - -3. send_message: Linux端发送消息。 -```` - int send_message(unsigned char *message, int len); -```` - message: 用户传入的消息发送buffer - len: 发送buffer的长度 - -4. openamp_deinit: 释放openamp资源。 -```` - void openamp_deinit(void); -```` - -#### 串口服务样例 -rpmsg_pty_demo包含2个源文件,实现通过Linux shell命令行访问Client OS的功能,样例支持多用户多线程场景。 - -rpmsg_main.c: 初始化OpenAMP,用户创建线程,在线程中运行shell程序。 - -rpmsg_pty.c: 用户创建PTY虚拟串口设备,将PTY的slave端作为shell,PTY的master端与OpenAMP Endpint节点通信。 - -1. 安装教程,其他步骤与openamp_demo相同,把DEMO_TARGET换成rpmsg_pty_demo编译。 -```` - cmake -S . -B build -DDEMO_TARGET=rpmsg_pty_demo -```` - -2. 使用说明,为了不影响shell的使用,建议启动qemu时加上console=ttyAMA1内核参数,将内核打印屏蔽。 -```` - qemu-system-aarch64 -M virt,gic-version=3 -m 1G -cpu cortex-a57 -nographic -kernel zImage -initrd *.rootfs.cpio.gz -append 'mem=768M maxcpus=3 console=ttyAMA1' -smp 4 -```` - -树莓派可以通过设置printk在console上的打印优先级屏蔽内核打印。 -```` - cat /proc/sys/kernel/printk > /tmp/printk_bak - echo 1 4 1 7 > /proc/sys/kernel/printk -```` - -3. 运行rpmsg_main程序时,把程序放在后台,然后通过screen打开shell。 -```` - ./rpmsg_main -c 3 -t zephyr_qemu.bin -a 0x7a000000 & - screen /dev/pts/0 -```` - -4. 进入shell,输入help可以查看Client OS支持哪些命令,输入history可以查看历史命令,ctrl+d退出。 -```` - uart:~$ help - uart:~$ history -```` \ No newline at end of file diff --git a/mcs/latency_demo/rpmsg_main.c b/mcs/latency_demo/rpmsg_main.c deleted file mode 100644 index 2632ee0d8c52f1ca44bde5e10847478cbb677eee..0000000000000000000000000000000000000000 --- a/mcs/latency_demo/rpmsg_main.c +++ /dev/null @@ -1,87 +0,0 @@ -#include -#include -#include "openamp_module.h" - -char *cpu_id; -char *target_binfile; -char *target_binaddr; - -static void cleanup(int sig) -{ - openamp_deinit(); - exit(0); -} - -int rpmsg_app_master(void) -{ - int ret; - char buf[2048] = {0}; - int len; - int i; - - printf("start latency measure demo...\n"); - - /* linux send messsage to clientos first */ - ret = send_message("latency_demo\n", sizeof("latency_demo\n")); - if (ret < 0) { - printf("send_message failed with status %d\n", ret); - return ret; - } - - while (1) { - ret = receive_message(buf, sizeof(buf), &len); - if (ret < 0) { - printf("receive_message failed with status %d\n", ret); - return ret; - } - - /* show message */ - for (i = 0; i < len; i++) - printf("%c", buf[i]); - } - - return 0; -} - -int main(int argc, char **argv) -{ - int ret; - int opt; - - /* ctrl+c signal, do cleanup before program exit */ - signal(SIGINT, cleanup); - - while ((opt = getopt(argc, argv, "c:t:a:")) != -1) { - switch (opt) { - case 'c': - cpu_id = optarg; - break; - case 't': - target_binfile = optarg; - break; - case 'a': - target_binaddr = optarg; - break; - default: - break; - } - } - - ret = openamp_init(); - if (ret) { - printf("openamp init failed: %d\n", ret); - openamp_deinit(); - return ret; - } - - ret = rpmsg_app_master(); - if (ret) { - printf("rpmsg app master failed: %d\n", ret); - openamp_deinit(); - return ret; - } - - openamp_deinit(); - - return 0; -} diff --git a/mcs/latency_demo/zephyr_rpi.bin b/mcs/latency_demo/zephyr_rpi.bin deleted file mode 100644 index 2f3b03354f2e30aa6cb0e72b828b9866ac6d5cbd..0000000000000000000000000000000000000000 Binary files a/mcs/latency_demo/zephyr_rpi.bin and /dev/null differ diff --git a/mcs/mcs_km/Makefile b/mcs/mcs_km/Makefile deleted file mode 100644 index f9b3396cc9c7b44214201342c5f9e41320350e52..0000000000000000000000000000000000000000 --- a/mcs/mcs_km/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -obj-m := mcs_km.o - -all: - $(MAKE) -C $(KERNEL_SRC_DIR) M=$(PWD) modules -clean: - $(MAKE) -C $(KERNEL_SRC_DIR) M=$(PWD) clean diff --git a/mcs/mcs_km/mcs_km.c b/mcs/mcs_km/mcs_km.c deleted file mode 100644 index 0445be1f13cdef65b1b532d67e45f468222798d3..0000000000000000000000000000000000000000 --- a/mcs/mcs_km/mcs_km.c +++ /dev/null @@ -1,341 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define MCS_DEVICE_NAME "mcs" -#define CPU_ON_FUNCID 0xC4000003 -#define AFFINITY_INFO_FUNCID 0xC4000004 - -#define MAGIC_NUMBER 'A' -#define IOC_SENDIPI _IOW(MAGIC_NUMBER, 0, int) -#define IOC_CPUON _IOW(MAGIC_NUMBER, 1, int) -#define IOC_AFFINITY_INFO _IOW(MAGIC_NUMBER, 2, int) -#define IOC_MAXNR 2 - -#define OPENAMP_INIT_TRIGGER 0x0 -#define OPENAMP_CLIENTOS_TRIGGER 0x1 -#define OPENAMP_IRQ 8 - -#define START_INDEX 1 -#define SIZE_INDEX 2 - -static struct class *mcs_class; -static int mcs_major; - -static u64 valid_start; -static u64 valid_end; -static const char *smccc_method = "hvc"; - -static DECLARE_WAIT_QUEUE_HEAD(openamp_trigger_wait); -static int openamp_trigger; - -static irqreturn_t handle_clientos_ipi(int irq, void *data) -{ - pr_info("mcs_km: received ipi from client os\n"); - openamp_trigger = OPENAMP_CLIENTOS_TRIGGER; - wake_up_interruptible(&openamp_trigger_wait); - return IRQ_HANDLED; -} - -void set_openamp_ipi(void) -{ - int err; - struct irq_desc *desc; - - /* use IRQ8 as IPI7, init irq resource once */ - desc = irq_to_desc(OPENAMP_IRQ); - if (!desc->action) { - err = request_percpu_irq(OPENAMP_IRQ, handle_clientos_ipi, "IPI", &cpu_number); - if (err) { - pr_err("mcs_km: request openamp irq failed(%d)\n", err); - return; - } - } - - /* In SMP, all the cores run Linux should be enabled */ - if (!irq_percpu_is_enabled(OPENAMP_IRQ)) { - preempt_disable(); /* fix kernel err message: using smp_processor_id() in preemptible */ - enable_percpu_irq(OPENAMP_IRQ, 0); - preempt_enable(); - } - - return; -} - -static void send_clientos_ipi(const struct cpumask *target) -{ - ipi_send_mask(OPENAMP_IRQ, target); -} - -static unsigned int mcs_poll(struct file *file, poll_table *wait) -{ - unsigned int mask; - - poll_wait(file, &openamp_trigger_wait, wait); - mask = 0; - if (openamp_trigger == OPENAMP_CLIENTOS_TRIGGER) - mask |= POLLIN | POLLRDNORM; - - openamp_trigger = OPENAMP_INIT_TRIGGER; - return mask; -} - -static long mcs_ioctl(struct file *f, unsigned int cmd, unsigned long arg) -{ - int err; - int cpu_id, cpu_boot_addr; - struct arm_smccc_res res; - - if (_IOC_TYPE(cmd) != MAGIC_NUMBER) - return -EINVAL; - if (_IOC_NR(cmd) > IOC_MAXNR) - return -EINVAL; - err = !access_ok((void*)arg, _IOC_SIZE(cmd)); - if (err) - return -EINVAL; - - switch (cmd) { - case IOC_SENDIPI: - cpu_id = (int)arg; - pr_info("mcs_km: received ioctl cmd to send ipi to cpu(%d)\n", cpu_id); - send_clientos_ipi(cpumask_of(cpu_id)); - break; - case IOC_CPUON: - cpu_id = *(unsigned int*)arg; - cpu_boot_addr = *((unsigned int*)arg + 1); - - pr_info("mcs_km: start booting clientos on cpu(%d) addr(0x%x) smccc(%s)\n", cpu_id, cpu_boot_addr, smccc_method); - if (strcmp(smccc_method, "smc") == 0) - arm_smccc_smc(CPU_ON_FUNCID, cpu_id, cpu_boot_addr, 0, 0, 0, 0, 0, &res); - else - arm_smccc_hvc(CPU_ON_FUNCID, cpu_id, cpu_boot_addr, 0, 0, 0, 0, 0, &res); - if (res.a0) { - pr_err("mcs_km: boot clientos failed(%ld)\n", res.a0); - return -EINVAL; - } - break; - case IOC_AFFINITY_INFO: - cpu_id = *(unsigned int*)arg; - - if (strcmp(smccc_method, "smc") == 0) - arm_smccc_smc(AFFINITY_INFO_FUNCID, cpu_id, 0, 0, 0, 0, 0, 0, &res); - else - arm_smccc_hvc(AFFINITY_INFO_FUNCID, cpu_id, 0, 0, 0, 0, 0, 0, &res); - *(unsigned int*)arg = res.a0; - break; - default: - pr_err("mcs_km: IOC param invalid(0x%x)\n", cmd); - return -EINVAL; - } - - return 0; -} - -#ifdef CONFIG_STRICT_DEVMEM -static inline int range_is_allowed(unsigned long pfn, unsigned long size) -{ - u64 from = ((u64)pfn) << PAGE_SHIFT; - u64 to = from + size; - u64 cursor = from; - - while (cursor < to) { - if (page_is_ram(pfn)) - return 0; - cursor += PAGE_SIZE; - pfn++; - } - return 1; -} -#else -static inline int range_is_allowed(unsigned long pfn, unsigned long size) -{ - return 1; -} -#endif - -int mcs_phys_mem_access_prot_allowed(struct file *file, - unsigned long pfn, unsigned long size, pgprot_t *vma_prot) -{ - u64 start, end; - start = ((u64)pfn) << PAGE_SHIFT; - end = start + size; - - if (valid_start == 0 && valid_end == 0) { - if (!range_is_allowed(pfn, size)) - return 0; - return 1; - } - - if (start < valid_start || end > valid_end) { - return 0; - } - - return 1; -} - -static pgprot_t mcs_phys_mem_access_prot(struct file *file, unsigned long pfn, - unsigned long size, pgprot_t vma_prot) -{ - return __pgprot_modify(vma_prot, PTE_ATTRINDX_MASK, PTE_ATTRINDX(MT_NORMAL_NC) | PTE_PXN | PTE_UXN); -} - -static const struct vm_operations_struct mmap_mem_ops = { -#ifdef CONFIG_HAVE_IOREMAP_PROT - .access = generic_access_phys -#endif -}; - -/* A lite version of linux/drivers/char/mem.c, Test with MMU for arm64 mcs functions */ -static int mcs_mmap(struct file *file, struct vm_area_struct *vma) -{ - size_t size = vma->vm_end - vma->vm_start; - phys_addr_t offset = (phys_addr_t)vma->vm_pgoff << PAGE_SHIFT; - - /* Does it even fit in phys_addr_t? */ - if (offset >> PAGE_SHIFT != vma->vm_pgoff) - return -EINVAL; - - /* It's illegal to wrap around the end of the physical address space. */ - if (offset + (phys_addr_t)size - 1 < offset) - return -EINVAL; - - if (!mcs_phys_mem_access_prot_allowed(file, vma->vm_pgoff, size, - &vma->vm_page_prot)) - return -EINVAL; - - vma->vm_page_prot = mcs_phys_mem_access_prot(file, vma->vm_pgoff, - size, - vma->vm_page_prot); - - vma->vm_ops = &mmap_mem_ops; - - /* Remap-pfn-range will mark the range VM_IO */ - if (remap_pfn_range(vma, - vma->vm_start, - vma->vm_pgoff, - size, - vma->vm_page_prot)) { - return -EAGAIN; - } - return 0; -} - -static int mcs_open(struct inode *inode, struct file *filp) -{ - if (!capable(CAP_SYS_RAWIO)) - return -EPERM; - return 0; -} - -static const struct file_operations mcs_fops = { - .open = mcs_open, - .mmap = mcs_mmap, - .poll = mcs_poll, - .unlocked_ioctl = mcs_ioctl, - .llseek = generic_file_llseek, -}; - -static int get_mcs_node_info(void) -{ - int ret = 0; - struct device_node *nd = NULL; - u8 datasize; - u32 *val = NULL; - - nd = of_find_compatible_node(NULL, NULL, "mcs_mem"); - if (nd == NULL) { - pr_info("no reserved-memory mcs node.\n"); - return -EINVAL; - } - - datasize = of_property_count_elems_of_size(nd, "reg", sizeof(u32)); - if (datasize != 3) { - pr_err("invalid reserved-memory mcs reg size.\n"); - return -EINVAL; - } - - val = kmalloc(datasize * sizeof(u32), GFP_KERNEL); - if (val == NULL) - return -ENOMEM; - - ret = of_property_read_u32_array(nd, "reg", val, datasize); - if (ret < 0) - goto out; - - valid_start = (u64)(*(val + START_INDEX)); - valid_end = valid_start + (u64)(*(val + SIZE_INDEX)); - - ret = of_property_read_string(nd, "smccc", &smccc_method); - if (ret < 0) - goto out; - -out: - kfree(val); - return ret; -} - -static int __init mcs_dev_init(void) -{ - struct device *class_dev = NULL; - int ret = 0; - - mcs_major = register_chrdev(0, MCS_DEVICE_NAME, &mcs_fops); - if (mcs_major < 0) { - pr_err("mcs_km: unable to get major %d for memory devs.\n", mcs_major); - return -1; - } - - mcs_class = class_create(THIS_MODULE, MCS_DEVICE_NAME); - if (IS_ERR(mcs_class)) { - ret = PTR_ERR(mcs_class); - goto error_class_create; - } - - class_dev = device_create(mcs_class, NULL, MKDEV((unsigned int)mcs_major, 1), - NULL, MCS_DEVICE_NAME); - if (unlikely(IS_ERR(class_dev))) { - ret = PTR_ERR(class_dev); - goto error_device_create; - } - - set_openamp_ipi(); - - if (get_mcs_node_info() < 0) - pr_info("there's no mcsmem dts node info. Allow page isn't ram mmap.\n"); - else - pr_info("valid mcsmem node detected.\n"); - - pr_info("mcs_km: create major %d for mcs dev.\n", mcs_major); - return 0; - -error_device_create: - class_destroy(mcs_class); -error_class_create: - unregister_chrdev(mcs_major, MCS_DEVICE_NAME); - return ret; -} -module_init(mcs_dev_init); - -static void __exit mcs_dev_exit(void) -{ - device_destroy(mcs_class, MKDEV((unsigned int)mcs_major, 1)); - class_destroy(mcs_class); - unregister_chrdev(mcs_major, MCS_DEVICE_NAME); - - pr_info("mcs_km: remove mcs dev.\n"); -} -module_exit(mcs_dev_exit); - -MODULE_AUTHOR("OpenEuler Embedded"); -MODULE_DESCRIPTION("mcs device"); -MODULE_LICENSE("Dual BSD/GPL"); diff --git a/mcs/modules/openamp_module.c b/mcs/modules/openamp_module.c deleted file mode 100644 index 89ba609a6be798317ddba92a07bf5adcea64e467..0000000000000000000000000000000000000000 --- a/mcs/modules/openamp_module.c +++ /dev/null @@ -1,113 +0,0 @@ -#include -#include "openamp_module.h" - -#define MCS_DEVICE_NAME "/dev/mcs" -#define STR_TO_HEX 16 -#define PAGE_SIZE 4096 -#define PAGE_MASK (~(PAGE_SIZE - 1)) -#define PAGE_ALIGN(addr) ((addr & PAGE_MASK) + PAGE_SIZE) - -static int memfd; -static void *binaddr; -static int binsize; -void *shmaddr; - -static int reserved_mem_init(void) -{ - int binfd; - struct stat buf; - void *file_addr; - - /* open memfd */ - memfd = open(MCS_DEVICE_NAME, O_RDWR | O_SYNC); - if (memfd < 0) { - printf("mcsmem open failed: %d\n", memfd); - return -1; - } - - /* open clientos bin file */ - binfd = open(target_binfile, O_RDONLY); - if (binfd < 0) { - printf("open %s failed, binfd:%d\n", target_binfile, binfd); - return -1; - } - - /* shared memory for virtio */ - shmaddr = mmap(NULL, VDEV_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, memfd, VDEV_START_ADDR); - memset(shmaddr, 0, VDEV_SIZE); - - /* memory for loading clientos bin file */ - fstat(binfd, &buf); - binsize = PAGE_ALIGN(buf.st_size); - binaddr = mmap(NULL, binsize, PROT_READ | PROT_WRITE, MAP_SHARED, memfd, strtol(target_binaddr, NULL, STR_TO_HEX)); - memset(binaddr, 0, binsize); - - if (shmaddr < 0 || binaddr < 0) { - printf("mmap reserved mem failed: shmaddr:%p, binaddr:%p\n", shmaddr, binaddr); - return -1; - } - - /* load clientos */ - file_addr = mmap(NULL, binsize, PROT_READ, MAP_PRIVATE, binfd, 0); - memcpy(binaddr, file_addr, binsize); - - close(binfd); - - return 0; -} - -static void reserved_mem_release(void) -{ - if (shmaddr) - munmap(shmaddr, VDEV_SIZE); - if (binaddr) - munmap(binaddr, binsize); - if (memfd) - close(memfd); -} - -int openamp_init(void) -{ - int ret; - struct remoteproc *rproc; - int cpu_state; - - /* secondary core power state must be CPU_STATE_OFF, avoid initialize repeatedly */ - cpu_state = acquire_cpu_state(); - if (cpu_state != CPU_STATE_OFF) { - printf("cpu(%s) is already on(%d).\n", cpu_id, cpu_state); - return -1; - } - - ret = reserved_mem_init(); - if (ret) { - printf("failed to init reserved mem\n"); - return ret; - } - - rproc = create_remoteproc(); - if (!rproc) { - printf("create remoteproc failed\n"); - return -1; - } - - ret = remoteproc_start(rproc); - if (ret) { - printf("start processor failed\n"); - return ret; - } - - virtio_init(); - rpmsg_module_init(); - - return 0; -} - -void openamp_deinit(void) -{ - printf("\nOpenAMP demo ended.\n"); - - destory_remoteproc(); /* shutdown clientos first */ - virtio_deinit(); - reserved_mem_release(); -} diff --git a/mcs/modules/openamp_module.h b/mcs/modules/openamp_module.h deleted file mode 100644 index bc4237aba810248cbd20bea3e91d7bb784fad858..0000000000000000000000000000000000000000 --- a/mcs/modules/openamp_module.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef OPENAMP_MODULE_H -#define OPENAMP_MODULE_H - -#include -#include "remoteproc_module.h" -#include "virtio_module.h" -#include "rpmsg_module.h" - -extern char *target_binfile; -extern char *target_binaddr; -extern char *cpu_id; - -/* initialize openamp module, including remoteproc, virtio, rpmsg */ -int openamp_init(void); - -/* release openamp resource */ -void openamp_deinit(void); - -/* message standard receive interface */ -int receive_message(unsigned char *message, int message_len, int *real_len); - -/* message standard send interface */ -int send_message(unsigned char *message, int len); - -#endif \ No newline at end of file diff --git a/mcs/modules/remoteproc_module.c b/mcs/modules/remoteproc_module.c deleted file mode 100644 index 8965040ba600f7f4511d27f5adc142b49a4cadec..0000000000000000000000000000000000000000 --- a/mcs/modules/remoteproc_module.c +++ /dev/null @@ -1,133 +0,0 @@ -#include -#include -#include -#include -#include "remoteproc_module.h" -#include "openamp_module.h" - -#define MCS_DEVICE_NAME "/dev/mcs" -#define IOC_CPUON _IOW('A', 1, int) -#define IOC_AFFINITY_INFO _IOW('A', 2, int) -#define STR_TO_HEX 16 -#define STR_TO_DEC 10 - -struct rproc_priv { - struct remoteproc *rproc; /* pass a remoteproc instance pointer */ - unsigned int idx; /* remoteproc instance idx */ - unsigned int cpu_id; /* related arg: cpu id */ - unsigned int boot_address; /* related arg: boot address(in hex format) */ -}; - -static struct remoteproc rproc_inst; - -static struct remoteproc *rproc_init(struct remoteproc *rproc, - const struct remoteproc_ops *ops, void *args) -{ - struct rproc_priv *priv; - - (void)rproc; - priv = metal_allocate_memory(sizeof(*priv)); - if (!priv) - return NULL; - - memcpy(priv, (struct rproc_priv *)args, sizeof(*priv)); - priv->rproc->ops = ops; - metal_list_init(&priv->rproc->mems); - priv->rproc->priv = priv; - rproc->state = RPROC_READY; - return priv->rproc; -} - -static void rproc_remove(struct remoteproc *rproc) -{ - struct rproc_priv *priv; - - priv = (struct rproc_priv *)rproc->priv; - metal_free_memory(priv); -} - -static int rproc_start(struct remoteproc *rproc) -{ - int ret; - unsigned int boot_args[2]; - struct rproc_priv *args = (struct rproc_priv *)rproc->priv; - - int fd = open(MCS_DEVICE_NAME, O_RDWR); - if (fd < 0) { - printf("failed to open %s device.\n", MCS_DEVICE_NAME); - return fd; - } - - boot_args[0] = args->cpu_id; - boot_args[1] = args->boot_address; - ret = ioctl(fd, IOC_CPUON, boot_args); - if (ret) { - printf("boot clientos failed\n"); - return ret; - } - - close(fd); - return 0; -} - -static int rproc_stop(struct remoteproc *rproc) -{ - /* TODO: send order to clientos by RPC service, clientos shut itself down by PSCI */ - send_message("shutdown", sizeof("shutdown")); - - return 0; -} - -const struct remoteproc_ops rproc_ops = { - .init = rproc_init, - .remove = rproc_remove, - .start = rproc_start, - .stop = rproc_stop, -}; - -struct remoteproc *create_remoteproc(void) -{ - struct remoteproc *rproc; - struct rproc_priv args; - - args.rproc = &rproc_inst; - args.idx = 1; - args.cpu_id = strtol(cpu_id, NULL, STR_TO_DEC); - args.boot_address = strtol(target_binaddr, NULL, STR_TO_HEX); - rproc = remoteproc_init(&rproc_inst, &rproc_ops, &args); - if (!rproc) - return NULL; - - return rproc; -} - -void destory_remoteproc(void) -{ - remoteproc_stop(&rproc_inst); - rproc_inst.state = RPROC_OFFLINE; - if (rproc_inst.priv) - remoteproc_remove(&rproc_inst); -} - -int acquire_cpu_state(void) -{ - int ret; - int fd; - unsigned int state_arg; - - fd = open(MCS_DEVICE_NAME, O_RDWR); - if (fd < 0) { - printf("open %s device failed\n", MCS_DEVICE_NAME); - return fd; - } - - state_arg = strtol(cpu_id, NULL, STR_TO_DEC); - ret = ioctl(fd, IOC_AFFINITY_INFO, &state_arg); - if (ret) { - printf("acquire cpu state failed\n"); - return ret; - } - - close(fd); - return state_arg; /* secondary core power state */ -} diff --git a/mcs/modules/remoteproc_module.h b/mcs/modules/remoteproc_module.h deleted file mode 100644 index 6b0a6ae2f36cf23f398d194b116c488bcf102caf..0000000000000000000000000000000000000000 --- a/mcs/modules/remoteproc_module.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef REMOTEPROC_MODULE_H -#define REMOTEPROC_MODULE_H - -#include - -#define CPU_STATE_ON 0 -#define CPU_STATE_OFF 1 -#define CPU_STATE_ON_PENDING 2 - -/* create remoteproc */ -struct remoteproc *create_remoteproc(void); - -/* - start remoteproc: refet to - int remoteproc_start(struct remoteproc *rproc); -*/ - -/* - stop remoteproc: refet to - int remoteproc_stop(struct remoteproc *rproc); -*/ - -/* - remove remoteproc: refet to - int remoteproc_remove(struct remoteproc *rproc); -*/ - -/* destory remoteproc */ -void destory_remoteproc(void); - -/* acquire cpu power state */ -int acquire_cpu_state(void); - -extern char *cpu_id; -extern char *target_binaddr; - -#endif \ No newline at end of file diff --git a/mcs/modules/rpmsg_module.c b/mcs/modules/rpmsg_module.c deleted file mode 100644 index 9b1a78b24781230f80fbd5945d6666e9db555a07..0000000000000000000000000000000000000000 --- a/mcs/modules/rpmsg_module.c +++ /dev/null @@ -1,173 +0,0 @@ -#include -#include -#include -#include -#include "virtio_module.h" -#include "rpmsg_module.h" - -#define MCS_DEVICE_NAME "/dev/mcs" - -/* endpoint state */ -#define ENDPOINT_BOUND 0 -#define ENDPOINT_NOT_FOUND -1 -#define ENDPOINT_UNKNOWN_STATE -2 - -struct endpoint_priv { - unsigned char received_data[2048]; - unsigned int received_len; -}; - -/* TODO: endpoint ability negotiation */ -char ept_name[RPMSG_NAME_SIZE]; - -/* add more parameters such as dest_addr, when there are several clientos */ -static struct rpmsg_endpoint* obtain_endpoint(const char *name) -{ - struct metal_list *node; - struct rpmsg_endpoint *ept; - - metal_list_for_each(&rdev->endpoints, node) { - ept = metal_container_of(node, struct rpmsg_endpoint, node); - if (!strncmp(ept->name, name, sizeof(ept->name))) - return ept; - } - - return NULL; -} - -static int check_endpoint(const char *name) -{ - struct rpmsg_endpoint *ept = obtain_endpoint(name); - if (!ept) { - return ENDPOINT_NOT_FOUND; - } - - if ((ept->addr != RPMSG_ADDR_ANY) && (ept->dest_addr != RPMSG_ADDR_ANY)) - return ENDPOINT_BOUND; - - return ENDPOINT_UNKNOWN_STATE; -} - -static int endpoint_cb(struct rpmsg_endpoint *ept, void *data, - size_t len, uint32_t src, void *priv) -{ - /* put data into endpoint's priv buffer, do not cover. - user call receive_message of this endpoint will read and clear the buffer */ - struct endpoint_priv *p = priv; - - memcpy(p->received_data + p->received_len, data, len); - p->received_len += len; - - return RPMSG_SUCCESS; -} - -static void rpmsg_service_unbind(struct rpmsg_endpoint *ept) -{ - rpmsg_destroy_ept(ept); -} - -void destroy_endpoint(const char *name) -{ - struct rpmsg_endpoint *ept = obtain_endpoint(name); - rpmsg_destroy_ept(ept); - free(ept->priv); - free(ept); -} - -void ns_bind_cb(struct rpmsg_device *rdev, const char *name, uint32_t dest) -{ - strncpy(ept_name, name ? name : "", RPMSG_NAME_SIZE); - - /* endpoint_cb can be defined by user */ - struct rpmsg_endpoint *ept = malloc(sizeof(struct rpmsg_endpoint)); - ept->priv = malloc(sizeof(struct endpoint_priv)); - (void)rpmsg_create_ept(ept, rdev, ept_name, RPMSG_ADDR_ANY, dest, endpoint_cb, rpmsg_service_unbind); -} - -static void *rpmsg_receive_message(void *arg) -{ - int ret; - int dev_fd; - struct pollfd fds; - - dev_fd = open(MCS_DEVICE_NAME, O_RDWR); - if (dev_fd < 0) { - printf("rpmsg_receive_message: open %s device failed.\n", MCS_DEVICE_NAME); - return (void*)-1; - } - - fds.fd = dev_fd; - fds.events = POLLIN; - - while (1) { -#ifdef DEBUG - printf("master waiting for message....\n"); -#endif - ret = poll(&fds, 1, -1); - if (ret < 0) { - printf("rpmsg_receive_message: poll failed.\n"); - goto _cleanup; - } - - if (fds.revents & POLLIN) { -#ifdef DEBUG - printf("master receiving message....\n"); -#endif - virtqueue_notification(vq[0]); /* will call endpoint_cb or ns_bind_cb */ - } - } - -_cleanup: - close(dev_fd); - return (void*)0; -} - -int receive_message(unsigned char *message, int message_len, int *real_len) -{ - struct rpmsg_endpoint *ept = obtain_endpoint(ept_name); - if (!ept) { - printf("receive_message: no endpoint to receive message.\n"); - return -1; - } - - struct endpoint_priv *data = ept->priv; - if (data->received_len > message_len) { - printf("receive_message: buffer is too small. received_len:%d\n", data->received_len); - return -1; - } - if (!message) - return -1; - - /* copy buffer to message */ - memset(message, 0, message_len); - memcpy(message, data->received_data, data->received_len); - *real_len = data->received_len; - - /* clear buffer */ - memset(data->received_data, 0, sizeof(data->received_data)); - data->received_len = 0; - - return 0; -} - -int send_message(unsigned char *message, int len) -{ - /* ensure endpoint is bound, sleep to wait */ - while (check_endpoint(ept_name) != ENDPOINT_BOUND) - usleep(1000); - - struct rpmsg_endpoint *ept = obtain_endpoint(ept_name); - return rpmsg_send(ept, message, len); -} - -void rpmsg_module_init(void) -{ - pthread_t tid; - - /* deal with messages received from clientos */ - if (pthread_create(&tid, NULL, rpmsg_receive_message, NULL) < 0) { - perror("rpmsg_receive_message pthread_create"); - return; - } - pthread_detach(tid); -} diff --git a/mcs/modules/rpmsg_module.h b/mcs/modules/rpmsg_module.h deleted file mode 100644 index 93fb5c859d2edc88d0ad0fd76e9f6fcaf55832ef..0000000000000000000000000000000000000000 --- a/mcs/modules/rpmsg_module.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef RPMSG_MODULE_H -#define RPMSG_MODULE_H - -#include - -/* endpoint name */ -#define CONSOLE_ENDPOINT "console_ept" -#define LOG_ENDPOINT "log_ept" -#define SHELL_ENDPOINT "shell_ept" - -/* name service callback: create matching endpoint */ -void ns_bind_cb(struct rpmsg_device *rdev, const char *name, uint32_t dest); - -/* destroy endpoint and inform clientos to destroy */ -void destroy_endpoint(const char *name); - -void rpmsg_module_init(void); - -#endif \ No newline at end of file diff --git a/mcs/modules/virtio_module.c b/mcs/modules/virtio_module.c deleted file mode 100644 index 4e5d5811346cd0ed95ed95364273266f95386d7c..0000000000000000000000000000000000000000 --- a/mcs/modules/virtio_module.c +++ /dev/null @@ -1,134 +0,0 @@ -#include -#include -#include -#include -#include "rpmsg_module.h" -#include "virtio_module.h" - -#define IOC_SENDIPI _IOW('A', 0, int) -#define MCS_DEVICE_NAME "/dev/mcs" -#define STR_TO_DEC 10 - -static struct virtio_vring_info rvrings[2] = { - [0] = { - .info.align = VRING_ALIGNMENT, - }, - [1] = { - .info.align = VRING_ALIGNMENT, - }, -}; - -static struct virtio_device vdev; -static struct rpmsg_virtio_device rvdev; -static struct metal_io_region *io; -struct virtqueue *vq[2]; -static metal_phys_addr_t shm_physmap[] = { SHM_START_ADDR }; -struct rpmsg_device *rdev; - -static unsigned char virtio_get_status(struct virtio_device *vdev) -{ - return VIRTIO_CONFIG_STATUS_DRIVER_OK; -} - -static void virtio_set_status(struct virtio_device *vdev, unsigned char status) -{ - *(volatile unsigned int *)VDEVADDR(shmaddr) = (unsigned int)status; -} - -static uint32_t virtio_get_features(struct virtio_device *vdev) -{ - return 1 << VIRTIO_RPMSG_F_NS; -} - -static void virtio_notify(struct virtqueue *vq) -{ - (void)vq; - int cpu_handler_fd; - int ret; - - cpu_handler_fd = open(MCS_DEVICE_NAME, O_RDWR); - if (cpu_handler_fd < 0) { - printf("open %s device failed\n", MCS_DEVICE_NAME); - return; - } - - ret = ioctl(cpu_handler_fd, IOC_SENDIPI, strtol(cpu_id, NULL, STR_TO_DEC)); - if (ret) { - printf("send ipi tp second os failed\n"); - } - - close(cpu_handler_fd); - return; -} - -struct virtio_dispatch dispatch = { - .get_status = virtio_get_status, - .set_status = virtio_set_status, - .get_features = virtio_get_features, - .notify = virtio_notify, -}; - -static struct rpmsg_virtio_shm_pool shpool; - -void virtio_init(void) -{ - int status = 0; - - printf("\nInitialize the virtio, virtqueue and rpmsg device\n"); - - io = malloc(sizeof(struct metal_io_region)); - if (!io) { - printf("malloc io failed\n"); - return; - } - metal_io_init(io, SHMEMADDR(shmaddr), shm_physmap, SHM_SIZE, -1, 0, NULL); - - /* setup vdev */ - vq[0] = virtqueue_allocate(VRING_SIZE); - if (vq[0] == NULL) { - printf("virtqueue_allocate failed to alloc vq[0]\n"); - free(io); - return; - } - vq[1] = virtqueue_allocate(VRING_SIZE); - if (vq[1] == NULL) { - printf("virtqueue_allocate failed to alloc vq[1]\n"); - free(io); - return; - } - - vdev.role = RPMSG_HOST; - vdev.vrings_num = VRING_COUNT; - vdev.func = &dispatch; - rvrings[0].io = io; - rvrings[0].info.vaddr = TXADDR(shmaddr); - rvrings[0].info.num_descs = VRING_SIZE; - rvrings[0].info.align = VRING_ALIGNMENT; - rvrings[0].vq = vq[0]; - - rvrings[1].io = io; - rvrings[1].info.vaddr = RXADDR(shmaddr); - rvrings[1].info.num_descs = VRING_SIZE; - rvrings[1].info.align = VRING_ALIGNMENT; - rvrings[1].vq = vq[1]; - - vdev.vrings_info = &rvrings[0]; - - /* setup rvdev */ - rpmsg_virtio_init_shm_pool(&shpool, SHMEMADDR(shmaddr), SHM_SIZE); - status = rpmsg_init_vdev(&rvdev, &vdev, ns_bind_cb, io, &shpool); - if (status != 0) { - printf("rpmsg_init_vdev failed %d\n", status); - free(io); - return; - } - - rdev = rpmsg_virtio_get_rpmsg_device(&rvdev); -} - -void virtio_deinit(void) -{ - rpmsg_deinit_vdev(&rvdev); - if (io) - free(io); -} diff --git a/mcs/modules/virtio_module.h b/mcs/modules/virtio_module.h deleted file mode 100644 index e8db457214a5cbe85afad6241ae20542a7daa12a..0000000000000000000000000000000000000000 --- a/mcs/modules/virtio_module.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef VIRTIO_MODULE_H -#define VIRTIO_MODULE_H - -#include -#include - -#define VDEV_START_ADDR 0x70000000 -#define VDEV_SIZE 0x30000 - -#define VDEV_STATUS_ADDR VDEV_START_ADDR -#define VDEV_STATUS_SIZE 0x4000 - -#define SHM_START_ADDR (VDEV_START_ADDR + VDEV_STATUS_SIZE) -#define SHM_SIZE (VDEV_SIZE - VDEV_STATUS_SIZE) - -#define VRING_COUNT 2 -#define VRING_RX_ADDRESS (VDEV_START_ADDR + SHM_SIZE - VDEV_STATUS_SIZE) -#define VRING_TX_ADDRESS (VDEV_START_ADDR + SHM_SIZE) -#define VRING_ALIGNMENT 4 -#define VRING_SIZE 16 - -#define TXADDR(SHMADDR) (SHMADDR + VRING_TX_ADDRESS - VDEV_START_ADDR) -#define RXADDR(SHMADDR) (SHMADDR + VRING_RX_ADDRESS - VDEV_START_ADDR) -#define VDEVADDR(SHMADDR) (SHMADDR + VDEV_STATUS_ADDR - VDEV_START_ADDR) -#define SHMEMADDR(SHMADDR) (SHMADDR + SHM_START_ADDR - VDEV_START_ADDR) - -void virtio_init(void); -void virtio_deinit(void); - -extern char *cpu_id; -extern struct virtqueue *vq[2]; -extern void *shmaddr; -extern struct rpmsg_device *rdev; - -#endif \ No newline at end of file diff --git a/mcs/openamp_demo/rpmsg_main.c b/mcs/openamp_demo/rpmsg_main.c deleted file mode 100644 index 59d0258fa04ba9250dab9fcb9a2067344b670c05..0000000000000000000000000000000000000000 --- a/mcs/openamp_demo/rpmsg_main.c +++ /dev/null @@ -1,85 +0,0 @@ -#include -#include -#include "openamp_module.h" - -char *cpu_id; -char *target_binfile; -char *target_binaddr; - -static void cleanup(int sig) -{ - openamp_deinit(); - exit(0); -} - -int rpmsg_app_master(void) -{ - int ret; - int message = 10; - int len; - - printf("start processing OpenAMP demo...\n"); - - while (message < 99) { - ret = send_message((unsigned char*)&message, sizeof(message)); - if (ret < 0) { - printf("send_message(%u) failed with status %d\n", message, ret); - return ret; - } - sleep(1); - - ret = receive_message((unsigned char*)&message, sizeof(message), &len); - if (ret < 0) { - printf("receive_message failed with status %d\n", ret); - return ret; - } - printf("Master core received a message: %u\n", message); - message++; - sleep(1); - } - - return 0; -} - -int main(int argc, char **argv) -{ - int ret; - int opt; - - /* ctrl+c signal, do cleanup before program exit */ - signal(SIGINT, cleanup); - - while ((opt = getopt(argc, argv, "c:t:a:")) != -1) { - switch (opt) { - case 'c': - cpu_id = optarg; - break; - case 't': - target_binfile = optarg; - break; - case 'a': - target_binaddr = optarg; - break; - default: - break; - } - } - - ret = openamp_init(); - if (ret) { - printf("openamp init failed: %d\n", ret); - openamp_deinit(); - return ret; - } - - ret = rpmsg_app_master(); - if (ret) { - printf("rpmsg app master failed: %d\n", ret); - openamp_deinit(); - return ret; - } - - openamp_deinit(); - - return 0; -} diff --git a/mcs/openamp_demo/zephyr_qemu.bin b/mcs/openamp_demo/zephyr_qemu.bin deleted file mode 100644 index 457b597f7230ab5f7ebec7ca1e0d2d2dec25fc30..0000000000000000000000000000000000000000 Binary files a/mcs/openamp_demo/zephyr_qemu.bin and /dev/null differ diff --git a/mcs/openamp_demo/zephyr_rpi.bin b/mcs/openamp_demo/zephyr_rpi.bin deleted file mode 100644 index 5dcb9d9d185945fbb78cecaac70cfb103dc3f445..0000000000000000000000000000000000000000 Binary files a/mcs/openamp_demo/zephyr_rpi.bin and /dev/null differ diff --git a/mcs/openamp_demo_proc_ptyshell/Makefile b/mcs/openamp_demo_proc_ptyshell/Makefile deleted file mode 100644 index 5907eef3d33477956c9caccd9ba92cf3783c9521..0000000000000000000000000000000000000000 --- a/mcs/openamp_demo_proc_ptyshell/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -rpmsg_main: rpmsg_main.o rpmsg_linux_endpoint.o rpmsg_rtos_endpoint.o - $(CC) rpmsg_main.o rpmsg_linux_endpoint.o rpmsg_rtos_endpoint.o -g $(SDKTARGETSYSROOT)/usr/lib64/libmetal.so $(SDKTARGETSYSROOT)/usr/lib64/libopen_amp.so $(SDKTARGETSYSROOT)/lib64/libsysfs.so -o rpmsg_main - -rpmsg_main.o: rpmsg_main.c rpmsg-internal.h - $(CC) -g -I$(SDKTARGETSYSROOT)/usr/include -c rpmsg_main.c -o rpmsg_main.o - -rpmsg_linux_endpoint.o: rpmsg_linux_endpoint.c rpmsg-internal.h - $(CC) -g -I$(SDKTARGETSYSROOT)/usr/include -c rpmsg_linux_endpoint.c -o rpmsg_linux_endpoint.o - -rpmsg_rtos_endpoint.o: rpmsg_rtos_endpoint.c - $(CC) -g -I$(SDKTARGETSYSROOT)/usr/include -c rpmsg_rtos_endpoint.c -o rpmsg_rtos_endpoint.o - -clean: - rm -rf *.o rpmsg_main diff --git a/mcs/openamp_demo_proc_ptyshell/rpmsg-internal.h b/mcs/openamp_demo_proc_ptyshell/rpmsg-internal.h deleted file mode 100644 index 82ce62eb0d5b59d1b729ff4a9515c56fe3c77b9d..0000000000000000000000000000000000000000 --- a/mcs/openamp_demo_proc_ptyshell/rpmsg-internal.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef RPMSG_INTERNAL_H_ -#define RPMSG_INTERNAL_H_ - -#include -#include -#include - -#define SHM_START_ADDR 0x70000000 -#define SHM_SIZE 0x30000 - -#define VRING_ADDR_SIZE 0x4000 -#define VRING_RX_ADDRESS (SHM_START_ADDR + SHM_SIZE) -#define VRING_TX_ADDRESS (VRING_RX_ADDRESS + VRING_ADDR_SIZE) -#define RTOS_VRING_RX_ADDRESS VRING_TX_ADDRESS -#define RTOS_VRING_TX_ADDRESS VRING_RX_ADDRESS - -#define VRING_COUNT 2 -#define VRING_ALIGNMENT 4 -#define VRING_SIZE 16 - -#define RSC_TABLE_ADDR 0x71000000 - -#define VDEV_NOTIFY_ID 0 -#define VRING_RX_NOTIFY_ID 1 -#define VRING_TX_NOTIFY_ID 2 - -struct rproc_priv { - struct remoteproc *rproc; - unsigned int id; -}; - -#define NO_RESOURCE_ENTRIES 8 - -/* Resource table for the given remote */ -struct remote_resource_table { - unsigned int version; - unsigned int num; - unsigned int reserved[2]; - unsigned int offset[NO_RESOURCE_ENTRIES]; - - /* 1. rpmsg buffer mem entry */ - struct fw_rsc_carveout rpmsg_mem; - - /* 2. rpmsg vdev entry */ - struct fw_rsc_vdev rpmsg_vdev; - struct fw_rsc_vdev_vring rpmsg_vring0; - struct fw_rsc_vdev_vring rpmsg_vring1; -} __attribute__((__packed__)); - -extern int pipefd1[2]; -extern int pipefd2[2]; - -void *get_resource_table(int *len); - -#endif diff --git a/mcs/openamp_demo_proc_ptyshell/rpmsg_linux_endpoint.c b/mcs/openamp_demo_proc_ptyshell/rpmsg_linux_endpoint.c deleted file mode 100644 index 7d56db467da11c9d5b197f39e4a248ab4a136135..0000000000000000000000000000000000000000 --- a/mcs/openamp_demo_proc_ptyshell/rpmsg_linux_endpoint.c +++ /dev/null @@ -1,332 +0,0 @@ -/* Linux Endpoint run in parent process, isolate with child process */ - -#include -#define __USE_XOPEN_EXTENDED -#define __USE_XOPEN2KXSI -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "rpmsg-internal.h" - -static volatile unsigned int received_data; -static struct rpmsg_virtio_shm_pool shpool; //tmp, must be global var -static struct rpmsg_endpoint linux_ept; //tmp, must be global var - -static struct remoteproc *rproc_init(struct remoteproc *rproc, - struct remoteproc_ops *ops, void *arg) -{ - struct rproc_priv *priv; - unsigned int id = *((unsigned int *)arg); - - priv = metal_allocate_memory(sizeof(*priv)); - if (!priv) - return NULL; - - memset(priv, 0, sizeof(*priv)); - priv->rproc = rproc; - priv->id = id; - priv->rproc->ops = ops; - metal_list_init(&priv->rproc->mems); - priv->rproc->priv = priv; - rproc->state = RPROC_READY; - return priv->rproc; -} - -static void rproc_remove(struct remoteproc *rproc) -{ - struct rproc_priv *priv; - - priv = (struct rproc_priv *)rproc->priv; - metal_free_memory(priv); -} - -static void *rproc_mmap(struct remoteproc *rproc, - metal_phys_addr_t *pa, metal_phys_addr_t *da, - size_t size, unsigned int attribute, - struct metal_io_region **io) -{ - struct remoteproc_mem *mem; - struct metal_io_region *tmpio; - - if (*pa == METAL_BAD_PHYS && *da == METAL_BAD_PHYS) - return NULL; - if (*pa == METAL_BAD_PHYS) - *pa = *da; - if (*da == METAL_BAD_PHYS) - *da = *pa; - - mem = metal_allocate_memory(sizeof(*mem)); - if (!mem) - return NULL; - tmpio = metal_allocate_memory(sizeof(*tmpio)); - if (!tmpio) { - metal_free_memory(mem); - return NULL; - } - - /* mmap pa to va */ - int memfd; - void *va; - memfd = open("/dev/mem", O_RDWR); - va = mmap((void*)pa, size, PROT_READ | PROT_WRITE, MAP_SHARED, memfd, *pa); - - remoteproc_init_mem(mem, NULL, *pa, *da, size, tmpio); - metal_io_init(tmpio, va, &mem->pa, size, -1, attribute, NULL); /* metal io manage va and pa */ - remoteproc_add_mem(rproc, mem); - if (io) - *io = tmpio; - - printf("master mmap pa=0x%lx, da=0x%lx, size=0x%lx, attribute=0x%x va=%p\n", *pa, *da, size, attribute, va); - - return metal_io_phys_to_virt(tmpio, mem->pa); -} - -//master tmp -static int rproc_notify_tmp(struct remoteproc *rproc, uint32_t id) -{ - return 0; -} - -static int rproc_notify(struct remoteproc *rproc, uint32_t id) -{ - int ret; - - printf("master notify start\n"); - - /* notify RTOS Endpoint using IPC */ - ret = write(pipefd1[1], "Linux: notify ipi\n", strlen("Linux: notify ipi\n")); - if (ret == -1) - perror("master write pipefd1[1]"); - - return 0; -} - -static struct remoteproc_ops rproc_ops = { - .init = rproc_init, - .remove = rproc_remove, - .mmap = rproc_mmap, - .notify = rproc_notify_tmp, //master tmp -}; - -static unsigned int receive_message(struct remoteproc *rproc) -{ - char buf[50] = {0}; - int ret; - - /* 1. poll and wait for IPI(IPC) from RTOS Endpoint */ - while (read(pipefd2[0], buf, sizeof(buf)) > 0) { - printf("master poll:%s", buf); - if (strcmp(buf, "RTOS: notify ipi\n") == 0) - break; - } - - /* 2. receive data */ - ret = remoteproc_get_notification(rproc, VRING_RX_NOTIFY_ID); - if (ret) - printf("remoteproc_get_notification failed: 0x%x\n", ret); - return received_data; -} - -static int endpoint_cb(struct rpmsg_endpoint *ept, void *data, - size_t len, uint32_t src, void *priv) -{ - received_data = *((unsigned int *) data); - return RPMSG_SUCCESS; -} - -static void rpmsg_service_unbind(struct rpmsg_endpoint *ept) -{ - rpmsg_destroy_ept(ept); -} - -static void ns_bind_cb(struct rpmsg_device *rdev, const char *name, uint32_t dest) -{ - (void)rpmsg_create_ept(&linux_ept, rdev, name, - RPMSG_ADDR_ANY, dest, - endpoint_cb, - rpmsg_service_unbind); -} - -static int send_message(unsigned int message, struct rpmsg_endpoint *ept) -{ - return rpmsg_send(ept, &message, sizeof(message)); -} - -static struct remoteproc *platform_create_proc(unsigned int id) -{ - struct remoteproc *rproc; - struct remoteproc rproc_inst; - void *va; - void *rsc; - int ret; - metal_phys_addr_t pa = RSC_TABLE_ADDR; - int rsc_size; - - /* Initialize remoteproc instance */ - rproc = remoteproc_init(&rproc_inst, &rproc_ops, &id); - if (!rproc) - return NULL; - - /* mmap resource table */ - rsc = get_resource_table(&rsc_size); - va = remoteproc_mmap(rproc, &pa, NULL, rsc_size, 0, NULL); - memcpy(va, rsc, rsc_size); - - /* parse resource table to remoteproc */ - ret = remoteproc_set_rsc_table(rproc, va, rsc_size); - if (ret) { - printf("Failed to initialize remoteproc, ret:0x%x\n", ret); - remoteproc_remove(rproc); - return NULL; - } - - //tmp - struct remote_resource_table *va_tmp = va; - struct remote_resource_table *rsc_tmp = rsc; - va_tmp->rpmsg_vdev.notifyid = rsc_tmp->rpmsg_vdev.notifyid; - va_tmp->rpmsg_vdev.vring[0].notifyid = rsc_tmp->rpmsg_vdev.vring[0].notifyid; - va_tmp->rpmsg_vdev.vring[1].notifyid = rsc_tmp->rpmsg_vdev.vring[1].notifyid; - - printf("(1)master platform_create_proc success\n"); - - return rproc; -} - -static struct rpmsg_device *platform_create_rpmsg_vdev(struct remoteproc *rproc) -{ - struct rpmsg_virtio_device rpmsg_vdev; - struct virtio_device *vdev; - void *shbuf; - struct metal_io_region *shbuf_io; - int ret; - - shbuf_io = remoteproc_get_io_with_pa(rproc, SHM_START_ADDR); - if (!shbuf_io) - return NULL; - shbuf = metal_io_phys_to_virt(shbuf_io, SHM_START_ADDR); - - printf("(2)master creating remoteproc virtio\n"); - vdev = remoteproc_create_virtio(rproc, 0, RPMSG_MASTER, NULL); - if (!vdev) { - printf("failed remoteproc_create_virtio\n"); - return NULL; - } - - printf("(3)master initializing rpmsg shared buffer pool\n"); - /* Only RPMsg virtio master needs to initialize the shared buffers pool */ - rpmsg_virtio_init_shm_pool(&shpool, shbuf, SHM_SIZE); - - printf("(4)master initializing rpmsg vdev\n"); - /* RPMsg virtio slave can set shared buffers pool argument to NULL */ - ret = rpmsg_init_vdev(&rpmsg_vdev, vdev, ns_bind_cb, shbuf_io, &shpool); - if (ret) { - printf("failed rpmsg_init_vdev\n"); - remoteproc_remove_virtio(rproc, vdev); - return NULL; - } - - //printf("master vq[0].callback:%p, vq[1].callback:%p\n", vdev->vrings_info[0].vq->callback, vdev->vrings_info[1].vq->callback); - - printf("(5)master returning rdev\n"); - return rpmsg_virtio_get_rpmsg_device(&rpmsg_vdev); -} - -static void rpmsg_app_master(struct remoteproc *rproc, int fdm) -{ - int status = 0; - unsigned int message; - - //tmp - /* register notify function */ - rproc->ops->notify = rproc_notify; - - /* 1.2 master receive NS Announcement, and process it */ - receive_message(rproc); - - printf("1.2 master receive_message succeed\n"); - printf("1.2 master Endpoint: name:%s, addr:0x%x, dest_addr:0x%x\n", linux_ept.name, linux_ept.addr, linux_ept.dest_addr); - - char buffer[256] = {0}; - while (read(fdm, buffer, sizeof(buffer)) > 0) { - message = atoi(buffer); - /* 2. master send message */ - status = send_message(message, &linux_ept); - if (status < 0) - printf("send_message(%u) failed with status %d\n", message, status); - printf("2. master send_message succeed\n"); - - /* 5. master receive message */ - message = receive_message(rproc); - printf("5. Master core received a message: %u\n\n", message); - snprintf(buffer, sizeof(buffer), "%d\n", message); - status = write(fdm, buffer, strlen(buffer)); - if (status == -1) - perror("master write fdm"); - } -} - -void open_pty(int *pfdm, int *pfds) -{ - int ret, fdm, fds; - struct termios tty = {0}; - - /* Open the master side of the PTY */ - fdm = posix_openpt(O_RDWR | O_NOCTTY); - if (fdm < 0) - printf("Error %d on posix_openpt()\n", errno); - - ret = grantpt(fdm); - if (ret != 0) - printf("Error %d on grantpt()\n", errno); - - ret = unlockpt(fdm); - if (ret != 0) - printf("Error %d on unlockpt()\n", errno); - - /* Open the slave side of the PTY */ - fds = open(ptsname(fdm), O_RDWR | O_NOCTTY); - - /* Set the state of fds to TERMIOS_P */ - tty.c_cflag = CS8; - tcsetattr(fds, TCSAFLUSH, &tty); - - *pfdm = fdm; - *pfds = fds; -} - -int rpmsg_linux_endpoint() -{ - struct remoteproc *rproc = NULL; - unsigned int id = 1; - struct rpmsg_device *rdev = NULL; - int fdm, fds; - - open_pty(&fdm, &fds); - - /* create remoteproc */ - rproc = platform_create_proc(id); - if (!rproc) { - printf("create rproc failed\n"); - return -1; - } - - rdev = platform_create_rpmsg_vdev(rproc); - if (!rdev) - printf("master create rpmsg vdev failed\n"); - - rpmsg_app_master(rproc, fdm); - //remoteproc_remove(rproc); - - return 0; -} diff --git a/mcs/openamp_demo_proc_ptyshell/rpmsg_main.c b/mcs/openamp_demo_proc_ptyshell/rpmsg_main.c deleted file mode 100644 index ac08fba1f902f95cd535c2c9ea6a52bfd6ef22bd..0000000000000000000000000000000000000000 --- a/mcs/openamp_demo_proc_ptyshell/rpmsg_main.c +++ /dev/null @@ -1,76 +0,0 @@ -#include -#include -#include -#include - -#include "rpmsg-internal.h" - -int pipefd1[2]; -int pipefd2[2]; - -/* Place resource table in special ELF section */ -#define __section_t(S) __attribute__((__section__(#S))) -#define __resource __section_t(.resource_table) - -#define NUM_TABLE_ENTRIES 2 -#define DFEATURE_SUPPORT_NS 1 - -struct remote_resource_table __resource resources = { - /* Version */ - RSC_TAB_SUPPORTED_VERSION, - /* NUmber of table entries */ - NUM_TABLE_ENTRIES, - /* reserved fields */ - { 0, 0 }, - /* Offsets of rsc entries */ - { - offsetof(struct remote_resource_table, rpmsg_mem), - offsetof(struct remote_resource_table, rpmsg_vdev), - }, - - /* 1. Rpmsg buffer memory entry including vring TX/RX memory */ - { RSC_CARVEOUT, SHM_START_ADDR, SHM_START_ADDR, SHM_SIZE, 0 }, - - /* 2. Virtio device entry */ - { RSC_VDEV, VIRTIO_ID_RPMSG, VDEV_NOTIFY_ID, DFEATURE_SUPPORT_NS, 0, 0, 0, VRING_COUNT, { 0, 0 } }, - /* Vring rsc entry - part of vdev rsc entry */ - { VRING_RX_ADDRESS, VRING_ALIGNMENT, VRING_SIZE, VRING_RX_NOTIFY_ID, 0 }, /* VRING_RX */ - { VRING_TX_ADDRESS, VRING_ALIGNMENT, VRING_SIZE, VRING_TX_NOTIFY_ID, 0 }, /* VRING_TX */ -}; - -void *get_resource_table(int *len) -{ - *len = sizeof(resources); - return &resources; -} - -extern int rpmsg_linux_endpoint(); -extern int rpmsg_rtos_endpoint(); - -int main(int argc, char **argv) -{ - pid_t pid; - - /* Create unamed pipe */ - if (pipe(pipefd1) < 0) { - perror("pipe1"); - return -1; - } - if (pipe(pipefd2) < 0) { - perror("pipe2"); - return -1; - } - - if ((pid = fork()) < 0) { - perror("fork"); - return -1; - } else if (pid > 0) { - /* parent: Linux Endpoint */ - rpmsg_linux_endpoint(); - } else { - /* child: RTOS Endpoint */ - rpmsg_rtos_endpoint(); - } - - return 0; -} diff --git a/mcs/openamp_demo_proc_ptyshell/rpmsg_rtos_endpoint.c b/mcs/openamp_demo_proc_ptyshell/rpmsg_rtos_endpoint.c deleted file mode 100644 index 7094b436f86ed42e94bf38fd384e533c341826ec..0000000000000000000000000000000000000000 --- a/mcs/openamp_demo_proc_ptyshell/rpmsg_rtos_endpoint.c +++ /dev/null @@ -1,272 +0,0 @@ -/* RTOS Endpoint run in child process, isolate with parent process */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "rpmsg-internal.h" - -static volatile unsigned int rtos_received_data; - -static struct remoteproc *rtos_rproc_init(struct remoteproc *rproc, - struct remoteproc_ops *ops, void *arg) -{ - struct rproc_priv *priv; - unsigned int id = *((unsigned int *)arg); - - priv = metal_allocate_memory(sizeof(*priv)); - if (!priv) - return NULL; - - memset(priv, 0, sizeof(*priv)); - priv->rproc = rproc; - priv->id = id; - priv->rproc->ops = ops; - metal_list_init(&priv->rproc->mems); - priv->rproc->priv = priv; - rproc->state = RPROC_READY; - return priv->rproc; -} - -static void rtos_rproc_remove(struct remoteproc *rproc) -{ - struct rproc_priv *priv; - - priv = (struct rproc_priv *)rproc->priv; - metal_free_memory(priv); -} - -static void *rtos_rproc_mmap(struct remoteproc *rproc, - metal_phys_addr_t *pa, metal_phys_addr_t *da, - size_t size, unsigned int attribute, - struct metal_io_region **io) -{ - struct remoteproc_mem *mem; - struct metal_io_region *tmpio; - - if (*pa == METAL_BAD_PHYS && *da == METAL_BAD_PHYS) - return NULL; - if (*pa == METAL_BAD_PHYS) - *pa = *da; - if (*da == METAL_BAD_PHYS) - *da = *pa; - - mem = metal_allocate_memory(sizeof(*mem)); - if (!mem) - return NULL; - tmpio = metal_allocate_memory(sizeof(*tmpio)); - if (!tmpio) { - metal_free_memory(mem); - return NULL; - } - - /* mmap pa to va */ - int memfd; - void *va; - memfd = open("/dev/mem", O_RDWR); - va = mmap((void*)pa, size, PROT_READ | PROT_WRITE, MAP_SHARED, memfd, *pa); - - remoteproc_init_mem(mem, NULL, *pa, *da, size, tmpio); - metal_io_init(tmpio, va, &mem->pa, size, -1, attribute, NULL); /* metal io manage va and pa */ - remoteproc_add_mem(rproc, mem); - if (io) - *io = tmpio; - - printf("slave mmap pa=0x%lx, da=0x%lx, size=0x%lx, attribute=0x%x va=%p\n", *pa, *da, size, attribute, va); - - return metal_io_phys_to_virt(tmpio, mem->pa); -} - -static int rtos_rproc_notify(struct remoteproc *rproc, uint32_t id) -{ - int ret; - - printf("slave notify start\n"); - - /* notify RTOS Endpoint using IPC */ - ret = write(pipefd2[1], "RTOS: notify ipi\n", strlen("RTOS: notify ipi\n")); - if (ret == -1) - perror("slave write pipefd2[1]"); - - return 0; -} - -static struct remoteproc_ops rtos_rproc_ops = { - .init = rtos_rproc_init, - .remove = rtos_rproc_remove, - .mmap = rtos_rproc_mmap, - .notify = rtos_rproc_notify, -}; - -static unsigned int rtos_receive_message(struct remoteproc *rproc) -{ - char buf[50] = {0}; - int ret; - - /* 1. poll and wait for IPI(IPC) from RTOS Endpoint */ - while (read(pipefd1[0], buf, sizeof(buf)) > 0) { - printf("slave poll:%s", buf); - if (strcmp(buf, "Linux: notify ipi\n") == 0) - break; - } - - /* 2. receive data */ - ret = remoteproc_get_notification(rproc, VRING_TX_NOTIFY_ID); - if (ret) - printf("remoteproc_get_notification failed: 0x%x\n", ret); - return rtos_received_data; -} - -static int rtos_endpoint_cb(struct rpmsg_endpoint *ept, void *data, - size_t len, uint32_t src, void *priv) -{ - rtos_received_data = *((unsigned int *) data); - return RPMSG_SUCCESS; -} - -static void rtos_rpmsg_service_unbind(struct rpmsg_endpoint *ept) -{ - rpmsg_destroy_ept(ept); -} - -static int rtos_send_message(unsigned int message, struct rpmsg_endpoint *ept) -{ - return rpmsg_send(ept, &message, sizeof(message)); -} - -static struct remoteproc *rtos_platform_create_proc(unsigned int id) -{ - struct remoteproc *rproc; - struct remoteproc rproc_inst; - void *va; - void *rsc; - int ret; - metal_phys_addr_t pa = RSC_TABLE_ADDR; - int rsc_size; - - /* Initialize remoteproc instance */ - rproc = remoteproc_init(&rproc_inst, &rtos_rproc_ops, &id); - if (!rproc) - return NULL; - - /* mmap resource table */ - rsc = get_resource_table(&rsc_size); - va = remoteproc_mmap(rproc, &pa, NULL, rsc_size, 0, NULL); - memcpy(va, rsc, rsc_size); - - /* parse resource table to remoteproc */ - ret = remoteproc_set_rsc_table(rproc, va, rsc_size); - if (ret) { - printf("Failed to initialize remoteproc, ret:0x%x\n", ret); - remoteproc_remove(rproc); - return NULL; - } - - //tmp - struct remote_resource_table *va_tmp = va; - struct remote_resource_table *rsc_tmp = rsc; - va_tmp->rpmsg_vdev.notifyid = rsc_tmp->rpmsg_vdev.notifyid; - va_tmp->rpmsg_vdev.vring[0].notifyid = rsc_tmp->rpmsg_vdev.vring[0].notifyid; - va_tmp->rpmsg_vdev.vring[1].notifyid = rsc_tmp->rpmsg_vdev.vring[1].notifyid; - - printf("(1)slave platform_create_proc success\n"); - - return rproc; -} - -static struct rpmsg_device *rtos_platform_create_rpmsg_vdev(struct remoteproc *rproc) -{ - struct rpmsg_virtio_device rpmsg_vdev; - struct virtio_device *vdev; - void *shbuf; - struct metal_io_region *shbuf_io; - int ret; - - shbuf_io = remoteproc_get_io_with_pa(rproc, SHM_START_ADDR); - if (!shbuf_io) - return NULL; - shbuf = metal_io_phys_to_virt(shbuf_io, SHM_START_ADDR); - - printf("(2)slave creating remoteproc virtio\n"); - vdev = remoteproc_create_virtio(rproc, 0, RPMSG_REMOTE, NULL); - if (!vdev) { - printf("failed remoteproc_create_virtio\n"); - return NULL; - } - - printf("(3)slave initializing rpmsg vdev\n"); - /* RPMsg virtio slave can set shared buffers pool argument to NULL */ - ret = rpmsg_init_vdev(&rpmsg_vdev, vdev, NULL, shbuf_io, NULL); - if (ret) { - printf("failed rpmsg_init_vdev\n"); - remoteproc_remove_virtio(rproc, vdev); - return NULL; - } - - //printf("slave vq[0].callback:%p, vq[1].callback:%p\n", vdev->vrings_info[0].vq->callback, vdev->vrings_info[1].vq->callback); - - printf("(4)slave returning rdev\n"); - return rpmsg_virtio_get_rpmsg_device(&rpmsg_vdev); -} - -static void rtos_rpmsg_app_master(struct remoteproc *rproc, struct rpmsg_device *rdev) -{ - int status = 0; - unsigned int message; - struct rpmsg_endpoint ept; - - /* 1.1 slave create endpoint, and send an NS Announcement */ - status = rpmsg_create_ept(&ept, rdev, "k", RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, rtos_endpoint_cb, rtos_rpmsg_service_unbind); - if (status < 0) - printf("slave rpmsg_create_ept failed:%d\n", status); - - printf("1.1 slave rpmsg_create_ept succeed\n"); - printf("1.1 slave Endpoint: name:%s, addr:0x%x, dest_addr:0x%x\n", ept.name, ept.addr, ept.dest_addr); - - while (1) { - /* 3. slave receive message */ - message = rtos_receive_message(rproc); - printf("3. Slave core received a message: %u\n", message); - message++; - printf("3. slave Endpoint: name:%s, addr:0x%x, dest_addr:0x%x\n", ept.name, ept.addr, ept.dest_addr); - - /* 4. slave send message */ - status = rtos_send_message(message, &ept); - if (status < 0) - printf("rtos_send_message(%u) failed with status %d\n", message, status); - printf("4. slave rtos_send_message succeed\n"); - } -} - -int rpmsg_rtos_endpoint() -{ - struct remoteproc *rproc = NULL; - unsigned int id = 1; - struct rpmsg_device *rdev = NULL; - - /* create remoteproc */ - rproc = rtos_platform_create_proc(id); - if (!rproc) { - printf("create rproc failed\n"); - return -1; - } - - rdev = rtos_platform_create_rpmsg_vdev(rproc); - if (!rdev) - printf("slave create rpmsg vdev failed\n"); - - rtos_rpmsg_app_master(rproc, rdev); - //remoteproc_remove(rproc); - - return 0; -} diff --git a/mcs/openamp_demo_proc_rsctbl/Makefile b/mcs/openamp_demo_proc_rsctbl/Makefile deleted file mode 100644 index 5907eef3d33477956c9caccd9ba92cf3783c9521..0000000000000000000000000000000000000000 --- a/mcs/openamp_demo_proc_rsctbl/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -rpmsg_main: rpmsg_main.o rpmsg_linux_endpoint.o rpmsg_rtos_endpoint.o - $(CC) rpmsg_main.o rpmsg_linux_endpoint.o rpmsg_rtos_endpoint.o -g $(SDKTARGETSYSROOT)/usr/lib64/libmetal.so $(SDKTARGETSYSROOT)/usr/lib64/libopen_amp.so $(SDKTARGETSYSROOT)/lib64/libsysfs.so -o rpmsg_main - -rpmsg_main.o: rpmsg_main.c rpmsg-internal.h - $(CC) -g -I$(SDKTARGETSYSROOT)/usr/include -c rpmsg_main.c -o rpmsg_main.o - -rpmsg_linux_endpoint.o: rpmsg_linux_endpoint.c rpmsg-internal.h - $(CC) -g -I$(SDKTARGETSYSROOT)/usr/include -c rpmsg_linux_endpoint.c -o rpmsg_linux_endpoint.o - -rpmsg_rtos_endpoint.o: rpmsg_rtos_endpoint.c - $(CC) -g -I$(SDKTARGETSYSROOT)/usr/include -c rpmsg_rtos_endpoint.c -o rpmsg_rtos_endpoint.o - -clean: - rm -rf *.o rpmsg_main diff --git a/mcs/openamp_demo_proc_rsctbl/rpmsg-internal.h b/mcs/openamp_demo_proc_rsctbl/rpmsg-internal.h deleted file mode 100644 index 9caea59987188981e7e7c11d06a084cbdbf24358..0000000000000000000000000000000000000000 --- a/mcs/openamp_demo_proc_rsctbl/rpmsg-internal.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef RPMSG_INTERNAL_H_ -#define RPMSG_INTERNAL_H_ - -#include -#include -#include - -#define SHM_START_ADDR 0x70000000 -#define SHM_SIZE 0x30000 - -#define VRING_ADDR_SIZE 0x4000 -#define VRING_RX_ADDRESS (SHM_START_ADDR + SHM_SIZE) -#define VRING_TX_ADDRESS (VRING_RX_ADDRESS + VRING_ADDR_SIZE) -#define RTOS_VRING_RX_ADDRESS VRING_TX_ADDRESS -#define RTOS_VRING_TX_ADDRESS VRING_RX_ADDRESS - -#define VRING_COUNT 2 -#define VRING_ALIGNMENT 4 -#define VRING_SIZE 16 - -#define RSC_TABLE_ADDR 0x71000000 - -#define VDEV_NOTIFY_ID 0 -#define VRING_RX_NOTIFY_ID 1 -#define VRING_TX_NOTIFY_ID 2 - -struct rproc_priv { - struct remoteproc *rproc; - unsigned int id; -}; - -#define NO_RESOURCE_ENTRIES 8 - -/* Resource table for the given remote */ -struct remote_resource_table { - unsigned int version; - unsigned int num; - unsigned int reserved[2]; - unsigned int offset[NO_RESOURCE_ENTRIES]; - - /* 1. rpmsg buffer mem entry */ - struct fw_rsc_carveout rpmsg_mem; - - /* 2. rpmsg vdev entry */ - struct fw_rsc_vdev rpmsg_vdev; - struct fw_rsc_vdev_vring rpmsg_vring0; - struct fw_rsc_vdev_vring rpmsg_vring1; -} __attribute__((__packed__)); - -extern int pipefd[2]; - -void *get_resource_table(int *len); - -#endif diff --git a/mcs/openamp_demo_proc_rsctbl/rpmsg_linux_endpoint.c b/mcs/openamp_demo_proc_rsctbl/rpmsg_linux_endpoint.c deleted file mode 100644 index f4463f93bbd25a1dc68e785bb951f2bf99cb4016..0000000000000000000000000000000000000000 --- a/mcs/openamp_demo_proc_rsctbl/rpmsg_linux_endpoint.c +++ /dev/null @@ -1,296 +0,0 @@ -/* Linux Endpoint run in parent process, isolate with child process */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "rpmsg-internal.h" - -static volatile unsigned int received_data; -static struct rpmsg_virtio_shm_pool shpool; //tmp, must be global var -static struct rpmsg_endpoint linux_ept; //tmp, must be global var - -static struct remoteproc *rproc_init(struct remoteproc *rproc, - struct remoteproc_ops *ops, void *arg) -{ - struct rproc_priv *priv; - unsigned int id = *((unsigned int *)arg); - - priv = metal_allocate_memory(sizeof(*priv)); - if (!priv) - return NULL; - - memset(priv, 0, sizeof(*priv)); - priv->rproc = rproc; - priv->id = id; - priv->rproc->ops = ops; - metal_list_init(&priv->rproc->mems); - priv->rproc->priv = priv; - rproc->state = RPROC_READY; - return priv->rproc; -} - -static void rproc_remove(struct remoteproc *rproc) -{ - struct rproc_priv *priv; - - priv = (struct rproc_priv *)rproc->priv; - metal_free_memory(priv); -} - -static void *rproc_mmap(struct remoteproc *rproc, - metal_phys_addr_t *pa, metal_phys_addr_t *da, - size_t size, unsigned int attribute, - struct metal_io_region **io) -{ - struct remoteproc_mem *mem; - struct metal_io_region *tmpio; - - if (*pa == METAL_BAD_PHYS && *da == METAL_BAD_PHYS) - return NULL; - if (*pa == METAL_BAD_PHYS) - *pa = *da; - if (*da == METAL_BAD_PHYS) - *da = *pa; - - mem = metal_allocate_memory(sizeof(*mem)); - if (!mem) - return NULL; - tmpio = metal_allocate_memory(sizeof(*tmpio)); - if (!tmpio) { - metal_free_memory(mem); - return NULL; - } - - /* mmap pa to va */ - int memfd; - void *va; - memfd = open("/dev/mem", O_RDWR); - va = mmap((void*)pa, size, PROT_READ | PROT_WRITE, MAP_SHARED, memfd, *pa); - - remoteproc_init_mem(mem, NULL, *pa, *da, size, tmpio); - metal_io_init(tmpio, va, &mem->pa, size, -1, attribute, NULL); /* metal io manage va and pa */ - remoteproc_add_mem(rproc, mem); - if (io) - *io = tmpio; - - printf("master mmap pa=0x%lx, da=0x%lx, size=0x%lx, attribute=0x%x va=%p\n", *pa, *da, size, attribute, va); - - return metal_io_phys_to_virt(tmpio, mem->pa); -} - -//master tmp -static int rproc_notify_tmp(struct remoteproc *rproc, uint32_t id) -{ - return 0; -} - -static int rproc_notify(struct remoteproc *rproc, uint32_t id) -{ - int ret; - - printf("master notify start\n"); - - /* notify RTOS Endpoint using IPC */ - ret = write(pipefd1[1], "Linux: notify ipi\n", strlen("Linux: notify ipi\n")); - if (ret == -1) - perror("master write pipefd1[1]"); - - return 0; -} - -static struct remoteproc_ops rproc_ops = { - .init = rproc_init, - .remove = rproc_remove, - .mmap = rproc_mmap, - .notify = rproc_notify_tmp, //master tmp -}; - -static unsigned int receive_message(struct remoteproc *rproc) -{ - char buf[50] = {0}; - int ret; - - /* 1. poll and wait for IPI(IPC) from RTOS Endpoint */ - while (read(pipefd2[0], buf, sizeof(buf)) > 0) { - printf("master poll:%s", buf); - if (strcmp(buf, "RTOS: notify ipi\n") == 0) - break; - } - - /* 2. receive data */ - ret = remoteproc_get_notification(rproc, VRING_RX_NOTIFY_ID); - if (ret) - printf("remoteproc_get_notification failed: 0x%x\n", ret); - return received_data; -} - -static int endpoint_cb(struct rpmsg_endpoint *ept, void *data, - size_t len, uint32_t src, void *priv) -{ - received_data = *((unsigned int *) data); - return RPMSG_SUCCESS; -} - -static void rpmsg_service_unbind(struct rpmsg_endpoint *ept) -{ - rpmsg_destroy_ept(ept); -} - -static void ns_bind_cb(struct rpmsg_device *rdev, const char *name, uint32_t dest) -{ - (void)rpmsg_create_ept(&linux_ept, rdev, name, - RPMSG_ADDR_ANY, dest, - endpoint_cb, - rpmsg_service_unbind); -} - -static int send_message(unsigned int message, struct rpmsg_endpoint *ept) -{ - return rpmsg_send(ept, &message, sizeof(message)); -} - -static struct remoteproc *platform_create_proc(unsigned int id) -{ - struct remoteproc *rproc; - struct remoteproc rproc_inst; - void *va; - void *rsc; - int ret; - metal_phys_addr_t pa = RSC_TABLE_ADDR; - int rsc_size; - - /* Initialize remoteproc instance */ - rproc = remoteproc_init(&rproc_inst, &rproc_ops, &id); - if (!rproc) - return NULL; - - /* mmap resource table */ - rsc = get_resource_table(&rsc_size); - va = remoteproc_mmap(rproc, &pa, NULL, rsc_size, 0, NULL); - memcpy(va, rsc, rsc_size); - - /* parse resource table to remoteproc */ - ret = remoteproc_set_rsc_table(rproc, va, rsc_size); - if (ret) { - printf("Failed to initialize remoteproc, ret:0x%x\n", ret); - remoteproc_remove(rproc); - return NULL; - } - - //tmp - struct remote_resource_table *va_tmp = va; - struct remote_resource_table *rsc_tmp = rsc; - va_tmp->rpmsg_vdev.notifyid = rsc_tmp->rpmsg_vdev.notifyid; - va_tmp->rpmsg_vdev.vring[0].notifyid = rsc_tmp->rpmsg_vdev.vring[0].notifyid; - va_tmp->rpmsg_vdev.vring[1].notifyid = rsc_tmp->rpmsg_vdev.vring[1].notifyid; - - printf("(1)master platform_create_proc success\n"); - - return rproc; -} - -static struct rpmsg_device *platform_create_rpmsg_vdev(struct remoteproc *rproc) -{ - struct rpmsg_virtio_device rpmsg_vdev; - struct virtio_device *vdev; - void *shbuf; - struct metal_io_region *shbuf_io; - int ret; - - shbuf_io = remoteproc_get_io_with_pa(rproc, SHM_START_ADDR); - if (!shbuf_io) - return NULL; - shbuf = metal_io_phys_to_virt(shbuf_io, SHM_START_ADDR); - - printf("(2)master creating remoteproc virtio\n"); - vdev = remoteproc_create_virtio(rproc, 0, RPMSG_MASTER, NULL); - if (!vdev) { - printf("failed remoteproc_create_virtio\n"); - return NULL; - } - - printf("(3)master initializing rpmsg shared buffer pool\n"); - /* Only RPMsg virtio master needs to initialize the shared buffers pool */ - rpmsg_virtio_init_shm_pool(&shpool, shbuf, SHM_SIZE); - - printf("(4)master initializing rpmsg vdev\n"); - /* RPMsg virtio slave can set shared buffers pool argument to NULL */ - ret = rpmsg_init_vdev(&rpmsg_vdev, vdev, ns_bind_cb, shbuf_io, &shpool); - if (ret) { - printf("failed rpmsg_init_vdev\n"); - remoteproc_remove_virtio(rproc, vdev); - return NULL; - } - - //printf("master vq[0].callback:%p, vq[1].callback:%p\n", vdev->vrings_info[0].vq->callback, vdev->vrings_info[1].vq->callback); - - printf("(5)master returning rdev\n"); - return rpmsg_virtio_get_rpmsg_device(&rpmsg_vdev); -} - -static void rpmsg_app_master(struct remoteproc *rproc) -{ - int status = 0; - unsigned int message = 2; - - //tmp - /* register notify function */ - rproc->ops->notify = rproc_notify; - - /* 1.2 master receive NS Announcement, and process it */ - receive_message(rproc); - - printf("1.2 master receive_message succeed\n"); - printf("1.2 master Endpoint: name:%s, addr:0x%x, dest_addr:0x%x\n", linux_ept.name, linux_ept.addr, linux_ept.dest_addr); - - while (message < 99) { - /* 2. master send message */ - status = send_message(message, &linux_ept); - if (status < 0) - printf("send_message(%u) failed with status %d\n", message, status); - - printf("2. master send_message succeed\n"); - - sleep(1); - /* 5. master receive message */ - message = receive_message(rproc); - printf("5. Master core received a message: %u\n\n", message); - - message++; - sleep(1); - } -} - -int rpmsg_linux_endpoint() -{ - struct remoteproc *rproc = NULL; - unsigned int id = 1; - struct rpmsg_device *rdev = NULL; - - /* create remoteproc */ - rproc = platform_create_proc(id); - if (!rproc) { - printf("create rproc failed\n"); - return -1; - } - - rdev = platform_create_rpmsg_vdev(rproc); - if (!rdev) - printf("master create rpmsg vdev failed\n"); - - rpmsg_app_master(rproc); - //remoteproc_remove(rproc); - - return 0; -} diff --git a/mcs/openamp_demo_proc_rsctbl/rpmsg_main.c b/mcs/openamp_demo_proc_rsctbl/rpmsg_main.c deleted file mode 100644 index 611636ae7f6c3854a71b2055c60f9ff036bc137b..0000000000000000000000000000000000000000 --- a/mcs/openamp_demo_proc_rsctbl/rpmsg_main.c +++ /dev/null @@ -1,76 +0,0 @@ -#include -#include -#include -#include - -#include "rpmsg-internal.h" - -int pipefd1[2]; -int pipefd2[2]; - -/* Place resource table in special ELF section */ -#define __section_t(S) __attribute__((__section__(#S))) -#define __resource __section_t(.resource_table) - -#define NUM_TABLE_ENTRIES 2 -#define DFEATURE_SUPPORT_NS 1 - -struct remote_resource_table __resource resources = { - /* Version */ - RSC_TAB_SUPPORTED_VERSION, - /* NUmber of table entries */ - NUM_TABLE_ENTRIES, - /* reserved fields */ - { 0, 0 }, - /* Offsets of rsc entries */ - { - offsetof(struct remote_resource_table, rpmsg_mem), - offsetof(struct remote_resource_table, rpmsg_vdev), - }, - - /* 1. Rpmsg buffer memory entry */ - { RSC_CARVEOUT, SHM_START_ADDR, SHM_START_ADDR, SHM_SIZE, 0 }, - - /* 2. Virtio device entry */ - { RSC_VDEV, VIRTIO_ID_RPMSG, VDEV_NOTIFY_ID, DFEATURE_SUPPORT_NS, 0, 0, 0, VRING_COUNT, { 0, 0 } }, - /* Vring rsc entry - part of vdev rsc entry */ - { VRING_RX_ADDRESS, VRING_ALIGNMENT, VRING_SIZE, VRING_RX_NOTIFY_ID, 0 }, /* VRING_RX */ - { VRING_TX_ADDRESS, VRING_ALIGNMENT, VRING_SIZE, VRING_TX_NOTIFY_ID, 0 }, /* VRING_TX */ -}; - -void *get_resource_table(int *len) -{ - *len = sizeof(resources); - return &resources; -} - -extern int rpmsg_linux_endpoint(); -extern int rpmsg_rtos_endpoint(); - -int main(int argc, char **argv) -{ - pid_t pid; - - /* Create unamed pipe */ - if (pipe(pipefd1) < 0) { - perror("pipe1"); - return -1; - } - if (pipe(pipefd2) < 0) { - perror("pipe2"); - return -1; - } - - if ((pid = fork()) < 0) { - perror("fork"); - return -1; - } else if (pid > 0) { - /* parent: Linux Endpoint */ - rpmsg_linux_endpoint(); - } else { - /* child: RTOS Endpoint */ - rpmsg_rtos_endpoint(); - } - - return 0; -} diff --git a/mcs/openamp_demo_proc_rsctbl/rpmsg_rtos_endpoint.c b/mcs/openamp_demo_proc_rsctbl/rpmsg_rtos_endpoint.c deleted file mode 100644 index a0ad2872bab320cf59761d2e721d4c9ce41458a5..0000000000000000000000000000000000000000 --- a/mcs/openamp_demo_proc_rsctbl/rpmsg_rtos_endpoint.c +++ /dev/null @@ -1,277 +0,0 @@ -/* RTOS Endpoint run in child process, isolate with parent process */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "rpmsg-internal.h" - -static volatile unsigned int rtos_received_data; - -static struct remoteproc *rtos_rproc_init(struct remoteproc *rproc, - struct remoteproc_ops *ops, void *arg) -{ - struct rproc_priv *priv; - unsigned int id = *((unsigned int *)arg); - - priv = metal_allocate_memory(sizeof(*priv)); - if (!priv) - return NULL; - - memset(priv, 0, sizeof(*priv)); - priv->rproc = rproc; - priv->id = id; - priv->rproc->ops = ops; - metal_list_init(&priv->rproc->mems); - priv->rproc->priv = priv; - rproc->state = RPROC_READY; - return priv->rproc; -} - -static void rtos_rproc_remove(struct remoteproc *rproc) -{ - struct rproc_priv *priv; - - priv = (struct rproc_priv *)rproc->priv; - metal_free_memory(priv); -} - -static void *rtos_rproc_mmap(struct remoteproc *rproc, - metal_phys_addr_t *pa, metal_phys_addr_t *da, - size_t size, unsigned int attribute, - struct metal_io_region **io) -{ - struct remoteproc_mem *mem; - struct metal_io_region *tmpio; - - if (*pa == METAL_BAD_PHYS && *da == METAL_BAD_PHYS) - return NULL; - if (*pa == METAL_BAD_PHYS) - *pa = *da; - if (*da == METAL_BAD_PHYS) - *da = *pa; - - mem = metal_allocate_memory(sizeof(*mem)); - if (!mem) - return NULL; - tmpio = metal_allocate_memory(sizeof(*tmpio)); - if (!tmpio) { - metal_free_memory(mem); - return NULL; - } - - /* mmap pa to va */ - int memfd; - void *va; - memfd = open("/dev/mem", O_RDWR); - va = mmap((void*)pa, size, PROT_READ | PROT_WRITE, MAP_SHARED, memfd, *pa); - - remoteproc_init_mem(mem, NULL, *pa, *da, size, tmpio); - metal_io_init(tmpio, va, &mem->pa, size, -1, attribute, NULL); /* metal io manage va and pa */ - remoteproc_add_mem(rproc, mem); - if (io) - *io = tmpio; - - printf("slave mmap pa=0x%lx, da=0x%lx, size=0x%lx, attribute=0x%x va=%p\n", *pa, *da, size, attribute, va); - - return metal_io_phys_to_virt(tmpio, mem->pa); -} - -static int rtos_rproc_notify(struct remoteproc *rproc, uint32_t id) -{ - int ret; - - printf("slave notify start\n"); - - /* notify RTOS Endpoint using IPC */ - ret = write(pipefd2[1], "RTOS: notify ipi\n", strlen("RTOS: notify ipi\n")); - if (ret == -1) - perror("slave write pipefd2[1]"); - - return 0; -} - -static struct remoteproc_ops rtos_rproc_ops = { - .init = rtos_rproc_init, - .remove = rtos_rproc_remove, - .mmap = rtos_rproc_mmap, - .notify = rtos_rproc_notify, -}; - -static unsigned int rtos_receive_message(struct remoteproc *rproc) -{ - char buf[50] = {0}; - int ret; - - /* 1. poll and wait for IPI(IPC) from RTOS Endpoint */ - while (read(pipefd1[0], buf, sizeof(buf)) > 0) { - printf("slave poll:%s", buf); - if (strcmp(buf, "Linux: notify ipi\n") == 0) - break; - } - - /* 2. receive data */ - ret = remoteproc_get_notification(rproc, VRING_TX_NOTIFY_ID); - if (ret) - printf("remoteproc_get_notification failed: 0x%x\n", ret); - return rtos_received_data; -} - -static int rtos_endpoint_cb(struct rpmsg_endpoint *ept, void *data, - size_t len, uint32_t src, void *priv) -{ - rtos_received_data = *((unsigned int *) data); - return RPMSG_SUCCESS; -} - -static void rtos_rpmsg_service_unbind(struct rpmsg_endpoint *ept) -{ - rpmsg_destroy_ept(ept); -} - -static int rtos_send_message(unsigned int message, struct rpmsg_endpoint *ept) -{ - return rpmsg_send(ept, &message, sizeof(message)); -} - -static struct remoteproc *rtos_platform_create_proc(unsigned int id) -{ - struct remoteproc *rproc; - struct remoteproc rproc_inst; - void *va; - void *rsc; - int ret; - metal_phys_addr_t pa = RSC_TABLE_ADDR; - int rsc_size; - - /* Initialize remoteproc instance */ - rproc = remoteproc_init(&rproc_inst, &rtos_rproc_ops, &id); - if (!rproc) - return NULL; - - /* mmap resource table */ - rsc = get_resource_table(&rsc_size); - va = remoteproc_mmap(rproc, &pa, NULL, rsc_size, 0, NULL); - memcpy(va, rsc, rsc_size); - - /* parse resource table to remoteproc */ - ret = remoteproc_set_rsc_table(rproc, va, rsc_size); - if (ret) { - printf("Failed to initialize remoteproc, ret:0x%x\n", ret); - remoteproc_remove(rproc); - return NULL; - } - - //tmp - struct remote_resource_table *va_tmp = va; - struct remote_resource_table *rsc_tmp = rsc; - va_tmp->rpmsg_vdev.notifyid = rsc_tmp->rpmsg_vdev.notifyid; - va_tmp->rpmsg_vdev.vring[0].notifyid = rsc_tmp->rpmsg_vdev.vring[0].notifyid; - va_tmp->rpmsg_vdev.vring[1].notifyid = rsc_tmp->rpmsg_vdev.vring[1].notifyid; - - printf("(1)slave platform_create_proc success\n"); - - return rproc; -} - -static struct rpmsg_device *rtos_platform_create_rpmsg_vdev(struct remoteproc *rproc) -{ - struct rpmsg_virtio_device rpmsg_vdev; - struct virtio_device *vdev; - void *shbuf; - struct metal_io_region *shbuf_io; - int ret; - - shbuf_io = remoteproc_get_io_with_pa(rproc, SHM_START_ADDR); - if (!shbuf_io) - return NULL; - shbuf = metal_io_phys_to_virt(shbuf_io, SHM_START_ADDR); - - printf("(2)slave creating remoteproc virtio\n"); - vdev = remoteproc_create_virtio(rproc, 0, RPMSG_REMOTE, NULL); - if (!vdev) { - printf("failed remoteproc_create_virtio\n"); - return NULL; - } - - printf("(3)slave initializing rpmsg vdev\n"); - /* RPMsg virtio slave can set shared buffers pool argument to NULL */ - ret = rpmsg_init_vdev(&rpmsg_vdev, vdev, NULL, shbuf_io, NULL); - if (ret) { - printf("failed rpmsg_init_vdev\n"); - remoteproc_remove_virtio(rproc, vdev); - return NULL; - } - - //printf("slave vq[0].callback:%p, vq[1].callback:%p\n", vdev->vrings_info[0].vq->callback, vdev->vrings_info[1].vq->callback); - - printf("(4)slave returning rdev\n"); - return rpmsg_virtio_get_rpmsg_device(&rpmsg_vdev); -} - -static void rtos_rpmsg_app_master(struct remoteproc *rproc, struct rpmsg_device *rdev) -{ - int status = 0; - unsigned int message; - struct rpmsg_endpoint ept; - - /* 1.1 slave create endpoint, and send an NS Announcement */ - status = rpmsg_create_ept(&ept, rdev, "k", RPMSG_ADDR_ANY, RPMSG_ADDR_ANY, rtos_endpoint_cb, rtos_rpmsg_service_unbind); - if (status < 0) - printf("slave rpmsg_create_ept failed:%d\n", status); - - printf("1.1 slave rpmsg_create_ept succeed\n"); - printf("1.1 slave Endpoint: name:%s, addr:0x%x, dest_addr:0x%x\n", ept.name, ept.addr, ept.dest_addr); - - while (message < 99) { - /* 3. slave receive message */ - message = rtos_receive_message(rproc); - printf("3. Slave core received a message: %u\n", message); - message++; - sleep(1); - - printf("3. slave Endpoint: name:%s, addr:0x%x, dest_addr:0x%x\n", ept.name, ept.addr, ept.dest_addr); - - /* 4. slave send message */ - status = rtos_send_message(message, &ept); - if (status < 0) - printf("rtos_send_message(%u) failed with status %d\n", message, status); - - printf("4. slave rtos_send_message succeed\n"); - - sleep(1); - } -} - -int rpmsg_rtos_endpoint() -{ - struct remoteproc *rproc = NULL; - unsigned int id = 1; - struct rpmsg_device *rdev = NULL; - - /* create remoteproc */ - rproc = rtos_platform_create_proc(id); - if (!rproc) { - printf("create rproc failed\n"); - return -1; - } - - rdev = rtos_platform_create_rpmsg_vdev(rproc); - if (!rdev) - printf("slave create rpmsg vdev failed\n"); - - rtos_rpmsg_app_master(rproc, rdev); - //remoteproc_remove(rproc); - - return 0; -} diff --git a/mcs/rpmsg_pty_demo/rpmsg_main.c b/mcs/rpmsg_pty_demo/rpmsg_main.c deleted file mode 100644 index 74fa2f493baeb79407c370712b2006a09727d4cb..0000000000000000000000000000000000000000 --- a/mcs/rpmsg_pty_demo/rpmsg_main.c +++ /dev/null @@ -1,87 +0,0 @@ -#include -#include -#include -#include "rpmsg_pty.h" -#include "openamp_module.h" - -char *cpu_id; -char *target_binfile; -char *target_binaddr; - -static void cleanup(int sig) -{ - openamp_deinit(); - pthread_mutex_destroy(&mutex); - exit(0); -} - -int rpmsg_app_master(void) -{ - pthread_t tida, tidb, tidc; - - printf("Multi-thread processing user requests...\n"); - - /* init mutex as thread lock */ - pthread_mutex_init(&mutex, NULL); - - /* userA, zephyr shell, open with screen */ - if (pthread_create(&tida, NULL, shell_user, NULL) < 0) { - perror("userA pthread_create"); - return -1; - } - pthread_detach(tida); - - /* userB, zephyr shell, open with screen */ - if (pthread_create(&tidb, NULL, shell_user, NULL) < 0) { - perror("userB pthread_create"); - return -1; - } - pthread_detach(tidb); - - while (1); - - return 0; -} - -int main(int argc, char **argv) -{ - int ret; - int opt; - - /* ctrl+c signal, do cleanup before program exit */ - signal(SIGINT, cleanup); - - while ((opt = getopt(argc, argv, "c:t:a:")) != -1) { - switch (opt) { - case 'c': - cpu_id = optarg; - break; - case 't': - target_binfile = optarg; - break; - case 'a': - target_binaddr = optarg; - break; - default: - break; - } - } - - ret = openamp_init(); - if (ret) { - printf("openamp init failed: %d\n", ret); - openamp_deinit(); - return ret; - } - - ret = rpmsg_app_master(); - if (ret) { - printf("rpmsg app master failed: %d\n", ret); - openamp_deinit(); - return ret; - } - - openamp_deinit(); - - return 0; -} diff --git a/mcs/rpmsg_pty_demo/rpmsg_pty.c b/mcs/rpmsg_pty_demo/rpmsg_pty.c deleted file mode 100644 index f95b80c54ed0fb6630ae8b42c27e60f709f95af7..0000000000000000000000000000000000000000 --- a/mcs/rpmsg_pty_demo/rpmsg_pty.c +++ /dev/null @@ -1,153 +0,0 @@ -#define _XOPEN_SOURCE 600 -#include -#include -#include -#include -#include -#include -#include -#include "openamp_module.h" - -/* define the keys according to your terminfo */ -#define KEY_CTRL_D 4 -#define FILE_MODE 0644 -#define PTSNAME_LEN 20 - -pthread_mutex_t mutex; - -void open_pty(int *pfdm, int *pfds, const char *pty_name) -{ - int ret; - int fdm, fds; - char pts_name[PTSNAME_LEN] = {0}; - - /* Open the master side of the PTY */ - fdm = posix_openpt(O_RDWR | O_NOCTTY); - if (fdm < 0) - printf("Error %d on posix_openpt()\n", errno); - - ret = grantpt(fdm); - if (ret != 0) - printf("Error %d on grantpt()\n", errno); - - ret = unlockpt(fdm); - if (ret != 0) - printf("Error %d on unlockpt()\n", errno); - - /* Open the slave side of the PTY */ - ret = ptsname_r(fdm, pts_name, sizeof(pts_name)); - if (ret != 0) - printf("Error %d on ptsname_r()\n", errno); - - fds = open(pts_name, O_RDWR | O_NOCTTY); - if (ret != 0) - printf("Error %d on open()\n", errno); - - printf("open a new terminal, zephyr %s: screen %s\n", pty_name, pts_name); - - *pfdm = fdm; - *pfds = fds; -} - -void *shell_user(void *arg) -{ - int ret; - int fdm, fds; - unsigned char cmd[1]; - unsigned char reply[2048]; - int reply_len; - - open_pty(&fdm, &fds, "shell"); - - while (1) { - ret = read(fdm, cmd, 1); /* get command from ptmx */ - if (ret < 0) { - printf("shell_user: get from ptmx failed: %d\n", ret); - return (void*)-1; - } - - if (cmd[0] == KEY_CTRL_D) { /* special key: ctrl+d */ - close(fds); - close(fdm); - return (void*)0; /* exit this thread, the same as pthread_exit */ - } - - pthread_mutex_lock(&mutex); - - ret = send_message(cmd, 1); /* send command to rtos */ - usleep(100 * 1000); /* wait 100ms, some messages may be seperated */ - ret |= receive_message(reply, sizeof(reply), &reply_len); /* receive reply from rtos */ - - pthread_mutex_unlock(&mutex); - - if (ret < 0) { - printf("shell_user: send(%s)/receive(%s) message failed: %d\n", cmd, reply, ret); - return (void*)-1; - } - - ret = write(fdm, reply, reply_len); /* send reply to ptmx */ - if (ret < 0) { - printf("shell_user: write to ptmx(%s) failed: %d\n", reply, ret); - return (void*)-1; - } - } - - return (void*)0; -} - -void *console_user(void *arg) -{ - int ret; - int fdm, fds; - unsigned char reply[2048]; - int reply_len; - - /* open PTY, pts binds to terminal, using screen to open pts */ - open_pty(&fdm, &fds, "console"); - - while (1) { - ret = receive_message(reply, sizeof(reply), &reply_len); /* receive reply from rtos */ - if (ret < 0) { - printf("shell_user: receive_message failed: %d\n", ret); - return (void*)-1; - } - - ret = write(fdm, reply, reply_len); /* send reply to ptmx */ - if (ret < 0) { - printf("shell_user: write to ptmx(%s) failed: %d\n", reply, ret); - return (void*)-1; - } - } - - return (void*)0; -} - -void *log_user(void *arg) -{ - int ret; - int log_fd; - unsigned char log[2048] = {0}; - int log_len; - const char *log_file = "/tmp/zephyr_log.txt"; - - ret = receive_message(log, sizeof(log), &log_len); /* receive log from rtos */ - if (ret < 0) { - printf("log_user: receive_message(%s) failed: %d\n", log, ret); - return (void*)-1; - } - - /* write log into file */ - log_fd = open(log_file, O_RDWR | O_CREAT | O_APPEND, FILE_MODE); - if (log_fd < 0) { - printf("log_user: open (%s) failed: %d\n", log_file, log_fd); - return (void*)-1; - } - ret = write(log_fd, log, log_len); - if (ret < 0) { - printf("log_user: write to file(%s) failed: %d\n", log_file, ret); - return (void*)-1; - } - close(log_fd); - - return (void*)0; -} diff --git a/mcs/rpmsg_pty_demo/rpmsg_pty.h b/mcs/rpmsg_pty_demo/rpmsg_pty.h deleted file mode 100644 index 3668849dda9cc7b6b91cda516049bfe08e198f6a..0000000000000000000000000000000000000000 --- a/mcs/rpmsg_pty_demo/rpmsg_pty.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef RPMSG_PTY_H -#define RPMSG_PTY_H - -void *shell_user(void *arg); -void *console_user(void *arg); -void *log_user(void *arg); - -extern pthread_mutex_t mutex; - -#endif \ No newline at end of file diff --git a/mcs/rpmsg_pty_demo/zephyr_qemu.bin b/mcs/rpmsg_pty_demo/zephyr_qemu.bin deleted file mode 100644 index ebf342c54a341d7e2cec636e321e07725ea3c368..0000000000000000000000000000000000000000 Binary files a/mcs/rpmsg_pty_demo/zephyr_qemu.bin and /dev/null differ diff --git a/mcs/rpmsg_pty_demo/zephyr_rpi.bin b/mcs/rpmsg_pty_demo/zephyr_rpi.bin deleted file mode 100644 index 57d2c401ce021aa9230ca319000d312c1c829603..0000000000000000000000000000000000000000 Binary files a/mcs/rpmsg_pty_demo/zephyr_rpi.bin and /dev/null differ