|
|
|
PIC 、APIC(IOAPIC LAPIC) 2 ^ K8 ?! n& R1 A: f( S
1. Overview
6 E( Q# V- `& K% |
# z- a K6 o( D% w& N; |& `' rPIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中6 T5 _3 ?4 m+ w1 y; ~
用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。; \3 `# a- y$ {5 g
' ~9 Q0 b/ D8 i
/ q1 E2 S' C a/ D2. PIC
% [3 P9 Y; Z# l7 f3 ?4 v, z
$ L( E% l! ~% F4 l基于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。
0 q0 ~% {/ h2 o5 r2 z. E- Q; d3 v0 {: V! X4 }1 N6 |% n! B6 j; k
; s+ A+ q1 Q! { ^# O8 [. j
* \ L k% ~4 {; y
! D' F. A5 ~8 h; m$ `为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:
s; v& c2 r n0 j+ e
+ Q2 S! d5 |$ K/ {1 A$ dMOV1 {, a- K5 u7 \1 Z
AL,00010001b2 o% |, k- o; s, @" e
;级联,边沿触发,需要写ICW4- M# ?$ I5 w* L$ M1 p. W
OUT6 Z* W" o+ E3 S. z" g4 I! ]9 E
20H,AL& N% C# s0 w/ y& L
;写ICW1
6 L# q( }- C' }# Z# uMOV' A8 J+ e Y0 V
AL,01000000B ;中断类型号40H
8 c% O' L( Z- q$ z8 Y% V8 HOUT) W3 t) P# b( U9 L7 z
21H,AL
) t+ F0 H2 }) K) e/ ^' n/ q;写ICW2
( x. A5 C) a* l5 ?, v$ ^# EMOV
& R' J( ]. R5 O" P( N3 E$ ^AL,00000100B;主片的IR2引脚从片
- n" S9 w% q! _OUT) b$ b! s" Q2 _' K
21H,AL
' b9 N9 W9 r) l;写ICW3: M6 |2 E; E8 ^. e6 o3 P' q
MOV
0 ~ k! X5 u! v8 M: i9 jAL,00010001B;特殊完全嵌套,非缓冲,自动结束% w3 N e4 v$ `: W( A
OUT$ B3 [6 q! H# h( \
21H,AL
- H# c1 b1 z3 J- D) O;写ICW4
+ K2 Z) r" K% y% Z& B# V
& `9 N& Z+ q/ H- v3. APIC# x/ s% f; X) j5 a0 N& q( R8 J' S
8 T' z1 u0 o5 ]7 c, Z G% O7 e
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,
/ b1 b' ?' @& `+ }每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
# _' x$ F9 S, M1 n* l) b
- L2 |- ]% i0 ]& A7 @+ d0 S2 }% ]& Q4 s
$ T; M6 U8 f% |
, h4 y" b0 _( m; I9 E2 e
Programmable Redirection Table详细格式如下所示:- B( n6 {4 R' B: q
. x, }& z/ \- V* e3 y
Bit Description:* E- w# k2 o; ^: ]
| [63:56] Destination Field—R/W.$ K3 g. ?3 i7 `- n
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits9 g e! S1 O: }) `
| [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field, j8 f! N& }- {. \2 ?
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
8 m. v# I$ D. Tdestination address. _( l' F" A: V$ t+ K* M3 |
Destination Mode IOREDTBLx[11] Logical Destination Address u4 c9 ?+ `0 j
0, Physical Mode IOREDTBLx[59:56] = APIC ID# @# {3 c! o' k# }" k0 o
1, Logical Mode IOREDTBLx[63:56] = Set of processors
0 f- u& V* b+ \ | [55:17] Reserved.82093AA (IOAPIC) * W/ H* |8 U6 L9 h7 n
| [16]
( U! y" J+ p, D% T# o/ A) p7 F" EInterrupt Mask—R/W.
4 o% B ^3 m8 L# N, IWhen this bit is 1, the interrupt signal is masked. Edge-sensitive" V# X; G9 N$ O6 J9 f [
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).5 i4 @$ m, x: K6 l
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no# w1 T, V& v) O
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by ?/ k+ P+ @) l" a7 V1 B! R/ r
a local APIC has no effect on that interrupt. This behavior is identical to the case where the9 m+ b; J9 R& m0 P }- n* E
device withdraws the interrupt before that interrupt is posted to the processor. It is software's
' b9 Y1 n0 k7 N# H qresponsibility to handle the case where the mask bit is set after the interrupt message has been
+ \8 m7 O# G- w2 z+ E+ |accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this
; d6 J+ ^1 V6 E5 rbit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
3 x2 Z) |( e- Fresults in the delivery of the interrupt to the destination.
2 r* L/ V. W! }5 ?4 U. | | [15] Trigger Mode—R/W.
2 c r( w, h) _0 w5 |The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.2 d6 H% ]! U+ e, v" [7 w
| [14] Remote IRR—RO.
, Z( u/ W2 B) C( x% Y) aThis 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.& Q6 k& i( d) u4 m' i
| [13] Interrupt Input Pin Polarity (INTPOL)—R/W.
8 O& d$ \1 I. D2 F rThis bit specifies the polarity of the interrupt; q' T7 D$ {0 r3 C6 x- k' \; y5 L
signal. 0=High active, 1=Low active.
4 r% M4 v2 {7 S" e, z# W$ d | [12]* i3 `& _* N6 y" w
Delivery Status (DELIVS)—RO., b$ |- L p* m+ |- S' E
The Delivery Status bit contains the current status of the1 I' R ?, S4 [/ S1 f9 H O5 I
delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit8 K0 m4 s( O9 |1 X4 T c0 W
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
$ X8 O. K! W( lPending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
3 U4 {# d/ W. mbus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).% ^4 o3 r2 t9 O; i3 t
| [11] Destination Mode (DESTMOD)—R/W.
3 P- J; }+ z$ s" d9 G4 h& q# W1 }! MThis field determines the interpretation of the4 W3 k# B4 A+ }' L u
Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
1 A2 D% v Y' N4 ~( @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.6 y; E' p3 p! G3 N# r$ Q/ q% j
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)# z9 P. k. J7 G% R
| [10:8]Delivery Mode (DELMOD)—R/W.' U! F, D/ I% x* d( u
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 certain6 p, C4 m! j3 _+ r5 H; I
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.: F' e- Q, c( f# k Y" m/ |
These restrictions are indicated in the following table for each Delivery Mode.. z. \! q4 w. p8 `% q# k! D
Mode Description- s0 m2 z% w* q
000) s) ?( w7 ^" A: Y6 I
Fixed Deliver the signal on the INTR signal of all processor cores listed in the
6 N0 u& p1 r6 K! d% Pdestination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
" C2 F" ?. q6 b# q+ |001# v' u- C+ X: P! y
Lowest* T: w6 Y, S( |8 g4 Z
Priority Deliver the signal on the INTR signal of the processor core that is
9 [! ~) k; V) v: q6 N6 wexecuting at the lowest priority among all the processors listed in the; _; D8 b) j1 O& q9 N
specified destination. Trigger Mode for "lowest priority". Delivery Mode$ W; S2 w3 E2 A8 r" @: E
can be edge or level.
$ F/ B( ]2 z* s; B5 i0 ]010
! Y2 s0 B. O! P9 Q: E: `& h1 ZSMI System Management Interrupt. A delivery mode equal to SMI requires an
; W" Y" r1 w0 W/ a$ ^edge trigger mode. The vector information is ignored but must be% N& Y) X" I$ z6 L0 ]( P
programmed to all zeroes for future compatibility.' t9 l( ^- v0 G z
011# |- l( T, \7 R; E6 _ ]! L$ P
Reserved v7 N+ n6 s6 ]7 g9 m- [1 U- p- P
100
6 p* q) a. x2 T8 X1 YNMI Deliver the signal on the NMI signal of all processor cores listed in the
) e3 K' @4 u0 y3 U7 Kdestination. Vector information is ignored. NMI is treated as an edge
! Y. k2 Z* H& u6 ttriggered interrupt, even if it is programmed as a level triggered interrupt.8 [. s8 U4 X! O, M
For proper operation, this redirection table entry must be programmed to9 P$ }3 M+ O2 N- L% i& ]
“edge” triggered interrupt.; U# ~4 F1 \# Z- v. Z, |
101
* c+ i9 k" b* G/ zINIT Deliver the signal to all processor cores listed in the destination by
' C2 R% [& O* s: Q% r2 Sasserting the INIT signal. All addressed local APICs will assume their6 C+ _# G. I4 y( G, T* s
INIT state. INIT is always treated as an edge triggered interrupt, even if* Q2 g( X8 _/ V/ o% J( S, G
programmed otherwise. For proper operation, this redirection table entry: K: \% H1 U! w9 R+ b* F7 s' a3 K
must be programmed to “edge” triggered interrupt.
) c( _; K8 C4 D110
5 t# \; a A, S7 t$ G3 iReserved
7 P: F, w" S3 I, V111% G2 [! x$ c$ n' H- E: H
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the c: D# |- ~7 H; w' f7 y
destination as an interrupt that originated in an externally connected
D l" E! M8 m(8259A-compatible) interrupt controller. The INTA cycle that corresponds1 I0 d# l% l- J
to this ExtINT delivery is routed to the external controller that is expected
- {( A* t+ f9 O5 v' W7 t* s B9 R6 P3 Kto supply the vector. A Delivery Mode of "ExtINT"
( w6 n: ?1 A/ p! V6 jrequires an edge! V8 F6 u }+ p* y( N5 U& ~
trigger mode.! w5 { C7 s, x' o
| [7:0] Interrupt Vector (INTVEC)—R/W:
/ D, }# k3 ^& b- S. [The vector field is an 8 bit field containing the interrupt* D$ o" Z) i1 _9 P: d' j$ W
vector for this interrupt. Vector values range from 10h to FEh.) G) ]! i4 w; K
| * X, T" G- l. x$ M7 E( M
REFF:
/ R* k4 b" G$ a. O B" e2 g0 L
9 Q/ x2 S6 ~3 D! s/ _9 Q) N1.
6 W4 ]- ^& [# z# \0 {《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》
. J* M; q! r" M. [' \2.4 U8 }1 U% \0 _0 r
《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》: M4 I: R. F7 }* r
3./ i, ?, {8 N8 X8 x5 z
《Undocumented PC》
$ N8 N$ g s7 m0 }: h* q9 p4.
9 W x# }& P$ p/ v# P
/ l- F+ M, }; p& R7 ~1 Q% {8259A初始化编程/ ~* N8 U9 D8 \, m9 m8 O: {
" }3 O* {' H' h% o7 sThat’s all!: ^# S" S8 \' S
$ X. }& o$ J/ n% qPeter# k o6 n4 F0 ^( F+ P/ W, P
8 @! n1 N4 |1 B0 G" H2 M7 k z2010/10/07
8 g1 ~4 h! B2 W
) c8 K# w/ h/ E- I3 o[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|