VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/VBoxAppleSim/DataHub.c

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.4 KB
Line 
1/* $Id: DataHub.c 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * Console.c - VirtualBox Console control emulation
4 */
5
6/*
7 * Copyright (C) 2010-2023 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#include <Uefi.h>
37#include <Library/BaseLib.h>
38#include <Library/BaseMemoryLib.h>
39#include <Library/MemoryAllocationLib.h>
40#include <Library/UefiBootServicesTableLib.h>
41#include <Library/DebugLib.h>
42#include <Library/UefiLib.h>
43
44#include "VBoxPkg.h"
45#include "DataHub.h"
46
47/**
48 * Data hub logged entry.
49 */
50typedef struct
51{
52 /** List node for the linked list - must be at the top. */
53 LIST_ENTRY NdEntries;
54 /** The record header. */
55 EFI_DATA_RECORD_HEADER RecHdr;
56 /** The data logged, variable in size. */
57 UINT8 abData[1];
58} EFI_DATA_HUB_ENTRY;
59
60/**
61 * DataHub instance data.
62 */
63typedef struct
64{
65 /** Monotonic increasing counter. */
66 UINT64 cMonotonicCnt;
67 /** Linked list holding the logged entries. */
68 LIST_ENTRY LstEntries;
69 /** The lock protecting the key members above. */
70 EFI_LOCK Lck;
71} EFI_DATA_HUB_INSTANCE;
72
73
74EFI_DATA_HUB_INSTANCE mDataHubInstance;
75
76EFI_STATUS EFIAPI
77DataHubLogData (
78 IN EFI_DATA_HUB_PROTOCOL *This,
79 IN EFI_GUID *DataRecordGuid,
80 IN EFI_GUID *ProducerName,
81 IN UINT64 DataRecordClass,
82 IN VOID *RawData,
83 IN UINT32 RawDataSize
84 )
85{
86 UINT32 cbEntry = sizeof(EFI_DATA_HUB_ENTRY) + RawDataSize;
87 EFI_DATA_HUB_ENTRY *pEntry = AllocatePool(cbEntry);
88
89 if (pEntry == NULL)
90 return EFI_OUT_OF_RESOURCES;
91
92 pEntry->RecHdr.Version = EFI_DATA_RECORD_HEADER_VERSION;
93 pEntry->RecHdr.HeaderSize = sizeof(EFI_DATA_RECORD_HEADER);
94 pEntry->RecHdr.RecordSize = RawDataSize + sizeof(EFI_DATA_RECORD_HEADER);
95 CopyMem(&pEntry->RecHdr.DataRecordGuid, DataRecordGuid, sizeof(pEntry->RecHdr.DataRecordGuid));
96 CopyMem(&pEntry->RecHdr.ProducerName, ProducerName, sizeof(pEntry->RecHdr.ProducerName));
97 pEntry->RecHdr.DataRecordClass = DataRecordClass;
98 SetMem(&pEntry->RecHdr.LogTime, sizeof(pEntry->RecHdr.LogTime), 0);
99 pEntry->RecHdr.LogMonotonicCount = ++mDataHubInstance.cMonotonicCnt; /* Ensure non zero value in record. */
100 CopyMem(&pEntry->abData[0], RawData, RawDataSize);
101
102 EfiAcquireLock(&mDataHubInstance.Lck);
103 InsertTailList(&mDataHubInstance.LstEntries, &pEntry->NdEntries);
104 EfiReleaseLock(&mDataHubInstance.Lck);
105 return EFI_SUCCESS;
106}
107
108
109EFI_STATUS EFIAPI
110DataHubGetNextDataRecord (
111 IN EFI_DATA_HUB_PROTOCOL *This,
112 IN OUT UINT64 *MonotonicCount,
113 IN EFI_EVENT *FilterDriver OPTIONAL,
114 OUT EFI_DATA_RECORD_HEADER **Record
115 )
116{
117 EFI_DATA_HUB_ENTRY *pEntry = NULL;
118
119 EfiAcquireLock(&mDataHubInstance.Lck);
120 if (*MonotonicCount == 0)
121 {
122 if (!IsListEmpty(&mDataHubInstance.LstEntries))
123 pEntry = (EFI_DATA_HUB_ENTRY *)GetFirstNode(&mDataHubInstance.LstEntries);
124 }
125 else
126 {
127 /* Ignore filter driver handling for now. */
128 LIST_ENTRY *pHead = &mDataHubInstance.LstEntries;
129 LIST_ENTRY *pIt = NULL;
130
131 for (pIt = GetFirstNode(pHead); pIt != pHead; pIt = GetNextNode(pHead, pIt))
132 {
133 EFI_DATA_HUB_ENTRY *pTmp = (EFI_DATA_HUB_ENTRY *)pIt;
134 if (pTmp->RecHdr.LogMonotonicCount == *MonotonicCount)
135 {
136 pEntry = pTmp;
137 break;
138 }
139 }
140 }
141 EfiReleaseLock(&mDataHubInstance.Lck);
142
143 if (pEntry == NULL)
144 return EFI_NOT_FOUND;
145
146 *Record = &pEntry->RecHdr;
147
148 /* Look for the next entry and set MonotonicCount accordingly. */
149 if (!IsNodeAtEnd(&mDataHubInstance.LstEntries, &pEntry->NdEntries))
150 {
151 pEntry = (EFI_DATA_HUB_ENTRY *)GetNextNode(&mDataHubInstance.LstEntries, &pEntry->NdEntries);
152 *MonotonicCount = pEntry->RecHdr.LogMonotonicCount;
153 }
154 else
155 *MonotonicCount = 0;
156
157 return EFI_SUCCESS;
158}
159
160
161EFI_STATUS EFIAPI
162DataHubRegisterDataFilterDriver (
163 IN EFI_DATA_HUB_PROTOCOL *This,
164 IN EFI_EVENT FilterEvent,
165 IN EFI_TPL FilterTpl,
166 IN UINT64 FilterClass,
167 IN EFI_GUID *FilterDataRecordGui OPTIONAL
168 )
169{
170 return EFI_SUCCESS;
171}
172
173
174EFI_STATUS EFIAPI
175DataHubUnregisterDataFilterDriver (
176 IN EFI_DATA_HUB_PROTOCOL *This,
177 IN EFI_EVENT FilterEvent
178 )
179{
180 return EFI_SUCCESS;
181}
182
183
184EFI_DATA_HUB_PROTOCOL gDataHub =
185{
186 DataHubLogData,
187 DataHubGetNextDataRecord,
188 DataHubRegisterDataFilterDriver,
189 DataHubUnregisterDataFilterDriver
190};
191
192EFI_GUID gEfiDataHubProtocolGuid = EFI_DATA_HUB_PROTOCOL_GUID;
193
194EFI_STATUS
195EFIAPI
196InitializeDataHub (
197 IN EFI_HANDLE ImageHandle,
198 IN EFI_SYSTEM_TABLE *SystemTable
199 )
200{
201 EFI_STATUS Status;
202
203
204 InitializeListHead(&mDataHubInstance.LstEntries);
205 EfiInitializeLock (&mDataHubInstance.Lck, TPL_NOTIFY);
206
207 Status = gBS->InstallMultipleProtocolInterfaces (
208 &ImageHandle,
209 &gEfiDataHubProtocolGuid,
210 &gDataHub,
211 NULL);
212 ASSERT_EFI_ERROR (Status);
213
214 return Status;
215}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use