hc
2024-03-25 edb30157bad0c0001c32b854271ace01d3b9a16a
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/** @file
 
Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
 
**/
 
#include <Library/BoardInitLib.h>
#include <Library/MultiBoardInitSupportLib.h>
#include <Library/PcdLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PeiServicesLib.h>
 
/**
  Registers the given function for callback during board detection.
 
  When this function is called the given function pointer is added to an internal list. When board detection is
  performed within the BoardDetect() API, the function pointers in the list will be invoked until a board
  detection function reports it has successfully detected the board.
 
  @param[in]    BoardDetect             A pointer to a function of type BOARD_DETECT_FUNC that is called during
                                        board detection.
 
  @retval       EFI_SUCCESS             The function was successfully registered.
  @retval       EFI_INVALID_PARAMETER   The function pointer given is NULL.
  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources exist to add a new board detection callback.
 
**/
EFI_STATUS
EFIAPI
RegisterBoardDetect (
  IN BOARD_DETECT_FUNC  *BoardDetect
  )
{
  EFI_STATUS                 Status;
  EFI_PEI_PPI_DESCRIPTOR     *PpiListBoardDetect;
 
  if (BoardDetect == NULL) {
    return EFI_INVALID_PARAMETER;
  }
 
  PpiListBoardDetect = AllocatePool (sizeof (EFI_PEI_PPI_DESCRIPTOR));
  if (PpiListBoardDetect == NULL) {
    ASSERT (PpiListBoardDetect != NULL);
    return EFI_OUT_OF_RESOURCES;
  }
 
  PpiListBoardDetect->Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
  PpiListBoardDetect->Guid  = &gBoardDetectGuid;
  PpiListBoardDetect->Ppi   = BoardDetect;
 
  Status = PeiServicesInstallPpi (PpiListBoardDetect);
  ASSERT_EFI_ERROR (Status);
 
  return Status;
}
 
/**
  Registers the given set of board functions for callback to perform pre-memory board initialization tasks.
 
  When this function is called, the given structure of function pointers are stored for future invocation. When
  board pre-memory initialization tasks are required, the corresponding pre-memory function in this structure
  will be called. Typically, RegisterBoardPreMemInit() is called during board detection with the successfully
  detected board providing its set of board-specific pre-memory initialization functions.
 
  @param[in]    BoardPreMemInit         A pointer to a structure of function pointers described in the type
                                        BOARD_PRE_MEM_INIT_FUNC.
 
  @retval       EFI_SUCCESS             The board pre-memory functions were successfully registered.
  @retval       EFI_INVALID_PARAMETER   The pointer given is NULL.
  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources exist to register the callback functions.
 
**/
EFI_STATUS
EFIAPI
RegisterBoardPreMemInit (
  IN BOARD_PRE_MEM_INIT_FUNC  *BoardPreMemInit
  )
{
  EFI_STATUS                 Status;
  EFI_PEI_PPI_DESCRIPTOR     *PpiListBoardInitPreMem;
 
  if (BoardPreMemInit == NULL) {
    return EFI_OUT_OF_RESOURCES;
  }
 
  PpiListBoardInitPreMem = AllocatePool (sizeof (EFI_PEI_PPI_DESCRIPTOR));
  if (PpiListBoardInitPreMem == NULL) {
    ASSERT (PpiListBoardInitPreMem != NULL);
    return EFI_OUT_OF_RESOURCES;
  }
 
  PpiListBoardInitPreMem->Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
  PpiListBoardInitPreMem->Guid  = &gBoardPreMemInitGuid;
  PpiListBoardInitPreMem->Ppi   = BoardPreMemInit;
 
  Status = PeiServicesInstallPpi (PpiListBoardInitPreMem);
  ASSERT_EFI_ERROR (Status);
 
  return Status;
}
 
/**
  Registers the given set of board functions for callback to perform post-memory board initialization tasks.
 
  When this function is called, the given structure of function pointers are stored for future invocation. When
  board post-memory initialization tasks are required, the corresponding post-memory function in this structure
  will be called. Typically, RegisterBoardPostMemInit() is called during board detection with the successfuly
  detected board providing its set of board-specific post-memory initialization functions.
 
  @param[in]    BoardPostMemInit        A pointer to a structure of function pointers described in the type
                                        BOARD_POST_MEM_INIT_FUNC.
 
  @retval       EFI_SUCCESS             The board post-memory functions were successfully registered.
  @retval       EFI_INVALID_PARAMETER   The pointer given is NULL.
  @retval       EFI_OUT_OF_RESOURCES    Insufficient memory resources exist to register the callback functions.
 
**/
EFI_STATUS
EFIAPI
RegisterBoardPostMemInit (
  IN BOARD_POST_MEM_INIT_FUNC  *BoardPostMemInit
  )
{
  EFI_STATUS                 Status;
  EFI_PEI_PPI_DESCRIPTOR     *PpiListBoardInitPostMem;
 
  if (BoardPostMemInit == NULL) {
    return EFI_INVALID_PARAMETER;
  }
 
  PpiListBoardInitPostMem = AllocatePool (sizeof (EFI_PEI_PPI_DESCRIPTOR));
  if (PpiListBoardInitPostMem == NULL) {
    ASSERT (PpiListBoardInitPostMem != NULL);
    return EFI_OUT_OF_RESOURCES;
  }
 
  PpiListBoardInitPostMem->Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
  PpiListBoardInitPostMem->Guid  = &gBoardPostMemInitGuid;
  PpiListBoardInitPostMem->Ppi   = BoardPostMemInit;
 
  Status = PeiServicesInstallPpi (PpiListBoardInitPostMem);
  ASSERT_EFI_ERROR (Status);
 
  return Status;
}