9e29546506d3cf87b10649d64200baea5ca7935a
[coreboot.git] / src / mainboard / asrock / 939a785gmh / 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/sb700/sb700.h>
29 #include "chip.h"
30
31 #define SMBUS_IO_BASE 0x6000
32
33 uint64_t uma_memory_base, uma_memory_size;
34
35 void set_pcie_dereset(void);
36 void set_pcie_reset(void);
37 u8 is_dev3_present(void);
38 /*
39  * Mahogany uses GPIO 6 as PCIe slot reset, GPIO4 as GFX slot reset. We need to
40  * pull it up before training the slot.
41  ***/
42 void set_pcie_dereset()
43 {
44         u16 word;
45         device_t sm_dev;
46         /* GPIO 6 reset PCIe slot, GPIO 4 reset GFX PCIe */
47         sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
48
49         word = pci_read_config16(sm_dev, 0xA8);
50         word |= (1 << 0) | (1 << 2);    /* Set Gpio6,4 as output */
51         word &= ~((1 << 8) | (1 << 10));
52         pci_write_config16(sm_dev, 0xA8, word);
53 }
54
55 void set_pcie_reset()
56 {
57         u16 word;
58         device_t sm_dev;
59         /* GPIO 6 reset PCIe slot, GPIO 4 reset GFX PCIe */
60         sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
61
62         word = pci_read_config16(sm_dev, 0xA8);
63         word &= ~((1 << 0) | (1 << 2)); /* Set Gpio6,4 as output */
64         word &= ~((1 << 8) | (1 << 10));
65         pci_write_config16(sm_dev, 0xA8, word);
66 }
67
68 #if 0        /* not tested yet */
69 /********************************************************
70 * mahogany uses SB700 GPIO9 to detect IDE_DMA66.
71 * IDE_DMA66 is routed to GPIO 9. So we read Gpio 9 to
72 * get the cable type, 40 pin or 80 pin?
73 ********************************************************/
74 static void get_ide_dma66(void)
75 {
76         u8 byte;
77         /*u32 sm_dev, ide_dev; */
78         device_t sm_dev, ide_dev;
79
80         sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
81
82         byte = pci_read_config8(sm_dev, 0xA9);
83         byte |= (1 << 5);       /* Set Gpio9 as input */
84         pci_write_config8(sm_dev, 0xA9, byte);
85
86         ide_dev = dev_find_slot(0, PCI_DEVFN(0x14, 1));
87         byte = pci_read_config8(ide_dev, 0x56);
88         byte &= ~(7 << 0);
89         if ((1 << 5) & pci_read_config8(sm_dev, 0xAA))
90                 byte |= 2 << 0; /* mode 2 */
91         else
92                 byte |= 5 << 0; /* mode 5 */
93         pci_write_config8(ide_dev, 0x56, byte);
94 }
95 #endif  /* get_ide_dma66 */
96
97 u8 is_dev3_present(void)
98 {
99         return 0;
100 }
101
102 /*************************************************
103 * enable the dedicated function in mahogany board.
104 * This function called early than rs780_enable.
105 *************************************************/
106 static void mahogany_enable(device_t dev)
107 {
108         /* Leave it for future. */
109         /* struct mainboard_config *mainboard =
110            (struct mainboard_config *)dev->chip_info;*/
111
112         printk(BIOS_INFO, "Mainboard MAHOGANY Enable. dev=0x%p\n", dev);
113
114 #if (CONFIG_GFXUMA == 1)
115         msr_t msr, msr2;
116
117         /* TOP_MEM: the top of DRAM below 4G */
118         msr = rdmsr(TOP_MEM);
119         printk
120             (BIOS_INFO, "%s, TOP MEM: msr.lo = 0x%08x, msr.hi = 0x%08x\n",
121              __func__, msr.lo, msr.hi);
122
123         /* TOP_MEM2: the top of DRAM above 4G */
124         msr2 = rdmsr(TOP_MEM2);
125         printk
126             (BIOS_INFO, "%s, TOP MEM2: msr2.lo = 0x%08x, msr2.hi = 0x%08x\n",
127              __func__, msr2.lo, msr2.hi);
128
129         /* refer to UMA Size Consideration in 780 BDG. */
130         switch (msr.lo) {
131         case 0x10000000:        /* 256M system memory */
132                 uma_memory_size = 0x4000000;    /* 64M recommended UMA */
133                 break;
134
135         case 0x20000000:        /* 512M system memory */
136                 uma_memory_size = 0x8000000;    /* 128M recommended UMA */
137                 break;
138
139         default:                /* 1GB and above system memory */
140                 uma_memory_size = 0x10000000;   /* 256M recommended UMA */
141                 break;
142         }
143
144         uma_memory_base = msr.lo - uma_memory_size;     /* TOP_MEM1 */
145         printk(BIOS_INFO, "%s: uma size 0x%08llx, memory start 0x%08llx\n",
146                     __func__, uma_memory_size, uma_memory_base);
147
148         /* TODO: TOP_MEM2 */
149 #else
150         uma_memory_size = 0x8000000;    /* 128M recommended UMA */
151         uma_memory_base = 0x38000000;   /* 1GB  system memory supposed */
152 #endif
153
154         set_pcie_dereset();
155         /* get_ide_dma66(); */
156 }
157
158 int add_mainboard_resources(struct lb_memory *mem)
159 {
160         /* UMA is removed from system memory in the northbridge code, but
161          * in some circumstances we want the memory mentioned as reserved.
162          */
163 #if (CONFIG_GFXUMA == 1)
164         printk(BIOS_INFO, "uma_memory_start=0x%llx, uma_memory_size=0x%llx \n",
165                     uma_memory_base, uma_memory_size);
166         lb_add_memory_range(mem, LB_MEM_RESERVED, uma_memory_base,
167                             uma_memory_size);
168 #endif
169         return 0;
170 }
171
172 struct chip_operations mainboard_ops = {
173         CHIP_NAME("AMD MAHOGANY   Mainboard")
174         .enable_dev = mahogany_enable,
175 };