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

PIC 、APIC(IOAPIC LAPIC)

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

% m; n1 L8 x3 N, I" E) A1. Overview
! v% G9 m2 P* a& z/ b6 i, H2 h; ^! Q; c; i) }
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt ControllerAPIC是为了多核平台而设计的。它由两个部分组成IOAPICLAPIC,其中IOAPIC通常位于南桥中' O4 }+ ]/ L/ d( J9 R2 h
用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPULAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pendingnestingmasking,以及IOAPICLocal CPU的交互处理。
4 X3 H) O4 Q3 S) a9 l6 K/ }6 h; I" }7 v' ^1 n2 Z
3 M4 m3 u# D/ O) B  Z
2. PIC* R' ~: `1 [& _. |$ i

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

. w- H8 V! g; C! `4 ? PIC.jpg
/ K0 _* \' k/ `9 |5 I8 z2 n( x8 P" w* W- L. ~9 i  K

  ^) v1 a1 Q( T- Q, _' M为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code
1 m# @* a! p& A* |' Y2 z
5 W: K1 Q3 p, uMOV
' H! l  |! S! h5 @  `AL,00010001b8 X1 {7 G% b% W! L. Y5 [! I
;级联,边沿触发,需要写ICW4
) F3 E4 p# S: \( }6 [OUT/ T" m  @: R- b8 o
20H,AL' G# j% x; \/ m: s: S8 O
;ICW1/ v. a3 e* C) o# y' W7 V- v
MOV
* C8 c* ]2 c. ]3 s" D% N/ @2 ]# jAL,01000000B ;中断类型号40H3 x* I; |! E& }: ^  L
OUT8 @" {; V/ }) @$ E
21H,AL  Y$ `3 d, }3 J# w
;ICW2
, O- f1 U5 U* {& d4 n6 C; vMOV+ w- V% U6 F8 p$ Z8 S
AL,00000100B;主片的IR2引脚从片/ U4 _: o: _& d4 w2 w$ G, ^" U& r. u
OUT. X. p, O  J/ H# o
21H,AL7 H% {6 \$ i6 Q$ V" s/ B$ F
;ICW3
4 r: n: U$ D! X0 M* T* R' ~: BMOV* Z' d# U5 E1 m2 y" B
AL,00010001B;特殊完全嵌套,非缓冲,自动结束
  F3 |1 ?! P/ w1 ?1 |8 t8 sOUT
. c; y: q5 k# s4 L21H,AL2 B* Q9 P  a/ e; ^
;ICW4
' B, ^8 ?; j- N  D& ?! C4 i" y
* m1 B( a* o1 E) r! V3 G3. APIC
  d4 w, {; u) y9 C4 C* A0 u8 E! U) P. ^- \* c* U" 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
( i8 J" m  y; e6 `; o$ n. j每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
  J4 ]# v" o- ?4 m) `5 I3 L. R1 h4 I( C1 z7 W/ \5 _3 [1 X
