|
PIC 、APIC(IOAPIC LAPIC) , N1 e/ l3 x! P, ]1 d% _
1. Overview
' E1 S2 B9 e" G% G. e2 Q4 @# ~8 @7 K
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中) }% E* |: V8 A+ F& Z; w
用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。* c1 L2 a- h# P1 Q. }5 r
8 x) ~# i9 j6 C2 v! T& V
6 `8 `1 Q; `0 w3 Q/ w" ^
2. PIC
[; l- E" h' G% H* I! C
% O/ H( H& O2 M; L' r基于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。- f9 T3 ^2 i& S, G$ _- N
7 d! @! i- j) P2 y6 Z7 [
y9 z, Z) i# ?: V( u9 c* g; F% C- t$ b* {2 V
& E6 H4 h7 F+ n( o为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:
- J3 a; O: i8 m, t) S) O; M
# W# |( {3 M. l* sMOV
9 ^( ?$ H' Q3 r$ {3 p; sAL,00010001b' R: \% [& l9 z$ t) b) P5 {
;级联,边沿触发,需要写ICW4
/ \& s# ~2 z" i* }& tOUT
$ _2 Y0 Q# R. A# W; t/ n20H,AL, u# N7 N8 o; F# l
;写ICW1
0 d4 l s) L/ e5 R6 f4 H% t% d9 VMOV# ^2 F5 R0 V- m. x. O
AL,01000000B ;中断类型号40H# ^+ C* A, U# x2 Q! ?* S0 L* _7 r7 ]
OUT5 k, ^ N* p V* F, ]
21H,AL
7 S8 W( ~: [0 X. D2 U5 G! S6 z;写ICW28 W, ^5 w& c4 k* @' [
MOV* z% D" N0 Y% I$ a
AL,00000100B;主片的IR2引脚从片* j- X7 ?6 _4 _8 b& y2 g
OUT
7 N# A+ p i0 a21H,AL& G* c# M1 ? j6 T9 { O
;写ICW3
7 n' X8 O, U. h# A# f6 I4 C* Q2 |) LMOV
: F2 U0 V$ j" e5 f5 e8 rAL,00010001B;特殊完全嵌套,非缓冲,自动结束- w2 h4 L( }+ `3 F% j$ w
OUT
! ^: B8 h* Y1 o. j21H,AL* s2 q, S& ^: b G, O
;写ICW4
& W: v, @& \2 h* f# w" O. q- L& x, k( _8 t1 E2 R" T+ D
3. APIC, ?8 S& T3 s+ O, u: ?
0 j1 V# R0 Q N! P6 A @" ^8 O3 bIntel 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,
8 a, J4 _8 z3 q) V# m+ U( T6 }每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
( L6 c0 [, h9 E! B* E# e4 x y" G( ?8 O5 I. W a
- P" A5 V8 S0 V9 E- R0 u
8 l+ g( l6 q+ g ]
$ b) h- k1 V6 k6 K" J- a3 y* ?! _Programmable Redirection Table详细格式如下所示:: L; v3 M: J+ [0 c+ a+ M( n4 ~ H
% [# T' B+ m$ m4 T) L7 mBit Description:7 B# h9 R/ z e% a+ F% N- r0 t
| [63:56] Destination Field—R/W.! v( V0 k: k9 j9 h7 x' N
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits% K' x/ R# Y, ~# |; _
| [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field
0 ]; Q6 w; M% E& wpotentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
. V1 d3 `# ]2 b+ Q# wdestination address.4 F- L- B7 O) L1 E$ x) P& a6 D, \3 o
Destination Mode IOREDTBLx[11] Logical Destination Address
" w! `6 m. g5 i; R1 V2 n0 R7 h0, Physical Mode IOREDTBLx[59:56] = APIC ID7 `; L9 Y0 h1 m( f
1, Logical Mode IOREDTBLx[63:56] = Set of processors) \% R$ A0 C% s3 C a3 T8 ~
| [55:17] Reserved.82093AA (IOAPIC)
" A8 Z/ z5 e! X0 j | [16]
x/ C; K2 g1 u, DInterrupt Mask—R/W.
" q' G7 J r* w5 w4 X/ @2 O9 I1 N/ gWhen this bit is 1, the interrupt signal is masked. Edge-sensitive
7 P+ a6 ]0 f. U2 `& Iinterrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
. i4 A# s* Y' JLevel-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
6 ^2 ^/ d% Q8 ^2 V6 ?9 N' n" nside effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by2 h. y8 r4 z, Q
a local APIC has no effect on that interrupt. This behavior is identical to the case where the
2 P+ ~1 B2 [3 z* }: ^device withdraws the interrupt before that interrupt is posted to the processor. It is software's( l- m' {! H; ?0 K5 i6 ]
responsibility to handle the case where the mask bit is set after the interrupt message has been
# {+ e1 j' ~2 raccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this' x! |& K# q. l/ t& K4 D
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked& Q6 e' {6 x. w& K" j& ]( ?1 B# x5 U5 x
results in the delivery of the interrupt to the destination.6 I: p) F2 v4 H* O! e3 }& p
| [15] Trigger Mode—R/W./ a3 R: k2 J- M4 F6 M+ |
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
# W; W. X$ M) b: C( r& E u% c | [14] Remote IRR—RO.7 \2 i8 {+ U7 F& L6 D! v
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.( l) b; ~4 m) B( u6 [
| [13] Interrupt Input Pin Polarity (INTPOL)—R/W.
# N. Q% M7 w$ v: x2 L6 n/ LThis bit specifies the polarity of the interrupt- M4 |. C' r; m9 G( a
signal. 0=High active, 1=Low active.
! q8 u: X- M2 l7 V* L& n | [12]; ]6 x& g- w# i
Delivery Status (DELIVS)—RO.
p" v9 [ ~+ P- NThe Delivery Status bit contains the current status of the" ~. R4 m; b" I4 L: A5 I
delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit
% A1 c0 y/ Y! O, C% Bword) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
; b% R8 n0 S1 l6 G0 \Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC% ?' Z$ K: b& k a( _
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).9 f% o7 K, S) }5 U
| [11] Destination Mode (DESTMOD)—R/W.5 s6 t$ ~" I6 T4 b% u7 g$ l% p9 \
This field determines the interpretation of the
$ Z$ A z; U8 n( Z. m. GDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
+ |+ g7 T: J- _. mBits 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 L; ]( k' I+ G# ODestination Mode IOREDTBLx[11] Logical Destination Address 0, Physical Mode IOREDTBLx[59:56] = APIC ID1, Logical Mode IOREDTBLx[63:56] = Set of processorsE 82093AA (IOAPIC)9 ]$ o) G K9 K. B) i1 @1 R- D
| [10:8]Delivery Mode (DELMOD)—R/W.2 x7 N" u& h$ r
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+ c4 x- a) n# ?) k& S
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
% [/ f( w' ], E/ h5 WThese restrictions are indicated in the following table for each Delivery Mode.( E0 [% x7 H: D& r. W
Mode Description3 N: Q- c) ]/ w/ A* V- H
000& w, f$ X2 Y, D' u6 g- E8 q2 B! o7 L
Fixed Deliver the signal on the INTR signal of all processor cores listed in the
4 ^1 S0 [/ h+ l# A9 d! f2 Gdestination. Trigger Mode for "fixed" Delivery Mode can be edge or level.: D) C+ G6 C- S6 {1 m* N, x
001, \0 f8 E0 j( [' r5 X: B: N1 {
Lowest
$ p5 E2 b/ D0 l0 Z' @$ sPriority Deliver the signal on the INTR signal of the processor core that is
4 w& z2 H1 K) w. t) D* nexecuting at the lowest priority among all the processors listed in the
' ~& H' a+ i! u; c9 O [4 `specified destination. Trigger Mode for "lowest priority". Delivery Mode
) `7 Z+ J: ?% S; F e3 P$ G Hcan be edge or level.
$ v0 ?; ?% F% x+ t o, W010
3 I/ j! V* q8 P( N. R$ e0 h+ HSMI System Management Interrupt. A delivery mode equal to SMI requires an
# `( W0 ^. F/ H. ~5 @ bedge trigger mode. The vector information is ignored but must be, @( q& O7 H/ ~0 }, c* u/ C
programmed to all zeroes for future compatibility.
E4 Z Y# p. n K/ T, r: g7 N011! k( `: x5 Y: Z/ P/ N+ X
Reserved, [& z; H$ ^' p4 ?* R
100
4 ~# J0 h6 i5 v# x2 u' \1 w. {5 _9 eNMI Deliver the signal on the NMI signal of all processor cores listed in the" N5 m) U' P. c, K8 R
destination. Vector information is ignored. NMI is treated as an edge
( X6 w. o0 d" T# U8 Xtriggered interrupt, even if it is programmed as a level triggered interrupt.4 C1 X J T" o& h9 |4 K4 T( B
For proper operation, this redirection table entry must be programmed to
4 l& |, O* X0 {4 [- Q* ]1 t, a“edge” triggered interrupt. w9 M$ B2 v5 P3 k, G
101
7 N( ]; E! n D9 J; w1 lINIT Deliver the signal to all processor cores listed in the destination by+ W9 j, N r% \$ k5 f
asserting the INIT signal. All addressed local APICs will assume their
. I: N( m t) K) L( O1 lINIT state. INIT is always treated as an edge triggered interrupt, even if
% ^ @9 |; T+ R# pprogrammed otherwise. For proper operation, this redirection table entry3 `" Q2 R7 Y7 b& f- j5 ?& O% b P- s
must be programmed to “edge” triggered interrupt.
2 X" w6 A: y F8 h: l110 n' G. V" o6 H ?3 i* w: m1 S6 s
Reserved& ?( f" {7 t0 {
111
6 x6 P, N$ S) u( B; QExtINT Deliver the signal to the INTR signal of all processor cores listed in the$ }% E7 g4 ?& a" u; ]' @0 b# \
destination as an interrupt that originated in an externally connected
6 ^, M Y. p( A) a% \4 l+ S ?(8259A-compatible) interrupt controller. The INTA cycle that corresponds' B1 s# X; c. u. a8 O
to this ExtINT delivery is routed to the external controller that is expected
7 `; q. y8 P( n# Vto supply the vector. A Delivery Mode of "ExtINT"
& M; K! K/ m7 Y0 g4 o# c( L' Nrequires an edge F5 o+ k+ T6 Q6 ~
trigger mode.
7 ]3 U" C" O0 p" @9 v; S | [7:0] Interrupt Vector (INTVEC)—R/W:
0 O$ e7 r9 D6 [2 b5 @The vector field is an 8 bit field containing the interrupt
$ X6 D. o9 s& d6 g& ]vector for this interrupt. Vector values range from 10h to FEh.
6 Z" F; {5 t" t: J9 [) Q | ! [. ~2 h. [3 h) I: n6 a
REFF:4 f3 f- G2 o5 Z2 Z
/ j8 m2 G( i7 d' s1.
& `* }2 v& C6 j《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》
, d0 I9 b, w3 z5 C" I$ E7 L2.# ?) ]0 H, k' J+ Q
《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》
( W3 F) y r8 |( k2 p3.$ T9 N5 q; z$ E9 y. d" w
《Undocumented PC》
+ z% C* b" y( }% s. v% _3 U# u4 I, U4.# V; j# B6 c0 J
+ e9 \. J8 E. _/ S& b' \
8259A初始化编程! J0 @8 B; d% s( D. C4 z3 t
7 P+ q B8 Z. q
That’s all!
. p0 p2 q }6 Q) G1 x4 z- Y
7 }+ E9 ]9 [. L) q) _Peter/ J8 l! p! ~7 v
) B T, s: y2 [- {0 J6 N( V8 Y1 N) h# t
2010/10/07
) C6 _ |3 Q+ b" h# d8 _- P
2 a9 m- R% z9 S, D[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|