~ubuntu-branches/ubuntu/oneiric/oss4/oneiric-proposed

« back to all changes in this revision

Viewing changes to setup/gen_driver_linux.inc

  • Committer: Bazaar Package Importer
  • Author(s): Stefano Rivera
  • Date: 2011-06-16 20:37:48 UTC
  • mfrom: (5.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110616203748-jbrxik6ql33z54co
Tags: 4.2-build2004-1ubuntu1
* Merge from Debian unstable.
  - Supports our current kernel (LP: #746048)
  Remaining changes:
  - debian/oss4-dkms.dkms.in: s/source/build/ in Kernel headers paths.
* ld-as-needed.patch: Re-order CC arguments to enable building with ld
  --as-needed (LP: #770972)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
static void
 
2
generate_driver (char *name, conf_t * conf, char *cfg_name, char *cfg_header,
 
3
                 char *dirname, char *topdir)
 
4
{
 
5
  /* Linux version */
 
6
 
 
7
  FILE *f, *src;
 
8
  char tmp[256], line[256], *p, *s;
 
9
  int i, n = 0;
 
10
  char *options[MAXOPTS];
 
11
  char *option_desc[MAXOPTS];
 
12
  char desc[65536];
 
13
  int nopts = 0;
 
14
 
 
15
  sprintf (tmp, "target/build/%s.c", name);
 
16
  if ((src = fopen (tmp, "w")) == NULL)
 
17
    {
 
18
      perror (tmp);
 
19
      exit (-1);
 
20
    }
 
21
 
 
22
  fprintf (src, "/*\n");
 
23
  fprintf (src, " * Automatically generated file - do not edit.\n");
 
24
  fprintf (src, " */\n");
 
25
 
 
26
  fprintf (src, "#define DRIVER_NAME\t%s\n", name);
 
27
  fprintf (src, "#define DRIVER_NICK\t\"%s\"\n", name);
 
28
  fprintf (src, "#define DRIVER_PURPOSE\t\"%s\"\n", conf->purpose);
 
29
  fprintf (src, "#define DRIVER_STR_INFO\t%s_str_info\n", name);
 
30
  fprintf (src, "#define DRIVER_ATTACH\t%s_attach\n", name);
 
31
  fprintf (src, "#define DRIVER_DETACH\t%s_detach\n", name);
 
32
  fprintf (src, "#define DRIVER_TYPE\tDRV_%s\n", conf->bus);
 
33
  fprintf (src, "\n");
 
34
 
 
35
/*
 
36
 * Handle driver specific configuration options
 
37
 */
 
38
  *desc = 0;
 
39
  sprintf (tmp, "%s/.params", dirname);
 
40
  if ((f = fopen (tmp, "r")) != NULL)
 
41
    {
 
42
      while (fgets (line, sizeof (line) - 1, f) != NULL)
 
43
        {
 
44
          p = line + strlen (line) - 1;
 
45
          if (*p == '\n')
 
46
            *p = 0;
 
47
 
 
48
          fprintf (src, "%s\n", line);
 
49
          if (strncmp (line, "int ", 4) == 0)
 
50
            {
 
51
              char *s = line + 4, *p = s;
 
52
 
 
53
              while (*p && *p != '=' && *p != ';')
 
54
                p++;
 
55
              *p = 0;
 
56
              if (nopts >= MAXOPTS)
 
57
                {
 
58
                  fprintf (stderr, "Too many options for driver '%s' (%d)\n",
 
59
                           name, nopts);
 
60
                  exit (-1);
 
61
                }
 
62
 
 
63
              if (nopts != 0 && *desc != 0)
 
64
                option_desc[nopts - 1] = strdup (desc);
 
65
              option_desc[nopts] = 0;
 
66
              options[nopts++] = strdup (s);
 
67
              *desc = 0;
 
68
            }
 
69
          else
 
70
            {
 
71
              char *s = line, *p;
 
72
              char tmp[4096];
 
73
              while (*s == ' ' || *s == '/' || *s == '*')
 
74
                s++;
 
75
 
 
76
              p = tmp;
 
77
 
 
78
              while (*s)
 
79
                {
 
80
                  if (*s == '"')
 
81
                    *p++ = '\\';
 
82
 
 
83
                  *p++ = *s++;;
 
84
                }
 
85
              *p = 0;
 
86
 
 
87
              p = desc + strlen (desc);
 
88
              sprintf (p, "\n\"%s\\n\"", tmp);
 
89
            }
 
90
        }
 
91
 
 
92
      fclose (f);
 
93
    }
 
94
 
 
95
  if (nopts > 0 && *desc != 0)
 
96
    option_desc[nopts - 1] = strdup (desc);
 
97
 
 
98
  if ((f = fopen ("devices.list", "r")) == NULL)
 
99
    {
 
100
      perror ("devices.list");
 
101
      exit (-1);
 
102
    }
 
103
 
 
104
  if (strcmp (conf->bus, "PCI") == 0)
 
105
    {
 
106
      fprintf (src, "#include <linux/mod_devicetable.h>\n\n");
 
107
      fprintf (src, "#include <linux/pci_ids.h>\n\n");
 
108
      fprintf (src, "static struct pci_device_id id_table[] = {\n");
 
109
 
 
110
      while (fgets (line, sizeof (line) - 1, f) != NULL)
 
111
        {
 
112
          int vendor, product;
 
113
          p = line + strlen (line) - 1;
 
114
          if (*p == '\n')
 
115
            *p = 0;
 
116
 
 
117
          p = line;
 
118
          while (*p && *p != '\t')
 
119
            p++;
 
120
          if (*p == '\t')
 
121
            *p++ = 0;
 
122
 
 
123
          if (strcmp (line, name) != 0)
 
124
            continue;
 
125
 
 
126
          n++;
 
127
 
 
128
          s = p;
 
129
          while (*p && *p != '\t')
 
130
            p++;
 
131
          if (*p == '\t')
 
132
            *p++ = 0;
 
133
 
 
134
          if (strncmp (s, "pci", 3) == 0)
 
135
            {
 
136
              if (sscanf (s + 3, "%x,%x", &vendor, &product) != 2)
 
137
                {
 
138
                  fprintf (stderr, "Bad PCI id %s\n", s);
 
139
                }
 
140
 
 
141
              fprintf (src,
 
142
                       "\t{.vendor=0x%x,\t.device=0x%x,\t.subvendor=PCI_ANY_ID,\t.subdevice=PCI_ANY_ID,\t.class=PCI_CLASS_MULTIMEDIA_AUDIO},\n",
 
143
                       vendor, product);
 
144
            }
 
145
 
 
146
        }
 
147
 
 
148
      fclose (f);
 
149
 
 
150
      fprintf (src, "\t{0}\n");
 
151
      fprintf (src, "};\n");
 
152
      fprintf (src, "\n");
 
153
    }
 
154
 
 
155
  if (strcmp (conf->bus, "USB") == 0)
 
156
    {
 
157
      fprintf (src, "#include <linux/mod_devicetable.h>\n\n");
 
158
      fprintf (src, "#undef strcpy\n");
 
159
      fprintf (src, "#define strcpy dummy_strcpy\n");
 
160
      fprintf (src, "#include <linux/usb.h>\n");
 
161
      fprintf (src, "#undef strcpy\n");
 
162
      fprintf (src, "static struct usb_device_id udi_usb_table[] = {\n");
 
163
 
 
164
      while (fgets (line, sizeof (line) - 1, f) != NULL)
 
165
        {
 
166
          int vendor, product;
 
167
          p = line + strlen (line) - 1;
 
168
          if (*p == '\n')
 
169
            *p = 0;
 
170
 
 
171
          p = line;
 
172
          while (*p && *p != '\t')
 
173
            p++;
 
174
          if (*p == '\t')
 
175
            *p++ = 0;
 
176
 
 
177
          if (strcmp (line, name) != 0)
 
178
            continue;
 
179
 
 
180
          n++;
 
181
 
 
182
          s = p;
 
183
          while (*p && *p != '\t')
 
184
            p++;
 
185
          if (*p == '\t')
 
186
            *p++ = 0;
 
187
 
 
188
          if (strcmp (s, "usbif,class1") == 0)
 
189
            continue;
 
190
 
 
191
          if (strncmp (s, "usbi", 4) == 0)
 
192
            {
 
193
              if (sscanf (s + 4, "%x,%x", &vendor, &product) != 2)
 
194
                {
 
195
                  fprintf (stderr, "Bad USB id %s\n", s);
 
196
                }
 
197
 
 
198
              fprintf (src,
 
199
                       "\t{.match_flags=USB_DEVICE_ID_MATCH_DEVICE,\t.idVendor=0x%x,\t.idProduct=0x%x},\n",
 
200
                       vendor, product);
 
201
              continue;
 
202
            }
 
203
 
 
204
          if (strncmp (s, "usb", 3) == 0)
 
205
            {
 
206
              if (sscanf (s + 3, "%x,%x", &vendor, &product) != 2)
 
207
                {
 
208
                  fprintf (stderr, "Bad USB id %s\n", s);
 
209
                }
 
210
 
 
211
              fprintf (src,
 
212
                       "\t{.match_flags=USB_DEVICE_ID_MATCH_DEVICE,\t.idVendor=0x%x,\t.idProduct=0x%x},\n",
 
213
                       vendor, product);
 
214
              continue;
 
215
            }
 
216
 
 
217
 
 
218
        }
 
219
 
 
220
      fclose (f);
 
221
 
 
222
      fprintf (src, "\t{match_flags:USB_DEVICE_ID_MATCH_INT_CLASS,\n");
 
223
      fprintf (src, "\tbInterfaceClass: USB_CLASS_AUDIO},\n");
 
224
      fprintf (src, "\t{0}\n");
 
225
      fprintf (src, "};\n");
 
226
      fprintf (src, "\n");
 
227
    }
 
228
 
 
229
  fprintf (src, "#include \"module.inc\"\n");
 
230
  fprintf (src, "\n");
 
231
 
 
232
  for (i = 0; i < nopts; i++)
 
233
    {
 
234
      fprintf (src, "module_param(%s, int, S_IRUGO);\n", options[i]);
 
235
      if (option_desc[i] != NULL)
 
236
        fprintf (src, "MODULE_PARM_DESC(%s, %s);\n", options[i],
 
237
                 option_desc[i]);
 
238
    }
 
239
  fprintf (src, "\n");
 
240
  fprintf (src, "\n");
 
241
 
 
242
  fclose (src);
 
243
 
 
244
  sprintf (tmp, "%s/%s", dirname, cfg_header);
 
245
  if ((src = fopen (tmp, "w")) == NULL)
 
246
    {
 
247
      perror (tmp);
 
248
      exit (-1);
 
249
    }
 
250
 
 
251
  fprintf (src, "/*\n");
 
252
  fprintf (src, " * Automatically generated file - do not edit.\n");
 
253
  fprintf (src, " */\n");
 
254
 
 
255
  fprintf (src, "#include <oss_config.h>\n");
 
256
  fprintf (src, "\n");
 
257
 
 
258
  fprintf (src, "#define DRIVER_NAME\t%s\n", name);
 
259
  fprintf (src, "#define DRIVER_NICK\t\"%s\"\n", name);
 
260
  fprintf (src, "#define DRIVER_STR_INFO\t%s_str_info\n", name);
 
261
  fprintf (src, "#define DRIVER_ATTACH\t%s_attach\n", name);
 
262
  fprintf (src, "#define DRIVER_DETACH\t%s_detach\n", name);
 
263
  fprintf (src, "#define DRIVER_TYPE\tDRV_%s\n", conf->bus);
 
264
  fprintf (src, "\n");
 
265
 
 
266
  fprintf (src, "extern int DRIVER_ATTACH(oss_device_t *ossdev);\n");
 
267
  fprintf (src, "extern int DRIVER_DETACH(oss_device_t *ossdev);\n");
 
268
 
 
269
  fclose (src);
 
270
}