1/* ********************************************************************* 2 * Broadcom Common Firmware Environment (CFE) 3 * 4 * "Hyperspace" access routines File: lib_hssubr.h 5 * 6 * Routines to muck with memory independently of pointer size. 7 * 8 * Author: Mitch Lichtenberg 9 * 10 ********************************************************************* 11 * 12 * Copyright 2000,2001,2002,2003 13 * Broadcom Corporation. All rights reserved. 14 * 15 * This software is furnished under license and may be used and 16 * copied only in accordance with the following terms and 17 * conditions. Subject to these conditions, you may download, 18 * copy, install, use, modify and distribute modified or unmodified 19 * copies of this software in source and/or binary form. No title 20 * or ownership is transferred hereby. 21 * 22 * 1) Any source code used, modified or distributed must reproduce 23 * and retain this copyright notice and list of conditions 24 * as they appear in the source file. 25 * 26 * 2) No right is granted to use any trade name, trademark, or 27 * logo of Broadcom Corporation. The "Broadcom Corporation" 28 * name may not be used to endorse or promote products derived 29 * from this software without the prior written permission of 30 * Broadcom Corporation. 31 * 32 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR 33 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED 34 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 35 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT 36 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN 37 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT, 38 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 39 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 40 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 41 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 42 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 43 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF 44 * THE POSSIBILITY OF SUCH DAMAGE. 45 ********************************************************************* */ 46 47 48#ifndef _LIB_HSSUBR_H 49#define _LIB_HSSUBR_H 50 51/* 52 * The macros and functions in this file are used to wrangle 53 * 64-bit addresses on 32-bit versions of CFE. Generally CFE 54 * is 32-bits on all platforms, even those with 64-bit addressability. 55 * This is done for toolchain reasons, since 64-bitness interferes 56 * in nasty ways with relocation. 57 * 58 * There are two other macros of note: 59 * 60 * PTR2HSADDR(x) Converts a pointer to an hsaddr, with appopriate 61 * sign extensions 62 * 63 * HSADDR2PTR(x) Shortens an hsaddr into a regular pointer, assuming 64 * that pointer is already narrow enough to fit into 65 * a regular pointer. Used mostly in places where 66 * CFE is sending pointers to itself. 67 */ 68 69 70#if (CPUCFG_REGS32) 71 72/* We can use the macros. */ 73 74typedef long hsaddr_t; /* longs are already pointer-sized */ 75 76#define hs_write8(a,b) *((volatile uint8_t *) (a)) = (b) 77#define hs_write16(a,b) *((volatile uint16_t *) (a)) = (b) 78#define hs_write32(a,b) *((volatile uint32_t *) (a)) = (b) 79#define hs_write64(a,b) *((volatile uint64_t *) (a)) = (b) 80#define hs_read8(a) *((volatile uint8_t *) (a)) 81#define hs_read16(a) *((volatile uint16_t *) (a)) 82#define hs_read32(a) *((volatile uint32_t *) (a)) 83#define hs_read64(a) *((volatile uint64_t *) (a)) 84#define hs_memcpy_to_hs(d,s,c) memcpy((void *)(d),(s),(c)) 85#define hs_memcpy_from_hs(d,s,c) memcpy((d),(void *)(s),(c)) 86#define hs_memset(d,x,c) memset((void *)(d),(x),(c)) 87#define PTR2HSADDR(x) ((hsaddr_t)(x)) 88#define HSADDR2PTR(x) ((void *)(long)(x)) 89 90#else 91 92/* Need functions, pointers and registers are different */ 93 94#error "PowerPC package doesn't support 64-bit pointers yet." 95 96typedef long long hsaddr_t; /* Make sure pointers are 64 bits */ 97 98extern void hs_write8(hsaddr_t a,uint8_t b); 99extern void hs_write16(hsaddr_t a,uint16_t b); 100extern void hs_write32(hsaddr_t a,uint32_t b); 101extern void hs_write64(hsaddr_t a,uint64_t b); 102extern uint8_t hs_read8(hsaddr_t a); 103extern uint16_t hs_read16(hsaddr_t a); 104extern uint32_t hs_read32(hsaddr_t a); 105extern uint64_t hs_read64(hsaddr_t a); 106extern void hs_memset(hsaddr_t dest,int c,int cnt); 107extern void hs_memcpy_to_hs(hsaddr_t dest,void *src,int cnt); 108extern void hs_memcpy_from_hs(void *dest,hsaddr_t src,int cnt); 109 110#define PTR2HSADDR(x) ((hsaddr_t)(long)(x)) 111#define HSADDR2PTR(x) ((void *)(long)(x)) 112#endif 113 114#endif 115