Details | 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 |
2902 | hidnplayr | 19 | FAST_WRITE equ 0 ; may cause problems with some motherboards |
2899 | hidnplayr | 20 | |
21 | include 'proc32.inc' |
||
22 | include 'imports.inc' |
||
23 | |||
24 | struc IOCTL |
||
25 | { .handle dd ? |
||
26 | .io_code dd ? |
||
27 | .input dd ? |
||
28 | .inp_size dd ? |
||
29 | .output dd ? |
||
30 | .out_size dd ? |
||
31 | } |
||
32 | |||
33 | virtual at 0 |
||
34 | IOCTL IOCTL |
||
35 | end virtual |
||
36 | |||
37 | public START |
||
38 | public service_proc |
||
39 | public version |
||
40 | |||
2900 | hidnplayr | 41 | DRV_ENTRY equ 1 |
42 | DRV_EXIT equ -1 |
||
2899 | hidnplayr | 43 | |
44 | SRV_GETVERSION equ 0 |
||
45 | SRV_DETECT equ 1 |
||
46 | |||
2900 | hidnplayr | 47 | API_VERSION equ 1 |
48 | |||
2899 | hidnplayr | 49 | section '.flat' code readable align 16 |
50 | |||
51 | proc START stdcall, state:dword |
||
52 | |||
53 | cmp [state], 1 |
||
54 | jne .exit |
||
55 | .entry: |
||
56 | |||
57 | if DEBUG |
||
58 | mov esi, msgInit |
||
59 | call SysMsgBoardStr |
||
60 | end if |
||
61 | |||
62 | stdcall RegService, my_service, service_proc |
||
63 | ret |
||
64 | .fail: |
||
65 | .exit: |
||
66 | xor eax, eax |
||
67 | ret |
||
68 | endp |
||
69 | |||
70 | handle equ IOCTL.handle |
||
71 | io_code equ IOCTL.io_code |
||
72 | input equ IOCTL.input |
||
73 | inp_size equ IOCTL.inp_size |
||
74 | output equ IOCTL.output |
||
75 | out_size equ IOCTL.out_size |
||
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 |
||
83 | jne @F |
||
84 | |||
85 | mov eax, [ebx+output] |
||
86 | cmp [ebx+out_size], 4 |
||
87 | jne .fail |
||
88 | mov [eax], dword API_VERSION |
||
89 | xor eax, eax |
||
90 | ret |
||
91 | @@: |
||
92 | mov ebx, [ioctl] |
||
93 | mov eax, [ebx+io_code] |
||
94 | cmp eax, SRV_DETECT |
||
95 | jne @F |
||
96 | call detect |
||
97 | @@: |
||
98 | .fail: |
||
99 | or eax, -1 |
||
100 | ret |
||
101 | endp |
||
102 | |||
103 | restore handle |
||
104 | restore io_code |
||
105 | restore input |
||
106 | restore inp_size |
||
107 | restore output |
||
108 | restore out_size |
||
109 | |||
110 | align 4 |
||
111 | proc detect |
||
112 | locals |
||
113 | last_bus dd ? |
||
114 | endl |
||
115 | |||
2901 | hidnplayr | 116 | mov esi, msgSearch |
117 | call SysMsgBoardStr |
||
118 | |||
2899 | hidnplayr | 119 | xor eax, eax |
120 | mov [bus], eax |
||
121 | inc eax |
||
122 | call PciApi ; get last bus |
||
123 | cmp eax, -1 |
||
124 | je .error |
||
125 | mov [last_bus], eax |
||
126 | |||
127 | .next_bus: |
||
128 | and [devfn], 0 |
||
129 | .next_dev: |
||
2900 | hidnplayr | 130 | stdcall PciRead16, [bus], [devfn], dword 0x0a ; read class/subclass |
2899 | hidnplayr | 131 | |
2901 | hidnplayr | 132 | cmp ax, 0x0300 ; display controller - vga compatable controller |
133 | je .found |
||
134 | |||
2899 | hidnplayr | 135 | cmp ax, 0x0302 ; display controller - 3d controller |
136 | je .found |
||
137 | |||
138 | cmp ax, 0x0380 ; display controller - other display controller |
||
139 | je .found |
||
140 | |||
141 | .next: |
||
142 | inc [devfn] |
||
143 | cmp [devfn], 256 |
||
144 | jb .next_dev |
||
145 | mov eax, [bus] |
||
146 | inc eax |
||
147 | mov [bus], eax |
||
148 | cmp eax, [last_bus] |
||
149 | jna .next_bus |
||
2900 | hidnplayr | 150 | |
151 | .error: |
||
152 | mov esi, msgFail |
||
153 | call SysMsgBoardStr |
||
154 | |||
2899 | hidnplayr | 155 | xor eax, eax |
2900 | hidnplayr | 156 | inc eax |
2899 | hidnplayr | 157 | ret |
158 | |||
159 | .found: |
||
160 | stdcall PciRead8, [bus], [devfn], dword 0x06 ; read prog IF |
||
161 | test al, 1 shl 4 ; got capabilities list? |
||
162 | jnz .got_capabilities_list |
||
163 | |||
2900 | hidnplayr | 164 | ; TODO: Do it the old way: detect device and check with a list of known capabilities |
165 | ; stupid pre PCI 2.2 board.... |
||
166 | |||
167 | jmp .next |
||
168 | |||
2899 | hidnplayr | 169 | .got_capabilities_list: |
170 | stdcall PciRead8, [bus], [devfn], dword 0x34 ; read capabilities offset |
||
171 | and eax, 11111100b ; always dword aligned |
||
2901 | hidnplayr | 172 | mov edi, eax |
2899 | hidnplayr | 173 | |
174 | .read_capability: |
||
2901 | hidnplayr | 175 | stdcall PciRead32, [bus], [devfn], edi ; read capability |
2899 | hidnplayr | 176 | cmp al, 0x02 ; AGP |
177 | je .got_agp |
||
2901 | hidnplayr | 178 | movzx edi, ah ; pointer to next capability |
179 | test edi, edi |
||
2899 | hidnplayr | 180 | jnz .read_capability |
2900 | hidnplayr | 181 | jmp .next |
2899 | hidnplayr | 182 | |
183 | .got_agp: |
||
2901 | hidnplayr | 184 | shr eax, 16 |
2899 | hidnplayr | 185 | mov [revision], al ; high nibble = major revision |
186 | ; low nibble = minor revision |
||
2901 | hidnplayr | 187 | add edi, 4 |
2899 | hidnplayr | 188 | and al, 0xf0 |
189 | cmp al, 0x30 |
||
190 | je .agp_3 |
||
191 | |||
192 | .agp_2: |
||
2901 | hidnplayr | 193 | mov esi, msgAGP2 |
194 | call SysMsgBoardStr |
||
195 | |||
196 | stdcall PciRead32, [bus], [devfn], edi ; read AGP status |
||
197 | .agp_2_: |
||
2899 | hidnplayr | 198 | test al, 100b |
199 | jnz .100b |
||
200 | |||
201 | test al, 10b |
||
202 | jnz .010b |
||
203 | |||
204 | test al, 1b |
||
205 | jz .error |
||
206 | |||
207 | .001b: |
||
2900 | hidnplayr | 208 | mov [cmd], 001b |
2901 | hidnplayr | 209 | mov esi, msg1 |
210 | call SysMsgBoardStr |
||
2899 | hidnplayr | 211 | jmp .agp_go |
212 | |||
213 | .010b: |
||
2900 | hidnplayr | 214 | mov [cmd], 010b |
2901 | hidnplayr | 215 | mov esi, msg2 |
216 | call SysMsgBoardStr |
||
2899 | hidnplayr | 217 | jmp .agp_go |
218 | |||
219 | .100b: |
||
2900 | hidnplayr | 220 | mov [cmd], 100b |
2901 | hidnplayr | 221 | mov esi, msg4 |
222 | call SysMsgBoardStr |
||
2899 | hidnplayr | 223 | jmp .agp_go |
224 | |||
2901 | hidnplayr | 225 | .agp_2m: |
226 | mov esi, msgAGP2m |
||
227 | call SysMsgBoardStr |
||
228 | jmp .agp_2_ |
||
229 | |||
2899 | hidnplayr | 230 | .agp_3: |
2901 | hidnplayr | 231 | mov esi, msgAGP3 |
232 | call SysMsgBoardStr |
||
233 | |||
234 | stdcall PciRead32, [bus], [devfn], edi ; read AGP status |
||
2899 | hidnplayr | 235 | test al, 1 shl 3 |
2901 | hidnplayr | 236 | jz .agp_2m |
2902 | hidnplayr | 237 | |
2901 | hidnplayr | 238 | test eax, 10b |
239 | jnz .8x |
||
240 | mov [cmd], 01b |
||
241 | mov esi, msg4 |
||
242 | call SysMsgBoardStr |
||
243 | jmp .agp_go |
||
244 | |||
245 | .8x: |
||
2900 | hidnplayr | 246 | mov [cmd], 10b |
2901 | hidnplayr | 247 | mov esi, msg8 |
248 | call SysMsgBoardStr |
||
2899 | hidnplayr | 249 | |
250 | .agp_go: |
||
2900 | hidnplayr | 251 | |
252 | if FAST_WRITE |
||
253 | test ax, 1 shl 4 |
||
254 | jz @f |
||
255 | or [cmd], 1 shl 4 |
||
2901 | hidnplayr | 256 | mov esi, msgfast |
257 | call SysMsgBoardStr |
||
2900 | hidnplayr | 258 | @@: |
259 | end if |
||
2902 | hidnplayr | 260 | |
261 | test ax, 1 shl 9 ; Side band addressing |
||
2900 | hidnplayr | 262 | jz @f |
263 | or [cmd], 1 shl 9 |
||
2901 | hidnplayr | 264 | mov esi, msgside |
265 | call SysMsgBoardStr |
||
2900 | hidnplayr | 266 | @@: |
2902 | hidnplayr | 267 | |
2901 | hidnplayr | 268 | add edi, 4 |
2900 | hidnplayr | 269 | mov eax, [cmd] |
2899 | hidnplayr | 270 | or eax, 1 shl 8 ; enable AGP |
2901 | hidnplayr | 271 | stdcall PciWrite32, [bus], [devfn], edi, eax ; write AGP cmd |
2899 | hidnplayr | 272 | |
2900 | hidnplayr | 273 | mov esi, msgOK |
274 | call SysMsgBoardStr |
||
275 | |||
2899 | hidnplayr | 276 | ret |
277 | |||
278 | endp |
||
279 | |||
280 | |||
2900 | hidnplayr | 281 | ; initialized data |
2899 | hidnplayr | 282 | |
283 | align 4 |
||
284 | version dd (5 shl 16) or (API_VERSION and 0xFFFF) |
||
285 | |||
286 | my_service db 'AGP', 0 ; max 16 chars include zero |
||
287 | |||
2901 | hidnplayr | 288 | msgInit db 'AGP driver loaded.', 13, 10, 0 |
289 | msgSearch db 'Searching for AGP card...', 13, 10, 0 |
||
2899 | hidnplayr | 290 | msgFail db 'device not found', 13, 10, 0 |
2900 | hidnplayr | 291 | msgOK db 'AGP device enabled', 13, 10, 0 |
2901 | hidnplayr | 292 | msgAGP2 db 'AGP2 device found', 13, 10, 0 |
293 | msgAGP3 db 'AGP3 device found', 13, 10, 0 |
||
294 | msgAGP2m db 'Running in AGP2 mode', 13, 10, 0 |
||
295 | msg8 db '8x speed', 13, 10, 0 |
||
296 | msg4 db '4x speed', 13, 10, 0 |
||
297 | msg2 db '2x speed', 13, 10, 0 |
||
298 | msg1 db '1x speed', 13, 10, 0 |
||
299 | msgfast db 'Fast Write', 13, 10, 0 |
||
300 | msgside db 'Side band addressing', 13, 10, 0 |
||
2899 | hidnplayr | 301 | |
302 | section '.data' data readable writable align 16 |
||
303 | |||
2900 | hidnplayr | 304 | ; uninitialized data |
2899 | hidnplayr | 305 | |
306 | revision db ? |
||
2900 | hidnplayr | 307 | cmd dd ? |
2899 | hidnplayr | 308 | bus dd ? |
309 | devfn dd ? |
||
310 |