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.

406 lines
11 KiB

  1. //***************************************************************************
  2. // Initialize process
  3. //
  4. //***************************************************************************
  5. #include "common.h"
  6. #include "regs.h"
  7. #include "cdack.h"
  8. #include "cvdec.h"
  9. #include "cvpro.h"
  10. #include "cadec.h"
  11. #include "ccpgd.h"
  12. #include "ccpp.h"
  13. #include "dvdcmd.h"
  14. extern void BadWait( DWORD dwTime );
  15. //--- 97.09.23 K.Chujo
  16. extern void USCC_on( PHW_DEVICE_EXTENSION pHwDevExt );
  17. extern void USCC_off( PHW_DEVICE_EXTENSION pHwDevExt );
  18. //--- End.
  19. extern "C" BOOLEAN STREAMAPI HwInterrupt( IN PHW_DEVICE_EXTENSION pHwDevExt );
  20. /*
  21. ** DriverEntry()
  22. */
  23. extern "C" NTSTATUS DriverEntry( IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath )
  24. {
  25. HW_INITIALIZATION_DATA HwInitData;
  26. // TRAP;
  27. DebugPrint( (DebugLevelTrace, "TOSDVD:DriverEntry\r\n") );
  28. RtlZeroMemory( &HwInitData, sizeof(HW_INITIALIZATION_DATA) );
  29. HwInitData.HwInitializationDataSize = sizeof(HwInitData);
  30. HwInitData.HwInterrupt = (PHW_INTERRUPT)HwInterrupt;
  31. HwInitData.HwReceivePacket = AdapterReceivePacket;
  32. HwInitData.HwCancelPacket = AdapterCancelPacket;
  33. HwInitData.HwRequestTimeoutHandler = AdapterTimeoutPacket;
  34. HwInitData.DeviceExtensionSize = sizeof(HW_DEVICE_EXTENSION);
  35. HwInitData.PerRequestExtensionSize = sizeof(SRB_EXTENSION);
  36. HwInitData.PerStreamExtensionSize = sizeof(STREAMEX);
  37. HwInitData.FilterInstanceExtensionSize = 0;
  38. HwInitData.BusMasterDMA = TRUE;
  39. HwInitData.Dma24BitAddresses = FALSE;
  40. HwInitData.BufferAlignment = 4;
  41. HwInitData.TurnOffSynchronization = FALSE;
  42. HwInitData.DmaBufferSize = DMASIZE;
  43. return (
  44. StreamClassRegisterMinidriver(
  45. (PVOID)DriverObject,
  46. (PVOID)RegistryPath,
  47. &HwInitData )
  48. );
  49. }
  50. void GetPCIConfigSpace(IN PHW_STREAM_REQUEST_BLOCK pSrb)
  51. {
  52. PPORT_CONFIGURATION_INFORMATION ConfigInfo = pSrb->CommandData.ConfigInfo;
  53. PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)ConfigInfo->HwDeviceExtension;
  54. if( StreamClassReadWriteConfig(
  55. pSrb->HwDeviceExtension,
  56. TRUE, // indicates a READ (FALSE means a WRITE)
  57. (PVOID)&pHwDevExt->PciConfigSpace,
  58. 0, // this is the offset into the PCI space,
  59. // change this to whatever you need to read
  60. 64 // this is the # of bytes to read. Changer
  61. // it to the correct #.
  62. )) {
  63. //
  64. // process the config info your read here.
  65. //
  66. {
  67. ULONG i, j;
  68. DebugPrint( (DebugLevelTrace, "TOSDVD:PCI Config Space\r\n" ) );
  69. for( i=0; i<64; ) {
  70. DebugPrint( (DebugLevelTrace, "TOSDVD: " ) );
  71. for( j=0; j<8 && i<64; j++, i++ ) {
  72. DebugPrint( (DebugLevelTrace, "0x%02x ", (UCHAR)*(((PUCHAR)&pHwDevExt->PciConfigSpace) + i) ) );
  73. }
  74. DebugPrint( (DebugLevelTrace, "\r\n" ) );
  75. }
  76. }
  77. //
  78. // note that the PCI_COMMON_CONFIG structure in WDM.H can be used
  79. // for referencing the PCI data.
  80. //
  81. }
  82. //
  83. // now return to high priority to complete initialization
  84. //
  85. StreamClassCallAtNewPriority(
  86. NULL,
  87. pSrb->HwDeviceExtension,
  88. LowToHigh,
  89. (PHW_PRIORITY_ROUTINE) InitializationEntry,
  90. pSrb
  91. );
  92. return;
  93. }
  94. void InitializationEntry(IN PHW_STREAM_REQUEST_BLOCK pSrb)
  95. {
  96. DWORD st, et;
  97. st = GetCurrentTime_ms();
  98. HwInitialize( pSrb );
  99. et = GetCurrentTime_ms();
  100. DebugPrint( (DebugLevelTrace, "TOSDVD:init %dms\r\n", et - st ) );
  101. StreamClassDeviceNotification( ReadyForNextDeviceRequest,
  102. pSrb->HwDeviceExtension );
  103. StreamClassDeviceNotification( DeviceRequestComplete,
  104. pSrb->HwDeviceExtension,
  105. pSrb );
  106. }
  107. /*
  108. ** HwInitialize()
  109. */
  110. NTSTATUS HwInitialize( IN PHW_STREAM_REQUEST_BLOCK pSrb )
  111. {
  112. PPORT_CONFIGURATION_INFORMATION ConfigInfo = pSrb->CommandData.ConfigInfo;
  113. PHW_DEVICE_EXTENSION pHwDevExt =
  114. (PHW_DEVICE_EXTENSION)ConfigInfo->HwDeviceExtension;
  115. DebugPrint( (DebugLevelTrace, "TOSDVD:HwInitialize()\r\n") );
  116. DebugPrint( (DebugLevelTrace, "TOSDVD: pHwDevExt = %p\r\n", pHwDevExt ) );
  117. DebugPrint( (DebugLevelTrace, "TOSDVD: pSrb->HwDeviceExtension = %p\r\n", pSrb->HwDeviceExtension ) );
  118. DebugPrint( (DebugLevelTrace, "TOSDVD: NumberOfAccessRanges = %d\r\n", ConfigInfo->NumberOfAccessRanges ) );
  119. if ( ConfigInfo->NumberOfAccessRanges < 1 ) {
  120. DebugPrint( (DebugLevelTrace, "TOSDVD:illegal config info") );
  121. pSrb->Status = STATUS_NO_SUCH_DEVICE;
  122. return( FALSE );
  123. }
  124. // Debug Dump ConfigInfo
  125. DebugPrint( (DebugLevelTrace, "TOSDVD: Port = %p\r\n", ConfigInfo->AccessRanges[0].RangeStart.LowPart ) );
  126. DebugPrint( (DebugLevelTrace, "TOSDVD: Length = %p\r\n", ConfigInfo->AccessRanges[0].RangeLength ) );
  127. DebugPrint( (DebugLevelTrace, "TOSDVD: IRQ = %p\r\n", ConfigInfo->BusInterruptLevel ) );
  128. DebugPrint( (DebugLevelTrace, "TOSDVD: Vector = %p\r\n", ConfigInfo->BusInterruptVector ) );
  129. DebugPrint( (DebugLevelTrace, "TOSDVD: DMA = %p\r\n", ConfigInfo->DmaChannel ) );
  130. // initialize the size of stream descriptor information.
  131. ConfigInfo->StreamDescriptorSize =
  132. STREAMNUM * sizeof(HW_STREAM_INFORMATION) +
  133. sizeof(HW_STREAM_HEADER);
  134. // pick up the I/O windows for the card.
  135. pHwDevExt->ioBaseLocal =
  136. (PUCHAR)ConfigInfo->AccessRanges[0].RangeStart.QuadPart;
  137. // pick up the Interrupt level
  138. pHwDevExt->Irq =
  139. ConfigInfo->BusInterruptLevel;
  140. // pick up the Revision id
  141. pHwDevExt->RevID =
  142. (ULONG)pHwDevExt->PciConfigSpace.RevisionID;
  143. STREAM_PHYSICAL_ADDRESS adr;
  144. ULONG Size;
  145. PUCHAR pDmaBuf;
  146. pDmaBuf = (PUCHAR)StreamClassGetDmaBuffer( pHwDevExt );
  147. pHwDevExt->pDmaBuf = pDmaBuf;
  148. DebugPrint( (DebugLevelTrace, "TOSDVD: DMA Buffer Logical Addr = 0x%x\r\n", pDmaBuf ) );
  149. adr = StreamClassGetPhysicalAddress( pHwDevExt, NULL, pDmaBuf, DmaBuffer, &Size) ;
  150. pHwDevExt->addr = adr;
  151. DebugPrint( (DebugLevelTrace, "TOSDVD: DMA Buffer Physical Addr = 0x%x\r\n", adr.LowPart ) );
  152. DebugPrint( (DebugLevelTrace, "TOSDVD: DMA Buffer Size = %d\r\n", Size ) );
  153. //
  154. NTSTATUS Stat;
  155. PUCHAR ioBase = pHwDevExt->ioBaseLocal;
  156. DEVICE_INIT_INFO DevInfo;
  157. DevInfo.ioBase = ioBase;
  158. // initialize the hardware settings
  159. pHwDevExt->StreamType = STREAM_MODE_DVD;
  160. pHwDevExt->TVType = DISPLAY_MODE_NTSC;
  161. pHwDevExt->VideoAspect = ASPECT_04_03;
  162. pHwDevExt->LetterBox = FALSE;
  163. pHwDevExt->PanScan = FALSE;
  164. pHwDevExt->AudioMode = AUDIO_TYPE_AC3;
  165. // pHwDevExt->AudioMode = AUDIO_TYPE_PCM;
  166. pHwDevExt->AudioType = AUDIO_OUT_ANALOG;
  167. pHwDevExt->AudioVolume = 0x7f;
  168. pHwDevExt->AudioCgms = AUDIO_CGMS_03; // No copying is permitted
  169. pHwDevExt->AudioFreq = AUDIO_FS_48;
  170. pHwDevExt->VideoMute = FALSE;
  171. pHwDevExt->AudioMute = FALSE;
  172. pHwDevExt->SubpicMute = FALSE;
  173. pHwDevExt->OSDMute = TRUE;
  174. pHwDevExt->SubpicHilite = FALSE;
  175. pHwDevExt->PlayMode = PLAY_MODE_NORMAL;
  176. pHwDevExt->RunMode = PLAY_MODE_NORMAL; // PlayMode after BOOT is Normal Mode;
  177. pHwDevExt->pSrbDMA0 = NULL;
  178. pHwDevExt->pSrbDMA1 = NULL;
  179. pHwDevExt->SendFirst = FALSE;
  180. pHwDevExt->DecodeStart = FALSE;
  181. //--- 97.09.08 K.Chujo
  182. pHwDevExt->TimeDiscontFlagCount = 0;
  183. //--- End.
  184. //--- 97.09.09 K.Chujo
  185. pHwDevExt->DataDiscontFlagCount = 0;
  186. //--- End.
  187. pHwDevExt->bKeyDataXfer = FALSE;
  188. pHwDevExt->CppFlagCount = 0;
  189. pHwDevExt->pSrbCpp = NULL;
  190. pHwDevExt->bCppReset = FALSE;
  191. pHwDevExt->XferStartCount = 0;
  192. // pHwDevExt->lSeemVBuff = 0;
  193. // pHwDevExt->dwSeemSTC = 0;
  194. //--- 97.09.08 K.Chujo
  195. pHwDevExt->dwSTCInit = 0;
  196. pHwDevExt->bDMAscheduled = FALSE;
  197. pHwDevExt->fCauseOfStop = 0;
  198. pHwDevExt->bDMAstop = FALSE;
  199. pHwDevExt->bVideoQueue = FALSE;
  200. pHwDevExt->bAudioQueue = FALSE;
  201. pHwDevExt->bSubpicQueue = FALSE;
  202. //--- End.
  203. //--- 97.09.24
  204. pHwDevExt->VideoMaxFullRate = 1 * 10000;
  205. pHwDevExt->AudioMaxFullRate = 1 * 10000;
  206. pHwDevExt->SubpicMaxFullRate = 1 * 10000;
  207. //--- End.
  208. pHwDevExt->cOpenInputStream = 0;
  209. pHwDevExt->pstroVid = NULL;
  210. pHwDevExt->pstroAud = NULL;
  211. pHwDevExt->pstroSP = NULL;
  212. pHwDevExt->pstroYUV = NULL;
  213. pHwDevExt->pstroCC = NULL;
  214. pHwDevExt->DAck.init( &DevInfo );
  215. pHwDevExt->VDec.init( &DevInfo );
  216. pHwDevExt->ADec.init( &DevInfo );
  217. pHwDevExt->VPro.init( &DevInfo );
  218. pHwDevExt->CPgd.init( &DevInfo );
  219. pHwDevExt->ADec.SetParam(
  220. pHwDevExt->AudioMode,
  221. pHwDevExt->AudioFreq,
  222. pHwDevExt->AudioType,
  223. pHwDevExt->AudioCgms,
  224. &pHwDevExt->DAck
  225. );
  226. pHwDevExt->VPro.SetParam( pHwDevExt->AudioMode, pHwDevExt->SubpicMute );
  227. pHwDevExt->CPro.init( &DevInfo );
  228. // Set Stream Mode
  229. // initialize decoder
  230. Stat = pHwDevExt->DAck.PCIF_RESET();
  231. if( Stat != STATUS_SUCCESS ) {
  232. DebugPrint( (DebugLevelTrace, "TOSDVD:illegal config info") );
  233. pSrb->Status = STATUS_IO_DEVICE_ERROR;
  234. return FALSE;
  235. }
  236. pHwDevExt->VDec.VIDEO_RESET();
  237. pHwDevExt->VPro.VPRO_RESET_FUNC();
  238. pHwDevExt->VPro.SUBP_RESET_FUNC();
  239. // pHwDevExt->DAck.PCIF_INIT();
  240. // WRITE_PORT_UCHAR( ioBase + PCIF_CNTL, 0x10 );
  241. pHwDevExt->CPgd.CPGD_RESET_FUNC();
  242. // pHwDevExt->DAck.PCIF_DMA_ABORT();
  243. //
  244. // // check end abort
  245. // // Bad Coding !!!!!!!
  246. // for( ; ; ) {
  247. // UCHAR val;
  248. //
  249. // val = READ_PORT_UCHAR( ioBase + PCIF_INTF );
  250. // if( !( val & 0x04 ) )
  251. // break;
  252. // }
  253. pHwDevExt->VDec.VIDEO_ALL_INT_OFF();
  254. pHwDevExt->DAck.PCIF_VSYNC_ON();
  255. pHwDevExt->VDec.VIDEO_MODE_DVD( );
  256. pHwDevExt->DAck.PCIF_PACK_START_ON();
  257. // pHwDevExt->VDec.VIDEO_USER_INT_ON();
  258. // Set Display Mode
  259. pHwDevExt->VDec.VIDEO_OUT_NTSC();
  260. pHwDevExt->VPro.VPRO_INIT_NTSC();
  261. pHwDevExt->CPgd.CPGD_INIT_NTSC();
  262. pHwDevExt->DAck.PCIF_ASPECT_0403();
  263. pHwDevExt->VPro.VPRO_VIDEO_MUTE_OFF();
  264. pHwDevExt->CPgd.CPGD_VIDEO_MUTE_OFF();
  265. // Set Digital Out
  266. pHwDevExt->VideoPort = 0; // Disable
  267. pHwDevExt->DAck.PCIF_SET_DIGITAL_OUT( pHwDevExt->VideoPort );
  268. // Set Digital Palette
  269. // UCHAR paldata[256];
  270. // ULONG l;
  271. //
  272. // for( l = 0; l < 256; l++ )
  273. // paldata[l] = (UCHAR)l;
  274. //
  275. // pHwDevExt->DAck.PCIF_SET_PALETTE( PALETTE_Y, paldata );
  276. // pHwDevExt->DAck.PCIF_SET_PALETTE( PALETTE_Cb, paldata );
  277. // pHwDevExt->DAck.PCIF_SET_PALETTE( PALETTE_Cr, paldata );
  278. BOOLEAN bStatus;
  279. bStatus = pHwDevExt->CPro.reset( NO_GUARD );
  280. ASSERTMSG( "\r\n...CPro Status Error!!( reset )", bStatus );
  281. // Set Audio Mode
  282. if( pHwDevExt->AudioMode == AUDIO_TYPE_AC3 ) {
  283. pHwDevExt->VDec.VIDEO_PRSO_PS1();
  284. pHwDevExt->ADec.AUDIO_ZR38521_BOOT_AC3();
  285. pHwDevExt->ADec.AUDIO_ZR38521_CFG();
  286. pHwDevExt->ADec.AUDIO_ZR38521_AC3();
  287. pHwDevExt->ADec.AUDIO_ZR38521_KCOEF();
  288. pHwDevExt->ADec.AUDIO_TC6800_INIT_AC3();
  289. pHwDevExt->VPro.SUBP_SELECT_AUDIO_SSID();
  290. }
  291. else if( pHwDevExt->AudioMode == AUDIO_TYPE_PCM ) {
  292. pHwDevExt->VDec.VIDEO_PRSO_PS1();
  293. pHwDevExt->ADec.AUDIO_ZR38521_BOOT_PCM();
  294. pHwDevExt->ADec.AUDIO_ZR38521_CFG();
  295. pHwDevExt->ADec.AUDIO_ZR38521_PCMX();
  296. pHwDevExt->ADec.AUDIO_TC6800_INIT_PCM();
  297. pHwDevExt->VPro.SUBP_SELECT_AUDIO_SSID();
  298. }
  299. else
  300. TRAP;
  301. pHwDevExt->ADec.AUDIO_ZR38521_REPEAT_16();
  302. pHwDevExt->ADec.AUDIO_TC9425_INIT_DIGITAL();
  303. pHwDevExt->ADec.AUDIO_TC9425_INIT_ANALOG();
  304. pHwDevExt->ADec.AUDIO_ZR38521_MUTE_OFF();
  305. // AudioType Analog
  306. pHwDevExt->DAck.PCIF_AMUTE2_OFF();
  307. pHwDevExt->DAck.PCIF_AMUTE_OFF();
  308. // NTSC Copy Gaurd
  309. {
  310. BOOL ACGstatus;
  311. ACGstatus = pHwDevExt->CPgd.CPGD_SET_AGC_CHIP( pHwDevExt->RevID );
  312. ASSERTMSG( "\r\n...Analog Copy Guard Error!!", ACGstatus );
  313. // NTSC Analog Copy Guard Default Setting for Windows98 Beta 3
  314. // Aspect Ratio 4:3
  315. // Letter Box OFF
  316. // CGMS 3 ( No Copying is permitted )
  317. // APS 2 ( AGC pulse ON, Burst Inv ON (2line) )
  318. pHwDevExt->CPgd.CPGD_SET_CGMSnCPGD( 0, 0, 3, 2 );
  319. }
  320. //--- 97.09.23 K.Chujo; Closed Caption
  321. USCC_on( pHwDevExt );
  322. //--- End.
  323. DebugPrint( (DebugLevelTrace, "TOSDVD:HwInitialize() exit\r\n") );
  324. pSrb->Status = STATUS_SUCCESS;
  325. return TRUE;
  326. }