Subversion Repositories Kolibri OS

Rev

Rev 7136 | Rev 8111 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7136 Rev 7733
Line 1... Line 1...
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2020. All rights reserved. ;;
4
;; Distributed under terms of the GNU General Public License    ;;
4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 7... Line 7...
7
 
7
 
Line 8... Line -...
8
$Revision: 7136 $
-
 
9
 
-
 
10
 
8
$Revision: 7733 $
11
iglobal
-
 
Line 12... Line 9...
12
IRQ_COUNT    dd 24
9
 
13
endg
10
MAX_IOAPICS = 2
-
 
11
 
14
 
12
uglobal
-
 
13
IRQ_COUNT    rd  MAX_IOAPICS
-
 
14
irq_mode     rd  1              ; PIC/(IO)APIC
-
 
15
IOAPIC_base  rd  MAX_IOAPICS
15
uglobal
16
ioapic_gsi_base rd MAX_IOAPICS  ; zero-based, i.e. not vector
16
irq_mode     rd  1
17
ioapic_cnt   dd  ?              ; from MADT aka APIC table
Line 17... Line 18...
17
IOAPIC_base  rd  1
18
ioapic_cur   dd  ?
18
LAPIC_BASE   rd  1
19
LAPIC_BASE   rd  1
Line 43... Line 44...
43
IOAPIC_ARB      = 0x2
44
IOAPIC_ARB      = 0x2
44
IOAPIC_REDTBL   = 0x10
45
IOAPIC_REDTBL   = 0x10
Line 45... Line 46...
45
 
46
 
46
align 4
47
align 4
-
 
48
APIC_init:
47
APIC_init:
49
        push    ebx
Line 48... Line 50...
48
        mov     [irq_mode], IRQ_PIC
50
        mov     [irq_mode], IRQ_PIC
49
 
51
 
Line 58... Line 60...
58
        jz      .no_apic
60
        jz      .no_apic
Line 59... Line 61...
59
 
61
 
60
        mov     [acpi_dev_data], eax
62
        mov     [acpi_dev_data], eax
Line 61... Line -...
61
        mov     [acpi_dev_size], ebx
-
 
62
 
-
 
63
        call    IRQ_mask_all
63
        mov     [acpi_dev_size], ebx
-
 
64
 
-
 
65
; IOAPIC init
64
 
66
        xor     ebx, ebx
65
; IOAPIC init
67
@@:
-
 
68
        stdcall map_io_mem, [acpi_ioapic_base+ebx*4], 0x20, PG_GLOBAL+PG_NOCACHE+PG_SWR
-
 
69
        mov     [IOAPIC_base+ebx*4], eax
-
 
70
        inc     ebx
Line -... Line 71...
-
 
71
        cmp     ebx, [ioapic_cnt]
-
 
72
        jnz     @b
-
 
73
 
-
 
74
        call    IRQ_mask_all
66
        stdcall map_io_mem, [acpi_ioapic_base], 0x20, PG_GLOBAL+PG_NOCACHE+PG_SWR
75
        mov     [ioapic_cur], 0
67
        mov     [IOAPIC_base], eax
76
.next_ioapic:
68
 
77
        mov     edx, [ioapic_cur]
69
        mov     eax, IOAPIC_VER
78
        mov     eax, IOAPIC_VER
70
        call    IOAPIC_read
79
        call    IOAPIC_read
-
 
80
        shr     eax, 16
71
        shr     eax, 16
81
        inc     al
-
 
82
        movzx   eax, al
-
 
83
        mov     ecx, [ioapic_gsi_base+edx*4]
-
 
84
        cmp     ecx, IRQ_RESERVED
72
        inc     al
85
        jae     .lapic_init
73
        movzx   eax, al
-
 
74
        cmp     al, IRQ_RESERVED
86
        add     ecx, eax
75
        jbe     @f
87
        sub     ecx, IRQ_RESERVED
76
 
88
        jbe     @f
Line 77... Line 89...
77
        mov     al, IRQ_RESERVED
89
        sub     eax, ecx
78
@@:
90
@@:
79
        mov     [IRQ_COUNT], eax
91
        mov     [IRQ_COUNT+edx*4], eax
80
 
92
 
81
        ; Reroute IOAPIC & mask all interrupts
93
        ; Reroute IOAPIC & mask all interrupts
82
        xor     ecx, ecx
94
        xor     ecx, ecx
83
        mov     eax, IOAPIC_REDTBL
95
        mov     eax, IOAPIC_REDTBL
84
@@:
96
.next_irq:
85
        mov     ebx, eax
97
        mov     ebx, eax
-
 
98
        call    IOAPIC_read
86
        call    IOAPIC_read
99
        mov     ah, 0x08; Delivery Mode: Fixed, Destination Mode: Logical
-
 
100
        mov     al, cl
-
 
101
        add     al, 0x20; vector
87
        mov     ah, 0x08; Delivery Mode: Fixed, Destination Mode: Logical
102
        add     eax, [ioapic_gsi_base+edx*4]
88
        mov     al, cl
103
        or      eax, 0x1a000; Mask Interrupt, level-triggered active-low
89
        add     al, 0x20; vector
-
 
90
        or      eax, 0x10000; Mask Interrupt
104
        cmp     [ioapic_cur], 0
91
        cmp     ecx, 16
105
        jnz     @f
92
        jb      .set
106
        cmp     ecx, 16
93
 
107
        jae     @f
94
        or      eax, 0xa000;<<< level-triggered active-low for IRQ16+
108
        and     eax, NOT 0xa000 ; edge-triggered active-high for IRQ0-15
95
.set:
109
@@:
96
        xchg    eax, ebx
110
        xchg    eax, ebx
97
        call    IOAPIC_write
111
        call    IOAPIC_write
98
        inc     eax
112
        inc     eax
99
        mov     ebx, eax
113
        mov     ebx, eax
100
        call    IOAPIC_read
114
        call    IOAPIC_read
101
        or      eax, 0xff000000; Destination Field
115
        or      eax, 0xff000000; Destination Field
102
        xchg    eax, ebx
116
        xchg    eax, ebx
-
 
117
        call    IOAPIC_write
-
 
118
        inc     eax
-
 
119
        inc     ecx
103
        call    IOAPIC_write
120
        cmp     ecx, [IRQ_COUNT+edx*4]
-
 
121
        jb      .next_irq
-
 
122
 
Line -... Line 123...
-
 
123
        inc     [ioapic_cur]
104
        inc     eax
124
        inc     edx
Line 105... Line 125...
105
        inc     ecx
125
        cmp     edx, [ioapic_cnt]
Line 106... Line 126...
106
        cmp     ecx, [IRQ_COUNT]
126
        jnz     .next_ioapic
Line 115... Line 135...
115
        mov     al, 1
135
        mov     al, 1
116
        out     0x23, al
136
        out     0x23, al
Line 117... Line 137...
117
 
137
 
118
        call    pci_irq_fixup
138
        call    pci_irq_fixup
119
.no_apic:
-
 
-
 
139
.no_apic:
120
 
140
        pop     ebx
Line 121... Line 141...
121
        ret
141
        ret
122
 
142
 
123
;===========================================================
143
;===========================================================
Line 208... Line 228...
208
align 4
228
align 4
209
IOAPIC_read:
229
IOAPIC_read:
210
; in : EAX - IOAPIC register
230
; in : EAX - IOAPIC register
211
; out: EAX - readed value
231
; out: EAX - readed value
212
        push    esi
232
        push    esi
-
 
233
        mov     esi, [ioapic_cur]
213
        mov     esi, [IOAPIC_base]
234
        mov     esi, [IOAPIC_base+esi*4]
214
        mov     [esi], eax
235
        mov     [esi], eax
215
        mov     eax, [esi + 0x10]
236
        mov     eax, [esi + 0x10]
216
        pop     esi
237
        pop     esi
217
        ret
238
        ret
Line 220... Line 241...
220
IOAPIC_write:
241
IOAPIC_write:
221
; in :  EAX - IOAPIC register
242
; in :  EAX - IOAPIC register
222
;       EBX - value
243
;       EBX - value
223
; out:  none
244
; out:  none
224
        push    esi
245
        push    esi
-
 
246
        mov     esi, [ioapic_cur]
225
        mov     esi, [IOAPIC_base]
247
        mov     esi, [IOAPIC_base+esi*4]
226
        mov     [esi], eax
248
        mov     [esi], eax
227
        mov     [esi + 0x10], ebx
249
        mov     [esi + 0x10], ebx
228
        pop     esi
250
        pop     esi
229
        ret
251
        ret
230
;===========================================================
252
;===========================================================
231
; Remap all IRQ to 0x20+ Vectors
253
; Remap all IRQ to 0x20+ Vectors
232
; IRQ0 to vector 0x20, IRQ1 to vector 0x21....
254
; IRQ0 to vector 0x20, IRQ1 to vector 0x21....
233
align 4
255
align 4
234
PIC_init:
256
PIC_init:
-
 
257
        mov     [IRQ_COUNT], 16
235
        cli
258
        cli
236
        mov     al, 0x11        ;  icw4, edge triggered
259
        mov     al, 0x11        ;  icw4, edge triggered
237
        out     0x20, al
260
        out     0x20, al
238
        out     0xA0, al
261
        out     0xA0, al
Line 250... Line 273...
250
        mov     al, 0x01        ;  8086 mode
273
        mov     al, 0x01        ;  8086 mode
251
        out     0x21, al
274
        out     0x21, al
252
        out     0xA1, al
275
        out     0xA1, al
Line 253... Line 276...
253
 
276
 
254
        call    IRQ_mask_all
-
 
255
        ; mov   dword[irq_type_to_set], IRQ_TYPE_PIC
277
        call    IRQ_mask_all
Line 256... Line 278...
256
        ret
278
        ret
257
 
279
 
258
; -----------------------------------------
280
; -----------------------------------------
Line 307... Line 329...
307
        out     0x21, al
329
        out     0x21, al
308
        out     0xA1, al
330
        out     0xA1, al
309
        mov     ecx, 0x1000
331
        mov     ecx, 0x1000
310
        ret
332
        ret
311
.APIC:
333
.APIC:
-
 
334
        cmp     [IOAPIC_base], 0
-
 
335
        jz      .done
-
 
336
        mov     [ioapic_cur], 0
-
 
337
.next_ioapic:
-
 
338
        mov     edx, [ioapic_cur]
312
        mov     ecx, [IRQ_COUNT]
339
        mov     ecx, [IRQ_COUNT+edx*4]
313
        mov     eax, 0x10
340
        mov     eax, 0x10
314
@@:
341
@@:
315
        mov     ebx, eax
342
        mov     ebx, eax
316
        call    IOAPIC_read
343
        call    IOAPIC_read
317
        or      eax, 0x10000; bit 16
344
        or      eax, 0x10000; bit 16
318
        xchg    eax, ebx
345
        xchg    eax, ebx
319
        call    IOAPIC_write
346
        call    IOAPIC_write
320
        inc     eax
347
        inc     eax
321
        inc     eax
348
        inc     eax
322
        loop    @b
349
        loop    @b
-
 
350
 
-
 
351
        inc     [ioapic_cur]
-
 
352
        inc     edx
-
 
353
        cmp     edx, [ioapic_cnt]
-
 
354
        jnz     .next_ioapic
-
 
355
.done:
323
        ret
356
        ret
Line 324... Line 357...
324
 
357
 
325
; -----------------------------------------
358
; -----------------------------------------
326
; End Of Interrupt
359
; End Of Interrupt
Line 361... Line 394...
361
        in      al, dx
394
        in      al, dx
362
        btr     eax, ebx
395
        btr     eax, ebx
363
        out     dx, al
396
        out     dx, al
364
        ret
397
        ret
365
.APIC:
398
.APIC:
-
 
399
        push    [ioapic_cur]
-
 
400
        xor     eax, eax
-
 
401
.next_ioapic:
-
 
402
        mov     ecx, [ioapic_gsi_base+eax*4]
-
 
403
        add     ecx, [IRQ_COUNT+eax*4]
-
 
404
        cmp     ebx, ecx
-
 
405
        jb      .found
-
 
406
        inc     eax
-
 
407
        cmp     eax, [ioapic_cnt]
-
 
408
        jnz     .next_ioapic
-
 
409
        jmp     .done
-
 
410
.found:
-
 
411
        mov     [ioapic_cur], eax
-
 
412
        sub     ebx, [ioapic_gsi_base+eax*4]
366
        shl     ebx, 1
413
        shl     ebx, 1
367
        add     ebx, 0x10
414
        add     ebx, 0x10
368
        mov     eax, ebx
415
        mov     eax, ebx
369
        call    IOAPIC_read
416
        call    IOAPIC_read
370
        and     eax, 0xfffeffff; bit 16
417
        and     eax, 0xfffeffff; bit 16
371
        xchg    eax, ebx
418
        xchg    eax, ebx
372
        call    IOAPIC_write
419
        call    IOAPIC_write
-
 
420
.done:
-
 
421
        pop     [ioapic_cur]
373
        ret
422
        ret
374
endp
423
endp
Line 375... Line 424...
375
 
424
 
376
proc disable_irq stdcall, irq_line:dword
425
proc disable_irq stdcall, irq_line:dword
Line 388... Line 437...
388
        in      al, dx
437
        in      al, dx
389
        bts     eax, ebx
438
        bts     eax, ebx
390
        out     dx, al
439
        out     dx, al
391
        ret
440
        ret
392
.APIC:
441
.APIC:
-
 
442
        push    [ioapic_cur]
-
 
443
        xor     eax, eax
-
 
444
.next_ioapic:
-
 
445
        mov     ecx, [ioapic_gsi_base+eax*4]
-
 
446
        add     ecx, [IRQ_COUNT+eax*4]
-
 
447
        cmp     ebx, ecx
-
 
448
        jae     .found
-
 
449
        inc     eax
-
 
450
        cmp     eax, [ioapic_cnt]
-
 
451
        jnz     .next_ioapic
-
 
452
        jmp     .done
-
 
453
.found:
-
 
454
        mov     [ioapic_cur], eax
-
 
455
        sub     ebx, [ioapic_gsi_base+eax*4]
393
        shl     ebx, 1
456
        shl     ebx, 1
394
        add     ebx, 0x10
457
        add     ebx, 0x10
395
        mov     eax, ebx
458
        mov     eax, ebx
396
        call    IOAPIC_read
459
        call    IOAPIC_read
397
        or      eax, 0x10000; bit 16
460
        or      eax, 0x10000; bit 16
398
        xchg    eax, ebx
461
        xchg    eax, ebx
399
        call    IOAPIC_write
462
        call    IOAPIC_write
-
 
463
.done:
-
 
464
        pop     [ioapic_cur]
400
        ret
465
        ret
401
endp
466
endp
Line 402... Line 467...
402
 
467
 
403
align 4
468
align 4