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