agp/intel: Use the correct mask to detect i830 aperture size.
[linux-2.6.git] / drivers / char / agp / intel-gtt.c
index 131c5d5..a754715 100644 (file)
@@ -203,13 +203,11 @@ static int intel_i810_fetch_size(void)
                return 0;
        }
        if ((smram_miscc & I810_GFX_MEM_WIN_SIZE) == I810_GFX_MEM_WIN_32M) {
-               agp_bridge->previous_size =
-                       agp_bridge->current_size = (void *) (values + 1);
+               agp_bridge->current_size = (void *) (values + 1);
                agp_bridge->aperture_size_idx = 1;
                return values[1].size;
        } else {
-               agp_bridge->previous_size =
-                       agp_bridge->current_size = (void *) (values);
+               agp_bridge->current_size = (void *) (values);
                agp_bridge->aperture_size_idx = 0;
                return values[0].size;
        }
@@ -266,11 +264,6 @@ static void intel_i810_cleanup(void)
        iounmap(intel_private.registers);
 }
 
-static void intel_i810_tlbflush(struct agp_memory *mem)
-{
-       return;
-}
-
 static void intel_i810_agp_enable(struct agp_bridge_data *bridge, u32 mode)
 {
        return;
@@ -372,7 +365,6 @@ static int intel_i810_insert_entries(struct agp_memory *mem, off_t pg_start,
                goto out_err;
        }
 
-       agp_bridge->driver->tlb_flush(mem);
 out:
        ret = 0;
 out_err:
@@ -393,7 +385,6 @@ static int intel_i810_remove_entries(struct agp_memory *mem, off_t pg_start,
        }
        readl(intel_private.registers+I810_PTE_BASE+((i-1)*4));
 
-       agp_bridge->driver->tlb_flush(mem);
        return 0;
 }
 
@@ -832,7 +823,7 @@ static int intel_i830_fetch_size(void)
        if (agp_bridge->dev->device != PCI_DEVICE_ID_INTEL_82830_HB &&
            agp_bridge->dev->device != PCI_DEVICE_ID_INTEL_82845G_HB) {
                /* 855GM/852GM/865G has 128MB aperture size */
-               agp_bridge->previous_size = agp_bridge->current_size = (void *) values;
+               agp_bridge->current_size = (void *) values;
                agp_bridge->aperture_size_idx = 0;
                return values[0].size;
        }
@@ -840,11 +831,11 @@ static int intel_i830_fetch_size(void)
        pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
 
        if ((gmch_ctrl & I830_GMCH_MEM_MASK) == I830_GMCH_MEM_128M) {
-               agp_bridge->previous_size = agp_bridge->current_size = (void *) values;
+               agp_bridge->current_size = (void *) values;
                agp_bridge->aperture_size_idx = 0;
                return values[0].size;
        } else {
-               agp_bridge->previous_size = agp_bridge->current_size = (void *) (values + 1);
+               agp_bridge->current_size = (void *) (values + 1);
                agp_bridge->aperture_size_idx = 1;
                return values[1].size;
        }
@@ -938,7 +929,6 @@ static int intel_i830_insert_entries(struct agp_memory *mem, off_t pg_start,
                       intel_private.registers+I810_PTE_BASE+(j*4));
        }
        readl(intel_private.registers+I810_PTE_BASE+((j-1)*4));
-       agp_bridge->driver->tlb_flush(mem);
 
 out:
        ret = 0;
@@ -966,7 +956,6 @@ static int intel_i830_remove_entries(struct agp_memory *mem, off_t pg_start,
        }
        readl(intel_private.registers+I810_PTE_BASE+((i-1)*4));
 
-       agp_bridge->driver->tlb_flush(mem);
        return 0;
 }
 
@@ -1070,7 +1059,7 @@ static void intel_i9xx_setup_flush(void)
        }
 }
 
