ReactOS 0.4.15-dev-5666-gc548b97
hdaudbus.h File Reference
#include <ntddk.h>
#include <debug.h>
#include <initguid.h>
#include <hdaudio.h>
#include <stdio.h>
#include <ntstrsafe.h>
#include "driver.h"
Include dependency graph for hdaudbus.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  RIRB_RESPONSE
 
struct  HDA_CODEC_AUDIO_GROUP
 
struct  HDA_CODEC_ENTRY
 
struct  HDA_FDO_DEVICE_EXTENSION
 
struct  HDA_PDO_DEVICE_EXTENSION
 
struct  CODEC_RESPONSE
 

Macros

#define YDEBUG
 
#define TAG_HDA   'bADH'
 
#define MAKE_RATE(base, multiply, divide)
 
#define HDAC_INPUT_STREAM_OFFSET(index)    ((index) * HDAC_STREAM_SIZE)
 
#define HDAC_OUTPUT_STREAM_OFFSET(num_input_streams, index)    ((num_input_streams + (index)) * HDAC_STREAM_SIZE)
 
#define HDAC_BIDIR_STREAM_OFFSET(num_input_streams, num_output_streams, index)
 
#define ALIGN(size, align)   (((size) + align - 1) & ~(align - 1))
 

Typedefs

typedef struct RIRB_RESPONSEPRIRB_RESPONSE
 
typedef struct HDA_CODEC_AUDIO_GROUPPHDA_CODEC_AUDIO_GROUP
 
typedef struct HDA_CODEC_ENTRYPHDA_CODEC_ENTRY
 
typedef struct HDA_FDO_DEVICE_EXTENSIONPHDA_FDO_DEVICE_EXTENSION
 
typedef struct HDA_PDO_DEVICE_EXTENSIONPHDA_PDO_DEVICE_EXTENSION
 
typedef struct CODEC_RESPONSEPCODEC_RESPONSE
 

Functions

