media: omap3isp: support 64-bit version of omap3isp_stat_data
authorArnd Bergmann <arnd@arndb.de>
Wed, 25 Apr 2018 21:30:10 +0000 (17:30 -0400)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Wed, 9 May 2018 20:37:05 +0000 (16:37 -0400)
C libraries with 64-bit time_t use an incompatible format for
struct omap3isp_stat_data. This changes the kernel code to
support either version, by moving over the normal handling
to the 64-bit variant, and adding compatiblity code to handle
the old binary format with the existing ioctl command code.

Fortunately, the command code includes the size of the structure,
so the difference gets handled automatically. In the process of
eliminating the references to 'struct timeval' from the kernel,
I also change the way the timestamp is generated internally,
basically by open-coding the v4l2_get_timestamp() call.

[Sakari Ailus: Alphabetical order of headers, clean up compat code]

Cc: Sakari Ailus <sakari.ailus@iki.fi>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/media/platform/omap3isp/isph3a_aewb.c
drivers/media/platform/omap3isp/isph3a_af.c
drivers/media/platform/omap3isp/isphist.c
drivers/media/platform/omap3isp/ispstat.c
drivers/media/platform/omap3isp/ispstat.h
include/uapi/linux/omap3isp.h

index d44626f20ac616a345cc1f423771bb8b8d239f48..3c82dea4d375f16c3b1712683ac4a55e80309fb1 100644 (file)
@@ -250,6 +250,8 @@ static long h3a_aewb_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
                return omap3isp_stat_config(stat, arg);
        case VIDIOC_OMAP3ISP_STAT_REQ:
                return omap3isp_stat_request_statistics(stat, arg);
