2 #include "libopenbios/bindings.h"
3 #include "drivers/pci.h"
4 #include "libc/vsprintf.h"
6 #include "pci_database.h"
8 /* PCI devices database */
10 typedef struct pci_class_t pci_class_t
;
11 typedef struct pci_subclass_t pci_subclass_t
;
12 typedef struct pci_iface_t pci_iface_t
;
18 const pci_dev_t
*devices
;
19 int (*config_cb
)(const pci_config_t
*config
);
23 struct pci_subclass_t
{
27 const pci_dev_t
*devices
;
28 const pci_iface_t
*iface
;
29 int (*config_cb
)(const pci_config_t
*config
);
36 const pci_subclass_t
*subc
;
39 /* Current machine description */
41 static const pci_subclass_t undef_subclass
[] = {
43 0xFF, NULL
, NULL
, NULL
, NULL
,
48 static const pci_dev_t ide_devices
[] = {
50 PCI_VENDOR_ID_CMD
, PCI_DEVICE_ID_CMD_646
, /* CMD646 IDE controller */
51 "pci-ide", "pci-ata", NULL
,
52 "pci1095,646\0pci1095,646\0pciclass,01018f\0",
58 NULL
, NULL
, NULL
, NULL
,
64 static const pci_subclass_t mass_subclass
[] = {
66 PCI_SUBCLASS_STORAGE_SCSI
, "SCSI bus controller",
71 PCI_SUBCLASS_STORAGE_IDE
, "IDE controller",
72 "ide", ide_devices
, NULL
,
76 PCI_SUBCLASS_STORAGE_FLOPPY
, "Floppy disk controller",
81 PCI_SUBCLASS_STORAGE_IPI
, "IPI bus controller",
86 PCI_SUBCLASS_STORAGE_RAID
, "RAID controller",
91 PCI_SUBCLASS_STORAGE_ATA
, "ATA controller",
96 PCI_SUBCLASS_STORAGE_OTHER
, "misc mass-storage controller",
107 static const pci_dev_t eth_devices
[] = {
109 PCI_VENDOR_ID_REALTEK
, PCI_DEVICE_ID_REALTEK_RTL8029
,
110 NULL
, "NE2000", "NE2000 PCI", NULL
,
116 NULL
, NULL
, NULL
, NULL
,
122 static const pci_subclass_t net_subclass
[] = {
124 PCI_SUBCLASS_NETWORK_ETHERNET
, "ethernet controller",
125 NULL
, eth_devices
, NULL
,
126 eth_config_cb
, "ethernet",
129 PCI_SUBCLASS_NETWORK_TOKEN_RING
, "token ring controller",
134 PCI_SUBCLASS_NETWORK_FDDI
, "FDDI controller",
139 PCI_SUBCLASS_NETWORK_ATM
, "ATM controller",
144 PCI_SUBCLASS_NETWORK_ISDN
, "ISDN controller",
149 PCI_SUBCLASS_NETWORK_WORDFIP
, "WordFip controller",
154 PCI_SUBCLASS_NETWORK_PICMG214
, "PICMG 2.14 controller",
159 PCI_SUBCLASS_NETWORK_OTHER
, "misc network controller",
170 static const pci_dev_t vga_devices
[] = {
172 PCI_VENDOR_ID_ATI
, PCI_DEVICE_ID_ATI_RAGE128_PF
,
173 NULL
, "ATY", "ATY Rage128", "VGA\0",
178 PCI_VENDOR_ID_QEMU
, PCI_DEVICE_ID_QEMU_VGA
,
179 NULL
, "QEMU,VGA", "Qemu VGA", "VGA\0",
185 NULL
, NULL
, NULL
, NULL
,
191 static const struct pci_iface_t vga_iface
[] = {
193 0x00, "VGA controller", NULL
,
194 vga_devices
, &vga_config_cb
, NULL
,
197 0x01, "8514 compatible controller", NULL
,
206 static const pci_subclass_t displ_subclass
[] = {
208 PCI_SUBCLASS_DISPLAY_VGA
, "display controller",
209 NULL
, NULL
, vga_iface
,
213 PCI_SUBCLASS_DISPLAY_XGA
, "XGA display controller",
218 PCI_SUBCLASS_DISPLAY_3D
, "3D display controller",
223 PCI_SUBCLASS_DISPLAY_OTHER
, "misc display controller",
234 static const pci_subclass_t media_subclass
[] = {
236 PCI_SUBCLASS_MULTIMEDIA_VIDEO
, "video device",
241 PCI_SUBCLASS_MULTIMEDIA_AUDIO
, "audio device",
246 PCI_SUBCLASS_MULTIMEDIA_PHONE
, "computer telephony device",
251 PCI_SUBCLASS_MULTIMEDIA_OTHER
, "misc multimedia device",
262 static const pci_subclass_t mem_subclass
[] = {
264 PCI_SUBCLASS_MEMORY_RAM
, "RAM controller",
269 PCI_SUBCLASS_MEMORY_FLASH
, "flash controller",
281 static const pci_dev_t hbrg_devices
[] = {
283 PCI_VENDOR_ID_APPLE
, PCI_DEVICE_ID_APPLE_U3_AGP
, NULL
,
284 "pci", "AAPL,UniNorth", "u3-agp\0",
286 host_config_cb
, NULL
,
289 PCI_VENDOR_ID_APPLE
, PCI_DEVICE_ID_APPLE_UNI_N_AGP
, NULL
,
290 "pci", "AAPL,UniNorth", "uni-north\0",
292 host_config_cb
, NULL
,
295 PCI_VENDOR_ID_APPLE
, PCI_DEVICE_ID_APPLE_UNI_N_PCI
, NULL
,
296 "pci", "AAPL,UniNorth", "uni-north\0",
298 host_config_cb
, NULL
,
301 PCI_VENDOR_ID_APPLE
, PCI_DEVICE_ID_APPLE_UNI_N_I_PCI
, NULL
,
302 "pci", "AAPL,UniNorth", "uni-north\0",
307 PCI_VENDOR_ID_MOTOROLA
, PCI_DEVICE_ID_MOTOROLA_MPC106
, "pci",
308 "pci", "MOT,MPC106", "grackle\0",
313 PCI_VENDOR_ID_MOTOROLA
, PCI_DEVICE_ID_MOTOROLA_RAVEN
, NULL
,
314 "pci-bridge", "PREP Host PCI Bridge - Motorola Raven", NULL
,
319 PCI_VENDOR_ID_SUN
, PCI_DEVICE_ID_SUN_SABRE
, NULL
,
320 "pci", "SUNW,sabre", "pci108e,a000\0pciclass,0\0",
322 sabre_config_cb
, NULL
,
326 NULL
, NULL
, NULL
, NULL
,
332 static const pci_dev_t PCIbrg_devices
[] = {
334 PCI_VENDOR_ID_DEC
, PCI_DEVICE_ID_DEC_21154
, NULL
,
335 "pci-bridge", "DEV,21154", "DEV,21154\0pci-bridge\0",
337 bridge_config_cb
, NULL
,
340 PCI_VENDOR_ID_SUN
, PCI_DEVICE_ID_SUN_SIMBA
, NULL
,
341 "pci", "SUNW,simba", "pci108e,5000\0pciclass,060400\0",
343 bridge_config_cb
, NULL
,
347 NULL
, NULL
, NULL
, NULL
,
353 static const pci_dev_t miscbrg_devices
[] = {
355 PCI_VENDOR_ID_SUN
, PCI_DEVICE_ID_SUN_EBUS
, NULL
,
356 "ebus", "ebus", "pci108e,1000\0pciclass,068000\0",
358 ebus_config_cb
, NULL
,
362 NULL
, NULL
, NULL
, NULL
,
368 static const pci_subclass_t bridg_subclass
[] = {
370 PCI_SUBCLASS_BRIDGE_HOST
, "PCI host bridge",
371 "pci", hbrg_devices
, NULL
,
375 PCI_SUBCLASS_BRIDGE_ISA
, "ISA bridge",
380 PCI_SUBCLASS_BRIDGE_EISA
, "EISA bridge",
385 PCI_SUBCLASS_BRIDGE_MC
, "MCA bridge",
390 PCI_SUBCLASS_BRIDGE_PCI
, "PCI-to-PCI bridge",
391 "pci", PCIbrg_devices
, NULL
,
395 PCI_SUBCLASS_BRIDGE_PCMCIA
, "PCMCIA bridge",
400 PCI_SUBCLASS_BRIDGE_NUBUS
, "NUBUS bridge",
405 PCI_SUBCLASS_BRIDGE_CARDBUS
, "cardbus bridge",
410 PCI_SUBCLASS_BRIDGE_RACEWAY
, "raceway bridge",
415 PCI_SUBCLASS_BRIDGE_PCI_SEMITP
, "semi-transparent PCI-to-PCI bridge",
420 PCI_SUBCLASS_BRIDGE_IB_PCI
, "infiniband-to-PCI bridge",
425 PCI_SUBCLASS_BRIDGE_OTHER
, "misc PCI bridge",
426 NULL
, miscbrg_devices
, NULL
,
436 static const pci_iface_t serial_iface
[] = {
438 0x00, "XT serial controller", NULL
,
442 0x01, "16450 serial controller", NULL
,
446 0x02, "16550 serial controller", NULL
,
450 0x03, "16650 serial controller", NULL
,
454 0x04, "16750 serial controller", NULL
,
458 0x05, "16850 serial controller", NULL
,
462 0x06, "16950 serial controller", NULL
,
471 static const pci_iface_t par_iface
[] = {
473 0x00, "parallel port", NULL
,
477 0x01, "bi-directional parallel port", NULL
,
481 0x02, "ECP 1.x parallel port", NULL
,
485 0x03, "IEEE 1284 controller", NULL
,
489 0xFE, "IEEE 1284 device", NULL
,
498 static const pci_iface_t modem_iface
[] = {
500 0x00, "generic modem", NULL
,
504 0x01, "Hayes 16450 modem", NULL
,
508 0x02, "Hayes 16550 modem", NULL
,
512 0x03, "Hayes 16650 modem", NULL
,
516 0x04, "Hayes 16750 modem", NULL
,
525 static const pci_subclass_t comm_subclass
[] = {
527 PCI_SUBCLASS_COMMUNICATION_SERIAL
, "serial controller",
528 NULL
, NULL
, serial_iface
,
532 PCI_SUBCLASS_COMMUNICATION_PARALLEL
, "parallel port",
533 NULL
, NULL
, par_iface
,
537 PCI_SUBCLASS_COMMUNICATION_MULTISERIAL
, "multiport serial controller",
542 PCI_SUBCLASS_COMMUNICATION_MODEM
, "modem",
543 NULL
, NULL
, modem_iface
,
547 PCI_SUBCLASS_COMMUNICATION_GPIB
, "GPIB controller",
552 PCI_SUBCLASS_COMMUNICATION_SC
, "smart card",
557 PCI_SUBCLASS_COMMUNICATION_OTHER
, "misc communication device",
568 static const pci_iface_t pic_iface
[] = {
570 0x00, "8259 PIC", NULL
,
574 0x01, "ISA PIC", NULL
,
578 0x02, "EISA PIC", NULL
,
582 0x10, "I/O APIC", NULL
,
586 0x20, "I/O APIC", NULL
,
595 static const pci_iface_t dma_iface
[] = {
597 0x00, "8237 DMA controller", NULL
,
601 0x01, "ISA DMA controller", NULL
,
605 0x02, "EISA DMA controller", NULL
,
614 static const pci_iface_t tmr_iface
[] = {
616 0x00, "8254 system timer", NULL
,
620 0x01, "ISA system timer", NULL
,
624 0x02, "EISA system timer", NULL
,
633 static const pci_iface_t rtc_iface
[] = {
635 0x00, "generic RTC controller", NULL
,
639 0x01, "ISA RTC controller", NULL
,
648 static const pci_dev_t sys_devices
[] = {
649 /* IBM MPIC controller */
651 PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OPENPIC
,
652 "open-pic", "MPIC", NULL
, "chrp,open-pic\0",
656 /* IBM MPIC2 controller */
658 PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OPENPIC2
,
659 "open-pic", "MPIC2", NULL
, "chrp,open-pic\0",
665 NULL
, NULL
, NULL
, NULL
,
671 static const pci_subclass_t sys_subclass
[] = {
673 PCI_SUBCLASS_SYSTEM_PIC
, "PIC",
674 NULL
, NULL
, pic_iface
,
678 PCI_SUBCLASS_SYSTEM_DMA
, "DMA controller",
679 NULL
, NULL
, dma_iface
,
683 PCI_SUBCLASS_SYSTEM_TIMER
, "system timer",
684 NULL
, NULL
, tmr_iface
,
688 PCI_SUBCLASS_SYSTEM_RTC
, "RTC controller",
689 NULL
, NULL
, rtc_iface
,
693 PCI_SUBCLASS_SYSTEM_PCI_HOTPLUG
, "PCI hotplug controller",
698 PCI_SUBCLASS_SYSTEM_OTHER
, "misc system peripheral",
699 NULL
, sys_devices
, NULL
,
709 static const pci_subclass_t inp_subclass
[] = {
711 PCI_SUBCLASS_INPUT_KEYBOARD
, "keyboard controller",
716 PCI_SUBCLASS_INPUT_PEN
, "digitizer",
721 PCI_SUBCLASS_INPUT_MOUSE
, "mouse controller",
726 PCI_SUBCLASS_INPUT_SCANNER
, "scanner controller",
731 PCI_SUBCLASS_INPUT_GAMEPORT
, "gameport controller",
736 PCI_SUBCLASS_INPUT_OTHER
, "misc input device",
747 static const pci_subclass_t dock_subclass
[] = {
749 PCI_SUBCLASS_DOCKING_GENERIC
, "generic docking station",
754 PCI_SUBCLASS_DOCKING_OTHER
, "misc docking station",
765 static const pci_subclass_t cpu_subclass
[] = {
767 PCI_SUBCLASS_PROCESSOR_386
, "i386 processor",
772 PCI_SUBCLASS_PROCESSOR_486
, "i486 processor",
777 PCI_SUBCLASS_PROCESSOR_PENTIUM
, "pentium processor",
782 PCI_SUBCLASS_PROCESSOR_ALPHA
, "alpha processor",
787 PCI_SUBCLASS_PROCESSOR_POWERPC
, "PowerPC processor",
792 PCI_SUBCLASS_PROCESSOR_MIPS
, "MIPS processor",
797 PCI_SUBCLASS_PROCESSOR_CO
, "co-processor",
808 static const pci_iface_t usb_iface
[] = {
810 0x00, "UHCI USB controller", NULL
,
814 0x10, "OHCI USB controller", NULL
,
818 0x20, "EHCI USB controller", NULL
,
822 0x80, "misc USB controller", NULL
,
826 0xFE, "USB device", NULL
,
835 static const pci_iface_t ipmi_iface
[] = {
837 0x00, "IPMI SMIC interface", NULL
,
841 0x01, "IPMI keyboard interface", NULL
,
845 0x02, "IPMI block transfer interface", NULL
,
854 static const pci_subclass_t ser_subclass
[] = {
856 PCI_SUBCLASS_SERIAL_FIREWIRE
, "Firewire bus controller",
857 "ieee1394", NULL
, NULL
,
861 PCI_SUBCLASS_SERIAL_ACCESS
, "ACCESS bus controller",
866 PCI_SUBCLASS_SERIAL_SSA
, "SSA controller",
871 PCI_SUBCLASS_SERIAL_USB
, "USB controller",
872 "usb", NULL
, usb_iface
,
876 PCI_SUBCLASS_SERIAL_FIBER
, "fibre channel controller",
881 PCI_SUBCLASS_SERIAL_SMBUS
, "SMBus controller",
886 PCI_SUBCLASS_SERIAL_IB
, "InfiniBand controller",
891 PCI_SUBCLASS_SERIAL_IPMI
, "IPMI interface",
892 NULL
, NULL
, ipmi_iface
,
896 PCI_SUBCLASS_SERIAL_SERCOS
, "SERCOS controller",
897 NULL
, NULL
, ipmi_iface
,
901 PCI_SUBCLASS_SERIAL_CANBUS
, "CANbus controller",
902 NULL
, NULL
, ipmi_iface
,
912 static const pci_subclass_t wrl_subclass
[] = {
914 PCI_SUBCLASS_WIRELESS_IRDA
, "IRDA controller",
919 PCI_SUBCLASS_WIRELESS_CIR
, "consumer IR controller",
924 PCI_SUBCLASS_WIRELESS_RF_CONTROLLER
, "RF controller",
929 PCI_SUBCLASS_WIRELESS_BLUETOOTH
, "bluetooth controller",
934 PCI_SUBCLASS_WIRELESS_BROADBAND
, "broadband controller",
939 PCI_SUBCLASS_WIRELESS_OTHER
, "misc wireless controller",
950 static const pci_subclass_t sat_subclass
[] = {
952 PCI_SUBCLASS_SATELLITE_TV
, "satellite TV controller",
957 PCI_SUBCLASS_SATELLITE_AUDIO
, "satellite audio controller",
962 PCI_SUBCLASS_SATELLITE_VOICE
, "satellite voice controller",
967 PCI_SUBCLASS_SATELLITE_DATA
, "satellite data controller",
978 static const pci_subclass_t crypt_subclass
[] = {
980 PCI_SUBCLASS_CRYPT_NETWORK
, "cryptographic network controller",
985 PCI_SUBCLASS_CRYPT_ENTERTAINMENT
,
986 "cryptographic entertainment controller",
991 PCI_SUBCLASS_CRYPT_OTHER
, "misc cryptographic controller",
1002 static const pci_subclass_t spc_subclass
[] = {
1004 PCI_SUBCLASS_SP_DPIO
, "DPIO module",
1009 PCI_SUBCLASS_SP_PERF
, "performances counters",
1014 PCI_SUBCLASS_SP_SYNCH
, "communication synchronisation",
1019 PCI_SUBCLASS_SP_MANAGEMENT
, "management card",
1024 PCI_SUBCLASS_SP_OTHER
, "misc signal processing controller",
1035 static const pci_class_t pci_classes
[] = {
1037 { "undefined", NULL
, undef_subclass
, },
1039 { "mass-storage controller", NULL
, mass_subclass
, },
1041 { "network controller", "network", net_subclass
, },
1043 { "display controller", "display", displ_subclass
, },
1045 { "multimedia device", NULL
, media_subclass
, },
1047 { "memory controller", "memory-controller", mem_subclass
, },
1049 { "PCI bridge", NULL
, bridg_subclass
, },
1051 { "communication device", NULL
, comm_subclass
,},
1053 { "system peripheral", NULL
, sys_subclass
, },
1055 { "input device", NULL
, inp_subclass
, },
1057 { "docking station", NULL
, dock_subclass
, },
1059 { "processor", NULL
, cpu_subclass
, },
1061 { "serial bus controller", NULL
, ser_subclass
, },
1063 { "wireless controller", NULL
, wrl_subclass
, },
1065 { "intelligent I/O controller", NULL
, NULL
, },
1067 { "satellite communication controller", NULL
, sat_subclass
, },
1069 { "cryptographic controller", NULL
, crypt_subclass
, },
1071 { "signal processing controller", NULL
, spc_subclass
, },
1074 static const pci_dev_t misc_pci
[] = {
1075 /* Heathrow Mac I/O */
1077 PCI_VENDOR_ID_APPLE
, PCI_DEVICE_ID_APPLE_343S1201
,
1078 "mac-io", "mac-io", "AAPL,343S1201", "heathrow\0",
1080 &macio_heathrow_config_cb
, NULL
,
1082 /* Paddington Mac I/O */
1084 PCI_VENDOR_ID_APPLE
, PCI_DEVICE_ID_APPLE_343S1211
,
1085 "mac-io", "mac-io", "AAPL,343S1211", "paddington\0heathrow\0",
1087 &macio_heathrow_config_cb
, NULL
,
1089 /* KeyLargo Mac I/O */
1091 PCI_VENDOR_ID_APPLE
, PCI_DEVICE_ID_APPLE_UNI_N_KEYL
,
1092 "mac-io", "mac-io", "AAPL,Keylargo", "Keylargo\0",
1094 &macio_keylargo_config_cb
, NULL
,
1098 NULL
, NULL
, NULL
, NULL
,
1104 const pci_dev_t
*pci_find_device (uint8_t class, uint8_t subclass
,
1105 uint8_t iface
, uint16_t vendor
,
1108 int (*config_cb
)(const pci_config_t
*config
);
1109 const pci_class_t
*pclass
;
1110 const pci_subclass_t
*psubclass
;
1111 const pci_iface_t
*piface
;
1112 const pci_dev_t
*dev
;
1113 const void *private;
1115 const char *name
, *type
;
1122 if (class == 0x00 && subclass
== 0x01) {
1123 /* Special hack for old style VGA devices */
1126 } else if (class == 0xFF) {
1127 /* Special case for misc devices */
1131 if (class > (sizeof(pci_classes
) / sizeof(pci_class_t
))) {
1132 name
= "invalid PCI device";
1136 pclass
= &pci_classes
[class];
1137 name
= pclass
->name
;
1138 type
= pclass
->type
;
1139 for (psubclass
= pclass
->subc
; ; psubclass
++) {
1140 if (psubclass
->subclass
== 0xFF)
1142 if (psubclass
->subclass
== subclass
) {
1143 if (psubclass
->name
!= NULL
)
1144 name
= psubclass
->name
;
1145 if (psubclass
->type
!= NULL
)
1146 type
= psubclass
->type
;
1147 if (psubclass
->config_cb
!= NULL
) {
1148 config_cb
= psubclass
->config_cb
;
1150 if (psubclass
->private != NULL
)
1151 private = psubclass
->private;
1152 if (psubclass
->iface
!= NULL
)
1154 dev
= psubclass
->devices
;
1158 for (piface
= psubclass
->iface
; ; piface
++) {
1159 if (piface
->iface
== 0xFF) {
1160 dev
= psubclass
->devices
;
1163 if (piface
->iface
== iface
) {
1164 if (piface
->name
!= NULL
)
1165 name
= piface
->name
;
1166 if (piface
->type
!= NULL
)
1167 type
= piface
->type
;
1168 if (piface
->config_cb
!= NULL
) {
1169 config_cb
= piface
->config_cb
;
1171 if (piface
->private != NULL
)
1172 private = piface
->private;
1173 dev
= piface
->devices
;
1181 if (dev
->vendor
== 0xFFFF && dev
->product
== 0xFFFF) {
1184 if (dev
->vendor
== vendor
&& dev
->product
== product
) {
1185 if (dev
->name
!= NULL
)
1187 if (dev
->type
!= NULL
)
1189 if (dev
->config_cb
!= NULL
) {
1190 config_cb
= dev
->config_cb
;
1192 if (dev
->private != NULL
)
1193 private = dev
->private;
1194 new = malloc(sizeof(pci_dev_t
));
1197 new->vendor
= vendor
;
1198 new->product
= product
;
1201 new->model
= dev
->model
;
1202 new->compat
= dev
->compat
;
1203 new->acells
= dev
->acells
;
1204 new->scells
= dev
->scells
;
1205 new->icells
= dev
->icells
;
1206 new->config_cb
= config_cb
;
1207 new->private = private;
1213 printk("Cannot manage '%s' PCI device type '%s':\n %x %x (%x %x %x)\n",
1214 name
, type
, vendor
, product
, class, subclass
, iface
);