123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
-
-
- #include <stdint.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <gpxe/pci.h>
- #include <undi.h>
- #include <undirom.h>
- #include <undiload.h>
- #include <undinet.h>
- #include <undipreload.h>
-
-
-
-
- static struct undi_rom * undipci_find_rom ( struct pci_device *pci ) {
- struct undi_rom *undirom;
- unsigned long rombase;
-
- rombase = pci_bar_start ( pci, PCI_ROM_ADDRESS );
- undirom = undirom_find_pci ( pci->vendor, pci->device, rombase );
- if ( ! undirom )
- undirom = undirom_find_pci ( pci->vendor, pci->device, 0 );
- return undirom;
- }
-
-
- static int undipci_probe ( struct pci_device *pci,
- const struct pci_device_id *id __unused ) {
- struct undi_device *undi;
- struct undi_rom *undirom;
- unsigned int busdevfn = PCI_BUSDEVFN ( pci->bus, pci->devfn );
- int rc;
-
-
- if ( PCI_BASE_CLASS ( pci->class ) != PCI_BASE_CLASS_NETWORK )
- return -ENOTTY;
-
-
- undi = zalloc ( sizeof ( *undi ) );
- if ( ! undi )
- return -ENOMEM;
- pci_set_drvdata ( pci, undi );
-
-
- if ( preloaded_undi.pci_busdevfn == busdevfn ) {
-
- DBGC ( undi, "UNDI %p using preloaded UNDI device\n", undi );
- memcpy ( undi, &preloaded_undi, sizeof ( *undi ) );
- memset ( &preloaded_undi, 0, sizeof ( preloaded_undi ) );
- } else {
-
- if ( ! ( undirom = undipci_find_rom ( pci ) ) ) {
- rc = -ENODEV;
- goto err_find_rom;
- }
-
-
- if ( ( rc = undi_load_pci ( undi, undirom, busdevfn ) ) != 0 )
- goto err_load_pci;
- }
-
-
- snprintf ( undi->dev.name, sizeof ( undi->dev.name ),
- "UNDI-%s", pci->dev.name );
- memcpy ( &undi->dev.desc, &pci->dev.desc, sizeof ( undi->dev.desc ) );
- undi->dev.parent = &pci->dev;
- INIT_LIST_HEAD ( &undi->dev.children );
- list_add ( &undi->dev.siblings, &pci->dev.children );
-
-
- if ( ( rc = undinet_probe ( undi ) ) != 0 )
- goto err_undinet_probe;
-
- return 0;
-
- err_undinet_probe:
- undi_unload ( undi );
- list_del ( &undi->dev.siblings );
- err_find_rom:
- err_load_pci:
- free ( undi );
- pci_set_drvdata ( pci, NULL );
- return rc;
- }
-
-
- static void undipci_remove ( struct pci_device *pci ) {
- struct undi_device *undi = pci_get_drvdata ( pci );
-
- undinet_remove ( undi );
- undi_unload ( undi );
- list_del ( &undi->dev.siblings );
- free ( undi );
- pci_set_drvdata ( pci, NULL );
- }
-
- static struct pci_device_id undipci_nics[] = {
- PCI_ROM ( 0xffff, 0xffff, "undipci", "UNDI (PCI)" ),
- };
-
- struct pci_driver undipci_driver __pci_driver = {
- .ids = undipci_nics,
- .id_count = ( sizeof ( undipci_nics ) / sizeof ( undipci_nics[0] ) ),
- .probe = undipci_probe,
- .remove = undipci_remove,
- };
|