|
|
|
PIC 、APIC(IOAPIC LAPIC) / _- C, w9 [* k1 H3 T2 g+ i
1. Overview
, j- x0 }9 q4 Y3 @& I8 h- j
: c. F4 v0 e9 b3 J$ ^8 M; t9 oPIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中
# Y9 l N% w( | H$ q用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。
1 a L+ [* V, @$ R! a4 F" ~3 Y& F0 g. B7 g1 @2 k
2 ?# d6 V- `4 S1 m) N# N
2. PIC
; M' Z, N# [/ X* O
! p& _( l4 j3 [ A: ?基于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。1 N* h5 D- `% J- s( O" m% w
" y- P2 E; c9 k. {# O, g1 Y
" v7 f' k% T4 ]4 A; D+ I# U+ e0 ]* e1 |5 z
; F, }& r4 R# U4 Q为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:
# `# X+ Y; |- e' C
9 P) D' S6 E1 L+ @MOV8 w) p( Y2 _$ t: A; |6 K. j6 ]
AL,00010001b* P4 Q3 u4 F0 J0 D8 N' x( r$ o
;级联,边沿触发,需要写ICW4+ P% i6 _' F0 Y: B; n, ]; r
OUT- l1 w. {5 ]$ X3 t, {4 u
20H,AL
7 U0 b- M+ |4 q0 A7 `& J;写ICW1
9 ?* Q+ ?- e; E8 G: o, YMOV
+ N* V5 f: Q6 L' e% VAL,01000000B ;中断类型号40H
0 n# l/ I+ y6 e% A1 Z1 w, M! UOUT- Y# C! x+ K: Y
21H,AL/ a6 c9 d8 O2 V) z' ^7 D8 K
;写ICW2
7 R* _) M7 x; DMOV7 Q6 c" o8 x6 [" S t
AL,00000100B;主片的IR2引脚从片
/ m+ M! ?/ B9 h }/ hOUT
4 H2 |2 L* x M! |1 r21H,AL- T# h/ N# A/ H) m1 r3 |1 W
;写ICW33 e& C0 w' u8 E8 n) ]% c
MOV5 ]. v0 X( d" S$ T
AL,00010001B;特殊完全嵌套,非缓冲,自动结束
& Z% \- m- y9 IOUT* I6 U6 d! d$ W. |1 D
21H,AL
) E; X" l. a1 ~: };写ICW4( ~8 _4 { U \. _: U9 e+ r
5 c6 i! O9 y, I2 ^( Q7 h! d& x3. APIC
* F6 p, A8 ?2 T% B2 ]! a- {. j: k8 ~3 {
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,
# ]* m: P& ]* d: S7 h每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
% D7 w" K: z1 O x1 e( o5 v8 M0 D% E, X8 i2 w
1 x- F" H5 R5 u5 W& i j6 n" L
1 E2 R/ U5 g8 \8 f, @. Z( L* ~, h
' n. d {" I: i- K" R/ S0 P$ uProgrammable Redirection Table详细格式如下所示:. L$ P s$ e' r
* X( y/ a2 y9 Q3 x0 \& w) A9 K/ OBit Description:* z- u" o4 j: L5 X3 a
| [63:56] Destination Field—R/W.: D6 W% H- y' `- w- \4 [6 Y
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits6 b: {% U0 Z/ v B8 I
| [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field, w( F/ Y: Q; h P9 J8 a
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
( J; `- H3 S/ A$ V: b! o" {destination address.
/ O! q) b+ F* P; J" f5 b+ x. PDestination Mode IOREDTBLx[11] Logical Destination Address% C; H; j. K( C# g
0, Physical Mode IOREDTBLx[59:56] = APIC ID1 k/ Z$ Q' R! `8 v3 w. Q
1, Logical Mode IOREDTBLx[63:56] = Set of processors
, Q1 u, c% X) Y' G0 u | [55:17] Reserved.82093AA (IOAPIC) - [) _$ O+ c9 T- g
| [16]
+ d* G" D, t D1 N1 b/ d/ FInterrupt Mask—R/W.
/ {& p3 Z$ b4 c# G8 @& TWhen this bit is 1, the interrupt signal is masked. Edge-sensitive
6 Y8 Y; T" C" [, hinterrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
' p- d! i, l3 v7 [. q3 E+ KLevel-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
5 U% g* v- ?& f3 tside effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
% P, E, H/ H3 V' G- fa local APIC has no effect on that interrupt. This behavior is identical to the case where the
, ~# ]5 ]6 p( L) ldevice withdraws the interrupt before that interrupt is posted to the processor. It is software's4 J+ d5 l9 v. E% t" ~
responsibility to handle the case where the mask bit is set after the interrupt message has been2 y0 B/ ^+ S) K! c- y( H/ }/ x
accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this6 [+ O! C1 I0 B: G$ F
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
4 H; r- A- F( sresults in the delivery of the interrupt to the destination.
2 Z& Y. W* \! V* @% ?# j- G | [15] Trigger Mode—R/W.1 O0 x! v$ j: I8 H3 u. M7 [8 w/ m( p
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
% S- Z* o0 U0 _5 O0 Y | [14] Remote IRR—RO./ o* o* H( p' \% g. T
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.
% ]) u+ [- G3 B. ~" p | [13] Interrupt Input Pin Polarity (INTPOL)—R/W.
u& d8 g- H/ L- T$ Z. NThis bit specifies the polarity of the interrupt$ S4 P B2 \' _3 l2 G: X
signal. 0=High active, 1=Low active.
/ h! |* W3 ]1 q& t/ S4 _ | [12]2 \# s9 h9 }9 ~! c
Delivery Status (DELIVS)—RO.# B2 h2 W# u* l( ?' \6 P
The Delivery Status bit contains the current status of the. S6 Z3 g- j- w2 b
delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit! L; H( }+ y0 G1 n7 p3 N
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send& @# y+ m6 [4 O; |4 r- \
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
% w R5 u4 f' \* `bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
5 \# h' \ L! p" C+ m | [11] Destination Mode (DESTMOD)—R/W.* l+ m# x: n. N2 e
This field determines the interpretation of the* l: Z/ Q- f) l* O" V' ?& b( \! _
Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
1 H! Y- o2 T6 LBits 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.
( ^* R+ @% p: {3 t1 ?3 Y- O2 m8 ~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)
& g7 Q& G9 e) \( T- f6 F- m | [10:8]Delivery Mode (DELMOD)—R/W.7 s7 W$ C. u t1 |: u/ v
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
" {. ]& C/ g7 k+ H- `2 b% g' pDelivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
1 \ w4 r+ o0 C! T6 [These restrictions are indicated in the following table for each Delivery Mode.: ^0 D# A0 w {) @
Mode Description1 M9 Q# Z2 R- j
000& r( @5 r! C2 O5 ?2 ^
Fixed Deliver the signal on the INTR signal of all processor cores listed in the
+ a4 y" y* l2 n( i3 ]( {destination. Trigger Mode for "fixed" Delivery Mode can be edge or level." w; m% D S0 \. z6 m
001
8 z3 t# Q1 I4 L' r* {" h" HLowest
% f! v4 D# B1 W! o) _, OPriority Deliver the signal on the INTR signal of the processor core that is7 ^: f0 S* i8 ]4 ~
executing at the lowest priority among all the processors listed in the. i) j M# I) w0 |
specified destination. Trigger Mode for "lowest priority". Delivery Mode
* }# f- E- ?0 }can be edge or level.4 ~3 Z8 o: L D5 U+ T
010
; S1 x3 z: G& KSMI System Management Interrupt. A delivery mode equal to SMI requires an
( _ g3 K- N7 q+ p& b* Kedge trigger mode. The vector information is ignored but must be5 \5 S! D% B% e" i, o7 j2 @
programmed to all zeroes for future compatibility.
$ X0 H* u) L' h: ^8 j7 J011
7 D( K7 m2 k; K2 r5 L VReserved" T4 V. r3 Z# f1 L F
100
" k: G6 u, W+ r; {- ]" oNMI Deliver the signal on the NMI signal of all processor cores listed in the% G! Y+ t0 d; M+ ?" ]/ y
destination. Vector information is ignored. NMI is treated as an edge6 H+ E# X) D5 o$ U
triggered interrupt, even if it is programmed as a level triggered interrupt.
- B3 h6 l0 u/ F* b. yFor proper operation, this redirection table entry must be programmed to# _2 e) _7 ~3 ]' Z5 R Z
“edge” triggered interrupt., }- _2 Z- Q2 w" R5 }/ F' W9 r
101
3 A$ {# R* e* [6 p6 u, b+ F4 u3 UINIT Deliver the signal to all processor cores listed in the destination by" g: C2 H6 a; K4 @- [% ~9 L
asserting the INIT signal. All addressed local APICs will assume their
}+ b$ `2 |+ P* j. b3 Q3 Q( AINIT state. INIT is always treated as an edge triggered interrupt, even if
- A2 U2 y/ t- [8 R# Fprogrammed otherwise. For proper operation, this redirection table entry* p# f: @. f% U) ~" H1 Z
must be programmed to “edge” triggered interrupt.; F& ~6 k8 n# {! a+ Y; v" A( M
110
$ m+ g- J2 a& @! BReserved. J( a9 o1 `7 _6 l$ M
111% v- W5 u2 P7 w" E! e
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the
6 u j+ m" Q0 I. L( O# a6 Ddestination as an interrupt that originated in an externally connected( B4 z1 k( l8 A- M" i
(8259A-compatible) interrupt controller. The INTA cycle that corresponds
7 ~5 [- A/ ^1 T# t4 ~) rto this ExtINT delivery is routed to the external controller that is expected
1 r! r. ?+ }5 `; p7 o1 Jto supply the vector. A Delivery Mode of "ExtINT"
: D, h% {: h1 h& i) F* vrequires an edge5 K% I* c2 R _) d+ Y, T% R* B1 o
trigger mode.5 R$ f# t5 A% W, g |' E
| [7:0] Interrupt Vector (INTVEC)—R/W:
7 U' I9 `) i7 o' vThe vector field is an 8 bit field containing the interrupt
! z- d; |3 {4 c3 V% B4 r5 ivector for this interrupt. Vector values range from 10h to FEh.
& A0 k* s- ]2 w5 }% b+ u. N' x |
) y/ q1 y9 j1 }REFF:
/ ~' J. O6 t% E; P
% G" K* P6 ^" V/ A1 T1.6 R9 M, ^6 N/ N b! L9 h% j$ R
《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》0 h- b4 Q d- j8 p) l3 e- f# \# N. {/ Y
2.8 Z- }& r7 _7 [' E
《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》
& X" r' ~) ]* i7 C. I3.
1 ]. M \. _5 `2 H《Undocumented PC》# G8 g, P/ [& E. I! ?+ T. O H& L
4./ G2 k+ V9 \% m) D. \
; A+ l& }1 M- C7 i# |
8259A初始化编程% g% B; L0 n3 G) ?: e2 i
& W7 {, o. X9 P+ c
That’s all!
5 Z( `$ V/ J1 q# G7 L5 Q! w, j- M* B. @: x3 Y4 n1 x+ v
Peter$ O0 t6 b7 u1 }9 l+ p, S3 E
: X/ K7 o- a% D$ v4 d- I
2010/10/079 r! y0 t( o1 P8 k$ r- P* ?+ Y+ L
, M$ {5 _. p8 I[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|