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

PIC 、APIC(IOAPIC LAPIC)

[复制链接]
发表于 2010-10-29 16:11:58 | 显示全部楼层 |阅读模式
PIC APIC(IOAPIC LAPIC)
4 H6 b- g! P, ]" {
1. Overview+ t( d9 i* R& `. ?, U0 P

2 |. X* m/ n/ g5 WPIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt ControllerAPIC是为了多核平台而设计的。它由两个部分组成IOAPICLAPIC,其中IOAPIC通常位于南桥中
* g. W, E" l* q2 n' L- G2 p& t$ L用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPULAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pendingnestingmasking,以及IOAPICLocal CPU的交互处理。% x; A0 h' T. n$ c/ v; m8 _9 c

& r. S  P7 B/ a% j& `' [4 I8 v$ g! E: V  e
2. PIC7 E$ ^9 M! m0 M5 _
( C6 ^: R7 U& ?# K$ c5 i2 i3 r8 E) v& P
基于Intel 80x86PC使用两片8259A级联的方式组成了可以管理15级中断向量的一个中断系统,下图是它的一个连接示意图。两片8259A,一片为Master,另一片为Slaver。其中SlaverINT接到MasterIRQ2上。8259A有两种工作模式分别为编程和操作模式。BIOS初始化的时候会先通过IO port8259A进行编程配置,在此之后8259A就可以响应来自外部设备的中断请求了。MasterIO address0x20 0x21; SlaverIO address0xA0 0xA1
% Z! l' x5 k$ I5 @7 u* U% C; o! ?$ `* j8 a- g* i$ c) Y, c
PIC.jpg $ w6 E# L9 X! N1 o

* D" s* Z. P0 k; W6 ]' \/ ], r5 r2 h3 K8 D3 K6 x9 x0 Z/ a
为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code
$ I* j- ], d7 y7 Q, O
: j, Q% H" ~- }MOV
- T8 J( @' N* r: o; Q$ U% Z2 w# ]AL,00010001b
3 h8 L1 ?$ v$ C+ j3 u;级联,边沿触发,需要写ICW4
$ i# j' Y9 K* t0 H0 x6 q" \; Y2 POUT
, J( D  \9 M0 g$ \0 N20H,AL
, T3 q. t9 ^9 p: X, d! g/ f1 q$ K;ICW15 K9 n, e: t9 W0 V$ F
MOV$ E: S" ?' I7 A
AL,01000000B ;中断类型号40H
: H. N3 x# \& g$ k  h2 i% D- MOUT6 d! G" @, M* |* V9 L& @5 L$ L% N0 T
21H,AL/ H4 P, _! t" C) T  g" h% _6 \
;ICW2
. y+ B) }7 x$ Q9 A: k; AMOV& K% g3 I  |1 m. l: C7 A+ ?
AL,00000100B;主片的IR2引脚从片* T! \6 ~1 B& ]& ~
OUT
8 |/ \) c6 j9 d# I7 ]( L! b& t+ R6 |21H,AL" V- B4 z0 j! G- v5 c1 U! y
;ICW3
6 U- F) f+ L& B  QMOV
& }2 k2 B5 X: L# x, uAL,00010001B;特殊完全嵌套,非缓冲,自动结束
7 @8 E7 C5 {6 kOUT
* z. A5 _. M2 \4 w21H,AL
0 ?+ v* y) u* W7 `) c;ICW4( K) z. Y9 I$ U* _, t
# a+ Q. w9 m! j( D9 }2 W2 n# |
3. APIC- L0 {( F1 q" {8 b

3 U7 u" U  [8 F, }  aIntel 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
1 G0 ^( |3 |8 c: e7 j; y5 t# r+ ~每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。. u4 ~* ^+ _; g0 S( H# O1 y& Y

) t) i  n$ D$ }6 u1 q3 a* ^4 `) D+ u$ y* T3 f( I% j
IOAPIC.jpg " I: z% E- L/ f4 F
9 w3 i& z3 a4 S. Z  E+ N
Programmable Redirection Table详细格式如下所示:
0 h7 y5 U$ f% _8 {' J1 N4 h. n( V/ g; C, ]- |6 \, H8 H5 l
Bit Description:) }1 `% X" n  b, g% K
[63:56] Destination Field—R/W.
' _' @' D/ x; E, s% \, @' }If the Destination Mode of this entry is Physical Mode (bit 11=0), bits

' r  N* {. l- Y" A
[59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field* q2 [+ k" \1 f$ P0 P
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical7 V6 n. r  r  i$ ]1 c
destination address.. x: W( J: j/ l* r. d
Destination Mode IOREDTBLx[11] Logical Destination Address, v! K9 M% V7 D! c3 m# }
0, Physical Mode IOREDTBLx[59:56] = APIC ID" H- L* @! R/ {: y' C4 t- E
1, Logical Mode IOREDTBLx[63:56] = Set of processors6 c3 R) z5 V* ]4 o" B( i$ Y
[55:17] Reserved.82093AA (IOAPIC)
7 N# g* s1 |, ^: `
[16]5 o+ B9 d. Q/ L. B& ]5 `- g% M& V
Interrupt Mask—R/W.* u+ }1 D2 d+ |8 F8 M
When this bit is 1, the interrupt signal is masked. Edge-sensitive
( |! J4 D8 Y  q* N4 ?
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).; s  g/ N9 \9 e: O& [- t
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no" v+ I/ k, b7 X, s% S# @+ e
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
* I- ^/ d# @9 e2 \3 n. l6 ^a local APIC has no effect on that interrupt. This behavior is identical to the case where the1 J5 r2 m. W) L3 u& [9 |
device withdraws the interrupt before that interrupt is posted to the processor. It is software's
# V8 H6 X  M8 n: _. V- ]% T) ?9 eresponsibility to handle the case where the mask bit is set after the interrupt message has been
+ b: X2 j# g- P6 uaccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this
+ w: ?+ _* Y* q4 fbit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked' R7 r5 V* w# F' {
results in the delivery of the interrupt to the destination./ e9 ?: n$ p0 P9 ]4 P& b( l
[15] Trigger Mode—R/W.
  }1 o2 E  @- J# d. bThe trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
2 B8 A, d# K8 r
[14] Remote IRR—RO.& h6 R( w  ~9 }+ X) |) |  k4 D
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.
  O9 Q: g1 Y/ [" h( Z* ?7 X
[13] Interrupt Input Pin Polarity (INTPOL)—R/W." b' J+ N; L: @
This bit specifies the polarity of the interrupt

; _- K1 D3 \0 Y. K1 P( D5 J+ esignal. 0=High active, 1=Low active.
8 F3 C% ^( U$ s8 B" }8 L! N2 m3 u
[12]( L$ f  O* e/ S/ Q
Delivery Status (DELIVS)—RO.
- F9 z6 g- j6 w4 V1 ZThe Delivery Status bit contains the current status of the
5 J0 S6 Y& A0 q( G, {2 g
delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit0 W. R8 i' b7 ~6 `- V
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
  Y7 F' K7 G8 e0 `" n3 Z: APending (the interrupt has been injected but its delivery is temporarily held up due to the APIC6 G5 D$ ?- s! n+ ^' j  Y/ A1 ]
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).. b' t( f- w9 W6 |
[11] Destination Mode (DESTMOD)—R/W.. |# j$ i5 [# g& [3 b
This field determines the interpretation of the
1 x; ~3 W. f: x. S4 S7 p+ _4 [4 n
Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
8 v% [: F8 ^! r8 @9 k" d% u' E  [. e! _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.# {6 ]! _5 D$ 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)/ O) S- c1 D/ m0 z. r6 D" G
[10:8]Delivery Mode (DELMOD)—R/W.
; _9 m2 a( J8 |/ V- ]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

. ~9 H' T  o, O+ \Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.* M7 }& g, T6 a+ z" U
These restrictions are indicated in the following table for each Delivery Mode.+ ]' i5 O8 _2 ~9 n/ p! ~1 x
Mode Description
5 M2 }6 `* V+ _. U+ U000- f3 `- [. Z7 L8 }% r: Z
Fixed Deliver the signal on the INTR signal of all processor cores listed in the
+ D6 M3 E6 o5 n4 {# C* _$ t
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
% o& v. T8 F! q. d001
; x" L! p. z; X( `/ dLowest
: J+ }* \" G: Y6 C
Priority Deliver the signal on the INTR signal of the processor core that is& x, K7 ~, z9 H% D$ ]3 E2 X
executing at the lowest priority among all the processors listed in the% p) v$ B, M, B! x$ |- x" X
specified destination. Trigger Mode for "lowest priority". Delivery Mode
8 K$ F9 n- o' X8 s/ m4 d0 [can be edge or level." a1 i( E5 U8 r' a
010' _  ]( H# A% P$ A
SMI System Management Interrupt. A delivery mode equal to SMI requires an

