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

PIC 、APIC(IOAPIC LAPIC)

[复制链接]
发表于 2010-10-29 16:11:58 | 显示全部楼层 |阅读模式
PIC 、APIC(IOAPIC LAPIC)
; l2 o) e% {+ u) ?. l2 M
1. Overview
$ K4 I% [4 N% _5 ]+ w. p2 {; b: z$ U. J+ v- j/ t) Y8 H7 n
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15个interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt Controller,APIC是为了多核平台而设计的。它由两个部分组成IOAPIC和LAPIC,其中IOAPIC通常位于南桥中7 E  T  s8 Y' F8 s3 C) V9 ~- s) ~. d
用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPU的LAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pending、nesting、masking,以及IOAPIC于Local CPU的交互处理。
7 b  m0 y* `& I# }2 A8 M5 D3 z& U$ q; ]( U. T9 k  [" j

; D; h7 O, l9 H1 }2. PIC
0 n- k# M' b  d, G* p
9 H( D8 R& l7 \* v3 b: |4 m# e基于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。
9 B  Z$ c; c% ]5 Q. |
3 @+ U7 v: n! U, n PIC.jpg
/ }& L) I+ P& k, |0 F# W( L! `0 I! @8 ^3 h

6 M6 p" P* d  _: x为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code:$ I: R" n% N: ]
6 {& [2 v& j& S5 X
MOV
* c2 T, h1 [; dAL,00010001b
  }$ e$ Q  N  ]5 `) G. s; Q+ O;级联,边沿触发,需要写ICW4& o5 X( L, a: |9 @- m% e2 w
OUT* _% q, w! ]8 f
20H,AL
0 I9 b1 n3 L9 g) n0 }. p( q  Y; e. S;写ICW1( W2 m7 |& [" `4 M- I/ @- D
MOV
2 q7 `% ?  D% V. X- P4 \2 y* hAL,01000000B ;中断类型号40H4 M8 B4 J2 X9 w2 s
OUT8 V0 X* q$ f( Z) R
21H,AL& p8 `/ r7 y; d- \1 d0 ~5 b
;写ICW22 M, M( x1 x4 x4 R" m1 n' |
MOV$ L# R: P, F# E. `) }! T
AL,00000100B;主片的IR2引脚从片0 v- f; W2 f. Z. m4 a. |6 l2 D
OUT% P5 z# `% q3 b7 k- ^% @) y  q
21H,AL
! q7 l! k1 [+ g& L. w' Z. H;写ICW3
; V' K) i2 ~& o! d* [  gMOV
8 _8 w% }" u& h# b& ?/ XAL,00010001B;特殊完全嵌套,非缓冲,自动结束- c% D( ?9 \# l* v- t! W
OUT( H1 ^& h5 U& z/ k) J- F& V& D- c( _" S
21H,AL9 _1 d# `. x6 a4 K/ l3 @" t) M
;写ICW44 a( w" S7 o' {; b/ n4 U. C5 W  x
; g- L- C2 `$ d( {5 E
3. APIC
' b+ F+ F! |: F. I* R8 k0 c$ d$ |4 K6 f" }2 l
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,
% v. f  Q; {  `7 I5 X每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。7 x# @9 e& ^" ~" C/ C4 Z: l

5 }# {4 R( j4 N  o  E
6 j5 O' q8 B0 g' l6 v1 E IOAPIC.jpg - c0 I( J  y& w% G9 K. n
; F2 U2 @" E$ F; N7 x, w& E9 a
Programmable Redirection Table详细格式如下所示:
9 A) I3 l3 `6 c1 G, x; x+ Z+ g: {  i0 j5 b) I
Bit Description:4 c$ F+ q! r4 P: c5 q  J; _0 |
[63:56] Destination Field—R/W.
, i* ?0 }2 ^1 t; y2 eIf the Destination Mode of this entry is Physical Mode (bit 11=0), bits

0 e: j, A6 {% u
[59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field
3 i5 \6 |9 A; x" x2 X: f- Npotentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical( Z% `- s! a  M! L6 M
destination address.' F; m; i& r" Z+ Y) K# n
Destination Mode IOREDTBLx[11] Logical Destination Address
: d' o* \0 w+ o) M# d0, Physical Mode IOREDTBLx[59:56] = APIC ID
* V1 g2 D) t6 b) B5 ^- v9 Y% N1, Logical Mode IOREDTBLx[63:56] = Set of processors: G. q- Y7 @+ i' d1 N. U5 e
[55:17] Reserved.82093AA (IOAPIC) ! e. t8 Z7 }4 M
[16]
) x* q; V* _! D2 K, a& ]. U( L: `Interrupt Mask—R/W.5 K; M" e5 g2 a7 E
When this bit is 1, the interrupt signal is masked. Edge-sensitive
( t; d+ Z1 L- K7 J* D6 x' m0 r
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).  s: b# O. ^6 W2 }) {9 K
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
6 I; @. `* J- Z' j9 S3 bside effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by1 m* T# X# L" z6 {
a local APIC has no effect on that interrupt. This behavior is identical to the case where the. ^5 J6 q# Z6 y7 l  k. }& i
device withdraws the interrupt before that interrupt is posted to the processor. It is software's6 C; c' q) O2 F, b# R
responsibility to handle the case where the mask bit is set after the interrupt message has been
3 q( v2 ^; q& L# P! n* xaccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this' {$ U1 p# O* m& ^5 P/ p' g
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
9 T; o( @+ @, x. N1 n/ nresults in the delivery of the interrupt to the destination.$ N6 ?( V2 U! j
[15] Trigger Mode—R/W.
- \; U- |- U1 K# l* _0 o- IThe trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.

7 ^5 n3 v5 k, m' ?+ L0 M* X
[14] Remote IRR—RO.0 u  g& Q. |- U$ @
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.
5 X# c8 w9 H* Y' Q% Y
[13] Interrupt Input Pin Polarity (INTPOL)—R/W.% s  O; b1 f/ X5 m# a3 a
This bit specifies the polarity of the interrupt

9 q; s7 U* |7 rsignal. 0=High active, 1=Low active.
5 V% y6 k" u& {+ L) B2 j% l
[12]9 L4 W! x* |1 t
Delivery Status (DELIVS)—RO.9 x1 K9 u9 @% C
The Delivery Status bit contains the current status of the
2 q5 P. [9 e+ A- L
delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit4 n  v, N7 T$ D$ `- G6 [+ K' q
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send+ Z, Z8 r& k1 I. [/ T2 |( T% V% G
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC- s( r  X, K+ E, F
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).! ~6 O& ^& I# l# \& L
[11] Destination Mode (DESTMOD)—R/W.
# C; ]3 G" b% {6 r; mThis field determines the interpretation of the
2 i- s/ _& @- K) Y+ v% E3 c
Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.# {! W- l& K, d$ C( |7 w
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.
3 Q  X+ h! `. j4 C6 {% p: jDestination 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, Q" }$ w3 J, ?2 Q  D+ B; a
[10:8]Delivery Mode (DELMOD)—R/W.6 t( ~2 D$ \$ V) }1 v& M4 d0 @
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
  d/ J3 b/ [+ T2 K! `3 }; S2 e3 Y
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
/ E  M$ o. P6 @These restrictions are indicated in the following table for each Delivery Mode.. K, R1 _( m# S% ?+ M5 o* u
Mode Description; f, Y; f; I3 n" E
000. _8 o# g6 O. d& D# s
Fixed Deliver the signal on the INTR signal of all processor cores listed in the
" o3 B' P& t# F( Q; ]" \/ \
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
, p1 |" N) [: X: V! {001
* Q* Q% B( L2 H8 [Lowest
$ V: L5 x+ e. @9 C; W
Priority Deliver the signal on the INTR signal of the processor core that is, U* L' y1 j' n4 i: X- s- A
executing at the lowest priority among all the processors listed in the
7 q8 n  S4 t) y5 g# J  cspecified destination. Trigger Mode for "lowest priority". Delivery Mode1 k& Q8 }8 H/ \  j& n
can be edge or level.. Y2 x0 S! O$ h+ j
010  m6 ^" ]  _& a. t0 |
SMI System Management Interrupt. A delivery mode equal to SMI requires an

" N3 c* C0 j! X3 g- |. F, _0 ?edge trigger mode. The vector information is ignored but must be
& a5 ~; U* V; {( z! Lprogrammed to all zeroes for future compatibility.
5 A4 s- ^# y8 v9 F0 R& l* F! X' L* x0118 `1 A9 v+ A9 P7 q- l  Z/ \
Reserved
: K! p0 d' b: D( c2 k3 m4 i
100
5 e5 |$ a' j1 ^$ A0 ^1 bNMI Deliver the signal on the NMI signal of all processor cores listed in the

" o5 @; G7 k0 M% tdestination. Vector information is ignored. NMI is treated as an edge
: Z2 x0 d( o8 X* H! ]  Wtriggered interrupt, even if it is programmed as a level triggered interrupt./ r! g: l& U5 i+ F
For proper operation, this redirection table entry must be programmed to6 x/ R; Y, G6 N8 F' z
“edge” triggered interrupt.5 y+ D) L: H# j, T+ V. i
101
9 L. y! g1 ^' ~  @INIT Deliver the signal to all processor cores listed in the destination by

' e# k4 D" T0 I  H$ e( dasserting the INIT signal. All addressed local APICs will assume their
  K: [3 S) D/ {- _' {' UINIT state. INIT is always treated as an edge triggered interrupt, even if
% S; |2 ~% e, D- uprogrammed otherwise. For proper operation, this redirection table entry
" m8 r/ j1 b. n/ V/ }' {must be programmed to “edge” triggered interrupt.
' k' P2 \  J% C) I1108 J6 n# x# X% j4 ^; u7 [
Reserved

4 H8 C5 E" u5 f( e) G7 g% G111- Y8 r; |# A1 t8 |
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the
9 z- ?; [. K3 b, x5 I
destination as an interrupt that originated in an externally connected: ?2 W4 I. s( W: R
(8259A-compatible) interrupt controller. The INTA cycle that corresponds
  B- b4 w: r) Z' M2 dto this ExtINT delivery is routed to the external controller that is expected# m- o: i7 d. c; k, }0 o' U8 C/ ~
to supply the vector. A Delivery Mode of "ExtINT"
2 r2 [" A! V5 P! d" `- I6 prequires an edge
* x4 N3 u# X& Q7 y3 B. Z2 W- i
trigger mode.
" `" I% l/ N8 S5 P! [6 \
[7:0] Interrupt Vector (INTVEC)—R/W:, L0 D3 b7 I. m$ u
The vector field is an 8 bit field containing the interrupt
1 q' a  L) v* S5 P& j) l
vector for this interrupt. Vector values range from 10h to FEh., s. R2 F" Z, g# d- Y

6 w: x0 d/ B' q; ~3 h7 O$ V+ j6 ^% eREFF:
" T. g5 o. j9 j* x4 F5 O! x7 S
1.
# r9 V9 J# Y. h. t! Z《82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)》
! N0 z$ F/ g8 c, N2.
, a6 T3 t& t, w, @- q7 R' ~《8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)》6 m0 w( P7 Y4 o2 t8 }* n+ w
3.& |+ _7 [. D6 q7 C! _) o
《Undocumented PC》
9 h/ t3 `, e7 B& h/ u4.& x& w( b# j( `& y$ i
2 a$ U8 U9 B. e
8259A初始化编程% T7 |2 n/ R& w: }+ s- h- g4 C: p
8 H' v  Y: [' l! K( R- m
That’s all!
0 N& d0 Q3 I: z$ \
9 {) ^2 f0 a9 Y$ a, @Peter- b: O3 p' O# G" K6 ?

; `6 @/ Y7 N+ Z  o2010/10/07
# w! W+ ^; z# o4 d# T, W; |; Y' A* L6 _& x: x
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ]
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

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

GMT+8, 2026-10-18 08:57 , Processed in 0.324252 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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