linux/drivers/media/video/s5p-fimc/fimc-mdevice.h
Sylwester Nawrocki e3fc82e8b9 [media] s5p-fimc: Prevent lock-up in multiple sensor systems
The camera clocks managed by the driver were improperly reference counted
and remained disabled when multiple video nodes were opened simultaneously.
It manifested itself with following warning:

 [12.920000] WARNING: at drivers/media/video/s5p-fimc/fimc-mdevice.c:787 __fimc_md_set_camclk+0x1c0/0x1dc()
 [13.005000] Modules linked in:
 [13.005000] Backtrace:
 [13.040000] [<c0013084>] (dump_backtrace+0x0/0x10c) from [<c0454b70>] (dump_stack+0x18/0x1c)
 [13.070000]  r7:00000009 r6:00000313 r5:c02d576c r4:00000000
 [13.155000] [<c0454b58>] (dump_stack+0x0/0x1c) from [<c0022ec4>] (warn_slowpath_common+0x54/0x6c)
 [13.285000] [<c0022e70>] (warn_slowpath_common+0x0/0x6c) from [<c0022f00>] (warn_slowpath_null+0x24/0x2c)
 [13.360000]  r9:e1981010 r8:00000000 r7:c061d3fc r6:e1981010 r5:e1981030
 [13.430000] r4:00000000
 [13.430000] [<c0022edc>] (warn_slowpath_null+0x0/0x2c) from [<c02d576c>] (__fimc_md_set_camclk+0x1c0/0x1dc)
 [13.550000] [<c02d55ac>] (__fimc_md_set_camclk+0x0/0x1dc) from [<c02d57b0>] (fimc_md_set_camclk+0x28/0x2c)
 [13.630000] [<c02d5788>] (fimc_md_set_camclk+0x0/0x2c) from [<c02d57e8>] (__fimc_pipeline_shutdown+0x34/0x50)
 [13.705000] [<c02d57b4>] (__fimc_pipeline_shutdown+0x0/0x50) from [<c02d5844>] (fimc_pipeline_shutdown+0x40/0x58)
 [13.765000]  r5:e2391200 r4:e2357704
 [13.805000] [<c02d5804>] (fimc_pipeline_shutdown+0x0/0x58) from [<c02d4754>] (fimc_capture_close+0xcc/0xe4)
 [13.915000]  r5:e1b396c0 r4:e2357410
 [13.915000] [<c02d4688>] (fimc_capture_close+0x0/0xe4) from [<c02b2d5c>] (v4l2_release+0x5c/0x80)
 [13.970000]  r7:00000010 r6:e1d2d990 r5:e1b396c0 r4:e2394800
 [14.000000] [<c02b2d00>] (v4l2_release+0x0/0x80) from [<c00b66cc>] (fput+0xc0/0x22c)
 [14.015000]  r5:c157ef30 r4:e1b396c0
 [14.015000] [<c00b660c>] (fput+0x0/0x22c) from [<c00b2ca0>] (filp_close+0x60/0x80)
 [14.080000] [<c00b2c40>] (filp_close+0x0/0x80) from [<c00b2d78>] (sys_close+0xb8/0xf4)
 [14.125000]  r7:00000001 r6:e1b396c0 r5:c1400340 r4:c1400300
 [14.125000] [<c00b2cc0>] (sys_close+0x0/0xf4) from [<c000f300>] (ret_fast_syscall+0x0/0x30)
 [14.205000]  r7:00000006 r6:beee5b94 r5:00000003 r4:b6f64fac

Fix this, as well as potential memory leaks due to not calling
v4l2_fh_release() on some error paths.

Also remove some error logs printed for events that aren't critical and
are normal conditions for some system configurations.

Also check if the device have been properly run-time enabled during
video node open.

Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
2012-06-25 09:18:02 -03:00

121 lines
3.6 KiB
C

