ck804 pref mem 4G above support
[coreboot.git] / src / southbridge / nvidia / ck804 / ck804_pci.c
1 /*
2  * Copyright 2004 Tyan Computer
3  *  by yhlu@tyan.com
4  */
5
6 #include <console/console.h>
7 #include <device/device.h>
8 #include <device/pci.h>
9 #include <device/pci_ids.h>
10 #include <device/pci_ops.h>
11 #include "ck804.h"
12
13 static void pci_init(struct device *dev)
14 {
15
16         uint32_t dword;
17 #if CONFIG_PCI_64BIT_PREF_MEM == 1
18         device_t pci_domain_dev;
19         struct resource *mem1, *mem2;
20 #endif
21         
22         /* System error enable */
23         dword = pci_read_config32(dev, 0x04);
24         dword |= (1<<8); /* System error enable */
25         dword |= (1<<30); /* Clear possible errors */
26         pci_write_config32(dev, 0x04, dword);
27
28 #if 0
29         word = pci_read_config16(dev, 0x48);
30         word |= (1<<0); /* MRL2MRM */
31         word |= (1<<2); /* MR2MRM */
32         pci_write_config16(dev, 0x48, word);
33 #endif
34
35 #if 1
36         dword = pci_read_config32(dev, 0x4c);
37         dword |= 0x00440000; /*TABORT_SER_ENABLE Park Last Enable.*/
38         pci_write_config32(dev, 0x4c, dword);
39 #endif
40
41 #if CONFIG_PCI_64BIT_PREF_MEM == 1
42         pci_domain_dev = dev->bus->dev;
43         while(pci_domain_dev) {
44                 if(pci_domain_dev->path.type == DEVICE_PATH_PCI_DOMAIN) break;
45                 pci_domain_dev = pci_domain_dev->bus->dev;
46         }
47
48         if(!pci_domain_dev) return; // impossiable
49         mem1 = find_resource(pci_domain_dev, 1); // prefmem, it could be 64bit
50         mem2 = find_resource(pci_domain_dev, 2); // mem
51         if(mem1->base > mem2->base) {
52                 dword = mem2->base  & (0xffff0000UL);
53                 printk_debug("PCI DOMAIN mem2 base = 0x%010Lx\n", mem2->base);
54         } else {
55                 dword = mem1->base  & (0xffff0000UL);
56                 printk_debug("PCI DOMAIN mem1 (prefmem) base = 0x%010Lx\n", mem1->base);
57         }
58 #else
59         dword = dev_root.resource[1].base & (0xffff0000UL);
60         printk_debug("dev_root mem base = 0x%010Lx\n", dev_root.resource[1].base);
61 #endif
62
63         printk_debug("[0x50] <-- 0x%08x\n", dword);
64         pci_write_config32(dev, 0x50, dword); //TOM
65
66 }
67
68 static struct pci_operations lops_pci = {
69         .set_subsystem = 0,
70 };
71
72 static struct device_operations pci_ops  = {
73         .read_resources   = pci_bus_read_resources,
74         .set_resources    = pci_dev_set_resources,
75         .enable_resources = pci_bus_enable_resources,
76         .init             = pci_init,
77         .scan_bus         = pci_scan_bridge,
78 //      .enable           = ck804_enable,
79         .ops_pci          = &lops_pci,
80 };
81
82 static struct pci_driver pci_driver __pci_driver = {
83         .ops    = &pci_ops,
84         .vendor = PCI_VENDOR_ID_NVIDIA,
85         .device = PCI_DEVICE_ID_NVIDIA_CK804_PCI,
86 };
87