summaryrefslogtreecommitdiff
path: root/UefiCpuPkg/Include/Register/LocalApic.h
blob: bb0e211dc7e1b106ee00a544108cf039fcb788c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/** @file
  IA32 Local APIC Definitions.

  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
  This program and the accompanying materials
  are licensed and made available under the terms and conditions of the BSD License
  which accompanies this distribution.  The full text of the license may be found at
  http://opensource.org/licenses/bsd-license.php

  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

**/

#ifndef __LOCAL_APIC_H__
#define __LOCAL_APIC_H__

//
// Definitions for IA32 architectural MSRs
//
#define MSR_IA32_APIC_BASE_ADDRESS              0x1B

//
// Definitions for CPUID instruction
//
#define CPUID_VERSION_INFO                      0x1
#define CPUID_EXTENDED_FUNCTION                 0x80000000
#define CPUID_VIR_PHY_ADDRESS_SIZE              0x80000008

//
// Definition for Local APIC registers and related values
//
#define XAPIC_ID_OFFSET                         0x20
#define XAPIC_VERSION_OFFSET                    0x30
#define XAPIC_EOI_OFFSET                        0x0b0
#define XAPIC_ICR_DFR_OFFSET                    0x0e0
#define XAPIC_SPURIOUS_VECTOR_OFFSET            0x0f0
#define XAPIC_ICR_LOW_OFFSET                    0x300
#define XAPIC_ICR_HIGH_OFFSET                   0x310
#define XAPIC_LVT_TIMER_OFFSET                  0x320
#define XAPIC_LVT_LINT0_OFFSET                  0x350
#define XAPIC_LVT_LINT1_OFFSET                  0x360
#define XAPIC_TIMER_INIT_COUNT_OFFSET           0x380
#define XAPIC_TIMER_CURRENT_COUNT_OFFSET        0x390
#define XAPIC_TIMER_DIVIDE_CONFIGURATION_OFFSET 0x3E0

#define X2APIC_MSR_BASE_ADDRESS                 0x800
#define X2APIC_MSR_ICR_ADDRESS                  0x830

#define LOCAL_APIC_DELIVERY_MODE_FIXED           0
#define LOCAL_APIC_DELIVERY_MODE_LOWEST_PRIORITY 1
#define LOCAL_APIC_DELIVERY_MODE_SMI             2
#define LOCAL_APIC_DELIVERY_MODE_NMI             4
#define LOCAL_APIC_DELIVERY_MODE_INIT            5
#define LOCAL_APIC_DELIVERY_MODE_STARTUP         6
#define LOCAL_APIC_DELIVERY_MODE_EXTINT          7

#define LOCAL_APIC_DESTINATION_SHORTHAND_NO_SHORTHAND       0
#define LOCAL_APIC_DESTINATION_SHORTHAND_SELF               1
#define LOCAL_APIC_DESTINATION_SHORTHAND_ALL_INCLUDING_SELF 2
#define LOCAL_APIC_DESTINATION_SHORTHAND_ALL_EXCLUDING_SELF 3

typedef union {
  struct {
    UINT32  Reserved0:8;     ///< Reserved.
    UINT32  Bsp:1;           ///< Processor is BSP.
    UINT32  Reserved1:1;     ///< Reserved.
    UINT32  Extd:1;          ///< Enable x2APIC mode.
    UINT32  En:1;            ///< xAPIC global enable/disable.
    UINT32  ApicBaseLow:20;  ///< APIC Base physical address. The actual field width depends on physical address width.
    UINT32  ApicBaseHigh:32;
  } Bits;
  UINT64    Uint64;
} MSR_IA32_APIC_BASE;

//
// Local APIC Version Register.
//
typedef union {
  struct {
    UINT32  Version:8;                  ///< The version numbers of the local APIC.
    UINT32  Reserved0:8;                ///< Reserved.
    UINT32  MaxLvtEntry:8;              ///< Number of LVT entries minus 1.
    UINT32  EoiBroadcastSuppression:1;  ///< 1 if EOI-broadcast suppression supported.
    UINT32  Reserved1:7;                ///< Reserved.
  } Bits;
  UINT32    Uint32;
} LOCAL_APIC_VERSION;

//
// Low half of Interrupt Command Register (ICR).
//
typedef union {
  struct {
    UINT32  Vector:8;                ///< The vector number of the interrupt being sent.
    UINT32  DeliveryMode:3;          ///< Specifies the type of IPI to be sent.
    UINT32  DestinationMode:1;       ///< 0: physical destination mode, 1: logical destination mode.
    UINT32  DeliveryStatus:1;        ///< Indicates the IPI delivery status. This field is reserved in x2APIC mode.
    UINT32  Reserved0:1;             ///< Reserved.
    UINT32  Level:1;                 ///< 0 for the INIT level de-assert delivery mode. Otherwise 1.
    UINT32  TriggerMode:1;           ///< 0: edge, 1: level when using the INIT level de-assert delivery mode.
    UINT32  Reserved1:2;             ///< Reserved.
    UINT32  DestinationShorthand:2;  ///< A shorthand notation to specify the destination of the interrupt.
    UINT32  Reserved2:12;            ///< Reserved.
  } Bits;
  UINT32    Uint32;
} LOCAL_APIC_ICR_LOW;

