|
|
|
PIC 、APIC(IOAPIC LAPIC) . N9 D5 b, |, l6 x# W# g% x
1. Overview# r9 k. g. l* t9 _! b
P$ d- R3 I* A' `
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中
3 Q M2 I% `- _" v用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。: C' S8 V: {+ P6 Z3 z
/ h$ N4 O% o. G% y0 P0 N6 ~7 d9 M' P) r% a
2. PIC
1 |6 f( Q7 o3 k8 l: g
+ G* `' K* Q6 Z# E" Y/ o基于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。
4 M- m1 [. p) D$ m: ]# p1 l9 p0 D, L9 S6 K0 q) x8 V
" ~2 L# S6 N( s% @( p K
( E. v; L3 `: f2 m$ y/ L# K, m1 H. y% S' I2 R3 D* j! s
为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code: `* n2 k( v" `$ o- k9 Y% A! N
7 _: p, t3 s0 _0 M: y$ ~MOV
) C$ W: J( D7 @! D. n3 RAL,00010001b% i, v% h: }: N3 {- Y) a
;级联,边沿触发,需要写ICW4
( B+ Y1 Y" A7 }0 d3 q4 ?: L: ZOUT
! E7 e( P, T* f4 U) L. l20H,AL+ }" ^% d8 c0 e
;写ICW13 [2 a6 Y( A4 V1 b
MOV
, [7 [+ |1 u! D% u% EAL,01000000B ;中断类型号40H
4 U* r9 |4 F4 J, z' ^9 \OUT& d" f7 h0 h1 {8 t q/ `
21H,AL
% i- x" H0 \8 m/ b. H7 r;写ICW2, F- t, X$ J4 J" l# e$ S
MOV- u4 [" G) N' |$ D+ ?
AL,00000100B;主片的IR2引脚从片5 b5 ]$ W h6 ^) c% G+ j9 J$ i
OUT
. f# i) ^" S( p' y21H,AL
; ^% O' u# D6 g8 d3 E;写ICW3
0 [- w- b, }3 K, R1 e% YMOV
Q" a7 X4 `9 V' S; i- P IAL,00010001B;特殊完全嵌套,非缓冲,自动结束
& N& k5 u8 M; v2 Q: I$ g. k! t; j# oOUT
" d8 [7 |4 Y: Z& v5 n% m2 |' `$ o, N/ W21H,AL! d- P( x/ u3 P# k
;写ICW47 E. ]9 H& h, d1 u
. \1 `% {5 O' V2 c' c0 c7 @3. APIC6 Q- k0 S) x' k0 J5 B
: l6 r. q2 W# ~1 _7 E
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,2 Y) \* D7 o+ _2 x$ p
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。1 H* k/ h! L/ Z, K7 w1 ~, L
, R' r/ H/ H8 r* S
9 o3 Q4 {, j, [/ ^
) [8 b* e& {/ L0 Q+ ^6 F& W$ k! x" J( }$ E9 t8 }
Programmable Redirection Table详细格式如下所示:
# L) y8 H( f; @; G: U8 o2 X, r5 B+ V& e
Bit Description:
/ R5 C. ^4 [8 h3 T | [63:56] Destination Field—R/W.( U0 G0 I, M: e# I
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits) U3 A1 z; J/ _' C' Q9 Y
| [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field5 Y% u! Z" y% h3 M/ E7 C
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
! ?# U: J/ v/ B; r5 C6 @destination address.; L+ F# F8 p) n! F; \
Destination Mode IOREDTBLx[11] Logical Destination Address
+ n1 o3 @! z h. q0 b- Z. b0, Physical Mode IOREDTBLx[59:56] = APIC ID! v- b7 o1 s% ?; p& k
1, Logical Mode IOREDTBLx[63:56] = Set of processors& G v# S6 m& |' f E! W
| [55:17] Reserved.82093AA (IOAPIC) & I4 j+ ^8 j3 h( t
| [16]
" B4 s* Y8 Q I/ o: M9 fInterrupt Mask—R/W.
) G4 L |* M9 G( A0 R7 I7 f3 OWhen this bit is 1, the interrupt signal is masked. Edge-sensitive# U0 D2 j# `7 U, {8 D. Q
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).: _! O9 k7 z1 `5 g7 L
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
2 P% ]: i: }" lside effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
: z: T& L+ ^1 Z! U5 Na local APIC has no effect on that interrupt. This behavior is identical to the case where the0 P# `! h& s5 f' u) M* p
device withdraws the interrupt before that interrupt is posted to the processor. It is software's+ Z. i# `6 y* K* s3 a/ C7 X+ ~9 v
responsibility to handle the case where the mask bit is set after the interrupt message has been, |% a( F- f. p$ B" J( }! l
accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this
$ B: Z0 j" S" }' ybit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
- g8 z5 X7 i& O8 d/ |& H' bresults in the delivery of the interrupt to the destination.
+ @. g7 c- H# Z! C1 r | [15] Trigger Mode—R/W.4 K) Y. `$ O6 }$ n' o [: E
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
2 ~) W9 `1 v& B; u1 F' x1 A$ z | [14] Remote IRR—RO.7 E% ~. b3 h$ ?
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.
. {! C5 Y! B+ P) h" V6 {! k) l+ Y! T | [13] Interrupt Input Pin Polarity (INTPOL)—R/W.% y" ~" R0 E; `6 `( R( W
This bit specifies the polarity of the interrupt& @4 {$ n' X' V* z/ V! f5 O
signal. 0=High active, 1=Low active.
" \, G" ~1 P ?/ q, T6 |0 C | [12]. n# L# m D4 O& C
Delivery Status (DELIVS)—RO.+ o5 a) I4 R$ M$ d% D' b# O4 n% w
The Delivery Status bit contains the current status of the- H5 a- G1 Z2 K5 A" y, h
delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit
, D9 ~& s$ U' \# v! }2 yword) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send3 u! z: g' r4 o+ D0 f5 a
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
' U, j7 Y: ]0 Z4 F1 J9 ?9 xbus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).. [! t5 z2 r0 n) K% m6 t
| [11] Destination Mode (DESTMOD)—R/W.
7 ^- n+ q2 k: b$ ^" X+ gThis field determines the interpretation of the/ P; Q0 ?; w. [! ?
Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.9 _2 ~7 C/ h2 U2 P( n
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.* o+ b! ~4 W* }" o7 F
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)
0 M( \$ v9 H. Y: L3 c: ^" K! X- T; z | [10:8]Delivery Mode (DELMOD)—R/W.
+ L6 _' _% r% F/ {- pThe 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
4 a, u& X7 p/ F! V0 R- FDelivery Modes only operate as intended when used in conjunction with a specific trigger Mode." Y5 K" Z7 y" J* V& Y5 a. l
These restrictions are indicated in the following table for each Delivery Mode.
1 r$ O" ]) m7 o3 k! C+ yMode Description
2 K+ ]3 j5 M( T" P9 m( W0006 z3 t6 {# }: } ^, s2 Z
Fixed Deliver the signal on the INTR signal of all processor cores listed in the
) }+ b3 n& w) I( e d2 Tdestination. Trigger Mode for "fixed" Delivery Mode can be edge or level.! B7 J5 g# L \) S4 ]' \- H, L
001
* e; |# X/ ^6 H3 k0 ULowest$ _( b+ Q' o2 s; w8 c; R7 u
Priority Deliver the signal on the INTR signal of the processor core that is
' b# _4 J+ Z' }executing at the lowest priority among all the processors listed in the
4 p P V) x! f1 j+ h6 mspecified destination. Trigger Mode for "lowest priority". Delivery Mode' I- k1 a4 x- l2 X8 J
can be edge or level.5 O1 g/ \" n1 Y
010 x+ b1 Y+ @) K# r+ D4 P( l- [7 @
SMI System Management Interrupt. A delivery mode equal to SMI requires an
, M2 P) D. z5 b* ` Medge trigger mode. The vector information is ignored but must be
' {+ o* D8 V8 W) cprogrammed to all zeroes for future compatibility.) g1 x8 D* u; ]3 Y0 s; `
011! ?$ }- N/ c7 e
Reserved
2 h) l; d% Z; }* m100: v; L" \6 X3 O+ I, c
NMI Deliver the signal on the NMI signal of all processor cores listed in the2 R0 T4 B4 F& F9 f9 n
destination. Vector information is ignored. NMI is treated as an edge
% s9 F( X3 p; \( qtriggered interrupt, even if it is programmed as a level triggered interrupt.# b. F' W& h/ z/ t7 C4 x
For proper operation, this redirection table entry must be programmed to0 b) F: b2 z, r* \; N
“edge” triggered interrupt." i9 X( Y6 l6 s0 I0 f0 w
101, o) b) Y8 z8 z" t! T k4 J) v
INIT Deliver the signal to all processor cores listed in the destination by
' K0 Y7 l/ r. g3 F! _- Wasserting the INIT signal. All addressed local APICs will assume their6 @! F) j, x+ X; p/ {+ U
INIT state. INIT is always treated as an edge triggered interrupt, even if
4 u* ^2 T# Y {% |1 h" u! Q* m6 ]programmed otherwise. For proper operation, this redirection table entry5 u0 }8 d8 m \4 L7 p+ B, T; q
must be programmed to “edge” triggered interrupt.
# i' ]. ~+ H2 [, q5 l1105 J8 c7 W P# J2 X0 M5 W: W$ b
Reserved$ y. J# |- Y2 N8 h- i. r
1114 [. i+ a* D/ o( v6 g
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the1 v+ y7 Y. ^( c. ?( H& T" v2 \% A
destination as an interrupt that originated in an externally connected
1 g- U' {4 ?% N6 E, p(8259A-compatible) interrupt controller. The INTA cycle that corresponds
& u7 C: L( m4 v+ T6 j V, ito this ExtINT delivery is routed to the external controller that is expected/ D" x: _$ R# S9 V) t
to supply the vector. A Delivery Mode of "ExtINT"* j) Y! V) l1 o \
requires an edge! U5 H/ g) J3 K- t
trigger mode.4 O* Y) v, k7 ^
| [7:0] Interrupt Vector (INTVEC)—R/W:
9 [3 |. w* ]$ l, J) i; @ l) qThe vector field is an 8 bit field containing the interrupt
/ F" c! Q& d* @/ `: `' Nvector for this interrupt. Vector values range from 10h to FEh." t* `4 u8 _& h% u5 o
| 8 o2 O$ Q$ y1 g$ I3 W" l1 R, N N1 N
REFF:
, D; k1 ] R& H) I. C! i0 G4 X
- M A/ j: d, g u/ Z# r; t7 e3 _9 o1.
. o0 H" W1 i! s2 Z# [$ Q s《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》) m! J, X: C1 k. b$ u$ B
2.
1 z2 J6 d3 w: {$ _0 d# p《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》
* U$ _1 L1 C' L3. N( I h$ |! X$ V1 E3 B- b4 \
《Undocumented PC》
. T( C9 G) \0 t; V& Q$ H4.
5 }% _2 |: f( ~ ?
2 f N0 K N! Y( x9 ]8259A初始化编程' b* U5 j) k- K0 n- w7 \
' q8 S$ f/ ~' RThat’s all!5 }! G# U% ]2 d! o; r$ ^! }) w8 K
2 p! N M9 s( M' ]+ t. Q
Peter& b' q; o1 {" p; q3 O
7 f7 [- V; m! ]
2010/10/07
5 q+ H9 ]8 E: Q& L) ~, |4 P+ z8 w9 R0 h* u/ r# y
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|