Subversion Repositories Kolibri OS

Rev

Rev 2899 | Rev 2901 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2900 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved.    ;;
4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
6
;; simple AGP driver for KolibriOS                                 ;;
7
;;                                                                 ;;
8
;;    Written by hidnplayr@kolibrios.org                           ;;
9
;;                                                                 ;;
10
;;          GNU GENERAL PUBLIC LICENSE                             ;;
11
;;             Version 2, June 1991                                ;;
12
;;                                                                 ;;
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2899 hidnplayr 14
 
15
 
16
format MS COFF
17
 
2900 hidnplayr 18
DEBUG                   equ 1
19
FAST_WRITE              equ 0
20
SIDE_BAND_ADDRESSING    equ 0
2899 hidnplayr 21
 
22
include 'proc32.inc'
23
include 'imports.inc'
24
 
25
struc IOCTL
26
{  .handle      dd ?
27
   .io_code     dd ?
28
   .input       dd ?
29
   .inp_size    dd ?
30
   .output      dd ?
31
   .out_size    dd ?
32
}
33
 
34
virtual at 0
35
  IOCTL IOCTL
36
end virtual
37
 
38
public START
39
public service_proc
40
public version
41
 
2900 hidnplayr 42
DRV_ENTRY       equ 1
43
DRV_EXIT        equ -1
2899 hidnplayr 44
 
45
SRV_GETVERSION  equ 0
46
SRV_DETECT      equ 1
47
 
2900 hidnplayr 48
API_VERSION     equ 1
49
 
2899 hidnplayr 50
section '.flat' code readable align 16
51
 
52
proc START stdcall, state:dword
53
 
54
        cmp     [state], 1
55
        jne     .exit
56
.entry:
57
 
58
     if DEBUG
59
        mov     esi, msgInit
60
        call    SysMsgBoardStr
61
     end if
62
 
63
        stdcall RegService, my_service, service_proc
64
        ret
65
.fail:
66
.exit:
67
        xor     eax, eax
68
        ret
69
endp
70
 
71
handle     equ  IOCTL.handle
72
io_code    equ  IOCTL.io_code
73
input      equ  IOCTL.input
74
inp_size   equ  IOCTL.inp_size
75
output     equ  IOCTL.output
76
out_size   equ  IOCTL.out_size
77
 
78
align 4
79
proc service_proc stdcall, ioctl:dword
80
 
81
        mov     ebx, [ioctl]
82
        mov     eax, [ebx+io_code]
83
        cmp     eax, SRV_GETVERSION
84
        jne     @F
85
 
86
        mov     eax, [ebx+output]
87
        cmp     [ebx+out_size], 4
88
        jne     .fail
89
        mov     [eax], dword API_VERSION
90
        xor     eax, eax
91
        ret
92
@@:
93
        mov     ebx, [ioctl]
94
        mov     eax, [ebx+io_code]
95
        cmp     eax, SRV_DETECT
96
        jne     @F
97
        call    detect
98
@@:
99
.fail:
100
        or      eax, -1
101
        ret
102
endp
103
 
104
restore   handle
105
restore   io_code
106
restore   input
107
restore   inp_size
108
restore   output
109
restore   out_size
110
 
111
align 4
112
proc detect
113
           locals
114
            last_bus dd ?
115
           endl
116
 
117
        xor     eax, eax
118
        mov     [bus], eax
119
        inc     eax
120
        call    PciApi          ; get last bus
121
        cmp     eax, -1
122
        je      .error
123
        mov     [last_bus], eax
124
 
125
  .next_bus:
126
        and     [devfn], 0
127
  .next_dev:
2900 hidnplayr 128
        stdcall PciRead16, [bus], [devfn], dword 0x0a   ; read class/subclass
2899 hidnplayr 129
 
130
        cmp     ax, 0x0302      ; display controller - 3d controller
131
        je      .found
132
 
133
        cmp     ax, 0x0380      ; display controller - other display controller
134
        je      .found
135
 
136
  .next:
137
        inc     [devfn]
138
        cmp     [devfn], 256
139
        jb      .next_dev
140
        mov     eax, [bus]
141
        inc     eax
142
        mov     [bus], eax
143
        cmp     eax, [last_bus]
144
        jna     .next_bus
2900 hidnplayr 145
 
146
  .error:
147
     if DEBUG
148
        mov     esi, msgFail
149
        call    SysMsgBoardStr
150
     end if
151
 
2899 hidnplayr 152
        xor     eax, eax
