summaryrefslogtreecommitdiff
path: root/Platform/Intel/MinPlatformPkg/Pci/Library/PciSegmentInfoLibSimple/PciSegmentInfoLibSimple.c
blob: 1facc63d0179d8a0e701635edf38229c3c8ca6f7 (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
/** @file
  Default PCI Segment Information Library that returns one segment whose
  segment base address equals to PcdPciExpressBaseAddress.

  Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
  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.

**/

#include <Base.h>
#include <Library/PciSegmentInfoLib.h>
#include <Library/DebugLib.h>
#include <Library/HobLib.h>
#include <Library/PcdLib.h>

#define PCI_SEGMENT_INFO_HOB_GUID { \
  0x6eab7169, 0x9b21, 0x450e, 0x99, 0xe8, 0xe, 0xb1, 0x1b, 0x7d, 0xfe, 0xcb \
  }

EFI_GUID  mPciSegmentInfoHobGuid = PCI_SEGMENT_INFO_HOB_GUID;

/**
  Return an array of PCI_SEGMENT_INFO holding the segment information.

  Note: The returned array/buffer is owned by callee.

  @param  Count  Return the count of segments.

  @retval A callee owned array holding the segment information.
**/
PCI_SEGMENT_INFO *
EFIAPI
GetPciSegmentInfo (
  OUT UINTN  *Count
  )
{
  VOID              *Hob;
  PCI_SEGMENT_INFO  *PciSegmentInfo;

  if (Count == NULL) {
    return NULL;
  }

  *Count = 1;
  Hob = GetFirstGuidHob (&mPciSegmentInfoHobGuid);
  if (Hob != NULL) {
    PciSegmentInfo = GET_GUID_HOB_DATA(Hob);
  } else {
    PciSegmentInfo = BuildGuidHob (&mPciSegmentInfoHobGuid, sizeof(PCI_SEGMENT_INFO));
    ASSERT(PciSegmentInfo != NULL);
    if (PciSegmentInfo == NULL) {
      return NULL;
    }
    PciSegmentInfo->SegmentNumber = 0;
    PciSegmentInfo->BaseAddress = PcdGet64(PcdPciExpressBaseAddress);
    PciSegmentInfo->StartBusNumber = 0;
    PciSegmentInfo->EndBusNumber = 0xFF;
  }
  return PciSegmentInfo;
}