Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

pci_cmd.c 2.9KB

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