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

PIC 、APIC(IOAPIC LAPIC)

[复制链接]
发表于 2010-10-29 16:11:58 | 显示全部楼层 |阅读模式
PIC 、APIC(IOAPIC LAPIC)
2 |, a* c5 }: I, v
1. Overview+ B; _% S# l, K* I  N3 g
& u1 W  u/ U2 h3 e2 J7 ^
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中9 z2 l" B  B, k7 ~
用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。7 f' n% z- H8 j4 W7 `  Q  @

0 `8 h/ P7 I* K5 F% y4 u& B6 \$ F
2. PIC. w! T( r( d( V& B; q$ i

9 I  m0 ]2 q# W  G, o9 g基于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。" w7 T6 V. D" ~  Z% }% }
* O; H( z8 J5 U1 u% e9 u% C! D! L
PIC.jpg ! ^" n' Q9 o' N3 }

3 N3 W4 P. |: e$ N* B) J* E& f3 W, l" X$ \% L) J; y
为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:
' V$ [4 K9 ~& x! p) X& p* N
0 n) T) \7 a' N' u( D- T/ dMOV4 j( I! j5 j  `! V! F- f/ i5 j
AL,00010001b* j: A% j1 f& N( o  ?1 ]
;级联,边沿触发,需要写ICW4" g7 Y. l( F9 J& l
OUT" B3 O( k0 P$ L, W8 q) _
20H,AL6 J4 s2 E& Z- |  v9 l% u/ k+ ~4 c
;写ICW14 l" ]" p( e+ e3 }4 h1 f
MOV
/ k. u3 S% g& A, E! j* Q/ a. v; r# iAL,01000000B ;中断类型号40H: F( X% V0 {( b3 w5 @
OUT
- f' D- L$ ~8 _' j' K21H,AL( Q7 t2 ^) @+ T3 K
;写ICW2; z. e! H" B1 Y, }
MOV
3 D; a+ p1 E3 Q) hAL,00000100B;主片的IR2引脚从片
* l% _' E2 _9 c5 C5 I; v9 ~% BOUT
6 Z) D# M% F! U$ z21H,AL
$ h3 Z" e+ B$ A( J4 g;写ICW39 w, Q8 p4 X5 [" g. j. m2 J
MOV
9 P- I( V$ Z2 O- q+ e3 b$ ?5 xAL,00010001B;特殊完全嵌套,非缓冲,自动结束
0 w1 z, T+ B5 U% H! xOUT
6 r) U/ c6 R' m/ Z- K' ~+ Q% d21H,AL8 Z) K1 B+ j6 h- S
;写ICW4
+ {9 f" X7 {. u5 h5 K( X# r& d' H! u+ D1 X
3. APIC
' r# i& }7 k1 U4 E: S/ {; {( R- U9 V7 O
Intel 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,7 i' _3 H6 N( ^
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。8 W0 I* b+ j' W/ c" ^" F- @" F( u

' c2 d( c: K) K4 Q
, Y1 M. @* h8 x- P0 o IOAPIC.jpg
3 P, {# `$ w& H$ {2 Q2 z0 t" C0 v$ l; w2 e9 V
Programmable Redirection Table详细格式如下所示:
/ m% [6 ^1 _( {: y  ?7 ^, u6 {- Y+ Z" z" z( k1 `
Bit Description:
+ S2 r: j6 o( V  `* [0 z
[63:56] Destination Field—R/W.& k0 r  J3 `2 W0 S
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits
+ Q( j0 x2 ^7 C
[59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field
* `) p3 i: H9 W8 ?9 O" C3 T1 G6 kpotentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
/ q7 Y/ U7 @3 F) l9 a% [destination address.; K- y9 B, `% F2 B" S! j/ i
Destination Mode IOREDTBLx[11] Logical Destination Address( `, J! J( F$ z. ]8 X8 q( e" ~
0, Physical Mode IOREDTBLx[59:56] = APIC ID
# p9 p2 g8 N2 w/ _. I1, Logical Mode IOREDTBLx[63:56] = Set of processors8 F3 W3 F8 x& U% {# F& j6 V2 v* t
[55:17] Reserved.82093AA (IOAPIC) * ]- Q5 N4 Z9 q* ~
[16]/ I3 C; O+ r& W0 v) ~# b
Interrupt Mask—R/W., X: F) h# k4 r$ j
When this bit is 1, the interrupt signal is masked. Edge-sensitive

0 `4 [2 D4 ?* winterrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
9 d" g1 ~" Y! x0 aLevel-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no5 y+ A3 L4 B; p$ s! L
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by: Y2 z, d& e' x
a local APIC has no effect on that interrupt. This behavior is identical to the case where the# s# }2 E6 E- G( M& T) \! O
device withdraws the interrupt before that interrupt is posted to the processor. It is software's
) n: t7 \$ ~; ?/ Kresponsibility to handle the case where the mask bit is set after the interrupt message has been
% R0 T3 E# X$ _' `9 y) m9 uaccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this
% |0 _2 Y- F! m3 I$ M  T0 M' tbit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
. l2 s, E# X; D* p$ |, d* ]. Dresults in the delivery of the interrupt to the destination.4 L7 ?  J- P0 C" W
[15] Trigger Mode—R/W.! x& `, g2 U8 l# q3 f
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.

# ^6 |& F0 ?7 r9 @3 @
[14] Remote IRR—RO.  w% L4 L' ~* G3 L# k* z- V- E% ~/ D
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.

/ c4 Z! R5 o4 s. m
[13] Interrupt Input Pin Polarity (INTPOL)—R/W.
! _& f8 o9 ^0 u/ e6 g% O% Z( jThis bit specifies the polarity of the interrupt
; t  Y3 p* J0 v) \: n2 ?
signal. 0=High active, 1=Low active.
, h/ ~0 t+ Y2 O, `6 K/ M) w# H
[12]
& e; ]1 a. ^% aDelivery Status (DELIVS)—RO.
! |$ h  }  o$ ?' xThe Delivery Status bit contains the current status of the
4 |: y/ T, p# W& @8 }* l
delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit
8 Q! e$ S7 f3 {4 nword) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send( ]6 I% P$ Z5 ]9 m3 C
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
% R% y/ K; ~+ k. g, d, Kbus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).4 }8 P8 j  x9 n& i
[11] Destination Mode (DESTMOD)—R/W.
( Y7 b" {3 S& l- ^This field determines the interpretation of the

# x- E' k/ Z( Q  S% p. g/ wDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
- \" W) c9 q4 M7 }  h9 r7 [$ x) cBits 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.6 j- `; g$ [# a1 u- M4 @0 @$ I
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)0 @: U* j# N2 U7 a1 ~( V/ m
[10:8]Delivery Mode (DELMOD)—R/W.! |; A3 S, a8 X! @/ u
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
! l( L- J/ T) T$ E
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.0 [" E2 f" I; o  Z' U
These restrictions are indicated in the following table for each Delivery Mode.
) H! W! w6 K+ e7 Z3 h7 x1 F# Y; ]& tMode Description
8 B6 y: q# V2 B' S5 V000" Z2 k3 n$ A5 N8 }* ~
Fixed Deliver the signal on the INTR signal of all processor cores listed in the
$ Z! ]7 N5 {5 c/ u8 d; C/ {
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.8 ?1 G. W( U2 S$ M
001
! e; E( O1 h& T# a* m" h. GLowest

" p5 b! h8 S; I" R# n2 pPriority Deliver the signal on the INTR signal of the processor core that is
3 w! m1 F% |9 Nexecuting at the lowest priority among all the processors listed in the
6 h& T3 s( f2 M/ _  d0 gspecified destination. Trigger Mode for "lowest priority". Delivery Mode
; ?7 |5 v; u8 B5 D, u  Q/ e% H* U. H+ qcan be edge or level.
) t  \+ i2 |3 \* E- N4 U010
% U0 ~+ e0 a* g" w) d" DSMI System Management Interrupt. A delivery mode equal to SMI requires an

) c0 w( D. a# K- X/ fedge trigger mode. The vector information is ignored but must be
( x% R) X+ A; Sprogrammed to all zeroes for future compatibility.% C8 R' B1 [& U; c
011
4 ^  y% f* Q( W6 m3 HReserved
) W5 ^/ h8 V1 i- [- i3 J
100: Q, {2 }; Z( w$ C$ D
NMI Deliver the signal on the NMI signal of all processor cores listed in the
, p5 W! [! [1 n/ p: ?
destination. Vector information is ignored. NMI is treated as an edge4 [- l$ m* J, J, j
triggered interrupt, even if it is programmed as a level triggered interrupt.
; c: j) l8 }3 ~1 RFor proper operation, this redirection table entry must be programmed to7 T4 J1 E6 o3 o% Q
“edge” triggered interrupt.
; F0 q4 H. _3 `7 E* w101
& z2 C% w( I; I/ X5 BINIT Deliver the signal to all processor cores listed in the destination by
& G1 S+ _( \. D$ W& e& b3 g
asserting the INIT signal. All addressed local APICs will assume their
: q6 v7 |, K' g$ G! ^" O( a3 oINIT state. INIT is always treated as an edge triggered interrupt, even if
' l) F+ R; D1 G9 M2 oprogrammed otherwise. For proper operation, this redirection table entry. g1 [$ [6 ^7 b6 f1 G1 _  F
must be programmed to “edge” triggered interrupt.
' j# g3 C* `8 i110& j, a2 E- n$ m" M7 l7 U
Reserved

# O" o# L( P2 B0 v111
0 s  ^4 }5 Y- K5 O. K/ K+ g( U# rExtINT Deliver the signal to the INTR signal of all processor cores listed in the
' o" D7 g- W2 c! H3 x2 I  w6 [
destination as an interrupt that originated in an externally connected
* o' ^6 W$ m& e$ d(8259A-compatible) interrupt controller. The INTA cycle that corresponds: d4 f* K" H. z) {9 y8 k+ x: {$ f
to this ExtINT delivery is routed to the external controller that is expected- @. w5 h0 J- W! U# E
to supply the vector. A Delivery Mode of "ExtINT"; R- y$ j( @9 Z" |* F$ L# y
requires an edge

, `8 I' G9 v# |8 V9 mtrigger mode.
* A  \8 m2 f; O+ Z, k: J
[7:0] Interrupt Vector (INTVEC)—R/W:
; u( `# `) E) v# GThe vector field is an 8 bit field containing the interrupt
2 s8 h8 e5 M/ A2 Y- V! C3 t" F: z
vector for this interrupt. Vector values range from 10h to FEh.
7 ~$ [7 L9 D4 m0 u9 r! R0 G" y9 t

5 S# m  B/ E+ k5 l" KREFF:
$ D) {$ R3 q# S' C0 j( `* ?: Y* R8 b
1.  J) j$ V( E$ ^1 U: J( j  O
《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》* S" {9 M1 S7 ^% P
2.& w" L$ `8 X. y
《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》" Y1 O8 Z. S% p( z0 \9 Q
3.
$ j4 N5 F' U) S《Undocumented PC》' O9 i* X7 u( D1 L9 j
4.
; x# h) |+ i& p- V* Y; h' S' a6 v' B* w- [" ~8 s
8259A初始化编程
+ w( n: n/ E& Q' z7 G: x# N; K' p8 V
That’s all!
# A+ M2 g  C$ d' H
* T: A" U& e* q: ?" D+ k1 x& rPeter: Y6 E& ?6 ]8 u
! }5 Z3 V7 D5 h0 a& `3 c: e
2010/10/07
8 V  r- b* n) ?# W+ M8 v$ g- a# p' a6 N
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ]
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

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

GMT+8, 2026-12-2 20:33 , Processed in 0.098665 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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