|
|
|
PIC 、APIC(IOAPIC LAPIC) + z5 u5 G: g9 w K
1. Overview
3 T: P& H* E$ g# {2 a! x/ q2 x5 u' w& \6 T' a
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中
1 H/ \) E9 A1 P2 i用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。
+ m% ^9 ^9 G2 x& [6 I. ?
7 z: ]9 I/ c. s7 T
6 r, u7 R2 I3 o- W2. PIC
j- P/ ^; o# b7 v: L" w; X9 }! U2 B1 ]% y
基于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。
6 N) L, u6 g. _5 C" G" ?4 q1 v- S8 q7 m5 d/ e0 O' y& ?
% S+ S1 y( d% j# q& ?& h( T0 K
" Q7 ~6 K6 H0 J1 a' k
) _0 Q# q+ F8 s3 `9 W, Y& V O' ^为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:5 G" J: C# c9 x/ P/ d, U5 o
$ k+ o" ? p) _2 u) gMOV
7 l# X: w7 h5 A+ J0 yAL,00010001b+ w% ~9 h' ]% w s+ k
;级联,边沿触发,需要写ICW4
0 _* m0 p7 E, }, iOUT6 }' @* k+ j7 A# s/ }
20H,AL
+ X9 u6 k$ p+ C/ q$ ^9 q0 A;写ICW1
! a0 a6 f: s, S `MOV0 j/ x- a! T- M' y; Y5 n9 |7 x6 U
AL,01000000B ;中断类型号40H
1 y, b! K0 t3 | G+ v& H1 Y& OOUT& h' |2 N" v6 W/ b
21H,AL# R- [, n5 X7 V* r: b
;写ICW2
& Q' x9 V" v4 b+ `, CMOV
2 \$ X1 Y1 ^/ z0 SAL,00000100B;主片的IR2引脚从片1 m0 j# d5 t( @* {+ O+ ]
OUT; N% O( ]/ a6 m/ C+ d
21H,AL
/ O) R( J2 a! A;写ICW3! F2 k. v( ]. h
MOV4 N- w7 O* m( f' d3 |5 ~# f
AL,00010001B;特殊完全嵌套,非缓冲,自动结束
0 U, J; u6 r: h+ I) v3 c2 i* |OUT' r- F5 M5 A( M/ N q8 p
21H,AL- L- H$ x( e4 W& L, D) e
;写ICW4( Z6 F. n$ r% M/ {
- ]; N0 Z- Z& j4 z% ^( z
3. APIC
$ k6 Y+ y9 p, b) k+ Z) d) S6 s: n8 k9 F
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,! p2 H) |) }6 @; w" A P( a& j
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
3 h, e7 S. X$ V& [1 w7 l( e7 e8 v7 g( Q
7 J0 k4 m w; c0 s" Y r( {/ Z
/ r/ u. x% y8 _- f
4 C: Y; S+ S9 p4 L$ @
0 x( M1 l8 z& `Programmable Redirection Table详细格式如下所示:+ Y. o+ P! ]! N" ?
3 d9 w$ Y% V& {1 E) J9 k0 bBit Description:
4 d( X0 E* K) B9 S3 z! P6 W( _; K | [63:56] Destination Field—R/W.7 X9 x7 w* Q. w$ b6 C6 Z
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits
4 f: E d1 v1 b6 q! {4 h2 {4 T) {7 f | [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field
5 x# C, ^4 D) I9 c% Ppotentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
% ]0 [. }8 N0 o2 C) Mdestination address.
3 w T4 @+ k: v" K: h7 iDestination Mode IOREDTBLx[11] Logical Destination Address
" G# V; e8 t' q! H; O0 A: \0, Physical Mode IOREDTBLx[59:56] = APIC ID2 U9 ?0 z6 U* Z, {7 ?, E
1, Logical Mode IOREDTBLx[63:56] = Set of processors' n; s" G8 l d' X& Q
| [55:17] Reserved.82093AA (IOAPIC) - h3 X# j! S+ w; J- A
| [16], g: v, t d" m" V, ~6 N/ X
Interrupt Mask—R/W.( K2 Q" ?/ n8 @1 m& G t
When this bit is 1, the interrupt signal is masked. Edge-sensitive) r) N1 A# N; C9 p) A
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
: Y% C8 D1 J! V5 H/ qLevel-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no' ]: N1 z! \( @" ^( k1 W* F
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
4 b/ D8 E& \3 m T, M2 n, ]a local APIC has no effect on that interrupt. This behavior is identical to the case where the. k( D# l6 |3 d5 D+ X# c7 Z
device withdraws the interrupt before that interrupt is posted to the processor. It is software's9 U d) {3 e' q
responsibility to handle the case where the mask bit is set after the interrupt message has been! c$ x9 `, p8 r8 P" l1 l2 x2 b
accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this V6 O# N' g9 E m4 H! D% B: Z) S
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
( b9 S; P6 }4 K+ c, y$ iresults in the delivery of the interrupt to the destination.
1 V7 x! G1 O$ G1 M( U | [15] Trigger Mode—R/W.
/ `, d; g) R8 [% z9 q9 zThe trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.1 a- R/ w; Z6 `$ v& u
| [14] Remote IRR—RO., v" l0 Y# D1 C& g( k' J6 l: n
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.
. T" s6 W7 b; R5 }' e2 f | [13] Interrupt Input Pin Polarity (INTPOL)—R/W.
3 F% q$ h: Y9 i! n1 d! kThis bit specifies the polarity of the interrupt
6 r4 ]7 j$ y3 p: Jsignal. 0=High active, 1=Low active.8 M3 \/ H% _4 T
| [12]
7 {. A+ V" p! {* E9 A0 P+ |# NDelivery Status (DELIVS)—RO.2 l0 p4 x) Z4 N" ~; z5 b+ ?
The Delivery Status bit contains the current status of the/ b! ?5 G1 m w: O1 c
delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit9 P* v; t- k3 A$ e8 @
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send1 B3 V) E; g9 j5 F3 X) `
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC# W% c" b2 K( |( f, N
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
3 {9 H4 J) c `* s$ [3 Y, G+ x5 q, ~ | [11] Destination Mode (DESTMOD)—R/W.
$ ~7 a, E8 y; L+ o$ ~# HThis field determines the interpretation of the
- F9 `$ j0 j0 ^' S6 Y+ q4 GDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
3 u- w; o C) T4 Q# [+ YBits 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.
' f6 _4 \* G& ^% |+ T' ODestination Mode IOREDTBLx[11] Logical Destination Address 0, Physical Mode IOREDTBLx[59:56] = APIC ID1, Logical Mode IOREDTBLx[63:56] = Set of processorsE 82093AA (IOAPIC)$ e" z' I2 Q( m. G/ r, ^4 G
| [10:8]Delivery Mode (DELMOD)—R/W.
; }: l9 Z3 R/ EThe 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 certain7 K# s' {% U0 }9 X0 ^( s$ y
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode., t- h( X8 o) s: p
These restrictions are indicated in the following table for each Delivery Mode.$ R/ c) U9 ~# o7 m
Mode Description2 u5 G( A7 e2 K8 P
000. U2 s; d* `% b) _/ |; k/ E
Fixed Deliver the signal on the INTR signal of all processor cores listed in the
" r" Q, R' e0 Rdestination. Trigger Mode for "fixed" Delivery Mode can be edge or level.: R7 X8 y$ F; K+ }' [3 `" O
001
* }/ L/ } d u3 l7 G5 kLowest. f8 h$ H" ^5 m" f# _
Priority Deliver the signal on the INTR signal of the processor core that is+ }2 ?7 J0 x* D
executing at the lowest priority among all the processors listed in the# q% M8 j& |) V0 P5 l, e d
specified destination. Trigger Mode for "lowest priority". Delivery Mode
7 o9 }) J6 u6 T4 tcan be edge or level. K& A, P5 V% A3 j' X
010
* o3 \. \0 |- J/ v( j6 R: LSMI System Management Interrupt. A delivery mode equal to SMI requires an0 _6 S. l+ L0 I# f4 [
edge trigger mode. The vector information is ignored but must be; |5 d$ Q9 P, [- ]) v
programmed to all zeroes for future compatibility.
$ r1 {! Y# {" E( Q011" K$ }/ N: h2 w; e/ K: F3 t
Reserved
+ l4 W( ]/ I; G; i100; K3 N0 j. W) ]/ m
NMI Deliver the signal on the NMI signal of all processor cores listed in the! l: m( p0 z$ |1 V# R
destination. Vector information is ignored. NMI is treated as an edge R9 P3 y( U; o; Q, L7 ~0 R9 [
triggered interrupt, even if it is programmed as a level triggered interrupt.) W) ?" j+ @0 F) p. _+ @
For proper operation, this redirection table entry must be programmed to
5 u0 [5 N% I$ T( c* Z“edge” triggered interrupt.
+ |, u; o( {% L/ I4 c7 E8 t1 s101# L' a F4 b# [, h1 N
INIT Deliver the signal to all processor cores listed in the destination by" D1 H+ Y2 Z$ G; p/ S& C, O- _; n
asserting the INIT signal. All addressed local APICs will assume their; w+ y3 B4 M5 G
INIT state. INIT is always treated as an edge triggered interrupt, even if1 t# D. y! |+ U
programmed otherwise. For proper operation, this redirection table entry( i2 M3 x7 ^9 b6 f0 G. F( W
must be programmed to “edge” triggered interrupt.
9 [2 v% v/ X9 z- Z. X* l" m110
# [/ _! l# N5 Y a Q+ ~" C$ a CReserved0 ~) Z1 q# \* w5 i' a# r7 d
111
7 p) J/ g0 n. q. }2 N5 L/ rExtINT Deliver the signal to the INTR signal of all processor cores listed in the0 r$ I1 T0 ?: j) u# X
destination as an interrupt that originated in an externally connected
# U2 e6 p5 h) l+ d9 ?$ r ~(8259A-compatible) interrupt controller. The INTA cycle that corresponds
+ l% m4 R! y" `, mto this ExtINT delivery is routed to the external controller that is expected
: K9 k9 J9 j( j* w/ hto supply the vector. A Delivery Mode of "ExtINT"+ X2 g1 W. D" U6 ~) w* i5 m
requires an edge1 X2 L5 r2 _$ |; F' ?& Z- P+ d# D
trigger mode.
% O0 H; ~3 p0 N9 ? | [7:0] Interrupt Vector (INTVEC)—R/W:1 {( `; P Z. l. I- f
The vector field is an 8 bit field containing the interrupt2 u* e4 t# e9 \& a" C' s+ v8 B
vector for this interrupt. Vector values range from 10h to FEh." q2 n p3 b+ U5 ?( v
|
, ]; ~% p5 K9 {3 e: U0 s- c6 FREFF:1 f6 e) R0 F. E' |
, ^: s" T/ _& Q7 F! B1.1 q6 Y. L8 M* I
《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》3 J1 o1 W- t7 X2 m; J
2.
& @ Q: B! }5 d4 ?《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》1 g8 d' \: q% A' d7 Z2 I0 L
3.
" W8 \: e6 j: }5 r8 R6 d+ \《Undocumented PC》
3 ]( f7 [/ M) Y" ~/ N, e% E4.7 n% r C! J+ p0 d, H7 O1 e
# f. o1 J7 g) y5 }2 A+ F8259A初始化编程3 `- l' B4 G. K9 B5 h8 i+ g$ F$ F
+ f0 k4 a* ^8 X/ wThat’s all!$ c+ J. A9 }9 n, c2 O! U
5 m4 m7 k- r6 p- I- S
Peter
9 @* Q7 l9 R3 }. R
8 J2 U4 r/ C( T3 ]2010/10/07+ T; _, }* {' Y4 ]% w+ J3 E
& J; B' _. h K[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|