From: Jeremy Fitzhardinge <jeremy@goop.org>
To: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: dri-devel@lists.sourceforge.net, xen-devel@lists.xensource.com,
JBeulich@novell.com
Subject: Re: ATI radeon fails with "iommu=soft swiotlb=force" (seen on RV730/RV740 and RS780/RS800)
Date: Thu, 01 Oct 2009 12:37:32 -0700 [thread overview]
Message-ID: <4AC504FC.5010902@goop.org> (raw)
In-Reply-To: <4AC4FDEA.3070909@goop.org>
On 10/01/09 12:07, Jeremy Fitzhardinge wrote:
> Could modify drm_vmalloc_dma to do the vmalloc "manually":
>
> 1. call __get_vm_area to reserve a chunk of vmalloc address space
> 2. allocate a bunch of individual pages with dma_alloc_coherent
> 3. insert them into the vmalloc mapping with map_vm_area
>
> That will guarantee a normal-looking vmalloc area with device-friendly
> pages that subsequent pci_map_page operations will use as-is.
>
Like this (untested):
diff --git a/drivers/gpu/drm/drm_scatter.c b/drivers/gpu/drm/drm_scatter.c
index c7823c8..73bfa63 100644
--- a/drivers/gpu/drm/drm_scatter.c
+++ b/drivers/gpu/drm/drm_scatter.c
@@ -32,16 +32,60 @@
*/
#include <linux/vmalloc.h>
+#include <linux/mm.h>
#include "drmP.h"
#define DEBUG_SCATTER 0
-static inline void *drm_vmalloc_dma(unsigned long size)
+static inline void *drm_vmalloc_dma(struct drm_device *drmdev, unsigned long size)
{
#if defined(__powerpc__) && defined(CONFIG_NOT_COHERENT_CACHE)
return __vmalloc(size, GFP_KERNEL, PAGE_KERNEL | _PAGE_NO_CACHE);
#else
- return vmalloc_32(size);
+ struct device *dev = &drmdev->pdev->dev;
+ struct vm_struct *vma;
+ struct page **pages;
+ const int npages = PFN_UP(size);
+ int i;
+
+ pages = kmalloc(npages * sizeof(*pages), GFP_KERNEL);
+ if (!pages)
+ goto out_free_pagearr;
+
+ vma = __get_vm_area(size, VM_ALLOC, VMALLOC_START, VMALLOC_END);
+ if (!vma)
+ goto out_release_vma;
+
+ for (i = 0; i < npages; i++) {
+ dma_addr_t phys;
+ void *addr;
+ addr = dma_alloc_coherent(dev, PAGE_SIZE, &phys, GFP_KERNEL);
+ if (addr == NULL)
+ goto out_free_pages;
+
+ pages[i] = virt_to_page(addr);
+ }
+
+ if (map_vm_area(vma, PAGE_KERNEL, &pages))
+ goto out_free_pages;
+
+ kfree(pages);
+
+ return vma->addr;
+
+out_free_pages:
+ while(i > 0) {
+ void *addr = page_address(pages[--i]);
+ dma_free_coherent(dev, PAGE_SIZE, addr, virt_to_bus(addr));
+ }
+
+out_release_vma:
+ vunmap(vma->addr);
+
+out_free_pagearr:
+ kfree(pages);
+
+ return NULL;
#endif
}
@@ -107,7 +151,7 @@ int drm_sg_alloc(struct drm_device *dev, struct drm_scatter_gather * request)
}
memset((void *)entry->busaddr, 0, pages * sizeof(*entry->busaddr));
- entry->virtual = drm_vmalloc_dma(pages << PAGE_SHIFT);
+ entry->virtual = drm_vmalloc_dma(dev, pages << PAGE_SHIFT);
if (!entry->virtual) {
kfree(entry->busaddr);
kfree(entry->pagelist);
prev parent reply other threads:[~2009-10-01 19:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20090930152149.GA29603@phenom.dumpdata.com>
2009-10-01 17:35 ` ATI radeon fails with "iommu=soft swiotlb=force" (seen on RV730/RV740 and RS780/RS800) Konrad Rzeszutek Wilk
2009-10-01 19:07 ` Jeremy Fitzhardinge
2009-10-01 19:21 ` Konrad Rzeszutek Wilk
2009-10-01 20:03 ` Jeremy Fitzhardinge
2009-10-02 12:52 ` Jan Beulich
2009-10-02 14:44 ` Konrad Rzeszutek Wilk
2009-10-01 19:37 ` Jeremy Fitzhardinge [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4AC504FC.5010902@goop.org \
--to=jeremy@goop.org \
--cc=JBeulich@novell.com \
--cc=dri-devel@lists.sourceforge.net \
--cc=konrad.wilk@oracle.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.