/*  Copyright (C) MOXA Inc. All rights reserved.
 
    This software is distributed under the terms of the
    MOXA License.  See the file COPYING-MOXA for details.
*/

/*****************************************************************************/
/**  FILE NAME  : MxGeneralIo.h			                                     */
/**                                                                          */
/**  DESCRIPTION:                                                            */
/**    implementation file of the general IO interface.	                     */
/**    Definition for General Io			                                 */
/**                                                                          */
/**  Copyright (C) 2011 Moxa Inc. All rights reserved.                       */
/*****************************************************************************/

/*****************************************************************************/
/**  REVISION HISTORY   :                                                    */
/**                                                                          */
/**      2011-09-04		Epson												 */
/**						create file											 */
/**                                                                          */
/*****************************************************************************/
#ifndef MXGENERALIO_H
#define MXGENERALIO_H

/*****************************************************************************
 *  Include Section															 *
 ****************************************************************************/
#include "winio_nt.h"
#include "Iofunc.h"
#include "SuperIofunc.h"
#include "Memfunc.h"
#include "Msrfunc.h"
#include "Smifunc.h"
#include "devices.h"

#ifdef __cplusplus 
extern "C" {
#endif

/*****************************************************************************
 *  Definition Section														 *
 ****************************************************************************/
#define IO_TYPE_SUPERIO		0
#define IO_TYPE_IOBASE		1

/*****************************************************************************
 *  Self-defined function													 *
 ****************************************************************************/
/* GeneralIoOpen : Initialize the WinIo
 *
 * Param:
 * 
 * Input:
 *		none
 *	
 * Output:
 *		none	
 *
 * Return Value:
 *		status, TRUE for success, FALSE for fail	
 */
BOOL MxGeneralIoOpen();


/* GeneralIoClose : Close the WinIo
 *
 * Param:
 * 
 * Input:
 *		none
 *	
 * Output:
 *		none	
 *
 * Return Value:
 *		none	
 */
void MxGeneralIoClose();


/* GetGeneralIoVal : get io value from GPIO or SuperIO
 *
 * Param:
 * 
 * Input:
 *		<nIoType> : IO type, GPIO or SuperIO
 *		<wIoAddress> : Port address
 *	
 * Output:
 *		<pdwPortVal> : port value
 *
 * Return Value:
 *		TRUE for success, FALSE for fail	
 */
BOOL MxGetGeneralIoVal(int nIoType,WORD wIoAddress,DWORD *pdwPortVal,BYTE bSize);

BOOL MxGetGeneralIoValEx(int nIoType,WORD wIoAddress,DWORD *pdwPortVal,BYTE bSize,tagSuperIoStruct SuperIoStruct);

/* SetGeneralIoVal : get io value from GPIO or SuperIO
 *
 * Param:
 * 
 * Input:
 *		<nIoType> : IO type, GPIO or SuperIO
 *		<wIoAddress> : Port address
 *		<dwPortValue> : Port value to set
 *	
 * Output:
 *		none	
 *
 * Return Value:
 *		status, TRUE for success, FALSE for fail	
 */
BOOL MxSetGeneralIoVal(int nIoType,WORD wIoAddress, DWORD dwPortValue,BYTE bSize);


BOOL MxSetGeneralIoValEx(int nIoType,WORD wIoAddress, DWORD dwPortValue,BYTE bSize,tagSuperIoStruct SuperIoStruct);

/*****************************************************************************
 *  Super IO function by self-defined										 *
 ****************************************************************************/
UCHAR MxGeneralIoReadSuperIoChar(ULONG superIoVendor, SUPERIOPARAM superIoParam);

void MxGeneralIoWriteSuperIoChar(ULONG superIoVendor, SUPERIOPARAM superIoParam, UCHAR data);

/*****************************************************************************
 *  IO function	by Crystal CPU-ID											 *
 ****************************************************************************/

ULONG MxGeneralIoReadPortLong(ULONG address);

USHORT MxGeneralIoReadPortShort(ULONG address);

UCHAR MxGeneralIoReadPortChar(ULONG address);

void MxGeneralIoWritePortLong(ULONG address, ULONG data);

void MxGeneralIoWritePortShort(ULONG address, USHORT data);

void MxGeneralIoWritePortChar(ULONG address, UCHAR data);


/*****************************************************************************
 *  Memory function	by Crystal CPU-ID										 *
 ****************************************************************************/

ULONG MxGeneralIoReadMemBlockLong(ULONG address, UCHAR* data, ULONG count);

ULONG MxGeneralIoReadMemBlockShort(ULONG address, UCHAR* data, ULONG count);

ULONG MxGeneralIoReadMemBlockChar(ULONG address, UCHAR* data, ULONG count);

ULONG MxGeneralIoReadMemLong(ULONG address);

USHORT MxGeneralIoReadMemShort(ULONG address);

UCHAR MxGeneralIoReadMemChar(ULONG address);

ULONG MxGeneralIoWriteMemBlockLong(ULONG address, UCHAR* data, ULONG count);

ULONG MxGeneralIoWriteMemBlockShort(ULONG address, UCHAR* data, ULONG count);

ULONG MxGeneralIoWriteMemBlockChar(ULONG address, UCHAR* data, ULONG count);

void MxGeneralIoWriteMemLong(ULONG address, ULONG data);

void MxGeneralIoWriteMemShort(ULONG address, USHORT data);

void MxGeneralIoWriteMemChar(ULONG address, UCHAR data);

ULONG MxGeneralIoCopyMemLong(ULONG src_address, ULONG dest_address, ULONG count);

ULONG MxGeneralIoCopyMemShort(ULONG src_address, ULONG dest_address, ULONG count);

ULONG MxGeneralIoCopyMemChar(ULONG src_address, ULONG dest_address, ULONG count);

ULONG MxGeneralIoFillMemLong(ULONG address, ULONG data, ULONG count);

ULONG MxGeneralIoFillMemShort(ULONG address, USHORT data, ULONG count);

ULONG MxGeneralIoFillMemChar(ULONG address, UCHAR data, ULONG count);


/*****************************************************************************
 *  MSR operation function													 *
 ****************************************************************************/
BOOL MxGeneralIoReadMsr(ULONG ulECX,ULONG* pulEAX,ULONG* pulEDX);

BOOL MxGeneralIoWriteMsr(ULONG ulECX,ULONG* pulEAX,ULONG* pulEDX);

/*****************************************************************************
 *  SMI operation function													 *
 ****************************************************************************/
BOOL MxGeneralIoGetSmiMemAddr(PSmiMem psmiMem);

BOOL MxGeneralIoReadSmiMem(PSmiMem psmiMem);

BOOL MxGeneralIoWriteSmiMem(PSmiMem psmiMem);

BOOL MxGeneralIoSendSmiCmd(PSmiCmd psmiCmd);


/*****************************************************************************
 *  SuperIO operation function												 *
 ****************************************************************************/

/* Superio_Enter_Config : Enter SuperIO
 *
 * Param:
 * 
 * Input:
 *		none
 *		
 * Output:
 *		none	
 *
 * Return Value:
 *		none	
 */
void	Superio_Enter_Config(void);

/* Superio_Exit_Config : Exit SuperIO
 *
 * Param:
 * 
 * Input:
 *		none
 *		
 * Output:
 *		none	
 *
 * Return Value:
 *		none	
 */
void	Superio_Exit_Config(void);

/* Superio_Set_Reg : get SuperIO port value
 *
 * Param:
 * 
 * Input:
 *		<index> : logic device number
 *		<val> : value to set
 *		
 * Output:
 *		none	
 *
 * Return Value:
 *		Port value, -1 for fail	
 */
void	Superio_Set_Reg(DWORD val,DWORD index);

/* Superio_Get_Reg : get SuperIO port value
 *
 * Param:
 * 
 * Input:
 *		<val> : logic device number
 *	
 * Output:
 *		none	
 *
 * Return Value:
 *		Port value, -1 for fail	
 */
DWORD	Superio_Get_Reg(DWORD val);

/* Set_Logic_Device : Select logic device
 *
 * Param:
 * 
 * Input:
 *		<val> : logic device number
 *	
 * Output:
 *		none	
 *
 * Return Value:
 *		none	
 */
void	Set_Logic_Device(DWORD val);

/* NEWIODELAY : SuperIO operation delay
 *
 * Param:
 * 
 * Input:
 *		none
 *	
 * Output:
 *		none	
 *
 * Return Value:
 *		none	
 */
void	NEWIODELAY();

#ifdef __cplusplus 
}
#endif

#endif
