AGESA F15: AMD family15 AGESA code
[coreboot.git] / src / vendorcode / amd / agesa / f15 / Proc / HT / htGraph / htGraph.c
1 /* $NoKeywords:$ */
2 /**
3  * @file
4  *
5  * Routines to deal with topology data.
6  *
7  * Access the topologies and information about a topology.
8  *
9  * @xrefitem bom "File Content Label" "Release Content"
10  * @e project:      AGESA
11  * @e sub-project:  HyperTransport
12  * @e \$Revision: 56279 $   @e \$Date: 2011-07-11 13:11:28 -0600 (Mon, 11 Jul 2011) $
13  *
14  */
15 /*
16 *****************************************************************************
17 *
18 * Copyright (C) 2012 Advanced Micro Devices, Inc.
19 * All rights reserved.
20 *
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions are met:
23 *     * Redistributions of source code must retain the above copyright
24 *       notice, this list of conditions and the following disclaimer.
25 *     * Redistributions in binary form must reproduce the above copyright
26 *       notice, this list of conditions and the following disclaimer in the
27 *       documentation and/or other materials provided with the distribution.
28 *     * Neither the name of Advanced Micro Devices, Inc. nor the names of
29 *       its contributors may be used to endorse or promote products derived
30 *       from this software without specific prior written permission.
31 *
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
35 * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
36 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
37 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
38 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
39 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 *
43 * ***************************************************************************
44 *
45 */
46
47 #include "AGESA.h"
48 #include "Ids.h"
49 #include "htGraph.h"
50 #include "OptionsHt.h"
51 #include "Filecode.h"
52 CODE_GROUP (G1_PEICC)
53 RDATA_GROUP (G2_PEI)
54
55 #define FILECODE PROC_HT_HTGRAPH_HTGRAPH_FILECODE
56
57 extern OPTION_HT_CONFIGURATION OptionHtConfiguration;
58
59 /*----------------------------------------------------------------------------------------*/
60 /**
61  * Returns the AGESA built in topology list
62  *
63  * @param[out]    List    a pointer to the built in topology list
64  */
65 VOID
66 GetAmdTopolist (
67   OUT   UINT8    ***List
68   )
69 {
70   // Cast below to hush CONST warning. The built in list must be CONST to be in ROM statically.
71   // The caller of this routine may get a topolist pointer from the interface, however, and
72   // that is not CONST, since it could be on the stack.
73   //
74   *List = (UINT8 **)OptionHtConfiguration.HtOptionBuiltinTopologies;
75 }
76
77 /*----------------------------------------------------------------------------------------*/
78 /**
79  * Returns the number of Nodes in the compressed graph
80  *
81  * @param[in]     Graph   a compressed graph
82  *
83  * @return the number of Nodes in the graph
84  */
85 UINT8
86 GraphHowManyNodes (
87   IN       UINT8    *Graph
88   )
89 {
90   return Graph[0];
91 }
92
93 /*----------------------------------------------------------------------------------------*/
94 /**
95  * Returns true if NodeA is directly connected to NodeB, false otherwise
96  *
97  * if NodeA == NodeB also returns false.
98  * Relies on rule that directly connected Nodes always route requests directly.
99  *
100  * @param[in]     Graph   the graph to examine
101  * @param[in]     NodeA   the Node number of the first Node
102  * @param[in]     NodeB   the Node number of the second Node
103  *
104  * @retval        TRUE    NodeA connects to NodeB
105  * @retval        FALSE   NodeA does not connect to NodeB
106  */
107 BOOLEAN
108 GraphIsAdjacent (
109   IN       UINT8    *Graph,
110   IN       UINT8    NodeA,
111   IN       UINT8    NodeB
112   )
113 {
114   UINT8 size;
115   size = Graph[0];
116   ASSERT ((NodeA < size) && (NodeB < size));
117   return (Graph[1 + (NodeA*size + NodeB)*2 + 1] & 0x0F) == NodeB;
118 }
119
120 /*----------------------------------------------------------------------------------------*/
121 /**
122  * Returns the graph Node used by NodeA to route responses targeted at NodeB.
123  *
124  *     This will be a Node directly connected to NodeA (possibly NodeB itself),
125  *     or "Route to Self" if NodeA and NodeB are the same Node.
126  *     Note that all Node numbers are abstract Node numbers of the topology graph,
127  *     it is the responsibility of the caller to apply any permutation needed.
128  *
129  * @param[in]     Graph the graph to examine
130  * @param[in]     NodeA the Node number of the first Node
131  * @param[in]     NodeB  the Node number of the second Node
132  *
133  * @return The response route Node
134  */
135 UINT8
136 GraphGetRsp (
137   IN       UINT8    *Graph,
138   IN       UINT8    NodeA,
139   IN       UINT8    NodeB
140   )
141 {
142   UINT8 size;
143   size = Graph[0];
144   ASSERT ((NodeA < size) && (NodeB < size));
145   return (Graph[1 + (NodeA*size + NodeB)*2 + 1] & 0xF0) >> 4;
146 }
147
148 /*----------------------------------------------------------------------------------------*/
149 /**
150  * Returns the graph Node used by NodeA to route requests targeted at NodeB.
151  *
152  *     This will be a Node directly connected to NodeA (possibly NodeB itself),
153  *     or "Route to Self" if NodeA and NodeB are the same Node.
154  *     Note that all Node numbers are abstract Node numbers of the topology graph,
155  *     it is the responsibility of the caller to apply any permutation needed.
156  *
157  * @param[in]     Graph the graph to examine
158  * @param[in]     NodeA the Node number of the first Node
159  * @param[in]     NodeB the Node number of the second Node
160  *
161  * @return The request route Node
162  */
163 UINT8
164 GraphGetReq (
165   IN       UINT8    *Graph,
166   IN       UINT8    NodeA,
167   IN       UINT8    NodeB
168   )
169 {
170   UINT8 size;
171   size = Graph[0];
172   ASSERT ((NodeA < size) && (NodeB < size));
173   return (Graph[1 + (NodeA*size + NodeB)*2 + 1] & 0x0F);
174 }
175
176 /*----------------------------------------------------------------------------------------*/
177 /**
178  * Returns a bit vector of Nodes that NodeA should forward a broadcast from
179  * NodeB towards
180  *
181  * @param[in]     Graph the graph to examine
182  * @param[in]     NodeA the Node number of the first Node
183  * @param[in]     NodeB the Node number of the second Node
184  *
185  * @return the broadcast routes for NodeA from NodeB
186  */
187 UINT8
188 GraphGetBc (
189   IN       UINT8    *Graph,
190   IN       UINT8    NodeA,
191   IN       UINT8    NodeB
192   )
193 {
194   UINT8 size;
195   size = Graph[0];
196   ASSERT ((NodeA < size) && (NodeB < size));
197   return Graph[1 + (NodeA*size + NodeB)*2];
198 }
199