Rev 168 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
168 | serge | 1 | |
2 | |||
3 | |||
4 | |||
5 | |||
6 | |||
7 | |||
8 | |||
9 | |||
10 | |||
11 | ; FEDCBA9876543210 |
||
12 | VALID_IRQ equ 1100111011111000b |
||
13 | ATTCH_IRQ equ 0000111010101000b |
||
14 | |||
15 | |||
16 | |||
17 | |||
18 | |||
19 | |||
20 | BIT1 EQU 0x00000002 |
||
21 | BIT2 EQU 0x00000004 |
||
22 | BIT3 EQU 0x00000008 |
||
23 | BIT4 EQU 0x00000010 |
||
24 | BIT5 EQU 0x00000020 |
||
25 | BIT6 EQU 0x00000040 |
||
26 | BIT7 EQU 0x00000080 |
||
27 | BIT8 EQU 0x00000100 |
||
28 | BIT9 EQU 0x00000200 |
||
29 | BIT10 EQU 0x00000400 |
||
30 | BIT11 EQU 0x00000800 |
||
31 | BIT12 EQU 0x00001000 |
||
32 | BIT13 EQU 0x00002000 |
||
33 | BIT14 EQU 0x00004000 |
||
34 | BIT15 EQU 0x00008000 |
||
35 | BIT16 EQU 0x00010000 |
||
36 | BIT17 EQU 0x00020000 |
||
37 | BIT18 EQU 0x00040000 |
||
38 | BIT19 EQU 0x00080000 |
||
39 | BIT20 EQU 0x00100000 |
||
40 | BIT21 EQU 0x00200000 |
||
41 | BIT22 EQU 0x00400000 |
||
42 | BIT23 EQU 0x00800000 |
||
43 | BIT24 EQU 0x00100000 |
||
44 | BIT25 EQU 0x02000000 |
||
45 | BIT26 EQU 0x04000000 |
||
46 | BIT27 EQU 0x08000000 |
||
47 | BIT28 EQU 0x10000000 |
||
48 | BIT29 EQU 0x20000000 |
||
49 | BIT30 EQU 0x40000000 |
||
50 | BIT31 EQU 0x80000000 |
||
51 | |||
52 | |||
53 | VID_NVIDIA equ 0x10DE |
||
54 | |||
55 | |||
56 | CTRL_ICH0 equ 0x2425 |
||
57 | CTRL_ICH2 equ 0x2435 |
||
58 | CTRL_ICH3 equ 0x2445 |
||
59 | CTRL_ICH4 equ 0x24C5 |
||
60 | CTRL_ICH5 equ 0x24D5 |
||
61 | CTRL_ICH6 equ 0x266E |
||
62 | CTRL_ICH7 equ 0x27DE |
||
63 | |||
64 | |||
65 | CTRL_NFORCE2 equ 0x006A |
||
66 | CTRL_NFORCE3 equ 0x00DA |
||
67 | |||
68 | |||
69 | |||
70 | PCM_OUT_CR_REG equ 0x1b ; PCM out Control Register |
||
71 | PCM_OUT_LVI_REG equ 0x15 ; PCM last valid index |
||
72 | PCM_OUT_SR_REG equ 0x16 ; PCM out Status register |
||
73 | PCM_OUT_PIV_REG equ 0x1a |
||
74 | PCM_OUT_CIV_REG equ 0x14 ; PCM out current index |
||
75 | |||
76 | |||
77 | MC_IN_CR_REG equ 0x2b ; MIC in Control Register |
||
78 | RR equ BIT1 ; reset registers. Nukes all regs |
||
79 | |||
80 | |||
81 | CODEC_AUX_VOL equ 0x04 ; |
||
82 | CODEC_PCM_OUT_REG equ 18h ; PCM output volume |
||
83 | CODEC_EXT_AUDIO_REG equ 28h ; extended audio |
||
84 | CODEC_EXT_AUDIO_CTRL_REG equ 2ah ; extended audio control |
||
85 | CODEC_PCM_FRONT_DACRATE_REG equ 2ch ; PCM out sample rate |
||
86 | CODEC_PCM_SURND_DACRATE_REG equ 2eh ; surround sound sample rate |
||
87 | CODEC_PCM_LFE_DACRATE_REG equ 30h ; LFE sample rate |
||
88 | |||
89 | |||
90 | CTRL_STAT equ 0x30 ; Global Status |
||
91 | CTRL_CAS equ 0x34 ; Codec Access Semiphore |
||
92 | |||
93 | |||
94 | |||
95 | |||
96 | |||
97 | |||
98 | |||
99 | |||
100 | CTRL_CNT_AC_OFF equ 0x00000008 ; ACLINK Off |
||
101 | CTRL_CNT_WARM equ 0x00000004 ; AC97 Warm Reset |
||
102 | CTRL_CNT_COLD equ 0x00000002 ; AC97 Cold Reset |
||
103 | CTRL_CNT_GIE equ 0x00000001 ; GPI Interrupt Enable |
||
104 | |||
105 | |||
106 | CODEC_REG_ST equ 0x26 |
||
107 | |||
108 | |||
109 | DEV_STOP equ 2 |
||
110 | DEV_CALLBACK equ 3 |
||
111 | DEV_SET_BUFF equ 4 |
||
112 | DEV_NOTIFY equ 5 |
||
113 | DEV_SET_MASTERVOL equ 6 |
||
114 | DEV_GET_MASTERVOL equ 7 |
||
115 | DEV_GET_INFO equ 8 |
||
116 | |||
117 | |||
118 | { .bus dd ? |
||
188 | serge | 119 | .devfn dd ? |
120 | |||
168 | serge | 121 | |
188 | serge | 122 | .dev_id dd ? |
123 | .pci_cmd dd ? |
||
124 | .pci_stat dd ? |
||
125 | |||
168 | serge | 126 | |
188 | serge | 127 | .codec_mem_base dd ? |
128 | |||
168 | serge | 129 | |
188 | serge | 130 | .ctrl_mem_base dd ? |
131 | .cfg_reg dd ? |
||
132 | .int_line dd ? |
||
133 | |||
168 | serge | 134 | |
188 | serge | 135 | .ctrl_ids dd ? ;hub id string |
136 | |||
168 | serge | 137 | |
188 | serge | 138 | |
168 | serge | 139 | |
188 | serge | 140 | .notify_task dd ? |
141 | |||
168 | serge | 142 | |
188 | serge | 143 | .ctrl_setup dd ? |
144 | .user_callback dd ? |
||
145 | .codec_read16 dd ? |
||
146 | .codec_write16 dd ? |
||
147 | |||
168 | serge | 148 | |
188 | serge | 149 | .ctrl_read16 dd ? |
150 | .ctrl_read32 dd ? |
||
151 | |||
168 | serge | 152 | |
188 | serge | 153 | .ctrl_write16 dd ? |
154 | .ctrl_write32 dd ? |
||
155 | } |
||
168 | serge | 156 | |
157 | |||
158 | { |
||
159 | .chip_id dd ? |
||
188 | serge | 160 | .flags dd ? |
161 | .status dd ? |
||
162 | |||
168 | serge | 163 | |
188 | serge | 164 | .chip_ids dd ? ;chip model string |
165 | |||
168 | serge | 166 | |
188 | serge | 167 | dd ? |
168 | |||
168 | serge | 169 | |
188 | serge | 170 | .reg_master_vol dw ? ;0x02 |
171 | .reg_aux_out_vol dw ? ;0x04 |
||
172 | .reg_mone_vol dw ? ;0x06 |
||
173 | .reg_master_tone dw ? ;0x08 |
||
174 | .reg_beep_vol dw ? ;0x0A |
||
175 | .reg_phone_vol dw ? ;0x0C |
||
176 | .reg_mic_vol dw ? ;0x0E |
||
177 | .reg_line_in_vol dw ? ;0x10 |
||
178 | .reg_cd_vol dw ? ;0x12 |
||
179 | .reg_video_vol dw ? ;0x14 |
||
180 | .reg_aux_in_vol dw ? ;0x16 |
||
181 | .reg_pcm_out_vol dw ? ;0x18 |
||
182 | .reg_rec_select dw ? ;0x1A |
||
183 | .reg_rec_gain dw ? ;0x1C |
||
184 | .reg_rec_gain_mic dw ? ;0x1E |
||
185 | .reg_gen dw ? ;0x20 |
||
186 | .reg_3d_ctrl dw ? ;0X22 |
||
187 | .reg_page dw ? ;0X24 |
||
188 | .reg_powerdown dw ? ;0x26 |
||
189 | .reg_ext_audio dw ? ;0x28 |
||
190 | .reg_ext_st dw ? ;0x2a |
||
191 | .reg_pcm_front_rate dw ? ;0x2c |
||
192 | .reg_pcm_surr_rate dw ? ;0x2e |
||
193 | .reg_lfe_rate dw ? ;0x30 |
||
194 | .reg_pcm_in_rate dw ? ;0x32 |
||
195 | dw ? ;0x34 |
||
196 | .reg_cent_lfe_vol dw ? ;0x36 |
||
197 | .reg_surr_vol dw ? ;0x38 |
||
198 | .reg_spdif_ctrl dw ? ;0x3A |
||
199 | dw ? ;0x3C |
||
200 | dw ? ;0x3E |
||
201 | dw ? ;0x40 |
||
202 | dw ? ;0x42 |
||
203 | dw ? ;0x44 |
||
204 | dw ? ;0x46 |
||
205 | dw ? ;0x48 |
||
206 | dw ? ;0x4A |
||
207 | dw ? ;0x4C |
||
208 | dw ? ;0x4E |
||
209 | dw ? ;0x50 |
||
210 | dw ? ;0x52 |
||
211 | dw ? ;0x54 |
||
212 | dw ? ;0x56 |
||
213 | dw ? ;0x58 |
||
214 | dw ? ;0x5A |
||
215 | dw ? ;0x5C |
||
216 | dw ? ;0x5E |
||
217 | .reg_page_0 dw ? ;0x60 |
||
218 | .reg_page_1 dw ? ;0x62 |
||
219 | .reg_page_2 dw ? ;0x64 |
||
220 | .reg_page_3 dw ? ;0x66 |
||
221 | .reg_page_4 dw ? ;0x68 |
||
222 | .reg_page_5 dw ? ;0x6A |
||
223 | .reg_page_6 dw ? ;0x6C |
||
224 | .reg_page_7 dw ? ;0x6E |
||
225 | dw ? ;0x70 |
||
226 | dw ? ;0x72 |
||
227 | dw ? ;0x74 |
||
228 | dw ? ;0x76 |
||
229 | dw ? ;0x78 |
||
230 | dw ? ;0x7A |
||
231 | .reg_vendor_id_1 dw ? ;0x7C |
||
232 | .reg_vendor_id_2 dw ? ;0x7E |
||
233 | |||
168 | serge | 234 | |
235 | |||
188 | serge | 236 | .set_master_vol dd ? |
237 | } |
||
168 | serge | 238 | |
239 | |||
240 | { .pci_cmd dd ? |
||
241 | .irq dd ? |
||
242 | .glob_cntrl dd ? |
||
243 | .glob_sta dd ? |
||
244 | .codec_io_base dd ? |
||
245 | .ctrl_io_base dd ? |
||
246 | .codec_mem_base dd ? |
||
247 | .ctrl_mem_base dd ? |
||
248 | .codec_id dd ? |
||
249 | } |
||
250 | |||
251 | |||
252 | { .handle dd ? |
||
253 | .io_code dd ? |
||
254 | .input dd ? |
||
255 | .inp_size dd ? |
||
256 | .output dd ? |
||
257 | .out_size dd ? |
||
258 | } |
||
259 | |||
260 | |||
261 | IOCTL IOCTL |
||
262 | end virtual |
||
263 | |||
264 | |||
265 | |||
266 | |||
267 | new_app_base equ 0x60400000; 0x01000000 |
||
268 | PROC_BASE equ OS_BASE+0x0080000 |
||
269 | |||
270 | |||
188 | serge | 271 | public STOP |
272 | public service_proc |
||
168 | serge | 273 | |
274 | |||
188 | serge | 275 | extrn SysMsgBoardStr |
276 | extrn PciApi |
||
277 | extrn PciRead32 |
||
278 | extrn PciRead8 |
||
279 | extrn PciWrite8 |
||
280 | extrn AllocKernelSpace |
||
281 | extrn MapPage |
||
282 | extrn RegService |
||
283 | extrn KernelAlloc |
||
284 | extrn GetPgAddr |
||
285 | extrn GetCurrentTask |
||
286 | |||
168 | serge | 287 | |
188 | serge | 288 | |
289 | |||
168 | serge | 290 | if DEBUG |
291 | mov esi, msgInit |
||
292 | call SysMsgBoardStr |
||
188 | serge | 293 | end if |
168 | serge | 294 | |
295 | |||
296 | test eax, eax |
||
297 | jz .fail |
||
298 | |||
299 | |||
300 | mov esi,[ctrl.vendor_ids] |
||
301 | call SysMsgBoardStr |
||
188 | serge | 302 | mov esi, [ctrl.ctrl_ids] |
168 | serge | 303 | call SysMsgBoardStr |
188 | serge | 304 | |
168 | serge | 305 | |
306 | |||
307 | |||
308 | test eax, eax |
||
309 | jz .fail |
||
310 | |||
311 | |||
312 | mov esi, msgInitCodec |
||
313 | call SysMsgBoardStr |
||
188 | serge | 314 | end if |
168 | serge | 315 | |
316 | |||
317 | test eax, eax |
||
318 | jz .fail |
||
319 | |||
320 | |||
321 | mov esi, [codec.ac_vendor_ids] |
||
322 | call SysMsgBoardStr |
||
188 | serge | 323 | |
168 | serge | 324 | |
325 | call SysMsgBoardStr |
||
188 | serge | 326 | end if |
168 | serge | 327 | |
328 | |||
329 | call setup_codec |
||
330 | |||
331 | |||
332 | call SysMsgBoardStr |
||
188 | serge | 333 | |
168 | serge | 334 | |
335 | |||
336 | |||
337 | |||
338 | |||
339 | ; cmp eax, -1 |
||
340 | ; jz .fail |
||
341 | |||
342 | |||
343 | ; call remap_irq |
||
344 | ; end if |
||
345 | |||
346 | |||
347 | mov ebx, [ctrl.int_line] |
||
348 | mov esi, msgInvIRQ |
||
349 | bt eax, ebx |
||
350 | jnc .fail |
||
351 | mov eax, ATTCH_IRQ |
||
352 | mov esi, msgAttchIRQ |
||
353 | bt eax, ebx |
||
354 | jnc .fail |
||
355 | |||
356 | |||
188 | serge | 357 | stdcall RegService, sz_sound_srv, service_proc |
358 | ret |
||
168 | serge | 359 | .fail: |
360 | if DEBUG |
||
361 | mov esi, msgFail |
||
362 | call SysMsgBoardStr |
||
188 | serge | 363 | end if |
168 | serge | 364 | xor eax, eax |
365 | STOP: |
||
188 | serge | 366 | ret |
367 | |||
168 | serge | 368 | |
369 | io_code equ IOCTL.io_code |
||
370 | input equ IOCTL.input |
||
371 | inp_size equ IOCTL.inp_size |
||
372 | output equ IOCTL.output |
||
373 | out_size equ IOCTL.out_size |
||
374 | |||
375 | |||
376 | proc service_proc stdcall, ioctl:dword |
||
377 | |||
378 | |||
379 | mov eax, [edi+io_code] |
||
380 | cmp eax, DEV_PLAY |
||
381 | jne @F |
||
382 | if DEBUG |
||
383 | mov esi, msgPlay |
||
384 | call SysMsgBoardStr |
||
188 | serge | 385 | end if |
168 | serge | 386 | call play |
387 | ret |
||
388 | @@: |
||
389 | cmp eax, DEV_STOP |
||
390 | jne @F |
||
391 | if DEBUG |
||
392 | mov esi, msgStop |
||
393 | call SysMsgBoardStr |
||
188 | serge | 394 | end if |
168 | serge | 395 | call stop |
396 | ret |
||
397 | @@: |
||
398 | cmp eax, DEV_CALLBACK |
||
399 | jne @F |
||
400 | mov ebx, [edi+input] |
||
401 | stdcall set_callback, [ebx] |
||
402 | ret |
||
403 | @@: |
||
404 | cmp eax, DEV_SET_MASTERVOL |
||
405 | jne @F |
||
406 | mov ebx, [edi+input] |
||
407 | stdcall set_master_vol, [ebx] |
||
408 | ret |
||
409 | @@: |
||
410 | cmp eax, DEV_GET_MASTERVOL |
||
411 | jne @F |
||
412 | mov ebx, [edi+output] |
||
413 | test ebx, ebx |
||
414 | jz .fail |
||
415 | |||
416 | |||
417 | ret |
||
418 | @@: |
||
419 | cmp eax, DEV_GET_INFO |
||
420 | jne @F |
||
421 | mov ebx, [edi+output] |
||
422 | stdcall get_dev_info, ebx |
||
423 | ret |
||
424 | @@: |
||
425 | .fail: |
||
426 | xor eax, eax |
||
427 | ret |
||
428 | endp |
||
429 | |||
430 | |||
431 | restore io_code |
||
432 | restore input |
||
433 | restore inp_size |
||
434 | restore output |
||
435 | restore out_size |
||
436 | |||
437 | |||
438 | |||
439 | proc remap_irq ;for Intel chipsets ONLY !!! |
||
440 | mov eax, VALID_IRQ |
||
441 | bt eax, IRQ_LINE |
||
442 | jnc .exit |
||
443 | |||
444 | |||
445 | in ax,dx |
||
446 | bts ax, IRQ_LINE |
||
447 | out dx, aX |
||
448 | |||
449 | |||
188 | serge | 450 | mov [ctrl.int_line], IRQ_LINE |
168 | serge | 451 | |
452 | |||
453 | ret |
||
454 | endp |
||
455 | |||
456 | |||
457 | proc ac97_irq |
||
458 | |||
459 | |||
460 | ; mov esi, msgIRQ |
||
461 | ; call SysMsgBoardStr |
||
188 | serge | 462 | ; end if |
168 | serge | 463 | |
464 | |||
465 | mov al, 0x14 |
||
466 | call [ctrl.ctrl_write8] |
||
467 | |||
468 | |||
469 | mov edx, PCM_OUT_SR_REG |
||
470 | call [ctrl.ctrl_write16] |
||
471 | |||
472 | |||
473 | call [ctrl.ctrl_read8] |
||
474 | |||
475 | |||
476 | cmp eax, [civ_val] |
||
477 | je .skip |
||
478 | |||
479 | |||
480 | dec eax |
||
481 | and eax, 0x1F |
||
482 | mov [ctrl.lvi_reg], eax |
||
483 | |||
484 | |||
485 | call [ctrl.ctrl_write8] |
||
486 | |||
487 | |||
488 | mov ax, 0x1D |
||
489 | call [ctrl.ctrl_write8] |
||
490 | |||
491 | |||
492 | add eax, 2 |
||
493 | and eax, 31 |
||
494 | mov ebx, dword [buff_list+eax*4] |
||
495 | |||
496 | |||
497 | je @f |
||
498 | |||
499 | |||
500 | @@: |
||
501 | ret |
||
502 | |||
503 | |||
504 | mov edx, PCM_OUT_CR_REG |
||
505 | mov ax, 0x1D |
||
506 | call [ctrl.ctrl_write8] |
||
507 | ret |
||
508 | endp |
||
509 | |||
510 | |||
511 | proc create_primary_buff |
||
512 | |||
513 | |||
188 | serge | 514 | mov [ctrl.buffer], eax |
168 | serge | 515 | |
516 | |||
517 | mov ecx, 0x10000/4 |
||
518 | xor eax, eax |
||
519 | cld |
||
520 | rep stosd |
||
521 | |||
522 | |||
188 | serge | 523 | |
168 | serge | 524 | |
525 | mov ecx, 4 |
||
526 | mov edi, pcmout_bdl |
||
527 | @@: |
||
528 | mov [edi], eax |
||
529 | mov [edi+4], ebx |
||
530 | |||
531 | |||
532 | mov [edi+4+32], ebx |
||
533 | |||
534 | |||
535 | mov [edi+4+64], ebx |
||
536 | |||
537 | |||
538 | mov [edi+4+96], ebx |
||
539 | |||
540 | |||
541 | mov [edi+4+128], ebx |
||
542 | |||
543 | |||
544 | mov [edi+4+160], ebx |
||
545 | |||
546 | |||
547 | mov [edi+4+192], ebx |
||
548 | |||
549 | |||
550 | mov [edi+4+224], ebx |
||
551 | |||
552 | |||
553 | add edi, 8 |
||
554 | loop @B |
||
555 | |||
556 | |||
557 | mov eax, [ctrl.buffer] |
||
558 | mov ecx, 4 |
||
559 | @@: |
||
560 | mov [edi], eax |
||
561 | mov [edi+16], eax |
||
562 | mov [edi+32], eax |
||
563 | mov [edi+48], eax |
||
564 | mov [edi+64], eax |
||
565 | mov [edi+80], eax |
||
566 | mov [edi+96], eax |
||
567 | mov [edi+112], eax |
||
568 | |||
569 | |||
570 | add edi, 4 |
||
571 | loop @B |
||
572 | |||
573 | |||
574 | stdcall GetPgAddr, ecx |
||
188 | serge | 575 | and ecx, 0xFFF |
168 | serge | 576 | add eax, ecx |
577 | |||
578 | |||
579 | call [ctrl.ctrl_write32] |
||
580 | |||
581 | |||
582 | mov [ctrl.lvi_reg], eax |
||
583 | mov edx, PCM_OUT_LVI_REG |
||
584 | call [ctrl.ctrl_write8] |
||
585 | |||
586 | |||
587 | endp |
||
588 | |||
589 | |||
590 | proc detect_controller |
||
591 | locals |
||
592 | last_bus dd ? |
||
593 | bus dd ? |
||
594 | devfn dd ? |
||
595 | endl |
||
596 | |||
597 | |||
598 | mov [bus], eax |
||
599 | inc eax |
||
600 | call PciApi |
||
188 | serge | 601 | cmp eax, -1 |
168 | serge | 602 | je .err |
603 | |||
604 | |||
605 | |||
606 | |||
607 | and [devfn], 0 |
||
608 | .next_dev: |
||
609 | stdcall PciRead32, [bus], [devfn], dword 0 |
||
188 | serge | 610 | test eax, eax |
168 | serge | 611 | jz .next |
612 | cmp eax, -1 |
||
613 | je .next |
||
614 | |||
615 | |||
616 | @@: |
||
617 | mov ebx, [edi] |
||
618 | test ebx, ebx |
||
619 | jz .next |
||
620 | |||
621 | |||
622 | je .found |
||
623 | add edi, 12 |
||
624 | jmp @B |
||
625 | |||
626 | |||
627 | cmp [devfn], 256 |
||
628 | jb .next_dev |
||
629 | mov eax, [bus] |
||
630 | inc eax |
||
631 | mov [bus], eax |
||
632 | cmp eax, [last_bus] |
||
633 | jna .next_bus |
||
634 | xor eax, eax |
||
635 | ret |
||
636 | .found: |
||
637 | mov ebx, [bus] |
||
638 | mov [ctrl.bus], ebx |
||
639 | |||
640 | |||
641 | mov [ctrl.devfn], ecx |
||
642 | |||
643 | |||
644 | and edx, 0xFFFF |
||
645 | mov [ctrl.vendor], edx |
||
646 | shr eax, 16 |
||
647 | mov [ctrl.dev_id], eax |
||
648 | |||
649 | |||
650 | mov [ctrl.ctrl_ids], ebx |
||
651 | mov esi, [edi+8] |
||
652 | mov [ctrl.ctrl_setup], esi |
||
653 | |||
654 | |||
655 | jne @F |
||
656 | mov [ctrl.vendor_ids], msg_Intel |
||
657 | ret |
||
658 | @@: |
||
659 | cmp ebx, VID_NVIDIA |
||
660 | jne @F |
||
661 | mov [ctrl.vendor_ids], msg_NVidia |
||
662 | @@: |
||
663 | mov [ctrl.vendor_ids], 0 ;something wrong ? |
||
664 | ret |
||
665 | .err: |
||
666 | xor eax, eax |
||
667 | ret |
||
668 | endp |
||
669 | |||
670 | |||
671 | proc get_LPC_bus ;for Intel chipsets ONLY !!! |
||
672 | locals |
||
673 | last_bus dd ? |
||
674 | bus dd ? |
||
675 | endl |
||
676 | |||
677 | |||
678 | mov [bus], eax |
||
679 | inc eax |
||
680 | call [PciApi] |
||
681 | cmp eax, -1 |
||
682 | je .err |
||
683 | |||
684 | |||
685 | .next_bus: |
||
686 | stdcall PciRead32, [bus], dword 0xF8, dword 0 |
||
188 | serge | 687 | test eax, eax |
168 | serge | 688 | jz .next |
689 | cmp eax, -1 |
||
690 | je .next |
||
691 | |||
692 | |||
693 | je .found |
||
694 | .next: |
||
695 | mov eax, [bus] |
||
696 | inc eax |
||
697 | cmp eax, [last_bus] |
||
698 | mov [bus], eax |
||
699 | jna .next_bus |
||
700 | .err: |
||
701 | xor eax, eax |
||
702 | dec eax |
||
703 | ret |
||
704 | .found: |
||
705 | mov eax, [bus] |
||
706 | ret |
||
707 | endp |
||
708 | |||
709 | |||
710 | proc init_controller |
||
711 | |||
712 | |||
188 | serge | 713 | mov ebx, eax |
168 | serge | 714 | and eax, 0xFFFF |
715 | mov [ctrl.pci_cmd], eax |
||
716 | shr ebx, 16 |
||
717 | mov [ctrl.pci_stat], ebx |
||
718 | |||
719 | |||
188 | serge | 720 | and eax,0xFFFE |
168 | serge | 721 | mov [ctrl.codec_io_base], eax |
722 | |||
723 | |||
188 | serge | 724 | and eax, 0xFFC0 |
168 | serge | 725 | mov [ctrl.ctrl_io_base], eax |
726 | |||
727 | |||
188 | serge | 728 | mov [ctrl.codec_mem_base], eax |
168 | serge | 729 | |
730 | |||
188 | serge | 731 | mov [ctrl.ctrl_mem_base], eax |
168 | serge | 732 | |
733 | |||
188 | serge | 734 | and eax, 0xFF |
168 | serge | 735 | mov [ctrl.int_line], eax |
736 | |||
737 | |||
188 | serge | 738 | and eax, 0xFF |
168 | serge | 739 | mov [ctrl.cfg_reg], eax |
740 | |||
741 | |||
742 | xor eax, eax |
||
743 | inc eax |
||
744 | ret |
||
745 | endp |
||
746 | |||
747 | |||
748 | proc set_ICH |
||
749 | mov [ctrl.codec_read16], codec_io_r16 ;virtual |
||
750 | mov [ctrl.codec_write16], codec_io_w16 ;virtual |
||
751 | |||
752 | |||
753 | mov [ctrl.ctrl_read16], ctrl_io_r16 ;virtual |
||
754 | mov [ctrl.ctrl_read32], ctrl_io_r32 ;virtual |
||
755 | |||
756 | |||
757 | mov [ctrl.ctrl_write16], ctrl_io_w16 ;virtual |
||
758 | mov [ctrl.ctrl_write32], ctrl_io_w32 ;virtual |
||
759 | ret |
||
760 | endp |
||
761 | |||
762 | |||
763 | PG_NOCACHE equ 0x018 |
||
764 | |||
765 | |||
766 | proc set_ICH4 |
||
767 | stdcall AllocKernelSpace, dword 0x2000 |
||
188 | serge | 768 | mov edi, eax |
168 | serge | 769 | stdcall MapPage, edi,[ctrl.codec_mem_base],PG_SW+PG_NOCACHE |
188 | serge | 770 | mov [ctrl.codec_mem_base], edi |
168 | serge | 771 | add edi, 0x1000 |
772 | stdcall MapPage, edi, [ctrl.ctrl_mem_base],PG_SW+PG_NOCACHE |
||
188 | serge | 773 | mov [ctrl.ctrl_mem_base], edi |
168 | serge | 774 | |
775 | |||
776 | mov [ctrl.codec_write16], codec_mem_w16 ;virtual |
||
777 | |||
778 | |||
779 | mov [ctrl.ctrl_read16], ctrl_mem_r16 ;virtual |
||
780 | mov [ctrl.ctrl_read32], ctrl_mem_r32 ;virtual |
||
781 | |||
782 | |||
783 | mov [ctrl.ctrl_write16], ctrl_mem_w16 ;virtual |
||
784 | mov [ctrl.ctrl_write32], ctrl_mem_w32 ;virtual |
||
785 | ret |
||
786 | endp |
||
787 | |||
788 | |||
789 | proc reset_controller |
||
790 | |||
791 | |||
792 | mov edx, PCM_IN_CR_REG |
||
793 | call [ctrl.ctrl_write8] |
||
794 | |||
795 | |||
796 | call [ctrl.ctrl_write8] |
||
797 | |||
798 | |||
799 | call [ctrl.ctrl_write8] |
||
800 | |||
801 | |||
802 | mov edx, PCM_IN_CR_REG |
||
803 | call [ctrl.ctrl_write8] |
||
804 | |||
805 | |||
806 | call [ctrl.ctrl_write8] |
||
807 | |||
808 | |||
809 | call [ctrl.ctrl_write8] |
||
810 | |||
811 | |||
812 | endp |
||
813 | |||
814 | |||
815 | proc init_codec |
||
816 | locals |
||
817 | counter dd ? |
||
818 | endl |
||
819 | |||
820 | |||
821 | and eax, eax |
||
822 | jz .err |
||
823 | |||
824 | |||
825 | call [ctrl.codec_write16] |
||
826 | |||
827 | |||
828 | mov edx, CODEC_REG_POWERDOWN |
||
829 | call [ctrl.codec_write16] |
||
830 | |||
831 | |||
832 | .wait: |
||
833 | mov edx, CODEC_REG_POWERDOWN |
||
834 | call [ctrl.codec_read16] |
||
835 | and eax, 0x0F |
||
836 | cmp eax, 0x0F |
||
837 | jz .ready |
||
838 | |||
839 | |||
840 | call StallExec |
||
841 | sub [counter] , 1 |
||
842 | jnz .wait |
||
843 | .err: |
||
844 | xor eax, eax ; timeout error |
||
845 | ret |
||
846 | .ready: |
||
847 | call detect_codec |
||
848 | |||
849 | |||
850 | inc eax |
||
851 | ret |
||
852 | endp |
||
853 | |||
854 | |||
855 | proc reset_codec |
||
856 | mov edx, GLOB_CTRL |
||
857 | call [ctrl.ctrl_read32] |
||
858 | |||
859 | |||
860 | jz .cold |
||
861 | |||
862 | |||
863 | jnc .ok |
||
864 | .cold: |
||
865 | call cold_reset |
||
866 | jnc .ok |
||
867 | |||
868 | |||
869 | mov esi, msgCFail |
||
870 | call SysMsgBoardStr |
||
188 | serge | 871 | end if |
168 | serge | 872 | xor eax, eax ; timeout error |
873 | ret |
||
874 | .ok: |
||
875 | if DEBUG |
||
876 | mov esi, msgResetOk |
||
877 | call SysMsgBoardStr |
||
188 | serge | 878 | end if |
168 | serge | 879 | |
880 | |||
881 | inc eax |
||
882 | ret |
||
883 | endp |
||
884 | |||
885 | |||
886 | proc warm_reset |
||
887 | locals |
||
888 | counter dd ? |
||
889 | endl |
||
890 | |||
891 | |||
892 | mov edx, GLOB_CTRL |
||
893 | call [ctrl.ctrl_write32] |
||
894 | |||
895 | |||
896 | mov esi, msgWarm |
||
897 | call SysMsgBoardStr |
||
188 | serge | 898 | end if |
168 | serge | 899 | |
900 | |||
901 | .wait: |
||
902 | mov eax, 100000 ; wait 100 ms |
||
903 | call StallExec |
||
904 | |||
905 | |||
906 | call [ctrl.ctrl_read32] |
||
907 | test eax, 4 |
||
908 | jz .ok |
||
909 | sub [counter], 1 |
||
910 | jnz .wait |
||
911 | |||
912 | |||
913 | mov esi, msgWRFail |
||
914 | call SysMsgBoardStr |
||
188 | serge | 915 | end if |
168 | serge | 916 | |
917 | |||
918 | ret |
||
919 | .ok: |
||
920 | mov edx, CTRL_STAT |
||
921 | call [ctrl.ctrl_read32] |
||
922 | and eax, CTRL_ST_CREADY |
||
923 | jz .fail |
||
924 | clc |
||
925 | ret |
||
926 | .fail: |
||
927 | stc |
||
928 | ret |
||
929 | endp |
||
930 | |||
931 | |||
932 | proc cold_reset |
||
933 | locals |
||
934 | counter dd ? |
||
935 | endl |
||
936 | |||
937 | |||
938 | mov edx, GLOB_CTRL |
||
939 | call [ctrl.ctrl_write32] |
||
940 | |||
941 | |||
942 | mov esi, msgCold |
||
943 | call SysMsgBoardStr |
||
188 | serge | 944 | end if |
168 | serge | 945 | |
946 | |||
947 | call StallExec |
||
948 | |||
949 | |||
950 | mov edx, GLOB_CTRL |
||
951 | call [ctrl.ctrl_write32] |
||
952 | |||
953 | |||
954 | .wait: |
||
955 | mov eax, 100000 ; wait 100 ms |
||
956 | call StallExec |
||
957 | |||
958 | |||
959 | call [ctrl.ctrl_read32] |
||
960 | test eax, 4 |
||
961 | jz .ok |
||
962 | sub [counter], 1 |
||
963 | jnz .wait |
||
964 | |||
965 | |||
966 | mov esi, msgCRFail |
||
967 | call SysMsgBoardStr |
||
188 | serge | 968 | end if |
168 | serge | 969 | stc |
970 | ret |
||
971 | .ok: |
||
972 | mov edx, CTRL_STAT |
||
973 | call [ctrl.ctrl_read32] |
||
974 | and eax, CTRL_ST_CREADY |
||
975 | jz .fail |
||
976 | clc |
||
977 | ret |
||
978 | .fail: |
||
979 | stc |
||
980 | ret |
||
981 | endp |
||
982 | |||
983 | |||
984 | proc play |
||
985 | |||
986 | |||
987 | mov [ctrl.lvi_reg], eax |
||
988 | mov edx, PCM_OUT_LVI_REG |
||
989 | call [ctrl.ctrl_write8] |
||
990 | |||
991 | |||
992 | mov ax, 0x1D |
||
993 | call [ctrl.ctrl_write8] |
||
994 | ret |
||
995 | endp |
||
996 | |||
997 | |||
998 | proc stop |
||
999 | mov edx, PCM_OUT_CR_REG |
||
1000 | mov ax, 0x14 |
||
1001 | call [ctrl.ctrl_write8] |
||
1002 | |||
1003 | |||
1004 | mov [ctrl.lvi_reg], eax |
||
1005 | mov edx, PCM_OUT_LVI_REG |
||
1006 | call [ctrl.ctrl_write8] |
||
1007 | |||
1008 | |||
1009 | endp |
||
1010 | |||
1011 | |||
1012 | proc get_dev_info stdcall, p_info:dword |
||
1013 | virtual at esi |
||
1014 | CTRL_INFO CTRL_INFO |
||
1015 | end virtual |
||
1016 | |||
1017 | |||
1018 | mov eax, [ctrl.int_line] |
||
1019 | mov ebx, [ctrl.codec_io_base] |
||
1020 | mov ecx, [ctrl.ctrl_io_base] |
||
1021 | mov edx, [ctrl.codec_mem_base] |
||
1022 | mov edi, [ctrl.ctrl_mem_base] |
||
1023 | |||
1024 | |||
1025 | mov [CTRL_INFO.codec_io_base], ebx |
||
1026 | mov [CTRL_INFO.ctrl_io_base], ecx |
||
1027 | mov [CTRL_INFO.codec_mem_base], edx |
||
1028 | mov [CTRL_INFO.ctrl_mem_base], edi |
||
1029 | |||
1030 | |||
1031 | mov [CTRL_INFO.codec_id], eax |
||
1032 | |||
1033 | |||
1034 | call [ctrl.ctrl_read32] |
||
1035 | mov [CTRL_INFO.glob_cntrl], eax |
||
1036 | |||
1037 | |||
1038 | call [ctrl.ctrl_read32] |
||
1039 | mov [CTRL_INFO.glob_sta], eax |
||
1040 | |||
1041 | |||
1042 | mov [CTRL_INFO.pci_cmd], ebx |
||
1043 | |||
1044 | |||
1045 | endp |
||
1046 | |||
1047 | |||
1048 | proc set_callback stdcall, handler:dword |
||
1049 | mov eax, [handler] |
||
1050 | mov [ctrl.user_callback], eax |
||
1051 | ret |
||
1052 | endp |
||
1053 | |||
1054 | |||
1055 | proc codec_read stdcall, ac_reg:dword ; reg = edx, reval = eax |
||
1056 | |||
1057 | |||
1058 | |||
1059 | |||
1060 | shr ebx, 1 |
||
1061 | bt [codec.shadow_flag], ebx |
||
1062 | jc .use_shadow |
||
1063 | |||
1064 | |||
1065 | mov ecx, eax |
||
1066 | |||
1067 | |||
1068 | call [ctrl.ctrl_read32] |
||
1069 | test eax, CTRL_ST_RCS |
||
1070 | jz .read_ok |
||
1071 | |||
1072 | |||
1073 | call [ctrl.ctrl_write32] |
||
1074 | xor eax,eax |
||
1075 | not eax ;timeout |
||
1076 | ret |
||
1077 | .read_ok: |
||
1078 | mov edx, [ac_reg] |
||
1079 | mov [codec.regs+edx], cx |
||
1080 | bts [codec.shadow_flag], ebx |
||
1081 | mov eax, ecx |
||
1082 | ret |
||
1083 | .use_shadow: |
||
1084 | movzx eax, word [codec.regs+edx] |
||
1085 | ret |
||
1086 | endp |
||
1087 | |||
1088 | |||
1089 | proc codec_write stdcall, ac_reg:dword |
||
1090 | push eax |
||
1091 | call check_semafore |
||
1092 | and eax, eax |
||
1093 | jz .err |
||
1094 | pop eax |
||
1095 | |||
1096 | |||
1097 | mov edx, esi |
||
1098 | call [ctrl.codec_write16] |
||
1099 | mov [codec.regs+esi], ax |
||
1100 | shr esi, 1 |
||
1101 | bts [codec.shadow_flag], esi |
||
1102 | ret |
||
1103 | .err: |
||
1104 | pop eax |
||
1105 | ret |
||
1106 | endp |
||
1107 | |||
1108 | |||
1109 | proc codec_check_ready |
||
1110 | |||
1111 | |||
1112 | call [ctrl.ctrl_read32] |
||
1113 | and eax, CTRL_ST_CREADY |
||
1114 | jz .not_ready |
||
1115 | |||
1116 | |||
1117 | inc eax |
||
1118 | ret |
||
1119 | |||
1120 | |||
1121 | .not_ready: |
||
1122 | xor eax, eax |
||
1123 | ret |
||
1124 | endp |
||
1125 | |||
1126 | |||
1127 | proc check_semafore |
||
1128 | local counter:DWORD |
||
1129 | |||
1130 | |||
1131 | .l1: |
||
1132 | mov edx, CTRL_CAS |
||
1133 | call [ctrl.ctrl_read8] |
||
1134 | and eax, CAS_FLAG |
||
1135 | jz .ok |
||
1136 | |||
1137 | |||
1138 | call StallExec |
||
1139 | sub [counter], 1 |
||
1140 | jnz .l1 |
||
1141 | xor eax, eax |
||
1142 | ret |
||
1143 | align 4 |
||
1144 | .ok: |
||
1145 | xor eax,eax |
||
1146 | inc eax |
||
1147 | ret |
||
1148 | endp |
||
1149 | |||
1150 | |||
1151 | proc StallExec |
||
1152 | push ecx |
||
1153 | push edx |
||
1154 | push ebx |
||
1155 | push eax |
||
1156 | |||
1157 | |||
1158 | mul ecx |
||
1159 | mov ebx, eax ;low |
||
1160 | mov ecx, edx ;high |
||
1161 | rdtsc |
||
1162 | add ebx, eax |
||
1163 | adc ecx,edx |
||
1164 | @@: |
||
1165 | rdtsc |
||
1166 | sub eax, ebx |
||
1167 | sbb edx, ecx |
||
1168 | jb @B |
||
1169 | |||
1170 | |||
1171 | pop ebx |
||
1172 | pop edx |
||
1173 | pop ecx |
||
1174 | ret |
||
1175 | endp |
||
1176 | |||
1177 | |||
1178 | ; CONTROLLER IO functions |
||
1179 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
1180 | |||
1181 | |||
1182 | proc codec_io_r16 |
||
1183 | add edx, [ctrl.codec_io_base] |
||
1184 | in ax, dx |
||
1185 | ret |
||
1186 | endp |
||
1187 | |||
1188 | |||
1189 | proc codec_io_w16 |
||
1190 | add edx, [ctrl.codec_io_base] |
||
1191 | out dx, ax |
||
1192 | ret |
||
1193 | endp |
||
1194 | |||
1195 | |||
1196 | proc ctrl_io_r8 |
||
1197 | add edx, [ctrl.ctrl_io_base] |
||
1198 | in al, dx |
||
1199 | ret |
||
1200 | endp |
||
1201 | |||
1202 | |||
1203 | proc ctrl_io_r16 |
||
1204 | add edx, [ctrl.ctrl_io_base] |
||
1205 | in ax, dx |
||
1206 | ret |
||
1207 | endp |
||
1208 | |||
1209 | |||
1210 | proc ctrl_io_r32 |
||
1211 | add edx, [ctrl.ctrl_io_base] |
||
1212 | in eax, dx |
||
1213 | ret |
||
1214 | endp |
||
1215 | |||
1216 | |||
1217 | proc ctrl_io_w8 |
||
1218 | add edx, [ctrl.ctrl_io_base] |
||
1219 | out dx, al |
||
1220 | ret |
||
1221 | endp |
||
1222 | |||
1223 | |||
1224 | proc ctrl_io_w16 |
||
1225 | add edx, [ctrl.ctrl_io_base] |
||
1226 | out dx, ax |
||
1227 | ret |
||
1228 | endp |
||
1229 | |||
1230 | |||
1231 | proc ctrl_io_w32 |
||
1232 | add edx, [ctrl.ctrl_io_base] |
||
1233 | out dx, eax |
||
1234 | ret |
||
1235 | endp |
||
1236 | |||
1237 | |||
1238 | ; MEMORY MAPPED IO (os depended) |
||
1239 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
1240 | |||
1241 | |||
1242 | proc codec_mem_r16 |
||
1243 | add edx, [ctrl.codec_mem_base] |
||
1244 | mov ax, word [edx] |
||
1245 | ret |
||
1246 | endp |
||
1247 | |||
1248 | |||
1249 | proc codec_mem_w16 |
||
1250 | add edx, [ctrl.codec_mem_base] |
||
1251 | mov word [edx], ax |
||
1252 | ret |
||
1253 | endp |
||
1254 | |||
1255 | |||
1256 | proc ctrl_mem_r8 |
||
1257 | add edx, [ctrl.ctrl_mem_base] |
||
1258 | mov al, [edx] |
||
1259 | ret |
||
1260 | endp |
||
1261 | |||
1262 | |||
1263 | proc ctrl_mem_r16 |
||
1264 | add edx, [ctrl.ctrl_mem_base] |
||
1265 | mov ax, [edx] |
||
1266 | ret |
||
1267 | endp |
||
1268 | |||
1269 | |||
1270 | proc ctrl_mem_r32 |
||
1271 | add edx, [ctrl.ctrl_mem_base] |
||
1272 | mov eax, [edx] |
||
1273 | ret |
||
1274 | endp |
||
1275 | |||
1276 | |||
1277 | proc ctrl_mem_w8 |
||
1278 | add edx, [ctrl.ctrl_mem_base] |
||
1279 | mov [edx], al |
||
1280 | |||
1281 | |||
1282 | endp |
||
1283 | |||
1284 | |||
1285 | proc ctrl_mem_w16 |
||
1286 | add edx, [ctrl.ctrl_mem_base] |
||
1287 | mov [edx], ax |
||
1288 | ret |
||
1289 | endp |
||
1290 | |||
1291 | |||
1292 | proc ctrl_mem_w32 |
||
1293 | add edx, [ctrl.ctrl_mem_base] |
||
1294 | mov [edx], eax |
||
1295 | ret |
||
1296 | endp |
||
1297 | |||
1298 | |||
1299 | |||
1300 | |||
1301 | |||
188 | serge | 1302 | devices dd (CTRL_ICH shl 16)+VID_INTEL,msg_ICH, set_ICH |
168 | serge | 1303 | dd (CTRL_ICH0 shl 16)+VID_INTEL,msg_ICH0,set_ICH |
1304 | dd (CTRL_ICH2 shl 16)+VID_INTEL,msg_ICH2,set_ICH |
||
1305 | dd (CTRL_ICH3 shl 16)+VID_INTEL,msg_ICH3,set_ICH |
||
1306 | dd (CTRL_ICH4 shl 16)+VID_INTEL,msg_ICH4,set_ICH4 |
||
1307 | dd (CTRL_ICH5 shl 16)+VID_INTEL,msg_ICH5,set_ICH4 |
||
1308 | dd (CTRL_ICH6 shl 16)+VID_INTEL,msg_ICH6,set_ICH4 |
||
1309 | dd (CTRL_ICH7 shl 16)+VID_INTEL,msg_ICH7,set_ICH4 |
||
1310 | |||
1311 | |||
1312 | dd (CTRL_NFORCE2 shl 16)+VID_NVIDIA,msg_NForce2,set_ICH |
||
1313 | dd (CTRL_NFORCE3 shl 16)+VID_NVIDIA,msg_NForce3,set_ICH |
||
1314 | |||
1315 | |||
1316 | |||
1317 | |||
1318 | msg_ICH0 db 'Intel ICH0', 13,10, 0 |
||
1319 | msg_ICH2 db 'Intel ICH2', 13,10, 0 |
||
1320 | msg_ICH3 db 'Intel ICH3', 13,10, 0 |
||
1321 | msg_ICH4 db 'Intel ICH4', 13,10, 0 |
||
1322 | msg_ICH5 db 'Intel ICH5', 13,10, 0 |
||
1323 | msg_ICH6 db 'Intel ICH6', 13,10, 0 |
||
1324 | msg_ICH7 db 'Intel ICH7', 13,10, 0 |
||
1325 | msg_Intel db 'Intel Corp. ', 0 |
||
1326 | |||
1327 | |||
1328 | msg_NForce2 db 'NForce 2', 13,10, 0 |
||
1329 | msg_NForce3 db 'NForce 3', 13,10, 0 |
||
1330 | msg_NVidia db 'NVidea', 0 |
||
1331 | |||
1332 | |||
1333 | sz_sound_srv db 'SOUND',0 |
||
1334 | |||
1335 | |||
1336 | msgFail db 'device not found',13,10,0 |
||
1337 | msgAttchIRQ db 'IRQ line not supported', 13,10, 0 |
||
1338 | msgInvIRQ db 'IRQ line not assigned or invalid', 13,10, 0 |
||
1339 | msgPlay db 'start play', 13,10,0 |
||
1340 | msgStop db 'stop play', 13,10,0 |
||
1341 | msgNotify db 'call notify',13,10,0 |
||
1342 | msgIRQ db 'AC97 IRQ', 13,10,0 |
||
1343 | msgInitCtrl db 'init controller',13,10,0 |
||
1344 | msgInitCodec db 'init codec',13,10,0 |
||
1345 | msgPrimBuff db 'create primary buffer',13,10,0 |
||
1346 | msgReg db 'set service handler',13,10,0 |
||
1347 | msgOk db 'service installed',13,10,0 |
||
1348 | msgCold db 'cold reset',13,10,0 |
||
1349 | msgWarm db 'warm reset',13,10,0 |
||
1350 | msgWRFail db 'warm reset failed',13,10,0 |
||
1351 | msgCRFail db 'cold reset failed',13,10,0 |
||
1352 | msgCFail db 'codec not ready',13,10,0 |
||
1353 | msgResetOk db 'reset complete',13,10,0 |
||
1354 | |||
1355 | |||
188 | serge | 1356 | |
1357 | |||
1358 | buff_list rd 32 |
||
1359 | |||
1360 | |||
1361 | ctrl AC_CNTRL |
||
1362 | |||
1363 | |||
1364 | civ_val rd 1 |
||
1365 |