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

VxWorks

开发平台:

C/C++

  1. /* iPIIX4.c - low level initalization code for PCI ISA/IDE Xcelerator */
  2. /* Copyright 1984-2000 Wind River Systems, Inc. */
  3. #include "copyright_wrs.h"
  4. /*
  5. modification history
  6. --------------------
  7. 01f,16jun02,jln  fix compiler warning for elreg
  8. 01e,27apr02,dmh  fix for SPR76412 level/edge mistake
  9. 01d,24apr02,dmh  remove search for ipiix4 and assume its location instead.
  10. 01c,18nov01,dmh  enable 256 bytes of RTC nvram
  11. 01b,01nov01,dgp  doc: correct formatting to clean up doc build
  12. 01a,17oct01,dmh  written. Use iPIIX4.c instead of iPiix4Pci.c.
  13. */
  14. /*
  15. DESCRIPTION
  16. The 82371AB PCI ISA IDE Xcelerator (PIIX4) is a multi-function PCI device
  17. implementing a PCI-to-ISA bridge function, a PCI IDE function, a Universal
  18. Serial Bus host/hub function, and an Enhanced Power Management function. As
  19. a PCI-to-ISA bridge, PIIX4 integrates many common I/O functions found in
  20. ISA-based PC systems-two 82C37 DMA Controllers, two 82C59 Interrupt Controllers,
  21. an 82C54 Timer/Counter, and a Real Time Clock. In addition to compatible
  22. transfers, each DMA channel supports Type F transfers. PIIX4 also contains full
  23. support for both PC/PCI and Distributed DMA protocols implementing PCI-based
  24. DMA. The Interrupt Controller has Edge or Level sensitive programmable inputs
  25. and fully supports the use of an external I/O Advanced Programmable Interrupt
  26. Controller (APIC) and Serial Interrupts. Chip select decoding is provided for
  27. BIOS, Real Time Clock, Keyboard Controller, second external microcontroller,
  28. as well as two Programmable Chip Selects.
  29. PIIX4 is a multi-function PCI device that integrates many system-level
  30. functions. PIIX4 is compatible with the PCI Rev 2.1 specification, as well as
  31. the IEEE 996 specification for the ISA (AT) bus.
  32. .IP "PCI to ISA/EIO Bridge"
  33. PIIX4 can be configured for a full ISA bus or a subset of the ISA bus called the
  34. Extended IO (EIO) bus. The use of the EIO bus allows unused signals to be
  35. configured as general purpose inputs and outputs. PIIX4 can directly drive up to
  36. five ISA slots without external data or address buffering. It also provides
  37. byte-swap logic, I/O recovery support, wait-state generation, and SYSCLK
  38. generation. X-Bus chip selects are provided for Keyboard Controller, BIOS,
  39. Real Time Clock, a second microcontroller, as well as two programmable chip
  40. selects. PIIX4 can be configured as either a subtractive decode PCI to ISA
  41. bridge or as a positive decode bridge. This gives a system designer the option
  42. of placing another subtractive decode bridge in the system (e.g., an Intel
  43. 380FB Dock Set).
  44. .IP "IDE Interface (Bus Master capability and synchronous DMA Mode)"
  45. The fast IDE interface supports up to four IDE devices providing an interface
  46. for IDE hard disks and CD ROMs. Each IDE device can have independent timings.
  47. The IDE interface supports PIO IDE transfers up to 14 Mbytes/sec and Bus Master
  48. IDE transfers up to 33 Mbytes/sec. It does not consume any ISA DMA resources.
  49. The IDE interface integrates 16x32-bit buffers for optimal transfers.
  50. PIIX4's IDE system contains two independent IDE signal channels. They can be
  51. configured to the standard primary and secondary channels (four devices) or
  52. primary drive 0 and primary drive 1 channels (two devices).This allows
  53. flexibility in system design and device power management.
  54. .IP "Compatibility Modules"
  55. The DMA controller incorporates the logic of two 82C37 DMA controllers, with
  56. seven independently programmable channels. Channels [0:3] are hardwired to
  57. 8-bit, count-by-byte transfers, and channels [5:7] are hardwired to 16-bit,
  58. count-by-word transfers. Any two of the seven DMA channels can be programmed to 
  59. support fast Type-F transfers. The DMA controller also generates the ISA refresh
  60. cycles.
  61. The DMA controller supports two separate methods for handling legacy DMA via the
  62. PCI bus. The PC/PCI protocol allows PCI-based peripherals to initiate DMA cycles
  63. by encoding requests and grants via three PC/PCI REQ#/GNT# pairs. The second
  64. method, Distributed DMA, allows reads and writes to 82C37 registers to be
  65. distributed to other PCI devices. The two methods can be enabled concurrently.
  66. The serial interrupt scheme typically associated with Distributed DMA is also
  67. supported.
  68. The timer/counter block contains three counters that are equivalent in function
  69. to those found in one 82C54 programmable interval timer. These three counters
  70. are combined to provide the system timer function, refresh request, and speaker
  71. tone. The 14.31818-MHz oscillator input provides the clock source for these
  72. three counters.
  73. PIIX4 provides an ISA-Compatible interrupt controller that incorporates the
  74. functionality of two 82C59 interrupt controllers. The two interrupt
  75. controllers are cascaded so that 14 external and two internal interrupts are
  76. possible. In addition, PIIX4 supports a serial interrupt scheme. PIIX4 provides
  77. full support for the use of an external IO APIC.
  78. .IP "Enhanced Universal Serial Bus (USB) Controller"
  79. The PIIX4 USB controller provides enhanced support for the Universal Host
  80. Controller Interface (UHCI). This includes support that allows legacy software
  81. to use a USB-based keyboard and mouse.
  82. .IP "RTC"
  83. PIIX4 contains a Motorola MC146818A-compatible real-time clock with 256 bytes
  84. of battery-backed RAM. The real-time clock performs two key functions: keeping
  85. track of the time of day and storing system data, even when the system is
  86. powered down. The RTC operates on a 32.768-kHz crystal and a separate 3V lithium
  87. battery that provides up to 7 years of protection.
  88. The RTC also supports two lockable memory ranges. By setting bits in the
  89. configuration space, two 8-byte ranges can be locked to read and write accesses.
  90. This prevents unauthorized reading of passwords or other system security
  91. information. The RTC also supports a date alarm, that allows for scheduling a
  92. wake up event up to 30 days in advance, rather than just 24 hours in advance.
  93. .IP "GPIO and Chip Selects"
  94. Various general purpose inputs and outputs are provided for custom system
  95. design. The number of inputs and outputs varies depending on PIIX4
  96. configuration. Two programmable chip selects are provided which allows the
  97. designer to place devices on the X-Bus without the need for external decode logic.
  98. .IP "Pentium and Pentium II Processor Interface"
  99. The PIIX4 CPU interface allows connection to all Pentium and Pentium II
  100. processors. The Sleep mode for the Pentium II processors is also supported.
  101. .IP "Enhanced Power Management"
  102. PIIX4's power management functions include enhanced clock control, local and
  103. global monitoring support for 14 individual devices, and various low-power
  104. (suspend) states, such as Power-On Suspend, Suspend-to-DRAM, and
  105. Suspend-to-Disk. A hardware-based thermal management circuit permits
  106. software-independent entrance to low-power states. PIIX4 has dedicated pins to
  107. monitor various external events (e.g., interfaces to a notebook lid,
  108. suspend/resume button, battery low indicators, etc.). PIIX4 contains full
  109. support for the Advanced Configuration and Power Interface (ACPI) Specification.
  110. .IP "System Management Bus (SMBus)"
  111. PIIX4 contains an SMBus Host interface that allows the CPU to communicate with
  112. SMBus slaves and an SMBus Slave interface that allows external masters to
  113. activate power management events.
  114. .IP "Configurability"
  115. PIIX4 provides a wide range of system configuration options. This includes full
  116. 16-bit I/O decode on internal modules, dynamic disable on all the internal
  117. modules, various peripheral decode options, and many options on system
  118. configuration.
  119. .LP
  120. USAGE
  121. This library provides low level routines for PCI - ISA bridge intialization,
  122. and PCI interrupts routing. There are many functions provided here for
  123. enabling different logical devices existing on ISA bus.
  124. The functions addressed here include:
  125. ml
  126. m -
  127. Creating a logical device using an instance of physical device
  128. on PCI bus and initializing internal database accordingly.
  129. m -
  130. Initializing keyboard (logical device number 11) on PIIX4. 
  131. m -
  132. Initializing floppy disk drive (logical device number 5) on PIIX4.
  133. m -
  134. Initializing ATA device (IDE interface) on PIIX4.
  135. m -
  136. Route PIRQ[A:D] from PCI expansion slots on given PIIX4.
  137. m -
  138. Get interrupt level for a given device on PCI expansion slot.
  139. me
  140. USER INTERFACE
  141. .CS
  142. STATUS iPIIX4Init
  143.     (
  144.     )
  145. .CE
  146. The above mentioned routine does locates and initializes the PIIX4.
  147. .CS
  148. STATUS iPIIX4KbdInit
  149.     (
  150.     )
  151. .CE
  152. The above mentioned routine does keyboard specific intialization on PIIX4.
  153. .CS
  154. STATUS iPIIX4FdInit
  155.     (
  156.     )
  157. .CE
  158. The above mentioned routine does floppy disk specific intialization on PIIX4.
  159. .CS
  160. STATUS iPIIX4AtaInit
  161.     (
  162.     )
  163. .CE
  164. The above mentioned routine does ATA device specific intialization on PIIX4.
  165. .CS
  166. STATUS iPIIX4IntrRoute
  167.     (
  168.     int pintx, char irq
  169.     )
  170. .CE
  171. The above mentioned routines routes PIRQ[A:D] to interrupt routing state
  172. machine embedded in PIIX4 and makes them level triggered. This routine
  173. should be called early in boot process.
  174. .CS
  175. int iPIIX4GetIntr
  176.     (
  177.     int pintx
  178.     )
  179. .CE
  180. This above mentioned routine returns the interrupt level of a PCI interrupt
  181. previously set by iPIIX4IntrRoute.
  182. INCLUDE FILES: iPIIX4.h
  183. */
  184. /* includes */
  185. #include <vxWorks.h>
  186. #include <sysLib.h>
  187. #include <string.h>
  188. #include <drv/pci/pciConfigLib.h>
  189. #include <drv/pci/iPIIX4.h>
  190. /* globals */
  191. UINT32 iPIIX4busId = 0;
  192. UINT32 iPIIX4devId = 7;
  193. /* locals */
  194. LOCAL UINT8  iPIIX4xints[4] = {0,0,0,0};
  195.     
  196. /*******************************************************************************
  197. *
  198. * iPIIX4Init - initialize PIIX4
  199. *
  200. * initialize PIIX4
  201. *
  202. * RETURNS: OK or ERROR.
  203. */
  204. STATUS iPIIX4Init
  205.     (
  206.     )
  207.     {
  208.     /* enable upper and lower RTC ram with positive decode bit */
  209.     
  210.     pciConfigOutByte(iPIIX4busId, iPIIX4devId, 0, 0xcb, 0x25);
  211.     return (OK);
  212.     }
  213. /*******************************************************************************
  214. *
  215. * iPIIX4KbdInit - initializes the PCI-ISA/IDE bridge 
  216. *
  217. * This routine will initialize PIIX4 - PCI-ISA/IDE bridge to enable keyboard
  218. * device and IRQ routing
  219. *
  220. * RETURNS: OK or ERROR.
  221. */
  222. STATUS iPIIX4KbdInit
  223.     (
  224.     )
  225.     {
  226.     int longData;
  227.     short int shortData;
  228.     pciConfigInWord (iPIIX4busId, iPIIX4devId,
  229.                      IPIIX4_PCI_FUNC3, IPIIX4_PCI_DEVRESD, &shortData);
  230.     pciConfigOutWord (iPIIX4busId, iPIIX4devId,
  231.                       IPIIX4_PCI_FUNC3, IPIIX4_PCI_DEVRESD,
  232.                       (shortData | IPIIX4_PCI_IRQ1ENDEV11));
  233.     
  234.     pciConfigInLong (iPIIX4busId, iPIIX4devId,
  235.                      IPIIX4_PCI_FUNC3, IPIIX4_PCI_DEVRESA, &longData);
  236.     pciConfigOutLong (iPIIX4busId, iPIIX4devId,
  237.                       IPIIX4_PCI_FUNC3, IPIIX4_PCI_DEVRESA,
  238.                       (longData | IPIIX4_PCI_KBCENDEV11));
  239.     
  240.     pciConfigInLong (iPIIX4busId, iPIIX4devId,
  241.                      IPIIX4_PCI_FUNC3, IPIIX4_PCI_DEVRESB, &longData);
  242.     pciConfigOutLong (iPIIX4busId, iPIIX4devId,
  243.                       IPIIX4_PCI_FUNC3, IPIIX4_PCI_DEVRESB,
  244.                       (longData | IPIIX4_PCI_KBCEIOEN));
  245.     return (OK);
  246.     }
  247. /*******************************************************************************
  248. *
  249. * iPIIX4FdInit - initializes the floppy disk device
  250. *
  251. * This routine will initialize PIIX4 - PCI-ISA/IDE bridge and DMA
  252. * for proper working of floppy disk device
  253. *
  254. * RETURNS: OK or ERROR.
  255. */
  256. STATUS iPIIX4FdInit
  257.     (
  258.     )
  259.     {
  260.     unsigned char data;
  261.     /* DMA controller and Floppy */
  262.     
  263.     sysOutByte (IPIIX4_PCI_FD_DCM,
  264.                 (IPIIX4_PCI_FD_DCM_CASCADE | IPIIX4_PCI_FD_DCM_AUTOINIT));
  265.     
  266.     sysOutByte (IPIIX4_PCI_FD_RWAMB, IPIIX4_PCI_FD_RWAMB_MASKALL);
  267.     
  268.     pciConfigInByte (iPIIX4busId, iPIIX4devId,
  269.                      IPIIX4_PCI_FUNC3, (IPIIX4_PCI_DEVRESD + 1), &data);
  270.     pciConfigOutByte (iPIIX4busId, iPIIX4devId,
  271.                       IPIIX4_PCI_FUNC3, (IPIIX4_PCI_DEVRESD + 1),
  272.                       (data | IPIIX4_PCI_RESENDEV5));
  273.     return (OK);
  274.     }
  275. /*******************************************************************************
  276. *
  277. * iPIIX4AtaInit - low level initialization of ATA device 
  278. *
  279. * This routine will initialize PIIX4 - PCI-ISA/IDE bridge for proper
  280. * working of ATA device.
  281. *
  282. * RETURNS: OK or ERROR.
  283. */
  284. STATUS iPIIX4AtaInit
  285.     (
  286.     )
  287.     {
  288.     pciConfigOutWord (iPIIX4busId, iPIIX4devId,
  289.                       IPIIX4_PCI_FUNC1, IPIIX4_PCI_PCICMD,
  290.                       (IPIIX4_PCI_PCICMD_BME | IPIIX4_PCI_PCICMD_IOSE));
  291.     
  292.     pciConfigOutByte (iPIIX4busId, iPIIX4devId,
  293.                       IPIIX4_PCI_FUNC1, IPIIX4_PCI_MLT, IPIIX4_PCI_MLT_MLTCV);
  294.     
  295.     pciConfigOutLong (iPIIX4busId, iPIIX4devId,
  296.                       IPIIX4_PCI_FUNC1, IPIIX4_PCI_BMIBA, IPIIX4_PCI_BMIBA_RTE);
  297.     
  298.     pciConfigOutLong (iPIIX4busId, iPIIX4devId,
  299.                       IPIIX4_PCI_FUNC1, IPIIX4_PCI_IDETIM, IPIIX4_PCI_IDETIM_VAL);
  300.     return (OK);
  301.     }
  302. /*******************************************************************************
  303. *
  304. * iPIIX4IntrRoute - Route PIRQ[A:D]
  305. *
  306. * This routine will connect an irq to a pci interrupt.
  307. *
  308. * RETURNS: OK or ERROR.
  309. */
  310. STATUS iPIIX4IntrRoute
  311.     (
  312.     int pintx,
  313.     char irq
  314.     )
  315.     {
  316.     unsigned char elreg = 0;
  317.     unsigned char oldbits;
  318.     unsigned char newbit;
  319.     if(pintx > IPIIX4_PCI_XINT_MAX)
  320.         return(ERROR);
  321.     if((irq > 2) && (irq < 8))
  322.         {
  323.         elreg = (unsigned char)IPIIX4_PCI_ELCR1;
  324.         newbit = 1 << irq;
  325.         }
  326.     else 
  327.         if((irq < 9) || (irq == 13) || (irq > 15))
  328.             return(ERROR);
  329.         else
  330.             {
  331.             elreg = (unsigned char)IPIIX4_PCI_ELCR2;
  332.             newbit = 1 << (irq - 8);
  333.             }
  334.     /* route PIRQ signal to IRQ# input of PIC */
  335.     
  336.     pciConfigOutByte (iPIIX4busId,
  337.                       iPIIX4devId,
  338.                       IPIIX4_PCI_FUNC0, IPIIX4_PCI_PIRQRCA + pintx, irq);
  339.         
  340.     /* keep track of the irq */
  341.     
  342.     iPIIX4xints[pintx] = irq;
  343.     /* make IRQs level triggered */
  344.     
  345.     oldbits = sysInByte(elreg);
  346.     sysOutByte (elreg, (oldbits | newbit));
  347.     return (OK);
  348.     }
  349. /*******************************************************************************
  350. *
  351. * iPIIX4GetIntr - give device an interrupt level to use
  352. *
  353. * This routine will give device an interrupt level to use based on
  354. * PCI INT A through D, valid values for pintx are 0, 1, 2 and 3.
  355. * An autoroute in disguise.
  356. *
  357. * RETURNS: char - interrupt level 
  358. */
  359. char iPIIX4GetIntr
  360.     (
  361.     int pintx
  362.     )
  363.     {
  364.     if (pintx > IPIIX4_PCI_XINT_MAX)
  365.         return (IPIIX4_PCI_NOINT);
  366.     else
  367.         return(iPIIX4xints[pintx]);
  368.     }