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

PIC 、APIC(IOAPIC LAPIC)

[复制链接]
发表于 2010-10-29 16:11:58 | 显示全部楼层 |阅读模式
PIC APIC(IOAPIC LAPIC)
9 _% C* m  C* ~: y. h7 ?
1. Overview; @. \0 X" g  I; e' @" g
- a  @" R* U9 [9 s, }
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt ControllerAPIC是为了多核平台而设计的。它由两个部分组成IOAPICLAPIC,其中IOAPIC通常位于南桥中6 w; V" z6 M$ t$ u( a+ q
用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPULAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pendingnestingmasking,以及IOAPICLocal CPU的交互处理。
3 Q- x) C" A% J% _" ]6 t9 i0 \$ P
) n- T, |4 k, H- O  |8 r3 V6 o) z6 H) ~
2. PIC. J4 ^* Z3 a) C/ S

4 W* S% b- i( b6 ]* c* A基于Intel 80x86PC使用两片8259A级联的方式组成了可以管理15级中断向量的一个中断系统,下图是它的一个连接示意图。两片8259A,一片为Master,另一片为Slaver。其中SlaverINT接到MasterIRQ2上。8259A有两种工作模式分别为编程和操作模式。BIOS初始化的时候会先通过IO port8259A进行编程配置,在此之后8259A就可以响应来自外部设备的中断请求了。MasterIO address0x20 0x21; SlaverIO address0xA0 0xA1
" l. K. \' ?/ z. r1 C1 |  C4 f) J% _" P* N) b
PIC.jpg % F8 I2 m  _4 N) x- ^/ F: U

3 [' w3 r; o% A3 o& Y3 A0 f1 @' m4 X* c
为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code
' A% R  k; c/ w0 R2 g# q. O# Z3 g# n
MOV+ ]( P, ~; V0 U1 }
AL,00010001b
' x( K5 B/ p5 O. {1 @# O;级联,边沿触发,需要写ICW4
; y% F! _. _; y% @4 V) \4 O& B; cOUT
4 }* T/ ~* ^4 ^  S, B! x/ d20H,AL- ?6 F- O8 j0 C* ]( O' e
;ICW1
0 w3 m4 h( e- ~MOV3 K4 g/ p. [, ]$ t. q/ f9 Q, R
AL,01000000B ;中断类型号40H
% ?- u9 J- y7 s% q! K8 qOUT
) |& w8 a/ `) y- n2 d: K21H,AL
" p8 Q' L4 s. M: M0 K* q7 U7 s- K- R;ICW2
5 Q; O( z5 k3 ~* {6 aMOV  M6 r7 \8 E- q( A+ F
AL,00000100B;主片的IR2引脚从片
6 C3 J( t" v( r7 E: D% ^OUT; r1 C; a/ ]' L# h; k1 [2 o9 L0 P
21H,AL
; J1 N" v8 P& B% t! C;ICW3" ^- y/ S) a: A6 a
MOV
5 z0 A3 u' L0 W: R3 ]( lAL,00010001B;特殊完全嵌套,非缓冲,自动结束
* V/ j" v7 v7 w/ lOUT
' E' d. J' v5 V6 W1 \. U21H,AL" O( [' d" s0 M# I4 e2 Z0 ]
;ICW4
1 {1 A; L: T: z4 a5 u! M) X6 }3 z/ [! u
3. APIC
, z  d) I5 A" u, a  [- B
; y( y; t7 `# a# U+ B% J# kIntel 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 pin9 s. J: `3 g. b8 h
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
: H' e8 {5 l: f! ?, U$ Z' D# X3 n0 F3 v$ v0 C" p
; u. [& t. P7 [  t6 a7 @
IOAPIC.jpg 0 Y( L, r# G5 |& U

! @0 c( E; ]& LProgrammable Redirection Table详细格式如下所示:
) s  z# ]  J3 D- E# @' R2 ?7 ~% d* O. r% B" C1 [* ]; r
Bit Description:7 v: U+ v3 y  C3 t4 y/ l7 Z
[63:56] Destination Field—R/W.
2 A! G  E) S) E) _9 TIf the Destination Mode of this entry is Physical Mode (bit 11=0), bits

