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

PIC 、APIC(IOAPIC LAPIC)

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

2 c, l0 O4 s  K  n4 W2 x0 T1. Overview$ t7 t) k; n- O
( v3 q& y9 L. ~0 V/ G. d' i
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt ControllerAPIC是为了多核平台而设计的。它由两个部分组成IOAPICLAPIC,其中IOAPIC通常位于南桥中
4 _' `# c# s( X' V) B用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPULAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pendingnestingmasking,以及IOAPICLocal CPU的交互处理。  O6 ?/ L6 u% _  }
! E2 B7 k! N. o8 b7 l

+ f7 `, S4 N9 R' W' f' U3 |2. PIC' F5 t& I, m3 R: q9 X

4 J! Y, S0 G$ d基于Intel 80x86PC使用两片8259A级联的方式组成了可以管理15级中断向量的一个中断系统,下图是它的一个连接示意图。两片8259A,一片为Master,另一片为Slaver。其中SlaverINT接到MasterIRQ2上。8259A有两种工作模式分别为编程和操作模式。BIOS初始化的时候会先通过IO port8259A进行编程配置,在此之后8259A就可以响应来自外部设备的中断请求了。MasterIO address0x20 0x21; SlaverIO address0xA0 0xA1
2 L/ ~+ M/ |6 [9 A# }5 W  o8 U) L! o. z; j# s7 j: S5 @
PIC.jpg # E: X9 {$ @7 H; k

0 q- n0 R$ a) e7 S" Y, \# `* B( |5 d/ I5 k9 C2 @# k
为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code' q5 ?7 J5 B8 a' s2 m3 J

# v' D1 o; o& U; g' x; s0 y7 KMOV
5 T3 o7 A% p0 t+ R; `7 U. B, F3 S. ~2 sAL,00010001b5 y& m- x1 U2 u8 R* a2 u
;级联,边沿触发,需要写ICW4" ]5 b! o6 k; L# J$ ]' t( o9 V
OUT
& |. z+ F- \) |: m# |20H,AL
8 l+ j5 l  I! S4 q4 M/ A- q;ICW1
2 I; M9 B- ?: C, p- H7 D! W: z7 S4 n& h  UMOV
' _1 M2 r$ A& Q) R6 W0 h6 `8 C& T, UAL,01000000B ;中断类型号40H
5 a6 V) U0 G( ^( M, jOUT
4 c3 Q% k; R+ _  g/ t' |21H,AL! B" e5 b9 F8 T3 C3 U/ T
;ICW26 i+ a2 w, o  t& S! V
MOV
# g: H: s0 {# x* |& b0 _AL,00000100B;主片的IR2引脚从片1 |1 n+ `5 }( k0 n
OUT
% H2 x& V0 z. r% I/ ~3 I3 p21H,AL
. C9 J2 m6 f+ \4 e% |;ICW3- ]1 V  ]% h  W  t9 w) f, T! ?2 T* m
MOV+ X  m2 A) O/ m9 a  W
AL,00010001B;特殊完全嵌套,非缓冲,自动结束6 D0 w7 f: l8 K
OUT
9 ^& M3 @- D) ~& u, r8 @21H,AL
- P8 c3 j, u0 x;ICW4; Z7 a7 [/ [& m5 h0 W  F

3 C6 J/ n! `3 k8 G. m) T3. APIC/ ^! @% X# b( y: z3 }

. e, q: }, P, g' T* C& tIntel 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 pin7 I3 p& t$ t* g) i+ S3 G
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
) o  q3 @" O' h+ ]" `+ }: b( F* H8 O* D8 {9 Y) y4 H' o
* S0 I$ [2 Y& A7 D) R( e
IOAPIC.jpg   V8 M9 q5 u  c6 a" Q1 P* Y" f

( _& }3 f  B  O# ~+ i9 f4 l) GProgrammable Redirection Table详细格式如下所示:
. W) Y! Z0 Q! @3 U* D( m) C- B" B6 e' N1 O
Bit Description:! m' _9 V2 t/ K5 }" J
[63:56] Destination Field—R/W.
) S5 k; }( Z3 [2 D* }, W% K8 ]9 CIf the Destination Mode of this entry is Physical Mode (bit 11=0), bits
/ v3 q; y# Y4 _9 v6 r2 A9 H8 Q
[59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field
9 {. V- t) R8 Jpotentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
; ^; n& O  X7 C' edestination address.# E# V7 [9 A9 c
Destination Mode IOREDTBLx[11] Logical Destination Address
% V9 M4 j! Q- y# m, b8 p0, Physical Mode IOREDTBLx[59:56] = APIC ID5 N0 U. T* N( Z) V# Y, h6 C
1, Logical Mode IOREDTBLx[63:56] = Set of processors
5 N4 `& [( Z' [, Q
[55:17] Reserved.82093AA (IOAPIC)
6 o5 v2 j3 i/ |) E
[16]
1 P0 U, d+ f- N2 ZInterrupt Mask—R/W.
* Q" E7 W$ Q) i3 X+ y6 nWhen this bit is 1, the interrupt signal is masked. Edge-sensitive

& Q) t8 G* D, v0 ^  |* Winterrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
1 _3 R9 p: Z; `) \$ e. a' NLevel-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no* g9 g7 m4 y; u$ `6 e, r
side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
+ @- f0 a3 O8 k) r' t4 [a local APIC has no effect on that interrupt. This behavior is identical to the case where the
3 k* Q, ^* ]; y* Qdevice withdraws the interrupt before that interrupt is posted to the processor. It is software's
$ P/ b4 \" P1 {5 A2 z; n$ Bresponsibility to handle the case where the mask bit is set after the interrupt message has been
5 s$ |+ N! P" G- taccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this
/ K7 U1 W* m# V7 i7 qbit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked, I% j4 ~( ]- d
results in the delivery of the interrupt to the destination.2 g7 b+ L/ Z8 X2 o/ R
[15] Trigger Mode—R/W.) x! o* v8 `0 o. Y& y
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
6 q# R; {4 i& f6 @" f8 A+ q3 Z
[14] Remote IRR—RO.
: \: _6 i' h( p, C& M# p3 I1 yThis 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.

/ I9 l/ I1 h# q9 v, O6 Q
[13] Interrupt Input Pin Polarity (INTPOL)—R/W.
6 k$ m  ~& S7 [4 ^& W5 |  zThis bit specifies the polarity of the interrupt

$ e2 d; X1 q  f0 R) gsignal. 0=High active, 1=Low active.
8 e6 x- t: z, r6 l
[12]
6 z- X$ `0 o$ V5 }& r# cDelivery Status (DELIVS)—RO.- W; w% v2 o8 N5 ]  `8 I
The Delivery Status bit contains the current status of the

