Leaked source code of windows server 2003
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.

202 lines
5.3 KiB

  1. /*++
  2. Copyright (c) 1999, 2000 Microsoft Corporation
  3. Module Name:
  4. hydramp.c
  5. Abstract:
  6. USB 2.0 UHCI driver
  7. Environment:
  8. kernel mode only
  9. Notes:
  10. THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  11. KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  12. IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  13. PURPOSE.
  14. Copyright (c) 1999, 2000 Microsoft Corporation. All Rights Reserved.
  15. Revision History:
  16. 8-12-2000 : created, jsenior
  17. --*/
  18. #include "pch.h"
  19. //implements the following miniport functions:
  20. //UhciStopBIOS
  21. //UhciStartBIOS
  22. USB_MINIPORT_STATUS
  23. UhciStopBIOS(
  24. IN PDEVICE_DATA DeviceData,
  25. IN PHC_RESOURCES HcResources
  26. )
  27. /*++
  28. Routine Description:
  29. This routine steals the USB controller from the BIOS,
  30. making sure that it saves all the registers for later.
  31. Arguments:
  32. DeviceData - DeviceData for this USB controller.
  33. HcResources - The resources from the pnp start device.
  34. Return Value:
  35. NT status code.
  36. --*/
  37. {
  38. USBCMD cmd;
  39. USBSTS status;
  40. PHC_REGISTER reg;
  41. USBSETUP legsup;
  42. USB_MINIPORT_STATUS mpStatus = USBMP_STATUS_SUCCESS;
  43. LARGE_INTEGER startTime;
  44. ULONG sofModifyValue = 0;
  45. LARGE_INTEGER finishTime;
  46. UhciKdPrint((DeviceData, 2, "'Stop Bios.\n"));
  47. UHCI_ASSERT(DeviceData, HcResources->CommonBufferVa != NULL);
  48. // validate our resources
  49. if ((HcResources->Flags & (HCR_IO_REGS | HCR_IRQ)) !=
  50. (HCR_IO_REGS | HCR_IRQ)) {
  51. mpStatus = USBMP_STATUS_INIT_FAILURE;
  52. }
  53. // set up or device data structure
  54. reg = DeviceData->Registers =
  55. (PHC_REGISTER) (HcResources->DeviceRegisters);
  56. UhciKdPrint((DeviceData, 2, "'UHCI mapped Operational Regs = %x\n", reg));
  57. // Disable PIRQD, NOTE: the Hal should have disabled it for us
  58. //
  59. // Disable the PIRQD
  60. //
  61. USBPORT_READ_CONFIG_SPACE(
  62. DeviceData,
  63. &legsup,
  64. LEGACY_BIOS_REGISTER, // offset of legacy bios reg
  65. sizeof(legsup));
  66. #if DBG
  67. if (legsup & LEGSUP_USBPIRQD_EN) {
  68. UhciKdPrint((DeviceData, 2, "'PIRQD enabled on StartController (%x)\n",
  69. legsup));
  70. }
  71. #endif
  72. UhciDisableInterrupts(DeviceData);
  73. // UhciGetRegistryParameters(DeviceData);
  74. //
  75. // Get the SOF modify value. First, retrieve from
  76. // hardware, then see if we have something in the
  77. // registry to set it to, then save it away.
  78. //
  79. /* sofModifyValue = READ_PORT_UCHAR(&reg->StartOfFrameModify.uc);
  80. // Grab any SOF ModifyValue indicated in the registry
  81. // bugbug - todo
  82. // UHCD_GetSOFRegModifyValue(DeviceObject,
  83. // &sofModifyValue);
  84. // save the SOF modify for posterity
  85. DeviceData->BiosStartOfFrameModify.uc = (CHAR) sofModifyValue;
  86. UHCI_ASSERT(DeviceData, sofModifyValue <= 255);
  87. */
  88. // IF the host controller is in the global reset state,
  89. // clear the bit prior to trying to stop the controller.
  90. // stop the controller,
  91. // clear RUN bit and config flag so BIOS won't reinit
  92. cmd.us = READ_PORT_USHORT(&reg->UsbCommand.us);
  93. cmd.GlobalReset = 0;
  94. cmd.RunStop = 0;
  95. cmd.ConfigureFlag = 0;
  96. WRITE_PORT_USHORT(&DeviceData->Registers->UsbCommand.us, cmd.us);
  97. // NOTE: if no BIOS is present
  98. // halt bit is initially set with PIIX3
  99. // halt bit is initially clear with VIA
  100. // now wait for HC to halt
  101. // Spec'ed to take 10 ms, so that's what we'll wait for
  102. KeQuerySystemTime(&finishTime); // get current time
  103. finishTime.QuadPart += 1000000;
  104. KeQuerySystemTime(&startTime);
  105. status.us = READ_PORT_USHORT(&reg->UsbStatus.us);
  106. while (!status.HCHalted) {
  107. LARGE_INTEGER sysTime;
  108. status.us = READ_PORT_USHORT(&reg->UsbStatus.us);
  109. UhciKdPrint((DeviceData, 2, "'STATUS = %x\n", status.us));
  110. KeQuerySystemTime(&sysTime);
  111. if (sysTime.QuadPart >= finishTime.QuadPart) {
  112. // time out
  113. UhciKdPrint((DeviceData, 0,
  114. "'TIMEOUT HALTING CONTROLLER! (contact jsenior)\n"));
  115. TEST_TRAP();
  116. break;
  117. }
  118. }
  119. WRITE_PORT_USHORT(&reg->UsbStatus.us, 0xff);
  120. // If a legacy bios, disable it. note that PIRQD is disabled
  121. if ((legsup & LEGSUP_BIOS_MODE) != 0) {
  122. UhciKdPrint((DeviceData, 0, "'*** uhci detected a USB legacy BIOS ***\n"));
  123. HcResources->DetectedLegacyBIOS = TRUE;
  124. //
  125. // if BIOS mode bits set we have to take over
  126. //
  127. USBPORT_READ_CONFIG_SPACE(
  128. DeviceData,
  129. &legsup,
  130. LEGACY_BIOS_REGISTER, // offset of legacy bios reg
  131. sizeof(legsup));
  132. // shut off host controller SMI enable
  133. legsup = 0x0000;
  134. USBPORT_WRITE_CONFIG_SPACE(
  135. DeviceData,
  136. &legsup,
  137. LEGACY_BIOS_REGISTER, // offset of legacy bios reg
  138. sizeof(legsup));
  139. }
  140. UhciKdPrint((DeviceData, 2, "'Legacy support reg = 0x%x\n", legsup));
  141. UhciKdPrint((DeviceData, 2, "'exit UhciStopBIOS 0x%x\n", mpStatus));
  142. return mpStatus;
  143. }