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

📄 sysdec21x40end.c

📁 VxWorks的bootloader实现
💻 C
字号:
/* sysDec21x40End.c - system configuration module for Dec21x40 END */ /* Copyright 1984 - 1999 Wind River Systems, Inc. */ /*modification history--------------------01d,07mar02,kab  SPR 70817: *EndLoad returns NULL on failure01c,24jan02,pcs  Remove Warnings (DIAB) .01b,21mar01,pcs  Removed references to DEC_USR_PHY_CHK, since it is no longer                 needed.01a,10oct99,mtl   written from yk 750 by teamF1*//*DESCRIPTIONThis is the WRS-supplied configuration module for the VxWorks dec21x40End (dc) END driver.  It performs the dynamic parameterization of the dec21x40End driver.  This technique of 'just-in-time' parameterization allows driver parameter values to be declared as any other defined constants rather than as static strings. */ #if (defined(INCLUDE_NETWORK) && defined(INCLUDE_DC_END) \     && defined (INCLUDE_END))/* includes */#include "vxWorks.h"#include "stdio.h"#include "stdlib.h"#include "string.h"#include "end.h"#include "config.h"#include "drv/end/dec21x40End.h"	/* defines *//* DEC 21X4X 10/100Base-TX Board type */#define EB143           1       /* DEC 21143 10/100Base-TX Evaluation Board */#define DC140           2       /* DEC 21140 10/100Base-TX Based Board */#define DC040           3       /* DEC 21040 10/100Base-TX Based Board */#define BOARD_TYPE_NB   3/* 040/140/143 DEC driver user flags */#define DEC_USR_FLAGS_143 (DEC_USR_21143 )#define DEC_USR_FLAGS_140 (DEC_USR_BAR_RX | DEC_USR_RML | DEC_USR_CAL_08 | \                           DEC_USR_PBL_04 | DEC_USR_21140 )#define DEC_USR_FLAGS_040 (DEC_USR_BAR_RX | DEC_USR_CAL_08 | DEC_USR_PBL_04)/* DEC 21X4X PCI/CardBus specific definitions */#define DEC21X4X_PCI_VENDOR_ID  0x1011  /* PCI vendor ID */#define DEC21143_PCI_DEVICE_ID  0x0019  /* PCI device ID */#define DEC21140_PCI_DEVICE_ID  0x0009  /* PCI device ID */#define DEC21040_PCI_DEVICE_ID  0x0002  /* PCI device ID *//* This is where our dec pci memory space resides which  depends on the map  *  This is the address used to call dcattach */#define DEC_PCI_MEMBASE_MAP_A		0x80000000#define DEC_DEVADDR_MAP_A		0xC0000000#define DEC_PCI_MEMBASE_MAP_B		0x00000000#define DEC_DEVADDR_MAP_B		0x80000000/* forward declarations */STATUS sysDec21143MediaSelect (DEC21X40_DRV_CTRL *, UINT *);STATUS sysDec21140MediaSelect (DEC21X40_DRV_CTRL *, UINT *);/* typedefs */ typedef struct sysDecPciRsrc            /* SYS_DEC_PCI_RSRC */    {    UINT32      iobaseCsr;              /* Base Address Register 0 */    UINT32      membaseCsr;             /* Base Address Register 1 */    char        irq;                    /* Interrupt Request Level */    UINT32      irqvec;                 /* Interrupt Request vector */    UINT32      configType;             /* type of configuration */    UINT32      boardType;              /* type of LAN board this unit is */    UINT32      pciBus;                 /* PCI Bus number */    UINT32      pciDevice;              /* PCI Device number */    UINT32      pciFunc;                /* PCI Function number */    } SYS_DEC_PCI_RSRC;typedef struct sysDecBoardRsrc          /* SYS_DEC_BD_RSRC */    {    UINT32      type;           	/* type of the board */    UINT32      vendorId;               /* Vendor ID */    UINT32      deviceId;               /* Device ID */    UINT32      decUsrFlags;            /* DEC driver user flags */    FUNCPTR     mediaSelectFunc;        /* media select routine */    } SYS_DEC_BD_RSRC;/* locals *//* * This array defines the board-specific PCI resources, the base address * register configuration mode and the Ethernet adapter type. It's indexed * using the device number returned from pciFindDevice(). */ LOCAL SYS_DEC_PCI_RSRC sysDecPciRsrcs [PCI_MAX_DEV] =    {    {0, 0, 0, 0, 0, DC140, 0, 0, 0},    {0, 0, 0, 0, 0, DC040, 0, 0, 0},    {0, 0, 0, 0, 0, EB143, 0, 0, 0},    {0, 0, 0, 0, 0, EB143, 0, 0, 0},    };/* * This array defines board-specific vendor and device ids, flags to pass to * the driver load routine and the function used to select the media. */LOCAL SYS_DEC_BD_RSRC sysDecBoardRsrc [BOARD_TYPE_NB] =    {    {EB143, DEC21X4X_PCI_VENDOR_ID, DEC21143_PCI_DEVICE_ID, DEC_USR_FLAGS_143,\     sysDec21143MediaSelect},    {DC140, DEC21X4X_PCI_VENDOR_ID, DEC21140_PCI_DEVICE_ID, DEC_USR_FLAGS_140,\     sysDec21140MediaSelect},    {DC040, DEC21X4X_PCI_VENDOR_ID, DEC21040_PCI_DEVICE_ID, DEC_USR_FLAGS_040,\     NULL},    };LOCAL UINT32    sysDecPciDevNo = 0;         /* PCI device populated */LOCAL UINT32    sysDecBoardTypeNo = 0;      /* board type used */IMPORT END_OBJ* dec21x40EndLoad (char *);IMPORT int pciIntToIrq(int devNo, int pciInt);/******************************************************************************** sysDec21x40EndLoad - create load string and load a dec21x40 (dc) device.** This routine loads the dc device with initial parameters probed* during dec21x40PciInit().** RETURNS: pointer to END object or NULL.** SEE ALSO: dec21x40EndLoad()*/ END_OBJ * sysDec21x40EndLoad    (    char * pParamStr,   /* ptr to initialization parameter string */    void * unused       /* unused optional argument */    )    {    /*     * The dec21x40End driver END_LOAD_STRING should be:     * The format of the parameter string is:     *     * "<device_addr>:<PCI_addr>:<ivec>:<ilevel>:<num_rds>:<num_tds>:     * <mem_base>:<mem_size>:<user_flags>"     *     * Note that dec21x40 unit number is prepended in muxDevLoad, so we      * don't put it here!     */    char * cp; 			    char paramStr [END_INIT_STR_MAX];   	/* end.h */    END_OBJ * pEnd;    static char decParamTemplate[] = "0x%x:0x%x:0x%x:0x%x:-1:-1:-1:0:0x%x";    SYS_DEC_PCI_RSRC * pRsrc = &(sysDecPciRsrcs[sysDecPciDevNo]);    if (strlen (pParamStr) == 0)        {        /*          * muxDevLoad() calls us twice.  If the string is         * zero length, then this is the first time through         * this routine, so we just return.         */        pEnd = dec21x40EndLoad (pParamStr);        }    else	{        /*         * On the second pass though here, we actually create          * the initialization parameter string on the fly.            * Note that we will be handed our unit number on the          * second pass through and we need to preserve that information.         * So we use the unit number handed from the input string.         */        cp = strcpy (paramStr, pParamStr); /* cp points to paramStr */        /* Now, we advance cp, by finding the end the string */        cp += strlen (paramStr);                /* finish off the initialization parameter string */	sprintf (cp, decParamTemplate,                  /* device memory Io base */                 (UINT) PCI_MEMIO2LOCAL (pRsrc->membaseCsr),                  (UINT) PCI_SLV_MEM_LOCAL,         /* pciMemBase */                  pRsrc->irqvec,             /* interrupt IRQ vector */                  pRsrc->irq,                /* interrupt irq number */                  sysDecBoardRsrc[sysDecBoardTypeNo].decUsrFlags);        if ((pEnd = dec21x40EndLoad (paramStr)) == (END_OBJ *)NULL)	    {            printf ("Error: Dec21x4x device failed dec21x40EndLoad routine.\n");	    }	}    return (pEnd);    }/********************************************************************************* sysDec21x40PciInit - prepare LAN adapter for DEC21X4X initialization** This routine finds the PCI device, and maps its memory and IO address.* It must be done prior to initializing the DEC21X4X, sysDec21x40Init().  ** RETURNS: N/A*/STATUS sysDec21x40PciInit (void)    {    SYS_DEC_PCI_RSRC *  pRsrc;          /* dec resource */    INT32              pciBus;         /* PCI Bus number */    INT32              pciDevice;      /* PCI Device number */    INT32              pciFunc;        /* PCI Function number */    UINT32              membaseCsr;     /* Base Address Register 1 */    UINT32              iobaseCsr;      /* Base Address Register 0 */    char                irq;            /* Interrupt Request Level */    UINT32              boardType = NONE; /* board type detected */    BOOL                found = FALSE;    /*     * The following code tries to automatically detect the first instance     * of a DEC21143, DEC21140 or DEC21040 Ethernet based PCI board.     */    for (sysDecBoardTypeNo = 0; sysDecBoardTypeNo < BOARD_TYPE_NB; 	 sysDecBoardTypeNo++)        {        if (pciFindDevice (sysDecBoardRsrc[sysDecBoardTypeNo].vendorId,                               sysDecBoardRsrc[sysDecBoardTypeNo].deviceId,                               0, &pciBus, &pciDevice, &pciFunc) == OK)            {            /* board detected */            found = TRUE;            boardType = sysDecBoardRsrc[sysDecBoardTypeNo].type;            /* select the media function */            _func_dec21x40MediaSelect = 		sysDecBoardRsrc[sysDecBoardTypeNo].mediaSelectFunc;            break;            }        }    if (!found || (pciDevice > PCI_MAX_DEV))        {        return (ERROR);        }    /* we found the right one */    sysDecPciDevNo = pciDevice;    sysDecPciRsrcs[sysDecPciDevNo].boardType = boardType;    pRsrc = &(sysDecPciRsrcs[sysDecPciDevNo]);    pRsrc->pciBus    = pciBus;    pRsrc->pciDevice = pciDevice;    pRsrc->pciFunc   = pciFunc;#ifdef PCI_CONFIG_FORCE    if (sysPciMstrCfgAdrs == PCI_MSTR_CNFG_ADRS_A) /* map A */	{        membaseCsr = DEC_PCI_MEMBASE_MAP_A;        iobaseCsr = DEC_DEVADDR_MAP_A;  	}    else /* map B */	{        membaseCsr = DEC_PCI_MEMBASE_MAP_B;        iobaseCsr = DEC_DEVADDR_MAP_B;  	}    irq = pciIntToIrq(pciDevice, INTA);    pciDevConfig(pRsrc->pciBus, pRsrc->pciDevice, pRsrc->pciFunc,                 iobaseCsr, membaseCsr,            PCI_CMD_IO_ENABLE | PCI_CMD_MEM_ENABLE | PCI_CMD_MASTER_ENABLE);#endif    /* get memory base address and IO base address */    pciConfigInLong (pRsrc->pciBus, pRsrc->pciDevice, pRsrc->pciFunc,                            PCI_CFG_BASE_ADDRESS_0, &iobaseCsr);    pciConfigInLong (pRsrc->pciBus, pRsrc->pciDevice, pRsrc->pciFunc,                            PCI_CFG_BASE_ADDRESS_1, &membaseCsr);    pciConfigInByte (pRsrc->pciBus, pRsrc->pciDevice, pRsrc->pciFunc,                            PCI_CFG_DEV_INT_LINE, &irq);    membaseCsr   &= PCI_MEMBASE_MASK;    iobaseCsr    &= PCI_IOBASE_MASK;    /* overwrite the resource table with read value */     pRsrc->membaseCsr   = membaseCsr;    pRsrc->iobaseCsr    = iobaseCsr;    pRsrc->irq          = irq;    pRsrc->irqvec       = IVEC_TO_INUM(irq);    /*      * enable mapped memory and IO addresses.     */    pciConfigOutWord (pciBus, pciDevice, pciFunc, PCI_CFG_COMMAND,                      PCI_CMD_MEM_ENABLE | 		      PCI_CMD_IO_ENABLE  | 		      PCI_CMD_MASTER_ENABLE);    /* disable sleep mode */    pciConfigOutByte (pciBus, pciDevice, pciFunc, PCI_CFG_MODE, 		      SLEEP_MODE_DIS);    return (OK);    }/********************************************************************************* sysDec21x40Init - prepare LAN adapter for dec21X4X initialization** This routine is expected to perform any adapter-specific or target-specific* initialization that must be done prior to initializing the dec21X4X.** The dec21X4X driver calls this routine from the driver endLoad routine before* any other routines in this library.** This routine determines the base address, the main memory address over * the PCI bus, the interrupt level and the interrupt vector parameter.** RETURNS: OK or ERROR if the adapter could not be prepared for initialization.*/ STATUS sysDec21x40Init    (    DEC21X40_DRV_CTRL * pDrvCtrl    )    {    SYS_DEC_PCI_RSRC * pRsrc = &(sysDecPciRsrcs [sysDecPciDevNo]);     /* locate the dec21X4X based adapter. */    switch (pRsrc->boardType)        {        case EB143 :        case DC140 :        case DC040 :            /* set the device control structure */             pDrvCtrl->devAdrs = PCI_MEMIO2LOCAL (pRsrc->membaseCsr);            pDrvCtrl->pciMemBase = PCI_SLV_MEM_LOCAL;            pDrvCtrl->ilevel = pRsrc->irq;            pDrvCtrl->ivec = pRsrc->irqvec;            break;        default :            return (ERROR);        }     return (OK);    } /********************************************************************************* sysDec21x40EnetAddrGet - get Ethernet address** This routine provides a target-specific interface for accessing a* device Ethernet address.** RETURNS: OK or ERROR if could not be obtained.*/STATUS  sysDec21x40EnetAddrGet    (    int         unit,    char *      enetAdrs    )    {    /*     * There isn't a target-specific interface for accessing a     * device Ethernet address.     */    return (ERROR);    }/********************************************************************************* sysDec21143MediaSelect - hook routine for dec21x40Start** This is hook routine for dec21x40Start(). This routine selects a media for* dec21143 board.** RETURNS: OK, always.*/ STATUS sysDec21143MediaSelect    (    DEC21X40_DRV_CTRL *      pDrvCtrl,   /* Driver control */    UINT *                   pCsr6Val    /* CSR6 return value */    )    {    ULONG *     csrReg;    ULONG       csrData;    /* set CSR6 value */     *pCsr6Val |= CSR6_21140_MB1;    /* Led/Control selection */     csrReg   = (ULONG *)(pDrvCtrl->devAdrs + (CSR15 * DECPCI_REG_OFFSET));    csrData  = (CSR15_21143_CWE | CSR15_21143_LG3 | CSR15_21143_LG1                                                         | CSR15_MD_MSK);    *csrReg  = PCISWAP (csrData);    csrData = (CSR15_21143_LG3 | CSR15_21143_LG1 | CSR15_MODE_10);    *csrReg  = PCISWAP (csrData);    /* force 10Base-T halh duplex configuration */     /* set SIA registers */     csrReg   = (ULONG *)(pDrvCtrl->devAdrs + (CSR14 * DECPCI_REG_OFFSET));    csrData  = PCISWAP (*csrReg);    csrData &= ~(CSR14_21143_T4 | CSR14_21143_TXF| CSR14_21143_TXH |                        CSR14_21143_TAS | CSR14_21143_TH | CSR14_21143_ANE);    *csrReg = PCISWAP(csrData);     csrReg   = (ULONG *)(pDrvCtrl->devAdrs + (CSR13 * DECPCI_REG_OFFSET));    csrData  = PCISWAP (*csrReg);    csrData |= CSR13_SRL_SIA;    *csrReg  = PCISWAP (csrData);     return (OK);    }/********************************************************************************* sysDec21140MediaSelect - hook routine for dec21x40Start** This is hook routine for dec21x40Start(). This routine selects a media for* dec21140 board.** RETURNS: OK, always.*/STATUS sysDec21140MediaSelect    (    DEC21X40_DRV_CTRL *      pDrvCtrl,   /* Driver control */    UINT *                   pCsr6Val    /* CSR6 return value */    )    {    /* set CSR6 value */    *pCsr6Val = CSR6_21140_PS;    return (OK);    }#endif /* defined(INCLUDE_NETWORK) && defined(INCLUDE_DC_END) */

⌨️ 快捷键说明

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