|
|
|
PIC 、APIC(IOAPIC LAPIC)
1 W9 l8 m; s7 v) O1. Overview8 |: R0 k* M) C- B: k
0 R0 k: b! J- WPIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中
' ]- x$ g C& ^用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。
& u. O; O6 s0 W( w8 ` `
0 p- R+ {, n3 z" [! ^2 E
: Y. R1 O0 ]" j: H2. PIC
6 F z6 I6 A5 |0 {, N1 x: G# i5 w- }7 L/ m. 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。
, C) |$ I! q( [) g1 l+ ]3 ~: I" C; B; w9 O# {" E3 C' k
4 M" G+ P. \/ w7 o2 ?& k" D
1 F8 d4 ~8 T; S2 \
; j) C! o+ S! i' m为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:* x% m1 z- q- g) p! m( p' U4 F
* q# K" w7 m; V/ g, G/ d; K
MOV
5 r0 ]* n4 }' w! P# o% ~AL,00010001b
' e4 Q4 f7 C6 q* a6 D( U- |, Q;级联,边沿触发,需要写ICW4
+ L Q' \; f0 _7 Q+ D& D1 Y1 ?7 POUT
$ R! W, L( T' M4 `8 E* C% b8 g6 g20H,AL
; W* l8 i* W- I1 S' ]3 ?;写ICW1
" z9 w4 Y6 l6 C$ e, a. c) GMOV }; Q* `# B- s7 l, c/ Q
AL,01000000B ;中断类型号40H
. s5 X- _: _+ }, \" U6 oOUT& _3 {* {% M8 Z" [
21H,AL
9 I n- Y, h0 v: ]5 z! D;写ICW27 I. S- b- S3 l0 O# ~9 `
MOV
9 u" x7 \, H! \2 fAL,00000100B;主片的IR2引脚从片
7 n8 o2 w! T5 g iOUT
0 X! D! e/ w# a21H,AL+ F( `# _ B. H" C) D- J p7 O& a. Y
;写ICW3: P& B# g6 Q% S3 Y4 u
MOV+ b( C9 _+ M' N# z$ i% `
AL,00010001B;特殊完全嵌套,非缓冲,自动结束
9 G3 H |2 n! y/ d8 YOUT: Y @' B0 t# m
21H,AL( K& _1 P) g- }
;写ICW4
# H, b0 o& P$ C3 {2 Y* i. Y1 ]
1 q. h; w. E2 z6 s8 |- ]+ C3. APIC
+ g0 O6 j0 I0 n9 L( @, Y" |
$ {4 V9 @8 A! I9 s. g7 [4 Z* yIntel 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,+ H4 y% m' _. ~% u1 D+ O a! z
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。" b! _/ K- N- f7 Y
$ ?& x( v: p/ P& {9 d, {% r
5 U# E+ H1 Q' E' u3 i8 t3 f
( S/ D1 V9 B/ W
3 P, p; D( x3 S
Programmable Redirection Table详细格式如下所示:
7 n* v* [; b$ o5 a+ W/ _* ]: D( R8 H
Bit Description:
! S( }$ ~ Q# O& U | [63:56] Destination Field—R/W./ ]& r9 x4 t' i2 Z$ n& M
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits
- b- T5 z4 ?* I- b | [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field
" K# m0 `, u, n0 h; qpotentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
* f. w' T; K( n5 Ldestination address.
* i: J! e: A1 J- {% K: u6 l2 vDestination Mode IOREDTBLx[11] Logical Destination Address8 S9 s, I; a6 B j. f
0, Physical Mode IOREDTBLx[59:56] = APIC ID
% m6 t2 a. N( W: ?8 v( n1, Logical Mode IOREDTBLx[63:56] = Set of processors: ?3 s7 d+ v: N
| [55:17] Reserved.82093AA (IOAPIC) # L, G, B$ x, G5 {2 F' Y
| [16]) ^) s9 T( K% m, j/ W
Interrupt Mask—R/W.
3 i i' b% H" J1 e5 v) k% KWhen this bit is 1, the interrupt signal is masked. Edge-sensitive
1 T" t; W/ ]. Y3 H2 _% pinterrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).' s( z1 C7 J- D$ b9 P
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no4 y2 ?" K' S1 P4 T3 M% z
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
0 Z& m; o; `% J; w! la local APIC has no effect on that interrupt. This behavior is identical to the case where the0 d; K7 h6 j1 W; W9 X- k" _
device withdraws the interrupt before that interrupt is posted to the processor. It is software's4 L+ y! t1 w6 U& k' r7 }! S
responsibility to handle the case where the mask bit is set after the interrupt message has been
0 S1 y5 |* n; A5 p u0 Waccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this
7 {6 E' S# X* j& vbit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
. O5 ?: v$ w! Yresults in the delivery of the interrupt to the destination.
- o1 Z0 C, V: ? k2 f. U) I | [15] Trigger Mode—R/W.1 Q, t9 X+ x: _
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
6 M, o1 W* T; a0 I8 z' [ | [14] Remote IRR—RO.
$ b- {( b7 ]* I6 IThis 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 Z5 Q5 C1 t- |7 |% R | [13] Interrupt Input Pin Polarity (INTPOL)—R/W.0 O, u& M \. P. k6 O. U$ E& c4 E
This bit specifies the polarity of the interrupt. k, D+ w6 b* @
signal. 0=High active, 1=Low active.
4 r9 T, s" B+ M3 G2 U | [12]
9 x* D3 C% k' @7 ~3 ]& ADelivery Status (DELIVS)—RO.4 j4 ^) I# n8 d& n
The Delivery Status bit contains the current status of the
- g. r5 G9 K6 F' b6 q! \delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit5 u# J; M* H/ R3 G& }1 E
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
G* k) J1 V* U" w5 r0 x* mPending (the interrupt has been injected but its delivery is temporarily held up due to the APIC: Z/ M* x9 @# [* w4 U- Z" c
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
" ?) D% s6 L/ P4 G; S" C7 f | [11] Destination Mode (DESTMOD)—R/W." F- F0 ?+ W% x5 J) b W P' b
This field determines the interpretation of the
% A4 f; ~- Y. z# R3 Y& t! {Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
! E4 W, t" v/ vBits 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.* ^% {7 `) i7 W$ e( x- i/ 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)6 R; r* v1 x; T
| [10:8]Delivery Mode (DELMOD)—R/W.
1 H0 p5 ]' V, c4 W5 _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* n; Y% n2 ^) u1 |
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode./ P- i9 h5 A6 N; K( {
These restrictions are indicated in the following table for each Delivery Mode.& O3 |( g1 b" T# `0 Q% g
Mode Description
, e. \8 S, v9 w v000: H: T( C" K6 l: z7 B
Fixed Deliver the signal on the INTR signal of all processor cores listed in the/ v: u5 n5 n4 v8 _
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.9 K6 X' L+ d; f
001 r2 E- h; f8 }6 K7 Z& B& f$ H- ^
Lowest
- j$ {8 V& N5 Q' t' L. a7 A, C+ UPriority Deliver the signal on the INTR signal of the processor core that is+ b% W4 \4 S- L5 K' W
executing at the lowest priority among all the processors listed in the3 I) Z D5 M/ |+ ~& `
specified destination. Trigger Mode for "lowest priority". Delivery Mode9 Q3 K* M9 U0 N. P% |+ J
can be edge or level.8 ^- C% R& k* S5 q: J m
010
0 }- h. P9 x! ASMI System Management Interrupt. A delivery mode equal to SMI requires an4 S h" P" f8 n" n1 z# F5 p
edge trigger mode. The vector information is ignored but must be
% o& Z ~, w6 {, t6 V7 L" Jprogrammed to all zeroes for future compatibility.. o( M. m: j" d4 K5 A
011
8 S7 l" t3 V/ W6 NReserved3 m9 p0 F8 p, e( _1 d% u& C
1005 L! u, J& d' [
NMI Deliver the signal on the NMI signal of all processor cores listed in the
1 d$ h0 r" {3 Vdestination. Vector information is ignored. NMI is treated as an edge
( v5 b* m7 W/ t& ntriggered interrupt, even if it is programmed as a level triggered interrupt.
$ ^- w) j7 h, v0 G# f7 H9 X+ aFor proper operation, this redirection table entry must be programmed to, u9 ?7 i7 w/ X$ y
“edge” triggered interrupt.
/ d: r) F( i& n9 n2 \2 G/ ]101
& X: c. [; u4 K4 K5 WINIT Deliver the signal to all processor cores listed in the destination by
. R! ]3 t z9 V: E( S( F, B$ X8 sasserting the INIT signal. All addressed local APICs will assume their
6 A1 D4 k/ ^" O3 ?INIT state. INIT is always treated as an edge triggered interrupt, even if
; P7 @, K8 w! v" tprogrammed otherwise. For proper operation, this redirection table entry4 p# Y0 S8 t2 Q$ ?3 s- g; w* ^$ O5 Y( f
must be programmed to “edge” triggered interrupt.
0 V( X7 `. {. U110
+ Y- d8 ^! ~1 v1 _Reserved9 K( c$ ~$ X: y" q; R7 |
111; g* `7 m; Q" z* X, E0 p
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the7 x6 d! k4 X& g8 U3 G( W) U) {
destination as an interrupt that originated in an externally connected' C8 X. c7 v" E9 [, g! L8 O
(8259A-compatible) interrupt controller. The INTA cycle that corresponds" p# }( a0 s) z+ ~1 w
to this ExtINT delivery is routed to the external controller that is expected
4 z% X! X" n! a3 C5 V" { N4 sto supply the vector. A Delivery Mode of "ExtINT"6 h6 V# Q" q& _; C3 O
requires an edge
9 c" |+ S1 a8 V5 x: X: strigger mode.
" h: D/ k5 E. \! o' D) F# P | [7:0] Interrupt Vector (INTVEC)—R/W:% f0 B$ r# W. ?, h# ^; A5 q* E/ G
The vector field is an 8 bit field containing the interrupt6 _5 L$ K3 n, r& ^8 Y$ [
vector for this interrupt. Vector values range from 10h to FEh.
2 C! L" t* j( V; ^: c+ P |
3 {! C& @3 d# L' sREFF:
: A; W9 r6 Q7 o5 O# p4 J& w8 e8 v; {3 o7 k0 g; w
1.5 {8 b% t& K2 L4 ?+ I) F
《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》
/ ?6 l' Y; _& C" U w4 v2.+ R7 C+ w# v; a* `& j
《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》. V. R5 N; G: Z8 ]9 f0 x5 M
3.5 N/ A$ [8 }& V7 O; {, H9 }3 H
《Undocumented PC》2 Y7 p+ x- M, Z7 D1 ]; l
4.
1 t& O& B! N; r5 m- W# H W) N8 H* T; ^( O4 r
8259A初始化编程5 M7 q' Z4 J- i3 T
$ Q" z, i) L+ E8 M7 I
That’s all!( u2 j6 i& w0 \8 A) |' [, \1 k
# E- i6 ` H- d" y0 n9 o% I' a+ _
Peter& O" j9 [ ^! R. R' P% }! b$ S. J4 A6 R
3 C3 p7 P O$ `$ a+ G
2010/10/07; E! C$ l" @6 _/ z3 J
: C# ^0 }- q' U3 [
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|