iPXE
Functions | Variables
device.c File Reference

Device model. More...

#include <string.h>
#include <ipxe/list.h>
#include <ipxe/tables.h>
#include <ipxe/init.h>
#include <ipxe/interface.h>
#include <ipxe/device.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static LIST_HEAD (devices)
 Registered root devices. More...
 
static int rootdev_probe (struct root_device *rootdev)
 Probe a root device. More...
 
static void rootdev_remove (struct root_device *rootdev)
 Remove a root device. More...
 
static void probe_devices (void)
 Probe all devices. More...
 
static void remove_devices (int booting __unused)
 Remove all devices. More...
 
struct startup_fn startup_devices __startup_fn (STARTUP_NORMAL)
 
struct deviceidentify_device (struct interface *intf)
 Identify a device behind an interface. More...
 

Variables

int device_keep_count = 0
 Device removal inhibition counter. More...
 

Detailed Description

Device model.

Definition in file device.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ LIST_HEAD()

static LIST_HEAD ( devices  )
static

Registered root devices.

◆ rootdev_probe()

static int rootdev_probe ( struct root_device rootdev)
static

Probe a root device.

Parameters
rootdevRoot device
Return values
rcReturn status code

Definition at line 52 of file device.c.

52  {
53  int rc;
54 
55  DBG ( "Adding %s root bus\n", rootdev->dev.name );
56  if ( ( rc = rootdev->driver->probe ( rootdev ) ) != 0 ) {
57  DBG ( "Failed to add %s root bus: %s\n",
58  rootdev->dev.name, strerror ( rc ) );
59  return rc;
60  }
61 
62  return 0;
63 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
char name[40]
Name.
Definition: device.h:75
struct device dev
Device chain.
Definition: device.h:99
struct root_driver * driver
Root device driver.
Definition: device.h:101
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
int(* probe)(struct root_device *rootdev)
Add root device.
Definition: device.h:116
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498

References DBG, root_device::dev, root_device::driver, device::name, root_driver::probe, rc, and strerror().

Referenced by probe_devices().

◆ rootdev_remove()

static void rootdev_remove ( struct root_device rootdev)
static

Remove a root device.

Parameters
rootdevRoot device

Definition at line 70 of file device.c.

70  {
71  rootdev->driver->remove ( rootdev );
72  DBG ( "Removed %s root bus\n", rootdev->dev.name );
73 }
void(* remove)(struct root_device *rootdev)
Remove root device.
Definition: device.h:125
char name[40]
Name.
Definition: device.h:75
struct device dev
Device chain.
Definition: device.h:99
struct root_driver * driver
Root device driver.
Definition: device.h:101
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498

References DBG, root_device::dev, root_device::driver, device::name, and root_driver::remove.

Referenced by remove_devices().

◆ probe_devices()

static void probe_devices ( void  )
static

Probe all devices.

This initiates probing for all devices in the system. After this call, the device hierarchy will be populated, and all hardware should be ready to use.

Definition at line 82 of file device.c.

82  {
83  struct root_device *rootdev;
84  int rc;
85 
86  for_each_table_entry ( rootdev, ROOT_DEVICES ) {
87  list_add ( &rootdev->dev.siblings, &devices );
88  INIT_LIST_HEAD ( &rootdev->dev.children );
89  if ( ( rc = rootdev_probe ( rootdev ) ) != 0 )
90  list_del ( &rootdev->dev.siblings );
91  }
92 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
A root device.
Definition: device.h:94
#define ROOT_DEVICES
Root device table.
Definition: device.h:129
struct device dev
Device chain.
Definition: device.h:99
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
struct list_head siblings
Devices on the same bus.
Definition: device.h:81
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
static int rootdev_probe(struct root_device *rootdev)
Probe a root device.
Definition: device.c:52
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
struct list_head children
Devices attached to this device.
Definition: device.h:83

References device::children, root_device::dev, for_each_table_entry, INIT_LIST_HEAD, list_add, list_del, rc, ROOT_DEVICES, rootdev_probe(), and device::siblings.

◆ remove_devices()

static void remove_devices ( int booting  __unused)
static

Remove all devices.

Definition at line 98 of file device.c.

98  {
99  struct root_device *rootdev;
100  struct root_device *tmp;
101 
102  if ( device_keep_count != 0 ) {
103  DBG ( "Refusing to remove devices on shutdown\n" );
104  return;
105  }
106 
107  list_for_each_entry_safe ( rootdev, tmp, &devices, dev.siblings ) {
108  rootdev_remove ( rootdev );
109  list_del ( &rootdev->dev.siblings );
110  }
111 }
int device_keep_count
Device removal inhibition counter.
Definition: device.c:44
A root device.
Definition: device.h:94
struct device dev
Device chain.
Definition: device.h:99
unsigned long tmp
Definition: linux_pci.h:53
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define list_for_each_entry_safe(pos, tmp, head, member)
Iterate over entries in a list, safe against deletion of the current entry.
Definition: list.h:458
struct list_head siblings
Devices on the same bus.
Definition: device.h:81
static void rootdev_remove(struct root_device *rootdev)
Remove a root device.
Definition: device.c:70
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498

References DBG, root_device::dev, device_keep_count, list_del, list_for_each_entry_safe, rootdev_remove(), device::siblings, and tmp.

◆ __startup_fn()

struct startup_fn startup_devices __startup_fn ( STARTUP_NORMAL  )

◆ identify_device()

struct device* identify_device ( struct interface intf)

Identify a device behind an interface.

Parameters
intfInterface
Return values
deviceDevice, or NULL

Definition at line 125 of file device.c.

125  {
126  struct interface *dest;
127  identify_device_TYPE ( void * ) *op =
129  void *object = intf_object ( dest );
130  void *device;
131 
132  if ( op ) {
133  device = op ( object );
134  } else {
135  /* Default is to return NULL */
136  device = NULL;
137  }
138 
139  intf_put ( dest );
140  return device;
141 }
uint16_t device
Device ID.
Definition: ena.h:24
void * intf_object(struct interface *intf)
Get pointer to object containing object interface.
Definition: interface.c:159
struct interface * intf
Original interface.
Definition: interface.h:158
A hardware device.
Definition: device.h:73
An object interface.
Definition: interface.h:124
static void * dest
Definition: strings.h:176
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
void intf_put(struct interface *intf)
Decrement reference count on an object interface.
Definition: interface.c:149
#define identify_device_TYPE(object_type)
Definition: device.h:174
struct device * identify_device(struct interface *intf)
Identify a device behind an interface.
Definition: device.c:125
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#define intf_get_dest_op(intf, type, dest)
Get object interface destination and operation method.
Definition: interface.h:269

References dest, device, identify_device(), identify_device_TYPE, interface::intf, intf_get_dest_op, intf_object(), intf_put(), NULL, and op.

Referenced by fcpdev_identify_device(), identify_device(), and int13_device_path_info().

Variable Documentation

◆ device_keep_count

int device_keep_count = 0

Device removal inhibition counter.

Definition at line 44 of file device.c.

Referenced by devices_get(), devices_put(), and remove_devices().