Subversion Repositories Kolibri OS

Rev

Rev 4496 | Rev 5363 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4496 Rev 5077
Line 3... Line 3...
3
;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;;
4
;; Distributed under terms of the GNU General Public License    ;;
4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 7... Line 7...
7
 
7
 
-
 
8
format PE DLL native 0.05
Line 8... Line 9...
8
format MS COFF
9
entry START
Line 9... Line -...
9
 
-
 
10
DEBUG           equ 1
-
 
11
 
-
 
12
include 'proc32.inc'
10
 
Line 13... Line 11...
13
include 'imports.inc'
11
DEBUG           equ 1
14
 
12
 
15
API_VERSION     equ 0x01000100
13
API_VERSION     equ 0x01000100
Line 309... Line 307...
309
    .codec_mem_base   dd ?
307
    .codec_mem_base   dd ?
310
    .ctrl_mem_base    dd ?
308
    .ctrl_mem_base    dd ?
311
    .codec_id         dd ?
309
    .codec_id         dd ?
312
}
310
}
Line 313... Line -...
313
 
-
 
314
struc IOCTL
-
 
315
{  .handle            dd ?
-
 
316
   .io_code           dd ?
-
 
317
   .input             dd ?
-
 
318
   .inp_size          dd ?
-
 
319
   .output            dd ?
-
 
320
   .out_size          dd ?
-
 
321
}
-
 
322
 
-
 
323
virtual at 0
-
 
324
  IOCTL IOCTL
-
 
325
end virtual
-
 
326
 
311
 
Line -... Line 312...
-
 
312
EVENT_NOTIFY    equ 0x00000200
327
EVENT_NOTIFY    equ 0x00000200
313
 
328
 
314
section '.flat' code readable writable executable
329
public START
315
include '../struct.inc'
-
 
316
include '../macros.inc'
Line 330... Line -...
330
public service_proc
-
 
331
public version
-
 
332
 
317
include '../proc32.inc'
Line 333... Line 318...
333
section '.flat' code readable align 16
318
include '../peimport.inc'
334
 
319
 
Line 335... Line 320...
335
proc START stdcall, state:dword
320
proc START c, state:dword, cmdline:dword
336
 
321
 
337
        cmp     [state], 1
322
        cmp     [state], 1
338
        jne     .stop
323
        jne     .stop
Line 339... Line 324...
339
 
324
 
340
     if DEBUG
325
     if DEBUG
341
        mov     esi, msgInit
326
        mov     esi, msgInit
Line 342... Line 327...
342
        call    SysMsgBoardStr
327
        invoke  SysMsgBoardStr
343
     end if
328
     end if
344
 
329
 
345
        call    detect_controller
330
        call    detect_controller
346
        test    eax, eax
331
        test    eax, eax
347
        jz      .fail
332
        jz      .fail
Line 348... Line 333...
348
 
333
 
349
     if DEBUG
334
     if DEBUG
350
        mov     esi, [ctrl.vendor_ids]
335
        mov     esi, [ctrl.vendor_ids]
Line 362... Line 347...
362
        jz      .fail
347
        jz      .fail
Line 363... Line 348...
363
 
348
 
Line 364... Line 349...
364
        call    setup_codec
349
        call    setup_codec
365
 
350
 
366
        mov     esi, msgPrimBuff
351
        mov     esi, msgPrimBuff
367
        call    SysMsgBoardStr
352
        invoke  SysMsgBoardStr
368
        call    create_primary_buff
353
        call    create_primary_buff
Line 369... Line 354...
369
        mov     esi, msgDone
354
        mov     esi, msgDone
370
        call    SysMsgBoardStr
355
        invoke  SysMsgBoardStr
371
 
356
 
Line 384... Line 369...
384
        bts     ax, IRQ_LINE                    ;mask new ine
369
        bts     ax, IRQ_LINE                    ;mask new ine
385
        out     0x21, al
370
        out     0x21, al
386
        mov     al, ah
371
        mov     al, ah
387
        out     0xA1, al
372
        out     0xA1, al
Line 388... Line 373...
388
 
373
 
Line 389... Line 374...
389
        stdcall PciWrite8, 0, 0xF8, 0x61, IRQ_LINE      ;remap IRQ
374
        invoke  PciWrite8, 0, 0xF8, 0x61, IRQ_LINE      ;remap IRQ
390
 
375
 
391
        mov     dx, 0x4d0                       ;8259 ELCR1
376
        mov     dx, 0x4d0                       ;8259 ELCR1