0 v" J. X; h' M* k- a* D
[59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field) k% y1 S, B# C+ ^  @6 e$ a) B
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
/ Y5 N1 P% E( m3 U3 x3 cdestination address.' Q: Y* \4 q8 }) S! D: r
Destination Mode IOREDTBLx[11] Logical Destination Address
! I% S# \8 R3 [9 s! t1 w0, Physical Mode IOREDTBLx[59:56] = APIC ID& S! y1 n4 A: y7 E
1, Logical Mode IOREDTBLx[63:56] = Set of processors) r0 ^* J2 Q9 ~) ]" n; L  G; V
[55:17] Reserved.82093AA (IOAPIC)   ^" ^# a. K. _0 G3 ^1 `  q
[16]
$ n$ ?  W" {; _3 F6 x9 ?. ^7 LInterrupt Mask—R/W., `0 \9 \9 r; `. i  J! z
When this bit is 1, the interrupt signal is masked. Edge-sensitive

+ B2 V! g* K* A1 m( a+ Winterrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).& D1 a; G4 G+ t4 u" p* a7 Y
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no, `0 m. k: B- h! ~7 r
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
" D' N6 @9 ^% p! E+ ha local APIC has no effect on that interrupt. This behavior is identical to the case where the* |- X. o- O2 D5 q4 A" g" I
device withdraws the interrupt before that interrupt is posted to the processor. It is software's
  d3 }3 F  t5 q" |! presponsibility to handle the case where the mask bit is set after the interrupt message has been
; d) g6 |3 r, _accepted by a local APIC unit but before the interrupt is dispensed to the processor. When this
7 e0 u3 J+ M9 L+ l- k' o. `bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked* R( _( W: c8 v" g+ J7 d" [7 |8 C2 Q) @
results in the delivery of the interrupt to the destination.- B% p2 y( M! x$ q" b7 D* {- e
[15] Trigger Mode—R/W.
% \- ]6 o7 R: d9 B# X8 F8 R+ e; fThe trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.

8 S9 N7 s: `/ N) {! d) j
[14] Remote IRR—RO.
; p2 r2 x5 M% e7 G! TThis 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.

, d0 ~6 W. m5 n. A$ B( y
[13] Interrupt Input Pin Polarity (INTPOL)—R/W.1 X! c3 {  S8 N$ {
This bit specifies the polarity of the interrupt

( ^. F) {7 p  e3 nsignal. 0=High active, 1=Low active.
; x4 n- n2 l3 K, n
[12]) o+ ?, i8 M# Q" U- I
Delivery Status (DELIVS)—RO.
9 {' T) B% C0 Y; k0 b+ aThe Delivery Status bit contains the current status of the

% Z8 n9 f( P) g  @delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit! J2 x: p# c, J9 S; W& s( |
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send; h, i- P# @' p$ [* s% o
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC, S& Z9 M' k$ f
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
. h6 M& e# G+ w& q9 A6 _
[11] Destination Mode (DESTMOD)—R/W.' U: |' V4 F  _3 f/ L
This field determines the interpretation of the

/ O% _/ _9 [( `- Q- p# J  w  R/ BDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.* H  r- ^0 i# s( a% h, j
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.
' J, c. a5 R1 H9 Y) vDestination 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" I4 @- `, k" p* Z, e2 d* @
[10:8]Delivery Mode (DELMOD)—R/W.9 S8 F* N! V) B! 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
, W$ E  O  x. B7 x/ O8 i. c
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
6 X  E7 Y9 {, \  R) MThese restrictions are indicated in the following table for each Delivery Mode.3 ?: f* A; J7 v7 e
Mode Description
- ^+ W$ ]& `9 i& j6 R0 ^3 [* ~$ o000
; M) \( O  E' ~0 q: {Fixed Deliver the signal on the INTR signal of all processor cores listed in the
; N7 X4 c5 S: @1 q3 {
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
- a$ j" k' j0 `: n2 G8 a001
) N% w9 O2 y. Q% d+ OLowest

