Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
557 serge 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
8
;driver sceletone
9
 
10
format MS COFF
11
 
12
API_VERSION     equ 0  ;debug
13
 
14
include '../proc32.inc'
15
include '../imports.inc'
16
 
17
OS_BASE         equ 0x80000000
18
SLOT_BASE       equ OS_BASE+0x0080000
19
 
20
struc UHCI
21
{
22
   .bus         dd ?
23
   .devfn       dd ?
24
   .io_base     dd ?
25
   .mm_base     dd ?
26
   .irq         dd ?
27
   .flags       dd ?
28
   .reset       dd ?
29
   .start       dd ?
30
   .stop        dd ?
31
   .sizeof:
32
}
33
 
34
virtual at 0
35
  UHCI UHCI
36
end virtual
37
 
38
struc IOCTL
39
{  .handle      dd ?
40
   .io_code     dd ?
41
   .input       dd ?
42
   .inp_size    dd ?
43
   .output      dd ?
44
   .out_size    dd ?
45
}
46
 
47
virtual at 0
48
  IOCTL IOCTL
49
end virtual
50
 
51
public START
52
public service_proc
53
public version
54
 
55
DEBUG        equ 1
56
 
57
DRV_ENTRY    equ 1
58
DRV_EXIT     equ -1
59
STRIDE       equ 4      ;size of row in devices table
60
 
61
SRV_GETVERSION  equ 0
62
 
63
section '.flat' code readable align 16
64
 
65
proc START stdcall, state:dword
66
 
67
           cmp [state], 1
68
           jne .exit
69
.entry:
70
 
71
     if DEBUG
72
           mov esi, msgInit
73
           call SysMsgBoardStr
74
     end if
75
 
76
           call init
77
 
78
           stdcall RegService, my_service, service_proc
79
           ret
80
.fail:
81
.exit:
82
           xor eax, eax
83
           ret
84
endp
85
 
86
handle     equ  IOCTL.handle
87
io_code    equ  IOCTL.io_code
88
input      equ  IOCTL.input
89
inp_size   equ  IOCTL.inp_size
90
output     equ  IOCTL.output
91
out_size   equ  IOCTL.out_size
92
 
93
align 4
94
proc service_proc stdcall, ioctl:dword
95
 
96
           mov ebx, [ioctl]
97
           mov eax, [ebx+io_code]
98
           cmp eax, SRV_GETVERSION
99
           jne @F
100
 
101
           mov eax, [ebx+output]
102
           cmp [ebx+out_size], 4
103
           jne .fail
104
           mov [eax], dword API_VERSION
105
           xor eax, eax
106
           ret
107
@@:
108
.fail:
109
           or eax, -1
110
           ret
111
endp
112
 
113
restore   handle
114
restore   io_code
115
restore   input
116
restore   inp_size
117
restore   output
118
restore   out_size
119
 
120
align 4
121
proc detect
122
           locals
123
            last_bus   dd ?
124
            bus        dd ?
125
            devfn      dd ?
126
           endl
127
 
128
           xor eax, eax
129
           mov [bus], eax
130
           inc eax
131
           call PciApi
132
           cmp eax, -1
133
           je .err
134
 
135
           mov [last_bus], eax
136
 
137
.next_bus:
138
           and [devfn], 0
139
.next_dev:
140
           stdcall PciRead32, [bus], [devfn], dword 0
141
           test eax, eax
142
           jz .next
143
           cmp eax, -1
144
           je .next
145
 
146
           mov edi, devices
147
@@:
148
           mov ebx, [edi]
149
           test ebx, ebx
150
           jz .next
151
 
152
           cmp eax, ebx
153
           je .found
154
 
155
           add edi, STRIDE
156
           jmp @B
157
.next:
158
           inc [devfn]
159
           cmp [devfn], 256
160
           jb  .next_dev
161
           mov eax, [bus]
162
           inc eax
163
           mov [bus], eax
164
           cmp eax, [last_bus]
165
           jna .next_bus
166
           xor eax, eax
167
           ret
168
.found:
169
           mov eax, UHCI.sizeof
170
           call Kmalloc
171
           test eax, eax
172
           jz .mem_fail
173
 
