Fixed the obvious bugs

git-svn-id: svn://kolibrios.org@2900 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2012-08-01 10:55:11 +00:00
parent 954d3f5012
commit aaaa8209f1

View File

@ -1,15 +1,23 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;; ;; Distributed under terms of the GNU General Public License ;;
;; ;; ;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; simple AGP driver for KolibriOS ;;
;; ;;
;; Written by hidnplayr@kolibrios.org ;;
;; ;;
;; GNU GENERAL PUBLIC LICENSE ;;
;; Version 2, June 1991 ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
format MS COFF format MS COFF
DEBUG equ 1 DEBUG equ 1
API_VERSION equ 1 FAST_WRITE equ 0
SIDE_BAND_ADDRESSING equ 0
include 'proc32.inc' include 'proc32.inc'
include 'imports.inc' include 'imports.inc'
@ -37,6 +45,8 @@ DRV_EXIT equ -1
SRV_GETVERSION equ 0 SRV_GETVERSION equ 0
SRV_DETECT equ 1 SRV_DETECT equ 1
API_VERSION equ 1
section '.flat' code readable align 16 section '.flat' code readable align 16
proc START stdcall, state:dword proc START stdcall, state:dword
@ -110,17 +120,12 @@ proc detect
call PciApi ; get last bus call PciApi ; get last bus
cmp eax, -1 cmp eax, -1
je .error je .error
mov [last_bus], eax mov [last_bus], eax
.next_bus: .next_bus:
and [devfn], 0 and [devfn], 0
.next_dev: .next_dev:
stdcall PciRead16, [bus], [devfn], dword 0x08 ; read class/subclass stdcall PciRead16, [bus], [devfn], dword 0x0a ; read class/subclass
test eax, eax
jz .next
cmp eax, -1
je .next
cmp ax, 0x0302 ; display controller - 3d controller cmp ax, 0x0302 ; display controller - 3d controller
je .found je .found
@ -137,7 +142,15 @@ proc detect
mov [bus], eax mov [bus], eax
cmp eax, [last_bus] cmp eax, [last_bus]
jna .next_bus jna .next_bus
.error:
if DEBUG
mov esi, msgFail
call SysMsgBoardStr
end if
xor eax, eax xor eax, eax
inc eax
ret ret
.found: .found:
@ -145,6 +158,11 @@ proc detect
test al, 1 shl 4 ; got capabilities list? test al, 1 shl 4 ; got capabilities list?
jnz .got_capabilities_list jnz .got_capabilities_list
; TODO: Do it the old way: detect device and check with a list of known capabilities
; stupid pre PCI 2.2 board....
jmp .next
.got_capabilities_list: .got_capabilities_list:
stdcall PciRead8, [bus], [devfn], dword 0x34 ; read capabilities offset stdcall PciRead8, [bus], [devfn], dword 0x34 ; read capabilities offset
and eax, 11111100b ; always dword aligned and eax, 11111100b ; always dword aligned
@ -157,10 +175,7 @@ proc detect
movzx esi, ah ; pointer to next capability movzx esi, ah ; pointer to next capability
test esi, esi test esi, esi
jnz .read_capability jnz .read_capability
.error: jmp .next
xor eax, eax
inc eax
ret
.got_agp: .got_agp:
shl eax, 16 shl eax, 16
@ -183,57 +198,73 @@ proc detect
jz .error jz .error
.001b: .001b:
mov [speed], 001b mov [cmd], 001b
jmp .agp_go jmp .agp_go
.010b: .010b:
mov [speed], 010b mov [cmd], 010b
jmp .agp_go jmp .agp_go
.100b: .100b:
mov [speed], 100b mov [cmd], 100b
jmp .agp_go jmp .agp_go
.agp_3: .agp_3:
stdcall PciRead32, [bus], [devfn], esi ; read AGP status stdcall PciRead32, [bus], [devfn], esi ; read AGP status
test al, 1 shl 3 test al, 1 shl 3
jz .agp_2 jz .agp_2
and al, 11b mov [cmd], eax
mov [speed], al and [cmd], 11b
cmp al, 11b cmp [cmd], 11b
jne .agp_go jne .agp_go
mov [speed], 10b mov [cmd], 10b
.agp_go: .agp_go:
if FAST_WRITE
test ax, 1 shl 4
jz @f
or [cmd], 1 shl 4
@@:
end if
if SIDE_BAND_ADDRESSING
test ax, 1 shl 9
jz @f
or [cmd], 1 shl 9
@@:
end if
add esi, 4 add esi, 4
stdcall PciRead32, [bus], [devfn], esi ; read AGP cmd mov eax, [cmd]
and al, not 111b ; set max speed
or al, [speed]
or eax, 1 shl 8 ; enable AGP or eax, 1 shl 8 ; enable AGP
stdcall PciWrite32, [bus], [devfn], esi, eax ; write AGP cmd stdcall PciWrite32, [bus], [devfn], esi, eax ; write AGP cmd
if DEBUG
mov esi, msgOK
call SysMsgBoardStr
end if
ret ret
endp endp
;all initialized data place here ; initialized data
align 4 align 4
version dd (5 shl 16) or (API_VERSION and 0xFFFF) version dd (5 shl 16) or (API_VERSION and 0xFFFF)
my_service db 'AGP', 0 ; max 16 chars include zero my_service db 'AGP', 0 ; max 16 chars include zero
msgInit db 'detect hardware...', 13, 10, 0 msgInit db 'Searching AGP device...', 13, 10, 0
msgPCI db 'PCI acces not supported', 13, 10, 0
msgFail db 'device not found', 13, 10, 0 msgFail db 'device not found', 13, 10, 0
msgOK db 'AGP device enabled', 13, 10, 0
section '.data' data readable writable align 16 section '.data' data readable writable align 16
;all uninitialized data place here ; uninitialized data
revision db ? revision db ?
speed db ? cmd dd ?
bus dd ? bus dd ?
devfn dd ? devfn dd ?