|
|
|
PIC 、APIC(IOAPIC LAPIC)
, Z0 {( y; C. e( b2 U( \, @1. Overview% [! a( l( c- I& l
8 q6 ^% k' B: u
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中
" f% G, _& ~0 A4 i6 x用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。
3 e& O4 W+ q5 n9 q: d0 X0 D' \+ d- c
9 S( v: Y. r; G8 c. {# i4 x
2. PIC
4 T4 o8 U4 T" W% t/ S2 o
7 G/ W# F4 ], N2 p( b基于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。
# T2 w* a; ~1 c0 e T$ M
6 j% h" r& ^0 n! x3 j' m; E: Q0 W
- A; o1 M8 n3 m. A8 B1 r6 N
/ u6 W0 L: [8 P: \
# l, i6 V$ z/ |( u) Y2 e; A
为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:# l8 i1 t6 L' |% ~, k/ B! C J1 v
9 L8 \7 x! q- Z) A* W- c9 ~; V" k) w
MOV
9 S- T* i; O# e( G7 f/ vAL,00010001b
# [+ G3 {4 `( z [5 G! k;级联,边沿触发,需要写ICW4
# [1 J$ `/ z6 q# pOUT6 ~5 D8 e5 k$ X( x% U
20H,AL1 }) Q1 y+ P n! B
;写ICW1
) ^& r( Y+ x+ j( PMOV. { Y( \4 P* L, l. r$ W
AL,01000000B ;中断类型号40H( e& f& X6 a7 Y
OUT
5 K* p+ @1 R! J3 ] h! R# k21H,AL- e* H% f. m+ D% ?7 H1 m
;写ICW2( }; H- l% c# a/ n; [3 h$ @
MOV# d. {! ?8 ~2 Q ~2 @1 [3 C( Y2 c H
AL,00000100B;主片的IR2引脚从片3 E. O+ Q# q4 Y- x* H3 C
OUT) x$ ~6 \0 T8 N& b, c
21H,AL
% V: i9 L2 V) l, T: o- J: d4 F;写ICW30 T2 _; _ S* ^+ v0 k
MOV2 Z8 `4 }, d- X0 |
AL,00010001B;特殊完全嵌套,非缓冲,自动结束) \7 P# J# w- Y: Y
OUT
5 V9 h1 S$ v- e; L* U5 l21H,AL# n; B/ o- {; n; M
;写ICW4
! e9 |5 W9 f2 {. ?
* ~* `* I0 Y3 ?+ Y; H3. APIC. Z+ [* w% n: E2 n ?/ \3 j9 f
: `3 v1 }' o$ R) u6 I* w# N: cIntel 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,7 p0 `/ R4 C9 Q! S
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。" j; U- F3 n) ?2 ^( t
5 x4 z# w! \2 c0 N& L2 a# X6 L8 p$ G" s, E( O- H6 m' Q' k- G: e
, r9 h8 x: S4 S
5 q+ m, g8 s% @7 R: oProgrammable Redirection Table详细格式如下所示:
/ W. g. K2 V# T; w/ V
& o- `' m; X1 J8 O7 fBit Description:* y, T# H: u* _$ m. C
| [63:56] Destination Field—R/W.* S+ s6 U' c6 _$ i) M
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits( R! P0 R) v& ^2 H9 A& s
| [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field: B% `: C5 x- e3 h- d, I
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical+ t( d8 u% m* u/ m) G/ m) x5 _! i
destination address." L4 A7 a4 c J" j m
Destination Mode IOREDTBLx[11] Logical Destination Address
' |( k. |; o# \: [- N0, Physical Mode IOREDTBLx[59:56] = APIC ID2 D6 N3 s1 P' d. N, U* H3 A" N
1, Logical Mode IOREDTBLx[63:56] = Set of processors
# G0 w& ]8 o: u | [55:17] Reserved.82093AA (IOAPIC) G% a v' q; O, b
| [16]7 Q# @. ]* b; Y" f* W/ x
Interrupt Mask—R/W.
( F& I! k1 p. u. {6 m: h3 QWhen this bit is 1, the interrupt signal is masked. Edge-sensitive* y5 J; F* F) i, k# c1 H2 ?
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
' g0 d( ? E8 c$ E TLevel-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no1 k, C$ @: ]8 y8 Q: D4 y' g8 r( a
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
8 z: m2 x' A/ b* l- M8 Ea local APIC has no effect on that interrupt. This behavior is identical to the case where the
8 x) j( w( }7 C8 @. g' L8 |device withdraws the interrupt before that interrupt is posted to the processor. It is software's* V. B9 J+ b0 {2 }
responsibility to handle the case where the mask bit is set after the interrupt message has been, ?: i4 ~7 q6 Q: y
accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this" J8 U9 U: u, r0 M1 ~, A1 U0 Z& U- S3 S
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked' j) P9 j4 X4 H& V
results in the delivery of the interrupt to the destination.
! X1 P! V0 ~( H6 I* S0 X6 } | [15] Trigger Mode—R/W.
; b; M9 u& W! C8 q' S: lThe trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
0 i7 _1 o$ a9 Y" @. [$ j | [14] Remote IRR—RO.3 D$ z6 x8 E _7 c0 ~: T
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.8 r0 n) L( B9 X4 Y8 Q
| [13] Interrupt Input Pin Polarity (INTPOL)—R/W.: m% G4 P; h" ~1 d$ \3 ^
This bit specifies the polarity of the interrupt0 ^8 m2 `+ K9 V# A! y# A: a; ?
signal. 0=High active, 1=Low active.
2 r1 A* _; M$ R! b4 }# | | [12]
4 d+ P8 M" c# o, A' K6 aDelivery Status (DELIVS)—RO.
3 o0 d# a$ o# M+ M, FThe Delivery Status bit contains the current status of the
8 w* u5 r" `4 U( E" L+ `' edelivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit ?7 Q, p% G7 ?" l% S: x
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
5 H2 N1 s L) x2 u: VPending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
, t: q8 _8 w7 k" n( p2 Rbus being busy or the inability of the receiving APIC unit to accept that interrupt at that time)., w8 a5 i1 Y7 g: j, R$ f, U
| [11] Destination Mode (DESTMOD)—R/W.. ^+ d$ P, b1 N1 X! K: J' J5 j
This field determines the interpretation of the
6 H0 a2 g' l- L! E8 s# DDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
- V& G" ^1 a# B/ R" JBits 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.
& p( Z2 O' h' PDestination Mode IOREDTBLx[11] Logical Destination Address 0, Physical Mode IOREDTBLx[59:56] = APIC ID1, Logical Mode IOREDTBLx[63:56] = Set of processorsE 82093AA (IOAPIC)/ C1 V% `, [0 y t% _1 b3 q" F1 L# K4 h
| [10:8]Delivery Mode (DELMOD)—R/W.
# a; E8 _- r* ^1 m1 ~7 N7 l$ _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) {) u) k# F1 ^3 f" [
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
9 N+ w0 K I8 q0 E, m. ZThese restrictions are indicated in the following table for each Delivery Mode.
; e' }3 C% F' oMode Description
6 p- n R6 |2 s7 V5 b000
. {4 z7 J3 y; S* s7 mFixed Deliver the signal on the INTR signal of all processor cores listed in the
, E# l* \4 {. F* M- U) D2 `destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
G$ s$ o! ^9 V1 p0 {0018 r, |' g. {- ?6 I. O; M
Lowest- f) f! P8 I ^9 \# a& c
Priority Deliver the signal on the INTR signal of the processor core that is
1 \6 s3 k0 V& D9 pexecuting at the lowest priority among all the processors listed in the; [' V3 B2 Q) U/ D. O
specified destination. Trigger Mode for "lowest priority". Delivery Mode
' H& P& w7 A7 m8 K6 h6 j" l( Ocan be edge or level.
4 G8 A2 t. R( \010
/ _* s5 M: m5 F& C; _SMI System Management Interrupt. A delivery mode equal to SMI requires an) }1 c" M1 j$ z- t1 ]& R
edge trigger mode. The vector information is ignored but must be( s7 v8 H3 G) J' \* Q; P, _! d9 F) ]2 J
programmed to all zeroes for future compatibility.
9 o1 w( }. Y4 B" C2 X011
7 y, P9 R. p' G7 DReserved
) U9 m% Y2 Q. P8 a Q' N100
4 N* \: M* y+ U. m( vNMI Deliver the signal on the NMI signal of all processor cores listed in the3 c& V# J4 w8 a$ r* d' R/ f
destination. Vector information is ignored. NMI is treated as an edge
; q4 |& j) Q& Q/ Ztriggered interrupt, even if it is programmed as a level triggered interrupt.) L5 E8 R {9 e# g9 k$ p4 Q" @
For proper operation, this redirection table entry must be programmed to
1 g, y/ t; r, I0 R* Q+ y- o- M“edge” triggered interrupt.1 j# s1 D) S$ P6 p; x% |' Q# Y
101
; |/ L* \, \. w- W! NINIT Deliver the signal to all processor cores listed in the destination by, Q _/ D1 G- |2 P2 G
asserting the INIT signal. All addressed local APICs will assume their
+ {! s1 i+ [* T; l" `INIT state. INIT is always treated as an edge triggered interrupt, even if
7 w0 g# [0 r2 `) _* Qprogrammed otherwise. For proper operation, this redirection table entry
0 A8 }( c/ K3 b- @must be programmed to “edge” triggered interrupt.
) ?6 b/ K5 {* u. S! w3 K1 a& @110
+ v+ S* N! }3 Y8 \2 UReserved; {3 S5 B, g# m9 ^# f
111# }0 e8 g0 Z0 Q
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the
) {6 H6 x7 X( c/ x% c0 Y2 wdestination as an interrupt that originated in an externally connected
; O+ n& w$ k i5 P0 x: R ^3 }/ n(8259A-compatible) interrupt controller. The INTA cycle that corresponds
" V- I- Q( n! Y' w5 Ito this ExtINT delivery is routed to the external controller that is expected7 q; R/ K5 R& S3 A
to supply the vector. A Delivery Mode of "ExtINT"
$ K, m7 T, w$ B Frequires an edge4 O% }7 k" b$ ~% Y- Y' L6 @! w
trigger mode.
6 I1 Z3 s: V( h! `0 g | [7:0] Interrupt Vector (INTVEC)—R/W:
! W z. @" v" q# e8 P- WThe vector field is an 8 bit field containing the interrupt8 H2 n: K' ?: v, B0 V, R
vector for this interrupt. Vector values range from 10h to FEh." B& {" l' ^6 ~; t; T+ x& k, A p
|
. }( i2 K( i, W( g( @% c' u* zREFF:& j2 K* J$ J1 d, X- w, G
S- H: O; s% Z9 w' \$ m1.
, r, U/ m6 i; w& M5 S0 A《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》
) e9 B, |- ~. @5 X( ^( d8 H- Y2./ Y# N7 {# \2 F: Y# C$ D
《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》
9 m4 }! D7 ]$ c. @+ Z" g3.
* B+ B- y0 Z5 c# L1 g) i& h3 g% A《Undocumented PC》
$ } i; N. u5 Y4 f4.7 c! y6 G- {& U% J x- d
2 p2 O- O: [+ b
8259A初始化编程
- E3 @- d5 H7 z7 P# Y5 h) m# ~8 ]0 b1 Y
8 D; J$ S! L% mThat’s all!
- y& }, L7 i3 k5 Z' W+ @& x% |' j. X; W7 V
Peter
% Z& q5 M1 u% d1 B9 |$ b; j" c; O
6 q W! ^" x" r' ~2010/10/07
& [" [! A. M4 p; f5 L% ?5 `9 d" N6 D" |2 I( H
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|