//
// High half of Interrupt Command Register (ICR)
//
typedef union {
  struct {
    UINT32  Reserved0:24;   ///< Reserved.
    UINT32  Destination:8;  ///< Specifies the target processor or processors in xAPIC mode.
  } Bits;
  UINT32    Uint32;         ///< Destination field expanded to 32-bit in x2APIC mode.
} LOCAL_APIC_ICR_HIGH;

//
// Spurious-Interrupt Vector Register (SVR)
//
typedef union {
  struct {
    UINT32  SpuriousVector:8;           ///< Spurious Vector.
    UINT32  SoftwareEnable:1;           ///< APIC Software Enable/Disable.
    UINT32  FocusProcessorChecking:1;   ///< Focus Processor Checking.
    UINT32  Reserved0:2;                ///< Reserved.
    UINT32  EoiBroadcastSuppression:1;  ///< EOI-Broadcast Suppression.
    UINT32  Reserved1:19;               ///< Reserved.
  } Bits;
  UINT32    Uint32;
} LOCAL_APIC_SVR;

//
// Divide Configuration Register (DCR)
//
typedef union {
  struct {
    UINT32  DivideValue1:2;  ///< Low 2 bits of the divide value.
    UINT32  Reserved0:1;     ///< Always 0.
    UINT32  DivideValue2:1;  ///< Highest 1 bit of the divide value.
    UINT32  Reserved1:28;    ///< Reserved.
  } Bits;
  UINT32    Uint32;
} LOCAL_APIC_DCR;

//
// LVT Timer Register
//
typedef union {
  struct {
    UINT32  Vector:8;          ///< The vector number of the interrupt being sent.
    UINT32  Reserved0:4;       ///< Reserved.
    UINT32  DeliveryStatus:1;  ///< 0: Idle, 1: send pending.
    UINT32  Reserved1:3;       ///< Reserved.
    UINT32  Mask:1;            ///< 0: Not masked, 1: Masked.
    UINT32  TimerMode:1;       ///< 0: One-shot, 1: Periodic.
    UINT32  Reserved2:14;      ///< Reserved.
  } Bits;
  UINT32    Uint32;
} LOCAL_APIC_LVT_TIMER;

//
// LVT LINT0/LINT1 Register
//
typedef union {
  struct {
    UINT32  Vector:8;            ///< The vector number of the interrupt being sent.
    UINT32  DeliveryMode:3;      ///< Specifies the type of interrupt to be sent.
    UINT32  Reserved0:1;         ///< Reserved.
    UINT32  DeliveryStatus:1;    ///< 0: Idle, 1: send pending.
    UINT32  InputPinPolarity:1;  ///< Interrupt Input Pin Polarity.
    UINT32  RemoteIrr:1;         ///< RO. Set when the local APIC accepts the interrupt and reset when an EOI is received.
    UINT32  TriggerMode:1;       ///< 0:edge, 1:level.
    UINT32  Mask:1;              ///< 0: Not masked, 1: Masked.
    UINT32  Reserved1:15;        ///< Reserved.
  } Bits;
  UINT32    Uint32;
} LOCAL_APIC_LVT_LINT;

//
// MSI Address Register
//
typedef union {
  struct {
    UINT32  Reserved0:2;         ///< Reserved
    UINT32  DestinationMode:1;   ///< Specifies the Destination Mode.
    UINT32  RedirectionHint:1;   ///< Specifies the Redirection Hint.
    UINT32  Reserved1:8;         ///< Reserved.
    UINT32  DestinationId:8;     ///< Specifies the Destination ID.
    UINT32  BaseAddress:12;      ///< Must be 0FEEH
  } Bits;
  UINT32    Uint32;
} LOCAL_APIC_MSI_ADDRESS;

//
// MSI Address Register
//
typedef union {
  struct {
    UINT32  Vector:8;            ///< Interrupt vector in range 010h..0FEH
    UINT32  DeliveryMode:3;      ///< Specifies the type of interrupt to be sent.
    UINT32  Reserved0:3;         ///< Reserved.
    UINT32  Level:1;             ///< 0:Deassert, 1:Assert.  Ignored for Edge triggered interrupts.
    UINT32  TriggerMode:1;       ///< 0:Edge,     1:Level.
    UINT32  Reserved1:16;        ///< Reserved.
    UINT32  Reserved2:32;        ///< Reserved.
  } Bits;
  UINT64    Uint64;
} LOCAL_APIC_MSI_DATA;

#endif