Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

soc: riscv: andes_v5: update ae350 soc #59813

Merged
merged 12 commits into from
Jul 17, 2023

Conversation

jimmyzhe
Copy link
Collaborator

This PR refines ae350 porting and adds some Andes features below.

  • Refine exist code:

    • AE350 linker script
    • PMA driver
    • L2 cache driver
  • Enable RISC-V feature on AE350:

    • PMP
    • RV32E
    • C extension
  • Add Andes feature:

    • EXEC.IT (Execution on Instruction Table )
      EXEC.IT is supported by Andes V5 toolchain which generates a look-up table and replaces suitable 32-bit instructions with the 16-bit exec.it instruction to decrease code size.
    • IOCP (I/O Coherence Port)
      IOCP handle cache coherency between cache and external non-caching master, such DMA controller.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are the changes in this file valid in general for all the RISCV boards or just for Andes?

Copy link
Collaborator Author

@jimmyzhe jimmyzhe Jul 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference between RISC-V generic linker.ld and ae350 linker.ld is as follows:

  1. apply MPU_ALIGN to __rom_region_start and __rom_region_end (for XIP only).
  2. redefine MPU_ALIGN to match the granularity of PMA

I think (1) applies to all RISC-V boards, while (2) is specific to Andes boards.

@@ -28,6 +28,12 @@ config RV32I_CPU
select RISCV_ISA_EXT_ZICSR
select RISCV_ISA_EXT_ZIFENCEI

config RV32E_CPU
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have CONFIG_RISCV_ISA_RV32E, why this is needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AE350 is FPGA based platform and we want RV32E can be selected by
menuconfig or board_defconfig for AE350 bitstream integrate with RV32E core.

Comment on lines +63 to +64
/* Memory barrier, flush all I/D-Cache before setting L2C */
__asm__ volatile ("fence.i");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the newly introduced barrier API for this. See include/zephyr/sys/barrier.h

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Andes core needs to execute fence.i to flush all I/D cache before updating the L2 cache function.
The barrier API in RISC-V seems only support fence instruction.
Maybe I can modify the comment to avoid confusion.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right but why you cannot use fence here instead of fence.i? AFAIK fence should be just a bit more restrictive.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Andes core, fence instruction is used to order device I/O and memory accesses as viewed by other RISC-V harts and external devices, but it does not perform any operation on the local I/D cache.
fence.i is used to synchronizing the L1 and L2 cache due to the hardware limitation of Andes L2 cache.

# HW DSP options
#CONFIG_SOC_ANDES_V5_HWDSP=y

# EXEC.IT options
#CONFIG_SOC_ANDES_V5_EXECIT=y
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this commented out?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only Andes toolchain support this option, disable this option for zephyr-sdk.

# Cache options
CONFIG_CACHE_ENABLE=y

# Nocache memory options
#CONFIG_SOC_ANDES_V5_PMA=y
#CONFIG_NOCACHE_MEMORY=y

# I/O Coherence Port options
#CONFIG_SOC_ANDES_V5_IOCP=y
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all of AE350 bitstream support IOCP, disable this option for various AE350 bitstream compatible.

case 15:
write_csr(NDS_PMAADDR15, value); break;
csr_write(NDS_PMAADDR15, value); break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a lot of repeated code. Can you generate it with FOR_EACH helper macro?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice suggestion, fixed it, thank you.

case 3:
read_csr(pmacfg, NDS_PMACFG3); break;
pmacfg = csr_read(NDS_PMACFG3); break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto - FOR_EACH could help reduce the repeated code.

case 3:
write_csr(NDS_PMACFG3, pmacfg); break;
csr_write(NDS_PMACFG3, pmacfg); break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto - FOR_EACH could help reduce the repeated code.

Fix mtimer lack of interrupts-extended and make syscon compatilbe to
atcsmu100.

Signed-off-by: Jimmy Zheng <[email protected]>
Synchronize ae350 linker.ld with riscv generic linker.ld and workaround
kernel object address may be 0x0 in XIP system.

Signed-off-by: Jimmy Zheng <[email protected]>
Refine PMA driver and define MPU_ALIGN() to PMA granularity in
RAM_SECTIONS, otherwise MPU_ALIGN() is defined to PMP granularity.

Signed-off-by: Jimmy Zheng <[email protected]>
Enable PMP and set PMP granularity to 8 for most of ae350 bitstream.
This commit also make MPU_ALIGN() apply to __rom_region_end in XIP system.

Signed-off-by: Jimmy Zheng <[email protected]>
Enable RISC-V C extension for Andes core.

Signed-off-by: Jimmy Zheng <[email protected]>
Add CONFIG_RV32E_CPU for AE350 platform integrated with Andes RV32E core,
such as N22, D23 core.

Signed-off-by: Jimmy Zheng <[email protected]>
Andes EXEC.IT (Execution on Instruction Table) is supported by Andes
toolchain only. Andes toolchain will replaces suitable 32-bit instructions
with the 16-bit "exec.it <INDEX>" in which <INDEX> points to a
corresponding 32-bit instruction in look up table.

Signed-off-by: Jimmy Zheng <[email protected]>
Refine source code and flush all I/D-Cache before update L2 cache register.

Signed-off-by: Jimmy Zheng <[email protected]>
Add CONFIG_SOC_ANDES_V5_IOCP to indicate Andes I/O Coherence Port handle
cache coherency between cache and external non-caching master, such as DMA
controller.

Signed-off-by: Jimmy Zheng <[email protected]>
Enlarge TEST_EXTRA_STACK_SIZE for AE350 RV64 bitstream.

Signed-off-by: Jimmy Zheng <[email protected]>
Exclude adp_xc7k_ae350 because Andes core doesn't support RISC-V vectored
mode from csr $mtvec.

Signed-off-by: Jimmy Zheng <[email protected]>
Replace redundant CONFIG_CACHE_ENABLE by generic Kconfig CONFIG_ICACHE,
CONFIG_DCACHE.

Signed-off-by: Jimmy Zheng <[email protected]>
@jimmyzhe
Copy link
Collaborator Author

jimmyzhe commented Jul 3, 2023

Based on the conversation in #59041, I have removed the redundant Kconfig CONFIG_CACHE_ENABLE, thank you @carlocaione for your comment.

Copy link
Collaborator

@carlocaione carlocaione left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general LGTM. I cannot vouch for the soc-specific changes but being self-contained in the soc/board directories I'm ok with that.

@fabiobaltieri fabiobaltieri merged commit 4f26203 into zephyrproject-rtos:main Jul 17, 2023
18 checks passed
@jimmyzhe jimmyzhe deleted the update_andes_v5 branch July 18, 2023 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Kernel area: RISCV RISCV Architecture (32-bit & 64-bit)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants