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

PIC 、APIC(IOAPIC LAPIC)

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

$ o. Y; G* ^1 \2 m6 r2 J% i1. Overview
" m' ^. g4 J) h8 U) X  F, W, j6 g
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt ControllerAPIC是为了多核平台而设计的。它由两个部分组成IOAPICLAPIC,其中IOAPIC通常位于南桥中
4 _* x5 ?9 r3 w2 r* g& j5 t用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPULAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pendingnestingmasking,以及IOAPICLocal CPU的交互处理。
+ N1 C; K$ b* G) Z$ ~4 V9 C" F$ C9 ?* f% V

: O. k+ O! ~* u% \2. PIC7 k! z; f. s$ q! _) H" Q
& v4 H: Q: R" u) _6 p0 m. {5 _4 t. S
基于Intel 80x86PC使用两片8259A级联的方式组成了可以管理15级中断向量的一个中断系统,下图是它的一个连接示意图。两片8259A,一片为Master,另一片为Slaver。其中SlaverINT接到MasterIRQ2上。8259A有两种工作模式分别为编程和操作模式。BIOS初始化的时候会先通过IO port8259A进行编程配置,在此之后8259A就可以响应来自外部设备的中断请求了。MasterIO address0x20 0x21; SlaverIO address0xA0 0xA1
/ g9 d2 H+ q) N. y, ~3 c9 H
: g* M0 G% S3 r2 X8 R, m PIC.jpg
5 b' e/ [1 f* H5 b
, u; Z0 e, ]1 @& K; r4 ]
4 _* Z$ X  J- d1 X- L0 x为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code
, C7 X# }6 L2 Z3 r
' J+ I3 O0 J& V% p) ~+ Z- e2 u* PMOV
; @9 i5 Q! x8 W5 ~1 s$ L- RAL,00010001b: S6 C6 x$ i  R6 _( L
;级联,边沿触发,需要写ICW49 z. L( I- C, v& D  {& ?
OUT
' d6 x1 I9 q& O$ X% i+ [20H,AL
- E! }" Y) i& _1 _: ]3 w;ICW10 E1 A' K. [5 C7 O! N  l1 U
MOV" s" L( J4 Z) Q: w! L+ Z/ ~
AL,01000000B ;中断类型号40H
6 ]1 u: L9 u$ A- q6 jOUT
- K" C9 B8 j* E6 @21H,AL
$ H1 w( i* W" S! \: H8 i;ICW26 i# w5 V% x2 D2 W
MOV/ @) L9 c: d5 k' y( p! k
AL,00000100B;主片的IR2引脚从片
3 v" N9 T# L7 A7 ]OUT
- p- c& Q$ C0 f5 K; v& |3 ^21H,AL+ D" `  }6 Z& _+ N
;ICW3
: ]+ @: P/ p$ N: _6 LMOV
, ~4 L/ W' v4 ~5 QAL,00010001B;特殊完全嵌套,非缓冲,自动结束
7 t, W  E4 p5 a2 A4 JOUT
/ g1 q+ u" A' K21H,AL
1 m) @5 T1 T; q/ u;ICW4
  k- L/ F4 P' m3 ]/ b% S, z5 k; M" k% N9 |( n
3. APIC3 H# O2 X9 s7 S+ Z: p

- w1 M+ r& j; G' z- FIntel 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- ~2 Q7 Y/ E% ?) @) D% c
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
) m# z* c) y# z" a' T$ K/ o  y5 i4 Q9 Z4 L( v$ j! {; w0 X6 N! D

