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

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