pfsgetstatus.c 3.37 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 "controller.h"
#include "siint.h"
#ifdef BBPLAYER
#include "bbint.h"
#endif

extern	s32	__osCheckPackId(OSPfs *, __OSPackId *);
extern	s32	__osRepairPackId(OSPfs *, __OSPackId *, __OSPackId *);

s32
__osPfsGetStatus(OSMesgQueue *queue, int channel)
{
#ifdef BBPLAYER
       if (__osBbPakAddress[channel]) 
	   return 0;
       else
	   return PFS_ERR_NOPACK;
#else
	s32 ret = 0;
	OSMesg	dummy;
	OSContStatus data;

	__osPfsInodeCacheBank = 250; 	/* Bank of Inode Cache */

	/* Set up request command format for all channels */

	__osPfsRequestOneChannel(channel, CONT_REQUEST);
	ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam);
	(void)osRecvMesg(queue, &dummy, OS_MESG_BLOCK);

	/* trigger pifmacro */

	ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam);
	(void)osRecvMesg(queue, &dummy, OS_MESG_BLOCK);

	/* reformat the 64 bytes RAM data and save in data array */

	__osPfsGetOneChannelData(channel, &data);
	if (((data.status & CONT_CARD_ON) != 0) && 
	    ((data.status & CONT_CARD_PULL) != 0)) {
	  return(PFS_ERR_NEW_PACK);
	} else if (data.errno || ((data.status & CONT_CARD_ON) == 0)) {
	  return(PFS_ERR_NOPACK);
	} else if ((data.status & CONT_ADDR_CRC_ER) != 0)
		return(PFS_ERR_CONTRFAIL);
	return(ret);
#endif
}

void
__osPfsRequestOneChannel(int channel, u8 cmd)
{
  u8 				*ptr;
  __OSContRequesFormatShort 	requestformat;
  int	 			i;
  
  __osContLastCmd = CONT_ETC;
  
  /* clear pif ram */
  __osPfsPifRam.pifstatus = CONT_FORMAT;
  
  ptr = (u8 *)(&__osPfsPifRam);

  /* Setup request format for each channel */

  requestformat.txsize = 1;
  requestformat.rxsize = 3;
  requestformat.cmd = cmd;
  requestformat.typeh = 0xff;
  requestformat.typel = 0xff;
  requestformat.status = 0xff;

  for (i = 0; i < channel; i++) {
    *ptr++ = 0x00;		/* skip */
  }    

  /* setup request format for all the channel */

  *((__OSContRequesFormatShort *)ptr) = requestformat;
  ptr += sizeof(requestformat);
  *((u8 *)ptr) = FORMAT_END;
}

/*
 * Reformat the 64 bytes RAM data into RequestData format 
 * and check error code.
 */
void
__osPfsGetOneChannelData(int channel, OSContStatus *data)
{
  u8 				*ptr;
  __OSContRequesFormatShort 	requestformat;
  int	 			i;

  ptr = (u8 *)(&__osPfsPifRam);

  for (i = 0; i < channel; i++) {
    ptr++;			/* skip */
  }    

  /* read request format for one channel */
  requestformat = *((__OSContRequesFormatShort *)ptr);
  data->errno = (u8)((requestformat.rxsize & CON_ERR_MASK) >> 4);
  if (data->errno) return;
  data->type =(u16)((requestformat.typel<<8)|requestformat.typeh);
  data->status = requestformat.status;
}