pkarashchenko commented on code in PR #6304: URL: https://github.com/apache/incubator-nuttx/pull/6304#discussion_r877870638
########## arch/risc-v/src/mpfs/mpfs_ihc.c: ########## @@ -367,6 +440,51 @@ static void mpfs_ihc_rx_handler(uint32_t *message, bool is_ack) } } +/**************************************************************************** + * Name: mpfs_ihc_message_present_handler + * + * Description: + * This function fills up a structure that gets into the remote end, such + * as Linux kernel. The structure may contain data from the + * MPFS_IHC_MSG_IN -register, or in case of an ack, just the irq_type. + * + * Input Parameters: + * message - Pointer for storing data, must not be NULL + * mhartid - The primary hart id of a set of hartids. Not necessarily + * the absolute mhartid if multiple harts are incorporated + * within the remote (eg. Linux kernel used on 2 harts). + * rhartid - Remote hart id + * is_ack - Boolean indicating an ack message + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void mpfs_ihc_message_present_handler(uint32_t *message, + uint32_t mhartid, + uint32_t rhartid, + bool is_ack) +{ + struct ihc_sbi_rx_msg msg; + uintptr_t message_ihc = (uintptr_t)MPFS_IHC_MSG_IN(mhartid, rhartid); + uint32_t message_size_ihc = getreg32(MPFS_IHC_MSG_SIZE(mhartid, rhartid)); + + if (is_ack == true) + { + msg.irq_type = ACK_IRQ; + } + else + { + msg.irq_type = MP_IRQ; + DEBUGASSERT(sizeof(msg.ihc_msg) >= message_size_ihc); + memcpy((uint32_t *)&msg.ihc_msg, (void *)message_ihc, + message_size_ihc); + } + + memcpy(message, (uint32_t *)&msg, sizeof(struct ihc_sbi_rx_msg)); Review Comment: ```suggestion memcpy(message, &msg, sizeof(struct ihc_sbi_rx_msg)); ``` ########## arch/risc-v/src/mpfs/mpfs_ihc.c: ########## @@ -367,6 +440,51 @@ static void mpfs_ihc_rx_handler(uint32_t *message, bool is_ack) } } +/**************************************************************************** + * Name: mpfs_ihc_message_present_handler + * + * Description: + * This function fills up a structure that gets into the remote end, such + * as Linux kernel. The structure may contain data from the + * MPFS_IHC_MSG_IN -register, or in case of an ack, just the irq_type. + * + * Input Parameters: + * message - Pointer for storing data, must not be NULL + * mhartid - The primary hart id of a set of hartids. Not necessarily + * the absolute mhartid if multiple harts are incorporated + * within the remote (eg. Linux kernel used on 2 harts). + * rhartid - Remote hart id + * is_ack - Boolean indicating an ack message + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void mpfs_ihc_message_present_handler(uint32_t *message, + uint32_t mhartid, + uint32_t rhartid, + bool is_ack) +{ + struct ihc_sbi_rx_msg msg; + uintptr_t message_ihc = (uintptr_t)MPFS_IHC_MSG_IN(mhartid, rhartid); + uint32_t message_size_ihc = getreg32(MPFS_IHC_MSG_SIZE(mhartid, rhartid)); + + if (is_ack == true) Review Comment: ```suggestion if (is_ack) ``` ########## arch/risc-v/src/mpfs/mpfs_ihc.c: ########## @@ -1134,6 +1268,63 @@ static int mpfs_rptun_thread(int argc, char *argv[]) * Public Functions ****************************************************************************/ +/**************************************************************************** + * Name: mpfs_ihc_sbi_ecall_handler + * + * Description: + * This is sbi_platform_operations / vendor_ext_provider ecall handler. + * Related Linux ecalls end up here. + * + * Input Parameters: + * funcid - SBI_EXT_IHC_CTX_INIT, SBI_EXT_IHC_SEND or + * SBI_EXT_IHC_RECEIVE. Others are invalid. + * remote_channel - The remote we're communicating with + * message_ptr - Local storage for data exchange + * + * Returned Value: + * OK on success, a negated error code otherwise + * + ****************************************************************************/ + +#ifdef CONFIG_MPFS_OPENSBI +int mpfs_ihc_sbi_ecall_handler(unsigned long funcid, uint32_t remote_channel, + uint32_t *message_ptr) +{ + uint32_t mhartid; + uint32_t rhartid; + int result = OK; + + /* Check the channel is bound to a valid context */ + + if ((remote_channel < IHC_CHANNEL_TO_CONTEXTA) || + (remote_channel > IHC_CHANNEL_TO_CONTEXTB)) + { + return -EINVAL; + } + + switch (funcid) + { + case SBI_EXT_IHC_CTX_INIT: + mhartid = mpfs_ihc_context_to_local_hart_id(remote_channel); + rhartid = mpfs_ihc_context_to_remote_hart_id(remote_channel); + mpfs_ihc_local_context_init(mhartid); + mpfs_ihc_local_remote_config(mhartid, rhartid); + break; + case SBI_EXT_IHC_SEND: + result = mpfs_ihc_tx_message(remote_channel, message_ptr); + break; + case SBI_EXT_IHC_RECEIVE: + mpfs_ihc_sbi_message_present_indirect_isr(remote_channel, + message_ptr); + break; + default: + result = -ENOTSUP; Review Comment: ```suggestion case SBI_EXT_IHC_CTX_INIT: mhartid = mpfs_ihc_context_to_local_hart_id(remote_channel); rhartid = mpfs_ihc_context_to_remote_hart_id(remote_channel); mpfs_ihc_local_context_init(mhartid); mpfs_ihc_local_remote_config(mhartid, rhartid); break; case SBI_EXT_IHC_SEND: result = mpfs_ihc_tx_message(remote_channel, message_ptr); break; case SBI_EXT_IHC_RECEIVE: mpfs_ihc_sbi_message_present_indirect_isr(remote_channel, message_ptr); break; default: result = -ENOTSUP; ``` ########## arch/risc-v/src/mpfs/mpfs_opensbi.c: ########## @@ -499,6 +517,72 @@ static void mpfs_opensbi_pmp_setup(void) csr_write(pmpcfg2, 0); } +/**************************************************************************** + * Name: mpfs_opensbi_vendor_ext_check + * + * Description: + * Used by the OpenSBI in vendor probe to check the vendor ID. + * + * Input Parameters: + * extid - hart number to be prepared + * + * Returned Value: + * 1 on match, zero if not + * + ****************************************************************************/ + +#ifdef CONFIG_MPFS_IHC +static int mpfs_opensbi_vendor_ext_check(long extid) +{ + return (SBI_EXT_MICROCHIP_TECHNOLOGY == extid); +} + +/**************************************************************************** + * Name: mpfs_opensbi_ecall_handler + * + * Description: + * Used by the S-mode kernel such as Linux to perform M-mode ecall actions + * related to Inter-Hart Communication (IHC). + * + * Input Parameters: + * extid - Vendor ID + * funcid - One of the valid functions + * sbi_trap_regs - SBI trap registers + * out_val - Error code location + * out_trap - Trap registers such as epc, unused + * + * Returned Value: + * 0 always + * + ****************************************************************************/ + +static int mpfs_opensbi_ecall_handler(long extid, long funcid, + const struct sbi_trap_regs *regs, + unsigned long *out_val, + struct sbi_trap_info *out_trap) +{ + uint32_t remote_channel = (uint32_t)regs->a0; + uint32_t *message_ptr = (uint32_t *)regs->a1; + int result = 0; + + switch (funcid) + { + case SBI_EXT_IHC_CTX_INIT: + case SBI_EXT_IHC_SEND: + case SBI_EXT_IHC_RECEIVE: + result = mpfs_ihc_sbi_ecall_handler(funcid, remote_channel, + message_ptr); + break; + default: Review Comment: ```suggestion break; default: ``` ########## arch/risc-v/src/mpfs/mpfs_ihc.c: ########## @@ -367,6 +440,51 @@ static void mpfs_ihc_rx_handler(uint32_t *message, bool is_ack) } } +/**************************************************************************** + * Name: mpfs_ihc_message_present_handler + * + * Description: + * This function fills up a structure that gets into the remote end, such + * as Linux kernel. The structure may contain data from the + * MPFS_IHC_MSG_IN -register, or in case of an ack, just the irq_type. + * + * Input Parameters: + * message - Pointer for storing data, must not be NULL + * mhartid - The primary hart id of a set of hartids. Not necessarily + * the absolute mhartid if multiple harts are incorporated + * within the remote (eg. Linux kernel used on 2 harts). + * rhartid - Remote hart id + * is_ack - Boolean indicating an ack message + * + * Returned Value: + * None + * + ****************************************************************************/ + +static void mpfs_ihc_message_present_handler(uint32_t *message, + uint32_t mhartid, + uint32_t rhartid, + bool is_ack) +{ + struct ihc_sbi_rx_msg msg; + uintptr_t message_ihc = (uintptr_t)MPFS_IHC_MSG_IN(mhartid, rhartid); + uint32_t message_size_ihc = getreg32(MPFS_IHC_MSG_SIZE(mhartid, rhartid)); + + if (is_ack == true) + { + msg.irq_type = ACK_IRQ; + } + else + { + msg.irq_type = MP_IRQ; + DEBUGASSERT(sizeof(msg.ihc_msg) >= message_size_ihc); + memcpy((uint32_t *)&msg.ihc_msg, (void *)message_ihc, Review Comment: ```suggestion memcpy(&msg.ihc_msg, (void *)message_ihc, ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org