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