1840afc55219b5ed4ca9e241408093d5ecaf9b90
[coreboot.git] / src / mainboard / amd / inagua / PlatformGnbPcie.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2011 Advanced Micro Devices, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  */
19
20 #include "AGESA.h"
21 #include "amdlib.h"
22 #include "Ids.h"
23 #include "heapManager.h"
24 #include "PlatformGnbPcieComplex.h"
25 #include "Filecode.h"
26
27 #define FILECODE PROC_RECOVERY_MEM_NB_ON_MRNON_FILECODE
28
29 PCIe_PORT_DESCRIPTOR PortList [] = {
30         // Initialize Port descriptor (PCIe port, Lanes 4, PCI Device Number 4, ...)
31         {
32           0, //Descriptor flags  !!!IMPORTANT!!! Terminate last element of array
33           PCIE_ENGINE_DATA_INITIALIZER (PciePortEngine, 4, 4),
34           PCIE_PORT_DATA_INITIALIZER (GNB_GPP_PORT4_PORT_PRESENT, GNB_GPP_PORT4_CHANNEL_TYPE, 4, GNB_GPP_PORT4_HOTPLUG_SUPPORT, GNB_GPP_PORT4_SPEED_MODE, GNB_GPP_PORT4_SPEED_MODE, GNB_GPP_PORT4_LINK_ASPM, 4)
35         },
36         // Initialize Port descriptor (PCIe port, Lanes 5, PCI Device Number 5, ...)
37         {
38           0, //Descriptor flags  !!!IMPORTANT!!! Terminate last element of array
39           PCIE_ENGINE_DATA_INITIALIZER (PciePortEngine, 5, 5),
40           PCIE_PORT_DATA_INITIALIZER (GNB_GPP_PORT5_PORT_PRESENT, GNB_GPP_PORT5_CHANNEL_TYPE, 5, GNB_GPP_PORT5_HOTPLUG_SUPPORT, GNB_GPP_PORT5_SPEED_MODE, GNB_GPP_PORT5_SPEED_MODE, GNB_GPP_PORT5_LINK_ASPM, 5)
41         },
42         // Initialize Port descriptor (PCIe port, Lanes 6, PCI Device Number 6, ...)
43         {
44           0, //Descriptor flags  !!!IMPORTANT!!! Terminate last element of array
45           PCIE_ENGINE_DATA_INITIALIZER (PciePortEngine, 6, 6),
46           PCIE_PORT_DATA_INITIALIZER (GNB_GPP_PORT6_PORT_PRESENT, GNB_GPP_PORT6_CHANNEL_TYPE, 6, GNB_GPP_PORT6_HOTPLUG_SUPPORT, GNB_GPP_PORT6_SPEED_MODE, GNB_GPP_PORT6_SPEED_MODE, GNB_GPP_PORT6_LINK_ASPM, 6)
47         },
48         // Initialize Port descriptor (PCIe port, Lanes 7, PCI Device Number 7, ...)
49         {
50           0,
51           PCIE_ENGINE_DATA_INITIALIZER (PciePortEngine, 7, 7),
52           PCIE_PORT_DATA_INITIALIZER (GNB_GPP_PORT7_PORT_PRESENT, GNB_GPP_PORT7_CHANNEL_TYPE, 7, GNB_GPP_PORT7_HOTPLUG_SUPPORT, GNB_GPP_PORT7_SPEED_MODE, GNB_GPP_PORT7_SPEED_MODE, GNB_GPP_PORT7_LINK_ASPM, 7)
53         },
54         // Initialize Port descriptor (PCIe port, Lanes 8, PCI Device Number 8, ...)
55         {
56           DESCRIPTOR_TERMINATE_LIST, //Descriptor flags  !!!IMPORTANT!!! Terminate last element of array
57           PCIE_ENGINE_DATA_INITIALIZER (PciePortEngine, 0, 3),
58           PCIE_PORT_DATA_INITIALIZER (GNB_GPP_PORT8_PORT_PRESENT, GNB_GPP_PORT8_CHANNEL_TYPE, 8, GNB_GPP_PORT8_HOTPLUG_SUPPORT, GNB_GPP_PORT8_SPEED_MODE, GNB_GPP_PORT8_SPEED_MODE, GNB_GPP_PORT8_LINK_ASPM, 0)
59         }       
60 };
61
62 PCIe_DDI_DESCRIPTOR DdiList [] = {
63         // Initialize Ddi descriptor (DDI interface Lanes 8:11, DdA, ...)
64         {
65           0,   //Descriptor flags
66           PCIE_ENGINE_DATA_INITIALIZER (PcieDdiEngine, 8, 11),
67           //PCIE_DDI_DATA_INITIALIZER (ConnectorTypeDP, Aux1, Hdp1)
68           {ConnectorTypeDP, Aux1, Hdp1}
69         },
70         // Initialize Ddi descriptor (DDI interface Lanes 12:15, DdB, ...)
71         {
72           DESCRIPTOR_TERMINATE_LIST, //Descriptor flags  !!!IMPORTANT!!! Terminate last element of array
73           PCIE_ENGINE_DATA_INITIALIZER (PcieDdiEngine, 12, 15),
74           //PCIE_DDI_DATA_INITIALIZER (ConnectorTypeDP, Aux2, Hdp2)
75           {ConnectorTypeDP, Aux2, Hdp2}
76         }
77 };
78
79 PCIe_COMPLEX_DESCRIPTOR Brazos = {
80         DESCRIPTOR_TERMINATE_LIST,
81         0,
82         &PortList[0],
83         &DdiList[0]
84 };
85
86 /*---------------------------------------------------------------------------------------*/
87 /**
88  *  OemCustomizeInitEarly
89  *
90  *  Description:
91  *    This is the stub function will call the host environment through the binary block
92  *    interface (call-out port) to provide a user hook opportunity
93  *
94  *  Parameters:
95  *    @param[in]      **PeiServices
96  *    @param[in]      *InitEarly
97  *
98  *    @retval         VOID
99  *
100  **/
101 /*---------------------------------------------------------------------------------------*/
102 VOID
103 OemCustomizeInitEarly (
104   IN  OUT AMD_EARLY_PARAMS    *InitEarly
105   )
106 {
107   AGESA_STATUS         Status;
108   VOID                 *BrazosPcieComplexListPtr;
109   VOID                 *BrazosPciePortPtr;
110   VOID                 *BrazosPcieDdiPtr;
111
112   ALLOCATE_HEAP_PARAMS AllocHeapParams;
113
114   // GNB PCIe topology Porting
115
116   //
117   // Allocate buffer for PCIe_COMPLEX_DESCRIPTOR , PCIe_PORT_DESCRIPTOR and PCIe_DDI_DESCRIPTOR
118   //
119   AllocHeapParams.RequestedBufferSize = (sizeof (PCIe_COMPLEX_DESCRIPTOR)  + 
120                                          sizeof (PCIe_PORT_DESCRIPTOR) * 5 + 
121                                          sizeof (PCIe_DDI_DESCRIPTOR)) * 2;
122
123   AllocHeapParams.BufferHandle = AMD_MEM_MISC_HANDLES_START;
124   AllocHeapParams.Persist = HEAP_LOCAL_CACHE;
125   Status = HeapAllocateBuffer (&AllocHeapParams, &InitEarly->StdHeader);
126   if ( Status!= AGESA_SUCCESS) {
127     // Could not allocate buffer for PCIe_COMPLEX_DESCRIPTOR , PCIe_PORT_DESCRIPTOR and PCIe_DDI_DESCRIPTOR
128     ASSERT(FALSE); 
129     return Status;
130   }
131   
132   BrazosPcieComplexListPtr  =  (PCIe_COMPLEX_DESCRIPTOR *) AllocHeapParams.BufferPtr;
133
134   AllocHeapParams.BufferPtr += sizeof (PCIe_COMPLEX_DESCRIPTOR);
135   BrazosPciePortPtr         =  (PCIe_PORT_DESCRIPTOR *)AllocHeapParams.BufferPtr;
136
137   AllocHeapParams.BufferPtr += sizeof (PCIe_PORT_DESCRIPTOR) * 5;
138   BrazosPcieDdiPtr          =  (PCIe_DDI_DESCRIPTOR *) AllocHeapParams.BufferPtr;
139  
140   LibAmdMemFill (BrazosPcieComplexListPtr,
141                    0,
142                    sizeof (PCIe_COMPLEX_DESCRIPTOR),
143                    &InitEarly->StdHeader);
144
145   LibAmdMemFill (BrazosPciePortPtr,
146                    0,
147                    sizeof (PCIe_PORT_DESCRIPTOR) * 5,
148                    &InitEarly->StdHeader);
149      
150   LibAmdMemFill (BrazosPcieDdiPtr,
151                    0,
152                    sizeof (PCIe_DDI_DESCRIPTOR) * 2,
153                    &InitEarly->StdHeader);
154
155   LibAmdMemCopy  (BrazosPcieComplexListPtr, &Brazos, sizeof (PCIe_COMPLEX_DESCRIPTOR), &InitEarly->StdHeader);
156   LibAmdMemCopy  (BrazosPciePortPtr, &PortList[0], sizeof (PCIe_PORT_DESCRIPTOR) * 5, &InitEarly->StdHeader);
157   LibAmdMemCopy  (BrazosPcieDdiPtr, &DdiList[0], sizeof (PCIe_DDI_DESCRIPTOR) *2, &InitEarly->StdHeader);
158
159
160   ((PCIe_COMPLEX_DESCRIPTOR*)BrazosPcieComplexListPtr)->PciePortList =  (PCIe_PORT_DESCRIPTOR*)BrazosPciePortPtr;
161   ((PCIe_COMPLEX_DESCRIPTOR*)BrazosPcieComplexListPtr)->DdiLinkList  =  (PCIe_DDI_DESCRIPTOR*)BrazosPcieDdiPtr;
162
163   InitEarly->GnbConfig.PcieComplexList = BrazosPcieComplexListPtr; 
164   InitEarly->GnbConfig.PsppPolicy      = 0; 
165 }
166