xref: /kernel/linux/linux-6.6/include/sound/info.h (revision 62306a36)
162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci#ifndef __SOUND_INFO_H
362306a36Sopenharmony_ci#define __SOUND_INFO_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci/*
662306a36Sopenharmony_ci *  Header file for info interface
762306a36Sopenharmony_ci *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include <linux/poll.h>
1162306a36Sopenharmony_ci#include <linux/seq_file.h>
1262306a36Sopenharmony_ci#include <sound/core.h>
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci/* buffer for information */
1562306a36Sopenharmony_cistruct snd_info_buffer {
1662306a36Sopenharmony_ci	char *buffer;		/* pointer to begin of buffer */
1762306a36Sopenharmony_ci	unsigned int curr;	/* current position in buffer */
1862306a36Sopenharmony_ci	unsigned int size;	/* current size */
1962306a36Sopenharmony_ci	unsigned int len;	/* total length of buffer */
2062306a36Sopenharmony_ci	int stop;		/* stop flag */
2162306a36Sopenharmony_ci	int error;		/* error code */
2262306a36Sopenharmony_ci};
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci#define SNDRV_INFO_CONTENT_TEXT		0
2562306a36Sopenharmony_ci#define SNDRV_INFO_CONTENT_DATA		1
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_cistruct snd_info_entry;
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_cistruct snd_info_entry_text {
3062306a36Sopenharmony_ci	void (*read)(struct snd_info_entry *entry,
3162306a36Sopenharmony_ci		     struct snd_info_buffer *buffer);
3262306a36Sopenharmony_ci	void (*write)(struct snd_info_entry *entry,
3362306a36Sopenharmony_ci		      struct snd_info_buffer *buffer);
3462306a36Sopenharmony_ci};
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_cistruct snd_info_entry_ops {
3762306a36Sopenharmony_ci	int (*open)(struct snd_info_entry *entry,
3862306a36Sopenharmony_ci		    unsigned short mode, void **file_private_data);
3962306a36Sopenharmony_ci	int (*release)(struct snd_info_entry *entry,
4062306a36Sopenharmony_ci		       unsigned short mode, void *file_private_data);
4162306a36Sopenharmony_ci	ssize_t (*read)(struct snd_info_entry *entry, void *file_private_data,
4262306a36Sopenharmony_ci			struct file *file, char __user *buf,
4362306a36Sopenharmony_ci			size_t count, loff_t pos);
4462306a36Sopenharmony_ci	ssize_t (*write)(struct snd_info_entry *entry, void *file_private_data,
4562306a36Sopenharmony_ci			 struct file *file, const char __user *buf,
4662306a36Sopenharmony_ci			 size_t count, loff_t pos);
4762306a36Sopenharmony_ci	loff_t (*llseek)(struct snd_info_entry *entry,
4862306a36Sopenharmony_ci			 void *file_private_data, struct file *file,
4962306a36Sopenharmony_ci			 loff_t offset, int orig);
5062306a36Sopenharmony_ci	__poll_t (*poll)(struct snd_info_entry *entry,
5162306a36Sopenharmony_ci			     void *file_private_data, struct file *file,
5262306a36Sopenharmony_ci			     poll_table *wait);
5362306a36Sopenharmony_ci	int (*ioctl)(struct snd_info_entry *entry, void *file_private_data,
5462306a36Sopenharmony_ci		     struct file *file, unsigned int cmd, unsigned long arg);
5562306a36Sopenharmony_ci	int (*mmap)(struct snd_info_entry *entry, void *file_private_data,
5662306a36Sopenharmony_ci		    struct inode *inode, struct file *file,
5762306a36Sopenharmony_ci		    struct vm_area_struct *vma);
5862306a36Sopenharmony_ci};
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_cistruct snd_info_entry {
6162306a36Sopenharmony_ci	const char *name;
6262306a36Sopenharmony_ci	umode_t mode;
6362306a36Sopenharmony_ci	long size;
6462306a36Sopenharmony_ci	unsigned short content;
6562306a36Sopenharmony_ci	union {
6662306a36Sopenharmony_ci		struct snd_info_entry_text text;
6762306a36Sopenharmony_ci		const struct snd_info_entry_ops *ops;
6862306a36Sopenharmony_ci	} c;
6962306a36Sopenharmony_ci	struct snd_info_entry *parent;
7062306a36Sopenharmony_ci	struct module *module;
7162306a36Sopenharmony_ci	void *private_data;
7262306a36Sopenharmony_ci	void (*private_free)(struct snd_info_entry *entry);
7362306a36Sopenharmony_ci	struct proc_dir_entry *p;
7462306a36Sopenharmony_ci	struct mutex access;
7562306a36Sopenharmony_ci	struct list_head children;
7662306a36Sopenharmony_ci	struct list_head list;
7762306a36Sopenharmony_ci};
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci#if defined(CONFIG_SND_OSSEMUL) && defined(CONFIG_SND_PROC_FS)
8062306a36Sopenharmony_ciint snd_info_minor_register(void);
8162306a36Sopenharmony_ci#else
8262306a36Sopenharmony_ci#define snd_info_minor_register()	0
8362306a36Sopenharmony_ci#endif
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci#ifdef CONFIG_SND_PROC_FS
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ciextern struct snd_info_entry *snd_seq_root;
8962306a36Sopenharmony_ci#ifdef CONFIG_SND_OSSEMUL
9062306a36Sopenharmony_ciextern struct snd_info_entry *snd_oss_root;
9162306a36Sopenharmony_civoid snd_card_info_read_oss(struct snd_info_buffer *buffer);
9262306a36Sopenharmony_ci#else
9362306a36Sopenharmony_ci#define snd_oss_root NULL
9462306a36Sopenharmony_cistatic inline void snd_card_info_read_oss(struct snd_info_buffer *buffer) {}
9562306a36Sopenharmony_ci#endif
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci/**
9862306a36Sopenharmony_ci * snd_iprintf - printf on the procfs buffer
9962306a36Sopenharmony_ci * @buf: the procfs buffer
10062306a36Sopenharmony_ci * @fmt: the printf format
10162306a36Sopenharmony_ci *
10262306a36Sopenharmony_ci * Outputs the string on the procfs buffer just like printf().
10362306a36Sopenharmony_ci *
10462306a36Sopenharmony_ci * Return: zero for success, or a negative error code.
10562306a36Sopenharmony_ci */
10662306a36Sopenharmony_ci#define snd_iprintf(buf, fmt, args...) \
10762306a36Sopenharmony_ci	seq_printf((struct seq_file *)(buf)->buffer, fmt, ##args)
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ciint snd_info_init(void);
11062306a36Sopenharmony_ciint snd_info_done(void);
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ciint snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len);
11362306a36Sopenharmony_ciconst char *snd_info_get_str(char *dest, const char *src, int len);
11462306a36Sopenharmony_cistruct snd_info_entry *snd_info_create_module_entry(struct module *module,
11562306a36Sopenharmony_ci					       const char *name,
11662306a36Sopenharmony_ci					       struct snd_info_entry *parent);
11762306a36Sopenharmony_cistruct snd_info_entry *snd_info_create_card_entry(struct snd_card *card,
11862306a36Sopenharmony_ci					     const char *name,
11962306a36Sopenharmony_ci					     struct snd_info_entry *parent);
12062306a36Sopenharmony_civoid snd_info_free_entry(struct snd_info_entry *entry);
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ciint snd_info_card_create(struct snd_card *card);
12362306a36Sopenharmony_ciint snd_info_card_register(struct snd_card *card);
12462306a36Sopenharmony_ciint snd_info_card_free(struct snd_card *card);
12562306a36Sopenharmony_civoid snd_info_card_disconnect(struct snd_card *card);
12662306a36Sopenharmony_civoid snd_info_card_id_change(struct snd_card *card);
12762306a36Sopenharmony_ciint snd_info_register(struct snd_info_entry *entry);
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ci/* for card drivers */
13062306a36Sopenharmony_cistatic inline int snd_card_proc_new(struct snd_card *card, const char *name,
13162306a36Sopenharmony_ci				    struct snd_info_entry **entryp)
13262306a36Sopenharmony_ci{
13362306a36Sopenharmony_ci	*entryp = snd_info_create_card_entry(card, name, card->proc_root);
13462306a36Sopenharmony_ci	return *entryp ? 0 : -ENOMEM;
13562306a36Sopenharmony_ci}
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_cistatic inline void snd_info_set_text_ops(struct snd_info_entry *entry,
13862306a36Sopenharmony_ci	void *private_data,
13962306a36Sopenharmony_ci	void (*read)(struct snd_info_entry *, struct snd_info_buffer *))
14062306a36Sopenharmony_ci{
14162306a36Sopenharmony_ci	entry->private_data = private_data;
14262306a36Sopenharmony_ci	entry->c.text.read = read;
14362306a36Sopenharmony_ci}
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ciint snd_card_rw_proc_new(struct snd_card *card, const char *name,
14662306a36Sopenharmony_ci			 void *private_data,
14762306a36Sopenharmony_ci			 void (*read)(struct snd_info_entry *,
14862306a36Sopenharmony_ci				      struct snd_info_buffer *),
14962306a36Sopenharmony_ci			 void (*write)(struct snd_info_entry *entry,
15062306a36Sopenharmony_ci				       struct snd_info_buffer *buffer));
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ciint snd_info_check_reserved_words(const char *str);
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_ci#else
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_ci#define snd_seq_root NULL
15762306a36Sopenharmony_ci#define snd_oss_root NULL
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_cistatic inline int snd_iprintf(struct snd_info_buffer *buffer, char *fmt, ...) { return 0; }
16062306a36Sopenharmony_cistatic inline int snd_info_init(void) { return 0; }
16162306a36Sopenharmony_cistatic inline int snd_info_done(void) { return 0; }
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_cistatic inline int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len) { return 0; }
16462306a36Sopenharmony_cistatic inline char *snd_info_get_str(char *dest, char *src, int len) { return NULL; }
16562306a36Sopenharmony_cistatic inline struct snd_info_entry *snd_info_create_module_entry(struct module *module, const char *name, struct snd_info_entry *parent) { return NULL; }
16662306a36Sopenharmony_cistatic inline struct snd_info_entry *snd_info_create_card_entry(struct snd_card *card, const char *name, struct snd_info_entry *parent) { return NULL; }
16762306a36Sopenharmony_cistatic inline void snd_info_free_entry(struct snd_info_entry *entry) { ; }
16862306a36Sopenharmony_ci
16962306a36Sopenharmony_cistatic inline int snd_info_card_create(struct snd_card *card) { return 0; }
17062306a36Sopenharmony_cistatic inline int snd_info_card_register(struct snd_card *card) { return 0; }
17162306a36Sopenharmony_cistatic inline int snd_info_card_free(struct snd_card *card) { return 0; }
17262306a36Sopenharmony_cistatic inline void snd_info_card_disconnect(struct snd_card *card) { }
17362306a36Sopenharmony_cistatic inline void snd_info_card_id_change(struct snd_card *card) { }
17462306a36Sopenharmony_cistatic inline int snd_info_register(struct snd_info_entry *entry) { return 0; }
17562306a36Sopenharmony_ci
17662306a36Sopenharmony_cistatic inline int snd_card_proc_new(struct snd_card *card, const char *name,
17762306a36Sopenharmony_ci				    struct snd_info_entry **entryp) { return -EINVAL; }
17862306a36Sopenharmony_cistatic inline void snd_info_set_text_ops(struct snd_info_entry *entry __attribute__((unused)),
17962306a36Sopenharmony_ci					 void *private_data,
18062306a36Sopenharmony_ci					 void (*read)(struct snd_info_entry *, struct snd_info_buffer *)) {}
18162306a36Sopenharmony_cistatic inline int snd_card_rw_proc_new(struct snd_card *card, const char *name,
18262306a36Sopenharmony_ci				       void *private_data,
18362306a36Sopenharmony_ci				       void (*read)(struct snd_info_entry *,
18462306a36Sopenharmony_ci						    struct snd_info_buffer *),
18562306a36Sopenharmony_ci				       void (*write)(struct snd_info_entry *entry,
18662306a36Sopenharmony_ci						     struct snd_info_buffer *buffer))
18762306a36Sopenharmony_ci{
18862306a36Sopenharmony_ci	return 0;
18962306a36Sopenharmony_ci}
19062306a36Sopenharmony_cistatic inline int snd_info_check_reserved_words(const char *str) { return 1; }
19162306a36Sopenharmony_ci
19262306a36Sopenharmony_ci#endif
19362306a36Sopenharmony_ci
19462306a36Sopenharmony_ci/**
19562306a36Sopenharmony_ci * snd_card_ro_proc_new - Create a read-only text proc file entry for the card
19662306a36Sopenharmony_ci * @card: the card instance
19762306a36Sopenharmony_ci * @name: the file name
19862306a36Sopenharmony_ci * @private_data: the arbitrary private data
19962306a36Sopenharmony_ci * @read: the read callback
20062306a36Sopenharmony_ci *
20162306a36Sopenharmony_ci * This proc file entry will be registered via snd_card_register() call, and
20262306a36Sopenharmony_ci * it will be removed automatically at the card removal, too.
20362306a36Sopenharmony_ci */
20462306a36Sopenharmony_cistatic inline int
20562306a36Sopenharmony_cisnd_card_ro_proc_new(struct snd_card *card, const char *name,
20662306a36Sopenharmony_ci		     void *private_data,
20762306a36Sopenharmony_ci		     void (*read)(struct snd_info_entry *,
20862306a36Sopenharmony_ci				  struct snd_info_buffer *))
20962306a36Sopenharmony_ci{
21062306a36Sopenharmony_ci	return snd_card_rw_proc_new(card, name, private_data, read, NULL);
21162306a36Sopenharmony_ci}
21262306a36Sopenharmony_ci
21362306a36Sopenharmony_ci/*
21462306a36Sopenharmony_ci * OSS info part
21562306a36Sopenharmony_ci */
21662306a36Sopenharmony_ci
21762306a36Sopenharmony_ci#if defined(CONFIG_SND_OSSEMUL) && defined(CONFIG_SND_PROC_FS)
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_ci#define SNDRV_OSS_INFO_DEV_AUDIO	0
22062306a36Sopenharmony_ci#define SNDRV_OSS_INFO_DEV_SYNTH	1
22162306a36Sopenharmony_ci#define SNDRV_OSS_INFO_DEV_MIDI		2
22262306a36Sopenharmony_ci#define SNDRV_OSS_INFO_DEV_TIMERS	4
22362306a36Sopenharmony_ci#define SNDRV_OSS_INFO_DEV_MIXERS	5
22462306a36Sopenharmony_ci
22562306a36Sopenharmony_ci#define SNDRV_OSS_INFO_DEV_COUNT	6
22662306a36Sopenharmony_ci
22762306a36Sopenharmony_ciint snd_oss_info_register(int dev, int num, char *string);
22862306a36Sopenharmony_ci#define snd_oss_info_unregister(dev, num) snd_oss_info_register(dev, num, NULL)
22962306a36Sopenharmony_ci
23062306a36Sopenharmony_ci#endif /* CONFIG_SND_OSSEMUL && CONFIG_SND_PROC_FS */
23162306a36Sopenharmony_ci
23262306a36Sopenharmony_ci#endif /* __SOUND_INFO_H */
233