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.

422 lines
13 KiB

  1. //**************************************************************************
  2. //
  3. // Title : CTVCtrl.cpp
  4. //
  5. // Date : 1998.06.29 1st making
  6. //
  7. // Author : Toshiba [PCS](PSY) Hideki Yagi
  8. //
  9. // Copyright 1997-1998 Toshiba Corporation. All Rights Reserved.
  10. //
  11. // -------------------------------------------------------------------------
  12. //
  13. // Change log :
  14. //
  15. // Date Revision Description
  16. // ------------ ---------- -----------------------------------------------
  17. // 1998.06.29 000.0000 1st making.
  18. //
  19. //**************************************************************************
  20. #include "includes.h"
  21. #include "ctvctrl.h"
  22. //#include <ntddk.h>
  23. //#include <string.h>
  24. //#include <devioctl.h>
  25. //#include <windef.h>
  26. #include "Acpiioct.h" // ACPI Driver Interface
  27. CTVControl::CTVControl( void )
  28. {
  29. ;
  30. };
  31. CTVControl::~CTVControl( void )
  32. {
  33. ;
  34. };
  35. BOOL CTVControl :: Initialize( void )
  36. {
  37. PFILE_OBJECT TvaldFileObject;
  38. STRING NameString;
  39. NTSTATUS status;
  40. #ifndef TVALD
  41. UNICODE_STRING RegPath;
  42. STRING KeyPathString;
  43. DWORD DeviceReference, Count;
  44. char keyname[512];
  45. #endif
  46. DBG_PRINTF( ( "CTVControl::Initialize() RtlInitString\n") );
  47. RtlInitString( &NameString, TVALDDRVR_DEVICE_OPEN_NAME );
  48. DBG_PRINTF( ( "CTVControl::Initialize() RtlAnsiStringToUnicodeString\n") );
  49. RtlAnsiStringToUnicodeString( &UNameString, &NameString, TRUE );
  50. is_init_success = TRUE; // add by do '98-08-04
  51. //
  52. // get the device object for the TVALD.sys
  53. //
  54. DBG_PRINTF( ( "CTVControl::Initialize() IoGetDeviceObjectPointer\n") );
  55. status = IoGetDeviceObjectPointer(
  56. &UNameString,
  57. FILE_ANY_ACCESS,
  58. &TvaldFileObject,
  59. &TvaldDeviceObject
  60. );
  61. if (status != STATUS_SUCCESS){
  62. DBG_PRINTF( ( "CTVControl::Initialize() IoGetDeviceObjectPointer Error!!\n") );
  63. #ifndef TVALD
  64. RTL_QUERY_REGISTRY_TABLE Table[2];
  65. //
  66. // TVALD Install check
  67. //
  68. RtlInitUnicodeString( &RegPath, L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services\\TVALD\\Enum");
  69. RtlZeroMemory( Table, sizeof(Table) );
  70. Table[0].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED;
  71. Table[0].Name = L"Count";
  72. Table[0].EntryContext = &Count;
  73. Table[0].DefaultType = REG_DWORD;
  74. Table[0].DefaultData = &RegPath;
  75. Table[0].DefaultLength = sizeof(ULONG);
  76. DBG_PRINTF( ("DVDINIT:RtlQueryRegistryValues Count\n\r") );
  77. status = RtlQueryRegistryValues( RTL_REGISTRY_ABSOLUTE,
  78. RegPath.Buffer,
  79. Table,
  80. NULL,
  81. NULL );
  82. if (status != STATUS_SUCCESS){
  83. DBG_PRINTF( ( "CTVControl::Initialize() RtlQueryRegistryValues Get Count Error!!\n") );
  84. RtlFreeUnicodeString( &UNameString );
  85. is_init_success = FALSE; // add by do '98-08-04
  86. return( FALSE );
  87. }
  88. DBG_PRINTF( ("DVDINIT:RtlQueryRegistryValues success Count = %x\n\r", Count) );
  89. if (Count != 1)
  90. {
  91. DBG_PRINTF( ( "CTVControl::Initialize() RtlQueryRegistryValues Count != 1!!\n") );
  92. RtlFreeUnicodeString( &UNameString );
  93. is_init_success = FALSE; // add by do '98-08-04
  94. return( FALSE );
  95. }
  96. //
  97. // Search control-key
  98. //
  99. RtlInitUnicodeString( &RegPath, L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Enum\\ACPI\\TOS6200");
  100. PKEY_BASIC_INFORMATION pControllerKeyInformation;
  101. OBJECT_ATTRIBUTES objectAttributes;
  102. UCHAR keyBuffer[256]; // Allow for variable length name at end
  103. ULONG resultLength;
  104. HANDLE openKey = NULL;
  105. InitializeObjectAttributes(&objectAttributes,
  106. &RegPath,
  107. OBJ_CASE_INSENSITIVE,
  108. NULL,
  109. NULL);
  110. status = ZwOpenKey(&openKey,
  111. KEY_READ,
  112. &objectAttributes);
  113. if (status != STATUS_SUCCESS){
  114. DBG_PRINTF( ( "CTVControl::Initialize() ZwOpenKey Error!!\n") );
  115. RtlFreeUnicodeString( &UNameString );
  116. is_init_success = FALSE; // add by do '98-08-04
  117. return( FALSE );
  118. }
  119. RtlZeroMemory(keyBuffer, sizeof(keyBuffer));
  120. pControllerKeyInformation = (PKEY_BASIC_INFORMATION) keyBuffer;
  121. for(int Index=0; Index < 256; Index++)
  122. {
  123. status = ZwEnumerateKey(openKey,
  124. Index,
  125. KeyBasicInformation,
  126. pControllerKeyInformation,
  127. sizeof(keyBuffer),
  128. &resultLength);
  129. if (status != STATUS_SUCCESS)
  130. {
  131. DBG_PRINTF( ( "CTVControl::Initialize() ZwOpenKey Error!!\n") );
  132. RtlFreeUnicodeString( &UNameString );
  133. is_init_success = FALSE; // add by do '98-08-04
  134. ZwClose(openKey);
  135. return( FALSE );
  136. }
  137. char szSchKey[256];
  138. for(int schcnt = 0; schcnt < 256; schcnt++)
  139. {
  140. szSchKey[schcnt] = (char)pControllerKeyInformation->Name[schcnt];
  141. if (szSchKey[schcnt] == NULL)
  142. break;
  143. }
  144. memset(keyname,NULL,sizeof(keyname));
  145. memcpy( keyname, "\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Enum\\ACPI\\TOS6200\\",61);
  146. memcpy((&(keyname[61])), szSchKey,(pControllerKeyInformation->NameLength / 2));
  147. memcpy((&(keyname[61 + (pControllerKeyInformation->NameLength / 2)])),"\\Control",8);
  148. DBG_PRINTF( ("DVDINIT:ZwEnumerateKey NameString = %s\n\r", keyname) );
  149. break;
  150. }
  151. ZwClose(openKey);
  152. //
  153. // get the device object for the TVALD.sys
  154. //
  155. RtlInitString( &KeyPathString, keyname );
  156. RtlAnsiStringToUnicodeString( &RegPath, &KeyPathString, TRUE );
  157. RtlZeroMemory( Table, sizeof(Table) );
  158. Table[0].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_REQUIRED;
  159. Table[0].Name = L"DeviceReference";
  160. Table[0].EntryContext = &DeviceReference;
  161. Table[0].DefaultType = REG_DWORD;
  162. Table[0].DefaultData = &RegPath;
  163. Table[0].DefaultLength = sizeof(ULONG);
  164. DBG_PRINTF( ("DVDINIT:RtlQueryRegistryValues DeviceReference\n\r") );
  165. status = RtlQueryRegistryValues( RTL_REGISTRY_ABSOLUTE,
  166. RegPath.Buffer,
  167. Table,
  168. NULL,
  169. NULL );
  170. if (status != STATUS_SUCCESS){
  171. DBG_PRINTF( ( "CTVControl::Initialize() RtlQueryRegistryValues Get DeviceReference Error!!\n") );
  172. RtlFreeUnicodeString( &UNameString );
  173. is_init_success = FALSE; // add by do '98-08-04
  174. return( FALSE );
  175. }
  176. DBG_PRINTF( ("DVDINIT:RtlQueryRegistryValues success DeviceReference = %x\n\r", DeviceReference) );
  177. TvaldDeviceObject = (PDEVICE_OBJECT)DeviceReference;
  178. TvaldDeviceObject = TvaldDeviceObject->AttachedDevice;
  179. #else
  180. RtlFreeUnicodeString( &UNameString );
  181. is_init_success = FALSE; // add by do '98-08-04
  182. return( FALSE );
  183. #endif TVALD
  184. }
  185. DBG_PRINTF( ( "CTVControl::Initialize() KeInitializeObject\n") );
  186. KeInitializeEvent(&event, NotificationEvent, FALSE);
  187. inputreg.GHCI_EAX = 0x0000f100;
  188. inputreg.GHCI_EBX = inputreg.GHCI_ECX = inputreg.GHCI_EDX =
  189. inputreg.GHCI_ESI = inputreg.GHCI_EDI = 0x0;
  190. if( Tvald_GHCI( &inputreg ) == FALSE ){ // SCI Interface Open
  191. DBG_PRINTF( ( "CTVControl::Initialize() SCI Interface Open Error! \n") );
  192. is_init_success = FALSE; // add by do '98-08-04
  193. return (FALSE);
  194. }
  195. return( TRUE );
  196. };
  197. BOOL CTVControl :: Uninitialize( void )
  198. {
  199. inputreg.GHCI_EAX = 0x0000f200;
  200. inputreg.GHCI_EBX = inputreg.GHCI_ECX = inputreg.GHCI_EDX =
  201. inputreg.GHCI_ESI = inputreg.GHCI_EDI = 0x0;
  202. if( Tvald_GHCI( &inputreg ) == FALSE ){ // SCI Interface Close
  203. DBG_PRINTF( ( "CTVControl::Uninitialize() SCI Interface Close Error!\n") );
  204. is_init_success = FALSE; // add by do '98-08-04
  205. return (FALSE);
  206. }
  207. DBG_PRINTF( ( "CTVControl::Uninitialize() RtlFreeUnicodeString\n") );
  208. RtlFreeUnicodeString( &UNameString );
  209. return( TRUE );
  210. };
  211. BOOL CTVControl :: GetDisplayStatus( PVOID status )
  212. {
  213. DisplayStatusStruc *pDisplayStat;
  214. DBG_PRINTF( ( "CTVControl::GetDisplayStatus() begin --->\n") );
  215. if(is_init_success == FALSE){ // add by do '98-08-04
  216. DBG_PRINTF( ( "CTVControl::GetDisplayStatus() end <--- is_init_success == FALSE\n") );
  217. return (FALSE); // add by do '98-08-04
  218. }
  219. pDisplayStat = (DisplayStatusStruc *)status;
  220. // Get Current Display Status from BIOS by using ASl call.
  221. inputreg.GHCI_EAX = 0x0000fe00;
  222. inputreg.GHCI_EBX = 0x00000035;
  223. inputreg.GHCI_ECX = 0x0;
  224. inputreg.GHCI_EDX = 0x0;
  225. inputreg.GHCI_ESI = 0x0;
  226. inputreg.GHCI_EDI = 0x0;
  227. if( Tvald_GHCI( &inputreg ) == FALSE ){
  228. DBG_PRINTF( ( "CTVControl::GetDisplayStatus() Tvald_GHCI Error!\n") );
  229. return (FALSE);
  230. }
  231. if( (inputreg.GHCI_EAX & 0x0000ff00) != 0 ){
  232. DBG_PRINTF( ( "CTVControl::GetDisplayStatus() Get Display Status Error!!\n") );
  233. return( FALSE );
  234. }
  235. pDisplayStat->SizeofStruc = sizeof(DisplayStatusStruc);
  236. pDisplayStat->AvailableDisplay = (inputreg.GHCI_EBX & 0x00000700)>>8;
  237. pDisplayStat->CurrentDisplay = ((inputreg.GHCI_EBX & 0x00000078) << 25)|
  238. (inputreg.GHCI_EBX & 0x00000007);
  239. DBG_PRINTF( ( "CTVControl::GetDisplayStatus() end <---\n") );
  240. return( TRUE );
  241. };
  242. BOOL CTVControl :: SetDisplayStatus( PVOID status )
  243. {
  244. DisplayStatusStruc *pDisplayStat, currStat;
  245. ULONG setstatusreg, getstatusreg;
  246. DBG_PRINTF( ( "CTVControl::SetDisplayStatus() begin --->\n") );
  247. if(is_init_success == FALSE){ // add by do '98-08-04
  248. DBG_PRINTF( ( "CTVControl::SetDisplayStatus() end <--- is_init_success == FALSE\n") );
  249. return (FALSE); // add by do '98-08-04
  250. }
  251. pDisplayStat = (DisplayStatusStruc *)status;
  252. setstatusreg = pDisplayStat->CurrentDisplay;
  253. // 98.11.17 H.Yagi
  254. currStat.AvailableDisplay = 0x0;
  255. currStat.CurrentDisplay = 0x0;
  256. GetDisplayStatus( &currStat );
  257. getstatusreg = ( (currStat.CurrentDisplay & 0x0f0000000)>>25 );
  258. if( (getstatusreg & 0x40)==0x00 ){ // single mode
  259. getstatusreg = (getstatusreg & 0x008) | 0x040; // keep TV type bit
  260. }
  261. // getstatusreg = ((pDisplayStat->CurrentDisplay & 0x30000000) >> 25) | 0x00000040;
  262. // Set Current Display Status from BIOS by using ASl call.
  263. inputreg.GHCI_EAX = 0x0000ff00;
  264. inputreg.GHCI_EBX = 0x00000035;
  265. inputreg.GHCI_ECX = (setstatusreg & 0x00000007)| getstatusreg;
  266. inputreg.GHCI_EDX = 0x0;
  267. inputreg.GHCI_ESI = 0x0;
  268. inputreg.GHCI_EDI = 0x0;
  269. if( Tvald_GHCI( &inputreg ) == FALSE ){
  270. DBG_PRINTF( ( "CTVControl::SetDisplayStatus() Tvald_GHCI Error!\n") );
  271. return (FALSE);
  272. }
  273. if( (inputreg.GHCI_EAX & 0x0000ff00) != 0 ){
  274. DBG_PRINTF( ( "CTVControl::SetDisplayStatus() Set Display Status Error!!\n") );
  275. DBG_PRINTF( ( "CTVControl::SetDisplayStatus() end <---\n") );
  276. return( FALSE );
  277. }
  278. DBG_PRINTF( ( "CTVControl::SetDisplayStatus() end <---\n") );
  279. return( TRUE );
  280. };
  281. BOOL CTVControl :: SetTVOutput( DWORD status )
  282. {
  283. DBG_PRINTF( ( "CTVControl::SetTVOutput() begin --->\n") );
  284. if(is_init_success == FALSE){ // add by do '98-08-04
  285. DBG_PRINTF( ( "CTVControl::SetTVOutput() end <--- is_init_success == FALSE\n") );
  286. return (FALSE); // add by do '98-08-04
  287. }
  288. switch( status ){
  289. case DISABLE_TV:
  290. // Set status
  291. inputreg.GHCI_ECX = 0x00000001; // Play back "In progress" copy protected DVD.
  292. break;
  293. case ENABLE_TV:
  294. // Set status
  295. inputreg.GHCI_ECX = 0; // Play back "Done" copy protected DVD.
  296. break;
  297. default:
  298. break;
  299. }
  300. inputreg.GHCI_EAX = 0x0000ff00;
  301. inputreg.GHCI_EBX = 0x00000036;
  302. inputreg.GHCI_EDX = 0x0;
  303. inputreg.GHCI_ESI = 0x0;
  304. inputreg.GHCI_EDI = 0x0;
  305. if( Tvald_GHCI( &inputreg ) == FALSE ){
  306. DBG_PRINTF( ( "CTVControl::SetTVOutput() Tvald_GHCI Error!\n") );
  307. return (FALSE);
  308. }
  309. if( (inputreg.GHCI_EAX & 0x0000ff00) != 0 ){
  310. DBG_PRINTF( ( "CTVControl::SetTVOutput() Set Display Status Error!!\n") );
  311. DBG_PRINTF( ( "CTVControl::SetTVOutput() end <---\n") );
  312. return( FALSE );
  313. }
  314. DBG_PRINTF( ( "CTVControl::SetTVOutput() end <---\n") );
  315. return( TRUE );
  316. };
  317. //void CTVControl :: Tvald_GHCI( PGHCI_INTERFACE pinputreg )
  318. BOOL CTVControl :: Tvald_GHCI( PGHCI_INTERFACE pinputreg )
  319. {
  320. PIRP irp;
  321. NTSTATUS status;
  322. IO_STATUS_BLOCK iostatus;
  323. USHORT index;
  324. PULONG pUlongTmpInput, pUlongTmpOutput;
  325. DBG_PRINTF( ( "CTVControl::Tvald_GHCI() begin --->\n") );
  326. status = STATUS_SUCCESS;
  327. // KIRQL CurentIrql = KeGetCurrentIrql();
  328. // DBG_PRINTF( ( "CTVControl::Tvald_GHCI() CurentIrql = %d \n", CurentIrql) );
  329. DBG_PRINTF( ( "CTVControl::Tvald_GHCI() IoBuildDeviceIoControlRequest\n") );
  330. irp = IoBuildDeviceIoControlRequest(
  331. IOCTL_TVALD_GHCI,
  332. TvaldDeviceObject,
  333. pinputreg,
  334. sizeof(GHCI_INTERFACE),
  335. pinputreg,
  336. sizeof(GHCI_INTERFACE),
  337. FALSE,
  338. &event,
  339. &iostatus
  340. );
  341. if(!irp){
  342. DBG_PRINTF( ( "CTVControl::Tvald_GHCI() IoBuildDeviceIoControlRequest Error!!\n") );
  343. iostatus.Status = STATUS_INSUFFICIENT_RESOURCES;
  344. iostatus.Information = 0;
  345. DBG_PRINTF( ( "CTVControl::Tvald_GHCI() RtlFreeUnicodeString\n") );
  346. RtlFreeUnicodeString( &UNameString );
  347. // return;
  348. return (FALSE);
  349. }
  350. DBG_PRINTF( ( "CTVControl::Tvald_GHCI() IoCallDriver\n") );
  351. status = IoCallDriver(TvaldDeviceObject, irp);
  352. if( status == STATUS_PENDING ){
  353. DBG_PRINTF( ( "CTVControl::Tvald_GHCI() KeWaitForSingleObject\n") );
  354. KeWaitForSingleObject(&event, Suspended, KernelMode, FALSE, NULL);
  355. }
  356. else if ( status != STATUS_SUCCESS )
  357. return (FALSE);
  358. pUlongTmpInput = (PULONG)pinputreg;
  359. pUlongTmpOutput = (PULONG)irp->AssociatedIrp.SystemBuffer;
  360. for(index = 0; index < 6; index++){
  361. *pUlongTmpInput = *pUlongTmpOutput;
  362. pUlongTmpInput++;
  363. pUlongTmpOutput++;
  364. }
  365. return (TRUE);
  366. }