-static int intel_i915_configure(void)
+static int intel_i9xx_configure(void)
 {
        struct aper_size_info_fixed *current_size;
        u32 temp;
@@ -1166,7 +1155,6 @@ static int intel_i915_insert_entries(struct agp_memory *mem, off_t pg_start,
                global_cache_flush();
 
        intel_agp_insert_sg_entries(mem, pg_start, mask_type);
-       agp_bridge->driver->tlb_flush(mem);
 
  out:
        ret = 0;
@@ -1194,7 +1182,6 @@ static int intel_i915_remove_entries(struct agp_memory *mem, off_t pg_start,
 
        readl(intel_private.gtt+i-1);
 
-       agp_bridge->driver->tlb_flush(mem);
        return 0;
 }
 
@@ -1213,7 +1200,6 @@ static int intel_i9xx_fetch_size(void)
        for (i = 0; i < num_sizes; i++) {
                if (aper_size == intel_i830_sizes[i].size) {
                        agp_bridge->current_size = intel_i830_sizes + i;
-                       agp_bridge->previous_size = agp_bridge->current_size;
                        return aper_size;
                }
        }
@@ -1221,6 +1207,41 @@ static int intel_i9xx_fetch_size(void)
        return 0;
 }
 
+static int intel_i915_get_gtt_size(void)
+{
+       int size;
+
+       if (IS_G33) {
+               u16 gmch_ctrl;
+
+               /* G33's GTT size defined in gmch_ctrl */
+               pci_read_config_word(agp_bridge->dev, I830_GMCH_CTRL, &gmch_ctrl);
+               switch (gmch_ctrl & I830_GMCH_GMS_MASK) {
+               case I830_GMCH_GMS_STOLEN_512:
+                       size = 512;
+                       break;
+               case I830_GMCH_GMS_STOLEN_1024:
+                       size = 1024;
+                       break;
+               case I830_GMCH_GMS_STOLEN_8192:
+                       size = 8*1024;
+                       break;
+               default:
+                       dev_info(&agp_bridge->dev->dev,
+                                "unknown page table size 0x%x, assuming 512KB\n",
+                               (gmch_ctrl & I830_GMCH_GMS_MASK));
+                       size = 512;
+               }
+       } else {
+               /* On previous hardware, the GTT size was just what was
+                * required to map the aperture.
+                */
+               size = agp_bridge->driver->fetch_size();
+       }
+
+       return KB(size);
+}
+
 /* The intel i915 automatically initializes the agp aperture during POST.
  * Use the memory already set aside for in the GTT.
  */
@@ -1230,7 +1251,7 @@ static int intel_i915_create_gatt_table(struct agp_bridge_data *bridge)
        struct aper_size_info_fixed *size;
        int num_entries;
        u32 temp, temp2;
-       int gtt_map_size = 256 * 1024;
+       int gtt_map_size;
 
        size = agp_bridge->current_size;
        page_order = size->page_order;
@@ -1240,8 +1261,8 @@ static int intel_i915_create_gatt_table(struct agp_bridge_data *bridge)
        pci_read_config_dword(intel_private.pcidev, I915_MMADDR, &temp);
        pci_read_config_dword(intel_private.pcidev, I915_PTEADDR, &temp2);
 
-       if (IS_G33)
-           gtt_map_size = 1024 * 1024; /* 1M on G33 */
+       gtt_map_size = intel_i915_get_gtt_size();
+
        intel_private.gtt = ioremap(temp2, gtt_map_size);
        if (!intel_private.gtt)
                return -ENOMEM;
@@ -1386,7 +1407,6 @@ static const struct agp_bridge_driver intel_810_driver = {
        .configure              = intel_i810_configure,
        .fetch_size             = intel_i810_fetch_size,
        .cleanup                = intel_i810_cleanup,
-       .tlb_flush              = intel_i810_tlbflush,
        .mask_memory            = intel_i810_mask_memory,
        .masks                  = intel_i810_masks,
        .agp_enable             = intel_i810_agp_enable,
@@ -1413,7 +1433,6 @@ static const struct agp_bridge_driver intel_830_driver = {
        .configure              = intel_i830_configure,
        .fetch_size             = intel_i830_fetch_size,
        .cleanup                = intel_i830_cleanup,
-       .tlb_flush              = intel_i810_tlbflush,
        .mask_memory            = intel_i810_mask_memory,
        .masks                  = intel_i810_masks,
        .agp_enable             = intel_i810_agp_enable,
@@ -1438,10 +1457,9 @@ static const struct agp_bridge_driver intel_915_driver = {
        .size_type              = FIXED_APER_SIZE,
        .num_aperture_sizes     = 4,
        .needs_scratch_page     = true,
-       .configure              = intel_i915_configure,
+       .configure              = intel_i9xx_configure,
        .fetch_size             = intel_i9xx_fetch_size,
        .cleanup                = intel_i915_cleanup,
-       .tlb_flush              = intel_i810_tlbflush,
        .mask_memory            = intel_i810_mask_memory,
        .masks                  = intel_i810_masks,
        .agp_enable             = intel_i810_agp_enable,
@@ -1472,10 +1490,9 @@ static const struct agp_bridge_driver intel_i965_driver = {
        .size_type              = FIXED_APER_SIZE,
        .num_aperture_sizes     = 4,
        .needs_scratch_page     = true,
-       .configure              = intel_i915_configure,
+       .configure              = intel_i9xx_configure,
        .fetch_size             = intel_i9xx_fetch_size,
        .cleanup                = intel_i915_cleanup,
-       .tlb_flush              = intel_i810_tlbflush,
        .mask_memory            = intel_i965_mask_memory,
        .masks                  = intel_i810_masks,
        .agp_enable             = intel_i810_agp_enable,
@@ -1506,10 +1523,9 @@ static const struct agp_bridge_driver intel_g33_driver = {
        .size_type              = FIXED_APER_SIZE,
        .num_aperture_sizes     = 4,
        .needs_scratch_page     = true,
-       .configure              = intel_i915_configure,
+       .configure              = intel_i9xx_configure,
        .fetch_size             = intel_i9xx_fetch_size,
        .cleanup                = intel_i915_cleanup,
-       .tlb_flush              = intel_i810_tlbflush,
        .mask_memory            = intel_i965_mask_memory,
        .masks                  = intel_i810_masks,
        .agp_enable             = intel_i810_agp_enable,