]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/PlatformDebugLibIoPort/DebugLibDetect.c
e24cc834c2a3c40214a75ef9fe68e2e96d679005
[mirror_edk2.git] / OvmfPkg / Library / PlatformDebugLibIoPort / DebugLibDetect.c
1 /** @file
2 Detection code for QEMU debug port.
3 Non-SEC instance, caches the result of detection.
4
5 Copyright (c) 2017, Red Hat, Inc.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include <Base.h>
17 #include "DebugLibDetect.h"
18
19 //
20 // Set to TRUE if the debug I/O port has been checked
21 //
22 STATIC BOOLEAN mDebugIoPortChecked = FALSE;
23
24 //
25 // Set to TRUE if the debug I/O port is enabled
26 //
27 STATIC BOOLEAN mDebugIoPortFound = FALSE;
28
29 /**
30 This constructor function must not do anything.
31
32 Some modules consuming this library instance, such as the DXE Core, invoke
33 the DEBUG() macro before they explicitly call
34 ProcessLibraryConstructorList(). Therefore the auto-generated call from
35 ProcessLibraryConstructorList() to this constructor function may be preceded
36 by some calls to PlatformDebugLibIoPortFound() below. Hence
37 PlatformDebugLibIoPortFound() must not rely on anything this constructor
38 could set up.
39
40 @retval RETURN_SUCCESS The constructor always returns RETURN_SUCCESS.
41
42 **/
43 RETURN_STATUS
44 EFIAPI
45 PlatformDebugLibIoPortConstructor (
46 VOID
47 )
48 {
49 return RETURN_SUCCESS;
50 }
51
52 /**
53 At the first call, check if the debug I/O port device is present, and cache
54 the result for later use. At subsequent calls, return the cached result.
55
56 @retval TRUE if the debug I/O port device was detected.
57 @retval FALSE otherwise
58
59 **/
60 BOOLEAN
61 EFIAPI
62 PlatformDebugLibIoPortFound (
63 VOID
64 )
65 {
66 if (!mDebugIoPortChecked) {
67 mDebugIoPortFound = PlatformDebugLibIoPortDetect ();
68 mDebugIoPortChecked = TRUE;
69 }
70 return mDebugIoPortFound;
71 }