|
|
|
PIC 、APIC(IOAPIC LAPIC) 9 n2 _/ K: A' B
1. Overview
3 G9 U# `( z1 `+ k
+ c4 \7 A2 O, O: F$ y) CPIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中; @% w- d6 U, w+ e! S) O+ h
用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。
, B" n' t" F2 f/ F
5 c0 u4 A3 Y7 k- b7 O' u# W5 N* J+ Y5 G9 E N: W c# Z
2. PIC
% Q' H# |3 J* j L6 c5 ]
5 ^1 U- A* ]3 F基于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。' {# e* Y, S' p' W
/ I5 a" B! e$ c1 E# f4 r2 ?+ K
; n( O$ f, k+ q
6 @4 e9 p0 s# j) ]3 s
8 C; \5 B+ W3 b/ r- C5 N; T' s
为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:
# H$ ^8 y7 C& d) I0 y& S y
C# D, D& \$ |5 }MOV
, t5 O: B- H& Q) ^/ _AL,00010001b
2 c# `% y; Q8 k% U( D$ O R;级联,边沿触发,需要写ICW4, [' t: u/ z2 q- \" p7 {$ N9 J8 r& {
OUT/ z4 P; W6 |8 v% h# [8 K4 ?: D
20H,AL
6 K. r: i( M* x) m;写ICW1
$ A5 L8 Z: \9 g: y: CMOV" D# I1 ~) a4 p5 z
AL,01000000B ;中断类型号40H
# [- w) F2 h: WOUT
0 ?* X" B! f$ t/ \21H,AL
/ M: A7 w" O" H- m) I7 A;写ICW2
: @% s3 b. w5 i2 K9 gMOV
9 w' I- n) G1 G7 c) I) P6 O3 E2 BAL,00000100B;主片的IR2引脚从片& [- H& Z, X8 i
OUT
# o- c' W$ r6 r% D' s21H,AL
9 G8 m Y% X3 w! C$ b;写ICW3
2 V' B! {7 l- i% Y& G/ rMOV
/ Y( t1 n7 e& T) G3 B0 HAL,00010001B;特殊完全嵌套,非缓冲,自动结束1 x7 m* H7 p7 C$ K) m
OUT
! \2 O8 ]5 X+ I21H,AL7 [, G5 G4 G& j
;写ICW4, t( J* x. f, G" ]* u
$ C3 Q( M6 R' J' w3. APIC
1 a. `# i9 _& f/ I3 L* _, }
0 [$ C. S4 B' f2 O- CIntel 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,
; J E1 m( t8 Z4 g每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
3 ^7 T( l9 B9 ]. s
# B* Y% M0 E0 g7 u \: X9 n
( h) C% N5 U: W/ X. x9 A
2 @$ j- }2 ~+ t+ c* ?# T6 |
3 Y8 A) U$ S* T: jProgrammable Redirection Table详细格式如下所示:# y P8 n, X7 _; X1 u' [! T
. t/ h9 w+ j: j: z5 E
Bit Description:
7 X) c/ l% u% t& N1 M" l# s, G | [63:56] Destination Field—R/W.
+ b* ]3 \/ @ m" } \, Z& Z1 c( [' BIf the Destination Mode of this entry is Physical Mode (bit 11=0), bits9 Q& @* V7 Q1 \* Y9 d
| [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field9 v4 m$ l6 [; w8 y) \& O
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
4 U) q. I9 ~. Ddestination address.7 W ]4 k% o) h: j! x
Destination Mode IOREDTBLx[11] Logical Destination Address; e. N, {) S/ i$ }
0, Physical Mode IOREDTBLx[59:56] = APIC ID# F- ^# Z3 J3 e/ N/ [
1, Logical Mode IOREDTBLx[63:56] = Set of processors+ X# r; L4 ~' Y# U7 ^; n E5 ]
| [55:17] Reserved.82093AA (IOAPIC)
- L3 _+ N) `- ~4 T0 M, N | [16]- F s) K+ Q: u. b' ?
Interrupt Mask—R/W.
7 N m: p# r) T0 m! K( [When this bit is 1, the interrupt signal is masked. Edge-sensitive
2 m$ ~8 P w$ s: Kinterrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).. F5 Q0 U- z) x9 i2 @& D1 Q3 [
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
% t+ k8 H! O2 w, O4 H8 W7 M9 pside effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
, @5 ^, A4 x8 w, C- R# r- fa local APIC has no effect on that interrupt. This behavior is identical to the case where the
& Q4 ~2 K) G: f9 n& e0 D" S" I5 f* W+ Idevice withdraws the interrupt before that interrupt is posted to the processor. It is software's
7 E. `5 R: D/ G) A, _0 L) B5 ]responsibility to handle the case where the mask bit is set after the interrupt message has been
2 o: N$ f+ e! R* S" N/ |accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this, t# F: `, V5 z. }
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
/ \3 {% q& ~& R% j0 f: Hresults in the delivery of the interrupt to the destination.
, m) E9 i; p3 j- |* q, e5 {" i i | [15] Trigger Mode—R/W.
& t6 B8 A8 U$ O/ o; y" LThe trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.4 b, g, ?3 @4 ]& A1 G/ l
| [14] Remote IRR—RO.
3 f2 G4 V+ Q5 ^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.( ]( O" L; K) C: [3 p& Y+ ~
| [13] Interrupt Input Pin Polarity (INTPOL)—R/W.' E5 r( p, _7 F. |1 ^3 @
This bit specifies the polarity of the interrupt
! E( c8 _; r& U9 Qsignal. 0=High active, 1=Low active.7 y! Q; r- c O) h* V2 h- E
| [12]
! s7 o& W$ C- A7 r) P0 W, ^, r9 |Delivery Status (DELIVS)—RO.9 [ o2 Z8 l- Q# T; J l# } ]
The Delivery Status bit contains the current status of the; u9 |& E, x+ I' B* C0 j
delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit
' I& @1 i0 G+ S9 Z6 R$ N: f( B* pword) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
# m* J) t4 ?! v5 b# N' J+ WPending (the interrupt has been injected but its delivery is temporarily held up due to the APIC* d7 C5 r( _5 H" `0 Y- D4 \
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
4 ~4 F* q: x) x" ~1 o4 W | [11] Destination Mode (DESTMOD)—R/W.
6 i* e9 z# R B6 LThis field determines the interpretation of the
1 |* ]/ B* \/ I0 tDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
" D' k1 |1 }* ]* W5 y( [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.7 @7 U( o4 L) @# q
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)7 }' V5 n+ s7 s! }" U9 @8 j& j
| [10:8]Delivery Mode (DELMOD)—R/W.! ?& t" Z/ S& r
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
2 z0 K" M; y- [% b2 gDelivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
# {& X9 |3 M% f: o" l6 }. X! j; M$ jThese restrictions are indicated in the following table for each Delivery Mode.( t: g1 ~% v# v6 Q4 J8 T! V% U0 A
Mode Description6 g! x6 m% a5 P: b
0009 k: J4 A4 F, D1 Y( x0 u4 p
Fixed Deliver the signal on the INTR signal of all processor cores listed in the
* l. w0 j# `7 c9 \: w9 X Cdestination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
* q5 q4 r, o6 q$ Y8 Y! p; ^001( W$ W$ N, ]$ P3 O! v
Lowest
) y4 m, C) s# v$ j& QPriority Deliver the signal on the INTR signal of the processor core that is
/ J" E S$ F3 K4 `executing at the lowest priority among all the processors listed in the
5 u/ _. |' M! C# a# ~8 yspecified destination. Trigger Mode for "lowest priority". Delivery Mode
9 B W2 I5 G v5 M4 @! U! bcan be edge or level.! ]/ d& b& Q5 u" m! `
010! X$ ~5 S1 g3 g0 @
SMI System Management Interrupt. A delivery mode equal to SMI requires an
. x) C$ T9 C+ D' Y6 u& Nedge trigger mode. The vector information is ignored but must be
K' n, K$ }! c" N/ cprogrammed to all zeroes for future compatibility.
! H: l0 {6 D6 X. h1 \4 s0117 E$ H/ `5 [! ~& A. B7 ^" o9 [
Reserved
7 [' x3 |+ K6 K100
1 ]0 l$ F* Z) \NMI Deliver the signal on the NMI signal of all processor cores listed in the
( g! t8 T$ l" |: @$ x# {/ ddestination. Vector information is ignored. NMI is treated as an edge4 x7 _# R+ P4 f* V$ @" b
triggered interrupt, even if it is programmed as a level triggered interrupt.
9 u: i1 \# M5 o: B2 MFor proper operation, this redirection table entry must be programmed to/ H" s& y6 M# x7 L+ S
“edge” triggered interrupt.! {$ y. m( K+ s
1011 {- D: h1 m! F9 W1 L& Z( F& i
INIT Deliver the signal to all processor cores listed in the destination by
2 Q8 w0 E4 L: q0 u( X; d. Sasserting the INIT signal. All addressed local APICs will assume their
. C* t- W/ y# xINIT state. INIT is always treated as an edge triggered interrupt, even if
/ {4 X! u6 `; e9 S7 vprogrammed otherwise. For proper operation, this redirection table entry
+ C+ Z3 j* i7 _ `$ ]must be programmed to “edge” triggered interrupt., I4 ], L0 R8 y2 U0 l( {% b
110
* e+ s5 w8 ~0 `Reserved& r( M7 E1 \, T/ A1 o4 I
111
- K8 L2 x9 f9 nExtINT Deliver the signal to the INTR signal of all processor cores listed in the
& T, h" ~. n4 C5 n( Z# vdestination as an interrupt that originated in an externally connected
1 Z% X& [4 w; S(8259A-compatible) interrupt controller. The INTA cycle that corresponds5 z4 C& S- d8 i) Q
to this ExtINT delivery is routed to the external controller that is expected
. S4 L b& S% K: |; x( g, z' _to supply the vector. A Delivery Mode of "ExtINT"& G& W" [2 d* U( t
requires an edge# E- C" q* [3 _5 p2 ^0 K' \0 @
trigger mode.0 s% x3 e2 X9 N
| [7:0] Interrupt Vector (INTVEC)—R/W:
8 R0 k: m$ g1 n' KThe vector field is an 8 bit field containing the interrupt' o/ i9 O8 Y: Z `% y
vector for this interrupt. Vector values range from 10h to FEh., { z$ |7 y' \) \# i/ ^
|
" |% \1 J+ X" m5 q$ t9 Y% T/ N8 k3 oREFF:
4 P- u- M2 @% v8 m m; [4 j; B/ r
+ \& `2 \+ L3 |. e" s* R$ ]1.7 O, y) B3 z4 T B, m
《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》
- i. E: W4 a& O2 I2.
+ D! X$ m* W+ Z2 w9 |8 o9 A《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》" _4 F0 Z" S! u0 y) ^
3., ~! S: L' E+ ]' l
《Undocumented PC》4 ]$ {- c; q ^9 p! P0 w6 D$ F5 Z
4.* e, m* @0 |1 O
1 W, ` j% e$ @+ I/ F8259A初始化编程
; d9 d4 D+ w- b1 h4 I/ `* u0 P. U8 U8 s! b) H. _& U
That’s all!
; S% x# @2 U- t
1 y( E* x% y$ YPeter
7 v* H( g \8 `4 ?: b4 {" e# J( t# B) E
2010/10/07
* U/ S$ k% ?! m5 C
- I+ u4 }, t; E[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|