|
|
|
PIC 、APIC(IOAPIC LAPIC)
[" H# ]. w% t- l% L3 V) [1. Overview8 @$ k n8 j3 o8 K$ U) h
! M! T! O3 r wPIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中9 H+ U1 i+ p) E
用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。
: j% ^ F- o( ?6 C3 {9 r% h* S9 D3 M( _1 B R. M# R9 I2 o
& s [; f, a" e' |* X! ~2. PIC
) K3 B0 ~% r2 m7 }0 x4 e7 T7 [( _6 Z0 q( \% t- S3 w- B
基于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。, T) a/ @) }" \* [
$ X) x2 i5 i% a7 P, p) w% [
; O0 h8 K" W0 v0 k) ?7 _
! R' Q1 s+ ]3 ]
; `* T: @) u& O/ }" X为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:- N7 [, j* ~& v) K9 v% [% n9 x
( x. I4 T' n+ ?0 y% n- ~/ |6 oMOV
; N" \# {5 `8 \3 q f7 wAL,00010001b2 @1 ?2 I1 I+ S5 l% q
;级联,边沿触发,需要写ICW4
# R5 Z( t/ e3 ~$ wOUT5 H+ c- @+ G' b( t
20H,AL
t. o9 P6 w; w, B, m;写ICW1: ~7 E( t+ @% X. L
MOV& G3 d$ b# n8 x$ w
AL,01000000B ;中断类型号40H4 u& {+ z4 K0 E- T
OUT
) q8 V# p- ?/ f9 X W7 r21H,AL
( T4 {, u: Z% E0 r% P' |;写ICW2* J" R4 a A! G! I, L. R" b
MOV
! [+ p8 F! y/ R; ]% J9 f3 JAL,00000100B;主片的IR2引脚从片
: s, d& }; Y6 F, w0 NOUT5 Z' r2 I# g3 I* @, W% `
21H,AL7 A2 G( |, r# I
;写ICW3
" k" H. f( C- }/ v& LMOV0 O' ?* q$ N7 L+ H7 S. G
AL,00010001B;特殊完全嵌套,非缓冲,自动结束
3 P$ {' y/ O j. I: A3 SOUT9 m9 K- P. r- y" K" [8 h' x
21H,AL
, k/ P& c1 L: {" n6 B5 A;写ICW4! Q# ~) @+ l$ I v4 L( t3 C
" Y; Z; }6 K4 p' X0 h
3. APIC
' s) D! t) Z# S5 O/ s
% O$ t1 W7 ^) y' I* [/ q0 o' dIntel 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,& a8 R- K3 I; ^. Z$ k
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
' B9 w9 |3 y2 h3 s7 S3 ]- P. _: W) y
, X4 Y2 r9 u* {+ `9 u4 |
/ ]! E+ q. t1 s' C
' R. w+ t! x8 `1 f1 N0 j
Programmable Redirection Table详细格式如下所示:8 K+ [+ V5 d1 W9 R: [
* L/ k. T) D& {# U' F% b6 _
Bit Description:
3 Y$ f! D/ }% L. x7 M( R | [63:56] Destination Field—R/W.
6 w4 N& Q) z p% H7 X# fIf the Destination Mode of this entry is Physical Mode (bit 11=0), bits
) i; W9 F+ G, _ | [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field
% U) c. A2 e4 }1 D+ Gpotentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical9 r3 h) j" T9 E" U
destination address.
$ S8 Z3 U5 {" tDestination Mode IOREDTBLx[11] Logical Destination Address& E/ l! [/ m$ ^9 E
0, Physical Mode IOREDTBLx[59:56] = APIC ID6 A3 L U) V/ h, f# b5 n
1, Logical Mode IOREDTBLx[63:56] = Set of processors
w" n" n2 y E3 J. Y( ^# Q. l# _( _ | [55:17] Reserved.82093AA (IOAPIC)
* D/ d; m) c4 t- z | [16]$ b- r: w4 l/ E' T- N9 }1 {
Interrupt Mask—R/W.6 o; \% K8 n! a
When this bit is 1, the interrupt signal is masked. Edge-sensitive
! I; Q0 P% t2 Jinterrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
. a4 b8 D% R+ Z" g `0 nLevel-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
+ F, k5 i) B9 r+ Wside effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
; V) X0 M3 M$ J$ ya local APIC has no effect on that interrupt. This behavior is identical to the case where the1 d6 j# b" v: T) c! J( f5 G) D
device withdraws the interrupt before that interrupt is posted to the processor. It is software's: y% z$ ?& n. L: F9 L
responsibility to handle the case where the mask bit is set after the interrupt message has been
8 p* V/ N6 o; Z/ E# raccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this
8 w8 U+ h& I7 E3 b' m: _$ y1 ~bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
, L5 U1 L/ Y5 a% J7 Jresults in the delivery of the interrupt to the destination.
* f- r8 T8 ~2 _7 I& e- g0 D | [15] Trigger Mode—R/W.0 x9 P5 g8 x# A/ B1 H
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.. D. a, t# A: n6 d9 d: a
| [14] Remote IRR—RO.6 Q. r% |/ s3 N2 I. \8 ]
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.
+ u7 ?4 L* W) c, O- V | [13] Interrupt Input Pin Polarity (INTPOL)—R/W." z* |. c# J) ^# U, G1 Y
This bit specifies the polarity of the interrupt; Z1 Y6 I0 L$ [+ O6 m' h- @" r
signal. 0=High active, 1=Low active.8 m; P; J. N) i4 r# K
| [12]& ~4 D8 o5 W, S+ c: }/ W3 `
Delivery Status (DELIVS)—RO.
# {, K* q. [$ T5 T9 iThe Delivery Status bit contains the current status of the
4 T7 a0 z/ V6 O, ~* Kdelivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit
6 K6 p* J" J& p) G6 \word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
8 u) A: K7 y$ q- c, f WPending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
7 ^5 Z" J& I9 w4 A! Dbus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
+ z P' b! |2 [$ e8 { | [11] Destination Mode (DESTMOD)—R/W.
" N' P b3 s5 D' F, T+ ]; r4 sThis field determines the interpretation of the
; D7 h+ q# Y# Z! Q' ]* U8 M; dDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
1 a* c- G) z" e @% N: XBits 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.
! g" h; q# u+ i! FDestination Mode IOREDTBLx[11] Logical Destination Address 0, Physical Mode IOREDTBLx[59:56] = APIC ID1, Logical Mode IOREDTBLx[63:56] = Set of processorsE 82093AA (IOAPIC)' C$ C# L! h1 e" l5 r- A7 T
| [10:8]Delivery Mode (DELMOD)—R/W.
, H$ m" G& Z$ v, uThe 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
/ m! {) k6 S1 |$ P& SDelivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
8 n( t+ D4 r, E9 ^% P4 z2 u- T0 fThese restrictions are indicated in the following table for each Delivery Mode.
6 K5 d h- R. w8 e7 f2 T ZMode Description
5 T+ P2 ?) K' ?7 D7 c000
4 d$ K$ v0 I" J @4 b8 WFixed Deliver the signal on the INTR signal of all processor cores listed in the' C5 q9 ]0 L# A
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.: a0 v- x( Z7 l1 a5 c
0014 y- x6 o% T8 o- K( a+ Z4 l
Lowest
8 g3 c) h- R. w$ [, g6 a- DPriority Deliver the signal on the INTR signal of the processor core that is6 {. ?) B% G! T0 B8 R
executing at the lowest priority among all the processors listed in the
# E( }5 f0 u" }specified destination. Trigger Mode for "lowest priority". Delivery Mode
8 g5 R8 x. k2 J% Y3 tcan be edge or level. C: a7 ^9 Z; M
010
- }: P8 c3 f U/ F# f* _1 Z: @1 [SMI System Management Interrupt. A delivery mode equal to SMI requires an
4 A z. t K9 l6 }- [/ iedge trigger mode. The vector information is ignored but must be: e: C- H; {# K% d* C0 V
programmed to all zeroes for future compatibility.; B. P' w4 I' ?: c4 }6 o
0114 i. M. X2 T: R. ~
Reserved
6 ?1 K& V f3 o100, H" o/ |* _* I/ N" W
NMI Deliver the signal on the NMI signal of all processor cores listed in the* \5 m8 g/ @$ L4 j3 |
destination. Vector information is ignored. NMI is treated as an edge
- ~% H3 ~) q4 Ftriggered interrupt, even if it is programmed as a level triggered interrupt.
. j4 B0 m! w+ RFor proper operation, this redirection table entry must be programmed to2 E( S2 ]5 ~2 N+ x* C" _, s
“edge” triggered interrupt.
- v$ r, ] u* C101% k9 ]7 S+ u! k P
INIT Deliver the signal to all processor cores listed in the destination by! G* o/ S$ ?: f. ?) S
asserting the INIT signal. All addressed local APICs will assume their5 [" N: d& g) Z: I' s% }
INIT state. INIT is always treated as an edge triggered interrupt, even if- _" M: o2 @+ W0 \
programmed otherwise. For proper operation, this redirection table entry
' u9 f/ Y& {' V2 F; k/ A) Hmust be programmed to “edge” triggered interrupt.
7 u3 w- H% v; s/ t7 c; b' t1108 t% |4 U2 a$ {8 ]# ?+ I, ^' I
Reserved
" H+ g+ u+ S4 q8 b3 h' t1114 E% k Y* f/ t9 y' D
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the
( P5 G% d0 z$ @* o1 g& zdestination as an interrupt that originated in an externally connected
& o: w0 d& s+ e! {$ ^(8259A-compatible) interrupt controller. The INTA cycle that corresponds
% }8 s% x L( u- d, ]to this ExtINT delivery is routed to the external controller that is expected
1 J' D: ]! m! Z7 w& y* z/ r. ^2 U0 `5 tto supply the vector. A Delivery Mode of "ExtINT"1 p. o8 u, Y' Z# K+ _- Q" {
requires an edge7 a. \8 o! x8 p$ B
trigger mode.
0 W8 Q0 F' F3 e, W | [7:0] Interrupt Vector (INTVEC)—R/W:
+ c2 H. I5 Y; x( {. q2 VThe vector field is an 8 bit field containing the interrupt3 _! Y6 l( b! U$ h2 ~
vector for this interrupt. Vector values range from 10h to FEh.) S0 i m" H- e$ D+ `& F
|
3 O/ Z2 d" {; e( lREFF:
# j/ E7 J$ ~ q! \5 Z* l5 [4 ^: p) g) J8 k* |7 a, s- h$ a4 I
1.! X5 P) E& T4 ?
《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》. m# a0 _: K. E/ g+ i+ E+ v1 u& a
2.: s2 S9 T- p1 H
《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》
$ f' _& `2 h" k3 B! E7 L$ g3.% e+ h7 s! s) B0 ?7 L( r* P
《Undocumented PC》
# ?% }9 m! j$ U$ s; p! z4.! ^+ [8 X! H2 |. K
$ @- }: ^* }2 d8259A初始化编程
, m( r% }' o9 O6 l W$ Z& m$ R, @$ ~6 w! o: C+ `4 j7 T
That’s all!3 Y" U( @) `3 p2 J" l
) n, t6 c* n* m. T
Peter
& b7 r% o O. ]$ d3 a2 [8 s, T; Y+ ]! K3 C }; q; V
2010/10/07
1 q$ z" X' n" A8 y% P
n( H, q* R% h6 a9 v& u[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|