392
        in      al, dx
377
        in      al, dx
393
        bts     ax, IRQ_LINE
378
        bts     ax, IRQ_LINE
394
        out     dx, al                          ;set level-triggered mode
379
        out     dx, al                          ;set level-triggered mode
395
        mov     [ctrl.int_line], IRQ_LINE
380
        mov     [ctrl.int_line], IRQ_LINE
396
        popf
381
        popf
397
        mov     esi, msgRemap
382
        mov     esi, msgRemap
Line 398... Line 383...
398
        call    SysMsgBoardStr
383
        invoke  SysMsgBoardStr
399
  end if
384
  end if
400
 
385
 
Line 406... Line 391...
406
        mov     eax, ATTCH_IRQ
391
        mov     eax, ATTCH_IRQ
407
        mov     esi, msgAttchIRQ
392
        mov     esi, msgAttchIRQ
408
        bt      eax, ebx
393
        bt      eax, ebx
409
        jnc     .fail_msg
394
        jnc     .fail_msg
Line 410... Line 395...
410
 
395
 
411
        stdcall AttachIntHandler, ebx, ac97_irq_VIA, dword 0
396
        invoke  AttachIntHandler, ebx, ac97_irq_VIA, 0
412
.reg:
397
.reg:
413
        stdcall RegService, sz_sound_srv, service_proc
398
        invoke  RegService, sz_sound_srv, service_proc
414
        ret
399
        ret
415
.fail:
400
.fail:
416
     if DEBUG
401
     if DEBUG
417
        mov     esi, msgFail
402
        mov     esi, msgFail
418
        call    SysMsgBoardStr
403
        invoke  SysMsgBoardStr
419
     end if
404
     end if
420
        xor     eax, eax
405
        xor     eax, eax
421
        ret
406
        ret
422
.fail_msg:
407
.fail_msg:
423
        call    SysMsgBoardStr
408
        invoke  SysMsgBoardStr
424
        xor     eax, eax
409
        xor     eax, eax
425
        ret
410
        ret
426
.stop:
411
.stop:
427
        call    stop
412
        call    stop
Line 454... Line 439...
454
@@:
439
@@:
455
        cmp     eax, DEV_PLAY
440
        cmp     eax, DEV_PLAY
456
        jne     @F
441
        jne     @F
457
     if DEBUG
442
     if DEBUG
458
        mov     esi, msgPlay
443
        mov     esi, msgPlay
459
        call    SysMsgBoardStr
444
        invoke  SysMsgBoardStr
460
     end if
445
     end if
461
        call    play
446
        call    play
462
        ret
447
        ret
463
@@:
448
@@:
464
        cmp     eax, DEV_STOP
449
        cmp     eax, DEV_STOP
465
        jne     @F
450
        jne     @F
466
     if DEBUG
451
     if DEBUG
467
        mov     esi, msgStop
452
        mov     esi, msgStop
468
        call    SysMsgBoardStr
453
        invoke  SysMsgBoardStr
469
     end if
454
     end if
470
        call    stop
455
        call    stop
471
        ret
456
        ret
472
@@:
457
@@:
473
        cmp     eax, DEV_CALLBACK
458
        cmp     eax, DEV_CALLBACK
Line 550... Line 535...
550
 
535
 
551
 
536
 
Line 552... Line 537...
552
align 4
537
align 4
553
proc create_primary_buff
538
proc create_primary_buff
Line 554... Line 539...
554
 
539
 
555
        stdcall KernelAlloc, 0x10000
540
        invoke  KernelAlloc, 0x10000
556
        mov     [ctrl.buffer], eax
541
        mov     [ctrl.buffer], eax
557
 
542
 
558
        mov     edi, eax
543
        mov     edi, eax
Line 559... Line 544...
559
        mov     ecx, 0x10000/4
544
        mov     ecx, 0x10000/4
560
        xor     eax, eax
545
        xor     eax, eax
561
        cld
546
        cld
562
        rep stosd
547
        rep stosd
563
 
548
 
564
        mov     eax, [ctrl.buffer]
549
        mov     eax, [ctrl.buffer]
Line 588... Line 573...
588
        stdcall channel_reset, VIADEV_PLAYBACK
573
        stdcall channel_reset, VIADEV_PLAYBACK
589
        stdcall codec_check_ready
574
        stdcall codec_check_ready
Line 590... Line 575...
590
 
575
 
591
        mov     eax, pcmout_bdl
