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

PIC 、APIC(IOAPIC LAPIC)

[复制链接]
发表于 2010-10-29 16:11:58 | 显示全部楼层 |阅读模式
PIC APIC(IOAPIC LAPIC)
1 X9 G0 g3 w  i0 \) e
1. Overview
2 R5 L& J( `: G- h2 A7 t) j; k0 P6 v6 B
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt ControllerAPIC是为了多核平台而设计的。它由两个部分组成IOAPICLAPIC,其中IOAPIC通常位于南桥中# _$ E  t4 S8 f" i! e2 @
用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPULAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pendingnestingmasking,以及IOAPICLocal CPU的交互处理。  @5 }# n4 G% B$ z8 B: T  h

" C& t) k; p: j! w4 D; X
1 ~  ~/ `6 a1 q1 z) T2. PIC& H# L/ e' l) Z/ H
8 f9 ^1 X0 ?5 C# X
基于Intel 80x86PC使用两片8259A级联的方式组成了可以管理15级中断向量的一个中断系统,下图是它的一个连接示意图。两片8259A,一片为Master,另一片为Slaver。其中SlaverINT接到MasterIRQ2上。8259A有两种工作模式分别为编程和操作模式。BIOS初始化的时候会先通过IO port8259A进行编程配置,在此之后8259A就可以响应来自外部设备的中断请求了。MasterIO address0x20 0x21; SlaverIO address0xA0 0xA1, a9 Q4 @9 m8 e, {2 A

2 v* Q  y5 G/ v  E! k PIC.jpg
1 s9 j" s! }% u2 R) }% v7 A# T8 C6 l! s! u6 ?) ]
: c1 A7 e- v" N6 |" c5 A
为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code0 w8 Q# E: s. V9 n- {

0 h" A7 h2 K: SMOV9 v# |9 ]$ y; s! A, y% N! }( a
AL,00010001b
- ^+ \8 ?7 T  u* B9 U( n;级联,边沿触发,需要写ICW4
1 p9 h4 A- u8 D( @6 ]OUT
- t8 F2 X: d1 F; [# I20H,AL' |1 ?/ W* G2 v7 P
;ICW1
1 l/ c9 ]9 w) X" YMOV7 T* C) k2 Q4 P/ @  ?
AL,01000000B ;中断类型号40H
5 E7 \2 g! B( _& gOUT: {/ w/ z5 ~4 A2 l9 g2 J
21H,AL
5 x$ C) w7 T* L2 d; f4 s/ s5 K;ICW2! c7 D% Y' V2 ^& J
MOV( Y% B9 ?& O7 p* u* c# O
AL,00000100B;主片的IR2引脚从片- b5 ~) b5 {/ I+ C% b% q
OUT7 B. Y( K( l& _) j" d* O* L( h) x
21H,AL
# {, {* R& Y) X/ z- P7 Q;ICW3( C; y0 _* h: ]
MOV
. @3 x8 [% o5 v% Y1 gAL,00010001B;特殊完全嵌套,非缓冲,自动结束) B) b, C' w' y5 ?0 o
OUT4 G3 B! @0 p' l& r1 F. R6 V
21H,AL7 Y4 t0 X6 @" C- r- M
;ICW4
, x+ z. `  p4 p1 ]1 _, v3 }" u8 M. r$ W
3. APIC
+ c0 _# B6 n5 w/ G; c9 m: j7 _" c+ F- @* v3 D9 |
Intel 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
  j. I0 g5 j$ e& v+ d每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。# G% q* c( G2 B9 y
3 U5 P0 I9 \0 _% J

2 }% i0 M7 {, C" b IOAPIC.jpg
& u+ d: }1 N2 C3 b+ b( b+ J
9 F8 x. @) V, K& i$ C1 ]7 ?' nProgrammable Redirection Table详细格式如下所示:! y7 b7 F! p: k! w3 j* G
  b& B& ]. O! _& v$ Q) o; t: b
Bit Description:
5 n6 w8 B! O/ D7 R
[63:56] Destination Field—R/W.
# y7 M' @9 T6 j5 ~1 U' _If the Destination Mode of this entry is Physical Mode (bit 11=0), bits
4 c9 A/ b/ {  `* |& y
[59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field
( M/ l9 h6 J: A* |, w+ R. B; Apotentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
. g$ ^/ \8 }! R, [destination address.+ d' k* m7 x: g4 m6 I. M
Destination Mode IOREDTBLx[11] Logical Destination Address
1 u8 E8 p* o8 e3 b2 C0, Physical Mode IOREDTBLx[59:56] = APIC ID( K* y& K2 Q% `! c+ S
1, Logical Mode IOREDTBLx[63:56] = Set of processors' X6 A7 d/ s! s9 i4 O
[55:17] Reserved.82093AA (IOAPIC)
  s- |. ^( B9 o2 x& |# h
[16]/ _! a8 S+ z' O
Interrupt Mask—R/W.% y5 N' M" y! P8 F  q
When this bit is 1, the interrupt signal is masked. Edge-sensitive

" s; b- r' a" T! Rinterrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
. q  F  @* q' k. ?, J6 OLevel-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
; T7 `: ?5 U- n# wside effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
9 C8 y3 p  U9 j$ ~" u0 W; ha local APIC has no effect on that interrupt. This behavior is identical to the case where the
2 o* f% o' I5 b$ rdevice withdraws the interrupt before that interrupt is posted to the processor. It is software's
# |1 a1 t; T4 J0 R9 q9 |/ {- _responsibility to handle the case where the mask bit is set after the interrupt message has been  }# q% S- R: N. A- g
accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this
/ M' @1 ~: d- p3 sbit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked; i' b, L. K) e" a
results in the delivery of the interrupt to the destination.) T' r7 |- }" f0 _9 Q$ ]' e
[15] Trigger Mode—R/W.
5 ^- r* F  P7 {2 p& w7 O* I$ ZThe trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.

9 W$ G" W+ J) t+ X) b
[14] Remote IRR—RO.! N6 L8 p$ I1 ^  X9 X: F9 m0 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.
- {" A( i$ x" l' {
[13] Interrupt Input Pin Polarity (INTPOL)—R/W./ B( A, \" o+ z- t6 ?5 ]0 v$ V! P( A
This bit specifies the polarity of the interrupt
4 w, @( c/ `& f1 `8 T
signal. 0=High active, 1=Low active.& _+ H( y* S( n6 c: a
[12]) C% q7 g7 c) y5 o
Delivery Status (DELIVS)—RO.
3 M. }+ ]1 |+ I. y- qThe Delivery Status bit contains the current status of the

0 H& k: u& D+ I) p9 k: J! qdelivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit
0 K0 @! w" N9 C9 }word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
+ Z0 ]5 ^7 N% A& xPending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
; A% a4 d7 a6 z2 }1 b/ i4 ^6 f8 ybus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).& c$ {) `' |$ g* d
[11] Destination Mode (DESTMOD)—R/W." Z/ Q7 d7 @1 e0 Q. e2 I; e
This field determines the interpretation of the
& `/ M( P* D, C, ~. C% u4 }; n
Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
, v% x" C& i& K3 I. V. VBits 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.
) D6 o9 L4 g4 A! UDestination Mode IOREDTBLx[11] Logical Destination Address 0, Physical Mode IOREDTBLx[59:56] = APIC ID1, Logical Mode IOREDTBLx[63:56] = Set of processorsE 82093AA (IOAPIC)& z" D( G$ X$ Q0 q4 U+ o5 n; w; E) q
[10:8]Delivery Mode (DELMOD)—R/W.
+ i$ h1 o% _1 p9 L6 xThe 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
5 _. j4 ~9 I4 j
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
  `2 d: i9 u& ]- cThese restrictions are indicated in the following table for each Delivery Mode.
6 `! c. C: K+ T& X+ KMode Description
7 V$ E) S: O4 l2 }: v% C9 c0 c000  G. n/ S* x# i2 @0 k
Fixed Deliver the signal on the INTR signal of all processor cores listed in the
( L- k- L0 f& v% @. Y
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.* @6 o4 R% V: W: m* p- M
001/ U/ q7 y$ m7 Q  X3 j6 M; M
Lowest
# K& P. d1 w: c
Priority Deliver the signal on the INTR signal of the processor core that is
; a  R: N+ z3 L. ^, Dexecuting at the lowest priority among all the processors listed in the  w( x! h; V# H: g6 h
specified destination. Trigger Mode for "lowest priority". Delivery Mode
+ U0 [  S* P0 I# }& Z& acan be edge or level.9 ^9 _/ u& |, q7 l2 B
0107 r& d3 n" B/ W1 i
SMI System Management Interrupt. A delivery mode equal to SMI requires an
1 o; U( x+ r9 h# i+ Z
edge trigger mode. The vector information is ignored but must be
3 c  H! _/ g( [- bprogrammed to all zeroes for future compatibility.
) C$ w; [: ?+ v1 e! S1 s0115 H0 {: I% k3 u" |  F9 I
Reserved

) G" S% F+ Y) w* P; k* _; s2 I100
$ T& x2 s: r4 E2 z+ tNMI Deliver the signal on the NMI signal of all processor cores listed in the

% {: a4 B' N5 I6 A% w9 u# N& Gdestination. Vector information is ignored. NMI is treated as an edge. ?( k+ P) _9 l) \  a; h/ h" m% |  z
triggered interrupt, even if it is programmed as a level triggered interrupt.8 }7 `* `/ K$ o# A" Y
For proper operation, this redirection table entry must be programmed to
) F# ^; Z! I+ I1 D' Cedge” triggered interrupt.
& n" E$ }9 |/ a- S6 s- [, v101- U+ v1 |& ]& C# T
INIT Deliver the signal to all processor cores listed in the destination by
7 ?$ H, V0 X4 }3 W
asserting the INIT signal. All addressed local APICs will assume their1 v8 Y( K1 i; B8 ^% h" [
INIT state. INIT is always treated as an edge triggered interrupt, even if" o: F8 z) t( o4 }0 j( F0 J
programmed otherwise. For proper operation, this redirection table entry& W' N1 }* C( N) A& X, c+ ?& X* T
must be programmed to “edge” triggered interrupt.
  y# s3 r# x0 P  g110
- T3 h+ T6 H" X; U& pReserved
. V9 |7 R5 T' w) D
111
2 C& D" T: J  w3 R( EExtINT Deliver the signal to the INTR signal of all processor cores listed in the

' w' J1 i4 W  Tdestination as an interrupt that originated in an externally connected
% d  f7 q# c4 ]/ C2 `/ j- a(8259A-compatible) interrupt controller. The INTA cycle that corresponds$ o$ [/ S) ~4 X5 U9 ^
to this ExtINT delivery is routed to the external controller that is expected
5 H6 a2 C7 f; g8 Y  e( X7 ?; C' v# hto supply the vector. A Delivery Mode of "ExtINT"
0 v9 v9 h6 W9 Q: Z$ M  f2 F, _3 yrequires an edge

. l# x# Q) n9 P4 C; k* v1 @& Ktrigger mode.
  E' l% r2 e" l+ k1 A. Y! n
[7:0] Interrupt Vector (INTVEC)—R/W:# x, o! O4 _2 _
The vector field is an 8 bit field containing the interrupt
/ p) _: N# L( v* q
vector for this interrupt. Vector values range from 10h to FEh.$ N. |. e* H2 m, G) K% Z! X
6 h  S4 a7 h! ]
REFF:
9 P, w# X" C8 L1 Y
& O4 b' n* t1 [7 H! K# r1.
9 r* f( y. N+ e( s% E) y82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)
# Y! Y0 S8 o8 y5 ]: W# x  s1 ^2.4 B' G* E" |3 \3 [! e5 G
8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)
5 y4 O$ x( R. W# o7 ^  a3.
7 A$ `  T3 S  n* ?% R0 t8 U! j! B! oUndocumented PC; j( _1 {1 K  T* J# J( v
4.
. V# g/ W# Z' i* g2 a/ l" j/ R
3 s: g# y- y: Z, X+ @8259A初始化编程
6 Q8 m0 `* Z# |' ?
; ~! U5 h# v4 pThat’s all!  l  w: J! X" ?
6 l9 [1 @  h9 T
Peter( A% j/ }* i) s$ _7 Q8 A( c+ Q

" u. u5 J0 W: F# _2010/10/07
, w: g/ s1 ?* Q: o$ T
0 t1 s0 v+ r$ ~; N4 J5 i[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ]
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

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

GMT+8, 2025-6-17 07:34 , Processed in 0.052488 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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