AMD Bimini: Small fixes, and updates to recent trunk conventions.
[coreboot.git] / src / mainboard / amd / bimini_fam10 / mainboard.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2010 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 <console/console.h>
21 #include <device/device.h>
22 #include <device/pci.h>
23 #include <arch/io.h>
24 #include <boot/tables.h>
25 #include <cpu/x86/msr.h>
26 #include <cpu/amd/mtrr.h>
27 #include <device/pci_def.h>
28 //#include <southbridge/amd/sb800/sb800.h>
29 #include "pmio.h"
30 #include "chip.h"
31
32 uint64_t uma_memory_base, uma_memory_size;
33
34 u8 is_dev3_present(void);
35 void set_pcie_dereset(void);
36 void set_pcie_reset(void);
37 void enable_int_gfx(void);
38
39 /* GPIO6. */
40 void enable_int_gfx(void)
41 {
42         u8 byte;
43
44         volatile u8 *gpio_reg;
45
46         pm_iowrite(0xEA, 0x01); /* diable the PCIB */
47         /* Disable Gec */
48         byte = pm_ioread(0xF6);
49         byte |= 1;
50         pm_iowrite(0xF6, byte);
51         /* make sure the fed80000 is accessible */
52         byte = pm_ioread(0x24);
53         byte |= 1;
54         pm_iowrite(0x24, byte);
55
56         gpio_reg = (volatile u8 *)0xFED80000 + 0xD00; /* IoMux Register */
57
58         *(gpio_reg + 0x6) = 0x1; /* Int_vga_en */
59         *(gpio_reg + 170) = 0x1; /* gpio_gate */
60
61         gpio_reg = (volatile u8 *)0xFED80000 + 0x100; /* GPIO Registers */
62
63         *(gpio_reg + 0x6) = 0x8;
64         *(gpio_reg + 170) = 0x0;
65 }
66
67 /*
68  * Bimini uses GPIO 6 as PCIe slot reset, GPIO4 as GFX slot reset. We need to
69  * pull it up before training the slot.
70  ***/
71 void set_pcie_dereset(void)
72 {
73         /* GPIO 50h reset PCIe slot */
74 /*
75         u8 *addr = (u8 *)(0xFED80000 + 0x100 + 0x50);
76         u8 byte = ~(1 << 5);
77         byte |= ~(1 << 6);
78         *addr = byte;
79 */
80 }
81
82 void set_pcie_reset(void)
83 {
84         /* GPIO 50h reset PCIe slot */
85 /*
86         u8 *addr = (u8 *)(0xFED80000 + 0x100 + 0x50);
87         u8 byte = ~((1 << 5) | (1 << 6));
88         *addr = byte;
89 */
90 }
91
92 u8 is_dev3_present(void)
93 {
94         return 0;
95 }
96
97 #if 0        /* not tested yet. */
98 /********************************************************
99 * bimini uses SB800 GPIO9 to detect IDE_DMA66.
100 * IDE_DMA66 is routed to GPIO 9. So we read Gpio 9 to
101 * get the cable type, 40 pin or 80 pin?
102 ********************************************************/
103 static void get_ide_dma66(void)
104 {
105         u8 byte;
106         /*u32 sm_dev, ide_dev; */
107         device_t sm_dev, ide_dev;
108
109         sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
110
111         byte = pci_read_config8(sm_dev, 0xA9);
112         byte |= (1 << 5);       /* Set Gpio9 as input */
113         pci_write_config8(sm_dev, 0xA9, byte);
114
115         ide_dev = dev_find_slot(0, PCI_DEVFN(0x14, 1));
116         byte = pci_read_config8(ide_dev, 0x56);
117         byte &= ~(7 << 0);
118         if ((1 << 5) & pci_read_config8(sm_dev, 0xAA))
119                 byte |= 2 << 0; /* mode 2 */
120         else
121                 byte |= 5 << 0; /* mode 5 */
122         pci_write_config8(ide_dev, 0x56, byte);
123 }
124 #endif  /* get_ide_dma66() */
125
126 /*************************************************
127 * enable the dedicated function in bimini board.
128 * This function called early than rs780_enable.
129 *************************************************/
130 static void bimini_enable(device_t dev)
131 {
132         /* Leave it for furture use. */
133         /* struct mainboard_config *mainboard =
134            (struct mainboard_config *)dev->chip_info; */
135
136         printk(BIOS_INFO, "Mainboard BIMINI Enable. dev=0x%p\n", dev);
137
138 #if (CONFIG_GFXUMA == 1)
139         msr_t msr, msr2;
140
141         /* TOP_MEM: the top of DRAM below 4G */
142         msr = rdmsr(TOP_MEM);
143         printk
144             (BIOS_INFO, "%s, TOP MEM: msr.lo = 0x%08x, msr.hi = 0x%08x\n",
145              __func__, msr.lo, msr.hi);
146
147         /* TOP_MEM2: the top of DRAM above 4G */
148         msr2 = rdmsr(TOP_MEM2);
149         printk
150             (BIOS_INFO, "%s, TOP MEM2: msr2.lo = 0x%08x, msr2.hi = 0x%08x\n",
151              __func__, msr2.lo, msr2.hi);
152
153         /* refer to UMA Size Consideration in 780 BDG. */
154         switch (msr.lo) {
155         case 0x10000000:        /* 256M system memory */
156                 uma_memory_size = 0x4000000;    /* 64M recommended UMA */
157                 break;
158
159         case 0x20000000:        /* 512M system memory */
160                 uma_memory_size = 0x8000000;    /* 128M recommended UMA */
161                 break;
162
163         default:                /* 1GB and above system memory */
164                 uma_memory_size = 0x10000000;   /* 256M recommended UMA */
165                 break;
166         }
167
168         uma_memory_base = msr.lo - uma_memory_size;     /* TOP_MEM1 */
169         printk(BIOS_INFO, "%s: uma size 0x%08llx, memory start 0x%08llx\n",
170                     __func__, uma_memory_size, uma_memory_base);
171
172         /* TODO: TOP_MEM2 */
173 #else
174         uma_memory_size = 0x8000000;    /* 128M recommended UMA */
175         uma_memory_base = 0x38000000;   /* 1GB  system memory supposed */
176 #endif
177
178         set_pcie_dereset();
179         enable_int_gfx();
180         /* get_ide_dma66(); */
181 }
182
183 int add_mainboard_resources(struct lb_memory *mem)
184 {
185         /* UMA is removed from system memory in the northbridge code, but
186          * in some circumstances we want the memory mentioned as reserved.
187          */
188 #if (CONFIG_GFXUMA == 1)
189         printk(BIOS_INFO, "uma_memory_start=0x%llx, uma_memory_size=0x%llx \n",
190                     uma_memory_base, uma_memory_size);
191         lb_add_memory_range(mem, LB_MEM_RESERVED, uma_memory_base,
192                             uma_memory_size);
193 #endif
194         return 0;
195 }
196
197 struct chip_operations mainboard_ops = {
198         CHIP_NAME("AMD Bimini Mainboard")
199         .enable_dev = bimini_enable,
200 };