pkarashchenko commented on a change in pull request #5758: URL: https://github.com/apache/incubator-nuttx/pull/5758#discussion_r828502124
########## File path: arch/risc-v/include/barriers.h ########## @@ -0,0 +1,32 @@ +/**************************************************************************** + * arch/risc-v/include/barriers.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __ARCH_RISCV_INCLUDE_BARRIERS_H_ +#define __ARCH_RISCV_INCLUDE_BARRIERS_H_ Review comment: ```suggestion #ifndef __ARCH_RISCV_INCLUDE_BARRIERS_H #define __ARCH_RISCV_INCLUDE_BARRIERS_H ``` ########## File path: arch/risc-v/include/barriers.h ########## @@ -0,0 +1,32 @@ +/**************************************************************************** + * arch/risc-v/include/barriers.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __ARCH_RISCV_INCLUDE_BARRIERS_H_ +#define __ARCH_RISCV_INCLUDE_BARRIERS_H_ + +/* Common memory barriers: + * __DMB() is used to synchronize external devices (I/O domain mainly) + * __ISB() is used to synchronize the instruction and data streams + */ + +#define __DMB() __asm__ __volatile__ ("fence" ::: "memory") +#define __ISB() __asm__ __volatile__ ("fence.i" ::: "memory") + +#endif /* __ARCH_RISCV_INCLUDE_BARRIERS_H_ */ Review comment: ```suggestion #endif /* __ARCH_RISCV_INCLUDE_BARRIERS_H */ ``` ########## File path: arch/risc-v/src/mpfs/mpfs_plic.c ########## @@ -0,0 +1,131 @@ +/**************************************************************************** + * arch/risc-v/src/mpfs/mpfs_plic.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdint.h> +#include <stdio.h> +#include <assert.h> +#include <debug.h> + +#include <nuttx/arch.h> +#include <arch/irq.h> + +#include "mpfs.h" +#include "mpfs_plic.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mpfs_plic_get_iebase + * + * Description: + * Context aware way to query PLIC interrupt enable base address + * + * Returned Value: + * Interrupt enable base address + * + ****************************************************************************/ + +uintptr_t mpfs_plic_get_iebase(void) +{ + uint32_t *iebase; + uint64_t hart_id = riscv_mhartid(); + + if (hart_id == 0) + { + iebase = (uint32_t *)MPFS_PLIC_H0_MIE0; + } + else + { + iebase = (uint32_t *)(MPFS_PLIC_H1_MIE0 + + (hart_id - 1) * MPFS_HART_MIE_OFFSET); + } + + return (uintptr_t) iebase; Review comment: ```suggestion return iebase; ``` ########## File path: arch/risc-v/src/mpfs/mpfs_plic.c ########## @@ -0,0 +1,131 @@ +/**************************************************************************** + * arch/risc-v/src/mpfs/mpfs_plic.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdint.h> +#include <stdio.h> +#include <assert.h> +#include <debug.h> + +#include <nuttx/arch.h> +#include <arch/irq.h> + +#include "mpfs.h" +#include "mpfs_plic.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mpfs_plic_get_iebase + * + * Description: + * Context aware way to query PLIC interrupt enable base address + * + * Returned Value: + * Interrupt enable base address + * + ****************************************************************************/ + +uintptr_t mpfs_plic_get_iebase(void) +{ + uint32_t *iebase; Review comment: ```suggestion uintptr_t iebase; ``` ########## File path: sched/init/nx_start.c ########## @@ -38,6 +38,7 @@ #include <nuttx/mm/iob.h> #include <nuttx/mm/mm.h> #include <nuttx/kmalloc.h> +#include <nuttx/pgalloc.h> Review comment: why we need this change? ########## File path: boards/risc-v/mpfs/icicle/scripts/ld-envm.script ########## @@ -27,6 +27,9 @@ MEMORY OUTPUT_ARCH("riscv") +__ksram_start = ORIGIN(lim); +__ksram_size = LENGTH(lim); Review comment: Why not to define `__ksram_end = ORIGIN(lim) + LENGTH(lim)` and use it instead of `((uintptr_t)&__ksram_start + (uintptr_t)&__ksram_size)`? ########## File path: arch/risc-v/src/mpfs/mpfs_plic.c ########## @@ -0,0 +1,131 @@ +/**************************************************************************** + * arch/risc-v/src/mpfs/mpfs_plic.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdint.h> +#include <stdio.h> +#include <assert.h> +#include <debug.h> + +#include <nuttx/arch.h> +#include <arch/irq.h> + +#include "mpfs.h" +#include "mpfs_plic.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mpfs_plic_get_iebase + * + * Description: + * Context aware way to query PLIC interrupt enable base address + * + * Returned Value: + * Interrupt enable base address + * + ****************************************************************************/ + +uintptr_t mpfs_plic_get_iebase(void) +{ + uint32_t *iebase; + uint64_t hart_id = riscv_mhartid(); + + if (hart_id == 0) + { + iebase = (uint32_t *)MPFS_PLIC_H0_MIE0; + } + else + { + iebase = (uint32_t *)(MPFS_PLIC_H1_MIE0 + + (hart_id - 1) * MPFS_HART_MIE_OFFSET); + } + + return (uintptr_t) iebase; +} + +/**************************************************************************** + * Name: mpfs_plic_get_claimbase + * + * Description: + * Context aware way to query PLIC interrupt claim base address + * + * Returned Value: + * Interrupt enable claim address + * + ****************************************************************************/ + +uintptr_t mpfs_plic_get_claimbase(void) +{ + uintptr_t claim_address; + uint64_t hart_id = riscv_mhartid(); + + if (hart_id == 0) + { + claim_address = MPFS_PLIC_H0_MCLAIM; + } + else + { + claim_address = MPFS_PLIC_H1_MCLAIM + + ((hart_id - 1) * MPFS_PLIC_NEXTHART_OFFSET); + } + + return claim_address; +} + +/**************************************************************************** + * Name: mpfs_plic_get_thresholdbase + * + * Description: + * Context aware way to query PLIC interrupt threshold base address + * + * Returned Value: + * Interrupt enable threshold address + * + ****************************************************************************/ + +uintptr_t mpfs_plic_get_thresholdbase(void) +{ + uint32_t *threshold_address; + uint64_t hart_id = riscv_mhartid(); + + if (hart_id == 0) + { + threshold_address = (uint32_t *)MPFS_PLIC_H0_MTHRESHOLD; + } + else + { + threshold_address = (uint32_t *)(MPFS_PLIC_H1_MTHRESHOLD + + ((hart_id - 1) * MPFS_PLIC_NEXTHART_OFFSET)); + } + + return (uintptr_t) threshold_address; Review comment: ```suggestion return threshold_address; ``` ########## File path: arch/risc-v/src/mpfs/mpfs_irq.c ########## @@ -238,22 +192,11 @@ void up_enable_irq(int irq) /* Set enable bit for the irq */ - uint64_t hart_id = READ_CSR(mhartid); - uintptr_t miebase; - - if (hart_id == 0) - { - miebase = MPFS_PLIC_H0_MIE0; - } - else - { - miebase = MPFS_PLIC_H1_MIE0 + - ((hart_id - 1) * MPFS_HART_MIE_OFFSET); - } + uintptr_t iebase = mpfs_plic_get_iebase(); Review comment: ```suggestion uint32_t *iebase = (uint32_t *)mpfs_plic_get_iebase(); ``` ########## File path: arch/risc-v/src/mpfs/mpfs_irq.c ########## @@ -184,22 +149,11 @@ void up_disable_irq(int irq) /* Clear enable bit for the irq */ - uint64_t hart_id = READ_CSR(mhartid); - uintptr_t miebase; - - if (hart_id == 0) - { - miebase = MPFS_PLIC_H0_MIE0; - } - else - { - miebase = MPFS_PLIC_H1_MIE0 + - ((hart_id - 1) * MPFS_HART_MIE_OFFSET); - } + uintptr_t iebase = mpfs_plic_get_iebase(); Review comment: ```suggestion uint32_t *iebase = (uint32_t *)mpfs_plic_get_iebase(); ``` ########## File path: arch/risc-v/src/mpfs/mpfs_irq.c ########## @@ -60,45 +61,20 @@ void up_irqinitialize(void) up_disable_irq(RISCV_IRQ_MTIMER); - /* enable access from supervisor mode */ - - putreg32(0x1, MPFS_PLIC_CTRL); - /* Disable all global interrupts for current hart */ - uint64_t hart_id = READ_CSR(mhartid); - - uint32_t *miebase; - if (hart_id == 0) - { - miebase = (uint32_t *)MPFS_PLIC_H0_MIE0; - } - else - { - miebase = (uint32_t *)(MPFS_PLIC_H1_MIE0 + - (hart_id - 1) * MPFS_HART_MIE_OFFSET); - } + uint32_t *iebase = (uint32_t *) mpfs_plic_get_iebase(); Review comment: ```suggestion uint32_t *iebase = (uint32_t *)mpfs_plic_get_iebase(); ``` ########## File path: arch/risc-v/src/mpfs/Make.defs ########## @@ -55,19 +56,29 @@ CHIP_CSRCS += mpfs_irq.c mpfs_irq_dispatch.c CHIP_CSRCS += mpfs_lowputc.c mpfs_serial.c CHIP_CSRCS += mpfs_start.c mpfs_timerisr.c CHIP_CSRCS += mpfs_gpio.c mpfs_systemreset.c +CHIP_CSRCS += mpfs_plic.c ifeq ($(CONFIG_MPFS_DMA),y) CHIP_CSRCS += mpfs_dma.c endif -ifeq ($(CONFIG_BUILD_PROTECTED),y) -CMN_CSRCS += riscv_task_start.c -CMN_CSRCS += riscv_pthread_start.c -CMN_CSRCS += riscv_signal_dispatch.c +# Flag to enable certain modules for non-flat builds (PROTECTED/KERNEL) +__MPFS_BUILD_NONFLAT = +ifeq ($(CONFIG_BUILD_PROTECTED),y) +CHIP_CSRCS += mpfs_userspace.c CMN_UASRCS += riscv_signal_handler.S +__MPFS_BUILD_NONFLAT=y +endif -CHIP_CSRCS += mpfs_userspace.c +ifeq ($(CONFIG_BUILD_KERNEL),y) +__MPFS_BUILD_NONFLAT=y +endif + +ifeq ($(__MPFS_BUILD_NONFLAT),y) +CMN_CSRCS += riscv_task_start.c +CMN_CSRCS += riscv_pthread_start.c +CMN_CSRCS += riscv_signal_dispatch.c Review comment: ```suggestion CMN_CSRCS += riscv_pthread_start.c CMN_CSRCS += riscv_signal_dispatch.c ``` ########## File path: arch/risc-v/src/mpfs/mpfs_irq.c ########## @@ -120,18 +96,7 @@ void up_irqinitialize(void) /* Set irq threshold to 0 (permits all global interrupts) */ - uint32_t *threshold_address; - if (hart_id == 0) - { - threshold_address = (uint32_t *)MPFS_PLIC_H0_MTHRESHOLD; - } - else - { - threshold_address = (uint32_t *)(MPFS_PLIC_H1_MTHRESHOLD + - ((hart_id - 1) * - MPFS_PLIC_NEXTHART_OFFSET)); - } - + uint32_t *threshold_address = (uint32_t *) mpfs_plic_get_thresholdbase(); Review comment: ```suggestion uintptr_t threshold_address = mpfs_plic_get_thresholdbase(); ``` ########## File path: arch/risc-v/src/mpfs/mpfs_irq.c ########## @@ -184,22 +149,11 @@ void up_disable_irq(int irq) /* Clear enable bit for the irq */ - uint64_t hart_id = READ_CSR(mhartid); - uintptr_t miebase; - - if (hart_id == 0) - { - miebase = MPFS_PLIC_H0_MIE0; - } - else - { - miebase = MPFS_PLIC_H1_MIE0 + - ((hart_id - 1) * MPFS_HART_MIE_OFFSET); - } + uintptr_t iebase = mpfs_plic_get_iebase(); if (0 <= extirq && extirq <= NR_IRQS - MPFS_IRQ_EXT_START) { - modifyreg32(miebase + (4 * (extirq / 32)), 1 << (extirq % 32), 0); + modifyreg32(iebase + (4 * (extirq / 32)), 1 << (extirq % 32), 0); Review comment: ```suggestion modifyreg32(iebase + (extirq / 32), 1 << (extirq % 32), 0); ``` together with `uint32_t *iebase = (uint32_t *)mpfs_plic_get_iebase();` Or we can change `up_irqinitialize` code to: ``` uintptr_t iebase = mpfs_plic_get_iebase(); putreg32(0x0, iebase + 0); putreg32(0x0, iebase + 4); putreg32(0x0, iebase + 8); putreg32(0x0, iebase + 12); putreg32(0x0, iebase + 16); putreg32(0x0, iebase + 20); ``` Just to follow same style ########## File path: arch/risc-v/src/mpfs/mpfs_irq.c ########## @@ -238,22 +192,11 @@ void up_enable_irq(int irq) /* Set enable bit for the irq */ - uint64_t hart_id = READ_CSR(mhartid); - uintptr_t miebase; - - if (hart_id == 0) - { - miebase = MPFS_PLIC_H0_MIE0; - } - else - { - miebase = MPFS_PLIC_H1_MIE0 + - ((hart_id - 1) * MPFS_HART_MIE_OFFSET); - } + uintptr_t iebase = mpfs_plic_get_iebase(); if (0 <= extirq && extirq <= NR_IRQS - MPFS_IRQ_EXT_START) { - modifyreg32(miebase + (4 * (extirq / 32)), 0, 1 << (extirq % 32)); + modifyreg32(iebase + (4 * (extirq / 32)), 0, 1 << (extirq % 32)); Review comment: ```suggestion modifyreg32(iebase + (extirq / 32), 0, 1 << (extirq % 32)); ``` together with `uint32_t *iebase = (uint32_t *)mpfs_plic_get_iebase();` ########## File path: arch/risc-v/src/mpfs/mpfs_plic.h ########## @@ -0,0 +1,73 @@ +/**************************************************************************** + * arch/risc-v/src/mpfs/mpfs_plic.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __ARCH_RISC_V_SRC_MPFS_MPFS_PLIC_H_ +#define __ARCH_RISC_V_SRC_MPFS_MPFS_PLIC_H_ Review comment: ```suggestion #ifndef __ARCH_RISC_V_SRC_MPFS_MPFS_PLIC_H #define __ARCH_RISC_V_SRC_MPFS_MPFS_PLIC_H ``` ########## File path: arch/risc-v/src/mpfs/mpfs_plic.c ########## @@ -0,0 +1,131 @@ +/**************************************************************************** + * arch/risc-v/src/mpfs/mpfs_plic.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdint.h> +#include <stdio.h> +#include <assert.h> +#include <debug.h> + +#include <nuttx/arch.h> +#include <arch/irq.h> + +#include "mpfs.h" +#include "mpfs_plic.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mpfs_plic_get_iebase + * + * Description: + * Context aware way to query PLIC interrupt enable base address + * + * Returned Value: + * Interrupt enable base address + * + ****************************************************************************/ + +uintptr_t mpfs_plic_get_iebase(void) +{ + uint32_t *iebase; + uint64_t hart_id = riscv_mhartid(); + + if (hart_id == 0) + { + iebase = (uint32_t *)MPFS_PLIC_H0_MIE0; + } + else + { + iebase = (uint32_t *)(MPFS_PLIC_H1_MIE0 + + (hart_id - 1) * MPFS_HART_MIE_OFFSET); + } + + return (uintptr_t) iebase; +} + +/**************************************************************************** + * Name: mpfs_plic_get_claimbase + * + * Description: + * Context aware way to query PLIC interrupt claim base address + * + * Returned Value: + * Interrupt enable claim address + * + ****************************************************************************/ + +uintptr_t mpfs_plic_get_claimbase(void) +{ + uintptr_t claim_address; + uint64_t hart_id = riscv_mhartid(); + + if (hart_id == 0) + { + claim_address = MPFS_PLIC_H0_MCLAIM; + } + else + { + claim_address = MPFS_PLIC_H1_MCLAIM + + ((hart_id - 1) * MPFS_PLIC_NEXTHART_OFFSET); + } + + return claim_address; +} + +/**************************************************************************** + * Name: mpfs_plic_get_thresholdbase + * + * Description: + * Context aware way to query PLIC interrupt threshold base address + * + * Returned Value: + * Interrupt enable threshold address + * + ****************************************************************************/ + +uintptr_t mpfs_plic_get_thresholdbase(void) +{ + uint32_t *threshold_address; + uint64_t hart_id = riscv_mhartid(); + + if (hart_id == 0) + { + threshold_address = (uint32_t *)MPFS_PLIC_H0_MTHRESHOLD; Review comment: ```suggestion threshold_address = MPFS_PLIC_H0_MTHRESHOLD; ``` ########## File path: arch/risc-v/src/mpfs/mpfs_plic.c ########## @@ -0,0 +1,131 @@ +/**************************************************************************** + * arch/risc-v/src/mpfs/mpfs_plic.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdint.h> +#include <stdio.h> +#include <assert.h> +#include <debug.h> + +#include <nuttx/arch.h> +#include <arch/irq.h> + +#include "mpfs.h" +#include "mpfs_plic.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mpfs_plic_get_iebase + * + * Description: + * Context aware way to query PLIC interrupt enable base address + * + * Returned Value: + * Interrupt enable base address + * + ****************************************************************************/ + +uintptr_t mpfs_plic_get_iebase(void) +{ + uint32_t *iebase; + uint64_t hart_id = riscv_mhartid(); + + if (hart_id == 0) + { + iebase = (uint32_t *)MPFS_PLIC_H0_MIE0; + } + else + { + iebase = (uint32_t *)(MPFS_PLIC_H1_MIE0 + + (hart_id - 1) * MPFS_HART_MIE_OFFSET); + } + + return (uintptr_t) iebase; +} + +/**************************************************************************** + * Name: mpfs_plic_get_claimbase + * + * Description: + * Context aware way to query PLIC interrupt claim base address + * + * Returned Value: + * Interrupt enable claim address + * + ****************************************************************************/ + +uintptr_t mpfs_plic_get_claimbase(void) +{ + uintptr_t claim_address; + uint64_t hart_id = riscv_mhartid(); + + if (hart_id == 0) + { + claim_address = MPFS_PLIC_H0_MCLAIM; + } + else + { + claim_address = MPFS_PLIC_H1_MCLAIM + + ((hart_id - 1) * MPFS_PLIC_NEXTHART_OFFSET); + } + + return claim_address; +} + +/**************************************************************************** + * Name: mpfs_plic_get_thresholdbase + * + * Description: + * Context aware way to query PLIC interrupt threshold base address + * + * Returned Value: + * Interrupt enable threshold address + * + ****************************************************************************/ + +uintptr_t mpfs_plic_get_thresholdbase(void) +{ + uint32_t *threshold_address; + uint64_t hart_id = riscv_mhartid(); + + if (hart_id == 0) + { + threshold_address = (uint32_t *)MPFS_PLIC_H0_MTHRESHOLD; + } + else + { + threshold_address = (uint32_t *)(MPFS_PLIC_H1_MTHRESHOLD + + ((hart_id - 1) * MPFS_PLIC_NEXTHART_OFFSET)); Review comment: ```suggestion threshold_address = MPFS_PLIC_H1_MTHRESHOLD + (hart_id - 1) * MPFS_PLIC_NEXTHART_OFFSET; ``` ########## File path: arch/risc-v/src/mpfs/mpfs_plic.c ########## @@ -0,0 +1,131 @@ +/**************************************************************************** + * arch/risc-v/src/mpfs/mpfs_plic.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdint.h> +#include <stdio.h> +#include <assert.h> +#include <debug.h> + +#include <nuttx/arch.h> +#include <arch/irq.h> + +#include "mpfs.h" +#include "mpfs_plic.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mpfs_plic_get_iebase + * + * Description: + * Context aware way to query PLIC interrupt enable base address + * + * Returned Value: + * Interrupt enable base address + * + ****************************************************************************/ + +uintptr_t mpfs_plic_get_iebase(void) +{ + uint32_t *iebase; + uint64_t hart_id = riscv_mhartid(); + + if (hart_id == 0) + { + iebase = (uint32_t *)MPFS_PLIC_H0_MIE0; Review comment: ```suggestion iebase = MPFS_PLIC_H0_MIE0; ``` ########## File path: arch/risc-v/src/mpfs/Make.defs ########## @@ -55,19 +56,29 @@ CHIP_CSRCS += mpfs_irq.c mpfs_irq_dispatch.c CHIP_CSRCS += mpfs_lowputc.c mpfs_serial.c CHIP_CSRCS += mpfs_start.c mpfs_timerisr.c CHIP_CSRCS += mpfs_gpio.c mpfs_systemreset.c +CHIP_CSRCS += mpfs_plic.c ifeq ($(CONFIG_MPFS_DMA),y) CHIP_CSRCS += mpfs_dma.c endif -ifeq ($(CONFIG_BUILD_PROTECTED),y) -CMN_CSRCS += riscv_task_start.c -CMN_CSRCS += riscv_pthread_start.c -CMN_CSRCS += riscv_signal_dispatch.c +# Flag to enable certain modules for non-flat builds (PROTECTED/KERNEL) +__MPFS_BUILD_NONFLAT = +ifeq ($(CONFIG_BUILD_PROTECTED),y) +CHIP_CSRCS += mpfs_userspace.c CMN_UASRCS += riscv_signal_handler.S +__MPFS_BUILD_NONFLAT=y +endif -CHIP_CSRCS += mpfs_userspace.c +ifeq ($(CONFIG_BUILD_KERNEL),y) +__MPFS_BUILD_NONFLAT=y +endif + +ifeq ($(__MPFS_BUILD_NONFLAT),y) +CMN_CSRCS += riscv_task_start.c Review comment: ```suggestion CMN_CSRCS += riscv_task_start.c ``` ########## File path: arch/risc-v/src/mpfs/mpfs_plic.c ########## @@ -0,0 +1,131 @@ +/**************************************************************************** + * arch/risc-v/src/mpfs/mpfs_plic.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdint.h> +#include <stdio.h> +#include <assert.h> +#include <debug.h> + +#include <nuttx/arch.h> +#include <arch/irq.h> + +#include "mpfs.h" +#include "mpfs_plic.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mpfs_plic_get_iebase + * + * Description: + * Context aware way to query PLIC interrupt enable base address + * + * Returned Value: + * Interrupt enable base address + * + ****************************************************************************/ + +uintptr_t mpfs_plic_get_iebase(void) +{ + uint32_t *iebase; + uint64_t hart_id = riscv_mhartid(); + + if (hart_id == 0) + { + iebase = (uint32_t *)MPFS_PLIC_H0_MIE0; + } + else + { + iebase = (uint32_t *)(MPFS_PLIC_H1_MIE0 + + (hart_id - 1) * MPFS_HART_MIE_OFFSET); + } + + return (uintptr_t) iebase; +} + +/**************************************************************************** + * Name: mpfs_plic_get_claimbase + * + * Description: + * Context aware way to query PLIC interrupt claim base address + * + * Returned Value: + * Interrupt enable claim address + * + ****************************************************************************/ + +uintptr_t mpfs_plic_get_claimbase(void) +{ + uintptr_t claim_address; + uint64_t hart_id = riscv_mhartid(); + + if (hart_id == 0) + { + claim_address = MPFS_PLIC_H0_MCLAIM; + } + else + { + claim_address = MPFS_PLIC_H1_MCLAIM + + ((hart_id - 1) * MPFS_PLIC_NEXTHART_OFFSET); + } + + return claim_address; +} + +/**************************************************************************** + * Name: mpfs_plic_get_thresholdbase + * + * Description: + * Context aware way to query PLIC interrupt threshold base address + * + * Returned Value: + * Interrupt enable threshold address + * + ****************************************************************************/ + +uintptr_t mpfs_plic_get_thresholdbase(void) +{ + uint32_t *threshold_address; Review comment: ```suggestion uintptr_t threshold_address; ``` ########## File path: arch/risc-v/src/common/riscv_internal.h ########## @@ -253,6 +253,19 @@ void riscv_cpu_boot(int cpu); int riscv_pause_handler(int irq, void *c, void *arg); #endif +/**************************************************************************** + * Name: riscv_mhartid + * + * Description: + * Context aware way to query hart id + * + * Returned Value: + * Hart id + * + ****************************************************************************/ + +uint64_t riscv_mhartid(void); Review comment: Does it really need to be `uint64_t`? I mean maybe we can use `uintptr_t`? ########## File path: arch/risc-v/src/mpfs/mpfs_plic.c ########## @@ -0,0 +1,131 @@ +/**************************************************************************** + * arch/risc-v/src/mpfs/mpfs_plic.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdint.h> +#include <stdio.h> +#include <assert.h> +#include <debug.h> + +#include <nuttx/arch.h> +#include <arch/irq.h> + +#include "mpfs.h" +#include "mpfs_plic.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mpfs_plic_get_iebase + * + * Description: + * Context aware way to query PLIC interrupt enable base address + * + * Returned Value: + * Interrupt enable base address + * + ****************************************************************************/ + +uintptr_t mpfs_plic_get_iebase(void) +{ + uint32_t *iebase; + uint64_t hart_id = riscv_mhartid(); + + if (hart_id == 0) + { + iebase = (uint32_t *)MPFS_PLIC_H0_MIE0; + } + else + { + iebase = (uint32_t *)(MPFS_PLIC_H1_MIE0 + + (hart_id - 1) * MPFS_HART_MIE_OFFSET); + } + + return (uintptr_t) iebase; +} + +/**************************************************************************** + * Name: mpfs_plic_get_claimbase + * + * Description: + * Context aware way to query PLIC interrupt claim base address + * + * Returned Value: + * Interrupt enable claim address + * + ****************************************************************************/ + +uintptr_t mpfs_plic_get_claimbase(void) +{ + uintptr_t claim_address; + uint64_t hart_id = riscv_mhartid(); + + if (hart_id == 0) + { + claim_address = MPFS_PLIC_H0_MCLAIM; + } + else + { + claim_address = MPFS_PLIC_H1_MCLAIM + + ((hart_id - 1) * MPFS_PLIC_NEXTHART_OFFSET); Review comment: ```suggestion claim_address = MPFS_PLIC_H1_MCLAIM + (hart_id - 1) * MPFS_PLIC_NEXTHART_OFFSET; ``` ########## File path: arch/risc-v/src/mpfs/mpfs_plic.h ########## @@ -0,0 +1,73 @@ +/**************************************************************************** + * arch/risc-v/src/mpfs/mpfs_plic.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __ARCH_RISC_V_SRC_MPFS_MPFS_PLIC_H_ +#define __ARCH_RISC_V_SRC_MPFS_MPFS_PLIC_H_ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <stdint.h> + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: mpfs_plic_get_iebase + * + * Description: + * Context aware way to query PLIC interrupt enable base address + * + * Returned Value: + * Interrupt enable base address + * + ****************************************************************************/ + +uintptr_t mpfs_plic_get_iebase(void); + +/**************************************************************************** + * Name: mpfs_plic_get_claimbase + * + * Description: + * Context aware way to query PLIC interrupt claim base address + * + * Returned Value: + * Interrupt enable claim address + * + ****************************************************************************/ + +uintptr_t mpfs_plic_get_claimbase(void); + +/**************************************************************************** + * Name: mpfs_plic_get_thresholdbase + * + * Description: + * Context aware way to query PLIC interrupt threshold base address + * + * Returned Value: + * Interrupt enable threshold address + * + ****************************************************************************/ + +uintptr_t mpfs_plic_get_thresholdbase(void); + +#endif /* __ARCH_RISC_V_SRC_MPFS_MPFS_PLIC_H_ */ Review comment: ```suggestion #endif /* __ARCH_RISC_V_SRC_MPFS_MPFS_PLIC_H */ ``` ########## File path: arch/risc-v/src/mpfs/mpfs_plic.c ########## @@ -0,0 +1,131 @@ +/**************************************************************************** + * arch/risc-v/src/mpfs/mpfs_plic.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdint.h> +#include <stdio.h> +#include <assert.h> +#include <debug.h> + +#include <nuttx/arch.h> +#include <arch/irq.h> + +#include "mpfs.h" +#include "mpfs_plic.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: mpfs_plic_get_iebase + * + * Description: + * Context aware way to query PLIC interrupt enable base address + * + * Returned Value: + * Interrupt enable base address + * + ****************************************************************************/ + +uintptr_t mpfs_plic_get_iebase(void) +{ + uint32_t *iebase; + uint64_t hart_id = riscv_mhartid(); + + if (hart_id == 0) + { + iebase = (uint32_t *)MPFS_PLIC_H0_MIE0; + } + else + { + iebase = (uint32_t *)(MPFS_PLIC_H1_MIE0 + + (hart_id - 1) * MPFS_HART_MIE_OFFSET); Review comment: ```suggestion iebase = MPFS_PLIC_H1_MIE0 + (hart_id - 1) * MPFS_HART_MIE_OFFSET; ``` -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
