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

PIC 、APIC(IOAPIC LAPIC)

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

  d: A7 ~. \4 P5 ~5 Z1. Overview
0 w8 n) @3 X0 R6 w# f( @4 {+ Q0 C! P  M
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt ControllerAPIC是为了多核平台而设计的。它由两个部分组成IOAPICLAPIC,其中IOAPIC通常位于南桥中
. A1 r8 m0 D2 w用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPULAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pendingnestingmasking,以及IOAPICLocal CPU的交互处理。4 U  q. L. x8 a% u7 `; q) t4 e$ T

( [9 `" b$ p1 P$ p* n+ v
' l  d, F$ e/ b7 k2. PIC" w+ Z7 w0 z6 `9 c5 o( f: d& A

3 e2 p8 L4 w( u0 \: N基于Intel 80x86PC使用两片8259A级联的方式组成了可以管理15级中断向量的一个中断系统,下图是它的一个连接示意图。两片8259A,一片为Master,另一片为Slaver。其中SlaverINT接到MasterIRQ2上。8259A有两种工作模式分别为编程和操作模式。BIOS初始化的时候会先通过IO port8259A进行编程配置,在此之后8259A就可以响应来自外部设备的中断请求了。MasterIO address0x20 0x21; SlaverIO address0xA0 0xA1* ^! B* o" `2 b" J- p7 }$ a

