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