media: atomisp_gmin_platform: Switch to use acpi_evaluate_dsm_typed()
Subsystems (4)
PATCH v2 1/13 media: atomisp_gmin_platform: Switch to use acpi_evaluate_dsm_typed()
From: Andy Shevchenko <[email protected]>
The acpi_evaluate_dsm_typed() provides a way to check the type of the object evaluated by _DSM call. Use it instead of open coded variant.
--- drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c +3 -5
@@ -1250,16 +1250,14 @@ static int gmin_get_config_dsm_var(struct device *dev,if (!strcmp (var,"CamClk" ))return -EINVAL ; - obj =acpi_evaluate_dsm (handle, &atomisp_dsm_guid,0 ,0 ,NULL ); +/* Return on unexpected object type */ + obj =acpi_evaluate_dsm_typed (handle, &atomisp_dsm_guid,0 ,0 ,NULL , +ACPI_TYPE_PACKAGE );if (!obj) {dev_info_once (dev,"Didn't find ACPI _DSM table.\n" );return -EINVAL ; } -/* Return on unexpected object type */ -if (obj->type !=ACPI_TYPE_PACKAGE ) -return -EINVAL ; -#if 0 /* Just for debugging purposes */ for (i =0 ; i < obj->package.count; i++) {union acpi_object *cur = &obj->package.elements[i];
Signature · 1 line
2.36.1
PATCH v2 2/13 media: atomisp-ov2680: Fix ov2680_set_fmt()
On sets actually store the set (closest) format inside ov2680_device.dev, so that it also properly gets returned by get_fmt.
This fixes the following problem:
1. App does an VIDIOC_SET_FMT 640x480, calling ov2680_set_fmt()
2. Internal buffers (atomisp_create_pipes_stream()) get allocated at 640x480 size by atomisp_set_fmt()
3. ov2680_get_fmt() gets called later on and returns 1600x1200 since ov2680_device.dev was not updated. So things get configured to stream at 1600x1200, but the internal buffers created during atomisp_create_pipes_stream() do not get updated in size
4. streaming starts, internal buffers overflow and the entire machine freezes eventually due to memory being corrupted
--- drivers/staging/media/atomisp/i2c/atomisp-ov2680.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +1 -5
@@ -894,11 +894,7 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd,if (v_flag)ov2680_v_flip (sd, v_flag); -/* -* ret = startup(sd); -* if (ret) -* dev_err(&client->dev, "ov2680 startup err\n"); -*/ + dev->res = res; err:mutex_unlock (&dev->input_lock);return ret;
Signature · 1 line
2.36.1
PATCH v2 3/13 media: atomisp-ov2680: Don't take the input_lock for try_fmt calls.
In reply to Hans de GoedeOn ov2680_set_fmt() calls with format->which == V4L2_SUBDEV_FORMAT_TRY, ov2680_set_fmt() does not talk to the sensor, so there is no need to lock the dev->input_lock mutex in this case.
--- drivers/staging/media/atomisp/i2c/atomisp-ov2680.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +2 -3
@@ -841,8 +841,6 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd,if (!ov2680_info)return -EINVAL ; -mutex_lock (&dev->input_lock); - res =v4l2_find_nearest_size (ov2680_res_preview,ARRAY_SIZE (ov2680_res_preview), width, height, fmt->width, fmt->height);
@@ -855,13 +853,14 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd, fmt->code =MEDIA_BUS_FMT_SBGGR10_1X10 ;if (format->which ==V4L2_SUBDEV_FORMAT_TRY ) { sd_state->pads->try_fmt = *fmt; -mutex_unlock (&dev->input_lock);return 0 ; }dev_dbg (&client->dev,"%s: %dx%d\n" , __func__, fmt->width, fmt->height); +mutex_lock (&dev->input_lock); +/* s_power has not been called yet for std v4l2 clients (camorama) */ power_up (sd); ret =ov2680_write_reg_array (client, dev->res->regs);
Signature · 1 line
2.36.1
PATCH v2 4/13 media: atomisp-ov2680: Improve ov2680_set_fmt() error handling
In reply to Hans de GoedeExit with an error on any i2c-write errors, rather then only exiting with an error when ov2680_get_intg_factor() fails.
--- drivers/staging/media/atomisp/i2c/atomisp-ov2680.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/staging/media/atomisp/i2c/atomisp-ov2680.c +6 -2
@@ -864,9 +864,11 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd,/* s_power has not been called yet for std v4l2 clients (camorama) */ power_up (sd); ret =ov2680_write_reg_array (client, dev->res->regs); -if (ret) +if (ret) {dev_err (&client->dev,"ov2680 write resolution register err: %d\n" , ret); + goto err; + } vts = dev->res->lines_per_frame;
@@ -875,8 +877,10 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd, vts = dev->exposure +OV2680_INTEGRATION_TIME_MARGIN ; ret =ov2680_write_reg (client,2 ,OV2680_TIMING_VTS_H , vts); -if (ret) +if (ret) {dev_err (&client->dev,"ov2680 write vts err: %d\n" , ret); + goto err; + } ret =ov2680_get_intg_factor (client, ov2680_info, res);if (ret) {
Signature · 1 line
2.36.1
PATCH v2 5/13 media: atomisp-notes: Add info about sensors v4l2_get_subdev_hostdata() use
In reply to Hans de GoedeAdd info about sensors v4l2_get_subdev_hostdata() use, to notes.txt.
--- drivers/staging/media/atomisp/notes.txt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/staging/media/atomisp/notes.txt +19 -0
@@ -28,3 +28,22 @@ Since getting a picture requires multiple processing steps, this means that unlike in fixed pipelines the soft pipelines on the ISP can do multiple processing steps in a single pipeline element (in a single binary). + +### + +The sensor drivers use of v4l2_get_subdev_hostdata(), which returns +a camera_mipi_info struct. This struct is allocated/managed by +the core atomisp code. The most important parts of the struct +are filled by the atomisp core itself, like e.g. the port number. + +The sensor drivers on a set_fmt call do fill in camera_mipi_info.data +which is a atomisp_sensor_mode_data struct. This gets filled from +a function called <sensor_name>_get_intg_factor(). This struct is not +used by the atomisp code at all. It is returned to userspace by +a ATOMISP_IOC_G_SENSOR_MODE_DATA and the Android userspace does use this. + +Other members of camera_mipi_info which are set by some drivers are: +-metadata_width, metadata_height, metadata_effective_width, set by + the ov5693 driver (and used by the atomisp core) +-raw_bayer_order, adjusted by the ov2680 driver when flipping since + flipping can change the bayer order
Signature · 1 line
2.36.1
PATCH v2 6/13 media: atomisp: Fix VIDIOC_TRY_FMT
In reply to Hans de Goedeatomisp_try_fmt() calls the sensor's try_fmt handler but it does not copy the result back to the passed in v4l2_pix_format under some circumstances.
Potentially returning an unsupported resolution to userspace, which VIDIOC_TRY_FMT is not supposed to do.
atomisp_set_fmt() also uses atomisp_try_fmt() and relies on this wrong behavior. The VIDIOC_TRY_FMT call passes NULL for the res_overflow argument where as the atomisp_set_fmt() call passes non NULL.
Use the res_overflow argument to differentiate between the 2 callers and always propagate the sensors result in the VIDIOC_TRY_FMT case.
This fixes the resolution list in camorama showing resolutions like e.g. 1584x1184 instead of 1600x1200.
--- drivers/staging/media/atomisp/pci/atomisp_cmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/media/atomisp/pci/atomisp_cmd.c +2 -2
@@ -4886,8 +4886,8 @@ int atomisp_try_fmt(struct video_device *vdev, struct v4l2_pix_format *f,return 0 ; } -if (snr_mbus_fmt->width < f->width - && snr_mbus_fmt->height < f->height) { +if (!res_overflow || (snr_mbus_fmt->width < f->width && + snr_mbus_fmt->height < f->height)) { f->width = snr_mbus_fmt->width; f->height = snr_mbus_fmt->height;/* Set the flag when resolution requested is
Signature · 1 line
2.36.1
PATCH v2 7/13 media: atomisp: Make atomisp_try_fmt_cap() take padding into account
In reply to Hans de Goedeatomisp_try_fmt() gives results with padding included. So when userspace asks for e.g. 1600x1200 then we should pass 1616x1216 to atomisp_try_fmt() this will then get adjusted back to 1600x1200 before returning it to userspace by the atomisp_adjust_fmt() call at the end of atomisp_try_fmt().
This fixes the resolution list in camorama showing resolutions like e.g. 1584x1184 instead of 1600x1200.
--- drivers/staging/media/atomisp/pci/atomisp_ioctl.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/staging/media/atomisp/pci/atomisp_ioctl.c +7 -0
@@ -960,6 +960,13 @@ static int atomisp_try_fmt_cap(struct file *file, void *fh,struct atomisp_device *isp =video_get_drvdata (vdev);int ret; +/* +* atomisp_try_fmt() gived results with padding included, note +* (this gets removed again by the atomisp_adjust_fmt() call below. +*/ + f->fmt.pix.width += pad_w; + f->fmt.pix.height += pad_h; +rt_mutex_lock (&isp->mutex); ret =atomisp_try_fmt (vdev, &f->fmt.pix,NULL );rt_mutex_unlock (&isp->mutex);
Signature · 1 line
2.36.1
PATCH v2 8/13 media: atomisp: hmm_bo: Simplify alloc_private_pages()
In reply to Hans de GoedeSince lack_mem starts initialized to true, alloc_private_pages() will always set order to HMM_MIN_ORDER aka 0 / will always alloc 1 page at a time.
So all the magic to decrease order if allocs fail is not necessary and can be removed.
--- .../media/atomisp/include/hmm/hmm_bo.h | 3 - .../staging/media/atomisp/pci/hmm/hmm_bo.c | 83 +++---------------- 2 files changed, 10 insertions(+), 76 deletions(-)
drivers/staging/media/atomisp/include/hmm/hmm_bo.h +0 -3
@@ -65,9 +65,6 @@#define check_bo_null_return_void (bo) \ check_null_return_void(bo, "NULL hmm buffer object.\n") -#define HMM_MAX_ORDER 3 -#define HMM_MIN_ORDER 0 -#define ISP_VM_START 0x0#define ISP_VM_SIZE (0x7FFFFFFF)/* 2G address space */ #define ISP_PTR_NULL NULL
drivers/staging/media/atomisp/pci/hmm/hmm_bo.c +10 -73
119 lines not on this page · raw message
Signature · 1 line
2.36.1
PATCH v2 9/13 media: atomisp: hmm_bo: Further simplify alloc_private_pages()
In reply to Hans de GoedeFurther simplify alloc_private_pages().
--- .../staging/media/atomisp/pci/hmm/hmm_bo.c | 29 ++++--------------- 1 file changed, 6 insertions(+), 23 deletions(-)
drivers/staging/media/atomisp/pci/hmm/hmm_bo.c +6 -23
@@ -642,21 +642,11 @@ static void free_private_bo_pages(struct hmm_buffer_object *bo,/*Allocate pages which will be used only by ISP*/ static int alloc_private_pages (struct hmm_buffer_object *bo) { -int ret; -unsigned int pgnr, blk_pgnr, alloc_pgnr; +const gfp_t gfp = __GFP_NOWARN | __GFP_RECLAIM | __GFP_FS;struct page *pages; -gfp_t gfp =GFP_NOWAIT | __GFP_NOWARN;/* REVISIT: need __GFP_FS too? */ -int i, j; - - pgnr = bo->pgnr; - - i =0 ; - alloc_pgnr =0 ; - -while (pgnr) { - gfp &= ~GFP_NOWAIT ; - gfp |= __GFP_RECLAIM | __GFP_FS; +int i, ret; +for (i =0 ; i < bo->pgnr; i++) { pages =alloc_pages (gfp,0 );// alloc 1 page if (unlikely (!pages)) { dev_err(atomisp_dev,
@@ -664,12 +654,10 @@ static int alloc_private_pages(struct hmm_buffer_object *bo) __func__); goto cleanup; }else { - blk_pgnr =1 ; -/* * set memory to uncacheable -- UC_MINUS */ - ret =set_pages_uc (pages, blk_pgnr); + ret =set_pages_uc (pages,1 );if (ret) {dev_err (atomisp_dev,"set page uncacheablefailed.\n" );
@@ -679,18 +667,13 @@ static int alloc_private_pages(struct hmm_buffer_object *bo) goto cleanup; } -for (j =0 ; j < blk_pgnr; j++, i++) { - bo->pages[i] = pages + j; - } - - pgnr -= blk_pgnr; + bo->pages[i] = pages; } }return 0 ; cleanup: - alloc_pgnr = i; -free_private_bo_pages (bo, alloc_pgnr); +free_private_bo_pages (bo, i);return -ENOMEM ; }
Signature · 1 line
2.36.1
PATCH v2 10/13 media: atomisp: hmm_bo: Rewrite alloc_private_pages() using pages_array helper funcs
In reply to Hans de GoedeRewrite alloc_private_pages() using pages_array helper funcs.
Note alloc_pages_bulk_array() skips non NULL pages, so switch the allocating of the pages pointer array to kcalloc to ensure the pages are initially all set to NULL.
--- .../staging/media/atomisp/pci/hmm/hmm_bo.c | 48 ++++++++----------- 1 file changed, 20 insertions(+), 28 deletions(-)
drivers/staging/media/atomisp/pci/hmm/hmm_bo.c +20 -28
@@ -615,6 +615,14 @@ struct hmm_buffer_object *hmm_bo_device_search_vmap_start(return bo; } +static void free_pages_bulk_array (unsigned long nr_pages,struct page **page_array) +{ +unsigned long i; + +for (i =0 ; i < nr_pages; i++) +__free_pages (page_array[i],0 ); +} +static void free_private_bo_pages (struct hmm_buffer_object *bo,int free_pgnr) {
@@ -643,38 +651,22 @@ static void free_private_bo_pages(struct hmm_buffer_object *bo,static int alloc_private_pages (struct hmm_buffer_object *bo) {const gfp_t gfp = __GFP_NOWARN | __GFP_RECLAIM | __GFP_FS; -struct page *pages; -int i, ret; - -for (i =0 ; i < bo->pgnr; i++) { - pages =alloc_pages (gfp,0 );// alloc 1 page -if (unlikely (!pages)) { -dev_err (atomisp_dev, -"%s: cannot allocate pages\n" , - __func__); - goto cleanup; - }else { -/* -* set memory to uncacheable -- UC_MINUS -*/ - ret =set_pages_uc (pages,1 ); -if (ret) { -dev_err (atomisp_dev, -"set page uncacheablefailed.\n" ); - -__free_pages (pages,0 ); +int ret; - goto cleanup; - } + ret =alloc_pages_bulk_array (gfp, bo->pgnr, bo->pages); +if (ret != bo->pgnr) { +free_pages_bulk_array (ret, bo->pages); +return -ENOMEM ; + } - bo->pages[i] = pages; - } + ret =set_pages_array_uc (bo->pages, bo->pgnr); +if (ret) { +dev_err (atomisp_dev,"set pages uncacheable failed.\n" ); +free_pages_bulk_array (bo->pgnr, bo->pages); +return ret; }return 0 ; -cleanup: -free_private_bo_pages (bo, i); -return -ENOMEM ; } static void free_user_pages(struct hmm_buffer_object *bo,
@@ -774,7 +766,7 @@ int hmm_bo_alloc_pages(struct hmm_buffer_object *bo,mutex_lock (&bo->mutex);check_bo_status_no_goto (bo,HMM_BO_PAGE_ALLOCED , status_err); - bo->pages =kmalloc_array (bo->pgnr,sizeof (struct page *),GFP_KERNEL ); + bo->pages =kcalloc (bo->pgnr,sizeof (struct page *),GFP_KERNEL );if (unlikely (!bo->pages)) { ret = -ENOMEM ; goto alloc_err;
Signature · 1 line
2.36.1
PATCH v2 11/13 media: atomisp: hmm_bo: Rewrite free_private_pages() using pages_array helper funcs
In reply to Hans de GoedeRewrite free_private_pages() using pages_array helper funcs.
--- .../staging/media/atomisp/pci/hmm/hmm_bo.c | 26 +++---------------- 1 file changed, 4 insertions(+), 22 deletions(-)
drivers/staging/media/atomisp/pci/hmm/hmm_bo.c +4 -22
@@ -623,28 +623,10 @@ static void free_pages_bulk_array(unsigned long nr_pages, struct page **page_arr__free_pages (page_array[i],0 ); } -static void free_private_bo_pages (struct hmm_buffer_object *bo, -int free_pgnr) +static void free_private_bo_pages (struct hmm_buffer_object *bo) { -int i, ret; - -for (i =0 ; i < free_pgnr; i++) { - ret =set_pages_wb (bo->pages[i],1 ); -if (ret) -dev_err (atomisp_dev, -"set page to WB err ...ret = %d\n" , - ret); -/* -W/A: set_pages_wb seldom return value = -EFAULT -indicate that address of page is not in valid -range(0xffff880000000000~0xffffc7ffffffffff) -then, _free_pages would panic; Do not know why page -address be valid,it maybe memory corruption by lowmemory -*/ -if (!ret) { -__free_pages (bo->pages[i],0 ); - } - } +set_pages_array_wb (bo->pages, bo->pgnr); +free_pages_bulk_array (bo->pgnr, bo->pages); }/*Allocate pages which will be used only by ISP*/
@@ -822,7 +804,7 @@ void hmm_bo_free_pages(struct hmm_buffer_object *bo) bo->status &= (~HMM_BO_PAGE_ALLOCED );if (bo->type ==HMM_BO_PRIVATE ) -free_private_bo_pages (bo, bo->pgnr); +free_private_bo_pages (bo);else if (bo->type ==HMM_BO_USER )free_user_pages (bo, bo->pgnr);else
Signature · 1 line
2.36.1
PATCH v2 12/13 media: atomisp: hmm_bo: Drop PFN code path from alloc_user_pages()
In reply to Hans de Goedealloc_user_pages() is only ever called on qbuf for USERPTR buffers which always hits the get_user_pages_fast() path, so the pin_user_pages() path can be removed.
Getting the vma then also is no longer necessary since that is only done to determine which path to use.
And this also removes the only users of the mem_type struct hmm_bo member, so remove that as well.
---
Changes in v2:
- Various small style fixes suggested by Andy
- Drop useless dev_dbg call while at it
--- .../media/atomisp/include/hmm/hmm_bo.h | 3 -- .../staging/media/atomisp/pci/hmm/hmm_bo.c | 46 +++---------------- 2 files changed, 6 insertions(+), 43 deletions(-)
drivers/staging/media/atomisp/include/hmm/hmm_bo.h +0 -3
@@ -86,8 +86,6 @@ enum hmm_bo_type {#define HMM_BO_VMAPED 0x10#define HMM_BO_VMAPED_CACHED 0x20#define HMM_BO_ACTIVE 0x1000 -#define HMM_BO_MEM_TYPE_USER 0x1 -#define HMM_BO_MEM_TYPE_PFN 0x2struct hmm_bo_device {struct isp_mmu mmu;
@@ -123,7 +121,6 @@ struct hmm_buffer_object {enum hmm_bo_type type;int mmap_count;int status; -int mem_type;void *vmap_addr;/* kernel virtual address by vmap */ struct rb_node node;
drivers/staging/media/atomisp/pci/hmm/hmm_bo.c +6 -40
61 lines not on this page · raw message
Signature · 1 line
2.36.1
PATCH v2 13/13 media: atomisp: Ensure that USERPTR pointers are page aligned
In reply to Hans de GoedeThe atomisp code needs USERPTR pointers to be page aligned, otherwise bad things (scribbling over other parts of the process' RAM) happen.
Add a check to ensure this and exit VIDIOC_QBUF calls with unaligned pointers with -EINVAL.
---
Changes in v2:
- Use offset_in_page()
--- drivers/staging/media/atomisp/pci/atomisp_ioctl.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/staging/media/atomisp/pci/atomisp_ioctl.c +6 -0
@@ -1345,6 +1345,12 @@ static int atomisp_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf)* address and reprograme out page table properly */ if (buf->memory ==V4L2_MEMORY_USERPTR ) { +if (offset_in_page (buf->m.userptr)) { +dev_err (isp->dev,"Error userptr is not page aligned.\n" ); + ret = -EINVAL ; + goto error; + } + vb = pipe->capq.bufs[buf->index]; vm_mem = vb->priv;if (!vm_mem) {
Signature · 1 line
2.36.1
Quoted 5 lines · Hans de Goede
From: Andy Shevchenko <[email protected]>
The
acpi_evaluate_dsm_typed()provides a way to check the type of the object evaluated by_DSMcall. Use it instead of open coded variant.
of an open
...
Hmm... I thought I gave the Rb tag for patches 2-11. In this version patches 12 and 13 also look good to me.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi,
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Hans de Goede
From: Andy Shevchenko <[email protected]>
Quoted 8 lines
Quoted 2 lines
The
acpi_evaluate_dsm_typed()provides a way to check the type of the object evaluated by_DSMcall. Use it instead of open coded variant.of an open
...
Hmm... I thought I gave the Rb tag for patches 2-11.
Yes you did I forgot to add that, sorry. I have added it in my local tree now.
Quoted 1 line
In this version patches 12 and 13 also look good to me.
Thanks, also added in my local tree (I plan to send a v3 with more cleanups added on top).
Regards,
Hans