f1d1fe26d830cbd83d74af930b428f13ef74ee0f
[coreboot.git] / src / southbridge / sis / sis966 / sis761.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007 Silicon Integrated Systems Corp. (SiS)
5  * Written by Morgan Tsai <my_tsai@sis.com> for SiS.
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; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20  */
21
22 /*
23  * Turn off machine check triggers when reading
24  * pci space where there are no devices.
25  * This is necessary when scaning the bus for
26  * devices which is done by the kernel
27  *
28  * written in 2003 by Eric Biederman
29  *
30  *  - Athlon64 workarounds by Stefan Reinauer
31  *  - "reset once" logic by Yinghai Lu
32  */
33
34 #include <console/console.h>
35 #include <device/device.h>
36 #include <device/pci.h>
37 #include <device/pci_ids.h>
38 #include <device/pci_ops.h>
39 #include <pc80/mc146818rtc.h>
40 #include <bitops.h>
41 #include <cpu/amd/model_fxx_rev.h>
42 #include <arch/io.h>
43
44 /**
45  * @brief Read resources for AGP aperture
46  *
47  * @param
48  *
49  * There is only one AGP aperture resource needed. The resoruce is added to
50  * the northbridge of BSP.
51  *
52  * The same trick can be used to augment legacy VGA resources which can
53  * be detect by generic pci reousrce allocator for VGA devices.
54  * BAD: it is more tricky than I think, the resource allocation code is
55  * implemented in a way to NOT DOING legacy VGA resource allcation on
56  * purpose :-(.
57  */
58
59
60 typedef struct msr_struct
61 {
62         unsigned lo;
63         unsigned hi;
64 } msr_t;
65
66 static inline msr_t rdmsr(unsigned index)
67 {
68         msr_t result;
69         result.lo = 0;
70         result.hi = 0;
71         return result;
72 }
73
74 static void sis761_read_resources(device_t dev)
75 {
76         /* Read the generic PCI resources */
77         printk(BIOS_DEBUG, "sis761_read_resources ------->\n");
78         pci_dev_read_resources(dev);
79
80         /* If we are not the first processor don't allocate the gart apeture */
81         if (dev->path.pci.devfn != PCI_DEVFN(0x0, 0)) {
82                 printk(BIOS_DEBUG, "sis761_not_the_first_processor !!!\n");
83                 return;
84         }
85
86         printk(BIOS_DEBUG, "sis761_read_resources <-------\n");
87         return;
88
89 }
90
91 static void sis761_set_resources(device_t dev)
92 {
93         printk(BIOS_DEBUG, "sis761_set_resources ------->\n");
94
95         /* Set the generic PCI resources */
96         pci_dev_set_resources(dev);
97         printk(BIOS_DEBUG, "sis761_set_resources <-------\n");
98 }
99
100 static void sis761_init(struct device *dev)
101 {
102         int needs_reset;
103         msr_t   msr;
104
105
106         needs_reset = 0;
107         printk(BIOS_DEBUG, "sis761_init: ---------->\n");
108
109         msr = rdmsr(0xC001001A);
110         pci_write_config16(dev, 0x8E, msr.lo >> 16);                            // Topbound
111         pci_write_config8(dev, 0x7F, 0x08);                     // ACPI Base
112         outb(inb(0x856) | 0x40, 0x856);  // Auto-Reset Function
113
114         printk(BIOS_DEBUG, "sis761_init: <----------\n");
115 }
116
117
118 static struct device_operations sis761_ops  = {
119         .read_resources   = sis761_read_resources,
120         .set_resources    = sis761_set_resources,
121         .enable_resources = pci_dev_enable_resources,
122         .init             = sis761_init,
123         .scan_bus         = 0,
124         .ops_pci          = 0,
125 };
126
127 static const struct pci_driver sis761_driver __pci_driver = {
128         .ops    = &sis761_ops,
129         .vendor = PCI_VENDOR_ID_SIS,
130         .device = PCI_DEVICE_ID_SIS_SIS761,
131 };