|
|
|
PIC 、APIC(IOAPIC LAPIC)
: y0 a) k' @# Q: w8 o& C1. Overview4 A/ `& o) F- E e: v
% Z0 v% \% N8 J1 C5 M0 r1 B5 o) V. P: u) |PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中5 A, L5 j$ Q% x
用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。
$ D; ?! w, h+ ^. P: F* W4 k' b- ] {/ k( I- I
/ ]$ j, q( x) Y2 h2 l# B& _2. PIC
' w- @6 O. P# A7 x8 f7 E1 p+ Q' V
/ k0 x0 d# V1 o7 d% C基于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。7 R2 h( v' W& D1 d" p" w
3 M; d3 C7 I9 t7 |; D' B8 `
# I) s$ L# c4 v% s+ T; s
k/ U1 ~2 u* {
M8 q) N2 U: Y$ z' H4 ?为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:
% @$ O) t1 a& L/ @; j W2 o: Z' q: l9 _+ |3 H1 m* D' {0 l
MOV
7 [. V' q) j) E% r3 IAL,00010001b
- v2 i6 ^5 y3 S6 };级联,边沿触发,需要写ICW45 @) y9 q3 F" M# n3 a: t
OUT$ _ ]( R! {( f3 j
20H,AL
( a" C5 |2 E" w4 p;写ICW1
6 X1 o9 R+ n, `& |4 h! SMOV3 x2 D& O8 E/ Q1 Y" @2 P
AL,01000000B ;中断类型号40H
7 Y7 ?3 E d2 Q9 k, v$ aOUT
* [# H1 I, t0 c2 z9 J) S5 ~21H,AL# P; k Q6 w' n1 f8 t1 g
;写ICW2
3 G/ N9 v0 P9 X$ mMOV
4 _0 n6 Q7 ~2 B. ?/ dAL,00000100B;主片的IR2引脚从片& l0 M8 |8 ]3 U; ]- W. s2 H+ O3 Y' b' M
OUT1 |% b( G7 y6 P# o$ _. O
21H,AL
) p, L4 U8 T5 Q' K7 M) a! r" e+ h% z;写ICW3# Q q+ v0 F# R. O7 O& p& _# C. q
MOV4 s) y. b! ?: U- v# B# t6 @% D
AL,00010001B;特殊完全嵌套,非缓冲,自动结束
9 t! L/ w; Y, \2 SOUT
( l% w( q+ o u" t0 R0 ~( ?$ w2 Q21H,AL
5 J1 e# H% a9 ?# g;写ICW4
- y: o2 {: b% t% V* ^8 e/ K2 p, [8 F4 e, {: \+ ~
3. APIC
0 L" |' w4 l5 g; |) i
) H; c+ r: o0 e, N' @ E6 Q, e0 c2 h3 TIntel 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,
$ W6 W! M7 ^9 ~每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。! F! Y) G# H5 ?( C: I
/ s- j5 d$ X( m1 g, w, b* m) O3 T8 c4 T3 U
; N7 T# ?. L# P9 u) u+ o1 S1 t6 _+ y* p' B( w3 z: U3 M1 D
Programmable Redirection Table详细格式如下所示:
, [2 n7 G2 j& B7 g& V' H9 x5 d8 x' D, ~' r, K; {
Bit Description:1 H2 \4 g& s: H" o' |3 B
| [63:56] Destination Field—R/W.- W( y& \) c3 h: {* D
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits8 E1 k: g0 K7 T: T2 b. I$ d. X
| [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field
9 T1 G0 J+ n1 [, Npotentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
, [, u: g# W1 U" X; L& Ydestination address.
7 M! N8 ]& w. P a1 vDestination Mode IOREDTBLx[11] Logical Destination Address
- E8 l5 a& Q2 |: m/ X$ I; P1 X0, Physical Mode IOREDTBLx[59:56] = APIC ID, ^2 v& x8 ~+ |6 X
1, Logical Mode IOREDTBLx[63:56] = Set of processors7 N( ?6 Z# ^, L: \! k
| [55:17] Reserved.82093AA (IOAPIC)
6 | Q+ x1 ] \4 C3 {* D | [16]
3 A! g. U' ^4 }0 n4 X+ g' |: {Interrupt Mask—R/W.8 @# \9 Z2 `9 A; ~8 v
When this bit is 1, the interrupt signal is masked. Edge-sensitive
% f) b! g: E2 d4 A' Pinterrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
; Z5 W8 E: Y: L4 W7 \$ ILevel-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no l8 v( U* I% N7 q: R# v2 A
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
4 C" t* w) R0 @# d- f7 Ka local APIC has no effect on that interrupt. This behavior is identical to the case where the
n. E0 Y/ k2 G9 n9 V4 V1 B, A/ Udevice withdraws the interrupt before that interrupt is posted to the processor. It is software's
5 p2 B. ^9 _4 A- D x- gresponsibility to handle the case where the mask bit is set after the interrupt message has been2 n# c/ A. f" T2 T- E% {5 L
accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this9 ]! y1 |+ C/ ~6 j+ w
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked8 R! M) w# {. i# N
results in the delivery of the interrupt to the destination." c4 A) R" j, ~9 }5 q0 M
| [15] Trigger Mode—R/W.) S; y' H3 E8 `( \
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.8 q9 I0 k. T2 I& K
| [14] Remote IRR—RO.6 I) s& w! n; x
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." ]9 n/ r2 n4 J9 {- Q
| [13] Interrupt Input Pin Polarity (INTPOL)—R/W., f; ~& F" x+ A& ^
This bit specifies the polarity of the interrupt
& S0 P) n' S5 C" Esignal. 0=High active, 1=Low active.
# J. n9 U/ {1 a6 {' Q | [12]
! G$ L4 n# j+ b9 |7 bDelivery Status (DELIVS)—RO.& \7 l1 j5 K. b- k
The Delivery Status bit contains the current status of the
# T3 D' u, u$ m' Y+ ^delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit
3 P6 O1 W U0 I; _4 k' kword) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send( O1 a& b' s; Z6 k7 ]
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC) D) m. L" D, W3 J' g( z$ f
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time)." e. f( l2 P# @7 w6 i8 k% M
| [11] Destination Mode (DESTMOD)—R/W.
' ^# X8 u2 K9 T( T( C; j" h f8 sThis field determines the interpretation of the
' \8 L6 O! d! V* z& Z; Z! E. aDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.6 {9 J9 Z3 P2 u( m& r o
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. H* y. h5 e) v/ f+ b/ c
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)# B { |7 c! g7 u! E- P; K
| [10:8]Delivery Mode (DELMOD)—R/W.7 @; R) [9 E7 S 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* |2 D$ ]0 g! i
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
' A/ i2 w& s9 k$ c) jThese restrictions are indicated in the following table for each Delivery Mode.
) N0 k- Z3 _, U5 M4 k. VMode Description
" {) h, r. R7 p! Q. Y( D000
% l }% x1 F; n+ G. H4 F( ?) OFixed Deliver the signal on the INTR signal of all processor cores listed in the
* @7 Y4 q- Q2 K3 ]destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.2 u& [/ s9 |5 e: G7 D! m
0017 x9 E) y+ _. p$ t3 C3 W
Lowest
( l+ b7 N: e" u' W6 a) cPriority Deliver the signal on the INTR signal of the processor core that is; ^0 G5 ~& y: E* \
executing at the lowest priority among all the processors listed in the& d2 e0 Y8 G% {# n
specified destination. Trigger Mode for "lowest priority". Delivery Mode
% j, J9 g/ \# Acan be edge or level.
$ n# f4 w/ ~& o+ Q; h010# j8 Y3 e+ D4 K. u4 G }3 ?2 X6 K3 E
SMI System Management Interrupt. A delivery mode equal to SMI requires an1 {: c( z( E3 }/ b4 e. {! X
edge trigger mode. The vector information is ignored but must be
' e8 m% e4 D) C0 Yprogrammed to all zeroes for future compatibility.
: O6 S' i! ?6 U2 V N( z! s* `011/ ?; A" _8 s" }3 Y( Q
Reserved
# H6 I8 m& ^, d5 q' R& v100- f# l5 t, s( A( u
NMI Deliver the signal on the NMI signal of all processor cores listed in the
) U* T& T% t% c, E9 n. ~destination. Vector information is ignored. NMI is treated as an edge$ E" W. B4 u, X: o' E
triggered interrupt, even if it is programmed as a level triggered interrupt.% L# g2 |3 D+ x% ]1 r
For proper operation, this redirection table entry must be programmed to+ x7 A# L, p U) T
“edge” triggered interrupt.
, q" h3 p0 A) v" m$ H6 ?101
2 e0 \% z% {$ DINIT Deliver the signal to all processor cores listed in the destination by. s) I- q% M" L1 @( p/ ~
asserting the INIT signal. All addressed local APICs will assume their: v) Z9 _/ K1 u9 b
INIT state. INIT is always treated as an edge triggered interrupt, even if% Q5 x& Z' D* q: `0 R
programmed otherwise. For proper operation, this redirection table entry, G- ]$ N$ T" Q5 B- O% A
must be programmed to “edge” triggered interrupt." {' P; n& V0 e/ L' D" u( X; L
110) P3 r+ ^8 d) ^* ?% a( H
Reserved8 f+ f# e4 G, W9 p$ o
1112 J* n5 P0 m6 ?7 ~! U& Y
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the0 ~( ?! p' Z. H2 i# D
destination as an interrupt that originated in an externally connected
2 f2 K1 S1 s) E% x; d3 u/ _(8259A-compatible) interrupt controller. The INTA cycle that corresponds( }, |( c' k; A
to this ExtINT delivery is routed to the external controller that is expected
1 u2 c( `4 q( d3 W, n" Wto supply the vector. A Delivery Mode of "ExtINT"
8 j0 ]4 G: d6 B# Q( y& nrequires an edge
4 |; s, M1 ]) G7 D! G- i/ Strigger mode.: k4 K; b6 S; e
| [7:0] Interrupt Vector (INTVEC)—R/W:8 f( ^7 ]1 I& z4 ?. V% s
The vector field is an 8 bit field containing the interrupt/ q4 L# f {* z
vector for this interrupt. Vector values range from 10h to FEh.
- Q6 K7 n! P2 j7 d6 S- V | ( l, I3 p" m/ c) Q7 q9 K0 x
REFF:
B/ c+ T" r0 M
b8 |# X" F; a% B3 ~$ L1.
/ S9 X( ^) j1 f+ f; G: e H9 p《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》8 x& @3 C$ s- y O' H% q5 a5 T
2.3 n- a0 f; Y/ b6 G$ K& P. {+ L
《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》
2 {; R' f% q5 @! G: R3.- ~6 P9 T5 l4 [( |
《Undocumented PC》
# ~* |: Q' I y' r& U$ y4.
" ^2 f' Z6 ^4 L T& b7 I; Q$ K/ J# j8 b/ u% k0 K j& I- d
8259A初始化编程
5 y: Q. s( P$ c8 v# p
* c; h$ U6 ]8 q1 t) C$ a4 }That’s all!
2 k' n; n2 v5 t6 `
6 Z2 @" K8 }6 ePeter
3 u1 T ^: r v2 u5 f+ B( Q# w5 q; Z0 T$ v' X- D. x L! O( C: t* b8 m& o
2010/10/07$ P M. X9 ?+ j! b+ i$ B! L5 f6 V7 j. q
0 s3 Z6 {* y% ~" D) i
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|