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

PIC 、APIC(IOAPIC LAPIC)

[复制链接]
发表于 2010-10-29 16:11:58 | 显示全部楼层 |阅读模式
PIC APIC(IOAPIC LAPIC)
7 ^3 i. U' A0 K/ W- G
1. Overview
- t2 H* F7 X% ^/ n7 N" C% W6 e: `4 B! I
PIC全称Programmable Interrupt Controller,通常是指Intel 8259A双片级联构成的最多支持15interrupts的中断控制系统。APIC全称Advanced Programmable Interrupt ControllerAPIC是为了多核平台而设计的。它由两个部分组成IOAPICLAPIC,其中IOAPIC通常位于南桥中
5 t/ `8 D5 `/ N. W3 v' W用于处理桥上的设备所产生的各种中断,LAPIC则是每个CPU都会有一个。IOAPIC通过APICBUS(现在都是通过FSB/QPI)将中断信息分派给每颗CPULAPIC,CPU上的LAPIC能够智能的决定是否接受系统总线上传递过来的中断信息,而且它还可以处理Local端中断的pendingnestingmasking,以及IOAPICLocal CPU的交互处理。& o! h* S8 R0 c8 V  [& B5 F
& V6 {2 @4 Q8 _- g8 j2 L0 @

) I$ t  M( \' _; N2. PIC0 c/ J& ?# A6 b( C. b* W! Z

" P9 y, s: V' E, }$ C& @基于Intel 80x86PC使用两片8259A级联的方式组成了可以管理15级中断向量的一个中断系统,下图是它的一个连接示意图。两片8259A,一片为Master,另一片为Slaver。其中SlaverINT接到MasterIRQ2上。8259A有两种工作模式分别为编程和操作模式。BIOS初始化的时候会先通过IO port8259A进行编程配置,在此之后8259A就可以响应来自外部设备的中断请求了。MasterIO address0x20 0x21; SlaverIO address0xA0 0xA1
- U' \4 K8 d# Y; I+ o7 r* x2 r4 |
- H" C2 N: u. q PIC.jpg ! O2 {' I, |. U) X0 ?
0 Y$ t! A3 y$ V" p9 k& X4 Q
- D' M2 f  p& s3 ?  H3 p, K
为了能够正常的使用PIC来管理系统中断,就需要对它进行初始化。8259A支持两种类型的命令字,一类是初始化命令字ICW1~4,另一类是操作命令字OCW1~3,其中每一个命令字的各个bit都有其代表的特定意义。下述是一个初始化Master的一个sample code
) h- D4 `: ^& u6 F. F2 e  J6 x. I- W( a1 M
MOV
0 D$ h+ C( y: D" M2 a: Y1 U9 R: DAL,00010001b
: l8 O. m- _! L% q, M0 z+ ^, x4 t6 T;级联,边沿触发,需要写ICW48 J5 m, \4 N8 r- m. o& r
OUT
0 y. b6 u; n: |- H1 h# S- Y9 T9 J20H,AL
' i% Y" _8 J; T1 |$ J& ?;ICW1
# j* P% {% M$ X1 D/ J+ {" vMOV8 j! _  P2 L+ T+ T2 b  B2 |/ |
AL,01000000B ;中断类型号40H
# Q! a  B' U7 BOUT
: ?) H: R& m. ?1 k3 s21H,AL
6 s1 _$ ~9 f) e9 U1 @;ICW2
$ Q5 M# C, L, S! a" U; QMOV, e# J4 ~' Z8 N+ Z% J
AL,00000100B;主片的IR2引脚从片& }9 p* u3 R% f! }9 p# m1 g
OUT
$ R# E' r" h& L8 N+ z21H,AL: ]- P7 N- @1 {$ B
;ICW3
8 s4 M2 s+ _; C. f6 q# i0 P$ GMOV
! S! S" T9 I% |7 t. GAL,00010001B;特殊完全嵌套,非缓冲,自动结束
3 r$ Y- C+ A& u+ T, W% \4 ]OUT
8 }6 {' O) k/ Z. |2 E9 k21H,AL
! z; _$ K& P# |) n, T! B. n! H;ICW4
4 B/ {. L( m0 m' [( ?: x, r' N; v1 I9 v( T9 w; m) O
3. APIC
6 u3 |, k: }( u8 s* j+ y
0 i, \4 `1 A# P  q% O3 T9 XIntel 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
5 j- Z+ k, x- b$ ^1 @每一个pin都对应一个RTE,所以针对每一个interrupt pin都可以单独设定它的mask,触发方式(level,edge trigger),中断管脚的极性,传送方式,传送状态,目的地,中断向量等。
; {; U2 t! S" C$ `, J% x, G; e& q( I

1 T" q# O" |! M# k5 R IOAPIC.jpg
$ A' F4 z1 V; u. s, x
  c) `5 T& W6 ], s/ lProgrammable Redirection Table详细格式如下所示:
9 |3 i/ s8 g4 _7 l! ^
2 M; R2 K8 W& h; J5 L, M% O
Bit Description:
! z/ }( `# A: u' X) n" L* {) Y
[63:56] Destination Field—R/W./ }* Z4 ]% w2 S4 z% M" G
If the Destination Mode of this entry is Physical Mode (bit 11=0), bits

