Rev 4841 | Rev 5147 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4850 | mario79 | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; Copyright (C) KolibriOS team 2014. All rights reserved. ;; |
||
4 | ;; Distributed under terms of the GNU General Public License ;; |
||
5 | ;; ;; |
||
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
7 | |||
8 | $Revision: 4850 $ |
||
9 | |||
10 | |||
4624 | mario79 | 11 | ;----------------------------------------------------------------------------- |
12 | ; find the IDE controller in the device list |
||
13 | ;----------------------------------------------------------------------------- |
||
4700 | mario79 | 14 | mov ecx, IDE_controller_1 |
4624 | mario79 | 15 | mov esi, pcidev_list |
4700 | mario79 | 16 | ;-------------------------------------- |
17 | align 4 |
||
4624 | mario79 | 18 | .loop: |
19 | mov esi, [esi+PCIDEV.fd] |
||
20 | cmp esi, pcidev_list |
||
4700 | mario79 | 21 | jz find_IDE_controller_done |
22 | |||
4624 | mario79 | 23 | mov eax, [esi+PCIDEV.class] |
24 | shr eax, 4 |
||
25 | cmp eax, 0x01018 |
||
26 | jnz .loop |
||
4700 | mario79 | 27 | ;-------------------------------------- |
4624 | mario79 | 28 | .found: |
29 | mov eax, [esi+PCIDEV.class] |
||
30 | DEBUGF 1, 'K : IDE controller programming interface %x\n', eax |
||
4700 | mario79 | 31 | mov [ecx+IDE_DATA.ProgrammingInterface], eax |
4624 | mario79 | 32 | |
33 | mov ah, [esi+PCIDEV.bus] |
||
34 | mov al, 2 |
||
35 | mov bh, [esi+PCIDEV.devfn] |
||
4700 | mario79 | 36 | ;-------------------------------------- |
4841 | clevermous | 37 | mov dx, 0x1F0 |
38 | test byte [esi+PCIDEV.class], 1 |
||
39 | jz @f |
||
4624 | mario79 | 40 | mov bl, 0x10 |
41 | push eax |
||
42 | call pci_read_reg |
||
43 | and eax, 0xFFFC |
||
4841 | clevermous | 44 | mov edx, eax |
45 | pop eax |
||
4624 | mario79 | 46 | @@: |
4841 | clevermous | 47 | DEBUGF 1, 'K : BAR0 IDE base addr %x\n', dx |
48 | mov [StandardATABases], dx |
||
49 | mov [ecx+IDE_DATA.BAR0_val], dx |
||
4700 | mario79 | 50 | ;-------------------------------------- |
4841 | clevermous | 51 | mov dx, 0x3F4 |
52 | test byte [esi+PCIDEV.class], 1 |
||
53 | jz @f |
||
4624 | mario79 | 54 | mov bl, 0x14 |
55 | push eax |
||
56 | call pci_read_reg |
||
57 | and eax, 0xFFFC |
||
4841 | clevermous | 58 | mov edx, eax |
59 | pop eax |
||
4624 | mario79 | 60 | @@: |
4841 | clevermous | 61 | DEBUGF 1, 'K : BAR1 IDE base addr %x\n', dx |
62 | mov [ecx+IDE_DATA.BAR1_val], dx |
||
4700 | mario79 | 63 | ;-------------------------------------- |
4841 | clevermous | 64 | mov dx, 0x170 |
65 | test byte [esi+PCIDEV.class], 4 |
||
66 | jz @f |
||
4624 | mario79 | 67 | mov bl, 0x18 |
68 | push eax |
||
69 | call pci_read_reg |
||
70 | and eax, 0xFFFC |
||
4841 | clevermous | 71 | mov edx, eax |
72 | pop eax |
||
4624 | mario79 | 73 | @@: |
4841 | clevermous | 74 | DEBUGF 1, 'K : BAR2 IDE base addr %x\n', dx |
75 | mov [StandardATABases+2], dx |
||
76 | mov [ecx+IDE_DATA.BAR2_val], dx |
||
4700 | mario79 | 77 | ;-------------------------------------- |
4841 | clevermous | 78 | mov dx, 0x374 |
79 | test byte [esi+PCIDEV.class], 4 |
||
80 | jz @f |
||
4624 | mario79 | 81 | mov bl, 0x1C |
82 | push eax |
||
83 | call pci_read_reg |
||
84 | and eax, 0xFFFC |
||
4841 | clevermous | 85 | mov edx, eax |
86 | pop eax |
||
4624 | mario79 | 87 | @@: |
4841 | clevermous | 88 | DEBUGF 1, 'K : BAR3 IDE base addr %x\n', dx |
89 | mov [ecx+IDE_DATA.BAR3_val], dx |
||
4700 | mario79 | 90 | ;-------------------------------------- |
4624 | mario79 | 91 | mov bl, 0x20 |
92 | push eax |
||
93 | call pci_read_reg |
||
94 | and eax, 0xFFFC |
||
95 | DEBUGF 1, 'K : BAR4 IDE controller register base addr %x\n', ax |
||
4700 | mario79 | 96 | mov [ecx+IDE_DATA.RegsBaseAddres], ax |
4624 | mario79 | 97 | pop eax |
4700 | mario79 | 98 | ;-------------------------------------- |
4624 | mario79 | 99 | mov bl, 0x3C |
100 | push eax |
||
101 | call pci_read_reg |
||
102 | and eax, 0xFF |
||
103 | DEBUGF 1, 'K : IDE Interrupt %x\n', al |
||
4700 | mario79 | 104 | mov [ecx+IDE_DATA.Interrupt], ax |
4624 | mario79 | 105 | pop eax |
4700 | mario79 | 106 | |
107 | add ecx, sizeof.IDE_DATA |
||
108 | ;-------------------------------------- |
||
109 | jmp .loop |
||
4624 | mario79 | 110 | ;----------------------------------------------------------------------------- |
4700 | mario79 | 111 | uglobal |
112 | align 4 |
||
113 | ;-------------------------------------- |
||
114 | IDE_controller_pointer dd ? |
||
115 | ;-------------------------------------- |
||
116 | IDE_controller_1 IDE_DATA |
||
117 | IDE_controller_2 IDE_DATA |
||
118 | IDE_controller_3 IDE_DATA |
||
119 | ;-------------------------------------- |
||
120 | cache_ide0 IDE_CACHE |
||
121 | cache_ide1 IDE_CACHE |
||
122 | cache_ide2 IDE_CACHE |
||
123 | cache_ide3 IDE_CACHE |
||
124 | cache_ide4 IDE_CACHE |
||
125 | cache_ide5 IDE_CACHE |
||
126 | cache_ide6 IDE_CACHE |
||
127 | cache_ide7 IDE_CACHE |
||
128 | cache_ide8 IDE_CACHE |
||
129 | cache_ide9 IDE_CACHE |
||
130 | cache_ide10 IDE_CACHE |
||
131 | cache_ide11 IDE_CACHE |
||
132 | ;-------------------------------------- |
||
4772 | mario79 | 133 | IDE_device_1 rd 2 |
134 | IDE_device_2 rd 2 |
||
135 | IDE_device_3 rd 2 |
||
136 | ;-------------------------------------- |
||
4700 | mario79 | 137 | endg |
4624 | mario79 | 138 | ;----------------------------------------------------------------------------- |
139 | ; START of initialisation IDE ATA code |
||
140 | ;----------------------------------------------------------------------------- |
||
4700 | mario79 | 141 | Init_IDE_ATA_controller: |
142 | cmp [ecx+IDE_DATA.ProgrammingInterface], 0 |
||
4720 | mario79 | 143 | jne @f |
4624 | mario79 | 144 | |
4720 | mario79 | 145 | ret |
146 | ;-------------------------------------- |
||
147 | @@: |
||
4624 | mario79 | 148 | mov esi, boot_disabling_ide |
149 | call boot_log |
||
150 | ;-------------------------------------- |
||
151 | ; Disable IDE interrupts, because the search |
||
152 | ; for IDE partitions is in the PIO mode. |
||
153 | ;-------------------------------------- |
||
154 | .disable_IDE_interrupt: |
||
155 | ; Disable interrupts in IDE controller for PIO |
||
156 | mov al, 2 |
||
4700 | mario79 | 157 | mov dx, [ecx+IDE_DATA.BAR1_val] ;0x3F4 |
4624 | mario79 | 158 | add dx, 2 ;0x3F6 |
159 | out dx, al |
||
4700 | mario79 | 160 | mov dx, [ecx+IDE_DATA.BAR3_val] ;0x374 |
4624 | mario79 | 161 | add dx, 2 ;0x376 |
162 | out dx, al |
||
4700 | mario79 | 163 | ;----------------------------------------------------------------------------- |
164 | ; set current ata bases |
||
4624 | mario79 | 165 | @@: |
4700 | mario79 | 166 | mov ax, [ecx+IDE_DATA.BAR0_val] |
167 | mov [StandardATABases], ax |
||
168 | mov ax, [ecx+IDE_DATA.BAR2_val] |
||
169 | mov [StandardATABases+2], ax |
||
170 | |||
4624 | mario79 | 171 | mov esi, boot_detecthdcd |
172 | call boot_log |
||
4720 | mario79 | 173 | ;-------------------------------------- |
4625 | mario79 | 174 | include 'dev_hdcd.inc' |
4720 | mario79 | 175 | ;-------------------------------------- |
176 | ret |
||
4624 | mario79 | 177 | ;----------------------------------------------------------------------------- |
4720 | mario79 | 178 | Init_IDE_ATA_controller_2: |
179 | cmp [ecx+IDE_DATA.ProgrammingInterface], 0 |
||
180 | jne @f |
||
181 | |||
182 | ret |
||
183 | ;-------------------------------------- |
||
184 | @@: |
||
4700 | mario79 | 185 | mov dx, [ecx+IDE_DATA.RegsBaseAddres] |
4624 | mario79 | 186 | ; test whether it is our interrupt? |
187 | add dx, 2 |
||
188 | in al, dx |
||
189 | test al, 100b |
||
190 | jz @f |
||
191 | ; clear Bus Master IDE Status register |
||
192 | ; clear Interrupt bit |
||
193 | out dx, al |
||
4700 | mario79 | 194 | ;-------------------------------------- |
4624 | mario79 | 195 | @@: |
196 | add dx, 8 |
||
197 | ; test whether it is our interrupt? |
||
198 | in al, dx |
||
199 | test al, 100b |
||
200 | jz @f |
||
201 | ; clear Bus Master IDE Status register |
||
202 | ; clear Interrupt bit |
||
203 | out dx, al |
||
4700 | mario79 | 204 | ;-------------------------------------- |
4624 | mario79 | 205 | @@: |
206 | ; read status register and remove the interrupt request |
||
4700 | mario79 | 207 | mov dx, [ecx+IDE_DATA.BAR0_val] ;0x1F0 |
4624 | mario79 | 208 | add dx, 0x7 ;0x1F7 |
209 | in al, dx |
||
4700 | mario79 | 210 | mov dx, [ecx+IDE_DATA.BAR2_val] ;0x170 |
4624 | mario79 | 211 | add dx, 0x7 ;0x177 |
212 | in al, dx |
||
213 | ;----------------------------------------------------------------------------- |
||
4720 | mario79 | 214 | ; push eax edx |
215 | ; mov dx, [ecx+IDE_DATA.RegsBaseAddres] |
||
216 | ; xor eax, eax |
||
217 | ; add dx, 2 |
||
218 | ; in al, dx |
||
4711 | mario79 | 219 | ; DEBUGF 1, "K : Primary Bus Master IDE Status Register %x\n", eax |
4624 | mario79 | 220 | |
4720 | mario79 | 221 | ; add dx, 8 |
222 | ; in al, dx |
||
4711 | mario79 | 223 | ; DEBUGF 1, "K : Secondary Bus Master IDE Status Register %x\n", eax |
4720 | mario79 | 224 | ; pop edx eax |
4624 | mario79 | 225 | |
4720 | mario79 | 226 | ; cmp [ecx+IDE_DATA.RegsBaseAddres], 0 |
227 | ; setnz [ecx+IDE_DATA.dma_hdd] |
||
4624 | mario79 | 228 | ;----------------------------------------------------------------------------- |
229 | ; set interrupts for IDE Controller |
||
230 | ;----------------------------------------------------------------------------- |
||
4838 | mario79 | 231 | pushfd |
232 | cli |
||
4624 | mario79 | 233 | .enable_IDE_interrupt: |
234 | mov esi, boot_enabling_ide |
||
235 | call boot_log |
||
236 | ; Enable interrupts in IDE controller for DMA |
||
4700 | mario79 | 237 | xor ebx, ebx |
238 | cmp ecx, IDE_controller_2 |
||
239 | jne @f |
||
240 | |||
241 | add ebx, 5 |
||
242 | jmp .check_DRIVE_DATA |
||
243 | ;-------------------------------------- |
||
244 | @@: |
||
245 | cmp ecx, IDE_controller_3 |
||
246 | jne .check_DRIVE_DATA |
||
247 | |||
248 | add ebx, 10 |
||
249 | ;-------------------------------------- |
||
250 | .check_DRIVE_DATA: |
||
4624 | mario79 | 251 | mov al, 0 |
4700 | mario79 | 252 | mov ah, [ebx+DRIVE_DATA+1] |
4772 | mario79 | 253 | test ah, 10100000b ; check for ATAPI devices |
4624 | mario79 | 254 | jz @f |
4772 | mario79 | 255 | ;-------------------------------------- |
256 | .ch1_pio_set_ATAPI: |
||
4624 | mario79 | 257 | DEBUGF 1, "K : IDE CH1 PIO, because ATAPI drive present\n" |
4772 | mario79 | 258 | jmp .ch1_pio_set_for_all |
259 | ;-------------------------------------- |
||
260 | .ch1_pio_set_no_devices: |
||
261 | DEBUGF 1, "K : IDE CH1 PIO because no devices\n" |
||
262 | jmp .ch1_pio_set_for_all |
||
263 | ;------------------------------------- |
||
264 | .ch1_pio_set: |
||
265 | DEBUGF 1, "K : IDE CH1 PIO because device not support UDMA\n" |
||
266 | ;------------------------------------- |
||
267 | .ch1_pio_set_for_all: |
||
268 | mov [ecx+IDE_DATA.dma_hdd_channel_1], al |
||
4624 | mario79 | 269 | jmp .ch2_check |
4700 | mario79 | 270 | ;-------------------------------------- |
4624 | mario79 | 271 | @@: |
4772 | mario79 | 272 | xor ebx, ebx |
273 | call calculate_IDE_device_values_storage |
||
274 | |||
275 | test ah, 1010000b |
||
276 | jz .ch1_pio_set_no_devices |
||
277 | |||
278 | test ah, 1000000b |
||
279 | jz @f |
||
280 | |||
281 | cmp [ebx+IDE_DEVICE.UDMA_possible_modes], al |
||
282 | je .ch1_pio_set |
||
283 | |||
284 | cmp [ebx+IDE_DEVICE.UDMA_set_mode], al |
||
285 | je .ch1_pio_set |
||
286 | ;-------------------------------------- |
||
287 | @@: |
||
288 | test ah, 10000b |
||
289 | jz @f |
||
290 | |||
291 | add ebx, 2 |
||
292 | |||
293 | cmp [ebx+IDE_DEVICE.UDMA_possible_modes], al |
||
294 | je .ch1_pio_set |
||
295 | |||
296 | cmp [ebx+IDE_DEVICE.UDMA_set_mode], al |
||
297 | je .ch1_pio_set |
||
298 | ;-------------------------------------- |
||
299 | @@: |
||
4700 | mario79 | 300 | mov dx, [ecx+IDE_DATA.BAR1_val] ;0x3F4 |
4624 | mario79 | 301 | add dx, 2 ;0x3F6 |
302 | out dx, al |
||
303 | DEBUGF 1, "K : IDE CH1 DMA enabled\n" |
||
4720 | mario79 | 304 | mov [ecx+IDE_DATA.dma_hdd_channel_1], byte 1 |
4700 | mario79 | 305 | ;-------------------------------------- |
4624 | mario79 | 306 | .ch2_check: |
4772 | mario79 | 307 | test ah, 1010b ; check for ATAPI devices |
4624 | mario79 | 308 | jz @f |
4772 | mario79 | 309 | ;-------------------------------------- |
310 | .ch2_pio_set_ATAPI: |
||
4624 | mario79 | 311 | DEBUGF 1, "K : IDE CH2 PIO, because ATAPI drive present\n" |
4772 | mario79 | 312 | jmp .ch2_pio_set_for_all |
313 | ;-------------------------------------- |
||
314 | .ch2_pio_set_no_devices: |
||
315 | DEBUGF 1, "K : IDE CH2 PIO because no devices\n" |
||
316 | jmp .ch2_pio_set_for_all |
||
317 | ;-------------------------------------- |
||
318 | .ch2_pio_set: |
||
319 | DEBUGF 1, "K : IDE CH2 PIO because device not support UDMA\n" |
||
320 | ;-------------------------------------- |
||
321 | .ch2_pio_set_for_all: |
||
322 | mov [ecx+IDE_DATA.dma_hdd_channel_2], al |
||
4838 | mario79 | 323 | jmp .set_interrupts_for_IDE_controllers |
4700 | mario79 | 324 | ;-------------------------------------- |
4624 | mario79 | 325 | @@: |
4772 | mario79 | 326 | mov ebx, 4 |
327 | call calculate_IDE_device_values_storage |
||
328 | |||
329 | test ah, 101b |
||
330 | jz .ch2_pio_set_no_devices |
||
331 | |||
332 | test ah, 100b |
||
333 | jz @f |
||
334 | |||
335 | cmp [ebx+IDE_DEVICE.UDMA_possible_modes], al |
||
336 | je .ch2_pio_set |
||
337 | |||
338 | cmp [ebx+IDE_DEVICE.UDMA_set_mode], al |
||
339 | je .ch2_pio_set |
||
340 | ;-------------------------------------- |
||
341 | @@: |
||
342 | test ah, 1b |
||
343 | jz @f |
||
344 | |||
345 | add ebx, 2 |
||
346 | |||
347 | cmp [ebx+IDE_DEVICE.UDMA_possible_modes], al |
||
348 | je .ch2_pio_set |
||
349 | |||
350 | cmp [ebx+IDE_DEVICE.UDMA_set_mode], al |
||
351 | je .ch2_pio_set |
||
352 | ;-------------------------------------- |
||
353 | @@: |
||
4700 | mario79 | 354 | mov dx, [ecx+IDE_DATA.BAR3_val] ;0x374 |
4624 | mario79 | 355 | add dx, 2 ;0x376 |
356 | out dx, al |
||
357 | DEBUGF 1, "K : IDE CH2 DMA enabled\n" |
||
4720 | mario79 | 358 | mov [ecx+IDE_DATA.dma_hdd_channel_2], byte 1 |
4624 | mario79 | 359 | ;-------------------------------------- |
4838 | mario79 | 360 | .set_interrupts_for_IDE_controllers: |
361 | mov esi, boot_set_int_IDE |
||
362 | call boot_log |
||
363 | ;-------------------------------------- |
||
364 | mov eax, [ecx+IDE_DATA.ProgrammingInterface] |
||
365 | cmp ax, 0x0180 |
||
366 | je .pata_ide |
||
367 | |||
368 | cmp ax, 0x018a |
||
369 | jne .sata_ide |
||
370 | ;-------------------------------------- |
||
371 | .pata_ide: |
||
372 | cmp [ecx+IDE_DATA.RegsBaseAddres], 0 |
||
373 | je .end_set_interrupts |
||
374 | |||
375 | push ecx |
||
376 | stdcall attach_int_handler, 14, IDE_irq_14_handler, 0 |
||
377 | DEBUGF 1, "K : Set IDE IRQ14 return code %x\n", eax |
||
378 | stdcall attach_int_handler, 15, IDE_irq_15_handler, 0 |
||
379 | DEBUGF 1, "K : Set IDE IRQ15 return code %x\n", eax |
||
380 | pop ecx |
||
381 | |||
382 | jmp .end_set_interrupts |
||
383 | ;-------------------------------------- |
||
384 | .sata_ide: |
||
385 | cmp ax, 0x0185 |
||
386 | je .sata_ide_1 |
||
387 | |||
388 | cmp ax, 0x018f |
||
389 | jne .end_set_interrupts |
||
390 | ;-------------------------------------- |
||
391 | .sata_ide_1: |
||
392 | ; Some weird controllers generate an interrupt even if IDE interrupts |
||
393 | ; are disabled and no IDE devices. For example, notebook ASUS K72F - |
||
394 | ; IDE controller 010185 generates false interrupt when we work with |
||
395 | ; the IDE controller 01018f. For this reason, the interrupt handler |
||
396 | ; does not need to be installed if both channel IDE controller |
||
397 | ; running in PIO mode. |
||
398 | cmp [ecx+IDE_DATA.RegsBaseAddres], 0 |
||
399 | je .end_set_interrupts |
||
400 | |||
401 | cmp [ecx+IDE_DATA.dma_hdd_channel_1], 0 |
||
402 | jne @f |
||
403 | |||
404 | cmp [ecx+IDE_DATA.dma_hdd_channel_2], 0 |
||
405 | je .end_set_interrupts |
||
406 | ;-------------------------------------- |
||
407 | @@: |
||
408 | mov ax, [ecx+IDE_DATA.Interrupt] |
||
409 | movzx eax, al |
||
410 | push ecx |
||
411 | stdcall attach_int_handler, eax, IDE_common_irq_handler, 0 |
||
412 | pop ecx |
||
413 | DEBUGF 1, "K : Set IDE IRQ%d return code %x\n", [ecx+IDE_DATA.Interrupt]:1, eax |
||
414 | ;-------------------------------------- |
||
4624 | mario79 | 415 | .end_set_interrupts: |
4838 | mario79 | 416 | popfd |
4700 | mario79 | 417 | ret |
4624 | mario79 | 418 | ;----------------------------------------------------------------------------- |
419 | ; END of initialisation IDE ATA code |
||
420 | ;----------------------------------------------------------------------------- |
||
4700 | mario79 | 421 | find_IDE_controller_done: |
422 | mov ecx, IDE_controller_1 |
||
423 | mov [IDE_controller_pointer], ecx |
||
424 | call Init_IDE_ATA_controller |
||
425 | mov ecx, IDE_controller_2 |
||
426 | mov [IDE_controller_pointer], ecx |
||
427 | call Init_IDE_ATA_controller |
||
428 | mov ecx, IDE_controller_3 |
||
429 | mov [IDE_controller_pointer], ecx |
||
430 | call Init_IDE_ATA_controller |
||
431 | ;----------------------------------------------------------------------------- |
||
432 | mov esi, boot_getcache |
||
433 | call boot_log |
||
434 | include 'getcache.inc' |
||
435 | ;----------------------------------------------------------------------------- |
||
436 | mov esi, boot_detectpart |
||
437 | call boot_log |
||
438 | include 'sear_par.inc' |
||
439 | ;----------------------------------------------------------------------------- |
||
4772 | mario79 | 440 | mov esi, boot_init_sys |
441 | call boot_log |
||
442 | call Parser_params |
||
443 | |||
444 | if ~ defined extended_primary_loader |
||
445 | ; ramdisk image should be loaded by extended primary loader if it exists |
||
446 | ; READ RAMDISK IMAGE FROM HD |
||
447 | include '../boot/rdload.inc' |
||
448 | end if |
||
449 | ;----------------------------------------------------------------------------- |
||
4720 | mario79 | 450 | mov ecx, IDE_controller_1 |
451 | mov [IDE_controller_pointer], ecx |
||
452 | call Init_IDE_ATA_controller_2 |
||
453 | mov ecx, IDE_controller_2 |
||
454 | mov [IDE_controller_pointer], ecx |
||
455 | call Init_IDE_ATA_controller_2 |
||
456 | mov ecx, IDE_controller_3 |
||
457 | mov [IDE_controller_pointer], ecx |
||
458 | call Init_IDE_ATA_controller_2 |
||
459 | ;----------------------------------------------------------------------------- |