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

PIC 、APIC(IOAPIC LAPIC)

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

+ o! a  [! P; _! ^' {2 Y/ ]+ ]1. Overview
7 Y2 r" Y+ K: s+ B( g0 N! F: h, W/ }: p: F( C
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt ControllerAPIC是为了多核平台而设计的。它由两个部分组成IOAPICLAPIC,其中IOAPIC通常位于南桥中
( F" ?5 u  z( {, j: |  H% I用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPULAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pendingnestingmasking,以及IOAPICLocal CPU的交互处理。
4 S; w7 t& G/ O9 }0 {9 B( K, P. x. x% a" S9 G$ T6 s1 ^6 H

2 j6 U* i3 K3 G2. PIC! V0 d! Y  `9 d5 e
5 t0 d5 X$ ]6 ~% E2 b  U  o# e" [
基于Intel 80x86PC使用两片8259A级联的方式组成了可以管理15级中断向量的一个中断系统,下图是它的一个连接示意图。两片8259A,一片为Master,另一片为Slaver。其中SlaverINT接到MasterIRQ2上。8259A有两种工作模式分别为编程和操作模式。BIOS初始化的时候会先通过IO port8259A进行编程配置,在此之后8259A就可以响应来自外部设备的中断请求了。MasterIO address0x20 0x21; SlaverIO address0xA0 0xA1' ~9 E  c, T* p9 m

5 i8 U) |0 j4 e7 x  U5 e PIC.jpg " K1 r- ~* J4 k" ~6 z6 q
9 b9 h" c: u" m3 z; B5 J

; ~8 Y' Z) R5 b为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code
) ^' F$ `! v, y. ]0 v+ ?5 ]: |) {0 |) d% D3 w) g. |8 l
MOV# p/ q; Z  }# y0 L; W, a
AL,00010001b
  z. b$ g/ @" r& R: _  E9 z' ];级联,边沿触发,需要写ICW4( g( O7 c- n# f5 u3 p
OUT
2 o$ v- _9 t  ?: O20H,AL
6 K' f5 {" }7 a( o5 k, a7 K;ICW1. Z1 ?. B4 h# J6 T! D
MOV
4 h9 j  _  T& O5 C. q# `* _8 u" hAL,01000000B ;中断类型号40H
8 L3 l5 u7 f$ z3 cOUT
% s1 e4 u( |/ [21H,AL
; G" N4 C: k( t0 B* O;ICW2
" E; g8 r6 W4 o; a5 W1 G! Q+ k  dMOV
9 z0 S3 ]. W5 p$ SAL,00000100B;主片的IR2引脚从片
6 r3 d2 v; j. F1 B5 H, SOUT
& |& A% R; z0 k/ s% p; _3 c/ A21H,AL1 U7 ]! H8 e- {
;ICW3, B8 P% s. Y/ m  B2 F5 _  ]
MOV7 W/ y8 Z1 m# X
AL,00010001B;特殊完全嵌套,非缓冲,自动结束5 A) j; C" K1 }  r) P9 s& }9 u
OUT
6 f; t7 j) |1 V& E21H,AL
+ i8 ~* B2 D. ~' B; y( Y$ q. Z0 D. h;ICW4  |& H/ P5 F& s; |

) `# {' _5 W1 D+ y" g0 `3. APIC
; m' s* y. i* [" q
# x& W# L$ A+ VIntel 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( _: m5 r2 \: F* }8 v
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
+ J- Z- E1 V' A* c( E+ Z& [
' V1 D# V8 E1 i  V& _+ H
- @0 P# P' |9 @- a. a IOAPIC.jpg
& u( U+ F- e1 H4 x0 ]3 T
" C9 d( ~( S" Y  m: u! i/ y& L# P- bProgrammable Redirection Table详细格式如下所示:
( @# u7 b  s# h1 u+ y6 V
" ]- W7 ]/ ]) J9 Q7 I
Bit Description:
2 p3 j0 h4 X2 H3 g' `. {: S1 g
[63:56] Destination Field—R/W.1 O9 ~3 V( a7 x
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits
: }6 R2 ?" H0 v( ?" y" k' |
[59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field
- \; h: v# D& d0 d' Gpotentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical2 L" m  F3 D. L1 u' g
destination address.
8 C/ d3 K9 [0 l; QDestination Mode IOREDTBLx[11] Logical Destination Address
" s2 n. a2 F9 F+ ~; Y0, Physical Mode IOREDTBLx[59:56] = APIC ID
' W8 t  ]. \- @/ `1 w1, Logical Mode IOREDTBLx[63:56] = Set of processors. R, b# O, r* Q; i
[55:17] Reserved.82093AA (IOAPIC)
* j, @, O& o+ p8 T6 r
[16]
0 g- ~: w8 D% ?" m1 j* Z2 ~! p$ iInterrupt Mask—R/W.
( @: W) v* R2 ]( TWhen this bit is 1, the interrupt signal is masked. Edge-sensitive
7 T- D6 e6 ^3 ]1 T# o+ w
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).# P$ Y* q2 q/ }% B# j3 _+ u
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
* }: a+ g3 D" I, L1 gside effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
- c% i* K- r& z& g0 wa local APIC has no effect on that interrupt. This behavior is identical to the case where the/ ^' S/ }* f6 }+ t& G
device withdraws the interrupt before that interrupt is posted to the processor. It is software's
' O  w7 l1 P% }- l4 I: e  Qresponsibility to handle the case where the mask bit is set after the interrupt message has been
' S6 E0 u" q1 f. c# daccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this8 X$ {9 b4 @( Z: V
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
  Z) ]- O6 }  H7 w! m/ Q: presults in the delivery of the interrupt to the destination.
