Commit d8d04504 authored by Alessandro Rubini's avatar Alessandro Rubini

tools/wrpc-uart-sw: support old spec identifiers too

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent ecb40265
...@@ -28,8 +28,6 @@ ...@@ -28,8 +28,6 @@
/* /*
* The following parameters match the spec, but can be changed on env/cmdline * The following parameters match the spec, but can be changed on env/cmdline
*/ */
#define DEFAULT_VENDOR 0x10dc /* CERN */
#define DEFAULT_DEVICE 0x018d /* SPEC */
#define DEFAULT_BUS -1 /* all */ #define DEFAULT_BUS -1 /* all */
#define DEFAULT_BAR 0 /* first bar */ #define DEFAULT_BAR 0 /* first bar */
#define DEFAULT_RAMADDR 0 /* beginning */ #define DEFAULT_RAMADDR 0 /* beginning */
...@@ -37,6 +35,15 @@ ...@@ -37,6 +35,15 @@
#define MAX_DEVICES 8 /* no alloc, me lazy */ #define MAX_DEVICES 8 /* no alloc, me lazy */
static struct usw_pci_id {
unsigned pci_v;
unsigned pci_d;
} spec_devices[] = {
{ 0x10dc /* CERN */, 0x018d /* SPEC */ },
{ 0x1a39 /* Gennum */, 0x0004 /* GN4124 */ },
{ 0, },
};
struct usw_device { struct usw_device {
void *mapaddr; void *mapaddr;
int mapsize; int mapsize;
...@@ -118,13 +125,14 @@ static int usw_access_pci(char *name, int index) ...@@ -118,13 +125,14 @@ static int usw_access_pci(char *name, int index)
/* Scan PCI space for vendor and device; return number of successes */ /* Scan PCI space for vendor and device; return number of successes */
static int usw_scan_pci(int vendor, int device, struct usw_device *arr, static int usw_scan_pci(struct usw_pci_id *id, struct usw_device *arr,
int alen) int alen)
{ {
char path[PATH_MAX]; char path[PATH_MAX];
FILE *f; FILE *f;
struct dirent **namelist; struct dirent **namelist;
int i, n, val, ndevs; int i, j, n, ndevs;
unsigned v, d;
n = scandir("/sys/bus/pci/devices", &namelist, 0, 0); n = scandir("/sys/bus/pci/devices", &namelist, 0, 0);
if (n < 0) { if (n < 0) {
...@@ -145,11 +153,9 @@ static int usw_scan_pci(int vendor, int device, struct usw_device *arr, ...@@ -145,11 +153,9 @@ static int usw_scan_pci(int vendor, int device, struct usw_device *arr,
strerror(errno)); strerror(errno));
continue; continue;
} }
if (fscanf(f, "%i", &val) != 1) if (fscanf(f, "%i", &v) != 1)
continue; continue;
fclose(f); fclose(f);
if (val != vendor)
continue;
/* check device */ /* check device */
sprintf(path, "/sys/bus/pci/devices/%s/device", sprintf(path, "/sys/bus/pci/devices/%s/device",
...@@ -160,15 +166,19 @@ static int usw_scan_pci(int vendor, int device, struct usw_device *arr, ...@@ -160,15 +166,19 @@ static int usw_scan_pci(int vendor, int device, struct usw_device *arr,
strerror(errno)); strerror(errno));
continue; continue;
} }
if (fscanf(f, "%i", &val) != 1) if (fscanf(f, "%i", &d) != 1)
continue; continue;
fclose(f); fclose(f);
if (val != device)
continue; for (j = 0; id[j].pci_v; j++)
if (id[j].pci_v == v && id[j].pci_d == d)
break;
if (!spec_devices[j].pci_v)
continue; /* not found in whole array */
/* Ok, so this is ours. Celebrate, and open it */ /* Ok, so this is ours. Celebrate, and open it */
fprintf(stderr, "%s: found device %s\n", prgname, fprintf(stderr, "%s: found device %04x:%04x: %s\n", prgname,
namelist[i]->d_name); v, d, namelist[i]->d_name);
if (ndevs == alen) { if (ndevs == alen) {
fprintf(stderr, "%s: array overflow, ignoring card\n", fprintf(stderr, "%s: array overflow, ignoring card\n",
...@@ -249,11 +259,9 @@ int main(int argc, char **argv) ...@@ -249,11 +259,9 @@ int main(int argc, char **argv)
/* FIXME: parse commandline arguments */ /* FIXME: parse commandline arguments */
ndev = usw_scan_pci(DEFAULT_VENDOR, DEFAULT_DEVICE, ndev = usw_scan_pci(spec_devices, devs, MAX_DEVICES);
devs, MAX_DEVICES);
if (ndev < 1) { if (ndev < 1) {
fprintf(stderr, "%s: no %04x:%04x devices on PCI\n", fprintf(stderr, "%s: no suitable PCI devices\n", argv[0]);
argv[0], DEFAULT_VENDOR, DEFAULT_DEVICE);
exit(1); exit(1);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment