[PATCH v2 6/7] grlib: use cpu-independent routines for uncached access

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Jan 18 12:47:14 UTC 2019


On 18/01/2019 12:55, Jiri Gaisler wrote:
>  From 02c67c905e4ed02678ee8efc6d9e6cbc946fdf77 Mon Sep 17 00:00:00 2001
> From: Jiri Gaisler<jiri at gaisler.se>
> Date: Fri, 18 Jan 2019 11:32:28 +0100
> Subject: [PATCH v2 6/7] grlib: use cpu-independent routines for uncached
>   access
>
> ---
>   bsps/include/grlib/grlib_impl.h               | 54 +++++++++++++++++++
>   bsps/shared/grlib/1553/b1553brm.c             | 10 +---
>   bsps/shared/grlib/1553/b1553rt.c              | 11 +---
>   bsps/shared/grlib/can/grcan.c                 | 27 ++--------
>   bsps/shared/grlib/pci/grpci2dma.c             |  2 +-
>   bsps/shared/grlib/spw/grspw.c                 | 33 +++---------
>   bsps/shared/grlib/spw/grspw_pkt.c             |  2 +-
>   cpukit/score/cpu/riscv/headers.am             |  2 +
>   .../score/cpu/riscv/include/libcpu/access.h   | 50 +++++++++++++++++
>   .../cpu/riscv/include/libcpu/byteorder.h      | 31 +++++++++++
>   10 files changed, 151 insertions(+), 71 deletions(-)
>   create mode 100644 cpukit/score/cpu/riscv/include/libcpu/access.h
>   create mode 100644 cpukit/score/cpu/riscv/include/libcpu/byteorder.h
>
> diff --git a/bsps/include/grlib/grlib_impl.h b/bsps/include/grlib/grlib_impl.h
> index 755f635911..f1260671e0 100644
> --- a/bsps/include/grlib/grlib_impl.h
> +++ b/bsps/include/grlib/grlib_impl.h
> @@ -90,6 +90,60 @@ 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;

Does this ambapp_plb belong to this commit or to grlib_impl.h?

> +
>   #ifdef __cplusplus
>   }
>   #endif
> 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..fbaadd1e13 100644
> --- a/bsps/shared/grlib/spw/grspw.c
> +++ b/bsps/shared/grlib/spw/grspw.c
> @@ -25,6 +25,10 @@
>   
>   #include <grlib/grlib_impl.h>
>   
> +#ifndef CPU_SPARC_HAS_SNOOPING
> +#define CPU_SPARC_HAS_SNOOPING 1
> +#endif

This should move to grlib_int.h and be turned into something like

GRLIB_DMA_IS_CACHE_COHERENT

I am not sure if it is used to indicate this purpose.

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber at embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.




More information about the devel mailing list