2 * Shared support code for AMD K8 northbridges and derivates.
3 * Copyright 2006 Andi Kleen, SUSE Labs. Subject to GPLv2.
6 #include <linux/types.h>
7 #include <linux/init.h>
8 #include <linux/errno.h>
9 #include <linux/module.h>
10 #include <linux/spinlock.h>
13 int num_k8_northbridges;
14 EXPORT_SYMBOL(num_k8_northbridges);
16 static u32 *flush_words;
18 struct pci_device_id k8_nb_ids[] = {
19 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MISC) },
20 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_10H_NB_MISC) },
21 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_11H_NB_MISC) },
24 EXPORT_SYMBOL(k8_nb_ids);
26 struct pci_dev **k8_northbridges;
27 EXPORT_SYMBOL(k8_northbridges);
29 static struct pci_dev *next_k8_northbridge(struct pci_dev *dev)
32 dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev);
35 } while (!pci_match_id(&k8_nb_ids[0], dev));
39 int cache_k8_northbridges(void)
44 if (num_k8_northbridges)
48 while ((dev = next_k8_northbridge(dev)) != NULL)
49 num_k8_northbridges++;
51 k8_northbridges = kmalloc((num_k8_northbridges + 1) * sizeof(void *),
56 if (!num_k8_northbridges) {
57 k8_northbridges[0] = NULL;
61 flush_words = kmalloc(num_k8_northbridges * sizeof(u32), GFP_KERNEL);
63 kfree(k8_northbridges);
69 while ((dev = next_k8_northbridge(dev)) != NULL) {
70 k8_northbridges[i] = dev;
71 pci_read_config_dword(dev, 0x9c, &flush_words[i++]);
73 k8_northbridges[i] = NULL;
76 EXPORT_SYMBOL_GPL(cache_k8_northbridges);
78 /* Ignores subdevice/subvendor but as far as I can figure out
79 they're useless anyways */
80 int __init early_is_k8_nb(u32 device)
82 struct pci_device_id *id;
83 u32 vendor = device & 0xffff;
85 for (id = k8_nb_ids; id->vendor; id++)
86 if (vendor == id->vendor && device == id->device)
91 void k8_flush_garts(void)
95 static DEFINE_SPINLOCK(gart_lock);
97 /* Avoid races between AGP and IOMMU. In theory it's not needed
98 but I'm not sure if the hardware won't lose flush requests
99 when another is pending. This whole thing is so expensive anyways
100 that it doesn't matter to serialize more. -AK */
101 spin_lock_irqsave(&gart_lock, flags);
103 for (i = 0; i < num_k8_northbridges; i++) {
104 pci_write_config_dword(k8_northbridges[i], 0x9c,
108 for (i = 0; i < num_k8_northbridges; i++) {
110 /* Make sure the hardware actually executed the flush*/
112 pci_read_config_dword(k8_northbridges[i],
119 spin_unlock_irqrestore(&gart_lock, flags);
121 printk("nothing to flush?\n");
123 EXPORT_SYMBOL_GPL(k8_flush_garts);