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

PIC 、APIC(IOAPIC LAPIC)

[复制链接]
发表于 2010-10-29 16:11:58 | 显示全部楼层 |阅读模式
PIC APIC(IOAPIC LAPIC)

* ]9 X& v. |9 k, S5 h1. Overview
7 X! _- X- \9 r+ g0 U
5 \: g: ?4 Q9 BPIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt ControllerAPIC是为了多核平台而设计的。它由两个部分组成IOAPICLAPIC,其中IOAPIC通常位于南桥中  \+ Q; T# J8 q: j
用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPULAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pendingnestingmasking,以及IOAPICLocal CPU的交互处理。4 s3 ^( x& c, y6 j2 p

6 F5 t5 \! o2 S5 U  k  b# q) P8 b0 g6 l* ]+ M: s6 }# Y. v
2. PIC
. S0 r9 A3 k. k7 y7 ]; {
4 p* V$ n- L5 [6 l基于Intel 80x86PC使用两片8259A级联的方式组成了可以管理15级中断向量的一个中断系统,下图是它的一个连接示意图。两片8259A,一片为Master,另一片为Slaver。其中SlaverINT接到MasterIRQ2上。8259A有两种工作模式分别为编程和操作模式。BIOS初始化的时候会先通过IO port8259A进行编程配置,在此之后8259A就可以响应来自外部设备的中断请求了。MasterIO address0x20 0x21; SlaverIO address0xA0 0xA1) E4 ^6 |2 c) W0 _2 _2 Y; A
8 w% R7 k! h8 S5 k" S% Q  g  ~
PIC.jpg
; |2 V* m, W. w2 x0 M% ]* o! H  O
* h9 W6 L, q& l) k! k( _
$ a+ f/ M; a, f4 W# D; l6 }* O为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code+ X3 O4 R+ r0 U  `$ t+ J$ ^

7 m2 F7 g3 M* H. ?2 a! W7 [) GMOV  q4 u" h3 ^" d% g$ m3 j9 x
AL,00010001b' t: j% y5 _3 m. w" T- l
;级联,边沿触发,需要写ICW4# U# m6 ~) @5 \2 ^9 L
OUT+ j2 N! n# ?2 }5 Y  m1 R
20H,AL
" b! x5 u* {2 ^. k- g, d;ICW1
7 d1 c3 L6 ]$ U* LMOV( @; i* c4 ?4 i2 ]
AL,01000000B ;中断类型号40H# K" K3 b5 U9 {  U* ]6 |
OUT
0 V1 k* t# a9 C# q2 H1 v9 T21H,AL( l, L# t" }( A5 q3 G9 A0 {
;ICW2  x5 s# x" j$ [0 P+ O
MOV9 v+ d( k8 ^8 B3 N# l
AL,00000100B;主片的IR2引脚从片
, v; ?- C$ d! D, SOUT
$ e' |; W4 J" i21H,AL) g! B5 c+ d- Z( z
;ICW3% B0 w5 \  F' N7 N- O+ L
MOV; o( g3 p4 [9 h8 u- X
AL,00010001B;特殊完全嵌套,非缓冲,自动结束
' h; c: x# M9 y+ xOUT
" Y: k4 V4 S: y# C21H,AL7 R  L7 q: N+ q7 K+ k, _8 Q5 x
;ICW43 T# ~, s2 X0 n: W
! b. L5 k* m6 v4 _4 T1 U; B
3. APIC
4 \8 [7 U1 ^+ @5 _$ t) z0 c
- Z8 J& v8 h) J$ IIntel 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
7 {" ?; |( v; j& S" r# A每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。. w) P9 A; O+ m8 \  l/ h: i5 m

# ^9 G7 {# l5 u/ @. E
/ T+ A: o3 V. b% e6 b% V IOAPIC.jpg
$ }8 `. r& K# Q0 C" B6 l& N* O9 R0 J
Programmable Redirection Table详细格式如下所示:
% E6 S6 ^# Y& n! B8 {& d" s/ d) N4 |9 L9 i( y+ P
Bit Description:
9 N; e, }% \2 q% z$ O: A& y
[63:56] Destination Field—R/W.
7 G  H$ v8 p/ [' cIf the Destination Mode of this entry is Physical Mode (bit 11=0), bits
6 n, r/ s9 _. s: c, U
[59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field
" e  N0 l. V9 L& T% H5 V7 r* Spotentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical  t) e! i& h8 X! E2 R) e1 ~- z
destination address.1 T& a, h, {1 A: v) [0 p
Destination Mode IOREDTBLx[11] Logical Destination Address' w; Y/ r" L) u. P0 d7 f
0, Physical Mode IOREDTBLx[59:56] = APIC ID6 ^* F* n0 V9 z" d
1, Logical Mode IOREDTBLx[63:56] = Set of processors" t) I; P/ U9 [* s
[55:17] Reserved.82093AA (IOAPIC)
7 n& N) a! x; w0 {: U- r# q
[16]
. j2 K& X( p* R9 c: gInterrupt Mask—R/W.( M: Z/ D9 b; _& P. R
When this bit is 1, the interrupt signal is masked. Edge-sensitive
% k/ c. o2 O  X- C
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).; R, }  j! M" |3 x9 ]) r
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
1 S( _, G3 E. l6 R# x2 B, x5 Jside effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by! v% }# P, Z3 b2 u. b
a local APIC has no effect on that interrupt. This behavior is identical to the case where the
: e& w  P9 ~3 o8 A5 {device withdraws the interrupt before that interrupt is posted to the processor. It is software's
6 ?4 v, y' x; W) a+ E1 V8 `responsibility to handle the case where the mask bit is set after the interrupt message has been
7 U% v/ T( y; H1 Q" d" Y( Baccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this
- s% L) t- V1 }) c# xbit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked! D: y: U' z9 q' `( @
results in the delivery of the interrupt to the destination.
3 A7 s" }# K4 ^- O8 ^" r
[15] Trigger Mode—R/W.
2 C& H# l5 [( t5 ~0 PThe trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
( q/ ?' m! ?& D* B6 h
[14] Remote IRR—RO.
. }8 a1 M- ]4 W& p9 QThis 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.
7 A& @! k0 t9 v/ [+ {- Z$ c
[13] Interrupt Input Pin Polarity (INTPOL)—R/W.
6 F+ V: O, M+ ZThis bit specifies the polarity of the interrupt
& i0 U; p7 x" T. B
signal. 0=High active, 1=Low active.- B. L! l8 e) D9 A  P7 F
[12]
# E: z' y# E/ `) y3 o: B2 zDelivery Status (DELIVS)—RO.
/ P, x: q  C2 \4 G1 o8 mThe Delivery Status bit contains the current status of the

4 J0 E% e4 U: D1 Q  N! s- z7 hdelivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit
; z2 A# h2 j0 J9 P  U+ T+ @word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send* W. h- H/ J4 g5 K
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
; {3 l  Z4 |7 r) K7 rbus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).# `% a2 k! D) T0 q5 e$ e
[11] Destination Mode (DESTMOD)—R/W.
* }. Z- ?1 b3 D: P2 L! dThis field determines the interpretation of the

) Y% G0 \, i# ?: {  }' [Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.) q# v4 m; C1 ?6 s7 x9 u
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.
. v  V) w: n* X6 e: m1 h2 cDestination Mode IOREDTBLx[11] Logical Destination Address 0, Physical Mode IOREDTBLx[59:56] = APIC ID1, Logical Mode IOREDTBLx[63:56] = Set of processorsE 82093AA (IOAPIC); I3 k8 O5 X. `3 W0 Z; _
[10:8]Delivery Mode (DELMOD)—R/W.3 [$ z' t6 I6 E0 ^& u! M  M
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
+ t  \# r! _7 ]9 A
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.& V& q# \, i2 N, B
These restrictions are indicated in the following table for each Delivery Mode.0 j9 p& F; A, `# F
Mode Description, d0 _3 Y3 |. C, A4 X
000
5 d6 J" M5 g) a1 y) W9 M' qFixed Deliver the signal on the INTR signal of all processor cores listed in the
  f0 ^# F3 d/ s, P1 Y
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
2 q8 m' T+ {; G2 z9 G9 n# Q( h1 T! E001# U8 w( d$ ?; _
Lowest
: G- r8 S0 l1 @
Priority Deliver the signal on the INTR signal of the processor core that is
  s% }+ B: t+ k1 l1 Kexecuting at the lowest priority among all the processors listed in the2 h$ h1 q  M7 V) ?. `
specified destination. Trigger Mode for "lowest priority". Delivery Mode
2 Z& k- s/ S6 m( ^9 [can be edge or level.
6 g; K0 o' F2 _$ y9 |. x010
0 T! f7 O( f% f& {, t) R- m! pSMI System Management Interrupt. A delivery mode equal to SMI requires an

& I& f6 M: q; R& R: @  b3 ~edge trigger mode. The vector information is ignored but must be0 @/ S) F# f. z, E! o) [  }# _
programmed to all zeroes for future compatibility.$ {* ?/ |7 q- e% U
011$ R' U7 l: ]3 S" N
Reserved

$ I7 R( z3 p& P+ n. Z- \- Z% k100  h% ^5 w$ Z0 B
NMI Deliver the signal on the NMI signal of all processor cores listed in the

. H$ z0 _/ }. o6 adestination. Vector information is ignored. NMI is treated as an edge
: Z% m( a! I! I1 F4 ~9 Atriggered interrupt, even if it is programmed as a level triggered interrupt.
; z" g2 p8 s9 }2 b( A  Y4 O( pFor proper operation, this redirection table entry must be programmed to7 \" R8 m1 K5 W1 {
edge” triggered interrupt.* O9 I5 |, d- V/ S3 P
101$ l; t0 j9 Q$ t* j9 |7 N8 R
INIT Deliver the signal to all processor cores listed in the destination by

4 b. g) T+ j8 y/ ?! m/ qasserting the INIT signal. All addressed local APICs will assume their
7 H+ T6 S' |- O+ y# L& U, h# fINIT state. INIT is always treated as an edge triggered interrupt, even if! j, W1 w3 t' e
programmed otherwise. For proper operation, this redirection table entry& [' W- U( c$ B& Q5 i  ]
must be programmed to “edge” triggered interrupt.
: o& P9 D; s+ x110
# e1 j0 o: M! Y* b5 aReserved

& U+ ]6 _- B3 ?: j- H& N111
/ J; Z4 B8 r1 x( V# x3 rExtINT Deliver the signal to the INTR signal of all processor cores listed in the

& r0 `+ k. j0 f1 W  Q) Y% F0 P' v7 gdestination as an interrupt that originated in an externally connected+ A& w* N6 ~# D6 O  l
(8259A-compatible) interrupt controller. The INTA cycle that corresponds
& T+ o! _5 j2 p- J9 E& Pto this ExtINT delivery is routed to the external controller that is expected
6 X! E4 s+ u  ^, h5 {7 V7 Kto supply the vector. A Delivery Mode of "ExtINT"
" K# o3 ]+ }8 Z7 Y' n& s% mrequires an edge
% C7 [  Q) n, ]2 e3 `, o) z
trigger mode.& [; ?' t2 I3 V) g
[7:0] Interrupt Vector (INTVEC)—R/W:, g  e" X2 V' |+ ^! K
The vector field is an 8 bit field containing the interrupt

, ~  ], _5 p( f7 R- avector for this interrupt. Vector values range from 10h to FEh.
7 h8 g7 S) ]& ?! x' b. Z
5 K4 Q. I2 }4 ]5 N7 ]
REFF:9 u1 A9 ]# z/ G8 L  ^5 |1 W
# A, i. e8 Q, V) m. t/ p
1.
  w4 J8 c( V. A0 g8 u# w82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)
& R8 m9 {0 J, r; S: \# |, i2.
7 L3 @( u! C( @  p( H% h" s8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)
+ s& X  _3 |$ s! G3.9 n1 b" D# X4 E) _" {2 i
Undocumented PC
" |: U! Y) Y' ~) A4.
2 X2 B! U: s  ~% J% s2 d) i5 \
7 o; L' h" V1 D- E+ _8259A初始化编程
5 @5 a; M  e8 K% T) n, n
% c: @( {+ H5 i" x$ G3 h  ~That’s all!) F" x9 k8 R' d
: p0 x2 d0 t; i8 S4 n
Peter
) b# e6 {8 z2 o9 W
% c+ ~* V' h1 m3 j7 g" V2010/10/07/ _0 v. D, q6 d) j
- w5 l9 _# _) L% R0 X
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ]
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

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

GMT+8, 2025-12-1 07:50 , Processed in 0.082541 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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