174
           mov ebx, [bus]
175
           mov [eax+UHCI.bus], ebx
176
 
177
           mov ecx, [devfn]
178
           mov [eax+UHCI.devfn], ecx
179
           ret
180
.mem_fail:
181
     if DEBUG
182
           mov esi, msgMemFail
183
           call SysMsgBoardStr
184
     end if
185
.err:
186
           xor eax, eax
187
           ret
188
endp
189
 
190
PCI_BASE     equ 0x20
191
USB_LEGKEY  equ 0xC0
192
 
193
align 4
194
proc init
195
           locals
196
            uhci       dd ?
197
           endl
198
 
199
           call detect
200
           test eax, eax
201
           jz .fail
202
 
203
           mov [uhci], eax
204
 
205
           stdcall PciRead32, [eax+UHCI.bus], [eax+UHCI.devfn], PCI_BASE
206
           and eax, 0xFFC0
207
           mov esi, [uhci]
208
           mov [esi+UHCI.io_base], eax
209
 
210
           stdcall uhci_reset, esi
211
 
212
 
213
.fail:
214
     if DEBUG
215
           mov esi, msgDevNotFound
216
           call SysMsgBoardStr
217
     end if
218
           ret
219
endp
220
 
221
UHCI_USBINTR          equ  4             ; interrupt register
222
 
223
UHCI_USBLEGSUP_RWC    equ  0x8f00        ; the R/WC bits
224
UHCI_USBLEGSUP_RO     equ  0x5040        ; R/O and reserved bits
225
 
226
UHCI_USBCMD_RUN       equ  0x0001        ; RUN/STOP bit
227
UHCI_USBCMD_HCRESET   equ  0x0002        ; Host Controller reset
228
UHCI_USBCMD_EGSM      equ  0x0008        ; Global Suspend Mode
229
UHCI_USBCMD_CONFIGURE equ  0x0040        ; Config Flag
230
UHCI_USBINTR_RESUME   equ  0x0002        ; Resume interrupt enable
231
 
232
 
233
align 4
234
proc uhci_reset stdcall, uhci:dword
235
 
236
           mov esi, [uhci]
237
           stdcall PciRead16, [esi+UHCI.bus], [esi+UHCI.devfn], USB_LEGKEY
238
           test eax, not (UHCI_USBLEGSUP_RO or UHCI_USBLEGSUP_RWC)
239
           jnz .reset
240
 
241
           mov edx, [esi+UHCI.io_base]
242
           in ax, dx
243
           test ax, UHCI_USBCMD_RUN
244
           jnz .reset
245
 
246
           test ax, UHCI_USBCMD_CONFIGURE
247
           jz .reset
248
 
249
           test ax, UHCI_USBCMD_EGSM
250
           jz .reset
251
           ret
252
.reset:
253
           stdcall PciWrite16, [esi+UHCI.bus], [esi+UHCI.devfn], USB_LEGKEY, UHCI_USBLEGSUP_RWC
254
 
255
           mov edx, [esi+UHCI.io_base]
256
           mov ax, UHCI_USBCMD_HCRESET
257
           out dx, ax
258
 
259
           xor eax, eax
260
           out dx, ax
261
           add edx, UHCI_USBINTR
262
           out dx, ax
263
           ret
264
endp
265
 
266
 
267
DEVICE_ID    equ  0x8086;  pci device id
268
VENDOR_ID    equ  0x24D4;  device vendor id
269
 
270
 
271
;all initialized data place here
272
 
273
align 4
274
devices         dd (DEVICE_ID shl 16)+VENDOR_ID
275
                dd 0    ;terminator
276
 
277
version         dd (5 shl 16) or (API_VERSION and 0xFFFF)
278
 
279
my_service      db 'UHCI',0  ;max 16 chars include zero
280
 
281
msgInit         db 'detect hardware...',13,10,0
282
msgPCI          db 'PCI accsess not supported',13,10,0
283
msgDevNotFound  db 'device not found',13,10,0
284
msgMemFail      db 'Kmalloc failed', 10,10,0
285
;msgFail         db 'device not found',13,10,0
286
 
287
section '.data' data readable writable align 16
288
 
289
;all uninitialized data place here
290