7 N% ~! K" x& b+ u8 p0 q; z
IOAPIC.jpg
0 n& r3 ]2 e: d' {/ ^' i# C" q) O4 R) A$ r9 u) B
Programmable Redirection Table详细格式如下所示:
% R9 _& h' R- ]' Y. T7 v& P! c. ]2 S( I" M$ b
Bit Description:2 o) d. k+ ?6 Y4 d
[63:56] Destination Field—R/W.
7 K$ S4 L3 X5 h- pIf the Destination Mode of this entry is Physical Mode (bit 11=0), bits
- U1 A) R$ }- n' h
[59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field
9 P8 W/ W3 _$ u' Qpotentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
8 W1 G8 m+ P4 }9 m4 d- W3 c- J; u2 O3 \destination address.* u- }* K+ ]( \/ |! g! X% n
Destination Mode IOREDTBLx[11] Logical Destination Address
9 l4 \. j+ ^( G9 ]8 O: K$ {0, Physical Mode IOREDTBLx[59:56] = APIC ID
( Q3 C6 m0 O* a: ]1 ?: A1, Logical Mode IOREDTBLx[63:56] = Set of processors6 W+ w0 p: W6 Q/ a0 I' W
[55:17] Reserved.82093AA (IOAPIC) 0 d: t# |& ^1 b) R
[16]
0 l) _+ t! H3 \7 `4 J( [4 [& hInterrupt Mask—R/W.3 V: x! ~; X1 J! ?' e% [5 y& i
When this bit is 1, the interrupt signal is masked. Edge-sensitive

: l' t5 Z6 ]) N) d) B7 p1 @( Rinterrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
9 w: B( l0 t& E9 m3 @6 T% iLevel-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
% p- C7 }7 P4 h+ _, ?4 oside effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by& [' Y0 h5 W: n- @6 T9 }: J5 S
a local APIC has no effect on that interrupt. This behavior is identical to the case where the
4 [* [; O, M$ c: e- }device withdraws the interrupt before that interrupt is posted to the processor. It is software's
% n# G$ b" T4 K: Z: R0 B, d- g3 }responsibility to handle the case where the mask bit is set after the interrupt message has been0 T! N. O+ I. J7 U$ u
accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this0 g8 G! P& X9 `  \4 m1 C6 U9 n: P  I
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked6 M! a% {4 X; Z- v4 H
results in the delivery of the interrupt to the destination., V) L# X5 T) ]4 b; J7 t' N" m  r
[15] Trigger Mode—R/W.2 X1 p) J# t3 ^: T% ], h9 _+ f% ]
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.

& |& V% g+ z9 M7 b
[14] Remote IRR—RO.
' s" r. O: f4 n0 X2 \* ~! mThis 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.
% t0 U- u* p3 ~# U) M; E
[13] Interrupt Input Pin Polarity (INTPOL)—R/W.2 B, J8 {% f# ]( d
This bit specifies the polarity of the interrupt

5 h& M6 \( a" z9 \8 M! x7 L: }1 @signal. 0=High active, 1=Low active.
* _/ O6 m' z6 A* `; M
[12]) h+ d, o! C5 S- ?4 }
Delivery Status (DELIVS)—RO.
. \% `4 G( x5 n4 q7 EThe Delivery Status bit contains the current status of the

" v" s' k8 j4 }/ ~% P+ E4 pdelivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit
! E6 ]/ p% A/ dword) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
/ i. k' s' x" V, q/ jPending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
7 j( }( j$ W) c  Dbus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
8 b; {0 s0 e" Y9 G2 w" T
[11] Destination Mode (DESTMOD)—R/W.
8 |# x& f1 i2 p- a1 `! aThis field determines the interpretation of the

