Source code of Windows XP (NT5)
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.

188 lines
5.5 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: par12843.c
  8. //
  9. //--------------------------------------------------------------------------
  10. //
  11. // This file contains functions to select and deselect 1284.3 daisy chain devices
  12. //
  13. #include "pch.h"
  14. BOOLEAN
  15. ParSelectDevice(
  16. IN PDEVICE_EXTENSION Extension,
  17. IN BOOLEAN HavePort
  18. )
  19. /*++
  20. Routine Description:
  21. This routine acquires the ParPort and selects a 1284.3 device
  22. Arguments:
  23. Extension - Supplies the device extension.
  24. HavePort - TRUE indicates that caller has already acquired port
  25. so we should only do a SELECT_DEVICE
  26. - FALSE indicates that caller has not already acquired port
  27. so we should do a combination ACQUIRE_PORT/SELECT_DEVICE
  28. Return Value:
  29. TRUE - success - the device was selected (and port acquired if needed)
  30. FALSE - failure
  31. --*/
  32. {
  33. NTSTATUS status;
  34. PDEVICE_OBJECT pPortDeviceObject;
  35. PARALLEL_1284_COMMAND par1284Command;
  36. LARGE_INTEGER timeOut;
  37. // ParDumpP( ("par12843::ParSelectDevice - Enter\n") );
  38. //
  39. // Initialize command structure and extract parameters from the DeviceExtension
  40. //
  41. par1284Command.ID = (UCHAR)Extension->Ieee1284_3DeviceId;
  42. par1284Command.Port = 0; // reserved - 0 for now
  43. if( HavePort ) {
  44. par1284Command.CommandFlags = PAR_HAVE_PORT_KEEP_PORT;
  45. } else {
  46. par1284Command.CommandFlags = 0;
  47. }
  48. if(Extension->EndOfChain) {
  49. // this is NOT a daisy chain device - flag ParPort that
  50. // the ID field of the command should be ignored
  51. par1284Command.CommandFlags |= PAR_END_OF_CHAIN_DEVICE;
  52. }
  53. pPortDeviceObject = Extension->PortDeviceObject;
  54. //
  55. // Send the request
  56. //
  57. timeOut.QuadPart = -(10*1000*500); // 500ms ( 100ns units )
  58. status = ParBuildSendInternalIoctl(IOCTL_INTERNAL_SELECT_DEVICE,
  59. pPortDeviceObject,
  60. &par1284Command, sizeof(PARALLEL_1284_COMMAND),
  61. NULL, 0,
  62. &timeOut);
  63. if( NT_SUCCESS( status ) ) {
  64. // SELECT succeeded
  65. ParDump2(PARSELECTDESELECT, ("par12843::ParSelectDevice - SUCCESS\n") );
  66. if( !HavePort ) {
  67. // note in the device extension that we have the port
  68. Extension->bAllocated = TRUE;
  69. }
  70. return TRUE;
  71. } else {
  72. // SELECT failed
  73. ParDump2(PARSELECTDESELECT, ("par12843::ParSelectDevice - FAIL\n") );
  74. return FALSE;
  75. }
  76. }
  77. BOOLEAN
  78. ParDeselectDevice(
  79. IN PDEVICE_EXTENSION Extension,
  80. IN BOOLEAN KeepPort
  81. )
  82. /*++
  83. Routine Description:
  84. This routine deselects a 1284.3 device and releases the ParPort
  85. Arguments:
  86. Extension - Supplies the device extension.
  87. KeepPort - TRUE indicates that we should keep the port acquired,
  88. so we should only do a DESELECT_DEVICE
  89. - FALSE indicates that we should not keep the port acquired,
  90. so we should do a combination DESELECT_DEVICE/FREE_PORT
  91. Return Value:
  92. TRUE - The device was deselected (and the port released if requested)
  93. FALSE - Failure
  94. --*/
  95. {
  96. NTSTATUS status;
  97. PDEVICE_OBJECT pPortDeviceObject;
  98. PARALLEL_1284_COMMAND par1284Command;
  99. // ParDumpP( ("par12843::ParDeselectDevice - Enter\n") );
  100. //
  101. // If we don't have the port, succeed and return
  102. //
  103. if( !Extension->bAllocated ) {
  104. ParDump2(PARSELECTDESELECT, ("par12843::ParDeselectDevice: we do not have the port, returning TRUE/SUCCESS\n") );
  105. return TRUE;
  106. }
  107. //
  108. // Initialize command structure and extract parameters from the DeviceExtension
  109. //
  110. par1284Command.ID = (UCHAR)Extension->Ieee1284_3DeviceId;
  111. par1284Command.Port = 0; // reserved - 0 for now
  112. if( KeepPort ) {
  113. par1284Command.CommandFlags = PAR_HAVE_PORT_KEEP_PORT;
  114. } else {
  115. par1284Command.CommandFlags = 0;
  116. }
  117. if(Extension->EndOfChain) {
  118. // this is NOT a daisy chain device - flag ParPort that
  119. // the ID field of the command should be ignored
  120. par1284Command.CommandFlags |= PAR_END_OF_CHAIN_DEVICE;
  121. }
  122. pPortDeviceObject = Extension->PortDeviceObject;
  123. //
  124. // Send the request
  125. //
  126. status = ParBuildSendInternalIoctl(IOCTL_INTERNAL_DESELECT_DEVICE,
  127. pPortDeviceObject,
  128. &par1284Command, sizeof(PARALLEL_1284_COMMAND),
  129. NULL, 0,
  130. NULL);
  131. if( NT_SUCCESS( status ) ) {
  132. // DESELECT succeeded
  133. if( !KeepPort ) {
  134. // note in the device extension that we gave up the port
  135. ParDump2(PARSELECTDESELECT, ("par12843::ParDeselectDevice - SUCCESS - giving up Port\n") );
  136. Extension->bAllocated = FALSE;
  137. } else {
  138. ParDump2(PARSELECTDESELECT, ("par12843::ParDeselectDevice - SUCCESS - keeping Port\n") );
  139. }
  140. return TRUE;
  141. } else {
  142. // DESELECT failed
  143. ParDump2(PARSELECTDESELECT, ("par12843::ParDeselectDevice - FAILED - status=%x\n", status) );
  144. ASSERTMSG("DESELECT FAILED??? - this should never happen", FALSE );
  145. return FALSE;
  146. }
  147. }