Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (C) 2013 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. * You can also choose to distribute this program under the terms of
  20. * the Unmodified Binary Distribution Licence (as given in the file
  21. * COPYING.UBDL), provided that you have satisfied its requirements.
  22. */
  23. #include <stdio.h>
  24. #include <getopt.h>
  25. #include <ipxe/pci.h>
  26. #include <ipxe/command.h>
  27. #include <ipxe/parseopt.h>
  28. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  29. /** @file
  30. *
  31. * PCI commands
  32. *
  33. */
  34. /** "pciscan" options */
  35. struct pciscan_options {};
  36. /** "pciscan" option list */
  37. static struct option_descriptor pciscan_opts[] = {};
  38. /** "pciscan" command descriptor */
  39. static struct command_descriptor pciscan_cmd =
  40. COMMAND_DESC ( struct pciscan_options, pciscan_opts, 1, 1,
  41. "<setting>" );
  42. /**
  43. * "pciscan" command
  44. *
  45. * @v argc Argument count
  46. * @v argv Argument list
  47. * @ret rc Return status code
  48. */
  49. static int pciscan_exec ( int argc, char **argv ) {
  50. struct pciscan_options opts;
  51. struct named_setting setting;
  52. struct pci_device pci;
  53. unsigned long prev;
  54. int next;
  55. int len;
  56. int rc;
  57. /* Parse options */
  58. if ( ( rc = parse_options ( argc, argv, &pciscan_cmd, &opts ) ) != 0 )
  59. goto err_parse_options;
  60. /* Parse setting name */
  61. if ( ( rc = parse_autovivified_setting ( argv[optind],
  62. &setting ) ) != 0 )
  63. goto err_parse_setting;
  64. /* Determine starting bus:dev.fn address */
  65. if ( ( len = fetchn_setting ( setting.settings, &setting.setting,
  66. NULL, &setting.setting, &prev ) ) < 0 ) {
  67. /* Setting not yet defined: start searching from 00:00.0 */
  68. prev = 0;
  69. } else {
  70. /* Setting is defined: start searching from next location */
  71. prev++;
  72. }
  73. /* Find next existent PCI device */
  74. if ( ( next = pci_find_next ( &pci, prev ) ) < 0 ) {
  75. rc = next;
  76. goto err_find_next;
  77. }
  78. /* Apply default type if necessary. Use ":uint16" rather than
  79. * ":busdevfn" to allow for easy inclusion within a
  80. * "${pci/${location}.x.y}" constructed setting.
  81. */
  82. if ( ! setting.setting.type )
  83. setting.setting.type = &setting_type_uint16;
  84. /* Store setting */
  85. if ( ( rc = storen_setting ( setting.settings, &setting.setting,
  86. next ) ) != 0 ) {
  87. printf ( "Could not store \"%s\": %s\n",
  88. setting.setting.name, strerror ( rc ) );
  89. goto err_store;
  90. }
  91. err_store:
  92. err_find_next:
  93. err_parse_setting:
  94. err_parse_options:
  95. return rc;
  96. }
  97. /** PCI commands */
  98. struct command pci_commands[] __command = {
  99. {
  100. .name = "pciscan",
  101. .exec = pciscan_exec,
  102. },
  103. };