From 4ac38c54277a94a4bc3917773f4bf1e9596dd186 Mon Sep 17 00:00:00 2001 From: Gedare Bloom Date: Thu, 5 Feb 2026 12:12:07 -0700 Subject: [PATCH] cpukit/libdrvmgr: reformat Fixes #5446 --- cpukit/include/drvmgr/drvmgr.h | 763 +++++++++++--------- cpukit/include/drvmgr/drvmgr_confdefs.h | 204 +++--- cpukit/include/drvmgr/drvmgr_list.h | 39 +- cpukit/include/drvmgr/pci_bus.h | 171 +++-- cpukit/libdrvmgr/drvmgr.c | 719 +++++++++--------- cpukit/libdrvmgr/drvmgr_by_id.c | 23 +- cpukit/libdrvmgr/drvmgr_by_name.c | 28 +- cpukit/libdrvmgr/drvmgr_dev_by_name.c | 25 +- cpukit/libdrvmgr/drvmgr_drvinf.c | 182 ++--- cpukit/libdrvmgr/drvmgr_for_each_dev.c | 134 ++-- cpukit/libdrvmgr/drvmgr_for_each_list_dev.c | 51 +- cpukit/libdrvmgr/drvmgr_func.c | 47 +- cpukit/libdrvmgr/drvmgr_func_call.c | 18 +- cpukit/libdrvmgr/drvmgr_init.c | 13 +- cpukit/libdrvmgr/drvmgr_internal.h | 50 +- cpukit/libdrvmgr/drvmgr_list.c | 72 +- cpukit/libdrvmgr/drvmgr_lock.c | 2 +- cpukit/libdrvmgr/drvmgr_print.c | 714 +++++++++--------- cpukit/libdrvmgr/drvmgr_res.c | 138 ++-- cpukit/libdrvmgr/drvmgr_rw.c | 57 +- cpukit/libdrvmgr/drvmgr_translate.c | 199 ++--- cpukit/libdrvmgr/drvmgr_translate_check.c | 31 +- cpukit/libdrvmgr/drvmgr_unregister.c | 216 +++--- 23 files changed, 2074 insertions(+), 1822 deletions(-) diff --git a/cpukit/include/drvmgr/drvmgr.h b/cpukit/include/drvmgr/drvmgr.h index bb17c0065f..00ba4657a1 100644 --- a/cpukit/include/drvmgr/drvmgr.h +++ b/cpukit/include/drvmgr/drvmgr.h @@ -56,33 +56,35 @@ extern "C" { #define DRVMGR_USE_LOCKS 1 #endif -struct drvmgr_dev; /* Device */ -struct drvmgr_bus; /* Bus */ -struct drvmgr_drv; /* Driver */ +struct drvmgr_dev; /* Device */ +struct drvmgr_bus; /* Bus */ +struct drvmgr_drv; /* Driver */ /*** List Interface shortcuts ***/ -#define BUS_LIST_HEAD(list) LIST_HEAD(list, struct drvmgr_bus) -#define BUS_LIST_TAIL(list) LIST_TAIL(list, struct drvmgr_bus) -#define DEV_LIST_HEAD(list) LIST_HEAD(list, struct drvmgr_dev) -#define DEV_LIST_TAIL(list) LIST_TAIL(list, struct drvmgr_dev) -#define DRV_LIST_HEAD(list) LIST_HEAD(list, struct drvmgr_drv) -#define DRV_LIST_TAIL(list) LIST_TAIL(list, struct drvmgr_drv) +#define BUS_LIST_HEAD( list ) LIST_HEAD( list, struct drvmgr_bus ) +#define BUS_LIST_TAIL( list ) LIST_TAIL( list, struct drvmgr_bus ) +#define DEV_LIST_HEAD( list ) LIST_HEAD( list, struct drvmgr_dev ) +#define DEV_LIST_TAIL( list ) LIST_TAIL( list, struct drvmgr_dev ) +#define DRV_LIST_HEAD( list ) LIST_HEAD( list, struct drvmgr_drv ) +#define DRV_LIST_TAIL( list ) LIST_TAIL( list, struct drvmgr_drv ) /*** Bus indentification ***/ -#define DRVMGR_BUS_TYPE_NONE 0 /* Not a valid bus */ -#define DRVMGR_BUS_TYPE_ROOT 1 /* Hard coded bus */ -#define DRVMGR_BUS_TYPE_PCI 2 /* PCI bus */ -#define DRVMGR_BUS_TYPE_AMBAPP 3 /* AMBA Plug & Play bus */ -#define DRVMGR_BUS_TYPE_LEON2_AMBA 4 /* LEON2 hardcoded bus */ -#define DRVMGR_BUS_TYPE_AMBAPP_DIST 5 /* Distibuted AMBA Plug & Play bus accessed using a communication interface */ -#define DRVMGR_BUS_TYPE_SPW_RMAP 6 /* SpaceWire Network bus */ -#define DRVMGR_BUS_TYPE_AMBAPP_RMAP 7 /* SpaceWire RMAP accessed AMBA Plug & Play bus */ +#define DRVMGR_BUS_TYPE_NONE 0 /* Not a valid bus */ +#define DRVMGR_BUS_TYPE_ROOT 1 /* Hard coded bus */ +#define DRVMGR_BUS_TYPE_PCI 2 /* PCI bus */ +#define DRVMGR_BUS_TYPE_AMBAPP 3 /* AMBA Plug & Play bus */ +#define DRVMGR_BUS_TYPE_LEON2_AMBA 4 /* LEON2 hardcoded bus */ +#define DRVMGR_BUS_TYPE_AMBAPP_DIST \ + 5 /* Distibuted AMBA Plug & Play bus accessed using a communication interface */ +#define DRVMGR_BUS_TYPE_SPW_RMAP 6 /* SpaceWire Network bus */ +#define DRVMGR_BUS_TYPE_AMBAPP_RMAP \ + 7 /* SpaceWire RMAP accessed AMBA Plug & Play bus */ enum { - DRVMGR_OBJ_NONE = 0, - DRVMGR_OBJ_DRV = 1, - DRVMGR_OBJ_BUS = 2, - DRVMGR_OBJ_DEV = 3, + DRVMGR_OBJ_NONE = 0, + DRVMGR_OBJ_DRV = 1, + DRVMGR_OBJ_BUS = 2, + DRVMGR_OBJ_DEV = 3, }; /*** Driver indentification *** @@ -110,32 +112,36 @@ enum { #define DRIVER_ID_DEV_MASK 0x00FFFFFFFFFFFF00ULL /* Set Bus ID Mask. */ -#define DRIVER_ID(busid, devid) ((unsigned long long) \ - ((((unsigned long long)(devid) << 8) & DRIVER_ID_DEV_MASK) | \ - ((unsigned long long)(busid) & DRIVER_ID_BUS_MASK))) +#define DRIVER_ID( busid, devid ) \ + ( (unsigned long long) ( ( ( (unsigned long long) ( devid ) << 8 ) & \ + DRIVER_ID_DEV_MASK ) | \ + ( (unsigned long long) ( busid ) & \ + DRIVER_ID_BUS_MASK ) ) ) /* Get IDs */ -#define DRIVER_BUSID_GET(id) ((unsigned long long)(id) & DRIVER_ID_BUS_MASK) -#define DRIVER_DEVID_GET(id) (((unsigned long long)(id) & DRIVER_ID_DEV_MASK) >> 8) +#define DRIVER_BUSID_GET( id ) \ + ( (unsigned long long) ( id ) & DRIVER_ID_BUS_MASK ) +#define DRIVER_DEVID_GET( id ) \ + ( ( (unsigned long long) ( id ) & DRIVER_ID_DEV_MASK ) >> 8 ) -#define DRIVER_ROOTBUS_ID(bus_type) DRIVER_ID(bus_type, 0) +#define DRIVER_ROOTBUS_ID( bus_type ) DRIVER_ID( bus_type, 0 ) /*** Root Bus drivers ***/ /* Generic Hard coded Root bus: Driver ID */ -#define DRIVER_ROOT_ID DRIVER_ROOTBUS_ID(DRVMGR_BUS_TYPE_ROOT) +#define DRIVER_ROOT_ID DRIVER_ROOTBUS_ID( DRVMGR_BUS_TYPE_ROOT ) /* PCI Plug & Play bus: Driver ID */ -#define DRIVER_PCIBUS_ID DRIVER_ROOTBUS_ID(DRVMGR_BUS_TYPE_PCI) +#define DRIVER_PCIBUS_ID DRIVER_ROOTBUS_ID( DRVMGR_BUS_TYPE_PCI ) /* AMBA Plug & Play bus: Driver ID */ -#define DRIVER_GRLIB_AMBAPP_ID DRIVER_ROOTBUS_ID(DRVMGR_BUS_TYPE_AMBAPP) +#define DRIVER_GRLIB_AMBAPP_ID DRIVER_ROOTBUS_ID( DRVMGR_BUS_TYPE_AMBAPP ) /* AMBA Hard coded bus: Driver ID */ -#define DRIVER_LEON2_AMBA_ID DRIVER_ROOTBUS_ID(DRVMGR_BUS_TYPE_LEON2_AMBA) +#define DRIVER_LEON2_AMBA_ID DRIVER_ROOTBUS_ID( DRVMGR_BUS_TYPE_LEON2_AMBA ) /* Distributed AMBA Plug & Play bus: Driver ID */ -#define DRIVER_AMBAPP_DIST_ID DRIVER_ROOTBUS_ID(DRVMGR_BUS_TYPE_AMBAPP_DIST) +#define DRIVER_AMBAPP_DIST_ID DRIVER_ROOTBUS_ID( DRVMGR_BUS_TYPE_AMBAPP_DIST ) /*! Bus parameters used by driver interface functions to aquire information * about bus. All Bus drivers should implement the operation 'get_params' so @@ -143,48 +149,69 @@ enum { * an non-dependent way. */ struct drvmgr_bus_params { - char *dev_prefix; /*!< Optional name prefix */ + char *dev_prefix; /*!< Optional name prefix */ }; /* Interrupt Service Routine (ISR) */ -typedef void (*drvmgr_isr)(void *arg); +typedef void ( *drvmgr_isr )( void *arg ); /*! Bus operations */ struct drvmgr_bus_ops { - /* Functions used internally within driver manager */ - int (*init[DRVMGR_LEVEL_MAX])(struct drvmgr_bus *); - int (*remove)(struct drvmgr_bus *); - int (*unite)(struct drvmgr_drv *, struct drvmgr_dev *); /*!< Unite Hardware Device with Driver */ + /* Functions used internally within driver manager */ + int ( *init[ DRVMGR_LEVEL_MAX ] )( struct drvmgr_bus * ); + int ( *remove )( struct drvmgr_bus * ); + int ( *unite )( + struct drvmgr_drv *, + struct drvmgr_dev * + ); /*!< Unite Hardware Device with Driver */ - /* Functions called indirectly from drivers */ - int (*int_register)(struct drvmgr_dev *, int index, const char *info, drvmgr_isr isr, void *arg); - int (*int_unregister)(struct drvmgr_dev *, int index, drvmgr_isr isr, void *arg); - int (*int_clear)(struct drvmgr_dev *, int index); - int (*int_mask)(struct drvmgr_dev *, int index); - int (*int_unmask)(struct drvmgr_dev *, int index); + /* Functions called indirectly from drivers */ + int ( *int_register )( + struct drvmgr_dev *, + int index, + const char *info, + drvmgr_isr isr, + void *arg + ); + int ( *int_unregister )( + struct drvmgr_dev *, + int index, + drvmgr_isr isr, + void *arg + ); + int ( *int_clear )( struct drvmgr_dev *, int index ); + int ( *int_mask )( struct drvmgr_dev *, int index ); + int ( *int_unmask )( struct drvmgr_dev *, int index ); #ifdef RTEMS_SMP - int (*int_set_affinity)(struct drvmgr_dev *, int index, - const Processor_mask *cpus); + int ( *int_set_affinity )( + struct drvmgr_dev *, + int index, + const Processor_mask *cpus + ); #endif - /* Get Parameters */ - int (*get_params)(struct drvmgr_dev *, struct drvmgr_bus_params *); - /* Get Frequency of Bus */ - int (*get_freq)(struct drvmgr_dev*, int, unsigned int*); - /*! Function called to request information about a device. The bus + /* Get Parameters */ + int ( *get_params )( struct drvmgr_dev *, struct drvmgr_bus_params * ); + /* Get Frequency of Bus */ + int ( *get_freq )( struct drvmgr_dev *, int, unsigned int * ); + /*! Function called to request information about a device. The bus * driver interpret the bus-specific information about the device. */ - void (*get_info_dev)(struct drvmgr_dev *, - void (*print)(void *p, char *str), void *p); + void ( *get_info_dev )( + struct drvmgr_dev *, + void ( *print )( void *p, char *str ), + void *p + ); }; -#define BUS_OPS_NUM (sizeof(struct drvmgr_bus_ops)/sizeof(void (*)(void))) +#define BUS_OPS_NUM \ + ( sizeof( struct drvmgr_bus_ops ) / sizeof( void ( * )( void ) ) ) struct drvmgr_func { - int funcid; - void *func; + int funcid; + void *func; }; -#define DRVMGR_FUNC(_ID_, _FUNC_) {(int)(_ID_), (void *)(_FUNC_)} -#define DRVMGR_FUNC_END {0, NULL} +#define DRVMGR_FUNC( _ID_, _FUNC_ ) { (int) ( _ID_ ), (void *) ( _FUNC_ ) } +#define DRVMGR_FUNC_END { 0, NULL } /*** Resource definitions *** * @@ -200,44 +227,45 @@ struct drvmgr_func { /* Key Data Types */ enum drvmgr_kt { - DRVMGR_KT_ANY = -1, - DRVMGR_KT_NONE = 0, - DRVMGR_KT_INT = 1, - DRVMGR_KT_STRING = 2, - DRVMGR_KT_POINTER = 3, + DRVMGR_KT_ANY = -1, + DRVMGR_KT_NONE = 0, + DRVMGR_KT_INT = 1, + DRVMGR_KT_STRING = 2, + DRVMGR_KT_POINTER = 3, }; -#define DRVMGR_KEY_EMPTY {NULL, DRVMGR_KT_NONE, {0}} -#define DRVMGR_RES_EMPTY {0, 0, NULL} -#define MMAP_EMPTY {0, 0, 0} +#define DRVMGR_KEY_EMPTY { NULL, DRVMGR_KT_NONE, { 0 } } +#define DRVMGR_RES_EMPTY { 0, 0, NULL } +#define MMAP_EMPTY { 0, 0, 0 } /*! Union of different values */ union drvmgr_key_value { - unsigned int i; /*!< Key data type UNSIGNED INTEGER */ - char *str; /*!< Key data type STRING */ - void *ptr; /*!< Key data type ADDRESS/POINTER */ + unsigned int i; /*!< Key data type UNSIGNED INTEGER */ + char *str; /*!< Key data type STRING */ + void *ptr; /*!< Key data type ADDRESS/POINTER */ }; /* One key. One Value. Holding information relevant to the driver. */ struct drvmgr_key { - char *key_name; /* Name of key */ - enum drvmgr_kt key_type; /* How to interpret key_value */ - union drvmgr_key_value key_value; /* The value or pointer to value */ + char *key_name; /* Name of key */ + enum drvmgr_kt key_type; /* How to interpret key_value */ + union drvmgr_key_value key_value; /* The value or pointer to value */ }; /*! Driver resource entry, Driver resources for a certain device instance, * containing a number of keys where each key hold the data of interest. */ struct drvmgr_drv_res { - uint64_t drv_id; /*!< Identifies the driver this resource is aiming */ - int minor_bus; /*!< Indentifies a specfic device */ - struct drvmgr_key *keys; /*!< First key in key array, ended with KEY_EMPTY */ + uint64_t drv_id; /*!< Identifies the driver this resource is aiming */ + int minor_bus; /*!< Indentifies a specfic device */ + struct drvmgr_key *keys; /*!< First key in key array, ended with KEY_EMPTY */ }; /*! Bus resource list node */ struct drvmgr_bus_res { - struct drvmgr_bus_res *next; /*!< Next resource node in list */ - struct drvmgr_drv_res resource[]; /*!< Array of resources, one per device instance */ + struct drvmgr_bus_res *next; /*!< Next resource node in list */ + struct drvmgr_drv_res + resource[]; /*!< Array of resources, one per device instance */ }; /*! MAP entry. Describes an linear address space translation. Untranslated @@ -247,154 +275,171 @@ struct drvmgr_bus_res { * the translation driver interface. */ struct drvmgr_map_entry { - char *name; /*!< Map Name */ - unsigned int size; /*!< Size of map window */ - char *from_adr; /*!< Start address of access window used + char *name; /*!< Map Name */ + unsigned int size; /*!< Size of map window */ + char *from_adr; /*!< Start address of access window used * to reach into remote bus */ - char *to_adr; /*!< Start address of remote system + char *to_adr; /*!< Start address of remote system * address range */ }; -#define DRVMGR_TRANSLATE_ONE2ONE NULL -#define DRVMGR_TRANSLATE_NO_BRIDGE ((void *)1) /* No bridge, error */ +#define DRVMGR_TRANSLATE_ONE2ONE NULL +#define DRVMGR_TRANSLATE_NO_BRIDGE ( (void *) 1 ) /* No bridge, error */ /*! Bus information. Describes a bus. */ struct drvmgr_bus { - int obj_type; /*!< DRVMGR_OBJ_BUS */ - unsigned char bus_type; /*!< Type of bus */ - unsigned char depth; /*!< Bus level distance from root bus */ - struct drvmgr_bus *next; /*!< Next Bus */ - struct drvmgr_dev *dev; /*!< Bus device, the hardware... */ - void *priv; /*!< Private data structure used by BUS driver */ - struct drvmgr_dev *children; /*!< Hardware devices on this bus */ - struct drvmgr_bus_ops *ops; /*!< Bus operations supported by this bus driver */ - struct drvmgr_func *funcs; /*!< Extra operations */ - int dev_cnt; /*!< Number of devices this bus has */ - struct drvmgr_bus_res *reslist; /*!< Bus resources, head of a linked list of resources. */ - struct drvmgr_map_entry *maps_up; /*!< Map Translation, array of address spaces upstreams to CPU */ - struct drvmgr_map_entry *maps_down; /*!< Map Translation, array of address spaces downstreams to Hardware */ + int obj_type; /*!< DRVMGR_OBJ_BUS */ + unsigned char bus_type; /*!< Type of bus */ + unsigned char depth; /*!< Bus level distance from root bus */ + struct drvmgr_bus *next; /*!< Next Bus */ + struct drvmgr_dev *dev; /*!< Bus device, the hardware... */ + void *priv; /*!< Private data structure used by BUS driver */ + struct drvmgr_dev *children; /*!< Hardware devices on this bus */ + struct drvmgr_bus_ops + *ops; /*!< Bus operations supported by this bus driver */ + struct drvmgr_func *funcs; /*!< Extra operations */ + int dev_cnt; /*!< Number of devices this bus has */ + struct drvmgr_bus_res + *reslist; /*!< Bus resources, head of a linked list of resources. */ + struct drvmgr_map_entry + *maps_up; /*!< Map Translation, array of address spaces upstreams to CPU */ + struct drvmgr_map_entry * + maps_down; /*!< Map Translation, array of address spaces downstreams to Hardware */ - /* Bus status */ - int level; /*!< Initialization Level of Bus */ - int state; /*!< Init State of Bus, BUS_STATE_* */ - int error; /*!< Return code from bus->ops->initN() */ + /* Bus status */ + int level; /*!< Initialization Level of Bus */ + int state; /*!< Init State of Bus, BUS_STATE_* */ + int error; /*!< Return code from bus->ops->initN() */ }; /* States of a bus */ -#define BUS_STATE_INIT_FAILED 0x00000001 /* Initialization Failed */ -#define BUS_STATE_LIST_INACTIVE 0x00001000 /* In inactive bus list */ -#define BUS_STATE_DEPEND_FAILED 0x00000004 /* Device init failed */ +#define BUS_STATE_INIT_FAILED 0x00000001 /* Initialization Failed */ +#define BUS_STATE_LIST_INACTIVE 0x00001000 /* In inactive bus list */ +#define BUS_STATE_DEPEND_FAILED 0x00000004 /* Device init failed */ /* States of a device */ -#define DEV_STATE_INIT_FAILED 0x00000001 /* Initialization Failed */ -#define DEV_STATE_INIT_DONE 0x00000002 /* All init levels completed */ -#define DEV_STATE_DEPEND_FAILED 0x00000004 /* Parent Bus init failed */ -#define DEV_STATE_UNITED 0x00000100 /* Device United with Device Driver */ -#define DEV_STATE_REMOVED 0x00000200 /* Device has been removed (unregistered) */ -#define DEV_STATE_IGNORED 0x00000400 /* Device was ignored according to user's request, the device +#define DEV_STATE_INIT_FAILED 0x00000001 /* Initialization Failed */ +#define DEV_STATE_INIT_DONE 0x00000002 /* All init levels completed */ +#define DEV_STATE_DEPEND_FAILED 0x00000004 /* Parent Bus init failed */ +#define DEV_STATE_UNITED 0x00000100 /* Device United with Device Driver */ +#define DEV_STATE_REMOVED \ + 0x00000200 /* Device has been removed (unregistered) */ +#define DEV_STATE_IGNORED \ + 0x00000400 /* Device was ignored according to user's request, the device * was never reported to it's driver (as expected). */ -#define DEV_STATE_LIST_INACTIVE 0x00001000 /* In inactive device list */ +#define DEV_STATE_LIST_INACTIVE 0x00001000 /* In inactive device list */ /*! Device information */ struct drvmgr_dev { - int obj_type; /*!< DRVMGR_OBJ_DEV */ - struct drvmgr_dev *next; /*!< Next device */ - struct drvmgr_dev *next_in_bus; /*!< Next device on the same bus */ - struct drvmgr_dev *next_in_drv; /*!< Next device using the same driver */ + int obj_type; /*!< DRVMGR_OBJ_DEV */ + struct drvmgr_dev *next; /*!< Next device */ + struct drvmgr_dev *next_in_bus; /*!< Next device on the same bus */ + struct drvmgr_dev *next_in_drv; /*!< Next device using the same driver */ - struct drvmgr_drv *drv; /*!< The driver owning this device */ - struct drvmgr_bus *parent; /*!< Bus that this device resides on */ - short minor_drv; /*!< Device number within driver */ - short minor_bus; /*!< Device number on bus (for device separation) */ - char *name; /*!< Name of Device Hardware */ - void *priv; /*!< Pointer to driver private device structure */ - void *businfo; /*!< Host bus specific information */ - struct drvmgr_bus *bus; /*!< Pointer to bus, set only if this is a bridge */ + struct drvmgr_drv *drv; /*!< The driver owning this device */ + struct drvmgr_bus *parent; /*!< Bus that this device resides on */ + short minor_drv; /*!< Device number within driver */ + short minor_bus; /*!< Device number on bus (for device separation) */ + char *name; /*!< Name of Device Hardware */ + void *priv; /*!< Pointer to driver private device structure */ + void *businfo; /*!< Host bus specific information */ + struct drvmgr_bus *bus; /*!< Pointer to bus, set only if this is a bridge */ - /* Device Status */ - unsigned int state; /*!< State of device, see DEV_STATE_* */ - int level; /*!< Init Level */ - int error; /*!< Error state returned by driver */ + /* Device Status */ + unsigned int state; /*!< State of device, see DEV_STATE_* */ + int level; /*!< Init Level */ + int error; /*!< Error state returned by driver */ }; /*! Driver operations, function pointers. */ struct drvmgr_drv_ops { - int (*init[DRVMGR_LEVEL_MAX])(struct drvmgr_dev *); /*! Function doing Init Stage 1 of a hardware device */ - int (*remove)(struct drvmgr_dev *); /*! Function called when device instance is to be removed */ - int (*info)(struct drvmgr_dev *, void (*print)(void *p, char *str), void *p, int, char *argv[]);/*! Function called to request information about a device or driver */ + int ( *init[ DRVMGR_LEVEL_MAX ] )( + struct drvmgr_dev * + ); /*! Function doing Init Stage 1 of a hardware device */ + int ( *remove )( + struct drvmgr_dev * + ); /*! Function called when device instance is to be removed */ + int ( *info )( + struct drvmgr_dev *, + void ( *print )( void *p, char *str ), + void *p, + int, + char *argv[] + ); /*! Function called to request information about a device or driver */ }; -#define DRVMGR_OPS_NUM(x) (sizeof(x)/sizeof(void (*)(void))) +#define DRVMGR_OPS_NUM( x ) ( sizeof( x ) / sizeof( void ( * )( void ) ) ) /*! Device driver description */ struct drvmgr_drv { - int obj_type; /*!< DRVMGR_OBJ_DRV */ - struct drvmgr_drv *next; /*!< Next Driver */ - struct drvmgr_dev *dev; /*!< Devices using this driver */ + int obj_type; /*!< DRVMGR_OBJ_DRV */ + struct drvmgr_drv *next; /*!< Next Driver */ + struct drvmgr_dev *dev; /*!< Devices using this driver */ - uint64_t drv_id; /*!< Unique Driver ID */ - char *name; /*!< Name of Driver */ - int bus_type; /*!< Type of Bus this driver supports */ - struct drvmgr_drv_ops *ops; /*!< Driver operations */ - struct drvmgr_func *funcs; /*!< Extra Operations */ - unsigned int dev_cnt; /*!< Number of devices in dev */ - unsigned int dev_priv_size; /*!< If non-zero DRVMGR will allocate memory for dev->priv */ + uint64_t drv_id; /*!< Unique Driver ID */ + char *name; /*!< Name of Driver */ + int bus_type; /*!< Type of Bus this driver supports */ + struct drvmgr_drv_ops *ops; /*!< Driver operations */ + struct drvmgr_func *funcs; /*!< Extra Operations */ + unsigned int dev_cnt; /*!< Number of devices in dev */ + unsigned int + dev_priv_size; /*!< If non-zero DRVMGR will allocate memory for dev->priv */ }; /*! Structure defines a function pointer called when driver manager is ready * for drivers to register themselfs. Used to select drivers available to the * driver manager. */ -typedef void (*drvmgr_drv_reg_func)(void); +typedef void ( *drvmgr_drv_reg_func )( void ); /*** DRIVER | DEVICE | BUS FUNCTIONS ***/ /* Return Codes */ enum { - DRVMGR_OK = 0, /* Sucess */ - DRVMGR_NOMEM = 1, /* Memory allocation error */ - DRVMGR_EIO = 2, /* I/O error */ - DRVMGR_EINVAL = 3, /* Invalid parameter */ - DRVMGR_ENOSYS = 4, - DRVMGR_TIMEDOUT = 5, /* Operation timeout error */ - DRVMGR_EBUSY = 6, - DRVMGR_ENORES = 7, /* Not enough resources */ - DRVMGR_FAIL = -1 /* Unspecified failure */ + DRVMGR_OK = 0, /* Sucess */ + DRVMGR_NOMEM = 1, /* Memory allocation error */ + DRVMGR_EIO = 2, /* I/O error */ + DRVMGR_EINVAL = 3, /* Invalid parameter */ + DRVMGR_ENOSYS = 4, + DRVMGR_TIMEDOUT = 5, /* Operation timeout error */ + DRVMGR_EBUSY = 6, + DRVMGR_ENORES = 7, /* Not enough resources */ + DRVMGR_FAIL = -1 /* Unspecified failure */ }; /*! Initialize data structures of the driver management system. * Calls predefined register driver functions so that drivers can * register themselves. */ -extern void _DRV_Manager_initialization(void); +extern void _DRV_Manager_initialization( void ); /*! Take all devices into init level 'level', all devices registered later * will directly be taken into this level as well, ensuring that all * registerd devices has been taken into the level. * */ -extern void _DRV_Manager_init_level(int level); +extern void _DRV_Manager_init_level( int level ); /*! Init driver manager all in one go, will call _DRV_Manager_initialization(), * then _DRV_Manager_init_level([1..DRVMGR_LEVEL_MAX]). * Typically called from Init task when user wants to initilize driver * manager after startup, otherwise not used. */ -extern int drvmgr_init(void); +extern int drvmgr_init( void ); /* Take registered buses and devices into the correct init level, * this function is called from _init_level() so normally * we don't need to call it directly. */ -extern void drvmgr_init_update(void); +extern void drvmgr_init_update( void ); /*! Register Root Bus device driver */ -extern int drvmgr_root_drv_register(struct drvmgr_drv *drv); +extern int drvmgr_root_drv_register( struct drvmgr_drv *drv ); /*! Register a driver */ -extern int drvmgr_drv_register(struct drvmgr_drv *drv); +extern int drvmgr_drv_register( struct drvmgr_drv *drv ); /*! Register a device */ -extern int drvmgr_dev_register(struct drvmgr_dev *dev); +extern int drvmgr_dev_register( struct drvmgr_dev *dev ); /*! Remove a device, and all its children devices if device is a bus device. The * device driver will be requested to remove the device and once gone from bus, @@ -406,23 +451,23 @@ extern int drvmgr_dev_register(struct drvmgr_dev *dev); * \param remove If non-zero the device will be deallocated, and not put into * the inacitve list. */ -extern int drvmgr_dev_unregister(struct drvmgr_dev *dev); +extern int drvmgr_dev_unregister( struct drvmgr_dev *dev ); /*! Register a bus */ -extern int drvmgr_bus_register(struct drvmgr_bus *bus); +extern int drvmgr_bus_register( struct drvmgr_bus *bus ); /*! Unregister a bus */ -extern int drvmgr_bus_unregister(struct drvmgr_bus *bus); +extern int drvmgr_bus_unregister( struct drvmgr_bus *bus ); /*! Unregister all child devices of a bus. * * This function is called from the bus driver, from a "safe" state where * devices will not be added or removed on this particular bus at this time */ -extern int drvmgr_children_unregister(struct drvmgr_bus *bus); +extern int drvmgr_children_unregister( struct drvmgr_bus *bus ); /* Separate a device from the driver it has been united with */ -extern int drvmgr_dev_drv_separate(struct drvmgr_dev *dev); +extern int drvmgr_dev_drv_separate( struct drvmgr_dev *dev ); /*! Allocate a device structure, if no memory available * rtems_error_fatal_occurred is called. @@ -430,7 +475,7 @@ extern int drvmgr_dev_drv_separate(struct drvmgr_dev *dev); * the device structure, this is typically used for "businfo" structures. The extra * space is always aligned to a 4-byte boundary. */ -extern int drvmgr_alloc_dev(struct drvmgr_dev **pdev, int extra); +extern int drvmgr_alloc_dev( struct drvmgr_dev **pdev, int extra ); /*! Allocate a bus structure, if no memory available rtems_error_fatal_occurred * is called. @@ -438,7 +483,7 @@ extern int drvmgr_alloc_dev(struct drvmgr_dev **pdev, int extra); * the device structure, this is typically used for "businfo" structures. The * extra space is always aligned to a 4-byte boundary. */ -extern int drvmgr_alloc_bus(struct drvmgr_bus **pbus, int extra); +extern int drvmgr_alloc_bus( struct drvmgr_bus **pbus, int extra ); /*** DRIVER RESOURCE FUNCTIONS ***/ @@ -448,8 +493,10 @@ extern int drvmgr_alloc_bus(struct drvmgr_bus **pbus, int extra); * \param res An array with Driver resources, all together are called bus * resources. */ -extern void drvmgr_bus_res_add(struct drvmgr_bus *bus, - struct drvmgr_bus_res *bres); +extern void drvmgr_bus_res_add( + struct drvmgr_bus *bus, + struct drvmgr_bus_res *bres +); /*! Find all the resource keys for a device among all driver resources on a * bus. Typically used by a device driver to get configuration options. @@ -457,7 +504,7 @@ extern void drvmgr_bus_res_add(struct drvmgr_bus *bus, * \param dev Device to find resources for * \param key Location where the pointer to the driver resource array (drvmgr_drv_res->keys) is stored. */ -extern int drvmgr_keys_get(struct drvmgr_dev *dev, struct drvmgr_key **keys); +extern int drvmgr_keys_get( struct drvmgr_dev *dev, struct drvmgr_key **keys ); /*! Return the one key that matches key name from a driver keys array. The keys * can be obtained using drvmgr_keys_get(). @@ -465,7 +512,10 @@ extern int drvmgr_keys_get(struct drvmgr_dev *dev, struct drvmgr_key **keys); * \param keys An array of keys ended with DRVMGR_KEY_EMPTY to search among. * \param key_name Name of key to search for among the keys. */ -extern struct drvmgr_key *drvmgr_key_get(struct drvmgr_key *keys, char *key_name); +extern struct drvmgr_key *drvmgr_key_get( + struct drvmgr_key *keys, + char *key_name +); /*! Extract key value from the key in the keys array matching name and type. * @@ -480,9 +530,10 @@ extern struct drvmgr_key *drvmgr_key_get(struct drvmgr_key *keys, char *key_name * Type. */ extern union drvmgr_key_value *drvmgr_key_val_get( - struct drvmgr_key *keys, - char *key_name, - enum drvmgr_kt key_type); + struct drvmgr_key *keys, + char *key_name, + enum drvmgr_kt key_type +); /*! Get key value from the bus resources matching [device, key name, key type] * if no matching key is found NULL is returned. @@ -497,29 +548,31 @@ extern union drvmgr_key_value *drvmgr_key_val_get( * Key Type was found for device. */ extern union drvmgr_key_value *drvmgr_dev_key_get( - struct drvmgr_dev *dev, - char *key_name, - enum drvmgr_kt key_type); + struct drvmgr_dev *dev, + char *key_name, + enum drvmgr_kt key_type +); /*** DRIVER INTERACE USED TO REQUEST INFORMATION/SERVICES FROM BUS DRIVER ***/ /*! Get parent bus */ -static inline struct drvmgr_bus *drvmgr_get_parent( - struct drvmgr_dev *dev) +static inline struct drvmgr_bus *drvmgr_get_parent( struct drvmgr_dev *dev ) { - if (dev) - return dev->parent; - else - return NULL; + if ( dev ) { + return dev->parent; + } else { + return NULL; + } } /*! Get Driver of device */ -static inline struct drvmgr_drv *drvmgr_get_drv(struct drvmgr_dev *dev) +static inline struct drvmgr_drv *drvmgr_get_drv( struct drvmgr_dev *dev ) { - if (dev) - return dev->drv; - else - return NULL; + if ( dev ) { + return dev->drv; + } else { + return NULL; + } } /*! Calls func() for every device found in the device tree, regardless of @@ -534,12 +587,13 @@ static inline struct drvmgr_drv *drvmgr_get_drv(struct drvmgr_dev *dev) * \param options Search Options, see DRVMGR_FED_* * */ -#define DRVMGR_FED_BF 1 /* Breadth-first search */ -#define DRVMGR_FED_DF 0 /* Depth first search */ +#define DRVMGR_FED_BF 1 /* Breadth-first search */ +#define DRVMGR_FED_DF 0 /* Depth first search */ extern intptr_t drvmgr_for_each_dev( - intptr_t (*func)(struct drvmgr_dev *dev, void *arg), - void *arg, - int options); + intptr_t ( *func )( struct drvmgr_dev *dev, void *arg ), + void *arg, + int options +); /*! Get Device pointer from Driver and Driver minor number * @@ -550,9 +604,10 @@ extern intptr_t drvmgr_for_each_dev( * found in driver device list. */ extern int drvmgr_get_dev( - struct drvmgr_drv *drv, - int minor, - struct drvmgr_dev **pdev); + struct drvmgr_drv *drv, + int minor, + struct drvmgr_dev **pdev +); /*! Get Bus frequency in Hertz. Frequency is stored into address of freq_hz. * @@ -561,12 +616,13 @@ extern int drvmgr_get_dev( * \param freq_hz Location where Bus Frequency will be stored. */ extern int drvmgr_freq_get( - struct drvmgr_dev *dev, - int options, - unsigned int *freq_hz); + struct drvmgr_dev *dev, + int options, + unsigned int *freq_hz +); /*! Return 0 if dev is not located on the root bus, 1 if on root bus */ -extern int drvmgr_on_rootbus(struct drvmgr_dev *dev); +extern int drvmgr_on_rootbus( struct drvmgr_dev *dev ); /*! Get device name prefix, this name can be used to register a unique name in * the bus->error filesystem or to get an idea where the device is located. @@ -574,7 +630,7 @@ extern int drvmgr_on_rootbus(struct drvmgr_dev *dev); * \param dev The Device to get the device Prefix for. * \param dev_prefix Location where the prefix will be stored. */ -extern int drvmgr_get_dev_prefix(struct drvmgr_dev *dev, char *dev_prefix); +extern int drvmgr_get_dev_prefix( struct drvmgr_dev *dev, char *dev_prefix ); /*! Register a shared interrupt handler. Since this service is shared among * interrupt drivers/handlers the handler[arg] must be installed before the @@ -590,11 +646,12 @@ extern int drvmgr_get_dev_prefix(struct drvmgr_dev *dev, char *dev_prefix); * \param arg Optional ISR argument. */ extern int drvmgr_interrupt_register( - struct drvmgr_dev *dev, - int index, - const char *info, - drvmgr_isr isr, - void *arg); + struct drvmgr_dev *dev, + int index, + const char *info, + drvmgr_isr isr, + void *arg +); /*! Unregister an interrupt handler. This also disables the interrupt before * unregistering the interrupt handler. @@ -607,10 +664,11 @@ extern int drvmgr_interrupt_register( * \param arg Optional ISR argument, previously registered. */ extern int drvmgr_interrupt_unregister( - struct drvmgr_dev *dev, - int index, - drvmgr_isr isr, - void *arg); + struct drvmgr_dev *dev, + int index, + drvmgr_isr isr, + void *arg +); /*! Clear (ACK) pending interrupt * @@ -621,9 +679,7 @@ extern int drvmgr_interrupt_unregister( * \param isr Interrupt Service Routine, previously registered. * \param arg Optional ISR argument, previously registered. */ -extern int drvmgr_interrupt_clear( - struct drvmgr_dev *dev, - int index); +extern int drvmgr_interrupt_clear( struct drvmgr_dev *dev, int index ); /*! Force unmasking/enableing an interrupt on the interrupt controller, this is not normally used, * if used the caller has masked/disabled the interrupt just before. @@ -635,9 +691,7 @@ extern int drvmgr_interrupt_clear( * \param isr Interrupt Service Routine, previously registered. * \param arg Optional ISR argument, previously registered. */ -extern int drvmgr_interrupt_unmask( - struct drvmgr_dev *dev, - int index); +extern int drvmgr_interrupt_unmask( struct drvmgr_dev *dev, int index ); /*! Force masking/disable an interrupt on the interrupt controller, this is not normally performed * since this will stop all other (shared) ISRs to be disabled until _unmask() is called. @@ -647,9 +701,7 @@ extern int drvmgr_interrupt_unmask( * Normally Index is set to 0 to indicated the first and only IRQ source. * A negative index is interpreted as a absolute bus IRQ number. */ -extern int drvmgr_interrupt_mask( - struct drvmgr_dev *dev, - int index); +extern int drvmgr_interrupt_mask( struct drvmgr_dev *dev, int index ); /*! Force masking/disable an interrupt on the interrupt controller, this is not normally performed * since this will stop all other (shared) ISRs to be disabled until _unmask() is called. @@ -661,23 +713,24 @@ extern int drvmgr_interrupt_mask( */ #ifdef RTEMS_SMP extern int drvmgr_interrupt_set_affinity( - struct drvmgr_dev *dev, - int index, - const Processor_mask *cpus); + struct drvmgr_dev *dev, + int index, + const Processor_mask *cpus +); #endif /*! drvmgr_translate() translation options */ enum drvmgr_tr_opts { - /* Translate CPU RAM Address (input) to DMA unit accessible address + /* Translate CPU RAM Address (input) to DMA unit accessible address * (output), this is an upstreams translation in reverse order. * * Typical Usage: * It is common to translate a CPU accessible RAM address to an * address that DMA units can access over bridges. */ - CPUMEM_TO_DMA = 0x0, + CPUMEM_TO_DMA = 0x0, - /* Translate DMA Unit Accessible address mapped to CPU RAM (input) to + /* Translate DMA Unit Accessible address mapped to CPU RAM (input) to * CPU accessible address (output). This is an upstreams translation. * * Typical Usage (not often used): @@ -686,9 +739,9 @@ enum drvmgr_tr_opts { * the descriptors and want to access the data but a translation back * to CPU address is required. */ - CPUMEM_FROM_DMA = 0x1, + CPUMEM_FROM_DMA = 0x1, - /* Translate DMA Memory Address (input) to CPU accessible address + /* Translate DMA Memory Address (input) to CPU accessible address * (output), this is a downstreams translation in reverse order. * * Typical Usage: @@ -696,17 +749,17 @@ enum drvmgr_tr_opts { * PCI, in order for the CPU to access them the PCI address must be * translated. */ - DMAMEM_TO_CPU = 0x2, + DMAMEM_TO_CPU = 0x2, - /* Translate CPU accessible address (input) mapped to DMA Memory Address + /* Translate CPU accessible address (input) mapped to DMA Memory Address * to DMA Unit accessible address (output). This is a downstreams * translation. */ - DMAMEM_FROM_CPU = 0x3, + DMAMEM_FROM_CPU = 0x3, }; -#define DRVMGR_TR_REVERSE 0x1 /* do reverse translation direction order */ -#define DRVMGR_TR_PATH 0x2 /* 0x0=down-stream 0x2=up-stream address path */ - +#define DRVMGR_TR_REVERSE 0x1 /* do reverse translation direction order */ +#define DRVMGR_TR_PATH 0x2 /* 0x0=down-stream 0x2=up-stream address path */ + /*! Translate an address on one bus to an address on another bus. * * The device determines source or destination bus, the root bus is always @@ -744,10 +797,11 @@ enum drvmgr_tr_opts { * and src_address is stored in *dst_address. */ extern unsigned int drvmgr_translate( - struct drvmgr_dev *dev, - unsigned int options, - void *src_address, - void **dst_address); + struct drvmgr_dev *dev, + unsigned int options, + void *src_address, + void **dst_address +); /* Translate addresses between buses, used internally to implement * drvmgr_translate. Function is not limited to translate from/to root bus @@ -769,11 +823,12 @@ extern unsigned int drvmgr_translate( * and src_address is stored in *dst_address. */ extern unsigned int drvmgr_translate_bus( - struct drvmgr_bus *from, - struct drvmgr_bus *to, - int reverse, - void *src_address, - void **dst_address); + struct drvmgr_bus *from, + struct drvmgr_bus *to, + int reverse, + void *src_address, + void **dst_address +); /* Calls drvmgr_translate() to translate an address range and checks the result, * a printout is generated if the check fails. All parameters are passed on to @@ -784,122 +839,145 @@ extern unsigned int drvmgr_translate_bus( * If mapping failes a non-zero result is returned. */ extern int drvmgr_translate_check( - struct drvmgr_dev *dev, - unsigned int options, - void *src_address, - void **dst_address, - unsigned int size); + struct drvmgr_dev *dev, + unsigned int options, + void *src_address, + void **dst_address, + unsigned int size +); /*! Get function pointer from Device Driver or Bus Driver. * * Returns 0 if function is available */ -extern int drvmgr_func_get(void *obj, int funcid, void **func); +extern int drvmgr_func_get( void *obj, int funcid, void **func ); /*! Lookup function and call it directly with the four optional arguments */ -extern int drvmgr_func_call(void *obj, int funcid, void *a, void *b, void *c, void *d); +extern int drvmgr_func_call( + void *obj, + int funcid, + void *a, + void *b, + void *c, + void *d +); /* Builds a Function ID. * * Used to request optional functions by a bus or device driver */ -#define DRVMGR_FUNCID(major, minor) ((((major) & 0xfff) << 20) | ((minor) & 0xfffff)) +#define DRVMGR_FUNCID( major, minor ) \ + ( ( ( ( major ) & 0xfff ) << 20 ) | ( ( minor ) & 0xfffff ) ) #define DRVMGR_FUNCID_NONE 0 -#define DRVMGR_FUNCID_END DRVMGR_FUNCID(DRVMGR_FUNCID_NONE, 0) +#define DRVMGR_FUNCID_END DRVMGR_FUNCID( DRVMGR_FUNCID_NONE, 0 ) /* Major Function ID. Most significant 12-bits. */ enum { - FUNCID_NONE = 0x000, - FUNCID_RW = 0x001, /* Read/Write functions */ + FUNCID_NONE = 0x000, + FUNCID_RW = 0x001, /* Read/Write functions */ }; /* Select Sub-Function Read/Write function by ID */ -#define RW_SIZE_1 0x00001 /* Access Size */ -#define RW_SIZE_2 0x00002 -#define RW_SIZE_4 0x00004 -#define RW_SIZE_8 0x00008 -#define RW_SIZE_ANY 0x00000 -#define RW_SIZE(id) ((unsigned int)(id) & 0xf) +#define RW_SIZE_1 0x00001 /* Access Size */ +#define RW_SIZE_2 0x00002 +#define RW_SIZE_4 0x00004 +#define RW_SIZE_8 0x00008 +#define RW_SIZE_ANY 0x00000 +#define RW_SIZE( id ) ( (unsigned int) ( id ) & 0xf ) -#define RW_DIR_ANY 0x00000 /* Access Direction */ -#define RW_READ 0x00000 /* Read */ -#define RW_WRITE 0x00010 /* Write */ -#define RW_SET 0x00020 /* Write with same value (memset) */ -#define RW_DIR(id) (((unsigned int)(id) >> 4) & 0x3) +#define RW_DIR_ANY 0x00000 /* Access Direction */ +#define RW_READ 0x00000 /* Read */ +#define RW_WRITE 0x00010 /* Write */ +#define RW_SET 0x00020 /* Write with same value (memset) */ +#define RW_DIR( id ) ( ( (unsigned int) ( id ) >> 4 ) & 0x3 ) -#define RW_RAW 0x00000 /* Raw access - no swapping (machine default) */ -#define RW_LITTLE 0x00040 /* Little Endian */ -#define RW_BIG 0x00080 /* Big Endian */ -#define RW_ENDIAN(id) (((unsigned int)(id) >> 6) & 0x3) +#define RW_RAW 0x00000 /* Raw access - no swapping (machine default) */ +#define RW_LITTLE 0x00040 /* Little Endian */ +#define RW_BIG 0x00080 /* Big Endian */ +#define RW_ENDIAN( id ) ( ( (unsigned int) ( id ) >> 6 ) & 0x3 ) -#define RW_TYPE_ANY 0x00000 /* Access type */ -#define RW_REG 0x00100 -#define RW_MEM 0x00200 -#define RW_MEMREG 0x00300 -#define RW_CFG 0x00400 -#define RW_TYPE(id) (((unsigned int)(id) >> 8) & 0xf) +#define RW_TYPE_ANY 0x00000 /* Access type */ +#define RW_REG 0x00100 +#define RW_MEM 0x00200 +#define RW_MEMREG 0x00300 +#define RW_CFG 0x00400 +#define RW_TYPE( id ) ( ( (unsigned int) ( id ) >> 8 ) & 0xf ) -#define RW_ARG 0x01000 /* Optional Argument */ -#define RW_ERR 0x02000 /* Optional Error Handler */ +#define RW_ARG 0x01000 /* Optional Argument */ +#define RW_ERR 0x02000 /* Optional Error Handler */ /* Build a Read/Write function ID */ -#define DRVMGR_RWFUNC(minor) DRVMGR_FUNCID(FUNCID_RW, minor) +#define DRVMGR_RWFUNC( minor ) DRVMGR_FUNCID( FUNCID_RW, minor ) /* Argument to Read/Write functions, the "void *arg" pointer is returned by * RW_ARG. If NULL is returned no argument is needed. */ struct drvmgr_rw_arg { - void *arg; - struct drvmgr_dev *dev; + void *arg; + struct drvmgr_dev *dev; }; /* Standard Read/Write function types */ -typedef uint8_t (*drvmgr_r8)(uint8_t *srcadr); -typedef uint16_t (*drvmgr_r16)(uint16_t *srcadr); -typedef uint32_t (*drvmgr_r32)(uint32_t *srcadr); -typedef uint64_t (*drvmgr_r64)(uint64_t *srcadr); -typedef void (*drvmgr_w8)(uint8_t *dstadr, uint8_t data); -typedef void (*drvmgr_w16)(uint16_t *dstadr, uint16_t data); -typedef void (*drvmgr_w32)(uint32_t *dstadr, uint32_t data); -typedef void (*drvmgr_w64)(uint64_t *dstadr, uint64_t data); +typedef uint8_t ( *drvmgr_r8 )( uint8_t *srcadr ); +typedef uint16_t ( *drvmgr_r16 )( uint16_t *srcadr ); +typedef uint32_t ( *drvmgr_r32 )( uint32_t *srcadr ); +typedef uint64_t ( *drvmgr_r64 )( uint64_t *srcadr ); +typedef void ( *drvmgr_w8 )( uint8_t *dstadr, uint8_t data ); +typedef void ( *drvmgr_w16 )( uint16_t *dstadr, uint16_t data ); +typedef void ( *drvmgr_w32 )( uint32_t *dstadr, uint32_t data ); +typedef void ( *drvmgr_w64 )( uint64_t *dstadr, uint64_t data ); /* READ/COPY a memory area located on bus into CPU memory. * From 'src' (remote) to the destination 'dest' (local), n=number of bytes */ -typedef int (*drvmgr_rmem)(void *dest, const void *src, int n); +typedef int ( *drvmgr_rmem )( void *dest, const void *src, int n ); /* WRITE/COPY a user buffer located in CPU memory to a location on the bus. * From 'src' (local) to the destination 'dest' (remote), n=number of bytes */ -typedef int (*drvmgr_wmem)(void *dest, const void *src, int n); +typedef int ( *drvmgr_wmem )( void *dest, const void *src, int n ); /* Set a memory area to the byte value given in c, see LIBC memset(). Memset is * implemented by calling wmem() multiple times with a "large" buffer. */ -typedef int (*drvmgr_memset)(void *dstadr, int c, size_t n); +typedef int ( *drvmgr_memset )( void *dstadr, int c, size_t n ); /* Read/Write function types with additional argument */ -typedef uint8_t (*drvmgr_r8_arg)(uint8_t *srcadr, void *a); -typedef uint16_t (*drvmgr_r16_arg)(uint16_t *srcadr, void *a); -typedef uint32_t (*drvmgr_r32_arg)(uint32_t *srcadr, void *a); -typedef uint64_t (*drvmgr_r64_arg)(uint64_t *srcadr, void *a); -typedef void (*drvmgr_w8_arg)(uint8_t *dstadr, uint8_t data, void *a); -typedef void (*drvmgr_w16_arg)(uint16_t *dstadr, uint16_t data, void *a); -typedef void (*drvmgr_w32_arg)(uint32_t *dstadr, uint32_t data, void *a); -typedef void (*drvmgr_w64_arg)(uint64_t *dstadr, uint64_t data, void *a); -typedef int (*drvmgr_rmem_arg)(void *dest, const void *src, int n, void *a); -typedef int (*drvmgr_wmem_arg)(void *dest, const void *src, int n, void *a); -typedef int (*drvmgr_memset_arg)(void *dstadr, int c, size_t n, void *a); +typedef uint8_t ( *drvmgr_r8_arg )( uint8_t *srcadr, void *a ); +typedef uint16_t ( *drvmgr_r16_arg )( uint16_t *srcadr, void *a ); +typedef uint32_t ( *drvmgr_r32_arg )( uint32_t *srcadr, void *a ); +typedef uint64_t ( *drvmgr_r64_arg )( uint64_t *srcadr, void *a ); +typedef void ( *drvmgr_w8_arg )( uint8_t *dstadr, uint8_t data, void *a ); +typedef void ( *drvmgr_w16_arg )( uint16_t *dstadr, uint16_t data, void *a ); +typedef void ( *drvmgr_w32_arg )( uint32_t *dstadr, uint32_t data, void *a ); +typedef void ( *drvmgr_w64_arg )( uint64_t *dstadr, uint64_t data, void *a ); +typedef int ( *drvmgr_rmem_arg )( + void *dest, + const void *src, + int n, + void *a +); +typedef int ( *drvmgr_wmem_arg )( + void *dest, + const void *src, + int n, + void *a +); +typedef int ( *drvmgr_memset_arg )( void *dstadr, int c, size_t n, void *a ); /* Report an error to the parent bus of the device */ -typedef void (*drvmgr_rw_err)(struct drvmgr_rw_arg *a, struct drvmgr_bus *bus, - int funcid, void *adr); +typedef void ( *drvmgr_rw_err )( + struct drvmgr_rw_arg *a, + struct drvmgr_bus *bus, + int funcid, + void *adr +); /* Helper function for buses that implement the memset() over wmem() */ extern void drvmgr_rw_memset( - void *dstadr, - int c, - size_t n, - void *a, - drvmgr_wmem_arg wmem - ); + void *dstadr, + int c, + size_t n, + void *a, + drvmgr_wmem_arg wmem +); /*** PRINT INFORMATION ABOUT DRIVER MANAGER ***/ @@ -928,76 +1006,79 @@ extern void drvmgr_rw_memset( * */ extern int drvmgr_for_each_listdev( - struct drvmgr_list *devlist, - unsigned int state_set_mask, - unsigned int state_clr_mask, - int (*func)(struct drvmgr_dev *dev, void *arg), - void *arg); + struct drvmgr_list *devlist, + unsigned int state_set_mask, + unsigned int state_clr_mask, + int ( *func )( struct drvmgr_dev *dev, void *arg ), + void *arg +); /* Print all devices */ -#define PRINT_DEVS_FAILED 0x01 /* Failed during initialization */ -#define PRINT_DEVS_ASSIGNED 0x02 /* Driver assigned */ -#define PRINT_DEVS_UNASSIGNED 0x04 /* Driver not assigned */ -#define PRINT_DEVS_IGNORED 0x08 /* Device ignored on user's request */ -#define PRINT_DEVS_ALL (PRINT_DEVS_FAILED | \ - PRINT_DEVS_ASSIGNED | \ - PRINT_DEVS_UNASSIGNED |\ - PRINT_DEVS_IGNORED) +#define PRINT_DEVS_FAILED 0x01 /* Failed during initialization */ +#define PRINT_DEVS_ASSIGNED 0x02 /* Driver assigned */ +#define PRINT_DEVS_UNASSIGNED 0x04 /* Driver not assigned */ +#define PRINT_DEVS_IGNORED 0x08 /* Device ignored on user's request */ +#define PRINT_DEVS_ALL \ + ( PRINT_DEVS_FAILED | PRINT_DEVS_ASSIGNED | PRINT_DEVS_UNASSIGNED | \ + PRINT_DEVS_IGNORED ) /*! Print number of devices, buses and drivers */ -extern void drvmgr_summary(void); +extern void drvmgr_summary( void ); /*! Print devices with certain condictions met according to 'options' */ -extern void drvmgr_print_devs(unsigned int options); +extern void drvmgr_print_devs( unsigned int options ); /*! Print device/bus topology */ -extern void drvmgr_print_topo(void); +extern void drvmgr_print_topo( void ); /*! Print the memory usage * Only accounts for data structures. Not for the text size. */ -extern void drvmgr_print_mem(void); +extern void drvmgr_print_mem( void ); -#define OPTION_DEV_GENINFO 0x00000001 -#define OPTION_DEV_BUSINFO 0x00000002 -#define OPTION_DEV_DRVINFO 0x00000004 -#define OPTION_DRV_DEVS 0x00000100 -#define OPTION_BUS_DEVS 0x00010000 -#define OPTION_RECURSIVE 0x01000000 -#define OPTION_INFO_ALL 0xffffffff +#define OPTION_DEV_GENINFO 0x00000001 +#define OPTION_DEV_BUSINFO 0x00000002 +#define OPTION_DEV_DRVINFO 0x00000004 +#define OPTION_DRV_DEVS 0x00000100 +#define OPTION_BUS_DEVS 0x00010000 +#define OPTION_RECURSIVE 0x01000000 +#define OPTION_INFO_ALL 0xffffffff /*! Print information about a driver manager object (device, driver, bus) */ -extern void drvmgr_info(void *id, unsigned int options); +extern void drvmgr_info( void *id, unsigned int options ); /*! Get information about a device */ -extern void drvmgr_info_dev(struct drvmgr_dev *dev, unsigned int options); +extern void drvmgr_info_dev( struct drvmgr_dev *dev, unsigned int options ); /*! Get information about a bus */ -extern void drvmgr_info_bus(struct drvmgr_bus *bus, unsigned int options); +extern void drvmgr_info_bus( struct drvmgr_bus *bus, unsigned int options ); /*! Get information about a driver */ -extern void drvmgr_info_drv(struct drvmgr_drv *drv, unsigned int options); +extern void drvmgr_info_drv( struct drvmgr_drv *drv, unsigned int options ); /*! Get information about all devices on a bus */ -extern void drvmgr_info_devs_on_bus(struct drvmgr_bus *bus, unsigned int options); +extern void drvmgr_info_devs_on_bus( + struct drvmgr_bus *bus, + unsigned int options +); /*! Get information about all devices in the system (on all buses) */ -extern void drvmgr_info_devs(unsigned int options); +extern void drvmgr_info_devs( unsigned int options ); /*! Get information about all drivers in the system */ -extern void drvmgr_info_drvs(unsigned int options); +extern void drvmgr_info_drvs( unsigned int options ); /*! Get information about all buses in the system */ -extern void drvmgr_info_buses(unsigned int options); +extern void drvmgr_info_buses( unsigned int options ); /*! Get Driver by Driver ID */ -extern struct drvmgr_drv *drvmgr_drv_by_id(uint64_t id); +extern struct drvmgr_drv *drvmgr_drv_by_id( uint64_t id ); /*! Get Driver by Driver Name */ -extern struct drvmgr_drv *drvmgr_drv_by_name(const char *name); +extern struct drvmgr_drv *drvmgr_drv_by_name( const char *name ); /*! Get Device by Device Name */ -extern struct drvmgr_dev *drvmgr_dev_by_name(const char *name); +extern struct drvmgr_dev *drvmgr_dev_by_name( const char *name ); #ifdef __cplusplus } diff --git a/cpukit/include/drvmgr/drvmgr_confdefs.h b/cpukit/include/drvmgr/drvmgr_confdefs.h index bd6fa4c3c0..f715a07bbf 100644 --- a/cpukit/include/drvmgr/drvmgr_confdefs.h +++ b/cpukit/include/drvmgr/drvmgr_confdefs.h @@ -53,228 +53,224 @@ extern drvmgr_drv_reg_func drvmgr_drivers[]; #ifdef CONFIGURE_INIT /*** AMBA Plug & Play Drivers ***/ -extern void gptimer_register_drv(void); -extern void apbuart_cons_register_drv(void); -extern void greth_register_drv(void); -extern void grspw_register_drv(void); -extern void grspw2_register_drv(void); -extern void grcan_register_drv(void); -extern void occan_register_drv(void); -extern void gr1553_register(void); -extern void gr1553bc_register(void); -extern void gr1553bm_register(void); -extern void gr1553rt_register(void); -extern void b1553brm_register_drv(void); -extern void b1553rt_register_drv(void); -extern void grtm_register_drv(void); -extern void grtc_register_drv(void); -extern void pcif_register_drv(void); -extern void grpci_register_drv(void); -extern void mctrl_register_drv(void); -extern void l2cache_register_drv(void); -extern void griommu_register_drv(void); -extern void grpci2_register_drv(void); -extern void spictrl_register_drv(void); -extern void i2cmst_register_drv(void); -extern void grgpio_register_drv(void); -extern void grpwm_register_drv(void); -extern void gradcdac_register_drv(void); -extern void spwcuc_register(void); -extern void grctm_register(void); -extern void router_register_drv(void); -extern void ahbstat_register_drv(void); -extern void memscrub_register_drv(void); -extern void l4stat_register_drv(void); -extern void spwtdp_register_drv(void); - +extern void gptimer_register_drv( void ); +extern void apbuart_cons_register_drv( void ); +extern void greth_register_drv( void ); +extern void grspw_register_drv( void ); +extern void grspw2_register_drv( void ); +extern void grcan_register_drv( void ); +extern void occan_register_drv( void ); +extern void gr1553_register( void ); +extern void gr1553bc_register( void ); +extern void gr1553bm_register( void ); +extern void gr1553rt_register( void ); +extern void b1553brm_register_drv( void ); +extern void b1553rt_register_drv( void ); +extern void grtm_register_drv( void ); +extern void grtc_register_drv( void ); +extern void pcif_register_drv( void ); +extern void grpci_register_drv( void ); +extern void mctrl_register_drv( void ); +extern void l2cache_register_drv( void ); +extern void griommu_register_drv( void ); +extern void grpci2_register_drv( void ); +extern void spictrl_register_drv( void ); +extern void i2cmst_register_drv( void ); +extern void grgpio_register_drv( void ); +extern void grpwm_register_drv( void ); +extern void gradcdac_register_drv( void ); +extern void spwcuc_register( void ); +extern void grctm_register( void ); +extern void router_register_drv( void ); +extern void ahbstat_register_drv( void ); +extern void memscrub_register_drv( void ); +extern void l4stat_register_drv( void ); +extern void spwtdp_register_drv( void ); /*** LEON2 AMBA Hard coded bus Drivers ***/ -extern void at697pci_register_drv(void); -extern void ambapp_leon2_register(void); - +extern void at697pci_register_drv( void ); +extern void ambapp_leon2_register( void ); /*** PCI Bus Drivers (PCI Target drivers) ***/ -extern void gr_rasta_adcdac_register_drv(void); -extern void gr_rasta_io_register_drv(void); -extern void gr_rasta_tmtc_register_drv(void); -extern void gr701_register_drv(void); -extern void gr_tmtc_1553_register_drv(void); -extern void gr_rasta_spw_router_register_drv(void); -extern void gr_cpci_leon4_n2x_register_drv(void); -extern void gr_cpci_gr740_register_drv(void); - +extern void gr_rasta_adcdac_register_drv( void ); +extern void gr_rasta_io_register_drv( void ); +extern void gr_rasta_tmtc_register_drv( void ); +extern void gr701_register_drv( void ); +extern void gr_tmtc_1553_register_drv( void ); +extern void gr_rasta_spw_router_register_drv( void ); +extern void gr_cpci_leon4_n2x_register_drv( void ); +extern void gr_cpci_gr740_register_drv( void ); /* CONFIGURE DRIVER MANAGER */ drvmgr_drv_reg_func drvmgr_drivers[] = { - /*** AMBA Plug & Play Drivers ***/ +/*** AMBA Plug & Play Drivers ***/ #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER - gptimer_register_drv, + gptimer_register_drv, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART - apbuart_cons_register_drv, + apbuart_cons_register_drv, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_GRETH - greth_register_drv, + greth_register_drv, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW - grspw_register_drv, + grspw_register_drv, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW2 - grspw2_register_drv, + grspw2_register_drv, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_GRCAN - grcan_register_drv, + grcan_register_drv, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_OCCAN - occan_register_drv, + occan_register_drv, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_GR1553B - gr1553_register, + gr1553_register, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_GR1553BC - gr1553bc_register, + gr1553bc_register, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_GR1553BM - gr1553bm_register, + gr1553bm_register, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_GR1553RT - gr1553rt_register, + gr1553rt_register, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_B1553BRM - b1553brm_register_drv, + b1553brm_register_drv, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_B1553RT - b1553rt_register_drv, + b1553rt_register_drv, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_GRTM - grtm_register_drv, + grtm_register_drv, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_GRTC - grtc_register_drv, + grtc_register_drv, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_PCIF - pcif_register_drv, + pcif_register_drv, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_GRPCI - grpci_register_drv, + grpci_register_drv, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_GRPCI2 - grpci2_register_drv, + grpci2_register_drv, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_MCTRL - mctrl_register_drv, + mctrl_register_drv, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_L2CACHE - l2cache_register_drv, + l2cache_register_drv, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_GRIOMMU - griommu_register_drv, + griommu_register_drv, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_SPICTRL - spictrl_register_drv, + spictrl_register_drv, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_I2CMST - i2cmst_register_drv, + i2cmst_register_drv, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_GRGPIO - grgpio_register_drv, + grgpio_register_drv, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_GRPWM - grpwm_register_drv, + grpwm_register_drv, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_GRADCDAC - gradcdac_register_drv, + gradcdac_register_drv, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_SPWCUC - spwcuc_register, + spwcuc_register, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_GRCTM - grctm_register, + grctm_register, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_SPW_ROUTER - router_register_drv, + router_register_drv, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_AHBSTAT - ahbstat_register_drv, + ahbstat_register_drv, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_MEMSCRUB - memscrub_register_drv, + memscrub_register_drv, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_L4STAT - l4stat_register_drv, + l4stat_register_drv, #endif #ifdef CONFIGURE_DRIVER_AMBAPP_GAISLER_SPWTDP - spwtdp_register_drv, + spwtdp_register_drv, #endif - /*** LEON2 AMBA Drivers ***/ +/*** LEON2 AMBA Drivers ***/ #ifdef CONFIGURE_DRIVER_LEON2_AT697PCI - at697pci_register_drv, + at697pci_register_drv, #endif #ifdef CONFIGURE_DRIVER_LEON2_AMBAPP - ambapp_leon2_register, + ambapp_leon2_register, #endif - /*** PCI Target Drivers ***/ +/*** PCI Target Drivers ***/ #ifdef CONFIGURE_DRIVER_PCI_GR_RASTA_ADCDAC - gr_rasta_adcdac_register_drv, + gr_rasta_adcdac_register_drv, #endif #ifdef CONFIGURE_DRIVER_PCI_GR_RASTA_IO - gr_rasta_io_register_drv, + gr_rasta_io_register_drv, #endif #ifdef CONFIGURE_DRIVER_PCI_GR_RASTA_TMTC - gr_rasta_tmtc_register_drv, + gr_rasta_tmtc_register_drv, #endif #ifdef CONFIGURE_DRIVER_PCI_GR_701 - gr701_register_drv, + gr701_register_drv, #endif #ifdef CONFIGURE_DRIVER_PCI_GR_TMTC_1553 - gr_tmtc_1553_register_drv, + gr_tmtc_1553_register_drv, #endif #ifdef CONFIGURE_DRIVER_PCI_GR_RASTA_SPW_ROUTER - gr_rasta_spw_router_register_drv, + gr_rasta_spw_router_register_drv, #endif #ifdef CONFIGURE_DRIVER_PCI_GR_LEON4_N2X - gr_cpci_leon4_n2x_register_drv, + gr_cpci_leon4_n2x_register_drv, #endif #ifdef CONFIGURE_DRIVER_PCI_GR_CPCI_GR740 - gr_cpci_gr740_register_drv, + gr_cpci_gr740_register_drv, #endif - /* Macros for adding custom drivers without needing to recompile * kernel. */ #ifdef CONFIGURE_DRIVER_CUSTOM1 - DRIVER_CUSTOM1_REG, + DRIVER_CUSTOM1_REG, #endif #ifdef CONFIGURE_DRIVER_CUSTOM2 - DRIVER_CUSTOM2_REG, + DRIVER_CUSTOM2_REG, #endif #ifdef CONFIGURE_DRIVER_CUSTOM3 - DRIVER_CUSTOM3_REG, + DRIVER_CUSTOM3_REG, #endif #ifdef CONFIGURE_DRIVER_CUSTOM4 - DRIVER_CUSTOM4_REG, + DRIVER_CUSTOM4_REG, #endif #ifdef CONFIGURE_DRIVER_CUSTOM5 - DRIVER_CUSTOM5_REG, + DRIVER_CUSTOM5_REG, #endif #ifdef CONFIGURE_DRIVER_CUSTOM6 - DRIVER_CUSTOM6_REG, + DRIVER_CUSTOM6_REG, #endif #ifdef CONFIGURE_DRIVER_CUSTOM7 - DRIVER_CUSTOM7_REG, + DRIVER_CUSTOM7_REG, #endif #ifdef CONFIGURE_DRIVER_CUSTOM8 - DRIVER_CUSTOM8_REG, + DRIVER_CUSTOM8_REG, #endif #ifdef CONFIGURE_DRIVER_CUSTOM9 - DRIVER_CUSTOM9_REG, + DRIVER_CUSTOM9_REG, #endif - /* End array with NULL */ - NULL + /* End array with NULL */ + NULL }; #endif /* CONFIGURE_INIT */ diff --git a/cpukit/include/drvmgr/drvmgr_list.h b/cpukit/include/drvmgr/drvmgr_list.h index a5eb927ec6..d8b9cad231 100644 --- a/cpukit/include/drvmgr/drvmgr_list.h +++ b/cpukit/include/drvmgr/drvmgr_list.h @@ -46,31 +46,34 @@ extern "C" { /*! List description, Singly link list with head and tail pointers. */ struct drvmgr_list { - void *head; /*!< First entry in queue */ - void *tail; /*!< Last entry in queue */ - int ofs; /*!< Offset into head and tail to find next field */ + void *head; /*!< First entry in queue */ + void *tail; /*!< Last entry in queue */ + int ofs; /*!< Offset into head and tail to find next field */ }; /* Static initialization of list */ -#define LIST_INITIALIZER(type, field) {NULL, NULL, offsetof(type, field)} +#define LIST_INITIALIZER( type, field ) { NULL, NULL, offsetof( type, field ) } /* Return the first element in list */ -#define LIST_HEAD(list, type) ((type *)(list)->head) +#define LIST_HEAD( list, type ) ( (type *) ( list )->head ) /* Return the last element in list */ -#define LIST_TAIL(list, type) ((type *)(list)->tail) +#define LIST_TAIL( list, type ) ( (type *) ( list )->tail ) /* Get the next pointer of an entry */ -#define LIST_FIELD(list, entry) (*(void **)((char *)(entry) + (list)->ofs)) +#define LIST_FIELD( list, entry ) \ + ( *(void **) ( (char *) ( entry ) + ( list )->ofs ) ) /* Return the next emlement in list */ -#define LIST_NEXT(list, entry, type) ((type *)(LIST_FIELD(list, entry))) +#define LIST_NEXT( list, entry, type ) \ + ( (type *) ( LIST_FIELD( list, entry ) ) ) /* Iterate through all entries in list */ -#define LIST_FOR_EACH(list, entry, type) \ - for (entry = LIST_HEAD(list, type); \ - entry; \ - entry = LIST_NEXT(list, entry, type)) +#define LIST_FOR_EACH( list, entry, type ) \ + for ( \ + entry = LIST_HEAD( list, type ); entry; \ + entry = LIST_NEXT( list, entry, type ) \ + ) /*! Initialize a list during runtime * @@ -78,22 +81,22 @@ struct drvmgr_list { * \param offset The number of bytes into the entry structure the next pointer * is found */ -extern void drvmgr_list_init(struct drvmgr_list *list, int offset); +extern void drvmgr_list_init( struct drvmgr_list *list, int offset ); /*! Clear list */ -extern void drvmgr_list_empty(struct drvmgr_list *list); +extern void drvmgr_list_empty( struct drvmgr_list *list ); /*! Add entry to front of list */ -extern void drvmgr_list_add_head(struct drvmgr_list *list, void *entry); +extern void drvmgr_list_add_head( struct drvmgr_list *list, void *entry ); /*! Add entry to end of list */ -extern void drvmgr_list_add_tail(struct drvmgr_list *list, void *entry); +extern void drvmgr_list_add_tail( struct drvmgr_list *list, void *entry ); /*! Remove entry from front of list */ -extern void drvmgr_list_remove_head(struct drvmgr_list *list); +extern void drvmgr_list_remove_head( struct drvmgr_list *list ); /*! Remove entry from anywhere in list */ -extern void drvmgr_list_remove(struct drvmgr_list *list, void *entry); +extern void drvmgr_list_remove( struct drvmgr_list *list, void *entry ); #ifdef __cplusplus } diff --git a/cpukit/include/drvmgr/pci_bus.h b/cpukit/include/drvmgr/pci_bus.h index 2e3940f1e5..ef8c776e45 100644 --- a/cpukit/include/drvmgr/pci_bus.h +++ b/cpukit/include/drvmgr/pci_bus.h @@ -55,120 +55,134 @@ extern "C" { #endif /* PCI Driver ID generation (VENDOR: 16-bit, DEVICE: 16-bit) */ -#define DRIVER_PCI_ID(vendor, device) \ - DRIVER_ID(DRVMGR_BUS_TYPE_PCI, \ - ((((vendor) & 0xffff) << 16) | ((device) & 0xffff))) +#define DRIVER_PCI_ID( vendor, device ) \ + DRIVER_ID( \ + DRVMGR_BUS_TYPE_PCI, \ + ( ( ( ( vendor ) & 0xffff ) << 16 ) | ( ( device ) & 0xffff ) ) \ + ) /* PCI Driver ID generation (CLASS: 24-bit) */ -#define DRIVER_PCI_CLASS(class) \ - DRIVER_ID(DRVMGR_BUS_TYPE_PCI, ((1 << 32) | ((class) & 0xffffff))) +#define DRIVER_PCI_CLASS( class ) \ + DRIVER_ID( DRVMGR_BUS_TYPE_PCI, ( ( 1 << 32 ) | ( ( class ) & 0xffffff ) ) ) /* PCI driver IDs (DRIVER_PCI_VENDOR_DEVICE or DRIVER_PCI_CLASS_NAME) */ -#define DRIVER_PCI_GAISLER_RASTAIO_ID DRIVER_PCI_ID(PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_RASTA_IO) -#define DRIVER_PCI_GAISLER_RASTATMTC_ID DRIVER_PCI_ID(PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_RASTA_TMTC) -#define DRIVER_PCI_GAISLER_GR701_ID DRIVER_PCI_ID(PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_701) -#define DRIVER_PCI_GAISLER_RASTAADCDAC_ID DRIVER_PCI_ID(PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_RASTA_ADCDAC) -#define DRIVER_PCI_GAISLER_TMTC_1553_ID DRIVER_PCI_ID(PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_TMTC_1553) -#define DRIVER_PCI_GAISLER_RASTA_SPW_ROUTER_ID DRIVER_PCI_ID(PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_RASTA_SPW_RTR) -#define DRIVER_PCI_GAISLER_LEON4_N2X_ID DRIVER_PCI_ID(PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_LEON4_N2X) -#define DRIVER_PCI_GAISLER_CPCI_GR740_ID DRIVER_PCI_ID(PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_CPCI_GR740) +#define DRIVER_PCI_GAISLER_RASTAIO_ID \ + DRIVER_PCI_ID( PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_RASTA_IO ) +#define DRIVER_PCI_GAISLER_RASTATMTC_ID \ + DRIVER_PCI_ID( PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_RASTA_TMTC ) +#define DRIVER_PCI_GAISLER_GR701_ID \ + DRIVER_PCI_ID( PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_701 ) +#define DRIVER_PCI_GAISLER_RASTAADCDAC_ID \ + DRIVER_PCI_ID( PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_RASTA_ADCDAC ) +#define DRIVER_PCI_GAISLER_TMTC_1553_ID \ + DRIVER_PCI_ID( PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_TMTC_1553 ) +#define DRIVER_PCI_GAISLER_RASTA_SPW_ROUTER_ID \ + DRIVER_PCI_ID( PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_RASTA_SPW_RTR ) +#define DRIVER_PCI_GAISLER_LEON4_N2X_ID \ + DRIVER_PCI_ID( PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_LEON4_N2X ) +#define DRIVER_PCI_GAISLER_CPCI_GR740_ID \ + DRIVER_PCI_ID( PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_CPCI_GR740 ) struct pci_dev_id { - uint16_t vendor; - uint16_t device; - uint16_t subvendor; - uint16_t subdevice; - uint32_t class; /* 24 lower bits */ + uint16_t vendor; + uint16_t device; + uint16_t subvendor; + uint16_t subdevice; + uint32_t class; /* 24 lower bits */ }; struct pci_dev_id_match { - uint16_t vendor; - uint16_t device; - uint16_t subvendor; - uint16_t subdevice; - uint32_t class; /* 24 lower bits */ - uint32_t class_mask; /* 24 lower bits */ + uint16_t vendor; + uint16_t device; + uint16_t subvendor; + uint16_t subdevice; + uint32_t class; /* 24 lower bits */ + uint32_t class_mask; /* 24 lower bits */ }; -#define PCIID_DEVVEND(vendor, device) \ - {vendor, device, PCI_ID_ANY, PCI_ID_ANY, 0, 0} -#define PCIID_END_TABLE {0, 0, 0, 0, 0, 0} +#define PCIID_DEVVEND( vendor, device ) \ + { vendor, device, PCI_ID_ANY, PCI_ID_ANY, 0, 0 } +#define PCIID_END_TABLE { 0, 0, 0, 0, 0, 0 } enum { - /* A Device has up to 6 BARs and an optional ROM BAR */ - PCIDEV_RES_BAR1 = 0, - PCIDEV_RES_BAR2 = 1, - PCIDEV_RES_BAR3 = 2, - PCIDEV_RES_BAR4 = 3, - PCIDEV_RES_BAR5 = 4, - PCIDEV_RES_BAR6 = 5, - PCIDEV_RES_ROM = 6, + /* A Device has up to 6 BARs and an optional ROM BAR */ + PCIDEV_RES_BAR1 = 0, + PCIDEV_RES_BAR2 = 1, + PCIDEV_RES_BAR3 = 2, + PCIDEV_RES_BAR4 = 3, + PCIDEV_RES_BAR5 = 4, + PCIDEV_RES_BAR6 = 5, + PCIDEV_RES_ROM = 6, }; /* Maximum Number of Resources of a device */ -#define PCIDEV_RES_CNT (PCIDEV_RES_ROM + 1) +#define PCIDEV_RES_CNT ( PCIDEV_RES_ROM + 1 ) /* IO, MEMIO or MEM resource. Can be BAR, ROM or Bridge Window */ struct pcibus_res { - uint32_t address; /* Base Address, CPU accessible */ - uint32_t size; /* 0=Unimplemented, 0!=Resource Size */ - struct pci_res *res; /* PCI-layer resource */ + uint32_t address; /* Base Address, CPU accessible */ + uint32_t size; /* 0=Unimplemented, 0!=Resource Size */ + struct pci_res *res; /* PCI-layer resource */ }; struct pci_dev_info { - struct pci_dev_id id; - uint8_t rev; - uint8_t irq; /* 0 = NO IRQ */ - pci_dev_t pcidev; - struct pcibus_res resources[PCIDEV_RES_CNT]; - struct pci_dev *pci_device; + struct pci_dev_id id; + uint8_t rev; + uint8_t irq; /* 0 = NO IRQ */ + pci_dev_t pcidev; + struct pcibus_res resources[ PCIDEV_RES_CNT ]; + struct pci_dev *pci_device; }; struct pci_drv_info { - struct drvmgr_drv general; /* General bus info */ - /* PCI specific bus information */ - struct pci_dev_id_match *ids; /* Supported hardware */ + struct drvmgr_drv general; /* General bus info */ + /* PCI specific bus information */ + struct pci_dev_id_match *ids; /* Supported hardware */ }; /* Access routines */ struct pcibus_regmem_ops { - drvmgr_r8 r8; - drvmgr_r16 r16; - drvmgr_r32 r32; - drvmgr_r64 r64; - drvmgr_w8 w8; - drvmgr_w16 w16; - drvmgr_w32 w32; - drvmgr_w64 w64; + drvmgr_r8 r8; + drvmgr_r16 r16; + drvmgr_r32 r32; + drvmgr_r64 r64; + drvmgr_w8 w8; + drvmgr_w16 w16; + drvmgr_w32 w32; + drvmgr_w64 w64; }; /* Let driver configure PCI bus driver */ struct pcibus_config { - struct drvmgr_map_entry *maps_up; - struct drvmgr_map_entry *maps_down; + struct drvmgr_map_entry *maps_up; + struct drvmgr_map_entry *maps_down; }; /* PCI Configuration Space Access - Not implemented (use PCI Lib directly) */ -#define PCI_FUNC_CFG_R8 DRVMGR_RWFUNC(RW_SIZE_1|RW_READ|RW_CFG) -#define PCI_FUNC_CFG_R16 DRVMGR_RWFUNC(RW_SIZE_2|RW_READ|RW_CFG) -#define PCI_FUNC_CFG_R32 DRVMGR_RWFUNC(RW_SIZE_4|RW_READ|RW_CFG) -#define PCI_FUNC_CFG_W8 DRVMGR_RWFUNC(RW_SIZE_1|RW_WRITE|RW_CFG) -#define PCI_FUNC_CFG_W16 DRVMGR_RWFUNC(RW_SIZE_2|RW_WRITE|RW_CFG) -#define PCI_FUNC_CFG_W32 DRVMGR_RWFUNC(RW_SIZE_4|RW_WRITE|RW_CFG) +#define PCI_FUNC_CFG_R8 DRVMGR_RWFUNC( RW_SIZE_1 | RW_READ | RW_CFG ) +#define PCI_FUNC_CFG_R16 DRVMGR_RWFUNC( RW_SIZE_2 | RW_READ | RW_CFG ) +#define PCI_FUNC_CFG_R32 DRVMGR_RWFUNC( RW_SIZE_4 | RW_READ | RW_CFG ) +#define PCI_FUNC_CFG_W8 DRVMGR_RWFUNC( RW_SIZE_1 | RW_WRITE | RW_CFG ) +#define PCI_FUNC_CFG_W16 DRVMGR_RWFUNC( RW_SIZE_2 | RW_WRITE | RW_CFG ) +#define PCI_FUNC_CFG_W32 DRVMGR_RWFUNC( RW_SIZE_4 | RW_WRITE | RW_CFG ) /* PCI I/O Register Access - Not implemented (use PCI Lib directly) */ -#define PCI_FUNC_IO_R8 DRVMGR_RWFUNC(RW_SIZE_1|RW_READ|RW_IO) -#define PCI_FUNC_IO_R16 DRVMGR_RWFUNC(RW_SIZE_2|RW_READ|RW_IO) -#define PCI_FUNC_IO_R32 DRVMGR_RWFUNC(RW_SIZE_4|RW_READ|RW_IO) -#define PCI_FUNC_IO_W8 DRVMGR_RWFUNC(RW_SIZE_1|RW_WRITE|RW_IO) -#define PCI_FUNC_IO_W16 DRVMGR_RWFUNC(RW_SIZE_2|RW_WRITE|RW_IO) -#define PCI_FUNC_IO_W32 DRVMGR_RWFUNC(RW_SIZE_4|RW_WRITE|RW_IO) +#define PCI_FUNC_IO_R8 DRVMGR_RWFUNC( RW_SIZE_1 | RW_READ | RW_IO ) +#define PCI_FUNC_IO_R16 DRVMGR_RWFUNC( RW_SIZE_2 | RW_READ | RW_IO ) +#define PCI_FUNC_IO_R32 DRVMGR_RWFUNC( RW_SIZE_4 | RW_READ | RW_IO ) +#define PCI_FUNC_IO_W8 DRVMGR_RWFUNC( RW_SIZE_1 | RW_WRITE | RW_IO ) +#define PCI_FUNC_IO_W16 DRVMGR_RWFUNC( RW_SIZE_2 | RW_WRITE | RW_IO ) +#define PCI_FUNC_IO_W32 DRVMGR_RWFUNC( RW_SIZE_4 | RW_WRITE | RW_IO ) /* PCI Register Access over Memory Space (Little Endian) */ -#define PCI_FUNC_MREG_R8 DRVMGR_RWFUNC(RW_SIZE_1|RW_READ|RW_MEMREG) -#define PCI_FUNC_MREG_R16 DRVMGR_RWFUNC(RW_SIZE_2|RW_READ|RW_MEMREG|RW_LITTLE) -#define PCI_FUNC_MREG_R32 DRVMGR_RWFUNC(RW_SIZE_4|RW_READ|RW_MEMREG|RW_LITTLE) -#define PCI_FUNC_MREG_W8 DRVMGR_RWFUNC(RW_SIZE_1|RW_WRITE|RW_MEMREG) -#define PCI_FUNC_MREG_W16 DRVMGR_RWFUNC(RW_SIZE_2|RW_WRITE|RW_MEMREG|RW_LITTLE) -#define PCI_FUNC_MREG_W32 DRVMGR_RWFUNC(RW_SIZE_4|RW_WRITE|RW_MEMREG|RW_LITTLE) +#define PCI_FUNC_MREG_R8 DRVMGR_RWFUNC( RW_SIZE_1 | RW_READ | RW_MEMREG ) +#define PCI_FUNC_MREG_R16 \ + DRVMGR_RWFUNC( RW_SIZE_2 | RW_READ | RW_MEMREG | RW_LITTLE ) +#define PCI_FUNC_MREG_R32 \ + DRVMGR_RWFUNC( RW_SIZE_4 | RW_READ | RW_MEMREG | RW_LITTLE ) +#define PCI_FUNC_MREG_W8 DRVMGR_RWFUNC( RW_SIZE_1 | RW_WRITE | RW_MEMREG ) +#define PCI_FUNC_MREG_W16 \ + DRVMGR_RWFUNC( RW_SIZE_2 | RW_WRITE | RW_MEMREG | RW_LITTLE ) +#define PCI_FUNC_MREG_W32 \ + DRVMGR_RWFUNC( RW_SIZE_4 | RW_WRITE | RW_MEMREG | RW_LITTLE ) /* Weak default PCI driver resources, override this from project configuration * to set PCI Bus resources used to configure PCI device drivers. @@ -176,7 +190,10 @@ struct pcibus_config { extern struct drvmgr_bus_res pcibus_drv_resources; /* Attach a PCI bus on top of a PCI Host device */ -extern int pcibus_register(struct drvmgr_dev *dev, struct pcibus_config *cfg); +extern int pcibus_register( + struct drvmgr_dev *dev, + struct pcibus_config *cfg +); #ifdef __cplusplus } diff --git a/cpukit/libdrvmgr/drvmgr.c b/cpukit/libdrvmgr/drvmgr.c index aa70f17842..eac163094c 100644 --- a/cpukit/libdrvmgr/drvmgr.c +++ b/cpukit/libdrvmgr/drvmgr.c @@ -41,183 +41,183 @@ /*#define DEBUG 1*/ #ifdef DEBUG -#define DBG(x...) printk(x) +#define DBG( x... ) printk( x ) #else -#define DBG(x...) +#define DBG( x... ) #endif struct drvmgr drvmgr = { - .level = 0, - .initializing_objs = 0, - .lock = API_MUTEX_INITIALIZER("_Drvmgr"), - .root_dev = {0}, - .root_drv = NULL, + .level = 0, + .initializing_objs = 0, + .lock = API_MUTEX_INITIALIZER( "_Drvmgr" ), + .root_dev = { 0 }, + .root_drv = NULL, - .drivers = LIST_INITIALIZER(struct drvmgr_drv, next), + .drivers = LIST_INITIALIZER( struct drvmgr_drv, next ), - .buses = { - LIST_INITIALIZER(struct drvmgr_bus, next), - LIST_INITIALIZER(struct drvmgr_bus, next), - LIST_INITIALIZER(struct drvmgr_bus, next), - LIST_INITIALIZER(struct drvmgr_bus, next), - LIST_INITIALIZER(struct drvmgr_bus, next), - }, - .buses_inactive = LIST_INITIALIZER(struct drvmgr_bus, next), + .buses = + { + LIST_INITIALIZER( struct drvmgr_bus, next ), + LIST_INITIALIZER( struct drvmgr_bus, next ), + LIST_INITIALIZER( struct drvmgr_bus, next ), + LIST_INITIALIZER( struct drvmgr_bus, next ), + LIST_INITIALIZER( struct drvmgr_bus, next ), + }, + .buses_inactive = LIST_INITIALIZER( struct drvmgr_bus, next ), - .devices = { - LIST_INITIALIZER(struct drvmgr_dev, next), - LIST_INITIALIZER(struct drvmgr_dev, next), - LIST_INITIALIZER(struct drvmgr_dev, next), - LIST_INITIALIZER(struct drvmgr_dev, next), - LIST_INITIALIZER(struct drvmgr_dev, next), - }, - .devices_inactive = LIST_INITIALIZER(struct drvmgr_dev, next), + .devices = + { + LIST_INITIALIZER( struct drvmgr_dev, next ), + LIST_INITIALIZER( struct drvmgr_dev, next ), + LIST_INITIALIZER( struct drvmgr_dev, next ), + LIST_INITIALIZER( struct drvmgr_dev, next ), + LIST_INITIALIZER( struct drvmgr_dev, next ), + }, + .devices_inactive = LIST_INITIALIZER( struct drvmgr_dev, next ), }; static int do_bus_init( - struct drvmgr *mgr, - struct drvmgr_bus *bus, - int level); + struct drvmgr *mgr, + struct drvmgr_bus *bus, + int level +); static int do_dev_init( - struct drvmgr *mgr, - struct drvmgr_dev *dev, - int level); + struct drvmgr *mgr, + struct drvmgr_dev *dev, + int level +); /* DRIVER MANAGER */ -void _DRV_Manager_init_level(int level) +void _DRV_Manager_init_level( int level ) { - struct drvmgr *mgr = &drvmgr; + struct drvmgr *mgr = &drvmgr; - if (mgr->level >= level) - return; + if ( mgr->level >= level ) { + return; + } - /* Set new Level */ - mgr->level = level; + /* Set new Level */ + mgr->level = level; - /* Initialize buses and devices into this new level */ - drvmgr_init_update(); + /* Initialize buses and devices into this new level */ + drvmgr_init_update(); } /* Initialize Data structures of the driver manager and call driver * register functions configured by the user. */ -void _DRV_Manager_initialization(void) +void _DRV_Manager_initialization( void ) { - drvmgr_drv_reg_func *drvreg; + drvmgr_drv_reg_func *drvreg; - /* Call driver register functions. */ - drvreg = &drvmgr_drivers[0]; - while (*drvreg) { - /* Make driver register */ - (*drvreg)(); - drvreg++; - } + /* Call driver register functions. */ + drvreg = &drvmgr_drivers[ 0 ]; + while ( *drvreg ) { + /* Make driver register */ + ( *drvreg )(); + drvreg++; + } } /* Take ready devices and buses into the correct init level step by step. * Once a bus or a device has been registered there is no turning * back - they are taken to the level of the driver manager. */ -void drvmgr_init_update(void) +void drvmgr_init_update( void ) { - struct drvmgr *mgr = &drvmgr; - struct drvmgr_bus *bus; - struct drvmgr_dev *dev; - int bus_might_been_registered; - int level; + struct drvmgr *mgr = &drvmgr; + struct drvmgr_bus *bus; + struct drvmgr_dev *dev; + int bus_might_been_registered; + int level; - /* "Lock" to make sure we don't use up the stack and that the lists + /* "Lock" to make sure we don't use up the stack and that the lists * remain consistent. */ - DRVMGR_LOCK_WRITE(); - if (mgr->initializing_objs || (mgr->level == 0)) - goto out; - mgr->initializing_objs = 1; + DRVMGR_LOCK_WRITE(); + if ( mgr->initializing_objs || ( mgr->level == 0 ) ) { + goto out; + } + mgr->initializing_objs = 1; - /* Take all buses and devices ready into the same stage + /* Take all buses and devices ready into the same stage * as the driver manager global level. */ - for (level = 0; level < mgr->level; level++) { + for ( level = 0; level < mgr->level; level++ ) { + bus_might_been_registered = 0; - bus_might_been_registered = 0; + /* Take buses into next level */ - /* Take buses into next level */ - - while ((bus = BUS_LIST_HEAD(&mgr->buses[level])) != NULL) { - - /* Remove first in the list (will be inserted in + while ( ( bus = BUS_LIST_HEAD( &mgr->buses[ level ] ) ) != NULL ) { + /* Remove first in the list (will be inserted in * appropriate list by do_bus_init()) */ - drvmgr_list_remove_head(&mgr->buses[level]); + drvmgr_list_remove_head( &mgr->buses[ level ] ); - DRVMGR_UNLOCK(); + DRVMGR_UNLOCK(); - /* Initialize Bus, this will register devices on + /* Initialize Bus, this will register devices on * the bus. Take bus into next level. */ - do_bus_init(mgr, bus, level+1); + do_bus_init( mgr, bus, level + 1 ); - DRVMGR_LOCK_WRITE(); - } + DRVMGR_LOCK_WRITE(); + } - /* Take devices into next level */ - while ((dev = DEV_LIST_HEAD(&mgr->devices[level])) != NULL) { + /* Take devices into next level */ + while ( ( dev = DEV_LIST_HEAD( &mgr->devices[ level ] ) ) != NULL ) { + /* Always process first in list */ + dev = DEV_LIST_HEAD( &mgr->devices[ level ] ); - /* Always process first in list */ - dev = DEV_LIST_HEAD(&mgr->devices[level]); - - /* Remove first in the list (will be inserted in + /* Remove first in the list (will be inserted in * appropriate list by do_dev_init()) */ - drvmgr_list_remove_head(&mgr->devices[level]); + drvmgr_list_remove_head( &mgr->devices[ level ] ); - DRVMGR_UNLOCK(); + DRVMGR_UNLOCK(); - /* Initialize Device, this may register a new bus */ - do_dev_init(mgr, dev, level+1); + /* Initialize Device, this may register a new bus */ + do_dev_init( mgr, dev, level + 1 ); - DRVMGR_LOCK_WRITE(); + DRVMGR_LOCK_WRITE(); - bus_might_been_registered = 1; - } + bus_might_been_registered = 1; + } - /* Make sure all buses registered and ready are taken at + /* Make sure all buses registered and ready are taken at * the same time into init level N. */ - if (bus_might_been_registered) { - level = -1; /* restart loop */ - } - } + if ( bus_might_been_registered ) { + level = -1; /* restart loop */ + } + } - /* Release bus/device initialization "Lock" */ - mgr->initializing_objs = 0; + /* Release bus/device initialization "Lock" */ + mgr->initializing_objs = 0; out: - DRVMGR_UNLOCK(); + DRVMGR_UNLOCK(); } /* Take bus into next level */ -static int do_bus_init( - struct drvmgr *mgr, - struct drvmgr_bus *bus, - int level) +static int do_bus_init( struct drvmgr *mgr, struct drvmgr_bus *bus, int level ) { - int (*init)(struct drvmgr_bus *); + int ( *init )( struct drvmgr_bus * ); - /* If bridge device has failed during initialization, the bus is not + /* If bridge device has failed during initialization, the bus is not * initialized further. */ - if (bus->dev->state & DEV_STATE_INIT_FAILED) { - bus->state |= BUS_STATE_DEPEND_FAILED; - goto inactivate_out; - } + if ( bus->dev->state & DEV_STATE_INIT_FAILED ) { + bus->state |= BUS_STATE_DEPEND_FAILED; + goto inactivate_out; + } - if (bus->ops && (init = bus->ops->init[level-1])) { - /* Note: This init1 function may register new devices */ - bus->error = init(bus); - if (bus->error != DRVMGR_OK) { - /* An error of some kind during bus initialization. + if ( bus->ops && ( init = bus->ops->init[ level - 1 ] ) ) { + /* Note: This init1 function may register new devices */ + bus->error = init( bus ); + if ( bus->error != DRVMGR_OK ) { + /* An error of some kind during bus initialization. * * Child devices and their buses are not inactived * directly here, instead they will all be catched by @@ -225,67 +225,64 @@ static int do_bus_init( * parent or bridge-device failed. We know that * initialization will happen later for those devices. */ - goto inactivate_out; - } - } + goto inactivate_out; + } + } - DRVMGR_LOCK_WRITE(); + DRVMGR_LOCK_WRITE(); - /* Bus taken into the new level */ - bus->level = level; + /* Bus taken into the new level */ + bus->level = level; - /* Put bus into list of buses reached level 'level'. + /* Put bus into list of buses reached level 'level'. * Put at end of bus list so that init[N+1]() calls comes * in the same order as init[N]() */ - drvmgr_list_add_tail(&mgr->buses[level], bus); + drvmgr_list_add_tail( &mgr->buses[ level ], bus ); - DRVMGR_UNLOCK(); + DRVMGR_UNLOCK(); - return 0; + return 0; inactivate_out: - DRVMGR_LOCK_WRITE(); - bus->state |= BUS_STATE_INIT_FAILED; - bus->state |= BUS_STATE_LIST_INACTIVE; - drvmgr_list_add_head(&mgr->buses_inactive, bus); - DRVMGR_UNLOCK(); + DRVMGR_LOCK_WRITE(); + bus->state |= BUS_STATE_INIT_FAILED; + bus->state |= BUS_STATE_LIST_INACTIVE; + drvmgr_list_add_head( &mgr->buses_inactive, bus ); + DRVMGR_UNLOCK(); - DBG("do_bus_init(%d): (DEV: %s) failed\n", level, bus->dev->name); + DBG( "do_bus_init(%d): (DEV: %s) failed\n", level, bus->dev->name ); - return 1; + return 1; } /* Take device to initialization level 1 */ -static int do_dev_init( - struct drvmgr *mgr, - struct drvmgr_dev *dev, - int level) +static int do_dev_init( struct drvmgr *mgr, struct drvmgr_dev *dev, int level ) { - int (*init)(struct drvmgr_dev *); + int ( *init )( struct drvmgr_dev * ); - /* Try to allocate Private Device Structure for driver if driver + /* Try to allocate Private Device Structure for driver if driver * requests for this feature. */ - if (dev->drv && dev->drv->dev_priv_size && !dev->priv) { - dev->priv = malloc(dev->drv->dev_priv_size); - memset(dev->priv, 0, dev->drv->dev_priv_size); - } + if ( dev->drv && dev->drv->dev_priv_size && !dev->priv ) { + dev->priv = malloc( dev->drv->dev_priv_size ); + memset( dev->priv, 0, dev->drv->dev_priv_size ); + } - /* If parent bus has failed during initialization, + /* If parent bus has failed during initialization, * the device is not initialized further. */ - if (dev->parent && (dev->parent->state & BUS_STATE_INIT_FAILED)) { - dev->state |= DEV_STATE_DEPEND_FAILED; - goto inactivate_out; - } + if ( dev->parent && ( dev->parent->state & BUS_STATE_INIT_FAILED ) ) { + dev->state |= DEV_STATE_DEPEND_FAILED; + goto inactivate_out; + } - /* Call Driver's Init Routine */ - if (dev->drv && (init = dev->drv->ops->init[level-1])) { - /* Note: This init function may register new devices */ - dev->error = init(dev); - if (dev->error != DRVMGR_OK) { - /* An error of some kind has occurred in the + /* Call Driver's Init Routine */ + if ( dev->drv && ( init = dev->drv->ops->init[ level - 1 ] ) ) { + /* Note: This init function may register new devices */ + dev->error = init( dev ); + if ( dev->error != DRVMGR_OK ) { + /* An error of some kind has occurred in the * driver/device, the failed device is put into the * inactive list, this way Init2,3 and/or 4 will not * be called for this device. @@ -301,83 +298,88 @@ static int do_dev_init( * parent or bridge-device failed. We know that * initialization will happen later for those devices. */ - goto inactivate_out; - } - } + goto inactivate_out; + } + } - DRVMGR_LOCK_WRITE(); - /* Dev taken into new level */ - dev->level = level; + DRVMGR_LOCK_WRITE(); + /* Dev taken into new level */ + dev->level = level; - /* Put at end of device list so that init[N+1]() calls comes + /* Put at end of device list so that init[N+1]() calls comes * in the same order as init[N]() */ - drvmgr_list_add_tail(&mgr->devices[level], dev); - DRVMGR_UNLOCK(); + drvmgr_list_add_tail( &mgr->devices[ level ], dev ); + DRVMGR_UNLOCK(); - return 0; + return 0; inactivate_out: - DRVMGR_LOCK_WRITE(); - dev->state |= DEV_STATE_INIT_FAILED; - dev->state |= DEV_STATE_LIST_INACTIVE; - drvmgr_list_add_head(&mgr->devices_inactive, dev); - DRVMGR_UNLOCK(); + DRVMGR_LOCK_WRITE(); + dev->state |= DEV_STATE_INIT_FAILED; + dev->state |= DEV_STATE_LIST_INACTIVE; + drvmgr_list_add_head( &mgr->devices_inactive, dev ); + DRVMGR_UNLOCK(); - DBG("do_dev_init(%d): DRV: %s (DEV: %s) failed\n", - level, dev->drv->name, dev->name); + DBG( + "do_dev_init(%d): DRV: %s (DEV: %s) failed\n", + level, + dev->drv->name, + dev->name + ); - return 1; /* Failed to take device into requested level */ + return 1; /* Failed to take device into requested level */ } /* Register Root device driver */ -int drvmgr_root_drv_register(struct drvmgr_drv *drv) +int drvmgr_root_drv_register( struct drvmgr_drv *drv ) { - struct drvmgr *mgr = &drvmgr; - struct drvmgr_dev *root = &mgr->root_dev; + struct drvmgr *mgr = &drvmgr; + struct drvmgr_dev *root = &mgr->root_dev; - if (mgr->root_drv) { - /* Only possible to register root device once */ - return DRVMGR_FAIL; - } + if ( mgr->root_drv ) { + /* Only possible to register root device once */ + return DRVMGR_FAIL; + } - /* Set root device driver */ - drv->next = NULL; - mgr->root_drv = drv; + /* Set root device driver */ + drv->next = NULL; + mgr->root_drv = drv; - /* Init root device non-NULL fields */ - root->minor_drv = -1; - root->minor_bus = 0; - root->businfo = mgr; - root->name = "root bus"; - /* Custom Driver association */ - root->drv = mgr->root_drv; + /* Init root device non-NULL fields */ + root->minor_drv = -1; + root->minor_bus = 0; + root->businfo = mgr; + root->name = "root bus"; + /* Custom Driver association */ + root->drv = mgr->root_drv; - /* This registers the root device and a bus */ - drvmgr_dev_register(root); + /* This registers the root device and a bus */ + drvmgr_dev_register( root ); - return DRVMGR_OK; + return DRVMGR_OK; } /* Register a driver */ -int drvmgr_drv_register(struct drvmgr_drv *drv) +int drvmgr_drv_register( struct drvmgr_drv *drv ) { - struct drvmgr *mgr = &drvmgr; + struct drvmgr *mgr = &drvmgr; - /* All drivers must have been registered before start of init, + /* All drivers must have been registered before start of init, * because the manager does not scan all existing devices to find * suitable hardware for this driver, and it is not protected with * a lock therefore. */ - if (mgr->level > 0) - return -1; + if ( mgr->level > 0 ) { + return -1; + } - drv->obj_type = DRVMGR_OBJ_DRV; + drv->obj_type = DRVMGR_OBJ_DRV; - /* Put driver into list of registered drivers */ - drvmgr_list_add_head(&mgr->drivers, drv); + /* Put driver into list of registered drivers */ + drvmgr_list_add_head( &mgr->drivers, drv ); - /* TODO: we could scan for devices that this new driver has support + /* TODO: we could scan for devices that this new driver has support * for. However, at this stage we assume that all drivers are * registered before devices are registered. * @@ -385,7 +387,7 @@ int drvmgr_drv_register(struct drvmgr_drv *drv) * either. */ - return 0; + return 0; } /* Insert a device into a driver's device list and assign a driver minor number @@ -395,32 +397,33 @@ int drvmgr_drv_register(struct drvmgr_drv *drv) * the minor number is found by looking for a gap or at the end. */ static void drvmgr_insert_dev_into_drv( - struct drvmgr_drv *drv, - struct drvmgr_dev *dev) + struct drvmgr_drv *drv, + struct drvmgr_dev *dev +) { - struct drvmgr_dev *curr, **pprevnext; - int minor; + struct drvmgr_dev *curr, **pprevnext; + int minor; - minor = 0; - pprevnext = &drv->dev; - curr = drv->dev; + minor = 0; + pprevnext = &drv->dev; + curr = drv->dev; - while (curr) { - if (minor < curr->minor_drv) { - /* Found a gap. Insert new device between prev + while ( curr ) { + if ( minor < curr->minor_drv ) { + /* Found a gap. Insert new device between prev * and curr. */ - break; - } - minor++; - pprevnext = &curr->next_in_drv; - curr = curr->next_in_drv; - } - dev->next_in_drv = curr; - *pprevnext = dev; + break; + } + minor++; + pprevnext = &curr->next_in_drv; + curr = curr->next_in_drv; + } + dev->next_in_drv = curr; + *pprevnext = dev; - /* Set minor */ - dev->minor_drv = minor; - drv->dev_cnt++; + /* Set minor */ + dev->minor_drv = minor; + drv->dev_cnt++; } /* Insert a device into a bus device list and assign a bus minor number to the @@ -432,102 +435,109 @@ static void drvmgr_insert_dev_into_drv( * The minor number is found by looking for a gap or at the end. */ static void drvmgr_insert_dev_into_bus( - struct drvmgr_bus *bus, - struct drvmgr_dev *dev) + struct drvmgr_bus *bus, + struct drvmgr_dev *dev +) { - struct drvmgr_dev *curr, **pprevnext; - int minor; + struct drvmgr_dev *curr, **pprevnext; + int minor; - minor = 0; - pprevnext = &bus->children; - curr = bus->children; + minor = 0; + pprevnext = &bus->children; + curr = bus->children; - while (curr) { - if (dev->drv && (dev->drv == curr->drv)) { - if (minor < curr->minor_bus) { - /* Found a gap. Insert new device between prev + while ( curr ) { + if ( dev->drv && ( dev->drv == curr->drv ) ) { + if ( minor < curr->minor_bus ) { + /* Found a gap. Insert new device between prev * and curr. */ - break; - } - minor++; - } - pprevnext = &curr->next_in_bus; - curr = curr->next_in_bus; - } - dev->next_in_bus = curr; - *pprevnext = dev; + break; + } + minor++; + } + pprevnext = &curr->next_in_bus; + curr = curr->next_in_bus; + } + dev->next_in_bus = curr; + *pprevnext = dev; - /* Set minor. Devices without driver are given -1 */ - if (dev->drv == NULL) - minor = -1; - dev->minor_bus = minor; - bus->dev_cnt++; + /* Set minor. Devices without driver are given -1 */ + if ( dev->drv == NULL ) { + minor = -1; + } + dev->minor_bus = minor; + bus->dev_cnt++; } /* Try to find a driver for a device (unite a device with driver). * a device with a driver */ -static struct drvmgr_drv *drvmgr_dev_find_drv( - struct drvmgr_dev *dev) +static struct drvmgr_drv *drvmgr_dev_find_drv( struct drvmgr_dev *dev ) { - struct drvmgr *mgr = &drvmgr; - struct drvmgr_drv *drv; + struct drvmgr *mgr = &drvmgr; + struct drvmgr_drv *drv; - /* NOTE: No locking is needed here since Driver list is supposed to be + /* NOTE: No locking is needed here since Driver list is supposed to be * initialized once during startup, we treat it as a static * read-only list */ - /* Try to find a driver that can handle this device */ - for (drv = DRV_LIST_HEAD(&mgr->drivers); drv; drv = drv->next) - if (dev->parent->ops->unite(drv, dev) == 1) - break; + /* Try to find a driver that can handle this device */ + for ( drv = DRV_LIST_HEAD( &mgr->drivers ); drv; drv = drv->next ) { + if ( dev->parent->ops->unite( drv, dev ) == 1 ) { + break; + } + } - return drv; + return drv; } /* Register a device */ -int drvmgr_dev_register(struct drvmgr_dev *dev) +int drvmgr_dev_register( struct drvmgr_dev *dev ) { - struct drvmgr *mgr = &drvmgr; - struct drvmgr_drv *drv; - struct drvmgr_bus *bus = dev->parent; - struct drvmgr_key *keys; - struct drvmgr_list *init_list = &mgr->devices_inactive; + struct drvmgr *mgr = &drvmgr; + struct drvmgr_drv *drv; + struct drvmgr_bus *bus = dev->parent; + struct drvmgr_key *keys; + struct drvmgr_list *init_list = &mgr->devices_inactive; - DBG("DEV_REG: %s at bus \"%s\"\n", dev->name, - bus && bus->dev && bus->dev->name ? bus->dev->name : "UNKNOWN"); + DBG( + "DEV_REG: %s at bus \"%s\"\n", + dev->name, + bus && bus->dev && bus->dev->name ? bus->dev->name : "UNKNOWN" + ); - /* Custom driver assocation? */ - if (dev->drv) { - drv = dev->drv; - DBG("CUSTOM ASSOCIATION (%s to %s)\n", dev->name, drv->name); - } else { - /* Try to find a driver that can handle this device */ - dev->drv = drv = drvmgr_dev_find_drv(dev); - } + /* Custom driver assocation? */ + if ( dev->drv ) { + drv = dev->drv; + DBG( "CUSTOM ASSOCIATION (%s to %s)\n", dev->name, drv->name ); + } else { + /* Try to find a driver that can handle this device */ + dev->drv = drv = drvmgr_dev_find_drv( dev ); + } - DRVMGR_LOCK_WRITE(); + DRVMGR_LOCK_WRITE(); - /* Assign Bus Minor number and put into bus device list + /* Assign Bus Minor number and put into bus device list * unless root device. */ - if (bus) - drvmgr_insert_dev_into_bus(bus, dev); + if ( bus ) { + drvmgr_insert_dev_into_bus( bus, dev ); + } - if (!drv) { - /* No driver found that can handle this device, put into + if ( !drv ) { + /* No driver found that can handle this device, put into * inactive list */ - dev->minor_drv = -1; - dev->state |= DEV_STATE_LIST_INACTIVE; - } else { - /* United device with driver. + dev->minor_drv = -1; + dev->state |= DEV_STATE_LIST_INACTIVE; + } else { + /* United device with driver. * Put the device on the registered device list */ - dev->state |= DEV_STATE_UNITED; + dev->state |= DEV_STATE_UNITED; - /* Check if user want to skip this core. This is not a + /* Check if user want to skip this core. This is not a * normal request, however in a multi-processor system * the two(or more) RTEMS instances must not use the same * devices in a system, not reporting a device to @@ -540,123 +550,126 @@ int drvmgr_dev_register(struct drvmgr_dev *dev) * device the user can simply define a resource entry * for a certain device but set the keys field to NULL. */ - if (drvmgr_keys_get(dev, &keys) == 0 && keys == NULL) { - /* Found Driver resource entry point + if ( drvmgr_keys_get( dev, &keys ) == 0 && keys == NULL ) { + /* Found Driver resource entry point * for this device, it was NULL, this * indicates to skip the core. * * We put it into the inactive list * marking it as ignored. */ - dev->state |= DEV_STATE_IGNORED; - } else { - /* Assign Driver Minor number and put into driver's + dev->state |= DEV_STATE_IGNORED; + } else { + /* Assign Driver Minor number and put into driver's * device list */ - drvmgr_insert_dev_into_drv(drv, dev); + drvmgr_insert_dev_into_drv( drv, dev ); - /* Just register device, it will be initialized + /* Just register device, it will be initialized * later together with bus. * * At the end of the list (breadth first search) */ - init_list = &mgr->devices[0]; + init_list = &mgr->devices[ 0 ]; - DBG("Registered %s (DRV: %s) on %s\n", - dev->name, drv->name, - bus ? bus->dev->name : "NO PARENT"); - } - } + DBG( + "Registered %s (DRV: %s) on %s\n", + dev->name, + drv->name, + bus ? bus->dev->name : "NO PARENT" + ); + } + } - drvmgr_list_add_tail(init_list, dev); + drvmgr_list_add_tail( init_list, dev ); - DRVMGR_UNLOCK(); + DRVMGR_UNLOCK(); - /* Trigger Device initialization if not root device and + /* Trigger Device initialization if not root device and * has a driver */ - if (bus && dev->drv) - drvmgr_init_update(); + if ( bus && dev->drv ) { + drvmgr_init_update(); + } - return 0; + return 0; } /* Register a bus */ -int drvmgr_bus_register(struct drvmgr_bus *bus) +int drvmgr_bus_register( struct drvmgr_bus *bus ) { - struct drvmgr *mgr = &drvmgr; - struct drvmgr_bus *bus_up; + struct drvmgr *mgr = &drvmgr; + struct drvmgr_bus *bus_up; - /* Get bus architecture depth - the distance from root bus */ - bus->depth = 0; - bus_up = bus->dev->parent; - while (bus_up) { - bus->depth++; - bus_up = bus_up->dev->parent; - } + /* Get bus architecture depth - the distance from root bus */ + bus->depth = 0; + bus_up = bus->dev->parent; + while ( bus_up ) { + bus->depth++; + bus_up = bus_up->dev->parent; + } - DRVMGR_LOCK_WRITE(); + DRVMGR_LOCK_WRITE(); - /* Put driver into list of found buses */ - drvmgr_list_add_tail(&mgr->buses[0], bus); + /* Put driver into list of found buses */ + drvmgr_list_add_tail( &mgr->buses[ 0 ], bus ); - DRVMGR_UNLOCK(); + DRVMGR_UNLOCK(); - /* Take bus into level1 and so on */ - drvmgr_init_update(); + /* Take bus into level1 and so on */ + drvmgr_init_update(); - return 0; + return 0; } /* Allocate memory for a Device structure */ -int drvmgr_alloc_dev(struct drvmgr_dev **pdev, int extra) +int drvmgr_alloc_dev( struct drvmgr_dev **pdev, int extra ) { - struct drvmgr_dev *dev; - int size; + struct drvmgr_dev *dev; + int size; - /* The extra memory "service" is aligned to 4 bytes boundary. */ - size = ((sizeof(struct drvmgr_dev) + 3) & ~0x3) + extra; - dev = (struct drvmgr_dev *)calloc(size, 1); - if (!dev) { - /* Failed to allocate device structure - critical error */ - rtems_fatal_error_occurred(RTEMS_NO_MEMORY); - } - *pdev = dev; - dev->obj_type = DRVMGR_OBJ_DEV; + /* The extra memory "service" is aligned to 4 bytes boundary. */ + size = ( ( sizeof( struct drvmgr_dev ) + 3 ) & ~0x3 ) + extra; + dev = (struct drvmgr_dev *) calloc( size, 1 ); + if ( !dev ) { + /* Failed to allocate device structure - critical error */ + rtems_fatal_error_occurred( RTEMS_NO_MEMORY ); + } + *pdev = dev; + dev->obj_type = DRVMGR_OBJ_DEV; - return 0; + return 0; } /* Allocate memory for a Bus structure */ -int drvmgr_alloc_bus(struct drvmgr_bus **pbus, int extra) +int drvmgr_alloc_bus( struct drvmgr_bus **pbus, int extra ) { - struct drvmgr_bus *bus; - int size; + struct drvmgr_bus *bus; + int size; - /* The extra memory "service" is aligned to 4 bytes boundary. */ - size = ((sizeof(struct drvmgr_bus) + 3) & ~0x3) + extra; - bus = (struct drvmgr_bus *)calloc(size, 1); - if (!bus) { - /* Failed to allocate device structure - critical error */ - rtems_fatal_error_occurred(RTEMS_NO_MEMORY); - } - *pbus = bus; - bus->obj_type = DRVMGR_OBJ_BUS; + /* The extra memory "service" is aligned to 4 bytes boundary. */ + size = ( ( sizeof( struct drvmgr_bus ) + 3 ) & ~0x3 ) + extra; + bus = (struct drvmgr_bus *) calloc( size, 1 ); + if ( !bus ) { + /* Failed to allocate device structure - critical error */ + rtems_fatal_error_occurred( RTEMS_NO_MEMORY ); + } + *pbus = bus; + bus->obj_type = DRVMGR_OBJ_BUS; - return 0; + return 0; } /* Add driver resources to a bus instance */ -void drvmgr_bus_res_add(struct drvmgr_bus *bus, - struct drvmgr_bus_res *bres) +void drvmgr_bus_res_add( struct drvmgr_bus *bus, struct drvmgr_bus_res *bres ) { - /* insert first in bus resource list. Locking isn't needed since + /* insert first in bus resource list. Locking isn't needed since * resources can only be added before resource requests are made. * When bus has been registered resources are considered a read-only * tree. */ - bres->next = bus->reslist; - bus->reslist = bres; + bres->next = bus->reslist; + bus->reslist = bres; } #ifdef RTEMS_DRVMGR_STARTUP @@ -684,9 +697,9 @@ RTEMS_SYSINIT_ITEM( * - Install console driver and debug printk() * - Install extra memory. */ -static void _DRV_Manager_init_level_1(void) +static void _DRV_Manager_init_level_1( void ) { - _DRV_Manager_init_level(1); + _DRV_Manager_init_level( 1 ); } RTEMS_SYSINIT_ITEM( @@ -703,9 +716,9 @@ RTEMS_SYSINIT_ITEM( * This is typically where drivers are initialized * for the first time. */ -static void _DRV_Manager_init_level_2(void) +static void _DRV_Manager_init_level_2( void ) { - _DRV_Manager_init_level(2); + _DRV_Manager_init_level( 2 ); } RTEMS_SYSINIT_ITEM( @@ -720,9 +733,9 @@ RTEMS_SYSINIT_ITEM( * for the second time, they may depend on other drivers * API inited in level 2 */ -static void _DRV_Manager_init_level_3(void) +static void _DRV_Manager_init_level_3( void ) { - _DRV_Manager_init_level(3); + _DRV_Manager_init_level( 3 ); } RTEMS_SYSINIT_ITEM( @@ -734,9 +747,9 @@ RTEMS_SYSINIT_ITEM( /* Init Drivers to Level 4, * Init drivers that depend on services initialized in Level 3 */ -static void _DRV_Manager_init_level_4(void) +static void _DRV_Manager_init_level_4( void ) { - _DRV_Manager_init_level(4); + _DRV_Manager_init_level( 4 ); } RTEMS_SYSINIT_ITEM( diff --git a/cpukit/libdrvmgr/drvmgr_by_id.c b/cpukit/libdrvmgr/drvmgr_by_id.c index c3c2a9b1b2..26870a1bfd 100644 --- a/cpukit/libdrvmgr/drvmgr_by_id.c +++ b/cpukit/libdrvmgr/drvmgr_by_id.c @@ -30,22 +30,23 @@ #include "drvmgr_internal.h" /* Get driver from driver name */ -struct drvmgr_drv *drvmgr_drv_by_id(uint64_t id) +struct drvmgr_drv *drvmgr_drv_by_id( uint64_t id ) { - struct drvmgr *mgr = &drvmgr; - struct drvmgr_drv *drv = NULL; + struct drvmgr *mgr = &drvmgr; + struct drvmgr_drv *drv = NULL; - /* NOTE: No locking is needed here since Driver list is supposed to be + /* NOTE: No locking is needed here since Driver list is supposed to be * initialized once during startup, we treat it as a static * read-only list */ - drv = DRV_LIST_HEAD(&mgr->drivers); - while (drv) { - if (drv->drv_id == id) - break; - drv = drv->next; - } + drv = DRV_LIST_HEAD( &mgr->drivers ); + while ( drv ) { + if ( drv->drv_id == id ) { + break; + } + drv = drv->next; + } - return drv; + return drv; } diff --git a/cpukit/libdrvmgr/drvmgr_by_name.c b/cpukit/libdrvmgr/drvmgr_by_name.c index dfb854abec..63adf2db5e 100644 --- a/cpukit/libdrvmgr/drvmgr_by_name.c +++ b/cpukit/libdrvmgr/drvmgr_by_name.c @@ -31,25 +31,27 @@ #include "drvmgr_internal.h" /* Get driver from driver name */ -struct drvmgr_drv *drvmgr_drv_by_name(const char *name) +struct drvmgr_drv *drvmgr_drv_by_name( const char *name ) { - struct drvmgr *mgr = &drvmgr; - struct drvmgr_drv *drv = NULL; + struct drvmgr *mgr = &drvmgr; + struct drvmgr_drv *drv = NULL; - if (!name) - return NULL; + if ( !name ) { + return NULL; + } - /* NOTE: No locking is needed here since Driver list is supposed to be + /* NOTE: No locking is needed here since Driver list is supposed to be * initialized once during startup, we treat it as a static * read-only list */ - drv = DRV_LIST_HEAD(&mgr->drivers); - while (drv) { - if (drv->name && (strcmp(drv->name, name) == 0)) - break; - drv = drv->next; - } + drv = DRV_LIST_HEAD( &mgr->drivers ); + while ( drv ) { + if ( drv->name && ( strcmp( drv->name, name ) == 0 ) ) { + break; + } + drv = drv->next; + } - return drv; + return drv; } diff --git a/cpukit/libdrvmgr/drvmgr_dev_by_name.c b/cpukit/libdrvmgr/drvmgr_dev_by_name.c index 13c7c95992..efcb95d18d 100644 --- a/cpukit/libdrvmgr/drvmgr_dev_by_name.c +++ b/cpukit/libdrvmgr/drvmgr_dev_by_name.c @@ -31,22 +31,25 @@ #include #include "drvmgr_internal.h" -static intptr_t dev_name_compare(struct drvmgr_dev *dev, void *arg) +static intptr_t dev_name_compare( struct drvmgr_dev *dev, void *arg ) { - const char *name = arg; + const char *name = arg; - if (dev->name && (strcmp(dev->name, name) == 0)) - return (intptr_t)dev; - else - return 0; + if ( dev->name && ( strcmp( dev->name, name ) == 0 ) ) { + return (intptr_t) dev; + } else { + return 0; + } } /* Get device by device name or bus name */ -struct drvmgr_dev *drvmgr_dev_by_name(const char *name) +struct drvmgr_dev *drvmgr_dev_by_name( const char *name ) { - if (!name) - return NULL; + if ( !name ) { + return NULL; + } - return (struct drvmgr_dev *) - drvmgr_for_each_dev(dev_name_compare, (void *)name, 0); + return ( + struct drvmgr_dev * + ) drvmgr_for_each_dev( dev_name_compare, (void *) name, 0 ); } diff --git a/cpukit/libdrvmgr/drvmgr_drvinf.c b/cpukit/libdrvmgr/drvmgr_drvinf.c index 11ba1eabb7..67c3f65bba 100644 --- a/cpukit/libdrvmgr/drvmgr_drvinf.c +++ b/cpukit/libdrvmgr/drvmgr_drvinf.c @@ -44,136 +44,152 @@ * that was assigned to it */ int drvmgr_get_dev( - struct drvmgr_drv *drv, - int minor, - struct drvmgr_dev **pdev) + struct drvmgr_drv *drv, + int minor, + struct drvmgr_dev **pdev +) { - struct drvmgr_dev *dev; - if (!drv) - return -1; + struct drvmgr_dev *dev; + if ( !drv ) { + return -1; + } - DRVMGR_LOCK_READ(); - dev = drv->dev; - while (dev) { - if (dev->minor_drv == minor) - break; - dev = dev->next_in_drv; - } - DRVMGR_UNLOCK(); - if (!dev) - return -1; - if (pdev) - *pdev = dev; - return 0; + DRVMGR_LOCK_READ(); + dev = drv->dev; + while ( dev ) { + if ( dev->minor_drv == minor ) { + break; + } + dev = dev->next_in_drv; + } + DRVMGR_UNLOCK(); + if ( !dev ) { + return -1; + } + if ( pdev ) { + *pdev = dev; + } + return 0; } /* Get Bus frequency in HZ from bus driver */ int drvmgr_freq_get( - struct drvmgr_dev *dev, - int options, - unsigned int *freq_hz) + struct drvmgr_dev *dev, + int options, + unsigned int *freq_hz +) { - if (!dev || !dev->parent || !dev->parent->ops->get_freq) - return -1; + if ( !dev || !dev->parent || !dev->parent->ops->get_freq ) { + return -1; + } - return dev->parent->ops->get_freq(dev, options, freq_hz); + return dev->parent->ops->get_freq( dev, options, freq_hz ); } /* Get driver prefix */ -int drvmgr_get_dev_prefix(struct drvmgr_dev *dev, char *dev_prefix) +int drvmgr_get_dev_prefix( struct drvmgr_dev *dev, char *dev_prefix ) { - struct drvmgr_bus_params params; - if (!dev || !dev->parent || !dev->parent->ops->get_params) - return -1; + struct drvmgr_bus_params params; + if ( !dev || !dev->parent || !dev->parent->ops->get_params ) { + return -1; + } - dev->parent->ops->get_params(dev, ¶ms); - if (!params.dev_prefix) - return -1; - if (dev_prefix) - strcpy(dev_prefix, params.dev_prefix); - return 0; + dev->parent->ops->get_params( dev, ¶ms ); + if ( !params.dev_prefix ) { + return -1; + } + if ( dev_prefix ) { + strcpy( dev_prefix, params.dev_prefix ); + } + return 0; } /* Register an interrupt */ int drvmgr_interrupt_register( - struct drvmgr_dev *dev, - int index, - const char *info, - drvmgr_isr isr, - void *arg) + struct drvmgr_dev *dev, + int index, + const char *info, + drvmgr_isr isr, + void *arg +) { - if (!dev || !dev->parent || !dev->parent->ops->int_register) - return -1; + if ( !dev || !dev->parent || !dev->parent->ops->int_register ) { + return -1; + } - if (!isr) - return -1; + if ( !isr ) { + return -1; + } - return dev->parent->ops->int_register(dev, index, info, isr, arg); + return dev->parent->ops->int_register( dev, index, info, isr, arg ); } /* Unregister an interrupt */ int drvmgr_interrupt_unregister( - struct drvmgr_dev *dev, - int index, - drvmgr_isr isr, - void *arg) + struct drvmgr_dev *dev, + int index, + drvmgr_isr isr, + void *arg +) { - if (!dev || !dev->parent || !dev->parent->ops->int_unregister) - return -1; + if ( !dev || !dev->parent || !dev->parent->ops->int_unregister ) { + return -1; + } - if (!isr) - return -1; + if ( !isr ) { + return -1; + } - return dev->parent->ops->int_unregister(dev, index, isr, arg); + return dev->parent->ops->int_unregister( dev, index, isr, arg ); } -int drvmgr_interrupt_clear( - struct drvmgr_dev *dev, - int index) +int drvmgr_interrupt_clear( struct drvmgr_dev *dev, int index ) { - if (!dev || !dev->parent || !dev->parent->ops->int_clear) - return -1; + if ( !dev || !dev->parent || !dev->parent->ops->int_clear ) { + return -1; + } - return dev->parent->ops->int_clear(dev, index); + return dev->parent->ops->int_clear( dev, index ); } -int drvmgr_interrupt_unmask( - struct drvmgr_dev *dev, - int index) +int drvmgr_interrupt_unmask( struct drvmgr_dev *dev, int index ) { - if (!dev || !dev->parent || !dev->parent->ops->int_unmask) - return -1; + if ( !dev || !dev->parent || !dev->parent->ops->int_unmask ) { + return -1; + } - return dev->parent->ops->int_unmask(dev, index); + return dev->parent->ops->int_unmask( dev, index ); } -int drvmgr_interrupt_mask( - struct drvmgr_dev *dev, - int index) +int drvmgr_interrupt_mask( struct drvmgr_dev *dev, int index ) { - if (!dev || !dev->parent || !dev->parent->ops->int_mask) - return -1; + if ( !dev || !dev->parent || !dev->parent->ops->int_mask ) { + return -1; + } - return dev->parent->ops->int_mask(dev, index); + return dev->parent->ops->int_mask( dev, index ); } #ifdef RTEMS_SMP int drvmgr_interrupt_set_affinity( - struct drvmgr_dev *dev, - int index, - const Processor_mask *cpus) + struct drvmgr_dev *dev, + int index, + const Processor_mask *cpus +) { - if (!dev || !dev->parent || !dev->parent->ops->int_set_affinity) - return -1; + if ( !dev || !dev->parent || !dev->parent->ops->int_set_affinity ) { + return -1; + } - return dev->parent->ops->int_set_affinity(dev, index, cpus); + return dev->parent->ops->int_set_affinity( dev, index, cpus ); } #endif -int drvmgr_on_rootbus(struct drvmgr_dev *dev) +int drvmgr_on_rootbus( struct drvmgr_dev *dev ) { - if (dev->parent && dev->parent->dev && dev->parent->dev->parent) - return 0; - else - return 1; + if ( dev->parent && dev->parent->dev && dev->parent->dev->parent ) { + return 0; + } else { + return 1; + } } diff --git a/cpukit/libdrvmgr/drvmgr_for_each_dev.c b/cpukit/libdrvmgr/drvmgr_for_each_dev.c index 1b27ce856b..ddccfe18db 100644 --- a/cpukit/libdrvmgr/drvmgr_for_each_dev.c +++ b/cpukit/libdrvmgr/drvmgr_for_each_dev.c @@ -33,90 +33,96 @@ /* Traverse device tree breadth-first. Supports up to 31 buses */ static intptr_t drvmgr_for_each_dev_breadth( - intptr_t (*func)(struct drvmgr_dev *dev, void *arg), - void *arg - ) + intptr_t ( *func )( struct drvmgr_dev *dev, void *arg ), + void *arg +) { - int ret = 0, i, pos; - struct drvmgr_bus *bus, *buses[32]; - struct drvmgr_dev *dev; + int ret = 0, i, pos; + struct drvmgr_bus *bus, *buses[ 32 ]; + struct drvmgr_dev *dev; - pos = 0; - memset(&buses[0], 0, sizeof(buses)); - buses[pos++] = drvmgr.root_dev.bus; /* Get root bus */ + pos = 0; + memset( &buses[ 0 ], 0, sizeof( buses ) ); + buses[ pos++ ] = drvmgr.root_dev.bus; /* Get root bus */ - for (i = 0, bus = buses[0]; buses[i]; i++, bus = buses[i]) { - dev = bus->children; - while (dev) { - ret = func(dev, arg); - if (ret != 0) - break; - if (dev->bus && pos < 31) - buses[pos++] = dev->bus; + for ( i = 0, bus = buses[ 0 ]; buses[ i ]; i++, bus = buses[ i ] ) { + dev = bus->children; + while ( dev ) { + ret = func( dev, arg ); + if ( ret != 0 ) { + break; + } + if ( dev->bus && pos < 31 ) { + buses[ pos++ ] = dev->bus; + } - dev = dev->next_in_bus; - } - } + dev = dev->next_in_bus; + } + } - return ret; + return ret; } /* Traverse device tree depth-first. */ static intptr_t drvmgr_for_each_dev_depth( - intptr_t (*func)(struct drvmgr_dev *dev, void *arg), - void *arg - ) + intptr_t ( *func )( struct drvmgr_dev *dev, void *arg ), + void *arg +) { - int ret = 0; - struct drvmgr_dev *dev; + int ret = 0; + struct drvmgr_dev *dev; - /* Get first device */ - dev = drvmgr.root_dev.bus->children; + /* Get first device */ + dev = drvmgr.root_dev.bus->children; - while (dev) { - ret = func(dev, arg); - if (ret != 0) - break; - if (dev->bus && dev->bus->children) { - dev = dev->bus->children; - } else { -next_dev: - if (dev->next_in_bus == NULL) { - /* Step up one level... back to parent bus */ - dev = dev->parent->dev; - if (dev == &drvmgr.root_dev) - break; - goto next_dev; - } else { - dev = dev->next_in_bus; - } - } - } + while ( dev ) { + ret = func( dev, arg ); + if ( ret != 0 ) { + break; + } + if ( dev->bus && dev->bus->children ) { + dev = dev->bus->children; + } else { + next_dev: + if ( dev->next_in_bus == NULL ) { + /* Step up one level... back to parent bus */ + dev = dev->parent->dev; + if ( dev == &drvmgr.root_dev ) { + break; + } + goto next_dev; + } else { + dev = dev->next_in_bus; + } + } + } - return ret; + return ret; } /* Traverse device tree depth-first or breadth-first */ intptr_t drvmgr_for_each_dev( - intptr_t (*func)(struct drvmgr_dev *dev, void *arg), - void *arg, - int options - ) + intptr_t ( *func )( struct drvmgr_dev *dev, void *arg ), + void *arg, + int options +) { - intptr_t ret; + intptr_t ret; - DRVMGR_LOCK_READ(); + DRVMGR_LOCK_READ(); - /* Get Root Device */ - if (drvmgr.root_dev.bus->children != NULL) { - if (options & DRVMGR_FED_BF) - ret = drvmgr_for_each_dev_breadth(func, arg); - else - ret = drvmgr_for_each_dev_depth(func, arg); - } else - ret = 0; + /* Get Root Device */ + if ( drvmgr.root_dev.bus->children != NULL ) { + if ( options & DRVMGR_FED_BF ) { + ret = drvmgr_for_each_dev_breadth( func, arg ); + } else { + ret = drvmgr_for_each_dev_depth( func, arg ); + } + } else { + ret = 0; + } - DRVMGR_UNLOCK(); + DRVMGR_UNLOCK(); - return ret; + return ret; } diff --git a/cpukit/libdrvmgr/drvmgr_for_each_list_dev.c b/cpukit/libdrvmgr/drvmgr_for_each_list_dev.c index 1ef6a47424..4d86b0abb2 100644 --- a/cpukit/libdrvmgr/drvmgr_for_each_list_dev.c +++ b/cpukit/libdrvmgr/drvmgr_for_each_list_dev.c @@ -31,32 +31,37 @@ #include "drvmgr_internal.h" int drvmgr_for_each_listdev( - struct drvmgr_list *devlist, - unsigned int state_set_mask, - unsigned int state_clr_mask, - int (*func)(struct drvmgr_dev *dev, void *arg), - void *arg - ) + struct drvmgr_list *devlist, + unsigned int state_set_mask, + unsigned int state_clr_mask, + int ( *func )( struct drvmgr_dev *dev, void *arg ), + void *arg +) { - struct drvmgr_dev *dev; - int ret = 0; + struct drvmgr_dev *dev; + int ret = 0; - DRVMGR_LOCK_READ(); + DRVMGR_LOCK_READ(); - /* Get First Device */ - dev = DEV_LIST_HEAD(devlist); - while (dev) { - if (((state_set_mask != 0) && ((dev->state & state_set_mask) == state_set_mask)) || - ((state_clr_mask != 0) && ((dev->state & state_clr_mask) == 0)) || - ((state_set_mask == 0) && (state_clr_mask == 0))) { - ret = func(dev, arg); - if (ret != 0) - break; - } - dev = dev->next; - } + /* Get First Device */ + dev = DEV_LIST_HEAD( devlist ); + while ( dev ) { + if ( + ( ( state_set_mask != 0 ) && + ( ( dev->state & state_set_mask ) == state_set_mask ) ) || + ( ( state_clr_mask != 0 ) && + ( ( dev->state & state_clr_mask ) == 0 ) ) || + ( ( state_set_mask == 0 ) && ( state_clr_mask == 0 ) ) + ) { + ret = func( dev, arg ); + if ( ret != 0 ) { + break; + } + } + dev = dev->next; + } - DRVMGR_UNLOCK(); + DRVMGR_UNLOCK(); - return ret; + return ret; } diff --git a/cpukit/libdrvmgr/drvmgr_func.c b/cpukit/libdrvmgr/drvmgr_func.c index aea52e1e8d..45e3bec20c 100644 --- a/cpukit/libdrvmgr/drvmgr_func.c +++ b/cpukit/libdrvmgr/drvmgr_func.c @@ -29,32 +29,35 @@ #include /* Get Function from Function ID */ -int drvmgr_func_get(void *obj, int funcid, void **func) +int drvmgr_func_get( void *obj, int funcid, void **func ) { - int objtype; - struct drvmgr_func *f; + int objtype; + struct drvmgr_func *f; - if (!obj) - return DRVMGR_FAIL; - objtype = *(int *)obj; + if ( !obj ) { + return DRVMGR_FAIL; + } + objtype = *(int *) obj; - if (objtype == DRVMGR_OBJ_BUS) - f = ((struct drvmgr_bus *)obj)->funcs; - else if (objtype == DRVMGR_OBJ_DRV) - f = ((struct drvmgr_drv *)obj)->funcs; - else - return DRVMGR_FAIL; + if ( objtype == DRVMGR_OBJ_BUS ) { + f = ( (struct drvmgr_bus *) obj )->funcs; + } else if ( objtype == DRVMGR_OBJ_DRV ) { + f = ( (struct drvmgr_drv *) obj )->funcs; + } else { + return DRVMGR_FAIL; + } - if (f == NULL) - return DRVMGR_FAIL; + if ( f == NULL ) { + return DRVMGR_FAIL; + } - while (f->funcid != DRVMGR_FUNCID_NONE) { - if (f->funcid == funcid) { - *func = f->func; - return DRVMGR_OK; - } - f++; - } + while ( f->funcid != DRVMGR_FUNCID_NONE ) { + if ( f->funcid == funcid ) { + *func = f->func; + return DRVMGR_OK; + } + f++; + } - return DRVMGR_FAIL; + return DRVMGR_FAIL; } diff --git a/cpukit/libdrvmgr/drvmgr_func_call.c b/cpukit/libdrvmgr/drvmgr_func_call.c index 22c892dca5..e1a427b48c 100644 --- a/cpukit/libdrvmgr/drvmgr_func_call.c +++ b/cpukit/libdrvmgr/drvmgr_func_call.c @@ -29,11 +29,19 @@ #include /* Lookup function from function ID and call it using given arguments */ -int drvmgr_func_call(void *obj, int funcid, void *a, void *b, void *c, void *d) +int drvmgr_func_call( + void *obj, + int funcid, + void *a, + void *b, + void *c, + void *d +) { - int (*func)(void *arg1, void *arg2, void *arg3, void *arg4) = NULL; + int ( *func )( void *arg1, void *arg2, void *arg3, void *arg4 ) = NULL; - if (drvmgr_func_get(obj, funcid, (void *)&func) != DRVMGR_OK) - return DRVMGR_FAIL; - return func(a, b, c, d); + if ( drvmgr_func_get( obj, funcid, (void *) &func ) != DRVMGR_OK ) { + return DRVMGR_FAIL; + } + return func( a, b, c, d ); } diff --git a/cpukit/libdrvmgr/drvmgr_init.c b/cpukit/libdrvmgr/drvmgr_init.c index b7d02e5ab8..425ca5088a 100644 --- a/cpukit/libdrvmgr/drvmgr_init.c +++ b/cpukit/libdrvmgr/drvmgr_init.c @@ -31,14 +31,15 @@ /* Init driver manager - all in one go. Typically called from Init task when * user wants to initilize driver manager after startup, otherwise not used. */ -int drvmgr_init(void) +int drvmgr_init( void ) { - int level; + int level; - _DRV_Manager_initialization(); + _DRV_Manager_initialization(); - for (level = 1; level <= DRVMGR_LEVEL_MAX; level++) - _DRV_Manager_init_level(level); + for ( level = 1; level <= DRVMGR_LEVEL_MAX; level++ ) { + _DRV_Manager_init_level( level ); + } - return 0; + return 0; } diff --git a/cpukit/libdrvmgr/drvmgr_internal.h b/cpukit/libdrvmgr/drvmgr_internal.h index 94d46ab552..9db65d79ff 100644 --- a/cpukit/libdrvmgr/drvmgr_internal.h +++ b/cpukit/libdrvmgr/drvmgr_internal.h @@ -32,56 +32,56 @@ * internally by Driver Manager routines. */ struct drvmgr { - int level; - int initializing_objs; + int level; + int initializing_objs; - /* Device tree Lock */ - API_Mutex_Control lock; + /* Device tree Lock */ + API_Mutex_Control lock; - /* The first device - The root device and it's driver */ - struct drvmgr_drv *root_drv; - struct drvmgr_dev root_dev; + /* The first device - The root device and it's driver */ + struct drvmgr_drv *root_drv; + struct drvmgr_dev root_dev; - /*!< Linked list of all registered drivers */ - struct drvmgr_list drivers; + /*!< Linked list of all registered drivers */ + struct drvmgr_list drivers; - /* Buses that reached a certain initialization level. + /* Buses that reached a certain initialization level. * Lists by Level: * N=0 - Not intialized, just registered * N=1..MAX-1 - Reached init level N * N=MAX - Successfully initialized bus */ - struct drvmgr_list buses[DRVMGR_LEVEL_MAX+1]; - /* Buses failed to initialize or has been removed by not freed */ - struct drvmgr_list buses_inactive; + struct drvmgr_list buses[ DRVMGR_LEVEL_MAX + 1 ]; + /* Buses failed to initialize or has been removed by not freed */ + struct drvmgr_list buses_inactive; - /* Devices that reached a certain initialization level. + /* Devices that reached a certain initialization level. * Lists by Level: * N=0 - Not intialized, just registered * N=1..MAX-1 - Reached init level N * N=MAX - Successfully initialized device */ - struct drvmgr_list devices[DRVMGR_LEVEL_MAX+1]; - /*!< Devices failed to initialize, removed, ignored, no driver */ - struct drvmgr_list devices_inactive; + struct drvmgr_list devices[ DRVMGR_LEVEL_MAX + 1 ]; + /*!< Devices failed to initialize, removed, ignored, no driver */ + struct drvmgr_list devices_inactive; }; extern struct drvmgr drvmgr; -extern void _DRV_Manager_Lock(void); -extern void _DRV_Manager_Unlock(void); +extern void _DRV_Manager_Lock( void ); +extern void _DRV_Manager_Unlock( void ); /* The best solution is to implement the locking with a RW lock, however there * is no such API available. Care must be taken so that dead-lock isn't created * for example in recursive functions. */ -#if defined(DRVMGR_USE_LOCKS) && (DRVMGR_USE_LOCKS == 1) +#if defined( DRVMGR_USE_LOCKS ) && ( DRVMGR_USE_LOCKS == 1 ) #define DRVMGR_LOCK_WRITE() _DRV_Manager_Lock() - #define DRVMGR_LOCK_READ() _DRV_Manager_Lock() - #define DRVMGR_UNLOCK() _DRV_Manager_Unlock() + #define DRVMGR_LOCK_READ() _DRV_Manager_Lock() + #define DRVMGR_UNLOCK() _DRV_Manager_Unlock() #else /* no locking */ - #define DRVMGR_LOCK_WRITE() - #define DRVMGR_LOCK_READ() - #define DRVMGR_UNLOCK() + #define DRVMGR_LOCK_WRITE() + #define DRVMGR_LOCK_READ() + #define DRVMGR_UNLOCK() #endif diff --git a/cpukit/libdrvmgr/drvmgr_list.c b/cpukit/libdrvmgr/drvmgr_list.c index fc868d7b44..7e2004feec 100644 --- a/cpukit/libdrvmgr/drvmgr_list.c +++ b/cpukit/libdrvmgr/drvmgr_list.c @@ -31,55 +31,59 @@ /* LIST interface */ -void drvmgr_list_init(struct drvmgr_list *list, int offset) +void drvmgr_list_init( struct drvmgr_list *list, int offset ) { - list->head = list->tail = NULL; - list->ofs = offset; + list->head = list->tail = NULL; + list->ofs = offset; } -void drvmgr_list_empty(struct drvmgr_list *list) +void drvmgr_list_empty( struct drvmgr_list *list ) { - list->head = list->tail = NULL; + list->head = list->tail = NULL; } -void drvmgr_list_add_head(struct drvmgr_list *list, void *entry) +void drvmgr_list_add_head( struct drvmgr_list *list, void *entry ) { - LIST_FIELD(list, entry) = list->head; - if (list->head == NULL) - list->tail = entry; - list->head = entry; + LIST_FIELD( list, entry ) = list->head; + if ( list->head == NULL ) { + list->tail = entry; + } + list->head = entry; } -void drvmgr_list_add_tail(struct drvmgr_list *list, void *entry) +void drvmgr_list_add_tail( struct drvmgr_list *list, void *entry ) { - if (list->tail == NULL) - list->head = entry; - else - LIST_FIELD(list, list->tail) = entry; - LIST_FIELD(list, entry) = NULL; - list->tail = entry; + if ( list->tail == NULL ) { + list->head = entry; + } else { + LIST_FIELD( list, list->tail ) = entry; + } + LIST_FIELD( list, entry ) = NULL; + list->tail = entry; } -void drvmgr_list_remove_head(struct drvmgr_list *list) +void drvmgr_list_remove_head( struct drvmgr_list *list ) { - list->head = LIST_FIELD(list, list->head); - if (list->head == NULL) - list->tail = NULL; + list->head = LIST_FIELD( list, list->head ); + if ( list->head == NULL ) { + list->tail = NULL; + } } -void drvmgr_list_remove(struct drvmgr_list *list, void *entry) +void drvmgr_list_remove( struct drvmgr_list *list, void *entry ) { - void **prevptr = &list->head; - void *curr, *prev; + void **prevptr = &list->head; + void *curr, *prev; - prev = NULL; - curr = list->head; - while (curr != entry) { - prev = curr; - prevptr = &LIST_FIELD(list, curr); - curr = LIST_FIELD(list, curr); - } - *prevptr = LIST_FIELD(list, entry); - if (list->tail == entry) - list->tail = prev; + prev = NULL; + curr = list->head; + while ( curr != entry ) { + prev = curr; + prevptr = &LIST_FIELD( list, curr ); + curr = LIST_FIELD( list, curr ); + } + *prevptr = LIST_FIELD( list, entry ); + if ( list->tail == entry ) { + list->tail = prev; + } } diff --git a/cpukit/libdrvmgr/drvmgr_lock.c b/cpukit/libdrvmgr/drvmgr_lock.c index 38708a72a6..fb3ce760ce 100644 --- a/cpukit/libdrvmgr/drvmgr_lock.c +++ b/cpukit/libdrvmgr/drvmgr_lock.c @@ -37,7 +37,7 @@ void _DRV_Manager_Lock( void ) } } -void _DRV_Manager_Unlock(void) +void _DRV_Manager_Unlock( void ) { if ( !_System_state_Is_before_initialization( _System_state_Get() ) ) { _API_Mutex_Unlock( &drvmgr.lock ); diff --git a/cpukit/libdrvmgr/drvmgr_print.c b/cpukit/libdrvmgr/drvmgr_print.c index 6ec302134a..5250ad2188 100644 --- a/cpukit/libdrvmgr/drvmgr_print.c +++ b/cpukit/libdrvmgr/drvmgr_print.c @@ -40,433 +40,491 @@ #include #include "drvmgr_internal.h" -typedef void (*fun_ptr)(void); +typedef void ( *fun_ptr )( void ); -static int print_dev_found(struct drvmgr_dev *dev, void *arg) +static int print_dev_found( struct drvmgr_dev *dev, void *arg ) { - char **pparg = arg; + char **pparg = arg; - if (pparg && *pparg) { - printf(*pparg); - *pparg = NULL; - } + if ( pparg && *pparg ) { + printf( *pparg ); + *pparg = NULL; + } - printf(" DEV %p %s on bus %p\n", dev, - dev->name ? dev->name : "NO_NAME", dev->parent); + printf( + " DEV %p %s on bus %p\n", + dev, + dev->name ? dev->name : "NO_NAME", + dev->parent + ); - return 0; /* Continue to next device */ + return 0; /* Continue to next device */ } -void drvmgr_print_devs(unsigned int options) +void drvmgr_print_devs( unsigned int options ) { - struct drvmgr *mgr = &drvmgr; - char *parg; + struct drvmgr *mgr = &drvmgr; + char *parg; - /* Print Drivers */ - if (options & PRINT_DEVS_ASSIGNED) { - parg = " --- DEVICES ASSIGNED TO DRIVER ---\n"; - drvmgr_for_each_listdev(&mgr->devices[DRVMGR_LEVEL_MAX], - DEV_STATE_UNITED, 0, print_dev_found, &parg); - if (parg != NULL) - printf("\n NO DEVICES WERE ASSIGNED A DRIVER\n"); - } + /* Print Drivers */ + if ( options & PRINT_DEVS_ASSIGNED ) { + parg = " --- DEVICES ASSIGNED TO DRIVER ---\n"; + drvmgr_for_each_listdev( + &mgr->devices[ DRVMGR_LEVEL_MAX ], + DEV_STATE_UNITED, + 0, + print_dev_found, + &parg + ); + if ( parg != NULL ) { + printf( "\n NO DEVICES WERE ASSIGNED A DRIVER\n" ); + } + } - if (options & PRINT_DEVS_UNASSIGNED) { - parg = "\n --- DEVICES WITHOUT DRIVER ---\n"; - drvmgr_for_each_listdev(&mgr->devices_inactive, 0, - DEV_STATE_UNITED, print_dev_found, &parg); - if (parg != NULL) - printf("\n NO DEVICES WERE WITHOUT DRIVER\n"); - } + if ( options & PRINT_DEVS_UNASSIGNED ) { + parg = "\n --- DEVICES WITHOUT DRIVER ---\n"; + drvmgr_for_each_listdev( + &mgr->devices_inactive, + 0, + DEV_STATE_UNITED, + print_dev_found, + &parg + ); + if ( parg != NULL ) { + printf( "\n NO DEVICES WERE WITHOUT DRIVER\n" ); + } + } - if (options & PRINT_DEVS_FAILED) { - parg = "\n --- DEVICES FAILED TO INITIALIZE ---\n"; - drvmgr_for_each_listdev(&mgr->devices_inactive, - DEV_STATE_INIT_FAILED, 0, print_dev_found, &parg); - if (parg != NULL) - printf("\n NO DEVICES FAILED TO INITIALIZE\n"); - } + if ( options & PRINT_DEVS_FAILED ) { + parg = "\n --- DEVICES FAILED TO INITIALIZE ---\n"; + drvmgr_for_each_listdev( + &mgr->devices_inactive, + DEV_STATE_INIT_FAILED, + 0, + print_dev_found, + &parg + ); + if ( parg != NULL ) { + printf( "\n NO DEVICES FAILED TO INITIALIZE\n" ); + } + } - if (options & PRINT_DEVS_IGNORED) { - parg = "\n --- DEVICES IGNORED ---\n"; - drvmgr_for_each_listdev(&mgr->devices_inactive, - DEV_STATE_IGNORED, 0, print_dev_found, &parg); - if (parg != NULL) - printf("\n NO DEVICES WERE IGNORED\n"); - } + if ( options & PRINT_DEVS_IGNORED ) { + parg = "\n --- DEVICES IGNORED ---\n"; + drvmgr_for_each_listdev( + &mgr->devices_inactive, + DEV_STATE_IGNORED, + 0, + print_dev_found, + &parg + ); + if ( parg != NULL ) { + printf( "\n NO DEVICES WERE IGNORED\n" ); + } + } - printf("\n\n"); + printf( "\n\n" ); } -static intptr_t drvmgr_topo_func(struct drvmgr_dev *dev, void *arg) +static intptr_t drvmgr_topo_func( struct drvmgr_dev *dev, void *arg ) { - (void) arg; + (void) arg; - char prefix[32]; - int depth = dev->parent->depth; + char prefix[ 32 ]; + int depth = dev->parent->depth; - if (depth > 30) - return 0; /* depth more than 30 not supported */ - memset(prefix, ' ', depth + 1); - prefix[depth + 1] = '\0'; + if ( depth > 30 ) { + return 0; /* depth more than 30 not supported */ + } + memset( prefix, ' ', depth + 1 ); + prefix[ depth + 1 ] = '\0'; - printf(" %s|-> DEV %p %s\n", prefix, dev, - dev->name ? dev->name : "NO_NAME"); - return 0; + printf( + " %s|-> DEV %p %s\n", + prefix, + dev, + dev->name ? dev->name : "NO_NAME" + ); + return 0; } -void drvmgr_print_topo(void) +void drvmgr_print_topo( void ) { - /* Print Bus topology */ - printf(" --- BUS TOPOLOGY ---\n"); - drvmgr_for_each_dev(drvmgr_topo_func, NULL, DRVMGR_FED_DF); - printf("\n\n"); + /* Print Bus topology */ + printf( " --- BUS TOPOLOGY ---\n" ); + drvmgr_for_each_dev( drvmgr_topo_func, NULL, DRVMGR_FED_DF ); + printf( "\n\n" ); } /* Print the memory usage */ -void drvmgr_print_mem(void) +void drvmgr_print_mem( void ) { - struct drvmgr *mgr = &drvmgr; - struct drvmgr_bus *bus; - struct drvmgr_dev *dev; - struct drvmgr_drv *drv; + struct drvmgr *mgr = &drvmgr; + struct drvmgr_bus *bus; + struct drvmgr_dev *dev; + struct drvmgr_drv *drv; - struct drvmgr_bus_res *node; - struct drvmgr_drv_res *res; - struct drvmgr_key *key; + struct drvmgr_bus_res *node; + struct drvmgr_drv_res *res; + struct drvmgr_key *key; - unsigned int busmem = 0; - unsigned int devmem = 0; - unsigned int drvmem = 0; - unsigned int resmem = 0; - unsigned int devprivmem = 0; + unsigned int busmem = 0; + unsigned int devmem = 0; + unsigned int drvmem = 0; + unsigned int resmem = 0; + unsigned int devprivmem = 0; - DRVMGR_LOCK_READ(); + DRVMGR_LOCK_READ(); - bus = BUS_LIST_HEAD(&mgr->buses[DRVMGR_LEVEL_MAX]); - while (bus) { - busmem += sizeof(struct drvmgr_bus); + bus = BUS_LIST_HEAD( &mgr->buses[ DRVMGR_LEVEL_MAX ] ); + while ( bus ) { + busmem += sizeof( struct drvmgr_bus ); - /* Get size of resources on this bus */ - node = bus->reslist; - while (node) { - resmem += sizeof(struct drvmgr_bus_res); + /* Get size of resources on this bus */ + node = bus->reslist; + while ( node ) { + resmem += sizeof( struct drvmgr_bus_res ); - res = node->resource; - while (res->keys) { - resmem += sizeof(struct drvmgr_drv_res); + res = node->resource; + while ( res->keys ) { + resmem += sizeof( struct drvmgr_drv_res ); - key = res->keys; - while (key->key_type != DRVMGR_KT_NONE) { - resmem += sizeof - (struct drvmgr_key); - key++; - } - resmem += sizeof(struct drvmgr_key); - res++; - } + key = res->keys; + while ( key->key_type != DRVMGR_KT_NONE ) { + resmem += sizeof( struct drvmgr_key ); + key++; + } + resmem += sizeof( struct drvmgr_key ); + res++; + } - node = node->next; - } + node = node->next; + } - bus = bus->next; - } + bus = bus->next; + } - drv = DRV_LIST_HEAD(&mgr->drivers); - while (drv) { - drvmem += sizeof(struct drvmgr_drv); - drv = drv->next; - } + drv = DRV_LIST_HEAD( &mgr->drivers ); + while ( drv ) { + drvmem += sizeof( struct drvmgr_drv ); + drv = drv->next; + } - dev = DEV_LIST_HEAD(&mgr->devices[DRVMGR_LEVEL_MAX]); - while (dev) { - devmem += sizeof(struct drvmgr_dev); - if (dev->drv && dev->drv->dev_priv_size > 0) - devprivmem += dev->drv->dev_priv_size; - dev = dev->next; - } + dev = DEV_LIST_HEAD( &mgr->devices[ DRVMGR_LEVEL_MAX ] ); + while ( dev ) { + devmem += sizeof( struct drvmgr_dev ); + if ( dev->drv && dev->drv->dev_priv_size > 0 ) { + devprivmem += dev->drv->dev_priv_size; + } + dev = dev->next; + } - DRVMGR_UNLOCK(); + DRVMGR_UNLOCK(); - printf(" --- MEMORY USAGE ---\n"); - printf(" BUS: %d bytes\n", busmem); - printf(" DRV: %d bytes\n", drvmem); - printf(" DEV: %d bytes\n", devmem); - printf(" DEV private: %d bytes\n", devprivmem); - printf(" RES: %d bytes\n", resmem); - printf(" TOTAL: %d bytes\n", - busmem + drvmem + devmem + devprivmem + resmem); - printf("\n\n"); + printf( " --- MEMORY USAGE ---\n" ); + printf( " BUS: %d bytes\n", busmem ); + printf( " DRV: %d bytes\n", drvmem ); + printf( " DEV: %d bytes\n", devmem ); + printf( " DEV private: %d bytes\n", devprivmem ); + printf( " RES: %d bytes\n", resmem ); + printf( + " TOTAL: %d bytes\n", + busmem + drvmem + devmem + devprivmem + resmem + ); + printf( "\n\n" ); } /* Print the memory usage */ -void drvmgr_summary(void) +void drvmgr_summary( void ) { - struct drvmgr *mgr = &drvmgr; - struct drvmgr_bus *bus; - struct drvmgr_dev *dev; - struct drvmgr_drv *drv; - int i, buscnt = 0, devcnt = 0, drvcnt = 0; + struct drvmgr *mgr = &drvmgr; + struct drvmgr_bus *bus; + struct drvmgr_dev *dev; + struct drvmgr_drv *drv; + int i, buscnt = 0, devcnt = 0, drvcnt = 0; - printf(" --- SUMMARY ---\n"); + printf( " --- SUMMARY ---\n" ); - drv = DRV_LIST_HEAD(&mgr->drivers); - while (drv) { - drvcnt++; - drv = drv->next; - } - printf(" NUMBER OF DRIVERS: %d\n", drvcnt); + drv = DRV_LIST_HEAD( &mgr->drivers ); + while ( drv ) { + drvcnt++; + drv = drv->next; + } + printf( " NUMBER OF DRIVERS: %d\n", drvcnt ); - DRVMGR_LOCK_READ(); + DRVMGR_LOCK_READ(); - for (i = 0; i <= DRVMGR_LEVEL_MAX; i++) { - buscnt = 0; - bus = BUS_LIST_HEAD(&mgr->buses[i]); - while (bus) { - buscnt++; - bus = bus->next; - } - if (buscnt > 0) { - printf(" NUMBER OF BUSES IN LEVEL[%d]: %d\n", - i, buscnt); - } - } + for ( i = 0; i <= DRVMGR_LEVEL_MAX; i++ ) { + buscnt = 0; + bus = BUS_LIST_HEAD( &mgr->buses[ i ] ); + while ( bus ) { + buscnt++; + bus = bus->next; + } + if ( buscnt > 0 ) { + printf( " NUMBER OF BUSES IN LEVEL[%d]: %d\n", i, buscnt ); + } + } - for (i = 0; i <= DRVMGR_LEVEL_MAX; i++) { - devcnt = 0; - dev = DEV_LIST_HEAD(&mgr->devices[i]); - while (dev) { - devcnt++; - dev = dev->next; - } - if (devcnt > 0) { - printf(" NUMBER OF DEVS IN LEVEL[%d]: %d\n", - i, devcnt); - } - } + for ( i = 0; i <= DRVMGR_LEVEL_MAX; i++ ) { + devcnt = 0; + dev = DEV_LIST_HEAD( &mgr->devices[ i ] ); + while ( dev ) { + devcnt++; + dev = dev->next; + } + if ( devcnt > 0 ) { + printf( " NUMBER OF DEVS IN LEVEL[%d]: %d\n", i, devcnt ); + } + } - DRVMGR_UNLOCK(); + DRVMGR_UNLOCK(); - printf("\n\n"); + printf( "\n\n" ); } -static void print_info(void *p, char *str) +static void print_info( void *p, char *str ) { - (void) p; + (void) p; - printf(" "); - puts(str); + printf( " " ); + puts( str ); } -void drvmgr_info_dev(struct drvmgr_dev *dev, unsigned int options) +void drvmgr_info_dev( struct drvmgr_dev *dev, unsigned int options ) { - if (!dev) - return; + if ( !dev ) { + return; + } - printf(" -- DEVICE %p --\n", dev); - if (options & OPTION_DEV_GENINFO) { - printf(" PARENT BUS: %p\n", dev->parent); - printf(" NAME: %s\n", dev->name ? dev->name : "NO_NAME"); - printf(" STATE: 0x%08x\n", dev->state); - if (dev->bus) - printf(" BRIDGE TO: %p\n", dev->bus); - printf(" INIT LEVEL: %d\n", dev->level); - printf(" ERROR: %d\n", dev->error); - printf(" MINOR BUS: %d\n", dev->minor_bus); - if (dev->drv) { - printf(" MINOR DRV: %d\n", dev->minor_drv); - printf(" DRIVER: %p (%s)\n", dev->drv, - dev->drv->name ? dev->drv->name : "NO_NAME"); - printf(" PRIVATE: %p\n", dev->priv); - } - } + printf( " -- DEVICE %p --\n", dev ); + if ( options & OPTION_DEV_GENINFO ) { + printf( " PARENT BUS: %p\n", dev->parent ); + printf( " NAME: %s\n", dev->name ? dev->name : "NO_NAME" ); + printf( " STATE: 0x%08x\n", dev->state ); + if ( dev->bus ) { + printf( " BRIDGE TO: %p\n", dev->bus ); + } + printf( " INIT LEVEL: %d\n", dev->level ); + printf( " ERROR: %d\n", dev->error ); + printf( " MINOR BUS: %d\n", dev->minor_bus ); + if ( dev->drv ) { + printf( " MINOR DRV: %d\n", dev->minor_drv ); + printf( + " DRIVER: %p (%s)\n", + dev->drv, + dev->drv->name ? dev->drv->name : "NO_NAME" + ); + printf( " PRIVATE: %p\n", dev->priv ); + } + } - if (options & OPTION_DEV_BUSINFO) { - printf(" --- DEVICE INFO FROM BUS DRIVER ---\n"); - if (!dev->parent) - printf(" !! device has no parent bus !!\n"); - else if (dev->parent->ops->get_info_dev) - dev->parent->ops->get_info_dev(dev, print_info, NULL); - else - printf(" Bus doesn't implement get_info_dev func\n"); - } + if ( options & OPTION_DEV_BUSINFO ) { + printf( " --- DEVICE INFO FROM BUS DRIVER ---\n" ); + if ( !dev->parent ) { + printf( " !! device has no parent bus !!\n" ); + } else if ( dev->parent->ops->get_info_dev ) { + dev->parent->ops->get_info_dev( dev, print_info, NULL ); + } else { + printf( " Bus doesn't implement get_info_dev func\n" ); + } + } - if (options & OPTION_DEV_DRVINFO) { - if (dev->drv) { - printf(" --- DEVICE INFO FROM DEVICE DRIVER ---\n"); - if (dev->drv->ops->info) - dev->drv->ops->info(dev, print_info, NULL, 0, 0); - else - printf(" Driver doesn't implement info func\n"); - } - } + if ( options & OPTION_DEV_DRVINFO ) { + if ( dev->drv ) { + printf( " --- DEVICE INFO FROM DEVICE DRIVER ---\n" ); + if ( dev->drv->ops->info ) { + dev->drv->ops->info( dev, print_info, NULL, 0, 0 ); + } else { + printf( " Driver doesn't implement info func\n" ); + } + } + } } -static void drvmgr_info_bus_map(struct drvmgr_map_entry *map) +static void drvmgr_info_bus_map( struct drvmgr_map_entry *map ) { - if (map == NULL) - printf(" Addresses mapped 1:1\n"); - else if (map == DRVMGR_TRANSLATE_NO_BRIDGE) - printf(" No bridge in this direction\n"); - else { - while (map->size != 0) { - printf(" 0x%08lx-0x%08lx => 0x%08lx-0x%08lx %s\n", - (unsigned long)map->from_adr, - (unsigned long)(map->from_adr + map->size - 1), - (unsigned long)map->to_adr, - (unsigned long)(map->to_adr + map->size - 1), - map->name ? map->name : "no label"); - map++; - } - } + if ( map == NULL ) { + printf( " Addresses mapped 1:1\n" ); + } else if ( map == DRVMGR_TRANSLATE_NO_BRIDGE ) { + printf( " No bridge in this direction\n" ); + } else { + while ( map->size != 0 ) { + printf( + " 0x%08lx-0x%08lx => 0x%08lx-0x%08lx %s\n", + (unsigned long) map->from_adr, + (unsigned long) ( map->from_adr + map->size - 1 ), + (unsigned long) map->to_adr, + (unsigned long) ( map->to_adr + map->size - 1 ), + map->name ? map->name : "no label" + ); + map++; + } + } } -void drvmgr_info_bus(struct drvmgr_bus *bus, unsigned int options) +void drvmgr_info_bus( struct drvmgr_bus *bus, unsigned int options ) { - struct drvmgr_dev *dev; + struct drvmgr_dev *dev; - /* Print Driver */ - printf("-- BUS %p --\n", bus); - printf(" BUS TYPE: %d\n", bus->bus_type); - printf(" DEVICE: %p (%s)\n", bus->dev, - bus->dev->name ? bus->dev->name : "NO_NAME"); - printf(" OPS: %p\n", bus->ops); - printf(" CHILDREN: %d devices\n", bus->dev_cnt); - printf(" LEVEL: %d\n", bus->level); - printf(" STATE: 0x%08x\n", bus->state); - printf(" ERROR: %d\n", bus->error); + /* Print Driver */ + printf( "-- BUS %p --\n", bus ); + printf( " BUS TYPE: %d\n", bus->bus_type ); + printf( + " DEVICE: %p (%s)\n", + bus->dev, + bus->dev->name ? bus->dev->name : "NO_NAME" + ); + printf( " OPS: %p\n", bus->ops ); + printf( " CHILDREN: %d devices\n", bus->dev_cnt ); + printf( " LEVEL: %d\n", bus->level ); + printf( " STATE: 0x%08x\n", bus->state ); + printf( " ERROR: %d\n", bus->error ); - /* Print address mappings up- (to parent) and down- (from parent to + /* Print address mappings up- (to parent) and down- (from parent to * this bus) stream the bridge of this bus */ - printf(" DOWN STREAMS BRIDGE MAPPINGS (from parent to this bus)\n"); - drvmgr_info_bus_map(bus->maps_down); - printf(" UP STREAMS BRIDGE MAPPINGS (from this bus to parent)\n"); - drvmgr_info_bus_map(bus->maps_up); + printf( " DOWN STREAMS BRIDGE MAPPINGS (from parent to this bus)\n" ); + drvmgr_info_bus_map( bus->maps_down ); + printf( " UP STREAMS BRIDGE MAPPINGS (from this bus to parent)\n" ); + drvmgr_info_bus_map( bus->maps_up ); - /* Print Devices on this bus? */ - if (options & OPTION_BUS_DEVS) { - printf(" CHILDREN:\n"); - DRVMGR_LOCK_READ(); - dev = bus->children; - while (dev) { - printf(" |- DEV[%02d]: %p %s\n", dev->minor_bus, - dev, dev->name ? dev->name : "NO_NAME"); - dev = dev->next_in_bus; - } - DRVMGR_UNLOCK(); - } + /* Print Devices on this bus? */ + if ( options & OPTION_BUS_DEVS ) { + printf( " CHILDREN:\n" ); + DRVMGR_LOCK_READ(); + dev = bus->children; + while ( dev ) { + printf( + " |- DEV[%02d]: %p %s\n", + dev->minor_bus, + dev, + dev->name ? dev->name : "NO_NAME" + ); + dev = dev->next_in_bus; + } + DRVMGR_UNLOCK(); + } } -void drvmgr_info_drv(struct drvmgr_drv *drv, unsigned int options) +void drvmgr_info_drv( struct drvmgr_drv *drv, unsigned int options ) { - struct drvmgr_dev *dev; - int i; + struct drvmgr_dev *dev; + int i; - /* Print Driver */ - printf(" -- DRIVER %p --\n", drv); - printf(" DRIVER ID: 0x%" PRIx64 "\n", drv->drv_id); - printf(" NAME: %s\n", drv->name ? drv->name : "NO_NAME"); - printf(" BUS TYPE: %d\n", drv->bus_type); - printf(" OPERATIONS:\n"); - for (i = 0; i < DRVMGR_LEVEL_MAX; i++) - printf(" init[%d]: %p\n", i + 1, drv->ops->init[i]); - printf(" remove: %p\n", drv->ops->remove); - printf(" info: %p\n", drv->ops->info); - printf(" NO. DEVICES: %d\n", drv->dev_cnt); + /* Print Driver */ + printf( " -- DRIVER %p --\n", drv ); + printf( " DRIVER ID: 0x%" PRIx64 "\n", drv->drv_id ); + printf( " NAME: %s\n", drv->name ? drv->name : "NO_NAME" ); + printf( " BUS TYPE: %d\n", drv->bus_type ); + printf( " OPERATIONS:\n" ); + for ( i = 0; i < DRVMGR_LEVEL_MAX; i++ ) { + printf( " init[%d]: %p\n", i + 1, drv->ops->init[ i ] ); + } + printf( " remove: %p\n", drv->ops->remove ); + printf( " info: %p\n", drv->ops->info ); + printf( " NO. DEVICES: %d\n", drv->dev_cnt ); - /* Print devices united with this driver? */ - if (options & OPTION_DRV_DEVS) { - DRVMGR_LOCK_READ(); - dev = drv->dev; - while (dev) { - printf(" DEV[%02d]: %p %s\n", dev->minor_drv, - dev, dev->name ? dev->name : "NO_NAME"); - dev = dev->next_in_drv; - } - DRVMGR_UNLOCK(); - } + /* Print devices united with this driver? */ + if ( options & OPTION_DRV_DEVS ) { + DRVMGR_LOCK_READ(); + dev = drv->dev; + while ( dev ) { + printf( + " DEV[%02d]: %p %s\n", + dev->minor_drv, + dev, + dev->name ? dev->name : "NO_NAME" + ); + dev = dev->next_in_drv; + } + DRVMGR_UNLOCK(); + } } -void (*info_obj[3])(void *obj, unsigned int) = { - /* DRVMGR_OBJ_DRV */ (void (*)(void *, unsigned int))drvmgr_info_drv, - /* DRVMGR_OBJ_BUS */ (void (*)(void *, unsigned int))drvmgr_info_bus, - /* DRVMGR_OBJ_DEV */ (void (*)(void *, unsigned int))drvmgr_info_dev, +void ( *info_obj[ 3 ] )( void *obj, unsigned int ) = { + /* DRVMGR_OBJ_DRV */ (void ( * )( void *, unsigned int )) drvmgr_info_drv, + /* DRVMGR_OBJ_BUS */ (void ( * )( void *, unsigned int )) drvmgr_info_bus, + /* DRVMGR_OBJ_DEV */ (void ( * )( void *, unsigned int )) drvmgr_info_dev, }; /* Get information about a device/bus/driver */ -void drvmgr_info(void *id, unsigned int options) +void drvmgr_info( void *id, unsigned int options ) { - int obj_type; - void (*func)(void *, unsigned int); + int obj_type; + void ( *func )( void *, unsigned int ); - if (!id) - return; - obj_type = *(int *)id; - if ((obj_type < DRVMGR_OBJ_DRV) || (obj_type > DRVMGR_OBJ_DEV)) - return; - func = info_obj[obj_type - 1]; - func(id, options); + if ( !id ) { + return; + } + obj_type = *(int *) id; + if ( ( obj_type < DRVMGR_OBJ_DRV ) || ( obj_type > DRVMGR_OBJ_DEV ) ) { + return; + } + func = info_obj[ obj_type - 1 ]; + func( id, options ); } -void drvmgr_info_devs_on_bus(struct drvmgr_bus *bus, unsigned int options) +void drvmgr_info_devs_on_bus( struct drvmgr_bus *bus, unsigned int options ) { - struct drvmgr_dev *dev; + struct drvmgr_dev *dev; - /* Print All Devices on Bus */ - printf("\n\n -= All Devices on BUS %p =-\n\n", bus); - dev = bus->children; - while (dev) { - drvmgr_info_dev(dev, options); - puts(""); - dev = dev->next_in_bus; - } + /* Print All Devices on Bus */ + printf( "\n\n -= All Devices on BUS %p =-\n\n", bus ); + dev = bus->children; + while ( dev ) { + drvmgr_info_dev( dev, options ); + puts( "" ); + dev = dev->next_in_bus; + } - if ((options & OPTION_RECURSIVE) == 0) - return; + if ( ( options & OPTION_RECURSIVE ) == 0 ) { + return; + } - /* This device provides a bus, print the bus */ - dev = bus->children; - while (dev) { - if (dev->bus) - drvmgr_info_devs_on_bus(dev->bus, options); - dev = dev->next_in_bus; - } + /* This device provides a bus, print the bus */ + dev = bus->children; + while ( dev ) { + if ( dev->bus ) { + drvmgr_info_devs_on_bus( dev->bus, options ); + } + dev = dev->next_in_bus; + } } -void drvmgr_info_devs(unsigned int options) +void drvmgr_info_devs( unsigned int options ) { - struct drvmgr *mgr = &drvmgr; - struct drvmgr_dev *dev; + struct drvmgr *mgr = &drvmgr; + struct drvmgr_dev *dev; - /* Print device information of all devices and their child devices */ - dev = &mgr->root_dev; - drvmgr_info_devs_on_bus(dev->bus, options); - printf("\n\n"); + /* Print device information of all devices and their child devices */ + dev = &mgr->root_dev; + drvmgr_info_devs_on_bus( dev->bus, options ); + printf( "\n\n" ); } -void drvmgr_info_drvs(unsigned int options) +void drvmgr_info_drvs( unsigned int options ) { - struct drvmgr *mgr = &drvmgr; - struct drvmgr_drv *drv; + struct drvmgr *mgr = &drvmgr; + struct drvmgr_drv *drv; - drv = DRV_LIST_HEAD(&mgr->drivers); - while (drv) { - drvmgr_info_drv(drv, options); - puts("\n"); - drv = drv->next; - } + drv = DRV_LIST_HEAD( &mgr->drivers ); + while ( drv ) { + drvmgr_info_drv( drv, options ); + puts( "\n" ); + drv = drv->next; + } } -void drvmgr_info_buses(unsigned int options) +void drvmgr_info_buses( unsigned int options ) { - struct drvmgr *mgr = &drvmgr; - struct drvmgr_bus *bus; + struct drvmgr *mgr = &drvmgr; + struct drvmgr_bus *bus; - bus = BUS_LIST_HEAD(&mgr->buses[DRVMGR_LEVEL_MAX]); - while (bus) { - drvmgr_info_bus(bus, options); - puts("\n"); - bus = bus->next; - } + bus = BUS_LIST_HEAD( &mgr->buses[ DRVMGR_LEVEL_MAX ] ); + while ( bus ) { + drvmgr_info_bus( bus, options ); + puts( "\n" ); + bus = bus->next; + } } diff --git a/cpukit/libdrvmgr/drvmgr_res.c b/cpukit/libdrvmgr/drvmgr_res.c index 8a447dab48..fa7552fbee 100644 --- a/cpukit/libdrvmgr/drvmgr_res.c +++ b/cpukit/libdrvmgr/drvmgr_res.c @@ -30,92 +30,100 @@ #include /* Find all the resource keys for a device among all bus resources */ -int drvmgr_keys_get(struct drvmgr_dev *dev, struct drvmgr_key **keys) +int drvmgr_keys_get( struct drvmgr_dev *dev, struct drvmgr_key **keys ) { - struct drvmgr_bus *bus; - struct drvmgr_bus_res *node; - struct drvmgr_drv_res *res; - uint64_t drv_id; + struct drvmgr_bus *bus; + struct drvmgr_bus_res *node; + struct drvmgr_drv_res *res; + uint64_t drv_id; - bus = dev->parent; - if (!bus || !dev->drv) - return -1; + bus = dev->parent; + if ( !bus || !dev->drv ) { + return -1; + } - drv_id = dev->drv->drv_id; + drv_id = dev->drv->drv_id; - /* Loop all resource arrays */ - node = bus->reslist; - while (node) { - /* Find driver ID in resource array */ - res = &node->resource[0]; - while (res->drv_id) { - if (res->drv_id == drv_id) { - /* Found resource matching driver, now check + /* Loop all resource arrays */ + node = bus->reslist; + while ( node ) { + /* Find driver ID in resource array */ + res = &node->resource[ 0 ]; + while ( res->drv_id ) { + if ( res->drv_id == drv_id ) { + /* Found resource matching driver, now check * that this resource is for this device. */ - if (dev->minor_bus == res->minor_bus) { - /* Matching driver and core number */ - if (keys) - *keys = res->keys; - return 0; - } - } - res++; - } - node = node->next; - } - if (keys) - *keys = NULL; - return 1; + if ( dev->minor_bus == res->minor_bus ) { + /* Matching driver and core number */ + if ( keys ) { + *keys = res->keys; + } + return 0; + } + } + res++; + } + node = node->next; + } + if ( keys ) { + *keys = NULL; + } + return 1; } /* Return key that matches key name */ -struct drvmgr_key *drvmgr_key_get( - struct drvmgr_key *keys, - char *key_name) +struct drvmgr_key *drvmgr_key_get( struct drvmgr_key *keys, char *key_name ) { - struct drvmgr_key *key; + struct drvmgr_key *key; - if (!keys) - return NULL; + if ( !keys ) { + return NULL; + } - key = keys; - while (key->key_type != DRVMGR_KT_NONE) { - if (strcmp(key_name, key->key_name) == 0) - return key; - key++; - } - return NULL; + key = keys; + while ( key->key_type != DRVMGR_KT_NONE ) { + if ( strcmp( key_name, key->key_name ) == 0 ) { + return key; + } + key++; + } + return NULL; } union drvmgr_key_value *drvmgr_key_val_get( - struct drvmgr_key *keys, - char *key_name, - enum drvmgr_kt key_type) + struct drvmgr_key *keys, + char *key_name, + enum drvmgr_kt key_type +) { - struct drvmgr_key *key_match; + struct drvmgr_key *key_match; - key_match = drvmgr_key_get(keys, key_name); - if (key_match) { - /* Found key, put pointer to value into */ - if ((key_type == DRVMGR_KT_ANY) || - (key_match->key_type == key_type)) - return &key_match->key_value; - } - return NULL; + key_match = drvmgr_key_get( keys, key_name ); + if ( key_match ) { + /* Found key, put pointer to value into */ + if ( + ( key_type == DRVMGR_KT_ANY ) || ( key_match->key_type == key_type ) + ) { + return &key_match->key_value; + } + } + return NULL; } union drvmgr_key_value *drvmgr_dev_key_get( - struct drvmgr_dev *dev, - char *key_name, - enum drvmgr_kt key_type) + struct drvmgr_dev *dev, + char *key_name, + enum drvmgr_kt key_type +) { - struct drvmgr_key *keys = NULL; + struct drvmgr_key *keys = NULL; - /* Find first entry in key array for the device */ - if (drvmgr_keys_get(dev, &keys)) - return NULL; + /* Find first entry in key array for the device */ + if ( drvmgr_keys_get( dev, &keys ) ) { + return NULL; + } - /* Find a specific key among the device keys */ - return drvmgr_key_val_get(keys, key_name, key_type); + /* Find a specific key among the device keys */ + return drvmgr_key_val_get( keys, key_name, key_type ); } diff --git a/cpukit/libdrvmgr/drvmgr_rw.c b/cpukit/libdrvmgr/drvmgr_rw.c index d4efb3c4e2..086bd82b8f 100644 --- a/cpukit/libdrvmgr/drvmgr_rw.c +++ b/cpukit/libdrvmgr/drvmgr_rw.c @@ -33,38 +33,41 @@ * This call will take 128 bytes for buffer on stack */ void drvmgr_rw_memset( - void *dstadr, - int c, - size_t n, - void *a, - drvmgr_wmem_arg wmem - ) + void *dstadr, + int c, + size_t n, + void *a, + drvmgr_wmem_arg wmem +) { - unsigned long long buf[16+1]; /* Extra bytes after data are reserved + unsigned long long buf[ 16 + 1 ]; /* Extra bytes after data are reserved * for optimizations by write_mem */ - int txlen; - char *adr; + int txlen; + char *adr; - if (n <= 0) - return; + if ( n <= 0 ) { + return; + } - if (n > sizeof(unsigned long long)*16) - txlen = sizeof(unsigned long long)*16; - else - txlen = n; + if ( n > sizeof( unsigned long long ) * 16 ) { + txlen = sizeof( unsigned long long ) * 16; + } else { + txlen = n; + } - memset(buf, c, txlen); + memset( buf, c, txlen ); - adr = dstadr; - do { - wmem(adr, (const void *)&buf[0], txlen, a); - adr += txlen; - n -= txlen; + adr = dstadr; + do { + wmem( adr, (const void *) &buf[ 0 ], txlen, a ); + adr += txlen; + n -= txlen; - /* next length to transmitt */ - if (n > 16*sizeof(unsigned long long)) - txlen = 16*sizeof(unsigned long long); - else - txlen = n; - } while (n > 0); + /* next length to transmitt */ + if ( n > 16 * sizeof( unsigned long long ) ) { + txlen = 16 * sizeof( unsigned long long ); + } else { + txlen = n; + } + } while ( n > 0 ); } diff --git a/cpukit/libdrvmgr/drvmgr_translate.c b/cpukit/libdrvmgr/drvmgr_translate.c index afd0eacbeb..4851424d09 100644 --- a/cpukit/libdrvmgr/drvmgr_translate.c +++ b/cpukit/libdrvmgr/drvmgr_translate.c @@ -49,119 +49,130 @@ #include "drvmgr_internal.h" unsigned int drvmgr_translate_bus( - struct drvmgr_bus *from, - struct drvmgr_bus *to, - int reverse, - void *src_address, - void **dst_address) + struct drvmgr_bus *from, + struct drvmgr_bus *to, + int reverse, + void *src_address, + void **dst_address +) { - struct drvmgr_bus *path[16]; - int dir, levels, i; - void *dst, *from_adr, *to_adr; - struct drvmgr_map_entry *map; - struct drvmgr_bus *bus; - ssize_t sz; - struct drvmgr_bus *bus_bot, *bus_top; + struct drvmgr_bus *path[ 16 ]; + int dir, levels, i; + void *dst, *from_adr, *to_adr; + struct drvmgr_map_entry *map; + struct drvmgr_bus *bus; + ssize_t sz; + struct drvmgr_bus *bus_bot, *bus_top; - dst = src_address; - sz = 0xffffffff; + dst = src_address; + sz = 0xffffffff; - if (from == to) /* no need translating addresses when on same bus */ - goto out; + if ( from == to ) { /* no need translating addresses when on same bus */ + goto out; + } - /* Always find translation path from remote bus towards root bus. All + /* Always find translation path from remote bus towards root bus. All * buses have root bus has parent at some level */ - if (from->depth > to->depth) { - bus_bot = from; - bus_top = to; - dir = 0; - } else { - bus_bot = to; - bus_top = from; - dir = 1; - } - levels = bus_bot->depth - bus_top->depth; - if (levels >= 16) - return 0; /* Does not support such a big depth */ - i = 0; - while ((bus_bot != NULL) && bus_bot != bus_top) { - if (dir) - path[(levels - 1) - i] = bus_bot; - else - path[i] = bus_bot; - i++; - bus_bot = bus_bot->dev->parent; - } - if (bus_bot == NULL) - return 0; /* from -> to is not linearly connected */ + if ( from->depth > to->depth ) { + bus_bot = from; + bus_top = to; + dir = 0; + } else { + bus_bot = to; + bus_top = from; + dir = 1; + } + levels = bus_bot->depth - bus_top->depth; + if ( levels >= 16 ) { + return 0; /* Does not support such a big depth */ + } + i = 0; + while ( ( bus_bot != NULL ) && bus_bot != bus_top ) { + if ( dir ) { + path[ ( levels - 1 ) - i ] = bus_bot; + } else { + path[ i ] = bus_bot; + } + i++; + bus_bot = bus_bot->dev->parent; + } + if ( bus_bot == NULL ) { + return 0; /* from -> to is not linearly connected */ + } - for (i = 0; i < levels; i++) { - bus = path[i]; + for ( i = 0; i < levels; i++ ) { + bus = path[ i ]; - if ((dir && reverse) || (!dir && !reverse)) - map = bus->maps_up; - else - map = bus->maps_down; + if ( ( dir && reverse ) || ( !dir && !reverse ) ) { + map = bus->maps_up; + } else { + map = bus->maps_down; + } - if (map == NULL) - continue; /* No translation needed - 1:1 mapping */ + if ( map == NULL ) { + continue; /* No translation needed - 1:1 mapping */ + } - if (map == DRVMGR_TRANSLATE_NO_BRIDGE) { - sz = 0; - break; /* No bridge interface in this direction */ - } + if ( map == DRVMGR_TRANSLATE_NO_BRIDGE ) { + sz = 0; + break; /* No bridge interface in this direction */ + } - while (map->size != 0) { - if (reverse) { - /* Opposite direction */ - from_adr = map->to_adr; - to_adr = map->from_adr; - } else { - from_adr = map->from_adr; - to_adr = map->to_adr; - } + while ( map->size != 0 ) { + if ( reverse ) { + /* Opposite direction */ + from_adr = map->to_adr; + to_adr = map->from_adr; + } else { + from_adr = map->from_adr; + to_adr = map->to_adr; + } - if ((dst >= from_adr) && - (dst <= (from_adr + (map->size - 1)))) { - if (((from_adr + (map->size - 1)) - dst) < sz) - sz = (from_adr + (map->size - 1)) - dst; - dst = (dst - from_adr) + to_adr; - break; - } - map++; - } - /* quit if no matching translation information */ - if (map->size == 0) { - sz = 0; - break; - } - } + if ( + ( dst >= from_adr ) && ( dst <= ( from_adr + ( map->size - 1 ) ) ) + ) { + if ( ( ( from_adr + ( map->size - 1 ) ) - dst ) < sz ) { + sz = ( from_adr + ( map->size - 1 ) ) - dst; + } + dst = ( dst - from_adr ) + to_adr; + break; + } + map++; + } + /* quit if no matching translation information */ + if ( map->size == 0 ) { + sz = 0; + break; + } + } out: - if (dst_address) - *dst_address = dst; + if ( dst_address ) { + *dst_address = dst; + } - return sz; + return sz; } unsigned int drvmgr_translate( - struct drvmgr_dev *dev, - unsigned int options, - void *src_address, - void **dst_address) + struct drvmgr_dev *dev, + unsigned int options, + void *src_address, + void **dst_address +) { - struct drvmgr_bus *to, *from; - int rev = 0; + struct drvmgr_bus *to, *from; + int rev = 0; - rev = (~options) & 1; - if ((options == CPUMEM_TO_DMA) || (options == DMAMEM_FROM_CPU)) { - from = drvmgr.root_dev.bus; - to = dev->parent; - } else { /* CPUMEM_FROM_DMA || DMAMEM_TO_CPU */ - from = dev->parent; - to = drvmgr.root_dev.bus; - } + rev = ( ~options ) & 1; + if ( ( options == CPUMEM_TO_DMA ) || ( options == DMAMEM_FROM_CPU ) ) { + from = drvmgr.root_dev.bus; + to = dev->parent; + } else { /* CPUMEM_FROM_DMA || DMAMEM_TO_CPU */ + from = dev->parent; + to = drvmgr.root_dev.bus; + } - return drvmgr_translate_bus(from, to, rev, src_address, dst_address); + return drvmgr_translate_bus( from, to, rev, src_address, dst_address ); } diff --git a/cpukit/libdrvmgr/drvmgr_translate_check.c b/cpukit/libdrvmgr/drvmgr_translate_check.c index 9459def64a..01ea914650 100644 --- a/cpukit/libdrvmgr/drvmgr_translate_check.c +++ b/cpukit/libdrvmgr/drvmgr_translate_check.c @@ -36,20 +36,25 @@ * If size=0 only the starting address is not checked. */ int drvmgr_translate_check( - struct drvmgr_dev *dev, - unsigned int options, - void *src_address, - void **dst_address, - unsigned int size) + struct drvmgr_dev *dev, + unsigned int options, + void *src_address, + void **dst_address, + unsigned int size +) { - unsigned int max; + unsigned int max; - max = drvmgr_translate(dev, options, src_address, dst_address); - if (max == 0 || (max < size && (size != 0))) { - printk(" ### dev %p (%s) failed mapping %p\n", - dev, dev->name ? dev->name : "unnamed", src_address); - return -1; - } + max = drvmgr_translate( dev, options, src_address, dst_address ); + if ( max == 0 || ( max < size && ( size != 0 ) ) ) { + printk( + " ### dev %p (%s) failed mapping %p\n", + dev, + dev->name ? dev->name : "unnamed", + src_address + ); + return -1; + } - return 0; + return 0; } diff --git a/cpukit/libdrvmgr/drvmgr_unregister.c b/cpukit/libdrvmgr/drvmgr_unregister.c index 391594279e..0001a00372 100644 --- a/cpukit/libdrvmgr/drvmgr_unregister.c +++ b/cpukit/libdrvmgr/drvmgr_unregister.c @@ -37,20 +37,20 @@ * This function is called from the bus driver, from a "safe" state where * devices will not be added or removed on this particular bus at this time */ -int drvmgr_children_unregister(struct drvmgr_bus *bus) +int drvmgr_children_unregister( struct drvmgr_bus *bus ) { - int err; + int err; - while (bus->children != NULL) { - err = drvmgr_dev_unregister(bus->children); - if (err != DRVMGR_OK) { - /* An error occurred */ - bus->children->error = err; - return err; - } - } + while ( bus->children != NULL ) { + err = drvmgr_dev_unregister( bus->children ); + if ( err != DRVMGR_OK ) { + /* An error occurred */ + bus->children->error = err; + return err; + } + } - return DRVMGR_OK; + return DRVMGR_OK; } /* Unregister a BUS and all it's devices. @@ -59,105 +59,112 @@ int drvmgr_children_unregister(struct drvmgr_bus *bus) * one by one calling drvmgr_dev_unregister(), or by letting the driver * manager unregister all children by calling drvmgr_children_unregister(). */ -int drvmgr_bus_unregister(struct drvmgr_bus *bus) +int drvmgr_bus_unregister( struct drvmgr_bus *bus ) { - struct drvmgr *mgr = &drvmgr; - struct drvmgr_list *list; + struct drvmgr *mgr = &drvmgr; + struct drvmgr_list *list; - if (bus->ops->remove == NULL) - return DRVMGR_ENOSYS; + if ( bus->ops->remove == NULL ) { + return DRVMGR_ENOSYS; + } - /* Call Bus driver to clean things up, it must remove all children */ - bus->error = bus->ops->remove(bus); - if (bus->error != DRVMGR_OK) - return bus->error; - /* Check that bus driver has done its job and removed all children */ - if (bus->children != NULL) - return DRVMGR_FAIL; - /* Remove References to bus */ - bus->dev->bus = NULL; + /* Call Bus driver to clean things up, it must remove all children */ + bus->error = bus->ops->remove( bus ); + if ( bus->error != DRVMGR_OK ) { + return bus->error; + } + /* Check that bus driver has done its job and removed all children */ + if ( bus->children != NULL ) { + return DRVMGR_FAIL; + } + /* Remove References to bus */ + bus->dev->bus = NULL; - DRVMGR_LOCK_WRITE(); + DRVMGR_LOCK_WRITE(); - /* Remove bus from bus-list */ - if (bus->state & BUS_STATE_LIST_INACTIVE) - list = &mgr->buses_inactive; - else - list = &mgr->buses[bus->level]; - drvmgr_list_remove(list, bus); + /* Remove bus from bus-list */ + if ( bus->state & BUS_STATE_LIST_INACTIVE ) { + list = &mgr->buses_inactive; + } else { + list = &mgr->buses[ bus->level ]; + } + drvmgr_list_remove( list, bus ); - DRVMGR_UNLOCK(); + DRVMGR_UNLOCK(); - /* All references to this bus has been removed at this point */ - free(bus); + /* All references to this bus has been removed at this point */ + free( bus ); - return DRVMGR_OK; + return DRVMGR_OK; } /* Separate Driver and Device from each other */ -int drvmgr_dev_drv_separate(struct drvmgr_dev *dev) +int drvmgr_dev_drv_separate( struct drvmgr_dev *dev ) { - struct drvmgr *mgr = &drvmgr; - struct drvmgr_dev *subdev, **pprev; - int rc; + struct drvmgr *mgr = &drvmgr; + struct drvmgr_dev *subdev, **pprev; + int rc; - /* Remove children if this device exports a bus of devices. All + /* Remove children if this device exports a bus of devices. All * children must be removed first as they depend upon the bus * services this bridge provide. */ - if (dev->bus) { - rc = drvmgr_bus_unregister(dev->bus); - if (rc != DRVMGR_OK) - return rc; - } + if ( dev->bus ) { + rc = drvmgr_bus_unregister( dev->bus ); + if ( rc != DRVMGR_OK ) { + return rc; + } + } - if (dev->drv == NULL) - return DRVMGR_OK; + if ( dev->drv == NULL ) { + return DRVMGR_OK; + } - /* Remove device by letting assigned driver take care of hardware + /* Remove device by letting assigned driver take care of hardware * issues */ - if (!dev->drv->ops->remove) { - /* No remove function is considered severe when someone + if ( !dev->drv->ops->remove ) { + /* No remove function is considered severe when someone * is trying to remove the device */ - return DRVMGR_ENOSYS; - } - dev->error = dev->drv->ops->remove(dev); - if (dev->error != DRVMGR_OK) - return DRVMGR_FAIL; + return DRVMGR_ENOSYS; + } + dev->error = dev->drv->ops->remove( dev ); + if ( dev->error != DRVMGR_OK ) { + return DRVMGR_FAIL; + } - DRVMGR_LOCK_WRITE(); + DRVMGR_LOCK_WRITE(); - /* Delete device from driver's device list */ - pprev = &dev->drv->dev; - subdev = dev->drv->dev; - while (subdev != dev) { - pprev = &subdev->next_in_drv; - subdev = subdev->next_in_drv; - } - *pprev = subdev->next_in_drv; - dev->drv->dev_cnt--; + /* Delete device from driver's device list */ + pprev = &dev->drv->dev; + subdev = dev->drv->dev; + while ( subdev != dev ) { + pprev = &subdev->next_in_drv; + subdev = subdev->next_in_drv; + } + *pprev = subdev->next_in_drv; + dev->drv->dev_cnt--; - /* Move device to inactive list */ - drvmgr_list_remove(&mgr->devices[dev->level], dev); - dev->level = 0; - dev->state &= ~(DEV_STATE_UNITED|DEV_STATE_INIT_DONE); - dev->state |= DEV_STATE_LIST_INACTIVE; - drvmgr_list_add_tail(&mgr->devices_inactive, dev); + /* Move device to inactive list */ + drvmgr_list_remove( &mgr->devices[ dev->level ], dev ); + dev->level = 0; + dev->state &= ~( DEV_STATE_UNITED | DEV_STATE_INIT_DONE ); + dev->state |= DEV_STATE_LIST_INACTIVE; + drvmgr_list_add_tail( &mgr->devices_inactive, dev ); - DRVMGR_UNLOCK(); + DRVMGR_UNLOCK(); - /* Free Device Driver Private memory if allocated previously by + /* Free Device Driver Private memory if allocated previously by * Driver manager. */ - if (dev->drv->dev_priv_size && dev->priv) { - free(dev->priv); - dev->priv = NULL; - } - dev->drv = NULL; + if ( dev->drv->dev_priv_size && dev->priv ) { + free( dev->priv ); + dev->priv = NULL; + } + dev->drv = NULL; - return DRVMGR_OK; + return DRVMGR_OK; } /* Unregister device, @@ -166,39 +173,40 @@ int drvmgr_dev_drv_separate(struct drvmgr_dev *dev) * - remove from driver list * - remove from bus list */ -int drvmgr_dev_unregister(struct drvmgr_dev *dev) +int drvmgr_dev_unregister( struct drvmgr_dev *dev ) { - struct drvmgr *mgr = &drvmgr; - struct drvmgr_dev *subdev, **pprev; - int err; + struct drvmgr *mgr = &drvmgr; + struct drvmgr_dev *subdev, **pprev; + int err; - /* Separate device from driver, if the device is united with a driver. + /* Separate device from driver, if the device is united with a driver. * * If this device is a bridge all child buses/devices are also removed. */ - err = drvmgr_dev_drv_separate(dev); - if (err != DRVMGR_OK) - return err; + err = drvmgr_dev_drv_separate( dev ); + if ( err != DRVMGR_OK ) { + return err; + } - DRVMGR_LOCK_WRITE(); + DRVMGR_LOCK_WRITE(); - /* Remove it from inactive list */ - drvmgr_list_remove(&mgr->devices_inactive, dev); + /* Remove it from inactive list */ + drvmgr_list_remove( &mgr->devices_inactive, dev ); - /* Remove device from parent bus list (no check if dev not in list) */ - pprev = &dev->parent->children; - subdev = dev->parent->children; - while (subdev != dev) { - pprev = &subdev->next_in_bus; - subdev = subdev->next_in_bus; - } - *pprev = subdev->next_in_bus; - dev->parent->dev_cnt--; + /* Remove device from parent bus list (no check if dev not in list) */ + pprev = &dev->parent->children; + subdev = dev->parent->children; + while ( subdev != dev ) { + pprev = &subdev->next_in_bus; + subdev = subdev->next_in_bus; + } + *pprev = subdev->next_in_bus; + dev->parent->dev_cnt--; - DRVMGR_UNLOCK(); + DRVMGR_UNLOCK(); - /* All references to this device has been removed at this point */ - free(dev); + /* All references to this device has been removed at this point */ + free( dev ); - return DRVMGR_OK; + return DRVMGR_OK; }