blob: 22f48b1ab7f04e131096062ac1fbe20bfaf64505 [file] [log] [blame]
Marc Jones8ae8c882007-12-19 01:32:08 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Marc Jones8ae8c882007-12-19 01:32:08 +00003 *
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.
Marc Jones8ae8c882007-12-19 01:32:08 +000014 */
15
16#include <stdint.h>
17#include <cpu/x86/lapic.h>
Damien Zammit75a3d1f2016-11-28 00:29:10 +110018#include <northbridge/amd/amdfam10/raminit.h>
19#include <northbridge/amd/amdfam10/amdfam10.h>
Marc Jones8ae8c882007-12-19 01:32:08 +000020
21/* mmconf is not ready */
22/* io_ext is not ready */
Stefan Reinauer6f57b512010-07-08 16:41:05 +000023u32 cpu_init_detected(u8 nodeid)
Marc Jones8ae8c882007-12-19 01:32:08 +000024{
25 u32 htic;
Edward O'Callaghan3ec9c952014-10-26 10:36:02 +110026 pci_devfn_t dev;
Marc Jones8ae8c882007-12-19 01:32:08 +000027
28 dev = NODE_PCI(nodeid, 0);
29 htic = pci_io_read_config32(dev, HT_INIT_CONTROL);
30
31 return !!(htic & HTIC_INIT_Detect);
32}
33
Stefan Reinauer6f57b512010-07-08 16:41:05 +000034u32 bios_reset_detected(void)
Marc Jones8ae8c882007-12-19 01:32:08 +000035{
36 u32 htic;
Stefan Reinauer08670622009-06-30 15:17:49 +000037 htic = pci_io_read_config32(PCI_DEV(CONFIG_CBB, CONFIG_CDB, 0), HT_INIT_CONTROL);
Marc Jones8ae8c882007-12-19 01:32:08 +000038
39 return (htic & HTIC_ColdR_Detect) && !(htic & HTIC_BIOSR_Detect);
40}
41
Stefan Reinauer6f57b512010-07-08 16:41:05 +000042u32 cold_reset_detected(void)
Marc Jones8ae8c882007-12-19 01:32:08 +000043{
44 u32 htic;
Stefan Reinauer08670622009-06-30 15:17:49 +000045 htic = pci_io_read_config32(PCI_DEV(CONFIG_CBB, CONFIG_CDB, 0), HT_INIT_CONTROL);
Marc Jones8ae8c882007-12-19 01:32:08 +000046
47 return !(htic & HTIC_ColdR_Detect);
48}
49
Stefan Reinauer6f57b512010-07-08 16:41:05 +000050u32 other_reset_detected(void) // other warm reset not started by BIOS
Marc Jones8ae8c882007-12-19 01:32:08 +000051{
52 u32 htic;
Stefan Reinauer08670622009-06-30 15:17:49 +000053 htic = pci_io_read_config32(PCI_DEV(CONFIG_CBB, CONFIG_CDB, 0), HT_INIT_CONTROL);
Marc Jones8ae8c882007-12-19 01:32:08 +000054
55 return (htic & HTIC_ColdR_Detect) && (htic & HTIC_BIOSR_Detect);
56}
57
Damien Zammit75a3d1f2016-11-28 00:29:10 +110058void distinguish_cpu_resets(u8 nodeid)
Marc Jones8ae8c882007-12-19 01:32:08 +000059{
60 u32 htic;
Edward O'Callaghan3ec9c952014-10-26 10:36:02 +110061 pci_devfn_t device;
Marc Jones8ae8c882007-12-19 01:32:08 +000062 device = NODE_PCI(nodeid, 0);
63 htic = pci_io_read_config32(device, HT_INIT_CONTROL);
64 htic |= HTIC_ColdR_Detect | HTIC_BIOSR_Detect | HTIC_INIT_Detect;
65 pci_io_write_config32(device, HT_INIT_CONTROL, htic);
66}
67
Damien Zammit75a3d1f2016-11-28 00:29:10 +110068u32 warm_reset_detect(u8 nodeid)
Marc Jones8ae8c882007-12-19 01:32:08 +000069{
70 u32 htic;
Edward O'Callaghan3ec9c952014-10-26 10:36:02 +110071 pci_devfn_t device;
Marc Jones8ae8c882007-12-19 01:32:08 +000072 device = NODE_PCI(nodeid, 0);
73 htic = pci_io_read_config32(device, HT_INIT_CONTROL);
74 return (htic & HTIC_ColdR_Detect) && !(htic & HTIC_BIOSR_Detect);
75}
76
Vladimir Serbinenkobf8722a2014-11-09 13:17:39 +010077void set_bios_reset(void)
Marc Jones8ae8c882007-12-19 01:32:08 +000078{
79
80 u32 nodes;
81 u32 htic;
Edward O'Callaghan3ec9c952014-10-26 10:36:02 +110082 pci_devfn_t dev;
Marc Jones8ae8c882007-12-19 01:32:08 +000083 int i;
84
Stefan Reinauer08670622009-06-30 15:17:49 +000085 nodes = ((pci_read_config32(PCI_DEV(CONFIG_CBB, CONFIG_CDB, 0), 0x60) >> 4) & 7) + 1;
Marc Jones8ae8c882007-12-19 01:32:08 +000086
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +020087 for (i = 0; i < nodes; i++) {
Marc Jones8ae8c882007-12-19 01:32:08 +000088 dev = NODE_PCI(i,0);
89 htic = pci_read_config32(dev, HT_INIT_CONTROL);
90 htic &= ~HTIC_BIOSR_Detect;
91 pci_write_config32(dev, HT_INIT_CONTROL, htic);
92 }
93}
94
95
96/* Look up a which bus a given node/link combination is on.
97 * return 0 when we can't find the answer.
98 */
99static u8 node_link_to_bus(u8 node, u8 link) // node are 6 bit, and link three bit
100{
101 u32 reg;
102 u32 val;
103
104 // put node and link in correct bit
Elyes HAOUAS7db506c2016-10-02 11:56:39 +0200105 val = ((node & 0x0f)<<4) | ((node & 0x30)<< (12-4)) | ((link & 0x07)<<8);
Marc Jones8ae8c882007-12-19 01:32:08 +0000106
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200107 for (reg = 0xE0; reg < 0xF0; reg += 0x04) {
Marc Jones8ae8c882007-12-19 01:32:08 +0000108 u32 config_map;
Stefan Reinauer08670622009-06-30 15:17:49 +0000109 config_map = pci_io_read_config32(PCI_DEV(CONFIG_CBB, CONFIG_CDB, 1), reg);
Marc Jones8ae8c882007-12-19 01:32:08 +0000110 if ((config_map & 3) != 3) {
111 continue;
112 }
Elyes HAOUAS04f8fd92016-09-19 10:24:34 -0600113 if ((config_map & (((63 & 0x0f)<<4) | ((63 & 0x30)<< (12-4)) | ((7 & 0x07)<<8))
114 ) == val)
Marc Jones8ae8c882007-12-19 01:32:08 +0000115 {
116 return (config_map >> 16) & 0xff;
117 }
118 }
119
Marc Jones8ae8c882007-12-19 01:32:08 +0000120 return 0;
121}
122
Stefan Reinauer6f57b512010-07-08 16:41:05 +0000123u32 get_sblk(void)
Marc Jones8ae8c882007-12-19 01:32:08 +0000124{
125 u32 reg;
Stefan Reinauer08670622009-06-30 15:17:49 +0000126 /* read PCI_DEV(CONFIG_CBB,CONFIG_CDB,0) 0x64 bit [8:9] to find out SbLink m */
127 reg = pci_io_read_config32(PCI_DEV(CONFIG_CBB, CONFIG_CDB, 0), 0x64);
Elyes HAOUAS7db506c2016-10-02 11:56:39 +0200128 return ((reg>>8) & 3);
Marc Jones8ae8c882007-12-19 01:32:08 +0000129}
130
131
Stefan Reinauer6f57b512010-07-08 16:41:05 +0000132u8 get_sbbusn(u8 sblk)
Marc Jones8ae8c882007-12-19 01:32:08 +0000133{
134 return node_link_to_bus(0, sblk);
135}