|
|
|
PIC 、APIC(IOAPIC LAPIC)
; X9 b# s& S/ h* Z( b4 M1. Overview7 r: p- S/ J: ~" h; \ a5 ^* J
% p6 x' x4 T i: d. A( a
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中
9 t) p/ J" T3 |2 X1 n用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。
7 W9 _7 q$ a1 @' @8 G3 s1 z" o" L9 W6 i% |3 B
# p9 j0 h* K% l8 J8 K2. PIC
! w# {( x: y) d2 r: C# ]- J% Y% n9 t+ @1 o1 y; L
基于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。
; Z5 N# |9 I) |8 R1 B/ e/ q8 X0 n: _# l' K- k
/ W9 S! M J6 M5 } [0 w+ |! v$ k& v, `, ^$ Y1 J6 B( `
2 P/ Y" t* p- H4 p2 [, v+ x为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:
* J9 y3 }: G% u9 d3 L6 w1 v- {- y" Y0 ?: P+ w$ ], U3 {
MOV2 u' r' l- {: E$ ]& `
AL,00010001b9 N6 ~; S5 y& _4 E
;级联,边沿触发,需要写ICW4
1 m9 v1 o/ w4 ^+ L i/ \OUT
, S5 _1 X1 D( z( M% g1 W( [0 \20H,AL, B1 F# P/ b# H( k% ~
;写ICW1/ G/ v f, u4 P. _$ j7 m
MOV
- g6 L7 z: L( ~3 y; V. r0 f8 IAL,01000000B ;中断类型号40H i" Z' S; o6 a( @
OUT
6 ^" |. P4 X) z21H,AL7 y e* K' l7 }+ _4 W$ s. m
;写ICW20 c% g/ Y8 S+ s0 P. V6 ]
MOV. G$ ]/ y- N; _8 D" T
AL,00000100B;主片的IR2引脚从片
. k% m' E: w4 ]. d/ D" U8 J8 y" w& \OUT0 d2 N$ F6 v3 @* J ^, c$ G# V
21H,AL
- T# a: F% N/ t* D9 w2 r;写ICW3; h: ^' Q2 w, b5 k E \
MOV2 m; Q) U7 v6 l M$ ~6 Q" i; S
AL,00010001B;特殊完全嵌套,非缓冲,自动结束
9 Q, f) t- L5 H: n3 x5 S# COUT
2 J" T9 ^7 x$ X' w* ?; j21H,AL7 [4 `. s, S2 U z3 G" E$ l
;写ICW4
5 F! _# w; a/ p% t1 g8 d
2 x8 }' R ?$ U- `, j% a3. APIC
8 z$ T3 V- F" _: j* y
; N; j% g7 d4 sIntel 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,
; r8 ?8 s( j# P4 \9 Z/ j1 {每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
" t, E: e% Z: k; \
9 v0 }' g/ L9 c! r2 g; ~- y) p1 I3 ~$ Y8 f4 S
# m+ F; f" ^% q2 h$ r- V1 E8 j5 c' Q3 i) n) ]! E
Programmable Redirection Table详细格式如下所示:
% L# e0 H% A# v
_4 k2 M6 }( qBit Description:
7 ~# G! U4 Y1 n1 X4 K7 F7 E% t | [63:56] Destination Field—R/W.
+ n( [& P w2 b' UIf the Destination Mode of this entry is Physical Mode (bit 11=0), bits f5 U7 f2 ^6 v% i& n ~
| [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field0 a4 M9 e2 K. x# V
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
+ r. B/ |7 C0 w0 I* Sdestination address.
3 Y4 b/ @( c; S. \) ~8 rDestination Mode IOREDTBLx[11] Logical Destination Address
$ t G( u9 s4 G' t0 Y7 d. F! U) P7 z0, Physical Mode IOREDTBLx[59:56] = APIC ID, Y6 U4 E/ b2 k. f
1, Logical Mode IOREDTBLx[63:56] = Set of processors+ f7 s2 o) g0 M/ j4 L9 P
| [55:17] Reserved.82093AA (IOAPIC)
( ?% d* x5 {% M9 [ A- b | [16]' ~) m6 b1 T, B+ k$ B. \3 y
Interrupt Mask—R/W.
+ L6 X* t$ j4 B' O# eWhen this bit is 1, the interrupt signal is masked. Edge-sensitive% P+ ]% i5 Z8 F6 s% k3 B2 o
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).% @, ?1 i, [ \
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no) V6 f) [1 V) l# ^3 L/ o' \, E
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
0 V; h5 K8 v0 la local APIC has no effect on that interrupt. This behavior is identical to the case where the7 H' r$ J- m6 D: u" m2 } R& `
device withdraws the interrupt before that interrupt is posted to the processor. It is software's
8 ~/ C5 V" Q: U$ y; W3 ^) F! Dresponsibility to handle the case where the mask bit is set after the interrupt message has been
' q% Y* d" [: q" b6 ^1 o- S: s- Laccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this
! a1 i) |1 p. X# x# T4 u. ybit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked6 M% Y" r1 Y, q9 k- }8 F9 i% ~% q1 t
results in the delivery of the interrupt to the destination.
) G# X, v4 b+ s% t1 q9 g1 i6 e4 | | [15] Trigger Mode—R/W.
: W: Y+ ]5 {* G" ]4 d9 D) F+ ?The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.3 @5 X6 B: p- H, \# h: U
| [14] Remote IRR—RO.# D: C* L( h# O 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.
) r9 T3 U; B5 s" O' K0 U. { | [13] Interrupt Input Pin Polarity (INTPOL)—R/W.( r' S: p D: \, |* s" X" ~
This bit specifies the polarity of the interrupt0 `2 D8 z, ^+ }, m8 |
signal. 0=High active, 1=Low active.
7 v8 r7 O# H! H, @! G1 E- } | [12]3 J7 N4 Z t1 \
Delivery Status (DELIVS)—RO.
/ a: j/ ?/ ] L( ZThe Delivery Status bit contains the current status of the0 Q! [3 G% A5 P) T/ Y" o4 m
delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit9 ?$ O0 H) C- `7 ~5 V
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
9 I2 y; P( ^. U/ W+ n7 jPending (the interrupt has been injected but its delivery is temporarily held up due to the APIC; r4 N4 u/ H: g
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).* f' k/ R2 @, m( e' v$ {% L
| [11] Destination Mode (DESTMOD)—R/W.
) y8 e- Q w1 D" ]" iThis field determines the interpretation of the
6 b% ?! p. D9 A# g2 x) q* RDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
* m& u4 T* x. DBits 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.4 F4 c# [7 R3 N# T
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)
e2 _$ g, Y! H; r# q6 G- @! W | [10:8]Delivery Mode (DELMOD)—R/W.
. F9 u2 ^' o. p, G) h' CThe 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
) h" L9 N: J+ dDelivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
+ s! o) Y- h; L, }. NThese restrictions are indicated in the following table for each Delivery Mode.+ _- I l b- h9 a1 X6 r0 {
Mode Description) l `, W( Z- N* ?& W
000
1 x1 E- n$ h) Y' \1 AFixed Deliver the signal on the INTR signal of all processor cores listed in the
9 u; M9 C+ x8 K& Mdestination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
: f' c0 U d4 Y: c1 R; {9 _001: V9 v/ L b- K7 x9 t3 b
Lowest% R7 \# L3 a$ J% E4 U
Priority Deliver the signal on the INTR signal of the processor core that is3 y# q7 m5 O# P' W
executing at the lowest priority among all the processors listed in the
- u% S, X3 V) n+ Y% F; U K J& g) ospecified destination. Trigger Mode for "lowest priority". Delivery Mode: U! E# \3 B% j: p# ^
can be edge or level.
' `8 p1 a$ [5 V3 N1 ?0100 \. b$ {( {: j1 ^8 S; F
SMI System Management Interrupt. A delivery mode equal to SMI requires an1 U5 T! l4 J+ N9 L
edge trigger mode. The vector information is ignored but must be4 i" y" F5 l/ X5 u7 B0 Q* A
programmed to all zeroes for future compatibility.
) N- }4 j! A- q9 T# \2 R( n; b011
2 F3 Z9 }! ]/ c0 g6 ^+ lReserved" f8 u# \: e3 x7 R
1003 m3 ]% Y. H' m/ H+ \5 [9 S5 _6 Z
NMI Deliver the signal on the NMI signal of all processor cores listed in the* [+ ^5 V {6 n- A8 \, \
destination. Vector information is ignored. NMI is treated as an edge
: p L" J7 ^" xtriggered interrupt, even if it is programmed as a level triggered interrupt.
1 ]: N, [2 V G( `$ q( Z$ bFor proper operation, this redirection table entry must be programmed to
7 I; }; x' @, m- I( i“edge” triggered interrupt.
: n. W* d& A: j+ ^101
$ y- d8 H! N5 ~! ~$ E. @+ nINIT Deliver the signal to all processor cores listed in the destination by" [* f1 R, {: @5 M3 X4 o6 M
asserting the INIT signal. All addressed local APICs will assume their' Q. H0 E( y4 D9 C
INIT state. INIT is always treated as an edge triggered interrupt, even if" \* h8 c7 @9 b! @8 Q
programmed otherwise. For proper operation, this redirection table entry0 x/ c+ r& h7 M/ m- ~; c& ~
must be programmed to “edge” triggered interrupt.: b+ p/ _; b& ` f
110
2 W8 f' I" J4 {. c+ B1 f& GReserved
' l) u6 S- d t7 w$ }: @111
; Z# x* G6 Y/ K8 s* BExtINT Deliver the signal to the INTR signal of all processor cores listed in the
8 p8 l* g: r+ y& rdestination as an interrupt that originated in an externally connected% n6 e% J1 Q6 ?& C
(8259A-compatible) interrupt controller. The INTA cycle that corresponds
6 u( L/ Q2 F7 z8 {* r! J7 Ito this ExtINT delivery is routed to the external controller that is expected
2 d9 ]# P6 d& N# M' Q5 H/ n- G: tto supply the vector. A Delivery Mode of "ExtINT"
, W1 N. @' j8 s- N5 orequires an edge5 X/ r+ f2 N7 O9 Z8 ~
trigger mode.; P3 C7 V( I6 ~* m+ q* A+ H0 e
| [7:0] Interrupt Vector (INTVEC)—R/W:
+ P/ B( _5 Y( \# w0 ^The vector field is an 8 bit field containing the interrupt. V- p: U. q# M8 M0 s( B
vector for this interrupt. Vector values range from 10h to FEh.
# N/ _3 D) t) v% u5 P" | |
+ i9 z8 m2 x) x) R+ u) w9 G5 p5 sREFF:
, a9 V, p* Z% R- V6 G5 X- B; W1 n) n9 Q) K( r5 O W
1.9 \% a2 U0 |+ ^- h" S
《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》" v4 ~; A* n1 U1 o/ p
2.- f3 \9 ~( Z& ]& N! O- R
《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》! ?' G6 [: i) e& O9 B; i
3.
2 W# v: n3 T. M* V8 o$ O' k《Undocumented PC》
8 d7 B- {% l# r3 ?# b7 a6 d+ k3 V4 Y4.* m: [- d0 |. b% L
( h4 K: s# k) e( P9 g
8259A初始化编程- h7 M4 B0 I# q* k4 E: `/ z
" ~0 c' \3 _- h& W6 DThat’s all!! d5 J. H9 B1 u
9 f" K/ y# z A! ?4 E# }Peter6 B" X! s% o$ ~1 Z! h
! U3 h# t7 e% N. E
2010/10/07
% u! ~4 Z! s( f4 y) g9 E" ^: [6 d2 G5 H: J& K1 u( z
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|