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.

216 lines
5.8 KiB

  1. /*****************************************************************************
  2. * adapter.cpp - DMusic adapter implementation
  3. *
  4. * This includes the adapter driver for the
  5. * kernel mode DirectMusic DLS 1.0 SW synthesizer
  6. *
  7. *****************************************************************************
  8. * Copyright (c) 1998-2000 Microsoft Corporation. All rights reserved.
  9. *
  10. * 06/08/98 MartinP
  11. *
  12. */
  13. //
  14. // All the GUIDS for all the miniports end up in this object.
  15. //
  16. #define PUT_GUIDS_HERE
  17. #define STR_MODULENAME "DDKSynth.sys:Adapter: "
  18. #define PC_NEW_NAMES 1
  19. #include "common.h"
  20. #include "private.h"
  21. /*****************************************************************************
  22. * Defines
  23. */
  24. #define MAX_MINIPORTS 1
  25. #if (DBG)
  26. #define SUCCEEDS(s) ASSERT(NT_SUCCESS(s))
  27. #else
  28. #define SUCCEEDS(s) (s)
  29. #endif
  30. /*****************************************************************************
  31. * Referenced forward
  32. */
  33. NTSTATUS
  34. AddDevice
  35. (
  36. IN PVOID Context1, // Context for the class driver.
  37. IN PVOID Context2 // Context for the class driver.
  38. );
  39. NTSTATUS
  40. StartDevice
  41. (
  42. IN PDEVICE_OBJECT pDeviceObject, // Context for the class driver.
  43. IN PIRP pIrp, // Context for the class driver.
  44. IN PRESOURCELIST ResourceList // List of hardware resources.
  45. );
  46. #pragma code_seg("INIT")
  47. /*****************************************************************************
  48. * DriverEntry()
  49. *****************************************************************************
  50. * This function is called by the operating system when the driver is loaded.
  51. * All adapter drivers can use this code without change.
  52. */
  53. extern "C"
  54. NTSTATUS
  55. DriverEntry
  56. (
  57. IN PVOID Context1, // Context for the class driver.
  58. IN PVOID Context2 // Context for the class driver.
  59. )
  60. {
  61. PAGED_CODE();
  62. _DbgPrintF(DEBUGLVL_VERBOSE, ("DriverEntry"));
  63. //
  64. // Tell the class driver to initialize the driver.
  65. //
  66. return PcInitializeAdapterDriver((PDRIVER_OBJECT)Context1,
  67. (PUNICODE_STRING)Context2,
  68. (PDRIVER_ADD_DEVICE)AddDevice);
  69. }
  70. #pragma code_seg()
  71. /*****************************************************************************
  72. * AddDevice()
  73. *****************************************************************************
  74. * This function is called by the operating system when the device is added.
  75. * All adapter drivers can use this code without change.
  76. */
  77. NTSTATUS
  78. AddDevice
  79. (
  80. IN PVOID Context1, // Context for the class driver.
  81. IN PVOID Context2 // Context for the class driver.
  82. )
  83. {
  84. PAGED_CODE();
  85. _DbgPrintF(DEBUGLVL_VERBOSE, ("AddDevice"));
  86. //
  87. // Tell the class driver to add the device.
  88. //
  89. return PcAddAdapterDevice((PDRIVER_OBJECT)Context1, (PDEVICE_OBJECT)Context2, StartDevice, MAX_MINIPORTS, 0);
  90. }
  91. /*****************************************************************************
  92. * StartDevice()
  93. *****************************************************************************
  94. *
  95. * This function is called by the operating system when the device is started.
  96. * It is responsible for starting the miniports. This code is specific to
  97. * the adapter because it calls out miniports for functions that are specific
  98. * to the adapter. A list of no resources is not the same as a NULL list ptr.
  99. *
  100. */
  101. NTSTATUS
  102. StartDevice
  103. (
  104. IN PDEVICE_OBJECT pDeviceObject, // Context for the class driver.
  105. IN PIRP pIrp, // Context for the class driver.
  106. IN PRESOURCELIST ResourceList // List of hardware resources.
  107. )
  108. {
  109. PAGED_CODE();
  110. _DbgPrintF(DEBUGLVL_VERBOSE, ("StartDevice"));
  111. ASSERT(ResourceList);
  112. if (!ResourceList)
  113. {
  114. return STATUS_INVALID_PARAMETER;
  115. }
  116. PPORT port;
  117. NTSTATUS ntStatus = PcNewPort(&port, CLSID_PortDMus);
  118. if (!NT_SUCCESS(ntStatus))
  119. {
  120. _DbgPrintF(DEBUGLVL_TERSE,("StartDevice PcNewPort failed (0x%08x)", ntStatus));
  121. return ntStatus;
  122. }
  123. ASSERT(port);
  124. PUNKNOWN miniport;
  125. #ifdef USE_OBSOLETE_FUNCS
  126. ntStatus = CreateMiniportDmSynth(&miniport, NULL, NonPagedPool);
  127. #else
  128. ntStatus = CreateMiniportDmSynth(&miniport, NULL, NonPagedPool, pDeviceObject);
  129. #endif
  130. if (!NT_SUCCESS(ntStatus))
  131. {
  132. _DbgPrintF(DEBUGLVL_TERSE,("StartDevice CreateMiniportDmSynth failed (0x%08x)", ntStatus));
  133. port->Release();
  134. return ntStatus;
  135. }
  136. ASSERT(miniport);
  137. ntStatus =
  138. port->Init
  139. (
  140. pDeviceObject,
  141. pIrp,
  142. miniport,
  143. NULL,
  144. ResourceList
  145. );
  146. if (!NT_SUCCESS(ntStatus))
  147. {
  148. _DbgPrintF(DEBUGLVL_TERSE,("StartDevice port Init failed (0x%08x)", ntStatus));
  149. port->Release();
  150. miniport->Release();
  151. return ntStatus;
  152. }
  153. ntStatus = PcRegisterSubdevice( pDeviceObject,
  154. L"DDKSynth",
  155. port);
  156. if (!NT_SUCCESS(ntStatus))
  157. {
  158. _DbgPrintF(DEBUGLVL_TERSE,("StartDevice PcRegisterSubdevice failed (0x%08x)", ntStatus));
  159. }
  160. //
  161. // We don't need the miniport any more. Either the port has it,
  162. // or we've failed, and it should be deleted.
  163. //
  164. miniport->Release();
  165. //
  166. // Release the reference which existed when PcNewPort() gave us the
  167. // pointer in the first place. This is the right thing to do
  168. // regardless of the outcome.
  169. //
  170. port->Release();
  171. return ntStatus;
  172. }
  173. /*****************************************************************************
  174. * _purecall()
  175. *****************************************************************************
  176. * The C++ compiler loves me.
  177. * TODO: Figure out how to put this into portcls.sys
  178. */
  179. int __cdecl
  180. _purecall( void )
  181. {
  182. ASSERT( !"Pure virtual function called" );
  183. return 0;
  184. }