5 c7 e) `; m6 B- [, T# g/ j7 j
[59:56] contain an APIC ID. If Logical Mode is selected (bit 11=1), the Destination Field2 V( s! K: i4 k8 t& u# {; @+ X
potentially defines a set of processors. Bits [63:56] of the Destination Field specify the logical
  P& G+ z; B5 X0 D- Sdestination address.$ j! v9 N- D9 N3 J
Destination Mode IOREDTBLx[11] Logical Destination Address
; y3 v% q9 Q- v! X# j6 ~( p: J0, Physical Mode IOREDTBLx[59:56] = APIC ID
; o, d# L# u; m7 ?1, Logical Mode IOREDTBLx[63:56] = Set of processors
4 g0 }  Q2 D( G
[55:17] Reserved.82093AA (IOAPIC)
; ^/ F) [/ L7 }6 t1 f5 M$ ~
[16]: z9 ]+ ?/ U: K6 R' F
Interrupt Mask—R/W.% J/ L) W1 Y5 l. J' }+ w' q. v
When this bit is 1, the interrupt signal is masked. Edge-sensitive

  c* P0 @3 L3 q0 W% D3 j: vinterrupts signaled on a masked interrupt pin are ignored (i.e., not delivered or held pending).. J& N' ^4 S/ ], ~" M
Level-asserts or negates occurring on a masked level-sensitive pin are also ignored and have no
4 N7 n* {1 O& Z% X3 m" S6 ?" Cside effects. Changing the mask bit from unmasked to masked after the interrupt is accepted by
/ n. y) Q# d1 T3 h0 L1 e: W$ Ma local APIC has no effect on that interrupt. This behavior is identical to the case where the- T4 i' C1 t8 J8 J+ O. k) t
device withdraws the interrupt before that interrupt is posted to the processor. It is software's
0 ?* j- C5 x! Nresponsibility to handle the case where the mask bit is set after the interrupt message has been
" \! z& Z( B0 o; h% iaccepted by a local APIC unit but before the interrupt is dispensed to the processor. When this! g/ s4 j8 q  L7 ~- E
bit is 0, the interrupt is not masked. An edge or level on an interrupt pin that is not masked0 I) g. r1 I1 p- v1 ]4 w# e* q
results in the delivery of the interrupt to the destination.
( Z4 \: o  H8 g8 V
[15] Trigger Mode—R/W.2 C% t, \) _( {) ^2 Q& D
The trigger mode field indicates the type of signal on the interrupt pin that triggers an interrupt. 1=Level sensitive, 0=Edge sensitive.

& D8 ]6 W. Z4 T% I6 B
[14] Remote IRR—RO.
' R# O7 ?2 ^0 Q/ |. ~" j' i& ^* sThis 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.

, T- Y" Y0 l+ X/ I" H( k$ S
[13] Interrupt Input Pin Polarity (INTPOL)—R/W.
9 D' D+ m! @+ E2 v0 w' oThis bit specifies the polarity of the interrupt
! D$ a, p% c0 F* H. x3 \% z8 |0 ]) ^
signal. 0=High active, 1=Low active.3 C6 o6 }" @6 s8 A: [" L* F
[12]
- s/ M2 G( D& u5 ]; H/ h2 o  F7 x+ J3 VDelivery Status (DELIVS)—RO.
6 K7 z/ y! Y$ b. D* k- z3 d+ {The Delivery Status bit contains the current status of the
4 L: i8 ^. K# j5 u6 O& J
delivery of this interrupt. Delivery Status is read-only and writes to this bit (as part of a 32 bit
# k, H4 `5 @" nword) do not effect this bit. 0=IDLE (there is currently no activity for this interrupt). 1=Send
- ~* P5 q; ~/ c8 ]Pending (the interrupt has been injected but its delivery is temporarily held up due to the APIC+ a1 ^% t% T1 P6 G3 ^
bus being busy or the inability of the receiving APIC unit to accept that interrupt at that time).
$ s' g1 e2 r, N4 t  I
[11] Destination Mode (DESTMOD)—R/W.
3 @* O$ y2 J( V  JThis field determines the interpretation of the

  Z! J; Y, A; A2 U" d7 xDestination field. When DESTMOD=0 (physical mode), a destination APIC is identified by its ID.5 X) \; S" M1 x8 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.
, C3 _4 y- ^" t; r$ p8 V5 ^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); M- b( I/ R' S
[10:8]Delivery Mode (DELMOD)—R/W.
* ?7 [! h* }8 ^6 VThe 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

% N( |2 z  ]6 E, jDelivery Modes only operate as intended when used in conjunction with a specific trigger Mode.# Z, ]5 L- Y# y# P$ c9 {
These restrictions are indicated in the following table for each Delivery Mode.$ b) m0 G+ {( H8 m3 e$ L4 A2 t7 Y, R
Mode Description+ K& I! @$ x9 f5 w3 b
000
! Q+ @! [7 ~- rFixed Deliver the signal on the INTR signal of all processor cores listed in the

5 B, Z2 _. i+ H) q5 U$ Udestination. Trigger Mode for "fixed" Delivery Mode can be edge or level.% w4 p0 n7 Q& y
001
1 ]# `* E( q/ V! r5 ]! W+ E+ E3 L7 aLowest
, W0 x0 T1 A% c7 m7 S. L. L
Priority Deliver the signal on the INTR signal of the processor core that is. K! B) S+ r* d
executing at the lowest priority among all the processors listed in the" \! q+ r7 d! ~! {1 S, W; E" M
specified destination. Trigger Mode for "lowest priority". Delivery Mode
4 f/ B$ Y6 R  j$ D# R0 {; b4 }can be edge or level.$ J, w/ C: k# q, T$ s; C0 i8 m
010
7 G9 `) C: R0 w( ~7 ^1 e$ MSMI System Management Interrupt. A delivery mode equal to SMI requires an
) p4 Q4 }3 p& ^' V+ r& g9 t
edge trigger mode. The vector information is ignored but must be; e  T2 e2 I8 v- d- k/ i1 \
programmed to all zeroes for future compatibility.
. d! J4 ?, t; P& T# s; b011/ l. e; _1 n. c3 O% ], q& j
Reserved
8 t1 O  j' `* W& O9 Y
1009 s  K" D1 P, T' x4 ]
NMI Deliver the signal on the NMI signal of all processor cores listed in the

