Rev 2900 | 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 | |||
2901 | hidnplayr | 117 | mov esi, msgSearch |
118 | call SysMsgBoardStr |
||
119 | |||
2899 | hidnplayr | 120 | xor eax, eax |
121 | mov [bus], eax |
||
122 | inc eax |
||
123 | call PciApi ; get last bus |
||
124 | cmp eax, -1 |
||
125 | je .error |
||
126 | mov [last_bus], eax |
||
127 | |||
128 | .next_bus: |
||
129 | and [devfn], 0 |
||
130 | .next_dev: |
||
2900 | hidnplayr | 131 | stdcall PciRead16, [bus], [devfn], dword 0x0a ; read class/subclass |
2899 | hidnplayr | 132 | |
2901 | hidnplayr | 133 | cmp ax, 0x0300 ; display controller - vga compatable controller |
134 | je .found |
||
135 | |||
2899 | hidnplayr | 136 | cmp ax, 0x0302 ; display controller - 3d controller |
137 | je .found |
||
138 | |||
139 | cmp ax, 0x0380 ; display controller - other display controller |
||
140 | je .found |
||
141 | |||
142 | .next: |
||
143 | inc [devfn] |
||
144 | cmp [devfn], 256 |
||
145 | jb .next_dev |
||
146 | mov eax, [bus] |
||
147 | inc eax |
||
148 | mov [bus], eax |
||
149 | cmp eax, [last_bus] |
||
150 | jna .next_bus |
||
2900 | hidnplayr | 151 | |
152 | .error: |
||
153 | if DEBUG |
||
154 | mov esi, msgFail |
||
155 | call SysMsgBoardStr |
||
156 | end if |
||
157 | |||
2899 | hidnplayr | 158 | xor eax, eax |
2900 | hidnplayr | 159 | inc eax |
2899 | hidnplayr | 160 | ret |
161 | |||
162 | .found: |
||
163 | stdcall PciRead8, [bus], [devfn], dword 0x06 ; read prog IF |
||
164 | test al, 1 shl 4 ; got capabilities list? |
||
165 | jnz .got_capabilities_list |
||
166 | |||
2900 | hidnplayr | 167 | ; TODO: Do it the old way: detect device and check with a list of known capabilities |
168 | ; stupid pre PCI 2.2 board.... |
||
169 | |||
170 | jmp .next |
||
171 | |||
2899 | hidnplayr | 172 | .got_capabilities_list: |
173 | stdcall PciRead8, [bus], [devfn], dword 0x34 ; read capabilities offset |
||
174 | and eax, 11111100b ; always dword aligned |
||
2901 | hidnplayr | 175 | mov edi, eax |
2899 | hidnplayr | 176 | |
177 | .read_capability: |
||
2901 | hidnplayr | 178 | stdcall PciRead32, [bus], [devfn], edi ; read capability |
2899 | hidnplayr | 179 | cmp al, 0x02 ; AGP |
180 | je .got_agp |
||
2901 | hidnplayr | 181 | movzx edi, ah ; pointer to next capability |
182 | test edi, edi |
||
2899 | hidnplayr | 183 | jnz .read_capability |
2900 | hidnplayr | 184 | jmp .next |
2899 | hidnplayr | 185 | |
186 | .got_agp: |
||
2901 | hidnplayr | 187 | shr eax, 16 |
2899 | hidnplayr | 188 | mov [revision], al ; high nibble = major revision |
189 | ; low nibble = minor revision |
||
2901 | hidnplayr | 190 | add edi, 4 |
2899 | hidnplayr | 191 | and al, 0xf0 |
192 | cmp al, 0x30 |
||
193 | je .agp_3 |
||
194 | |||
195 | .agp_2: |
||
2901 | hidnplayr | 196 | mov esi, msgAGP2 |
197 | call SysMsgBoardStr |
||
198 | |||
199 | stdcall PciRead32, [bus], [devfn], edi ; read AGP status |
||
200 | .agp_2_: |
||
2899 | hidnplayr | 201 | test al, 100b |
202 | jnz .100b |
||
203 | |||
204 | test al, 10b |
||
205 | jnz .010b |
||
206 | |||
207 | test al, 1b |
||
208 | jz .error |
||
209 | |||
210 | .001b: |
||
2900 | hidnplayr | 211 | mov [cmd], 001b |
2901 | hidnplayr | 212 | mov esi, msg1 |
213 | call SysMsgBoardStr |
||
2899 | hidnplayr | 214 | jmp .agp_go |
215 | |||
216 | .010b: |
||
2900 | hidnplayr | 217 | mov [cmd], 010b |
2901 | hidnplayr | 218 | mov esi, msg2 |
219 | call SysMsgBoardStr |
||
2899 | hidnplayr | 220 | jmp .agp_go |
221 | |||
222 | .100b: |
||
2900 | hidnplayr | 223 | mov [cmd], 100b |
2901 | hidnplayr | 224 | mov esi, msg4 |
225 | call SysMsgBoardStr |
||
2899 | hidnplayr | 226 | jmp .agp_go |
227 | |||
2901 | hidnplayr | 228 | .agp_2m: |
229 | mov esi, msgAGP2m |
||
230 | call SysMsgBoardStr |
||
231 | jmp .agp_2_ |
||
232 | |||
2899 | hidnplayr | 233 | .agp_3: |
2901 | hidnplayr | 234 | mov esi, msgAGP3 |
235 | call SysMsgBoardStr |
||
236 | |||
237 | stdcall PciRead32, [bus], [devfn], edi ; read AGP status |
||
2899 | hidnplayr | 238 | test al, 1 shl 3 |
2901 | hidnplayr | 239 | jz .agp_2m |
240 | test eax, 10b |
||
241 | jnz .8x |
||
242 | mov [cmd], 01b |
||
243 | mov esi, msg4 |
||
244 | call SysMsgBoardStr |
||
245 | jmp .agp_go |
||
246 | |||
247 | .8x: |
||
2900 | hidnplayr | 248 | mov [cmd], 10b |
2901 | hidnplayr | 249 | mov esi, msg8 |
250 | call SysMsgBoardStr |
||
2899 | hidnplayr | 251 | |
252 | .agp_go: |
||
2900 | hidnplayr | 253 | |
254 | if FAST_WRITE |
||
255 | test ax, 1 shl 4 |
||
256 | jz @f |
||
257 | or [cmd], 1 shl 4 |
||
2901 | hidnplayr | 258 | mov esi, msgfast |
259 | call SysMsgBoardStr |
||
2900 | hidnplayr | 260 | @@: |
261 | end if |
||
262 | if SIDE_BAND_ADDRESSING |
||
263 | test ax, 1 shl 9 |
||
264 | jz @f |
||
265 | or [cmd], 1 shl 9 |
||
2901 | hidnplayr | 266 | mov esi, msgside |
267 | call SysMsgBoardStr |
||
2900 | hidnplayr | 268 | @@: |
269 | end if |
||
2901 | hidnplayr | 270 | add edi, 4 |
2900 | hidnplayr | 271 | mov eax, [cmd] |
2901 | hidnplayr | 272 | stdcall PciWrite32, [bus], [devfn], edi, eax ; write AGP cmd |
273 | |||
274 | mov eax, [cmd] |
||
2899 | hidnplayr | 275 | or eax, 1 shl 8 ; enable AGP |
2901 | hidnplayr | 276 | stdcall PciWrite32, [bus], [devfn], edi, eax ; write AGP cmd |
2899 | hidnplayr | 277 | |
2900 | hidnplayr | 278 | if DEBUG |
279 | mov esi, msgOK |
||
280 | call SysMsgBoardStr |
||
281 | end if |
||
282 | |||
2899 | hidnplayr | 283 | ret |
284 | |||
285 | endp |
||
286 | |||
287 | |||
2900 | hidnplayr | 288 | ; initialized data |
2899 | hidnplayr | 289 | |
290 | align 4 |
||
291 | version dd (5 shl 16) or (API_VERSION and 0xFFFF) |
||
292 | |||
293 | my_service db 'AGP', 0 ; max 16 chars include zero |
||
294 | |||
2901 | hidnplayr | 295 | msgInit db 'AGP driver loaded.', 13, 10, 0 |
296 | msgSearch db 'Searching for AGP card...', 13, 10, 0 |
||
2899 | hidnplayr | 297 | msgFail db 'device not found', 13, 10, 0 |
2900 | hidnplayr | 298 | msgOK db 'AGP device enabled', 13, 10, 0 |
2901 | hidnplayr | 299 | msgAGP2 db 'AGP2 device found', 13, 10, 0 |
300 | msgAGP3 db 'AGP3 device found', 13, 10, 0 |
||
301 | msgAGP2m db 'Running in AGP2 mode', 13, 10, 0 |
||
302 | msg8 db '8x speed', 13, 10, 0 |
||
303 | msg4 db '4x speed', 13, 10, 0 |
||
304 | msg2 db '2x speed', 13, 10, 0 |
||
305 | msg1 db '1x speed', 13, 10, 0 |
||
306 | msgfast db 'Fast Write', 13, 10, 0 |
||
307 | msgside db 'Side band addressing', 13, 10, 0 |
||
2899 | hidnplayr | 308 | |
309 | section '.data' data readable writable align 16 |
||
310 | |||
2900 | hidnplayr | 311 | ; uninitialized data |
2899 | hidnplayr | 312 | |
313 | revision db ? |
||
2900 | hidnplayr | 314 | cmd dd ? |
2899 | hidnplayr | 315 | bus dd ? |
316 | devfn dd ? |
||
317 |