|
|
|
PIC 、APIC(IOAPIC LAPIC) 5 [9 k( Y( k. F+ d
1. Overview, ^, ~ }1 i a& _' J3 V
) n; }! u: ]& Y# i/ T4 ?PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中
& F) z N, s" M& B7 L: C: O& X用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。
7 X- z0 O7 |2 V: J8 d! l- t# t; X' ]
$ h$ M6 H3 U. S u+ [
d3 s) F5 v- e/ P2. PIC
+ m9 N8 L( Y1 h# r6 g
% R' N! Q: o& g/ c% A/ 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。7 Q8 f2 i& N/ @% }3 g# r
* u: B7 A3 o+ f
* m% {, L; K5 Z" N! S. E6 [9 }! C( I. L' X
) K# h, Y. q9 e. C* H为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:9 ^5 b% S: S$ D5 p5 F* l- Q
/ b/ N8 b; T& ]2 AMOV
* o0 P i' {; ]3 p& T5 F! S7 L6 vAL,00010001b
, V3 P$ [! m5 L# X! @6 s+ m;级联,边沿触发,需要写ICW44 M8 L: V2 P9 K
OUT
4 y% p G% I {0 M! |6 ?20H,AL
1 ~6 f3 ]- k. x$ s. ~( K( ?;写ICW1$ Z* U9 H4 |5 u. \/ {: `' \
MOV
3 K# y C3 a$ d" K9 e; S ^AL,01000000B ;中断类型号40H+ ?* w- O) F7 n- M
OUT
! }2 T9 d! v: l+ A! A% r p) W21H,AL4 U" n) A }! d& q
;写ICW2& M1 V- E& ~, X( ~- c! t$ x$ i
MOV. [* V# O, ~5 H; G# J
AL,00000100B;主片的IR2引脚从片
# T9 P$ P8 Z1 o# R$ ~OUT
$ M3 T6 n& v3 d) v; _0 T! K21H,AL
- H; u( R( m: f, Q, M$ t% g, o;写ICW3
, [0 H7 J6 n T6 mMOV
6 p, M( d0 n0 ?# E/ b3 ?# F4 w! Z3 WAL,00010001B;特殊完全嵌套,非缓冲,自动结束" {) ?5 a) S8 q6 ?; O6 a$ j% x' U( y4 u
OUT( G% G: P5 ^4 ~" I
21H,AL! N. C, H! {7 @
;写ICW4" j" i0 u3 X8 S! ? V
9 l8 U1 J/ s7 W- f( B
3. APIC
9 e4 p/ i0 m* n5 `/ ~0 c: [3 F9 J
3 M8 C+ I5 O8 H7 D( q$ l3 YIntel 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,1 Q. f4 U u9 g) ?3 C$ S3 G
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。& ^0 n3 t$ n1 j# C2 }
, I* c* s3 ]2 q; a: h# z' V9 L
4 l& x% r( W" |% n! \* G
* Z9 ^5 y0 ^) @& _! m
4 {& x* z5 c% d! z6 F+ b2 a
Programmable Redirection Table详细格式如下所示:
8 N+ C7 ?. m Y' r* i& ^( ~1 f+ W8 N, f" G1 v, I9 r
Bit Description:# C) G: m6 B5 G2 d3 {: p+ E
| [63:56] Destination Field—R/W.
$ w* b: K8 e9 t) d$ B7 IIf the Destination Mode of this entry is Physical Mode (bit 11=0), bits% G( F0 |# `# \% L$ E: c# {! ~
| [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field
6 l' `: c" h2 H @4 Y2 e9 g0 Npotentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
+ ?; F' i) X) C+ ~2 bdestination address.
( E; L# d# `" M0 I9 B1 {$ Q: u$ \Destination Mode IOREDTBLx[11] Logical Destination Address5 M' a% U$ T W! g+ R# N: t
0, Physical Mode IOREDTBLx[59:56] = APIC ID
$ R% V, {+ F- M h. [( Z4 ?1, Logical Mode IOREDTBLx[63:56] = Set of processors
4 ^7 T" [1 C o | [55:17] Reserved.82093AA (IOAPIC)
% h# R' ~ F) s8 T7 Q! | | [16]7 j: t4 w% W) _6 x
Interrupt Mask—R/W.7 H. T( ]* U( i& I$ m& }3 l6 P' G5 N
When this bit is 1, the interrupt signal is masked. Edge-sensitive
* D8 ]; {* M7 r$ S7 yinterrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
1 \# P& y5 C" T: a0 s; p7 BLevel-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no( E: f" k* L5 c9 p7 s; r# N
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
( W K4 |2 M2 ~ Ua local APIC has no effect on that interrupt. This behavior is identical to the case where the) E- B+ a, c; i8 K1 }
device withdraws the interrupt before that interrupt is posted to the processor. It is software's9 }1 R# i# A, z$ u) O
responsibility to handle the case where the mask bit is set after the interrupt message has been
0 n3 M4 A! ~2 s7 maccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this) D0 u# x7 D* n/ k, b: E* V
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
) b4 B9 \2 ?$ q5 C8 n3 Wresults in the delivery of the interrupt to the destination.
, b" N. [* F% }- ? @8 x/ ^ | [15] Trigger Mode—R/W.2 `; p' i3 z! J: z7 Z" N
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.# K9 z& n; s: p. j( V
| [14] Remote IRR—RO.
" a3 r& y! t, g6 v4 K/ \6 WThis 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.
1 u0 e; y5 P( [# R' o/ Q+ R | [13] Interrupt Input Pin Polarity (INTPOL)—R/W.
; \% \% e/ F. Q% C" ?* |1 e; U$ [This bit specifies the polarity of the interrupt8 O, n" E4 q/ ^% O
signal. 0=High active, 1=Low active.6 X; V% s4 b0 v
| [12]
9 Y9 E4 X9 Y M3 A" n xDelivery Status (DELIVS)—RO.
( }5 _7 K0 @' u! YThe Delivery Status bit contains the current status of the
T5 { Q# G/ N- ldelivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit: ]0 {* D" u- E$ ^+ U
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send. h9 O' v2 h, ?+ t
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
; I3 z/ Z/ a' q& q R7 t: ^bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
+ C% u: A: G3 Q- @( [' A | [11] Destination Mode (DESTMOD)—R/W.
8 \% @2 ~$ d2 S. S3 K1 AThis field determines the interpretation of the! p7 f) ?1 {6 Y% n+ T7 p2 A+ E
Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.. R3 P5 G8 h7 t7 V% v8 [5 a
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.. E6 F# }1 j N1 s( L5 C7 Y, Z, R
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)% b7 j1 l, V! m' ~9 Z8 A
| [10:8]Delivery Mode (DELMOD)—R/W.; n" F* M: s% U: S h: U6 h
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
, s+ y- g, L8 L+ j( I2 G- S0 HDelivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
& b/ [* J: q% N% E1 q) C# U dThese restrictions are indicated in the following table for each Delivery Mode.3 O: g. ]4 v& C. A( \
Mode Description
* R" T0 _, _1 m, J$ P$ m000
8 I$ Q. P( N# F: \# uFixed Deliver the signal on the INTR signal of all processor cores listed in the2 c7 E% C" y( e O' d" E
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.3 |# z$ E2 W8 u
0011 v/ _1 W9 u) w/ _
Lowest7 v6 F* P( J" a- F8 v
Priority Deliver the signal on the INTR signal of the processor core that is
# a# S2 H9 s2 u3 Z4 I0 U+ aexecuting at the lowest priority among all the processors listed in the+ A( m1 x5 t! U6 M# n& |
specified destination. Trigger Mode for "lowest priority". Delivery Mode
7 q, {5 C; A# _* ?2 f; y9 hcan be edge or level.
! A) c* J$ p( U' g* I' _! f010' j" d! a0 x0 d, v- r( D
SMI System Management Interrupt. A delivery mode equal to SMI requires an* {' ?3 I! N- C( A, _3 {
edge trigger mode. The vector information is ignored but must be
: D5 W z, v/ d) mprogrammed to all zeroes for future compatibility.
5 @( b' X3 h( i# g* [0 {011
% W; v& z* o& J0 @Reserved: f4 c$ j" O/ p# _( r/ ]: L
100
. u3 n2 B# a6 ~NMI Deliver the signal on the NMI signal of all processor cores listed in the
+ x; S# ?6 v( ]$ Ldestination. Vector information is ignored. NMI is treated as an edge2 }8 Q( B3 V8 O; t9 T2 n* F% ^$ ^
triggered interrupt, even if it is programmed as a level triggered interrupt.( k, f# p4 m D* ~6 Q4 N3 }
For proper operation, this redirection table entry must be programmed to& f) O8 C# C# u/ {/ _
“edge” triggered interrupt.& L: a0 a5 U4 [. d, r2 T; |* w
101: f1 V! o! l7 n2 n0 b: b
INIT Deliver the signal to all processor cores listed in the destination by
( T" V8 O* X0 @7 p" v/ J& Jasserting the INIT signal. All addressed local APICs will assume their
8 `* M" p. l' M7 O7 L7 O7 ]INIT state. INIT is always treated as an edge triggered interrupt, even if
/ R2 z" ]) z7 `: Pprogrammed otherwise. For proper operation, this redirection table entry6 ^; Q7 @- Q! o% K! _1 C
must be programmed to “edge” triggered interrupt.0 y, W* h+ e6 `% \2 u
110
* K5 e6 h9 I; DReserved2 T. ~5 j# ?" V1 c$ S
111
% O! |4 e( B8 n; K3 }, BExtINT Deliver the signal to the INTR signal of all processor cores listed in the
l6 t0 q" _. |% M: xdestination as an interrupt that originated in an externally connected& L' N& S! V9 L, {
(8259A-compatible) interrupt controller. The INTA cycle that corresponds. h' w8 v$ D* [6 `
to this ExtINT delivery is routed to the external controller that is expected. }6 W! u3 w6 M9 W
to supply the vector. A Delivery Mode of "ExtINT"
( u, ^3 L; i- j8 A1 U' Lrequires an edge
8 E: H, i0 u, strigger mode.
# @" u& n7 i- x. i8 K | [7:0] Interrupt Vector (INTVEC)—R/W:, A2 C4 a" B+ ~" f$ C0 l/ X
The vector field is an 8 bit field containing the interrupt
, v: n/ \& o$ _* E; }( `" [vector for this interrupt. Vector values range from 10h to FEh.
: }1 z3 G5 ~5 a4 B |
: ] Z; n1 p& @ v' T. \REFF:
8 |0 A! d# B/ B! ?0 a& B) S0 q3 M' N U, Y- C z' f- l+ g/ j5 f( B
1.
9 R( I) p7 m+ o3 e' l' q《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》# O2 \6 f- }+ s% l1 S: Y1 j
2.! D0 e$ G) a6 u. {8 i! a g( ?3 a
《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》
( S3 F1 N) y j I3.) B/ c2 V3 L$ a/ ?( K7 f
《Undocumented PC》5 |/ @3 c) Z' G
4.
) d# f. F1 g I: u# Z( X% b1 L; r; Y! m$ B O( i
8259A初始化编程
0 q" |5 h0 U5 f; g+ R* M! N1 F' y
& C, ^* Q& i. U1 G+ v8 V1 wThat’s all!! s9 y) b" W3 \6 |+ |! k
; e, o, y' }) x9 i7 o% u4 q9 e% ]/ APeter8 k9 P2 W: l ` {) I L, Y: W
" z. N1 L: p! a2 d0 u2010/10/07
! y. e$ O2 y5 }( S: E% J3 Y( ~) V7 ?4 h9 z
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|