|
PIC 、APIC(IOAPIC LAPIC)
5 G% S, y" P1 k8 `: j1. Overview4 z* B Y3 U t: ?
* D& f- Q t) R+ ^# Y/ k) {( ^PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中
/ f5 l7 u: j; D9 \/ J X/ h6 U用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。4 S9 C r9 \! S9 K! M
$ }/ U+ F$ l9 V
) w9 u4 W2 k$ Q: B5 n# C& K
2. PIC
8 `( g, Q, j) O% s7 `2 g M2 }0 X$ _0 q
基于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。1 y1 ?% D# O4 F
# u$ i1 p, n' I6 _& Q# U8 `
/ I. C: ^# j/ Q" @
% B! N( ]! ?; z8 G+ B3 V9 r+ Y, e# C) T0 } }% X
为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:! `4 v+ S5 ?& T H
% T- W5 }, { T3 K
MOV
" I/ t+ j* F, ]AL,00010001b! K7 h+ r, c b0 X" o: ?/ U8 f3 S
;级联,边沿触发,需要写ICW48 H M) h: L' x
OUT! y9 Q6 G, Z) Z( U H( T
20H,AL
. M' n N6 s+ V ?& `;写ICW1
# o7 f: N; P5 J- l, I( G* yMOV6 P, v& d$ S2 [* r4 }4 P: d
AL,01000000B ;中断类型号40H
9 Z2 c% ~& L/ wOUT
7 `4 n5 t/ s' D21H,AL
1 Z9 T& L8 A4 ^/ s% |" T# j( q# H4 T0 T;写ICW2* h6 D) `' J5 V2 k6 Y, B1 ?
MOV
1 q/ w: K( Z5 ]+ H* QAL,00000100B;主片的IR2引脚从片
; C- g' T1 [1 ?) |* l, WOUT# [* @3 R" B* \& t
21H,AL
# ], J9 L' `/ |$ |. f S1 ?* s+ o- H;写ICW37 e2 }) p G$ {/ n0 {8 ~
MOV ~) X% v" p% I4 t
AL,00010001B;特殊完全嵌套,非缓冲,自动结束: u ^, D K& i: M. B& ?+ c
OUT3 k: d6 ~2 x$ ~) Z& Y8 T/ i
21H,AL7 ?2 O* [) m$ A
;写ICW4
& u+ D4 k; P8 H8 z. j+ L$ t' w7 U1 U7 o; a
3. APIC
/ h" ?, a9 Q. [. r. o+ |4 `! B L9 T+ J" C, ?, ^$ W& k
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,
! }# I7 K, W; D* `. M" z/ f9 U每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
1 T4 B7 G9 |" ?% A7 S8 k3 q
( A% q' `$ P- W5 U3 z7 |1 n
* c. |& ^. t: H( j
+ F [' Q% p0 u7 _+ O
1 L9 m& Y+ N& i- P6 z! W9 D& H3 U% v( I
Programmable Redirection Table详细格式如下所示:
% M; f' Q \. W# L, t6 I" N' n! z5 o* Y4 u! m
Bit Description:8 j0 `0 [7 R9 [: q J
| [63:56] Destination Field—R/W.3 T R7 w" b& F0 ~" g
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits& E3 B# y9 J3 f3 b; N: l
| [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field: b- o7 N, E' R) B2 U% d6 h9 z
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical4 b* Z( @ l& y! P- n5 M
destination address.- d$ d/ V. x5 x2 z' Y
Destination Mode IOREDTBLx[11] Logical Destination Address
$ c: O8 t \) C/ Q% `, ~0, Physical Mode IOREDTBLx[59:56] = APIC ID
+ z( K) x2 M3 X$ U) C1, Logical Mode IOREDTBLx[63:56] = Set of processors+ q) K; q. q, n- x5 p
| [55:17] Reserved.82093AA (IOAPIC)
K$ s2 r; G/ O% ^$ y | [16]
! S/ ^. F) o" Q0 _2 f" O1 iInterrupt Mask—R/W.: F8 r: d; X7 z$ G P
When this bit is 1, the interrupt signal is masked. Edge-sensitive+ x' h% r6 I5 J( I* c+ Z" R9 d3 L
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
# g* }8 `# r" V/ Y8 K# bLevel-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
. `/ m" s! t! y9 P' G, a# ]% ^side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
9 s% o1 O/ l! }! ?2 ]a local APIC has no effect on that interrupt. This behavior is identical to the case where the
9 W" D+ ?' ~0 ~3 U& {device withdraws the interrupt before that interrupt is posted to the processor. It is software's
# @5 m# l1 l! e7 \8 nresponsibility to handle the case where the mask bit is set after the interrupt message has been1 U" U8 R7 w' K T- `. q
accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this2 n* [9 ]. p6 o# }5 f+ r' I
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
5 s5 B' t% O( Gresults in the delivery of the interrupt to the destination.2 C( j8 Q) ]4 S* H( e# \; q% R
| [15] Trigger Mode—R/W.3 E" y) W* \! W% I5 q& T
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
% ^. I/ O. } D' D' t8 _ | [14] Remote IRR—RO.
1 U# H) Z* F' V; c1 w$ MThis 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.
# j1 Q6 b0 \$ _6 p8 O | [13] Interrupt Input Pin Polarity (INTPOL)—R/W.
/ j& s# O$ g9 `- T# eThis bit specifies the polarity of the interrupt- A, a2 ~2 z5 j1 d
signal. 0=High active, 1=Low active.
& ^5 @8 u4 A- ?& F. ~3 K: X" y+ U- H" E | [12]! t% S; a l: I- z3 Q+ k9 @$ I# H
Delivery Status (DELIVS)—RO.. O7 A+ f9 ?4 s* c: k; P7 d2 o# B
The Delivery Status bit contains the current status of the* z4 _( _; i6 W" S) t( m
delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit
( ^+ o; c. t5 h5 Y7 ^" Fword) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send2 a9 \ ?" _# e% }+ `- ?" p
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC# }; f- v, \$ N: E
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
7 d8 D. e, g; V' H | [11] Destination Mode (DESTMOD)—R/W.& A- O, |; g2 B1 |# p" B+ H
This field determines the interpretation of the
! @) \; f3 z4 x/ lDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
& d" }, M) B# N XBits 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 ]6 ^9 t8 E; H2 n
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 ]; K7 W( p! R* V7 W% }
| [10:8]Delivery Mode (DELMOD)—R/W.( i. r( B8 x" k; i9 v
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
, ^) c3 Y4 e0 I) A! ~Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.) D/ \% ~1 A3 ?* ?& P7 h
These restrictions are indicated in the following table for each Delivery Mode.
* f+ X+ a7 \8 t [2 a3 d( Q* RMode Description
+ ?7 R; E2 f6 H6 R7 g& `! C000
( ?$ w: V5 T' [/ yFixed Deliver the signal on the INTR signal of all processor cores listed in the5 `/ l+ i2 v1 z* d! M" f' C& K
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
- d( A* {* E2 P2 I9 n+ ]9 e! {001
' U* _. e$ D) i! _9 {0 h. O8 Z2 @Lowest v+ G0 Z% q( g; n
Priority Deliver the signal on the INTR signal of the processor core that is
4 e: c5 y% t: }executing at the lowest priority among all the processors listed in the9 w! y) H/ z r0 N, S2 h
specified destination. Trigger Mode for "lowest priority". Delivery Mode; ^, x7 Z* X8 i8 [( i
can be edge or level.4 O2 C1 w3 _) ^9 J/ D
010
/ @$ s- i" C; J, A, W& cSMI System Management Interrupt. A delivery mode equal to SMI requires an
4 L% K0 @# y% s% L9 H# pedge trigger mode. The vector information is ignored but must be
4 i) ?$ @% f* k, {4 dprogrammed to all zeroes for future compatibility.
2 q* Z# x% |7 ~( s; l# l. U; `0 O011$ ]/ k' b7 d/ E, G }
Reserved
/ F8 k3 f) f/ W6 j2 d' c3 z100
# J4 U* G8 K9 @ Y' Z/ ONMI Deliver the signal on the NMI signal of all processor cores listed in the0 ]. K) L; Z9 H7 R5 x+ ?( A
destination. Vector information is ignored. NMI is treated as an edge
: o4 L' P* Y5 B9 [; w6 ktriggered interrupt, even if it is programmed as a level triggered interrupt.
4 h9 e p8 x4 q2 LFor proper operation, this redirection table entry must be programmed to0 x- Y \, v( g: ]
“edge” triggered interrupt.
3 R$ q2 m) q2 N- p) K! ]3 W; F2 w* D* d# I101
$ n" J/ J6 O& p/ I/ pINIT Deliver the signal to all processor cores listed in the destination by
6 F) h+ u3 H3 v+ t. ]asserting the INIT signal. All addressed local APICs will assume their
& U* A9 n3 \2 I- KINIT state. INIT is always treated as an edge triggered interrupt, even if
# ^. X% {* S4 D9 [2 y* qprogrammed otherwise. For proper operation, this redirection table entry$ K. g; ?, F* y. i
must be programmed to “edge” triggered interrupt.
7 b, ^- ?- E, k110: n8 E* G. |2 F) ?" M' `* g
Reserved
3 A8 o* m: u% p$ S6 t0 @111
. ]. K- B5 s. G" ~ExtINT Deliver the signal to the INTR signal of all processor cores listed in the5 `7 P: \" p( i$ `* y1 L
destination as an interrupt that originated in an externally connected* O# I! c3 U3 H9 w, N$ C3 @/ t
(8259A-compatible) interrupt controller. The INTA cycle that corresponds
& \1 }3 r( v* B. M s, f: zto this ExtINT delivery is routed to the external controller that is expected" r- n/ t" y1 s" z7 K) u! h9 r
to supply the vector. A Delivery Mode of "ExtINT"( F; M, K# C# n. D: [. h
requires an edge. I* I! j1 ^" B6 n; g% P
trigger mode.2 ]! B) a k+ A/ J
| [7:0] Interrupt Vector (INTVEC)—R/W:- h8 b. j% Y+ I: \/ g
The vector field is an 8 bit field containing the interrupt
% V$ L& _( F. `. q( Rvector for this interrupt. Vector values range from 10h to FEh.6 s j. s3 A, v5 D- x
|
8 e9 T( ~0 n' D7 X. W1 O* dREFF:- Z% q6 k# ?# \& g0 E, `
, S# P X) P# G. ~+ r$ p
1." p8 T5 [3 E# E/ k8 e
《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》* C- a5 R3 [! y. O/ H9 u
2.
+ N# Q: r+ `" h% @# i《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》
+ A- @! Q3 Z4 P# g3.3 T$ B1 z7 [/ B/ P% P
《Undocumented PC》/ A- C+ X# r2 B
4.
" E R2 u i) P+ Q2 T) D0 C; ]
4 n8 }! b, |' [8 y+ E' F8259A初始化编程
7 @5 s5 G1 \; [8 J( H# j% U) C' l2 e- G4 ]% A; i y5 x5 T! p
That’s all!# U3 Y9 V/ P, \0 Z) k
! y4 L, K% n( h8 D( I1 {7 w6 cPeter6 V, M' M5 R% r H, G
4 B) k- {* I7 K, n
2010/10/07
- l h8 H! l5 D: w5 W. f" s4 u
! E3 m- Z) d. V9 n) ]1 a1 T[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|