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

PIC 、APIC(IOAPIC LAPIC)

[复制链接]
发表于 2010-10-29 16:11:58 | 显示全部楼层 |阅读模式
PIC APIC(IOAPIC LAPIC)
7 A- j) Y5 j) P2 M5 i' v  L( d
1. Overview5 l) ~7 Q& S4 d  F
4 q% W8 z" g  Q5 p0 G  F# I
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt ControllerAPIC是为了多核平台而设计的。它由两个部分组成IOAPICLAPIC,其中IOAPIC通常位于南桥中
! ]1 S, v# i+ @; f6 \8 m用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPULAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pendingnestingmasking,以及IOAPICLocal CPU的交互处理。5 V$ Y: n9 k; k$ p- B5 Q; i
$ M7 C! l$ z3 U" U
; w4 H) K$ y4 D
2. PIC3 T$ L7 e- ~) G7 y" a+ U: E

9 i* c6 Y! y( H' L! V基于Intel 80x86PC使用两片8259A级联的方式组成了可以管理15级中断向量的一个中断系统,下图是它的一个连接示意图。两片8259A,一片为Master,另一片为Slaver。其中SlaverINT接到MasterIRQ2上。8259A有两种工作模式分别为编程和操作模式。BIOS初始化的时候会先通过IO port8259A进行编程配置,在此之后8259A就可以响应来自外部设备的中断请求了。MasterIO address0x20 0x21; SlaverIO address0xA0 0xA1
% m# K8 `- g  F' e9 z% d) N+ s6 r! Q" V
6 _, C- d5 f  ]; g$ c PIC.jpg
- p) H$ l( f! b( Z( |6 C
7 b$ ^% W; i% G+ Z1 g% N
/ Z6 Y- \: a) f为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code
  M/ `/ T# o/ Q7 U: T) \
' x) ?! [8 v7 V/ `1 H% u+ N8 PMOV
, N( p/ t% R7 N6 W- u' dAL,00010001b
: q; D& p' L5 b( Z" y0 u; b2 b;级联,边沿触发,需要写ICW4: p  M; e. U% j4 J
OUT1 g' c' @  n% t
20H,AL, b' z$ D" `9 D1 D6 a' R& f
;ICW1
, k. j( r, p( xMOV9 D$ s* _! r& ?
AL,01000000B ;中断类型号40H
1 H  [1 D& i" s; [/ z' n" U) J) POUT
- u  b6 G, o& y21H,AL9 j* g" ]( L& ~  y  v
;ICW2
) M. R: ~1 O; J3 t# [( AMOV7 W1 v$ y9 T+ y& @; c7 t
AL,00000100B;主片的IR2引脚从片- y$ S( J1 \: k8 @1 F
OUT% m2 o$ l% R; `
21H,AL
  a& f2 J' B3 D;ICW3
" R+ r3 h) Q/ A$ w: v; ?MOV
; p) e7 c7 n4 Z$ C  l& r3 U; z1 _AL,00010001B;特殊完全嵌套,非缓冲,自动结束
- f4 F3 H! c  u# Q! x5 t( UOUT
8 S4 |% E$ a/ T- J% J% f21H,AL
9 w. F% Z: ^7 S( c) M) L, J;ICW4
; x6 i& L2 y5 j, j$ V
- |; N" E; |2 h/ P# {& P) R" q3. APIC
0 c/ j3 H1 @% U; [+ [  ^/ S5 Z# N  c) B
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
0 a" Z' T3 I' j! K每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
7 v' P% x& q- w! ?. [0 j  j% h3 |, a0 `7 P0 u
) R' ?) K: V: e) i9 }
IOAPIC.jpg " G3 ?9 U# a- D: b, n; g2 I& X

9 e8 @4 h/ A$ t! c8 S8 F$ g! E+ N: ?Programmable Redirection Table详细格式如下所示:" x; Z/ N& A$ p1 ~0 [, a- F

/ j+ f! q+ H* ?
Bit Description:
1 e' Z- d8 D* D* e9 `3 l8 h
[63:56] Destination Field—R/W." {  F+ ^8 |5 ]$ a
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits
! [( }; Q" M  c5 B9 k) G& N9 B5 j
[59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field/ U% Q; V8 W5 K: Z2 V, C0 ]
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical4 O! R! T0 x7 O6 M+ G, l! h$ A# r
destination address.+ I9 Z/ {! N) q1 x# h4 n# ]
Destination Mode IOREDTBLx[11] Logical Destination Address
# ^  A0 w7 X  J+ P0, Physical Mode IOREDTBLx[59:56] = APIC ID
: w3 w8 I+ D# L1, Logical Mode IOREDTBLx[63:56] = Set of processors  [$ `, w7 o# i+ @* }$ E" ?
[55:17] Reserved.82093AA (IOAPIC) " {& n- G, U6 X
[16]+ w0 n- b7 w, j' t* R
Interrupt Mask—R/W.3 V/ p; X0 }8 V) x
When this bit is 1, the interrupt signal is masked. Edge-sensitive

& W8 G4 F3 |  ^) Y, Linterrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).3 {5 P. |) \- |! u
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no: Z* e  S- }* t, S+ N; a
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
: a% X4 E6 k- g! D, J& @! {$ ja local APIC has no effect on that interrupt. This behavior is identical to the case where the& ^: x5 ~! ~5 X& M0 F
device withdraws the interrupt before that interrupt is posted to the processor. It is software's0 A. t1 W7 i3 e+ z. ], ~
responsibility to handle the case where the mask bit is set after the interrupt message has been. t8 H& q# k* u
accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this
4 S5 u! r% r; i- v  N$ F) ?bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
4 k/ t( `/ {7 vresults in the delivery of the interrupt to the destination.
1 ]1 Z3 I- ]) \# A8 I7 K3 v- \
[15] Trigger Mode—R/W.
7 ]2 H' h3 m9 w8 d' }The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.

# N& z8 n" s  g! M
[14] Remote IRR—RO.7 q, \  }2 M7 U4 w, B
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.
* v3 D3 ?% T& H0 g7 [
[13] Interrupt Input Pin Polarity (INTPOL)—R/W.) l% e* E$ P8 I  r9 p
This bit specifies the polarity of the interrupt
5 e9 M5 @1 [# b- i( _; C. W, z
signal. 0=High active, 1=Low active.; `3 u  n. ]& \
[12]; S# e- {* @* g# L1 @' g8 x) n. V
Delivery Status (DELIVS)—RO.8 o2 E/ Y9 Z# L. X5 y
The Delivery Status bit contains the current status of the

