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

PIC 、APIC(IOAPIC LAPIC)

[复制链接]
发表于 2010-10-29 16:11:58 | 显示全部楼层 |阅读模式
PIC 、APIC(IOAPIC LAPIC)
" }2 I, {) f, W/ `
1. Overview
* c  X8 y: C- Z0 U
' \) a  t" P6 r/ \- GPIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中5 O- x) w$ k2 {, u& t. o( G
用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。
/ E, Y/ }7 G1 m6 x  G8 q
  ~3 I! r) D$ }
9 k- Y+ h- w6 v2 [3 K2. PIC
! a3 a+ Y# a* \* ?1 O4 X% b6 ~6 s/ H7 `  g' N5 d2 V4 g, d
基于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。: z9 X" v& ^4 _

; G! e# p5 g' @+ p, X PIC.jpg + z$ ~6 a, l4 @) y; V
, N- ?  G8 \& E

$ [8 t1 v4 w; B为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:2 w) Q) r3 C" }$ A% J
" n+ u) ^9 ^5 E* E4 S0 Z  K6 d
MOV
# C3 {# R. O: S  w% N4 ?AL,00010001b* ?& s6 S* U% q+ U4 P' o/ s- s
;级联,边沿触发,需要写ICW4
* b- Q6 Y  o, U9 V3 MOUT
! B6 p* D) P1 j: z7 s20H,AL
) B/ R! S: j: h;写ICW1
& n) r* `1 C" Z& f; f. z' D, _1 n' l2 r' TMOV" s9 c9 L! `; v& `! @
AL,01000000B ;中断类型号40H' ^! ]# g/ m! a( O- N+ |7 w
OUT
2 d- x5 F& E, R1 c) r4 \21H,AL* ?. |0 q& {( ^7 k" F& b& [
;写ICW2$ E2 j6 E9 @1 F$ f3 }
MOV. l3 p, X! N' m2 |' i
AL,00000100B;主片的IR2引脚从片+ i, v$ i6 V$ j2 `1 C+ d
OUT, r1 N! t" u+ p; M7 A8 g
21H,AL0 }. z+ F5 w2 g
;写ICW38 j- _( o. ]" t' y8 m
MOV
& P' T: C8 ~& @; D$ D0 }) eAL,00010001B;特殊完全嵌套,非缓冲,自动结束) }, y$ C6 v. E  W6 D
OUT5 {, v7 u4 O" K
21H,AL$ Q  w% N" N; x3 h, Y! r# ]
;写ICW4
9 J/ T& A# A) e6 y; H: G% }- b' o8 A6 L. W" u1 X) a0 x& J3 Q: S
3. APIC
' V( m6 e9 s$ i2 _4 u6 P8 U" [0 O4 I, Y# s7 n: b5 u0 W
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,9 j( y4 b; k! ^, {6 J0 B& m# g
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
$ `0 I+ x$ p5 H, s8 c( t) J/ z) u4 {. p+ h1 M/ o

$ s) i$ X8 t/ z' H IOAPIC.jpg # {, }) R: Q) d" P1 v% U
+ g# i: Y6 O) V- W
Programmable Redirection Table详细格式如下所示:9 _7 `/ ?3 K* Z- N0 ^3 s

9 n1 P9 S8 {" K% ]( w. p- n
Bit Description:$ n+ t6 F7 n, `  E2 q- E
[63:56] Destination Field—R/W./ d  w! H- W) W4 R  N: q
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits

2 [/ u& F7 V6 F, I" k. P! V
[59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field5 G7 ?. O9 Z$ r9 E! m
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical  \' A7 R. y, M7 q  v: T: ~9 y
destination address.4 H% J& h& R5 P/ ^5 r* J! o7 O
Destination Mode IOREDTBLx[11] Logical Destination Address2 G) {0 t# i3 J. a& z( G
0, Physical Mode IOREDTBLx[59:56] = APIC ID4 U" ?- d! Y, x9 x3 A
1, Logical Mode IOREDTBLx[63:56] = Set of processors
  {1 O% J8 a' Y4 p9 A# @
[55:17] Reserved.82093AA (IOAPIC) & `% \, M9 n( r7 _/ y. K) _
[16]: q: y1 G/ l/ G
Interrupt Mask—R/W.
6 n5 T4 \; x- @4 yWhen this bit is 1, the interrupt signal is masked. Edge-sensitive

1 b( T% n' Z/ s* @7 V9 a! L6 Ointerrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).( _1 O$ f- w0 l) [# I# p  l& G) Y  h
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no1 k; `( y) B& t5 u6 j* f2 b  T
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by- n8 m( I9 a( v, G) [, V! z0 ~
a local APIC has no effect on that interrupt. This behavior is identical to the case where the' D8 K1 N$ P3 {4 V# G
device withdraws the interrupt before that interrupt is posted to the processor. It is software's0 U6 r& u5 w7 F: h
responsibility to handle the case where the mask bit is set after the interrupt message has been2 x& z+ j" V' H6 ^+ m( W
accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this$ f) P, k4 [# o6 q
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked7 ^3 _% s: k+ j" b2 o  s
results in the delivery of the interrupt to the destination.
! z  T) p$ s! i  |: ?/ _
[15] Trigger Mode—R/W.
. O3 B' N% [: ?# U( Q" I+ a+ F& Q1 lThe trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
' J: R4 Y* g& p; w+ z$ c+ Q
[14] Remote IRR—RO.
6 h$ R# y- @( \- N# {1 t9 Q+ J* 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.
: W# Z- f; v3 D/ ~; J4 R3 A+ p% K
[13] Interrupt Input Pin Polarity (INTPOL)—R/W.) O2 e. c+ o3 N# X  q5 |
This bit specifies the polarity of the interrupt

7 E6 t  Z' {' I: D. H( E7 _/ T4 vsignal. 0=High active, 1=Low active.
6 E8 b+ Z2 o3 N, Y& c5 p
[12]0 c3 I. i% W0 ]) W
Delivery Status (DELIVS)—RO.6 w5 L% v' R1 A: A1 I
The Delivery Status bit contains the current status of the
* l2 o2 Q) ~: C
delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit* O% k: R5 C) A* w# D- Z, q
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
$ q+ [4 n! @5 q: {# ~; ]2 y- HPending (the interrupt has been injected but its delivery is temporarily held up due to the APIC- O" [) Y* b! o& Q
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
4 ^, V6 H9 o: h. |. j% i
[11] Destination Mode (DESTMOD)—R/W.
2 V" g7 W' L0 M3 x' c# U) Y. PThis field determines the interpretation of the
7 V! i8 ^3 y; r4 n! F; L" m7 U1 Q
Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
9 a3 T! v, _& }7 \. ^2 `2 H+ VBits 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% C; R! a8 \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 g1 @) p8 @2 a8 _) n
[10:8]Delivery Mode (DELMOD)—R/W./ ?( _3 }* ~- n% N) q- p& ~
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
' }& }& G9 [9 k, }
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
" o1 _/ L% w9 }These restrictions are indicated in the following table for each Delivery Mode.. @3 v) d0 ^. Z4 C$ g* X8 w1 S+ z, j
Mode Description$ x8 `1 j% Q( n- |
000
0 r+ S) A5 N: I8 z1 D9 {. ^Fixed Deliver the signal on the INTR signal of all processor cores listed in the
% p; ]( u- U6 d2 }6 X3 w1 P' R
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
+ b( D. n# a5 g001# |! X0 U# L8 R2 e
Lowest

* c2 Q6 j% a1 s" S1 H" b6 ~# LPriority Deliver the signal on the INTR signal of the processor core that is
  y8 n' Q/ B7 I4 G. d" b# |0 R4 cexecuting at the lowest priority among all the processors listed in the' u8 j6 ]/ c! U' ?( e3 e* e  a: X
specified destination. Trigger Mode for "lowest priority". Delivery Mode
$ Q  O5 S- C2 D, o0 Qcan be edge or level.
3 G$ \. |. ^* ^% p, H7 @010
: a! b0 O) j- C9 H( s- j  {SMI System Management Interrupt. A delivery mode equal to SMI requires an
7 }4 q/ r4 t9 @) D+ i0 T
edge trigger mode. The vector information is ignored but must be
" l0 [: Q: [4 g. }0 J5 iprogrammed to all zeroes for future compatibility.
6 G- \  p. a+ q& {011
; c' i4 m4 S$ h; q, p  uReserved
* R& R4 d6 {. k  g/ N* F
1003 g& ^& e0 r# m1 b' l: k4 L
NMI Deliver the signal on the NMI signal of all processor cores listed in the
7 R7 M- B3 U0 e/ a; B
destination. Vector information is ignored. NMI is treated as an edge
+ _! p: q+ s) v% l' M/ btriggered interrupt, even if it is programmed as a level triggered interrupt.9 S( v! b* \, T2 c
For proper operation, this redirection table entry must be programmed to
% J' _  \. @9 O) B4 s9 u2 e+ Y“edge” triggered interrupt.
0 {3 B! H; h& c+ f' c2 J8 y5 M8 o101! Q( x7 h. ~% r  {- Q1 m
INIT Deliver the signal to all processor cores listed in the destination by

3 I. j2 M1 {3 f. S: O" \$ ~& lasserting the INIT signal. All addressed local APICs will assume their# g- g" b/ O$ s' k" D
INIT state. INIT is always treated as an edge triggered interrupt, even if5 M" c% l# [1 N5 m
programmed otherwise. For proper operation, this redirection table entry
8 N3 Q7 t) z5 u1 I6 Z- W8 ~1 _must be programmed to “edge” triggered interrupt.
9 i" {$ S' [# E7 Z4 b1100 W* B$ L( K6 O+ c; U: L. ^( e) j: V
Reserved

+ e6 F1 p! h4 |& c4 d) j+ `6 D7 c3 q111
, C. s' {* m4 X( |/ Q# L7 nExtINT Deliver the signal to the INTR signal of all processor cores listed in the

- K$ ~0 \) [; n+ b; ~: T5 Q3 mdestination as an interrupt that originated in an externally connected2 d4 y8 e; j" C
(8259A-compatible) interrupt controller. The INTA cycle that corresponds
. I+ {( J8 F/ c, w6 n% _to this ExtINT delivery is routed to the external controller that is expected: M2 F9 W3 z6 W7 W  m! t
to supply the vector. A Delivery Mode of "ExtINT"% E" c9 n6 D$ r9 H0 R
requires an edge
- ^0 M, f  {0 u/ V4 i# y! p2 Q. \2 D
trigger mode.! F# \) ?- Z& p* a6 {% Y2 Y9 h3 ]
[7:0] Interrupt Vector (INTVEC)—R/W:
6 P* D6 s" `) ?" H6 [. ^, dThe vector field is an 8 bit field containing the interrupt
  h7 g% X! ]6 v5 M2 X' \9 I
vector for this interrupt. Vector values range from 10h to FEh.
/ T4 V% T! q8 x
' I0 D7 U4 H8 }  t# _$ }
REFF:0 C8 u8 U" f9 l+ X8 ~" g9 ]
5 L7 _1 t6 R3 S. P  O( n
1.' B3 K" y# v7 v" |; I
《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》
  T: |$ s; W/ S/ U( I% V; p2.5 Q0 n% Q) Z7 m1 V" }
《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》9 Q. n' H5 r+ Z% a  Y) w
3.
: J5 E) L! Y$ K1 k" e; V6 I《Undocumented PC》( f1 w3 S  j5 c; p
4.0 S8 [' Q, R' |; u
1 t0 p% ?4 @0 o  I
8259A初始化编程
& t% H- @! {& o# L0 y
0 ^  A/ I, q/ Q3 h6 oThat’s all!
" V7 i# [0 K# @0 _" e; V  `5 m$ ]! Z: M
Peter
4 o( I* h4 A8 e* Z( u8 R  }. c
: D4 N& v1 @# Q# M; G2010/10/075 N! X: I, i* m

5 J) c2 b, e- S& R) Q! [. v3 V[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ]
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

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

GMT+8, 2026-10-20 10:20 , Processed in 1.896349 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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