|
PIC 、APIC(IOAPIC LAPIC) ' ]( V& A2 K* R$ j* ?
1. Overview
: r2 ~' v& R" W1 I% U8 e' ?" y B# F" p3 c) S0 x
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中
6 i& D0 F1 p5 q9 y% F) ?用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。; w/ N9 d- E w% F
/ v+ Y7 L8 Z5 R- b
, { R. I+ t! o* |, E2. PIC
# ?" {. l( z0 X
u) U3 |; e W: u2 f2 l, |# H1 M( D" i基于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。& m+ t6 v Y( _: y) \
: v& @8 w( G# v y
) n: K5 U1 @ a* ]8 y$ Q k+ p# [7 C$ l( {6 C
- b, z7 ?1 `" m4 f为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:
; T2 a1 _4 h* g6 O! H9 n; {/ |; i" Q8 p( U w
MOV1 ]* @$ V8 f% ?1 X
AL,00010001b
" K6 R9 M$ d$ b6 @7 f;级联,边沿触发,需要写ICW4
: j( r7 g( p! w& {8 D. i0 pOUT* o% x6 K6 a5 _; u, g
20H,AL
4 b# E) H0 c. w" `;写ICW1
& p3 O( _# I. ?MOV% |2 C( ?4 z! ^1 g2 t" ]5 H
AL,01000000B ;中断类型号40H
" i6 k" i( J5 `" q+ i- b0 n. r k# cOUT
" P. \0 l& H: D d' Z9 I" X21H,AL' O& V6 m, `( e) X" |
;写ICW2# {. o+ T9 ^- Q2 H/ G9 s
MOV' b' ~; I" h+ T# I, Q1 G
AL,00000100B;主片的IR2引脚从片0 |6 U; A0 s: ~) q9 I8 v) z
OUT/ ^2 P% a- I1 U1 j, L
21H,AL! q8 {. L/ ], s: n) `, U
;写ICW3
: J B) b' f5 w( r2 vMOV e/ L6 s0 g( Z H$ u- O; ~( z0 g
AL,00010001B;特殊完全嵌套,非缓冲,自动结束
+ g3 C4 b9 E) C) e& @& R. jOUT
3 F" z1 I, ]' N; \9 @8 [& h @21H,AL. W I! x& N0 s) g' c8 n+ t M( \
;写ICW4; H; k1 i7 V" j( ^
( m f" D! G. M' |, g4 N. M% y5 {
3. APIC& P9 g' S: y& _/ H. T! W9 ]
& J. O2 \) W3 `4 A7 q z' K: P
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,
0 N9 l9 I s2 W J3 M: l/ F: Y& D8 H每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。6 b1 G* u8 p+ v. f
6 e" u: Q6 T2 x8 X
7 u* b, B" U* ^/ Q" N) f1 g
1 m7 N+ F/ ?* y0 n
% @: u/ C( _" L9 U, k5 EProgrammable Redirection Table详细格式如下所示:; n$ p8 _# K. N% \
* L# {% N/ _" D
Bit Description:
& X6 t# |2 G0 C7 b( |! x( [ | [63:56] Destination Field—R/W.2 z# w! M7 L( I* g: `( |2 n
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits# K0 y! {6 b6 x0 y
| [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field2 R! B) a! ?. Q. e
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical Q L! a1 T8 L5 ?6 u
destination address.
5 u, ~' G( z+ FDestination Mode IOREDTBLx[11] Logical Destination Address
+ X r- S- T* r: Y' }- C; q9 p0, Physical Mode IOREDTBLx[59:56] = APIC ID' j7 g+ J( O# Q# ?5 O; k, l; a
1, Logical Mode IOREDTBLx[63:56] = Set of processors9 z, [ O* _+ U+ C
| [55:17] Reserved.82093AA (IOAPIC)
1 z& y2 Q8 ^2 j2 ` | [16]
4 `7 O6 R1 r W SInterrupt Mask—R/W.# u; x/ `% W9 U
When this bit is 1, the interrupt signal is masked. Edge-sensitive+ [" e3 S1 G2 T( p* ?2 a/ [
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
& N a8 |( E/ _5 t: V- N0 j1 cLevel-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no o$ @+ Y, E, C4 B
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
/ d* c A& _- c/ g7 R; ma local APIC has no effect on that interrupt. This behavior is identical to the case where the/ ^- V/ B5 u. i# m" l& W
device withdraws the interrupt before that interrupt is posted to the processor. It is software's. L& a; ~) u4 t9 j( D7 J/ U" }
responsibility to handle the case where the mask bit is set after the interrupt message has been
- F- }, }# T+ n% q+ K. baccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this( s: ?) a) E( }, U# x/ m
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
8 w& d% z0 L; |8 ?- ?. sresults in the delivery of the interrupt to the destination.
% s% M! f9 g+ ^/ E& U( ]0 Z | [15] Trigger Mode—R/W.) ?5 Q6 c) H8 E/ s
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
- e, ~8 _1 ~( n- f1 \# m | [14] Remote IRR—RO.( Z2 m3 }% N/ X) A P$ l q
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.
. u8 G9 y1 U/ M* b3 Z | [13] Interrupt Input Pin Polarity (INTPOL)—R/W.1 w6 R2 {: I% C: E1 e& E, V
This bit specifies the polarity of the interrupt8 T+ [3 a1 ]" A# s( b# q
signal. 0=High active, 1=Low active.% e' ?0 T P5 T% ^
| [12]
% v- }5 N! k1 ?& O$ N4 w/ MDelivery Status (DELIVS)—RO. ~+ z: c" e' o
The Delivery Status bit contains the current status of the l! g4 y3 P) T" ?. B! _
delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit
# V2 S# ?( A! D& Q0 H; _word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send0 y, \ J" x2 D8 y- q! }
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC9 k! m. W- X) C
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
- c8 |) _" Q) i& ~6 i+ s" k* \; { | [11] Destination Mode (DESTMOD)—R/W.: t5 }6 H( y W: K
This field determines the interpretation of the
4 g$ K# m" z* Q tDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.6 ]- Z! N# o) |: m
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.0 d9 y* L4 w" c$ o
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)
9 R# a( `- T+ Y# F0 B$ K$ \! r | [10:8]Delivery Mode (DELMOD)—R/W.
: \) C$ m* v( Q7 R% \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
8 E& U% d, } ]; C/ nDelivery Modes only operate as intended when used in conjunction with a specific trigger Mode.4 j; }, Y$ e' ?
These restrictions are indicated in the following table for each Delivery Mode.
1 ~- J1 ]7 ~2 N# CMode Description& h+ j/ M/ { T. x9 z0 ?$ h# [
000
0 u; ]) {0 H4 m$ o- bFixed Deliver the signal on the INTR signal of all processor cores listed in the$ G& R0 @+ d. M( K
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
: D! v8 v; b: _* f001
0 J& \- Y" M C; h6 MLowest" g" `. ~; ?' X% _
Priority Deliver the signal on the INTR signal of the processor core that is$ T! _, j( N$ e% r9 Q
executing at the lowest priority among all the processors listed in the8 o, F! S! g6 G! x: \2 `! d/ O
specified destination. Trigger Mode for "lowest priority". Delivery Mode! a7 E1 X. |' v5 e5 n; z
can be edge or level.
9 P2 R1 S+ ?# }+ l0 {010
: y8 k" w% C+ ?& N3 F/ vSMI System Management Interrupt. A delivery mode equal to SMI requires an
) e0 D; m$ \8 \6 d/ b% pedge trigger mode. The vector information is ignored but must be% s8 C. ~7 x3 x' w2 k
programmed to all zeroes for future compatibility.
$ {* ^1 Z& H, X3 ]; U& W011
/ X; G: @- x5 l' u# E# vReserved9 K% @# _% v; L+ p! v# y5 o* z
100
6 ~% H% C7 ]6 g5 w2 \& O) QNMI Deliver the signal on the NMI signal of all processor cores listed in the* u& d- c: d- Y' f3 c; S2 A X3 v
destination. Vector information is ignored. NMI is treated as an edge
5 t6 x j' Y! l8 I7 vtriggered interrupt, even if it is programmed as a level triggered interrupt.3 } V+ v. G1 J5 E2 l3 G
For proper operation, this redirection table entry must be programmed to
! r3 w; J( {3 u+ ~$ a" U“edge” triggered interrupt.
$ e3 V) f6 [/ s2 m101& P/ p% G0 t: H4 {! f1 g( C9 K2 {, K
INIT Deliver the signal to all processor cores listed in the destination by- M9 a9 A0 B+ A
asserting the INIT signal. All addressed local APICs will assume their
' ?3 [; z y& E/ xINIT state. INIT is always treated as an edge triggered interrupt, even if
7 m" f, ?. D; mprogrammed otherwise. For proper operation, this redirection table entry
) e" X9 U6 p/ u0 b" ~5 Emust be programmed to “edge” triggered interrupt.! T# `7 z; d0 B2 f+ S6 o. S
110" }+ |+ c$ a4 {0 m
Reserved
( l1 ~9 A+ x/ A8 r- Z111
: c3 f7 u* u# }) _ rExtINT Deliver the signal to the INTR signal of all processor cores listed in the* w6 L! i+ ]6 W% G
destination as an interrupt that originated in an externally connected2 L) a# z$ h. ]0 I: x
(8259A-compatible) interrupt controller. The INTA cycle that corresponds
% b- F8 H% q* d& Oto this ExtINT delivery is routed to the external controller that is expected
3 S' h" N g$ y, |to supply the vector. A Delivery Mode of "ExtINT"
+ f( S8 y: \) A3 |8 n$ F$ Srequires an edge+ u0 o% v; e+ l# X# K! y
trigger mode., W' r K- Q0 f, t; U
| [7:0] Interrupt Vector (INTVEC)—R/W:/ G! K& B3 F3 e0 M$ D c, Z
The vector field is an 8 bit field containing the interrupt0 ?; }7 g! O7 V1 b C
vector for this interrupt. Vector values range from 10h to FEh.
) T% _' I# h, L |
9 X; `) k. }5 _' {; b( I; YREFF:
/ V) m+ X, A0 E3 |# _" G2 V% [3 ?4 T
1., b% i1 |6 _6 r0 k2 b# D
《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》" m2 Q* _7 ?/ B! q7 P0 m
2.
9 |, d$ W+ I) ?) Q) U! P5 T1 a0 x% N《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》
l% w; D$ h) V6 J1 f- J3.
) r" j k% N* i! u% Q, ]; V0 Q( \# y《Undocumented PC》
) {3 S ?8 m7 d% s% }3 @+ @4.; {) z w- ` q ~$ F
' c1 H6 r( Y* n' Y a
8259A初始化编程
' \# E5 ^2 C# h: Y
D) t9 w9 Y. ^; \That’s all!+ M; k4 r# F- _, d# ~9 t6 A
% o' h2 V# d! z) g
Peter
2 K3 x8 Q5 [0 e5 i& K
% O- Z; j: ~ F2010/10/07
: `, W' ]" @! M4 t6 {% e+ g
5 N9 [) j" @; `9 e% f s[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|