Commit 931d87d2 authored by Hans de Goede's avatar Hans de Goede Committed by Mauro Carvalho Chehab

media: atomisp: Add hmm_create_from_vmalloc_buf() function

Add a new hmm creating function to create a vmm object from a vmalloc-ed
kernel buffer. This is a preparation patch for adding videobuf2 (and
working MMAP mode) support.
Reviewed-by: default avatarAndy Shevchenko <andy@kernel.org>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
parent 813ceef0
...@@ -38,6 +38,8 @@ void hmm_cleanup(void); ...@@ -38,6 +38,8 @@ void hmm_cleanup(void);
ia_css_ptr hmm_alloc(size_t bytes); ia_css_ptr hmm_alloc(size_t bytes);
ia_css_ptr hmm_create_from_userdata(size_t bytes, const void __user *userptr); ia_css_ptr hmm_create_from_userdata(size_t bytes, const void __user *userptr);
ia_css_ptr hmm_create_from_vmalloc_buf(size_t bytes, void *vmalloc_addr);
void hmm_free(ia_css_ptr ptr); void hmm_free(ia_css_ptr ptr);
int hmm_load(ia_css_ptr virt, void *data, unsigned int bytes); int hmm_load(ia_css_ptr virt, void *data, unsigned int bytes);
int hmm_store(ia_css_ptr virt, const void *data, unsigned int bytes); int hmm_store(ia_css_ptr virt, const void *data, unsigned int bytes);
......
...@@ -73,6 +73,7 @@ ...@@ -73,6 +73,7 @@
enum hmm_bo_type { enum hmm_bo_type {
HMM_BO_PRIVATE, HMM_BO_PRIVATE,
HMM_BO_VMALLOC,
HMM_BO_USER, HMM_BO_USER,
HMM_BO_LAST, HMM_BO_LAST,
}; };
...@@ -207,7 +208,8 @@ int hmm_bo_allocated(struct hmm_buffer_object *bo); ...@@ -207,7 +208,8 @@ int hmm_bo_allocated(struct hmm_buffer_object *bo);
*/ */
int hmm_bo_alloc_pages(struct hmm_buffer_object *bo, int hmm_bo_alloc_pages(struct hmm_buffer_object *bo,
enum hmm_bo_type type, enum hmm_bo_type type,
const void __user *userptr); const void __user *userptr,
void *vmalloc_addr);
void hmm_bo_free_pages(struct hmm_buffer_object *bo); void hmm_bo_free_pages(struct hmm_buffer_object *bo);
int hmm_bo_page_allocated(struct hmm_buffer_object *bo); int hmm_bo_page_allocated(struct hmm_buffer_object *bo);
......
...@@ -41,11 +41,10 @@ static bool hmm_initialized; ...@@ -41,11 +41,10 @@ static bool hmm_initialized;
/* /*
* p: private * p: private
* s: shared * v: vmalloc
* u: user * u: user
* i: ion
*/ */
static const char hmm_bo_type_string[] = "psui"; static const char hmm_bo_type_string[] = "pvu";
static ssize_t bo_show(struct device *dev, struct device_attribute *attr, static ssize_t bo_show(struct device *dev, struct device_attribute *attr,
char *buf, struct list_head *bo_list, bool active) char *buf, struct list_head *bo_list, bool active)
...@@ -168,7 +167,9 @@ void hmm_cleanup(void) ...@@ -168,7 +167,9 @@ void hmm_cleanup(void)
hmm_initialized = false; hmm_initialized = false;
} }
static ia_css_ptr __hmm_alloc(size_t bytes, enum hmm_bo_type type, const void __user *userptr) static ia_css_ptr __hmm_alloc(size_t bytes, enum hmm_bo_type type,
const void __user *userptr,
void *vmalloc_addr)
{ {
unsigned int pgnr; unsigned int pgnr;
struct hmm_buffer_object *bo; struct hmm_buffer_object *bo;
...@@ -192,7 +193,7 @@ static ia_css_ptr __hmm_alloc(size_t bytes, enum hmm_bo_type type, const void __ ...@@ -192,7 +193,7 @@ static ia_css_ptr __hmm_alloc(size_t bytes, enum hmm_bo_type type, const void __
} }
/* Allocate pages for memory */ /* Allocate pages for memory */
ret = hmm_bo_alloc_pages(bo, type, userptr); ret = hmm_bo_alloc_pages(bo, type, userptr, vmalloc_addr);
if (ret) { if (ret) {
dev_err(atomisp_dev, "hmm_bo_alloc_pages failed.\n"); dev_err(atomisp_dev, "hmm_bo_alloc_pages failed.\n");
goto alloc_page_err; goto alloc_page_err;
...@@ -221,12 +222,17 @@ static ia_css_ptr __hmm_alloc(size_t bytes, enum hmm_bo_type type, const void __ ...@@ -221,12 +222,17 @@ static ia_css_ptr __hmm_alloc(size_t bytes, enum hmm_bo_type type, const void __
ia_css_ptr hmm_alloc(size_t bytes) ia_css_ptr hmm_alloc(size_t bytes)
{ {
return __hmm_alloc(bytes, HMM_BO_PRIVATE, NULL); return __hmm_alloc(bytes, HMM_BO_PRIVATE, NULL, NULL);
}
ia_css_ptr hmm_create_from_vmalloc_buf(size_t bytes, void *vmalloc_addr)
{
return __hmm_alloc(bytes, HMM_BO_VMALLOC, NULL, vmalloc_addr);
} }
ia_css_ptr hmm_create_from_userdata(size_t bytes, const void __user *userptr) ia_css_ptr hmm_create_from_userdata(size_t bytes, const void __user *userptr)
{ {
return __hmm_alloc(bytes, HMM_BO_USER, userptr); return __hmm_alloc(bytes, HMM_BO_USER, userptr, NULL);
} }
void hmm_free(ia_css_ptr virt) void hmm_free(ia_css_ptr virt)
......
...@@ -694,18 +694,38 @@ static int alloc_user_pages(struct hmm_buffer_object *bo, ...@@ -694,18 +694,38 @@ static int alloc_user_pages(struct hmm_buffer_object *bo,
return -ENOMEM; return -ENOMEM;
} }
static int alloc_vmalloc_pages(struct hmm_buffer_object *bo, void *vmalloc_addr)
{
void *vaddr = vmalloc_addr;
int i;
for (i = 0; i < bo->pgnr; i++) {
bo->pages[i] = vmalloc_to_page(vaddr);
if (!bo->pages[i]) {
dev_err(atomisp_dev, "Error could not get page %d of vmalloc buf\n", i);
return -ENOMEM;
}
vaddr += PAGE_SIZE;
}
return 0;
}
/* /*
* allocate/free physical pages for the bo. * allocate/free physical pages for the bo.
* *
* type indicate where are the pages from. currently we have 3 types * type indicate where are the pages from. currently we have 3 types
* of memory: HMM_BO_PRIVATE, HMM_BO_USER. * of memory: HMM_BO_PRIVATE, HMM_BO_VMALLOC, HMM_BO_USER.
*
* vmalloc_addr is only valid when type is HMM_BO_VMALLOC.
* *
* userptr is only valid when type is HMM_BO_USER, it indicates * userptr is only valid when type is HMM_BO_USER, it indicates
* the start address from user space task. * the start address from user space task.
*/ */
int hmm_bo_alloc_pages(struct hmm_buffer_object *bo, int hmm_bo_alloc_pages(struct hmm_buffer_object *bo,
enum hmm_bo_type type, enum hmm_bo_type type,
const void __user *userptr) const void __user *userptr,
void *vmalloc_addr)
{ {
int ret = -EINVAL; int ret = -EINVAL;
...@@ -720,12 +740,10 @@ int hmm_bo_alloc_pages(struct hmm_buffer_object *bo, ...@@ -720,12 +740,10 @@ int hmm_bo_alloc_pages(struct hmm_buffer_object *bo,
goto alloc_err; goto alloc_err;
} }
/*
* TO DO:
* add HMM_BO_USER type
*/
if (type == HMM_BO_PRIVATE) { if (type == HMM_BO_PRIVATE) {
ret = alloc_private_pages(bo); ret = alloc_private_pages(bo);
} else if (type == HMM_BO_VMALLOC) {
ret = alloc_vmalloc_pages(bo, vmalloc_addr);
} else if (type == HMM_BO_USER) { } else if (type == HMM_BO_USER) {
ret = alloc_user_pages(bo, userptr); ret = alloc_user_pages(bo, userptr);
} else { } else {
...@@ -771,6 +789,8 @@ void hmm_bo_free_pages(struct hmm_buffer_object *bo) ...@@ -771,6 +789,8 @@ void hmm_bo_free_pages(struct hmm_buffer_object *bo)
if (bo->type == HMM_BO_PRIVATE) if (bo->type == HMM_BO_PRIVATE)
free_private_bo_pages(bo); free_private_bo_pages(bo);
else if (bo->type == HMM_BO_VMALLOC)
; /* No-op, nothing to do */
else if (bo->type == HMM_BO_USER) else if (bo->type == HMM_BO_USER)
free_user_pages(bo, bo->pgnr); free_user_pages(bo, bo->pgnr);
else else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment