|
|
|
PIC 、APIC(IOAPIC LAPIC) ' L" n+ i' b# q% P% C- X0 _
1. Overview
) f" d8 ~& u7 n, g- k! |1 d8 [/ x( f8 @
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中
/ h# Y$ Z) R9 [- T! b; f# E用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。
1 }9 a0 y# v+ c. S* Y3 Y. Y: H" q; @2 q+ ^, X
3 O$ z8 l8 C9 G1 r( c
2. PIC
% p# q4 p# j. e- }+ } M: P9 h- e9 N5 U0 V6 g1 ^
基于Intel 80x86的PC使用两片8259A级联的方式组成了可以管理15级中断向量的一个中断系统,下图是它的一个连接示意图。两片8259A,一片为Master,另一片为Slaver。其中Slaver的INT接到Master的IRQ2上。8259A有两种工作模式分别为编程和操作模式。BIOS初始化的时候会先通过IO port对8259A进行编程配置,在此之后8259A就可以响应来自外部设备的中断请求了。Master的IO address是0x20 0x21; Slaver的IO address是0xA0 0xA1。
. S, N" o7 v3 p0 V
7 w1 i3 ?" H0 @4 ~( w( w
0 m. @7 M& N. C) N+ l/ w; I
* g/ Z- w2 G- f9 r; ?
7 D) H* H# z, Y为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:3 p3 n& ~( i/ i2 s3 Q; r& H8 E' c
& T5 V; G! P* t7 U' t
MOV. |! ?: a5 G9 N# T% b, L
AL,00010001b# U; I2 L! E; c3 Y6 n
;级联,边沿触发,需要写ICW4
' D+ e: q1 s/ f7 WOUT
. l- v, k" u* C20H,AL
+ H. X+ A4 ]* ~;写ICW1; |5 j" A+ B* U: h
MOV
2 n) o; n i4 K( e2 n/ ^: EAL,01000000B ;中断类型号40H. q L* n2 k5 U
OUT
0 q$ r& ~+ A8 Q& u21H,AL
( r. }, j' i. i/ K4 Z" K4 B( M;写ICW2
: O+ F9 |- d' ?0 R8 kMOV
$ i. j9 i+ S. I8 [8 TAL,00000100B;主片的IR2引脚从片
, k/ E3 {- W8 Q" C/ G/ L; kOUT9 [& O- W8 N- P3 ^: \7 S! [6 D
21H,AL3 u/ A5 C) s* o: v4 m& J/ I2 d+ {
;写ICW3
4 x. U+ j) ^9 d. c b& J$ G# ~MOV
5 u' ^2 R5 \7 o% _6 G' Z1 iAL,00010001B;特殊完全嵌套,非缓冲,自动结束9 b4 B+ x9 E- t- ~' n) O* O
OUT
g9 n6 W, X7 [+ W9 A( E# H21H,AL A% U6 B( N1 s" M" P. l
;写ICW4
# s2 G* P# J: p: \* S) i4 T- y2 p( s
3. APIC
; T+ l% _/ l1 | p6 P4 v
1 Y' R; {( g& q4 v$ ~! ?Intel APIC由一组中断输入信号,一个24*64bit的Programmable Redirection Table(PRT),一组register和用于从APIC BUS(FSB/QPI)上传送APIC MSG的部件组成,当南桥的IO device通过IOAPIC的interrupt lines产生interrupt,IOAPIC将根据内部的PRT table格式化成中断请求信息,并将该信息发送给目标CPU的LAPIC,再由LAPIC通知CPU进行处理。下图是一个基于Intel APIC的连接示意图,如下图所示IOAPIC上有24个interrupt pin,6 [4 g! b+ `- C; m
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。8 q. S( G5 T& T
, Q. \, x/ k: U* U) U
/ C9 |! q, t- n) X: ]8 A& k
# w+ f/ X) p+ i; v
: v4 Q6 A# _! O* E3 W$ {
Programmable Redirection Table详细格式如下所示:: G9 v7 j- _7 F
5 V+ w& d; W* P4 I( g' n/ TBit Description:
0 b7 m+ Z1 ? r9 i7 Z8 U | [63:56] Destination Field—R/W.
+ g5 r1 v/ F7 J% Z) m* bIf the Destination Mode of this entry is Physical Mode (bit 11=0), bits
) K% X1 e: n4 n: k8 m | [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field
; [, |3 ]: L. j3 W1 k; ?$ E+ npotentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical0 Z5 W y8 J4 F: v
destination address.
& Z+ v0 o2 ]! g7 ?. {! m% FDestination Mode IOREDTBLx[11] Logical Destination Address
2 r1 l5 T4 v2 u5 u/ }8 J; `. L0, Physical Mode IOREDTBLx[59:56] = APIC ID' r$ _3 |5 f4 }7 P% t
1, Logical Mode IOREDTBLx[63:56] = Set of processors( w0 S6 l( @0 F8 f
| [55:17] Reserved.82093AA (IOAPIC)
( H8 Z4 o; q$ @* y! x( O1 H% y | [16] h* j8 W! M, h7 H8 Y% G
Interrupt Mask—R/W.
F0 M; R* {7 O6 f0 j- \' ZWhen this bit is 1, the interrupt signal is masked. Edge-sensitive
8 T0 a0 P9 u- F# w cinterrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
2 i' y' t% b7 N: w" J+ c+ w; @Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no7 [% T+ g& r2 D& t9 w: W u9 w% T
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
* J9 S2 e* @; w4 ^a local APIC has no effect on that interrupt. This behavior is identical to the case where the; q7 ]& S8 C+ T% y& j# q" R x0 d
device withdraws the interrupt before that interrupt is posted to the processor. It is software's; h* h' c& G9 A# U
responsibility to handle the case where the mask bit is set after the interrupt message has been/ v# a$ y2 E( G* Z( w' c
accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this
) L% k3 u( ~( w! g0 R& ^bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
^. b) R& Z, K3 d8 i9 Y' f2 Jresults in the delivery of the interrupt to the destination.1 k( V. I4 M/ d, j E
| [15] Trigger Mode—R/W.
1 a8 O. {: X& P; [; M% e8 GThe trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.9 i& j: @* G- e0 M7 _3 o
| [14] Remote IRR—RO.
+ c+ ^' Y+ ?1 X5 E( y4 S' SThis bit is used for level triggered interrupts. Its meaning is undefined for edge triggered interrupts. For level triggered interrupts, this bit is set to 1 when local APIC(s) accept the level interrupt sent by the IOAPIC. The Remote IRR bit is set to 0 when an EOI message with a matching interrupt vector is received from a local APIC.
2 S) c" M7 _! A9 J | [13] Interrupt Input Pin Polarity (INTPOL)—R/W.
7 ?0 `$ Y) B; ^" AThis bit specifies the polarity of the interrupt
7 V/ @6 u% N& u' _ r+ r- P0 msignal. 0=High active, 1=Low active." d) u3 c. ~! }! r0 z3 U
| [12]+ V0 z, M* L5 z9 k i2 l% w6 b* D
Delivery Status (DELIVS)—RO.
6 \4 \ T$ Z. K$ aThe Delivery Status bit contains the current status of the+ }/ d7 i( ]% {1 F2 O. w& P
delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit$ g" l( q/ Z- v0 O" ~9 j3 J
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
8 t7 f6 S% r; c! ]% k$ OPending (the interrupt has been injected but its delivery is temporarily held up due to the APIC2 `! V# d5 n% c0 f! S) |1 g$ Q
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
8 n1 o' P; w* O! m3 X# e | [11] Destination Mode (DESTMOD)—R/W.
. E8 Z& u9 p% u& X0 YThis field determines the interpretation of the1 T6 F2 X* x% ]
Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.1 [# S' P/ r& K& K* V0 G
Bits 56 through 59 of the Destination field specify the 4 bit APIC ID. When DESTMOD=1 (logical mode), destinations are identified by matching on the logical destination under the control of theDestination Format Register and Logical Destination Register in each Local APIC.
' z; B; J1 c( _2 c& \Destination Mode IOREDTBLx[11] Logical Destination Address 0, Physical Mode IOREDTBLx[59:56] = APIC ID1, Logical Mode IOREDTBLx[63:56] = Set of processorsE 82093AA (IOAPIC)( M3 O% m2 U( q8 g
| [10:8]Delivery Mode (DELMOD)—R/W.- A, j* E% O3 s/ k8 @
The Delivery Mode is a 3 bit field that specifies how the APICs listed in the destination field should act upon reception of this signal. Note that certain. u2 @2 ^& k& G" z
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
5 j, t- R# `8 u9 e8 gThese restrictions are indicated in the following table for each Delivery Mode.) Y4 c4 \7 ^8 D9 _4 [, p4 A+ m
Mode Description2 \$ U- s5 t- B, k2 z
0004 s' X. H5 C* j/ h( `% T3 m; R
Fixed Deliver the signal on the INTR signal of all processor cores listed in the
; \" E) I; G8 E" _destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.0 m0 b0 Z E3 y Z
0012 g2 `5 |' k. A, o! n. V; t% q
Lowest
6 y& t# Q" e: C9 wPriority Deliver the signal on the INTR signal of the processor core that is4 Q- `/ X- \% V' Z3 {2 \0 v& t
executing at the lowest priority among all the processors listed in the
6 D" \7 Z: b E& `' J8 a4 especified destination. Trigger Mode for "lowest priority". Delivery Mode% L. R1 D. r: D* F
can be edge or level.8 a4 E. X8 F8 h& L% r
0108 Q/ J2 ]0 t* I, v- ]5 u( M
SMI System Management Interrupt. A delivery mode equal to SMI requires an
' A! U- `8 H0 Y* J6 |$ o; \. iedge trigger mode. The vector information is ignored but must be
! o1 ] \5 K* K7 {. uprogrammed to all zeroes for future compatibility.$ a: p" t7 j4 d3 H
011
4 Q% @2 X( ^, w4 @Reserved- L; d0 A F! Y! I9 z
100
9 p8 L2 d8 b- o7 Y$ `, c6 ]NMI Deliver the signal on the NMI signal of all processor cores listed in the
T+ M; u1 y+ r$ C0 \destination. Vector information is ignored. NMI is treated as an edge/ {; Q/ `1 G# ?( F) F
triggered interrupt, even if it is programmed as a level triggered interrupt.
$ X* X( x- e! }For proper operation, this redirection table entry must be programmed to
+ {/ O) v3 n; c0 S+ i4 A. o8 X7 o“edge” triggered interrupt.
+ ^& h- G+ P9 ?/ c* N101
& s7 u9 R% h& M; X5 m! n eINIT Deliver the signal to all processor cores listed in the destination by' n3 F9 Z! A( o- ^; n' J6 u
asserting the INIT signal. All addressed local APICs will assume their; K- b7 j, l8 p2 R6 w) d& s
INIT state. INIT is always treated as an edge triggered interrupt, even if
: T. E/ v6 ~# f: f9 S4 h% hprogrammed otherwise. For proper operation, this redirection table entry
6 ^* m) S6 q* umust be programmed to “edge” triggered interrupt.: p8 @+ Z7 k2 l) T& h, D# k( J" D7 {
110% e! ?; Y5 D: a; S F' m' \6 a
Reserved
9 [3 {/ m7 x" I4 u1 y111
3 l& x1 d# H, y: w: ~ExtINT Deliver the signal to the INTR signal of all processor cores listed in the
" ^( I3 x- E( B7 v6 u( Edestination as an interrupt that originated in an externally connected
) d9 e5 }7 M5 H4 j9 Y& b(8259A-compatible) interrupt controller. The INTA cycle that corresponds7 Y8 Y, z1 q4 b1 o" R
to this ExtINT delivery is routed to the external controller that is expected: o# W) s1 h- B+ b5 W9 ^7 m# _# J! ~
to supply the vector. A Delivery Mode of "ExtINT"
, T* R2 b4 c( o/ z8 `" i) Rrequires an edge" ~( P/ ^5 P3 R) o
trigger mode.
' p, z4 x9 P) o3 ? | [7:0] Interrupt Vector (INTVEC)—R/W:
4 ^. {. t; q# j. }9 M% zThe vector field is an 8 bit field containing the interrupt
9 w* { @, E! Z* a3 vvector for this interrupt. Vector values range from 10h to FEh.
. n) J7 |) p2 M3 @. c( a9 G. [4 p | " N4 P3 O% J3 s5 C% {
REFF:
* r4 z( N; y) \9 T+ B, s s6 ?! s. O- M, G" w0 b
1.
) n3 B# \* o3 V《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》$ t, z1 x0 H9 P
2.
" j1 |! I+ Q0 C& t- Y: [% Z《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》0 O6 C7 ]7 `- m+ F( {* f: ~
3. O+ n$ ]( D# i8 x
《Undocumented PC》
0 N% w' Q3 d) {; u4.6 a! N M/ }! D1 G' A
$ y% M2 w2 p4 H1 |! a$ I
8259A初始化编程
* S, n2 J7 U% x) f
' R+ D" i8 _( K F; J* Q3 k) hThat’s all!
4 ^6 s7 s, M. G7 D0 v
3 l! V9 v. r) ~7 aPeter& ]4 o( r8 }: L" ?3 U- p
' D7 b# @3 Y) Q# t; ~2010/10/07
" O4 d4 j8 j; M3 O. k L
' B3 N( `, m3 T% \+ W& G[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|