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

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