Rev 5074 | Rev 5544 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2900 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
5363 | yogev_ezra | 3 | ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; |
2900 | hidnplayr | 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 | |||
5066 | hidnplayr | 16 | format PE DLL native |
17 | entry START |
||
2899 | hidnplayr | 18 | |
5066 | hidnplayr | 19 | CURRENT_API = 0x0200 |
20 | COMPATIBLE_API = 0x0100 |
||
21 | API_VERSION = (COMPATIBLE_API shl 16) + CURRENT_API |
||
2899 | hidnplayr | 22 | |
5066 | hidnplayr | 23 | FAST_WRITE = 0 ; may cause problems with some motherboards |
2899 | hidnplayr | 24 | |
5066 | hidnplayr | 25 | section '.flat' readable writable executable |
2899 | hidnplayr | 26 | |
5066 | hidnplayr | 27 | include '../proc32.inc' |
28 | include '../struct.inc' |
||
29 | include '../macros.inc' |
||
5074 | hidnplayr | 30 | include '../pci.inc' |
2899 | hidnplayr | 31 | |
5066 | hidnplayr | 32 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
33 | ;; ;; |
||
34 | ;; proc START ;; |
||
35 | ;; ;; |
||
36 | ;; (standard driver proc) ;; |
||
37 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
2899 | hidnplayr | 38 | |
5066 | hidnplayr | 39 | proc START c, reason:dword, cmdline:dword |
2899 | hidnplayr | 40 | |
5066 | hidnplayr | 41 | cmp [reason], DRV_ENTRY |
42 | jne .fail |
||
2899 | hidnplayr | 43 | |
5066 | hidnplayr | 44 | mov esi, msgInit |
45 | invoke SysMsgBoardStr |
||
46 | invoke RegService, my_service, service_proc |
||
2900 | hidnplayr | 47 | |
5066 | hidnplayr | 48 | call detect |
2899 | hidnplayr | 49 | |
5066 | hidnplayr | 50 | ret |
2899 | hidnplayr | 51 | |
5066 | hidnplayr | 52 | .fail: |
2899 | hidnplayr | 53 | xor eax, eax |
54 | ret |
||
5066 | hidnplayr | 55 | |
2899 | hidnplayr | 56 | endp |
57 | |||
5066 | hidnplayr | 58 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
59 | ;; ;; |
||
60 | ;; proc SERVICE_PROC ;; |
||
61 | ;; ;; |
||
62 | ;; (standard driver proc) ;; |
||
63 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
2899 | hidnplayr | 64 | |
65 | proc service_proc stdcall, ioctl:dword |
||
66 | |||
5066 | hidnplayr | 67 | mov edx, [ioctl] |
68 | mov eax, [edx + IOCTL.io_code] |
||
2899 | hidnplayr | 69 | |
5066 | hidnplayr | 70 | ;------------------------------------------------------ |
71 | |||
72 | cmp eax, 0 ;SRV_GETVERSION |
||
2899 | hidnplayr | 73 | jne .fail |
5066 | hidnplayr | 74 | |
75 | cmp [edx + IOCTL.out_size], 4 |
||
76 | jb .fail |
||
77 | mov eax, [edx + IOCTL.output] |
||
2899 | hidnplayr | 78 | mov [eax], dword API_VERSION |
5066 | hidnplayr | 79 | |
2899 | hidnplayr | 80 | xor eax, eax |
81 | ret |
||
5066 | hidnplayr | 82 | |
83 | .fail: |
||
2899 | hidnplayr | 84 | or eax, -1 |
85 | ret |
||
5066 | hidnplayr | 86 | |
2899 | hidnplayr | 87 | endp |
88 | |||
89 | align 4 |
||
90 | proc detect |
||
91 | locals |
||
92 | last_bus dd ? |
||
93 | endl |
||
94 | |||
2901 | hidnplayr | 95 | mov esi, msgSearch |
5066 | hidnplayr | 96 | invoke SysMsgBoardStr |
2901 | hidnplayr | 97 | |
2899 | hidnplayr | 98 | xor eax, eax |
99 | mov [bus], eax |
||
100 | inc eax |
||
5066 | hidnplayr | 101 | invoke PciApi ; get last bus |
2899 | hidnplayr | 102 | cmp eax, -1 |
103 | je .error |
||
104 | mov [last_bus], eax |
||
105 | |||
106 | .next_bus: |
||
107 | and [devfn], 0 |
||
108 | .next_dev: |
||
5066 | hidnplayr | 109 | invoke PciRead16, [bus], [devfn], PCI_header.subclass ; subclass/vendor |
2901 | hidnplayr | 110 | cmp ax, 0x0300 ; display controller - vga compatable controller |
111 | je .found |
||
2899 | hidnplayr | 112 | cmp ax, 0x0302 ; display controller - 3d controller |
113 | je .found |
||
114 | cmp ax, 0x0380 ; display controller - other display controller |
||
115 | je .found |
||
116 | |||
117 | .next: |
||
118 | inc [devfn] |
||
119 | cmp [devfn], 256 |
||
120 | jb .next_dev |
||
121 | mov eax, [bus] |
||
122 | inc eax |
||
123 | mov [bus], eax |
||
124 | cmp eax, [last_bus] |
||
125 | jna .next_bus |
||
2900 | hidnplayr | 126 | |
127 | .error: |
||
128 | mov esi, msgFail |
||
5066 | hidnplayr | 129 | invoke SysMsgBoardStr |
2900 | hidnplayr | 130 | |
2899 | hidnplayr | 131 | xor eax, eax |
2900 | hidnplayr | 132 | inc eax |
2899 | hidnplayr | 133 | ret |
134 | |||
135 | .found: |
||
5066 | hidnplayr | 136 | invoke PciRead8, [bus], [devfn], PCI_header00.prog_if |
2899 | hidnplayr | 137 | test al, 1 shl 4 ; got capabilities list? |
138 | jnz .got_capabilities_list |
||
139 | |||
2900 | hidnplayr | 140 | ; TODO: Do it the old way: detect device and check with a list of known capabilities |
141 | ; stupid pre PCI 2.2 board.... |
||
142 | |||
143 | jmp .next |
||
144 | |||
2899 | hidnplayr | 145 | .got_capabilities_list: |
5066 | hidnplayr | 146 | invoke PciRead8, [bus], [devfn], PCI_header00.cap_ptr |
2899 | hidnplayr | 147 | and eax, 11111100b ; always dword aligned |
2901 | hidnplayr | 148 | mov edi, eax |
2899 | hidnplayr | 149 | |
150 | .read_capability: |
||
5066 | hidnplayr | 151 | invoke PciRead32, [bus], [devfn], edi ; read capability |
2899 | hidnplayr | 152 | cmp al, 0x02 ; AGP |
153 | je .got_agp |
||
2901 | hidnplayr | 154 | movzx edi, ah ; pointer to next capability |
155 | test edi, edi |
||
2899 | hidnplayr | 156 | jnz .read_capability |
2900 | hidnplayr | 157 | jmp .next |
2899 | hidnplayr | 158 | |
159 | .got_agp: |
||
2901 | hidnplayr | 160 | shr eax, 16 |
2899 | hidnplayr | 161 | mov [revision], al ; high nibble = major revision |
162 | ; low nibble = minor revision |
||
2901 | hidnplayr | 163 | add edi, 4 |
2899 | hidnplayr | 164 | and al, 0xf0 |
165 | cmp al, 0x30 |
||
166 | je .agp_3 |
||
167 | |||
168 | .agp_2: |
||
2901 | hidnplayr | 169 | mov esi, msgAGP2 |
5066 | hidnplayr | 170 | invoke SysMsgBoardStr |
2901 | hidnplayr | 171 | |
5066 | hidnplayr | 172 | invoke PciRead32, [bus], [devfn], edi ; read AGP status |
2901 | hidnplayr | 173 | .agp_2_: |
2899 | hidnplayr | 174 | test al, 100b |
175 | jnz .100b |
||
176 | test al, 10b |
||
177 | jnz .010b |
||
178 | test al, 1b |
||
179 | jz .error |
||
180 | |||
181 | .001b: |
||
2900 | hidnplayr | 182 | mov [cmd], 001b |
2901 | hidnplayr | 183 | mov esi, msg1 |
5066 | hidnplayr | 184 | invoke SysMsgBoardStr |
2899 | hidnplayr | 185 | jmp .agp_go |
186 | |||
187 | .010b: |
||
2900 | hidnplayr | 188 | mov [cmd], 010b |
2901 | hidnplayr | 189 | mov esi, msg2 |
5066 | hidnplayr | 190 | invoke SysMsgBoardStr |
2899 | hidnplayr | 191 | jmp .agp_go |
192 | |||
193 | .100b: |
||
2900 | hidnplayr | 194 | mov [cmd], 100b |
2901 | hidnplayr | 195 | mov esi, msg4 |
5066 | hidnplayr | 196 | invoke SysMsgBoardStr |
2899 | hidnplayr | 197 | jmp .agp_go |
198 | |||
2901 | hidnplayr | 199 | .agp_2m: |
200 | mov esi, msgAGP2m |
||
5066 | hidnplayr | 201 | invoke SysMsgBoardStr |
2901 | hidnplayr | 202 | jmp .agp_2_ |
203 | |||
2899 | hidnplayr | 204 | .agp_3: |
2901 | hidnplayr | 205 | mov esi, msgAGP3 |
5066 | hidnplayr | 206 | invoke SysMsgBoardStr |
2901 | hidnplayr | 207 | |
5066 | hidnplayr | 208 | invoke PciRead32, [bus], [devfn], edi ; read AGP status |
2899 | hidnplayr | 209 | test al, 1 shl 3 |
2901 | hidnplayr | 210 | jz .agp_2m |
2902 | hidnplayr | 211 | |
2901 | hidnplayr | 212 | test eax, 10b |
213 | jnz .8x |
||
214 | mov [cmd], 01b |
||
215 | mov esi, msg4 |
||
5066 | hidnplayr | 216 | invoke SysMsgBoardStr |
2901 | hidnplayr | 217 | jmp .agp_go |
218 | |||
219 | .8x: |
||
2900 | hidnplayr | 220 | mov [cmd], 10b |
2901 | hidnplayr | 221 | mov esi, msg8 |
5066 | hidnplayr | 222 | invoke SysMsgBoardStr |
2899 | hidnplayr | 223 | |
224 | .agp_go: |
||
2900 | hidnplayr | 225 | |
226 | if FAST_WRITE |
||
227 | test ax, 1 shl 4 |
||
228 | jz @f |
||
229 | or [cmd], 1 shl 4 |
||
2901 | hidnplayr | 230 | mov esi, msgfast |
5066 | hidnplayr | 231 | invoke SysMsgBoardStr |
2900 | hidnplayr | 232 | @@: |
233 | end if |
||
2902 | hidnplayr | 234 | |
235 | test ax, 1 shl 9 ; Side band addressing |
||
2900 | hidnplayr | 236 | jz @f |
237 | or [cmd], 1 shl 9 |
||
2901 | hidnplayr | 238 | mov esi, msgside |
5066 | hidnplayr | 239 | invoke SysMsgBoardStr |
2900 | hidnplayr | 240 | @@: |
2902 | hidnplayr | 241 | |
2901 | hidnplayr | 242 | add edi, 4 |
2900 | hidnplayr | 243 | mov eax, [cmd] |
2899 | hidnplayr | 244 | or eax, 1 shl 8 ; enable AGP |
5066 | hidnplayr | 245 | invoke PciWrite32, [bus], [devfn], edi, eax ; write AGP cmd |
2899 | hidnplayr | 246 | |
2900 | hidnplayr | 247 | mov esi, msgOK |
5066 | hidnplayr | 248 | invoke SysMsgBoardStr |
2900 | hidnplayr | 249 | |
2899 | hidnplayr | 250 | ret |
251 | |||
252 | endp |
||
253 | |||
254 | |||
5066 | hidnplayr | 255 | ; End of code |
2899 | hidnplayr | 256 | |
5066 | hidnplayr | 257 | data fixups |
258 | end data |
||
2899 | hidnplayr | 259 | |
5066 | hidnplayr | 260 | include '../peimport.inc' |
261 | |||
2899 | hidnplayr | 262 | my_service db 'AGP', 0 ; max 16 chars include zero |
263 | |||
2901 | hidnplayr | 264 | msgInit db 'AGP driver loaded.', 13, 10, 0 |
265 | msgSearch db 'Searching for AGP card...', 13, 10, 0 |
||
2899 | hidnplayr | 266 | msgFail db 'device not found', 13, 10, 0 |
2900 | hidnplayr | 267 | msgOK db 'AGP device enabled', 13, 10, 0 |
2901 | hidnplayr | 268 | msgAGP2 db 'AGP2 device found', 13, 10, 0 |
269 | msgAGP3 db 'AGP3 device found', 13, 10, 0 |
||
270 | msgAGP2m db 'Running in AGP2 mode', 13, 10, 0 |
||
271 | msg8 db '8x speed', 13, 10, 0 |
||
272 | msg4 db '4x speed', 13, 10, 0 |
||
273 | msg2 db '2x speed', 13, 10, 0 |
||
274 | msg1 db '1x speed', 13, 10, 0 |
||
275 | msgfast db 'Fast Write', 13, 10, 0 |
||
276 | msgside db 'Side band addressing', 13, 10, 0 |
||
2899 | hidnplayr | 277 | |
2900 | hidnplayr | 278 | ; uninitialized data |
2899 | hidnplayr | 279 | |
280 | revision db ? |
||
2900 | hidnplayr | 281 | cmd dd ? |
2899 | hidnplayr | 282 | bus dd ? |
283 | devfn dd ? |
||
284 |