2
generate_driver (char *name, conf_t * conf, char *cfg_name, char *cfg_header,
3
char *dirname, char *topdir)
10
char tmp[256], line[256], *p, *s;
12
char *options[MAXOPTS];
15
sprintf (tmp, "%s/%s", dirname, cfg_name);
17
if ((src = fopen (tmp, "w")) == NULL)
23
fprintf (src, "/*\n");
24
fprintf (src, " * Automatically generated file - do not edit.\n");
25
fprintf (src, " */\n");
29
* Handle driver specific configuration options
31
sprintf (tmp, "%s/.params", dirname);
32
if ((f = fopen (tmp, "r")) != NULL)
34
while (fgets (line, sizeof (line) - 1, f) != NULL)
36
p = line + strlen (line) - 1;
40
fprintf (src, "%s\n", line);
41
if (strncmp (line, "int ", 4) == 0)
43
char *s = line + 4, *p = s;
45
while (*p && *p != '=' && *p != ';')
50
fprintf (stderr, "Too many options for driver '%s' (%d)\n",
55
options[nopts++] = strdup (s);
63
fprintf (src, "#include \"%s\"\n", cfg_header);
66
if ((f = fopen ("devices.list", "r")) == NULL)
68
perror ("devices.list");
72
if (strcmp (conf->bus, "PCI") == 0)
74
fprintf (src, "static struct {\n");
75
fprintf (src, "\tbool subsystem;\n");
76
fprintf (src, "\tuint32 vendor, product;\n");
77
fprintf (src, "} id_table[] = {\n");
79
while (fgets (line, sizeof (line) - 1, f) != NULL)
82
p = line + strlen (line) - 1;
87
while (*p && *p != '\t')
92
if (strcmp (line, name) != 0)
98
while (*p && *p != '\t')
103
if (strncmp (s, "pci", 3) == 0 || strncmp (s, "pcs", 3) == 0)
105
const char *sub = (strncmp (s, "pcs", 3) == 0) ? "true" : "false";
106
if (sscanf (s + 3, "%x,%x", &vendor, &product) != 2)
108
fprintf (stderr, "Bad PCI id %s\n", s);
111
fprintf (src, "\t{%s,\t0x%x,\t0x%x},\n", sub, vendor, product);
116
fprintf (src, "\t{0}\n");
117
fprintf (src, "};\n");
125
* Create the driver specific option list
127
fprintf (src, "static oss_option_map_t local_driver_options[] =\n");
128
fprintf (src, "{\n");
129
for (i = 0; i < nopts; i++)
130
fprintf (src, "\t{\"%s\", &%s},\n", options[i], options[i]);
131
fprintf (src, "\t{NULL, NULL}\n");
132
fprintf (src, "};\n");
135
fprintf (src, "#include \"%s/%s/module.inc\"\n", topdir, this_os);
140
"Warning: No device entries (devices.list) for driver %s\n",
148
sprintf (tmp, "%s/%s", dirname, cfg_header);
149
if ((src = fopen (tmp, "w")) == NULL)
155
fprintf (src, "/*\n");
156
fprintf (src, " * Automatically generated file - do not edit.\n");
157
fprintf (src, " */\n");
159
/* nudge all symbols to function pointers */
160
fprintf (src, "#define BUILDING_DRIVER\n");
162
fprintf (src, "#include <oss_config.h>\n");
165
fprintf (src, "#define DRIVER_NAME\t%s\n", name);
166
fprintf (src, "#define DRIVER_NICK\t\"%s\"\n", name);
167
fprintf (src, "#define DRIVER_PURPOSE\t\"%s\"\n", conf->purpose);
168
fprintf (src, "#define DRIVER_STR_INFO\t%s_str_info\n", name);
169
fprintf (src, "#define DRIVER_PROBE\t%s_probe\n", name);
170
fprintf (src, "#define DRIVER_ATTACH\t%s_attach\n", name);
171
fprintf (src, "#define DRIVER_DETACH\t%s_detach\n", name);
172
fprintf (src, "#define DRIVER_TYPE\tDRV_%s\n", conf->bus);
174
fprintf (src, "#define DRIVER_MODULE_OBJECT\tgModule_%s\n", name);
177
fprintf (src, "extern int DRIVER_PROBE(void);\n");
178
fprintf (src, "extern int DRIVER_ATTACH(oss_device_t *ossdev);\n");
179
fprintf (src, "extern int DRIVER_DETACH(oss_device_t *ossdev);\n");