7 i! x. U- H; n9 Y5 p; a9 \- qdelivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit- t: v( E7 }: E4 l
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
4 p, l4 s; {! _% T4 K5 Z; nPending (the interrupt has been injected but its delivery is temporarily held up due to the APIC$ ]$ o% l, N$ |
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
" B. ~5 s1 R' ?6 H9 B2 T
[11] Destination Mode (DESTMOD)—R/W.2 ]. i' ~+ f) _( U" \/ `& l  A
This field determines the interpretation of the

# y( r1 z  r4 {5 k- j" ]; k# C, g+ wDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
" `2 d' y5 r" g9 V# QBits 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 p1 m! n0 p! ~9 S5 K* r; \7 Z9 sDestination Mode IOREDTBLx[11] Logical Destination Address 0, Physical Mode IOREDTBLx[59:56] = APIC ID1, Logical Mode IOREDTBLx[63:56] = Set of processorsE 82093AA (IOAPIC)
) B$ S0 O, }- |8 Q
[10:8]Delivery Mode (DELMOD)—R/W.
6 `& x% o9 W. ]. P, ^: qThe 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

2 Z( w3 z  O: ]" ~6 ]Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
7 c3 z: q6 i$ Y: aThese restrictions are indicated in the following table for each Delivery Mode.
/ Q7 \* z; s& y2 [Mode Description
: c* H% q: X: s9 h; q" d: _000, [# g) Q' ~2 D6 {0 A/ p3 y
Fixed Deliver the signal on the INTR signal of all processor cores listed in the

% e: Z6 [7 M6 p6 Ndestination. Trigger Mode for "fixed" Delivery Mode can be edge or level.+ f" {% g9 t1 g4 n. P4 U: h6 ]9 M
001
; e: f0 l4 c: n. PLowest
3 V4 V0 j0 v8 Z$ u
Priority Deliver the signal on the INTR signal of the processor core that is% H7 I6 y; w% |: a# j( K1 b
executing at the lowest priority among all the processors listed in the
2 \* ~0 B* e) pspecified destination. Trigger Mode for "lowest priority". Delivery Mode" V) X* \5 p& E. f5 ?
can be edge or level.0 }; n- C1 U9 |0 |4 ^# t7 s* I
010
9 I+ p& w; G- S9 X. k5 {! XSMI System Management Interrupt. A delivery mode equal to SMI requires an

9 b% a3 D/ w, x4 P' ?! `' ^edge trigger mode. The vector information is ignored but must be9 o2 b0 a7 L' P7 _
programmed to all zeroes for future compatibility.
4 @5 U" {' U, [, Z011
6 [" n$ S9 k: o' z0 {' [Reserved
6 M# Z- [3 e  l5 l! C$ h" m1 K" {
100
# K, L  r7 c2 M1 e- RNMI Deliver the signal on the NMI signal of all processor cores listed in the
! C1 M9 _# F5 R+ O& e! ^
destination. Vector information is ignored. NMI is treated as an edge
$ P& b) x/ q7 Z# U  g: v/ Z0 @triggered interrupt, even if it is programmed as a level triggered interrupt.
/ N2 _. e4 }" s% y6 [& o" s% @7 WFor proper operation, this redirection table entry must be programmed to, H# x" h# g1 M! B7 z
edge” triggered interrupt.
- q! |- G0 |8 W101
7 A% l6 X2 X  FINIT Deliver the signal to all processor cores listed in the destination by
  z& q& B# W5 h0 P& t$ V/ l* c
asserting the INIT signal. All addressed local APICs will assume their
9 w6 Z  E5 T- e" yINIT state. INIT is always treated as an edge triggered interrupt, even if: v; V* o' t/ m2 f" {  `
programmed otherwise. For proper operation, this redirection table entry
' l7 m0 K/ X1 W& O7 Lmust be programmed to “edge” triggered interrupt.
2 b6 s& S! V0 V& l5 ~# e1109 c+ X2 C8 {6 O) m+ M
Reserved

" q0 I1 _- a% \+ l7 k% B111, `! t! g; x# S, o+ R' f
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the
; i: [. Z  |- X8 P6 l3 m0 u
destination as an interrupt that originated in an externally connected
' M9 V8 ^% o6 H# ^0 y6 g(8259A-compatible) interrupt controller. The INTA cycle that corresponds% b" }/ y1 |$ w: z9 D5 z9 q
to this ExtINT delivery is routed to the external controller that is expected
7 K- T1 Y( x; g0 Ato supply the vector. A Delivery Mode of "ExtINT"' ~9 B; C( n4 C8 Y4 \9 U$ o: U/ R
requires an edge

% B; P. A1 f8 @- t9 _. itrigger mode.
8 f+ a6 ]& Z" w) c5 h. H
[7:0] Interrupt Vector (INTVEC)—R/W:
0 H) r+ z" u7 H  z- Q* ~0 fThe vector field is an 8 bit field containing the interrupt

- J! k- x8 x3 z6 Xvector for this interrupt. Vector values range from 10h to FEh.
0 u% z, X% d2 T( P  V0 a4 t
! Y5 \( I- O6 b; f! h
REFF:( l1 u9 P  d3 ]+ l" Q

: H; M6 I, p' [# c+ P1.
* G( a4 C! P. T$ l# W82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)
, e% F  Z* N  M! y% p5 e* ~: |. a2.
( ], a2 W- B6 D8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)8 N3 K& N5 K0 c5 ]) }3 d9 q
3.: g6 Q9 U3 P* t: @7 S* G
Undocumented PC
/ O, K! `! W. j0 M* w4.
) \. p, q2 ^3 i) O2 @0 x- B) \; i/ Q: f0 K
8259A初始化编程7 d/ d1 I3 [) _  B& [' H

: P3 {6 R) U' b% LThat’s all!$ c6 e0 Y8 L/ p: Y* U# \* K( d
7 Z( P# b8 H- F1 t$ d% p& B8 x
Peter
3 _0 L5 T/ O0 J4 `8 b( u& L
6 T) C3 y6 C1 o2 @0 P3 G9 W2010/10/07
% P6 y$ @( `$ m  ]& p. H, l. a6 U: d5 s7 k, B  q5 M5 O. ~- `
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ]
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

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

GMT+8, 2024-5-15 13:01 , Processed in 0.040177 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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