aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/ttm/ttm_page_alloc.c
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2011-02-22 21:06:39 -0500
committerDave Airlie <airlied@redhat.com>2011-02-22 21:06:39 -0500
commitde1e7cd63a8ec26a3bd3740708cfd72dd76509e2 (patch)
tree52bc82a71f34e92895d22821543a2be011834505 /drivers/gpu/drm/ttm/ttm_page_alloc.c
parent7811bddb6654337fd85837ef14c1a96a0c264745 (diff)
parent5a893fc28f0393adb7c885a871b8c59e623fd528 (diff)
Merge branch 'stable/ttm.pci-api.v5' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen into drm-next
* 'stable/ttm.pci-api.v5' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen: ttm: Include the 'struct dev' when using the DMA API. nouveau/ttm/PCIe: Use dma_addr if TTM has set it. radeon/ttm/PCIe: Use dma_addr if TTM has set it. ttm: Expand (*populate) to support an array of DMA addresses. ttm: Utilize the DMA API for pages that have TTM_PAGE_FLAG_DMA32 set. ttm: Introduce a placeholder for DMA (bus) addresses.
Diffstat (limited to 'drivers/gpu/drm/ttm/ttm_page_alloc.c')
-rw-r--r--drivers/gpu/drm/ttm/ttm_page_alloc.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
index b1e02fffd3cc..35849dbf3ab5 100644
--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
@@ -38,6 +38,7 @@
38#include <linux/mm.h> 38#include <linux/mm.h>
39#include <linux/seq_file.h> /* for seq_printf */ 39#include <linux/seq_file.h> /* for seq_printf */
40#include <linux/slab.h> 40#include <linux/slab.h>
41#include <linux/dma-mapping.h>
41 42
42#include <asm/atomic.h> 43#include <asm/atomic.h>
43 44
@@ -662,7 +663,8 @@ out:
662 * cached pages. 663 * cached pages.
663 */ 664 */
664int ttm_get_pages(struct list_head *pages, int flags, 665int ttm_get_pages(struct list_head *pages, int flags,
665 enum ttm_caching_state cstate, unsigned count) 666 enum ttm_caching_state cstate, unsigned count,
667 dma_addr_t *dma_address, struct device *dev)
666{ 668{
667 struct ttm_page_pool *pool = ttm_get_pool(flags, cstate); 669 struct ttm_page_pool *pool = ttm_get_pool(flags, cstate);
668 struct page *p = NULL; 670 struct page *p = NULL;
@@ -681,14 +683,22 @@ int ttm_get_pages(struct list_head *pages, int flags,
681 gfp_flags |= GFP_HIGHUSER; 683 gfp_flags |= GFP_HIGHUSER;
682 684
683 for (r = 0; r < count; ++r) { 685 for (r = 0; r < count; ++r) {
684 p = alloc_page(gfp_flags); 686 if ((flags & TTM_PAGE_FLAG_DMA32) && dma_address) {
687 void *addr;
688 addr = dma_alloc_coherent(dev, PAGE_SIZE,
689 &dma_address[r],
690 gfp_flags);
691 if (addr == NULL)
692 return -ENOMEM;
693 p = virt_to_page(addr);
694 } else
695 p = alloc_page(gfp_flags);
685 if (!p) { 696 if (!p) {
686 697
687 printk(KERN_ERR TTM_PFX 698 printk(KERN_ERR TTM_PFX
688 "Unable to allocate page."); 699 "Unable to allocate page.");
689 return -ENOMEM; 700 return -ENOMEM;
690 } 701 }
691
692 list_add(&p->lru, pages); 702 list_add(&p->lru, pages);
693 } 703 }
694 return 0; 704 return 0;
@@ -720,7 +730,7 @@ int ttm_get_pages(struct list_head *pages, int flags,
720 printk(KERN_ERR TTM_PFX 730 printk(KERN_ERR TTM_PFX
721 "Failed to allocate extra pages " 731 "Failed to allocate extra pages "
722 "for large request."); 732 "for large request.");
723 ttm_put_pages(pages, 0, flags, cstate); 733 ttm_put_pages(pages, 0, flags, cstate, NULL, NULL);
724 return r; 734 return r;
725 } 735 }
726 } 736 }
@@ -731,17 +741,30 @@ int ttm_get_pages(struct list_head *pages, int flags,
731 741
732/* Put all pages in pages list to correct pool to wait for reuse */ 742/* Put all pages in pages list to correct pool to wait for reuse */
733void ttm_put_pages(struct list_head *pages, unsigned page_count, int flags, 743void ttm_put_pages(struct list_head *pages, unsigned page_count, int flags,
734 enum ttm_caching_state cstate) 744 enum ttm_caching_state cstate, dma_addr_t *dma_address,
745 struct device *dev)
735{ 746{
736 unsigned long irq_flags; 747 unsigned long irq_flags;
737 struct ttm_page_pool *pool = ttm_get_pool(flags, cstate); 748 struct ttm_page_pool *pool = ttm_get_pool(flags, cstate);
738 struct page *p, *tmp; 749 struct page *p, *tmp;
750 unsigned r;
739 751
740 if (pool == NULL) { 752 if (pool == NULL) {
741 /* No pool for this memory type so free the pages */ 753 /* No pool for this memory type so free the pages */
742 754
755 r = page_count-1;
743 list_for_each_entry_safe(p, tmp, pages, lru) { 756 list_for_each_entry_safe(p, tmp, pages, lru) {
744 __free_page(p); 757 if ((flags & TTM_PAGE_FLAG_DMA32) && dma_address) {
758 void *addr = page_address(p);
759 WARN_ON(!addr || !dma_address[r]);
760 if (addr)
761 dma_free_coherent(dev, PAGE_SIZE,
762 addr,
763 dma_address[r]);
764 dma_address[r] = 0;
765 } else
766 __free_page(p);
767 r--;
745 } 768 }
746 /* Make the pages list empty */ 769 /* Make the pages list empty */
747 INIT_LIST_HEAD(pages); 770 INIT_LIST_HEAD(pages);