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.

device.c 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (C) 2006 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 <string.h>
  20. #include <gpxe/list.h>
  21. #include <gpxe/tables.h>
  22. #include <gpxe/device.h>
  23. #include <gpxe/init.h>
  24. /**
  25. * @file
  26. *
  27. * Device model
  28. *
  29. */
  30. /** Registered root devices */
  31. static LIST_HEAD ( devices );
  32. /**
  33. * Probe a root device
  34. *
  35. * @v rootdev Root device
  36. * @ret rc Return status code
  37. */
  38. static int rootdev_probe ( struct root_device *rootdev ) {
  39. int rc;
  40. DBG ( "Adding %s root bus\n", rootdev->dev.name );
  41. if ( ( rc = rootdev->driver->probe ( rootdev ) ) != 0 ) {
  42. DBG ( "Failed to add %s root bus: %s\n",
  43. rootdev->dev.name, strerror ( rc ) );
  44. return rc;
  45. }
  46. return 0;
  47. }
  48. /**
  49. * Remove a root device
  50. *
  51. * @v rootdev Root device
  52. */
  53. static void rootdev_remove ( struct root_device *rootdev ) {
  54. rootdev->driver->remove ( rootdev );
  55. DBG ( "Removed %s root bus\n", rootdev->dev.name );
  56. }
  57. /**
  58. * Probe all devices
  59. *
  60. * This initiates probing for all devices in the system. After this
  61. * call, the device hierarchy will be populated, and all hardware
  62. * should be ready to use.
  63. */
  64. static void probe_devices ( void ) {
  65. struct root_device *rootdev;
  66. int rc;
  67. for_each_table_entry ( rootdev, ROOT_DEVICES ) {
  68. list_add ( &rootdev->dev.siblings, &devices );
  69. INIT_LIST_HEAD ( &rootdev->dev.children );
  70. if ( ( rc = rootdev_probe ( rootdev ) ) != 0 )
  71. list_del ( &rootdev->dev.siblings );
  72. }
  73. }
  74. /**
  75. * Remove all devices
  76. *
  77. */
  78. static void remove_devices ( int flags ) {
  79. struct root_device *rootdev;
  80. struct root_device *tmp;
  81. if ( flags & SHUTDOWN_KEEP_DEVICES ) {
  82. DBG ( "Refusing to remove devices on shutdown\n" );
  83. return;
  84. }
  85. list_for_each_entry_safe ( rootdev, tmp, &devices, dev.siblings ) {
  86. rootdev_remove ( rootdev );
  87. list_del ( &rootdev->dev.siblings );
  88. }
  89. }
  90. struct startup_fn startup_devices __startup_fn ( STARTUP_NORMAL ) = {
  91. .startup = probe_devices,
  92. .shutdown = remove_devices,
  93. };