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