summaryrefslogtreecommitdiff
path: root/Vlv2TbltDevicePkg/PlatformDxe/SlotConfig.c
blob: c0c752601f64e4b4c9a62817bd0b465f9f76701d (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
/** @file

  Copyright (c) 2004  - 2014, 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 that 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:

  SlotConfig.c

Abstract:

  Sets platform/SKU specific expansion slot information.



--*/
#include "SlotConfig.h"

//
// Implementation
//
VOID
InitializeSlotInfo (
  )
{
  UINT16                              BusSaveState;
  UINT16                              Vendor;
  UINT8                               CurrentBus;
  UINTN                               i;
  UINTN                               j;
  EFI_HANDLE                          Handle;
  EFI_STATUS                          Status;
  BOOLEAN                             RunNext;

  //
  // Loop through the slot table and see if any slots have cards in them
  //
  for (i = 0; i < mSlotBridgeTableSize; i++) {
    //
    // Initialize variable
    //
    RunNext = FALSE;

    //
    // Hide mini PCIe slots per SKU
    //
    for (j = 0; j < mSlotInformation.NumberOfEntries; j++) {
      if (mSlotInformation.SlotEntries[j].SmbiosSlotId == mSlotBridgeTable[i].SmbiosSlotId) {
        if ((mSlotInformation.SlotEntries[j].SmbiosSlotId == 0x02) &&
            (mBoardFeatures & B_BOARD_FEATURES_NO_MINIPCIE)
          ) {
          mSlotInformation.SlotEntries[j].Disabled = TRUE;
          RunNext = TRUE;
        }
        break;
      }
    }

    if (RunNext) {
      //
      // Skip slot device detection since the slot is disabled.
      //
      continue;
    }

    //
    // Check to see if the bridge has a bus number and assign one if not
    //
    BusSaveState = MmPci16 (
      0,
      mSlotBridgeTable[i].Bus,
      mSlotBridgeTable[i].Dev,
      mSlotBridgeTable[i].Function,
      PCI_BRIDGE_SECONDARY_BUS_REGISTER_OFFSET
                            );
    if (BusSaveState == 0) {
      //
      // Assign temp bus number
      //
      MmPci16 (
        0,
        mSlotBridgeTable[i].Bus,
        mSlotBridgeTable[i].Dev,
        mSlotBridgeTable[i].Function,
        PCI_BRIDGE_SECONDARY_BUS_REGISTER_OFFSET
        ) = DEF_BUS_CONFIG;
      CurrentBus = DEF_BUS;
    } else if (BusSaveState == 0xFFFF) {
      //
      // Bridge is disabled so continue with next entry in the table
      //
      continue;
    } else {
      //
      // Use existing bus number
      //
      CurrentBus = (UINT8) BusSaveState & 0xFF;
    }

    //
    // Check to see if a device is behind the bridge
    //
    Vendor = MmPci16 (
               0,
               CurrentBus,
               mSlotBridgeTable[i].TargetDevice,
               0,
               0
               );
    if (Vendor != 0xFFFF) {
      //
      // Device found so make sure the slot is marked that way
      //
      for (j = 0; j < mSlotInformation.NumberOfEntries; j++) {
        if (mSlotInformation.SlotEntries[j].SmbiosSlotId == mSlotBridgeTable[i].SmbiosSlotId) {
          mSlotInformation.SlotEntries[j].InUse = TRUE;
          break;
        }
      }
    }

    //
    // Restore previous bus information
    //
    if (BusSaveState == 0) {
      MmPci16 (
        0,
        mSlotBridgeTable[i].Bus,
        mSlotBridgeTable[i].Dev,
        mSlotBridgeTable[i].Function,
        PCI_BRIDGE_SECONDARY_BUS_REGISTER_OFFSET
        ) = 0;
    }
  }

  Handle = NULL;
  Status = gBS->InstallProtocolInterface (
                  &Handle,
                  &gEfiSmbiosSlotPopulationGuid,
                  EFI_NATIVE_INTERFACE,
                  &mSlotInformation
                  );
  ASSERT_EFI_ERROR(Status);

}