Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

device.c 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 <gpxe/list.h>
  19. #include <gpxe/tables.h>
  20. #include <gpxe/device.h>
  21. #include "stdio.h"
  22. /**
  23. * @file
  24. *
  25. * Device model
  26. *
  27. */
  28. static struct root_device root_devices[0] __table_start ( root_devices );
  29. static struct root_device root_devices_end[0] __table_end ( root_devices );
  30. /** Registered root devices */
  31. static LIST_HEAD ( devices );
  32. /**
  33. * Register a root device
  34. *
  35. * @v rootdev Root device
  36. * @ret rc Return status code
  37. *
  38. * Calls the root device driver's probe() method, and adds it to the
  39. * list of registered root devices if successful.
  40. */
  41. static int register_rootdev ( struct root_device *rootdev ) {
  42. int rc;
  43. DBG ( "Registering %s root bus\n", rootdev->name );
  44. if ( ( rc = rootdev->driver->probe ( rootdev ) ) != 0 )
  45. return rc;
  46. list_add ( &rootdev->dev.siblings, &devices );
  47. return 0;
  48. }
  49. /**
  50. * Unregister a root device
  51. *
  52. * @v rootdev Root device
  53. */
  54. static void unregister_rootdev ( struct root_device *rootdev ) {
  55. rootdev->driver->remove ( rootdev );
  56. list_del ( &rootdev->dev.siblings );
  57. DBG ( "Unregistered %s root bus\n", rootdev->name );
  58. }
  59. /**
  60. * Probe all devices
  61. *
  62. * @ret rc Return status code
  63. *
  64. * This initiates probing for all devices in the system. After this
  65. * call, the device hierarchy will be populated, and all hardware
  66. * should be ready to use.
  67. */
  68. int probe_devices ( void ) {
  69. struct root_device *rootdev;
  70. for ( rootdev = root_devices; rootdev < root_devices_end; rootdev++ ) {
  71. register_rootdev ( rootdev );
  72. }
  73. return 0;
  74. }
  75. /**
  76. * Remove all devices
  77. *
  78. */
  79. void remove_devices ( void ) {
  80. struct root_device *rootdev;
  81. struct root_device *tmp;
  82. list_for_each_entry_safe ( rootdev, tmp, &devices, dev.siblings ) {
  83. unregister_rootdev ( rootdev );
  84. }
  85. }