|
|
|
PIC 、APIC(IOAPIC LAPIC)
4 k8 J6 u: L9 [- `8 F2 ]) I: Z V. s1. Overview
. q+ e" \0 u3 }7 V3 O. D _$ J/ E8 R5 i* P) K) m
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中
& \ |% V9 ] C0 }! B用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。( z4 K0 l/ t2 n1 A( |
2 Q) G* y5 e; u; h: V' [! U! b. V! e8 R3 a7 {7 m" g
2. PIC
1 X% h$ _: h1 m% k+ R
* ] u z: p# X! l# e基于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。
+ I( `# T" H0 N6 N0 F) _$ o3 V+ |; s& |; t2 _0 Z1 F. N2 i8 x- p
! L9 Z1 `" n6 F/ N7 j0 ~. X6 m6 f
* G8 {$ _' I0 _/ [9 ?0 x# a
7 S2 s; h2 t* q' g: g% p4 g; s为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:( V) E& f# P6 Q& J) D, j+ j
) o% J9 Y+ H- V: B, d5 QMOV7 Z& b# o* M! l0 G: |
AL,00010001b$ ~! c* d+ X- e i: f
;级联,边沿触发,需要写ICW4
}% r* C! k4 l# i: c* A: i7 e) SOUT i9 S0 K* r) M r# u0 Z
20H,AL
9 K7 G( `- p# F) g8 M, Z% T% |3 W;写ICW1' w/ C ]$ F& Z. ?. r
MOV
; p2 X2 q! w! b$ p% z% U& G% [AL,01000000B ;中断类型号40H+ N9 ^: }) ^; K0 I q: L8 W1 ^
OUT
J. ^: T: p! [% Z4 `0 l& C P21H,AL
5 F& Z. [0 P3 W, P2 y;写ICW27 Z! |. D6 _+ Z% x q1 u+ o
MOV
3 z2 P9 I2 |( D9 @AL,00000100B;主片的IR2引脚从片- Y) I- B' A D# q7 H
OUT
1 Y6 W8 o& {7 q# F; d/ u, S21H,AL( }, l0 Z# J5 M" }5 B
;写ICW3) e+ U5 {9 r2 a- v$ P3 G: B
MOV0 X. M5 [: f9 P) t( p7 | P9 y* l1 E
AL,00010001B;特殊完全嵌套,非缓冲,自动结束2 V3 ` c# [# {) K
OUT: v1 E4 |/ F- C* r7 Y, U4 f8 j
21H,AL
0 U, P% C, g" R1 S4 B6 o;写ICW4
) \# F2 @% P( J3 f3 l( U# u: X0 A1 D7 {
3. APIC
4 A& Q! ?" `; M& _5 p
7 }6 R, Z) i! h$ q0 Z. x0 u" wIntel 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,: J9 [; i* d+ z- S4 z& S
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
6 {% ^. L+ ^% b7 b2 Z5 |: R t; U2 ?+ H5 Y
+ A4 c }8 }1 D( a! t9 y& |$ @
; D# A! M9 b6 N" }. Z) _! f4 k: k& w7 L
Programmable Redirection Table详细格式如下所示:
4 d3 }( W& ~. U8 b( D
3 }- x; y O' T: l. e; CBit Description:
* V e" d. {' ]9 `8 R; I) ` | [63:56] Destination Field—R/W.
! V- U) I; [1 C) R* m# r) L/ C8 tIf the Destination Mode of this entry is Physical Mode (bit 11=0), bits
# N* p( r* i+ p0 y9 h5 Y | [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field2 G; j8 w8 p+ n
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
9 H K7 u w2 R9 L) m6 zdestination address.
2 O4 M& L7 U# f+ b9 B6 [ R6 e; B1 zDestination Mode IOREDTBLx[11] Logical Destination Address; Z" |! @9 T& @
0, Physical Mode IOREDTBLx[59:56] = APIC ID
4 l" w' I5 D k' e# r+ f1, Logical Mode IOREDTBLx[63:56] = Set of processors0 T0 a7 n9 f8 E/ R
| [55:17] Reserved.82093AA (IOAPIC)
6 p$ ?5 V9 N# g; h6 G | [16]( i: R3 T( T$ h
Interrupt Mask—R/W.8 Z& N+ F4 r, F3 c8 g
When this bit is 1, the interrupt signal is masked. Edge-sensitive
7 l0 p7 p4 ?; J, c* h. q6 X, ?interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
% n8 h L" W1 R+ h2 tLevel-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
7 q, E' V" A8 d8 H# R) U6 Fside effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
6 N1 W9 W5 r6 u. [6 ta local APIC has no effect on that interrupt. This behavior is identical to the case where the
]: `% l- j& m, o8 n0 g0 Odevice withdraws the interrupt before that interrupt is posted to the processor. It is software's" h# z7 D X! c4 ?4 }. F8 L
responsibility to handle the case where the mask bit is set after the interrupt message has been
$ E. r" f; e0 ], j, {accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this; z y1 u5 A2 G
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
8 z1 S( V' ~6 l$ ^7 M6 q- Nresults in the delivery of the interrupt to the destination.. ^5 o M, T7 I* Q8 X
| [15] Trigger Mode—R/W.
) {1 M3 d' b$ @8 IThe trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
" K( b6 H; f8 i8 d% R. m1 H | [14] Remote IRR—RO.7 M/ a5 j Q4 T! F# Q2 A1 Y
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.9 K! v, a) @7 n6 y: Z9 ^
| [13] Interrupt Input Pin Polarity (INTPOL)—R/W.
8 i& Q& v. g. _8 K" ]& K$ z7 @" pThis bit specifies the polarity of the interrupt
+ @% U+ u7 d! x0 Z2 z6 O4 ?signal. 0=High active, 1=Low active.
$ _! B6 ~2 ~+ V' q- m' `2 Z | [12]
6 L0 R: p8 l% n4 zDelivery Status (DELIVS)—RO.
. v/ ~$ P+ L1 n# I/ jThe Delivery Status bit contains the current status of the
, e: h, `! |1 T# l" Odelivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit# Y+ a: L u) W: m) Q) d. G ^
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send/ b! {' i& k+ ~: C+ T( k# g
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC4 [. G4 O4 R: c& Y. X A
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).& u# L1 r3 I5 E4 U& J- R
| [11] Destination Mode (DESTMOD)—R/W.* l6 B8 ?$ e1 L4 f: q# m- _9 a [
This field determines the interpretation of the) b- s/ `. f) \ { [1 {' _8 I- C
Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.* {4 a& h1 d1 W7 L
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.
/ W( E" Y1 L4 d' l6 x' S4 HDestination Mode IOREDTBLx[11] Logical Destination Address 0, Physical Mode IOREDTBLx[59:56] = APIC ID1, Logical Mode IOREDTBLx[63:56] = Set of processorsE 82093AA (IOAPIC)
( h, A c' G5 e: ? p | [10:8]Delivery Mode (DELMOD)—R/W.7 y7 v$ `+ g* q) g* [9 i/ c
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# A5 g( W1 X8 K5 B2 E, q- }
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.. h5 @$ @. ~: t {7 _
These restrictions are indicated in the following table for each Delivery Mode.0 a0 I% u0 i$ t
Mode Description
3 i; @0 H9 t! ^& t) Q000
`3 m- z( B( xFixed Deliver the signal on the INTR signal of all processor cores listed in the
2 K8 o, L, s' y2 Pdestination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
6 F" O; v! F n, N0 |3 ]* S0 \6 A" n001
$ h. @* V9 w$ g4 S3 Y4 Z4 b ^Lowest9 N) O4 y2 \7 B% H
Priority Deliver the signal on the INTR signal of the processor core that is
" A- a; q$ t6 L; v: _. A G1 P) Nexecuting at the lowest priority among all the processors listed in the
3 F8 I2 }/ \6 C2 G2 i' a" Fspecified destination. Trigger Mode for "lowest priority". Delivery Mode
' h3 r% N* Z5 @2 \. ucan be edge or level.; N$ M; a4 {4 D# n; X$ B. ^9 q4 x
010% l p; ?3 h0 j0 H. U6 b
SMI System Management Interrupt. A delivery mode equal to SMI requires an- ~2 a* m% x: B% v% q/ K8 H( ]
edge trigger mode. The vector information is ignored but must be7 t' D; E/ D+ S" J( k/ ~: ~. T
programmed to all zeroes for future compatibility.% d; u D* S3 j7 {
011
2 x0 h4 e: F7 D! `4 p3 C. d. zReserved
( i0 I* G" M% Y100% N# }6 K) a- R% z7 G" c
NMI Deliver the signal on the NMI signal of all processor cores listed in the
/ O# @: l; L2 N [: H& \8 r* Fdestination. Vector information is ignored. NMI is treated as an edge2 L1 S: k7 F. D$ W9 p% I' ]6 L
triggered interrupt, even if it is programmed as a level triggered interrupt.
( G0 j8 ~- O4 i3 v) p$ e0 c! d( oFor proper operation, this redirection table entry must be programmed to, p# p' Z+ h/ _. t }' j! a
“edge” triggered interrupt.! M& J( B5 ~. c- n0 b
101
# E2 B7 \4 f5 W- F2 W& k8 gINIT Deliver the signal to all processor cores listed in the destination by0 H/ O# |/ X+ K; }3 P4 c. X( [
asserting the INIT signal. All addressed local APICs will assume their
0 m9 v _9 N. ]- r9 J% QINIT state. INIT is always treated as an edge triggered interrupt, even if
7 z( k; d! g2 m, ^7 v0 k& v! b5 ^programmed otherwise. For proper operation, this redirection table entry7 s9 q' F4 q% G' S1 C. d' O3 z
must be programmed to “edge” triggered interrupt.! A' M3 R- N+ y7 g
1106 p) ^0 \9 c4 W, P
Reserved
' q! B8 t, _$ T- Z% T7 y" U111) v- a; `0 h3 \. D6 Z
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the
( G# p6 s, v+ F8 E8 z( Wdestination as an interrupt that originated in an externally connected8 v' U. x. A/ l \5 _
(8259A-compatible) interrupt controller. The INTA cycle that corresponds5 H7 J' z* K. u2 Z2 e( }- h `- b; B
to this ExtINT delivery is routed to the external controller that is expected$ g1 I* K K* C; t
to supply the vector. A Delivery Mode of "ExtINT"2 d) Y9 [6 ?: ]( e# p
requires an edge
a q8 z% u! I" I3 J1 wtrigger mode.
9 A" u7 [7 u, W4 t4 u" a8 E4 D | [7:0] Interrupt Vector (INTVEC)—R/W:. h6 I6 a1 \$ H5 ^1 t9 ~0 J3 N2 n
The vector field is an 8 bit field containing the interrupt% r! @( H' ]$ T0 n) Z+ Z* b
vector for this interrupt. Vector values range from 10h to FEh.
2 k. {8 ^7 B" p |
& J2 N T9 K1 gREFF:2 F- z: U( |$ |7 J) C
) Z2 ?/ l- b1 S7 V
1.9 h2 L+ U v/ `3 m/ s& l; w
《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》. R+ J4 @# o5 z' _3 c( H6 ]& H
2.
: Q7 W. C1 S7 L! W% Z, w( }《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》
5 C' ^* y+ T1 G3.
' K9 l- d! ]7 ?% G9 p0 q- q9 K. @《Undocumented PC》& {& w0 k( D t, S6 W, [
4.
( g( P A4 C, p) A3 J. k
) O& o$ z3 a, w8259A初始化编程+ Q, d3 k2 E7 Q; k" |
0 s# ?/ W; f4 y/ }; d& S
That’s all!
4 Z- C" ^) H# N2 V$ l2 o. G: {* t# X r6 L6 Q
Peter
/ ^) g) M9 a3 |
/ f& X3 u. h2 e- m1 m6 ^3 ~) [7 V2010/10/07
2 N7 ^, B0 C. ]' B& d2 N! r- @' h9 E* A" n( s1 `
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|