/**********************************************************************
**                                                                   **
**                I N T E L   P R O P R I E T A R Y                  **
**                                                                   **
**   COPYRIGHT (c)  1993 - 2005       BY  INTEL  CORPORATION.  ALL   **
**   RIGHTS RESERVED.   NO PART OF THIS PROGRAM OR PUBLICATION MAY   **
**   BE  REPRODUCED,   TRANSMITTED,   TRANSCRIBED,   STORED  IN  A   **
**   RETRIEVAL SYSTEM, OR TRANSLATED INTO ANY LANGUAGE OR COMPUTER   **
**   LANGUAGE IN ANY FORM OR BY ANY MEANS, ELECTRONIC, MECHANICAL,   **
**   MAGNETIC,  OPTICAL,  CHEMICAL, MANUAL, OR OTHERWISE,  WITHOUT   **
**   THE PRIOR WRITTEN PERMISSION OF :                               **
**                                                                   **
**                      INTEL  CORPORATION                           **
**                                                                   **
**                2200 MISSION COLLEGE BOULEVARD                     **
**                                                                   **
**             SANTA  CLARA,  CALIFORNIA  95052-8119                 **
**                                                                   **
**********************************************************************/

/*************************************************************************
*                                                                        *
* INTEL CORPORATION PROPRIETARY INFORMATION                              *
* This software is supplied under the terms of a license agreement       *
* with Intel Corporation and may not be copied nor disclosed             *
* except in accordance with the terms of that agreement.                 *
*                                                                        *
* Module Name:                                                           *
*   e1000_osdep.h                                                        *
*                                                                        *
* Abstract:                                                              *
*   This header file contains some software constants, macros, and       *
*   structures that are required by the shared code.                     *
*                                                                        *
*   This driver runs on the following hardware:                          *
*   - 825xx based PCI gigabit ethernet adapters                          *
*                                                                        *
* Environment:                                                           *
*   Kernel Mode -                                                        *
*                                                                        *
*************************************************************************/
/*************************************************************************
* Revision Control Information
* ----------------------------
* $Id: e1000_osdep.h,v 1.23 2006/09/08 20:34:16 yli16 Exp $
* $Source: /home/cvsroot/ladsw/pro1000/windows/ndis/pcie/intel/e1000_osdep.h,v $
*************************************************************************/

#ifndef _NDIS_OS_H_
#define _NDIS_OS_H_

#include "ndis.h"
#include <x86kitl.h>

#define EEPROM_WORD_SIZE        64
//
// E1000_64_BIT_PHYSICAL_ADDRESS defines the physical addresseses used
// by the MAC chip. This is eight bytes in the descriptor, although currently
// only the lower four bytes are used.
//
typedef CHAR                  INT8, int8_t;      /*  8-bit signed */
typedef UCHAR                 UINT8, uint8_t;    /*  8-bit unsigned */
typedef PUCHAR                PUINT8;            /*  8-bit unsigned pointer */

typedef SHORT                 INT16, int16_t;    /* 16-bit signed */
typedef USHORT                UINT16, uint16_t;  /* 16-bit unsigned */
typedef PUSHORT               PUINT16;           /* 16-bit unsigned pointer */
typedef BOOLEAN               boolean_t;         /* Boolean type used in shared code */

typedef INT32                 int32_t;
typedef UINT32                uint32_t;
typedef UINT64                uint64_t;

//
// Macros required by the shared code
//
#ifdef IA64
#ifdef NDIS60_MINIPORT
#define MEMORY_BARRIER_R()
#define MEMORY_BARRIER_W()    KeMemoryBarrier();
#else
#define MEMORY_BARRIER_R()    __mf(),
#define MEMORY_BARRIER_W()    __mf();
#endif //NDIS60_MINIPORT
#define E1000_VOLATILE
#else
#define MEMORY_BARRIER_R()
#define MEMORY_BARRIER_W()
#define E1000_VOLATILE volatile
#endif

extern UINT32 e1000_not_implemented (char* name);

