summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJérôme Glisse <jglisse@redhat.com>2017-08-11 12:57:27 -0400
committerJérôme Glisse <jglisse@redhat.com>2017-09-05 14:52:37 -0400
commit115d9394d40fdbae29f28e35cd964ccc52a5616d (patch)
treeef8a729e8c360bca012e0b7b4542f9ee8a598460
parentf1fcc4ed7b234391e1aec6b7f3e1001e9729bdfe (diff)
drm/nouveau/compote: add helper to map nvkm_vma
Signed-off-by: Jérôme Glisse <jglisse@redhat.com>
-rw-r--r--drivers/gpu/drm/nouveau/compote/compote-hmm.c29
-rw-r--r--drivers/gpu/drm/nouveau/compote/compote.h5
2 files changed, 34 insertions, 0 deletions
diff --git a/drivers/gpu/drm/nouveau/compote/compote-hmm.c b/drivers/gpu/drm/nouveau/compote/compote-hmm.c
index 0879fead00e1..eb1b0f9c336e 100644
--- a/drivers/gpu/drm/nouveau/compote/compote-hmm.c
+++ b/drivers/gpu/drm/nouveau/compote/compote-hmm.c
@@ -19,6 +19,35 @@
#include <linux/hmm.h>
#include "compote.h"
+int compote_nvkm_vma_map(struct compote_file *cfile,
+ struct nvkm_vma *nvvma,
+ unsigned long addr,
+ unsigned long nbytes)
+{
+ struct nvkm_mem mem = {0};
+ unsigned long skip, i;
+ struct device *pdev;
+
+ pdev = nvxx_device(&cfile->cdevice->nvdrm->client.device)->dev;
+ skip = addr - nvvma->offset;
+ for (i = skip >> 12; i < ((skip + nbytes) >> 12); ++i) {
+ struct page *page = hmm_pfn_t_to_page(nvvma->pfns[i]);
+ if (!page)
+ continue;
+ nvvma->dmas[i] = dma_map_page(pdev, page, 0, PAGE_SIZE,
+ DMA_BIDIRECTIONAL);
+ if (dma_mapping_error(pdev, nvvma->dmas[i])) {
+ return -EFAULT;
+ }
+ }
+
+ mem.pages = nvvma->dmas;
+ mem.memtype = 0;
+ nvkm_vm_map(nvvma, &mem);
+
+ return 0;
+}
+
static void compote_nvkm_vma_unmap(struct compote_file *cfile,
struct nvkm_vma *nvvma,
unsigned long addr,
diff --git a/drivers/gpu/drm/nouveau/compote/compote.h b/drivers/gpu/drm/nouveau/compote/compote.h
index b0fff7fa7cb9..ef8ea114db42 100644
--- a/drivers/gpu/drm/nouveau/compote/compote.h
+++ b/drivers/gpu/drm/nouveau/compote/compote.h
@@ -89,4 +89,9 @@ void compote_file_hmm_fini(struct compote_file *cfile);
int compote_file_pfault_init(struct compote_file *cfile);
void compote_file_pfault_fini(struct compote_file *cfile);
+int compote_nvkm_vma_map(struct compote_file *cfile,
+ struct nvkm_vma *nvvma,
+ unsigned long addr,
+ unsigned long nbytes);
+
#endif /* COMPOTE_H */