hda_hwdep.c 3.0 KB

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