ReactOS  0.4.15-dev-3453-gff89651
driver.h
Go to the documentation of this file.
1 /*
2  * Copyright 2007-2012, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  * Ithamar Adema, ithamar AT unet DOT nl
7  * Axel Dörfler, axeld@pinc-software.de
8  */
9 #ifndef _HDA_H_
10 #define _HDA_H_
11 
12 #ifndef __REACTOS__
13 #include <KernelExport.h>
14 #include <Drivers.h>
15 #include <PCI.h>
16 #include <PCI_x86.h>
17 
18 #include <string.h>
19 #include <stdlib.h>
20 
21 #ifndef HAIKU_TARGET_PLATFORM_HAIKU
22 # define DEVFS_PATH_FORMAT "audio/multi/hda/%lu"
23 # include <multi_audio.h>
24 #else
25 # define DEVFS_PATH_FORMAT "audio/hmulti/hda/%lu"
26 # include <hmulti_audio.h>
27 #endif
28 #endif
29 
30 #include "hda_controller_defs.h"
31 #include "hda_codec_defs.h"
32 
33 #define MAX_CARDS 4
34 
35 /* values for the class_sub field for class_base = 0x04 (multimedia device) */
36 #ifndef __HAIKU__
37 # define PCI_hd_audio 3
38 #endif
39 
40 #define HDA_MAX_AUDIO_GROUPS 15
41 #define HDA_MAX_CODECS 15
42 #define HDA_MAX_STREAMS 16
43 #define MAX_CODEC_RESPONSES 16
44 #define MAX_CODEC_UNSOL_RESPONSES 16
45 #define MAX_INPUTS 32
46 #define MAX_IO_WIDGETS 8
47 #define MAX_ASSOCIATIONS 16
48 #define MAX_ASSOCIATION_PINS 16
49 
50 #define STREAM_MAX_BUFFERS 10
51 #define STREAM_MIN_BUFFERS 2
52 
53 
54 enum {
57 };
58 
59 struct hda_codec;
60 struct hda_stream;
61 struct hda_multi;
62 
68 #ifndef __REACTOS__
72  const char* devfs_path;
73 
74  area_id regs_area;
75  vuint8* regs;
77  bool msi;
79 
84 
93 
97 
100 
102  {
103  return *(regs + reg);
104  }
105 
107  {
108  return *(vuint16*)(regs + reg);
109  }
110 
112  {
113  return *(vuint32*)(regs + reg);
114  }
115 
117  {
118  *(regs + reg) = value;
119  }
120 
122  {
123  *(vuint16*)(regs + reg) = value;
124  }
125 
127  {
128  *(vuint32*)(regs + reg) = value;
129  }
130 
132  {
133  uint8 temp = Read8(reg);
134  temp &= ~mask;
135  temp |= value;
136  Write8(reg, temp);
137  }
138 
140  {
141  uint16 temp = Read16(reg);
142  temp &= ~mask;
143  temp |= value;
144  Write16(reg, temp);
145  }
146 
148  {
149  uint32 temp = Read32(reg);
150  temp &= ~mask;
151  temp |= value;
152  Write32(reg, temp);
153  }
154 };
155 
159 struct hda_stream {
160  uint32 id; /* HDA controller stream # */
161  uint32 offset; /* HDA I/O/B descriptor offset */
162  bool running;
163  spinlock lock; /* Write lock */
165 
167 
168  uint32 pin_widget; /* PIN Widget ID */
169  uint32 io_widgets[MAX_IO_WIDGETS]; /* Input/Output Converter Widget ID */
171 
174 
177  uint32 buffer_length; /* size of buffer in samples */
178  uint32 buffer_size; /* actual (aligned) size of buffer in bytes */
181  /* Virtual addresses for buffer */
183  /* Physical addresses for buffer */
184 
185  volatile bigtime_t real_time;
188  volatile int32 buffer_cycle;
189 
190  uint32 rate, bps; /* Samplerate & bits per sample */
191 
192  area_id buffer_area;
194  phys_addr_t physical_buffer_descriptors; /* BDL physical address */
195 
198 
200  {
202  }
203 
205  {
207  }
208 
210  {
212  }
213 
215  {
217  }
218 
220  {
221  *(vuint16*)(controller->regs + HDAC_STREAM_BASE + offset + reg) = value;
222  }
223 
225  {
226  *(vuint32*)(controller->regs + HDAC_STREAM_BASE + offset + reg) = value;
227  }
228 };
229 
230 struct hda_widget {
232 
237 
240 
241  struct {
245  } capabilities;
246 
247  union {
248  struct {
251  } io;
252  struct {
253  } mixer;
254  struct {
257  } pin;
258  } d;
259 };
260 
263  bool enabled;
266 };
267 #endif
268 
269 #define WIDGET_FLAG_OUTPUT_PATH 0x01
270 #define WIDGET_FLAG_INPUT_PATH 0x02
271 #define WIDGET_FLAG_WIDGET_PATH 0x04
272 
278 #ifndef __REACTOS__
282 
283  /* Multi Audio API data */
286 
289 
292 
295 
297 };
298 
306 struct hda_codec {
314 
316 
317  sem_id response_sem;
320 
325 
328 
330 };
331 
332 
333 #define MULTI_CONTROL_FIRSTID 1024
334 #define MULTI_CONTROL_MASTERID 0
335 #define MULTI_MAX_CONTROLS 128
336 #define MULTI_MAX_CHANNELS 128
337 
342  bool input;
347  multi_mix_control mix_control;
348 };
349 
350 
351 struct hda_multi {
355 
356  multi_channel_info chans[MULTI_MAX_CHANNELS];
362 };
363 
364 
365 /* driver.c */
366 extern device_hooks gDriverHooks;
367 extern pci_module_info* gPci;
368 extern pci_x86_module_info* gPCIx86Module;
370 extern uint32 gNumCards;
371 
372 /* hda_codec.c */
373 const char* get_widget_location(uint32 location);
375 
376 status_t hda_audio_group_get_widgets(hda_audio_group* audioGroup,
377  hda_stream* stream);
378 hda_codec* hda_codec_new(hda_controller* controller, uint32 cad);
379 void hda_codec_delete(hda_codec* codec);
380 
381 /* hda_multi_audio.c */
382 status_t multi_audio_control(void* cookie, uint32 op, void* arg, size_t length);
383 
384 /* hda_controller.c: Basic controller support */
385 status_t hda_hw_init(hda_controller* controller);
386 void hda_hw_stop(hda_controller* controller);
387 void hda_hw_uninit(hda_controller* controller);
388 status_t hda_send_verbs(hda_codec* codec, corb_t* verbs, uint32* responses,
389  uint32 count);
390 status_t hda_verb_write(hda_codec* codec, uint32 nid, uint32 vid, uint16 payload);
391 status_t hda_verb_read(hda_codec* codec, uint32 nid, uint32 vid, uint32 *response);
392 
393 /* hda_controller.c: Stream support */
394 hda_stream* hda_stream_new(hda_audio_group* audioGroup, int type);
396 status_t hda_stream_setup_buffers(hda_audio_group* audioGroup,
397  hda_stream* stream, const char* desc);
398 status_t hda_stream_start(hda_controller* controller, hda_stream* stream);
399 status_t hda_stream_stop(hda_controller* controller, hda_stream* stream);
400 #endif
401 
402 #endif /* _HDA_H_ */
sem_id response_sem
Definition: driver.h:317
uint32 num_inputs
Definition: driver.h:233
unsigned long long uint64
Definition: platform.h:18
uint16 codec_status
Definition: driver.h:80
#define MAX_CARDS
Definition: driver.h:33
uint32 input_amplifier
Definition: driver.h:244
status_t hda_audio_group_get_widgets(hda_audio_group *audioGroup, hda_stream *stream)
uint8 revision
Definition: driver.h:311
uint32 Read32(uint32 reg)
Definition: driver.h:209
rirb_t * rirb
Definition: driver.h:91
void Write8(uint32 reg, uint8 value)
Definition: driver.h:214
Definition: pdh_main.c:93
uint32 io_widgets[MAX_IO_WIDGETS]
Definition: driver.h:169
#define HDA_MAX_AUDIO_GROUPS
Definition: driver.h:40
uint32 association_count
Definition: driver.h:290
uint32 gpio
Definition: driver.h:291
uint8 stepping
Definition: driver.h:312
uint32 input_channel_count
Definition: driver.h:358
status_t hda_send_verbs(hda_codec *codec, corb_t *verbs, uint32 *responses, uint32 count)
uint8 Read8(uint32 reg)
Definition: driver.h:199
uint32 sample_format
Definition: driver.h:173
struct pci_info pci_info
Definition: driver.h:70
uint32 aux_bus_channel_count
Definition: driver.h:361
area_id buffer_descriptors_area
Definition: driver.h:193
void hda_hw_uninit(hda_controller *controller)
area_id regs_area
Definition: driver.h:74
hda_codec * hda_codec_new(hda_controller *controller, uint32 cad)
NOTIFYICONDATA nid
Definition: magnifier.c:44
status_t hda_hw_init(hda_controller *controller)
uint32 input_bus_channel_count
Definition: driver.h:360
void Write32(uint32 reg, uint32 value)
Definition: driver.h:224
unsigned int uint32
Definition: types.h:32
GLuint GLuint GLsizei count
Definition: gl.h:1545
uint32 corb_length
Definition: driver.h:85
uint16 Read16(uint32 reg)
Definition: driver.h:106
uint32 unsol_response_write
Definition: driver.h:324
#define MAX_CODEC_UNSOL_RESPONSES
Definition: driver.h:44
bool use_dma_position
Definition: driver.h:197
bool running
Definition: driver.h:162
hda_widget widget
Definition: driver.h:281
int32 active_input
Definition: driver.h:234
void ReadModifyWrite16(uint32 reg, uint16 mask, uint16 value)
Definition: driver.h:139
uint32 num_buffers
Definition: driver.h:175
uint32 pm
Definition: driver.h:239
hda_controller * controller
Definition: driver.h:166
corb_t * corb
Definition: driver.h:90
const GLuint * buffers
Definition: glext.h:5916
#define MAX_ASSOCIATION_PINS
Definition: driver.h:48
hda_codec * codec
Definition: driver.h:280
#define MULTI_MAX_CONTROLS
Definition: driver.h:335
status_t hda_stream_start(hda_controller *controller, hda_stream *stream)
void Write32(uint32 reg, uint32 value)
Definition: driver.h:126
hda_multi * multi
Definition: driver.h:339
multi_channel_info chans[MULTI_MAX_CHANNELS]
Definition: driver.h:356
uint32 gNumCards
uint32 last_link_frame_position
Definition: driver.h:187
area_id buffer_area
Definition: driver.h:192
uint32 num_codecs
Definition: driver.h:96
hda_codec * active_codec
Definition: driver.h:95
uint32 type
Definition: driver.h:164
hda_audio_group * group
Definition: driver.h:352
#define HDAC_STREAM_BASE
uint32 flags
Definition: driver.h:236
uint8 Read8(uint32 reg)
Definition: driver.h:101
GLenum GLint GLuint mask
Definition: glext.h:6028
void ReadModifyWrite8(uint32 reg, uint8 mask, uint8 value)
Definition: driver.h:131
hda_audio_group * audio_groups[HDA_MAX_AUDIO_GROUPS]
Definition: driver.h:326
void ReadModifyWrite32(uint32 reg, uint32 mask, uint32 value)
Definition: driver.h:147
static const WCHAR desc[]
Definition: protectdata.c:36
hda_widget * hda_audio_group_get_widget(hda_audio_group *audioGroup, uint32 nodeID)
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
#define MAX_CODEC_RESPONSES
Definition: driver.h:43
#define MAX_INPUTS
Definition: driver.h:45
uint32 formats
Definition: driver.h:249
uint32 rate
Definition: driver.h:190
uint8 minor
Definition: driver.h:310
uint32 buffer_size
Definition: driver.h:178
hda_codec * codecs[HDA_MAX_CODECS+1]
Definition: driver.h:94
uint32 capabilities
Definition: driver.h:255
uint32 corb_t
uint32 unsol_responses[MAX_CODEC_UNSOL_RESPONSES]
Definition: driver.h:323
hda_widget_type
bool msi
Definition: driver.h:77
uint32 buffer_length
Definition: driver.h:177
thread_id unsol_response_thread
Definition: driver.h:322
uint8 addr
Definition: driver.h:313
uint32 unsol_response_read
Definition: driver.h:324
struct hda_widget::@1400::@1401 io
vuint8 * regs
Definition: driver.h:75
uint32 inputs[MAX_INPUTS]
Definition: driver.h:235
uint32 sample_rate
Definition: driver.h:172
struct hda_widget::@1399 capabilities
uint32 rates
Definition: driver.h:250
uint32 offset
Definition: driver.h:161
uint32 num_output_streams
Definition: driver.h:82
uint32 pin_count
Definition: driver.h:264
GLintptr offset
Definition: glext.h:5920
hda_widget * widgets
Definition: driver.h:293
uint32 Read32(uint32 reg)
Definition: driver.h:111
hda_stream * streams[HDA_MAX_STREAMS]
Definition: driver.h:98
void Write16(uint32 reg, uint16 value)
Definition: driver.h:219
uint32 bps
Definition: driver.h:190
UINT op
Definition: effect.c:236
struct hda_widget::@1400::@1403 pin
unsigned char uint8
Definition: types.h:28
int32 opened
Definition: driver.h:71
static int reg
Definition: i386-dis.c:1283
hda_stream * record_stream
Definition: driver.h:285
volatile int32 buffer_cycle
Definition: driver.h:188
uint16 product_id
Definition: driver.h:308
device_hooks gDriverHooks
uint32 config
Definition: driver.h:256
Definition: parse.h:22
uint32 id
Definition: driver.h:160
#define STREAM_MAX_BUFFERS
Definition: driver.h:50
bool dma_snooping
Definition: driver.h:78
uint32 audio
Definition: driver.h:242
status_t hda_verb_read(hda_codec *codec, uint32 nid, uint32 vid, uint32 *response)
#define HDA_MAX_STREAMS
Definition: driver.h:42
area_id corb_rirb_pos_area
Definition: driver.h:89
hda_multi_mixer_control controls[MULTI_MAX_CONTROLS]
Definition: driver.h:353
GLsizei const GLfloat * value
Definition: glext.h:6069
#define MAX_IO_WIDGETS
Definition: driver.h:46
union hda_widget::@1400 d
uint32 node_id
Definition: driver.h:231
hda_stream * playback_stream
Definition: driver.h:284
pci_x86_module_info * gPCIx86Module
uint32 rirb_length
Definition: driver.h:86
sem_id unsol_response_sem
Definition: driver.h:321
multi_mix_control mix_control
Definition: driver.h:347
status_t multi_audio_control(void *cookie, uint32 op, void *arg, size_t length)
uint32 pin_widget
Definition: driver.h:168
void Write8(uint32 reg, uint8 value)
Definition: driver.h:116
#define HDA_MAX_CODECS
Definition: driver.h:41
uint32 num_channels
Definition: driver.h:176
uint8 major
Definition: driver.h:309
spinlock lock
Definition: driver.h:163
static calc_node_t temp
Definition: rpn_ieee.c:38
unsigned short uint16
Definition: types.h:30
uint32 response_count
Definition: driver.h:319
static DWORD thread_id
Definition: protocol.c:159
void hda_hw_stop(hda_controller *controller)
Definition: cookie.c:33
uint32 widget_start
Definition: driver.h:287
uint32 widget_count
Definition: driver.h:288
struct hda_widget::@1400::@1402 mixer
uint32 num_input_streams
Definition: driver.h:81
hda_widget_type type
Definition: driver.h:238
phys_addr_t physical_buffers[STREAM_MAX_BUFFERS]
Definition: driver.h:182
void Write16(uint32 reg, uint16 value)
Definition: driver.h:121
phys_addr_t physical_buffer_descriptors
Definition: driver.h:194
status_t hda_stream_stop(hda_controller *controller, hda_stream *stream)
uint32 * stream_positions
Definition: driver.h:92
long int32
Definition: platform.h:12
uint16 Read16(uint32 reg)
Definition: driver.h:204
hda_controller gCards[MAX_CARDS]
uint32 num_io_widgets
Definition: driver.h:170
pci_module_info * gPci
bool enabled
Definition: driver.h:263
uint16 vendor_id
Definition: driver.h:307
uint32 sample_size
Definition: driver.h:179
status_t hda_stream_setup_buffers(hda_audio_group *audioGroup, hda_stream *stream, const char *desc)
uint32 output_bus_channel_count
Definition: driver.h:359
volatile uint64 frames_count
Definition: driver.h:186
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
hda_multi * multi
Definition: driver.h:296
uint32 pins[MAX_ASSOCIATION_PINS]
Definition: driver.h:265
uint32 irq
Definition: driver.h:76
uint32 index
Definition: driver.h:262
struct hda_controller * controller
Definition: driver.h:329
uint32 num_bidir_streams
Definition: driver.h:83
uint32 corb_write_pos
Definition: driver.h:88
int32 incorrect_position_count
Definition: driver.h:196
uint32 control_count
Definition: driver.h:354
hda_association associations[MAX_ASSOCIATIONS]
Definition: driver.h:294
uint32 rirb_read_pos
Definition: driver.h:87
uint32 responses[MAX_CODEC_RESPONSES]
Definition: driver.h:318
const char * get_widget_location(uint32 location)
#define MAX_ASSOCIATIONS
Definition: driver.h:47
const char * devfs_path
Definition: driver.h:72
volatile bigtime_t real_time
Definition: driver.h:185
uint32 output_amplifier
Definition: driver.h:243
status_t hda_verb_write(hda_codec *codec, uint32 nid, uint32 vid, uint16 payload)
void hda_stream_delete(hda_stream *stream)
uint32 output_channel_count
Definition: driver.h:357
hda_stream * hda_stream_new(hda_audio_group *audioGroup, int type)
uint32 quirks
Definition: driver.h:315
sem_id buffer_ready_sem
Definition: driver.h:99
void hda_codec_delete(hda_codec *codec)
#define MULTI_MAX_CHANNELS
Definition: driver.h:336
uint32 num_audio_groups
Definition: driver.h:327