|
|
|
PIC 、APIC(IOAPIC LAPIC)
: G4 }6 \- f! U. b& Y# x% v! x1. Overview& k% B% M: X6 F5 s1 D
* C8 T9 L8 k; d- O
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中
7 `. J7 T. k+ X. |/ L用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。2 U8 Q" s. c- z' @! i) m
" p. r( I; C# {$ v. Y& h8 G
* D. H. D. t- m |# O: Y7 |
2. PIC
7 f0 \. i- c6 Y, U0 ]! {/ M- W7 k# g$ ^
基于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。
$ C$ E1 Y/ o- U0 N6 {& N
8 l4 I- l* z0 U6 Y( Y% D
5 t2 g" _7 v" M! [: Q
( e) ]8 x5 N1 x( j0 J
: v7 J0 k; F( {/ m! F' }
为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:
5 ^3 r' d* |# U/ g" [8 x
( c# \: L0 H+ m; w. s7 u$ F; e5 uMOV! `6 ~, _( j) V; p8 ]
AL,00010001b
2 N6 h7 V, u1 L6 I+ x;级联,边沿触发,需要写ICW4$ l; h" i8 K8 W( M6 u
OUT
4 I( q/ [. p6 o% }7 o20H,AL8 T6 v) q+ H8 m5 P6 I% E' G% |
;写ICW1
7 n( t3 R! X {/ M/ `4 U+ x$ r; @MOV" W. q6 s3 z# L: W! J9 g8 K
AL,01000000B ;中断类型号40H
: @, e: |6 w% h$ ?; z* X. dOUT3 Z6 z, d9 T3 X$ `
21H,AL3 n" O. a i u; ~- {2 Y5 q: \" |
;写ICW2
& e6 p9 \) \! p4 E1 {* B3 W( ?. D! XMOV, Y o9 k& t8 T# I8 Y
AL,00000100B;主片的IR2引脚从片4 I, f; Q3 u! V
OUT6 {7 r; X/ [; l1 T8 h8 S8 m
21H,AL
6 S6 e9 m$ S+ B9 Z) X;写ICW3
$ o& N! C# P5 [7 o) m/ C: D @MOV
7 ?5 X" h8 Q( Q0 z; ^AL,00010001B;特殊完全嵌套,非缓冲,自动结束
! z- z- B; U/ L8 \) pOUT; M1 V' l0 X5 t+ n
21H,AL" l, q; l7 ?' }; B: b; q. i
;写ICW4
' A. k) F7 J- Y! x! K
* F; {$ M. V1 x" D9 P! t/ Q3. APIC2 L1 h- I j( `
# l/ X8 o& D9 @$ C5 W& Y" ^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,
g8 {7 \+ p$ f. E3 m O( \每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
% p, t. B# o1 ]4 v) l3 u" v: v" H8 S1 Q2 a
; T" |8 }" w9 N' }$ m# b
, F% l7 D% C4 C
& s) B0 [" z1 [Programmable Redirection Table详细格式如下所示:9 @' S! Q( v4 V0 F- c1 i
) \) K" y: k9 U: g# i- b
Bit Description:0 a" d! B1 Q) [: i4 i; h
| [63:56] Destination Field—R/W.# i) S' e3 o5 g% _
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits
% Y- D! k2 s5 s | [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field
% J o) Q1 ~$ u) d1 }potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
& E4 { l+ h; \* O: |3 s( ^destination address.
/ J; ^& i7 A. ]/ JDestination Mode IOREDTBLx[11] Logical Destination Address5 E6 X4 X( a- ^1 D7 c$ b0 M
0, Physical Mode IOREDTBLx[59:56] = APIC ID9 ?1 a4 o* Z" [ q, B' L
1, Logical Mode IOREDTBLx[63:56] = Set of processors+ _- i* D8 `2 x3 u
| [55:17] Reserved.82093AA (IOAPIC)
4 }: Q5 F5 z/ _9 q | [16]1 c* Y( |, r) j; N+ C
Interrupt Mask—R/W.
, ~* c& n) e9 H7 vWhen this bit is 1, the interrupt signal is masked. Edge-sensitive$ O9 I0 K4 v: \4 c
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).# ?9 j/ l* q* \) P& N
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
7 z. s, L+ H# f3 F6 |side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by* Z# m1 Q3 ] t) }5 s4 n3 H
a local APIC has no effect on that interrupt. This behavior is identical to the case where the: [8 Y9 B3 K5 ?/ {
device withdraws the interrupt before that interrupt is posted to the processor. It is software's' `4 _0 v% C7 P# L9 p
responsibility to handle the case where the mask bit is set after the interrupt message has been9 l3 O& @+ J9 Y2 f' T/ o* Z
accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this3 D2 F* U7 T8 K( N, H* E
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
+ v [4 p* S) G. d2 A. g! Sresults in the delivery of the interrupt to the destination.
7 O" v! U J5 |2 x4 K% G | [15] Trigger Mode—R/W.
# y6 j1 f) c P# \' Q/ ^The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
' k' C. f! L" k% w' g# c1 c/ M | [14] Remote IRR—RO.9 F: ?9 f5 x& t3 i0 b
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.
5 b, t1 b& s( t | [13] Interrupt Input Pin Polarity (INTPOL)—R/W.
2 }, u7 U$ K V. jThis bit specifies the polarity of the interrupt
; X: r2 I6 u. P0 y5 F! a: R& asignal. 0=High active, 1=Low active.
( _/ x4 R9 N; G$ H u | [12]
% r; M. {/ H" KDelivery Status (DELIVS)—RO.; t8 a( G. q1 P7 x5 e2 u* \
The Delivery Status bit contains the current status of the
, B6 u3 |! L6 ?6 s- g- W7 Rdelivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit, V8 C1 x9 Y0 K: f: N8 _6 N$ P; q
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
8 ~! P/ z* j3 z4 { {& pPending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
& J* O9 {" \4 k1 H6 P* m+ Wbus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).- h3 {5 ^2 I# Q5 z$ }, V
| [11] Destination Mode (DESTMOD)—R/W.6 K# ~$ f1 U% a! i7 o% A
This field determines the interpretation of the- B3 Y5 S" h# M- |$ F; E
Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.0 [, P& s* H1 G7 s) N% f
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.$ C6 g, N5 P. O, o' ^0 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)
0 o$ ] e/ L2 w# d5 j \8 s2 i | [10:8]Delivery Mode (DELMOD)—R/W., F+ Y& C$ P8 d1 r9 D2 O
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( P/ s' t& H. C. u
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
$ ]2 E n T0 T1 a( LThese restrictions are indicated in the following table for each Delivery Mode.
' I0 q$ b" {0 e. K) V. U$ C g& @- DMode Description
2 u7 `& a, E+ @) C) \000
. m3 y0 d! v+ X1 q" xFixed Deliver the signal on the INTR signal of all processor cores listed in the! |, }- u) B1 Q) b9 }7 ?
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level." ^6 I+ F8 z0 ?8 g/ j- M' S
001
4 J3 c# e# w- e! W+ { |Lowest+ W4 L' H4 I; A+ t; V4 u
Priority Deliver the signal on the INTR signal of the processor core that is" B# X& W+ C8 t' Q* }
executing at the lowest priority among all the processors listed in the6 [" p% ^/ _/ f( \- k
specified destination. Trigger Mode for "lowest priority". Delivery Mode D" z" R* a. _, j$ o! I8 Z1 T
can be edge or level.! w" ^- H" |( @: G7 r
010
4 X1 l$ Q0 R! ~1 c- Y! dSMI System Management Interrupt. A delivery mode equal to SMI requires an$ A. ?7 e1 t f, i$ G) ^
edge trigger mode. The vector information is ignored but must be* b+ m4 i' R6 C; Q# Y8 q
programmed to all zeroes for future compatibility.
. D* J' F; L1 t! _9 v011
& H1 z" O# x1 Q# LReserved
9 [! L$ Y2 I, ]100
8 Q" o( I9 I. ]5 O3 mNMI Deliver the signal on the NMI signal of all processor cores listed in the3 P3 A$ x$ C; v( c4 T# N
destination. Vector information is ignored. NMI is treated as an edge& D% e6 c' U h7 ~
triggered interrupt, even if it is programmed as a level triggered interrupt.
- P. k* j# U0 p. X4 J+ u- K9 nFor proper operation, this redirection table entry must be programmed to6 G! w" _3 @, w4 W! z7 u5 X
“edge” triggered interrupt.
; [( m/ S) h+ p J5 O. ^1 _101
1 {; b* W" k- y* ?INIT Deliver the signal to all processor cores listed in the destination by
3 X2 [4 j3 k0 t& N! y: F U; Nasserting the INIT signal. All addressed local APICs will assume their$ u6 q( Y- C. g- q
INIT state. INIT is always treated as an edge triggered interrupt, even if: T2 F6 ?; B8 ` l. O y
programmed otherwise. For proper operation, this redirection table entry
3 U* I0 B% i* R& i5 m# Gmust be programmed to “edge” triggered interrupt.! Q* P; A+ O9 V! T, ?
1102 c2 {/ Z; _( w, N% B2 J7 e
Reserved
0 e4 _' l& w# {) ~2 w/ b. [2 F111
4 r1 d2 M: i, D! G' P; ]ExtINT Deliver the signal to the INTR signal of all processor cores listed in the$ P9 l8 V8 a9 a* M \! I: P
destination as an interrupt that originated in an externally connected
4 n# F! E/ a, T1 ]+ O/ p( {(8259A-compatible) interrupt controller. The INTA cycle that corresponds2 j! f# f& e" Q# G9 }2 o) y, T
to this ExtINT delivery is routed to the external controller that is expected
7 t) s9 z' p& I9 O( M+ ]to supply the vector. A Delivery Mode of "ExtINT"; K5 }2 \9 r) U4 h, _8 M
requires an edge# |. _+ a8 V6 h, p; O, j
trigger mode.) r9 D9 b/ Z( g: t, x0 t# p/ f
| [7:0] Interrupt Vector (INTVEC)—R/W:
. h% ?0 }/ Y/ L. mThe vector field is an 8 bit field containing the interrupt
% ]0 X0 \ W. N+ d/ @1 I# vvector for this interrupt. Vector values range from 10h to FEh.) p: g( a+ w$ V6 C& L% k
|
' K' p% ^9 t' c! y7 K o3 C3 CREFF:7 f0 \; u9 q0 R* O' m
2 S# \: u3 a- r, i
1.. t! J2 O; f$ k* }
《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》6 q( O4 ^1 q W+ f+ Y
2.; V9 y" a ^ s4 g
《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》- [* C- j+ b, p8 R# P
3.
$ K6 y7 I- U' j: a6 v! I U《Undocumented PC》, B5 t9 p+ F z- i' x
4.
8 I9 |( }+ ^$ I7 f. m- f- [
6 `: y3 r7 C- v9 S }1 k: s" G8259A初始化编程9 E/ _' c* ]: {# M+ f
" C1 F' H, Q% d7 _; B
That’s all!
1 T3 _2 f/ Z0 H( W- q4 @
* i4 t4 n. W5 i" @0 P, c* h: fPeter
" G% ]! N# u, s( N$ L" @' I. Z" X/ B
- `/ K9 @( o9 x& a2010/10/07
. q, S- |1 I2 h& @% ?* t/ S+ n) k- J8 J' T" Q
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|