1. vgabios removed, will go to extra repository
[coreboot.git] / src / southbridge / sis / sis966 / sis761.c
1 /*
2  * This file is part of the LinuxBIOS 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 <part/hard_reset.h>
38 #include <pc80/mc146818rtc.h>
39 #include <bitops.h>
40 #include <cpu/amd/model_fxx_rev.h>
41
42 //#include "amdk8.h"
43
44 #include <arch/io.h>
45
46 /**
47  * @brief Read resources for AGP aperture
48  *
49  * @param
50  *
51  * There is only one AGP aperture resource needed. The resoruce is added to
52  * the northbridge of BSP.
53  *
54  * The same trick can be used to augment legacy VGA resources which can
55  * be detect by generic pci reousrce allocator for VGA devices.
56  * BAD: it is more tricky than I think, the resource allocation code is
57  * implemented in a way to NOT DOING legacy VGA resource allcation on
58  * purpose :-(.
59  */
60
61
62 typedef struct msr_struct
63 {
64         unsigned lo;
65         unsigned hi;
66 } msr_t;
67
68 static inline msr_t rdmsr(unsigned index)
69 {
70         msr_t result;
71         result.lo = 0;
72         result.hi = 0;
73         return result;
74 }
75
76
77
78 static void sis761_read_resources(device_t dev)
79 {
80         struct resource *resource;
81         unsigned char iommu;
82         /* Read the generic PCI resources */
83         printk_debug("sis761_read_resources\n");
84         pci_dev_read_resources(dev);
85
86         /* If we are not the first processor don't allocate the gart apeture */
87         if (dev->path.u.pci.devfn != PCI_DEVFN(0x0, 0)) {
88                 return;
89         }
90
91
92         return;
93
94         iommu = 1;
95         get_option(&iommu, "iommu");
96
97         if (iommu) {
98                 /* Add a Gart apeture resource */
99                 resource = new_resource(dev, 0x94);
100                 resource->size = iommu?AGP_APERTURE_SIZE:1;
101                 resource->align = log2(resource->size);
102                 resource->gran  = log2(resource->size);
103                 resource->limit = 0xffffffff; /* 4G */
104                 resource->flags = IORESOURCE_MEM;
105         }
106 }
107
108 static void set_agp_aperture(device_t dev)
109 {
110         struct resource *resource;
111
112         return;
113
114         resource = probe_resource(dev, 0x94);
115         if (resource) {
116                 device_t pdev;
117                 uint32_t gart_base, gart_acr;
118
119                 /* Remember this resource has been stored */
120                 resource->flags |= IORESOURCE_STORED;
121
122                 /* Find the size of the GART aperture */
123                 gart_acr = (0<<6)|(0<<5)|(0<<4)|((resource->gran - 25) << 1)|(0<<0);
124
125                 /* Get the base address */
126                 gart_base = ((resource->base) >> 25) & 0x00007fff;
127
128                 /* Update the other northbriges */
129                 pdev = 0;
130                 while((pdev = dev_find_device(PCI_VENDOR_ID_AMD, 0x1103, pdev))) {
131                         /* Store the GART size but don't enable it */
132                         pci_write_config32(pdev, 0x90, gart_acr);
133
134                         /* Store the GART base address */
135                         pci_write_config32(pdev, 0x94, gart_base);
136
137                         /* Don't set the GART Table base address */
138                         pci_write_config32(pdev, 0x98, 0);
139
140                         /* Report the resource has been stored... */
141                         report_resource_stored(pdev, resource, " <gart>");
142                 }
143         }
144 }
145
146 static void sis761_set_resources(device_t dev)
147 {
148         printk_debug("sis761_set_resources ------->\n");
149         /* Set the gart apeture */
150 //      set_agp_aperture(dev);
151
152         /* Set the generic PCI resources */
153         pci_dev_set_resources(dev);
154         printk_debug("sis761_set_resources <-------\n");
155 }
156
157 static void sis761_init(struct device *dev)
158 {
159         uint32_t cmd, cmd_ref;
160         int needs_reset;
161         struct device *f0_dev, *f2_dev;
162         msr_t   msr;
163
164
165         needs_reset = 0;
166         printk_debug("sis761_init: ---------->\n");
167
168         msr = rdmsr(0xC001001A);
169         pci_write_config16(dev, 0x8E, msr.lo >> 16);                            // Topbound
170         pci_write_config8(dev, 0x7F, 0x08);                     // ACPI Base
171         outb(inb(0x856) | 0x40, 0x856);  // Auto-Reset Function
172
173         printk_debug("sis761_init: <----------\n");
174         printk_debug("done.\n");
175 }
176
177
178 static struct device_operations sis761_ops  = {
179         .read_resources   = sis761_read_resources,
180         .set_resources    = sis761_set_resources,
181         .enable_resources = pci_dev_enable_resources,
182         .init             = sis761_init,
183         .scan_bus         = 0,
184         .ops_pci          = 0,
185 };
186
187 static const struct pci_driver sis761_driver __pci_driver = {
188         .ops    = &sis761_ops,
189         .vendor = PCI_VENDOR_ID_SIS,
190         .device = PCI_DEVICE_ID_SIS_SIS761,
191 };