Subversion Repositories Kolibri OS

Rev

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

Rev 2902 Rev 5066
Line 1... Line 1...
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved.    ;;
3
;; Copyright (C) KolibriOS team 2004-2014. All rights reserved.    ;;
4
;; Distributed under terms of the GNU General Public License       ;;
4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
5
;;                                                                 ;;
6
;; simple AGP driver for KolibriOS                                 ;;
6
;; simple AGP driver for KolibriOS                                 ;;
7
;;                                                                 ;;
7
;;                                                                 ;;
8
;;    Written by hidnplayr@kolibrios.org                           ;;
8
;;    Written by hidnplayr@kolibrios.org                           ;;
Line 11... Line 11...
11
;;             Version 2, June 1991                                ;;
11
;;             Version 2, June 1991                                ;;
12
;;                                                                 ;;
12
;;                                                                 ;;
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 14... Line 14...
14
 
14
 
-
 
15
 
Line 15... Line 16...
15
 
16
format PE DLL native
-
 
17
entry START
16
format MS COFF
18
 
Line 17... Line -...
17
 
-
 
18
DEBUG                   equ 1
19
        CURRENT_API             = 0x0200
Line 19... Line -...
19
FAST_WRITE              equ 0           ; may cause problems with some motherboards
-
 
20
 
20
        COMPATIBLE_API          = 0x0100
21
include 'proc32.inc'
-
 
22
include 'imports.inc'
-
 
23
 
-
 
24
struc IOCTL
-
 
25
{  .handle      dd ?
-
 
26
   .io_code     dd ?
-
 
Line -... Line 21...
-
 
21
        API_VERSION             = (COMPATIBLE_API shl 16) + CURRENT_API
27
   .input       dd ?
22
 
28
   .inp_size    dd ?
23
        FAST_WRITE              = 0     ; may cause problems with some motherboards
29
   .output      dd ?
24
 
Line 30... Line -...
30
   .out_size    dd ?
-
 
31
}
25
section '.flat' readable writable executable
32
 
-
 
33
virtual at 0
-
 
34
  IOCTL IOCTL
26
 
35
end virtual
27
include '../proc32.inc'
36
 
-
 
37
public START
-
 
38
public service_proc
28
include '../struct.inc'
39
public version
-
 
40
 
29
include '../macros.inc'
41
DRV_ENTRY       equ 1
-
 
42
DRV_EXIT        equ -1
30
include '../pci_pe.inc'
Line 43... Line 31...
43
 
31
 
Line 44... Line 32...
44
SRV_GETVERSION  equ 0
32
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
45
SRV_DETECT      equ 1
33
;;                        ;;
46
 
-
 
Line 47... Line -...
47
API_VERSION     equ 1
-
 
48
 
34
;; proc START             ;;
49
section '.flat' code readable align 16
35
;;                        ;;
-
 
36
;; (standard driver proc) ;;
-
 
37
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
50
 
38
 
Line 51... Line -...
51
proc START stdcall, state:dword
-
 
52
 
39
proc START c, reason:dword, cmdline:dword
-
 
40
 
53
        cmp     [state], 1
41
        cmp     [reason], DRV_ENTRY
54
        jne     .exit
-
 
55
.entry:
42
        jne     .fail
56
 
43
 
-
 
44
        mov     esi, msgInit
57
     if DEBUG
45
        invoke  SysMsgBoardStr
Line 58... Line 46...
58
        mov     esi, msgInit
46
        invoke  RegService, my_service, service_proc
59
        call    SysMsgBoardStr
47
 
60
     end if
48
        call    detect
61
 
49
 
62
        stdcall RegService, my_service, service_proc
50
        ret
63
        ret
51
 
Line 64... Line -...
64
.fail:
-
 
65
.exit:
52
  .fail:
Line 66... Line 53...
66
        xor     eax, eax
53
        xor     eax, eax
67
        ret
54
        ret
-
 
55
 
68
endp
56
endp
69
 
-
 
Line 70... Line -...
70
handle     equ  IOCTL.handle
-
 
71
io_code    equ  IOCTL.io_code
57
 
72
input      equ  IOCTL.input
58
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
 
59
;;                        ;;
-
 
60
;; proc SERVICE_PROC      ;;
-
 
61
;;                        ;;
-
 
62
;; (standard driver proc) ;;
73
inp_size   equ  IOCTL.inp_size
63
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
 
64
 
74
output     equ  IOCTL.output
65
proc service_proc stdcall, ioctl:dword
75
out_size   equ  IOCTL.out_size
66
 
76
 
-
 
77
align 4
-
 
78
proc service_proc stdcall, ioctl:dword
-
 
79
 
-
 
80
        mov     ebx, [ioctl]
-
 
81
        mov     eax, [ebx+io_code]
-
 
82
        cmp     eax, SRV_GETVERSION
67
        mov     edx, [ioctl]
83
        jne     @F
68
        mov     eax, [edx + IOCTL.io_code]
84
 
69
 
85
        mov     eax, [ebx+output]