576
        mov     eax, pcmout_bdl
592
        mov     ebx, eax
577
        mov     ebx, eax
593
        call    GetPgAddr
578
        invoke  GetPgAddr
594
        and     ebx, 0xFFF
579
        and     ebx, 0xFFF
Line 595... Line 580...
595
        add     eax, ebx
580
        add     eax, ebx
596
 
581
 
Line 667... Line 652...
667
           endl
652
           endl
Line 668... Line 653...
668
 
653
 
669
        xor     eax, eax
654
        xor     eax, eax
670
        mov     [bus], eax
655
        mov     [bus], eax
671
        inc     eax
656
        inc     eax
672
        call    PciApi
657
        invoke  PciApi
673
        cmp     eax, -1
658
        cmp     eax, -1
Line 674... Line 659...
674
        je      .err
659
        je      .err
Line 675... Line 660...
675
 
660
 
676
        mov     [last_bus], eax
661
        mov     [last_bus], eax
677
 
662
 
678
.next_bus:
663
.next_bus:
679
        and     [devfn], 0
664
        and     [devfn], 0
680
.next_dev:
665
.next_dev:
681
        stdcall PciRead32, [bus], [devfn], dword 0
666
        invoke  PciRead32, [bus], [devfn], dword 0
682
        test    eax, eax
667
        test    eax, eax
Line 736... Line 721...
736
endp
721
endp
Line 737... Line 722...
737
 
722
 
738
align 4
723
align 4
Line 739... Line 724...
739
proc init_controller
724
proc init_controller
740
 
725
 
741
        stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 4
726
        invoke  PciRead32, [ctrl.bus], [ctrl.devfn], dword 4
742
        mov     ebx, eax
727
        mov     ebx, eax
743
        and     eax, 0xFFFF
728
        and     eax, 0xFFFF
744
        mov     [ctrl.pci_cmd], eax
729
        mov     [ctrl.pci_cmd], eax
Line 745... Line 730...
745
        shr     ebx, 16
730
        shr     ebx, 16
746
        mov     [ctrl.pci_stat], ebx
731
        mov     [ctrl.pci_stat], ebx
747
 
732
 
748
        mov     esi, msgPciCmd
733
        mov     esi, msgPciCmd
Line 749... Line 734...
749
        call    SysMsgBoardStr
734
        invoke  SysMsgBoardStr
750
        call    dword2str
735
        call    dword2str
751
        call    SysMsgBoardStr
736
        invoke  SysMsgBoardStr
752
 
737
 
753
        mov     esi, msgPciStat
738
        mov     esi, msgPciStat
Line 754... Line 739...
754
        call    SysMsgBoardStr
739
        invoke  SysMsgBoardStr
755
        mov     eax, [ctrl.pci_stat]
740
        mov     eax, [ctrl.pci_stat]
756
        call    dword2str
741
        call    dword2str
757
        call    SysMsgBoardStr
742
        invoke  SysMsgBoardStr
758
 
743
 
Line 759... Line 744...
759
        mov     esi, msgCtrlIsaIo
744
        mov     esi, msgCtrlIsaIo
760
        call    SysMsgBoardStr
745
        invoke  SysMsgBoardStr
Line 761... Line 746...
761
        stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x10
746
        invoke  PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x10
762
        call    dword2str
747
        call    dword2str
763
        call    SysMsgBoardStr
748
        invoke  SysMsgBoardStr
764
 
749
 
765
        and     eax, 0xFFC0
750
        and     eax, 0xFFC0
Line 766... Line 751...
766
        mov     [ctrl.ctrl_io_base], eax
751
        mov     [ctrl.ctrl_io_base], eax
Line 811... Line 796...
811
           locals
796
           locals
812
             counter dd ?
797
             counter dd ?
813
           endl
798
           endl
Line 814... Line 799...
814
 
799
 
815
        mov     esi, msgControl
800
        mov     esi, msgControl
816
        call    SysMsgBoardStr
801
        invoke  SysMsgBoardStr
817
        stdcall PciRead8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_CTRL
802
        invoke  PciRead8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_CTRL
818
        and     eax, 0xFF
803
        and     eax, 0xFF
819
        call    dword2str
804
        call    dword2str
Line 820... Line 805...
820
        call    SysMsgBoardStr
805
        invoke  SysMsgBoardStr
821
 
806
 
822
        mov     esi, msgStatus
807
        mov     esi, msgStatus
823
        call    SysMsgBoardStr
808
        invoke  SysMsgBoardStr
