pirawread.c 2.31 KB

/*====================================================================
 * pirawread.c
 *
 * Copyright 1995, Silicon Graphics, Inc.
 * All Rights Reserved.
 *
 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics,
 * Inc.; the contents of this file may not be disclosed to third
 * parties, copied or duplicated in any form, in whole or in part,
 * without the prior written permission of Silicon Graphics, Inc.
 *
 * RESTRICTED RIGHTS LEGEND:
 * Use, duplication or disclosure by the Government is subject to
 * restrictions as set forth in subdivision (c)(1)(ii) of the Rights
 * in Technical Data and Computer Software clause at DFARS
 * 252.227-7013, and/or in similar or successor clauses in the FAR,
 * DOD or NASA FAR Supplement. Unpublished - rights reserved under the
 * Copyright Laws of the United States.
 *====================================================================*/

/**************************************************************************
 *
 *  $Revision: 1.2 $
 *  $Date: 2003/05/15 07:36:30 $
 *  $Source: /root/leakn64/depot/rf/sw/bbplayer/libultra/nintendo/pi/pirawread.c,v $
 *
 **************************************************************************/

#include "osint.h"
#include "rcp.h"
#include "assert.h"
#if defined(BBPLAYER) && !defined(_FINALROM)
#include "ramrom.h"
#include "bbint.h"
#endif



/*
 * Name:   __osPiRawReadIo
 *
 * Description:
 *	Perform a 32-bit programmed IO read from the PI device address space.
 *	If the interface is busy, return a "-1" and abort the operation.
 *	Note that address must be 32-bit aligned.
 *
 * Globals Referenced: 
 *	None
 */
s32	
__osPiRawReadIo(u32 devAddr, u32 *data)
{
    register u32 stat;

#ifdef _DEBUG
    /* Ensure that address is 32-bit aligned */
    if (devAddr & 0x3) {
	__osError(ERR_OSPIRAWREADIO, 1, devAddr);
	return(-1);
    }

    /* Ensure data pointer is not empty */
    assert(data != NULL);
#endif

    stat = IO_READ(PI_STATUS_REG);
    while (stat & (PI_STATUS_IO_BUSY | PI_STATUS_DMA_BUSY)) {
        stat = IO_READ(PI_STATUS_REG);
    } 

#if defined(BBPLAYER) && !defined(_FINALROM)
    if (__osBbIsBb && devAddr >= RAMROM_APP_WRITE_ADDR &&
	              devAddr < RAMROM_APP_WRITE_ADDR+512) {
	*data = IO_READ(devAddr);
	return 0;
    }
#endif
    *data = IO_READ((u32)osRomBase | devAddr);

    return(0);

}  /* __osPiRawReadIo */