Device manager.

HelenOS device manager. More...

Files

file  main.c

Data Structures

struct  class_list
 The list of device classes. More...
struct  dev_class
struct  dev_class_info
 Provides n-to-m mapping between function nodes and classes - each function can register in an arbitrary number of classes and each class can contain an arbitrary number of device functions. More...
struct  dev_node
 Device node in the device tree. More...
struct  dev_tree
 Represents device tree. More...
struct  driver
 Driver structure. More...
struct  driver_list
 The list of drivers. More...
struct  fun_node
 Function node in the device tree. More...
struct  match_id
 Ids of device models used for device-to-driver matching. More...
struct  match_id_list
 List of ids for matching devices to drivers sorted according to match scores in descending order. More...

Defines

#define DEVICE_BUCKETS   256
#define DEVMAN_NAME_MAXLEN   256
#define DEVMAP_CLASS_NAMESPACE   "class"
#define DEVMAP_DEVICE_NAMESPACE   "devices"
#define DEVMAP_SEPARATOR   '\\'
#define DRIVER_DEFAULT_STORE   "/drv"
#define MATCH_EXT   ".ma"
#define NAME   "devman"

Typedefs

typedef class_list class_list_t
 The list of device classes.
typedef dev_class_info dev_class_info_t
 Provides n-to-m mapping between function nodes and classes - each function can register in an arbitrary number of classes and each class can contain an arbitrary number of device functions.
typedef dev_node dev_node_t
typedef dev_tree dev_tree_t
 Represents device tree.
typedef sysarg_t devman_handle_t
typedef driver_list driver_list_t
 The list of drivers.
typedef driver driver_t
 Representation of device driver.
typedef fun_node fun_node_t
typedef match_id_list match_id_list_t
 List of ids for matching devices to drivers sorted according to match scores in descending order.
typedef match_id match_id_t
 Ids of device models used for device-to-driver matching.

Enumerations

enum  client_to_devman_t
enum  device_state_t
 The state of the device.
enum  devman_interface_t
enum  devman_to_driver_t
enum  driver_state_t { DRIVER_NOT_STARTED = 0, DRIVER_STARTING, DRIVER_RUNNING }
enum  driver_to_devman_t
enum  fun_type_t { fun_invalid = 0, fun_inner, fun_exposed }

Functions

void add_dev_class_no_lock (class_list_t *class_list, dev_class_t *cl)
void add_device (int phone, driver_t *drv, dev_node_t *dev, dev_tree_t *tree)
 Pass a device to running driver.
void add_driver (driver_list_t *drivers_list, driver_t *drv)
 Add a driver to the list of drivers.
dev_class_info_tadd_function_to_class (fun_node_t *fun, dev_class_t *cl, const char *base_dev_name)
 Add the device function to the class.
static void add_match_id (match_id_list_t *ids, match_id_t *id)
bool assign_driver (dev_node_t *dev, driver_list_t *drivers_list, dev_tree_t *tree)
 Find suitable driver for a device and assign the driver to it.
static int assign_driver_fibril (void *arg)
void attach_driver (dev_node_t *dev, driver_t *drv)
 Assign a driver to a device.
void class_add_devmap_function (class_list_t *class_list, dev_class_info_t *cli)
void clean_driver (driver_t *drv)
 Device driver structure clean-up.
static void clean_match_ids (match_id_list_t *ids)
char * clone_string (const char *s)
static int compute_match_score (match_id_t *driver, match_id_t *device)
 Compute compound score of driver and device.
dev_class_tcreate_dev_class (void)
 Create device class.
dev_class_info_tcreate_dev_class_info (void)
 Create device class info.
char * create_dev_name_for_class (dev_class_t *cl, const char *base_dev_name)
 Create unique device name within the class.
dev_node_tcreate_dev_node (void)
 Create a new device node.
driver_tcreate_driver (void)
 Allocate and initialize a new driver structure.
fun_node_tcreate_fun_node (void)
 Create a new function node.
static match_id_tcreate_match_id (void)
bool create_root_nodes (dev_tree_t *tree)
 Create root device and function node in the device tree.
void delete_dev_node (dev_node_t *dev)
 Delete a device node.