824
        stdcall PciRead8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_STAT
809
        invoke  PciRead8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_STAT
825
        and     eax, 0xFF
810
        and     eax, 0xFF
826
        push    eax
811
        push    eax
827
        call    dword2str
812
        call    dword2str
Line 828... Line 813...
828
        call    SysMsgBoardStr
813
        invoke  SysMsgBoardStr
829
        pop     eax
814
        pop     eax
Line 852... Line 837...
852
        ret
837
        ret
853
endp
838
endp
Line 854... Line 839...
854
 
839
 
855
align 4
840
align 4
856
proc reset_codec
841
proc reset_codec
857
        stdcall PciWrite8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_CTRL, \
842
        invoke  PciWrite8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_CTRL, \
858
                VIA_ACLINK_CTRL_ENABLE or VIA_ACLINK_CTRL_RESET or VIA_ACLINK_CTRL_SYNC
843
                VIA_ACLINK_CTRL_ENABLE or VIA_ACLINK_CTRL_RESET or VIA_ACLINK_CTRL_SYNC
859
        mov     eax, 100000        ; wait 100 ms
844
        mov     eax, 100000        ; wait 100 ms
860
        call    StallExec
845
        call    StallExec
861
.cold:
846
.cold:
862
        call    cold_reset
847
        call    cold_reset
Line 863... Line 848...
863
        jnc     .ok
848
        jnc     .ok
864
 
849
 
865
     if DEBUG
850
     if DEBUG
866
        mov     esi, msgCFail
851
        mov     esi, msgCFail
867
        call    SysMsgBoardStr
852
        invoke  SysMsgBoardStr
868
     end if
853
     end if
869
        xor     eax, eax         ; timeout error
854
        xor     eax, eax         ; timeout error
870
        ret
855
        ret
871
.ok:
856
.ok:
872
     if DEBUG
857
     if DEBUG
873
        mov     esi, msgResetOk
858
        mov     esi, msgResetOk
874
        call    SysMsgBoardStr
859
        invoke  SysMsgBoardStr
875
     end if
860
     end if
876
        xor     eax, eax
861
        xor     eax, eax
877
        inc     eax
862
        inc     eax
Line 883... Line 868...
883
proc cold_reset
868
proc cold_reset
884
           locals
869
           locals
885
             counter dd ?
870
             counter dd ?
886
           endl
871
           endl
Line 887... Line 872...
887
 
872
 
Line 888... Line 873...
888
        stdcall PciWrite8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_CTRL, dword 0
873
        invoke  PciWrite8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_CTRL, dword 0
889
 
874
 
890
     if DEBUG
875
     if DEBUG
891
        mov     esi, msgCold
876
        mov     esi, msgCold
Line 892... Line 877...
892
        call    SysMsgBoardStr
877
        invoke  SysMsgBoardStr
893
     end if
878
     end if
Line 894... Line 879...
894
 
879
 
895
        mov     eax, 100000         ; wait 100 ms ;400000     ; wait 400 ms
880
        mov     eax, 100000         ; wait 100 ms ;400000     ; wait 400 ms
896
        call    StallExec
881
        call    StallExec
Line 897... Line 882...
897
 
882
 
898
           ;; ACLink on, deassert ACLink reset, VSR, SGD data out
883
           ;; ACLink on, deassert ACLink reset, VSR, SGD data out
899
           ;; note - FM data out has trouble with non VRA codecs !!
884
           ;; note - FM data out has trouble with non VRA codecs !!
900
        stdcall PciWrite8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_CTRL, dword VIA_ACLINK_CTRL_INIT
885
        invoke  PciWrite8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_CTRL, dword VIA_ACLINK_CTRL_INIT
901
 
886
 
Line 902... Line 887...
902
        mov     [counter], 16        ; total 20*100 ms = 2s
887
        mov     [counter], 16        ; total 20*100 ms = 2s
903
.wait:
888
.wait:
Line 911... Line 896...
911
        dec     [counter]
896
        dec     [counter]
912
        jnz     .wait
897
        jnz     .wait
Line 913... Line 898...
913
 
898
 
914
     if DEBUG
899
     if DEBUG
915
        mov     esi, msgCRFail
900
        mov     esi, msgCRFail
916
        call    SysMsgBoardStr
901
        invoke  SysMsgBoardStr
Line 917... Line 902...
917
     end if
902
     end if
918
 
903
 
919
.fail:
904
.fail:
920
        stc
905
        stc
921
        ret
906
        ret
