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.

275 lines
6.6 KiB

  1. /**************************************************************************
  2. AVStream Simulated Hardware Sample
  3. Copyright (c) 2001, Microsoft Corporation.
  4. File:
  5. hwsim.cpp
  6. Abstract:
  7. This file is the hardware simulation header.
  8. The simulation fakes "DMA" transfers, scatter gather mapping handling,
  9. ISR's, etc... The ISR routine in here will be called when an ISR
  10. would be generated by the fake hardware and it will directly call into
  11. the device level ISR for more accurate simulation.
  12. History:
  13. created 3/9/2001
  14. **************************************************************************/
  15. //
  16. // SCATTER_GATHER_MAPPINGS_MAX:
  17. //
  18. // The maximum number of entries in the hardware's scatter/gather list. I
  19. // am making this so large for a few reasons:
  20. //
  21. // 1) we're faking this with uncompressed surfaces --
  22. // these are large buffers which will map to a lot of s/g entries
  23. // 2) the fake hardware implementation requires at least one frame's
  24. // worth of s/g entries to generate a frame
  25. //
  26. #define SCATTER_GATHER_MAPPINGS_MAX 128
  27. //
  28. // SCATTER_GATHER_ENTRY:
  29. //
  30. // This structure is used to keep the scatter gather table for the fake
  31. // hardware as a doubly linked list.
  32. //
  33. typedef struct _SCATTER_GATHER_ENTRY {
  34. LIST_ENTRY ListEntry;
  35. PUCHAR Virtual;
  36. ULONG ByteCount;
  37. } SCATTER_GATHER_ENTRY, *PSCATTER_GATHER_ENTRY;
  38. //
  39. // CHardwareSimulation:
  40. //
  41. // The hardware simulation class.
  42. //
  43. class CHardwareSimulation {
  44. private:
  45. //
  46. // The transport stream synthesizer. This is a piece of code which
  47. // fills in the requested transport stream.
  48. //
  49. CTsSynthesizer *m_TsSynth;
  50. //
  51. // The synthesis buffer. This is a private buffer we use to generate the
  52. // transport stream in. The fake "scatter / gather" mappings are filled
  53. // in from this buffer during each interrupt.
  54. //
  55. PUCHAR m_SynthesisBuffer;
  56. //
  57. // Key information regarding the frames we generate.
  58. //
  59. LONGLONG m_TimePerFrame;
  60. ULONG m_PacketSize;
  61. ULONG m_PacketsPerSample;
  62. ULONG m_SampleSize;
  63. //
  64. // Scatter gather mappings for the simulated hardware.
  65. //
  66. KSPIN_LOCK m_ListLock;
  67. LIST_ENTRY m_ScatterGatherMappings;
  68. //
  69. // Lookaside for memory for the scatter / gather entries on the scatter /
  70. // gather list.
  71. //
  72. NPAGED_LOOKASIDE_LIST m_ScatterGatherLookaside;
  73. //
  74. // The current state of the fake hardware.
  75. //
  76. HARDWARE_STATE m_HardwareState;
  77. //
  78. // The pause / stop hardware flag and event.
  79. //
  80. BOOLEAN m_StopHardware;
  81. KEVENT m_HardwareEvent;
  82. //
  83. // Maximum number of scatter / gather mappins in the s/g table of the
  84. // fake hardware.
  85. //
  86. ULONG m_ScatterGatherMappingsMax;
  87. //
  88. // Number of scatter / gather mappings that have been completed (total)
  89. // since the start of the hardware or any reset.
  90. //
  91. ULONG m_NumMappingsCompleted;
  92. //
  93. // Number of scatter / gather mappings that are queued for this hardware.
  94. //
  95. ULONG m_ScatterGatherMappingsQueued;
  96. ULONG m_ScatterGatherBytesQueued;
  97. //
  98. // Number of frames skipped due to lack of scatter / gather mappings.
  99. //
  100. ULONG m_NumFramesSkipped;
  101. //
  102. // The "Interrupt Time". Number of "fake" interrupts that have occurred
  103. // since the hardware was started.
  104. //
  105. ULONG m_InterruptTime;
  106. //
  107. // The system time at start.
  108. //
  109. LARGE_INTEGER m_StartTime;
  110. //
  111. // The DPC used to "fake" ISR
  112. //
  113. KDPC m_IsrFakeDpc;
  114. KTIMER m_IsrTimer;
  115. //
  116. // The hardware sink that will be used for interrupt notifications.
  117. //
  118. IHardwareSink *m_HardwareSink;
  119. //
  120. // FakeHardware():
  121. //
  122. // Called from the simulated interrupt. First we fake the hardware's
  123. // actions (at DPC) then we call the "Interrupt service routine" on
  124. // the hardware sink.
  125. //
  126. void
  127. FakeHardware (
  128. );
  129. //
  130. // SimulatedInterrupt():
  131. //
  132. // This is the hardware's simulated interrupt. Really, it's just a DPC.
  133. // We'll use a spinlock instead of any KeSynchronizeExecutions.
  134. //
  135. static
  136. void
  137. SimulatedInterrupt (
  138. IN PKDPC Dpc,
  139. IN CHardwareSimulation *HardwareSim,
  140. IN PVOID SystemArg1,
  141. IN PVOID SystemArg2
  142. )
  143. {
  144. HardwareSim -> FakeHardware ();
  145. }
  146. //
  147. // FillScatterGatherBuffers():
  148. //
  149. // This is called by the hardware simulation to fill a series of scatter /
  150. // gather buffers with synthesized data.
  151. //
  152. NTSTATUS
  153. FillScatterGatherBuffers (
  154. );
  155. public:
  156. //
  157. // CHardwareSimulation():
  158. //
  159. // The hardware simulation constructor. Since the new operator will
  160. // have zeroed the memory, only initialize non-NULL, non-0 fields.
  161. //
  162. CHardwareSimulation (
  163. IN IHardwareSink *HardwareSink
  164. );
  165. //
  166. // ~CHardwareSimulation():
  167. //
  168. // The hardware simulation destructor.
  169. //
  170. ~CHardwareSimulation (
  171. )
  172. {
  173. }
  174. //
  175. // Start():
  176. //
  177. // "Start" the fake hardware. This will start issuing interrupts and
  178. // DPC's.
  179. //
  180. // The sample rate, sample size, and a synthesizer must be provided.
  181. //
  182. NTSTATUS
  183. Start (
  184. CTsSynthesizer *TsSynth,
  185. IN LONGLONG TimePerSample,
  186. IN ULONG PacketWidth,
  187. IN ULONG PacketsPerSample
  188. );
  189. //
  190. // Pause():
  191. //
  192. // "Pause" or "unpause" the fake hardware. This will stop issuing
  193. // interrupts or DPC's on a pause and restart them on an unpause. Note
  194. // that this will not reset counters as a Stop() would.
  195. //
  196. NTSTATUS
  197. Pause (
  198. IN BOOLEAN Pausing
  199. );
  200. //
  201. // Stop():
  202. //
  203. // "Stop" the fake hardware. This will stop issuing interrupts and
  204. // DPC's.
  205. //
  206. NTSTATUS
  207. Stop (
  208. );
  209. //
  210. // ProgramScatterGatherMappings():
  211. //
  212. // Program a series of scatter gather mappings into the fake hardware.
  213. //
  214. ULONG
  215. ProgramScatterGatherMappings (
  216. IN PUCHAR *Buffer,
  217. IN PKSMAPPING Mappings,
  218. IN ULONG MappingsCount,
  219. IN ULONG MappingStride
  220. );
  221. //
  222. // ReadNumberOfMappingsCompleted():
  223. //
  224. // Read the number of mappings completed since the last hardware reset.
  225. //
  226. ULONG
  227. ReadNumberOfMappingsCompleted (
  228. );
  229. };