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

PIC 、APIC(IOAPIC LAPIC)

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

; h' q; K) S2 b+ U1 V1. Overview- j5 {9 ~& ]" y5 q" y: C! H

* ~# o1 {2 ], P9 l, P2 w; ]7 fPIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt ControllerAPIC是为了多核平台而设计的。它由两个部分组成IOAPICLAPIC,其中IOAPIC通常位于南桥中  V5 B& f* P2 m- w
用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPULAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pendingnestingmasking,以及IOAPICLocal CPU的交互处理。
0 ~8 ]  r7 `1 N  @2 k. |, W
8 m7 b: w2 I- C" C* j/ t% [/ Z2 w( i8 Z/ T
2. PIC
$ V6 j+ n2 ?+ \8 M/ k) p( ]
2 k! D0 g2 R5 Q0 H! G: C. P基于Intel 80x86PC使用两片8259A级联的方式组成了可以管理15级中断向量的一个中断系统,下图是它的一个连接示意图。两片8259A,一片为Master,另一片为Slaver。其中SlaverINT接到MasterIRQ2上。8259A有两种工作模式分别为编程和操作模式。BIOS初始化的时候会先通过IO port8259A进行编程配置,在此之后8259A就可以响应来自外部设备的中断请求了。MasterIO address0x20 0x21; SlaverIO address0xA0 0xA1& U( R7 Y, y: i; B: o

  ~6 T2 l& @) z PIC.jpg 1 W7 x& v2 }* t, H* ?. Q# o

( V- d' G: q7 |  _2 W% O9 ~
/ U$ a1 X. k  Z, `为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code6 K$ L/ n, a' L- @! [+ x* k

7 v8 s5 r, G, F. S& u) g& pMOV
0 o7 Q" b6 F/ s  _6 j2 z2 BAL,00010001b1 M; v! H+ q1 Q- f# h
;级联,边沿触发,需要写ICW49 O% |& C$ j. I" K: ~
OUT
; Q* f/ H1 r1 Q20H,AL& Q; b+ [5 X) A/ n6 \
;ICW1! Z* E3 P9 @3 Q4 n% Q' T$ l
MOV' J! Y, o8 J. O
AL,01000000B ;中断类型号40H
5 J: X- q& W" o# UOUT( O# Q2 r& s( f% F) ?
21H,AL
% G2 X- s7 x! d8 d- \;ICW2
; r6 V* D4 w3 h+ HMOV9 Y4 J7 h% `6 u7 _
AL,00000100B;主片的IR2引脚从片" Z0 B. ^8 C/ q9 a! c2 g
OUT6 J. G! a6 z+ N/ X2 g. ^- d
21H,AL
/ W$ Q  D' P1 d+ e( \- Y;ICW3
# @* F& G$ R5 l: L7 Y- UMOV
: @! ^) t& T; _9 Z  v$ H, X" y% \AL,00010001B;特殊完全嵌套,非缓冲,自动结束
0 r  V1 Y' r- F9 ROUT" S" G  X  M. R) x
21H,AL" w1 M7 F5 q6 l2 h1 }3 I) J9 ^
;ICW4# k# c+ h3 E- n, q1 f( b

/ T& s; Q9 J. @& D: A9 J9 b2 i3. APIC
8 U6 T6 W; I3 |  D, l" F+ H4 y# r" O: v' d& v
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 pin5 _8 X' r8 s. s, g# K* e
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。0 X' D; L# `; W* G& t3 A0 A

