aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/char/agp/intel-agp.c29
-rw-r--r--include/linux/agp_backend.h1
2 files changed, 10 insertions, 20 deletions
diff --git a/drivers/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c
index b9d9886ff3c3..d8c80d8be5e2 100644
--- a/drivers/char/agp/intel-agp.c
+++ b/drivers/char/agp/intel-agp.c
@@ -198,39 +198,30 @@ static void intel_agp_unmap_page(struct page *page, dma_addr_t dma)
198 198
199static void intel_agp_free_sglist(struct agp_memory *mem) 199static void intel_agp_free_sglist(struct agp_memory *mem)
200{ 200{
201 struct sg_table st;
202
203 st.sgl = mem->sg_list;
204 st.orig_nents = st.nents = mem->page_count;
205
206 sg_free_table(&st);
201 207
202 if (mem->sg_vmalloc_flag)
203 vfree(mem->sg_list);
204 else
205 kfree(mem->sg_list);
206 mem->sg_vmalloc_flag = 0;
207 mem->sg_list = NULL; 208 mem->sg_list = NULL;
208 mem->num_sg = 0; 209 mem->num_sg = 0;
209} 210}
210 211
211static int intel_agp_map_memory(struct agp_memory *mem) 212static int intel_agp_map_memory(struct agp_memory *mem)
212{ 213{
214 struct sg_table st;
213 struct scatterlist *sg; 215 struct scatterlist *sg;
214 int i; 216 int i;
215 217
216 DBG("try mapping %lu pages\n", (unsigned long)mem->page_count); 218 DBG("try mapping %lu pages\n", (unsigned long)mem->page_count);
217 219
218 if ((mem->page_count * sizeof(*mem->sg_list)) < 2*PAGE_SIZE) 220 if (sg_alloc_table(&st, mem->page_count, GFP_KERNEL))
219 mem->sg_list = kcalloc(mem->page_count, sizeof(*mem->sg_list),
220 GFP_KERNEL);
221
222 if (mem->sg_list == NULL) {
223 mem->sg_list = vmalloc(mem->page_count * sizeof(*mem->sg_list));
224 mem->sg_vmalloc_flag = 1;
225 }
226
227 if (!mem->sg_list) {
228 mem->sg_vmalloc_flag = 0;
229 return -ENOMEM; 221 return -ENOMEM;
230 }
231 sg_init_table(mem->sg_list, mem->page_count);
232 222
233 sg = mem->sg_list; 223 mem->sg_list = sg = st.sgl;
224
234 for (i = 0 ; i < mem->page_count; i++, sg = sg_next(sg)) 225 for (i = 0 ; i < mem->page_count; i++, sg = sg_next(sg))
235 sg_set_page(sg, mem->pages[i], PAGE_SIZE, 0); 226 sg_set_page(sg, mem->pages[i], PAGE_SIZE, 0);
236 227
diff --git a/include/linux/agp_backend.h b/include/linux/agp_backend.h
index 8a294d65b9b1..880130f7311f 100644
--- a/include/linux/agp_backend.h
+++ b/include/linux/agp_backend.h
@@ -80,7 +80,6 @@ struct agp_memory {
80 bool is_bound; 80 bool is_bound;
81 bool is_flushed; 81 bool is_flushed;
82 bool vmalloc_flag; 82 bool vmalloc_flag;
83 bool sg_vmalloc_flag;
84 /* list of agp_memory mapped to the aperture */ 83 /* list of agp_memory mapped to the aperture */
85 struct list_head mapped_list; 84 struct list_head mapped_list;
86 /* DMA-mapped addresses */ 85 /* DMA-mapped addresses */