agp/uninorth: Unify U3 and pre-U3 insert_memory and remove_memory hooks.
authorMichel Dänzer <daenzer@vmware.com>
Sun, 6 Dec 2009 02:15:56 +0000 (02:15 +0000)
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>
Wed, 9 Dec 2009 06:09:30 +0000 (17:09 +1100)
Signed-off-by: Michel Dänzer <daenzer@vmware.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
drivers/char/agp/uninorth-agp.c

index 4e05021f3f18b04d1096e8babce9e7438ef82ba1..d89da4ac061f2d0c3aea71b51666039b203537ec 100644 (file)
@@ -144,53 +144,7 @@ static int uninorth_configure(void)
        return 0;
 }
 
-static int uninorth_insert_memory(struct agp_memory *mem, off_t pg_start,
-                               int type)
-{
-       int i, j, num_entries;
-       void *temp;
-       int mask_type;
-
-       if (type != mem->type)
-               return -EINVAL;
-
-       mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
-       if (mask_type != 0) {
-               /* We know nothing of memory types */
-               return -EINVAL;
-       }
-
-       if (mem->page_count == 0)
-               return 0;
-
-       temp = agp_bridge->current_size;
-       num_entries = A_SIZE_32(temp)->num_entries;
-
-       if ((pg_start + mem->page_count) > num_entries)
-               return -EINVAL;
-
-       j = pg_start;
-
-       while (j < (pg_start + mem->page_count)) {
-               if (agp_bridge->gatt_table[j])
-                       return -EBUSY;
-               j++;
-       }
-
-       for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
-               agp_bridge->gatt_table[j] =
-                       cpu_to_le32((page_to_phys(mem->pages[i]) & 0xFFFFF000UL) | 0x1UL);
-               flush_dcache_range((unsigned long)__va(page_to_phys(mem->pages[i])),
-                                  (unsigned long)__va(page_to_phys(mem->pages[i]))+0x1000);
-       }
-       (void)in_le32((volatile u32*)&agp_bridge->gatt_table[pg_start]);
-       mb();
-
-       uninorth_tlbflush(mem);
-       return 0;
-}
-
-static int u3_insert_memory(struct agp_memory *mem, off_t pg_start, int type)
+static int uninorth_insert_memory(struct agp_memory *mem, off_t pg_start, int type)
 {
        int i, num_entries;
        void *temp;
@@ -219,14 +173,18 @@ static int u3_insert_memory(struct agp_memory *mem, off_t pg_start, int type)
        for (i = 0; i < mem->page_count; ++i) {
                if (gp[i]) {
                        dev_info(&agp_bridge->dev->dev,
-                                "u3_insert_memory: entry 0x%x occupied (%x)\n",
+                                "uninorth_insert_memory: entry 0x%x occupied (%x)\n",
                                 i, gp[i]);
                        return -EBUSY;
                }
        }
 
        for (i = 0; i < mem->page_count; i++) {
-               gp[i] = (page_to_phys(mem->pages[i]) >> PAGE_SHIFT) | 0x80000000UL;
+               if (is_u3)
+                       gp[i] = (page_to_phys(mem->pages[i]) >> PAGE_SHIFT) | 0x80000000UL;
+               else
+                       gp[i] = cpu_to_le32((page_to_phys(mem->pages[i]) & 0xFFFFF000UL) |
+                                           0x1UL);
                flush_dcache_range((unsigned long)__va(page_to_phys(mem->pages[i])),
                                   (unsigned long)__va(page_to_phys(mem->pages[i]))+0x1000);
        }
@@ -236,7 +194,7 @@ static int u3_insert_memory(struct agp_memory *mem, off_t pg_start, int type)
        return 0;
 }
 
-int u3_remove_memory(struct agp_memory *mem, off_t pg_start, int type)
+int uninorth_remove_memory(struct agp_memory *mem, off_t pg_start, int type)
 {
        size_t i;
        u32 *gp;
@@ -551,7 +509,7 @@ const struct agp_bridge_driver uninorth_agp_driver = {
        .create_gatt_table      = uninorth_create_gatt_table,
        .free_gatt_table        = uninorth_free_gatt_table,
        .insert_memory          = uninorth_insert_memory,
-       .remove_memory          = agp_generic_remove_memory,
+       .remove_memory          = uninorth_remove_memory,
        .alloc_by_type          = agp_generic_alloc_by_type,
        .free_by_type           = agp_generic_free_by_type,
        .agp_alloc_page         = agp_generic_alloc_page,
@@ -577,8 +535,8 @@ const struct agp_bridge_driver u3_agp_driver = {
        .agp_enable             = uninorth_agp_enable,
        .create_gatt_table      = uninorth_create_gatt_table,
        .free_gatt_table        = uninorth_free_gatt_table,
-       .insert_memory          = u3_insert_memory,
-       .remove_memory          = u3_remove_memory,
+       .insert_memory          = uninorth_insert_memory,
+       .remove_memory          = uninorth_remove_memory,
        .alloc_by_type          = agp_generic_alloc_by_type,
        .free_by_type           = agp_generic_free_by_type,
        .agp_alloc_page         = agp_generic_alloc_page,