gus_dram.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (c) by Jaroslav Kysela <perex@suse.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. #include <sound/driver.h>
  22. #include <linux/time.h>
  23. #include <sound/core.h>
  24. #include <sound/gus.h>
  25. #include <sound/info.h>
  26. static int snd_gus_dram_poke(struct snd_gus_card *gus, char __user *_buffer,
  27. unsigned int address, unsigned int size)
  28. {
  29. unsigned long flags;
  30. unsigned int size1, size2;
  31. char buffer[256], *pbuffer;
  32. while (size > 0) {
  33. size1 = size > sizeof(buffer) ? sizeof(buffer) : size;
  34. if (copy_from_user(buffer, _buffer, size1))
  35. return -EFAULT;
  36. if (gus->interwave) {
  37. spin_lock_irqsave(&gus->reg_lock, flags);
  38. snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x01);
  39. snd_gf1_dram_addr(gus, address);
  40. outsb(GUSP(gus, DRAM), buffer, size1);
  41. spin_unlock_irqrestore(&gus->reg_lock, flags);
  42. address += size1;
  43. } else {
  44. pbuffer = buffer;
  45. size2 = size1;
  46. while (size2--)
  47. snd_gf1_poke(gus, address++, *pbuffer++);
  48. }
  49. size -= size1;
  50. _buffer += size1;
  51. }
  52. return 0;
  53. }
  54. int snd_gus_dram_write(struct snd_gus_card *gus, char __user *buffer,
  55. unsigned int address, unsigned int size)
  56. {
  57. return snd_gus_dram_poke(gus, buffer, address, size);
  58. }
  59. static int snd_gus_dram_peek(struct snd_gus_card *gus, char __user *_buffer,
  60. unsigned int address, unsigned int size,
  61. int rom)
  62. {
  63. unsigned long flags;
  64. unsigned int size1, size2;
  65. char buffer[256], *pbuffer;
  66. while (size > 0) {
  67. size1 = size > sizeof(buffer) ? sizeof(buffer) : size;
  68. if (gus->interwave) {
  69. spin_lock_irqsave(&gus->reg_lock, flags);
  70. snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, rom ? 0x03 : 0x01);
  71. snd_gf1_dram_addr(gus, address);
  72. insb(GUSP(gus, DRAM), buffer, size1);
  73. snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x01);
  74. spin_unlock_irqrestore(&gus->reg_lock, flags);
  75. address += size1;
  76. } else {
  77. pbuffer = buffer;
  78. size2 = size1;
  79. while (size2--)
  80. *pbuffer++ = snd_gf1_peek(gus, address++);
  81. }
  82. if (copy_to_user(_buffer, buffer, size1))
  83. return -EFAULT;
  84. size -= size1;
  85. _buffer += size1;
  86. }
  87. return 0;
  88. }
  89. int snd_gus_dram_read(struct snd_gus_card *gus, char __user *buffer,
  90. unsigned int address, unsigned int size,
  91. int rom)
  92. {
  93. return snd_gus_dram_peek(gus, buffer, address, size, rom);
  94. }