Skip to content

Commit

Permalink
Add memory barriers wbflush, mb and iobarrier_rw
Browse files Browse the repository at this point in the history
  • Loading branch information
frno7 committed Dec 15, 2020
1 parent 0c2ed89 commit d4caf4c
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions include/iopmod/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,34 @@
#ifndef IOPMOD_IO_H
#define IOPMOD_IO_H

#include "iopmod/addrspace.h"
#include "iopmod/types.h"

/* Use I/O read and write with KSEG1. */

/* Macro definition from the Linux kernel. */
#define __fast_iob() \
__asm__ __volatile__( \
".set push\n\t" \
".set noreorder\n\t" \
"lw $0,%0\n\t" \
"nop\n\t" \
".set pop" \
: /* No output. */ \
: "m" (*(int *)CKSEG1) \
: "memory")

#define wbflush() __fast_iob()

#define mb() wbflush()
#define iobarrier_rw() mb()

#define DEFINE_IORD(type, name) \
static inline type name(const u32 addr) \
{ \
const volatile type *__addr = (const volatile type *)addr; \
\
/* FIXME: Crashes? __sync_synchronize(); */ \
iobarrier_rw(); \
\
return *__addr; \
}
Expand All @@ -29,7 +47,7 @@ static inline void name(type value, u32 addr) \
{ \
volatile type *__addr = (volatile type *)addr; \
\
/* FIXME: Crashes? __sync_synchronize(); */ \
iobarrier_rw(); \
\
*__addr = value; \
}
Expand Down

0 comments on commit d4caf4c

Please sign in to comment.