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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
|
/* $NoKeywords:$ */
/**
* @file
*
* HT Features.
*
* This file provides definitions used in common by HT internal modules. The
* data is private and not for external client access.
* Definitions include the HT global internal state data structures, and
* access to the available HT features from the main HT entry point.
*
* This file includes the feature constructor and feature support which is not
* removed with various build options.
*
* @xrefitem bom "File Content Label" "Release Content"
* @e project: AGESA
* @e sub-project: HyperTransport
* @e \$Revision: 44324 $ @e \$Date: 2010-12-22 02:16:51 -0700 (Wed, 22 Dec 2010) $
*
*/
/*
*****************************************************************************
*
* Copyright (C) 2012 Advanced Micro Devices, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Advanced Micro Devices, Inc. nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***************************************************************************
*
*/
#ifndef _HT_FEAT_H_
#define _HT_FEAT_H_
/**
* @page htimplfeat HT Features Implementation Guide
*
* HT Features provides access to the HT Feature set, in a manner that isolates
* calling code from knowledge about the Feature set implementation or which
* features are supported in the current build. In the case of feature sets, this
* is mostly used for build options to reduce code size by removing unneeded features.
*
* @par Adding a Method to HT Features
*
* To add a new method to the HT Features, follow these steps.
* <ul>
* <li> Create a typedef for the Method with the correct parameters and return type.
*
* <ul>
* <li> Name the method typedef (F_METHOD_NAME)(), where METHOD_NAME is the same name as the method table item,
* but with "_"'s and UPPERCASE, rather than mixed case.
* @n <tt> typedef VOID (F_METHOD_NAME)(); </tt> @n
*
* <li> Make a reference type for references to a method implementation:
* @n <tt> /// Reference to a Method </tt>
* @n <tt> typedef F_METHOD_NAME *PF_METHOD_NAME </tt> @n
* </ul>
*
* <li> Provide a standard doxygen function preamble for the Method typedef. Begin the
* detailed description by providing a reference to the method instances page by including
* the lines below:
* @code
* *
* * @HtFeatInstances.
* *
* @endcode
* @note It is important to provide documentation for the method type, because the method may not
* have an implementation in any families supported by the current package. @n
*
* <li> Add to the _HT_FEATURES struct an item for the Method:
* @n <tt> PF_METHOD_NAME MethodName; ///< Method: description. </tt> @n
* </ul>
*
* @par Implementing an HT Features Instance of the method.
*
* To implement an instance of a method for a specific feature follow these steps.
*
* - In appropriate files, implement the method with the return type and parameters
* matching the method typedef.
*
* - Name the function MethodName().
*
* - Create a doxygen function preamble for the method instance. Begin the detailed description with
* an Implements command to reference the method type and add this instance to the Method Instances page.
* @code
* *
* * @HtFeatMethod{::F_METHOD_NAME}.
* *
* @endcode
*
* - To access other Ht feature routines or data as part of the method implementation, the function
* must use HtFeatures->OtherMethod(). Do not directly access other HT feature
* routines, because in the table there may be overrides or this routine may be shared by multiple configurations.
*
* - Add the instance to the HT_FEATURES instances.
*
* - If a configuration does not need an instance of the method use one of the CommonReturns from
* CommonReturns.h with the same return type.
*
* @par Invoking HT Features Methods.
*
* The first step is carried out only once by the top level HT entry point.
* @n @code
* HT_FEATURES HtFeatures;
* // Get the current HT Feature Set
* NewHtFeatures (&HtFeatures);
* State->HtFeatures = &HtFeatures;
* @endcode
*
* The following example shows how to invoke a HT Features method.
* @n @code
* State->HtFeatures->MethodName ();
* @endcode
*
*/
/*----------------------------------------------------------------------------
* Mixed (DEFINITIONS AND MACROS / TYPEDEFS, STRUCTURES, ENUMS)
*
*----------------------------------------------------------------------------
*/
/*-----------------------------------------------------------------------------
* DEFINITIONS AND MACROS
*
*-----------------------------------------------------------------------------
*/
#define MAX_PLATFORM_LINKS 64
#define MAX_LINK_PAIRS 4
/* These following are internal definitions */
#define ROUTE_TO_SELF 0x0F
#define INVALID_LINK 0xCC /* Used in port list data structure to mark unused data entries.
Can also be used for no Link found in a port list search */
/* definitions for working with the port list structure */
#define PORTLIST_TYPE_CPU 0
#define PORTLIST_TYPE_IO 1
/*
* Hypertransport Capability definitions and macros
*
*/
#define HT_INTERFACE_CAP_SUBTYPE_MASK ((UINT32)0xE00000FF)
#define HT_CAP_SUBTYPE_MASK ((UINT32)0xF80000FF)
/* HT Host Capability */
#define HT_HOST_CAPABILITY 1
#define HT_HOST_CAP_SIZE 0x20
/* Host CapabilityRegisters */
#define HTHOST_LINK_CAPABILITY_REG 0x00
#define HTHOST_LINK_CONTROL_REG 0x04
#define HTHOST_FREQ_REV_REG 0x08
#define HTHOST_REV_REV3 0x60
#define HTHOST_FEATURE_CAP_REG 0x0C
#define HTHOST_BUFFER_COUNT_REG 0x10
#define HTHOST_ISOC_REG 0x14
#define HTHOST_LINK_TYPE_REG 0x18
#define HTHOST_FREQ_EXTENSION 0x1C
#define HTHOST_TYPE_COHERENT 3
#define HTHOST_TYPE_NONCOHERENT 7
#define HTHOST_TYPE_MASK 0x1F
/* HT Slave Capability (HT1 compat) */
#define HT_SLAVE_CAPABILITY 0
#define HTSLAVE_LINK01_OFFSET 4
#define HTSLAVE_LINK_CONTROL_0_REG 4
#define HTSLAVE_FREQ_REV_0_REG 0xC
#define HTSLAVE_FEATURECAP_REG 0x10
#define HT_CONTROL_CLEAR_CRC (~(3 << 8))
#define HT_FREQUENCY_CLEAR_LINK_ERRORS (~(0x7 << 12))
#define MAX_BUID 31
/* HT3 gen Capability */
#define HT_GEN3_CAPABILITY (0xD << 1)
#define HTGEN3_LINK01_OFFSET 0x10
#define HTGEN3_LINK_TRAINING_0_REG 0x10
/* HT3 Retry Capability */
#define HT_RETRY_CAPABILITY (0xC << 1)
#define HTRETRY_CONTROL_REG 4
/* Unit ID Clumping Capability */
#define HT_UNITID_CAPABILITY (0x9 << 1)
#define HTUNIT_SUPPORT_REG 4
#define HTUNIT_ENABLE_REG 8
#define HT_CLUMPING_PASSIVE 1
/*----------------------------------------------------------------------------
* TYPEDEFS, STRUCTURES, ENUMS
*
*----------------------------------------------------------------------------
*/
// Forward declarations.
/// Used for forward reference.
typedef struct _NORTHBRIDGE NORTHBRIDGE;
/// Used for forward reference.
typedef struct _HT_FEATURES HT_FEATURES;
/// Used for forward reference.
typedef struct _HT_INTERFACE HT_INTERFACE;
/**
* Coherent Init Data.
*
* Metrics representing the coherent fabric which was discovered: Degree of nodes, adjacency,
* node numbering permutations, and the topology which it matched.
*/
typedef struct {
/** The number of coherent Links connected on each Node (the 'Degree' of the Node) */
UINT8 SysDegree[MAX_NODES];
/** The systems adjacency (sysMatrix[i][j] is true if Node_i has a Link to Node_j) */
BOOLEAN SysMatrix[MAX_NODES][MAX_NODES];
UINT8 DbDegree[MAX_NODES]; /**< Like sysDegree, but for the current database topology */
BOOLEAN DbMatrix[MAX_NODES][MAX_NODES]; /**< Like sysMatrix, but for the current database topology */
UINT8 Perm[MAX_NODES]; /**< The Node mapping from the system to the database */
UINT8 ReversePerm[MAX_NODES]; /**< The Node mapping from the database to the system */
UINT8 *MatchedTopology; /**< The topology that matched the current system or NULL */
} COHERENT_FABRIC;
/**
* Represent the system as Links of matched port pairs.
* A pair consists of a source Node, a Link to the destination Node, the
* destination Node, and its Link back to source Node. The even indices are
* the source Nodes and Links, and the odd indices are for the destination
* Nodes and Links.
* @note The Port pair 2*N and 2*N+1 are connected together to form a Link
* (e.g. 0,1 and 8,9 are ports on either end of an HT Link) The lower number
* port (2*N) is the source port. The device that owns the source port is
* always the device closer to the BSP. (i.e. nearer the CPU in a
* non-coherent chain, or the CPU with the lower NodeID).
*/
typedef struct {
/* This section is where the Link is in the system and how to find it */
UINT8 Type; /**< 0 = CPU, 1 = Device, all others reserved */
UINT8 Link; /**< 0-1 for devices, 0-7 for CPUs */
UINT8 NodeID; /**< The Node, or a pointer to the devices parent Node */
UINT8 HostLink; /**< For Devices, the root CPU's Link to the chain */
UINT8 HostDepth; /**< Link Depth in chain, only used by devices */
PCI_ADDR Pointer; /**< A pointer to the device's slave HT capability, so we don't have to keep searching */
/* This section is for the final settings, which are written to hardware */
BOOLEAN SelRegang; /**< Indicates to software regang Link, only used for CPU->CPU Links */
UINT8 SelWidthIn; /**< Width in setting */
UINT8 SelWidthOut; /**< Width out setting */
UINT8 SelFrequency; /**< Frequency setting */
/* This section is for keeping track of capabilities and possible configurations */
BOOLEAN RegangCap; /**< Is the port capable of reganging? CPUs only */
UINT32 PrvFrequencyCap; /**< Possible frequency settings */
UINT8 PrvWidthInCap; /**< Possible Width setting */
UINT8 PrvWidthOutCap; /**< Possible Width setting */
UINT32 CompositeFrequencyCap; /**< Possible Link frequency setting */
UINT32 ClumpingSupport; /**< Unit ID Clumping value (bit 0 = passive support) */
} PORT_DESCRIPTOR;
/// Reference to a set of PORT_DESCRIPTORs.
typedef PORT_DESCRIPTOR (*PORT_LIST)[MAX_PLATFORM_LINKS*2];
/**
* Our global state data structure
*/
typedef struct {
AMD_HT_INTERFACE *HtBlock; /**< The input data structure. */
UINT8 NodesDiscovered; /**< One less than the number of Nodes found in the system */
UINT8 TotalLinks; /**< How many HT Links have we discovered so far. */
UINT8 SysMpCap; /**< The maximum number of Nodes that all processors are capable of */
AGESA_STATUS MaxEventClass; /**< The event class of the highest severity event generated */
PORT_LIST PortList; /**< Represent the system as a set of Links, each two Ports. */
COHERENT_FABRIC *Fabric; /**< Describe metrics about the coherent fabric.
* Limited scope to CoherentInit(). */
/* Data interface to other Agesa Modules */
SOCKET_DIE_TO_NODE_MAP SocketDieToNodeMap; /**< For each Socket, Die the Node ids */
NODE_TO_SOCKET_DIE_MAP NodeToSocketDieMap; /**< For each Node id, Socket and Die */
HOP_COUNT_TABLE *HopCountTable; /**< Table of hops between nodes */
/* Data for non-coherent initialization */
UINT8 AutoBusCurrent; /**< The next bus number available */
UINT8 UsedCfgMapEntries; /**< The next Config address Map set available, Limit 4 (F1X[EC:E0]) */
BOOLEAN IsUsingRecoveryHt; /**< Manual BUID Swap List processing should assume that HT Recovery was used */
BOOLEAN IsSetHtCrcFlood; /**< Enable setting of HT CRC Flood */
BOOLEAN IsUsingUnitIdClumping; /**< Enable automatic Unit Id Clumping configuration. */
HT_INTERFACE *HtInterface; /**< Interface for feature code to external parameters */
HT_FEATURES *HtFeatures; /**< The current feature implementations */
NORTHBRIDGE *Nb; /**< The current northbridge */
PLATFORM_CONFIGURATION *PlatformConfiguration; /**< The platform specific configuration customizations */
VOID *ConfigHandle; /**< Config Pointer, opaque handle for passing to lib */
} STATE_DATA;
//
// Feature Method types
//
/**
* Discover all coherent devices in the system.
*
* @HtFeatInstances.
*
* @param[in,out] State our global state
*
*/
typedef VOID F_COHERENT_DISCOVERY (
IN OUT STATE_DATA *State
);
/// Reference to a method.
typedef F_COHERENT_DISCOVERY *PF_COHERENT_DISCOVERY;
/**
* Using the description of the fabric topology we discovered, try to find a match
* among the supported topologies.
*
* @HtFeatInstances.
*
* @param[in,out] State the discovered fabric, degree matrix, permutation
*
*/
typedef VOID F_LOOKUP_COMPUTE_AND_LOAD_ROUTING_TABLES (
IN OUT STATE_DATA *State
);
/// Reference to a method.
typedef F_LOOKUP_COMPUTE_AND_LOAD_ROUTING_TABLES *PF_LOOKUP_COMPUTE_AND_LOAD_ROUTING_TABLES;
/**
* Make a Hop Count Table for the installed topology.
*
* @HtFeatInstances.
*
* @param[in,out] State access topology, permutation, update hop table
*
*/
typedef VOID F_MAKE_HOP_COUNT_TABLE (
IN OUT STATE_DATA *State
);
/// Reference to a method.
typedef F_MAKE_HOP_COUNT_TABLE *PF_MAKE_HOP_COUNT_TABLE;
/**
* Process a non-coherent Link.
*
* @HtFeatInstances.
*
* @param[in] Node Node on which to process nc init
* @param[in] Link The non-coherent Link on that Node
* @param[in] IsCompatChain Is this the chain with the southbridge? TRUE if yes.
* @param[in,out] State our global state
*/
typedef VOID F_PROCESS_LINK (
IN UINT8 Node,
IN UINT8 Link,
IN BOOLEAN IsCompatChain,
IN OUT STATE_DATA *State
);
/// Reference to a method.
typedef F_PROCESS_LINK *PF_PROCESS_LINK;
/**
* Get Link features into system data structure.
*
* @HtFeatInstances.
*
* @param[in] State our global state, port list
*/
typedef VOID F_GATHER_LINK_DATA (
IN STATE_DATA *State
);
/// Reference to a method.
typedef F_GATHER_LINK_DATA *PF_GATHER_LINK_DATA;
/**
* Optimize Links.
*
* @HtFeatInstances.
*
* @param[in,out] State Process and update portlist
*/
typedef VOID F_SELECT_OPTIMAL_WIDTH_AND_FREQUENCY (
IN OUT STATE_DATA *State
);
/// Reference to a method.
typedef F_SELECT_OPTIMAL_WIDTH_AND_FREQUENCY *PF_SELECT_OPTIMAL_WIDTH_AND_FREQUENCY;
/**
* Change the hardware state for all Links according to the now optimized data in the
* port list data structure.
*
* @HtFeatInstances.
*
* @param[in] State our global state, port list
*/
typedef VOID F_SET_LINK_DATA (
IN STATE_DATA *State
);
/// Reference to a method.
typedef F_SET_LINK_DATA *PF_SET_LINK_DATA;
/**
* Retry must be enabled on all coherent links if it is enabled on any coherent links.
*
* @HtFeatInstances.
*
* @param[in,out] State global state, port frequency settings.
*
* @retval TRUE Fixup occurred, all coherent links HT1
* @retval FALSE No changes
*/
typedef BOOLEAN F_IS_COHERENT_RETRY_FIXUP (
IN STATE_DATA *State
);
/// Reference to a method.
typedef F_IS_COHERENT_RETRY_FIXUP *PF_IS_COHERENT_RETRY_FIXUP;
/**
* Test the subLinks of a Link to see if they qualify to be reganged.
*
* @HtFeatInstances.
*
* @param[in,out] State Our global state
*/
typedef VOID F_REGANG_LINKS (
IN OUT STATE_DATA *State
);
/// Reference to a method.
typedef F_REGANG_LINKS *PF_REGANG_LINKS;
/**
* Iterate through all Links, checking the frequency of each subLink pair.
*
* @HtFeatInstances.
*
* @param[in,out] State Link state and port list
*
*/
typedef VOID F_SUBLINK_RATIO_FIXUP (
IN OUT STATE_DATA *State
);
/// Reference to a method.
typedef F_SUBLINK_RATIO_FIXUP *PF_SUBLINK_RATIO_FIXUP;
/**
* Identify Links which can have traffic distribution.
*
* @HtFeatInstances.
*
* @param[in] State port list data
*/
typedef VOID F_TRAFFIC_DISTRIBUTION (
IN STATE_DATA *State
);
/// Reference to a method.
typedef F_TRAFFIC_DISTRIBUTION *PF_TRAFFIC_DISTRIBUTION;
/**
* Access HT Link Control Register.
*
* @HtFeatInstances.
*
* @param[in] Reg the PCI config address the control register
* @param[in] HiBit the high bit number
* @param[in] LoBit the low bit number
* @param[in] Value the value to write to that bit range. Bit 0 => loBit.
* @param[in] State Our state, config handle for lib
*/
typedef VOID F_SET_HT_CONTROL_REGISTER_BITS (
IN PCI_ADDR Reg,
IN UINT8 HiBit,
IN UINT8 LoBit,
IN UINT32 *Value,
IN STATE_DATA *State
);
/// Reference to a method.
typedef F_SET_HT_CONTROL_REGISTER_BITS *PF_SET_HT_CONTROL_REGISTER_BITS;
/**
* Translate a desired width setting to the bits to set in the register field.
*
* @HtFeatInstances.
*
* @param[in] Value the width Value
*
* @return The bits for the register
*/
typedef UINT8 F_CONVERT_WIDTH_TO_BITS (
IN UINT8 Value
);
/// Reference to a method.
typedef F_CONVERT_WIDTH_TO_BITS *PF_CONVERT_WIDTH_TO_BITS;
/**
* HT Feature Methods.
*
* Provides abstract methods which are bound to specific feature implementations.
*/
struct _HT_FEATURES {
PF_COHERENT_DISCOVERY CoherentDiscovery; /**< Method: Coherent Discovery. */
PF_LOOKUP_COMPUTE_AND_LOAD_ROUTING_TABLES LookupComputeAndLoadRoutingTables;
/**< Method: Route the discovered system */
PF_MAKE_HOP_COUNT_TABLE MakeHopCountTable; /**< Method: Compute slit hop counts */
PF_PROCESS_LINK ProcessLink; /**< Method: Process a non-coherent Link. */
PF_GATHER_LINK_DATA GatherLinkData; /**< Method: Gather Link Capabilities and data. */
PF_SELECT_OPTIMAL_WIDTH_AND_FREQUENCY SelectOptimalWidthAndFrequency;
/**< Method: Optimize link features. */
PF_REGANG_LINKS RegangLinks; /**< Method: Regang Sublinks. */
PF_SUBLINK_RATIO_FIXUP SubLinkRatioFixup; /**< Method: Fix Sublink Frequency ratios */
PF_IS_COHERENT_RETRY_FIXUP IsCoherentRetryFixup;
/**< Method: Fix Retry mixed on coherent links. */
PF_SET_LINK_DATA SetLinkData; /**< Method: Set optimized values. */
PF_TRAFFIC_DISTRIBUTION TrafficDistribution; /**< Method: Detect and Initialize Traffic Distribution */
PF_SET_HT_CONTROL_REGISTER_BITS SetHtControlRegisterBits; /**< Method: Access HT Link Control Reg. */
PF_CONVERT_WIDTH_TO_BITS ConvertWidthToBits; /**< Method: Convert a bit width to the value used for register setting. */
} ;
/*----------------------------------------------------------------------------
* Prototypes
*
*----------------------------------------------------------------------------
*/
/**
* Provide the current Feature set implementation.
*
* Add an implementation reference for the constructor, just to make sure the page is created.
* @HtFeatMethod{_HT_FEATURES}.
*
*/
VOID
NewHtFeatures (
OUT HT_FEATURES *HtFeatures,
IN AMD_CONFIG_PARAMS *StdHeader
);
#endif /* _HT_FEAT_H_ */
|