Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2899 | 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 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
7 | |||
8 | |||
9 | format MS COFF |
||
10 | |||
11 | DEBUG equ 1 |
||
12 | API_VERSION equ 1 |
||
13 | |||
14 | include 'proc32.inc' |
||
15 | include 'imports.inc' |
||
16 | |||
17 | struc IOCTL |
||
18 | { .handle dd ? |
||
19 | .io_code dd ? |
||
20 | .input dd ? |
||
21 | .inp_size dd ? |
||
22 | .output dd ? |
||
23 | .out_size dd ? |
||
24 | } |
||
25 | |||
26 | virtual at 0 |
||
27 | IOCTL IOCTL |
||
28 | end virtual |
||
29 | |||
30 | public START |
||
31 | public service_proc |
||
32 | public version |
||
33 | |||
34 | DRV_ENTRY equ 1 |
||
35 | DRV_EXIT equ -1 |
||
36 | |||
37 | SRV_GETVERSION equ 0 |
||
38 | SRV_DETECT equ 1 |
||
39 | |||
40 | section '.flat' code readable align 16 |
||
41 | |||
42 | proc START stdcall, state:dword |
||
43 | |||
44 | cmp [state], 1 |
||
45 | jne .exit |
||
46 | .entry: |
||
47 | |||
48 | if DEBUG |
||
49 | mov esi, msgInit |
||
50 | call SysMsgBoardStr |
||
51 | end if |
||
52 | |||
53 | stdcall RegService, my_service, service_proc |
||
54 | ret |
||
55 | .fail: |
||
56 | .exit: |
||
57 | xor eax, eax |
||
58 | ret |
||
59 | endp |
||
60 | |||
61 | handle equ IOCTL.handle |
||
62 | io_code equ IOCTL.io_code |
||
63 | input equ IOCTL.input |
||
64 | inp_size equ IOCTL.inp_size |
||
65 | output equ IOCTL.output |
||
66 | out_size equ IOCTL.out_size |
||
67 | |||
68 | align 4 |
||
69 | proc service_proc stdcall, ioctl:dword |
||
70 | |||
71 | mov ebx, [ioctl] |
||
72 | mov eax, [ebx+io_code] |
||
73 | cmp eax, SRV_GETVERSION |
||
74 | jne @F |
||
75 | |||
76 | mov eax, [ebx+output] |
||
77 | cmp [ebx+out_size], 4 |
||
78 | jne .fail |
||
79 | mov [eax], dword API_VERSION |
||
80 | xor eax, eax |
||
81 | ret |
||
82 | @@: |
||
83 | mov ebx, [ioctl] |
||
84 | mov eax, [ebx+io_code] |
||
85 | cmp eax, SRV_DETECT |
||
86 | jne @F |
||
87 | call detect |
||
88 | @@: |
||
89 | .fail: |
||
90 | or eax, -1 |
||
91 | ret |
||
92 | endp |
||
93 | |||
94 | restore handle |
||
95 | restore io_code |
||
96 | restore input |
||
97 | restore inp_size |
||
98 | restore output |
||
99 | restore out_size |
||
100 | |||
101 | align 4 |
||
102 | proc detect |
||
103 | locals |
||
104 | last_bus dd ? |
||
105 | endl |
||
106 | |||
107 | xor eax, eax |
||
108 | mov [bus], eax |
||
109 | inc eax |
||
110 | call PciApi ; get last bus |
||
111 | cmp eax, -1 |
||
112 | je .error |
||
113 | |||
114 | mov [last_bus], eax |
||
115 | |||
116 | .next_bus: |
||
117 | and [devfn], 0 |
||
118 | .next_dev: |
||
119 | stdcall PciRead16, [bus], [devfn], dword 0x08 ; read class/subclass |
||
120 | test eax, eax |
||
121 | jz .next |
||
122 | cmp eax, -1 |
||
123 | je .next |
||
124 | |||
125 | cmp ax, 0x0302 ; display controller - 3d controller |
||
126 | je .found |
||
127 | |||
128 | cmp ax, 0x0380 ; display controller - other display controller |
||
129 | je .found |
||
130 | |||
131 | .next: |
||
132 | inc [devfn] |
||
133 | cmp [devfn], 256 |
||
134 | jb .next_dev |
||
135 | mov eax, [bus] |
||
136 | inc eax |
||
137 | mov [bus], eax |
||
138 | cmp eax, [last_bus] |
||
139 | jna .next_bus |
||
140 | xor eax, eax |
||
141 | ret |
||
142 | |||
143 | .found: |
||
144 | stdcall PciRead8, [bus], [devfn], dword 0x06 ; read prog IF |
||
145 | test al, 1 shl 4 ; got capabilities list? |
||
146 | jnz .got_capabilities_list |
||
147 | |||
148 | .got_capabilities_list: |
||
149 | stdcall PciRead8, [bus], [devfn], dword 0x34 ; read capabilities offset |
||
150 | and eax, 11111100b ; always dword aligned |
||
151 | mov esi, eax |
||
152 | |||
153 | .read_capability: |
||
154 | stdcall PciRead32, [bus], [devfn], esi ; read capability |
||
155 | cmp al, 0x02 ; AGP |
||
156 | je .got_agp |
||
157 | movzx esi, ah ; pointer to next capability |
||
158 | test esi, esi |
||
159 | jnz .read_capability |
||
160 | .error: |
||
161 | xor eax, eax |
||
162 | inc eax |
||
163 | ret |
||
164 | |||
165 | .got_agp: |
||
166 | shl eax, 16 |
||
167 | mov [revision], al ; high nibble = major revision |
||
168 | ; low nibble = minor revision |
||
169 | add esi, 4 |
||
170 | and al, 0xf0 |
||
171 | cmp al, 0x30 |
||
172 | je .agp_3 |
||
173 | |||
174 | .agp_2: |
||
175 | stdcall PciRead32, [bus], [devfn], esi ; read AGP status |
||
176 | test al, 100b |
||
177 | jnz .100b |
||
178 | |||
179 | test al, 10b |
||
180 | jnz .010b |
||
181 | |||
182 | test al, 1b |
||
183 | jz .error |
||
184 | |||
185 | .001b: |
||
186 | mov [speed], 001b |
||
187 | jmp .agp_go |
||
188 | |||
189 | .010b: |
||
190 | mov [speed], 010b |
||
191 | jmp .agp_go |
||
192 | |||
193 | .100b: |
||
194 | mov [speed], 100b |
||
195 | jmp .agp_go |
||
196 | |||
197 | .agp_3: |
||
198 | stdcall PciRead32, [bus], [devfn], esi ; read AGP status |
||
199 | test al, 1 shl 3 |
||
200 | jz .agp_2 |
||
201 | and al, 11b |
||
202 | mov [speed], al |
||
203 | cmp al, 11b |
||
204 | jne .agp_go |
||
205 | mov [speed], 10b |
||
206 | |||
207 | .agp_go: |
||
208 | add esi, 4 |
||
209 | stdcall PciRead32, [bus], [devfn], esi ; read AGP cmd |
||
210 | and al, not 111b ; set max speed |
||
211 | or al, [speed] |
||
212 | or eax, 1 shl 8 ; enable AGP |
||
213 | stdcall PciWrite32, [bus], [devfn], esi, eax ; write AGP cmd |
||
214 | |||
215 | ret |
||
216 | |||
217 | endp |
||
218 | |||
219 | |||
220 | ;all initialized data place here |
||
221 | |||
222 | align 4 |
||
223 | version dd (5 shl 16) or (API_VERSION and 0xFFFF) |
||
224 | |||
225 | my_service db 'AGP', 0 ; max 16 chars include zero |
||
226 | |||
227 | msgInit db 'detect hardware...', 13, 10, 0 |
||
228 | msgPCI db 'PCI acces not supported', 13, 10, 0 |
||
229 | msgFail db 'device not found', 13, 10, 0 |
||
230 | |||
231 | section '.data' data readable writable align 16 |
||
232 | |||
233 | ;all uninitialized data place here |
||
234 | |||
235 | revision db ? |
||
236 | speed db ? |
||
237 | bus dd ? |
||
238 | devfn dd ? |
||
239 |