mpc107Pci.c
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:6k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* mpc107Pci.c - MPC107 PCI bus support */
  2. /* Copyright 1996-2000 Wind River Systems, Inc. */
  3. #include "copyright_wrs.h"
  4. /*
  5. modification history
  6. --------------------
  7. 01b,11sep00,rcs fix includes
  8. 01a,06jun00,bri written
  9. */
  10. /*
  11. DESCRIPTION
  12. This module contains routines to detect whether the processor uses
  13. Address Map A or Address Map B and use the corresponding PCI address
  14. map depending on the the address map detected for PCI configuations.
  15. .SH INITIALIZATION
  16. mpc107MemMapDetect() should be called before any other PCI configuration
  17. functions are called.
  18. */
  19. /* includes */
  20. #include "vxWorks.h"
  21. #include "sysLib.h"
  22. #include "drv/pci/pciConfigLib.h"
  23. #include "drv/pci/pciIntLib.h"
  24. #include "drv/pci/pciAutoConfigLib.h"
  25. #include "drv/multi/mpc107.h"
  26. #include "drv/pci/mpc107Pci.h"
  27. /* static file scope locals */
  28. /* static locals which define the PREP or CHRP mapping */
  29. LOCAL ULONG  mpc107PciConfAddr;  /* PCI Configuration Address */
  30. LOCAL ULONG  mpc107PciConfData;  /* PCI Configuration Data */
  31. LOCAL ULONG  mpc107PciMstrCfgAdrs;  /* CPU's PCI Config Address */
  32. LOCAL ULONG  mpc107PciMstrCfgSize;   /* CPU's PCI Config Size */
  33. LOCAL ULONG  mpc107PciMstrIoLocal;  /* CPU's PCI IO Address */
  34. LOCAL ULONG  mpc107PciMstrIoSize;  /* CPU's PCI I/O Size */
  35. LOCAL ULONG  mpc107PciMstrIoBus;  /* PCI view of I/O */
  36. LOCAL ULONG  mpc107PciMstrIackLocal;  /* CPU's PCI IACK Address */
  37. LOCAL ULONG  mpc107PciMstrIackSize;  /* CPU's PCI IACK Address */
  38. LOCAL ULONG  mpc107PciMstrMemIoLocal; /* CPU's PCI Memory Address */
  39. LOCAL ULONG  mpc107PciSlvMemBus;  /* PCI view of system memory */
  40. LOCAL ULONG  mpc107PciMstrMemIoBus;  /* PCI view of PCI */
  41. LOCAL ULONG  mpc107PciMemorySize;     /* Memory Size */
  42. /* forward Declarations */
  43. LOCAL ULONG mpc107IndirectRegRead (ULONG regNum);
  44. /***************************************************************************
  45. *
  46. * mpc107MemMapDetect - detect PCI address map A or B
  47. *
  48. * This procedure detects the address map (A or B)  and
  49. * assigns proper values to some global variables.  First it assumes
  50. * that the memory map is of Map B, then reads the Vendor and Device
  51. * ids.  If the value does not match with what is expected, all global
  52. * variables are then set for Map A.
  53. *
  54. * The following global variables are set to reflect the PCI address map:
  55. * .CS
  56. *    mpc107PciConfAddr
  57. *    mpc107PciConfData
  58. *    mpc107PciMstrCfgAdrs
  59. *    mpc107PciMstrCfgSize
  60. *    mpc107PciMstrIoLocal
  61. *    mpc107PciMstrIoSize
  62. *    mpc107PciMstrIoBus
  63. *    mpc107PciMstrIackLocal
  64. *    mpc107PciMstrIackSize
  65. *    mpc107PciMstrMemIoLocal
  66. *    mpc107PciSlvMemBus
  67. *    mpc107PciMstrMemIoBus
  68. *    mpc107PciMemorySize
  69. * .CE
  70. *
  71. * RETURNS: N/A
  72. */
  73. void mpc107MemMapDetect(void)
  74.     {
  75.     ULONG retVal;
  76.     /*
  77.      * Read the Device & Vendor Id Register of PCI to  determine whether
  78.      * whether MAP A(PREP) or MAP B(CHRP) is to be used .
  79.      * We assume that the memory map is Map B  and attempt to read the MPC107's
  80.      * PCI Vendor and Device IDs. If we read it ok, then use map B, else assume
  81.      * map A.
  82.      */
  83.     mpc107PciConfAddr           = MPC107_CFG_ADDR_CHRP;
  84.     mpc107PciConfData           = MPC107_CFG_DATA_CHRP;
  85.     retVal = mpc107IndirectRegRead(MPC107_CFG_BASE);
  86.     /* Read Device & Vendor Ids */
  87.     if ((retVal == MPC107_DEV_VEN_ID )) /* True if it is address Map B */
  88.         {
  89.         /* If it is address Map B*/
  90.         mpc107PciConfAddr        = MPC107_CFG_ADDR_CHRP;
  91.         mpc107PciConfData        = MPC107_CFG_DATA_CHRP;
  92.         mpc107PciMstrCfgAdrs  = MPC107_PCI_MSTR_CFG_ADRS_B;
  93.         mpc107PciMstrCfgSize  = MPC107_PCI_MSTR_CFG_SIZE_B;
  94.         mpc107PciMstrIoLocal  = MPC107_PCI_MSTR_IO_LOCAL_B;
  95.         mpc107PciMstrIoSize      = MPC107_PCI_MSTR_IO_SIZE_B;
  96.         mpc107PciMstrIoBus  = MPC107_PCI_MSTR_IO_BUS_B;
  97.         mpc107PciMstrIackLocal  = MPC107_PCI_MSTR_IACK_LOCAL_B;
  98.         mpc107PciMstrIackSize  = MPC107_PCI_MSTR_IACK_SIZE_B;
  99.         mpc107PciMstrMemIoLocal  = MPC107_PCI_MSTR_MEMIO_LOCAL_B;
  100.         mpc107PciSlvMemBus  = MPC107_PCI_SLV_MEM_BUS_B;
  101.         mpc107PciMstrMemIoBus  = MPC107_PCI_MSTR_MEMIO_BUS_B;
  102.         mpc107PciMemorySize  = MPC107_PCI_MSTR_MEMIO_SIZE_B;
  103.         return ;
  104.         }
  105.     /* If it is Map -A */
  106.     mpc107PciConfAddr        = MPC107_CFG_ADDR_PREP;
  107.     mpc107PciConfData       = MPC107_CFG_DATA_PREP;
  108.     mpc107PciMstrCfgAdrs     = MPC107_PCI_MSTR_CFG_ADRS_A;
  109.     mpc107PciMstrCfgSize     = MPC107_PCI_MSTR_CFG_SIZE_A;
  110.     mpc107PciMstrIoLocal     = MPC107_PCI_MSTR_IO_LOCAL_A;
  111.     mpc107PciMstrIoSize      = MPC107_PCI_MSTR_IO_SIZE_A;
  112.     mpc107PciMstrIoBus      = MPC107_PCI_MSTR_IO_BUS_A;
  113.     mpc107PciMstrIackLocal   = MPC107_PCI_MSTR_IACK_LOCAL_A;
  114.     mpc107PciMstrIackSize    = MPC107_PCI_MSTR_IACK_SIZE_A;
  115.     mpc107PciMstrMemIoLocal  = MPC107_PCI_MSTR_MEMIO_LOCAL_A;
  116.     mpc107PciSlvMemBus       = MPC107_PCI_SLV_MEM_BUS_A;
  117.     mpc107PciMstrMemIoBus    = MPC107_PCI_MSTR_MEMIO_BUS_A;
  118.     mpc107PciMemorySize      = MPC107_PCI_MSTR_MEMIO_SIZE_A;
  119.     }
  120. /***************************************************************************
  121. *
  122. * mpc107IndirectRegRead - read a 32-bit address MPC107 register
  123. *
  124. * Read a 32-bit address MPC107 register and returns
  125. * a 32 bit value.  Swap the address to little endian before
  126. * writing it to config address since it is PCI, and swap the
  127. * value to big endian before returning to the caller.
  128. *
  129. * RETURNS: The contents of the specified MPC107 register.
  130. */
  131. LOCAL ULONG mpc107IndirectRegRead
  132.     (
  133.     ULONG regNum  /* register number */
  134.     )
  135.     {
  136.     ULONG temp;
  137.     /* swap the value to little endian */
  138.     *(ULONG *) mpc107PciConfAddr =  MPC107LONGSWAP(regNum);
  139.     SYNC;
  140.     temp = *(ULONG *) mpc107PciConfData;
  141.     SYNC;
  142.     /* swap the data & return */
  143.     return ( MPC107LONGSWAP (temp));
  144.     }