* c; V. K& U( ]" X) Y
% S7 a, [3 U2 K, i0 { IOAPIC.jpg 6 }+ K0 {( c. G. A$ L* }, v6 w

7 ]$ F; t5 ~, XProgrammable Redirection Table详细格式如下所示:
% S' f8 t2 H/ m. B. S* |, C: t) y# N# O* P+ Q) U  R
Bit Description:
  D  U- `1 X. }" m$ H' S# c7 a& @9 O
[63:56] Destination Field—R/W.8 T; k) s% }& G
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits

# c# `( X! t& J+ j9 |3 X+ X- R
[59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field0 k* ]1 W  z1 v1 }) L& w
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical3 P2 e6 h& j( S
destination address.4 Z$ ]  u' @; r9 k8 @! L
Destination Mode IOREDTBLx[11] Logical Destination Address
' S/ |6 E) s- T7 [$ N/ t- b. s0, Physical Mode IOREDTBLx[59:56] = APIC ID2 N/ U, I. v$ ~8 x! S- @- c
1, Logical Mode IOREDTBLx[63:56] = Set of processors
% G6 u: I7 r; h" J8 E
[55:17] Reserved.82093AA (IOAPIC) ' g8 E+ }" \) k
[16]
6 }7 w) X5 x$ h" H0 \# t( ~Interrupt Mask—R/W.7 ?$ G- z& r5 c6 I: Q
When this bit is 1, the interrupt signal is masked. Edge-sensitive

