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

PIC 、APIC(IOAPIC LAPIC)

[复制链接]
发表于 2010-10-29 16:11:58 | 显示全部楼层 |阅读模式
PIC APIC(IOAPIC LAPIC)
  ]' Q! @# ^( N: c- C4 F
1. Overview# Y$ O2 j8 l- ^6 v& R' j
+ B# F% {' e/ N
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt ControllerAPIC是为了多核平台而设计的。它由两个部分组成IOAPICLAPIC,其中IOAPIC通常位于南桥中8 x+ a" Z0 }- s4 {0 H0 [) ^
用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPULAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pendingnestingmasking,以及IOAPICLocal CPU的交互处理。6 c; H' |4 [- x% H! ^
# h4 F+ Z& S& s2 q+ ^; ?

& B* ?, e. ]$ t' ^7 J% T2. PIC& D7 j' L  a/ B6 r8 ]

0 H: W$ F6 n" K4 L- t1 P基于Intel 80x86PC使用两片8259A级联的方式组成了可以管理15级中断向量的一个中断系统,下图是它的一个连接示意图。两片8259A,一片为Master,另一片为Slaver。其中SlaverINT接到MasterIRQ2上。8259A有两种工作模式分别为编程和操作模式。BIOS初始化的时候会先通过IO port8259A进行编程配置,在此之后8259A就可以响应来自外部设备的中断请求了。MasterIO address0x20 0x21; SlaverIO address0xA0 0xA1
7 r" e7 s% W% y: Q# ~* U) M7 l% t8 T, N
PIC.jpg
; |, o+ t4 r8 T/ N* v0 g+ j8 _) e: w9 ~( F! [0 B+ @

6 k; g" j& S. T# ^+ n为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code+ s5 G% D# W* L! Y

3 s4 i5 Y" c2 C6 z0 L9 i* C+ {MOV5 j% P* x/ f1 d
AL,00010001b
! s" p0 n1 m+ ]! h# C;级联,边沿触发,需要写ICW41 V( t" }* f" I/ d0 q0 u2 c
OUT, K  y# ^* Y+ W
20H,AL  U, p1 _0 ?% z1 T3 V. k: S) Z
;ICW11 x3 a0 b+ _* S; U# ?( e
MOV0 x# ?; {; \8 R( r
AL,01000000B ;中断类型号40H: g( y* m# f6 G. A( ^
OUT
" A" z0 v8 X5 L( k2 O21H,AL4 ^* K- b5 d; @6 T' i, C
;ICW25 T. f8 o: F/ {9 L0 M3 z5 R
MOV
! ?# D% H8 Y, {& W% qAL,00000100B;主片的IR2引脚从片1 |* Q3 Z: X( Q" a5 L
OUT
  t) X2 D1 g, N" J  J* F% p21H,AL
; ]% G! s8 @. j8 y: m! \8 P6 N' E;ICW3& d4 ?$ [$ P3 s9 i+ p0 G5 d
MOV
0 d) i# b/ n' K- Z5 [) H1 y6 w9 |AL,00010001B;特殊完全嵌套,非缓冲,自动结束
9 R- A; O; e! WOUT
: c6 I: X( v* a) m# n8 i6 f21H,AL2 H0 G9 V3 A+ R2 B
;ICW49 c5 t) s/ u- i: |$ _7 P
8 R5 W8 ^6 {1 p! y9 A# P9 _: [
3. APIC
; R, _8 G/ w5 h/ R" B7 e& i$ n+ d% [! ~3 W
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 pin
! n+ Z) H* p. A& B+ {# J, c" [每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
& L, T- n7 L# n! h* {& v
8 Z. f* i" L" R, ~( T0 f) C! H9 G# D5 L4 W
IOAPIC.jpg 9 c  ^/ u9 m8 l% k& y$ s' K" y, _

8 I( Q6 [$ N) K( s  IProgrammable Redirection Table详细格式如下所示:
5 G& W& J8 ?& f5 _: R# Y7 B3 l. `7 d2 Z2 K1 @( c1 m* U% V
Bit Description:# O3 I: h- Y* B/ m# ^, Z
[63:56] Destination Field—R/W.; |$ q% c# w1 A0 P$ E0 x$ t
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits

# d" n* a' u& X" K# q
[59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field) ~$ p& d/ R1 n
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical3 p# q3 t) q* [, e" V
destination address.
" D' N+ u5 Q" F$ q' F# T7 S) ODestination Mode IOREDTBLx[11] Logical Destination Address! M$ C- @) O4 u% E
0, Physical Mode IOREDTBLx[59:56] = APIC ID
( f; Z7 {4 L0 y9 D1, Logical Mode IOREDTBLx[63:56] = Set of processors" f1 n5 d, x# h( U
[55:17] Reserved.82093AA (IOAPIC) / E6 v# {7 o( \8 \+ c4 j# f
[16]9 C" U* W- E# s+ P
Interrupt Mask—R/W.
7 r+ [3 c' S; Y3 N. PWhen this bit is 1, the interrupt signal is masked. Edge-sensitive

, k  m  ~% c' i0 i7 T( n- Finterrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending)./ P' |  ?1 u. K- N9 L
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
' @- M. g2 e! C( Uside effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
- G8 h/ Q. ?6 t1 W( C/ ~2 l! d7 oa local APIC has no effect on that interrupt. This behavior is identical to the case where the3 {, ]9 w7 Q3 V% H
device withdraws the interrupt before that interrupt is posted to the processor. It is software's
5 M6 e: N3 s( e, r% `) Y7 x3 ]3 r8 jresponsibility to handle the case where the mask bit is set after the interrupt message has been
$ `! P& h" f! Y" B& C/ Y0 D3 Raccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this) d( {6 d6 [: z3 h
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked# o& A2 N! l* j& J8 L
results in the delivery of the interrupt to the destination.6 u5 H( Z$ Z; \8 \6 a7 r$ }' [5 y
[15] Trigger Mode—R/W.
2 s4 a2 X6 E7 n3 g* \: b/ G* FThe trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.

8 Q7 V" q1 z/ L# b* d6 P' B
[14] Remote IRR—RO.' E: n* |: r  |  s7 o" \* t' `
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.
8 y8 h6 _+ y& z2 }* ~/ f
[13] Interrupt Input Pin Polarity (INTPOL)—R/W.
$ u* N$ ^6 |$ O: [This bit specifies the polarity of the interrupt

% Z: j+ k/ }0 _7 u  k, [signal. 0=High active, 1=Low active.
* L; X: A3 h, I& j* l0 u2 i
[12]
3 k6 v2 X' |% bDelivery Status (DELIVS)—RO.% @) l$ K9 r: ]5 [/ @, D# e
The Delivery Status bit contains the current status of the

1 D8 c. D5 b) t4 s4 R) ]delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit+ C! C( C( |& \. w$ ~, `( f: d( M
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
# d: c, J# N; ], p6 g3 EPending (the interrupt has been injected but its delivery is temporarily held up due to the APIC8 v# q: s* T* z! \2 J$ P& J
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).# A% V" \/ K0 m$ s! }( N8 G. z
[11] Destination Mode (DESTMOD)—R/W.
# H( ?' z9 h' b; H5 V  gThis field determines the interpretation of the
% q3 j. h2 q) ]
Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.4 V6 m% |) d7 u8 o; t
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.9 i9 |' b, m  v  D* R
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)
& K$ V( }+ `: \) ^
[10:8]Delivery Mode (DELMOD)—R/W.
! H5 T! J" Q# _- @$ ~& C9 pThe 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
; P6 X- o2 N- q4 N9 V- [
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
# Z3 @5 W, L+ o* sThese restrictions are indicated in the following table for each Delivery Mode.
+ B2 b( V3 h# F- h7 RMode Description
. @: [" ~$ ^2 _6 d000" H6 G0 [2 d+ n
Fixed Deliver the signal on the INTR signal of all processor cores listed in the
6 {0 U- e9 w4 K% k* E$ q; w
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.. o& `& g- E$ A6 N
001
2 q* R+ M" j- C9 {2 {- [+ xLowest
: O6 g, Q% {# ?3 t
Priority Deliver the signal on the INTR signal of the processor core that is
; A9 `1 Z, H5 a, T6 {3 g  w  vexecuting at the lowest priority among all the processors listed in the
# |$ B$ Y) Z0 }& [specified destination. Trigger Mode for "lowest priority". Delivery Mode% S$ ]& s, m/ ?
can be edge or level.' M/ \/ U$ H& ^2 m3 c( C
010" k7 r7 s; [7 _9 V! C  N
SMI System Management Interrupt. A delivery mode equal to SMI requires an

$ G1 M; Z* O& `% G: N3 G* pedge trigger mode. The vector information is ignored but must be7 i8 h6 v+ u; j. d) _4 s
programmed to all zeroes for future compatibility.: @! ~0 G( J2 D* ?5 |! r
011% t/ u! v: d; @1 \) v
Reserved

" b9 [* R; s9 y. q* o( x100
! b& p  q- n) ?6 HNMI Deliver the signal on the NMI signal of all processor cores listed in the

! g/ r( |# _2 v9 m8 u/ u; Xdestination. Vector information is ignored. NMI is treated as an edge+ K, o& v, Z$ o2 p, {. U7 ?) s
triggered interrupt, even if it is programmed as a level triggered interrupt.
: f2 ^2 o7 R8 t9 K9 n3 bFor proper operation, this redirection table entry must be programmed to
1 w7 [( U0 m! c$ T+ pedge” triggered interrupt.: e5 n, l& `) Q" b4 y; M
101/ ]$ `& O4 e' T0 v" s; u
INIT Deliver the signal to all processor cores listed in the destination by
9 o4 }, P/ P) I/ V: D) h. j% ?
asserting the INIT signal. All addressed local APICs will assume their" J( [3 ?1 A  F7 _( ~
INIT state. INIT is always treated as an edge triggered interrupt, even if
. {$ J4 a. s& ?programmed otherwise. For proper operation, this redirection table entry
5 V. l* {* }; u' R5 x% H/ ?& nmust be programmed to “edge” triggered interrupt.
! i% P- a" }. O110" J% |2 f" j3 u) G
Reserved

1 L4 U! F) ^2 m4 _0 f, M* L111. P" @% A! V- g2 w/ F4 p
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the

0 X) z9 V: ~7 `  `3 Y; ydestination as an interrupt that originated in an externally connected
  g) I1 }1 g9 o(8259A-compatible) interrupt controller. The INTA cycle that corresponds  `: R# U7 m. l) ]' s
to this ExtINT delivery is routed to the external controller that is expected6 B+ e# L  a- C4 o9 Y0 O2 l9 a
to supply the vector. A Delivery Mode of "ExtINT"/ N$ |8 |) }; ]+ q8 Z4 F  y
requires an edge
/ ^% d9 g* l0 x& I) |. [2 z
trigger mode.
" O! B" k9 V9 `% F1 s& m! v
[7:0] Interrupt Vector (INTVEC)—R/W:( O+ G7 ^4 |5 S0 o& o; y3 x
The vector field is an 8 bit field containing the interrupt

% r/ I# d# E) c7 i5 l1 w- xvector for this interrupt. Vector values range from 10h to FEh.
) v4 I5 v( i4 w- A, r

: d' L, _; q% G5 K( TREFF:
0 \2 H7 p$ {1 ]4 e) q) ^" p1 v# I  i2 b) Y
1.
1 c/ s' R2 p& q0 Y: Q1 X' r82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)
. w7 o2 `0 g; Z; S: n  `; e8 P/ S3 i2.
% b8 P3 t2 F4 @% v+ G( w/ a8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)1 f, A4 x+ d* i4 {# p+ H
3." L" Q) ~9 |6 S+ m
Undocumented PC
- Y, K. h8 ]7 O: A4 y4.: ]8 H/ A4 b5 w! |

7 w' T; L1 d% `% v7 B2 N$ P8259A初始化编程
. @, g1 @& `8 ]# E; _% {6 b2 }1 k. R# X. J
That’s all!5 S5 f5 F) V8 a8 O) H

, R$ g$ x( O2 a/ z! ?5 S! cPeter3 r4 O3 @$ ?8 Z) f

0 m, B- j6 G* V1 R/ X/ q1 o7 `2010/10/07& x; o# e# C2 l, V
" e# T6 L: Z% k; l# c
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ]
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

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

GMT+8, 2024-5-9 14:10 , Processed in 0.053414 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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