void delete_driver (driver_t *drv)
 Delete device driver structure.
void delete_fun_node (fun_node_t *fun)
 Delete a function node.
static void delete_match_id (match_id_t *id)
static hash_index_t devices_hash (unsigned long key[])
static void devices_remove_callback (link_t *item)
static void devman_add_function (ipc_callid_t callid, ipc_call_t *call)
 Handle function registration.
static void devman_add_function_to_class (ipc_callid_t callid, ipc_call_t *call)
static void devman_connection (ipc_callid_t iid, ipc_call_t *icall)
 Function for handling connections to device manager.
static void devman_connection_client (ipc_callid_t iid, ipc_call_t *icall)
 Function for handling connections from a client to the device manager.
static void devman_connection_devmapper (ipc_callid_t iid, ipc_call_t *icall)
 Function for handling connections from a client forwarded by the device mapper to the device manager.
static void devman_connection_driver (ipc_callid_t iid, ipc_call_t *icall)
 Function for handling connections from a driver to the device manager.
static int devman_devices_compare (unsigned long key[], hash_count_t keys, link_t *item)
static driver_tdevman_driver_register (void)
 Register running driver.
static void devman_forward (ipc_callid_t iid, ipc_call_t *icall, bool drv_to_parent)
static void devman_function_get_handle (ipc_callid_t iid, ipc_call_t *icall)
 Find handle for the device instance identified by the device's path in the device tree.
static void devman_function_get_handle_by_class (ipc_callid_t iid, ipc_call_t *icall)
 Find handle for the device instance identified by device class name.
static int devman_functions_compare (unsigned long key[], hash_count_t keys, link_t *item)
static void devman_get_device_path_by_handle (ipc_callid_t iid, ipc_call_t *icall)
 Find device path by its handle.
static bool devman_init (void)
 Initialize device manager internal structures.
static int devman_receive_match_id (match_id_list_t *match_ids)
 Receive device match ID from the device's parent driver and add it to the list of devices match ids.
static int devman_receive_match_ids (sysarg_t match_count, match_id_list_t *match_ids)
 Receive device match IDs from the device's parent driver and add them to the list of devices match ids.
static int devmap_devices_class_compare (unsigned long key[], hash_count_t keys, link_t *item)
static int devmap_functions_compare (unsigned long key[], hash_count_t keys, link_t *item)
static void devmap_register_class_dev (dev_class_info_t *cli)
void devmap_register_tree_function (fun_node_t *fun, dev_tree_t *tree)
 Create devmap path and name for the function.
driver_tfind_best_match_driver (driver_list_t *drivers_list, dev_node_t *node)
 Lookup the best matching driver for the specified device in the list of drivers.
dev_class_tfind_dev_class_no_lock (class_list_t *class_list, const char *class_name)
dev_class_info_tfind_dev_in_class (dev_class_t *dev_class, const char *dev_name)
dev_node_tfind_dev_node (dev_tree_t *tree, devman_handle_t handle)
 Find the device node structure of the device witch has the specified handle.
dev_node_tfind_dev_node_no_lock (dev_tree_t *tree, devman_handle_t handle)
 Find the device node structure of the device witch has the specified handle.
fun_node_tfind_devmap_class_function (class_list_t *classes, devmap_handle_t devmap_handle)
fun_node_tfind_devmap_tree_function (dev_tree_t *tree, devmap_handle_t devmap_handle)
driver_tfind_driver (driver_list_t *drv_list, const char *drv_name)
 Find device driver in the list of device drivers.
fun_node_tfind_fun_node (dev_tree_t *tree, devman_handle_t handle)
 Find the function node with the specified handle.
fun_node_tfind_fun_node_by_class (class_list_t *class_list, const char *class_name, const char *dev_name)
 Find function node by its class name and index.
fun_node_tfind_fun_node_by_path (dev_tree_t *tree, char *path)
 Find function node with a specified path in the device tree.
fun_node_tfind_fun_node_in_device (dev_node_t *dev, const char *name)
 Find function with a specified name belonging to given device.
fun_node_tfind_fun_node_no_lock (dev_tree_t *tree, devman_handle_t handle)
 Find the function node with the specified handle.
