1 /* ----------------------------------------------------------------------- *
3 * Copyright 2005-2008 H. Peter Anvin - All Rights Reserved
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8 * Boston MA 02111-1307, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
11 * ----------------------------------------------------------------------- */
16 * Search for an Ethernet card with a known PCI signature, and run
17 * the corresponding Ethernet module.
19 * To use this, set up a syslinux config file like this:
22 * DEFAULT ethersel.c32
23 * # DEV [DID xxxx:yyyy[/mask]] [RID zz-zz] [SID uuuu:vvvv[/mask]] commandline
27 * RID = Revision ID (range)
39 #include <syslinux/boot.h>
40 #include <syslinux/config.h>
45 /* Check to see if we are at a certain keyword (case insensitive) */
46 static int looking_at(const char *line
, const char *kwd
)
51 while (*p
&& *q
&& ((*p
^ *q
) & ~0x20) == 0) {
57 return 0; /* Didn't see the keyword */
59 return *p
<= ' '; /* Must be EOL or whitespace */
62 static char *get_did(char *p
, uint32_t * idptr
, uint32_t * maskptr
)
64 unsigned long vid
, did
, m1
, m2
;
67 *maskptr
= 0xffffffff;
69 vid
= strtoul(p
, &p
, 16);
71 return p
; /* Bogus ID */
72 did
= strtoul(p
+ 1, &p
, 16);
74 *idptr
= (did
<< 16) + vid
;
77 m1
= strtoul(p
+ 1, &p
, 16);
79 *maskptr
= (m1
<< 16) | 0xffff;
81 m2
= strtoul(p
+ 1, &p
, 16);
82 *maskptr
= (m1
<< 16) | m2
;
89 static char *get_rid_range(char *p
, uint8_t * rid_min
, uint8_t * rid_max
)
95 r0
= strtoul(p
, &p
, 16);
97 r1
= strtoul(p
+ 1, &p
, 16);
108 static struct match
*parse_config(const char *filename
)
110 char line
[MAX_LINE
], *p
;
112 struct match
*list
= NULL
;
113 struct match
**ep
= &list
;
117 filename
= syslinux_config_file();
119 f
= fopen(filename
, "r");
123 while (fgets(line
, sizeof line
, f
)) {
126 if (!looking_at(p
, "#"))
128 p
= skipspace(p
+ 1);
130 if (!looking_at(p
, "dev"))
132 p
= skipspace(p
+ 3);
134 m
= malloc(sizeof(struct match
));
138 memset(m
, 0, sizeof *m
);
144 if (looking_at(p
, "did")) {
145 p
= get_did(p
+ 3, &m
->did
, &m
->did_mask
);
146 } else if (looking_at(p
, "sid")) {
147 p
= get_did(p
+ 3, &m
->sid
, &m
->sid_mask
);
148 } else if (looking_at(p
, "rid")) {
149 p
= get_rid_range(p
+ 3, &m
->rid_min
, &m
->rid_max
);
160 m
->filename
= strdup(p
);
163 break; /* Done with this line */
167 dprintf("DEV DID %08x/%08x SID %08x/%08x RID %02x-%02x CMD %s\n",
168 m
->did
, m
->did_mask
, m
->sid
, m
->sid_mask
,
169 m
->rid_min
, m
->rid_max
, m
->filename
);
178 int main(int argc
, char *argv
[])
180 struct match
*list
, *match
;
181 struct pci_domain
*pci_domain
;
183 pci_domain
= pci_scan();
186 list
= parse_config(argc
< 2 ? NULL
: argv
[1]);
188 match
= find_pci_device(pci_domain
, list
);
191 syslinux_run_command(match
->filename
);
194 /* On error, return to the command line */
195 fputs("Error: no recognized network card found!\n", stderr
);