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>
14 #include "northbridge.h"
17 * This fixup is based on capturing values from an Award bios. Without
18 * this fixup the DMA write performance is awful (i.e. hdparm -t /dev/hda is 20x
19 * slower than normal, ethernet drops packets).
20 * Apparently these registers govern some sort of bus master behavior.
22 static void northbridge_init(device_t dev)
28 printk_debug("VT8623 random fixup ...\n");
29 pci_write_config8(dev, 0x0d, 0x08);
30 pci_write_config8(dev, 0x70, 0x82);
31 pci_write_config8(dev, 0x71, 0xc8);
32 pci_write_config8(dev, 0x72, 0x00);
33 pci_write_config8(dev, 0x73, 0x01);
34 pci_write_config8(dev, 0x74, 0x01);
35 pci_write_config8(dev, 0x75, 0x08);
36 pci_write_config8(dev, 0x76, 0x52);
37 pci_write_config8(dev, 0x13, 0xd0);
38 pci_write_config8(dev, 0x84, 0x80);
39 pci_write_config16(dev, 0x80, 0x610f);
40 pci_write_config32(dev, 0x88, 0x00000002);
42 fb_dev = dev_find_device(PCI_VENDOR_ID_VIA, 0x3122, 0);
44 /* Fixup GART and framebuffer addresses properly.
45 * First setup frame buffer properly.
47 fb = pci_read_config32(dev, 0x10); /* Base addres of framebuffer */
48 printk_debug("Frame buffer at %8x\n",fb);
50 c = pci_read_config8(dev, 0xe1) & 0xf0; /* size of vga */
51 c |= fb>>28; /* upper nibble of frame buffer address */
52 pci_write_config8(dev, 0xe1, c);
53 c = (fb>>20) | 1; /* enable framebuffer */
54 pci_write_config8(dev, 0xe0, c);
55 pci_write_config8(dev, 0xe2, 0x42); /* 'cos award does */
60 static struct device_operations northbridge_operations = {
61 .read_resources = pci_dev_read_resources,
62 .set_resources = pci_dev_set_resources,
63 .enable_resources = pci_dev_enable_resources,
64 .init = northbridge_init
67 static struct pci_driver northbridge_driver __pci_driver = {
68 .ops = &northbridge_operations,
69 .vendor = PCI_VENDOR_ID_VIA,
70 .device = PCI_DEVICE_ID_VIA_8623,
73 static void agp_init(device_t dev)
75 printk_debug("VT8623 AGP random fixup ...\n");
77 pci_write_config8(dev, 0x3e, 0x0c);
78 pci_write_config8(dev, 0x40, 0x83);
79 pci_write_config8(dev, 0x41, 0xc5);
80 pci_write_config8(dev, 0x43, 0x44);
81 pci_write_config8(dev, 0x44, 0x34);
82 pci_write_config8(dev, 0x83, 0x02);
85 static struct device_operations agp_operations = {
86 .read_resources = pci_bus_read_resources,
87 .set_resources = pci_dev_set_resources,
88 .enable_resources = pci_bus_enable_resources,
90 .scan_bus = pci_scan_bridge,
94 static struct pci_driver agp_driver __pci_driver = {
95 .ops = &agp_operations,
96 .vendor = PCI_VENDOR_ID_VIA,
97 .device = PCI_DEVICE_ID_VIA_8633_1,
100 static void vga_init(device_t dev)
104 printk_debug("VGA random fixup ...\n");
105 pci_write_config8(dev, 0x04, 0x07);
106 pci_write_config8(dev, 0x0d, 0x20);
108 /* Set the vga mtrrs - disable for the moment */
110 add_var_mtrr( 0xd0000000 >> 10, 0x08000000>>10, MTRR_TYPE_WRCOMB);
111 fb = pci_read_config32(dev,0x10); // get the fb address
112 add_var_mtrr( fb>>10, 8192, MTRR_TYPE_WRCOMB);
116 static struct device_operations vga_operations = {
117 .read_resources = pci_dev_read_resources,
118 .set_resources = pci_dev_set_resources,
119 .enable_resources = pci_dev_enable_resources,
124 static struct pci_driver vga_driver __pci_driver = {
125 .ops = &vga_operations,
126 .vendor = PCI_VENDOR_ID_VIA,
131 #define BRIDGE_IO_MASK (IORESOURCE_IO | IORESOURCE_MEM)
133 static void pci_domain_read_resources(device_t dev)
135 struct resource *resource;
137 printk_spew("Entering vt8623 pci_domain_read_resources.\n");
139 /* Initialize the system wide io space constraints */
140 resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0,0));
141 resource->limit = 0xffffUL;
142 resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
145 /* Initialize the system wide memory resources constraints */
146 resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1,0));
147 resource->limit = 0xffffffffULL;
148 resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE |
151 printk_spew("Leaving vt8623 pci_domain_read_resources.\n");
154 static void ram_resource(device_t dev, unsigned long index,
155 unsigned long basek, unsigned long sizek)
157 struct resource *resource;
162 resource = new_resource(dev, index);
163 resource->base = ((resource_t)basek) << 10;
164 resource->size = ((resource_t)sizek) << 10;
165 resource->flags = IORESOURCE_MEM | IORESOURCE_CACHEABLE | \
166 IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
169 static void tolm_test(void *gp, struct device *dev, struct resource *new)
171 struct resource **best_p = gp;
172 struct resource *best;
174 if (!best || (best->base > new->base)) {
180 static uint32_t find_pci_tolm(struct bus *bus)
182 struct resource *min;
185 search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, tolm_test, &min);
187 if (min && tolm > min->base) {
193 static void pci_domain_set_resources(device_t dev)
195 static const uint8_t ramregs[] = {0x5a, 0x5b, 0x5c, 0x5d };
199 printk_spew("Entering vt8623 pci_domain_set_resources.\n");
201 pci_tolm = find_pci_tolm(&dev->link[0]);
202 mc_dev = dev->link[0].children;
204 unsigned long tomk, tolmk;
205 unsigned char rambits;
208 for(rambits = 0, i = 0; i < sizeof(ramregs)/sizeof(ramregs[0]); i++) {
210 reg = pci_read_config8(mc_dev, ramregs[i]);
211 /* these are ENDING addresses, not sizes.
212 * if there is memory in this slot, then reg will be > rambits.
213 * So we just take the max, that gives us total.
214 * We take the highest one to cover for once and future linuxbios
215 * bugs. We warn about bugs.
220 printk_err("ERROR! register 0x%x is not set!\n",
223 printk_debug("I would set ram size to 0x%x Kbytes\n", (rambits)*16*1024);
224 tomk = rambits*16*1024 - 32768;
225 /* Compute the top of Low memory */
226 tolmk = pci_tolm >> 10;
228 /* The PCI hole does does not overlap the memory.
232 /* Report the memory regions */
234 ram_resource(dev, idx++, 0, 640); /* first 640k */
235 ram_resource(dev, idx++, 768, tolmk - 768); /* leave a hole for vga */
237 assign_resources(&dev->link[0]);
240 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max)
242 printk_spew("Entering vt8623 pci_domain_scan_bus.\n");
244 max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max);
248 static struct device_operations pci_domain_ops = {
249 .read_resources = pci_domain_read_resources,
250 .set_resources = pci_domain_set_resources,
251 .enable_resources = enable_childrens_resources,
253 .scan_bus = pci_domain_scan_bus,
256 static void cpu_bus_init(device_t dev)
258 initialize_cpus(&dev->link[0]);
261 static void cpu_bus_noop(device_t dev)
265 static struct device_operations cpu_bus_ops = {
266 .read_resources = cpu_bus_noop,
267 .set_resources = cpu_bus_noop,
268 .enable_resources = cpu_bus_noop,
269 .init = cpu_bus_init,
273 static void enable_dev(struct device *dev)
275 printk_spew("In vt8623 enable_dev for device %s.\n", dev_path(dev));
277 /* Set the operations if it is a special bus type */
278 if (dev->path.type == DEVICE_PATH_PCI_DOMAIN) {
279 dev->ops = &pci_domain_ops;
282 else if (dev->path.type == DEVICE_PATH_APIC_CLUSTER) {
283 dev->ops = &cpu_bus_ops;
287 struct chip_operations northbridge_via_vt8623_ops = {
288 CHIP_NAME("VIA vt8623 Northbridge")
289 .enable_dev = enable_dev,