fun_node_tfind_node_child (fun_node_t *pfun, const char *name)
 Find child function node with a specified name.
void free_not_null (const void *ptr)
char * get_abs_path (const char *base_path, const char *name, const char *ext)
dev_class_tget_dev_class (class_list_t *class_list, char *class_name)
bool get_driver_info (const char *base_path, const char *name, driver_t *drv)
 Get information about a driver.
int get_match_score (driver_t *, dev_node_t *)
size_t get_new_class_dev_idx (dev_class_t *cl)
size_t get_nonspace_len (const char *str)
char * get_path_elem_end (char *path)
void init_class_list (class_list_t *class_list)
bool init_device_tree (dev_tree_t *tree, driver_list_t *drivers_list)
 Initialize the device tree.
void init_driver (driver_t *drv)
 Initialize device driver structure.
void init_driver_list (driver_list_t *drv_list)
 Initialize the list of device driver's.
static void init_match_ids (match_id_list_t *id_list)
static int init_running_drv (void *drv)
 Initialize driver which has registered itself as running and ready.
void initialize_running_driver (driver_t *driver, dev_tree_t *tree)
 Finish the initialization of a driver after it has succesfully started and after it has registered itself by the device manager.
bool insert_dev_node (dev_tree_t *tree, dev_node_t *dev, fun_node_t *pfun)
 Insert new device into device tree.
bool insert_fun_node (dev_tree_t *tree, fun_node_t *fun, char *fun_name, dev_node_t *dev)
 Insert new function into device tree.
int lookup_available_drivers (driver_list_t *drivers_list, const char *dir_path)
 Lookup drivers in the directory.
int main (int argc, char *argv[])
 Main entry point.
bool parse_match_ids (char *buf, match_id_list_t *ids)
 Read match ids and associated match scores from a string.
static void pass_devices_to_driver (driver_t *driver, dev_tree_t *tree)
 Notify driver about the devices to which it was assigned.
char * read_match_id (char **buf)
 Read match id at the specified position of a string and set the position in the string to the first character following the id.
bool read_match_ids (const char *conf_path, match_id_list_t *ids)
 Read match ids and associated match scores from a file.
void replace_char (char *str, char orig, char repl)
ssize_t safe_read (int fd, void *buffer, size_t size)
static bool set_fun_path (fun_node_t *fun, fun_node_t *parent)
 Create and set device's full path in device tree.
bool skip_spaces (char **buf)
bool start_driver (driver_t *drv)
 Start a driver.
void tree_add_devmap_function (dev_tree_t *tree, fun_node_t *fun)

Variables

static class_list_t class_list
static dev_tree_t device_tree
static hash_table_operations_t devman_devices_ops
static hash_table_operations_t devman_functions_ops
static hash_table_operations_t devmap_devices_class_ops
static hash_table_operations_t devmap_devices_ops
static driver_list_t drivers_list

Detailed Description

HelenOS device manager.


Enumeration Type Documentation

enum driver_state_t

Enumerator:
DRIVER_NOT_STARTED  Driver has not been started.
DRIVER_STARTING  Driver has been started, but has not registered as running and ready to receive requests.
DRIVER_RUNNING  Driver is running and prepared to serve incomming requests.

Definition at line 64 of file devman.h.

enum fun_type_t

Enumerator:
fun_invalid  Invalid value for debugging purposes.
fun_inner  Function to which child devices attach.
fun_exposed  Fuction exported to external clients (leaf function).

Definition at line 45 of file devman.h.


Function Documentation

void add_device ( int  phone,
driver_t drv,
dev_node_t dev,
dev_tree_t tree 
)

Pass a device to running driver.

Parameters:
drv The driver's structure.
node The device's node in the device tree.

Definition at line 739 of file devman.c.

void add_driver ( driver_list_t drivers_list,
driver_t drv 
)

Add a driver to the list of drivers.

Parameters:
drivers_list List of drivers.
drv Driver structure.

Definition at line 144 of file devman.c.

dev_class_info_t * add_function_to_class ( fun_node_t fun,
dev_class_t cl,
const char *  base_dev_name 
)

