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

PIC 、APIC(IOAPIC LAPIC)

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

, s& D  {- U# z, n2 P4 ?1. Overview6 y/ W$ @8 ^; ~+ E/ R4 |( Z
/ ]% t# b* E! G8 L1 q
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt ControllerAPIC是为了多核平台而设计的。它由两个部分组成IOAPICLAPIC,其中IOAPIC通常位于南桥中
7 c* {9 s# q$ b  W- T8 ~2 M用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPULAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pendingnestingmasking,以及IOAPICLocal CPU的交互处理。
# W4 ^5 q* ^! m: C; O- ~) \5 T" B9 z/ y; c. i) }3 n. y5 F3 R

3 Y2 r, y. I2 p1 I6 m/ q' r& l/ e4 M2. PIC8 Z7 v! U8 D9 y+ i6 a/ I8 Q

: y* q) W5 r. \7 t基于Intel 80x86PC使用两片8259A级联的方式组成了可以管理15级中断向量的一个中断系统,下图是它的一个连接示意图。两片8259A,一片为Master,另一片为Slaver。其中SlaverINT接到MasterIRQ2上。8259A有两种工作模式分别为编程和操作模式。BIOS初始化的时候会先通过IO port8259A进行编程配置,在此之后8259A就可以响应来自外部设备的中断请求了。MasterIO address0x20 0x21; SlaverIO address0xA0 0xA16 r3 {& b$ I" |( S! [. J
% k2 r. T: Y4 ^8 h  s
PIC.jpg
7 B2 f" @4 a' U+ C! W2 m3 o$ R6 G1 _. I

. l6 f) j' ]6 ^4 u* b为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code- Y& m+ R% S8 u

