|
|
|
PIC 、APIC(IOAPIC LAPIC) 0 B2 l' l9 G8 V6 l6 J7 E
1. Overview
5 s# v! G! t/ f" _$ \, U6 n
+ }, z [+ d% a( }& rPIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中
# p& c3 B! z. K ?* u6 ~用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。+ m6 w1 b# ?* Q3 F0 o4 a* x5 V
& m2 {, L# J: O6 y7 E( n M7 `) Q
4 P. C) V& r' |$ j) c" ?* R. E
2. PIC, C* ^# X" o3 p9 f0 @
! k' p B! x$ ~' T8 b& z- j& X
基于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。
5 ?* K+ H: B& M8 Z
; v4 X- H( S$ Y4 ^4 X% ?
4 S- ^" S0 P7 j- M7 V7 j6 |
: `: U8 E3 S" q L% f8 d; q; k& a0 L2 j
为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:& G: |/ ?2 `( O, g1 H- L1 g
/ E3 F5 u- c/ E
MOV5 e5 ]1 B4 k" k% h4 Q' L
AL,00010001b
0 j6 B& @5 W ] u& @; E$ b+ U; y;级联,边沿触发,需要写ICW4/ E5 N5 G: u: t3 O4 T
OUT S; l- M, `4 A" h# c7 Z& J+ q
20H,AL
/ k2 X0 h0 k, y% r- J;写ICW1
: |8 d4 S6 t5 a+ n# E1 A! EMOV
2 J" g/ `. S3 s2 q3 I7 [AL,01000000B ;中断类型号40H
6 I& p1 i! p- k) _( I% f" m! EOUT. ?5 c$ w* r9 I8 i
21H,AL
2 f& E; W* j; u# N;写ICW2
. ]% n- }3 G3 I& c+ P, T' y' G& V$ ?MOV
: S' K- [. ~4 q& j& sAL,00000100B;主片的IR2引脚从片. M& x {* u2 ?! g& ^, a6 h
OUT
( i; R' y4 Z b) l21H,AL
4 O# H# g7 a0 m L# f. v3 T;写ICW3
8 [& X8 q" f% X3 EMOV+ |9 p4 U2 _2 g2 d" w7 g
AL,00010001B;特殊完全嵌套,非缓冲,自动结束
2 S0 L* ?" M/ x$ ~/ EOUT, |5 Y8 i+ Z1 C0 B# Z7 P# b
21H,AL
# \3 V6 g3 D6 y& ]0 y0 [# ~+ R;写ICW4: W, p4 `* c7 k, w7 c) h
) h2 c) L- I6 \) x. O+ `: E
3. APIC8 Y6 g5 i( o/ [5 N' z
+ ]# M4 G5 N) _! Z* y: Y; V! W
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,1 i, q6 ]/ x4 _4 B1 x; F7 p5 z% m
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。2 F/ Z' N! u( ?; p
( W: i. ?" S$ j2 G
+ R o2 w A3 Q8 J
& K5 C3 D, ^: i' g; }( a
: v) @6 D" I- _4 j7 {; R ^Programmable Redirection Table详细格式如下所示:
2 E! ~9 G# a- v1 A
) P$ n' v- v$ kBit Description:+ J7 G" n1 y3 I. M& b
| [63:56] Destination Field—R/W.4 Y9 n- u- B6 P4 v# n; V
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits
+ Y0 V% r3 Y0 Q- S2 E/ H5 ~( j) E | [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field7 U* ?0 @5 X; u( P& i
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
# p( H5 }' T9 T* m8 Odestination address.
- Q6 n* r# A5 [; YDestination Mode IOREDTBLx[11] Logical Destination Address
3 S5 u/ K1 C, H2 g" t, T9 C0, Physical Mode IOREDTBLx[59:56] = APIC ID
5 E/ ?$ ?9 f4 m5 G1 @0 a1, Logical Mode IOREDTBLx[63:56] = Set of processors7 _# Q9 P: s6 t, s5 @
| [55:17] Reserved.82093AA (IOAPIC)
2 p' I2 C) W% ^# N; L) K1 P' Y | [16]5 m$ @1 u( \& @9 y) x
Interrupt Mask—R/W., C0 o* U" ~& D8 X% V/ x
When this bit is 1, the interrupt signal is masked. Edge-sensitive' R. L. ~7 Y8 Z9 ^9 M
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).. R$ L' m4 s6 Y; R/ s3 i# D
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no4 a: f/ d7 }% ^
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by) L' X! s7 n: {/ U
a local APIC has no effect on that interrupt. This behavior is identical to the case where the: X. I1 T; t' A L7 m
device withdraws the interrupt before that interrupt is posted to the processor. It is software's/ w* l1 e* X% x/ s; ^1 Q3 p
responsibility to handle the case where the mask bit is set after the interrupt message has been
3 m% v# h$ T5 ^0 W) m7 n# ]accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this- a$ K' Z$ g( b( d
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
( W9 r0 ~4 p) @( @$ wresults in the delivery of the interrupt to the destination.
6 P4 h' J7 Q9 G3 J | [15] Trigger Mode—R/W.( j. \$ h! N3 ]8 \) R
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.: h0 W k, a8 A! C) A
| [14] Remote IRR—RO.
3 m8 N! J3 O! J( g0 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.1 z' J9 Y# W4 R- c2 t% E# d$ z
| [13] Interrupt Input Pin Polarity (INTPOL)—R/W.1 w. w3 ^: V( e' X) u
This bit specifies the polarity of the interrupt1 \8 i1 U# t% n8 h( }+ |4 U3 ~
signal. 0=High active, 1=Low active.
9 P7 ]& H: p7 }4 i' P4 e | [12], a( ^$ ^/ x# ]4 o# [% V
Delivery Status (DELIVS)—RO.
5 Q" @9 q* T3 e1 M5 R" yThe Delivery Status bit contains the current status of the
+ \$ F) T/ H9 J4 E2 Z2 `delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit5 ]3 w K1 h2 U" D
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
: J* A* X7 j3 b, A! NPending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
* H* _, ?; V# Q& gbus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
, I" Q3 N+ l. {6 v! H | [11] Destination Mode (DESTMOD)—R/W.& i7 c) Z1 V7 l# j
This field determines the interpretation of the
* M% ~1 H/ V; FDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.' ] D' C5 m/ X) Z7 E2 N
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.1 f) k6 E4 P- u d3 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)2 I) F2 Q$ H! h' n/ L' S
| [10:8]Delivery Mode (DELMOD)—R/W.0 Z1 ^+ k& w7 Z( v. B3 f
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: t8 T! { v6 }) G: Y5 q
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
& G' m7 I% j7 CThese restrictions are indicated in the following table for each Delivery Mode./ x; X$ D8 b( ]5 L
Mode Description
6 a2 |3 O" L1 v0004 J: p. `2 I; m6 K v6 b, b; z6 X; W
Fixed Deliver the signal on the INTR signal of all processor cores listed in the
5 d" m* ~& q) G! W$ u; g; a4 Udestination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
6 M' M6 Z& D8 u/ c$ B& V: l, i001* M8 y( }1 |7 T8 ~! n4 r
Lowest3 Z+ K: ]6 j1 @, C4 U
Priority Deliver the signal on the INTR signal of the processor core that is! ~# \; r. Q3 [9 g- `/ L# M+ I9 H9 Q
executing at the lowest priority among all the processors listed in the
2 s) R4 `0 C9 z8 |1 h) `7 nspecified destination. Trigger Mode for "lowest priority". Delivery Mode
) Y; F5 O; {% p% j; [can be edge or level.1 N& T+ F4 P! O1 Q* i
010- \. X. L R+ _2 `9 R
SMI System Management Interrupt. A delivery mode equal to SMI requires an# _: j& e7 H: o# c& @! G
edge trigger mode. The vector information is ignored but must be5 o' q6 V1 ^9 A, C& h4 w, {
programmed to all zeroes for future compatibility.
6 `; t3 A- o+ {7 d! b0111 {+ M. J$ u; H+ K: P$ A( \
Reserved
; P* h2 L: V2 _( P1003 z2 @: _& q: L8 [
NMI Deliver the signal on the NMI signal of all processor cores listed in the5 c/ @; e' J/ A6 d$ T! G, e+ s
destination. Vector information is ignored. NMI is treated as an edge
, {! z; Y }+ H/ Q) t5 etriggered interrupt, even if it is programmed as a level triggered interrupt.8 r4 Y8 s3 z' W( i. e: ?
For proper operation, this redirection table entry must be programmed to6 r& u N; L3 n) M( U* p
“edge” triggered interrupt.
8 y8 s" v6 C# Y% {9 a5 S3 L101) i( J# L" u6 h9 u8 q( U
INIT Deliver the signal to all processor cores listed in the destination by9 E' i: ?' {' i o
asserting the INIT signal. All addressed local APICs will assume their* V B* w1 T! w: b; f+ t
INIT state. INIT is always treated as an edge triggered interrupt, even if+ A0 U4 t; x: b6 a& l! m
programmed otherwise. For proper operation, this redirection table entry
: q9 m4 P' T5 O- Vmust be programmed to “edge” triggered interrupt.
4 l8 x6 N6 w8 R- j, N( g; v1101 W- Q) l& ?# \% S6 ?* G; q3 K
Reserved
, \9 }2 [- k. a) ~1 W: V! B' t2 P3 b111
8 ~% S3 d! M7 _! UExtINT Deliver the signal to the INTR signal of all processor cores listed in the/ v8 v' A7 S5 A- \5 Y
destination as an interrupt that originated in an externally connected/ K# T& J5 ~1 u' Z
(8259A-compatible) interrupt controller. The INTA cycle that corresponds
- I6 r# K) I( {1 f) Sto this ExtINT delivery is routed to the external controller that is expected0 K H, k& H% e' i2 o2 y
to supply the vector. A Delivery Mode of "ExtINT"
; `# M" O8 a/ X1 [3 ]- v1 mrequires an edge5 U# T! Y: T2 Q
trigger mode.
1 v$ [, Q3 S# a- A | [7:0] Interrupt Vector (INTVEC)—R/W:4 n: B: g6 E+ a. b( y
The vector field is an 8 bit field containing the interrupt; L" k; r" b+ b0 J
vector for this interrupt. Vector values range from 10h to FEh.
' F+ V9 A8 z7 g2 D/ D/ j |
6 H [4 O: @2 ~5 I: }# NREFF:: P0 _, l7 ?& D% U0 g# L& A, h
/ g+ G2 k' U& ~ s2 t; i
1.* \* I( \; q* g! Y8 m% j
《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》
1 M$ ~/ Y! l9 N0 h( w2.# W. L% X* i/ T s; B
《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》. X+ \2 r0 ?+ u. R, Q- I
3.
( A, Q, h& ?6 {9 a; b《Undocumented PC》
- u; Y5 J/ M- [4 P0 r/ N4 B4.
6 j$ d" T/ J8 F7 } y$ l$ L& [) {6 f! R5 N- z8 y7 P; ~" F
8259A初始化编程& I+ ~9 ~7 ~" _, I: P3 k* H R
" R/ q p i1 B" C9 ZThat’s all!
) s5 f) E |, h: k. f! M5 ?
- K* |. _. U) `9 ~Peter/ w! x2 ~4 @0 M+ Q: \
. }$ ~8 v4 T$ \
2010/10/07
+ @$ V. ]$ H" o& M. u" d6 h
! Y: D' T) Q5 N- H! p' G" Y3 X6 H6 C[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|