Add the device function to the class.

The device may be added to multiple classes and a class may contain multiple devices. The class and the device are associated with each other by the dev_class_info_t structure.

Parameters:
dev The device.
class The class.
base_dev_name The base name of the device within the class if specified by the driver, NULL otherwise.
Returns:
dev_class_info_t structure which associates the device with the class.

Definition at line 1324 of file devman.c.

bool assign_driver ( dev_node_t dev,
driver_list_t drivers_list,
dev_tree_t tree 
)

Find suitable driver for a device and assign the driver to it.

Parameters:
node The device node of the device in the device tree.
drivers_list The list of available drivers.
Returns:
True if the suitable driver is found and successfully assigned to the device, false otherwise.

Definition at line 795 of file devman.c.

void attach_driver ( dev_node_t dev,
driver_t drv 
)

Assign a driver to a device.

Parameters:
node The device's node in the device tree.
drv The driver.

Definition at line 489 of file devman.c.

void clean_driver ( driver_t drv  ) 

Device driver structure clean-up.

Parameters:
drv The device driver structure.

Definition at line 682 of file devman.c.

static int compute_match_score ( match_id_t driver,
match_id_t device 
) [static]

Compute compound score of driver and device.

Parameters:
driver Match id of the driver.
device Match id of the device.
Returns:
Compound score.
Return values:
0 No match at all.

Definition at line 44 of file match.c.

dev_class_t * create_dev_class ( void   ) 

Create device class.

Returns:
Device class.

Definition at line 1242 of file devman.c.

dev_class_info_t * create_dev_class_info ( void   ) 

Create device class info.

Returns:
Device class info.

Definition at line 1260 of file devman.c.

char * create_dev_name_for_class ( dev_class_t cl,
const char *  base_dev_name 
)

Create unique device name within the class.

Parameters:
cl The class.
base_dev_name Contains the base name for the device if it was specified by the driver when it registered the device by the class; NULL if driver specified no base name.
Returns:
The unique name for the device within the class.

Definition at line 1295 of file devman.c.

dev_node_t * create_dev_node ( void   ) 

Create a new device node.

Returns:
A device node structure.

Definition at line 872 of file devman.c.

driver_t * create_driver ( void   ) 

Allocate and initialize a new driver structure.

Returns:
Driver structure.

Definition at line 131 of file devman.c.

fun_node_t * create_fun_node ( void   ) 

Create a new function node.

Returns:
A function node structure.

Definition at line 939 of file devman.c.

bool create_root_nodes ( dev_tree_t tree  ) 

Create root device and function node in the device tree.

Parameters:
tree The device tree.
Returns:
True on success, false otherwise.

Definition at line 401 of file devman.c.

void delete_dev_node ( dev_node_t dev  ) 

Delete a device node.

Parameters:
node The device node structure.

Definition at line 890 of file devman.c.

void delete_driver ( driver_t drv  ) 

Delete device driver structure.

Parameters:
drv The device driver structure.

Definition at line 698 of file devman.c.

void delete_fun_node ( fun_node_t fun  ) 

Delete a function node.

Parameters:
fun The device node structure.

Definition at line 959 of file devman.c.

static void devman_add_function ( ipc_callid_t  callid,
ipc_call_t call 
) [static]

Handle function registration.

Child devices are registered by their parent's device driver.

Definition at line 241 of file main.c.

static int devman_receive_match_id ( match_id_list_t match_ids  )  [static]

Receive device match ID from the device's parent driver and add it to the list of devices match ids.

Parameters:
match_ids The list of the device's match ids.
Returns:
Zero on success, negative error code otherwise.

Definition at line 167 of file main.c.

static int devman_receive_match_ids ( sysarg_t  match_count,
match_id_list_t match_ids 
) [static]

Receive device match IDs from the device's parent driver and add them to the list of devices match ids.

Parameters:
match_count The number of device's match ids to be received.
match_ids The list of the device's match ids.
Returns:
Zero on success, negative error code otherwise.

Definition at line 217 of file main.c.

driver_t * find_best_match_driver ( driver_list_t drivers_list,
dev_node_t node 
)