3 a5 D: c" M' w3 d IOAPIC.jpg # j" \, y% b- G- A) ~+ B8 a
2 P. @4 L4 ]( K/ `" a4 u9 ~
Programmable Redirection Table详细格式如下所示:5 Z& g8 z3 h' v3 S
3 _5 _: C' q  U- t6 y; f
Bit Description:2 Y1 v+ t; |$ _# s" G
[63:56] Destination Field—R/W.9 N; k& G$ ]( A# J
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits
2 Y8 i' X% F9 L$ q: e, C
[59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field
% h( o) H2 y1 A7 n4 kpotentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical, C5 I+ J0 O0 r5 ]9 m
destination address.
- a4 b/ A' k4 I0 ^Destination Mode IOREDTBLx[11] Logical Destination Address# }& `7 q0 }3 o$ P% a6 o
0, Physical Mode IOREDTBLx[59:56] = APIC ID6 Z- c% p5 a) V. ]
1, Logical Mode IOREDTBLx[63:56] = Set of processors) |% V8 Q( V# Y+ N6 {$ u
[55:17] Reserved.82093AA (IOAPIC)
' J% k: S: D# F4 O! R) D
[16]' {" m2 I2 k4 g" c( I/ E
Interrupt Mask—R/W.) h. w/ W, ]+ X8 I# N7 w6 A: Q- }
When this bit is 1, the interrupt signal is masked. Edge-sensitive
: F  y& [7 l, e
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).: O( @" `9 n  P' w6 [0 ]/ k
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
, r0 f( J4 i3 O6 D* `" O8 v$ O1 kside effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by8 I9 t6 O. w, M) l# X* U
a local APIC has no effect on that interrupt. This behavior is identical to the case where the+ ^& H6 l& d+ _" c8 A" B9 e
device withdraws the interrupt before that interrupt is posted to the processor. It is software's
" I: H( C* ~4 R( m# h: m0 U4 U) Qresponsibility to handle the case where the mask bit is set after the interrupt message has been' t4 J" W- @" D- L! C
accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this" X( w( K. w0 K: Z8 z( B
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked; i8 \4 `% v$ }% ]
results in the delivery of the interrupt to the destination.8 O. ^9 w4 I3 B* b/ W" Y" @- }/ H
[15] Trigger Mode—R/W.) O. D# @& j, O# ]
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
* J( R$ s7 C! S* Y
[14] Remote IRR—RO.
$ S3 s1 @& V# i; l4 n7 ?. rThis 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.

2 D* D, C) `1 M% N. ?6 A
[13] Interrupt Input Pin Polarity (INTPOL)—R/W.
% C: l$ U* r, QThis bit specifies the polarity of the interrupt
! R1 u" y8 u5 U/ G
signal. 0=High active, 1=Low active.
6 n, m6 k' O& V4 H; q( f6 _. C
[12]
2 j* X% X$ l2 p! h9 |Delivery Status (DELIVS)—RO.. ?' v5 ^  G; X
The Delivery Status bit contains the current status of the

  I! u6 w% P: F7 F, A2 [delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit
; }  t8 x% E3 |& G* _word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send" G/ X7 l, t  \4 I! R8 B! H
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC& O; D1 d) J2 V! \1 \/ J9 X$ _
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
$ _9 o4 t! i$ b3 l: h) Y  l$ U( X
[11] Destination Mode (DESTMOD)—R/W.
% x7 k+ A" @8 u1 f5 FThis field determines the interpretation of the

" K7 n: e8 L  s0 ?: n' K9 k. \2 QDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
; l: f/ B* |- a  aBits 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.
* b. }- g; I& TDestination Mode IOREDTBLx[11] Logical Destination Address 0, Physical Mode IOREDTBLx[59:56] = APIC ID1, Logical Mode IOREDTBLx[63:56] = Set of processorsE 82093AA (IOAPIC)
" v- f$ p$ P, Q, w. s
[10:8]Delivery Mode (DELMOD)—R/W.
* u3 Z9 j) O, F9 zThe 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
3 U- ^' W* K0 I/ ?  ]
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.# ~) _$ I% C5 F# N
These restrictions are indicated in the following table for each Delivery Mode.3 o0 @* _8 {' J0 F! D) e4 T
Mode Description6 [5 {% l3 O7 i
000
" S! f' _" o/ ~: j- NFixed Deliver the signal on the INTR signal of all processor cores listed in the
9 z) Q5 t& H6 e0 c% i3 ^; [6 w
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
( \, G! S, p% `9 x% M% T001( H5 K2 Y$ G+ ^
Lowest

; {- @; [$ B5 ?# Z. i- RPriority Deliver the signal on the INTR signal of the processor core that is/ H- _1 x) T# G8 L( w
executing at the lowest priority among all the processors listed in the
% O* v4 U' m: N6 j. T0 ^9 O+ Q7 ~specified destination. Trigger Mode for "lowest priority". Delivery Mode: ~) q. _( I7 h
can be edge or level.5 k' C, \" a  y
010
- s0 Q' X% o) [, r; L( RSMI System Management Interrupt. A delivery mode equal to SMI requires an
: A% R& f* {6 O2 A  @) m, w) L
edge trigger mode. The vector information is ignored but must be
/ D$ e, P4 L8 F, y% T2 q8 P% iprogrammed to all zeroes for future compatibility.
7 ^8 Q6 a" O# i# [0112 P$ \$ Z2 }% O8 X" h, O$ Y
Reserved
& W# @  Q# ^  P; E
100* n* Z+ q8 w$ Q
NMI Deliver the signal on the NMI signal of all processor cores listed in the

. U! |+ P9 c5 a3 V! W- E- Gdestination. Vector information is ignored. NMI is treated as an edge
& L% w' {/ r  _4 ptriggered interrupt, even if it is programmed as a level triggered interrupt.
* b/ K) @8 C" S" h6 e& l0 TFor proper operation, this redirection table entry must be programmed to5 Q* h7 g" n. r/ u
edge” triggered interrupt.5 v5 ]! f, J3 W
101/ F( A  [, L3 G; T, F, s
INIT Deliver the signal to all processor cores listed in the destination by
& ]" a& g6 c" P! R4 g6 \+ F
asserting the INIT signal. All addressed local APICs will assume their
3 V" D: n0 h. k5 ]5 n: W  L: qINIT state. INIT is always treated as an edge triggered interrupt, even if! E- i% Q7 n7 W* V( V
programmed otherwise. For proper operation, this redirection table entry
. y; X( `7 \. T  |must be programmed to “edge” triggered interrupt.
9 R  e/ ?5 a9 x$ S0 Y. a  o2 d110- n! n4 M: ~; \5 b0 N) Y6 C
Reserved

9 Y1 W" u6 {" Q! `, u9 F! _" U111# k9 ~( @$ l% h, H' d
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the
2 b! v; |* P. ~: V5 e2 ^8 I4 k
destination as an interrupt that originated in an externally connected
  \" T4 b( }/ x3 \3 U(8259A-compatible) interrupt controller. The INTA cycle that corresponds
' G" n: c* `# q2 M* r1 Bto this ExtINT delivery is routed to the external controller that is expected# O4 O9 l& D% ^( h- R1 ], Y; B; S
to supply the vector. A Delivery Mode of "ExtINT"
4 O: m2 b) r$ \0 qrequires an edge
5 _8 e* b1 n1 K& ?0 Z
trigger mode.
6 i. k! z9 K/ ]" z
[7:0] Interrupt Vector (INTVEC)—R/W:
7 _( N: Y" z3 ^6 ]; sThe vector field is an 8 bit field containing the interrupt
# ], q' e! N. t/ S6 v% T- t
vector for this interrupt. Vector values range from 10h to FEh." m+ W) e' w; W
# j* d! [9 a, Q( v) c# A
REFF:$ Z! f0 ^$ l  S4 I, R7 z/ t
$ W, a9 ?& g. Y' s- s- k/ o0 H
1.
9 A# ^& u* X7 g82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)/ H; g! E7 h% W& A$ ]4 i) _
2.
( R! D# L" ]1 K; I. g8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)
9 g) K0 V9 t/ {& V3.
" E& @/ D8 g9 TUndocumented PC
9 b0 ]% R. `# f4.* J8 k) g5 L1 D1 ]
7 w" ~1 R  ]) `" Q7 t( Y) [' o: x" C
8259A初始化编程
" d( B0 K7 W/ @/ G+ D7 b3 w
, f$ {& F: w/ K( g9 nThat’s all!
3 d9 h" V7 l$ s6 ^
5 {+ h: Y) C0 }* s5 }8 Z" DPeter2 d! ^: C0 [' `+ N# g, O+ k: Q' k

4 g) P) H6 l# F/ T5 }2010/10/07
7 ?( e& I4 @6 {/ S8 I
7 A& {; m/ `3 `: m[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ]
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

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

GMT+8, 2026-2-1 04:23 , Processed in 0.061437 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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