2900 hidnplayr 153
        inc     eax
2899 hidnplayr 154
        ret
155
 
156
  .found:
157
        stdcall PciRead8, [bus], [devfn], dword 0x06    ; read prog IF
158
        test    al, 1 shl 4                             ; got capabilities list?
159
        jnz     .got_capabilities_list
160
 
2900 hidnplayr 161
        ; TODO: Do it the old way: detect device and check with a list of known capabilities
162
        ; stupid pre PCI 2.2 board....
163
 
164
        jmp     .next
165
 
2899 hidnplayr 166
  .got_capabilities_list:
167
        stdcall PciRead8, [bus], [devfn], dword 0x34    ; read capabilities offset
168
        and     eax, 11111100b                          ; always dword aligned
169
        mov     esi, eax
170
 
171
  .read_capability:
172
        stdcall PciRead32, [bus], [devfn], esi          ; read capability
173
        cmp     al, 0x02                                ; AGP
174
        je      .got_agp
175
        movzx   esi, ah                                 ; pointer to next capability
176
        test    esi, esi
177
        jnz     .read_capability
2900 hidnplayr 178
        jmp     .next
2899 hidnplayr 179
 
180
  .got_agp:
181
        shl     eax, 16
182
        mov     [revision], al                          ; high nibble = major revision
183
                                                        ; low nibble = minor revision
184
        add     esi, 4
185
        and     al, 0xf0
186
        cmp     al, 0x30
187
        je      .agp_3
188
 
189
  .agp_2:
190
        stdcall PciRead32, [bus], [devfn], esi          ; read AGP status
191
        test    al, 100b
192
        jnz     .100b
193
 
194
        test    al, 10b
195
        jnz     .010b
196
 
197
        test    al, 1b
198
        jz      .error
199
 
200
  .001b:
2900 hidnplayr 201
        mov     [cmd], 001b
2899 hidnplayr 202
        jmp     .agp_go
203
 
204
  .010b:
2900 hidnplayr 205
        mov     [cmd], 010b
2899 hidnplayr 206
        jmp     .agp_go
207
 
208
  .100b:
2900 hidnplayr 209
        mov     [cmd], 100b
2899 hidnplayr 210
        jmp     .agp_go
211
 
212
  .agp_3:
213
        stdcall PciRead32, [bus], [devfn], esi          ; read AGP status
214
        test    al, 1 shl 3
215
        jz      .agp_2
2900 hidnplayr 216
        mov     [cmd], eax
217
        and     [cmd], 11b
218
        cmp     [cmd], 11b
2899 hidnplayr 219
        jne     .agp_go
2900 hidnplayr 220
        mov     [cmd], 10b
2899 hidnplayr 221
 
222
  .agp_go:
2900 hidnplayr 223
 
224
if FAST_WRITE
225
        test    ax, 1 shl 4
226
        jz      @f
227
        or      [cmd], 1 shl 4
228
  @@:
229
end if
230
if SIDE_BAND_ADDRESSING
231
        test    ax, 1 shl 9
232
        jz      @f
233
        or      [cmd], 1 shl 9
234
  @@:
235
end if
2899 hidnplayr 236
        add     esi, 4
2900 hidnplayr 237
        mov     eax, [cmd]
2899 hidnplayr 238
        or      eax, 1 shl 8                            ; enable AGP
239
        stdcall PciWrite32, [bus], [devfn], esi, eax    ; write AGP cmd
240
 
2900 hidnplayr 241
     if DEBUG
242
        mov     esi, msgOK
243
        call    SysMsgBoardStr
244
     end if
245
 
2899 hidnplayr 246
        ret
247
 
248
endp
249
 
250
 
2900 hidnplayr 251
; initialized data
2899 hidnplayr 252
 
253
align 4
254
version         dd (5 shl 16) or (API_VERSION and 0xFFFF)
255
 
256
my_service      db 'AGP', 0                             ; max 16 chars include zero
257
 
2900 hidnplayr 258
msgInit         db 'Searching AGP device...', 13, 10, 0
2899 hidnplayr 259
msgFail         db 'device not found', 13, 10, 0
2900 hidnplayr 260
msgOK           db 'AGP device enabled', 13, 10, 0
2899 hidnplayr 261
 
262
section '.data' data readable writable align 16
263
 
2900 hidnplayr 264
; uninitialized data
2899 hidnplayr 265
 
266
revision        db ?
2900 hidnplayr 267
cmd             dd ?
2899 hidnplayr 268
bus             dd ?
269
devfn           dd ?
270