1 /* 2 * 3 * COPYRIGHT: See COPYING in the top level directory 4 * PROJECT: ReactOS kernel 5 * FILE: drivers/dd/sndblst/sndblst.h 6 * PURPOSE: Sound Blaster driver header 7 * PROGRAMMER: Andrew Greenwood 8 * UPDATE HISTORY: 9 * Sept 28, 2003: Created 10 */ 11 12 #pragma once 13 14 #include <ntddk.h> 15 16 #define NDEBUG 17 #include <debug.h> 18 19 #define DEFAULT_PORT 0x220 20 #define DEFAULT_IRQ 5 21 #define DEFAULT_DMA 1 22 #define DEFAULT_BUFSIZE 0x4000 23 #define DEFAULT_SAMPLERATE 11025 24 #define DEFAULT_BITDEPTH 8 25 #define DEFAULT_CHANNELS 1 26 27 #define VALID_IRQS {5} 28 29 #define MIN_BUFSIZE 0x1000 30 #define MAX_BUFSIZE 0x4000 31 32 #define DEVICE_SUBKEY L"Devices" 33 #define PARMS_SUBKEY L"Parameters" 34 35 #define REGISTRY_PORT L"Port" 36 37 // At the moment, we just support a single device with fixed parameters: 38 #define SB_PORT DEFAULT_PORT 39 #define SB_IRQ DEFAULT_IRQ 40 #define SB_DMA DEFAULT_DMA 41 #define SB_BUFSIZE DEFAULT_BUFSIZE 42 43 #define SB_TIMEOUT 1000000 44 45 #define IOCTL_SOUND_BASE FILE_DEVICE_SOUND 46 #define IOCTL_WAVE_BASE 0x0000 // CORRECT? 47 48 /* #define IOCTL_MIDI_PLAY CTL_CODE(IOCTL_SOUND_BASE, IOCTL_MIDI_BASE + 0x0006, \ 49 * METHOD_BUFFERED, FILE_WRITE_ACCESS) 50 */ 51 52 // Some constants 53 54 #define SB_DSP_READY 0xaa 55 56 // Commands (only the ones we use) 57 58 #define SB_SET_OUTPUT_RATE 0x41 // DSP v4.xx only 59 #define SB_SET_INPUT_RATE 0x42 // DSP v4.xx only 60 #define SB_SET_BLOCK_SIZE 0x48 // DSP v2.00 + 61 #define SB_ENABLE_SPEAKER 0xd1 62 #define SB_DISABLE_SPEAKER 0xd3 63 #define SB_GET_SPEAKER_STATUS 0xd8 // DSP v2.00 + 64 #define SB_GET_DSP_VERSION 0xe1 65 66 67 // Hmm... These are a weenie bit trickier than MPU401... 68 69 #define SB_WRITE_RESET(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp+0x6, x) 70 #define SB_READ_DATA(bp) READ_PORT_UCHAR((PUCHAR) bp+0xa) 71 #define SB_WRITE_DATA(bp, x) WRITE_PORT_UCHAR((PUCHAR) bp+0xc, x) 72 #define SB_READ_WRITESTATUS(bp) READ_PORT_UCHAR((PUCHAR) bp+0xc) 73 #define SB_READ_READSTATUS(bp) READ_PORT_UCHAR((PUCHAR) bp+0xe) 74 75 // Flow control 76 77 #define SB_READY_TO_SEND(bp) \ 78 SB_READ_WRITESTATUS(bp) & 0x80 79 80 #define SB_READY_TO_RECEIVE(bp) \ 81 SB_READ_READSTATUS(bp) & 0x80 82 83 84 #define SB_WRITE_BYTE(bp, x) \ 85 if (WaitToSend(bp)) SB_WRITE_DATA(bp, x) 86 87 //#define MPU401_READ(bp) 88 // if (WaitToRead(bp)) ... ??? 89 90 /* 91 DEVICE_EXTENSION contains the settings for each individual device 92 */ 93 94 typedef struct _DEVICE_EXTENSION 95 { 96 PWSTR RegistryPath; 97 PDRIVER_OBJECT DriverObject; 98 ULONG Port; 99 ULONG IRQ; 100 ULONG DMA; 101 ULONG BufferSize; 102 PADAPTER_OBJECT Adapter; 103 PMDL Mdl; 104 PCHAR VirtualBuffer; 105 PHYSICAL_ADDRESS Buffer; 106 } DEVICE_EXTENSION, *PDEVICE_EXTENSION; 107 108 /* 109 DEVICE_INSTANCE contains ??? 110 */ 111 112 typedef struct _DEVICE_INSTANCE 113 { 114 // pPrevGDI 115 PDRIVER_OBJECT DriverObject; 116 } DEVICE_INSTANCE, *PDEVICE_INSTANCE; 117 118 /* 119 CONFIG contains device parameters (port/IRQ) 120 THIS STRUCTURE IS REDUNDANT 121 */ 122 123 //typedef struct _CONFIG 124 //{ 125 // ULONG Port; 126 // ULONG IRQ; 127 //} CONFIG, *PCONFIG; 128 129 /* 130 Some callback typedefs 131 */ 132 133 typedef NTSTATUS REGISTRY_CALLBACK_ROUTINE(PWSTR RegistryPath, PVOID Context); 134 typedef REGISTRY_CALLBACK_ROUTINE *PREGISTRY_CALLBACK_ROUTINE; 135 136 137 /* 138 Prototypes for functions in portio.c : 139 */ 140 141 BOOLEAN WaitToSend(ULONG BasePort); 142 BOOLEAN WaitToReceive(ULONG BasePort); 143 USHORT InitSoundCard(ULONG BasePort); 144 145 /* 146 Prototypes for functions in settings.c : 147 */ 148 149 NTSTATUS NTAPI EnumDeviceKeys( 150 IN PUNICODE_STRING RegistryPath, 151 IN PWSTR SubKey, 152 IN PREGISTRY_CALLBACK_ROUTINE Callback, 153 IN PVOID Context); 154 155 NTSTATUS NTAPI LoadSettings( 156 IN PWSTR ValueName, 157 IN ULONG ValueType, 158 IN PVOID ValueData, 159 IN ULONG ValueLength, 160 IN PVOID Context, 161 IN PVOID EntryContext); 162 163 164 165 166 BOOLEAN CreateDMA(PDEVICE_OBJECT DeviceObject); 167 168 169 170 VOID SetOutputSampleRate(ULONG BasePort, ULONG SampleRate); 171 VOID EnableSpeaker(ULONG BasePort, BOOLEAN SpeakerOn); 172 BOOLEAN IsSpeakerEnabled(ULONG BasePort); 173 VOID BeginPlayback(ULONG BasePort, ULONG BitDepth, ULONG Channels, ULONG BlockSize); 174