Subversion Repositories Kolibri OS

Rev

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