Add CONFIG_GENERATE_* for tables so that the user can select which tables not
[coreboot.git] / src / northbridge / intel / i82830 / northbridge.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2008 Joseph Smith <joe@smittys.pointclark.net>
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; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20
21 #include <console/console.h>
22 #include <arch/io.h>
23 #include <stdint.h>
24 #include <device/device.h>
25 #include <device/pci.h>
26 #include <device/pci_ids.h>
27 #include <cpu/cpu.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <bitops.h>
31 #include "chip.h"
32 #include "i82830.h"
33
34 static void northbridge_init(device_t dev)
35 {
36         printk_spew("Northbridge init\n");
37 }
38
39 static struct device_operations northbridge_operations = {
40         .read_resources = pci_dev_read_resources,
41         .set_resources = pci_dev_set_resources,
42         .enable_resources = pci_dev_enable_resources,
43         .init = northbridge_init,
44         .enable = 0,
45         .ops_pci = 0,
46 };
47
48 static struct pci_driver northbridge_driver __pci_driver = {
49         .ops = &northbridge_operations,
50         .vendor = PCI_VENDOR_ID_INTEL,
51         .device = 0x3575,
52 };
53
54 static void ram_resource(device_t dev, unsigned long index,
55                          unsigned long basek, unsigned long sizek)
56 {
57         struct resource *resource;
58
59         if (!sizek)
60                 return;
61         resource = new_resource(dev, index);
62         resource->base = ((resource_t) basek) << 10;
63         resource->size = ((resource_t) sizek) << 10;
64         resource->flags = IORESOURCE_MEM | IORESOURCE_CACHEABLE |
65             IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
66 }
67
68 static void tolm_test(void *gp, struct device *dev, struct resource *new)
69 {
70         struct resource **best_p = gp;
71         struct resource *best;
72         best = *best_p;
73         if (!best || (best->base > new->base))
74                 best = new;
75         *best_p = best;
76 }
77
78 static uint32_t find_pci_tolm(struct bus *bus)
79 {
80         struct resource *min;
81         uint32_t tolm;
82         min = 0;
83         search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, tolm_test,
84                              &min);
85         tolm = 0xffffffffUL;
86         if (min && tolm > min->base)
87                 tolm = min->base;
88         return tolm;
89 }
90
91 #if CONFIG_WRITE_HIGH_TABLES==1
92 #define HIGH_TABLES_SIZE 64     // maximum size of high tables in KB
93 extern uint64_t high_tables_base, high_tables_size;
94 #endif
95 static void pci_domain_set_resources(device_t dev)
96 {
97         device_t mc_dev;
98         uint32_t pci_tolm;
99         int igd_memory = 0;
100
101         pci_tolm = find_pci_tolm(&dev->link[0]);
102         mc_dev = dev->link[0].children;
103         if (mc_dev) {
104                 unsigned long tomk, tolmk;
105                 int idx;
106
107                 if (CONFIG_VIDEO_MB == 512) {
108                         igd_memory = (CONFIG_VIDEO_MB);
109                 } else {
110                         igd_memory = (CONFIG_VIDEO_MB * 1024);
111                 }
112
113                 /* Get the value of the highest DRB. This tells the end of
114                  * the physical memory. The units are ticks of 32MB
115                  * i.e. 1 means 32MB.
116                  */
117                 tomk = ((unsigned long)pci_read_config8(mc_dev, DRB + 3)) << 15;
118                 tomk -= igd_memory;
119                 printk_debug("Setting RAM size to %d\n", tomk);
120
121                 /* Compute the top of low memory. */
122                 tolmk = pci_tolm >> 10;
123                 if (tolmk >= tomk) {
124                         /* The PCI hole does does not overlap the memory. */
125                         tolmk = tomk;
126                 }
127
128                 /* Report the memory regions. */
129                 idx = 10;
130                 ram_resource(dev, idx++, 0, 640);
131                 ram_resource(dev, idx++, 1024, tolmk - 1024);
132
133 #if CONFIG_WRITE_HIGH_TABLES==1
134                 /* Leave some space for ACPI, PIRQ and MP tables */
135                 high_tables_base = (tomk - HIGH_TABLES_SIZE) * 1024;
136                 high_tables_size = HIGH_TABLES_SIZE * 1024;
137 #endif
138         }
139         assign_resources(&dev->link[0]);
140 }
141
142 static struct device_operations pci_domain_ops = {
143         .read_resources         = pci_domain_read_resources,
144         .set_resources          = pci_domain_set_resources,
145         .enable_resources       = enable_childrens_resources,
146         .init                   = 0,
147         .scan_bus               = pci_domain_scan_bus,
148 };
149
150 static void cpu_bus_init(device_t dev)
151 {
152         initialize_cpus(&dev->link[0]);
153 }
154
155 static void cpu_bus_noop(device_t dev)
156 {
157 }
158
159 static struct device_operations cpu_bus_ops = {
160         .read_resources         = cpu_bus_noop,
161         .set_resources          = cpu_bus_noop,
162         .enable_resources       = cpu_bus_noop,
163         .init                   = cpu_bus_init,
164         .scan_bus               = 0,
165 };
166
167 static void enable_dev(struct device *dev)
168 {
169         struct device_path;
170
171         /* Set the operations if it is a special bus type. */
172         if (dev->path.type == DEVICE_PATH_PCI_DOMAIN) {
173                 dev->ops = &pci_domain_ops;
174                 pci_set_method(dev);
175         } else if (dev->path.type == DEVICE_PATH_APIC_CLUSTER) {
176                 dev->ops = &cpu_bus_ops;
177         }
178 }
179
180 struct chip_operations northbridge_intel_i82830_ops = {
181         CHIP_NAME("Intel 82830 Northbridge")
182         .enable_dev = enable_dev,
183 };