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

PIC 、APIC(IOAPIC LAPIC)

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

8 U; S$ i4 k9 R  K* G0 o8 G6 y1. Overview" e" R8 b' u1 U$ r  c2 D
; W: F2 k. m7 ~- {1 f9 a6 t
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt ControllerAPIC是为了多核平台而设计的。它由两个部分组成IOAPICLAPIC,其中IOAPIC通常位于南桥中, h" h: E0 @% ~- K* W" Q, N: S4 B: U
用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPULAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pendingnestingmasking,以及IOAPICLocal CPU的交互处理。$ I1 x. v% L8 o
1 V& ~$ T1 Y: {7 {4 n8 P( r' q$ B

8 \  O7 P" p. G3 R7 C2. PIC
8 V2 S% [0 \1 s# v. q( u
( c$ e8 F1 p8 H7 p基于Intel 80x86PC使用两片8259A级联的方式组成了可以管理15级中断向量的一个中断系统,下图是它的一个连接示意图。两片8259A,一片为Master,另一片为Slaver。其中SlaverINT接到MasterIRQ2上。8259A有两种工作模式分别为编程和操作模式。BIOS初始化的时候会先通过IO port8259A进行编程配置,在此之后8259A就可以响应来自外部设备的中断请求了。MasterIO address0x20 0x21; SlaverIO address0xA0 0xA1
4 w$ @8 |: j3 k1 T2 u& s0 d$ C! w8 K4 t$ }- M: C
PIC.jpg
; R) p, y6 u" H) Y1 D  g4 m& A# `; G7 a, F4 E: j

+ Z( L1 _. B: Q/ f! I为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code
8 c5 B8 [9 R' B! N6 ^: {+ n+ \& \9 x: ~$ G, p/ h
MOV$ {" G' R5 w" x% T& V8 E
AL,00010001b* C: a5 b5 G5 l7 H( w, }9 B& L
;级联,边沿触发,需要写ICW4- g# U- l- f: Q; t
OUT
: B" t2 K) X4 _2 ?0 |# ?20H,AL
2 x% @8 B, `6 Y% ^8 T;ICW1
2 o4 Q) c. E' D3 X. C$ a+ E$ ^$ f# SMOV; Y  Y! H. H: E. ~
AL,01000000B ;中断类型号40H
4 ]+ w# X* U+ a/ @% A8 C1 Y3 H1 QOUT
) \- C+ `' x. R21H,AL
1 Y+ F4 |. j: B* s' X# Z# I! ~;ICW2
: o. [9 N% T# D& s& YMOV
3 Y- O% v) ]' _. z9 T$ I: t0 GAL,00000100B;主片的IR2引脚从片7 n5 O; s, s6 I7 r
OUT$ @, N4 l3 j* _
21H,AL
: V1 _+ q5 ]  b' g4 e;ICW3
" k% o, [1 W! ^; bMOV
; a  \. Q* P& L. H# WAL,00010001B;特殊完全嵌套,非缓冲,自动结束
8 k3 n3 f( ?$ b# \0 POUT1 O- J+ A- r7 V  \; N
21H,AL
- [9 C1 ?% F5 S, ?# E;ICW4/ a+ n. P4 s" a9 j6 R" Z

, M; y' u) u( H% g) `3. APIC2 p5 W' g$ s" w$ k7 ~. ]
( C" S' n( `8 k3 I8 G. A3 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% _1 C$ x3 R6 `; u6 i8 F
每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。- N$ v2 `- [9 n# W. `

6 w) g0 I. ~1 M! b( E
& R4 m) L6 O3 D, C. V% g IOAPIC.jpg # W) M: R+ H# Q& }; X# t7 Q
6 c0 h& e9 d, p# o. c1 b
Programmable Redirection Table详细格式如下所示:
; z$ j/ n8 ]/ P2 i( n  i! h1 h/ p5 a. D# z7 d0 O  U* H0 h
Bit Description:
4 R7 z/ E. B8 \0 R$ B+ e
[63:56] Destination Field—R/W.1 J( B+ [4 h* |* t0 ]3 c" |1 O
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits

$ m$ d' `6 Z, I, z! Y, ]
[59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field
0 k. u: q& v8 Jpotentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical) w; s9 p" T# w' F
destination address.7 w7 F; m# q7 I9 K- b" Y
Destination Mode IOREDTBLx[11] Logical Destination Address
- D+ ]$ K! L3 V- r, H3 d! v0, Physical Mode IOREDTBLx[59:56] = APIC ID+ w) l8 E+ c8 B
1, Logical Mode IOREDTBLx[63:56] = Set of processors
& t2 Y5 w8 n& G( }5 F
[55:17] Reserved.82093AA (IOAPIC) . h  f8 u1 E9 N3 }
[16]
, [0 w1 h4 n* }+ t/ fInterrupt Mask—R/W.5 t+ [5 v/ U: n& T7 ?
When this bit is 1, the interrupt signal is masked. Edge-sensitive
, z+ S0 z8 c# [5 N0 r' B# p+ Z$ {3 o
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).4 _4 v( o  l; m0 o# z
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
! Z# I4 G9 y+ n+ c* Aside effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
! P( |$ W3 k( G2 J4 g3 ga local APIC has no effect on that interrupt. This behavior is identical to the case where the" s6 ?" s- |! i' z# Z
device withdraws the interrupt before that interrupt is posted to the processor. It is software's
4 v' Y5 `8 B% r. Q2 Sresponsibility to handle the case where the mask bit is set after the interrupt message has been
9 k- a/ s5 ~, E; Jaccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this
$ E  ?" l. d2 ]bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked
9 m* E! \" h3 Nresults in the delivery of the interrupt to the destination.
, v" e' ?5 Y9 u. s$ G, E
[15] Trigger Mode—R/W.% [/ R( F- h! l% I* ?
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.
3 s- \* ^' a) _2 b& |% ]; ?* F/ [
[14] Remote IRR—RO.0 t3 _  ^! y$ O1 [
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.

  ], \+ Y& v  p3 G& A, `
[13] Interrupt Input Pin Polarity (INTPOL)—R/W.
( S' T7 x3 F- C/ Z5 GThis bit specifies the polarity of the interrupt
  R: q* n. p0 L1 x) m  S
signal. 0=High active, 1=Low active.
; W6 w1 J* U' I/ B7 n1 S
[12]+ {# P2 E* w9 _( z" t
Delivery Status (DELIVS)—RO.
' n' o: y' W3 B; ^$ qThe Delivery Status bit contains the current status of the
+ E  y6 C) ~  o) x
delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit
# h" Q/ n% B. k) `word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send/ h$ I6 D3 F& c. x  I+ A% Q
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC( f  N# V) k& o  {2 P
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
9 f! Z% q2 ], a. B
[11] Destination Mode (DESTMOD)—R/W.7 t. k" D- [; _1 b: Q- _/ T
This field determines the interpretation of the

# z* p1 J* g# N2 |$ J) dDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
( T/ g9 r/ s4 U9 ?* ABits 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.
4 U! k$ I6 _* P& d0 cDestination Mode IOREDTBLx[11] Logical Destination Address 0, Physical Mode IOREDTBLx[59:56] = APIC ID1, Logical Mode IOREDTBLx[63:56] = Set of processorsE 82093AA (IOAPIC)
! U0 J( P& O+ k( V8 _9 h
[10:8]Delivery Mode (DELMOD)—R/W.$ v: y1 }) N3 e
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

0 {5 A( I6 h! [; q1 a5 _  NDelivery Modes only operate as intended when used in conjunction with a specific trigger Mode.  b8 a1 t# m* c5 |% e# F# S
These restrictions are indicated in the following table for each Delivery Mode.
( N2 T" V7 _3 x# B: P8 CMode Description
2 F& Z) ^$ o' T6 z; k1 w000
6 i& c% ?2 [, A" CFixed Deliver the signal on the INTR signal of all processor cores listed in the

+ q$ A/ E% B9 a' ^4 u" ]  Mdestination. Trigger Mode for "fixed" Delivery Mode can be edge or level.+ J3 F4 I$ g" t/ [! M9 L" [
001/ V3 V: C0 ~, U0 ~- T2 J3 m
Lowest

7 S! `; `: M2 M' s* L* {2 vPriority Deliver the signal on the INTR signal of the processor core that is
; F7 Q0 W9 \6 g) Wexecuting at the lowest priority among all the processors listed in the
( E2 j" F; a) T7 H. aspecified destination. Trigger Mode for "lowest priority". Delivery Mode( X8 O7 d; S# W% K# s: m
can be edge or level.! C$ @& f4 \" [' F
0107 U/ }! M9 z3 ]# t+ ?. n1 L% _
SMI System Management Interrupt. A delivery mode equal to SMI requires an

, j6 _6 ^9 F- s9 n4 Y# d5 P6 gedge trigger mode. The vector information is ignored but must be
: S; D5 l" g, ^( P8 N% m- ^$ Kprogrammed to all zeroes for future compatibility.
; z) R! ^' M+ p/ s011
9 V! e3 e* T4 \9 q' [/ z/ IReserved

3 L2 ^, s: W  [6 Q  s* d100
% @# d: y$ X+ D4 ], x+ BNMI Deliver the signal on the NMI signal of all processor cores listed in the

' P: T8 I" N4 M$ x! q) H6 Q' zdestination. Vector information is ignored. NMI is treated as an edge
5 H8 I4 \: v# _& otriggered interrupt, even if it is programmed as a level triggered interrupt.
6 }% Q4 L/ b" ~2 G/ |For proper operation, this redirection table entry must be programmed to
" t/ D& s7 M' b/ l5 Redge” triggered interrupt." s) T7 X. A. s% E( K1 p% A
1012 \- L. ~6 R5 D' N6 V, Y4 f
INIT Deliver the signal to all processor cores listed in the destination by

& u3 [; {) o; `! i0 jasserting the INIT signal. All addressed local APICs will assume their+ d2 e4 {5 n4 d) O
INIT state. INIT is always treated as an edge triggered interrupt, even if$ [! Z( Z  R: u8 V! @5 Z9 k
programmed otherwise. For proper operation, this redirection table entry
- j! }% t) R" smust be programmed to “edge” triggered interrupt.# b$ |( P' R& w3 }
1108 G4 p& B7 A/ E9 P
Reserved

+ ~; V' x5 U% g# b111& f3 y" Q& Y5 G) t
ExtINT Deliver the signal to the INTR signal of all processor cores listed in the

( h2 |1 b  `' m8 u; i0 Z# G! sdestination as an interrupt that originated in an externally connected# j5 B9 B$ w/ M7 C
(8259A-compatible) interrupt controller. The INTA cycle that corresponds4 v0 P. F/ R6 y$ g) u7 n% Z+ G
to this ExtINT delivery is routed to the external controller that is expected5 Y# X, K5 [0 L3 t
to supply the vector. A Delivery Mode of "ExtINT"
3 ]9 D6 N) u3 o5 H; h5 Qrequires an edge
2 b4 B" y( t' n( ^
trigger mode.
+ m+ G- A4 W! F% b% e: g5 z7 _
[7:0] Interrupt Vector (INTVEC)—R/W:- n$ B& o$ g) z- @, o( s
The vector field is an 8 bit field containing the interrupt
  o( D0 z2 z1 J" Q! l3 Y  Z2 A5 u+ R
vector for this interrupt. Vector values range from 10h to FEh.
9 [( }" U/ ?$ ]0 E% l( }
# {3 l( ?5 g" @! m% A
REFF:, p% ]- j& R' o0 |. ]

6 R) K- [. s. b& q# V1.  ~2 Z4 Q; ?6 q
82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)8 C3 k4 b# o7 q
2.
& c  a; @9 l$ Q  W% f+ G7 G, g+ H! U8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)5 K/ {1 ]0 O+ l$ s$ D$ B/ \
3.
* P+ s  R7 y% `( tUndocumented PC* ?' j. o9 G; Z
4.& d# C: h& p2 f5 H8 s  y
4 k) M! x% c- r" S+ m# [! z6 d, d: }
8259A初始化编程+ @+ S( y0 J! }! v6 Y
1 x) C) L8 c' T
That’s all!$ R. Z: ]5 U8 t# j& F
4 h8 T& V( T3 s8 {4 h4 a' @) v" ]
Peter) Q7 D. h  }2 Z/ r  @, @- k. A0 V  r
4 \) y* d; h' ~' f# J
2010/10/077 X  X6 q0 C' H: E% _+ ]

! ~" X9 p! ^* H" m/ ?$ n[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ]
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

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

GMT+8, 2024-5-20 12:02 , Processed in 0.026307 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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