TianoCore EDK2 master
Loading...
Searching...
No Matches
IoApicLib.c
Go to the documentation of this file.
1
12#include <Base.h>
13
14#include <Library/IoApicLib.h>
15
16#include <Library/DebugLib.h>
17#include <Library/PcdLib.h>
18#include <Library/IoLib.h>
20
21#include <Register/IoApic.h>
22
32UINT32
33EFIAPI
35 IN UINTN Index
36 )
37{
38 ASSERT (Index < 0x100);
39 MmioWrite8 (PcdGet32 (PcdIoApicBaseAddress) + IOAPIC_INDEX_OFFSET, (UINT8)Index);
40 return MmioRead32 (PcdGet32 (PcdIoApicBaseAddress) + IOAPIC_DATA_OFFSET);
41}
42
53UINT32
54EFIAPI
56 IN UINTN Index,
57 IN UINT32 Value
58 )
59{
60 ASSERT (Index < 0x100);
61 MmioWrite8 (PcdGet32 (PcdIoApicBaseAddress) + IOAPIC_INDEX_OFFSET, (UINT8)Index);
62 return MmioWrite32 (PcdGet32 (PcdIoApicBaseAddress) + IOAPIC_DATA_OFFSET, Value);
63}
64
74VOID
75EFIAPI
77 IN UINTN Irq,
78 IN BOOLEAN Enable
79 )
80{
83
84 Version.Uint32 = IoApicRead (IO_APIC_VERSION_REGISTER_INDEX);
85 ASSERT (Version.Bits.MaximumRedirectionEntry < 0xF0);
86 ASSERT (Irq <= Version.Bits.MaximumRedirectionEntry);
87
88 Entry.Uint32.Low = IoApicRead (IO_APIC_REDIRECTION_TABLE_ENTRY_INDEX + Irq * 2);
89 Entry.Bits.Mask = Enable ? 0 : 1;
90 IoApicWrite (IO_APIC_REDIRECTION_TABLE_ENTRY_INDEX + Irq * 2, Entry.Uint32.Low);
91}
92
121VOID
122EFIAPI
124 IN UINTN Irq,
125 IN UINTN Vector,
126 IN UINTN DeliveryMode,
127 IN BOOLEAN LevelTriggered,
128 IN BOOLEAN AssertionLevel
129 )
130{
133
134 Version.Uint32 = IoApicRead (IO_APIC_VERSION_REGISTER_INDEX);
135 ASSERT (Version.Bits.MaximumRedirectionEntry < 0xF0);
136 ASSERT (Irq <= Version.Bits.MaximumRedirectionEntry);
137 ASSERT (Vector <= 0xFF);
138 ASSERT (DeliveryMode < 8 && DeliveryMode != 6 && DeliveryMode != 3);
139
140 Entry.Uint32.Low = IoApicRead (IO_APIC_REDIRECTION_TABLE_ENTRY_INDEX + Irq * 2);
141 Entry.Bits.Vector = (UINT8)Vector;
142 Entry.Bits.DeliveryMode = (UINT32)DeliveryMode;
143 Entry.Bits.DestinationMode = 0;
144 Entry.Bits.Polarity = AssertionLevel ? 0 : 1;
145 Entry.Bits.TriggerMode = LevelTriggered ? 1 : 0;
146 Entry.Bits.Mask = 1;
147 IoApicWrite (IO_APIC_REDIRECTION_TABLE_ENTRY_INDEX + Irq * 2, Entry.Uint32.Low);
148
149 Entry.Uint32.High = IoApicRead (IO_APIC_REDIRECTION_TABLE_ENTRY_INDEX + Irq * 2 + 1);
150 Entry.Bits.DestinationID = GetApicId ();
151 IoApicWrite (IO_APIC_REDIRECTION_TABLE_ENTRY_INDEX + Irq * 2 + 1, Entry.Uint32.High);
152}
UINT64 UINTN
#define IOAPIC_INDEX_OFFSET
Definition: IoApic.h:16
UINT32 EFIAPI IoApicWrite(IN UINTN Index, IN UINT32 Value)
Definition: IoApicLib.c:55
VOID EFIAPI IoApicConfigureInterrupt(IN UINTN Irq, IN UINTN Vector, IN UINTN DeliveryMode, IN BOOLEAN LevelTriggered, IN BOOLEAN AssertionLevel)
Definition: IoApicLib.c:123
VOID EFIAPI IoApicEnableInterrupt(IN UINTN Irq, IN BOOLEAN Enable)
Definition: IoApicLib.c:76
UINT32 EFIAPI IoApicRead(IN UINTN Index)
Definition: IoApicLib.c:34
UINT8 EFIAPI MmioWrite8(IN UINTN Address, IN UINT8 Value)
Definition: IoLib.c:126
UINT32 EFIAPI MmioRead32(IN UINTN Address)
Definition: IoLib.c:262
UINT32 EFIAPI MmioWrite32(IN UINTN Address, IN UINT32 Value)
Definition: IoLib.c:309
UINT32 EFIAPI GetApicId(VOID)
Definition: BaseXApicLib.c:337
#define IN
Definition: Base.h:279
#define PcdGet32(TokenName)
Definition: PcdLib.h:362