! X1 |0 }) k& R! T2 E0 \+ ~
[15] Trigger Mode—R/W.
; \8 I) X, O' e: G, \& qThe trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
. p8 f5 m6 C$ T4 Y
[14] Remote IRR—RO.! X+ @5 p$ M; k9 G. U1 r
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.

0 k* ^5 `. U$ J6 ]
[13] Interrupt Input Pin Polarity (INTPOL)—R/W.! f* h& L/ x% l
This bit specifies the polarity of the interrupt
( m: ?- e1 T9 |; ]; Y- n
signal. 0=High active, 1=Low active.1 X# k4 L" `- i/ E' o4 v
[12]
# I# @: X' C; j; |8 R. v7 d0 wDelivery Status (DELIVS)—RO.( ~9 t$ x( Q: B4 }; Q$ t, O
The Delivery Status bit contains the current status of the

/ M5 t8 c' Q8 D0 \4 u0 b4 k: Kdelivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit2 _, D! q& c# Y
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send7 z* `' p2 Q, h& Z' I; W2 ]. t
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
. P) n+ R6 y' @5 |6 P/ Kbus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).( j' }! s' \: N9 n0 ]5 N. `- w
[11] Destination Mode (DESTMOD)—R/W.
/ O# }( l  e* T$ c& U  AThis field determines the interpretation of the

" f5 t- n% z& i: \% BDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
. `' b4 h& N% H) _2 c: uBits 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.. ]# m4 y: l9 A) O
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)
( L( e9 j1 @/ ^3 \
[10:8]Delivery Mode (DELMOD)—R/W.
( Y7 f% N. U: UThe 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
! g$ j0 M+ C- o7 Q5 V
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
6 U5 R8 @" D. ^& s/ B) a* EThese restrictions are indicated in the following table for each Delivery Mode.. f7 s( u( p6 b
Mode Description& `  s* {, l1 |
000% S  A' F5 ]7 X0 a! L; L2 `, O" r
Fixed Deliver the signal on the INTR signal of all processor cores listed in the
; s" o7 O7 c1 f( _. l( ~4 Y  a* x
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
- e7 A8 x4 b/ }* A7 g& U001) i8 y& [+ T) Q
Lowest