! U+ X: x7 ~5 O! W! m  y3 CMOV! R& K9 g. y! w2 J* ?
AL,00010001b# m6 @7 m0 W. h, ]+ u' f' j: {. [
;级联,边沿触发,需要写ICW4
1 V, l' z5 b7 BOUT/ {& g) U* e( |3 r2 I7 }
20H,AL
4 t. `) H, s: p- I# k; O;ICW1
2 a9 u* Q* N9 x7 U! LMOV% `4 p( l% O; A2 ^
AL,01000000B ;中断类型号40H
: z- V. d( o# b) B1 M. p1 xOUT
7 Q4 d2 m) R9 Y! D# v% L, g21H,AL" ^( Q9 g# L  [! Z
;ICW2/ _) |2 B- J* J, N
MOV
' y& B5 T4 \" m* A$ h* x+ wAL,00000100B;主片的IR2引脚从片
( W8 Q- }  J. E; S$ n+ JOUT& q& k! F* t( X. X! X
21H,AL
" z7 {8 K# Q! x;ICW3
8 ?' a& ]; a& l' d: `MOV$ s- y/ J4 j7 b" ]( R3 k0 S! v% c
AL,00010001B;特殊完全嵌套,非缓冲,自动结束
- n6 L% ?! B6 IOUT- _7 ?9 ?2 |! E& _
21H,AL, G, A8 S. k) U( y( C% Z
;ICW49 r3 R# g  S9 T' g

- g+ H8 Y( v/ z3. APIC
  s! p2 S! {3 J/ c* y- C2 Y+ s
" J% f( W' a# C! ^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( t; |9 H6 q) z2 k9 b) X
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。/ ~+ t7 }; I# a2 {: Z9 a

% J4 H$ V0 {& J5 e" x  R+ _+ m9 W4 a/ m6 F3 ^9 {# K
IOAPIC.jpg + O+ y. g' F6 D* k* `  D7 [
$ w) Q+ x8 K, u. W+ e# A1 |- W
Programmable Redirection Table详细格式如下所示:4 O& J9 [/ w0 v1 m* z! g7 p& D

: a4 X* Z" o4 }' b" z2 V6 F
Bit Description:
$ H1 M* V6 j) |( l
[63:56] Destination Field—R/W., l5 p% k8 A! {' R2 B0 _2 N: X
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits

' n1 y; |1 Y$ n3 i
[59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field% X: K$ D- O$ ^( d' V8 l+ v
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical; K1 y9 u2 z( L% `8 U: {
destination address.
" ?8 z9 _+ k; O& K( aDestination Mode IOREDTBLx[11] Logical Destination Address5 v% ^- Z5 N0 B5 E
0, Physical Mode IOREDTBLx[59:56] = APIC ID
' y4 S* c9 @5 s3 o1, Logical Mode IOREDTBLx[63:56] = Set of processors
3 N8 L& k9 D! f
[55:17] Reserved.82093AA (IOAPIC) ( P" _" q" J& r
[16]* Y# |, {  Z* L0 q, @
Interrupt Mask—R/W./ h& `1 q* r  X- Y1 _9 @
When this bit is 1, the interrupt signal is masked. Edge-sensitive
1 I( L, _  y1 k
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
, A- i& r  V! e& C7 A1 ELevel-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
+ L5 |. i" N' q" i3 @side effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by. \1 g9 e% f" v! n  \6 x
a local APIC has no effect on that interrupt. This behavior is identical to the case where the
; a- o/ o5 f8 R  V/ Idevice withdraws the interrupt before that interrupt is posted to the processor. It is software's0 k- A; C1 k. p; p% w9 S& M$ Z
responsibility to handle the case where the mask bit is set after the interrupt message has been
* b7 M$ u$ o% G2 w$ K; O; L5 Jaccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this' m' w' Z+ a5 C0 I8 K
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
! A4 g% D0 S9 {- Fresults in the delivery of the interrupt to the destination." t7 c; p4 f  Q, A' G
[15] Trigger Mode—R/W.
! Q, {, V4 n* p+ TThe trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
, ~- O5 ~8 A# R& T! [% g( c  g
[14] Remote IRR—RO.3 }, Z" h! V1 Q$ G+ F3 q
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.

% l6 f9 @# s/ O6 s, {
[13] Interrupt Input Pin Polarity (INTPOL)—R/W.4 o" s- l$ l$ W
This bit specifies the polarity of the interrupt
" l# A7 z/ l& m/ f
signal. 0=High active, 1=Low active.
, C; k: Z/ H# s( X( Q1 d* C
[12]
+ ?( z/ V  G  u# M$ bDelivery Status (DELIVS)—RO.( R/ ~6 s- B& H
The Delivery Status bit contains the current status of the
0 S) ~* T5 o: l+ O" d
delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit
: u: M* O7 ?2 w8 ~/ h8 v/ Jword) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send7 T5 c7 i6 m# t; B# @8 M) {* x) M
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC6 @- c3 b2 I1 H& X* F7 u  \
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
1 R1 o# T9 B; C
[11] Destination Mode (DESTMOD)—R/W.
1 P9 p' w- T) m0 W$ yThis field determines the interpretation of the
5 ]  Y  \. q: q( \) H" y# C
Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.5 w: a( }: W- N, n
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 W4 M/ I3 H3 W$ C+ K+ ^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)
/ S9 ]- }( ]! Y
[10:8]Delivery Mode (DELMOD)—R/W.- Q; c0 d! S* u2 ]  b
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

9 l! {- c3 S7 H& iDelivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
3 |- o: w$ q& t1 GThese restrictions are indicated in the following table for each Delivery Mode.
% S; D" B/ j6 Q# o- E3 wMode Description
5 i; _( p- V/ O" E000  b- {1 I$ ?# }3 E* ~
Fixed Deliver the signal on the INTR signal of all processor cores listed in the

4 n3 N* N! ?. ?7 Tdestination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
9 h7 V* F' J4 L8 G. Q! I7 K- V001; Y( D3 Y, A/ Y$ D4 S4 U. _
Lowest
7 Z& L; l: O  b' u2 ]
Priority Deliver the signal on the INTR signal of the processor core that is5 N' s, g! u, H% T% R0 ^& ^. p
executing at the lowest priority among all the processors listed in the8 L6 P2 ^( N  k$ h9 d9 D& _
specified destination. Trigger Mode for "lowest priority". Delivery Mode
3 ^" I" |$ q( J9 f) a% gcan be edge or level.- Q# v' y4 N: j( v
010
( g( u9 T, I1 F* ^) F7 t$ XSMI System Management Interrupt. A delivery mode equal to SMI requires an

0 `9 R/ E) {+ |- Pedge trigger mode. The vector information is ignored but must be; |1 Z  _4 R: ]; g4 V
programmed to all zeroes for future compatibility.. P' o% U- ^3 ^& a: M# ?  \( J
0117 I4 U3 L/ x3 C: Y- Z# T& V
Reserved
* Y" }6 p9 N: z1 ?# [
100
& P6 F; ^2 G( G7 T6 d! e! TNMI Deliver the signal on the NMI signal of all processor cores listed in the

$ |  w' l% F" z  G; H$ Sdestination. Vector information is ignored. NMI is treated as an edge
1 I1 d0 k- d& A% c9 htriggered interrupt, even if it is programmed as a level triggered interrupt., P+ ]; ?1 O# A$ z7 d0 a
For proper operation, this redirection table entry must be programmed to
1 K# U( e' m; k$ M( {  D/ K# P0 Iedge” triggered interrupt.
* x4 C& q& M+ H$ V  {: J101
/ ]8 x% R- C" _/ q# VINIT Deliver the signal to all processor cores listed in the destination by

2 U$ F( a& h# b* s# \1 ~6 w, T. Nasserting the INIT signal. All addressed local APICs will assume their
% a6 E( Y( t' ]0 S- vINIT state. INIT is always treated as an edge triggered interrupt, even if
, K0 Y+ ^) C" p7 X  W& qprogrammed otherwise. For proper operation, this redirection table entry
; i# C; F9 N5 Q0 C8 l) V: \must be programmed to “edge” triggered interrupt.
0 {2 m/ \8 i- ~' B2 A1 o- e1100 a1 U3 P( [3 k7 |) T7 E
Reserved
& m$ y5 ?6 q$ q; o. o; q
111
6 B  w; o) j5 N7 n' Z8 S7 r" u0 sExtINT Deliver the signal to the INTR signal of all processor cores listed in the

4 ]/ e3 y# O, s" m* L2 Rdestination as an interrupt that originated in an externally connected
" {) w- H$ F2 |. }# Y(8259A-compatible) interrupt controller. The INTA cycle that corresponds1 P9 Y0 B7 Y" J  @
to this ExtINT delivery is routed to the external controller that is expected
9 H( D, w! A, G6 b" B0 Zto supply the vector. A Delivery Mode of "ExtINT"
1 a5 F( h5 n1 i' g7 Q, {& F0 rrequires an edge
& D& I) T9 y( l+ u" r$ d* O
trigger mode.5 C8 a2 M0 d' l( A0 j9 G% Z
[7:0] Interrupt Vector (INTVEC)—R/W:
' [/ Q: M. w( O) H8 m- NThe vector field is an 8 bit field containing the interrupt

; y5 m+ T. ^, L& L3 ~- h$ t9 B( Vvector for this interrupt. Vector values range from 10h to FEh./ p& h( h: f( ^9 e% H! V* A
3 ~! v; G- h; u+ V6 R8 b1 K& L$ G
REFF:- @2 p( Y& T5 E

# Y; C' P6 B# m7 \, Y# M3 w1 D1.
" Q- i( h, O/ J$ Q$ R8 X1 E82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)/ N* x) ]' P& Q( i* s( k5 V
2./ q/ B0 k. T) g# N" C
8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)
: t" e  k" `4 y: Y3.) c/ z& S* G4 E3 w" s1 R6 l
Undocumented PC; f% [2 r6 B" p$ R
4.
. e1 @  z8 o* d" L7 [* L1 X- k+ s) H* L. c4 d
8259A初始化编程' P1 B% T' ^* ]+ d$ F5 m" j9 Z6 j; S
# a3 c( w# ^+ U$ H
That’s all!- Z+ g  n/ o3 z- d5 E
. h, l  G! L$ o. p
Peter
; s; l$ Z  v6 W7 N+ N( s1 g
) f; l4 j3 w/ c3 ~9 C2010/10/07
2 C: A4 I5 p9 U8 e
( m- r, E. {! ?7 `[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ]
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

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

GMT+8, 2026-3-5 14:24 , Processed in 0.084338 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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