|
|
|
PIC 、APIC(IOAPIC LAPIC)
1 j6 f- D I% J1 P+ K, Z: Z$ _4 u1. Overview5 L7 Y- E/ Y4 @3 v F- _
W2 c9 u! h) B R5 ?
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中
+ z" H* o+ w. A$ P9 w用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。
) Y+ O. ?9 x2 _& |4 x% b9 Z( s$ ]* g+ ?7 |
- ]: n9 V0 G- z$ G- x0 f
2. PIC3 B- b% Q" }; k
' J4 f8 X; ?# {4 j; P) L- X
基于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。
$ s" I4 D& O ]$ P) u! B- m5 Y8 D% g% V8 K, @4 ]4 w& F, k
! x, t" J0 f4 D% R6 M9 g m2 C
3 T* x3 h# Y x0 Z5 A& f ]3 X" `
为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:
P) F. Y+ I' C8 Z/ U' [ n4 B, j5 H
MOV
J. m* ~( S0 q) ^7 P; \# i5 U, CAL,00010001b0 c# T5 W$ }$ b6 i
;级联,边沿触发,需要写ICW4/ K3 n+ H: _- Q7 W" D$ G+ q
OUT" H% m7 m. `. }6 k# e# A6 u
20H,AL
: c7 G B3 A' e0 o- ~;写ICW1
5 D9 q u6 T: C& ^9 `# n# K' KMOV! i/ ^5 b# j# ]: [+ |- o( a
AL,01000000B ;中断类型号40H$ u7 ]- ~/ g& \6 U" Z% s) |
OUT
" r* ~" V& m+ g9 J! {21H,AL
4 J: b- S9 _6 C$ G+ X$ f;写ICW2
3 C0 z1 Z2 u7 ? M7 pMOV
0 S4 b# [& y4 W" q0 tAL,00000100B;主片的IR2引脚从片2 }! w6 x4 I1 l6 H: B
OUT
' p% z3 j5 g" @+ I& z7 ~4 ~21H,AL
2 H. D1 r; G: D4 l7 d2 c' `* d3 a# A;写ICW3
1 C( X9 z6 S" @- |) F. HMOV
7 J3 v, o( t) Y, f4 f' `AL,00010001B;特殊完全嵌套,非缓冲,自动结束" O" M- V- w4 [
OUT C6 R' V( C9 R! e3 h
21H,AL. P$ D! k0 e3 {
;写ICW40 B4 W; `* ^% e) u
% Y+ k4 v) t- M
3. APIC0 Z% k7 x `$ d' H
9 P1 L$ E3 K9 T ]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,- {3 l7 R8 u8 L" J# D( @4 a
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
. x# T/ z; j" k* Z+ p( {
- r% x2 V3 K# A/ n" } I/ {. q& f! M8 M f" M; W
' y f9 O$ G0 i. V. m
- l* a* F+ P* D6 i7 L9 C F" CProgrammable Redirection Table详细格式如下所示:
! N* n' s/ d: A. y7 ?' z, T z* }: i* B
Bit Description:
4 k& Z* }' M- ?; n4 j | [63:56] Destination Field—R/W.: R2 m. a8 U7 y( H1 K$ A
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits
* {; f+ y+ q- Y7 l, M ]2 ` | [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field
# `8 f3 ?7 s) ^9 w, b6 q1 `potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical4 z2 m" h: X- ^7 \' m: u
destination address.8 l6 Q9 c# t8 _, G' _
Destination Mode IOREDTBLx[11] Logical Destination Address$ v4 h2 s, u# j( x* p+ O0 _
0, Physical Mode IOREDTBLx[59:56] = APIC ID
h$ j" t, n7 g/ |1 G) o, U* ~( ]/ B1, Logical Mode IOREDTBLx[63:56] = Set of processors8 h. l' C0 D0 `% Q- m4 I+ n3 N
| [55:17] Reserved.82093AA (IOAPIC) * ~: E* a( q3 V7 b Z2 l' t
| [16]
. W$ B; m/ `+ N( C5 iInterrupt Mask—R/W.0 i! @% N" r1 M( ^, N4 o
When this bit is 1, the interrupt signal is masked. Edge-sensitive! d: s$ n8 b* ]5 N6 d* i' @
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending)." K" d. t: E9 k3 i+ w2 |# G5 @3 n
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no, f v6 N- T1 C5 Z) I" D0 A
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
, P- X: q7 C3 `/ M8 C9 pa local APIC has no effect on that interrupt. This behavior is identical to the case where the; y0 K) D: d% Q: m, v; S
device withdraws the interrupt before that interrupt is posted to the processor. It is software's! Y: {; m% @: ]
responsibility to handle the case where the mask bit is set after the interrupt message has been
& r6 f3 o" I5 S5 @ faccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this
$ t% U) {# o( r, F7 ]bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
! |$ [; S' f* g) ]" u$ Presults in the delivery of the interrupt to the destination.
; Z( n% A9 ^# v8 `( t | [15] Trigger Mode—R/W.( w- D3 Q. c# n
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
9 v9 r, E+ }! P | [14] Remote IRR—RO.
! E8 o1 c* j: G- R! m+ a8 L( tThis 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./ e/ z) U+ s: Y9 z" Y. B
| [13] Interrupt Input Pin Polarity (INTPOL)—R/W.
; t4 @9 h+ V/ H/ U% L T" VThis bit specifies the polarity of the interrupt
/ \7 a+ f1 I( O! `$ L9 Ksignal. 0=High active, 1=Low active.
6 z. F+ x+ n' |9 n | [12]% W8 s9 f7 n* Z* [8 V1 Q2 L3 f
Delivery Status (DELIVS)—RO.
. Q( X7 _7 s% a7 Y0 t% vThe Delivery Status bit contains the current status of the
0 [4 b0 M5 ^/ h5 C# A- Edelivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit
# } Y! k- c: C9 |4 o/ Jword) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send6 U5 ^1 f4 j$ p4 E& K
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
- t8 y5 j2 _* B, s/ L# X* }bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).% M( S5 e4 q8 L- [/ E2 M4 M
| [11] Destination Mode (DESTMOD)—R/W.* L% x. Y4 J. }
This field determines the interpretation of the
- i( B8 H3 d- n( ^/ X4 SDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.- {5 G: G- K0 O) t7 @0 d
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 b1 F. V( ^" c4 n( j
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)4 Z* c; p. R1 f; x9 |* p: h
| [10:8]Delivery Mode (DELMOD)—R/W.6 I2 S4 B3 D3 b! m9 {2 A
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
c/ @& A5 M! WDelivery Modes only operate as intended when used in conjunction with a specific trigger Mode.# `6 H# r) t* r7 V8 l3 I( I
These restrictions are indicated in the following table for each Delivery Mode.& B) }- _6 C' G& R/ m/ U9 R/ B
Mode Description
, P! f% c' G7 q2 w4 w. L000$ v: C n- \6 p; ]
Fixed Deliver the signal on the INTR signal of all processor cores listed in the* w) n8 C+ J. @6 {& ^, F
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.% O3 ^2 y1 t, C+ n4 _) l
001 q y( [! j" O& |+ L2 F
Lowest# {9 d( u4 e9 R, v V! D
Priority Deliver the signal on the INTR signal of the processor core that is0 L M9 p% U7 i$ v1 G7 }
executing at the lowest priority among all the processors listed in the( p, \9 V$ C+ Y7 g6 Y, |9 X
specified destination. Trigger Mode for "lowest priority". Delivery Mode
" T* t6 q I8 b. O" Kcan be edge or level.1 B N1 B. Z3 p- O6 T
010
+ q8 ?& x+ N2 G: b. PSMI System Management Interrupt. A delivery mode equal to SMI requires an
: T$ ~/ A, f, g( iedge trigger mode. The vector information is ignored but must be
+ _/ `0 t* L0 f3 L- S5 B8 T* Zprogrammed to all zeroes for future compatibility.5 C M+ n/ B/ y6 ~, `) f2 ~
011
5 W" v% V5 L3 J( S9 K+ k, v' S( gReserved; t5 u- g; h# e. K+ n
100
- D9 p+ D* `+ hNMI Deliver the signal on the NMI signal of all processor cores listed in the
9 P' v- R% x7 S* C' ydestination. Vector information is ignored. NMI is treated as an edge
, D* `# v _* I$ o$ etriggered interrupt, even if it is programmed as a level triggered interrupt.
; {, g% r* \% O; TFor proper operation, this redirection table entry must be programmed to7 L# v# P+ W% c4 H: C, x1 ~$ w
“edge” triggered interrupt.: U& z: |, c" J
101$ ]+ b) k9 D& I7 k7 G3 K: l3 [
INIT Deliver the signal to all processor cores listed in the destination by
}& v. X# m3 `; P! N! N6 Masserting the INIT signal. All addressed local APICs will assume their
" J, x# Q/ g( H. CINIT state. INIT is always treated as an edge triggered interrupt, even if. z$ N5 ^7 o8 g: Z Y0 X
programmed otherwise. For proper operation, this redirection table entry
' a& ~5 U: X' Rmust be programmed to “edge” triggered interrupt.
) _4 O( Q( Y0 p6 p/ }5 o110
1 f8 I; \' |2 S6 O, T5 F! T* WReserved+ Q: O/ Z2 @, }+ @( W/ ~
111
5 v# u' _# V7 {: W! s2 rExtINT Deliver the signal to the INTR signal of all processor cores listed in the& b4 S# E. y" S! F! I# G/ x5 F
destination as an interrupt that originated in an externally connected8 X: M# ~/ s8 P P' p
(8259A-compatible) interrupt controller. The INTA cycle that corresponds
4 c# a; ~9 V1 R4 t- x, _3 pto this ExtINT delivery is routed to the external controller that is expected
: L! @9 C# u+ Q# \to supply the vector. A Delivery Mode of "ExtINT"
* W9 v# q: z/ O Hrequires an edge
! Q1 M$ o! t# S# }7 b& o9 \& Y$ y9 ltrigger mode.; }( M! u h9 W( g# W; a
| [7:0] Interrupt Vector (INTVEC)—R/W:
: U/ q7 f, ~# q0 yThe vector field is an 8 bit field containing the interrupt4 f8 c5 o4 I" G0 o9 [. G
vector for this interrupt. Vector values range from 10h to FEh.
8 P# |# @0 V+ c6 g% H9 r% C |
) w# ]- ?/ _4 ^3 g2 ~& F% aREFF:
5 m+ e b! G3 R: y( {( }+ }2 r$ P, c1 O
1.
' N# n- o, |! a3 C5 m《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》* L# n$ z% i# R) D
2.1 Z4 } G/ A- H; {$ J( |' _8 Z
《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》
& R9 J& m5 ~9 Y' s3 w8 n( }7 P3.
@+ I+ r- H+ U8 r2 z# d8 J$ l《Undocumented PC》9 g( u8 N: l6 K. a% Y/ q( ?: m
4.
( E0 Z* G p% ` d- I& z" g! D# J4 H h: ?- J$ N9 I1 Q( G( U+ t6 S& [
8259A初始化编程
" b. [( l5 A, G
" |7 P& M4 \+ U5 s/ A* V) aThat’s all!
8 T7 W" K1 D6 W) S, c
3 Z A! \) u- E& G: s3 T L" QPeter& u$ a; q+ T% R/ y7 D5 M) Z
. P# _ @- w. k: I- p2 K
2010/10/07
g3 R4 b$ |* e7 B7 y% k
+ D( U, g/ n; ?' J[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|