blob: 9059a29e9bd6e2615a95af8535d5a7899df6cc18 [file] [log] [blame]
Wang Qing Pei0ede4c02010-08-17 15:19:32 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2010 Wang Qing Pei <wangqingpei@gmail.com>
5 * Copyright (C) 2010 Advanced Micro Devices, Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <console/console.h>
22#include <device/device.h>
23#include <device/pci.h>
24#include <arch/io.h>
25#include <boot/tables.h>
26#include <cpu/x86/msr.h>
27#include <cpu/amd/mtrr.h>
28#include <device/pci_def.h>
29#include <southbridge/amd/sb700/sb700.h>
30#include "chip.h"
31
32#define SMBUS_IO_BASE 0x6000
33
34uint64_t uma_memory_base, uma_memory_size;
35
36void set_pcie_dereset(void);
37void set_pcie_reset(void);
Wang Qing Peid6c43952010-08-18 01:55:11 +000038u8 is_dev3_present(void);
Wang Qing Pei0ede4c02010-08-17 15:19:32 +000039
40/*
41 * the board uses GPIO 6 as PCIe slot reset, GPIO4 as GFX slot reset. We need to
42 * pull it up before training the slot.
43 ***/
44void set_pcie_dereset()
45{
46 u16 word;
47 device_t sm_dev;
48 /* GPIO 6 reset PCIe slot, GPIO 4 reset GFX PCIe */
49 sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
50
51 word = pci_read_config16(sm_dev, 0xA8);
52 word |= (1 << 0) | (1 << 2); /* Set Gpio6,4 as output */
53 word &= ~((1 << 8) | (1 << 10));
54 pci_write_config16(sm_dev, 0xA8, word);
55}
56
57void set_pcie_reset()
58{
59 u16 word;
60 device_t sm_dev;
61 /* GPIO 6 reset PCIe slot, GPIO 4 reset GFX PCIe */
62 sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
63
64 word = pci_read_config16(sm_dev, 0xA8);
65 word &= ~((1 << 0) | (1 << 2)); /* Set Gpio6,4 as output */
66 word &= ~((1 << 8) | (1 << 10));
67 pci_write_config16(sm_dev, 0xA8, word);
68}
69
70#if 0 /* not tested yet. */
71/********************************************************
72* board uses SB700 GPIO9 to detect IDE_DMA66.
73* IDE_DMA66 is routed to GPIO 9. So we read Gpio 9 to
74* get the cable type, 40 pin or 80 pin?
75********************************************************/
76static void get_ide_dma66(void)
77{
78 u8 byte;
79 /*u32 sm_dev, ide_dev; */
80 device_t sm_dev, ide_dev;
81
82 sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
83
84 byte = pci_read_config8(sm_dev, 0xA9);
85 byte |= (1 << 5); /* Set Gpio9 as input */
86 pci_write_config8(sm_dev, 0xA9, byte);
87
88 ide_dev = dev_find_slot(0, PCI_DEVFN(0x14, 1));
89 byte = pci_read_config8(ide_dev, 0x56);
90 byte &= ~(7 << 0);
91 if ((1 << 5) & pci_read_config8(sm_dev, 0xAA))
92 byte |= 2 << 0; /* mode 2 */
93 else
94 byte |= 5 << 0; /* mode 5 */
95 pci_write_config8(ide_dev, 0x56, byte);
96}
97#endif /* get_ide_dma66() */
98
Wang Qing Peid6c43952010-08-18 01:55:11 +000099u8 is_dev3_present(void)
100{
101 return 0;
102}
103
Wang Qing Pei0ede4c02010-08-17 15:19:32 +0000104/*************************************************
105* enable the dedicated function in this board.
106* This function called early than rs780_enable.
107*************************************************/
108static void pa78vm5_enable(device_t dev)
109{
110 /* Leave it for furture use. */
111 /* struct mainboard_config *mainboard =
112 (struct mainboard_config *)dev->chip_info; */
113
114 printk(BIOS_INFO, "Mainboard PA78VM5 Enable. dev=0x%p\n", dev);
115
116#if (CONFIG_GFXUMA == 1)
117 msr_t msr, msr2;
118
119 /* TOP_MEM: the top of DRAM below 4G */
120 msr = rdmsr(TOP_MEM);
121 printk
122 (BIOS_INFO, "%s, TOP MEM: msr.lo = 0x%08x, msr.hi = 0x%08x\n",
123 __func__, msr.lo, msr.hi);
124
125 /* TOP_MEM2: the top of DRAM above 4G */
126 msr2 = rdmsr(TOP_MEM2);
127 printk
128 (BIOS_INFO, "%s, TOP MEM2: msr2.lo = 0x%08x, msr2.hi = 0x%08x\n",
129 __func__, msr2.lo, msr2.hi);
130
131 /* refer to UMA Size Consideration in 780 BDG. */
132 switch (msr.lo) {
133 case 0x10000000: /* 256M system memory */
134 uma_memory_size = 0x4000000; /* 64M recommended UMA */
135 break;
136
137 case 0x20000000: /* 512M system memory */
138 uma_memory_size = 0x8000000; /* 128M recommended UMA */
139 break;
140
141 default: /* 1GB and above system memory */
142 uma_memory_size = 0x10000000; /* 256M recommended UMA */
143 break;
144 }
145
146 uma_memory_base = msr.lo - uma_memory_size; /* TOP_MEM1 */
147 printk(BIOS_INFO, "%s: uma size 0x%08llx, memory start 0x%08llx\n",
148 __func__, uma_memory_size, uma_memory_base);
149
150 /* TODO: TOP_MEM2 */
151#else
152 uma_memory_size = 0x8000000; /* 128M recommended UMA */
153 uma_memory_base = 0x38000000; /* 1GB system memory supposed */
154#endif
155
156 set_pcie_dereset();
157 /* get_ide_dma66(); */
158}
159
160int add_mainboard_resources(struct lb_memory *mem)
161{
162 /* UMA is removed from system memory in the northbridge code, but
163 * in some circumstances we want the memory mentioned as reserved.
164 */
165#if (CONFIG_GFXUMA == 1)
166 printk(BIOS_INFO, "uma_memory_start=0x%llx, uma_memory_size=0x%llx \n",
167 uma_memory_base, uma_memory_size);
168 lb_add_memory_range(mem, LB_MEM_RESERVED, uma_memory_base,
169 uma_memory_size);
170#endif
171 return 0;
172}
173
174struct chip_operations mainboard_ops = {
175 CHIP_NAME("AMD PA78VM5 Mainboard")
176 .enable_dev = pa78vm5_enable,
177};