]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/io/server/libpciids/src/names.c
update
[l4.git] / l4 / pkg / io / server / libpciids / src / names.c
1 /*
2  *      PCI Class and Device Name Tables
3  *
4  *      Copyright 1993--1999 Drew Eckhardt, Frederic Potter,
5  *      David Mosberger-Tang, Martin Mares
6  */
7
8 //#include <linux/types.h>
9 //#include <linux/kernel.h>
10 //#include <linux/pci.h>
11
12 #include <stdio.h>
13 #include <l4/io/pciids.h>
14
15 struct pci_device_info {
16         unsigned short device;
17         unsigned short seen;
18         const char *name;
19 };
20
21 struct pci_vendor_info {
22         unsigned short vendor;
23         unsigned short nr;
24         const char *name;
25         struct pci_device_info *devices;
26 };
27
28 #define __devinitdata
29
30 /*
31  * This is ridiculous, but we want the strings in
32  * the .init section so that they don't take up
33  * real memory.. Parse the same file multiple times
34  * to get all the info.
35  */
36 #define VENDOR( vendor, name )          static char __vendorstr_##vendor[] __devinitdata = name;
37 #define ENDVENDOR()
38 #define DEVICE( vendor, device, name )  static char __devicestr_##vendor##device[] __devinitdata = name;
39 #include "devlist.h"
40
41
42 #define VENDOR( vendor, name )          static struct pci_device_info __devices_##vendor[] __devinitdata = {
43 #define ENDVENDOR()                     };
44 #define DEVICE( vendor, device, name )  { 0x##device, 0, __devicestr_##vendor##device },
45 #include "devlist.h"
46
47 static struct pci_vendor_info __devinitdata pci_vendor_list[] = {
48 #define VENDOR( vendor, name )          { 0x##vendor, sizeof(__devices_##vendor) / sizeof(struct pci_device_info), __vendorstr_##vendor, __devices_##vendor },
49 #define ENDVENDOR()
50 #define DEVICE( vendor, device, name )
51 #include "devlist.h"
52 };
53
54 #define VENDORS (sizeof(pci_vendor_list)/sizeof(struct pci_vendor_info))
55
56 //void libpci_name_device(char *name, struct pci_dev *dev)
57 void libpciids_name_device(char *name, int len,
58                            unsigned vendor, unsigned device)
59 {
60         const struct pci_vendor_info *vendor_p = pci_vendor_list;
61         int i = VENDORS;
62
63         do {
64                 if (vendor_p->vendor == vendor)
65                         goto match_vendor;
66                 vendor_p++;
67         } while (--i);
68
69         /* Couldn't find either the vendor nor the device */
70         snprintf(name, len, "PCI device %04x:%04x", vendor, device);
71         name[len - 1] = 0;
72         return;
73
74         match_vendor: {
75                 struct pci_device_info *device_p = vendor_p->devices;
76                 int i = vendor_p->nr;
77
78                 while (i > 0) {
79                         if (device_p->device == device)
80                                 goto match_device;
81                         device_p++;
82                         i--;
83                 }
84
85                 /* Ok, found the vendor, but unknown device */
86                 snprintf(name, len, "PCI device %04x:%04x (%s)", vendor, device, vendor_p->name);
87                 name[len - 1] = 0;
88                 return;
89
90                 /* Full match */
91                 match_device: {
92                         int w = snprintf(name, len, "%s %s", vendor_p->name, device_p->name);
93                         int nr = device_p->seen + 1;
94                         device_p->seen = nr;
95                         if (nr > 1)
96                                 snprintf(name + w, len - w, " (#%d)", nr);
97                         name[len - 1] = 0;
98                 }
99         }
100 }
101
102 /*
103  *  Class names. Not in .init section as they are needed in runtime.
104  */
105
106 #if 0
107 static u16 pci_class_numbers[] = {
108 #define CLASS(x,y) 0x##x,
109 #include "classlist.h"
110 };
111
112 static char *pci_class_names[] = {
113 #define CLASS(x,y) y,
114 #include "classlist.h"
115 };
116
117 char *
118 libpci_class_name(u32 class)
119 {
120         int i;
121
122         for(i=0; i<sizeof(pci_class_numbers)/sizeof(pci_class_numbers[0]); i++)
123                 if (pci_class_numbers[i] == class)
124                         return pci_class_names[i];
125         return NULL;
126 }
127 #endif