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