+       case VIDIOC_OMAP3ISP_STAT_REQ_TIME32:
+               return omap3isp_stat_request_statistics_time32(stat, arg);
        case VIDIOC_OMAP3ISP_STAT_EN: {
                unsigned long *en = arg;
                return omap3isp_stat_enable(stat, !!*en);
index 99bd6cc21d86df18f0d97b0c0a267cd784ca811a..4da25c84f0c6214337e61c2d08c00ec54c203705 100644 (file)
@@ -314,6 +314,8 @@ static long h3a_af_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
                return omap3isp_stat_config(stat, arg);
        case VIDIOC_OMAP3ISP_STAT_REQ:
                return omap3isp_stat_request_statistics(stat, arg);
+       case VIDIOC_OMAP3ISP_STAT_REQ_TIME32:
+               return omap3isp_stat_request_statistics_time32(stat, arg);
        case VIDIOC_OMAP3ISP_STAT_EN: {
                int *en = arg;
                return omap3isp_stat_enable(stat, !!*en);
index a4ed5d140d4898a4513f6eb56fa4e71d8264cf5b..d4be3d0e06f94e5e15883af039d756fc244f40af 100644 (file)
@@ -435,6 +435,8 @@ static long hist_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
                return omap3isp_stat_config(stat, arg);
        case VIDIOC_OMAP3ISP_STAT_REQ:
                return omap3isp_stat_request_statistics(stat, arg);
+       case VIDIOC_OMAP3ISP_STAT_REQ_TIME32:
+               return omap3isp_stat_request_statistics_time32(stat, arg);
        case VIDIOC_OMAP3ISP_STAT_EN: {
                int *en = arg;
                return omap3isp_stat_enable(stat, !!*en);
index 0b31f6c5791fbe04d94ee23517546f71a1e8295b..6af7460a355905cdc61bd9fedd60dd2365f2dcaf 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <linux/dma-mapping.h>
 #include <linux/slab.h>
+#include <linux/timekeeping.h>
 #include <linux/uaccess.h>
 
 #include "isp.h"
@@ -237,7 +238,7 @@ static int isp_stat_buf_queue(struct ispstat *stat)
        if (!stat->active_buf)
                return STAT_NO_BUF;
 
-       v4l2_get_timestamp(&stat->active_buf->ts);
+       ktime_get_ts64(&stat->active_buf->ts);
 
        stat->active_buf->buf_size = stat->buf_size;
        if (isp_stat_buf_check_magic(stat, stat->active_buf)) {
@@ -498,7 +499,8 @@ int omap3isp_stat_request_statistics(struct ispstat *stat,
                return PTR_ERR(buf);
        }
 
-       data->ts = buf->ts;
+       data->ts.tv_sec = buf->ts.tv_sec;
+       data->ts.tv_usec = buf->ts.tv_nsec / NSEC_PER_USEC;
        data->config_counter = buf->config_counter;
        data->frame_number = buf->frame_number;
        data->buf_size = buf->buf_size;
@@ -510,6 +512,23 @@ int omap3isp_stat_request_statistics(struct ispstat *stat,
        return 0;
 }
 
+int omap3isp_stat_request_statistics_time32(struct ispstat *stat,
+                                       struct omap3isp_stat_data_time32 *data)
+{
+       struct omap3isp_stat_data data64;
+       int ret;
+
+       ret = omap3isp_stat_request_statistics(stat, &data64);
+       if (ret)
+               return ret;
+
+       data->ts.tv_sec = data64.ts.tv_sec;
+       data->ts.tv_usec = data64.ts.tv_usec;
+       memcpy(&data->buf, &data64.buf, sizeof(*data) - sizeof(data->ts));
+
+       return 0;
+}
+
 /*
  * omap3isp_stat_config - Receives new statistic engine configuration.
  * @new_conf: Pointer to config structure.
index 6d9b0244f3209d8b6b86911fe5a371fd3e9b8e1e..923b38cfc682ccc83ff6f5a83e0e2023df9786ee 100644 (file)
@@ -39,7 +39,7 @@ struct ispstat_buffer {
        struct sg_table sgt;
        void *virt_addr;
        dma_addr_t dma_addr;
-       struct timeval ts;
+       struct timespec64 ts;
        u32 buf_size;
        u32 frame_number;
        u16 config_counter;
@@ -130,6 +130,8 @@ struct ispstat_generic_config {
 int omap3isp_stat_config(struct ispstat *stat, void *new_conf);
 int omap3isp_stat_request_statistics(struct ispstat *stat,
                                     struct omap3isp_stat_data *data);
+int omap3isp_stat_request_statistics_time32(struct ispstat *stat,
+                                    struct omap3isp_stat_data_time32 *data);
 int omap3isp_stat_init(struct ispstat *stat, const char *name,
                       const struct v4l2_subdev_ops *sd_ops);
 void omap3isp_stat_cleanup(struct ispstat *stat);
index 1a920145db04bba0ee8e99f16d50d19b5f57bca8..87b55755f4ffe57ab8fd7467881750a9e3531897 100644 (file)
@@ -55,6 +55,8 @@
        _IOWR('V', BASE_VIDIOC_PRIVATE + 5, struct omap3isp_h3a_af_config)
 #define VIDIOC_OMAP3ISP_STAT_REQ \
        _IOWR('V', BASE_VIDIOC_PRIVATE + 6, struct omap3isp_stat_data)
+#define VIDIOC_OMAP3ISP_STAT_REQ_TIME32 \
+       _IOWR('V', BASE_VIDIOC_PRIVATE + 6, struct omap3isp_stat_data_time32)
 #define VIDIOC_OMAP3ISP_STAT_EN \
        _IOWR('V', BASE_VIDIOC_PRIVATE + 7, unsigned long)
 
@@ -165,7 +167,14 @@ struct omap3isp_h3a_aewb_config {
  * @config_counter: Number of the configuration associated with the data.
  */
 struct omap3isp_stat_data {
+#ifdef __KERNEL__
+       struct {
+               __s64   tv_sec;
+               __s64   tv_usec;
+       } ts;
+#else
        struct timeval ts;
+#endif
        void __user *buf;
        __u32 buf_size;
        __u16 frame_number;
@@ -173,6 +182,19 @@ struct omap3isp_stat_data {
        __u16 config_counter;
 };
 
+#ifdef __KERNEL__
+struct omap3isp_stat_data_time32 {
+       struct {
+               __s32   tv_sec;
+               __s32   tv_usec;
+       } ts;
+       __u32 buf;
+       __u32 buf_size;
+       __u16 frame_number;
+       __u16 cur_frame;
+       __u16 config_counter;
+};
+#endif
 
 /* Histogram related structs */