Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  *  @file
0005  *
0006  *  This file contains the code to do simple memory and io accesses.
0007  */
0008 
0009 /*
0010  *  COPYRIGHT (c) 1989-2012.
0011  *  On-Line Applications Research Corporation (OAR).
0012  *
0013  * Redistribution and use in source and binary forms, with or without
0014  * modification, are permitted provided that the following conditions
0015  * are met:
0016  * 1. Redistributions of source code must retain the above copyright
0017  *    notice, this list of conditions and the following disclaimer.
0018  * 2. Redistributions in binary form must reproduce the above copyright
0019  *    notice, this list of conditions and the following disclaimer in the
0020  *    documentation and/or other materials provided with the distribution.
0021  *
0022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0023  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0025  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0026  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0027  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0028  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0029  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0030  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0031  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0032  * POSSIBILITY OF SUCH DAMAGE.
0033  */
0034 
0035 #include <rtems.h>
0036 #include <bsp.h>
0037 
0038 #include <bsp/pci.h>
0039 #include <bsp/irq.h>
0040 #include <rtems/bspIo.h>
0041 #include <rtems/endian.h>
0042 // #define DEBUG_ACCESSES   1
0043 
0044 #ifdef DEBUG_ACCESSES
0045   #define JPRINTK(fmt, ...) printk("%s: " fmt, __FUNCTION__, ##__VA_ARGS__)
0046 #else
0047   #define JPRINTK(fmt, ...)
0048 #endif
0049 
0050 /*
0051  *  *  Simple accesses
0052  *   */
0053 void simple_out_32(uint32_t base, uint32_t addr, uint32_t val)
0054 {
0055   volatile uint32_t *ptr;
0056 
0057   ptr = (volatile uint32_t *) (base + addr);
0058   *ptr = val;
0059 
0060   JPRINTK( "%p data: 0x%x\n", ptr, val);
0061 }
0062 
0063 void simple_out_le32(uint32_t base, uint32_t addr, uint32_t val)
0064 {
0065   volatile uint32_t *ptr;
0066   uint32_t           data = 0;
0067 
0068   ptr = (volatile uint32_t *) (base + addr);
0069   rtems_uint32_to_little_endian( val, (uint8_t *) &data);
0070   *ptr = data;
0071 
0072   JPRINTK( "%p data: 0x%x\n", ptr, data);
0073 }
0074 
0075 uint8_t simple_in_8( uint32_t base, uint32_t addr ) {
0076   volatile uint8_t *ptr;
0077   uint8_t           val;
0078 
0079   ptr = (volatile uint8_t *) (base + addr);
0080   val = *ptr;
0081   JPRINTK( "0x%x data: 0x%x\n", ptr, val);
0082 
0083   return val;
0084 }
0085 
0086 int16_t simple_in_le16( uint32_t base, uint32_t addr ) {
0087   volatile uint16_t *ptr;
0088   uint16_t           val;
0089   uint16_t           rval;
0090 
0091   ptr = (volatile uint16_t *) (base + addr);
0092   val = *ptr;
0093   rval = rtems_uint16_from_little_endian( (uint8_t *) &val);
0094   JPRINTK( "0x%x data: 0x%x raw: 0x%x\n", ptr, rval, val);
0095   return rval;
0096 }
0097 
0098 int16_t simple_in_16( uint32_t base, uint32_t addr ) {
0099   volatile uint16_t *ptr;
0100   uint16_t           val;
0101 
0102   ptr = (volatile uint16_t *) (base + addr);
0103   val = *ptr;
0104   JPRINTK( "0x%x data: 0x%x raw: 0x%x\n", ptr, val, val);
0105   return val;
0106 }
0107 
0108 uint32_t simple_in_le32( uint32_t base, uint32_t addr ) {
0109   volatile uint32_t *ptr;
0110   uint32_t           val;
0111   uint32_t           rval;
0112 
0113   ptr = (volatile uint32_t *) (base + addr);
0114   val = *ptr;
0115   rval = rtems_uint32_from_little_endian( (uint8_t *) &val);
0116   JPRINTK( "0x%x data: 0x%x raw: 0x%x\n", ptr, rval, val);
0117   return rval;
0118 }
0119 
0120 uint32_t simple_in_32( uint32_t base, uint32_t addr ) {
0121   volatile uint32_t *ptr;
0122   uint32_t           val;
0123 
0124   ptr = (volatile uint32_t *) (base + addr);
0125   val = *ptr;
0126   JPRINTK( "0x%x data: 0x%x raw: 0x%x\n", ptr, val, val);
0127   return val;
0128 }
0129 
0130 void simple_out_8( uint32_t base, uint32_t addr, uint8_t val ) {
0131   volatile uint8_t *ptr;
0132 
0133   ptr = (volatile uint8_t *) (base | addr);
0134   JPRINTK( "0x%x data: 0x%x\n", ptr, val);
0135   *ptr = val;
0136 }
0137 
0138 void simple_out_le16( uint32_t base, uint32_t addr, uint16_t val ) {
0139   volatile uint16_t *ptr;
0140   uint16_t           data;
0141   ptr = (volatile uint16_t *) (base + addr);
0142   rtems_uint16_to_little_endian( val, (uint8_t *) &data);
0143   *ptr = data;
0144   JPRINTK( "0x%x data: 0x%x\n", ptr, data);
0145 }
0146 
0147 void simple_out_16( uint32_t base, uint32_t addr, uint16_t val ) {
0148   volatile uint16_t *ptr;
0149   ptr = (volatile uint16_t *) (base + addr);
0150   *ptr = val;
0151   JPRINTK( "0x%x data: 0x%x\n", ptr, val);
0152 }