You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

undionly.c 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #include <stdint.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <gpxe/device.h>
  22. #include <gpxe/init.h>
  23. #include <undi.h>
  24. #include <undinet.h>
  25. #include <undipreload.h>
  26. /** @file
  27. *
  28. * "Pure" UNDI driver
  29. *
  30. * This is the UNDI driver without explicit support for PCI or any
  31. * other bus type. It is capable only of using the preloaded UNDI
  32. * device. It must not be combined in an image with any other
  33. * drivers.
  34. *
  35. * If you want a PXE-loadable image that contains only the UNDI
  36. * driver, build "bin/undionly.kpxe".
  37. *
  38. * If you want any other image format, or any other drivers in
  39. * addition to the UNDI driver, build e.g. "bin/undi.dsk".
  40. */
  41. /**
  42. * Probe UNDI root bus
  43. *
  44. * @v rootdev UNDI bus root device
  45. *
  46. * Scans the UNDI bus for devices and registers all devices it can
  47. * find.
  48. */
  49. static int undibus_probe ( struct root_device *rootdev ) {
  50. struct undi_device *undi = &preloaded_undi;
  51. int rc;
  52. /* Check for a valie preloaded UNDI device */
  53. if ( ! undi->entry.segment ) {
  54. DBG ( "No preloaded UNDI device found!\n" );
  55. return -ENODEV;
  56. }
  57. /* Add to device hierarchy */
  58. strncpy ( undi->dev.name, "UNDI",
  59. ( sizeof ( undi->dev.name ) - 1 ) );
  60. if ( undi->pci_busdevfn != UNDI_NO_PCI_BUSDEVFN ) {
  61. undi->dev.desc.bus_type = BUS_TYPE_PCI;
  62. undi->dev.desc.location = undi->pci_busdevfn;
  63. undi->dev.desc.vendor = undi->pci_vendor;
  64. undi->dev.desc.device = undi->pci_device;
  65. } else if ( undi->isapnp_csn != UNDI_NO_ISAPNP_CSN ) {
  66. undi->dev.desc.bus_type = BUS_TYPE_ISAPNP;
  67. }
  68. undi->dev.parent = &rootdev->dev;
  69. list_add ( &undi->dev.siblings, &rootdev->dev.children);
  70. INIT_LIST_HEAD ( &undi->dev.children );
  71. /* Create network device */
  72. if ( ( rc = undinet_probe ( undi ) ) != 0 )
  73. goto err;
  74. return 0;
  75. err:
  76. list_del ( &undi->dev.siblings );
  77. return rc;
  78. }
  79. /**
  80. * Remove UNDI root bus
  81. *
  82. * @v rootdev UNDI bus root device
  83. */
  84. static void undibus_remove ( struct root_device *rootdev __unused ) {
  85. struct undi_device *undi = &preloaded_undi;
  86. undinet_remove ( undi );
  87. list_del ( &undi->dev.siblings );
  88. }
  89. /** UNDI bus root device driver */
  90. static struct root_driver undi_root_driver = {
  91. .probe = undibus_probe,
  92. .remove = undibus_remove,
  93. };
  94. /** UNDI bus root device */
  95. struct root_device undi_root_device __root_device = {
  96. .dev = { .name = "UNDI" },
  97. .driver = &undi_root_driver,
  98. };
  99. /**
  100. * Prepare for exit
  101. *
  102. * @v flags Shutdown flags
  103. */
  104. static void undionly_shutdown ( int flags ) {
  105. /* If we are shutting down to boot an OS, clear the "keep PXE
  106. * stack" flag.
  107. */
  108. if ( flags & SHUTDOWN_BOOT )
  109. preloaded_undi.flags &= ~UNDI_FL_KEEP_ALL;
  110. }
  111. struct startup_fn startup_undionly __startup_fn ( STARTUP_LATE ) = {
  112. .shutdown = undionly_shutdown,
  113. };