Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:43

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  * Copyright (C) 2017 Cobham Gaisler AB
0005  *
0006  * Redistribution and use in source and binary forms, with or without
0007  * modification, are permitted provided that the following conditions
0008  * are met:
0009  * 1. Redistributions of source code must retain the above copyright
0010  *    notice, this list of conditions and the following disclaimer.
0011  * 2. Redistributions in binary form must reproduce the above copyright
0012  *    notice, this list of conditions and the following disclaimer in the
0013  *    documentation and/or other materials provided with the distribution.
0014  *
0015  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0016  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0017  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0018  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0019  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0020  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0021  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0024  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0025  * POSSIBILITY OF SUCH DAMAGE.
0026  */
0027 
0028 #ifndef GRLIB_IMPL_H
0029 #define GRLIB_IMPL_H
0030 
0031 #include <rtems/score/basedefs.h>
0032 #include <rtems/malloc.h>
0033 
0034 /*
0035  * Use interrupt lock primitives compatible with SMP defined in RTEMS 4.11.99
0036  * and higher.
0037  */
0038 #if (((__RTEMS_MAJOR__ << 16) | (__RTEMS_MINOR__ << 8) | __RTEMS_REVISION__) >= 0x040b63)
0039 
0040 #include <rtems/score/isrlock.h>
0041 
0042 /* map via rtems_interrupt_lock_* API: */
0043 #define SPIN_DECLARE(lock) RTEMS_INTERRUPT_LOCK_MEMBER(lock)
0044 #define SPIN_INIT(lock, name) rtems_interrupt_lock_initialize(lock, name)
0045 #define SPIN_LOCK(lock, level) rtems_interrupt_lock_acquire_isr(lock, &level)
0046 #define SPIN_LOCK_IRQ(lock, level) rtems_interrupt_lock_acquire(lock, &level)
0047 #define SPIN_UNLOCK(lock, level) rtems_interrupt_lock_release_isr(lock, &level)
0048 #define SPIN_UNLOCK_IRQ(lock, level) rtems_interrupt_lock_release(lock, &level)
0049 #define SPIN_IRQFLAGS(k) rtems_interrupt_lock_context k
0050 #define SPIN_ISR_IRQFLAGS(k) SPIN_IRQFLAGS(k)
0051 #define SPIN_FREE(lock) rtems_interrupt_lock_destroy(lock)
0052 
0053 /* turn on/off local CPU's interrupt to ensure HW timing - not SMP safe. */
0054 #define IRQ_LOCAL_DECLARE(_level) rtems_interrupt_level _level
0055 #define IRQ_LOCAL_DISABLE(_level) rtems_interrupt_local_disable(_level)
0056 #define IRQ_LOCAL_ENABLE(_level) rtems_interrupt_local_enable(_level)
0057 
0058 #else
0059 
0060 #ifdef RTEMS_SMP
0061 #error SMP mode not compatible with these interrupt lock primitives
0062 #endif
0063 
0064 /* maintain single-core compatibility with older versions of RTEMS: */
0065 #define SPIN_DECLARE(name)
0066 #define SPIN_INIT(lock, name)
0067 #define SPIN_LOCK(lock, level)
0068 #define SPIN_LOCK_IRQ(lock, level) rtems_interrupt_disable(level)
0069 #define SPIN_UNLOCK(lock, level)
0070 #define SPIN_UNLOCK_IRQ(lock, level) rtems_interrupt_enable(level)
0071 #define SPIN_IRQFLAGS(k) rtems_interrupt_level k
0072 #define SPIN_ISR_IRQFLAGS(k)
0073 #define SPIN_FREE(lock)
0074 
0075 /* turn on/off local CPU's interrupt to ensure HW timing - not SMP safe. */
0076 #define IRQ_LOCAL_DECLARE(_level) rtems_interrupt_level _level
0077 #define IRQ_LOCAL_DISABLE(_level) rtems_interrupt_disable(_level)
0078 #define IRQ_LOCAL_ENABLE(_level) rtems_interrupt_enable(_level)
0079 
0080 #endif
0081 
0082 #ifdef __cplusplus
0083 extern "C" {
0084 #endif
0085 
0086 #if (((__RTEMS_MAJOR__ << 16) | (__RTEMS_MINOR__ << 8) | __RTEMS_REVISION__) >= 0x050000)
0087 
0088 static inline void *grlib_malloc(size_t size)
0089 {
0090  return rtems_malloc(size);
0091 }
0092 
0093 static inline void *grlib_calloc(size_t nelem, size_t elsize)
0094 {
0095  return rtems_calloc(nelem, elsize);
0096 }
0097 
0098 #else
0099 
0100 static inline void *grlib_malloc(size_t size)
0101 {
0102  return malloc(size);
0103 }
0104 
0105 static inline void *grlib_calloc(size_t nelem, size_t elsize)
0106 {
0107  return calloc(nelem, elsize);
0108 }
0109 
0110 #endif
0111 
0112 #ifdef __sparc__
0113 
0114 static inline unsigned char grlib_read_uncached8(unsigned int address)
0115 {
0116        unsigned char tmp;
0117        __asm__ (" lduba [%1]1, %0 "
0118            : "=r"(tmp)
0119            : "r"(address)
0120        );
0121        return tmp;
0122 }
0123 
0124 static inline unsigned short grlib_read_uncached16(unsigned int addr) {
0125        unsigned short tmp;
0126        __asm__ (" lduha [%1]1, %0 "
0127          : "=r"(tmp)
0128          : "r"(addr)
0129        );
0130        return tmp;
0131 }
0132 
0133 
0134 static inline unsigned int grlib_read_uncached32(unsigned int address)
0135 {
0136     unsigned int tmp;
0137     __asm__ (" lda [%1]1, %0 "
0138             : "=r"(tmp)
0139             : "r"(address)
0140     );
0141     return tmp;
0142 }
0143 
0144 static inline uint64_t grlib_read_uncached64(uint64_t *address)
0145 {
0146     uint64_t tmp;
0147     __asm__ (" ldda [%1]1, %0 "
0148             : "=r"(tmp)
0149             : "r"(address)
0150     );
0151     return tmp;
0152 }
0153 
0154 #define GRLIB_DMA_IS_CACHE_COHERENT CPU_SPARC_HAS_SNOOPING
0155 
0156 #else
0157 
0158 static unsigned char __inline__ grlib_read_uncached8(unsigned int address)
0159 {
0160     unsigned char tmp = (*(volatile unsigned char *)(address));
0161     return tmp;
0162 }
0163 
0164 static __inline__ unsigned short grlib_read_uncached16(unsigned int address) {
0165     unsigned short tmp = (*(volatile unsigned short *)(address));
0166     return tmp;
0167 }
0168 
0169 static inline unsigned int grlib_read_uncached32(unsigned int address)
0170 {
0171     unsigned int tmp = (*(volatile unsigned int *)(address));
0172     return tmp;
0173 }
0174 
0175 #define GRLIB_DMA_IS_CACHE_COHERENT 1
0176 
0177 #endif
0178 
0179 #ifdef __cplusplus
0180 }
0181 #endif
0182 
0183 #endif /* GRLIB_IMPL_H */