grlib: use cpu-independent routines for uncached access

Update #3678.
This commit is contained in:
Jiri Gaisler
2019-01-18 18:00:47 +01:00
committed by Sebastian Huber
parent 5981c8ca9f
commit 9b2b389e8d
10 changed files with 145 additions and 71 deletions

View File

@@ -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

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;

View File

@@ -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))

View File

@@ -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))

View File

@@ -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))

View File

@@ -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

View File

@@ -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

View File

@@ -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