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 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. /** UNDI root bus device */
  50. static struct device undibus_dev;
  51. /**
  52. * Probe UNDI root bus
  53. *
  54. * @v rootdev UNDI bus root device
  55. *
  56. * Scans the UNDI bus for devices and registers all devices it can
  57. * find.
  58. */
  59. static int undibus_probe ( struct root_device *rootdev ) {
  60. struct undi_device *undi = &preloaded_undi;
  61. struct device *dev = &undibus_dev;
  62. int rc;
  63. /* Check for a valie preloaded UNDI device */
  64. if ( ! undi->entry.segment ) {
  65. DBG ( "No preloaded UNDI device found!\n" );
  66. return -ENODEV;
  67. }
  68. /* Add to device hierarchy */
  69. dev->driver_name = "undionly";
  70. if ( undi->pci_busdevfn != UNDI_NO_PCI_BUSDEVFN ) {
  71. dev->desc.bus_type = BUS_TYPE_PCI;
  72. dev->desc.location = undi->pci_busdevfn;
  73. dev->desc.vendor = undi->pci_vendor;
  74. dev->desc.device = undi->pci_device;
  75. snprintf ( dev->name, sizeof ( dev->name ),
  76. "0000:%02x:%02x.%x", PCI_BUS ( undi->pci_busdevfn ),
  77. PCI_SLOT ( undi->pci_busdevfn ),
  78. PCI_FUNC ( undi->pci_busdevfn ) );
  79. } else if ( undi->isapnp_csn != UNDI_NO_ISAPNP_CSN ) {
  80. dev->desc.bus_type = BUS_TYPE_ISAPNP;
  81. snprintf ( dev->name, sizeof ( dev->name ), "ISAPNP" );
  82. }
  83. dev->parent = &rootdev->dev;
  84. list_add ( &dev->siblings, &rootdev->dev.children);
  85. INIT_LIST_HEAD ( &dev->children );
  86. /* Create network device */
  87. if ( ( rc = undinet_probe ( undi, dev ) ) != 0 )
  88. goto err;
  89. return 0;
  90. err:
  91. list_del ( &dev->siblings );
  92. return rc;
  93. }
  94. /**
  95. * Remove UNDI root bus
  96. *
  97. * @v rootdev UNDI bus root device
  98. */
  99. static void undibus_remove ( struct root_device *rootdev __unused ) {
  100. struct undi_device *undi = &preloaded_undi;
  101. struct device *dev = &undibus_dev;
  102. undinet_remove ( undi );
  103. list_del ( &dev->siblings );
  104. }
  105. /** UNDI bus root device driver */
  106. static struct root_driver undi_root_driver = {
  107. .probe = undibus_probe,
  108. .remove = undibus_remove,
  109. };
  110. /** UNDI bus root device */
  111. struct root_device undi_root_device __root_device = {
  112. .dev = { .name = "UNDI" },
  113. .driver = &undi_root_driver,
  114. };
  115. /**
  116. * Prepare for exit
  117. *
  118. * @v booting System is shutting down for OS boot
  119. */
  120. static void undionly_shutdown ( int booting ) {
  121. /* If we are shutting down to boot an OS, clear the "keep PXE
  122. * stack" flag.
  123. */
  124. if ( booting )
  125. preloaded_undi.flags &= ~UNDI_FL_KEEP_ALL;
  126. }
  127. struct startup_fn startup_undionly __startup_fn ( STARTUP_LATE ) = {
  128. .name = "undionly",
  129. .shutdown = undionly_shutdown,
  130. };