Commit fcae40c9 authored by Baolin Wang's avatar Baolin Wang Committed by Arnd Bergmann
Browse files

ALSA: Replace timespec with timespec64



Since timespec is not year 2038 safe on 32bit system, and we need to
convert all timespec variables to timespec64 type for sound subsystem.

This patch is used to do preparation for following patches, that will
convert all structures defined in uapi/sound/asound.h to use 64-bit
time_t.

Signed-off-by: default avatarBaolin Wang <baolin.wang@linaro.org>
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
parent e42617b8
Loading
Loading
Loading
Loading
+9 −9
Original line number Original line Diff line number Diff line
@@ -62,7 +62,7 @@ struct snd_pcm_ops {
	int (*sync_stop)(struct snd_pcm_substream *substream);
	int (*sync_stop)(struct snd_pcm_substream *substream);
	snd_pcm_uframes_t (*pointer)(struct snd_pcm_substream *substream);
	snd_pcm_uframes_t (*pointer)(struct snd_pcm_substream *substream);
	int (*get_time_info)(struct snd_pcm_substream *substream,
	int (*get_time_info)(struct snd_pcm_substream *substream,
			struct timespec *system_ts, struct timespec *audio_ts,
			struct timespec64 *system_ts, struct timespec64 *audio_ts,
			struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
			struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
			struct snd_pcm_audio_tstamp_report *audio_tstamp_report);
			struct snd_pcm_audio_tstamp_report *audio_tstamp_report);
	int (*fill_silence)(struct snd_pcm_substream *substream, int channel,
	int (*fill_silence)(struct snd_pcm_substream *substream, int channel,
@@ -343,7 +343,7 @@ static inline void snd_pcm_pack_audio_tstamp_report(__u32 *data, __u32 *accuracy
struct snd_pcm_runtime {
struct snd_pcm_runtime {
	/* -- Status -- */
	/* -- Status -- */
	struct snd_pcm_substream *trigger_master;
	struct snd_pcm_substream *trigger_master;
	struct timespec trigger_tstamp;	/* trigger timestamp */
	struct timespec64 trigger_tstamp;	/* trigger timestamp */
	bool trigger_tstamp_latched;     /* trigger timestamp latched in low-level driver/hardware */
	bool trigger_tstamp_latched;     /* trigger timestamp latched in low-level driver/hardware */
	int overrange;
	int overrange;
	snd_pcm_uframes_t avail_max;
	snd_pcm_uframes_t avail_max;
@@ -421,7 +421,7 @@ struct snd_pcm_runtime {
	/* -- audio timestamp config -- */
	/* -- audio timestamp config -- */
	struct snd_pcm_audio_tstamp_config audio_tstamp_config;
	struct snd_pcm_audio_tstamp_config audio_tstamp_config;
	struct snd_pcm_audio_tstamp_report audio_tstamp_report;
	struct snd_pcm_audio_tstamp_report audio_tstamp_report;
	struct timespec driver_tstamp;
	struct timespec64 driver_tstamp;


#if IS_ENABLED(CONFIG_SND_PCM_OSS)
#if IS_ENABLED(CONFIG_SND_PCM_OSS)
	/* -- OSS things -- */
	/* -- OSS things -- */
@@ -1155,22 +1155,22 @@ static inline void snd_pcm_set_runtime_buffer(struct snd_pcm_substream *substrea
}
}


/**
/**
 * snd_pcm_gettime - Fill the timespec depending on the timestamp mode
 * snd_pcm_gettime - Fill the timespec64 depending on the timestamp mode
 * @runtime: PCM runtime instance
 * @runtime: PCM runtime instance
 * @tv: timespec to fill
 * @tv: timespec64 to fill
 */
 */
static inline void snd_pcm_gettime(struct snd_pcm_runtime *runtime,
static inline void snd_pcm_gettime(struct snd_pcm_runtime *runtime,
				   struct timespec *tv)
				   struct timespec64 *tv)
{
{
	switch (runtime->tstamp_type) {
	switch (runtime->tstamp_type) {
	case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC:
	case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC:
		ktime_get_ts(tv);
		ktime_get_ts64(tv);
		break;
		break;
	case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW:
	case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW:
		getrawmonotonic(tv);
		ktime_get_raw_ts64(tv);
		break;
		break;
	default:
	default:
		getnstimeofday(tv);
		ktime_get_real_ts64(tv);
		break;
		break;
	}
	}
}
}
+2 −2
Original line number Original line Diff line number Diff line
@@ -93,8 +93,8 @@ struct snd_soc_component_driver {
	snd_pcm_uframes_t (*pointer)(struct snd_soc_component *component,
	snd_pcm_uframes_t (*pointer)(struct snd_soc_component *component,
				     struct snd_pcm_substream *substream);
				     struct snd_pcm_substream *substream);
	int (*get_time_info)(struct snd_soc_component *component,
	int (*get_time_info)(struct snd_soc_component *component,
		struct snd_pcm_substream *substream, struct timespec *system_ts,
		struct snd_pcm_substream *substream, struct timespec64 *system_ts,
		struct timespec *audio_ts,
		struct timespec64 *audio_ts,
		struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
		struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
		struct snd_pcm_audio_tstamp_report *audio_tstamp_report);
		struct snd_pcm_audio_tstamp_report *audio_tstamp_report);
	int (*copy_user)(struct snd_soc_component *component,
	int (*copy_user)(struct snd_soc_component *component,
+2 −2
Original line number Original line Diff line number Diff line
@@ -89,7 +89,7 @@ struct snd_timer_instance {
			  unsigned long ticks, unsigned long resolution);
			  unsigned long ticks, unsigned long resolution);
	void (*ccallback) (struct snd_timer_instance * timeri,
	void (*ccallback) (struct snd_timer_instance * timeri,
			   int event,
			   int event,
			   struct timespec * tstamp,
			   struct timespec64 * tstamp,
			   unsigned long resolution);
			   unsigned long resolution);
	void (*disconnect)(struct snd_timer_instance *timeri);
	void (*disconnect)(struct snd_timer_instance *timeri);
	void *callback_data;
	void *callback_data;
@@ -113,7 +113,7 @@ struct snd_timer_instance {
 */
 */


int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid, struct snd_timer **rtimer);
int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid, struct snd_timer **rtimer);
void snd_timer_notify(struct snd_timer *timer, int event, struct timespec *tstamp);
void snd_timer_notify(struct snd_timer *timer, int event, struct timespec64 *tstamp);
int snd_timer_global_new(char *id, int device, struct snd_timer **rtimer);
int snd_timer_global_new(char *id, int device, struct snd_timer **rtimer);
int snd_timer_global_free(struct snd_timer *timer);
int snd_timer_global_free(struct snd_timer *timer);
int snd_timer_global_register(struct snd_timer *timer);
int snd_timer_global_register(struct snd_timer *timer);
+22 −14
Original line number Original line Diff line number Diff line
@@ -144,8 +144,12 @@ void __snd_pcm_xrun(struct snd_pcm_substream *substream)
	struct snd_pcm_runtime *runtime = substream->runtime;
	struct snd_pcm_runtime *runtime = substream->runtime;


	trace_xrun(substream);
	trace_xrun(substream);
	if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE)
	if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) {
		snd_pcm_gettime(runtime, (struct timespec *)&runtime->status->tstamp);
		struct timespec64 tstamp;

		snd_pcm_gettime(runtime, &tstamp);
		runtime->status->tstamp = timespec64_to_timespec(tstamp);
	}
	snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
	snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
	if (xrun_debug(substream, XRUN_DEBUG_BASIC)) {
	if (xrun_debug(substream, XRUN_DEBUG_BASIC)) {
		char name[16];
		char name[16];
@@ -200,12 +204,12 @@ int snd_pcm_update_state(struct snd_pcm_substream *substream,
}
}


static void update_audio_tstamp(struct snd_pcm_substream *substream,
static void update_audio_tstamp(struct snd_pcm_substream *substream,
				struct timespec *curr_tstamp,
				struct timespec64 *curr_tstamp,
				struct timespec *audio_tstamp)
				struct timespec64 *audio_tstamp)
{
{
	struct snd_pcm_runtime *runtime = substream->runtime;
	struct snd_pcm_runtime *runtime = substream->runtime;
	u64 audio_frames, audio_nsecs;
	u64 audio_frames, audio_nsecs;
	struct timespec driver_tstamp;
	struct timespec64 driver_tstamp;


	if (runtime->tstamp_mode != SNDRV_PCM_TSTAMP_ENABLE)
	if (runtime->tstamp_mode != SNDRV_PCM_TSTAMP_ENABLE)
		return;
		return;
@@ -229,18 +233,22 @@ static void update_audio_tstamp(struct snd_pcm_substream *substream,
		}
		}
		audio_nsecs = div_u64(audio_frames * 1000000000LL,
		audio_nsecs = div_u64(audio_frames * 1000000000LL,
				runtime->rate);
				runtime->rate);
		*audio_tstamp = ns_to_timespec(audio_nsecs);
		*audio_tstamp = ns_to_timespec64(audio_nsecs);
	}
	}
	if (!timespec_equal(&runtime->status->audio_tstamp, audio_tstamp)) {

		runtime->status->audio_tstamp = *audio_tstamp;
	if (runtime->status->audio_tstamp.tv_sec != audio_tstamp->tv_sec ||
		runtime->status->tstamp = *curr_tstamp;
	    runtime->status->audio_tstamp.tv_nsec != audio_tstamp->tv_nsec) {
		runtime->status->audio_tstamp =
			timespec64_to_timespec(*audio_tstamp);
		runtime->status->tstamp = timespec64_to_timespec(*curr_tstamp);
	}
	}



	/*
	/*
	 * re-take a driver timestamp to let apps detect if the reference tstamp
	 * re-take a driver timestamp to let apps detect if the reference tstamp
	 * read by low-level hardware was provided with a delay
	 * read by low-level hardware was provided with a delay
	 */
	 */
	snd_pcm_gettime(substream->runtime, (struct timespec *)&driver_tstamp);
	snd_pcm_gettime(substream->runtime, &driver_tstamp);
	runtime->driver_tstamp = driver_tstamp;
	runtime->driver_tstamp = driver_tstamp;
}
}


@@ -253,8 +261,8 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,
	snd_pcm_sframes_t hdelta, delta;
	snd_pcm_sframes_t hdelta, delta;
	unsigned long jdelta;
	unsigned long jdelta;
	unsigned long curr_jiffies;
	unsigned long curr_jiffies;
	struct timespec curr_tstamp;
	struct timespec64 curr_tstamp;
	struct timespec audio_tstamp;
	struct timespec64 audio_tstamp;
	int crossed_boundary = 0;
	int crossed_boundary = 0;


	old_hw_ptr = runtime->status->hw_ptr;
	old_hw_ptr = runtime->status->hw_ptr;
@@ -277,9 +285,9 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream,


			/* re-test in case tstamp type is not supported in hardware and was demoted to DEFAULT */
			/* re-test in case tstamp type is not supported in hardware and was demoted to DEFAULT */
			if (runtime->audio_tstamp_report.actual_type == SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT)
			if (runtime->audio_tstamp_report.actual_type == SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT)
				snd_pcm_gettime(runtime, (struct timespec *)&curr_tstamp);
				snd_pcm_gettime(runtime, &curr_tstamp);
		} else
		} else
			snd_pcm_gettime(runtime, (struct timespec *)&curr_tstamp);
			snd_pcm_gettime(runtime, &curr_tstamp);
	}
	}


	if (pos == SNDRV_PCM_POS_XRUN) {
	if (pos == SNDRV_PCM_POS_XRUN) {
+8 −4
Original line number Original line Diff line number Diff line
@@ -918,12 +918,12 @@ int snd_pcm_status(struct snd_pcm_substream *substream,
	status->suspended_state = runtime->status->suspended_state;
	status->suspended_state = runtime->status->suspended_state;
	if (status->state == SNDRV_PCM_STATE_OPEN)
	if (status->state == SNDRV_PCM_STATE_OPEN)
		goto _end;
		goto _end;
	status->trigger_tstamp = runtime->trigger_tstamp;
	status->trigger_tstamp = timespec64_to_timespec(runtime->trigger_tstamp);
	if (snd_pcm_running(substream)) {
	if (snd_pcm_running(substream)) {
		snd_pcm_update_hw_ptr(substream);
		snd_pcm_update_hw_ptr(substream);
		if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) {
		if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) {
			status->tstamp = runtime->status->tstamp;
			status->tstamp = runtime->status->tstamp;
			status->driver_tstamp = runtime->driver_tstamp;
			status->driver_tstamp = timespec64_to_timespec(runtime->driver_tstamp);
			status->audio_tstamp =
			status->audio_tstamp =
				runtime->status->audio_tstamp;
				runtime->status->audio_tstamp;
			if (runtime->audio_tstamp_report.valid == 1)
			if (runtime->audio_tstamp_report.valid == 1)
@@ -936,8 +936,12 @@ int snd_pcm_status(struct snd_pcm_substream *substream,
		}
		}
	} else {
	} else {
		/* get tstamp only in fallback mode and only if enabled */
		/* get tstamp only in fallback mode and only if enabled */
		if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE)
		if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) {
			snd_pcm_gettime(runtime, &status->tstamp);
			struct timespec64 tstamp;

			snd_pcm_gettime(runtime, &tstamp);
			status->tstamp = timespec64_to_timespec(tstamp);
		}
	}
	}
 _tstamp_end:
 _tstamp_end:
	status->appl_ptr = runtime->control->appl_ptr;
	status->appl_ptr = runtime->control->appl_ptr;
Loading