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

PIC 、APIC(IOAPIC LAPIC)

[复制链接]
发表于 2010-10-29 16:11:58 | 显示全部楼层 |阅读模式
PIC APIC(IOAPIC LAPIC)
, g: B" c# l2 p$ o5 k2 n9 l; K( r
1. Overview0 m. R' K0 i% @2 X2 h/ {% ^2 }

1 G* O. \4 m4 _& tPIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt ControllerAPIC是为了多核平台而设计的。它由两个部分组成IOAPICLAPIC,其中IOAPIC通常位于南桥中8 X1 u  v% A1 ]1 k4 E
用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPULAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pendingnestingmasking,以及IOAPICLocal CPU的交互处理。8 o- w% m& e4 _8 g7 _) X0 L7 s
, J- N6 S" u5 }1 M
! i4 e6 l( u/ _: e% u( d4 t+ t
2. PIC& A3 c" m- S/ ?9 V8 H5 q

- i; \  @, z. Z基于Intel 80x86PC使用两片8259A级联的方式组成了可以管理15级中断向量的一个中断系统,下图是它的一个连接示意图。两片8259A,一片为Master,另一片为Slaver。其中SlaverINT接到MasterIRQ2上。8259A有两种工作模式分别为编程和操作模式。BIOS初始化的时候会先通过IO port8259A进行编程配置,在此之后8259A就可以响应来自外部设备的中断请求了。MasterIO address0x20 0x21; SlaverIO address0xA0 0xA10 Q6 Z$ o6 Q  j0 @* y/ m, `
" d# w% z) E- B  E# a' T0 k
PIC.jpg ; Q5 E, |1 y& M; O1 ?/ ]

4 v7 _; s* g3 x# g, _& Y& r! C4 `
( _* N+ N" G( ]% _1 y. p# }为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code
( F& `4 a' d8 D% E" Y/ D' J" p) u* m2 B
MOV+ i& u& R% z1 R( I1 P
AL,00010001b, u% |! v3 `5 j/ V, [4 U8 u
;级联,边沿触发,需要写ICW4
% t4 g# u" n. S. IOUT# e. K: j) ?  E- K: l7 ]  x
20H,AL  A4 B  D7 _2 z9 N  n4 w6 p7 D" H
;ICW1
. V6 T6 b+ ?' q$ c3 m% N% qMOV
) \- v, T2 u$ c* }8 H' FAL,01000000B ;中断类型号40H( ?# k# M4 Z, g9 {* F2 ]
OUT
( [/ g6 M1 R* b. d* e0 A8 l21H,AL
) Z1 Y9 V) }* m( c) e;ICW2) y( R% E8 y" o2 Z# p' q
MOV
. f2 a0 P( A0 A, SAL,00000100B;主片的IR2引脚从片
4 q2 X$ ~( P4 FOUT
8 G/ n, i* N( K2 l- h) v21H,AL5 ~; s% q' O" ~; G
;ICW34 ]6 r0 ^( T$ J- A* r  q
MOV
2 \0 H) R( V2 q/ w. ]8 vAL,00010001B;特殊完全嵌套,非缓冲,自动结束" H( ?5 i  G2 z  V! ?+ f
OUT
7 m) M+ l% @0 [21H,AL
# `, R/ A# V( H+ B* [;ICW4
& E: R' D5 S. D9 y% f" t2 o4 `  A$ L5 w* N3 J7 N. U
3. APIC
1 ]' M7 z: i/ o% w( v
6 S' N( k! ?$ F- C" S+ oIntel 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
* X" j+ Z7 O' a每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
! }* ^% R3 X# V* C
& [+ z; {9 c9 p& W3 I5 L* H. p* d4 r
IOAPIC.jpg 1 L' q7 q$ \. R: {! p

3 X0 `  q+ _* Z7 ZProgrammable Redirection Table详细格式如下所示:
7 Y& j8 y# n4 z9 T+ i
  \! U8 M/ @3 B; {* @
Bit Description:
" G3 p) ]" L( S) e- _
[63:56] Destination Field—R/W.7 P$ H* {0 Q; P) E# O: ~+ X$ {
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits
% }4 U* S' c/ |1 x- S# |
[59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field; o1 o0 \, a6 |$ N/ M
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical( ], m4 c7 O( J# e9 j; I$ |; B
destination address.: l+ k6 {0 P4 p& R( R5 {
Destination Mode IOREDTBLx[11] Logical Destination Address; k: d# p7 {2 |4 ^! k) z4 h- [
0, Physical Mode IOREDTBLx[59:56] = APIC ID
* ~. P6 o$ y% B( q! l* G) o# _0 w1, Logical Mode IOREDTBLx[63:56] = Set of processors
* u- I# J" L4 z1 z+ J
[55:17] Reserved.82093AA (IOAPIC) ! Y! ?! w7 r7 r+ j) l+ v6 ^2 Y
[16]
: F" x$ f; O+ e# C9 sInterrupt Mask—R/W.' g, l9 |- Y$ q* I2 i0 u
When this bit is 1, the interrupt signal is masked. Edge-sensitive
7 g8 Q$ r9 X: H6 S: O& d$ g- s
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
) o* T  d! _; O+ E- ^Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
5 ~) B4 ~' {6 D; g4 A* oside effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
2 C4 B  A) y; b9 Ra local APIC has no effect on that interrupt. This behavior is identical to the case where the
- E4 i7 Z: `4 P, T7 ?# Q4 Y6 }0 pdevice withdraws the interrupt before that interrupt is posted to the processor. It is software's
& n" s! {& G7 ?3 a2 `- K' u6 U3 M; @responsibility to handle the case where the mask bit is set after the interrupt message has been
& A+ m/ ?2 ]' I" l0 ~$ ^& Jaccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this
# ]. ?8 L3 R" h, I# ubit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
/ ?4 F3 h( l$ T1 d( S: [/ h- p1 vresults in the delivery of the interrupt to the destination., j1 X1 B+ ^1 ~9 T3 g. F
[15] Trigger Mode—R/W.- M2 z* ^" ~; h2 D4 h
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
1 e" K/ V& L0 N2 `
[14] Remote IRR—RO.
3 M6 F5 p* D% c  S9 _# p. E2 dThis 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 m( \4 b4 w/ D5 V
[13] Interrupt Input Pin Polarity (INTPOL)—R/W.! R  }) e: W; u/ \6 |
This bit specifies the polarity of the interrupt

; r0 U7 d! {9 ?8 Vsignal. 0=High active, 1=Low active.6 h4 \* B3 m& [0 C6 F5 m' n
[12]2 N, _/ S0 p, n: }
Delivery Status (DELIVS)—RO.3 s2 t# j! p4 _- {
The Delivery Status bit contains the current status of the

: X3 c. m6 S. W& h+ a, F4 ]6 s3 Mdelivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit
, W7 q$ o8 [# Pword) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send9 i8 I( q8 Y3 w+ N0 C6 x7 [) }4 q$ C
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC$ s1 d& \2 G5 u# D3 ~2 k
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).2 B3 Y! c( g$ L: Q1 h
[11] Destination Mode (DESTMOD)—R/W.2 \( K: x0 {0 Z5 f! q6 s: {2 o
This field determines the interpretation of the
. p( C' x- h1 K3 e, N4 }
Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.* H4 O8 e& h  ~9 f
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.
0 L. W* d6 A, J4 ~0 FDestination Mode IOREDTBLx[11] Logical Destination Address 0, Physical Mode IOREDTBLx[59:56] = APIC ID1, Logical Mode IOREDTBLx[63:56] = Set of processorsE 82093AA (IOAPIC)6 ~9 [0 {8 i# B+ A
[10:8]Delivery Mode (DELMOD)—R/W.& k$ I7 k3 w  i* J8 m8 I$ J
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
5 H. U$ B3 p! S) c4 {
Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
; X/ ^& e* a- e% O3 U  w- [These restrictions are indicated in the following table for each Delivery Mode.: c$ x9 x6 C, X$ v+ _) i
Mode Description
! x& [6 S, E2 e) D. {- u000
  s' `$ a4 [/ g5 y" a/ v5 i8 DFixed Deliver the signal on the INTR signal of all processor cores listed in the
) j% z" F# B) W
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
% T/ b$ }6 Y1 V; i2 l001/ H! Y' M5 e4 v% N
Lowest

- B7 O& J- @0 s9 k6 FPriority Deliver the signal on the INTR signal of the processor core that is: k, }) u/ b1 I# ~6 @5 n) d2 z
executing at the lowest priority among all the processors listed in the
; @$ Z& v$ |4 z  v) Fspecified destination. Trigger Mode for "lowest priority". Delivery Mode4 q2 {; S1 t# S. S5 U
can be edge or level.% W9 k6 j1 Q+ [& r/ G- ~/ M
010, p: F6 G" K1 e- R# P! z
SMI System Management Interrupt. A delivery mode equal to SMI requires an
+ O  _5 y; F; S/ [6 J
edge trigger mode. The vector information is ignored but must be% a' W& [: I4 n& Q
programmed to all zeroes for future compatibility.
, ?$ h. @8 {9 v* ^011: L7 x5 E, G" ?/ G
Reserved

1 k( e5 {/ J! ~- I( {% X100
9 {1 x8 l4 l/ Z' Z; R* p- z( MNMI Deliver the signal on the NMI signal of all processor cores listed in the

" t" Q- c0 `( u4 r, f% V8 ]destination. Vector information is ignored. NMI is treated as an edge
! t# D8 @" l9 Ftriggered interrupt, even if it is programmed as a level triggered interrupt.
- c& K( N6 x& j) Y: ~For proper operation, this redirection table entry must be programmed to4 R3 M6 b2 p6 R, `: _; W
edge” triggered interrupt.
' x/ `, g. M# v( [. t2 B( W' ^101
( z8 X9 h4 r0 {0 PINIT Deliver the signal to all processor cores listed in the destination by

( X: x  R; l6 Easserting the INIT signal. All addressed local APICs will assume their# s3 r( R8 Y" ~2 }4 r) w9 K
INIT state. INIT is always treated as an edge triggered interrupt, even if5 u9 T# ]  p7 ?& Z
programmed otherwise. For proper operation, this redirection table entry% \7 G* W  y6 M4 ]8 e4 l* v0 @
must be programmed to “edge” triggered interrupt.
2 S# d1 [- @* i8 W) ]110% h. ~5 j7 R5 J+ W1 ^) ]
Reserved

/ K& d5 N3 d6 F* t. F- D111) h. x; R$ H, t! W0 X; @7 J
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the

3 \( J! ]1 U) C$ \destination as an interrupt that originated in an externally connected- v" n* u% \4 r, `6 ?
(8259A-compatible) interrupt controller. The INTA cycle that corresponds' d3 k1 q7 j1 z. C7 O
to this ExtINT delivery is routed to the external controller that is expected
- P9 h) a  g% fto supply the vector. A Delivery Mode of "ExtINT"
( ^$ b' e+ F# D# f2 E7 m$ u- prequires an edge
# K& [0 x4 ]8 l. |" U  L  P
trigger mode.6 N. S3 s/ ~( H+ ]$ T
[7:0] Interrupt Vector (INTVEC)—R/W:
2 C+ D6 Q& B3 T3 c( @: OThe vector field is an 8 bit field containing the interrupt

) P& I  f. ]( [( e0 a  o* G) svector for this interrupt. Vector values range from 10h to FEh.
1 u5 @0 m/ i6 j1 G4 b2 T% j! g
& N) s' ?( O+ s) a/ p
REFF:
8 b  B$ I/ J' B, _1 V, x; \1 F% D5 ~+ D  Q: y- W
1.
% k( p5 h* E1 C: P; z. j: `4 d82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)
6 e# L4 I3 O/ Z7 l4 B4 J& {2.
0 N  w' n! [# r3 k: U' z8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)3 s, p. {: d" B& I" E
3.7 B2 m+ A% _  e* r% `
Undocumented PC
  [( J& L/ e4 N; j% H3 {3 [4.% Q" [9 S# f4 c0 N& g) N& a' F

6 e- e% i' j5 x/ \- B8259A初始化编程& h+ n7 l& H+ S" L  e+ q" m
4 a- W, h3 A5 Q9 a
That’s all!
5 T8 P& ^4 I4 x  u9 v3 I! ^& i( L- a% T- A. `5 m0 t
Peter6 h8 @" G) W2 c+ q, p2 a

/ [. ]& L8 @% p% v, t2010/10/07
: y/ G7 ~: }1 {- @8 l/ Z! W- W! l" m, W3 C
[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ]
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

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

GMT+8, 2026-4-4 18:25 , Processed in 0.081151 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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