|
|
|
PIC 、APIC(IOAPIC LAPIC)
' Q2 u0 x1 ] c6 \1. Overview
* t& j$ O9 W3 t3 Q4 H
/ \; |- }0 K" y; z! D7 ], Z& c6 u& MPIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中" ~5 l/ V5 P8 K9 S: W W) s' Q
用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。
' l9 i5 F/ A' Q( i9 U% t9 h) K9 h( m
& A# P3 \6 ]7 E# V2 ^2 Z
2. PIC
% c4 J- X# g* q" d; o# G1 f8 u( ?6 ^3 W t+ O: r* ~
基于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+ |$ N3 H" q7 i9 O4 C5 `8 L
3 q9 O/ g- g% |7 Q$ s% O
8 C; d% c# X8 L; F# l% {' s& N, l% k6 Z
5 H# R, U/ G$ k% g6 X为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:
* K6 K' A: f1 T- V! ~: y3 R& x$ B7 q4 K8 I8 S& K7 t
MOV2 D* @; l$ X1 U" \, s* r) f- N- n
AL,00010001b9 I' @7 d* W7 Q0 W* o: m
;级联,边沿触发,需要写ICW4
7 T N' p+ k' c& l" qOUT
5 z( @ W6 n* l1 j& y/ o G20H,AL* Z/ y1 u. [2 v. ~
;写ICW1' d$ e2 n1 |/ _0 U+ N+ e* g
MOV
6 z% K8 o$ a! \' B1 R4 ZAL,01000000B ;中断类型号40H/ q7 E8 `' R5 N% N( f9 T
OUT
1 m; y1 U( e W1 A/ r5 N9 Y1 |21H,AL
" V% B, L* N- H;写ICW2; f4 N; n! f5 I# |& K
MOV1 p1 _8 r& U' y1 w, W
AL,00000100B;主片的IR2引脚从片+ C' q' @1 u& ~0 v) ?& r+ s8 o
OUT: y! S$ Y8 I' x+ n
21H,AL
8 W9 J ~7 M3 \8 H# `) A3 e+ x;写ICW3. o4 T/ Q; ]/ a: [/ |, M
MOV% C# k5 X: N* _5 n$ {3 v
AL,00010001B;特殊完全嵌套,非缓冲,自动结束
9 W' z, T6 b9 F/ P' }OUT
. m V" W. w) _21H,AL' x% `- g2 ^$ W- ?& h
;写ICW4
9 V0 N& n4 z6 [5 |2 E8 C4 l7 u2 q+ ^( D5 {
3. APIC
+ Z- G* G; v0 v8 E$ r/ v- r4 S
' n" h' R [6 w2 ?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,. @6 x7 J( @2 q3 v. W
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。& L) \, V9 I0 j
9 L+ N, i# F9 k
' C2 I. C# C/ P+ m l
: _3 N/ Z' i( ^: |
: x# Q# ^, m0 \6 |Programmable Redirection Table详细格式如下所示:% ]7 k3 R2 x6 L6 M8 H( L1 G9 A
+ z& q# M6 b3 L5 {& x) g h6 V7 sBit Description:" _' x1 a& V& ^/ {
| [63:56] Destination Field—R/W.
7 w& U: I- u" v" T3 xIf the Destination Mode of this entry is Physical Mode (bit 11=0), bits
8 X* b0 j8 {( W7 S" t | [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field; o# g5 X C1 l. L! j h# s$ Z
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
+ s% Y& g2 q+ P, t) Gdestination address.
\ y0 L2 d) f; l: uDestination Mode IOREDTBLx[11] Logical Destination Address
# w7 [& k* y6 @+ n0, Physical Mode IOREDTBLx[59:56] = APIC ID/ t6 @" x h. ] X, d' a0 _- C
1, Logical Mode IOREDTBLx[63:56] = Set of processors
6 j; |0 o4 R$ G! c. D$ B3 e( k6 U | [55:17] Reserved.82093AA (IOAPIC) 6 W4 Z9 i& _, n w7 Y5 Q3 Q
| [16]
& q+ c) H' r! N& X$ XInterrupt Mask—R/W.
+ G3 M/ B& ?( c3 U/ K' WWhen this bit is 1, the interrupt signal is masked. Edge-sensitive
9 J% U. }& G3 ]$ binterrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
4 H5 M+ u" \4 @5 TLevel-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
8 \: _ a* X( ^- |$ m; ^; Pside effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by9 l H, L, ~7 E7 ~1 [% S7 }
a local APIC has no effect on that interrupt. This behavior is identical to the case where the; K8 q; B8 H( p, {7 n( n
device withdraws the interrupt before that interrupt is posted to the processor. It is software's
! H$ z% y% l; ~8 Lresponsibility to handle the case where the mask bit is set after the interrupt message has been
2 ^7 K. z- W# F5 c+ M! v" q: Zaccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this
* J: s; c+ a' v4 qbit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
9 X9 X6 T7 Y; i, e- g7 Z- Xresults in the delivery of the interrupt to the destination.2 a6 U7 e' }1 q' C
| [15] Trigger Mode—R/W.$ E' b1 c( s# P2 w: D4 j
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
1 W0 W' R/ B8 U7 h8 @ | [14] Remote IRR—RO.
8 R! s) @7 M9 t0 p1 T3 \. g+ JThis 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.
& Y8 ?( V3 s- b- J9 O8 h" n | [13] Interrupt Input Pin Polarity (INTPOL)—R/W.
) U4 M+ t1 B7 \. @& S% [) |This bit specifies the polarity of the interrupt& U ]/ M, V( w' o' \9 X
signal. 0=High active, 1=Low active.
0 d+ s2 G, ]) U | [12]& \! S. r% L- p5 |
Delivery Status (DELIVS)—RO./ k+ q7 X/ k0 [) b) L6 {5 j
The Delivery Status bit contains the current status of the& y- }! Z: ?# D9 D5 y# ^; |4 U
delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit8 P( t g& {7 u! L9 I5 C
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send$ n; W2 H& Q- t. d7 M
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
" C" h* m/ ^% r, m8 F/ \1 f% u; \3 W9 Obus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
' R& N8 k h5 y% A | [11] Destination Mode (DESTMOD)—R/W.
- d5 y" k6 I" [This field determines the interpretation of the0 k& P4 S6 o' w' U* R
Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.! M' s- [* r0 K8 }+ S& X( X
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.
- K1 k# l: X% ^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)
% E, `( V% c9 e X1 s) {3 a | [10:8]Delivery Mode (DELMOD)—R/W.% m. u3 e" F. t! Y
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
9 t+ R; N" \/ G4 g0 G# ZDelivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
/ J7 G/ _5 v5 A# I& f5 e) uThese restrictions are indicated in the following table for each Delivery Mode.
7 O2 ?+ s! ?# E) O( QMode Description
6 j& b7 s' A$ i9 G* s000; d0 X( _' o! E: r/ R
Fixed Deliver the signal on the INTR signal of all processor cores listed in the C! k( [, I/ B- ^
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.3 t7 Y/ w0 }) ^ |8 j
001' {$ x4 K; ^# q/ \/ ^
Lowest
. P+ E1 J. H+ kPriority Deliver the signal on the INTR signal of the processor core that is
) Q2 q8 Z, ~5 v; {' a! S0 D5 yexecuting at the lowest priority among all the processors listed in the. C: B2 P2 e4 G5 N
specified destination. Trigger Mode for "lowest priority". Delivery Mode% S N! n! r+ L
can be edge or level.) M7 M# A' z4 O1 q7 h/ E
010; ^8 R/ I% g! |' B3 h8 z
SMI System Management Interrupt. A delivery mode equal to SMI requires an$ U: F6 N% y1 M$ S9 H* c0 K
edge trigger mode. The vector information is ignored but must be% u! }1 v, T( _1 U! {
programmed to all zeroes for future compatibility.2 V8 S8 `* r( u: z4 K
0116 _( z. {$ \5 q3 N4 q5 `& S; w
Reserved
5 s }. c; D, A, O# [( ~' h) f1008 e& @, H# ?+ ?8 a( u. t/ c
NMI Deliver the signal on the NMI signal of all processor cores listed in the
* B% G4 Q/ y) p9 ~5 qdestination. Vector information is ignored. NMI is treated as an edge
; d/ D' J: t( M1 w7 i) ktriggered interrupt, even if it is programmed as a level triggered interrupt.
$ x$ z2 U) N* ^8 mFor proper operation, this redirection table entry must be programmed to
' [( `& @5 b# `5 l1 I7 z1 {6 R$ \7 H0 e“edge” triggered interrupt.5 l% J7 f- {, L, L
1016 f9 W/ O) C) l4 B" s9 {
INIT Deliver the signal to all processor cores listed in the destination by) }1 |# y) A4 e, C0 I
asserting the INIT signal. All addressed local APICs will assume their
3 K7 m2 ~1 {6 d+ iINIT state. INIT is always treated as an edge triggered interrupt, even if
% ]+ O9 o! z+ |programmed otherwise. For proper operation, this redirection table entry
( p+ s# d" _. y& V2 y5 }must be programmed to “edge” triggered interrupt.- [$ F' r5 r ?/ o' W5 N' q
110$ p2 \& y5 A1 W* ~7 f: @7 U4 t
Reserved
' j( A3 P7 i9 ?* l! N7 l7 K111% I" k4 i) ]6 g2 G; D
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the, O& P) n) B% {3 [/ W( W7 @
destination as an interrupt that originated in an externally connected6 p6 K. v' R4 p3 V+ M+ O) }
(8259A-compatible) interrupt controller. The INTA cycle that corresponds6 [! I* }; G3 I
to this ExtINT delivery is routed to the external controller that is expected5 ?( r+ b8 @' Z- Z i
to supply the vector. A Delivery Mode of "ExtINT"# g4 [5 R0 w" G& Q. r
requires an edge0 [' h9 M. t2 V* J. A( w# h
trigger mode.# w; s Z3 y+ p+ I4 F* M
| [7:0] Interrupt Vector (INTVEC)—R/W:, U( v; U, d- f
The vector field is an 8 bit field containing the interrupt/ a( R) H9 p/ Q7 N: U! B
vector for this interrupt. Vector values range from 10h to FEh.
! ~1 d K" B- x) b I4 m; F | * f3 ?% m p0 j: M+ }
REFF:$ c# A. @$ H/ [8 x+ N% k8 i
* F5 _5 U6 P4 I7 g' i+ K, ^. U
1.& p$ G) r8 P1 {$ j. K7 f& f
《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》0 h9 W; h; N& s Y: B
2.
6 g" B0 q l' ~《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》& L& ?6 h" y. F" I! k6 @0 T
3.
: E6 ]: c$ N" T# }* g《Undocumented PC》
j4 l9 [5 |' w- J% f4.* N } b: _% @5 |4 o2 ]; l
; h; H$ r0 U7 ^1 r- \8259A初始化编程
" p/ \+ j/ ]* f; O& R4 g8 K Z# P
; w! d: [; e" Q$ X! @That’s all!0 ^1 _3 t- R' b3 Q. a7 M
' ], _! Y# ?( S6 q/ C+ f. ?
Peter" W, j* p6 X! M+ d! `* z5 O" z
) {" {& j0 n, s4 N/ l
2010/10/07
0 r, t- {1 w! K# a; R1 {7 u0 o6 S
7 Q7 l f3 s9 k P: O[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|