1 #include <console/console.h>
4 #include <device/device.h>
5 #include <device/pci.h>
6 #include <device/hypertransport.h>
7 #include <device/pci_ids.h>
12 #include <cpu/x86/mtrr.h>
13 #include <cpu/x86/msr.h>
15 #include "northbridge.h"
18 * This fixup is based on capturing values from an Award bios. Without
19 * this fixup the DMA write performance is awful (i.e. hdparm -t /dev/hda is 20x
20 * slower than normal, ethernet drops packets).
21 * Apparently these registers govern some sort of bus master behavior.
24 static void dump_dev(device_t dev)
28 for(i = 0; i < 256; i += 16) {
29 printk_debug("0x%x: ", i);
30 for(j = 0; j < 16; j++) {
31 printk_debug("%02x ", pci_read_config8(dev, i+j));
38 static void northbridge_init(device_t dev)
44 printk_debug("VT8623 random fixup ...\n");
45 pci_write_config8(dev, 0x0d, 0x08);
46 pci_write_config8(dev, 0x70, 0x82);
47 pci_write_config8(dev, 0x71, 0xc8);
48 pci_write_config8(dev, 0x72, 0x00);
49 pci_write_config8(dev, 0x73, 0x01);
50 pci_write_config8(dev, 0x74, 0x01);
51 pci_write_config8(dev, 0x75, 0x08);
52 pci_write_config8(dev, 0x76, 0x52);
53 pci_write_config8(dev, 0x13, 0xd0);
54 pci_write_config8(dev, 0x84, 0x80);
55 pci_write_config16(dev, 0x80, 0x610f);
56 pci_write_config32(dev, 0x88, 0x00000002);
58 fb_dev = dev_find_device(PCI_VENDOR_ID_VIA, 0x3122, 0);
60 /* Fixup GART and framebuffer addresses properly.
61 * First setup frame buffer properly.
63 //fb = pci_read_config32(dev, 0x10); /* Base addres of framebuffer */
65 printk_debug("Frame buffer at %8x\n",fb);
67 c = pci_read_config8(dev, 0xe1) & 0xf0; /* size of vga */
68 c |= fb>>28; /* upper nibble of frame buffer address */
70 pci_write_config8(dev, 0xe1, c);
71 c = 0x81; /* enable framebuffer */
72 pci_write_config8(dev, 0xe0, c);
73 pci_write_config8(dev, 0xe2, 0x42); /* 'cos award does */
78 static void nullfunc(){}
80 static struct device_operations northbridge_operations = {
81 .read_resources = nullfunc,
82 .set_resources = pci_dev_set_resources,
83 .enable_resources = pci_dev_enable_resources,
84 .init = northbridge_init
87 static const struct pci_driver northbridge_driver __pci_driver = {
88 .ops = &northbridge_operations,
89 .vendor = PCI_VENDOR_ID_VIA,
90 .device = PCI_DEVICE_ID_VIA_8623,
93 static void agp_init(device_t dev)
95 printk_debug("VT8623 AGP random fixup ...\n");
97 pci_write_config8(dev, 0x3e, 0x0c);
98 pci_write_config8(dev, 0x40, 0x83);
99 pci_write_config8(dev, 0x41, 0xc5);
100 pci_write_config8(dev, 0x43, 0x44);
101 pci_write_config8(dev, 0x44, 0x34);
102 pci_write_config8(dev, 0x83, 0x02);
106 static struct device_operations agp_operations = {
107 .read_resources = nullfunc,
108 .set_resources = pci_dev_set_resources,
109 .enable_resources = pci_bus_enable_resources,
111 .scan_bus = pci_scan_bridge,
115 static const struct pci_driver agp_driver __pci_driver = {
116 .ops = &agp_operations,
117 .vendor = PCI_VENDOR_ID_VIA,
118 .device = PCI_DEVICE_ID_VIA_8633_1,
121 static void vga_init(device_t dev)
124 msr_t clocks1,clocks2,instructions,setup;
126 printk_debug("VGA random fixup ...\n");
127 pci_write_config8(dev, 0x04, 0x07);
128 pci_write_config8(dev, 0x0d, 0x20);
129 pci_write_config32(dev,0x10,0xd8000008);
130 pci_write_config32(dev,0x14,0xdc000000);
134 // set up performnce counters for debugging vga init sequence
135 //setup.lo = 0x1c0; // count instructions
136 //wrmsr(0x187,setup);
137 //instructions.hi = 0;
138 //instructions.lo = 0;
139 //wrmsr(0xc2,instructions);
140 //clocks1 = rdmsr(0x10);
144 /* code to make vga init go through the emulator - as of yet this does not workfor the epia-m */
146 dev->rom_address = (void *)0xfffc0000;
150 call_bios_interrupt(0x10,0x4f1f,0x8003,1,0);
152 //clocks2 = rdmsr(0x10);
153 //instructions = rdmsr(0xc2);
155 printk_debug("Clocks 1 = %08x:%08x\n",clocks1.hi,clocks1.lo);
156 printk_debug("Clocks 2 = %08x:%08x\n",clocks2.hi,clocks2.lo);
157 printk_debug("Instructions = %08x:%08x\n",instructions.hi,instructions.lo);
161 /* code to make vga init run in real mode - does work but against the current coreboot philosophy */
162 printk_debug("INSTALL REAL-MODE IDT\n");
163 setup_realmode_idt();
164 printk_debug("DO THE VGA BIOS\n");
167 //clocks2 = rdmsr(0x10);
168 //instructions = rdmsr(0xc2);
170 //printk_debug("Clocks 1 = %08x:%08x\n",clocks1.hi,clocks1.lo);
171 //printk_debug("Clocks 2 = %08x:%08x\n",clocks2.hi,clocks2.lo);
172 //printk_debug("Instructions = %08x:%08x\n",instructions.hi,instructions.lo);
174 vga_enable_console();
179 pci_write_config32(dev,0x30,0);
181 /* Set the vga mtrrs - disable for the moment as the add_var_mtrr function has vapourised */
183 add_var_mtrr( 0xd0000000 >> 10, 0x08000000>>10, MTRR_TYPE_WRCOMB);
184 fb = pci_read_config32(dev,0x10); // get the fb address
185 add_var_mtrr( fb>>10, 8192, MTRR_TYPE_WRCOMB);
189 static void vga_read_resources(device_t dev)
192 dev->rom_address = (void *)0xfffc0000;
194 pci_dev_read_resources(dev);
198 static struct device_operations vga_operations = {
199 .read_resources = vga_read_resources,
200 .set_resources = pci_dev_set_resources,
201 .enable_resources = pci_dev_enable_resources,
206 static const struct pci_driver vga_driver __pci_driver = {
207 .ops = &vga_operations,
208 .vendor = PCI_VENDOR_ID_VIA,
213 #define BRIDGE_IO_MASK (IORESOURCE_IO | IORESOURCE_MEM)
215 static void pci_domain_read_resources(device_t dev)
217 struct resource *resource;
219 printk_spew("Entering vt8623 pci_domain_read_resources.\n");
221 /* Initialize the system wide io space constraints */
222 resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0,0));
223 resource->limit = 0xffffUL;
224 resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
227 /* Initialize the system wide memory resources constraints */
228 resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1,0));
229 resource->limit = 0xffffffffULL;
230 resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE |
233 printk_spew("Leaving vt8623 pci_domain_read_resources.\n");
236 static void ram_resource(device_t dev, unsigned long index,
237 unsigned long basek, unsigned long sizek)
239 struct resource *resource;
244 resource = new_resource(dev, index);
245 resource->base = ((resource_t)basek) << 10;
246 resource->size = ((resource_t)sizek) << 10;
247 resource->flags = IORESOURCE_MEM | IORESOURCE_CACHEABLE | \
248 IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
251 static void tolm_test(void *gp, struct device *dev, struct resource *new)
253 struct resource **best_p = gp;
254 struct resource *best;
256 if (!best || (best->base > new->base)) {
262 static uint32_t find_pci_tolm(struct bus *bus)
264 struct resource *min;
267 search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, tolm_test, &min);
269 if (min && tolm > min->base) {
275 static void pci_domain_set_resources(device_t dev)
277 static const uint8_t ramregs[] = {0x5a, 0x5b, 0x5c, 0x5d };
281 printk_spew("Entering vt8623 pci_domain_set_resources.\n");
283 pci_tolm = find_pci_tolm(&dev->link[0]);
284 mc_dev = dev->link[0].children;
286 unsigned long tomk, tolmk;
287 unsigned char rambits;
290 for(rambits = 0, i = 0; i < ARRAY_SIZE(ramregs); i++) {
292 reg = pci_read_config8(mc_dev, ramregs[i]);
293 /* these are ENDING addresses, not sizes.
294 * if there is memory in this slot, then reg will be > rambits.
295 * So we just take the max, that gives us total.
296 * We take the highest one to cover for once and future coreboot
297 * bugs. We warn about bugs.
302 printk_err("ERROR! register 0x%x is not set!\n",
305 printk_debug("I would set ram size to 0x%x Kbytes\n", (rambits)*16*1024);
306 tomk = rambits*16*1024 - 32768;
307 /* Compute the top of Low memory */
308 tolmk = pci_tolm >> 10;
310 /* The PCI hole does does not overlap the memory.
314 /* Report the memory regions */
316 ram_resource(dev, idx++, 0, 640); /* first 640k */
317 ram_resource(dev, idx++, 768, tolmk - 768); /* leave a hole for vga */
319 assign_resources(&dev->link[0]);
322 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max)
324 printk_spew("Entering vt8623 pci_domain_scan_bus.\n");
326 max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max);
330 static struct device_operations pci_domain_ops = {
331 .read_resources = pci_domain_read_resources,
332 .set_resources = pci_domain_set_resources,
333 .enable_resources = enable_childrens_resources,
335 .scan_bus = pci_domain_scan_bus,
338 static void cpu_bus_init(device_t dev)
340 initialize_cpus(&dev->link[0]);
343 static void cpu_bus_noop(device_t dev)
347 static struct device_operations cpu_bus_ops = {
348 .read_resources = cpu_bus_noop,
349 .set_resources = cpu_bus_noop,
350 .enable_resources = cpu_bus_noop,
351 .init = cpu_bus_init,
355 static void enable_dev(struct device *dev)
357 printk_spew("In vt8623 enable_dev for device %s.\n", dev_path(dev));
359 /* Set the operations if it is a special bus type */
360 if (dev->path.type == DEVICE_PATH_PCI_DOMAIN) {
361 dev->ops = &pci_domain_ops;
364 else if (dev->path.type == DEVICE_PATH_APIC_CLUSTER) {
365 dev->ops = &cpu_bus_ops;
369 struct chip_operations northbridge_via_vt8623_ops = {
370 CHIP_NAME("VIA VT8623 Northbridge")
371 .enable_dev = enable_dev,