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

PIC 、APIC(IOAPIC LAPIC)

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

" k" v) p, c5 J0 r3 c& m) h1. Overview: \2 _+ T$ Z, I( S5 F

$ Y% X+ s- ?8 X! S' j' Q  C1 KPIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt ControllerAPIC是为了多核平台而设计的。它由两个部分组成IOAPICLAPIC,其中IOAPIC通常位于南桥中7 M  Y2 c. X6 l0 a5 B
用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPULAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pendingnestingmasking,以及IOAPICLocal CPU的交互处理。$ @( B& i  g5 r0 R2 I' O

/ w) b7 Z7 h5 L$ l2 z
" g# E! H3 k) g2 m3 {2 w2. PIC
, k6 ]: s/ e) ?0 H# ?) Q, @" k5 o3 B# d5 R
基于Intel 80x86PC使用两片8259A级联的方式组成了可以管理15级中断向量的一个中断系统,下图是它的一个连接示意图。两片8259A,一片为Master,另一片为Slaver。其中SlaverINT接到MasterIRQ2上。8259A有两种工作模式分别为编程和操作模式。BIOS初始化的时候会先通过IO port8259A进行编程配置,在此之后8259A就可以响应来自外部设备的中断请求了。MasterIO address0x20 0x21; SlaverIO address0xA0 0xA1
' s/ m+ ~6 _! M) y' X
( U6 Z  w' B! r8 g PIC.jpg ' g0 q6 A7 D( K
# E, [. B* H$ _( \" p6 c
0 U/ I# Q5 U# y( o% ~
为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code
- q: M& `( K- O8 v* ~" @; Z; u$ g
" z2 R) l6 p. @1 o: R3 BMOV
/ Y& Y  g/ C$ X6 bAL,00010001b2 h( h2 A/ `& [. a
;级联,边沿触发,需要写ICW4( G6 Q! B5 n7 k- V$ K8 j
OUT/ M+ s8 f( U6 J. b" Z- y" }- h
20H,AL
; P/ F& ]3 i# h9 A; q6 Z;ICW1& L/ R0 i. r; B# M
MOV. A2 _; W4 d' p5 X4 y0 Z: f% Y( E6 i! u
AL,01000000B ;中断类型号40H
1 H/ o5 a7 M8 v% L6 _* KOUT# ~; w% X9 M$ h: [$ V
21H,AL
( W, A9 g7 x/ t$ L7 C# T8 B;ICW2& I9 M" T, T5 o5 u
MOV9 l  J4 p( B# T/ k* I# v
AL,00000100B;主片的IR2引脚从片
" B' l$ ^6 D; ^: c& v0 o. M6 tOUT
; o1 |! F- [8 O9 z21H,AL
) c, V5 j! e' e  h/ n;ICW3  ^1 }! j9 a. y" Y
MOV
% S- u% U7 j2 X( M1 V9 X7 jAL,00010001B;特殊完全嵌套,非缓冲,自动结束
* e/ @" O- G6 ]+ o2 jOUT
8 r/ ~/ f% _- y* S21H,AL
$ M" N9 o3 A6 x! S' [;ICW4
5 d2 P: ~: [: ]) j1 i) B7 P, ?# D  l: o, c( h8 v3 L/ L. C
3. APIC
; D0 w  Y; N. s2 \) I; y, C# a; i' X- A
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* c! T: G: \* k9 a, z! E# ^
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
2 H2 p, D: M6 T5 ~& M: i1 @% W+ Z+ C3 w& U
, M, T3 @! w9 L$ s# q2 N$ i+ s' c% p2 F
IOAPIC.jpg
& x3 T6 Z% N% g+ ~: c- B2 ?3 H2 h  e  F4 _
# _. B7 f+ h8 GProgrammable Redirection Table详细格式如下所示:6 c1 ^% Z! o, j: H( K
7 x0 R$ ~3 p# A) |) ]+ Z; y
Bit Description:& \' Z8 B2 B. v$ p
[63:56] Destination Field—R/W.
, K' c, i) I! Y0 ]1 YIf the Destination Mode of this entry is Physical Mode (bit 11=0), bits

* l1 n* {0 d6 t# {. \$ t/ K
[59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field% X: `- G0 x. i  P  P4 [- d% v
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
$ r- r" U5 m8 F+ r& v! edestination address.# z; g9 r7 p7 ^+ U' O
Destination Mode IOREDTBLx[11] Logical Destination Address
' t2 M4 s4 c, L- {( u9 G0, Physical Mode IOREDTBLx[59:56] = APIC ID) j/ Q- L. D( X5 M2 k2 l6 D
1, Logical Mode IOREDTBLx[63:56] = Set of processors# |# P! S6 D/ G) u* l$ x
[55:17] Reserved.82093AA (IOAPIC)
' A% K3 _4 t5 m' N* N- K5 f
[16]
3 e4 v( F+ l4 l9 {# c" A' D8 O6 u6 xInterrupt Mask—R/W.
# Z; T6 g* l3 P$ iWhen this bit is 1, the interrupt signal is masked. Edge-sensitive

, s# t, h3 z9 y' zinterrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
4 a! h+ f8 p/ G8 |+ u( `: E9 LLevel-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no! l$ i1 q" \" [2 @2 ~# }4 j& K
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
5 |( P( U. H& C4 za local APIC has no effect on that interrupt. This behavior is identical to the case where the: a! h+ D$ d/ G8 E
device withdraws the interrupt before that interrupt is posted to the processor. It is software's
. x2 _3 R6 l! presponsibility to handle the case where the mask bit is set after the interrupt message has been& }+ ^8 `# ~8 [0 R2 g. _8 V) u
accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this
# p& G, G5 C, y0 ~bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
* z& w9 |0 a$ [. ]# l. H7 I* M2 ~results in the delivery of the interrupt to the destination.
: S& z- p& L3 ?/ p2 A
[15] Trigger Mode—R/W.0 S/ M" k! A; f# t9 ?5 E
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
- R3 M' S, u" E$ u/ f" k+ [9 F2 T
[14] Remote IRR—RO.  s5 ?2 j; K1 ]( T' }, N) _
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.
( s9 U% a- l2 a7 ]8 O- z
[13] Interrupt Input Pin Polarity (INTPOL)—R/W.
1 V0 _9 d/ L6 ^( e6 z6 U* dThis bit specifies the polarity of the interrupt

6 K4 l* k% x+ |) Fsignal. 0=High active, 1=Low active.$ v- j& S/ y4 o: r, _. M
[12]1 q, T0 k7 }/ S0 J& G( N; k
Delivery Status (DELIVS)—RO.
+ \. ]! s3 x! s/ F5 dThe Delivery Status bit contains the current status of the

4 d- h8 G' a0 a" B. `; X4 ddelivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit0 S: R9 T9 `2 ~
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send0 G2 Q+ I8 b4 a7 `; r
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
. P! n0 q; V( tbus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).8 M$ v7 l7 J' K. ^
[11] Destination Mode (DESTMOD)—R/W." L+ d2 W; m+ R7 u" C/ Y6 ^
This field determines the interpretation of the

/ o; [* _1 \( ~6 DDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
& j: T6 l8 U" W  LBits 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 z) ?) t# h" EDestination Mode IOREDTBLx[11] Logical Destination Address 0, Physical Mode IOREDTBLx[59:56] = APIC ID1, Logical Mode IOREDTBLx[63:56] = Set of processorsE 82093AA (IOAPIC)' J+ F% M! n' c% T
[10:8]Delivery Mode (DELMOD)—R/W.6 j3 R; b% `. C- T& A  f6 g' r/ R
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
4 h( M, ]9 A- s% ?, U; F
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
* y" Z. v9 j- t, VThese restrictions are indicated in the following table for each Delivery Mode.
4 h8 E# w" K5 _Mode Description- W5 U+ m1 A& M2 h6 M' x2 v
000
& }+ G! }" M/ U/ H: RFixed Deliver the signal on the INTR signal of all processor cores listed in the

' j- O( U& U0 \destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
, m. i) U+ [" U001
' Y$ }: y5 c9 h1 i& f" c2 b9 L6 c# h# zLowest
- }8 ]1 j  K% V/ h! [" U
Priority Deliver the signal on the INTR signal of the processor core that is
, \: e; E, N) ^2 }1 Bexecuting at the lowest priority among all the processors listed in the
* Q& y0 Z( k  @# n4 k4 Yspecified destination. Trigger Mode for "lowest priority". Delivery Mode4 d% L' K0 \" v8 ]+ U0 i
can be edge or level.
$ z& z9 W! k. r# D010! a9 {1 a$ A7 d3 E; J
SMI System Management Interrupt. A delivery mode equal to SMI requires an

- y8 S: p0 B5 f0 B% k9 vedge trigger mode. The vector information is ignored but must be
- J; d+ H& t- A* m6 Eprogrammed to all zeroes for future compatibility.2 E" V% I  T. n. I/ G+ f
011% ~: x% [- d# Q: e. M! l. S: q
Reserved
4 L; B) L8 Y4 k; |' P; w" ]
1003 K$ I4 K# {5 I) Q) i& m1 \
NMI Deliver the signal on the NMI signal of all processor cores listed in the
& v. ]8 w& a0 f/ p/ X
destination. Vector information is ignored. NMI is treated as an edge. {  I/ V3 J/ `
triggered interrupt, even if it is programmed as a level triggered interrupt.0 b. P  p# X; r$ Q) D
For proper operation, this redirection table entry must be programmed to  m5 m* n. E5 l! I
edge” triggered interrupt.
7 h: e( Z7 \9 e5 r& g: G101. @/ K5 s* \. v( n6 E
INIT Deliver the signal to all processor cores listed in the destination by
; k: A+ \% q8 K, W1 k0 i
asserting the INIT signal. All addressed local APICs will assume their3 J, J3 n. ]+ \% ^4 l7 h
INIT state. INIT is always treated as an edge triggered interrupt, even if
# D* O# F4 _* z" Z- F  w* Gprogrammed otherwise. For proper operation, this redirection table entry! y' }* u9 t) H  ?7 `) l
must be programmed to “edge” triggered interrupt.
, ^5 b) P. d' X. d110( {) O- ^* Q0 ]0 o3 }) ^" m9 u/ P* w
Reserved

2 t6 _; y$ ^1 p" j1 P0 M1115 t. s: }2 v3 J; o5 y
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the

3 `' v# G9 @! ?8 `3 l& e( pdestination as an interrupt that originated in an externally connected! H% F, _* B& \8 W5 m! a
(8259A-compatible) interrupt controller. The INTA cycle that corresponds+ J# Q2 E- E; P3 z( g
to this ExtINT delivery is routed to the external controller that is expected! J8 u( M$ s$ k7 C& R/ h1 Q
to supply the vector. A Delivery Mode of "ExtINT"! a1 _, M: _6 Y3 I! E+ z; w! z
requires an edge

! V4 L" [5 |4 C. Ptrigger mode.* n, y  O0 n, N7 P) {' h; {
[7:0] Interrupt Vector (INTVEC)—R/W:
- {% C9 b* q+ ]The vector field is an 8 bit field containing the interrupt

2 z' a, ~5 C0 `- b  X" y+ Avector for this interrupt. Vector values range from 10h to FEh.1 z. L( ?& w/ @5 T  J/ J

" p+ B6 K1 _  ]/ L9 p2 ^8 kREFF:" h; i4 S& u, ?
# p! W. v" D5 ~
1.
  j  R) z$ e. f0 O82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)1 a5 I. Y9 p+ e* s
2.
$ l3 f6 Z( y2 D3 Q3 }( }8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)
& Y0 ?3 m6 ~4 }  t; @) G/ j6 J4 O3.
% k( g/ A1 \9 W$ P$ F0 ]Undocumented PC
" U' b2 {2 w4 ~0 O. |  B4.) t$ ]& x7 ~* a2 z3 l- ?4 i+ Q( X

5 B$ t/ e! o( Q) B; Y8 B8259A初始化编程
) [# ?( E7 c# O( D6 ^- m2 J
  g. ]9 B2 O) |& @% Y5 Y/ s* [That’s all!
( s- T0 H0 U8 G) {7 Z# W& s# ~
2 m0 H9 p5 Y" b2 Y$ k7 yPeter& ~1 R- X9 N7 s5 V/ I7 l+ Z

6 [- \- F( t/ P  U" l2010/10/07; Y0 U: U' ~& s3 m% h2 \: Z
) P* o# s* d7 q9 K; }3 E
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ]
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

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

GMT+8, 2025-6-17 15:10 , Processed in 0.121998 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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