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