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

riscv/barrier: Define more granular memory barriers #9538

Merged
merged 1 commit into from Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 14 additions & 6 deletions arch/risc-v/include/barriers.h
Expand Up @@ -21,12 +21,20 @@
#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
*/
/* Common memory barriers (p=predecessor, s=successor) */

#define __DMB() __asm__ __volatile__ ("fence" ::: "memory")
#define __ISB() __asm__ __volatile__ ("fence.i" ::: "memory")
#define __FENCE(p, s) __asm__ __volatile__ ("fence "#p", "#s ::: "memory")

/* __DMB() is used to flush local data caches (memory) */

#define __DMB() __FENCE(rw, rw)

/* __MB() is a full memory barrier */

#define __MB() __FENCE(iorw, iorw)

/* __ISB() is used to synchronize the instruction and data streams */

#define __ISB() __asm__ __volatile__ ("fence.i" ::: "memory")

#endif /* __ARCH_RISCV_INCLUDE_BARRIERS_H */
4 changes: 1 addition & 3 deletions arch/risc-v/src/common/riscv_addrenv.c
Expand Up @@ -736,10 +736,8 @@ int up_addrenv_select(const arch_addrenv_t *addrenv)

int up_addrenv_coherent(const arch_addrenv_t *addrenv)
{
/* Flush the instruction and data caches */
/* Nothing needs to be done */

__ISB();
__DMB();
return OK;
}

Expand Down
3 changes: 2 additions & 1 deletion arch/risc-v/src/common/riscv_mmu.h
Expand Up @@ -187,7 +187,8 @@ static inline void mmu_write_satp(uintptr_t reg)
(
"csrw satp, %0\n"
"sfence.vma x0, x0\n"
"fence\n"
"fence rw, rw\n"
"fence.i\n"
:
: "rK" (reg)
: "memory"
Expand Down
2 changes: 1 addition & 1 deletion arch/risc-v/src/common/riscv_mtimer.c
Expand Up @@ -124,7 +124,7 @@ static void riscv_mtimer_set_mtimecmp(struct riscv_mtimer_lowerhalf_s *priv,

/* Make sure it sticks */

__DMB();
__MB();
}
#else
static uint64_t riscv_mtimer_get_mtime(struct riscv_mtimer_lowerhalf_s *priv)
Expand Down
2 changes: 1 addition & 1 deletion arch/risc-v/src/common/riscv_percpu.c
Expand Up @@ -147,7 +147,7 @@ void riscv_percpu_add_hart(uintptr_t hartid)

/* Make sure it sticks */

__DMB();
__MB();
}

/****************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion arch/risc-v/src/mpfs/mpfs_gpio.c
Expand Up @@ -100,7 +100,7 @@ static struct gpio_callback_s g_mss_gpio_callbacks[GPIO_BANK0_NUM_PINS +
static void mpfs_gpio_irq_clear(int bank, int pin)
{
putreg32(1 << pin, g_gpio_base[bank] + MPFS_GPIO_INTR_OFFSET);
__DMB();
__MB();
}

/****************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion arch/risc-v/src/nuttsbi/sbi_mscratch.c
Expand Up @@ -81,5 +81,5 @@ void sbi_mscratch_assign(uintptr_t hartid)

/* Make sure mscratch is updated before continuing */

__DMB();
__MB();
}
2 changes: 1 addition & 1 deletion arch/risc-v/src/nuttsbi/sbi_mtimer.c
Expand Up @@ -96,5 +96,5 @@ void sbi_set_mtimecmp(uint64_t value)

/* Make sure it sticks */

__DMB();
__MB();
}