Merge master.kernel.org:/pub/scm/linux/kernel/git/davej/agpgart
[linux-drm-fsl-dcu.git] / drivers / char / agp / nvidia-agp.c
index 80dafa3030bd5433a9e128dc62820ea6cc95f180..2563286b2fcf3db9a112a986147cd0d23c2c5ed0 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/gfp.h>
 #include <linux/page-flags.h>
 #include <linux/mm.h>
+#include <linux/jiffies.h>
 #include "agp.h"
 
 /* NVIDIA registers */
@@ -72,7 +73,7 @@ static int nvidia_init_iorr(u32 base, u32 size)
        /* Find the iorr that is already used for the base */
        /* If not found, determine the uppermost available iorr */
        free_iorr_addr = AMD_K7_NUM_IORR;
-       for(iorr_addr = 0; iorr_addr < AMD_K7_NUM_IORR; iorr_addr++) {
+       for (iorr_addr = 0; iorr_addr < AMD_K7_NUM_IORR; iorr_addr++) {
                rdmsr(IORR_BASE0 + 2 * iorr_addr, base_lo, base_hi);
                rdmsr(IORR_MASK0 + 2 * iorr_addr, mask_lo, mask_hi);
 
@@ -82,7 +83,7 @@ static int nvidia_init_iorr(u32 base, u32 size)
                if ((mask_lo & 0x00000800) == 0)
                        free_iorr_addr = iorr_addr;
        }
-       
+
        if (iorr_addr >= AMD_K7_NUM_IORR) {
                iorr_addr = free_iorr_addr;
                if (iorr_addr >= AMD_K7_NUM_IORR)
@@ -139,7 +140,7 @@ static int nvidia_configure(void)
        }
 
        /* attbase */
-       for(i = 0; i < 8; i++) {
+       for (i = 0; i < 8; i++) {
                pci_write_config_dword(nvidia_private.dev_2, NVIDIA_2_ATTBASE(i),
                        (agp_bridge->gatt_bus_addr + (i % num_dirs) * 64 * 1024) | 1);
        }
@@ -197,15 +198,15 @@ extern int agp_memory_reserved;
 static int nvidia_insert_memory(struct agp_memory *mem, off_t pg_start, int type)
 {
        int i, j;
-       
+
        if ((type != 0) || (mem->type != 0))
                return -EINVAL;
-       
+
        if ((pg_start + mem->page_count) >
                (nvidia_private.num_active_entries - agp_memory_reserved/PAGE_SIZE))
                return -EINVAL;
-       
-       for(j = pg_start; j < (pg_start + mem->page_count); j++) {
+
+       for (j = pg_start; j < (pg_start + mem->page_count); j++) {
                if (!PGE_EMPTY(agp_bridge, readl(agp_bridge->gatt_table+nvidia_private.pg_offset+j)))
                        return -EBUSY;
        }
@@ -256,7 +257,7 @@ static void nvidia_tlbflush(struct agp_memory *mem)
                do {
                        pci_read_config_dword(nvidia_private.dev_1,
                                        NVIDIA_1_WBC, &wbc_reg);
-                       if ((signed)(end - jiffies) <= 0) {
+                       if (time_before_eq(end, jiffies)) {
                                printk(KERN_ERR PFX
                                    "TLB flush took more than 3 seconds.\n");
                        }
@@ -264,9 +265,9 @@ static void nvidia_tlbflush(struct agp_memory *mem)
        }
 
        /* flush TLB entries */
-       for(i = 0; i < 32 + 1; i++)
+       for (i = 0; i < 32 + 1; i++)
                temp = readl(nvidia_private.aperture+(i * PAGE_SIZE / sizeof(u32)));
-       for(i = 0; i < 32 + 1; i++)
+       for (i = 0; i < 32 + 1; i++)
                temp = readl(nvidia_private.aperture+(i * PAGE_SIZE / sizeof(u32)));
 }
 
@@ -309,6 +310,7 @@ static struct agp_bridge_driver nvidia_driver = {
        .free_by_type           = agp_generic_free_by_type,
        .agp_alloc_page         = agp_generic_alloc_page,
        .agp_destroy_page       = agp_generic_destroy_page,
+       .agp_type_to_mask_type  = agp_generic_type_to_mask_type,
 };
 
 static int __devinit agp_nvidia_probe(struct pci_dev *pdev,
@@ -323,7 +325,7 @@ static int __devinit agp_nvidia_probe(struct pci_dev *pdev,
                pci_find_slot((unsigned int)pdev->bus->number, PCI_DEVFN(0, 2));
        nvidia_private.dev_3 =
                pci_find_slot((unsigned int)pdev->bus->number, PCI_DEVFN(30, 0));
-       
+
        if (!nvidia_private.dev_1 || !nvidia_private.dev_2 || !nvidia_private.dev_3) {
                printk(KERN_INFO PFX "Detected an NVIDIA nForce/nForce2 "
                        "chipset, but could not find the secondary devices.\n");
@@ -375,6 +377,29 @@ static void __devexit agp_nvidia_remove(struct pci_dev *pdev)
        agp_put_bridge(bridge);
 }
 
+#ifdef CONFIG_PM
+static int agp_nvidia_suspend(struct pci_dev *pdev, pm_message_t state)
+{
+       pci_save_state (pdev);
+       pci_set_power_state (pdev, 3);
+
+       return 0;
+}
+
+static int agp_nvidia_resume(struct pci_dev *pdev)
+{
+       /* set power state 0 and restore PCI space */
+       pci_set_power_state (pdev, 0);
+       pci_restore_state(pdev);
+
+       /* reconfigure AGP hardware again */
+       nvidia_configure();
+
+       return 0;
+}
+#endif
+
+
 static struct pci_device_id agp_nvidia_pci_table[] = {
        {
        .class          = (PCI_CLASS_BRIDGE_HOST << 8),
@@ -402,6 +427,10 @@ static struct pci_driver agp_nvidia_pci_driver = {
        .id_table       = agp_nvidia_pci_table,
        .probe          = agp_nvidia_probe,
        .remove         = agp_nvidia_remove,
+#ifdef CONFIG_PM
+       .suspend        = agp_nvidia_suspend,
+       .resume         = agp_nvidia_resume,
+#endif
 };
 
 static int __init agp_nvidia_init(void)