|
|
|
PIC 、APIC(IOAPIC LAPIC)
2 J0 U+ r, [" ?7 ~2 X8 A1. Overview
# l( v. w2 c( Q5 @2 k( r
6 C" w& x* s3 ^! k$ P# ~# F# dPIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中
* C7 e" C) y3 _用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。* G) c2 c7 L) O2 s2 e/ Q
; Y$ w; M( K) a' m }- @9 Y/ |8 A* Q9 w) {( Y, H* L# ]1 _: Y
2. PIC
$ o2 \6 O' Z. z0 x5 E3 V' w0 V% _* b6 S5 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。
* t& Y" ]$ _5 F8 x0 p) e, f$ V- H: M# ^ Z) ^, }5 W( W v( K$ Q
0 z: g. _2 V& g$ y: x6 X
! r+ J9 ~# U. j: ^& }! n* ^& ]! m9 `
为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:. m9 j3 }: N q9 c; L6 p$ W6 I: |
4 h6 W3 t) O+ J/ x( ]6 x- \
MOV3 F& _4 }# M2 ?7 M' e: V% V, R
AL,00010001b$ e/ \. t! P4 E: F1 c) {
;级联,边沿触发,需要写ICW4
: D Q) C) \/ fOUT
& c7 H$ c$ w4 L2 A( q20H,AL
- \1 l! H9 f+ D% K0 t- N6 M;写ICW1; C( H$ w- @# v+ {! ~" @
MOV
. [3 U& b- u- L HAL,01000000B ;中断类型号40H
; I" K7 P0 ^ H! a5 `& G5 s4 X9 u9 _OUT; w" Y# ^8 R7 P- V3 u
21H,AL
5 V8 T ]' Z" l4 j% N;写ICW29 H, y6 n; Z1 i! G V$ ^- z+ m- ~) E
MOV/ J6 c a6 t) X4 `6 b6 `. R0 x
AL,00000100B;主片的IR2引脚从片: t4 y# e' G1 L, l( `% Q& [' p
OUT
- B8 m1 \+ w( b: |- C21H,AL
& ?; }5 T) T2 e6 x;写ICW3 C5 a0 T7 }7 s0 v; c* ~
MOV
! y1 F% d( R* zAL,00010001B;特殊完全嵌套,非缓冲,自动结束! S2 t% i: f5 g! J+ \, K& K
OUT4 \# F) [6 y$ P1 {) A( |+ ~
21H,AL
+ C F" D8 y8 I6 d, t, w;写ICW40 O1 O5 }7 P7 t7 A Z, z, Y- J5 y
6 d W/ F: Z) W/ Q
3. APIC
( N9 m+ ?/ d3 v( F1 j* E
/ Y+ R; Y1 T% nIntel 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,* }/ Q/ ^2 ]7 k- \# A# F
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
f9 \' X- s' }: c5 M+ M8 [
. y' J. f8 i3 ~ r6 |; f) S# u: l$ ?5 j$ W
) g' M+ z* \1 _$ t7 p. D" l, G
4 C$ J7 D3 Y7 Y. y: f% S
Programmable Redirection Table详细格式如下所示:9 k1 N4 b8 A. ^! u% l( Q
3 s8 A; t8 ]( J0 B9 Z' V8 u, \Bit Description:% v- }$ o B5 A4 j, |5 m
| [63:56] Destination Field—R/W./ a8 l* _3 y: O4 X0 ^6 ]# |& B
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits3 V9 \# ?: `/ s5 ]9 o1 s2 d4 h# ?7 R
| [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field! f0 F# r/ W9 L; S5 |4 B( J: D
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical* ^" e! G# J8 Y) q) R
destination address.
2 _8 C8 `0 O+ NDestination Mode IOREDTBLx[11] Logical Destination Address6 V4 E( N& k( S, c) G+ y2 ?
0, Physical Mode IOREDTBLx[59:56] = APIC ID
; Q5 B0 D3 f* W$ F1, Logical Mode IOREDTBLx[63:56] = Set of processors8 V, h9 y: S* h! r7 j
| [55:17] Reserved.82093AA (IOAPIC) & x, }: |* e7 e5 j
| [16]
3 n( D7 O' ]( |5 \; aInterrupt Mask—R/W.& e0 W* [1 N) A* ]
When this bit is 1, the interrupt signal is masked. Edge-sensitive" d$ Q* ^, A7 c6 Q8 k& B
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).- M. ^5 K3 A+ F& v7 F' [: J0 @3 b
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
' B0 V! X# S s: Aside effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
$ `, a, P9 V- S$ g! C; ua local APIC has no effect on that interrupt. This behavior is identical to the case where the
8 R/ I" t& C% m+ z$ tdevice withdraws the interrupt before that interrupt is posted to the processor. It is software's) n% T. p x2 ~, a) P/ M" Z( F+ o- k; G
responsibility to handle the case where the mask bit is set after the interrupt message has been
# a9 ^7 I- v$ j. d3 Xaccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this O1 q5 l! [2 J; F( k! g G6 E
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked& N5 k L) O* J) l3 t
results in the delivery of the interrupt to the destination.* ?& l. _! O4 N4 ]' @
| [15] Trigger Mode—R/W.
2 }# l0 i$ z9 ]/ z% t9 S4 AThe trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
/ _7 s. f! l1 W: U8 t' n( r) R; Q; q2 B2 Y | [14] Remote IRR—RO.5 k/ v( @4 ?1 u; d
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.
+ {2 X/ F ^ Q | [13] Interrupt Input Pin Polarity (INTPOL)—R/W.
( S( G( s2 r) |+ J3 LThis bit specifies the polarity of the interrupt0 q1 p7 o2 t$ P9 D" u
signal. 0=High active, 1=Low active.
: \! I* i, T A" n# }7 A& w& M5 B+ ~ | [12]: O4 w$ x' ~9 {: r. V3 c
Delivery Status (DELIVS)—RO.
8 n' U/ I! v7 p! O5 Z- R) OThe Delivery Status bit contains the current status of the
- H8 q% _' b2 p& p$ \6 tdelivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit
" C1 `* F/ M/ K! U5 [- i$ nword) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
' b @; N( W- L: j+ Z3 p3 W9 Z: u( iPending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
5 s( I- z+ w* Z+ m1 i' Kbus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
7 Z: q7 u& N8 t9 `& M' E | [11] Destination Mode (DESTMOD)—R/W.
! c+ U8 Q& d( S ~) ~/ IThis field determines the interpretation of the4 c$ D( O7 y' a0 W
Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.$ _1 h- b/ M$ ?: z9 x
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.& V8 c! g- R& e& A1 N! b
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)2 I* G$ u9 Z# l) T7 {8 a. f" U2 t
| [10:8]Delivery Mode (DELMOD)—R/W.
& z; x, x8 p& W, ]) d1 h4 ^. |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
. {4 o& w' u- [) Y* ^Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
- v6 q/ o+ a' i0 kThese restrictions are indicated in the following table for each Delivery Mode.
5 J3 z; \! K- IMode Description
8 O! I8 W9 w5 r9 l! I+ o' C+ m4 A000
/ i$ S: u+ U& M+ _9 g* f( uFixed Deliver the signal on the INTR signal of all processor cores listed in the
0 X+ Q- G6 `0 }$ |& O/ b0 Q3 }destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
& G9 I6 J3 L- `. f0014 N; W0 T1 V3 u% S6 {, U
Lowest: v; Q! L& e- F! Z
Priority Deliver the signal on the INTR signal of the processor core that is/ R& F% X7 a O% c' \: I& v
executing at the lowest priority among all the processors listed in the
* o. |! {% _ }1 Q; v4 C+ vspecified destination. Trigger Mode for "lowest priority". Delivery Mode" j& H, H/ u. V8 `' H' ]
can be edge or level.
H& R8 ~6 _( O3 W! _0100 a. L& ?6 t7 R" g0 I- a
SMI System Management Interrupt. A delivery mode equal to SMI requires an4 k! {, i! f7 T2 f4 c% h
edge trigger mode. The vector information is ignored but must be
7 C- n. Y8 x4 H( Eprogrammed to all zeroes for future compatibility.' {) a2 F; O9 T: Z& Q. z1 ^( `
011
& H4 G4 s# d: @+ ^# X% `& JReserved
2 t+ q2 n$ L, p/ A' P! e1003 L! |: Z$ l u) c+ R/ a3 v0 V
NMI Deliver the signal on the NMI signal of all processor cores listed in the
5 G7 G# @7 q* M5 Fdestination. Vector information is ignored. NMI is treated as an edge
8 m. G7 T" L5 `4 utriggered interrupt, even if it is programmed as a level triggered interrupt.! o" ?7 {) j" V5 H# t
For proper operation, this redirection table entry must be programmed to! {% k. i. }! e8 |. X+ O
“edge” triggered interrupt. v9 ]/ U: k* R9 [; j8 w& A* D
101
* y$ `! b$ Y2 p7 gINIT Deliver the signal to all processor cores listed in the destination by
4 m( f1 c8 y7 S a( S2 T4 A# masserting the INIT signal. All addressed local APICs will assume their
8 I+ W, F; N. qINIT state. INIT is always treated as an edge triggered interrupt, even if
' m% F- z( a# e# Rprogrammed otherwise. For proper operation, this redirection table entry
* S; ]; K) k2 {% f8 p+ X3 }must be programmed to “edge” triggered interrupt.
3 Z7 B5 Q* c7 Q7 Q: Y3 A$ K110
; g. o: Z1 a, {9 p: C! a0 tReserved# G- M: J5 c# ~1 z$ R6 y
111! ^( _0 o4 Z9 P8 [
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the
1 I/ T* X. i+ V6 |& t" F: \destination as an interrupt that originated in an externally connected
( g3 h4 T$ E0 D(8259A-compatible) interrupt controller. The INTA cycle that corresponds4 V5 z# k9 _" H e5 p7 u
to this ExtINT delivery is routed to the external controller that is expected
# o+ z- _# @ V; ^8 {, R' H* V2 {to supply the vector. A Delivery Mode of "ExtINT"
' @" m; T# y5 R P! @8 srequires an edge
" J1 ^9 Z/ R1 N0 Z5 \trigger mode.
; [ W! b, q7 G | [7:0] Interrupt Vector (INTVEC)—R/W:7 y) R4 W& p8 L* m( I1 h- z$ q( P
The vector field is an 8 bit field containing the interrupt
+ q5 u, q7 c. Z6 K& p- ~6 Ovector for this interrupt. Vector values range from 10h to FEh.
/ s/ J# F$ k9 F" q. { | 2 q& B7 v( J5 W, e7 M( G
REFF:
9 p' k5 s7 M8 W# y1 m2 w8 V5 Y5 x8 y3 U5 x# U0 ~
1.
! e V) e5 e: M4 d《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》& H/ P/ d4 e- ~6 o; V( l) X
2.
: r. A& T" o; D6 T" R/ M《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》
: S, {, {/ p: n& q3." d8 Z: F# n0 F/ C, U, C
《Undocumented PC》
) s: ]! k+ K& D9 j* u9 r4.
" l2 q+ `5 f! C- g R) b$ m7 U3 i$ L" M' w) I
8259A初始化编程
' [* |: R4 G! j
, o' S1 M+ J1 D4 l7 MThat’s all!
w& P& ^' k1 E/ u* X0 L) \: a3 A* F* p; [
Peter) c' m) P% R6 d) q2 A
, [' L6 o/ p& B: m+ t2010/10/07
5 C7 [. D: ?9 ?, {4 d1 H8 S8 b( K; |$ d/ A8 u( V7 i/ X
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|