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.

280 lines
7.9 KiB

  1. // $Header: G:/SwDev/WDM/Video/bt848/rcs/Registry.cpp 1.7 1998/05/07 15:24:55 tomz Exp $
  2. extern "C" {
  3. #include <strmini.h>
  4. }
  5. #include "device.h"
  6. //LONG PsDevice::PinTypes_ [MaxInpPins]; // just allocate maximum possible
  7. //DWORD PsDevice::xtals_ [2]; // no more than 2 xtals
  8. /*++
  9. Routine Description:
  10. Reads the specified registry value
  11. Arguments:
  12. Handle - handle to the registry key
  13. KeyNameString - value to read
  14. KeyNameStringLength - length of string
  15. Data - buffer to read data into
  16. DataLength - length of data buffer
  17. Return Value:
  18. NTSTATUS returned as appropriate
  19. --*/
  20. NTSTATUS GetRegistryValue( IN HANDLE Handle, IN const PUNICODE_STRING KeyName,
  21. IN PCHAR Data, IN ULONG DataLength )
  22. {
  23. NTSTATUS Status = STATUS_INSUFFICIENT_RESOURCES;
  24. ULONG Length;
  25. PKEY_VALUE_FULL_INFORMATION FullInfo;
  26. Length = sizeof( KEY_VALUE_FULL_INFORMATION ) + DataLength + KeyName->MaximumLength;
  27. FullInfo = (struct _KEY_VALUE_FULL_INFORMATION *)ExAllocatePool(PagedPool, Length);
  28. if ( FullInfo ) {
  29. Status = ZwQueryValueKey( Handle, KeyName, KeyValueFullInformation,
  30. FullInfo, Length, &Length );
  31. if ( NT_SUCCESS( Status ) ) {
  32. if ( DataLength >= FullInfo->DataLength ) {
  33. RtlCopyMemory( Data, ((PUCHAR) FullInfo) + FullInfo->DataOffset,
  34. FullInfo->DataLength );
  35. } else {
  36. Status = STATUS_BUFFER_TOO_SMALL;
  37. } // buffer right length
  38. } // if success
  39. ExFreePool( FullInfo );
  40. } // if fullinfo
  41. return Status;
  42. }
  43. /* Function: OpenDriverKey
  44. * Purpose: Opens the DriverData key off the main driver key
  45. * Input: PhysicalDeviceObject : DEVICE_OBJECT *
  46. * Output: Open key handle or NULL
  47. */
  48. HANDLE OpenDriverKey( IN PDEVICE_OBJECT PhysicalDeviceObject )
  49. {
  50. NTSTATUS Status;
  51. HANDLE DevHandle;
  52. Status = IoOpenDeviceRegistryKey( PhysicalDeviceObject, PLUGPLAY_REGKEY_DRIVER,
  53. STANDARD_RIGHTS_ALL, &DevHandle );
  54. HANDLE KeyHandle = NULL;
  55. if ( NT_SUCCESS( Status ) ) {
  56. OBJECT_ATTRIBUTES attr;
  57. UNICODE_STRING UDevDataName;
  58. PWCHAR WDataName = L"DriverData";
  59. RtlInitUnicodeString( &UDevDataName, WDataName );
  60. InitializeObjectAttributes( &attr, &UDevDataName, OBJ_INHERIT, DevHandle,
  61. NULL );
  62. ZwOpenKey( &KeyHandle, KEY_QUERY_VALUE, &attr );
  63. ZwClose( DevHandle );
  64. }
  65. return KeyHandle;
  66. }
  67. /* Function: PrepareKeyName
  68. * Purpose: Creates a UNICODE name for a key
  69. * Parameters: UKeyName: UNICODE_STRING * - key will be created here
  70. * name: PCHAR - regular "C" string
  71. * idx: int - number to append to the name
  72. * Note: this function is useful in creating numbered key names
  73. */
  74. inline void PrepareKeyName( PUNICODE_STRING UKeyName, PCHAR name, int idx )
  75. {
  76. char buf [80];
  77. ANSI_STRING AKeyName;
  78. if ( idx == -1 )
  79. {
  80. RtlInitAnsiString( &AKeyName, name );
  81. }
  82. else
  83. {
  84. sprintf( buf, "%s%d", name, idx );
  85. RtlInitAnsiString( &AKeyName, buf );
  86. }
  87. RtlAnsiStringToUnicodeString( UKeyName, &AKeyName, TRUE );
  88. }
  89. /*++
  90. Routine Description:
  91. Reads the XBAR registry values for the device
  92. Arguments:
  93. PhysicalDeviceObject - pointer to the PDO
  94. Return Value:
  95. None.
  96. --*/
  97. void ReadXBarRegistryValues( IN PDEVICE_OBJECT PhysicalDeviceObject )
  98. {
  99. HANDLE KeyHandle = OpenDriverKey( PhysicalDeviceObject );
  100. if ( KeyHandle ) {
  101. for ( int i = 0; i < MaxInpPins; i++ ) {
  102. UNICODE_STRING UKeyName;
  103. PrepareKeyName( &UKeyName, "XBarInPin", i );
  104. CHAR buf [10];
  105. NTSTATUS Status;
  106. Status = GetRegistryValue( KeyHandle, &UKeyName, buf, sizeof( buf ) );
  107. RtlFreeUnicodeString( &UKeyName );
  108. if ( NT_SUCCESS(Status ) ) {
  109. DebugOut((1, "ReadRegistry %d\n", i ) );
  110. PinTypes_ [i] = *(PDWORD)buf;
  111. } else
  112. PinTypes_ [i] = -1;
  113. }
  114. ZwClose( KeyHandle );
  115. } else { // just use some default to make life eaiser for the xbar code
  116. PinTypes_ [0] = KS_PhysConn_Video_SVideo;
  117. PinTypes_ [1] = KS_PhysConn_Video_Tuner;
  118. PinTypes_ [2] = KS_PhysConn_Video_Composite;
  119. PinTypes_ [3] = KS_PhysConn_Audio_Tuner;
  120. }
  121. }
  122. /* Method: ReadXTalRegistryValues
  123. * Purpose: Obtains number and types of the crystals for this device
  124. * Input: DEVICE_OBJECT *
  125. * Output: None
  126. */
  127. void ReadXTalRegistryValues( IN PDEVICE_OBJECT PhysicalDeviceObject )
  128. {
  129. HANDLE KeyHandle = OpenDriverKey( PhysicalDeviceObject );
  130. if ( KeyHandle ) {
  131. for ( int i = 0; i < 2; i++ ) {
  132. UNICODE_STRING UKeyName;
  133. PrepareKeyName( &UKeyName, "XTal", i );
  134. CHAR buf [10];
  135. NTSTATUS Status;
  136. Status = GetRegistryValue( KeyHandle, &UKeyName, buf, sizeof( buf ) );
  137. RtlFreeUnicodeString( &UKeyName );
  138. if ( NT_SUCCESS(Status ) ) {
  139. DebugOut((1, "Got Xtal %d\n", i ) );
  140. xtals_ [i] = *(PDWORD)buf;
  141. } else
  142. xtals_ [i] = 28; // is this a good default ? :0)
  143. }
  144. ZwClose( KeyHandle );
  145. } else // just use some default to make life eaiser for the xbar code
  146. xtals_ [0] = 28; // default to NTSC only
  147. }
  148. TUNER_INFO TunerInfo;
  149. void DumpTunerInfo( TUNER_INFO * pTunerInfo )
  150. {
  151. DUMPX( pTunerInfo->TunerBrand );
  152. DUMPX( pTunerInfo->TunerI2CAddress );
  153. DUMPX( pTunerInfo->TunerBandCtrlLow );
  154. DUMPX( pTunerInfo->TunerBandCtrlMid );
  155. DUMPX( pTunerInfo->TunerBandCtrlHigh );
  156. }
  157. void ReadTunerRegistryValues( IN PDEVICE_OBJECT PhysicalDeviceObject )
  158. {
  159. HANDLE KeyHandle = OpenDriverKey( PhysicalDeviceObject );
  160. if ( KeyHandle )
  161. {
  162. CHAR buf [10];
  163. NTSTATUS Status;
  164. UNICODE_STRING UKeyName;
  165. BOOL bSuccess = TRUE;
  166. PrepareKeyName( &UKeyName, "TunerBrand", -1 );
  167. Status = GetRegistryValue( KeyHandle, &UKeyName, buf, sizeof( buf ) );
  168. if ( bSuccess = NT_SUCCESS(Status ) )
  169. {
  170. TunerInfo.TunerBrand = *(PDWORD)buf;
  171. PrepareKeyName( &UKeyName, "TunerI2CAddress", -1 );
  172. Status = GetRegistryValue( KeyHandle, &UKeyName, buf, sizeof( buf ) );
  173. if ( bSuccess = NT_SUCCESS(Status ) ) {
  174. TunerInfo.TunerI2CAddress = *(PBYTE)buf;
  175. }
  176. else
  177. {
  178. DebugOut((0, "Failed GetRegistryValue(TunerI2CAddress)\n"));
  179. }
  180. }
  181. else
  182. {
  183. DebugOut((0, "Failed GetRegistryValue(TunerBrand)\n"));
  184. }
  185. if ( !bSuccess )
  186. {
  187. TunerInfo.TunerBrand = TUNER_BRAND_TEMIC;
  188. TunerInfo.TunerI2CAddress = 0xC2;
  189. DebugOut((0, "Defaulting to Temic tuner at I2C address 0xC2\n"));
  190. }
  191. RtlFreeUnicodeString( &UKeyName );
  192. ZwClose( KeyHandle );
  193. }
  194. else
  195. {
  196. TunerInfo.TunerBrand = TUNER_BRAND_TEMIC;
  197. TunerInfo.TunerI2CAddress = 0xC2;
  198. DebugOut((0, "Failed OpenDriverKey()\n"));
  199. DebugOut((0, "Defaulting to Temic tuner at I2C address 0xC2\n"));
  200. }
  201. switch( TunerInfo.TunerBrand )
  202. {
  203. case TUNER_BRAND_PHILIPS:
  204. TunerInfo.TunerBandCtrlLow = 0xCEA0; // Ctrl code for VHF low
  205. TunerInfo.TunerBandCtrlMid = 0xCE90; // Ctrl code for VHF high
  206. TunerInfo.TunerBandCtrlHigh = 0xCE30; // Ctrl code for UHF
  207. break;
  208. case TUNER_BRAND_ALPS:
  209. TunerInfo.TunerBandCtrlLow = 0xC214; // Ctrl code for VHF low
  210. TunerInfo.TunerBandCtrlMid = 0xC212; // Ctrl code for VHF high
  211. TunerInfo.TunerBandCtrlHigh = 0xC211; // Ctrl code for UHF
  212. break;
  213. case TUNER_BRAND_TEMIC:
  214. default:
  215. TunerInfo.TunerBandCtrlLow = 0x8E02; // Ctrl code for VHF low
  216. TunerInfo.TunerBandCtrlMid = 0x8E04; // Ctrl code for VHF high
  217. TunerInfo.TunerBandCtrlHigh = 0x8E01; // Ctrl code for UHF
  218. break;
  219. }
  220. DumpTunerInfo( &TunerInfo );
  221. }