$ x" |& V$ U7 R2 k$ hinterrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
/ G- w8 s# Z7 R4 f& q% w  g: Q+ YLevel-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no/ F! \; a- o  b
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
1 o* a7 [& {# v0 sa local APIC has no effect on that interrupt. This behavior is identical to the case where the) I2 @5 ]  D! k" K
device withdraws the interrupt before that interrupt is posted to the processor. It is software's
: B! ]( O) v. u3 v: T6 B( rresponsibility to handle the case where the mask bit is set after the interrupt message has been
. W0 P6 `$ I5 x$ v8 y, N! maccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this$ G0 d  x" H" ~: X
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked, Q0 @' j7 c. R$ [8 b* g
results in the delivery of the interrupt to the destination.2 `+ Z$ `! |- [- q
[15] Trigger Mode—R/W.
* m$ B" b1 O% j" y4 ^8 ~The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.

- K( b7 f' q# ?: H4 t5 s7 O2 N
[14] Remote IRR—RO.
; L6 f8 @9 Y/ M2 k8 V. A( pThis 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.

1 e/ A& ~" W5 U
[13] Interrupt Input Pin Polarity (INTPOL)—R/W.
, A7 n3 A' ~* e* \8 BThis bit specifies the polarity of the interrupt
# r  T  o9 B8 n: z
signal. 0=High active, 1=Low active.
  P2 v, I  T: K5 r8 F+ x& z! x
[12]3 R! D2 o6 S$ Z3 W/ J& o
Delivery Status (DELIVS)—RO.2 F, ?7 Q  x* ^5 K/ w- @. ?3 r
The Delivery Status bit contains the current status of the
, H; \' i% s, U, A1 ^+ _3 `6 N
delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit
; N( ^% {; I  c$ V. [word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send$ g4 j- h9 D; _
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
- N, f2 X# F6 h2 U' H$ zbus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
+ B0 U8 E: S9 p% L( x
[11] Destination Mode (DESTMOD)—R/W.8 }* f! _: N: R
This field determines the interpretation of the
- _1 ]2 K2 ^4 I: K
Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
8 G6 M" r$ Z1 G2 j9 TBits 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.
. t3 o9 N5 Y$ g$ ^! V* ~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); t( v; G6 D9 N& I
[10:8]Delivery Mode (DELMOD)—R/W.
1 C- u( q/ u, ^8 f1 D- x# |4 {( hThe 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

8 _! j! ~7 z" c. O* l% GDelivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
) ]" V; t7 T% T  [- h# ~* t& NThese restrictions are indicated in the following table for each Delivery Mode.# i0 v* T* ^4 E( K+ C3 B5 o
Mode Description
$ K  U) p' ~$ N7 U! B000
1 }( I+ ^4 B- ~0 _4 k& C* m1 mFixed Deliver the signal on the INTR signal of all processor cores listed in the
0 {$ Z$ Q( x- r( p2 m4 u; A& D6 v( d
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.# J) J6 d/ {4 ?" a) y5 T* F9 s: |
001
9 L7 S8 b7 l+ `$ W4 a  f9 K3 TLowest

2 n1 ^8 h+ S9 `: |Priority Deliver the signal on the INTR signal of the processor core that is- e; Q3 v) @  Z
executing at the lowest priority among all the processors listed in the% q+ ~# A2 ~+ A# \* {
specified destination. Trigger Mode for "lowest priority". Delivery Mode
5 `4 x& L$ j% o0 V5 Q8 ^can be edge or level./ f0 b: \1 c1 }9 D# |8 y
010
0 `1 p. }/ B* [SMI System Management Interrupt. A delivery mode equal to SMI requires an

4 Q) h$ t! @! T5 {1 a; M4 p3 \. V- M- Redge trigger mode. The vector information is ignored but must be
; |8 ?) l+ l7 jprogrammed to all zeroes for future compatibility.# X4 i4 c  b& K$ [  F# R
011/ @. D3 L8 w" Y7 Q1 {
Reserved
* n" J% s7 o2 s5 r7 J2 F& w
1001 Y3 ?3 u- w  @0 [
NMI Deliver the signal on the NMI signal of all processor cores listed in the

2 P1 Z: S3 c& ^. @3 N# Udestination. Vector information is ignored. NMI is treated as an edge: h+ _! \) P0 o
triggered interrupt, even if it is programmed as a level triggered interrupt.* I2 p2 N7 R% {0 Z5 y0 I
For proper operation, this redirection table entry must be programmed to( a4 C3 e; M- s: g
edge” triggered interrupt.( @/ D$ I- T2 i1 w
101* P1 w/ C, q0 G' T
INIT Deliver the signal to all processor cores listed in the destination by

0 ?+ u5 U8 d/ A7 m8 f5 @- \asserting the INIT signal. All addressed local APICs will assume their& @& u, U& S5 b0 N
INIT state. INIT is always treated as an edge triggered interrupt, even if  J2 S" K% S# A% M
programmed otherwise. For proper operation, this redirection table entry
$ Z/ F5 T) o# N6 jmust be programmed to “edge” triggered interrupt.
% @: i4 T# ^. T$ r7 w110
: f, v9 p- D) FReserved
  W. x. ~$ G7 M+ u, s# i. ^+ g
111& k) y# k! D0 T, {
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the
# K) k3 d* d4 ~  L9 ^9 G( L! a( k
destination as an interrupt that originated in an externally connected
1 {/ t) _. }' n" c, p% j(8259A-compatible) interrupt controller. The INTA cycle that corresponds
% v3 \  D/ B# ]to this ExtINT delivery is routed to the external controller that is expected* U) j, Y# _( P0 _% X
to supply the vector. A Delivery Mode of "ExtINT"
4 |' Y) w. U9 [; M# \: [4 @requires an edge

# w4 t8 n6 N; m) e$ v" Ftrigger mode.+ @, h7 j, t" B0 p3 m- }7 B/ j- B
[7:0] Interrupt Vector (INTVEC)—R/W:" l9 P! h6 {6 s" G7 b0 l; N+ i
The vector field is an 8 bit field containing the interrupt

7 d2 T; r( Z  l( ^8 Bvector for this interrupt. Vector values range from 10h to FEh.
5 Z- g( n3 e" S

2 I4 l# y5 Q. q4 _0 sREFF:5 Q- K: G! s. P% Z$ Q9 V

4 U& K/ l+ c; k1.
. ~9 T- C# v0 L" u7 @3 f2 J82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)! x" O* ]3 e2 r; X) `
2.
2 w* _) J  c3 j+ k8 H1 R. u8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2). }) h- N: T+ S' R# z
3.
" \/ C. t$ Q! ^" [Undocumented PC
1 @) h! G3 u0 x' r$ e4.
2 `( O2 j4 n+ v4 }
8 a; Q  m* V4 v4 y3 ?8259A初始化编程& ?8 g$ j1 V' u! \+ r5 X. c( c

- W$ F9 b; i- Q8 s- p# mThat’s all!1 y" Y8 l7 M+ m' r" Y' Y6 h2 r: _# L

: z- h* u  P2 KPeter  l! K, j$ K1 V6 Q# h2 k
. q8 P' l1 @3 U  n3 _8 v' G" L3 k8 J" {: h
2010/10/07
# N, w7 \  K, X, Q* B4 X
1 i0 J) O# r4 A+ }' m1 k4 Z[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ]
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

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

GMT+8, 2024-5-19 16:22 , Processed in 0.030544 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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