]> git.proxmox.com Git - mirror_edk2.git/blame - PcAtChipsetPkg/Library/BaseIoApicLib/IoApicLib.c
PcAtChipsetPkg: Apply uncrustify changes
[mirror_edk2.git] / PcAtChipsetPkg / Library / BaseIoApicLib / IoApicLib.c
CommitLineData
5a702acd 1/** @file\r
986d1dfb 2 I/O APIC library.\r
3\r
4 I/O APIC library assumes I/O APIC is enabled. It does not\r
5 handles cases where I/O APIC is disabled.\r
6\r
5a702acd 7 Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r
e1d302e5 8 SPDX-License-Identifier: BSD-2-Clause-Patent\r
986d1dfb 9\r
10**/\r
11\r
12#include <Base.h>\r
13\r
14#include <Library/IoApicLib.h>\r
15\r
16#include <Library/DebugLib.h>\r
17#include <Library/PcdLib.h>\r
18#include <Library/IoLib.h>\r
19#include <Library/LocalApicLib.h>\r
20\r
21#include <Register/IoApic.h>\r
22\r
23/**\r
24 Read a 32-bit I/O APIC register.\r
25\r
26 If Index is >= 0x100, then ASSERT().\r
5a702acd 27\r
986d1dfb 28 @param Index Specifies the I/O APIC register to read.\r
29\r
30 @return The 32-bit value read from the I/O APIC register specified by Index.\r
31**/\r
32UINT32\r
33EFIAPI\r
34IoApicRead (\r
35 IN UINTN Index\r
36 )\r
37{\r
38 ASSERT (Index < 0x100);\r
39 MmioWrite8 (PcdGet32 (PcdIoApicBaseAddress) + IOAPIC_INDEX_OFFSET, (UINT8)Index);\r
40 return MmioRead32 (PcdGet32 (PcdIoApicBaseAddress) + IOAPIC_DATA_OFFSET);\r
41}\r
42\r
43/**\r
44 Write a 32-bit I/O APIC register.\r
45\r
46 If Index is >= 0x100, then ASSERT().\r
5a702acd 47\r
986d1dfb 48 @param Index Specifies the I/O APIC register to write.\r
49 @param Value Specifies the value to write to the I/O APIC register specified by Index.\r
50\r
51 @return The 32-bit value written to I/O APIC register specified by Index.\r
52**/\r
53UINT32\r
54EFIAPI\r
55IoApicWrite (\r
56 IN UINTN Index,\r
57 IN UINT32 Value\r
58 )\r
59{\r
60 ASSERT (Index < 0x100);\r
61 MmioWrite8 (PcdGet32 (PcdIoApicBaseAddress) + IOAPIC_INDEX_OFFSET, (UINT8)Index);\r
62 return MmioWrite32 (PcdGet32 (PcdIoApicBaseAddress) + IOAPIC_DATA_OFFSET, Value);\r
63}\r
64\r
65/**\r
66 Set the interrupt mask of an I/O APIC interrupt.\r
67\r
5a702acd 68 If Irq is larger than the maximum number I/O APIC redirection entries, then ASSERT().\r
986d1dfb 69\r
70 @param Irq Specifies the I/O APIC interrupt to enable or disable.\r
71 @param Enable If TRUE, then enable the I/O APIC interrupt specified by Irq.\r
72 If FALSE, then disable the I/O APIC interrupt specified by Irq.\r
73**/\r
74VOID\r
75EFIAPI\r
76IoApicEnableInterrupt (\r
77 IN UINTN Irq,\r
78 IN BOOLEAN Enable\r
79 )\r
80{\r
81 IO_APIC_VERSION_REGISTER Version;\r
82 IO_APIC_REDIRECTION_TABLE_ENTRY Entry;\r
83\r
84 Version.Uint32 = IoApicRead (IO_APIC_VERSION_REGISTER_INDEX);\r
85 ASSERT (Version.Bits.MaximumRedirectionEntry < 0xF0);\r
86 ASSERT (Irq <= Version.Bits.MaximumRedirectionEntry);\r
87\r
88 Entry.Uint32.Low = IoApicRead (IO_APIC_REDIRECTION_TABLE_ENTRY_INDEX + Irq * 2);\r
5220bd21 89 Entry.Bits.Mask = Enable ? 0 : 1;\r
986d1dfb 90 IoApicWrite (IO_APIC_REDIRECTION_TABLE_ENTRY_INDEX + Irq * 2, Entry.Uint32.Low);\r
91}\r
92\r
93/**\r
94 Configures an I/O APIC interrupt.\r
5a702acd 95\r
986d1dfb 96 Configure an I/O APIC Redirection Table Entry to deliver an interrupt in physical\r
53b1dd10 97 mode to the Local APIC of the currently executing CPU. The default state of the\r
986d1dfb 98 entry is for the interrupt to be disabled (masked). IoApicEnableInterrupts() must\r
99 be used to enable(unmask) the I/O APIC Interrupt.\r
5a702acd
LG
100\r
101 If Irq is larger than the maximum number I/O APIC redirection entries, then ASSERT().\r
986d1dfb 102 If Vector >= 0x100, then ASSERT().\r
103 If DeliveryMode is not supported, then ASSERT().\r
104\r
105 @param Irq Specifies the I/O APIC interrupt to initialize.\r
106 @param Vector The 8-bit interrupt vector associated with the I/O APIC\r
107 Interrupt. Must be in the range 0x10..0xFE.\r
108 @param DeliveryMode A 3-bit value that specifies how the recept of the I/O APIC\r
109 interrupt is handled. The only supported values are:\r
110 0: IO_APIC_DELIVERY_MODE_FIXED\r
111 1: IO_APIC_DELIVERY_MODE_LOWEST_PRIORITY\r
112 2: IO_APIC_DELIVERY_MODE_SMI\r
113 4: IO_APIC_DELIVERY_MODE_NMI\r
114 5: IO_APIC_DELIVERY_MODE_INIT\r
115 7: IO_APIC_DELIVERY_MODE_EXTINT\r
116 @param LevelTriggered TRUE specifies a level triggered interrupt.\r
117 FALSE specifies an edge triggered interrupt.\r
118 @param AssertionLevel TRUE specified an active high interrupt.\r
119 FALSE specifies an active low interrupt.\r
120**/\r
121VOID\r
122EFIAPI\r
123IoApicConfigureInterrupt (\r
124 IN UINTN Irq,\r
125 IN UINTN Vector,\r
126 IN UINTN DeliveryMode,\r
127 IN BOOLEAN LevelTriggered,\r
128 IN BOOLEAN AssertionLevel\r
129 )\r
130{\r
131 IO_APIC_VERSION_REGISTER Version;\r
132 IO_APIC_REDIRECTION_TABLE_ENTRY Entry;\r
133\r
134 Version.Uint32 = IoApicRead (IO_APIC_VERSION_REGISTER_INDEX);\r
135 ASSERT (Version.Bits.MaximumRedirectionEntry < 0xF0);\r
136 ASSERT (Irq <= Version.Bits.MaximumRedirectionEntry);\r
137 ASSERT (Vector <= 0xFF);\r
138 ASSERT (DeliveryMode < 8 && DeliveryMode != 6 && DeliveryMode != 3);\r
5a702acd 139\r
5220bd21 140 Entry.Uint32.Low = IoApicRead (IO_APIC_REDIRECTION_TABLE_ENTRY_INDEX + Irq * 2);\r
986d1dfb 141 Entry.Bits.Vector = (UINT8)Vector;\r
142 Entry.Bits.DeliveryMode = (UINT32)DeliveryMode;\r
5a702acd 143 Entry.Bits.DestinationMode = 0;\r
986d1dfb 144 Entry.Bits.Polarity = AssertionLevel ? 0 : 1;\r
145 Entry.Bits.TriggerMode = LevelTriggered ? 1 : 0;\r
146 Entry.Bits.Mask = 1;\r
147 IoApicWrite (IO_APIC_REDIRECTION_TABLE_ENTRY_INDEX + Irq * 2, Entry.Uint32.Low);\r
148\r
5220bd21 149 Entry.Uint32.High = IoApicRead (IO_APIC_REDIRECTION_TABLE_ENTRY_INDEX + Irq * 2 + 1);\r
986d1dfb 150 Entry.Bits.DestinationID = GetApicId ();\r
151 IoApicWrite (IO_APIC_REDIRECTION_TABLE_ENTRY_INDEX + Irq * 2 + 1, Entry.Uint32.High);\r
152}\r