70
;------------------------------------------------------
86
        cmp     [ebx+out_size], 4
-
 
Line 87... Line 71...
87
        jne     .fail
71
 
88
        mov     [eax], dword API_VERSION
-
 
89
        xor     eax, eax
-
 
90
        ret
-
 
91
@@:
-
 
92
        mov     ebx, [ioctl]
-
 
Line 93... Line 72...
93
        mov     eax, [ebx+io_code]
72
        cmp     eax, 0 ;SRV_GETVERSION
94
        cmp     eax, SRV_DETECT
73
        jne     .fail
95
        jne     @F
74
 
96
        call    detect
75
        cmp     [edx + IOCTL.out_size], 4
97
@@:
76
        jb      .fail
Line 98... Line 77...
98
.fail:
77
        mov     eax, [edx + IOCTL.output]
99
        or      eax, -1
78
        mov     [eax], dword API_VERSION
Line 100... Line 79...
100
        ret
79
 
101
endp
80
        xor     eax, eax
102
 
81
        ret
103
restore   handle
82
 
104
restore   io_code
83
  .fail:
105
restore   input
84
        or      eax, -1
106
restore   inp_size
85
        ret
Line 107... Line 86...
107
restore   output
86
 
108
restore   out_size
87
endp
109
 
88
 
110
align 4
89
align 4
111
proc detect
-
 
112
           locals
90
proc detect
113
            last_bus dd ?
91
           locals
114
           endl
-
 
115
 
92
            last_bus dd ?
116
        mov     esi, msgSearch
93
           endl
117
        call    SysMsgBoardStr
-
 
118
 
94
 
119
        xor     eax, eax
95
        mov     esi, msgSearch
Line 120... Line 96...
120
        mov     [bus], eax
96
        invoke  SysMsgBoardStr
121
        inc     eax
97
 
Line 148... Line 124...
148
        cmp     eax, [last_bus]
124
        cmp     eax, [last_bus]
149
        jna     .next_bus
125
        jna     .next_bus
Line 150... Line 126...
150
 
126
 
151
  .error:
127
  .error:
152
        mov     esi, msgFail
128
        mov     esi, msgFail
Line 153... Line 129...
153
        call    SysMsgBoardStr
129
        invoke  SysMsgBoardStr
154
 
130
 
155
        xor     eax, eax
131
        xor     eax, eax
Line 156... Line 132...
156
        inc     eax
132
        inc     eax
157
        ret
133
        ret
158
 
134
 
159
  .found:
135
  .found:
Line 160... Line 136...
160
        stdcall PciRead8, [bus], [devfn], dword 0x06    ; read prog IF
136
        invoke  PciRead8, [bus], [devfn], PCI_header00.prog_if
161
        test    al, 1 shl 4                             ; got capabilities list?
137
        test    al, 1 shl 4                             ; got capabilities list?
Line 162... Line 138...
162
        jnz     .got_capabilities_list
138
        jnz     .got_capabilities_list
Line 163... Line 139...
163
 
139
 
164
        ; TODO: Do it the old way: detect device and check with a list of known capabilities
140
        ; TODO: Do it the old way: detect device and check with a list of known capabilities
165
        ; stupid pre PCI 2.2 board....
141
        ; stupid pre PCI 2.2 board....
166
 
142
 
Line 167... Line 143...
167
        jmp     .next
143
        jmp     .next
168
 
144
 
169
  .got_capabilities_list:
145
  .got_capabilities_list:
170
        stdcall PciRead8, [bus], [devfn], dword 0x34    ; read capabilities offset
146
        invoke  PciRead8, [bus], [devfn], PCI_header00.cap_ptr
171
        and     eax, 11111100b                          ; always dword aligned
147
        and     eax, 11111100b                          ; always dword aligned
172
        mov     edi, eax
148
        mov     edi, eax
173
 
149
 
Line 189... Line 165...
189
        cmp     al, 0x30
165
        cmp     al, 0x30
190
        je      .agp_3
166
        je      .agp_3
Line 191... Line 167...
191
 
167
 
192
  .agp_2:
168
  .agp_2:
193
        mov     esi, msgAGP2
169
        mov     esi, msgAGP2
Line 194... Line 170...
194
        call    SysMsgBoardStr
170
        invoke  SysMsgBoardStr
195
 
171
 
196
        stdcall PciRead32, [bus], [devfn], edi          ; read AGP status
172
        invoke  PciRead32, [bus], [devfn], edi          ; read AGP status
197
  .agp_2_:
173
  .agp_2_:
198
        test    al, 100b
-
 
199
        jnz     .100b
174
        test    al, 100b
200
 
175
        jnz     .100b
201
        test    al, 10b
-
 
202
        jnz     .010b
176
        test    al, 10b
203
 
177
        jnz     .010b
Line 204... Line 178...
204
        test    al, 1b
178
        test    al, 1b
205
        jz      .error
179
        jz      .error
206
 
180
 
207
  .001b:
181
  .001b:
208
        mov     [cmd], 001b
182
        mov     [cmd], 001b
Line 209... Line 183...
209
        mov     esi, msg1
183
        mov     esi, msg1
210
        call    SysMsgBoardStr
184
        invoke  SysMsgBoardStr
211
        jmp     .agp_go
185
        jmp     .agp_go
212
 
186
 
213
  .010b:
187
  .010b:
Line 214... Line 188...
214
        mov     [cmd], 010b
188
        mov     [cmd], 010b
215
        mov     esi, msg2
189
        mov     esi, msg2
216
        call    SysMsgBoardStr
190
        invoke  SysMsgBoardStr
217
        jmp     .agp_go
191
        jmp     .agp_go
218
 
192
 
Line 219... Line 193...
219
  .100b:
193
  .100b:
220
        mov     [cmd], 100b
194
        mov     [cmd], 100b
221
        mov     esi, msg4
195
        mov     esi, msg4
222
        call    SysMsgBoardStr
196
        invoke  SysMsgBoardStr
Line 223... Line 197...
223
        jmp     .agp_go
197
        jmp     .agp_go
224
 
198
 
225
  .agp_2m:
199
  .agp_2m:
Line 226... Line 200...
226
        mov     esi, msgAGP2m
200
        mov     esi, msgAGP2m
227
        call    SysMsgBoardStr
201
        invoke  SysMsgBoardStr
228
        jmp     .agp_2_
202
        jmp     .agp_2_
Line 229... Line 203...
229
 
203
 
230
  .agp_3:
204
  .agp_3:
231
        mov     esi, msgAGP3
205
        mov     esi, msgAGP3
232
        call    SysMsgBoardStr
206
        invoke  SysMsgBoardStr
233
 
207
 
234
        stdcall PciRead32, [bus], [devfn], edi          ; read AGP status
208
        invoke  PciRead32, [bus], [devfn], edi          ; read AGP status
Line 235... Line 209...
235
        test    al, 1 shl 3
209
        test    al, 1 shl 3
236
        jz      .agp_2m
210
        jz      .agp_2m
237
 
211
 
238
        test    eax, 10b
212
        test    eax, 10b
Line 239... Line 213...
239
        jnz     .8x
213
        jnz     .8x
Line 240... Line 214...
240
        mov     [cmd], 01b
214
        mov     [cmd], 01b
241
        mov     esi, msg4
215
        mov     esi, msg4
242
        call    SysMsgBoardStr
216
        invoke  SysMsgBoardStr
243
        jmp     .agp_go
217
        jmp     .agp_go
244
 
218
 
245
  .8x:
219
  .8x:
246
        mov     [cmd], 10b
220
        mov     [cmd], 10b
247
        mov     esi, msg8
221
        mov     esi, msg8
Line 248... Line 222...
248
        call    SysMsgBoardStr
222
        invoke  SysMsgBoardStr
249
 
223
 
250
  .agp_go:
224
  .agp_go:
251
 
225
 
252
if FAST_WRITE
226
if FAST_WRITE
253
        test    ax, 1 shl 4
227
        test    ax, 1 shl 4
Line 254... Line 228...
254
        jz      @f
228
        jz      @f
255
        or      [cmd], 1 shl 4
229
        or      [cmd], 1 shl 4
256
        mov     esi, msgfast
230
        mov     esi, msgfast
257
        call    SysMsgBoardStr
231
        invoke  SysMsgBoardStr
Line 258... Line 232...
258
  @@:
232
  @@:
259
end if
233
end if
Line 260... Line 234...
260
 
234
 
Line 261... Line 235...
261
        test    ax, 1 shl 9     ; Side band addressing
235
        test    ax, 1 shl 9     ; Side band addressing
Line 262... Line 236...
262
        jz      @f
236
        jz      @f
Line 263... Line 237...
263
        or      [cmd], 1 shl 9
237
        or      [cmd], 1 shl 9
-
 
238
        mov     esi, msgside
-
 
239
        invoke  SysMsgBoardStr
264
        mov     esi, msgside
240
  @@:
Line 265... Line 241...
265
        call    SysMsgBoardStr
241
 
Line 266... Line 242...
266
  @@:
242
        add     edi, 4
267
 
243
        mov     eax, [cmd]
Line 297... Line 273...
297
msg2            db '2x speed', 13, 10, 0
273
msg2            db '2x speed', 13, 10, 0
298
msg1            db '1x speed', 13, 10, 0
274
msg1            db '1x speed', 13, 10, 0
299
msgfast         db 'Fast Write', 13, 10, 0
275
msgfast         db 'Fast Write', 13, 10, 0
300
msgside         db 'Side band addressing', 13, 10, 0
276
msgside         db 'Side band addressing', 13, 10, 0
Line 301... Line -...
301
 
-
 
302
section '.data' data readable writable align 16
-
 
303
 
277
 
Line 304... Line 278...
304
; uninitialized data
278
; uninitialized data
305
 
279
 
306
revision        db ?
280
revision        db ?