iPXE
Data Structures | Functions | Variables
pci_cmd.c File Reference

PCI commands. More...

#include <stdio.h>
#include <errno.h>
#include <getopt.h>
#include <ipxe/pci.h>
#include <ipxe/command.h>
#include <ipxe/parseopt.h>

Go to the source code of this file.

Data Structures

struct  pciscan_options
 "pciscan" options More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int pciscan_exec (int argc, char **argv)
 "pciscan" command More...
 

Variables

static struct option_descriptor pciscan_opts [] = {}
 "pciscan" option list More...
 
static struct command_descriptor pciscan_cmd
 "pciscan" command descriptor More...
 
struct command pci_commands [] __command
 PCI commands. More...
 

Detailed Description

PCI commands.

Definition in file pci_cmd.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ pciscan_exec()

static int pciscan_exec ( int  argc,
char **  argv 
)
static

"pciscan" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 57 of file pci_cmd.c.

57  {
58  struct pciscan_options opts;
59  struct named_setting setting;
60  struct pci_device pci;
61  unsigned long prev;
63  int len;
64  int rc;
65 
66  /* Parse options */
67  if ( ( rc = parse_options ( argc, argv, &pciscan_cmd, &opts ) ) != 0 )
68  goto err_parse_options;
69 
70  /* Parse setting name */
71  if ( ( rc = parse_autovivified_setting ( argv[optind],
72  &setting ) ) != 0 )
73  goto err_parse_setting;
74 
75  /* Determine starting bus:dev.fn address */
76  if ( ( len = fetchn_setting ( setting.settings, &setting.setting,
77  NULL, &setting.setting, &prev ) ) < 0 ) {
78  /* Setting not yet defined: start searching from 00:00.0 */
79  busdevfn = 0;
80  } else {
81  /* Setting is defined: start searching from next location */
82  busdevfn = ( prev + 1 );
83  if ( ! busdevfn ) {
84  rc = -ENOENT;
85  goto err_end;
86  }
87  }
88 
89  /* Find next existent PCI device */
90  if ( ( rc = pci_find_next ( &pci, &busdevfn ) ) != 0 )
91  goto err_find_next;
92 
93  /* Apply default type if necessary. Use ":uint16" rather than
94  * ":busdevfn" to allow for easy inclusion within a
95  * "${pci/${location}.x.y}" constructed setting.
96  */
97  if ( ! setting.setting.type )
98  setting.setting.type = &setting_type_uint16;
99 
100  /* Store setting */
101  if ( ( rc = storen_setting ( setting.settings, &setting.setting,
102  busdevfn ) ) != 0 ) {
103  printf ( "Could not store \"%s\": %s\n",
104  setting.setting.name, strerror ( rc ) );
105  goto err_store;
106  }
107 
108  err_store:
109  err_end:
110  err_find_next:
111  err_parse_setting:
112  err_parse_options:
113  return rc;
114 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
A parsed named setting.
Definition: parseopt.h:122
int optind
Current option index.
Definition: getopt.c:51
int storen_setting(struct settings *settings, const struct setting *setting, unsigned long value)
Store numeric value of setting.
Definition: settings.c:1414
int parse_autovivified_setting(char *text, struct named_setting *setting)
Parse and autovivify setting name.
Definition: parseopt.c:336
#define ENOENT
No such file or directory.
Definition: errno.h:514
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:484
"pciscan" options
Definition: pci_cmd.c:40
const char * name
Name.
Definition: settings.h:28
uint16_t busdevfn
PCI bus:dev.fn address.
Definition: ena.h:28
int pci_find_next(struct pci_device *pci, uint32_t *busdevfn)
Find next device on PCI bus.
Definition: pci.c:236
const struct setting_type * type
Setting type.
Definition: settings.h:36
int fetchn_setting(struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, unsigned long *value)
Fetch numeric value of setting.
Definition: settings.c:1372
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
A PCI device.
Definition: pci.h:206
unsigned int uint32_t
Definition: stdint.h:12
static union @437 opts
"cert<xxx>" option list
A setting.
Definition: settings.h:23
uint32_t len
Length.
Definition: ena.h:14
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
static struct command_descriptor pciscan_cmd
"pciscan" command descriptor
Definition: pci_cmd.c:46

References busdevfn, ENOENT, fetchn_setting(), len, setting::name, NULL, optind, opts, parse_autovivified_setting(), parse_options(), pci_find_next(), pciscan_cmd, printf(), rc, storen_setting(), strerror(), and setting::type.

Variable Documentation

◆ pciscan_opts

struct option_descriptor pciscan_opts[] = {}
static

"pciscan" option list

Definition at line 43 of file pci_cmd.c.

◆ pciscan_cmd

struct command_descriptor pciscan_cmd
static
Initial value:
=
"<setting>" )
"pciscan" options
Definition: pci_cmd.c:40
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:108
static struct option_descriptor pciscan_opts[]
"pciscan" option list
Definition: pci_cmd.c:43

"pciscan" command descriptor

Definition at line 46 of file pci_cmd.c.

Referenced by pciscan_exec().

◆ __command

struct command pci_commands [] __command
Initial value:
= {
{
.name = "pciscan",
.exec = pciscan_exec,
},
}
static int pciscan_exec(int argc, char **argv)
"pciscan" command
Definition: pci_cmd.c:57

PCI commands.

Definition at line 117 of file pci_cmd.c.