Rev 4711 | Rev 4772 | 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 | ;-------------------------------------- |
||
143 | endg |
||
4624 | mario79 | 144 | ;----------------------------------------------------------------------------- |
145 | ; START of initialisation IDE ATA code |
||
146 | ;----------------------------------------------------------------------------- |
||
4700 | mario79 | 147 | Init_IDE_ATA_controller: |
148 | cmp [ecx+IDE_DATA.ProgrammingInterface], 0 |
||
4720 | mario79 | 149 | jne @f |
4624 | mario79 | 150 | |
4720 | mario79 | 151 | ret |
152 | ;-------------------------------------- |
||
153 | @@: |
||
4624 | mario79 | 154 | mov esi, boot_disabling_ide |
155 | call boot_log |
||
156 | ;-------------------------------------- |
||
157 | ; Disable IDE interrupts, because the search |
||
158 | ; for IDE partitions is in the PIO mode. |
||
159 | ;-------------------------------------- |
||
160 | .disable_IDE_interrupt: |
||
161 | ; Disable interrupts in IDE controller for PIO |
||
162 | mov al, 2 |
||
4700 | mario79 | 163 | mov dx, [ecx+IDE_DATA.BAR1_val] ;0x3F4 |
4624 | mario79 | 164 | add dx, 2 ;0x3F6 |
165 | out dx, al |
||
4700 | mario79 | 166 | mov dx, [ecx+IDE_DATA.BAR3_val] ;0x374 |
4624 | mario79 | 167 | add dx, 2 ;0x376 |
168 | out dx, al |
||
4700 | mario79 | 169 | ;----------------------------------------------------------------------------- |
170 | ; set current ata bases |
||
4624 | mario79 | 171 | @@: |
4700 | mario79 | 172 | mov ax, [ecx+IDE_DATA.BAR0_val] |
173 | mov [StandardATABases], ax |
||
174 | mov ax, [ecx+IDE_DATA.BAR2_val] |
||
175 | mov [StandardATABases+2], ax |
||
176 | |||
4624 | mario79 | 177 | mov esi, boot_detecthdcd |
178 | call boot_log |
||
4720 | mario79 | 179 | ;-------------------------------------- |
4625 | mario79 | 180 | include 'dev_hdcd.inc' |
4720 | mario79 | 181 | ;-------------------------------------- |
182 | ret |
||
4624 | mario79 | 183 | ;----------------------------------------------------------------------------- |
4720 | mario79 | 184 | Init_IDE_ATA_controller_2: |
185 | cmp [ecx+IDE_DATA.ProgrammingInterface], 0 |
||
186 | jne @f |
||
187 | |||
188 | ret |
||
189 | ;-------------------------------------- |
||
190 | @@: |
||
4700 | mario79 | 191 | mov dx, [ecx+IDE_DATA.RegsBaseAddres] |
4624 | mario79 | 192 | ; test whether it is our interrupt? |
193 | add dx, 2 |
||
194 | in al, dx |
||
195 | test al, 100b |
||
196 | jz @f |
||
197 | ; clear Bus Master IDE Status register |
||
198 | ; clear Interrupt bit |
||
199 | out dx, al |
||
4700 | mario79 | 200 | ;-------------------------------------- |
4624 | mario79 | 201 | @@: |
202 | add dx, 8 |
||
203 | ; test whether it is our interrupt? |
||
204 | in al, dx |
||
205 | test al, 100b |
||
206 | jz @f |
||
207 | ; clear Bus Master IDE Status register |
||
208 | ; clear Interrupt bit |
||
209 | out dx, al |
||
4700 | mario79 | 210 | ;-------------------------------------- |
4624 | mario79 | 211 | @@: |
212 | ; read status register and remove the interrupt request |
||
4700 | mario79 | 213 | mov dx, [ecx+IDE_DATA.BAR0_val] ;0x1F0 |
4624 | mario79 | 214 | add dx, 0x7 ;0x1F7 |
215 | in al, dx |
||
4700 | mario79 | 216 | mov dx, [ecx+IDE_DATA.BAR2_val] ;0x170 |
4624 | mario79 | 217 | add dx, 0x7 ;0x177 |
218 | in al, dx |
||
219 | ;----------------------------------------------------------------------------- |
||
4720 | mario79 | 220 | ; push eax edx |
221 | ; mov dx, [ecx+IDE_DATA.RegsBaseAddres] |
||
222 | ; xor eax, eax |
||
223 | ; add dx, 2 |
||
224 | ; in al, dx |
||
4711 | mario79 | 225 | ; DEBUGF 1, "K : Primary Bus Master IDE Status Register %x\n", eax |
4624 | mario79 | 226 | |
4720 | mario79 | 227 | ; add dx, 8 |
228 | ; in al, dx |
||
4711 | mario79 | 229 | ; DEBUGF 1, "K : Secondary Bus Master IDE Status Register %x\n", eax |
4720 | mario79 | 230 | ; pop edx eax |
4624 | mario79 | 231 | |
4720 | mario79 | 232 | ; cmp [ecx+IDE_DATA.RegsBaseAddres], 0 |
233 | ; setnz [ecx+IDE_DATA.dma_hdd] |
||
4624 | mario79 | 234 | ;----------------------------------------------------------------------------- |
235 | ; set interrupts for IDE Controller |
||
236 | ;----------------------------------------------------------------------------- |
||
237 | mov esi, boot_set_int_IDE |
||
238 | call boot_log |
||
4720 | mario79 | 239 | .set_interrupts_for_IDE_controllers: |
4700 | mario79 | 240 | mov eax, [ecx+IDE_DATA.ProgrammingInterface] |
4624 | mario79 | 241 | cmp ax, 0x0180 |
242 | je .pata_ide |
||
243 | |||
244 | cmp ax, 0x018a |
||
245 | jne .sata_ide |
||
246 | ;-------------------------------------- |
||
247 | .pata_ide: |
||
4700 | mario79 | 248 | cmp [ecx+IDE_DATA.RegsBaseAddres], 0 |
4624 | mario79 | 249 | je .end_set_interrupts |
250 | |||
4700 | mario79 | 251 | push ecx |
4624 | mario79 | 252 | stdcall attach_int_handler, 14, IDE_irq_14_handler, 0 |
253 | DEBUGF 1, "K : Set IDE IRQ14 return code %x\n", eax |
||
254 | stdcall attach_int_handler, 15, IDE_irq_15_handler, 0 |
||
255 | DEBUGF 1, "K : Set IDE IRQ15 return code %x\n", eax |
||
4700 | mario79 | 256 | pop ecx |
257 | |||
4624 | mario79 | 258 | jmp .enable_IDE_interrupt |
259 | ;-------------------------------------- |
||
260 | .sata_ide: |
||
261 | cmp ax, 0x0185 |
||
262 | je .sata_ide_1 |
||
263 | |||
264 | cmp ax, 0x018f |
||
265 | jne .end_set_interrupts |
||
266 | ;-------------------------------------- |
||
267 | .sata_ide_1: |
||
4700 | mario79 | 268 | cmp [ecx+IDE_DATA.RegsBaseAddres], 0 |
4624 | mario79 | 269 | je .end_set_interrupts |
270 | |||
4700 | mario79 | 271 | mov ax, [ecx+IDE_DATA.Interrupt] |
4624 | mario79 | 272 | movzx eax, al |
4700 | mario79 | 273 | push ecx |
4624 | mario79 | 274 | stdcall attach_int_handler, eax, IDE_common_irq_handler, 0 |
4700 | mario79 | 275 | pop ecx |
276 | DEBUGF 1, "K : Set IDE IRQ%d return code %x\n", [ecx+IDE_DATA.Interrupt]:1, eax |
||
4624 | mario79 | 277 | ;-------------------------------------- |
278 | .enable_IDE_interrupt: |
||
279 | mov esi, boot_enabling_ide |
||
280 | call boot_log |
||
281 | ; Enable interrupts in IDE controller for DMA |
||
4700 | mario79 | 282 | xor ebx, ebx |
283 | cmp ecx, IDE_controller_2 |
||
284 | jne @f |
||
285 | |||
286 | add ebx, 5 |
||
287 | jmp .check_DRIVE_DATA |
||
288 | ;-------------------------------------- |
||
289 | @@: |
||
290 | cmp ecx, IDE_controller_3 |
||
291 | jne .check_DRIVE_DATA |
||
292 | |||
293 | add ebx, 10 |
||
294 | ;-------------------------------------- |
||
295 | .check_DRIVE_DATA: |
||
4624 | mario79 | 296 | mov al, 0 |
4700 | mario79 | 297 | mov ah, [ebx+DRIVE_DATA+1] |
4624 | mario79 | 298 | test ah, 10100000b |
299 | jz @f |
||
300 | |||
301 | DEBUGF 1, "K : IDE CH1 PIO, because ATAPI drive present\n" |
||
4720 | mario79 | 302 | mov [ecx+IDE_DATA.dma_hdd_channel_1], byte 0 |
303 | |||
4624 | mario79 | 304 | jmp .ch2_check |
4700 | mario79 | 305 | ;-------------------------------------- |
4624 | mario79 | 306 | @@: |
4700 | mario79 | 307 | mov dx, [ecx+IDE_DATA.BAR1_val] ;0x3F4 |
4624 | mario79 | 308 | add dx, 2 ;0x3F6 |
309 | out dx, al |
||
310 | DEBUGF 1, "K : IDE CH1 DMA enabled\n" |
||
4720 | mario79 | 311 | mov [ecx+IDE_DATA.dma_hdd_channel_1], byte 1 |
4700 | mario79 | 312 | ;-------------------------------------- |
4624 | mario79 | 313 | .ch2_check: |
314 | test ah, 1010b |
||
315 | jz @f |
||
316 | |||
317 | DEBUGF 1, "K : IDE CH2 PIO, because ATAPI drive present\n" |
||
4720 | mario79 | 318 | mov [ecx+IDE_DATA.dma_hdd_channel_2], byte 0 |
319 | |||
4624 | mario79 | 320 | jmp .end_set_interrupts |
4700 | mario79 | 321 | ;-------------------------------------- |
4624 | mario79 | 322 | @@: |
4700 | mario79 | 323 | mov dx, [ecx+IDE_DATA.BAR3_val] ;0x374 |
4624 | mario79 | 324 | add dx, 2 ;0x376 |
325 | out dx, al |
||
326 | DEBUGF 1, "K : IDE CH2 DMA enabled\n" |
||
4720 | mario79 | 327 | mov [ecx+IDE_DATA.dma_hdd_channel_2], byte 1 |
4624 | mario79 | 328 | ;-------------------------------------- |
329 | .end_set_interrupts: |
||
4700 | mario79 | 330 | ret |
4624 | mario79 | 331 | ;----------------------------------------------------------------------------- |
332 | ; END of initialisation IDE ATA code |
||
333 | ;----------------------------------------------------------------------------- |
||
4700 | mario79 | 334 | find_IDE_controller_done: |
335 | mov ecx, IDE_controller_1 |
||
336 | mov [IDE_controller_pointer], ecx |
||
337 | call Init_IDE_ATA_controller |
||
338 | mov ecx, IDE_controller_2 |
||
339 | mov [IDE_controller_pointer], ecx |
||
340 | call Init_IDE_ATA_controller |
||
341 | mov ecx, IDE_controller_3 |
||
342 | mov [IDE_controller_pointer], ecx |
||
343 | call Init_IDE_ATA_controller |
||
344 | ;----------------------------------------------------------------------------- |
||
345 | mov esi, boot_getcache |
||
346 | call boot_log |
||
347 | include 'getcache.inc' |
||
348 | ;----------------------------------------------------------------------------- |
||
349 | mov esi, boot_detectpart |
||
350 | call boot_log |
||
351 | include 'sear_par.inc' |
||
352 | ;----------------------------------------------------------------------------- |
||
4720 | mario79 | 353 | mov ecx, IDE_controller_1 |
354 | mov [IDE_controller_pointer], ecx |
||
355 | call Init_IDE_ATA_controller_2 |
||
356 | mov ecx, IDE_controller_2 |
||
357 | mov [IDE_controller_pointer], ecx |
||
358 | call Init_IDE_ATA_controller_2 |
||
359 | mov ecx, IDE_controller_3 |
||
360 | mov [IDE_controller_pointer], ecx |
||
361 | call Init_IDE_ATA_controller_2 |
||
362 | ;----------------------------------------------------------------------------- |