|
|
|
PIC 、APIC(IOAPIC LAPIC) * w7 T) f5 g6 V& ^ S& E
1. Overview) p# U' T. q5 j4 m6 ~) T- N
! w; ]6 x! S* rPIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中
/ M% m9 J9 q% p/ F% H n; @用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。+ e7 d# t# Q% N+ {9 g3 }. x
7 G8 f; S( z' f! ?4 `1 I) k0 C& G _% `, E' K8 g/ q s
2. PIC
4 F3 M" r4 [6 X [' H+ `
; Y5 o* c# V% v \& }基于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。& D( x e. Y$ g* `# B
5 }) S" g: V$ Y; J
8 z4 v9 j2 B+ F! G' N3 T) ^& S" A! d0 O7 O9 k
3 m" i) y$ \4 x. I' V- a5 e" B- p为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:
1 o7 s. U5 H; y' e- a$ S
, g6 ~5 G) U' MMOV: A6 P1 o: r% ~. e
AL,00010001b
! s x% w) v! C;级联,边沿触发,需要写ICW4
0 n3 ~1 v- Q7 C) w" c4 FOUT9 {0 D% d$ ]; i4 u
20H,AL h6 p( d" Q6 {3 f1 r: z
;写ICW1
$ `/ o0 e/ s5 w! a5 m- L. XMOV
/ | B" N$ G% v' OAL,01000000B ;中断类型号40H
; C) b) E5 m5 ~ W- j9 QOUT
d8 i/ A* b1 f5 B- I' ]. T21H,AL6 r8 e8 _( f: w8 J+ c
;写ICW2
% ?) A2 X$ u6 @9 K2 g% ~MOV) x9 H, T& X% X8 T5 h. {" Z* W
AL,00000100B;主片的IR2引脚从片8 G7 |& _6 l9 \1 L0 q: i8 t
OUT5 o' ^- y4 p8 y
21H,AL
% L0 I7 R+ j& g# H# w;写ICW3
' L( @4 c P: w/ Z0 l3 @4 S UMOV% E1 a5 ~# }+ n# Z7 x" G6 f: e
AL,00010001B;特殊完全嵌套,非缓冲,自动结束! K/ e7 U: A3 A" ?$ O
OUT
4 I8 p& \" P+ V7 l) I, I) N21H,AL
& f+ W: L8 X- |0 T# _4 D( d;写ICW4
7 \# x& v/ v( d
7 Z5 X) B/ ~* k% n& W2 a3. APIC
8 B) w. V! {! a1 O# ]* H8 A" b3 e `8 H: L; P/ V
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,
* d7 B, D# j* Z, y- s9 o. u5 k每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
) j4 E* ?& _/ u% R$ Y0 H
3 N5 R+ p9 q$ R. L( Y( S% W% O) P! y; q
" @8 z* l6 R2 F2 f% W7 P! ?+ a. `/ ?' l( D: h$ I
Programmable Redirection Table详细格式如下所示:% Q& W6 x1 e7 B1 X2 g
3 D9 f0 f2 L8 w {% [Bit Description: N! W9 s. H1 y& X% D1 \8 S
| [63:56] Destination Field—R/W./ O' X! j: }" S! g7 g8 e
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits
* ]" l5 M7 t7 A | [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field
' b$ }5 [- d0 E3 n4 S4 B! opotentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
) l( C* T( X% a- y2 O/ ^1 }! Zdestination address.
. P; u& w) T' `7 A8 P! W$ \; c9 sDestination Mode IOREDTBLx[11] Logical Destination Address
7 k+ u3 C! K: ^0, Physical Mode IOREDTBLx[59:56] = APIC ID
8 l* h2 F1 E. Q" r+ H. J0 z& r1, Logical Mode IOREDTBLx[63:56] = Set of processors; n, R+ f A& L' k& f. L+ X
| [55:17] Reserved.82093AA (IOAPIC) # I* y; V! C, j2 @. }
| [16]3 @, N' c A3 [- [4 @4 W
Interrupt Mask—R/W.9 h) s7 N( V0 @2 l5 k( G6 u
When this bit is 1, the interrupt signal is masked. Edge-sensitive
6 f& D0 |( U. s/ Y b1 qinterrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
; H8 b' ~) q; h! \0 j% c" CLevel-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no, x+ {; Y. s0 Y4 p1 `6 J9 i
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
$ v! a! t% K" W: f( T4 b. Ua local APIC has no effect on that interrupt. This behavior is identical to the case where the, b( a/ P* T$ E' s3 C
device withdraws the interrupt before that interrupt is posted to the processor. It is software's
* ]8 }4 p5 }5 M# y0 ]& hresponsibility to handle the case where the mask bit is set after the interrupt message has been
" a C5 _$ d1 Iaccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this
. `/ m4 M6 \8 p" O, f- s* Mbit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked. P& C: Y" T% O3 t4 v
results in the delivery of the interrupt to the destination.* K( C8 O+ ~+ Q* q
| [15] Trigger Mode—R/W., A# |$ x2 M7 S: ?
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.6 l. z4 z8 l8 G* I4 U5 f
| [14] Remote IRR—RO.
1 R( Z4 f& a8 o1 i9 rThis 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.4 L5 p0 d* }3 I& ?. F8 Q1 J2 M+ d
| [13] Interrupt Input Pin Polarity (INTPOL)—R/W.! g, N$ w0 ]. E% E( d+ c! U
This bit specifies the polarity of the interrupt
2 c7 Q2 C8 N) C& nsignal. 0=High active, 1=Low active.
% K% {6 t: C% D4 F8 s7 d% h7 H; O/ e | [12]% z3 P) I# V$ q9 @# y' U. U# y/ E, T/ `
Delivery Status (DELIVS)—RO.: o; f! a, U$ q
The Delivery Status bit contains the current status of the
5 q. H9 S! w6 I' v: [delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit
; t0 G- b& f- i$ r" Z" `word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
% y4 }4 X Y! C, D; FPending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
, W& y+ _/ D! r$ \bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).' l) w, o# o* l" ]7 v5 g* p
| [11] Destination Mode (DESTMOD)—R/W.
& d: \- `4 h& y5 D1 WThis field determines the interpretation of the' D" O# |, I- H0 Z
Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
) w2 g3 j7 @# P/ IBits 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.
* W3 h: p7 W1 e" d: B; SDestination Mode IOREDTBLx[11] Logical Destination Address 0, Physical Mode IOREDTBLx[59:56] = APIC ID1, Logical Mode IOREDTBLx[63:56] = Set of processorsE 82093AA (IOAPIC)& k+ W3 b: M$ X
| [10:8]Delivery Mode (DELMOD)—R/W.
* O4 n) ~) c) }* @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
0 k# O, m0 f( E- M) `Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode., `) m/ t& Q; g+ L: t! h
These restrictions are indicated in the following table for each Delivery Mode.
# t% }) G$ d# x: ^: hMode Description1 h/ X" D& L: t" @" M$ F4 v
000
6 {' h1 I# a+ m0 RFixed Deliver the signal on the INTR signal of all processor cores listed in the& ~4 I; `" b) c* l: z) O9 t0 C! H _
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
3 } u( O" S, U" }" j6 u }) [001$ x" a p7 b1 Y0 c9 K4 D
Lowest
, x2 D/ N7 v8 n4 J* }$ [Priority Deliver the signal on the INTR signal of the processor core that is
6 a, a! o1 [) H8 z5 R1 Oexecuting at the lowest priority among all the processors listed in the
. y. m" l1 b) y& f5 Cspecified destination. Trigger Mode for "lowest priority". Delivery Mode
) [5 ~3 y$ ~/ ~$ I7 U' F! [6 n) zcan be edge or level.7 x( p- h7 k6 P7 e* d5 S
0107 c2 h2 _7 ]2 D) c$ ^
SMI System Management Interrupt. A delivery mode equal to SMI requires an
: [) q- d8 V8 I8 e w8 W9 u2 r. ~edge trigger mode. The vector information is ignored but must be
" @1 A! h5 h* e! W' Iprogrammed to all zeroes for future compatibility.
+ j E. }+ {- _. U011
9 V8 S( t0 ?; i7 s7 k$ j2 LReserved
7 I( e7 c- I' l% I0 g$ I100
/ }; w9 ~+ h; T% r8 e& n& O; f+ s DNMI Deliver the signal on the NMI signal of all processor cores listed in the, d; U/ L" Y S Y8 p: a5 b
destination. Vector information is ignored. NMI is treated as an edge7 A$ L2 k- t4 E
triggered interrupt, even if it is programmed as a level triggered interrupt.9 j- q8 I* _: a3 b+ v
For proper operation, this redirection table entry must be programmed to4 n- { q1 P4 n" d7 @( c
“edge” triggered interrupt./ l& _- b$ S* p9 ~
101
0 |- l8 X' Y+ kINIT Deliver the signal to all processor cores listed in the destination by
) ~" e# y* m8 Z# Q! n7 \' Qasserting the INIT signal. All addressed local APICs will assume their1 ^8 [5 E; b6 R0 i
INIT state. INIT is always treated as an edge triggered interrupt, even if
0 x* {+ b7 p2 xprogrammed otherwise. For proper operation, this redirection table entry
- u0 ]5 z$ @, K# v, |must be programmed to “edge” triggered interrupt.
+ f- i& ]5 P$ i6 w# S. {+ C1109 L, J" @# W3 W- u
Reserved
/ Z' Z# E& v R, k# z1117 H' u+ O8 n! `( r8 `2 W/ z
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the
5 [5 P* l5 W/ v. N/ g) W) {2 ]destination as an interrupt that originated in an externally connected
" E* e2 Z$ T. F(8259A-compatible) interrupt controller. The INTA cycle that corresponds
8 P( m' b x6 v1 sto this ExtINT delivery is routed to the external controller that is expected
0 G2 Q* K" [% P/ d& T9 t9 ~" b% |to supply the vector. A Delivery Mode of "ExtINT"
8 z/ N0 S4 }# o( \4 U* z* J' f# Brequires an edge$ |5 @% N% ]# E& p
trigger mode.3 {/ B+ M3 O& K/ Z( t; D1 E1 _
| [7:0] Interrupt Vector (INTVEC)—R/W:
4 L0 b! C6 Q+ W2 EThe vector field is an 8 bit field containing the interrupt! z% X. e1 f9 ]4 b% P6 C
vector for this interrupt. Vector values range from 10h to FEh.
. k# ]3 ?$ C1 k* W# O( ]( { |
. m. v. H# i4 I1 e; rREFF:+ E4 I( l5 f* p) [/ j, I
7 E9 B/ a$ k) i
1.! S7 @# n9 L0 ?' U" R
《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》
2 p0 S' z9 K2 ^7 a( g K ?2.* |) s' q% d- i; O
《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》
4 R" L' o9 \. F$ j3.
* p/ x+ a0 e7 q& P《Undocumented PC》
6 ]- i- g7 f* T1 I4 z. E4 J0 Y4 W# Y4./ D! X. f) m7 R6 }3 K
; j9 x3 |; `( C9 g2 @" ]& u+ V& u- M
8259A初始化编程# I* j% [4 }1 a$ j9 g1 {
8 _5 f# L( y- k* f7 l, e; [That’s all!/ y7 w. c+ U2 w% f% n
* C- G! C Y5 L4 o2 J
Peter8 E8 H! s+ m/ F& k; M
$ ^3 u' A S+ F& L2010/10/071 O- i' o% g+ h- ?" [
6 c) f( C: ~2 l[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|