⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pci_api.h

📁 MIPS下的boottloader yamon 的源代码
💻 H
字号:

/************************************************************************
 *
 *  pci_api.h
 *
 *  PCI functions API
 *
 *
 * ######################################################################
 *
 * Copyright (c) 1999-2000 MIPS Technologies, Inc. All rights reserved. 
 * 
 * Unpublished rights reserved under the Copyright Laws of the United States of 
 * America. 
 * 
 * This document contains information that is proprietary to MIPS Technologies, 
 * Inc. ("MIPS Technologies"). Any copying, modifying or use of this information 
 * (in whole or in part) which is not expressly permitted in writing by MIPS 
 * Technologies or a contractually-authorized third party is strictly 
 * prohibited. At a minimum, this information is protected under unfair 
 * competition laws and the expression of the information contained herein is 
 * protected under federal copyright laws. Violations thereof may result in 
 * criminal penalties and fines. 
 * MIPS Technologies or any contractually-authorized third party reserves the 
 * right to change the information contained in this document to improve 
 * function, design or otherwise. MIPS Technologies does not assume any 
 * liability arising out of the application or use of this information. Any 
 * license under patent rights or any other intellectual property rights owned 
 * by MIPS Technologies or third parties shall be conveyed by MIPS Technologies 
 * or any contractually-authorized third party in a separate license agreement 
 * between the parties. 
 * The information contained in this document constitutes one or more of the 
 * following: commercial computer software, commercial computer software 
 * documentation or other commercial items. If the user of this information, or 
 * any related documentation of any kind, including related technical data or 
 * manuals, is an agency, department, or other entity of the United States 
 * government ("Government"), the use, duplication, reproduction, release, 
 * modification, disclosure, or transfer of this information, or any related 
 * documentation of any kind, is restricted in accordance with Federal 
 * Acquisition Regulation 12.212 for civilian agencies and Defense Federal 
 * Acquisition Regulation Supplement 227.7202 for military agencies. The use of 
 * this information by the Government is further restricted in accordance with 
 * the terms of the license agreement(s) and/or applicable contract terms and 
 * conditions covering this information from MIPS Technologies or any 
 * contractually-authorized third party. 
 *
 ************************************************************************/


#ifndef PCI_API_H
#define PCI_API_H


/************************************************************************
 *  Include files
 ************************************************************************/

#include <syserror.h>

/************************************************************************
 *  Definitions
*************************************************************************/


/* Known vendors and device IDs */
#define PCI_VENDID_GALILEO		0x11ab
#define PCI_DEVID_64120			0x4620

#define PCI_VENDID_PHILIPS		0x1131
#define PCI_DEVID_9730			0x9730

#define PCI_VENDID_INTEL_A		0x1011
#define PCI_DEVID_PPB			0x0022

#define PCI_VENDID_INTEL		0x8086
#define PCI_DEVID_PIIX4_BRIDGE	0x7110
#define PCI_DEVID_PIIX4_IDE		0x7111
#define PCI_DEVID_PIIX4_USB		0x7112
#define PCI_DEVID_PIIX4_POWER	0x7113

#define PCI_VENDID_SYMBIOS		0x1000
#define PCI_DEVID_SCSI			0x0001

#define PCI_VENDID_AMD			0x1022
#define PCI_DEVID_79C973		0x2000

#define PCI_VENDID_CRYSTAL		0x1013
#define PCI_DEVID_4281			0x6005

/* Local bus number */
#define PCI_BUS_LOCAL			0


/*  Mapping between PCI device number and address bit 
 *  (ADP<n>) used for IDSEL is :
 *  
 *  Device number 1 maps to ADP11
 *  Device number 2 maps to ADP12
 *  ...
 *  Device number 21 maps to ADP31
 *
 *  In other words :
 *
 *  Address bit = Device number + 10 (Device number = 1..21)
 */

#define PCI_IDSEL2DEVNUM(idsel)	  ((idsel) - 10)


#ifndef _ASSEMBLER_


/* BAR definition */

