2019-05-27 08:55:05 +02:00
// SPDX-License-Identifier: GPL-2.0-or-later
2005-04-16 15:20:36 -07:00
/*
2007-10-15 09:50:19 +02:00
* Copyright ( c ) by Jaroslav Kysela < perex @ perex . cz >
2005-04-16 15:20:36 -07:00
* DRAM access routines
*/
# include <linux/time.h>
# include <sound/core.h>
# include <sound/gus.h>
# include <sound/info.h>
2005-11-17 14:36:44 +01:00
static int snd_gus_dram_poke ( struct snd_gus_card * gus , char __user * _buffer ,
2005-04-16 15:20:36 -07:00
unsigned int address , unsigned int size )
{
unsigned long flags ;
unsigned int size1 , size2 ;
char buffer [ 256 ] , * pbuffer ;
while ( size > 0 ) {
size1 = size > sizeof ( buffer ) ? sizeof ( buffer ) : size ;
if ( copy_from_user ( buffer , _buffer , size1 ) )
return - EFAULT ;
if ( gus - > interwave ) {
spin_lock_irqsave ( & gus - > reg_lock , flags ) ;
snd_gf1_write8 ( gus , SNDRV_GF1_GB_MEMORY_CONTROL , 0x01 ) ;
snd_gf1_dram_addr ( gus , address ) ;
outsb ( GUSP ( gus , DRAM ) , buffer , size1 ) ;
spin_unlock_irqrestore ( & gus - > reg_lock , flags ) ;
address + = size1 ;
} else {
pbuffer = buffer ;
size2 = size1 ;
while ( size2 - - )
snd_gf1_poke ( gus , address + + , * pbuffer + + ) ;
}
size - = size1 ;
_buffer + = size1 ;
}
return 0 ;
}
2005-11-17 14:36:44 +01:00
int snd_gus_dram_write ( struct snd_gus_card * gus , char __user * buffer ,
2005-04-16 15:20:36 -07:00
unsigned int address , unsigned int size )
{
return snd_gus_dram_poke ( gus , buffer , address , size ) ;
}
2005-11-17 14:36:44 +01:00
static int snd_gus_dram_peek ( struct snd_gus_card * gus , char __user * _buffer ,
2005-04-16 15:20:36 -07:00
unsigned int address , unsigned int size ,
int rom )
{
unsigned long flags ;
unsigned int size1 , size2 ;
char buffer [ 256 ] , * pbuffer ;
while ( size > 0 ) {
size1 = size > sizeof ( buffer ) ? sizeof ( buffer ) : size ;
if ( gus - > interwave ) {
spin_lock_irqsave ( & gus - > reg_lock , flags ) ;
snd_gf1_write8 ( gus , SNDRV_GF1_GB_MEMORY_CONTROL , rom ? 0x03 : 0x01 ) ;
snd_gf1_dram_addr ( gus , address ) ;
insb ( GUSP ( gus , DRAM ) , buffer , size1 ) ;
snd_gf1_write8 ( gus , SNDRV_GF1_GB_MEMORY_CONTROL , 0x01 ) ;
spin_unlock_irqrestore ( & gus - > reg_lock , flags ) ;
address + = size1 ;
} else {
pbuffer = buffer ;
size2 = size1 ;
while ( size2 - - )
* pbuffer + + = snd_gf1_peek ( gus , address + + ) ;
}
if ( copy_to_user ( _buffer , buffer , size1 ) )
return - EFAULT ;
size - = size1 ;
_buffer + = size1 ;
}
return 0 ;
}
2005-11-17 14:36:44 +01:00
int snd_gus_dram_read ( struct snd_gus_card * gus , char __user * buffer ,
2005-04-16 15:20:36 -07:00
unsigned int address , unsigned int size ,
int rom )
{
return snd_gus_dram_peek ( gus , buffer , address , size , rom ) ;
}