|
|
|
PIC 、APIC(IOAPIC LAPIC)
7 T. x! f: V) v. J% @; |9 Y1. Overview7 ^9 a+ g2 J, \( ]4 S
/ o& {# D: B4 K4 g% A, b- d' ?, u
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中
5 S E0 J [" y! o用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。
/ j9 A2 x8 P) }( f q% f0 g6 d" @' x U) G, i3 A
- ?- l* ?; k% _; K7 I$ J% B2. PIC
) c e) f4 R% t' R: P- P8 f
( C* B. |) @# W% f) w基于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。 Q& g& S, C3 Z& \$ O/ ]) r4 T
" q* C% o! {) G) Z) _& |+ R
4 f" m( j- J" S2 ^+ O2 M# r) m; m" m7 K4 ?' }% M6 W+ S K7 b& g( q
/ P. o( b" S, {% t; k为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:: @ C: |* t& c, {2 B
$ Z9 ]' t3 N3 Z1 y' c, ] i* LMOV) q' Y8 c0 i8 R) Q
AL,00010001b
1 B. w) B1 B; E;级联,边沿触发,需要写ICW4& S+ o- I+ ^- c: N6 s2 x
OUT
; p1 i; \9 u, h% B2 `% g. j. o20H,AL% b; |8 K D% d- a/ K
;写ICW11 L* [/ N/ ]1 Q, A
MOV( Y. S' e6 T4 b
AL,01000000B ;中断类型号40H5 U/ @: @. i5 P/ X# Y) o+ Q9 q) Y
OUT
- k# c) a/ W4 h& T, V21H,AL$ }5 t# | \2 `' K: h/ @+ d g
;写ICW2
$ K5 l5 d# }4 o3 Q6 ] bMOV: Z4 C8 y% q9 V
AL,00000100B;主片的IR2引脚从片
/ ^/ S; ]8 Y: y/ w. |. |OUT- {1 b. R* S% Y6 Q, p+ J
21H,AL( b* W0 u- N6 D$ X
;写ICW3
- R, v8 K. i/ E! z) hMOV
: d* [- s( `. T7 V) IAL,00010001B;特殊完全嵌套,非缓冲,自动结束/ `( r, ~( u! ^* R) w/ `
OUT
9 I* P( A0 F" Q5 u* g21H,AL
5 ~' L S9 v4 F+ @;写ICW4$ ?! c3 w7 s/ I
" l. N# z( Y: j4 {
3. APIC; T, S8 z$ w1 h+ J6 u4 E1 X
0 d3 c8 b, y9 v/ }5 PIntel 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,
8 Y$ ^0 [' T/ Y% [+ h4 h每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
* M; q9 L0 L) X0 q7 v( m
3 L, J% Z }* x& R y* \
6 h5 p" v q/ y1 u) Q
# b: F( U8 @0 v) G5 i6 i
6 M* }5 l8 h7 p6 v7 N1 \Programmable Redirection Table详细格式如下所示:' K: m6 W5 U) G
, t6 O1 P8 |1 ~3 N3 j! CBit Description:
8 t8 w: w% T% P1 W. t! o | [63:56] Destination Field—R/W.
: s) \* I$ T3 v8 j; bIf the Destination Mode of this entry is Physical Mode (bit 11=0), bits
: c1 G7 s& g9 Z5 ]+ W, h4 S. I @ | [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field- r) k. i7 |+ D* ?
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical/ M. T2 c7 C$ ]1 T! B
destination address.1 X4 h Z$ V2 l5 n
Destination Mode IOREDTBLx[11] Logical Destination Address( O2 v! B0 b9 c
0, Physical Mode IOREDTBLx[59:56] = APIC ID1 e7 m/ f, \; G# t+ x
1, Logical Mode IOREDTBLx[63:56] = Set of processors }, `; J+ q' F5 n! \: B
| [55:17] Reserved.82093AA (IOAPIC) 5 O4 ^+ L$ G; E5 x9 Q
| [16]
% _( x5 I: W* d* o8 wInterrupt Mask—R/W.8 D4 t8 ?9 _: G! U. c$ }! [
When this bit is 1, the interrupt signal is masked. Edge-sensitive
+ y0 Q% n0 B0 C! Y7 f$ dinterrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).$ e0 E- V3 M9 E2 b+ [) O1 p7 x
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
& D- q2 @5 e( ]3 y& B# Q/ i4 sside effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by, D* U) z# l: H# R, I1 k
a local APIC has no effect on that interrupt. This behavior is identical to the case where the9 y! i* R: A" G5 O8 U( p9 H8 i
device withdraws the interrupt before that interrupt is posted to the processor. It is software's
* x4 C- }$ T* O" L3 T- q; Lresponsibility to handle the case where the mask bit is set after the interrupt message has been
9 F8 o0 a w, H z, }accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this0 n, O x; P) z3 \0 d7 S
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked, \+ _: P% i; `( U1 b
results in the delivery of the interrupt to the destination.1 @: U2 m8 \( _0 X L- n" d6 r. n
| [15] Trigger Mode—R/W.
/ @% p6 M7 g" D) rThe trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
. Q4 B# m3 c* }/ K9 \ | [14] Remote IRR—RO.) |4 y* V* }% p, k
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.0 K- X( s# a+ X# k d5 l2 g
| [13] Interrupt Input Pin Polarity (INTPOL)—R/W.
* Y; {: T% [+ Y' j2 RThis bit specifies the polarity of the interrupt
& B8 s/ G6 P1 n6 i, Isignal. 0=High active, 1=Low active.
2 F: h F/ X5 y' X' P7 y6 Z | [12]: b! A1 `. A! L3 Q9 k; K
Delivery Status (DELIVS)—RO.6 H& q. p: I$ J* R) N# t& T3 y' y4 `& k
The Delivery Status bit contains the current status of the
2 u- w! i5 Z+ O3 h/ J6 Zdelivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit
( w8 x/ x* G- x: s& }( zword) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
9 a" N! [/ u+ [- U( S+ B% E2 W. oPending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
, B. }- @$ v! H' k6 W }bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
, R& o! n/ s$ C$ B# ?3 k | [11] Destination Mode (DESTMOD)—R/W.
, \0 J/ W% \$ l) U2 g9 k2 iThis field determines the interpretation of the; H: K# M3 {( P3 g) e0 i0 [
Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.# S5 w/ O" G; p/ ?
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.5 l, f. i% I! `2 {
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): ~; t% s5 K. e* d8 F$ i
| [10:8]Delivery Mode (DELMOD)—R/W.5 q( G; k' S2 j: q1 C4 a7 Q
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
. K0 q2 i8 Q( a, u+ `: gDelivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
) E9 }0 I+ {! [$ L( g6 iThese restrictions are indicated in the following table for each Delivery Mode.: T' E7 d7 g7 a4 R/ ~2 ]& b
Mode Description9 ^6 o1 E$ Y+ J9 b. P
0002 o/ V& N/ E* f$ O
Fixed Deliver the signal on the INTR signal of all processor cores listed in the- @$ N5 l2 ^+ E7 R' r
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.& g7 M7 s7 h1 b a
001
2 X1 e( c n" z) dLowest
8 \+ y% p' K' C; K% v* L+ U" NPriority Deliver the signal on the INTR signal of the processor core that is* {4 t+ H/ N+ t
executing at the lowest priority among all the processors listed in the- S) }8 k9 Z* M4 y+ J, `+ M
specified destination. Trigger Mode for "lowest priority". Delivery Mode8 e. S6 T \# c* e
can be edge or level.
$ R% T4 I- P! u( ^0 W2 F2 A# ~010
4 g2 W$ V, C9 TSMI System Management Interrupt. A delivery mode equal to SMI requires an
8 p: w( ]0 v* x7 Z" xedge trigger mode. The vector information is ignored but must be
3 E, Y- _7 K. ] Zprogrammed to all zeroes for future compatibility.
% ^8 O: c' H+ ^% Y( k, |8 H011
& ]; ~4 o0 T" |: r* N% t, T+ AReserved
+ A& B! y7 h) c# F) ^1 ~100. L" h. v8 E" \6 ^. d: c
NMI Deliver the signal on the NMI signal of all processor cores listed in the
% p2 X; K5 l3 ]/ Ddestination. Vector information is ignored. NMI is treated as an edge
X$ p# |* u! ]1 ktriggered interrupt, even if it is programmed as a level triggered interrupt.
8 H9 L5 H- _# ]; @- m. qFor proper operation, this redirection table entry must be programmed to
+ R7 d! Y, X& y* U“edge” triggered interrupt.
/ ]9 X$ s5 b# l: K- K7 K$ ~1 t101
7 H, S* o+ ?& s' p/ u' ]2 p" hINIT Deliver the signal to all processor cores listed in the destination by
& R. D8 P& R1 x7 p; B) vasserting the INIT signal. All addressed local APICs will assume their4 Y5 \( J. T4 D& h$ u% y0 X/ R' b* Q
INIT state. INIT is always treated as an edge triggered interrupt, even if
# [5 N4 X4 Q& B" m1 B) z# Mprogrammed otherwise. For proper operation, this redirection table entry% i" L* e9 F4 D' k3 i( U! K
must be programmed to “edge” triggered interrupt.
# d, f2 u4 ]" w! y, T6 y110
" R( C. R& ]) \; M4 e) [Reserved
: N5 y! l5 @( F3 y: y1 t111
; j7 |1 ]8 N4 L3 ^! ^8 [: iExtINT Deliver the signal to the INTR signal of all processor cores listed in the
9 o. B" w4 D T4 I& ~- ^destination as an interrupt that originated in an externally connected
% A! C! o/ w0 S/ D/ C( u4 a% U( B(8259A-compatible) interrupt controller. The INTA cycle that corresponds
k& I m5 W; T% }- Cto this ExtINT delivery is routed to the external controller that is expected
& L9 z# L# [, \% g& w( @ lto supply the vector. A Delivery Mode of "ExtINT"
4 b9 O% V' O) N: ?! m" f+ srequires an edge
( Q. O4 y5 C' l% p6 btrigger mode.
1 R9 ^. P* Z' n+ v | [7:0] Interrupt Vector (INTVEC)—R/W:
3 p/ B/ _+ g Z6 h. d, P! m- @ wThe vector field is an 8 bit field containing the interrupt+ W+ M. d/ u8 I. D7 ~9 T
vector for this interrupt. Vector values range from 10h to FEh.' I# {4 q* d0 w* ~
| * V: a1 J0 G/ `& u& k
REFF:
! x H3 a4 D( ~! W# {# M* h) X, O0 p" x$ d# h( d
1.4 T7 l7 N& Z( c; e, Q Z
《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》* N! i$ {$ s2 Q1 M! B9 y
2.1 l# E# \* ^+ S
《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》
* V; ^8 _0 D M$ @6 }! O' G3.
! v+ a ^* i% t& ^/ f《Undocumented PC》7 e, f0 m/ a. k& A
4.& I1 e' s% ] w
o0 O% y8 ^% J, y8259A初始化编程
3 U& u% X9 J- W6 [7 Z+ n3 l% m' u$ y: h5 |
That’s all!
" }2 [6 Y, n, q+ ~0 D3 f. T, ]' g5 R. j, R' _0 f; }
Peter
: C3 L* S6 V$ n* r+ n& \4 B# n; U. A; i" } H- i
2010/10/07. z' K! V1 Y) f/ v
5 Y( S; `! R5 w' m( G
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|