/*
* Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#ifndef FIMC_MDEVICE_H_
#define FIMC_MDEVICE_H_
#include <linux/clk.h>
#include <linux/platform_device.h>
#include <linux/mutex.h>
#include <media/media-device.h>
#include <media/media-entity.h>
#include <media/v4l2-device.h>
#include <media/v4l2-subdev.h>
#include "fimc-core.h"
#include "fimc-lite.h"
#include "mipi-csis.h"
/* Group IDs of sensor, MIPI-CSIS, FIMC-LITE and the writeback subdevs. */
#define SENSOR_GROUP_ID (1 << 8)
#define CSIS_GROUP_ID (1 << 9)
#define WRITEBACK_GROUP_ID (1 << 10)
#define FIMC_GROUP_ID (1 << 11)
#define FLITE_GROUP_ID (1 << 12)
#define FIMC_MAX_SENSORS 8
#define FIMC_MAX_CAMCLKS 2
struct fimc_csis_info {
struct v4l2_subdev *sd;
int id;
};
struct fimc_camclk_info {
struct clk *clock;
int use_count;
unsigned long frequency;
};
/**
* struct fimc_sensor_info - image data source subdev information
* @pdata: sensor's atrributes passed as media device's platform data
* @subdev: image sensor v4l2 subdev
* @host: fimc device the sensor is currently linked to
*
* This data structure applies to image sensor and the writeback subdevs.
*/
struct fimc_sensor_info {
struct s5p_fimc_isp_info *pdata;
struct v4l2_subdev *subdev;
struct fimc_dev *host;
};
/**
* struct fimc_md - fimc media device information
* @csis: MIPI CSIS subdevs data
* @sensor: array of registered sensor subdevs
* @num_sensors: actual number of registered sensors
* @camclk: external sensor clock information
* @fimc: array of registered fimc devices
* @media_dev: top level media device
* @v4l2_dev: top level v4l2_device holding up the subdevs
* @pdev: platform device this media device is hooked up into
* @user_subdev_api: true if subdevs are not configured by the host driver
* @slock: spinlock protecting @sensor array
*/
struct fimc_md {
struct fimc_csis_info csis[CSIS_MAX_ENTITIES];
struct fimc_sensor_info sensor[FIMC_MAX_SENSORS];
int num_sensors;
struct fimc_camclk_info camclk[FIMC_MAX_CAMCLKS];
struct fimc_lite *fimc_lite[FIMC_LITE_MAX_DEVS];
struct fimc_dev *fimc[FIMC_MAX_DEVS];
struct media_device media_dev;
struct v4l2_device v4l2_dev;
struct platform_device *pdev;
bool user_subdev_api;
spinlock_t slock;
};
#define is_subdev_pad(pad) (pad == NULL || \
media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV)
#define me_subtype(me) \
((me->type) & (MEDIA_ENT_TYPE_MASK | MEDIA_ENT_SUBTYPE_MASK))
#define subdev_has_devnode(__sd) (__sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE)
static inline struct fimc_md *entity_to_fimc_mdev(struct media_entity *me)
{
return me->parent == NULL ? NULL :
container_of(me->parent, struct fimc_md, media_dev);
}
static inline void fimc_md_graph_lock(struct fimc_dev *fimc)
{
BUG_ON(fimc->vid_cap.vfd == NULL);
mutex_lock(&fimc->vid_cap.vfd->entity.parent->graph_mutex);
}
static inline void fimc_md_graph_unlock(struct fimc_dev *fimc)
{
BUG_ON(fimc->vid_cap.vfd == NULL);
mutex_unlock(&fimc->vid_cap.vfd->entity.parent->graph_mutex);
}
int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on);
void fimc_pipeline_prepare(struct fimc_pipeline *p, struct media_entity *me);
int fimc_pipeline_initialize(struct fimc_pipeline *p, struct media_entity *me,
bool resume);
int fimc_pipeline_shutdown(struct fimc_pipeline *p);
int fimc_pipeline_s_power(struct fimc_pipeline *p, bool state);
int fimc_pipeline_s_stream(struct fimc_pipeline *p, bool state);
#endif