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.

299 lines
5.7 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Copyright (c) 1994 MOTOROLA, INC. All Rights Reserved. This file
  4. contains copyrighted material. Use of this file is restricted
  5. by the provisions of a Motorola Software License Agreement.
  6. Copyright (c) 1995-96 International Business Machines Corporation
  7. Module Name:
  8. pxmemctl.c
  9. Abstract:
  10. The module initializes any planar registers.
  11. This module also implements machince check parity error handling.
  12. Author:
  13. Jim Wooldridge (jimw@austin.vnet.ibm.com)
  14. Revision History:
  15. --*/
  16. #include "halp.h"
  17. #include "pci.h"
  18. #include "pcip.h"
  19. extern PVOID HalpPciConfigBase;
  20. #define PCI_INTERRUPT_ROUTING_OTHER 15 //IBMCPK: should we really have seperate scsi int??
  21. #define PCI_INTERRUPT_ROUTING_SCSI PCI_INTERRUPT_ROUTING_OTHER
  22. #ifdef ALLOC_PRAGMA
  23. #pragma alloc_text(PAGE,HalpGetPCIIrq)
  24. #endif
  25. ULONG HalpPciMaxSlots = PCI_MAX_DEVICES;
  26. ULONG
  27. HalpTranslatePciSlotNumber (
  28. ULONG BusNumber,
  29. ULONG SlotNumber
  30. )
  31. /*++
  32. Routine Description:
  33. This routine translate a PCI slot number to a PCI device number.
  34. This is a sandalfoot memory map implementation.
  35. Arguments:
  36. None.
  37. Return Value:
  38. Returns length of data written.
  39. --*/
  40. {
  41. //
  42. // Sandalfoot only has 1 PCI bus so bus number is unused
  43. //
  44. PCI_TYPE1_CFG_BITS PciConfig;
  45. PCI_SLOT_NUMBER PciSlotNumber;
  46. PciSlotNumber.u.AsULONG = SlotNumber;
  47. PciConfig.u.AsULONG = 0;
  48. PciConfig.u.bits.DeviceNumber = PciSlotNumber.u.bits.DeviceNumber;
  49. PciConfig.u.bits.FunctionNumber = PciSlotNumber.u.bits.FunctionNumber;
  50. PciConfig.u.bits.BusNumber = BusNumber;
  51. PciConfig.u.bits.Enable = TRUE;
  52. return (PciConfig.u.AsULONG);
  53. }
  54. ULONG
  55. HalpPhase0SetPciDataByOffset (
  56. ULONG BusNumber,
  57. ULONG SlotNumber,
  58. PUCHAR Buffer,
  59. ULONG Offset,
  60. ULONG Length
  61. )
  62. /*++
  63. Routine Description:
  64. This routine writes to PCI configuration space prior to bus handler installation.
  65. Arguments:
  66. None.
  67. Return Value:
  68. Returns length of data written.
  69. --*/
  70. {
  71. ULONG to;
  72. PUCHAR from;
  73. ULONG tmpLength;
  74. ULONG i;
  75. if (SlotNumber < HalpPciMaxSlots) {
  76. to = (ULONG) HalpPciConfigBase + (SlotNumber << 11);
  77. to += Offset;
  78. from = Buffer;
  79. tmpLength = Length;
  80. while (tmpLength > 0) {
  81. WRITE_PORT_ULONG ((PUCHAR)HalpIoControlBase + 0xCF8, to );
  82. i = to % sizeof(ULONG);
  83. WRITE_PORT_UCHAR ((PUCHAR)HalpIoControlBase + 0xCFC + i,*from);
  84. to++;
  85. from++;
  86. tmpLength--;
  87. }
  88. return(Length);
  89. }
  90. else {
  91. return (0);
  92. }
  93. }
  94. ULONG
  95. HalpPhase0GetPciDataByOffset (
  96. ULONG BusNumber,
  97. ULONG SlotNumber,
  98. PUCHAR Buffer,
  99. ULONG Offset,
  100. ULONG Length
  101. )
  102. /*++
  103. Routine Description:
  104. This routine reads PCI config space prior to bus handlder installation.
  105. Arguments:
  106. None.
  107. Return Value:
  108. Amount of data read.
  109. --*/
  110. {
  111. PUCHAR to;
  112. ULONG from;
  113. ULONG tmpLength;
  114. ULONG i;
  115. if (SlotNumber < HalpPciMaxSlots) {
  116. from = (ULONG) HalpPciConfigBase + (SlotNumber << 11);
  117. from += Offset;
  118. to = Buffer;
  119. tmpLength = Length;
  120. while (tmpLength > 0) {
  121. WRITE_PORT_ULONG ((PUCHAR)HalpIoControlBase + 0xCF8, from);
  122. i = from % sizeof(ULONG);
  123. *((PUCHAR) to) = READ_PORT_UCHAR ((PUCHAR)HalpIoControlBase + 0xCFC + i);
  124. to++;
  125. from++;
  126. tmpLength--;
  127. }
  128. return(Length);
  129. }
  130. else {
  131. return (0);
  132. }
  133. }
  134. NTSTATUS
  135. HalpGetPCIIrq (
  136. IN PBUS_HANDLER BusHandler,
  137. IN PBUS_HANDLER RootHandler,
  138. IN PCI_SLOT_NUMBER PciSlot,
  139. OUT PSUPPORTED_RANGE *Interrupt
  140. )
  141. {
  142. ULONG buffer[PCI_COMMON_HDR_LENGTH/sizeof(ULONG)];
  143. PPCI_COMMON_CONFIG PciData;
  144. #define PCI_VENDOR_NCR 0x1000
  145. PciData = (PPCI_COMMON_CONFIG) buffer;
  146. HalGetBusData (
  147. PCIConfiguration,
  148. BusHandler->BusNumber,
  149. PciSlot.u.AsULONG,
  150. PciData,
  151. PCI_COMMON_HDR_LENGTH
  152. );
  153. if (PciData->VendorID == PCI_INVALID_VENDORID ||
  154. PCI_CONFIG_TYPE (PciData) != 0) {
  155. return STATUS_UNSUCCESSFUL;
  156. }
  157. *Interrupt = ExAllocatePool (PagedPool, sizeof (SUPPORTED_RANGE));
  158. if (!*Interrupt) {
  159. return STATUS_INSUFFICIENT_RESOURCES;
  160. }
  161. RtlZeroMemory (*Interrupt, sizeof (SUPPORTED_RANGE));
  162. if (PciSlot.u.bits.DeviceNumber == 2) {
  163. (*Interrupt)->Base = PCI_INTERRUPT_ROUTING_SCSI;
  164. (*Interrupt)->Limit = PCI_INTERRUPT_ROUTING_SCSI;
  165. } else {
  166. (*Interrupt)->Base = PCI_INTERRUPT_ROUTING_OTHER;
  167. (*Interrupt)->Limit = PCI_INTERRUPT_ROUTING_OTHER;
  168. }
  169. #if defined(SOFT_HDD_LAMP)
  170. if ( (PciData->BaseClass == 1) ||
  171. ( (PciData->VendorID == PCI_VENDOR_NCR) && (PciData->DeviceID == 1) ) ) {
  172. //
  173. // This device is a Mass Storage Controller, set flag to
  174. // turn on the HDD Lamp when interrupts come in on this
  175. // vector.
  176. //
  177. // N.B. We recognize NCR 810 controllers as they were implemented
  178. // before class codes.
  179. //
  180. extern ULONG HalpMassStorageControllerVectors;
  181. HalpMassStorageControllerVectors |= 1 << (*Interrupt)->Base;
  182. }
  183. #endif
  184. return STATUS_SUCCESS;
  185. }
  186. VOID
  187. HalpMapPlugInPciBridges(
  188. UCHAR NoBuses
  189. )
  190. /*++
  191. Routine Description:
  192. Looks for any unexpected (plug-in) PCI-PCI bridges so
  193. that interrupts can be mapped from these buses back
  194. into the interrupt controller.
  195. Arguments:
  196. NoBuses -- This is the number of buses that HalpGetPciBridgeConfig found
  197. Return Value:
  198. none
  199. --*/
  200. {
  201. // Carolina supports some plug-in PCI busses, but this
  202. // HAL doesn't need to build the map because all Carolina PCI
  203. // interrupts are routed to the same IRQ. Hence the
  204. // map reduces to nothing.
  205. return;
  206. }