4 N! {( F: r; s2 w; v* y0 u# ?Priority Deliver the signal on the INTR signal of the processor core that is
9 k! M. a: m8 `9 ?3 ]* B2 mexecuting at the lowest priority among all the processors listed in the
# L& b: Y/ X8 a, S% p0 ^5 k) Kspecified destination. Trigger Mode for "lowest priority". Delivery Mode- p0 R; m$ f4 A* u/ t8 I
can be edge or level.$ e# G3 t  B1 \& k
010
) J8 F  K' B$ T$ P; T6 pSMI System Management Interrupt. A delivery mode equal to SMI requires an
. e3 V- a3 {+ A- D9 Q8 V; ]1 `
edge trigger mode. The vector information is ignored but must be# q  f, ~# V- j, J
programmed to all zeroes for future compatibility.7 `3 X4 s, @; s
011
7 A& w3 a( B! |! W& Z2 E" @9 {Reserved
5 j! G$ u( F5 Y/ U  p
100/ N4 g" }, u4 S! q
NMI Deliver the signal on the NMI signal of all processor cores listed in the
, W$ X8 B6 e8 M' j* o" W" f
destination. Vector information is ignored. NMI is treated as an edge* ~* N3 o+ v6 x
triggered interrupt, even if it is programmed as a level triggered interrupt.
1 g8 d% F' @, h2 V, T1 h5 M, w$ s* qFor proper operation, this redirection table entry must be programmed to( L- a" X# `* p- e2 {
edge” triggered interrupt.
; P1 c9 ?$ \8 t; K, u# x; X101
, r4 p! p3 p, j5 ^# |INIT Deliver the signal to all processor cores listed in the destination by
' W8 P* |) Q8 ]  p
asserting the INIT signal. All addressed local APICs will assume their
' N% M& {0 d/ OINIT state. INIT is always treated as an edge triggered interrupt, even if
# r5 u4 g+ r: F2 X! b! ^9 z: }programmed otherwise. For proper operation, this redirection table entry7 C  u+ t0 H9 z3 q
must be programmed to “edge” triggered interrupt.
' X0 H3 R+ p% p2 x5 e1100 n7 \/ J# e- q* Y  r6 e' m
Reserved
) n- U; S* }. v+ c
1114 }3 {4 t) g6 v, Q: r+ |
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the
8 {! n8 O2 w) G, @* V' i
destination as an interrupt that originated in an externally connected
) t7 {8 S# I. l(8259A-compatible) interrupt controller. The INTA cycle that corresponds
9 \' }6 R7 s' ]" `7 @3 ]to this ExtINT delivery is routed to the external controller that is expected+ p3 u% {- X  ^0 m9 B
to supply the vector. A Delivery Mode of "ExtINT"
) a2 E  f$ i3 yrequires an edge

4 x* W- _6 z- ~) X0 K; W3 ptrigger mode.
9 e4 G: O5 G" r& {+ f$ B
[7:0] Interrupt Vector (INTVEC)—R/W:$ P% d$ _8 z( o( Z# C; X6 x/ m
The vector field is an 8 bit field containing the interrupt

; t  Z' k, u0 K$ P: ?& Hvector for this interrupt. Vector values range from 10h to FEh.1 i; c5 x7 a) \' T) R

5 D9 b0 A7 S1 J" ^REFF:
3 ~0 m/ x# X0 v6 E% T( {1 f3 E# O! |0 V3 J9 g2 U9 y
1.& b) I6 h, A& b
82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)$ S' U2 s; O" \+ c7 O
2.1 `* \, v5 F  U/ M' f, a/ P
8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)% h$ Y4 c' v/ Y+ Q1 ?
3." ]' R7 F. J( q; ?6 Z
Undocumented PC
0 o! p* Y/ y# q5 m, m9 k) a' S4.
, i( k* K2 r' O
, n# L+ ]  ^" x# _1 v8259A初始化编程
* M3 ~( p4 P3 H# p& D
! [/ e0 w# H! kThat’s all!2 p. p9 {  F1 d$ {
7 I/ z. D- V2 [; z" p: j
Peter
( k* z: Q  h0 G! _3 w( n# }1 ~% s# ]
2010/10/07, {2 N4 ?/ U, ~3 b& {2 q. s
# v) R. H  f) e* ~
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ]
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

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

GMT+8, 2025-12-1 00:19 , Processed in 0.325534 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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