. U2 X1 U# h) |  G( V3 OPriority Deliver the signal on the INTR signal of the processor core that is
. w2 J8 M+ @5 Q5 S# Texecuting at the lowest priority among all the processors listed in the$ @9 o" r' D2 Z. Y9 t' P' R
specified destination. Trigger Mode for "lowest priority". Delivery Mode, ^2 O& q; U+ w1 S( E% D
can be edge or level.1 H; L* _# \1 j1 V/ l9 Y- m
010
5 h9 O+ W& L5 h0 n+ g( [SMI System Management Interrupt. A delivery mode equal to SMI requires an
  K# P5 ]0 G- u/ }$ n0 u- m
edge trigger mode. The vector information is ignored but must be
# a+ ]4 j! \" I3 yprogrammed to all zeroes for future compatibility.
- s3 j- p' C$ ~/ J$ S% L; Q/ I/ N011, q* ]6 t, ?. P+ n- j$ z- s
Reserved

7 G2 \. }* j6 q$ ~6 |100' J  y6 I. l1 {0 z
NMI Deliver the signal on the NMI signal of all processor cores listed in the

! c' l+ y: v5 n  F2 g0 [* ydestination. Vector information is ignored. NMI is treated as an edge7 J  X5 d( S* {
triggered interrupt, even if it is programmed as a level triggered interrupt.
7 J6 N8 w7 @5 {3 zFor proper operation, this redirection table entry must be programmed to
4 p: a4 N  ?! G4 C" uedge” triggered interrupt.; P/ V$ f: v- U6 r( G, F( G; Y5 w* g
101$ q: Y/ z' }* f+ @. F  t" H
INIT Deliver the signal to all processor cores listed in the destination by
$ L7 C+ `+ W9 p1 Z; }- o: z( J5 e) i
asserting the INIT signal. All addressed local APICs will assume their5 g$ ?, D% a  m; ~! C* b8 ^! j
INIT state. INIT is always treated as an edge triggered interrupt, even if/ {3 l6 Z" ~, D9 B+ K. d" K
programmed otherwise. For proper operation, this redirection table entry# ?# z) j4 l; |6 @
must be programmed to “edge” triggered interrupt.
" h6 l; C6 }7 Z- i: d. g110$ E' f/ }( y" h1 e8 n: d
Reserved
# ]7 h7 D6 E8 M  j0 {
111$ p! _5 x1 b0 @6 o
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the
2 [0 i) }) L* |0 x
destination as an interrupt that originated in an externally connected+ b% H' P1 J; i: Z5 v
(8259A-compatible) interrupt controller. The INTA cycle that corresponds8 `8 J% H; T5 L; t4 w, n# G; z2 l
to this ExtINT delivery is routed to the external controller that is expected0 |. {* }0 ]3 K3 @" {
to supply the vector. A Delivery Mode of "ExtINT"" S4 J! b+ p# P% N8 q8 v
requires an edge
# Q: I6 x$ P; T+ ~8 B" @, ~
trigger mode.
# m# }& f) U: L* X! B( U
[7:0] Interrupt Vector (INTVEC)—R/W:
4 r6 v5 o( ?" H% Y# p. g0 eThe vector field is an 8 bit field containing the interrupt
0 d$ f3 ]+ f9 w$ f
vector for this interrupt. Vector values range from 10h to FEh.
( w( p( [3 x5 x1 q$ q. m$ V- M

! K# a, P, j9 K) _REFF:
* H7 t) Z+ }: b1 ^7 Z3 ]5 E8 A' E+ U8 i! d' |: A
1.
" V( x3 w4 \# Q82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)
+ A6 U7 j% i( |* o2.+ _: u$ {4 R8 [3 z" ~
8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2), Q% y  ]6 N" C( p: L# M: i
3.
% [. y6 i/ l# }( VUndocumented PC% {3 X/ C6 \+ s8 P. J
4.& e+ D! o/ v8 i0 T8 n7 ]
, Q- {. N9 P  C: I
8259A初始化编程
" N& J# w6 `3 c, q! H: A- D* X5 f8 l, Z$ o& [
That’s all!5 p/ U6 i) Q( z# z0 V6 G- e
+ z- k% K0 N7 X  k7 \! q: G
Peter
! {' c/ D3 }  G% \' a
- U# E7 \  c0 i& x2010/10/07
% J8 h. S+ I  X) R+ k8 x7 W( \2 l' a4 z% I* L1 Q
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ]
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

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

GMT+8, 2026-5-25 19:15 , Processed in 0.077290 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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