Lookup the best matching driver for the specified device in the list of drivers.

A match between a device and a driver is found if one of the driver's match ids match one of the device's match ids. The score of the match is the product of the driver's and device's score associated with the matching id. The best matching driver for a device is the driver with the highest score of the match between the device and the driver.

Parameters:
drivers_list The list of drivers, where we look for the driver suitable for handling the device.
node The device node structure of the device.
Returns:
The best matching driver or NULL if no matching driver is found.

Definition at line 461 of file devman.c.

dev_node_t * find_dev_node ( dev_tree_t tree,
devman_handle_t  handle 
)

Find the device node structure of the device witch has the specified handle.

Parameters:
tree The device tree where we look for the device node.
handle The handle of the device.
Returns:
The device node.

Definition at line 922 of file devman.c.

dev_node_t * find_dev_node_no_lock ( dev_tree_t tree,
devman_handle_t  handle 
)

Find the device node structure of the device witch has the specified handle.

Parameters:
tree The device tree where we look for the device node.
handle The handle of the device.
Returns:
The device node.

Definition at line 905 of file devman.c.

driver_t * find_driver ( driver_list_t drv_list,
const char *  drv_name 
)

Find device driver in the list of device drivers.

Parameters:
drv_list The list of device drivers.
drv_name The name of the device driver which is searched.
Returns:
The device driver of the specified name, if it is in the list, NULL otherwise.

Definition at line 534 of file devman.c.

fun_node_t * find_fun_node ( dev_tree_t tree,
devman_handle_t  handle 
)

Find the function node with the specified handle.

Parameters:
tree The device tree where we look for the device node.
handle The handle of the function.
Returns:
The function node.

Definition at line 996 of file devman.c.

fun_node_t * find_fun_node_by_path ( dev_tree_t tree,
char *  path 
)

Find function node with a specified path in the device tree.

Parameters:
path The path of the function node in the device tree.
tree The device tree.
Returns:
The function node if it is present in the tree, NULL otherwise.

Definition at line 1121 of file devman.c.

fun_node_t * find_fun_node_in_device ( dev_node_t dev,
const char *  name 
)

Find function with a specified name belonging to given device.

Device tree rwlock should be held at least for reading.

Parameters:
dev Device the function belongs to.
name Function name (not path).
Returns:
Function node.
Return values:
NULL No function with given name.

Definition at line 1173 of file devman.c.

fun_node_t * find_fun_node_no_lock ( dev_tree_t tree,
devman_handle_t  handle 
)

Find the function node with the specified handle.

Parameters:
tree The device tree where we look for the device node.
handle The handle of the function.
Returns:
The function node.

Definition at line 976 of file devman.c.

fun_node_t * find_node_child ( fun_node_t pfun,
const char *  name 
)

Find child function node with a specified name.

Device tree rwlock should be held at least for reading.

Parameters:
parent The parent function node.
name The name of the child function.
Returns:
The child function node.

Definition at line 1231 of file devman.c.

bool get_driver_info ( const char *  base_path,
const char *  name,
driver_t drv 
)

Get information about a driver.

Each driver has its own directory in the base directory. The name of the driver's directory is the same as the name of the driver. The driver's directory contains driver's binary (named as the driver without extension) and the configuration file with match ids for device-to-driver matching (named as the driver with a special extension).

This function searches for the driver's directory and containing configuration files. If all the files needed are found, they are parsed and the information about the driver is stored in the driver's structure.

Parameters:
base_path The base directory, in which we look for driver's subdirectory.
name The name of the driver.
drv The driver structure to fill information in.
Returns:
True on success, false otherwise.

Definition at line 310 of file devman.c.

bool init_device_tree ( dev_tree_t tree,
driver_list_t drivers_list 
)

Initialize the device tree.

Create root device node of the tree and assign driver to it.

Parameters:
tree The device tree.
drivers_list the list of available drivers.
Returns:
True on success, false otherwise.

Definition at line 843 of file devman.c.

void init_driver ( driver_t drv  ) 

Initialize device driver structure.

Parameters:
drv The device driver structure.

Definition at line 667 of file devman.c.