9 p: ]/ N( F3 ydestination. Vector information is ignored. NMI is treated as an edge
; u3 o1 Z0 P) z, p7 ?9 k( X. Jtriggered interrupt, even if it is programmed as a level triggered interrupt.% {2 L) O) G4 p0 n, R% c
For proper operation, this redirection table entry must be programmed to4 d& d1 y/ \( `; k/ c4 g- l
edge” triggered interrupt.
4 U  e# l& \1 Z- W6 y/ J# {' B3 g* P1016 r9 U7 |7 N( g/ t8 i
INIT Deliver the signal to all processor cores listed in the destination by
% s- x: w. F$ _
asserting the INIT signal. All addressed local APICs will assume their
+ A$ g& M7 R; }8 \. [9 V3 jINIT state. INIT is always treated as an edge triggered interrupt, even if
. G" p* H3 F% {* uprogrammed otherwise. For proper operation, this redirection table entry, D) ]& t/ @% n
must be programmed to “edge” triggered interrupt.+ x) K8 l: w9 L# e% b3 T
110
! ~0 K: ?/ h( [) vReserved
% D+ U8 Y$ j) X' n; ]5 W
111
7 A, t' v- A8 O( i& nExtINT Deliver the signal to the INTR signal of all processor cores listed in the
! [+ x2 }6 ^" T- R5 I
destination as an interrupt that originated in an externally connected+ k6 S5 ?/ @8 r
(8259A-compatible) interrupt controller. The INTA cycle that corresponds
6 O* Z; \9 a/ }# oto this ExtINT delivery is routed to the external controller that is expected) \6 x, y5 E8 R( v: b' N) ^
to supply the vector. A Delivery Mode of "ExtINT"
/ N. }- M3 g& N. rrequires an edge

7 E4 x9 z+ q; O$ s" Gtrigger mode.
# v7 O: G& g' ]. D% n! p1 S
[7:0] Interrupt Vector (INTVEC)—R/W:+ L, r3 v" x! e: A5 v
The vector field is an 8 bit field containing the interrupt

* g# e7 V3 T- Mvector for this interrupt. Vector values range from 10h to FEh.
; |. K, H5 ?0 E2 X

5 D5 M9 a- t2 [# [REFF:, @$ a) q; k! y" h: `
, A! x+ [7 q- \* K& B! d
1.. r8 J( H! f7 k5 l& F- L
82093AA I/O ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (IOAPIC)
9 }& y3 N, E) P* e+ Q1 \2.- L" _4 J( S/ L) {) l/ N
8259A PROGRAMMABLE INTERRUPT CONTROLLER(8259A/8259A-2)* h- u: c+ R* I5 t+ _$ H) }8 a
3.
  o# u3 o9 @. HUndocumented PC. `, V8 q! S  S' z/ o
4.3 W7 w% t. S% K0 B# n

1 A0 ^$ {, p: K8259A初始化编程6 D* F1 n  a6 \% ^- Y
% W0 D8 X& g& v7 U) h: A
That’s all!
5 h% r# k/ o: @9 |
" M1 R7 Z  }, o, H% L  I) GPeter
2 B+ C' U1 u0 h- c8 c8 z7 q
  I0 [% |2 ^" j- Y( c- n+ n2010/10/07
  H( H1 R4 e' _* k6 j% s( i
1 ~( u6 q* q, A# w5 ?1 N3 {6 V[ 本帖最后由 peterhu 于 2010-10-29 16:13 编辑 ]
您需要登录后才可以回帖 登录 | 加入计匠网

本版积分规则

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

GMT+8, 2026-6-29 04:40 , Processed in 0.224512 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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