* n; d% C* `4 c) Xedge trigger mode. The vector information is ignored but must be
6 O: ~2 f% g) w5 gprogrammed to all zeroes for future compatibility.
- F4 y  q% z0 E% G  G011; z6 k$ X# w8 Q1 Z
Reserved
$ b5 A- y) V1 Y- T2 n8 S  U& |
1008 Q0 J% Z. x6 S) U2 E7 t2 {6 Q3 ]
NMI Deliver the signal on the NMI signal of all processor cores listed in the

- u# ?$ {* |$ N5 W' Mdestination. Vector information is ignored. NMI is treated as an edge
+ V/ r+ ^7 ]- Y) Ytriggered interrupt, even if it is programmed as a level triggered interrupt.
4 i9 {3 c$ A6 |+ NFor proper operation, this redirection table entry must be programmed to
4 ^2 b+ h# e$ z8 A, Dedge” triggered interrupt.
8 L, c4 p( s) A7 [5 q101, j$ i7 ~& f: K% F
INIT Deliver the signal to all processor cores listed in the destination by
2 ~/ X! n- @) U1 s5 y: d: d
asserting the INIT signal. All addressed local APICs will assume their# W- X  }; ?, z6 L( p- o1 m* t" Q
INIT state. INIT is always treated as an edge triggered interrupt, even if5 k* r4 [0 C0 |2 [. _+ R; @
programmed otherwise. For proper operation, this redirection table entry
3 {% ~, o, o6 t' E4 g$ J0 l+ h9 fmust be programmed to “edge” triggered interrupt.
# ~" V8 [" p$ R4 D% u110. q9 y5 V3 [# ?6 a- a5 l. m
Reserved
* O/ T0 r  T5 M
111# i& b" O9 @+ m0 M
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the
0 A/ z% {3 h( y1 A) H8 l' Y
destination as an interrupt that originated in an externally connected
+ x: W5 C2 z" j, l" b# ](8259A-compatible) interrupt controller. The INTA cycle that corresponds! P/ ^8 X7 ^9 N! o/ i6 i
to this ExtINT delivery is routed to the external controller that is expected
# ^1 J5 k4 Z- r% K2 \% nto supply the vector. A Delivery Mode of "ExtINT"
! ^" [! O" ^& y: q# Yrequires an edge

7 X0 x3 K2 y: \7 D2 y7 ]2 Atrigger mode.7 x8 g2 P! R. t
[7:0] Interrupt Vector (INTVEC)—R/W:
8 T/ e& d$ Y& bThe vector field is an 8 bit field containing the interrupt
: [1 i, B& |8 d% w; `/ m
vector for this interrupt. Vector values range from 10h to FEh.! K& C3 c) l& d0 t1 [$ u9 t: d; |
8 U. `8 m4 _& |% h) T2 ], f
REFF:
* T3 N3 |+ w5 H) z  T) s6 R; f! z8 ]
& ^1 c; e2 n9 A1.6 n3 y& Z- S% s; J$ @8 a
82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)" U0 F8 G( ^, Q3 s
2.
; O; x" B( A6 D( J- {! c' n- {( ^8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)
4 e6 l1 S- N& l% L" C% A3.) S2 ?% W! m0 T" f/ |
Undocumented PC; Y7 f. C1 g3 I
4.
, P2 b% V! V, f3 u: B# K7 d& P) V8 r, c; o) _9 ]) Y( F
8259A初始化编程
+ y( Q- e! e) I2 w8 Q$ w  g
$ v# w2 F+ ~( W5 t$ d: M  }5 aThat’s all!
5 u3 b" R# D* e* W  D
8 U2 m1 d/ J3 T) Z( kPeter; X/ P6 t$ c2 ]9 L0 a

% ]1 o* T( B4 ?. C. I3 N2010/10/07
/ s: i) m; O+ Q& s0 h, ?( T) t9 D1 X& Q. E6 y* C7 [2 s6 S9 b
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ]
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

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

GMT+8, 2024-11-15 20:42 , Processed in 0.027506 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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