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

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