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

PIC 、APIC(IOAPIC LAPIC)

[复制链接]
发表于 2010-10-29 16:11:58 | 显示全部楼层 |阅读模式
PIC APIC(IOAPIC LAPIC)
; B: J2 h- n, E- i
1. Overview% o2 ]9 }$ k- C9 a3 ^7 S! T8 ]% {

' J7 e5 n' F8 j5 E9 w4 jPIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt ControllerAPIC是为了多核平台而设计的。它由两个部分组成IOAPICLAPIC,其中IOAPIC通常位于南桥中: y0 G6 S) k' a0 J# m: o
用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPULAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pendingnestingmasking,以及IOAPICLocal CPU的交互处理。
7 q) G. q9 x: N* A+ ^4 [" B6 J* D  e- a+ p

' ?+ u. \3 B" x* H! X9 \* R2. PIC& `2 H& C4 G( o/ F* m% K7 f/ C4 W  ]

* a( r4 e8 r, k0 i( Z, A# M& q; y基于Intel 80x86PC使用两片8259A级联的方式组成了可以管理15级中断向量的一个中断系统,下图是它的一个连接示意图。两片8259A,一片为Master,另一片为Slaver。其中SlaverINT接到MasterIRQ2上。8259A有两种工作模式分别为编程和操作模式。BIOS初始化的时候会先通过IO port8259A进行编程配置,在此之后8259A就可以响应来自外部设备的中断请求了。MasterIO address0x20 0x21; SlaverIO address0xA0 0xA1# [+ H! H, A% g

6 R& {, W- d# a& F2 V. `! O PIC.jpg + Q2 j+ J2 n: f! \
* N" Q- H5 F6 m# X7 s2 B

- G% G1 U0 u* K. X) m为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code5 N9 x5 P  I  b9 g. n9 Z
9 ~; F$ A2 R, W9 C7 ?- e; O4 k" Q
MOV* k% Y% V5 [3 `" d
AL,00010001b7 f$ c9 d0 l9 n6 |$ \5 w
;级联,边沿触发,需要写ICW4% Q2 Q% ?  m/ v2 M7 c1 Y
OUT' c% C1 o' G  L
20H,AL% X4 }7 \, F: K' R: ?3 Z9 S/ L  Q
;ICW1) x0 Y! s8 w$ \" \3 J1 C, {
MOV1 D4 P  q9 o7 ?/ ^# u* M1 _
AL,01000000B ;中断类型号40H% H0 j: s+ G5 S% j3 Y' I, ], f
OUT
7 z+ a; q% R3 C. U  M1 H21H,AL
% L$ v6 ]; _! {) {) N;ICW2
( I# ^+ B, ~" P" {# O/ iMOV
5 v7 h6 v1 O0 Q) A* l& WAL,00000100B;主片的IR2引脚从片) L, E: ~7 z$ d: M: X
OUT: Y% C7 c  w: E8 L8 ^$ f
21H,AL5 i, @. T) O# d; {2 M
;ICW3
0 L3 ^8 z5 P/ V' T4 m3 vMOV
: \! q- g  S1 d9 v" V& g7 f8 tAL,00010001B;特殊完全嵌套,非缓冲,自动结束$ s- d$ n/ o3 _
OUT. y; h) Y& `( b  V5 i$ ~- T
21H,AL% _( D4 N, Y; [  d- o0 ?6 W
;ICW45 t& V( B6 r# @$ C+ k8 o! Y
9 p6 [% l- C8 j% w$ O! U0 t
3. APIC
/ m9 O+ a- b! O4 I$ d  B! y# e. S7 Z/ w8 G& H- Q) D6 t" c7 G/ 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
( d; }2 q: n8 e6 b; y: r每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。' z/ a& Q% o( g  Y# ^1 _# G
( t$ q9 {/ c7 v( b0 s) ^# j% F# l
. g1 z* K7 Z4 L$ v4 w
IOAPIC.jpg & i5 h+ H$ P  s; H- `

6 H" X/ L, e) G4 s, eProgrammable Redirection Table详细格式如下所示:* I" \3 P( f3 }2 S

6 E0 R+ K6 c0 V4 H5 n
Bit Description:. w. C7 ^* q. [) f* {5 ?
[63:56] Destination Field—R/W.+ |5 C3 z$ M+ f3 S6 C, \) v
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits
, j) U2 N8 H& J8 }/ a7 w& e
[59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field1 b& d0 N. B; B+ R& u. w
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
5 a' R0 n# m  c) |* zdestination address.
" i6 w" ~& z$ b$ m6 h! N9 p  Y# u8 Y- zDestination Mode IOREDTBLx[11] Logical Destination Address1 q* h) I1 ?& j: h
0, Physical Mode IOREDTBLx[59:56] = APIC ID( h5 H( D  r/ f$ |. R( ?/ L
1, Logical Mode IOREDTBLx[63:56] = Set of processors' A  x, i& n8 Z/ ]7 v0 q3 a; u9 x9 V
[55:17] Reserved.82093AA (IOAPIC) / O  x/ D% B+ ]8 N* k+ f2 S' ]0 I  d
[16]: h2 x) c: ^, S- @8 q: L
Interrupt Mask—R/W.
1 q* [& G  ?0 [- |; M* W9 {* QWhen this bit is 1, the interrupt signal is masked. Edge-sensitive
% Q* y# G7 @) k0 _
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).6 T# z8 k, v5 l
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no0 Q' V2 _5 Y6 e6 i
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by% h  y- k. x8 X, L
a local APIC has no effect on that interrupt. This behavior is identical to the case where the, V0 T/ C5 u/ m1 h: e: b8 U
device withdraws the interrupt before that interrupt is posted to the processor. It is software's2 I2 ?" w/ A. X/ L" l- |
responsibility to handle the case where the mask bit is set after the interrupt message has been
& ^3 ]9 m; s8 Y. Y$ iaccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this
2 e& @. u' u- ?8 G/ M' {bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked- g6 a- G: _/ M; N* Y
results in the delivery of the interrupt to the destination.9 Q& L7 ?$ S5 h" k0 N  F1 f
[15] Trigger Mode—R/W.. c9 `9 `! T/ X! p
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.

) K1 y6 s7 W; V4 L* P
[14] Remote IRR—RO.
9 U, h9 [/ d9 ~* Z! `+ K, m. p* T$ QThis 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.

# |( H# d* n& w: i& t* I5 I' l4 F
[13] Interrupt Input Pin Polarity (INTPOL)—R/W.
. l2 w, k) }+ WThis bit specifies the polarity of the interrupt
' X. ?' }( F+ K1 A+ x
signal. 0=High active, 1=Low active.! N& `4 D& |0 N- Y  U. Q: b
[12]
* p' E5 M4 c+ L; ODelivery Status (DELIVS)—RO.( ~) H5 F$ u$ m7 P0 b7 o. d
The Delivery Status bit contains the current status of the
0 u4 l" q- K+ h2 H+ x
delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit! I" V! t8 k' J. n* T2 d
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send* o) c) B3 j. `  o
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC. R" C9 s& |  K+ U
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
$ D/ p$ b$ y8 ^: S
[11] Destination Mode (DESTMOD)—R/W.
5 `5 Z" {' z( a* `9 j! {2 m0 v7 f- ~This field determines the interpretation of the

- v8 P2 J; a  T, H( NDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.* q$ q( g. C1 V2 P+ ~4 r
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.
4 C- K* p$ ]( \# v- 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)5 _7 g, h0 ~$ j- j4 J
[10:8]Delivery Mode (DELMOD)—R/W.. T2 ^/ r8 }5 K8 ^" i: S
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
( M% G0 n2 [& A/ b% P% e5 E
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
: X* }" o9 n! K- RThese restrictions are indicated in the following table for each Delivery Mode.# D7 |% j" f* l# R" u
Mode Description
9 K) J' s! L/ N8 `; x/ z000
; l( }  ^$ s7 l6 ]" N- SFixed Deliver the signal on the INTR signal of all processor cores listed in the

) ^' y  d/ D* s2 [2 ?destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.- q) ?3 A; W, r
001
7 P& ?% r& n. ~( v, rLowest
4 ~, ~; x( |& h; N' r/ _$ V* s
Priority Deliver the signal on the INTR signal of the processor core that is
7 `3 q: C2 j4 n# z2 u. m# sexecuting at the lowest priority among all the processors listed in the
9 A0 k, D% p6 `4 pspecified destination. Trigger Mode for "lowest priority". Delivery Mode
( h; D6 j$ _3 l( F+ q+ lcan be edge or level." U+ d( z- [7 l8 T' y3 [
0101 _  @1 f4 l8 d+ V9 s
SMI System Management Interrupt. A delivery mode equal to SMI requires an
/ t, n8 T, M9 q  v" J: b" }7 e, x
edge trigger mode. The vector information is ignored but must be
& j  J% J+ Z# _( ~4 kprogrammed to all zeroes for future compatibility.) c$ T' M/ U8 q0 Y
011
; q7 q2 j) p; d7 R9 OReserved

* N! J$ |9 c& m100
8 Y% W1 U9 n# h( g, R3 S1 _1 xNMI Deliver the signal on the NMI signal of all processor cores listed in the

4 D7 F* \- l) _7 K0 N) b# fdestination. Vector information is ignored. NMI is treated as an edge% ~4 A- @. I" e  [. C
triggered interrupt, even if it is programmed as a level triggered interrupt.7 e- n# Y; e9 I! E. w, c
For proper operation, this redirection table entry must be programmed to
: U: C+ B; {7 C7 F- b- ledge” triggered interrupt.
2 T; n9 r0 |# v- `' _# I; i  a1013 n+ r" l+ o* ]0 M2 ?2 e- @
INIT Deliver the signal to all processor cores listed in the destination by

) t" C: O! F& V( basserting the INIT signal. All addressed local APICs will assume their* w' B  v( ]3 p
INIT state. INIT is always treated as an edge triggered interrupt, even if% C( W/ p% s# t" T. N& f3 b" i
programmed otherwise. For proper operation, this redirection table entry* S" K, U0 \! Q+ e  O; T
must be programmed to “edge” triggered interrupt.& N& z. y; b7 z( R, ]8 z
110
# X" |3 z* _2 E9 v/ |! D2 ~! ]Reserved
' t) D: f* s0 f7 w. d( k+ A$ [
111
/ O. @0 J- x3 D7 F9 PExtINT Deliver the signal to the INTR signal of all processor cores listed in the

6 C. Z; S4 `0 R. o( kdestination as an interrupt that originated in an externally connected2 r+ K4 E  y# ^, q! V4 e; r
(8259A-compatible) interrupt controller. The INTA cycle that corresponds1 g+ C7 V2 L# V
to this ExtINT delivery is routed to the external controller that is expected
6 |* E7 P- y& O8 |to supply the vector. A Delivery Mode of "ExtINT", |6 Y4 ~- S5 ]. M/ j  `
requires an edge
6 M% G8 `7 \6 g$ _: j6 ~0 S) I
trigger mode.. }' g4 b; v5 U
[7:0] Interrupt Vector (INTVEC)—R/W:8 h& T1 }! M) _% k7 j9 _& H
The vector field is an 8 bit field containing the interrupt

( Z. X5 ]6 f8 j& M2 w$ Uvector for this interrupt. Vector values range from 10h to FEh.9 {9 G5 O$ ?) b7 }0 U5 S/ z
) e* s4 ]! o/ d; q7 {) V
REFF:
' I& W) p5 Z+ B
' h8 P. C  v# v( p4 J4 f. w1.- a8 ~( P2 j1 U. ?4 ~
82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)( G" S+ w/ f' N# E/ d/ E5 a: _
2.6 S4 C+ j( Y% H  x, D$ u' k
8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)
; l6 c, V# o7 k% {! ?- a3.2 \; G6 y9 G' A9 v$ z- o1 R1 g
Undocumented PC
% F( X: D# _! j- h: G; w4.
' r$ Z4 `3 V, l6 z4 _
; z* O. T3 h# O, I# i' o# p9 S5 k2 N8259A初始化编程
* x7 J# i$ k- Q* }- t: Q5 D+ l8 A4 s- W* @
That’s all!7 }, D3 Z2 Q) |+ z8 k

0 j+ L$ X+ P7 ^* g' vPeter
# R. }. N" H& J/ y) s& k% g! N0 ^3 P' s; f& N+ Y; g' Z
2010/10/07: K* R' w" |2 P* J# y1 H0 q, G+ w

& r7 d3 L" @( o% S# X[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ]
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

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

GMT+8, 2026-7-20 09:21 , Processed in 1.329294 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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