sound_firmware.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:2k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. #include "os.h"
  2. #define __KERNEL_SYSCALLS__
  3. #include <linux/module.h>
  4. #include <linux/fs.h>
  5. #include <linux/mm.h>
  6. #include <linux/slab.h>
  7. #include <linux/unistd.h>
  8. #include <asm/uaccess.h>
  9. static int errno;
  10. static int do_mod_firmware_load(const char *fn, char **fp)
  11. {
  12. int fd;
  13. long l;
  14. char *dp;
  15. fd = open(fn, 0, 0);
  16. if (fd == -1)
  17. {
  18. printk(KERN_INFO "Unable to load '%s'.n", fn);
  19. return 0;
  20. }
  21. l = lseek(fd, 0L, 2);
  22. if (l <= 0 || l > 131072)
  23. {
  24. printk(KERN_INFO "Invalid firmware '%s'n", fn);
  25. sys_close(fd);
  26. return 0;
  27. }
  28. lseek(fd, 0L, 0);
  29. dp = vmalloc(l);
  30. if (dp == NULL)
  31. {
  32. printk(KERN_INFO "Out of memory loading '%s'.n", fn);
  33. sys_close(fd);
  34. return 0;
  35. }
  36. if (read(fd, dp, l) != l)
  37. {
  38. printk(KERN_INFO "Failed to read '%s'.n", fn);
  39. vfree(dp);
  40. sys_close(fd);
  41. return 0;
  42. }
  43. close(fd);
  44. *fp = dp;
  45. return (int) l;
  46. }
  47. /**
  48.  * mod_firmware_load - load sound driver firmware
  49.  * @fn: filename
  50.  * @fp: return for the buffer.
  51.  *
  52.  * Load the firmware for a sound module (up to 128K) into a buffer.
  53.  * The buffer is returned in *fp. It is allocated with vmalloc so is
  54.  * virtually linear and not DMAable. The caller should free it with
  55.  * vfree when finished.
  56.  *
  57.  * The length of the buffer is returned on a successful load, the
  58.  * value zero on a failure.
  59.  *
  60.  * Caution: This API is not recommended. Firmware should be loaded via
  61.  * an ioctl call and a setup application. This function may disappear
  62.  * in future.
  63.  */
  64.  
  65. int mod_firmware_load(const char *fn, char **fp)
  66. {
  67. int r;
  68. mm_segment_t fs = get_fs();
  69. set_fs(get_ds());
  70. r = do_mod_firmware_load(fn, fp);
  71. set_fs(fs);
  72. return r;
  73. }