|
|
|
PIC 、APIC(IOAPIC LAPIC)
. o+ e k4 b4 ~ A5 `& w( h1. Overview3 f* p0 b8 }4 Z5 I( Y
9 E4 y8 }& {0 C4 b$ C9 pPIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中
* ?$ j# m b) n. n用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。6 c. q3 A3 q$ i% k
/ n, C1 o. h* g1 l- H9 F& L' |
2. PIC
+ A- S$ k- U0 |1 ^% r* w9 L h5 [* \1 n$ _8 T
基于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。
; N, ~6 l" t( e! h- s2 H+ j7 n. I, p% [
( Z& e2 H# E" W' ~) @0 B
# Y: Z; b; T5 T- n, W( S1 ^
) P5 l( k- G7 a! f为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:- c: [8 L$ D5 K/ t% K
$ w! o6 P) ^ n7 o7 I2 Z
MOV
$ C J6 p( W1 a; C; D& i8 H) WAL,00010001b
+ e2 ~% i, z0 {+ W5 M0 A;级联,边沿触发,需要写ICW4% m" e- ^" l& j4 M8 G4 ~
OUT$ [/ D% C |7 _5 q9 z( P
20H,AL" {9 o6 J, X6 ]
;写ICW1
1 @8 V! C7 W% l/ g) ]6 LMOV; @2 U! E) j, }9 {! n6 X# [- c, J
AL,01000000B ;中断类型号40H
* k: X+ W; ^! o. B: Q" g* E0 oOUT$ g+ q. g8 Y: M4 ]6 U
21H,AL6 H* v* ]+ S+ c/ E6 g
;写ICW2! C, [4 [" p; ~1 v
MOV
" D1 J; t) n2 i9 D. SAL,00000100B;主片的IR2引脚从片
( j" H2 D+ p6 E6 BOUT
! A$ V8 k1 g* d) r1 C5 `; @21H,AL
0 C1 H5 h# ^; [# }& f3 h% v" o$ @;写ICW34 v7 @9 S* u6 s% I+ b
MOV1 u. x: F! s: b( h' E. L
AL,00010001B;特殊完全嵌套,非缓冲,自动结束) T$ U$ ~# F$ U6 u+ {. m) y J
OUT6 r# K5 h) ~8 q" K# Y; R& g
21H,AL
V% S" R( j3 X# ]) N, ]8 R3 `;写ICW4
1 F6 R- m! d$ Y3 J9 U7 ?) r+ p# F' ?4 | x
3. APIC
) y5 r1 X+ f* [* g7 _1 A+ K4 H( n; r7 _# P/ V9 o6 N
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,, a5 a( P; U, I
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
: y& J; }& k! a/ k" E9 p8 z: q
9 J- q1 r5 c( o/ M; w6 f, p$ U
) c3 r/ N: H w9 H2 o
- u8 m2 i1 g6 |9 v& ^$ R' A; ^Programmable Redirection Table详细格式如下所示:
' P" ~6 ]: t* b& N
: \3 O' l S U7 s3 {Bit Description:
& u' k6 j' G4 j) `4 u. ^: y, N6 P | [63:56] Destination Field—R/W.
! e$ L0 i m' n3 D; E$ ?If the Destination Mode of this entry is Physical Mode (bit 11=0), bits7 Y4 U8 I9 l5 Q8 a* [# k
| [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field
* N) i3 u7 t9 I) y1 s9 s( w4 _potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
/ }# p& Q6 w$ V" C3 @) tdestination address.
. o! l/ I# W/ XDestination Mode IOREDTBLx[11] Logical Destination Address' {& _4 _0 F9 w* ~2 {/ |2 c4 [) w
0, Physical Mode IOREDTBLx[59:56] = APIC ID
0 U' {; ]/ s: ~9 y+ L+ R3 U1, Logical Mode IOREDTBLx[63:56] = Set of processors7 l& r3 ?& r" o2 F3 X& b
| [55:17] Reserved.82093AA (IOAPIC)
" ?5 j7 i* z- | | [16]
; e/ B4 r# L) o _% B5 OInterrupt Mask—R/W.0 `( H- b4 S5 a9 o" J! [
When this bit is 1, the interrupt signal is masked. Edge-sensitive; q _% Q% }# c! ~1 L$ n9 P
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).5 L/ a# f( c+ q5 q8 E
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no8 b7 Z" m& }/ h1 |( R: f! m
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by4 f3 Q; U8 e0 f) ?. e. o" j9 Z
a local APIC has no effect on that interrupt. This behavior is identical to the case where the
9 F! X6 J; R' g4 m+ v: E/ @' Sdevice withdraws the interrupt before that interrupt is posted to the processor. It is software's
5 w, s+ \- J& _( D" A3 I% Rresponsibility to handle the case where the mask bit is set after the interrupt message has been
+ b2 O: ]& t5 D7 Y5 L3 Waccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this
/ C r" ?# |5 kbit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked& C6 X2 Z: m* g6 E
results in the delivery of the interrupt to the destination.& h6 W0 p v) P
| [15] Trigger Mode—R/W.
* _5 B# M# E) c U% ^" x8 vThe trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.2 S( X4 m6 _0 _+ O& W6 c g" N# j
| [14] Remote IRR—RO.
* ^6 N) i% J! l% a/ b5 b) C8 BThis 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./ i7 m- q0 w5 ?! |8 i2 [5 ?
| [13] Interrupt Input Pin Polarity (INTPOL)—R/W.) j8 M8 _$ P) ?' M
This bit specifies the polarity of the interrupt
7 m g" m" E; b8 k! Asignal. 0=High active, 1=Low active.; a5 _3 x1 w; C9 N: X/ ~
| [12]
" \5 ^' X, S8 u; `1 K1 fDelivery Status (DELIVS)—RO.& |. Z3 ?, }0 c9 z2 ~, ]
The Delivery Status bit contains the current status of the
& i% j5 }, P4 s2 P# n% sdelivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit2 V' H$ p- h6 N
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send0 L" J) T7 F: t$ @# J- B, E
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC: Q4 f8 E' H0 M7 X
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
& w7 Q- T( i5 X4 S2 ] | [11] Destination Mode (DESTMOD)—R/W.
, b9 t9 m2 n+ U. ?5 WThis field determines the interpretation of the
1 n& U4 w( z1 }/ i1 L6 C8 ^1 B% x* HDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.( v. t. _0 {" k0 W7 Z; k
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.3 N4 b- z. b) ?0 p3 r0 g' B8 p
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 z- Y) M5 W% ~% t: C% B5 Q% j
| [10:8]Delivery Mode (DELMOD)—R/W.
, |- z9 b3 w- i: NThe 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 certain1 [: W* [5 G& d0 u* o0 l. P
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
5 @+ a W! a' B. X6 f. d3 mThese restrictions are indicated in the following table for each Delivery Mode.- U3 N% A- H B
Mode Description
4 J( V) o2 m6 X2 K5 _& L2 L000
' l1 u* L' m6 S& dFixed Deliver the signal on the INTR signal of all processor cores listed in the
: C% ?8 l6 P. wdestination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
/ t$ y; g# o5 m( \2 @$ I001
+ T1 A U6 L4 E' H+ e% A7 `7 S+ `Lowest
- v3 u4 d3 q& b8 IPriority Deliver the signal on the INTR signal of the processor core that is5 J5 h/ W! |3 s: I9 ~5 g
executing at the lowest priority among all the processors listed in the
8 ]3 s( ]: j7 K3 Ospecified destination. Trigger Mode for "lowest priority". Delivery Mode
* O9 i( W, f4 Y8 a' Q; Pcan be edge or level., X6 O2 v; H. p' A8 M a8 z
010
4 Z! E2 c8 D7 }+ e2 gSMI System Management Interrupt. A delivery mode equal to SMI requires an
6 u, Q/ z- G0 a5 G2 b- H1 eedge trigger mode. The vector information is ignored but must be
% R: \0 e) A1 y3 B8 E6 [! {programmed to all zeroes for future compatibility.
n( ]) y/ ~! w* ]- U% ]0113 C3 D; e' g1 [ \
Reserved
+ t* z$ y- _! Y& f& ?& `8 e$ P100
0 }& M/ k! }* V* \: F5 e- TNMI Deliver the signal on the NMI signal of all processor cores listed in the
6 h5 ?: q% m5 |! `0 E6 ?3 idestination. Vector information is ignored. NMI is treated as an edge( r+ u: `3 U: _% L7 J5 \
triggered interrupt, even if it is programmed as a level triggered interrupt.
+ M8 [. P' ^ u) iFor proper operation, this redirection table entry must be programmed to
0 s$ t+ h3 @! ]+ V$ l+ ?3 A“edge” triggered interrupt.. ^2 B2 b8 z' g' _. `9 x- k
101
( z" @- L! p7 ?( PINIT Deliver the signal to all processor cores listed in the destination by- D& `4 U& Y: u% X+ K: {" D W6 c
asserting the INIT signal. All addressed local APICs will assume their
2 e! D$ i. w$ H1 H" F3 E/ sINIT state. INIT is always treated as an edge triggered interrupt, even if! n# H8 L4 V0 c! I) v
programmed otherwise. For proper operation, this redirection table entry D/ C$ G* T: ]2 ]; ], ?7 X
must be programmed to “edge” triggered interrupt.8 h: M |6 A" a' O. k" i6 u
110+ B, Q. E: M1 q! T/ g
Reserved
2 f7 W& y% I/ ], T5 q* I7 x111) Y8 P0 D7 r Z, J" j: b- y: K9 D
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the
4 u1 N- y3 r" O/ B. S- e: ^8 Cdestination as an interrupt that originated in an externally connected
) `, O, M) q# {3 W(8259A-compatible) interrupt controller. The INTA cycle that corresponds
& o( _ T' k, [* t5 J1 m$ Mto this ExtINT delivery is routed to the external controller that is expected% I9 V4 q/ B, F# K- a+ ^( [
to supply the vector. A Delivery Mode of "ExtINT"% c" h1 ?. Y: V
requires an edge" ?2 W1 T' x7 \5 P
trigger mode.
P% X$ D2 l$ e) b2 o1 m; T" R | [7:0] Interrupt Vector (INTVEC)—R/W:
% L1 v5 W. a0 t5 _4 F2 e# HThe vector field is an 8 bit field containing the interrupt
5 R* A" s0 K% D7 e9 rvector for this interrupt. Vector values range from 10h to FEh.: J" e( c3 V( ^
|
' j! a1 o% u' CREFF:
+ Y$ i, P0 `' h2 |2 Y
7 Z; r4 Z) _7 R- b1.9 h0 u/ M5 |6 y7 N8 C0 {4 p
《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》3 k" b( ^" D. c0 g7 c
2.
2 v( Q: T, s! T5 h" E《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》* @2 s8 A( M( K i9 E& I# B( g; l
3.) e" N, }- c, d. q( G$ a" z2 b: z) C
《Undocumented PC》
4 W: H. T% E. `/ H/ Z5 T4.
6 H: _' A, G! D" u
6 ^+ y- j, P. C7 z2 h! C2 ]3 }8259A初始化编程
2 g* t) G, L9 y2 n! w, w2 }
& P* x% A7 q$ _* GThat’s all!
. g3 h- P. w& `, m, `! ~! X7 K, w
1 n. K8 M5 d" o# ]Peter; X8 N) ^6 z: T$ r; k; c# d0 C
# O9 F+ N7 l/ l5 m" h" l
2010/10/07: b7 a" E) Y# n4 _5 Y& J# a) K
7 Y( B7 V; ^3 C: J9 w! X# |: g
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|