$ h% v& D2 N6 s* J2 ~  B; o9 F; z PIC.jpg
8 ~" S  t  N. U3 P; g' ^
& {7 Y0 r& {- U) m, a4 M8 q' M7 E- E
6 Y& P2 a8 {3 E, z; C7 B为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code8 H9 O# e2 L# ^8 s' j! j3 y

0 l3 D+ f9 \+ O+ j0 n/ D  U, _MOV
( Z' r1 M4 }8 a- h7 l8 W7 jAL,00010001b7 e. g! \: L/ x
;级联,边沿触发,需要写ICW4
' h& ^4 q. z0 xOUT6 _6 e  N' X) L% g) u. }+ {8 p
20H,AL6 D; E0 `5 p( @* f. A
;ICW1
" P7 x5 B! \( R% v( oMOV
- x% Z; q* ~+ s1 l! vAL,01000000B ;中断类型号40H
3 b5 x& v& |5 r. ]: {$ [( b1 WOUT! L4 b8 V3 e: `; J9 v4 w5 \0 ~
21H,AL
, }9 z6 r6 ?7 j. y: a) i;ICW2& a0 R4 D" t% t) V! z- ]/ v
MOV1 k7 {  q6 F2 D# ]8 Z. R
AL,00000100B;主片的IR2引脚从片" g' Z* a* W! h/ x7 Y. g( x
OUT
8 I( x6 T! z% t+ Y1 v, e21H,AL! @( x7 Y& S5 Q0 _5 K9 p4 e- h. F
;ICW3
7 a4 P4 ?, u9 [* y; }MOV( k4 y8 I/ R  n
AL,00010001B;特殊完全嵌套,非缓冲,自动结束, ]4 C4 h* R9 R9 H3 ?
OUT
2 `* w; C. }0 C6 @21H,AL4 W. q, `6 `3 p7 A! ~
;ICW46 G: e1 Q0 i; a, s, S
& ~4 c, X8 }4 D& v* S6 H' L
3. APIC$ |1 z5 t/ M8 _  i: O
7 X& d1 l, p7 L+ \* J# e) m! u
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 pin9 }: l- f8 h! v9 a
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
; {  ~+ ^# \. x0 I0 J- I0 F; C/ _4 A0 a: F  E9 E2 ~5 a

: J& q  S8 ~3 X0 W1 A IOAPIC.jpg
1 c4 f: X0 M, h9 Y3 \! U- v
2 H9 `3 q7 y% @. v7 p" Y7 dProgrammable Redirection Table详细格式如下所示:
2 l3 J2 s$ X, H6 Q  l& W/ V
; `* ]4 f$ T) f) Q
Bit Description:
9 D7 w8 }! l. X$ m6 C# h
[63:56] Destination Field—R/W.
! w$ h; R) u! e0 ZIf the Destination Mode of this entry is Physical Mode (bit 11=0), bits
" n5 V0 q  y+ n' ]
[59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field- Y; j( r0 m2 @: N8 }
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
. Z8 S  \; R$ M8 L* Cdestination address.
3 ~1 R5 q% n, T5 VDestination Mode IOREDTBLx[11] Logical Destination Address! D+ `* |  D5 [  q+ A/ r# @. m
0, Physical Mode IOREDTBLx[59:56] = APIC ID
5 A4 B8 u5 ?4 ?6 h" t1, Logical Mode IOREDTBLx[63:56] = Set of processors3 K* C/ A+ m6 U. s3 ]3 J# G" _
[55:17] Reserved.82093AA (IOAPIC)
8 y8 f' F) F* u5 C2 r5 q
[16]
. n& U0 n8 x- n, \Interrupt Mask—R/W.
5 Z) J( w5 [6 t' e$ bWhen this bit is 1, the interrupt signal is masked. Edge-sensitive
( M" d3 r$ Y3 S7 ^* V$ s5 j- t
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).& S, p  {6 j; a$ K1 h& I9 R
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no! g. d: u, o% U6 G; W
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
% r. q1 E- u. Z* u% y6 na local APIC has no effect on that interrupt. This behavior is identical to the case where the
# F% e0 |+ k" Z( _2 b' Z4 Wdevice withdraws the interrupt before that interrupt is posted to the processor. It is software's  ]5 |3 ^5 f- a; X/ Q
responsibility to handle the case where the mask bit is set after the interrupt message has been
1 O0 F) v7 D: \! Baccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this
" X( |5 B4 |0 e0 D$ p% N% M7 [bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked; C3 c6 K' s6 N8 N% {! I) ?3 R  w8 u/ E
results in the delivery of the interrupt to the destination.
$ F. N. ]; @3 c( q- C, v" S
[15] Trigger Mode—R/W.3 ]3 c% P& h1 ]" {( X
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.

+ I# S7 H, j5 ^2 l8 f6 y" Z
[14] Remote IRR—RO.
3 Q/ P2 t9 r. l6 |* K" UThis 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.
0 |# F6 j, j7 x0 B' t
[13] Interrupt Input Pin Polarity (INTPOL)—R/W.
! s$ V5 g; }! W; U9 a, h4 VThis bit specifies the polarity of the interrupt

& T9 `3 O; F5 a% A" Tsignal. 0=High active, 1=Low active.
/ J: ~# W+ t' Y  f5 D) R' Q$ i
[12]' b! ^6 ~; c' o' ]4 j% e6 q
Delivery Status (DELIVS)—RO.8 X, i  I% S) b& b( |3 L
The Delivery Status bit contains the current status of the

% M5 a* j5 q  u! d& ~delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit- \9 w* ~  I1 V$ g* s5 z
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
1 H% Q( y& y% P( O. v* t2 ]Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC7 T9 X# Z. y7 M" F8 ?/ n
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).) `* y5 o% R* u
[11] Destination Mode (DESTMOD)—R/W.
: @4 F% f6 q" S2 ZThis field determines the interpretation of the

  x& e1 R  P* d  i' [Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.) d. k+ ]! }7 r* t' Z
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 C. w& L$ y$ o7 C7 `8 GDestination Mode IOREDTBLx[11] Logical Destination Address 0, Physical Mode IOREDTBLx[59:56] = APIC ID1, Logical Mode IOREDTBLx[63:56] = Set of processorsE 82093AA (IOAPIC)! s& n6 p) t. w/ F, P, i$ z
[10:8]Delivery Mode (DELMOD)—R/W.( y+ U, ^, d# V! o; A
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

: \& H9 D) g& D# b& W& T: R: TDelivery Modes only operate as intended when used in conjunction with a specific trigger Mode.: g* E2 v, A- }9 p! [; s
These restrictions are indicated in the following table for each Delivery Mode.
# d1 h3 q9 C0 W' D1 `Mode Description; t, }! K3 w: C, m# E3 ], c+ r* K
000
1 w, e% ^: Y7 W; ?# I" Y% p$ wFixed Deliver the signal on the INTR signal of all processor cores listed in the
& V, Z( B. D& j, t; D& W* ?) y' s' E6 |
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
! m) H& m$ O+ f% V0 y001( P, h1 Q9 ?+ E
Lowest
, a" v: J2 D& F5 f
Priority Deliver the signal on the INTR signal of the processor core that is4 ]( U% P6 Y: s  m! F! D& A* n
executing at the lowest priority among all the processors listed in the
: K2 |  n, x/ o7 i$ M7 I. Xspecified destination. Trigger Mode for "lowest priority". Delivery Mode  [. U9 m6 \4 P1 c
can be edge or level.
, B. `5 e/ ^* T+ M: w010
- X5 E. f3 Y( S: e7 eSMI System Management Interrupt. A delivery mode equal to SMI requires an
1 Y* k+ E" K3 X: Y" A; {/ ?
edge trigger mode. The vector information is ignored but must be
$ o. U$ e% g, G: V' \programmed to all zeroes for future compatibility.
1 g* N: \; w! E0115 S8 U6 u% {$ O% D# t
Reserved
8 F& H9 w5 o# Z+ a
100# z4 I  w. j. }! g$ Z1 Y7 J
NMI Deliver the signal on the NMI signal of all processor cores listed in the

+ h( G" \2 C- X8 e2 U& R- p& Hdestination. Vector information is ignored. NMI is treated as an edge% u% b. l9 k; Y" y; Z5 L; f2 {
triggered interrupt, even if it is programmed as a level triggered interrupt.9 D0 h3 }1 e6 K  }! d4 B
For proper operation, this redirection table entry must be programmed to1 s" z( H4 H" ]1 Q8 {
edge” triggered interrupt.# w$ l6 L3 F: p2 x7 F5 @/ S
101- j" S, m; Z5 O2 P; Y
INIT Deliver the signal to all processor cores listed in the destination by
% x: q. ?7 e; S6 T
asserting the INIT signal. All addressed local APICs will assume their' ~- p* o/ u5 \
INIT state. INIT is always treated as an edge triggered interrupt, even if3 |$ V$ y7 E9 ~# Y% O( [6 z
programmed otherwise. For proper operation, this redirection table entry
/ ?9 @, S. x1 b& o6 K$ Y' wmust be programmed to “edge” triggered interrupt.
3 l& k/ X, G) B0 U6 [# E" p( h110
; R6 B3 c) `$ }9 Y/ c" GReserved
1 D- ?( g- `# |; o
111' q0 \8 S$ \& L+ n5 s1 b6 n, {
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the

* i2 M" A% V/ n- J; Udestination as an interrupt that originated in an externally connected$ ^* S( Y1 {; t
(8259A-compatible) interrupt controller. The INTA cycle that corresponds
0 [7 q! A2 t8 s& F% J% h* Hto this ExtINT delivery is routed to the external controller that is expected
7 w- s5 `5 f5 _% w8 lto supply the vector. A Delivery Mode of "ExtINT"
7 G" h% R  z+ Mrequires an edge
$ j+ L) g& m, ~+ n5 P. Y
trigger mode.% P' A$ P$ `. {
[7:0] Interrupt Vector (INTVEC)—R/W:
5 q* r, y: w* hThe vector field is an 8 bit field containing the interrupt
% l* |" L% d4 }; Q% _3 n2 T3 n
vector for this interrupt. Vector values range from 10h to FEh.
4 V0 Z+ X/ D# k
& S/ G' p$ P: N! H& T
REFF:
, U" C4 K  |) o! \8 k0 B0 S, ?) Y& S- I8 r( D( X3 Z1 i
1.
6 `/ T2 `. X6 A1 f! i, z82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)! e/ L0 {, i* V) I5 H
2.( a  S( I2 N1 I
8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)& I) S1 P2 C, k
3.1 I5 @  M" I7 |2 r# s3 D
Undocumented PC0 h* w" T7 S3 V3 x0 O
4.
+ E1 p$ I; Y' [) Y' S" Z0 z8 M: p& }
2 _9 c- r5 n5 ]1 J8259A初始化编程3 p. i, v$ ?2 F4 G! i; E

8 x2 Q  r$ Z' z  N) I( hThat’s all!& _7 Z+ {4 h9 k: G$ f5 \5 N& O# Z
/ q- V5 A- w0 n2 h1 I
Peter4 g5 q6 D! R8 E; I

1 C! |" j! B1 o  I+ p4 ~2010/10/07
. r7 J+ }2 t( M3 U, r
" H9 @8 {+ u4 G[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ]
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

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

GMT+8, 2026-8-11 16:08 , Processed in 0.059694 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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