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

PIC 、APIC(IOAPIC LAPIC)

[复制链接]
发表于 2010-10-29 16:11:58 | 显示全部楼层 |阅读模式
PIC APIC(IOAPIC LAPIC)
' q( E  H+ }& D% |. `
1. Overview! t$ `; h4 n3 ?1 {
) G) ?* D9 D0 D% M& m5 T" d6 J
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt ControllerAPIC是为了多核平台而设计的。它由两个部分组成IOAPICLAPIC,其中IOAPIC通常位于南桥中6 Y% M1 d7 l5 F$ I6 h
用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPULAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pendingnestingmasking,以及IOAPICLocal CPU的交互处理。4 {: \6 w- V( }: r  o1 H5 e9 J
% `8 F$ r4 o5 Y% _) N2 g
' V9 A% ~- l# t4 ~, \
2. PIC; b4 o  h: ^. k& ?9 Y0 J8 x5 W

! g6 c6 s  p8 P- |) u基于Intel 80x86PC使用两片8259A级联的方式组成了可以管理15级中断向量的一个中断系统,下图是它的一个连接示意图。两片8259A,一片为Master,另一片为Slaver。其中SlaverINT接到MasterIRQ2上。8259A有两种工作模式分别为编程和操作模式。BIOS初始化的时候会先通过IO port8259A进行编程配置,在此之后8259A就可以响应来自外部设备的中断请求了。MasterIO address0x20 0x21; SlaverIO address0xA0 0xA10 Q7 R4 ]  p( t3 P8 N8 p
2 H$ a' _. a3 B4 a' i9 F& ?  p
PIC.jpg
2 l( I; ]9 ~" l" O" }0 r
  @) A0 a. D: O( C6 {8 [7 G4 n/ g3 J. M) N0 l7 ^; K
为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code
" ~/ r' u: e7 R! w) j3 J! q, C( `& r2 I8 \& j7 c  a- s
MOV
# R$ K& r! [$ ?. Q$ ?/ e8 K; X9 QAL,00010001b
, n0 ?1 T, G* o0 d# S5 u8 Q;级联,边沿触发,需要写ICW4
6 B5 `0 C9 T/ W5 P5 z+ |8 d5 r4 P1 NOUT4 ~, n' z+ p, E" z0 C1 @( u
20H,AL
! A- t/ e6 t/ o& d4 y; a;ICW1
# P& P0 H  V: Q, ^% o8 b$ cMOV
) `- G0 A$ w0 a4 wAL,01000000B ;中断类型号40H
* f1 r/ R. k' j! q9 K4 iOUT/ W9 J' f' {% G! t1 ?3 y7 p  @! \
21H,AL# L+ V  r  P3 H' A8 H- V$ t5 S
;ICW2
) J0 v' ]/ A' R$ h5 n4 d9 U! B; lMOV
. l' E- v+ z8 n, n' _AL,00000100B;主片的IR2引脚从片$ ^& ^: f9 M* S+ y+ i. ]) P
OUT* {& ~2 b) o1 f2 c" M
21H,AL+ ^. z: z4 r; {3 [& v. i8 O1 O
;ICW3
- T' L, ~* S" Z* I- WMOV
  _, Y: L) P- f  l# B. D, l1 BAL,00010001B;特殊完全嵌套,非缓冲,自动结束! t# w* n0 L3 G7 \2 j$ o% r0 ^
OUT
  P1 N" T5 ]" Z- B5 D- O# Z0 a21H,AL
; u8 t/ _6 C) W6 u" Q' I" `5 x;ICW4
% E) K0 K; J, D
' d& _/ G! H! V! D3. APIC
9 g8 W- ~4 n, F" a2 _, {& m! S' W2 Q2 T2 r
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 b. `* j9 u' v5 Z) Z( s每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
3 z- [+ r+ |7 x( a% `: |4 z
; D' d2 Y' ]# X; ?! T; ]5 c4 j& T3 p/ j' H
IOAPIC.jpg
* A9 A& Q. f6 B
  d! H2 X2 v' l+ ?+ J; Y/ eProgrammable Redirection Table详细格式如下所示:
! v& Q1 P9 ]2 k( \7 u
: Z5 |; f4 }3 i0 R9 u. Z" L  }
Bit Description:
; w# n  E" T( ]
[63:56] Destination Field—R/W.% O8 u; a1 Q& a3 m' X: Z( @
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits
& u; O) I; d2 i. ]
[59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field& D8 ]7 I( w; P1 `. a. A: k
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
; A8 z7 g1 n8 C, `3 ^1 ^- d6 [& g6 |destination address.
9 ^+ W/ [6 y' Y- q( Z4 `( N0 EDestination Mode IOREDTBLx[11] Logical Destination Address0 T( ?, E8 z9 U8 S- [; F
0, Physical Mode IOREDTBLx[59:56] = APIC ID
  t, ]( W+ H9 U+ F1, Logical Mode IOREDTBLx[63:56] = Set of processors( h% r' J$ C; U" Y7 K
[55:17] Reserved.82093AA (IOAPIC) 8 `! }  }! \) C1 U1 }9 p7 Z& b' j
[16]& x9 B+ p5 W# a4 s
Interrupt Mask—R/W.
5 `8 n( ^* n4 L, w+ A+ |8 _When this bit is 1, the interrupt signal is masked. Edge-sensitive
5 E5 D! `/ d# h% ~! P
interrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).4 P3 H& ~9 R" E, U9 v2 o8 E* _
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
0 w% _: f. U  m8 K) z% M( aside effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
; o- L5 V  A+ G8 f" q0 ma local APIC has no effect on that interrupt. This behavior is identical to the case where the
4 J4 d% P' \& f; ^device withdraws the interrupt before that interrupt is posted to the processor. It is software's
5 N) w- ~: J, Tresponsibility to handle the case where the mask bit is set after the interrupt message has been
3 D8 v9 Z5 ]5 kaccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this$ J$ {+ E. o( A; E$ V: t  Q
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked  y7 K6 W. |$ N& _' H$ l. j* z. h. g
results in the delivery of the interrupt to the destination.+ L8 c! U3 V& {% C" y& Z1 l# S# {6 j
[15] Trigger Mode—R/W.
/ S, H: l! N6 b# AThe trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.

1 h4 N, r8 I- o0 ~/ V1 ]
[14] Remote IRR—RO.; I: v0 V+ D; i6 y
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.

2 X# ?3 J- ]9 N3 j, C* O+ {4 S
[13] Interrupt Input Pin Polarity (INTPOL)—R/W.
" o* k7 A0 C" c5 j$ nThis bit specifies the polarity of the interrupt

' h, W) @$ x- Osignal. 0=High active, 1=Low active.- u# O6 d4 Q6 @) u$ _" D- i+ f
[12]) q) S8 e8 X! p) J  R4 I
Delivery Status (DELIVS)—RO.
' I0 ?1 Y0 _( ^+ v( ]/ bThe Delivery Status bit contains the current status of the
: X+ o2 c% T6 k; F
delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit
6 J$ g9 X% H/ S4 N1 }word) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send! D8 K" e$ p' o7 l4 v8 {5 `$ r
Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC2 a. [9 q# U; V0 M0 q0 |! W9 Q9 g! e
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
' p; D- E# P5 I
[11] Destination Mode (DESTMOD)—R/W.
1 A! H2 W' w0 o* \& hThis field determines the interpretation of the

$ {+ v4 ?/ B* q# R1 u$ t! YDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.
0 m( d& q" V1 e' }! d& _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.
2 J0 D. a' [: W* _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)
. w0 e  u/ a8 d$ g6 {
[10:8]Delivery Mode (DELMOD)—R/W.
% A3 s; l& x! n( @0 WThe 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

% m1 V) Z" w2 Z9 [Delivery Modes only operate as intended when used in conjunction with a specific trigger Mode.( {! [1 f0 @0 m5 z% N
These restrictions are indicated in the following table for each Delivery Mode., l2 ]1 T( p' A
Mode Description
& ?6 B9 P2 s% I/ @% a6 E  b0006 S  n- q, o8 \9 G2 ~' f
Fixed Deliver the signal on the INTR signal of all processor cores listed in the
6 b( F* K4 e% L' {9 a
destination. Trigger Mode for "fixed" Delivery Mode can be edge or level.6 _3 w+ b2 [: n* O
001
; S& U) A  j7 H# E# C8 {Lowest

/ z" f& z$ |1 M! i! e7 x, ^6 xPriority Deliver the signal on the INTR signal of the processor core that is$ t0 i9 H) C- ^% Y3 l
executing at the lowest priority among all the processors listed in the& d2 {! M% g% }: c- D4 Q$ e2 c# h, g
specified destination. Trigger Mode for "lowest priority". Delivery Mode
( C  _" n/ a: F  A/ {' xcan be edge or level.
  _# M. E. k" o/ r, o9 \010
$ d! y' N' t1 K+ gSMI System Management Interrupt. A delivery mode equal to SMI requires an

- Q2 ?" U, F  O9 hedge trigger mode. The vector information is ignored but must be6 ?( w1 a" C; F- A5 f
programmed to all zeroes for future compatibility.
4 ^, H5 V1 A3 J+ I4 p5 Q/ ^011
; w+ q1 e7 M( |4 xReserved

! v7 z! M0 U6 T100
" q$ E# l! Y* v0 F0 JNMI Deliver the signal on the NMI signal of all processor cores listed in the

6 ?: K4 n9 Q" H/ e% M1 ^( R! Q% vdestination. Vector information is ignored. NMI is treated as an edge$ K! E' }' v& y7 o
triggered interrupt, even if it is programmed as a level triggered interrupt.
$ ~" h' E) E9 R  ~For proper operation, this redirection table entry must be programmed to$ |, n; q0 V+ \
edge” triggered interrupt.
$ q; X9 x' G; k6 h101' i7 S- q1 o1 c. K; n
INIT Deliver the signal to all processor cores listed in the destination by
: n$ e$ C) T1 `: [3 l
asserting the INIT signal. All addressed local APICs will assume their
1 J) N5 p9 q- `  s6 QINIT state. INIT is always treated as an edge triggered interrupt, even if
! V( S% e& G5 e. K4 @- Lprogrammed otherwise. For proper operation, this redirection table entry4 c9 \7 _: j* u7 D0 r: {' s1 @
must be programmed to “edge” triggered interrupt.3 I  `% V0 D, V9 z/ A
110; K9 I5 K, c: x% \
Reserved

9 B. q& P3 g0 I/ _& r111
: i- P! i% Z- n6 ]2 |$ ?6 d# U+ G! hExtINT Deliver the signal to the INTR signal of all processor cores listed in the

- G. g1 z5 W# bdestination as an interrupt that originated in an externally connected" p! i0 F, r1 K$ ?! P# ~. r! f
(8259A-compatible) interrupt controller. The INTA cycle that corresponds  r7 g1 E* X) N$ ~3 K+ x
to this ExtINT delivery is routed to the external controller that is expected! ^3 O: w. |% R( d1 l; {
to supply the vector. A Delivery Mode of "ExtINT"% _7 U& W1 D9 b; S0 o
requires an edge

9 R' d" n2 u+ r9 a! }trigger mode.8 S, P( z, v& v8 A" U* T
[7:0] Interrupt Vector (INTVEC)—R/W:
( f! h* \9 Z4 V3 h! NThe vector field is an 8 bit field containing the interrupt
, q- e% A, s9 o* Y6 O7 @4 r" a+ Q
vector for this interrupt. Vector values range from 10h to FEh.) u4 z/ i+ f# m0 c/ }

. J$ ]' ~4 `# X' AREFF:
' u9 z: Z) f) L% v' i* l1 d* }" b0 c' a! e9 b
1.5 }/ _& J1 R% N. S
82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)! Y8 C6 S  h6 f' }+ K% V
2.
. o1 r2 t1 k& E& v0 j8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)2 T0 r4 r+ o+ _$ ?
3.
: I; X1 T: ^* h' D0 p2 |Undocumented PC
% R" P; v6 ]! Q4.5 K4 b5 z" L; P" N# p. W* ?% b( R

$ V6 T, _$ G/ V( v3 i8259A初始化编程
2 y( i: a3 Q/ v1 _3 z" @3 J
8 Y; f( V* a3 o9 i* _. [! k. Y- YThat’s all!
( Y" X, |/ A) p( x; f" D8 C. Q8 Q9 k2 G
Peter
" I- e& t$ `, R4 x0 p7 H8 }7 H' N6 `& X8 H9 C! k6 l+ Z
2010/10/077 U, |; m& Y# g( ~2 u  R

; f+ B9 |3 k2 u) H) x0 q8 ~[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ]
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

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

GMT+8, 2025-6-13 06:48 , Processed in 0.075668 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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