Subversion Repositories Kolibri OS

Rev

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

Rev 1591 Rev 1598
Line 19... Line 19...
19
;;                                                              ;;
19
;;                                                              ;;
20
;;  See file COPYING for details                                ;;
20
;;  See file COPYING for details                                ;;
21
;;                                                              ;;
21
;;                                                              ;;
22
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 23... Line 23...
23
 
23
 
Line 24... Line 24...
24
$Revision: 1591 $
24
$Revision: 1598 $
25
 
25
 
26
;***************************************************************************
26
;***************************************************************************
27
;   Function
27
;   Function
Line 168... Line 168...
168
;   Function
168
;   Function
169
;      pci_read_reg:
169
;      pci_read_reg:
170
;
170
;
171
;   Description
171
;   Description
172
;       read a register from the PCI config space into EAX/AX/AL
172
;       read a register from the PCI config space into EAX/AX/AL
173
;       IN: ah=bus,device+func=bh,register address=bl
173
;       IN: bh=bus,device+func=ch,register address=cl
174
;           number of bytes to read (1,2,4) coded into AL, bits 0-1
174
;           number of bytes to read (1,2,4) coded into BL, bits 0-1
175
;           (0 - byte, 1 - word, 2 - dword)
175
;           (0 - byte, 1 - word, 2 - dword)
176
;***************************************************************************
176
;***************************************************************************
Line 177... Line 177...
177
 
177
 
Line 301... Line 301...
301
;   Function
301
;   Function
302
;      pci_write_reg:
302
;      pci_write_reg:
303
;
303
;
304
;   Description
304
;   Description
305
;       write a register from ECX/CX/CL into the PCI config space
305
;       write a register from ECX/CX/CL into the PCI config space
306
;       IN: ah=bus,device+func=bh,register address (dword aligned)=bl,
306
;       IN: bh=bus,device+func=ch,register address (dword aligned)=cl,
307
;           value to write in ecx
307
;           value to write in edx
308
;           number of bytes to write (1,2,4) coded into AL, bits 0-1
308
;           number of bytes to write (1,2,4) coded into BL, bits 0-1
309
;           (0 - byte, 1 - word, 2 - dword)
309
;           (0 - byte, 1 - word, 2 - dword)
310
;***************************************************************************
310
;***************************************************************************
Line 311... Line 311...
311
 
311
 
Line 466... Line 466...
466
;       maps a block of PCI memory to user-accessible linear address
466
;       maps a block of PCI memory to user-accessible linear address
467
;
467
;
468
;       WARNING! This VERY EXPERIMENTAL service is for one chosen PCI device only!
468
;       WARNING! This VERY EXPERIMENTAL service is for one chosen PCI device only!
469
;       The target device address should be set in kernel var mmio_pci_addr
469
;       The target device address should be set in kernel var mmio_pci_addr
470
;
470
;
471
;       IN:  ah = BAR#;
471
;       IN:  bh = BAR#;
472
;       IN: ebx = block size (bytes);
472
;       IN: ecx = block size (bytes);
473
;       IN: ecx = offset in MMIO block (in 4K-pages, to avoid misaligned pages);
473
;       IN: edx = offset in MMIO block (in 4K-pages, to avoid misaligned pages);
474
;
474
;
475
;   Returns eax = MMIO block's linear address in the userspace (if no error)
475
;   Returns eax = MMIO block's linear address in the userspace (if no error)
476
;
476
;
477
;
477
;
478
;   Error codes
478
;   Error codes
Line 482... Line 482...
482
;       eax = -4 : a port i/o BAR register referred
482
;       eax = -4 : a port i/o BAR register referred
483
;       eax = -5 : dynamic userspace allocation problem
483
;       eax = -5 : dynamic userspace allocation problem
484
;***************************************************************************
484
;***************************************************************************
Line 485... Line 485...
485
 
485
 
486
pci_mmio_map:
-
 
487
;cross
-
 
488
	mov	eax,ebx
-
 
489
	mov	ebx,ecx
-
 
490
	mov	ecx,edx
-
 
491
;;;;;;;;;;;;;;;;;;;
486
pci_mmio_map:
492
    and     edx,0x0ffff
487
    and     edx,0x0ffff
493
    cmp     ah,6
488
    cmp     bh, 6
494
    jc     .bar_0_5
489
    jc     .bar_0_5
495
    jz     .bar_rom
490
    jz     .bar_rom
496
    mov     eax,-2
491
    mov     eax,-2
497
    ret
492
    ret
498
.bar_rom:
493
.bar_rom:
499
    mov    ah, 8	; bar6 = Expansion ROM base address
494
    mov    ah, 8	; bar6 = Expansion ROM base address
-
 
495
.bar_0_5:
-
 
496
    push    edx
-
 
497
    add     ecx, 4095
500
.bar_0_5:
498
    and     ecx, 0xFFFFF000	; 4k-alignment
501
    push    ecx
-
 
502
    add     ebx, 4095
-
 
503
    and     ebx,-4096
-
 
504
    push    ebx
499
    push    ecx
505
    mov     bl, ah	; bl = BAR# (0..5), however bl=8 for BAR6
500
    mov     cl, bh	; cl = BAR# (0..5), however cl=8 for BAR6
506
    shl     bl, 1
501
    shl     cl, 1
507
    shl     bl, 1
502
    shl     cl, 1
508
    add     bl, 0x10	; now bl = BAR offset in PCI config. space
503
    add     cl, 0x10	; now cl = BAR offset in PCI config. space
509
    mov     ax, mmio_pci_addr
504
    mov     ax, mmio_pci_addr
