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

PIC 、APIC(IOAPIC LAPIC)

[复制链接]
发表于 2010-10-29 16:11:58 | 显示全部楼层 |阅读模式
PIC APIC(IOAPIC LAPIC)
# G" `+ K2 V* V( G
1. Overview
$ K8 r! h( R6 M/ G) J3 Z4 j9 e, d4 P' Z, `* S+ g7 _: B- H
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt ControllerAPIC是为了多核平台而设计的。它由两个部分组成IOAPICLAPIC,其中IOAPIC通常位于南桥中
$ ]3 s. a7 a/ }/ {5 u, L用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPULAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pendingnestingmasking,以及IOAPICLocal CPU的交互处理。
8 R* K7 O( K: K: k+ N' `/ U  A( |9 L1 H/ O& T+ l$ ]
% y. t$ n9 C1 K9 \! q
2. PIC
; K  u  B% b7 r) \/ c: x6 s8 A/ a9 x) Q- r
基于Intel 80x86PC使用两片8259A级联的方式组成了可以管理15级中断向量的一个中断系统,下图是它的一个连接示意图。两片8259A,一片为Master,另一片为Slaver。其中SlaverINT接到MasterIRQ2上。8259A有两种工作模式分别为编程和操作模式。BIOS初始化的时候会先通过IO port8259A进行编程配置,在此之后8259A就可以响应来自外部设备的中断请求了。MasterIO address0x20 0x21; SlaverIO address0xA0 0xA1; s  t- a/ S; J+ J3 }
6 _; f* D% x4 T: S* \0 h8 S# f
PIC.jpg ! Y8 [7 G4 E; [1 `8 F0 I* `
4 Q7 M8 c$ O+ {, X1 b

# V8 u: \1 t1 f& _为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code
# [5 |5 ]3 r  M$ s0 u( x2 ^, u( X5 K% V* J- o$ V
MOV5 S; l0 q$ X5 C' \( [+ m: Q3 H6 i
AL,00010001b5 B0 }; T- U! w  t& L! i6 w: ^
;级联,边沿触发,需要写ICW45 K0 t  v) N8 t6 A  o+ i$ b
OUT
7 C: y# j4 k; W7 ]4 Y4 j* r20H,AL
: x1 @# ?5 X6 e;ICW1
6 A: l, ^8 v* x) q# `3 KMOV
& r1 ~2 @5 c$ \AL,01000000B ;中断类型号40H4 N+ c& ^: _5 ]
OUT
; e" {/ D; c' J21H,AL4 b+ }6 F* u: w5 W  T1 p+ w2 V2 |
;ICW29 C' T$ @0 N, P. D9 H# t+ C
MOV; Q& }' z: ~) P  r+ j% F% h# }$ i
AL,00000100B;主片的IR2引脚从片2 e0 `6 k' `% l8 s
OUT# ^5 R0 |# P& j1 M4 K. C' o
21H,AL
6 ~2 T) g; g% H, m;ICW3! B: l  R, Q' a: K
MOV
% e) w9 a" J0 J9 L: t' uAL,00010001B;特殊完全嵌套,非缓冲,自动结束6 P& C  ^8 t. N3 l) b: |' U9 L- q- v
OUT+ u7 [5 {$ B2 O+ a# J
21H,AL
, H% h% g. C9 h6 x6 t) S;ICW4: H6 _2 U4 u8 o' `+ p+ J5 ~

8 z/ L# P! B2 V, }  ^+ |3. APIC
$ F# Y" [+ N- D7 ?) `+ ^) ~( s; V& E0 s) N, G$ n5 \  U
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" U5 T: o/ q+ ^
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。, [+ t. Y, B4 j/ a- ?6 E' T

' c2 X- i4 c' S( f1 U/ [
4 b5 N" H8 @- a4 K0 h/ ] IOAPIC.jpg : L1 H2 }5 E  u; x

8 X+ U* n& E, x' f! ~# ZProgrammable Redirection Table详细格式如下所示:
; `2 H* R" J' D8 k6 _- j- N
! V4 S2 V4 [8 Y+ ~# k' `9 Y& p
Bit Description:
: U/ D( a7 R* }- ?5 D
[63:56] Destination Field—R/W.
5 H7 k, Z5 `$ H' aIf the Destination Mode of this entry is Physical Mode (bit 11=0), bits

* I/ ~8 N& f2 }  ?! M
[59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field3 a' l& O  `8 ?( i& K8 q# c
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical# u8 @0 `5 I6 L" e. l* S
destination address.
; d& u, m4 Q  Q6 }/ `Destination Mode IOREDTBLx[11] Logical Destination Address
0 K; U$ {: e2 z0, Physical Mode IOREDTBLx[59:56] = APIC ID
3 f$ A" N* J2 ?) e1, Logical Mode IOREDTBLx[63:56] = Set of processors
( F4 E) F/ S9 C8 J- O% R
[55:17] Reserved.82093AA (IOAPIC) $ R8 W9 F- q, ~3 g5 k: f. _& M
[16]/ F; ~! ~; q! G1 X! \+ {+ c0 u9 W
Interrupt Mask—R/W.9 a' i9 A3 _) p' g  h) o
When this bit is 1, the interrupt signal is masked. Edge-sensitive

$ ^1 N4 ?( _- N8 c+ jinterrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).  n  _9 t" O. V  B1 `0 E+ Y
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
% \1 m1 {% l# i4 h7 _5 b3 \side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by/ ^0 {# x8 T  l9 B
a local APIC has no effect on that interrupt. This behavior is identical to the case where the/ N6 d+ D) ?* r0 H& k, ^: k; [
device withdraws the interrupt before that interrupt is posted to the processor. It is software's2 z( u% G* {* {; i2 E3 t6 f! C1 M* E4 B6 b
responsibility to handle the case where the mask bit is set after the interrupt message has been. [# o4 t  d1 S* s" o" ]. x
accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this
3 @! H2 h" |$ Q% k6 E9 kbit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked( @" K; Q, ^  v6 Q- L% H) `: n, l
results in the delivery of the interrupt to the destination.( j3 n5 w  o6 l" a; h9 u
[15] Trigger Mode—R/W.
' ]- F; t8 q7 C) l( Y8 OThe trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
6 N$ V1 N8 T! u8 f
[14] Remote IRR—RO.
. ?4 T. X: f) }' J5 \, |! m+ QThis 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.

  x3 ~0 Y( i. o& a2 }5 }* F
[13] Interrupt Input Pin Polarity (INTPOL)—R/W.. S  ~3 e4 @+ O
This bit specifies the polarity of the interrupt
1 x0 S' X9 M. V! d; ~
signal. 0=High active, 1=Low active.
: j5 W2 k8 t# `( r' Y+ I
[12]$ o9 ~/ D3 M2 M3 r- z. J
Delivery Status (DELIVS)—RO.
: u0 T, i8 I% g* I! bThe Delivery Status bit contains the current status of the

# g3 H' V) J, q% N# T8 Zdelivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit
; ~3 Y* S, V2 ]/ `4 T. `word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send2 x. w* E# U# o7 r
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC& d, g$ h1 @+ x+ z2 f
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
4 K- C$ R; w/ G$ v9 l
[11] Destination Mode (DESTMOD)—R/W." H. f' O- m. Z- t
This field determines the interpretation of the

1 m$ T4 ~/ W* Y* V; eDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
% P/ }3 f" y  a% jBits 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.0 B* A3 N( l$ e1 e. f9 L& g6 p
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)4 Y: @( s/ [) h
[10:8]Delivery Mode (DELMOD)—R/W.1 r1 R8 y( i, ~% N+ u! z0 w( o
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
0 [$ Y3 X7 `7 I' H6 E
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.# N; o" s! w/ j  n' ]/ k# n
These restrictions are indicated in the following table for each Delivery Mode.
1 A1 U# {- |4 u5 |/ }! kMode Description
# t0 B; W2 K  w5 h3 Z9 p2 C000; L4 U8 q( p) J! h# H
Fixed Deliver the signal on the INTR signal of all processor cores listed in the
% V# l3 y9 [9 l% ?$ }- l
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.  W/ V- l( q+ N, G1 U8 H# L
001% X  T" B, d: ]& R6 N9 q
Lowest
+ D1 ~' U# V0 @4 |, x
Priority Deliver the signal on the INTR signal of the processor core that is/ B4 G( S' V9 d% _1 f9 L, L
executing at the lowest priority among all the processors listed in the
" F1 y9 C+ [9 r, t1 A5 `0 Gspecified destination. Trigger Mode for "lowest priority". Delivery Mode
& W3 ^  t# E6 E8 A! x$ }8 w8 ccan be edge or level.
1 X* x9 ^5 s  C010
9 M4 b; B4 C' k' u6 KSMI System Management Interrupt. A delivery mode equal to SMI requires an

7 V* K* l4 O" E  G# j1 s1 iedge trigger mode. The vector information is ignored but must be
; M# }5 f$ _# [9 vprogrammed to all zeroes for future compatibility.
: B% S4 g3 O; K$ f011
4 [/ ^- P- F8 H, s  v; [Reserved
2 a8 R$ s9 C3 H+ }5 o5 H
100% E+ ~$ R0 A3 w9 z  C
NMI Deliver the signal on the NMI signal of all processor cores listed in the
3 D4 C, w) f4 K' Z( x: n
destination. Vector information is ignored. NMI is treated as an edge
# W1 a7 U, a) U! c5 [1 utriggered interrupt, even if it is programmed as a level triggered interrupt.
  }# X1 U- d" Q' y. p# kFor proper operation, this redirection table entry must be programmed to3 _2 C- G' _: q& i% N! b. l% P
edge” triggered interrupt.6 E7 ^3 _2 S, g0 z- |3 t+ r! F8 r  \
101
( f) T3 r# L( V' M8 U$ hINIT Deliver the signal to all processor cores listed in the destination by
2 l: v( g' V' j5 _8 W
asserting the INIT signal. All addressed local APICs will assume their& r! Z4 l! S4 Q5 q) g
INIT state. INIT is always treated as an edge triggered interrupt, even if+ |$ [. D5 O1 U  r! Z1 }5 b9 r
programmed otherwise. For proper operation, this redirection table entry0 x* f; f4 B0 N. U; W$ ]: |( k
must be programmed to “edge” triggered interrupt.' _. i/ g8 v, n, B4 R* S
110
! G' L; J4 H  R0 t# dReserved

4 W6 |* M" g, B/ _0 ^2 V111
5 N( ^! b! I* [/ z3 HExtINT Deliver the signal to the INTR signal of all processor cores listed in the

+ d) n% J. |# w$ ydestination as an interrupt that originated in an externally connected! f1 ~! O: x, w/ J5 l0 V
(8259A-compatible) interrupt controller. The INTA cycle that corresponds8 l, X. p6 j- T- G, h
to this ExtINT delivery is routed to the external controller that is expected' z3 O) Y2 D$ d
to supply the vector. A Delivery Mode of "ExtINT"
7 _1 b+ a0 r# V& E% G6 U0 Q) drequires an edge

5 b# S, D. G: B6 mtrigger mode.
& O( g: N( u/ b  V
[7:0] Interrupt Vector (INTVEC)—R/W:. ]7 M: f) ?& p' _& B; u2 R
The vector field is an 8 bit field containing the interrupt

! W9 G% M8 M; D  zvector for this interrupt. Vector values range from 10h to FEh.7 U, b8 D: y6 C* k4 I5 {# d  p- F
+ ]- i& a* m) h. Q
REFF:
2 ?/ R+ q1 M  M0 D: w1 N% ]4 x" m9 C3 M2 t9 r0 y
1.7 ^* `" d. t; M4 H! G
82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)
3 w+ j" c9 P3 H2 H8 ]6 f  ]6 F+ o2.% o9 d$ J$ s" w( O
8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)
9 d5 k) a- N- |3.
% d8 U& E: ]  m7 w/ F1 `  `Undocumented PC
$ I0 M. Z3 L9 e1 b& i6 i4.( R6 ^9 y7 A3 w* Q" K( a2 E
& p. F# W% n6 N8 [" E% v2 h/ x/ L
8259A初始化编程
' d* B" T- U! h7 h
- L: k8 k; o! ]6 qThat’s all!
) A( \% j3 e9 ]" k1 w( Y2 ~3 \% t6 x8 I
Peter
4 v# E: F, @( @7 M! x8 F! Q' Y9 }
9 H" `* A% T) h/ Z. ~) P2010/10/07
) A$ u* m! Z9 u, s8 v: y& q/ R; H
' m# N5 w: b$ }! U[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ]
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

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

GMT+8, 2026-8-11 16:06 , Processed in 0.052193 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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