printk_foo -> printk(BIOS_FOO, ...)
[coreboot.git] / src / northbridge / amd / amdfam10 / misc_control.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2003 by Eric Biederman
5  * Copyright (C) Stefan Reinauer
6  * Copyright (C) 2007 Advanced Micro Devices, Inc.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
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 /* Turn off machine check triggers when reading
23  * pci space where there are no devices.
24  * This is necessary when scaning the bus for
25  * devices which is done by the kernel
26  */
27
28 #include <console/console.h>
29 #include <device/device.h>
30 #include <device/pci.h>
31 #include <device/pci_ids.h>
32 #include <device/pci_ops.h>
33 #include <pc80/mc146818rtc.h>
34 #include <bitops.h>
35 #include <cpu/amd/model_10xxx_rev.h>
36
37 #include "amdfam10.h"
38
39 /**
40  * @brief Read resources for AGP aperture
41  *
42  * @param
43  *
44  * There is only one AGP aperture resource needed. The resoruce is added to
45  * the northbridge of BSP.
46  *
47  * The same trick can be used to augment legacy VGA resources which can
48  * be detect by generic pci reousrce allocator for VGA devices.
49  * BAD: it is more tricky than I think, the resource allocation code is
50  * implemented in a way to NOT DOING legacy VGA resource allcation on
51  * purpose :-(.
52  */
53 static void mcf3_read_resources(device_t dev)
54 {
55         struct resource *resource;
56         unsigned char iommu;
57         /* Read the generic PCI resources */
58         pci_dev_read_resources(dev);
59
60         /* If we are not the first processor don't allocate the gart apeture */
61         if (dev->path.pci.devfn != PCI_DEVFN(CONFIG_CDB, 3)) {
62                 return;
63         }
64
65         iommu = 1;
66         get_option(&iommu, "iommu");
67
68         if (iommu) {
69                 /* Add a Gart apeture resource */
70                 resource = new_resource(dev, 0x94);
71                 resource->size = iommu?CONFIG_AGP_APERTURE_SIZE:1;
72                 resource->align = log2(resource->size);
73                 resource->gran  = log2(resource->size);
74                 resource->limit = 0xffffffff; /* 4G */
75                 resource->flags = IORESOURCE_MEM;
76         }
77 }
78
79 static void set_agp_aperture(device_t dev)
80 {
81         struct resource *resource;
82
83         resource = probe_resource(dev, 0x94);
84         if (resource) {
85                 device_t pdev;
86                 u32 gart_base, gart_acr;
87
88                 /* Remember this resource has been stored */
89                 resource->flags |= IORESOURCE_STORED;
90
91                 /* Find the size of the GART aperture */
92                 gart_acr = (0<<6)|(0<<5)|(0<<4)|((resource->gran - 25) << 1)|(0<<0);
93
94                 /* Get the base address */
95                 gart_base = ((resource->base) >> 25) & 0x00007fff;
96
97                 /* Update the other northbriges */
98                 pdev = 0;
99                 while((pdev = dev_find_device(PCI_VENDOR_ID_AMD, 0x1203, pdev))) {
100                         /* Store the GART size but don't enable it */
101                         pci_write_config32(pdev, 0x90, gart_acr);
102
103                         /* Store the GART base address */
104                         pci_write_config32(pdev, 0x94, gart_base);
105
106                         /* Don't set the GART Table base address */
107                         pci_write_config32(pdev, 0x98, 0);
108
109                         /* Report the resource has been stored... */
110                         report_resource_stored(pdev, resource, " <gart>");
111                 }
112         }
113 }
114
115 static void mcf3_set_resources(device_t dev)
116 {
117         /* Set the gart apeture */
118         set_agp_aperture(dev);
119
120         /* Set the generic PCI resources */
121         pci_dev_set_resources(dev);
122 }
123
124 static void misc_control_init(struct device *dev)
125 {
126         u32 cmd;
127
128         printk(BIOS_DEBUG, "NB: Function 3 Misc Control.. ");
129
130         /* Disable Machine checks from Invalid Locations.
131          * This is needed for PC backwards compatibility.
132          */
133         cmd = pci_read_config32(dev, 0x44);
134         cmd |= (1<<6) | (1<<25);
135         pci_write_config32(dev, 0x44, cmd );
136
137         printk(BIOS_DEBUG, "done.\n");
138 }
139
140
141 static struct device_operations mcf3_ops  = {
142         .read_resources   = mcf3_read_resources,
143         .set_resources    = mcf3_set_resources,
144         .enable_resources = pci_dev_enable_resources,
145         .init             = misc_control_init,
146         .scan_bus         = 0,
147         .ops_pci          = 0,
148 };
149
150 static const struct pci_driver mcf3_driver __pci_driver = {
151         .ops    = &mcf3_ops,
152         .vendor = PCI_VENDOR_ID_AMD,
153         .device = 0x1203,
154 };