]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/PlatformDebugLibIoPort/DebugLibDetect.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / OvmfPkg / Library / PlatformDebugLibIoPort / DebugLibDetect.c
1 /** @file
2 Detection code for hypervisor debug port.
3 Non-SEC instance, caches the result of detection.
4
5 Copyright (c) 2017, Red Hat, Inc.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include <Base.h>
11 #include "DebugLibDetect.h"
12
13 //
14 // Set to TRUE if the debug I/O port has been checked
15 //
16 STATIC BOOLEAN mDebugIoPortChecked = FALSE;
17
18 //
19 // Set to TRUE if the debug I/O port is enabled
20 //
21 STATIC BOOLEAN mDebugIoPortFound = FALSE;
22
23 /**
24 This constructor function must not do anything.
25
26 Some modules consuming this library instance, such as the DXE Core, invoke
27 the DEBUG() macro before they explicitly call
28 ProcessLibraryConstructorList(). Therefore the auto-generated call from
29 ProcessLibraryConstructorList() to this constructor function may be preceded
30 by some calls to PlatformDebugLibIoPortFound() below. Hence
31 PlatformDebugLibIoPortFound() must not rely on anything this constructor
32 could set up.
33
34 @retval RETURN_SUCCESS The constructor always returns RETURN_SUCCESS.
35
36 **/
37 RETURN_STATUS
38 EFIAPI
39 PlatformDebugLibIoPortConstructor (
40 VOID
41 )
42 {
43 return RETURN_SUCCESS;
44 }
45
46 /**
47 At the first call, check if the debug I/O port device is present, and cache
48 the result for later use. At subsequent calls, return the cached result.
49
50 @retval TRUE if the debug I/O port device was detected.
51 @retval FALSE otherwise
52
53 **/
54 BOOLEAN
55 EFIAPI
56 PlatformDebugLibIoPortFound (
57 VOID
58 )
59 {
60 if (!mDebugIoPortChecked) {
61 mDebugIoPortFound = PlatformDebugLibIoPortDetect ();
62 mDebugIoPortChecked = TRUE;
63 }
64
65 return mDebugIoPortFound;
66 }