|
|
|
PIC 、APIC(IOAPIC LAPIC) ' W5 d1 f3 V) B, T6 l p, p
1. Overview
M% Q q# G! [
; c; m% c, K& [' Q' EPIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中
% S! E# H- ~/ | t用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。
) G. a2 K5 X- h3 ^; T4 z: R' r% F/ L3 _. r% W8 i* F; A
% l6 O! {/ g! ]2 h5 |! ]2. PIC8 K* g; A; \8 h) `! F
: ~9 r( F4 d+ U+ T4 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。5 p. {' e' c2 A) u. m7 V# }4 v x
$ m. v# @$ ]& T t0 t4 }
# k5 _3 R) j& N6 [* J; F) B2 v3 W
+ [) w# l8 F9 {; |+ m6 i# X
# U" F# q* F8 k \, o {为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:
. o6 U1 i! q- X8 P7 V' ~6 p( E3 }; I! g$ m( R; o
MOV. Y# K9 k0 I- \1 u2 `0 H% ^
AL,00010001b' s2 Z+ ?* j K1 n
;级联,边沿触发,需要写ICW4
6 |4 ]; L: Y' ]OUT
% n: @! k3 g( a" E# S$ r20H,AL/ c/ k- ]0 r9 w5 H" C6 v: ? D
;写ICW1
& a* a# y8 H/ S1 UMOV1 Z5 e! ~# K7 K$ [) z% L
AL,01000000B ;中断类型号40H2 m" I- q3 W$ P6 ^; U, k
OUT5 [1 P2 |9 T" y s. |9 X
21H,AL
6 t0 }' z/ A9 G+ I* i;写ICW2- r+ ^. X- z( C2 A* R+ i. H
MOV
/ o# E( y" z2 k7 XAL,00000100B;主片的IR2引脚从片
1 G% y- B& G4 y B. ROUT
. ^5 l) \' ^; U3 q. I7 M5 H% P2 |21H,AL" W5 i& G5 u$ V% X f6 n
;写ICW3
% [+ h) j4 M/ K7 `, VMOV
! y7 Y6 T7 ~9 O) L! tAL,00010001B;特殊完全嵌套,非缓冲,自动结束2 N5 [% r) R0 r3 s) ]6 J" P
OUT
+ e; D: X- u4 @8 U1 a; J4 t& c21H,AL; }5 t0 D! @9 N& \
;写ICW4
9 F0 \/ c9 T5 t& i( _! b& N1 k( b- e+ O* P0 e& V0 c, U
3. APIC3 M r: c( G9 P7 m
9 \+ t, [2 P! s8 G! j- G
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,& \# k& c. _! @. y/ @* F
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。( r. ]) _0 [7 r" D7 ]# w
, Y# X R3 }4 s" B9 {
+ W- z6 z* M$ I0 ]& c* Q4 r+ t
: B n( e2 A/ \
D# f% `7 r+ Y# c! w7 `
Programmable Redirection Table详细格式如下所示:/ V$ A! D, I' z# J& F0 T
. z+ q" s( i( \5 t$ n2 M; \Bit Description:: q4 z+ y# C& C1 W2 v
| [63:56] Destination Field—R/W.
$ Z7 l2 x3 t! G* Y; y+ Q+ dIf the Destination Mode of this entry is Physical Mode (bit 11=0), bits
* P! D, X# b+ e) o( m | [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field8 r, _1 q; l: w0 `2 R0 t9 Q
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical$ e+ N# c& Y1 e+ T, _
destination address.
& D% {8 S" h; s) A8 ODestination Mode IOREDTBLx[11] Logical Destination Address
2 l+ c( u: Z# w' v, E6 i0, Physical Mode IOREDTBLx[59:56] = APIC ID
' V3 {7 _6 b$ u0 E+ E1, Logical Mode IOREDTBLx[63:56] = Set of processors! M5 E) p1 ]2 [5 c& l
| [55:17] Reserved.82093AA (IOAPIC)
8 ^/ t& p1 }- S/ ~ | [16]8 M4 q l% o/ Y. m( S* t6 [/ ^) h
Interrupt Mask—R/W.) E2 S t; a8 ^0 _7 T
When this bit is 1, the interrupt signal is masked. Edge-sensitive/ d7 m. q! a# L+ r, i' B
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
% c1 `: k5 Y& c, U B1 U1 `Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no0 o8 t2 O- c4 s: t; o( b
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by$ I: I$ f6 ?4 E7 p9 I
a local APIC has no effect on that interrupt. This behavior is identical to the case where the) v, Q% e: u C: g# ?9 Z
device withdraws the interrupt before that interrupt is posted to the processor. It is software's
& C! l* H' N0 aresponsibility to handle the case where the mask bit is set after the interrupt message has been0 Z; ?+ p M% h) c7 w
accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this1 A0 v# @$ A$ A4 {
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
% N \: F7 g' Iresults in the delivery of the interrupt to the destination.; |, c: \5 H; S# I
| [15] Trigger Mode—R/W.
, _9 G3 ~9 {% ?The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.+ y6 z. K2 ^0 y; F j7 S4 F$ Y
| [14] Remote IRR—RO.
# V8 u* u. F; j/ d( b; dThis 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.
" }. Q" N7 W9 f2 W& y1 |- W | [13] Interrupt Input Pin Polarity (INTPOL)—R/W.
: G& u+ R8 a% u/ F+ f4 g0 X, }9 OThis bit specifies the polarity of the interrupt
0 e0 j s* U! E) h! T5 u9 `1 ?signal. 0=High active, 1=Low active.4 j1 r2 q$ Z+ T0 m* q8 X
| [12]
$ w3 r. G- b8 t. TDelivery Status (DELIVS)—RO.
9 `' T0 z: ^# H6 b* \The Delivery Status bit contains the current status of the
! |7 m8 r# o0 z6 y- p% Edelivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit" s8 _' O$ l) {5 [1 n( i
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send% p+ p" u! S$ H4 w; H5 n6 h$ t
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
$ b. K3 [* t7 f+ zbus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
/ ^6 [7 W5 E& G! l: _ | [11] Destination Mode (DESTMOD)—R/W.
" R* D& l0 I) y, z8 i- zThis field determines the interpretation of the
4 N" l; _) g6 o9 nDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.5 L- M x" ?1 @! w! Y
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.2 O6 Y2 f( W; V S( w
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)/ {5 Z5 {$ z- O6 q* r
| [10:8]Delivery Mode (DELMOD)—R/W.$ J( U0 v, G" `6 h9 `2 o& j
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 K$ p" l# |9 A1 ^; M
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.- y% ]1 _7 R/ r9 u
These restrictions are indicated in the following table for each Delivery Mode.
$ _8 k! J# U. Q( y! X) P" Z7 B4 H8 zMode Description0 I) j; w8 I8 _* E- A0 C- o
000% o8 D; R- d( r' ^( M8 X t/ y9 M
Fixed Deliver the signal on the INTR signal of all processor cores listed in the3 x7 D% g" w/ l9 `! F
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
* H. @1 i n& f001
$ U; ]$ y6 K3 K8 q1 XLowest
% k( s* v9 D. j, f+ ?Priority Deliver the signal on the INTR signal of the processor core that is
7 W( [) P0 z2 y- aexecuting at the lowest priority among all the processors listed in the
2 X- n, _* N% b5 H/ Zspecified destination. Trigger Mode for "lowest priority". Delivery Mode+ x+ g" B6 G8 }: x
can be edge or level.7 T+ x- V" @# }; V! F
010. o2 O* D& R4 o1 K6 R" O
SMI System Management Interrupt. A delivery mode equal to SMI requires an
1 w f2 l- _* K& h2 Y& xedge trigger mode. The vector information is ignored but must be* E7 D% v; P5 N; B8 h1 R0 {
programmed to all zeroes for future compatibility.5 E2 A7 r7 y1 F( E- K* `- ]$ `8 X
011
! _9 b E( _5 gReserved
3 e& z) \* U* J8 Q& \' w1 j6 s100: R. L0 i7 w2 ^8 d
NMI Deliver the signal on the NMI signal of all processor cores listed in the6 K, O/ Q* [3 W, d" g. V. y
destination. Vector information is ignored. NMI is treated as an edge4 |# U. R9 A& y- R
triggered interrupt, even if it is programmed as a level triggered interrupt.
: c, n9 _3 ~0 t0 I) JFor proper operation, this redirection table entry must be programmed to
- M8 M/ f( R9 b1 J7 r“edge” triggered interrupt.
+ L* U; d6 U2 f1014 d' j) t+ u/ `4 M2 v% f4 C
INIT Deliver the signal to all processor cores listed in the destination by
; f5 t* D8 ]4 X7 H" Oasserting the INIT signal. All addressed local APICs will assume their y' S, F0 H& o+ W
INIT state. INIT is always treated as an edge triggered interrupt, even if& \/ J. K- k: {% X9 ~0 x/ Z0 g# C S+ g
programmed otherwise. For proper operation, this redirection table entry
- {) |$ C% }1 h; P/ y' emust be programmed to “edge” triggered interrupt.
. V& K ^5 n/ y/ d7 p# e! h6 I9 a8 J1105 [7 Z% z7 R" ^9 t7 j! o0 I
Reserved
- V4 Y1 o T6 N% B4 D% y111
0 H# d& R( i0 E& h# S- p, {' F# o2 kExtINT Deliver the signal to the INTR signal of all processor cores listed in the3 [3 O: R$ j3 Z
destination as an interrupt that originated in an externally connected
) @6 A5 u( m$ R' `) H(8259A-compatible) interrupt controller. The INTA cycle that corresponds
; ] S8 i) U) R; rto this ExtINT delivery is routed to the external controller that is expected; o+ V& a- i0 k2 N* |6 t6 y+ x8 M
to supply the vector. A Delivery Mode of "ExtINT"
. N' E4 _, K& `) A8 L6 d% Krequires an edge' O5 ^: a/ X2 `4 w0 i
trigger mode. @& _1 o% i' [* r7 B1 R
| [7:0] Interrupt Vector (INTVEC)—R/W:5 f) r Q: D1 @# }# {; z8 A
The vector field is an 8 bit field containing the interrupt& z! k d$ B. q6 S7 y
vector for this interrupt. Vector values range from 10h to FEh.+ }; Z! S, G' b/ r' ^
| 8 w: }9 ^. J; t! E. L. I
REFF:
2 r4 R3 q5 T3 G) `
+ d' ~2 F! A+ d' l+ }1.9 v1 R1 X- o Q5 y( y7 N
《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》6 J- A# p3 s, Q- Q7 Z4 P' X
2.
% v. @4 M5 K8 q# G《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》
; B$ j+ W7 x# ], z p1 E3.
/ [ i t* V& M" Q8 P《Undocumented PC》
$ ?7 k. Y' \' `! r! N+ U8 i- E4.1 h$ v, t) z7 m9 F
9 {& z" e' `7 h6 q" W8259A初始化编程0 }. n& L7 ~. n) k
, T0 s$ \3 [3 z; d+ \% a" M
That’s all!
9 y4 i# M5 S" B7 A
3 D# A- i# A9 |7 r0 a2 W8 fPeter( m& {2 I2 V; z+ v
8 E: X. Z# B. K* G0 z2010/10/07
* s7 B% @8 k0 _! O0 Z! {3 V: d6 {" ~" T
+ r8 P! x S! p h1 j[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|