922
.ok:
907
.ok:
923
        mov     esi, msgControl
908
        mov     esi, msgControl
924
        call    SysMsgBoardStr
909
        invoke  SysMsgBoardStr
925
        stdcall PciRead8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_CTRL
910
        invoke  PciRead8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_CTRL
Line 926... Line 911...
926
        call    dword2str
911
        call    dword2str
927
        call    SysMsgBoardStr
912
        invoke  SysMsgBoardStr
928
 
913
 
929
        mov     esi, msgStatus
914
        mov     esi, msgStatus
930
        call    SysMsgBoardStr
915
        invoke  SysMsgBoardStr
931
        stdcall PciRead8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_STAT
916
        invoke  PciRead8, [ctrl.bus], [ctrl.devfn], dword VIA_ACLINK_STAT
932
        and     eax, 0xFF
917
        and     eax, 0xFF
933
        push    eax
918
        push    eax
Line 934... Line 919...
934
        call    dword2str
919
        call    dword2str
935
        call    SysMsgBoardStr
920
        invoke  SysMsgBoardStr
936
        pop     eax
921
        pop     eax
Line 1085... Line 1070...
1085
        and     eax, 0xFFFF
1070
        and     eax, 0xFFFF
1086
        ret
1071
        ret
1087
.err:
1072
.err:
1088
     if DEBUG
1073
     if DEBUG
1089
        mov     esi, msgCInvalid
1074
        mov     esi, msgCInvalid
1090
        call    SysMsgBoardStr
1075
        invoke  SysMsgBoardStr
1091
     end if
1076
     end if
1092
        mov     eax, -1            ; invalid codec error
1077
        mov     eax, -1            ; invalid codec error
1093
        ret
1078
        ret
1094
endp
1079
endp
Line 1118... Line 1103...
1118
.ok:
1103
.ok:
1119
        ret
1104
        ret
1120
.err:
1105
.err:
1121
     if DEBUG
1106
     if DEBUG
1122
        mov     esi, msgCFail
1107
        mov     esi, msgCFail
1123
        call    SysMsgBoardStr
1108
        invoke  SysMsgBoardStr
1124
     end if
1109
     end if
1125
           ;mov      eax, -1        ; codec not ready error
1110
           ;mov      eax, -1        ; codec not ready error
1126
        ret
1111
        ret
1127
endp
1112
endp
Line 1242... Line 1227...
1242
devices dd (CTRL_VT82C686  shl 16)+VID_VIA,msg_VT82C686,set_VIA
1227
devices dd (CTRL_VT82C686  shl 16)+VID_VIA,msg_VT82C686,set_VIA
1243
        dd (CTRL_VT8233_5  shl 16)+VID_VIA,msg_VT8233,set_VIA
1228
        dd (CTRL_VT8233_5  shl 16)+VID_VIA,msg_VT8233,set_VIA
1244
        dd 0    ;terminator
1229
        dd 0    ;terminator
Line 1245... Line -...
1245
 
-
 
1246
 
-
 
1247
version      dd (5 shl 16) or (API_VERSION and 0xFFFF)
1230
 
1248
 
1231
 
1249
msg_VT82C686 db 'VT82C686', 13,10, 0
1232
msg_VT82C686 db 'VT82C686', 13,10, 0
Line 1250... Line 1233...
1250
msg_VT8233   db 'VT8233',   13,10, 0
1233
msg_VT8233   db 'VT8233',   13,10, 0
Line 1282... Line 1265...
1282
;msgMixIsaIo  db 'codec io base        ',0
1265
;msgMixIsaIo  db 'codec io base        ',0
1283
;msgCtrlMMIo  db 'controller mmio base ',0
1266
;msgCtrlMMIo  db 'controller mmio base ',0
1284
;msgMixMMIo   db 'codec mmio base      ',0
1267
;msgMixMMIo   db 'codec mmio base      ',0
1285
;msgIrqMap    db 'AC97 irq map as      ',0
1268
;msgIrqMap    db 'AC97 irq map as      ',0
Line -... Line 1269...
-
 
1269
 
-
 
1270
align 4
-
 
1271
data fixups
Line 1286... Line -...
1286
 
-
 
1287
 
1272
end data
1288
section '.data' data readable writable align 16
1273
 
1289
 
1274
align 8
Line 1290... Line 1275...
1290
pcmout_bdl       rq 32
1275
pcmout_bdl       rq 32
1291
buff_list        rd 32
1276
buff_list        rd 32