Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

569 lines
11 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Copyright (c) 1992, 1993 Digital Equipment Corporation
  4. Module Name:
  5. ebintsup.c
  6. Abstract:
  7. The module provides the interrupt support for EB64+ systems.
  8. Author:
  9. Eric Rehm (DEC) 29-December-1993
  10. Revision History:
  11. --*/
  12. #include "halp.h"
  13. #include "eisa.h"
  14. #include "ebsgdma.h"
  15. #include "eb64pdef.h"
  16. #include "pcrtc.h"
  17. #include "pintolin.h"
  18. //
  19. // Global to control interrupt handling for EB64+
  20. //
  21. UCHAR IntMask0, IntMask1, IntMask2;
  22. VOID
  23. HalpInitializePciInterrupts (
  24. VOID
  25. );
  26. //
  27. // Define the context structure for use by interrupt service routines.
  28. //
  29. typedef BOOLEAN (*PSECOND_LEVEL_DISPATCH)(
  30. PKINTERRUPT InterruptObject
  31. );
  32. //
  33. // Declare the interupt handler for the PCI and ISA bus.
  34. //
  35. BOOLEAN
  36. HalpPCIDispatch(
  37. IN PKINTERRUPT Interrupt,
  38. IN PVOID ServiceContext,
  39. IN PKTRAP_FRAME TrapFrame
  40. );
  41. //
  42. // The following is the interrupt object used for DMA controller interrupts.
  43. // DMA controller interrupts occur when a memory parity error occurs or a
  44. // programming error occurs to the DMA controller.
  45. //
  46. KINTERRUPT HalpEisaNmiInterrupt;
  47. //
  48. // The following function initializes NMI handling.
  49. //
  50. VOID
  51. HalpInitializeNMI(
  52. VOID
  53. );
  54. //
  55. // The following function is called when an ISA NMI occurs.
  56. //
  57. BOOLEAN
  58. HalHandleNMI(
  59. IN PKINTERRUPT Interrupt,
  60. IN PVOID ServiceContext
  61. );
  62. VOID
  63. HalpDisableSioInterrupt(
  64. IN ULONG Vector
  65. );
  66. VOID
  67. HalpEnableSioInterrupt(
  68. IN ULONG Vector,
  69. IN KINTERRUPT_MODE InterruptMode
  70. );
  71. BOOLEAN
  72. HalpInitializePCIInterrupts (
  73. VOID
  74. )
  75. /*++
  76. Routine Description:
  77. This routine initializes the structures necessary for EISA & PCI operations
  78. and connects the intermediate interrupt dispatcher. It also initializes the
  79. ISA interrupt controller.
  80. Arguments:
  81. None.
  82. Return Value:
  83. If the second level interrupt dispatcher is connected, then a value of
  84. TRUE is returned. Otherwise, a value of FALSE is returned.
  85. --*/
  86. {
  87. KIRQL oldIrql;
  88. //
  89. // Initialize the EISA NMI interrupt.
  90. //
  91. HalpInitializeNMI();
  92. //
  93. // Directly connect the ISA interrupt dispatcher to the level for
  94. // ISA bus interrupt.
  95. //
  96. // N.B. This vector is reserved for exclusive use by the HAL (see
  97. // interrupt initialization.
  98. //
  99. PCR->InterruptRoutine[PIC_VECTOR] = (PVOID)HalpPCIDispatch;
  100. HalEnableSystemInterrupt(PIC_VECTOR, DEVICE_LEVEL, LevelSensitive);
  101. if (SystemIsAlphaPC64)
  102. (PVOID) HalpPCIPinToLineTable = (PVOID) AlphaPC64PCIPinToLineTable;
  103. else
  104. (PVOID) HalpPCIPinToLineTable = (PVOID) EB64PPCIPinToLineTable;
  105. //
  106. // Intitialize interrupt controller
  107. //
  108. KeRaiseIrql(ISA_DEVICE_LEVEL, &oldIrql);
  109. //
  110. // Initialize the PCI interrupts.
  111. //
  112. HalpInitializePciInterrupts();
  113. //
  114. // Initialize the SIO Interrupt Controller
  115. //
  116. HalpInitializeSioInterrupts();
  117. //
  118. // Restore IRQL level.
  119. //
  120. KeLowerIrql(oldIrql);
  121. //
  122. // Initialize the DMA mode registers to a default value.
  123. // Disable all of the DMA channels except channel 4 which is the
  124. // cascade of channels 0-3.
  125. //
  126. WRITE_PORT_UCHAR(
  127. &((PEISA_CONTROL) HalpEisaControlBase)->Dma1BasePort.AllMask,
  128. 0x0F
  129. );
  130. WRITE_PORT_UCHAR(
  131. &((PEISA_CONTROL) HalpEisaControlBase)->Dma2BasePort.AllMask,
  132. 0x0E
  133. );
  134. return(TRUE);
  135. }
  136. BOOLEAN
  137. HalpPCIDispatch(
  138. IN PKINTERRUPT Interrupt,
  139. IN PVOID ServiceContext,
  140. IN PKTRAP_FRAME TrapFrame
  141. )
  142. /*++
  143. Routine Description:
  144. This routine is entered as the result of an interrupt being generated
  145. via the vector that is connected to an interrupt object that describes
  146. the PCI and ISA device interrupts. Its function is to call the second
  147. level interrupt dispatch routine and acknowledge the interrupt at the ISA
  148. controller.
  149. This service routine should be connected as follows:
  150. KeInitializeInterrupt(&Interrupt, HalpPCIDispatch,
  151. EISA_VIRTUAL_BASE,
  152. (PKSPIN_LOCK)NULL, PCI_LEVEL, PCI_LEVEL, PCI_LEVEL,
  153. LevelSensitive, TRUE, 0, FALSE);
  154. KeConnectInterrupt(&Interrupt);
  155. Arguments:
  156. Interrupt - Supplies a pointer to the interrupt object.
  157. ServiceContext - Supplies a pointer to the ISA interrupt acknowledge
  158. register.
  159. TrapFrame - Supplies a pointer to the trap frame for this interrupt.
  160. Return Value:
  161. Returns the value returned from the second level routine.
  162. --*/
  163. {
  164. UCHAR PciVector, IntNumber;
  165. ULONG PCRInOffset = 0xffff;
  166. KPCR *pcr;
  167. //
  168. // Read in the 1st interrupt register.
  169. //
  170. PciVector = READ_PORT_UCHAR(INTERRUPT_MASK0_QVA) & IntMask0;
  171. //
  172. // Was it an ISA (SIO) interrupt?
  173. //
  174. if (PciVector & SIO_INTERRUPT_MASK) {
  175. //
  176. // ISA interrupt - call HalpSioDispatch().
  177. //
  178. return HalpSioDispatch();
  179. }
  180. //
  181. // Which PCI interrupt was it?
  182. //
  183. if (PciVector) {
  184. for(IntNumber = 0; IntNumber < 8; IntNumber++) {
  185. if (PciVector & 1) {
  186. PCRInOffset = IntNumber;
  187. break;
  188. }
  189. PciVector >>= 1;
  190. }
  191. } else {
  192. PciVector = READ_PORT_UCHAR(INTERRUPT_MASK1_QVA) & IntMask1;
  193. if (PciVector) {
  194. for(IntNumber = 0; IntNumber < 8; IntNumber++) {
  195. if (PciVector & 1) {
  196. PCRInOffset = IntNumber + 8;
  197. break;
  198. }
  199. PciVector >>= 1;
  200. }
  201. } else if (INTERRUPT_MASK2_QVA != NULL) {
  202. PciVector = READ_PORT_UCHAR(INTERRUPT_MASK2_QVA) & IntMask2;
  203. if (PciVector)
  204. PCRInOffset = 0x10;
  205. }
  206. }
  207. if (PCRInOffset == 0xffff) {
  208. return FALSE;
  209. }
  210. PCRInOffset += PCI_VECTORS;
  211. PCRInOffset++;
  212. return ((PSECONDARY_DISPATCH)PCR->InterruptRoutine[PCRInOffset])(
  213. PCR->InterruptRoutine[PCRInOffset], TrapFrame);
  214. }
  215. VOID
  216. HalpDisablePCIInterrupt(
  217. IN ULONG Vector
  218. )
  219. /*++
  220. Routine Description:
  221. This function Disables the PCI bus specified PCI bus interrupt.
  222. Arguments:
  223. Vector - Supplies the vector of the PCI interrupt that is Disabled.
  224. Return Value:
  225. None.
  226. --*/
  227. {
  228. //
  229. // Calculate the PCI interrupt vector.
  230. //
  231. Vector -= PCI_VECTORS;
  232. Vector--;
  233. //
  234. // Clear the corresponding bit in the appropriate interrupt mask
  235. // shadow and write it out to the interrupt mask.
  236. //
  237. if (Vector >= 0 && Vector <= 7) {
  238. IntMask0 &= (UCHAR) ~(1 << Vector);
  239. WRITE_PORT_UCHAR(INTERRUPT_MASK0_QVA, ~IntMask0);
  240. } else if (Vector >= 8 && Vector <= 0xf) {
  241. IntMask1 &= (UCHAR) ~(1 << (Vector - 8));
  242. WRITE_PORT_UCHAR(INTERRUPT_MASK1_QVA, ~IntMask1);
  243. } else if ((Vector == 0x10) && (INTERRUPT_MASK2_QVA != NULL)) {
  244. IntMask2 = 0;
  245. WRITE_PORT_UCHAR(INTERRUPT_MASK2_QVA, ~IntMask2);
  246. } else {
  247. #ifdef HALDBG
  248. DbgPrint("HalpDisablePCIInterrupt: bad vector\n");
  249. #endif // HALDBG
  250. }
  251. }
  252. VOID
  253. HalpEnablePCIInterrupt(
  254. IN ULONG Vector
  255. )
  256. /*++
  257. Routine Description:
  258. This function enables the PCI bus specified PCI bus interrupt.
  259. PCI interrupts must be LevelSensitve. (PCI Spec. 2.2.6)
  260. Arguments:
  261. Vector - Supplies the vector of the ESIA interrupt that is enabled.
  262. InterruptMode - Supplies the mode of the interrupt; LevelSensitive or
  263. Latched.
  264. Return Value:
  265. None.
  266. --*/
  267. {
  268. //
  269. // Calculate the PCI interrupt vector.
  270. //
  271. Vector -= PCI_VECTORS;
  272. Vector--;
  273. //
  274. // Set the corresponding bit in the appropriate interrupt mask
  275. // shadow and write it out to the interrupt mask.
  276. //
  277. if (Vector >= 0 && Vector <= 7) {
  278. IntMask0 |= (UCHAR) (1 << Vector);
  279. WRITE_PORT_UCHAR(INTERRUPT_MASK0_QVA, ~IntMask0);
  280. } else if (Vector >= 8 && Vector <= 0xf) {
  281. IntMask1 |= (UCHAR) (1 << (Vector - 8));
  282. WRITE_PORT_UCHAR(INTERRUPT_MASK1_QVA, ~IntMask1);
  283. } else if ((Vector == 0x10) && (INTERRUPT_MASK2_QVA != NULL)) {
  284. IntMask2 = 1;
  285. WRITE_PORT_UCHAR(INTERRUPT_MASK2_QVA, ~IntMask2);
  286. } else {
  287. #ifdef HALDBG
  288. DbgPrint("HalpEnablePCIInterrupt: bad vector\n");
  289. #endif // HALDBG
  290. }
  291. }
  292. VOID
  293. HalpInitializeNMI(
  294. VOID
  295. )
  296. /*++
  297. Routine Description:
  298. This function is called to intialize SIO NMI interrupts.
  299. Arguments:
  300. None.
  301. Return Value:
  302. None.
  303. --*/
  304. {
  305. UCHAR DataByte;
  306. //
  307. // Initialize the SIO NMI interrupt.
  308. //
  309. KeInitializeInterrupt( &HalpEisaNmiInterrupt,
  310. HalHandleNMI,
  311. NULL,
  312. NULL,
  313. EISA_NMI_VECTOR,
  314. EISA_NMI_LEVEL,
  315. EISA_NMI_LEVEL,
  316. LevelSensitive,
  317. FALSE,
  318. 0,
  319. FALSE
  320. );
  321. //
  322. // Don't fail if the interrupt cannot be connected.
  323. //
  324. KeConnectInterrupt( &HalpEisaNmiInterrupt );
  325. //
  326. // Clear the Eisa NMI disable bit. This bit is the high order of the
  327. // NMI enable register.
  328. //
  329. DataByte = 0;
  330. WRITE_PORT_UCHAR(
  331. &((PEISA_CONTROL) HalpEisaControlBase)->NmiEnable,
  332. DataByte
  333. );
  334. }
  335. BOOLEAN
  336. HalHandleNMI(
  337. IN PKINTERRUPT Interrupt,
  338. IN PVOID ServiceContext
  339. )
  340. /*++
  341. Routine Description:
  342. This function is called when an EISA NMI occurs. It print the appropriate
  343. status information and bugchecks.
  344. Arguments:
  345. Interrupt - Supplies a pointer to the interrupt object
  346. ServiceContext - Bug number to call bugcheck with.
  347. Return Value:
  348. Returns TRUE.
  349. --*/
  350. {
  351. UCHAR StatusByte;
  352. StatusByte =
  353. READ_PORT_UCHAR(&((PEISA_CONTROL) HalpEisaControlBase)->NmiStatus);
  354. if (StatusByte & 0x80) {
  355. HalDisplayString ("NMI: Parity Check / Parity Error\n");
  356. }
  357. if (StatusByte & 0x40) {
  358. HalDisplayString ("NMI: Channel Check / IOCHK\n");
  359. }
  360. //
  361. // This is an Sio machine, no extnded nmi information, so just do it.
  362. //
  363. KeBugCheck(NMI_HARDWARE_FAILURE);
  364. return(TRUE);
  365. }
  366. VOID
  367. HalpAcknowledgeClockInterrupt(
  368. VOID
  369. )
  370. /*++
  371. Routine Description:
  372. Acknowledge the clock interrupt from the interval timer. The interval
  373. timer for EB66 comes from the Dallas real-time clock.
  374. Arguments:
  375. None.
  376. Return Value:
  377. None.
  378. --*/
  379. {
  380. //
  381. // Acknowledge the clock interrupt by reading the control register C of
  382. // the Real Time Clock.
  383. //
  384. HalpReadClockRegister( RTC_CONTROL_REGISTERC );
  385. return;
  386. }
  387. VOID
  388. HalpInitializePciInterrupts (
  389. VOID
  390. )
  391. /*++
  392. Routine Description:
  393. This routine initializes the PCI device interrupt mask.
  394. Arguments:
  395. None.
  396. Return Value:
  397. None.
  398. --*/
  399. {
  400. //
  401. // Initialize the shadow copies of the interrupt masks to enable only
  402. // the SIO interrupt.
  403. //
  404. IntMask0 = (UCHAR)SIO_INTERRUPT_MASK;
  405. IntMask1 = 0;
  406. IntMask2 = 0;
  407. //
  408. // Write the masks.
  409. //
  410. WRITE_PORT_UCHAR(INTERRUPT_MASK0_QVA, ~IntMask0);
  411. WRITE_PORT_UCHAR(INTERRUPT_MASK1_QVA, ~IntMask1);
  412. if (INTERRUPT_MASK2_QVA != NULL) {
  413. WRITE_PORT_UCHAR(INTERRUPT_MASK2_QVA, ~IntMask2);
  414. }
  415. }