summaryrefslogtreecommitdiff
path: root/EDK/Foundation/Core/Pei/DebugMask/DebugMask.c
blob: a804eda39c1bad72388ff2fae48ee6b22cb49c68 (plain)
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
148
149
150
151
152
153
154
155
156
/*++

Copyright (c) 2009 - 2010, Intel Corporation                                                         
All rights reserved. This program and the accompanying materials                          
are licensed and made available under the terms and conditions of the BSD License         
which accompanies this distribution.  The full text of the license may be found at        
http://opensource.org/licenses/bsd-license.php                                            
                                                                                          
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             

Module Name:

  DebugMask.c
    
Abstract:

  Installs DebugMask PPI.

--*/

#include "Tiano.h"
#include "PeiCore.h"
#include EFI_PPI_CONSUMER (DebugMask)
#include EFI_PPI_DEPENDENCY (Variable)
#include EFI_GUID_DEFINITION (GlobalVariable)

EFI_STATUS
EFIAPI
DebugMaskNotifyCallback (
  IN EFI_PEI_SERVICES           **PeiServices,
  IN EFI_PEI_NOTIFY_DESCRIPTOR  *NotifyDescriptor,
  IN VOID                       *Ppi
  );

static EFI_PEI_NOTIFY_DESCRIPTOR mNotifyList = {
   EFI_PEI_PPI_DESCRIPTOR_NOTIFY_DISPATCH | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
   &gPeiReadOnlyVariablePpiGuid,
   DebugMaskNotifyCallback
};

VOID
InstallCoreDebugMaskPpi (
  IN EFI_PEI_SERVICES  **PeiServices,
  IN PEI_CORE_INSTANCE *OldCoreData
  )
/*++

Routine Description:

  Installs DebugMask PPI.

Arguments:

  PeiServices - The PEI core services table.
  OldCoreData - Pointer to the old core data.
                NULL if being run in non-permament memory mode.
Returns:

  None

--*/
{
  EFI_STATUS                      Status;
  EFI_DEBUG_MASK_PPI              *DebugMaskPpi;
  EFI_PEI_PPI_DESCRIPTOR          *DebugMaskPpiDesc;

  if (OldCoreData == NULL) {
    Status = ((*PeiServices)->AllocatePool) (PeiServices, sizeof (EFI_DEBUG_MASK_PPI), &DebugMaskPpi);
    if (EFI_ERROR(Status) || (DebugMaskPpi == NULL)) {
      return;
    }

    Status = ((*PeiServices)->AllocatePool) (PeiServices, sizeof (EFI_PEI_PPI_DESCRIPTOR), &DebugMaskPpiDesc);
    if (EFI_ERROR(Status) || (DebugMaskPpiDesc == NULL)) {
      return;
    }

    DebugMaskPpiDesc->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
    DebugMaskPpiDesc->Guid  = &gEfiDebugMaskPpiGuid;
    DebugMaskPpiDesc->Ppi   = DebugMaskPpi;

    DebugMaskPpi->ImageDebugMask = gErrorLevel;

    Status = (**PeiServices).InstallPpi (PeiServices, DebugMaskPpiDesc);
    ASSERT_PEI_ERROR (PeiServices, Status);
    if (EFI_ERROR(Status)) {
      return;
    }

    PeiNotifyPpi (PeiServices, &mNotifyList);
  }
  return;
}

EFI_STATUS
EFIAPI
DebugMaskNotifyCallback (
  IN EFI_PEI_SERVICES           **PeiServices,
  IN EFI_PEI_NOTIFY_DESCRIPTOR  *NotifyDescriptor,
  IN VOID                       *Ppi
  )
/*++

Routine Description:

  Callback function to update DebugMask value

Arguments:

  PeiServices       - The PEI core services table.
  NotifyDescriptor  - The descriptor for the notification event.
  Ppi               - Pointer to the PPI in question.

Returns:

  EFI_SUCCESS - The function is successfully processed.

--*/
{
  EFI_STATUS                      Status;
  PEI_READ_ONLY_VARIABLE_PPI      *VariableServices;
  UINTN                           DebugMaskSize;
  UINT64                          DebugMask;
  EFI_DEBUG_MASK_PPI              *DebugMaskPpi;

  //
  // Locate Variable Ppi
  //
  Status = (*PeiServices)->LocatePpi (PeiServices, &gPeiReadOnlyVariablePpiGuid, 0, NULL, &VariableServices);

  if (VariableServices) {
    //
    // Get L"EFIDebug" Variable
    //
    DebugMaskSize = sizeof (UINT32);
    Status = VariableServices->PeiGetVariable (
                                PeiServices,
                                L"EFIDebug",
                                &gEfiGlobalVariableGuid,
                                NULL,
                                &DebugMaskSize,
                                &DebugMask
                                );

    if (!EFI_ERROR(Status)) {
      Status = (*PeiServices)->LocatePpi (PeiServices, &gEfiDebugMaskPpiGuid, 0, NULL, &DebugMaskPpi);

      if (!EFI_ERROR(Status)) {
        DebugMaskPpi->ImageDebugMask = (UINTN)DebugMask;
      }
    }
  }

  return Status;
}