/*++
 * Copyright (c) 1990-96 Digi International Inc., All Rights Reserved
 * 
 * This software contains proprietary and confidential information of Digi
 * International Inc.  By accepting transfer of this copy, Recipient agrees
 * to retain this software in confidence, to prevent disclosure to others,
 * and to make no use of this software other than that for which it was
 * delivered.  This is an unpublished copyrighted work of Digi International
 * Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly
 * prohibited.
 * 
 * Restricted Rights Legend
 *
 * Use, duplication, or disclosure by the Government is subject to
 * restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in
 * Technical Data and Computer Software clause at DFARS 252.227-7031 or
 * subparagraphs (c)(1) and (2) of the Commercial Computer Software -
 * Restricted Rights at 48 CFR 52.227-19, as applicable.
 *
 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
 *
 *
 * Last Update: $Date: 10/22/97 11:56a $
 *
 * $Header: /Components/Windows/NT/Sync/Build/Mp570/io.c 3     10/22/97 11:56a Darinh $
 *
 * Revision History:
 * $Log: /Components/Windows/NT/Sync/Build/Mp570/io.c $
 * 
 * 3     10/22/97 11:56a Darinh
 * Changes to make multiple board installations work better.
 * 
 * 2     6/06/97 1:48p Darinh
 * Everything seems functional, but more testing is required.
 * 
 * 1     4/02/97 10:08a Darinh
 * Initial checkin; ISA cards initialize, but do not pass data.
 * 
--*/

#include <ntddk.h>
#include "digilib.h"
#include "def570.h"
#include "board.h"
#include "io.h"



UCHAR
fnReadIO (
	PUCHAR		pSrc)
/*++

Description:

	Macro wrapper for IO mapped Read operations

Parameters:

	pSrc - pointer to the desired IO port to read

Return Value:

	None.

--*/
{
	// Call the IO function via a macro
	return (IO_IN (pSrc));
}


VOID
fnWriteIO (
	IN PUCHAR	pSrc,
	IN UCHAR	data)
/*++

Description:

	Macro wrapper for IO mapped write operations

Parameters:

	pSrc - pointer to the desired IO port to read
	data - the byte to write to a given port

Return Value:

	None.

--*/
{
	// Call the IO function via a macro
	IO_OUT (pSrc, data);
}


UCHAR
fnReadMem (
	IN PUCHAR	pSrc)
/*++

Description:

	Macro wrapper for Mem mapped read operations

Parameters:

	pSrc - pointer to the desired IO port to read

Return Value:

	Byte read.

--*/
{
	// Call the IO function via a macro
	return READ_REGISTER_UCHAR (pSrc);
}


VOID
fnWriteMem (
	IN PUCHAR	pSrc,
	IN UCHAR	data)
/*++

Description:

	Macro wrapper for Mem mapped write operations

Parameters:

	pSrc - pointer to the desired IO port to write
	data - the byte to write to a given port

Return Value:

	None.

--*/
{
	// Call the IO function via a macro
	WRT_REG_UCHAR (pSrc, data);
}


//
//  Some utility functions for dealing with register functions
//
VOID
DisableInterrupt (
	IN PCONTROLLER_EXT	pControllerExt)
{
	if (PCIBus == pControllerExt->BusType)
	{
		if (pControllerExt->VirtualPlxRegisters) {
			WRT_REG_UCHAR (pControllerExt->VirtualPlxRegisters + 0x69, 0);
		}
	}
	else
	{
		if (pControllerExt->VirtualIO) {
			IO_OUT (pControllerExt->VirtualIO + REG570_INT_SEL, 0);
		}
	}
}


VOID
EnableScaMemMap (
	IN PDEVICE_EXT	pDeviceExt)
{
	if (PCIBus != pDeviceExt->pControllerExt->BusType)
		IO_OUT (pDeviceExt->pControllerExt->pDigiMemScaReg,
			pDeviceExt->DigiMemScaE);
}


VOID
EnableMemory (
	IN PDEVICE_EXT	pDeviceExt,
	IN UCHAR		DesiredWindow)
{

	if (PCIBus != pDeviceExt->pControllerExt->BusType)
		IO_OUT (pDeviceExt->pControllerExt->pDigiMemScaReg,
			(DesiredWindow | MSCA_MEM));
}


VOID
EnableControllerMemory (
	IN PCONTROLLER_EXT	pControllerExt,
	IN UCHAR			DesiredWindow)
{
	if (PCIBus != pControllerExt->BusType)
		IO_OUT (pControllerExt->pDigiMemScaReg, (DesiredWindow | MSCA_MEM));
}


VOID
DisableMemory (
	IN PDEVICE_EXT	pDeviceExt)
{
	if (PCIBus != pDeviceExt->pControllerExt->BusType)
		IO_OUT (pDeviceExt->pControllerExt->pDigiMemScaReg, 0);
}


VOID
DisableControllerMemory (
	IN PCONTROLLER_EXT	pControllerExt)
{
	if (PCIBus != pControllerExt->BusType)
		IO_OUT (pControllerExt->pDigiMemScaReg, 0);
}

