38733c9863584575bd4739c5789f53746cb7e8ba
[coreboot.git] / src / northbridge / amd / amdht / ht_wrapper.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007-2008 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 <cpu/x86/msr.h>
21 #include <console/console.h>
22 #include <northbridge/amd/amdfam10/amdfam10.h>
23
24 /*----------------------------------------------------------------------------
25  *                      TYPEDEFS, DEFINITIONS AND MACROS
26  *
27  *----------------------------------------------------------------------------
28  */
29
30 /* Single CPU system? */
31 #if (CONFIG_MAX_PHYSICAL_CPUS == 1)
32         #define HT_BUILD_NC_ONLY 1
33 #endif
34
35 /* Debugging Options */
36 #define AMD_DEBUG 1
37 //#define AMD_DEBUG_ERROR_STOP 1
38
39 /*----------------------------------------------------------------------------
40  *                              MODULES USED
41  *
42  *----------------------------------------------------------------------------
43  */
44
45 #undef FILECODE
46 #define FILECODE 0xFF01
47 #include "comlib.h"
48 #include "h3gtopo.h"
49 #include "h3finit.h"
50
51 /* include the main HT source file */
52 #include "h3finit.c"
53
54
55 /*----------------------------------------------------------------------------
56  *                      LOCAL FUNCTIONS
57  *
58  *----------------------------------------------------------------------------
59  */
60
61 /* FIXME: Find a better place for these pre-ram functions. */
62 #define NODE_HT(x) NODE_PCI(x,0)
63 #define NODE_MP(x) NODE_PCI(x,1)
64 #define NODE_MC(x) NODE_PCI(x,3)
65 #define NODE_LC(x) NODE_PCI(x,4)
66
67 static  u32 get_nodes(void)
68 {
69         device_t dev;
70         u32 nodes;
71
72         dev = PCI_DEV(CONFIG_CBB, CONFIG_CDB, 0);
73         nodes = ((pci_read_config32(dev, 0x60)>>4) & 7) ;
74 #if CONFIG_MAX_PHYSICAL_CPUS > 8
75         nodes += (((pci_read_config32(dev, 0x160)>>4) & 7)<<3);
76 #endif
77         nodes++;
78
79         return nodes;
80 }
81
82
83 /**
84  * void AMD_CB_EventNotify (u8 evtClass, u16 event, const u8 *pEventData0)
85  */
86 static void AMD_CB_EventNotify (u8 evtClass, u16 event, const u8 *pEventData0)
87 {
88         u8 i;
89
90         printk(BIOS_DEBUG, "AMD_CB_EventNotify()\n");
91         printk(BIOS_DEBUG, " event class: %02x\n event: %04x\n data: ", evtClass, event);
92
93         for (i = 0; i < *pEventData0; i++) {
94                 printk(BIOS_DEBUG, " %02x ", *(pEventData0 + i));
95         }
96         printk(BIOS_DEBUG, "\n");
97
98 }
99
100
101 /**
102  * BOOL AMD_CB_ManualBUIDSwapList(u8 Node, u8 Link, u8 **List)
103  * Description:
104  *      This routine is called every time a non-coherent chain is processed.
105  *      BUID assignment may be controlled explicitly on a non-coherent chain. Provide a
106  *      swap list. The first part of the list controls the BUID assignment and the
107  *      second part of the list provides the device to device linking.  Device orientation
108  *      can be detected automatically, or explicitly.  See documentation for more details.
109  *
110  *      Automatic non-coherent init assigns BUIDs starting at 1 and incrementing sequentially
111  *      based on each device's unit count.
112  *
113  * Parameters:
114  *      @param[in]  u8  node    = The node on which this chain is located
115  *      @param[in]  u8  link    = The link on the host for this chain
116  *      @param[out] u8** list   = supply a pointer to a list
117  *      @param[out] BOOL result = true to use a manual list
118  *                                false to initialize the link automatically
119  */
120 static BOOL AMD_CB_ManualBUIDSwapList (u8 node, u8 link, u8 **List)
121 {
122         static u8 swaplist[] = { 0xFF, CONFIG_HT_CHAIN_UNITID_BASE, CONFIG_HT_CHAIN_END_UNITID_BASE, 0xFF };
123         /* If the BUID was adjusted in early_ht we need to do the manual override */
124         if ((CONFIG_HT_CHAIN_UNITID_BASE != 0) && (CONFIG_HT_CHAIN_END_UNITID_BASE != 0)) {
125                 printk(BIOS_DEBUG, "AMD_CB_ManualBUIDSwapList()\n");
126                 if ((node == 0) && (link == 0)) {       /* BSP SB link */
127                         *List = swaplist;
128                         return 1;
129                 }
130         }
131
132         return 0;
133 }
134
135
136 /**
137  * void getAmdTopolist(u8 ***p)
138  *
139  *  point to the stock topo list array
140  *
141  */
142 void getAmdTopolist(u8 ***p)
143 {
144         *p = (u8 **)amd_topo_list;
145 }
146
147
148 /**
149  * void amd_ht_init(struct sys_info *sysinfo)
150  *
151  *  AMD HT init coreboot wrapper
152  *
153  */
154 static void amd_ht_init(struct sys_info *sysinfo)
155 {
156
157         AMD_HTBLOCK ht_wrapper = {
158                 NULL,   // u8 **topolist;
159                 0,      // u8 AutoBusStart;
160                 32,     // u8 AutoBusMax;
161                 6,      // u8 AutoBusIncrement;
162                 NULL,   // BOOL (*AMD_CB_IgnoreLink)();
163                 NULL,   // BOOL (*AMD_CB_OverrideBusNumbers)();
164                 AMD_CB_ManualBUIDSwapList,      // BOOL (*AMD_CB_ManualBUIDSwapList)();
165                 NULL,   // void (*AMD_CB_DeviceCapOverride)();
166                 NULL,   // void (*AMD_CB_Cpu2CpuPCBLimits)();
167                 NULL,   // void (*AMD_CB_IOPCBLimits)();
168                 NULL,   // BOOL (*AMD_CB_SkipRegang)();
169                 NULL,   // BOOL (*AMD_CB_CustomizeTrafficDistribution)();
170                 NULL,   // BOOL (*AMD_CB_CustomizeBuffers)();
171                 NULL,   // void (*AMD_CB_OverrideDevicePort)();
172                 NULL,   // void (*AMD_CB_OverrideCpuPort)();
173                 AMD_CB_EventNotify      // void (*AMD_CB_EventNotify) ();
174         };
175
176         printk(BIOS_DEBUG, "Enter amd_ht_init()\n");
177         amdHtInitialize(&ht_wrapper);
178         printk(BIOS_DEBUG, "Exit amd_ht_init()\n");
179
180
181 }
182
183
184
185