iPXE
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)
 FILE_SECBOOT (PERMITTED)
static LIST_HEAD (devices)
 Registered root devices.
static int rootdev_probe (struct root_device *rootdev)
 Probe a root device.
static void rootdev_remove (struct root_device *rootdev)
 Remove a root device.
static void probe_devices (void)
 Probe all devices.
static void remove_devices (int booting __unused)
 Remove all devices.
struct startup_fn startup_devices __startup_fn (STARTUP_NORMAL)
struct deviceidentify_device (struct interface *intf)
 Identify a device behind an interface.

Variables

int device_keep_count = 0
 Device removal inhibition counter.

Detailed Description

Device model.

Definition in file device.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ LIST_HEAD()

LIST_HEAD ( devices )
static

Registered root devices.

◆ rootdev_probe()

int rootdev_probe ( struct root_device * rootdev)
static

Probe a root device.

Parameters
rootdevRoot device
Return values
rcReturn status code

Definition at line 53 of file device.c.

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

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

Referenced by probe_devices().

◆ rootdev_remove()

void rootdev_remove ( struct root_device * rootdev)
static

Remove a root device.

Parameters
rootdevRoot device

Definition at line 71 of file device.c.

71 {
72 rootdev->driver->remove ( rootdev );
73 DBG ( "Removed %s root bus\n", rootdev->dev.name );
74}
void(* remove)(struct root_device *rootdev)
Remove root device.
Definition device.h:129

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

Referenced by remove_devices().

◆ probe_devices()

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 83 of file device.c.

83 {
84 struct root_device *rootdev;
85 int rc;
86
88 list_add ( &rootdev->dev.siblings, &devices );
89 INIT_LIST_HEAD ( &rootdev->dev.children );
90 if ( ( rc = rootdev_probe ( rootdev ) ) != 0 )
91 list_del ( &rootdev->dev.siblings );
92 }
93}
static int rootdev_probe(struct root_device *rootdev)
Probe a root device.
Definition device.c:53
#define ROOT_DEVICES
Root device table.
Definition device.h:133
#define list_del(list)
Delete an entry from a list.
Definition list.h:120
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition list.h:46
#define list_add(new, head)
Add a new entry to the head of a list.
Definition list.h:70
struct list_head children
Devices attached to this device.
Definition device.h:87
struct list_head siblings
Devices on the same bus.
Definition device.h:85
A root device.
Definition device.h:98
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition tables.h:386

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.

Referenced by __startup_fn().

◆ remove_devices()

void remove_devices ( int booting __unused)
static

Remove all devices.

Definition at line 99 of file device.c.

99 {
100 struct root_device *rootdev;
101 struct root_device *tmp;
102
103 if ( device_keep_count != 0 ) {
104 DBG ( "Refusing to remove devices on shutdown\n" );
105 return;
106 }
107
108 list_for_each_entry_safe ( rootdev, tmp, &devices, dev.siblings ) {
109 rootdev_remove ( rootdev );
110 list_del ( &rootdev->dev.siblings );
111 }
112}
static void rootdev_remove(struct root_device *rootdev)
Remove a root device.
Definition device.c:71
int device_keep_count
Device removal inhibition counter.
Definition device.c:45
unsigned long tmp
Definition linux_pci.h:65
#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:459

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

Referenced by __startup_fn().

◆ __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 126 of file device.c.

126 {
127 struct interface *dest;
128 identify_device_TYPE ( void * ) *op =
130 void *object = intf_object ( dest );
131 void *device;
132
133 if ( op ) {
134 device = op ( object );
135 } else {
136 /* Default is to return NULL */
137 device = NULL;
138 }
139
140 intf_put ( dest );
141 return device;
142}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" retur dest)
Definition string.h:151
struct device * identify_device(struct interface *intf)
Identify a device behind an interface.
Definition device.c:126
#define identify_device_TYPE(object_type)
Definition device.h:178
void * intf_object(struct interface *intf)
Get pointer to object containing object interface.
Definition interface.c:160
void intf_put(struct interface *intf)
Decrement reference count on an object interface.
Definition interface.c:150
#define intf_get_dest_op(intf, type, dest)
Get object interface destination and operation method.
Definition interface.h:270
static uint16_t struct vmbus_xfer_pages_operations * op
Definition netvsc.h:327
A hardware device.
Definition device.h:77
An object interface.
Definition interface.h:125
struct interface * intf
Original interface.
Definition interface.h:159

References dest, 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 45 of file device.c.

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