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

PIC 、APIC(IOAPIC LAPIC)

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

1 n: y) v- O4 }% O0 I+ U1. Overview
) O# q; n( }/ d7 g
3 L' i5 N" g- e! w1 N/ BPIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt ControllerAPIC是为了多核平台而设计的。它由两个部分组成IOAPICLAPIC,其中IOAPIC通常位于南桥中
& t8 C* S' K. e' d! E用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPULAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pendingnestingmasking,以及IOAPICLocal CPU的交互处理。
- Y8 F% D8 E# r" Z( j6 F  H% T2 G. e8 u1 j5 V

8 _* c0 s0 l4 h2 Y6 g& M2. PIC
; m  |: \7 l) d& e$ C3 g5 L2 I( h2 s
7 a9 p+ y9 h( U+ K- c基于Intel 80x86PC使用两片8259A级联的方式组成了可以管理15级中断向量的一个中断系统,下图是它的一个连接示意图。两片8259A,一片为Master,另一片为Slaver。其中SlaverINT接到MasterIRQ2上。8259A有两种工作模式分别为编程和操作模式。BIOS初始化的时候会先通过IO port8259A进行编程配置,在此之后8259A就可以响应来自外部设备的中断请求了。MasterIO address0x20 0x21; SlaverIO address0xA0 0xA1! U. b9 s4 W8 f. p8 E4 x3 i, }
4 y4 T8 ~3 Z; ^2 L# \- D8 q. a8 g
PIC.jpg ' `" ]1 y' P5 ~3 A
2 S- o" m# Q- o; K" @/ |  J
0 B0 p& W& {& ^) ^, p- T7 z
为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code
( a7 X- p+ l7 C
8 N3 _/ a& o% B. m# s5 KMOV
4 U( b1 E" R3 y& ~# e0 DAL,00010001b; ~4 C  P$ F2 G; s5 c; X
;级联,边沿触发,需要写ICW4+ N: `. T/ M( B  C# ]
OUT! a  U% S7 R! L6 `- Q
20H,AL
  n7 p( ?7 G3 v* p. t+ s+ c;ICW1- L& j4 a% T/ r
MOV% S" r: [6 g1 p
AL,01000000B ;中断类型号40H
' E+ j9 z) a- D1 bOUT: E! J! S' H: j9 @$ V* J  G
21H,AL1 M  n; U0 {) `
;ICW29 Z3 ~  K* |2 Y
MOV
9 B8 m- T! J8 p4 o4 cAL,00000100B;主片的IR2引脚从片: |8 h4 v2 A: ?9 ^) {; \
OUT
& b8 y0 j/ b) p* K21H,AL. M) q. |- O# Z" X9 I# p! @
;ICW3
+ l4 j+ E& Q8 p2 _1 cMOV5 U# e  Z9 n& l
AL,00010001B;特殊完全嵌套,非缓冲,自动结束. y. R& w8 y' m, g
OUT2 w* [" E9 O; t$ Z7 @) m
21H,AL; O5 [7 V( d* w- P( C# |" m" I
;ICW4
: S2 g* q/ D) _3 B' K) A( N1 x, K2 H3 X! v9 m& U% Z" p
3. APIC
% d$ v7 O2 b) g! w+ q: m( K+ A
8 p7 j8 w/ L1 I) b  i: w# qIntel 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' u7 g2 r, c) [1 v: _
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
, k3 a# D1 v4 w1 Z( S2 w3 G3 \+ d
( g# K  m8 W; H/ T$ f
; j- O3 E# H; h) f/ a2 Z IOAPIC.jpg
8 r! U; I3 L% e+ m- r; G6 R6 ]6 E
6 g+ d3 R6 K. b+ HProgrammable Redirection Table详细格式如下所示:
! z6 R2 k( s  W# k2 V2 P/ B& G, p0 `; r, x: D- Q9 o* \
Bit Description:
" x6 k: i" M: F& l
[63:56] Destination Field—R/W.' Q5 j; X4 e) ?' d8 |+ s' a9 d
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits

0 C9 J+ r/ U) v5 L/ z- ^
[59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field
' |( T. ]0 Y# j. i# Zpotentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical' A$ a# z2 r5 x9 Q4 C1 _* `9 i' P
destination address.+ x3 L) f- f" P7 I% l
Destination Mode IOREDTBLx[11] Logical Destination Address7 m2 [% O- Q) }) c7 q0 T8 o# \
0, Physical Mode IOREDTBLx[59:56] = APIC ID% V2 ]8 B$ i$ C: N9 a
1, Logical Mode IOREDTBLx[63:56] = Set of processors
' i, v! {9 s- n  u( d- t/ V
[55:17] Reserved.82093AA (IOAPIC) . S- E( E! T6 n( |5 r
[16]/ U4 f7 ?' q! C+ h0 \, C
Interrupt Mask—R/W.5 [- ^7 P! m" z
When this bit is 1, the interrupt signal is masked. Edge-sensitive

. v. _" U6 A% y+ B' minterrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
$ ^3 v! H3 w3 V; V+ v) RLevel-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no. r6 N! k1 d6 S
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by6 V( t0 ]; k+ h6 ]6 ]
a local APIC has no effect on that interrupt. This behavior is identical to the case where the, e; n3 t# f1 _' X/ ~
device withdraws the interrupt before that interrupt is posted to the processor. It is software's
/ k  _" l$ ]- i# R& presponsibility to handle the case where the mask bit is set after the interrupt message has been
/ b. s3 b  q9 m# l& Daccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this
( ~* G* [6 c' t. H& v4 Jbit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
' p" Z9 }! A7 n* cresults in the delivery of the interrupt to the destination.
. Q+ [8 m. U# N
[15] Trigger Mode—R/W.
9 O  G& J" |* V9 e' v5 X3 x# iThe trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.

" E2 q+ h& T6 h9 m) Z3 t
[14] Remote IRR—RO.
/ x4 ~8 X# j+ H; e" z5 g& 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 W0 K6 L/ o# g- a7 K- p& |; d
[13] Interrupt Input Pin Polarity (INTPOL)—R/W.
& w# r8 H" a. p3 g4 W; p3 V: qThis bit specifies the polarity of the interrupt
2 j  c! b+ C' _
signal. 0=High active, 1=Low active./ {' Y0 e% |. d; g- @9 e
[12]
- Q: t6 Q+ L8 `5 QDelivery Status (DELIVS)—RO." ^& c% \& w7 n
The Delivery Status bit contains the current status of the

  J2 D8 @8 N  t" p4 Kdelivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit
9 l0 L/ r3 Q& Rword) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send/ I* N  j( U' ?
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
) M' Z% c  b% D0 [bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).4 p2 U0 u1 o. u8 {6 q1 j! H
[11] Destination Mode (DESTMOD)—R/W.
, c: L7 [$ s* c/ iThis field determines the interpretation of the
. z5 q. U0 ^) G) X% z  J5 K
Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.4 A: z9 ]6 o! j2 s* C" V" q
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.
) U4 w0 S4 P9 G7 \4 b* WDestination Mode IOREDTBLx[11] Logical Destination Address 0, Physical Mode IOREDTBLx[59:56] = APIC ID1, Logical Mode IOREDTBLx[63:56] = Set of processorsE 82093AA (IOAPIC)9 z2 b4 I$ G( ?6 T
[10:8]Delivery Mode (DELMOD)—R/W.8 S( z) z. g0 \0 M0 L
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
5 Z. V& e; t, K( q3 Z# m4 e6 a
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
3 D+ B# [) V, VThese restrictions are indicated in the following table for each Delivery Mode.
, }( `) J0 u/ ?/ nMode Description
/ s3 R& E. q; x/ V" Y000
, V8 z5 W7 A3 s9 N" Q, C3 D# S* hFixed Deliver the signal on the INTR signal of all processor cores listed in the

0 s2 m6 H1 w3 O/ V! f: x$ odestination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
! |- v% t: _/ i, R001# m5 _# u5 w- N0 W
Lowest

: u, M5 i' K, p  E4 u9 pPriority Deliver the signal on the INTR signal of the processor core that is  q! F% _- e) N
executing at the lowest priority among all the processors listed in the
6 w% o' z2 [- C% q) ^/ ^# k# Rspecified destination. Trigger Mode for "lowest priority". Delivery Mode
- f7 X3 m' L. p. |/ \& c# Kcan be edge or level.6 d* J9 e/ l0 e, P0 {
010$ ^5 c0 U5 ^; N7 h, K
SMI System Management Interrupt. A delivery mode equal to SMI requires an
) e) ^, l5 O7 {
edge trigger mode. The vector information is ignored but must be; D. m- {# [( @. q$ c' L
programmed to all zeroes for future compatibility.
6 N" J2 m9 u! J6 l4 `! G+ ^011$ z- k& `0 F2 B
Reserved
+ Q; c# Q: ]' B. E6 B8 G7 m8 u1 B
1000 y% a; ~* F$ |6 f# V! R* c0 S
NMI Deliver the signal on the NMI signal of all processor cores listed in the

, q1 z1 ^+ d% r8 |' v/ x" jdestination. Vector information is ignored. NMI is treated as an edge
, @/ J+ H% H9 u* t. E6 L6 V1 qtriggered interrupt, even if it is programmed as a level triggered interrupt., [$ L9 }0 o/ [( M0 o- O7 g
For proper operation, this redirection table entry must be programmed to
/ O1 C+ g* `. M! Y- c2 H& ^edge” triggered interrupt.
; B3 M) \8 q  F& }( v$ f101! W4 o# I. z: j/ Z
INIT Deliver the signal to all processor cores listed in the destination by
! \  A* ^0 H. ?8 c" d" J
asserting the INIT signal. All addressed local APICs will assume their
' x9 K( H9 L8 i2 |3 pINIT state. INIT is always treated as an edge triggered interrupt, even if1 |7 Z& {! \) N7 }) i
programmed otherwise. For proper operation, this redirection table entry
7 z2 q6 X0 ~4 g: X# P' B8 \3 d. C% omust be programmed to “edge” triggered interrupt.
+ {, W% m& W3 J, n4 A- r110( I# `& d3 \' {
Reserved
/ N7 o0 V! G) z! P# @
111
0 X: a  E0 J+ YExtINT Deliver the signal to the INTR signal of all processor cores listed in the
. @) c* t1 S& O" K
destination as an interrupt that originated in an externally connected
* a" _: O) y# b% ^(8259A-compatible) interrupt controller. The INTA cycle that corresponds  F5 U" `7 s  b8 Q
to this ExtINT delivery is routed to the external controller that is expected
6 M6 b8 ^0 @0 J9 qto supply the vector. A Delivery Mode of "ExtINT"1 x6 Y9 y! T) c, X7 `3 W& x
requires an edge

4 v7 X1 }/ H! P# n4 G  n9 W2 O+ w% Otrigger mode.* K; N5 j9 @& Z# `# r6 t- _
[7:0] Interrupt Vector (INTVEC)—R/W:3 N! V# c/ ^" _  R( q/ a" ~
The vector field is an 8 bit field containing the interrupt

0 m8 O: @% i1 a7 {8 j! {$ jvector for this interrupt. Vector values range from 10h to FEh.
/ n3 o) K' ]9 e- J8 w+ {
8 D/ D1 i- C: `6 t3 l  M8 U' B
REFF:& H1 t, F* D/ _- T
" G/ E: n7 X; [3 f' d( Q3 v
1.
3 n# n& F' T" `  g82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)
5 `( I; H3 P( d- \' G2.
5 \5 ~8 b1 ~$ [, c8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)& f9 c% a" [6 R' _: O/ o
3.
' w% f% `$ J/ E2 ~Undocumented PC
4 D. k7 K& h  d+ o+ S7 Q: _4./ E+ x. Y) P" O9 I1 M" r7 x/ V" E

. }" A6 Z( Z- q% j8259A初始化编程! h/ \; {$ ]4 E0 O* C

" h4 v* P) L. V6 _. Q$ JThat’s all!
( Q4 F! t' g8 P" W! Y
2 z) ^* q, w) q8 `Peter$ F& i$ V. w* \7 G1 W8 Q; X6 @

' t2 Q- `5 u0 X; r1 r2 A8 g: m2010/10/07" F3 X; `& _1 k

/ e" S: G+ v4 C5 H; b9 l0 C[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ]
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

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

GMT+8, 2026-4-19 23:51 , Processed in 0.102600 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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