cartrominit.c 2.98 KB

/**************************************************************************
 *									  *
 *		 Copyright (C) 1995, Silicon Graphics, Inc.		  *
 *									  *
 *  These coded instructions, statements, and computer programs  contain  *
 *  unpublished  proprietary  information of Silicon Graphics, Inc., and  *
 *  are protected by Federal copyright law.  They  may  not be disclosed  *
 *  to  third  parties  or copied or duplicated in any form, in whole or  *
 *  in part, without the prior written consent of Silicon Graphics, Inc.  *
 *									  *
 **************************************************************************/

#include "osint.h"
#include "piint.h"
#include "rcp.h"

OSPiHandle __CartRomHandle;


/*
 * Name:   osCartRomInit
 *
 * Description:
 *	Get cartridge rom handler
 *
 */
OSPiHandle *
osCartRomInit(void)
{
	u32		value = 0;
	u32		saveMask;
	static s32	first = 1;
	register u32	stat;
	u32		latency, pulse, pageSize, relDuration;


	/* Block to get resource token */
	__osPiGetAccess();

	/*
	 * 2回目以降は既に取得した設定値を返す
	 */
	if (! first)
	{
	    /* Return resource token */
	    __osPiRelAccess();

	    return(&__CartRomHandle);
	}

	first = 0;


	__CartRomHandle.type = DEVICE_TYPE_CART;
	__CartRomHandle.baseAddress = PHYS_TO_K1(PI_DOM1_ADDR2);
	__CartRomHandle.domain = PI_DOMAIN1;

	/* Fill speed and transferInfo to zero */

	__CartRomHandle.speed = 0;
	bzero(&(__CartRomHandle.transferInfo),
			sizeof(__CartRomHandle.transferInfo));
	
	/*
	 * ロムのアクセススピードを得る。EPI と同様の処理。
	 */

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

	/*
	 * アクセススピードを変更する前に、現在の値を保存しておく
	 */
	latency = IO_READ(PI_BSD_DOM1_LAT_REG);
	pageSize = IO_READ(PI_BSD_DOM1_PGS_REG);
	relDuration = IO_READ(PI_BSD_DOM1_RLS_REG);
	pulse = IO_READ(PI_BSD_DOM1_PWD_REG);

	/*
	 * アクセススピード値を読むため、超低速な値に設定。
	 */
	IO_WRITE(PI_BSD_DOM1_LAT_REG, (u8)0xff);
	IO_WRITE(PI_BSD_DOM1_PGS_REG, (u8)0x0);
	IO_WRITE(PI_BSD_DOM1_RLS_REG, (u8)0x3);
	IO_WRITE(PI_BSD_DOM1_PWD_REG, (u8)0xff);

	/*
	 * 先頭をリード
	 */
	value = IO_READ((u32)__CartRomHandle.baseAddress);

	__CartRomHandle.latency = (u8)(value & 0xff);
	__CartRomHandle.pageSize = (u8)((value >> 16) & 0xf);
	__CartRomHandle.relDuration = (u8)((value >> 20) & 0xf);
	__CartRomHandle.pulse = (u8)((value >> 8) & 0xff);

	/*
	 * PI バスの設定値を、変更前に戻しておく
	 */
	IO_WRITE(PI_BSD_DOM1_LAT_REG, latency);
	IO_WRITE(PI_BSD_DOM1_PGS_REG, pageSize);
	IO_WRITE(PI_BSD_DOM1_RLS_REG, relDuration);
	IO_WRITE(PI_BSD_DOM1_PWD_REG, pulse);

	/*
	 * cartrominit は PI バスの設定値を変更しない
	 * よって、__osCurrentHandle の値も変更してはいけない
	 */

	/* 
	 * Put the CartRomHandle onto PiTable
	 */
	saveMask = __osDisableInt();

	__CartRomHandle.next = __osPiTable;
	__osPiTable = &__CartRomHandle;

	__osRestoreInt(saveMask);


	/* Return resource token */
	__osPiRelAccess();


    	return(&__CartRomHandle);

}  /* osCartRomInit */