5 m8 p9 f5 N8 `: ^2 z- @- C$ RDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
7 B( A! }* {' F( WBits 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.0 ~8 o* J! B5 R5 F
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)* Y/ q9 t+ }9 A" }+ \
[10:8]Delivery Mode (DELMOD)—R/W.) |) j& o& K. V0 F; k& 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

' `! W" a' X( L2 `5 m+ qDelivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
' z# D* Z% I" [! B6 `2 r* lThese restrictions are indicated in the following table for each Delivery Mode.- s+ Y; r2 ~' O
Mode Description* M5 _7 Y* d4 W: G. W
000
7 C/ o9 ^6 q5 u% g6 R! ^Fixed Deliver the signal on the INTR signal of all processor cores listed in the
5 s1 j$ ?) b% {$ K8 N* T( U
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
, n# S; }, \% V3 Q8 d# D% ~001
) u. R3 m$ U( I+ v5 sLowest
4 {# u/ n( \9 E4 A: ^7 j
Priority Deliver the signal on the INTR signal of the processor core that is) G+ f+ s: V6 y7 ]
executing at the lowest priority among all the processors listed in the
3 p! g/ f% z! K1 x8 Yspecified destination. Trigger Mode for "lowest priority". Delivery Mode
5 P7 O$ E* k9 p0 b! s6 K; ccan be edge or level.* L9 y' V$ U# n
010. K9 p% r  t) @
SMI System Management Interrupt. A delivery mode equal to SMI requires an
( L# l5 g3 ?# t
edge trigger mode. The vector information is ignored but must be
$ A! G1 ]8 ~7 B, u. rprogrammed to all zeroes for future compatibility.1 [- s, [7 u( p" p
0118 W9 J5 O& s; P/ U, T; e3 O
Reserved

6 s+ s# b; h9 ^9 A* N' C  Q, E" A$ l3 T100
2 a5 F  Z0 F% ^NMI Deliver the signal on the NMI signal of all processor cores listed in the
+ e5 d) _( ^( @- b0 ~7 h
destination. Vector information is ignored. NMI is treated as an edge
8 r  \' |6 v4 O; A) l0 @* {triggered interrupt, even if it is programmed as a level triggered interrupt., k3 r/ T: f1 c+ w2 Q! m) f0 m
For proper operation, this redirection table entry must be programmed to' T0 q1 R+ c1 c( z; e
edge” triggered interrupt.
; b0 D) m' K3 U9 T101+ s, L& P8 v: D, o
INIT Deliver the signal to all processor cores listed in the destination by
* @; G- [0 V* @! H
asserting the INIT signal. All addressed local APICs will assume their
' T7 s4 ^5 K& J5 O( O; OINIT state. INIT is always treated as an edge triggered interrupt, even if, H% K9 D' H$ J5 ]9 B! A4 S
programmed otherwise. For proper operation, this redirection table entry% W/ h8 l9 v, J$ W8 K# z! T
must be programmed to “edge” triggered interrupt.7 r- K6 b2 o, Z; }# K$ O
110$ q& ^$ t# h5 g  @" W
Reserved

2 t0 L9 h7 q2 Y6 a" I111
/ W8 q4 n# O  l3 G2 tExtINT Deliver the signal to the INTR signal of all processor cores listed in the

9 r4 w1 y. f2 E- h6 Pdestination as an interrupt that originated in an externally connected2 f# t4 Z( }* \/ |5 r: b2 W
(8259A-compatible) interrupt controller. The INTA cycle that corresponds
: x6 l: i3 K0 J* V3 S- J3 {- hto this ExtINT delivery is routed to the external controller that is expected9 ?3 K" n( Y; M; m
to supply the vector. A Delivery Mode of "ExtINT"
$ m. W- C4 b$ g: [requires an edge
1 P! H3 d0 p/ v( @
trigger mode.
& b. x- q- C9 K
[7:0] Interrupt Vector (INTVEC)—R/W:
" J! @0 s- T2 D& a! ^: H  h3 `The vector field is an 8 bit field containing the interrupt

4 T) K- i0 F8 W- Qvector for this interrupt. Vector values range from 10h to FEh.
; W! X$ ?5 X$ M4 z8 B

7 Y4 t. a9 `7 Z7 S8 R/ LREFF:
3 B$ ^. [  ?* V, n4 r1 X6 g) O
& p4 _$ }3 k. v0 U1.
, Y- }3 }) U+ O, v5 P. h, o# A82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)
' q* Q+ B  k4 I) q6 x) f2 C2.
- {$ [+ H6 y6 E8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)! c  m& u/ Z# L2 Z# F, X
3.. G& f2 o+ {! g  A6 e* |
Undocumented PC
' G5 S5 X: B& b% y# r6 k4.
! R" b: X8 w' L. k  @, s/ B! g1 l7 \+ ]# n
8259A初始化编程9 L8 h. U2 K- |' K4 Z* W1 \' q
4 Q# R% [5 A  j) X1 |* z
That’s all!
6 p6 T" `9 s6 @; O8 ]8 S# q1 n5 q; b
Peter
3 _& L0 e  g% W! r* v" Q: r* }! N9 H
2010/10/07
( U4 L" W; [1 `7 Q) g
$ _1 @5 E! K+ [7 `5 ?[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ]
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

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

GMT+8, 2024-5-20 06:20 , Processed in 0.028623 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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