driverominit.c 3 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 __DriveRomHandle;


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


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

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

	    return(&__DriveRomHandle);
	}

	first = 0;


	__DriveRomHandle.type = DEVICE_TYPE_BULK;
	__DriveRomHandle.baseAddress = PHYS_TO_K1(PI_DOM1_ADDR1);
	__DriveRomHandle.domain = PI_DOMAIN1;

	/* Fill speed and transferInfo to zero */

	__DriveRomHandle.speed = 0;
	bzero(&(__DriveRomHandle.transferInfo),
			sizeof(__DriveRomHandle.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)__DriveRomHandle.baseAddress);

	__DriveRomHandle.latency = (u8)(value & 0xff);
	__DriveRomHandle.pageSize = (u8)((value >> 16) & 0xf);
	__DriveRomHandle.relDuration = (u8)((value >> 20) & 0xf);
	__DriveRomHandle.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 DriveRomHandle onto PiTable
	 */
	saveMask = __osDisableInt();

	__DriveRomHandle.next = __osPiTable;
	__osPiTable = &__DriveRomHandle;

	__osRestoreInt(saveMask);


	/* Return resource token */
	__osPiRelAccess();


    	return(&__DriveRomHandle);

}  /* osDriveRomInit */