2 * Copyright (C) 2013 Michael Brown <mbrown@fensystems.co.uk>.
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.
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.
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
23 #include <ipxe/command.h>
24 #include <ipxe/parseopt.h>
26 FILE_LICENCE ( GPL2_OR_LATER );
34 /** "pciscan" options */
35 struct pciscan_options {};
37 /** "pciscan" option list */
38 static struct option_descriptor pciscan_opts[] = {};
40 /** "pciscan" command descriptor */
41 static struct command_descriptor pciscan_cmd =
42 COMMAND_DESC ( struct pciscan_options, pciscan_opts, 1, 1,
48 * @v argc Argument count
49 * @v argv Argument list
50 * @ret rc Return status code
52 static int pciscan_exec ( int argc, char **argv ) {
53 struct pciscan_options opts;
54 struct named_setting setting;
55 struct pci_device pci;
62 if ( ( rc = parse_options ( argc, argv, &pciscan_cmd, &opts ) ) != 0 )
63 goto err_parse_options;
65 /* Parse setting name */
66 if ( ( rc = parse_autovivified_setting ( argv[optind],
68 goto err_parse_setting;
70 /* Determine starting bus:dev.fn address */
71 if ( ( len = fetchn_setting ( setting.settings, &setting.setting,
72 NULL, &setting.setting, &prev ) ) < 0 ) {
73 /* Setting not yet defined: start searching from 00:00.0 */
76 /* Setting is defined: start searching from next location */
80 /* Find next existent PCI device */
81 if ( ( next = pci_find_next ( &pci, prev ) ) < 0 ) {
86 /* Apply default type if necessary. Use ":uint16" rather than
87 * ":busdevfn" to allow for easy inclusion within a
88 * "${pci/${location}.x.y}" constructed setting.
90 if ( ! setting.setting.type )
91 setting.setting.type = &setting_type_uint16;
94 if ( ( rc = storen_setting ( setting.settings, &setting.setting,
96 printf ( "Could not store \"%s\": %s\n",
97 setting.setting.name, strerror ( rc ) );
109 struct command pci_commands[] __command = {
112 .exec = pciscan_exec,