2012-08-01 12:55:11 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2015-01-08 21:10:22 +01:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
|
2012-08-01 12:55:11 +02:00
|
|
|
;; 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
|
|
|
|
|
|
|
|
2014-08-29 17:09:56 +02:00
|
|
|
format PE DLL native
|
|
|
|
entry START
|
2012-08-01 10:33:50 +02:00
|
|
|
|
2014-08-29 17:09:56 +02:00
|
|
|
CURRENT_API = 0x0200
|
|
|
|
COMPATIBLE_API = 0x0100
|
|
|
|
API_VERSION = (COMPATIBLE_API shl 16) + CURRENT_API
|
2012-08-01 10:33:50 +02:00
|
|
|
|
2014-08-29 17:09:56 +02:00
|
|
|
FAST_WRITE = 0 ; may cause problems with some motherboards
|
2012-08-01 10:33:50 +02:00
|
|
|
|
2014-08-29 17:09:56 +02:00
|
|
|
section '.flat' readable writable executable
|
2012-08-01 10:33:50 +02:00
|
|
|
|
2014-08-29 17:09:56 +02:00
|
|
|
include '../proc32.inc'
|
|
|
|
include '../struct.inc'
|
|
|
|
include '../macros.inc'
|
2014-08-31 16:09:14 +02:00
|
|
|
include '../pci.inc'
|
2012-08-01 10:33:50 +02:00
|
|
|
|
2014-08-29 17:09:56 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; proc START ;;
|
|
|
|
;; ;;
|
|
|
|
;; (standard driver proc) ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2012-08-01 10:33:50 +02:00
|
|
|
|
2014-08-29 17:09:56 +02:00
|
|
|
proc START c, reason:dword, cmdline:dword
|
2012-08-01 10:33:50 +02:00
|
|
|
|
2014-08-29 17:09:56 +02:00
|
|
|
cmp [reason], DRV_ENTRY
|
|
|
|
jne .fail
|
2012-08-01 10:33:50 +02:00
|
|
|
|
|
|
|
mov esi, msgInit
|
2014-08-29 17:09:56 +02:00
|
|
|
invoke SysMsgBoardStr
|
|
|
|
invoke RegService, my_service, service_proc
|
|
|
|
|
|
|
|
call detect
|
2012-08-01 10:33:50 +02:00
|
|
|
|
|
|
|
ret
|
2014-08-29 17:09:56 +02:00
|
|
|
|
|
|
|
.fail:
|
2012-08-01 10:33:50 +02:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
2014-08-29 17:09:56 +02:00
|
|
|
|
2012-08-01 10:33:50 +02:00
|
|
|
endp
|
|
|
|
|
2014-08-29 17:09:56 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; proc SERVICE_PROC ;;
|
|
|
|
;; ;;
|
|
|
|
;; (standard driver proc) ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2012-08-01 10:33:50 +02:00
|
|
|
|
|
|
|
proc service_proc stdcall, ioctl:dword
|
|
|
|
|
2014-08-29 17:09:56 +02:00
|
|
|
mov edx, [ioctl]
|
|
|
|
mov eax, [edx + IOCTL.io_code]
|
2012-08-01 10:33:50 +02:00
|
|
|
|
2014-08-29 17:09:56 +02:00
|
|
|
;------------------------------------------------------
|
|
|
|
|
|
|
|
cmp eax, 0 ;SRV_GETVERSION
|
2012-08-01 10:33:50 +02:00
|
|
|
jne .fail
|
2014-08-29 17:09:56 +02:00
|
|
|
|
|
|
|
cmp [edx + IOCTL.out_size], 4
|
|
|
|
jb .fail
|
|
|
|
mov eax, [edx + IOCTL.output]
|
2012-08-01 10:33:50 +02:00
|
|
|
mov [eax], dword API_VERSION
|
2014-08-29 17:09:56 +02:00
|
|
|
|
2012-08-01 10:33:50 +02:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
2014-08-29 17:09:56 +02:00
|
|
|
|
|
|
|
.fail:
|
2012-08-01 10:33:50 +02:00
|
|
|
or eax, -1
|
|
|
|
ret
|
|
|
|
|
2014-08-29 17:09:56 +02:00
|
|
|
endp
|
2012-08-01 10:33:50 +02:00
|
|
|
|
|
|
|
align 4
|
|
|
|
proc detect
|
|
|
|
locals
|
|
|
|
last_bus dd ?
|
|
|
|
endl
|
|
|
|
|
2012-08-02 09:30:54 +02:00
|
|
|
mov esi, msgSearch
|
2014-08-29 17:09:56 +02:00
|
|
|
invoke SysMsgBoardStr
|
2012-08-02 09:30:54 +02:00
|
|
|
|
2012-08-01 10:33:50 +02:00
|
|
|
xor eax, eax
|
|
|
|
mov [bus], eax
|
|
|
|
inc eax
|
2014-08-29 17:09:56 +02:00
|
|
|
invoke PciApi ; get last bus
|
2012-08-01 10:33:50 +02:00
|
|
|
cmp eax, -1
|
|
|
|
je .error
|
|
|
|
mov [last_bus], eax
|
|
|
|
|
|
|
|
.next_bus:
|
|
|
|
and [devfn], 0
|
|
|
|
.next_dev:
|
2014-08-29 17:09:56 +02:00
|
|
|
invoke PciRead16, [bus], [devfn], PCI_header.subclass ; subclass/vendor
|
2012-08-02 09:30:54 +02:00
|
|
|
cmp ax, 0x0300 ; display controller - vga compatable controller
|
|
|
|
je .found
|
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:
|
|
|
|
mov esi, msgFail
|
2014-08-29 17:09:56 +02:00
|
|
|
invoke SysMsgBoardStr
|
2012-08-01 12:55:11 +02:00
|
|
|
|
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:
|
2014-08-29 17:09:56 +02:00
|
|
|
invoke PciRead8, [bus], [devfn], PCI_header00.prog_if
|
2012-08-01 10:33:50 +02:00
|
|
|
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:
|
2014-08-29 17:09:56 +02:00
|
|
|
invoke PciRead8, [bus], [devfn], PCI_header00.cap_ptr
|
2012-08-01 10:33:50 +02:00
|
|
|
and eax, 11111100b ; always dword aligned
|
2012-08-02 09:30:54 +02:00
|
|
|
mov edi, eax
|
2012-08-01 10:33:50 +02:00
|
|
|
|
|
|
|
.read_capability:
|
2014-08-29 17:09:56 +02:00
|
|
|
invoke PciRead32, [bus], [devfn], edi ; read capability
|
2012-08-01 10:33:50 +02:00
|
|
|
cmp al, 0x02 ; AGP
|
|
|
|
je .got_agp
|
2012-08-02 09:30:54 +02:00
|
|
|
movzx edi, ah ; pointer to next capability
|
|
|
|
test edi, edi
|
2012-08-01 10:33:50 +02:00
|
|
|
jnz .read_capability
|
2012-08-01 12:55:11 +02:00
|
|
|
jmp .next
|
2012-08-01 10:33:50 +02:00
|
|
|
|
|
|
|
.got_agp:
|
2012-08-02 09:30:54 +02:00
|
|
|
shr eax, 16
|
2012-08-01 10:33:50 +02:00
|
|
|
mov [revision], al ; high nibble = major revision
|
|
|
|
; low nibble = minor revision
|
2012-08-02 09:30:54 +02:00
|
|
|
add edi, 4
|
2012-08-01 10:33:50 +02:00
|
|
|
and al, 0xf0
|
|
|
|
cmp al, 0x30
|
|
|
|
je .agp_3
|
|
|
|
|
|
|
|
.agp_2:
|
2012-08-02 09:30:54 +02:00
|
|
|
mov esi, msgAGP2
|
2014-08-29 17:09:56 +02:00
|
|
|
invoke SysMsgBoardStr
|
2012-08-02 09:30:54 +02:00
|
|
|
|
2014-08-29 17:09:56 +02:00
|
|
|
invoke PciRead32, [bus], [devfn], edi ; read AGP status
|
2012-08-02 09:30:54 +02:00
|
|
|
.agp_2_:
|
2012-08-01 10:33:50 +02:00
|
|
|
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-02 09:30:54 +02:00
|
|
|
mov esi, msg1
|
2014-08-29 17:09:56 +02:00
|
|
|
invoke SysMsgBoardStr
|
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-02 09:30:54 +02:00
|
|
|
mov esi, msg2
|
2014-08-29 17:09:56 +02:00
|
|
|
invoke SysMsgBoardStr
|
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-02 09:30:54 +02:00
|
|
|
mov esi, msg4
|
2014-08-29 17:09:56 +02:00
|
|
|
invoke SysMsgBoardStr
|
2012-08-01 10:33:50 +02:00
|
|
|
jmp .agp_go
|
|
|
|
|
2012-08-02 09:30:54 +02:00
|
|
|
.agp_2m:
|
|
|
|
mov esi, msgAGP2m
|
2014-08-29 17:09:56 +02:00
|
|
|
invoke SysMsgBoardStr
|
2012-08-02 09:30:54 +02:00
|
|
|
jmp .agp_2_
|
|
|
|
|
2012-08-01 10:33:50 +02:00
|
|
|
.agp_3:
|
2012-08-02 09:30:54 +02:00
|
|
|
mov esi, msgAGP3
|
2014-08-29 17:09:56 +02:00
|
|
|
invoke SysMsgBoardStr
|
2012-08-02 09:30:54 +02:00
|
|
|
|
2014-08-29 17:09:56 +02:00
|
|
|
invoke PciRead32, [bus], [devfn], edi ; read AGP status
|
2012-08-01 10:33:50 +02:00
|
|
|
test al, 1 shl 3
|
2012-08-02 09:30:54 +02:00
|
|
|
jz .agp_2m
|
2012-08-02 11:05:35 +02:00
|
|
|
|
2012-08-02 09:30:54 +02:00
|
|
|
test eax, 10b
|
|
|
|
jnz .8x
|
|
|
|
mov [cmd], 01b
|
|
|
|
mov esi, msg4
|
2014-08-29 17:09:56 +02:00
|
|
|
invoke SysMsgBoardStr
|
2012-08-02 09:30:54 +02:00
|
|
|
jmp .agp_go
|
|
|
|
|
|
|
|
.8x:
|
2012-08-01 12:55:11 +02:00
|
|
|
mov [cmd], 10b
|
2012-08-02 09:30:54 +02:00
|
|
|
mov esi, msg8
|
2014-08-29 17:09:56 +02:00
|
|
|
invoke SysMsgBoardStr
|
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
|
2012-08-02 09:30:54 +02:00
|
|
|
mov esi, msgfast
|
2014-08-29 17:09:56 +02:00
|
|
|
invoke SysMsgBoardStr
|
2012-08-01 12:55:11 +02:00
|
|
|
@@:
|
|
|
|
end if
|
2012-08-02 11:05:35 +02:00
|
|
|
|
|
|
|
test ax, 1 shl 9 ; Side band addressing
|
2012-08-01 12:55:11 +02:00
|
|
|
jz @f
|
|
|
|
or [cmd], 1 shl 9
|
2012-08-02 09:30:54 +02:00
|
|
|
mov esi, msgside
|
2014-08-29 17:09:56 +02:00
|
|
|
invoke SysMsgBoardStr
|
2012-08-01 12:55:11 +02:00
|
|
|
@@:
|
2012-08-02 09:30:54 +02:00
|
|
|
|
2012-08-02 11:05:35 +02:00
|
|
|
add edi, 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
|
2014-08-29 17:09:56 +02:00
|
|
|
invoke PciWrite32, [bus], [devfn], edi, eax ; write AGP cmd
|
2012-08-01 10:33:50 +02:00
|
|
|
|
2012-08-01 12:55:11 +02:00
|
|
|
mov esi, msgOK
|
2014-08-29 17:09:56 +02:00
|
|
|
invoke SysMsgBoardStr
|
2012-08-01 12:55:11 +02:00
|
|
|
|
2012-08-01 10:33:50 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
endp
|
|
|
|
|
|
|
|
|
2014-08-29 17:09:56 +02:00
|
|
|
; End of code
|
2012-08-01 10:33:50 +02:00
|
|
|
|
2014-08-29 17:09:56 +02:00
|
|
|
data fixups
|
|
|
|
end data
|
|
|
|
|
|
|
|
include '../peimport.inc'
|
2012-08-01 10:33:50 +02:00
|
|
|
|
|
|
|
my_service db 'AGP', 0 ; max 16 chars include zero
|
|
|
|
|
2012-08-02 09:30:54 +02:00
|
|
|
msgInit db 'AGP driver loaded.', 13, 10, 0
|
|
|
|
msgSearch db 'Searching for AGP card...', 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-02 09:30:54 +02:00
|
|
|
msgAGP2 db 'AGP2 device found', 13, 10, 0
|
|
|
|
msgAGP3 db 'AGP3 device found', 13, 10, 0
|
|
|
|
msgAGP2m db 'Running in AGP2 mode', 13, 10, 0
|
|
|
|
msg8 db '8x speed', 13, 10, 0
|
|
|
|
msg4 db '4x speed', 13, 10, 0
|
|
|
|
msg2 db '2x speed', 13, 10, 0
|
|
|
|
msg1 db '1x speed', 13, 10, 0
|
|
|
|
msgfast db 'Fast Write', 13, 10, 0
|
|
|
|
msgside db 'Side band addressing', 13, 10, 0
|
2012-08-01 10:33:50 +02:00
|
|
|
|
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 ?
|
|
|
|
|