File Index
Files and directories
Sign in
FILE

opl4_proc.c

File preview with syntax highlighting.

linux-6.19.14/sound/drivers/opl4/opl4_proc.c C
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 * Functions for the OPL4 proc file
  4 * Copyright (c) 2003 by Clemens Ladisch <clemens@ladisch.de>
  5 */
  6
  7#include "opl4_local.h"
  8#include <linux/vmalloc.h>
  9#include <linux/export.h>
 10#include <sound/info.h>
 11
 12static int snd_opl4_mem_proc_open(struct snd_info_entry *entry,
 13				  unsigned short mode, void **file_private_data)
 14{
 15	struct snd_opl4 *opl4 = entry->private_data;
 16
 17	guard(mutex)(&opl4->access_mutex);
 18	if (opl4->memory_access)
 19		return -EBUSY;
 20	opl4->memory_access++;
 21	return 0;
 22}
 23
 24static int snd_opl4_mem_proc_release(struct snd_info_entry *entry,
 25				     unsigned short mode, void *file_private_data)
 26{
 27	struct snd_opl4 *opl4 = entry->private_data;
 28
 29	guard(mutex)(&opl4->access_mutex);
 30	opl4->memory_access--;
 31	return 0;
 32}
 33
 34static ssize_t snd_opl4_mem_proc_read(struct snd_info_entry *entry,
 35				      void *file_private_data,
 36				      struct file *file, char __user *_buf,
 37				      size_t count, loff_t pos)
 38{
 39	struct snd_opl4 *opl4 = entry->private_data;
 40	char* buf;
 41
 42	buf = vmalloc(count);
 43	if (!buf)
 44		return -ENOMEM;
 45	snd_opl4_read_memory(opl4, buf, pos, count);
 46	if (copy_to_user(_buf, buf, count)) {
 47		vfree(buf);
 48		return -EFAULT;
 49	}
 50	vfree(buf);
 51	return count;
 52}
 53
 54static ssize_t snd_opl4_mem_proc_write(struct snd_info_entry *entry,
 55				       void *file_private_data,
 56				       struct file *file,
 57				       const char __user *_buf,
 58				       size_t count, loff_t pos)
 59{
 60	struct snd_opl4 *opl4 = entry->private_data;
 61	char *buf;
 62
 63	buf = vmalloc(count);
 64	if (!buf)
 65		return -ENOMEM;
 66	if (copy_from_user(buf, _buf, count)) {
 67		vfree(buf);
 68		return -EFAULT;
 69	}
 70	snd_opl4_write_memory(opl4, buf, pos, count);
 71	vfree(buf);
 72	return count;
 73}
 74
 75static const struct snd_info_entry_ops snd_opl4_mem_proc_ops = {
 76	.open = snd_opl4_mem_proc_open,
 77	.release = snd_opl4_mem_proc_release,
 78	.read = snd_opl4_mem_proc_read,
 79	.write = snd_opl4_mem_proc_write,
 80};
 81
 82int snd_opl4_create_proc(struct snd_opl4 *opl4)
 83{
 84	struct snd_info_entry *entry;
 85
 86	entry = snd_info_create_card_entry(opl4->card, "opl4-mem", opl4->card->proc_root);
 87	if (entry) {
 88		if (opl4->hardware < OPL3_HW_OPL4_ML) {
 89			/* OPL4 can access 4 MB external ROM/SRAM */
 90			entry->mode |= 0200;
 91			entry->size = 4 * 1024 * 1024;
 92		} else {
 93			/* OPL4-ML has 1 MB internal ROM */
 94			entry->size = 1 * 1024 * 1024;
 95		}
 96		entry->content = SNDRV_INFO_CONTENT_DATA;
 97		entry->c.ops = &snd_opl4_mem_proc_ops;
 98		entry->module = THIS_MODULE;
 99		entry->private_data = opl4;
100	}
101	opl4->proc_entry = entry;
102	return 0;
103}
104
105void snd_opl4_free_proc(struct snd_opl4 *opl4)
106{
107	snd_info_free_entry(opl4->proc_entry);
108}
~/ Read-only file preview.