#ifndef NOMEMIO
#define E1000_WRITE_REG(sharedadapter, reg, value)                                          \
      {                                                                                     \
        MEMORY_BARRIER_W()                                                                  \
        if ((sharedadapter)->mac_type >= e1000_82543)                                       \
            (*((UINT32*)((sharedadapter)->hw_addr + E1000_##reg))) = (UINT32)(value);       \
        else                                                                                \
            (*((UINT32*)((sharedadapter)->hw_addr + E1000_82542_##reg))) = (UINT32)(value); \
      }

#define E1000_READ_REG(sharedadapter, reg)                            \
        (((sharedadapter)->mac_type >= e1000_82543)?                  \
            MEMORY_BARRIER_R()(*((UINT32*)((sharedadapter)->hw_addr + E1000_##reg))):      \
            MEMORY_BARRIER_R()(*((UINT32*)((sharedadapter)->hw_addr + E1000_82542_##reg)))) 

#define E1000_WRITE_REG_ARRAY(sharedadapter, reg, offset, value)                                                \
      {                                                                                                         \
        MEMORY_BARRIER_W()                                                                                       \
        if ((sharedadapter)->mac_type >= e1000_82543)                                                           \
            (*((UINT32*)((sharedadapter)->hw_addr + E1000_##reg + ((offset) << 2)))) = (UINT32)(value);       \
        else                                                                                                    \
            (*((UINT32*)((sharedadapter)->hw_addr + E1000_82542_##reg + ((offset) << 2)))) = (UINT32)(value); \
      }

#define E1000_READ_REG_ARRAY(sharedadapter, reg, offset)                                \
        (((sharedadapter)->mac_type >= e1000_82543)?                                      \
            MEMORY_BARRIER_R()(*((UINT32*)((sharedadapter)->hw_addr + E1000_##reg + ((offset) << 2)))):        \
            MEMORY_BARRIER_R()(*((UINT32*)((sharedadapter)->hw_addr + E1000_82542_##reg + ((offset) << 2))))) 

#define E1000_READ_REG_ARRAY_DWORD E1000_READ_REG_ARRAY
#define E1000_WRITE_REG_ARRAY_DWORD E1000_WRITE_REG_ARRAY

#define E1000_WRITE_REG_ARRAY_WORD(sharedadapter, reg, offset, value) \
            (*((UINT16*)((sharedadapter)->hw_addr + E1000_##reg + ((offset) << 1)))) = (UINT16)(value)

#define E1000_READ_REG_ARRAY_WORD(sharedadapter, reg, offset) \
           (*((UINT16*)((sharedadapter)->hw_addr + E1000_##reg + ((offset) << 1))))

#define E1000_WRITE_REG_ARRAY_BYTE(sharedadapter, reg, offset, value) \
            (*((UINT8*)((sharedadapter)->hw_addr + E1000_##reg + ((offset))))) = (UINT8)(value)

#define E1000_READ_REG_ARRAY_BYTE(sharedadapter, reg, offset) \
            (*((UINT8*)((sharedadapter)->hw_addr + E1000_##reg + ((offset)))))

// Used to READ/WRITE the flash on ICH8
#define E1000_READ_ICH_FLASH_REG(sharedadapter, reg) \
	(MEMORY_BARRIER_R()(*((UINT32*)((sharedadapter)->flash_address + reg)))) 

#define E1000_READ_ICH_FLASH_REG16(sharedadapter, reg) \
	(MEMORY_BARRIER_R()(*((UINT16*)((sharedadapter)->flash_address + reg)))) 

#define E1000_WRITE_ICH_FLASH_REG(sharedadapter, reg, value) \
      {                                                                                     \
        MEMORY_BARRIER_W()                                                                  \
            (*((UINT32*)((sharedadapter)->flash_address + reg))) = (UINT32)(value);         \
      }

#define E1000_WRITE_ICH_FLASH_REG16(sharedadapter, reg, value) \
      {                                                                                     \
        MEMORY_BARRIER_W()                                                                  \
            (*((UINT16*)((sharedadapter)->flash_address + reg))) = (UINT16)(value);         \
      }

#else // NOMEMIO
#define E1000_WRITE_REG(sharedadapter, reg, value) \
    e1000_write_reg_io((sharedadapter), \
        (((sharedadapter)->mac_type >= e1000_82543) ? E1000_##reg : E1000_82542_##reg), (UINT32)(value))

#define E1000_READ_REG(sharedadapter, reg) \
    e1000_read_reg_io((sharedadapter), \
        (((sharedadapter)->mac_type >= e1000_82543) ? E1000_##reg : E1000_82542_##reg))

#define E1000_WRITE_REG_ARRAY(sharedadapter, reg, offset, value) \
    e1000_write_reg_io((sharedadapter), \
        (((sharedadapter)->mac_type >= e1000_82543) ? E1000_##reg : E1000_82542_##reg) + \
        ((offset) << 2), (UINT32)(value))

#define E1000_READ_REG_ARRAY(sharedadapter, reg, offset) \
    e1000_read_reg_io((sharedadapter), \
        (((sharedadapter)->mac_type >= e1000_82543) ? E1000_##reg : E1000_82542_##reg) + \
        ((offset) << 2))

#define E1000_READ_REG_ARRAY_DWORD E1000_READ_REG_ARRAY
#define E1000_WRITE_REG_ARRAY_DWORD E1000_WRITE_REG_ARRAY

#define E1000_WRITE_REG_ARRAY_WORD(sharedadapter, reg, offset, value) \
    e1000_not_implemented("E1000_WRITE_REG_ARRAY_WORD")

#define E1000_READ_REG_ARRAY_WORD(sharedadapter, reg, offset) \
    e1000_not_implemented("E1000_READ_REG_ARRAY_WORD")

#define E1000_WRITE_REG_ARRAY_BYTE(sharedadapter, reg, offset, value) \
    e1000_not_implemented("E1000_WRITE_REG_ARRAY_BYTE")

#define E1000_READ_REG_ARRAY_BYTE(sharedadapter, reg, offset) \
    e1000_not_implemented("E1000_READ_REG_ARRAY_BYTE")

// Used to READ/WRITE the flash on ICH8
#define E1000_READ_ICH_FLASH_REG(sharedadapter, reg) \
    e1000_not_implemented("E1000_READ_ICH_FLASH_REG")

#define E1000_READ_ICH_FLASH_REG16(sharedadapter, reg) \
    e1000_not_implemented("E1000_READ_ICH_FLASH_REG16")

#define E1000_WRITE_ICH_FLASH_REG(sharedadapter, reg, value) \
    e1000_not_implemented("E1000_WRITE_ICH_FLASH_REG")

#define E1000_WRITE_ICH_FLASH_REG16(sharedadapter, reg, value) \
    e1000_not_implemented("E1000_WRITE_ICH_FLASH_REG16")

#endif // NOMEMIO

extern VOID usec_delay(UINT32 time);
extern void msec_delay (UINT32 msec);
#define msec_delay_irq msec_delay

#define E1000_WRITE_FLUSH(sharedadapter) E1000_READ_REG(sharedadapter, STATUS);

#if DBG
    #define DEBUGFUNC(F)	//EdbgOutputDebugString(F "\n")
    #define DEBUGOUT(S)         EdbgOutputDebugString(S) //TRACE(Adapter, DBG_SHARED_2,(S))
    #define DEBUGOUT1(S,A)      //TRACE(Adapter, DBG_SHARED_2,(S,A))
    #define DEBUGOUT2(S,A,B)    //TRACE(Adapter, DBG_SHARED_2,(S,A,B))
    #define DEBUGOUT3(S,A,B,C)  //TRACE(Adapter, DBG_SHARED_2,(S,A,B,C))
    #define DEBUGOUT7(S,A,B,C,D,E,F,G)  //TRACE(Adapter, DBG_SHARED_2,(S,A,B,C,D,E,F,G))
#else
    #define DEBUGFUNC
    #define DEBUGOUT(S)        ;
    #define DEBUGOUT1(S,A)     ;
    #define DEBUGOUT2(S,A,B)   ;
    #define DEBUGOUT3(S,A,B,C) ;
    #define DEBUGOUT7(S,A,B,C,D,E,F,G)  ;
#endif

//  The shared code doesn't define a SUCCESS macro, so
//  do it here.
#define E1000_SUCCESS 0

#define CMD_MEM_WRT_INVALIDATE		PCI_ENABLE_WRITE_AND_INVALIDATE
#define	__FUNC_NOT_IMPLEMENTED__	EdbgOutputDebugString("%s:%d not implemented\n", __FILE__, __LINE__);

#endif /* _NDIS_OS_H_ */