typedef struct pci_bar
{
    struct pci_bar  *next;	/* Reserved (linked list ptr)		*/

    UINT8           pos;	/* BAR position (word index)		*/
    UINT8           io;		/* 1 -> IO mapped, 0 -> Memory mapped   */
    UINT32          mask;       /* Mask obtained from device		*/
    UINT8	    prefetch;   /* Prefetch field obtained from device	*/
    UINT32	    start;	/* PCI side start address of range	*/
    UINT32	    size;	/* Size of range			*/
    bool	    fixed;	/* TRUE -> Fixed location BAR		*/
}
t_pci_bar;


/* PCI device definition */

typedef struct
{
    UINT8      bus;
    UINT8      dev;
    UINT8      function;
    UINT8      ht;
    UINT8      multi;
    UINT8      lat_tim;
    UINT16     devid;
    UINT16     vendorid;
    UINT16     status;
    UINT32     class;
    UINT8      revid;
    UINT8      max_lat;
    UINT8      min_gnt;
    UINT8      intpin;
    UINT8      intline;

/*  Offsets :
 *    The system controller supports remapping of memory
 *    and IO ranges so that the addresses seen on the CPU side (SysAD) of
 *    the controller and the addresses seen on PCI are offset by some amount.
 *    The CPU side start address is found by adding the offset to the
 *    PCI side start address.
 */
    UINT32     mem_offset;
    UINT32     io_offset;

    UINT8      bar_count;	/* Number of active BARs	*/

/* Array of BARs */
#define PCI_BAR_MAXCOUNT	6
    t_pci_bar  bar[PCI_BAR_MAXCOUNT];
}
t_pci_cfg_dev;


/* Error codes */

typedef enum pci_error_ids
{
    ERROR_PCI_MALLOC = ERROR_PCI,
    ERROR_PCI_RANGE,
    ERROR_PCI_UNKNOWN_DEVICE,
    ERROR_PCI_ABORT,
    ERROR_PCI_STRUCTURE
} t_pci_error_ids;


/************************************************************************
 *  Public variables
 ************************************************************************/

/************************************************************************
 *  Public functions
 ************************************************************************/


/************************************************************************
 *
 *                          pci_init
 *  Description :
 *  -------------
 *
 *  PCI module initialisation function
 *
 *  Return values :
 *  ---------------
 *
 *  OK if no error, else error code
 *
 ************************************************************************/
UINT32
pci_init( 
    UINT32   mem_start,		/* Start of PCI memory range		*/
    UINT32   mem_size,		/* Size of PCI memory range		*/
    UINT32   mem_offset,	/* Offset of PCI memory range		*/

    UINT32   io_start,		/* Start of PCI io range		*/
    UINT32   io_size,		/* Size of PCI io range			*/
    UINT32   io_offset );	/* Offset of PCI io range		*/


/************************************************************************
 *
 *                          pci_lookup_device
 *  Description :
 *  -------------
 *
 *  Obtains data for device.
 *
 *  If more than one device fits the IDs and function number, the
 *  device is selected based on the following priority :
 *
 *  1) Known local (bus 0) device
 *  2) First unknown local (bus 0) device found (based on device number)
 *  3) First unknown remote (bus != 0) device found (based on device number)
 *
 *  Return values :
 *  ---------------
 *
 *  TRUE  : Device found
 *  FALSE : Device not found
 *
 ************************************************************************/
bool
pci_lookup_device(
    UINT16        vendorid,		/* Vendor ID			*/
    UINT16        devid,		/* Device ID			*/
    UINT8	  function,		/* Function number		*/
    t_pci_cfg_dev *data );		/* Pointer to structure where
					   device data will be written  */


/************************************************************************
 *
 *                          pci_lookup_bar
 *  Description :
 *  -------------
 *
 *  Determine base address (physical) of specific BAR of specific device.
 *
 *  If more than one device fits the IDs and function number, the
 *  device is selected based on the following priority :
 *
 *  1) Known local (bus 0) device
 *  2) First unknown local (bus 0) device found (based on device number)
 *  3) First unknown remote (bus != 0) device found (based on device number)
 *
 *  Return values :
 *  ---------------
 *
 *  TRUE  : BAR found
 *  FALSE : BAR not found
 *
 ************************************************************************/
