|
|
|
PIC 、APIC(IOAPIC LAPIC) ; k, S1 T9 p& y# u( s7 K2 m, y. L
1. Overview
4 @( {1 ?4 z- ~6 i; i! P/ R: Y) B
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中
- I7 _8 g& a4 y$ e& T2 C6 B1 o6 U用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。
. _: G) V5 C# F7 ~! ]/ W) F: f# q) F* @0 d" X: }( V
& X) K# v5 g: r% v& p. z* {2. PIC: y7 r8 K* E* e& F0 X
) v8 q0 m' o1 u; l. U$ m基于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。
, O" Z. C3 F. Q9 Q
I. G( \# t `, K+ `3 ?* H9 r9 E
3 m) f9 d: T9 m9 p! ]3 p6 ?3 G, H# I0 d. Z& G
. R: N' E( E. H; h# Q" L1 t! T为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:- n' T3 C3 `# c2 h( l. e _- k, D
* C3 [6 ]: \3 D9 M* M0 rMOV
0 D0 Y$ y6 z' _+ [' k& I4 Z6 ]" e5 bAL,00010001b: l6 ^6 `! _ S. ^6 L) M! W* H6 @
;级联,边沿触发,需要写ICW4
# N" J) k: G% |/ s. H+ ]: f( t. SOUT7 l6 v, N4 Y) i6 E
20H,AL
6 ]- v2 s& ~/ v! S9 b" l;写ICW11 {9 Q- G2 [: g& t) q
MOV
1 E( G% O0 }* u4 T2 RAL,01000000B ;中断类型号40H
2 u% T/ Q5 }3 w# l6 ~/ ZOUT
+ l, V) X) V9 h+ B6 v4 I* N21H,AL' z" C; `( p& a. o; H
;写ICW2
. O2 e3 q& ^' fMOV
- b- P7 z- W: G; O/ xAL,00000100B;主片的IR2引脚从片( a* I$ e Z& c* Q' ]6 b
OUT
. H- |. g5 w9 i! k2 a21H,AL
, l7 U* t/ _, B2 Q! e8 B, G& t# K;写ICW3- j# u4 [' k, X: P# y6 X: F: x5 @( e
MOV8 {) V, I5 N# H5 {: K2 a
AL,00010001B;特殊完全嵌套,非缓冲,自动结束
- y2 i H( v' M" a1 b9 [OUT
( a. i' H+ \6 r21H,AL
6 d/ C) X" s& o2 K8 f;写ICW4
2 }1 N1 h& @7 n3 ?! F/ _
' u; n$ Q2 _* ~ x8 H# Z+ H6 {3. APIC
; E7 |- H# B6 `( @- L
# i8 T# @/ O. g/ e9 C. ZIntel 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 c0 m0 U* H% q( c s
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。7 g+ o9 a( L, M. h) u
$ d+ H4 ]: A- T8 K3 {/ w& E1 @. j7 b z! [* k% A' U, f! Y! P
( R9 w! E, w# W
9 C: ^6 J! Q$ f$ E& wProgrammable Redirection Table详细格式如下所示:# @1 b: r0 g& v5 |/ _% A
) a3 C6 D4 j8 b A; M
Bit Description:
1 Q0 U K4 e$ }5 \; D | [63:56] Destination Field—R/W.
$ v7 D: b) e& m/ lIf the Destination Mode of this entry is Physical Mode (bit 11=0), bits- v9 M$ l7 ^/ C
| [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field
/ h9 T& s* a; m0 @4 Lpotentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
0 o3 C& o) g5 k! h0 x9 l* Edestination address.
. r' Z4 I z `% N9 YDestination Mode IOREDTBLx[11] Logical Destination Address
( x" ]- ^6 Q8 f& _/ L# x0, Physical Mode IOREDTBLx[59:56] = APIC ID2 X A2 j+ Z* I) M
1, Logical Mode IOREDTBLx[63:56] = Set of processors
; n0 L+ A( Q% m7 Q Y, }, { | [55:17] Reserved.82093AA (IOAPIC)
, y" e U! T( s8 h | [16]. J* m% R0 U4 O- y; ~8 n
Interrupt Mask—R/W.+ M/ @7 f: `" D- N$ Z q i$ A
When this bit is 1, the interrupt signal is masked. Edge-sensitive
0 e% G8 w) x, I _interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
V) x6 x" B8 n U. u FLevel-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
5 e8 J9 T" L% S& r- \+ g9 N7 _side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by W4 f m1 L$ R' |& ? N, Y8 A
a local APIC has no effect on that interrupt. This behavior is identical to the case where the
4 K }! ?; k. l5 ]- _' D& cdevice withdraws the interrupt before that interrupt is posted to the processor. It is software's
( T. Q' A9 r; E' ? x$ `& F9 b/ wresponsibility to handle the case where the mask bit is set after the interrupt message has been, X7 x4 @- K7 [
accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this- U% o. {/ [/ j% I' h' D. b: k
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
5 _2 ?( J% N% lresults in the delivery of the interrupt to the destination.
. \7 s1 e) K- R7 H* t+ E | [15] Trigger Mode—R/W.: i: |) c! p3 u6 I9 X6 L' V
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
) [7 Q6 n: |. L8 w1 e% B | [14] Remote IRR—RO.0 D3 z% u# [% a5 E0 ^! h7 _+ P5 i
This 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.
. x/ w1 n; X: S+ a, ^ | [13] Interrupt Input Pin Polarity (INTPOL)—R/W.! u# F& [9 z9 x( J3 b' D. d1 E* T0 I
This bit specifies the polarity of the interrupt
. `$ O# @8 a b1 F2 qsignal. 0=High active, 1=Low active.0 l! |# {2 B3 P) E
| [12]
& K5 \8 C1 ~: m |! RDelivery Status (DELIVS)—RO.# p9 J/ w2 F5 c, d) }' h( `
The Delivery Status bit contains the current status of the
/ n' r( w' Y5 k7 L9 E& ~3 Odelivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit/ ?. c+ D. g: V+ v; h4 ]; c
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send# y1 Y4 o; o) J/ [( b8 X8 f4 ~
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC: `/ ^+ S5 z( B5 l x& D
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).# L" O6 [' k- R' C! {1 U9 i
| [11] Destination Mode (DESTMOD)—R/W.# T! C/ Z$ u6 g% j" h$ o
This field determines the interpretation of the
( s/ k9 r* t9 F( C6 d8 bDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID." W! B8 X* H) V) h- U
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.8 @; m' u) M. r: d% E) x* H# H
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)
3 ^' R- p3 `4 o3 G7 _ | [10:8]Delivery Mode (DELMOD)—R/W.6 q5 B* J6 l5 @3 g
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
! H% _7 u% V1 Q8 PDelivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
' g! B0 y0 A% R- ]& p6 V- y* E& U+ kThese restrictions are indicated in the following table for each Delivery Mode.
1 m2 C, c3 f4 fMode Description
. V8 v7 o, v$ C% s7 \5 U H+ H8 m000$ o6 t! d" n* z ~
Fixed Deliver the signal on the INTR signal of all processor cores listed in the# i5 d( L3 w3 N0 w2 A8 I0 P3 X4 L
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
) O+ `4 Y5 Y c, V& M, O& l001! W$ D2 V* h1 _4 Q, o
Lowest
: w. j# F' D$ p6 ~% v6 \Priority Deliver the signal on the INTR signal of the processor core that is
5 G, i* o" d7 \. V2 kexecuting at the lowest priority among all the processors listed in the; l( _+ k- }# ?# R' v% f
specified destination. Trigger Mode for "lowest priority". Delivery Mode
) @( \4 |6 q2 q* O4 A! vcan be edge or level.: C E8 C& S' p2 A$ p" F' i
0103 J# @) r v2 T$ `' L% l0 O/ o. V7 u
SMI System Management Interrupt. A delivery mode equal to SMI requires an6 L7 | `- l) y: |( G% h
edge trigger mode. The vector information is ignored but must be- d" P" Z' ?6 y+ `
programmed to all zeroes for future compatibility.. t+ Q" E. O& P7 V
011
) _0 Y+ k% P1 o8 x2 n1 dReserved* |8 [/ X2 I" z8 X: x" @, t
1009 o4 L1 X2 m9 Y. E4 l! z' F% Y
NMI Deliver the signal on the NMI signal of all processor cores listed in the/ R* L, e+ m8 L: v% j
destination. Vector information is ignored. NMI is treated as an edge( R4 k2 H0 g6 F5 M$ ^. [
triggered interrupt, even if it is programmed as a level triggered interrupt.; d; P8 r5 y$ F; v2 s {+ V( A& {9 F
For proper operation, this redirection table entry must be programmed to
1 p: C9 |" z& x+ J: m“edge” triggered interrupt.( n, L) h& m; x9 F4 e* `
101
+ e% N6 {/ ~; s( M: fINIT Deliver the signal to all processor cores listed in the destination by3 c5 [; t: K$ E2 }" O: H
asserting the INIT signal. All addressed local APICs will assume their
" t9 T2 A+ X) L' B& L; WINIT state. INIT is always treated as an edge triggered interrupt, even if- D" d8 D' a1 ?( `) R
programmed otherwise. For proper operation, this redirection table entry
5 ~( c5 T1 M8 v6 X* Kmust be programmed to “edge” triggered interrupt.4 W T7 D" X/ B: \1 T8 e; h
110
& k7 h- r# C5 S+ H% J3 N5 NReserved/ t3 T1 L* A; V# C2 M* B
1110 ~1 R8 {7 {/ u1 |* R8 m$ p5 U4 d7 H" I
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the
0 }, n$ @- k9 O! Q1 t1 c Zdestination as an interrupt that originated in an externally connected
- H2 i3 d$ x0 _$ Q(8259A-compatible) interrupt controller. The INTA cycle that corresponds9 p+ s) U3 S/ E' A P
to this ExtINT delivery is routed to the external controller that is expected+ Z2 y% f+ o8 a# b) p
to supply the vector. A Delivery Mode of "ExtINT"
6 n7 o3 H9 w7 h0 q# Zrequires an edge
' j' ~2 c9 E, m/ z7 y; B8 q! c+ @trigger mode.
; E: y) f0 J4 T' V6 n. r' y | [7:0] Interrupt Vector (INTVEC)—R/W:- ? y9 I0 E1 C+ K! W
The vector field is an 8 bit field containing the interrupt
" F% q( g, p! S! g& R6 K0 Wvector for this interrupt. Vector values range from 10h to FEh.( {6 V& u! i6 _ ]
| # X3 o1 T3 i. Y) I
REFF:
3 `7 u# _0 E: G. T# C- G7 q4 Z' `) j9 t; a( C3 j o {
1.
0 k9 f. e2 P; p《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》6 Y! q& G* r8 G: K8 A, T' ]* s0 ]
2.
L5 b" E6 d$ ]《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》
4 G" ^& p! W2 s0 ~3. p+ E; L1 p" c' S% }" F G+ j2 u
《Undocumented PC》; G2 m+ I9 Q& {7 r
4.1 z& c2 |( S2 s# _1 c
9 c; m, d% W: x6 q1 W0 F1 Y$ ~0 v& B; h- b8259A初始化编程
5 A( G" ?8 w+ A" l" l5 P! C7 O9 C% P; D7 ^# d1 x, T6 Q
That’s all!% q; V/ z3 d1 ?. \: b
$ x, _: O) q) [& [0 i B
Peter* p' N0 ]/ s' m/ {) a5 V
& c& b4 }' ~/ ^- w- q
2010/10/07
7 {; W% Z7 ?' W! ^4 ~
+ l H+ n1 i& X* f$ Z2 w5 e[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|