|
|
|
PIC 、APIC(IOAPIC LAPIC) 5 Y7 R. h0 D; z4 O
1. Overview9 F% W/ M0 Z& H0 T
$ A0 D a7 \: F5 \PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中' W( K: s" O/ x- l0 O k9 Y" E
用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。
% D& d% ~- h& C8 L& d- V t* p# h) c% H$ l
+ Z5 r% w* y) p# ^
2. PIC
# z: m, t% g0 v- i, B
8 V; A* Z- R( F) f) `基于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。
6 h, ~) l( A5 f7 k7 U3 {* [# i9 F3 C) v6 U3 J
( ^* c7 r7 S0 p
9 T0 M1 t0 c" X0 y u/ B
+ m+ Y, E% S" T# q为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:3 ?! P6 J" |1 w- [& O
: b Z8 d1 H) R+ F& |/ s# W
MOV! r: ^0 [) }% Y2 ^1 b; E* o& i
AL,00010001b p; l+ p% n$ I& F
;级联,边沿触发,需要写ICW45 F" @6 x' T$ G2 V
OUT I- z0 N- k. h t
20H,AL2 }- m- E% }5 u2 [
;写ICW1
. ^7 e$ |' \1 dMOV
3 U+ F! n. Y8 E+ qAL,01000000B ;中断类型号40H
# B: u/ J, z1 C: u- @9 W- I; mOUT
1 Y9 @" g7 N" T. B21H,AL
3 A+ z0 a; I2 U: g' Z" K;写ICW2
% |' n2 b, x& n. O8 `) s0 S lMOV
1 {6 H' B* S2 h# SAL,00000100B;主片的IR2引脚从片
" f5 c f2 w1 R& QOUT; ~" m6 ?7 d4 {* H
21H,AL- Q: p" p( X: l& E) t( z( T, a6 F
;写ICW31 z. G. _% p3 f' a9 T/ M3 c
MOV
/ b/ e4 x4 C. \2 q' p e nAL,00010001B;特殊完全嵌套,非缓冲,自动结束; y6 q+ d7 e) O: F
OUT
; j; |. a1 C0 u; H9 i21H,AL
: M5 H+ k& b: d;写ICW4
2 Y4 k. E; x+ Y& s* \$ P& X; _# ~5 X5 H; r0 A1 n; `
3. APIC
5 a) z# q# E0 N" v9 i) \9 A3 T; X
/ _" p! n: J9 A. A" P, ^! zIntel 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,
) Q3 |/ k5 Y) |; Z1 H! j每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
6 B: S9 _4 S7 \5 |5 T p
2 u) m) u2 K5 e- {: @/ N' c5 Z1 ]5 r; b+ a9 n+ I% N
4 \9 d! p! ~2 b
" b( m( M o* i% d& Y1 cProgrammable Redirection Table详细格式如下所示:
) M0 l& o. p+ ]6 [8 I, n, ?+ g1 i: x8 C. I/ L$ _5 ]
Bit Description:
7 _- }- G6 g; [" d7 f; T | [63:56] Destination Field—R/W.' P( ^5 `$ A0 Q
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits! r/ ]" p k, V2 u1 O5 s# |4 _
| [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field
+ T. m2 g, q' D% |0 B3 ]potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
# ~' F2 q* z. w/ Ndestination address.4 o5 d7 K% q7 C9 A
Destination Mode IOREDTBLx[11] Logical Destination Address! T, [8 l+ D7 g' P1 t1 {& t
0, Physical Mode IOREDTBLx[59:56] = APIC ID% N. ]( q9 f8 |( M$ w3 c+ ^
1, Logical Mode IOREDTBLx[63:56] = Set of processors1 m A1 V5 n s1 F& x
| [55:17] Reserved.82093AA (IOAPIC)
5 p u1 b c" t5 w w | [16]
& r( H6 \4 {% l/ x( e( m, LInterrupt Mask—R/W.# T0 p8 \% R& x5 @! @+ l9 h
When this bit is 1, the interrupt signal is masked. Edge-sensitive9 `* T3 J; N# H5 E% K/ g# {6 T, O
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).2 Z2 _7 s4 h9 _4 Y2 |3 C9 l4 `- B
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
1 e) W6 ^7 K; _, Q Mside effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
8 u$ I! R% u. t9 r# H" W! D' `a local APIC has no effect on that interrupt. This behavior is identical to the case where the
+ t: c$ X+ n& q' J, gdevice withdraws the interrupt before that interrupt is posted to the processor. It is software's. G, Q4 m) b) O _7 T$ _. Q; m# r
responsibility to handle the case where the mask bit is set after the interrupt message has been4 u' b" J; Y9 k
accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this% V% H. ?# p; c: ?- }
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
* o% h6 l7 ?/ B$ y: bresults in the delivery of the interrupt to the destination.
4 s& t& E* @2 _0 a% k' t | [15] Trigger Mode—R/W.- o2 Y p( u" _( b2 J3 n" {, e
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
- `' V6 I3 T Q3 K& A | [14] Remote IRR—RO.
3 o. S& A4 R, u: C" k' sThis 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.! a; v( Z \5 S% ]) h8 a% Q- S
| [13] Interrupt Input Pin Polarity (INTPOL)—R/W. _" e/ A5 A: Y
This bit specifies the polarity of the interrupt
! z1 {6 ^8 `1 S& \8 O, osignal. 0=High active, 1=Low active.
4 _9 L2 R( T9 j+ N% A M/ {" Q | [12]$ n! E6 t$ G# g0 [# h# [* A2 ?
Delivery Status (DELIVS)—RO.
0 s) z( x! [* V* @The Delivery Status bit contains the current status of the* ]( K& a3 H( I/ m
delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit4 r, q7 K/ _& A' ?. i
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
* F9 `8 N1 M6 NPending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
' }) f+ r1 N l4 R# p6 V. |3 _3 xbus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
/ t' h' D- S3 s0 \) N" q) C | [11] Destination Mode (DESTMOD)—R/W.. \. l& G/ ]* f) e) p2 a: J
This field determines the interpretation of the# T: i4 \, a- _' @
Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.! S, |# e, f! B1 G( h% \8 \$ N
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.
! j6 O3 F: ]- W, b, X2 }$ m9 gDestination Mode IOREDTBLx[11] Logical Destination Address 0, Physical Mode IOREDTBLx[59:56] = APIC ID1, Logical Mode IOREDTBLx[63:56] = Set of processorsE 82093AA (IOAPIC)
& f3 T1 O# N" ~- Q | [10:8]Delivery Mode (DELMOD)—R/W.
. ~ s* W2 n4 g. ~ C1 l& m$ xThe 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
( d) {2 i, `$ U& W" @$ IDelivery Modes only operate as intended when used in conjunction with a specific trigger Mode., u* r& B! i, q; s7 R
These restrictions are indicated in the following table for each Delivery Mode." @* J% ?* ?: c0 c
Mode Description
1 _: d* E" m, i( c' W" f( v000
) | l3 X# `1 z2 K8 ^+ WFixed Deliver the signal on the INTR signal of all processor cores listed in the
. ?- V+ |& O4 S3 u) k' S# Xdestination. Trigger Mode for "fixed" Delivery Mode can be edge or level.; L" T6 t$ _9 D
001: ]$ ~, [ g0 m2 |/ }; M
Lowest
1 \8 w7 M5 P$ E: e/ n0 e; RPriority Deliver the signal on the INTR signal of the processor core that is' e6 N; `7 G7 B- J1 d: {' n$ ]9 H
executing at the lowest priority among all the processors listed in the
* G( v' f/ H; U$ ~; uspecified destination. Trigger Mode for "lowest priority". Delivery Mode
9 T) h% @3 m, p* r; S, scan be edge or level.
# H8 x# N6 m4 d& |$ m4 N010
1 O0 T7 `9 X6 V1 M8 h b* \SMI System Management Interrupt. A delivery mode equal to SMI requires an
& M4 x }) t& b5 W. wedge trigger mode. The vector information is ignored but must be
. M [8 {* q* A! sprogrammed to all zeroes for future compatibility.
6 J1 {& W! }( _: v5 _0110 @; h0 x& n' Z& l8 l, m1 A7 }9 h5 T
Reserved
$ T* p2 p( S7 a0 W4 s100: |, v# P$ N1 J$ a
NMI Deliver the signal on the NMI signal of all processor cores listed in the
# Z0 z: r. a3 h- ]destination. Vector information is ignored. NMI is treated as an edge( r* g) ]- j1 m# G+ g6 c0 Y, S
triggered interrupt, even if it is programmed as a level triggered interrupt.
: o$ X; _( g zFor proper operation, this redirection table entry must be programmed to: e: s2 Q+ y2 a: j
“edge” triggered interrupt.
/ P3 X" Z0 t/ |* d3 |101" [% g2 L0 W9 d/ N) M& s7 o
INIT Deliver the signal to all processor cores listed in the destination by# q N }9 U; i9 v" L
asserting the INIT signal. All addressed local APICs will assume their
1 ~' o& W8 s# ]INIT state. INIT is always treated as an edge triggered interrupt, even if* J; x3 P+ N' e5 x; W
programmed otherwise. For proper operation, this redirection table entry% m1 F# U. L0 J4 f4 `
must be programmed to “edge” triggered interrupt.
, B1 S; P* _0 {! e8 j: B1109 F. I9 M; R6 G. s9 f. d( a& w
Reserved
H3 Q5 W# b6 |5 K6 r3 G111
/ P) c' Y+ f7 {ExtINT Deliver the signal to the INTR signal of all processor cores listed in the% }" d# [. c2 F) _6 I
destination as an interrupt that originated in an externally connected
1 _0 @6 y3 a$ f( }5 G3 A(8259A-compatible) interrupt controller. The INTA cycle that corresponds
' X( ~, i6 F4 L5 C4 F( n$ p& p1 }to this ExtINT delivery is routed to the external controller that is expected
9 @2 ^# W% G% `- m( I4 B' X( tto supply the vector. A Delivery Mode of "ExtINT"
+ f% ]( C" D1 _: F9 |requires an edge2 H8 K' U& i. f# d& U
trigger mode.
; B# i" P4 x% L8 \0 S% K | [7:0] Interrupt Vector (INTVEC)—R/W:' E6 S% i2 ?$ `0 U
The vector field is an 8 bit field containing the interrupt, r( [, K8 ~* ?1 e& B
vector for this interrupt. Vector values range from 10h to FEh.' {8 ]+ T: _. y' X. E
|
5 Z# c! }/ e7 R8 j: v4 T4 \REFF:
4 z2 R. o, i0 g: w e/ ]2 a; ]1 b I
1.$ Y/ l p, y; Y0 }7 V
《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》$ K$ m( N: D" e9 n3 l' ^7 P) W0 C5 @: i
2.; k* F1 L5 Q$ Z8 s0 d
《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》* J2 J5 W4 f+ n: K
3.5 o- L3 ]. u( G- | W+ \. G" L
《Undocumented PC》% U0 i- r" S6 |7 u5 R- `
4.
/ |! [$ k0 D3 q7 S! R. l# w* l, {0 \
8259A初始化编程
! g: z0 S+ D% J: ?) p7 B
( |0 ~8 b* ~1 N5 ~6 i( x1 s% pThat’s all!! R7 ?0 T$ g9 X) q; v! {
8 C$ o2 [( z7 x1 _' x* ^7 F. A2 gPeter! Q) F) u' s- c( u7 S
; }8 w+ s% \5 n; ^8 u
2010/10/077 M3 Z, F/ g5 C! T& n
# C- m- Y( Y( x. {% o[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|