hda_hwdep.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * HWDEP Interface for HD-audio codec
  3. *
  4. * Copyright (c) 2007 Takashi Iwai <tiwai@suse.de>
  5. *
  6. * This driver 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 driver 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. #include <sound/driver.h>
  21. #include <linux/init.h>
  22. #include <linux/slab.h>
  23. #include <linux/pci.h>
  24. #include <linux/compat.h>
  25. #include <linux/mutex.h>
  26. #include <sound/core.h>
  27. #include "hda_codec.h"
  28. #include "hda_local.h"
  29. #include <sound/hda_hwdep.h>
  30. /*
  31. * write/read an out-of-bound verb
  32. */
  33. static int verb_write_ioctl(struct hda_codec *codec,
  34. struct hda_verb_ioctl __user *arg)
  35. {
  36. u32 verb, res;
  37. if (get_user(verb, &arg->verb))
  38. return -EFAULT;
  39. res = snd_hda_codec_read(codec, verb >> 24, 0,
  40. (verb >> 8) & 0xffff, verb & 0xff);
  41. if (put_user(res, &arg->res))
  42. return -EFAULT;
  43. return 0;
  44. }
  45. static int get_wcap_ioctl(struct hda_codec *codec,
  46. struct hda_verb_ioctl __user *arg)
  47. {
  48. u32 verb, res;
  49. if (get_user(verb, &arg->verb))
  50. return -EFAULT;
  51. res = get_wcaps(codec, verb >> 24);
  52. if (put_user(res, &arg->res))
  53. return -EFAULT;
  54. return 0;
  55. }
  56. /*
  57. */
  58. static int hda_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
  59. unsigned int cmd, unsigned long arg)
  60. {
  61. struct hda_codec *codec = hw->private_data;
  62. void __user *argp = (void __user *)arg;
  63. switch (cmd) {
  64. case HDA_IOCTL_PVERSION:
  65. return put_user(HDA_HWDEP_VERSION, (int __user *)argp);
  66. case HDA_IOCTL_VERB_WRITE:
  67. return verb_write_ioctl(codec, argp);
  68. case HDA_IOCTL_GET_WCAP:
  69. return get_wcap_ioctl(codec, argp);
  70. }
  71. return -ENOIOCTLCMD;
  72. }
  73. #ifdef CONFIG_COMPAT
  74. static int hda_hwdep_ioctl_compat(struct snd_hwdep *hw, struct file *file,
  75. unsigned int cmd, unsigned long arg)
  76. {
  77. return hda_hwdep_ioctl(hw, file, cmd, (unsigned long)compat_ptr(arg));
  78. }
  79. #endif
  80. static int hda_hwdep_open(struct snd_hwdep *hw, struct file *file)
  81. {
  82. #ifndef CONFIG_SND_DEBUG_DETECT
  83. if (!capable(CAP_SYS_RAWIO))
  84. return -EACCES;
  85. #endif
  86. return 0;
  87. }
  88. int __devinit snd_hda_create_hwdep(struct hda_codec *codec)
  89. {
  90. char hwname[16];
  91. struct snd_hwdep *hwdep;
  92. int err;
  93. sprintf(hwname, "HDA Codec %d", codec->addr);
  94. err = snd_hwdep_new(codec->bus->card, hwname, codec->addr, &hwdep);
  95. if (err < 0)
  96. return err;
  97. codec->hwdep = hwdep;
  98. sprintf(hwdep->name, "HDA Codec %d", codec->addr);
  99. hwdep->iface = SNDRV_HWDEP_IFACE_HDA;
  100. hwdep->private_data = codec;
  101. hwdep->exclusive = 1;
  102. hwdep->ops.open = hda_hwdep_open;
  103. hwdep->ops.ioctl = hda_hwdep_ioctl;
  104. #ifdef CONFIG_COMPAT
  105. hwdep->ops.ioctl_compat = hda_hwdep_ioctl_compat;
  106. #endif
  107. return 0;
  108. }