Linux Audio

Check our new training course

Loading...
v4.10.11
 
  1/*
  2 *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  3 *  DRAM access routines
  4 *
  5 *
  6 *   This program is free software; you can redistribute it and/or modify
  7 *   it under the terms of the GNU General Public License as published by
  8 *   the Free Software Foundation; either version 2 of the License, or
  9 *   (at your option) any later version.
 10 *
 11 *   This program is distributed in the hope that it will be useful,
 12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14 *   GNU General Public License for more details.
 15 *
 16 *   You should have received a copy of the GNU General Public License
 17 *   along with this program; if not, write to the Free Software
 18 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 19 *
 20 */
 21
 22#include <linux/time.h>
 23#include <sound/core.h>
 24#include <sound/gus.h>
 25#include <sound/info.h>
 26
 27
 28static int snd_gus_dram_poke(struct snd_gus_card *gus, char __user *_buffer,
 29			     unsigned int address, unsigned int size)
 30{
 31	unsigned long flags;
 32	unsigned int size1, size2;
 33	char buffer[256], *pbuffer;
 34
 35	while (size > 0) {
 36		size1 = size > sizeof(buffer) ? sizeof(buffer) : size;
 37		if (copy_from_user(buffer, _buffer, size1))
 38			return -EFAULT;
 39		if (gus->interwave) {
 40			spin_lock_irqsave(&gus->reg_lock, flags);
 41			snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x01);
 42			snd_gf1_dram_addr(gus, address);
 43			outsb(GUSP(gus, DRAM), buffer, size1);
 44			spin_unlock_irqrestore(&gus->reg_lock, flags);
 45			address += size1;
 46		} else {
 47			pbuffer = buffer;
 48			size2 = size1;
 49			while (size2--)
 50				snd_gf1_poke(gus, address++, *pbuffer++);
 51		}
 52		size -= size1;
 53		_buffer += size1;
 54	}
 55	return 0;
 56}
 57
 58
 59int snd_gus_dram_write(struct snd_gus_card *gus, char __user *buffer,
 60		       unsigned int address, unsigned int size)
 61{
 62	return snd_gus_dram_poke(gus, buffer, address, size);
 63}
 64
 65static int snd_gus_dram_peek(struct snd_gus_card *gus, char __user *_buffer,
 66			     unsigned int address, unsigned int size,
 67			     int rom)
 68{
 69	unsigned long flags;
 70	unsigned int size1, size2;
 71	char buffer[256], *pbuffer;
 72
 73	while (size > 0) {
 74		size1 = size > sizeof(buffer) ? sizeof(buffer) : size;
 75		if (gus->interwave) {
 76			spin_lock_irqsave(&gus->reg_lock, flags);
 77			snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, rom ? 0x03 : 0x01);
 78			snd_gf1_dram_addr(gus, address);
 79			insb(GUSP(gus, DRAM), buffer, size1);
 80			snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x01);
 81			spin_unlock_irqrestore(&gus->reg_lock, flags);
 82			address += size1;
 83		} else {
 84			pbuffer = buffer;
 85			size2 = size1;
 86			while (size2--)
 87				*pbuffer++ = snd_gf1_peek(gus, address++);
 88		}
 89		if (copy_to_user(_buffer, buffer, size1))
 90			return -EFAULT;
 91		size -= size1;
 92		_buffer += size1;
 93	}
 94	return 0;
 95}
 96
 97int snd_gus_dram_read(struct snd_gus_card *gus, char __user *buffer,
 98		      unsigned int address, unsigned int size,
 99		      int rom)
100{
101	return snd_gus_dram_peek(gus, buffer, address, size, rom);
102}
v5.9
 1// SPDX-License-Identifier: GPL-2.0-or-later
 2/*
 3 *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
 4 *  DRAM access routines
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 5 */
 6
 7#include <linux/time.h>
 8#include <sound/core.h>
 9#include <sound/gus.h>
10#include <sound/info.h>
11
12
13static int snd_gus_dram_poke(struct snd_gus_card *gus, char __user *_buffer,
14			     unsigned int address, unsigned int size)
15{
16	unsigned long flags;
17	unsigned int size1, size2;
18	char buffer[256], *pbuffer;
19
20	while (size > 0) {
21		size1 = size > sizeof(buffer) ? sizeof(buffer) : size;
22		if (copy_from_user(buffer, _buffer, size1))
23			return -EFAULT;
24		if (gus->interwave) {
25			spin_lock_irqsave(&gus->reg_lock, flags);
26			snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x01);
27			snd_gf1_dram_addr(gus, address);
28			outsb(GUSP(gus, DRAM), buffer, size1);
29			spin_unlock_irqrestore(&gus->reg_lock, flags);
30			address += size1;
31		} else {
32			pbuffer = buffer;
33			size2 = size1;
34			while (size2--)
35				snd_gf1_poke(gus, address++, *pbuffer++);
36		}
37		size -= size1;
38		_buffer += size1;
39	}
40	return 0;
41}
42
43
44int snd_gus_dram_write(struct snd_gus_card *gus, char __user *buffer,
45		       unsigned int address, unsigned int size)
46{
47	return snd_gus_dram_poke(gus, buffer, address, size);
48}
49
50static int snd_gus_dram_peek(struct snd_gus_card *gus, char __user *_buffer,
51			     unsigned int address, unsigned int size,
52			     int rom)
53{
54	unsigned long flags;
55	unsigned int size1, size2;
56	char buffer[256], *pbuffer;
57
58	while (size > 0) {
59		size1 = size > sizeof(buffer) ? sizeof(buffer) : size;
60		if (gus->interwave) {
61			spin_lock_irqsave(&gus->reg_lock, flags);
62			snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, rom ? 0x03 : 0x01);
63			snd_gf1_dram_addr(gus, address);
64			insb(GUSP(gus, DRAM), buffer, size1);
65			snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x01);
66			spin_unlock_irqrestore(&gus->reg_lock, flags);
67			address += size1;
68		} else {
69			pbuffer = buffer;
70			size2 = size1;
71			while (size2--)
72				*pbuffer++ = snd_gf1_peek(gus, address++);
73		}
74		if (copy_to_user(_buffer, buffer, size1))
75			return -EFAULT;
76		size -= size1;
77		_buffer += size1;
78	}
79	return 0;
80}
81
82int snd_gus_dram_read(struct snd_gus_card *gus, char __user *buffer,
83		      unsigned int address, unsigned int size,
84		      int rom)
85{
86	return snd_gus_dram_peek(gus, buffer, address, size, rom);
87}