usb.patch, with conflicts and some warnings fixed
[pintos-anon] / src / devices / pci_lookup.h
1 #ifndef PCILOOKUP_H
2 #define PCILOOKUP_H
3
4 #ifdef PCI_TRANSLATION_ENABLE
5
6 struct pci_vendor
7 {
8   uint16_t vendor_id;
9   char *vendor;
10 };
11
12 struct pci_vendor pci_vendor_table[] = {
13   {0x1013, "Cirrus Logic"},
14   {0x10de, "nVidia"},
15   {0x10EC, "Realtek"},
16   {0x11c1, "Agere Systems"},
17   {0x8086, "Intel"}
18 };
19
20 struct pci_device
21 {
22   uint16_t vendor_id;
23   uint16_t device_id;
24   char *device;
25 };
26
27 struct pci_device pci_device_table[] = {
28   {0x1013, 0x00b8, "CL-GD5446"},
29   {0x10ec, 0x8029, "RTL8029 - NE2K Compatible"},
30   {0x10ec, 0x8139, "RTL8139"},
31   {0x8086, 0x1237, "82441FX"},
32   {0x8086, 0x7000, "82371SB_ISA"},
33   {0x8086, 0x7010, "82371SB_IDE"},
34   {0x8086, 0x7020, "82371SB_USB"},
35   {0x8086, 0x7113, "82371AB/EB/MB_ACPI"}
36 };
37
38
39 #define PCI_DEVICE_TABLE_SZ     (sizeof (pci_device_table) / sizeof (struct pci_device ))
40 #define PCI_VENDOR_TABLE_SZ     (sizeof (pci_vendor_table) / sizeof (struct pci_vendor))
41
42 /** Too lazy to to a binary search... */
43
44 const char *pci_lookup_vendor (uint16_t vendor);
45 const char *pci_lookup_device (uint16_t vendor, uint16_t device);
46
47 const char *
48 pci_lookup_vendor (uint16_t vendor)
49 {
50   unsigned int i;
51   for (i = 0; i < PCI_VENDOR_TABLE_SZ; i++)
52     {
53       if (pci_vendor_table[i].vendor_id > vendor)
54         break;
55       if (pci_vendor_table[i].vendor_id == vendor)
56         return pci_vendor_table[i].vendor;
57     }
58
59   return "Unknown Vendor";
60 }
61
62 const char *
63 pci_lookup_device (uint16_t vendor, uint16_t device)
64 {
65   unsigned int i;
66   for (i = 0; i < PCI_DEVICE_TABLE_SZ; i++)
67     {
68       if (pci_device_table[i].vendor_id > vendor)
69         break;
70       if (pci_device_table[i].vendor_id == vendor &&
71           pci_device_table[i].device_id == device)
72         return pci_device_table[i].device;
73     }
74
75   return "Unknown Device";
76 }
77
78 #else
79
80 #define pci_lookup_vendor(x)    "Unknown Vendor"
81 #define pci_lookup_device(x,y)  "Unknown Device"
82
83 #endif
84
85 struct pci_class
86 {
87   uint8_t major;
88   uint8_t minor;
89   uint8_t iface;
90   char *name;
91 };
92
93 struct pci_class pci_class_table[] = {
94   {0, 0, 0, "Pre-PCI 2.0 Non-VGA Device"},
95   {0, 1, 0, "Pre-PCI 2.0 VGA Device"},
96   {1, 0, 0, "SCSI Controller"},
97   {1, 1, 0, "IDE Controller"},
98   {1, 2, 0, "Floppy Disk Controller"},
99   {2, 0, 0, "Ethernet"},
100   {3, 0, 0, "VGA Controller"},
101   {3, 1, 0, "XGA Controller"},
102   {5, 0, 0, "Memory Controller - RAM"},
103   {5, 1, 0, "Memory Controller - Flash"},
104   {6, 0, 0, "PCI Host"},
105   {6, 1, 0, "PCI-ISA Bridge"},
106   {6, 2, 0, "PCI-EISA Bridge"},
107   {6, 4, 0, "PCI-PCI Bridge"},
108   {6, 5, 0, "PCI-PCMCIA Bridge"},
109   {12, 0, 0, "Firewire Adapter"},
110   {12, 3, 0, "USB 1.1 Controller (UHCI)"},
111   {12, 3, 0x10, "USB 1.1 Controller (OHCI)"},
112   {12, 3, 0x20, "USB 2.0 Controller (EHCI)"}
113 };
114
115 #define PCI_CLASS_TABLE_SZ (sizeof(pci_class_table) / sizeof(struct pci_class))
116
117 const char *pci_lookup_class (uint8_t major, uint8_t minor, uint8_t iface);
118 const char *
119 pci_lookup_class (uint8_t major, uint8_t minor, uint8_t iface)
120 {
121   unsigned int i;
122   for (i = 0; i < PCI_CLASS_TABLE_SZ; i++)
123     {
124       if (pci_class_table[i].major > major)
125         break;
126       if (pci_class_table[i].major != major)
127         continue;
128       if (pci_class_table[i].minor != minor)
129         continue;
130       if (pci_class_table[i].iface != iface)
131         continue;
132       return pci_class_table[i].name;
133     }
134
135   return "Unknown Type";
136 }
137
138 #endif