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
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
/** @file
  Gbe Library.
  All function in this library is available for PEI, DXE, and SMM,
  But do not support UEFI RUNTIME environment call.
 
  Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>
  SPDX-License-Identifier: BSD-2-Clause-Patent
**/
 
#include <Base.h>
#include <Uefi/UefiBaseType.h>
#include <Library/IoLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseLib.h>
#include <Library/PciSegmentLib.h>
#include <Library/PchInfoLib.h>
#include <Library/PchPcrLib.h>
#include <Library/PchCycleDecodingLib.h>
#include <Library/PmcPrivateLib.h>
#include <Library/SpiAccessLib.h>
#include <Library/GbeMdiLib.h>
#include <IndustryStandard/Pci30.h>
#include <Register/PchRegs.h>
#include <Register/GbeRegs.h>
#include <Library/PchPciBdfLib.h>
 
/**
  Check whether GbE region is valid
  Check SPI region directly since GbE might be disabled in SW.
 
  @retval TRUE                    Gbe Region is valid
  @retval FALSE                   Gbe Region is invalid
**/
BOOLEAN
IsGbeRegionValid (
  VOID
  )
{
  return SpiIsGbeRegionValid ();
}
 
/**
  Check whether GBE controller is enabled in the platform.
 
  @retval TRUE                    GbE is enabled
  @retval FALSE                   GbE is disabled
**/
BOOLEAN
IsGbePresent (
  VOID
  )
{
  //
  // Check PCH Support
  //
  if (!PchIsGbeSupported ()) {
    return FALSE;
  }
  //
  // Check PMC strap/fuse
  //
  if (!PmcIsGbeSupported ()) {
    return FALSE;
  }
  //
  // Check GbE NVM
  //
  if (IsGbeRegionValid () == FALSE) {
    return FALSE;
  }
  return TRUE;
}
 
/**
  Verifies Gigabit Ethernet PCI Class Code
 
  @param [in]  GbePciCfgBase      GbE PCI Config Space Address
 
  @retval TRUE                    GbE Class Code match
  @retval FALSE                   GbE Class Code does not match
**/
BOOLEAN
STATIC
GbeCheckClassCode (
  UINT64 GbePciCfgBase
  )
{
  UINT8 BaseCode;
  UINT8 SubClassCode;
 
  SubClassCode  = PciSegmentRead8 (GbePciCfgBase + PCI_CLASSCODE_OFFSET + 1);
  BaseCode      = PciSegmentRead8 (GbePciCfgBase + PCI_CLASSCODE_OFFSET + 2);
 
  if ((BaseCode != PCI_CLASS_NETWORK) || (SubClassCode != PCI_CLASS_NETWORK_ETHERNET)) {
    DEBUG ((DEBUG_ERROR, "GbeCheckClassCode : BaseCode(0x%x) or ClassCode(0x%x) is not supported\n", BaseCode, SubClassCode));
    ASSERT (FALSE);
    return FALSE;
  }
  return TRUE;
}
 
/**
  Checks if Gbe is Enabled or Disabled
 
  @retval  BOOLEAN    TRUE if device is enabled, FALSE otherwise.
**/
BOOLEAN
IsGbeEnabled (
  VOID
  )
{
  UINT64  GbePciBase;
 
  GbePciBase = GbePciCfgBase ();
 
  if (PciSegmentRead32 (GbePciBase) != 0xFFFFFFFF) {
    return GbeCheckClassCode (GbePciBase);
  }
 
  return FALSE;
}