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