PVOID AllocateItem (IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
 
VOID FreeItem (IN PVOID Item)
 
NTSTATUS NTAPI HDA_FDOStartDevice (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI HDA_FDORemoveDevice (_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
 
NTSTATUS NTAPI HDA_FDOQueryBusRelations (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS HDA_SendVerbs (IN PDEVICE_OBJECT DeviceObject, IN PHDA_CODEC_ENTRY Codec, IN PULONG Verbs, OUT PULONG Responses, IN ULONG Count)
 
NTSTATUS HDA_PDORemoveDevice (_In_ PDEVICE_OBJECT DeviceObject)
 
NTSTATUS HDA_PDOQueryBusInformation (IN PIRP Irp)
 
NTSTATUS NTAPI HDA_PDOQueryId (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS HDA_PDOHandleQueryDeviceText (IN PIRP Irp)
 
NTSTATUS HDA_PDOQueryBusDeviceCapabilities (IN PIRP Irp)
 
NTSTATUS HDA_PDOQueryBusDevicePnpState (IN PIRP Irp)
 
NTSTATUS HDA_PDOHandleQueryInterface (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 

Variables

KSERVICE_ROUTINE HDA_InterruptService
 
IO_DPC_ROUTINE HDA_DpcForIsr
 

Macro Definition Documentation

◆ ALIGN

#define ALIGN (   size,
  align 
)    (((size) + align - 1) & ~(align - 1))

Definition at line 30 of file hdaudbus.h.

◆ HDAC_BIDIR_STREAM_OFFSET

#define HDAC_BIDIR_STREAM_OFFSET (   num_input_streams,
  num_output_streams,
  index 
)
Value:
((num_input_streams + num_output_streams \
#define index(s, c)
Definition: various.h:29
#define HDAC_STREAM_SIZE

Definition at line 26 of file hdaudbus.h.

◆ HDAC_INPUT_STREAM_OFFSET

#define HDAC_INPUT_STREAM_OFFSET (   index)     ((index) * HDAC_STREAM_SIZE)

Definition at line 22 of file hdaudbus.h.

◆ HDAC_OUTPUT_STREAM_OFFSET

#define HDAC_OUTPUT_STREAM_OFFSET (   num_input_streams,
  index 
)     ((num_input_streams + (index)) * HDAC_STREAM_SIZE)

Definition at line 24 of file hdaudbus.h.

◆ MAKE_RATE

#define MAKE_RATE (   base,
  multiply,
  divide 
)
Value:
((base == 44100 ? FORMAT_44_1_BASE_RATE : 0) \
| ((multiply - 1) << FORMAT_MULTIPLY_RATE_SHIFT) \
| ((divide - 1) << FORMAT_DIVIDE_RATE_SHIFT))
#define FORMAT_44_1_BASE_RATE
#define FORMAT_DIVIDE_RATE_SHIFT
#define FORMAT_MULTIPLY_RATE_SHIFT

Definition at line 17 of file hdaudbus.h.

◆ TAG_HDA

#define TAG_HDA   'bADH'

Definition at line 11 of file hdaudbus.h.

◆ YDEBUG

#define YDEBUG

Definition at line 3 of file hdaudbus.h.

Typedef Documentation

◆ PCODEC_RESPONSE

◆ PHDA_CODEC_AUDIO_GROUP

◆ PHDA_CODEC_ENTRY

◆ PHDA_FDO_DEVICE_EXTENSION

◆ PHDA_PDO_DEVICE_EXTENSION

◆ PRIRB_RESPONSE

Function Documentation

◆ AllocateItem()

PVOID AllocateItem ( IN POOL_TYPE  PoolType,
IN SIZE_T  NumberOfBytes 
)

Definition at line 30 of file misc.c.

33{
35 if (!Item)
36 return Item;
37
39 return Item;
40}
#define TAG_KS
Definition: misc.c:14
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_In_ WDFCOLLECTION _In_ WDFOBJECT Item
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE PoolType
Definition: wdfdevice.h:3815
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _Inout_ PLARGE_INTEGER NumberOfBytes
Definition: iotypes.h:1036

◆ FreeItem()

VOID FreeItem ( IN PVOID  Item)

Definition at line 43 of file misc.c.

45{
47}
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

◆ HDA_FDOQueryBusRelations()

NTSTATUS NTAPI HDA_FDOQueryBusRelations ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 760 of file fdo.cpp.

763{
764 ULONG DeviceCount, CodecIndex, AFGIndex;
765 PHDA_FDO_DEVICE_EXTENSION DeviceExtension;
766 PHDA_CODEC_ENTRY Codec;
767 PDEVICE_RELATIONS DeviceRelations;
768
769 /* get device extension */
770 DeviceExtension = (PHDA_FDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
771 ASSERT(DeviceExtension->IsFDO == TRUE);
772
773 DeviceCount = 0;
774 for (CodecIndex = 0; CodecIndex < HDA_MAX_CODECS; CodecIndex++)
775 {
776 if (DeviceExtension->Codecs[CodecIndex] == NULL)
777 continue;
778
779 Codec = DeviceExtension->Codecs[CodecIndex];
781 }
782
783 if (DeviceCount == 0)
784 return STATUS_UNSUCCESSFUL;
785
786 DeviceRelations = (PDEVICE_RELATIONS)AllocateItem(NonPagedPool, sizeof(DEVICE_RELATIONS) + (DeviceCount > 1 ? sizeof(PDEVICE_OBJECT) * (DeviceCount - 1) : 0));
787 if (!DeviceRelations)
789
790 DeviceRelations->Count = 0;
791 for (CodecIndex = 0; CodecIndex < HDA_MAX_CODECS; CodecIndex++)
792 {
793 if (DeviceExtension->Codecs[CodecIndex] == NULL)
794 continue;
795
796 Codec = DeviceExtension->Codecs[CodecIndex];
798 for (AFGIndex = 0; AFGIndex < Codec->AudioGroupCount; AFGIndex++)
799 {
800 DeviceRelations->Objects[DeviceRelations->Count] = Codec->AudioGroups[AFGIndex]->ChildPDO;
801 ObReferenceObject(Codec->AudioGroups[AFGIndex]->ChildPDO);
802 DeviceRelations->Count++;
803 }
804 }
805
806 /* FIXME handle existing device relations */
807 ASSERT(Irp->IoStatus.Information == 0);
808
809 /* store device relations */
810 Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
811
812 /* done */
813 return STATUS_SUCCESS;
814}
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define ULONG_PTR
Definition: config.h:101
#define HDA_MAX_AUDIO_GROUPS
Definition: driver.h:40
#define HDA_MAX_CODECS
Definition: driver.h:41
struct _DEVICE_OBJECT * PDEVICE_OBJECT
#define NonPagedPool
Definition: env_spec_w32.h:307
struct HDA_FDO_DEVICE_EXTENSION * PHDA_FDO_DEVICE_EXTENSION
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
unsigned int ULONG
Definition: retypes.h:1
#define ASSERT(a)
Definition: mode.c:44
ULONG DeviceCount
Definition: mpu401.c:26
#define STATUS_SUCCESS
Definition: shellext.h:65
PDEVICE_OBJECT ChildPDO
Definition: hdaudbus.h:40
Definition: hdaudbus.h:46
PHDA_CODEC_AUDIO_GROUP AudioGroups[HDA_MAX_AUDIO_GROUPS]
Definition: hdaudbus.h:59
ULONG AudioGroupCount
Definition: hdaudbus.h:60
PHDA_CODEC_ENTRY Codecs[HDA_MAX_CODECS+1]
Definition: hdaudbus.h:82
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2163
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
struct _DEVICE_RELATIONS * PDEVICE_RELATIONS
#define ObReferenceObject
Definition: obfuncs.h:204

Referenced by HDA_FdoPnp().

◆ HDA_FDORemoveDevice()

NTSTATUS NTAPI HDA_FDORemoveDevice ( _In_ PDEVICE_OBJECT  DeviceObject,
_Inout_ PIRP  Irp 
)

Definition at line 692 of file fdo.cpp.

695{
697 PHDA_FDO_DEVICE_EXTENSION DeviceExtension;
698 ULONG CodecIndex, AFGIndex;
699 PHDA_CODEC_ENTRY CodecEntry;
700 PDEVICE_OBJECT ChildPDO;
701 PHDA_PDO_DEVICE_EXTENSION ChildDeviceExtension;
702
703 /* get device extension */
704 DeviceExtension = static_cast<PHDA_FDO_DEVICE_EXTENSION>(DeviceObject->DeviceExtension);
705 ASSERT(DeviceExtension->IsFDO == TRUE);
706
707 Irp->IoStatus.Status = STATUS_SUCCESS;
709 Status = IoCallDriver(DeviceExtension->LowerDevice, Irp);
710
711 IoDetachDevice(DeviceExtension->LowerDevice);
712
713 if (DeviceExtension->RegBase != NULL)
714 {
715 MmUnmapIoSpace(DeviceExtension->RegBase,
716 DeviceExtension->RegLength);
717 }
718 if (DeviceExtension->Interrupt != NULL)
719 {
720 IoDisconnectInterrupt(DeviceExtension->Interrupt);
721 }
722 if (DeviceExtension->CorbBase != NULL)
723 {
724 MmFreeContiguousMemory(DeviceExtension->CorbBase);
725 }
726
727 for (CodecIndex = 0; CodecIndex < HDA_MAX_CODECS; CodecIndex++)
728 {
729 CodecEntry = DeviceExtension->Codecs[CodecIndex];
730 if (CodecEntry == NULL)
731 {
732 continue;
733 }
734
736 for (AFGIndex = 0; AFGIndex < CodecEntry->AudioGroupCount; AFGIndex++)
737 {
738 ChildPDO = CodecEntry->AudioGroups[AFGIndex]->ChildPDO;
739 if (ChildPDO != NULL)
740 {
741 ChildDeviceExtension = static_cast<PHDA_PDO_DEVICE_EXTENSION>(ChildPDO->DeviceExtension);
742 ChildDeviceExtension->Codec = NULL;
743 ChildDeviceExtension->AudioGroup = NULL;
744 ChildDeviceExtension->FDO = NULL;
745 ChildDeviceExtension->ReportedMissing = TRUE;
746 HDA_PDORemoveDevice(ChildPDO);
747 }
748 FreeItem(CodecEntry->AudioGroups[AFGIndex]);
749 }
750 FreeItem(CodecEntry);
751 }
752
754
755 return Status;
756}
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI MmFreeContiguousMemory(IN PVOID BaseAddress)
Definition: contmem.c:653
Status
Definition: gdiplustypes.h:25
NTSTATUS HDA_PDORemoveDevice(_In_ PDEVICE_OBJECT DeviceObject)
Definition: pdo.cpp:11
VOID NTAPI MmUnmapIoSpace(IN PVOID BaseAddress, IN SIZE_T NumberOfBytes)
Definition: iosup.c:193
VOID FreeItem(IN PVOID Item)
Definition: misc.c:43
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define IoCallDriver
Definition: irp.c:1225
VOID NTAPI IoDisconnectInterrupt(PKINTERRUPT InterruptObject)
Definition: irq.c:140
PDEVICE_OBJECT LowerDevice
Definition: hdaudbus.h:68
PKINTERRUPT Interrupt
Definition: hdaudbus.h:72
PHDA_CODEC_AUDIO_GROUP AudioGroup
Definition: hdaudbus.h:91
PHDA_CODEC_ENTRY Codec
Definition: hdaudbus.h:90
PDEVICE_OBJECT FDO
Definition: hdaudbus.h:92
PVOID DeviceExtension
Definition: env_spec_w32.h:418

Referenced by HDA_FdoPnp().

◆ HDA_FDOStartDevice()

NTSTATUS NTAPI HDA_FDOStartDevice ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 578 of file fdo.cpp.

581{
582 PIO_STACK_LOCATION IoStack;
584 PHDA_FDO_DEVICE_EXTENSION DeviceExtension;
586 ULONG Index;
588
589 /* get device extension */
590 DeviceExtension = (PHDA_FDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
591 ASSERT(DeviceExtension->IsFDO == TRUE);
592
593 /* forward irp to lower device */
594 if (!IoForwardIrpSynchronously(DeviceExtension->LowerDevice, Irp))
595 {
596 ASSERT(FALSE);
598 }
599 Status = Irp->IoStatus.Status;
600 if (!NT_SUCCESS(Status))
601 {
602 // failed to start
603 DPRINT1("HDA_StartDevice Lower device failed to start %x\n", Status);
604 return Status;
605 }
606
607 /* get current irp stack location */
609
610 Resources = IoStack->Parameters.StartDevice.AllocatedResourcesTranslated;
611 for (Index = 0; Index < Resources->List[0].PartialResourceList.Count; Index++)
612 {
613 PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor = &Resources->List[0].PartialResourceList.PartialDescriptors[Index];
614
615 if (Descriptor->Type == CmResourceTypeMemory)
616 {
617 DeviceExtension->RegLength = Descriptor->u.Memory.Length;
618 DeviceExtension->RegBase = (PUCHAR)MmMapIoSpace(Descriptor->u.Memory.Start, Descriptor->u.Memory.Length, MmNonCached);
619 if (DeviceExtension->RegBase == NULL)
620 {
621 DPRINT1("[HDAB] Failed to map registers\n");
623 break;
624 }
625 }
626 else if (Descriptor->Type == CmResourceTypeInterrupt)
627 {
628 Status = IoConnectInterrupt(&DeviceExtension->Interrupt,
631 NULL,
632 Descriptor->u.Interrupt.Vector,
633 Descriptor->u.Interrupt.Level,
634 Descriptor->u.Interrupt.Level,
636 (Descriptor->ShareDisposition != CmResourceShareDeviceExclusive),
637 Descriptor->u.Interrupt.Affinity,
638 FALSE);
639 if (!NT_SUCCESS(Status))
640 {
641 DPRINT1("[HDAB] Failed to connect interrupt. Status=%lx\n", Status);
642 break;
643 }
644
645 }
646 }
647
648 if (NT_SUCCESS(Status))
649 {
650 // Get controller into valid state
652 if (!NT_SUCCESS(Status)) return Status;
653
654 // Setup CORB/RIRB/DMA POS
656 if (!NT_SUCCESS(Status)) return Status;
657
658
659 // Don't enable codec state change interrupts. We don't handle
660 // them, as we want to use the STATE_STATUS register to identify
661 // available codecs. We'd have to clear that register in the interrupt
662 // handler to 'ack' the codec change.
663 Value = READ_REGISTER_USHORT((PUSHORT)(DeviceExtension->RegBase + HDAC_WAKE_ENABLE)) & ~HDAC_WAKE_ENABLE_MASK;
665
666 // Enable controller interrupts
668
670
672 if (!Value) {
673 DPRINT1("hda: bad codec status\n");
674 return STATUS_UNSUCCESSFUL;
675 }
677
678 // Create codecs
679 DPRINT1("Codecs %lx\n", Value);
680 for (Index = 0; Index < HDA_MAX_CODECS; Index++) {
681 if ((Value & (1 << Index)) != 0) {
683 }
684 }
685 }
686
687 return Status;
688}
#define WRITE_REGISTER_USHORT(r, v)
Definition: arm.h:24
#define READ_REGISTER_USHORT(r)
Definition: arm.h:23
#define WRITE_REGISTER_ULONG(r, v)
Definition: arm.h:21
#define DPRINT1
Definition: precomp.h:8
VOID NTAPI KeStallExecutionProcessor(IN ULONG MicroSeconds)
Definition: ntoskrnl.c:81
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI HDA_ResetController(IN PDEVICE_OBJECT DeviceObject)
Definition: fdo.cpp:468
NTSTATUS HDA_InitCodec(IN PDEVICE_OBJECT DeviceObject, IN ULONG codecAddress)
Definition: fdo.cpp:203
NTSTATUS NTAPI HDA_InitCorbRirbPos(IN PDEVICE_OBJECT DeviceObject)
Definition: fdo.cpp:321
#define HDAC_INTR_CONTROL
#define INTR_CONTROL_GLOBAL_ENABLE
#define INTR_CONTROL_CONTROLLER_ENABLE
#define HDAC_STATE_STATUS
#define HDAC_WAKE_ENABLE
KSERVICE_ROUTINE HDA_InterruptService
Definition: hdaudbus.h:121
#define CmResourceTypeMemory
Definition: hwresource.cpp:125
#define CmResourceTypeInterrupt
Definition: hwresource.cpp:124
PVOID NTAPI MmMapIoSpace(IN PHYSICAL_ADDRESS PhysicalAddress, IN SIZE_T NumberOfBytes, IN MEMORY_CACHING_TYPE CacheType)
Definition: iosup.c:47
unsigned int * PULONG
Definition: retypes.h:1
unsigned short * PUSHORT
Definition: retypes.h:2
unsigned char * PUCHAR
Definition: retypes.h:3
#define CM_RESOURCE_INTERRUPT_LATCHED
Definition: cmtypes.h:144
BOOLEAN NTAPI IoForwardIrpSynchronously(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1625
NTSTATUS NTAPI IoConnectInterrupt(OUT PKINTERRUPT *InterruptObject, IN PKSERVICE_ROUTINE ServiceRoutine, IN PVOID ServiceContext, IN PKSPIN_LOCK SpinLock, IN ULONG Vector, IN KIRQL Irql, IN KIRQL SynchronizeIrql, IN KINTERRUPT_MODE InterruptMode, IN BOOLEAN ShareVector, IN KAFFINITY ProcessorEnableMask, IN BOOLEAN FloatingSave)
Definition: irq.c:22
unsigned short USHORT
Definition: pedump.c:61
enum _KINTERRUPT_MODE KINTERRUPT_MODE
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342
@ CmResourceShareDeviceExclusive
Definition: cmtypes.h:241
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
@ MmNonCached
Definition: mmtypes.h:129

Referenced by HDA_FdoPnp().

◆ HDA_PDOHandleQueryDeviceText()

NTSTATUS HDA_PDOHandleQueryDeviceText ( IN PIRP  Irp)

Definition at line 154 of file pdo.cpp.

156{
157 PIO_STACK_LOCATION IoStack;
159 static WCHAR DeviceText[] = L"Audio Device on High Definition Audio Bus";
160
162 if (IoStack->Parameters.QueryDeviceText.DeviceTextType == DeviceTextDescription)
163 {
164 DPRINT("HDA_PdoHandleQueryDeviceText DeviceTextDescription\n");
165
166 Buffer = (LPWSTR)AllocateItem(PagedPool, sizeof(DeviceText));
167 if (!Buffer)
168 {
169 Irp->IoStatus.Information = 0;
171 }
172
173 wcscpy(Buffer, DeviceText);
174
175 Irp->IoStatus.Information = (ULONG_PTR)Buffer;
176 return STATUS_SUCCESS;
177 }
178 else
179 {
180 DPRINT("HDA_PdoHandleQueryDeviceText DeviceTextLocationInformation\n");
181
182 Buffer = (LPWSTR)AllocateItem(PagedPool, sizeof(DeviceText));
183 if (!Buffer)
184 {
185 Irp->IoStatus.Information = 0;
187 }
188
189 wcscpy(Buffer, DeviceText);
190
191 /* save result */
192 Irp->IoStatus.Information = (ULONG_PTR)Buffer;
193 return STATUS_SUCCESS;
194 }
195
196}
Definition: bufpool.h:45
#define PagedPool
Definition: env_spec_w32.h:308
#define L(x)
Definition: ntvdm.h:50
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define DPRINT
Definition: sndvol32.h:71
@ DeviceTextDescription
Definition: iotypes.h:2945
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by HDA_PdoPnp().

◆ HDA_PDOHandleQueryInterface()

NTSTATUS HDA_PDOHandleQueryInterface ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 299 of file businterface.cpp.

302{
303 PIO_STACK_LOCATION IoStack;
304 PHDAUDIO_BUS_INTERFACE_V2 InterfaceHDA;
305 PHDA_PDO_DEVICE_EXTENSION DeviceExtension;
306
307 /* get device extension */
308 DeviceExtension = (PHDA_PDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
309 ASSERT(DeviceExtension->IsFDO == FALSE);
310
312
313 if (IsEqualGUIDAligned(*IoStack->Parameters.QueryInterface.InterfaceType, GUID_HDAUDIO_BUS_INTERFACE))
314 {
315 InterfaceHDA = (PHDAUDIO_BUS_INTERFACE_V2)IoStack->Parameters.QueryInterface.Interface;
316 InterfaceHDA->Version = IoStack->Parameters.QueryInterface.Version;
317 InterfaceHDA->Size = sizeof(HDAUDIO_BUS_INTERFACE);
318 InterfaceHDA->Context = DeviceExtension;
321
327 InterfaceHDA->FreeDmaBuffer = HDA_FreeDmaBuffer;
328 InterfaceHDA->FreeDmaEngine = HDA_FreeDmaEngine;
336 return STATUS_SUCCESS;
337 }
338 else if (IsEqualGUIDAligned(*IoStack->Parameters.QueryInterface.InterfaceType, GUID_HDAUDIO_BUS_INTERFACE_V2))
339 {
340 InterfaceHDA = (PHDAUDIO_BUS_INTERFACE_V2)IoStack->Parameters.QueryInterface.Interface;
341 InterfaceHDA->Version = IoStack->Parameters.QueryInterface.Version;
342 InterfaceHDA->Size = sizeof(HDAUDIO_BUS_INTERFACE_V2);
343 InterfaceHDA->Context = DeviceExtension;
346
352 InterfaceHDA->FreeDmaBuffer = HDA_FreeDmaBuffer;
353 InterfaceHDA->FreeDmaEngine = HDA_FreeDmaEngine;
361
366 }
367
368 // FIXME
369 // implement support for GUID_HDAUDIO_BUS_INTERFACE_BDL
372}
#define UNIMPLEMENTED
Definition: debug.h:115
VOID NTAPI HDA_InterfaceDereference(PVOID BusContext)
VOID NTAPI HDA_GetResourceInformation(IN PVOID _context, OUT PUCHAR CodecAddress, OUT PUCHAR FunctionGroupStartNode)
NTSTATUS NTAPI HDA_UnregisterEventCallback(IN PVOID _context, IN UCHAR Tag)
NTSTATUS NTAPI HDA_TransferCodecVerbs(IN PVOID _context, IN ULONG Count, IN OUT PHDAUDIO_CODEC_TRANSFER CodecTransfer, IN PHDAUDIO_TRANSFER_COMPLETE_CALLBACK Callback, IN PVOID Context)
NTSTATUS NTAPI HDA_SetDmaEngineState(IN PVOID _context, IN HDAUDIO_STREAM_STATE StreamState, IN ULONG NumberOfHandles, IN PHANDLE Handles)
VOID NTAPI HDA_GetWallClockRegister(IN PVOID _context, OUT PULONG *Wallclock)
NTSTATUS NTAPI HDA_ChangeBandwidthAllocation(IN PVOID _context, IN HANDLE Handle, IN PHDAUDIO_STREAM_FORMAT StreamFormat, OUT PHDAUDIO_CONVERTER_FORMAT ConverterFormat)
NTSTATUS NTAPI HDA_AllocateRenderDmaEngine(IN PVOID _context, IN PHDAUDIO_STREAM_FORMAT StreamFormat, IN BOOLEAN Stripe, OUT PHANDLE Handle, OUT PHDAUDIO_CONVERTER_FORMAT ConverterFormat)
NTSTATUS NTAPI HDA_FreeDmaBuffer(IN PVOID _context, IN HANDLE Handle)
NTSTATUS NTAPI HDA_RegisterEventCallback(IN PVOID _context, IN PHDAUDIO_UNSOLICITED_RESPONSE_CALLBACK Routine, IN PVOID Context, OUT PUCHAR Tag)
NTSTATUS NTAPI HDA_GetDeviceInformation(IN PVOID _context, OUT PHDAUDIO_DEVICE_INFORMATION DeviceInformation)
NTSTATUS NTAPI HDA_GetLinkPositionRegister(IN PVOID _context, IN HANDLE Handle, OUT PULONG *Position)
NTSTATUS NTAPI HDA_AllocateCaptureDmaEngine(IN PVOID _context, IN UCHAR CodecAddress, IN PHDAUDIO_STREAM_FORMAT StreamFormat, OUT PHANDLE Handle, OUT PHDAUDIO_CONVERTER_FORMAT ConverterFormat)
NTSTATUS NTAPI HDA_AllocateDmaBufferWithNotification(IN PVOID _context, IN HANDLE Handle, IN ULONG NotificationCount, IN SIZE_T RequestedBufferSize, OUT PMDL *BufferMdl, OUT PSIZE_T AllocatedBufferSize, OUT PSIZE_T OffsetFromFirstPage, OUT PUCHAR StreamId, OUT PULONG FifoSize)
NTSTATUS NTAPI HDA_UnregisterNotificationEvent(IN PVOID _context, IN HANDLE Handle, IN PKEVENT NotificationEvent)
NTSTATUS NTAPI HDA_RegisterNotificationEvent(PVOID _context, HANDLE Handle, IN PKEVENT NotificationEvent)
NTSTATUS NTAPI HDA_AllocateDmaBuffer(IN PVOID _context, IN HANDLE Handle, IN SIZE_T RequestedBufferSize, OUT PMDL *BufferMdl, OUT PSIZE_T AllocatedBufferSize, OUT PUCHAR StreamId, OUT PULONG FifoSize)
NTSTATUS NTAPI HDA_FreeDmaBufferWithNotification(IN PVOID _context, IN HANDLE Handle, IN PMDL BufferMdl, IN SIZE_T BufferSize)
NTSTATUS NTAPI HDA_FreeDmaEngine(IN PVOID _context, IN HANDLE Handle)
VOID NTAPI HDA_InterfaceReference(PVOID BusContext)
struct HDA_PDO_DEVICE_EXTENSION * PHDA_PDO_DEVICE_EXTENSION
struct _HDAUDIO_BUS_INTERFACE_V2 * PHDAUDIO_BUS_INTERFACE_V2
HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
PALLOCATE_CAPTURE_DMA_ENGINE AllocateCaptureDmaEngine
Definition: hdaudio.h:355
PALLOCATE_DMA_BUFFER_WITH_NOTIFICATION AllocateDmaBufferWithNotification
Definition: hdaudio.h:368
PFREE_DMA_ENGINE FreeDmaEngine
Definition: hdaudio.h:360
PINTERFACE_REFERENCE InterfaceReference
Definition: hdaudio.h:352
PGET_DEVICE_INFORMATION GetDeviceInformation
Definition: hdaudio.h:366
PCHANGE_BANDWIDTH_ALLOCATION ChangeBandwidthAllocation
Definition: hdaudio.h:357
PFREE_DMA_BUFFER FreeDmaBuffer
Definition: hdaudio.h:359
PUNREGISTER_NOTIFICATION_EVENT UnregisterNotificationEvent
Definition: hdaudio.h:371
PSET_DMA_ENGINE_STATE SetDmaEngineState
Definition: hdaudio.h:361
PREGISTER_EVENT_CALLBACK RegisterEventCallback
Definition: hdaudio.h:364
PREGISTER_NOTIFICATION_EVENT RegisterNotificationEvent
Definition: hdaudio.h:370
PGET_LINK_POSITION_REGISTER GetLinkPositionRegister
Definition: hdaudio.h:363
PUNREGISTER_EVENT_CALLBACK UnregisterEventCallback
Definition: hdaudio.h:365
PINTERFACE_DEREFERENCE InterfaceDereference
Definition: hdaudio.h:353
PTRANSFER_CODEC_VERBS TransferCodecVerbs
Definition: hdaudio.h:354
PGET_WALL_CLOCK_REGISTER GetWallClockRegister
Definition: hdaudio.h:362
PFREE_DMA_BUFFER_WITH_NOTIFICATION FreeDmaBufferWithNotification
Definition: hdaudio.h:369
PALLOCATE_DMA_BUFFER AllocateDmaBuffer
Definition: hdaudio.h:358
PGET_RESOURCE_INFORMATION GetResourceInformation
Definition: hdaudio.h:367
PALLOCATE_RENDER_DMA_ENGINE AllocateRenderDmaEngine
Definition: hdaudio.h:356
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:235

Referenced by HDA_PdoPnp().

◆ HDA_PDOQueryBusDeviceCapabilities()

NTSTATUS HDA_PDOQueryBusDeviceCapabilities ( IN PIRP  Irp)

Definition at line 199 of file pdo.cpp.

201{
203 PIO_STACK_LOCATION IoStack;
204
205 /* get stack location */
207
208 /* get capabilities */
209 Capabilities = IoStack->Parameters.DeviceCapabilities.Capabilities;
210
212
213 /* setup capabilities */
214 Capabilities->UniqueID = TRUE;
215 Capabilities->SilentInstall = TRUE;
216 Capabilities->SurpriseRemovalOK = TRUE;
217 Capabilities->Address = 0;
218 Capabilities->UINumber = 0;
219 Capabilities->SystemWake = PowerSystemWorking; /* FIXME common device extension */
220 Capabilities->DeviceWake = PowerDeviceD0;
221
222 /* done */
223 return STATUS_SUCCESS;
224}
_Must_inspect_result_ typedef _Out_ PHIDP_CAPS Capabilities
Definition: hidclass.h:103
@ PowerSystemWorking
Definition: ntpoapi.h:36
@ PowerDeviceD0
Definition: ntpoapi.h:49
DEVICE_CAPABILITIES
Definition: iotypes.h:965
* PDEVICE_CAPABILITIES
Definition: iotypes.h:965

Referenced by HDA_PdoPnp().

◆ HDA_PDOQueryBusDevicePnpState()

NTSTATUS HDA_PDOQueryBusDevicePnpState ( IN PIRP  Irp)

Definition at line 227 of file pdo.cpp.

229{
230 /* set device flags */
232
233 /* done */
234 return STATUS_SUCCESS;
235}
#define PNP_DEVICE_NOT_DISABLEABLE
Definition: iotypes.h:1006
#define PNP_DEVICE_DONT_DISPLAY_IN_UI
Definition: iotypes.h:1002

Referenced by HDA_PdoPnp().

◆ HDA_PDOQueryBusInformation()

NTSTATUS HDA_PDOQueryBusInformation ( IN PIRP  Irp)

Definition at line 33 of file pdo.cpp.

35{
37
38 /* allocate bus information */
40
41 if (!BusInformation)
42 {
43 /* no memory */
45 }
46
47 /* return info */
48 BusInformation->BusNumber = 0;
49 BusInformation->LegacyBusType = PCIBus;
50 RtlMoveMemory(&BusInformation->BusTypeGuid, &GUID_HDAUDIO_BUS_INTERFACE, sizeof(GUID));
51
52 /* store result */
53 Irp->IoStatus.Information = (ULONG_PTR)BusInformation;
54
55 /* done */
56 return STATUS_SUCCESS;
57}
@ PCIBus
Definition: hwresource.cpp:142
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
_In_ WDFDEVICE _In_ PPNP_BUS_INFORMATION BusInformation
Definition: wdfdevice.h:3915
struct _PNP_BUS_INFORMATION * PPNP_BUS_INFORMATION

Referenced by HDA_PdoPnp().

◆ HDA_PDOQueryId()

NTSTATUS NTAPI HDA_PDOQueryId ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 62 of file pdo.cpp.

65{
66 PIO_STACK_LOCATION IoStack;
67 WCHAR DeviceName[200];
68 PHDA_PDO_DEVICE_EXTENSION DeviceExtension;
72
73 /* get device extension */
74 DeviceExtension = (PHDA_PDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
75 ASSERT(DeviceExtension->IsFDO == FALSE);
76
77 /* get current irp stack location */
79
80 if (IoStack->Parameters.QueryId.IdType == BusQueryInstanceID)
81 {
83 sizeof(DeviceName),
84 L"%02x%02x",
85 DeviceExtension->Codec->Addr,
86 DeviceExtension->AudioGroup->NodeId);
89
90 /* allocate result buffer*/
92 if (!Device)
94
96 Length * sizeof(WCHAR),
99
100 DPRINT1("ID: %S\n", Device);
101 /* store result */
102 Irp->IoStatus.Information = (ULONG_PTR)Device;
103 return STATUS_SUCCESS;
104 }
105 else if (IoStack->Parameters.QueryId.IdType == BusQueryDeviceID ||
106 IoStack->Parameters.QueryId.IdType == BusQueryHardwareIDs)
107 {
108
109 /* calculate size */
110 swprintf(DeviceName, L"HDAUDIO\\FUNC_%02X&VEN_%04X&DEV_%04X&SUBSYS_%08X", DeviceExtension->AudioGroup->FunctionGroup, DeviceExtension->Codec->VendorId, DeviceExtension->Codec->ProductId, DeviceExtension->Codec->VendorId << 16 | DeviceExtension->Codec->ProductId);
111 Length = wcslen(DeviceName) + 20;
112
113 /* allocate result buffer*/
115 if (!Device)
117
119
120 DPRINT1("ID: %S\n", Device);
121 /* store result */
122 Irp->IoStatus.Information = (ULONG_PTR)Device;
123 return STATUS_SUCCESS;
124 }
125 else if (IoStack->Parameters.QueryId.IdType == BusQueryCompatibleIDs)
126 {
128 Length = swprintf(DeviceName, L"HDAUDIO\\FUNC_%02X&VEN_%04X&DEV_%04X&REV_%04X", DeviceExtension->AudioGroup->FunctionGroup, DeviceExtension->Codec->VendorId, DeviceExtension->Codec->ProductId, DeviceExtension->Codec->Major << 12 | DeviceExtension->Codec->Minor << 8 | DeviceExtension->Codec->Revision) + 1;
129 Length += swprintf(&DeviceName[Length], L"HDAUDIO\\FUNC_%02X&VEN_%04X&DEV_%04X", DeviceExtension->AudioGroup->FunctionGroup, DeviceExtension->Codec->VendorId, DeviceExtension->Codec->ProductId) + 1;
130 Length += swprintf(&DeviceName[Length], L"HDAUDIO\\FUNC_%02X&VEN_%04X", DeviceExtension->AudioGroup->FunctionGroup, DeviceExtension->Codec->VendorId) + 1;
131 Length += swprintf(&DeviceName[Length], L"HDAUDIO\\FUNC_%02X", DeviceExtension->AudioGroup->FunctionGroup) + 2;
132
133 /* allocate result buffer*/
135 if (!Device)
137
139
140 DPRINT1("ID: %S\n", Device);
141 /* store result */
142 Irp->IoStatus.Information = (ULONG_PTR)Device;
143 return STATUS_SUCCESS;
144 }
145 else
146 {
147 DPRINT1("QueryID Type %x not implemented\n", IoStack->Parameters.QueryId.IdType);
148 return Irp->IoStatus.Status;
149 }
151}
#define swprintf
Definition: precomp.h:40
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
NTSTRSAFEAPI RtlStringCbCopyW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
Definition: ntstrsafe.h:174
NTSTRSAFEVAPI RtlStringCbPrintfW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1173
UCHAR Revision
Definition: hdaudbus.h:51
USHORT ProductId
Definition: hdaudbus.h:48
UCHAR Major
Definition: hdaudbus.h:49
USHORT VendorId
Definition: hdaudbus.h:47
UCHAR Minor
Definition: hdaudbus.h:50
UCHAR Addr
Definition: hdaudbus.h:53
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
@ BusQueryCompatibleIDs
Definition: iotypes.h:2938
@ BusQueryInstanceID
Definition: iotypes.h:2939
@ BusQueryDeviceID
Definition: iotypes.h:2936
@ BusQueryHardwareIDs
Definition: iotypes.h:2937
#define NT_ASSERT
Definition: rtlfuncs.h:3310

Referenced by HDA_PdoPnp().

◆ HDA_PDORemoveDevice()

NTSTATUS HDA_PDORemoveDevice ( _In_ PDEVICE_OBJECT  DeviceObject)

Definition at line 11 of file pdo.cpp.

13{
14 PHDA_PDO_DEVICE_EXTENSION DeviceExtension;
15
16 /* get device extension */
17 DeviceExtension = static_cast<PHDA_PDO_DEVICE_EXTENSION>(DeviceObject->DeviceExtension);
18 ASSERT(DeviceExtension->IsFDO == FALSE);
19
20 if (DeviceExtension->ReportedMissing)
21 {
22 if (DeviceExtension->AudioGroup != NULL)
23 {
24 DeviceExtension->AudioGroup->ChildPDO = NULL;
25 }
27 }
28
29 return STATUS_SUCCESS;
30}

Referenced by HDA_FDORemoveDevice(), and HDA_PdoPnp().

◆ HDA_SendVerbs()

NTSTATUS HDA_SendVerbs ( IN PDEVICE_OBJECT  DeviceObject,
IN PHDA_CODEC_ENTRY  Codec,
IN PULONG  Verbs,
OUT PULONG  Responses,
IN ULONG  Count 
)

Definition at line 138 of file fdo.cpp.

144{
145 PHDA_FDO_DEVICE_EXTENSION DeviceExtension;
146 ULONG Sent = 0, ReadPosition, WritePosition, Queued;
147
148 /* get device extension */
149 DeviceExtension = (PHDA_FDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
150 ASSERT(DeviceExtension->IsFDO);
151
152 /* reset response count */
153 Codec->ResponseCount = 0;
154
155 while (Sent < Count) {
156 ReadPosition = READ_REGISTER_USHORT((PUSHORT)(DeviceExtension->RegBase + HDAC_CORB_READ_POS));
157
158 Queued = 0;
159
160 while (Sent < Count) {
161 WritePosition = (DeviceExtension->CorbWritePos + 1) % DeviceExtension->CorbLength;
162
163 if (WritePosition == ReadPosition) {
164 // There is no space left in the ring buffer; execute the
165 // queued commands and wait until
166 break;
167 }
168
169 DeviceExtension->CorbBase[WritePosition] = Verbs[Sent++];
170 DeviceExtension->CorbWritePos = WritePosition;
171 Queued++;
172 }
173
174 WRITE_REGISTER_USHORT((PUSHORT)(DeviceExtension->RegBase + HDAC_CORB_WRITE_POS), DeviceExtension->CorbWritePos);
175 }
176
177 while (Queued--)
178 {
180 Timeout.QuadPart = -1000LL * 10000; // 1 sec
181
182 NTSTATUS waitStatus = KeWaitForSingleObject(&Codec->ResponseSemaphore,
183 Executive,
185 FALSE,
186 &Timeout);
187
188 if (waitStatus == STATUS_TIMEOUT)
189 {
190 DPRINT1("HDA_SendVerbs: timeout! Queued: %u\n", Queued);
192 }
193 }
194
195 if (Responses != NULL) {
196 memcpy(Responses, Codec->Responses, Codec->ResponseCount * sizeof(ULONG));
197 }
198
199 return STATUS_SUCCESS;
200}
UINT Sent
Definition: arping.c:39
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define HDAC_CORB_READ_POS
#define HDAC_CORB_WRITE_POS
if(dx< 0)
Definition: linetemp.h:194
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define KernelMode
Definition: asm.h:34
int Count
Definition: noreturn.cpp:7
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
static ULONG Timeout
Definition: ping.c:61
@ Executive
Definition: ketypes.h:403

Referenced by HDA_InitCodec(), and HDA_TransferCodecVerbs().

Variable Documentation

◆ HDA_DpcForIsr

IO_DPC_ROUTINE HDA_DpcForIsr

Definition at line 122 of file hdaudbus.h.

Referenced by HDA_AddDevice().

◆ HDA_InterruptService

KSERVICE_ROUTINE HDA_InterruptService

Definition at line 121 of file hdaudbus.h.

Referenced by HDA_FDOStartDevice().