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.

255 lines
9.2 KiB

  1. /***************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Parport.sys - Parallel port (IEEE 1284, IEEE 1284.3) driver.
  5. File Name:
  6. driverEntry.c
  7. Abstract:
  8. DriverEntry routine - driver initialization
  9. Environment:
  10. Kernel mode only
  11. Notes:
  12. THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  13. KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14. IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  15. PURPOSE.
  16. Copyright (c) 2000 Microsoft Corporation. All Rights Reserved.
  17. Revision History:
  18. 2000-07-25 - Doug Fritz
  19. - code cleanup, add comments, add copyright
  20. Author(s):
  21. Doug Fritz
  22. ****************************************************************************/
  23. #include "pch.h"
  24. /************************************************************************/
  25. /* DriverEntry */
  26. /************************************************************************/
  27. //
  28. // Routine Description:
  29. //
  30. // This is the DriverEntry routine -- the first function called
  31. // after the driver has been loaded into memory.
  32. //
  33. // Arguments:
  34. //
  35. // DriverObject - points to the DRIVER_OBJECT for this driver
  36. // RegPath - the service registry key for this driver
  37. //
  38. // Return Value:
  39. //
  40. // STATUS_SUCCESS - on success
  41. // STATUS_NO_MEMORY - if unable to allocate pool
  42. //
  43. // Notes:
  44. //
  45. // Log:
  46. //
  47. /************************************************************************/
  48. NTSTATUS
  49. DriverEntry(
  50. IN PDRIVER_OBJECT DriverObject,
  51. IN PUNICODE_STRING RegPath
  52. )
  53. {
  54. //
  55. // Save a copy of *RegPath in driver global RegistryPath for future reference.
  56. //
  57. // UNICODE_NULL terminate the path so that we can safely use RegistryPath.Buffer
  58. // as a PWSTR.
  59. //
  60. {
  61. USHORT size = RegPath->Length + sizeof(WCHAR);
  62. RegistryPath.Buffer = ExAllocatePool( (PagedPool | POOL_COLD_ALLOCATION), size );
  63. if( NULL == RegistryPath.Buffer ) {
  64. return STATUS_NO_MEMORY;
  65. }
  66. RegistryPath.Length = 0;
  67. RegistryPath.MaximumLength = size;
  68. RtlCopyUnicodeString( &RegistryPath, RegPath );
  69. RegistryPath.Buffer[ size/sizeof(WCHAR) - 1 ] = UNICODE_NULL;
  70. }
  71. //
  72. // Initialize Driver Globals
  73. //
  74. // Non-zero means don't raise IRQL from PASSIVE_LEVEL to DISPATCH_LEVEL
  75. // when doing CENTRONICS mode (SPP) writes.
  76. SppNoRaiseIrql = 0;
  77. PptRegGetDword( RTL_REGISTRY_SERVICES, L"Parport\\Parameters", L"SppNoRaiseIrql", &SppNoRaiseIrql );
  78. // Non-zero means override CENTRONICS as the default Forward mode and/or NIBBLE as
  79. // the default Reverse mode. Valid modes are those defined in ntddpar.h as
  80. // parameters for IOCTL_IEEE1284_NEGOTIATE.
  81. // *** Warning: invalid settings and/or setting/device incompatibilities can render
  82. // the port unusable until the settings are corrected
  83. DefaultModes = 0;
  84. PptRegGetDword( RTL_REGISTRY_SERVICES, L"Parport\\Parameters", L"DefaultModes", &DefaultModes );
  85. // Set tracing level for driver DbgPrint messages. Trace values defined in debug.h.
  86. // Zero means no trace output.
  87. Trace = 0;
  88. PptRegGetDword( RTL_REGISTRY_SERVICES, L"Parport\\Parameters", L"Trace", &Trace );
  89. // Request DbgBreakPoint on driver events. Event values defined in debug.h.
  90. // Zero means no breakpoints requested.
  91. Break = 0;
  92. PptRegGetDword( RTL_REGISTRY_SERVICES, L"Parport\\Parameters", L"Break", &Break );
  93. // Mask OFF debug spew for specific devices. See debug.h for flag definitions
  94. // 0 means allow debug spew for that device
  95. // ~0 means mask OFF all (show NO) debug spew for that device type
  96. DbgMaskFdo = 0;
  97. PptRegGetDword( RTL_REGISTRY_SERVICES, L"Parport\\Parameters", L"DbgMaskFdo", &DbgMaskFdo );
  98. DbgMaskRawPort = 0;
  99. PptRegGetDword( RTL_REGISTRY_SERVICES, L"Parport\\Parameters", L"DbgMaskRawPort", &DbgMaskRawPort );
  100. DbgMaskDaisyChain0 = 0;
  101. PptRegGetDword( RTL_REGISTRY_SERVICES, L"Parport\\Parameters", L"DbgMaskDaisyChain0", &DbgMaskDaisyChain0 );
  102. DbgMaskDaisyChain1 = 0;
  103. PptRegGetDword( RTL_REGISTRY_SERVICES, L"Parport\\Parameters", L"DbgMaskDaisyChain1", &DbgMaskDaisyChain1 );
  104. DbgMaskEndOfChain = 0;
  105. PptRegGetDword( RTL_REGISTRY_SERVICES, L"Parport\\Parameters", L"DbgMaskEndOfChain", &DbgMaskEndOfChain );
  106. DbgMaskLegacyZip = 0;
  107. PptRegGetDword( RTL_REGISTRY_SERVICES, L"Parport\\Parameters", L"DbgMaskLegacyZip", &DbgMaskLegacyZip );
  108. DbgMaskNoDevice = 0;
  109. PptRegGetDword( RTL_REGISTRY_SERVICES, L"Parport\\Parameters", L"DbgMaskNoDevice", &DbgMaskNoDevice );
  110. #if 1 == DBG_SHOW_BYTES
  111. DbgShowBytes = 1;
  112. PptRegGetDword( RTL_REGISTRY_SERVICES, L"Parport\\Parameters", L"DbgShowBytes", &DbgShowBytes );
  113. #endif
  114. //
  115. // Allow asserts? non-zero means allow assertions
  116. //
  117. AllowAsserts = 0;
  118. PptRegGetDword( RTL_REGISTRY_SERVICES, L"Parport\\Parameters", L"AllowAsserts", &AllowAsserts );
  119. // Non-zero means enable detection of Iomega Legacy Zip-100 drives that use
  120. // an Iomega proprietary Select/Deselect mechanism rather than the Select/Deselect
  121. // mechanism defined by IEEE 1284.3. (These drives pre-date IEEE 1284.3)
  122. // *** Note: if zero, this registry setting is checked again during every PnP QDR/BusRelations
  123. // query to see if the user has enabled detection via the Ports property page "Enable
  124. // legacy Plug and Play detection" checkbox.
  125. ParEnableLegacyZip = 0;
  126. PptRegGetDword( RTL_REGISTRY_SERVICES, L"Parport\\Parameters", L"ParEnableLegacyZip", &ParEnableLegacyZip );
  127. // Default timeout when trying to acquire exclusive access to the (shared) port
  128. {
  129. const ULONG halfSecond = 500; // in milliseconds
  130. const ULONG fiveSeconds = 5000;
  131. ULONG requestedTimeout = halfSecond;
  132. PptRegGetDword( RTL_REGISTRY_SERVICES, L"Parport\\Parameters", L"AcquirePortTimeout", &requestedTimeout );
  133. if( requestedTimeout < halfSecond ) {
  134. requestedTimeout = halfSecond;
  135. } else if( requestedTimeout > fiveSeconds ) {
  136. requestedTimeout = fiveSeconds;
  137. }
  138. PPT_SET_RELATIVE_TIMEOUT_IN_MILLISECONDS( AcquirePortTimeout, requestedTimeout );
  139. }
  140. {
  141. //
  142. // register for callbacks so that we can detect switch between
  143. // AC and battery power and tone done "polling for printers"
  144. // when machine switches to battery power.
  145. //
  146. OBJECT_ATTRIBUTES objAttributes;
  147. UNICODE_STRING callbackName;
  148. NTSTATUS localStatus;
  149. RtlInitUnicodeString(&callbackName, L"\\Callback\\PowerState");
  150. InitializeObjectAttributes(&objAttributes,
  151. &callbackName,
  152. OBJ_CASE_INSENSITIVE,
  153. NULL,
  154. NULL);
  155. localStatus = ExCreateCallback(&PowerStateCallbackObject,
  156. &objAttributes,
  157. FALSE,
  158. TRUE);
  159. if( STATUS_SUCCESS == localStatus ) {
  160. PowerStateCallbackRegistration = ExRegisterCallback(PowerStateCallbackObject,
  161. PowerStateCallback,
  162. NULL);
  163. }
  164. }
  165. //
  166. // Set dispatch table entries for IRP_MJ_* functions that we handle
  167. //
  168. DriverObject->MajorFunction[ IRP_MJ_CREATE ] = PptDispatchCreateOpen;
  169. DriverObject->MajorFunction[ IRP_MJ_CLOSE ] = PptDispatchClose;
  170. DriverObject->MajorFunction[ IRP_MJ_CLEANUP ] = PptDispatchCleanup;
  171. DriverObject->MajorFunction[ IRP_MJ_READ ] = PptDispatchRead;
  172. DriverObject->MajorFunction[ IRP_MJ_WRITE ] = PptDispatchWrite;
  173. DriverObject->MajorFunction[ IRP_MJ_DEVICE_CONTROL ] = PptDispatchDeviceControl;
  174. DriverObject->MajorFunction[ IRP_MJ_INTERNAL_DEVICE_CONTROL ] = PptDispatchInternalDeviceControl;
  175. DriverObject->MajorFunction[ IRP_MJ_QUERY_INFORMATION ] = PptDispatchQueryInformation;
  176. DriverObject->MajorFunction[ IRP_MJ_SET_INFORMATION ] = PptDispatchSetInformation;
  177. DriverObject->MajorFunction[ IRP_MJ_PNP ] = PptDispatchPnp;
  178. DriverObject->MajorFunction[ IRP_MJ_POWER ] = PptDispatchPower;
  179. DriverObject->MajorFunction[ IRP_MJ_SYSTEM_CONTROL ] = PptDispatchSystemControl;
  180. DriverObject->DriverExtension->AddDevice = P5AddDevice;
  181. DriverObject->DriverUnload = PptUnload;
  182. //
  183. // Break on user request
  184. // (typically via registry setting ...\Services\Parport\Parameters : Break : REG_DWORD : 0x1)
  185. //
  186. // This is a useful breakpoint in order to manually set appropriate breakpoints elsewhere in the driver.
  187. //
  188. PptBreakOnRequest( PPT_BREAK_ON_DRIVER_ENTRY, ("PPT_BREAK_ON_DRIVER_ENTRY - BreakPoint requested") );
  189. DD(NULL,DDT,"Parport DriverEntry - SUCCESS\n");
  190. return STATUS_SUCCESS;
  191. }