void init_driver_list ( driver_list_t drv_list  ) 

Initialize the list of device driver's.

Parameters:
drv_list the list of device driver's.

Definition at line 119 of file devman.c.

static int init_running_drv ( void *  drv  )  [static]

Initialize driver which has registered itself as running and ready.

The initialization is done in a separate fibril to avoid deadlocks (if the driver needed to be served by devman during the driver's initialization).

Definition at line 403 of file main.c.

void initialize_running_driver ( driver_t driver,
dev_tree_t tree 
)

Finish the initialization of a driver after it has succesfully started and after it has registered itself by the device manager.

Pass devices formerly matched to the driver to the driver and remember the driver is running and fully functional now.

Parameters:
driver The driver which registered itself as running by the device manager.

Definition at line 651 of file devman.c.

bool insert_dev_node ( dev_tree_t tree,
dev_node_t dev,
fun_node_t pfun 
)

Insert new device into device tree.

Parameters:
tree The device tree.
node The newly added device node.
dev_name The name of the newly added device.
parent The parent device node.
Returns:
True on success, false otherwise (insufficient resources etc.).

Definition at line 1049 of file devman.c.

bool insert_fun_node ( dev_tree_t tree,
fun_node_t fun,
char *  fun_name,
dev_node_t dev 
)

Insert new function into device tree.

Parameters:
tree The device tree.
node The newly added function node.
dev_name The name of the newly added function.
parent Owning device node.
Returns:
True on success, false otherwise (insufficient resources etc.).

Definition at line 1080 of file devman.c.

int lookup_available_drivers ( driver_list_t drivers_list,
const char *  dir_path 
)

Lookup drivers in the directory.

Parameters:
drivers_list The list of available drivers.
dir_path The path to the directory where we search for drivers.
Returns:
Number of drivers which were found.

Definition at line 370 of file devman.c.

int main ( int  argc,
char *  argv[] 
)

Main entry point.

Parameters:
[in] argc Nmber of arguments in argv vector (ignored).
[in] argv Cmdline argument vector (ignored).
Returns:
Error code.
Driver debug level is set here.

Definition at line 764 of file main.c.

bool parse_match_ids ( char *  buf,
match_id_list_t ids 
)

Read match ids and associated match scores from a string.

Each match score in the string is followed by its match id. The match ids and match scores are separated by whitespaces. Neither match ids nor match scores can contain whitespaces.

Parameters:
buf The string from which the match ids are read.
ids The list of match ids into which the match ids and scores are added.
Returns:
True if at least one match id and associated match score was successfully read, false otherwise.

Definition at line 189 of file devman.c.

static void pass_devices_to_driver ( driver_t driver,
dev_tree_t tree 
) [static]

Notify driver about the devices to which it was assigned.

Parameters:
driver The driver to which the devices are passed.

Definition at line 562 of file devman.c.

char * read_match_id ( char **  buf  ) 

Read match id at the specified position of a string and set the position in the string to the first character following the id.

Parameters:
buf The position in the input string.
Returns:
The match id.

Definition at line 160 of file devman.c.

bool read_match_ids ( const char *  conf_path,
match_id_list_t ids 
)

Read match ids and associated match scores from a file.

Each match score in the file is followed by its match id. The match ids and match scores are separated by whitespaces. Neither match ids nor match scores can contain whitespaces.

Parameters:
buf The path to the file from which the match ids are read.
ids The list of match ids into which the match ids and scores are added.
Returns:
True if at least one match id and associated match score was successfully read, false otherwise.

Definition at line 239 of file devman.c.

static bool set_fun_path ( fun_node_t fun,
fun_node_t parent 
) [static]

Create and set device's full path in device tree.

Parameters:
node The device's device node.
parent The parent device node.
Returns:
True on success, false otherwise (insufficient resources etc.).

Definition at line 1014 of file devman.c.

bool start_driver ( driver_t drv  ) 

Start a driver.

Parameters:
drv The driver's structure.
Returns:
True if the driver's task is successfully spawned, false otherwise.

Definition at line 508 of file devman.c.


Generated on Thu Jun 2 07:45:56 2011 for HelenOS/USB by  doxygen 1.4.7