1 | /* $Id: VBoxSysTables.c 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxSysTables.c - VirtualBox system tables
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * The contents of this file may alternatively be used under the terms
|
---|
26 | * of the Common Development and Distribution License Version 1.0
|
---|
27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | * CDDL are applicable instead of those of the GPL.
|
---|
30 | *
|
---|
31 | * You may elect to license modified versions of this file under the
|
---|
32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | *
|
---|
34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | */
|
---|
36 |
|
---|
37 |
|
---|
38 | /*********************************************************************************************************************************
|
---|
39 | * Header Files *
|
---|
40 | *********************************************************************************************************************************/
|
---|
41 | #include <Library/BaseMemoryLib.h>
|
---|
42 | #include <Library/DebugLib.h>
|
---|
43 | #include <Library/UefiBootServicesTableLib.h>
|
---|
44 | #include <Library/UefiLib.h>
|
---|
45 |
|
---|
46 | #include <Protocol/DevicePathToText.h>
|
---|
47 |
|
---|
48 | #include <IndustryStandard/Acpi10.h>
|
---|
49 | #include <IndustryStandard/Acpi20.h>
|
---|
50 | #include <IndustryStandard/SmBios.h>
|
---|
51 |
|
---|
52 | #include <Guid/SmBios.h>
|
---|
53 | #include <Guid/Acpi.h>
|
---|
54 | #include <Guid/Mps.h>
|
---|
55 |
|
---|
56 | #include "VBoxPkg.h"
|
---|
57 | #include "DevEFI.h"
|
---|
58 | #include "iprt/asm.h"
|
---|
59 |
|
---|
60 |
|
---|
61 | /*********************************************************************************************************************************
|
---|
62 | * Internal Functions *
|
---|
63 | *********************************************************************************************************************************/
|
---|
64 |
|
---|
65 |
|
---|
66 | EFI_STATUS EFIAPI
|
---|
67 | ConvertSystemTable (
|
---|
68 | IN EFI_GUID *TableGuid,
|
---|
69 | IN OUT VOID **Table
|
---|
70 | );
|
---|
71 |
|
---|
72 | #define MPS_PTR SIGNATURE_32('_','M','P','_')
|
---|
73 | #define SMBIOS_PTR SIGNATURE_32('_','S','M','_')
|
---|
74 |
|
---|
75 | #define EBDA_BASE (0x9FC0 << 4)
|
---|
76 |
|
---|
77 | VOID *
|
---|
78 | FindSMBIOSPtr (
|
---|
79 | VOID
|
---|
80 | )
|
---|
81 | {
|
---|
82 | UINTN Address;
|
---|
83 |
|
---|
84 | //
|
---|
85 | // First Search 0x0e0000 - 0x0fffff for SMBIOS Ptr
|
---|
86 | //
|
---|
87 | for (Address = 0xe0000; Address < 0xfffff; Address += 0x10) {
|
---|
88 | if (*(UINT32 *)(Address) == SMBIOS_PTR) {
|
---|
89 | return (VOID *)Address;
|
---|
90 | }
|
---|
91 | }
|
---|
92 | return NULL;
|
---|
93 | }
|
---|
94 |
|
---|
95 | VOID *
|
---|
96 | FindMPSPtr (
|
---|
97 | VOID
|
---|
98 | )
|
---|
99 | {
|
---|
100 | UINTN Address;
|
---|
101 | UINTN Index;
|
---|
102 |
|
---|
103 | //
|
---|
104 | // First Search 0x0e0000 - 0x0fffff for MPS Ptr
|
---|
105 | //
|
---|
106 | for (Address = 0xe0000; Address < 0xfffff; Address += 0x10) {
|
---|
107 | if (*(UINT32 *)(Address) == MPS_PTR) {
|
---|
108 | return (VOID *)Address;
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | //
|
---|
113 | // Search EBDA
|
---|
114 | //
|
---|
115 |
|
---|
116 | Address = EBDA_BASE;
|
---|
117 | for (Index = 0; Index < 0x400 ; Index += 16) {
|
---|
118 | if (*(UINT32 *)(Address + Index) == MPS_PTR) {
|
---|
119 | return (VOID *)(Address + Index);
|
---|
120 | }
|
---|
121 | }
|
---|
122 | return NULL;
|
---|
123 | }
|
---|
124 |
|
---|
125 | EFI_STATUS EFIAPI
|
---|
126 | ConvertAndInstallTable(EFI_GUID* Guid, VOID* Ptr)
|
---|
127 | {
|
---|
128 | EFI_STATUS rc = EFI_SUCCESS;
|
---|
129 |
|
---|
130 | rc = ConvertSystemTable(Guid, &Ptr);
|
---|
131 | //ASSERT_EFI_ERROR (rc);
|
---|
132 |
|
---|
133 | rc = gBS->InstallConfigurationTable(Guid, Ptr);
|
---|
134 | ASSERT_EFI_ERROR (rc);
|
---|
135 |
|
---|
136 | return rc;
|
---|
137 | }
|
---|
138 |
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * VBoxSysTablesDxe entry point.
|
---|
142 | *
|
---|
143 | * @returns EFI status code.
|
---|
144 | *
|
---|
145 | * @param ImageHandle The image handle.
|
---|
146 | * @param SystemTable The system table pointer.
|
---|
147 | */
|
---|
148 | EFI_STATUS EFIAPI
|
---|
149 | DxeInitializeVBoxSysTables(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
|
---|
150 | {
|
---|
151 | EFI_STATUS rc;
|
---|
152 | VOID* Ptr;
|
---|
153 |
|
---|
154 | DEBUG((DEBUG_INFO, "DxeInitializeVBoxSysTables\n"));
|
---|
155 |
|
---|
156 | Ptr = FindSMBIOSPtr();
|
---|
157 | DEBUG((DEBUG_INFO, "SMBIOS=%p\n", Ptr));
|
---|
158 | ASSERT(Ptr != NULL);
|
---|
159 | if (Ptr)
|
---|
160 | {
|
---|
161 | rc = ConvertAndInstallTable(&gEfiSmbiosTableGuid, Ptr);
|
---|
162 | ASSERT_EFI_ERROR (rc);
|
---|
163 | }
|
---|
164 |
|
---|
165 | Ptr = FindMPSPtr();
|
---|
166 | DEBUG((DEBUG_INFO, "MPS=%p\n", Ptr));
|
---|
167 | // MPS can be null in non IO-APIC configs
|
---|
168 | if (Ptr)
|
---|
169 | rc = ConvertAndInstallTable(&gEfiMpsTableGuid, Ptr);
|
---|
170 |
|
---|
171 | return EFI_SUCCESS;
|
---|
172 | }
|
---|
173 |
|
---|
174 | EFI_STATUS EFIAPI
|
---|
175 | DxeUninitializeVBoxSysTables(IN EFI_HANDLE ImageHandle)
|
---|
176 | {
|
---|
177 | return EFI_SUCCESS;
|
---|
178 | }
|
---|