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

PIC 、APIC(IOAPIC LAPIC)

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

2 `- v2 ?: m  Z1. Overview
) _1 D& F2 N* p$ @$ d" n5 J6 \1 A2 I/ }; V- W# ^( C2 d
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt ControllerAPIC是为了多核平台而设计的。它由两个部分组成IOAPICLAPIC,其中IOAPIC通常位于南桥中
; ]7 b* z- [2 e用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPULAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pendingnestingmasking,以及IOAPICLocal CPU的交互处理。
1 T* l6 G4 o# P8 }5 b' J% H
5 ?) B% [( E" w( _# o, D3 a
/ p/ ?+ L$ J( Q% [2. PIC
0 Q+ I% S+ h9 K& L" t, w3 z$ x# l
' \. v8 k* E, ~$ o% O, x基于Intel 80x86PC使用两片8259A级联的方式组成了可以管理15级中断向量的一个中断系统,下图是它的一个连接示意图。两片8259A,一片为Master,另一片为Slaver。其中SlaverINT接到MasterIRQ2上。8259A有两种工作模式分别为编程和操作模式。BIOS初始化的时候会先通过IO port8259A进行编程配置,在此之后8259A就可以响应来自外部设备的中断请求了。MasterIO address0x20 0x21; SlaverIO address0xA0 0xA1  D# a2 v) E* c* _4 A9 T1 f5 M
; y% g/ }8 Y1 u
PIC.jpg ; |! U. l; K  Z  J: w/ U

: |2 E: y4 N8 X! r" Q( R& O0 H" u
为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code
' [9 h4 }( y. N; J0 d" v/ d5 |' `
MOV" W) w2 V+ H  `  ]0 p; R2 m) Y
AL,00010001b
4 W+ u/ p: }- E2 T, m;级联,边沿触发,需要写ICW4
1 L+ i5 K) ^7 Q5 K5 m6 B% NOUT
6 K! b4 g5 F) @* |0 z20H,AL
" T: \  }  b4 n- E' Y* U9 ];ICW1
* G/ h* _4 Q1 L0 T/ L  p) s3 i6 v) yMOV. Y$ C7 g$ @* h+ u0 q( c( X
AL,01000000B ;中断类型号40H
( w6 K4 J2 g  Y" T6 \9 C0 W) JOUT. `8 W- p: A5 g# X
21H,AL
! @2 \$ l; t9 [$ I# c4 _, k;ICW2
6 [0 |7 X# E% x, O8 u) SMOV3 a: I: I5 e0 L/ G; I2 |% D
AL,00000100B;主片的IR2引脚从片/ Q3 k; z# q, `- f4 N
OUT
  F' g5 ^! P& z% g, ~21H,AL
& m* T$ j& M3 ~0 z1 U;ICW3
; K, x; c- R" ]3 C  MMOV
' E9 A8 r& s' T/ X7 ^1 uAL,00010001B;特殊完全嵌套,非缓冲,自动结束
$ c8 l) y$ S. p) C$ T( s2 q# e+ QOUT
) J* {5 p! E6 T/ Q9 Z' V6 `6 E, }21H,AL
6 J; Q1 B' L# g. [" d6 x1 H;ICW4% a7 y. y: y: U6 ~  p
  ]% r3 W8 c$ h: x) c" R' E; C
3. APIC2 H$ N& R5 b+ r" q
" l3 K. V, Z7 w8 M( F! E
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
, q( R2 ^6 j; E0 `0 X+ X每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
4 u  R0 ?/ z, F4 S" z! _6 k
; N% c! M+ j; f1 ?
, C0 q( j& w$ _) q IOAPIC.jpg ( C- I: E/ s/ l7 M; E

! K; ^, U. a$ ~2 {Programmable Redirection Table详细格式如下所示:" a  g! w: }- o/ G  R  ?
5 w! F: Q1 L# t$ C
Bit Description:/ Z0 c" ~7 }- ]% s( t1 C# h
[63:56] Destination Field—R/W.
8 M' E( K& u/ l8 p# g+ IIf the Destination Mode of this entry is Physical Mode (bit 11=0), bits

* H6 V  h' p2 X, B
[59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field5 p+ L( L# O6 v+ b
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
& D2 E4 S8 e, G8 zdestination address.1 h. g. s1 B; m' q5 M& I. m- e* ?
Destination Mode IOREDTBLx[11] Logical Destination Address# C% o, v3 T$ K4 s: _) ~
0, Physical Mode IOREDTBLx[59:56] = APIC ID1 Q4 n$ W+ g4 |
1, Logical Mode IOREDTBLx[63:56] = Set of processors
3 z* [1 u  {8 L/ }) j
[55:17] Reserved.82093AA (IOAPIC) 1 Q; G1 `$ m+ `$ F5 T% k
[16]  ?4 J* U4 L" B
Interrupt Mask—R/W.% i* \+ l* V9 K; H
When this bit is 1, the interrupt signal is masked. Edge-sensitive
; t- v0 m% B8 q2 |" ~! A" ]
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).
7 E) k& P" V' ?( yLevel-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
# F& l3 w' E4 V  _6 tside effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
& `7 f! J. W' A) `8 K, a+ r$ r5 e  ha local APIC has no effect on that interrupt. This behavior is identical to the case where the
. b) F+ n2 K' m- B+ `device withdraws the interrupt before that interrupt is posted to the processor. It is software's: t; V4 I# L( B7 V
responsibility to handle the case where the mask bit is set after the interrupt message has been
1 w- v, s7 [, R& c% v, Baccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this, E5 |5 a- }: X& [. B! M) [  M' b
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked( ]5 k, [$ k3 o9 q
results in the delivery of the interrupt to the destination.: W5 T2 g$ k+ H( C! t7 L, U4 {0 ?
[15] Trigger Mode—R/W.
6 X/ H+ Y" P) ^  U- H- A6 j- x' qThe trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.

/ g9 r# v- ^, P" Y
[14] Remote IRR—RO.
! u0 w: C" ?  i3 c. aThis 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.

$ D$ L1 Q8 M9 ^- v" E
[13] Interrupt Input Pin Polarity (INTPOL)—R/W.
' X7 j4 X3 U, W3 W2 ^8 c! KThis bit specifies the polarity of the interrupt
4 R  J* r4 {6 `" z- E5 u+ v
signal. 0=High active, 1=Low active.
* Q3 R6 t' d5 L9 F  w9 {0 N
[12]( z+ Q8 q7 t8 D' z2 l
Delivery Status (DELIVS)—RO.3 {. H# {7 n, z, ]7 y6 E& r& }8 L3 E5 H
The Delivery Status bit contains the current status of the

3 x6 ]. @2 J, L* A. v+ f* A% idelivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit# F8 ~/ l0 `' I; V6 f; j
word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
, `1 G& c& v& Q( aPending (the interrupt has been injected but its delivery is temporarily held up due to the APIC
& w  r0 d+ h; }) C& \! z9 jbus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
2 X$ A" }( d2 _8 V% S$ ~' t
[11] Destination Mode (DESTMOD)—R/W.
6 o0 l" M3 m6 V8 _  f: u2 g+ dThis field determines the interpretation of the

: t" p% \, k- v: d5 n7 \Destination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.# H2 [% m! _2 j: M, S
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.
8 r. x. J: Q9 X: Y% XDestination Mode IOREDTBLx[11] Logical Destination Address 0, Physical Mode IOREDTBLx[59:56] = APIC ID1, Logical Mode IOREDTBLx[63:56] = Set of processorsE 82093AA (IOAPIC)- O$ E. z8 i7 w& B' e
[10:8]Delivery Mode (DELMOD)—R/W.1 \2 ^+ l5 `. G4 _! {5 O( w
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

; z: |# H  A) O3 G. _Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.
, p6 R# y( p$ f* N7 ^7 U# AThese restrictions are indicated in the following table for each Delivery Mode.
* c, {( x+ {  sMode Description
+ e: m; \8 l2 y7 u$ Z  S4 U000/ l+ w! k7 d6 V9 l& j8 K4 _
Fixed Deliver the signal on the INTR signal of all processor cores listed in the

5 u) w3 _# ^0 L; B9 Gdestination. Trigger Mode for "fixed" Delivery Mode can be edge or level.
; x) [, N. S+ P001
' d0 A& a$ i; wLowest
' K7 X! m+ E* \  ?" ~
Priority Deliver the signal on the INTR signal of the processor core that is
/ V) a" L$ u/ Q9 v6 jexecuting at the lowest priority among all the processors listed in the
5 A7 G- P# a4 o2 u9 e. W$ Dspecified destination. Trigger Mode for "lowest priority". Delivery Mode  P% _) D9 o6 {% \. E2 Z" M
can be edge or level.8 q1 g% M/ ]( M
010
) T/ x/ J" s, kSMI System Management Interrupt. A delivery mode equal to SMI requires an
$ o/ t6 j! ]2 j4 {& F8 b, F
edge trigger mode. The vector information is ignored but must be
# C4 g7 P- Y' B, {0 K! V2 rprogrammed to all zeroes for future compatibility.* ^3 Q" r; `7 k( K
011
% m% ?9 V0 i) V0 QReserved

8 I# J  ~) [" ?100
; l9 g. l& X  s, _4 f' T/ X( _NMI Deliver the signal on the NMI signal of all processor cores listed in the

/ ?# S. z: I  R* o- b. Sdestination. Vector information is ignored. NMI is treated as an edge: k# g: Q8 I. w9 o
triggered interrupt, even if it is programmed as a level triggered interrupt.
, A) V& b8 n9 h! e0 J$ f) ?, j0 j( p$ _For proper operation, this redirection table entry must be programmed to  I6 U0 g& k6 ?
edge” triggered interrupt./ J- X: @- t) l8 b  V- P
101& S3 S8 a5 M" P$ k  X+ f7 h/ i, o+ [
INIT Deliver the signal to all processor cores listed in the destination by
0 D3 n1 I7 ?' X: {( _7 x  _
asserting the INIT signal. All addressed local APICs will assume their
& x! d# C  M% M4 SINIT state. INIT is always treated as an edge triggered interrupt, even if
2 V8 `7 F- E4 X, l) S2 {0 Zprogrammed otherwise. For proper operation, this redirection table entry
" Q; u+ `  u/ k: Qmust be programmed to “edge” triggered interrupt.
) z) ~$ D/ ^& Y2 r1 |! S1107 K6 i6 s" S" f
Reserved
  a5 c$ e2 `9 k) i  E$ x$ I1 a
111: _4 n: O6 ?6 _8 X) I8 n* {
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the

) e- K4 `: w+ a) |) m8 adestination as an interrupt that originated in an externally connected, M( E$ `6 q' F$ ]
(8259A-compatible) interrupt controller. The INTA cycle that corresponds
) b5 H! I/ c& M3 v7 M6 _to this ExtINT delivery is routed to the external controller that is expected
1 q3 T7 _- |% Ato supply the vector. A Delivery Mode of "ExtINT"+ q6 p1 T( f( A2 v  ^
requires an edge

# ~0 {7 D. I) R  r. I5 atrigger mode.
$ B; Y' c- E+ r# J" G+ z- r
[7:0] Interrupt Vector (INTVEC)—R/W:+ K# _4 z* g; u& _* U
The vector field is an 8 bit field containing the interrupt
$ Z$ \' `1 v0 [" z5 e' B( k( F0 V
vector for this interrupt. Vector values range from 10h to FEh., ]" y+ _+ x; d

# {" `- e! P5 w" S- _7 ~( e- G8 kREFF:$ R$ _* t7 |% u% y+ Q
- U  O+ j+ G$ ]! V
1.7 ~& O6 f- \. s  q) m1 h+ l
82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)! m! j- {  z+ O4 E
2.
6 o; \9 m9 P/ v5 C4 t- b9 |8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)
) M3 Z8 p% Z% k9 b* l3.4 v- G5 s  c- |5 Y* }- T8 t9 D
Undocumented PC# o8 H6 O8 ]& y# W' u0 d* J- {
4.( ~2 H/ d4 F- T# A4 ^  c+ G
# h+ a7 Z8 c9 V* C$ `/ J. K* @
8259A初始化编程2 i+ q3 f! }& c0 H3 G7 z
' `2 `. ?4 M0 k6 p7 ?! a  e4 E8 s5 K
That’s all!- F% m9 I6 M2 G. V& s( l  w$ ^
" B8 J6 K) u+ D5 J' s
Peter' `+ x) t9 O  L6 H. K
& W4 k) H) k( x! G
2010/10/07/ |1 r% d, `5 ?8 U% a, U. L

6 ^  K+ ?8 @5 r- Z; {+ Y5 X  t# ^[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ]
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

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

GMT+8, 2025-5-22 03:13 , Processed in 0.045522 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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