amdfam10: add phenom II as known cpu
[coreboot.git] / src / northbridge / amd / amdfam10 / reset_test.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007 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 <stdint.h>
21 #include <cpu/x86/lapic.h>
22 #include "amdfam10.h"
23
24 #define NODE_ID         0x60
25 #define HT_INIT_CONTROL 0x6c
26 #define HTIC_ColdR_Detect       (1<<4)
27 #define HTIC_BIOSR_Detect       (1<<5)
28 #define HTIC_INIT_Detect        (1<<6)
29
30 /* mmconf is not ready */
31 /* io_ext is not ready */
32 u32 cpu_init_detected(u8 nodeid)
33 {
34         u32 htic;
35         device_t dev;
36
37         dev = NODE_PCI(nodeid, 0);
38         htic = pci_io_read_config32(dev, HT_INIT_CONTROL);
39
40         return !!(htic & HTIC_INIT_Detect);
41 }
42
43 u32 bios_reset_detected(void)
44 {
45         u32 htic;
46         htic = pci_io_read_config32(PCI_DEV(CONFIG_CBB, CONFIG_CDB, 0), HT_INIT_CONTROL);
47
48         return (htic & HTIC_ColdR_Detect) && !(htic & HTIC_BIOSR_Detect);
49 }
50
51 u32 cold_reset_detected(void)
52 {
53         u32 htic;
54         htic = pci_io_read_config32(PCI_DEV(CONFIG_CBB, CONFIG_CDB, 0), HT_INIT_CONTROL);
55
56         return !(htic & HTIC_ColdR_Detect);
57 }
58
59 u32 other_reset_detected(void)  // other warm reset not started by BIOS
60 {
61         u32 htic;
62         htic = pci_io_read_config32(PCI_DEV(CONFIG_CBB, CONFIG_CDB, 0), HT_INIT_CONTROL);
63
64         return (htic & HTIC_ColdR_Detect) && (htic & HTIC_BIOSR_Detect);
65 }
66
67 static void distinguish_cpu_resets(u8 nodeid)
68 {
69         u32 htic;
70         device_t device;
71         device = NODE_PCI(nodeid, 0);
72         htic = pci_io_read_config32(device, HT_INIT_CONTROL);
73         htic |= HTIC_ColdR_Detect | HTIC_BIOSR_Detect | HTIC_INIT_Detect;
74         pci_io_write_config32(device, HT_INIT_CONTROL, htic);
75 }
76
77 static u32 warm_reset_detect(u8 nodeid)
78 {
79         u32 htic;
80         device_t device;
81         device = NODE_PCI(nodeid, 0);
82         htic = pci_io_read_config32(device, HT_INIT_CONTROL);
83         return (htic & HTIC_ColdR_Detect) && !(htic & HTIC_BIOSR_Detect);
84 }
85
86 void __attribute__ ((weak)) set_bios_reset(void);
87 void __attribute__ ((weak)) set_bios_reset(void)
88 {
89
90         u32 nodes;
91         u32 htic;
92         device_t dev;
93         int i;
94
95         nodes = ((pci_read_config32(PCI_DEV(CONFIG_CBB, CONFIG_CDB, 0), 0x60) >> 4) & 7) + 1;
96
97         for(i = 0; i < nodes; i++) {
98                 dev = NODE_PCI(i,0);
99                 htic = pci_read_config32(dev, HT_INIT_CONTROL);
100                 htic &= ~HTIC_BIOSR_Detect;
101                 pci_write_config32(dev, HT_INIT_CONTROL, htic);
102         }
103 }
104
105
106 /* Look up a which bus a given node/link combination is on.
107  * return 0 when we can't find the answer.
108  */
109 static u8 node_link_to_bus(u8 node, u8 link) // node are 6 bit, and link three bit
110 {
111         u32 reg;
112         u32 val;
113
114         // put node and link in correct bit
115         val = ((node & 0x0f)<<4) | ((node & 0x30)<< (12-4)) | ((link & 0x07)<<8) ;
116
117         for(reg = 0xE0; reg < 0xF0; reg += 0x04) {
118                 u32 config_map;
119                 config_map = pci_io_read_config32(PCI_DEV(CONFIG_CBB, CONFIG_CDB, 1), reg);
120                 if ((config_map & 3) != 3) {
121                         continue;
122                 }
123                 if ((config_map & (((63 & 0x0f)<<4) | ((63 & 0x30)<< (12-4)) | ((7 & 0x07)<<8) )
124                         ) == val )
125                 {
126                         return (config_map >> 16) & 0xff;
127                 }
128         }
129
130 #if CONFIG_EXT_CONF_SUPPORT == 1
131         // let's check that in extend space
132         // use the nodeid extend space to find out the bus for the linkn
133         u32 tempreg;
134         int i;
135         int j;
136         u32 cfg_map_dest;
137         device_t dev;
138
139         cfg_map_dest = (1<<7)|(1<<6)|link;
140
141         // three case: index_min==index_max, index_min+1=index_max; index_min+1<index_max
142         dev = NODE_PCI(node, 1);
143         for(j=0; j<64; j++) {
144                 pci_io_write_config32(dev, 0x110, j | (6<<28));
145                 tempreg = pci_io_read_config32(dev, 0x114);
146                 for(i=0; i<=3; i++) {
147                         tempreg >>= (i*8);
148                         if((tempreg & ((1<<7)|(1<<6)|0x3f)) == cfg_map_dest) {
149                                 return (i+(j<<2)); //busn_min
150                         }
151                 }
152         }
153 #endif
154
155         return 0;
156 }
157
158 u32 get_sblk(void)
159 {
160         u32 reg;
161         /* read PCI_DEV(CONFIG_CBB,CONFIG_CDB,0) 0x64 bit [8:9] to find out SbLink m */
162         reg = pci_io_read_config32(PCI_DEV(CONFIG_CBB, CONFIG_CDB, 0), 0x64);
163         return ((reg>>8) & 3) ;
164 }
165
166
167 u8 get_sbbusn(u8 sblk)
168 {
169         return node_link_to_bus(0, sblk);
170 }
171