|
|
|
PIC 、APIC(IOAPIC LAPIC) 9 Y" D: v2 Q% A( F
1. Overview
( ^& i$ T: R/ t( |' k3 ?/ h2 y& B* c5 P7 A, v' d
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中! i9 s2 _% r7 g8 ~6 b7 J+ S% @
用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。& c& k' X+ v% X! i
+ e1 L( E+ D+ J1 X
6 B0 e) o. V) K: h0 V- p8 \2. PIC- B5 k, D. E6 v0 h2 s* n1 \
' Y% n3 v5 B4 I8 h. U$ O0 T
基于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/ @7 A, m' s) _7 P: V& }& V, e# }) h6 ^& U
/ j# W+ P8 s$ x* r/ i3 c& v( b$ d
5 X4 ^' R3 Y' \0 @9 w+ }2 y0 J9 g- g
为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:
0 w( \" r' j0 N% Z& [# E
8 M* ]( W& l" A$ Q, ^9 s& M( rMOV- F# w9 j- a% q" ?" d. q
AL,00010001b
/ G8 c. W1 \ S;级联,边沿触发,需要写ICW4: D# c3 I! T7 P/ j- h6 a/ j
OUT( I- i% S" Y( u2 @. F d: V8 f
20H,AL" U1 I# O0 j( n" U5 N- W5 E
;写ICW1" A: w% h1 S4 W/ ?0 e* W
MOV
. X. D* O6 a( K- R% RAL,01000000B ;中断类型号40H3 U6 z% D' f9 s5 U- ?: h& z; K
OUT; u2 w6 w: N1 w$ p
21H,AL
& f5 g, r2 ]% k/ J;写ICW2
5 @ k8 l1 Z0 w. p9 v. V" J8 hMOV
+ `* E- E% J- t1 n! u6 A5 S0 aAL,00000100B;主片的IR2引脚从片
" l2 \- ~% J6 T! }+ e) |2 gOUT" U* O2 c _3 R' m3 V/ \
21H,AL1 {$ B+ q; x) q& N& q; S
;写ICW3; A# c4 W! h; U7 m' q7 @! r2 ^% E F( o
MOV
9 T% D! Z/ X' Y" o: XAL,00010001B;特殊完全嵌套,非缓冲,自动结束# l( m- H: {% R! _
OUT
9 t. f: P! @( }' Y/ M% _21H,AL
; ]7 e, r, M! R;写ICW4
8 V* d3 }. x& W2 c/ y* e3 m# C& L8 g) d5 H, K2 m
3. APIC
" p2 ]& q% `" T# t% \0 f
& W D% ~0 N5 T8 UIntel 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,3 f, W/ t1 B' p6 @ F( s. [2 q
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。4 H5 v% ?0 g8 {- u$ `- L. Q9 p
9 Z- ~3 b% H- [ ?5 i
8 a! ?7 T+ y- l8 C) v
c) C- `5 a" J Y; t5 \6 [1 T" J$ S2 i& [* z; B% H' l6 z# O2 t' l& \
Programmable Redirection Table详细格式如下所示:" k& E$ n; w& z& Z' i: N, y
1 ^& r M- E. ^1 T
Bit Description:
- W8 m9 ^. E- |. x7 U; ~ | [63:56] Destination Field—R/W.7 `! q2 h3 O0 n& Z! V: N% z. w/ B3 o
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits+ p3 f( p. _" k. M% j' p
| [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field# m$ _0 q$ M1 H4 L
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical/ Q5 {+ J, s D6 d9 ]! m; @. K$ E; `
destination address.( l2 U1 p/ J" I3 c1 w% C
Destination Mode IOREDTBLx[11] Logical Destination Address: B% c# \6 U" S( @# S% d- K3 V" M
0, Physical Mode IOREDTBLx[59:56] = APIC ID
- p! }, o4 \( P1, Logical Mode IOREDTBLx[63:56] = Set of processors! ^- a5 ? i& H- i4 t( b. _
| [55:17] Reserved.82093AA (IOAPIC) * M9 A$ S7 Z- g3 e
| [16]
6 L3 W' g: v I" a3 aInterrupt Mask—R/W.
* I9 O- O& a% dWhen this bit is 1, the interrupt signal is masked. Edge-sensitive/ L5 u8 n9 z) _* z" ? j6 q5 ^' U9 a
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).5 ]4 Q( N7 t. F
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
/ R: o& U) W, H0 {. {7 z. b, ?side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
! n) R: t3 a6 j2 qa local APIC has no effect on that interrupt. This behavior is identical to the case where the
c$ ^. }+ I8 D' wdevice withdraws the interrupt before that interrupt is posted to the processor. It is software's
0 m0 k7 a5 E2 L! a: [2 Q. K- j, zresponsibility to handle the case where the mask bit is set after the interrupt message has been* C9 U- G+ c0 i. v
accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this& d: E2 t/ U! A l
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked8 h' o5 }2 x" n0 N; P
results in the delivery of the interrupt to the destination.- \( R$ f* @, y, s" k
| [15] Trigger Mode—R/W.
; W: e$ v8 }. }5 y# b2 F% S3 `The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
* [) G/ N! Y4 j$ A# V m9 n | [14] Remote IRR—RO.8 v3 }% B* H7 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. s+ r& i+ C7 W1 [& j$ F' T% `
| [13] Interrupt Input Pin Polarity (INTPOL)—R/W.+ m. T3 k4 ^/ T2 V; m
This bit specifies the polarity of the interrupt
7 `7 g8 [5 j; ~signal. 0=High active, 1=Low active.
% q) n3 X( q- Q3 J p2 S | [12]
/ \" m! G2 ]6 F+ b0 D/ G3 cDelivery Status (DELIVS)—RO.
. x a# P( U$ k7 Z" } @0 }The Delivery Status bit contains the current status of the
4 g( j, `. U* e/ m9 n1 ddelivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit0 L2 |, Q. n7 q
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send# U! E+ W! G6 c& u! H$ x
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC+ c7 y6 e9 [- F6 ?5 W
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
3 k' C0 b8 ^; |5 r, l* p( h W | [11] Destination Mode (DESTMOD)—R/W.3 h' D' L! G/ g# J
This field determines the interpretation of the6 a. q; W" i$ N6 O
Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
; A( M, b/ b6 A& Y' cBits 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.- \' G, Z8 [8 A* \
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)( }3 [7 s4 t0 ^0 Z7 D& ]. x
| [10:8]Delivery Mode (DELMOD)—R/W.
$ _9 g2 Q( m2 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 certain1 e5 L0 p* N& [' a9 V) J* w8 r
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
7 K x/ {( T yThese restrictions are indicated in the following table for each Delivery Mode.
+ E' P0 D. E& LMode Description
7 r5 l1 T- ~- d% \0 Y; Y/ ~) N# R2 K000
, H3 H3 b _0 A- h" \! i: ZFixed Deliver the signal on the INTR signal of all processor cores listed in the; `( Y! \& {5 G+ q: Q0 r- s
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
. A( A L `7 G001
4 Q4 r: I. C; S+ f' k$ ~Lowest: L- O) L/ u$ z- d7 c3 E: I9 e0 O
Priority Deliver the signal on the INTR signal of the processor core that is) {+ Z% {7 N+ }* f; s3 n
executing at the lowest priority among all the processors listed in the7 y: [4 {2 v' h; S
specified destination. Trigger Mode for "lowest priority". Delivery Mode
% ]6 h1 x4 t5 O+ m# l' S; [* Y- hcan be edge or level.2 b- P1 H, m9 ]+ V) Q
010
2 c& p6 w) {1 y! s. f6 ]$ ?) N7 |% XSMI System Management Interrupt. A delivery mode equal to SMI requires an
/ s3 K; P+ [/ E' \6 E( ]edge trigger mode. The vector information is ignored but must be& z+ p5 C `& E: v; ]1 X
programmed to all zeroes for future compatibility.* q, t- W* k8 _# T3 V/ b, L. Z
011
+ B" `" A) C- lReserved/ V/ i6 D: L3 t
100+ }: ^& ^2 j9 u: @, g
NMI Deliver the signal on the NMI signal of all processor cores listed in the
5 t! Y( H9 P7 @0 Z# ?4 F% ^destination. Vector information is ignored. NMI is treated as an edge
* N/ U$ B) D. b2 D, k4 O2 Ftriggered interrupt, even if it is programmed as a level triggered interrupt.
. r& M2 m0 C, u; C; AFor proper operation, this redirection table entry must be programmed to' Y: ?8 I4 N$ p' q) `* y6 L4 Q
“edge” triggered interrupt.- \# s3 d+ m* S8 Q( h( v9 d9 E2 p
1015 m9 A! L# c( S- q' T5 J9 s' p
INIT Deliver the signal to all processor cores listed in the destination by$ g5 P5 G" Q5 T, v: |! D, A8 ~
asserting the INIT signal. All addressed local APICs will assume their7 M, a2 H# m, Z
INIT state. INIT is always treated as an edge triggered interrupt, even if
/ g9 H! V9 H& bprogrammed otherwise. For proper operation, this redirection table entry
3 r3 J" d- n$ g7 i6 b. M/ imust be programmed to “edge” triggered interrupt.
6 q( F% y8 ^* {' W$ ]110
* P# t) k% h; P( U4 uReserved0 N5 l0 r% B9 `5 c
111
3 |# y/ B. N' J" SExtINT Deliver the signal to the INTR signal of all processor cores listed in the( x1 M! X; _: h) J% ^
destination as an interrupt that originated in an externally connected
( ? T+ w6 U- O2 I% v: @(8259A-compatible) interrupt controller. The INTA cycle that corresponds5 Q9 S, J+ R) i
to this ExtINT delivery is routed to the external controller that is expected) w1 S( m, }7 X' K- [; c
to supply the vector. A Delivery Mode of "ExtINT"; H+ V1 I6 N. ]1 ~$ p, m! s2 d( r
requires an edge
! i8 y( {7 A7 _/ ]8 |1 t8 {trigger mode.6 G# z8 u9 O- F! F1 Z
| [7:0] Interrupt Vector (INTVEC)—R/W:
' y2 b- h( {* m& TThe vector field is an 8 bit field containing the interrupt
" I1 D' e! n# S2 xvector for this interrupt. Vector values range from 10h to FEh.
0 P+ W; G1 K" ? | " G% D( L/ c* g5 ?! H
REFF:
W) X5 _3 _3 p" L, G" V2 m+ W3 k" \8 ~% n$ U
1.
2 ~ S. t- Q# ]( F1 C( \) A/ z《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》
& O/ {8 ^: _5 [4 I6 j$ Z/ b2.
$ ` ?* T. u0 [/ x% o! i$ j《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》
. `9 L% ~: P; g/ W$ \3.
f0 o- K1 N- z' }" e. l; C$ j, ~《Undocumented PC》
$ L1 H/ h( t G* v+ q4.7 W: r, Y/ a8 C6 k0 N3 l
6 Z. k" n: g% S5 z6 m0 L5 p; s! t8259A初始化编程
2 O" e h4 ?5 s/ m! |. [. k2 m/ B: O- e0 | k/ M: J7 q; f7 E
That’s all!* e" {9 I8 B a& m
8 x6 T. b* {( C, V8 ~3 c; d& K nPeter
% m" ?; U( y2 |. Z9 r, \2 A
+ P+ i( Q z9 a$ |" J [2010/10/07
% ?6 W; s$ @3 v# s) |6 A0 n( V4 s1 V# ~7 S& c
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|