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.

1139 lines
27 KiB

  1. /*******************************************************************
  2. *
  3. * MPINIT.C
  4. *
  5. * Copyright (C) 1995 SGS-THOMSON Microelectronics.
  6. *
  7. *
  8. * PORT/MINIPORT Interface init routines
  9. *
  10. *******************************************************************/
  11. #include "common.h"
  12. #include "strmini.h"
  13. #include <ntddk.h>
  14. #include <windef.h>
  15. #include "ksguid.h"
  16. #include "uuids.h"
  17. #include "mpeg2ids.h"
  18. #include "mpinit.h"
  19. #include "mpst.h"
  20. #include "mpvideo.h"
  21. #include "mpaudio.h"
  22. #include "debug.h"
  23. #include "mpegprop.h"
  24. #include "mpegguid.h"
  25. #include "dmpeg.h"
  26. #define DMA_BUFFER_SIZE 8192
  27. // Few globals here, should be put in the
  28. // structure
  29. BOOL bInitialized = FALSE;
  30. VOID STREAMAPI StreamReceiveAudioPacket(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  31. VOID DummyTime(PHW_DEVICE_EXTENSION de);
  32. VOID DummyHigh(PHW_DEVICE_EXTENSION de);
  33. VOID DummyLow(PHW_DEVICE_EXTENSION de);
  34. /********************************************************************
  35. * Function Name : DriverEntry
  36. * Args : Context1 and Context2
  37. * Returns : Return of MpegPortInitialize
  38. * Purpose : Entry Point into the MINIPORT Driver.
  39. *
  40. * Revision History : Last modified on 25/8/95 by JBS
  41. ********************************************************************/
  42. ULONG DriverEntry ( PVOID Arg1, PVOID Arg2 )
  43. {
  44. HW_INITIALIZATION_DATA HwInitData;
  45. DebugPrint((DebugLevelVerbose,"ST MPEG2 MiniDriver DriverEntry"));
  46. // MpegPortZeroMemory(&HwInitData, sizeof(HwInitData));
  47. HwInitData.HwInitializationDataSize = sizeof(HwInitData);
  48. //
  49. // Entry points for Port Driver
  50. //
  51. HwInitData.HwUnInitialize = HwUnInitialize;
  52. HwInitData.HwInterrupt = HwInterrupt;
  53. HwInitData.HwReceivePacket = AdapterReceivePacket;
  54. HwInitData.HwCancelPacket = AdapterCancelPacket;
  55. HwInitData.HwRequestTimeoutHandler = AdapterTimeoutPacket;
  56. HwInitData.DeviceExtensionSize = sizeof(HW_DEVICE_EXTENSION);
  57. HwInitData.PerRequestExtensionSize = sizeof(MRP_EXTENSION);
  58. HwInitData.FilterInstanceExtensionSize = 0;
  59. HwInitData.PerStreamExtensionSize = sizeof(STREAMEX); // random size for code testing
  60. HwInitData.BusMasterDMA = FALSE;
  61. HwInitData.Dma24BitAddresses = FALSE;
  62. HwInitData.BufferAlignment = 3;
  63. HwInitData.TurnOffSynchronization = FALSE;
  64. HwInitData.DmaBufferSize = DMA_BUFFER_SIZE;
  65. DebugPrint((DebugLevelVerbose,"SGS: call to portinitialize"));
  66. return (StreamClassRegisterAdapter(Arg1, Arg2,&HwInitData));
  67. }
  68. VOID AdapterCancelPacket(PHW_STREAM_REQUEST_BLOCK pSrb)
  69. {
  70. PHW_DEVICE_EXTENSION pdevex = (PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension;
  71. BOOL fRestart = FALSE; // determines whether this requires a restart
  72. BOOL fReset = FALSE; // indicates we need to reset the device
  73. PHW_STREAM_REQUEST_BLOCK pSrbTmp;
  74. //
  75. // need to find this packet, pull it off our queues, and cancel it
  76. //
  77. if (pdevex->pCurSrb == pSrb)
  78. {
  79. pdevex->pCurSrb = NULL;
  80. fRestart = TRUE;
  81. }
  82. //
  83. // look for it in the main device queues
  84. //
  85. for (pSrbTmp = CONTAINING_RECORD((&(pdevex->pSrbQ)),
  86. HW_STREAM_REQUEST_BLOCK, NextSRB);
  87. pSrbTmp->NextSRB && pSrbTmp->NextSRB != pSrb;
  88. pSrbTmp = pSrbTmp->NextSRB);
  89. if (pSrbTmp->NextSRB ==pSrb)
  90. {
  91. TRAP
  92. pSrbTmp->NextSRB == pSrb->NextSRB;
  93. }
  94. if (pdevex->VideoDeviceExt.pCurrentSRB == pSrb)
  95. {
  96. StreamClassScheduleTimer(pSrb->StreamObject, pdevex,
  97. 0, VideoPacketStub, pSrb->StreamObject);
  98. pdevex->VideoDeviceExt.pCurrentSRB = NULL;
  99. //
  100. // cancel the video timer
  101. //
  102. fRestart = TRUE;
  103. fReset = TRUE;
  104. }
  105. if (pdevex->AudioDeviceExt.pCurrentSRB == pSrb)
  106. {
  107. TRAP
  108. pdevex->AudioDeviceExt.pCurrentSRB = NULL;
  109. fRestart = TRUE;
  110. }
  111. if (fReset)
  112. {
  113. miniPortVideoReset(pSrb, pSrb->HwDeviceExtension);
  114. }
  115. pSrb->Status = STATUS_CANCELLED;
  116. switch (pSrb->Flags & (SRB_HW_FLAGS_DATA_TRANSFER |
  117. SRB_HW_FLAGS_STREAM_REQUEST))
  118. {
  119. //
  120. // find all stream commands, and do stream notifications
  121. //
  122. case SRB_HW_FLAGS_STREAM_REQUEST | SRB_HW_FLAGS_DATA_TRANSFER:
  123. StreamClassStreamNotification(ReadyForNextStreamDataRequest,
  124. pSrb->StreamObject);
  125. StreamClassStreamNotification(StreamRequestComplete,
  126. pSrb->StreamObject,
  127. pSrb);
  128. break;
  129. case SRB_HW_FLAGS_STREAM_REQUEST:
  130. TRAP
  131. mpstCtrlCommandComplete(pSrb);
  132. break;
  133. default:
  134. //
  135. // must be a device request
  136. //
  137. StreamClassDeviceNotification(ReadyForNextDeviceRequest,
  138. pSrb->HwDeviceExtension);
  139. StreamClassDeviceNotification(DeviceRequestComplete,
  140. pSrb->HwDeviceExtension,
  141. pSrb);
  142. }
  143. if (fRestart)
  144. {
  145. StreamStartCommand(pdevex);
  146. }
  147. }
  148. VOID AdapterTimeoutPacket(PHW_STREAM_REQUEST_BLOCK pSrb)
  149. {
  150. //
  151. // if we timeout while playing, then we need to consider this
  152. // condition an error, and reset the hardware, and reset everything
  153. //
  154. TRAP
  155. //
  156. // if we are not playing, and this is a CTRL request, we still
  157. // need to reset everything
  158. //
  159. }
  160. VOID AdapterOpenStream(PHW_STREAM_REQUEST_BLOCK pSrb)
  161. {
  162. PSTREAMEX strm = (PSTREAMEX)pSrb->StreamObject->HwStreamExtension;
  163. //
  164. // for now, just return success
  165. //
  166. pSrb->Status = STATUS_SUCCESS;
  167. switch (pSrb->StreamObject->StreamNumber)
  168. {
  169. case 0:
  170. //
  171. // this is the video stream
  172. //
  173. strm->pfnWriteData = (PFN_WRITE_DATA)miniPortVideoPacket;
  174. strm->pfnSetState = (PFN_WRITE_DATA)miniPortSetState;
  175. strm->pfnGetProp = (PFN_WRITE_DATA)miniPortGetProperty;
  176. pSrb->StreamObject->ReceiveDataPacket = (PVOID)StreamReceiveDataPacket;
  177. break;
  178. case 1:
  179. //
  180. // this is the audio stream
  181. //
  182. strm->pfnWriteData = (PFN_WRITE_DATA)miniPortAudioPacket;
  183. pSrb->StreamObject->ReceiveDataPacket = (PVOID)StreamReceiveAudioPacket;
  184. strm->pfnSetState = (PFN_WRITE_DATA)miniPortAudioSetState;
  185. strm->pfnGetProp = (PFN_WRITE_DATA)miniPortAudioGetProperty;
  186. break;
  187. default:
  188. TRAP
  189. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  190. }
  191. pSrb->StreamObject->ReceiveControlPacket = (PVOID)StreamReceiveCtrlPacket;
  192. //pSrb->StreamObject->Dma = FALSE;
  193. pSrb->StreamObject->Pio = TRUE;
  194. StreamClassDeviceNotification(ReadyForNextDeviceRequest,
  195. pSrb->HwDeviceExtension);
  196. StreamClassDeviceNotification(DeviceRequestComplete,
  197. pSrb->HwDeviceExtension,
  198. pSrb);
  199. /*
  200. //
  201. // switch on GUID
  202. //
  203. default:
  204. //
  205. // we don't own this GUID, so just fail the open stream
  206. // call
  207. //
  208. */
  209. }
  210. VOID STREAMAPI AdapterReceivePacket(IN PHW_STREAM_REQUEST_BLOCK pSrb)
  211. {
  212. PHW_DEVICE_EXTENSION pdevext =
  213. ((PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension);
  214. //
  215. // determine the type of packet.
  216. //
  217. switch (pSrb->Command)
  218. {
  219. case SRB_OPEN_STREAM:
  220. AdapterOpenStream(pSrb);
  221. break;
  222. case SRB_GET_STREAM_INFO:
  223. AdapterStreamInfo(pSrb);
  224. break;
  225. case SRB_INITIALIZE_DEVICE:
  226. HwInitialize(pSrb);
  227. break;
  228. case SRB_TURN_POWER_ON:
  229. case SRB_TURN_POWER_OFF:
  230. pSrb->Status = STATUS_SUCCESS;
  231. StreamClassDeviceNotification(ReadyForNextDeviceRequest,
  232. pSrb->HwDeviceExtension);
  233. StreamClassDeviceNotification(DeviceRequestComplete,
  234. pSrb->HwDeviceExtension,
  235. pSrb);
  236. break;
  237. default:
  238. TRAP
  239. pSrb->Status = STATUS_NOT_SUPPORTED;
  240. StreamClassDeviceNotification(ReadyForNextDeviceRequest,
  241. pSrb->HwDeviceExtension);
  242. StreamClassDeviceNotification(DeviceRequestComplete,
  243. pSrb->HwDeviceExtension,
  244. pSrb);
  245. }
  246. /*
  247. //
  248. // switch on GUID
  249. //
  250. default:
  251. //
  252. // we don't own this GUID, so just fail the open stream
  253. // call
  254. //
  255. */
  256. }
  257. KSDATAFORMAT hwfmtiMpeg2Vid
  258. = {
  259. sizeof (KSDATAFORMAT),
  260. 0,
  261. {0xe06d8020, 0xdb46, 0x11cf, 0xb4, 0xd1, 0x00, 0x80, 0x05f, 0x6c, 0xbb, 0xea},
  262. //MEDIATYPE_MPEG2_PES,
  263. // MEDIASUBTYPE_MPEG2_VIDEO,
  264. {0xe06d8026, 0xdb46, 0x11cf, 0xb4, 0xd1, 0x00, 0x80, 0x05f, 0x6c, 0xbb, 0xea},
  265. //FORMAT_MPEG2Video,
  266. {0xe06d80e3, 0xdb46, 0x11cf, 0xb4, 0xd1, 0x00, 0x80, 0x05f, 0x6c, 0xbb, 0xea}
  267. };
  268. KSDATAFORMAT hwfmtiMpeg2Aud
  269. = {
  270. sizeof (KSDATAFORMAT),
  271. 0,
  272. //MEDIATYPE_MPEG2_PES,
  273. {0xe06d8020, 0xdb46, 0x11cf, 0xb4, 0xd1, 0x00, 0x80, 0x05f, 0x6c, 0xbb, 0xea},
  274. //MEDIASUBTYPE_DOLBY_AC3_AUDIO,
  275. {0xe06d802c, 0xdb46, 0x11cf, 0xb4, 0xd1, 0x00, 0x80, 0x05f, 0x6c, 0xbb, 0xea},
  276. //FORMAT_WaveFormatEx
  277. {0x05589f81, 0xc356, 0x11ce, 0xbf, 0x01, 0x00, 0xaa, 0x000, 0x55, 0x59, 0x5a},
  278. };
  279. KSDATAFORMAT hwfmtiMpeg2Out;
  280. /* = {
  281. };
  282. */
  283. static const KSPROPERTY_ITEM mpegVidPropItm[]={
  284. {0,
  285. TRUE,
  286. sizeof (KSPROPERTY),
  287. sizeof (BUF_LVL_DATA),
  288. FALSE,
  289. 0,
  290. 0,
  291. NULL,
  292. 0,
  293. NULL
  294. }};
  295. static const KSPROPERTY_SET mpegVidPropSet[] = {
  296. &KSPROPSETID_Mpeg2Vid,
  297. SIZEOF_ARRAY(mpegVidPropItm),
  298. (PKSPROPERTY_ITEM)mpegVidPropItm
  299. };
  300. VOID AdapterStreamInfo(PHW_STREAM_REQUEST_BLOCK pSrb)
  301. {
  302. PHW_DEVICE_EXTENSION pdevext =
  303. ((PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension);
  304. PHW_STREAM_INFORMATION pstrinfo = &(pSrb->CommandData.StreamBuffer->StreamInfo);
  305. PBOOLEAN RelatedStreams;
  306. ULONG ulTmp;
  307. pSrb->CommandData.StreamBuffer->StreamHeader.NumberOfStreams = 3;
  308. //
  309. // set up the stream info structures for the MPEG2 video
  310. //
  311. pstrinfo->NumberOfPossibleInstances = 1;
  312. pstrinfo->DataFlow = KSPIN_DATAFLOW_IN;
  313. pstrinfo->DataAccessible = TRUE;
  314. pstrinfo->FormatInfo = &hwfmtiMpeg2Vid;
  315. RelatedStreams = (PBOOLEAN) (pstrinfo+
  316. pSrb->CommandData.StreamBuffer->StreamHeader.NumberOfStreams);
  317. pstrinfo->RelatedStreams = RelatedStreams;
  318. RelatedStreams[0] = TRUE; // related to self
  319. RelatedStreams[1] = FALSE;
  320. RelatedStreams[2] = TRUE;
  321. RelatedStreams += 4;
  322. //
  323. // set the property information
  324. //
  325. pstrinfo->NumStreamPropArrayEntries = 0;
  326. pstrinfo->StreamPropertiesArray = mpegVidPropSet;
  327. pstrinfo++;
  328. //
  329. // set up the stream info structures for the MPEG2 audio
  330. //
  331. pstrinfo->NumberOfPossibleInstances = 1;
  332. pstrinfo->DataFlow = KSPIN_DATAFLOW_IN;
  333. pstrinfo->DataAccessible = TRUE;
  334. pstrinfo->FormatInfo = &hwfmtiMpeg2Aud;
  335. pstrinfo->RelatedStreams = RelatedStreams;
  336. pstrinfo->RelatedStreams[0] = FALSE;
  337. pstrinfo->RelatedStreams[1] = TRUE; // related to self
  338. pstrinfo->RelatedStreams[2] = TRUE;
  339. RelatedStreams += 4;
  340. pstrinfo++;
  341. //
  342. // set up the stream info structures for the MPEG2 NTSC stream
  343. //
  344. pstrinfo->NumberOfPossibleInstances = 1;
  345. pstrinfo->DataFlow = KSPIN_DATAFLOW_OUT;
  346. pstrinfo->DataAccessible = FALSE;
  347. pstrinfo->FormatInfo = &hwfmtiMpeg2Out;
  348. pstrinfo->RelatedStreams = RelatedStreams;
  349. pstrinfo->RelatedStreams[0] = TRUE;
  350. pstrinfo->RelatedStreams[1] = TRUE;
  351. pstrinfo->RelatedStreams[2] = TRUE; // related to self
  352. pSrb->Status = STATUS_SUCCESS;
  353. StreamClassDeviceNotification(ReadyForNextDeviceRequest,
  354. pSrb->HwDeviceExtension);
  355. StreamClassDeviceNotification(DeviceRequestComplete,
  356. pSrb->HwDeviceExtension,
  357. pSrb);
  358. }
  359. VOID STREAMAPI StreamReceiveDataPacket(IN PHW_STREAM_REQUEST_BLOCK pSrb)
  360. {
  361. PHW_DEVICE_EXTENSION pdevext =
  362. ((PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension);
  363. // DEBUG_ASSERT(pdevext);
  364. //
  365. // determine the type of packet.
  366. //
  367. switch (pSrb->Command)
  368. {
  369. case SRB_WRITE_DATA:
  370. //
  371. // put it on the queue, and start dequeing if necessary
  372. //
  373. Enqueue(pSrb, pdevext);
  374. if (!pdevext->pCurSrb)
  375. {
  376. StreamStartCommand(pdevext);
  377. }
  378. break;
  379. default:
  380. //
  381. // invalid / unsupported command. Fail it as such
  382. //
  383. TRAP
  384. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  385. StreamClassStreamNotification(ReadyForNextStreamDataRequest,
  386. pSrb->StreamObject);
  387. StreamClassStreamNotification(StreamRequestComplete,
  388. pSrb->StreamObject,
  389. pSrb);
  390. }
  391. }
  392. VOID STREAMAPI StreamReceiveAudioPacket(IN PHW_STREAM_REQUEST_BLOCK pSrb)
  393. {
  394. PHW_DEVICE_EXTENSION pdevext =
  395. ((PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension);
  396. //
  397. // determine the type of packet.
  398. //
  399. pSrb->Status = STATUS_SUCCESS;
  400. ((PSTREAMEX)pSrb->StreamObject->HwStreamExtension)
  401. ->pfnWriteData(pSrb);
  402. }
  403. VOID STREAMAPI StreamReceiveCtrlPacket(IN PHW_STREAM_REQUEST_BLOCK pSrb)
  404. {
  405. PHW_DEVICE_EXTENSION pdevext =
  406. ((PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension);
  407. // DEBUG_ASSERT(pdevext);
  408. //
  409. // determine the type of packet.
  410. //
  411. switch (pSrb->Command)
  412. {
  413. case SRB_SET_STREAM_STATE:
  414. ((PSTREAMEX)pSrb->StreamObject->HwStreamExtension)
  415. ->pfnSetState(pSrb);
  416. break;
  417. case SRB_GET_STREAM_PROPERTY:
  418. ((PSTREAMEX)pSrb->StreamObject->HwStreamExtension)
  419. ->pfnGetProp(pSrb);
  420. break;
  421. default:
  422. //
  423. // invalid / unsupported command. Fail it as such
  424. //
  425. TRAP
  426. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  427. mpstCtrlCommandComplete(pSrb);
  428. }
  429. }
  430. VOID mpstCtrlCommandComplete(PHW_STREAM_REQUEST_BLOCK pSrb)
  431. {
  432. StreamClassStreamNotification(
  433. ReadyForNextStreamControlRequest,
  434. pSrb->StreamObject);
  435. StreamClassStreamNotification(StreamRequestComplete,
  436. pSrb->StreamObject,
  437. pSrb);
  438. }
  439. #if 0
  440. VOID STREAMAPI StreamReceiveDataPacket(IN PHW_STREAM_REQUEST_BLOCK pSrb)
  441. {
  442. PHW_DEVICE_EXTENSION pdevext =
  443. ((PHW_DEVICE_EXTENSION)pSrb->HwDeviceExtension);
  444. DEBUG_ASSERT(pdevext);
  445. // determine the type of packet.
  446. //
  447. switch (pSrb->Command)
  448. {
  449. case SRB_WRITE_DATA:
  450. case SRB_SET_STREAM_STATE:
  451. //
  452. // put it on the queue, and start dequeing if necessary
  453. //
  454. Enqueue(pSrb, pdevext);
  455. if (!pdevext->pCurSrb)
  456. {
  457. StreamStartCommand(pdevext);
  458. }
  459. break;
  460. default:
  461. //
  462. // invalid / unsupported command. Fail it as such
  463. //
  464. TRAP
  465. pSrb->Status = STATUS_NOT_IMPLEMENTED;
  466. StreamClassStreamNotification(ReadyForNextStreamRequest,
  467. pSrb->StreamObject);
  468. StreamClassStreamNotification(StreamRequestComplete,
  469. pSrb->StreamObject,
  470. pSrb);
  471. }
  472. /*
  473. //
  474. // switch on GUID
  475. //
  476. default:
  477. //
  478. // we don't own this GUID, so just fail the open stream
  479. // call
  480. //
  481. */
  482. }
  483. #endif
  484. void Enqueue (PHW_STREAM_REQUEST_BLOCK pSrb,
  485. PHW_DEVICE_EXTENSION pdevext)
  486. {
  487. PHW_STREAM_REQUEST_BLOCK pSrbTmp;
  488. //
  489. // enqueue the given SRB on the device extension queue
  490. //
  491. for (pSrbTmp = CONTAINING_RECORD((&(pdevext->pSrbQ)),
  492. HW_STREAM_REQUEST_BLOCK, NextSRB);
  493. pSrbTmp->NextSRB;
  494. pSrbTmp = pSrbTmp->NextSRB);
  495. pSrbTmp->NextSRB = pSrb;
  496. pSrb->NextSRB = NULL;
  497. }
  498. PHW_STREAM_REQUEST_BLOCK Dequeue(PHW_DEVICE_EXTENSION pdevext)
  499. {
  500. PHW_STREAM_REQUEST_BLOCK pRet = NULL;
  501. if (pdevext->pSrbQ)
  502. {
  503. pRet = pdevext->pSrbQ;
  504. pdevext->pSrbQ = pRet->NextSRB;
  505. }
  506. return(pRet);
  507. }
  508. VOID StreamStartCommand (PHW_DEVICE_EXTENSION pdevext)
  509. {
  510. PHW_STREAM_REQUEST_BLOCK pSrb;
  511. //
  512. // See if there is something to dequeue
  513. //
  514. if (!(pSrb=Dequeue(pdevext)))
  515. {
  516. return;
  517. }
  518. pdevext->pCurSrb = pSrb;
  519. switch (pSrb->Command)
  520. {
  521. case SRB_WRITE_DATA:
  522. ((PSTREAMEX)pSrb->StreamObject->HwStreamExtension)
  523. ->pfnWriteData(pSrb);
  524. break;
  525. default:
  526. TRAP
  527. }
  528. }
  529. VOID AdapterCloseStream(PHW_STREAM_REQUEST_BLOCK pSrb)
  530. {
  531. DEBUG_BREAKPOINT();
  532. /*
  533. //
  534. // switch on GUID
  535. //
  536. default:
  537. //
  538. // we don't own this GUID, so just fail the open stream
  539. // call
  540. //
  541. */
  542. }
  543. /********************************************************************
  544. * Function Name : HwInitialize
  545. * Args : Pointer to Device Ext.
  546. * Returns : TRUE if sucessful, FALSE otherwise
  547. * Purpose : Initialize the Board, Setup IRQ, Initialize the
  548. * Control and Card structures.
  549. *
  550. * Revision History : Last modified on 19/8/95 by JBS
  551. ********************************************************************/
  552. NTSTATUS HwInitialize (
  553. IN PHW_STREAM_REQUEST_BLOCK pSrb)
  554. {
  555. NTSTATUS Stat;
  556. STREAM_PHYSICAL_ADDRESS adr;
  557. ULONG Size;
  558. ULONG i;
  559. PUCHAR pDmaBuf;
  560. PPORT_CONFIGURATION_INFORMATION ConfigInfo = pSrb->CommandData.ConfigInfo;
  561. PHW_DEVICE_EXTENSION pHwDevExt =
  562. (PHW_DEVICE_EXTENSION)ConfigInfo->HwDeviceExtension;
  563. DebugPrint((DebugLevelVerbose,"Entry : HwInitialize()\n"));
  564. bInitialized = TRUE;
  565. if (ConfigInfo->NumberOfAccessRanges < 1)
  566. {
  567. DebugPrint((DebugLevelVerbose,"ST3520: illegal config info"));
  568. pSrb->Status = STATUS_NO_SUCH_DEVICE;
  569. goto exit;
  570. }
  571. //
  572. // testing only !!!!
  573. //
  574. StreamClassCallAtNewPriority(NULL, pHwDevExt, Low, DummyLow, pHwDevExt);
  575. StreamClassScheduleTimer(NULL, pHwDevExt, 1*1000*1000, DummyTime, pHwDevExt);
  576. DebugPrint((DebugLevelVerbose, "No of access ranges = %lx", ConfigInfo->NumberOfAccessRanges));
  577. pHwDevExt->ioBaseLocal = (PUSHORT)(ConfigInfo->AccessRanges[0].RangeStart.LowPart);
  578. DebugPrint((DebugLevelVerbose, "Memory Range = %lx\n", pHwDevExt->ioBaseLocal));
  579. DebugPrint((DebugLevelVerbose, "IRQ = %lx\n", ConfigInfo->BusInterruptLevel));
  580. pHwDevExt->Irq = (USHORT)(ConfigInfo->BusInterruptLevel);
  581. pHwDevExt->VideoDeviceExt.videoSTC = 0;
  582. pHwDevExt->AudioDeviceExt.audioSTC = 0;
  583. pHwDevExt->AudioDeviceExt.pCurrentSRB = NULL;
  584. pHwDevExt->VideoDeviceExt.pCurrentSRB = NULL;
  585. pHwDevExt->VideoDeviceExt.DeviceState = -1;
  586. pHwDevExt->AudioDeviceExt.DeviceState = -1;
  587. pHwDevExt->AudioDeviceExt.pCurrentSRB = NULL;
  588. pHwDevExt->VideoDeviceExt.pCurrentSRB = NULL;
  589. pHwDevExt->VideoDeviceExt.pCurrentSRB = NULL;
  590. pHwDevExt->AudioDeviceExt.pCurrentSRB = NULL;
  591. pHwDevExt->VideoDeviceExt.DeviceState = KSSTATE_PAUSE;
  592. pHwDevExt->AudioDeviceExt.DeviceState = KSSTATE_PAUSE;
  593. ConfigInfo->StreamDescriptorSize = 3 * (sizeof (HW_STREAM_INFORMATION) +
  594. 4 * sizeof (BOOLEAN)) + sizeof (HW_STREAM_HEADER);
  595. Stat = STATUS_SUCCESS;
  596. pDmaBuf = StreamClassGetDmaBuffer(pHwDevExt);
  597. adr = StreamClassGetPhysicalAddress(pHwDevExt, NULL, pDmaBuf, DmaBuffer, &Size);
  598. if(dmpgOpen((ULONG)(pHwDevExt->ioBaseLocal), pDmaBuf, (ULONG)(adr.LowPart)))
  599. Stat = STATUS_SUCCESS;
  600. else
  601. Stat = STATUS_NO_SUCH_DEVICE;
  602. DebugPrint((DebugLevelVerbose,"Exit : HwInitialize()\n"));
  603. pSrb->Status = Stat;
  604. exit:
  605. StreamClassDeviceNotification(ReadyForNextDeviceRequest,
  606. pSrb->HwDeviceExtension);
  607. StreamClassDeviceNotification(DeviceRequestComplete,
  608. pSrb->HwDeviceExtension,
  609. pSrb);
  610. }
  611. VOID DummyLow(PHW_DEVICE_EXTENSION pHwDevEx)
  612. {
  613. ASSERT(KeGetCurrentIrql() < DISPATCH_LEVEL);
  614. StreamClassCallAtNewPriority(NULL, pHwDevEx, LowToHigh, DummyHigh, pHwDevEx);
  615. }
  616. VOID DummyHigh(PHW_DEVICE_EXTENSION de)
  617. {
  618. ASSERT(KeGetCurrentIrql() > DISPATCH_LEVEL);
  619. DebugPrint((DebugLevelError,"Went from Low to High!!!"));
  620. }
  621. VOID DummyTime(PHW_DEVICE_EXTENSION de)
  622. {
  623. ASSERT(KeGetCurrentIrql() > DISPATCH_LEVEL);
  624. DebugPrint((DebugLevelError,"Timer fired!!!"));
  625. }
  626. /********************************************************************
  627. * Function Name : HwUnInitialize
  628. * Args : Pointer to Device Ext.
  629. * Returns : TRUE if sucessful, FALSE otherwise
  630. * Purpose : Uninitialize the H/W and data initialized
  631. * by HwInitialize Function
  632. *
  633. * Revision History : Last modified on 15/7/95 JBS
  634. ********************************************************************/
  635. BOOLEAN HwUnInitialize ( IN PVOID DeviceExtension)
  636. {
  637. dmpgClose();
  638. return TRUE;
  639. }
  640. #if 0
  641. /********************************************************************
  642. * Function Name : HwFindAdapter
  643. * Args : Pointer to Device Ext, Bus Information, ArgString,
  644. * port configuration information, Again
  645. * Returns : MP_FOUND, NOT FOUND OR ERROR
  646. * Purpose : Finds the H/W Adapter on the system
  647. *
  648. * Revision History : Last modified on 15/7/95 by JBS
  649. ********************************************************************/
  650. MP_RETURN_CODES HwFindAdapter (
  651. IN PVOID DeviceExtension,
  652. IN PVOID HwContext,
  653. IN PVOID BusInformation,
  654. IN PCHAR ArgString,
  655. IN OUT PPORT_CONFIGURATION_INFORMATION ConfigInfo,
  656. OUT PBOOLEAN Again
  657. )
  658. {
  659. // Code to find the adapter has to be added. - JBS
  660. ULONG ioAddress;
  661. ULONG IrqLevel; // Temp code to be put in HW_DEV_EXT
  662. PUSHORT ioBase;
  663. PHW_DEVICE_EXTENSION pHwDevExt = (PHW_DEVICE_EXTENSION)DeviceExtension;
  664. *Again = FALSE; // Only one card is allowed in the system
  665. DebugPrint((DebugLevelVerbose, "Entry : HwFindAparter()\n"));
  666. if(ConfigInfo->Length != sizeof(PORT_CONFIGURATION_INFORMATION))
  667. {
  668. DebugPrint((DebugLevelError,"Find Adapter : Different Size!!"));
  669. return MP_RETURN_BAD_CONFIG;
  670. }
  671. ConfigInfo->DmaChannels[VideoDevice].DmaChannel = MP_UNINITIALIZED_VALUE;
  672. ConfigInfo->DmaChannels[AudioDevice].DmaChannel = MP_UNINITIALIZED_VALUE;
  673. if(ConfigInfo->AccessRanges[0].RangeLength == 0){
  674. // IO Base was not specified in the registry
  675. DebugPrint((DebugLevelError, "FindAdapter: IO Base not specified\n"));
  676. return MP_RETURN_INSUFFICIENT_RESOURCES;
  677. }
  678. // DebugPrint((DebugLevelVerbose,"3520 Address Physical = %lx\n", ConfigInfo->AccessRanges[2].RangeStart));
  679. // DebugPrint((DebugLevelVerbose,"PCI9060 Address Physical = %lx\n", ConfigInfo->AccessRanges[1].RangeStart));
  680. ioAddress = MPEG_PORT_CONVERT_PHYSICAL_ADDRESS_TO_ULONG(
  681. ConfigInfo->AccessRanges[2].RangeStart
  682. );
  683. ConfigInfo->AccessRanges[0].RangeStart = ConfigInfo->AccessRanges[2].RangeStart ;
  684. DebugPrint((DebugLevelVerbose,"3520 Base Address = %lx\n", ioAddress));
  685. if( (ConfigInfo->Interrupts[VideoDevice].BusInterruptLevel == MP_UNINITIALIZED_VALUE) &&
  686. (ConfigInfo->Interrupts[AudioDevice].BusInterruptLevel == MP_UNINITIALIZED_VALUE) &&
  687. DebugPrint((DebugLevelError, "FindAdapter: Interrupt not specfied correctly\n"));
  688. return MP_RETURN_INVALID_INTERRUPT;
  689. }
  690. IrqLevel = ConfigInfo->Interrupts[VideoDevice].BusInterruptLevel;
  691. DebugPrint((DebugLevelVerbose,"Video Interrupt = %lx\n", IrqLevel));
  692. // ConfigInfo->Interrupts[AudioDevice].BusInterruptLevel = IrqLevel;
  693. ioBase = MpegPortGetDeviceBase(
  694. pHwDevExt, // HwDeviceExtension
  695. ConfigInfo->AdapterInterfaceType, // AdapterInterfaceType
  696. ConfigInfo->SystemIoBusNumber, // SystemIoBusNumber
  697. ConfigInfo->AccessRanges[0].RangeStart,
  698. 0x4, // NumberOfBytes
  699. TRUE // InIoSpace - Memory mapped
  700. );
  701. DebugPrint((DebugLevelVerbose,"3520 Base Address = %lx\n", ioBase));
  702. pHwDevExt->ioBaseLocal = ioBase;
  703. ioBase = MpegPortGetDeviceBase(
  704. pHwDevExt, // HwDeviceExtension
  705. ConfigInfo->AdapterInterfaceType, // AdapterInterfaceType
  706. ConfigInfo->SystemIoBusNumber, // SystemIoBusNumber
  707. ConfigInfo->AccessRanges[1].RangeStart,
  708. 0x4, // NumberOfBytes
  709. TRUE // InIoSpace - Memory mapped
  710. );
  711. DebugPrint((DebugLevelVerbose,"PCI9060 Address = %lx\n", ioBase));
  712. pHwDevExt->ioBasePCI9060 = ioBase;
  713. pHwDevExt->Irq = IrqLevel;
  714. pHwDevExt->VideoDeviceExt.videoSTC = 0;
  715. pHwDevExt->AudioDeviceExt.audioSTC = 0;
  716. pHwDevExt->AudioDeviceExt.pCurrentSRB = NULL;
  717. pHwDevExt->VideoDeviceExt.pCurrentSRB = NULL;
  718. pHwDevExt->VideoDeviceExt.DeviceState = -1;
  719. pHwDevExt->AudioDeviceExt.DeviceState = -1;
  720. pHwDevExt->AudioDeviceExt.pCurrentSRB = NULL;
  721. pHwDevExt->VideoDeviceExt.pCurrentSRB = NULL;
  722. DebugPrint((DebugLevelVerbose, "Exit : HwFindAparter()"));
  723. return MP_RETURN_FOUND;
  724. }
  725. #endif
  726. /********************************************************************
  727. * Function Name : HwInterrupt
  728. * Args : Pointer to Device Ext.
  729. * Returns : TRUE or FALSE
  730. * Purpose : Called by port driver if there is an interrupt
  731. * on the IRQ line. Must return False if it does not
  732. * Processes the interrupt
  733. *
  734. * Revision History : Last modified on 15/7/95 by JBS
  735. ********************************************************************/
  736. BOOLEAN HwInterrupt ( IN PVOID pDeviceExtension )
  737. {
  738. // Call the interrupt handler should check if the interrupt belongs to
  739. BOOLEAN bRetValue;
  740. if(!bInitialized)
  741. return FALSE;
  742. bRetValue = dmpgInterrupt();
  743. return bRetValue;
  744. }
  745. /********************************************************************
  746. * Function Name : HwStartIo
  747. * Args : Pointer to Device Ext, Mini-Port Request Block (MRB)
  748. * Returns : TRUE or FALSE
  749. * Purpose : Main fuction which accepts the MRBs from port Driver
  750. * Port driver calls this function for all the commands
  751. * it wants to execute
  752. *
  753. * Revision History : Last modified on 15/7/95 JBS
  754. ********************************************************************/
  755. BOOLEAN HwStartIo (
  756. IN PVOID DeviceExtension,
  757. PHW_STREAM_REQUEST_BLOCK pMrb
  758. )
  759. {
  760. pMrb->Status = STATUS_SUCCESS;
  761. switch (pMrb->Command)
  762. {
  763. #if 0
  764. case MrbCommandAudioCancel :
  765. miniPortCancelAudio(pMrb, (PHW_DEVICE_EXTENSION)DeviceExtension);
  766. break;
  767. case MrbCommandVideoCancel :
  768. miniPortCancelVideo(pMrb, (PHW_DEVICE_EXTENSION)DeviceExtension);
  769. break;
  770. case MrbCommandVideoClearBuffer :
  771. miniPortClearVideoBuffer(pMrb, (PHW_DEVICE_EXTENSION)DeviceExtension);
  772. break;
  773. case MrbCommandAudioEndOfStream :
  774. miniPortAudioEndOfStream(pMrb, (PHW_DEVICE_EXTENSION)DeviceExtension);
  775. break;
  776. case MrbCommandVideoEndOfStream :
  777. miniPortVideoEndOfStream(pMrb, (PHW_DEVICE_EXTENSION)DeviceExtension);
  778. break;
  779. case MrbCommandAudioGetProperty :
  780. miniPortAudioGetAttribute (pMrb, (PHW_DEVICE_EXTENSION)DeviceExtension);
  781. break;
  782. case MrbCommandVideoGetProperty :
  783. miniPortVideoGetAttribute (pMrb, (PHW_DEVICE_EXTENSION)DeviceExtension);
  784. break;
  785. case MrbCommandAudioGetOnboardClock :
  786. miniPortAudioGetStc(pMrb, (PHW_DEVICE_EXTENSION)DeviceExtension);
  787. break;
  788. case MrbCommandVideoGetOnboardClock :
  789. miniPortVideoGetStc(pMrb, (PHW_DEVICE_EXTENSION)DeviceExtension);
  790. break;
  791. case MrbCommandAudioPacket :
  792. miniPortAudioPacket(pMrb, (PHW_DEVICE_EXTENSION)DeviceExtension);
  793. break;
  794. case MrbCommandVideoPacket :
  795. miniPortVideoPacket(pMrb, (PHW_DEVICE_EXTENSION)DeviceExtension);
  796. break;
  797. case MrbCommandAudioPause :
  798. miniPortAudioPause(pMrb, (PHW_DEVICE_EXTENSION)DeviceExtension);
  799. break;
  800. case MrbCommandVideoPause :
  801. miniPortVideoPause(pMrb, (PHW_DEVICE_EXTENSION)DeviceExtension);
  802. break;
  803. case MrbCommandAudioPlay :
  804. miniPortAudioPlay(pMrb, (PHW_DEVICE_EXTENSION)DeviceExtension);
  805. break;
  806. case MrbCommandVideoPlay :
  807. miniPortVideoPlay(pMrb, (PHW_DEVICE_EXTENSION)DeviceExtension);
  808. break;
  809. case MrbCommandAudioQueryDevice :
  810. miniPortAudioQueryInfo (pMrb, (PHW_DEVICE_EXTENSION)DeviceExtension);
  811. break;
  812. case MrbCommandVideoQueryDevice :
  813. miniPortVideoQueryInfo (pMrb, (PHW_DEVICE_EXTENSION)DeviceExtension);
  814. break;
  815. case MrbCommandAudioReset :
  816. miniPortAudioReset (pMrb, (PHW_DEVICE_EXTENSION)DeviceExtension);
  817. break;
  818. case MrbCommandVideoReset :
  819. miniPortVideoReset (pMrb, (PHW_DEVICE_EXTENSION)DeviceExtension);
  820. break;
  821. case MrbCommandAudioSetProperty :
  822. miniPortAudioSetAttribute ( pMrb , (PHW_DEVICE_EXTENSION)DeviceExtension);
  823. break;
  824. case MrbCommandAudioUpdateOnboardClock :
  825. miniPortAudioSetStc ( pMrb , (PHW_DEVICE_EXTENSION)DeviceExtension);
  826. break;
  827. case MrbCommandVideoUpdateOnboardClock :
  828. miniPortVideoSetStc ( pMrb, (PHW_DEVICE_EXTENSION)DeviceExtension);
  829. break;
  830. case MrbCommandAudioStop :
  831. miniPortAudioStop( pMrb , (PHW_DEVICE_EXTENSION)DeviceExtension);
  832. break;
  833. case MrbCommandVideoStop :
  834. miniPortVideoStop( pMrb , (PHW_DEVICE_EXTENSION)DeviceExtension);
  835. break;
  836. #endif
  837. }
  838. return TRUE;
  839. }
  840. VOID HostDisableIT(VOID)
  841. {
  842. // Has to be implemented !! - JBS
  843. }
  844. VOID HostEnableIT(VOID)
  845. {
  846. // Has to be implemented !! - JBS
  847. }
  848. 
  849.