bool
pci_lookup_bar(
    UINT16        vendorid,		/* Vendor ID			*/
    UINT16        devid,		/* Device ID			*/
    UINT8	  function,		/* Function number		*/
    UINT8	  bar,			/* Address of BAR register	*/
    void	  **param );		/* OUT : Base address of BAR	*/


/************************************************************************
 *
 *                          pci_display
 *  Description :
 *  -------------
 *
 *  Display devices detected during autodetect and display the 
 *  autoconfiguration data (memory space and IO space allocations)
 *
 *  Return values :
 *  ---------------
 *
 *  None
 *
 ************************************************************************/
void
pci_display( void );


/************************************************************************
 *
 *                          pci_busfreq_string
 *  Description :
 *  -------------
 *
 *  Format string containing PCI bus freqency in format xx.yy MHz
 *
 *  Return values :
 *  ---------------
 *
 *  None
 *
 ************************************************************************/
void
pci_busfreq_string(
    char   *msg,
    UINT32 freq_kHz );


/************************************************************************
 *
 *                          pci_iack
 *  Description :
 *  -------------
 *
 *  Perform PCI Interrupt Acknowledge Cycle
 *
 *  Return values :
 *  ---------------
 *
 *  Vector obtained from cycle
 *
 ************************************************************************/
UINT32
pci_iack( void );


/************************************************************************
 *
 *                          pci_config_read32/16/8
 *  Description :
 *  -------------
 *
 *  Low level pci configuration space read routines (32/16/8 bit)
 *
 *  Return values :
 *  ---------------
 *
 *  0 (No error) or ERROR_PCI_ABORT    
 *
 ************************************************************************/
UINT32
pci_config_read32(
    UINT32 busnum,	/* IN   bus number           */
    UINT32 devnum,	/* IN   device number        */
    UINT32 func,	/* IN   function number      */
    UINT32 reg,		/* IN   address		     */
    UINT32  *data );	/* OUT  pointer to data read */

UINT32
pci_config_read16(
    UINT32 busnum,	/* IN   bus number           */
    UINT32 devnum,	/* IN   device number        */
    UINT32 func,	/* IN   function number      */
    UINT32 reg,		/* IN   address		     */
    UINT16  *data );	/* OUT  pointer to data read */

UINT32
pci_config_read8(
    UINT32 busnum,	/* IN   bus number           */
    UINT32 devnum,	/* IN   device number        */
    UINT32 func,	/* IN   function number      */
    UINT32 reg,		/* IN   address		     */
    UINT8  *data );	/* OUT  pointer to data read */


/************************************************************************
 *
 *                          pci_config_write32/16/8
 *  Description :
 *  -------------
 *
 *  Low level pci configuration space write routines (32/16/8 bit)
 *
 *  Return values :
 *  ---------------
 *
 *  0 (No error) or ERROR_PCI_ABORT    
 *
 ************************************************************************/
UINT32
pci_config_write32(
    UINT32 busnum,	/* IN   bus number      */
    UINT32 devnum,	/* IN   device number   */
    UINT32 func,	/* IN   function number */
    UINT32 reg,		/* IN   address		*/
    UINT32 data );	/* IN   data to write   */

UINT32
pci_config_write16(
    UINT32 busnum,	/* IN   bus number      */
    UINT32 devnum,	/* IN   device number   */
    UINT32 func,	/* IN   function number */
    UINT32 reg,		/* IN   address		*/
    UINT16 data );	/* IN   data to write   */

UINT32
pci_config_write8(
    UINT32 busnum,	/* IN   bus number      */
    UINT32 devnum,	/* IN   device number   */
    UINT32 func,	/* IN   function number */
    UINT32 reg,		/* IN   address		*/
    UINT8  data );	/* IN   data to write   */



#endif /* #ifndef _ASSEMBLER_ */

#endif /* #ifndef PCI_API_H */



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -