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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. *
  19. * You can also choose to distribute this program under the terms of
  20. * the Unmodified Binary Distribution Licence (as given in the file
  21. * COPYING.UBDL), provided that you have satisfied its requirements.
  22. */
  23. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. #include <stdint.h>
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27. #include <string.h>
  28. #include <ipxe/device.h>
  29. #include <ipxe/init.h>
  30. #include <ipxe/pci.h>
  31. #include <undi.h>
  32. #include <undinet.h>
  33. #include <undipreload.h>
  34. /** @file
  35. *
  36. * "Pure" UNDI driver
  37. *
  38. * This is the UNDI driver without explicit support for PCI or any
  39. * other bus type. It is capable only of using the preloaded UNDI
  40. * device. It must not be combined in an image with any other
  41. * drivers.
  42. *
  43. * If you want a PXE-loadable image that contains only the UNDI
  44. * driver, build "bin/undionly.kpxe".
  45. *
  46. * If you want any other image format, or any other drivers in
  47. * addition to the UNDI driver, build e.g. "bin/undi.dsk".
  48. */
  49. /**
  50. * Probe UNDI root bus
  51. *
  52. * @v rootdev UNDI bus root device
  53. *
  54. * Scans the UNDI bus for devices and registers all devices it can
  55. * find.
  56. */
  57. static int undibus_probe ( struct root_device *rootdev ) {
  58. struct undi_device *undi = &preloaded_undi;
  59. int rc;
  60. /* Check for a valie preloaded UNDI device */
  61. if ( ! undi->entry.segment ) {
  62. DBG ( "No preloaded UNDI device found!\n" );
  63. return -ENODEV;
  64. }
  65. /* Add to device hierarchy */
  66. undi->dev.driver_name = "undionly";
  67. if ( undi->pci_busdevfn != UNDI_NO_PCI_BUSDEVFN ) {
  68. undi->dev.desc.bus_type = BUS_TYPE_PCI;
  69. undi->dev.desc.location = undi->pci_busdevfn;
  70. undi->dev.desc.vendor = undi->pci_vendor;
  71. undi->dev.desc.device = undi->pci_device;
  72. snprintf ( undi->dev.name, sizeof ( undi->dev.name ),
  73. "UNDI-PCI%02x:%02x.%x",
  74. PCI_BUS ( undi->pci_busdevfn ),
  75. PCI_SLOT ( undi->pci_busdevfn ),
  76. PCI_FUNC ( undi->pci_busdevfn ) );
  77. } else if ( undi->isapnp_csn != UNDI_NO_ISAPNP_CSN ) {
  78. undi->dev.desc.bus_type = BUS_TYPE_ISAPNP;
  79. snprintf ( undi->dev.name, sizeof ( undi->dev.name ),
  80. "UNDI-ISAPNP" );
  81. }
  82. undi->dev.parent = &rootdev->dev;
  83. list_add ( &undi->dev.siblings, &rootdev->dev.children);
  84. INIT_LIST_HEAD ( &undi->dev.children );
  85. /* Create network device */
  86. if ( ( rc = undinet_probe ( undi ) ) != 0 )
  87. goto err;
  88. return 0;
  89. err:
  90. list_del ( &undi->dev.siblings );
  91. return rc;
  92. }
  93. /**
  94. * Remove UNDI root bus
  95. *
  96. * @v rootdev UNDI bus root device
  97. */
  98. static void undibus_remove ( struct root_device *rootdev __unused ) {
  99. struct undi_device *undi = &preloaded_undi;
  100. undinet_remove ( undi );
  101. list_del ( &undi->dev.siblings );
  102. }
  103. /** UNDI bus root device driver */
  104. static struct root_driver undi_root_driver = {
  105. .probe = undibus_probe,
  106. .remove = undibus_remove,
  107. };
  108. /** UNDI bus root device */
  109. struct root_device undi_root_device __root_device = {
  110. .dev = { .name = "UNDI" },
  111. .driver = &undi_root_driver,
  112. };
  113. /**
  114. * Prepare for exit
  115. *
  116. * @v booting System is shutting down for OS boot
  117. */
  118. static void undionly_shutdown ( int booting ) {
  119. /* If we are shutting down to boot an OS, clear the "keep PXE
  120. * stack" flag.
  121. */
  122. if ( booting )
  123. preloaded_undi.flags &= ~UNDI_FL_KEEP_ALL;
  124. }
  125. struct startup_fn startup_undionly __startup_fn ( STARTUP_LATE ) = {
  126. .shutdown = undionly_shutdown,
  127. };