|
|
|
PIC 、APIC(IOAPIC LAPIC) 3 D8 l$ D' W, G: j& X2 L2 S) C
1. Overview2 ?9 t4 k8 @) v* O( C( K! E
9 v0 `% C( O) e8 ^8 {PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中1 t/ o" Q2 u8 ]9 ~
用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。/ P8 ?+ K q. ] c7 f( e5 N9 y8 b1 {
" J# s( B3 ^7 q3 n8 `) q* k
; V( z" w- f% A; L. Z0 e2. PIC" D# F5 i3 M4 t2 J( N, Z$ s
/ m/ H# _% @, I0 @" l' ]基于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。
/ b0 `0 v( z" l' o7 y# {
! H) @' g# N$ S
# y; x* J- y9 U$ d3 H) C
5 a5 T+ f9 M+ _; G m
& e3 ], ^# b Q: \2 f为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:* l( I; x5 z, Y% B( s& ]' B8 q6 A$ ~
% q7 l4 G" [) B4 _4 j: ?. i1 x( wMOV5 C$ n. R1 Q' ^& b
AL,00010001b
7 B) I& Q1 ?5 _& o. q* x' } @6 K;级联,边沿触发,需要写ICW40 r- s" V" P, ]4 |9 n Z
OUT
' @6 {, j" n0 m2 ~- |20H,AL
% r* I5 @$ u) s% C;写ICW1
! N6 C7 [' l3 N0 qMOV
' |' Z d( _3 q( L3 C0 i! JAL,01000000B ;中断类型号40H
* P1 t" H& ~/ h5 I1 T1 j. {& z2 KOUT& M. x m) N4 ~# ?2 N2 [" }, j
21H,AL( e0 k: w# E$ T, X* j
;写ICW26 S0 b6 z3 v5 {1 d
MOV% o4 p" A/ `- v! w) t
AL,00000100B;主片的IR2引脚从片
$ u/ M! I, f2 @* P5 `! mOUT5 q9 E. N* j; C. A/ H1 s* i( `
21H,AL. o5 Q# Y+ F6 V- x
;写ICW3+ i2 E h# Z3 G* R- N% d
MOV* Z' C+ _$ M3 k5 M( e! v: h* R
AL,00010001B;特殊完全嵌套,非缓冲,自动结束
7 ~+ s) u2 t0 S3 X( J kOUT5 A1 Z8 h, E9 }; ? q! G! ^
21H,AL
/ O6 v* [8 I: ~9 i" _: o9 ], L;写ICW4) |: Z: \) X" A9 S( M1 L) U& j7 o
, h' o% y. c* ~& e0 M) ^3. APIC
$ |6 i) k# Q5 B& O. O% c( X0 K) h
Intel 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,
6 k( j( T3 K* J) _每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。4 _& N2 A; H9 t$ `8 L
1 \$ T8 o' \0 K8 _) b% k) f0 n& h, \0 h5 Y+ ?. @1 W: d2 q
: _' m7 r1 j6 g+ f
- p t6 X/ g9 ?4 `& H$ B2 e' d
Programmable Redirection Table详细格式如下所示:, u- d3 z, x, X) S- l; `
& U5 @/ k2 p! P4 f2 O1 \! n
Bit Description:! t0 Q; x3 o8 R9 |- _
| [63:56] Destination Field—R/W.' \7 P: Q* Q) G g8 v
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits
1 V( c2 k0 \9 x+ L | [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field
0 R7 \5 t0 b8 o6 b* Jpotentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
% W0 ?8 s3 p: q: n. kdestination address.
" b# p; [* y+ a4 P' dDestination Mode IOREDTBLx[11] Logical Destination Address1 M' C" U) B- u+ G) z' M
0, Physical Mode IOREDTBLx[59:56] = APIC ID; ?( f. G" M. R
1, Logical Mode IOREDTBLx[63:56] = Set of processors l) E" W" A) r, x1 [
| [55:17] Reserved.82093AA (IOAPIC)
9 H/ c- s! J6 n7 H, X3 I | [16]
7 h2 N" W1 P, ~% o7 aInterrupt Mask—R/W.3 x6 V0 T( Y. }5 d1 g6 T" ]
When this bit is 1, the interrupt signal is masked. Edge-sensitive
; {" |, _* e! M9 b& I. G4 C$ winterrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending)./ `) i# k% R1 e; o8 u+ Q: w) ~
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no v. e" [; D! j( ]
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
" h z b2 E9 O& m- H1 M- ^) @a local APIC has no effect on that interrupt. This behavior is identical to the case where the
( F5 G5 _/ O, a; n! H2 {device withdraws the interrupt before that interrupt is posted to the processor. It is software's
0 G. G) M! |5 h6 Mresponsibility to handle the case where the mask bit is set after the interrupt message has been
! ~; i8 e' V! @7 V; }3 S6 p; ^accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this( h# O: v" y' Y' h( x
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked5 @: Z4 w6 P/ L+ k9 L; \
results in the delivery of the interrupt to the destination.
3 I( S7 m1 J# S2 e | [15] Trigger Mode—R/W.
; H' N7 ]; L! W+ |6 XThe trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
2 G/ o( M$ X+ g, m+ o& D+ n | [14] Remote IRR—RO.
8 H$ \, W# X% ?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.! x! f+ F% _) ]0 E
| [13] Interrupt Input Pin Polarity (INTPOL)—R/W.
7 ]& k( c# m$ o- ~7 |! ~This bit specifies the polarity of the interrupt
2 m$ V% e7 g" k% |/ isignal. 0=High active, 1=Low active.9 E. O n" w8 ] W/ V
| [12]
- F1 X8 E1 |0 s1 d! zDelivery Status (DELIVS)—RO.( P7 Z4 Z3 O t5 W) H5 @
The Delivery Status bit contains the current status of the& k% F9 |* f. a& t6 X' l3 j
delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit' V! K( g- J0 k8 }
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
3 {2 P' C+ k& DPending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
4 B0 s, R! }! _" [0 M# zbus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
3 @6 V6 J0 r% l% U A | [11] Destination Mode (DESTMOD)—R/W.
8 w% ]/ X. R) M. CThis field determines the interpretation of the
* H( L6 Y0 a) y9 m, zDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
% J6 W: Q$ S1 H. z: c: x: fBits 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.
; E6 g# M0 V0 ]6 ?: }* Z2 F2 LDestination Mode IOREDTBLx[11] Logical Destination Address 0, Physical Mode IOREDTBLx[59:56] = APIC ID1, Logical Mode IOREDTBLx[63:56] = Set of processorsE 82093AA (IOAPIC)
' o) P. O' A% R) m | [10:8]Delivery Mode (DELMOD)—R/W., E8 I; o! h4 O* ?+ t6 ]% n I
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 certain6 t6 b4 V5 `) { ]
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.) r3 D5 b' [. v4 y7 m/ I/ K. t
These restrictions are indicated in the following table for each Delivery Mode.$ v, q2 P- D- ?% k& d+ G$ G# U
Mode Description
( Q3 p( {3 p( T( S2 W0005 b" `. V1 C+ P# v
Fixed Deliver the signal on the INTR signal of all processor cores listed in the
: ?' q) g3 m- D7 t; d+ T0 Zdestination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
8 a% C- l# H' |001
6 ?, y& h! t# z* B1 U! u. S w( `5 eLowest: {. n: d+ t& c3 H) n* ^9 y) [! l
Priority Deliver the signal on the INTR signal of the processor core that is$ m5 B+ U) r$ C% {1 s7 @( d
executing at the lowest priority among all the processors listed in the
+ W5 o! x0 X1 c6 hspecified destination. Trigger Mode for "lowest priority". Delivery Mode0 d, q, @* E8 t: c
can be edge or level.
- Z) q8 D( f0 a5 O) O" x' @0109 s) K3 b# | s: P
SMI System Management Interrupt. A delivery mode equal to SMI requires an
# T1 Q: E; g* y- ~5 S: Bedge trigger mode. The vector information is ignored but must be
: Y# z0 @# h( Q$ Eprogrammed to all zeroes for future compatibility.
2 u( j' \) O2 e( s0113 ^& Y/ L4 i. z* q- P* J
Reserved
/ ~) w2 y3 L! l8 g; x100
1 s& h5 p" d& ^& _& O& J0 S, gNMI Deliver the signal on the NMI signal of all processor cores listed in the6 k' j6 y" N0 u% v
destination. Vector information is ignored. NMI is treated as an edge
" Y' O( {! {; `% p; c2 ~triggered interrupt, even if it is programmed as a level triggered interrupt.
0 ~( ^4 x/ |" ]; L L7 MFor proper operation, this redirection table entry must be programmed to' X" N1 |! U/ g
“edge” triggered interrupt.
0 D/ [) ~* e0 E- M- w# z7 @* l' c101" [7 R2 d) L; ]8 e# a
INIT Deliver the signal to all processor cores listed in the destination by+ X) E8 r' v* F% C( J
asserting the INIT signal. All addressed local APICs will assume their" [, T. J/ w5 S+ S: @) A6 L
INIT state. INIT is always treated as an edge triggered interrupt, even if( I& T1 f- l/ m0 D2 h- x
programmed otherwise. For proper operation, this redirection table entry
* X6 B- j+ q9 {# P5 h6 f, Vmust be programmed to “edge” triggered interrupt.4 W( O9 c; ^: B+ `& W6 l, E6 R$ I7 R0 G
110
8 N6 b' l, d- T& N0 aReserved
! x) S2 r' U7 d& Q u3 D111
7 H! }! |! o8 o1 K1 L, O# aExtINT Deliver the signal to the INTR signal of all processor cores listed in the
' O" ^* I9 L; y+ {) R6 u- n% y1 qdestination as an interrupt that originated in an externally connected2 |5 x2 p [$ r: J
(8259A-compatible) interrupt controller. The INTA cycle that corresponds2 d0 @% r3 d4 d# a+ D( m9 [
to this ExtINT delivery is routed to the external controller that is expected
$ a4 n6 A) M A! | [; u; g& J( ?; S. Hto supply the vector. A Delivery Mode of "ExtINT"( }% n% f# V7 p$ P
requires an edge
* U) O0 M' E4 R5 a, m; Q6 Y3 [trigger mode.; H8 l# @+ H& r' u$ P6 M. \
| [7:0] Interrupt Vector (INTVEC)—R/W:- r1 ^& w, t. J0 R- ~* c
The vector field is an 8 bit field containing the interrupt
/ |7 y( r+ K/ G& j, `2 A6 w- Lvector for this interrupt. Vector values range from 10h to FEh.
) }' I1 L2 u/ \3 j |
7 N- ?) F. M. Y- O& c9 t; dREFF:
/ k8 I; }( K% O9 z* f8 }2 I/ X% }7 K, o& Q/ p
1." G o8 V- I& ^0 M2 c ]' J' K1 ^
《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》
. I6 u; ?# F7 D4 C* w2.
! b# {( D0 g# \1 a( V) j《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》
' e6 E$ L, C7 t: _4 i' y3.; @; W- I0 D( U9 Z, V, [- w
《Undocumented PC》
% V1 f) Q# c: c! g! g) }4.
# z7 {! a D# |+ D U0 p, L
- H) V# A$ j) b# t* W9 O5 n0 u8259A初始化编程
' t$ \0 _% r5 g! q" U
# R' \& L5 m, [) [2 xThat’s all!# i" r3 T$ R- _ g/ g" _2 B$ i
* x9 T- Z5 W7 K) lPeter
8 z, O( g M# _4 H( {( O$ O1 N2 i1 o: w0 F+ |6 R! g1 P
2010/10/079 D, Q8 v# p- Q+ h; L- L
, M1 `$ f( e; U' P+ |/ x0 U2 ?
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|