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