! Z; v5 v4 g* vdelivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit8 w! U. K$ _, X4 M: W% Q
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
( d8 M3 {" h; ZPending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
9 p+ |! y* U8 Q' L% R* x" f# bbus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
# p* }2 U; j8 y8 _1 n8 t; p
[11] Destination Mode (DESTMOD)—R/W.
8 q* q0 |/ f  l* `: o! \2 K$ T4 t* y& PThis field determines the interpretation of the

1 D/ v- v% Z# Y: I$ Q' ^, FDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
  d2 A7 W0 D% h/ dBits 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.
5 n5 h1 f& s( Q8 i1 N( LDestination Mode IOREDTBLx[11] Logical Destination Address 0, Physical Mode IOREDTBLx[59:56] = APIC ID1, Logical Mode IOREDTBLx[63:56] = Set of processorsE 82093AA (IOAPIC)1 E- ?/ L1 d& D% M
[10:8]Delivery Mode (DELMOD)—R/W.
2 P" E* s1 S4 T% dThe 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
' {, d( t% `. [9 S- L
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
8 @. |& X  n9 ~These restrictions are indicated in the following table for each Delivery Mode.
: W, T8 n/ S( J8 k; G! Y2 |Mode Description+ ^, ^$ z  `2 S
0002 d3 f- L' |" g$ D$ F* S5 g
Fixed Deliver the signal on the INTR signal of all processor cores listed in the

% J( e3 F# ~: v6 p5 h. x7 z$ Vdestination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
2 t2 j. p. h  a* j% d001
: B* ?% F; J# f0 b) tLowest
) r8 R2 E8 r$ H" q( ?* o; ]" ]
Priority Deliver the signal on the INTR signal of the processor core that is
- }& r7 W1 v- q) q: xexecuting at the lowest priority among all the processors listed in the3 J4 Y, n4 R/ i
specified destination. Trigger Mode for "lowest priority". Delivery Mode, a1 x+ o. S7 t
can be edge or level.
+ r( Q+ B  _* @; S: G2 U( H2 b. q010
3 a2 h% A5 C- K7 v* h) J( q/ pSMI System Management Interrupt. A delivery mode equal to SMI requires an

5 X. a1 _, ?. K( L- ?edge trigger mode. The vector information is ignored but must be
, ^9 _) O' m( P9 }4 F% Z  }programmed to all zeroes for future compatibility.
8 E$ v$ |2 \# |- w3 l9 I011, C; J, [. c/ I4 D' [
Reserved
% B, _& g4 ^0 F8 R0 K) O6 r
1009 C3 o! F/ X& @1 y' h8 `2 ~+ Y
NMI Deliver the signal on the NMI signal of all processor cores listed in the
% f0 M5 h( A, p1 {5 k7 Y
destination. Vector information is ignored. NMI is treated as an edge# K" O) ~7 F/ D: |* Y
triggered interrupt, even if it is programmed as a level triggered interrupt.
5 q  o$ F9 E; A; h1 @2 f- Y1 kFor proper operation, this redirection table entry must be programmed to" ?; t4 W: w5 [, R6 j: J
edge” triggered interrupt." d1 b9 R- O& c/ [) t. R9 v
101
6 |' n" c. [1 W" Z; j" N; nINIT Deliver the signal to all processor cores listed in the destination by
) l  N4 L# J$ R) k& C7 v1 m' s
asserting the INIT signal. All addressed local APICs will assume their, F& G9 |& t' {
INIT state. INIT is always treated as an edge triggered interrupt, even if
( t9 T$ H: T+ a  `( h1 ~* Bprogrammed otherwise. For proper operation, this redirection table entry
* Z0 |0 @7 Q7 `8 s) \must be programmed to “edge” triggered interrupt.5 r( \# n  O' P" o/ S9 ?6 T% o% n: h
110: L, w2 D5 N% _1 n! o( F
Reserved
" u, b4 ]3 `, F! h' f9 m; c
111" _* {( d, q) E/ B
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the
2 U6 t" m) f6 J. ~5 B! l, f
destination as an interrupt that originated in an externally connected9 w+ K  F2 ~" P) _& w9 D7 u0 m0 E
(8259A-compatible) interrupt controller. The INTA cycle that corresponds3 O0 p6 v/ _) v5 D4 g
to this ExtINT delivery is routed to the external controller that is expected
6 x, l8 ^8 K7 N- h3 `$ jto supply the vector. A Delivery Mode of "ExtINT"/ B/ K9 y' u0 Q. ^7 f. C
requires an edge
) y+ ]! b  ^" c- i0 H0 Q
trigger mode.
/ P: }& V* T  i! @5 z( D5 @
[7:0] Interrupt Vector (INTVEC)—R/W:
# ?" m/ O% U' U4 |8 ?The vector field is an 8 bit field containing the interrupt
3 B- Q9 S8 D3 t& v
vector for this interrupt. Vector values range from 10h to FEh.
9 g% L9 g; y+ b/ B4 q
. S. T  ~9 _7 W" U* A$ p) ~' r' h1 S, c
REFF:: B" O; W, U( S; C4 [7 B' F
+ q/ p, q  B% S9 H2 {8 {/ a
1.
5 }0 k2 E9 V+ C, ^0 G8 g82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)
4 M$ H, @$ n# D0 x, E4 H- \% T2.* h5 `% c+ X4 x% ^- C3 p
8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)$ ^+ q+ p/ [7 T3 e" r
3.8 s- r8 l6 [0 J8 N0 q& d
Undocumented PC
/ ~9 E( I9 x2 C: j4.; ^6 X' |3 \! a3 J
* {! v) H- v) ~/ e
8259A初始化编程4 Y/ R0 t" N4 Q8 a9 h9 K7 h
/ i0 L; A. h/ ^# p% j
That’s all!
9 n& A$ g; D( b2 M$ D" R1 J+ ^
Peter9 k7 |2 a. ^% d4 q# C
' u8 Y% a- v( ]4 c: R9 ^% ]
2010/10/07
2 k( C; c! a: m5 D4 \: S' {9 c/ [5 m6 v! w; d. F8 J6 ^
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ]
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

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

GMT+8, 2026-2-1 04:20 , Processed in 0.066885 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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