sysIo.c
资源名称:idt438.rar [点击查看]
上传用户:yingyi0918
上传日期:2022-06-26
资源大小:214k
文件大小:8k
源码类别:
VxWorks
开发平台:
C/C++
- /* sysIo.c - System Input/Output routines for IDT BSP. */
- /* Copyright 1984-2002 Wind River Systems, Inc. */
- #include "copyright_wrs.h"
- /*
- * This file has been developed or significantly modified by the
- * MIPS Center of Excellence Dedicated Engineering Staff.
- * This notice is as per the MIPS Center of Excellence Master Partner
- * Agreement, do not remove this notice without checking first with
- * WR/Platforms MIPS Center of Excellence engineering management.
- */
- /*
- modification history
- --------------------
- 01a,05mar02,d_c Make common for idt79s33x, idt79eb33x
- */
- /*
- DESCRIPTION
- This file contains the board-specific routines for intput and output.
- It is included as a part of sysLib.c.
- The "sysConfig*" functions (below) are necessary because the RC32334/RC32332
- PCI bridge does not perform byte-lane swapping for PCI config cycles.
- How ever it *does* perform byte-lane swapping for normal PCI cycles.
- The "sysConfig*" functions are only used by the PCI modules for
- config cycles.
- It is assumed that this file is include by sysLib.c.
- */
- /* includes */
- #include "vxWorks.h"
- #include "config.h"
- #include "sysLib.h"
- /* defines */
- /*
- * Override in/out functions used for PCI config cycle access. This
- * was necessary because the PCI controller does not perform byte-lane
- * swapping for config cycles. The "Config" functions are defined in
- * sysIo.c.
- */
- #define PCI_IN_BYTE(x) sysConfigInByte (x)
- #define PCI_IN_WORD(x) sysConfigInWord (x)
- #define PCI_IN_LONG(x) sysConfigInLong (x)
- #define PCI_OUT_BYTE(x,y) sysConfigOutByte (x,y)
- #define PCI_OUT_WORD(x,y) sysConfigOutWord (x,y)
- #define PCI_OUT_LONG(x,y) sysConfigOutLong (x,y)
- /* Macros for swapping bytes within words and half-words */
- #define SHORT_BYTESWAP(x) (MSB(x) | (LSB(x) << 8))
- #define LONG_BYTESWAP(x) LONGSWAP(x)
- /* typedefs */
- /* globals */
- /* locals */
- int sysVectorIRQ0 = INT_NUM_IRQ0 ;
- /* forward declarations */
- LOCAL BOOL sysIsPciMapped (ULONG address);
- /***************************************************************************
- *
- * sysConfigInByte - Read one byte from PCI configuration space
- *
- * RETURNS: The byte that was read
- */
- UCHAR sysConfigInByte
- (
- ULONG address /* Address to read */
- )
- {
- ULONG leAddress; /* Address offset for little endian access */
- /*
- * Address swap for byte address by XOR operation
- * to translate BigEndian to Litle Endian
- */
- leAddress = address ^ 0x3;
- return (*(UCHAR *)leAddress);
- }
- /***************************************************************************
- *
- * sysConfigInWord - Read one half-word from PCI configuration space
- *
- * RETURNS: The half-word that was read
- */
- USHORT sysConfigInWord
- (
- ULONG address /* Address to read */
- )
- {
- ULONG leAddress; /* Address offset for little endian access */
- /*
- * Address swap for half-word address by XOR operation
- * to translate BigEndian to Litle Endian
- */
- leAddress = address ^ 0x2;
- return (*(USHORT *)leAddress);
- }
- /***************************************************************************
- *
- * sysConfigInLong - Read one long word from PCI configuration space
- *
- * RETURNS: The word that was read
- */
- ULONG sysConfigInLong
- (
- ULONG address /* Address to read */
- )
- {
- return (*(ULONG *)address);
- }
- /***************************************************************************
- *
- * sysConfigOutByte - Write a byte to PCI configuration Space
- *
- * RETURNS: N/A
- */
- void sysConfigOutByte
- (
- ULONG address, /* Address to write to */
- UCHAR data /* Data to write */
- )
- {
- ULONG leAddress; /* Address offset for little endian access */
- /*
- * Address swap for byte address by XOR operation
- * to translate BigEndian to Litle Endian
- */
- leAddress = (address ^ 0x3);
- *(UCHAR *)leAddress = data;
- }
- /***************************************************************************
- *
- * sysConfigOutWord - Write a word to PCI configuration space
- *
- * RETURNS: N/A
- */
- void sysConfigOutWord
- (
- ULONG address, /* Address to write to */
- USHORT data /* Data to write */
- )
- {
- ULONG leAddress; /* Address offset for little endian access */
- /*
- * Address swap for half-word address by XOR operation
- * to translate BigEndian to Litle Endian
- */
- leAddress = (address ^ 0x2);
- *(USHORT *)leAddress = data;
- }
- /***************************************************************************
- *
- * sysConfigOutLong - Write a word to PCI configuration space
- *
- * RETURNS: N/A
- */
- void sysConfigOutLong
- (
- ULONG address, /* Address to write to */
- ULONG data /* Data to write */
- )
- {
- *(ULONG *)address = data;
- }
- /***************************************************************************
- *
- * sysInByte - Read one byte
- *
- * RETURNS: The byte that was read
- */
- UCHAR sysInByte
- (
- ULONG address /* Address to read */
- )
- {
- return (*(UCHAR *)address);
- }
- /***************************************************************************
- *
- * sysInWord - Read one word
- *
- * RETURNS: The half-word that was read, byte-swapped if read from PCI
- */
- USHORT sysInWord
- (
- ULONG address /* Address to read */
- )
- {
- USHORT retVal; /* Final return value */
- USHORT rawRetVal; /* Raw value before possible byte swap */
- rawRetVal = *(USHORT *)address;
- if (sysIsPciMapped (address))
- {
- retVal = (USHORT) SHORT_BYTESWAP(rawRetVal);
- }
- else
- {
- retVal = rawRetVal;
- }
- return (retVal);
- }
- /***************************************************************************
- *
- * sysInLong - Read a long word
- *
- * RETURNS: The word that was read, byte-swapped if read from PCI
- */
- ULONG sysInLong
- (
- ULONG address /* Address to read */
- )
- {
- ULONG retVal; /* Final return value */
- ULONG rawRetVal; /* Raw value before possible byte swap */
- rawRetVal = *(ULONG *)address;
- if (sysIsPciMapped (address))
- {
- retVal = LONG_BYTESWAP(rawRetVal);
- }
- else
- {
- retVal = rawRetVal;
- }
- return (retVal);
- }
- /***************************************************************************
- *
- * sysOutByte - Write a byte
- *
- * RETURNS: N/A
- */
- void sysOutByte
- (
- ULONG address, /* Address to write to */
- UCHAR data /* Data to write */
- )
- {
- *(UCHAR *)address = data;
- }
- /***************************************************************************
- *
- * sysOutWord - Write a word, swapping bytes if output to PCI space
- *
- * RETURNS: N/A
- */
- void sysOutWord
- (
- ULONG address, /* Address to write to */
- USHORT data /* Data to write */
- )
- {
- USHORT outData; /* Output data after possible byte swap */
- if (sysIsPciMapped (address))
- {
- outData = SHORT_BYTESWAP(data);
- }
- else
- {
- outData = data;
- }
- *(USHORT *)address = outData;
- }
- /***************************************************************************
- *
- * sysOutLong - Write a long word, swapping the bytes if output to PCI space
- *
- * RETURNS: N/A
- */
- void sysOutLong
- (
- ULONG address, /* Address to write to */
- ULONG data /* Data to write */
- )
- {
- ULONG outData; /* Output data after possible byte swap */
- if (sysIsPciMapped (address))
- {
- outData = LONG_BYTESWAP(data);
- }
- else
- {
- outData = data;
- }
- *(ULONG *)address = outData;
- }
- /**************************************************************************
- *
- * sysIsPciMapped - Is address within an area mapped to the PCI bus?
- *
- * This routine tests the passed address to determine if it is within
- * an area mapped to the PCI bus. This includes PCI I/O space and
- * PCI memory space 1, 2 and 3.
- *
- * RETURNS: TRUE if address falls in PCI-mapped space
- * FALSE otherwise
- */
- LOCAL BOOL sysIsPciMapped
- (
- ULONG address /* Address under consideration */
- )
- {
- BOOL isPciMapped = /* TRUE if address is PCI-mapped */
- (
- (
- address >= CPU_TO_PCI_MEM_BASE1 &&
- address < (CPU_TO_PCI_MEM_BASE1 + CPU_TO_PCI_MEM_SIZE1)
- )
- ||
- (
- address >= CPU_TO_PCI_MEM_BASE2 &&
- address < (CPU_TO_PCI_MEM_BASE2 + CPU_TO_PCI_MEM_SIZE2)
- )
- ||
- (
- address >= CPU_TO_PCI_MEM_BASE3 &&
- address < (CPU_TO_PCI_MEM_BASE3 + CPU_TO_PCI_MEM_SIZE3)
- )
- ||
- (
- address >= CPU_TO_PCI_IO_BASE &&
- address < (CPU_TO_PCI_IO_BASE + CPU_TO_PCI_IO_SIZE)
- )
- );
- return (isPciMapped);
- }