510
    mov     bh, al	; bh = dddddfff
505
    mov     ch, al	; ch = dddddfff
511
    mov     al, 2	; al : DW to read
506
    mov     bl, 2		; bl : DW to read
512
    call    pci_read_reg
507
    call    pci_read_reg	; new call
513
    or	    eax, eax
508
    or	    eax, eax
514
    jnz     @f
509
    jnz     @f
515
    mov     eax,-3	; empty I/O space
510
    mov     eax,-3	; empty I/O space
516
    jmp     mmio_ret_fail
511
    jmp     mmio_ret_fail
Line 520... Line 515...
520
    mov     eax,-4	; damned ports (not MMIO space)
515
    mov     eax,-4	; damned ports (not MMIO space)
521
    jmp     mmio_ret_fail
516
    jmp     mmio_ret_fail
522
@@:
517
@@:
523
    pop     ecx 	; ecx = block size, bytes (expanded to whole page)
518
    pop     ecx 		; ecx = block size, bytes (expanded to whole page)
524
    mov     ebx, ecx	; user_alloc destroys eax, ecx, edx, but saves ebx
519
    mov     ebx, ecx	; user_alloc destroys eax, ecx, edx, but saves ebx
525
    and     eax, 0xFFFFFFF0
520
    and     al, 0xF0	; clear flags 
526
    push    eax 	      ; store MMIO physical address + keep 2DWords in the stack
521
    push    eax 	      ; store MMIO physical address + keep 2DWords in the stack
527
    stdcall user_alloc, ecx
522
    stdcall user_alloc, ecx
528
    or	    eax, eax
523
    or	eax, eax
529
    jnz     mmio_map_over
524
    jnz     mmio_map_over
530
    mov     eax,-5	; problem with page allocation
525
    mov     eax,-5	; problem with page allocation
Line 540... Line 535...
540
    mov     ebx, eax	; ebx = linear address
535
    mov     ebx, eax	; ebx = linear address
541
    pop     eax 	; eax = MMIO start
536
    pop     eax 		; eax = MMIO start
542
    pop     edx 	; edx = MMIO shift (pages)
537
    pop     edx 		; edx = MMIO shift (pages)
543
    shl     edx, 12	; edx = MMIO shift (bytes)
538
    shl     edx, 12	; edx = MMIO shift (bytes)
544
    add     eax, edx	; eax = uMMIO physical address
539
    add     eax, edx	; eax = uMMIO physical address
545
    or	    eax, PG_SHARED
-
 
546
    or	    eax, PG_UW
-
 
547
    or	    eax, PG_NOCACHE
540
    or	eax, PG_SHARED+PG_UW+PG_NOCACHE
548
    mov     edi, ebx
541
    mov     edi, ebx
549
    call    commit_pages
542
    call    commit_pages
550
    mov     eax, edi
543
    mov     eax, edi
551
    ret
544
    ret
Line 640... Line 633...
640
	je	..dev_not_found
633
	je	..dev_not_found
641
	add	esi, 10
634
	add	esi, 10
642
	jmp	..nxt2
635
	jmp	..nxt2
Line 643... Line 636...
643
 
636
 
-
 
637
.not_FIND_PCI_CLASS_CODE:
644
.not_FIND_PCI_CLASS_CODE:
638
	mov	edx, ecx
645
	cmp	ebp, 8			; READ_CONFIG_*
639
	cmp	ebp, 8			; READ_CONFIG_*
646
	jb	.not_READ_CONFIG
640
	jb	.not_READ_CONFIG
647
	cmp	ebp, 0x0A
641
	cmp	ebp, 0x0A
648
	ja	.not_READ_CONFIG
642
	ja	.not_READ_CONFIG
649
	mov	eax, ebp
643
	mov	eax, ebp	; -- ?? 
650
	mov	ah, bh
644
;	mov	ah, bh	; bus
651
	mov	edx, edi
645
	mov	ecx, edi
652
	mov	bh, bl
646
	mov	ch, bl	; dev+fn
653
	mov	bl, dl
647
;	mov	cl, dl	; reg#
654
	call	pci_read_reg
648
	call	pci_read_reg	
655
	mov	ecx, eax
649
	mov	edx, eax
656
	xor	ah, ah			; SUCCESSFUL
650
	xor	ah, ah			; SUCCESSFUL
657
	jmp	.return_abc
651
	jmp	.return_abc
658
.not_READ_CONFIG:
652
.not_READ_CONFIG:
659
	cmp	ebp, 0x0B		; WRITE_CONFIG_*
653
	cmp	ebp, 0x0B		; WRITE_CONFIG_*
660
	jb	.not_WRITE_CONFIG
654
	jb	.not_WRITE_CONFIG
661
	cmp	ebp, 0x0D
655
	cmp	ebp, 0x0D
662
	ja	.not_WRITE_CONFIG
656
	ja	.not_WRITE_CONFIG
663
	lea	eax, [ebp+1]
657
	lea	eax, [ebp+1]
664
	mov	ah, bh
658
;	mov	ah, bh	; bus
665
	mov	edx, edi
659
	mov	ecx, edi	
666
	mov	bh, bl
660
	mov	ch, bl
667
	mov	bl, dl
661
;	mov	cl, dl
668
	call	pci_write_reg
662
	call	pci_write_reg
669
	xor	ah, ah			; SUCCESSFUL
663
	xor	ah, ah			; SUCCESSFUL
670
	jmp	.return_abc
664
	jmp	.return_abc
671
.not_WRITE_CONFIG:
665
.not_WRITE_CONFIG: