|
|
|
PIC 、APIC(IOAPIC LAPIC) ) \" z; M0 _. m
1. Overview
: z$ M9 Q, P. F! K; C5 z! g! E8 L' Y4 I6 g' c. C: l0 n
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中
7 ^2 z v# s( s用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。
- S' F5 q, q6 A* U" y4 q9 P: M2 V. D' r; M9 ]
& f0 H3 D7 j+ @2. PIC' Q# e+ J, y k& k
: R, ?' S D' q: m. f基于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。
G+ X" a/ D8 p, s2 t) z7 p; P/ I" R$ n+ O8 e% ]% v
% s' R( k/ y' f3 v% P, s+ S* X8 A; x4 {- k8 Y! t3 Q
u& }5 v2 ]. S8 z1 k& s' F: Z
为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:
8 z0 X9 _- k# c# |# d) E) p0 e* d4 o$ W: [$ S
MOV- }& W3 O8 U% {+ s& K# P
AL,00010001b3 S) Z6 k4 J% V2 V. S( B) B1 J
;级联,边沿触发,需要写ICW46 p: b4 T& y% j
OUT" Y0 E/ R; ?" n: Y+ G2 ]/ O
20H,AL3 z( m' Y& V( r2 H: q
;写ICW1
8 T; H: W/ A( u6 MMOV
. p2 q9 A. X0 d2 J" k+ ~# S+ ]) Y1 qAL,01000000B ;中断类型号40H
p7 i$ _3 L6 _5 _$ J- d1 HOUT, C: N0 R" s! i5 X" s4 f, R* S
21H,AL% x, R2 F+ V( z; Q& Z6 @5 Z
;写ICW2
* _) J/ R& V% o; J( eMOV
0 z! k6 b5 k2 e- i- jAL,00000100B;主片的IR2引脚从片
- c5 n' U# @( E- K# x1 ~OUT- h* m# N8 J& L' F R! E
21H,AL$ Z* t0 W1 L3 F; @& Q7 ?' n, ~
;写ICW3 n1 J& l4 u+ \1 O
MOV0 `7 v' O# x# o7 A! y8 y
AL,00010001B;特殊完全嵌套,非缓冲,自动结束
9 J7 g( G) h; i$ qOUT
1 Z8 c9 n. \7 T- b8 o. `21H,AL
* a7 ^5 N3 ^0 y6 _( e( d1 u;写ICW46 m' H- ^6 y/ x3 V3 f6 V0 j
" L- [, @: R5 \. W3. APIC2 O% K, Y9 V" ~
/ ^% \9 H' N- |$ G# {
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,5 X9 M, a1 `2 a) x4 ]2 |0 w
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。( L- D6 M; M$ v" N3 ]
$ f/ w2 n" y0 ^% N2 g
- c! E7 R8 R, t! S: k
* c- b/ R+ R6 F# d6 ~( {/ r
$ J7 d1 a, z/ G) t4 Z# k( EProgrammable Redirection Table详细格式如下所示:' s) y8 B" T' P% P
+ ~* F8 v' \/ m/ q5 g
Bit Description:
4 D! E+ e; A) Z3 B7 ]6 r | [63:56] Destination Field—R/W.7 k) Y- c e1 q! r! x
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits
) x' Z3 s/ p! r5 y5 l | [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field" J. S' x0 E& k, \
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
4 d0 h }1 W9 N8 b& p- Tdestination address.
5 r' A' y6 U# G; W% @1 e% H1 F2 rDestination Mode IOREDTBLx[11] Logical Destination Address8 \2 ^5 p6 T: a" b! D5 g# V
0, Physical Mode IOREDTBLx[59:56] = APIC ID
; G& \4 Q% T2 |8 @6 l1, Logical Mode IOREDTBLx[63:56] = Set of processors
: \4 A, ~" G. l( @ | [55:17] Reserved.82093AA (IOAPIC) 0 |# F' ^3 K4 `2 [+ G
| [16]- F! d6 j! G: k# g8 x& I( z" K
Interrupt Mask—R/W.
, ~6 Y" Y' N6 ~! h9 z9 e; UWhen this bit is 1, the interrupt signal is masked. Edge-sensitive
; T! A+ R+ u) Y# p: cinterrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).$ m( G/ e) B w/ h* N
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no" n9 @( X! C: s6 P
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
" z+ ]1 ?" }; @ k$ y8 M) La local APIC has no effect on that interrupt. This behavior is identical to the case where the+ A( _6 o# f8 v; d8 J/ J0 {- P6 m
device withdraws the interrupt before that interrupt is posted to the processor. It is software's& v* `5 E; P0 X) R( ~" j Z ]
responsibility to handle the case where the mask bit is set after the interrupt message has been
. V. g& M1 r8 A2 z) y/ Iaccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this0 l: P. O6 C- ?# g+ {
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
0 Y% @& m Y; ^' xresults in the delivery of the interrupt to the destination.4 i0 L0 f1 w. ?* F* [1 ]
| [15] Trigger Mode—R/W.
- z6 Y* |: `$ q) N: dThe trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.3 S$ n. ?& E8 Z5 @" N
| [14] Remote IRR—RO.
! l( T. r9 A5 @, Z" a6 t- PThis 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.3 E! ?) w' u7 y9 h; P+ d
| [13] Interrupt Input Pin Polarity (INTPOL)—R/W.
! r7 U, ^, {0 d" B, M, }This bit specifies the polarity of the interrupt
* b- s, e0 M* D7 O+ i& `2 \/ k- @signal. 0=High active, 1=Low active.
6 d8 s& v, N. {, P& B4 L: F | [12]# d% P9 C5 w4 S) u
Delivery Status (DELIVS)—RO.4 _2 C/ E8 i4 q2 S3 g1 d
The Delivery Status bit contains the current status of the( \: G5 V6 A: B% e7 k
delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit0 B7 h- X! i, V1 a2 F- j4 M* M
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
) f: D7 U0 E0 f& J' A. ~8 H; uPending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
* z. S- L3 B9 L% ebus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).* k- S7 m* R/ h
| [11] Destination Mode (DESTMOD)—R/W.0 r- _( c6 S+ W: \* o- s3 ]8 y- K
This field determines the interpretation of the, L6 D2 K1 k. j2 \2 k
Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID., Q I. Q1 J7 a( D
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.' X K, _$ B7 p9 o9 Z
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): ~. H4 g" {8 h5 O
| [10:8]Delivery Mode (DELMOD)—R/W.
/ E, r# q+ J. ]" \/ @2 |/ [1 dThe 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( u1 s- |) k% R0 Z1 c L p
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode. A1 H6 B5 E* N5 ~
These restrictions are indicated in the following table for each Delivery Mode.5 q0 L' i& b: {+ O
Mode Description3 \+ o3 d: L, E, |7 w) [) Q
0004 R" I. G; J0 w& ?7 _/ @5 ]
Fixed Deliver the signal on the INTR signal of all processor cores listed in the* n- \7 \+ J8 p' m; R
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level. G- i8 j7 S% l. W7 `5 K( c
001
; i' d5 h: a; D" L( [& ]. a+ kLowest7 H+ }% R l! C
Priority Deliver the signal on the INTR signal of the processor core that is
# J7 N1 N* H0 P* Q) Bexecuting at the lowest priority among all the processors listed in the
' m3 Q9 S" F( a4 v2 r K' b4 ?specified destination. Trigger Mode for "lowest priority". Delivery Mode* j1 G8 o: p) u# S3 W( v P
can be edge or level.) z' u2 b1 P+ r! K
010- `0 K/ L9 m" a6 w1 j7 s
SMI System Management Interrupt. A delivery mode equal to SMI requires an
9 M* R0 D% x1 \ P) p7 u8 Iedge trigger mode. The vector information is ignored but must be% m: m2 o) C3 i# q4 T9 @
programmed to all zeroes for future compatibility.0 Z! ]7 w+ K* Z, B4 s
011
# E$ E0 S9 O' xReserved
1 x" n% S$ A8 L h, X1008 B0 ?% m9 k# g% N& _+ e; L
NMI Deliver the signal on the NMI signal of all processor cores listed in the1 F* e# N, K0 R% M
destination. Vector information is ignored. NMI is treated as an edge. P/ a# P7 \( t' V E5 O1 u
triggered interrupt, even if it is programmed as a level triggered interrupt.
6 M0 b9 Z' n7 s p9 w$ W# v* ZFor proper operation, this redirection table entry must be programmed to
/ Q1 F% a ^! H“edge” triggered interrupt.3 b* I6 X2 H' N( d4 g4 d" \6 }9 q
101
& }, `1 l" z# Z5 {INIT Deliver the signal to all processor cores listed in the destination by' f( F4 r4 O( o$ ^
asserting the INIT signal. All addressed local APICs will assume their
2 j, ~7 C! B+ DINIT state. INIT is always treated as an edge triggered interrupt, even if
9 i# E! I) b5 c- |7 ^, r% @programmed otherwise. For proper operation, this redirection table entry' k0 g; x$ q. N5 L, D: z7 {
must be programmed to “edge” triggered interrupt.
# B" ~0 B5 a7 _110
; E) G, c4 N0 P pReserved
) ~. Z# F. q; ^111
4 z7 `1 c, Q( IExtINT Deliver the signal to the INTR signal of all processor cores listed in the. x3 o5 a8 h, |
destination as an interrupt that originated in an externally connected, I' J5 N2 T3 h, ^/ G) K
(8259A-compatible) interrupt controller. The INTA cycle that corresponds- o- ^& k. e6 q& _+ c8 f
to this ExtINT delivery is routed to the external controller that is expected1 [0 d0 u, E7 o
to supply the vector. A Delivery Mode of "ExtINT"+ o& G9 A+ T& S+ M" E
requires an edge
1 V+ g! ^; z+ y! Y; |3 H3 X! ptrigger mode.
; `* s4 O' m/ L | [7:0] Interrupt Vector (INTVEC)—R/W:! } v; A! R' H9 Z6 L
The vector field is an 8 bit field containing the interrupt/ w* A6 W" O) e: a' _4 T8 `. X1 a# H. L
vector for this interrupt. Vector values range from 10h to FEh.
, v+ D$ k' ~/ G% L5 Y( O& O | 1 E% J9 g) t% p8 L% _. c; n2 m
REFF:
+ q" J/ n8 e7 S! b, s0 f+ R% M- @9 {0 J" @8 e2 `
1." q# L1 n- D: A ?/ B
《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》9 C) u! V9 \1 a N, I
2., c! n) O- z9 s9 O ]
《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》, X8 m6 x/ K0 z7 e# I" a. r
3.0 h" C; ^3 p# _, y
《Undocumented PC》
# y/ T- m* q7 I4 r4.
L3 n% ^7 m/ L; o; D2 N7 B( R7 R9 e- u, q, u
8259A初始化编程, ^- t6 r; u( w6 S. L
) P0 S6 H* m M# f2 f6 \
That’s all!
z& W1 z2 o' T
6 G5 R; J0 P1 a) LPeter E1 m1 L% n6 _' y- x4 ?+ Z! ?
5 W! u- _; \9 b3 n
2010/10/070 G4 ^+ A( d/ W A
+ l2 K& C# Y+ F/ [) W
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|