找回密码
 加入计匠网
搜索
热搜: BIOS ACPI CPU Windows
查看: 39915|回复: 0

PIC 、APIC(IOAPIC LAPIC)

[复制链接]
发表于 2010-10-29 16:11:58 | 显示全部楼层 |阅读模式
PIC APIC(IOAPIC LAPIC)
. y/ a" s- G$ T
1. Overview
; c& ]& |/ @6 H$ J# {  u$ u9 P8 K7 L0 s$ a/ W. _. z! l* y  f3 g( p
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt ControllerAPIC是为了多核平台而设计的。它由两个部分组成IOAPICLAPIC,其中IOAPIC通常位于南桥中9 q+ I, a, P$ j0 A
用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPULAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pendingnestingmasking,以及IOAPICLocal CPU的交互处理。
# t, o8 Q. O8 L) N0 {4 Y2 Y) |+ n# m- r. C7 _6 f6 Q

/ q0 v% H! l& j0 e7 R0 E2. PIC
6 p" w; |# a# B& ~0 {& b' |; ?0 s
! h  z+ ~. f* U( p  J基于Intel 80x86PC使用两片8259A级联的方式组成了可以管理15级中断向量的一个中断系统,下图是它的一个连接示意图。两片8259A,一片为Master,另一片为Slaver。其中SlaverINT接到MasterIRQ2上。8259A有两种工作模式分别为编程和操作模式。BIOS初始化的时候会先通过IO port8259A进行编程配置,在此之后8259A就可以响应来自外部设备的中断请求了。MasterIO address0x20 0x21; SlaverIO address0xA0 0xA1
' ~1 @  e0 R$ B% d& J" I1 ~- T6 p9 i' C2 a
PIC.jpg
& b$ |5 W; f7 f( A+ Z; a) d7 q- u; n% o

6 H, r1 N6 \! N( O% o, m+ j为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code% X" @- y6 Y' q
4 }) N7 }, W: H, ~6 _( k
MOV
! V  L9 G4 c' _* X. [) \, Q' a/ Y3 Q  h0 TAL,00010001b6 M2 x& y6 @2 g  ?
;级联,边沿触发,需要写ICW4
: D, [" X( m/ g1 FOUT+ I) x3 w* N' t" U
20H,AL  C" m: \6 `9 p3 S
;ICW1' i: |# J6 x) x- N/ J9 R5 |8 O2 D, C
MOV
+ F4 _8 U* b  V* f. o/ y  |AL,01000000B ;中断类型号40H
; [8 g+ C: G% U- ?7 MOUT! z' O4 T  Q+ [, E
21H,AL
9 p: O  z: W6 Z;ICW2
* ^1 {5 b3 l% r8 W2 \MOV
* }* B; ^& R" v% p4 ^AL,00000100B;主片的IR2引脚从片2 u' e$ M  E  K8 c$ \, e( a  k& w! N
OUT; I$ }. ]( [9 {& E6 P( T4 m
21H,AL9 o" O, M* i% o: G
;ICW3
! |+ W, @3 ]8 ~# u4 WMOV
! j, [; v% v% J$ KAL,00010001B;特殊完全嵌套,非缓冲,自动结束$ a/ L4 D$ S5 E0 Z0 e' c
OUT
4 A7 @  F) ]( x5 c' b- ]! @: y21H,AL
) A2 ~4 t  W$ W6 D  t;ICW42 h( }1 e# m6 S2 k
  _( x4 N3 U" T3 _3 G
3. APIC2 ]3 ^2 r. |2 w1 {) ~, q5 Q

9 M+ }  n8 }  ]& H4 d: DIntel APIC由一组中断输入信号,一个24*64bitProgrammable Redirection Table(PRT),一组register和用于从APIC BUS(FSB/QPI)上传送APIC MSG的部件组成,当南桥的IO device通过IOAPICinterrupt lines产生interruptIOAPIC将根据内部的PRT table格式化成中断请求信息,并将该信息发送给目标CPULAPIC,再由LAPIC通知CPU进行处理。下图是一个基于Intel APIC的连接示意图,如下图所示IOAPIC上有24interrupt pin
4 d: _' @$ e' z, e. q每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。) U( S$ B( `# h% M3 g2 b
# P7 L" |8 |. M6 |' w( o! X
. R$ H$ X* v7 c3 ^
IOAPIC.jpg , o9 N" x' r8 z! n

% J" Z- [9 g" m' R& V& _Programmable Redirection Table详细格式如下所示:4 L% ~7 h$ G7 w; ?, ~  q
" t, m7 y3 U, l# D9 p
Bit Description:2 X( x) j4 C# Y( t  k& p1 d
[63:56] Destination Field—R/W.+ {8 \2 ~1 @, S0 k; I# b6 n
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits

# `) X' M4 D7 O1 m
[59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field: i$ L8 e/ n0 u& @5 T/ F4 e
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical0 b( _; x5 m/ `2 F4 u1 X) b
destination address.9 i7 J/ P' B7 ?
Destination Mode IOREDTBLx[11] Logical Destination Address
3 R, c' X& x* E" c. D+ S0, Physical Mode IOREDTBLx[59:56] = APIC ID
8 C1 m( M) ?  t7 }1 n1, Logical Mode IOREDTBLx[63:56] = Set of processors9 W% c) j4 B$ ]4 K7 Z) V
[55:17] Reserved.82093AA (IOAPIC) $ h: `1 I1 j; r* O# s3 c2 n' b
[16]
" x( L; L; D0 j1 [Interrupt Mask—R/W.
$ B! [, p6 q) K1 x' }% Z) F2 i5 mWhen this bit is 1, the interrupt signal is masked. Edge-sensitive
( G  i6 ^1 V$ b3 @
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
& e2 U5 R8 D- _/ y8 uLevel-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
0 k0 _8 a! o* G" R6 Hside effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
3 Z8 V2 I9 g4 o' e$ n( Ya local APIC has no effect on that interrupt. This behavior is identical to the case where the5 M9 e' ]% d6 \7 I
device withdraws the interrupt before that interrupt is posted to the processor. It is software's: Q) u5 a) G+ n' H3 R* l3 i
responsibility to handle the case where the mask bit is set after the interrupt message has been
- D$ Q! V" F% p+ Y% F; kaccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this1 K5 e7 T" I7 _8 ~
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked7 Y3 i- |5 M9 s; j" t
results in the delivery of the interrupt to the destination.: z6 o+ e- a, n6 n; h
[15] Trigger Mode—R/W.  D& i$ M1 t4 G! ~3 z1 n7 y- ?# c' \
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.

. x9 ]; Q2 y% v6 V9 C3 M( a
[14] Remote IRR—RO.0 v2 _' j5 r, a
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.

; A: `+ v/ t$ l& S
[13] Interrupt Input Pin Polarity (INTPOL)—R/W.
& p6 h2 b4 ]6 jThis bit specifies the polarity of the interrupt
6 ]* a- S- w3 X9 n
signal. 0=High active, 1=Low active.
. E* ~1 @! M; v& {; I( S% `1 v& s
[12]1 o$ x* @/ \+ l( v" G
Delivery Status (DELIVS)—RO.5 m6 p! ~  B- h  a0 j- l: ~
The Delivery Status bit contains the current status of the

; d1 P, h) Y% L& v' L% Pdelivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit5 D! O. }7 |# w. I( |  z
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
/ ?: r' E. O/ g+ p: vPending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
" n; H, D. D: r& a1 f2 qbus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).& A/ [5 l- v# @& M; \& i
[11] Destination Mode (DESTMOD)—R/W., X% @0 g& A( F! x" }9 j
This field determines the interpretation of the
- D, S" X- u& v, N& e+ L- L3 q7 c
Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
6 E4 \. v9 p' x; }, _. TBits 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 t5 M) |! V& ?3 B& c/ F% N
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)
* y7 Y1 T) W+ K  _+ j
[10:8]Delivery Mode (DELMOD)—R/W.
2 i/ F! q* ~+ `9 P% lThe 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

& s/ \# i7 h$ a* L1 v. sDelivery Modes only operate as intended when used in conjunction with a specific trigger Mode.* v2 c. v* d( u& J; u2 N, ^& G. k
These restrictions are indicated in the following table for each Delivery Mode.% l& @9 U7 a8 O5 P: ~" C2 {! }) s
Mode Description
  G( `; A: j# a0 Z000
- K* [  a3 ?" S9 w& tFixed Deliver the signal on the INTR signal of all processor cores listed in the
) R4 S* i$ h* u1 F6 l6 ]
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.3 h+ ^7 r1 Q, }# t% {8 u$ E9 s
001, d. V: i& W! t% B& v
Lowest
7 U, Y) |- c+ h
Priority Deliver the signal on the INTR signal of the processor core that is! U& d' V/ }: f* f0 ], \
executing at the lowest priority among all the processors listed in the
; [3 ^: X. M& T. _/ Q5 x- Uspecified destination. Trigger Mode for "lowest priority". Delivery Mode2 b8 L4 I+ i& W
can be edge or level./ f. b- }! |5 a0 ^% w3 d# y
0108 r  {1 c1 d4 s( R  j: B0 X
SMI System Management Interrupt. A delivery mode equal to SMI requires an
; D7 `! G2 r& w8 u6 G4 F
edge trigger mode. The vector information is ignored but must be& |* c  a( u5 N1 O; g
programmed to all zeroes for future compatibility.
& N6 C. q; Y) T3 m9 w011* e- ]8 Z" c; ?, }0 C
Reserved
% z. y- k2 _* L. ]
100  {$ Z* n; i$ @5 n! H, }
NMI Deliver the signal on the NMI signal of all processor cores listed in the

0 L# u/ ?6 f, L( Kdestination. Vector information is ignored. NMI is treated as an edge
  u1 e9 s2 [5 [2 J$ h1 j  b1 V9 utriggered interrupt, even if it is programmed as a level triggered interrupt.
! n! n) v; n% O4 y* A4 d. C. [% lFor proper operation, this redirection table entry must be programmed to
) J. b! S9 o$ O- K* Oedge” triggered interrupt.
1 o, ]+ a" Z9 N2 W1 ^6 k; k101) E2 \7 R/ V+ [4 d: U; W# d
INIT Deliver the signal to all processor cores listed in the destination by

+ T0 V; i7 f8 a: v- \- R* v: ]asserting the INIT signal. All addressed local APICs will assume their- l; {  w. ?" ]5 c2 z5 G+ b4 d
INIT state. INIT is always treated as an edge triggered interrupt, even if. H9 L4 W8 }- b; G4 W4 K0 @/ @
programmed otherwise. For proper operation, this redirection table entry! K+ v1 H) Y, h
must be programmed to “edge” triggered interrupt.+ t6 s3 O7 q! V1 l3 O3 z4 n
1104 Y5 F" v8 }3 h
Reserved

( f/ u5 R7 `7 F. S111
8 E1 f# [) ?: q7 b- a9 y3 MExtINT Deliver the signal to the INTR signal of all processor cores listed in the
4 N$ v0 ~. d) @* a7 m
destination as an interrupt that originated in an externally connected+ d" M( R) J( Q3 A4 I
(8259A-compatible) interrupt controller. The INTA cycle that corresponds, F" L" _0 H6 ~  `% i2 i
to this ExtINT delivery is routed to the external controller that is expected
: B/ C0 n; ~* n3 f( i7 R, \to supply the vector. A Delivery Mode of "ExtINT"
- O! r1 [$ q& g5 }requires an edge

+ B- z' J. X% i. n- l4 ytrigger mode.! Z3 C. M# h! K- ^
[7:0] Interrupt Vector (INTVEC)—R/W:
* c- ?3 c! m& r5 N+ @The vector field is an 8 bit field containing the interrupt
- F/ m9 ]3 k. [
vector for this interrupt. Vector values range from 10h to FEh.
1 U+ U) c; Q; o1 [0 p4 X; ~: m6 p3 @

5 P" h& @: F3 ~+ z, jREFF:! Y% @  R/ p0 r/ Y2 u5 {- c8 A8 I3 c
- b+ D% ]7 g5 R4 j' I
1.
' W3 ^& k' f: r$ G. C4 ~3 ?3 s/ S  b82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC): L7 B* @6 v( S- t: m
2.
5 X# H5 l" d) z' v7 @* N( `4 S8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)
) i, h8 Y4 I) V! x: u3.
% l! [  ?- b" i' QUndocumented PC
2 f" b2 i" f1 r7 R4.6 x/ V/ S/ e- I: k$ y

# z( _, J4 z$ t6 M& a( c; O8 g1 ]8259A初始化编程
+ k' z% `2 m1 S( X: L  R
0 \( O, j# O! H: mThat’s all!- G8 K+ a: s9 ?/ o4 B& j
2 y: s* }- G3 ?3 H( v8 a
Peter8 r" P: W7 M" s- U) f0 N3 f6 |9 M
* W3 X/ x8 t7 T! n" O
2010/10/07! W3 J* S, \; X) H5 o0 h9 `7 v

- ?1 d. e5 C; y, e% G- R: M[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ]
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

Archiver|手机版|小黑屋|计匠网

GMT+8, 2026-7-19 12:19 , Processed in 0.043906 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表