|
|
|
PIC 、APIC(IOAPIC LAPIC)
: q( @9 f& a" W6 v( [# K- T9 [1. Overview9 k, j, e9 L& Y& G9 h
6 K* V! E' W h
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中1 D W3 x6 ], _% V
用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。
) R$ `" U& N, ^4 _# z; `& _
4 C2 {5 j) S% n% {3 k/ I; N: ~- D# ^( B
2. PIC5 W. E G" \6 H3 J0 r) ?- N
: z* t) Y5 u' U& t+ x# M% |9 c
基于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。
( z7 F* y O* y8 ]: e, {- L& `" V5 L9 W8 A3 c5 n. b' B# A
+ u* \" v2 d M$ J. U! ]" O" J" P7 ` {6 M7 ?0 n) Q1 s
8 l# A/ d" k1 r( m6 ]
为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:. B. K: p# `% `8 k
9 w6 N( L, x' m$ t2 s% z+ H3 S5 ]5 C5 t
MOV! X& u ]: x9 e3 p% u
AL,00010001b
* z1 n6 Q. Q, m0 N1 C p;级联,边沿触发,需要写ICW4
/ s8 _1 v5 a- _OUT* x8 z1 G. f5 J4 U$ G
20H,AL0 q; V1 |- B+ _" t- V# ^
;写ICW13 X) S% q" F# h6 d$ p; D4 l
MOV
1 T# W' L; J6 E1 j' e0 vAL,01000000B ;中断类型号40H
6 q+ d5 G# P g4 COUT. k7 k1 G. H: T( k1 g' @" | c; u
21H,AL
* u9 p) t! e* q5 d;写ICW2
1 K6 ~" o. O: {6 S* f3 YMOV
0 }4 T9 H# f. O* zAL,00000100B;主片的IR2引脚从片
8 e) m# _1 S3 g# b9 o4 y& B' P2 kOUT
( }: d9 [/ u- X4 Z0 [2 @7 B; M21H,AL( q8 @) H7 @7 O( z1 `( X
;写ICW3
7 l5 a% {$ j( hMOV
! I8 h8 I2 p! R; `& QAL,00010001B;特殊完全嵌套,非缓冲,自动结束& z: T+ \0 z& w" ?+ S
OUT
9 t# k( |" V/ K" R7 h+ B( |8 ]21H,AL1 ]9 d2 ]3 ]0 T' g
;写ICW4
2 D4 L" Y" ^; v5 V- H0 @
1 ~' e0 s& A, Y3. APIC
/ }: M& u( Y6 c0 F! M
6 C5 l% n( R* \ J. `$ oIntel 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,
) \( C( L7 `' J$ @2 L* C每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
/ P1 p* I; {; b. w* T1 B& U1 i
" y& Q1 V) K; m$ m2 i5 H- o3 h+ K+ h: J: q6 {9 z
P5 ?0 b' m& Z; L; }
3 G3 Z6 J7 ~. s* K# g& }7 xProgrammable Redirection Table详细格式如下所示:& e2 i8 E+ C. l9 b/ V
8 A/ ]2 `0 n1 g2 a- y A) k
Bit Description:
; _. ~, [9 ~( P- k2 U" x; x | [63:56] Destination Field—R/W.
. a# }' e" \% M& Z" k* q cIf the Destination Mode of this entry is Physical Mode (bit 11=0), bits
: d( U7 [! T1 b# `; c1 ~! P+ ~ | [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field6 ]: O$ a# g2 a# J. \
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
- L W: I% H( P& m( A+ @destination address.9 t$ w V& Z0 q- o& K* q$ f# ~' ^
Destination Mode IOREDTBLx[11] Logical Destination Address t( Z9 l) k; k" C2 e& p4 ]
0, Physical Mode IOREDTBLx[59:56] = APIC ID
$ T8 h* ~* R0 V+ y1, Logical Mode IOREDTBLx[63:56] = Set of processors: S8 R1 d$ Z, H' _1 L4 _* @/ u
| [55:17] Reserved.82093AA (IOAPIC)
* A4 |, I( V6 ~+ _ | [16]
$ ?/ T0 _2 q8 DInterrupt Mask—R/W.
- _* w# j$ ?/ P1 c' Z8 rWhen this bit is 1, the interrupt signal is masked. Edge-sensitive$ U" x% f2 q! S1 M
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
$ r- @! i- r$ L& J3 Q1 FLevel-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
/ Z( i, V6 p+ F- k' Xside effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by1 w& U r- [7 y/ s5 N/ D) X
a local APIC has no effect on that interrupt. This behavior is identical to the case where the! `$ m2 F, C# D! x
device withdraws the interrupt before that interrupt is posted to the processor. It is software's9 y2 C e) [+ V7 L% E
responsibility to handle the case where the mask bit is set after the interrupt message has been
1 n+ c" K; u& A% N+ H# r1 naccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this6 [* _$ L" s, [
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked7 ^+ ^+ y6 v9 x0 N" i, r
results in the delivery of the interrupt to the destination.
2 T+ i+ t! G: r+ n | [15] Trigger Mode—R/W.; _4 y: q0 v% \: E1 [
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
5 I1 L: I0 M2 @0 w% C+ k5 D- D2 s | [14] Remote IRR—RO.
5 o; F: d4 K# ^# n/ m$ YThis 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.$ Z* [/ \1 h( T0 t: X! R
| [13] Interrupt Input Pin Polarity (INTPOL)—R/W.! ^5 | P' U: u$ X3 p" t: d
This bit specifies the polarity of the interrupt7 {8 {0 P6 Z8 m
signal. 0=High active, 1=Low active.
/ g0 H& p1 z; M | [12]( t! L6 |9 |! t
Delivery Status (DELIVS)—RO.
0 X' z1 x; i U. } v. }' {The Delivery Status bit contains the current status of the
1 b6 K/ E! F$ N+ [* Gdelivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit2 N6 F4 W5 M+ S. w3 V% J
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
# g9 Y3 Z( b, M, G" nPending (the interrupt has been injected but its delivery is temporarily held up due to the APIC% y: B$ f0 h2 O
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
) d# [3 ]. N a3 }0 ` | [11] Destination Mode (DESTMOD)—R/W.
& R4 p& O/ }+ I3 w. O6 L' |This field determines the interpretation of the
0 C1 F; s# \; p; ^; \# |- N5 nDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.* d( [- K0 K1 |' T8 ?8 g& {
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.' J9 d; {$ V- b, ~9 b
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)
# t1 u& C. D* N/ v' D | [10:8]Delivery Mode (DELMOD)—R/W.
6 z) Y9 C* C' H1 a! p/ UThe 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 certain3 ?. _) B) X! h& [' x
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
. s. ^- j7 ~! K8 F! WThese restrictions are indicated in the following table for each Delivery Mode.
; f9 _! a+ N8 O& vMode Description
% W3 n1 k& d9 H8 N( C0002 o+ T. z- A- @1 a: F* M* A" n: K+ t
Fixed Deliver the signal on the INTR signal of all processor cores listed in the
& i0 ?# f% _ O( T& Fdestination. Trigger Mode for "fixed" Delivery Mode can be edge or level., q+ M2 o0 i/ h1 W
0019 o5 z% |2 p) V) X/ {- s% z" V+ N
Lowest6 T- e* f3 H" q! r9 D7 z
Priority Deliver the signal on the INTR signal of the processor core that is- T/ k' ] I1 L
executing at the lowest priority among all the processors listed in the
: T/ h3 K" O8 A* Pspecified destination. Trigger Mode for "lowest priority". Delivery Mode, k' f$ A! C8 z1 j
can be edge or level.
4 g: D7 m4 Z, k010
: L% C; ]. }/ r' c1 fSMI System Management Interrupt. A delivery mode equal to SMI requires an* l r! S ?9 }( V0 }9 [0 `
edge trigger mode. The vector information is ignored but must be
+ u! ]7 R/ n! I/ e1 x* ~) K# lprogrammed to all zeroes for future compatibility.( u8 D6 t3 J6 a" s# |1 c# R: j( J
011
2 C; B8 O, R% {& z& ]6 i0 T+ j$ [3 V, B( eReserved( K" g& l4 w6 L: J/ k# C4 G
100
, a/ z" a! C+ I+ WNMI Deliver the signal on the NMI signal of all processor cores listed in the
/ z. P* A; w- kdestination. Vector information is ignored. NMI is treated as an edge
) M4 t) t% w$ F5 a9 C0 |triggered interrupt, even if it is programmed as a level triggered interrupt.
7 @8 i: C. b S, R" {$ g7 |For proper operation, this redirection table entry must be programmed to3 ]0 Z# Z$ U6 D# d$ x+ k+ q( {# b
“edge” triggered interrupt.& u4 M9 D# I5 {5 O! v1 S
101
$ C; a: D# H2 m h q9 h& V% bINIT Deliver the signal to all processor cores listed in the destination by- o G: J J- @9 |1 M( Z- k
asserting the INIT signal. All addressed local APICs will assume their) } }6 b" i. c" e
INIT state. INIT is always treated as an edge triggered interrupt, even if! m# f/ B& B, l! H
programmed otherwise. For proper operation, this redirection table entry( ~' ]0 l! l& ]% L
must be programmed to “edge” triggered interrupt.
. x# w, X, e' R$ q: v- o110
2 F3 Z9 a* ^8 F5 qReserved
8 k4 p$ `. B2 c111
. b2 @- C1 [! ^' S& NExtINT Deliver the signal to the INTR signal of all processor cores listed in the
r1 f) `" B. Y) Vdestination as an interrupt that originated in an externally connected
% E- V! W: z" `(8259A-compatible) interrupt controller. The INTA cycle that corresponds- I, }5 @8 g4 O( y; m
to this ExtINT delivery is routed to the external controller that is expected
$ B1 b2 R) N) n% z# [& Rto supply the vector. A Delivery Mode of "ExtINT"+ Y- ^, W/ V( l0 w; K! a; g0 n- U
requires an edge" H0 g5 S: S2 s: ^5 @8 i; n0 X0 l
trigger mode.1 w- n0 D1 c E) t$ n. f
| [7:0] Interrupt Vector (INTVEC)—R/W:
/ p& q3 M3 L5 z9 F3 F* OThe vector field is an 8 bit field containing the interrupt& `% a$ i+ [6 d3 k
vector for this interrupt. Vector values range from 10h to FEh.
4 D8 u5 M7 K5 r. Q1 j |
' _. N2 M+ I; e9 k, aREFF:
' T# b' r% P+ z8 ` b% H7 D. n/ h$ Z1 C6 v( ^
1.
( f: E0 H% o) q' _' r6 G, ]4 g5 Q" o6 b《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》3 s% t7 n4 o; f# L. G- ~* B
2.4 Y* N+ ]; ?1 N- f
《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》
8 p. z$ W9 x) g' J* q# b+ Q- h3.
6 W; x, u. R! m* Y+ K1 X《Undocumented PC》
# q. h1 F# ^4 K& ? O4.! _3 ^) t9 p! E ^- C
/ z2 d/ b& T& Y' l; w' j
8259A初始化编程) d: H7 c0 T+ V1 U
, {3 x8 Q2 K c6 _/ D
That’s all!0 f4 `+ C( L* u( s$ @' [' o/ l
# ~; k2 ?' w `, |/ `2 ZPeter
+ j0 \: e- F3 S( {$ y2 J0 N
- f, R' X4 Q6 W5 G0 W* A$ }$ g2010/10/07! q! L' U3 z4 |7 ~5 x4 f
9 d8 w% z$ A7 }- g$ l[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|