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.

117 lines
2.7 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. ixmcabus.c
  5. Abstract:
  6. Author:
  7. Environment:
  8. Revision History:
  9. --*/
  10. #include "halp.h"
  11. extern KSPIN_LOCK HalpSystemHardwareLock;
  12. ULONG
  13. HalpGetPosData (
  14. IN PBUS_HANDLER BusHandler,
  15. IN PBUS_HANDLER RootHandler,
  16. IN ULONG SlotNumber,
  17. IN PVOID Buffer,
  18. IN ULONG DOffset,
  19. IN ULONG Length
  20. )
  21. {
  22. ULONG DataLength = 0;
  23. ULONG Offset = 0;
  24. ULONG Index = 0;
  25. PUCHAR DataBuffer = Buffer;
  26. PVOID McaRegisterBase = 0;
  27. PUCHAR PosBase;
  28. KIRQL Irql;
  29. PHYSICAL_ADDRESS BusAddress;
  30. BOOLEAN Status;
  31. ULONG AddressSpace;
  32. if (DOffset != 0) {
  33. // bugbug: should support this
  34. return 0;
  35. }
  36. //
  37. // Translate the Mca Base port for this MCA bus
  38. //
  39. BusAddress.LowPart = (ULONG) McaRegisterBase;
  40. BusAddress.HighPart = 0;
  41. AddressSpace = 1; // I/O space
  42. Status = BusHandler->TranslateBusAddress(
  43. BusHandler,
  44. RootHandler,
  45. BusAddress,
  46. &AddressSpace, // I/O Space
  47. &BusAddress);
  48. if (Status == FALSE || AddressSpace != 1) {
  49. return 0;
  50. }
  51. McaRegisterBase = (PVOID) BusAddress.LowPart;
  52. PosBase = (PUCHAR) &((PMCA_CONTROL) McaRegisterBase)->Pos;
  53. Irql = KfAcquireSpinLock(&HalpSystemHardwareLock);
  54. //
  55. // Place the specified adapter into setup mode.
  56. //
  57. WRITE_PORT_UCHAR((PVOID) &((PMCA_CONTROL) McaRegisterBase)->AdapterSetup,
  58. (UCHAR) ( MCA_ADAPTER_SETUP_ON | SlotNumber ));
  59. while (DataLength < Length && DataLength < 6) {
  60. DataBuffer[DataLength] = READ_PORT_UCHAR( PosBase + DataLength );
  61. DataLength++;
  62. }
  63. while (DataLength < Length) {
  64. WRITE_PORT_UCHAR((PVOID) &((PPROGRAMMABLE_OPTION_SELECT)
  65. PosBase)->SubaddressExtensionLsb, (UCHAR) Index);
  66. WRITE_PORT_UCHAR((PVOID) &((PPROGRAMMABLE_OPTION_SELECT)
  67. PosBase)->SubaddressExtensionMsb, (UCHAR) (Index >> 8));
  68. DataBuffer[Index + 6] = READ_PORT_UCHAR(
  69. (PVOID) &((PPROGRAMMABLE_OPTION_SELECT)PosBase)->OptionSelectData2);
  70. DataLength++;
  71. if (DataLength < Length) {
  72. Offset = DataLength + ((Length - DataLength) / 2);
  73. DataBuffer[Offset] = READ_PORT_UCHAR(
  74. (PVOID) &((PPROGRAMMABLE_OPTION_SELECT)PosBase)->OptionSelectData3);
  75. DataLength++;
  76. Index++;
  77. }
  78. }
  79. //
  80. // Disable adapter setup.
  81. //
  82. WRITE_PORT_UCHAR((PVOID) &((PMCA_CONTROL) McaRegisterBase)->AdapterSetup,
  83. (UCHAR) ( MCA_ADAPTER_SETUP_OFF ));
  84. KfReleaseSpinLock( &HalpSystemHardwareLock, Irql );
  85. return DataLength;
  86. }