hc
2023-12-09 958e46acc8e900e8569dd467c1af9b8d2d019394
kernel/include/sound/pcm.h
....@@ -1,3 +1,4 @@
1
+/* SPDX-License-Identifier: GPL-2.0-or-later */
12 #ifndef __SOUND_PCM_H
23 #define __SOUND_PCM_H
34
....@@ -5,22 +6,6 @@
56 * Digital Audio (PCM) abstract layer
67 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
78 * Abramo Bagnara <abramo@alsa-project.org>
8
- *
9
- *
10
- * This program is free software; you can redistribute it and/or modify
11
- * it under the terms of the GNU General Public License as published by
12
- * the Free Software Foundation; either version 2 of the License, or
13
- * (at your option) any later version.
14
- *
15
- * This program is distributed in the hope that it will be useful,
16
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
- * GNU General Public License for more details.
19
- *
20
- * You should have received a copy of the GNU General Public License
21
- * along with this program; if not, write to the Free Software
22
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
- *
249 */
2510
2611 #include <sound/asound.h>
....@@ -30,6 +15,7 @@
3015 #include <linux/mm.h>
3116 #include <linux/bitops.h>
3217 #include <linux/pm_qos.h>
18
+#include <linux/refcount.h>
3319
3420 #define snd_pcm_substream_chip(substream) ((substream)->private_data)
3521 #define snd_pcm_chip(pcm) ((pcm)->private_data)
....@@ -58,6 +44,7 @@
5844 size_t fifo_size; /* fifo size in bytes */
5945 };
6046
47
+struct snd_pcm_status64;
6148 struct snd_pcm_substream;
6249
6350 struct snd_pcm_audio_tstamp_config; /* definitions further down */
....@@ -68,21 +55,17 @@
6855 int (*close)(struct snd_pcm_substream *substream);
6956 int (*ioctl)(struct snd_pcm_substream * substream,
7057 unsigned int cmd, void *arg);
71
- int (*compat_ioctl)(struct snd_pcm_substream *substream,
72
- unsigned int cmd, void *arg);
7358 int (*hw_params)(struct snd_pcm_substream *substream,
7459 struct snd_pcm_hw_params *params);
7560 int (*hw_free)(struct snd_pcm_substream *substream);
7661 int (*prepare)(struct snd_pcm_substream *substream);
7762 int (*trigger)(struct snd_pcm_substream *substream, int cmd);
63
+ int (*sync_stop)(struct snd_pcm_substream *substream);
7864 snd_pcm_uframes_t (*pointer)(struct snd_pcm_substream *substream);
7965 int (*get_time_info)(struct snd_pcm_substream *substream,
80
- struct timespec *system_ts, struct timespec *audio_ts,
66
+ struct timespec64 *system_ts, struct timespec64 *audio_ts,
8167 struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
8268 struct snd_pcm_audio_tstamp_report *audio_tstamp_report);
83
- int (*delay_blk)(struct snd_pcm_substream *substream);
84
- int (*wall_clock)(struct snd_pcm_substream *substream,
85
- struct timespec *audio_ts);
8669 int (*fill_silence)(struct snd_pcm_substream *substream, int channel,
8770 unsigned long pos, unsigned long bytes);
8871 int (*copy_user)(struct snd_pcm_substream *substream, int channel,
....@@ -94,7 +77,6 @@
9477 unsigned long offset);
9578 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
9679 int (*ack)(struct snd_pcm_substream *substream);
97
- int (*restart)(struct snd_pcm_substream *substream);
9880 };
9981
10082 /*
....@@ -122,11 +104,6 @@
122104 #define SNDRV_PCM_TRIGGER_DRAIN 7
123105
124106 #define SNDRV_PCM_POS_XRUN ((snd_pcm_uframes_t)-1)
125
-
126
-#define SNDRV_DMA_MODE (0)
127
-#define SNDRV_NON_DMA_MODE (1 << 0)
128
-#define SNDRV_RENDER_STOPPED (1 << 1)
129
-#define SNDRV_RENDER_RUNNING (1 << 2)
130107
131108 /* If you change this don't forget to change rates[] table in pcm_native.c */
132109 #define SNDRV_PCM_RATE_5512 (1<<0) /* 5512Hz */
....@@ -367,7 +344,7 @@
367344 struct snd_pcm_runtime {
368345 /* -- Status -- */
369346 struct snd_pcm_substream *trigger_master;
370
- struct timespec trigger_tstamp; /* trigger timestamp */
347
+ struct timespec64 trigger_tstamp; /* trigger timestamp */
371348 bool trigger_tstamp_latched; /* trigger timestamp latched in low-level driver/hardware */
372349 int overrange;
373350 snd_pcm_uframes_t avail_max;
....@@ -395,7 +372,6 @@
395372 unsigned int rate_num;
396373 unsigned int rate_den;
397374 unsigned int no_period_wakeup: 1;
398
- unsigned int render_flag;
399375
400376 /* -- SW params -- */
401377 int tstamp_mode; /* mmap timestamp is updated */
....@@ -421,6 +397,7 @@
421397 wait_queue_head_t sleep; /* poll sleep */
422398 wait_queue_head_t tsleep; /* transfer sleep */
423399 struct fasync_struct *fasync;
400
+ bool stop_operating; /* sync_stop will be called */
424401
425402 /* -- private section -- */
426403 void *private_data;
....@@ -440,15 +417,20 @@
440417 size_t dma_bytes; /* size of DMA area */
441418
442419 struct snd_dma_buffer *dma_buffer_p; /* allocated buffer */
420
+ unsigned int buffer_changed:1; /* buffer allocation changed; set only in managed mode */
443421
444422 /* -- audio timestamp config -- */
445423 struct snd_pcm_audio_tstamp_config audio_tstamp_config;
446424 struct snd_pcm_audio_tstamp_report audio_tstamp_report;
447
- struct timespec driver_tstamp;
425
+ struct timespec64 driver_tstamp;
448426
449427 #if IS_ENABLED(CONFIG_SND_PCM_OSS)
450428 /* -- OSS things -- */
451429 struct snd_pcm_oss_runtime oss;
430
+#endif
431
+#ifndef __GENKSYMS__
432
+ struct mutex buffer_mutex; /* protect for buffer changes */
433
+ atomic_t buffer_accessing; /* >0: in r/w operation, <0: blocked */
452434 #endif
453435 };
454436
....@@ -456,7 +438,7 @@
456438 spinlock_t lock;
457439 struct mutex mutex;
458440 struct list_head substreams;
459
- int count;
441
+ refcount_t refs;
460442 };
461443
462444 struct pid;
....@@ -476,7 +458,6 @@
476458 const struct snd_pcm_ops *ops;
477459 /* -- runtime information -- */
478460 struct snd_pcm_runtime *runtime;
479
- spinlock_t runtime_lock;
480461 /* -- timer section -- */
481462 struct snd_timer *timer; /* timer */
482463 unsigned timer_running: 1; /* time is running */
....@@ -488,7 +469,6 @@
488469 struct snd_pcm_group self_group; /* fake group for non linked substream (with substream lock inside) */
489470 struct snd_pcm_group *group; /* pointer to current group */
490471 /* -- assigned files -- */
491
- void *file;
492472 int ref_count;
493473 atomic_t mmap_count;
494474 unsigned int f_flags;
....@@ -500,19 +480,10 @@
500480 #endif
501481 #ifdef CONFIG_SND_VERBOSE_PROCFS
502482 struct snd_info_entry *proc_root;
503
- struct snd_info_entry *proc_info_entry;
504
- struct snd_info_entry *proc_hw_params_entry;
505
- struct snd_info_entry *proc_sw_params_entry;
506
- struct snd_info_entry *proc_status_entry;
507
- struct snd_info_entry *proc_prealloc_entry;
508
- struct snd_info_entry *proc_prealloc_max_entry;
509
-#ifdef CONFIG_SND_PCM_XRUN_DEBUG
510
- struct snd_info_entry *proc_xrun_injection_entry;
511
-#endif
512483 #endif /* CONFIG_SND_VERBOSE_PROCFS */
513484 /* misc flags */
514485 unsigned int hw_opened: 1;
515
- unsigned int hw_no_buffer: 1; /* substream may not have a buffer */
486
+ unsigned int managed_buffer_alloc:1;
516487 };
517488
518489 #define SUBSTREAM_BUSY(substream) ((substream)->ref_count > 0)
....@@ -531,15 +502,11 @@
531502 #endif
532503 #ifdef CONFIG_SND_VERBOSE_PROCFS
533504 struct snd_info_entry *proc_root;
534
- struct snd_info_entry *proc_info_entry;
535505 #ifdef CONFIG_SND_PCM_XRUN_DEBUG
536506 unsigned int xrun_debug; /* 0 = disabled, 1 = verbose, 2 = stacktrace */
537
- struct snd_info_entry *proc_xrun_debug_entry;
538507 #endif
539508 #endif
540509 struct snd_kcontrol *chmap_kctl; /* channel-mapping controls */
541
- struct snd_kcontrol *vol_kctl; /* volume controls */
542
- struct snd_kcontrol *usr_kctl; /* user controls */
543510 struct device dev;
544511 };
545512
....@@ -559,6 +526,7 @@
559526 void (*private_free) (struct snd_pcm *pcm);
560527 bool internal; /* pcm is for internal use only */
561528 bool nonatomic; /* whole PCM operations are in non-atomic context */
529
+ bool no_device_suspend; /* don't invoke device PM suspend */
562530 #if IS_ENABLED(CONFIG_SND_PCM_OSS)
563531 struct snd_pcm_oss oss;
564532 #endif
....@@ -595,20 +563,15 @@
595563 int snd_pcm_info(struct snd_pcm_substream *substream, struct snd_pcm_info *info);
596564 int snd_pcm_info_user(struct snd_pcm_substream *substream,
597565 struct snd_pcm_info __user *info);
598
-int snd_pcm_status(struct snd_pcm_substream *substream,
599
- struct snd_pcm_status *status);
566
+int snd_pcm_status64(struct snd_pcm_substream *substream,
567
+ struct snd_pcm_status64 *status);
600568 int snd_pcm_start(struct snd_pcm_substream *substream);
601569 int snd_pcm_stop(struct snd_pcm_substream *substream, snd_pcm_state_t status);
602570 int snd_pcm_drain_done(struct snd_pcm_substream *substream);
603571 int snd_pcm_stop_xrun(struct snd_pcm_substream *substream);
604572 #ifdef CONFIG_PM
605
-int snd_pcm_suspend(struct snd_pcm_substream *substream);
606573 int snd_pcm_suspend_all(struct snd_pcm *pcm);
607574 #else
608
-static inline int snd_pcm_suspend(struct snd_pcm_substream *substream)
609
-{
610
- return 0;
611
-}
612575 static inline int snd_pcm_suspend_all(struct snd_pcm *pcm)
613576 {
614577 return 0;
....@@ -684,6 +647,11 @@
684647 */
685648 #define snd_pcm_group_for_each_entry(s, substream) \
686649 list_for_each_entry(s, &substream->group->substreams, link_list)
650
+
651
+#define for_each_pcm_streams(stream) \
652
+ for (stream = SNDRV_PCM_STREAM_PLAYBACK; \
653
+ stream <= SNDRV_PCM_STREAM_LAST; \
654
+ stream++)
687655
688656 /**
689657 * snd_pcm_running - Check whether the substream is in a running state
....@@ -786,7 +754,7 @@
786754 }
787755
788756 /**
789
- * snd_pcm_playback_avail - Get the available (readable) space for capture
757
+ * snd_pcm_capture_avail - Get the available (readable) space for capture
790758 * @runtime: PCM runtime instance
791759 *
792760 * Result is between 0 ... (boundary - 1)
....@@ -1163,7 +1131,14 @@
11631131 return __snd_pcm_lib_xfer(substream, bufs, false, frames, true);
11641132 }
11651133
1166
-int snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime);
1134
+int snd_pcm_hw_limit_rates(struct snd_pcm_hardware *hw);
1135
+
1136
+static inline int
1137
+snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime)
1138
+{
1139
+ return snd_pcm_hw_limit_rates(&runtime->hw);
1140
+}
1141
+
11671142 unsigned int snd_pcm_rate_to_rate_bit(unsigned int rate);
11681143 unsigned int snd_pcm_rate_bit_to_rate(unsigned int rate_bit);
11691144 unsigned int snd_pcm_rate_mask_intersect(unsigned int rates_a,
....@@ -1197,22 +1172,22 @@
11971172 }
11981173
11991174 /**
1200
- * snd_pcm_gettime - Fill the timespec depending on the timestamp mode
1175
+ * snd_pcm_gettime - Fill the timespec64 depending on the timestamp mode
12011176 * @runtime: PCM runtime instance
1202
- * @tv: timespec to fill
1177
+ * @tv: timespec64 to fill
12031178 */
12041179 static inline void snd_pcm_gettime(struct snd_pcm_runtime *runtime,
1205
- struct timespec *tv)
1180
+ struct timespec64 *tv)
12061181 {
12071182 switch (runtime->tstamp_type) {
12081183 case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC:
1209
- ktime_get_ts(tv);
1184
+ ktime_get_ts64(tv);
12101185 break;
12111186 case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW:
1212
- getrawmonotonic(tv);
1187
+ ktime_get_raw_ts64(tv);
12131188 break;
12141189 default:
1215
- getnstimeofday(tv);
1190
+ ktime_get_real_ts64(tv);
12161191 break;
12171192 }
12181193 }
....@@ -1221,16 +1196,22 @@
12211196 * Memory
12221197 */
12231198
1224
-int snd_pcm_lib_preallocate_free(struct snd_pcm_substream *substream);
1225
-int snd_pcm_lib_preallocate_free_for_all(struct snd_pcm *pcm);
1226
-int snd_pcm_lib_preallocate_pages(struct snd_pcm_substream *substream,
1199
+void snd_pcm_lib_preallocate_free(struct snd_pcm_substream *substream);
1200
+void snd_pcm_lib_preallocate_free_for_all(struct snd_pcm *pcm);
1201
+void snd_pcm_lib_preallocate_pages(struct snd_pcm_substream *substream,
12271202 int type, struct device *data,
12281203 size_t size, size_t max);
1229
-int snd_pcm_lib_preallocate_pages_for_all(struct snd_pcm *pcm,
1204
+void snd_pcm_lib_preallocate_pages_for_all(struct snd_pcm *pcm,
12301205 int type, void *data,
12311206 size_t size, size_t max);
12321207 int snd_pcm_lib_malloc_pages(struct snd_pcm_substream *substream, size_t size);
12331208 int snd_pcm_lib_free_pages(struct snd_pcm_substream *substream);
1209
+
1210
+void snd_pcm_set_managed_buffer(struct snd_pcm_substream *substream, int type,
1211
+ struct device *data, size_t size, size_t max);
1212
+void snd_pcm_set_managed_buffer_all(struct snd_pcm *pcm, int type,
1213
+ struct device *data,
1214
+ size_t size, size_t max);
12341215
12351216 int _snd_pcm_lib_alloc_vmalloc_buffer(struct snd_pcm_substream *substream,
12361217 size_t size, gfp_t gfp_flags);
....@@ -1282,14 +1263,6 @@
12821263 */
12831264 #define snd_pcm_substream_sgbuf(substream) \
12841265 snd_pcm_get_dma_buf(substream)->private_data
1285
-
1286
-struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream,
1287
- unsigned long offset);
1288
-#else /* !SND_DMA_SGBUF */
1289
-/*
1290
- * fake using a continuous buffer
1291
- */
1292
-#define snd_pcm_sgbuf_ops_page NULL
12931266 #endif /* SND_DMA_SGBUF */
12941267
12951268 /**
....@@ -1315,8 +1288,8 @@
13151288 }
13161289
13171290 /**
1318
- * snd_pcm_sgbuf_chunk_size - Compute the max size that fits within the contig.
1319
- * page from the given size
1291
+ * snd_pcm_sgbuf_get_chunk_size - Compute the max size that fits within the
1292
+ * contig. page from the given size
13201293 * @substream: PCM substream
13211294 * @ofs: byte offset
13221295 * @size: byte size to examine
....@@ -1381,8 +1354,6 @@
13811354 (IEC958_AES1_CON_ORIGINAL<<8)|\
13821355 (IEC958_AES1_CON_PCM_CODER<<8)|\
13831356 (IEC958_AES3_CON_FS_48000<<24))
1384
-
1385
-#define PCM_RUNTIME_CHECK(sub) snd_BUG_ON(!(sub) || !(sub)->runtime)
13861357
13871358 const char *snd_pcm_format_name(snd_pcm_format_t format);
13881359
....@@ -1460,55 +1431,16 @@
14601431 return 1ULL << (__force int) pcm_format;
14611432 }
14621433
1463
-/*
1464
- * PCM Volume control API
1434
+/**
1435
+ * pcm_for_each_format - helper to iterate for each format type
1436
+ * @f: the iterator variable in snd_pcm_format_t type
14651437 */
1466
-/* array element of volume */
1467
-struct snd_pcm_volume_elem {
1468
- int volume;
1469
-};
1438
+#define pcm_for_each_format(f) \
1439
+ for ((f) = SNDRV_PCM_FORMAT_FIRST; \
1440
+ (__force int)(f) <= (__force int)SNDRV_PCM_FORMAT_LAST; \
1441
+ (f) = (__force snd_pcm_format_t)((__force int)(f) + 1))
14701442
1471
-/* pp information; retrieved via snd_kcontrol_chip() */
1472
-struct snd_pcm_volume {
1473
- struct snd_pcm *pcm; /* assigned PCM instance */
1474
- int stream; /* PLAYBACK or CAPTURE */
1475
- struct snd_kcontrol *kctl;
1476
- const struct snd_pcm_volume_elem *volume;
1477
- int max_length;
1478
- void *private_data; /* optional: private data pointer */
1479
-};
1480
-
1481
-int snd_pcm_add_volume_ctls(struct snd_pcm *pcm, int stream,
1482
- const struct snd_pcm_volume_elem *volume,
1483
- int max_length,
1484
- unsigned long private_value,
1485
- struct snd_pcm_volume **info_ret);
1486
-
1487
-/*
1488
- * PCM User control API
1489
- */
1490
-/* array element of usr elem */
1491
-struct snd_pcm_usr_elem {
1492
- int val[128];
1493
-};
1494
-
1495
-/* pp information; retrieved via snd_kcontrol_chip() */
1496
-struct snd_pcm_usr {
1497
- struct snd_pcm *pcm; /* assigned PCM instance */
1498
- int stream; /* PLAYBACK or CAPTURE */
1499
- struct snd_kcontrol *kctl;
1500
- const struct snd_pcm_usr_elem *usr;
1501
- int max_length;
1502
- void *private_data; /* optional: private data pointer */
1503
-};
1504
-
1505
-int snd_pcm_add_usr_ctls(struct snd_pcm *pcm, int stream,
1506
- const struct snd_pcm_usr_elem *usr,
1507
- int max_length, int max_control_str_len,
1508
- unsigned long private_value,
1509
- struct snd_pcm_usr **info_ret);
1510
-
1511
-#ifdef CONFIG_SND_SOC_ROCKCHIP_VAD
1443
+#if IS_ENABLED(CONFIG_SND_SOC_ROCKCHIP_VAD)
15121444 /**
15131445 * snd_pcm_vad_read - Read raw pcm data from vad buffer
15141446 * @substream: PCM substream instance
....@@ -1562,4 +1494,55 @@
15621494 #define pcm_dbg(pcm, fmt, args...) \
15631495 dev_dbg((pcm)->card->dev, fmt, ##args)
15641496
1497
+struct snd_pcm_status64 {
1498
+ snd_pcm_state_t state; /* stream state */
1499
+ u8 rsvd[4];
1500
+ s64 trigger_tstamp_sec; /* time when stream was started/stopped/paused */
1501
+ s64 trigger_tstamp_nsec;
1502
+ s64 tstamp_sec; /* reference timestamp */
1503
+ s64 tstamp_nsec;
1504
+ snd_pcm_uframes_t appl_ptr; /* appl ptr */
1505
+ snd_pcm_uframes_t hw_ptr; /* hw ptr */
1506
+ snd_pcm_sframes_t delay; /* current delay in frames */
1507
+ snd_pcm_uframes_t avail; /* number of frames available */
1508
+ snd_pcm_uframes_t avail_max; /* max frames available on hw since last status */
1509
+ snd_pcm_uframes_t overrange; /* count of ADC (capture) overrange detections from last status */
1510
+ snd_pcm_state_t suspended_state; /* suspended stream state */
1511
+ __u32 audio_tstamp_data; /* needed for 64-bit alignment, used for configs/report to/from userspace */
1512
+ s64 audio_tstamp_sec; /* sample counter, wall clock, PHC or on-demand sync'ed */
1513
+ s64 audio_tstamp_nsec;
1514
+ s64 driver_tstamp_sec; /* useful in case reference system tstamp is reported with delay */
1515
+ s64 driver_tstamp_nsec;
1516
+ __u32 audio_tstamp_accuracy; /* in ns units, only valid if indicated in audio_tstamp_data */
1517
+ unsigned char reserved[52-4*sizeof(s64)]; /* must be filled with zero */
1518
+};
1519
+
1520
+#define SNDRV_PCM_IOCTL_STATUS64 _IOR('A', 0x20, struct snd_pcm_status64)
1521
+#define SNDRV_PCM_IOCTL_STATUS_EXT64 _IOWR('A', 0x24, struct snd_pcm_status64)
1522
+
1523
+struct snd_pcm_status32 {
1524
+ snd_pcm_state_t state; /* stream state */
1525
+ s32 trigger_tstamp_sec; /* time when stream was started/stopped/paused */
1526
+ s32 trigger_tstamp_nsec;
1527
+ s32 tstamp_sec; /* reference timestamp */
1528
+ s32 tstamp_nsec;
1529
+ u32 appl_ptr; /* appl ptr */
1530
+ u32 hw_ptr; /* hw ptr */
1531
+ s32 delay; /* current delay in frames */
1532
+ u32 avail; /* number of frames available */
1533
+ u32 avail_max; /* max frames available on hw since last status */
1534
+ u32 overrange; /* count of ADC (capture) overrange detections from last status */
1535
+ snd_pcm_state_t suspended_state; /* suspended stream state */
1536
+ u32 audio_tstamp_data; /* needed for 64-bit alignment, used for configs/report to/from userspace */
1537
+ s32 audio_tstamp_sec; /* sample counter, wall clock, PHC or on-demand sync'ed */
1538
+ s32 audio_tstamp_nsec;
1539
+ s32 driver_tstamp_sec; /* useful in case reference system tstamp is reported with delay */
1540
+ s32 driver_tstamp_nsec;
1541
+ u32 audio_tstamp_accuracy; /* in ns units, only valid if indicated in audio_tstamp_data */
1542
+ unsigned char reserved[52-4*sizeof(s32)]; /* must be filled with zero */
1543
+};
1544
+
1545
+#define SNDRV_PCM_IOCTL_STATUS32 _IOR('A', 0x20, struct snd_pcm_status32)
1546
+#define SNDRV_PCM_IOCTL_STATUS_EXT32 _IOWR('A', 0x24, struct snd_pcm_status32)
1547
+
15651548 #endif /* __SOUND_PCM_H */