gus_dram.c 2.9 KB

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