summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Gaisler <jiri@gaisler.se>2019-01-18 18:00:47 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2019-01-22 12:50:08 +0100
commit9b2b389e8d6c9a871a3d5de882fc48b13bc9f1ac (patch)
tree813132b05c576d8327ae012439feb7207289f8c6
parentgrlib: use rtems_interrupt_handler_install() (diff)
downloadrtems-9b2b389e8d6c9a871a3d5de882fc48b13bc9f1ac.tar.bz2
grlib: use cpu-independent routines for uncached access
Update #3678.
-rw-r--r--bsps/include/grlib/grlib_impl.h52
-rw-r--r--bsps/shared/grlib/1553/b1553brm.c10
-rw-r--r--bsps/shared/grlib/1553/b1553rt.c11
-rw-r--r--bsps/shared/grlib/can/grcan.c27
-rw-r--r--bsps/shared/grlib/pci/grpci2dma.c2
-rw-r--r--bsps/shared/grlib/spw/grspw.c29
-rw-r--r--bsps/shared/grlib/spw/grspw_pkt.c2
-rw-r--r--cpukit/score/cpu/riscv/headers.am2
-rw-r--r--cpukit/score/cpu/riscv/include/libcpu/access.h50
-rw-r--r--cpukit/score/cpu/riscv/include/libcpu/byteorder.h31
10 files changed, 145 insertions, 71 deletions
diff --git a/bsps/include/grlib/grlib_impl.h b/bsps/include/grlib/grlib_impl.h
index 9a7fa15a5e..dd6bcc64b7 100644
--- a/bsps/include/grlib/grlib_impl.h
+++ b/bsps/include/grlib/grlib_impl.h
@@ -90,6 +90,58 @@ RTEMS_INLINE_ROUTINE void *grlib_calloc(size_t nelem, size_t elsize)
#endif
+#ifdef __sparc__
+
+RTEMS_INLINE_ROUTINE unsigned char grlib_read_uncached8(unsigned int address)
+{
+ unsigned char tmp;
+ __asm__ (" lduba [%1]1, %0 "
+ : "=r"(tmp)
+ : "r"(address)
+ );
+ return tmp;
+}
+
+RTEMS_INLINE_ROUTINE unsigned short grlib_read_uncached16(unsigned int addr) {
+ unsigned short tmp;
+ __asm__ (" lduha [%1]1, %0 "
+ : "=r"(tmp)
+ : "r"(addr)
+ );
+ return tmp;
+}
+
+
+RTEMS_INLINE_ROUTINE unsigned int grlib_read_uncached32(unsigned int address)
+{
+ unsigned int tmp;
+ __asm__ (" lda [%1]1, %0 "
+ : "=r"(tmp)
+ : "r"(address)
+ );
+ return tmp;
+}
+#else
+
+static unsigned char __inline__ grlib_read_uncached8(unsigned int address)
+{
+ unsigned char tmp = (*(volatile unsigned char *)(address));
+ return tmp;
+}
+
+static __inline__ unsigned short grlib_read_uncached16(unsigned int address) {
+ unsigned short tmp = (*(volatile unsigned short *)(address));
+ return tmp;
+}
+
+RTEMS_INLINE_ROUTINE unsigned int grlib_read_uncached32(unsigned int address)
+{
+ unsigned int tmp = (*(volatile unsigned int *)(address));
+ return tmp;
+}
+
+#endif
+
extern struct ambapp_bus ambapp_plb;
#ifdef __cplusplus
diff --git a/bsps/shared/grlib/1553/b1553brm.c b/bsps/shared/grlib/1553/b1553brm.c
index 5575abb525..57ef70126b 100644
--- a/bsps/shared/grlib/1553/b1553brm.c
+++ b/bsps/shared/grlib/1553/b1553brm.c
@@ -59,15 +59,7 @@
#endif
#define READ_REG(address) (*(volatile unsigned int *)address)
-#define READ_DMA(address) _BRM_REG_READ16((unsigned int)address)
-static __inline__ unsigned short _BRM_REG_READ16(unsigned int addr) {
- unsigned short tmp;
- __asm__ (" lduha [%1]1, %0 "
- : "=r"(tmp)
- : "r"(addr)
- );
- return tmp;
-}
+#define READ_DMA(address) grlib_read_uncached16((unsigned int)address)
static rtems_device_driver brm_initialize(rtems_device_major_number major, rtems_device_minor_number minor, void *arg);
static rtems_device_driver brm_open(rtems_device_major_number major, rtems_device_minor_number minor, void *arg);
diff --git a/bsps/shared/grlib/1553/b1553rt.c b/bsps/shared/grlib/1553/b1553rt.c
index 35afd901c8..d7257e461f 100644
--- a/bsps/shared/grlib/1553/b1553rt.c
+++ b/bsps/shared/grlib/1553/b1553rt.c
@@ -52,16 +52,7 @@
#define FUNCDBG(x...)
#endif
-#define READ_DMA(address) _READ16((unsigned int)address)
-
-static __inline__ unsigned short _READ16(unsigned int addr) {
- unsigned short tmp;
- asm(" lduha [%1]1, %0 "
- : "=r"(tmp)
- : "r"(addr)
- );
- return tmp;
-}
+#define READ_DMA(address) grlib_read_uncached16((unsigned int)address)
static rtems_device_driver rt_initialize(rtems_device_major_number major, rtems_device_minor_number minor, void *arg);
static rtems_device_driver rt_open(rtems_device_major_number major, rtems_device_minor_number minor, void *arg);
diff --git a/bsps/shared/grlib/can/grcan.c b/bsps/shared/grlib/can/grcan.c
index 55154d823a..d69d99d85a 100644
--- a/bsps/shared/grlib/can/grcan.c
+++ b/bsps/shared/grlib/can/grcan.c
@@ -165,40 +165,19 @@ static void grcan_hw_sync(
static void grcan_interrupt(void *arg);
#ifdef GRCAN_REG_BYPASS_CACHE
-#define READ_REG(address) _grcan_read_nocache((unsigned int)(address))
+#define READ_REG(address) grlib_read_uncached32((unsigned int)(address))
#else
#define READ_REG(address) (*(volatile unsigned int *)(address))
#endif
#ifdef GRCAN_DMA_BYPASS_CACHE
-#define READ_DMA_WORD(address) _grcan_read_nocache((unsigned int)(address))
-#define READ_DMA_BYTE(address) _grcan_read_nocache_byte((unsigned int)(address))
-static unsigned char __inline__ _grcan_read_nocache_byte(unsigned int address)
-{
- unsigned char tmp;
- __asm__ (" lduba [%1]1, %0 "
- : "=r"(tmp)
- : "r"(address)
- );
- return tmp;
-}
+#define READ_DMA_WORD(address) grlib_read_uncached32((unsigned int)(address))
+#define READ_DMA_BYTE(address) grlib_read_uncached8((unsigned int)(address))
#else
#define READ_DMA_WORD(address) (*(volatile unsigned int *)(address))
#define READ_DMA_BYTE(address) (*(volatile unsigned char *)(address))
#endif
-#if defined(GRCAN_REG_BYPASS_CACHE) || defined(GRCAN_DMA_BYPASS_CACHE)
-static unsigned int __inline__ _grcan_read_nocache(unsigned int address)
-{
- unsigned int tmp;
- __asm__ (" lda [%1]1, %0 "
- : "=r"(tmp)
- : "r"(address)
- );
- return tmp;
-}
-#endif
-
#define NELEM(a) ((int) (sizeof (a) / sizeof (a[0])))
static int grcan_count = 0;
diff --git a/bsps/shared/grlib/pci/grpci2dma.c b/bsps/shared/grlib/pci/grpci2dma.c
index 7e39ca691d..cb41d48966 100644
--- a/bsps/shared/grlib/pci/grpci2dma.c
+++ b/bsps/shared/grlib/pci/grpci2dma.c
@@ -98,7 +98,7 @@
/* Memory and HW Registers Access routines. All 32-bit access routines */
#define BD_WRITE(addr, val) (*(volatile unsigned int *)(addr) = (unsigned int)(val))
/*#define BD_READ(addr) (*(volatile unsigned int *)(addr))*/
-#define BD_READ(addr) leon_r32_no_cache((unsigned long)(addr))
+#define BD_READ(addr) grlib_read_uncached32((unsigned long)(addr))
#define REG_WRITE(addr, val) (*(volatile unsigned int *)(addr) = (unsigned int)(val))
#define REG_READ(addr) (*(volatile unsigned int *)(addr))
diff --git a/bsps/shared/grlib/spw/grspw.c b/bsps/shared/grlib/spw/grspw.c
index ca0f63edd8..586bb2537c 100644
--- a/bsps/shared/grlib/spw/grspw.c
+++ b/bsps/shared/grlib/spw/grspw.c
@@ -152,32 +152,9 @@ void (*grspw_timecode_callback)
#define _MEM_READ8(address) (*(volatile unsigned char *)(address))
#define _MEM_READ32(address) (*(volatile unsigned int *)(address))
#else
-static inline unsigned int _SPW_READ(volatile void *addr) {
- unsigned int tmp;
- __asm__ (" lda [%1]1, %0 "
- : "=r"(tmp)
- : "r"(addr)
- );
- return tmp;
-}
-
-static inline unsigned int _MEM_READ8(volatile void *addr) {
- unsigned int tmp;
- __asm__ (" lduba [%1]1, %0 "
- : "=r"(tmp)
- : "r"(addr)
- );
- return tmp;
-}
-
-static inline unsigned int _MEM_READ32(volatile void *addr) {
- unsigned int tmp;
- __asm__ (" lda [%1]1, %0 "
- : "=r"(tmp)
- : "r"(addr)
- );
- return tmp;
-}
+#define _SPW_READ(address) grlib_read_uncached32((unsigned int) address)
+#define _MEM_READ8(address) grlib_read_uncached8((unsigned int) address)
+#define _MEM_READ32(address) grlib_read_uncached32((unsigned int) address)
#endif
#define MEM_READ8(addr) _MEM_READ8((volatile void *)(addr))
diff --git a/bsps/shared/grlib/spw/grspw_pkt.c b/bsps/shared/grlib/spw/grspw_pkt.c
index 208f5a14f7..56b39d78db 100644
--- a/bsps/shared/grlib/spw/grspw_pkt.c
+++ b/bsps/shared/grlib/spw/grspw_pkt.c
@@ -315,7 +315,7 @@ struct grspw_txbd {
/* Memory and HW Registers Access routines. All 32-bit access routines */
#define BD_WRITE(addr, val) (*(volatile unsigned int *)(addr) = (unsigned int)(val))
/*#define BD_READ(addr) (*(volatile unsigned int *)(addr))*/
-#define BD_READ(addr) leon_r32_no_cache((unsigned long)(addr))
+#define BD_READ(addr) grlib_read_uncached32((unsigned long)(addr))
#define REG_WRITE(addr, val) (*(volatile unsigned int *)(addr) = (unsigned int)(val))
#define REG_READ(addr) (*(volatile unsigned int *)(addr))
diff --git a/cpukit/score/cpu/riscv/headers.am b/cpukit/score/cpu/riscv/headers.am
index 415075ce46..abb8a42f78 100644
--- a/cpukit/score/cpu/riscv/headers.am
+++ b/cpukit/score/cpu/riscv/headers.am
@@ -1,4 +1,6 @@
## This file was generated by "./boostrap -H".
+include_libcpu_HEADERS += score/cpu/riscv/include/libcpu/access.h
+include_libcpu_HEADERS += score/cpu/riscv/include/libcpu/byteorder.h
include_rtems_HEADERS += score/cpu/riscv/include/rtems/asm.h
include_rtems_score_HEADERS += score/cpu/riscv/include/rtems/score/cpu.h
include_rtems_score_HEADERS += score/cpu/riscv/include/rtems/score/cpu_asm.h
diff --git a/cpukit/score/cpu/riscv/include/libcpu/access.h b/cpukit/score/cpu/riscv/include/libcpu/access.h
new file mode 100644
index 0000000000..cdf6b77122
--- /dev/null
+++ b/cpukit/score/cpu/riscv/include/libcpu/access.h
@@ -0,0 +1,50 @@
+/*
+ * access.h - access routines for SPARC. SPARC is big endian only.
+ *
+ * COPYRIGHT (c) 2011
+ * Aeroflex Gaisler.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#ifndef _LIBCPU_ACCESS_H
+#define _LIBCPU_ACCESS_H
+
+#include <rtems/system.h>
+#include <rtems/score/cpu.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* "Raw" access */
+extern uint8_t _ld8(uint8_t *addr);
+extern void _st8(uint8_t *addr, uint8_t val);
+extern uint16_t _ld16(uint16_t *addr);
+extern void _st16(uint16_t *addr, uint16_t val);
+extern uint32_t _ld32(uint32_t *addr);
+extern void _st32(uint32_t *addr, uint32_t val);
+extern uint64_t _ld64(uint64_t *addr);
+extern void _st64(uint64_t *addr, uint64_t val);
+
+/* Aliases for Big Endian */
+extern uint16_t _ld_be16(uint16_t *addr);
+extern void _st_be16(uint16_t *addr, uint16_t val);
+extern uint32_t _ld_be32(uint32_t *addr);
+extern void _st_be32(uint32_t *addr, uint32_t val);
+extern uint64_t _ld_be64(uint64_t *addr);
+extern void _st_be64(uint64_t *addr, uint64_t val);
+
+/* Little endian */
+extern uint16_t _ld_le16(uint16_t *addr);
+extern void _st_le16(uint16_t *addr, uint16_t val);
+extern uint32_t _ld_le32(uint32_t *addr);
+extern void _st_le32(uint32_t *addr, uint32_t val);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/score/cpu/riscv/include/libcpu/byteorder.h b/cpukit/score/cpu/riscv/include/libcpu/byteorder.h
new file mode 100644
index 0000000000..939e51fe84
--- /dev/null
+++ b/cpukit/score/cpu/riscv/include/libcpu/byteorder.h
@@ -0,0 +1,31 @@
+/*
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#ifndef _LIBCPU_BYTEORDER_H
+#define _LIBCPU_BYTEORDER_H
+
+static inline void st_le32(volatile uint32_t *addr, uint32_t value)
+{
+ *(addr)=value ;
+}
+
+static inline uint32_t ld_le32(volatile uint32_t *addr)
+{
+ return(*addr);
+}
+
+static inline void st_le16(volatile uint16_t *addr, uint16_t value)
+{
+ *(addr)=value ;
+}
+
+static inline uint16_t ld_le16(volatile uint16_t *addr)
+{
+ return(*addr);
+}
+
+
+#endif