|
|
|
PIC 、APIC(IOAPIC LAPIC)
3 H/ ^# V6 ]& D8 Q3 ^( \1. Overview* X, H$ L& ^6 N- R
' R) s0 _$ ?* y' ^8 I3 bPIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中
+ Y. \& x, C ]0 D0 z用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。' x& g! i! V. T0 Q& t2 @/ B
3 t' Y: z; v" a8 C5 D0 i
/ M' A6 M" E8 i& S2. PIC
# N0 R+ t0 G9 H) r, X- c4 n! l" P; g V
基于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 P5 S1 ]/ w: h
4 M. B! n) E4 Z
2 E6 X& b, E1 ^
8 r: y' ?$ }9 R) V4 A" G! S3 g& O0 s: o j/ l- G
为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:/ h; i% Y# ~1 t( X9 c
$ U& v B9 A. }, k5 O* UMOV
k8 e% H3 C5 S7 Z( }6 Z. Y0 NAL,00010001b
?4 E4 m- |2 I2 V;级联,边沿触发,需要写ICW4% V2 N* D, P$ G* K
OUT5 x+ o1 z7 o. u. A6 W9 w1 l
20H,AL
7 L; z* u# I$ @. z E7 a; };写ICW1
$ {( S& i i$ a+ _4 rMOV
: `2 c/ R) Y- Z/ o! x% V; sAL,01000000B ;中断类型号40H9 I! l; G+ o" c' b4 J6 P2 e
OUT# m+ m( i/ U7 M+ @/ I$ P
21H,AL! Q/ a, B) _9 E8 _) W7 k
;写ICW2
+ O! ~0 O. S! V& y/ q2 D2 f( aMOV
$ Y u; r: |' v3 C5 UAL,00000100B;主片的IR2引脚从片
- h' a7 J! S$ h! r5 IOUT* j; i5 o3 Y# A. B) p
21H,AL
8 ~6 Q5 `4 f$ t: H, q! V1 W/ f" v1 r;写ICW3
" _" @' f; _# \: f8 d* B/ d$ p0 fMOV
% q6 z5 \. P0 p$ ?6 o: J' |2 T& @AL,00010001B;特殊完全嵌套,非缓冲,自动结束
3 }2 E: o# _8 j1 _& j( W9 s8 B. BOUT
1 [( b. ?% j: B- f" J21H,AL: N* G1 k/ q% e8 l
;写ICW4
. G8 k9 v/ s- h1 A7 f9 n z
0 B. _. n" K2 W% [. \3. APIC9 V, @3 ^, P0 `# k9 g0 G& f6 }- {
) | _7 C% e' m5 @+ N: EIntel 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,
9 _+ P; N: D; _" I) `每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
1 \* X! Z6 A3 W) j0 u
( R7 @; T' X2 [# o S) {7 J1 `8 x) A k- L+ F
( M' u, k) E4 N" f
* q# z7 e- i2 ^5 p
Programmable Redirection Table详细格式如下所示:: n/ w" L# Z, [5 @: H+ I6 ]1 X+ a
0 Z) M% l4 k8 R2 y- R
Bit Description:+ \5 c2 n4 C, Z5 J7 K
| [63:56] Destination Field—R/W.9 `, j/ g! f( J8 t& M8 [
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits$ L5 h$ {7 d& Y3 j( ]' L! O
| [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field, W- {' [1 q/ A: S( ] d
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical; r& d. K3 N& H
destination address. x# z8 E* \, O. T
Destination Mode IOREDTBLx[11] Logical Destination Address) z9 X6 Z2 Q2 l: Q! [0 z G
0, Physical Mode IOREDTBLx[59:56] = APIC ID
# v- s: l% d- I" y3 r o5 {1, Logical Mode IOREDTBLx[63:56] = Set of processors ]; K6 i5 T8 N0 }3 V4 e
| [55:17] Reserved.82093AA (IOAPIC)
. f" I R( s9 L | [16]: r& u/ Q* ~* O0 _4 y; U3 b
Interrupt Mask—R/W.* J3 p- g! t o0 W& |3 v N% K
When this bit is 1, the interrupt signal is masked. Edge-sensitive
' l8 w& ^: U; c, I( }- E. T/ Winterrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
1 D: l1 V3 d1 D$ g, Z/ qLevel-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no: h0 y: ^2 v' }/ ?
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by; p6 N9 k! ]" J- D2 X
a local APIC has no effect on that interrupt. This behavior is identical to the case where the
' ]7 h4 _* V2 J+ x: `, J# _device withdraws the interrupt before that interrupt is posted to the processor. It is software's
% T D- o/ |+ K4 W$ E' }responsibility to handle the case where the mask bit is set after the interrupt message has been
1 J) w/ b3 v0 f1 e2 @& K9 qaccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this
5 q( t5 _3 l( c; e- f. rbit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
8 `. f. _% L* G, @6 k n' W: iresults in the delivery of the interrupt to the destination.. M) d+ J, u2 |( e
| [15] Trigger Mode—R/W." ~3 R7 x3 |- C: Q5 _" G$ A
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
( D8 U. R% N7 p6 Z1 W6 q | [14] Remote IRR—RO.
; R: n+ T: r9 CThis 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.- V& c6 }+ _' j( G7 a3 Q5 l
| [13] Interrupt Input Pin Polarity (INTPOL)—R/W.
! a6 B: w. s+ l7 L& k4 YThis bit specifies the polarity of the interrupt2 h8 n3 B! R4 ?( k* Y+ L& f: x
signal. 0=High active, 1=Low active.4 T0 S1 f' T# \" I0 q
| [12]6 ]9 V' s2 |% u- {/ R- x. S, D8 D
Delivery Status (DELIVS)—RO.
. M3 U" H2 b% s& oThe Delivery Status bit contains the current status of the: I0 q* L" M) y; ~
delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit n" A2 W6 [' O, e
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send9 y; u; l* v$ H; @
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC: w% x! b, }( u0 r! b; X
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
. Q6 h( Z$ t+ O | [11] Destination Mode (DESTMOD)—R/W.
- x; S6 s0 I( ~: J: y) F0 t9 O0 iThis field determines the interpretation of the
9 ]3 q8 ]6 i' q# J9 a/ FDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
# O8 r& U- m8 }( B; d6 c% cBits 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.
3 U+ h- {8 c/ L6 }3 R, Z6 s/ @7 wDestination Mode IOREDTBLx[11] Logical Destination Address 0, Physical Mode IOREDTBLx[59:56] = APIC ID1, Logical Mode IOREDTBLx[63:56] = Set of processorsE 82093AA (IOAPIC)1 u5 N/ U6 R1 ]( O2 @0 A I
| [10:8]Delivery Mode (DELMOD)—R/W.% C6 u& l! J0 z3 N5 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
, @& u' H7 g" X) cDelivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
. X5 B# G. u5 }+ SThese restrictions are indicated in the following table for each Delivery Mode.
" }# |( F+ C1 AMode Description+ a$ w9 s# k! H) j- D( o- d! C
000
7 Q' h) s2 Q* S% L) C, c$ v7 ZFixed Deliver the signal on the INTR signal of all processor cores listed in the& _6 O: O+ @/ h- k9 b
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
( b9 n+ K9 n1 ?0 i" ]/ G3 I001
' L# S6 ~) `9 `) W. iLowest- ?8 H) V. L" g5 z; q J
Priority Deliver the signal on the INTR signal of the processor core that is1 i( d* E% ]0 I U- B! z U
executing at the lowest priority among all the processors listed in the- }+ c! i0 @" k- ]: H9 {# d/ p
specified destination. Trigger Mode for "lowest priority". Delivery Mode
0 j4 I% j% u- y$ j8 n+ tcan be edge or level.0 E, E. t: E% x7 }5 [: ~! K! J3 B
010
1 `- ]/ t3 h8 C' [* S MSMI System Management Interrupt. A delivery mode equal to SMI requires an
0 A9 o7 E' F$ N0 jedge trigger mode. The vector information is ignored but must be
% p* x4 P" Q1 j7 c3 J2 P5 L$ jprogrammed to all zeroes for future compatibility.; ?6 a' N! A0 j
0112 c$ L( m+ m& m5 ^9 r
Reserved: Y; n* X' A2 A) B
100
! x' u7 W) w; yNMI Deliver the signal on the NMI signal of all processor cores listed in the5 c3 G9 P& T2 ?8 ]% \
destination. Vector information is ignored. NMI is treated as an edge) ~$ w3 e* c% Z. o6 G+ N9 Z
triggered interrupt, even if it is programmed as a level triggered interrupt.
: X7 G8 p/ ~- e0 n$ I" bFor proper operation, this redirection table entry must be programmed to
2 Y4 E; a1 _) j$ z9 p7 d! p2 R5 O“edge” triggered interrupt.
* M$ K8 C) n3 N% l& C1010 Q9 R t) v* H1 }* q
INIT Deliver the signal to all processor cores listed in the destination by
8 a$ g" X3 o) d' Q& L+ Nasserting the INIT signal. All addressed local APICs will assume their5 \5 D9 s8 F& F( F f. Q/ G, C1 |
INIT state. INIT is always treated as an edge triggered interrupt, even if
6 {$ K& i+ z. w. y; }; T- b- Pprogrammed otherwise. For proper operation, this redirection table entry
: v* f3 ^3 K5 l9 z+ K! bmust be programmed to “edge” triggered interrupt.
/ Q" i% ^. ^+ X6 u) t7 q1101 d+ T1 |! O) s
Reserved
5 q6 I, W' _4 U+ e" ^111* ]( L3 _5 \# R
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the
3 F' _( R& X5 c C; ldestination as an interrupt that originated in an externally connected g. L! Y/ s& a" i0 z; _. ~
(8259A-compatible) interrupt controller. The INTA cycle that corresponds v; }; y E, [0 R
to this ExtINT delivery is routed to the external controller that is expected. x6 Y. f' S8 u
to supply the vector. A Delivery Mode of "ExtINT"$ O! N* f' ?! l
requires an edge
% P. f" s: H0 g; {" S, s3 itrigger mode.0 n( `- F2 I; d& M4 {. W# v
| [7:0] Interrupt Vector (INTVEC)—R/W:, \) e# u3 X# U$ G' L# N
The vector field is an 8 bit field containing the interrupt
7 r7 P9 y+ C; ?/ R2 t8 B# lvector for this interrupt. Vector values range from 10h to FEh.' v% Z% u' W# `7 ]# I
| $ ?+ L1 o% B+ l
REFF:
8 z; v, `' {. ^4 s( w3 r4 q6 M. g
3 J T, n* G8 G1.5 w/ m& {; o( v2 l
《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》5 \. g4 F+ v1 v2 m$ A8 P3 v
2.
\" W' p1 E- e3 M/ u《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》, ~& { p; l$ F0 H& Z9 m
3.) i5 ]7 C! h/ |8 Y$ n) t' V
《Undocumented PC》
/ y* j) ]. ~0 r, P4.
: U1 e; h" X1 L$ x( k! x% r/ k6 W' p; p, v6 ?$ J2 }) ` U6 j9 v
8259A初始化编程
% u9 x- A, W9 w5 f$ S' U, D$ y4 V4 ]
That’s all!4 J- P( s* w' W1 o" a4 a" b
' ?1 z- H6 M! d) X' y9 uPeter; W# \) V" E! ?
$ u) d9 |4 W) o8 o* }5 d ?2010/10/07
1 T* P0 @3 W4 e8 E2 N- X ^1 _1 F' R9 A
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|