hc
2024-03-22 a0752693d998599af469473b8dc239ef973a012f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/** @file
  This file contains GpioMemLib implementation for PEI phase
 
  Copyright (c) 2019 Intel Corporation. All rights reserved. <BR>
 
  SPDX-License-Identifier: BSD-2-Clause-Patent
**/
 
#include <Library/HobLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Private/Library/GpioNameBufferLib.h>
 
STATIC CONST EFI_GUID mGpioNamesPrivateHobGuid = {0x9AE3138D, 0x4EBF, 0x4E90, {0x87, 0x96, 0x11, 0xD3, 0x10, 0x04, 0x60, 0x0A}};
 
STATIC volatile BOOLEAN mGlobalMemoryWorking = FALSE;
 
STATIC CHAR8 mGpioNameBuffer[GPIO_NAME_LENGTH_MAX];
 
/**
  Returns pointer to the buffer taken from GpioLib private HOB
 
  @retval CHAR8*  Pointer to the buffer
**/
STATIC
CHAR8*
GetBufferFromHob (
  VOID
  )
{
  VOID  *Hob;
  CHAR8 *GpioNameBuffer;
 
  Hob = NULL;
  GpioNameBuffer = NULL;
 
  Hob = GetFirstGuidHob (&mGpioNamesPrivateHobGuid);
  if (Hob != NULL){
    GpioNameBuffer = (CHAR8*) GET_GUID_HOB_DATA (Hob);
  } else {
    GpioNameBuffer = (CHAR8*) BuildGuidHob (&mGpioNamesPrivateHobGuid, GPIO_NAME_LENGTH_MAX);
    if (GpioNameBuffer == NULL){
      DEBUG ((DEBUG_ERROR, "Failed to setup HOB for GPIO names lib\n"));
      ASSERT (FALSE);
    }
  }
  return GpioNameBuffer;
}
 
/**
  Returns pointer to the global buffer to be used by GpioNamesLib
 
  @retval CHAR8*  Pointer to the buffer
**/
CHAR8*
GpioGetStaticNameBuffer (
  VOID
  )
{
  mGlobalMemoryWorking = TRUE;
 
  if (mGlobalMemoryWorking) {
    return mGpioNameBuffer;
  } else {
    return GetBufferFromHob ();
  }
}