2012-08-01 12:55:11 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
|
|
|
|
;; 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 ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2012-08-01 10:33:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
format MS COFF
|
|
|
|
|
2012-08-01 12:55:11 +02:00
|
|
|
DEBUG equ 1
|
|
|
|
FAST_WRITE equ 0
|
|
|
|
SIDE_BAND_ADDRESSING equ 0
|
2012-08-01 10:33:50 +02:00
|
|
|
|
|
|
|
include 'proc32.inc'
|
|
|
|
include 'imports.inc'
|
|
|
|
|
|
|
|
struc IOCTL
|
|
|
|
{ .handle dd ?
|
|
|
|
.io_code dd ?
|
|
|
|
.input dd ?
|
|
|
|
.inp_size dd ?
|
|
|
|
.output dd ?
|
|
|
|
.out_size dd ?
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual at 0
|
|
|
|
IOCTL IOCTL
|
|
|
|
end virtual
|
|
|
|
|
|
|
|
public START
|
|
|
|
public service_proc
|
|
|
|
public version
|
|
|
|
|
2012-08-01 12:55:11 +02:00
|
|
|
DRV_ENTRY equ 1
|
|
|
|
DRV_EXIT equ -1
|
2012-08-01 10:33:50 +02:00
|
|
|
|
|
|
|
SRV_GETVERSION equ 0
|
|
|
|
SRV_DETECT equ 1
|
|
|
|
|
2012-08-01 12:55:11 +02:00
|
|
|
API_VERSION equ 1
|
|
|
|
|
2012-08-01 10:33:50 +02:00
|
|
|
section '.flat' code readable align 16
|
|
|
|
|
|
|
|
proc START stdcall, state:dword
|
|
|
|
|
|
|
|
cmp [state], 1
|
|
|
|
jne .exit
|
|
|
|
.entry:
|
|
|
|
|
|
|
|
if DEBUG
|
|
|
|
mov esi, msgInit
|
|
|
|
call SysMsgBoardStr
|
|
|
|
end if
|
|
|
|
|
|
|
|
stdcall RegService, my_service, service_proc
|
|
|
|
ret
|
|
|
|
.fail:
|
|
|
|
.exit:
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
handle equ IOCTL.handle
|
|
|
|
io_code equ IOCTL.io_code
|
|
|
|
input equ IOCTL.input
|
|
|
|
inp_size equ IOCTL.inp_size
|
|
|
|
output equ IOCTL.output
|
|
|
|
out_size equ IOCTL.out_size
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc service_proc stdcall, ioctl:dword
|
|
|
|
|
|
|
|
mov ebx, [ioctl]
|
|
|
|
mov eax, [ebx+io_code]
|
|
|
|
cmp eax, SRV_GETVERSION
|
|
|
|
jne @F
|
|
|
|
|
|
|
|
mov eax, [ebx+output]
|
|
|
|
cmp [ebx+out_size], 4
|
|
|
|
jne .fail
|
|
|
|
mov [eax], dword API_VERSION
|
|
|
|
xor eax, eax
|
|
|
|
ret
|
|
|
|
@@:
|
|
|
|
mov ebx, [ioctl]
|
|
|
|
mov eax, [ebx+io_code]
|
|
|
|
cmp eax, SRV_DETECT
|
|
|
|
jne @F
|
|
|
|
call detect
|
|
|
|
@@:
|
|
|
|
.fail:
|
|
|
|
or eax, -1
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
|
|
|
restore handle
|
|
|
|
restore io_code
|
|
|
|
restore input
|
|
|
|
restore inp_size
|
|
|
|
restore output
|
|
|
|
restore out_size
|
|
|
|
|
|
|
|
align 4
|
|
|
|
proc detect
|
|
|
|
locals
|
|
|
|
last_bus dd ?
|
|
|
|
endl
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
mov [bus], eax
|
|
|
|
inc eax
|
|
|
|
call PciApi ; get last bus
|
|
|
|
cmp eax, -1
|
|
|
|
je .error
|
|
|
|
mov [last_bus], eax
|
|
|
|
|
|
|
|
.next_bus:
|
|
|
|
and [devfn], 0
|
|
|
|
.next_dev:
|
2012-08-01 12:55:11 +02:00
|
|
|
stdcall PciRead16, [bus], [devfn], dword 0x0a ; read class/subclass
|
2012-08-01 10:33:50 +02:00
|
|
|
|
|
|
|
cmp ax, 0x0302 ; display controller - 3d controller
|
|
|
|
je .found
|
|
|
|
|
|
|
|
cmp ax, 0x0380 ; display controller - other display controller
|
|
|
|
je .found
|
|
|
|
|
|
|
|
.next:
|
|
|
|
inc [devfn]
|
|
|
|
cmp [devfn], 256
|
|
|
|
jb .next_dev
|
|
|
|
mov eax, [bus]
|
|
|
|
inc eax
|
|
|
|
mov [bus], eax
|
|
|
|
cmp eax, [last_bus]
|
|
|
|
jna .next_bus
|
2012-08-01 12:55:11 +02:00
|
|
|
|
|
|
|
.error:
|
|
|
|
if DEBUG
|
|
|
|
mov esi, msgFail
|
|
|
|
call SysMsgBoardStr
|
|
|
|
end if
|
|
|
|
|
2012-08-01 10:33:50 +02:00
|
|
|
xor eax, eax
|
2012-08-01 12:55:11 +02:00
|
|
|
inc eax
|
2012-08-01 10:33:50 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
.found:
|
|
|
|
stdcall PciRead8, [bus], [devfn], dword 0x06 ; read prog IF
|
|
|
|
test al, 1 shl 4 ; got capabilities list?
|
|
|
|
jnz .got_capabilities_list
|
|
|
|
|
2012-08-01 12:55:11 +02:00
|
|
|
; TODO: Do it the old way: detect device and check with a list of known capabilities
|
|
|
|
; stupid pre PCI 2.2 board....
|
|
|
|
|
|
|
|
jmp .next
|
|
|
|
|
2012-08-01 10:33:50 +02:00
|
|
|
.got_capabilities_list:
|
|
|
|
stdcall PciRead8, [bus], [devfn], dword 0x34 ; read capabilities offset
|
|
|
|
and eax, 11111100b ; always dword aligned
|
|
|
|
mov esi, eax
|
|
|
|
|
|
|
|
.read_capability:
|
|
|
|
stdcall PciRead32, [bus], [devfn], esi ; read capability
|
|
|
|
cmp al, 0x02 ; AGP
|
|
|
|
je .got_agp
|
|
|
|
movzx esi, ah ; pointer to next capability
|
|
|
|
test esi, esi
|
|
|
|
jnz .read_capability
|
2012-08-01 12:55:11 +02:00
|
|
|
jmp .next
|
2012-08-01 10:33:50 +02:00
|
|
|
|
|
|
|
.got_agp:
|
|
|
|
shl eax, 16
|
|
|
|
mov [revision], al ; high nibble = major revision
|
|
|
|
; low nibble = minor revision
|
|
|
|
add esi, 4
|
|
|
|
and al, 0xf0
|
|
|
|
cmp al, 0x30
|
|
|
|
je .agp_3
|
|
|
|
|
|
|
|
.agp_2:
|
|
|
|
stdcall PciRead32, [bus], [devfn], esi ; read AGP status
|
|
|
|
test al, 100b
|
|
|
|
jnz .100b
|
|
|
|
|
|
|
|
test al, 10b
|
|
|
|
jnz .010b
|
|
|
|
|
|
|
|
test al, 1b
|
|
|
|
jz .error
|
|
|
|
|
|
|
|
.001b:
|
2012-08-01 12:55:11 +02:00
|
|
|
mov [cmd], 001b
|
2012-08-01 10:33:50 +02:00
|
|
|
jmp .agp_go
|
|
|
|
|
|
|
|
.010b:
|
2012-08-01 12:55:11 +02:00
|
|
|
mov [cmd], 010b
|
2012-08-01 10:33:50 +02:00
|
|
|
jmp .agp_go
|
|
|
|
|
|
|
|
.100b:
|
2012-08-01 12:55:11 +02:00
|
|
|
mov [cmd], 100b
|
2012-08-01 10:33:50 +02:00
|
|
|
jmp .agp_go
|
|
|
|
|
|
|
|
.agp_3:
|
|
|
|
stdcall PciRead32, [bus], [devfn], esi ; read AGP status
|
|
|
|
test al, 1 shl 3
|
|
|
|
jz .agp_2
|
2012-08-01 12:55:11 +02:00
|
|
|
mov [cmd], eax
|
|
|
|
and [cmd], 11b
|
|
|
|
cmp [cmd], 11b
|
2012-08-01 10:33:50 +02:00
|
|
|
jne .agp_go
|
2012-08-01 12:55:11 +02:00
|
|
|
mov [cmd], 10b
|
2012-08-01 10:33:50 +02:00
|
|
|
|
|
|
|
.agp_go:
|
2012-08-01 12:55:11 +02:00
|
|
|
|
|
|
|
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
|
2012-08-01 10:33:50 +02:00
|
|
|
add esi, 4
|
2012-08-01 12:55:11 +02:00
|
|
|
mov eax, [cmd]
|
2012-08-01 10:33:50 +02:00
|
|
|
or eax, 1 shl 8 ; enable AGP
|
|
|
|
stdcall PciWrite32, [bus], [devfn], esi, eax ; write AGP cmd
|
|
|
|
|
2012-08-01 12:55:11 +02:00
|
|
|
if DEBUG
|
|
|
|
mov esi, msgOK
|
|
|
|
call SysMsgBoardStr
|
|
|
|
end if
|
|
|
|
|
2012-08-01 10:33:50 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
2012-08-01 12:55:11 +02:00
|
|
|
; initialized data
|
2012-08-01 10:33:50 +02:00
|
|
|
|
|
|
|
align 4
|
|
|
|
version dd (5 shl 16) or (API_VERSION and 0xFFFF)
|
|
|
|
|
|
|
|
my_service db 'AGP', 0 ; max 16 chars include zero
|
|
|
|
|
2012-08-01 12:55:11 +02:00
|
|
|
msgInit db 'Searching AGP device...', 13, 10, 0
|
2012-08-01 10:33:50 +02:00
|
|
|
msgFail db 'device not found', 13, 10, 0
|
2012-08-01 12:55:11 +02:00
|
|
|
msgOK db 'AGP device enabled', 13, 10, 0
|
2012-08-01 10:33:50 +02:00
|
|
|
|
|
|
|
section '.data' data readable writable align 16
|
|
|
|
|
2012-08-01 12:55:11 +02:00
|
|
|
; uninitialized data
|
2012-08-01 10:33:50 +02:00
|
|
|
|
|
|
|
revision db ?
|
2012-08-01 12:55:11 +02:00
|
|
|
cmd dd ?
|
2012-08-01 10:33:50 +02:00
|
|
|
bus dd ?
|
|
|
|
devfn dd ?
|
|
|
|
|