|
|
|
PIC 、APIC(IOAPIC LAPIC) & F) K( g$ q' e) p4 }+ a9 J% h
1. Overview
6 x2 C* E5 n# ]( X" j. c* n" N& ?2 B8 J/ _" V8 L) @3 H
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中0 E7 J3 E, N' t7 J" M6 {+ X9 E
用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。 M) p9 V) e- }* y& E4 H
% H6 a! @+ x8 s# d8 G
9 G" W* U1 v/ F2. PIC$ L, V0 J( H/ d* z, A& a/ p
1 Y6 f5 Q. `# p6 h+ b8 M3 u) L* T- ]" J
基于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。; J! `$ U, {4 f2 U. Q
! M# Y5 X9 G/ ^
2 k! }! X6 E4 N h
- \9 S& p% P* `( k6 x. k; g# h
) y3 ~% Y$ J8 o' X& W为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:& b* A9 ?% F- O8 c- u0 W# ?* H
! e* {1 ^, q; a' c ~
MOV! c2 N; l6 Y& R0 X8 A
AL,00010001b4 f, x# O/ ?" a5 C h% \
;级联,边沿触发,需要写ICW4% @1 R! O' o0 _4 @
OUT' m, `3 z+ u9 M8 A
20H,AL
# }! r, J8 m$ a" b4 _;写ICW18 v4 I& h6 [! Y1 t4 u) y
MOV9 A2 C0 Q9 { d8 Z
AL,01000000B ;中断类型号40H( o* ^( c, f3 w7 J3 {
OUT" w0 I( ~5 F8 m- p: o
21H,AL F6 Y* X" M- w3 ^& v" ]
;写ICW28 g' L9 a" p7 H9 A! ^0 a5 D1 ~
MOV
) a0 r o$ E1 {% s0 [AL,00000100B;主片的IR2引脚从片
+ T% n# K# `" | n9 U3 yOUT
! R- u n4 O3 g- t" Z21H,AL6 q, I6 ]' B, \4 h( d: I! Z
;写ICW3( R! P8 o3 J! T ]' C- I& D- m
MOV& d+ q6 A/ H3 z! N9 t3 c2 ^
AL,00010001B;特殊完全嵌套,非缓冲,自动结束8 N/ C6 T4 j& h& ]; o
OUT2 g5 x$ Z5 K1 E- i: z3 e
21H,AL* c: B6 M- z7 H4 N
;写ICW4
% I3 }: ?3 L0 k) X4 v
& I1 \* ^3 f& v3 F7 v3. APIC0 n4 b+ P$ ?. k8 t1 y- M5 B G
8 A# p; ^, X9 h( _% G+ k9 \' N: IIntel 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,& C2 ~+ I9 \0 i
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。" } N' j4 Y3 M
0 c6 u' ]. D& Y) r8 A& V
# m# t; H9 L) [# s: F' x
0 E$ g; p8 O+ {) d- z5 P* f+ @
) J: Y6 Y9 M3 p7 R9 L" w# B/ jProgrammable Redirection Table详细格式如下所示:
( ]; I+ ?. }" c+ Z( T4 A9 c7 O4 ]. S# x2 f: H+ p4 |
Bit Description:0 U( T4 F5 c& a7 X7 [
| [63:56] Destination Field—R/W.
) x7 V0 P, Y0 n- r' a/ U: t0 ~If the Destination Mode of this entry is Physical Mode (bit 11=0), bits
" h" \+ c# r7 I) E, c4 a | [59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field
: c' z P/ h( u8 Ypotentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
6 D3 X: f+ z/ u4 m$ N9 fdestination address.7 R! s' q; b' Z0 J8 ]* ]; |) \
Destination Mode IOREDTBLx[11] Logical Destination Address
' `/ |6 z$ I7 y+ [' t# i9 L0, Physical Mode IOREDTBLx[59:56] = APIC ID" L0 c" W5 {9 u' l) x
1, Logical Mode IOREDTBLx[63:56] = Set of processors: Q1 |1 N3 U% ~. E8 H+ O! E
| [55:17] Reserved.82093AA (IOAPIC)
7 Q: ~; \: A, _ | [16]1 u) u6 [# C% r1 a5 Y
Interrupt Mask—R/W.3 L; y% z/ Q( g6 X; _ B6 M9 C
When this bit is 1, the interrupt signal is masked. Edge-sensitive/ m' y& E: i" U) e) x0 Y
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
+ M6 L2 c; d4 t! fLevel-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no r) |% X7 u+ _% F
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
! w9 i7 _# Q& R7 P7 M0 c; Ta local APIC has no effect on that interrupt. This behavior is identical to the case where the
, A% l, [$ G4 l5 Ndevice withdraws the interrupt before that interrupt is posted to the processor. It is software's- L( [$ S' p/ H" @1 T+ {5 F
responsibility to handle the case where the mask bit is set after the interrupt message has been
3 G U5 n( Y# B% w! L& \accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this
2 [' |, ~" ]9 S- G" p# q, w% kbit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked1 P7 N8 F/ }0 w" {, r# g# b7 Q
results in the delivery of the interrupt to the destination., K3 @* H' a: r' G1 u
| [15] Trigger Mode—R/W.
* a, _: e `- c' EThe trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive., Y6 u, P1 c8 ]; H
| [14] Remote IRR—RO." k4 C' G* t I# E" t
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.
( p/ a9 U3 G3 g% o8 X6 I4 P/ ?/ \ | [13] Interrupt Input Pin Polarity (INTPOL)—R/W.
6 d4 p5 n# U9 U" ~& [0 z2 cThis bit specifies the polarity of the interrupt( Z. S. u5 s1 p: W
signal. 0=High active, 1=Low active.
; S* M! p' Q7 I2 G | [12]8 I) B2 M; j W0 j1 u3 c, Q
Delivery Status (DELIVS)—RO.3 q0 ]$ Z/ `: Y6 Q7 \" p" N) {( M( g
The Delivery Status bit contains the current status of the$ C! K! Q! E+ h0 H9 ]
delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit- g# @6 d: L8 n: m1 k/ f0 F2 |
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send. q7 O0 k' P$ H6 U2 }6 t8 Q
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
4 z0 O2 p$ k) \: H- _bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
! J/ R( u& B5 V/ K' j: h; D | [11] Destination Mode (DESTMOD)—R/W./ k# e# f* n- L* `
This field determines the interpretation of the
" `9 z2 t" _2 B yDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.1 v2 K' T1 O1 ]+ f& ~, l- `/ ?0 ]
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.. X: F6 T5 |$ U7 C5 C- f4 h
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 H; F; J* Q: c' U2 ]5 v5 ?: R$ L | [10:8]Delivery Mode (DELMOD)—R/W.
) D" p9 `, e& ~; g( h* K/ qThe 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+ U' U3 t, e' z
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.% U7 P3 H; u9 V8 o+ q" G
These restrictions are indicated in the following table for each Delivery Mode.' E- M, d/ _6 A
Mode Description
/ i3 J5 p& |7 c* E1 k0 e5 e000, y/ \2 ]% [4 [/ j V3 @
Fixed Deliver the signal on the INTR signal of all processor cores listed in the. h6 M4 ~- @/ i y" l
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.+ @9 v. j8 B( O7 A- Z/ g h$ s
001& i8 ~ p; C6 R+ P- Z
Lowest
6 g$ o. w7 ~0 o& V' j* jPriority Deliver the signal on the INTR signal of the processor core that is) d+ O. ]+ b% ^9 r2 j8 [
executing at the lowest priority among all the processors listed in the: [& F4 D; _+ }6 Q' Y y% m
specified destination. Trigger Mode for "lowest priority". Delivery Mode
^' |$ c6 C0 y' X( I% ]) M1 Tcan be edge or level.
( n6 z. ~$ X% D. c( `2 l L010+ _- P% ]6 Y5 c! Y
SMI System Management Interrupt. A delivery mode equal to SMI requires an* t% c- c+ K, q" H5 F$ j; C
edge trigger mode. The vector information is ignored but must be+ } k; W! L7 M0 M; m
programmed to all zeroes for future compatibility.
, V1 v) x# K8 _' l011" ~. M5 n- n+ W3 ~4 [0 ?$ q: \8 q
Reserved
, F; A% ^2 J$ M9 A3 v) {5 h: ?100( W1 Y1 k, K& b- j5 q- ~
NMI Deliver the signal on the NMI signal of all processor cores listed in the
% D: @. h; U; t* k# \* ?4 |8 Idestination. Vector information is ignored. NMI is treated as an edge
, T c6 A6 l' T* g" ~triggered interrupt, even if it is programmed as a level triggered interrupt.
- V+ P3 s1 k8 w0 H# iFor proper operation, this redirection table entry must be programmed to7 | ~+ {% b# o! B$ e% }8 B
“edge” triggered interrupt.3 H# U: }2 z3 h! \
1017 O7 a2 ~5 E' b( f
INIT Deliver the signal to all processor cores listed in the destination by$ p5 j7 f8 x l# ?$ [
asserting the INIT signal. All addressed local APICs will assume their
" J3 I, P) G" O" e! ]6 i5 }' o/ N" k$ HINIT state. INIT is always treated as an edge triggered interrupt, even if2 K% U6 O" b: G
programmed otherwise. For proper operation, this redirection table entry3 f+ ^# y& c: O2 i# w' X% ~
must be programmed to “edge” triggered interrupt.
' p3 u% N+ \8 ^2 q110
9 P& ~# I, M2 O1 _; DReserved
5 j O. M9 `" o" `7 H: }111
! o; O8 g' l0 Y% o# OExtINT Deliver the signal to the INTR signal of all processor cores listed in the
( }+ t+ p3 o* U; Q9 kdestination as an interrupt that originated in an externally connected3 S9 k, J0 Y% h' u6 b
(8259A-compatible) interrupt controller. The INTA cycle that corresponds/ V8 h( f; \ b# O/ ~( a
to this ExtINT delivery is routed to the external controller that is expected! c$ l& I5 `1 Y4 [# L3 \
to supply the vector. A Delivery Mode of "ExtINT", i, d. m' g0 E1 A4 p" C, e: h
requires an edge
# M5 `# r: [ c# g# c' u5 W5 A3 k- Ltrigger mode.
% w0 l M5 d1 R$ Y | [7:0] Interrupt Vector (INTVEC)—R/W:
/ m# J* q4 w7 ]* m+ y7 T' YThe vector field is an 8 bit field containing the interrupt! e; r8 u9 M V7 u
vector for this interrupt. Vector values range from 10h to FEh.+ n7 ?' P& {+ L' a/ {' \! b
|
0 p7 p( x: B- e+ XREFF:- Z9 @0 A/ U# ?! z
. U7 g% l: H: d2 _
1.) y! W! u9 ~* c0 l9 I
《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》8 E) j7 f% `& L; @6 [5 B
2.' N2 e' [# r3 K
《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》, g/ O+ r! {' c3 A
3.5 F6 X* r l5 W
《Undocumented PC》) D) \; b. e- J2 @; q/ _- i
4.
0 F; G( D V# R! X/ i( j- J+ s" D# a5 C2 B& r0 C
8259A初始化编程: ~' N; i& r k
+ l. `/ P' x% C- j' e; `5 k2 h3 n, ~" _That’s all!
- D0 \8 e9 z, h1 ?: {2 V* V( K$ t5 ], v& u8 b7 Q2 G/ j! u
Peter' O. e3 H5 q% z5 c2 p# B/ R
; v4 V" Q* S$ d) Z$ `9 \2010/10/07
7 T5 n0 p" E; v$ H5 j% a. J: Q8 C- H( {/ _5 w+ I G1 S
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ] |
|